@constl/utils-tests 1.1.2 → 1.2.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.2",
2
+ "version": "1.2.0",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "name": "@constl/utils-tests",
5
5
  "author": "Julien Jean Malard-Adam",
@@ -22,28 +22,29 @@
22
22
  "devDependencies": {
23
23
  "@chainsafe/libp2p-gossipsub": "^12.0.0",
24
24
  "@chainsafe/libp2p-noise": "^15.0.0",
25
- "@chainsafe/libp2p-yamux": "^6.0.1",
25
+ "@chainsafe/libp2p-yamux": "^6.0.2",
26
26
  "@constl/ipa": "1.0.0",
27
- "@libp2p/circuit-relay-v2": "^1.0.13",
28
- "@libp2p/crypto": "^4.0.1",
29
- "@libp2p/identify": "^1.0.12",
30
- "@libp2p/peer-id-factory": "^4.0.5",
31
- "@libp2p/websockets": "^8.0.13",
27
+ "@libp2p/circuit-relay-v2": "^1.0.15",
28
+ "@libp2p/crypto": "^4.0.2",
29
+ "@libp2p/identify": "^1.0.14",
30
+ "@libp2p/peer-id-factory": "^4.0.6",
31
+ "@libp2p/websockets": "^8.0.15",
32
32
  "@multiformats/multiaddr": "^12.1.14",
33
33
  "@multiformats/multiaddr-matcher": "^1.1.2",
34
34
  "@orbitdb/feed-db": "^1.0.0",
35
35
  "@types/crypto-js": "^4.2.2",
36
36
  "@types/file-saver": "^2.0.7",
37
37
  "@types/mocha": "^10.0.6",
38
- "@types/node": "^20.11.16",
38
+ "@types/node": "^20.11.19",
39
39
  "@types/uuid": "^9.0.8",
40
40
  "@typescript-eslint/eslint-plugin": "^6.21.0",
41
41
  "@typescript-eslint/parser": "^6.21.0",
42
- "aegir": "^42.2.3",
42
+ "aegir": "^42.2.4",
43
43
  "browserify-fs": "^1.0.0",
44
44
  "buffer": "^6.0.3",
45
- "core-js": "^3.35.1",
45
+ "core-js": "^3.36.0",
46
46
  "crypto-browserify": "^3.12.0",
47
+ "esbuild": "^0.20.1",
47
48
  "eslint": "^8.56.0",
48
49
  "eslint-config-airbnb-base": "^15.0.0",
49
50
  "eslint-config-prettier": "^9.1.0",
@@ -54,7 +55,7 @@
54
55
  "execa": "^8.0.1",
55
56
  "file-saver": "^2.0.5",
56
57
  "keys": "link:@libp2p/crypto/keys",
57
- "mocha": "^10.2.0",
58
+ "mocha": "^10.3.0",
58
59
  "os-browserify": "^0.3.0",
59
60
  "playwright": "^1.41.2",
60
61
  "prettier": "^3.2.5",
@@ -65,20 +66,21 @@
65
66
  "tsconfig-paths": "^4.2.0",
66
67
  "tscpaths": "^0.0.9",
67
68
  "typescript": "5.3.3",
68
- "typescript-transform-paths": "^3.4.6"
69
+ "typescript-transform-paths": "^3.4.7"
69
70
  },
70
71
  "dependencies": {
71
72
  "@helia/block-brokers": "^2.0.1",
72
73
  "@orbitdb/quickstart": "^1.0.0",
73
- "blockstore-core": "^4.3.10",
74
- "blockstore-level": "^1.1.7",
75
- "chokidar": "^3.5.3",
74
+ "blockstore-core": "^4.4.0",
75
+ "blockstore-level": "^1.1.8",
76
+ "chokidar": "^3.6.0",
76
77
  "events": "^3.3.0",
77
78
  "genversion": "^3.2.0",
78
79
  "helia": "^3.0.1",
79
- "libp2p": "^1.2.1",
80
+ "libp2p": "^1.2.3",
81
+ "read-package-up": "^11.0.0",
80
82
  "rimraf": "^5.0.5",
81
- "uint8arrays": "^5.0.1",
83
+ "uint8arrays": "^5.0.2",
82
84
  "uuid": "^9.0.1",
83
85
  "wherearewe": "^2.0.1"
84
86
  },
@@ -86,13 +88,12 @@
86
88
  "nettoyer": "rimraf dist",
87
89
  "compiler": "pnpm versioner && pnpm formatter && pnpm nettoyer && pnpm tspc -p tsconfig.build.json",
88
90
  "test:node": "pnpm compiler && pnpm aegir test -t node --cov -- --exit",
