@duplojs/server 0.0.0-stage → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +9 -0
- package/dist/_virtual/_rolldown/runtime.cjs +33 -0
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/command/argument.cjs +27 -0
- package/dist/command/argument.d.ts +18 -0
- package/dist/command/argument.mjs +24 -0
- package/dist/command/create.cjs +94 -0
- package/dist/command/create.d.ts +47 -0
- package/dist/command/create.mjs +88 -0
- package/dist/command/error.cjs +153 -0
- package/dist/command/error.d.ts +53 -0
- package/dist/command/error.mjs +140 -0
- package/dist/command/exec.cjs +19 -0
- package/dist/command/exec.d.ts +13 -0
- package/dist/command/exec.mjs +17 -0
- package/dist/command/execOptions.cjs +41 -0
- package/dist/command/execOptions.d.ts +14 -0
- package/dist/command/execOptions.mjs +37 -0
- package/dist/command/help.cjs +257 -0
- package/dist/command/help.d.ts +10 -0
- package/dist/command/help.mjs +244 -0
- package/dist/command/index.cjs +78 -0
- package/dist/command/index.d.ts +8 -0
- package/dist/command/index.mjs +45 -0
- package/dist/command/kind.cjs +7 -0
- package/dist/command/kind.d.ts +2 -0
- package/dist/command/kind.mjs +5 -0
- package/dist/command/options/base.cjs +68 -0
- package/dist/command/options/base.d.ts +24 -0
- package/dist/command/options/base.mjs +63 -0
- package/dist/command/options/defaults/array.cjs +35 -0
- package/dist/command/options/defaults/array.d.ts +24 -0
- package/dist/command/options/defaults/array.mjs +29 -0
- package/dist/command/options/defaults/boolean.cjs +14 -0
- package/dist/command/options/defaults/boolean.d.ts +11 -0
- package/dist/command/options/defaults/boolean.mjs +13 -0
- package/dist/command/options/defaults/index.d.ts +3 -0
- package/dist/command/options/defaults/simple.cjs +25 -0
- package/dist/command/options/defaults/simple.d.ts +16 -0
- package/dist/command/options/defaults/simple.mjs +22 -0
- package/dist/command/options/identifier.cjs +7 -0
- package/dist/command/options/identifier.d.ts +4 -0
- package/dist/command/options/identifier.mjs +5 -0
- package/dist/command/options/index.d.ts +4 -0
- package/dist/command/options/types/index.d.ts +1 -0
- package/dist/command/options/types/options.d.ts +9 -0
- package/dist/command/types/eligibleType.d.ts +4 -0
- package/dist/command/types/forbiddenDuplicateName.d.ts +11 -0
- package/dist/command/types/index.d.ts +2 -0
- package/dist/common/environmentVariable/expandEnvironmentVariables.cjs +27 -0
- package/dist/common/environmentVariable/expandEnvironmentVariables.d.ts +2 -0
- package/dist/common/environmentVariable/expandEnvironmentVariables.mjs +22 -0
- package/dist/common/environmentVariable/index.cjs +47 -0
- package/dist/common/environmentVariable/index.d.ts +16 -0
- package/dist/common/environmentVariable/index.mjs +41 -0
- package/dist/common/environmentVariable/overrideEnvironmentVariables.cjs +13 -0
- package/dist/common/environmentVariable/overrideEnvironmentVariables.d.ts +3 -0
- package/dist/common/environmentVariable/overrideEnvironmentVariables.mjs +9 -0
- package/dist/common/environmentVariable/parseEnvironmentFiles.cjs +32 -0
- package/dist/common/environmentVariable/parseEnvironmentFiles.d.ts +4 -0
- package/dist/common/environmentVariable/parseEnvironmentFiles.mjs +26 -0
- package/dist/common/environmentVariableOrThrow.cjs +23 -0
- package/dist/common/environmentVariableOrThrow.d.ts +12 -0
- package/dist/common/environmentVariableOrThrow.mjs +19 -0
- package/dist/common/exitProcess.cjs +7 -0
- package/dist/common/exitProcess.d.ts +6 -0
- package/dist/common/exitProcess.mjs +8 -0
- package/dist/common/getCurrentWorkDirectory.cjs +15 -0
- package/dist/common/getCurrentWorkDirectory.d.ts +8 -0
- package/dist/common/getCurrentWorkDirectory.mjs +11 -0
- package/dist/common/getCurrentWorkDirectoryOrThrow.cjs +25 -0
- package/dist/common/getCurrentWorkDirectoryOrThrow.d.ts +8 -0
- package/dist/common/getCurrentWorkDirectoryOrThrow.mjs +20 -0
- package/dist/common/getProcessArguments.cjs +18 -0
- package/dist/common/getProcessArguments.d.ts +6 -0
- package/dist/common/getProcessArguments.mjs +18 -0
- package/dist/common/index.cjs +41 -0
- package/dist/common/index.d.ts +8 -0
- package/dist/common/index.mjs +25 -0
- package/dist/common/setCurrentWorkingDirectory.cjs +11 -0
- package/dist/common/setCurrentWorkingDirectory.d.ts +8 -0
- package/dist/common/setCurrentWorkingDirectory.mjs +9 -0
- package/dist/common/setCurrentWorkingDirectoryOrThrow.cjs +23 -0
- package/dist/common/setCurrentWorkingDirectoryOrThrow.d.ts +8 -0
- package/dist/common/setCurrentWorkingDirectoryOrThrow.mjs +18 -0
- package/dist/dataStructure/common/codec/defaults/index.d.ts +2 -0
- package/dist/dataStructure/common/codec/defaults/json.cjs +14 -0
- package/dist/dataStructure/common/codec/defaults/json.d.ts +9 -0
- package/dist/dataStructure/common/codec/defaults/json.mjs +11 -0
- package/dist/dataStructure/common/codec/defaults/string.cjs +14 -0
- package/dist/dataStructure/common/codec/defaults/string.d.ts +13 -0
- package/dist/dataStructure/common/codec/defaults/string.mjs +11 -0
- package/dist/dataStructure/common/codec/index.d.ts +1 -0
- package/dist/dataStructure/common/error/defaultInterpreter.cjs +27 -0
- package/dist/dataStructure/common/error/defaultInterpreter.d.ts +64 -0
- package/dist/dataStructure/common/error/defaultInterpreter.mjs +24 -0
- package/dist/dataStructure/common/error/index.d.ts +1 -0
- package/dist/dataStructure/common/index.d.ts +2 -0
- package/dist/dataStructure/constraint/exist.cjs +19 -0
- package/dist/dataStructure/constraint/exist.d.ts +10 -0
- package/dist/dataStructure/constraint/exist.mjs +15 -0
- package/dist/dataStructure/constraint/index.d.ts +4 -0
- package/dist/dataStructure/constraint/mimeType.cjs +18 -0
- package/dist/dataStructure/constraint/mimeType.d.ts +11 -0
- package/dist/dataStructure/constraint/mimeType.mjs +14 -0
- package/dist/dataStructure/constraint/size.cjs +29 -0
- package/dist/dataStructure/constraint/size.d.ts +16 -0
- package/dist/dataStructure/constraint/size.mjs +24 -0
- package/dist/dataStructure/constraint/types/constraints.d.ts +10 -0
- package/dist/dataStructure/constraint/types/index.d.ts +1 -0
- package/dist/dataStructure/fundamentalType/file.cjs +11 -0
- package/dist/dataStructure/fundamentalType/file.d.ts +8 -0
- package/dist/dataStructure/fundamentalType/file.mjs +8 -0
- package/dist/dataStructure/fundamentalType/index.d.ts +2 -0
- package/dist/dataStructure/fundamentalType/types/fundamentalTypes.d.ts +6 -0
- package/dist/dataStructure/fundamentalType/types/index.d.ts +1 -0
- package/dist/dataStructure/helper/exist.cjs +7 -0
- package/dist/dataStructure/helper/exist.d.ts +2 -0
- package/dist/dataStructure/helper/exist.mjs +7 -0
- package/dist/dataStructure/helper/file.cjs +10 -0
- package/dist/dataStructure/helper/file.d.ts +3 -0
- package/dist/dataStructure/helper/file.mjs +8 -0
- package/dist/dataStructure/helper/index.d.ts +4 -0
- package/dist/dataStructure/helper/mimeType.cjs +7 -0
- package/dist/dataStructure/helper/mimeType.d.ts +2 -0
- package/dist/dataStructure/helper/mimeType.mjs +7 -0
- package/dist/dataStructure/helper/size.cjs +7 -0
- package/dist/dataStructure/helper/size.d.ts +2 -0
- package/dist/dataStructure/helper/size.mjs +7 -0
- package/dist/dataStructure/index.cjs +62 -0
- package/dist/dataStructure/index.d.ts +6 -0
- package/dist/dataStructure/index.mjs +38 -0
- package/dist/dataStructure/kind.cjs +7 -0
- package/dist/dataStructure/kind.d.ts +2 -0
- package/dist/dataStructure/kind.mjs +5 -0
- package/dist/dataStructure/type/file.cjs +14 -0
- package/dist/dataStructure/type/file.d.ts +11 -0
- package/dist/dataStructure/type/file.mjs +11 -0
- package/dist/dataStructure/type/index.d.ts +2 -0
- package/dist/dataStructure/type/types/index.d.ts +1 -0
- package/dist/dataStructure/type/types/types.d.ts +6 -0
- package/dist/file/appendFile.cjs +43 -0
- package/dist/file/appendFile.d.ts +11 -0
- package/dist/file/appendFile.mjs +41 -0
- package/dist/file/appendTextFile.cjs +43 -0
- package/dist/file/appendTextFile.d.ts +11 -0
- package/dist/file/appendTextFile.mjs +41 -0
- package/dist/file/copy.cjs +31 -0
- package/dist/file/copy.d.ts +11 -0
- package/dist/file/copy.mjs +29 -0
- package/dist/file/createEntryInterface.cjs +16 -0
- package/dist/file/createEntryInterface.d.ts +3 -0
- package/dist/file/createEntryInterface.mjs +13 -0
- package/dist/file/ensureDirectory.cjs +32 -0
- package/dist/file/ensureDirectory.d.ts +10 -0
- package/dist/file/ensureDirectory.mjs +30 -0
- package/dist/file/ensureFile.cjs +38 -0
- package/dist/file/ensureFile.d.ts +10 -0
- package/dist/file/ensureFile.mjs +36 -0
- package/dist/file/exists.cjs +29 -0
- package/dist/file/exists.d.ts +10 -0
- package/dist/file/exists.mjs +27 -0
- package/dist/file/fileInterface.cjs +74 -0
- package/dist/file/fileInterface.d.ts +30 -0
- package/dist/file/fileInterface.mjs +69 -0
- package/dist/file/folderInterface.cjs +74 -0
- package/dist/file/folderInterface.d.ts +32 -0
- package/dist/file/folderInterface.mjs +69 -0
- package/dist/file/index.cjs +122 -0
- package/dist/file/index.d.ts +36 -0
- package/dist/file/index.mjs +79 -0
- package/dist/file/link.cjs +44 -0
- package/dist/file/link.d.ts +11 -0
- package/dist/file/link.mjs +42 -0
- package/dist/file/linkStat.cjs +84 -0
- package/dist/file/linkStat.d.ts +11 -0
- package/dist/file/linkStat.mjs +80 -0
- package/dist/file/makeDirectory.cjs +36 -0
- package/dist/file/makeDirectory.d.ts +14 -0
- package/dist/file/makeDirectory.mjs +34 -0
- package/dist/file/makeTemporaryDirectory.cjs +30 -0
- package/dist/file/makeTemporaryDirectory.d.ts +9 -0
- package/dist/file/makeTemporaryDirectory.mjs +28 -0
- package/dist/file/makeTemporaryFile.cjs +45 -0
- package/dist/file/makeTemporaryFile.d.ts +10 -0
- package/dist/file/makeTemporaryFile.mjs +41 -0
- package/dist/file/move.cjs +45 -0
- package/dist/file/move.d.ts +11 -0
- package/dist/file/move.mjs +43 -0
- package/dist/file/readDirectory.cjs +20 -0
- package/dist/file/readDirectory.d.ts +14 -0
- package/dist/file/readDirectory.mjs +18 -0
- package/dist/file/readFile.cjs +33 -0
- package/dist/file/readFile.d.ts +10 -0
- package/dist/file/readFile.mjs +31 -0
- package/dist/file/readJsonFile.cjs +33 -0
- package/dist/file/readJsonFile.d.ts +11 -0
- package/dist/file/readJsonFile.mjs +31 -0
- package/dist/file/readLink.cjs +30 -0
- package/dist/file/readLink.d.ts +10 -0
- package/dist/file/readLink.mjs +28 -0
- package/dist/file/readTextFile.cjs +33 -0
- package/dist/file/readTextFile.d.ts +10 -0
- package/dist/file/readTextFile.mjs +31 -0
- package/dist/file/realPath.cjs +28 -0
- package/dist/file/realPath.d.ts +10 -0
- package/dist/file/realPath.mjs +26 -0
- package/dist/file/relocate.cjs +56 -0
- package/dist/file/relocate.d.ts +11 -0
- package/dist/file/relocate.mjs +53 -0
- package/dist/file/remove.cjs +38 -0
- package/dist/file/remove.d.ts +14 -0
- package/dist/file/remove.mjs +36 -0
- package/dist/file/rename.cjs +56 -0
- package/dist/file/rename.d.ts +11 -0
- package/dist/file/rename.mjs +53 -0
- package/dist/file/setMode.cjs +51 -0
- package/dist/file/setMode.d.ts +26 -0
- package/dist/file/setMode.mjs +48 -0
- package/dist/file/setOwner.cjs +37 -0
- package/dist/file/setOwner.d.ts +15 -0
- package/dist/file/setOwner.mjs +35 -0
- package/dist/file/setTime.cjs +39 -0
- package/dist/file/setTime.d.ts +17 -0
- package/dist/file/setTime.mjs +36 -0
- package/dist/file/stat.cjs +85 -0
- package/dist/file/stat.d.ts +42 -0
- package/dist/file/stat.mjs +81 -0
- package/dist/file/symlink.cjs +42 -0
- package/dist/file/symlink.d.ts +19 -0
- package/dist/file/symlink.mjs +40 -0
- package/dist/file/truncate.cjs +38 -0
- package/dist/file/truncate.d.ts +10 -0
- package/dist/file/truncate.mjs +35 -0
- package/dist/file/types/fileSystemEither.d.ts +2 -0
- package/dist/file/types/index.d.ts +1 -0
- package/dist/file/unknownEntryInterface.cjs +36 -0
- package/dist/file/unknownEntryInterface.d.ts +15 -0
- package/dist/file/unknownEntryInterface.mjs +33 -0
- package/dist/file/walkDirectory.cjs +34 -0
- package/dist/file/walkDirectory.d.ts +16 -0
- package/dist/file/walkDirectory.mjs +28 -0
- package/dist/file/writeFile.cjs +44 -0
- package/dist/file/writeFile.d.ts +11 -0
- package/dist/file/writeFile.mjs +42 -0
- package/dist/file/writeJsonFile.cjs +56 -0
- package/dist/file/writeJsonFile.d.ts +15 -0
- package/dist/file/writeJsonFile.mjs +53 -0
- package/dist/file/writeTextFile.cjs +44 -0
- package/dist/file/writeTextFile.d.ts +11 -0
- package/dist/file/writeTextFile.mjs +42 -0
- package/dist/implementor.cjs +64 -0
- package/dist/implementor.d.ts +35 -0
- package/dist/implementor.mjs +52 -0
- package/dist/index.cjs +74 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.mjs +14 -0
- package/dist/kind.cjs +7 -0
- package/dist/kind.d.ts +2 -0
- package/dist/kind.mjs +5 -0
- package/package.json +81 -3
- package/README.md +0 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
//#region scripts/file/appendTextFile.ts
|
|
4
|
+
function handleNodeAppendTextFileError(error) {
|
|
5
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
6
|
+
if (error.code === "ENOENT") return DEither.left("file-system-append-text-file-not-found", error);
|
|
7
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-append-text-file-permission-denied", error);
|
|
8
|
+
else if (error.code === "EISDIR") return DEither.left("file-system-append-text-file-is-directory", error);
|
|
9
|
+
else if (error.code === "ENOTDIR") return DEither.left("file-system-append-text-file-not-directory", error);
|
|
10
|
+
else if (error.code === "ENOSPC") return DEither.left("file-system-append-text-file-no-space", error);
|
|
11
|
+
else if (error.code === "EROFS") return DEither.left("file-system-append-text-file-read-only", error);
|
|
12
|
+
else if (error.code === "EINVAL") return DEither.left("file-system-append-text-file-invalid-argument", error);
|
|
13
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-append-text-file-too-many-open-files", error);
|
|
14
|
+
else if (error.code === "EBUSY") return DEither.left("file-system-append-text-file-busy", error);
|
|
15
|
+
}
|
|
16
|
+
return DEither.left("file-system-append-text-file-error", error);
|
|
17
|
+
}
|
|
18
|
+
function handleDenoAppendTextFileError(error) {
|
|
19
|
+
if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-append-text-file-not-found", error);
|
|
20
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-append-text-file-permission-denied", error);
|
|
21
|
+
if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-append-text-file-is-directory", error);
|
|
22
|
+
if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-append-text-file-not-directory", error);
|
|
23
|
+
if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-append-text-file-invalid-argument", error);
|
|
24
|
+
if (error instanceof Deno.errors.Busy) return DEither.left("file-system-append-text-file-busy", error);
|
|
25
|
+
return DEither.left("file-system-append-text-file-error", error);
|
|
26
|
+
}
|
|
27
|
+
const appendTextFileImplementation = implementFunction("appendTextFile", {
|
|
28
|
+
NODE: async (path, data) => {
|
|
29
|
+
return (await nodeFileSystem.value).appendFile(path, data).then(() => DEither.right("file-system-append-text-file")).catch(handleNodeAppendTextFileError);
|
|
30
|
+
},
|
|
31
|
+
DENO: (path, data) => Deno.writeTextFile(path, data, { append: true }).then(() => DEither.right("file-system-append-text-file")).catch(handleDenoAppendTextFileError)
|
|
32
|
+
});
|
|
33
|
+
function appendTextFile(...args) {
|
|
34
|
+
if (args.length === 1) {
|
|
35
|
+
const [data] = args;
|
|
36
|
+
return (path) => appendTextFileImplementation(path, data);
|
|
37
|
+
}
|
|
38
|
+
return appendTextFileImplementation(...args);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { appendTextFile };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_implementor = require("../implementor.cjs");
|
|
3
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
4
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
5
|
+
//#region scripts/file/copy.ts
|
|
6
|
+
function handleNodeCopyError(error) {
|
|
7
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
8
|
+
if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-copy-not-found", error);
|
|
9
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-copy-permission-denied", error);
|
|
10
|
+
else if (error.code === "EEXIST") return _duplojs_lang_either.left("file-system-copy-already-exists", error);
|
|
11
|
+
else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-copy-not-directory", error);
|
|
12
|
+
else if (error.code === "ENOSPC") return _duplojs_lang_either.left("file-system-copy-no-space", error);
|
|
13
|
+
else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-copy-read-only", error);
|
|
14
|
+
else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-copy-invalid-argument", error);
|
|
15
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-copy-too-many-open-files", error);
|
|
16
|
+
else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-copy-busy", error);
|
|
17
|
+
}
|
|
18
|
+
return _duplojs_lang_either.left("file-system-copy-error", error);
|
|
19
|
+
}
|
|
20
|
+
const copyImplementation = require_implementor.implementFunction("copy", { NODE: async (fromPath, toPath) => {
|
|
21
|
+
return (await require_implementor.nodeFileSystem.value).cp(fromPath, toPath, { recursive: true }).then(() => _duplojs_lang_either.right("file-system-copy")).catch(handleNodeCopyError);
|
|
22
|
+
} });
|
|
23
|
+
function copy(...args) {
|
|
24
|
+
if (args.length === 1) {
|
|
25
|
+
const [toPath] = args;
|
|
26
|
+
return (fromPath) => copyImplementation(fromPath, toPath);
|
|
27
|
+
}
|
|
28
|
+
return copyImplementation(...args);
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.copy = copy;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FileSystemEither } from './types';
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
4
|
+
export type CopyResult = FileSystemEither<DEither.Right<"copy", void> | DEither.Left<"copy-not-found", unknown> | DEither.Left<"copy-permission-denied", unknown> | DEither.Left<"copy-already-exists", unknown> | DEither.Left<"copy-not-directory", unknown> | DEither.Left<"copy-no-space", unknown> | DEither.Left<"copy-read-only", unknown> | DEither.Left<"copy-invalid-argument", unknown> | DEither.Left<"copy-too-many-open-files", unknown> | DEither.Left<"copy-busy", unknown> | DEither.Left<"copy-error", unknown>>;
|
|
5
|
+
declare module '../implementor' {
|
|
6
|
+
interface ServerFunction {
|
|
7
|
+
copy(fromPath: string & DPath.Path, toPath: string & DPath.Path): Promise<CopyResult>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare function copy(toPath: string & DPath.Path): (fromPath: string & DPath.Path) => Promise<CopyResult>;
|
|
11
|
+
export declare function copy(fromPath: string & DPath.Path, toPath: string & DPath.Path): Promise<CopyResult>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
//#region scripts/file/copy.ts
|
|
4
|
+
function handleNodeCopyError(error) {
|
|
5
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
6
|
+
if (error.code === "ENOENT") return DEither.left("file-system-copy-not-found", error);
|
|
7
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-copy-permission-denied", error);
|
|
8
|
+
else if (error.code === "EEXIST") return DEither.left("file-system-copy-already-exists", error);
|
|
9
|
+
else if (error.code === "ENOTDIR") return DEither.left("file-system-copy-not-directory", error);
|
|
10
|
+
else if (error.code === "ENOSPC") return DEither.left("file-system-copy-no-space", error);
|
|
11
|
+
else if (error.code === "EROFS") return DEither.left("file-system-copy-read-only", error);
|
|
12
|
+
else if (error.code === "EINVAL") return DEither.left("file-system-copy-invalid-argument", error);
|
|
13
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-copy-too-many-open-files", error);
|
|
14
|
+
else if (error.code === "EBUSY") return DEither.left("file-system-copy-busy", error);
|
|
15
|
+
}
|
|
16
|
+
return DEither.left("file-system-copy-error", error);
|
|
17
|
+
}
|
|
18
|
+
const copyImplementation = implementFunction("copy", { NODE: async (fromPath, toPath) => {
|
|
19
|
+
return (await nodeFileSystem.value).cp(fromPath, toPath, { recursive: true }).then(() => DEither.right("file-system-copy")).catch(handleNodeCopyError);
|
|
20
|
+
} });
|
|
21
|
+
function copy(...args) {
|
|
22
|
+
if (args.length === 1) {
|
|
23
|
+
const [toPath] = args;
|
|
24
|
+
return (fromPath) => copyImplementation(fromPath, toPath);
|
|
25
|
+
}
|
|
26
|
+
return copyImplementation(...args);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { copy };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_stat = require("./stat.cjs");
|
|
3
|
+
const require_fileInterface = require("./fileInterface.cjs");
|
|
4
|
+
const require_unknownEntryInterface = require("./unknownEntryInterface.cjs");
|
|
5
|
+
const require_folderInterface = require("./folderInterface.cjs");
|
|
6
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
7
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
8
|
+
let _duplojs_lang_pattern = require("@duplojs/lang/pattern");
|
|
9
|
+
_duplojs_lang_pattern = require_runtime.__toESM(_duplojs_lang_pattern, 1);
|
|
10
|
+
//#region scripts/file/createEntryInterface.ts
|
|
11
|
+
async function createEntryInterface(path) {
|
|
12
|
+
const result = await _duplojs_lang_either.rightAsyncPipe(require_stat.stat(path), _duplojs_lang_pattern.when(({ isFile }) => isFile, () => _duplojs_lang_either.right("file-interface", require_fileInterface.createFileInterface(path))), _duplojs_lang_pattern.when(({ isDirectory }) => isDirectory, () => _duplojs_lang_either.right("folder-interface", require_folderInterface.createFolderInterface(path))), _duplojs_lang_pattern.otherwise(() => _duplojs_lang_either.right("unknown-entry-interface", require_unknownEntryInterface.createUnknownEntryInterface(path))));
|
|
13
|
+
return _duplojs_lang_either.whenIsLeft(result, (value) => _duplojs_lang_either.left("create-entry-interface-error", value));
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.createEntryInterface = createEntryInterface;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
export declare function createEntryInterface(path: string & DPath.Path): Promise<DEither.Right<"file-interface", import('./fileInterface').FileInterface> | DEither.Right<"folder-interface", import('./folderInterface').FolderInterface> | DEither.Right<"unknown-entry-interface", import('./unknownEntryInterface').UnknownEntryInterface> | DEither.Left<"create-entry-interface-error", unknown>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { stat } from "./stat.mjs";
|
|
2
|
+
import { createFileInterface } from "./fileInterface.mjs";
|
|
3
|
+
import { createUnknownEntryInterface } from "./unknownEntryInterface.mjs";
|
|
4
|
+
import { createFolderInterface } from "./folderInterface.mjs";
|
|
5
|
+
import * as DEither from "@duplojs/lang/either";
|
|
6
|
+
import * as DPattern from "@duplojs/lang/pattern";
|
|
7
|
+
//#region scripts/file/createEntryInterface.ts
|
|
8
|
+
async function createEntryInterface(path) {
|
|
9
|
+
const result = await DEither.rightAsyncPipe(stat(path), DPattern.when(({ isFile }) => isFile, () => DEither.right("file-interface", createFileInterface(path))), DPattern.when(({ isDirectory }) => isDirectory, () => DEither.right("folder-interface", createFolderInterface(path))), DPattern.otherwise(() => DEither.right("unknown-entry-interface", createUnknownEntryInterface(path))));
|
|
10
|
+
return DEither.whenIsLeft(result, (value) => DEither.left("create-entry-interface-error", value));
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createEntryInterface };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_implementor = require("../implementor.cjs");
|
|
3
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
4
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
5
|
+
//#region scripts/file/ensureDirectory.ts
|
|
6
|
+
function handleNodeEnsureDirectoryError(error) {
|
|
7
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
8
|
+
if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-ensure-directory-permission-denied", error);
|
|
9
|
+
else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-ensure-directory-not-directory", error);
|
|
10
|
+
else if (error.code === "ENOSPC") return _duplojs_lang_either.left("file-system-ensure-directory-no-space", error);
|
|
11
|
+
else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-ensure-directory-read-only", error);
|
|
12
|
+
else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-ensure-directory-invalid-argument", error);
|
|
13
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-ensure-directory-too-many-open-files", error);
|
|
14
|
+
else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-ensure-directory-busy", error);
|
|
15
|
+
}
|
|
16
|
+
return _duplojs_lang_either.left("file-system-ensure-directory-error", error);
|
|
17
|
+
}
|
|
18
|
+
function handleDenoEnsureDirectoryError(error) {
|
|
19
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-ensure-directory-permission-denied", error);
|
|
20
|
+
if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-ensure-directory-not-directory", error);
|
|
21
|
+
if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-ensure-directory-invalid-argument", error);
|
|
22
|
+
if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-ensure-directory-busy", error);
|
|
23
|
+
return _duplojs_lang_either.left("file-system-ensure-directory-error", error);
|
|
24
|
+
}
|
|
25
|
+
const ensureDirectory = require_implementor.implementFunction("ensureDirectory", {
|
|
26
|
+
NODE: async (path) => {
|
|
27
|
+
return (await require_implementor.nodeFileSystem.value).mkdir(path, { recursive: true }).then(() => _duplojs_lang_either.right("file-system-ensure-directory")).catch(handleNodeEnsureDirectoryError);
|
|
28
|
+
},
|
|
29
|
+
DENO: (path) => Deno.mkdir(path, { recursive: true }).then(() => _duplojs_lang_either.right("file-system-ensure-directory")).catch(handleDenoEnsureDirectoryError)
|
|
30
|
+
});
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.ensureDirectory = ensureDirectory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FileSystemEither } from './types';
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
4
|
+
export type EnsureDirectoryResult = FileSystemEither<DEither.Right<"ensure-directory", void> | DEither.Left<"ensure-directory-permission-denied", unknown> | DEither.Left<"ensure-directory-not-directory", unknown> | DEither.Left<"ensure-directory-no-space", unknown> | DEither.Left<"ensure-directory-read-only", unknown> | DEither.Left<"ensure-directory-invalid-argument", unknown> | DEither.Left<"ensure-directory-too-many-open-files", unknown> | DEither.Left<"ensure-directory-busy", unknown> | DEither.Left<"ensure-directory-error", unknown>>;
|
|
5
|
+
declare module '../implementor' {
|
|
6
|
+
interface ServerFunction {
|
|
7
|
+
ensureDirectory(path: string & DPath.Path): Promise<EnsureDirectoryResult>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const ensureDirectory: (path: string & DPath.Path) => Promise<EnsureDirectoryResult>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
//#region scripts/file/ensureDirectory.ts
|
|
4
|
+
function handleNodeEnsureDirectoryError(error) {
|
|
5
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
6
|
+
if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-ensure-directory-permission-denied", error);
|
|
7
|
+
else if (error.code === "ENOTDIR") return DEither.left("file-system-ensure-directory-not-directory", error);
|
|
8
|
+
else if (error.code === "ENOSPC") return DEither.left("file-system-ensure-directory-no-space", error);
|
|
9
|
+
else if (error.code === "EROFS") return DEither.left("file-system-ensure-directory-read-only", error);
|
|
10
|
+
else if (error.code === "EINVAL") return DEither.left("file-system-ensure-directory-invalid-argument", error);
|
|
11
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-ensure-directory-too-many-open-files", error);
|
|
12
|
+
else if (error.code === "EBUSY") return DEither.left("file-system-ensure-directory-busy", error);
|
|
13
|
+
}
|
|
14
|
+
return DEither.left("file-system-ensure-directory-error", error);
|
|
15
|
+
}
|
|
16
|
+
function handleDenoEnsureDirectoryError(error) {
|
|
17
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-ensure-directory-permission-denied", error);
|
|
18
|
+
if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-ensure-directory-not-directory", error);
|
|
19
|
+
if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-ensure-directory-invalid-argument", error);
|
|
20
|
+
if (error instanceof Deno.errors.Busy) return DEither.left("file-system-ensure-directory-busy", error);
|
|
21
|
+
return DEither.left("file-system-ensure-directory-error", error);
|
|
22
|
+
}
|
|
23
|
+
const ensureDirectory = implementFunction("ensureDirectory", {
|
|
24
|
+
NODE: async (path) => {
|
|
25
|
+
return (await nodeFileSystem.value).mkdir(path, { recursive: true }).then(() => DEither.right("file-system-ensure-directory")).catch(handleNodeEnsureDirectoryError);
|
|
26
|
+
},
|
|
27
|
+
DENO: (path) => Deno.mkdir(path, { recursive: true }).then(() => DEither.right("file-system-ensure-directory")).catch(handleDenoEnsureDirectoryError)
|
|
28
|
+
});
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ensureDirectory };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_implementor = require("../implementor.cjs");
|
|
3
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
4
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
5
|
+
//#region scripts/file/ensureFile.ts
|
|
6
|
+
function handleNodeEnsureFileError(error) {
|
|
7
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
8
|
+
if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-ensure-file-permission-denied", error);
|
|
9
|
+
else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-ensure-file-is-directory", error);
|
|
10
|
+
else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-ensure-file-not-directory", error);
|
|
11
|
+
else if (error.code === "ENOSPC") return _duplojs_lang_either.left("file-system-ensure-file-no-space", error);
|
|
12
|
+
else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-ensure-file-read-only", error);
|
|
13
|
+
else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-ensure-file-invalid-argument", error);
|
|
14
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-ensure-file-too-many-open-files", error);
|
|
15
|
+
else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-ensure-file-busy", error);
|
|
16
|
+
}
|
|
17
|
+
return _duplojs_lang_either.left("file-system-ensure-file-error", error);
|
|
18
|
+
}
|
|
19
|
+
function handleDenoEnsureFileError(error) {
|
|
20
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-ensure-file-permission-denied", error);
|
|
21
|
+
if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-ensure-file-is-directory", error);
|
|
22
|
+
if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-ensure-file-not-directory", error);
|
|
23
|
+
if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-ensure-file-invalid-argument", error);
|
|
24
|
+
if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-ensure-file-busy", error);
|
|
25
|
+
return _duplojs_lang_either.left("file-system-ensure-file-error", error);
|
|
26
|
+
}
|
|
27
|
+
const ensureFile = require_implementor.implementFunction("ensureFile", {
|
|
28
|
+
NODE: async (path) => {
|
|
29
|
+
return (await require_implementor.nodeFileSystem.value).open(path, "a").then((fh) => fh.close()).then(() => _duplojs_lang_either.right("file-system-ensure-file")).catch(handleNodeEnsureFileError);
|
|
30
|
+
},
|
|
31
|
+
DENO: (path) => Deno.open(path, {
|
|
32
|
+
write: true,
|
|
33
|
+
create: true,
|
|
34
|
+
append: true
|
|
35
|
+
}).then((fh) => void fh.close()).then(() => _duplojs_lang_either.right("file-system-ensure-file")).catch(handleDenoEnsureFileError)
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.ensureFile = ensureFile;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FileSystemEither } from './types';
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
4
|
+
export type EnsureFileResult = FileSystemEither<DEither.Right<"ensure-file", void> | DEither.Left<"ensure-file-permission-denied", unknown> | DEither.Left<"ensure-file-is-directory", unknown> | DEither.Left<"ensure-file-not-directory", unknown> | DEither.Left<"ensure-file-no-space", unknown> | DEither.Left<"ensure-file-read-only", unknown> | DEither.Left<"ensure-file-invalid-argument", unknown> | DEither.Left<"ensure-file-too-many-open-files", unknown> | DEither.Left<"ensure-file-busy", unknown> | DEither.Left<"ensure-file-error", unknown>>;
|
|
5
|
+
declare module '../implementor' {
|
|
6
|
+
interface ServerFunction {
|
|
7
|
+
ensureFile(path: string & DPath.Path): Promise<EnsureFileResult>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const ensureFile: (path: string & DPath.Path) => Promise<EnsureFileResult>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
//#region scripts/file/ensureFile.ts
|
|
4
|
+
function handleNodeEnsureFileError(error) {
|
|
5
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
6
|
+
if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-ensure-file-permission-denied", error);
|
|
7
|
+
else if (error.code === "EISDIR") return DEither.left("file-system-ensure-file-is-directory", error);
|
|
8
|
+
else if (error.code === "ENOTDIR") return DEither.left("file-system-ensure-file-not-directory", error);
|
|
9
|
+
else if (error.code === "ENOSPC") return DEither.left("file-system-ensure-file-no-space", error);
|
|
10
|
+
else if (error.code === "EROFS") return DEither.left("file-system-ensure-file-read-only", error);
|
|
11
|
+
else if (error.code === "EINVAL") return DEither.left("file-system-ensure-file-invalid-argument", error);
|
|
12
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-ensure-file-too-many-open-files", error);
|
|
13
|
+
else if (error.code === "EBUSY") return DEither.left("file-system-ensure-file-busy", error);
|
|
14
|
+
}
|
|
15
|
+
return DEither.left("file-system-ensure-file-error", error);
|
|
16
|
+
}
|
|
17
|
+
function handleDenoEnsureFileError(error) {
|
|
18
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-ensure-file-permission-denied", error);
|
|
19
|
+
if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-ensure-file-is-directory", error);
|
|
20
|
+
if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-ensure-file-not-directory", error);
|
|
21
|
+
if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-ensure-file-invalid-argument", error);
|
|
22
|
+
if (error instanceof Deno.errors.Busy) return DEither.left("file-system-ensure-file-busy", error);
|
|
23
|
+
return DEither.left("file-system-ensure-file-error", error);
|
|
24
|
+
}
|
|
25
|
+
const ensureFile = implementFunction("ensureFile", {
|
|
26
|
+
NODE: async (path) => {
|
|
27
|
+
return (await nodeFileSystem.value).open(path, "a").then((fh) => fh.close()).then(() => DEither.right("file-system-ensure-file")).catch(handleNodeEnsureFileError);
|
|
28
|
+
},
|
|
29
|
+
DENO: (path) => Deno.open(path, {
|
|
30
|
+
write: true,
|
|
31
|
+
create: true,
|
|
32
|
+
append: true
|
|
33
|
+
}).then((fh) => void fh.close()).then(() => DEither.right("file-system-ensure-file")).catch(handleDenoEnsureFileError)
|
|
34
|
+
});
|
|
35
|
+
//#endregion
|
|
36
|
+
export { ensureFile };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_implementor = require("../implementor.cjs");
|
|
3
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
4
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
5
|
+
//#region scripts/file/exists.ts
|
|
6
|
+
function handleNodeExistsError(error) {
|
|
7
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
8
|
+
if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-exists-not-found", error);
|
|
9
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-exists-permission-denied", error);
|
|
10
|
+
else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-exists-not-directory", error);
|
|
11
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-exists-too-many-open-files", error);
|
|
12
|
+
}
|
|
13
|
+
return _duplojs_lang_either.left("file-system-exists-error", error);
|
|
14
|
+
}
|
|
15
|
+
function handleDenoExistsError(error) {
|
|
16
|
+
if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-exists-not-found", error);
|
|
17
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-exists-permission-denied", error);
|
|
18
|
+
if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-exists-not-directory", error);
|
|
19
|
+
return _duplojs_lang_either.left("file-system-exists-error", error);
|
|
20
|
+
}
|
|
21
|
+
const exists = require_implementor.implementFunction("exists", {
|
|
22
|
+
NODE: async (path) => {
|
|
23
|
+
return (await require_implementor.nodeFileSystem.value).access(path).then(() => _duplojs_lang_either.right("file-system-exists")).catch(handleNodeExistsError);
|
|
24
|
+
},
|
|
25
|
+
DENO: (path) => Deno.stat(path).then(() => _duplojs_lang_either.right("file-system-exists")).catch(handleDenoExistsError),
|
|
26
|
+
BUN: (path) => Bun.file(path).exists().then((value) => value ? _duplojs_lang_either.right("file-system-exists") : _duplojs_lang_either.left("file-system-exists-not-found", /* @__PURE__ */ new Error("Path does not exist"))).catch(handleNodeExistsError)
|
|
27
|
+
});
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.exists = exists;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FileSystemEither } from './types';
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
import type * as DPath from "@duplojs/lang/path";
|
|
4
|
+
export type ExistsResult = FileSystemEither<DEither.Right<"exists", void> | DEither.Left<"exists-not-found", unknown> | DEither.Left<"exists-permission-denied", unknown> | DEither.Left<"exists-not-directory", unknown> | DEither.Left<"exists-too-many-open-files", unknown> | DEither.Left<"exists-error", unknown>>;
|
|
5
|
+
declare module '../implementor' {
|
|
6
|
+
interface ServerFunction {
|
|
7
|
+
exists(path: string & DPath.Path): Promise<ExistsResult>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const exists: (path: string & DPath.Path) => Promise<ExistsResult>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
//#region scripts/file/exists.ts
|
|
4
|
+
function handleNodeExistsError(error) {
|
|
5
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
6
|
+
if (error.code === "ENOENT") return DEither.left("file-system-exists-not-found", error);
|
|
7
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-exists-permission-denied", error);
|
|
8
|
+
else if (error.code === "ENOTDIR") return DEither.left("file-system-exists-not-directory", error);
|
|
9
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-exists-too-many-open-files", error);
|
|
10
|
+
}
|
|
11
|
+
return DEither.left("file-system-exists-error", error);
|
|
12
|
+
}
|
|
13
|
+
function handleDenoExistsError(error) {
|
|
14
|
+
if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-exists-not-found", error);
|
|
15
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-exists-permission-denied", error);
|
|
16
|
+
if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-exists-not-directory", error);
|
|
17
|
+
return DEither.left("file-system-exists-error", error);
|
|
18
|
+
}
|
|
19
|
+
const exists = implementFunction("exists", {
|
|
20
|
+
NODE: async (path) => {
|
|
21
|
+
return (await nodeFileSystem.value).access(path).then(() => DEither.right("file-system-exists")).catch(handleNodeExistsError);
|
|
22
|
+
},
|
|
23
|
+
DENO: (path) => Deno.stat(path).then(() => DEither.right("file-system-exists")).catch(handleDenoExistsError),
|
|
24
|
+
BUN: (path) => Bun.file(path).exists().then((value) => value ? DEither.right("file-system-exists") : DEither.left("file-system-exists-not-found", /* @__PURE__ */ new Error("Path does not exist"))).catch(handleNodeExistsError)
|
|
25
|
+
});
|
|
26
|
+
//#endregion
|
|
27
|
+
export { exists };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_kind = require("../kind.cjs");
|
|
3
|
+
const require_stat = require("./stat.cjs");
|
|
4
|
+
const require_rename = require("./rename.cjs");
|
|
5
|
+
const require_exists = require("./exists.cjs");
|
|
6
|
+
const require_move = require("./move.cjs");
|
|
7
|
+
const require_remove = require("./remove.cjs");
|
|
8
|
+
const require_relocate = require("./relocate.cjs");
|
|
9
|
+
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
10
|
+
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
11
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
12
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
13
|
+
let _duplojs_lang_path = require("@duplojs/lang/path");
|
|
14
|
+
_duplojs_lang_path = require_runtime.__toESM(_duplojs_lang_path, 1);
|
|
15
|
+
//#region scripts/file/fileInterface.ts
|
|
16
|
+
const fileInterfaceKind = require_kind.createKind("fileInterface");
|
|
17
|
+
function createFileInterface(path) {
|
|
18
|
+
function getName() {
|
|
19
|
+
return _duplojs_lang_path.getBaseName(path);
|
|
20
|
+
}
|
|
21
|
+
function getExtension(params) {
|
|
22
|
+
return _duplojs_lang_path.getExtensionName(path, params);
|
|
23
|
+
}
|
|
24
|
+
function getMimeType() {
|
|
25
|
+
const extension = getExtension();
|
|
26
|
+
if (!extension) return null;
|
|
27
|
+
return _duplojs_lang_common.mimeType.get(extension) ?? null;
|
|
28
|
+
}
|
|
29
|
+
function getParentPath() {
|
|
30
|
+
return _duplojs_lang_path.getParentFolderPath(path);
|
|
31
|
+
}
|
|
32
|
+
function localExists() {
|
|
33
|
+
return require_exists.exists(path);
|
|
34
|
+
}
|
|
35
|
+
function localRename(newName) {
|
|
36
|
+
return _duplojs_lang_common.asyncPipe(require_rename.rename(path, newName), _duplojs_lang_either.whenIsRight(_duplojs_lang_common.innerPipe(createFileInterface, (value) => _duplojs_lang_either.right("file-system-rename", value))));
|
|
37
|
+
}
|
|
38
|
+
function localRelocate(newParentPath) {
|
|
39
|
+
return _duplojs_lang_common.asyncPipe(require_relocate.relocate(path, newParentPath), _duplojs_lang_either.whenIsRight(_duplojs_lang_common.innerPipe(createFileInterface, (value) => _duplojs_lang_either.right("file-system-relocate", value))));
|
|
40
|
+
}
|
|
41
|
+
function localMove(newPath) {
|
|
42
|
+
return _duplojs_lang_common.asyncPipe(require_move.move(path, newPath), _duplojs_lang_either.whenIsRight(() => _duplojs_lang_either.right("file-system-move", createFileInterface(newPath))));
|
|
43
|
+
}
|
|
44
|
+
function localRemove() {
|
|
45
|
+
return require_remove.remove(path);
|
|
46
|
+
}
|
|
47
|
+
function localStat() {
|
|
48
|
+
return require_stat.stat(path);
|
|
49
|
+
}
|
|
50
|
+
function isFile() {
|
|
51
|
+
return _duplojs_lang_common.asyncPipe(localStat(), _duplojs_lang_either.whenHasInformationOtherwise("file-system-stat", ({ isFile }) => isFile, _duplojs_lang_common.justReturn(false)));
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
path,
|
|
55
|
+
getName,
|
|
56
|
+
getExtension,
|
|
57
|
+
getMimeType,
|
|
58
|
+
getParentPath,
|
|
59
|
+
rename: localRename,
|
|
60
|
+
exists: localExists,
|
|
61
|
+
relocate: localRelocate,
|
|
62
|
+
remove: localRemove,
|
|
63
|
+
move: localMove,
|
|
64
|
+
stat: localStat,
|
|
65
|
+
isFile,
|
|
66
|
+
[fileInterfaceKind.runTimeKey]: null
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function isFileInterface(input) {
|
|
70
|
+
return fileInterfaceKind.has(input);
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
exports.createFileInterface = createFileInterface;
|
|
74
|
+
exports.isFileInterface = isFileInterface;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RenameResult } from './rename';
|
|
2
|
+
import { ExistsResult } from './exists';
|
|
3
|
+
import { MoveResult } from './move';
|
|
4
|
+
import { RemoveResult } from './remove';
|
|
5
|
+
import { StatResult } from './stat';
|
|
6
|
+
import { RelocateResult } from './relocate';
|
|
7
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
8
|
+
import * as DPath from "@duplojs/lang/path";
|
|
9
|
+
import * as DEither from "@duplojs/lang/either";
|
|
10
|
+
declare const fileInterfaceKind: DKind.Handler<DKind.Definition<"@DuplojsServer/fileInterface", unknown>>;
|
|
11
|
+
type FileInterfaceRenameResult = Exclude<RenameResult, DEither.Right> | DEither.Right<"file-system-rename", FileInterface>;
|
|
12
|
+
type FileInterfaceRelocateResult = Exclude<RelocateResult, DEither.Right> | DEither.Right<"file-system-relocate", FileInterface>;
|
|
13
|
+
type FileInterfaceMoveResult = Exclude<MoveResult, DEither.Right> | DEither.Right<"file-system-move", FileInterface>;
|
|
14
|
+
export interface FileInterface extends DKind.Kind<typeof fileInterfaceKind> {
|
|
15
|
+
path: string & DPath.Path;
|
|
16
|
+
getName(): (string & DPath.Segment) | null;
|
|
17
|
+
getMimeType(): string | null;
|
|
18
|
+
getExtension(params?: DPath.GetExtensionNameParams): (string & DPath.Segment) | null;
|
|
19
|
+
getParentPath(): (string & DPath.Path) | null;
|
|
20
|
+
rename(newName: string & DPath.Segment): Promise<FileInterfaceRenameResult>;
|
|
21
|
+
relocate(parentPath: string & DPath.Path): Promise<FileInterfaceRelocateResult>;
|
|
22
|
+
move(newPath: string & DPath.Path): Promise<FileInterfaceMoveResult>;
|
|
23
|
+
exists(): Promise<ExistsResult>;
|
|
24
|
+
remove(): Promise<RemoveResult>;
|
|
25
|
+
stat(): Promise<StatResult>;
|
|
26
|
+
isFile(): Promise<boolean>;
|
|
27
|
+
}
|
|
28
|
+
export declare function createFileInterface(path: string & DPath.Path): FileInterface;
|
|
29
|
+
export declare function isFileInterface(input: unknown): input is FileInterface;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createKind } from "../kind.mjs";
|
|
2
|
+
import { stat } from "./stat.mjs";
|
|
3
|
+
import { rename } from "./rename.mjs";
|
|
4
|
+
import { exists } from "./exists.mjs";
|
|
5
|
+
import { move } from "./move.mjs";
|
|
6
|
+
import { remove } from "./remove.mjs";
|
|
7
|
+
import { relocate } from "./relocate.mjs";
|
|
8
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
9
|
+
import * as DEither from "@duplojs/lang/either";
|
|
10
|
+
import * as DPath from "@duplojs/lang/path";
|
|
11
|
+
//#region scripts/file/fileInterface.ts
|
|
12
|
+
const fileInterfaceKind = createKind("fileInterface");
|
|
13
|
+
function createFileInterface(path) {
|
|
14
|
+
function getName() {
|
|
15
|
+
return DPath.getBaseName(path);
|
|
16
|
+
}
|
|
17
|
+
function getExtension(params) {
|
|
18
|
+
return DPath.getExtensionName(path, params);
|
|
19
|
+
}
|
|
20
|
+
function getMimeType() {
|
|
21
|
+
const extension = getExtension();
|
|
22
|
+
if (!extension) return null;
|
|
23
|
+
return DCommon.mimeType.get(extension) ?? null;
|
|
24
|
+
}
|
|
25
|
+
function getParentPath() {
|
|
26
|
+
return DPath.getParentFolderPath(path);
|
|
27
|
+
}
|
|
28
|
+
function localExists() {
|
|
29
|
+
return exists(path);
|
|
30
|
+
}
|
|
31
|
+
function localRename(newName) {
|
|
32
|
+
return DCommon.asyncPipe(rename(path, newName), DEither.whenIsRight(DCommon.innerPipe(createFileInterface, (value) => DEither.right("file-system-rename", value))));
|
|
33
|
+
}
|
|
34
|
+
function localRelocate(newParentPath) {
|
|
35
|
+
return DCommon.asyncPipe(relocate(path, newParentPath), DEither.whenIsRight(DCommon.innerPipe(createFileInterface, (value) => DEither.right("file-system-relocate", value))));
|
|
36
|
+
}
|
|
37
|
+
function localMove(newPath) {
|
|
38
|
+
return DCommon.asyncPipe(move(path, newPath), DEither.whenIsRight(() => DEither.right("file-system-move", createFileInterface(newPath))));
|
|
39
|
+
}
|
|
40
|
+
function localRemove() {
|
|
41
|
+
return remove(path);
|
|
42
|
+
}
|
|
43
|
+
function localStat() {
|
|
44
|
+
return stat(path);
|
|
45
|
+
}
|
|
46
|
+
function isFile() {
|
|
47
|
+
return DCommon.asyncPipe(localStat(), DEither.whenHasInformationOtherwise("file-system-stat", ({ isFile }) => isFile, DCommon.justReturn(false)));
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
path,
|
|
51
|
+
getName,
|
|
52
|
+
getExtension,
|
|
53
|
+
getMimeType,
|
|
54
|
+
getParentPath,
|
|
55
|
+
rename: localRename,
|
|
56
|
+
exists: localExists,
|
|
57
|
+
relocate: localRelocate,
|
|
58
|
+
remove: localRemove,
|
|
59
|
+
move: localMove,
|
|
60
|
+
stat: localStat,
|
|
61
|
+
isFile,
|
|
62
|
+
[fileInterfaceKind.runTimeKey]: null
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function isFileInterface(input) {
|
|
66
|
+
return fileInterfaceKind.has(input);
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { createFileInterface, isFileInterface };
|