@libp2p/utils 1.0.7 → 1.0.10

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.
@@ -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/interfaces/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,+BAA+B,CAAA;AAG5D;;;;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":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/utils",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
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",
@@ -64,8 +64,8 @@
64
64
  "types": "./dist/src/multiaddr/is-private.d.ts"
65
65
  },
66
66
  "./stream-to-ma-conn": {
67
- "import": "./dist/src/stream-to-ma-connr.js",
68
- "types": "./dist/src/stream-to-ma-connr.d.ts"
67
+ "import": "./dist/src/stream-to-ma-conn.js",
68
+ "types": "./dist/src/stream-to-ma-conn.d.ts"
69
69
  }
70
70
  },
71
71
  "eslintConfig": {
@@ -156,18 +156,18 @@
156
156
  ]
157
157
  },
158
158
  "scripts": {
159
+ "clean": "aegir clean",
159
160
  "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"
161
+ "dep-check": "aegir dep-check",
162
+ "build": "aegir build",
163
+ "test": "aegir test",
164
+ "test:chrome": "aegir test -t browser --cov",
165
+ "test:chrome-webworker": "aegir test -t webworker",
166
+ "test:firefox": "aegir test -t browser -- --browser firefox",
167
+ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
168
+ "test:node": "aegir test -t node --cov",
169
+ "test:electron-main": "aegir test -t electron-main",
170
+ "release": "aegir release"
171
171
  },
172
172
  "dependencies": {
173
173
  "@achingbrain/ip-address": "^8.1.0",
@@ -177,13 +177,16 @@
177
177
  "err-code": "^3.0.1",
178
178
  "is-loopback-addr": "^2.0.1",
179
179
  "it-stream-types": "^1.0.4",
180
- "private-ip": "^2.1.1"
180
+ "private-ip": "^2.1.1",
181
+ "ts-mocha": "^9.0.2",
182
+ "ts-node": "^10.7.0"
181
183
  },
182
184
  "devDependencies": {
183
185
  "@libp2p/interfaces": "^1.0.3",
184
- "aegir": "^36.1.2",
186
+ "aegir": "^37.0.4",
185
187
  "it-all": "^1.0.6",
186
188
  "it-pair": "^2.0.2",
187
- "it-pipe": "^2.0.2"
189
+ "it-pipe": "^2.0.2",
190
+ "uint8arrays": "^3.0.0"
188
191
  }
189
192
  }
@@ -1,17 +1,12 @@
1
- import type { Multiaddr } from '@multiformats/multiaddr'
1
+ import type { Address } from '@libp2p/interfaces/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 {}