@constl/utils-tests 1.7.0 → 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.
Files changed (81) hide show
  1. package/.aegir.js +2 -2
  2. package/dist/attente.d.ts +8 -30
  3. package/dist/attente.js +101 -141
  4. package/dist/attente.js.map +1 -1
  5. package/dist/config.d.ts +4 -1
  6. package/dist/config.js +4 -4
  7. package/dist/config.js.map +1 -1
  8. package/dist/constellation.d.ts +14 -10
  9. package/dist/constellation.js +24 -43
  10. package/dist/constellation.js.map +1 -1
  11. package/dist/dossiers.d.ts +1 -1
  12. package/dist/dossiers.js +19 -5
  13. package/dist/dossiers.js.map +1 -1
  14. package/dist/h/303/251lia.d.ts +11 -0
  15. package/dist/h/303/251lia.js +38 -0
  16. package/dist/h/303/251lia.js.map +1 -0
  17. package/dist/index.d.ts +8 -8
  18. package/dist/index.js +8 -8
  19. package/dist/index.js.map +1 -1
  20. package/dist/libp2p/config.d.ts +25 -0
  21. package/dist/{libp2p.js → libp2p/config.js} +47 -56
  22. package/dist/libp2p/config.js.map +1 -0
  23. package/dist/libp2p/index.d.ts +3 -0
  24. package/dist/libp2p/index.js +4 -0
  25. package/dist/libp2p/index.js.map +1 -0
  26. package/dist/libp2p/libp2p.d.ts +9 -0
  27. package/dist/libp2p/libp2p.js +21 -0
  28. package/dist/libp2p/libp2p.js.map +1 -0
  29. package/dist/libp2p/utils.d.ts +10 -0
  30. package/dist/libp2p/utils.js +41 -0
  31. package/dist/libp2p/utils.js.map +1 -0
  32. package/dist/orbite.d.ts +7 -23
  33. package/dist/orbite.js +31 -154
  34. package/dist/orbite.js.map +1 -1
  35. package/dist/{scripts/relai.js → relai/bin.js} +12 -16
  36. package/dist/relai/bin.js.map +1 -0
  37. package/dist/relai/consts.d.ts +3 -0
  38. package/dist/relai/consts.js +4 -0
  39. package/dist/relai/consts.js.map +1 -0
  40. package/dist/relai/index.d.ts +3 -0
  41. package/dist/relai/index.js +4 -0
  42. package/dist/relai/index.js.map +1 -0
  43. package/dist/relai/relai.d.ts +5 -0
  44. package/dist/relai/relai.js +29 -0
  45. package/dist/relai/relai.js.map +1 -0
  46. package/dist/relai/utils.d.ts +4 -0
  47. package/dist/relai/utils.js +6 -0
  48. package/dist/relai/utils.js.map +1 -0
  49. package/dist/tsconfig.build.tsbuildinfo +1 -1
  50. package/dist/utils.d.ts +4 -0
  51. package/dist/utils.js +5 -0
  52. package/dist/utils.js.map +1 -0
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.js +1 -1
  55. package/package.json +1 -1
  56. package/src/attente.ts +129 -156
  57. package/src/config.ts +10 -4
  58. package/src/constellation.ts +39 -60
  59. package/src/dossiers.ts +18 -6
  60. package/src/h/303/251lia.ts +61 -0
  61. package/src/index.ts +28 -8
  62. package/src/{libp2p.ts → libp2p/config.ts} +66 -71
  63. package/src/libp2p/index.ts +9 -0
  64. package/src/libp2p/libp2p.ts +41 -0
  65. package/src/libp2p/utils.ts +59 -0
  66. package/src/orbite.ts +43 -228
  67. package/src/{scripts/relai.ts → relai/bin.ts} +11 -16
  68. package/src/relai/consts.ts +5 -0
  69. package/src/relai/index.ts +3 -0
  70. package/src/relai/relai.ts +40 -0
  71. package/src/relai/utils.ts +14 -0
  72. package/src/utils.ts +5 -0
  73. package/src/version.ts +1 -1
  74. package/dist/libp2p.d.ts +0 -26
  75. package/dist/libp2p.js.map +0 -1
  76. package/dist/scripts/relai.js.map +0 -1
  77. package/dist/sfip.d.ts +0 -13
  78. package/dist/sfip.js +0 -89
  79. package/dist/sfip.js.map +0 -1
  80. package/src/sfip.ts +0 -127
  81. /package/dist/{scripts/relai.d.ts → relai/bin.d.ts} +0 -0