89
- "test:navig": "pnpm compiler && pnpm webrtc && pnpm aegir test -t browser --cov",
91
+ "test:navig": "pnpm compiler && pnpm aegir test -t browser --cov",
90
92
  "test:électron-principal": "pnpm compiler && pnpm aegir test -t electron-main --cov",
91
- "test:électron-rendu": "pnpm compiler && pnpm webrtc && pnpm aegir test -t electron-renderer --cov",
93
+ "test:électron-rendu": "pnpm compiler && pnpm aegir test -t electron-renderer --cov",
92
94
  "test": "pnpm test:node && pnpm test:navig",
93
95
  "formatter": "pnpm prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\" && pnpm eslint --ext .js,.ts src",
94
96
  "publier": "pnpm versioner && pnpm compiler && (git commit -a -m 'version' || true) && pnpm publish",
95
- "versioner": "pnpm genversion --es6 --semi src/version.ts",
96
- "webrtc": "node ./test/utils/relai.js &"
97
+ "versioner": "pnpm genversion --es6 --semi src/version.ts"
97
98
  }
98
99
  }
package/src/config.ts ADDED
@@ -0,0 +1,81 @@
1
+ import type { PartialOptions } from "aegir";
2
+ import type { BuildOptions } from "esbuild";
3
+
4
+ import { createRequire } from "module";
5
+ import path, { dirname } from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ import { lancerRelai } from "./sfip.js";
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+ const require = createRequire(import.meta.url);
12
+
13
+ const esbuild: BuildOptions = {
14
+ // this will inject all the named exports from 'node-globals.js' as globals
15
+ inject: [path.join(__dirname, "./scripts/node-globals.js")],
16
+ plugins: [
17
+ {
18
+ name: "node built ins",
19
+ setup(build) {
20
+ build.onResolve({ filter: /^crypto$/ }, () => {
21
+ return { path: require.resolve("crypto-browserify") };
22
+ });
23
+ build.onResolve({ filter: /^fs/ }, () => {
24
+ return { path: require.resolve("browserify-fs") };
25
+ });
26
+ build.onResolve({ filter: /^stream$/ }, () => {
27
+ return { path: require.resolve("stream-browserify") };
28
+ });
29
+ build.onResolve({ filter: /^os$/ }, () => {
30
+ return { path: require.resolve("os-browserify") };
31
+ });
32
+ build.onResolve({ filter: /^node:process$/ }, () => {
33
+ return { path: require.resolve("process/browser") };
34
+ });
35
+ },
36
+ },
37
+ ],
38
+ external: [
39
+ "fs",
40
+ "path",
41
+ "os",
42
+ "chokidar",
43
+ "url",
44
+ "execa",
45
+ "zlib",
46
+ "rimraf",
47
+ "stream",
48
+ "electron",
49
+ "env-paths",
50
+ "@libp2p/tcp",
51
+ "@libp2p/mdns",
52
+ ],
53
+ };
54
+ type RetourAvant = {
55
+ relai?: () => void;
56
+ };
57
+ export const configÆgir: PartialOptions = {
58
+ test: {
59
+ // @ts-expect-error Erreur types Ægir
60
+ before: async (opts): Promise<RetourAvant> => {
61
+ let relai = undefined;
62
+ if (opts.target.includes("browser")) {
63
+ relai = await lancerRelai();
64
+ }
65
+
66
+ return { relai };
67
+ },
68
+ // @ts-expect-error Erreur types Ægir
69
+ after: async (_opts, avant: RetourAvant) => {
70
+ avant.relai?.();
71
+ },
72
+ browser: {
73
+ config: {
74
+ buildConfig: esbuild,
75
+ },
76
+ },
77
+ },
78
+ build: {
79
+ config: esbuild,
80
+ },
81
+ };
package/src/index.ts CHANGED
@@ -3,5 +3,6 @@ export * as constellation from "@/constellation.js";
3
3
  export * as dossiers from "@/dossiers.js";
4
4
  export * as orbite from "@/orbite.js";
5
5
  export * as sfip from "@/sfip.js";
6
+ export * as config from "@/config.js";
6
7
 
7
8
  export { version } from "@/version.js";
