depflow 3.0.0-dev.10 → 3.0.0-dev.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -43
- package/dist/builder/Builder.d.ts +279 -0
- package/dist/builder/Builder.js +391 -0
- package/dist/builder/Builder.js.map +1 -0
- package/dist/cli/CLI.d.ts +157 -0
- package/dist/cli/CLI.js +214 -0
- package/dist/cli/CLI.js.map +1 -0
- package/dist/cli/DepFLowCLI.d.ts +93 -0
- package/dist/cli/DepFLowCLI.js +413 -0
- package/dist/cli/DepFLowCLI.js.map +1 -0
- package/dist/cli/Flags.d.ts +106 -0
- package/dist/cli/Flags.js +125 -0
- package/dist/cli/Flags.js.map +1 -0
- package/dist/cli/bin.js +68 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/config/Config.d.ts +690 -0
- package/dist/config/Config.js +45 -0
- package/dist/config/Config.js.map +1 -0
- package/dist/config/ImportMap.d.ts +60 -0
- package/dist/config/ImportMap.js +66 -0
- package/dist/config/ImportMap.js.map +1 -0
- package/dist/config/JsonSchema.d.ts +12 -0
- package/dist/config/JsonSchema.js +26 -0
- package/dist/config/JsonSchema.js.map +1 -0
- package/dist/config/Settings.d.ts +201 -0
- package/dist/config/Settings.js +191 -0
- package/dist/config/Settings.js.map +1 -0
- package/dist/config/TSConfig.d.ts +73 -0
- package/dist/config/TSConfig.js +73 -0
- package/dist/config/TSConfig.js.map +1 -0
- package/dist/config/codecs/JsonCodec.d.ts +30 -0
- package/dist/config/codecs/JsonCodec.js +31 -0
- package/dist/config/codecs/JsonCodec.js.map +1 -0
- package/dist/config/codecs/YamlCodec.d.ts +62 -0
- package/dist/config/codecs/YamlCodec.js +89 -0
- package/dist/config/codecs/YamlCodec.js.map +1 -0
- package/dist/dependency/DepUtils.d.ts +50 -0
- package/dist/dependency/DepUtils.js +71 -0
- package/dist/dependency/DepUtils.js.map +1 -0
- package/dist/dependency/Dependency.d.ts +81 -0
- package/dist/dependency/Dependency.js +71 -0
- package/dist/dependency/Dependency.js.map +1 -0
- package/dist/dependency/Git.d.ts +75 -0
- package/dist/dependency/Git.js +97 -0
- package/dist/dependency/Git.js.map +1 -0
- package/dist/dependency/GitDependency.d.ts +30 -0
- package/dist/dependency/GitDependency.js +79 -0
- package/dist/dependency/GitDependency.js.map +1 -0
- package/dist/dependency/NpmDependency.d.ts +27 -0
- package/dist/dependency/NpmDependency.js +91 -0
- package/dist/dependency/NpmDependency.js.map +1 -0
- package/{build/support/PathResolver → dist/resolve}/AliasCompiler.d.ts +18 -5
- package/{build/support/PathResolver → dist/resolve}/AliasCompiler.js +31 -9
- package/dist/resolve/AliasCompiler.js.map +1 -0
- package/{build/support/PathResolver → dist/resolve}/PathResolver.d.ts +25 -8
- package/dist/resolve/PathResolver.js +133 -0
- package/dist/resolve/PathResolver.js.map +1 -0
- package/dist/resolve/PathRewriter.d.ts +24 -0
- package/{build/support/PathResolver → dist/resolve}/PathRewriter.js +21 -11
- package/dist/resolve/PathRewriter.js.map +1 -0
- package/{build → dist}/schema/Config/Builder.d.ts +114 -49
- package/dist/schema/Config/Builder.js +78 -0
- package/dist/schema/Config/Builder.js.map +1 -0
- package/{build → dist}/schema/Config/Config.d.ts +169 -78
- package/dist/schema/Config/Config.js +62 -0
- package/dist/schema/Config/Config.js.map +1 -0
- package/{build → dist}/schema/Config/Dependency.d.ts +219 -89
- package/dist/schema/Config/Dependency.js +80 -0
- package/dist/schema/Config/Dependency.js.map +1 -0
- package/{build → dist}/schema/Config/Extractor.d.ts +41 -17
- package/dist/schema/Config/Extractor.js +43 -0
- package/dist/schema/Config/Extractor.js.map +1 -0
- package/{build → dist}/schema/Config/Resolver.d.ts +25 -8
- package/dist/schema/Config/Resolver.js +43 -0
- package/dist/schema/Config/Resolver.js.map +1 -0
- package/{build → dist}/schema/Config/Transform.d.ts +22 -5
- package/dist/schema/Config/Transform.js +51 -0
- package/dist/schema/Config/Transform.js.map +1 -0
- package/dist/schema/Defaults.d.ts +20 -0
- package/dist/schema/Defaults.js +24 -0
- package/dist/schema/Defaults.js.map +1 -0
- package/dist/schema/ImportMap.d.ts +30 -0
- package/dist/schema/ImportMap.js +28 -0
- package/dist/schema/ImportMap.js.map +1 -0
- package/{build → dist}/schema/TSConfig.d.ts +23 -9
- package/dist/schema/TSConfig.js +39 -0
- package/dist/schema/TSConfig.js.map +1 -0
- package/{build → dist}/schema/schema.d.ts +11 -2
- package/{build → dist}/schema/schema.js +11 -2
- package/dist/schema/schema.js.map +1 -0
- package/dist/task/Command.d.ts +287 -0
- package/dist/task/Command.js +404 -0
- package/dist/task/Command.js.map +1 -0
- package/dist/task/Group.d.ts +15 -0
- package/dist/task/Group.js +29 -0
- package/dist/task/Group.js.map +1 -0
- package/dist/task/OutputPolicy.d.ts +262 -0
- package/dist/task/OutputPolicy.js +364 -0
- package/dist/task/OutputPolicy.js.map +1 -0
- package/dist/task/Task.d.ts +210 -0
- package/dist/task/Task.js +312 -0
- package/dist/task/Task.js.map +1 -0
- package/package.json +13 -10
- package/.gitignore +0 -7
- package/build/cli/DepFLowCLI.d.ts +0 -16
- package/build/cli/DepFLowCLI.js +0 -254
- package/build/cli/DepFLowCLI.js.map +0 -1
- package/build/cli/bin.js +0 -38
- package/build/cli/bin.js.map +0 -1
- package/build/config/Config.d.ts +0 -28
- package/build/config/Config.js +0 -46
- package/build/config/Config.js.map +0 -1
- package/build/config/ImportMap.d.ts +0 -51
- package/build/config/ImportMap.js +0 -97
- package/build/config/ImportMap.js.map +0 -1
- package/build/config/TSConfig.d.ts +0 -54
- package/build/config/TSConfig.js +0 -104
- package/build/config/TSConfig.js.map +0 -1
- package/build/schema/Config/Builder.js +0 -48
- package/build/schema/Config/Builder.js.map +0 -1
- package/build/schema/Config/Config.js +0 -20
- package/build/schema/Config/Config.js.map +0 -1
- package/build/schema/Config/Dependency.js +0 -25
- package/build/schema/Config/Dependency.js.map +0 -1
- package/build/schema/Config/Extractor.js +0 -25
- package/build/schema/Config/Extractor.js.map +0 -1
- package/build/schema/Config/Resolver.js +0 -25
- package/build/schema/Config/Resolver.js.map +0 -1
- package/build/schema/Config/Transform.js +0 -27
- package/build/schema/Config/Transform.js.map +0 -1
- package/build/schema/ImportMap.d.ts +0 -22
- package/build/schema/ImportMap.js +0 -12
- package/build/schema/ImportMap.js.map +0 -1
- package/build/schema/TSConfig.js +0 -19
- package/build/schema/TSConfig.js.map +0 -1
- package/build/schema/schema.js.map +0 -1
- package/build/support/Builder/Builder.d.ts +0 -46
- package/build/support/Builder/Builder.js +0 -116
- package/build/support/Builder/Builder.js.map +0 -1
- package/build/support/Dependency/Dependency.d.ts +0 -38
- package/build/support/Dependency/Dependency.js +0 -14
- package/build/support/Dependency/Dependency.js.map +0 -1
- package/build/support/Dependency/GitDependency.d.ts +0 -20
- package/build/support/Dependency/GitDependency.js +0 -67
- package/build/support/Dependency/GitDependency.js.map +0 -1
- package/build/support/Dependency/NpmDependency.d.ts +0 -18
- package/build/support/Dependency/NpmDependency.js +0 -65
- package/build/support/Dependency/NpmDependency.js.map +0 -1
- package/build/support/Git.d.ts +0 -53
- package/build/support/Git.js +0 -86
- package/build/support/Git.js.map +0 -1
- package/build/support/PathResolver/AliasCompiler.js.map +0 -1
- package/build/support/PathResolver/PathResolver.js +0 -105
- package/build/support/PathResolver/PathResolver.js.map +0 -1
- package/build/support/PathResolver/PathRewriter.d.ts +0 -18
- package/build/support/PathResolver/PathRewriter.js.map +0 -1
- package/build/support/PathResolver/Utils.d.ts +0 -36
- package/build/support/PathResolver/Utils.js +0 -45
- package/build/support/PathResolver/Utils.js.map +0 -1
- package/build/support/Task/Command.d.ts +0 -49
- package/build/support/Task/Command.js +0 -100
- package/build/support/Task/Command.js.map +0 -1
- package/build/support/Task/Task.d.ts +0 -84
- package/build/support/Task/Task.js +0 -145
- package/build/support/Task/Task.js.map +0 -1
- package/build/support/Utils.d.ts +0 -40
- package/build/support/Utils.js +0 -138
- package/build/support/Utils.js.map +0 -1
- package/build/support/Validator.d.ts +0 -22
- package/build/support/Validator.js +0 -28
- package/build/support/Validator.js.map +0 -1
- /package/{build → dist}/cli/bin.d.ts +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export class Flags {
|
|
2
|
+
/** The declared flags, kept at their declared type so the parsed values are inferred from them. */
|
|
3
|
+
declaration;
|
|
4
|
+
/** Maps every accepted name, canonical or alias, to the name of the flag declaring it. */
|
|
5
|
+
names;
|
|
6
|
+
/**
|
|
7
|
+
* Declares the flags accepted by a command line.
|
|
8
|
+
* @param declaration - The declared flags, keyed by the name each one is declared under.
|
|
9
|
+
* @throws { Error } When a name is declared or aliased twice, or when an alias carries a dash prefix.
|
|
10
|
+
*/
|
|
11
|
+
constructor(declaration) {
|
|
12
|
+
this.declaration = declaration;
|
|
13
|
+
this.names = Flags.index(declaration);
|
|
14
|
+
}
|
|
15
|
+
/** The values a parsed command line carries when a flag is absent, taken from the declared defaults. **/
|
|
16
|
+
get defaults() {
|
|
17
|
+
const values = {};
|
|
18
|
+
for (const [name, flag] of Object.entries(this.declaration)) {
|
|
19
|
+
if ('default' in flag)
|
|
20
|
+
values[name] = flag.default;
|
|
21
|
+
}
|
|
22
|
+
return values;
|
|
23
|
+
}
|
|
24
|
+
/** The values parsed from a command line. Type-only: accessing it at runtime throws. **/
|
|
25
|
+
get infer() { throw new Error('Flags.infer is type-only.'); }
|
|
26
|
+
/**
|
|
27
|
+
* Extracts the positional arguments and the flag values of a command line.
|
|
28
|
+
* @param args - The command-line arguments.
|
|
29
|
+
* @returns The positional arguments and the values of the declared flags.
|
|
30
|
+
* @throws { Error } When a flag is not declared, or when a boolean flag carries a value other than "true" or "false".
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* A flag is the whole token, so short clusters are not expanded: `-abc` is the single flag `-abc`.
|
|
34
|
+
* Names are matched without their dash prefix, so `-f` and `--flow` reach the same declaration.
|
|
35
|
+
* A boolean flag never consumes the following argument and only accepts `=true` or `=false` inline.
|
|
36
|
+
* A value flag takes the following argument as its value when that argument is not a flag; when it is,
|
|
37
|
+
* the value has to be written inline as `--flag=value`. The `--` terminator moves every remaining token
|
|
38
|
+
* to the positional arguments, and the last occurrence of a flag wins.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const options = new Flags({
|
|
43
|
+
* flow: { type: 'string', default: 'depflow.yml', aliases: [ 'f' ] },
|
|
44
|
+
* cdn: { type: 'boolean', default: false }
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* const { args, flags } = options.parse([ '-f', 'depflow.yml', 'install', '--cdn' ]);
|
|
48
|
+
* // args → [ 'install' ]
|
|
49
|
+
* // flags → { flow: 'depflow.yml', cdn: true }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
parse(args) {
|
|
53
|
+
const positionals = [];
|
|
54
|
+
const values = {};
|
|
55
|
+
let parsing = true;
|
|
56
|
+
let index = 0;
|
|
57
|
+
while (parsing && index < args.length) {
|
|
58
|
+
const arg = args[index++];
|
|
59
|
+
if (arg === '--') {
|
|
60
|
+
parsing = false;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!Flags.isFlag(arg)) {
|
|
64
|
+
positionals.push(arg);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const separator = arg.indexOf('=');
|
|
68
|
+
const name = this.resolve(separator < 0 ? arg : arg.slice(0, separator));
|
|
69
|
+
if (name === undefined)
|
|
70
|
+
throw new Error(`Unknown flag: ${arg}`);
|
|
71
|
+
if (this.isBoolean(name)) {
|
|
72
|
+
const value = separator < 0 ? 'true' : arg.slice(separator + 1);
|
|
73
|
+
if (value !== 'true' && value !== 'false')
|
|
74
|
+
throw new Error(`Invalid boolean value: ${arg}`);
|
|
75
|
+
values[name] = value === 'true';
|
|
76
|
+
}
|
|
77
|
+
else if (separator >= 0)
|
|
78
|
+
values[name] = arg.slice(separator + 1);
|
|
79
|
+
else if (index < args.length && !Flags.isFlag(args[index]))
|
|
80
|
+
values[name] = args[index++];
|
|
81
|
+
}
|
|
82
|
+
while (index < args.length)
|
|
83
|
+
positionals.push(args[index++]);
|
|
84
|
+
return { args: positionals, flags: { ...this.defaults, ...values } };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resolves the token of a flag to the name of the flag declaring it.
|
|
88
|
+
* @param token - The token of the flag, without its inline value.
|
|
89
|
+
* @returns The name the flag is declared under, or `undefined` when no declaration accepts the token.
|
|
90
|
+
*/
|
|
91
|
+
resolve(token) {
|
|
92
|
+
return this.names.get(token.replace(/^--?/, ''));
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Whether a declared flag carries a boolean value, meaning it never consumes the following argument.
|
|
96
|
+
* @param name - The name the flag is declared under.
|
|
97
|
+
* @returns Whether the flag is declared as a boolean.
|
|
98
|
+
*/
|
|
99
|
+
isBoolean(name) {
|
|
100
|
+
return this.declaration[name].type === 'boolean';
|
|
101
|
+
}
|
|
102
|
+
/** Whether an argument is a flag token, meaning a dash prefix longer than a single dash. **/
|
|
103
|
+
static isFlag(arg) { return arg.length > 1 && arg.startsWith('-'); }
|
|
104
|
+
/**
|
|
105
|
+
* Builds the lookup of every accepted name, canonical or alias, to the name of the flag declaring it.
|
|
106
|
+
* @param declaration - The declared flags.
|
|
107
|
+
* @returns The lookup of accepted names to declared names.
|
|
108
|
+
* @throws { Error } When a name is declared or aliased twice, or when an alias carries a dash prefix.
|
|
109
|
+
*/
|
|
110
|
+
static index(declaration) {
|
|
111
|
+
const names = new Map();
|
|
112
|
+
for (const [name, flag] of Object.entries(declaration)) {
|
|
113
|
+
for (const alias of [name, ...flag.aliases ?? []]) {
|
|
114
|
+
if (alias.startsWith('-'))
|
|
115
|
+
throw new Error(`Flag name must not carry a dash prefix: ${alias}`);
|
|
116
|
+
if (names.has(alias))
|
|
117
|
+
throw new Error(`Duplicated flag name: ${alias}`);
|
|
118
|
+
names.set(alias, name);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return names;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export default Flags;
|
|
125
|
+
//# sourceMappingURL=Flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Flags.js","sourceRoot":"","sources":["../../src/cli/Flags.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,KAAK;IACd,mGAAmG;IACnF,WAAW,CAAI;IAE/B,0FAA0F;IACzE,KAAK,CAAsB;IAE5C;;;;OAIG;IACH,YAAmB,WAAc;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;IAED,yGAAyG;IACzG,IAAW,QAAQ;QACf,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC1D,IAAI,SAAS,IAAI,IAAI;gBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;QACvD,CAAC;QACD,OAAO,MAAyB,CAAC;IACrC,CAAC;IAED,yFAAyF;IACzF,IAAW,KAAK,KAAsB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC;IAErF;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,KAAK,CAAC,IAAuB;QAChC,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,MAAM,MAAM,GAA4B,EAAE,CAAC;QAC3C,IAAI,OAAO,GAAG,IAAI,CAAC;QACnB,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,OAAO,OAAO,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACpC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;YAC1B,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CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;gBACxE,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC3B,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAsCD,eAAe,KAAK,CAAC"}
|
package/dist/cli/bin.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @author NetFeez <netfeez.dev@gmail.com>.
|
|
4
|
+
* @description Command-line entry point: parses arguments and dispatches the invoked command to the CLI.
|
|
5
|
+
* @license Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
import Logger from "@netfeez/vterm";
|
|
8
|
+
import DepFlowCLI, { options } from "./DepFLowCLI.js";
|
|
9
|
+
const skip = 2;
|
|
10
|
+
const [commandName, ...argsList] = process.argv.slice(skip);
|
|
11
|
+
/**
|
|
12
|
+
* Reports a failure to the user and marks the process as failed.
|
|
13
|
+
*
|
|
14
|
+
* @remarks The failure is reported as one line through the logger, and not as a box painted with
|
|
15
|
+
* literals: the box was a second implementation of the decoration of vterm, it disappeared with
|
|
16
|
+
* `--decorate=false` while this one did not, and the summary it printed is not a per-command diagnostic,
|
|
17
|
+
* so the policy never printed it and nothing was duplicated.
|
|
18
|
+
*
|
|
19
|
+
* @remarks The channel is the one of the console interface, which every mode leaves visible: a verdict
|
|
20
|
+
* that fails while the screen says nothing at all is a verdict nobody can see, and the exit status is
|
|
21
|
+
* the signal of a user who is not looking.
|
|
22
|
+
*
|
|
23
|
+
* @remarks The status is marked with `process.exitCode` and not forced with `process.exit`, and this is
|
|
24
|
+
* the only way the evidence of a failing run reaches the `.vlog`: `vterm` feeds that file from a queue
|
|
25
|
+
* it flushes without anyone awaiting it, and a forced exit kills the process while the complete buffer
|
|
26
|
+
* of the commands is still in it. The status a user observes is the same one in both, because the run
|
|
27
|
+
* is already over by the time this is called; what changes is whether the transcript survives it.
|
|
28
|
+
*
|
|
29
|
+
* @param out - The logger or engine the failure is reported to.
|
|
30
|
+
* @param error - The failure, either an error or a message.
|
|
31
|
+
* @returns void
|
|
32
|
+
*/
|
|
33
|
+
function fail(out, error) {
|
|
34
|
+
out.error(`&C1${error?.message || error}`);
|
|
35
|
+
process.exitCode = 1;
|
|
36
|
+
}
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = options.parse(argsList);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
fail(new Logger(), error);
|
|
43
|
+
}
|
|
44
|
+
// A failed parse leaves nothing to dispatch: the invocation was never understood, so there is no command
|
|
45
|
+
// to run and no CLI to run it with. The process still ends here, with the status `fail` marked.
|
|
46
|
+
if (parsed !== undefined) {
|
|
47
|
+
const { args, flags } = parsed;
|
|
48
|
+
const cli = new DepFlowCLI(flags.flow);
|
|
49
|
+
try {
|
|
50
|
+
if (commandName !== null) {
|
|
51
|
+
const command = cli.getCommand(commandName);
|
|
52
|
+
if (command) {
|
|
53
|
+
const exec = command.exec;
|
|
54
|
+
await exec.call(cli, commandName, args, flags);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
cli.out.error(`Unknown command: ${commandName}`);
|
|
58
|
+
cli.getCommand('help')?.exec.call(cli, 'help', []);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else
|
|
62
|
+
cli.start();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
fail(cli.out, error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=bin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":";AACA;;;;GAIG;AACH,OAAO,MAAuB,MAAM,gBAAgB,CAAC;AAErD,OAAO,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGtD,MAAM,IAAI,GAAG,CAA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