@duplojs/agents-kit 0.1.0-beta.7 → 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.
- package/README.md +17 -9
- package/dist/bin/index.mjs +2 -2
- package/dist/bin/skills/index.d.ts +5 -0
- package/dist/bin/skills/index.mjs +11 -0
- package/dist/bin/{installSkill/index.d.ts → skills/install.d.ts} +1 -1
- package/dist/bin/{installSkill/index.mjs → skills/install.mjs} +2 -2
- package/dist/bin/{installSkill → skills}/skill.d.ts +7 -0
- package/dist/bin/{installSkill → skills}/skill.mjs +10 -8
- package/dist/bin/skills/update.d.ts +2 -0
- package/dist/bin/skills/update.mjs +19 -0
- package/docs/API/10-lang/10-common/10-asyncLoop.ts +4 -6
- package/docs/API/10-lang/10-common/10-asyncLoopAccumulator.ts +40 -0
- package/docs/API/10-lang/10-common/10-loop.ts +5 -7
- package/docs/API/10-lang/10-common/10-loopAccumulator.ts +35 -0
- package/docs/API/10-lang/10-common/10-loopAccumulatorFrom.ts +29 -0
- package/docs/API/10-lang/10-common/index.llms.md +14 -2
- package/docs/API/10-lang/10-generator/10-asyncLoop.ts +11 -20
- package/docs/API/10-lang/10-generator/10-asyncLoopAccumulator.ts +40 -0
- package/docs/API/10-lang/10-generator/10-loop.ts +11 -20
- package/docs/API/10-lang/10-generator/10-loopAccumulator.ts +33 -0
- package/docs/API/10-lang/10-generator/10-loopAccumulatorFrom.ts +30 -0
- package/docs/API/10-lang/10-generator/index.llms.md +14 -2
- package/docs/API/10-lang/10-object/10-discriminate.ts +84 -37
- package/docs/API/10-lang/10-object/index.llms.md +1 -5
- package/docs/API/20-server/10-file/10-appendFile.ts +50 -0
- package/docs/API/20-server/10-file/10-appendTextFile.ts +49 -0
- package/docs/API/20-server/10-file/10-copy.ts +50 -0
- package/docs/API/20-server/10-file/10-createEntryInterface.ts +13 -0
- package/docs/API/20-server/10-file/10-createFileInterface.ts +22 -0
- package/docs/API/20-server/10-file/10-createFolderInterface.ts +20 -0
- package/docs/API/20-server/10-file/10-createUnknownEntryInterface.ts +13 -0
- package/docs/API/20-server/10-file/10-ensureDirectory.ts +39 -0
- package/docs/API/20-server/10-file/10-ensureFile.ts +40 -0
- package/docs/API/20-server/10-file/10-exists.ts +36 -0
- package/docs/API/20-server/10-file/10-link.ts +51 -0
- package/docs/API/20-server/10-file/10-linkStat.ts +37 -0
- package/docs/API/20-server/10-file/10-makeDirectory.ts +41 -0
- package/docs/API/20-server/10-file/10-makeTemporaryDirectory.ts +35 -0
- package/docs/API/20-server/10-file/10-makeTemporaryFile.ts +40 -0
- package/docs/API/20-server/10-file/10-move.ts +51 -0
- package/docs/API/20-server/10-file/10-readDirectory.ts +52 -0
- package/docs/API/20-server/10-file/10-readFile.ts +38 -0
- package/docs/API/20-server/10-file/10-readJsonFile.ts +38 -0
- package/docs/API/20-server/10-file/10-readLink.ts +37 -0
- package/docs/API/20-server/10-file/10-readTextFile.ts +38 -0
- package/docs/API/20-server/10-file/10-realPath.ts +36 -0
- package/docs/API/20-server/10-file/10-relocate.ts +51 -0
- package/docs/API/20-server/10-file/10-remove.ts +40 -0
- package/docs/API/20-server/10-file/10-rename.ts +43 -0
- package/docs/API/20-server/10-file/10-setMode.ts +37 -0
- package/docs/API/20-server/10-file/10-setOwner.ts +38 -0
- package/docs/API/20-server/10-file/10-setTime.ts +42 -0
- package/docs/API/20-server/10-file/10-stat.ts +37 -0
- package/docs/API/20-server/10-file/10-symlink.ts +49 -0
- package/docs/API/20-server/10-file/10-truncate.ts +41 -0
- package/docs/API/20-server/10-file/10-walkDirectory.ts +75 -0
- package/docs/API/20-server/10-file/10-writeFile.ts +50 -0
- package/docs/API/20-server/10-file/10-writeJsonFile.ts +41 -0
- package/docs/API/20-server/10-file/10-writeTextFile.ts +49 -0
- package/docs/API/20-server/10-file/index.llms.md +144 -0
- package/docs/API/20-server/10-file/index.md +3 -0
- package/docs/API/20-server/20-common/10-environmentVariable.ts +57 -0
- package/docs/API/20-server/20-common/10-environmentVariableOrThrow.ts +21 -0
- package/docs/API/20-server/20-common/10-exitProcess.ts +9 -0
- package/docs/API/20-server/20-common/10-getCurrentDirectoryName.ts +10 -0
- package/docs/API/20-server/20-common/10-getCurrentWorkDirectory.ts +10 -0
- package/docs/API/20-server/20-common/10-getCurrentWorkDirectoryOrThrow.ts +10 -0
- package/docs/API/20-server/20-common/10-getProcessArguments.ts +10 -0
- package/docs/API/20-server/20-common/10-setCurrentWorkingDirectory.ts +14 -0
- package/docs/API/20-server/20-common/10-setCurrentWorkingDirectoryOrThrow.ts +12 -0
- package/docs/API/20-server/20-common/index.llms.md +40 -0
- package/docs/API/20-server/20-common/index.md +3 -0
- package/docs/API/20-server/30-dataStructure/10-file.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-fileExist.ts +27 -0
- package/docs/API/20-server/30-dataStructure/10-folder.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-folderExist.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-mimeType.ts +14 -0
- package/docs/API/20-server/30-dataStructure/10-size.ts +32 -0
- package/docs/API/20-server/30-dataStructure/index.llms.md +28 -0
- package/docs/API/20-server/30-dataStructure/index.md +3 -0
- package/docs/API/20-server/40-command/10-create.ts +39 -0
- package/docs/API/20-server/40-command/10-createArgument.ts +39 -0
- package/docs/API/20-server/40-command/10-createArrayOption.ts +36 -0
- package/docs/API/20-server/40-command/10-createBooleanOption.ts +28 -0
- package/docs/API/20-server/40-command/10-createOption.ts +46 -0
- package/docs/API/20-server/40-command/10-exec.ts +51 -0
- package/docs/API/20-server/40-command/10-execOptions.ts +30 -0
- package/docs/API/20-server/40-command/index.llms.md +32 -0
- package/docs/API/20-server/40-command/index.md +3 -0
- package/docs/API/20-server/index.md +3 -0
- package/docs/API.llms.md +20 -0
- package/package.json +14 -14
- package/skills/fundamental/SKILL.md +33 -33
- package/skills/fundamental/references/composition.md +9 -25
- package/skills/fundamental/references/constraints-and-validation.md +14 -51
- package/skills/fundamental/references/examples/iterations.ts +112 -0
- package/skills/fundamental/references/examples/result-selection.ts +65 -0
- package/skills/fundamental/references/iterations.md +24 -0
- package/skills/fundamental/references/results-and-errors.md +20 -45
- package/docs/API/10-lang/10-object/10-deepDiscriminate.ts +0 -63
|
@@ -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
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
## File
|
|
2
|
+
|
|
3
|
+
Lire et modifier les ressources du système de fichiers, leurs chemins et leurs métadonnées.
|
|
4
|
+
|
|
5
|
+
### [DSFile.appendFile](10-appendFile.ts)
|
|
6
|
+
|
|
7
|
+
Ajouter des octets à un fichier.
|
|
8
|
+
|
|
9
|
+
### [DSFile.appendTextFile](10-appendTextFile.ts)
|
|
10
|
+
|
|
11
|
+
Ajouter du texte à un fichier.
|
|
12
|
+
|
|
13
|
+
### [DSFile.copy](10-copy.ts)
|
|
14
|
+
|
|
15
|
+
Copier une ressource, récursivement pour un dossier.
|
|
16
|
+
|
|
17
|
+
### [DSFile.createEntryInterface](10-createEntryInterface.ts)
|
|
18
|
+
|
|
19
|
+
Inspecter une entrée et construire son interface adaptée.
|
|
20
|
+
|
|
21
|
+
### [DSFile.createFileInterface](10-createFileInterface.ts)
|
|
22
|
+
|
|
23
|
+
Construire une référence de fichier sans accès au disque.
|
|
24
|
+
|
|
25
|
+
### [DSFile.createFolderInterface](10-createFolderInterface.ts)
|
|
26
|
+
|
|
27
|
+
Construire une référence de dossier sans accès au disque.
|
|
28
|
+
|
|
29
|
+
### [DSFile.createUnknownEntryInterface](10-createUnknownEntryInterface.ts)
|
|
30
|
+
|
|
31
|
+
Construire une référence d’entrée de type inconnu sans accès au disque.
|
|
32
|
+
|
|
33
|
+
### [DSFile.ensureDirectory](10-ensureDirectory.ts)
|
|
34
|
+
|
|
35
|
+
Créer un dossier et ses parents si nécessaire.
|
|
36
|
+
|
|
37
|
+
### [DSFile.ensureFile](10-ensureFile.ts)
|
|
38
|
+
|
|
39
|
+
Créer un fichier absent sans tronquer un fichier existant.
|
|
40
|
+
|
|
41
|
+
### [DSFile.exists](10-exists.ts)
|
|
42
|
+
|
|
43
|
+
Vérifier l’accès à une entrée du système de fichiers.
|
|
44
|
+
|
|
45
|
+
### [DSFile.link](10-link.ts)
|
|
46
|
+
|
|
47
|
+
Créer un lien physique vers une entrée existante.
|
|
48
|
+
|
|
49
|
+
### [DSFile.linkStat](10-linkStat.ts)
|
|
50
|
+
|
|
51
|
+
Lire les métadonnées d’un lien lui-même.
|
|
52
|
+
|
|
53
|
+
### [DSFile.makeDirectory](10-makeDirectory.ts)
|
|
54
|
+
|
|
55
|
+
Créer un dossier, éventuellement avec ses parents.
|
|
56
|
+
|
|
57
|
+
### [DSFile.makeTemporaryDirectory](10-makeTemporaryDirectory.ts)
|
|
58
|
+
|
|
59
|
+
Créer un dossier temporaire avec un préfixe.
|
|
60
|
+
|
|
61
|
+
### [DSFile.makeTemporaryFile](10-makeTemporaryFile.ts)
|
|
62
|
+
|
|
63
|
+
Créer un fichier temporaire avec préfixe et suffixe.
|
|
64
|
+
|
|
65
|
+
### [DSFile.move](10-move.ts)
|
|
66
|
+
|
|
67
|
+
Déplacer une ressource vers un chemin de destination.
|
|
68
|
+
|
|
69
|
+
### [DSFile.readDirectory](10-readDirectory.ts)
|
|
70
|
+
|
|
71
|
+
Lister les chemins d’un dossier avec récursivité et résolution absolue optionnelles.
|
|
72
|
+
|
|
73
|
+
### [DSFile.readFile](10-readFile.ts)
|
|
74
|
+
|
|
75
|
+
Lire les octets d’un fichier.
|
|
76
|
+
|
|
77
|
+
### [DSFile.readJsonFile](10-readJsonFile.ts)
|
|
78
|
+
|
|
79
|
+
Lire et analyser un fichier JSON.
|
|
80
|
+
|
|
81
|
+
### [DSFile.readLink](10-readLink.ts)
|
|
82
|
+
|
|
83
|
+
Lire la cible d’un lien symbolique.
|
|
84
|
+
|
|
85
|
+
### [DSFile.readTextFile](10-readTextFile.ts)
|
|
86
|
+
|
|
87
|
+
Lire le contenu UTF-8 d'un fichier et distinguer les erreurs d'accès.
|
|
88
|
+
|
|
89
|
+
### [DSFile.realPath](10-realPath.ts)
|
|
90
|
+
|
|
91
|
+
Résoudre le chemin réel d’une entrée.
|
|
92
|
+
|
|
93
|
+
### [DSFile.relocate](10-relocate.ts)
|
|
94
|
+
|
|
95
|
+
Déplacer une entrée dans un autre dossier en conservant son nom.
|
|
96
|
+
|
|
97
|
+
### [DSFile.remove](10-remove.ts)
|
|
98
|
+
|
|
99
|
+
Supprimer une entrée, éventuellement récursivement.
|
|
100
|
+
|
|
101
|
+
### [DSFile.rename](10-rename.ts)
|
|
102
|
+
|
|
103
|
+
Renommer une entrée dans son dossier parent.
|
|
104
|
+
|
|
105
|
+
### [DSFile.setMode](10-setMode.ts)
|
|
106
|
+
|
|
107
|
+
Modifier les permissions d’une entrée.
|
|
108
|
+
|
|
109
|
+
### [DSFile.setOwner](10-setOwner.ts)
|
|
110
|
+
|
|
111
|
+
Modifier le propriétaire et le groupe d’une entrée.
|
|
112
|
+
|
|
113
|
+
### [DSFile.setTime](10-setTime.ts)
|
|
114
|
+
|
|
115
|
+
Modifier les dates d’accès et de modification d’une entrée.
|
|
116
|
+
|
|
117
|
+
### [DSFile.stat](10-stat.ts)
|
|
118
|
+
|
|
119
|
+
Lire les métadonnées d’une entrée.
|
|
120
|
+
|
|
121
|
+
### [DSFile.symlink](10-symlink.ts)
|
|
122
|
+
|
|
123
|
+
Créer un lien symbolique vers une cible.
|
|
124
|
+
|
|
125
|
+
### [DSFile.truncate](10-truncate.ts)
|
|
126
|
+
|
|
127
|
+
Tronquer ou étendre un fichier à une taille en octets.
|
|
128
|
+
|
|
129
|
+
### [DSFile.walkDirectory](10-walkDirectory.ts)
|
|
130
|
+
|
|
131
|
+
Parcourir les entrées d’un dossier sous forme d’interfaces.
|
|
132
|
+
|
|
133
|
+
### [DSFile.writeFile](10-writeFile.ts)
|
|
134
|
+
|
|
135
|
+
Écrire des octets dans un fichier.
|
|
136
|
+
|
|
137
|
+
### [DSFile.writeJsonFile](10-writeJsonFile.ts)
|
|
138
|
+
|
|
139
|
+
Sérialiser une valeur en JSON et l’écrire dans un fichier.
|
|
140
|
+
|
|
141
|
+
### [DSFile.writeTextFile](10-writeTextFile.ts)
|
|
142
|
+
|
|
143
|
+
Écrire du texte dans un fichier.
|
|
144
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.environmentVariable
|
|
3
|
+
*
|
|
4
|
+
* Charger et décoder une configuration issue de l’environnement.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
7
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
8
|
+
import * as DPath from "@duplojs/lang/path";
|
|
9
|
+
import * as DEither from "@duplojs/lang/either";
|
|
10
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
11
|
+
import * as DSDataStructure from "@duplojs/server/dataStructure";
|
|
12
|
+
|
|
13
|
+
const result = await DSCommon.environmentVariable(
|
|
14
|
+
{
|
|
15
|
+
PORT: DDataStructure.number(),
|
|
16
|
+
HOST: DDataStructure.string(),
|
|
17
|
+
INPUT: DSDataStructure.file(),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
// Les fichiers sont lus dans cet ordre. Une erreur de lecture est renvoyée.
|
|
21
|
+
includedEnvironmentFiles: [
|
|
22
|
+
DPath.declarePath(".env"),
|
|
23
|
+
DPath.declarePath(".env.local"),
|
|
24
|
+
],
|
|
25
|
+
// false : la première source gagne, en commençant par le runtime.
|
|
26
|
+
// true : les sources suivantes remplacent les précédentes.
|
|
27
|
+
override: false,
|
|
28
|
+
// true : ne pas répercuter les valeurs chargées sur l'environnement.
|
|
29
|
+
// Par défaut, l'environnement est mis à jour après validation réussie.
|
|
30
|
+
justRead: true,
|
|
31
|
+
// Les codecs serveur décodent aussi INPUT en interface de fichier.
|
|
32
|
+
codecs: DSDataStructure.codecsString,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (DEither.isRight(result)) {
|
|
37
|
+
const configuration = DEither.unwrapRight(result);
|
|
38
|
+
|
|
39
|
+
type _CheckPort = DCommon.ExpectType<
|
|
40
|
+
typeof configuration.PORT,
|
|
41
|
+
number,
|
|
42
|
+
"strict"
|
|
43
|
+
>;
|
|
44
|
+
|
|
45
|
+
// INPUT est une interface ; le codec seul ne vérifie pas l'existence.
|
|
46
|
+
const inputPath = configuration.INPUT.path;
|
|
47
|
+
} else if (DEither.hasInformation(result, "decode-error")) {
|
|
48
|
+
// Une variable absente ou invalide échoue au décodage de la shape.
|
|
49
|
+
const validationError = DEither.unwrapLeft(result);
|
|
50
|
+
} else {
|
|
51
|
+
// Un fichier d'environnement demandé n'a pas pu être lu : l'erreur
|
|
52
|
+
// conserve les catégories de readTextFile (absence, permission, etc.).
|
|
53
|
+
const readError = DEither.unwrapLeft(result);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Les références comme ${HOST} sont développées après fusion des sources,
|
|
57
|
+
// avant le décodage. La valeur finale dépend de l'environnement courant.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.environmentVariableOrThrow
|
|
3
|
+
*
|
|
4
|
+
* Charger une configuration typée ou lever une erreur.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
8
|
+
|
|
9
|
+
// Adapté au démarrage lorsque la configuration est indispensable.
|
|
10
|
+
const configuration = await DSCommon.environmentVariableOrThrow(
|
|
11
|
+
{
|
|
12
|
+
PORT: DDataStructure.number(),
|
|
13
|
+
HOST: DDataStructure.string(),
|
|
14
|
+
},
|
|
15
|
+
{ justRead: true },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// Une lecture ou un décodage en échec lève EnvironmentVariableError.
|
|
19
|
+
|
|
20
|
+
// Voir 10-environmentVariable.ts pour les sources, la priorité, les codecs
|
|
21
|
+
// et les effets de justRead ; cette variante applique les mêmes paramètres.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.getCurrentDirectoryName
|
|
3
|
+
*
|
|
4
|
+
* Obtenir le dossier absolu du module fourni.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
7
|
+
|
|
8
|
+
const moduleDirectory = DSCommon.getCurrentDirectoryName(import.meta);
|
|
9
|
+
|
|
10
|
+
// Ce chemin dépend du module, pas du répertoire de lancement.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.getCurrentWorkDirectory
|
|
3
|
+
*
|
|
4
|
+
* Obtenir le répertoire de travail courant sous forme de résultat.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
7
|
+
|
|
8
|
+
const result = DSCommon.getCurrentWorkDirectory();
|
|
9
|
+
|
|
10
|
+
// Le Right porte un chemin absolu ; le Left signale un échec du runtime.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.getCurrentWorkDirectoryOrThrow
|
|
3
|
+
*
|
|
4
|
+
* Obtenir le répertoire de travail courant ou lever une erreur.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
7
|
+
|
|
8
|
+
const directory = DSCommon.getCurrentWorkDirectoryOrThrow();
|
|
9
|
+
|
|
10
|
+
// Le chemin absolu dépend du dossier courant du processus.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.getProcessArguments
|
|
3
|
+
*
|
|
4
|
+
* Lire les arguments utilisateur du processus.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
7
|
+
|
|
8
|
+
const argumentsFromTerminal = DSCommon.getProcessArguments();
|
|
9
|
+
|
|
10
|
+
// Les entrées de lancement du runtime ne figurent pas dans ce tableau.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.setCurrentWorkingDirectory
|
|
3
|
+
*
|
|
4
|
+
* Changer le répertoire de travail et retourner un résultat.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
7
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
8
|
+
|
|
9
|
+
declare const directory: string & DPath.Absolute;
|
|
10
|
+
|
|
11
|
+
const result = DSCommon.setCurrentWorkingDirectory(directory);
|
|
12
|
+
|
|
13
|
+
// Un Left indique que le changement a échoué ; les chemins relatifs suivants
|
|
14
|
+
// sont résolus depuis le nouveau dossier uniquement en cas de succès.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommon.setCurrentWorkingDirectoryOrThrow
|
|
3
|
+
*
|
|
4
|
+
* Changer le répertoire de travail ou lever une erreur.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
7
|
+
import * as DSCommon from "@duplojs/server/common";
|
|
8
|
+
|
|
9
|
+
declare const directory: string & DPath.Absolute;
|
|
10
|
+
|
|
11
|
+
// Lève SetCurrentWorkingDirectoryError si le changement échoue.
|
|
12
|
+
DSCommon.setCurrentWorkingDirectoryOrThrow(directory);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
## Common
|
|
2
|
+
|
|
3
|
+
Accéder à la configuration, aux arguments et aux capacités du processus.
|
|
4
|
+
|
|
5
|
+
### [DSCommon.environmentVariable](10-environmentVariable.ts)
|
|
6
|
+
|
|
7
|
+
Charger et décoder une configuration issue de l’environnement.
|
|
8
|
+
|
|
9
|
+
### [DSCommon.environmentVariableOrThrow](10-environmentVariableOrThrow.ts)
|
|
10
|
+
|
|
11
|
+
Charger une configuration typée ou lever une erreur.
|
|
12
|
+
|
|
13
|
+
### [DSCommon.exitProcess](10-exitProcess.ts)
|
|
14
|
+
|
|
15
|
+
Terminer le processus avec un code de sortie.
|
|
16
|
+
|
|
17
|
+
### [DSCommon.getCurrentDirectoryName](10-getCurrentDirectoryName.ts)
|
|
18
|
+
|
|
19
|
+
Obtenir le dossier absolu du module fourni.
|
|
20
|
+
|
|
21
|
+
### [DSCommon.getCurrentWorkDirectory](10-getCurrentWorkDirectory.ts)
|
|
22
|
+
|
|
23
|
+
Obtenir le répertoire de travail courant sous forme de résultat.
|
|
24
|
+
|
|
25
|
+
### [DSCommon.getCurrentWorkDirectoryOrThrow](10-getCurrentWorkDirectoryOrThrow.ts)
|
|
26
|
+
|
|
27
|
+
Obtenir le répertoire de travail courant ou lever une erreur.
|
|
28
|
+
|
|
29
|
+
### [DSCommon.getProcessArguments](10-getProcessArguments.ts)
|
|
30
|
+
|
|
31
|
+
Lire les arguments utilisateur du processus.
|
|
32
|
+
|
|
33
|
+
### [DSCommon.setCurrentWorkingDirectory](10-setCurrentWorkingDirectory.ts)
|
|
34
|
+
|
|
35
|
+
Changer le répertoire de travail et retourner un résultat.
|
|
36
|
+
|
|
37
|
+
### [DSCommon.setCurrentWorkingDirectoryOrThrow](10-setCurrentWorkingDirectoryOrThrow.ts)
|
|
38
|
+
|
|
39
|
+
Changer le répertoire de travail ou lever une erreur.
|
|
40
|
+
|