@constl/utils-tests 1.4.3 → 1.6.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.
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.4.3";
1
+ export declare const version = "1.6.1";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated by genversion.
2
- export const version = "1.4.3";
2
+ export const version = "1.6.1";
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.3",
2
+ "version": "1.6.1",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "name": "@constl/utils-tests",
5
5
  "author": "Julien Jean Malard-Adam",
@@ -20,63 +20,67 @@
20
20
  "postbuild": "./dist/**/*"
21
21
  },
22
22
  "devDependencies": {
23
- "@chainsafe/libp2p-gossipsub": "^13.1.0",
24
- "@chainsafe/libp2p-noise": "^15.1.0",
25
- "@chainsafe/libp2p-yamux": "^6.0.2",
26
- "@constl/ipa": "1.2.1",
27
- "@eslint/js": "^9.7.0",
28
- "@libp2p/circuit-relay-v2": "^1.1.2",
29
- "@libp2p/crypto": "^4.1.6",
30
- "@libp2p/identify": "^2.1.2",
31
- "@libp2p/interface": "^1.6.1",
32
- "@libp2p/peer-id-factory": "^4.2.1",
33
- "@libp2p/websockets": "^8.1.2",
34
- "@multiformats/multiaddr": "^12.3.0",
35
- "@multiformats/multiaddr-matcher": "^1.2.4",
36
- "@orbitdb/feed-db": "^1.0.1",
23
+ "@chainsafe/libp2p-gossipsub": "14.1.0",
24
+ "@chainsafe/libp2p-noise": "^16.0.0",
25
+ "@chainsafe/libp2p-yamux": "^7.0.1",
26
+ "@constl/bohr-db": "^1.2.0",
27
+ "@constl/ipa": "1.2.7",
28
+ "@constl/orbit-db-types": "^2.0.6",
29
+ "@eslint/js": "^9.13.0",
30
+ "@libp2p/circuit-relay-v2": "^3.1.0",
31
+ "@libp2p/crypto": "^5.0.6",
32
+ "@libp2p/identify": "^3.0.10",
33
+ "@libp2p/interface": "^2.2.0",
34
+ "@libp2p/websockets": "^9.0.10",
35
+ "@multiformats/multiaddr": "^12.3.1",
36
+ "@multiformats/multiaddr-matcher": "^1.3.0",
37
+ "@orbitdb/feed-db": "^1.1.0",
37
38
  "@types/crypto-js": "^4.2.2",
38
39
  "@types/file-saver": "^2.0.7",
39
- "@types/mocha": "^10.0.7",
40
- "@types/node": "^20.14.11",
40
+ "@types/mocha": "^10.0.9",
41
+ "@types/node": "^22.8.1",
41
42
  "@types/uuid": "^10.0.0",
42
- "@typescript-eslint/eslint-plugin": "^7.16.1",
43
- "@typescript-eslint/parser": "^7.16.1",
44
- "aegir": "^44.0.1",
43
+ "@typescript-eslint/eslint-plugin": "^8.11.0",
44
+ "@typescript-eslint/parser": "^8.11.0",
45
+ "aegir": "^44.1.4",
46
+ "ajv": "^8.17.1",
45
47
  "buffer": "^6.0.3",
46
- "core-js": "^3.37.1",
47
- "electron": "^31.4.0",
48
- "esbuild": "^0.23.0",
49
- "eslint": "^9.7.0",
48
+ "core-js": "^3.38.1",
49
+ "electron": "^33.0.2",
50
+ "esbuild": "^0.24.0",
51
+ "eslint": "^9.13.0",
50
52
  "eslint-config-airbnb-base": "^15.0.0",
51
53
  "eslint-config-prettier": "^9.1.0",
52
54
  "eslint-config-standard": "^17.1.0",
53
- "eslint-plugin-import": "^2.29.1",
54
- "eslint-plugin-n": "^17.9.0",
55
- "eslint-plugin-promise": "^7.0.0",
56
- "execa": "^9.3.0",
57
- "mocha": "^10.6.0",
58
- "playwright": "^1.45.2",
55
+ "eslint-plugin-import": "^2.31.0",
56
+ "eslint-plugin-n": "^17.11.1",
57
+ "eslint-plugin-promise": "^7.1.0",
58
+ "execa": "^9.5.0",
59
+ "mocha": "^10.7.3",
60
+ "playwright": "^1.48.2",
59
61
  "prettier": "^3.3.3",
60
62
  "source-map-support": "^0.5.21",
61
63
  "ts-patch": "^3.2.1",
62
64
  "tsconfig-paths": "^4.2.0",
63
65
  "tscpaths": "^0.0.9",
64
66
  "typescript": "5.5.4",
65
- "typescript-eslint": "^7.16.1",
66
- "typescript-transform-paths": "^3.4.7"
67
+ "typescript-eslint": "^8.11.0",
68
+ "typescript-transform-paths": "^3.5.1"
67
69
  },
