@duplojs/server 0.0.0-stage → 0.1.0-beta.2
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,29 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_kind = require("../kind.cjs");
|
|
3
|
+
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
4
|
+
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
5
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
6
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
7
|
+
let _duplojs_lang_dataStructure = require("@duplojs/lang/dataStructure");
|
|
8
|
+
_duplojs_lang_dataStructure = require_runtime.__toESM(_duplojs_lang_dataStructure, 1);
|
|
9
|
+
//#region scripts/dataStructure/constraint/size.ts
|
|
10
|
+
const sizeConstraintKind = require_kind.createKind("size-constraint");
|
|
11
|
+
const SizeConstraint = _duplojs_lang_dataStructure.createConstraint(sizeConstraintKind, ({ init }) => (params) => init({
|
|
12
|
+
max: params.max === void 0 ? void 0 : _duplojs_lang_common.stringToBytes(params.max),
|
|
13
|
+
min: params.min === void 0 ? void 0 : _duplojs_lang_common.stringToBytes(params.min)
|
|
14
|
+
}, {
|
|
15
|
+
executeCheck: async (self, data) => {
|
|
16
|
+
const result = _duplojs_lang_either.rightPipe(await data.stat(), (stat) => {
|
|
17
|
+
if (!stat.isFile) return _duplojs_lang_either.fail();
|
|
18
|
+
if (self.definition.max !== void 0 && stat.sizeBytes > self.definition.max) return _duplojs_lang_either.fail();
|
|
19
|
+
if (self.definition.min !== void 0 && stat.sizeBytes < self.definition.min) return _duplojs_lang_either.fail();
|
|
20
|
+
return stat;
|
|
21
|
+
});
|
|
22
|
+
if (_duplojs_lang_either.isLeft(result)) return _duplojs_lang_dataStructure.ErrorSymbol;
|
|
23
|
+
return _duplojs_lang_dataStructure.SuccessSymbol;
|
|
24
|
+
},
|
|
25
|
+
isAsynchronous: () => true
|
|
26
|
+
}));
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.SizeConstraint = SizeConstraint;
|
|
29
|
+
exports.sizeConstraintKind = sizeConstraintKind;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
2
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
3
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
4
|
+
import type * as DSFile from '../../file';
|
|
5
|
+
export declare const sizeConstraintKind: DKind.Handler<DKind.Definition<"@DuplojsServerDataStructure/size-constraint", unknown>>;
|
|
6
|
+
export interface SizeConstraintDefinition extends DDataStructure.ConstraintDefinition {
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SizeConstraintParams {
|
|
11
|
+
min?: number | DCommon.BytesInString;
|
|
12
|
+
max?: number | DCommon.BytesInString;
|
|
13
|
+
}
|
|
14
|
+
export interface SizeConstraint extends DCommon.UnionToIntersection<DDataStructure.Constraint<DSFile.FileInterface, DSFile.FileInterface, SizeConstraintDefinition> & DKind.Kind<typeof sizeConstraintKind>> {
|
|
15
|
+
}
|
|
16
|
+
export declare const SizeConstraint: (params: SizeConstraintParams) => SizeConstraint;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createKind } from "../kind.mjs";
|
|
2
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
3
|
+
import * as DEither from "@duplojs/lang/either";
|
|
4
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
5
|
+
//#region scripts/dataStructure/constraint/size.ts
|
|
6
|
+
const sizeConstraintKind = createKind("size-constraint");
|
|
7
|
+
const SizeConstraint = DDataStructure.createConstraint(sizeConstraintKind, ({ init }) => (params) => init({
|
|
8
|
+
max: params.max === void 0 ? void 0 : DCommon.stringToBytes(params.max),
|
|
9
|
+
min: params.min === void 0 ? void 0 : DCommon.stringToBytes(params.min)
|
|
10
|
+
}, {
|
|
11
|
+
executeCheck: async (self, data) => {
|
|
12
|
+
const result = DEither.rightPipe(await data.stat(), (stat) => {
|
|
13
|
+
if (!stat.isFile) return DEither.fail();
|
|
14
|
+
if (self.definition.max !== void 0 && stat.sizeBytes > self.definition.max) return DEither.fail();
|
|
15
|
+
if (self.definition.min !== void 0 && stat.sizeBytes < self.definition.min) return DEither.fail();
|
|
16
|
+
return stat;
|
|
17
|
+
});
|
|
18
|
+
if (DEither.isLeft(result)) return DDataStructure.ErrorSymbol;
|
|
19
|
+
return DDataStructure.SuccessSymbol;
|
|
20
|
+
},
|
|
21
|
+
isAsynchronous: () => true
|
|
22
|
+
}));
|
|
23
|
+
//#endregion
|
|
24
|
+
export { SizeConstraint, sizeConstraintKind };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExistConstraint } from '../exist';
|
|
2
|
+
import { MimeTypeConstraint } from '../mimeType';
|
|
3
|
+
import { SizeConstraint } from '../size';
|
|
4
|
+
declare module "@duplojs/lang/dataStructure" {
|
|
5
|
+
interface ConstraintsStore {
|
|
6
|
+
exist: ExistConstraint;
|
|
7
|
+
size: SizeConstraint;
|
|
8
|
+
mimeType: MimeTypeConstraint;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './constraints';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_fileInterface = require("../../file/fileInterface.cjs");
|
|
3
|
+
const require_kind = require("../kind.cjs");
|
|
4
|
+
let _duplojs_lang_dataStructure = require("@duplojs/lang/dataStructure");
|
|
5
|
+
_duplojs_lang_dataStructure = require_runtime.__toESM(_duplojs_lang_dataStructure, 1);
|
|
6
|
+
//#region scripts/dataStructure/fundamentalType/file.ts
|
|
7
|
+
const fileFundamentalTypeKind = require_kind.createKind("file-fundamental-type");
|
|
8
|
+
const TheFile = _duplojs_lang_dataStructure.createFundamentalType(fileFundamentalTypeKind, (self, data) => require_fileInterface.isFileInterface(data) ? _duplojs_lang_dataStructure.SuccessSymbol : _duplojs_lang_dataStructure.ErrorSymbol);
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.TheFile = TheFile;
|
|
11
|
+
exports.fileFundamentalTypeKind = fileFundamentalTypeKind;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
2
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
3
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
4
|
+
import * as DSFile from '../../file';
|
|
5
|
+
export declare const fileFundamentalTypeKind: DKind.Handler<DKind.Definition<"@DuplojsServerDataStructure/file-fundamental-type", unknown>>;
|
|
6
|
+
export interface TheFile extends DCommon.UnionToIntersection<DDataStructure.FundamentalType<DSFile.FileInterface> & DKind.Kind<typeof fileFundamentalTypeKind>> {
|
|
7
|
+
}
|
|
8
|
+
export declare const TheFile: TheFile;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { isFileInterface } from "../../file/fileInterface.mjs";
|
|
2
|
+
import { createKind } from "../kind.mjs";
|
|
3
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
4
|
+
//#region scripts/dataStructure/fundamentalType/file.ts
|
|
5
|
+
const fileFundamentalTypeKind = createKind("file-fundamental-type");
|
|
6
|
+
const TheFile = DDataStructure.createFundamentalType(fileFundamentalTypeKind, (self, data) => isFileInterface(data) ? DDataStructure.SuccessSymbol : DDataStructure.ErrorSymbol);
|
|
7
|
+
//#endregion
|
|
8
|
+
export { TheFile, fileFundamentalTypeKind };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './fundamentalTypes';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_file = require("../type/file.cjs");
|
|
3
|
+
let _duplojs_lang_dataStructure = require("@duplojs/lang/dataStructure");
|
|
4
|
+
_duplojs_lang_dataStructure = require_runtime.__toESM(_duplojs_lang_dataStructure, 1);
|
|
5
|
+
//#region scripts/dataStructure/helper/file.ts
|
|
6
|
+
function file(constraints = []) {
|
|
7
|
+
return _duplojs_lang_dataStructure.TypeStructure(require_file.FileType(), constraints);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.file = file;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
2
|
+
import type * as DSFile from '../../file';
|
|
3
|
+
export declare function file<const GenericConstraints extends readonly DDataStructure.Constraint<DSFile.FileInterface>[] = readonly []>(constraints?: GenericConstraints): NoInfer<DDataStructure.TypeStructure<DSFile.FileInterface, readonly [...GenericConstraints]>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FileType } from "../type/file.mjs";
|
|
2
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
3
|
+
//#region scripts/dataStructure/helper/file.ts
|
|
4
|
+
function file(constraints = []) {
|
|
5
|
+
return DDataStructure.TypeStructure(FileType(), constraints);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { file };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_kind = require("./kind.cjs");
|
|
3
|
+
const require_file = require("./fundamentalType/file.cjs");
|
|
4
|
+
const require_json = require("./common/codec/defaults/json.cjs");
|
|
5
|
+
const require_string = require("./common/codec/defaults/string.cjs");
|
|
6
|
+
const require_defaultInterpreter = require("./common/error/defaultInterpreter.cjs");
|
|
7
|
+
const require_exist = require("./constraint/exist.cjs");
|
|
8
|
+
const require_mimeType = require("./constraint/mimeType.cjs");
|
|
9
|
+
const require_size = require("./constraint/size.cjs");
|
|
10
|
+
const require_exist$1 = require("./helper/exist.cjs");
|
|
11
|
+
const require_file$1 = require("./type/file.cjs");
|
|
12
|
+
const require_file$2 = require("./helper/file.cjs");
|
|
13
|
+
const require_mimeType$1 = require("./helper/mimeType.cjs");
|
|
14
|
+
const require_size$1 = require("./helper/size.cjs");
|
|
15
|
+
//#region scripts/dataStructure/index.ts
|
|
16
|
+
var dataStructure_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
17
|
+
ExistConstraint: () => require_exist.ExistConstraint,
|
|
18
|
+
FileType: () => require_file$1.FileType,
|
|
19
|
+
MimeTypeConstraint: () => require_mimeType.MimeTypeConstraint,
|
|
20
|
+
SizeConstraint: () => require_size.SizeConstraint,
|
|
21
|
+
TheFile: () => require_file.TheFile,
|
|
22
|
+
codecsJson: () => require_json.codecsJson,
|
|
23
|
+
codecsString: () => require_string.codecsString,
|
|
24
|
+
createKind: () => require_kind.createKind,
|
|
25
|
+
defaultErrorInterpreterCodecDictionary: () => require_defaultInterpreter.defaultErrorInterpreterCodecDictionary,
|
|
26
|
+
defaultErrorInterpreterDataStructureDictionary: () => require_defaultInterpreter.defaultErrorInterpreterDataStructureDictionary,
|
|
27
|
+
exist: () => require_exist$1.exist,
|
|
28
|
+
existConstraintKind: () => require_exist.existConstraintKind,
|
|
29
|
+
file: () => require_file$2.file,
|
|
30
|
+
fileFundamentalTypeKind: () => require_file.fileFundamentalTypeKind,
|
|
31
|
+
fileTypeKind: () => require_file$1.fileTypeKind,
|
|
32
|
+
mimeType: () => require_mimeType$1.mimeType,
|
|
33
|
+
mimeTypeConstraintKind: () => require_mimeType.mimeTypeConstraintKind,
|
|
34
|
+
size: () => require_size$1.size,
|
|
35
|
+
sizeConstraintKind: () => require_size.sizeConstraintKind
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.ExistConstraint = require_exist.ExistConstraint;
|
|
39
|
+
exports.FileType = require_file$1.FileType;
|
|
40
|
+
exports.MimeTypeConstraint = require_mimeType.MimeTypeConstraint;
|
|
41
|
+
exports.SizeConstraint = require_size.SizeConstraint;
|
|
42
|
+
exports.TheFile = require_file.TheFile;
|
|
43
|
+
exports.codecsJson = require_json.codecsJson;
|
|
44
|
+
exports.codecsString = require_string.codecsString;
|
|
45
|
+
exports.createKind = require_kind.createKind;
|
|
46
|
+
Object.defineProperty(exports, "dataStructure_exports", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function() {
|
|
49
|
+
return dataStructure_exports;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
exports.defaultErrorInterpreterCodecDictionary = require_defaultInterpreter.defaultErrorInterpreterCodecDictionary;
|
|
53
|
+
exports.defaultErrorInterpreterDataStructureDictionary = require_defaultInterpreter.defaultErrorInterpreterDataStructureDictionary;
|
|
54
|
+
exports.exist = require_exist$1.exist;
|
|
55
|
+
exports.existConstraintKind = require_exist.existConstraintKind;
|
|
56
|
+
exports.file = require_file$2.file;
|
|
57
|
+
exports.fileFundamentalTypeKind = require_file.fileFundamentalTypeKind;
|
|
58
|
+
exports.fileTypeKind = require_file$1.fileTypeKind;
|
|
59
|
+
exports.mimeType = require_mimeType$1.mimeType;
|
|
60
|
+
exports.mimeTypeConstraintKind = require_mimeType.mimeTypeConstraintKind;
|
|
61
|
+
exports.size = require_size$1.size;
|
|
62
|
+
exports.sizeConstraintKind = require_size.sizeConstraintKind;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { createKind } from "./kind.mjs";
|
|
3
|
+
import { TheFile, fileFundamentalTypeKind } from "./fundamentalType/file.mjs";
|
|
4
|
+
import { codecsJson } from "./common/codec/defaults/json.mjs";
|
|
5
|
+
import { codecsString } from "./common/codec/defaults/string.mjs";
|
|
6
|
+
import { defaultErrorInterpreterCodecDictionary, defaultErrorInterpreterDataStructureDictionary } from "./common/error/defaultInterpreter.mjs";
|
|
7
|
+
import { ExistConstraint, existConstraintKind } from "./constraint/exist.mjs";
|
|
8
|
+
import { MimeTypeConstraint, mimeTypeConstraintKind } from "./constraint/mimeType.mjs";
|
|
9
|
+
import { SizeConstraint, sizeConstraintKind } from "./constraint/size.mjs";
|
|
10
|
+
import { exist } from "./helper/exist.mjs";
|
|
11
|
+
import { FileType, fileTypeKind } from "./type/file.mjs";
|
|
12
|
+
import { file } from "./helper/file.mjs";
|
|
13
|
+
import { mimeType } from "./helper/mimeType.mjs";
|
|
14
|
+
import { size } from "./helper/size.mjs";
|
|
15
|
+
//#region scripts/dataStructure/index.ts
|
|
16
|
+
var dataStructure_exports = /* @__PURE__ */ __exportAll({
|
|
17
|
+
ExistConstraint: () => ExistConstraint,
|
|
18
|
+
FileType: () => FileType,
|
|
19
|
+
MimeTypeConstraint: () => MimeTypeConstraint,
|
|
20
|
+
SizeConstraint: () => SizeConstraint,
|
|
21
|
+
TheFile: () => TheFile,
|
|
22
|
+
codecsJson: () => codecsJson,
|
|
23
|
+
codecsString: () => codecsString,
|
|
24
|
+
createKind: () => createKind,
|
|
25
|
+
defaultErrorInterpreterCodecDictionary: () => defaultErrorInterpreterCodecDictionary,
|
|
26
|
+
defaultErrorInterpreterDataStructureDictionary: () => defaultErrorInterpreterDataStructureDictionary,
|
|
27
|
+
exist: () => exist,
|
|
28
|
+
existConstraintKind: () => existConstraintKind,
|
|
29
|
+
file: () => file,
|
|
30
|
+
fileFundamentalTypeKind: () => fileFundamentalTypeKind,
|
|
31
|
+
fileTypeKind: () => fileTypeKind,
|
|
32
|
+
mimeType: () => mimeType,
|
|
33
|
+
mimeTypeConstraintKind: () => mimeTypeConstraintKind,
|
|
34
|
+
size: () => size,
|
|
35
|
+
sizeConstraintKind: () => sizeConstraintKind
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ExistConstraint, FileType, MimeTypeConstraint, SizeConstraint, TheFile, codecsJson, codecsString, createKind, dataStructure_exports, defaultErrorInterpreterCodecDictionary, defaultErrorInterpreterDataStructureDictionary, exist, existConstraintKind, file, fileFundamentalTypeKind, fileTypeKind, mimeType, mimeTypeConstraintKind, size, sizeConstraintKind };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let _duplojs_lang_kind = require("@duplojs/lang/kind");
|
|
3
|
+
_duplojs_lang_kind = require_runtime.__toESM(_duplojs_lang_kind, 1);
|
|
4
|
+
//#region scripts/dataStructure/kind.ts
|
|
5
|
+
const createKind = _duplojs_lang_kind.createNamespace("DuplojsServerDataStructure");
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.createKind = createKind;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import * as DKind from "@duplojs/lang/kind";
|
|
2
|
+
export declare const createKind: <GenericName extends string, GenericKindValue extends unknown = unknown>(name: GenericName & import('@duplojs/lang/string').ForbiddenContain<GenericName, DKind.ForbiddenKindNameCharacter>) => DKind.Handler<DKind.Definition<`@DuplojsServerDataStructure/${GenericName}`, GenericKindValue>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const require_runtime = require("../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_kind = require("../kind.cjs");
|
|
3
|
+
const require_file = require("../fundamentalType/file.cjs");
|
|
4
|
+
let _duplojs_lang_dataStructure = require("@duplojs/lang/dataStructure");
|
|
5
|
+
_duplojs_lang_dataStructure = require_runtime.__toESM(_duplojs_lang_dataStructure, 1);
|
|
6
|
+
//#region scripts/dataStructure/type/file.ts
|
|
7
|
+
const fileTypeKind = require_kind.createKind("file-type");
|
|
8
|
+
const FileType = _duplojs_lang_dataStructure.createType(require_file.TheFile, fileTypeKind, ({ init }) => () => init({}, {
|
|
9
|
+
executeCheck: () => _duplojs_lang_dataStructure.SuccessSymbol,
|
|
10
|
+
isAsynchronous: () => false
|
|
11
|
+
}));
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.FileType = FileType;
|
|
14
|
+
exports.fileTypeKind = fileTypeKind;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
2
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
3
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
4
|
+
import type * as DSFile from '../../file';
|
|
5
|
+
import * as FundamentalType from "../fundamentalType";
|
|
6
|
+
export declare const fileTypeKind: DKind.Handler<DKind.Definition<"@DuplojsServerDataStructure/file-type", unknown>>;
|
|
7
|
+
export interface TimeTypeDefinition extends DDataStructure.TypeDefinition {
|
|
8
|
+
}
|
|
9
|
+
export interface FileType extends DCommon.UnionToIntersection<DDataStructure.Type<FundamentalType.TheFile, DSFile.FileInterface, TimeTypeDefinition> & DKind.Kind<typeof fileTypeKind>> {
|
|
10
|
+
}
|
|
11
|
+
export declare const FileType: () => FileType;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createKind } from "../kind.mjs";
|
|
2
|
+
import { TheFile } from "../fundamentalType/file.mjs";
|
|
3
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
4
|
+
//#region scripts/dataStructure/type/file.ts
|
|
5
|
+
const fileTypeKind = createKind("file-type");
|
|
6
|
+
const FileType = DDataStructure.createType(TheFile, fileTypeKind, ({ init }) => () => init({}, {
|
|
7
|
+
executeCheck: () => DDataStructure.SuccessSymbol,
|
|
8
|
+
isAsynchronous: () => false
|
|
9
|
+
}));
|
|
10
|
+
//#endregion
|
|
11
|
+
export { FileType, fileTypeKind };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './types';
|
|
@@ -0,0 +1,43 @@
|
|
|
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/appendFile.ts
|
|
6
|
+
function handleNodeAppendFileError(error) {
|
|
7
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
8
|
+
if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-append-file-not-found", error);
|
|
9
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-append-file-permission-denied", error);
|
|
10
|
+
else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-append-file-is-directory", error);
|
|
11
|
+
else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-append-file-not-directory", error);
|
|
12
|
+
else if (error.code === "ENOSPC") return _duplojs_lang_either.left("file-system-append-file-no-space", error);
|
|
13
|
+
else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-append-file-read-only", error);
|
|
14
|
+
else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-append-file-invalid-argument", error);
|
|
15
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-append-file-too-many-open-files", error);
|
|
16
|
+
else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-append-file-busy", error);
|
|
17
|
+
}
|
|
18
|
+
return _duplojs_lang_either.left("file-system-append-file-error", error);
|
|
19
|
+
}
|
|
20
|
+
function handleDenoAppendFileError(error) {
|
|
21
|
+
if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-append-file-not-found", error);
|
|
22
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-append-file-permission-denied", error);
|
|
23
|
+
if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-append-file-is-directory", error);
|
|
24
|
+
if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-append-file-not-directory", error);
|
|
25
|
+
if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-append-file-invalid-argument", error);
|
|
26
|
+
if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-append-file-busy", error);
|
|
27
|
+
return _duplojs_lang_either.left("file-system-append-file-error", error);
|
|
28
|
+
}
|
|
29
|
+
const appendFileImplementation = require_implementor.implementFunction("appendFile", {
|
|
30
|
+
NODE: async (path, data) => {
|
|
31
|
+
return (await require_implementor.nodeFileSystem.value).appendFile(path, data).then(() => _duplojs_lang_either.right("file-system-append-file")).catch(handleNodeAppendFileError);
|
|
32
|
+
},
|
|
33
|
+
DENO: (path, data) => Deno.writeFile(path, data, { append: true }).then(() => _duplojs_lang_either.right("file-system-append-file")).catch(handleDenoAppendFileError)
|
|
34
|
+
});
|
|
35
|
+
function appendFile(...args) {
|
|
36
|
+
if (args.length === 1) {
|
|
37
|
+
const [data] = args;
|
|
38
|
+
return (path) => appendFileImplementation(path, data);
|
|
39
|
+
}
|
|
40
|
+
return appendFileImplementation(...args);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.appendFile = appendFile;
|
|
@@ -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 AppendFileResult = FileSystemEither<DEither.Right<"append-file", void> | DEither.Left<"append-file-not-found", unknown> | DEither.Left<"append-file-permission-denied", unknown> | DEither.Left<"append-file-is-directory", unknown> | DEither.Left<"append-file-not-directory", unknown> | DEither.Left<"append-file-no-space", unknown> | DEither.Left<"append-file-read-only", unknown> | DEither.Left<"append-file-invalid-argument", unknown> | DEither.Left<"append-file-too-many-open-files", unknown> | DEither.Left<"append-file-busy", unknown> | DEither.Left<"append-file-error", unknown>>;
|
|
5
|
+
declare module '../implementor' {
|
|
6
|
+
interface ServerFunction {
|
|
7
|
+
appendFile(path: string & DPath.Path, data: Uint8Array): Promise<AppendFileResult>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare function appendFile(data: Uint8Array): (path: string & DPath.Path) => Promise<AppendFileResult>;
|
|
11
|
+
export declare function appendFile(path: string & DPath.Path, data: Uint8Array): Promise<AppendFileResult>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { implementFunction, nodeFileSystem } from "../implementor.mjs";
|
|
2
|
+
import * as DEither from "@duplojs/lang/either";
|
|
3
|
+
//#region scripts/file/appendFile.ts
|
|
4
|
+
function handleNodeAppendFileError(error) {
|
|
5
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
6
|
+
if (error.code === "ENOENT") return DEither.left("file-system-append-file-not-found", error);
|
|
7
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return DEither.left("file-system-append-file-permission-denied", error);
|
|
8
|
+
else if (error.code === "EISDIR") return DEither.left("file-system-append-file-is-directory", error);
|
|
9
|
+
else if (error.code === "ENOTDIR") return DEither.left("file-system-append-file-not-directory", error);
|
|
10
|
+
else if (error.code === "ENOSPC") return DEither.left("file-system-append-file-no-space", error);
|
|
11
|
+
else if (error.code === "EROFS") return DEither.left("file-system-append-file-read-only", error);
|
|
12
|
+
else if (error.code === "EINVAL") return DEither.left("file-system-append-file-invalid-argument", error);
|
|
13
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return DEither.left("file-system-append-file-too-many-open-files", error);
|
|
14
|
+
else if (error.code === "EBUSY") return DEither.left("file-system-append-file-busy", error);
|
|
15
|
+
}
|
|
16
|
+
return DEither.left("file-system-append-file-error", error);
|
|
17
|
+
}
|
|
18
|
+
function handleDenoAppendFileError(error) {
|
|
19
|
+
if (error instanceof Deno.errors.NotFound) return DEither.left("file-system-append-file-not-found", error);
|
|
20
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return DEither.left("file-system-append-file-permission-denied", error);
|
|
21
|
+
if (error instanceof Deno.errors.IsADirectory) return DEither.left("file-system-append-file-is-directory", error);
|
|
22
|
+
if (error instanceof Deno.errors.NotADirectory) return DEither.left("file-system-append-file-not-directory", error);
|
|
23
|
+
if (error instanceof Deno.errors.InvalidData) return DEither.left("file-system-append-file-invalid-argument", error);
|
|
24
|
+
if (error instanceof Deno.errors.Busy) return DEither.left("file-system-append-file-busy", error);
|
|
25
|
+
return DEither.left("file-system-append-file-error", error);
|
|
26
|
+
}
|
|
27
|
+
const appendFileImplementation = implementFunction("appendFile", {
|
|
28
|
+
NODE: async (path, data) => {
|
|
29
|
+
return (await nodeFileSystem.value).appendFile(path, data).then(() => DEither.right("file-system-append-file")).catch(handleNodeAppendFileError);
|
|
30
|
+
},
|
|
31
|
+
DENO: (path, data) => Deno.writeFile(path, data, { append: true }).then(() => DEither.right("file-system-append-file")).catch(handleDenoAppendFileError)
|
|
32
|
+
});
|
|
33
|
+
function appendFile(...args) {
|
|
34
|
+
if (args.length === 1) {
|
|
35
|
+
const [data] = args;
|
|
36
|
+
return (path) => appendFileImplementation(path, data);
|
|
37
|
+
}
|
|
38
|
+
return appendFileImplementation(...args);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { appendFile };
|
|
@@ -0,0 +1,43 @@
|
|
|
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/appendTextFile.ts
|
|
6
|
+
function handleNodeAppendTextFileError(error) {
|
|
7
|
+
if (typeof error === "object" && error !== null && "code" in error) {
|
|
8
|
+
if (error.code === "ENOENT") return _duplojs_lang_either.left("file-system-append-text-file-not-found", error);
|
|
9
|
+
else if (error.code === "EACCES" || error.code === "EPERM") return _duplojs_lang_either.left("file-system-append-text-file-permission-denied", error);
|
|
10
|
+
else if (error.code === "EISDIR") return _duplojs_lang_either.left("file-system-append-text-file-is-directory", error);
|
|
11
|
+
else if (error.code === "ENOTDIR") return _duplojs_lang_either.left("file-system-append-text-file-not-directory", error);
|
|
12
|
+
else if (error.code === "ENOSPC") return _duplojs_lang_either.left("file-system-append-text-file-no-space", error);
|
|
13
|
+
else if (error.code === "EROFS") return _duplojs_lang_either.left("file-system-append-text-file-read-only", error);
|
|
14
|
+
else if (error.code === "EINVAL") return _duplojs_lang_either.left("file-system-append-text-file-invalid-argument", error);
|
|
15
|
+
else if (error.code === "EMFILE" || error.code === "ENFILE") return _duplojs_lang_either.left("file-system-append-text-file-too-many-open-files", error);
|
|
16
|
+
else if (error.code === "EBUSY") return _duplojs_lang_either.left("file-system-append-text-file-busy", error);
|
|
17
|
+
}
|
|
18
|
+
return _duplojs_lang_either.left("file-system-append-text-file-error", error);
|
|
19
|
+
}
|
|
20
|
+
function handleDenoAppendTextFileError(error) {
|
|
21
|
+
if (error instanceof Deno.errors.NotFound) return _duplojs_lang_either.left("file-system-append-text-file-not-found", error);
|
|
22
|
+
if (error instanceof Deno.errors.PermissionDenied || error instanceof Deno.errors.NotCapable) return _duplojs_lang_either.left("file-system-append-text-file-permission-denied", error);
|
|
23
|
+
if (error instanceof Deno.errors.IsADirectory) return _duplojs_lang_either.left("file-system-append-text-file-is-directory", error);
|
|
24
|
+
if (error instanceof Deno.errors.NotADirectory) return _duplojs_lang_either.left("file-system-append-text-file-not-directory", error);
|
|
25
|
+
if (error instanceof Deno.errors.InvalidData) return _duplojs_lang_either.left("file-system-append-text-file-invalid-argument", error);
|
|
26
|
+
if (error instanceof Deno.errors.Busy) return _duplojs_lang_either.left("file-system-append-text-file-busy", error);
|
|
27
|
+
return _duplojs_lang_either.left("file-system-append-text-file-error", error);
|
|
28
|
+
}
|
|
29
|
+
const appendTextFileImplementation = require_implementor.implementFunction("appendTextFile", {
|
|
30
|
+
NODE: async (path, data) => {
|
|
31
|
+
return (await require_implementor.nodeFileSystem.value).appendFile(path, data).then(() => _duplojs_lang_either.right("file-system-append-text-file")).catch(handleNodeAppendTextFileError);
|
|
32
|
+
},
|
|
33
|
+
DENO: (path, data) => Deno.writeTextFile(path, data, { append: true }).then(() => _duplojs_lang_either.right("file-system-append-text-file")).catch(handleDenoAppendTextFileError)
|
|
34
|
+
});
|
|
35
|
+
function appendTextFile(...args) {
|
|
36
|
+
if (args.length === 1) {
|
|
37
|
+
const [data] = args;
|
|
38
|
+
return (path) => appendTextFileImplementation(path, data);
|
|
39
|
+
}
|
|
40
|
+
return appendTextFileImplementation(...args);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
exports.appendTextFile = appendTextFile;
|
|
@@ -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 AppendTextFileResult = FileSystemEither<DEither.Right<"append-text-file", void> | DEither.Left<"append-text-file-not-found", unknown> | DEither.Left<"append-text-file-permission-denied", unknown> | DEither.Left<"append-text-file-is-directory", unknown> | DEither.Left<"append-text-file-not-directory", unknown> | DEither.Left<"append-text-file-no-space", unknown> | DEither.Left<"append-text-file-read-only", unknown> | DEither.Left<"append-text-file-invalid-argument", unknown> | DEither.Left<"append-text-file-too-many-open-files", unknown> | DEither.Left<"append-text-file-busy", unknown> | DEither.Left<"append-text-file-error", unknown>>;
|
|
5
|
+
declare module '../implementor' {
|
|
6
|
+
interface ServerFunction {
|
|
7
|
+
appendTextFile(path: string & DPath.Path, data: string): Promise<AppendTextFileResult>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare function appendTextFile(data: string): (path: string & DPath.Path) => Promise<AppendTextFileResult>;
|
|
11
|
+
export declare function appendTextFile(path: string & DPath.Path, data: string): Promise<AppendTextFileResult>;
|