@duplojs/server 0.0.0-stage → 0.1.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/_virtual/_rolldown/runtime.cjs +33 -0
- package/dist/_virtual/_rolldown/runtime.mjs +17 -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 +102 -0
- package/dist/command/create.d.ts +47 -0
- package/dist/command/create.mjs +96 -0
- package/dist/command/error.cjs +206 -0
- package/dist/command/error.d.ts +61 -0
- package/dist/command/error.mjs +193 -0
- package/dist/command/exec.cjs +19 -0
- package/dist/command/exec.d.ts +14 -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 +250 -0
- package/dist/command/help.d.ts +10 -0
- package/dist/command/help.mjs +237 -0
- package/dist/command/index.cjs +82 -0
- package/dist/command/index.d.ts +8 -0
- package/dist/command/index.mjs +47 -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 +76 -0
- package/dist/command/options/base.d.ts +30 -0
- package/dist/command/options/base.mjs +69 -0
- package/dist/command/options/defaults/array.cjs +35 -0
- package/dist/command/options/defaults/array.d.ts +26 -0
- package/dist/command/options/defaults/array.mjs +29 -0
- package/dist/command/options/defaults/boolean.cjs +28 -0
- package/dist/command/options/defaults/boolean.d.ts +14 -0
- package/dist/command/options/defaults/boolean.mjs +25 -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 +18 -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/forbiddenInvalidIdentifier.d.ts +6 -0
- package/dist/command/types/index.d.ts +3 -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 +5 -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 +44 -0
- package/dist/common/index.d.ts +9 -0
- package/dist/common/index.mjs +27 -0
- 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/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 +25 -0
- package/dist/dataStructure/common/codec/defaults/json.d.ts +9 -0
- package/dist/dataStructure/common/codec/defaults/json.mjs +22 -0
- package/dist/dataStructure/common/codec/defaults/string.cjs +25 -0
- package/dist/dataStructure/common/codec/defaults/string.d.ts +13 -0
- package/dist/dataStructure/common/codec/defaults/string.mjs +22 -0
- package/dist/dataStructure/common/codec/index.d.ts +1 -0
- package/dist/dataStructure/common/error/defaultInterpreter.cjs +29 -0
- package/dist/dataStructure/common/error/defaultInterpreter.d.ts +69 -0
- package/dist/dataStructure/common/error/defaultInterpreter.mjs +26 -0
- package/dist/dataStructure/common/error/index.d.ts +1 -0
- package/dist/dataStructure/common/index.d.ts +2 -0
- package/dist/dataStructure/constraint/fileExist.cjs +19 -0
- package/dist/dataStructure/constraint/fileExist.d.ts +10 -0
- package/dist/dataStructure/constraint/fileExist.mjs +15 -0
- 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 +5 -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 +12 -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/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 +3 -0
- package/dist/dataStructure/fundamentalType/types/fundamentalTypes.d.ts +8 -0
- package/dist/dataStructure/fundamentalType/types/index.d.ts +1 -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/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 +6 -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 +83 -0
- package/dist/dataStructure/index.d.ts +6 -0
- package/dist/dataStructure/index.mjs +51 -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/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 +3 -0
- package/dist/dataStructure/type/types/index.d.ts +1 -0
- package/dist/dataStructure/type/types/types.d.ts +8 -0
- package/dist/file/appendFile.cjs +67 -0
- package/dist/file/appendFile.d.ts +43 -0
- package/dist/file/appendFile.mjs +54 -0
- package/dist/file/appendTextFile.cjs +67 -0
- package/dist/file/appendTextFile.d.ts +43 -0
- package/dist/file/appendTextFile.mjs +54 -0
- package/dist/file/copy.cjs +53 -0
- package/dist/file/copy.d.ts +43 -0
- package/dist/file/copy.mjs +40 -0
- package/dist/file/createEntryInterface.cjs +19 -0
- package/dist/file/createEntryInterface.d.ts +3 -0
- package/dist/file/createEntryInterface.mjs +15 -0
- package/dist/file/ensureDirectory.cjs +52 -0
- package/dist/file/ensureDirectory.d.ts +36 -0
- package/dist/file/ensureDirectory.mjs +41 -0
- package/dist/file/ensureFile.cjs +60 -0
- package/dist/file/ensureFile.d.ts +39 -0
- package/dist/file/ensureFile.mjs +48 -0
- package/dist/file/exists.cjs +43 -0
- package/dist/file/exists.d.ts +27 -0
- package/dist/file/exists.mjs +35 -0
- package/dist/file/fileInterface.cjs +76 -0
- package/dist/file/fileInterface.d.ts +31 -0
- package/dist/file/fileInterface.mjs +70 -0
- package/dist/file/folderInterface.cjs +76 -0
- package/dist/file/folderInterface.d.ts +33 -0
- package/dist/file/folderInterface.mjs +70 -0
- package/dist/file/index.cjs +634 -0
- package/dist/file/index.d.ts +35 -0
- package/dist/file/index.mjs +335 -0
- package/dist/file/link.cjs +70 -0
- package/dist/file/link.d.ts +46 -0
- package/dist/file/link.mjs +56 -0
- package/dist/file/linkStat.cjs +98 -0
- package/dist/file/linkStat.d.ts +31 -0
- package/dist/file/linkStat.mjs +88 -0
- package/dist/file/makeDirectory.cjs +60 -0
- package/dist/file/makeDirectory.d.ts +45 -0
- package/dist/file/makeDirectory.mjs +47 -0
- package/dist/file/makeTemporaryDirectory.cjs +48 -0
- package/dist/file/makeTemporaryDirectory.d.ts +32 -0
- package/dist/file/makeTemporaryDirectory.mjs +38 -0
- package/dist/file/makeTemporaryFile.cjs +62 -0
- package/dist/file/makeTemporaryFile.d.ts +36 -0
- package/dist/file/makeTemporaryFile.mjs +50 -0
- package/dist/file/move.cjs +71 -0
- package/dist/file/move.d.ts +46 -0
- package/dist/file/move.mjs +57 -0
- package/dist/file/readDirectory.cjs +44 -0
- package/dist/file/readDirectory.d.ts +35 -0
- package/dist/file/readDirectory.mjs +33 -0
- package/dist/file/readFile.cjs +51 -0
- package/dist/file/readFile.d.ts +33 -0
- package/dist/file/readFile.mjs +41 -0
- package/dist/file/readJsonFile.cjs +51 -0
- package/dist/file/readJsonFile.d.ts +33 -0
- package/dist/file/readJsonFile.mjs +41 -0
- package/dist/file/readLink.cjs +46 -0
- package/dist/file/readLink.d.ts +30 -0
- package/dist/file/readLink.mjs +37 -0
- package/dist/file/readTextFile.cjs +51 -0
- package/dist/file/readTextFile.d.ts +33 -0
- package/dist/file/readTextFile.mjs +41 -0
- package/dist/file/realPath.cjs +42 -0
- package/dist/file/realPath.d.ts +27 -0
- package/dist/file/realPath.mjs +34 -0
- package/dist/file/relocate.cjs +83 -0
- package/dist/file/relocate.d.ts +46 -0
- package/dist/file/relocate.mjs +68 -0
- package/dist/file/remove.cjs +60 -0
- package/dist/file/remove.d.ts +42 -0
- package/dist/file/remove.mjs +48 -0
- package/dist/file/rename.cjs +83 -0
- package/dist/file/rename.d.ts +46 -0
- package/dist/file/rename.mjs +68 -0
- package/dist/file/setMode.cjs +65 -0
- package/dist/file/setMode.d.ts +45 -0
- package/dist/file/setMode.mjs +56 -0
- package/dist/file/setOwner.cjs +53 -0
- package/dist/file/setOwner.d.ts +35 -0
- package/dist/file/setOwner.mjs +44 -0
- package/dist/file/setTime.cjs +55 -0
- package/dist/file/setTime.d.ts +36 -0
- package/dist/file/setTime.mjs +45 -0
- package/dist/file/stat.cjs +99 -0
- package/dist/file/stat.d.ts +62 -0
- package/dist/file/stat.mjs +89 -0
- package/dist/file/symlink.cjs +64 -0
- package/dist/file/symlink.d.ts +48 -0
- package/dist/file/symlink.mjs +52 -0
- package/dist/file/truncate.cjs +60 -0
- package/dist/file/truncate.d.ts +42 -0
- package/dist/file/truncate.mjs +47 -0
- package/dist/file/unknownEntryInterface.cjs +40 -0
- package/dist/file/unknownEntryInterface.d.ts +17 -0
- package/dist/file/unknownEntryInterface.mjs +35 -0
- package/dist/file/walkDirectory.cjs +57 -0
- package/dist/file/walkDirectory.d.ts +37 -0
- package/dist/file/walkDirectory.mjs +45 -0
- package/dist/file/writeFile.cjs +68 -0
- package/dist/file/writeFile.d.ts +43 -0
- package/dist/file/writeFile.mjs +55 -0
- package/dist/file/writeJsonFile.cjs +77 -0
- package/dist/file/writeJsonFile.d.ts +46 -0
- package/dist/file/writeJsonFile.mjs +64 -0
- package/dist/file/writeTextFile.cjs +68 -0
- package/dist/file/writeTextFile.d.ts +43 -0
- package/dist/file/writeTextFile.mjs +55 -0
- package/dist/implementor.cjs +67 -0
- package/dist/implementor.d.ts +35 -0
- package/dist/implementor.mjs +55 -0
- package/dist/index.cjs +76 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.mjs +15 -0
- package/dist/kind.cjs +7 -0
- package/dist/kind.d.ts +2 -0
- package/dist/kind.mjs +5 -0
- package/dist/override.d.ts +8 -0
- package/package.json +81 -3
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @duplojs/server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@duplojs/server)
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @duplojs/server
|
|
9
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
+
key = keys[i];
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
+
get: ((k) => from[k]).bind(null, key),
|
|
22
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.__exportAll = __exportAll;
|
|
33
|
+
exports.__toESM = __toESM;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
13
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
14
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { __exportAll, __require };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_string = require("../dataStructure/common/codec/defaults/string.cjs");
|
|
3
|
+
const require_kind = require("./kind.cjs");
|
|
4
|
+
let _duplojs_lang_either = require("@duplojs/lang/either");
|
|
5
|
+
_duplojs_lang_either = require_runtime.__toESM(_duplojs_lang_either, 1);
|
|
6
|
+
//#region scripts/command/argument.ts
|
|
7
|
+
const argumentKind = require_kind.createKind("command-argument");
|
|
8
|
+
function createArgument(name, dataStructure, params) {
|
|
9
|
+
const self = {
|
|
10
|
+
name,
|
|
11
|
+
dataStructure,
|
|
12
|
+
description: params?.description ?? null,
|
|
13
|
+
optional: params?.optional ?? false,
|
|
14
|
+
execute: async (argument, error) => {
|
|
15
|
+
if (self.optional === false && argument === void 0) return error.addRequiredArgumentIssue(self.name);
|
|
16
|
+
if (argument === void 0) return;
|
|
17
|
+
const result = await self.dataStructure.asyncDecode(require_string.codecsString, argument);
|
|
18
|
+
if (_duplojs_lang_either.isLeft(result)) return error.addDataStructureArgumentIssue(self.name, argument, _duplojs_lang_either.unwrapLeft(result));
|
|
19
|
+
return _duplojs_lang_either.unwrapRight(result);
|
|
20
|
+
},
|
|
21
|
+
[argumentKind.runTimeKey]: null
|
|
22
|
+
};
|
|
23
|
+
return self;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.argumentKind = argumentKind;
|
|
27
|
+
exports.createArgument = createArgument;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Error, SymbolCommandError } from './error';
|
|
2
|
+
import { EligibleType, ForbiddenInvalidIdentifier } from './types';
|
|
3
|
+
import type * as DCommon from "@duplojs/lang/common";
|
|
4
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
5
|
+
import type * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
6
|
+
export declare const argumentKind: DKind.Handler<DKind.Definition<"@DuplojsServerCommand/command-argument", unknown>>;
|
|
7
|
+
export interface Argument<GenericName extends string = string, GenericValue extends EligibleType = EligibleType> extends DKind.Kind<typeof argumentKind> {
|
|
8
|
+
readonly name: GenericName;
|
|
9
|
+
readonly dataStructure: DDataStructure.Structure<GenericValue>;
|
|
10
|
+
readonly optional: boolean;
|
|
11
|
+
readonly description: string | null;
|
|
12
|
+
execute(argument: string | undefined, error: Error): Promise<GenericValue | SymbolCommandError>;
|
|
13
|
+
}
|
|
14
|
+
export interface CreateArgumentParams {
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
readonly optional?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function createArgument<GenericName extends string, GenericStructure extends DDataStructure.Structure<EligibleType>, GenericValue extends DDataStructure.StructureValue<GenericStructure>, const GenericParams extends CreateArgumentParams = {}>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, dataStructure: GenericStructure, params?: GenericParams): Argument<GenericName, (GenericValue | (DCommon.IsEqual<GenericParams["optional"], true> extends true ? undefined : never))>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { codecsString } from "../dataStructure/common/codec/defaults/string.mjs";
|
|
2
|
+
import { createKind } from "./kind.mjs";
|
|
3
|
+
import * as DEither from "@duplojs/lang/either";
|
|
4
|
+
//#region scripts/command/argument.ts
|
|
5
|
+
const argumentKind = createKind("command-argument");
|
|
6
|
+
function createArgument(name, dataStructure, params) {
|
|
7
|
+
const self = {
|
|
8
|
+
name,
|
|
9
|
+
dataStructure,
|
|
10
|
+
description: params?.description ?? null,
|
|
11
|
+
optional: params?.optional ?? false,
|
|
12
|
+
execute: async (argument, error) => {
|
|
13
|
+
if (self.optional === false && argument === void 0) return error.addRequiredArgumentIssue(self.name);
|
|
14
|
+
if (argument === void 0) return;
|
|
15
|
+
const result = await self.dataStructure.asyncDecode(codecsString, argument);
|
|
16
|
+
if (DEither.isLeft(result)) return error.addDataStructureArgumentIssue(self.name, argument, DEither.unwrapLeft(result));
|
|
17
|
+
return DEither.unwrapRight(result);
|
|
18
|
+
},
|
|
19
|
+
[argumentKind.runTimeKey]: null
|
|
20
|
+
};
|
|
21
|
+
return self;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { argumentKind, createArgument };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_kind = require("./kind.cjs");
|
|
3
|
+
const require_error = require("./error.cjs");
|
|
4
|
+
const require_base = require("./options/base.cjs");
|
|
5
|
+
const require_help = require("./help.cjs");
|
|
6
|
+
let _duplojs_lang_common = require("@duplojs/lang/common");
|
|
7
|
+
_duplojs_lang_common = require_runtime.__toESM(_duplojs_lang_common, 1);
|
|
8
|
+
let _duplojs_lang_object = require("@duplojs/lang/object");
|
|
9
|
+
_duplojs_lang_object = require_runtime.__toESM(_duplojs_lang_object, 1);
|
|
10
|
+
let _duplojs_lang_array = require("@duplojs/lang/array");
|
|
11
|
+
_duplojs_lang_array = require_runtime.__toESM(_duplojs_lang_array, 1);
|
|
12
|
+
let _duplojs_lang_generator = require("@duplojs/lang/generator");
|
|
13
|
+
_duplojs_lang_generator = require_runtime.__toESM(_duplojs_lang_generator, 1);
|
|
14
|
+
//#region scripts/command/create.ts
|
|
15
|
+
const commandKind = require_kind.createKind("command");
|
|
16
|
+
function isCommands(input) {
|
|
17
|
+
return input instanceof Array ? input.every(commandKind.has) : false;
|
|
18
|
+
}
|
|
19
|
+
function create(...args) {
|
|
20
|
+
const [name, params, execute] = args.length === 2 ? [
|
|
21
|
+
args[0],
|
|
22
|
+
{},
|
|
23
|
+
args[1]
|
|
24
|
+
] : args;
|
|
25
|
+
const self = {
|
|
26
|
+
name,
|
|
27
|
+
description: params.description ?? null,
|
|
28
|
+
options: params.options ?? [],
|
|
29
|
+
subject: _duplojs_lang_common.justExec(() => {
|
|
30
|
+
if (isCommands(params.subjects)) return {
|
|
31
|
+
type: "subCommand",
|
|
32
|
+
subCommands: params.subjects
|
|
33
|
+
};
|
|
34
|
+
else if (params.subjects) return {
|
|
35
|
+
type: "argument",
|
|
36
|
+
args: params.subjects
|
|
37
|
+
};
|
|
38
|
+
return null;
|
|
39
|
+
}),
|
|
40
|
+
execute: async (args, error) => {
|
|
41
|
+
if (self.subject?.type === "subCommand") {
|
|
42
|
+
for (const command of self.subject.subCommands) if (args[0] === command.name) {
|
|
43
|
+
error.pushPath(command.name);
|
|
44
|
+
return command.execute(_duplojs_lang_array.shift(args), error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const help = await require_help.helpOption.execute(args, error);
|
|
48
|
+
if (help === require_error.SymbolCommandError) return require_error.SymbolCommandError;
|
|
49
|
+
else if (help.result) {
|
|
50
|
+
require_help.logCommandHelp(self);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const commandOptions = await _duplojs_lang_generator.asyncReduce(self.options, _duplojs_lang_generator.reduceFrom({
|
|
54
|
+
options: {},
|
|
55
|
+
restArgs: args,
|
|
56
|
+
hasError: false
|
|
57
|
+
}), async ({ item: option, lastValue, next }) => {
|
|
58
|
+
const optionResult = await option.execute(lastValue.restArgs, error);
|
|
59
|
+
if (optionResult === require_error.SymbolCommandError) return next(_duplojs_lang_object.override(lastValue, { hasError: true }));
|
|
60
|
+
return next({
|
|
61
|
+
options: _duplojs_lang_object.override(lastValue.options, { [option.name]: optionResult.result }),
|
|
62
|
+
restArgs: optionResult.argumentRest,
|
|
63
|
+
hasError: lastValue.hasError
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
if (commandOptions.hasError === true) return require_error.SymbolCommandError;
|
|
67
|
+
const unknownOptions = _duplojs_lang_array.filter(commandOptions.restArgs, require_base.isOptionToken);
|
|
68
|
+
if (unknownOptions.length > 0) return error.addUnknownOptionIssue(unknownOptions);
|
|
69
|
+
if (self.subject?.type === "argument") {
|
|
70
|
+
if (self.subject.args.length < commandOptions.restArgs.length) return error.addTooMuchCommandArgumentIssue(self.subject.args.length, commandOptions.restArgs.length);
|
|
71
|
+
const commandArgs = await _duplojs_lang_generator.asyncReduce(self.subject.args, _duplojs_lang_generator.reduceFrom({
|
|
72
|
+
args: {},
|
|
73
|
+
restArgs: commandOptions.restArgs
|
|
74
|
+
}), async ({ item: argument, lastValue, next, exit }) => {
|
|
75
|
+
const firstArgument = _duplojs_lang_array.first(lastValue.restArgs);
|
|
76
|
+
const argumentResult = await argument.execute(firstArgument, error);
|
|
77
|
+
if (argumentResult === require_error.SymbolCommandError) return exit(require_error.SymbolCommandError);
|
|
78
|
+
return next({
|
|
79
|
+
args: _duplojs_lang_object.override(lastValue.args, { [argument.name]: argumentResult }),
|
|
80
|
+
restArgs: _duplojs_lang_array.shift(lastValue.restArgs)
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
if (commandArgs === require_error.SymbolCommandError) return require_error.SymbolCommandError;
|
|
84
|
+
await execute({
|
|
85
|
+
options: commandOptions.options,
|
|
86
|
+
args: commandArgs.args
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
if (commandOptions.restArgs.length > 0) {
|
|
90
|
+
if (self.subject?.type === "subCommand") return error.addUnknownSubCommandIssue(commandOptions.restArgs[0]);
|
|
91
|
+
return error.addTooMuchCommandArgumentIssue(0, commandOptions.restArgs.length);
|
|
92
|
+
}
|
|
93
|
+
await execute({ options: commandOptions.options });
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
[commandKind.runTimeKey]: null
|
|
97
|
+
};
|
|
98
|
+
return self;
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
exports.create = create;
|
|
102
|
+
exports.isCommands = isCommands;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Option } from './options';
|
|
2
|
+
import { SymbolCommandError, Error } from './error';
|
|
3
|
+
import { Argument } from './argument';
|
|
4
|
+
import { ForbiddenDuplicateName, ForbiddenInvalidIdentifier } from './types';
|
|
5
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
6
|
+
import type * as DKind from "@duplojs/lang/kind";
|
|
7
|
+
declare const commandKind: DKind.Handler<DKind.Definition<"@DuplojsServerCommand/command", unknown>>;
|
|
8
|
+
export declare function isCommands(input: unknown): input is DCommon.AnyTuple<Command>;
|
|
9
|
+
type CommandSubject = {
|
|
10
|
+
readonly type: "subCommand";
|
|
11
|
+
readonly subCommands: readonly Command[];
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "argument";
|
|
14
|
+
readonly args: readonly Argument[];
|
|
15
|
+
};
|
|
16
|
+
export interface Command<GenericName extends string = string> extends DKind.Kind<typeof commandKind> {
|
|
17
|
+
readonly name: GenericName;
|
|
18
|
+
readonly description: string | null;
|
|
19
|
+
readonly subject: CommandSubject | null;
|
|
20
|
+
readonly options: readonly Option[];
|
|
21
|
+
execute(args: readonly string[], error: Error): Promise<undefined | SymbolCommandError>;
|
|
22
|
+
}
|
|
23
|
+
export type Subjects = (DCommon.AnyTuple<Argument> | DCommon.AnyTuple<Command>);
|
|
24
|
+
export type ForbiddenBadOrderArguments<GenericSubject extends readonly Subjects[number][], GenericContainOptional extends boolean = false> = GenericSubject extends readonly [
|
|
25
|
+
Argument<string, infer InferredValue>,
|
|
26
|
+
...infer InferredRest extends Argument[]
|
|
27
|
+
] ? DCommon.And<[
|
|
28
|
+
DCommon.IsEqual<GenericContainOptional, true>,
|
|
29
|
+
DCommon.Not<DCommon.UnionContain<InferredValue, undefined>>
|
|
30
|
+
]> extends true ? DCommon.ComputedTypeError<"Optional argument can't be define before required argument"> : ForbiddenBadOrderArguments<InferredRest, DCommon.UnionContain<InferredValue, undefined>> : unknown;
|
|
31
|
+
export interface CreateCommandParams<GenericOptions extends DCommon.AnyTuple<Option> = DCommon.AnyTuple<Option>, GenericSubject extends Subjects = Subjects> {
|
|
32
|
+
readonly description?: string;
|
|
33
|
+
readonly options?: (GenericOptions & ForbiddenDuplicateName<GenericOptions, "option">);
|
|
34
|
+
readonly subjects?: (GenericSubject & ForbiddenDuplicateName<GenericSubject, "subject"> & ForbiddenBadOrderArguments<GenericSubject>);
|
|
35
|
+
}
|
|
36
|
+
export type CreateCommandExecuteParams<GenericOptions extends DCommon.AnyTuple<Option>, GenericArguments extends DCommon.AnyTuple<Argument>> = ((DCommon.IsEqual<GenericOptions, never> extends true ? {} : {
|
|
37
|
+
options: {
|
|
38
|
+
readonly [GenericOption in GenericOptions[number] as GenericOption["name"]]: Exclude<Awaited<ReturnType<GenericOption["execute"]>>, SymbolCommandError>["result"];
|
|
39
|
+
};
|
|
40
|
+
}) & (DCommon.IsEqual<GenericArguments, never> extends true ? {} : {
|
|
41
|
+
args: {
|
|
42
|
+
readonly [GenericArgument in GenericArguments[number] as GenericArgument["name"]]: Exclude<Awaited<ReturnType<GenericArgument["execute"]>>, SymbolCommandError>;
|
|
43
|
+
};
|
|
44
|
+
}));
|
|
45
|
+
export declare function create<GenericName extends string>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, execute: () => void): Command<GenericName>;
|
|
46
|
+
export declare function create<GenericName extends string, const GenericOptions extends DCommon.AnyTuple<Option> = never, GenericSubjects extends Subjects = never>(name: GenericName & ForbiddenInvalidIdentifier<GenericName>, params: CreateCommandParams<GenericOptions, GenericSubjects>, execute: (params: CreateCommandExecuteParams<GenericOptions, Extract<GenericSubjects, DCommon.AnyTuple<Argument>>>) => DCommon.MaybePromise<void>): Command<GenericName>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createKind } from "./kind.mjs";
|
|
2
|
+
import { SymbolCommandError } from "./error.mjs";
|
|
3
|
+
import { isOptionToken } from "./options/base.mjs";
|
|
4
|
+
import { helpOption, logCommandHelp } from "./help.mjs";
|
|
5
|
+
import * as DCommon from "@duplojs/lang/common";
|
|
6
|
+
import * as DObject from "@duplojs/lang/object";
|
|
7
|
+
import * as DArray from "@duplojs/lang/array";
|
|
8
|
+
import * as DGenerator from "@duplojs/lang/generator";
|
|
9
|
+
//#region scripts/command/create.ts
|
|
10
|
+
const commandKind = createKind("command");
|
|
11
|
+
function isCommands(input) {
|
|
12
|
+
return input instanceof Array ? input.every(commandKind.has) : false;
|
|
13
|
+
}
|
|
14
|
+
function create(...args) {
|
|
15
|
+
const [name, params, execute] = args.length === 2 ? [
|
|
16
|
+
args[0],
|
|
17
|
+
{},
|
|
18
|
+
args[1]
|
|
19
|
+
] : args;
|
|
20
|
+
const self = {
|
|
21
|
+
name,
|
|
22
|
+
description: params.description ?? null,
|
|
23
|
+
options: params.options ?? [],
|
|
24
|
+
subject: DCommon.justExec(() => {
|
|
25
|
+
if (isCommands(params.subjects)) return {
|
|
26
|
+
type: "subCommand",
|
|
27
|
+
subCommands: params.subjects
|
|
28
|
+
};
|
|
29
|
+
else if (params.subjects) return {
|
|
30
|
+
type: "argument",
|
|
31
|
+
args: params.subjects
|
|
32
|
+
};
|
|
33
|
+
return null;
|
|
34
|
+
}),
|
|
35
|
+
execute: async (args, error) => {
|
|
36
|
+
if (self.subject?.type === "subCommand") {
|
|
37
|
+
for (const command of self.subject.subCommands) if (args[0] === command.name) {
|
|
38
|
+
error.pushPath(command.name);
|
|
39
|
+
return command.execute(DArray.shift(args), error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const help = await helpOption.execute(args, error);
|
|
43
|
+
if (help === SymbolCommandError) return SymbolCommandError;
|
|
44
|
+
else if (help.result) {
|
|
45
|
+
logCommandHelp(self);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const commandOptions = await DGenerator.asyncReduce(self.options, DGenerator.reduceFrom({
|
|
49
|
+
options: {},
|
|
50
|
+
restArgs: args,
|
|
51
|
+
hasError: false
|
|
52
|
+
}), async ({ item: option, lastValue, next }) => {
|
|
53
|
+
const optionResult = await option.execute(lastValue.restArgs, error);
|
|
54
|
+
if (optionResult === SymbolCommandError) return next(DObject.override(lastValue, { hasError: true }));
|
|
55
|
+
return next({
|
|
56
|
+
options: DObject.override(lastValue.options, { [option.name]: optionResult.result }),
|
|
57
|
+
restArgs: optionResult.argumentRest,
|
|
58
|
+
hasError: lastValue.hasError
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
if (commandOptions.hasError === true) return SymbolCommandError;
|
|
62
|
+
const unknownOptions = DArray.filter(commandOptions.restArgs, isOptionToken);
|
|
63
|
+
if (unknownOptions.length > 0) return error.addUnknownOptionIssue(unknownOptions);
|
|
64
|
+
if (self.subject?.type === "argument") {
|
|
65
|
+
if (self.subject.args.length < commandOptions.restArgs.length) return error.addTooMuchCommandArgumentIssue(self.subject.args.length, commandOptions.restArgs.length);
|
|
66
|
+
const commandArgs = await DGenerator.asyncReduce(self.subject.args, DGenerator.reduceFrom({
|
|
67
|
+
args: {},
|
|
68
|
+
restArgs: commandOptions.restArgs
|
|
69
|
+
}), async ({ item: argument, lastValue, next, exit }) => {
|
|
70
|
+
const firstArgument = DArray.first(lastValue.restArgs);
|
|
71
|
+
const argumentResult = await argument.execute(firstArgument, error);
|
|
72
|
+
if (argumentResult === SymbolCommandError) return exit(SymbolCommandError);
|
|
73
|
+
return next({
|
|
74
|
+
args: DObject.override(lastValue.args, { [argument.name]: argumentResult }),
|
|
75
|
+
restArgs: DArray.shift(lastValue.restArgs)
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
if (commandArgs === SymbolCommandError) return SymbolCommandError;
|
|
79
|
+
await execute({
|
|
80
|
+
options: commandOptions.options,
|
|
81
|
+
args: commandArgs.args
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
if (commandOptions.restArgs.length > 0) {
|
|
85
|
+
if (self.subject?.type === "subCommand") return error.addUnknownSubCommandIssue(commandOptions.restArgs[0]);
|
|
86
|
+
return error.addTooMuchCommandArgumentIssue(0, commandOptions.restArgs.length);
|
|
87
|
+
}
|
|
88
|
+
await execute({ options: commandOptions.options });
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
[commandKind.runTimeKey]: null
|
|
92
|
+
};
|
|
93
|
+
return self;
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
export { create, isCommands };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_defaultInterpreter = require("../dataStructure/common/error/defaultInterpreter.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_pattern = require("@duplojs/lang/pattern");
|
|
6
|
+
_duplojs_lang_pattern = require_runtime.__toESM(_duplojs_lang_pattern, 1);
|
|
7
|
+
let _duplojs_lang_dataStructure = require("@duplojs/lang/dataStructure");
|
|
8
|
+
_duplojs_lang_dataStructure = require_runtime.__toESM(_duplojs_lang_dataStructure, 1);
|
|
9
|
+
let _duplojs_lang_array = require("@duplojs/lang/array");
|
|
10
|
+
_duplojs_lang_array = require_runtime.__toESM(_duplojs_lang_array, 1);
|
|
11
|
+
let _duplojs_lang_string = require("@duplojs/lang/string");
|
|
12
|
+
_duplojs_lang_string = require_runtime.__toESM(_duplojs_lang_string, 1);
|
|
13
|
+
let _duplojs_lang_printer = require("@duplojs/lang/printer");
|
|
14
|
+
_duplojs_lang_printer = require_runtime.__toESM(_duplojs_lang_printer, 1);
|
|
15
|
+
let _duplojs_lang_modeling = require("@duplojs/lang/modeling");
|
|
16
|
+
_duplojs_lang_modeling = require_runtime.__toESM(_duplojs_lang_modeling, 1);
|
|
17
|
+
//#region scripts/command/error.ts
|
|
18
|
+
const SymbolCommandError = Symbol.for("SymbolCommandError");
|
|
19
|
+
function createError(commandName) {
|
|
20
|
+
const issues = [];
|
|
21
|
+
const currentPath = [commandName];
|
|
22
|
+
return {
|
|
23
|
+
issues,
|
|
24
|
+
currentPath,
|
|
25
|
+
pushPath: (path) => void currentPath.push(path),
|
|
26
|
+
addUnknownOptionIssue: (optionTokens) => {
|
|
27
|
+
issues.push(_duplojs_lang_modeling.taggedObject("UnknownOptionIssue", {
|
|
28
|
+
optionTokens,
|
|
29
|
+
path: _duplojs_lang_string.join(currentPath, ".")
|
|
30
|
+
}));
|
|
31
|
+
return SymbolCommandError;
|
|
32
|
+
},
|
|
33
|
+
addUnknownSubCommandIssue: (subCommandName) => {
|
|
34
|
+
issues.push(_duplojs_lang_modeling.taggedObject("UnknownSubCommandIssue", {
|
|
35
|
+
subCommandName,
|
|
36
|
+
path: _duplojs_lang_string.join(currentPath, ".")
|
|
37
|
+
}));
|
|
38
|
+
return SymbolCommandError;
|
|
39
|
+
},
|
|
40
|
+
addRequiredOptionIssue: (optionName) => {
|
|
41
|
+
issues.push(_duplojs_lang_modeling.taggedObject("RequiredOptionIssue", {
|
|
42
|
+
optionName,
|
|
43
|
+
data: void 0,
|
|
44
|
+
path: currentPath.join(".")
|
|
45
|
+
}));
|
|
46
|
+
return SymbolCommandError;
|
|
47
|
+
},
|
|
48
|
+
addRequiredOptionValueIssue: (optionName) => {
|
|
49
|
+
issues.push(_duplojs_lang_modeling.taggedObject("RequiredOptionValueIssue", {
|
|
50
|
+
optionName,
|
|
51
|
+
data: void 0,
|
|
52
|
+
path: currentPath.join(".")
|
|
53
|
+
}));
|
|
54
|
+
return SymbolCommandError;
|
|
55
|
+
},
|
|
56
|
+
addUnexpectedOptionValueIssue: (optionName, data) => {
|
|
57
|
+
issues.push(_duplojs_lang_modeling.taggedObject("UnexpectedOptionValueIssue", {
|
|
58
|
+
optionName,
|
|
59
|
+
data,
|
|
60
|
+
path: currentPath.join(".")
|
|
61
|
+
}));
|
|
62
|
+
return SymbolCommandError;
|
|
63
|
+
},
|
|
64
|
+
addDataStructureOptionIssue: (optionName, data, dataStructureError) => {
|
|
65
|
+
issues.push(_duplojs_lang_modeling.taggedObject("DataStructureOptionIssue", {
|
|
66
|
+
optionName,
|
|
67
|
+
data,
|
|
68
|
+
dataStructureError,
|
|
69
|
+
path: currentPath.join(".")
|
|
70
|
+
}));
|
|
71
|
+
return SymbolCommandError;
|
|
72
|
+
},
|
|
73
|
+
addRequiredArgumentIssue: (argumentName) => {
|
|
74
|
+
issues.push(_duplojs_lang_modeling.taggedObject("RequiredArgumentIssue", {
|
|
75
|
+
argumentName,
|
|
76
|
+
data: void 0,
|
|
77
|
+
path: currentPath.join(".")
|
|
78
|
+
}));
|
|
79
|
+
return SymbolCommandError;
|
|
80
|
+
},
|
|
81
|
+
addDataStructureArgumentIssue: (argumentName, data, dataStructureError) => {
|
|
82
|
+
issues.push(_duplojs_lang_modeling.taggedObject("DataStructureArgumentIssue", {
|
|
83
|
+
argumentName,
|
|
84
|
+
data,
|
|
85
|
+
dataStructureError,
|
|
86
|
+
path: currentPath.join(".")
|
|
87
|
+
}));
|
|
88
|
+
return SymbolCommandError;
|
|
89
|
+
},
|
|
90
|
+
addTooMuchCommandArgumentIssue: (expect, receive) => {
|
|
91
|
+
issues.push(_duplojs_lang_modeling.taggedObject("TooMuchCommandArgumentIssue", {
|
|
92
|
+
expect,
|
|
93
|
+
receive,
|
|
94
|
+
path: currentPath.join(".")
|
|
95
|
+
}));
|
|
96
|
+
return SymbolCommandError;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function interpretDataStructureError(error, dataStructureErrorInterpreter) {
|
|
101
|
+
return _duplojs_lang_common.pipe(dataStructureErrorInterpreter(error), _duplojs_lang_array.map(({ interpretedMessage, path }) => _duplojs_lang_printer.renderLine([
|
|
102
|
+
"↳ ",
|
|
103
|
+
_duplojs_lang_printer.colorizedBold(path || "<value>", "cyan"),
|
|
104
|
+
" : ",
|
|
105
|
+
_duplojs_lang_printer.colorizedBold(interpretedMessage.subSource ?? interpretedMessage.interpretedSubSource ?? interpretedMessage.source ?? interpretedMessage.interpretedSource ?? "unknown data structure error.", "red")
|
|
106
|
+
], {
|
|
107
|
+
joinCharacter: "",
|
|
108
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
109
|
+
indentLevel: 1
|
|
110
|
+
})));
|
|
111
|
+
}
|
|
112
|
+
function interpretErrorIssues(issues, dataStructureErrorInterpreter) {
|
|
113
|
+
return _duplojs_lang_printer.renderParagraph([_duplojs_lang_array.map(issues, _duplojs_lang_pattern.matchWithTaggedObject({
|
|
114
|
+
UnknownOptionIssue: ({ optionTokens }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("OPTION: ", "blue"), _duplojs_lang_string.join(optionTokens, ", ")], {
|
|
115
|
+
joinCharacter: "",
|
|
116
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
117
|
+
indentLevel: 1
|
|
118
|
+
}), _duplojs_lang_printer.renderLine(["↳ Unknown Option"], {
|
|
119
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
120
|
+
indentLevel: 1
|
|
121
|
+
})],
|
|
122
|
+
UnknownSubCommandIssue: ({ subCommandName }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("SUB-COMMAND: ", "cyan"), subCommandName], {
|
|
123
|
+
joinCharacter: "",
|
|
124
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
125
|
+
indentLevel: 1
|
|
126
|
+
}), _duplojs_lang_printer.renderLine(["↳ Unknown Sub-command"], {
|
|
127
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
128
|
+
indentLevel: 1
|
|
129
|
+
})],
|
|
130
|
+
DataStructureArgumentIssue: ({ argumentName, dataStructureError }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("ARGUMENT: ", "magenta"), `--${argumentName}`], {
|
|
131
|
+
joinCharacter: "",
|
|
132
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
133
|
+
indentLevel: 1
|
|
134
|
+
}), interpretDataStructureError(dataStructureError, dataStructureErrorInterpreter)],
|
|
135
|
+
RequiredArgumentIssue: ({ argumentName }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("ARGUMENT: ", "magenta"), argumentName], {
|
|
136
|
+
joinCharacter: "",
|
|
137
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
138
|
+
indentLevel: 1
|
|
139
|
+
}), _duplojs_lang_printer.renderLine(["↳ Missing Argument"], {
|
|
140
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
141
|
+
indentLevel: 1
|
|
142
|
+
})],
|
|
143
|
+
DataStructureOptionIssue: ({ optionName, dataStructureError }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("OPTION: ", "blue"), `--${optionName}`], {
|
|
144
|
+
joinCharacter: "",
|
|
145
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
146
|
+
indentLevel: 1
|
|
147
|
+
}), interpretDataStructureError(dataStructureError, dataStructureErrorInterpreter)],
|
|
148
|
+
RequiredOptionIssue: ({ optionName }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("OPTION: ", "blue"), `--${optionName}`], {
|
|
149
|
+
joinCharacter: "",
|
|
150
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
151
|
+
indentLevel: 1
|
|
152
|
+
}), _duplojs_lang_printer.renderLine(["↳ Missing Option"], {
|
|
153
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
154
|
+
indentLevel: 1
|
|
155
|
+
})],
|
|
156
|
+
RequiredOptionValueIssue: ({ optionName }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("OPTION: ", "blue"), `--${optionName}`], {
|
|
157
|
+
joinCharacter: "",
|
|
158
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
159
|
+
indentLevel: 1
|
|
160
|
+
}), _duplojs_lang_printer.renderLine(["↳ Missing Option Value"], {
|
|
161
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
162
|
+
indentLevel: 1
|
|
163
|
+
})],
|
|
164
|
+
UnexpectedOptionValueIssue: ({ optionName }) => [_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("OPTION: ", "blue"), `--${optionName}`], {
|
|
165
|
+
joinCharacter: "",
|
|
166
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
167
|
+
indentLevel: 1
|
|
168
|
+
}), _duplojs_lang_printer.renderLine(["↳ Unexpected Value At This Option"], {
|
|
169
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
170
|
+
indentLevel: 1
|
|
171
|
+
})],
|
|
172
|
+
TooMuchCommandArgumentIssue: ({ expect, receive }) => [_duplojs_lang_printer.renderLine([" Too Much Arguments"], {
|
|
173
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
174
|
+
indentLevel: 1
|
|
175
|
+
}), _duplojs_lang_printer.renderLine([` expect: ${expect} receive: ${receive}`], {
|
|
176
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
177
|
+
indentLevel: 1
|
|
178
|
+
})]
|
|
179
|
+
})), issues.length === 0 && "No issue found"]);
|
|
180
|
+
}
|
|
181
|
+
const defaultDataStructureErrorInterpreter = _duplojs_lang_dataStructure.createErrorInterpreter(require_defaultInterpreter.defaultErrorInterpreterDataStructureDictionary, require_defaultInterpreter.defaultErrorInterpreterCodecDictionary);
|
|
182
|
+
function interpretExecCommandError(error, dataStructureErrorInterpreter) {
|
|
183
|
+
return _duplojs_lang_printer.renderParagraph([
|
|
184
|
+
_duplojs_lang_printer.colorizedBold("Command failed", "red"),
|
|
185
|
+
_duplojs_lang_printer.renderLine([_duplojs_lang_printer.colorizedBold("COMMAND: ", "cyan"), _duplojs_lang_string.join(error.currentPath, " ")], {
|
|
186
|
+
joinCharacter: "",
|
|
187
|
+
indent: _duplojs_lang_printer.Indent.tab,
|
|
188
|
+
indentLevel: 1
|
|
189
|
+
}),
|
|
190
|
+
interpretErrorIssues(error.issues, dataStructureErrorInterpreter ?? defaultDataStructureErrorInterpreter)
|
|
191
|
+
]);
|
|
192
|
+
}
|
|
193
|
+
function interpretExecOptionsError(error, dataStructureErrorInterpreter) {
|
|
194
|
+
return _duplojs_lang_printer.renderParagraph([
|
|
195
|
+
_duplojs_lang_printer.colorizedBold("Invalid options", "red"),
|
|
196
|
+
["", ""],
|
|
197
|
+
interpretErrorIssues(error.issues, dataStructureErrorInterpreter ?? defaultDataStructureErrorInterpreter)
|
|
198
|
+
]);
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
exports.SymbolCommandError = SymbolCommandError;
|
|
202
|
+
exports.createError = createError;
|
|
203
|
+
exports.interpretDataStructureError = interpretDataStructureError;
|
|
204
|
+
exports.interpretErrorIssues = interpretErrorIssues;
|
|
205
|
+
exports.interpretExecCommandError = interpretExecCommandError;
|
|
206
|
+
exports.interpretExecOptionsError = interpretExecOptionsError;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as DModeling from "@duplojs/lang/modeling";
|
|
2
|
+
import * as DDataStructure from "@duplojs/lang/dataStructure";
|
|
3
|
+
export interface OptionIssueBase {
|
|
4
|
+
readonly data: unknown;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly optionName: string;
|
|
7
|
+
}
|
|
8
|
+
export interface RequiredOptionIssue extends OptionIssueBase, DModeling.ObjectTag<"RequiredOptionIssue"> {
|
|
9
|
+
}
|
|
10
|
+
export interface RequiredOptionValueIssue extends OptionIssueBase, DModeling.ObjectTag<"RequiredOptionValueIssue"> {
|
|
11
|
+
}
|
|
12
|
+
export interface UnexpectedOptionValueIssue extends OptionIssueBase, DModeling.ObjectTag<"UnexpectedOptionValueIssue"> {
|
|
13
|
+
}
|
|
14
|
+
export interface DataStructureOptionIssue extends OptionIssueBase, DModeling.ObjectTag<"DataStructureOptionIssue"> {
|
|
15
|
+
readonly dataStructureError: DDataStructure.Error;
|
|
16
|
+
}
|
|
17
|
+
export interface ArgumentIssueBase {
|
|
18
|
+
readonly data: unknown;
|
|
19
|
+
readonly path: string;
|
|
20
|
+
readonly argumentName: string;
|
|
21
|
+
}
|
|
22
|
+
export interface RequiredArgumentIssue extends ArgumentIssueBase, DModeling.ObjectTag<"RequiredArgumentIssue"> {
|
|
23
|
+
}
|
|
24
|
+
export interface DataStructureArgumentIssue extends ArgumentIssueBase, DModeling.ObjectTag<"DataStructureArgumentIssue"> {
|
|
25
|
+
readonly dataStructureError: DDataStructure.Error;
|
|
26
|
+
}
|
|
27
|
+
export interface CommandArgumentIssueBase {
|
|
28
|
+
readonly path: string;
|
|
29
|
+
}
|
|
30
|
+
export interface UnknownOptionIssue extends CommandArgumentIssueBase, DModeling.ObjectTag<"UnknownOptionIssue"> {
|
|
31
|
+
readonly optionTokens: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
export interface UnknownSubCommandIssue extends CommandArgumentIssueBase, DModeling.ObjectTag<"UnknownSubCommandIssue"> {
|
|
34
|
+
readonly subCommandName: string;
|
|
35
|
+
}
|
|
36
|
+
export interface TooMuchCommandArgumentIssue extends CommandArgumentIssueBase, DModeling.ObjectTag<"TooMuchCommandArgumentIssue"> {
|
|
37
|
+
readonly expect: number;
|
|
38
|
+
readonly receive: number;
|
|
39
|
+
}
|
|
40
|
+
export type Issues = (RequiredOptionIssue | RequiredOptionValueIssue | UnexpectedOptionValueIssue | DataStructureOptionIssue | RequiredArgumentIssue | DataStructureArgumentIssue | TooMuchCommandArgumentIssue | UnknownOptionIssue | UnknownSubCommandIssue);
|
|
41
|
+
export declare const SymbolCommandError: unique symbol;
|
|
42
|
+
export type SymbolCommandError = typeof SymbolCommandError;
|
|
43
|
+
export interface Error {
|
|
44
|
+
readonly issues: readonly Issues[];
|
|
45
|
+
readonly currentPath: readonly string[];
|
|
46
|
+
pushPath(path: string): void;
|
|
47
|
+
addUnknownOptionIssue(optionTokens: readonly string[]): SymbolCommandError;
|
|
48
|
+
addUnknownSubCommandIssue(subCommandName: string): SymbolCommandError;
|
|
49
|
+
addRequiredOptionIssue(optionName: string): SymbolCommandError;
|
|
50
|
+
addRequiredOptionValueIssue(optionName: string): SymbolCommandError;
|
|
51
|
+
addUnexpectedOptionValueIssue(optionName: string, data: unknown): SymbolCommandError;
|
|
52
|
+
addDataStructureOptionIssue(optionName: string, data: unknown, dataStructureError: DDataStructure.Error): SymbolCommandError;
|
|
53
|
+
addRequiredArgumentIssue(argumentName: string): SymbolCommandError;
|
|
54
|
+
addDataStructureArgumentIssue(argumentName: string, data: unknown, dataStructureError: DDataStructure.Error): SymbolCommandError;
|
|
55
|
+
addTooMuchCommandArgumentIssue(expect: number, receive: number): SymbolCommandError;
|
|
56
|
+
}
|
|
57
|
+
export declare function createError(commandName: string): Error;
|
|
58
|
+
export declare function interpretDataStructureError(error: DDataStructure.Error, dataStructureErrorInterpreter: DDataStructure.ErrorInterpreter): readonly string[];
|
|
59
|
+
export declare function interpretErrorIssues(issues: readonly Issues[], dataStructureErrorInterpreter: DDataStructure.ErrorInterpreter): string;
|
|
60
|
+
export declare function interpretExecCommandError(error: Error, dataStructureErrorInterpreter?: DDataStructure.ErrorInterpreter): string;
|
|
61
|
+
export declare function interpretExecOptionsError(error: Error, dataStructureErrorInterpreter?: DDataStructure.ErrorInterpreter): string;
|