@shell-shock/core 0.17.7 → 0.17.8

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.
Files changed (145) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +1 -29
  2. package/dist/api.cjs +1 -95
  3. package/dist/api.d.cts +52 -4
  4. package/dist/api.d.cts.map +1 -1
  5. package/dist/api.d.mts +52 -4
  6. package/dist/api.d.mts.map +1 -1
  7. package/dist/api.mjs +1 -92
  8. package/dist/api.mjs.map +1 -1
  9. package/dist/components/command-validation-logic.cjs +1 -292
  10. package/dist/components/command-validation-logic.mjs +1 -289
  11. package/dist/components/command-validation-logic.mjs.map +1 -1
  12. package/dist/components/docs.cjs +1 -265
  13. package/dist/components/docs.d.cts.map +1 -1
  14. package/dist/components/docs.d.mts.map +1 -1
  15. package/dist/components/docs.mjs +1 -256
  16. package/dist/components/docs.mjs.map +1 -1
  17. package/dist/components/exec-builtin.cjs +13 -429
  18. package/dist/components/exec-builtin.mjs +13 -425
  19. package/dist/components/exec-builtin.mjs.map +1 -1
  20. package/dist/components/helpers.cjs +1 -120
  21. package/dist/components/helpers.mjs +1 -112
  22. package/dist/components/helpers.mjs.map +1 -1
  23. package/dist/components/index.cjs +1 -58
  24. package/dist/components/index.mjs +1 -10
  25. package/dist/components/options-parser-logic.cjs +5 -960
  26. package/dist/components/options-parser-logic.d.cts +1 -1
  27. package/dist/components/options-parser-logic.mjs +5 -945
  28. package/dist/components/options-parser-logic.mjs.map +1 -1
  29. package/dist/components/state-builtin.cjs +8 -629
  30. package/dist/components/state-builtin.d.cts.map +1 -1
  31. package/dist/components/state-builtin.d.mts.map +1 -1
  32. package/dist/components/state-builtin.mjs +8 -622
  33. package/dist/components/state-builtin.mjs.map +1 -1
  34. package/dist/components/usage.cjs +1 -117
  35. package/dist/components/usage.mjs +1 -114
  36. package/dist/components/usage.mjs.map +1 -1
  37. package/dist/components/utils-builtin.cjs +33 -838
  38. package/dist/components/utils-builtin.d.cts.map +1 -1
  39. package/dist/components/utils-builtin.d.mts.map +1 -1
  40. package/dist/components/utils-builtin.mjs +33 -828
  41. package/dist/components/utils-builtin.mjs.map +1 -1
  42. package/dist/config.cjs +1 -31
  43. package/dist/config.mjs +1 -29
  44. package/dist/config.mjs.map +1 -1
  45. package/dist/contexts/command.cjs +1 -26
  46. package/dist/contexts/command.mjs +1 -23
  47. package/dist/contexts/command.mjs.map +1 -1
  48. package/dist/contexts/index.cjs +1 -9
  49. package/dist/contexts/index.mjs +1 -4
  50. package/dist/contexts/options.cjs +1 -63
  51. package/dist/contexts/options.mjs +1 -58
  52. package/dist/contexts/options.mjs.map +1 -1
  53. package/dist/helpers/automd.cjs +1 -71
  54. package/dist/helpers/automd.mjs +1 -70
  55. package/dist/helpers/automd.mjs.map +1 -1
  56. package/dist/helpers/docs-helpers.cjs +1 -23
  57. package/dist/helpers/docs-helpers.mjs +1 -22
  58. package/dist/helpers/docs-helpers.mjs.map +1 -1
  59. package/dist/helpers/paths.cjs +1 -137
  60. package/dist/helpers/paths.mjs +1 -133
  61. package/dist/helpers/paths.mjs.map +1 -1
  62. package/dist/helpers/persistence.cjs +1 -113
  63. package/dist/helpers/persistence.mjs +1 -110
  64. package/dist/helpers/persistence.mjs.map +1 -1
  65. package/dist/helpers/update-package-json.cjs +1 -59
  66. package/dist/helpers/update-package-json.mjs +1 -57
  67. package/dist/helpers/update-package-json.mjs.map +1 -1
  68. package/dist/helpers/utilities.cjs +1 -95
  69. package/dist/helpers/utilities.mjs +1 -93
  70. package/dist/helpers/utilities.mjs.map +1 -1
  71. package/dist/helpers/validations.cjs +1 -71
  72. package/dist/helpers/validations.mjs +1 -71
  73. package/dist/helpers/validations.mjs.map +1 -1
  74. package/dist/index.cjs +1 -52
  75. package/dist/index.d.cts +1 -1
  76. package/dist/index.d.mts +1 -1
  77. package/dist/index.mjs +1 -7
  78. package/dist/plugin-utils/compute-bin.cjs +1 -50
  79. package/dist/plugin-utils/compute-bin.mjs +1 -49
  80. package/dist/plugin-utils/compute-bin.mjs.map +1 -1
  81. package/dist/plugin-utils/context-helpers.cjs +1 -231
  82. package/dist/plugin-utils/context-helpers.mjs +1 -221
  83. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  84. package/dist/plugin-utils/deepkit.cjs +1 -71
  85. package/dist/plugin-utils/deepkit.mjs +1 -69
  86. package/dist/plugin-utils/deepkit.mjs.map +1 -1
  87. package/dist/plugin-utils/description-helpers.cjs +2 -111
  88. package/dist/plugin-utils/description-helpers.mjs +2 -107
  89. package/dist/plugin-utils/description-helpers.mjs.map +1 -1
  90. package/dist/plugin-utils/get-command-tree.cjs +1 -117
  91. package/dist/plugin-utils/get-command-tree.mjs +1 -114
  92. package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
  93. package/dist/plugin-utils/index.cjs +1 -39
  94. package/dist/plugin-utils/index.mjs +1 -10
  95. package/dist/plugin-utils/reflect.cjs +1 -52
  96. package/dist/plugin-utils/reflect.mjs +1 -52
  97. package/dist/plugin-utils/reflect.mjs.map +1 -1
  98. package/dist/plugin-utils/traverse-command-tree.cjs +1 -64
  99. package/dist/plugin-utils/traverse-command-tree.mjs +1 -62
  100. package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
  101. package/dist/plugin-utils/type-checks.cjs +1 -93
  102. package/dist/plugin-utils/type-checks.mjs +1 -88
  103. package/dist/plugin-utils/type-checks.mjs.map +1 -1
  104. package/dist/plugin.cjs +4 -429
  105. package/dist/plugin.d.cts.map +1 -1
  106. package/dist/plugin.d.mts.map +1 -1
  107. package/dist/plugin.mjs +4 -423
  108. package/dist/plugin.mjs.map +1 -1
  109. package/dist/resolver/deepkit.cjs +1 -135
  110. package/dist/resolver/deepkit.mjs +1 -134
  111. package/dist/resolver/deepkit.mjs.map +1 -1
  112. package/dist/resolver/helpers.cjs +1 -173
  113. package/dist/resolver/helpers.mjs +1 -168
  114. package/dist/resolver/helpers.mjs.map +1 -1
  115. package/dist/resolver/module.cjs +1 -145
  116. package/dist/resolver/module.mjs +1 -144
  117. package/dist/resolver/module.mjs.map +1 -1
  118. package/dist/resolver/resolve.cjs +1 -222
  119. package/dist/resolver/resolve.mjs +1 -221
  120. package/dist/resolver/resolve.mjs.map +1 -1
  121. package/dist/types/command.cjs +1 -441
  122. package/dist/types/command.mjs +1 -405
  123. package/dist/types/command.mjs.map +1 -1
  124. package/dist/types/config.cjs +1 -144
  125. package/dist/types/config.d.cts +3 -2
  126. package/dist/types/config.d.cts.map +1 -1
  127. package/dist/types/config.d.mts +3 -2
  128. package/dist/types/config.d.mts.map +1 -1
  129. package/dist/types/config.mjs +1 -138
  130. package/dist/types/config.mjs.map +1 -1
  131. package/dist/types/context.cjs +1 -37
  132. package/dist/types/context.d.cts +3 -2
  133. package/dist/types/context.d.cts.map +1 -1
  134. package/dist/types/context.d.mts +3 -2
  135. package/dist/types/context.d.mts.map +1 -1
  136. package/dist/types/context.mjs +1 -34
  137. package/dist/types/context.mjs.map +1 -1
  138. package/dist/types/env.cjs +1 -52
  139. package/dist/types/env.mjs +1 -50
  140. package/dist/types/env.mjs.map +1 -1
  141. package/dist/types/index.cjs +1 -49
  142. package/dist/types/index.mjs +1 -6
  143. package/dist/types/options.cjs +1 -12
  144. package/dist/types/options.mjs +1 -10
  145. package/package.json +23 -23
