@duplojs/server 0.1.0-beta.2 → 0.1.0-beta.3
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/dist/_virtual/_rolldown/runtime.mjs +5 -1
- package/dist/command/create.cjs +11 -9
- package/dist/command/create.mjs +11 -9
- package/dist/command/error.cjs +2 -2
- package/dist/command/error.mjs +1 -1
- package/dist/command/help.cjs +11 -9
- package/dist/command/help.mjs +10 -8
- package/dist/common/environmentVariable/parseEnvironmentFiles.d.ts +2 -1
- package/dist/common/index.cjs +3 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.mjs +3 -1
- package/dist/common/meta/getCurrentDirectoryName.cjs +10 -0
- package/dist/common/meta/getCurrentDirectoryName.d.ts +7 -0
- package/dist/common/meta/getCurrentDirectoryName.mjs +7 -0
- package/dist/common/meta/index.d.ts +7 -0
- package/dist/dataStructure/common/codec/defaults/json.cjs +12 -1
- package/dist/dataStructure/common/codec/defaults/json.d.ts +2 -2
- package/dist/dataStructure/common/codec/defaults/json.mjs +12 -1
- package/dist/dataStructure/common/codec/defaults/string.cjs +12 -1
- package/dist/dataStructure/common/codec/defaults/string.d.ts +2 -2
- package/dist/dataStructure/common/codec/defaults/string.mjs +12 -1
- package/dist/dataStructure/common/error/defaultInterpreter.cjs +3 -1
- package/dist/dataStructure/common/error/defaultInterpreter.d.ts +7 -2
- package/dist/dataStructure/common/error/defaultInterpreter.mjs +3 -1
- package/dist/dataStructure/constraint/{exist.cjs → fileExist.cjs} +5 -5
- package/dist/dataStructure/constraint/fileExist.d.ts +10 -0
- package/dist/dataStructure/constraint/{exist.mjs → fileExist.mjs} +4 -4
- package/dist/dataStructure/constraint/folderExist.cjs +19 -0
- package/dist/dataStructure/constraint/folderExist.d.ts +10 -0
- package/dist/dataStructure/constraint/folderExist.mjs +15 -0
- package/dist/dataStructure/constraint/index.d.ts +2 -1
- package/dist/dataStructure/constraint/mimeType.cjs +1 -1
- package/dist/dataStructure/constraint/mimeType.mjs +1 -1
- package/dist/dataStructure/constraint/types/constraints.d.ts +4 -2
- package/dist/dataStructure/fundamentalType/folder.cjs +11 -0
- package/dist/dataStructure/fundamentalType/folder.d.ts +8 -0
- package/dist/dataStructure/fundamentalType/folder.mjs +8 -0
- package/dist/dataStructure/fundamentalType/index.d.ts +1 -0
- package/dist/dataStructure/fundamentalType/types/fundamentalTypes.d.ts +2 -0
- package/dist/dataStructure/helper/file.d.ts +1 -1
- package/dist/dataStructure/helper/fileExist.cjs +7 -0
- package/dist/dataStructure/helper/fileExist.d.ts +2 -0
- package/dist/dataStructure/helper/fileExist.mjs +7 -0
- package/dist/dataStructure/helper/folder.cjs +10 -0
- package/dist/dataStructure/helper/folder.d.ts +3 -0
- package/dist/dataStructure/helper/folder.mjs +8 -0
- package/dist/dataStructure/helper/folderExist.cjs +7 -0
- package/dist/dataStructure/helper/folderExist.d.ts +2 -0
- package/dist/dataStructure/helper/folderExist.mjs +7 -0
- package/dist/dataStructure/helper/index.d.ts +3 -1
- package/dist/dataStructure/index.cjs +29 -8
- package/dist/dataStructure/index.mjs +19 -6
- package/dist/dataStructure/type/folder.cjs +14 -0
- package/dist/dataStructure/type/folder.d.ts +11 -0
- package/dist/dataStructure/type/folder.mjs +11 -0
- package/dist/dataStructure/type/index.d.ts +1 -0
- package/dist/dataStructure/type/types/types.d.ts +2 -0
- package/dist/file/appendFile.cjs +36 -22
- package/dist/file/appendFile.d.ts +34 -2
- package/dist/file/appendFile.mjs +35 -22
- package/dist/file/appendTextFile.cjs +34 -20
- package/dist/file/appendTextFile.d.ts +34 -2
- package/dist/file/appendTextFile.mjs +33 -20
- package/dist/file/copy.cjs +26 -14
- package/dist/file/copy.d.ts +34 -2
- package/dist/file/copy.mjs +25 -14
- package/dist/file/createEntryInterface.cjs +2 -2
- package/dist/file/createEntryInterface.d.ts +1 -1
- package/dist/file/createEntryInterface.mjs +1 -1
- package/dist/file/ensureDirectory.cjs +29 -17
- package/dist/file/ensureDirectory.d.ts +28 -2
- package/dist/file/ensureDirectory.mjs +28 -17
- package/dist/file/ensureFile.cjs +32 -19
- package/dist/file/ensureFile.d.ts +31 -2
- package/dist/file/ensureFile.mjs +31 -19
- package/dist/file/exists.cjs +23 -14
- package/dist/file/exists.d.ts +19 -2
- package/dist/file/exists.mjs +22 -14
- package/dist/file/fileInterface.cjs +2 -0
- package/dist/file/fileInterface.d.ts +8 -6
- package/dist/file/fileInterface.mjs +2 -1
- package/dist/file/folderInterface.cjs +2 -0
- package/dist/file/folderInterface.d.ts +7 -5
- package/dist/file/folderInterface.mjs +2 -1
- package/dist/file/index.cjs +6 -0
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.mjs +7 -4
- package/dist/file/link.cjs +37 -22
- package/dist/file/link.d.ts +37 -2
- package/dist/file/link.mjs +36 -22
- package/dist/file/linkStat.cjs +23 -15
- package/dist/file/linkStat.d.ts +22 -2
- package/dist/file/linkStat.mjs +23 -15
- package/dist/file/makeDirectory.cjs +35 -21
- package/dist/file/makeDirectory.d.ts +33 -2
- package/dist/file/makeDirectory.mjs +34 -21
- package/dist/file/makeTemporaryDirectory.cjs +26 -15
- package/dist/file/makeTemporaryDirectory.d.ts +25 -2
- package/dist/file/makeTemporaryDirectory.mjs +25 -15
- package/dist/file/makeTemporaryFile.cjs +29 -20
- package/dist/file/makeTemporaryFile.d.ts +28 -2
- package/dist/file/makeTemporaryFile.mjs +29 -20
- package/dist/file/move.cjs +38 -23
- package/dist/file/move.d.ts +37 -2
- package/dist/file/move.mjs +37 -23
- package/dist/file/readDirectory.cjs +27 -9
- package/dist/file/readDirectory.d.ts +26 -5
- package/dist/file/readDirectory.mjs +24 -9
- package/dist/file/readFile.cjs +28 -17
- package/dist/file/readFile.d.ts +25 -2
- package/dist/file/readFile.mjs +27 -17
- package/dist/file/readJsonFile.cjs +28 -17
- package/dist/file/readJsonFile.d.ts +25 -3
- package/dist/file/readJsonFile.mjs +27 -17
- package/dist/file/readLink.cjs +25 -15
- package/dist/file/readLink.d.ts +22 -2
- package/dist/file/readLink.mjs +24 -15
- package/dist/file/readTextFile.cjs +28 -17
- package/dist/file/readTextFile.d.ts +25 -2
- package/dist/file/readTextFile.mjs +27 -17
- package/dist/file/realPath.cjs +22 -13
- package/dist/file/realPath.d.ts +19 -2
- package/dist/file/realPath.mjs +21 -13
- package/dist/file/relocate.cjs +41 -25
- package/dist/file/relocate.d.ts +37 -2
- package/dist/file/relocate.mjs +40 -25
- package/dist/file/remove.cjs +36 -23
- package/dist/file/remove.d.ts +30 -2
- package/dist/file/remove.mjs +35 -23
- package/dist/file/rename.cjs +41 -25
- package/dist/file/rename.d.ts +37 -2
- package/dist/file/rename.mjs +40 -25
- package/dist/file/setMode.cjs +23 -15
- package/dist/file/setMode.d.ts +21 -2
- package/dist/file/setMode.mjs +23 -15
- package/dist/file/setOwner.cjs +25 -15
- package/dist/file/setOwner.d.ts +22 -2
- package/dist/file/setOwner.mjs +24 -15
- package/dist/file/setTime.cjs +25 -15
- package/dist/file/setTime.d.ts +21 -2
- package/dist/file/setTime.mjs +24 -15
- package/dist/file/stat.cjs +23 -15
- package/dist/file/stat.d.ts +22 -2
- package/dist/file/stat.mjs +23 -15
- package/dist/file/symlink.cjs +33 -20
- package/dist/file/symlink.d.ts +31 -2
- package/dist/file/symlink.mjs +32 -20
- package/dist/file/truncate.cjs +33 -21
- package/dist/file/truncate.d.ts +34 -2
- package/dist/file/truncate.mjs +33 -21
- package/dist/file/unknownEntryInterface.cjs +2 -0
- package/dist/file/unknownEntryInterface.d.ts +7 -5
- package/dist/file/unknownEntryInterface.mjs +2 -1
- package/dist/file/walkDirectory.cjs +28 -15
- package/dist/file/walkDirectory.d.ts +23 -2
- package/dist/file/walkDirectory.mjs +27 -14
- package/dist/file/writeFile.cjs +35 -21
- package/dist/file/writeFile.d.ts +34 -2
- package/dist/file/writeFile.mjs +34 -21
- package/dist/file/writeJsonFile.cjs +38 -27
- package/dist/file/writeJsonFile.d.ts +36 -5
- package/dist/file/writeJsonFile.mjs +38 -27
- package/dist/file/writeTextFile.cjs +35 -21
- package/dist/file/writeTextFile.d.ts +34 -2
- package/dist/file/writeTextFile.mjs +34 -21
- package/dist/implementor.cjs +8 -5
- package/dist/implementor.d.ts +4 -4
- package/dist/implementor.mjs +8 -5
- package/dist/index.cjs +2 -0
- package/dist/index.mjs +2 -1
- package/package.json +4 -4
- package/dist/dataStructure/constraint/exist.d.ts +0 -10
- package/dist/dataStructure/helper/exist.cjs +0 -7
- package/dist/dataStructure/helper/exist.d.ts +0 -2
- package/dist/dataStructure/helper/exist.mjs +0 -7
- package/dist/file/types/fileSystemEither.d.ts +0 -2
- package/dist/file/types/index.d.ts +0 -1
- /package/{README → README.md} +0 -0
|
@@ -1,10 +1,36 @@
|
|
|
1
|
-
import { FileSystemEither } from './types';
|
|
2
1
|
import * as DEither from "@duplojs/lang/either";
|
|
3
2
|
import type * as DPath from "@duplojs/lang/path";
|
|
4
|
-
|
|
3
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
4
|
+
declare const EnsureDirectoryErrorPermissionDenied_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-permission-denied", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-permission-denied", unknown>>, unknown>;
|
|
5
|
+
declare class EnsureDirectoryErrorPermissionDenied extends EnsureDirectoryErrorPermissionDenied_base {
|
|
6
|
+
}
|
|
7
|
+
declare const EnsureDirectoryErrorNotDirectory_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-not-directory", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-not-directory", unknown>>, unknown>;
|
|
8
|
+
declare class EnsureDirectoryErrorNotDirectory extends EnsureDirectoryErrorNotDirectory_base {
|
|
9
|
+
}
|
|
10
|
+
declare const EnsureDirectoryErrorNoSpace_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-no-space", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-no-space", unknown>>, unknown>;
|
|
11
|
+
declare class EnsureDirectoryErrorNoSpace extends EnsureDirectoryErrorNoSpace_base {
|
|
12
|
+
}
|
|
13
|
+
declare const EnsureDirectoryErrorReadOnly_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-read-only", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-read-only", unknown>>, unknown>;
|
|
14
|
+
declare class EnsureDirectoryErrorReadOnly extends EnsureDirectoryErrorReadOnly_base {
|
|
15
|
+
}
|
|
16
|
+
declare const EnsureDirectoryErrorInvalidArgument_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-invalid-argument", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-invalid-argument", unknown>>, unknown>;
|
|
17
|
+
declare class EnsureDirectoryErrorInvalidArgument extends EnsureDirectoryErrorInvalidArgument_base {
|
|
18
|
+
}
|
|
19
|
+
declare const EnsureDirectoryErrorTooManyOpenFiles_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-too-many-open-files", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-too-many-open-files", unknown>>, unknown>;
|
|
20
|
+
declare class EnsureDirectoryErrorTooManyOpenFiles extends EnsureDirectoryErrorTooManyOpenFiles_base {
|
|
21
|
+
}
|
|
22
|
+
declare const EnsureDirectoryErrorBusy_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-busy", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-busy", unknown>>, unknown>;
|
|
23
|
+
declare class EnsureDirectoryErrorBusy extends EnsureDirectoryErrorBusy_base {
|
|
24
|
+
}
|
|
25
|
+
declare const EnsureDirectoryError_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-directory-error", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-directory-error", unknown>>, unknown>;
|
|
26
|
+
declare class EnsureDirectoryError extends EnsureDirectoryError_base {
|
|
27
|
+
}
|
|
28
|
+
export type EnsureDirectoryErrors = (EnsureDirectoryErrorPermissionDenied | EnsureDirectoryErrorNotDirectory | EnsureDirectoryErrorNoSpace | EnsureDirectoryErrorReadOnly | EnsureDirectoryErrorInvalidArgument | EnsureDirectoryErrorTooManyOpenFiles | EnsureDirectoryErrorBusy | EnsureDirectoryError);
|
|
29
|
+
export type EnsureDirectoryResult = (DEither.Right<"file-system-ensure-directory", void> | DEither.Left<"file-system-ensure-directory-error", EnsureDirectoryErrors>);
|
|
5
30
|
declare module '../implementor' {
|
|
6
31
|
interface ServerFunction {
|
|
7
32
|
ensureDirectory(path: string & DPath.Path): Promise<EnsureDirectoryResult>;
|
|
8
33
|
}
|
|
9
34
|
}
|
|
10
35
|
export declare const ensureDirectory: (path: string & DPath.Path) => Promise<EnsureDirectoryResult>;
|
|
36
|
+
export {};
|
|
@@ -1,29 +1,40 @@
|
|
|
1
1
|
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
2
3
|
import * as DEither from "@duplojs/lang/either";
|
|
3
4
|
//#region scripts/file/ensureDirectory.ts
|
|
5
|
+
var EnsureDirectoryErrorPermissionDenied = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-permission-denied", Error) {};
|
|
6
|
+
var EnsureDirectoryErrorNotDirectory = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-not-directory", Error) {};
|
|
7
|
+
var EnsureDirectoryErrorNoSpace = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-no-space", Error) {};
|
|
8
|
+
var EnsureDirectoryErrorReadOnly = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-read-only", Error) {};
|
|
9
|
+
var EnsureDirectoryErrorInvalidArgument = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-invalid-argument", Error) {};
|
|
10
|
+
var EnsureDirectoryErrorTooManyOpenFiles = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-too-many-open-files", Error) {};
|
|
11
|
+
var EnsureDirectoryErrorBusy = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-busy", Error) {};
|
|
12
|
+
var EnsureDirectoryError = class extends DCommon.DuploJSError.parentClass("file-system-ensure-directory-error", Error) {};
|
|
4
13
|
function handleNodeEnsureDirectoryError(error) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
else if (error.code === "
|
|
9
|
-
else if (error.code === "
|
|
10
|
-
else if (error.code === "
|
|
11
|
-
else if (error.code === "
|
|
12
|
-
else if (error.code === "
|
|
14
|
+
let ensureDirectoryError = void 0;
|
|
15
|
+
if ("code" in error) {
|
|
16
|
+
if (error.code === "EACCES" || error.code === "EPERM") ensureDirectoryError = new EnsureDirectoryErrorPermissionDenied(error);
|
|
17
|
+
else if (error.code === "ENOTDIR") ensureDirectoryError = new EnsureDirectoryErrorNotDirectory(error);
|
|
18
|
+
else if (error.code === "ENOSPC") ensureDirectoryError = new EnsureDirectoryErrorNoSpace(error);
|
|
19
|
+
else if (error.code === "EROFS") ensureDirectoryError = new EnsureDirectoryErrorReadOnly(error);
|
|
20
|
+
else if (error.code === "EINVAL") ensureDirectoryError = new EnsureDirectoryErrorInvalidArgument(error);
|
|
21
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") ensureDirectoryError = new EnsureDirectoryErrorTooManyOpenFiles(error);
|
|
22
|
+
else if (error.code === "EBUSY") ensureDirectoryError = new EnsureDirectoryErrorBusy(error);
|
|
13
23
|
}
|
|
14
|
-
|
|
24
|
+
if (ensureDirectoryError === void 0) ensureDirectoryError = new EnsureDirectoryError(error);
|
|
25
|
+
return DEither.left("file-system-ensure-directory-error", ensureDirectoryError);
|
|
15
26
|
}
|
|
16
27
|
function handleDenoEnsureDirectoryError(error) {
|
|
17
|
-
|
|
18
|
-
if (error instanceof Deno.errors.
|
|
19
|
-
if (error instanceof Deno.errors.
|
|
20
|
-
if (error instanceof Deno.errors.
|
|
21
|
-
|
|
28
|
+
let ensureDirectoryError = void 0;
|
|
29
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) ensureDirectoryError = new EnsureDirectoryErrorPermissionDenied(error);
|
|
30
|
+
else if (error instanceof Deno.errors.NotADirectory) ensureDirectoryError = new EnsureDirectoryErrorNotDirectory(error);
|
|
31
|
+
else if (error instanceof Deno.errors.InvalidData) ensureDirectoryError = new EnsureDirectoryErrorInvalidArgument(error);
|
|
32
|
+
else if (error instanceof Deno.errors.Busy) ensureDirectoryError = new EnsureDirectoryErrorBusy(error);
|
|
33
|
+
if (ensureDirectoryError === void 0) ensureDirectoryError = new EnsureDirectoryError(error);
|
|
34
|
+
return DEither.left("file-system-ensure-directory-error", ensureDirectoryError);
|
|
22
35
|
}
|
|
23
36
|
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
|
-
},
|
|
37
|
+
NODE: async (path) => nodeFileSystem.value.mkdir(path, { recursive: true }).then(() => DEither.right("file-system-ensure-directory")).catch(handleNodeEnsureDirectoryError),
|
|
27
38
|
DENO: (path) => Deno.mkdir(path, { recursive: true }).then(() => DEither.right("file-system-ensure-directory")).catch(handleDenoEnsureDirectoryError)
|
|
28
39
|
});
|
|
29
40
|
//#endregion
|
package/dist/file/ensureFile.cjs
CHANGED
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_implementor = require("../implementor.cjs");
|
|
3
|
+
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
4
|
+
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
3
5
|
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
4
6
|
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
5
7
|
//#region scripts/file/ensureFile.ts
|
|
8
|
+
var EnsureFileErrorPermissionDenied = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-permission-denied", Error) {};
|
|
9
|
+
var EnsureFileErrorIsDirectory = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-is-directory", Error) {};
|
|
10
|
+
var EnsureFileErrorNotDirectory = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-not-directory", Error) {};
|
|
11
|
+
var EnsureFileErrorNoSpace = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-no-space", Error) {};
|
|
12
|
+
var EnsureFileErrorReadOnly = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-read-only", Error) {};
|
|
13
|
+
var EnsureFileErrorInvalidArgument = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-invalid-argument", Error) {};
|
|
14
|
+
var EnsureFileErrorTooManyOpenFiles = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-too-many-open-files", Error) {};
|
|
15
|
+
var EnsureFileErrorBusy = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-busy", Error) {};
|
|
16
|
+
var EnsureFileError = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-ensure-file-error", Error) {};
|
|
6
17
|
function handleNodeEnsureFileError(error) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
else if (error.code === "
|
|
11
|
-
else if (error.code === "
|
|
12
|
-
else if (error.code === "
|
|
13
|
-
else if (error.code === "
|
|
14
|
-
else if (error.code === "
|
|
15
|
-
else if (error.code === "
|
|
18
|
+
let ensureFileError = void 0;
|
|
19
|
+
if ("code" in error) {
|
|
20
|
+
if (error.code === "EACCES" || error.code === "EPERM") ensureFileError = new EnsureFileErrorPermissionDenied(error);
|
|
21
|
+
else if (error.code === "EISDIR") ensureFileError = new EnsureFileErrorIsDirectory(error);
|
|
22
|
+
else if (error.code === "ENOTDIR") ensureFileError = new EnsureFileErrorNotDirectory(error);
|
|
23
|
+
else if (error.code === "ENOSPC") ensureFileError = new EnsureFileErrorNoSpace(error);
|
|
24
|
+
else if (error.code === "EROFS") ensureFileError = new EnsureFileErrorReadOnly(error);
|
|
25
|
+
else if (error.code === "EINVAL") ensureFileError = new EnsureFileErrorInvalidArgument(error);
|
|
26
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") ensureFileError = new EnsureFileErrorTooManyOpenFiles(error);
|
|
27
|
+
else if (error.code === "EBUSY") ensureFileError = new EnsureFileErrorBusy(error);
|
|
16
28
|
}
|
|
17
|
-
|
|
29
|
+
if (ensureFileError === void 0) ensureFileError = new EnsureFileError(error);
|
|
30
|
+
return _duplojs_lang_either.left("file-system-ensure-file-error", ensureFileError);
|
|
18
31
|
}
|
|
19
32
|
function handleDenoEnsureFileError(error) {
|
|
20
|
-
|
|
21
|
-
if (error instanceof Deno.errors.
|
|
22
|
-
if (error instanceof Deno.errors.
|
|
23
|
-
if (error instanceof Deno.errors.
|
|
24
|
-
if (error instanceof Deno.errors.
|
|
25
|
-
|
|
33
|
+
let ensureFileError = void 0;
|
|
34
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) ensureFileError = new EnsureFileErrorPermissionDenied(error);
|
|
35
|
+
else if (error instanceof Deno.errors.IsADirectory) ensureFileError = new EnsureFileErrorIsDirectory(error);
|
|
36
|
+
else if (error instanceof Deno.errors.NotADirectory) ensureFileError = new EnsureFileErrorNotDirectory(error);
|
|
37
|
+
else if (error instanceof Deno.errors.InvalidData) ensureFileError = new EnsureFileErrorInvalidArgument(error);
|
|
38
|
+
else if (error instanceof Deno.errors.Busy) ensureFileError = new EnsureFileErrorBusy(error);
|
|
39
|
+
if (ensureFileError === void 0) ensureFileError = new EnsureFileError(error);
|
|
40
|
+
return _duplojs_lang_either.left("file-system-ensure-file-error", ensureFileError);
|
|
26
41
|
}
|
|
27
42
|
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
|
-
},
|
|
43
|
+
NODE: async (path) => require_implementor.nodeFileSystem.value.open(path, "a").then((fh) => fh.close()).then(() => _duplojs_lang_either.right("file-system-ensure-file")).catch(handleNodeEnsureFileError),
|
|
31
44
|
DENO: (path) => Deno.open(path, {
|
|
32
45
|
write: true,
|
|
33
46
|
create: true,
|
|
@@ -1,10 +1,39 @@
|
|
|
1
|
-
import { FileSystemEither } from './types';
|
|
2
1
|
import * as DEither from "@duplojs/lang/either";
|
|
3
2
|
import type * as DPath from "@duplojs/lang/path";
|
|
4
|
-
|
|
3
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
4
|
+
declare const EnsureFileErrorPermissionDenied_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-permission-denied", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-permission-denied", unknown>>, unknown>;
|
|
5
|
+
declare class EnsureFileErrorPermissionDenied extends EnsureFileErrorPermissionDenied_base {
|
|
6
|
+
}
|
|
7
|
+
declare const EnsureFileErrorIsDirectory_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-is-directory", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-is-directory", unknown>>, unknown>;
|
|
8
|
+
declare class EnsureFileErrorIsDirectory extends EnsureFileErrorIsDirectory_base {
|
|
9
|
+
}
|
|
10
|
+
declare const EnsureFileErrorNotDirectory_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-not-directory", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-not-directory", unknown>>, unknown>;
|
|
11
|
+
declare class EnsureFileErrorNotDirectory extends EnsureFileErrorNotDirectory_base {
|
|
12
|
+
}
|
|
13
|
+
declare const EnsureFileErrorNoSpace_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-no-space", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-no-space", unknown>>, unknown>;
|
|
14
|
+
declare class EnsureFileErrorNoSpace extends EnsureFileErrorNoSpace_base {
|
|
15
|
+
}
|
|
16
|
+
declare const EnsureFileErrorReadOnly_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-read-only", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-read-only", unknown>>, unknown>;
|
|
17
|
+
declare class EnsureFileErrorReadOnly extends EnsureFileErrorReadOnly_base {
|
|
18
|
+
}
|
|
19
|
+
declare const EnsureFileErrorInvalidArgument_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-invalid-argument", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-invalid-argument", unknown>>, unknown>;
|
|
20
|
+
declare class EnsureFileErrorInvalidArgument extends EnsureFileErrorInvalidArgument_base {
|
|
21
|
+
}
|
|
22
|
+
declare const EnsureFileErrorTooManyOpenFiles_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-too-many-open-files", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-too-many-open-files", unknown>>, unknown>;
|
|
23
|
+
declare class EnsureFileErrorTooManyOpenFiles extends EnsureFileErrorTooManyOpenFiles_base {
|
|
24
|
+
}
|
|
25
|
+
declare const EnsureFileErrorBusy_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-busy", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-busy", unknown>>, unknown>;
|
|
26
|
+
declare class EnsureFileErrorBusy extends EnsureFileErrorBusy_base {
|
|
27
|
+
}
|
|
28
|
+
declare const EnsureFileError_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-ensure-file-error", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-ensure-file-error", unknown>>, unknown>;
|
|
29
|
+
declare class EnsureFileError extends EnsureFileError_base {
|
|
30
|
+
}
|
|
31
|
+
export type EnsureFileErrors = (EnsureFileErrorPermissionDenied | EnsureFileErrorIsDirectory | EnsureFileErrorNotDirectory | EnsureFileErrorNoSpace | EnsureFileErrorReadOnly | EnsureFileErrorInvalidArgument | EnsureFileErrorTooManyOpenFiles | EnsureFileErrorBusy | EnsureFileError);
|
|
32
|
+
export type EnsureFileResult = (DEither.Right<"file-system-ensure-file", void> | DEither.Left<"file-system-ensure-file-error", EnsureFileErrors>);
|
|
5
33
|
declare module '../implementor' {
|
|
6
34
|
interface ServerFunction {
|
|
7
35
|
ensureFile(path: string & DPath.Path): Promise<EnsureFileResult>;
|
|
8
36
|
}
|
|
9
37
|
}
|
|
10
38
|
export declare const ensureFile: (path: string & DPath.Path) => Promise<EnsureFileResult>;
|
|
39
|
+
export {};
|
package/dist/file/ensureFile.mjs
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
2
3
|
import * as DEither from "@duplojs/lang/either";
|
|
3
4
|
//#region scripts/file/ensureFile.ts
|
|
5
|
+
var EnsureFileErrorPermissionDenied = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-permission-denied", Error) {};
|
|
6
|
+
var EnsureFileErrorIsDirectory = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-is-directory", Error) {};
|
|
7
|
+
var EnsureFileErrorNotDirectory = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-not-directory", Error) {};
|
|
8
|
+
var EnsureFileErrorNoSpace = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-no-space", Error) {};
|
|
9
|
+
var EnsureFileErrorReadOnly = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-read-only", Error) {};
|
|
10
|
+
var EnsureFileErrorInvalidArgument = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-invalid-argument", Error) {};
|
|
11
|
+
var EnsureFileErrorTooManyOpenFiles = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-too-many-open-files", Error) {};
|
|
12
|
+
var EnsureFileErrorBusy = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-busy", Error) {};
|
|
13
|
+
var EnsureFileError = class extends DCommon.DuploJSError.parentClass("file-system-ensure-file-error", Error) {};
|
|
4
14
|
function handleNodeEnsureFileError(error) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
else if (error.code === "
|
|
9
|
-
else if (error.code === "
|
|
10
|
-
else if (error.code === "
|
|
11
|
-
else if (error.code === "
|
|
12
|
-
else if (error.code === "
|
|
13
|
-
else if (error.code === "
|
|
15
|
+
let ensureFileError = void 0;
|
|
16
|
+
if ("code" in error) {
|
|
17
|
+
if (error.code === "EACCES" || error.code === "EPERM") ensureFileError = new EnsureFileErrorPermissionDenied(error);
|
|
18
|
+
else if (error.code === "EISDIR") ensureFileError = new EnsureFileErrorIsDirectory(error);
|
|
19
|
+
else if (error.code === "ENOTDIR") ensureFileError = new EnsureFileErrorNotDirectory(error);
|
|
20
|
+
else if (error.code === "ENOSPC") ensureFileError = new EnsureFileErrorNoSpace(error);
|
|
21
|
+
else if (error.code === "EROFS") ensureFileError = new EnsureFileErrorReadOnly(error);
|
|
22
|
+
else if (error.code === "EINVAL") ensureFileError = new EnsureFileErrorInvalidArgument(error);
|
|
23
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") ensureFileError = new EnsureFileErrorTooManyOpenFiles(error);
|
|
24
|
+
else if (error.code === "EBUSY") ensureFileError = new EnsureFileErrorBusy(error);
|
|
14
25
|
}
|
|
15
|
-
|
|
26
|
+
if (ensureFileError === void 0) ensureFileError = new EnsureFileError(error);
|
|
27
|
+
return DEither.left("file-system-ensure-file-error", ensureFileError);
|
|
16
28
|
}
|
|
17
29
|
function handleDenoEnsureFileError(error) {
|
|
18
|
-
|
|
19
|
-
if (error instanceof Deno.errors.
|
|
20
|
-
if (error instanceof Deno.errors.
|
|
21
|
-
if (error instanceof Deno.errors.
|
|
22
|
-
if (error instanceof Deno.errors.
|
|
23
|
-
|
|
30
|
+
let ensureFileError = void 0;
|
|
31
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) ensureFileError = new EnsureFileErrorPermissionDenied(error);
|
|
32
|
+
else if (error instanceof Deno.errors.IsADirectory) ensureFileError = new EnsureFileErrorIsDirectory(error);
|
|
33
|
+
else if (error instanceof Deno.errors.NotADirectory) ensureFileError = new EnsureFileErrorNotDirectory(error);
|
|
34
|
+
else if (error instanceof Deno.errors.InvalidData) ensureFileError = new EnsureFileErrorInvalidArgument(error);
|
|
35
|
+
else if (error instanceof Deno.errors.Busy) ensureFileError = new EnsureFileErrorBusy(error);
|
|
36
|
+
if (ensureFileError === void 0) ensureFileError = new EnsureFileError(error);
|
|
37
|
+
return DEither.left("file-system-ensure-file-error", ensureFileError);
|
|
24
38
|
}
|
|
25
39
|
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
|
-
},
|
|
40
|
+
NODE: async (path) => nodeFileSystem.value.open(path, "a").then((fh) => fh.close()).then(() => DEither.right("file-system-ensure-file")).catch(handleNodeEnsureFileError),
|
|
29
41
|
DENO: (path) => Deno.open(path, {
|
|
30
42
|
write: true,
|
|
31
43
|
create: true,
|
package/dist/file/exists.cjs
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
const require_implementor = require("../implementor.cjs");
|
|
3
|
+
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
4
|
+
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
3
5
|
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
4
6
|
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
5
7
|
//#region scripts/file/exists.ts
|
|
8
|
+
var ExistsErrorNotFound = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-exists-not-found", Error) {};
|
|
9
|
+
var ExistsErrorPermissionDenied = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-exists-permission-denied", Error) {};
|
|
10
|
+
var ExistsErrorNotDirectory = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-exists-not-directory", Error) {};
|
|
11
|
+
var ExistsErrorTooManyOpenFiles = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-exists-too-many-open-files", Error) {};
|
|
12
|
+
var ExistsError = class extends _duplojs_lang_common.DuploJSError.parentClass("file-system-exists-error", Error) {};
|
|
6
13
|
function handleNodeExistsError(error) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
else if (error.code === "
|
|
11
|
-
else if (error.code === "
|
|
14
|
+
let existsError = void 0;
|
|
15
|
+
if ("code" in error) {
|
|
16
|
+
if (error.code === "ENOENT") existsError = new ExistsErrorNotFound(error);
|
|
17
|
+
else if (error.code === "EACCES" || error.code === "EPERM") existsError = new ExistsErrorPermissionDenied(error);
|
|
18
|
+
else if (error.code === "ENOTDIR") existsError = new ExistsErrorNotDirectory(error);
|
|
19
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") existsError = new ExistsErrorTooManyOpenFiles(error);
|
|
12
20
|
}
|
|
13
|
-
|
|
21
|
+
if (existsError === void 0) existsError = new ExistsError(error);
|
|
22
|
+
return _duplojs_lang_either.left("file-system-exists-error", existsError);
|
|
14
23
|
}
|
|
15
24
|
function handleDenoExistsError(error) {
|
|
16
|
-
|
|
17
|
-
if (error instanceof Deno.errors.
|
|
18
|
-
if (error instanceof Deno.errors.
|
|
19
|
-
|
|
25
|
+
let existsError = void 0;
|
|
26
|
+
if (error instanceof Deno.errors.NotFound) existsError = new ExistsErrorNotFound(error);
|
|
27
|
+
else if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) existsError = new ExistsErrorPermissionDenied(error);
|
|
28
|
+
else if (error instanceof Deno.errors.NotADirectory) existsError = new ExistsErrorNotDirectory(error);
|
|
29
|
+
if (existsError === void 0) existsError = new ExistsError(error);
|
|
30
|
+
return _duplojs_lang_either.left("file-system-exists-error", existsError);
|
|
20
31
|
}
|
|
21
32
|
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
|
-
},
|
|
33
|
+
NODE: async (path) => require_implementor.nodeFileSystem.value.access(path).then(() => _duplojs_lang_either.right("file-system-exists")).catch(handleNodeExistsError),
|
|
25
34
|
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-
|
|
35
|
+
BUN: (path) => Bun.file(path).exists().then((value) => value ? _duplojs_lang_either.right("file-system-exists") : _duplojs_lang_either.left("file-system-exists-error", new ExistsErrorNotFound(/* @__PURE__ */ new Error("Path does not exist")))).catch(handleNodeExistsError)
|
|
27
36
|
});
|
|
28
37
|
//#endregion
|
|
29
38
|
exports.exists = exists;
|
package/dist/file/exists.d.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import { FileSystemEither } from './types';
|
|
2
1
|
import * as DEither from "@duplojs/lang/either";
|
|
3
2
|
import type * as DPath from "@duplojs/lang/path";
|
|
4
|
-
|
|
3
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
4
|
+
declare const ExistsErrorNotFound_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-exists-not-found", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-exists-not-found", unknown>>, unknown>;
|
|
5
|
+
declare class ExistsErrorNotFound extends ExistsErrorNotFound_base {
|
|
6
|
+
}
|
|
7
|
+
declare const ExistsErrorPermissionDenied_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-exists-permission-denied", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-exists-permission-denied", unknown>>, unknown>;
|
|
8
|
+
declare class ExistsErrorPermissionDenied extends ExistsErrorPermissionDenied_base {
|
|
9
|
+
}
|
|
10
|
+
declare const ExistsErrorNotDirectory_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-exists-not-directory", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-exists-not-directory", unknown>>, unknown>;
|
|
11
|
+
declare class ExistsErrorNotDirectory extends ExistsErrorNotDirectory_base {
|
|
12
|
+
}
|
|
13
|
+
declare const ExistsErrorTooManyOpenFiles_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-exists-too-many-open-files", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-exists-too-many-open-files", unknown>>, unknown>;
|
|
14
|
+
declare class ExistsErrorTooManyOpenFiles extends ExistsErrorTooManyOpenFiles_base {
|
|
15
|
+
}
|
|
16
|
+
declare const ExistsError_base: abstract new (error: Error) => DCommon.DuploJSError<"file-system-exists-error", Error> & import('@duplojs/lang/kind').Kind<import('@duplojs/lang/kind').Handler<import('@duplojs/lang/kind').Definition<"@DuplojsLangCommon/duplojs-error-file-system-exists-error", unknown>>, unknown>;
|
|
17
|
+
declare class ExistsError extends ExistsError_base {
|
|
18
|
+
}
|
|
19
|
+
export type ExistsErrors = (ExistsErrorNotFound | ExistsErrorPermissionDenied | ExistsErrorNotDirectory | ExistsErrorTooManyOpenFiles | ExistsError);
|
|
20
|
+
export type ExistsResult = (DEither.Right<"file-system-exists", void> | DEither.Left<"file-system-exists-error", ExistsErrors>);
|
|
5
21
|
declare module '../implementor' {
|
|
6
22
|
interface ServerFunction {
|
|
7
23
|
exists(path: string & DPath.Path): Promise<ExistsResult>;
|
|
8
24
|
}
|
|
9
25
|
}
|
|
10
26
|
export declare const exists: (path: string & DPath.Path) => Promise<ExistsResult>;
|
|
27
|
+
export {};
|
package/dist/file/exists.mjs
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
2
3
|
import * as DEither from "@duplojs/lang/either";
|
|
3
4
|
//#region scripts/file/exists.ts
|
|
5
|
+
var ExistsErrorNotFound = class extends DCommon.DuploJSError.parentClass("file-system-exists-not-found", Error) {};
|
|
6
|
+
var ExistsErrorPermissionDenied = class extends DCommon.DuploJSError.parentClass("file-system-exists-permission-denied", Error) {};
|
|
7
|
+
var ExistsErrorNotDirectory = class extends DCommon.DuploJSError.parentClass("file-system-exists-not-directory", Error) {};
|
|
8
|
+
var ExistsErrorTooManyOpenFiles = class extends DCommon.DuploJSError.parentClass("file-system-exists-too-many-open-files", Error) {};
|
|
9
|
+
var ExistsError = class extends DCommon.DuploJSError.parentClass("file-system-exists-error", Error) {};
|
|
4
10
|
function handleNodeExistsError(error) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
else if (error.code === "
|
|
9
|
-
else if (error.code === "
|
|
11
|
+
let existsError = void 0;
|
|
12
|
+
if ("code" in error) {
|
|
13
|
+
if (error.code === "ENOENT") existsError = new ExistsErrorNotFound(error);
|
|
14
|
+
else if (error.code === "EACCES" || error.code === "EPERM") existsError = new ExistsErrorPermissionDenied(error);
|
|
15
|
+
else if (error.code === "ENOTDIR") existsError = new ExistsErrorNotDirectory(error);
|
|
16
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") existsError = new ExistsErrorTooManyOpenFiles(error);
|
|
10
17
|
}
|
|
11
|
-
|
|
18
|
+
if (existsError === void 0) existsError = new ExistsError(error);
|
|
19
|
+
return DEither.left("file-system-exists-error", existsError);
|
|
12
20
|
}
|
|
13
21
|
function handleDenoExistsError(error) {
|
|
14
|
-
|
|
15
|
-
if (error instanceof Deno.errors.
|
|
16
|
-
if (error instanceof Deno.errors.
|
|
17
|
-
|
|
22
|
+
let existsError = void 0;
|
|
23
|
+
if (error instanceof Deno.errors.NotFound) existsError = new ExistsErrorNotFound(error);
|
|
24
|
+
else if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) existsError = new ExistsErrorPermissionDenied(error);
|
|
25
|
+
else if (error instanceof Deno.errors.NotADirectory) existsError = new ExistsErrorNotDirectory(error);
|
|
26
|
+
if (existsError === void 0) existsError = new ExistsError(error);
|
|
27
|
+
return DEither.left("file-system-exists-error", existsError);
|
|
18
28
|
}
|
|
19
29
|
const exists = implementFunction("exists", {
|
|
20
|
-
NODE: async (path) =>
|
|
21
|
-
return (await nodeFileSystem.value).access(path).then(() => DEither.right("file-system-exists")).catch(handleNodeExistsError);
|
|
22
|
-
},
|
|
30
|
+
NODE: async (path) => nodeFileSystem.value.access(path).then(() => DEither.right("file-system-exists")).catch(handleNodeExistsError),
|
|
23
31
|
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-
|
|
32
|
+
BUN: (path) => Bun.file(path).exists().then((value) => value ? DEither.right("file-system-exists") : DEither.left("file-system-exists-error", new ExistsErrorNotFound(/* @__PURE__ */ new Error("Path does not exist")))).catch(handleNodeExistsError)
|
|
25
33
|
});
|
|
26
34
|
//#endregion
|
|
27
35
|
export { exists };
|
|
@@ -69,6 +69,8 @@ function createFileInterface(path) {
|
|
|
69
69
|
function isFileInterface(input) {
|
|
70
70
|
return fileInterfaceKind.has(input);
|
|
71
71
|
}
|
|
72
|
+
const isFileInterfaceFromUnknown = isFileInterface;
|
|
72
73
|
//#endregion
|
|
73
74
|
exports.createFileInterface = createFileInterface;
|
|
74
75
|
exports.isFileInterface = isFileInterface;
|
|
76
|
+
exports.isFileInterfaceFromUnknown = isFileInterfaceFromUnknown;
|
|
@@ -4,6 +4,7 @@ import { MoveResult } from './move';
|
|
|
4
4
|
import { RemoveResult } from './remove';
|
|
5
5
|
import { StatResult } from './stat';
|
|
6
6
|
import { RelocateResult } from './relocate';
|
|
7
|
+
import { EntryPath } from './unknownEntryInterface';
|
|
7
8
|
import type * as DKind from "@duplojs/lang/kind";
|
|
8
9
|
import * as DPath from "@duplojs/lang/path";
|
|
9
10
|
import * as DEither from "@duplojs/lang/either";
|
|
@@ -11,11 +12,11 @@ declare const fileInterfaceKind: DKind.Handler<DKind.Definition<"@DuplojsServer/
|
|
|
11
12
|
type FileInterfaceRenameResult = Exclude<RenameResult, DEither.Right> | DEither.Right<"file-system-rename", FileInterface>;
|
|
12
13
|
type FileInterfaceRelocateResult = Exclude<RelocateResult, DEither.Right> | DEither.Right<"file-system-relocate", FileInterface>;
|
|
13
14
|
type FileInterfaceMoveResult = Exclude<MoveResult, DEither.Right> | DEither.Right<"file-system-move", FileInterface>;
|
|
14
|
-
export interface FileInterface extends DKind.Kind<typeof fileInterfaceKind> {
|
|
15
|
-
path:
|
|
16
|
-
getName(): (string & DPath.Segment) | null;
|
|
15
|
+
export interface FileInterface<GenericPath extends EntryPath = EntryPath> extends DKind.Kind<typeof fileInterfaceKind> {
|
|
16
|
+
path: GenericPath & DPath.Path;
|
|
17
|
+
getName(): (string & DPath.Segment & DPath.Path) | null;
|
|
17
18
|
getMimeType(): string | null;
|
|
18
|
-
getExtension(params?: DPath.GetExtensionNameParams): (string & DPath.Segment) | null;
|
|
19
|
+
getExtension(params?: DPath.GetExtensionNameParams): (string & DPath.Segment & DPath.Path) | null;
|
|
19
20
|
getParentPath(): (string & DPath.Path) | null;
|
|
20
21
|
rename(newName: string & DPath.Segment): Promise<FileInterfaceRenameResult>;
|
|
21
22
|
relocate(parentPath: string & DPath.Path): Promise<FileInterfaceRelocateResult>;
|
|
@@ -25,6 +26,7 @@ export interface FileInterface extends DKind.Kind<typeof fileInterfaceKind> {
|
|
|
25
26
|
stat(): Promise<StatResult>;
|
|
26
27
|
isFile(): Promise<boolean>;
|
|
27
28
|
}
|
|
28
|
-
export declare function createFileInterface(path:
|
|
29
|
-
export declare function isFileInterface(input:
|
|
29
|
+
export declare function createFileInterface<GenericPath extends EntryPath = EntryPath>(path: GenericPath): FileInterface<GenericPath>;
|
|
30
|
+
export declare function isFileInterface<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput, FileInterface>;
|
|
31
|
+
export declare const isFileInterfaceFromUnknown: (input: unknown) => input is FileInterface;
|
|
30
32
|
export {};
|
|
@@ -65,5 +65,6 @@ function createFileInterface(path) {
|
|
|
65
65
|
function isFileInterface(input) {
|
|
66
66
|
return fileInterfaceKind.has(input);
|
|
67
67
|
}
|
|
68
|
+
const isFileInterfaceFromUnknown = isFileInterface;
|
|
68
69
|
//#endregion
|
|
69
|
-
export { createFileInterface, isFileInterface };
|
|
70
|
+
export { createFileInterface, isFileInterface, isFileInterfaceFromUnknown };
|
|
@@ -69,6 +69,8 @@ function createFolderInterface(path) {
|
|
|
69
69
|
function isFolderInterface(input) {
|
|
70
70
|
return folderInterfaceKind.has(input);
|
|
71
71
|
}
|
|
72
|
+
const isFolderInterfaceFromUnknown = isFolderInterface;
|
|
72
73
|
//#endregion
|
|
73
74
|
exports.createFolderInterface = createFolderInterface;
|
|
74
75
|
exports.isFolderInterface = isFolderInterface;
|
|
76
|
+
exports.isFolderInterfaceFromUnknown = isFolderInterfaceFromUnknown;
|
|
@@ -6,6 +6,7 @@ import { ReadDirectoryResult } from './readDirectory';
|
|
|
6
6
|
import { StatResult } from './stat';
|
|
7
7
|
import { WalkDirectoryParams, WalkDirectoryResult } from './walkDirectory';
|
|
8
8
|
import { RelocateResult } from './relocate';
|
|
9
|
+
import { EntryPath } from './unknownEntryInterface';
|
|
9
10
|
import type * as DKind from "@duplojs/lang/kind";
|
|
10
11
|
import * as DPath from "@duplojs/lang/path";
|
|
11
12
|
import * as DEither from "@duplojs/lang/either";
|
|
@@ -13,9 +14,9 @@ declare const folderInterfaceKind: DKind.Handler<DKind.Definition<"@DuplojsServe
|
|
|
13
14
|
type FolderInterfaceRenameResult = Exclude<RenameResult, DEither.Right> | DEither.Right<"file-system-rename", FolderInterface>;
|
|
14
15
|
type FolderInterfaceRelocateResult = Exclude<RelocateResult, DEither.Right> | DEither.Right<"file-system-relocate", FolderInterface>;
|
|
15
16
|
type FolderInterfaceMoveResult = Exclude<MoveResult, DEither.Right> | DEither.Right<"file-system-move", FolderInterface>;
|
|
16
|
-
export interface FolderInterface extends DKind.Kind<typeof folderInterfaceKind> {
|
|
17
|
-
path:
|
|
18
|
-
getName(): (string & DPath.Segment) | null;
|
|
17
|
+
export interface FolderInterface<GenericPath extends EntryPath = EntryPath> extends DKind.Kind<typeof folderInterfaceKind> {
|
|
18
|
+
path: GenericPath & DPath.Path;
|
|
19
|
+
getName(): (string & DPath.Segment & DPath.Path) | null;
|
|
19
20
|
getParentPath(): (string & DPath.Path) | null;
|
|
20
21
|
rename(newName: (string & DPath.Segment)): Promise<FolderInterfaceRenameResult>;
|
|
21
22
|
exists(): Promise<ExistsResult>;
|
|
@@ -27,6 +28,7 @@ export interface FolderInterface extends DKind.Kind<typeof folderInterfaceKind>
|
|
|
27
28
|
walk(params?: WalkDirectoryParams): Promise<WalkDirectoryResult>;
|
|
28
29
|
isFolder(): Promise<boolean>;
|
|
29
30
|
}
|
|
30
|
-
export declare function createFolderInterface(path:
|
|
31
|
-
export declare function isFolderInterface(input:
|
|
31
|
+
export declare function createFolderInterface<GenericPath extends EntryPath = EntryPath>(path: GenericPath): FolderInterface<GenericPath>;
|
|
32
|
+
export declare function isFolderInterface<GenericInput extends unknown>(input: GenericInput): input is Extract<GenericInput, FolderInterface>;
|
|
33
|
+
export declare const isFolderInterfaceFromUnknown: (input: unknown) => input is FolderInterface;
|
|
32
34
|
export {};
|
|
@@ -65,5 +65,6 @@ function createFolderInterface(path) {
|
|
|
65
65
|
function isFolderInterface(input) {
|
|
66
66
|
return folderInterfaceKind.has(input);
|
|
67
67
|
}
|
|
68
|
+
const isFolderInterfaceFromUnknown = isFolderInterface;
|
|
68
69
|
//#endregion
|
|
69
|
-
export { createFolderInterface, isFolderInterface };
|
|
70
|
+
export { createFolderInterface, isFolderInterface, isFolderInterfaceFromUnknown };
|
package/dist/file/index.cjs
CHANGED
|
@@ -47,8 +47,11 @@ var file_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
47
47
|
ensureFile: () => require_ensureFile.ensureFile,
|
|
48
48
|
exists: () => require_exists.exists,
|
|
49
49
|
isFileInterface: () => require_fileInterface.isFileInterface,
|
|
50
|
+
isFileInterfaceFromUnknown: () => require_fileInterface.isFileInterfaceFromUnknown,
|
|
50
51
|
isFolderInterface: () => require_folderInterface.isFolderInterface,
|
|
52
|
+
isFolderInterfaceFromUnknown: () => require_folderInterface.isFolderInterfaceFromUnknown,
|
|
51
53
|
isUnknownEntryInterface: () => require_unknownEntryInterface.isUnknownEntryInterface,
|
|
54
|
+
isUnknownEntryInterfaceFromUnknown: () => require_unknownEntryInterface.isUnknownEntryInterfaceFromUnknown,
|
|
52
55
|
link: () => require_link.link,
|
|
53
56
|
linkStat: () => require_linkStat.linkStat,
|
|
54
57
|
makeDirectory: () => require_makeDirectory.makeDirectory,
|
|
@@ -93,8 +96,11 @@ Object.defineProperty(exports, "file_exports", {
|
|
|
93
96
|
}
|
|
94
97
|
});
|
|
95
98
|
exports.isFileInterface = require_fileInterface.isFileInterface;
|
|
99
|
+
exports.isFileInterfaceFromUnknown = require_fileInterface.isFileInterfaceFromUnknown;
|
|
96
100
|
exports.isFolderInterface = require_folderInterface.isFolderInterface;
|
|
101
|
+
exports.isFolderInterfaceFromUnknown = require_folderInterface.isFolderInterfaceFromUnknown;
|
|
97
102
|
exports.isUnknownEntryInterface = require_unknownEntryInterface.isUnknownEntryInterface;
|
|
103
|
+
exports.isUnknownEntryInterfaceFromUnknown = require_unknownEntryInterface.isUnknownEntryInterfaceFromUnknown;
|
|
98
104
|
exports.link = require_link.link;
|
|
99
105
|
exports.linkStat = require_linkStat.linkStat;
|
|
100
106
|
exports.makeDirectory = require_makeDirectory.makeDirectory;
|
package/dist/file/index.d.ts
CHANGED