@peerbit/libp2p-test-utils 1.0.8 → 2.0.1

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,3 +1,2 @@
1
- import { TestSession, LibP2POptions } from "./session.js";
1
+ import { TestSession } from "./session.js";
2
2
  export { TestSession };
3
- export type { LibP2POptions };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiB,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -1,19 +1,6 @@
1
- import { Libp2p, ServiceFactoryMap } from "libp2p";
2
- import { RecursivePartial } from "@libp2p/interfaces";
3
- import { Datastore } from "interface-datastore";
4
- import { ConnectionManagerInit } from "libp2p/dist/src/connection-manager";
5
- import { Components } from "libp2p/components";
6
- import { CircuitRelayService } from "libp2p/dist/src/circuit-relay/index.js";
1
+ import { Libp2p, Libp2pOptions } from "libp2p";
2
+ import { CircuitRelayService } from "@libp2p/circuit-relay-v2";
7
3
  import type { Multiaddr } from "@multiformats/multiaddr";
8
- import type { Transport } from "@libp2p/interface/transport";
9
- export type LibP2POptions<T extends Record<string, unknown>> = {
10
- transports?: RecursivePartial<(components: Components) => Transport>[] | undefined;
11
- connectionManager?: RecursivePartial<ConnectionManagerInit>;
12
- datastore?: RecursivePartial<Datastore> | undefined;
13
- browser?: boolean;
14
- services?: ServiceFactoryMap<T>;
15
- start?: boolean;
16
- };
17
4
  type DefaultServices = {
18
5
  relay: CircuitRelayService;
19
6
  identify: any;
@@ -26,8 +13,8 @@ export declare class TestSession<T> {
26
13
  getMultiaddrs: () => Multiaddr[];
27
14
  dial: (addres: Multiaddr[]) => Promise<any>;
28
15
  }[][]): Promise<this>;
29
- static connected<T extends Record<string, unknown>>(n: number, options?: LibP2POptions<T> | LibP2POptions<T>[]): Promise<TestSession<T>>;
30
- static disconnected<T extends Record<string, unknown>>(n: number, options?: LibP2POptions<T> | LibP2POptions<T>[]): Promise<TestSession<T>>;
16
+ static connected<T extends Record<string, unknown>>(n: number, options?: Libp2pOptions<T> | Libp2pOptions<T>[]): Promise<TestSession<T>>;
17
+ static disconnected<T extends Record<string, unknown>>(n: number, options?: Libp2pOptions<T> | Libp2pOptions<T>[]): Promise<TestSession<T>>;
31
18
  stop(): Promise<any>;
32
19
  }
33
20
  export {};
@@ -3,7 +3,7 @@ import { noise } from "@dao-xyz/libp2p-noise";
3
3
  import { mplex } from "@libp2p/mplex";
4
4
  import { setMaxListeners } from "events";
5
5
  import { relay, transports } from "./transports.js";
