@duplojs/agents-kit 0.1.0-beta.8 → 0.1.0-beta.9

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 (83) hide show
  1. package/docs/API/10-lang/10-common/10-asyncLoop.ts +4 -6
  2. package/docs/API/10-lang/10-common/10-asyncLoopAccumulator.ts +40 -0
  3. package/docs/API/10-lang/10-common/10-loop.ts +5 -7
  4. package/docs/API/10-lang/10-common/10-loopAccumulator.ts +35 -0
  5. package/docs/API/10-lang/10-common/10-loopAccumulatorFrom.ts +29 -0
  6. package/docs/API/10-lang/10-common/index.llms.md +14 -2
  7. package/docs/API/10-lang/10-generator/10-asyncLoop.ts +11 -20
  8. package/docs/API/10-lang/10-generator/10-asyncLoopAccumulator.ts +40 -0
  9. package/docs/API/10-lang/10-generator/10-loop.ts +11 -20
  10. package/docs/API/10-lang/10-generator/10-loopAccumulator.ts +33 -0
  11. package/docs/API/10-lang/10-generator/10-loopAccumulatorFrom.ts +30 -0
  12. package/docs/API/10-lang/10-generator/index.llms.md +14 -2
  13. package/docs/API/20-server/10-file/10-appendFile.ts +50 -0
  14. package/docs/API/20-server/10-file/10-appendTextFile.ts +49 -0
  15. package/docs/API/20-server/10-file/10-copy.ts +50 -0
  16. package/docs/API/20-server/10-file/10-createEntryInterface.ts +13 -0
  17. package/docs/API/20-server/10-file/10-createFileInterface.ts +22 -0
  18. package/docs/API/20-server/10-file/10-createFolderInterface.ts +20 -0
  19. package/docs/API/20-server/10-file/10-createUnknownEntryInterface.ts +13 -0
  20. package/docs/API/20-server/10-file/10-ensureDirectory.ts +39 -0
  21. package/docs/API/20-server/10-file/10-ensureFile.ts +40 -0
  22. package/docs/API/20-server/10-file/10-exists.ts +36 -0
  23. package/docs/API/20-server/10-file/10-link.ts +51 -0
  24. package/docs/API/20-server/10-file/10-linkStat.ts +37 -0
  25. package/docs/API/20-server/10-file/10-makeDirectory.ts +41 -0
  26. package/docs/API/20-server/10-file/10-makeTemporaryDirectory.ts +35 -0
  27. package/docs/API/20-server/10-file/10-makeTemporaryFile.ts +40 -0
  28. package/docs/API/20-server/10-file/10-move.ts +51 -0
  29. package/docs/API/20-server/10-file/10-readDirectory.ts +52 -0
  30. package/docs/API/20-server/10-file/10-readFile.ts +38 -0
  31. package/docs/API/20-server/10-file/10-readJsonFile.ts +38 -0
  32. package/docs/API/20-server/10-file/10-readLink.ts +37 -0
  33. package/docs/API/20-server/10-file/10-readTextFile.ts +38 -0
  34. package/docs/API/20-server/10-file/10-realPath.ts +36 -0
  35. package/docs/API/20-server/10-file/10-relocate.ts +51 -0
  36. package/docs/API/20-server/10-file/10-remove.ts +40 -0
  37. package/docs/API/20-server/10-file/10-rename.ts +43 -0
  38. package/docs/API/20-server/10-file/10-setMode.ts +37 -0
  39. package/docs/API/20-server/10-file/10-setOwner.ts +38 -0
  40. package/docs/API/20-server/10-file/10-setTime.ts +42 -0
  41. package/docs/API/20-server/10-file/10-stat.ts +37 -0
  42. package/docs/API/20-server/10-file/10-symlink.ts +49 -0
  43. package/docs/API/20-server/10-file/10-truncate.ts +41 -0
  44. package/docs/API/20-server/10-file/10-walkDirectory.ts +75 -0
  45. package/docs/API/20-server/10-file/10-writeFile.ts +50 -0
  46. package/docs/API/20-server/10-file/10-writeJsonFile.ts +41 -0
  47. package/docs/API/20-server/10-file/10-writeTextFile.ts +49 -0
  48. package/docs/API/20-server/10-file/index.llms.md +144 -0
  49. package/docs/API/20-server/10-file/index.md +3 -0
  50. package/docs/API/20-server/20-common/10-environmentVariable.ts +57 -0
  51. package/docs/API/20-server/20-common/10-environmentVariableOrThrow.ts +21 -0
  52. package/docs/API/20-server/20-common/10-exitProcess.ts +9 -0
  53. package/docs/API/20-server/20-common/10-getCurrentDirectoryName.ts +10 -0
  54. package/docs/API/20-server/20-common/10-getCurrentWorkDirectory.ts +10 -0
  55. package/docs/API/20-server/20-common/10-getCurrentWorkDirectoryOrThrow.ts +10 -0
  56. package/docs/API/20-server/20-common/10-getProcessArguments.ts +10 -0
  57. package/docs/API/20-server/20-common/10-setCurrentWorkingDirectory.ts +14 -0
  58. package/docs/API/20-server/20-common/10-setCurrentWorkingDirectoryOrThrow.ts +12 -0
  59. package/docs/API/20-server/20-common/index.llms.md +40 -0
  60. package/docs/API/20-server/20-common/index.md +3 -0
  61. package/docs/API/20-server/30-dataStructure/10-file.ts +14 -0
  62. package/docs/API/20-server/30-dataStructure/10-fileExist.ts +27 -0
  63. package/docs/API/20-server/30-dataStructure/10-folder.ts +14 -0
  64. package/docs/API/20-server/30-dataStructure/10-folderExist.ts +14 -0
  65. package/docs/API/20-server/30-dataStructure/10-mimeType.ts +14 -0
  66. package/docs/API/20-server/30-dataStructure/10-size.ts +32 -0
  67. package/docs/API/20-server/30-dataStructure/index.llms.md +28 -0
  68. package/docs/API/20-server/30-dataStructure/index.md +3 -0
  69. package/docs/API/20-server/40-command/10-create.ts +39 -0
  70. package/docs/API/20-server/40-command/10-createArgument.ts +39 -0
  71. package/docs/API/20-server/40-command/10-createArrayOption.ts +36 -0
  72. package/docs/API/20-server/40-command/10-createBooleanOption.ts +28 -0
  73. package/docs/API/20-server/40-command/10-createOption.ts +46 -0
  74. package/docs/API/20-server/40-command/10-exec.ts +51 -0
  75. package/docs/API/20-server/40-command/10-execOptions.ts +30 -0
  76. package/docs/API/20-server/40-command/index.llms.md +32 -0
  77. package/docs/API/20-server/40-command/index.md +3 -0
  78. package/docs/API/20-server/index.md +3 -0
  79. package/docs/API.llms.md +20 -0
  80. package/package.json +14 -14
  81. package/skills/fundamental/SKILL.md +3 -1
  82. package/skills/fundamental/references/examples/iterations.ts +26 -13
  83. package/skills/fundamental/references/iterations.md +5 -1
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @title DSFile.relocate
3
+ *
4
+ * Déplacer une entrée dans un autre dossier en conservant son nom.
5
+ */
6
+ import * as DCommon from "@duplojs/lang/common";
7
+ import type * as DPath from "@duplojs/lang/path";
8
+ import * as DSFile from "@duplojs/server/file";
9
+ import * as DEither from "@duplojs/lang/either";
10
+ import * as DPattern from "@duplojs/lang/pattern";
11
+
12
+ declare const source: string & DPath.Path;
13
+ declare const destination: string & DPath.Path;
14
+
15
+ // Appel direct
16
+ const result = await DSFile.relocate(source, destination);
17
+
18
+ // Forme curifiée
19
+ const pipedResult = await DCommon.pipe(
20
+ source,
21
+ DSFile.relocate(destination),
22
+ );
23
+
24
+ // Les résultats dépendent de l'état du système de fichiers et peuvent échouer.
25
+
26
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
27
+ if (DEither.isLeft(result)) {
28
+ const error = DEither.unwrapLeft(result);
29
+
30
+ const diagnosis = DPattern.matchWithErrorOtherwise(
31
+ error,
32
+ {
33
+ "file-system-relocate-not-found": () => "missing",
34
+ "file-system-relocate-permission-denied": () => "access-denied",
35
+ },
36
+ (otherError) => otherError,
37
+ );
38
+ }
39
+
40
+ // Identifiants d’erreur déclarés pour cette opération :
41
+ // file-system-relocate-not-found
42
+ // file-system-relocate-permission-denied
43
+ // file-system-relocate-already-exists
44
+ // file-system-relocate-is-directory
45
+ // file-system-relocate-not-directory
46
+ // file-system-relocate-directory-not-empty
47
+ // file-system-relocate-read-only
48
+ // file-system-relocate-invalid-argument
49
+ // file-system-relocate-busy
50
+ // file-system-relocate-cross-device
51
+ // file-system-relocate-error
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @title DSFile.remove
3
+ *
4
+ * Supprimer une entrée, éventuellement récursivement.
5
+ */
6
+ import type * as DPath from "@duplojs/lang/path";
7
+ import * as DSFile from "@duplojs/server/file";
8
+ import * as DEither from "@duplojs/lang/either";
9
+ import * as DPattern from "@duplojs/lang/pattern";
10
+
11
+ declare const path: string & DPath.Path;
12
+
13
+ const result = await DSFile.remove(path, { recursive: true });
14
+
15
+ // Le résultat doit être traité même si une vérification préalable a réussi.
16
+
17
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
18
+ if (DEither.isLeft(result)) {
19
+ const error = DEither.unwrapLeft(result);
20
+
21
+ const diagnosis = DPattern.matchWithErrorOtherwise(
22
+ error,
23
+ {
24
+ "file-system-remove-not-found": () => "missing",
25
+ "file-system-remove-permission-denied": () => "access-denied",
26
+ },
27
+ (otherError) => otherError,
28
+ );
29
+ }
30
+
31
+ // Identifiants d’erreur déclarés pour cette opération :
32
+ // file-system-remove-not-found
33
+ // file-system-remove-permission-denied
34
+ // file-system-remove-is-directory
35
+ // file-system-remove-not-directory
36
+ // file-system-remove-directory-not-empty
37
+ // file-system-remove-read-only
38
+ // file-system-remove-invalid-argument
39
+ // file-system-remove-busy
40
+ // file-system-remove-error
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @title DSFile.rename
3
+ *
4
+ * Renommer une entrée dans son dossier parent.
5
+ */
6
+ import type * as DPath from "@duplojs/lang/path";
7
+ import * as DSFile from "@duplojs/server/file";
8
+ import * as DEither from "@duplojs/lang/either";
9
+ import * as DPattern from "@duplojs/lang/pattern";
10
+
11
+ declare const path: string & DPath.Path;
12
+ declare const name: string & DPath.Segment;
13
+
14
+ const result = await DSFile.rename(path, name);
15
+
16
+ // Le résultat porte le nouveau chemin en cas de succès.
17
+
18
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
19
+ if (DEither.isLeft(result)) {
20
+ const error = DEither.unwrapLeft(result);
21
+
22
+ const diagnosis = DPattern.matchWithErrorOtherwise(
23
+ error,
24
+ {
25
+ "file-system-rename-not-found": () => "missing",
26
+ "file-system-rename-permission-denied": () => "access-denied",
27
+ },
28
+ (otherError) => otherError,
29
+ );
30
+ }
31
+
32
+ // Identifiants d’erreur déclarés pour cette opération :
33
+ // file-system-rename-not-found
34
+ // file-system-rename-permission-denied
35
+ // file-system-rename-already-exists
36
+ // file-system-rename-is-directory
37
+ // file-system-rename-not-directory
38
+ // file-system-rename-directory-not-empty
39
+ // file-system-rename-read-only
40
+ // file-system-rename-invalid-argument
41
+ // file-system-rename-busy
42
+ // file-system-rename-cross-device
43
+ // file-system-rename-error
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @title DSFile.setMode
3
+ *
4
+ * Modifier les permissions d’une entrée.
5
+ */
6
+ import type * as DPath from "@duplojs/lang/path";
7
+ import * as DSFile from "@duplojs/server/file";
8
+ import * as DEither from "@duplojs/lang/either";
9
+ import * as DPattern from "@duplojs/lang/pattern";
10
+
11
+ declare const path: string & DPath.Path;
12
+
13
+ const result = await DSFile.setMode(path, 0o640);
14
+
15
+ // Le résultat peut notamment signaler un refus d’accès.
16
+
17
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
18
+ if (DEither.isLeft(result)) {
19
+ const error = DEither.unwrapLeft(result);
20
+
21
+ const diagnosis = DPattern.matchWithErrorOtherwise(
22
+ error,
23
+ {
24
+ "file-system-set-mode-not-found": () => "missing",
25
+ "file-system-set-mode-permission-denied": () => "access-denied",
26
+ },
27
+ (otherError) => otherError,
28
+ );
29
+ }
30
+
31
+ // Identifiants d’erreur déclarés pour cette opération :
32
+ // file-system-set-mode-not-found
33
+ // file-system-set-mode-permission-denied
34
+ // file-system-set-mode-not-directory
35
+ // file-system-set-mode-read-only
36
+ // file-system-set-mode-invalid-argument
37
+ // file-system-set-mode-error
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @title DSFile.setOwner
3
+ *
4
+ * Modifier le propriétaire et le groupe d’une entrée.
5
+ */
6
+ import type * as DPath from "@duplojs/lang/path";
7
+ import * as DSFile from "@duplojs/server/file";
8
+ import * as DEither from "@duplojs/lang/either";
9
+ import * as DPattern from "@duplojs/lang/pattern";
10
+
11
+ declare const path: string & DPath.Path;
12
+ declare const owner: DSFile.SetOwnerParams;
13
+
14
+ const result = await DSFile.setOwner(path, owner);
15
+
16
+ // La disponibilité et les permissions dépendent de l’environnement.
17
+
18
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
19
+ if (DEither.isLeft(result)) {
20
+ const error = DEither.unwrapLeft(result);
21
+
22
+ const diagnosis = DPattern.matchWithErrorOtherwise(
23
+ error,
24
+ {
25
+ "file-system-set-owner-not-found": () => "missing",
26
+ "file-system-set-owner-permission-denied": () => "access-denied",
27
+ },
28
+ (otherError) => otherError,
29
+ );
30
+ }
31
+
32
+ // Identifiants d’erreur déclarés pour cette opération :
33
+ // file-system-set-owner-not-found
34
+ // file-system-set-owner-permission-denied
35
+ // file-system-set-owner-not-directory
36
+ // file-system-set-owner-read-only
37
+ // file-system-set-owner-invalid-argument
38
+ // file-system-set-owner-error
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @title DSFile.setTime
3
+ *
4
+ * Modifier les dates d’accès et de modification d’une entrée.
5
+ */
6
+ import type * as DChrono from "@duplojs/lang/chrono";
7
+ import type * as DPath from "@duplojs/lang/path";
8
+ import * as DSFile from "@duplojs/server/file";
9
+ import * as DEither from "@duplojs/lang/either";
10
+ import * as DPattern from "@duplojs/lang/pattern";
11
+
12
+ declare const path: string & DPath.Path;
13
+ declare const date: DChrono.TheDate;
14
+
15
+ const result = await DSFile.setTime(path, {
16
+ accessTime: date,
17
+ modifiedTime: date,
18
+ });
19
+
20
+ // Le résultat indique si les métadonnées ont été modifiées.
21
+
22
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
23
+ if (DEither.isLeft(result)) {
24
+ const error = DEither.unwrapLeft(result);
25
+
26
+ const diagnosis = DPattern.matchWithErrorOtherwise(
27
+ error,
28
+ {
29
+ "file-system-set-time-not-found": () => "missing",
30
+ "file-system-set-time-permission-denied": () => "access-denied",
31
+ },
32
+ (otherError) => otherError,
33
+ );
34
+ }
35
+
36
+ // Identifiants d’erreur déclarés pour cette opération :
37
+ // file-system-set-time-not-found
38
+ // file-system-set-time-permission-denied
39
+ // file-system-set-time-not-directory
40
+ // file-system-set-time-read-only
41
+ // file-system-set-time-invalid-argument
42
+ // file-system-set-time-error
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @title DSFile.stat
3
+ *
4
+ * Lire les métadonnées d’une entrée.
5
+ */
6
+ import type * as DPath from "@duplojs/lang/path";
7
+ import * as DSFile from "@duplojs/server/file";
8
+ import * as DEither from "@duplojs/lang/either";
9
+ import * as DPattern from "@duplojs/lang/pattern";
10
+
11
+ declare const path: string & DPath.Path;
12
+
13
+ const result = await DSFile.stat(path);
14
+
15
+ // Le Right décrit notamment la nature, la taille et les dates de l’entrée.
16
+
17
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
18
+ if (DEither.isLeft(result)) {
19
+ const error = DEither.unwrapLeft(result);
20
+
21
+ const diagnosis = DPattern.matchWithErrorOtherwise(
22
+ error,
23
+ {
24
+ "file-system-stat-not-found": () => "missing",
25
+ "file-system-stat-permission-denied": () => "access-denied",
26
+ },
27
+ (otherError) => otherError,
28
+ );
29
+ }
30
+
31
+ // Identifiants d’erreur déclarés pour cette opération :
32
+ // file-system-stat-not-found
33
+ // file-system-stat-permission-denied
34
+ // file-system-stat-not-directory
35
+ // file-system-stat-too-many-open-files
36
+ // file-system-stat-busy
37
+ // file-system-stat-error
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @title DSFile.symlink
3
+ *
4
+ * Créer un lien symbolique vers une cible.
5
+ */
6
+ import * as DCommon from "@duplojs/lang/common";
7
+ import type * as DPath from "@duplojs/lang/path";
8
+ import * as DSFile from "@duplojs/server/file";
9
+ import * as DEither from "@duplojs/lang/either";
10
+ import * as DPattern from "@duplojs/lang/pattern";
11
+
12
+ declare const source: string & DPath.Path;
13
+ declare const destination: string & DPath.Path;
14
+
15
+ // Appel direct
16
+ const result = await DSFile.symlink(source, destination);
17
+
18
+ // Forme curifiée
19
+ const pipedResult = await DCommon.pipe(
20
+ source,
21
+ DSFile.symlink(destination),
22
+ );
23
+
24
+ // Les résultats dépendent de l'état du système de fichiers et peuvent échouer.
25
+
26
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
27
+ if (DEither.isLeft(result)) {
28
+ const error = DEither.unwrapLeft(result);
29
+
30
+ const diagnosis = DPattern.matchWithErrorOtherwise(
31
+ error,
32
+ {
33
+ "file-system-symlink-not-found": () => "missing",
34
+ "file-system-symlink-permission-denied": () => "access-denied",
35
+ },
36
+ (otherError) => otherError,
37
+ );
38
+ }
39
+
40
+ // Identifiants d’erreur déclarés pour cette opération :
41
+ // file-system-symlink-not-found
42
+ // file-system-symlink-permission-denied
43
+ // file-system-symlink-already-exists
44
+ // file-system-symlink-not-directory
45
+ // file-system-symlink-read-only
46
+ // file-system-symlink-invalid-argument
47
+ // file-system-symlink-too-many-open-files
48
+ // file-system-symlink-busy
49
+ // file-system-symlink-error
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @title DSFile.truncate
3
+ *
4
+ * Tronquer ou étendre un fichier à une taille en octets.
5
+ */
6
+ import type * as DPath from "@duplojs/lang/path";
7
+ import * as DSFile from "@duplojs/server/file";
8
+ import * as DEither from "@duplojs/lang/either";
9
+ import * as DPattern from "@duplojs/lang/pattern";
10
+
11
+ declare const path: string & DPath.Path;
12
+
13
+ const result = await DSFile.truncate(path, 128);
14
+
15
+ // Le résultat indique si la modification a réussi.
16
+
17
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
18
+ if (DEither.isLeft(result)) {
19
+ const error = DEither.unwrapLeft(result);
20
+
21
+ const diagnosis = DPattern.matchWithErrorOtherwise(
22
+ error,
23
+ {
24
+ "file-system-truncate-not-found": () => "missing",
25
+ "file-system-truncate-permission-denied": () => "access-denied",
26
+ },
27
+ (otherError) => otherError,
28
+ );
29
+ }
30
+
31
+ // Identifiants d’erreur déclarés pour cette opération :
32
+ // file-system-truncate-not-found
33
+ // file-system-truncate-permission-denied
34
+ // file-system-truncate-is-directory
35
+ // file-system-truncate-not-directory
36
+ // file-system-truncate-no-space
37
+ // file-system-truncate-read-only
38
+ // file-system-truncate-invalid-argument
39
+ // file-system-truncate-too-many-open-files
40
+ // file-system-truncate-busy
41
+ // file-system-truncate-error
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @title DSFile.walkDirectory
3
+ *
4
+ * Parcourir les entrées d’un dossier sous forme d’interfaces.
5
+ */
6
+ import type * as DCommon from "@duplojs/lang/common";
7
+ import * as DArray from "@duplojs/lang/array";
8
+ import * as DGenerator from "@duplojs/lang/generator";
9
+ import type * as DPath from "@duplojs/lang/path";
10
+ import * as DEither from "@duplojs/lang/either";
11
+ import * as DPattern from "@duplojs/lang/pattern";
12
+ import * as DSFile from "@duplojs/server/file";
13
+
14
+ declare const directory: string & DPath.Path;
15
+
16
+ const result = await DSFile.walkDirectory(
17
+ directory,
18
+ { recursive: true },
19
+ );
20
+
21
+ if (DEither.isRight(result)) {
22
+ const entries = DEither.unwrapRight(result);
23
+
24
+ // Le générateur produit des interfaces munies d'un chemin absolu.
25
+ // Le test du kind permet d'utiliser les opérations propres aux fichiers.
26
+ const descriptions = DArray.from(
27
+ DGenerator.map(
28
+ entries,
29
+ (entry) => {
30
+ type _CheckPath = DCommon.ExpectType<
31
+ typeof entry.path,
32
+ string & DPath.Path & DPath.Absolute,
33
+ "strict"
34
+ >;
35
+
36
+ if (DSFile.isFileInterface(entry)) {
37
+ return {
38
+ path: entry.path,
39
+ mimeType: entry.getMimeType(),
40
+ };
41
+ }
42
+
43
+ if (DSFile.isFolderInterface(entry)) {
44
+ return {
45
+ path: entry.path,
46
+ name: entry.getName(),
47
+ };
48
+ }
49
+
50
+ // Une entrée inconnue conserve notamment path et stat().
51
+ return { path: entry.path };
52
+ },
53
+ ),
54
+ );
55
+ } else {
56
+ const error = DEither.unwrapLeft(result);
57
+
58
+ const diagnosis = DPattern.matchWithErrorOtherwise(
59
+ error,
60
+ {
61
+ "file-system-walk-directory-not-found": () => "missing-directory",
62
+ "file-system-walk-directory-permission-denied": () => "access-denied",
63
+ "file-system-walk-directory-not-directory": () => "not-a-directory",
64
+ },
65
+ (otherError) => otherError,
66
+ );
67
+ }
68
+
69
+ // Identifiants d’erreur déclarés pour cette opération :
70
+ // file-system-walk-directory-not-found
71
+ // file-system-walk-directory-permission-denied
72
+ // file-system-walk-directory-not-directory
73
+ // file-system-walk-directory-too-many-open-files
74
+ // file-system-walk-directory-busy
75
+ // file-system-walk-directory-error
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @title DSFile.writeFile
3
+ *
4
+ * Écrire des octets dans un fichier.
5
+ */
6
+ import * as DCommon from "@duplojs/lang/common";
7
+ import type * as DPath from "@duplojs/lang/path";
8
+ import * as DSFile from "@duplojs/server/file";
9
+ import * as DEither from "@duplojs/lang/either";
10
+ import * as DPattern from "@duplojs/lang/pattern";
11
+
12
+ declare const path: string & DPath.Path;
13
+ declare const bytes: Uint8Array;
14
+
15
+ // Appel direct
16
+ const result = await DSFile.writeFile(path, bytes);
17
+
18
+ // Forme curifiée
19
+ const pipedResult = await DCommon.pipe(
20
+ path,
21
+ DSFile.writeFile(bytes),
22
+ );
23
+
24
+ // Chaque résultat indique la réussite ou l'échec de l'écriture.
25
+
26
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
27
+ if (DEither.isLeft(result)) {
28
+ const error = DEither.unwrapLeft(result);
29
+
30
+ const diagnosis = DPattern.matchWithErrorOtherwise(
31
+ error,
32
+ {
33
+ "file-system-write-file-not-found": () => "missing",
34
+ "file-system-write-file-permission-denied": () => "access-denied",
35
+ },
36
+ (otherError) => otherError,
37
+ );
38
+ }
39
+
40
+ // Identifiants d’erreur déclarés pour cette opération :
41
+ // file-system-write-file-not-found
42
+ // file-system-write-file-permission-denied
43
+ // file-system-write-file-is-directory
44
+ // file-system-write-file-not-directory
45
+ // file-system-write-file-no-space
46
+ // file-system-write-file-read-only
47
+ // file-system-write-file-invalid-argument
48
+ // file-system-write-file-too-many-open-files
49
+ // file-system-write-file-busy
50
+ // file-system-write-file-error
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @title DSFile.writeJsonFile
3
+ *
4
+ * Sérialiser une valeur en JSON et l’écrire dans un fichier.
5
+ */
6
+ import type * as DPath from "@duplojs/lang/path";
7
+ import * as DSFile from "@duplojs/server/file";
8
+ import * as DEither from "@duplojs/lang/either";
9
+ import * as DPattern from "@duplojs/lang/pattern";
10
+
11
+ declare const path: string & DPath.Path;
12
+
13
+ const result = await DSFile.writeJsonFile(path, { enabled: true });
14
+
15
+ // Le résultat peut signaler une erreur de sérialisation ou d’écriture.
16
+
17
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
18
+ if (DEither.isLeft(result)) {
19
+ const error = DEither.unwrapLeft(result);
20
+
21
+ const diagnosis = DPattern.matchWithErrorOtherwise(
22
+ error,
23
+ {
24
+ "file-system-write-json-file-not-found": () => "missing",
25
+ "file-system-write-json-file-permission-denied": () => "access-denied",
26
+ },
27
+ (otherError) => otherError,
28
+ );
29
+ }
30
+
31
+ // Identifiants d’erreur déclarés pour cette opération :
32
+ // file-system-write-json-file-not-found
33
+ // file-system-write-json-file-permission-denied
34
+ // file-system-write-json-file-is-directory
35
+ // file-system-write-json-file-not-directory
36
+ // file-system-write-json-file-no-space
37
+ // file-system-write-json-file-read-only
38
+ // file-system-write-json-file-invalid-argument
39
+ // file-system-write-json-file-too-many-open-files
40
+ // file-system-write-json-file-busy
41
+ // file-system-write-json-file-error
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @title DSFile.writeTextFile
3
+ *
4
+ * Écrire du texte dans un fichier.
5
+ */
6
+ import * as DCommon from "@duplojs/lang/common";
7
+ import type * as DPath from "@duplojs/lang/path";
8
+ import * as DSFile from "@duplojs/server/file";
9
+ import * as DEither from "@duplojs/lang/either";
10
+ import * as DPattern from "@duplojs/lang/pattern";
11
+
12
+ declare const path: string & DPath.Path;
13
+
14
+ // Appel direct
15
+ const result = await DSFile.writeTextFile(path, "configuration");
16
+
17
+ // Forme curifiée
18
+ const pipedResult = await DCommon.pipe(
19
+ path,
20
+ DSFile.writeTextFile("configuration"),
21
+ );
22
+
23
+ // Chaque résultat indique la réussite ou l'échec de l'écriture.
24
+
25
+ // L’information du Left identifie l’opération ; sa valeur précise la cause.
26
+ if (DEither.isLeft(result)) {
27
+ const error = DEither.unwrapLeft(result);
28
+
29
+ const diagnosis = DPattern.matchWithErrorOtherwise(
30
+ error,
31
+ {
32
+ "file-system-write-text-file-not-found": () => "missing",
33
+ "file-system-write-text-file-permission-denied": () => "access-denied",
34
+ },
35
+ (otherError) => otherError,
36
+ );
37
+ }
38
+
39
+ // Identifiants d’erreur déclarés pour cette opération :
40
+ // file-system-write-text-file-not-found
41
+ // file-system-write-text-file-permission-denied
42
+ // file-system-write-text-file-is-directory
43
+ // file-system-write-text-file-not-directory
44
+ // file-system-write-text-file-no-space
45
+ // file-system-write-text-file-read-only
46
+ // file-system-write-text-file-invalid-argument
47
+ // file-system-write-text-file-too-many-open-files
48
+ // file-system-write-text-file-busy
49
+ // file-system-write-text-file-error