@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.
- 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/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 +3 -1
- package/skills/fundamental/references/examples/iterations.ts +26 -13
- package/skills/fundamental/references/iterations.md +5 -1
|
@@ -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
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSDataStructure.file
|
|
3
|
+
*
|
|
4
|
+
* Décrire une interface de fichier serveur.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSDataStructure from "@duplojs/server/dataStructure";
|
|
7
|
+
|
|
8
|
+
declare const input: unknown;
|
|
9
|
+
|
|
10
|
+
const structure = DSDataStructure.file([DSDataStructure.fileExist()]);
|
|
11
|
+
const result = await structure.asyncDecode(DSDataStructure.codecsString, input);
|
|
12
|
+
|
|
13
|
+
// Le codec construit une interface ; la contrainte inspecte le disque.
|
|
14
|
+
// Le résultat distingue le décodage réussi de l’échec de validation.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSDataStructure.fileExist
|
|
3
|
+
*
|
|
4
|
+
* Exiger que l’interface représente un fichier existant.
|
|
5
|
+
*/
|
|
6
|
+
import * as DEither from "@duplojs/lang/either";
|
|
7
|
+
import * as DSDataStructure from "@duplojs/server/dataStructure";
|
|
8
|
+
import * as DSFile from "@duplojs/server/file";
|
|
9
|
+
|
|
10
|
+
declare const input: unknown;
|
|
11
|
+
|
|
12
|
+
const structure = DSDataStructure.file([DSDataStructure.fileExist()]);
|
|
13
|
+
|
|
14
|
+
// Le codec transforme le chemin textuel en FileInterface. La contrainte
|
|
15
|
+
// interroge ensuite le système de fichiers : utiliser asyncDecode.
|
|
16
|
+
const result = await structure.asyncDecode(DSDataStructure.codecsString, input);
|
|
17
|
+
|
|
18
|
+
if (DEither.isRight(result)) {
|
|
19
|
+
const file = DEither.unwrapRight(result);
|
|
20
|
+
|
|
21
|
+
// La validation a constaté l'existence au moment du contrôle ; le fichier
|
|
22
|
+
// peut avoir changé ou disparu avant cette lecture, qui peut encore échouer.
|
|
23
|
+
const readResult = await DSFile.readTextFile(file.path);
|
|
24
|
+
} else {
|
|
25
|
+
// Le décodage du chemin ou le contrôle de la ressource a échoué.
|
|
26
|
+
const validationError = DEither.unwrapLeft(result);
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSDataStructure.folder
|
|
3
|
+
*
|
|
4
|
+
* Décrire une interface de dossier serveur.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSDataStructure from "@duplojs/server/dataStructure";
|
|
7
|
+
|
|
8
|
+
declare const input: unknown;
|
|
9
|
+
|
|
10
|
+
const structure = DSDataStructure.folder([DSDataStructure.folderExist()]);
|
|
11
|
+
const result = await structure.asyncDecode(DSDataStructure.codecsString, input);
|
|
12
|
+
|
|
13
|
+
// Le codec construit une interface ; la contrainte inspecte le disque.
|
|
14
|
+
// Le résultat distingue le décodage réussi de l’échec de validation.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSDataStructure.folderExist
|
|
3
|
+
*
|
|
4
|
+
* Exiger que l’interface représente un dossier existant.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSDataStructure from "@duplojs/server/dataStructure";
|
|
7
|
+
|
|
8
|
+
declare const input: unknown;
|
|
9
|
+
|
|
10
|
+
const structure = DSDataStructure.folder([DSDataStructure.folderExist()]);
|
|
11
|
+
const result = await structure.asyncDecode(DSDataStructure.codecsString, input);
|
|
12
|
+
|
|
13
|
+
// La vérification asynchrone constate l’état du disque au moment du décodage.
|
|
14
|
+
// Le résultat distingue le décodage réussi de l’échec de validation.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSDataStructure.mimeType
|
|
3
|
+
*
|
|
4
|
+
* Contraindre le type MIME déduit de l’extension du fichier.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSDataStructure from "@duplojs/server/dataStructure";
|
|
7
|
+
|
|
8
|
+
declare const input: unknown;
|
|
9
|
+
|
|
10
|
+
const structure = DSDataStructure.file([DSDataStructure.mimeType("image/png")]);
|
|
11
|
+
const result = await structure.asyncDecode(DSDataStructure.codecsString, input);
|
|
12
|
+
|
|
13
|
+
// Le type MIME est déduit de l’extension, pas du contenu.
|
|
14
|
+
// Le résultat distingue le décodage réussi de l’échec de validation.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSDataStructure.size
|
|
3
|
+
*
|
|
4
|
+
* Contraindre la taille en octets d’un fichier.
|
|
5
|
+
*/
|
|
6
|
+
import * as DEither from "@duplojs/lang/either";
|
|
7
|
+
import * as DSDataStructure from "@duplojs/server/dataStructure";
|
|
8
|
+
import type * as DSFile from "@duplojs/server/file";
|
|
9
|
+
|
|
10
|
+
declare const file: DSFile.FileInterface;
|
|
11
|
+
|
|
12
|
+
const structure = DSDataStructure.file([
|
|
13
|
+
DSDataStructure.fileExist(),
|
|
14
|
+
DSDataStructure.size({
|
|
15
|
+
min: 1,
|
|
16
|
+
max: "1mb",
|
|
17
|
+
}),
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
// La taille est lue dans les métadonnées : asyncCheck est nécessaire même
|
|
21
|
+
// lorsque l'entrée est déjà une interface et ne nécessite pas de codec.
|
|
22
|
+
const result = await structure.asyncCheck(file);
|
|
23
|
+
|
|
24
|
+
if (DEither.isRight(result)) {
|
|
25
|
+
const checkedFile = DEither.unwrapRight(result);
|
|
26
|
+
|
|
27
|
+
// Les bornes sont vérifiées au moment du contrôle ; elles ne réservent pas
|
|
28
|
+
// le fichier et ne valident pas le contenu de ses octets.
|
|
29
|
+
const path = checkedFile.path;
|
|
30
|
+
} else {
|
|
31
|
+
const validationError = DEither.unwrapLeft(result);
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
## DataStructure
|
|
2
|
+
|
|
3
|
+
Décoder et valider les interfaces de fichiers et dossiers avec les contraintes serveur.
|
|
4
|
+
|
|
5
|
+
### [DSDataStructure.file](10-file.ts)
|
|
6
|
+
|
|
7
|
+
Décrire une interface de fichier serveur.
|
|
8
|
+
|
|
9
|
+
### [DSDataStructure.fileExist](10-fileExist.ts)
|
|
10
|
+
|
|
11
|
+
Exiger que l’interface représente un fichier existant.
|
|
12
|
+
|
|
13
|
+
### [DSDataStructure.folder](10-folder.ts)
|
|
14
|
+
|
|
15
|
+
Décrire une interface de dossier serveur.
|
|
16
|
+
|
|
17
|
+
### [DSDataStructure.folderExist](10-folderExist.ts)
|
|
18
|
+
|
|
19
|
+
Exiger que l’interface représente un dossier existant.
|
|
20
|
+
|
|
21
|
+
### [DSDataStructure.mimeType](10-mimeType.ts)
|
|
22
|
+
|
|
23
|
+
Contraindre le type MIME déduit de l’extension du fichier.
|
|
24
|
+
|
|
25
|
+
### [DSDataStructure.size](10-size.ts)
|
|
26
|
+
|
|
27
|
+
Contraindre la taille en octets d’un fichier.
|
|
28
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommand.create
|
|
3
|
+
*
|
|
4
|
+
* Construire une commande nommée à placer dans un arbre de commandes.
|
|
5
|
+
*/
|
|
6
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
7
|
+
import * as DSCommand from "@duplojs/server/command";
|
|
8
|
+
|
|
9
|
+
declare function inspect(source: string): Promise<void>;
|
|
10
|
+
|
|
11
|
+
const inspectCommand = DSCommand.create(
|
|
12
|
+
"inspect",
|
|
13
|
+
{
|
|
14
|
+
description: "Inspect a resource",
|
|
15
|
+
subjects: [
|
|
16
|
+
DSCommand.createArgument(
|
|
17
|
+
"source",
|
|
18
|
+
DDataStructure.string(),
|
|
19
|
+
),
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
async({ args }) => {
|
|
23
|
+
await inspect(args.source);
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const result = await DSCommand.exec(
|
|
28
|
+
{ subjects: [inspectCommand] },
|
|
29
|
+
() => {},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// La sous-commande sélectionnée exécute son callback sans exécuter celui du parent.
|
|
33
|
+
|
|
34
|
+
// Exemple avec un fichier cli.ts exécuté par tsx :
|
|
35
|
+
// tsx cli.ts inspect ./resources
|
|
36
|
+
// « inspect » sélectionne la sous-commande, puis source reçoit ./resources.
|
|
37
|
+
// Un tableau subjects contient des arguments OU des sous-commandes : ces
|
|
38
|
+
// deux catégories ne peuvent pas être mélangées dans une même commande.
|
|
39
|
+
// Les options du parent ne sont pas héritées par les sous-commandes.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommand.createArgument
|
|
3
|
+
*
|
|
4
|
+
* Déclarer un argument positionnel validé et transmis à une commande.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
7
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
8
|
+
import * as DSCommand from "@duplojs/server/command";
|
|
9
|
+
|
|
10
|
+
const command = DSCommand.create(
|
|
11
|
+
"generate",
|
|
12
|
+
{
|
|
13
|
+
subjects: [
|
|
14
|
+
DSCommand.createArgument(
|
|
15
|
+
"source",
|
|
16
|
+
DDataStructure.string(),
|
|
17
|
+
),
|
|
18
|
+
DSCommand.createArgument(
|
|
19
|
+
"destination",
|
|
20
|
+
DDataStructure.string(),
|
|
21
|
+
{ optional: true },
|
|
22
|
+
),
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
({ args }) => {
|
|
26
|
+
// Les arguments facultatifs suivent les arguments obligatoires.
|
|
27
|
+
type _CheckArgs = DCommon.ExpectType<
|
|
28
|
+
typeof args,
|
|
29
|
+
{
|
|
30
|
+
readonly source: string;
|
|
31
|
+
readonly destination: string | undefined;
|
|
32
|
+
},
|
|
33
|
+
"strict"
|
|
34
|
+
>;
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// Dans subjects, les arguments facultatifs suivent les obligatoires.
|
|
39
|
+
// Le même tableau ne peut pas mélanger arguments et sous-commandes.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommand.createArrayOption
|
|
3
|
+
*
|
|
4
|
+
* Déclarer une option contenant plusieurs valeurs décodées.
|
|
5
|
+
*/
|
|
6
|
+
import * as DArray from "@duplojs/lang/array";
|
|
7
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
8
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
9
|
+
import * as DSCommand from "@duplojs/server/command";
|
|
10
|
+
|
|
11
|
+
const command = DSCommand.create(
|
|
12
|
+
"inspect",
|
|
13
|
+
{
|
|
14
|
+
options: [
|
|
15
|
+
DSCommand.createArrayOption(
|
|
16
|
+
"include",
|
|
17
|
+
DDataStructure.string(),
|
|
18
|
+
{
|
|
19
|
+
required: true,
|
|
20
|
+
min: 1,
|
|
21
|
+
},
|
|
22
|
+
),
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
({ options }) => {
|
|
26
|
+
// La liste obligatoire et sa borne minimale garantissent un premier élément.
|
|
27
|
+
const first = DArray.first(options.include);
|
|
28
|
+
type _CheckFirst = DCommon.ExpectType<
|
|
29
|
+
typeof first,
|
|
30
|
+
string,
|
|
31
|
+
"strict"
|
|
32
|
+
>;
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// Par défaut les éléments d'une valeur sont séparés par des virgules.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSCommand.createBooleanOption
|
|
3
|
+
*
|
|
4
|
+
* Déclarer un flag représentant la présence d’une option.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
7
|
+
import * as DSCommand from "@duplojs/server/command";
|
|
8
|
+
|
|
9
|
+
const command = DSCommand.create(
|
|
10
|
+
"inspect",
|
|
11
|
+
{
|
|
12
|
+
options: [
|
|
13
|
+
DSCommand.createBooleanOption(
|
|
14
|
+
"verbose",
|
|
15
|
+
{ aliases: ["v"] },
|
|
16
|
+
),
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
({ options }) => {
|
|
20
|
+
type _CheckVerbose = DCommon.ExpectType<
|
|
21
|
+
typeof options.verbose,
|
|
22
|
+
boolean,
|
|
23
|
+
"strict"
|
|
24
|
+
>;
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// Le flag vaut false si absent, true si présent ; il n'accepte pas de valeur.
|