68
70
  "dependencies": {
69
- "@helia/block-brokers": "^3.0.2",
70
- "@orbitdb/quickstart": "git+https://github.com/orbitdb/quickstart.git#1557ffe",
71
- "blockstore-core": "^5.0.0",
72
- "blockstore-level": "^1.1.8",
71
+ "@helia/block-brokers": "^4.0.1",
72
+ "@libp2p/peer-id": "^5.0.7",
73
+ "@libp2p/webrtc": "^5.0.15",
74
+ "@orbitdb/core": "^2.3.0",
75
+ "blockstore-core": "^5.0.2",
76
+ "blockstore-level": "^2.0.1",
73
77
  "browserify-fs": "^1.0.0",
74
- "chokidar": "^3.6.0",
75
- "crypto-browserify": "^3.12.0",
78
+ "chokidar": "^4.0.1",
79
+ "crypto-browserify": "^3.12.1",
76
80
  "events": "^3.3.0",
77
81
  "genversion": "^3.2.0",
78
- "helia": "^4.2.4",
79
- "libp2p": "^1.8.1",
82
+ "helia": "5.1.0",
83
+ "libp2p": "^2.2.0",
80
84
  "os-browserify": "^0.3.0",
81
85
  "process": "^0.11.10",
82
86
  "read-package-up": "^11.0.0",
@@ -84,7 +88,7 @@
84
88
  "stream-browserify": "^3.0.0",
85
89
  "uint8arrays": "^5.1.0",
86
90
  "url-polyfill": "^1.1.12",
87
- "uuid": "^10.0.0",
91
+ "uuid": "^11.0.1",
88
92
  "wherearewe": "^2.0.1"
89
93
  },
90
94
  "scripts": {
@@ -1,15 +1 @@
1
- declare module "@orbitdb/quickstart" {
2
- import { Identities, Identity, OrbitDB } from "@orbitdb/core";
3
- import { Libp2pOptions as Libp2pOptionsType } from "libp2p";
4
-
5
- export function startOrbitDB(args: {
6
- id?: string;
7
- identity?: Identity;
8
- identities?: Identities;
9
- directory?: string;
10
- }): Promise<OrbitDB>;
11
- export function stopOrbitDB(orbitdb: OrbitDB): Promise<void>;
12
-
13
- export const DefaultLibp2pOptions: Libp2pOptionsType;
14
- export const DefaultLibp2pBrowserOptions: Libp2pOptionsType;
15
- }
1
+ export * from "@constl/orbit-db-types";
package/src/attente.ts CHANGED
@@ -88,7 +88,7 @@ export class AttendreFichierExiste extends EventEmitter {
88
88
  }
89
89
 
90
90
  annuler() {
91
- this.fOublier && this.fOublier();
91
+ this.fOublier?.();
92
92
  }
93
93
  }
94
94
 
package/src/config.ts CHANGED
@@ -86,7 +86,6 @@ export const générerConfigÆgir = async (): Promise<PartialOptions> => {
86
86
  },
87
87
  },
88
88
  build: {
89
- // @ts-expect-error Erreur différentes versions esbuild et Ægir
90
89
  config: esbuild,
91
90
  },
92
91
  };
