@constl/utils-tests 1.6.15 → 2.0.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 -2
- package/dist/attente.d.ts +8 -30
- package/dist/attente.js +101 -141
- package/dist/attente.js.map +1 -1
- package/dist/config.d.ts +4 -1
- package/dist/config.js +4 -4
- package/dist/config.js.map +1 -1
- package/dist/constellation.d.ts +14 -10
- package/dist/constellation.js +24 -42
- package/dist/constellation.js.map +1 -1
- package/dist/dossiers.d.ts +1 -1
- package/dist/dossiers.js +19 -5
- package/dist/dossiers.js.map +1 -1
- package/dist/h/303/251lia.d.ts +11 -0
- package/dist/h/303/251lia.js +38 -0
- package/dist/h/303/251lia.js.map +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/libp2p/config.d.ts +25 -0
- package/dist/{libp2p.js → libp2p/config.js} +47 -56
- package/dist/libp2p/config.js.map +1 -0
- package/dist/libp2p/index.d.ts +3 -0
- package/dist/libp2p/index.js +4 -0
- package/dist/libp2p/index.js.map +1 -0
- package/dist/libp2p/libp2p.d.ts +9 -0
- package/dist/libp2p/libp2p.js +21 -0
- package/dist/libp2p/libp2p.js.map +1 -0
- package/dist/libp2p/utils.d.ts +10 -0
- package/dist/libp2p/utils.js +41 -0
- package/dist/libp2p/utils.js.map +1 -0
- package/dist/orbite.d.ts +7 -21
- package/dist/orbite.js +31 -156
- package/dist/orbite.js.map +1 -1
- package/dist/{scripts/relai.js → relai/bin.js} +12 -17
- package/dist/relai/bin.js.map +1 -0
- package/dist/relai/consts.d.ts +3 -0
- package/dist/relai/consts.js +4 -0
- package/dist/relai/consts.js.map +1 -0
- package/dist/relai/index.d.ts +3 -0
- package/dist/relai/index.js +4 -0
- package/dist/relai/index.js.map +1 -0
- package/dist/relai/relai.d.ts +5 -0
- package/dist/relai/relai.js +29 -0
- package/dist/relai/relai.js.map +1 -0
- package/dist/relai/utils.d.ts +4 -0
- package/dist/relai/utils.js +6 -0
- package/dist/relai/utils.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +5 -0
- package/dist/utils.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +43 -43
- package/renovate.json +10 -4
- package/src/attente.ts +129 -156
- package/src/config.ts +10 -4
- package/src/constellation.ts +38 -58
- package/src/dossiers.ts +18 -6
- package/src/h/303/251lia.ts +61 -0
- package/src/index.ts +24 -8
- package/src/libp2p/config.ts +115 -0
- package/src/libp2p/index.ts +9 -0
- package/src/libp2p/libp2p.ts +41 -0
- package/src/libp2p/utils.ts +59 -0
- package/src/orbite.ts +43 -223
- package/src/{scripts/relai.ts → relai/bin.ts} +11 -17
- package/src/relai/consts.ts +5 -0
- package/src/relai/index.ts +3 -0
- package/src/relai/relai.ts +40 -0
- package/src/relai/utils.ts +14 -0
- package/src/utils.ts +5 -0
- package/src/version.ts +1 -1
- package/dist/libp2p.d.ts +0 -26
- package/dist/libp2p.js.map +0 -1
- package/dist/scripts/relai.js.map +0 -1
- package/dist/sfip.d.ts +0 -13
- package/dist/sfip.js +0 -89
- package/dist/sfip.js.map +0 -1
- package/src/libp2p.ts +0 -112
- package/src/sfip.ts +0 -127
- /package/dist/{scripts/relai.d.ts → relai/bin.d.ts} +0 -0
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,EAAkC,EAAE,EAAE;IAC5E,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACrC,CAAC,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "
|
|
1
|
+
export declare const version = "2.0.0";
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "
|
|
2
|
+
"version": "2.0.0",
|
|
3
3
|
"license": "AGPL-3.0-or-later",
|
|
4
4
|
"name": "@constl/utils-tests",
|
|
5
5
|
"author": "Julien Jean Malard-Adam",
|
|
@@ -20,68 +20,68 @@
|
|
|
20
20
|
"postbuild": "./dist/**/*"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@chainsafe/libp2p-noise": "^16.
|
|
24
|
-
"@chainsafe/libp2p-yamux": "^7.0.
|
|
25
|
-
"@constl/bohr-db": "^1.
|
|
26
|
-
"@constl/ipa": "1.
|
|
27
|
-
"@eslint/js": "^9.
|
|
28
|
-
"@libp2p/circuit-relay-v2": "^3.
|
|
29
|
-
"@libp2p/crypto": "^5.
|
|
30
|
-
"@libp2p/identify": "^3.0.
|
|
31
|
-
"@libp2p/interface": "^2.5
|
|
32
|
-
"@libp2p/websockets": "^9.
|
|
33
|
-
"@multiformats/multiaddr": "^12.
|
|
34
|
-
"@multiformats/multiaddr-matcher": "^
|
|
35
|
-
"@orbitdb/core-types": "^1.0
|
|
36
|
-
"@orbitdb/feed-db": "^1.
|
|
23
|
+
"@chainsafe/libp2p-noise": "^16.1.4",
|
|
24
|
+
"@chainsafe/libp2p-yamux": "^7.0.4",
|
|
25
|
+
"@constl/bohr-db": "^1.3.1",
|
|
26
|
+
"@constl/ipa": "1.6.24",
|
|
27
|
+
"@eslint/js": "^9.32.0",
|
|
28
|
+
"@libp2p/circuit-relay-v2": "^3.2.23",
|
|
29
|
+
"@libp2p/crypto": "^5.1.7",
|
|
30
|
+
"@libp2p/identify": "^3.0.38",
|
|
31
|
+
"@libp2p/interface": "^2.10.5",
|
|
32
|
+
"@libp2p/websockets": "^9.2.18",
|
|
33
|
+
"@multiformats/multiaddr": "^12.5.1",
|
|
34
|
+
"@multiformats/multiaddr-matcher": "^2.0.2",
|
|
35
|
+
"@orbitdb/core-types": "^1.2.0",
|
|
36
|
+
"@orbitdb/feed-db": "^1.3.0",
|
|
37
37
|
"@types/crypto-js": "^4.2.2",
|
|
38
38
|
"@types/file-saver": "^2.0.7",
|
|
39
39
|
"@types/mocha": "^10.0.10",
|
|
40
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^24.1.0",
|
|
41
41
|
"@types/uuid": "^10.0.0",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
43
|
-
"@typescript-eslint/parser": "^8.
|
|
44
|
-
"aegir": "^
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
43
|
+
"@typescript-eslint/parser": "^8.38.0",
|
|
44
|
+
"aegir": "^47.0.20",
|
|
45
45
|
"ajv": "^8.17.1",
|
|
46
46
|
"buffer": "^6.0.3",
|
|
47
|
-
"core-js": "^3.
|
|
48
|
-
"electron": "^
|
|
49
|
-
"esbuild": "^0.
|
|
50
|
-
"eslint": "^9.
|
|
47
|
+
"core-js": "^3.44.0",
|
|
48
|
+
"electron": "^37.2.4",
|
|
49
|
+
"esbuild": "^0.25.8",
|
|
50
|
+
"eslint": "^9.32.0",
|
|
51
51
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
52
|
-
"eslint-config-prettier": "^10.
|
|
52
|
+
"eslint-config-prettier": "^10.1.8",
|
|
53
53
|
"eslint-config-standard": "^17.1.0",
|
|
54
|
-
"eslint-plugin-import": "^2.
|
|
55
|
-
"eslint-plugin-n": "^17.
|
|
54
|
+
"eslint-plugin-import": "^2.32.0",
|
|
55
|
+
"eslint-plugin-n": "^17.21.3",
|
|
56
56
|
"eslint-plugin-promise": "^7.2.1",
|
|
57
|
-
"execa": "^9.
|
|
58
|
-
"mocha": "^11.1
|
|
59
|
-
"playwright": "^1.
|
|
60
|
-
"prettier": "^3.
|
|
57
|
+
"execa": "^9.6.0",
|
|
58
|
+
"mocha": "^11.7.1",
|
|
59
|
+
"playwright": "^1.54.1",
|
|
60
|
+
"prettier": "^3.6.2",
|
|
61
61
|
"progress-events": "^1.0.1",
|
|
62
62
|
"source-map-support": "^0.5.21",
|
|
63
63
|
"ts-patch": "^3.3.0",
|
|
64
64
|
"tsconfig-paths": "^4.2.0",
|
|
65
65
|
"tscpaths": "^0.0.9",
|
|
66
|
-
"typescript": "5.
|
|
67
|
-
"typescript-eslint": "^8.
|
|
68
|
-
"typescript-transform-paths": "^3.5.
|
|
66
|
+
"typescript": "5.8.3",
|
|
67
|
+
"typescript-eslint": "^8.38.0",
|
|
68
|
+
"typescript-transform-paths": "^3.5.5"
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@chainsafe/libp2p-gossipsub": "14.1.
|
|
72
|
-
"@helia/block-brokers": "^4.
|
|
73
|
-
"@libp2p/peer-id": "^5.
|
|
74
|
-
"@libp2p/webrtc": "^5.
|
|
75
|
-
"@orbitdb/core": "^
|
|
76
|
-
"blockstore-core": "^5.0.
|
|
77
|
-
"blockstore-level": "^2.0.
|
|
71
|
+
"@chainsafe/libp2p-gossipsub": "14.1.1",
|
|
72
|
+
"@helia/block-brokers": "^4.2.3",
|
|
73
|
+
"@libp2p/peer-id": "^5.1.8",
|
|
74
|
+
"@libp2p/webrtc": "^5.2.23",
|
|
75
|
+
"@orbitdb/core": "^3.0.2",
|
|
76
|
+
"blockstore-core": "^5.0.4",
|
|
77
|
+
"blockstore-level": "^2.0.3",
|
|
78
78
|
"browserify-fs": "^1.0.0",
|
|
79
79
|
"chokidar": "^4.0.3",
|
|
80
80
|
"crypto-browserify": "^3.12.1",
|
|
81
81
|
"events": "^3.3.0",
|
|
82
82
|
"genversion": "^3.2.0",
|
|
83
|
-
"helia": "5.
|
|
84
|
-
"libp2p": "^2.
|
|
83
|
+
"helia": "5.5.0",
|
|
84
|
+
"libp2p": "^2.9.0",
|
|
85
85
|
"os-browserify": "^0.3.0",
|
|
86
86
|
"process": "^0.11.10",
|
|
87
87
|
"read-package-up": "^11.0.0",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"stream-browserify": "^3.0.0",
|
|
90
90
|
"uint8arrays": "^5.1.0",
|
|
91
91
|
"url-polyfill": "^1.1.13",
|
|
92
|
-
"uuid": "^11.0
|
|
92
|
+
"uuid": "^11.1.0",
|
|
93
93
|
"wherearewe": "^2.0.1"
|
|
94
94
|
},
|
|
95
95
|
"scripts": {
|
package/renovate.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
-
"extends": ["config:
|
|
3
|
+
"extends": ["config:recommended"],
|
|
4
4
|
"packageRules": [
|
|
5
5
|
{
|
|
6
6
|
"matchDepTypes": ["devDependencies"],
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"automerge": true
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"automerge": true,
|
|
16
|
+
"matchPackageNames": ["/^actions//"]
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"description": "Regrouper les librairies @constl.",
|
|
@@ -27,7 +27,13 @@
|
|
|
27
27
|
"groupName": "Libp2p et Helia",
|
|
28
28
|
"groupSlug": "libp2p-helia-node",
|
|
29
29
|
"matchDatasources": ["npm"],
|
|
30
|
-
"matchPackageNames": [
|
|
30
|
+
"matchPackageNames": [
|
|
31
|
+
"@libp2p/**",
|
|
32
|
+
"@chainsafe/**",
|
|
33
|
+
"@helia/**",
|
|
34
|
+
"libp2p",
|
|
35
|
+
"helia"
|
|
36
|
+
]
|
|
31
37
|
}
|
|
32
38
|
]
|
|
33
39
|
}
|
package/src/attente.ts
CHANGED
|
@@ -1,165 +1,138 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.oublier(id);
|
|
30
|
-
résoudre(this.val);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
this.événements.on("changé", fLorsqueChangé);
|
|
34
|
-
this.fsOublier[id] = () => this.événements.off("changé", fLorsqueChangé);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async attendreExiste(): Promise<T> {
|
|
39
|
-
const val = (await this.attendreQue((x) => !!x)) as T;
|
|
40
|
-
return val;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async attendreNexistePas(): Promise<void> {
|
|
44
|
-
if (this.val === undefined) return;
|
|
45
|
-
|
|
46
|
-
const id = uuidv4();
|
|
47
|
-
|
|
48
|
-
return new Promise((résoudre) => {
|
|
49
|
-
const fLorsqueChangé = async () => {
|
|
50
|
-
if (this.val === undefined) {
|
|
51
|
-
this.oublier(id);
|
|
52
|
-
résoudre();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
this.événements.on("changé", fLorsqueChangé);
|
|
56
|
-
this.fsOublier[id] = () => this.événements.off("changé", fLorsqueChangé);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
oublier(id: string) {
|
|
61
|
-
this.fsOublier[id]();
|
|
62
|
-
delete this.fsOublier[id];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
toutAnnuler() {
|
|
66
|
-
Object.keys(this.fsOublier).forEach((id) => this.oublier(id));
|
|
1
|
+
import { isBrowser, isElectronRenderer } from "wherearewe";
|
|
2
|
+
|
|
3
|
+
export const que = async <T>(
|
|
4
|
+
f: () => T | Promise<T | undefined>,
|
|
5
|
+
t = 100,
|
|
6
|
+
): Promise<T> => {
|
|
7
|
+
return new Promise<T>((résoudre) => {
|
|
8
|
+
const testF = async () => {
|
|
9
|
+
const résultat = await f();
|
|
10
|
+
if (résultat !== undefined) {
|
|
11
|
+
résoudre(résultat);
|
|
12
|
+
} else {
|
|
13
|
+
setTimeout(testF, t);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
testF();
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const attendreFichierExiste = async ({
|
|
21
|
+
fichier,
|
|
22
|
+
signal,
|
|
23
|
+
}: {
|
|
24
|
+
fichier: string;
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
}): Promise<boolean> => {
|
|
27
|
+
if (isBrowser || isElectronRenderer) {
|
|
28
|
+
throw new Error("Test non disponible dans le navigateur.");
|
|
67
29
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
30
|
+
const chokidar = await import("chokidar");
|
|
31
|
+
const fs = await import("fs");
|
|
32
|
+
const path = await import("path");
|
|
33
|
+
|
|
34
|
+
return new Promise<boolean>((résoudre) => {
|
|
35
|
+
// Arrêter tout de suite si le fichier existe déjà
|
|
36
|
+
if (fs.existsSync(fichier)) résoudre(true);
|
|
37
|
+
|
|
38
|
+
// Actions signal
|
|
39
|
+
const lorsqueAvorté = () => {
|
|
40
|
+
fermerEtRésoudre(false);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Actions écouteur de fichiers
|
|
44
|
+
const dossier = path.dirname(fichier);
|
|
45
|
+
const écouteur = chokidar.watch(dossier);
|
|
46
|
+
const fermerÉcouteur = async () => await écouteur.close();
|
|
47
|
+
|
|
48
|
+
const lorsquFichierAjouté = () => {
|
|
49
|
+
if (fs.existsSync(fichier)) {
|
|
50
|
+
fermerEtRésoudre(true);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Fermeture des écouteurs
|
|
55
|
+
const fermerEtRésoudre = async (statut: boolean) => {
|
|
56
|
+
signal?.removeEventListener("abort", lorsqueAvorté);
|
|
57
|
+
écouteur.off("add", lorsquFichierAjouté);
|
|
58
|
+
await fermerÉcouteur();
|
|
59
|
+
|
|
60
|
+
résoudre(statut);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
signal?.addEventListener("abort", lorsqueAvorté);
|
|
64
|
+
|
|
65
|
+
écouteur.on("add", lorsquFichierAjouté);
|
|
66
|
+
if (signal?.aborted) fermerEtRésoudre(false);
|
|
67
|
+
|
|
68
|
+
if (fs.existsSync(fichier)) fermerEtRésoudre(true);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const attendreFichierModifié = async ({
|
|
73
|
+
fichier,
|
|
74
|
+
condition,
|
|
75
|
+
signal,
|
|
76
|
+
}: {
|
|
72
77
|
fichier: string;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
condition?: () => Promise<boolean>;
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
}) => {
|
|
81
|
+
if (isBrowser || isElectronRenderer) {
|
|
82
|
+
throw new Error("Test non disponible dans le navigateur.");
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
await attendreFichierExiste({ fichier, signal });
|
|
86
|
+
const tempsAvant = Date.now();
|
|
87
|
+
|
|
88
|
+
const chokidar = await import("chokidar");
|
|
89
|
+
const fs = await import("fs");
|
|
90
|
+
|
|
91
|
+
return new Promise((résoudre) => {
|
|
92
|
+
// Actions signal
|
|
93
|
+
const lorsqueAvorté = () => {
|
|
94
|
+
fermerEtRésoudre(false);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Actions écouteur de fichiers
|
|
98
|
+
const écouteur = chokidar.watch(fichier);
|
|
99
|
+
const fermerÉcouteur = async () => await écouteur.close();
|
|
100
|
+
const lorsqueModifié = async (adresse: string) => {
|
|
101
|
+
if (adresse !== fichier) return;
|
|
102
|
+
await vérifierModifié();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const fermerEtRésoudre = async (statut: boolean) => {
|
|
106
|
+
clearInterval(intervale);
|
|
107
|
+
signal?.removeEventListener("abort", lorsqueAvorté);
|
|
108
|
+
écouteur.off("change", lorsqueModifié);
|
|
109
|
+
await fermerÉcouteur();
|
|
110
|
+
|
|
111
|
+
résoudre(statut);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const vérifierModifié = async () => {
|
|
115
|
+
try {
|
|
116
|
+
const { mtime } = fs.statSync(fichier);
|
|
117
|
+
const prêt = mtime.getTime() > tempsAvant;
|
|
118
|
+
|
|
119
|
+
if (prêt && (!condition || (await condition()))) {
|
|
120
|
+
fermerEtRésoudre(true);
|
|
102
121
|
}
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
|
|
122
|
+
} catch (e) {
|
|
123
|
+
// Le fichier a été effacé
|
|
124
|
+
await fermerEtRésoudre(false);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
106
127
|
|
|
107
|
-
|
|
108
|
-
this.fOublier?.();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
128
|
+
signal?.addEventListener("abort", lorsqueAvorté);
|
|
111
129
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
fichier: string;
|
|
115
|
-
attendreExiste: AttendreFichierExiste;
|
|
116
|
-
|
|
117
|
-
constructor(fichier: string) {
|
|
118
|
-
super();
|
|
119
|
-
this.fichier = fichier;
|
|
120
|
-
this.attendreExiste = new AttendreFichierExiste(fichier);
|
|
121
|
-
this.fsOublier = [];
|
|
122
|
-
this.fsOublier.push(() => this.attendreExiste.annuler());
|
|
123
|
-
}
|
|
130
|
+
écouteur.on("change", lorsqueModifié);
|
|
131
|
+
écouteur.on("unlink", lorsqueModifié);
|
|
124
132
|
|
|
125
|
-
|
|
126
|
-
tempsAvant: number,
|
|
127
|
-
condition?: () => Promise<boolean>,
|
|
128
|
-
): Promise<void> {
|
|
129
|
-
await this.attendreExiste.attendre();
|
|
130
|
-
const chokidar = await import("chokidar");
|
|
131
|
-
const fs = await import("fs");
|
|
132
|
-
return new Promise((résoudre, rejeter) => {
|
|
133
|
-
const écouteur = chokidar.watch(this.fichier);
|
|
134
|
-
this.fsOublier.push(() => écouteur.close());
|
|
135
|
-
|
|
136
|
-
const vérifierModifié = async () => {
|
|
137
|
-
try {
|
|
138
|
-
const { mtime } = fs.statSync(this.fichier);
|
|
139
|
-
const prêt = mtime.getTime() > tempsAvant;
|
|
140
|
-
|
|
141
|
-
if (prêt && (!condition || (await condition()))) {
|
|
142
|
-
await écouteur.close();
|
|
143
|
-
clearInterval(intervale);
|
|
144
|
-
résoudre();
|
|
145
|
-
}
|
|
146
|
-
} catch (e) {
|
|
147
|
-
// Le fichier a été effacé
|
|
148
|
-
écouteur.close();
|
|
149
|
-
rejeter(e);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
écouteur.on("change", async (adresse) => {
|
|
154
|
-
if (adresse !== this.fichier) return;
|
|
155
|
-
await vérifierModifié();
|
|
156
|
-
});
|
|
157
|
-
// Parfois, on dirait que chokidar ne détecte pas l'événement...
|
|
158
|
-
const intervale = setInterval(vérifierModifié, 1000);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
133
|
+
if (signal?.aborted) fermerEtRésoudre(false);
|
|
161
134
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
}
|
|
135
|
+
// Parfois, on dirait que chokidar ne détecte pas l'événement...
|
|
136
|
+
const intervale = setInterval(vérifierModifié, 1000);
|
|
137
|
+
});
|
|
138
|
+
};
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PartialOptions } from "aegir";
|
|
2
2
|
import type { BuildOptions } from "esbuild";
|
|
3
3
|
|
|
4
|
-
import { lancerRelai } from "./
|
|
4
|
+
import { lancerRelai } from "./relai/index.js";
|
|
5
5
|
|
|
6
6
|
export const obtConfigEsbuild = async (): Promise<BuildOptions> => {
|
|
7
7
|
const { createRequire } = (await import("module")).default;
|
|
@@ -11,7 +11,7 @@ export const obtConfigEsbuild = async (): Promise<BuildOptions> => {
|
|
|
11
11
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
12
12
|
const require = createRequire(import.meta.url);
|
|
13
13
|
const configEsbuild: BuildOptions = {
|
|
14
|
-
//
|
|
14
|
+
// ceci injecte les exportations nomées de 'node-globals.js' en tant que variables globales
|
|
15
15
|
inject: [path.join(__dirname, "./scripts/node-globals.js")],
|
|
16
16
|
plugins: [
|
|
17
17
|
{
|
|
@@ -64,7 +64,13 @@ type RetourAvant = {
|
|
|
64
64
|
relai?: () => void;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
export const générerConfigÆgir = async (
|
|
67
|
+
export const générerConfigÆgir = async ({
|
|
68
|
+
portDéfautRelai,
|
|
69
|
+
clefPrivéeRelai,
|
|
70
|
+
}: {
|
|
71
|
+
portDéfautRelai?: string;
|
|
72
|
+
clefPrivéeRelai?: string;
|
|
73
|
+
} = {}): Promise<PartialOptions> => {
|
|
68
74
|
const esbuild = await obtConfigEsbuild();
|
|
69
75
|
return {
|
|
70
76
|
test: {
|
|
@@ -72,7 +78,7 @@ export const générerConfigÆgir = async (): Promise<PartialOptions> => {
|
|
|
72
78
|
before: async (opts): Promise<RetourAvant> => {
|
|
73
79
|
let relai = undefined;
|
|
74
80
|
if (opts.target.includes("browser")) {
|
|
75
|
-
relai = await lancerRelai();
|
|
81
|
+
relai = await lancerRelai({ portDéfautRelai, clefPrivéeRelai });
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
return { relai };
|
package/src/constellation.ts
CHANGED
|
@@ -1,78 +1,58 @@
|
|
|
1
|
-
import type { réseau, client, Constellation } from "@constl/ipa";
|
|
2
|
-
import type { OrbitDB } from "@orbitdb/core";
|
|
3
1
|
import { isBrowser } from "wherearewe";
|
|
2
|
+
import { créerOrbitesTest } from "./orbite.js";
|
|
3
|
+
import { dossierTempo } from "./dossiers.js";
|
|
4
|
+
import { OrbitDB } from "@orbitdb/core";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
interface InterfaceConstellation {
|
|
7
|
+
fermer: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface OptionsConstellation {
|
|
11
|
+
dossier?: string;
|
|
12
|
+
orbite?: OrbitDB;
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
export const créerConstellationsTest = async <
|
|
10
|
-
T
|
|
11
|
-
U = client.optsConstellation,
|
|
16
|
+
T extends InterfaceConstellation,
|
|
12
17
|
>({
|
|
13
18
|
n = 1,
|
|
14
19
|
créerConstellation,
|
|
20
|
+
dossier,
|
|
15
21
|
}: {
|
|
16
22
|
n: number;
|
|
17
|
-
créerConstellation: (opts:
|
|
23
|
+
créerConstellation: (opts: OptionsConstellation) => T;
|
|
24
|
+
dossier?: string;
|
|
18
25
|
}): Promise<{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
fOublier: () => Promise<void>;
|
|
26
|
+
constls: T[];
|
|
27
|
+
fermer: () => Promise<void>;
|
|
22
28
|
}> => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (isBrowser) window.localStorage.clear();
|
|
29
|
+
let effacerDossier: () => void = () => {};
|
|
30
|
+
if (!dossier) {
|
|
31
|
+
({ dossier, effacer: effacerDossier } = await dossierTempo());
|
|
32
|
+
}
|
|
28
33
|
|
|
29
|
-
const { orbites,
|
|
30
|
-
|
|
34
|
+
const { orbites, fermer: fermerOrbites } = await créerOrbitesTest({
|
|
35
|
+
n,
|
|
36
|
+
dossier,
|
|
37
|
+
});
|
|
31
38
|
|
|
39
|
+
const constls: T[] = [];
|
|
32
40
|
for (const i in [...Array(n).keys()]) {
|
|
33
|
-
const
|
|
41
|
+
const constl = créerConstellation({
|
|
34
42
|
orbite: orbites[i],
|
|
35
|
-
dossier
|
|
36
|
-
}
|
|
37
|
-
|
|
43
|
+
dossier,
|
|
44
|
+
});
|
|
45
|
+
constls.push(constl);
|
|
38
46
|
}
|
|
39
47
|
|
|
40
|
-
const
|
|
41
|
-
for (const
|
|
42
|
-
await Promise.all(fsOublier.map((f) => f()));
|
|
43
|
-
};
|
|
44
|
-
return { fOublier, clients, orbites };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const constellationConnectéeÀ = async (
|
|
48
|
-
constellation: client.Constellation,
|
|
49
|
-
connectéeÀ: client.Constellation,
|
|
50
|
-
): Promise<void> => {
|
|
51
|
-
const dispositifsConnectés = new AttendreRésultat<
|
|
52
|
-
réseau.statutDispositif[]
|
|
53
|
-
>();
|
|
54
|
-
const idCompte2 = await connectéeÀ.obtIdCompte();
|
|
48
|
+
const fermer = async () => {
|
|
49
|
+
for (const constl of constls) await constl.fermer();
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
await dispositifsConnectés.attendreQue((dispositifs) => {
|
|
60
|
-
return !!dispositifs.find((d) => d.infoDispositif.idCompte === idCompte2);
|
|
61
|
-
});
|
|
62
|
-
await fOublier();
|
|
63
|
-
return;
|
|
64
|
-
};
|
|
51
|
+
await fermerOrbites();
|
|
52
|
+
effacerDossier();
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const promesses: Promise<void>[] = [];
|
|
71
|
-
for (let i = 1; i < clients.length; i++) {
|
|
72
|
-
for (let j = 0; j < i; j++) {
|
|
73
|
-
promesses.push(constellationConnectéeÀ(clients[i], clients[j]));
|
|
74
|
-
promesses.push(constellationConnectéeÀ(clients[j], clients[i]));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
await Promise.all(promesses);
|
|
54
|
+
// Nécessaire pour Playwright
|
|
55
|
+
if (isBrowser) window.localStorage.clear();
|
|
56
|
+
};
|
|
57
|
+
return { constls, fermer };
|
|
78
58
|
};
|