routess 1.122.4
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 +36 -0
- package/dist/index.js +4709 -0
- package/package.json +17 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4709 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
13
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod != null && typeof mod === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
if (canCache)
|
|
30
|
+
cache.set(mod, to);
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
34
|
+
var __returnValue = (v) => v;
|
|
35
|
+
function __exportSetter(name, newValue) {
|
|
36
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
37
|
+
}
|
|
38
|
+
var __export = (target, all) => {
|
|
39
|
+
for (var name in all)
|
|
40
|
+
__defProp(target, name, {
|
|
41
|
+
get: all[name],
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
set: __exportSetter.bind(all, name)
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
48
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
49
|
+
|
|
50
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/lib/error.js
|
|
51
|
+
var require_error = __commonJS((exports) => {
|
|
52
|
+
class CommanderError extends Error {
|
|
53
|
+
constructor(exitCode, code, message) {
|
|
54
|
+
super(message);
|
|
55
|
+
Error.captureStackTrace(this, this.constructor);
|
|
56
|
+
this.name = this.constructor.name;
|
|
57
|
+
this.code = code;
|
|
58
|
+
this.exitCode = exitCode;
|
|
59
|
+
this.nestedError = undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class InvalidArgumentError extends CommanderError {
|
|
64
|
+
constructor(message) {
|
|
65
|
+
super(1, "commander.invalidArgument", message);
|
|
66
|
+
Error.captureStackTrace(this, this.constructor);
|
|
67
|
+
this.name = this.constructor.name;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.CommanderError = CommanderError;
|
|
71
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/lib/argument.js
|
|
75
|
+
var require_argument = __commonJS((exports) => {
|
|
76
|
+
var { InvalidArgumentError } = require_error();
|
|
77
|
+
|
|
78
|
+
class Argument {
|
|
79
|
+
constructor(name, description) {
|
|
80
|
+
this.description = description || "";
|
|
81
|
+
this.variadic = false;
|
|
82
|
+
this.parseArg = undefined;
|
|
83
|
+
this.defaultValue = undefined;
|
|
84
|
+
this.defaultValueDescription = undefined;
|
|
85
|
+
this.argChoices = undefined;
|
|
86
|
+
switch (name[0]) {
|
|
87
|
+
case "<":
|
|
88
|
+
this.required = true;
|
|
89
|
+
this._name = name.slice(1, -1);
|
|
90
|
+
break;
|
|
91
|
+
case "[":
|
|
92
|
+
this.required = false;
|
|
93
|
+
this._name = name.slice(1, -1);
|
|
94
|
+
break;
|
|
95
|
+
default:
|
|
96
|
+
this.required = true;
|
|
97
|
+
this._name = name;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (this._name.length > 3 && this._name.slice(-3) === "...") {
|
|
101
|
+
this.variadic = true;
|
|
102
|
+
this._name = this._name.slice(0, -3);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
name() {
|
|
106
|
+
return this._name;
|
|
107
|
+
}
|
|
108
|
+
_concatValue(value, previous) {
|
|
109
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
110
|
+
return [value];
|
|
111
|
+
}
|
|
112
|
+
return previous.concat(value);
|
|
113
|
+
}
|
|
114
|
+
default(value, description) {
|
|
115
|
+
this.defaultValue = value;
|
|
116
|
+
this.defaultValueDescription = description;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
argParser(fn) {
|
|
120
|
+
this.parseArg = fn;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
choices(values) {
|
|
124
|
+
this.argChoices = values.slice();
|
|
125
|
+
this.parseArg = (arg, previous) => {
|
|
126
|
+
if (!this.argChoices.includes(arg)) {
|
|
127
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
128
|
+
}
|
|
129
|
+
if (this.variadic) {
|
|
130
|
+
return this._concatValue(arg, previous);
|
|
131
|
+
}
|
|
132
|
+
return arg;
|
|
133
|
+
};
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
argRequired() {
|
|
137
|
+
this.required = true;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
argOptional() {
|
|
141
|
+
this.required = false;
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function humanReadableArgName(arg) {
|
|
146
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
147
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
148
|
+
}
|
|
149
|
+
exports.Argument = Argument;
|
|
150
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/lib/help.js
|
|
154
|
+
var require_help = __commonJS((exports) => {
|
|
155
|
+
var { humanReadableArgName } = require_argument();
|
|
156
|
+
|
|
157
|
+
class Help {
|
|
158
|
+
constructor() {
|
|
159
|
+
this.helpWidth = undefined;
|
|
160
|
+
this.minWidthToWrap = 40;
|
|
161
|
+
this.sortSubcommands = false;
|
|
162
|
+
this.sortOptions = false;
|
|
163
|
+
this.showGlobalOptions = false;
|
|
164
|
+
}
|
|
165
|
+
prepareContext(contextOptions) {
|
|
166
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
167
|
+
}
|
|
168
|
+
visibleCommands(cmd) {
|
|
169
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
170
|
+
const helpCommand = cmd._getHelpCommand();
|
|
171
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
172
|
+
visibleCommands.push(helpCommand);
|
|
173
|
+
}
|
|
174
|
+
if (this.sortSubcommands) {
|
|
175
|
+
visibleCommands.sort((a, b) => {
|
|
176
|
+
return a.name().localeCompare(b.name());
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return visibleCommands;
|
|
180
|
+
}
|
|
181
|
+
compareOptions(a, b) {
|
|
182
|
+
const getSortKey = (option) => {
|
|
183
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
184
|
+
};
|
|
185
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
186
|
+
}
|
|
187
|
+
visibleOptions(cmd) {
|
|
188
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
189
|
+
const helpOption = cmd._getHelpOption();
|
|
190
|
+
if (helpOption && !helpOption.hidden) {
|
|
191
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
192
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
193
|
+
if (!removeShort && !removeLong) {
|
|
194
|
+
visibleOptions.push(helpOption);
|
|
195
|
+
} else if (helpOption.long && !removeLong) {
|
|
196
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
197
|
+
} else if (helpOption.short && !removeShort) {
|
|
198
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (this.sortOptions) {
|
|
202
|
+
visibleOptions.sort(this.compareOptions);
|
|
203
|
+
}
|
|
204
|
+
return visibleOptions;
|
|
205
|
+
}
|
|
206
|
+
visibleGlobalOptions(cmd) {
|
|
207
|
+
if (!this.showGlobalOptions)
|
|
208
|
+
return [];
|
|
209
|
+
const globalOptions = [];
|
|
210
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
211
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
212
|
+
globalOptions.push(...visibleOptions);
|
|
213
|
+
}
|
|
214
|
+
if (this.sortOptions) {
|
|
215
|
+
globalOptions.sort(this.compareOptions);
|
|
216
|
+
}
|
|
217
|
+
return globalOptions;
|
|
218
|
+
}
|
|
219
|
+
visibleArguments(cmd) {
|
|
220
|
+
if (cmd._argsDescription) {
|
|
221
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
222
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
226
|
+
return cmd.registeredArguments;
|
|
227
|
+
}
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
subcommandTerm(cmd) {
|
|
231
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
232
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
233
|
+
}
|
|
234
|
+
optionTerm(option) {
|
|
235
|
+
return option.flags;
|
|
236
|
+
}
|
|
237
|
+
argumentTerm(argument) {
|
|
238
|
+
return argument.name();
|
|
239
|
+
}
|
|
240
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
241
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
242
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
243
|
+
}, 0);
|
|
244
|
+
}
|
|
245
|
+
longestOptionTermLength(cmd, helper) {
|
|
246
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
247
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
248
|
+
}, 0);
|
|
249
|
+
}
|
|
250
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
251
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
252
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
253
|
+
}, 0);
|
|
254
|
+
}
|
|
255
|
+
longestArgumentTermLength(cmd, helper) {
|
|
256
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
257
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
258
|
+
}, 0);
|
|
259
|
+
}
|
|
260
|
+
commandUsage(cmd) {
|
|
261
|
+
let cmdName = cmd._name;
|
|
262
|
+
if (cmd._aliases[0]) {
|
|
263
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
264
|
+
}
|
|
265
|
+
let ancestorCmdNames = "";
|
|
266
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
267
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
268
|
+
}
|
|
269
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
270
|
+
}
|
|
271
|
+
commandDescription(cmd) {
|
|
272
|
+
return cmd.description();
|
|
273
|
+
}
|
|
274
|
+
subcommandDescription(cmd) {
|
|
275
|
+
return cmd.summary() || cmd.description();
|
|
276
|
+
}
|
|
277
|
+
optionDescription(option) {
|
|
278
|
+
const extraInfo = [];
|
|
279
|
+
if (option.argChoices) {
|
|
280
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
281
|
+
}
|
|
282
|
+
if (option.defaultValue !== undefined) {
|
|
283
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
284
|
+
if (showDefault) {
|
|
285
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
289
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
290
|
+
}
|
|
291
|
+
if (option.envVar !== undefined) {
|
|
292
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
293
|
+
}
|
|
294
|
+
if (extraInfo.length > 0) {
|
|
295
|
+
return `${option.description} (${extraInfo.join(", ")})`;
|
|
296
|
+
}
|
|
297
|
+
return option.description;
|
|
298
|
+
}
|
|
299
|
+
argumentDescription(argument) {
|
|
300
|
+
const extraInfo = [];
|
|
301
|
+
if (argument.argChoices) {
|
|
302
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
303
|
+
}
|
|
304
|
+
if (argument.defaultValue !== undefined) {
|
|
305
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
306
|
+
}
|
|
307
|
+
if (extraInfo.length > 0) {
|
|
308
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
309
|
+
if (argument.description) {
|
|
310
|
+
return `${argument.description} ${extraDescription}`;
|
|
311
|
+
}
|
|
312
|
+
return extraDescription;
|
|
313
|
+
}
|
|
314
|
+
return argument.description;
|
|
315
|
+
}
|
|
316
|
+
formatHelp(cmd, helper) {
|
|
317
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
318
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
319
|
+
function callFormatItem(term, description) {
|
|
320
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
321
|
+
}
|
|
322
|
+
let output = [
|
|
323
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
324
|
+
""
|
|
325
|
+
];
|
|
326
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
327
|
+
if (commandDescription.length > 0) {
|
|
328
|
+
output = output.concat([
|
|
329
|
+
helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
|
|
330
|
+
""
|
|
331
|
+
]);
|
|
332
|
+
}
|
|
333
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
334
|
+
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
335
|
+
});
|
|
336
|
+
if (argumentList.length > 0) {
|
|
337
|
+
output = output.concat([
|
|
338
|
+
helper.styleTitle("Arguments:"),
|
|
339
|
+
...argumentList,
|
|
340
|
+
""
|
|
341
|
+
]);
|
|
342
|
+
}
|
|
343
|
+
const optionList = helper.visibleOptions(cmd).map((option) => {
|
|
344
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
345
|
+
});
|
|
346
|
+
if (optionList.length > 0) {
|
|
347
|
+
output = output.concat([
|
|
348
|
+
helper.styleTitle("Options:"),
|
|
349
|
+
...optionList,
|
|
350
|
+
""
|
|
351
|
+
]);
|
|
352
|
+
}
|
|
353
|
+
if (helper.showGlobalOptions) {
|
|
354
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
355
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
356
|
+
});
|
|
357
|
+
if (globalOptionList.length > 0) {
|
|
358
|
+
output = output.concat([
|
|
359
|
+
helper.styleTitle("Global Options:"),
|
|
360
|
+
...globalOptionList,
|
|
361
|
+
""
|
|
362
|
+
]);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const commandList = helper.visibleCommands(cmd).map((cmd2) => {
|
|
366
|
+
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(cmd2)), helper.styleSubcommandDescription(helper.subcommandDescription(cmd2)));
|
|
367
|
+
});
|
|
368
|
+
if (commandList.length > 0) {
|
|
369
|
+
output = output.concat([
|
|
370
|
+
helper.styleTitle("Commands:"),
|
|
371
|
+
...commandList,
|
|
372
|
+
""
|
|
373
|
+
]);
|
|
374
|
+
}
|
|
375
|
+
return output.join(`
|
|
376
|
+
`);
|
|
377
|
+
}
|
|
378
|
+
displayWidth(str) {
|
|
379
|
+
return stripColor(str).length;
|
|
380
|
+
}
|
|
381
|
+
styleTitle(str) {
|
|
382
|
+
return str;
|
|
383
|
+
}
|
|
384
|
+
styleUsage(str) {
|
|
385
|
+
return str.split(" ").map((word) => {
|
|
386
|
+
if (word === "[options]")
|
|
387
|
+
return this.styleOptionText(word);
|
|
388
|
+
if (word === "[command]")
|
|
389
|
+
return this.styleSubcommandText(word);
|
|
390
|
+
if (word[0] === "[" || word[0] === "<")
|
|
391
|
+
return this.styleArgumentText(word);
|
|
392
|
+
return this.styleCommandText(word);
|
|
393
|
+
}).join(" ");
|
|
394
|
+
}
|
|
395
|
+
styleCommandDescription(str) {
|
|
396
|
+
return this.styleDescriptionText(str);
|
|
397
|
+
}
|
|
398
|
+
styleOptionDescription(str) {
|
|
399
|
+
return this.styleDescriptionText(str);
|
|
400
|
+
}
|
|
401
|
+
styleSubcommandDescription(str) {
|
|
402
|
+
return this.styleDescriptionText(str);
|
|
403
|
+
}
|
|
404
|
+
styleArgumentDescription(str) {
|
|
405
|
+
return this.styleDescriptionText(str);
|
|
406
|
+
}
|
|
407
|
+
styleDescriptionText(str) {
|
|
408
|
+
return str;
|
|
409
|
+
}
|
|
410
|
+
styleOptionTerm(str) {
|
|
411
|
+
return this.styleOptionText(str);
|
|
412
|
+
}
|
|
413
|
+
styleSubcommandTerm(str) {
|
|
414
|
+
return str.split(" ").map((word) => {
|
|
415
|
+
if (word === "[options]")
|
|
416
|
+
return this.styleOptionText(word);
|
|
417
|
+
if (word[0] === "[" || word[0] === "<")
|
|
418
|
+
return this.styleArgumentText(word);
|
|
419
|
+
return this.styleSubcommandText(word);
|
|
420
|
+
}).join(" ");
|
|
421
|
+
}
|
|
422
|
+
styleArgumentTerm(str) {
|
|
423
|
+
return this.styleArgumentText(str);
|
|
424
|
+
}
|
|
425
|
+
styleOptionText(str) {
|
|
426
|
+
return str;
|
|
427
|
+
}
|
|
428
|
+
styleArgumentText(str) {
|
|
429
|
+
return str;
|
|
430
|
+
}
|
|
431
|
+
styleSubcommandText(str) {
|
|
432
|
+
return str;
|
|
433
|
+
}
|
|
434
|
+
styleCommandText(str) {
|
|
435
|
+
return str;
|
|
436
|
+
}
|
|
437
|
+
padWidth(cmd, helper) {
|
|
438
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
439
|
+
}
|
|
440
|
+
preformatted(str) {
|
|
441
|
+
return /\n[^\S\r\n]/.test(str);
|
|
442
|
+
}
|
|
443
|
+
formatItem(term, termWidth, description, helper) {
|
|
444
|
+
const itemIndent = 2;
|
|
445
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
446
|
+
if (!description)
|
|
447
|
+
return itemIndentStr + term;
|
|
448
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
449
|
+
const spacerWidth = 2;
|
|
450
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
451
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
452
|
+
let formattedDescription;
|
|
453
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
454
|
+
formattedDescription = description;
|
|
455
|
+
} else {
|
|
456
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
457
|
+
formattedDescription = wrappedDescription.replace(/\n/g, `
|
|
458
|
+
` + " ".repeat(termWidth + spacerWidth));
|
|
459
|
+
}
|
|
460
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
461
|
+
${itemIndentStr}`);
|
|
462
|
+
}
|
|
463
|
+
boxWrap(str, width) {
|
|
464
|
+
if (width < this.minWidthToWrap)
|
|
465
|
+
return str;
|
|
466
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
467
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
468
|
+
const wrappedLines = [];
|
|
469
|
+
rawLines.forEach((line) => {
|
|
470
|
+
const chunks = line.match(chunkPattern);
|
|
471
|
+
if (chunks === null) {
|
|
472
|
+
wrappedLines.push("");
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
let sumChunks = [chunks.shift()];
|
|
476
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
477
|
+
chunks.forEach((chunk) => {
|
|
478
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
479
|
+
if (sumWidth + visibleWidth <= width) {
|
|
480
|
+
sumChunks.push(chunk);
|
|
481
|
+
sumWidth += visibleWidth;
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
wrappedLines.push(sumChunks.join(""));
|
|
485
|
+
const nextChunk = chunk.trimStart();
|
|
486
|
+
sumChunks = [nextChunk];
|
|
487
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
488
|
+
});
|
|
489
|
+
wrappedLines.push(sumChunks.join(""));
|
|
490
|
+
});
|
|
491
|
+
return wrappedLines.join(`
|
|
492
|
+
`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function stripColor(str) {
|
|
496
|
+
const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
|
|
497
|
+
return str.replace(sgrPattern, "");
|
|
498
|
+
}
|
|
499
|
+
exports.Help = Help;
|
|
500
|
+
exports.stripColor = stripColor;
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/lib/option.js
|
|
504
|
+
var require_option = __commonJS((exports) => {
|
|
505
|
+
var { InvalidArgumentError } = require_error();
|
|
506
|
+
|
|
507
|
+
class Option {
|
|
508
|
+
constructor(flags, description) {
|
|
509
|
+
this.flags = flags;
|
|
510
|
+
this.description = description || "";
|
|
511
|
+
this.required = flags.includes("<");
|
|
512
|
+
this.optional = flags.includes("[");
|
|
513
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
514
|
+
this.mandatory = false;
|
|
515
|
+
const optionFlags = splitOptionFlags(flags);
|
|
516
|
+
this.short = optionFlags.shortFlag;
|
|
517
|
+
this.long = optionFlags.longFlag;
|
|
518
|
+
this.negate = false;
|
|
519
|
+
if (this.long) {
|
|
520
|
+
this.negate = this.long.startsWith("--no-");
|
|
521
|
+
}
|
|
522
|
+
this.defaultValue = undefined;
|
|
523
|
+
this.defaultValueDescription = undefined;
|
|
524
|
+
this.presetArg = undefined;
|
|
525
|
+
this.envVar = undefined;
|
|
526
|
+
this.parseArg = undefined;
|
|
527
|
+
this.hidden = false;
|
|
528
|
+
this.argChoices = undefined;
|
|
529
|
+
this.conflictsWith = [];
|
|
530
|
+
this.implied = undefined;
|
|
531
|
+
}
|
|
532
|
+
default(value, description) {
|
|
533
|
+
this.defaultValue = value;
|
|
534
|
+
this.defaultValueDescription = description;
|
|
535
|
+
return this;
|
|
536
|
+
}
|
|
537
|
+
preset(arg) {
|
|
538
|
+
this.presetArg = arg;
|
|
539
|
+
return this;
|
|
540
|
+
}
|
|
541
|
+
conflicts(names) {
|
|
542
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
543
|
+
return this;
|
|
544
|
+
}
|
|
545
|
+
implies(impliedOptionValues) {
|
|
546
|
+
let newImplied = impliedOptionValues;
|
|
547
|
+
if (typeof impliedOptionValues === "string") {
|
|
548
|
+
newImplied = { [impliedOptionValues]: true };
|
|
549
|
+
}
|
|
550
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
551
|
+
return this;
|
|
552
|
+
}
|
|
553
|
+
env(name) {
|
|
554
|
+
this.envVar = name;
|
|
555
|
+
return this;
|
|
556
|
+
}
|
|
557
|
+
argParser(fn) {
|
|
558
|
+
this.parseArg = fn;
|
|
559
|
+
return this;
|
|
560
|
+
}
|
|
561
|
+
makeOptionMandatory(mandatory = true) {
|
|
562
|
+
this.mandatory = !!mandatory;
|
|
563
|
+
return this;
|
|
564
|
+
}
|
|
565
|
+
hideHelp(hide = true) {
|
|
566
|
+
this.hidden = !!hide;
|
|
567
|
+
return this;
|
|
568
|
+
}
|
|
569
|
+
_concatValue(value, previous) {
|
|
570
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
571
|
+
return [value];
|
|
572
|
+
}
|
|
573
|
+
return previous.concat(value);
|
|
574
|
+
}
|
|
575
|
+
choices(values) {
|
|
576
|
+
this.argChoices = values.slice();
|
|
577
|
+
this.parseArg = (arg, previous) => {
|
|
578
|
+
if (!this.argChoices.includes(arg)) {
|
|
579
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
580
|
+
}
|
|
581
|
+
if (this.variadic) {
|
|
582
|
+
return this._concatValue(arg, previous);
|
|
583
|
+
}
|
|
584
|
+
return arg;
|
|
585
|
+
};
|
|
586
|
+
return this;
|
|
587
|
+
}
|
|
588
|
+
name() {
|
|
589
|
+
if (this.long) {
|
|
590
|
+
return this.long.replace(/^--/, "");
|
|
591
|
+
}
|
|
592
|
+
return this.short.replace(/^-/, "");
|
|
593
|
+
}
|
|
594
|
+
attributeName() {
|
|
595
|
+
if (this.negate) {
|
|
596
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
597
|
+
}
|
|
598
|
+
return camelcase(this.name());
|
|
599
|
+
}
|
|
600
|
+
is(arg) {
|
|
601
|
+
return this.short === arg || this.long === arg;
|
|
602
|
+
}
|
|
603
|
+
isBoolean() {
|
|
604
|
+
return !this.required && !this.optional && !this.negate;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
class DualOptions {
|
|
609
|
+
constructor(options) {
|
|
610
|
+
this.positiveOptions = new Map;
|
|
611
|
+
this.negativeOptions = new Map;
|
|
612
|
+
this.dualOptions = new Set;
|
|
613
|
+
options.forEach((option) => {
|
|
614
|
+
if (option.negate) {
|
|
615
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
616
|
+
} else {
|
|
617
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
this.negativeOptions.forEach((value, key) => {
|
|
621
|
+
if (this.positiveOptions.has(key)) {
|
|
622
|
+
this.dualOptions.add(key);
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
valueFromOption(value, option) {
|
|
627
|
+
const optionKey = option.attributeName();
|
|
628
|
+
if (!this.dualOptions.has(optionKey))
|
|
629
|
+
return true;
|
|
630
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
631
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
632
|
+
return option.negate === (negativeValue === value);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function camelcase(str) {
|
|
636
|
+
return str.split("-").reduce((str2, word) => {
|
|
637
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
function splitOptionFlags(flags) {
|
|
641
|
+
let shortFlag;
|
|
642
|
+
let longFlag;
|
|
643
|
+
const shortFlagExp = /^-[^-]$/;
|
|
644
|
+
const longFlagExp = /^--[^-]/;
|
|
645
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
646
|
+
if (shortFlagExp.test(flagParts[0]))
|
|
647
|
+
shortFlag = flagParts.shift();
|
|
648
|
+
if (longFlagExp.test(flagParts[0]))
|
|
649
|
+
longFlag = flagParts.shift();
|
|
650
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
651
|
+
shortFlag = flagParts.shift();
|
|
652
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
653
|
+
shortFlag = longFlag;
|
|
654
|
+
longFlag = flagParts.shift();
|
|
655
|
+
}
|
|
656
|
+
if (flagParts[0].startsWith("-")) {
|
|
657
|
+
const unsupportedFlag = flagParts[0];
|
|
658
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
659
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
660
|
+
throw new Error(`${baseError}
|
|
661
|
+
- a short flag is a single dash and a single character
|
|
662
|
+
- either use a single dash and a single character (for a short flag)
|
|
663
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
664
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
665
|
+
throw new Error(`${baseError}
|
|
666
|
+
- too many short flags`);
|
|
667
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
668
|
+
throw new Error(`${baseError}
|
|
669
|
+
- too many long flags`);
|
|
670
|
+
throw new Error(`${baseError}
|
|
671
|
+
- unrecognised flag format`);
|
|
672
|
+
}
|
|
673
|
+
if (shortFlag === undefined && longFlag === undefined)
|
|
674
|
+
throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
675
|
+
return { shortFlag, longFlag };
|
|
676
|
+
}
|
|
677
|
+
exports.Option = Option;
|
|
678
|
+
exports.DualOptions = DualOptions;
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/lib/suggestSimilar.js
|
|
682
|
+
var require_suggestSimilar = __commonJS((exports) => {
|
|
683
|
+
var maxDistance = 3;
|
|
684
|
+
function editDistance(a, b) {
|
|
685
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
686
|
+
return Math.max(a.length, b.length);
|
|
687
|
+
const d = [];
|
|
688
|
+
for (let i = 0;i <= a.length; i++) {
|
|
689
|
+
d[i] = [i];
|
|
690
|
+
}
|
|
691
|
+
for (let j = 0;j <= b.length; j++) {
|
|
692
|
+
d[0][j] = j;
|
|
693
|
+
}
|
|
694
|
+
for (let j = 1;j <= b.length; j++) {
|
|
695
|
+
for (let i = 1;i <= a.length; i++) {
|
|
696
|
+
let cost = 1;
|
|
697
|
+
if (a[i - 1] === b[j - 1]) {
|
|
698
|
+
cost = 0;
|
|
699
|
+
} else {
|
|
700
|
+
cost = 1;
|
|
701
|
+
}
|
|
702
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
703
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
704
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
return d[a.length][b.length];
|
|
709
|
+
}
|
|
710
|
+
function suggestSimilar(word, candidates) {
|
|
711
|
+
if (!candidates || candidates.length === 0)
|
|
712
|
+
return "";
|
|
713
|
+
candidates = Array.from(new Set(candidates));
|
|
714
|
+
const searchingOptions = word.startsWith("--");
|
|
715
|
+
if (searchingOptions) {
|
|
716
|
+
word = word.slice(2);
|
|
717
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
718
|
+
}
|
|
719
|
+
let similar = [];
|
|
720
|
+
let bestDistance = maxDistance;
|
|
721
|
+
const minSimilarity = 0.4;
|
|
722
|
+
candidates.forEach((candidate) => {
|
|
723
|
+
if (candidate.length <= 1)
|
|
724
|
+
return;
|
|
725
|
+
const distance = editDistance(word, candidate);
|
|
726
|
+
const length = Math.max(word.length, candidate.length);
|
|
727
|
+
const similarity = (length - distance) / length;
|
|
728
|
+
if (similarity > minSimilarity) {
|
|
729
|
+
if (distance < bestDistance) {
|
|
730
|
+
bestDistance = distance;
|
|
731
|
+
similar = [candidate];
|
|
732
|
+
} else if (distance === bestDistance) {
|
|
733
|
+
similar.push(candidate);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
738
|
+
if (searchingOptions) {
|
|
739
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
740
|
+
}
|
|
741
|
+
if (similar.length > 1) {
|
|
742
|
+
return `
|
|
743
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
744
|
+
}
|
|
745
|
+
if (similar.length === 1) {
|
|
746
|
+
return `
|
|
747
|
+
(Did you mean ${similar[0]}?)`;
|
|
748
|
+
}
|
|
749
|
+
return "";
|
|
750
|
+
}
|
|
751
|
+
exports.suggestSimilar = suggestSimilar;
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/lib/command.js
|
|
755
|
+
var require_command = __commonJS((exports) => {
|
|
756
|
+
var EventEmitter = __require("node:events").EventEmitter;
|
|
757
|
+
var childProcess = __require("node:child_process");
|
|
758
|
+
var path = __require("node:path");
|
|
759
|
+
var fs = __require("node:fs");
|
|
760
|
+
var process2 = __require("node:process");
|
|
761
|
+
var { Argument, humanReadableArgName } = require_argument();
|
|
762
|
+
var { CommanderError } = require_error();
|
|
763
|
+
var { Help, stripColor } = require_help();
|
|
764
|
+
var { Option, DualOptions } = require_option();
|
|
765
|
+
var { suggestSimilar } = require_suggestSimilar();
|
|
766
|
+
|
|
767
|
+
class Command extends EventEmitter {
|
|
768
|
+
constructor(name) {
|
|
769
|
+
super();
|
|
770
|
+
this.commands = [];
|
|
771
|
+
this.options = [];
|
|
772
|
+
this.parent = null;
|
|
773
|
+
this._allowUnknownOption = false;
|
|
774
|
+
this._allowExcessArguments = false;
|
|
775
|
+
this.registeredArguments = [];
|
|
776
|
+
this._args = this.registeredArguments;
|
|
777
|
+
this.args = [];
|
|
778
|
+
this.rawArgs = [];
|
|
779
|
+
this.processedArgs = [];
|
|
780
|
+
this._scriptPath = null;
|
|
781
|
+
this._name = name || "";
|
|
782
|
+
this._optionValues = {};
|
|
783
|
+
this._optionValueSources = {};
|
|
784
|
+
this._storeOptionsAsProperties = false;
|
|
785
|
+
this._actionHandler = null;
|
|
786
|
+
this._executableHandler = false;
|
|
787
|
+
this._executableFile = null;
|
|
788
|
+
this._executableDir = null;
|
|
789
|
+
this._defaultCommandName = null;
|
|
790
|
+
this._exitCallback = null;
|
|
791
|
+
this._aliases = [];
|
|
792
|
+
this._combineFlagAndOptionalValue = true;
|
|
793
|
+
this._description = "";
|
|
794
|
+
this._summary = "";
|
|
795
|
+
this._argsDescription = undefined;
|
|
796
|
+
this._enablePositionalOptions = false;
|
|
797
|
+
this._passThroughOptions = false;
|
|
798
|
+
this._lifeCycleHooks = {};
|
|
799
|
+
this._showHelpAfterError = false;
|
|
800
|
+
this._showSuggestionAfterError = true;
|
|
801
|
+
this._savedState = null;
|
|
802
|
+
this._outputConfiguration = {
|
|
803
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
804
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
805
|
+
outputError: (str, write) => write(str),
|
|
806
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
807
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
808
|
+
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
809
|
+
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
810
|
+
stripColor: (str) => stripColor(str)
|
|
811
|
+
};
|
|
812
|
+
this._hidden = false;
|
|
813
|
+
this._helpOption = undefined;
|
|
814
|
+
this._addImplicitHelpCommand = undefined;
|
|
815
|
+
this._helpCommand = undefined;
|
|
816
|
+
this._helpConfiguration = {};
|
|
817
|
+
}
|
|
818
|
+
copyInheritedSettings(sourceCommand) {
|
|
819
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
820
|
+
this._helpOption = sourceCommand._helpOption;
|
|
821
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
822
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
823
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
824
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
825
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
826
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
827
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
828
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
829
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
830
|
+
return this;
|
|
831
|
+
}
|
|
832
|
+
_getCommandAndAncestors() {
|
|
833
|
+
const result = [];
|
|
834
|
+
for (let command = this;command; command = command.parent) {
|
|
835
|
+
result.push(command);
|
|
836
|
+
}
|
|
837
|
+
return result;
|
|
838
|
+
}
|
|
839
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
840
|
+
let desc = actionOptsOrExecDesc;
|
|
841
|
+
let opts = execOpts;
|
|
842
|
+
if (typeof desc === "object" && desc !== null) {
|
|
843
|
+
opts = desc;
|
|
844
|
+
desc = null;
|
|
845
|
+
}
|
|
846
|
+
opts = opts || {};
|
|
847
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
848
|
+
const cmd = this.createCommand(name);
|
|
849
|
+
if (desc) {
|
|
850
|
+
cmd.description(desc);
|
|
851
|
+
cmd._executableHandler = true;
|
|
852
|
+
}
|
|
853
|
+
if (opts.isDefault)
|
|
854
|
+
this._defaultCommandName = cmd._name;
|
|
855
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
856
|
+
cmd._executableFile = opts.executableFile || null;
|
|
857
|
+
if (args)
|
|
858
|
+
cmd.arguments(args);
|
|
859
|
+
this._registerCommand(cmd);
|
|
860
|
+
cmd.parent = this;
|
|
861
|
+
cmd.copyInheritedSettings(this);
|
|
862
|
+
if (desc)
|
|
863
|
+
return this;
|
|
864
|
+
return cmd;
|
|
865
|
+
}
|
|
866
|
+
createCommand(name) {
|
|
867
|
+
return new Command(name);
|
|
868
|
+
}
|
|
869
|
+
createHelp() {
|
|
870
|
+
return Object.assign(new Help, this.configureHelp());
|
|
871
|
+
}
|
|
872
|
+
configureHelp(configuration) {
|
|
873
|
+
if (configuration === undefined)
|
|
874
|
+
return this._helpConfiguration;
|
|
875
|
+
this._helpConfiguration = configuration;
|
|
876
|
+
return this;
|
|
877
|
+
}
|
|
878
|
+
configureOutput(configuration) {
|
|
879
|
+
if (configuration === undefined)
|
|
880
|
+
return this._outputConfiguration;
|
|
881
|
+
Object.assign(this._outputConfiguration, configuration);
|
|
882
|
+
return this;
|
|
883
|
+
}
|
|
884
|
+
showHelpAfterError(displayHelp = true) {
|
|
885
|
+
if (typeof displayHelp !== "string")
|
|
886
|
+
displayHelp = !!displayHelp;
|
|
887
|
+
this._showHelpAfterError = displayHelp;
|
|
888
|
+
return this;
|
|
889
|
+
}
|
|
890
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
891
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
892
|
+
return this;
|
|
893
|
+
}
|
|
894
|
+
addCommand(cmd, opts) {
|
|
895
|
+
if (!cmd._name) {
|
|
896
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
897
|
+
- specify the name in Command constructor or using .name()`);
|
|
898
|
+
}
|
|
899
|
+
opts = opts || {};
|
|
900
|
+
if (opts.isDefault)
|
|
901
|
+
this._defaultCommandName = cmd._name;
|
|
902
|
+
if (opts.noHelp || opts.hidden)
|
|
903
|
+
cmd._hidden = true;
|
|
904
|
+
this._registerCommand(cmd);
|
|
905
|
+
cmd.parent = this;
|
|
906
|
+
cmd._checkForBrokenPassThrough();
|
|
907
|
+
return this;
|
|
908
|
+
}
|
|
909
|
+
createArgument(name, description) {
|
|
910
|
+
return new Argument(name, description);
|
|
911
|
+
}
|
|
912
|
+
argument(name, description, fn, defaultValue) {
|
|
913
|
+
const argument = this.createArgument(name, description);
|
|
914
|
+
if (typeof fn === "function") {
|
|
915
|
+
argument.default(defaultValue).argParser(fn);
|
|
916
|
+
} else {
|
|
917
|
+
argument.default(fn);
|
|
918
|
+
}
|
|
919
|
+
this.addArgument(argument);
|
|
920
|
+
return this;
|
|
921
|
+
}
|
|
922
|
+
arguments(names) {
|
|
923
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
924
|
+
this.argument(detail);
|
|
925
|
+
});
|
|
926
|
+
return this;
|
|
927
|
+
}
|
|
928
|
+
addArgument(argument) {
|
|
929
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
930
|
+
if (previousArgument && previousArgument.variadic) {
|
|
931
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
932
|
+
}
|
|
933
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
934
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
935
|
+
}
|
|
936
|
+
this.registeredArguments.push(argument);
|
|
937
|
+
return this;
|
|
938
|
+
}
|
|
939
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
940
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
941
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
942
|
+
return this;
|
|
943
|
+
}
|
|
944
|
+
enableOrNameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
945
|
+
const [, helpName, helpArgs] = enableOrNameAndArgs.match(/([^ ]+) *(.*)/);
|
|
946
|
+
const helpDescription = description ?? "display help for command";
|
|
947
|
+
const helpCommand = this.createCommand(helpName);
|
|
948
|
+
helpCommand.helpOption(false);
|
|
949
|
+
if (helpArgs)
|
|
950
|
+
helpCommand.arguments(helpArgs);
|
|
951
|
+
if (helpDescription)
|
|
952
|
+
helpCommand.description(helpDescription);
|
|
953
|
+
this._addImplicitHelpCommand = true;
|
|
954
|
+
this._helpCommand = helpCommand;
|
|
955
|
+
return this;
|
|
956
|
+
}
|
|
957
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
958
|
+
if (typeof helpCommand !== "object") {
|
|
959
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
960
|
+
return this;
|
|
961
|
+
}
|
|
962
|
+
this._addImplicitHelpCommand = true;
|
|
963
|
+
this._helpCommand = helpCommand;
|
|
964
|
+
return this;
|
|
965
|
+
}
|
|
966
|
+
_getHelpCommand() {
|
|
967
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
968
|
+
if (hasImplicitHelpCommand) {
|
|
969
|
+
if (this._helpCommand === undefined) {
|
|
970
|
+
this.helpCommand(undefined, undefined);
|
|
971
|
+
}
|
|
972
|
+
return this._helpCommand;
|
|
973
|
+
}
|
|
974
|
+
return null;
|
|
975
|
+
}
|
|
976
|
+
hook(event, listener) {
|
|
977
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
978
|
+
if (!allowedValues.includes(event)) {
|
|
979
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
980
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
981
|
+
}
|
|
982
|
+
if (this._lifeCycleHooks[event]) {
|
|
983
|
+
this._lifeCycleHooks[event].push(listener);
|
|
984
|
+
} else {
|
|
985
|
+
this._lifeCycleHooks[event] = [listener];
|
|
986
|
+
}
|
|
987
|
+
return this;
|
|
988
|
+
}
|
|
989
|
+
exitOverride(fn) {
|
|
990
|
+
if (fn) {
|
|
991
|
+
this._exitCallback = fn;
|
|
992
|
+
} else {
|
|
993
|
+
this._exitCallback = (err) => {
|
|
994
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
995
|
+
throw err;
|
|
996
|
+
}
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
return this;
|
|
1000
|
+
}
|
|
1001
|
+
_exit(exitCode, code, message) {
|
|
1002
|
+
if (this._exitCallback) {
|
|
1003
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
1004
|
+
}
|
|
1005
|
+
process2.exit(exitCode);
|
|
1006
|
+
}
|
|
1007
|
+
action(fn) {
|
|
1008
|
+
const listener = (args) => {
|
|
1009
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
1010
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1011
|
+
if (this._storeOptionsAsProperties) {
|
|
1012
|
+
actionArgs[expectedArgsCount] = this;
|
|
1013
|
+
} else {
|
|
1014
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
1015
|
+
}
|
|
1016
|
+
actionArgs.push(this);
|
|
1017
|
+
return fn.apply(this, actionArgs);
|
|
1018
|
+
};
|
|
1019
|
+
this._actionHandler = listener;
|
|
1020
|
+
return this;
|
|
1021
|
+
}
|
|
1022
|
+
createOption(flags, description) {
|
|
1023
|
+
return new Option(flags, description);
|
|
1024
|
+
}
|
|
1025
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1026
|
+
try {
|
|
1027
|
+
return target.parseArg(value, previous);
|
|
1028
|
+
} catch (err) {
|
|
1029
|
+
if (err.code === "commander.invalidArgument") {
|
|
1030
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1031
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
1032
|
+
}
|
|
1033
|
+
throw err;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
_registerOption(option) {
|
|
1037
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1038
|
+
if (matchingOption) {
|
|
1039
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1040
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1041
|
+
- already used by option '${matchingOption.flags}'`);
|
|
1042
|
+
}
|
|
1043
|
+
this.options.push(option);
|
|
1044
|
+
}
|
|
1045
|
+
_registerCommand(command) {
|
|
1046
|
+
const knownBy = (cmd) => {
|
|
1047
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
1048
|
+
};
|
|
1049
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
1050
|
+
if (alreadyUsed) {
|
|
1051
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1052
|
+
const newCmd = knownBy(command).join("|");
|
|
1053
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
1054
|
+
}
|
|
1055
|
+
this.commands.push(command);
|
|
1056
|
+
}
|
|
1057
|
+
addOption(option) {
|
|
1058
|
+
this._registerOption(option);
|
|
1059
|
+
const oname = option.name();
|
|
1060
|
+
const name = option.attributeName();
|
|
1061
|
+
if (option.negate) {
|
|
1062
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1063
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
1064
|
+
this.setOptionValueWithSource(name, option.defaultValue === undefined ? true : option.defaultValue, "default");
|
|
1065
|
+
}
|
|
1066
|
+
} else if (option.defaultValue !== undefined) {
|
|
1067
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1068
|
+
}
|
|
1069
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1070
|
+
if (val == null && option.presetArg !== undefined) {
|
|
1071
|
+
val = option.presetArg;
|
|
1072
|
+
}
|
|
1073
|
+
const oldValue = this.getOptionValue(name);
|
|
1074
|
+
if (val !== null && option.parseArg) {
|
|
1075
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1076
|
+
} else if (val !== null && option.variadic) {
|
|
1077
|
+
val = option._concatValue(val, oldValue);
|
|
1078
|
+
}
|
|
1079
|
+
if (val == null) {
|
|
1080
|
+
if (option.negate) {
|
|
1081
|
+
val = false;
|
|
1082
|
+
} else if (option.isBoolean() || option.optional) {
|
|
1083
|
+
val = true;
|
|
1084
|
+
} else {
|
|
1085
|
+
val = "";
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
1089
|
+
};
|
|
1090
|
+
this.on("option:" + oname, (val) => {
|
|
1091
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
1092
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
1093
|
+
});
|
|
1094
|
+
if (option.envVar) {
|
|
1095
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
1096
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
1097
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
return this;
|
|
1101
|
+
}
|
|
1102
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1103
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
1104
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
1105
|
+
}
|
|
1106
|
+
const option = this.createOption(flags, description);
|
|
1107
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
1108
|
+
if (typeof fn === "function") {
|
|
1109
|
+
option.default(defaultValue).argParser(fn);
|
|
1110
|
+
} else if (fn instanceof RegExp) {
|
|
1111
|
+
const regex = fn;
|
|
1112
|
+
fn = (val, def) => {
|
|
1113
|
+
const m = regex.exec(val);
|
|
1114
|
+
return m ? m[0] : def;
|
|
1115
|
+
};
|
|
1116
|
+
option.default(defaultValue).argParser(fn);
|
|
1117
|
+
} else {
|
|
1118
|
+
option.default(fn);
|
|
1119
|
+
}
|
|
1120
|
+
return this.addOption(option);
|
|
1121
|
+
}
|
|
1122
|
+
option(flags, description, parseArg, defaultValue) {
|
|
1123
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1124
|
+
}
|
|
1125
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1126
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
1127
|
+
}
|
|
1128
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
1129
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
1130
|
+
return this;
|
|
1131
|
+
}
|
|
1132
|
+
allowUnknownOption(allowUnknown = true) {
|
|
1133
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
1134
|
+
return this;
|
|
1135
|
+
}
|
|
1136
|
+
allowExcessArguments(allowExcess = true) {
|
|
1137
|
+
this._allowExcessArguments = !!allowExcess;
|
|
1138
|
+
return this;
|
|
1139
|
+
}
|
|
1140
|
+
enablePositionalOptions(positional = true) {
|
|
1141
|
+
this._enablePositionalOptions = !!positional;
|
|
1142
|
+
return this;
|
|
1143
|
+
}
|
|
1144
|
+
passThroughOptions(passThrough = true) {
|
|
1145
|
+
this._passThroughOptions = !!passThrough;
|
|
1146
|
+
this._checkForBrokenPassThrough();
|
|
1147
|
+
return this;
|
|
1148
|
+
}
|
|
1149
|
+
_checkForBrokenPassThrough() {
|
|
1150
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
1151
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1155
|
+
if (this.options.length) {
|
|
1156
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1157
|
+
}
|
|
1158
|
+
if (Object.keys(this._optionValues).length) {
|
|
1159
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1160
|
+
}
|
|
1161
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1162
|
+
return this;
|
|
1163
|
+
}
|
|
1164
|
+
getOptionValue(key) {
|
|
1165
|
+
if (this._storeOptionsAsProperties) {
|
|
1166
|
+
return this[key];
|
|
1167
|
+
}
|
|
1168
|
+
return this._optionValues[key];
|
|
1169
|
+
}
|
|
1170
|
+
setOptionValue(key, value) {
|
|
1171
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
1172
|
+
}
|
|
1173
|
+
setOptionValueWithSource(key, value, source) {
|
|
1174
|
+
if (this._storeOptionsAsProperties) {
|
|
1175
|
+
this[key] = value;
|
|
1176
|
+
} else {
|
|
1177
|
+
this._optionValues[key] = value;
|
|
1178
|
+
}
|
|
1179
|
+
this._optionValueSources[key] = source;
|
|
1180
|
+
return this;
|
|
1181
|
+
}
|
|
1182
|
+
getOptionValueSource(key) {
|
|
1183
|
+
return this._optionValueSources[key];
|
|
1184
|
+
}
|
|
1185
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1186
|
+
let source;
|
|
1187
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1188
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
1189
|
+
source = cmd.getOptionValueSource(key);
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
return source;
|
|
1193
|
+
}
|
|
1194
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1195
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
1196
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
1197
|
+
}
|
|
1198
|
+
parseOptions = parseOptions || {};
|
|
1199
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
1200
|
+
if (process2.versions?.electron) {
|
|
1201
|
+
parseOptions.from = "electron";
|
|
1202
|
+
}
|
|
1203
|
+
const execArgv = process2.execArgv ?? [];
|
|
1204
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1205
|
+
parseOptions.from = "eval";
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
if (argv === undefined) {
|
|
1209
|
+
argv = process2.argv;
|
|
1210
|
+
}
|
|
1211
|
+
this.rawArgs = argv.slice();
|
|
1212
|
+
let userArgs;
|
|
1213
|
+
switch (parseOptions.from) {
|
|
1214
|
+
case undefined:
|
|
1215
|
+
case "node":
|
|
1216
|
+
this._scriptPath = argv[1];
|
|
1217
|
+
userArgs = argv.slice(2);
|
|
1218
|
+
break;
|
|
1219
|
+
case "electron":
|
|
1220
|
+
if (process2.defaultApp) {
|
|
1221
|
+
this._scriptPath = argv[1];
|
|
1222
|
+
userArgs = argv.slice(2);
|
|
1223
|
+
} else {
|
|
1224
|
+
userArgs = argv.slice(1);
|
|
1225
|
+
}
|
|
1226
|
+
break;
|
|
1227
|
+
case "user":
|
|
1228
|
+
userArgs = argv.slice(0);
|
|
1229
|
+
break;
|
|
1230
|
+
case "eval":
|
|
1231
|
+
userArgs = argv.slice(1);
|
|
1232
|
+
break;
|
|
1233
|
+
default:
|
|
1234
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1235
|
+
}
|
|
1236
|
+
if (!this._name && this._scriptPath)
|
|
1237
|
+
this.nameFromFilename(this._scriptPath);
|
|
1238
|
+
this._name = this._name || "program";
|
|
1239
|
+
return userArgs;
|
|
1240
|
+
}
|
|
1241
|
+
parse(argv, parseOptions) {
|
|
1242
|
+
this._prepareForParse();
|
|
1243
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1244
|
+
this._parseCommand([], userArgs);
|
|
1245
|
+
return this;
|
|
1246
|
+
}
|
|
1247
|
+
async parseAsync(argv, parseOptions) {
|
|
1248
|
+
this._prepareForParse();
|
|
1249
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1250
|
+
await this._parseCommand([], userArgs);
|
|
1251
|
+
return this;
|
|
1252
|
+
}
|
|
1253
|
+
_prepareForParse() {
|
|
1254
|
+
if (this._savedState === null) {
|
|
1255
|
+
this.saveStateBeforeParse();
|
|
1256
|
+
} else {
|
|
1257
|
+
this.restoreStateBeforeParse();
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
saveStateBeforeParse() {
|
|
1261
|
+
this._savedState = {
|
|
1262
|
+
_name: this._name,
|
|
1263
|
+
_optionValues: { ...this._optionValues },
|
|
1264
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
restoreStateBeforeParse() {
|
|
1268
|
+
if (this._storeOptionsAsProperties)
|
|
1269
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
1270
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
1271
|
+
this._name = this._savedState._name;
|
|
1272
|
+
this._scriptPath = null;
|
|
1273
|
+
this.rawArgs = [];
|
|
1274
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
1275
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
1276
|
+
this.args = [];
|
|
1277
|
+
this.processedArgs = [];
|
|
1278
|
+
}
|
|
1279
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
1280
|
+
if (fs.existsSync(executableFile))
|
|
1281
|
+
return;
|
|
1282
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
1283
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1284
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1285
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1286
|
+
- ${executableDirMessage}`;
|
|
1287
|
+
throw new Error(executableMissing);
|
|
1288
|
+
}
|
|
1289
|
+
_executeSubCommand(subcommand, args) {
|
|
1290
|
+
args = args.slice();
|
|
1291
|
+
let launchWithNode = false;
|
|
1292
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
1293
|
+
function findFile(baseDir, baseName) {
|
|
1294
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1295
|
+
if (fs.existsSync(localBin))
|
|
1296
|
+
return localBin;
|
|
1297
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
1298
|
+
return;
|
|
1299
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1300
|
+
if (foundExt)
|
|
1301
|
+
return `${localBin}${foundExt}`;
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
this._checkForMissingMandatoryOptions();
|
|
1305
|
+
this._checkForConflictingOptions();
|
|
1306
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1307
|
+
let executableDir = this._executableDir || "";
|
|
1308
|
+
if (this._scriptPath) {
|
|
1309
|
+
let resolvedScriptPath;
|
|
1310
|
+
try {
|
|
1311
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1312
|
+
} catch {
|
|
1313
|
+
resolvedScriptPath = this._scriptPath;
|
|
1314
|
+
}
|
|
1315
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1316
|
+
}
|
|
1317
|
+
if (executableDir) {
|
|
1318
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1319
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1320
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1321
|
+
if (legacyName !== this._name) {
|
|
1322
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
executableFile = localFile || executableFile;
|
|
1326
|
+
}
|
|
1327
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
1328
|
+
let proc;
|
|
1329
|
+
if (process2.platform !== "win32") {
|
|
1330
|
+
if (launchWithNode) {
|
|
1331
|
+
args.unshift(executableFile);
|
|
1332
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1333
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
1334
|
+
} else {
|
|
1335
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
1336
|
+
}
|
|
1337
|
+
} else {
|
|
1338
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1339
|
+
args.unshift(executableFile);
|
|
1340
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
1341
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
1342
|
+
}
|
|
1343
|
+
if (!proc.killed) {
|
|
1344
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
1345
|
+
signals.forEach((signal) => {
|
|
1346
|
+
process2.on(signal, () => {
|
|
1347
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
1348
|
+
proc.kill(signal);
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
const exitCallback = this._exitCallback;
|
|
1354
|
+
proc.on("close", (code) => {
|
|
1355
|
+
code = code ?? 1;
|
|
1356
|
+
if (!exitCallback) {
|
|
1357
|
+
process2.exit(code);
|
|
1358
|
+
} else {
|
|
1359
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1362
|
+
proc.on("error", (err) => {
|
|
1363
|
+
if (err.code === "ENOENT") {
|
|
1364
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
1365
|
+
} else if (err.code === "EACCES") {
|
|
1366
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
1367
|
+
}
|
|
1368
|
+
if (!exitCallback) {
|
|
1369
|
+
process2.exit(1);
|
|
1370
|
+
} else {
|
|
1371
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
1372
|
+
wrappedError.nestedError = err;
|
|
1373
|
+
exitCallback(wrappedError);
|
|
1374
|
+
}
|
|
1375
|
+
});
|
|
1376
|
+
this.runningCommand = proc;
|
|
1377
|
+
}
|
|
1378
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
1379
|
+
const subCommand = this._findCommand(commandName);
|
|
1380
|
+
if (!subCommand)
|
|
1381
|
+
this.help({ error: true });
|
|
1382
|
+
subCommand._prepareForParse();
|
|
1383
|
+
let promiseChain;
|
|
1384
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
1385
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1386
|
+
if (subCommand._executableHandler) {
|
|
1387
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
1388
|
+
} else {
|
|
1389
|
+
return subCommand._parseCommand(operands, unknown);
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
return promiseChain;
|
|
1393
|
+
}
|
|
1394
|
+
_dispatchHelpCommand(subcommandName) {
|
|
1395
|
+
if (!subcommandName) {
|
|
1396
|
+
this.help();
|
|
1397
|
+
}
|
|
1398
|
+
const subCommand = this._findCommand(subcommandName);
|
|
1399
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
1400
|
+
subCommand.help();
|
|
1401
|
+
}
|
|
1402
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
1403
|
+
}
|
|
1404
|
+
_checkNumberOfArguments() {
|
|
1405
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
1406
|
+
if (arg.required && this.args[i] == null) {
|
|
1407
|
+
this.missingArgument(arg.name());
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1410
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
1414
|
+
this._excessArguments(this.args);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
_processArguments() {
|
|
1418
|
+
const myParseArg = (argument, value, previous) => {
|
|
1419
|
+
let parsedValue = value;
|
|
1420
|
+
if (value !== null && argument.parseArg) {
|
|
1421
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
1422
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
1423
|
+
}
|
|
1424
|
+
return parsedValue;
|
|
1425
|
+
};
|
|
1426
|
+
this._checkNumberOfArguments();
|
|
1427
|
+
const processedArgs = [];
|
|
1428
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
1429
|
+
let value = declaredArg.defaultValue;
|
|
1430
|
+
if (declaredArg.variadic) {
|
|
1431
|
+
if (index < this.args.length) {
|
|
1432
|
+
value = this.args.slice(index);
|
|
1433
|
+
if (declaredArg.parseArg) {
|
|
1434
|
+
value = value.reduce((processed, v) => {
|
|
1435
|
+
return myParseArg(declaredArg, v, processed);
|
|
1436
|
+
}, declaredArg.defaultValue);
|
|
1437
|
+
}
|
|
1438
|
+
} else if (value === undefined) {
|
|
1439
|
+
value = [];
|
|
1440
|
+
}
|
|
1441
|
+
} else if (index < this.args.length) {
|
|
1442
|
+
value = this.args[index];
|
|
1443
|
+
if (declaredArg.parseArg) {
|
|
1444
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
processedArgs[index] = value;
|
|
1448
|
+
});
|
|
1449
|
+
this.processedArgs = processedArgs;
|
|
1450
|
+
}
|
|
1451
|
+
_chainOrCall(promise, fn) {
|
|
1452
|
+
if (promise && promise.then && typeof promise.then === "function") {
|
|
1453
|
+
return promise.then(() => fn());
|
|
1454
|
+
}
|
|
1455
|
+
return fn();
|
|
1456
|
+
}
|
|
1457
|
+
_chainOrCallHooks(promise, event) {
|
|
1458
|
+
let result = promise;
|
|
1459
|
+
const hooks = [];
|
|
1460
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
1461
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
1462
|
+
hooks.push({ hookedCommand, callback });
|
|
1463
|
+
});
|
|
1464
|
+
});
|
|
1465
|
+
if (event === "postAction") {
|
|
1466
|
+
hooks.reverse();
|
|
1467
|
+
}
|
|
1468
|
+
hooks.forEach((hookDetail) => {
|
|
1469
|
+
result = this._chainOrCall(result, () => {
|
|
1470
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
1471
|
+
});
|
|
1472
|
+
});
|
|
1473
|
+
return result;
|
|
1474
|
+
}
|
|
1475
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
1476
|
+
let result = promise;
|
|
1477
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
1478
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
1479
|
+
result = this._chainOrCall(result, () => {
|
|
1480
|
+
return hook(this, subCommand);
|
|
1481
|
+
});
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
return result;
|
|
1485
|
+
}
|
|
1486
|
+
_parseCommand(operands, unknown) {
|
|
1487
|
+
const parsed = this.parseOptions(unknown);
|
|
1488
|
+
this._parseOptionsEnv();
|
|
1489
|
+
this._parseOptionsImplied();
|
|
1490
|
+
operands = operands.concat(parsed.operands);
|
|
1491
|
+
unknown = parsed.unknown;
|
|
1492
|
+
this.args = operands.concat(unknown);
|
|
1493
|
+
if (operands && this._findCommand(operands[0])) {
|
|
1494
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
1495
|
+
}
|
|
1496
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
1497
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
1498
|
+
}
|
|
1499
|
+
if (this._defaultCommandName) {
|
|
1500
|
+
this._outputHelpIfRequested(unknown);
|
|
1501
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
1502
|
+
}
|
|
1503
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
1504
|
+
this.help({ error: true });
|
|
1505
|
+
}
|
|
1506
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
1507
|
+
this._checkForMissingMandatoryOptions();
|
|
1508
|
+
this._checkForConflictingOptions();
|
|
1509
|
+
const checkForUnknownOptions = () => {
|
|
1510
|
+
if (parsed.unknown.length > 0) {
|
|
1511
|
+
this.unknownOption(parsed.unknown[0]);
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
const commandEvent = `command:${this.name()}`;
|
|
1515
|
+
if (this._actionHandler) {
|
|
1516
|
+
checkForUnknownOptions();
|
|
1517
|
+
this._processArguments();
|
|
1518
|
+
let promiseChain;
|
|
1519
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
1520
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
1521
|
+
if (this.parent) {
|
|
1522
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
1523
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
1527
|
+
return promiseChain;
|
|
1528
|
+
}
|
|
1529
|
+
if (this.parent && this.parent.listenerCount(commandEvent)) {
|
|
1530
|
+
checkForUnknownOptions();
|
|
1531
|
+
this._processArguments();
|
|
1532
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
1533
|
+
} else if (operands.length) {
|
|
1534
|
+
if (this._findCommand("*")) {
|
|
1535
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
1536
|
+
}
|
|
1537
|
+
if (this.listenerCount("command:*")) {
|
|
1538
|
+
this.emit("command:*", operands, unknown);
|
|
1539
|
+
} else if (this.commands.length) {
|
|
1540
|
+
this.unknownCommand();
|
|
1541
|
+
} else {
|
|
1542
|
+
checkForUnknownOptions();
|
|
1543
|
+
this._processArguments();
|
|
1544
|
+
}
|
|
1545
|
+
} else if (this.commands.length) {
|
|
1546
|
+
checkForUnknownOptions();
|
|
1547
|
+
this.help({ error: true });
|
|
1548
|
+
} else {
|
|
1549
|
+
checkForUnknownOptions();
|
|
1550
|
+
this._processArguments();
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
_findCommand(name) {
|
|
1554
|
+
if (!name)
|
|
1555
|
+
return;
|
|
1556
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
1557
|
+
}
|
|
1558
|
+
_findOption(arg) {
|
|
1559
|
+
return this.options.find((option) => option.is(arg));
|
|
1560
|
+
}
|
|
1561
|
+
_checkForMissingMandatoryOptions() {
|
|
1562
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1563
|
+
cmd.options.forEach((anOption) => {
|
|
1564
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
1565
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
1566
|
+
}
|
|
1567
|
+
});
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
_checkForConflictingLocalOptions() {
|
|
1571
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
1572
|
+
const optionKey = option.attributeName();
|
|
1573
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
1574
|
+
return false;
|
|
1575
|
+
}
|
|
1576
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
1577
|
+
});
|
|
1578
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
1579
|
+
optionsWithConflicting.forEach((option) => {
|
|
1580
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
1581
|
+
if (conflictingAndDefined) {
|
|
1582
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
1583
|
+
}
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
_checkForConflictingOptions() {
|
|
1587
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1588
|
+
cmd._checkForConflictingLocalOptions();
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
parseOptions(argv) {
|
|
1592
|
+
const operands = [];
|
|
1593
|
+
const unknown = [];
|
|
1594
|
+
let dest = operands;
|
|
1595
|
+
const args = argv.slice();
|
|
1596
|
+
function maybeOption(arg) {
|
|
1597
|
+
return arg.length > 1 && arg[0] === "-";
|
|
1598
|
+
}
|
|
1599
|
+
let activeVariadicOption = null;
|
|
1600
|
+
while (args.length) {
|
|
1601
|
+
const arg = args.shift();
|
|
1602
|
+
if (arg === "--") {
|
|
1603
|
+
if (dest === unknown)
|
|
1604
|
+
dest.push(arg);
|
|
1605
|
+
dest.push(...args);
|
|
1606
|
+
break;
|
|
1607
|
+
}
|
|
1608
|
+
if (activeVariadicOption && !maybeOption(arg)) {
|
|
1609
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
activeVariadicOption = null;
|
|
1613
|
+
if (maybeOption(arg)) {
|
|
1614
|
+
const option = this._findOption(arg);
|
|
1615
|
+
if (option) {
|
|
1616
|
+
if (option.required) {
|
|
1617
|
+
const value = args.shift();
|
|
1618
|
+
if (value === undefined)
|
|
1619
|
+
this.optionMissingArgument(option);
|
|
1620
|
+
this.emit(`option:${option.name()}`, value);
|
|
1621
|
+
} else if (option.optional) {
|
|
1622
|
+
let value = null;
|
|
1623
|
+
if (args.length > 0 && !maybeOption(args[0])) {
|
|
1624
|
+
value = args.shift();
|
|
1625
|
+
}
|
|
1626
|
+
this.emit(`option:${option.name()}`, value);
|
|
1627
|
+
} else {
|
|
1628
|
+
this.emit(`option:${option.name()}`);
|
|
1629
|
+
}
|
|
1630
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
1631
|
+
continue;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
1635
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
1636
|
+
if (option) {
|
|
1637
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
1638
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
1639
|
+
} else {
|
|
1640
|
+
this.emit(`option:${option.name()}`);
|
|
1641
|
+
args.unshift(`-${arg.slice(2)}`);
|
|
1642
|
+
}
|
|
1643
|
+
continue;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
1647
|
+
const index = arg.indexOf("=");
|
|
1648
|
+
const option = this._findOption(arg.slice(0, index));
|
|
1649
|
+
if (option && (option.required || option.optional)) {
|
|
1650
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
1651
|
+
continue;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
if (maybeOption(arg)) {
|
|
1655
|
+
dest = unknown;
|
|
1656
|
+
}
|
|
1657
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
1658
|
+
if (this._findCommand(arg)) {
|
|
1659
|
+
operands.push(arg);
|
|
1660
|
+
if (args.length > 0)
|
|
1661
|
+
unknown.push(...args);
|
|
1662
|
+
break;
|
|
1663
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
1664
|
+
operands.push(arg);
|
|
1665
|
+
if (args.length > 0)
|
|
1666
|
+
operands.push(...args);
|
|
1667
|
+
break;
|
|
1668
|
+
} else if (this._defaultCommandName) {
|
|
1669
|
+
unknown.push(arg);
|
|
1670
|
+
if (args.length > 0)
|
|
1671
|
+
unknown.push(...args);
|
|
1672
|
+
break;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
if (this._passThroughOptions) {
|
|
1676
|
+
dest.push(arg);
|
|
1677
|
+
if (args.length > 0)
|
|
1678
|
+
dest.push(...args);
|
|
1679
|
+
break;
|
|
1680
|
+
}
|
|
1681
|
+
dest.push(arg);
|
|
1682
|
+
}
|
|
1683
|
+
return { operands, unknown };
|
|
1684
|
+
}
|
|
1685
|
+
opts() {
|
|
1686
|
+
if (this._storeOptionsAsProperties) {
|
|
1687
|
+
const result = {};
|
|
1688
|
+
const len = this.options.length;
|
|
1689
|
+
for (let i = 0;i < len; i++) {
|
|
1690
|
+
const key = this.options[i].attributeName();
|
|
1691
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
1692
|
+
}
|
|
1693
|
+
return result;
|
|
1694
|
+
}
|
|
1695
|
+
return this._optionValues;
|
|
1696
|
+
}
|
|
1697
|
+
optsWithGlobals() {
|
|
1698
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
1699
|
+
}
|
|
1700
|
+
error(message, errorOptions) {
|
|
1701
|
+
this._outputConfiguration.outputError(`${message}
|
|
1702
|
+
`, this._outputConfiguration.writeErr);
|
|
1703
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
1704
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
1705
|
+
`);
|
|
1706
|
+
} else if (this._showHelpAfterError) {
|
|
1707
|
+
this._outputConfiguration.writeErr(`
|
|
1708
|
+
`);
|
|
1709
|
+
this.outputHelp({ error: true });
|
|
1710
|
+
}
|
|
1711
|
+
const config = errorOptions || {};
|
|
1712
|
+
const exitCode = config.exitCode || 1;
|
|
1713
|
+
const code = config.code || "commander.error";
|
|
1714
|
+
this._exit(exitCode, code, message);
|
|
1715
|
+
}
|
|
1716
|
+
_parseOptionsEnv() {
|
|
1717
|
+
this.options.forEach((option) => {
|
|
1718
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
1719
|
+
const optionKey = option.attributeName();
|
|
1720
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
1721
|
+
if (option.required || option.optional) {
|
|
1722
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
1723
|
+
} else {
|
|
1724
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
_parseOptionsImplied() {
|
|
1731
|
+
const dualHelper = new DualOptions(this.options);
|
|
1732
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
1733
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
1734
|
+
};
|
|
1735
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
1736
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
1737
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
1738
|
+
});
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
missingArgument(name) {
|
|
1742
|
+
const message = `error: missing required argument '${name}'`;
|
|
1743
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
1744
|
+
}
|
|
1745
|
+
optionMissingArgument(option) {
|
|
1746
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
1747
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
1748
|
+
}
|
|
1749
|
+
missingMandatoryOptionValue(option) {
|
|
1750
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
1751
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
1752
|
+
}
|
|
1753
|
+
_conflictingOption(option, conflictingOption) {
|
|
1754
|
+
const findBestOptionFromValue = (option2) => {
|
|
1755
|
+
const optionKey = option2.attributeName();
|
|
1756
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
1757
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
1758
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
1759
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
1760
|
+
return negativeOption;
|
|
1761
|
+
}
|
|
1762
|
+
return positiveOption || option2;
|
|
1763
|
+
};
|
|
1764
|
+
const getErrorMessage = (option2) => {
|
|
1765
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
1766
|
+
const optionKey = bestOption.attributeName();
|
|
1767
|
+
const source = this.getOptionValueSource(optionKey);
|
|
1768
|
+
if (source === "env") {
|
|
1769
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
1770
|
+
}
|
|
1771
|
+
return `option '${bestOption.flags}'`;
|
|
1772
|
+
};
|
|
1773
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
1774
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
1775
|
+
}
|
|
1776
|
+
unknownOption(flag) {
|
|
1777
|
+
if (this._allowUnknownOption)
|
|
1778
|
+
return;
|
|
1779
|
+
let suggestion = "";
|
|
1780
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
1781
|
+
let candidateFlags = [];
|
|
1782
|
+
let command = this;
|
|
1783
|
+
do {
|
|
1784
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
1785
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
1786
|
+
command = command.parent;
|
|
1787
|
+
} while (command && !command._enablePositionalOptions);
|
|
1788
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
1789
|
+
}
|
|
1790
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
1791
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
1792
|
+
}
|
|
1793
|
+
_excessArguments(receivedArgs) {
|
|
1794
|
+
if (this._allowExcessArguments)
|
|
1795
|
+
return;
|
|
1796
|
+
const expected = this.registeredArguments.length;
|
|
1797
|
+
const s = expected === 1 ? "" : "s";
|
|
1798
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
1799
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
1800
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
1801
|
+
}
|
|
1802
|
+
unknownCommand() {
|
|
1803
|
+
const unknownName = this.args[0];
|
|
1804
|
+
let suggestion = "";
|
|
1805
|
+
if (this._showSuggestionAfterError) {
|
|
1806
|
+
const candidateNames = [];
|
|
1807
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
1808
|
+
candidateNames.push(command.name());
|
|
1809
|
+
if (command.alias())
|
|
1810
|
+
candidateNames.push(command.alias());
|
|
1811
|
+
});
|
|
1812
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
1813
|
+
}
|
|
1814
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
1815
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
1816
|
+
}
|
|
1817
|
+
version(str, flags, description) {
|
|
1818
|
+
if (str === undefined)
|
|
1819
|
+
return this._version;
|
|
1820
|
+
this._version = str;
|
|
1821
|
+
flags = flags || "-V, --version";
|
|
1822
|
+
description = description || "output the version number";
|
|
1823
|
+
const versionOption = this.createOption(flags, description);
|
|
1824
|
+
this._versionOptionName = versionOption.attributeName();
|
|
1825
|
+
this._registerOption(versionOption);
|
|
1826
|
+
this.on("option:" + versionOption.name(), () => {
|
|
1827
|
+
this._outputConfiguration.writeOut(`${str}
|
|
1828
|
+
`);
|
|
1829
|
+
this._exit(0, "commander.version", str);
|
|
1830
|
+
});
|
|
1831
|
+
return this;
|
|
1832
|
+
}
|
|
1833
|
+
description(str, argsDescription) {
|
|
1834
|
+
if (str === undefined && argsDescription === undefined)
|
|
1835
|
+
return this._description;
|
|
1836
|
+
this._description = str;
|
|
1837
|
+
if (argsDescription) {
|
|
1838
|
+
this._argsDescription = argsDescription;
|
|
1839
|
+
}
|
|
1840
|
+
return this;
|
|
1841
|
+
}
|
|
1842
|
+
summary(str) {
|
|
1843
|
+
if (str === undefined)
|
|
1844
|
+
return this._summary;
|
|
1845
|
+
this._summary = str;
|
|
1846
|
+
return this;
|
|
1847
|
+
}
|
|
1848
|
+
alias(alias) {
|
|
1849
|
+
if (alias === undefined)
|
|
1850
|
+
return this._aliases[0];
|
|
1851
|
+
let command = this;
|
|
1852
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
1853
|
+
command = this.commands[this.commands.length - 1];
|
|
1854
|
+
}
|
|
1855
|
+
if (alias === command._name)
|
|
1856
|
+
throw new Error("Command alias can't be the same as its name");
|
|
1857
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
1858
|
+
if (matchingCommand) {
|
|
1859
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
1860
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
1861
|
+
}
|
|
1862
|
+
command._aliases.push(alias);
|
|
1863
|
+
return this;
|
|
1864
|
+
}
|
|
1865
|
+
aliases(aliases) {
|
|
1866
|
+
if (aliases === undefined)
|
|
1867
|
+
return this._aliases;
|
|
1868
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
1869
|
+
return this;
|
|
1870
|
+
}
|
|
1871
|
+
usage(str) {
|
|
1872
|
+
if (str === undefined) {
|
|
1873
|
+
if (this._usage)
|
|
1874
|
+
return this._usage;
|
|
1875
|
+
const args = this.registeredArguments.map((arg) => {
|
|
1876
|
+
return humanReadableArgName(arg);
|
|
1877
|
+
});
|
|
1878
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
1879
|
+
}
|
|
1880
|
+
this._usage = str;
|
|
1881
|
+
return this;
|
|
1882
|
+
}
|
|
1883
|
+
name(str) {
|
|
1884
|
+
if (str === undefined)
|
|
1885
|
+
return this._name;
|
|
1886
|
+
this._name = str;
|
|
1887
|
+
return this;
|
|
1888
|
+
}
|
|
1889
|
+
nameFromFilename(filename) {
|
|
1890
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
1891
|
+
return this;
|
|
1892
|
+
}
|
|
1893
|
+
executableDir(path2) {
|
|
1894
|
+
if (path2 === undefined)
|
|
1895
|
+
return this._executableDir;
|
|
1896
|
+
this._executableDir = path2;
|
|
1897
|
+
return this;
|
|
1898
|
+
}
|
|
1899
|
+
helpInformation(contextOptions) {
|
|
1900
|
+
const helper = this.createHelp();
|
|
1901
|
+
const context = this._getOutputContext(contextOptions);
|
|
1902
|
+
helper.prepareContext({
|
|
1903
|
+
error: context.error,
|
|
1904
|
+
helpWidth: context.helpWidth,
|
|
1905
|
+
outputHasColors: context.hasColors
|
|
1906
|
+
});
|
|
1907
|
+
const text = helper.formatHelp(this, helper);
|
|
1908
|
+
if (context.hasColors)
|
|
1909
|
+
return text;
|
|
1910
|
+
return this._outputConfiguration.stripColor(text);
|
|
1911
|
+
}
|
|
1912
|
+
_getOutputContext(contextOptions) {
|
|
1913
|
+
contextOptions = contextOptions || {};
|
|
1914
|
+
const error = !!contextOptions.error;
|
|
1915
|
+
let baseWrite;
|
|
1916
|
+
let hasColors;
|
|
1917
|
+
let helpWidth;
|
|
1918
|
+
if (error) {
|
|
1919
|
+
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
1920
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
1921
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
1922
|
+
} else {
|
|
1923
|
+
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
1924
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
1925
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
1926
|
+
}
|
|
1927
|
+
const write = (str) => {
|
|
1928
|
+
if (!hasColors)
|
|
1929
|
+
str = this._outputConfiguration.stripColor(str);
|
|
1930
|
+
return baseWrite(str);
|
|
1931
|
+
};
|
|
1932
|
+
return { error, write, hasColors, helpWidth };
|
|
1933
|
+
}
|
|
1934
|
+
outputHelp(contextOptions) {
|
|
1935
|
+
let deprecatedCallback;
|
|
1936
|
+
if (typeof contextOptions === "function") {
|
|
1937
|
+
deprecatedCallback = contextOptions;
|
|
1938
|
+
contextOptions = undefined;
|
|
1939
|
+
}
|
|
1940
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
1941
|
+
const eventContext = {
|
|
1942
|
+
error: outputContext.error,
|
|
1943
|
+
write: outputContext.write,
|
|
1944
|
+
command: this
|
|
1945
|
+
};
|
|
1946
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
1947
|
+
this.emit("beforeHelp", eventContext);
|
|
1948
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
1949
|
+
if (deprecatedCallback) {
|
|
1950
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
1951
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
1952
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
outputContext.write(helpInformation);
|
|
1956
|
+
if (this._getHelpOption()?.long) {
|
|
1957
|
+
this.emit(this._getHelpOption().long);
|
|
1958
|
+
}
|
|
1959
|
+
this.emit("afterHelp", eventContext);
|
|
1960
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
1961
|
+
}
|
|
1962
|
+
helpOption(flags, description) {
|
|
1963
|
+
if (typeof flags === "boolean") {
|
|
1964
|
+
if (flags) {
|
|
1965
|
+
this._helpOption = this._helpOption ?? undefined;
|
|
1966
|
+
} else {
|
|
1967
|
+
this._helpOption = null;
|
|
1968
|
+
}
|
|
1969
|
+
return this;
|
|
1970
|
+
}
|
|
1971
|
+
flags = flags ?? "-h, --help";
|
|
1972
|
+
description = description ?? "display help for command";
|
|
1973
|
+
this._helpOption = this.createOption(flags, description);
|
|
1974
|
+
return this;
|
|
1975
|
+
}
|
|
1976
|
+
_getHelpOption() {
|
|
1977
|
+
if (this._helpOption === undefined) {
|
|
1978
|
+
this.helpOption(undefined, undefined);
|
|
1979
|
+
}
|
|
1980
|
+
return this._helpOption;
|
|
1981
|
+
}
|
|
1982
|
+
addHelpOption(option) {
|
|
1983
|
+
this._helpOption = option;
|
|
1984
|
+
return this;
|
|
1985
|
+
}
|
|
1986
|
+
help(contextOptions) {
|
|
1987
|
+
this.outputHelp(contextOptions);
|
|
1988
|
+
let exitCode = Number(process2.exitCode ?? 0);
|
|
1989
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
1990
|
+
exitCode = 1;
|
|
1991
|
+
}
|
|
1992
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
1993
|
+
}
|
|
1994
|
+
addHelpText(position, text) {
|
|
1995
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
1996
|
+
if (!allowedValues.includes(position)) {
|
|
1997
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
1998
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1999
|
+
}
|
|
2000
|
+
const helpEvent = `${position}Help`;
|
|
2001
|
+
this.on(helpEvent, (context) => {
|
|
2002
|
+
let helpStr;
|
|
2003
|
+
if (typeof text === "function") {
|
|
2004
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
2005
|
+
} else {
|
|
2006
|
+
helpStr = text;
|
|
2007
|
+
}
|
|
2008
|
+
if (helpStr) {
|
|
2009
|
+
context.write(`${helpStr}
|
|
2010
|
+
`);
|
|
2011
|
+
}
|
|
2012
|
+
});
|
|
2013
|
+
return this;
|
|
2014
|
+
}
|
|
2015
|
+
_outputHelpIfRequested(args) {
|
|
2016
|
+
const helpOption = this._getHelpOption();
|
|
2017
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
2018
|
+
if (helpRequested) {
|
|
2019
|
+
this.outputHelp();
|
|
2020
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
function incrementNodeInspectorPort(args) {
|
|
2025
|
+
return args.map((arg) => {
|
|
2026
|
+
if (!arg.startsWith("--inspect")) {
|
|
2027
|
+
return arg;
|
|
2028
|
+
}
|
|
2029
|
+
let debugOption;
|
|
2030
|
+
let debugHost = "127.0.0.1";
|
|
2031
|
+
let debugPort = "9229";
|
|
2032
|
+
let match;
|
|
2033
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
2034
|
+
debugOption = match[1];
|
|
2035
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
2036
|
+
debugOption = match[1];
|
|
2037
|
+
if (/^\d+$/.test(match[3])) {
|
|
2038
|
+
debugPort = match[3];
|
|
2039
|
+
} else {
|
|
2040
|
+
debugHost = match[3];
|
|
2041
|
+
}
|
|
2042
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
2043
|
+
debugOption = match[1];
|
|
2044
|
+
debugHost = match[3];
|
|
2045
|
+
debugPort = match[4];
|
|
2046
|
+
}
|
|
2047
|
+
if (debugOption && debugPort !== "0") {
|
|
2048
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
2049
|
+
}
|
|
2050
|
+
return arg;
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
function useColor() {
|
|
2054
|
+
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
2055
|
+
return false;
|
|
2056
|
+
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
|
|
2057
|
+
return true;
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
exports.Command = Command;
|
|
2061
|
+
exports.useColor = useColor;
|
|
2062
|
+
});
|
|
2063
|
+
|
|
2064
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/index.js
|
|
2065
|
+
var require_commander = __commonJS((exports) => {
|
|
2066
|
+
var { Argument } = require_argument();
|
|
2067
|
+
var { Command } = require_command();
|
|
2068
|
+
var { CommanderError, InvalidArgumentError } = require_error();
|
|
2069
|
+
var { Help } = require_help();
|
|
2070
|
+
var { Option } = require_option();
|
|
2071
|
+
exports.program = new Command;
|
|
2072
|
+
exports.createCommand = (name) => new Command(name);
|
|
2073
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
2074
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
2075
|
+
exports.Command = Command;
|
|
2076
|
+
exports.Option = Option;
|
|
2077
|
+
exports.Argument = Argument;
|
|
2078
|
+
exports.Help = Help;
|
|
2079
|
+
exports.CommanderError = CommanderError;
|
|
2080
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
2081
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
2082
|
+
});
|
|
2083
|
+
|
|
2084
|
+
// ../../packages/core/dist/errors/index.js
|
|
2085
|
+
var require_errors = __commonJS((exports) => {
|
|
2086
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2087
|
+
exports.severityForCode = exports.inferCodeFromStatus = exports.isDomainErrorPayload = undefined;
|
|
2088
|
+
var DOMAIN_CODES = new Set([
|
|
2089
|
+
"VALIDATION_FAILED",
|
|
2090
|
+
"NOT_FOUND",
|
|
2091
|
+
"UNAUTHORIZED",
|
|
2092
|
+
"FORBIDDEN",
|
|
2093
|
+
"CONFLICT",
|
|
2094
|
+
"PRECONDITION_REQUIRED",
|
|
2095
|
+
"RATE_LIMITED",
|
|
2096
|
+
"INTERNAL"
|
|
2097
|
+
]);
|
|
2098
|
+
var isDomainErrorPayload = (value) => {
|
|
2099
|
+
if (typeof value !== "object" || value === null)
|
|
2100
|
+
return false;
|
|
2101
|
+
const v = value;
|
|
2102
|
+
return typeof v.statusCode === "number" && typeof v.code === "string" && DOMAIN_CODES.has(v.code) && typeof v.message === "string";
|
|
2103
|
+
};
|
|
2104
|
+
exports.isDomainErrorPayload = isDomainErrorPayload;
|
|
2105
|
+
var inferCodeFromStatus = (status) => {
|
|
2106
|
+
if (status === 401)
|
|
2107
|
+
return "UNAUTHORIZED";
|
|
2108
|
+
if (status === 403)
|
|
2109
|
+
return "FORBIDDEN";
|
|
2110
|
+
if (status === 404)
|
|
2111
|
+
return "NOT_FOUND";
|
|
2112
|
+
if (status === 409)
|
|
2113
|
+
return "CONFLICT";
|
|
2114
|
+
if (status === 412 || status === 428)
|
|
2115
|
+
return "PRECONDITION_REQUIRED";
|
|
2116
|
+
if (status === 422 || status === 400)
|
|
2117
|
+
return "VALIDATION_FAILED";
|
|
2118
|
+
if (status === 429)
|
|
2119
|
+
return "RATE_LIMITED";
|
|
2120
|
+
return "INTERNAL";
|
|
2121
|
+
};
|
|
2122
|
+
exports.inferCodeFromStatus = inferCodeFromStatus;
|
|
2123
|
+
var severityForCode = (code) => {
|
|
2124
|
+
switch (code) {
|
|
2125
|
+
case "VALIDATION_FAILED":
|
|
2126
|
+
return "low";
|
|
2127
|
+
case "NOT_FOUND":
|
|
2128
|
+
case "CONFLICT":
|
|
2129
|
+
case "PRECONDITION_REQUIRED":
|
|
2130
|
+
case "RATE_LIMITED":
|
|
2131
|
+
return "medium";
|
|
2132
|
+
case "UNAUTHORIZED":
|
|
2133
|
+
case "FORBIDDEN":
|
|
2134
|
+
return "high";
|
|
2135
|
+
case "INTERNAL":
|
|
2136
|
+
return "critical";
|
|
2137
|
+
}
|
|
2138
|
+
};
|
|
2139
|
+
exports.severityForCode = severityForCode;
|
|
2140
|
+
});
|
|
2141
|
+
|
|
2142
|
+
// ../../packages/core/dist/history/index.js
|
|
2143
|
+
var require_history = __commonJS((exports) => {
|
|
2144
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2145
|
+
exports.canRedo = exports.canUndo = exports.emptyHistory = undefined;
|
|
2146
|
+
exports.recordSnapshot = recordSnapshot;
|
|
2147
|
+
exports.undoStep = undoStep;
|
|
2148
|
+
exports.redoStep = redoStep;
|
|
2149
|
+
var emptyHistory = () => ({ past: [], future: [] });
|
|
2150
|
+
exports.emptyHistory = emptyHistory;
|
|
2151
|
+
var canUndo = (history) => history.past.length > 0;
|
|
2152
|
+
exports.canUndo = canUndo;
|
|
2153
|
+
var canRedo = (history) => history.future.length > 0;
|
|
2154
|
+
exports.canRedo = canRedo;
|
|
2155
|
+
var DEFAULT_MAX_DEPTH = 50;
|
|
2156
|
+
function recordSnapshot(history, current, config = {}) {
|
|
2157
|
+
const { maxDepth = DEFAULT_MAX_DEPTH, equals } = config;
|
|
2158
|
+
const lastPast = history.past[history.past.length - 1];
|
|
2159
|
+
if (lastPast !== undefined && equals?.(lastPast, current)) {
|
|
2160
|
+
return history;
|
|
2161
|
+
}
|
|
2162
|
+
const past = [...history.past, current];
|
|
2163
|
+
const trimmed = past.length > maxDepth ? past.slice(past.length - maxDepth) : past;
|
|
2164
|
+
return { past: trimmed, future: [] };
|
|
2165
|
+
}
|
|
2166
|
+
function undoStep(history, current) {
|
|
2167
|
+
if (history.past.length === 0)
|
|
2168
|
+
return null;
|
|
2169
|
+
const previous = history.past[history.past.length - 1];
|
|
2170
|
+
return {
|
|
2171
|
+
history: { past: history.past.slice(0, -1), future: [...history.future, current] },
|
|
2172
|
+
previous
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
function redoStep(history, current) {
|
|
2176
|
+
if (history.future.length === 0)
|
|
2177
|
+
return null;
|
|
2178
|
+
const next = history.future[history.future.length - 1];
|
|
2179
|
+
return {
|
|
2180
|
+
history: { past: [...history.past, current], future: history.future.slice(0, -1) },
|
|
2181
|
+
next
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
});
|
|
2185
|
+
|
|
2186
|
+
// ../../packages/core/dist/types/index.js
|
|
2187
|
+
var require_types = __commonJS((exports) => {
|
|
2188
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2189
|
+
exports.ROUTE_VISIBILITIES = exports.ROUTE_ACTIVITIES = undefined;
|
|
2190
|
+
exports.ROUTE_ACTIVITIES = ["run", "cycle", "walk"];
|
|
2191
|
+
exports.ROUTE_VISIBILITIES = ["private", "unlisted", "public"];
|
|
2192
|
+
});
|
|
2193
|
+
|
|
2194
|
+
// ../../packages/core/dist/preferences/user-preferences.js
|
|
2195
|
+
var require_user_preferences = __commonJS((exports) => {
|
|
2196
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2197
|
+
exports.DEFAULT_USER_PREFERENCES = exports.OVERLAY_KEYS = exports.ROUTE_VISIBILITIES = exports.MAP_STYLES = exports.UNITS = exports.ACTIVITIES = undefined;
|
|
2198
|
+
exports.isActivity = isActivity;
|
|
2199
|
+
exports.isUnits = isUnits;
|
|
2200
|
+
exports.isMapStyle = isMapStyle;
|
|
2201
|
+
exports.isRouteVisibility = isRouteVisibility;
|
|
2202
|
+
exports.normalizeUserPreferences = normalizeUserPreferences;
|
|
2203
|
+
exports.mergeUserPreferences = mergeUserPreferences;
|
|
2204
|
+
exports.ACTIVITIES = ["run", "cycle", "walk"];
|
|
2205
|
+
exports.UNITS = ["km", "mi"];
|
|
2206
|
+
exports.MAP_STYLES = ["streets", "outdoors", "satellite"];
|
|
2207
|
+
var types_1 = require_types();
|
|
2208
|
+
Object.defineProperty(exports, "ROUTE_VISIBILITIES", { enumerable: true, get: function() {
|
|
2209
|
+
return types_1.ROUTE_VISIBILITIES;
|
|
2210
|
+
} });
|
|
2211
|
+
exports.OVERLAY_KEYS = ["heatmap", "contour", "bike", "surface", "wind"];
|
|
2212
|
+
var ACTIVITY_LABELS = {
|
|
2213
|
+
run: "Running",
|
|
2214
|
+
cycle: "Cycling",
|
|
2215
|
+
walk: "Walking"
|
|
2216
|
+
};
|
|
2217
|
+
var LABEL_TO_ACTIVITY = {
|
|
2218
|
+
Running: "run",
|
|
2219
|
+
Cycling: "cycle",
|
|
2220
|
+
Walking: "walk"
|
|
2221
|
+
};
|
|
2222
|
+
exports.DEFAULT_USER_PREFERENCES = {
|
|
2223
|
+
units: "km",
|
|
2224
|
+
showPois: true,
|
|
2225
|
+
terrain3d: false,
|
|
2226
|
+
autoSnap: true,
|
|
2227
|
+
defaultActivity: "Cycling",
|
|
2228
|
+
selectedSports: [],
|
|
2229
|
+
sportSpeeds: {},
|
|
2230
|
+
mapStyle: "outdoors",
|
|
2231
|
+
overlays: {
|
|
2232
|
+
heatmap: true,
|
|
2233
|
+
contour: false,
|
|
2234
|
+
bike: true,
|
|
2235
|
+
surface: false,
|
|
2236
|
+
wind: false
|
|
2237
|
+
},
|
|
2238
|
+
defaultRouteVisibility: "private"
|
|
2239
|
+
};
|
|
2240
|
+
function isActivity(value) {
|
|
2241
|
+
return exports.ACTIVITIES.includes(value);
|
|
2242
|
+
}
|
|
2243
|
+
function isUnits(value) {
|
|
2244
|
+
return exports.UNITS.includes(value);
|
|
2245
|
+
}
|
|
2246
|
+
function isMapStyle(value) {
|
|
2247
|
+
return exports.MAP_STYLES.includes(value);
|
|
2248
|
+
}
|
|
2249
|
+
function isRouteVisibility(value) {
|
|
2250
|
+
return types_1.ROUTE_VISIBILITIES.includes(value);
|
|
2251
|
+
}
|
|
2252
|
+
function isFiniteNumber(value) {
|
|
2253
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
2254
|
+
}
|
|
2255
|
+
function normalizeSelectedSports(input) {
|
|
2256
|
+
if (!Array.isArray(input)) {
|
|
2257
|
+
return [...exports.DEFAULT_USER_PREFERENCES.selectedSports];
|
|
2258
|
+
}
|
|
2259
|
+
const seen = new Set;
|
|
2260
|
+
return input.filter(isActivity).filter((sport) => {
|
|
2261
|
+
if (seen.has(sport)) {
|
|
2262
|
+
return false;
|
|
2263
|
+
}
|
|
2264
|
+
seen.add(sport);
|
|
2265
|
+
return true;
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
function normalizeDefaultActivity(input, selectedSports) {
|
|
2269
|
+
if (typeof input === "string") {
|
|
2270
|
+
const mappedSport = LABEL_TO_ACTIVITY[input];
|
|
2271
|
+
if (!mappedSport) {
|
|
2272
|
+
return input;
|
|
2273
|
+
}
|
|
2274
|
+
if (selectedSports.length === 0 || selectedSports.includes(mappedSport)) {
|
|
2275
|
+
return input;
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
if (selectedSports.length > 0) {
|
|
2279
|
+
return ACTIVITY_LABELS[selectedSports[0]];
|
|
2280
|
+
}
|
|
2281
|
+
return exports.DEFAULT_USER_PREFERENCES.defaultActivity;
|
|
2282
|
+
}
|
|
2283
|
+
function normalizeSportSpeeds(input) {
|
|
2284
|
+
if (!input || typeof input !== "object") {
|
|
2285
|
+
return { ...exports.DEFAULT_USER_PREFERENCES.sportSpeeds };
|
|
2286
|
+
}
|
|
2287
|
+
const source = input;
|
|
2288
|
+
const next = {};
|
|
2289
|
+
for (const activity of exports.ACTIVITIES) {
|
|
2290
|
+
const value = source[activity];
|
|
2291
|
+
if (isFiniteNumber(value) && value > 0) {
|
|
2292
|
+
next[activity] = value;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
return next;
|
|
2296
|
+
}
|
|
2297
|
+
function normalizeOverlays(input) {
|
|
2298
|
+
const source = input && typeof input === "object" ? input : {};
|
|
2299
|
+
const result = { ...exports.DEFAULT_USER_PREFERENCES.overlays };
|
|
2300
|
+
for (const key of exports.OVERLAY_KEYS) {
|
|
2301
|
+
const value = source[key];
|
|
2302
|
+
if (typeof value === "boolean") {
|
|
2303
|
+
result[key] = value;
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
return result;
|
|
2307
|
+
}
|
|
2308
|
+
function normalizeUserPreferences(input) {
|
|
2309
|
+
const selectedSports = normalizeSelectedSports(input?.selectedSports);
|
|
2310
|
+
return {
|
|
2311
|
+
units: isUnits(input?.units) ? input.units : exports.DEFAULT_USER_PREFERENCES.units,
|
|
2312
|
+
showPois: typeof input?.showPois === "boolean" ? input.showPois : exports.DEFAULT_USER_PREFERENCES.showPois,
|
|
2313
|
+
terrain3d: typeof input?.terrain3d === "boolean" ? input.terrain3d : exports.DEFAULT_USER_PREFERENCES.terrain3d,
|
|
2314
|
+
autoSnap: typeof input?.autoSnap === "boolean" ? input.autoSnap : exports.DEFAULT_USER_PREFERENCES.autoSnap,
|
|
2315
|
+
defaultActivity: normalizeDefaultActivity(input?.defaultActivity, selectedSports),
|
|
2316
|
+
selectedSports,
|
|
2317
|
+
sportSpeeds: normalizeSportSpeeds(input?.sportSpeeds),
|
|
2318
|
+
mapStyle: isMapStyle(input?.mapStyle) ? input.mapStyle : exports.DEFAULT_USER_PREFERENCES.mapStyle,
|
|
2319
|
+
overlays: normalizeOverlays(input?.overlays),
|
|
2320
|
+
defaultRouteVisibility: isRouteVisibility(input?.defaultRouteVisibility) ? input.defaultRouteVisibility : exports.DEFAULT_USER_PREFERENCES.defaultRouteVisibility
|
|
2321
|
+
};
|
|
2322
|
+
}
|
|
2323
|
+
function mergeUserPreferences(current, update) {
|
|
2324
|
+
const base = normalizeUserPreferences(current);
|
|
2325
|
+
return normalizeUserPreferences({
|
|
2326
|
+
...base,
|
|
2327
|
+
...update,
|
|
2328
|
+
sportSpeeds: {
|
|
2329
|
+
...base.sportSpeeds,
|
|
2330
|
+
...update.sportSpeeds ?? {}
|
|
2331
|
+
},
|
|
2332
|
+
overlays: {
|
|
2333
|
+
...base.overlays,
|
|
2334
|
+
...update.overlays ?? {}
|
|
2335
|
+
}
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
|
|
2340
|
+
// ../../node_modules/.bun/zustand@5.0.13+e55371ec98c955e9/node_modules/zustand/vanilla.js
|
|
2341
|
+
var require_vanilla = __commonJS((exports) => {
|
|
2342
|
+
var createStoreImpl = (createState) => {
|
|
2343
|
+
let state;
|
|
2344
|
+
const listeners = /* @__PURE__ */ new Set;
|
|
2345
|
+
const setState = (partial, replace) => {
|
|
2346
|
+
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
2347
|
+
if (!Object.is(nextState, state)) {
|
|
2348
|
+
const previousState = state;
|
|
2349
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
2350
|
+
listeners.forEach((listener) => listener(state, previousState));
|
|
2351
|
+
}
|
|
2352
|
+
};
|
|
2353
|
+
const getState = () => state;
|
|
2354
|
+
const getInitialState = () => initialState;
|
|
2355
|
+
const subscribe = (listener) => {
|
|
2356
|
+
listeners.add(listener);
|
|
2357
|
+
return () => listeners.delete(listener);
|
|
2358
|
+
};
|
|
2359
|
+
const api = { setState, getState, getInitialState, subscribe };
|
|
2360
|
+
const initialState = state = createState(setState, getState, api);
|
|
2361
|
+
return api;
|
|
2362
|
+
};
|
|
2363
|
+
var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
|
|
2364
|
+
exports.createStore = createStore;
|
|
2365
|
+
});
|
|
2366
|
+
|
|
2367
|
+
// ../../node_modules/.bun/react@19.2.6/node_modules/react/cjs/react.development.js
|
|
2368
|
+
var require_react_development = __commonJS((exports, module) => {
|
|
2369
|
+
(function() {
|
|
2370
|
+
function defineDeprecationWarning(methodName, info) {
|
|
2371
|
+
Object.defineProperty(Component.prototype, methodName, {
|
|
2372
|
+
get: function() {
|
|
2373
|
+
console.warn("%s(...) is deprecated in plain JavaScript React classes. %s", info[0], info[1]);
|
|
2374
|
+
}
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2377
|
+
function getIteratorFn(maybeIterable) {
|
|
2378
|
+
if (maybeIterable === null || typeof maybeIterable !== "object")
|
|
2379
|
+
return null;
|
|
2380
|
+
maybeIterable = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable["@@iterator"];
|
|
2381
|
+
return typeof maybeIterable === "function" ? maybeIterable : null;
|
|
2382
|
+
}
|
|
2383
|
+
function warnNoop(publicInstance, callerName) {
|
|
2384
|
+
publicInstance = (publicInstance = publicInstance.constructor) && (publicInstance.displayName || publicInstance.name) || "ReactClass";
|
|
2385
|
+
var warningKey = publicInstance + "." + callerName;
|
|
2386
|
+
didWarnStateUpdateForUnmountedComponent[warningKey] || (console.error("Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.", callerName, publicInstance), didWarnStateUpdateForUnmountedComponent[warningKey] = true);
|
|
2387
|
+
}
|
|
2388
|
+
function Component(props, context, updater) {
|
|
2389
|
+
this.props = props;
|
|
2390
|
+
this.context = context;
|
|
2391
|
+
this.refs = emptyObject;
|
|
2392
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
2393
|
+
}
|
|
2394
|
+
function ComponentDummy() {}
|
|
2395
|
+
function PureComponent(props, context, updater) {
|
|
2396
|
+
this.props = props;
|
|
2397
|
+
this.context = context;
|
|
2398
|
+
this.refs = emptyObject;
|
|
2399
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
2400
|
+
}
|
|
2401
|
+
function noop() {}
|
|
2402
|
+
function testStringCoercion(value) {
|
|
2403
|
+
return "" + value;
|
|
2404
|
+
}
|
|
2405
|
+
function checkKeyStringCoercion(value) {
|
|
2406
|
+
try {
|
|
2407
|
+
testStringCoercion(value);
|
|
2408
|
+
var JSCompiler_inline_result = false;
|
|
2409
|
+
} catch (e) {
|
|
2410
|
+
JSCompiler_inline_result = true;
|
|
2411
|
+
}
|
|
2412
|
+
if (JSCompiler_inline_result) {
|
|
2413
|
+
JSCompiler_inline_result = console;
|
|
2414
|
+
var JSCompiler_temp_const = JSCompiler_inline_result.error;
|
|
2415
|
+
var JSCompiler_inline_result$jscomp$0 = typeof Symbol === "function" && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
|
|
2416
|
+
JSCompiler_temp_const.call(JSCompiler_inline_result, "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.", JSCompiler_inline_result$jscomp$0);
|
|
2417
|
+
return testStringCoercion(value);
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
function getComponentNameFromType(type) {
|
|
2421
|
+
if (type == null)
|
|
2422
|
+
return null;
|
|
2423
|
+
if (typeof type === "function")
|
|
2424
|
+
return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
|
|
2425
|
+
if (typeof type === "string")
|
|
2426
|
+
return type;
|
|
2427
|
+
switch (type) {
|
|
2428
|
+
case REACT_FRAGMENT_TYPE:
|
|
2429
|
+
return "Fragment";
|
|
2430
|
+
case REACT_PROFILER_TYPE:
|
|
2431
|
+
return "Profiler";
|
|
2432
|
+
case REACT_STRICT_MODE_TYPE:
|
|
2433
|
+
return "StrictMode";
|
|
2434
|
+
case REACT_SUSPENSE_TYPE:
|
|
2435
|
+
return "Suspense";
|
|
2436
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
2437
|
+
return "SuspenseList";
|
|
2438
|
+
case REACT_ACTIVITY_TYPE:
|
|
2439
|
+
return "Activity";
|
|
2440
|
+
}
|
|
2441
|
+
if (typeof type === "object")
|
|
2442
|
+
switch (typeof type.tag === "number" && console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), type.$$typeof) {
|
|
2443
|
+
case REACT_PORTAL_TYPE:
|
|
2444
|
+
return "Portal";
|
|
2445
|
+
case REACT_CONTEXT_TYPE:
|
|
2446
|
+
return type.displayName || "Context";
|
|
2447
|
+
case REACT_CONSUMER_TYPE:
|
|
2448
|
+
return (type._context.displayName || "Context") + ".Consumer";
|
|
2449
|
+
case REACT_FORWARD_REF_TYPE:
|
|
2450
|
+
var innerType = type.render;
|
|
2451
|
+
type = type.displayName;
|
|
2452
|
+
type || (type = innerType.displayName || innerType.name || "", type = type !== "" ? "ForwardRef(" + type + ")" : "ForwardRef");
|
|
2453
|
+
return type;
|
|
2454
|
+
case REACT_MEMO_TYPE:
|
|
2455
|
+
return innerType = type.displayName || null, innerType !== null ? innerType : getComponentNameFromType(type.type) || "Memo";
|
|
2456
|
+
case REACT_LAZY_TYPE:
|
|
2457
|
+
innerType = type._payload;
|
|
2458
|
+
type = type._init;
|
|
2459
|
+
try {
|
|
2460
|
+
return getComponentNameFromType(type(innerType));
|
|
2461
|
+
} catch (x) {}
|
|
2462
|
+
}
|
|
2463
|
+
return null;
|
|
2464
|
+
}
|
|
2465
|
+
function getTaskName(type) {
|
|
2466
|
+
if (type === REACT_FRAGMENT_TYPE)
|
|
2467
|
+
return "<>";
|
|
2468
|
+
if (typeof type === "object" && type !== null && type.$$typeof === REACT_LAZY_TYPE)
|
|
2469
|
+
return "<...>";
|
|
2470
|
+
try {
|
|
2471
|
+
var name = getComponentNameFromType(type);
|
|
2472
|
+
return name ? "<" + name + ">" : "<...>";
|
|
2473
|
+
} catch (x) {
|
|
2474
|
+
return "<...>";
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
function getOwner() {
|
|
2478
|
+
var dispatcher = ReactSharedInternals.A;
|
|
2479
|
+
return dispatcher === null ? null : dispatcher.getOwner();
|
|
2480
|
+
}
|
|
2481
|
+
function UnknownOwner() {
|
|
2482
|
+
return Error("react-stack-top-frame");
|
|
2483
|
+
}
|
|
2484
|
+
function hasValidKey(config) {
|
|
2485
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
2486
|
+
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
|
2487
|
+
if (getter && getter.isReactWarning)
|
|
2488
|
+
return false;
|
|
2489
|
+
}
|
|
2490
|
+
return config.key !== undefined;
|
|
2491
|
+
}
|
|
2492
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
2493
|
+
function warnAboutAccessingKey() {
|
|
2494
|
+
specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)", displayName));
|
|
2495
|
+
}
|
|
2496
|
+
warnAboutAccessingKey.isReactWarning = true;
|
|
2497
|
+
Object.defineProperty(props, "key", {
|
|
2498
|
+
get: warnAboutAccessingKey,
|
|
2499
|
+
configurable: true
|
|
2500
|
+
});
|
|
2501
|
+
}
|
|
2502
|
+
function elementRefGetterWithDeprecationWarning() {
|
|
2503
|
+
var componentName = getComponentNameFromType(this.type);
|
|
2504
|
+
didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."));
|
|
2505
|
+
componentName = this.props.ref;
|
|
2506
|
+
return componentName !== undefined ? componentName : null;
|
|
2507
|
+
}
|
|
2508
|
+
function ReactElement(type, key, props, owner, debugStack, debugTask) {
|
|
2509
|
+
var refProp = props.ref;
|
|
2510
|
+
type = {
|
|
2511
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
2512
|
+
type,
|
|
2513
|
+
key,
|
|
2514
|
+
props,
|
|
2515
|
+
_owner: owner
|
|
2516
|
+
};
|
|
2517
|
+
(refProp !== undefined ? refProp : null) !== null ? Object.defineProperty(type, "ref", {
|
|
2518
|
+
enumerable: false,
|
|
2519
|
+
get: elementRefGetterWithDeprecationWarning
|
|
2520
|
+
}) : Object.defineProperty(type, "ref", { enumerable: false, value: null });
|
|
2521
|
+
type._store = {};
|
|
2522
|
+
Object.defineProperty(type._store, "validated", {
|
|
2523
|
+
configurable: false,
|
|
2524
|
+
enumerable: false,
|
|
2525
|
+
writable: true,
|
|
2526
|
+
value: 0
|
|
2527
|
+
});
|
|
2528
|
+
Object.defineProperty(type, "_debugInfo", {
|
|
2529
|
+
configurable: false,
|
|
2530
|
+
enumerable: false,
|
|
2531
|
+
writable: true,
|
|
2532
|
+
value: null
|
|
2533
|
+
});
|
|
2534
|
+
Object.defineProperty(type, "_debugStack", {
|
|
2535
|
+
configurable: false,
|
|
2536
|
+
enumerable: false,
|
|
2537
|
+
writable: true,
|
|
2538
|
+
value: debugStack
|
|
2539
|
+
});
|
|
2540
|
+
Object.defineProperty(type, "_debugTask", {
|
|
2541
|
+
configurable: false,
|
|
2542
|
+
enumerable: false,
|
|
2543
|
+
writable: true,
|
|
2544
|
+
value: debugTask
|
|
2545
|
+
});
|
|
2546
|
+
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
|
2547
|
+
return type;
|
|
2548
|
+
}
|
|
2549
|
+
function cloneAndReplaceKey(oldElement, newKey) {
|
|
2550
|
+
newKey = ReactElement(oldElement.type, newKey, oldElement.props, oldElement._owner, oldElement._debugStack, oldElement._debugTask);
|
|
2551
|
+
oldElement._store && (newKey._store.validated = oldElement._store.validated);
|
|
2552
|
+
return newKey;
|
|
2553
|
+
}
|
|
2554
|
+
function validateChildKeys(node) {
|
|
2555
|
+
isValidElement(node) ? node._store && (node._store.validated = 1) : typeof node === "object" && node !== null && node.$$typeof === REACT_LAZY_TYPE && (node._payload.status === "fulfilled" ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1));
|
|
2556
|
+
}
|
|
2557
|
+
function isValidElement(object) {
|
|
2558
|
+
return typeof object === "object" && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
2559
|
+
}
|
|
2560
|
+
function escape(key) {
|
|
2561
|
+
var escaperLookup = { "=": "=0", ":": "=2" };
|
|
2562
|
+
return "$" + key.replace(/[=:]/g, function(match) {
|
|
2563
|
+
return escaperLookup[match];
|
|
2564
|
+
});
|
|
2565
|
+
}
|
|
2566
|
+
function getElementKey(element, index) {
|
|
2567
|
+
return typeof element === "object" && element !== null && element.key != null ? (checkKeyStringCoercion(element.key), escape("" + element.key)) : index.toString(36);
|
|
2568
|
+
}
|
|
2569
|
+
function resolveThenable(thenable) {
|
|
2570
|
+
switch (thenable.status) {
|
|
2571
|
+
case "fulfilled":
|
|
2572
|
+
return thenable.value;
|
|
2573
|
+
case "rejected":
|
|
2574
|
+
throw thenable.reason;
|
|
2575
|
+
default:
|
|
2576
|
+
switch (typeof thenable.status === "string" ? thenable.then(noop, noop) : (thenable.status = "pending", thenable.then(function(fulfilledValue) {
|
|
2577
|
+
thenable.status === "pending" && (thenable.status = "fulfilled", thenable.value = fulfilledValue);
|
|
2578
|
+
}, function(error) {
|
|
2579
|
+
thenable.status === "pending" && (thenable.status = "rejected", thenable.reason = error);
|
|
2580
|
+
})), thenable.status) {
|
|
2581
|
+
case "fulfilled":
|
|
2582
|
+
return thenable.value;
|
|
2583
|
+
case "rejected":
|
|
2584
|
+
throw thenable.reason;
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
throw thenable;
|
|
2588
|
+
}
|
|
2589
|
+
function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
|
|
2590
|
+
var type = typeof children;
|
|
2591
|
+
if (type === "undefined" || type === "boolean")
|
|
2592
|
+
children = null;
|
|
2593
|
+
var invokeCallback = false;
|
|
2594
|
+
if (children === null)
|
|
2595
|
+
invokeCallback = true;
|
|
2596
|
+
else
|
|
2597
|
+
switch (type) {
|
|
2598
|
+
case "bigint":
|
|
2599
|
+
case "string":
|
|
2600
|
+
case "number":
|
|
2601
|
+
invokeCallback = true;
|
|
2602
|
+
break;
|
|
2603
|
+
case "object":
|
|
2604
|
+
switch (children.$$typeof) {
|
|
2605
|
+
case REACT_ELEMENT_TYPE:
|
|
2606
|
+
case REACT_PORTAL_TYPE:
|
|
2607
|
+
invokeCallback = true;
|
|
2608
|
+
break;
|
|
2609
|
+
case REACT_LAZY_TYPE:
|
|
2610
|
+
return invokeCallback = children._init, mapIntoArray(invokeCallback(children._payload), array, escapedPrefix, nameSoFar, callback);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
if (invokeCallback) {
|
|
2614
|
+
invokeCallback = children;
|
|
2615
|
+
callback = callback(invokeCallback);
|
|
2616
|
+
var childKey = nameSoFar === "" ? "." + getElementKey(invokeCallback, 0) : nameSoFar;
|
|
2617
|
+
isArrayImpl(callback) ? (escapedPrefix = "", childKey != null && (escapedPrefix = childKey.replace(userProvidedKeyEscapeRegex, "$&/") + "/"), mapIntoArray(callback, array, escapedPrefix, "", function(c) {
|
|
2618
|
+
return c;
|
|
2619
|
+
})) : callback != null && (isValidElement(callback) && (callback.key != null && (invokeCallback && invokeCallback.key === callback.key || checkKeyStringCoercion(callback.key)), escapedPrefix = cloneAndReplaceKey(callback, escapedPrefix + (callback.key == null || invokeCallback && invokeCallback.key === callback.key ? "" : ("" + callback.key).replace(userProvidedKeyEscapeRegex, "$&/") + "/") + childKey), nameSoFar !== "" && invokeCallback != null && isValidElement(invokeCallback) && invokeCallback.key == null && invokeCallback._store && !invokeCallback._store.validated && (escapedPrefix._store.validated = 2), callback = escapedPrefix), array.push(callback));
|
|
2620
|
+
return 1;
|
|
2621
|
+
}
|
|
2622
|
+
invokeCallback = 0;
|
|
2623
|
+
childKey = nameSoFar === "" ? "." : nameSoFar + ":";
|
|
2624
|
+
if (isArrayImpl(children))
|
|
2625
|
+
for (var i = 0;i < children.length; i++)
|
|
2626
|
+
nameSoFar = children[i], type = childKey + getElementKey(nameSoFar, i), invokeCallback += mapIntoArray(nameSoFar, array, escapedPrefix, type, callback);
|
|
2627
|
+
else if (i = getIteratorFn(children), typeof i === "function")
|
|
2628
|
+
for (i === children.entries && (didWarnAboutMaps || console.warn("Using Maps as children is not supported. Use an array of keyed ReactElements instead."), didWarnAboutMaps = true), children = i.call(children), i = 0;!(nameSoFar = children.next()).done; )
|
|
2629
|
+
nameSoFar = nameSoFar.value, type = childKey + getElementKey(nameSoFar, i++), invokeCallback += mapIntoArray(nameSoFar, array, escapedPrefix, type, callback);
|
|
2630
|
+
else if (type === "object") {
|
|
2631
|
+
if (typeof children.then === "function")
|
|
2632
|
+
return mapIntoArray(resolveThenable(children), array, escapedPrefix, nameSoFar, callback);
|
|
2633
|
+
array = String(children);
|
|
2634
|
+
throw Error("Objects are not valid as a React child (found: " + (array === "[object Object]" ? "object with keys {" + Object.keys(children).join(", ") + "}" : array) + "). If you meant to render a collection of children, use an array instead.");
|
|
2635
|
+
}
|
|
2636
|
+
return invokeCallback;
|
|
2637
|
+
}
|
|
2638
|
+
function mapChildren(children, func, context) {
|
|
2639
|
+
if (children == null)
|
|
2640
|
+
return children;
|
|
2641
|
+
var result = [], count = 0;
|
|
2642
|
+
mapIntoArray(children, result, "", "", function(child) {
|
|
2643
|
+
return func.call(context, child, count++);
|
|
2644
|
+
});
|
|
2645
|
+
return result;
|
|
2646
|
+
}
|
|
2647
|
+
function lazyInitializer(payload) {
|
|
2648
|
+
if (payload._status === -1) {
|
|
2649
|
+
var ioInfo = payload._ioInfo;
|
|
2650
|
+
ioInfo != null && (ioInfo.start = ioInfo.end = performance.now());
|
|
2651
|
+
ioInfo = payload._result;
|
|
2652
|
+
var thenable = ioInfo();
|
|
2653
|
+
thenable.then(function(moduleObject) {
|
|
2654
|
+
if (payload._status === 0 || payload._status === -1) {
|
|
2655
|
+
payload._status = 1;
|
|
2656
|
+
payload._result = moduleObject;
|
|
2657
|
+
var _ioInfo = payload._ioInfo;
|
|
2658
|
+
_ioInfo != null && (_ioInfo.end = performance.now());
|
|
2659
|
+
thenable.status === undefined && (thenable.status = "fulfilled", thenable.value = moduleObject);
|
|
2660
|
+
}
|
|
2661
|
+
}, function(error) {
|
|
2662
|
+
if (payload._status === 0 || payload._status === -1) {
|
|
2663
|
+
payload._status = 2;
|
|
2664
|
+
payload._result = error;
|
|
2665
|
+
var _ioInfo2 = payload._ioInfo;
|
|
2666
|
+
_ioInfo2 != null && (_ioInfo2.end = performance.now());
|
|
2667
|
+
thenable.status === undefined && (thenable.status = "rejected", thenable.reason = error);
|
|
2668
|
+
}
|
|
2669
|
+
});
|
|
2670
|
+
ioInfo = payload._ioInfo;
|
|
2671
|
+
if (ioInfo != null) {
|
|
2672
|
+
ioInfo.value = thenable;
|
|
2673
|
+
var displayName = thenable.displayName;
|
|
2674
|
+
typeof displayName === "string" && (ioInfo.name = displayName);
|
|
2675
|
+
}
|
|
2676
|
+
payload._status === -1 && (payload._status = 0, payload._result = thenable);
|
|
2677
|
+
}
|
|
2678
|
+
if (payload._status === 1)
|
|
2679
|
+
return ioInfo = payload._result, ioInfo === undefined && console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
2680
|
+
|
|
2681
|
+
Your code should look like:
|
|
2682
|
+
const MyComponent = lazy(() => import('./MyComponent'))
|
|
2683
|
+
|
|
2684
|
+
Did you accidentally put curly braces around the import?`, ioInfo), "default" in ioInfo || console.error(`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
2685
|
+
|
|
2686
|
+
Your code should look like:
|
|
2687
|
+
const MyComponent = lazy(() => import('./MyComponent'))`, ioInfo), ioInfo.default;
|
|
2688
|
+
throw payload._result;
|
|
2689
|
+
}
|
|
2690
|
+
function resolveDispatcher() {
|
|
2691
|
+
var dispatcher = ReactSharedInternals.H;
|
|
2692
|
+
dispatcher === null && console.error(`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
|
2693
|
+
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
|
2694
|
+
2. You might be breaking the Rules of Hooks
|
|
2695
|
+
3. You might have more than one copy of React in the same app
|
|
2696
|
+
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`);
|
|
2697
|
+
return dispatcher;
|
|
2698
|
+
}
|
|
2699
|
+
function releaseAsyncTransition() {
|
|
2700
|
+
ReactSharedInternals.asyncTransitions--;
|
|
2701
|
+
}
|
|
2702
|
+
function enqueueTask(task) {
|
|
2703
|
+
if (enqueueTaskImpl === null)
|
|
2704
|
+
try {
|
|
2705
|
+
var requireString = ("require" + Math.random()).slice(0, 7);
|
|
2706
|
+
enqueueTaskImpl = (module && module[requireString]).call(module, "timers").setImmediate;
|
|
2707
|
+
} catch (_err) {
|
|
2708
|
+
enqueueTaskImpl = function(callback) {
|
|
2709
|
+
didWarnAboutMessageChannel === false && (didWarnAboutMessageChannel = true, typeof MessageChannel === "undefined" && console.error("This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."));
|
|
2710
|
+
var channel = new MessageChannel;
|
|
2711
|
+
channel.port1.onmessage = callback;
|
|
2712
|
+
channel.port2.postMessage(undefined);
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
return enqueueTaskImpl(task);
|
|
2716
|
+
}
|
|
2717
|
+
function aggregateErrors(errors) {
|
|
2718
|
+
return 1 < errors.length && typeof AggregateError === "function" ? new AggregateError(errors) : errors[0];
|
|
2719
|
+
}
|
|
2720
|
+
function popActScope(prevActQueue, prevActScopeDepth) {
|
|
2721
|
+
prevActScopeDepth !== actScopeDepth - 1 && console.error("You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. ");
|
|
2722
|
+
actScopeDepth = prevActScopeDepth;
|
|
2723
|
+
}
|
|
2724
|
+
function recursivelyFlushAsyncActWork(returnValue, resolve, reject) {
|
|
2725
|
+
var queue = ReactSharedInternals.actQueue;
|
|
2726
|
+
if (queue !== null)
|
|
2727
|
+
if (queue.length !== 0)
|
|
2728
|
+
try {
|
|
2729
|
+
flushActQueue(queue);
|
|
2730
|
+
enqueueTask(function() {
|
|
2731
|
+
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
|
|
2732
|
+
});
|
|
2733
|
+
return;
|
|
2734
|
+
} catch (error) {
|
|
2735
|
+
ReactSharedInternals.thrownErrors.push(error);
|
|
2736
|
+
}
|
|
2737
|
+
else
|
|
2738
|
+
ReactSharedInternals.actQueue = null;
|
|
2739
|
+
0 < ReactSharedInternals.thrownErrors.length ? (queue = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(queue)) : resolve(returnValue);
|
|
2740
|
+
}
|
|
2741
|
+
function flushActQueue(queue) {
|
|
2742
|
+
if (!isFlushing) {
|
|
2743
|
+
isFlushing = true;
|
|
2744
|
+
var i = 0;
|
|
2745
|
+
try {
|
|
2746
|
+
for (;i < queue.length; i++) {
|
|
2747
|
+
var callback = queue[i];
|
|
2748
|
+
do {
|
|
2749
|
+
ReactSharedInternals.didUsePromise = false;
|
|
2750
|
+
var continuation = callback(false);
|
|
2751
|
+
if (continuation !== null) {
|
|
2752
|
+
if (ReactSharedInternals.didUsePromise) {
|
|
2753
|
+
queue[i] = callback;
|
|
2754
|
+
queue.splice(0, i);
|
|
2755
|
+
return;
|
|
2756
|
+
}
|
|
2757
|
+
callback = continuation;
|
|
2758
|
+
} else
|
|
2759
|
+
break;
|
|
2760
|
+
} while (1);
|
|
2761
|
+
}
|
|
2762
|
+
queue.length = 0;
|
|
2763
|
+
} catch (error) {
|
|
2764
|
+
queue.splice(0, i + 1), ReactSharedInternals.thrownErrors.push(error);
|
|
2765
|
+
} finally {
|
|
2766
|
+
isFlushing = false;
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
2771
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = Symbol.for("react.activity"), MAYBE_ITERATOR_SYMBOL = Symbol.iterator, didWarnStateUpdateForUnmountedComponent = {}, ReactNoopUpdateQueue = {
|
|
2772
|
+
isMounted: function() {
|
|
2773
|
+
return false;
|
|
2774
|
+
},
|
|
2775
|
+
enqueueForceUpdate: function(publicInstance) {
|
|
2776
|
+
warnNoop(publicInstance, "forceUpdate");
|
|
2777
|
+
},
|
|
2778
|
+
enqueueReplaceState: function(publicInstance) {
|
|
2779
|
+
warnNoop(publicInstance, "replaceState");
|
|
2780
|
+
},
|
|
2781
|
+
enqueueSetState: function(publicInstance) {
|
|
2782
|
+
warnNoop(publicInstance, "setState");
|
|
2783
|
+
}
|
|
2784
|
+
}, assign = Object.assign, emptyObject = {};
|
|
2785
|
+
Object.freeze(emptyObject);
|
|
2786
|
+
Component.prototype.isReactComponent = {};
|
|
2787
|
+
Component.prototype.setState = function(partialState, callback) {
|
|
2788
|
+
if (typeof partialState !== "object" && typeof partialState !== "function" && partialState != null)
|
|
2789
|
+
throw Error("takes an object of state variables to update or a function which returns an object of state variables.");
|
|
2790
|
+
this.updater.enqueueSetState(this, partialState, callback, "setState");
|
|
2791
|
+
};
|
|
2792
|
+
Component.prototype.forceUpdate = function(callback) {
|
|
2793
|
+
this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
|
|
2794
|
+
};
|
|
2795
|
+
var deprecatedAPIs = {
|
|
2796
|
+
isMounted: [
|
|
2797
|
+
"isMounted",
|
|
2798
|
+
"Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
|
|
2799
|
+
],
|
|
2800
|
+
replaceState: [
|
|
2801
|
+
"replaceState",
|
|
2802
|
+
"Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
|
|
2803
|
+
]
|
|
2804
|
+
};
|
|
2805
|
+
for (fnName in deprecatedAPIs)
|
|
2806
|
+
deprecatedAPIs.hasOwnProperty(fnName) && defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
|
|
2807
|
+
ComponentDummy.prototype = Component.prototype;
|
|
2808
|
+
deprecatedAPIs = PureComponent.prototype = new ComponentDummy;
|
|
2809
|
+
deprecatedAPIs.constructor = PureComponent;
|
|
2810
|
+
assign(deprecatedAPIs, Component.prototype);
|
|
2811
|
+
deprecatedAPIs.isPureReactComponent = true;
|
|
2812
|
+
var isArrayImpl = Array.isArray, REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = {
|
|
2813
|
+
H: null,
|
|
2814
|
+
A: null,
|
|
2815
|
+
T: null,
|
|
2816
|
+
S: null,
|
|
2817
|
+
actQueue: null,
|
|
2818
|
+
asyncTransitions: 0,
|
|
2819
|
+
isBatchingLegacy: false,
|
|
2820
|
+
didScheduleLegacyUpdate: false,
|
|
2821
|
+
didUsePromise: false,
|
|
2822
|
+
thrownErrors: [],
|
|
2823
|
+
getCurrentStack: null,
|
|
2824
|
+
recentlyCreatedOwnerStacks: 0
|
|
2825
|
+
}, hasOwnProperty = Object.prototype.hasOwnProperty, createTask = console.createTask ? console.createTask : function() {
|
|
2826
|
+
return null;
|
|
2827
|
+
};
|
|
2828
|
+
deprecatedAPIs = {
|
|
2829
|
+
react_stack_bottom_frame: function(callStackForError) {
|
|
2830
|
+
return callStackForError();
|
|
2831
|
+
}
|
|
2832
|
+
};
|
|
2833
|
+
var specialPropKeyWarningShown, didWarnAboutOldJSXRuntime;
|
|
2834
|
+
var didWarnAboutElementRef = {};
|
|
2835
|
+
var unknownOwnerDebugStack = deprecatedAPIs.react_stack_bottom_frame.bind(deprecatedAPIs, UnknownOwner)();
|
|
2836
|
+
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
2837
|
+
var didWarnAboutMaps = false, userProvidedKeyEscapeRegex = /\/+/g, reportGlobalError = typeof reportError === "function" ? reportError : function(error) {
|
|
2838
|
+
if (typeof window === "object" && typeof window.ErrorEvent === "function") {
|
|
2839
|
+
var event = new window.ErrorEvent("error", {
|
|
2840
|
+
bubbles: true,
|
|
2841
|
+
cancelable: true,
|
|
2842
|
+
message: typeof error === "object" && error !== null && typeof error.message === "string" ? String(error.message) : String(error),
|
|
2843
|
+
error
|
|
2844
|
+
});
|
|
2845
|
+
if (!window.dispatchEvent(event))
|
|
2846
|
+
return;
|
|
2847
|
+
} else if (typeof process === "object" && typeof process.emit === "function") {
|
|
2848
|
+
process.emit("uncaughtException", error);
|
|
2849
|
+
return;
|
|
2850
|
+
}
|
|
2851
|
+
console.error(error);
|
|
2852
|
+
}, didWarnAboutMessageChannel = false, enqueueTaskImpl = null, actScopeDepth = 0, didWarnNoAwaitAct = false, isFlushing = false, queueSeveralMicrotasks = typeof queueMicrotask === "function" ? function(callback) {
|
|
2853
|
+
queueMicrotask(function() {
|
|
2854
|
+
return queueMicrotask(callback);
|
|
2855
|
+
});
|
|
2856
|
+
} : enqueueTask;
|
|
2857
|
+
deprecatedAPIs = Object.freeze({
|
|
2858
|
+
__proto__: null,
|
|
2859
|
+
c: function(size) {
|
|
2860
|
+
return resolveDispatcher().useMemoCache(size);
|
|
2861
|
+
}
|
|
2862
|
+
});
|
|
2863
|
+
var fnName = {
|
|
2864
|
+
map: mapChildren,
|
|
2865
|
+
forEach: function(children, forEachFunc, forEachContext) {
|
|
2866
|
+
mapChildren(children, function() {
|
|
2867
|
+
forEachFunc.apply(this, arguments);
|
|
2868
|
+
}, forEachContext);
|
|
2869
|
+
},
|
|
2870
|
+
count: function(children) {
|
|
2871
|
+
var n = 0;
|
|
2872
|
+
mapChildren(children, function() {
|
|
2873
|
+
n++;
|
|
2874
|
+
});
|
|
2875
|
+
return n;
|
|
2876
|
+
},
|
|
2877
|
+
toArray: function(children) {
|
|
2878
|
+
return mapChildren(children, function(child) {
|
|
2879
|
+
return child;
|
|
2880
|
+
}) || [];
|
|
2881
|
+
},
|
|
2882
|
+
only: function(children) {
|
|
2883
|
+
if (!isValidElement(children))
|
|
2884
|
+
throw Error("React.Children.only expected to receive a single React element child.");
|
|
2885
|
+
return children;
|
|
2886
|
+
}
|
|
2887
|
+
};
|
|
2888
|
+
exports.Activity = REACT_ACTIVITY_TYPE;
|
|
2889
|
+
exports.Children = fnName;
|
|
2890
|
+
exports.Component = Component;
|
|
2891
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
2892
|
+
exports.Profiler = REACT_PROFILER_TYPE;
|
|
2893
|
+
exports.PureComponent = PureComponent;
|
|
2894
|
+
exports.StrictMode = REACT_STRICT_MODE_TYPE;
|
|
2895
|
+
exports.Suspense = REACT_SUSPENSE_TYPE;
|
|
2896
|
+
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = ReactSharedInternals;
|
|
2897
|
+
exports.__COMPILER_RUNTIME = deprecatedAPIs;
|
|
2898
|
+
exports.act = function(callback) {
|
|
2899
|
+
var prevActQueue = ReactSharedInternals.actQueue, prevActScopeDepth = actScopeDepth;
|
|
2900
|
+
actScopeDepth++;
|
|
2901
|
+
var queue = ReactSharedInternals.actQueue = prevActQueue !== null ? prevActQueue : [], didAwaitActCall = false;
|
|
2902
|
+
try {
|
|
2903
|
+
var result = callback();
|
|
2904
|
+
} catch (error) {
|
|
2905
|
+
ReactSharedInternals.thrownErrors.push(error);
|
|
2906
|
+
}
|
|
2907
|
+
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
2908
|
+
throw popActScope(prevActQueue, prevActScopeDepth), callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
2909
|
+
if (result !== null && typeof result === "object" && typeof result.then === "function") {
|
|
2910
|
+
var thenable = result;
|
|
2911
|
+
queueSeveralMicrotasks(function() {
|
|
2912
|
+
didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error("You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"));
|
|
2913
|
+
});
|
|
2914
|
+
return {
|
|
2915
|
+
then: function(resolve, reject) {
|
|
2916
|
+
didAwaitActCall = true;
|
|
2917
|
+
thenable.then(function(returnValue) {
|
|
2918
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
2919
|
+
if (prevActScopeDepth === 0) {
|
|
2920
|
+
try {
|
|
2921
|
+
flushActQueue(queue), enqueueTask(function() {
|
|
2922
|
+
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
|
|
2923
|
+
});
|
|
2924
|
+
} catch (error$0) {
|
|
2925
|
+
ReactSharedInternals.thrownErrors.push(error$0);
|
|
2926
|
+
}
|
|
2927
|
+
if (0 < ReactSharedInternals.thrownErrors.length) {
|
|
2928
|
+
var _thrownError = aggregateErrors(ReactSharedInternals.thrownErrors);
|
|
2929
|
+
ReactSharedInternals.thrownErrors.length = 0;
|
|
2930
|
+
reject(_thrownError);
|
|
2931
|
+
}
|
|
2932
|
+
} else
|
|
2933
|
+
resolve(returnValue);
|
|
2934
|
+
}, function(error) {
|
|
2935
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
2936
|
+
0 < ReactSharedInternals.thrownErrors.length ? (error = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(error)) : reject(error);
|
|
2937
|
+
});
|
|
2938
|
+
}
|
|
2939
|
+
};
|
|
2940
|
+
}
|
|
2941
|
+
var returnValue$jscomp$0 = result;
|
|
2942
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
2943
|
+
prevActScopeDepth === 0 && (flushActQueue(queue), queue.length !== 0 && queueSeveralMicrotasks(function() {
|
|
2944
|
+
didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error("A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)"));
|
|
2945
|
+
}), ReactSharedInternals.actQueue = null);
|
|
2946
|
+
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
2947
|
+
throw callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
2948
|
+
return {
|
|
2949
|
+
then: function(resolve, reject) {
|
|
2950
|
+
didAwaitActCall = true;
|
|
2951
|
+
prevActScopeDepth === 0 ? (ReactSharedInternals.actQueue = queue, enqueueTask(function() {
|
|
2952
|
+
return recursivelyFlushAsyncActWork(returnValue$jscomp$0, resolve, reject);
|
|
2953
|
+
})) : resolve(returnValue$jscomp$0);
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
};
|
|
2957
|
+
exports.cache = function(fn) {
|
|
2958
|
+
return function() {
|
|
2959
|
+
return fn.apply(null, arguments);
|
|
2960
|
+
};
|
|
2961
|
+
};
|
|
2962
|
+
exports.cacheSignal = function() {
|
|
2963
|
+
return null;
|
|
2964
|
+
};
|
|
2965
|
+
exports.captureOwnerStack = function() {
|
|
2966
|
+
var getCurrentStack = ReactSharedInternals.getCurrentStack;
|
|
2967
|
+
return getCurrentStack === null ? null : getCurrentStack();
|
|
2968
|
+
};
|
|
2969
|
+
exports.cloneElement = function(element, config, children) {
|
|
2970
|
+
if (element === null || element === undefined)
|
|
2971
|
+
throw Error("The argument must be a React element, but you passed " + element + ".");
|
|
2972
|
+
var props = assign({}, element.props), key = element.key, owner = element._owner;
|
|
2973
|
+
if (config != null) {
|
|
2974
|
+
var JSCompiler_inline_result;
|
|
2975
|
+
a: {
|
|
2976
|
+
if (hasOwnProperty.call(config, "ref") && (JSCompiler_inline_result = Object.getOwnPropertyDescriptor(config, "ref").get) && JSCompiler_inline_result.isReactWarning) {
|
|
2977
|
+
JSCompiler_inline_result = false;
|
|
2978
|
+
break a;
|
|
2979
|
+
}
|
|
2980
|
+
JSCompiler_inline_result = config.ref !== undefined;
|
|
2981
|
+
}
|
|
2982
|
+
JSCompiler_inline_result && (owner = getOwner());
|
|
2983
|
+
hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key);
|
|
2984
|
+
for (propName in config)
|
|
2985
|
+
!hasOwnProperty.call(config, propName) || propName === "key" || propName === "__self" || propName === "__source" || propName === "ref" && config.ref === undefined || (props[propName] = config[propName]);
|
|
2986
|
+
}
|
|
2987
|
+
var propName = arguments.length - 2;
|
|
2988
|
+
if (propName === 1)
|
|
2989
|
+
props.children = children;
|
|
2990
|
+
else if (1 < propName) {
|
|
2991
|
+
JSCompiler_inline_result = Array(propName);
|
|
2992
|
+
for (var i = 0;i < propName; i++)
|
|
2993
|
+
JSCompiler_inline_result[i] = arguments[i + 2];
|
|
2994
|
+
props.children = JSCompiler_inline_result;
|
|
2995
|
+
}
|
|
2996
|
+
props = ReactElement(element.type, key, props, owner, element._debugStack, element._debugTask);
|
|
2997
|
+
for (key = 2;key < arguments.length; key++)
|
|
2998
|
+
validateChildKeys(arguments[key]);
|
|
2999
|
+
return props;
|
|
3000
|
+
};
|
|
3001
|
+
exports.createContext = function(defaultValue) {
|
|
3002
|
+
defaultValue = {
|
|
3003
|
+
$$typeof: REACT_CONTEXT_TYPE,
|
|
3004
|
+
_currentValue: defaultValue,
|
|
3005
|
+
_currentValue2: defaultValue,
|
|
3006
|
+
_threadCount: 0,
|
|
3007
|
+
Provider: null,
|
|
3008
|
+
Consumer: null
|
|
3009
|
+
};
|
|
3010
|
+
defaultValue.Provider = defaultValue;
|
|
3011
|
+
defaultValue.Consumer = {
|
|
3012
|
+
$$typeof: REACT_CONSUMER_TYPE,
|
|
3013
|
+
_context: defaultValue
|
|
3014
|
+
};
|
|
3015
|
+
defaultValue._currentRenderer = null;
|
|
3016
|
+
defaultValue._currentRenderer2 = null;
|
|
3017
|
+
return defaultValue;
|
|
3018
|
+
};
|
|
3019
|
+
exports.createElement = function(type, config, children) {
|
|
3020
|
+
for (var i = 2;i < arguments.length; i++)
|
|
3021
|
+
validateChildKeys(arguments[i]);
|
|
3022
|
+
i = {};
|
|
3023
|
+
var key = null;
|
|
3024
|
+
if (config != null)
|
|
3025
|
+
for (propName in didWarnAboutOldJSXRuntime || !("__self" in config) || "key" in config || (didWarnAboutOldJSXRuntime = true, console.warn("Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform")), hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key), config)
|
|
3026
|
+
hasOwnProperty.call(config, propName) && propName !== "key" && propName !== "__self" && propName !== "__source" && (i[propName] = config[propName]);
|
|
3027
|
+
var childrenLength = arguments.length - 2;
|
|
3028
|
+
if (childrenLength === 1)
|
|
3029
|
+
i.children = children;
|
|
3030
|
+
else if (1 < childrenLength) {
|
|
3031
|
+
for (var childArray = Array(childrenLength), _i = 0;_i < childrenLength; _i++)
|
|
3032
|
+
childArray[_i] = arguments[_i + 2];
|
|
3033
|
+
Object.freeze && Object.freeze(childArray);
|
|
3034
|
+
i.children = childArray;
|
|
3035
|
+
}
|
|
3036
|
+
if (type && type.defaultProps)
|
|
3037
|
+
for (propName in childrenLength = type.defaultProps, childrenLength)
|
|
3038
|
+
i[propName] === undefined && (i[propName] = childrenLength[propName]);
|
|
3039
|
+
key && defineKeyPropWarningGetter(i, typeof type === "function" ? type.displayName || type.name || "Unknown" : type);
|
|
3040
|
+
var propName = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
3041
|
+
return ReactElement(type, key, i, getOwner(), propName ? Error("react-stack-top-frame") : unknownOwnerDebugStack, propName ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
|
|
3042
|
+
};
|
|
3043
|
+
exports.createRef = function() {
|
|
3044
|
+
var refObject = { current: null };
|
|
3045
|
+
Object.seal(refObject);
|
|
3046
|
+
return refObject;
|
|
3047
|
+
};
|
|
3048
|
+
exports.forwardRef = function(render) {
|
|
3049
|
+
render != null && render.$$typeof === REACT_MEMO_TYPE ? console.error("forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...)).") : typeof render !== "function" ? console.error("forwardRef requires a render function but was given %s.", render === null ? "null" : typeof render) : render.length !== 0 && render.length !== 2 && console.error("forwardRef render functions accept exactly two parameters: props and ref. %s", render.length === 1 ? "Did you forget to use the ref parameter?" : "Any additional parameter will be undefined.");
|
|
3050
|
+
render != null && render.defaultProps != null && console.error("forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?");
|
|
3051
|
+
var elementType = { $$typeof: REACT_FORWARD_REF_TYPE, render }, ownName;
|
|
3052
|
+
Object.defineProperty(elementType, "displayName", {
|
|
3053
|
+
enumerable: false,
|
|
3054
|
+
configurable: true,
|
|
3055
|
+
get: function() {
|
|
3056
|
+
return ownName;
|
|
3057
|
+
},
|
|
3058
|
+
set: function(name) {
|
|
3059
|
+
ownName = name;
|
|
3060
|
+
render.name || render.displayName || (Object.defineProperty(render, "name", { value: name }), render.displayName = name);
|
|
3061
|
+
}
|
|
3062
|
+
});
|
|
3063
|
+
return elementType;
|
|
3064
|
+
};
|
|
3065
|
+
exports.isValidElement = isValidElement;
|
|
3066
|
+
exports.lazy = function(ctor) {
|
|
3067
|
+
ctor = { _status: -1, _result: ctor };
|
|
3068
|
+
var lazyType = {
|
|
3069
|
+
$$typeof: REACT_LAZY_TYPE,
|
|
3070
|
+
_payload: ctor,
|
|
3071
|
+
_init: lazyInitializer
|
|
3072
|
+
}, ioInfo = {
|
|
3073
|
+
name: "lazy",
|
|
3074
|
+
start: -1,
|
|
3075
|
+
end: -1,
|
|
3076
|
+
value: null,
|
|
3077
|
+
owner: null,
|
|
3078
|
+
debugStack: Error("react-stack-top-frame"),
|
|
3079
|
+
debugTask: console.createTask ? console.createTask("lazy()") : null
|
|
3080
|
+
};
|
|
3081
|
+
ctor._ioInfo = ioInfo;
|
|
3082
|
+
lazyType._debugInfo = [{ awaited: ioInfo }];
|
|
3083
|
+
return lazyType;
|
|
3084
|
+
};
|
|
3085
|
+
exports.memo = function(type, compare) {
|
|
3086
|
+
type == null && console.error("memo: The first argument must be a component. Instead received: %s", type === null ? "null" : typeof type);
|
|
3087
|
+
compare = {
|
|
3088
|
+
$$typeof: REACT_MEMO_TYPE,
|
|
3089
|
+
type,
|
|
3090
|
+
compare: compare === undefined ? null : compare
|
|
3091
|
+
};
|
|
3092
|
+
var ownName;
|
|
3093
|
+
Object.defineProperty(compare, "displayName", {
|
|
3094
|
+
enumerable: false,
|
|
3095
|
+
configurable: true,
|
|
3096
|
+
get: function() {
|
|
3097
|
+
return ownName;
|
|
3098
|
+
},
|
|
3099
|
+
set: function(name) {
|
|
3100
|
+
ownName = name;
|
|
3101
|
+
type.name || type.displayName || (Object.defineProperty(type, "name", { value: name }), type.displayName = name);
|
|
3102
|
+
}
|
|
3103
|
+
});
|
|
3104
|
+
return compare;
|
|
3105
|
+
};
|
|
3106
|
+
exports.startTransition = function(scope) {
|
|
3107
|
+
var prevTransition = ReactSharedInternals.T, currentTransition = {};
|
|
3108
|
+
currentTransition._updatedFibers = new Set;
|
|
3109
|
+
ReactSharedInternals.T = currentTransition;
|
|
3110
|
+
try {
|
|
3111
|
+
var returnValue = scope(), onStartTransitionFinish = ReactSharedInternals.S;
|
|
3112
|
+
onStartTransitionFinish !== null && onStartTransitionFinish(currentTransition, returnValue);
|
|
3113
|
+
typeof returnValue === "object" && returnValue !== null && typeof returnValue.then === "function" && (ReactSharedInternals.asyncTransitions++, returnValue.then(releaseAsyncTransition, releaseAsyncTransition), returnValue.then(noop, reportGlobalError));
|
|
3114
|
+
} catch (error) {
|
|
3115
|
+
reportGlobalError(error);
|
|
3116
|
+
} finally {
|
|
3117
|
+
prevTransition === null && currentTransition._updatedFibers && (scope = currentTransition._updatedFibers.size, currentTransition._updatedFibers.clear(), 10 < scope && console.warn("Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table.")), prevTransition !== null && currentTransition.types !== null && (prevTransition.types !== null && prevTransition.types !== currentTransition.types && console.error("We expected inner Transitions to have transferred the outer types set and that you cannot add to the outer Transition while inside the inner.This is a bug in React."), prevTransition.types = currentTransition.types), ReactSharedInternals.T = prevTransition;
|
|
3118
|
+
}
|
|
3119
|
+
};
|
|
3120
|
+
exports.unstable_useCacheRefresh = function() {
|
|
3121
|
+
return resolveDispatcher().useCacheRefresh();
|
|
3122
|
+
};
|
|
3123
|
+
exports.use = function(usable) {
|
|
3124
|
+
return resolveDispatcher().use(usable);
|
|
3125
|
+
};
|
|
3126
|
+
exports.useActionState = function(action, initialState, permalink) {
|
|
3127
|
+
return resolveDispatcher().useActionState(action, initialState, permalink);
|
|
3128
|
+
};
|
|
3129
|
+
exports.useCallback = function(callback, deps) {
|
|
3130
|
+
return resolveDispatcher().useCallback(callback, deps);
|
|
3131
|
+
};
|
|
3132
|
+
exports.useContext = function(Context) {
|
|
3133
|
+
var dispatcher = resolveDispatcher();
|
|
3134
|
+
Context.$$typeof === REACT_CONSUMER_TYPE && console.error("Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?");
|
|
3135
|
+
return dispatcher.useContext(Context);
|
|
3136
|
+
};
|
|
3137
|
+
exports.useDebugValue = function(value, formatterFn) {
|
|
3138
|
+
return resolveDispatcher().useDebugValue(value, formatterFn);
|
|
3139
|
+
};
|
|
3140
|
+
exports.useDeferredValue = function(value, initialValue) {
|
|
3141
|
+
return resolveDispatcher().useDeferredValue(value, initialValue);
|
|
3142
|
+
};
|
|
3143
|
+
exports.useEffect = function(create, deps) {
|
|
3144
|
+
create == null && console.warn("React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
3145
|
+
return resolveDispatcher().useEffect(create, deps);
|
|
3146
|
+
};
|
|
3147
|
+
exports.useEffectEvent = function(callback) {
|
|
3148
|
+
return resolveDispatcher().useEffectEvent(callback);
|
|
3149
|
+
};
|
|
3150
|
+
exports.useId = function() {
|
|
3151
|
+
return resolveDispatcher().useId();
|
|
3152
|
+
};
|
|
3153
|
+
exports.useImperativeHandle = function(ref, create, deps) {
|
|
3154
|
+
return resolveDispatcher().useImperativeHandle(ref, create, deps);
|
|
3155
|
+
};
|
|
3156
|
+
exports.useInsertionEffect = function(create, deps) {
|
|
3157
|
+
create == null && console.warn("React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
3158
|
+
return resolveDispatcher().useInsertionEffect(create, deps);
|
|
3159
|
+
};
|
|
3160
|
+
exports.useLayoutEffect = function(create, deps) {
|
|
3161
|
+
create == null && console.warn("React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?");
|
|
3162
|
+
return resolveDispatcher().useLayoutEffect(create, deps);
|
|
3163
|
+
};
|
|
3164
|
+
exports.useMemo = function(create, deps) {
|
|
3165
|
+
return resolveDispatcher().useMemo(create, deps);
|
|
3166
|
+
};
|
|
3167
|
+
exports.useOptimistic = function(passthrough, reducer) {
|
|
3168
|
+
return resolveDispatcher().useOptimistic(passthrough, reducer);
|
|
3169
|
+
};
|
|
3170
|
+
exports.useReducer = function(reducer, initialArg, init) {
|
|
3171
|
+
return resolveDispatcher().useReducer(reducer, initialArg, init);
|
|
3172
|
+
};
|
|
3173
|
+
exports.useRef = function(initialValue) {
|
|
3174
|
+
return resolveDispatcher().useRef(initialValue);
|
|
3175
|
+
};
|
|
3176
|
+
exports.useState = function(initialState) {
|
|
3177
|
+
return resolveDispatcher().useState(initialState);
|
|
3178
|
+
};
|
|
3179
|
+
exports.useSyncExternalStore = function(subscribe, getSnapshot, getServerSnapshot) {
|
|
3180
|
+
return resolveDispatcher().useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
3181
|
+
};
|
|
3182
|
+
exports.useTransition = function() {
|
|
3183
|
+
return resolveDispatcher().useTransition();
|
|
3184
|
+
};
|
|
3185
|
+
exports.version = "19.2.6";
|
|
3186
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
3187
|
+
})();
|
|
3188
|
+
});
|
|
3189
|
+
|
|
3190
|
+
// ../../node_modules/.bun/react@19.2.6/node_modules/react/index.js
|
|
3191
|
+
var require_react = __commonJS((exports, module) => {
|
|
3192
|
+
var react_development = __toESM(require_react_development());
|
|
3193
|
+
if (false) {} else {
|
|
3194
|
+
module.exports = react_development;
|
|
3195
|
+
}
|
|
3196
|
+
});
|
|
3197
|
+
|
|
3198
|
+
// ../../node_modules/.bun/zustand@5.0.13+e55371ec98c955e9/node_modules/zustand/react.js
|
|
3199
|
+
var require_react2 = __commonJS((exports) => {
|
|
3200
|
+
var React = __toESM(require_react());
|
|
3201
|
+
var vanilla = require_vanilla();
|
|
3202
|
+
var identity = (arg) => arg;
|
|
3203
|
+
function useStore(api, selector = identity) {
|
|
3204
|
+
const slice = React.useSyncExternalStore(api.subscribe, React.useCallback(() => selector(api.getState()), [api, selector]), React.useCallback(() => selector(api.getInitialState()), [api, selector]));
|
|
3205
|
+
React.useDebugValue(slice);
|
|
3206
|
+
return slice;
|
|
3207
|
+
}
|
|
3208
|
+
var createImpl = (createState) => {
|
|
3209
|
+
const api = vanilla.createStore(createState);
|
|
3210
|
+
const useBoundStore = (selector) => useStore(api, selector);
|
|
3211
|
+
Object.assign(useBoundStore, api);
|
|
3212
|
+
return useBoundStore;
|
|
3213
|
+
};
|
|
3214
|
+
var create = (createState) => createState ? createImpl(createState) : createImpl;
|
|
3215
|
+
exports.create = create;
|
|
3216
|
+
exports.useStore = useStore;
|
|
3217
|
+
});
|
|
3218
|
+
|
|
3219
|
+
// ../../node_modules/.bun/zustand@5.0.13+e55371ec98c955e9/node_modules/zustand/index.js
|
|
3220
|
+
var require_zustand = __commonJS((exports) => {
|
|
3221
|
+
var vanilla = require_vanilla();
|
|
3222
|
+
var react = require_react2();
|
|
3223
|
+
Object.keys(vanilla).forEach(function(k) {
|
|
3224
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
|
3225
|
+
Object.defineProperty(exports, k, {
|
|
3226
|
+
enumerable: true,
|
|
3227
|
+
get: function() {
|
|
3228
|
+
return vanilla[k];
|
|
3229
|
+
}
|
|
3230
|
+
});
|
|
3231
|
+
});
|
|
3232
|
+
Object.keys(react).forEach(function(k) {
|
|
3233
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
|
3234
|
+
Object.defineProperty(exports, k, {
|
|
3235
|
+
enumerable: true,
|
|
3236
|
+
get: function() {
|
|
3237
|
+
return react[k];
|
|
3238
|
+
}
|
|
3239
|
+
});
|
|
3240
|
+
});
|
|
3241
|
+
});
|
|
3242
|
+
|
|
3243
|
+
// ../../node_modules/.bun/zustand@5.0.13+e55371ec98c955e9/node_modules/zustand/middleware.js
|
|
3244
|
+
var require_middleware = __commonJS((exports) => {
|
|
3245
|
+
var reduxImpl = (reducer, initial) => (set, _get, api) => {
|
|
3246
|
+
api.dispatch = (action) => {
|
|
3247
|
+
set((state) => reducer(state, action), false, action);
|
|
3248
|
+
return action;
|
|
3249
|
+
};
|
|
3250
|
+
api.dispatchFromDevtools = true;
|
|
3251
|
+
return { dispatch: (...args) => api.dispatch(...args), ...initial };
|
|
3252
|
+
};
|
|
3253
|
+
var redux = reduxImpl;
|
|
3254
|
+
var shouldDispatchFromDevtools = (api) => !!api.dispatchFromDevtools && typeof api.dispatch === "function";
|
|
3255
|
+
var trackedConnections = /* @__PURE__ */ new Map;
|
|
3256
|
+
var getTrackedConnectionState = (name) => {
|
|
3257
|
+
const api = trackedConnections.get(name);
|
|
3258
|
+
if (!api)
|
|
3259
|
+
return {};
|
|
3260
|
+
return Object.fromEntries(Object.entries(api.stores).map(([key, api2]) => [key, api2.getState()]));
|
|
3261
|
+
};
|
|
3262
|
+
var extractConnectionInformation = (store, extensionConnector, options) => {
|
|
3263
|
+
if (store === undefined) {
|
|
3264
|
+
return {
|
|
3265
|
+
type: "untracked",
|
|
3266
|
+
connection: extensionConnector.connect(options)
|
|
3267
|
+
};
|
|
3268
|
+
}
|
|
3269
|
+
const existingConnection = trackedConnections.get(options.name);
|
|
3270
|
+
if (existingConnection) {
|
|
3271
|
+
return { type: "tracked", store, ...existingConnection };
|
|
3272
|
+
}
|
|
3273
|
+
const newConnection = {
|
|
3274
|
+
connection: extensionConnector.connect(options),
|
|
3275
|
+
stores: {}
|
|
3276
|
+
};
|
|
3277
|
+
trackedConnections.set(options.name, newConnection);
|
|
3278
|
+
return { type: "tracked", store, ...newConnection };
|
|
3279
|
+
};
|
|
3280
|
+
var removeStoreFromTrackedConnections = (name, store) => {
|
|
3281
|
+
if (store === undefined)
|
|
3282
|
+
return;
|
|
3283
|
+
const connectionInfo = trackedConnections.get(name);
|
|
3284
|
+
if (!connectionInfo)
|
|
3285
|
+
return;
|
|
3286
|
+
delete connectionInfo.stores[store];
|
|
3287
|
+
if (Object.keys(connectionInfo.stores).length === 0) {
|
|
3288
|
+
trackedConnections.delete(name);
|
|
3289
|
+
}
|
|
3290
|
+
};
|
|
3291
|
+
var v8StackLineRe = /.+ (.+) .+/;
|
|
3292
|
+
var geckoStackLineRe = /^([^@]+)@/;
|
|
3293
|
+
function findCallerName(stack) {
|
|
3294
|
+
var _a, _b, _c;
|
|
3295
|
+
if (!stack)
|
|
3296
|
+
return;
|
|
3297
|
+
const traceLines = stack.split(`
|
|
3298
|
+
`);
|
|
3299
|
+
const apiSetStateLineIndex = traceLines.findIndex((traceLine) => traceLine.includes("api.setState"));
|
|
3300
|
+
if (apiSetStateLineIndex < 0)
|
|
3301
|
+
return;
|
|
3302
|
+
const callerLine = ((_a = traceLines[apiSetStateLineIndex + 1]) == null ? undefined : _a.trim()) || "";
|
|
3303
|
+
return ((_b = v8StackLineRe.exec(callerLine)) == null ? undefined : _b[1]) || ((_c = geckoStackLineRe.exec(callerLine)) == null ? undefined : _c[1]);
|
|
3304
|
+
}
|
|
3305
|
+
var devtoolsImpl = (fn, devtoolsOptions = {}) => (set, get, api) => {
|
|
3306
|
+
const { enabled, anonymousActionType, store, ...options } = devtoolsOptions;
|
|
3307
|
+
let extensionConnector;
|
|
3308
|
+
try {
|
|
3309
|
+
extensionConnector = (enabled != null ? enabled : true) && window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
3310
|
+
} catch (e) {}
|
|
3311
|
+
if (!extensionConnector) {
|
|
3312
|
+
return fn(set, get, api);
|
|
3313
|
+
}
|
|
3314
|
+
const { connection, ...connectionInformation } = extractConnectionInformation(store, extensionConnector, options);
|
|
3315
|
+
let isRecording = true;
|
|
3316
|
+
api.setState = (state, replace, nameOrAction) => {
|
|
3317
|
+
const r = set(state, replace);
|
|
3318
|
+
if (!isRecording)
|
|
3319
|
+
return r;
|
|
3320
|
+
const action = nameOrAction === undefined ? {
|
|
3321
|
+
type: anonymousActionType || findCallerName(new Error().stack) || "anonymous"
|
|
3322
|
+
} : typeof nameOrAction === "string" ? { type: nameOrAction } : nameOrAction;
|
|
3323
|
+
if (store === undefined) {
|
|
3324
|
+
connection == null || connection.send(action, get());
|
|
3325
|
+
return r;
|
|
3326
|
+
}
|
|
3327
|
+
connection == null || connection.send({
|
|
3328
|
+
...action,
|
|
3329
|
+
type: `${store}/${action.type}`
|
|
3330
|
+
}, {
|
|
3331
|
+
...getTrackedConnectionState(options.name),
|
|
3332
|
+
[store]: api.getState()
|
|
3333
|
+
});
|
|
3334
|
+
return r;
|
|
3335
|
+
};
|
|
3336
|
+
api.devtools = {
|
|
3337
|
+
cleanup: () => {
|
|
3338
|
+
if (connection && typeof connection.unsubscribe === "function") {
|
|
3339
|
+
connection.unsubscribe();
|
|
3340
|
+
}
|
|
3341
|
+
removeStoreFromTrackedConnections(options.name, store);
|
|
3342
|
+
}
|
|
3343
|
+
};
|
|
3344
|
+
const setStateFromDevtools = (...a) => {
|
|
3345
|
+
const originalIsRecording = isRecording;
|
|
3346
|
+
isRecording = false;
|
|
3347
|
+
set(...a);
|
|
3348
|
+
isRecording = originalIsRecording;
|
|
3349
|
+
};
|
|
3350
|
+
const initialState = fn(api.setState, get, api);
|
|
3351
|
+
if (connectionInformation.type === "untracked") {
|
|
3352
|
+
connection == null || connection.init(initialState);
|
|
3353
|
+
} else {
|
|
3354
|
+
connectionInformation.stores[connectionInformation.store] = api;
|
|
3355
|
+
connection == null || connection.init(Object.fromEntries(Object.entries(connectionInformation.stores).map(([key, store2]) => [
|
|
3356
|
+
key,
|
|
3357
|
+
key === connectionInformation.store ? initialState : store2.getState()
|
|
3358
|
+
])));
|
|
3359
|
+
}
|
|
3360
|
+
if (shouldDispatchFromDevtools(api)) {
|
|
3361
|
+
let didWarnAboutReservedActionType = false;
|
|
3362
|
+
const originalDispatch = api.dispatch;
|
|
3363
|
+
api.dispatch = (...args) => {
|
|
3364
|
+
if (args[0].type === "__setState" && !didWarnAboutReservedActionType) {
|
|
3365
|
+
console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.');
|
|
3366
|
+
didWarnAboutReservedActionType = true;
|
|
3367
|
+
}
|
|
3368
|
+
originalDispatch(...args);
|
|
3369
|
+
};
|
|
3370
|
+
}
|
|
3371
|
+
connection.subscribe((message) => {
|
|
3372
|
+
var _a;
|
|
3373
|
+
switch (message.type) {
|
|
3374
|
+
case "ACTION":
|
|
3375
|
+
if (typeof message.payload !== "string") {
|
|
3376
|
+
console.error("[zustand devtools middleware] Unsupported action format");
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3379
|
+
return parseJsonThen(message.payload, (action) => {
|
|
3380
|
+
if (action.type === "__setState") {
|
|
3381
|
+
if (store === undefined) {
|
|
3382
|
+
setStateFromDevtools(action.state);
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
if (Object.keys(action.state).length !== 1) {
|
|
3386
|
+
console.error(`
|
|
3387
|
+
[zustand devtools middleware] Unsupported __setState action format.
|
|
3388
|
+
When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
|
|
3389
|
+
and value of this only key should be a state object. Example: { "type": "__setState", "state": { "abc123Store": { "foo": "bar" } } }
|
|
3390
|
+
`);
|
|
3391
|
+
}
|
|
3392
|
+
const stateFromDevtools = action.state[store];
|
|
3393
|
+
if (stateFromDevtools === undefined || stateFromDevtools === null) {
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
if (JSON.stringify(api.getState()) !== JSON.stringify(stateFromDevtools)) {
|
|
3397
|
+
setStateFromDevtools(stateFromDevtools);
|
|
3398
|
+
}
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3401
|
+
if (shouldDispatchFromDevtools(api)) {
|
|
3402
|
+
api.dispatch(action);
|
|
3403
|
+
}
|
|
3404
|
+
});
|
|
3405
|
+
case "DISPATCH":
|
|
3406
|
+
switch (message.payload.type) {
|
|
3407
|
+
case "RESET":
|
|
3408
|
+
setStateFromDevtools(initialState);
|
|
3409
|
+
if (store === undefined) {
|
|
3410
|
+
return connection == null ? undefined : connection.init(api.getState());
|
|
3411
|
+
}
|
|
3412
|
+
return connection == null ? undefined : connection.init(getTrackedConnectionState(options.name));
|
|
3413
|
+
case "COMMIT":
|
|
3414
|
+
if (store === undefined) {
|
|
3415
|
+
connection == null || connection.init(api.getState());
|
|
3416
|
+
return;
|
|
3417
|
+
}
|
|
3418
|
+
return connection == null ? undefined : connection.init(getTrackedConnectionState(options.name));
|
|
3419
|
+
case "ROLLBACK":
|
|
3420
|
+
return parseJsonThen(message.state, (state) => {
|
|
3421
|
+
if (store === undefined) {
|
|
3422
|
+
setStateFromDevtools(state);
|
|
3423
|
+
connection == null || connection.init(api.getState());
|
|
3424
|
+
return;
|
|
3425
|
+
}
|
|
3426
|
+
setStateFromDevtools(state[store]);
|
|
3427
|
+
connection == null || connection.init(getTrackedConnectionState(options.name));
|
|
3428
|
+
});
|
|
3429
|
+
case "JUMP_TO_STATE":
|
|
3430
|
+
case "JUMP_TO_ACTION":
|
|
3431
|
+
return parseJsonThen(message.state, (state) => {
|
|
3432
|
+
if (store === undefined) {
|
|
3433
|
+
setStateFromDevtools(state);
|
|
3434
|
+
return;
|
|
3435
|
+
}
|
|
3436
|
+
if (JSON.stringify(api.getState()) !== JSON.stringify(state[store])) {
|
|
3437
|
+
setStateFromDevtools(state[store]);
|
|
3438
|
+
}
|
|
3439
|
+
});
|
|
3440
|
+
case "IMPORT_STATE": {
|
|
3441
|
+
const { nextLiftedState } = message.payload;
|
|
3442
|
+
const lastComputedState = (_a = nextLiftedState.computedStates.slice(-1)[0]) == null ? undefined : _a.state;
|
|
3443
|
+
if (!lastComputedState)
|
|
3444
|
+
return;
|
|
3445
|
+
if (store === undefined) {
|
|
3446
|
+
setStateFromDevtools(lastComputedState);
|
|
3447
|
+
} else {
|
|
3448
|
+
setStateFromDevtools(lastComputedState[store]);
|
|
3449
|
+
}
|
|
3450
|
+
connection == null || connection.send(null, nextLiftedState);
|
|
3451
|
+
return;
|
|
3452
|
+
}
|
|
3453
|
+
case "PAUSE_RECORDING":
|
|
3454
|
+
return isRecording = !isRecording;
|
|
3455
|
+
}
|
|
3456
|
+
return;
|
|
3457
|
+
}
|
|
3458
|
+
});
|
|
3459
|
+
return initialState;
|
|
3460
|
+
};
|
|
3461
|
+
var devtools = devtoolsImpl;
|
|
3462
|
+
var parseJsonThen = (stringified, fn) => {
|
|
3463
|
+
let parsed;
|
|
3464
|
+
try {
|
|
3465
|
+
parsed = JSON.parse(stringified);
|
|
3466
|
+
} catch (e) {
|
|
3467
|
+
console.error("[zustand devtools middleware] Could not parse the received json", e);
|
|
3468
|
+
}
|
|
3469
|
+
if (parsed !== undefined)
|
|
3470
|
+
fn(parsed);
|
|
3471
|
+
};
|
|
3472
|
+
var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
|
|
3473
|
+
const origSubscribe = api.subscribe;
|
|
3474
|
+
api.subscribe = (selector, optListener, options) => {
|
|
3475
|
+
let listener = selector;
|
|
3476
|
+
if (optListener) {
|
|
3477
|
+
const equalityFn = (options == null ? undefined : options.equalityFn) || Object.is;
|
|
3478
|
+
let currentSlice = selector(api.getState());
|
|
3479
|
+
listener = (state) => {
|
|
3480
|
+
const nextSlice = selector(state);
|
|
3481
|
+
if (!equalityFn(currentSlice, nextSlice)) {
|
|
3482
|
+
const previousSlice = currentSlice;
|
|
3483
|
+
optListener(currentSlice = nextSlice, previousSlice);
|
|
3484
|
+
}
|
|
3485
|
+
};
|
|
3486
|
+
if (options == null ? undefined : options.fireImmediately) {
|
|
3487
|
+
optListener(currentSlice, currentSlice);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
return origSubscribe(listener);
|
|
3491
|
+
};
|
|
3492
|
+
const initialState = fn(set, get, api);
|
|
3493
|
+
return initialState;
|
|
3494
|
+
};
|
|
3495
|
+
var subscribeWithSelector = subscribeWithSelectorImpl;
|
|
3496
|
+
function combine(initialState, create) {
|
|
3497
|
+
return (...args) => Object.assign({}, initialState, create(...args));
|
|
3498
|
+
}
|
|
3499
|
+
function createJSONStorage(getStorage, options) {
|
|
3500
|
+
let storage;
|
|
3501
|
+
try {
|
|
3502
|
+
storage = getStorage();
|
|
3503
|
+
} catch (e) {
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
const persistStorage = {
|
|
3507
|
+
getItem: (name) => {
|
|
3508
|
+
var _a;
|
|
3509
|
+
const parse = (str2) => {
|
|
3510
|
+
if (str2 === null) {
|
|
3511
|
+
return null;
|
|
3512
|
+
}
|
|
3513
|
+
return JSON.parse(str2, options == null ? undefined : options.reviver);
|
|
3514
|
+
};
|
|
3515
|
+
const str = (_a = storage.getItem(name)) != null ? _a : null;
|
|
3516
|
+
if (str instanceof Promise) {
|
|
3517
|
+
return str.then(parse);
|
|
3518
|
+
}
|
|
3519
|
+
return parse(str);
|
|
3520
|
+
},
|
|
3521
|
+
setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue, options == null ? undefined : options.replacer)),
|
|
3522
|
+
removeItem: (name) => storage.removeItem(name)
|
|
3523
|
+
};
|
|
3524
|
+
return persistStorage;
|
|
3525
|
+
}
|
|
3526
|
+
var toThenable = (fn) => (input) => {
|
|
3527
|
+
try {
|
|
3528
|
+
const result = fn(input);
|
|
3529
|
+
if (result instanceof Promise) {
|
|
3530
|
+
return result;
|
|
3531
|
+
}
|
|
3532
|
+
return {
|
|
3533
|
+
then(onFulfilled) {
|
|
3534
|
+
return toThenable(onFulfilled)(result);
|
|
3535
|
+
},
|
|
3536
|
+
catch(_onRejected) {
|
|
3537
|
+
return this;
|
|
3538
|
+
}
|
|
3539
|
+
};
|
|
3540
|
+
} catch (e) {
|
|
3541
|
+
return {
|
|
3542
|
+
then(_onFulfilled) {
|
|
3543
|
+
return this;
|
|
3544
|
+
},
|
|
3545
|
+
catch(onRejected) {
|
|
3546
|
+
return toThenable(onRejected)(e);
|
|
3547
|
+
}
|
|
3548
|
+
};
|
|
3549
|
+
}
|
|
3550
|
+
};
|
|
3551
|
+
var persistImpl = (config, baseOptions) => (set, get, api) => {
|
|
3552
|
+
let options = {
|
|
3553
|
+
storage: createJSONStorage(() => window.localStorage),
|
|
3554
|
+
partialize: (state) => state,
|
|
3555
|
+
version: 0,
|
|
3556
|
+
merge: (persistedState, currentState) => ({
|
|
3557
|
+
...currentState,
|
|
3558
|
+
...persistedState
|
|
3559
|
+
}),
|
|
3560
|
+
...baseOptions
|
|
3561
|
+
};
|
|
3562
|
+
let hasHydrated = false;
|
|
3563
|
+
let hydrationVersion = 0;
|
|
3564
|
+
const hydrationListeners = /* @__PURE__ */ new Set;
|
|
3565
|
+
const finishHydrationListeners = /* @__PURE__ */ new Set;
|
|
3566
|
+
let storage = options.storage;
|
|
3567
|
+
if (!storage) {
|
|
3568
|
+
return config((...args) => {
|
|
3569
|
+
console.warn(`[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`);
|
|
3570
|
+
set(...args);
|
|
3571
|
+
}, get, api);
|
|
3572
|
+
}
|
|
3573
|
+
const setItem = () => {
|
|
3574
|
+
const state = options.partialize({ ...get() });
|
|
3575
|
+
return storage.setItem(options.name, {
|
|
3576
|
+
state,
|
|
3577
|
+
version: options.version
|
|
3578
|
+
});
|
|
3579
|
+
};
|
|
3580
|
+
const savedSetState = api.setState;
|
|
3581
|
+
api.setState = (state, replace) => {
|
|
3582
|
+
savedSetState(state, replace);
|
|
3583
|
+
return setItem();
|
|
3584
|
+
};
|
|
3585
|
+
const configResult = config((...args) => {
|
|
3586
|
+
set(...args);
|
|
3587
|
+
return setItem();
|
|
3588
|
+
}, get, api);
|
|
3589
|
+
api.getInitialState = () => configResult;
|
|
3590
|
+
let stateFromStorage;
|
|
3591
|
+
const hydrate = () => {
|
|
3592
|
+
var _a, _b;
|
|
3593
|
+
if (!storage)
|
|
3594
|
+
return;
|
|
3595
|
+
const currentVersion = ++hydrationVersion;
|
|
3596
|
+
hasHydrated = false;
|
|
3597
|
+
hydrationListeners.forEach((cb) => {
|
|
3598
|
+
var _a2;
|
|
3599
|
+
return cb((_a2 = get()) != null ? _a2 : configResult);
|
|
3600
|
+
});
|
|
3601
|
+
const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? undefined : _b.call(options, (_a = get()) != null ? _a : configResult)) || undefined;
|
|
3602
|
+
return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {
|
|
3603
|
+
if (deserializedStorageValue) {
|
|
3604
|
+
if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
|
|
3605
|
+
if (options.migrate) {
|
|
3606
|
+
const migration = options.migrate(deserializedStorageValue.state, deserializedStorageValue.version);
|
|
3607
|
+
if (migration instanceof Promise) {
|
|
3608
|
+
return migration.then((result) => [true, result]);
|
|
3609
|
+
}
|
|
3610
|
+
return [true, migration];
|
|
3611
|
+
}
|
|
3612
|
+
console.error(`State loaded from storage couldn't be migrated since no migrate function was provided`);
|
|
3613
|
+
} else {
|
|
3614
|
+
return [false, deserializedStorageValue.state];
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
return [false, undefined];
|
|
3618
|
+
}).then((migrationResult) => {
|
|
3619
|
+
var _a2;
|
|
3620
|
+
if (currentVersion !== hydrationVersion) {
|
|
3621
|
+
return;
|
|
3622
|
+
}
|
|
3623
|
+
const [migrated, migratedState] = migrationResult;
|
|
3624
|
+
stateFromStorage = options.merge(migratedState, (_a2 = get()) != null ? _a2 : configResult);
|
|
3625
|
+
set(stateFromStorage, true);
|
|
3626
|
+
if (migrated) {
|
|
3627
|
+
return setItem();
|
|
3628
|
+
}
|
|
3629
|
+
}).then(() => {
|
|
3630
|
+
if (currentVersion !== hydrationVersion) {
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3633
|
+
postRehydrationCallback == null || postRehydrationCallback(get(), undefined);
|
|
3634
|
+
stateFromStorage = get();
|
|
3635
|
+
hasHydrated = true;
|
|
3636
|
+
finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
|
|
3637
|
+
}).catch((e) => {
|
|
3638
|
+
if (currentVersion !== hydrationVersion) {
|
|
3639
|
+
return;
|
|
3640
|
+
}
|
|
3641
|
+
postRehydrationCallback == null || postRehydrationCallback(undefined, e);
|
|
3642
|
+
});
|
|
3643
|
+
};
|
|
3644
|
+
api.persist = {
|
|
3645
|
+
setOptions: (newOptions) => {
|
|
3646
|
+
options = {
|
|
3647
|
+
...options,
|
|
3648
|
+
...newOptions
|
|
3649
|
+
};
|
|
3650
|
+
if (newOptions.storage) {
|
|
3651
|
+
storage = newOptions.storage;
|
|
3652
|
+
}
|
|
3653
|
+
},
|
|
3654
|
+
clearStorage: () => {
|
|
3655
|
+
storage == null || storage.removeItem(options.name);
|
|
3656
|
+
},
|
|
3657
|
+
getOptions: () => options,
|
|
3658
|
+
rehydrate: () => hydrate(),
|
|
3659
|
+
hasHydrated: () => hasHydrated,
|
|
3660
|
+
onHydrate: (cb) => {
|
|
3661
|
+
hydrationListeners.add(cb);
|
|
3662
|
+
return () => {
|
|
3663
|
+
hydrationListeners.delete(cb);
|
|
3664
|
+
};
|
|
3665
|
+
},
|
|
3666
|
+
onFinishHydration: (cb) => {
|
|
3667
|
+
finishHydrationListeners.add(cb);
|
|
3668
|
+
return () => {
|
|
3669
|
+
finishHydrationListeners.delete(cb);
|
|
3670
|
+
};
|
|
3671
|
+
}
|
|
3672
|
+
};
|
|
3673
|
+
if (!options.skipHydration) {
|
|
3674
|
+
hydrate();
|
|
3675
|
+
}
|
|
3676
|
+
return stateFromStorage || configResult;
|
|
3677
|
+
};
|
|
3678
|
+
var persist = persistImpl;
|
|
3679
|
+
function ssrSafe(config, isSSR = typeof window === "undefined") {
|
|
3680
|
+
return (set, get, api) => {
|
|
3681
|
+
if (!isSSR) {
|
|
3682
|
+
return config(set, get, api);
|
|
3683
|
+
}
|
|
3684
|
+
const ssrSet = () => {
|
|
3685
|
+
throw new Error("Cannot set state of Zustand store in SSR");
|
|
3686
|
+
};
|
|
3687
|
+
api.setState = ssrSet;
|
|
3688
|
+
return config(ssrSet, get, api);
|
|
3689
|
+
};
|
|
3690
|
+
}
|
|
3691
|
+
exports.combine = combine;
|
|
3692
|
+
exports.createJSONStorage = createJSONStorage;
|
|
3693
|
+
exports.devtools = devtools;
|
|
3694
|
+
exports.persist = persist;
|
|
3695
|
+
exports.redux = redux;
|
|
3696
|
+
exports.subscribeWithSelector = subscribeWithSelector;
|
|
3697
|
+
exports.unstable_ssrSafe = ssrSafe;
|
|
3698
|
+
});
|
|
3699
|
+
|
|
3700
|
+
// ../../packages/core/dist/stores/routing.js
|
|
3701
|
+
var require_routing = __commonJS((exports) => {
|
|
3702
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3703
|
+
exports.createRoutingStore = createRoutingStore;
|
|
3704
|
+
var zustand_1 = require_zustand();
|
|
3705
|
+
var middleware_1 = require_middleware();
|
|
3706
|
+
var history_1 = require_history();
|
|
3707
|
+
var initialState = {
|
|
3708
|
+
waypoints: [],
|
|
3709
|
+
routePath: [],
|
|
3710
|
+
distanceMeters: null,
|
|
3711
|
+
durationSeconds: null,
|
|
3712
|
+
isOfflineRoute: false,
|
|
3713
|
+
hasRoute: false,
|
|
3714
|
+
elevationGain: undefined,
|
|
3715
|
+
elevationLoss: undefined,
|
|
3716
|
+
elevationProfile: undefined,
|
|
3717
|
+
isComputingElevation: false,
|
|
3718
|
+
isMapLocked: false,
|
|
3719
|
+
mode: { kind: "unsaved" },
|
|
3720
|
+
activity: undefined,
|
|
3721
|
+
history: (0, history_1.emptyHistory)(),
|
|
3722
|
+
canUndo: false,
|
|
3723
|
+
canRedo: false
|
|
3724
|
+
};
|
|
3725
|
+
var migrateWaypoints = (coords = [], flags = []) => coords.map((coord, i) => ({ coord, type: flags[i] ? "direct" : "routed" }));
|
|
3726
|
+
var migrateLegacyPersistedState = (persisted) => {
|
|
3727
|
+
const { waypoints, directFlags, undoStack: _u, redoStack: _r, ...rest } = persisted;
|
|
3728
|
+
return {
|
|
3729
|
+
...rest,
|
|
3730
|
+
waypoints: migrateWaypoints(waypoints ?? [], directFlags ?? [])
|
|
3731
|
+
};
|
|
3732
|
+
};
|
|
3733
|
+
var dropLegacyMetricStrings = (persisted) => {
|
|
3734
|
+
const { routeDistance: _rd, routeDuration: _rdur, ...rest } = persisted;
|
|
3735
|
+
return rest;
|
|
3736
|
+
};
|
|
3737
|
+
function createRoutingStore(logger) {
|
|
3738
|
+
const persistConfig = {
|
|
3739
|
+
name: "routing-store",
|
|
3740
|
+
version: 3,
|
|
3741
|
+
migrate: (persisted, version) => {
|
|
3742
|
+
let next = persisted ?? {};
|
|
3743
|
+
if (version < 1) {
|
|
3744
|
+
next = migrateLegacyPersistedState(next);
|
|
3745
|
+
}
|
|
3746
|
+
if (version < 2) {
|
|
3747
|
+
next = dropLegacyMetricStrings(next);
|
|
3748
|
+
}
|
|
3749
|
+
return next;
|
|
3750
|
+
},
|
|
3751
|
+
partialize: (state) => ({
|
|
3752
|
+
waypoints: state.waypoints,
|
|
3753
|
+
routePath: state.routePath,
|
|
3754
|
+
distanceMeters: state.distanceMeters,
|
|
3755
|
+
durationSeconds: state.durationSeconds,
|
|
3756
|
+
isOfflineRoute: state.isOfflineRoute,
|
|
3757
|
+
hasRoute: state.hasRoute,
|
|
3758
|
+
elevationGain: state.elevationGain,
|
|
3759
|
+
elevationLoss: state.elevationLoss,
|
|
3760
|
+
elevationProfile: state.elevationProfile,
|
|
3761
|
+
isMapLocked: state.isMapLocked,
|
|
3762
|
+
mode: state.mode,
|
|
3763
|
+
activity: state.activity,
|
|
3764
|
+
history: state.history,
|
|
3765
|
+
canUndo: state.canUndo,
|
|
3766
|
+
canRedo: state.canRedo
|
|
3767
|
+
})
|
|
3768
|
+
};
|
|
3769
|
+
return (0, zustand_1.create)()((0, middleware_1.persist)((set) => ({
|
|
3770
|
+
...initialState,
|
|
3771
|
+
addWaypoint: (coord, type) => {
|
|
3772
|
+
logger.info("[RoutingStore] Adding waypoint:", coord, "type:", type);
|
|
3773
|
+
set((state) => ({ waypoints: [...state.waypoints, { coord, type }] }));
|
|
3774
|
+
},
|
|
3775
|
+
removeWaypoint: (index) => {
|
|
3776
|
+
logger.info("[RoutingStore] Removing waypoint at index:", index);
|
|
3777
|
+
set((state) => ({ waypoints: state.waypoints.filter((_, i) => i !== index) }));
|
|
3778
|
+
},
|
|
3779
|
+
setWaypoints: (waypoints) => {
|
|
3780
|
+
logger.info("[RoutingStore] Setting waypoints:", waypoints.length);
|
|
3781
|
+
set({ waypoints });
|
|
3782
|
+
},
|
|
3783
|
+
updateWaypointCoords: (coords) => {
|
|
3784
|
+
logger.info("[RoutingStore] Updating waypoint coords:", coords.length);
|
|
3785
|
+
set((state) => ({
|
|
3786
|
+
waypoints: state.waypoints.map((wp, i) => i < coords.length ? { ...wp, coord: coords[i] } : wp)
|
|
3787
|
+
}));
|
|
3788
|
+
},
|
|
3789
|
+
setWaypointType: (index, type) => {
|
|
3790
|
+
set((state) => ({
|
|
3791
|
+
waypoints: state.waypoints.map((wp, i) => i === index ? { ...wp, type } : wp)
|
|
3792
|
+
}));
|
|
3793
|
+
},
|
|
3794
|
+
setWaypointName: (index, name) => {
|
|
3795
|
+
const trimmed = name?.trim();
|
|
3796
|
+
set((state) => ({
|
|
3797
|
+
waypoints: state.waypoints.map((wp, i) => i === index ? { ...wp, name: trimmed && trimmed.length > 0 ? trimmed : undefined } : wp)
|
|
3798
|
+
}));
|
|
3799
|
+
},
|
|
3800
|
+
clearWaypoints: () => {
|
|
3801
|
+
logger.info("[RoutingStore] Clearing waypoints");
|
|
3802
|
+
set({
|
|
3803
|
+
waypoints: [],
|
|
3804
|
+
routePath: [],
|
|
3805
|
+
distanceMeters: null,
|
|
3806
|
+
durationSeconds: null,
|
|
3807
|
+
isOfflineRoute: false,
|
|
3808
|
+
hasRoute: false,
|
|
3809
|
+
elevationGain: undefined,
|
|
3810
|
+
elevationLoss: undefined,
|
|
3811
|
+
elevationProfile: undefined,
|
|
3812
|
+
isComputingElevation: false,
|
|
3813
|
+
mode: { kind: "unsaved" }
|
|
3814
|
+
});
|
|
3815
|
+
},
|
|
3816
|
+
setRoutePath: (routePath) => {
|
|
3817
|
+
set({ routePath });
|
|
3818
|
+
},
|
|
3819
|
+
clearRoutePath: () => {
|
|
3820
|
+
set({ routePath: [] });
|
|
3821
|
+
},
|
|
3822
|
+
setRouteMetrics: ({ distanceMeters, durationSeconds, isOffline }) => {
|
|
3823
|
+
set({ distanceMeters, durationSeconds, isOfflineRoute: isOffline });
|
|
3824
|
+
},
|
|
3825
|
+
clearRouteMetrics: () => {
|
|
3826
|
+
set({ distanceMeters: null, durationSeconds: null, isOfflineRoute: false });
|
|
3827
|
+
},
|
|
3828
|
+
setHasRoute: (hasRoute) => {
|
|
3829
|
+
set({ hasRoute });
|
|
3830
|
+
},
|
|
3831
|
+
setElevation: ({ gainMeters, lossMeters, profile }) => {
|
|
3832
|
+
set({
|
|
3833
|
+
elevationGain: gainMeters,
|
|
3834
|
+
elevationLoss: lossMeters,
|
|
3835
|
+
elevationProfile: profile
|
|
3836
|
+
});
|
|
3837
|
+
},
|
|
3838
|
+
clearElevation: () => {
|
|
3839
|
+
set({
|
|
3840
|
+
elevationGain: undefined,
|
|
3841
|
+
elevationLoss: undefined,
|
|
3842
|
+
elevationProfile: undefined
|
|
3843
|
+
});
|
|
3844
|
+
},
|
|
3845
|
+
setIsComputingElevation: (computing) => {
|
|
3846
|
+
set({ isComputingElevation: computing });
|
|
3847
|
+
},
|
|
3848
|
+
setIsMapLocked: (isLocked) => {
|
|
3849
|
+
set({ isMapLocked: isLocked });
|
|
3850
|
+
},
|
|
3851
|
+
setMode: (mode) => {
|
|
3852
|
+
set({ mode });
|
|
3853
|
+
},
|
|
3854
|
+
setEditingName: (name) => {
|
|
3855
|
+
const trimmed = name.trim();
|
|
3856
|
+
if (!trimmed)
|
|
3857
|
+
return;
|
|
3858
|
+
set((state) => {
|
|
3859
|
+
if (state.mode.kind !== "editing" || state.mode.name === trimmed)
|
|
3860
|
+
return state;
|
|
3861
|
+
return { mode: { ...state.mode, name: trimmed } };
|
|
3862
|
+
});
|
|
3863
|
+
},
|
|
3864
|
+
setBaseline: (baseline) => {
|
|
3865
|
+
set((state) => {
|
|
3866
|
+
if (state.mode.kind !== "editing")
|
|
3867
|
+
return state;
|
|
3868
|
+
return { mode: { ...state.mode, name: baseline.name, baseline } };
|
|
3869
|
+
});
|
|
3870
|
+
},
|
|
3871
|
+
setActivity: (activity) => {
|
|
3872
|
+
set({ activity });
|
|
3873
|
+
},
|
|
3874
|
+
saveSnapshot: () => {
|
|
3875
|
+
set((state) => {
|
|
3876
|
+
const snapshot = state.waypoints.map((wp) => ({ ...wp }));
|
|
3877
|
+
const nextHistory = (0, history_1.recordSnapshot)(state.history, snapshot);
|
|
3878
|
+
logger.info("[RoutingStore] Saving snapshot:", snapshot.length, "waypoints");
|
|
3879
|
+
return {
|
|
3880
|
+
history: nextHistory,
|
|
3881
|
+
canUndo: (0, history_1.canUndo)(nextHistory),
|
|
3882
|
+
canRedo: (0, history_1.canRedo)(nextHistory)
|
|
3883
|
+
};
|
|
3884
|
+
});
|
|
3885
|
+
},
|
|
3886
|
+
undo: () => {
|
|
3887
|
+
set((state) => {
|
|
3888
|
+
const current = state.waypoints.map((wp) => ({ ...wp }));
|
|
3889
|
+
const step = (0, history_1.undoStep)(state.history, current);
|
|
3890
|
+
if (!step) {
|
|
3891
|
+
logger.warn("[RoutingStore] No actions to undo");
|
|
3892
|
+
return state;
|
|
3893
|
+
}
|
|
3894
|
+
logger.info("[RoutingStore] Undo:", state.waypoints.length, "->", step.previous.length, "waypoints");
|
|
3895
|
+
return {
|
|
3896
|
+
waypoints: step.previous,
|
|
3897
|
+
history: step.history,
|
|
3898
|
+
canUndo: (0, history_1.canUndo)(step.history),
|
|
3899
|
+
canRedo: (0, history_1.canRedo)(step.history)
|
|
3900
|
+
};
|
|
3901
|
+
});
|
|
3902
|
+
},
|
|
3903
|
+
redo: () => {
|
|
3904
|
+
set((state) => {
|
|
3905
|
+
const current = state.waypoints.map((wp) => ({ ...wp }));
|
|
3906
|
+
const step = (0, history_1.redoStep)(state.history, current);
|
|
3907
|
+
if (!step) {
|
|
3908
|
+
logger.warn("[RoutingStore] No actions to redo");
|
|
3909
|
+
return state;
|
|
3910
|
+
}
|
|
3911
|
+
logger.info("[RoutingStore] Redo:", state.waypoints.length, "->", step.next.length, "waypoints");
|
|
3912
|
+
return {
|
|
3913
|
+
waypoints: step.next,
|
|
3914
|
+
history: step.history,
|
|
3915
|
+
canUndo: (0, history_1.canUndo)(step.history),
|
|
3916
|
+
canRedo: (0, history_1.canRedo)(step.history)
|
|
3917
|
+
};
|
|
3918
|
+
});
|
|
3919
|
+
},
|
|
3920
|
+
clearHistory: () => {
|
|
3921
|
+
logger.info("[RoutingStore] Clearing history");
|
|
3922
|
+
set({ history: (0, history_1.emptyHistory)(), canUndo: false, canRedo: false });
|
|
3923
|
+
}
|
|
3924
|
+
}), persistConfig));
|
|
3925
|
+
}
|
|
3926
|
+
});
|
|
3927
|
+
|
|
3928
|
+
// ../../packages/core/dist/stores/index.js
|
|
3929
|
+
var require_stores = __commonJS((exports) => {
|
|
3930
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
3931
|
+
if (k2 === undefined)
|
|
3932
|
+
k2 = k;
|
|
3933
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
3934
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
3935
|
+
desc = { enumerable: true, get: function() {
|
|
3936
|
+
return m[k];
|
|
3937
|
+
} };
|
|
3938
|
+
}
|
|
3939
|
+
Object.defineProperty(o, k2, desc);
|
|
3940
|
+
} : function(o, m, k, k2) {
|
|
3941
|
+
if (k2 === undefined)
|
|
3942
|
+
k2 = k;
|
|
3943
|
+
o[k2] = m[k];
|
|
3944
|
+
});
|
|
3945
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
3946
|
+
for (var p in m)
|
|
3947
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
3948
|
+
__createBinding(exports2, m, p);
|
|
3949
|
+
};
|
|
3950
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3951
|
+
__exportStar(require_routing(), exports);
|
|
3952
|
+
});
|
|
3953
|
+
|
|
3954
|
+
// ../../packages/core/dist/utils/formatting.js
|
|
3955
|
+
var require_formatting = __commonJS((exports) => {
|
|
3956
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3957
|
+
exports.formatFileSize = exports.formatElevation = exports.formatBearing = exports.formatCoordinate = exports.formatRouteStats = exports.formatDuration = exports.formatDistance = exports.formatDisplaySpeed = exports.fromDisplaySpeed = exports.toDisplaySpeed = exports.KMH_TO_MPH = undefined;
|
|
3958
|
+
exports.KMH_TO_MPH = 0.621371;
|
|
3959
|
+
var toDisplaySpeed = (kmh, units) => units === "mi" ? kmh * exports.KMH_TO_MPH : kmh;
|
|
3960
|
+
exports.toDisplaySpeed = toDisplaySpeed;
|
|
3961
|
+
var fromDisplaySpeed = (value, units) => units === "mi" ? value / exports.KMH_TO_MPH : value;
|
|
3962
|
+
exports.fromDisplaySpeed = fromDisplaySpeed;
|
|
3963
|
+
var formatDisplaySpeed = (kmh, units) => {
|
|
3964
|
+
const display = (0, exports.toDisplaySpeed)(kmh, units);
|
|
3965
|
+
return Number.isFinite(display) ? String(Math.round(display * 10) / 10) : "";
|
|
3966
|
+
};
|
|
3967
|
+
exports.formatDisplaySpeed = formatDisplaySpeed;
|
|
3968
|
+
var formatDistance = (distanceKm, options = {}) => {
|
|
3969
|
+
const { precision = 2, unit = "auto", showUnit = true } = options;
|
|
3970
|
+
if (unit === "auto") {
|
|
3971
|
+
if (distanceKm < 1) {
|
|
3972
|
+
const meters = Math.round(distanceKm * 1000);
|
|
3973
|
+
return showUnit ? `${meters} m` : meters.toString();
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
const formatted = distanceKm.toFixed(precision);
|
|
3977
|
+
return showUnit ? `${formatted} km` : formatted;
|
|
3978
|
+
};
|
|
3979
|
+
exports.formatDistance = formatDistance;
|
|
3980
|
+
var formatDuration = (durationMinutes, options = {}) => {
|
|
3981
|
+
const { format = "auto", showUnit = true } = options;
|
|
3982
|
+
if (format === "minutes" || format === "auto" && durationMinutes < 60) {
|
|
3983
|
+
const minutes2 = Math.round(durationMinutes);
|
|
3984
|
+
return showUnit ? `${minutes2} min` : minutes2.toString();
|
|
3985
|
+
}
|
|
3986
|
+
if (format === "hours" || format === "auto" && durationMinutes >= 60) {
|
|
3987
|
+
const hours = Math.floor(durationMinutes / 60);
|
|
3988
|
+
const minutes2 = Math.round(durationMinutes % 60);
|
|
3989
|
+
if (minutes2 === 0) {
|
|
3990
|
+
return showUnit ? `${hours} h` : hours.toString();
|
|
3991
|
+
}
|
|
3992
|
+
const decimalHours = (durationMinutes / 60).toFixed(1);
|
|
3993
|
+
return showUnit ? `${decimalHours} h` : decimalHours;
|
|
3994
|
+
}
|
|
3995
|
+
if (format === "full") {
|
|
3996
|
+
const hours = Math.floor(durationMinutes / 60);
|
|
3997
|
+
const minutes2 = Math.round(durationMinutes % 60);
|
|
3998
|
+
if (durationMinutes >= 60) {
|
|
3999
|
+
return showUnit ? `${hours} h ${minutes2} min` : `${hours}:${minutes2.toString().padStart(2, "0")}`;
|
|
4000
|
+
} else {
|
|
4001
|
+
return showUnit ? `${minutes2} min` : minutes2.toString();
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
const minutes = Math.round(durationMinutes);
|
|
4005
|
+
return showUnit ? `${minutes} min` : minutes.toString();
|
|
4006
|
+
};
|
|
4007
|
+
exports.formatDuration = formatDuration;
|
|
4008
|
+
var formatRouteStats = (distanceKm, durationMinutes, options = {}) => {
|
|
4009
|
+
const { separator = " • ", includeSpeed = false } = options;
|
|
4010
|
+
const distance = (0, exports.formatDistance)(distanceKm);
|
|
4011
|
+
const duration = (0, exports.formatDuration)(durationMinutes);
|
|
4012
|
+
let result = `${distance}${separator}${duration}`;
|
|
4013
|
+
if (includeSpeed && durationMinutes > 0) {
|
|
4014
|
+
const speedKmh = (distanceKm / (durationMinutes / 60)).toFixed(1);
|
|
4015
|
+
result += `${separator}${speedKmh} km/h`;
|
|
4016
|
+
}
|
|
4017
|
+
return result;
|
|
4018
|
+
};
|
|
4019
|
+
exports.formatRouteStats = formatRouteStats;
|
|
4020
|
+
var formatCoordinate = (coordinate, precision = 6) => {
|
|
4021
|
+
const [lon, lat] = coordinate;
|
|
4022
|
+
return `${lat.toFixed(precision)}, ${lon.toFixed(precision)}`;
|
|
4023
|
+
};
|
|
4024
|
+
exports.formatCoordinate = formatCoordinate;
|
|
4025
|
+
var formatBearing = (bearing, format = "degrees") => {
|
|
4026
|
+
const normalizedBearing = (bearing % 360 + 360) % 360;
|
|
4027
|
+
if (format === "degrees") {
|
|
4028
|
+
return `${normalizedBearing.toFixed(0)}°`;
|
|
4029
|
+
}
|
|
4030
|
+
if (format === "cardinal") {
|
|
4031
|
+
const cardinals = [
|
|
4032
|
+
"N",
|
|
4033
|
+
"NNE",
|
|
4034
|
+
"NE",
|
|
4035
|
+
"ENE",
|
|
4036
|
+
"E",
|
|
4037
|
+
"ESE",
|
|
4038
|
+
"SE",
|
|
4039
|
+
"SSE",
|
|
4040
|
+
"S",
|
|
4041
|
+
"SSW",
|
|
4042
|
+
"SW",
|
|
4043
|
+
"WSW",
|
|
4044
|
+
"W",
|
|
4045
|
+
"WNW",
|
|
4046
|
+
"NW",
|
|
4047
|
+
"NNW"
|
|
4048
|
+
];
|
|
4049
|
+
const index = Math.round(normalizedBearing / 22.5) % 16;
|
|
4050
|
+
return cardinals[index];
|
|
4051
|
+
}
|
|
4052
|
+
if (format === "both") {
|
|
4053
|
+
const degrees = (0, exports.formatBearing)(bearing, "degrees");
|
|
4054
|
+
const cardinal = (0, exports.formatBearing)(bearing, "cardinal");
|
|
4055
|
+
return `${degrees} (${cardinal})`;
|
|
4056
|
+
}
|
|
4057
|
+
return normalizedBearing.toString();
|
|
4058
|
+
};
|
|
4059
|
+
exports.formatBearing = formatBearing;
|
|
4060
|
+
var formatElevation = (elevationMeters, type = "absolute") => {
|
|
4061
|
+
const rounded = Math.round(elevationMeters);
|
|
4062
|
+
if (type === "gain") {
|
|
4063
|
+
return `↗ ${rounded} m`;
|
|
4064
|
+
}
|
|
4065
|
+
if (type === "loss") {
|
|
4066
|
+
return `↘ ${Math.abs(rounded)} m`;
|
|
4067
|
+
}
|
|
4068
|
+
return `${rounded} m`;
|
|
4069
|
+
};
|
|
4070
|
+
exports.formatElevation = formatElevation;
|
|
4071
|
+
var formatFileSize = (bytes) => {
|
|
4072
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
4073
|
+
let size = bytes;
|
|
4074
|
+
let unitIndex = 0;
|
|
4075
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
4076
|
+
size /= 1024;
|
|
4077
|
+
unitIndex++;
|
|
4078
|
+
}
|
|
4079
|
+
const precision = unitIndex === 0 ? 0 : 1;
|
|
4080
|
+
return `${size.toFixed(precision)} ${units[unitIndex]}`;
|
|
4081
|
+
};
|
|
4082
|
+
exports.formatFileSize = formatFileSize;
|
|
4083
|
+
});
|
|
4084
|
+
|
|
4085
|
+
// ../../packages/core/dist/utils/geospatial.js
|
|
4086
|
+
var require_geospatial = __commonJS((exports) => {
|
|
4087
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4088
|
+
exports.calculateBearing = exports.closestPointOnSegment = exports.estimateWalkingDuration = exports.estimateDuration = exports.isValidCoordinate = exports.pointToSegmentDistance = exports.calculatePathDistance = exports.haversineDistance = exports.EARTH_RADIUS_KM = undefined;
|
|
4089
|
+
exports.EARTH_RADIUS_KM = 6371;
|
|
4090
|
+
var toRadians = (degrees) => degrees * Math.PI / 180;
|
|
4091
|
+
var haversineDistance = (coord1, coord2) => {
|
|
4092
|
+
const [lon1, lat1] = coord1;
|
|
4093
|
+
const [lon2, lat2] = coord2;
|
|
4094
|
+
const dLat = toRadians(lat2 - lat1);
|
|
4095
|
+
const dLon = toRadians(lon2 - lon1);
|
|
4096
|
+
const lat1Rad = toRadians(lat1);
|
|
4097
|
+
const lat2Rad = toRadians(lat2);
|
|
4098
|
+
const a = Math.sin(dLat / 2) ** 2 + Math.cos(lat1Rad) * Math.cos(lat2Rad) * Math.sin(dLon / 2) ** 2;
|
|
4099
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
4100
|
+
return exports.EARTH_RADIUS_KM * c;
|
|
4101
|
+
};
|
|
4102
|
+
exports.haversineDistance = haversineDistance;
|
|
4103
|
+
var calculatePathDistance = (coordinates) => {
|
|
4104
|
+
if (coordinates.length < 2)
|
|
4105
|
+
return 0;
|
|
4106
|
+
let totalDistance = 0;
|
|
4107
|
+
for (let i = 0;i < coordinates.length - 1; i++) {
|
|
4108
|
+
totalDistance += (0, exports.haversineDistance)(coordinates[i], coordinates[i + 1]);
|
|
4109
|
+
}
|
|
4110
|
+
return totalDistance;
|
|
4111
|
+
};
|
|
4112
|
+
exports.calculatePathDistance = calculatePathDistance;
|
|
4113
|
+
var pointToSegmentDistance = (point, lineStart, lineEnd) => {
|
|
4114
|
+
const [px, py] = point;
|
|
4115
|
+
const [x1, y1] = lineStart;
|
|
4116
|
+
const [x2, y2] = lineEnd;
|
|
4117
|
+
const dx = x2 - x1;
|
|
4118
|
+
const dy = y2 - y1;
|
|
4119
|
+
if (dx === 0 && dy === 0) {
|
|
4120
|
+
return (0, exports.haversineDistance)(point, lineStart);
|
|
4121
|
+
}
|
|
4122
|
+
const t = Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy)));
|
|
4123
|
+
const closestPoint = [x1 + t * dx, y1 + t * dy];
|
|
4124
|
+
return (0, exports.haversineDistance)(point, closestPoint);
|
|
4125
|
+
};
|
|
4126
|
+
exports.pointToSegmentDistance = pointToSegmentDistance;
|
|
4127
|
+
var isValidCoordinate = (coordinate) => {
|
|
4128
|
+
const [lon, lat] = coordinate;
|
|
4129
|
+
return typeof lon === "number" && typeof lat === "number" && lon >= -180 && lon <= 180 && lat >= -90 && lat <= 90 && !Number.isNaN(lon) && !Number.isNaN(lat);
|
|
4130
|
+
};
|
|
4131
|
+
exports.isValidCoordinate = isValidCoordinate;
|
|
4132
|
+
var estimateDuration = (distanceKm, speedKmh) => {
|
|
4133
|
+
if (speedKmh <= 0)
|
|
4134
|
+
return 0;
|
|
4135
|
+
return Math.round(distanceKm / speedKmh * 60);
|
|
4136
|
+
};
|
|
4137
|
+
exports.estimateDuration = estimateDuration;
|
|
4138
|
+
var estimateWalkingDuration = (distanceKm) => (0, exports.estimateDuration)(distanceKm, 5);
|
|
4139
|
+
exports.estimateWalkingDuration = estimateWalkingDuration;
|
|
4140
|
+
var closestPointOnSegment = (p, v, w) => {
|
|
4141
|
+
const l2 = (v[0] - w[0]) ** 2 + (v[1] - w[1]) ** 2;
|
|
4142
|
+
if (l2 === 0)
|
|
4143
|
+
return v;
|
|
4144
|
+
let t = ((p[0] - v[0]) * (w[0] - v[0]) + (p[1] - v[1]) * (w[1] - v[1])) / l2;
|
|
4145
|
+
t = Math.max(0, Math.min(1, t));
|
|
4146
|
+
return [v[0] + t * (w[0] - v[0]), v[1] + t * (w[1] - v[1])];
|
|
4147
|
+
};
|
|
4148
|
+
exports.closestPointOnSegment = closestPointOnSegment;
|
|
4149
|
+
var calculateBearing = (coord1, coord2) => {
|
|
4150
|
+
const [lon1, lat1] = coord1;
|
|
4151
|
+
const [lon2, lat2] = coord2;
|
|
4152
|
+
const lat1Rad = toRadians(lat1);
|
|
4153
|
+
const lat2Rad = toRadians(lat2);
|
|
4154
|
+
const dLon = toRadians(lon2 - lon1);
|
|
4155
|
+
const x = Math.sin(dLon) * Math.cos(lat2Rad);
|
|
4156
|
+
const y = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad) * Math.cos(dLon);
|
|
4157
|
+
const bearing = Math.atan2(x, y);
|
|
4158
|
+
return (bearing * 180 / Math.PI + 360) % 360;
|
|
4159
|
+
};
|
|
4160
|
+
exports.calculateBearing = calculateBearing;
|
|
4161
|
+
});
|
|
4162
|
+
|
|
4163
|
+
// ../../packages/core/dist/utils/routeGeneration.js
|
|
4164
|
+
var require_routeGeneration = __commonJS((exports) => {
|
|
4165
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4166
|
+
exports.DEFAULT_SMART_WAYPOINT_THRESHOLDS = undefined;
|
|
4167
|
+
exports.selectSmartWaypoints = selectSmartWaypoints;
|
|
4168
|
+
var geospatial_1 = require_geospatial();
|
|
4169
|
+
exports.DEFAULT_SMART_WAYPOINT_THRESHOLDS = {
|
|
4170
|
+
directionChangeThresholdDeg: 30,
|
|
4171
|
+
maxDistanceIntervalKm: 2,
|
|
4172
|
+
minDistanceBetweenWaypointsKm: 0.1,
|
|
4173
|
+
maxWaypoints: 15
|
|
4174
|
+
};
|
|
4175
|
+
function calculateBearing(a, b) {
|
|
4176
|
+
const lat1 = a[1] * Math.PI / 180;
|
|
4177
|
+
const lat2 = b[1] * Math.PI / 180;
|
|
4178
|
+
const deltaLon = (b[0] - a[0]) * Math.PI / 180;
|
|
4179
|
+
const y = Math.sin(deltaLon) * Math.cos(lat2);
|
|
4180
|
+
const x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(deltaLon);
|
|
4181
|
+
const bearing = Math.atan2(y, x) * 180 / Math.PI;
|
|
4182
|
+
return (bearing + 360) % 360;
|
|
4183
|
+
}
|
|
4184
|
+
function angleDifference(a, b) {
|
|
4185
|
+
let diff = Math.abs(a - b);
|
|
4186
|
+
if (diff > 180)
|
|
4187
|
+
diff = 360 - diff;
|
|
4188
|
+
return diff;
|
|
4189
|
+
}
|
|
4190
|
+
function reduceToCap(waypoints, cap) {
|
|
4191
|
+
if (waypoints.length <= cap)
|
|
4192
|
+
return waypoints;
|
|
4193
|
+
const reduced = [waypoints[0]];
|
|
4194
|
+
const middleSlots = cap - 2;
|
|
4195
|
+
const step = Math.max(1, Math.floor((waypoints.length - 2) / middleSlots));
|
|
4196
|
+
for (let i = step;i < waypoints.length - 1; i += step) {
|
|
4197
|
+
if (reduced.length < cap - 1)
|
|
4198
|
+
reduced.push(waypoints[i]);
|
|
4199
|
+
}
|
|
4200
|
+
reduced.push(waypoints[waypoints.length - 1]);
|
|
4201
|
+
return reduced;
|
|
4202
|
+
}
|
|
4203
|
+
function selectSmartWaypoints(trackPoints, thresholds = exports.DEFAULT_SMART_WAYPOINT_THRESHOLDS) {
|
|
4204
|
+
if (trackPoints.length < 2)
|
|
4205
|
+
return [...trackPoints];
|
|
4206
|
+
const waypoints = [trackPoints[0]];
|
|
4207
|
+
let lastWaypointIndex = 0;
|
|
4208
|
+
let cumulativeDistance = 0;
|
|
4209
|
+
for (let i = 1;i < trackPoints.length - 1; i++) {
|
|
4210
|
+
const currentPoint = trackPoints[i];
|
|
4211
|
+
const prevPoint = trackPoints[i - 1];
|
|
4212
|
+
const lastWaypoint = trackPoints[lastWaypointIndex];
|
|
4213
|
+
const distanceFromLastWaypoint = (0, geospatial_1.haversineDistance)(lastWaypoint, currentPoint);
|
|
4214
|
+
const segmentDistance = (0, geospatial_1.haversineDistance)(prevPoint, currentPoint);
|
|
4215
|
+
cumulativeDistance += segmentDistance;
|
|
4216
|
+
if (distanceFromLastWaypoint < thresholds.minDistanceBetweenWaypointsKm)
|
|
4217
|
+
continue;
|
|
4218
|
+
let shouldAdd = false;
|
|
4219
|
+
if (i >= 2 && i < trackPoints.length - 2) {
|
|
4220
|
+
const windowSize = Math.min(3, Math.floor(trackPoints.length / 20));
|
|
4221
|
+
const beforeIndex = Math.max(0, i - windowSize);
|
|
4222
|
+
const afterIndex = Math.min(trackPoints.length - 1, i + windowSize);
|
|
4223
|
+
const bearingBefore = calculateBearing(trackPoints[beforeIndex], currentPoint);
|
|
4224
|
+
const bearingAfter = calculateBearing(currentPoint, trackPoints[afterIndex]);
|
|
4225
|
+
if (angleDifference(bearingBefore, bearingAfter) >= thresholds.directionChangeThresholdDeg) {
|
|
4226
|
+
shouldAdd = true;
|
|
4227
|
+
}
|
|
4228
|
+
}
|
|
4229
|
+
if (cumulativeDistance >= thresholds.maxDistanceIntervalKm) {
|
|
4230
|
+
shouldAdd = true;
|
|
4231
|
+
cumulativeDistance = 0;
|
|
4232
|
+
}
|
|
4233
|
+
if (shouldAdd) {
|
|
4234
|
+
waypoints.push(currentPoint);
|
|
4235
|
+
lastWaypointIndex = i;
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
const last = trackPoints[trackPoints.length - 1];
|
|
4239
|
+
const distanceToEnd = (0, geospatial_1.haversineDistance)(waypoints[waypoints.length - 1], last);
|
|
4240
|
+
if (distanceToEnd >= thresholds.minDistanceBetweenWaypointsKm) {
|
|
4241
|
+
waypoints.push(last);
|
|
4242
|
+
}
|
|
4243
|
+
return reduceToCap(waypoints, thresholds.maxWaypoints);
|
|
4244
|
+
}
|
|
4245
|
+
});
|
|
4246
|
+
|
|
4247
|
+
// ../../packages/core/dist/utils/index.js
|
|
4248
|
+
var require_utils = __commonJS((exports) => {
|
|
4249
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4250
|
+
if (k2 === undefined)
|
|
4251
|
+
k2 = k;
|
|
4252
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4253
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4254
|
+
desc = { enumerable: true, get: function() {
|
|
4255
|
+
return m[k];
|
|
4256
|
+
} };
|
|
4257
|
+
}
|
|
4258
|
+
Object.defineProperty(o, k2, desc);
|
|
4259
|
+
} : function(o, m, k, k2) {
|
|
4260
|
+
if (k2 === undefined)
|
|
4261
|
+
k2 = k;
|
|
4262
|
+
o[k2] = m[k];
|
|
4263
|
+
});
|
|
4264
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
4265
|
+
for (var p in m)
|
|
4266
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
4267
|
+
__createBinding(exports2, m, p);
|
|
4268
|
+
};
|
|
4269
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4270
|
+
__exportStar(require_formatting(), exports);
|
|
4271
|
+
__exportStar(require_geospatial(), exports);
|
|
4272
|
+
__exportStar(require_routeGeneration(), exports);
|
|
4273
|
+
});
|
|
4274
|
+
|
|
4275
|
+
// ../../packages/core/dist/index.js
|
|
4276
|
+
var require_dist = __commonJS((exports) => {
|
|
4277
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
4278
|
+
if (k2 === undefined)
|
|
4279
|
+
k2 = k;
|
|
4280
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4281
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
4282
|
+
desc = { enumerable: true, get: function() {
|
|
4283
|
+
return m[k];
|
|
4284
|
+
} };
|
|
4285
|
+
}
|
|
4286
|
+
Object.defineProperty(o, k2, desc);
|
|
4287
|
+
} : function(o, m, k, k2) {
|
|
4288
|
+
if (k2 === undefined)
|
|
4289
|
+
k2 = k;
|
|
4290
|
+
o[k2] = m[k];
|
|
4291
|
+
});
|
|
4292
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
|
|
4293
|
+
for (var p in m)
|
|
4294
|
+
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
|
|
4295
|
+
__createBinding(exports2, m, p);
|
|
4296
|
+
};
|
|
4297
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4298
|
+
__exportStar(require_errors(), exports);
|
|
4299
|
+
__exportStar(require_history(), exports);
|
|
4300
|
+
__exportStar(require_user_preferences(), exports);
|
|
4301
|
+
__exportStar(require_stores(), exports);
|
|
4302
|
+
__exportStar(require_types(), exports);
|
|
4303
|
+
__exportStar(require_utils(), exports);
|
|
4304
|
+
});
|
|
4305
|
+
|
|
4306
|
+
// src/output.ts
|
|
4307
|
+
var exports_output = {};
|
|
4308
|
+
__export(exports_output, {
|
|
4309
|
+
renderResult: () => renderResult,
|
|
4310
|
+
renderError: () => renderError,
|
|
4311
|
+
cliErrorFromDomain: () => cliErrorFromDomain,
|
|
4312
|
+
EXIT_CODES: () => EXIT_CODES,
|
|
4313
|
+
CliError: () => CliError
|
|
4314
|
+
});
|
|
4315
|
+
function cliErrorFromDomain(payload) {
|
|
4316
|
+
return new CliError(payload.message, EXIT_CODES[payload.code], payload);
|
|
4317
|
+
}
|
|
4318
|
+
function renderResult(options, data, humanRenderer) {
|
|
4319
|
+
if (options.json) {
|
|
4320
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}
|
|
4321
|
+
`);
|
|
4322
|
+
return;
|
|
4323
|
+
}
|
|
4324
|
+
const rendered = humanRenderer(data);
|
|
4325
|
+
if (rendered.length > 0) {
|
|
4326
|
+
process.stdout.write(`${rendered}
|
|
4327
|
+
`);
|
|
4328
|
+
}
|
|
4329
|
+
}
|
|
4330
|
+
function renderError(options, error) {
|
|
4331
|
+
if (error instanceof CliError) {
|
|
4332
|
+
if (options.json) {
|
|
4333
|
+
const body = error.payload ?? { exitCode: error.exitCode, message: error.message };
|
|
4334
|
+
process.stderr.write(`${JSON.stringify(body, null, 2)}
|
|
4335
|
+
`);
|
|
4336
|
+
} else {
|
|
4337
|
+
process.stderr.write(`error: ${error.message}
|
|
4338
|
+
`);
|
|
4339
|
+
}
|
|
4340
|
+
return error.exitCode;
|
|
4341
|
+
}
|
|
4342
|
+
if (import_core.isDomainErrorPayload(error)) {
|
|
4343
|
+
if (options.json) {
|
|
4344
|
+
process.stderr.write(`${JSON.stringify(error, null, 2)}
|
|
4345
|
+
`);
|
|
4346
|
+
} else {
|
|
4347
|
+
process.stderr.write(`error: ${error.message}
|
|
4348
|
+
`);
|
|
4349
|
+
}
|
|
4350
|
+
return EXIT_CODES[error.code];
|
|
4351
|
+
}
|
|
4352
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4353
|
+
if (options.json) {
|
|
4354
|
+
process.stderr.write(`${JSON.stringify({ exitCode: EXIT_CODES.GENERIC, message }, null, 2)}
|
|
4355
|
+
`);
|
|
4356
|
+
} else {
|
|
4357
|
+
process.stderr.write(`error: ${message}
|
|
4358
|
+
`);
|
|
4359
|
+
}
|
|
4360
|
+
return EXIT_CODES.GENERIC;
|
|
4361
|
+
}
|
|
4362
|
+
var import_core, EXIT_CODES, CliError;
|
|
4363
|
+
var init_output = __esm(() => {
|
|
4364
|
+
import_core = __toESM(require_dist(), 1);
|
|
4365
|
+
EXIT_CODES = {
|
|
4366
|
+
GENERIC: 1,
|
|
4367
|
+
USAGE: 2,
|
|
4368
|
+
VALIDATION_FAILED: 3,
|
|
4369
|
+
NOT_FOUND: 4,
|
|
4370
|
+
UNAUTHORIZED: 5,
|
|
4371
|
+
FORBIDDEN: 6,
|
|
4372
|
+
CONFLICT: 7,
|
|
4373
|
+
RATE_LIMITED: 8,
|
|
4374
|
+
PRECONDITION_REQUIRED: 9,
|
|
4375
|
+
NETWORK: 10,
|
|
4376
|
+
INTERNAL: 11
|
|
4377
|
+
};
|
|
4378
|
+
CliError = class CliError extends Error {
|
|
4379
|
+
exitCode;
|
|
4380
|
+
payload;
|
|
4381
|
+
constructor(message, exitCode, payload) {
|
|
4382
|
+
super(message);
|
|
4383
|
+
this.exitCode = exitCode;
|
|
4384
|
+
this.payload = payload;
|
|
4385
|
+
this.name = "CliError";
|
|
4386
|
+
}
|
|
4387
|
+
};
|
|
4388
|
+
});
|
|
4389
|
+
|
|
4390
|
+
// src/index.ts
|
|
4391
|
+
import { readFileSync as readFileSync2 } from "node:fs";
|
|
4392
|
+
import { dirname, join as join2 } from "node:path";
|
|
4393
|
+
import { fileURLToPath } from "node:url";
|
|
4394
|
+
|
|
4395
|
+
// ../../node_modules/.bun/commander@13.1.0/node_modules/commander/esm.mjs
|
|
4396
|
+
var import__ = __toESM(require_commander(), 1);
|
|
4397
|
+
var {
|
|
4398
|
+
program,
|
|
4399
|
+
createCommand,
|
|
4400
|
+
createArgument,
|
|
4401
|
+
createOption,
|
|
4402
|
+
CommanderError,
|
|
4403
|
+
InvalidArgumentError,
|
|
4404
|
+
InvalidOptionArgumentError,
|
|
4405
|
+
Command,
|
|
4406
|
+
Argument,
|
|
4407
|
+
Option,
|
|
4408
|
+
Help
|
|
4409
|
+
} = import__.default;
|
|
4410
|
+
|
|
4411
|
+
// src/client.ts
|
|
4412
|
+
init_output();
|
|
4413
|
+
var import_core2 = __toESM(require_dist(), 1);
|
|
4414
|
+
async function request(client, path, options = {}) {
|
|
4415
|
+
const url = new URL(path.startsWith("/") ? path.slice(1) : path, `${client.apiUrl.replace(/\/$/, "")}/`);
|
|
4416
|
+
const headers = {
|
|
4417
|
+
Accept: "application/json"
|
|
4418
|
+
};
|
|
4419
|
+
if (client.token) {
|
|
4420
|
+
headers.Authorization = `Bearer ${client.token}`;
|
|
4421
|
+
}
|
|
4422
|
+
if (options.body !== undefined) {
|
|
4423
|
+
headers["Content-Type"] = "application/json";
|
|
4424
|
+
}
|
|
4425
|
+
if (options.confirm) {
|
|
4426
|
+
headers["X-Routess-Confirm"] = "true";
|
|
4427
|
+
}
|
|
4428
|
+
let response;
|
|
4429
|
+
try {
|
|
4430
|
+
response = await fetch(url, {
|
|
4431
|
+
method: options.method ?? "GET",
|
|
4432
|
+
headers,
|
|
4433
|
+
body: options.body !== undefined ? JSON.stringify(options.body) : undefined
|
|
4434
|
+
});
|
|
4435
|
+
} catch (cause) {
|
|
4436
|
+
throw new CliError(`Network error reaching ${url.origin}: ${cause instanceof Error ? cause.message : String(cause)}`, EXIT_CODES.NETWORK);
|
|
4437
|
+
}
|
|
4438
|
+
if (response.status === 204) {
|
|
4439
|
+
return;
|
|
4440
|
+
}
|
|
4441
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
4442
|
+
const payload = contentType.includes("application/json") ? await response.json() : undefined;
|
|
4443
|
+
if (!response.ok) {
|
|
4444
|
+
if (import_core2.isDomainErrorPayload(payload)) {
|
|
4445
|
+
throw new CliError(payload.message, EXIT_CODES[payload.code], payload);
|
|
4446
|
+
}
|
|
4447
|
+
throw new CliError(`Request failed: ${response.status} ${response.statusText}`, response.status === 401 ? EXIT_CODES.UNAUTHORIZED : EXIT_CODES.GENERIC);
|
|
4448
|
+
}
|
|
4449
|
+
return payload;
|
|
4450
|
+
}
|
|
4451
|
+
|
|
4452
|
+
// src/config.ts
|
|
4453
|
+
init_output();
|
|
4454
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4455
|
+
import { homedir } from "node:os";
|
|
4456
|
+
import { join } from "node:path";
|
|
4457
|
+
function configDir() {
|
|
4458
|
+
const xdg = process.env.XDG_CONFIG_HOME?.trim();
|
|
4459
|
+
const base = xdg && xdg.length > 0 ? xdg : join(homedir(), ".config");
|
|
4460
|
+
return join(base, "routess");
|
|
4461
|
+
}
|
|
4462
|
+
function authFilePath() {
|
|
4463
|
+
return join(configDir(), "auth.json");
|
|
4464
|
+
}
|
|
4465
|
+
function readPersisted() {
|
|
4466
|
+
const path = authFilePath();
|
|
4467
|
+
if (!existsSync(path)) {
|
|
4468
|
+
return {};
|
|
4469
|
+
}
|
|
4470
|
+
try {
|
|
4471
|
+
const raw = readFileSync(path, "utf8");
|
|
4472
|
+
const parsed = JSON.parse(raw);
|
|
4473
|
+
return parsed;
|
|
4474
|
+
} catch {
|
|
4475
|
+
return {};
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
function loadConfig() {
|
|
4479
|
+
const envToken = process.env.ROUTESS_TOKEN?.trim();
|
|
4480
|
+
const envApiUrl = process.env.ROUTESS_API_URL?.trim();
|
|
4481
|
+
const persisted = readPersisted();
|
|
4482
|
+
const apiUrl = envApiUrl || persisted.apiUrl || "https://routess-api.robbeverhelst.com";
|
|
4483
|
+
if (envToken && envToken.length > 0) {
|
|
4484
|
+
return { apiUrl, token: envToken, tokenSource: "env" };
|
|
4485
|
+
}
|
|
4486
|
+
if (persisted.token && persisted.token.length > 0) {
|
|
4487
|
+
return { apiUrl, token: persisted.token, tokenSource: "file" };
|
|
4488
|
+
}
|
|
4489
|
+
return { apiUrl, token: null, tokenSource: "none" };
|
|
4490
|
+
}
|
|
4491
|
+
function saveToken(token, apiUrl) {
|
|
4492
|
+
const dir = configDir();
|
|
4493
|
+
mkdirSync(dir, { recursive: true });
|
|
4494
|
+
const path = authFilePath();
|
|
4495
|
+
const existing = readPersisted();
|
|
4496
|
+
const payload = {
|
|
4497
|
+
...existing,
|
|
4498
|
+
token,
|
|
4499
|
+
...apiUrl ? { apiUrl } : {}
|
|
4500
|
+
};
|
|
4501
|
+
writeFileSync(path, `${JSON.stringify(payload, null, 2)}
|
|
4502
|
+
`, { encoding: "utf8" });
|
|
4503
|
+
try {
|
|
4504
|
+
chmodSync(path, 384);
|
|
4505
|
+
} catch {}
|
|
4506
|
+
}
|
|
4507
|
+
function clearToken() {
|
|
4508
|
+
const path = authFilePath();
|
|
4509
|
+
if (!existsSync(path)) {
|
|
4510
|
+
return false;
|
|
4511
|
+
}
|
|
4512
|
+
rmSync(path);
|
|
4513
|
+
const dir = configDir();
|
|
4514
|
+
try {
|
|
4515
|
+
rmSync(dir, { recursive: false });
|
|
4516
|
+
} catch {}
|
|
4517
|
+
return true;
|
|
4518
|
+
}
|
|
4519
|
+
function configFileLocation() {
|
|
4520
|
+
return authFilePath();
|
|
4521
|
+
}
|
|
4522
|
+
function requireToken(config) {
|
|
4523
|
+
if (!config.token) {
|
|
4524
|
+
throw new CliError("Not signed in. Run `routess auth login --token <pat>` after minting a token in the web app Settings → API Tokens.", EXIT_CODES.UNAUTHORIZED);
|
|
4525
|
+
}
|
|
4526
|
+
return config.token;
|
|
4527
|
+
}
|
|
4528
|
+
|
|
4529
|
+
// src/commands/auth.ts
|
|
4530
|
+
init_output();
|
|
4531
|
+
function registerAuthCommands(program2) {
|
|
4532
|
+
const auth = program2.command("auth").description("Authentication: log in with a personal access token, log out, identify the current session.");
|
|
4533
|
+
auth.command("login").description("Store a personal access token for subsequent commands. Mint a token at the web app's Settings → API Tokens page first.").requiredOption("--token <pat>", "the routess_pat_… token copied from the web Settings page").option("--api-url <url>", "API base URL to associate with this token (otherwise the existing value or the default is kept)").action(async (options) => {
|
|
4534
|
+
await runWithProgram(program2, async (runOptions) => {
|
|
4535
|
+
if (!options.token?.startsWith("routess_pat_")) {
|
|
4536
|
+
throw new CliError("Token must start with routess_pat_", EXIT_CODES.USAGE);
|
|
4537
|
+
}
|
|
4538
|
+
const config = { ...loadConfig(), token: options.token, apiUrl: options.apiUrl ?? loadConfig().apiUrl };
|
|
4539
|
+
let me;
|
|
4540
|
+
try {
|
|
4541
|
+
me = await request(config, "/api/v1/users/me");
|
|
4542
|
+
} catch (error) {
|
|
4543
|
+
if (error instanceof CliError && error.exitCode === EXIT_CODES.UNAUTHORIZED) {
|
|
4544
|
+
throw new CliError("Token was rejected by the API. Confirm it was copied in full and that the API URL is correct.", EXIT_CODES.UNAUTHORIZED);
|
|
4545
|
+
}
|
|
4546
|
+
throw error;
|
|
4547
|
+
}
|
|
4548
|
+
saveToken(options.token, options.apiUrl);
|
|
4549
|
+
renderResult(runOptions, { user: me, location: configFileLocation() }, (data) => {
|
|
4550
|
+
return `Signed in as ${data.user.email}. Token saved to ${data.location}.`;
|
|
4551
|
+
});
|
|
4552
|
+
});
|
|
4553
|
+
});
|
|
4554
|
+
auth.command("logout").description("Forget the stored token. The token itself remains valid on the server until revoked from the web Settings page.").action(async () => {
|
|
4555
|
+
await runWithProgram(program2, async (runOptions) => {
|
|
4556
|
+
const removed = clearToken();
|
|
4557
|
+
renderResult(runOptions, { removed, location: configFileLocation() }, (data) => data.removed ? `Token removed (${data.location}).` : "No stored token to remove.");
|
|
4558
|
+
});
|
|
4559
|
+
});
|
|
4560
|
+
auth.command("whoami").description("Show the user identity associated with the currently active token.").action(async () => {
|
|
4561
|
+
await runWithProgram(program2, async (runOptions) => {
|
|
4562
|
+
const config = loadConfig();
|
|
4563
|
+
requireToken(config);
|
|
4564
|
+
const me = await request(config, "/api/v1/users/me");
|
|
4565
|
+
renderResult(runOptions, me, (data) => `${data.email} (id=${data.id}, name=${data.name})`);
|
|
4566
|
+
});
|
|
4567
|
+
});
|
|
4568
|
+
}
|
|
4569
|
+
async function runWithProgram(program2, action) {
|
|
4570
|
+
const opts = program2.opts();
|
|
4571
|
+
const runOptions = { json: Boolean(opts.json) };
|
|
4572
|
+
try {
|
|
4573
|
+
await action(runOptions);
|
|
4574
|
+
} catch (error) {
|
|
4575
|
+
const { renderError: renderError2 } = await Promise.resolve().then(() => (init_output(), exports_output));
|
|
4576
|
+
const code = renderError2(runOptions, error);
|
|
4577
|
+
process.exit(code);
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
|
|
4581
|
+
// src/commands/routes.ts
|
|
4582
|
+
init_output();
|
|
4583
|
+
function formatRouteRow(route) {
|
|
4584
|
+
const distanceKm = route.distance ? `${(route.distance / 1000).toFixed(1)}km` : "—";
|
|
4585
|
+
const activity = route.activity ?? "—";
|
|
4586
|
+
return `${route.id} ${route.name} ${activity} ${route.visibility} ${distanceKm}`;
|
|
4587
|
+
}
|
|
4588
|
+
function registerRoutesCommands(program2) {
|
|
4589
|
+
const routes = program2.command("routes").description("List, inspect, and edit metadata of saved routes.");
|
|
4590
|
+
routes.command("list").description("List the authenticated user's routes.").action(async () => {
|
|
4591
|
+
await runWithProgram2(program2, async (runOptions) => {
|
|
4592
|
+
const config = loadConfig();
|
|
4593
|
+
requireToken(config);
|
|
4594
|
+
const items = await request(config, "/api/v1/routes");
|
|
4595
|
+
renderResult(runOptions, items, (data) => {
|
|
4596
|
+
if (data.length === 0) {
|
|
4597
|
+
return "No routes.";
|
|
4598
|
+
}
|
|
4599
|
+
const header = "id\tname\tactivity\tprivacy\tdistance";
|
|
4600
|
+
const body = data.map(formatRouteRow).join(`
|
|
4601
|
+
`);
|
|
4602
|
+
return `${header}
|
|
4603
|
+
${body}`;
|
|
4604
|
+
});
|
|
4605
|
+
});
|
|
4606
|
+
});
|
|
4607
|
+
routes.command("get <id>").description("Fetch a single route by id.").action(async (id) => {
|
|
4608
|
+
await runWithProgram2(program2, async (runOptions) => {
|
|
4609
|
+
const config = loadConfig();
|
|
4610
|
+
requireToken(config);
|
|
4611
|
+
const numericId = parseId(id);
|
|
4612
|
+
const route = await request(config, `/api/v1/routes/${numericId}`);
|
|
4613
|
+
renderResult(runOptions, route, (data) => {
|
|
4614
|
+
const distanceKm = data.distance ? `${(data.distance / 1000).toFixed(2)} km` : "n/a";
|
|
4615
|
+
const lines = [
|
|
4616
|
+
`Route ${data.id}: ${data.name}`,
|
|
4617
|
+
` activity : ${data.activity ?? "n/a"}`,
|
|
4618
|
+
` visibility: ${data.visibility}`,
|
|
4619
|
+
` distance : ${distanceKm}`,
|
|
4620
|
+
` tags : ${data.tags.join(", ") || "(none)"}`,
|
|
4621
|
+
` created : ${data.createdAt}`,
|
|
4622
|
+
` updated : ${data.updatedAt}`
|
|
4623
|
+
];
|
|
4624
|
+
return lines.join(`
|
|
4625
|
+
`);
|
|
4626
|
+
});
|
|
4627
|
+
});
|
|
4628
|
+
});
|
|
4629
|
+
routes.command("update <id>").description("Update metadata on a route (name / activity / visibility). Body fields are optional but at least one is required.").option("--name <name>", "rename the route").option("--activity <activity>", "set the activity (e.g. run, cycle, walk)").option("--visibility <visibility>", "set the visibility: private | unlisted | public").option("--confirm", "set X-Routess-Confirm: true (required when --visibility is public)").action(async (id, options) => {
|
|
4630
|
+
await runWithProgram2(program2, async (runOptions) => {
|
|
4631
|
+
const config = loadConfig();
|
|
4632
|
+
requireToken(config);
|
|
4633
|
+
const body = {};
|
|
4634
|
+
if (options.name !== undefined)
|
|
4635
|
+
body.name = options.name;
|
|
4636
|
+
if (options.activity !== undefined)
|
|
4637
|
+
body.activity = options.activity;
|
|
4638
|
+
if (options.visibility !== undefined)
|
|
4639
|
+
body.visibility = options.visibility;
|
|
4640
|
+
if (Object.keys(body).length === 0) {
|
|
4641
|
+
throw new CliError("At least one of --name, --activity, --visibility is required.", EXIT_CODES.USAGE);
|
|
4642
|
+
}
|
|
4643
|
+
const numericId = parseId(id);
|
|
4644
|
+
const route = await request(config, `/api/v1/routes/${numericId}`, {
|
|
4645
|
+
method: "PATCH",
|
|
4646
|
+
body,
|
|
4647
|
+
confirm: options.confirm
|
|
4648
|
+
});
|
|
4649
|
+
renderResult(runOptions, route, (data) => `Updated route ${data.id}: ${data.name} (${data.visibility}).`);
|
|
4650
|
+
});
|
|
4651
|
+
});
|
|
4652
|
+
routes.command("delete <id>").description("Delete a route. PAT callers must pass --confirm.").option("--confirm", "set X-Routess-Confirm: true").action(async (id, options) => {
|
|
4653
|
+
await runWithProgram2(program2, async (runOptions) => {
|
|
4654
|
+
const config = loadConfig();
|
|
4655
|
+
requireToken(config);
|
|
4656
|
+
const numericId = parseId(id);
|
|
4657
|
+
const result = await request(config, `/api/v1/routes/${numericId}`, {
|
|
4658
|
+
method: "DELETE",
|
|
4659
|
+
confirm: options.confirm
|
|
4660
|
+
});
|
|
4661
|
+
renderResult(runOptions, result, (data) => data.message);
|
|
4662
|
+
});
|
|
4663
|
+
});
|
|
4664
|
+
}
|
|
4665
|
+
function parseId(id) {
|
|
4666
|
+
const numeric = Number(id);
|
|
4667
|
+
if (!Number.isFinite(numeric) || !Number.isInteger(numeric) || numeric <= 0) {
|
|
4668
|
+
throw new CliError(`Invalid route id: ${id}`, EXIT_CODES.USAGE);
|
|
4669
|
+
}
|
|
4670
|
+
return numeric;
|
|
4671
|
+
}
|
|
4672
|
+
async function runWithProgram2(program2, action) {
|
|
4673
|
+
const opts = program2.opts();
|
|
4674
|
+
const runOptions = { json: Boolean(opts.json) };
|
|
4675
|
+
try {
|
|
4676
|
+
await action(runOptions);
|
|
4677
|
+
} catch (error) {
|
|
4678
|
+
const { renderError: renderError2 } = await Promise.resolve().then(() => (init_output(), exports_output));
|
|
4679
|
+
const code = renderError2(runOptions, error);
|
|
4680
|
+
process.exit(code);
|
|
4681
|
+
}
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4684
|
+
// src/index.ts
|
|
4685
|
+
init_output();
|
|
4686
|
+
var program2 = new Command;
|
|
4687
|
+
var packageJsonPath = join2(dirname(fileURLToPath(import.meta.url)), "../package.json");
|
|
4688
|
+
var packageVersion = JSON.parse(readFileSync2(packageJsonPath, "utf8")).version;
|
|
4689
|
+
program2.name("routess").description("Routess command-line interface. See `routess auth login --help` to get started.").version(packageVersion).option("--json", "emit machine-readable JSON to stdout, errors as DomainErrorPayload to stderr", false).option("--api-url <url>", "override the API base URL (defaults to ROUTESS_API_URL env var or production)");
|
|
4690
|
+
async function runCommand(action) {
|
|
4691
|
+
const options = program2.opts();
|
|
4692
|
+
const runOptions = { json: Boolean(options.json) };
|
|
4693
|
+
try {
|
|
4694
|
+
await action(runOptions);
|
|
4695
|
+
} catch (error) {
|
|
4696
|
+
const code = renderError(runOptions, error);
|
|
4697
|
+
process.exit(code);
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
registerAuthCommands(program2);
|
|
4701
|
+
registerRoutesCommands(program2);
|
|
4702
|
+
program2.parseAsync(process.argv).catch((error) => {
|
|
4703
|
+
const options = program2.opts();
|
|
4704
|
+
const code = renderError({ json: Boolean(options.json) }, error);
|
|
4705
|
+
process.exit(code);
|
|
4706
|
+
});
|
|
4707
|
+
export {
|
|
4708
|
+
runCommand
|
|
4709
|
+
};
|