package/src/libp2p.ts ADDED
@@ -0,0 +1,84 @@
1
+ /*
2
+ Certaines parties de ce fichier proviennent de @orbitdb/quickstart
3
+
4
+ MIT License
5
+
6
+ Copyright (c) 2024 OrbitDB Community
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
25
+ */
26
+
27
+ import { identify } from "@libp2p/identify";
28
+ import { webSockets } from "@libp2p/websockets";
29
+ import { webRTC } from "@libp2p/webrtc";
30
+ import { all } from "@libp2p/websockets/filters";
31
+ import { noise } from "@chainsafe/libp2p-noise";
32
+ import { yamux } from "@chainsafe/libp2p-yamux";
33
+ import { gossipsub } from "@chainsafe/libp2p-gossipsub";
34
+ import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
35
+
36
+ /**
37
+ * A basic Libp2p configuration for Node.js nodes.
38
+ */
39
+ export const DefaultLibp2pOptions = {
40
+ addresses: {
41
+ listen: ["/ip4/0.0.0.0/tcp/0/ws", "/p2p-circuit"],
42
+ },
43
+ transports: [
44
+ webSockets({
45
+ filter: all,
46
+ }),
47
+ webRTC(),
48
+ circuitRelayTransport(),
49
+ ],
50
+ connectionEncrypters: [noise()],
51
+ streamMuxers: [yamux()],
52
+ connectionGater: {
53
+ denyDialMultiaddr: () => false,
54
+ },
55
+ services: {
56
+ identify: identify(),
57
+ pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
58
+ },
59
+ };
60
+
61
+ /**
62
+ * A basic Libp2p configuration for browser nodes.
63
+ */
64
+ export const DefaultLibp2pBrowserOptions = {
65
+ addresses: {
66
+ listen: ["/webrtc", "/p2p-circuit"],
67
+ },
68
+ transports: [
69
+ webSockets({
70
+ filter: all,
71
+ }),
72
+ webRTC(),
73
+ circuitRelayTransport(),
74
+ ],
75
+ connectionEncrypters: [noise()],
76
+ streamMuxers: [yamux()],
77
+ connectionGater: {
78
+ denyDialMultiaddr: () => false,
79
+ },
80
+ services: {
81
+ identify: identify(),
82
+ pubsub: gossipsub({ allowPublishToZeroTopicPeers: true }),
83
+ },
84
+ };
package/src/orbite.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  /*
2
- Certaines parties de ce fichier proviennent d'OrbitDB
2
+ Certaines parties de ce fichier proviennent d'OrbitDB et de @orbitdb/quickstart
3
3
 
4
4
  MIT License
5
5
 
6
6
  Copyright (c) 2019 Haja Networks Oy
7
+ Copyright (c) 2024 OrbitDB Community
7
8
 
8
9
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
10
  of this software and associated documentation files (the "Software"), to deal
@@ -25,21 +26,60 @@ SOFTWARE.
25
26
  */
26
27
 
27
28
  import type { HeliaLibp2p } from "helia";
28
- import type {
29
- FeedStoreTypé,
30
- KeyValueStoreTypé,
31
- OrbitDB,
32
- Store,
33
- } from "@orbitdb/core";
34
-
29
+ import type { Identities, Identity, OrbitDB, Database } from "@orbitdb/core";
30
+ import type { TypedKeyValue, TypedFeed, TypedSet } from "@constl/bohr-db";
35
31
  import { once } from "events";
36
32
 
37
33
  import { dossierTempo } from "@/dossiers.js";
38
34
  import { connecterPairs } from "@/sfip.js";
39
35
  import { isNode, isElectronMain } from "wherearewe";
40
36
 