@@ -0,0 +1,3 @@
1
+ export { Buffer } from "buffer";
2
+ // @ts-expect-error Mystère
3
+ export * as process from "process/browser";
@@ -0,0 +1,86 @@
1
+ /*
2
+ La majorité de ce fichier provient d'OrbitDB
3
+
4
+ MIT License
5
+
6
+ Copyright (c) 2019 Haja Networks Oy
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 { yamux } from "@chainsafe/libp2p-yamux";
28
+ import { createLibp2p } from "libp2p";
29
+ import { noise } from "@chainsafe/libp2p-noise";
30
+ import { circuitRelayServer } from "@libp2p/circuit-relay-v2";
31
+ import { webSockets } from "@libp2p/websockets";
32
+ import * as filters from "@libp2p/websockets/filters";
33
+ import { identify } from "@libp2p/identify";
34
+ import { createFromPrivKey } from "@libp2p/peer-id-factory";
35
+ import { unmarshalPrivateKey } from "@libp2p/crypto/keys";
36
+ import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
37
+
38
+ // output of: console.log(server.peerId.privateKey.toString('hex'))
39
+ const relayPrivKey =
40
+ "08011240821cb6bc3d4547fcccb513e82e4d718089f8a166b23ffcd4a436754b6b0774cf07447d1693cd10ce11ef950d7517bad6e9472b41a927cd17fc3fb23f8c70cd99";
41
+ // the peer id of the above key
42
+ // const relayId = '12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE'
43
+
44
+ const encoded = uint8ArrayFromString(relayPrivKey, "hex");
45
+ const privateKey = await unmarshalPrivateKey(encoded);
46
+ const peerId = await createFromPrivKey(privateKey);
47
+
48
+ const relai = await createLibp2p({
49
+ peerId,
50
+ addresses: {
51
+ listen: ["/ip4/0.0.0.0/tcp/12345/ws"],
52
+ },
53
+ transports: [
54
+ webSockets({
55
+ filter: filters.all,
56
+ }),
57
+ ],
58
+ connectionEncryption: [noise()],
59
+ streamMuxers: [yamux()],
60
+ services: {
61
+ identify: identify(),
62
+ relay: circuitRelayServer({
63
+ reservations: {
64
+ maxReservations: 5000,
65
+ reservationTtl: 1000,
66
+ defaultDataLimit: BigInt(1024 * 1024 * 1024),
67
+ },
68
+ }),
69
+ },
70
+ });
71
+
72
+ relai.addEventListener("peer:connect", async (event) => {
73
+ console.log("peer:connect", event.detail);
74
+ });
75
+
76
+ relai.addEventListener("peer:disconnect", async (event) => {
77
+ console.log("peer:disconnect", event.detail);
78
+ relai.peerStore.delete(event.detail);
79
+ });
80
+
81
+ console.log(relai.peerId.toString());
82
+ console.log(
83
+ "p2p addr: ",
84
+ relai.getMultiaddrs().map((ma) => ma.toString()),
85
+ );
86
+ // generates a deterministic address: /ip4/127.0.0.1/tcp/12345/ws/p2p/12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE
package/src/sfip.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { GossipSub } from "@chainsafe/libp2p-gossipsub";
2
+ import type { Multiaddr } from "@multiformats/multiaddr";
2
3
 
3
4
  import { createHelia, type Helia } from "helia";
4
5
  import { bitswap } from "@helia/block-brokers";
@@ -7,7 +8,6 @@ import { MemoryBlockstore } from "blockstore-core";
7
8
  import { LevelBlockstore } from "blockstore-level";
8
9
  import { multiaddr } from "@multiformats/multiaddr";
9
10
  import { WebRTC } from "@multiformats/multiaddr-matcher";
10
- import type { Multiaddr } from "@multiformats/multiaddr";
11
11
 
12
12
  import { isBrowser, isElectronRenderer } from "wherearewe";
13
13
 
@@ -91,3 +91,23 @@ export const toutesConnectées = async (sfips: Helia[]) => {
91
91
  connectés.push(sfip);
92
92
  }
93
93
  };
94
+
95
+ export const constObtFichierRelai = async (): Promise<string> => {
96
+ const path = await import("path");
97
+ const url = await import("url");
98
+ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
99
+
100
+ const fichierRelai = path.join(__dirname, "./scripts/relai.js");
101
+ return fichierRelai;
102
+ };
103
+
104
+ export const lancerRelai = async () => {
105
+ const { $ } = await import("execa");
106
+ const fichierRelai = await constObtFichierRelai();
107
+
108
+ const relai = $`node ${fichierRelai} &`;
109
+ return () => relai.kill();
110
+ };
111
+
112
+ export const adresseRelai =
113
+ "/ip4/127.0.0.1/tcp/12345/ws/p2p/12D3KooWAJjbRkp8FPF5MKgMU53aUTxWkqvDrs4zc1VMbwRwfsbE";
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = "1.1.2";
2
+ export const version = "1.2.0";
@@ -1,3 +0,0 @@
1
- // file: node-globals.js
2
- export const { Buffer } = require("buffer");
3
- export const process = require("process/browser");