@shell-shock/core 0.17.8 → 0.17.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +29 -1
- package/dist/api.cjs +148 -1
- package/dist/api.d.cts +6 -6
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +6 -6
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +145 -1
- package/dist/api.mjs.map +1 -1
- package/dist/components/command-validation-logic.cjs +292 -1
- package/dist/components/command-validation-logic.mjs +289 -1
- package/dist/components/command-validation-logic.mjs.map +1 -1
- package/dist/components/docs.cjs +265 -1
- package/dist/components/docs.mjs +256 -1
- package/dist/components/docs.mjs.map +1 -1
- package/dist/components/exec-builtin.cjs +429 -13
- package/dist/components/exec-builtin.mjs +425 -13
- package/dist/components/exec-builtin.mjs.map +1 -1
- package/dist/components/helpers.cjs +120 -1
- package/dist/components/helpers.mjs +112 -1
- package/dist/components/helpers.mjs.map +1 -1
- package/dist/components/index.cjs +58 -1
- package/dist/components/index.mjs +10 -1
- package/dist/components/options-parser-logic.cjs +960 -5
- package/dist/components/options-parser-logic.d.cts +1 -1
- package/dist/components/options-parser-logic.mjs +945 -5
- package/dist/components/options-parser-logic.mjs.map +1 -1
- package/dist/components/state-builtin.cjs +629 -8
- package/dist/components/state-builtin.mjs +622 -8
- package/dist/components/state-builtin.mjs.map +1 -1
- package/dist/components/usage.cjs +117 -1
- package/dist/components/usage.mjs +114 -1
- package/dist/components/usage.mjs.map +1 -1
- package/dist/components/utils-builtin.cjs +838 -33
- package/dist/components/utils-builtin.mjs +828 -33
- package/dist/components/utils-builtin.mjs.map +1 -1
- package/dist/config.cjs +31 -1
- package/dist/config.mjs +29 -1
- package/dist/config.mjs.map +1 -1
- package/dist/contexts/command.cjs +26 -1
- package/dist/contexts/command.mjs +23 -1
- package/dist/contexts/command.mjs.map +1 -1
- package/dist/contexts/index.cjs +9 -1
- package/dist/contexts/index.mjs +4 -1
- package/dist/contexts/options.cjs +63 -1
- package/dist/contexts/options.mjs +58 -1
- package/dist/contexts/options.mjs.map +1 -1
- package/dist/helpers/automd.cjs +71 -1
- package/dist/helpers/automd.mjs +70 -1
- package/dist/helpers/automd.mjs.map +1 -1
- package/dist/helpers/docs-helpers.cjs +23 -1
- package/dist/helpers/docs-helpers.mjs +22 -1
- package/dist/helpers/docs-helpers.mjs.map +1 -1
- package/dist/helpers/paths.cjs +137 -1
- package/dist/helpers/paths.mjs +133 -1
- package/dist/helpers/paths.mjs.map +1 -1
- package/dist/helpers/persistence.cjs +115 -1
- package/dist/helpers/persistence.mjs +112 -1
- package/dist/helpers/persistence.mjs.map +1 -1
- package/dist/helpers/update-package-json.cjs +65 -1
- package/dist/helpers/update-package-json.mjs +63 -1
- package/dist/helpers/update-package-json.mjs.map +1 -1
- package/dist/helpers/utilities.cjs +95 -1
- package/dist/helpers/utilities.mjs +93 -1
- package/dist/helpers/utilities.mjs.map +1 -1
- package/dist/helpers/validations.cjs +71 -1
- package/dist/helpers/validations.mjs +71 -1
- package/dist/helpers/validations.mjs.map +1 -1
- package/dist/index.cjs +53 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +7 -1
- package/dist/plugin-utils/compute-bin.cjs +50 -1
- package/dist/plugin-utils/compute-bin.mjs +49 -1
- package/dist/plugin-utils/compute-bin.mjs.map +1 -1
- package/dist/plugin-utils/context-helpers.cjs +231 -1
- package/dist/plugin-utils/context-helpers.mjs +221 -1
- package/dist/plugin-utils/context-helpers.mjs.map +1 -1
- package/dist/plugin-utils/deepkit.cjs +71 -1
- package/dist/plugin-utils/deepkit.mjs +69 -1
- package/dist/plugin-utils/deepkit.mjs.map +1 -1
- package/dist/plugin-utils/description-helpers.cjs +111 -2
- package/dist/plugin-utils/description-helpers.mjs +107 -2
- package/dist/plugin-utils/description-helpers.mjs.map +1 -1
- package/dist/plugin-utils/get-command-tree.cjs +117 -1
- package/dist/plugin-utils/get-command-tree.mjs +114 -1
- package/dist/plugin-utils/get-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/index.cjs +39 -1
- package/dist/plugin-utils/index.mjs +10 -1
- package/dist/plugin-utils/reflect.cjs +52 -1
- package/dist/plugin-utils/reflect.mjs +52 -1
- package/dist/plugin-utils/reflect.mjs.map +1 -1
- package/dist/plugin-utils/traverse-command-tree.cjs +64 -1
- package/dist/plugin-utils/traverse-command-tree.mjs +62 -1
- package/dist/plugin-utils/traverse-command-tree.mjs.map +1 -1
- package/dist/plugin-utils/type-checks.cjs +93 -1
- package/dist/plugin-utils/type-checks.mjs +88 -1
- package/dist/plugin-utils/type-checks.mjs.map +1 -1
- package/dist/plugin.cjs +471 -4
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.mts.map +1 -1
- package/dist/plugin.mjs +465 -4
- package/dist/plugin.mjs.map +1 -1
- package/dist/resolver/deepkit.cjs +135 -1
- package/dist/resolver/deepkit.mjs +134 -1
- package/dist/resolver/deepkit.mjs.map +1 -1
- package/dist/resolver/helpers.cjs +173 -1
- package/dist/resolver/helpers.mjs +168 -1
- package/dist/resolver/helpers.mjs.map +1 -1
- package/dist/resolver/module.cjs +145 -1
- package/dist/resolver/module.mjs +144 -1
- package/dist/resolver/module.mjs.map +1 -1
- package/dist/resolver/resolve.cjs +222 -1
- package/dist/resolver/resolve.mjs +221 -1
- package/dist/resolver/resolve.mjs.map +1 -1
- package/dist/types/command.cjs +441 -1
- package/dist/types/command.d.cts +1 -1
- package/dist/types/command.d.mts +2 -2
- package/dist/types/command.mjs +405 -1
- package/dist/types/command.mjs.map +1 -1
- package/dist/types/config.cjs +134 -1
- package/dist/types/config.d.cts +10 -8
- package/dist/types/config.d.cts.map +1 -1
- package/dist/types/config.d.mts +10 -8
- package/dist/types/config.d.mts.map +1 -1
- package/dist/types/config.mjs +127 -1
- package/dist/types/config.mjs.map +1 -1
- package/dist/types/context.cjs +37 -1
- package/dist/types/context.mjs +34 -1
- package/dist/types/context.mjs.map +1 -1
- package/dist/types/env.cjs +52 -1
- package/dist/types/env.d.cts +1 -1
- package/dist/types/env.d.mts +1 -1
- package/dist/types/env.mjs +50 -1
- package/dist/types/env.mjs.map +1 -1
- package/dist/types/index.cjs +50 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +6 -1
- package/dist/types/options.cjs +12 -1
- package/dist/types/options.mjs +10 -1
- package/package.json +22 -21
|
@@ -1 +1,222 @@
|
|
|
1
|
-
|
|
1
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
2
|
+
const require_context_helpers = require('../plugin-utils/context-helpers.cjs');
|
|
3
|
+
const require_deepkit = require('../plugin-utils/deepkit.cjs');
|
|
4
|
+
const require_utilities = require('../helpers/utilities.cjs');
|
|
5
|
+
const require_helpers = require('./helpers.cjs');
|
|
6
|
+
const require_deepkit$1 = require('./deepkit.cjs');
|
|
7
|
+
const require_module = require('./module.cjs');
|
|
8
|
+
let _powerlines_deepkit_vendor_type = require("@powerlines/deepkit/vendor/type");
|
|
9
|
+
let _stryke_string_format_constant_case = require("@stryke/string-format/constant-case");
|
|
10
|
+
let _stryke_string_format_title_case = require("@stryke/string-format/title-case");
|
|
11
|
+
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
12
|
+
let _powerlines_deepkit_esbuild_plugin = require("@powerlines/deepkit/esbuild-plugin");
|
|
13
|
+
let _powerlines_plugin_esbuild_helpers_resolve = require("@powerlines/plugin-esbuild/helpers/resolve");
|
|
14
|
+
|
|
15
|
+
//#region src/resolver/resolve.ts
|
|
16
|
+
function __assignType(fn, args) {
|
|
17
|
+
fn.__type = args;
|
|
18
|
+
return fn;
|
|
19
|
+
}
|
|
20
|
+
async function initialize(input) {
|
|
21
|
+
const { context, command, parent } = input;
|
|
22
|
+
const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/(?:c|C)ommands?$/, "").trim() : parent.title} - ` : ""}${(0, _stryke_string_format_title_case.titleCase)(command.name)}${command.isVirtual ? " Commands" : ""}`;
|
|
23
|
+
const result = {
|
|
24
|
+
input,
|
|
25
|
+
output: {
|
|
26
|
+
alias: [],
|
|
27
|
+
icon: parent?.icon,
|
|
28
|
+
tags: parent?.tags ?? [],
|
|
29
|
+
source: "file",
|
|
30
|
+
...command,
|
|
31
|
+
title,
|
|
32
|
+
options: parent === null ? require_utilities.getGlobalOptions(context, command) : {},
|
|
33
|
+
args: [],
|
|
34
|
+
parent: parent ?? null,
|
|
35
|
+
children: {}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
if (!command.isVirtual) {
|
|
39
|
+
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
40
|
+
context.debug(`Adding reflection for CLI command: ${command.id} (file: ${command.entry.input.file})`);
|
|
41
|
+
result.module = await (_powerlines_plugin_esbuild_helpers_resolve.resolveModule.Ω = [["CommandModule", "\"w!"]], (0, _powerlines_plugin_esbuild_helpers_resolve.resolveModule)(context, command.entry.input, {
|
|
42
|
+
name: command.title || (0, _stryke_string_format_title_case.titleCase)(command.name),
|
|
43
|
+
treeShaking: true,
|
|
44
|
+
resolve: { skipNodeModulesBundle: true },
|
|
45
|
+
plugins: [(0, _powerlines_deepkit_esbuild_plugin.esbuildPlugin)(context, {
|
|
46
|
+
reflection: "default",
|
|
47
|
+
level: "all"
|
|
48
|
+
})]
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
initialize.__type = [
|
|
54
|
+
"ResolverInput",
|
|
55
|
+
"input",
|
|
56
|
+
"ResolverContext",
|
|
57
|
+
"initialize",
|
|
58
|
+
"P\"w!2\"\"w#`/$"
|
|
59
|
+
];
|
|
60
|
+
async function postprocess(ctx) {
|
|
61
|
+
ctx.output.options = require_helpers.applyOptionsDefaults(ctx);
|
|
62
|
+
ctx.output.args = require_helpers.applyArgsDefaults(ctx);
|
|
63
|
+
ctx.output.args.forEach(__assignType((arg, index) => {
|
|
64
|
+
const found = ctx.output.args.findIndex(__assignType((a) => a.name === arg.name, [
|
|
65
|
+
"a",
|
|
66
|
+
"",
|
|
67
|
+
"P\"2!\"/\""
|
|
68
|
+
]));
|
|
69
|
+
if (found !== -1 && found !== index || ctx.output.segments.some(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment) === arg.name, [
|
|
70
|
+
"segment",
|
|
71
|
+
"",
|
|
72
|
+
"P\"2!\"/\""
|
|
73
|
+
]))) {
|
|
74
|
+
arg.name += `_${ctx.output.segments.filter(__assignType((segment) => require_context_helpers.isDynamicPathSegment(segment) && require_context_helpers.getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === arg.name, [
|
|
75
|
+
"segment",
|
|
76
|
+
"",
|
|
77
|
+
"P\"2!\"/\""
|
|
78
|
+
])).length + ctx.output.args.filter(__assignType((a) => a.name.replace(/_\d+$/, "") === arg.name, [
|
|
79
|
+
"a",
|
|
80
|
+
"",
|
|
81
|
+
"P\"2!\"/\""
|
|
82
|
+
])).length}`;
|
|
83
|
+
arg.env = arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? (0, _stryke_string_format_constant_case.constantCase)(arg.name) : false : false;
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
"arg",
|
|
87
|
+
"index",
|
|
88
|
+
"",
|
|
89
|
+
"P\"2!\"2\"\"/#"
|
|
90
|
+
]));
|
|
91
|
+
require_helpers.applyDefaults(ctx);
|
|
92
|
+
if (ctx.input.context.env) {
|
|
93
|
+
if ((0, _stryke_type_checks_is_set_object.isSetObject)(ctx.output.options)) Object.values(ctx.output.options).filter(__assignType((option) => Boolean(option.env), [
|
|
94
|
+
"option",
|
|
95
|
+
"",
|
|
96
|
+
"P\"2!\"/\""
|
|
97
|
+
])).forEach(__assignType((option) => {
|
|
98
|
+
ctx.input.context.env.types.env.addProperty({
|
|
99
|
+
name: option.env,
|
|
100
|
+
optional: option.optional ? true : void 0,
|
|
101
|
+
description: option.description,
|
|
102
|
+
visibility: _powerlines_deepkit_vendor_type.ReflectionVisibility.public,
|
|
103
|
+
type: require_deepkit.extractType(option),
|
|
104
|
+
default: option.default,
|
|
105
|
+
tags: {
|
|
106
|
+
title: option.title,
|
|
107
|
+
alias: option.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
108
|
+
"alias",
|
|
109
|
+
"",
|
|
110
|
+
"P\"2!\"/\""
|
|
111
|
+
])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
|
|
112
|
+
"alias",
|
|
113
|
+
"",
|
|
114
|
+
"P\"2!\"/\""
|
|
115
|
+
])),
|
|
116
|
+
domain: "cli"
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}, [
|
|
120
|
+
"option",
|
|
121
|
+
"",
|
|
122
|
+
"P\"2!\"/\""
|
|
123
|
+
]));
|
|
124
|
+
ctx.output.args.filter(__assignType((arg) => Boolean(arg.env), [
|
|
125
|
+
"arg",
|
|
126
|
+
"",
|
|
127
|
+
"P\"2!\"/\""
|
|
128
|
+
])).forEach(__assignType((arg) => ctx.input.context.env.types.env.addProperty({
|
|
129
|
+
name: arg.env,
|
|
130
|
+
optional: arg.optional ? true : void 0,
|
|
131
|
+
description: arg.description,
|
|
132
|
+
visibility: _powerlines_deepkit_vendor_type.ReflectionVisibility.public,
|
|
133
|
+
type: require_deepkit.extractType(arg),
|
|
134
|
+
default: arg.default,
|
|
135
|
+
tags: {
|
|
136
|
+
alias: arg.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
137
|
+
"alias",
|
|
138
|
+
"",
|
|
139
|
+
"P\"2!\"/\""
|
|
140
|
+
])).map(__assignType((alias) => (0, _stryke_string_format_constant_case.constantCase)(alias), [
|
|
141
|
+
"alias",
|
|
142
|
+
"",
|
|
143
|
+
"P\"2!\"/\""
|
|
144
|
+
])),
|
|
145
|
+
domain: "cli"
|
|
146
|
+
}
|
|
147
|
+
}), [
|
|
148
|
+
"arg",
|
|
149
|
+
"",
|
|
150
|
+
"P\"2!\"/\""
|
|
151
|
+
]));
|
|
152
|
+
}
|
|
153
|
+
await Promise.all(ctx.input.context.inputs.filter(__assignType((input) => input.segments.filter(__assignType((segment) => !require_context_helpers.isDynamicPathSegment(segment), [
|
|
154
|
+
"segment",
|
|
155
|
+
"",
|
|
156
|
+
"P\"2!\"/\""
|
|
157
|
+
])).length === ctx.input.command.segments.filter(__assignType((segment) => !require_context_helpers.isDynamicPathSegment(segment), [
|
|
158
|
+
"segment",
|
|
159
|
+
"",
|
|
160
|
+
"P\"2!\"/\""
|
|
161
|
+
])).length + 1 && input.segments.slice(0, ctx.input.command.segments.length).every(__assignType((value, index) => value === ctx.input.command.segments[index], [
|
|
162
|
+
"value",
|
|
163
|
+
"index",
|
|
164
|
+
"",
|
|
165
|
+
"P\"2!\"2\"\"/#"
|
|
166
|
+
])), [
|
|
167
|
+
"input",
|
|
168
|
+
"",
|
|
169
|
+
"P\"2!\"/\""
|
|
170
|
+
])).map(__assignType(async (input) => {
|
|
171
|
+
ctx.output.children[input.name] = await (resolve.Ω = [[
|
|
172
|
+
() => ctx,
|
|
173
|
+
"ResolverContext",
|
|
174
|
+
"Pi!\"w\"q\"!j"
|
|
175
|
+
]], resolve({
|
|
176
|
+
context: ctx.input.context,
|
|
177
|
+
command: input,
|
|
178
|
+
parent: ctx.output
|
|
179
|
+
}));
|
|
180
|
+
}, [
|
|
181
|
+
"input",
|
|
182
|
+
"",
|
|
183
|
+
"P\"2!\"/\""
|
|
184
|
+
])));
|
|
185
|
+
return ctx.output;
|
|
186
|
+
}
|
|
187
|
+
postprocess.__type = [
|
|
188
|
+
"ResolverContext",
|
|
189
|
+
"ctx",
|
|
190
|
+
"CommandTree",
|
|
191
|
+
"postprocess",
|
|
192
|
+
"P\"w!2\"\"w#`/$"
|
|
193
|
+
];
|
|
194
|
+
/**
|
|
195
|
+
* Resolves a command tree from the given resolver input.
|
|
196
|
+
*
|
|
197
|
+
* @param input - The resolver input containing the context, command, and optional parent command tree.
|
|
198
|
+
* @returns A promise that resolves to the resolved command tree.
|
|
199
|
+
*/
|
|
200
|
+
async function resolve(input) {
|
|
201
|
+
const ctx = await (initialize.Ω = [[
|
|
202
|
+
() => input,
|
|
203
|
+
"ResolverInput",
|
|
204
|
+
"Pi!\"w\"q\"!j"
|
|
205
|
+
]], initialize(input));
|
|
206
|
+
if (!ctx.output.isVirtual) {
|
|
207
|
+
await require_module.resolveFromExports(ctx);
|
|
208
|
+
require_deepkit$1.resolveFromBytecode(ctx);
|
|
209
|
+
} else require_helpers.resolveVirtualCommand(ctx);
|
|
210
|
+
return postprocess(ctx);
|
|
211
|
+
}
|
|
212
|
+
resolve.__type = [
|
|
213
|
+
"ResolverInput",
|
|
214
|
+
"input",
|
|
215
|
+
"CommandTree",
|
|
216
|
+
"resolve",
|
|
217
|
+
"Resolves a command tree from the given resolver input.",
|
|
218
|
+
"P\"w!2\"\"w#`/$?%"
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
//#endregion
|
|
222
|
+
exports.resolve = resolve;
|
|
@@ -1,2 +1,222 @@
|
|
|
1
|
-
import{getDynamicPathSegmentName
|
|
1
|
+
import { getDynamicPathSegmentName, isDynamicPathSegment } from "../plugin-utils/context-helpers.mjs";
|
|
2
|
+
import { extractType } from "../plugin-utils/deepkit.mjs";
|
|
3
|
+
import { getGlobalOptions } from "../helpers/utilities.mjs";
|
|
4
|
+
import { applyArgsDefaults, applyDefaults, applyOptionsDefaults, resolveVirtualCommand } from "./helpers.mjs";
|
|
5
|
+
import { resolveFromBytecode } from "./deepkit.mjs";
|
|
6
|
+
import { resolveFromExports } from "./module.mjs";
|
|
7
|
+
import { ReflectionVisibility } from "@powerlines/deepkit/vendor/type";
|
|
8
|
+
import { constantCase } from "@stryke/string-format/constant-case";
|
|
9
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
10
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
11
|
+
import { esbuildPlugin } from "@powerlines/deepkit/esbuild-plugin";
|
|
12
|
+
import { resolveModule } from "@powerlines/plugin-esbuild/helpers/resolve";
|
|
13
|
+
|
|
14
|
+
//#region src/resolver/resolve.ts
|
|
15
|
+
function __assignType(fn, args) {
|
|
16
|
+
fn.__type = args;
|
|
17
|
+
return fn;
|
|
18
|
+
}
|
|
19
|
+
async function initialize(input) {
|
|
20
|
+
const { context, command, parent } = input;
|
|
21
|
+
const title = command.title || `${parent?.title ? `${parent.isVirtual ? parent.title.replace(/(?:c|C)ommands?$/, "").trim() : parent.title} - ` : ""}${titleCase(command.name)}${command.isVirtual ? " Commands" : ""}`;
|
|
22
|
+
const result = {
|
|
23
|
+
input,
|
|
24
|
+
output: {
|
|
25
|
+
alias: [],
|
|
26
|
+
icon: parent?.icon,
|
|
27
|
+
tags: parent?.tags ?? [],
|
|
28
|
+
source: "file",
|
|
29
|
+
...command,
|
|
30
|
+
title,
|
|
31
|
+
options: parent === null ? getGlobalOptions(context, command) : {},
|
|
32
|
+
args: [],
|
|
33
|
+
parent: parent ?? null,
|
|
34
|
+
children: {}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
if (!command.isVirtual) {
|
|
38
|
+
if (!command.entry.input?.file || !context.fs.existsSync(command.entry.input.file)) throw new Error(`${!command.entry.input?.file ? "Missing" : "Non-existent"} command entry file for "${command.name}"`);
|
|
39
|
+
context.debug(`Adding reflection for CLI command: ${command.id} (file: ${command.entry.input.file})`);
|
|
40
|
+
result.module = await (resolveModule.Ω = [["CommandModule", "\"w!"]], resolveModule(context, command.entry.input, {
|
|
41
|
+
name: command.title || titleCase(command.name),
|
|
42
|
+
treeShaking: true,
|
|
43
|
+
resolve: { skipNodeModulesBundle: true },
|
|
44
|
+
plugins: [esbuildPlugin(context, {
|
|
45
|
+
reflection: "default",
|
|
46
|
+
level: "all"
|
|
47
|
+
})]
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
initialize.__type = [
|
|
53
|
+
"ResolverInput",
|
|
54
|
+
"input",
|
|
55
|
+
"ResolverContext",
|
|
56
|
+
"initialize",
|
|
57
|
+
"P\"w!2\"\"w#`/$"
|
|
58
|
+
];
|
|
59
|
+
async function postprocess(ctx) {
|
|
60
|
+
ctx.output.options = applyOptionsDefaults(ctx);
|
|
61
|
+
ctx.output.args = applyArgsDefaults(ctx);
|
|
62
|
+
ctx.output.args.forEach(__assignType((arg, index) => {
|
|
63
|
+
const found = ctx.output.args.findIndex(__assignType((a) => a.name === arg.name, [
|
|
64
|
+
"a",
|
|
65
|
+
"",
|
|
66
|
+
"P\"2!\"/\""
|
|
67
|
+
]));
|
|
68
|
+
if (found !== -1 && found !== index || ctx.output.segments.some(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment) === arg.name, [
|
|
69
|
+
"segment",
|
|
70
|
+
"",
|
|
71
|
+
"P\"2!\"/\""
|
|
72
|
+
]))) {
|
|
73
|
+
arg.name += `_${ctx.output.segments.filter(__assignType((segment) => isDynamicPathSegment(segment) && getDynamicPathSegmentName(segment).replace(/_\d+$/, "") === arg.name, [
|
|
74
|
+
"segment",
|
|
75
|
+
"",
|
|
76
|
+
"P\"2!\"/\""
|
|
77
|
+
])).length + ctx.output.args.filter(__assignType((a) => a.name.replace(/_\d+$/, "") === arg.name, [
|
|
78
|
+
"a",
|
|
79
|
+
"",
|
|
80
|
+
"P\"2!\"/\""
|
|
81
|
+
])).length}`;
|
|
82
|
+
arg.env = arg.name ? arg.env || arg.env === false ? arg.env : ctx.input.context.config.autoAssignEnv ? constantCase(arg.name) : false : false;
|
|
83
|
+
}
|
|
84
|
+
}, [
|
|
85
|
+
"arg",
|
|
86
|
+
"index",
|
|
87
|
+
"",
|
|
88
|
+
"P\"2!\"2\"\"/#"
|
|
89
|
+
]));
|
|
90
|
+
applyDefaults(ctx);
|
|
91
|
+
if (ctx.input.context.env) {
|
|
92
|
+
if (isSetObject(ctx.output.options)) Object.values(ctx.output.options).filter(__assignType((option) => Boolean(option.env), [
|
|
93
|
+
"option",
|
|
94
|
+
"",
|
|
95
|
+
"P\"2!\"/\""
|
|
96
|
+
])).forEach(__assignType((option) => {
|
|
97
|
+
ctx.input.context.env.types.env.addProperty({
|
|
98
|
+
name: option.env,
|
|
99
|
+
optional: option.optional ? true : void 0,
|
|
100
|
+
description: option.description,
|
|
101
|
+
visibility: ReflectionVisibility.public,
|
|
102
|
+
type: extractType(option),
|
|
103
|
+
default: option.default,
|
|
104
|
+
tags: {
|
|
105
|
+
title: option.title,
|
|
106
|
+
alias: option.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
107
|
+
"alias",
|
|
108
|
+
"",
|
|
109
|
+
"P\"2!\"/\""
|
|
110
|
+
])).map(__assignType((alias) => constantCase(alias), [
|
|
111
|
+
"alias",
|
|
112
|
+
"",
|
|
113
|
+
"P\"2!\"/\""
|
|
114
|
+
])),
|
|
115
|
+
domain: "cli"
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}, [
|
|
119
|
+
"option",
|
|
120
|
+
"",
|
|
121
|
+
"P\"2!\"/\""
|
|
122
|
+
]));
|
|
123
|
+
ctx.output.args.filter(__assignType((arg) => Boolean(arg.env), [
|
|
124
|
+
"arg",
|
|
125
|
+
"",
|
|
126
|
+
"P\"2!\"/\""
|
|
127
|
+
])).forEach(__assignType((arg) => ctx.input.context.env.types.env.addProperty({
|
|
128
|
+
name: arg.env,
|
|
129
|
+
optional: arg.optional ? true : void 0,
|
|
130
|
+
description: arg.description,
|
|
131
|
+
visibility: ReflectionVisibility.public,
|
|
132
|
+
type: extractType(arg),
|
|
133
|
+
default: arg.default,
|
|
134
|
+
tags: {
|
|
135
|
+
alias: arg.alias.filter(__assignType((alias) => alias.length > 1, [
|
|
136
|
+
"alias",
|
|
137
|
+
"",
|
|
138
|
+
"P\"2!\"/\""
|
|
139
|
+
])).map(__assignType((alias) => constantCase(alias), [
|
|
140
|
+
"alias",
|
|
141
|
+
"",
|
|
142
|
+
"P\"2!\"/\""
|
|
143
|
+
])),
|
|
144
|
+
domain: "cli"
|
|
145
|
+
}
|
|
146
|
+
}), [
|
|
147
|
+
"arg",
|
|
148
|
+
"",
|
|
149
|
+
"P\"2!\"/\""
|
|
150
|
+
]));
|
|
151
|
+
}
|
|
152
|
+
await Promise.all(ctx.input.context.inputs.filter(__assignType((input) => input.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
|
|
153
|
+
"segment",
|
|
154
|
+
"",
|
|
155
|
+
"P\"2!\"/\""
|
|
156
|
+
])).length === ctx.input.command.segments.filter(__assignType((segment) => !isDynamicPathSegment(segment), [
|
|
157
|
+
"segment",
|
|
158
|
+
"",
|
|
159
|
+
"P\"2!\"/\""
|
|
160
|
+
])).length + 1 && input.segments.slice(0, ctx.input.command.segments.length).every(__assignType((value, index) => value === ctx.input.command.segments[index], [
|
|
161
|
+
"value",
|
|
162
|
+
"index",
|
|
163
|
+
"",
|
|
164
|
+
"P\"2!\"2\"\"/#"
|
|
165
|
+
])), [
|
|
166
|
+
"input",
|
|
167
|
+
"",
|
|
168
|
+
"P\"2!\"/\""
|
|
169
|
+
])).map(__assignType(async (input) => {
|
|
170
|
+
ctx.output.children[input.name] = await (resolve.Ω = [[
|
|
171
|
+
() => ctx,
|
|
172
|
+
"ResolverContext",
|
|
173
|
+
"Pi!\"w\"q\"!j"
|
|
174
|
+
]], resolve({
|
|
175
|
+
context: ctx.input.context,
|
|
176
|
+
command: input,
|
|
177
|
+
parent: ctx.output
|
|
178
|
+
}));
|
|
179
|
+
}, [
|
|
180
|
+
"input",
|
|
181
|
+
"",
|
|
182
|
+
"P\"2!\"/\""
|
|
183
|
+
])));
|
|
184
|
+
return ctx.output;
|
|
185
|
+
}
|
|
186
|
+
postprocess.__type = [
|
|
187
|
+
"ResolverContext",
|
|
188
|
+
"ctx",
|
|
189
|
+
"CommandTree",
|
|
190
|
+
"postprocess",
|
|
191
|
+
"P\"w!2\"\"w#`/$"
|
|
192
|
+
];
|
|
193
|
+
/**
|
|
194
|
+
* Resolves a command tree from the given resolver input.
|
|
195
|
+
*
|
|
196
|
+
* @param input - The resolver input containing the context, command, and optional parent command tree.
|
|
197
|
+
* @returns A promise that resolves to the resolved command tree.
|
|
198
|
+
*/
|
|
199
|
+
async function resolve(input) {
|
|
200
|
+
const ctx = await (initialize.Ω = [[
|
|
201
|
+
() => input,
|
|
202
|
+
"ResolverInput",
|
|
203
|
+
"Pi!\"w\"q\"!j"
|
|
204
|
+
]], initialize(input));
|
|
205
|
+
if (!ctx.output.isVirtual) {
|
|
206
|
+
await resolveFromExports(ctx);
|
|
207
|
+
resolveFromBytecode(ctx);
|
|
208
|
+
} else resolveVirtualCommand(ctx);
|
|
209
|
+
return postprocess(ctx);
|
|
210
|
+
}
|
|
211
|
+
resolve.__type = [
|
|
212
|
+
"ResolverInput",
|
|
213
|
+
"input",
|
|
214
|
+
"CommandTree",
|
|
215
|
+
"resolve",
|
|
216
|
+
"Resolves a command tree from the given resolver input.",
|
|
217
|
+
"P\"w!2\"\"w#`/$?%"
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
//#endregion
|
|
221
|
+
export { resolve };
|
|
2
222
|
//# sourceMappingURL=resolve.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.mjs","names":[],"sources":["../../src/resolver/resolve.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 { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getGlobalOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n tags: parent?.tags ?? [],\n source: \"file\",\n ...command,\n title,\n options: parent === null ? getGlobalOptions(context, command) : {},\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for CLI command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n name: command.title || titleCase(command.name),\n treeShaking: true,\n resolve: {\n skipNodeModulesBundle: true\n },\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n await Promise.all(\n ctx.input.context.inputs\n .filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n })\n );\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);\n}\n"],"mappings":"q1BAAA,SAAS,EAAa,EAAI,EAAM,CAE9B,kBAAO,EA+BT,eAAE,EAAiB,EAAA,CACjB,GAAA,CACA,UACA,UACA,UACI,EACC,EAAO,EAAA,OAAiB,GAAA,GAAa,MAAQ,GAAG,EAAM,UAAA,EAAA,MAAA,QAAA,mBAAA,GAAA,CAAA,MAAA,CAAA,EAAA,MAAA,KAAA,KAAA,EAAA,EAAA,KAAA,GAAA,EAAA,UAAA,YAAA,KAarD,EAAQ,CACZ,QACA,OAAA,CAbJ,MAAM,EAAA,CACJ,KAAO,GAAA,KACN,KAAO,GAAC,MAAe,EAAE,CAC1B,OAAQ,YAER,QACE,QAAQ,IAAO,KAAA,EAAA,EAAA,EAAA,CAAA,EAAA,CACf,K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/resolve.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 { esbuildPlugin } from \"@powerlines/deepkit/esbuild-plugin\";\nimport { ReflectionVisibility } from \"@powerlines/deepkit/vendor/type\";\nimport { resolveModule } from \"@powerlines/plugin-esbuild/helpers/resolve\";\nimport { constantCase } from \"@stryke/string-format/constant-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { getGlobalOptions } from \"../helpers/utilities\";\nimport {\n getDynamicPathSegmentName,\n isDynamicPathSegment\n} from \"../plugin-utils/context-helpers\";\nimport { extractType } from \"../plugin-utils/deepkit\";\nimport type { CommandModule, CommandTree, Context } from \"../types\";\nimport { resolveFromBytecode } from \"./deepkit\";\nimport {\n applyArgsDefaults,\n applyDefaults,\n applyOptionsDefaults,\n resolveVirtualCommand\n} from \"./helpers\";\nimport { resolveFromExports } from \"./module\";\nimport type { ResolverContext, ResolverInput } from \"./types\";\n\nasync function initialize<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<ResolverContext> {\n const { context, command, parent } = input;\n\n const title =\n command.title ||\n `${\n parent?.title\n ? `${\n parent.isVirtual\n ? parent.title.replace(/(?:c|C)ommands?$/, \"\").trim()\n : parent.title\n } - `\n : \"\"\n }${titleCase(command.name)}${command.isVirtual ? \" Commands\" : \"\"}`;\n\n const output = {\n alias: [],\n icon: parent?.icon,\n tags: parent?.tags ?? [],\n source: \"file\",\n ...command,\n title,\n options: parent === null ? getGlobalOptions(context, command) : {},\n args: [],\n parent: parent ?? null,\n children: {}\n } as CommandTree;\n\n const result: ResolverContext = {\n input,\n output\n };\n\n if (!command.isVirtual) {\n if (\n !command.entry.input?.file ||\n !context.fs.existsSync(command.entry.input.file)\n ) {\n throw new Error(\n `${\n !command.entry.input?.file ? \"Missing\" : \"Non-existent\"\n } command entry file for \"${command.name}\"`\n );\n }\n\n context.debug(\n `Adding reflection for CLI command: ${command.id} (file: ${\n command.entry.input.file\n })`\n );\n\n result.module = await resolveModule<CommandModule>(\n context,\n command.entry.input,\n {\n name: command.title || titleCase(command.name),\n treeShaking: true,\n resolve: {\n skipNodeModulesBundle: true\n },\n plugins: [\n esbuildPlugin(context, {\n reflection: \"default\",\n level: \"all\"\n })\n ]\n }\n );\n }\n\n return result;\n}\n\nasync function postprocess<TContext extends Context = Context>(\n ctx: ResolverContext<TContext>\n): Promise<CommandTree> {\n ctx.output.options = applyOptionsDefaults(ctx);\n ctx.output.args = applyArgsDefaults(ctx);\n\n // Ensure unique argument names by appending an index suffix to duplicates\n ctx.output.args.forEach((arg, index) => {\n const found = ctx.output.args.findIndex(a => a.name === arg.name);\n if (\n (found !== -1 && found !== index) ||\n ctx.output.segments.some(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment) === arg.name\n )\n ) {\n arg.name += `_${\n ctx.output.segments.filter(\n segment =>\n isDynamicPathSegment(segment) &&\n getDynamicPathSegmentName(segment).replace(/_\\d+$/, \"\") === arg.name\n ).length +\n ctx.output.args.filter(a => a.name.replace(/_\\d+$/, \"\") === arg.name)\n .length\n }`;\n arg.env = arg.name\n ? arg.env || arg.env === false\n ? arg.env\n : ctx.input.context.config.autoAssignEnv\n ? constantCase(arg.name)\n : false\n : false;\n }\n });\n\n applyDefaults(ctx);\n\n if (ctx.input.context.env) {\n if (isSetObject(ctx.output.options)) {\n Object.values(ctx.output.options)\n .filter(option => Boolean(option.env))\n .forEach(option => {\n ctx.input.context.env.types.env.addProperty({\n name: option.env as string,\n optional: option.optional ? true : undefined,\n description: option.description,\n visibility: ReflectionVisibility.public,\n type: extractType(option),\n default: option.default,\n tags: {\n title: option.title,\n alias: option.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n });\n });\n }\n\n ctx.output.args\n .filter(arg => Boolean(arg.env))\n .forEach(arg =>\n ctx.input.context.env.types.env.addProperty({\n name: arg.env as string,\n optional: arg.optional ? true : undefined,\n description: arg.description,\n visibility: ReflectionVisibility.public,\n type: extractType(arg),\n default: arg.default,\n tags: {\n alias: arg.alias\n .filter(alias => alias.length > 1)\n .map(alias => constantCase(alias)),\n domain: \"cli\"\n }\n })\n );\n }\n\n await Promise.all(\n ctx.input.context.inputs\n .filter(\n input =>\n input.segments.filter(segment => !isDynamicPathSegment(segment))\n .length ===\n ctx.input.command.segments.filter(\n segment => !isDynamicPathSegment(segment)\n ).length +\n 1 &&\n input.segments\n .slice(0, ctx.input.command.segments.length)\n .every(\n (value, index) => value === ctx.input.command.segments[index]\n )\n )\n .map(async input => {\n ctx.output.children[input.name] = await resolve<TContext>({\n context: ctx.input.context,\n command: input,\n parent: ctx.output\n });\n })\n );\n\n return ctx.output;\n}\n\n/**\n * Resolves a command tree from the given resolver input.\n *\n * @param input - The resolver input containing the context, command, and optional parent command tree.\n * @returns A promise that resolves to the resolved command tree.\n */\nexport async function resolve<TContext extends Context = Context>(\n input: ResolverInput<TContext>\n): Promise<CommandTree> {\n const ctx = await initialize<TContext>(input);\n\n if (!ctx.output.isVirtual) {\n await resolveFromExports(ctx);\n resolveFromBytecode(ctx);\n } else {\n resolveVirtualCommand(ctx);\n }\n\n return postprocess(ctx);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,SAAS,aAAa,IAAI,MAAM;;AAE9B,QAAO;;AA+BT,eAAE,WAAiB,OAAA;CACjB,MAAA,EACA,SACA,SACA,WACI;CACN,MAAO,QAAO,QAAA,SAAiB,GAAA,QAAa,QAAQ,GAAG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