41
- const OrbitDBQuickstart = await import("@orbitdb/quickstart");
42
- const { startOrbitDB, stopOrbitDB } = OrbitDBQuickstart;
37
+ import { createHelia } from "helia";
38
+ import { createLibp2p } from "libp2p";
39
+ import { createOrbitDB } from "@orbitdb/core";
40
+ import { LevelBlockstore } from "blockstore-level";
41
+ import { bitswap } from "@helia/block-brokers";
42
+ import { DefaultLibp2pOptions, DefaultLibp2pBrowserOptions } from "./libp2p.js";
43
+
44
+ const isBrowser = () => typeof window !== "undefined";
45
+
46
+ const startOrbitDB = async ({
47
+ id,
48
+ identity,
49
+ identities,
50
+ directory,
51
+ }: {
52
+ id?: string;
53
+ identity?: Identity;
54
+ identities?: typeof Identities;
55
+ directory?: string;
56
+ } = {}) => {
57
+ const options = isBrowser()
58
+ ? DefaultLibp2pBrowserOptions
59
+ : DefaultLibp2pOptions;
60
+ const libp2p = await createLibp2p({ ...options });
61
+ directory = directory || ".";
62
+ const blockstore = new LevelBlockstore(`${directory}/ipfs/blocks`);
63
+ const ipfs = await createHelia({
64
+ libp2p,
65
+ blockstore,
66
+ blockBrokers: [bitswap()],
67
+ });
68
+ const orbitdb = await createOrbitDB({
69
+ ipfs,
70
+ id,
71
+ identity,
72
+ identities,
73
+ directory,
74
+ });
75
+ return orbitdb;
76
+ };
77
+
78
+ const stopOrbitDB = async (orbitdb: OrbitDB) => {
79
+ await orbitdb.stop();
80
+ await orbitdb.ipfs.stop();
81
+ await orbitdb.ipfs.blockstore.unwrap().unwrap().child.db.close();
82
+ };
43
83
 
