@shell-shock/core 0.17.8 → 0.17.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/dist/_virtual/_rolldown/runtime.cjs +29 -1
- package/dist/api.cjs +148 -1
- package/dist/api.d.cts +6 -6
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +6 -6
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +145 -1
- package/dist/api.mjs.map +1 -1
- package/dist/components/command-validation-logic.cjs +292 -1
- package/dist/components/command-validation-logic.mjs +289 -1
- package/dist/components/command-validation-logic.mjs.map +1 -1
- package/dist/components/docs.cjs +265 -1
- package/dist/components/docs.mjs +256 -1
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/exec-builtin.cjs +429 -13
- package/dist/components/exec-builtin.mjs +425 -13
- package/dist/components/exec-builtin.mjs.map +1 -1
- package/dist/components/helpers.cjs +120 -1
- package/dist/components/helpers.mjs +112 -1
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +58 -1
- package/dist/components/index.mjs +10 -1
- package/dist/components/options-parser-logic.cjs +960 -5
- package/dist/components/options-parser-logic.d.cts +1 -1
- package/dist/components/options-parser-logic.mjs +945 -5
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/state-builtin.cjs +629 -8
- package/dist/components/state-builtin.mjs +622 -8
- package/dist/components/state-builtin.mjs.map +1 -1
- package/dist/components/usage.cjs +117 -1
- package/dist/components/usage.mjs +114 -1
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +838 -33
- package/dist/components/utils-builtin.mjs +828 -33
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs +31 -1
- package/dist/config.mjs +29 -1
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/command.cjs +26 -1
- package/dist/contexts/command.mjs +23 -1
- package/dist/contexts/command.mjs.map +1 -1
- package/dist/contexts/index.cjs +9 -1
- package/dist/contexts/index.mjs +4 -1
- package/dist/contexts/options.cjs +63 -1
- package/dist/contexts/options.mjs +58 -1
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/helpers/automd.cjs +71 -1
- package/dist/helpers/automd.mjs +70 -1
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/helpers/docs-helpers.cjs +23 -1
- package/dist/helpers/docs-helpers.mjs +22 -1
- package/dist/helpers/docs-helpers.mjs.map +1 -1
- package/dist/helpers/paths.cjs +137 -1
- package/dist/helpers/paths.mjs +133 -1
- package/dist/helpers/paths.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +115 -1
- package/dist/helpers/persistence.mjs +112 -1
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +65 -1
- package/dist/helpers/update-package-json.mjs +63 -1
- package/dist/helpers/update-package-json.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +95 -1
- package/dist/helpers/utilities.mjs +93 -1
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/helpers/validations.cjs +71 -1
- package/dist/helpers/validations.mjs +71 -1
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +53 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +7 -1
- package/dist/plugin-utils/compute-bin.cjs +50 -1
- package/dist/plugin-utils/compute-bin.mjs +49 -1
- package/dist/plugin-utils/compute-bin.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +231 -1
- package/dist/plugin-utils/context-helpers.mjs +221 -1
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/deepkit.cjs +71 -1
- package/dist/plugin-utils/deepkit.mjs +69 -1
- package/dist/plugin-utils/deepkit.mjs.map +1 -1
- package/dist/plugin-utils/description-helpers.cjs +111 -2
- package/dist/plugin-utils/description-helpers.mjs +107 -2
- package/dist/plugin-utils/description-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +117 -1
- package/dist/plugin-utils/get-command-tree.mjs +114 -1
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +39 -1
- package/dist/plugin-utils/index.mjs +10 -1
- package/dist/plugin-utils/reflect.cjs +52 -1
- package/dist/plugin-utils/reflect.mjs +52 -1
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.cjs +64 -1
- package/dist/plugin-utils/traverse-command-tree.mjs +62 -1
- package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/type-checks.cjs +93 -1
- package/dist/plugin-utils/type-checks.mjs +88 -1
- package/dist/plugin-utils/type-checks.mjs.map +1 -1
- package/dist/plugin.cjs +471 -4
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +465 -4
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/deepkit.cjs +135 -1
- package/dist/resolver/deepkit.mjs +134 -1
- package/dist/resolver/deepkit.mjs.map +1 -1
- package/dist/resolver/helpers.cjs +173 -1
- package/dist/resolver/helpers.mjs +168 -1
- package/dist/resolver/helpers.mjs.map +1 -1
- package/dist/resolver/module.cjs +145 -1
- package/dist/resolver/module.mjs +144 -1
- package/dist/resolver/module.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +222 -1
- package/dist/resolver/resolve.mjs +221 -1
- package/dist/resolver/resolve.mjs.map +1 -1
- package/dist/types/command.cjs +441 -1
- package/dist/types/command.d.cts +1 -1
- package/dist/types/command.d.mts +2 -2
- package/dist/types/command.mjs +405 -1
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +134 -1
- package/dist/types/config.d.cts +10 -8
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +10 -8
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +127 -1
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/context.cjs +37 -1
- package/dist/types/context.mjs +34 -1
- package/dist/types/context.mjs.map +1 -1
- package/dist/types/env.cjs +52 -1
- package/dist/types/env.d.cts +1 -1
- package/dist/types/env.d.mts +1 -1
- package/dist/types/env.mjs +50 -1
- package/dist/types/env.mjs.map +1 -1
- package/dist/types/index.cjs +50 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +6 -1
- package/dist/types/options.cjs +12 -1
- package/dist/types/options.mjs +10 -1
- package/package.json +22 -21
|
@@ -1 +1,135 @@
|
|
|
1
|
-
require(
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_types_command = require('../types/command.cjs');
|
|
3
|
+
const require_helpers = require('./helpers.cjs');
|
|
4
|
+
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
5
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
6
|
+
let _stryke_type_checks_is_bigint = require("@stryke/type-checks/is-bigint");
|
|
7
|
+
let _stryke_type_checks_is_number = require("@stryke/type-checks/is-number");
|
|
8
|
+
let _stryke_type_checks_is_regexp = require("@stryke/type-checks/is-regexp");
|
|
9
|
+
|
|
10
|
+
//#region src/resolver/deepkit.ts
|
|
11
|
+
function __assignType(fn, args) {
|
|
12
|
+
fn.__type = args;
|
|
13
|
+
return fn;
|
|
14
|
+
}
|
|
15
|
+
function extractCommandParameterKind(type) {
|
|
16
|
+
const isKind = !((0, _stryke_type_checks_is_set_object.isSetObject)(type) && "kind" in type);
|
|
17
|
+
const kind = !isKind ? type.kind : type;
|
|
18
|
+
if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.string) return require_types_command.CommandParameterKinds.string;
|
|
19
|
+
else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.number || kind === _powerlines_deepkit_vendor_type.ReflectionKind.bigint || !isKind && type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, _stryke_type_checks_is_number.isNumber)(type.literal) || (0, _stryke_type_checks_is_bigint.isBigInt)(type.literal))) return require_types_command.CommandParameterKinds.number;
|
|
20
|
+
else if (kind === _powerlines_deepkit_vendor_type.ReflectionKind.boolean) return require_types_command.CommandParameterKinds.boolean;
|
|
21
|
+
else return require_types_command.CommandParameterKinds.string;
|
|
22
|
+
}
|
|
23
|
+
extractCommandParameterKind.__type = [
|
|
24
|
+
"type",
|
|
25
|
+
"CommandParameterKind",
|
|
26
|
+
"extractCommandParameterKind",
|
|
27
|
+
"PP!!J2!\"w\"/#"
|
|
28
|
+
];
|
|
29
|
+
function resolveCommandOption(ctx, reflection) {
|
|
30
|
+
const type = reflection.getType();
|
|
31
|
+
const existing = ctx.output.options[reflection.getNameAsString()] ?? {};
|
|
32
|
+
const option = {
|
|
33
|
+
name: reflection.getNameAsString(),
|
|
34
|
+
alias: reflection.getTags().alias ?? [],
|
|
35
|
+
title: reflection.getTags().title?.trim(),
|
|
36
|
+
description: reflection.getDescription(),
|
|
37
|
+
kind: extractCommandParameterKind(type),
|
|
38
|
+
optional: reflection.isOptional(),
|
|
39
|
+
default: reflection.getDefaultValue(),
|
|
40
|
+
variadic: reflection.isArray()
|
|
41
|
+
};
|
|
42
|
+
if (option.variadic) option.kind = extractCommandParameterKind(type.type.kind);
|
|
43
|
+
else if (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.union) {
|
|
44
|
+
option.kind = type.types.every(__assignType((t) => t.kind === _powerlines_deepkit_vendor_type.ReflectionKind.number || t.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, _stryke_type_checks_is_number.isNumber)(t.literal) || (0, _stryke_type_checks_is_bigint.isBigInt)(t.literal)), [
|
|
45
|
+
"t",
|
|
46
|
+
"",
|
|
47
|
+
"P\"2!\"/\""
|
|
48
|
+
])) ? require_types_command.CommandParameterKinds.number : require_types_command.CommandParameterKinds.string;
|
|
49
|
+
option.choices = type.types.map(__assignType((t) => t.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal ? (0, _stryke_type_checks_is_number.isNumber)(t.literal) ? t.literal : (0, _stryke_type_checks_is_bigint.isBigInt)(t.literal) ? Number(t.literal) : (0, _stryke_type_checks_is_regexp.isRegExp)(t.literal) ? t.literal.source : String(t.literal) : null, [
|
|
50
|
+
"t",
|
|
51
|
+
"",
|
|
52
|
+
"P\"2!\"/\""
|
|
53
|
+
])).filter(Boolean);
|
|
54
|
+
} else if (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal) option.choices = [(0, _stryke_type_checks_is_number.isNumber)(type.literal) ? type.literal : (0, _stryke_type_checks_is_bigint.isBigInt)(type.literal) ? Number(type.literal) : (0, _stryke_type_checks_is_regexp.isRegExp)(type.literal) ? type.literal.source : String(type.literal)].filter(Boolean);
|
|
55
|
+
else if (!existing.kind && type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.boolean && type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${ctx.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${(0, _powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
56
|
+
return require_helpers.mergeCommandParameter(existing, option);
|
|
57
|
+
}
|
|
58
|
+
resolveCommandOption.__type = [
|
|
59
|
+
"ResolverContext",
|
|
60
|
+
"ctx",
|
|
61
|
+
"reflection",
|
|
62
|
+
"CommandOption",
|
|
63
|
+
"resolveCommandOption",
|
|
64
|
+
"P\"w!2\"!2#\"w$/%"
|
|
65
|
+
];
|
|
66
|
+
function resolveCommandArgument(ctx, index, reflection) {
|
|
67
|
+
const type = reflection.getType();
|
|
68
|
+
const existing = ctx.output.args.length > index ? ctx.output.args[index] : {};
|
|
69
|
+
const argument = {
|
|
70
|
+
name: reflection.getName() || reflection.parameter.name,
|
|
71
|
+
alias: reflection.getAlias(),
|
|
72
|
+
kind: extractCommandParameterKind(type.kind),
|
|
73
|
+
title: reflection.getTitle() || reflection.parameter.tags?.title,
|
|
74
|
+
description: reflection.parameter.description,
|
|
75
|
+
optional: reflection.isOptional(),
|
|
76
|
+
default: reflection.getDefaultValue() || reflection.parameter.default
|
|
77
|
+
};
|
|
78
|
+
if (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.array) if (type.type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.string || type.type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.number) {
|
|
79
|
+
argument.variadic = true;
|
|
80
|
+
argument.kind = extractCommandParameterKind(type.type.kind);
|
|
81
|
+
} else throw new Error(`Unsupported array type for positional argument "${argument.name}" in command "${ctx.input.command.name}". Only string[], number[], or literal[] are supported, received ${(0, _powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
82
|
+
else if (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.union) {
|
|
83
|
+
argument.kind = type.types.every(__assignType((t) => t.kind === _powerlines_deepkit_vendor_type.ReflectionKind.number || t.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal && ((0, _stryke_type_checks_is_number.isNumber)(t.literal) || (0, _stryke_type_checks_is_bigint.isBigInt)(t.literal)), [
|
|
84
|
+
"t",
|
|
85
|
+
"",
|
|
86
|
+
"P\"2!\"/\""
|
|
87
|
+
])) ? require_types_command.CommandParameterKinds.number : require_types_command.CommandParameterKinds.string;
|
|
88
|
+
argument.choices = type.types.map(__assignType((t) => t.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal ? (0, _stryke_type_checks_is_number.isNumber)(t.literal) ? t.literal : (0, _stryke_type_checks_is_bigint.isBigInt)(t.literal) ? Number(t.literal) : (0, _stryke_type_checks_is_regexp.isRegExp)(t.literal) ? t.literal.source : String(t.literal) : null, [
|
|
89
|
+
"t",
|
|
90
|
+
"",
|
|
91
|
+
"P\"2!\"/\""
|
|
92
|
+
])).filter(Boolean);
|
|
93
|
+
} else if (type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.literal) argument.choices = [(0, _stryke_type_checks_is_number.isNumber)(type.literal) ? type.literal : (0, _stryke_type_checks_is_bigint.isBigInt)(type.literal) ? Number(type.literal) : (0, _stryke_type_checks_is_regexp.isRegExp)(type.literal) ? type.literal.source : String(type.literal)].filter(Boolean);
|
|
94
|
+
else if (!ctx.output.args?.length && type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.boolean && type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.string && type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.number) throw new Error(`Unsupported type for positional argument "${argument.name}" in command "${ctx.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${(0, _powerlines_deepkit_vendor_type.stringifyType)(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
95
|
+
return require_helpers.mergeCommandParameter(existing, argument, { name: `arg${index}` });
|
|
96
|
+
}
|
|
97
|
+
resolveCommandArgument.__type = [
|
|
98
|
+
"ResolverContext",
|
|
99
|
+
"ctx",
|
|
100
|
+
"index",
|
|
101
|
+
"reflection",
|
|
102
|
+
"CommandArgument",
|
|
103
|
+
"resolveCommandArgument",
|
|
104
|
+
"P\"w!2\"'2#!2$\"w%/&"
|
|
105
|
+
];
|
|
106
|
+
function resolveFromBytecode(ctx) {
|
|
107
|
+
const { input, module } = ctx;
|
|
108
|
+
const type = (0, _powerlines_deepkit_vendor_type.reflect)(module);
|
|
109
|
+
if (type.kind !== _powerlines_deepkit_vendor_type.ReflectionKind.function) throw new Error(`The command entry file "${input.command.entry.input?.file || input.command.path}" does not export a valid function.`);
|
|
110
|
+
const reflection = new _powerlines_deepkit_vendor_type.ReflectionFunction(type);
|
|
111
|
+
ctx.output.description ??= ctx.input.command.description || reflection.getDescription() || type.description;
|
|
112
|
+
const parameters = reflection.getParameters();
|
|
113
|
+
if (parameters.length > 0) {
|
|
114
|
+
const hasOptions = parameters[0] && (parameters[0].type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.objectLiteral || parameters[0].type.kind === _powerlines_deepkit_vendor_type.ReflectionKind.class);
|
|
115
|
+
if (hasOptions) {
|
|
116
|
+
const optionsReflection = _powerlines_deepkit_vendor_type.ReflectionClass.from(parameters[0]?.type);
|
|
117
|
+
for (const propertyReflection of optionsReflection.getProperties()) ctx.output.options[propertyReflection.getNameAsString()] = resolveCommandOption(ctx, propertyReflection);
|
|
118
|
+
}
|
|
119
|
+
ctx.output.args = (hasOptions ? parameters.slice(1) : parameters).map(__assignType((arg, index) => resolveCommandArgument(ctx, index, arg), [
|
|
120
|
+
"arg",
|
|
121
|
+
"index",
|
|
122
|
+
"",
|
|
123
|
+
"P\"2!\"2\"\"/#"
|
|
124
|
+
]));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
resolveFromBytecode.__type = [
|
|
128
|
+
"ResolverContext",
|
|
129
|
+
"ctx",
|
|
130
|
+
"resolveFromBytecode",
|
|
131
|
+
"P\"w!2\"\"/#"
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
//#endregion
|
|
135
|
+
exports.resolveFromBytecode = resolveFromBytecode;
|
|
@@ -1,2 +1,135 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CommandParameterKinds } from "../types/command.mjs";
|
|
2
|
+
import { mergeCommandParameter } from "./helpers.mjs";
|
|
3
|
+
import { ReflectionClass, ReflectionFunction, ReflectionKind, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
|
|
4
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
5
|
+
import { isBigInt } from "@stryke/type-checks/is-bigint";
|
|
6
|
+
import { isNumber } from "@stryke/type-checks/is-number";
|
|
7
|
+
import { isRegExp } from "@stryke/type-checks/is-regexp";
|
|
8
|
+
|
|
9
|
+
//#region src/resolver/deepkit.ts
|
|
10
|
+
function __assignType(fn, args) {
|
|
11
|
+
fn.__type = args;
|
|
12
|
+
return fn;
|
|
13
|
+
}
|
|
14
|
+
function extractCommandParameterKind(type) {
|
|
15
|
+
const isKind = !(isSetObject(type) && "kind" in type);
|
|
16
|
+
const kind = !isKind ? type.kind : type;
|
|
17
|
+
if (kind === ReflectionKind.string) return CommandParameterKinds.string;
|
|
18
|
+
else if (kind === ReflectionKind.number || kind === ReflectionKind.bigint || !isKind && type.kind === ReflectionKind.literal && (isNumber(type.literal) || isBigInt(type.literal))) return CommandParameterKinds.number;
|
|
19
|
+
else if (kind === ReflectionKind.boolean) return CommandParameterKinds.boolean;
|
|
20
|
+
else return CommandParameterKinds.string;
|
|
21
|
+
}
|
|
22
|
+
extractCommandParameterKind.__type = [
|
|
23
|
+
"type",
|
|
24
|
+
"CommandParameterKind",
|
|
25
|
+
"extractCommandParameterKind",
|
|
26
|
+
"PP!!J2!\"w\"/#"
|
|
27
|
+
];
|
|
28
|
+
function resolveCommandOption(ctx, reflection) {
|
|
29
|
+
const type = reflection.getType();
|
|
30
|
+
const existing = ctx.output.options[reflection.getNameAsString()] ?? {};
|
|
31
|
+
const option = {
|
|
32
|
+
name: reflection.getNameAsString(),
|
|
33
|
+
alias: reflection.getTags().alias ?? [],
|
|
34
|
+
title: reflection.getTags().title?.trim(),
|
|
35
|
+
description: reflection.getDescription(),
|
|
36
|
+
kind: extractCommandParameterKind(type),
|
|
37
|
+
optional: reflection.isOptional(),
|
|
38
|
+
default: reflection.getDefaultValue(),
|
|
39
|
+
variadic: reflection.isArray()
|
|
40
|
+
};
|
|
41
|
+
if (option.variadic) option.kind = extractCommandParameterKind(type.type.kind);
|
|
42
|
+
else if (type.kind === ReflectionKind.union) {
|
|
43
|
+
option.kind = type.types.every(__assignType((t) => t.kind === ReflectionKind.number || t.kind === ReflectionKind.literal && (isNumber(t.literal) || isBigInt(t.literal)), [
|
|
44
|
+
"t",
|
|
45
|
+
"",
|
|
46
|
+
"P\"2!\"/\""
|
|
47
|
+
])) ? CommandParameterKinds.number : CommandParameterKinds.string;
|
|
48
|
+
option.choices = type.types.map(__assignType((t) => t.kind === ReflectionKind.literal ? isNumber(t.literal) ? t.literal : isBigInt(t.literal) ? Number(t.literal) : isRegExp(t.literal) ? t.literal.source : String(t.literal) : null, [
|
|
49
|
+
"t",
|
|
50
|
+
"",
|
|
51
|
+
"P\"2!\"/\""
|
|
52
|
+
])).filter(Boolean);
|
|
53
|
+
} else if (type.kind === ReflectionKind.literal) option.choices = [isNumber(type.literal) ? type.literal : isBigInt(type.literal) ? Number(type.literal) : isRegExp(type.literal) ? type.literal.source : String(type.literal)].filter(Boolean);
|
|
54
|
+
else if (!existing.kind && type.kind !== ReflectionKind.boolean && type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number) throw new Error(`Unsupported type for option "${reflection.getNameAsString()}" in command "${ctx.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
55
|
+
return mergeCommandParameter(existing, option);
|
|
56
|
+
}
|
|
57
|
+
resolveCommandOption.__type = [
|
|
58
|
+
"ResolverContext",
|
|
59
|
+
"ctx",
|
|
60
|
+
"reflection",
|
|
61
|
+
"CommandOption",
|
|
62
|
+
"resolveCommandOption",
|
|
63
|
+
"P\"w!2\"!2#\"w$/%"
|
|
64
|
+
];
|
|
65
|
+
function resolveCommandArgument(ctx, index, reflection) {
|
|
66
|
+
const type = reflection.getType();
|
|
67
|
+
const existing = ctx.output.args.length > index ? ctx.output.args[index] : {};
|
|
68
|
+
const argument = {
|
|
69
|
+
name: reflection.getName() || reflection.parameter.name,
|
|
70
|
+
alias: reflection.getAlias(),
|
|
71
|
+
kind: extractCommandParameterKind(type.kind),
|
|
72
|
+
title: reflection.getTitle() || reflection.parameter.tags?.title,
|
|
73
|
+
description: reflection.parameter.description,
|
|
74
|
+
optional: reflection.isOptional(),
|
|
75
|
+
default: reflection.getDefaultValue() || reflection.parameter.default
|
|
76
|
+
};
|
|
77
|
+
if (type.kind === ReflectionKind.array) if (type.type.kind === ReflectionKind.string || type.type.kind === ReflectionKind.number) {
|
|
78
|
+
argument.variadic = true;
|
|
79
|
+
argument.kind = extractCommandParameterKind(type.type.kind);
|
|
80
|
+
} else throw new Error(`Unsupported array type for positional argument "${argument.name}" in command "${ctx.input.command.name}". Only string[], number[], or literal[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
81
|
+
else if (type.kind === ReflectionKind.union) {
|
|
82
|
+
argument.kind = type.types.every(__assignType((t) => t.kind === ReflectionKind.number || t.kind === ReflectionKind.literal && (isNumber(t.literal) || isBigInt(t.literal)), [
|
|
83
|
+
"t",
|
|
84
|
+
"",
|
|
85
|
+
"P\"2!\"/\""
|
|
86
|
+
])) ? CommandParameterKinds.number : CommandParameterKinds.string;
|
|
87
|
+
argument.choices = type.types.map(__assignType((t) => t.kind === ReflectionKind.literal ? isNumber(t.literal) ? t.literal : isBigInt(t.literal) ? Number(t.literal) : isRegExp(t.literal) ? t.literal.source : String(t.literal) : null, [
|
|
88
|
+
"t",
|
|
89
|
+
"",
|
|
90
|
+
"P\"2!\"/\""
|
|
91
|
+
])).filter(Boolean);
|
|
92
|
+
} else if (type.kind === ReflectionKind.literal) argument.choices = [isNumber(type.literal) ? type.literal : isBigInt(type.literal) ? Number(type.literal) : isRegExp(type.literal) ? type.literal.source : String(type.literal)].filter(Boolean);
|
|
93
|
+
else if (!ctx.output.args?.length && type.kind !== ReflectionKind.boolean && type.kind !== ReflectionKind.string && type.kind !== ReflectionKind.number) throw new Error(`Unsupported type for positional argument "${argument.name}" in command "${ctx.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${stringifyType(type).trim().replaceAll(" | ", ", or ")}.`);
|
|
94
|
+
return mergeCommandParameter(existing, argument, { name: `arg${index}` });
|
|
95
|
+
}
|
|
96
|
+
resolveCommandArgument.__type = [
|
|
97
|
+
"ResolverContext",
|
|
98
|
+
"ctx",
|
|
99
|
+
"index",
|
|
100
|
+
"reflection",
|
|
101
|
+
"CommandArgument",
|
|
102
|
+
"resolveCommandArgument",
|
|
103
|
+
"P\"w!2\"'2#!2$\"w%/&"
|
|
104
|
+
];
|
|
105
|
+
function resolveFromBytecode(ctx) {
|
|
106
|
+
const { input, module } = ctx;
|
|
107
|
+
const type = reflect(module);
|
|
108
|
+
if (type.kind !== ReflectionKind.function) throw new Error(`The command entry file "${input.command.entry.input?.file || input.command.path}" does not export a valid function.`);
|
|
109
|
+
const reflection = new ReflectionFunction(type);
|
|
110
|
+
ctx.output.description ??= ctx.input.command.description || reflection.getDescription() || type.description;
|
|
111
|
+
const parameters = reflection.getParameters();
|
|
112
|
+
if (parameters.length > 0) {
|
|
113
|
+
const hasOptions = parameters[0] && (parameters[0].type.kind === ReflectionKind.objectLiteral || parameters[0].type.kind === ReflectionKind.class);
|
|
114
|
+
if (hasOptions) {
|
|
115
|
+
const optionsReflection = ReflectionClass.from(parameters[0]?.type);
|
|
116
|
+
for (const propertyReflection of optionsReflection.getProperties()) ctx.output.options[propertyReflection.getNameAsString()] = resolveCommandOption(ctx, propertyReflection);
|
|
117
|
+
}
|
|
118
|
+
ctx.output.args = (hasOptions ? parameters.slice(1) : parameters).map(__assignType((arg, index) => resolveCommandArgument(ctx, index, arg), [
|
|
119
|
+
"arg",
|
|
120
|
+
"index",
|
|
121
|
+
"",
|
|
122
|
+
"P\"2!\"2\"\"/#"
|
|
123
|
+
]));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
resolveFromBytecode.__type = [
|
|
127
|
+
"ResolverContext",
|
|
128
|
+
"ctx",
|
|
129
|
+
"resolveFromBytecode",
|
|
130
|
+
"P\"w!2\"\"/#"
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { resolveFromBytecode };
|
|
2
135
|
//# sourceMappingURL=deepkit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepkit.mjs","names":[],"sources":["../../src/resolver/deepkit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n Type,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isBigInt } from \"@stryke/type-checks/is-bigint\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind,\n Context,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport { mergeCommandParameter } from \"./helpers\";\nimport type { ResolverContext } from \"./types\";\n\nfunction extractCommandParameterKind(\n type: Type | ReflectionKind\n): CommandParameterKind {\n const isKind = !(isSetObject(type) && \"kind\" in type);\n const kind = !isKind ? type.kind : type;\n if (kind === ReflectionKind.string) {\n return CommandParameterKinds.string;\n } else if (\n kind === ReflectionKind.number ||\n kind === ReflectionKind.bigint ||\n (!isKind &&\n type.kind === ReflectionKind.literal &&\n (isNumber(type.literal) || isBigInt(type.literal)))\n ) {\n return CommandParameterKinds.number;\n } else if (kind === ReflectionKind.boolean) {\n return CommandParameterKinds.boolean;\n } else {\n return CommandParameterKinds.string;\n }\n}\n\nfunction resolveCommandOption(\n ctx: ResolverContext,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n const existing = (ctx.output.options[reflection.getNameAsString()] ??\n {}) as Partial<CommandOption>;\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title: reflection.getTags().title?.trim(),\n description: reflection.getDescription(),\n kind: extractCommandParameterKind(type),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray()\n };\n\n if (option.variadic) {\n option.kind = extractCommandParameterKind((type as TypeArray).type.kind);\n } else if (type.kind === ReflectionKind.union) {\n option.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (option as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (option as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[], number[], or literal[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, option) as CommandOption;\n}\n\nfunction resolveCommandArgument(\n ctx: ResolverContext,\n index: number,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n const existing = (\n ctx.output.args.length > index ? ctx.output.args[index] : {}\n ) as Partial<CommandArgument>;\n\n const argument = {\n name: reflection.getName() || reflection.parameter.name,\n alias: reflection.getAlias(),\n kind: extractCommandParameterKind(type.kind),\n title: reflection.getTitle() || reflection.parameter.tags?.title,\n description: reflection.parameter.description,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue() || reflection.parameter.default\n };\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (argument as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind(type.type.kind) as \"string\" | \"number\";\n } else {\n throw new Error(\n `Unsupported array type for positional argument \"${argument.name}\" in command \"${\n ctx.input.command.name\n }\". Only string[], number[], or literal[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (type.kind === ReflectionKind.union) {\n argument.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (argument as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (argument as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !ctx.output.args?.length &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for positional argument \"${argument.name}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[], number[], or literal[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, argument, {\n name: `arg${index}`\n }) as CommandArgument;\n}\n\nexport function resolveFromBytecode<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n const { input, module } = ctx;\n\n const type = reflect(module);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${\n input.command.entry.input?.file || input.command.path\n }\" does not export a valid function.`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n ctx.output.description ??= (ctx.input.command.description ||\n reflection.getDescription() ||\n type.description)!;\n\n const parameters = reflection.getParameters();\n if (parameters.length > 0) {\n const hasOptions =\n parameters[0] &&\n (parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class);\n if (hasOptions) {\n const optionsReflection = ReflectionClass.from(parameters[0]?.type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n ctx.output.options[propertyReflection.getNameAsString()] =\n resolveCommandOption(ctx, propertyReflection);\n }\n }\n\n ctx.output.args = (hasOptions ? parameters.slice(1) : parameters).map(\n (arg, index) => resolveCommandArgument(ctx, index, arg)\n );\n }\n}\n"],"mappings":"4eAAA,SAAS,EAAa,EAAI,EAAM,CAE9B,kBAAO,EAST,SAAC,EAAkC,EAAK,CACvC,IAAO,EAAS,EAAE,EAAQ,EAAQ,EAAA,SAAc,gBAS/C,OAPI,IAAQ,EAAa,OAAA,EAAA,OAEd,IAAS,EAAe,QAAU,IAAS,EAAc,QAAA,CAAA,GAAA,EAAA,OAAA,EAAA,UAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAAA,EAAA,OAE1D,IAAA,EAAA,QACV,EAAmB,QAEf,EAAA,OAGN,EAAO,OAAA,CAAA,OAAA,uBAAA,8BAAA,eAAA,CACP,SAAS,EAAA,EAAA,EAAA,CACP,IAAA,EAAA,EAAe,SAAA,CACf,EAAA,EAAkB,OAAA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EAAA,CAAA,GAAA,IAAA,GAAA,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,CAAA,CAAA,MAAA,QAAA,GAAA,aAAA,CAAA,CAAA,EAGpC,EAAgB,OAAW,CAAA,kBAAO,MAAA,sBAAA,YAAA"}
|
|
1
|
+
{"version":3,"file":"deepkit.mjs","names":[],"sources":["../../src/resolver/deepkit.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Shell Shock\n\n This code was released as part of the Shell Shock project. Shell Shock\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/shell-shock.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/shell-shock\n Documentation: https://docs.stormsoftware.com/projects/shell-shock\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type {\n ReflectionParameter,\n ReflectionProperty,\n Type,\n TypeArray\n} from \"@powerlines/deepkit/vendor/type\";\nimport {\n reflect,\n ReflectionClass,\n ReflectionFunction,\n ReflectionKind,\n stringifyType\n} from \"@powerlines/deepkit/vendor/type\";\nimport { isBigInt } from \"@stryke/type-checks/is-bigint\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport type {\n CommandArgument,\n CommandOption,\n CommandParameterKind,\n Context,\n NumberCommandParameter,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport { mergeCommandParameter } from \"./helpers\";\nimport type { ResolverContext } from \"./types\";\n\nfunction extractCommandParameterKind(\n type: Type | ReflectionKind\n): CommandParameterKind {\n const isKind = !(isSetObject(type) && \"kind\" in type);\n const kind = !isKind ? type.kind : type;\n if (kind === ReflectionKind.string) {\n return CommandParameterKinds.string;\n } else if (\n kind === ReflectionKind.number ||\n kind === ReflectionKind.bigint ||\n (!isKind &&\n type.kind === ReflectionKind.literal &&\n (isNumber(type.literal) || isBigInt(type.literal)))\n ) {\n return CommandParameterKinds.number;\n } else if (kind === ReflectionKind.boolean) {\n return CommandParameterKinds.boolean;\n } else {\n return CommandParameterKinds.string;\n }\n}\n\nfunction resolveCommandOption(\n ctx: ResolverContext,\n reflection: ReflectionProperty\n): CommandOption {\n const type = reflection.getType();\n const existing = (ctx.output.options[reflection.getNameAsString()] ??\n {}) as Partial<CommandOption>;\n\n const option = {\n name: reflection.getNameAsString(),\n alias: reflection.getTags().alias ?? [],\n title: reflection.getTags().title?.trim(),\n description: reflection.getDescription(),\n kind: extractCommandParameterKind(type),\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue(),\n variadic: reflection.isArray()\n };\n\n if (option.variadic) {\n option.kind = extractCommandParameterKind((type as TypeArray).type.kind);\n } else if (type.kind === ReflectionKind.union) {\n option.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (option as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (option as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !existing.kind &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for option \"${reflection.getNameAsString()}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[], number[], or literal[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, option) as CommandOption;\n}\n\nfunction resolveCommandArgument(\n ctx: ResolverContext,\n index: number,\n reflection: ReflectionParameter\n): CommandArgument {\n const type = reflection.getType();\n const existing = (\n ctx.output.args.length > index ? ctx.output.args[index] : {}\n ) as Partial<CommandArgument>;\n\n const argument = {\n name: reflection.getName() || reflection.parameter.name,\n alias: reflection.getAlias(),\n kind: extractCommandParameterKind(type.kind),\n title: reflection.getTitle() || reflection.parameter.tags?.title,\n description: reflection.parameter.description,\n optional: reflection.isOptional(),\n default: reflection.getDefaultValue() || reflection.parameter.default\n };\n\n if (type.kind === ReflectionKind.array) {\n if (\n type.type.kind === ReflectionKind.string ||\n type.type.kind === ReflectionKind.number\n ) {\n (argument as StringCommandParameter | NumberCommandParameter).variadic =\n true;\n (argument as StringCommandParameter | NumberCommandParameter).kind =\n extractCommandParameterKind(type.type.kind) as \"string\" | \"number\";\n } else {\n throw new Error(\n `Unsupported array type for positional argument \"${argument.name}\" in command \"${\n ctx.input.command.name\n }\". Only string[], number[], or literal[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n } else if (type.kind === ReflectionKind.union) {\n argument.kind = type.types.every(\n t =>\n t.kind === ReflectionKind.number ||\n (t.kind === ReflectionKind.literal &&\n (isNumber(t.literal) || isBigInt(t.literal)))\n )\n ? CommandParameterKinds.number\n : CommandParameterKinds.string;\n\n (argument as StringCommandParameter | NumberCommandParameter).choices =\n type.types\n .map(t =>\n t.kind === ReflectionKind.literal\n ? isNumber(t.literal)\n ? t.literal\n : isBigInt(t.literal)\n ? Number(t.literal)\n : isRegExp(t.literal)\n ? t.literal.source\n : String(t.literal)\n : null\n )\n .filter(Boolean) as string[] | number[];\n } else if (type.kind === ReflectionKind.literal) {\n (argument as StringCommandParameter | NumberCommandParameter).choices = [\n isNumber(type.literal)\n ? type.literal\n : isBigInt(type.literal)\n ? Number(type.literal)\n : isRegExp(type.literal)\n ? type.literal.source\n : String(type.literal)\n ].filter(Boolean) as string[] | number[];\n } else if (\n !ctx.output.args?.length &&\n type.kind !== ReflectionKind.boolean &&\n type.kind !== ReflectionKind.string &&\n type.kind !== ReflectionKind.number\n ) {\n throw new Error(\n `Unsupported type for positional argument \"${argument.name}\" in command \"${\n ctx.input.command.name\n }\". Only string, number, boolean, string[], number[], or literal[] are supported, received ${stringifyType(\n type\n )\n .trim()\n .replaceAll(\" | \", \", or \")}.`\n );\n }\n\n return mergeCommandParameter(existing, argument, {\n name: `arg${index}`\n }) as CommandArgument;\n}\n\nexport function resolveFromBytecode<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n const { input, module } = ctx;\n\n const type = reflect(module);\n if (type.kind !== ReflectionKind.function) {\n throw new Error(\n `The command entry file \"${\n input.command.entry.input?.file || input.command.path\n }\" does not export a valid function.`\n );\n }\n\n const reflection = new ReflectionFunction(type);\n\n ctx.output.description ??= (ctx.input.command.description ||\n reflection.getDescription() ||\n type.description)!;\n\n const parameters = reflection.getParameters();\n if (parameters.length > 0) {\n const hasOptions =\n parameters[0] &&\n (parameters[0].type.kind === ReflectionKind.objectLiteral ||\n parameters[0].type.kind === ReflectionKind.class);\n if (hasOptions) {\n const optionsReflection = ReflectionClass.from(parameters[0]?.type);\n for (const propertyReflection of optionsReflection.getProperties()) {\n ctx.output.options[propertyReflection.getNameAsString()] =\n resolveCommandOption(ctx, propertyReflection);\n }\n }\n\n ctx.output.args = (hasOptions ? parameters.slice(1) : parameters).map(\n (arg, index) => resolveCommandArgument(ctx, index, arg)\n );\n }\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE9B,QAAO;;AAST,SAAC,4BAAkC,MAAK;CACvC,MAAO,SAAS,EAAE,YAAQ,KAAQ,IAAA,UAAc;;AAEhD,KAAK,SAA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,KAAO,OAAG,QAAA,mBAAyB,iBAAuB,IAAC,qBAAQ,KAAA,mBAAA;;AAGpE,MAAI,OAAI,QAAS,aAAe,WAAA,MAAA,EAAA,GAAA,YAAA,IAAA,cAAA,KAAA,UAAA,uBAAA,KAAA,OAAA,IAAA,EAAA;GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;;AAGpC,oBAAgB,SAAW;CAAA;CAAO;CAAA;CAAA;CAAA"}
|
|
@@ -1 +1,173 @@
|
|
|
1
|
-
require(
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
3
|
+
const require_types_command = require('../types/command.cjs');
|
|
4
|
+
let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
5
|
+
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
6
|
+
let defu = require("defu");
|
|
7
|
+
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
8
|
+
let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
9
|
+
let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
10
|
+
|
|
11
|
+
//#region src/resolver/helpers.ts
|
|
12
|
+
function __assignType(fn, args) {
|
|
13
|
+
fn.__type = args;
|
|
14
|
+
return fn;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the description for a command option based on its reflection.
|
|
18
|
+
*
|
|
19
|
+
* @param name - The name of the command option.
|
|
20
|
+
* @param kind - The reflection kind of the command option.
|
|
21
|
+
* @param optional - Whether the command option is optional.
|
|
22
|
+
* @param variadic - Whether the command option is variadic (i.e., an array).
|
|
23
|
+
* @param title - The title of the command option, if any.
|
|
24
|
+
* @param defaultValue - The default value of the command option, if any.
|
|
25
|
+
* @returns The resolved description for the command option.
|
|
26
|
+
*/
|
|
27
|
+
function resolveCommandOptionDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
|
|
28
|
+
return `A${optional && !defaultValue ? "n optional" : ""} command-line ${kind === require_types_command.CommandParameterKinds.boolean ? "flag" : "option"} that allows the user to ${kind === require_types_command.CommandParameterKinds.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || (0, _stryke_string_format_title_case.titleCase)(name)} ${kind === require_types_command.CommandParameterKinds.boolean ? "indicator" : `${kind === require_types_command.CommandParameterKinds.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
29
|
+
}
|
|
30
|
+
resolveCommandOptionDescription.__type = [
|
|
31
|
+
"name",
|
|
32
|
+
"CommandParameterKind",
|
|
33
|
+
"kind",
|
|
34
|
+
"optional",
|
|
35
|
+
"variadic",
|
|
36
|
+
"title",
|
|
37
|
+
"defaultValue",
|
|
38
|
+
"resolveCommandOptionDescription",
|
|
39
|
+
"Resolves the description for a command option based on its reflection.",
|
|
40
|
+
"P&2!\"w\"2#\"2$\"2%&2&8\"2'8&/(?)"
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the description for a command argument based on its reflection.
|
|
44
|
+
*
|
|
45
|
+
* @param name - The name of the command argument.
|
|
46
|
+
* @param kind - The reflection kind of the command argument.
|
|
47
|
+
* @param optional - Whether the command argument is optional.
|
|
48
|
+
* @param variadic - Whether the command argument is variadic (i.e., an array).
|
|
49
|
+
* @param title - The title of the command argument, if any.
|
|
50
|
+
* @param defaultValue - The default value of the command argument, if any.
|
|
51
|
+
* @returns The resolved description for the command argument.
|
|
52
|
+
*/
|
|
53
|
+
function resolveCommandArgumentDescription(name, kind, optional = false, variadic = false, title, defaultValue) {
|
|
54
|
+
return `An${optional && !defaultValue ? " optional" : ""} argument that allows the user to ${kind === require_types_command.CommandParameterKinds.boolean ? "set the" : variadic ? "specify custom" : "specify a custom"} ${title?.trim() || (0, _stryke_string_format_title_case.titleCase)(name)} ${kind === require_types_command.CommandParameterKinds.boolean ? "indicator" : `${kind === require_types_command.CommandParameterKinds.number ? "numeric" : "string"} value${variadic ? "s" : ""}`}.`;
|
|
55
|
+
}
|
|
56
|
+
resolveCommandArgumentDescription.__type = [
|
|
57
|
+
"name",
|
|
58
|
+
"CommandParameterKind",
|
|
59
|
+
"kind",
|
|
60
|
+
"optional",
|
|
61
|
+
"variadic",
|
|
62
|
+
"title",
|
|
63
|
+
"defaultValue",
|
|
64
|
+
"resolveCommandArgumentDescription",
|
|
65
|
+
"Resolves the description for a command argument based on its reflection.",
|
|
66
|
+
"P&2!\"w\"2#\"2$\"2%&2&8\"2'8&/(?)"
|
|
67
|
+
];
|
|
68
|
+
function applyOptionsDefaults(ctx) {
|
|
69
|
+
return Object.fromEntries(Object.entries(ctx.output.options).map(__assignType(([key, option]) => {
|
|
70
|
+
const name = option.name || key;
|
|
71
|
+
const title = option.title || (0, _stryke_string_format_title_case.titleCase)(name);
|
|
72
|
+
return [key, {
|
|
73
|
+
...option,
|
|
74
|
+
name,
|
|
75
|
+
title,
|
|
76
|
+
description: option.description || resolveCommandOptionDescription(name, option.kind, option.optional, option.kind !== require_types_command.CommandParameterKinds.boolean && option.variadic, title, option.default),
|
|
77
|
+
env: option.env || option.env === false ? option.env : ctx.input.context.config.autoAssignEnv ? (0, _stryke_string_format_constant_case.constantCase)(name) : false
|
|
78
|
+
}];
|
|
79
|
+
}, [
|
|
80
|
+
"param0",
|
|
81
|
+
"",
|
|
82
|
+
"P\"2!\"/\""
|
|
83
|
+
])));
|
|
84
|
+
}
|
|
85
|
+
applyOptionsDefaults.__type = [
|
|
86
|
+
"ResolverContext",
|
|
87
|
+
"ctx",
|
|
88
|
+
"applyOptionsDefaults",
|
|
89
|
+
"P\"w!2\"\"/#"
|
|
90
|
+
];
|
|
91
|
+
function applyArgsDefaults(ctx) {
|
|
92
|
+
return ctx.output.args.map(__assignType((arg, i) => {
|
|
93
|
+
const name = arg.name || `arg${i + 1}`;
|
|
94
|
+
const title = arg.title || (0, _stryke_string_format_title_case.titleCase)(name);
|
|
95
|
+
return {
|
|
96
|
+
...arg,
|
|
97
|
+
name,
|
|
98
|
+
title,
|
|
99
|
+
description: arg.description || resolveCommandArgumentDescription(name, arg.kind, arg.optional, arg.kind !== require_types_command.CommandParameterKinds.boolean && arg.variadic, title, arg.default),
|
|
100
|
+
env: arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? (0, _stryke_string_format_constant_case.constantCase)(name) : false : false
|
|
101
|
+
};
|
|
102
|
+
}, [
|
|
103
|
+
"arg",
|
|
104
|
+
"i",
|
|
105
|
+
"",
|
|
106
|
+
"P\"2!\"2\"\"/#"
|
|
107
|
+
]));
|
|
108
|
+
}
|
|
109
|
+
applyArgsDefaults.__type = [
|
|
110
|
+
"ResolverContext",
|
|
111
|
+
"ctx",
|
|
112
|
+
"CommandArgument",
|
|
113
|
+
"applyArgsDefaults",
|
|
114
|
+
"P\"w!2\"\"w#F/$"
|
|
115
|
+
];
|
|
116
|
+
function applyDefaults(ctx) {
|
|
117
|
+
ctx.output.description ??= `The ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim()} executable command-line interface.`;
|
|
118
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(ctx.input.context.config.reference?.commands) && ctx.input.context.config.reference.commands.includes("{command}")) ctx.output.reference ??= ctx.input.context.config.reference.commands ? ctx.input.context.config.reference.commands.replace("{command}", ctx.input.command.segments.filter(__assignType((segment) => !require_context_helpers.isDynamicPathSegment(segment), [
|
|
119
|
+
"segment",
|
|
120
|
+
"",
|
|
121
|
+
"P\"2!\"/\""
|
|
122
|
+
])).join("/")) : void 0;
|
|
123
|
+
}
|
|
124
|
+
applyDefaults.__type = [
|
|
125
|
+
"ResolverContext",
|
|
126
|
+
"ctx",
|
|
127
|
+
"applyDefaults",
|
|
128
|
+
"P\"w!2\"\"/#"
|
|
129
|
+
];
|
|
130
|
+
function resolveVirtualCommand(ctx) {
|
|
131
|
+
ctx.output.title ??= (0, _stryke_string_format_title_case.titleCase)(ctx.input.command.name);
|
|
132
|
+
ctx.output.description ??= `A collection of available ${ctx.output.title.replace(/(?:c|C)ommands?$/, "").trim() || (0, _stryke_string_format_title_case.titleCase)(ctx.input.command.name)} commands that are included in the ${require_context_helpers.getAppTitle(ctx.input.context, true)} command-line application.`;
|
|
133
|
+
}
|
|
134
|
+
resolveVirtualCommand.__type = [
|
|
135
|
+
"ResolverContext",
|
|
136
|
+
"ctx",
|
|
137
|
+
"resolveVirtualCommand",
|
|
138
|
+
"P\"w!2\"\"/#"
|
|
139
|
+
];
|
|
140
|
+
/**
|
|
141
|
+
* Merges two command parameters, giving precedence to string values in the second configuration.
|
|
142
|
+
*
|
|
143
|
+
* @param objA - The first command parameter object.
|
|
144
|
+
* @param objB - The second command parameter object.
|
|
145
|
+
* @returns The merged command parameter object.
|
|
146
|
+
*/
|
|
147
|
+
const mergeCommandParameter = (0, defu.createDefu)(__assignType((obj, key, value) => {
|
|
148
|
+
if ((0, _stryke_type_checks_is_string.isString)(obj[key]) && (0, _stryke_type_checks_is_string.isString)(value)) {
|
|
149
|
+
if ((0, _stryke_type_checks_is_set_string.isSetString)(value)) obj[key] = value;
|
|
150
|
+
return true;
|
|
151
|
+
} else if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
152
|
+
if (value.length > 0) obj[key] = (0, _stryke_helpers_get_unique.getUniqueBy)(obj[key].concat(value), __assignType((item) => (0, _stryke_type_checks_is_string.isString)(item) ? item : JSON.stringify(item), [
|
|
153
|
+
"item",
|
|
154
|
+
"",
|
|
155
|
+
"P\"2!\"/\""
|
|
156
|
+
]));
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
return false;
|
|
160
|
+
}, [
|
|
161
|
+
"obj",
|
|
162
|
+
"key",
|
|
163
|
+
"value",
|
|
164
|
+
"",
|
|
165
|
+
"P\"2!\"2\"\"2#\"/$"
|
|
166
|
+
]));
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
exports.applyArgsDefaults = applyArgsDefaults;
|
|
170
|
+
exports.applyDefaults = applyDefaults;
|
|
171
|
+
exports.applyOptionsDefaults = applyOptionsDefaults;
|
|
172
|
+
exports.mergeCommandParameter = mergeCommandParameter;
|
|
173
|
+
exports.resolveVirtualCommand = resolveVirtualCommand;
|