@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,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.makeTemporaryDirectory
|
|
3
|
+
*
|
|
4
|
+
* Créer un dossier temporaire avec un préfixe.
|
|
5
|
+
*/
|
|
6
|
+
import * as DSFile from "@duplojs/server/file";
|
|
7
|
+
import * as DEither from "@duplojs/lang/either";
|
|
8
|
+
import * as DPattern from "@duplojs/lang/pattern";
|
|
9
|
+
|
|
10
|
+
const result = await DSFile.makeTemporaryDirectory("export-");
|
|
11
|
+
|
|
12
|
+
// La position et le nom obtenus dépendent du runtime et du préfixe.
|
|
13
|
+
|
|
14
|
+
// L’information du Left identifie l’opération ; sa valeur précise la cause.
|
|
15
|
+
if (DEither.isLeft(result)) {
|
|
16
|
+
const error = DEither.unwrapLeft(result);
|
|
17
|
+
|
|
18
|
+
const diagnosis = DPattern.matchWithErrorOtherwise(
|
|
19
|
+
error,
|
|
20
|
+
{
|
|
21
|
+
"file-system-make-temporary-directory-permission-denied": () => "access-denied",
|
|
22
|
+
"file-system-make-temporary-directory-no-space": () => "no-space",
|
|
23
|
+
},
|
|
24
|
+
(otherError) => otherError,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Identifiants d’erreur déclarés pour cette opération :
|
|
29
|
+
// file-system-make-temporary-directory-permission-denied
|
|
30
|
+
// file-system-make-temporary-directory-not-directory
|
|
31
|
+
// file-system-make-temporary-directory-no-space
|
|
32
|
+
// file-system-make-temporary-directory-read-only
|
|
33
|
+
// file-system-make-temporary-directory-invalid-argument
|
|
34
|
+
// file-system-make-temporary-directory-too-many-open-files
|
|
35
|
+
// file-system-make-temporary-directory-error
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.makeTemporaryFile
|
|
3
|
+
*
|
|
4
|
+
* Créer un fichier temporaire avec préfixe et suffixe.
|
|
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 prefix: string & DPath.Segment;
|
|
12
|
+
declare const suffix: string & DPath.Segment;
|
|
13
|
+
|
|
14
|
+
const result = await DSFile.makeTemporaryFile(prefix, suffix);
|
|
15
|
+
|
|
16
|
+
// Le Right porte le chemin créé ; le Left porte l’erreur de création.
|
|
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-make-temporary-file-permission-denied": () => "access-denied",
|
|
26
|
+
"file-system-make-temporary-file-already-exists": () => "already-exists",
|
|
27
|
+
},
|
|
28
|
+
(otherError) => otherError,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Identifiants d’erreur déclarés pour cette opération :
|
|
33
|
+
// file-system-make-temporary-file-permission-denied
|
|
34
|
+
// file-system-make-temporary-file-already-exists
|
|
35
|
+
// file-system-make-temporary-file-not-directory
|
|
36
|
+
// file-system-make-temporary-file-no-space
|
|
37
|
+
// file-system-make-temporary-file-read-only
|
|
38
|
+
// file-system-make-temporary-file-invalid-argument
|
|
39
|
+
// file-system-make-temporary-file-too-many-open-files
|
|
40
|
+
// file-system-make-temporary-file-error
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.move
|
|
3
|
+
*
|
|
4
|
+
* Déplacer une ressource vers un chemin de destination.
|
|
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.move(source, destination);
|
|
17
|
+
|
|
18
|
+
// Forme curifiée
|
|
19
|
+
const pipedResult = await DCommon.pipe(
|
|
20
|
+
source,
|
|
21
|
+
DSFile.move(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-move-not-found": () => "missing",
|
|
34
|
+
"file-system-move-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-move-not-found
|
|
42
|
+
// file-system-move-permission-denied
|
|
43
|
+
// file-system-move-already-exists
|
|
44
|
+
// file-system-move-is-directory
|
|
45
|
+
// file-system-move-not-directory
|
|
46
|
+
// file-system-move-directory-not-empty
|
|
47
|
+
// file-system-move-read-only
|
|
48
|
+
// file-system-move-invalid-argument
|
|
49
|
+
// file-system-move-busy
|
|
50
|
+
// file-system-move-cross-device
|
|
51
|
+
// file-system-move-error
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.readDirectory
|
|
3
|
+
*
|
|
4
|
+
* Lister les chemins d’un dossier avec récursivité et résolution absolue optionnelles.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
7
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
8
|
+
import * as DEither from "@duplojs/lang/either";
|
|
9
|
+
import * as DPattern from "@duplojs/lang/pattern";
|
|
10
|
+
import * as DSFile from "@duplojs/server/file";
|
|
11
|
+
|
|
12
|
+
declare const directory: string & DPath.Path;
|
|
13
|
+
|
|
14
|
+
const result = await DSFile.readDirectory(
|
|
15
|
+
directory,
|
|
16
|
+
{
|
|
17
|
+
recursive: true,
|
|
18
|
+
absolute: true,
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
if (DEither.isRight(result)) {
|
|
23
|
+
const paths = DEither.unwrapRight(result);
|
|
24
|
+
|
|
25
|
+
type _CheckPaths = DCommon.ExpectType<
|
|
26
|
+
typeof paths,
|
|
27
|
+
readonly (string & DPath.Path & DPath.Absolute)[],
|
|
28
|
+
"strict"
|
|
29
|
+
>;
|
|
30
|
+
} else {
|
|
31
|
+
const error = DEither.unwrapLeft(result);
|
|
32
|
+
|
|
33
|
+
const diagnosis = DPattern.matchWithErrorOtherwise(
|
|
34
|
+
error,
|
|
35
|
+
{
|
|
36
|
+
"file-system-read-directory-not-found": () => "missing-directory",
|
|
37
|
+
"file-system-read-directory-permission-denied": () => "access-denied",
|
|
38
|
+
"file-system-read-directory-not-directory": () => "not-a-directory",
|
|
39
|
+
},
|
|
40
|
+
(otherError) => otherError,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Sans absolute, les chemins sont relatifs au dossier lu.
|
|
45
|
+
|
|
46
|
+
// Identifiants d’erreur déclarés pour cette opération :
|
|
47
|
+
// file-system-read-directory-not-found
|
|
48
|
+
// file-system-read-directory-permission-denied
|
|
49
|
+
// file-system-read-directory-not-directory
|
|
50
|
+
// file-system-read-directory-too-many-open-files
|
|
51
|
+
// file-system-read-directory-busy
|
|
52
|
+
// file-system-read-directory-error
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.readFile
|
|
3
|
+
*
|
|
4
|
+
* Lire les octets d’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.readFile(path);
|
|
14
|
+
|
|
15
|
+
// Le Right porte les octets lus ; le Left décrit l’échec 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-read-file-not-found": () => "missing",
|
|
25
|
+
"file-system-read-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-read-file-not-found
|
|
33
|
+
// file-system-read-file-permission-denied
|
|
34
|
+
// file-system-read-file-is-directory
|
|
35
|
+
// file-system-read-file-not-directory
|
|
36
|
+
// file-system-read-file-too-many-open-files
|
|
37
|
+
// file-system-read-file-busy
|
|
38
|
+
// file-system-read-file-error
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.readJsonFile
|
|
3
|
+
*
|
|
4
|
+
* Lire et analyser un fichier JSON.
|
|
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.readJsonFile(path);
|
|
14
|
+
|
|
15
|
+
// Le JSON obtenu doit encore être validé selon le contrat applicatif.
|
|
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-read-json-file-not-found": () => "missing",
|
|
25
|
+
"file-system-read-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-read-json-file-not-found
|
|
33
|
+
// file-system-read-json-file-permission-denied
|
|
34
|
+
// file-system-read-json-file-is-directory
|
|
35
|
+
// file-system-read-json-file-not-directory
|
|
36
|
+
// file-system-read-json-file-too-many-open-files
|
|
37
|
+
// file-system-read-json-file-busy
|
|
38
|
+
// file-system-read-json-file-error
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.readLink
|
|
3
|
+
*
|
|
4
|
+
* Lire la cible d’un lien symbolique.
|
|
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.readLink(path);
|
|
14
|
+
|
|
15
|
+
// Le résultat dépend de la cible enregistrée sur le système de fichiers.
|
|
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-read-link-not-found": () => "missing",
|
|
25
|
+
"file-system-read-link-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-read-link-not-found
|
|
33
|
+
// file-system-read-link-permission-denied
|
|
34
|
+
// file-system-read-link-invalid-argument
|
|
35
|
+
// file-system-read-link-not-directory
|
|
36
|
+
// file-system-read-link-too-many-open-files
|
|
37
|
+
// file-system-read-link-error
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.readTextFile
|
|
3
|
+
*
|
|
4
|
+
* Lire le contenu UTF-8 d'un fichier et distinguer les erreurs d'accès.
|
|
5
|
+
*/
|
|
6
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
7
|
+
import * as DEither from "@duplojs/lang/either";
|
|
8
|
+
import * as DPattern from "@duplojs/lang/pattern";
|
|
9
|
+
import * as DSFile from "@duplojs/server/file";
|
|
10
|
+
|
|
11
|
+
declare const configurationPath: string & DPath.Path;
|
|
12
|
+
|
|
13
|
+
const result = await DSFile.readTextFile(configurationPath);
|
|
14
|
+
|
|
15
|
+
if (DEither.isRight(result)) {
|
|
16
|
+
// Le contenu dépend du fichier au moment de la lecture.
|
|
17
|
+
const text = DEither.unwrapRight(result);
|
|
18
|
+
} else {
|
|
19
|
+
const error = DEither.unwrapLeft(result);
|
|
20
|
+
|
|
21
|
+
const diagnosis = DPattern.matchWithErrorOtherwise(
|
|
22
|
+
error,
|
|
23
|
+
{
|
|
24
|
+
"file-system-read-text-file-not-found": () => "missing-configuration",
|
|
25
|
+
"file-system-read-text-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-read-text-file-not-found
|
|
33
|
+
// file-system-read-text-file-permission-denied
|
|
34
|
+
// file-system-read-text-file-is-directory
|
|
35
|
+
// file-system-read-text-file-not-directory
|
|
36
|
+
// file-system-read-text-file-too-many-open-files
|
|
37
|
+
// file-system-read-text-file-busy
|
|
38
|
+
// file-system-read-text-file-error
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title DSFile.realPath
|
|
3
|
+
*
|
|
4
|
+
* Résoudre le chemin réel 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.realPath(path);
|
|
14
|
+
|
|
15
|
+
// Le résultat dépend de l’état du système de fichiers et des liens.
|
|
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-real-path-not-found": () => "missing",
|
|
25
|
+
"file-system-real-path-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-real-path-not-found
|
|
33
|
+
// file-system-real-path-permission-denied
|
|
34
|
+
// file-system-real-path-not-directory
|
|
35
|
+
// file-system-real-path-too-many-open-files
|
|
36
|
+
// file-system-real-path-error
|
|
@@ -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
|