6
- import { identifyService } from "libp2p/identify";
6
+ import { identify } from "@libp2p/identify";
7
7
  export class TestSession {
8
8
  peers;
9
9
  constructor(peers) {
@@ -46,12 +46,13 @@ export class TestSession {
46
46
  connectionManager: (options?.[i] || options)?.connectionManager ?? {
47
47
  minConnections: 0
48
48
  },
49
+ peerId: (options?.[i] || options)?.peerId,
49
50
  datastore: (options?.[i] || options)?.datastore,
50
51
  transports: (options?.[i] || options)?.transports ??
51
52
  transports((options?.[i] || options)?.browser),
52
53
  services: {
53
54
  relay: (options?.[i] || options)?.browser ? undefined : relay(),
54
- identify: identifyService(),
55
+ identify: identify(),
55
56
  ...(options?.[i] || options)?.services
56
57
  },
57
58
  connectionEncryption: [noise()],
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA6B,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,E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,CAAC,EAAE,KAAK;iBACvC,CAAC,CAAC;gBACH,OAAO,IAAI,CAAC;YACb,CAAC,CAAC;YACF,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QACzB,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAkC,CAAC;QAC5E,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI;QACH,OAAO,OAAO,CAAC,GAAG,CACjB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YAC1B,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QACjB,CAAC,CAAC,CACF,CAAC;IACH,CAAC;CACD"}
@@ -1,4 +1,4 @@
1
1
  import { Components } from "libp2p/components";
2
- import type { Transport } from "@libp2p/interface/transport";
2
+ import type { Transport } from "@libp2p/interface";
3
3
  export declare const transports: (browser: boolean) => ((components: Components) => Transport)[];
4
- export declare const relay: () => (components: import("libp2p/dist/src/circuit-relay/server").CircuitRelayServerComponents) => import("libp2p/circuit-relay").CircuitRelayService;
4
+ export declare const relay: () => (components: import("@libp2p/circuit-relay-v2/dist/src/server").CircuitRelayServerComponents) => import("@libp2p/circuit-relay-v2").CircuitRelayService;
@@ -1,5 +1,4 @@
1
- import { circuitRelayTransport } from "libp2p/circuit-relay";
2
- import { circuitRelayServer } from "libp2p/circuit-relay";
1
+ import { circuitRelayTransport, circuitRelayServer } from "@libp2p/circuit-relay-v2";
3
2
  import { webRTC } from "@libp2p/webrtc";
4
3
  import { webSockets } from "@libp2p/websockets";
5
4
  import * as filters from "@libp2p/websockets/filters";
@@ -1 +1 @@
1
- {"version":3,"file":"transports.js","sourceRoot":"","sources":["../../src/transports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MA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AC,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/libp2p-test-utils",
3
- "version": "1.0.8",
3
+ "version": "2.0.1",
4
4
  "description": "Test utils for Peerbit",
5
5
  "type": "module",
6
6
  "private": false,
@@ -37,20 +37,20 @@
37
37
  "author": "dao.xyz",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "@dao-xyz/libp2p-noise": "^13.0.1",
41
- "@libp2p/mplex": "^9.0.5",
42
- "@libp2p/tcp": "^8.0.5",
43
- "@libp2p/webrtc": "^3.1.9",
44
- "@libp2p/websockets": "^7.0.5",
45
- "datastore-level": "^10.1.4",
46
- "libp2p": "0.46.9",
47
- "memory-level": "^1.0.0"
40
+ "@dao-xyz/libp2p-noise": "^14.1.2",
41
+ "@libp2p/circuit-relay-v2": "^1.0.9",
42
+ "@libp2p/identify": "^1.0.8",
43
+ "@libp2p/mplex": "^10.0.9",
44
+ "@libp2p/tcp": "^9.0.9",
45
+ "@libp2p/webrtc": "^4.0.13",
46
+ "@libp2p/websockets": "^8.0.9",
47
+ "libp2p": "^1.1.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@peerbit/time": "1.0.4"
50
+ "@peerbit/time": "2.0.1"
51
51
  },
52
52
  "localMaintainers": [
53
53
  "dao.xyz"
54
54
  ],
55
- "gitHead": "851f1a4fdff94efd0f9331a43d6f8652e27e6d26"
55
+ "gitHead": "f4cb6a526d26e98360c32fd28dcdf9eb7ea10551"
56
56
  }
package/src/index.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { TestSession, LibP2POptions } from "./session.js";
1
+ import { TestSession } from "./session.js";
2
2
  export { TestSession };
3
- export type { LibP2POptions };
package/src/session.ts CHANGED
@@ -1,27 +1,11 @@
1
- import { createLibp2p, Libp2p, ServiceFactoryMap } from "libp2p";
1
+ import { createLibp2p, Libp2p, Libp2pOptions, ServiceFactoryMap } from "libp2p";
2
2
  import { noise } from "@dao-xyz/libp2p-noise";
3
3
  import { mplex } from "@libp2p/mplex";
4
4
  import { setMaxListeners } from "events";
5
- import { RecursivePartial } from "@libp2p/interfaces";
6
- import { Datastore } from "interface-datastore";
7
5
  import { relay, transports } from "./transports.js";
8
- import { ConnectionManagerInit } from "libp2p/dist/src/connection-manager";
9
- import { Components } from "libp2p/components";
10
- import { identifyService } from "libp2p/identify";
11
- import { CircuitRelayService } from "libp2p/dist/src/circuit-relay/index.js";
6
+ import { identify } from "@libp2p/identify";
7
+ import { CircuitRelayService } from "@libp2p/circuit-relay-v2";
12
8
  import type { Multiaddr } from "@multiformats/multiaddr";
13
- import type { Transport } from "@libp2p/interface/transport";
14
-
15
- export type LibP2POptions<T extends Record<string, unknown>> = {
16
- transports?:
17
- | RecursivePartial<(components: Components) => Transport>[]
18
- | undefined;
19
- connectionManager?: RecursivePartial<ConnectionManagerInit>;
20
- datastore?: RecursivePartial<Datastore> | undefined;
21
- browser?: boolean;
22
- services?: ServiceFactoryMap<T>;
23
- start?: boolean;
24
- };
25
9
 
26
10
  type DefaultServices = { relay: CircuitRelayService; identify: any };
27
11
  type Libp2pWithServices<T> = Libp2p<T & DefaultServices>;
@@ -59,7 +43,7 @@ export class TestSession<T> {
59
43
  }
60
44
  static async connected<T extends Record<string, unknown>>(
61
45
  n: number,
62
- options?: LibP2POptions<T> | LibP2POptions<T>[]
46
+ options?: Libp2pOptions<T> | Libp2pOptions<T>[]
63
47
  ) {
64
48
  const libs = (await TestSession.disconnected<T>(n, options)).peers;
65
49
  return new TestSession(libs).connect();
@@ -67,7 +51,7 @@ export class TestSession<T> {
67
51
 
68
52
  static async disconnected<T extends Record<string, unknown>>(
69
53
  n: number,
70
- options?: LibP2POptions<T> | LibP2POptions<T>[]
54
+ options?: Libp2pOptions<T> | Libp2pOptions<T>[]
71
55
  ) {
72
56
  // Allow more than 11 listneers
73
57
  setMaxListeners(Infinity);
@@ -83,13 +67,14 @@ export class TestSession<T> {
83
67
  connectionManager: (options?.[i] || options)?.connectionManager ?? {
84
68
  minConnections: 0
85
69
  },
70
+ peerId: (options?.[i] || options)?.peerId,
86
71
  datastore: (options?.[i] || options)?.datastore,
87
72
  transports:
88
73
  (options?.[i] || options)?.transports ??
89
74
  transports((options?.[i] || options)?.browser),
90
75
  services: {
91
76
  relay: (options?.[i] || options)?.browser ? undefined : relay(),
92
- identify: identifyService(),
77
+ identify: identify(),
93
78
  ...(options?.[i] || options)?.services
94
79
  },
95
80
  connectionEncryption: [noise()],
package/src/transports.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { circuitRelayTransport } from "libp2p/circuit-relay";
2
- import { circuitRelayServer } from "libp2p/circuit-relay";
1
+ import {
2
+ circuitRelayTransport,
3
+ circuitRelayServer
4
+ } from "@libp2p/circuit-relay-v2";
3
5
  import { webRTC } from "@libp2p/webrtc";
4
6
  import { webSockets } from "@libp2p/websockets";
5
7
  import * as filters from "@libp2p/websockets/filters";
6
8
  import { tcp } from "@libp2p/tcp";
7
9
  import { Components } from "libp2p/components";
8
- import type { Transport } from "@libp2p/interface/transport";
10
+ import type { Transport } from "@libp2p/interface";
9
11
 
10
12
  export const transports = (
11
13
  browser: boolean
@@ -17,7 +19,7 @@ export const transports = (
17
19
  }),
18
20
  webRTC({}),
19
21
  webSockets({ filter: filters.all })
20
- ]
21
- : [tcp()];
22
+ ]
23
+ : ([tcp()] as any);
22
24
 
23
25
  export const relay = () => circuitRelayServer({});