@libp2p/utils 1.0.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,18 +1,30 @@
1
- # js-libp2p-utils
1
+ # @libp2p/utils <!-- omit in toc -->
2
2
 
3
- [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)
4
- [![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
5
- [![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
6
- [![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
7
- [![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils)
8
- [![](https://img.shields.io/travis/libp2p/js-libp2p-utils.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-utils)
9
- [![Dependency Status](https://david-dm.org/libp2p/js-libp2p-utils.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-utils)
10
- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
5
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-utils.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-utils)
7
+ [![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml)
11
8
 
12
- > This package serves as a central repository for shared logic and dependencies for all libp2p packages, using `libp2p-utils` helps to easily re-use small scoped blocks of logic across all libp2p modules and also as a dependency proxy (think `aegir` for domain logic dependencies).
9
+ > Package to aggregate shared logic and dependencies for the libp2p ecosystem
13
10
 
11
+ ## Table of contents <!-- omit in toc -->
12
+
13
+ - [Install](#install)
14
+ - [Lead Maintainer](#lead-maintainer)
15
+ - [Usage](#usage)
16
+ - [Contribute](#contribute)
17
+ - [License](#license)
18
+ - [Contribution](#contribution)
19
+
20
+ ## Install
21
+
22
+ ```console
23
+ $ npm i @libp2p/utils
24
+ ```
14
25
 
15
26
  The libp2p ecosystem has lots of repos with it comes several problems like:
27
+
16
28
  - Domain logic dedupe - all modules shared a lot of logic like validation, streams handling, etc.
17
29
  - Dependencies management - it's really easy with so many repos for dependencies to go out of control, they become outdated, different repos use different modules to do the same thing (like merging defaults options), browser bundles ends up with multiple versions of the same package, bumping versions is cumbersome to do because we need to go through several repos, etc.
18
30
 
@@ -22,14 +34,8 @@ These problems are the motivation for this package, having shared logic in this
22
34
 
23
35
  [Vasco Santos](https://github.com/vasco-santos)
24
36
 
25
- ## Install
26
-
27
-
28
- ```bash
29
- $ npm install --save @libp2p/utils
30
- ```
31
-
32
37
  ## Usage
38
+
33
39
  Each function should be imported directly.
34
40
 
35
41
  ```js
@@ -48,4 +54,11 @@ Check out our [contributing document](https://github.com/ipfs/community/blob/mas
48
54
 
49
55
  ## License
50
56
 
51
- [MIT](LICENSE) © Protocol Labs Inc.
57
+ Licensed under either of
58
+
59
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
60
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
61
+
62
+ ## Contribution
63
+
64
+ 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.
@@ -1,12 +1,8 @@
1
- import type { Multiaddr } from '@multiformats/multiaddr';
2
- interface Address {
3
- multiaddr: Multiaddr;
4
- isCertified: boolean;
5
- }
1
+ import type { Address } from '@libp2p/interface-peer-store';
6
2
  /**
7
- * Sort given addresses by putting public addresses first.
3
+ * Compare function for array.sort().
4
+ * This sort aims to move the private addresses to the end of the array.
8
5
  * In case of equality, a certified address will come first.
9
6
  */
10
- export declare function publicAddressesFirst(addresses: Address[]): Address[];
11
- export {};
7
+ export declare function publicAddressesFirst(a: Address, b: Address): -1 | 0 | 1;
12
8
  //# sourceMappingURL=address-sort.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAGxD,UAAU,OAAO;IACf,SAAS,EAAE,SAAS,CAAA;IACpB,WAAW,EAAE,OAAO,CAAA;CACrB;AA0BD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAE,SAAS,EAAE,OAAO,EAAE,aAEzD"}
1
+ {"version":3,"file":"address-sort.d.ts","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAG3D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAiBxE"}
@@ -1,10 +1,10 @@
1
1
  import { isPrivate } from './multiaddr/is-private.js';
2
2
  /**
3
3
  * Compare function for array.sort().
4
- * This sort aims to move the private adresses to the end of the array.
4
+ * This sort aims to move the private addresses to the end of the array.
5
5
  * In case of equality, a certified address will come first.
6
6
  */
7
- function addressesPublicFirstCompareFunction(a, b) {
7
+ export function publicAddressesFirst(a, b) {
8
8
  const isAPrivate = isPrivate(a.multiaddr);
9
9
  const isBPrivate = isPrivate(b.multiaddr);
10
10
  if (isAPrivate && !isBPrivate) {
@@ -22,11 +22,4 @@ function addressesPublicFirstCompareFunction(a, b) {
22
22
  }
23
23
  return 0;
24
24
  }
25
- /**
26
- * Sort given addresses by putting public addresses first.
27
- * In case of equality, a certified address will come first.
28
- */
29
- export function publicAddressesFirst(addresses) {
30
- return [...addresses].sort(addressesPublicFirstCompareFunction);
31
- }
32
25
  //# sourceMappingURL=address-sort.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAOrD;;;;GAIG;AACH,SAAS,mCAAmC,CAAE,CAAU,EAAE,CAAU;IAClE,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACzC,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEzC,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE;QAC7B,OAAO,CAAC,CAAA;KACT;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE;QACpC,OAAO,CAAC,CAAC,CAAA;KACV;IACD,mBAAmB;IACnB,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE;QACnC,OAAO,CAAC,CAAC,CAAA;KACV;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE;QAC1C,OAAO,CAAC,CAAA;KACT;IAED,OAAO,CAAC,CAAA;AACV,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAE,SAAoB;IACxD,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAA;AACjE,CAAC"}
1
+ {"version":3,"file":"address-sort.js","sourceRoot":"","sources":["../../src/address-sort.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AAErD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAE,CAAU,EAAE,CAAU;IAC1D,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACzC,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAEzC,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE;QAC7B,OAAO,CAAC,CAAA;KACT;SAAM,IAAI,CAAC,UAAU,IAAI,UAAU,EAAE;QACpC,OAAO,CAAC,CAAC,CAAA;KACV;IACD,mBAAmB;IACnB,IAAI,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE;QACnC,OAAO,CAAC,CAAC,CAAA;KACV;SAAM,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,WAAW,EAAE;QAC1C,OAAO,CAAC,CAAA;KACT;IAED,OAAO,CAAC,CAAA;AACV,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import type { Multiaddr } from '@multiformats/multiaddr';
2
- import type { MultiaddrConnection } from '@libp2p/interfaces/transport';
2
+ import type { MultiaddrConnection } from '@libp2p/interface-connection';
3
3
  import type { Duplex } from 'it-stream-types';
4
4
  export interface Timeline {
5
5
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "1.0.8",
3
+ "version": "2.0.0",
4
4
  "description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-utils#readme",
@@ -41,31 +41,32 @@
41
41
  ],
42
42
  "exports": {
43
43
  ".": {
44
+ "types": "./src/index.d.ts",
44
45
  "import": "./dist/src/index.js"
45
46
  },
46
47
  "./address-sort": {
47
- "import": "./dist/src/address-sort.js",
48
- "types": "./dist/src/address-sort.d.ts"
48
+ "types": "./dist/src/address-sort.d.ts",
49
+ "import": "./dist/src/address-sort.js"
49
50
  },
50
51
  "./array-equals": {
51
- "import": "./dist/src/array-equals.js",
52
- "types": "./dist/src/array-equals.d.ts"
52
+ "types": "./dist/src/array-equals.d.ts",
53
+ "import": "./dist/src/array-equals.js"
53
54
  },
54
55
  "./ip-port-to-multiaddr": {
55
- "import": "./dist/src/ip-port-to-multiaddr.js",
56
- "types": "./dist/src/ip-port-to-multiaddr.d.ts"
56
+ "types": "./dist/src/ip-port-to-multiaddr.d.ts",
57
+ "import": "./dist/src/ip-port-to-multiaddr.js"
57
58
  },
58
59
  "./multiaddr/is-loopback": {
59
- "import": "./dist/src/multiaddr/is-loopback.js",
60
- "types": "./dist/src/multiaddr/is-loopback.d.ts"
60
+ "types": "./dist/src/multiaddr/is-loopback.d.ts",
61
+ "import": "./dist/src/multiaddr/is-loopback.js"
61
62
  },
62
63
  "./multiaddr/is-private": {
63
- "import": "./dist/src/multiaddr/is-private.js",
64
- "types": "./dist/src/multiaddr/is-private.d.ts"
64
+ "types": "./dist/src/multiaddr/is-private.d.ts",
65
+ "import": "./dist/src/multiaddr/is-private.js"
65
66
  },
66
67
  "./stream-to-ma-conn": {
67
- "import": "./dist/src/stream-to-ma-conn.js",
68
- "types": "./dist/src/stream-to-ma-conn.d.ts"
68
+ "types": "./dist/src/stream-to-ma-conn.d.ts",
69
+ "import": "./dist/src/stream-to-ma-conn.js"
69
70
  }
70
71
  },
71
72
  "eslintConfig": {
@@ -156,22 +157,25 @@
156
157
  ]
157
158
  },
158
159
  "scripts": {
160
+ "clean": "aegir clean",
159
161
  "lint": "aegir lint",
160
- "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
161
- "build": "tsc",
162
- "pretest": "npm run build",
163
- "test": "aegir test -f ./dist/test/*.js -f ./dist/test/**/*.js",
164
- "test:chrome": "npm run test -- -t browser --cov",
165
- "test:chrome-webworker": "npm run test -- -t webworker",
166
- "test:firefox": "npm run test -- -t browser -- --browser firefox",
167
- "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
168
- "test:node": "npm run test -- -t node --cov",
169
- "test:electron-main": "npm run test -- -t electron-main",
170
- "release": "semantic-release"
162
+ "dep-check": "aegir dep-check",
163
+ "build": "aegir build",
164
+ "test": "aegir test",
165
+ "test:chrome": "aegir test -t browser --cov",
166
+ "test:chrome-webworker": "aegir test -t webworker",
167
+ "test:firefox": "aegir test -t browser -- --browser firefox",
168
+ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
169
+ "test:node": "aegir test -t node --cov",
170
+ "test:electron-main": "aegir test -t electron-main",
171
+ "release": "aegir release"
171
172
  },
172
173
  "dependencies": {
173
174
  "@achingbrain/ip-address": "^8.1.0",
174
- "@libp2p/logger": "^1.0.1",
175
+ "@libp2p/interface-connection": "^1.0.1",
176
+ "@libp2p/interface-peer-store": "^1.0.0",
177
+ "@libp2p/interface-transport": "^1.0.0",
178
+ "@libp2p/logger": "^2.0.0",
175
179
  "@multiformats/multiaddr": "^10.1.1",
176
180
  "abortable-iterator": "^4.0.2",
177
181
  "err-code": "^3.0.1",
@@ -181,9 +185,10 @@
181
185
  },
182
186
  "devDependencies": {
183
187
  "@libp2p/interfaces": "^1.0.3",
184
- "aegir": "^36.1.2",
188
+ "aegir": "^37.2.0",
185
189
  "it-all": "^1.0.6",
186
190
  "it-pair": "^2.0.2",
187
- "it-pipe": "^2.0.2"
191
+ "it-pipe": "^2.0.2",
192
+ "uint8arrays": "^3.0.0"
188
193
  }
189
194
  }
@@ -1,17 +1,12 @@
1
- import type { Multiaddr } from '@multiformats/multiaddr'
1
+ import type { Address } from '@libp2p/interface-peer-store'
2
2
  import { isPrivate } from './multiaddr/is-private.js'
3
3
 
4
- interface Address {
5
- multiaddr: Multiaddr
6
- isCertified: boolean
7
- }
8
-
9
4
  /**
10
5
  * Compare function for array.sort().
11
- * This sort aims to move the private adresses to the end of the array.
6
+ * This sort aims to move the private addresses to the end of the array.
12
7
  * In case of equality, a certified address will come first.
13
8
  */
14
- function addressesPublicFirstCompareFunction (a: Address, b: Address) {
9
+ export function publicAddressesFirst (a: Address, b: Address): -1 | 0 | 1 {
15
10
  const isAPrivate = isPrivate(a.multiaddr)
16
11
  const isBPrivate = isPrivate(b.multiaddr)
17
12
 
@@ -29,11 +24,3 @@ function addressesPublicFirstCompareFunction (a: Address, b: Address) {
29
24
 
30
25
  return 0
31
26
  }
32
-
33
- /**
34
- * Sort given addresses by putting public addresses first.
35
- * In case of equality, a certified address will come first.
36
- */
37
- export function publicAddressesFirst (addresses: Address[]) {
38
- return [...addresses].sort(addressesPublicFirstCompareFunction)
39
- }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
@@ -1,7 +1,7 @@
1
1
  import { abortableSource } from 'abortable-iterator'
2
2
  import { logger } from '@libp2p/logger'
3
3
  import type { Multiaddr } from '@multiformats/multiaddr'
4
- import type { MultiaddrConnection } from '@libp2p/interfaces/transport'
4
+ import type { MultiaddrConnection } from '@libp2p/interface-connection'
5
5
  import type { Duplex } from 'it-stream-types'
6
6
 
7
7
  const log = logger('libp2p:stream:converter')