@shell-shock/core 0.17.10 → 0.17.12
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/api.cjs +31 -143
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.cts +2 -77
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +2 -76
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +30 -140
- package/dist/api.mjs.map +1 -1
- package/dist/components/command-validation-logic.cjs +14 -15
- package/dist/components/command-validation-logic.cjs.map +1 -0
- package/dist/components/command-validation-logic.d.cts +1 -3
- package/dist/components/command-validation-logic.d.cts.map +1 -1
- package/dist/components/command-validation-logic.d.mts +1 -3
- package/dist/components/command-validation-logic.d.mts.map +1 -1
- package/dist/components/command-validation-logic.mjs +12 -13
- package/dist/components/command-validation-logic.mjs.map +1 -1
- package/dist/components/docs.cjs +6 -6
- package/dist/components/docs.cjs.map +1 -0
- package/dist/components/docs.d.cts +4 -5
- package/dist/components/docs.d.cts.map +1 -1
- package/dist/components/docs.d.mts +4 -5
- package/dist/components/docs.d.mts.map +1 -1
- package/dist/components/docs.mjs +4 -4
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/exec-builtin.cjs +9 -11
- package/dist/components/exec-builtin.cjs.map +1 -0
- package/dist/components/exec-builtin.d.cts +1 -2
- package/dist/components/exec-builtin.d.cts.map +1 -1
- package/dist/components/exec-builtin.d.mts +1 -2
- package/dist/components/exec-builtin.d.mts.map +1 -1
- package/dist/components/exec-builtin.mjs +7 -10
- package/dist/components/exec-builtin.mjs.map +1 -1
- package/dist/components/helpers.cjs +4 -5
- package/dist/components/helpers.cjs.map +1 -0
- package/dist/components/helpers.d.cts +6 -8
- package/dist/components/helpers.d.cts.map +1 -1
- package/dist/components/helpers.d.mts +6 -8
- package/dist/components/helpers.d.mts.map +1 -1
- package/dist/components/helpers.mjs +2 -3
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/options-parser-logic.cjs +29 -30
- package/dist/components/options-parser-logic.cjs.map +1 -0
- package/dist/components/options-parser-logic.d.cts +8 -9
- package/dist/components/options-parser-logic.d.cts.map +1 -1
- package/dist/components/options-parser-logic.d.mts +8 -9
- package/dist/components/options-parser-logic.d.mts.map +1 -1
- package/dist/components/options-parser-logic.mjs +27 -28
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/state-builtin.cjs +3 -2
- package/dist/components/state-builtin.cjs.map +1 -0
- package/dist/components/state-builtin.d.cts +4 -5
- package/dist/components/state-builtin.d.cts.map +1 -1
- package/dist/components/state-builtin.d.mts +4 -5
- package/dist/components/state-builtin.d.mts.map +1 -1
- package/dist/components/state-builtin.mjs +1 -1
- package/dist/components/state-builtin.mjs.map +1 -1
- package/dist/components/usage.cjs +4 -6
- package/dist/components/usage.cjs.map +1 -0
- package/dist/components/usage.d.cts +1 -2
- package/dist/components/usage.d.cts.map +1 -1
- package/dist/components/usage.d.mts +1 -2
- package/dist/components/usage.d.mts.map +1 -1
- package/dist/components/usage.mjs +2 -4
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +5 -4
- package/dist/components/utils-builtin.cjs.map +1 -0
- package/dist/components/utils-builtin.d.cts +7 -8
- package/dist/components/utils-builtin.d.cts.map +1 -1
- package/dist/components/utils-builtin.d.mts +7 -8
- package/dist/components/utils-builtin.d.mts.map +1 -1
- package/dist/components/utils-builtin.mjs +3 -3
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs +53 -19
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +29 -8
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +29 -8
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +51 -18
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/command.cjs +2 -2
- package/dist/contexts/command.cjs.map +1 -0
- package/dist/contexts/command.d.cts.map +1 -1
- package/dist/contexts/command.d.mts.map +1 -1
- package/dist/contexts/command.mjs.map +1 -1
- package/dist/contexts/options.cjs +4 -4
- package/dist/contexts/options.cjs.map +1 -0
- package/dist/contexts/options.d.cts.map +1 -1
- package/dist/contexts/options.d.mts.map +1 -1
- package/dist/contexts/options.mjs +2 -3
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/engine.cjs +138 -0
- package/dist/engine.cjs.map +1 -0
- package/dist/engine.d.cts +79 -0
- package/dist/engine.d.cts.map +1 -0
- package/dist/engine.d.mts +79 -0
- package/dist/engine.d.mts.map +1 -0
- package/dist/engine.mjs +136 -0
- package/dist/engine.mjs.map +1 -0
- package/dist/helpers/automd.cjs +6 -7
- package/dist/helpers/automd.cjs.map +1 -0
- package/dist/helpers/automd.mjs +2 -3
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/helpers/docs-helpers.cjs +2 -2
- package/dist/helpers/docs-helpers.cjs.map +1 -0
- package/dist/helpers/docs-helpers.mjs.map +1 -1
- package/dist/helpers/get-framework.cjs +24 -0
- package/dist/helpers/get-framework.cjs.map +1 -0
- package/dist/helpers/get-framework.mjs +24 -0
- package/dist/helpers/get-framework.mjs.map +1 -0
- package/dist/helpers/paths.cjs +5 -5
- package/dist/helpers/paths.cjs.map +1 -0
- package/dist/helpers/paths.mjs +4 -4
- package/dist/helpers/paths.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +4 -6
- package/dist/helpers/persistence.cjs.map +1 -0
- package/dist/helpers/persistence.mjs +3 -3
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +2 -2
- package/dist/helpers/update-package-json.cjs.map +1 -0
- package/dist/helpers/update-package-json.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +3 -3
- package/dist/helpers/utilities.cjs.map +1 -0
- package/dist/helpers/utilities.mjs +1 -1
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/helpers/validations.cjs +3 -3
- package/dist/helpers/validations.cjs.map +1 -0
- package/dist/helpers/validations.mjs +1 -3
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +121 -51
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +80 -5
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +80 -5
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +118 -6
- package/dist/index.mjs.map +1 -0
- package/dist/package.cjs +12 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.mjs +6 -0
- package/dist/package.mjs.map +1 -0
- package/dist/plugin-utils/compute-bin.cjs +8 -10
- package/dist/plugin-utils/compute-bin.cjs.map +1 -0
- package/dist/plugin-utils/compute-bin.d.cts +2 -2
- package/dist/plugin-utils/compute-bin.d.cts.map +1 -1
- package/dist/plugin-utils/compute-bin.d.mts +2 -2
- package/dist/plugin-utils/compute-bin.d.mts.map +1 -1
- package/dist/plugin-utils/compute-bin.mjs +6 -8
- package/dist/plugin-utils/compute-bin.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +7 -14
- package/dist/plugin-utils/context-helpers.cjs.map +1 -0
- package/dist/plugin-utils/context-helpers.d.cts +4 -4
- package/dist/plugin-utils/context-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/context-helpers.d.mts +4 -4
- package/dist/plugin-utils/context-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/context-helpers.mjs +5 -12
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/deepkit.cjs +15 -16
- package/dist/plugin-utils/deepkit.cjs.map +1 -0
- package/dist/plugin-utils/deepkit.d.cts +5 -5
- package/dist/plugin-utils/deepkit.d.cts.map +1 -1
- package/dist/plugin-utils/deepkit.d.mts +5 -5
- package/dist/plugin-utils/deepkit.d.mts.map +1 -1
- package/dist/plugin-utils/deepkit.mjs +14 -15
- package/dist/plugin-utils/deepkit.mjs.map +1 -1
- package/dist/plugin-utils/description-helpers.cjs +2 -1
- package/dist/plugin-utils/description-helpers.cjs.map +1 -0
- package/dist/plugin-utils/description-helpers.d.cts.map +1 -1
- package/dist/plugin-utils/description-helpers.d.mts.map +1 -1
- package/dist/plugin-utils/description-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +2 -1
- package/dist/plugin-utils/get-command-tree.cjs.map +1 -0
- package/dist/plugin-utils/get-command-tree.d.cts.map +1 -1
- package/dist/plugin-utils/get-command-tree.d.mts.map +1 -1
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +1 -1
- package/dist/plugin-utils/index.d.cts +2 -2
- package/dist/plugin-utils/index.d.mts +2 -2
- package/dist/plugin-utils/index.mjs +2 -2
- package/dist/plugin-utils/reflect.cjs +5 -5
- package/dist/plugin-utils/reflect.cjs.map +1 -0
- package/dist/plugin-utils/reflect.d.cts.map +1 -1
- package/dist/plugin-utils/reflect.d.mts.map +1 -1
- package/dist/plugin-utils/reflect.mjs +3 -5
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.cjs +2 -1
- package/dist/plugin-utils/traverse-command-tree.cjs.map +1 -0
- package/dist/plugin-utils/traverse-command-tree.d.cts.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.d.mts.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/type-checks.cjs +146 -17
- package/dist/plugin-utils/type-checks.cjs.map +1 -0
- package/dist/plugin-utils/type-checks.d.cts +5 -5
- package/dist/plugin-utils/type-checks.d.cts.map +1 -1
- package/dist/plugin-utils/type-checks.d.mts +5 -5
- package/dist/plugin-utils/type-checks.d.mts.map +1 -1
- package/dist/plugin-utils/type-checks.mjs +145 -16
- package/dist/plugin-utils/type-checks.mjs.map +1 -1
- package/dist/plugin.cjs +80 -56
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +75 -52
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/helpers.cjs +33 -24
- package/dist/resolver/helpers.cjs.map +1 -0
- package/dist/resolver/helpers.mjs +32 -22
- package/dist/resolver/helpers.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +319 -61
- package/dist/resolver/resolve.cjs.map +1 -0
- package/dist/resolver/resolve.mjs +316 -58
- package/dist/resolver/resolve.mjs.map +1 -1
- package/dist/types/command.cjs +43 -82
- package/dist/types/command.cjs.map +1 -0
- package/dist/types/command.d.cts +61 -119
- package/dist/types/command.d.cts.map +1 -1
- package/dist/types/command.d.mts +61 -119
- package/dist/types/command.d.mts.map +1 -1
- package/dist/types/command.mjs +42 -80
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +45 -4
- package/dist/types/config.cjs.map +1 -0
- package/dist/types/config.d.cts +16 -11
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +16 -11
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +40 -4
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/context.cjs +9 -1
- package/dist/types/context.cjs.map +1 -0
- package/dist/types/context.d.cts +3 -2
- package/dist/types/context.d.cts.map +1 -1
- package/dist/types/context.d.mts +3 -2
- package/dist/types/context.d.mts.map +1 -1
- package/dist/types/context.mjs +7 -1
- package/dist/types/context.mjs.map +1 -1
- package/dist/types/env.cjs +2 -1
- package/dist/types/env.cjs.map +1 -0
- package/dist/types/env.d.cts.map +1 -1
- package/dist/types/env.d.mts.map +1 -1
- package/dist/types/env.mjs.map +1 -1
- package/dist/types/index.cjs +6 -3
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.mts +4 -4
- package/dist/types/index.mjs +4 -4
- package/dist/types/options.cjs +2 -1
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.d.cts.map +1 -1
- package/dist/types/options.d.mts.map +1 -1
- package/dist/types/options.mjs.map +1 -1
- package/package.json +43 -35
- package/dist/resolver/deepkit.cjs +0 -135
- package/dist/resolver/deepkit.mjs +0 -135
- package/dist/resolver/deepkit.mjs.map +0 -1
- package/dist/resolver/module.cjs +0 -145
- package/dist/resolver/module.mjs +0 -145
- package/dist/resolver/module.mjs.map +0 -1
package/dist/resolver/module.mjs
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { CommandParameterKinds } from "../types/command.mjs";
|
|
2
|
-
import { isCommandParameterConfig } from "../plugin-utils/type-checks.mjs";
|
|
3
|
-
import "../plugin-utils/index.mjs";
|
|
4
|
-
import { toArray } from "@stryke/convert/to-array";
|
|
5
|
-
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
6
|
-
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
7
|
-
import { getUnique } from "@stryke/helpers/get-unique";
|
|
8
|
-
import { isJsonSchema7ArrayType, isJsonSchema7BooleanType, isJsonSchema7NumberType, isJsonSchema7ObjectType, isJsonSchema7StringType, isJsonSchema7TupleType, isStandardJsonSchema } from "@stryke/json";
|
|
9
|
-
import { extractJsonSchema7, isZod3Type } from "@stryke/zod";
|
|
10
|
-
|
|
11
|
-
//#region src/resolver/module.ts
|
|
12
|
-
const __ΩPartial = [
|
|
13
|
-
"T",
|
|
14
|
-
"Partial",
|
|
15
|
-
"l+e#!e\"!fRb!Pde\"!gN#\"w\"y"
|
|
16
|
-
];
|
|
17
|
-
function __assignType(fn, args) {
|
|
18
|
-
fn.__type = args;
|
|
19
|
-
return fn;
|
|
20
|
-
}
|
|
21
|
-
function resolveCommandOption(name, parent, schema) {
|
|
22
|
-
const result = {
|
|
23
|
-
name,
|
|
24
|
-
kind: isJsonSchema7ArrayType(schema) && schema.items ? isJsonSchema7NumberType(schema.items) ? CommandParameterKinds.number : CommandParameterKinds.string : isJsonSchema7BooleanType(schema) ? CommandParameterKinds.boolean : isJsonSchema7NumberType(schema) ? CommandParameterKinds.number : CommandParameterKinds.string,
|
|
25
|
-
title: schema.title,
|
|
26
|
-
description: schema.description,
|
|
27
|
-
alias: toArray(schema.alias || []),
|
|
28
|
-
env: schema.env,
|
|
29
|
-
optional: !parent.required?.includes(name),
|
|
30
|
-
default: schema.default
|
|
31
|
-
};
|
|
32
|
-
if (result.kind === CommandParameterKinds.string || result.kind === CommandParameterKinds.number) {
|
|
33
|
-
result.variadic = isJsonSchema7ArrayType(schema);
|
|
34
|
-
if (result.kind === CommandParameterKinds.string) result.format = schema.format;
|
|
35
|
-
if ((isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) && schema.enum) result.choices = schema.enum;
|
|
36
|
-
} else if (result.kind === CommandParameterKinds.boolean && !result.variadic) {
|
|
37
|
-
result.skipAddingNegative = schema.skipAddingNegative;
|
|
38
|
-
result.isNegativeOf = schema.isNegativeOf;
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
resolveCommandOption.__type = [
|
|
43
|
-
"name",
|
|
44
|
-
"parent",
|
|
45
|
-
"schema",
|
|
46
|
-
() => __ΩPartial,
|
|
47
|
-
"CommandOption",
|
|
48
|
-
"resolveCommandOption",
|
|
49
|
-
"P&2!!2\"!2#\"w%o$\"/&"
|
|
50
|
-
];
|
|
51
|
-
function resolveCommandArgument(schema) {
|
|
52
|
-
const result = {
|
|
53
|
-
name: schema.name,
|
|
54
|
-
kind: isJsonSchema7ArrayType(schema) && schema.items ? isJsonSchema7NumberType(schema.items) ? CommandParameterKinds.number : CommandParameterKinds.string : isJsonSchema7BooleanType(schema) ? CommandParameterKinds.boolean : isJsonSchema7NumberType(schema) ? CommandParameterKinds.number : CommandParameterKinds.string,
|
|
55
|
-
title: schema.title,
|
|
56
|
-
description: schema.description,
|
|
57
|
-
alias: toArray(schema.alias || []),
|
|
58
|
-
env: schema.env,
|
|
59
|
-
default: schema.default
|
|
60
|
-
};
|
|
61
|
-
if (result.kind === CommandParameterKinds.string || result.kind === CommandParameterKinds.number) {
|
|
62
|
-
result.variadic = isJsonSchema7ArrayType(schema);
|
|
63
|
-
if (result.kind === CommandParameterKinds.string) result.format = schema.format;
|
|
64
|
-
if ((isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) && schema.enum) result.choices = schema.enum;
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
resolveCommandArgument.__type = [
|
|
69
|
-
"schema",
|
|
70
|
-
() => __ΩPartial,
|
|
71
|
-
"CommandArgument",
|
|
72
|
-
"resolveCommandArgument",
|
|
73
|
-
"P!2!\"w#o\"\"/$"
|
|
74
|
-
];
|
|
75
|
-
async function resolveFromExports(ctx) {
|
|
76
|
-
validateExports(ctx);
|
|
77
|
-
const metadata = ctx.module?.metadata ?? {};
|
|
78
|
-
if (isSetString(metadata.title)) ctx.output.title = metadata.title;
|
|
79
|
-
if (isSetString(metadata.description)) ctx.output.description = metadata.description;
|
|
80
|
-
if (isSetString(metadata.alias) || Array.isArray(metadata.alias) && metadata.alias.length > 0) ctx.output.alias = toArray(metadata.alias);
|
|
81
|
-
if (isSetString(metadata.icon)) ctx.output.icon = metadata.icon;
|
|
82
|
-
if (isSetString(metadata.tags)) ctx.output.tags = getUnique(ctx.output.tags.concat(toArray(metadata.tags)));
|
|
83
|
-
if (isSetObject(ctx.module?.options)) if (isZod3Type(ctx.module.options) || isStandardJsonSchema(ctx.module.options) || isJsonSchema7ObjectType(ctx.module.options)) {
|
|
84
|
-
let jsonSchema;
|
|
85
|
-
if (isZod3Type(ctx.module.options)) jsonSchema = extractJsonSchema7(ctx.module.options);
|
|
86
|
-
else if (isStandardJsonSchema(ctx.module.options)) jsonSchema = ctx.module.options["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
87
|
-
else jsonSchema = ctx.module.options;
|
|
88
|
-
if (!isJsonSchema7ObjectType(jsonSchema)) throw new TypeError(`Command options for command at path "${ctx.input.command.path}" must be defined as a Zod object schema, a standard JSON Schema object, or a JSON Schema object.`);
|
|
89
|
-
ctx.output.options = Object.fromEntries(Object.entries(jsonSchema.properties).map(__assignType(([name, property]) => [name, resolveCommandOption(name, jsonSchema, property)], [
|
|
90
|
-
"param0",
|
|
91
|
-
"",
|
|
92
|
-
"P\"2!\"/\""
|
|
93
|
-
])).concat(Object.entries(ctx.output.options)));
|
|
94
|
-
} else if (Object.values(ctx.module.options).every(isCommandParameterConfig)) ctx.output.options = Object.fromEntries(Object.entries(ctx.module.options).map(__assignType(([name, option]) => [name, {
|
|
95
|
-
name,
|
|
96
|
-
...option,
|
|
97
|
-
alias: toArray(option.alias)
|
|
98
|
-
}], [
|
|
99
|
-
"param0",
|
|
100
|
-
"",
|
|
101
|
-
"P\"2!\"/\""
|
|
102
|
-
])).concat(Object.entries(ctx.output.options)));
|
|
103
|
-
else throw new TypeError(`Command options for command at path "${ctx.input.command.path}" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`);
|
|
104
|
-
if (isSetObject(ctx.module?.args)) if (isZod3Type(ctx.module.args) || isStandardJsonSchema(ctx.module.args) || isJsonSchema7TupleType(ctx.module.args)) {
|
|
105
|
-
let jsonSchema;
|
|
106
|
-
if (isZod3Type(ctx.module.args)) jsonSchema = extractJsonSchema7(ctx.module.args);
|
|
107
|
-
else if (isStandardJsonSchema(ctx.module.args)) jsonSchema = ctx.module.args["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
108
|
-
else jsonSchema = ctx.module.args;
|
|
109
|
-
if (!isJsonSchema7TupleType(jsonSchema)) throw new TypeError(`Command arguments for command at path "${ctx.input.command.path}" must be defined as a Zod tuple schema, a standard JSON Schema tuple object, or a JSON Schema tuple object.`);
|
|
110
|
-
ctx.output.args = jsonSchema.items.map(__assignType((item) => resolveCommandArgument(item), [
|
|
111
|
-
"item",
|
|
112
|
-
"",
|
|
113
|
-
"P\"2!\"/\""
|
|
114
|
-
]));
|
|
115
|
-
} else if (Object.values(ctx.module.args).every(isCommandParameterConfig)) ctx.output.args = ctx.module.args.map(__assignType((arg) => ({
|
|
116
|
-
...arg,
|
|
117
|
-
alias: toArray(arg.alias)
|
|
118
|
-
}), [
|
|
119
|
-
"arg",
|
|
120
|
-
"",
|
|
121
|
-
"P\"2!\"/\""
|
|
122
|
-
]));
|
|
123
|
-
else throw new TypeError(`Command arguments for command at path "${ctx.input.command.path}" must be defined as a record of valid CommandArgument objects, a Zod tuple schema, or a standard JSON Schema tuple object.`);
|
|
124
|
-
}
|
|
125
|
-
resolveFromExports.__type = [
|
|
126
|
-
"ResolverContext",
|
|
127
|
-
"ctx",
|
|
128
|
-
"resolveFromExports",
|
|
129
|
-
"P\"w!2\"\"/#"
|
|
130
|
-
];
|
|
131
|
-
function validateExports(ctx) {
|
|
132
|
-
if (!ctx.module) throw new Error(`Command module at path "${ctx.input.command.path}" is undefined or null. Please ensure the module exports a valid command.`);
|
|
133
|
-
else if (!isSetObject(ctx.module)) throw new TypeError(`Command module at path "${ctx.input.command.path}" is not an object. Please ensure the module exports a valid command.`);
|
|
134
|
-
else if (!("default" in ctx.module)) throw new Error(`Command module at path "${ctx.input.command.path}" does not appear to be valid. Please ensure the module's default export is a valid command handler function.`);
|
|
135
|
-
}
|
|
136
|
-
validateExports.__type = [
|
|
137
|
-
"ResolverContext",
|
|
138
|
-
"ctx",
|
|
139
|
-
"validateExports",
|
|
140
|
-
"P\"w!2\"\"/#"
|
|
141
|
-
];
|
|
142
|
-
|
|
143
|
-
//#endregion
|
|
144
|
-
export { resolveFromExports };
|
|
145
|
-
//# sourceMappingURL=module.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.mjs","names":[],"sources":["../../src/resolver/module.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 { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport type {\n JsonSchema7EnumType,\n JsonSchema7ObjectType,\n JsonSchema7Type\n} from \"@stryke/json\";\nimport {\n isJsonSchema7ArrayType,\n isJsonSchema7BooleanType,\n isJsonSchema7NumberType,\n isJsonSchema7ObjectType,\n isJsonSchema7StringType,\n isJsonSchema7TupleType,\n isStandardJsonSchema\n} from \"@stryke/json\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { extractJsonSchema7, isZod3Type } from \"@stryke/zod\";\nimport { isCommandParameterConfig } from \"../plugin-utils\";\nimport type {\n BooleanCommandOption,\n CommandArgument,\n CommandOption,\n CommandParameterConfig,\n Context,\n StringCommandParameter\n} from \"../types\";\nimport { CommandParameterKinds } from \"../types\";\nimport type { ResolverContext } from \"./types\";\n\nfunction resolveCommandOption(\n name: string,\n parent: JsonSchema7ObjectType,\n schema: JsonSchema7Type\n): Partial<CommandOption> {\n const result = {\n name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n optional: !parent.required?.includes(name),\n default: schema.default\n } as Partial<CommandOption>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n } else if (\n result.kind === CommandParameterKinds.boolean &&\n !result.variadic\n ) {\n (result as BooleanCommandOption).skipAddingNegative = (\n schema as { skipAddingNegative?: boolean }\n ).skipAddingNegative;\n (result as BooleanCommandOption).isNegativeOf = (\n schema as { isNegativeOf?: string }\n ).isNegativeOf;\n }\n\n return result;\n}\n\nfunction resolveCommandArgument(\n schema: JsonSchema7Type\n): Partial<CommandArgument> {\n const result = {\n name: (schema as { name?: string }).name,\n kind:\n isJsonSchema7ArrayType(schema) && schema.items\n ? isJsonSchema7NumberType(schema.items)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string\n : isJsonSchema7BooleanType(schema)\n ? CommandParameterKinds.boolean\n : isJsonSchema7NumberType(schema)\n ? CommandParameterKinds.number\n : CommandParameterKinds.string,\n title: schema.title,\n description: schema.description,\n alias: toArray((schema as { alias?: string | string[] }).alias || []),\n env: (schema as { env?: string }).env,\n default: schema.default\n } as Partial<CommandArgument>;\n if (\n result.kind === CommandParameterKinds.string ||\n result.kind === CommandParameterKinds.number\n ) {\n result.variadic = isJsonSchema7ArrayType(schema);\n if (result.kind === CommandParameterKinds.string) {\n result.format = (\n schema as { format?: StringCommandParameter[\"format\"] }\n ).format;\n }\n\n if (\n (isJsonSchema7StringType(schema) || isJsonSchema7NumberType(schema)) &&\n (schema as JsonSchema7EnumType).enum\n ) {\n result.choices = (schema as JsonSchema7EnumType).enum;\n }\n }\n\n return result;\n}\n\nexport async function resolveFromExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n validateExports(ctx);\n\n const metadata = ctx.module?.metadata ?? {};\n if (isSetString(metadata.title)) {\n ctx.output.title = metadata.title;\n }\n if (isSetString(metadata.description)) {\n ctx.output.description = metadata.description;\n }\n if (\n isSetString(metadata.alias) ||\n (Array.isArray(metadata.alias) && metadata.alias.length > 0)\n ) {\n ctx.output.alias = toArray(metadata.alias);\n }\n if (isSetString(metadata.icon)) {\n ctx.output.icon = metadata.icon;\n }\n if (isSetString(metadata.tags)) {\n ctx.output.tags = getUnique(ctx.output.tags.concat(toArray(metadata.tags)));\n }\n\n if (isSetObject(ctx.module?.options)) {\n if (\n isZod3Type(ctx.module.options) ||\n isStandardJsonSchema(ctx.module.options) ||\n isJsonSchema7ObjectType(ctx.module.options)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.options)) {\n jsonSchema = extractJsonSchema7(ctx.module.options);\n } else if (isStandardJsonSchema(ctx.module.options)) {\n jsonSchema = ctx.module.options[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.options;\n }\n\n if (!isJsonSchema7ObjectType(jsonSchema)) {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod object schema, a standard JSON Schema object, or a JSON Schema object.`\n );\n }\n\n ctx.output.options = Object.fromEntries(\n Object.entries(jsonSchema.properties)\n .map(([name, property]) => [\n name,\n resolveCommandOption(name, jsonSchema, property)\n ])\n .concat(Object.entries(ctx.output.options))\n ) as Record<string, CommandOption>;\n } else if (\n Object.values(ctx.module.options).every(isCommandParameterConfig)\n ) {\n ctx.output.options = Object.fromEntries(\n Object.entries(\n ctx.module.options as Record<string, CommandParameterConfig>\n )\n .map(([name, option]) => [\n name,\n { name, ...option, alias: toArray(option.alias) }\n ])\n .concat(Object.entries(ctx.output.options))\n ) as Record<string, CommandOption>;\n } else {\n throw new TypeError(\n `Command options for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandOption objects, a Zod object schema, or a standard JSON Schema object.`\n );\n }\n }\n\n if (isSetObject(ctx.module?.args)) {\n if (\n isZod3Type(ctx.module.args) ||\n isStandardJsonSchema(ctx.module.args) ||\n isJsonSchema7TupleType(ctx.module.args)\n ) {\n let jsonSchema: JsonSchema7Type;\n if (isZod3Type(ctx.module.args)) {\n jsonSchema = extractJsonSchema7(ctx.module.args);\n } else if (isStandardJsonSchema(ctx.module.args)) {\n jsonSchema = ctx.module.args[\"~standard\"].jsonSchema.input({\n target: \"draft-07\"\n });\n } else {\n jsonSchema = ctx.module.args;\n }\n\n if (!isJsonSchema7TupleType(jsonSchema)) {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a Zod tuple schema, a standard JSON Schema tuple object, or a JSON Schema tuple object.`\n );\n }\n\n ctx.output.args = jsonSchema.items.map(item =>\n resolveCommandArgument(item)\n ) as CommandArgument[];\n } else if (Object.values(ctx.module.args).every(isCommandParameterConfig)) {\n ctx.output.args = ctx.module.args.map(arg => ({\n ...arg,\n alias: toArray(arg.alias)\n })) as CommandArgument[];\n } else {\n throw new TypeError(\n `Command arguments for command at path \"${\n ctx.input.command.path\n }\" must be defined as a record of valid CommandArgument objects, a Zod tuple schema, or a standard JSON Schema tuple object.`\n );\n }\n }\n}\n\nfunction validateExports<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n) {\n if (!ctx.module) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" is undefined or null. Please ensure the module exports a valid command.`\n );\n } else if (!isSetObject(ctx.module)) {\n throw new TypeError(\n `Command module at path \"${\n ctx.input.command.path\n }\" is not an object. Please ensure the module exports a valid command.`\n );\n } else if (!(\"default\" in ctx.module)) {\n throw new Error(\n `Command module at path \"${\n ctx.input.command.path\n }\" does not appear to be valid. Please ensure the module's default export is a valid command handler function.`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,MAAM,aAAa;CAAC;CAAK;CAAW;CAA2B;;AAE7D,IAAG,SAAS;;;AA4Bd,SAAE,qBAAuB,MAAA,QAAA,QAAA;CACvB,MAAA,SAAA;EACA;EACA,MAAO,uBAAY,OAAA,IAAA,OAAA,QAAA,wBAAA,OAAA,MAAA,GAAA,sBAAA,SAAA,sBAAA,SAAA,yBAAA,OAAA,GAAA,sBAAA,UAAA,wBAAA,OAAA,GAAA,sBAAA,SAAA,sBAAA;EACrB,OAAS,OAAA;EACT,aAAS,OAAc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