@constl/utils-tests 1.1.1-f631113.0 → 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/.aegir.js +2 -74
- package/dist/src/config.d.ts +2 -0
- package/dist/src/config.js +72 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/orbite.js +14 -2
- package/dist/src/orbite.js.map +1 -1
- package/dist/src/scripts/node-globals.d.ts +3 -0
- package/dist/src/scripts/node-globals.js +4 -0
- package/dist/src/scripts/node-globals.js.map +1 -0
- package/dist/src/scripts/relai.d.ts +1 -0
- package/dist/src/scripts/relai.js +76 -0
- package/dist/src/scripts/relai.js.map +1 -0
- package/dist/src/sfip.d.ts +3 -0
- package/dist/src/sfip.js +14 -0
- package/dist/src/sfip.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +34 -33
- package/src/config.ts +81 -0
- package/src/index.ts +1 -0
- package/src/orbite.ts +6 -4
- package/src/scripts/node-globals.ts +3 -0
- package/src/scripts/relai.ts +86 -0
- package/src/sfip.ts +21 -1
- package/src/version.ts +1 -1
- package/scripts/node-globals.js +0 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
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",
|
|
@@ -9,19 +9,6 @@
|
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=20"
|
|
11
11
|
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"nettoyer": "rimraf dist",
|
|
14
|
-
"compiler": "pnpm versioner && pnpm formatter && pnpm nettoyer && pnpm tspc -p tsconfig.build.json",
|
|
15
|
-
"test:node": "pnpm compiler && pnpm aegir test -t node --cov -- --exit",
|
|
16
|
-
"test:navig": "pnpm compiler && pnpm webrtc && pnpm aegir test -t browser --cov",
|
|
17
|
-
"test:électron-principal": "pnpm compiler && pnpm aegir test -t electron-main --cov",
|
|
18
|
-
"test:électron-rendu": "pnpm compiler && pnpm webrtc && pnpm aegir test -t electron-renderer --cov",
|
|
19
|
-
"test": "pnpm test:node && pnpm test:navig",
|
|
20
|
-
"formatter": "pnpm prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\" && pnpm eslint --ext .js,.ts src",
|
|
21
|
-
"publier": "pnpm versioner && pnpm compiler && (git commit -a -m 'version' || true) && pnpm publish",
|
|
22
|
-
"versioner": "pnpm genversion --es6 --semi src/version.ts",
|
|
23
|
-
"webrtc": "node ./test/utils/relai.js &"
|
|
24
|
-
},
|
|
25
12
|
"watch": {
|
|
26
13
|
"build": {
|
|
27
14
|
"patterns": "./src/**/*",
|
|
@@ -33,30 +20,31 @@
|
|
|
33
20
|
"postbuild": "./dist/**/*"
|
|
34
21
|
},
|
|
35
22
|
"devDependencies": {
|
|
36
|
-
"@chainsafe/libp2p-gossipsub": "^
|
|
23
|
+
"@chainsafe/libp2p-gossipsub": "^12.0.0",
|
|
37
24
|
"@chainsafe/libp2p-noise": "^15.0.0",
|
|
38
|
-
"@chainsafe/libp2p-yamux": "^6.0.
|
|
39
|
-
"@constl/ipa": "1.0.
|
|
40
|
-
"@libp2p/circuit-relay-v2": "^1.0.
|
|
41
|
-
"@libp2p/crypto": "^4.0.
|
|
42
|
-
"@libp2p/identify": "^1.0.
|
|
43
|
-
"@libp2p/peer-id-factory": "^4.0.
|
|
44
|
-
"@libp2p/websockets": "^8.0.
|
|
25
|
+
"@chainsafe/libp2p-yamux": "^6.0.2",
|
|
26
|
+
"@constl/ipa": "1.0.0",
|
|
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",
|
|
45
32
|
"@multiformats/multiaddr": "^12.1.14",
|
|
46
33
|
"@multiformats/multiaddr-matcher": "^1.1.2",
|
|
47
34
|
"@orbitdb/feed-db": "^1.0.0",
|
|
48
35
|
"@types/crypto-js": "^4.2.2",
|
|
49
36
|
"@types/file-saver": "^2.0.7",
|
|
50
37
|
"@types/mocha": "^10.0.6",
|
|
51
|
-
"@types/node": "^20.11.
|
|
38
|
+
"@types/node": "^20.11.19",
|
|
52
39
|
"@types/uuid": "^9.0.8",
|
|
53
40
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
54
41
|
"@typescript-eslint/parser": "^6.21.0",
|
|
55
|
-
"aegir": "^42.2.
|
|
42
|
+
"aegir": "^42.2.4",
|
|
56
43
|
"browserify-fs": "^1.0.0",
|
|
57
44
|
"buffer": "^6.0.3",
|
|
58
|
-
"core-js": "^3.
|
|
45
|
+
"core-js": "^3.36.0",
|
|
59
46
|
"crypto-browserify": "^3.12.0",
|
|
47
|
+
"esbuild": "^0.20.1",
|
|
60
48
|
"eslint": "^8.56.0",
|
|
61
49
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
62
50
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -67,7 +55,7 @@
|
|
|
67
55
|
"execa": "^8.0.1",
|
|
68
56
|
"file-saver": "^2.0.5",
|
|
69
57
|
"keys": "link:@libp2p/crypto/keys",
|
|
70
|
-
"mocha": "^10.
|
|
58
|
+
"mocha": "^10.3.0",
|
|
71
59
|
"os-browserify": "^0.3.0",
|
|
72
60
|
"playwright": "^1.41.2",
|
|
73
61
|
"prettier": "^3.2.5",
|
|
@@ -78,21 +66,34 @@
|
|
|
78
66
|
"tsconfig-paths": "^4.2.0",
|
|
79
67
|
"tscpaths": "^0.0.9",
|
|
80
68
|
"typescript": "5.3.3",
|
|
81
|
-
"typescript-transform-paths": "^3.4.
|
|
69
|
+
"typescript-transform-paths": "^3.4.7"
|
|
82
70
|
},
|
|
83
71
|
"dependencies": {
|
|
84
72
|
"@helia/block-brokers": "^2.0.1",
|
|
85
73
|
"@orbitdb/quickstart": "^1.0.0",
|
|
86
|
-
"blockstore-core": "^4.
|
|
87
|
-
"blockstore-level": "^1.1.
|
|
88
|
-
"chokidar": "^3.
|
|
74
|
+
"blockstore-core": "^4.4.0",
|
|
75
|
+
"blockstore-level": "^1.1.8",
|
|
76
|
+
"chokidar": "^3.6.0",
|
|
89
77
|
"events": "^3.3.0",
|
|
90
78
|
"genversion": "^3.2.0",
|
|
91
79
|
"helia": "^3.0.1",
|
|
92
|
-
"libp2p": "^1.2.
|
|
80
|
+
"libp2p": "^1.2.3",
|
|
81
|
+
"read-package-up": "^11.0.0",
|
|
93
82
|
"rimraf": "^5.0.5",
|
|
94
|
-
"uint8arrays": "^5.0.
|
|
83
|
+
"uint8arrays": "^5.0.2",
|
|
95
84
|
"uuid": "^9.0.1",
|
|
96
85
|
"wherearewe": "^2.0.1"
|
|
86
|
+
},
|
|
87
|
+
"scripts": {
|
|
88
|
+
"nettoyer": "rimraf dist",
|
|
89
|
+
"compiler": "pnpm versioner && pnpm formatter && pnpm nettoyer && pnpm tspc -p tsconfig.build.json",
|
|
90
|
+
"test:node": "pnpm compiler && pnpm aegir test -t node --cov -- --exit",
|
|
91
|
+
"test:navig": "pnpm compiler && pnpm aegir test -t browser --cov",
|
|
92
|
+
"test:électron-principal": "pnpm compiler && pnpm aegir test -t electron-main --cov",
|
|
93
|
+
"test:électron-rendu": "pnpm compiler && pnpm aegir test -t electron-renderer --cov",
|
|
94
|
+
"test": "pnpm test:node && pnpm test:navig",
|
|
95
|
+
"formatter": "pnpm prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\" && pnpm eslint --ext .js,.ts src",
|
|
96
|
+
"publier": "pnpm versioner && pnpm compiler && (git commit -a -m 'version' || true) && pnpm publish",
|
|
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
package/src/orbite.ts
CHANGED
|
@@ -36,8 +36,7 @@ import { once } from "events";
|
|
|
36
36
|
|
|
37
37
|
import { dossierTempo } from "@/dossiers.js";
|
|
38
38
|
import { connecterPairs } from "@/sfip.js";
|
|
39
|
-
import { isNode } from "wherearewe
|
|
40
|
-
import { isElectronMain } from "wherearewe/dist/src";
|
|
39
|
+
import { isNode, isElectronMain } from "wherearewe";
|
|
41
40
|
|
|
42
41
|
const OrbitDBQuickstart = await import("@orbitdb/quickstart");
|
|
43
42
|
const { startOrbitDB, stopOrbitDB } = OrbitDBQuickstart;
|
|
@@ -77,8 +76,11 @@ export const créerOrbiteTest = async ({
|
|
|
77
76
|
fEffacerRacineDossierOrbite();
|
|
78
77
|
} catch (e) {
|
|
79
78
|
// Sur Windows, parfois les fichiers de Hélia sont encore en utilisation
|
|
80
|
-
if (
|
|
81
|
-
|
|
79
|
+
if ((isNode || isElectronMain) && process.platform === "win32") {
|
|
80
|
+
console.log("On ignore ça sur Windows\n", e);
|
|
81
|
+
return;
|
|
82
|
+
} else {
|
|
83
|
+
throw e;
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
};
|
|
@@ -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.
|
|
2
|
+
export const version = "1.2.0";
|
package/scripts/node-globals.js
DELETED