@@ -0,0 +1,4 @@
1
+ export declare const sousDossier: ({ dossier, i }: {
2
+ dossier: string;
3
+ i: number;
4
+ }) => string;
package/dist/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ import { join } from "path";
2
+ export const sousDossier = ({ dossier, i }) => {
3
+ return join(dossier, i.toString());
4
+ };
5
+ //# sourceMappingURL=utils.js.map
@@ -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.7.0";
1
+ export declare const version = "2.0.1";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated by genversion.
2
- export const version = "1.7.0";
2
+ export const version = "2.0.1";
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.0",
2
+ "version": "2.0.1",
3
3
  "license": "AGPL-3.0-or-later",
4
4
  "name": "@constl/utils-tests",
5
5
  "author": "Julien Jean Malard-Adam",
package/src/attente.ts CHANGED
@@ -1,165 +1,138 @@
1
- import { EventEmitter } from "events";
2
- import { v4 as uuidv4 } from "uuid";
3
- import { isBrowser, isWebWorker } from "wherearewe";
4
- import type { Download } from "playwright";
5
-
6
- export class AttendreRésultat<T> {
7
- val?: T;
8
- fsOublier: { [clef: string]: () => void };
9
- événements: EventEmitter;
10
-
11
- constructor() {
12
- this.événements = new EventEmitter();
13
- this.val = undefined;
14
- this.fsOublier = {};
15
- }
16
-
17
- mettreÀJour(x?: T) {
18
- this.val = x;
19
- this.événements.emit("changé");
20
- }
21
-
22
- async attendreQue(f: (x: T) => boolean | Promise<boolean>): Promise<T> {
23
- if (this.val !== undefined && (await f(this.val))) return this.val;
24
- const id = uuidv4();
25
-
26
- return new Promise((résoudre) => {
27
- const fLorsqueChangé = async () => {
28
- if (this.val !== undefined && (await f(this.val))) {
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<void> => {
7
+ return new Promise((résoudre) => {
8
+ const testF = async () => {
9
+ const résultat = await f();
10
+ if (résultat) {
11
+ résoudre();
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
- export class AttendreFichierExiste extends EventEmitter {
71
- fOublier?: () => void;
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
- attenteTéléchargement?: Promise<Download>;
74
-
75
- constructor(fichier: string) {
76
- super();
77
- this.fichier = fichier;
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
- async attendre(): Promise<void> {
81
- if (isBrowser || isWebWorker) {
82
- throw new Error("Test non disponible dans le navigateur.");
83
- } else {
84
- const chokidar = await import("chokidar");
85
- const fs = await import("fs");
86
- const path = await import("path");
87
-
88
- await new Promise<void>((résoudre) => {
89
- if (fs.existsSync(this.fichier)) résoudre();
90
- const dossier = path.dirname(this.fichier);
91
- const écouteur = chokidar.watch(dossier);
92
- this.fOublier = () => écouteur.close();
93
- écouteur.on("add", async () => {
94
- if (fs.existsSync(this.fichier)) {
95
- await écouteur.close();
96
- résoudre();
97
- }
98
- });
99
- if (fs.existsSync(this.fichier)) {
100
- écouteur.close();
101
- résoudre();
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 {
123
+ // Le fichier a été effacé
124
+ await fermerEtRésoudre(false);
125
+ }
126
+ };
106
127
 
107
- annuler() {
108
- this.fOublier?.();
109
- }
110
- }
128
+ signal?.addEventListener("abort", lorsqueAvorté);
111
129
 
112
- export class AttendreFichierModifié extends EventEmitter {
113
- fsOublier: (() => void)[];
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
- async attendre(
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
- annuler() {
163
- this.fsOublier.forEach((f) => f());
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 "./sfip.js";
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
- // this will inject all the named exports from 'node-globals.js' as globals
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 (): Promise<PartialOptions> => {
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 };
@@ -1,79 +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";
4
- import { créerConstellation as _créerConstellation } from "@constl/ipa";
2
+ import { créerOrbitesTest } from "./orbite.js";
3
+ import { dossierTempo } from "./dossiers.js";
4
+ import { OrbitDB } from "@orbitdb/core";
5
5
 
6
- import { créerOrbiteTest } from "@/orbite.js";
7
- import { AttendreRésultat } from "@/attente.js";
8
- import type { ServicesLibp2pConstlTest } from "./libp2p";
6
+ interface InterfaceConstellation {
7
+ fermer: () => Promise<void>;
8
+ }
9
+
10
+ interface OptionsConstellation {
11
+ dossier?: string;
12
+ orbite?: OrbitDB;
13
+ }
9
14
 
10
15
  export const créerConstellationsTest = async <
11
- T = Constellation,
12
- U = client.optsConstellation,
16
+ T extends InterfaceConstellation,
13
17
  >({
14
18
  n = 1,
15
- créerConstellation = _créerConstellation as unknown as (opts: U) => T,
19
+ créerConstellation,
20
+ dossier,
16
21
  }: {
17
22
  n: number;
18
- créerConstellation: (opts: U) => T;
23
+ créerConstellation: (opts: OptionsConstellation) => T;
24
+ dossier?: string;
19
25
  }): Promise<{
20
- clients: ReturnType<typeof créerConstellation>[];
21
- orbites: OrbitDB<ServicesLibp2pConstlTest>[];
22
- fOublier: () => Promise<void>;
26
+ constls: T[];
27
+ fermer: () => Promise<void>;
23
28
  }> => {
24
- const clients: ReturnType<typeof créerConstellation>[] = [];
25
- const fsOublier: (() => Promise<void>)[] = [];
26
-
27
- // Nécessaire pour Playwright
28
- if (isBrowser) window.localStorage.clear();
29
+ let effacerDossier: () => void = () => {};
30
+ if (!dossier) {
31
+ ({ dossier, effacer: effacerDossier } = await dossierTempo());
32
+ }
29
33
 
30
- const { orbites, fOublier: fOublierOrbites } = await créerOrbiteTest({ n });
31
- fsOublier.push(fOublierOrbites);
34
+ const { orbites, fermer: fermerOrbites } = await créerOrbitesTest({
35
+ n,
36
+ dossier,
37
+ });
32
38
 
39
+ const constls: T[] = [];
33
40
  for (const i in [...Array(n).keys()]) {
34
- const client = créerConstellation({
41
+ const constl = créerConstellation({
35
42
  orbite: orbites[i],
36
- dossier: orbites[i].directory.split("/").slice(0, -1).join("/"),
37
- } as U);
38
- clients.push(client);
43
+ dossier,
44
+ });
45
+ constls.push(constl);
39
46
  }
40
47
 
41
- const fOublier = async () => {
42
- for (const client of clients) await (client as Constellation).fermer();
43
- await Promise.all(fsOublier.map((f) => f()));
44
- };
45
- return { fOublier, clients, orbites };
46
- };
47
-
48
- export const constellationConnectéeÀ = async (
49
- constellation: client.Constellation,
50
- connectéeÀ: client.Constellation,
51
- ): Promise<void> => {
52
- const dispositifsConnectés = new AttendreRésultat<
53
- réseau.statutDispositif[]
54
- >();
55
- const idCompte2 = await connectéeÀ.obtIdCompte();
48
+ const fermer = async () => {
49
+ for (const constl of constls) await constl.fermer();
56
50
 
57
- const fOublier = await constellation.réseau.suivreConnexionsDispositifs({
58
- f: (dispositifs) => dispositifsConnectés.mettreÀJour(dispositifs),
59
- });
60
- await dispositifsConnectés.attendreQue((dispositifs) => {
61
- return !!dispositifs.find((d) => d.infoDispositif.idCompte === idCompte2);
62
- });
63
- await fOublier();
64
- return;
65
- };
51
+ await fermerOrbites();
52
+ effacerDossier();
66
53
 
67
- export const constellationsConnectées = async (
68
- ...clients: client.Constellation[]
69
- ): Promise<void> => {
70
- if (clients.length < 2) return;
71
- const promesses: Promise<void>[] = [];
72
- for (let i = 1; i < clients.length; i++) {
73
- for (let j = 0; j < i; j++) {
74
- promesses.push(constellationConnectéeÀ(clients[i], clients[j]));
75
- promesses.push(constellationConnectéeÀ(clients[j], clients[i]));
76
- }
77
- }
78
- await Promise.all(promesses);
54
+ // Nécessaire pour Playwright
55
+ if (isBrowser) window.localStorage.clear();
56
+ };
57
+ return { constls, fermer };
79
58
  };
package/src/dossiers.ts CHANGED
@@ -3,7 +3,7 @@ import { v4 as uuidv4 } from "uuid";
3
3
 
4
4
  export const dossierTempo = async (): Promise<{
5
5
  dossier: string;
6
- fEffacer: () => void;
6
+ effacer: () => void;
7
7
  }> => {
8
8
  if (isNode || isElectronMain) {
9
9
  const fs = await import("fs");
@@ -11,14 +11,26 @@ export const dossierTempo = async (): Promise<{
11
11
  const os = await import("os");
12
12
  const sync = (await import("rimraf")).sync;
13
13
 
14
- const dossier = fs.mkdtempSync(path.join(os.tmpdir(), "constl-ipa-"));
15
- const fEffacer = () => sync(dossier);
16
- return { dossier, fEffacer };
14
+ const dossier = fs.mkdtempSync(path.join(os.tmpdir(), "constl-"));
15
+ const effacer = () => {
16
+ try {
17
+ sync(dossier);
18
+ } catch (e) {
19
+ // Sur Windows, parfois les fichiers de Hélia sont encore en utilisation
20
+ if (process.platform === "win32") {
21
+ console.log("On ignore ça sur Windows\n", e);
22
+ return;
23
+ } else {
24
+ throw e;
25
+ }
26
+ }
27
+ };
28
+ return { dossier, effacer };
17
29
  } else {
18
- const dossier = uuidv4() + "/constl-ipa";
30
+ const dossier = uuidv4() + "/constl-";
19
31
  return {
20
32
  dossier,
21
- fEffacer: () => {
33
+ effacer: () => {
22
34
  // Rien à faire, je crois
23
35
  },
24
36
  };
@@ -0,0 +1,61 @@
1
+ import { Helia, createHelia } from "helia";
2
+ import { ServicesLibp2pTest, créerLibp2psTest } from "./libp2p/index.js";
3
+ import { Libp2p } from "@libp2p/interface";
4
+ import { bitswap } from "@helia/block-brokers";
5
+ import { MemoryBlockstore } from "blockstore-core";
6
+ import { join } from "path";
7
+ import { sousDossier } from "./utils.js";
8
+ import { LevelBlockstore } from "blockstore-level";
9
+ import { obtenirAdresseRelai } from "./relai/index.js";
10
+
11
+ export const créerHéliasTest = async ({
12
+ n,
13
+ dossier,
14
+ adresseRelai,
15
+ }: {
16
+ n: number;
17
+ dossier?: string;
18
+ adresseRelai?: string;
19
+ }): Promise<{
20
+ hélias: Helia<Libp2p<ServicesLibp2pTest>>[];
21
+ fermer: () => Promise<void>;
22
+ }> => {
23
+ adresseRelai = adresseRelai ?? obtenirAdresseRelai();
24
+
25
+ const { libp2ps, fermer: fermerLibsp2p } = await créerLibp2psTest({
26
+ n,
27
+ adresseRelai,
28
+ });
29
+
30
+ let i = 0;
31
+ const hélias = await Promise.all(
32
+ libp2ps.map(async (libp2p) => {
33
+ const blockstore = dossier
34
+ ? new LevelBlockstore(
35
+ join(sousDossier({ dossier, i }), "hélia", "blocks"),
36
+ )
37
+ : new MemoryBlockstore();
38
+ i++;
39
+
40
+ const optionsHélia = {
41
+ blockstore,
42
+ libp2p,
43
+ blockBrokers: [bitswap()],
44
+ };
45
+ return await createHelia(optionsHélia);
46
+ }),
47
+ );
48
+
49
+ const fermer = async () => {
50
+ await Promise.all(
51
+ hélias.map(async (h) => {
52
+ await h.stop();
53
+ // @ts-expect-error Je ne sais pas pourquoi
54
+ await h.blockstore.unwrap()?.unwrap()?.child?.db?.close();
55
+ }),
56
+ );
57
+ await fermerLibsp2p();
58
+ };
59
+
60
+ return { hélias, fermer };
61
+ };
package/src/index.ts CHANGED
@@ -1,9 +1,29 @@
1
- export * as attente from "@/attente.js";
2
- export * as constellation from "@/constellation.js";
3
- export * as dossiers from "@/dossiers.js";
4
- export * as orbite from "@/orbite.js";
5
- export * as sfip from "@/sfip.js";
6
- export * as config from "@/config.js";
7
- export * as libp2p from "@/libp2p.js";
1
+ export {
2
+ ServicesLibp2pTest,
3
+ ComposantesServiceClefPrivée,
4
+ ServiceClefPrivée,
5
+ OptionsDéfautLibp2pNode,
6
+ OptionsDéfautLibp2pNavigateur,
7
+ créerLibp2psTest,
8
+ toutesConnectées,
9
+ connecterPairs,
10
+ } from "./libp2p/index.js";
8
11
 
9
- export { version } from "@/version.js";
12
+ export {
13
+ ID_DÉFAUT_RELAI,
14
+ PORT_DÉFAUT_RELAI,
15
+ obtenirAdresseRelai,
16
+ lancerRelai,
17
+ obtenirFichierRelai,
18
+ } from "./relai/index.js";
19
+
20
+ export {
21
+ attendreFichierExiste,
22
+ attendreFichierModifié,
23
+ que,
24
+ } from "./attente.js";
25
+ export { obtConfigEsbuild, générerConfigÆgir } from "./config.js";
26
+ export { créerConstellationsTest } from "./constellation.js";
27
+ export { dossierTempo } from "./dossiers.js";
28
+ export { créerHéliasTest } from "./hélia.js";
29
+ export { créerOrbitesTest } from "./orbite.js";