diff --git a/packages/metrics-simple/README.md b/packages/metrics-simple/README.md index 646db5606e..3038752d72 100644 --- a/packages/metrics-simple/README.md +++ b/packages/metrics-simple/README.md @@ -1,26 +1,57 @@ -# @libp2p/simple-metrics +# @libp2p/simple-metrics [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/) [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io) -[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-simple-metrics.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-simple-metrics) -[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-simple-metrics/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p-simple-metrics/actions/workflows/js-test-and-release.yml?query=branch%3Amain) +[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p) +[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) > Simple in-memory metrics gathering for libp2p -## Table of contents +# About -- [Install](#install) - - [Browser ` ``` -## License +# API Docs + +- + +# License Licensed under either of -- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / ) -- MIT ([LICENSE-MIT](LICENSE-MIT) / ) +- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-simple/LICENSE-APACHE) / ) +- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/metrics-simple/LICENSE-MIT) / ) -## Contribution +# Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/packages/metrics-simple/package.json b/packages/metrics-simple/package.json index e271d41b8d..d7ad46e556 100644 --- a/packages/metrics-simple/package.json +++ b/packages/metrics-simple/package.json @@ -3,13 +3,17 @@ "version": "1.0.1", "description": "Simple in-memory metrics gathering for libp2p", "license": "Apache-2.0 OR MIT", - "homepage": "https://github.com/libp2p/js-libp2p-simple-metrics#readme", + "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/metrics-simple#readme", "repository": { "type": "git", - "url": "git+https://github.com/libp2p/js-libp2p-simple-metrics.git" + "url": "git+https://github.com/libp2p/js-libp2p.git" }, "bugs": { - "url": "https://github.com/libp2p/js-libp2p-simple-metrics/issues" + "url": "https://github.com/libp2p/js-libp2p/issues" + }, + "publishConfig": { + "access": "public", + "provenance": true }, "type": "module", "types": "./dist/src/index.d.ts", @@ -28,94 +32,10 @@ "eslintConfig": { "extends": "ipfs", "parserOptions": { + "project": true, "sourceType": "module" } }, - "release": { - "branches": [ - "main" - ], - "plugins": [ - [ - "@semantic-release/commit-analyzer", - { - "preset": "conventionalcommits", - "releaseRules": [ - { - "breaking": true, - "release": "major" - }, - { - "revert": true, - "release": "patch" - }, - { - "type": "feat", - "release": "minor" - }, - { - "type": "fix", - "release": "patch" - }, - { - "type": "docs", - "release": "patch" - }, - { - "type": "test", - "release": "patch" - }, - { - "type": "deps", - "release": "patch" - }, - { - "scope": "no-release", - "release": false - } - ] - } - ], - [ - "@semantic-release/release-notes-generator", - { - "preset": "conventionalcommits", - "presetConfig": { - "types": [ - { - "type": "feat", - "section": "Features" - }, - { - "type": "fix", - "section": "Bug Fixes" - }, - { - "type": "chore", - "section": "Trivial Changes" - }, - { - "type": "docs", - "section": "Documentation" - }, - { - "type": "deps", - "section": "Dependencies" - }, - { - "type": "test", - "section": "Tests" - } - ] - } - } - ], - "@semantic-release/changelog", - "@semantic-release/npm", - "@semantic-release/github", - "@semantic-release/git" - ] - }, "scripts": { "clean": "aegir clean", "lint": "aegir lint", @@ -130,13 +50,13 @@ "dep-check": "aegir dep-check -i events" }, "dependencies": { - "@libp2p/interface": "^0.1.2", - "@libp2p/logger": "^3.0.2", + "@libp2p/interface": "^1.3.1", + "@libp2p/logger": "^4.0.12", "it-foreach": "^2.0.4", "it-stream-types": "^2.0.1" }, "devDependencies": { - "aegir": "^40.0.13", + "aegir": "^42.2.11", "p-defer": "^4.0.0" } } diff --git a/packages/metrics-simple/src/index.ts b/packages/metrics-simple/src/index.ts index 36e81da3e9..d8f25688b5 100644 --- a/packages/metrics-simple/src/index.ts +++ b/packages/metrics-simple/src/index.ts @@ -1,8 +1,8 @@ /** * @packageDocumentation * - * Stores metrics in memory and periodically invokes a configured callback - * to receive them. + * Stores metrics in memory and periodically invokes a configured callback to + * receive them. * * @example * @@ -25,10 +25,8 @@ import { logger } from '@libp2p/logger' import each from 'it-foreach' -import type { MultiaddrConnection, Stream, Connection } from '@libp2p/interface/connection' -import type { Startable } from '@libp2p/interface/dist/src/startable' -import type { Metric, MetricGroup, StopTimer, Metrics, CalculatedMetricOptions, MetricOptions, Counter, CounterGroup, CalculateMetric } from '@libp2p/interface/metrics' -import type { Duplex, Source } from 'it-stream-types' +import type { Startable, MultiaddrConnection, Stream, Connection, Metric, MetricGroup, StopTimer, Metrics, CalculatedMetricOptions, MetricOptions, Counter, CounterGroup, CalculateMetric } from '@libp2p/interface' +import type { Duplex } from 'it-stream-types' const log = logger('libp2p:simple-metrics') @@ -185,7 +183,7 @@ class SimpleMetrics implements Metrics, Startable { * Override the sink/source of the stream to count the bytes * in and out */ - _track (stream: Duplex>, name: string): void { + _track (stream: Duplex>, name: string): void { const self = this const sink = stream.sink @@ -218,7 +216,7 @@ class SimpleMetrics implements Metrics, Startable { registerMetric (name: string, opts: CalculatedMetricOptions): void registerMetric (name: string, opts?: MetricOptions): Metric registerMetric (name: string, opts: any = {}): any { - if (name == null ?? name.trim() === '') { + if (name == null || name.trim() === '') { throw new Error('Metric name is required') } @@ -237,7 +235,7 @@ class SimpleMetrics implements Metrics, Startable { registerMetricGroup (name: string, opts: CalculatedMetricOptions>): void registerMetricGroup (name: string, opts?: MetricOptions): MetricGroup registerMetricGroup (name: string, opts: any = {}): any { - if (name == null ?? name.trim() === '') { + if (name == null || name.trim() === '') { throw new Error('Metric name is required') } @@ -256,7 +254,7 @@ class SimpleMetrics implements Metrics, Startable { registerCounter (name: string, opts: CalculatedMetricOptions): void registerCounter (name: string, opts?: MetricOptions): Counter registerCounter (name: string, opts: any = {}): any { - if (name == null ?? name.trim() === '') { + if (name == null || name.trim() === '') { throw new Error('Metric name is required') } @@ -275,7 +273,7 @@ class SimpleMetrics implements Metrics, Startable { registerCounterGroup (name: string, opts: CalculatedMetricOptions>): void registerCounterGroup (name: string, opts?: MetricOptions): CounterGroup registerCounterGroup (name: string, opts: any = {}): any { - if (name == null ?? name.trim() === '') { + if (name == null || name.trim() === '') { throw new Error('Metric name is required') } diff --git a/packages/metrics-simple/test/index.spec.ts b/packages/metrics-simple/test/index.spec.ts index 3220de5151..6cc860f637 100644 --- a/packages/metrics-simple/test/index.spec.ts +++ b/packages/metrics-simple/test/index.spec.ts @@ -1,8 +1,8 @@ -import { start, stop } from '@libp2p/interface/startable' +import { start, stop } from '@libp2p/interface' import { expect } from 'aegir/chai' import pDefer from 'p-defer' import { simpleMetrics } from '../src/index.js' -import type { Metrics } from '@libp2p/interface/src/metrics' +import type { Metrics } from '@libp2p/interface' describe('simple-metrics', () => { let s: Metrics diff --git a/packages/metrics-simple/tsconfig.json b/packages/metrics-simple/tsconfig.json index 13a3599639..b382e52ffe 100644 --- a/packages/metrics-simple/tsconfig.json +++ b/packages/metrics-simple/tsconfig.json @@ -6,5 +6,13 @@ "include": [ "src", "test" + ], + "references": [ + { + "path": "../interface" + }, + { + "path": "../logger" + } ] }