44
84
  export const créerOrbiteTest = async ({
45
85
  n = 1,
@@ -87,7 +127,9 @@ export const créerOrbiteTest = async ({
87
127
  return { orbites, fOublier };
88
128
  };
89
129
 
90
- export const attendreSync = async (bd: Store): Promise<void> => {
130
+ export const attendreSync = async (
131
+ bd: Awaited<ReturnType<typeof Database>>,
132
+ ): Promise<void> => {
91
133
  await once(bd.events, "update");
92
134
  };
93
135
 
@@ -99,7 +141,7 @@ export type ContrôleurConstellation = {
99
141
  estAutorisé: (id: string) => Promise<boolean>;
100
142
  grant: (rôle: "MODÉRATEUR" | "MEMBRE", id: string) => Promise<void>;
101
143
  revoke: (_rôle: "MODÉRATEUR" | "MEMBRE", _id: string) => Promise<void>;
102
- bd: Store;
144
+ bd: Awaited<ReturnType<typeof Database>>;
103
145
  };
104
146
 
105
147
  const attendreInvité = (
@@ -119,7 +161,10 @@ const attendreInvité = (
119
161
  });
120
162
 
121
163
  export const peutÉcrire = async (
122
- bd: KeyValueStoreTypé<{ [clef: string]: number }> | FeedStoreTypé<string>,
164
+ bd:
165
+ | TypedKeyValue<{ [clef: string]: number }>
166
+ | TypedFeed<string>
167
+ | TypedSet<string>,
123
168
  attendre?: OrbitDB,
124
169
  ): Promise<boolean> => {
125
170
  if (attendre) {
@@ -131,7 +176,7 @@ export const peutÉcrire = async (
131
176
 
132
177
  try {
133
178
  if (bd.type === "keyvalue") {
134
- const bdKV = bd as KeyValueStoreTypé<{ [clef: string]: number }>;
179
+ const bdKV = bd as TypedKeyValue<{ [clef: string]: number }>;
135
180
 
136
181
  // Important d'avoir une clef unique pour éviter l'interférence entre les tests
137
182
  const CLEF = "test" + Math.random().toString();
@@ -145,26 +190,27 @@ export const peutÉcrire = async (
145
190
  } else if (bd.type === "feed") {
146
191
  const VAL = "test";
147
192
 
148
- await (bd as FeedStoreTypé<string>).add(VAL);
149
- const éléments = await (bd as FeedStoreTypé<string>).all();
193
+ await (bd as TypedFeed<string>).add(VAL);
194
+ const éléments = await (bd as TypedFeed<string>).all();
150
195
 
151
196
  const autorisé = éléments.length === 1 && éléments[0].value === VAL;
152
197
  if (éléments.length === 1) {
153
- await (bd as FeedStoreTypé<string>).remove(éléments[0].hash);
198
+ await (bd as TypedFeed<string>).remove(éléments[0].hash);
154
199
  }
155
200
  return autorisé;
156
201
  } else if (bd.type === "set") {
157
202
  const VAL = "test";
158
203
 
159
- await (bd as FeedStoreTypé<string>).add(VAL);
160
- const éléments = await (bd as FeedStoreTypé<string>).all();
204
+ await bd.add(VAL);
205
+ const éléments = await bd.all();
161
206
 
162
207
  const autorisé = éléments.length === 1 && éléments[0].value === VAL;
163
208
  if (éléments.length === 1) {
164
- await (bd as FeedStoreTypé<string>).remove(éléments[0].hash);
209
+ await bd.del(éléments[0].hash);
165
210
  }
166
211
  return autorisé;
167
212
  } else {
213
+ // @ts-expect-error bd.type n'a plus d'options
168
214
  throw new Error(`Type de BD ${bd.type} non supporté par ce test.`);
169
215
  }
170
216
  } catch (e) {
@@ -31,22 +31,21 @@ import { circuitRelayServer } from "@libp2p/circuit-relay-v2";
31
31
  import { webSockets } from "@libp2p/websockets";
32
32
  import * as filters from "@libp2p/websockets/filters";
33
33
  import { identify } from "@libp2p/identify";
34
- import { createFromPrivKey } from "@libp2p/peer-id-factory";
35
34
  import { keys } from "@libp2p/crypto";
36
35
  import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
36
+ import { FaultTolerance } from "@libp2p/interface";
37
37
 
38
38
  // output of: console.log(server.peerId.privateKey.toString('hex'))
39
- const relayPrivKey =
39
+ const privateKeyString =
40
40
  "08011240821cb6bc3d4547fcccb513e82e4d718089f8a166b23ffcd4a436754b6b0774cf07447d1693cd10ce11ef950d7517bad6e9472b41a927cd17fc3fb23f8c70cd99";
41
- // the peer id of the above key
41
+ // L'identité de pair qui correspond à la clef privée ci-dessus
42
42
  // const relayId = '12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE'
43
43
 
44
- const encoded = uint8ArrayFromString(relayPrivKey, "hex");
45
- const privateKey = await keys.unmarshalPrivateKey(encoded);
46
- const peerId = await createFromPrivKey(privateKey);
44
+ const encoded = uint8ArrayFromString(privateKeyString, "hex");
45
+ const privateKey = keys.privateKeyFromProtobuf(encoded);
47
46
 
48
47
  const relai = await createLibp2p({
49
- peerId,
48
+ privateKey,
50
49
  addresses: {
51
50
  listen: ["/ip4/0.0.0.0/tcp/54321/ws"],
52
51
  },
@@ -55,7 +54,10 @@ const relai = await createLibp2p({
55
54
  filter: filters.all,
56
55
  }),
57
56
  ],
58
- connectionEncryption: [noise()],
57
+ transportManager: {
58
+ faultTolerance: FaultTolerance.NO_FATAL,
59
+ },
60
+ connectionEncrypters: [noise()],
59
61
  streamMuxers: [yamux()],
60
62
  services: {
61
63
  identify: identify(),
@@ -73,6 +75,10 @@ relai.addEventListener("peer:connect", async (event) => {
73
75
  console.log("peer:connect", event.detail);
74
76
  });
75
77
 
78
+ relai.addEventListener("peer:discovery", async (event) => {
79
+ console.log("peer:discovery", event.detail);
80
+ });
81
+
76
82
  relai.addEventListener("peer:disconnect", async (event) => {
77
83
  console.log("peer:disconnect", event.detail);
78
84
  relai.peerStore.delete(event.detail);
package/src/sfip.ts CHANGED
@@ -12,10 +12,7 @@ import {} from "@libp2p/interface";
12
12
 
13
13
  import { isBrowser, isElectronRenderer } from "wherearewe";
14
14
 
15
- import {
16
- DefaultLibp2pBrowserOptions,
17
- DefaultLibp2pOptions,
18
- } from "@orbitdb/quickstart";
15
+ import { DefaultLibp2pBrowserOptions, DefaultLibp2pOptions } from "./libp2p.js";
19
16
 
20
17
  export const créerHéliaTest = async ({
21
18
  dossier,
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = "1.4.3";
2
+ export const version = "1.6.1";