@@ -1,135 +1 @@
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 _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
5
- let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
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
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../types/command.cjs`),t=require(`./helpers.cjs`);let n=require(`@powerlines/deepkit/vendor/type`),r=require(`@stryke/type-checks/is-set-object`),i=require(`@stryke/type-checks/is-bigint`),a=require(`@stryke/type-checks/is-number`),o=require(`@stryke/type-checks/is-regexp`);function s(e,t){return e.__type=t,e}function c(t){let o=!((0,r.isSetObject)(t)&&`kind`in t),s=o?t:t.kind;return s===n.ReflectionKind.string?e.CommandParameterKinds.string:s===n.ReflectionKind.number||s===n.ReflectionKind.bigint||!o&&t.kind===n.ReflectionKind.literal&&((0,a.isNumber)(t.literal)||(0,i.isBigInt)(t.literal))?e.CommandParameterKinds.number:s===n.ReflectionKind.boolean?e.CommandParameterKinds.boolean:e.CommandParameterKinds.string}c.__type=[`type`,`CommandParameterKind`,`extractCommandParameterKind`,`PP!!J2!"w"/#`];function l(r,l){let u=l.getType(),d=r.output.options[l.getNameAsString()]??{},f={name:l.getNameAsString(),alias:l.getTags().alias??[],title:l.getTags().title?.trim(),description:l.getDescription(),kind:c(u),optional:l.isOptional(),default:l.getDefaultValue(),variadic:l.isArray()};if(f.variadic)f.kind=c(u.type.kind);else if(u.kind===n.ReflectionKind.union)f.kind=u.types.every(s(e=>e.kind===n.ReflectionKind.number||e.kind===n.ReflectionKind.literal&&((0,a.isNumber)(e.literal)||(0,i.isBigInt)(e.literal)),[`t`,``,`P"2!"/"`]))?e.CommandParameterKinds.number:e.CommandParameterKinds.string,f.choices=u.types.map(s(e=>e.kind===n.ReflectionKind.literal?(0,a.isNumber)(e.literal)?e.literal:(0,i.isBigInt)(e.literal)?Number(e.literal):(0,o.isRegExp)(e.literal)?e.literal.source:String(e.literal):null,[`t`,``,`P"2!"/"`])).filter(Boolean);else if(u.kind===n.ReflectionKind.literal)f.choices=[(0,a.isNumber)(u.literal)?u.literal:(0,i.isBigInt)(u.literal)?Number(u.literal):(0,o.isRegExp)(u.literal)?u.literal.source:String(u.literal)].filter(Boolean);else if(!d.kind&&u.kind!==n.ReflectionKind.boolean&&u.kind!==n.ReflectionKind.string&&u.kind!==n.ReflectionKind.number)throw Error(`Unsupported type for option "${l.getNameAsString()}" in command "${r.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${(0,n.stringifyType)(u).trim().replaceAll(` | `,`, or `)}.`);return t.mergeCommandParameter(d,f)}l.__type=[`ResolverContext`,`ctx`,`reflection`,`CommandOption`,`resolveCommandOption`,`P"w!2"!2#"w$/%`];function u(r,l,u){let d=u.getType(),f=r.output.args.length>l?r.output.args[l]:{},p={name:u.getName()||u.parameter.name,alias:u.getAlias(),kind:c(d.kind),title:u.getTitle()||u.parameter.tags?.title,description:u.parameter.description,optional:u.isOptional(),default:u.getDefaultValue()||u.parameter.default};if(d.kind===n.ReflectionKind.array)if(d.type.kind===n.ReflectionKind.string||d.type.kind===n.ReflectionKind.number)p.variadic=!0,p.kind=c(d.type.kind);else throw Error(`Unsupported array type for positional argument "${p.name}" in command "${r.input.command.name}". Only string[], number[], or literal[] are supported, received ${(0,n.stringifyType)(d).trim().replaceAll(` | `,`, or `)}.`);else if(d.kind===n.ReflectionKind.union)p.kind=d.types.every(s(e=>e.kind===n.ReflectionKind.number||e.kind===n.ReflectionKind.literal&&((0,a.isNumber)(e.literal)||(0,i.isBigInt)(e.literal)),[`t`,``,`P"2!"/"`]))?e.CommandParameterKinds.number:e.CommandParameterKinds.string,p.choices=d.types.map(s(e=>e.kind===n.ReflectionKind.literal?(0,a.isNumber)(e.literal)?e.literal:(0,i.isBigInt)(e.literal)?Number(e.literal):(0,o.isRegExp)(e.literal)?e.literal.source:String(e.literal):null,[`t`,``,`P"2!"/"`])).filter(Boolean);else if(d.kind===n.ReflectionKind.literal)p.choices=[(0,a.isNumber)(d.literal)?d.literal:(0,i.isBigInt)(d.literal)?Number(d.literal):(0,o.isRegExp)(d.literal)?d.literal.source:String(d.literal)].filter(Boolean);else if(!r.output.args?.length&&d.kind!==n.ReflectionKind.boolean&&d.kind!==n.ReflectionKind.string&&d.kind!==n.ReflectionKind.number)throw Error(`Unsupported type for positional argument "${p.name}" in command "${r.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${(0,n.stringifyType)(d).trim().replaceAll(` | `,`, or `)}.`);return t.mergeCommandParameter(f,p,{name:`arg${l}`})}u.__type=[`ResolverContext`,`ctx`,`index`,`reflection`,`CommandArgument`,`resolveCommandArgument`,`P"w!2"'2#!2$"w%/&`];function d(e){let{input:t,module:r}=e,i=(0,n.reflect)(r);if(i.kind!==n.ReflectionKind.function)throw Error(`The command entry file "${t.command.entry.input?.file||t.command.path}" does not export a valid function.`);let a=new n.ReflectionFunction(i);e.output.description??=e.input.command.description||a.getDescription()||i.description;let o=a.getParameters();if(o.length>0){let t=o[0]&&(o[0].type.kind===n.ReflectionKind.objectLiteral||o[0].type.kind===n.ReflectionKind.class);if(t){let t=n.ReflectionClass.from(o[0]?.type);for(let n of t.getProperties())e.output.options[n.getNameAsString()]=l(e,n)}e.output.args=(t?o.slice(1):o).map(s((t,n)=>u(e,n,t),[`arg`,`index`,``,`P"2!"2""/#`]))}}d.__type=[`ResolverContext`,`ctx`,`resolveFromBytecode`,`P"w!2""/#`],exports.resolveFromBytecode=d;
@@ -1,135 +1,2 @@
1
- import { CommandParameterKinds } from "../types/command.mjs";
2
- import { mergeCommandParameter } from "./helpers.mjs";
3
- import { isSetObject } from "@stryke/type-checks/is-set-object";
4
- import { ReflectionClass, ReflectionFunction, ReflectionKind, reflect, stringifyType } from "@powerlines/deepkit/vendor/type";
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 };
1
+ import{CommandParameterKinds as e}from"../types/command.mjs";import{mergeCommandParameter as t}from"./helpers.mjs";import{ReflectionClass as n,ReflectionFunction as r,ReflectionKind as i,reflect as a,stringifyType as o}from"@powerlines/deepkit/vendor/type";import{isSetObject as s}from"@stryke/type-checks/is-set-object";import{isBigInt as c}from"@stryke/type-checks/is-bigint";import{isNumber as l}from"@stryke/type-checks/is-number";import{isRegExp as u}from"@stryke/type-checks/is-regexp";function d(e,t){return e.__type=t,e}function f(t){let n=!(s(t)&&`kind`in t),r=n?t:t.kind;return r===i.string?e.string:r===i.number||r===i.bigint||!n&&t.kind===i.literal&&(l(t.literal)||c(t.literal))?e.number:r===i.boolean?e.boolean:e.string}f.__type=[`type`,`CommandParameterKind`,`extractCommandParameterKind`,`PP!!J2!"w"/#`];function p(n,r){let a=r.getType(),s=n.output.options[r.getNameAsString()]??{},p={name:r.getNameAsString(),alias:r.getTags().alias??[],title:r.getTags().title?.trim(),description:r.getDescription(),kind:f(a),optional:r.isOptional(),default:r.getDefaultValue(),variadic:r.isArray()};if(p.variadic)p.kind=f(a.type.kind);else if(a.kind===i.union)p.kind=a.types.every(d(e=>e.kind===i.number||e.kind===i.literal&&(l(e.literal)||c(e.literal)),[`t`,``,`P"2!"/"`]))?e.number:e.string,p.choices=a.types.map(d(e=>e.kind===i.literal?l(e.literal)?e.literal:c(e.literal)?Number(e.literal):u(e.literal)?e.literal.source:String(e.literal):null,[`t`,``,`P"2!"/"`])).filter(Boolean);else if(a.kind===i.literal)p.choices=[l(a.literal)?a.literal:c(a.literal)?Number(a.literal):u(a.literal)?a.literal.source:String(a.literal)].filter(Boolean);else if(!s.kind&&a.kind!==i.boolean&&a.kind!==i.string&&a.kind!==i.number)throw Error(`Unsupported type for option "${r.getNameAsString()}" in command "${n.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${o(a).trim().replaceAll(` | `,`, or `)}.`);return t(s,p)}p.__type=[`ResolverContext`,`ctx`,`reflection`,`CommandOption`,`resolveCommandOption`,`P"w!2"!2#"w$/%`];function m(n,r,a){let s=a.getType(),p=n.output.args.length>r?n.output.args[r]:{},m={name:a.getName()||a.parameter.name,alias:a.getAlias(),kind:f(s.kind),title:a.getTitle()||a.parameter.tags?.title,description:a.parameter.description,optional:a.isOptional(),default:a.getDefaultValue()||a.parameter.default};if(s.kind===i.array)if(s.type.kind===i.string||s.type.kind===i.number)m.variadic=!0,m.kind=f(s.type.kind);else throw Error(`Unsupported array type for positional argument "${m.name}" in command "${n.input.command.name}". Only string[], number[], or literal[] are supported, received ${o(s).trim().replaceAll(` | `,`, or `)}.`);else if(s.kind===i.union)m.kind=s.types.every(d(e=>e.kind===i.number||e.kind===i.literal&&(l(e.literal)||c(e.literal)),[`t`,``,`P"2!"/"`]))?e.number:e.string,m.choices=s.types.map(d(e=>e.kind===i.literal?l(e.literal)?e.literal:c(e.literal)?Number(e.literal):u(e.literal)?e.literal.source:String(e.literal):null,[`t`,``,`P"2!"/"`])).filter(Boolean);else if(s.kind===i.literal)m.choices=[l(s.literal)?s.literal:c(s.literal)?Number(s.literal):u(s.literal)?s.literal.source:String(s.literal)].filter(Boolean);else if(!n.output.args?.length&&s.kind!==i.boolean&&s.kind!==i.string&&s.kind!==i.number)throw Error(`Unsupported type for positional argument "${m.name}" in command "${n.input.command.name}". Only string, number, boolean, string[], number[], or literal[] are supported, received ${o(s).trim().replaceAll(` | `,`, or `)}.`);return t(p,m,{name:`arg${r}`})}m.__type=[`ResolverContext`,`ctx`,`index`,`reflection`,`CommandArgument`,`resolveCommandArgument`,`P"w!2"'2#!2$"w%/&`];function h(e){let{input:t,module:o}=e,s=a(o);if(s.kind!==i.function)throw Error(`The command entry file "${t.command.entry.input?.file||t.command.path}" does not export a valid function.`);let c=new r(s);e.output.description??=e.input.command.description||c.getDescription()||s.description;let l=c.getParameters();if(l.length>0){let t=l[0]&&(l[0].type.kind===i.objectLiteral||l[0].type.kind===i.class);if(t){let t=n.from(l[0]?.type);for(let n of t.getProperties())e.output.options[n.getNameAsString()]=p(e,n)}e.output.args=(t?l.slice(1):l).map(d((t,n)=>m(e,n,t),[`arg`,`index`,``,`P"2!"2""/#`]))}}h.__type=[`ResolverContext`,`ctx`,`resolveFromBytecode`,`P"w!2""/#`];export{h as resolveFromBytecode};
135
2
  //# 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":";;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE5B,QAAO;;AASX,SAAC,4BAAkC,MAAK;CACvC,MAAS,SAAS,EAAE,Y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AS,IACnB,KAAA;CACF,MAAG,aAAY,WAAA,eAAyB;AACxC,KAAI,WAAI,SAAA,GAAA;EACL,MAAA,aAAY,WAAA,OACX,WAAA,GAAA,KAAA,SAAiC,eAAe,iBAC7C,WAAA,GAAA,KAAA,SAAA,eAAA;AACL,MAAM,YAAS;GACZ,MAAA,oBAA2B,gBAAW,KAAY,WAAS,IAAM,KAAI;AACpE,QAAI,MAAM,sBAAQ,kBAAA,eAAA,CACZ,KAAC,OAAU,QAAQ,mBAAmB,iBAAW,IACvD,qBAAA,KAAA,mBAAA;;AAGF,MAAG,OAAA,QAAgB,aAAY,WAAA,MAAA,EAAA,GAAA,YAAA,IAAA,cAAA,KAAA,UAAA,uBAAA,KAAA,OAAA,IAAA,EAAA;GAAA;GAAA;GAAA;GAAA;GAAA,CAAA,CAAA;;;AAGvC,oBAAkB,SAAS;CAAA;CAAsB;CAAA;CAAA;CAAA"}
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,QAAA,EAAA,iBAAA,GAAA,EAAA,CAClB,EAAc,CACd,KAAA,EAAA,iBAAA,CACA,MAAO,EAAW,SAAQ,CAAA,OAAY,EAAA,CACxC,MAAS,EAAW,SAAO,CAAA,OAAY,MAAM,CAC7C,YAAiB,EAAU,gBAAY,CACvC,KAAS,EAA6B,EAAC,CACvC,SAAS,EAAc,YAAc,CACrC,QAAY,EAAA,iBAAA,CACV,SAAA,EAAe,SAAA,CACf,CACA,GAAA,EAAA,SACA,EAAO,KAAA,EAAA,EAAA,KAAA,KAAA,SACP,EAAA,OAAsB,EAAA,MACtB,EAAA,KAAA,EAAA,MAAA,MAAA,EAAA,GAAA,EAAA,OAAA,EAAA,QAAA,EAAA,OAAA,EAAA,UAAA,EAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAAA,CAAA,IAAA,GAA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CAEJ,EAAU,OAAA,CAAA,kBAAiC,MAAA,QAAA,aAAA,kBAAA,yBAAA,oBAAA,CAC3C,SAAc,EAAsB,EAAC,CACnC,GAAE,CACA,QACD,UAAA,EAEG,EAAO,EAAU,EAAA,CACrB,GAAE,EAAO,OAAO,EAAA,SACd,MAAS,MAAK,2BAA6B,EAAE,QAAA,MAAA,OAAA,MAAA,EAAA,QAAA,KAAA,qCAAA,CAE/C,IAAM,EAAC,IAAA,EAAA,EAAA,CACP,EAAI,OAAI,cAAS,EAAc,MAAC,QAAQ,aAAA,EAAA,gBAAA,EAAA,EAAA,YACxC,IAAM,EAAY,EAAA,eAAwB,CAC1C,GAAI,EAAK,OAAW,EAAO,CACzB,IAAA,EAAA,EAAA,KAAA,EAAA,GAAA,KAAA,OAAA,EAAA,eAAA,EAAA,GAAA,KAAA,OAAA,EAAA,OACA,GAAI,EAAA,CACF,IAAE,EAAsB,EAAM,KAAA,EAAA,IAAA,KAAA,gCAE/B,EAAO,OAAG,QAAA,EAAyB,iBAAuB,EAAC,EAAQ,EAAA,EAAA,CAGpE,EAAI,OAAI,MAAS,EAAe,EAAA,MAAA,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,173 +1 @@
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;
1
+ require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../plugin-utils/context-helpers.cjs`),t=require(`../types/command.cjs`);let n=require(`@stryke/string-format/constant-case`),r=require(`@stryke/type-checks/is-set-string`),i=require(`defu`),a=require(`@stryke/string-format/title-case`),o=require(`@stryke/helpers/get-unique`),s=require(`@stryke/type-checks/is-string`);function c(e,t){return e.__type=t,e}function l(e,n,r=!1,i=!1,o,s){return`A${r&&!s?`n optional`:``} command-line ${n===t.CommandParameterKinds.boolean?`flag`:`option`} that allows the user to ${n===t.CommandParameterKinds.boolean?`set the`:i?`specify custom`:`specify a custom`} ${o?.trim()||(0,a.titleCase)(e)} ${n===t.CommandParameterKinds.boolean?`indicator`:`${n===t.CommandParameterKinds.number?`numeric`:`string`} value${i?`s`:``}`}.`}l.__type=[`name`,`CommandParameterKind`,`kind`,`optional`,`variadic`,`title`,`defaultValue`,`resolveCommandOptionDescription`,`Resolves the description for a command option based on its reflection.`,`P&2!"w"2#"2$"2%&2&8"2'8&/(?)`];function u(e,n,r=!1,i=!1,o,s){return`An${r&&!s?` optional`:``} argument that allows the user to ${n===t.CommandParameterKinds.boolean?`set the`:i?`specify custom`:`specify a custom`} ${o?.trim()||(0,a.titleCase)(e)} ${n===t.CommandParameterKinds.boolean?`indicator`:`${n===t.CommandParameterKinds.number?`numeric`:`string`} value${i?`s`:``}`}.`}u.__type=[`name`,`CommandParameterKind`,`kind`,`optional`,`variadic`,`title`,`defaultValue`,`resolveCommandArgumentDescription`,`Resolves the description for a command argument based on its reflection.`,`P&2!"w"2#"2$"2%&2&8"2'8&/(?)`];function d(e){return Object.fromEntries(Object.entries(e.output.options).map(c(([r,i])=>{let o=i.name||r,s=i.title||(0,a.titleCase)(o);return[r,{...i,name:o,title:s,description:i.description||l(o,i.kind,i.optional,i.kind!==t.CommandParameterKinds.boolean&&i.variadic,s,i.default),env:i.env||i.env===!1?i.env:e.input.context.config.autoAssignEnv?(0,n.constantCase)(o):!1}]},[`param0`,``,`P"2!"/"`])))}d.__type=[`ResolverContext`,`ctx`,`applyOptionsDefaults`,`P"w!2""/#`];function f(e){return e.output.args.map(c((r,i)=>{let o=r.name||`arg${i+1}`,s=r.title||(0,a.titleCase)(o);return{...r,name:o,title:s,description:r.description||u(o,r.kind,r.optional,r.kind!==t.CommandParameterKinds.boolean&&r.variadic,s,r.default),env:r.name?r.env||r.env===!1?r.env:e.input.context.config.autoAssignEnv?(0,n.constantCase)(o):!1:!1}},[`arg`,`i`,``,`P"2!"2""/#`]))}f.__type=[`ResolverContext`,`ctx`,`CommandArgument`,`applyArgsDefaults`,`P"w!2""w#F/$`];function p(t){t.output.description??=`The ${t.output.title.replace(/(?:c|C)ommands?$/,``).trim()} executable command-line interface.`,(0,r.isSetString)(t.input.context.config.reference?.commands)&&t.input.context.config.reference.commands.includes(`{command}`)&&(t.output.reference??=t.input.context.config.reference.commands?t.input.context.config.reference.commands.replace(`{command}`,t.input.command.segments.filter(c(t=>!e.isDynamicPathSegment(t),[`segment`,``,`P"2!"/"`])).join(`/`)):void 0)}p.__type=[`ResolverContext`,`ctx`,`applyDefaults`,`P"w!2""/#`];function m(t){t.output.title??=(0,a.titleCase)(t.input.command.name),t.output.description??=`A collection of available ${t.output.title.replace(/(?:c|C)ommands?$/,``).trim()||(0,a.titleCase)(t.input.command.name)} commands that are included in the ${e.getAppTitle(t.input.context,!0)} command-line application.`}m.__type=[`ResolverContext`,`ctx`,`resolveVirtualCommand`,`P"w!2""/#`];const h=(0,i.createDefu)(c((e,t,n)=>(0,s.isString)(e[t])&&(0,s.isString)(n)?((0,r.isSetString)(n)&&(e[t]=n),!0):Array.isArray(e[t])&&Array.isArray(n)?(n.length>0&&(e[t]=(0,o.getUniqueBy)(e[t].concat(n),c(e=>(0,s.isString)(e)?e:JSON.stringify(e),[`item`,``,`P"2!"/"`]))),!0):!1,[`obj`,`key`,`value`,``,`P"2!"2""2#"/$`]));exports.applyArgsDefaults=f,exports.applyDefaults=p,exports.applyOptionsDefaults=d,exports.mergeCommandParameter=h,exports.resolveVirtualCommand=m;