@apps-in-toss/web-framework 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-5AYTRYXW.js +27 -0
- package/dist/chunk-MHAJE5QI.js +34 -0
- package/dist/cli.cjs +4598 -0
- package/dist/cli.d.cts +3 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +3555 -0
- package/dist/config/index.cjs +17 -4
- package/dist/config/index.d.cts +19 -3
- package/dist/config/index.d.ts +19 -3
- package/dist/config/index.js +7714 -23
- package/dist/lib-EUN4APCZ.js +1007 -0
- package/dist/lib-OD73GAMK.js +1007 -0
- package/package.json +14 -12
- package/src-web/closeView.d.ts +24 -0
- package/src-web/generateHapticFeedback.d.ts +52 -0
- package/src-web/getDeviceId.d.ts +32 -0
- package/src-web/getLocale.d.ts +31 -0
- package/src-web/getNetworkStatus.d.ts +55 -0
- package/src-web/getSchemeUri.d.ts +26 -0
- package/src-web/index.js +1 -0
- package/src-web/setScreenAwakeMode.d.ts +69 -0
- package/src-web/setSecureScreen.d.ts +34 -0
- package/src-web/share.d.ts +37 -0
- package/dist/chunk-CH3CIAIW.js +0 -7688
- package/dist/closeView.d.ts +0 -1
- package/dist/generateHapticFeedback.d.ts +0 -1
- package/dist/getDeviceId.d.ts +0 -1
- package/dist/getLocale.d.ts +0 -1
- package/dist/getNetworkStatus.d.ts +0 -1
- package/dist/getSchemeUri.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/plugins/index.cjs +0 -7682
- package/dist/plugins/index.d.cts +0 -15
- package/dist/plugins/index.d.ts +0 -15
- package/dist/plugins/index.js +0 -11
- package/dist/setScreenAwakeMode.d.ts +0 -1
- package/dist/setSecureScreen.d.ts +0 -1
- package/dist/share.d.ts +0 -1
- /package/{dist → src-web}/fetchAlbumPhotos.d.ts +0 -0
- /package/{dist → src-web}/fetchContacts.d.ts +0 -0
- /package/{dist → src-web}/getClipboardText.d.ts +0 -0
- /package/{dist → src-web}/getCurrentLocation.d.ts +0 -0
- /package/{dist → src-web}/index.d.ts +0 -0
- /package/{dist → src-web}/openCamera.d.ts +0 -0
- /package/{dist → src-web}/setClipboardText.d.ts +0 -0
- /package/{dist → src-web}/startUpdateLocation.d.ts +0 -0
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,4598 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
|
|
36
|
+
// ../../.yarn/__virtual__/tsup-virtual-7254073ea3/0/cache/tsup-npm-8.3.5-ed25596739-7794953cbc.zip/node_modules/tsup/assets/cjs_shims.js
|
|
37
|
+
var init_cjs_shims = __esm({
|
|
38
|
+
"../../.yarn/__virtual__/tsup-virtual-7254073ea3/0/cache/tsup-npm-8.3.5-ed25596739-7794953cbc.zip/node_modules/tsup/assets/cjs_shims.js"() {
|
|
39
|
+
"use strict";
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ../../.yarn/cache/typanion-npm-3.14.0-0a46072207-8b03b19844.zip/node_modules/typanion/lib/index.js
|
|
44
|
+
var require_lib = __commonJS({
|
|
45
|
+
"../../.yarn/cache/typanion-npm-3.14.0-0a46072207-8b03b19844.zip/node_modules/typanion/lib/index.js"(exports2) {
|
|
46
|
+
"use strict";
|
|
47
|
+
init_cjs_shims();
|
|
48
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
49
|
+
var simpleKeyRegExp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
50
|
+
function getPrintable(value) {
|
|
51
|
+
if (value === null)
|
|
52
|
+
return `null`;
|
|
53
|
+
if (value === void 0)
|
|
54
|
+
return `undefined`;
|
|
55
|
+
if (value === ``)
|
|
56
|
+
return `an empty string`;
|
|
57
|
+
if (typeof value === "symbol")
|
|
58
|
+
return `<${value.toString()}>`;
|
|
59
|
+
if (Array.isArray(value))
|
|
60
|
+
return `an array`;
|
|
61
|
+
return JSON.stringify(value);
|
|
62
|
+
}
|
|
63
|
+
function getPrintableArray(value, conjunction) {
|
|
64
|
+
if (value.length === 0)
|
|
65
|
+
return `nothing`;
|
|
66
|
+
if (value.length === 1)
|
|
67
|
+
return getPrintable(value[0]);
|
|
68
|
+
const rest = value.slice(0, -1);
|
|
69
|
+
const trailing = value[value.length - 1];
|
|
70
|
+
const separator = value.length > 2 ? `, ${conjunction} ` : ` ${conjunction} `;
|
|
71
|
+
return `${rest.map((value2) => getPrintable(value2)).join(`, `)}${separator}${getPrintable(trailing)}`;
|
|
72
|
+
}
|
|
73
|
+
function computeKey(state, key) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
if (typeof key === `number`) {
|
|
76
|
+
return `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}[${key}]`;
|
|
77
|
+
} else if (simpleKeyRegExp.test(key)) {
|
|
78
|
+
return `${(_b = state === null || state === void 0 ? void 0 : state.p) !== null && _b !== void 0 ? _b : ``}.${key}`;
|
|
79
|
+
} else {
|
|
80
|
+
return `${(_c = state === null || state === void 0 ? void 0 : state.p) !== null && _c !== void 0 ? _c : `.`}[${JSON.stringify(key)}]`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function plural(n, singular, plural2) {
|
|
84
|
+
return n === 1 ? singular : plural2;
|
|
85
|
+
}
|
|
86
|
+
var colorStringRegExp = /^#[0-9a-f]{6}$/i;
|
|
87
|
+
var colorStringAlphaRegExp = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
|
|
88
|
+
var base64RegExp = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
89
|
+
var uuid4RegExp = /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}$/i;
|
|
90
|
+
var iso8601RegExp = /^(?:[1-9]\d{3}(-?)(?:(?:0[1-9]|1[0-2])\1(?:0[1-9]|1\d|2[0-8])|(?:0[13-9]|1[0-2])\1(?:29|30)|(?:0[13578]|1[02])(?:\1)31|00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[0-5]))|(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)(?:(-?)02(?:\2)29|-?366))T(?:[01]\d|2[0-3])(:?)[0-5]\d(?:\3[0-5]\d)?(?:Z|[+-][01]\d(?:\3[0-5]\d)?)$/;
|
|
91
|
+
function pushError({ errors, p } = {}, message) {
|
|
92
|
+
errors === null || errors === void 0 ? void 0 : errors.push(`${p !== null && p !== void 0 ? p : `.`}: ${message}`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
function makeSetter(target, key) {
|
|
96
|
+
return (v) => {
|
|
97
|
+
target[key] = v;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function makeCoercionFn(target, key) {
|
|
101
|
+
return (v) => {
|
|
102
|
+
const previous = target[key];
|
|
103
|
+
target[key] = v;
|
|
104
|
+
return makeCoercionFn(target, key).bind(null, previous);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function makeLazyCoercionFn(fn2, orig, generator) {
|
|
108
|
+
const commit = () => {
|
|
109
|
+
fn2(generator());
|
|
110
|
+
return revert;
|
|
111
|
+
};
|
|
112
|
+
const revert = () => {
|
|
113
|
+
fn2(orig);
|
|
114
|
+
return commit;
|
|
115
|
+
};
|
|
116
|
+
return commit;
|
|
117
|
+
}
|
|
118
|
+
function isUnknown() {
|
|
119
|
+
return makeValidator({
|
|
120
|
+
test: (value, state) => {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function isLiteral(expected) {
|
|
126
|
+
return makeValidator({
|
|
127
|
+
test: (value, state) => {
|
|
128
|
+
if (value !== expected)
|
|
129
|
+
return pushError(state, `Expected ${getPrintable(expected)} (got ${getPrintable(value)})`);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function isString() {
|
|
135
|
+
return makeValidator({
|
|
136
|
+
test: (value, state) => {
|
|
137
|
+
if (typeof value !== `string`)
|
|
138
|
+
return pushError(state, `Expected a string (got ${getPrintable(value)})`);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function isEnum(enumSpec) {
|
|
144
|
+
const valuesArray = Array.isArray(enumSpec) ? enumSpec : Object.values(enumSpec);
|
|
145
|
+
const isAlphaNum = valuesArray.every((item) => typeof item === "string" || typeof item === "number");
|
|
146
|
+
const values = new Set(valuesArray);
|
|
147
|
+
if (values.size === 1)
|
|
148
|
+
return isLiteral([...values][0]);
|
|
149
|
+
return makeValidator({
|
|
150
|
+
test: (value, state) => {
|
|
151
|
+
if (!values.has(value)) {
|
|
152
|
+
if (isAlphaNum) {
|
|
153
|
+
return pushError(state, `Expected one of ${getPrintableArray(valuesArray, `or`)} (got ${getPrintable(value)})`);
|
|
154
|
+
} else {
|
|
155
|
+
return pushError(state, `Expected a valid enumeration value (got ${getPrintable(value)})`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
var BOOLEAN_COERCIONS = /* @__PURE__ */ new Map([
|
|
163
|
+
[`true`, true],
|
|
164
|
+
[`True`, true],
|
|
165
|
+
[`1`, true],
|
|
166
|
+
[1, true],
|
|
167
|
+
[`false`, false],
|
|
168
|
+
[`False`, false],
|
|
169
|
+
[`0`, false],
|
|
170
|
+
[0, false]
|
|
171
|
+
]);
|
|
172
|
+
function isBoolean() {
|
|
173
|
+
return makeValidator({
|
|
174
|
+
test: (value, state) => {
|
|
175
|
+
var _a;
|
|
176
|
+
if (typeof value !== `boolean`) {
|
|
177
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
178
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
179
|
+
return pushError(state, `Unbound coercion result`);
|
|
180
|
+
const coercion = BOOLEAN_COERCIONS.get(value);
|
|
181
|
+
if (typeof coercion !== `undefined`) {
|
|
182
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return pushError(state, `Expected a boolean (got ${getPrintable(value)})`);
|
|
187
|
+
}
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function isNumber() {
|
|
193
|
+
return makeValidator({
|
|
194
|
+
test: (value, state) => {
|
|
195
|
+
var _a;
|
|
196
|
+
if (typeof value !== `number`) {
|
|
197
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
198
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
199
|
+
return pushError(state, `Unbound coercion result`);
|
|
200
|
+
let coercion;
|
|
201
|
+
if (typeof value === `string`) {
|
|
202
|
+
let val;
|
|
203
|
+
try {
|
|
204
|
+
val = JSON.parse(value);
|
|
205
|
+
} catch (_b) {
|
|
206
|
+
}
|
|
207
|
+
if (typeof val === `number`) {
|
|
208
|
+
if (JSON.stringify(val) === value) {
|
|
209
|
+
coercion = val;
|
|
210
|
+
} else {
|
|
211
|
+
return pushError(state, `Received a number that can't be safely represented by the runtime (${value})`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (typeof coercion !== `undefined`) {
|
|
216
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return pushError(state, `Expected a number (got ${getPrintable(value)})`);
|
|
221
|
+
}
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function isPayload(spec) {
|
|
227
|
+
return makeValidator({
|
|
228
|
+
test: (value, state) => {
|
|
229
|
+
var _a;
|
|
230
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) === `undefined`)
|
|
231
|
+
return pushError(state, `The isPayload predicate can only be used with coercion enabled`);
|
|
232
|
+
if (typeof state.coercion === `undefined`)
|
|
233
|
+
return pushError(state, `Unbound coercion result`);
|
|
234
|
+
if (typeof value !== `string`)
|
|
235
|
+
return pushError(state, `Expected a string (got ${getPrintable(value)})`);
|
|
236
|
+
let inner;
|
|
237
|
+
try {
|
|
238
|
+
inner = JSON.parse(value);
|
|
239
|
+
} catch (_b) {
|
|
240
|
+
return pushError(state, `Expected a JSON string (got ${getPrintable(value)})`);
|
|
241
|
+
}
|
|
242
|
+
const wrapper = { value: inner };
|
|
243
|
+
if (!spec(inner, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(wrapper, `value`) })))
|
|
244
|
+
return false;
|
|
245
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, wrapper.value)]);
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function isDate() {
|
|
251
|
+
return makeValidator({
|
|
252
|
+
test: (value, state) => {
|
|
253
|
+
var _a;
|
|
254
|
+
if (!(value instanceof Date)) {
|
|
255
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
256
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
257
|
+
return pushError(state, `Unbound coercion result`);
|
|
258
|
+
let coercion;
|
|
259
|
+
if (typeof value === `string` && iso8601RegExp.test(value)) {
|
|
260
|
+
coercion = new Date(value);
|
|
261
|
+
} else {
|
|
262
|
+
let timestamp;
|
|
263
|
+
if (typeof value === `string`) {
|
|
264
|
+
let val;
|
|
265
|
+
try {
|
|
266
|
+
val = JSON.parse(value);
|
|
267
|
+
} catch (_b) {
|
|
268
|
+
}
|
|
269
|
+
if (typeof val === `number`) {
|
|
270
|
+
timestamp = val;
|
|
271
|
+
}
|
|
272
|
+
} else if (typeof value === `number`) {
|
|
273
|
+
timestamp = value;
|
|
274
|
+
}
|
|
275
|
+
if (typeof timestamp !== `undefined`) {
|
|
276
|
+
if (Number.isSafeInteger(timestamp) || !Number.isSafeInteger(timestamp * 1e3)) {
|
|
277
|
+
coercion = new Date(timestamp * 1e3);
|
|
278
|
+
} else {
|
|
279
|
+
return pushError(state, `Received a timestamp that can't be safely represented by the runtime (${value})`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (typeof coercion !== `undefined`) {
|
|
284
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, coercion)]);
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return pushError(state, `Expected a date (got ${getPrintable(value)})`);
|
|
289
|
+
}
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function isArray(spec, { delimiter } = {}) {
|
|
295
|
+
return makeValidator({
|
|
296
|
+
test: (value, state) => {
|
|
297
|
+
var _a;
|
|
298
|
+
const originalValue = value;
|
|
299
|
+
if (typeof value === `string` && typeof delimiter !== `undefined`) {
|
|
300
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
301
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
302
|
+
return pushError(state, `Unbound coercion result`);
|
|
303
|
+
value = value.split(delimiter);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (!Array.isArray(value))
|
|
307
|
+
return pushError(state, `Expected an array (got ${getPrintable(value)})`);
|
|
308
|
+
let valid = true;
|
|
309
|
+
for (let t = 0, T = value.length; t < T; ++t) {
|
|
310
|
+
valid = spec(value[t], Object.assign(Object.assign({}, state), { p: computeKey(state, t), coercion: makeCoercionFn(value, t) })) && valid;
|
|
311
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (value !== originalValue)
|
|
316
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
|
|
317
|
+
return valid;
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function isSet(spec, { delimiter } = {}) {
|
|
322
|
+
const isArrayValidator = isArray(spec, { delimiter });
|
|
323
|
+
return makeValidator({
|
|
324
|
+
test: (value, state) => {
|
|
325
|
+
var _a, _b;
|
|
326
|
+
if (Object.getPrototypeOf(value).toString() === `[object Set]`) {
|
|
327
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
328
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
329
|
+
return pushError(state, `Unbound coercion result`);
|
|
330
|
+
const originalValues = [...value];
|
|
331
|
+
const coercedValues = [...value];
|
|
332
|
+
if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
333
|
+
return false;
|
|
334
|
+
const updateValue = () => coercedValues.some((val, t) => val !== originalValues[t]) ? new Set(coercedValues) : value;
|
|
335
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
|
|
336
|
+
return true;
|
|
337
|
+
} else {
|
|
338
|
+
let valid = true;
|
|
339
|
+
for (const subValue of value) {
|
|
340
|
+
valid = spec(subValue, Object.assign({}, state)) && valid;
|
|
341
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return valid;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
349
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
350
|
+
return pushError(state, `Unbound coercion result`);
|
|
351
|
+
const store = { value };
|
|
352
|
+
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) })))
|
|
353
|
+
return false;
|
|
354
|
+
state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Set(store.value))]);
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
return pushError(state, `Expected a set (got ${getPrintable(value)})`);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
function isMap(keySpec, valueSpec) {
|
|
362
|
+
const isArrayValidator = isArray(isTuple([keySpec, valueSpec]));
|
|
363
|
+
const isRecordValidator = isRecord(valueSpec, { keys: keySpec });
|
|
364
|
+
return makeValidator({
|
|
365
|
+
test: (value, state) => {
|
|
366
|
+
var _a, _b, _c;
|
|
367
|
+
if (Object.getPrototypeOf(value).toString() === `[object Map]`) {
|
|
368
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
369
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
370
|
+
return pushError(state, `Unbound coercion result`);
|
|
371
|
+
const originalValues = [...value];
|
|
372
|
+
const coercedValues = [...value];
|
|
373
|
+
if (!isArrayValidator(coercedValues, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
374
|
+
return false;
|
|
375
|
+
const updateValue = () => coercedValues.some((val, t) => val[0] !== originalValues[t][0] || val[1] !== originalValues[t][1]) ? new Map(coercedValues) : value;
|
|
376
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, makeLazyCoercionFn(state.coercion, value, updateValue)]);
|
|
377
|
+
return true;
|
|
378
|
+
} else {
|
|
379
|
+
let valid = true;
|
|
380
|
+
for (const [key, subValue] of value) {
|
|
381
|
+
valid = keySpec(key, Object.assign({}, state)) && valid;
|
|
382
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
valid = valueSpec(subValue, Object.assign(Object.assign({}, state), { p: computeKey(state, key) })) && valid;
|
|
386
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return valid;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
394
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
395
|
+
return pushError(state, `Unbound coercion result`);
|
|
396
|
+
const store = { value };
|
|
397
|
+
if (Array.isArray(value)) {
|
|
398
|
+
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
399
|
+
return false;
|
|
400
|
+
state.coercions.push([(_b = state.p) !== null && _b !== void 0 ? _b : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(store.value))]);
|
|
401
|
+
return true;
|
|
402
|
+
} else {
|
|
403
|
+
if (!isRecordValidator(value, Object.assign(Object.assign({}, state), { coercion: makeCoercionFn(store, `value`) })))
|
|
404
|
+
return false;
|
|
405
|
+
state.coercions.push([(_c = state.p) !== null && _c !== void 0 ? _c : `.`, makeLazyCoercionFn(state.coercion, value, () => new Map(Object.entries(store.value)))]);
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return pushError(state, `Expected a map (got ${getPrintable(value)})`);
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function isTuple(spec, { delimiter } = {}) {
|
|
414
|
+
const lengthValidator = hasExactLength(spec.length);
|
|
415
|
+
return makeValidator({
|
|
416
|
+
test: (value, state) => {
|
|
417
|
+
var _a;
|
|
418
|
+
if (typeof value === `string` && typeof delimiter !== `undefined`) {
|
|
419
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
420
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
421
|
+
return pushError(state, `Unbound coercion result`);
|
|
422
|
+
value = value.split(delimiter);
|
|
423
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (!Array.isArray(value))
|
|
427
|
+
return pushError(state, `Expected a tuple (got ${getPrintable(value)})`);
|
|
428
|
+
let valid = lengthValidator(value, Object.assign({}, state));
|
|
429
|
+
for (let t = 0, T = value.length; t < T && t < spec.length; ++t) {
|
|
430
|
+
valid = spec[t](value[t], Object.assign(Object.assign({}, state), { p: computeKey(state, t), coercion: makeCoercionFn(value, t) })) && valid;
|
|
431
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return valid;
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
function isRecord(spec, { keys: keySpec = null } = {}) {
|
|
440
|
+
const isArrayValidator = isArray(isTuple([keySpec !== null && keySpec !== void 0 ? keySpec : isString(), spec]));
|
|
441
|
+
return makeValidator({
|
|
442
|
+
test: (value, state) => {
|
|
443
|
+
var _a;
|
|
444
|
+
if (Array.isArray(value)) {
|
|
445
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
446
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
447
|
+
return pushError(state, `Unbound coercion result`);
|
|
448
|
+
if (!isArrayValidator(value, Object.assign(Object.assign({}, state), { coercion: void 0 })))
|
|
449
|
+
return false;
|
|
450
|
+
value = Object.fromEntries(value);
|
|
451
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, value)]);
|
|
452
|
+
return true;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (typeof value !== `object` || value === null)
|
|
456
|
+
return pushError(state, `Expected an object (got ${getPrintable(value)})`);
|
|
457
|
+
const keys = Object.keys(value);
|
|
458
|
+
let valid = true;
|
|
459
|
+
for (let t = 0, T = keys.length; t < T && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null); ++t) {
|
|
460
|
+
const key = keys[t];
|
|
461
|
+
const sub = value[key];
|
|
462
|
+
if (key === `__proto__` || key === `constructor`) {
|
|
463
|
+
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
if (keySpec !== null && !keySpec(key, state)) {
|
|
467
|
+
valid = false;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if (!spec(sub, Object.assign(Object.assign({}, state), { p: computeKey(state, key), coercion: makeCoercionFn(value, key) }))) {
|
|
471
|
+
valid = false;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return valid;
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
function isDict(spec, opts = {}) {
|
|
480
|
+
return isRecord(spec, opts);
|
|
481
|
+
}
|
|
482
|
+
function isObject(props, { extra: extraSpec = null } = {}) {
|
|
483
|
+
const specKeys = Object.keys(props);
|
|
484
|
+
const validator = makeValidator({
|
|
485
|
+
test: (value, state) => {
|
|
486
|
+
if (typeof value !== `object` || value === null)
|
|
487
|
+
return pushError(state, `Expected an object (got ${getPrintable(value)})`);
|
|
488
|
+
const keys = /* @__PURE__ */ new Set([...specKeys, ...Object.keys(value)]);
|
|
489
|
+
const extra = {};
|
|
490
|
+
let valid = true;
|
|
491
|
+
for (const key of keys) {
|
|
492
|
+
if (key === `constructor` || key === `__proto__`) {
|
|
493
|
+
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Unsafe property name`);
|
|
494
|
+
} else {
|
|
495
|
+
const spec = Object.prototype.hasOwnProperty.call(props, key) ? props[key] : void 0;
|
|
496
|
+
const sub = Object.prototype.hasOwnProperty.call(value, key) ? value[key] : void 0;
|
|
497
|
+
if (typeof spec !== `undefined`) {
|
|
498
|
+
valid = spec(sub, Object.assign(Object.assign({}, state), { p: computeKey(state, key), coercion: makeCoercionFn(value, key) })) && valid;
|
|
499
|
+
} else if (extraSpec === null) {
|
|
500
|
+
valid = pushError(Object.assign(Object.assign({}, state), { p: computeKey(state, key) }), `Extraneous property (got ${getPrintable(sub)})`);
|
|
501
|
+
} else {
|
|
502
|
+
Object.defineProperty(extra, key, {
|
|
503
|
+
enumerable: true,
|
|
504
|
+
get: () => sub,
|
|
505
|
+
set: makeSetter(value, key)
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (!valid && (state === null || state === void 0 ? void 0 : state.errors) == null) {
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (extraSpec !== null && (valid || (state === null || state === void 0 ? void 0 : state.errors) != null))
|
|
514
|
+
valid = extraSpec(extra, state) && valid;
|
|
515
|
+
return valid;
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
return Object.assign(validator, {
|
|
519
|
+
properties: props
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
function isPartial(props) {
|
|
523
|
+
return isObject(props, { extra: isRecord(isUnknown()) });
|
|
524
|
+
}
|
|
525
|
+
var isInstanceOf = (constructor) => makeValidator({
|
|
526
|
+
test: (value, state) => {
|
|
527
|
+
if (!(value instanceof constructor))
|
|
528
|
+
return pushError(state, `Expected an instance of ${constructor.name} (got ${getPrintable(value)})`);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
var isOneOf = (specs, { exclusive = false } = {}) => makeValidator({
|
|
533
|
+
test: (value, state) => {
|
|
534
|
+
var _a, _b, _c;
|
|
535
|
+
const matches = [];
|
|
536
|
+
const errorBuffer = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
|
|
537
|
+
for (let t = 0, T = specs.length; t < T; ++t) {
|
|
538
|
+
const subErrors = typeof (state === null || state === void 0 ? void 0 : state.errors) !== `undefined` ? [] : void 0;
|
|
539
|
+
const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
|
|
540
|
+
if (specs[t](value, Object.assign(Object.assign({}, state), { errors: subErrors, coercions: subCoercions, p: `${(_a = state === null || state === void 0 ? void 0 : state.p) !== null && _a !== void 0 ? _a : `.`}#${t + 1}` }))) {
|
|
541
|
+
matches.push([`#${t + 1}`, subCoercions]);
|
|
542
|
+
if (!exclusive) {
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
errorBuffer === null || errorBuffer === void 0 ? void 0 : errorBuffer.push(subErrors[0]);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (matches.length === 1) {
|
|
550
|
+
const [, subCoercions] = matches[0];
|
|
551
|
+
if (typeof subCoercions !== `undefined`)
|
|
552
|
+
(_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 ? void 0 : _b.push(...subCoercions);
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
if (matches.length > 1)
|
|
556
|
+
pushError(state, `Expected to match exactly a single predicate (matched ${matches.join(`, `)})`);
|
|
557
|
+
else
|
|
558
|
+
(_c = state === null || state === void 0 ? void 0 : state.errors) === null || _c === void 0 ? void 0 : _c.push(...errorBuffer);
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
function makeTrait(value) {
|
|
563
|
+
return () => {
|
|
564
|
+
return value;
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function makeValidator({ test }) {
|
|
568
|
+
return makeTrait(test)();
|
|
569
|
+
}
|
|
570
|
+
var TypeAssertionError = class extends Error {
|
|
571
|
+
constructor({ errors } = {}) {
|
|
572
|
+
let errorMessage = `Type mismatch`;
|
|
573
|
+
if (errors && errors.length > 0) {
|
|
574
|
+
errorMessage += `
|
|
575
|
+
`;
|
|
576
|
+
for (const error of errors) {
|
|
577
|
+
errorMessage += `
|
|
578
|
+
- ${error}`;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
super(errorMessage);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
function assert(val, validator) {
|
|
585
|
+
if (!validator(val)) {
|
|
586
|
+
throw new TypeAssertionError();
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function assertWithErrors(val, validator) {
|
|
590
|
+
const errors = [];
|
|
591
|
+
if (!validator(val, { errors })) {
|
|
592
|
+
throw new TypeAssertionError({ errors });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
function softAssert(val, validator) {
|
|
596
|
+
}
|
|
597
|
+
function as(value, validator, { coerce = false, errors: storeErrors, throw: throws } = {}) {
|
|
598
|
+
const errors = storeErrors ? [] : void 0;
|
|
599
|
+
if (!coerce) {
|
|
600
|
+
if (validator(value, { errors })) {
|
|
601
|
+
return throws ? value : { value, errors: void 0 };
|
|
602
|
+
} else if (!throws) {
|
|
603
|
+
return { value: void 0, errors: errors !== null && errors !== void 0 ? errors : true };
|
|
604
|
+
} else {
|
|
605
|
+
throw new TypeAssertionError({ errors });
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const state = { value };
|
|
609
|
+
const coercion = makeCoercionFn(state, `value`);
|
|
610
|
+
const coercions = [];
|
|
611
|
+
if (!validator(value, { errors, coercion, coercions })) {
|
|
612
|
+
if (!throws) {
|
|
613
|
+
return { value: void 0, errors: errors !== null && errors !== void 0 ? errors : true };
|
|
614
|
+
} else {
|
|
615
|
+
throw new TypeAssertionError({ errors });
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
for (const [, apply] of coercions)
|
|
619
|
+
apply();
|
|
620
|
+
if (throws) {
|
|
621
|
+
return state.value;
|
|
622
|
+
} else {
|
|
623
|
+
return { value: state.value, errors: void 0 };
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function fn(validators, fn2) {
|
|
627
|
+
const isValidArgList = isTuple(validators);
|
|
628
|
+
return (...args) => {
|
|
629
|
+
const check = isValidArgList(args);
|
|
630
|
+
if (!check)
|
|
631
|
+
throw new TypeAssertionError();
|
|
632
|
+
return fn2(...args);
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
function hasMinLength(length) {
|
|
636
|
+
return makeValidator({
|
|
637
|
+
test: (value, state) => {
|
|
638
|
+
if (!(value.length >= length))
|
|
639
|
+
return pushError(state, `Expected to have a length of at least ${length} elements (got ${value.length})`);
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
function hasMaxLength(length) {
|
|
645
|
+
return makeValidator({
|
|
646
|
+
test: (value, state) => {
|
|
647
|
+
if (!(value.length <= length))
|
|
648
|
+
return pushError(state, `Expected to have a length of at most ${length} elements (got ${value.length})`);
|
|
649
|
+
return true;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
function hasExactLength(length) {
|
|
654
|
+
return makeValidator({
|
|
655
|
+
test: (value, state) => {
|
|
656
|
+
if (!(value.length === length))
|
|
657
|
+
return pushError(state, `Expected to have a length of exactly ${length} elements (got ${value.length})`);
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
function hasUniqueItems({ map } = {}) {
|
|
663
|
+
return makeValidator({
|
|
664
|
+
test: (value, state) => {
|
|
665
|
+
const set = /* @__PURE__ */ new Set();
|
|
666
|
+
const dup = /* @__PURE__ */ new Set();
|
|
667
|
+
for (let t = 0, T = value.length; t < T; ++t) {
|
|
668
|
+
const sub = value[t];
|
|
669
|
+
const key = typeof map !== `undefined` ? map(sub) : sub;
|
|
670
|
+
if (set.has(key)) {
|
|
671
|
+
if (dup.has(key))
|
|
672
|
+
continue;
|
|
673
|
+
pushError(state, `Expected to contain unique elements; got a duplicate with ${getPrintable(value)}`);
|
|
674
|
+
dup.add(key);
|
|
675
|
+
} else {
|
|
676
|
+
set.add(key);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
return dup.size === 0;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
function isNegative() {
|
|
684
|
+
return makeValidator({
|
|
685
|
+
test: (value, state) => {
|
|
686
|
+
if (!(value <= 0))
|
|
687
|
+
return pushError(state, `Expected to be negative (got ${value})`);
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
function isPositive() {
|
|
693
|
+
return makeValidator({
|
|
694
|
+
test: (value, state) => {
|
|
695
|
+
if (!(value >= 0))
|
|
696
|
+
return pushError(state, `Expected to be positive (got ${value})`);
|
|
697
|
+
return true;
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
function isAtLeast(n) {
|
|
702
|
+
return makeValidator({
|
|
703
|
+
test: (value, state) => {
|
|
704
|
+
if (!(value >= n))
|
|
705
|
+
return pushError(state, `Expected to be at least ${n} (got ${value})`);
|
|
706
|
+
return true;
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
function isAtMost(n) {
|
|
711
|
+
return makeValidator({
|
|
712
|
+
test: (value, state) => {
|
|
713
|
+
if (!(value <= n))
|
|
714
|
+
return pushError(state, `Expected to be at most ${n} (got ${value})`);
|
|
715
|
+
return true;
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
function isInInclusiveRange(a, b) {
|
|
720
|
+
return makeValidator({
|
|
721
|
+
test: (value, state) => {
|
|
722
|
+
if (!(value >= a && value <= b))
|
|
723
|
+
return pushError(state, `Expected to be in the [${a}; ${b}] range (got ${value})`);
|
|
724
|
+
return true;
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
function isInExclusiveRange(a, b) {
|
|
729
|
+
return makeValidator({
|
|
730
|
+
test: (value, state) => {
|
|
731
|
+
if (!(value >= a && value < b))
|
|
732
|
+
return pushError(state, `Expected to be in the [${a}; ${b}[ range (got ${value})`);
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function isInteger({ unsafe = false } = {}) {
|
|
738
|
+
return makeValidator({
|
|
739
|
+
test: (value, state) => {
|
|
740
|
+
if (value !== Math.round(value))
|
|
741
|
+
return pushError(state, `Expected to be an integer (got ${value})`);
|
|
742
|
+
if (!unsafe && !Number.isSafeInteger(value))
|
|
743
|
+
return pushError(state, `Expected to be a safe integer (got ${value})`);
|
|
744
|
+
return true;
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
function matchesRegExp(regExp) {
|
|
749
|
+
return makeValidator({
|
|
750
|
+
test: (value, state) => {
|
|
751
|
+
if (!regExp.test(value))
|
|
752
|
+
return pushError(state, `Expected to match the pattern ${regExp.toString()} (got ${getPrintable(value)})`);
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
function isLowerCase() {
|
|
758
|
+
return makeValidator({
|
|
759
|
+
test: (value, state) => {
|
|
760
|
+
if (value !== value.toLowerCase())
|
|
761
|
+
return pushError(state, `Expected to be all-lowercase (got ${value})`);
|
|
762
|
+
return true;
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
function isUpperCase() {
|
|
767
|
+
return makeValidator({
|
|
768
|
+
test: (value, state) => {
|
|
769
|
+
if (value !== value.toUpperCase())
|
|
770
|
+
return pushError(state, `Expected to be all-uppercase (got ${value})`);
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
function isUUID4() {
|
|
776
|
+
return makeValidator({
|
|
777
|
+
test: (value, state) => {
|
|
778
|
+
if (!uuid4RegExp.test(value))
|
|
779
|
+
return pushError(state, `Expected to be a valid UUID v4 (got ${getPrintable(value)})`);
|
|
780
|
+
return true;
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
function isISO8601() {
|
|
785
|
+
return makeValidator({
|
|
786
|
+
test: (value, state) => {
|
|
787
|
+
if (!iso8601RegExp.test(value))
|
|
788
|
+
return pushError(state, `Expected to be a valid ISO 8601 date string (got ${getPrintable(value)})`);
|
|
789
|
+
return true;
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
function isHexColor({ alpha = false }) {
|
|
794
|
+
return makeValidator({
|
|
795
|
+
test: (value, state) => {
|
|
796
|
+
const res = alpha ? colorStringRegExp.test(value) : colorStringAlphaRegExp.test(value);
|
|
797
|
+
if (!res)
|
|
798
|
+
return pushError(state, `Expected to be a valid hexadecimal color string (got ${getPrintable(value)})`);
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
function isBase64() {
|
|
804
|
+
return makeValidator({
|
|
805
|
+
test: (value, state) => {
|
|
806
|
+
if (!base64RegExp.test(value))
|
|
807
|
+
return pushError(state, `Expected to be a valid base 64 string (got ${getPrintable(value)})`);
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
function isJSON(spec = isUnknown()) {
|
|
813
|
+
return makeValidator({
|
|
814
|
+
test: (value, state) => {
|
|
815
|
+
let data;
|
|
816
|
+
try {
|
|
817
|
+
data = JSON.parse(value);
|
|
818
|
+
} catch (_a) {
|
|
819
|
+
return pushError(state, `Expected to be a valid JSON string (got ${getPrintable(value)})`);
|
|
820
|
+
}
|
|
821
|
+
return spec(data, state);
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
function cascade(spec, ...followups) {
|
|
826
|
+
const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
|
|
827
|
+
return makeValidator({
|
|
828
|
+
test: (value, state) => {
|
|
829
|
+
var _a, _b;
|
|
830
|
+
const context = { value };
|
|
831
|
+
const subCoercion = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? makeCoercionFn(context, `value`) : void 0;
|
|
832
|
+
const subCoercions = typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined` ? [] : void 0;
|
|
833
|
+
if (!spec(value, Object.assign(Object.assign({}, state), { coercion: subCoercion, coercions: subCoercions })))
|
|
834
|
+
return false;
|
|
835
|
+
const reverts = [];
|
|
836
|
+
if (typeof subCoercions !== `undefined`)
|
|
837
|
+
for (const [, coercion] of subCoercions)
|
|
838
|
+
reverts.push(coercion());
|
|
839
|
+
try {
|
|
840
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercions) !== `undefined`) {
|
|
841
|
+
if (context.value !== value) {
|
|
842
|
+
if (typeof (state === null || state === void 0 ? void 0 : state.coercion) === `undefined`)
|
|
843
|
+
return pushError(state, `Unbound coercion result`);
|
|
844
|
+
state.coercions.push([(_a = state.p) !== null && _a !== void 0 ? _a : `.`, state.coercion.bind(null, context.value)]);
|
|
845
|
+
}
|
|
846
|
+
(_b = state === null || state === void 0 ? void 0 : state.coercions) === null || _b === void 0 ? void 0 : _b.push(...subCoercions);
|
|
847
|
+
}
|
|
848
|
+
return resolvedFollowups.every((spec2) => {
|
|
849
|
+
return spec2(context.value, state);
|
|
850
|
+
});
|
|
851
|
+
} finally {
|
|
852
|
+
for (const revert of reverts) {
|
|
853
|
+
revert();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
function applyCascade(spec, ...followups) {
|
|
860
|
+
const resolvedFollowups = Array.isArray(followups[0]) ? followups[0] : followups;
|
|
861
|
+
return cascade(spec, resolvedFollowups);
|
|
862
|
+
}
|
|
863
|
+
function isOptional(spec) {
|
|
864
|
+
return makeValidator({
|
|
865
|
+
test: (value, state) => {
|
|
866
|
+
if (typeof value === `undefined`)
|
|
867
|
+
return true;
|
|
868
|
+
return spec(value, state);
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
function isNullable(spec) {
|
|
873
|
+
return makeValidator({
|
|
874
|
+
test: (value, state) => {
|
|
875
|
+
if (value === null)
|
|
876
|
+
return true;
|
|
877
|
+
return spec(value, state);
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
var checks = {
|
|
882
|
+
missing: (keys, key) => keys.has(key),
|
|
883
|
+
undefined: (keys, key, value) => keys.has(key) && typeof value[key] !== `undefined`,
|
|
884
|
+
nil: (keys, key, value) => keys.has(key) && value[key] != null,
|
|
885
|
+
falsy: (keys, key, value) => keys.has(key) && !!value[key]
|
|
886
|
+
};
|
|
887
|
+
function hasRequiredKeys(requiredKeys, options) {
|
|
888
|
+
var _a;
|
|
889
|
+
const requiredSet = new Set(requiredKeys);
|
|
890
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
891
|
+
return makeValidator({
|
|
892
|
+
test: (value, state) => {
|
|
893
|
+
const keys = new Set(Object.keys(value));
|
|
894
|
+
const problems = [];
|
|
895
|
+
for (const key of requiredSet)
|
|
896
|
+
if (!check(keys, key, value))
|
|
897
|
+
problems.push(key);
|
|
898
|
+
if (problems.length > 0)
|
|
899
|
+
return pushError(state, `Missing required ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
|
|
900
|
+
return true;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
function hasAtLeastOneKey(requiredKeys, options) {
|
|
905
|
+
var _a;
|
|
906
|
+
const requiredSet = new Set(requiredKeys);
|
|
907
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
908
|
+
return makeValidator({
|
|
909
|
+
test: (value, state) => {
|
|
910
|
+
const keys = Object.keys(value);
|
|
911
|
+
const valid = keys.some((key) => check(requiredSet, key, value));
|
|
912
|
+
if (!valid)
|
|
913
|
+
return pushError(state, `Missing at least one property from ${getPrintableArray(Array.from(requiredSet), `or`)}`);
|
|
914
|
+
return true;
|
|
915
|
+
}
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
function hasForbiddenKeys(forbiddenKeys, options) {
|
|
919
|
+
var _a;
|
|
920
|
+
const forbiddenSet = new Set(forbiddenKeys);
|
|
921
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
922
|
+
return makeValidator({
|
|
923
|
+
test: (value, state) => {
|
|
924
|
+
const keys = new Set(Object.keys(value));
|
|
925
|
+
const problems = [];
|
|
926
|
+
for (const key of forbiddenSet)
|
|
927
|
+
if (check(keys, key, value))
|
|
928
|
+
problems.push(key);
|
|
929
|
+
if (problems.length > 0)
|
|
930
|
+
return pushError(state, `Forbidden ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, `and`)}`);
|
|
931
|
+
return true;
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
function hasMutuallyExclusiveKeys(exclusiveKeys, options) {
|
|
936
|
+
var _a;
|
|
937
|
+
const exclusiveSet = new Set(exclusiveKeys);
|
|
938
|
+
const check = checks[(_a = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _a !== void 0 ? _a : "missing"];
|
|
939
|
+
return makeValidator({
|
|
940
|
+
test: (value, state) => {
|
|
941
|
+
const keys = new Set(Object.keys(value));
|
|
942
|
+
const used = [];
|
|
943
|
+
for (const key of exclusiveSet)
|
|
944
|
+
if (check(keys, key, value))
|
|
945
|
+
used.push(key);
|
|
946
|
+
if (used.length > 1)
|
|
947
|
+
return pushError(state, `Mutually exclusive properties ${getPrintableArray(used, `and`)}`);
|
|
948
|
+
return true;
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
(function(KeyRelationship) {
|
|
953
|
+
KeyRelationship["Forbids"] = "Forbids";
|
|
954
|
+
KeyRelationship["Requires"] = "Requires";
|
|
955
|
+
})(exports2.KeyRelationship || (exports2.KeyRelationship = {}));
|
|
956
|
+
var keyRelationships = {
|
|
957
|
+
[exports2.KeyRelationship.Forbids]: {
|
|
958
|
+
expect: false,
|
|
959
|
+
message: `forbids using`
|
|
960
|
+
},
|
|
961
|
+
[exports2.KeyRelationship.Requires]: {
|
|
962
|
+
expect: true,
|
|
963
|
+
message: `requires using`
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
function hasKeyRelationship(subject, relationship, others, options) {
|
|
967
|
+
var _a, _b;
|
|
968
|
+
const skipped = new Set((_a = options === null || options === void 0 ? void 0 : options.ignore) !== null && _a !== void 0 ? _a : []);
|
|
969
|
+
const check = checks[(_b = options === null || options === void 0 ? void 0 : options.missingIf) !== null && _b !== void 0 ? _b : "missing"];
|
|
970
|
+
const otherSet = new Set(others);
|
|
971
|
+
const spec = keyRelationships[relationship];
|
|
972
|
+
const conjunction = relationship === exports2.KeyRelationship.Forbids ? `or` : `and`;
|
|
973
|
+
return makeValidator({
|
|
974
|
+
test: (value, state) => {
|
|
975
|
+
const keys = new Set(Object.keys(value));
|
|
976
|
+
if (!check(keys, subject, value) || skipped.has(value[subject]))
|
|
977
|
+
return true;
|
|
978
|
+
const problems = [];
|
|
979
|
+
for (const key of otherSet)
|
|
980
|
+
if ((check(keys, key, value) && !skipped.has(value[key])) !== spec.expect)
|
|
981
|
+
problems.push(key);
|
|
982
|
+
if (problems.length >= 1)
|
|
983
|
+
return pushError(state, `Property "${subject}" ${spec.message} ${plural(problems.length, `property`, `properties`)} ${getPrintableArray(problems, conjunction)}`);
|
|
984
|
+
return true;
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
exports2.TypeAssertionError = TypeAssertionError;
|
|
989
|
+
exports2.applyCascade = applyCascade;
|
|
990
|
+
exports2.as = as;
|
|
991
|
+
exports2.assert = assert;
|
|
992
|
+
exports2.assertWithErrors = assertWithErrors;
|
|
993
|
+
exports2.cascade = cascade;
|
|
994
|
+
exports2.fn = fn;
|
|
995
|
+
exports2.hasAtLeastOneKey = hasAtLeastOneKey;
|
|
996
|
+
exports2.hasExactLength = hasExactLength;
|
|
997
|
+
exports2.hasForbiddenKeys = hasForbiddenKeys;
|
|
998
|
+
exports2.hasKeyRelationship = hasKeyRelationship;
|
|
999
|
+
exports2.hasMaxLength = hasMaxLength;
|
|
1000
|
+
exports2.hasMinLength = hasMinLength;
|
|
1001
|
+
exports2.hasMutuallyExclusiveKeys = hasMutuallyExclusiveKeys;
|
|
1002
|
+
exports2.hasRequiredKeys = hasRequiredKeys;
|
|
1003
|
+
exports2.hasUniqueItems = hasUniqueItems;
|
|
1004
|
+
exports2.isArray = isArray;
|
|
1005
|
+
exports2.isAtLeast = isAtLeast;
|
|
1006
|
+
exports2.isAtMost = isAtMost;
|
|
1007
|
+
exports2.isBase64 = isBase64;
|
|
1008
|
+
exports2.isBoolean = isBoolean;
|
|
1009
|
+
exports2.isDate = isDate;
|
|
1010
|
+
exports2.isDict = isDict;
|
|
1011
|
+
exports2.isEnum = isEnum;
|
|
1012
|
+
exports2.isHexColor = isHexColor;
|
|
1013
|
+
exports2.isISO8601 = isISO8601;
|
|
1014
|
+
exports2.isInExclusiveRange = isInExclusiveRange;
|
|
1015
|
+
exports2.isInInclusiveRange = isInInclusiveRange;
|
|
1016
|
+
exports2.isInstanceOf = isInstanceOf;
|
|
1017
|
+
exports2.isInteger = isInteger;
|
|
1018
|
+
exports2.isJSON = isJSON;
|
|
1019
|
+
exports2.isLiteral = isLiteral;
|
|
1020
|
+
exports2.isLowerCase = isLowerCase;
|
|
1021
|
+
exports2.isMap = isMap;
|
|
1022
|
+
exports2.isNegative = isNegative;
|
|
1023
|
+
exports2.isNullable = isNullable;
|
|
1024
|
+
exports2.isNumber = isNumber;
|
|
1025
|
+
exports2.isObject = isObject;
|
|
1026
|
+
exports2.isOneOf = isOneOf;
|
|
1027
|
+
exports2.isOptional = isOptional;
|
|
1028
|
+
exports2.isPartial = isPartial;
|
|
1029
|
+
exports2.isPayload = isPayload;
|
|
1030
|
+
exports2.isPositive = isPositive;
|
|
1031
|
+
exports2.isRecord = isRecord;
|
|
1032
|
+
exports2.isSet = isSet;
|
|
1033
|
+
exports2.isString = isString;
|
|
1034
|
+
exports2.isTuple = isTuple;
|
|
1035
|
+
exports2.isUUID4 = isUUID4;
|
|
1036
|
+
exports2.isUnknown = isUnknown;
|
|
1037
|
+
exports2.isUpperCase = isUpperCase;
|
|
1038
|
+
exports2.makeTrait = makeTrait;
|
|
1039
|
+
exports2.makeValidator = makeValidator;
|
|
1040
|
+
exports2.matchesRegExp = matchesRegExp;
|
|
1041
|
+
exports2.softAssert = softAssert;
|
|
1042
|
+
}
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
// src/cli.ts
|
|
1046
|
+
var cli_exports = {};
|
|
1047
|
+
__export(cli_exports, {
|
|
1048
|
+
initialize: () => initialize
|
|
1049
|
+
});
|
|
1050
|
+
module.exports = __toCommonJS(cli_exports);
|
|
1051
|
+
init_cjs_shims();
|
|
1052
|
+
|
|
1053
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/index.mjs
|
|
1054
|
+
init_cjs_shims();
|
|
1055
|
+
|
|
1056
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/Command.mjs
|
|
1057
|
+
init_cjs_shims();
|
|
1058
|
+
|
|
1059
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/options/utils.mjs
|
|
1060
|
+
init_cjs_shims();
|
|
1061
|
+
|
|
1062
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/errors.mjs
|
|
1063
|
+
init_cjs_shims();
|
|
1064
|
+
|
|
1065
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/constants.mjs
|
|
1066
|
+
init_cjs_shims();
|
|
1067
|
+
var SpecialToken;
|
|
1068
|
+
(function(SpecialToken2) {
|
|
1069
|
+
SpecialToken2["StartOfInput"] = "\0";
|
|
1070
|
+
SpecialToken2["EndOfInput"] = "";
|
|
1071
|
+
SpecialToken2["EndOfPartialInput"] = "";
|
|
1072
|
+
})(SpecialToken || (SpecialToken = {}));
|
|
1073
|
+
var NodeType;
|
|
1074
|
+
(function(NodeType2) {
|
|
1075
|
+
NodeType2[NodeType2["InitialNode"] = 0] = "InitialNode";
|
|
1076
|
+
NodeType2[NodeType2["SuccessNode"] = 1] = "SuccessNode";
|
|
1077
|
+
NodeType2[NodeType2["ErrorNode"] = 2] = "ErrorNode";
|
|
1078
|
+
NodeType2[NodeType2["CustomNode"] = 3] = "CustomNode";
|
|
1079
|
+
})(NodeType || (NodeType = {}));
|
|
1080
|
+
var HELP_COMMAND_INDEX = -1;
|
|
1081
|
+
var HELP_REGEX = /^(-h|--help)(?:=([0-9]+))?$/;
|
|
1082
|
+
var OPTION_REGEX = /^(--[a-z]+(?:-[a-z]+)*|-[a-zA-Z]+)$/;
|
|
1083
|
+
var BATCH_REGEX = /^-[a-zA-Z]{2,}$/;
|
|
1084
|
+
var BINDING_REGEX = /^([^=]+)=([\s\S]*)$/;
|
|
1085
|
+
var IS_DEBUG = process.env.DEBUG_CLI === `1`;
|
|
1086
|
+
|
|
1087
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/errors.mjs
|
|
1088
|
+
var UsageError = class extends Error {
|
|
1089
|
+
constructor(message) {
|
|
1090
|
+
super(message);
|
|
1091
|
+
this.clipanion = { type: `usage` };
|
|
1092
|
+
this.name = `UsageError`;
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
var UnknownSyntaxError = class extends Error {
|
|
1096
|
+
constructor(input, candidates) {
|
|
1097
|
+
super();
|
|
1098
|
+
this.input = input;
|
|
1099
|
+
this.candidates = candidates;
|
|
1100
|
+
this.clipanion = { type: `none` };
|
|
1101
|
+
this.name = `UnknownSyntaxError`;
|
|
1102
|
+
if (this.candidates.length === 0) {
|
|
1103
|
+
this.message = `Command not found, but we're not sure what's the alternative.`;
|
|
1104
|
+
} else if (this.candidates.every((candidate) => candidate.reason !== null && candidate.reason === candidates[0].reason)) {
|
|
1105
|
+
const [{ reason }] = this.candidates;
|
|
1106
|
+
this.message = `${reason}
|
|
1107
|
+
|
|
1108
|
+
${this.candidates.map(({ usage }) => `$ ${usage}`).join(`
|
|
1109
|
+
`)}`;
|
|
1110
|
+
} else if (this.candidates.length === 1) {
|
|
1111
|
+
const [{ usage }] = this.candidates;
|
|
1112
|
+
this.message = `Command not found; did you mean:
|
|
1113
|
+
|
|
1114
|
+
$ ${usage}
|
|
1115
|
+
${whileRunning(input)}`;
|
|
1116
|
+
} else {
|
|
1117
|
+
this.message = `Command not found; did you mean one of:
|
|
1118
|
+
|
|
1119
|
+
${this.candidates.map(({ usage }, index) => {
|
|
1120
|
+
return `${`${index}.`.padStart(4)} ${usage}`;
|
|
1121
|
+
}).join(`
|
|
1122
|
+
`)}
|
|
1123
|
+
|
|
1124
|
+
${whileRunning(input)}`;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
var AmbiguousSyntaxError = class extends Error {
|
|
1129
|
+
constructor(input, usages) {
|
|
1130
|
+
super();
|
|
1131
|
+
this.input = input;
|
|
1132
|
+
this.usages = usages;
|
|
1133
|
+
this.clipanion = { type: `none` };
|
|
1134
|
+
this.name = `AmbiguousSyntaxError`;
|
|
1135
|
+
this.message = `Cannot find which to pick amongst the following alternatives:
|
|
1136
|
+
|
|
1137
|
+
${this.usages.map((usage, index) => {
|
|
1138
|
+
return `${`${index}.`.padStart(4)} ${usage}`;
|
|
1139
|
+
}).join(`
|
|
1140
|
+
`)}
|
|
1141
|
+
|
|
1142
|
+
${whileRunning(input)}`;
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
var whileRunning = (input) => `While running ${input.filter((token) => {
|
|
1146
|
+
return token !== SpecialToken.EndOfInput && token !== SpecialToken.EndOfPartialInput;
|
|
1147
|
+
}).map((token) => {
|
|
1148
|
+
const json = JSON.stringify(token);
|
|
1149
|
+
if (token.match(/\s/) || token.length === 0 || json !== `"${token}"`) {
|
|
1150
|
+
return json;
|
|
1151
|
+
} else {
|
|
1152
|
+
return token;
|
|
1153
|
+
}
|
|
1154
|
+
}).join(` `)}`;
|
|
1155
|
+
|
|
1156
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/options/utils.mjs
|
|
1157
|
+
var isOptionSymbol = Symbol(`clipanion/isOption`);
|
|
1158
|
+
function cleanValidationError(message, { mergeName = false } = {}) {
|
|
1159
|
+
const match = message.match(/^([^:]+): (.*)$/m);
|
|
1160
|
+
if (!match)
|
|
1161
|
+
return `validation failed`;
|
|
1162
|
+
let [, path2, line] = match;
|
|
1163
|
+
if (mergeName)
|
|
1164
|
+
line = line[0].toLowerCase() + line.slice(1);
|
|
1165
|
+
line = path2 !== `.` || !mergeName ? `${path2.replace(/^\.(\[|$)/, `$1`)}: ${line}` : `: ${line}`;
|
|
1166
|
+
return line;
|
|
1167
|
+
}
|
|
1168
|
+
function formatError(message, errors) {
|
|
1169
|
+
if (errors.length === 1) {
|
|
1170
|
+
return new UsageError(`${message}${cleanValidationError(errors[0], { mergeName: true })}`);
|
|
1171
|
+
} else {
|
|
1172
|
+
return new UsageError(`${message}:
|
|
1173
|
+
${errors.map((error) => `
|
|
1174
|
+
- ${cleanValidationError(error)}`).join(``)}`);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/Command.mjs
|
|
1179
|
+
var Command = class {
|
|
1180
|
+
constructor() {
|
|
1181
|
+
this.help = false;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Defines the usage information for the given command.
|
|
1185
|
+
*/
|
|
1186
|
+
static Usage(usage) {
|
|
1187
|
+
return usage;
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Standard error handler which will simply rethrow the error. Can be used
|
|
1191
|
+
* to add custom logic to handle errors from the command or simply return
|
|
1192
|
+
* the parent class error handling.
|
|
1193
|
+
*/
|
|
1194
|
+
async catch(error) {
|
|
1195
|
+
throw error;
|
|
1196
|
+
}
|
|
1197
|
+
async validateAndExecute() {
|
|
1198
|
+
const commandClass = this.constructor;
|
|
1199
|
+
const cascade = commandClass.schema;
|
|
1200
|
+
if (Array.isArray(cascade)) {
|
|
1201
|
+
const { isDict, isUnknown, applyCascade } = await Promise.resolve().then(() => __toESM(require_lib(), 1));
|
|
1202
|
+
const schema = applyCascade(isDict(isUnknown()), cascade);
|
|
1203
|
+
const errors = [];
|
|
1204
|
+
const coercions = [];
|
|
1205
|
+
const check = schema(this, { errors, coercions });
|
|
1206
|
+
if (!check)
|
|
1207
|
+
throw formatError(`Invalid option schema`, errors);
|
|
1208
|
+
for (const [, op] of coercions) {
|
|
1209
|
+
op();
|
|
1210
|
+
}
|
|
1211
|
+
} else if (cascade != null) {
|
|
1212
|
+
throw new Error(`Invalid command schema`);
|
|
1213
|
+
}
|
|
1214
|
+
const exitCode = await this.execute();
|
|
1215
|
+
if (typeof exitCode !== `undefined`) {
|
|
1216
|
+
return exitCode;
|
|
1217
|
+
} else {
|
|
1218
|
+
return 0;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
Command.isOption = isOptionSymbol;
|
|
1223
|
+
Command.Default = [];
|
|
1224
|
+
|
|
1225
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/Cli.mjs
|
|
1226
|
+
init_cjs_shims();
|
|
1227
|
+
|
|
1228
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/platform/node.mjs
|
|
1229
|
+
init_cjs_shims();
|
|
1230
|
+
var import_tty = __toESM(require("tty"), 1);
|
|
1231
|
+
function getDefaultColorDepth() {
|
|
1232
|
+
if (import_tty.default && `getColorDepth` in import_tty.default.WriteStream.prototype)
|
|
1233
|
+
return import_tty.default.WriteStream.prototype.getColorDepth();
|
|
1234
|
+
if (process.env.FORCE_COLOR === `0`)
|
|
1235
|
+
return 1;
|
|
1236
|
+
if (process.env.FORCE_COLOR === `1`)
|
|
1237
|
+
return 8;
|
|
1238
|
+
if (typeof process.stdout !== `undefined` && process.stdout.isTTY)
|
|
1239
|
+
return 8;
|
|
1240
|
+
return 1;
|
|
1241
|
+
}
|
|
1242
|
+
var gContextStorage;
|
|
1243
|
+
function getCaptureActivator(context) {
|
|
1244
|
+
let contextStorage = gContextStorage;
|
|
1245
|
+
if (typeof contextStorage === `undefined`) {
|
|
1246
|
+
if (context.stdout === process.stdout && context.stderr === process.stderr)
|
|
1247
|
+
return null;
|
|
1248
|
+
const { AsyncLocalStorage: LazyAsyncLocalStorage } = require("async_hooks");
|
|
1249
|
+
contextStorage = gContextStorage = new LazyAsyncLocalStorage();
|
|
1250
|
+
const origStdoutWrite = process.stdout._write;
|
|
1251
|
+
process.stdout._write = function(chunk, encoding, cb) {
|
|
1252
|
+
const context2 = contextStorage.getStore();
|
|
1253
|
+
if (typeof context2 === `undefined`)
|
|
1254
|
+
return origStdoutWrite.call(this, chunk, encoding, cb);
|
|
1255
|
+
return context2.stdout.write(chunk, encoding, cb);
|
|
1256
|
+
};
|
|
1257
|
+
const origStderrWrite = process.stderr._write;
|
|
1258
|
+
process.stderr._write = function(chunk, encoding, cb) {
|
|
1259
|
+
const context2 = contextStorage.getStore();
|
|
1260
|
+
if (typeof context2 === `undefined`)
|
|
1261
|
+
return origStderrWrite.call(this, chunk, encoding, cb);
|
|
1262
|
+
return context2.stderr.write(chunk, encoding, cb);
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
return (fn) => {
|
|
1266
|
+
return contextStorage.run(context, fn);
|
|
1267
|
+
};
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/core.mjs
|
|
1271
|
+
init_cjs_shims();
|
|
1272
|
+
function debug(str) {
|
|
1273
|
+
if (IS_DEBUG) {
|
|
1274
|
+
console.log(str);
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
var basicHelpState = {
|
|
1278
|
+
candidateUsage: null,
|
|
1279
|
+
requiredOptions: [],
|
|
1280
|
+
errorMessage: null,
|
|
1281
|
+
ignoreOptions: false,
|
|
1282
|
+
path: [],
|
|
1283
|
+
positionals: [],
|
|
1284
|
+
options: [],
|
|
1285
|
+
remainder: null,
|
|
1286
|
+
selectedIndex: HELP_COMMAND_INDEX,
|
|
1287
|
+
tokens: []
|
|
1288
|
+
};
|
|
1289
|
+
function makeStateMachine() {
|
|
1290
|
+
const stateMachine = {
|
|
1291
|
+
nodes: []
|
|
1292
|
+
};
|
|
1293
|
+
for (let t = 0; t < NodeType.CustomNode; ++t)
|
|
1294
|
+
stateMachine.nodes.push(makeNode());
|
|
1295
|
+
return stateMachine;
|
|
1296
|
+
}
|
|
1297
|
+
function makeAnyOfMachine(inputs) {
|
|
1298
|
+
const output = makeStateMachine();
|
|
1299
|
+
const heads = [];
|
|
1300
|
+
let offset = output.nodes.length;
|
|
1301
|
+
for (const input of inputs) {
|
|
1302
|
+
heads.push(offset);
|
|
1303
|
+
for (let t = 0; t < input.nodes.length; ++t)
|
|
1304
|
+
if (!isTerminalNode(t))
|
|
1305
|
+
output.nodes.push(cloneNode(input.nodes[t], offset));
|
|
1306
|
+
offset += input.nodes.length - NodeType.CustomNode + 1;
|
|
1307
|
+
}
|
|
1308
|
+
for (const head of heads)
|
|
1309
|
+
registerShortcut(output, NodeType.InitialNode, head);
|
|
1310
|
+
return output;
|
|
1311
|
+
}
|
|
1312
|
+
function injectNode(machine, node) {
|
|
1313
|
+
machine.nodes.push(node);
|
|
1314
|
+
return machine.nodes.length - 1;
|
|
1315
|
+
}
|
|
1316
|
+
function simplifyMachine(input) {
|
|
1317
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1318
|
+
const process2 = (node) => {
|
|
1319
|
+
if (visited.has(node))
|
|
1320
|
+
return;
|
|
1321
|
+
visited.add(node);
|
|
1322
|
+
const nodeDef = input.nodes[node];
|
|
1323
|
+
for (const transitions of Object.values(nodeDef.statics))
|
|
1324
|
+
for (const { to } of transitions)
|
|
1325
|
+
process2(to);
|
|
1326
|
+
for (const [, { to }] of nodeDef.dynamics)
|
|
1327
|
+
process2(to);
|
|
1328
|
+
for (const { to } of nodeDef.shortcuts)
|
|
1329
|
+
process2(to);
|
|
1330
|
+
const shortcuts = new Set(nodeDef.shortcuts.map(({ to }) => to));
|
|
1331
|
+
while (nodeDef.shortcuts.length > 0) {
|
|
1332
|
+
const { to } = nodeDef.shortcuts.shift();
|
|
1333
|
+
const toDef = input.nodes[to];
|
|
1334
|
+
for (const [segment, transitions] of Object.entries(toDef.statics)) {
|
|
1335
|
+
const store = !Object.prototype.hasOwnProperty.call(nodeDef.statics, segment) ? nodeDef.statics[segment] = [] : nodeDef.statics[segment];
|
|
1336
|
+
for (const transition of transitions) {
|
|
1337
|
+
if (!store.some(({ to: to2 }) => transition.to === to2)) {
|
|
1338
|
+
store.push(transition);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
for (const [test, transition] of toDef.dynamics)
|
|
1343
|
+
if (!nodeDef.dynamics.some(([otherTest, { to: to2 }]) => test === otherTest && transition.to === to2))
|
|
1344
|
+
nodeDef.dynamics.push([test, transition]);
|
|
1345
|
+
for (const transition of toDef.shortcuts) {
|
|
1346
|
+
if (!shortcuts.has(transition.to)) {
|
|
1347
|
+
nodeDef.shortcuts.push(transition);
|
|
1348
|
+
shortcuts.add(transition.to);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
process2(NodeType.InitialNode);
|
|
1354
|
+
}
|
|
1355
|
+
function debugMachine(machine, { prefix = `` } = {}) {
|
|
1356
|
+
if (IS_DEBUG) {
|
|
1357
|
+
debug(`${prefix}Nodes are:`);
|
|
1358
|
+
for (let t = 0; t < machine.nodes.length; ++t) {
|
|
1359
|
+
debug(`${prefix} ${t}: ${JSON.stringify(machine.nodes[t])}`);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
function runMachineInternal(machine, input, partial = false) {
|
|
1364
|
+
debug(`Running a vm on ${JSON.stringify(input)}`);
|
|
1365
|
+
let branches = [{
|
|
1366
|
+
node: NodeType.InitialNode,
|
|
1367
|
+
state: {
|
|
1368
|
+
candidateUsage: null,
|
|
1369
|
+
requiredOptions: [],
|
|
1370
|
+
errorMessage: null,
|
|
1371
|
+
ignoreOptions: false,
|
|
1372
|
+
options: [],
|
|
1373
|
+
path: [],
|
|
1374
|
+
positionals: [],
|
|
1375
|
+
remainder: null,
|
|
1376
|
+
selectedIndex: null,
|
|
1377
|
+
tokens: []
|
|
1378
|
+
}
|
|
1379
|
+
}];
|
|
1380
|
+
debugMachine(machine, { prefix: ` ` });
|
|
1381
|
+
const tokens = [SpecialToken.StartOfInput, ...input];
|
|
1382
|
+
for (let t = 0; t < tokens.length; ++t) {
|
|
1383
|
+
const segment = tokens[t];
|
|
1384
|
+
const isEOI = segment === SpecialToken.EndOfInput || segment === SpecialToken.EndOfPartialInput;
|
|
1385
|
+
const segmentIndex = t - 1;
|
|
1386
|
+
debug(` Processing ${JSON.stringify(segment)}`);
|
|
1387
|
+
const nextBranches = [];
|
|
1388
|
+
for (const { node, state } of branches) {
|
|
1389
|
+
debug(` Current node is ${node}`);
|
|
1390
|
+
const nodeDef = machine.nodes[node];
|
|
1391
|
+
if (node === NodeType.ErrorNode) {
|
|
1392
|
+
nextBranches.push({ node, state });
|
|
1393
|
+
continue;
|
|
1394
|
+
}
|
|
1395
|
+
console.assert(nodeDef.shortcuts.length === 0, `Shortcuts should have been eliminated by now`);
|
|
1396
|
+
const hasExactMatch = Object.prototype.hasOwnProperty.call(nodeDef.statics, segment);
|
|
1397
|
+
if (!partial || t < tokens.length - 1 || hasExactMatch) {
|
|
1398
|
+
if (hasExactMatch) {
|
|
1399
|
+
const transitions = nodeDef.statics[segment];
|
|
1400
|
+
for (const { to, reducer } of transitions) {
|
|
1401
|
+
nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment, segmentIndex) : state });
|
|
1402
|
+
debug(` Static transition to ${to} found`);
|
|
1403
|
+
}
|
|
1404
|
+
} else {
|
|
1405
|
+
debug(` No static transition found`);
|
|
1406
|
+
}
|
|
1407
|
+
} else {
|
|
1408
|
+
let hasMatches = false;
|
|
1409
|
+
for (const candidate of Object.keys(nodeDef.statics)) {
|
|
1410
|
+
if (!candidate.startsWith(segment))
|
|
1411
|
+
continue;
|
|
1412
|
+
if (segment === candidate) {
|
|
1413
|
+
for (const { to, reducer } of nodeDef.statics[candidate]) {
|
|
1414
|
+
nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment, segmentIndex) : state });
|
|
1415
|
+
debug(` Static transition to ${to} found`);
|
|
1416
|
+
}
|
|
1417
|
+
} else {
|
|
1418
|
+
for (const { to } of nodeDef.statics[candidate]) {
|
|
1419
|
+
nextBranches.push({ node: to, state: { ...state, remainder: candidate.slice(segment.length) } });
|
|
1420
|
+
debug(` Static transition to ${to} found (partial match)`);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
hasMatches = true;
|
|
1424
|
+
}
|
|
1425
|
+
if (!hasMatches) {
|
|
1426
|
+
debug(` No partial static transition found`);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
if (!isEOI) {
|
|
1430
|
+
for (const [test, { to, reducer }] of nodeDef.dynamics) {
|
|
1431
|
+
if (execute(tests, test, state, segment, segmentIndex)) {
|
|
1432
|
+
nextBranches.push({ node: to, state: typeof reducer !== `undefined` ? execute(reducers, reducer, state, segment, segmentIndex) : state });
|
|
1433
|
+
debug(` Dynamic transition to ${to} found (via ${test})`);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
if (nextBranches.length === 0 && isEOI && input.length === 1) {
|
|
1439
|
+
return [{
|
|
1440
|
+
node: NodeType.InitialNode,
|
|
1441
|
+
state: basicHelpState
|
|
1442
|
+
}];
|
|
1443
|
+
}
|
|
1444
|
+
if (nextBranches.length === 0) {
|
|
1445
|
+
throw new UnknownSyntaxError(input, branches.filter(({ node }) => {
|
|
1446
|
+
return node !== NodeType.ErrorNode;
|
|
1447
|
+
}).map(({ state }) => {
|
|
1448
|
+
return { usage: state.candidateUsage, reason: null };
|
|
1449
|
+
}));
|
|
1450
|
+
}
|
|
1451
|
+
if (nextBranches.every(({ node }) => node === NodeType.ErrorNode)) {
|
|
1452
|
+
throw new UnknownSyntaxError(input, nextBranches.map(({ state }) => {
|
|
1453
|
+
return { usage: state.candidateUsage, reason: state.errorMessage };
|
|
1454
|
+
}));
|
|
1455
|
+
}
|
|
1456
|
+
branches = trimSmallerBranches(nextBranches);
|
|
1457
|
+
}
|
|
1458
|
+
if (branches.length > 0) {
|
|
1459
|
+
debug(` Results:`);
|
|
1460
|
+
for (const branch of branches) {
|
|
1461
|
+
debug(` - ${branch.node} -> ${JSON.stringify(branch.state)}`);
|
|
1462
|
+
}
|
|
1463
|
+
} else {
|
|
1464
|
+
debug(` No results`);
|
|
1465
|
+
}
|
|
1466
|
+
return branches;
|
|
1467
|
+
}
|
|
1468
|
+
function runMachine(machine, input, { endToken = SpecialToken.EndOfInput } = {}) {
|
|
1469
|
+
const branches = runMachineInternal(machine, [...input, endToken]);
|
|
1470
|
+
return selectBestState(input, branches.map(({ state }) => {
|
|
1471
|
+
return state;
|
|
1472
|
+
}));
|
|
1473
|
+
}
|
|
1474
|
+
function trimSmallerBranches(branches) {
|
|
1475
|
+
let maxPathSize = 0;
|
|
1476
|
+
for (const { state } of branches)
|
|
1477
|
+
if (state.path.length > maxPathSize)
|
|
1478
|
+
maxPathSize = state.path.length;
|
|
1479
|
+
return branches.filter(({ state }) => {
|
|
1480
|
+
return state.path.length === maxPathSize;
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
function selectBestState(input, states) {
|
|
1484
|
+
const terminalStates = states.filter((state) => {
|
|
1485
|
+
return state.selectedIndex !== null;
|
|
1486
|
+
});
|
|
1487
|
+
if (terminalStates.length === 0)
|
|
1488
|
+
throw new Error();
|
|
1489
|
+
const requiredOptionsSetStates = terminalStates.filter((state) => state.selectedIndex === HELP_COMMAND_INDEX || state.requiredOptions.every((names) => names.some((name) => state.options.find((opt) => opt.name === name))));
|
|
1490
|
+
if (requiredOptionsSetStates.length === 0) {
|
|
1491
|
+
throw new UnknownSyntaxError(input, terminalStates.map((state) => ({
|
|
1492
|
+
usage: state.candidateUsage,
|
|
1493
|
+
reason: null
|
|
1494
|
+
})));
|
|
1495
|
+
}
|
|
1496
|
+
let maxPathSize = 0;
|
|
1497
|
+
for (const state of requiredOptionsSetStates)
|
|
1498
|
+
if (state.path.length > maxPathSize)
|
|
1499
|
+
maxPathSize = state.path.length;
|
|
1500
|
+
const bestPathBranches = requiredOptionsSetStates.filter((state) => {
|
|
1501
|
+
return state.path.length === maxPathSize;
|
|
1502
|
+
});
|
|
1503
|
+
const getPositionalCount = (state) => state.positionals.filter(({ extra }) => {
|
|
1504
|
+
return !extra;
|
|
1505
|
+
}).length + state.options.length;
|
|
1506
|
+
const statesWithPositionalCount = bestPathBranches.map((state) => {
|
|
1507
|
+
return { state, positionalCount: getPositionalCount(state) };
|
|
1508
|
+
});
|
|
1509
|
+
let maxPositionalCount = 0;
|
|
1510
|
+
for (const { positionalCount } of statesWithPositionalCount)
|
|
1511
|
+
if (positionalCount > maxPositionalCount)
|
|
1512
|
+
maxPositionalCount = positionalCount;
|
|
1513
|
+
const bestPositionalStates = statesWithPositionalCount.filter(({ positionalCount }) => {
|
|
1514
|
+
return positionalCount === maxPositionalCount;
|
|
1515
|
+
}).map(({ state }) => {
|
|
1516
|
+
return state;
|
|
1517
|
+
});
|
|
1518
|
+
const fixedStates = aggregateHelpStates(bestPositionalStates);
|
|
1519
|
+
if (fixedStates.length > 1)
|
|
1520
|
+
throw new AmbiguousSyntaxError(input, fixedStates.map((state) => state.candidateUsage));
|
|
1521
|
+
return fixedStates[0];
|
|
1522
|
+
}
|
|
1523
|
+
function aggregateHelpStates(states) {
|
|
1524
|
+
const notHelps = [];
|
|
1525
|
+
const helps = [];
|
|
1526
|
+
for (const state of states) {
|
|
1527
|
+
if (state.selectedIndex === HELP_COMMAND_INDEX) {
|
|
1528
|
+
helps.push(state);
|
|
1529
|
+
} else {
|
|
1530
|
+
notHelps.push(state);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
if (helps.length > 0) {
|
|
1534
|
+
notHelps.push({
|
|
1535
|
+
...basicHelpState,
|
|
1536
|
+
path: findCommonPrefix(...helps.map((state) => state.path)),
|
|
1537
|
+
options: helps.reduce((options, state) => options.concat(state.options), [])
|
|
1538
|
+
});
|
|
1539
|
+
}
|
|
1540
|
+
return notHelps;
|
|
1541
|
+
}
|
|
1542
|
+
function findCommonPrefix(firstPath, secondPath, ...rest) {
|
|
1543
|
+
if (secondPath === void 0)
|
|
1544
|
+
return Array.from(firstPath);
|
|
1545
|
+
return findCommonPrefix(firstPath.filter((segment, i) => segment === secondPath[i]), ...rest);
|
|
1546
|
+
}
|
|
1547
|
+
function makeNode() {
|
|
1548
|
+
return {
|
|
1549
|
+
dynamics: [],
|
|
1550
|
+
shortcuts: [],
|
|
1551
|
+
statics: {}
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
function isTerminalNode(node) {
|
|
1555
|
+
return node === NodeType.SuccessNode || node === NodeType.ErrorNode;
|
|
1556
|
+
}
|
|
1557
|
+
function cloneTransition(input, offset = 0) {
|
|
1558
|
+
const to = !isTerminalNode(input.to) ? input.to >= NodeType.CustomNode ? input.to + offset - NodeType.CustomNode + 1 : input.to + offset : input.to;
|
|
1559
|
+
return {
|
|
1560
|
+
to,
|
|
1561
|
+
reducer: input.reducer
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
function cloneNode(input, offset = 0) {
|
|
1565
|
+
const output = makeNode();
|
|
1566
|
+
for (const [test, transition] of input.dynamics)
|
|
1567
|
+
output.dynamics.push([test, cloneTransition(transition, offset)]);
|
|
1568
|
+
for (const transition of input.shortcuts)
|
|
1569
|
+
output.shortcuts.push(cloneTransition(transition, offset));
|
|
1570
|
+
for (const [segment, transitions] of Object.entries(input.statics))
|
|
1571
|
+
output.statics[segment] = transitions.map((transition) => cloneTransition(transition, offset));
|
|
1572
|
+
return output;
|
|
1573
|
+
}
|
|
1574
|
+
function registerDynamic(machine, from, test, to, reducer) {
|
|
1575
|
+
machine.nodes[from].dynamics.push([
|
|
1576
|
+
test,
|
|
1577
|
+
{ to, reducer }
|
|
1578
|
+
]);
|
|
1579
|
+
}
|
|
1580
|
+
function registerShortcut(machine, from, to, reducer) {
|
|
1581
|
+
machine.nodes[from].shortcuts.push({ to, reducer });
|
|
1582
|
+
}
|
|
1583
|
+
function registerStatic(machine, from, test, to, reducer) {
|
|
1584
|
+
const store = !Object.prototype.hasOwnProperty.call(machine.nodes[from].statics, test) ? machine.nodes[from].statics[test] = [] : machine.nodes[from].statics[test];
|
|
1585
|
+
store.push({ to, reducer });
|
|
1586
|
+
}
|
|
1587
|
+
function execute(store, callback, state, segment, segmentIndex) {
|
|
1588
|
+
if (Array.isArray(callback)) {
|
|
1589
|
+
const [name, ...args] = callback;
|
|
1590
|
+
return store[name](state, segment, segmentIndex, ...args);
|
|
1591
|
+
} else {
|
|
1592
|
+
return store[callback](state, segment, segmentIndex);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
var tests = {
|
|
1596
|
+
always: () => {
|
|
1597
|
+
return true;
|
|
1598
|
+
},
|
|
1599
|
+
isOptionLike: (state, segment) => {
|
|
1600
|
+
return !state.ignoreOptions && (segment !== `-` && segment.startsWith(`-`));
|
|
1601
|
+
},
|
|
1602
|
+
isNotOptionLike: (state, segment) => {
|
|
1603
|
+
return state.ignoreOptions || segment === `-` || !segment.startsWith(`-`);
|
|
1604
|
+
},
|
|
1605
|
+
isOption: (state, segment, segmentIndex, name) => {
|
|
1606
|
+
return !state.ignoreOptions && segment === name;
|
|
1607
|
+
},
|
|
1608
|
+
isBatchOption: (state, segment, segmentIndex, names) => {
|
|
1609
|
+
return !state.ignoreOptions && BATCH_REGEX.test(segment) && [...segment.slice(1)].every((name) => names.has(`-${name}`));
|
|
1610
|
+
},
|
|
1611
|
+
isBoundOption: (state, segment, segmentIndex, names, options) => {
|
|
1612
|
+
const optionParsing = segment.match(BINDING_REGEX);
|
|
1613
|
+
return !state.ignoreOptions && !!optionParsing && OPTION_REGEX.test(optionParsing[1]) && names.has(optionParsing[1]) && options.filter((opt) => opt.nameSet.includes(optionParsing[1])).every((opt) => opt.allowBinding);
|
|
1614
|
+
},
|
|
1615
|
+
isNegatedOption: (state, segment, segmentIndex, name) => {
|
|
1616
|
+
return !state.ignoreOptions && segment === `--no-${name.slice(2)}`;
|
|
1617
|
+
},
|
|
1618
|
+
isHelp: (state, segment) => {
|
|
1619
|
+
return !state.ignoreOptions && HELP_REGEX.test(segment);
|
|
1620
|
+
},
|
|
1621
|
+
isUnsupportedOption: (state, segment, segmentIndex, names) => {
|
|
1622
|
+
return !state.ignoreOptions && segment.startsWith(`-`) && OPTION_REGEX.test(segment) && !names.has(segment);
|
|
1623
|
+
},
|
|
1624
|
+
isInvalidOption: (state, segment) => {
|
|
1625
|
+
return !state.ignoreOptions && segment.startsWith(`-`) && !OPTION_REGEX.test(segment);
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
var reducers = {
|
|
1629
|
+
setCandidateState: (state, segment, segmentIndex, candidateState) => {
|
|
1630
|
+
return { ...state, ...candidateState };
|
|
1631
|
+
},
|
|
1632
|
+
setSelectedIndex: (state, segment, segmentIndex, index) => {
|
|
1633
|
+
return { ...state, selectedIndex: index };
|
|
1634
|
+
},
|
|
1635
|
+
pushBatch: (state, segment, segmentIndex, names) => {
|
|
1636
|
+
const options = state.options.slice();
|
|
1637
|
+
const tokens = state.tokens.slice();
|
|
1638
|
+
for (let t = 1; t < segment.length; ++t) {
|
|
1639
|
+
const name = names.get(`-${segment[t]}`);
|
|
1640
|
+
const slice = t === 1 ? [0, 2] : [t, t + 1];
|
|
1641
|
+
options.push({ name, value: true });
|
|
1642
|
+
tokens.push({ segmentIndex, type: `option`, option: name, slice });
|
|
1643
|
+
}
|
|
1644
|
+
return { ...state, options, tokens };
|
|
1645
|
+
},
|
|
1646
|
+
pushBound: (state, segment, segmentIndex) => {
|
|
1647
|
+
const [, name, value] = segment.match(BINDING_REGEX);
|
|
1648
|
+
const options = state.options.concat({ name, value });
|
|
1649
|
+
const tokens = state.tokens.concat([
|
|
1650
|
+
{ segmentIndex, type: `option`, slice: [0, name.length], option: name },
|
|
1651
|
+
{ segmentIndex, type: `assign`, slice: [name.length, name.length + 1] },
|
|
1652
|
+
{ segmentIndex, type: `value`, slice: [name.length + 1, name.length + value.length + 1] }
|
|
1653
|
+
]);
|
|
1654
|
+
return { ...state, options, tokens };
|
|
1655
|
+
},
|
|
1656
|
+
pushPath: (state, segment, segmentIndex) => {
|
|
1657
|
+
const path2 = state.path.concat(segment);
|
|
1658
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `path` });
|
|
1659
|
+
return { ...state, path: path2, tokens };
|
|
1660
|
+
},
|
|
1661
|
+
pushPositional: (state, segment, segmentIndex) => {
|
|
1662
|
+
const positionals = state.positionals.concat({ value: segment, extra: false });
|
|
1663
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `positional` });
|
|
1664
|
+
return { ...state, positionals, tokens };
|
|
1665
|
+
},
|
|
1666
|
+
pushExtra: (state, segment, segmentIndex) => {
|
|
1667
|
+
const positionals = state.positionals.concat({ value: segment, extra: true });
|
|
1668
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `positional` });
|
|
1669
|
+
return { ...state, positionals, tokens };
|
|
1670
|
+
},
|
|
1671
|
+
pushExtraNoLimits: (state, segment, segmentIndex) => {
|
|
1672
|
+
const positionals = state.positionals.concat({ value: segment, extra: NoLimits });
|
|
1673
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `positional` });
|
|
1674
|
+
return { ...state, positionals, tokens };
|
|
1675
|
+
},
|
|
1676
|
+
pushTrue: (state, segment, segmentIndex, name) => {
|
|
1677
|
+
const options = state.options.concat({ name, value: true });
|
|
1678
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `option`, option: name });
|
|
1679
|
+
return { ...state, options, tokens };
|
|
1680
|
+
},
|
|
1681
|
+
pushFalse: (state, segment, segmentIndex, name) => {
|
|
1682
|
+
const options = state.options.concat({ name, value: false });
|
|
1683
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `option`, option: name });
|
|
1684
|
+
return { ...state, options, tokens };
|
|
1685
|
+
},
|
|
1686
|
+
pushUndefined: (state, segment, segmentIndex, name) => {
|
|
1687
|
+
const options = state.options.concat({ name: segment, value: void 0 });
|
|
1688
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `option`, option: segment });
|
|
1689
|
+
return { ...state, options, tokens };
|
|
1690
|
+
},
|
|
1691
|
+
pushStringValue: (state, segment, segmentIndex) => {
|
|
1692
|
+
var _a;
|
|
1693
|
+
const lastOption = state.options[state.options.length - 1];
|
|
1694
|
+
const options = state.options.slice();
|
|
1695
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `value` });
|
|
1696
|
+
lastOption.value = ((_a = lastOption.value) !== null && _a !== void 0 ? _a : []).concat([segment]);
|
|
1697
|
+
return { ...state, options, tokens };
|
|
1698
|
+
},
|
|
1699
|
+
setStringValue: (state, segment, segmentIndex) => {
|
|
1700
|
+
const lastOption = state.options[state.options.length - 1];
|
|
1701
|
+
const options = state.options.slice();
|
|
1702
|
+
const tokens = state.tokens.concat({ segmentIndex, type: `value` });
|
|
1703
|
+
lastOption.value = segment;
|
|
1704
|
+
return { ...state, options, tokens };
|
|
1705
|
+
},
|
|
1706
|
+
inhibateOptions: (state) => {
|
|
1707
|
+
return { ...state, ignoreOptions: true };
|
|
1708
|
+
},
|
|
1709
|
+
useHelp: (state, segment, segmentIndex, command) => {
|
|
1710
|
+
const [
|
|
1711
|
+
,
|
|
1712
|
+
/* name */
|
|
1713
|
+
,
|
|
1714
|
+
index
|
|
1715
|
+
] = segment.match(HELP_REGEX);
|
|
1716
|
+
if (typeof index !== `undefined`) {
|
|
1717
|
+
return { ...state, options: [{ name: `-c`, value: String(command) }, { name: `-i`, value: index }] };
|
|
1718
|
+
} else {
|
|
1719
|
+
return { ...state, options: [{ name: `-c`, value: String(command) }] };
|
|
1720
|
+
}
|
|
1721
|
+
},
|
|
1722
|
+
setError: (state, segment, segmentIndex, errorMessage) => {
|
|
1723
|
+
if (segment === SpecialToken.EndOfInput || segment === SpecialToken.EndOfPartialInput) {
|
|
1724
|
+
return { ...state, errorMessage: `${errorMessage}.` };
|
|
1725
|
+
} else {
|
|
1726
|
+
return { ...state, errorMessage: `${errorMessage} ("${segment}").` };
|
|
1727
|
+
}
|
|
1728
|
+
},
|
|
1729
|
+
setOptionArityError: (state, segment) => {
|
|
1730
|
+
const lastOption = state.options[state.options.length - 1];
|
|
1731
|
+
return { ...state, errorMessage: `Not enough arguments to option ${lastOption.name}.` };
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
var NoLimits = Symbol();
|
|
1735
|
+
var CommandBuilder = class {
|
|
1736
|
+
constructor(cliIndex, cliOpts) {
|
|
1737
|
+
this.allOptionNames = /* @__PURE__ */ new Map();
|
|
1738
|
+
this.arity = { leading: [], trailing: [], extra: [], proxy: false };
|
|
1739
|
+
this.options = [];
|
|
1740
|
+
this.paths = [];
|
|
1741
|
+
this.cliIndex = cliIndex;
|
|
1742
|
+
this.cliOpts = cliOpts;
|
|
1743
|
+
}
|
|
1744
|
+
addPath(path2) {
|
|
1745
|
+
this.paths.push(path2);
|
|
1746
|
+
}
|
|
1747
|
+
setArity({ leading = this.arity.leading, trailing = this.arity.trailing, extra = this.arity.extra, proxy = this.arity.proxy }) {
|
|
1748
|
+
Object.assign(this.arity, { leading, trailing, extra, proxy });
|
|
1749
|
+
}
|
|
1750
|
+
addPositional({ name = `arg`, required = true } = {}) {
|
|
1751
|
+
if (!required && this.arity.extra === NoLimits)
|
|
1752
|
+
throw new Error(`Optional parameters cannot be declared when using .rest() or .proxy()`);
|
|
1753
|
+
if (!required && this.arity.trailing.length > 0)
|
|
1754
|
+
throw new Error(`Optional parameters cannot be declared after the required trailing positional arguments`);
|
|
1755
|
+
if (!required && this.arity.extra !== NoLimits) {
|
|
1756
|
+
this.arity.extra.push(name);
|
|
1757
|
+
} else if (this.arity.extra !== NoLimits && this.arity.extra.length === 0) {
|
|
1758
|
+
this.arity.leading.push(name);
|
|
1759
|
+
} else {
|
|
1760
|
+
this.arity.trailing.push(name);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
addRest({ name = `arg`, required = 0 } = {}) {
|
|
1764
|
+
if (this.arity.extra === NoLimits)
|
|
1765
|
+
throw new Error(`Infinite lists cannot be declared multiple times in the same command`);
|
|
1766
|
+
if (this.arity.trailing.length > 0)
|
|
1767
|
+
throw new Error(`Infinite lists cannot be declared after the required trailing positional arguments`);
|
|
1768
|
+
for (let t = 0; t < required; ++t)
|
|
1769
|
+
this.addPositional({ name });
|
|
1770
|
+
this.arity.extra = NoLimits;
|
|
1771
|
+
}
|
|
1772
|
+
addProxy({ required = 0 } = {}) {
|
|
1773
|
+
this.addRest({ required });
|
|
1774
|
+
this.arity.proxy = true;
|
|
1775
|
+
}
|
|
1776
|
+
addOption({ names: nameSet, description, arity = 0, hidden = false, required = false, allowBinding = true }) {
|
|
1777
|
+
if (!allowBinding && arity > 1)
|
|
1778
|
+
throw new Error(`The arity cannot be higher than 1 when the option only supports the --arg=value syntax`);
|
|
1779
|
+
if (!Number.isInteger(arity))
|
|
1780
|
+
throw new Error(`The arity must be an integer, got ${arity}`);
|
|
1781
|
+
if (arity < 0)
|
|
1782
|
+
throw new Error(`The arity must be positive, got ${arity}`);
|
|
1783
|
+
const preferredName = nameSet.reduce((longestName, name) => {
|
|
1784
|
+
return name.length > longestName.length ? name : longestName;
|
|
1785
|
+
}, ``);
|
|
1786
|
+
for (const name of nameSet)
|
|
1787
|
+
this.allOptionNames.set(name, preferredName);
|
|
1788
|
+
this.options.push({ preferredName, nameSet, description, arity, hidden, required, allowBinding });
|
|
1789
|
+
}
|
|
1790
|
+
setContext(context) {
|
|
1791
|
+
this.context = context;
|
|
1792
|
+
}
|
|
1793
|
+
usage({ detailed = true, inlineOptions = true } = {}) {
|
|
1794
|
+
const segments = [this.cliOpts.binaryName];
|
|
1795
|
+
const detailedOptionList = [];
|
|
1796
|
+
if (this.paths.length > 0)
|
|
1797
|
+
segments.push(...this.paths[0]);
|
|
1798
|
+
if (detailed) {
|
|
1799
|
+
for (const { preferredName, nameSet, arity, hidden, description, required } of this.options) {
|
|
1800
|
+
if (hidden)
|
|
1801
|
+
continue;
|
|
1802
|
+
const args = [];
|
|
1803
|
+
for (let t = 0; t < arity; ++t)
|
|
1804
|
+
args.push(` #${t}`);
|
|
1805
|
+
const definition = `${nameSet.join(`,`)}${args.join(``)}`;
|
|
1806
|
+
if (!inlineOptions && description) {
|
|
1807
|
+
detailedOptionList.push({ preferredName, nameSet, definition, description, required });
|
|
1808
|
+
} else {
|
|
1809
|
+
segments.push(required ? `<${definition}>` : `[${definition}]`);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
segments.push(...this.arity.leading.map((name) => `<${name}>`));
|
|
1813
|
+
if (this.arity.extra === NoLimits)
|
|
1814
|
+
segments.push(`...`);
|
|
1815
|
+
else
|
|
1816
|
+
segments.push(...this.arity.extra.map((name) => `[${name}]`));
|
|
1817
|
+
segments.push(...this.arity.trailing.map((name) => `<${name}>`));
|
|
1818
|
+
}
|
|
1819
|
+
const usage = segments.join(` `);
|
|
1820
|
+
return { usage, options: detailedOptionList };
|
|
1821
|
+
}
|
|
1822
|
+
compile() {
|
|
1823
|
+
if (typeof this.context === `undefined`)
|
|
1824
|
+
throw new Error(`Assertion failed: No context attached`);
|
|
1825
|
+
const machine = makeStateMachine();
|
|
1826
|
+
let firstNode = NodeType.InitialNode;
|
|
1827
|
+
const candidateUsage = this.usage().usage;
|
|
1828
|
+
const requiredOptions = this.options.filter((opt) => opt.required).map((opt) => opt.nameSet);
|
|
1829
|
+
firstNode = injectNode(machine, makeNode());
|
|
1830
|
+
registerStatic(machine, NodeType.InitialNode, SpecialToken.StartOfInput, firstNode, [`setCandidateState`, { candidateUsage, requiredOptions }]);
|
|
1831
|
+
const positionalArgument = this.arity.proxy ? `always` : `isNotOptionLike`;
|
|
1832
|
+
const paths = this.paths.length > 0 ? this.paths : [[]];
|
|
1833
|
+
for (const path2 of paths) {
|
|
1834
|
+
let lastPathNode = firstNode;
|
|
1835
|
+
if (path2.length > 0) {
|
|
1836
|
+
const optionPathNode = injectNode(machine, makeNode());
|
|
1837
|
+
registerShortcut(machine, lastPathNode, optionPathNode);
|
|
1838
|
+
this.registerOptions(machine, optionPathNode);
|
|
1839
|
+
lastPathNode = optionPathNode;
|
|
1840
|
+
}
|
|
1841
|
+
for (let t = 0; t < path2.length; ++t) {
|
|
1842
|
+
const nextPathNode = injectNode(machine, makeNode());
|
|
1843
|
+
registerStatic(machine, lastPathNode, path2[t], nextPathNode, `pushPath`);
|
|
1844
|
+
lastPathNode = nextPathNode;
|
|
1845
|
+
if (t + 1 < path2.length) {
|
|
1846
|
+
const helpNode = injectNode(machine, makeNode());
|
|
1847
|
+
registerDynamic(machine, lastPathNode, `isHelp`, helpNode, [`useHelp`, this.cliIndex]);
|
|
1848
|
+
registerStatic(machine, helpNode, SpecialToken.EndOfInput, NodeType.SuccessNode, [`setSelectedIndex`, HELP_COMMAND_INDEX]);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
if (this.arity.leading.length > 0 || !this.arity.proxy) {
|
|
1852
|
+
const helpNode = injectNode(machine, makeNode());
|
|
1853
|
+
registerDynamic(machine, lastPathNode, `isHelp`, helpNode, [`useHelp`, this.cliIndex]);
|
|
1854
|
+
registerDynamic(machine, helpNode, `always`, helpNode, `pushExtra`);
|
|
1855
|
+
registerStatic(machine, helpNode, SpecialToken.EndOfInput, NodeType.SuccessNode, [`setSelectedIndex`, HELP_COMMAND_INDEX]);
|
|
1856
|
+
this.registerOptions(machine, lastPathNode);
|
|
1857
|
+
}
|
|
1858
|
+
if (this.arity.leading.length > 0) {
|
|
1859
|
+
registerStatic(machine, lastPathNode, SpecialToken.EndOfInput, NodeType.ErrorNode, [`setError`, `Not enough positional arguments`]);
|
|
1860
|
+
registerStatic(machine, lastPathNode, SpecialToken.EndOfPartialInput, NodeType.SuccessNode, [`setSelectedIndex`, this.cliIndex]);
|
|
1861
|
+
}
|
|
1862
|
+
let lastLeadingNode = lastPathNode;
|
|
1863
|
+
for (let t = 0; t < this.arity.leading.length; ++t) {
|
|
1864
|
+
const nextLeadingNode = injectNode(machine, makeNode());
|
|
1865
|
+
if (!this.arity.proxy || t + 1 !== this.arity.leading.length)
|
|
1866
|
+
this.registerOptions(machine, nextLeadingNode);
|
|
1867
|
+
if (this.arity.trailing.length > 0 || t + 1 !== this.arity.leading.length) {
|
|
1868
|
+
registerStatic(machine, nextLeadingNode, SpecialToken.EndOfInput, NodeType.ErrorNode, [`setError`, `Not enough positional arguments`]);
|
|
1869
|
+
registerStatic(machine, nextLeadingNode, SpecialToken.EndOfPartialInput, NodeType.SuccessNode, [`setSelectedIndex`, this.cliIndex]);
|
|
1870
|
+
}
|
|
1871
|
+
registerDynamic(machine, lastLeadingNode, `isNotOptionLike`, nextLeadingNode, `pushPositional`);
|
|
1872
|
+
lastLeadingNode = nextLeadingNode;
|
|
1873
|
+
}
|
|
1874
|
+
let lastExtraNode = lastLeadingNode;
|
|
1875
|
+
if (this.arity.extra === NoLimits || this.arity.extra.length > 0) {
|
|
1876
|
+
const extraShortcutNode = injectNode(machine, makeNode());
|
|
1877
|
+
registerShortcut(machine, lastLeadingNode, extraShortcutNode);
|
|
1878
|
+
if (this.arity.extra === NoLimits) {
|
|
1879
|
+
const extraNode = injectNode(machine, makeNode());
|
|
1880
|
+
if (!this.arity.proxy)
|
|
1881
|
+
this.registerOptions(machine, extraNode);
|
|
1882
|
+
registerDynamic(machine, lastLeadingNode, positionalArgument, extraNode, `pushExtraNoLimits`);
|
|
1883
|
+
registerDynamic(machine, extraNode, positionalArgument, extraNode, `pushExtraNoLimits`);
|
|
1884
|
+
registerShortcut(machine, extraNode, extraShortcutNode);
|
|
1885
|
+
} else {
|
|
1886
|
+
for (let t = 0; t < this.arity.extra.length; ++t) {
|
|
1887
|
+
const nextExtraNode = injectNode(machine, makeNode());
|
|
1888
|
+
if (!this.arity.proxy || t > 0)
|
|
1889
|
+
this.registerOptions(machine, nextExtraNode);
|
|
1890
|
+
registerDynamic(machine, lastExtraNode, positionalArgument, nextExtraNode, `pushExtra`);
|
|
1891
|
+
registerShortcut(machine, nextExtraNode, extraShortcutNode);
|
|
1892
|
+
lastExtraNode = nextExtraNode;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
lastExtraNode = extraShortcutNode;
|
|
1896
|
+
}
|
|
1897
|
+
if (this.arity.trailing.length > 0) {
|
|
1898
|
+
registerStatic(machine, lastExtraNode, SpecialToken.EndOfInput, NodeType.ErrorNode, [`setError`, `Not enough positional arguments`]);
|
|
1899
|
+
registerStatic(machine, lastExtraNode, SpecialToken.EndOfPartialInput, NodeType.SuccessNode, [`setSelectedIndex`, this.cliIndex]);
|
|
1900
|
+
}
|
|
1901
|
+
let lastTrailingNode = lastExtraNode;
|
|
1902
|
+
for (let t = 0; t < this.arity.trailing.length; ++t) {
|
|
1903
|
+
const nextTrailingNode = injectNode(machine, makeNode());
|
|
1904
|
+
if (!this.arity.proxy)
|
|
1905
|
+
this.registerOptions(machine, nextTrailingNode);
|
|
1906
|
+
if (t + 1 < this.arity.trailing.length) {
|
|
1907
|
+
registerStatic(machine, nextTrailingNode, SpecialToken.EndOfInput, NodeType.ErrorNode, [`setError`, `Not enough positional arguments`]);
|
|
1908
|
+
registerStatic(machine, nextTrailingNode, SpecialToken.EndOfPartialInput, NodeType.SuccessNode, [`setSelectedIndex`, this.cliIndex]);
|
|
1909
|
+
}
|
|
1910
|
+
registerDynamic(machine, lastTrailingNode, `isNotOptionLike`, nextTrailingNode, `pushPositional`);
|
|
1911
|
+
lastTrailingNode = nextTrailingNode;
|
|
1912
|
+
}
|
|
1913
|
+
registerDynamic(machine, lastTrailingNode, positionalArgument, NodeType.ErrorNode, [`setError`, `Extraneous positional argument`]);
|
|
1914
|
+
registerStatic(machine, lastTrailingNode, SpecialToken.EndOfInput, NodeType.SuccessNode, [`setSelectedIndex`, this.cliIndex]);
|
|
1915
|
+
registerStatic(machine, lastTrailingNode, SpecialToken.EndOfPartialInput, NodeType.SuccessNode, [`setSelectedIndex`, this.cliIndex]);
|
|
1916
|
+
}
|
|
1917
|
+
return {
|
|
1918
|
+
machine,
|
|
1919
|
+
context: this.context
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
registerOptions(machine, node) {
|
|
1923
|
+
registerDynamic(machine, node, [`isOption`, `--`], node, `inhibateOptions`);
|
|
1924
|
+
registerDynamic(machine, node, [`isBatchOption`, this.allOptionNames], node, [`pushBatch`, this.allOptionNames]);
|
|
1925
|
+
registerDynamic(machine, node, [`isBoundOption`, this.allOptionNames, this.options], node, `pushBound`);
|
|
1926
|
+
registerDynamic(machine, node, [`isUnsupportedOption`, this.allOptionNames], NodeType.ErrorNode, [`setError`, `Unsupported option name`]);
|
|
1927
|
+
registerDynamic(machine, node, [`isInvalidOption`], NodeType.ErrorNode, [`setError`, `Invalid option name`]);
|
|
1928
|
+
for (const option of this.options) {
|
|
1929
|
+
if (option.arity === 0) {
|
|
1930
|
+
for (const name of option.nameSet) {
|
|
1931
|
+
registerDynamic(machine, node, [`isOption`, name], node, [`pushTrue`, option.preferredName]);
|
|
1932
|
+
if (name.startsWith(`--`) && !name.startsWith(`--no-`)) {
|
|
1933
|
+
registerDynamic(machine, node, [`isNegatedOption`, name], node, [`pushFalse`, option.preferredName]);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
} else {
|
|
1937
|
+
let lastNode = injectNode(machine, makeNode());
|
|
1938
|
+
for (const name of option.nameSet)
|
|
1939
|
+
registerDynamic(machine, node, [`isOption`, name], lastNode, [`pushUndefined`, option.preferredName]);
|
|
1940
|
+
for (let t = 0; t < option.arity; ++t) {
|
|
1941
|
+
const nextNode = injectNode(machine, makeNode());
|
|
1942
|
+
registerStatic(machine, lastNode, SpecialToken.EndOfInput, NodeType.ErrorNode, `setOptionArityError`);
|
|
1943
|
+
registerStatic(machine, lastNode, SpecialToken.EndOfPartialInput, NodeType.ErrorNode, `setOptionArityError`);
|
|
1944
|
+
registerDynamic(machine, lastNode, `isOptionLike`, NodeType.ErrorNode, `setOptionArityError`);
|
|
1945
|
+
const action = option.arity === 1 ? `setStringValue` : `pushStringValue`;
|
|
1946
|
+
registerDynamic(machine, lastNode, `isNotOptionLike`, nextNode, action);
|
|
1947
|
+
lastNode = nextNode;
|
|
1948
|
+
}
|
|
1949
|
+
registerShortcut(machine, lastNode, node);
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
};
|
|
1954
|
+
var CliBuilder = class _CliBuilder {
|
|
1955
|
+
static build(cbs, opts = {}) {
|
|
1956
|
+
return new _CliBuilder(opts).commands(cbs).compile();
|
|
1957
|
+
}
|
|
1958
|
+
constructor({ binaryName = `...` } = {}) {
|
|
1959
|
+
this.builders = [];
|
|
1960
|
+
this.opts = { binaryName };
|
|
1961
|
+
}
|
|
1962
|
+
getBuilderByIndex(n) {
|
|
1963
|
+
if (!(n >= 0 && n < this.builders.length))
|
|
1964
|
+
throw new Error(`Assertion failed: Out-of-bound command index (${n})`);
|
|
1965
|
+
return this.builders[n];
|
|
1966
|
+
}
|
|
1967
|
+
commands(cbs) {
|
|
1968
|
+
for (const cb of cbs)
|
|
1969
|
+
cb(this.command());
|
|
1970
|
+
return this;
|
|
1971
|
+
}
|
|
1972
|
+
command() {
|
|
1973
|
+
const builder = new CommandBuilder(this.builders.length, this.opts);
|
|
1974
|
+
this.builders.push(builder);
|
|
1975
|
+
return builder;
|
|
1976
|
+
}
|
|
1977
|
+
compile() {
|
|
1978
|
+
const machines = [];
|
|
1979
|
+
const contexts = [];
|
|
1980
|
+
for (const builder of this.builders) {
|
|
1981
|
+
const { machine: machine2, context } = builder.compile();
|
|
1982
|
+
machines.push(machine2);
|
|
1983
|
+
contexts.push(context);
|
|
1984
|
+
}
|
|
1985
|
+
const machine = makeAnyOfMachine(machines);
|
|
1986
|
+
simplifyMachine(machine);
|
|
1987
|
+
return {
|
|
1988
|
+
machine,
|
|
1989
|
+
contexts,
|
|
1990
|
+
process: (input, { partial } = {}) => {
|
|
1991
|
+
const endToken = partial ? SpecialToken.EndOfPartialInput : SpecialToken.EndOfInput;
|
|
1992
|
+
return runMachine(machine, input, { endToken });
|
|
1993
|
+
}
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
|
|
1998
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/format.mjs
|
|
1999
|
+
init_cjs_shims();
|
|
2000
|
+
var MAX_LINE_LENGTH = 80;
|
|
2001
|
+
var richLine = Array(MAX_LINE_LENGTH).fill(`\u2501`);
|
|
2002
|
+
for (let t = 0; t <= 24; ++t)
|
|
2003
|
+
richLine[richLine.length - t] = `\x1B[38;5;${232 + t}m\u2501`;
|
|
2004
|
+
var richFormat = {
|
|
2005
|
+
header: (str) => `\x1B[1m\u2501\u2501\u2501 ${str}${str.length < MAX_LINE_LENGTH - 5 ? ` ${richLine.slice(str.length + 5).join(``)}` : `:`}\x1B[0m`,
|
|
2006
|
+
bold: (str) => `\x1B[1m${str}\x1B[22m`,
|
|
2007
|
+
error: (str) => `\x1B[31m\x1B[1m${str}\x1B[22m\x1B[39m`,
|
|
2008
|
+
code: (str) => `\x1B[36m${str}\x1B[39m`
|
|
2009
|
+
};
|
|
2010
|
+
var textFormat = {
|
|
2011
|
+
header: (str) => str,
|
|
2012
|
+
bold: (str) => str,
|
|
2013
|
+
error: (str) => str,
|
|
2014
|
+
code: (str) => str
|
|
2015
|
+
};
|
|
2016
|
+
function dedent(text) {
|
|
2017
|
+
const lines = text.split(`
|
|
2018
|
+
`);
|
|
2019
|
+
const nonEmptyLines = lines.filter((line) => line.match(/\S/));
|
|
2020
|
+
const indent = nonEmptyLines.length > 0 ? nonEmptyLines.reduce((minLength, line) => Math.min(minLength, line.length - line.trimStart().length), Number.MAX_VALUE) : 0;
|
|
2021
|
+
return lines.map((line) => line.slice(indent).trimRight()).join(`
|
|
2022
|
+
`);
|
|
2023
|
+
}
|
|
2024
|
+
function formatMarkdownish(text, { format, paragraphs }) {
|
|
2025
|
+
text = text.replace(/\r\n?/g, `
|
|
2026
|
+
`);
|
|
2027
|
+
text = dedent(text);
|
|
2028
|
+
text = text.replace(/^\n+|\n+$/g, ``);
|
|
2029
|
+
text = text.replace(/^(\s*)-([^\n]*?)\n+/gm, `$1-$2
|
|
2030
|
+
|
|
2031
|
+
`);
|
|
2032
|
+
text = text.replace(/\n(\n)?\n*/g, ($0, $1) => $1 ? $1 : ` `);
|
|
2033
|
+
if (paragraphs) {
|
|
2034
|
+
text = text.split(/\n/).map((paragraph) => {
|
|
2035
|
+
const bulletMatch = paragraph.match(/^\s*[*-][\t ]+(.*)/);
|
|
2036
|
+
if (!bulletMatch)
|
|
2037
|
+
return paragraph.match(/(.{1,80})(?: |$)/g).join(`
|
|
2038
|
+
`);
|
|
2039
|
+
const indent = paragraph.length - paragraph.trimStart().length;
|
|
2040
|
+
return bulletMatch[1].match(new RegExp(`(.{1,${78 - indent}})(?: |$)`, `g`)).map((line, index) => {
|
|
2041
|
+
return ` `.repeat(indent) + (index === 0 ? `- ` : ` `) + line;
|
|
2042
|
+
}).join(`
|
|
2043
|
+
`);
|
|
2044
|
+
}).join(`
|
|
2045
|
+
|
|
2046
|
+
`);
|
|
2047
|
+
}
|
|
2048
|
+
text = text.replace(/(`+)((?:.|[\n])*?)\1/g, ($0, $1, $2) => {
|
|
2049
|
+
return format.code($1 + $2 + $1);
|
|
2050
|
+
});
|
|
2051
|
+
text = text.replace(/(\*\*)((?:.|[\n])*?)\1/g, ($0, $1, $2) => {
|
|
2052
|
+
return format.bold($1 + $2 + $1);
|
|
2053
|
+
});
|
|
2054
|
+
return text ? `${text}
|
|
2055
|
+
` : ``;
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/HelpCommand.mjs
|
|
2059
|
+
init_cjs_shims();
|
|
2060
|
+
var HelpCommand = class _HelpCommand extends Command {
|
|
2061
|
+
static from(state, contexts) {
|
|
2062
|
+
const command = new _HelpCommand(contexts);
|
|
2063
|
+
command.path = state.path;
|
|
2064
|
+
for (const opt of state.options) {
|
|
2065
|
+
switch (opt.name) {
|
|
2066
|
+
case `-c`:
|
|
2067
|
+
{
|
|
2068
|
+
command.commands.push(Number(opt.value));
|
|
2069
|
+
}
|
|
2070
|
+
break;
|
|
2071
|
+
case `-i`:
|
|
2072
|
+
{
|
|
2073
|
+
command.index = Number(opt.value);
|
|
2074
|
+
}
|
|
2075
|
+
break;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return command;
|
|
2079
|
+
}
|
|
2080
|
+
constructor(contexts) {
|
|
2081
|
+
super();
|
|
2082
|
+
this.contexts = contexts;
|
|
2083
|
+
this.commands = [];
|
|
2084
|
+
}
|
|
2085
|
+
async execute() {
|
|
2086
|
+
let commands = this.commands;
|
|
2087
|
+
if (typeof this.index !== `undefined` && this.index >= 0 && this.index < commands.length)
|
|
2088
|
+
commands = [commands[this.index]];
|
|
2089
|
+
if (commands.length === 0) {
|
|
2090
|
+
this.context.stdout.write(this.cli.usage());
|
|
2091
|
+
} else if (commands.length === 1) {
|
|
2092
|
+
this.context.stdout.write(this.cli.usage(this.contexts[commands[0]].commandClass, { detailed: true }));
|
|
2093
|
+
} else if (commands.length > 1) {
|
|
2094
|
+
this.context.stdout.write(`Multiple commands match your selection:
|
|
2095
|
+
`);
|
|
2096
|
+
this.context.stdout.write(`
|
|
2097
|
+
`);
|
|
2098
|
+
let index = 0;
|
|
2099
|
+
for (const command of this.commands)
|
|
2100
|
+
this.context.stdout.write(this.cli.usage(this.contexts[command].commandClass, { prefix: `${index++}. `.padStart(5) }));
|
|
2101
|
+
this.context.stdout.write(`
|
|
2102
|
+
`);
|
|
2103
|
+
this.context.stdout.write(`Run again with -h=<index> to see the longer details of any of those commands.
|
|
2104
|
+
`);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
};
|
|
2108
|
+
|
|
2109
|
+
// ../../.yarn/__virtual__/clipanion-virtual-8d4993908b/0/cache/clipanion-npm-4.0.0-rc.4-8228e3d944-047b415b59.zip/node_modules/clipanion/lib/advanced/Cli.mjs
|
|
2110
|
+
var errorCommandSymbol = Symbol(`clipanion/errorCommand`);
|
|
2111
|
+
var Cli = class _Cli {
|
|
2112
|
+
/**
|
|
2113
|
+
* Creates a new Cli and registers all commands passed as parameters.
|
|
2114
|
+
*
|
|
2115
|
+
* @param commandClasses The Commands to register
|
|
2116
|
+
* @returns The created `Cli` instance
|
|
2117
|
+
*/
|
|
2118
|
+
static from(commandClasses, options = {}) {
|
|
2119
|
+
const cli2 = new _Cli(options);
|
|
2120
|
+
const resolvedCommandClasses = Array.isArray(commandClasses) ? commandClasses : [commandClasses];
|
|
2121
|
+
for (const commandClass of resolvedCommandClasses)
|
|
2122
|
+
cli2.register(commandClass);
|
|
2123
|
+
return cli2;
|
|
2124
|
+
}
|
|
2125
|
+
constructor({ binaryLabel, binaryName: binaryNameOpt = `...`, binaryVersion, enableCapture = false, enableColors } = {}) {
|
|
2126
|
+
this.registrations = /* @__PURE__ */ new Map();
|
|
2127
|
+
this.builder = new CliBuilder({ binaryName: binaryNameOpt });
|
|
2128
|
+
this.binaryLabel = binaryLabel;
|
|
2129
|
+
this.binaryName = binaryNameOpt;
|
|
2130
|
+
this.binaryVersion = binaryVersion;
|
|
2131
|
+
this.enableCapture = enableCapture;
|
|
2132
|
+
this.enableColors = enableColors;
|
|
2133
|
+
}
|
|
2134
|
+
/**
|
|
2135
|
+
* Registers a command inside the CLI.
|
|
2136
|
+
*/
|
|
2137
|
+
register(commandClass) {
|
|
2138
|
+
var _a;
|
|
2139
|
+
if (this.registrations.has(commandClass))
|
|
2140
|
+
throw new RangeError(`${commandClass.name} has already been registered`);
|
|
2141
|
+
const specs = /* @__PURE__ */ new Map();
|
|
2142
|
+
const command = new commandClass();
|
|
2143
|
+
for (const key in command) {
|
|
2144
|
+
const value = command[key];
|
|
2145
|
+
if (typeof value === `object` && value !== null && value[Command.isOption]) {
|
|
2146
|
+
specs.set(key, value);
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
const builder = this.builder.command();
|
|
2150
|
+
const index = builder.cliIndex;
|
|
2151
|
+
const paths = (_a = commandClass.paths) !== null && _a !== void 0 ? _a : command.paths;
|
|
2152
|
+
if (typeof paths !== `undefined`)
|
|
2153
|
+
for (const path2 of paths)
|
|
2154
|
+
builder.addPath(path2);
|
|
2155
|
+
this.registrations.set(commandClass, { specs, builder, index });
|
|
2156
|
+
for (const [key, { definition }] of specs.entries())
|
|
2157
|
+
definition(builder, key);
|
|
2158
|
+
builder.setContext({
|
|
2159
|
+
commandClass
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
process(opts, contextArg) {
|
|
2163
|
+
const { input, context: userContext, partial } = typeof opts === `object` && Array.isArray(opts) ? { input: opts, context: contextArg } : opts;
|
|
2164
|
+
const { contexts, process: process2 } = this.builder.compile();
|
|
2165
|
+
const state = process2(input, { partial });
|
|
2166
|
+
const context = {
|
|
2167
|
+
..._Cli.defaultContext,
|
|
2168
|
+
...userContext
|
|
2169
|
+
};
|
|
2170
|
+
switch (state.selectedIndex) {
|
|
2171
|
+
case HELP_COMMAND_INDEX: {
|
|
2172
|
+
const command = HelpCommand.from(state, contexts);
|
|
2173
|
+
command.context = context;
|
|
2174
|
+
command.tokens = state.tokens;
|
|
2175
|
+
return command;
|
|
2176
|
+
}
|
|
2177
|
+
default:
|
|
2178
|
+
{
|
|
2179
|
+
const { commandClass } = contexts[state.selectedIndex];
|
|
2180
|
+
const record = this.registrations.get(commandClass);
|
|
2181
|
+
if (typeof record === `undefined`)
|
|
2182
|
+
throw new Error(`Assertion failed: Expected the command class to have been registered.`);
|
|
2183
|
+
const command = new commandClass();
|
|
2184
|
+
command.context = context;
|
|
2185
|
+
command.tokens = state.tokens;
|
|
2186
|
+
command.path = state.path;
|
|
2187
|
+
try {
|
|
2188
|
+
for (const [key, { transformer }] of record.specs.entries())
|
|
2189
|
+
command[key] = transformer(record.builder, key, state, context);
|
|
2190
|
+
return command;
|
|
2191
|
+
} catch (error) {
|
|
2192
|
+
error[errorCommandSymbol] = command;
|
|
2193
|
+
throw error;
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
break;
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
async run(input, userContext) {
|
|
2200
|
+
var _a, _b;
|
|
2201
|
+
let command;
|
|
2202
|
+
const context = {
|
|
2203
|
+
..._Cli.defaultContext,
|
|
2204
|
+
...userContext
|
|
2205
|
+
};
|
|
2206
|
+
const colored = (_a = this.enableColors) !== null && _a !== void 0 ? _a : context.colorDepth > 1;
|
|
2207
|
+
if (!Array.isArray(input)) {
|
|
2208
|
+
command = input;
|
|
2209
|
+
} else {
|
|
2210
|
+
try {
|
|
2211
|
+
command = this.process(input, context);
|
|
2212
|
+
} catch (error) {
|
|
2213
|
+
context.stdout.write(this.error(error, { colored }));
|
|
2214
|
+
return 1;
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
if (command.help) {
|
|
2218
|
+
context.stdout.write(this.usage(command, { colored, detailed: true }));
|
|
2219
|
+
return 0;
|
|
2220
|
+
}
|
|
2221
|
+
command.context = context;
|
|
2222
|
+
command.cli = {
|
|
2223
|
+
binaryLabel: this.binaryLabel,
|
|
2224
|
+
binaryName: this.binaryName,
|
|
2225
|
+
binaryVersion: this.binaryVersion,
|
|
2226
|
+
enableCapture: this.enableCapture,
|
|
2227
|
+
enableColors: this.enableColors,
|
|
2228
|
+
definitions: () => this.definitions(),
|
|
2229
|
+
definition: (command2) => this.definition(command2),
|
|
2230
|
+
error: (error, opts) => this.error(error, opts),
|
|
2231
|
+
format: (colored2) => this.format(colored2),
|
|
2232
|
+
process: (input2, subContext) => this.process(input2, { ...context, ...subContext }),
|
|
2233
|
+
run: (input2, subContext) => this.run(input2, { ...context, ...subContext }),
|
|
2234
|
+
usage: (command2, opts) => this.usage(command2, opts)
|
|
2235
|
+
};
|
|
2236
|
+
const activate = this.enableCapture ? (_b = getCaptureActivator(context)) !== null && _b !== void 0 ? _b : noopCaptureActivator : noopCaptureActivator;
|
|
2237
|
+
let exitCode;
|
|
2238
|
+
try {
|
|
2239
|
+
exitCode = await activate(() => command.validateAndExecute().catch((error) => command.catch(error).then(() => 0)));
|
|
2240
|
+
} catch (error) {
|
|
2241
|
+
context.stdout.write(this.error(error, { colored, command }));
|
|
2242
|
+
return 1;
|
|
2243
|
+
}
|
|
2244
|
+
return exitCode;
|
|
2245
|
+
}
|
|
2246
|
+
async runExit(input, context) {
|
|
2247
|
+
process.exitCode = await this.run(input, context);
|
|
2248
|
+
}
|
|
2249
|
+
definition(commandClass, { colored = false } = {}) {
|
|
2250
|
+
if (!commandClass.usage)
|
|
2251
|
+
return null;
|
|
2252
|
+
const { usage: path2 } = this.getUsageByRegistration(commandClass, { detailed: false });
|
|
2253
|
+
const { usage, options } = this.getUsageByRegistration(commandClass, { detailed: true, inlineOptions: false });
|
|
2254
|
+
const category = typeof commandClass.usage.category !== `undefined` ? formatMarkdownish(commandClass.usage.category, { format: this.format(colored), paragraphs: false }) : void 0;
|
|
2255
|
+
const description = typeof commandClass.usage.description !== `undefined` ? formatMarkdownish(commandClass.usage.description, { format: this.format(colored), paragraphs: false }) : void 0;
|
|
2256
|
+
const details = typeof commandClass.usage.details !== `undefined` ? formatMarkdownish(commandClass.usage.details, { format: this.format(colored), paragraphs: true }) : void 0;
|
|
2257
|
+
const examples = typeof commandClass.usage.examples !== `undefined` ? commandClass.usage.examples.map(([label, cli2]) => [formatMarkdownish(label, { format: this.format(colored), paragraphs: false }), cli2.replace(/\$0/g, this.binaryName)]) : void 0;
|
|
2258
|
+
return { path: path2, usage, category, description, details, examples, options };
|
|
2259
|
+
}
|
|
2260
|
+
definitions({ colored = false } = {}) {
|
|
2261
|
+
const data = [];
|
|
2262
|
+
for (const commandClass of this.registrations.keys()) {
|
|
2263
|
+
const usage = this.definition(commandClass, { colored });
|
|
2264
|
+
if (!usage)
|
|
2265
|
+
continue;
|
|
2266
|
+
data.push(usage);
|
|
2267
|
+
}
|
|
2268
|
+
return data;
|
|
2269
|
+
}
|
|
2270
|
+
usage(command = null, { colored, detailed = false, prefix = `$ ` } = {}) {
|
|
2271
|
+
var _a;
|
|
2272
|
+
if (command === null) {
|
|
2273
|
+
for (const commandClass2 of this.registrations.keys()) {
|
|
2274
|
+
const paths = commandClass2.paths;
|
|
2275
|
+
const isDocumented = typeof commandClass2.usage !== `undefined`;
|
|
2276
|
+
const isExclusivelyDefault = !paths || paths.length === 0 || paths.length === 1 && paths[0].length === 0;
|
|
2277
|
+
const isDefault = isExclusivelyDefault || ((_a = paths === null || paths === void 0 ? void 0 : paths.some((path2) => path2.length === 0)) !== null && _a !== void 0 ? _a : false);
|
|
2278
|
+
if (isDefault) {
|
|
2279
|
+
if (command) {
|
|
2280
|
+
command = null;
|
|
2281
|
+
break;
|
|
2282
|
+
} else {
|
|
2283
|
+
command = commandClass2;
|
|
2284
|
+
}
|
|
2285
|
+
} else {
|
|
2286
|
+
if (isDocumented) {
|
|
2287
|
+
command = null;
|
|
2288
|
+
continue;
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
if (command) {
|
|
2293
|
+
detailed = true;
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
const commandClass = command !== null && command instanceof Command ? command.constructor : command;
|
|
2297
|
+
let result = ``;
|
|
2298
|
+
if (!commandClass) {
|
|
2299
|
+
const commandsByCategories = /* @__PURE__ */ new Map();
|
|
2300
|
+
for (const [commandClass2, { index }] of this.registrations.entries()) {
|
|
2301
|
+
if (typeof commandClass2.usage === `undefined`)
|
|
2302
|
+
continue;
|
|
2303
|
+
const category = typeof commandClass2.usage.category !== `undefined` ? formatMarkdownish(commandClass2.usage.category, { format: this.format(colored), paragraphs: false }) : null;
|
|
2304
|
+
let categoryCommands = commandsByCategories.get(category);
|
|
2305
|
+
if (typeof categoryCommands === `undefined`)
|
|
2306
|
+
commandsByCategories.set(category, categoryCommands = []);
|
|
2307
|
+
const { usage } = this.getUsageByIndex(index);
|
|
2308
|
+
categoryCommands.push({ commandClass: commandClass2, usage });
|
|
2309
|
+
}
|
|
2310
|
+
const categoryNames = Array.from(commandsByCategories.keys()).sort((a, b) => {
|
|
2311
|
+
if (a === null)
|
|
2312
|
+
return -1;
|
|
2313
|
+
if (b === null)
|
|
2314
|
+
return 1;
|
|
2315
|
+
return a.localeCompare(b, `en`, { usage: `sort`, caseFirst: `upper` });
|
|
2316
|
+
});
|
|
2317
|
+
const hasLabel = typeof this.binaryLabel !== `undefined`;
|
|
2318
|
+
const hasVersion = typeof this.binaryVersion !== `undefined`;
|
|
2319
|
+
if (hasLabel || hasVersion) {
|
|
2320
|
+
if (hasLabel && hasVersion)
|
|
2321
|
+
result += `${this.format(colored).header(`${this.binaryLabel} - ${this.binaryVersion}`)}
|
|
2322
|
+
|
|
2323
|
+
`;
|
|
2324
|
+
else if (hasLabel)
|
|
2325
|
+
result += `${this.format(colored).header(`${this.binaryLabel}`)}
|
|
2326
|
+
`;
|
|
2327
|
+
else
|
|
2328
|
+
result += `${this.format(colored).header(`${this.binaryVersion}`)}
|
|
2329
|
+
`;
|
|
2330
|
+
result += ` ${this.format(colored).bold(prefix)}${this.binaryName} <command>
|
|
2331
|
+
`;
|
|
2332
|
+
} else {
|
|
2333
|
+
result += `${this.format(colored).bold(prefix)}${this.binaryName} <command>
|
|
2334
|
+
`;
|
|
2335
|
+
}
|
|
2336
|
+
for (const categoryName of categoryNames) {
|
|
2337
|
+
const commands = commandsByCategories.get(categoryName).slice().sort((a, b) => {
|
|
2338
|
+
return a.usage.localeCompare(b.usage, `en`, { usage: `sort`, caseFirst: `upper` });
|
|
2339
|
+
});
|
|
2340
|
+
const header = categoryName !== null ? categoryName.trim() : `General commands`;
|
|
2341
|
+
result += `
|
|
2342
|
+
`;
|
|
2343
|
+
result += `${this.format(colored).header(`${header}`)}
|
|
2344
|
+
`;
|
|
2345
|
+
for (const { commandClass: commandClass2, usage } of commands) {
|
|
2346
|
+
const doc = commandClass2.usage.description || `undocumented`;
|
|
2347
|
+
result += `
|
|
2348
|
+
`;
|
|
2349
|
+
result += ` ${this.format(colored).bold(usage)}
|
|
2350
|
+
`;
|
|
2351
|
+
result += ` ${formatMarkdownish(doc, { format: this.format(colored), paragraphs: false })}`;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
result += `
|
|
2355
|
+
`;
|
|
2356
|
+
result += formatMarkdownish(`You can also print more details about any of these commands by calling them with the \`-h,--help\` flag right after the command name.`, { format: this.format(colored), paragraphs: true });
|
|
2357
|
+
} else {
|
|
2358
|
+
if (!detailed) {
|
|
2359
|
+
const { usage } = this.getUsageByRegistration(commandClass);
|
|
2360
|
+
result += `${this.format(colored).bold(prefix)}${usage}
|
|
2361
|
+
`;
|
|
2362
|
+
} else {
|
|
2363
|
+
const { description = ``, details = ``, examples = [] } = commandClass.usage || {};
|
|
2364
|
+
if (description !== ``) {
|
|
2365
|
+
result += formatMarkdownish(description, { format: this.format(colored), paragraphs: false }).replace(/^./, ($0) => $0.toUpperCase());
|
|
2366
|
+
result += `
|
|
2367
|
+
`;
|
|
2368
|
+
}
|
|
2369
|
+
if (details !== `` || examples.length > 0) {
|
|
2370
|
+
result += `${this.format(colored).header(`Usage`)}
|
|
2371
|
+
`;
|
|
2372
|
+
result += `
|
|
2373
|
+
`;
|
|
2374
|
+
}
|
|
2375
|
+
const { usage, options } = this.getUsageByRegistration(commandClass, { inlineOptions: false });
|
|
2376
|
+
result += `${this.format(colored).bold(prefix)}${usage}
|
|
2377
|
+
`;
|
|
2378
|
+
if (options.length > 0) {
|
|
2379
|
+
result += `
|
|
2380
|
+
`;
|
|
2381
|
+
result += `${this.format(colored).header(`Options`)}
|
|
2382
|
+
`;
|
|
2383
|
+
const maxDefinitionLength = options.reduce((length, option) => {
|
|
2384
|
+
return Math.max(length, option.definition.length);
|
|
2385
|
+
}, 0);
|
|
2386
|
+
result += `
|
|
2387
|
+
`;
|
|
2388
|
+
for (const { definition, description: description2 } of options) {
|
|
2389
|
+
result += ` ${this.format(colored).bold(definition.padEnd(maxDefinitionLength))} ${formatMarkdownish(description2, { format: this.format(colored), paragraphs: false })}`;
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
if (details !== ``) {
|
|
2393
|
+
result += `
|
|
2394
|
+
`;
|
|
2395
|
+
result += `${this.format(colored).header(`Details`)}
|
|
2396
|
+
`;
|
|
2397
|
+
result += `
|
|
2398
|
+
`;
|
|
2399
|
+
result += formatMarkdownish(details, { format: this.format(colored), paragraphs: true });
|
|
2400
|
+
}
|
|
2401
|
+
if (examples.length > 0) {
|
|
2402
|
+
result += `
|
|
2403
|
+
`;
|
|
2404
|
+
result += `${this.format(colored).header(`Examples`)}
|
|
2405
|
+
`;
|
|
2406
|
+
for (const [description2, example] of examples) {
|
|
2407
|
+
result += `
|
|
2408
|
+
`;
|
|
2409
|
+
result += formatMarkdownish(description2, { format: this.format(colored), paragraphs: false });
|
|
2410
|
+
result += `${example.replace(/^/m, ` ${this.format(colored).bold(prefix)}`).replace(/\$0/g, this.binaryName)}
|
|
2411
|
+
`;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
return result;
|
|
2417
|
+
}
|
|
2418
|
+
error(error, _a) {
|
|
2419
|
+
var _b;
|
|
2420
|
+
var { colored, command = (_b = error[errorCommandSymbol]) !== null && _b !== void 0 ? _b : null } = _a === void 0 ? {} : _a;
|
|
2421
|
+
if (!error || typeof error !== `object` || !(`stack` in error))
|
|
2422
|
+
error = new Error(`Execution failed with a non-error rejection (rejected value: ${JSON.stringify(error)})`);
|
|
2423
|
+
let result = ``;
|
|
2424
|
+
let name = error.name.replace(/([a-z])([A-Z])/g, `$1 $2`);
|
|
2425
|
+
if (name === `Error`)
|
|
2426
|
+
name = `Internal Error`;
|
|
2427
|
+
result += `${this.format(colored).error(name)}: ${error.message}
|
|
2428
|
+
`;
|
|
2429
|
+
const meta = error.clipanion;
|
|
2430
|
+
if (typeof meta !== `undefined`) {
|
|
2431
|
+
if (meta.type === `usage`) {
|
|
2432
|
+
result += `
|
|
2433
|
+
`;
|
|
2434
|
+
result += this.usage(command);
|
|
2435
|
+
}
|
|
2436
|
+
} else {
|
|
2437
|
+
if (error.stack) {
|
|
2438
|
+
result += `${error.stack.replace(/^.*\n/, ``)}
|
|
2439
|
+
`;
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
return result;
|
|
2443
|
+
}
|
|
2444
|
+
format(colored) {
|
|
2445
|
+
var _a;
|
|
2446
|
+
return ((_a = colored !== null && colored !== void 0 ? colored : this.enableColors) !== null && _a !== void 0 ? _a : _Cli.defaultContext.colorDepth > 1) ? richFormat : textFormat;
|
|
2447
|
+
}
|
|
2448
|
+
getUsageByRegistration(klass, opts) {
|
|
2449
|
+
const record = this.registrations.get(klass);
|
|
2450
|
+
if (typeof record === `undefined`)
|
|
2451
|
+
throw new Error(`Assertion failed: Unregistered command`);
|
|
2452
|
+
return this.getUsageByIndex(record.index, opts);
|
|
2453
|
+
}
|
|
2454
|
+
getUsageByIndex(n, opts) {
|
|
2455
|
+
return this.builder.getBuilderByIndex(n).usage(opts);
|
|
2456
|
+
}
|
|
2457
|
+
};
|
|
2458
|
+
Cli.defaultContext = {
|
|
2459
|
+
env: process.env,
|
|
2460
|
+
stdin: process.stdin,
|
|
2461
|
+
stdout: process.stdout,
|
|
2462
|
+
stderr: process.stderr,
|
|
2463
|
+
colorDepth: getDefaultColorDepth()
|
|
2464
|
+
};
|
|
2465
|
+
function noopCaptureActivator(fn) {
|
|
2466
|
+
return fn();
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
// src/commands/DevCommand.ts
|
|
2470
|
+
init_cjs_shims();
|
|
2471
|
+
|
|
2472
|
+
// ../../.yarn/__virtual__/@hono-node-server-virtual-cf2888014c/0/cache/@hono-node-server-npm-1.13.8-e78cfff928-5880892fdd.zip/node_modules/@hono/node-server/dist/index.mjs
|
|
2473
|
+
init_cjs_shims();
|
|
2474
|
+
var import_http = require("http");
|
|
2475
|
+
var import_http2 = require("http2");
|
|
2476
|
+
var import_stream = require("stream");
|
|
2477
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
2478
|
+
var RequestError = class extends Error {
|
|
2479
|
+
static name = "RequestError";
|
|
2480
|
+
constructor(message, options) {
|
|
2481
|
+
super(message, options);
|
|
2482
|
+
}
|
|
2483
|
+
};
|
|
2484
|
+
var toRequestError = (e) => {
|
|
2485
|
+
if (e instanceof RequestError) {
|
|
2486
|
+
return e;
|
|
2487
|
+
}
|
|
2488
|
+
return new RequestError(e.message, { cause: e });
|
|
2489
|
+
};
|
|
2490
|
+
var GlobalRequest = global.Request;
|
|
2491
|
+
var Request2 = class extends GlobalRequest {
|
|
2492
|
+
constructor(input, options) {
|
|
2493
|
+
if (typeof input === "object" && getRequestCache in input) {
|
|
2494
|
+
input = input[getRequestCache]();
|
|
2495
|
+
}
|
|
2496
|
+
if (typeof options?.body?.getReader !== "undefined") {
|
|
2497
|
+
;
|
|
2498
|
+
options.duplex ??= "half";
|
|
2499
|
+
}
|
|
2500
|
+
super(input, options);
|
|
2501
|
+
}
|
|
2502
|
+
};
|
|
2503
|
+
var newRequestFromIncoming = (method, url, incoming, abortController) => {
|
|
2504
|
+
const headerRecord = [];
|
|
2505
|
+
const rawHeaders = incoming.rawHeaders;
|
|
2506
|
+
for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
2507
|
+
const { [i]: key, [i + 1]: value } = rawHeaders;
|
|
2508
|
+
if (key.charCodeAt(0) !== /*:*/
|
|
2509
|
+
58) {
|
|
2510
|
+
headerRecord.push([key, value]);
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
const init = {
|
|
2514
|
+
method,
|
|
2515
|
+
headers: headerRecord,
|
|
2516
|
+
signal: abortController.signal
|
|
2517
|
+
};
|
|
2518
|
+
if (method === "TRACE") {
|
|
2519
|
+
init.method = "GET";
|
|
2520
|
+
const req = new Request2(url, init);
|
|
2521
|
+
Object.defineProperty(req, "method", {
|
|
2522
|
+
get() {
|
|
2523
|
+
return "TRACE";
|
|
2524
|
+
}
|
|
2525
|
+
});
|
|
2526
|
+
return req;
|
|
2527
|
+
}
|
|
2528
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
2529
|
+
if ("rawBody" in incoming && incoming.rawBody instanceof Buffer) {
|
|
2530
|
+
init.body = new ReadableStream({
|
|
2531
|
+
start(controller) {
|
|
2532
|
+
controller.enqueue(incoming.rawBody);
|
|
2533
|
+
controller.close();
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
} else {
|
|
2537
|
+
init.body = import_stream.Readable.toWeb(incoming);
|
|
2538
|
+
}
|
|
2539
|
+
}
|
|
2540
|
+
return new Request2(url, init);
|
|
2541
|
+
};
|
|
2542
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
2543
|
+
var requestCache = Symbol("requestCache");
|
|
2544
|
+
var incomingKey = Symbol("incomingKey");
|
|
2545
|
+
var urlKey = Symbol("urlKey");
|
|
2546
|
+
var abortControllerKey = Symbol("abortControllerKey");
|
|
2547
|
+
var getAbortController = Symbol("getAbortController");
|
|
2548
|
+
var requestPrototype = {
|
|
2549
|
+
get method() {
|
|
2550
|
+
return this[incomingKey].method || "GET";
|
|
2551
|
+
},
|
|
2552
|
+
get url() {
|
|
2553
|
+
return this[urlKey];
|
|
2554
|
+
},
|
|
2555
|
+
[getAbortController]() {
|
|
2556
|
+
this[getRequestCache]();
|
|
2557
|
+
return this[abortControllerKey];
|
|
2558
|
+
},
|
|
2559
|
+
[getRequestCache]() {
|
|
2560
|
+
this[abortControllerKey] ||= new AbortController();
|
|
2561
|
+
return this[requestCache] ||= newRequestFromIncoming(
|
|
2562
|
+
this.method,
|
|
2563
|
+
this[urlKey],
|
|
2564
|
+
this[incomingKey],
|
|
2565
|
+
this[abortControllerKey]
|
|
2566
|
+
);
|
|
2567
|
+
}
|
|
2568
|
+
};
|
|
2569
|
+
[
|
|
2570
|
+
"body",
|
|
2571
|
+
"bodyUsed",
|
|
2572
|
+
"cache",
|
|
2573
|
+
"credentials",
|
|
2574
|
+
"destination",
|
|
2575
|
+
"headers",
|
|
2576
|
+
"integrity",
|
|
2577
|
+
"mode",
|
|
2578
|
+
"redirect",
|
|
2579
|
+
"referrer",
|
|
2580
|
+
"referrerPolicy",
|
|
2581
|
+
"signal",
|
|
2582
|
+
"keepalive"
|
|
2583
|
+
].forEach((k) => {
|
|
2584
|
+
Object.defineProperty(requestPrototype, k, {
|
|
2585
|
+
get() {
|
|
2586
|
+
return this[getRequestCache]()[k];
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
});
|
|
2590
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
2591
|
+
Object.defineProperty(requestPrototype, k, {
|
|
2592
|
+
value: function() {
|
|
2593
|
+
return this[getRequestCache]()[k]();
|
|
2594
|
+
}
|
|
2595
|
+
});
|
|
2596
|
+
});
|
|
2597
|
+
Object.setPrototypeOf(requestPrototype, Request2.prototype);
|
|
2598
|
+
var newRequest = (incoming, defaultHostname) => {
|
|
2599
|
+
const req = Object.create(requestPrototype);
|
|
2600
|
+
req[incomingKey] = incoming;
|
|
2601
|
+
const host = (incoming instanceof import_http2.Http2ServerRequest ? incoming.authority : incoming.headers.host) || defaultHostname;
|
|
2602
|
+
if (!host) {
|
|
2603
|
+
throw new RequestError("Missing host header");
|
|
2604
|
+
}
|
|
2605
|
+
const url = new URL(
|
|
2606
|
+
`${incoming instanceof import_http2.Http2ServerRequest || incoming.socket && incoming.socket.encrypted ? "https" : "http"}://${host}${incoming.url}`
|
|
2607
|
+
);
|
|
2608
|
+
if (url.hostname.length !== host.length && url.hostname !== host.replace(/:\d+$/, "")) {
|
|
2609
|
+
throw new RequestError("Invalid host header");
|
|
2610
|
+
}
|
|
2611
|
+
req[urlKey] = url.href;
|
|
2612
|
+
return req;
|
|
2613
|
+
};
|
|
2614
|
+
function writeFromReadableStream(stream, writable) {
|
|
2615
|
+
if (stream.locked) {
|
|
2616
|
+
throw new TypeError("ReadableStream is locked.");
|
|
2617
|
+
} else if (writable.destroyed) {
|
|
2618
|
+
stream.cancel();
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
const reader = stream.getReader();
|
|
2622
|
+
writable.on("close", cancel);
|
|
2623
|
+
writable.on("error", cancel);
|
|
2624
|
+
reader.read().then(flow, cancel);
|
|
2625
|
+
return reader.closed.finally(() => {
|
|
2626
|
+
writable.off("close", cancel);
|
|
2627
|
+
writable.off("error", cancel);
|
|
2628
|
+
});
|
|
2629
|
+
function cancel(error) {
|
|
2630
|
+
reader.cancel(error).catch(() => {
|
|
2631
|
+
});
|
|
2632
|
+
if (error) {
|
|
2633
|
+
writable.destroy(error);
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
function onDrain() {
|
|
2637
|
+
reader.read().then(flow, cancel);
|
|
2638
|
+
}
|
|
2639
|
+
function flow({ done, value }) {
|
|
2640
|
+
try {
|
|
2641
|
+
if (done) {
|
|
2642
|
+
writable.end();
|
|
2643
|
+
} else if (!writable.write(value)) {
|
|
2644
|
+
writable.once("drain", onDrain);
|
|
2645
|
+
} else {
|
|
2646
|
+
return reader.read().then(flow, cancel);
|
|
2647
|
+
}
|
|
2648
|
+
} catch (e) {
|
|
2649
|
+
cancel(e);
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
var buildOutgoingHttpHeaders = (headers) => {
|
|
2654
|
+
const res = {};
|
|
2655
|
+
if (!(headers instanceof Headers)) {
|
|
2656
|
+
headers = new Headers(headers ?? void 0);
|
|
2657
|
+
}
|
|
2658
|
+
const cookies = [];
|
|
2659
|
+
for (const [k, v] of headers) {
|
|
2660
|
+
if (k === "set-cookie") {
|
|
2661
|
+
cookies.push(v);
|
|
2662
|
+
} else {
|
|
2663
|
+
res[k] = v;
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2666
|
+
if (cookies.length > 0) {
|
|
2667
|
+
res["set-cookie"] = cookies;
|
|
2668
|
+
}
|
|
2669
|
+
res["content-type"] ??= "text/plain; charset=UTF-8";
|
|
2670
|
+
return res;
|
|
2671
|
+
};
|
|
2672
|
+
var responseCache = Symbol("responseCache");
|
|
2673
|
+
var getResponseCache = Symbol("getResponseCache");
|
|
2674
|
+
var cacheKey = Symbol("cache");
|
|
2675
|
+
var GlobalResponse = global.Response;
|
|
2676
|
+
var Response2 = class _Response {
|
|
2677
|
+
#body;
|
|
2678
|
+
#init;
|
|
2679
|
+
[getResponseCache]() {
|
|
2680
|
+
delete this[cacheKey];
|
|
2681
|
+
return this[responseCache] ||= new GlobalResponse(this.#body, this.#init);
|
|
2682
|
+
}
|
|
2683
|
+
constructor(body, init) {
|
|
2684
|
+
this.#body = body;
|
|
2685
|
+
if (init instanceof _Response) {
|
|
2686
|
+
const cachedGlobalResponse = init[responseCache];
|
|
2687
|
+
if (cachedGlobalResponse) {
|
|
2688
|
+
this.#init = cachedGlobalResponse;
|
|
2689
|
+
this[getResponseCache]();
|
|
2690
|
+
return;
|
|
2691
|
+
} else {
|
|
2692
|
+
this.#init = init.#init;
|
|
2693
|
+
}
|
|
2694
|
+
} else {
|
|
2695
|
+
this.#init = init;
|
|
2696
|
+
}
|
|
2697
|
+
if (typeof body === "string" || typeof body?.getReader !== "undefined") {
|
|
2698
|
+
let headers = init?.headers || { "content-type": "text/plain; charset=UTF-8" };
|
|
2699
|
+
if (headers instanceof Headers) {
|
|
2700
|
+
headers = buildOutgoingHttpHeaders(headers);
|
|
2701
|
+
}
|
|
2702
|
+
;
|
|
2703
|
+
this[cacheKey] = [init?.status || 200, body, headers];
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
};
|
|
2707
|
+
[
|
|
2708
|
+
"body",
|
|
2709
|
+
"bodyUsed",
|
|
2710
|
+
"headers",
|
|
2711
|
+
"ok",
|
|
2712
|
+
"redirected",
|
|
2713
|
+
"status",
|
|
2714
|
+
"statusText",
|
|
2715
|
+
"trailers",
|
|
2716
|
+
"type",
|
|
2717
|
+
"url"
|
|
2718
|
+
].forEach((k) => {
|
|
2719
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
2720
|
+
get() {
|
|
2721
|
+
return this[getResponseCache]()[k];
|
|
2722
|
+
}
|
|
2723
|
+
});
|
|
2724
|
+
});
|
|
2725
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
2726
|
+
Object.defineProperty(Response2.prototype, k, {
|
|
2727
|
+
value: function() {
|
|
2728
|
+
return this[getResponseCache]()[k]();
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
});
|
|
2732
|
+
Object.setPrototypeOf(Response2, GlobalResponse);
|
|
2733
|
+
Object.setPrototypeOf(Response2.prototype, GlobalResponse.prototype);
|
|
2734
|
+
var stateKey = Reflect.ownKeys(new GlobalResponse()).find(
|
|
2735
|
+
(k) => typeof k === "symbol" && k.toString() === "Symbol(state)"
|
|
2736
|
+
);
|
|
2737
|
+
if (!stateKey) {
|
|
2738
|
+
console.warn("Failed to find Response internal state key");
|
|
2739
|
+
}
|
|
2740
|
+
function getInternalBody(response) {
|
|
2741
|
+
if (!stateKey) {
|
|
2742
|
+
return;
|
|
2743
|
+
}
|
|
2744
|
+
if (response instanceof Response2) {
|
|
2745
|
+
response = response[getResponseCache]();
|
|
2746
|
+
}
|
|
2747
|
+
const state = response[stateKey];
|
|
2748
|
+
return state && state.body || void 0;
|
|
2749
|
+
}
|
|
2750
|
+
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
2751
|
+
var webFetch = global.fetch;
|
|
2752
|
+
if (typeof global.crypto === "undefined") {
|
|
2753
|
+
global.crypto = import_crypto.default;
|
|
2754
|
+
}
|
|
2755
|
+
global.fetch = (info, init) => {
|
|
2756
|
+
init = {
|
|
2757
|
+
// Disable compression handling so people can return the result of a fetch
|
|
2758
|
+
// directly in the loader without messing with the Content-Encoding header.
|
|
2759
|
+
compress: false,
|
|
2760
|
+
...init
|
|
2761
|
+
};
|
|
2762
|
+
return webFetch(info, init);
|
|
2763
|
+
};
|
|
2764
|
+
var regBuffer = /^no$/i;
|
|
2765
|
+
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
2766
|
+
var handleRequestError = () => new Response(null, {
|
|
2767
|
+
status: 400
|
|
2768
|
+
});
|
|
2769
|
+
var handleFetchError = (e) => new Response(null, {
|
|
2770
|
+
status: e instanceof Error && (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") ? 504 : 500
|
|
2771
|
+
});
|
|
2772
|
+
var handleResponseError = (e, outgoing) => {
|
|
2773
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
2774
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
2775
|
+
console.info("The user aborted a request.");
|
|
2776
|
+
} else {
|
|
2777
|
+
console.error(e);
|
|
2778
|
+
if (!outgoing.headersSent) {
|
|
2779
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
2780
|
+
}
|
|
2781
|
+
outgoing.end(`Error: ${err.message}`);
|
|
2782
|
+
outgoing.destroy(err);
|
|
2783
|
+
}
|
|
2784
|
+
};
|
|
2785
|
+
var responseViaCache = (res, outgoing) => {
|
|
2786
|
+
const [status, body, header] = res[cacheKey];
|
|
2787
|
+
if (typeof body === "string") {
|
|
2788
|
+
header["Content-Length"] = Buffer.byteLength(body);
|
|
2789
|
+
outgoing.writeHead(status, header);
|
|
2790
|
+
outgoing.end(body);
|
|
2791
|
+
} else {
|
|
2792
|
+
outgoing.writeHead(status, header);
|
|
2793
|
+
return writeFromReadableStream(body, outgoing)?.catch(
|
|
2794
|
+
(e) => handleResponseError(e, outgoing)
|
|
2795
|
+
);
|
|
2796
|
+
}
|
|
2797
|
+
};
|
|
2798
|
+
var responseViaResponseObject = async (res, outgoing, options = {}) => {
|
|
2799
|
+
if (res instanceof Promise) {
|
|
2800
|
+
if (options.errorHandler) {
|
|
2801
|
+
try {
|
|
2802
|
+
res = await res;
|
|
2803
|
+
} catch (err) {
|
|
2804
|
+
const errRes = await options.errorHandler(err);
|
|
2805
|
+
if (!errRes) {
|
|
2806
|
+
return;
|
|
2807
|
+
}
|
|
2808
|
+
res = errRes;
|
|
2809
|
+
}
|
|
2810
|
+
} else {
|
|
2811
|
+
res = await res.catch(handleFetchError);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
if (cacheKey in res) {
|
|
2815
|
+
return responseViaCache(res, outgoing);
|
|
2816
|
+
}
|
|
2817
|
+
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
2818
|
+
const internalBody = getInternalBody(res);
|
|
2819
|
+
if (internalBody) {
|
|
2820
|
+
const { length, source, stream } = internalBody;
|
|
2821
|
+
if (source instanceof Uint8Array && source.byteLength !== length) {
|
|
2822
|
+
} else {
|
|
2823
|
+
if (length) {
|
|
2824
|
+
resHeaderRecord["content-length"] = length;
|
|
2825
|
+
}
|
|
2826
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
2827
|
+
if (typeof source === "string" || source instanceof Uint8Array) {
|
|
2828
|
+
outgoing.end(source);
|
|
2829
|
+
} else if (source instanceof Blob) {
|
|
2830
|
+
outgoing.end(new Uint8Array(await source.arrayBuffer()));
|
|
2831
|
+
} else {
|
|
2832
|
+
await writeFromReadableStream(stream, outgoing);
|
|
2833
|
+
}
|
|
2834
|
+
return;
|
|
2835
|
+
}
|
|
2836
|
+
}
|
|
2837
|
+
if (res.body) {
|
|
2838
|
+
const {
|
|
2839
|
+
"transfer-encoding": transferEncoding,
|
|
2840
|
+
"content-encoding": contentEncoding,
|
|
2841
|
+
"content-length": contentLength,
|
|
2842
|
+
"x-accel-buffering": accelBuffering,
|
|
2843
|
+
"content-type": contentType
|
|
2844
|
+
} = resHeaderRecord;
|
|
2845
|
+
if (transferEncoding || contentEncoding || contentLength || // nginx buffering variant
|
|
2846
|
+
accelBuffering && regBuffer.test(accelBuffering) || !regContentType.test(contentType)) {
|
|
2847
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
2848
|
+
await writeFromReadableStream(res.body, outgoing);
|
|
2849
|
+
} else {
|
|
2850
|
+
const buffer = await res.arrayBuffer();
|
|
2851
|
+
resHeaderRecord["content-length"] = buffer.byteLength;
|
|
2852
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
2853
|
+
outgoing.end(new Uint8Array(buffer));
|
|
2854
|
+
}
|
|
2855
|
+
} else if (resHeaderRecord[X_ALREADY_SENT]) {
|
|
2856
|
+
} else {
|
|
2857
|
+
outgoing.writeHead(res.status, resHeaderRecord);
|
|
2858
|
+
outgoing.end();
|
|
2859
|
+
}
|
|
2860
|
+
};
|
|
2861
|
+
var getRequestListener = (fetchCallback, options = {}) => {
|
|
2862
|
+
if (options.overrideGlobalObjects !== false && global.Request !== Request2) {
|
|
2863
|
+
Object.defineProperty(global, "Request", {
|
|
2864
|
+
value: Request2
|
|
2865
|
+
});
|
|
2866
|
+
Object.defineProperty(global, "Response", {
|
|
2867
|
+
value: Response2
|
|
2868
|
+
});
|
|
2869
|
+
}
|
|
2870
|
+
return async (incoming, outgoing) => {
|
|
2871
|
+
let res, req;
|
|
2872
|
+
try {
|
|
2873
|
+
req = newRequest(incoming, options.hostname);
|
|
2874
|
+
outgoing.on("close", () => {
|
|
2875
|
+
const abortController = req[abortControllerKey];
|
|
2876
|
+
if (!abortController) {
|
|
2877
|
+
return;
|
|
2878
|
+
}
|
|
2879
|
+
if (incoming.errored) {
|
|
2880
|
+
req[abortControllerKey].abort(incoming.errored.toString());
|
|
2881
|
+
} else if (!outgoing.writableFinished) {
|
|
2882
|
+
req[abortControllerKey].abort("Client connection prematurely closed.");
|
|
2883
|
+
}
|
|
2884
|
+
});
|
|
2885
|
+
res = fetchCallback(req, { incoming, outgoing });
|
|
2886
|
+
if (cacheKey in res) {
|
|
2887
|
+
return responseViaCache(res, outgoing);
|
|
2888
|
+
}
|
|
2889
|
+
} catch (e) {
|
|
2890
|
+
if (!res) {
|
|
2891
|
+
if (options.errorHandler) {
|
|
2892
|
+
res = await options.errorHandler(req ? e : toRequestError(e));
|
|
2893
|
+
if (!res) {
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2896
|
+
} else if (!req) {
|
|
2897
|
+
res = handleRequestError();
|
|
2898
|
+
} else {
|
|
2899
|
+
res = handleFetchError(e);
|
|
2900
|
+
}
|
|
2901
|
+
} else {
|
|
2902
|
+
return handleResponseError(e, outgoing);
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
try {
|
|
2906
|
+
return responseViaResponseObject(res, outgoing, options);
|
|
2907
|
+
} catch (e) {
|
|
2908
|
+
return handleResponseError(e, outgoing);
|
|
2909
|
+
}
|
|
2910
|
+
};
|
|
2911
|
+
};
|
|
2912
|
+
var createAdaptorServer = (options) => {
|
|
2913
|
+
const fetchCallback = options.fetch;
|
|
2914
|
+
const requestListener = getRequestListener(fetchCallback, {
|
|
2915
|
+
hostname: options.hostname,
|
|
2916
|
+
overrideGlobalObjects: options.overrideGlobalObjects
|
|
2917
|
+
});
|
|
2918
|
+
const createServer = options.createServer || import_http.createServer;
|
|
2919
|
+
const server = createServer(options.serverOptions || {}, requestListener);
|
|
2920
|
+
return server;
|
|
2921
|
+
};
|
|
2922
|
+
var serve = (options, listeningListener) => {
|
|
2923
|
+
const server = createAdaptorServer(options);
|
|
2924
|
+
server.listen(options?.port ?? 3e3, options.hostname, () => {
|
|
2925
|
+
const serverInfo = server.address();
|
|
2926
|
+
listeningListener && listeningListener(serverInfo);
|
|
2927
|
+
});
|
|
2928
|
+
return server;
|
|
2929
|
+
};
|
|
2930
|
+
|
|
2931
|
+
// src/server.ts
|
|
2932
|
+
init_cjs_shims();
|
|
2933
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
2934
|
+
var import_path = __toESM(require("path"), 1);
|
|
2935
|
+
var import_core2 = require("@babel/core");
|
|
2936
|
+
|
|
2937
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/index.js
|
|
2938
|
+
init_cjs_shims();
|
|
2939
|
+
|
|
2940
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/hono.js
|
|
2941
|
+
init_cjs_shims();
|
|
2942
|
+
|
|
2943
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/hono-base.js
|
|
2944
|
+
init_cjs_shims();
|
|
2945
|
+
|
|
2946
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/compose.js
|
|
2947
|
+
init_cjs_shims();
|
|
2948
|
+
var compose = (middleware, onError, onNotFound) => {
|
|
2949
|
+
return (context, next) => {
|
|
2950
|
+
let index = -1;
|
|
2951
|
+
return dispatch(0);
|
|
2952
|
+
async function dispatch(i) {
|
|
2953
|
+
if (i <= index) {
|
|
2954
|
+
throw new Error("next() called multiple times");
|
|
2955
|
+
}
|
|
2956
|
+
index = i;
|
|
2957
|
+
let res;
|
|
2958
|
+
let isError = false;
|
|
2959
|
+
let handler;
|
|
2960
|
+
if (middleware[i]) {
|
|
2961
|
+
handler = middleware[i][0][0];
|
|
2962
|
+
context.req.routeIndex = i;
|
|
2963
|
+
} else {
|
|
2964
|
+
handler = i === middleware.length && next || void 0;
|
|
2965
|
+
}
|
|
2966
|
+
if (handler) {
|
|
2967
|
+
try {
|
|
2968
|
+
res = await handler(context, () => dispatch(i + 1));
|
|
2969
|
+
} catch (err) {
|
|
2970
|
+
if (err instanceof Error && onError) {
|
|
2971
|
+
context.error = err;
|
|
2972
|
+
res = await onError(err, context);
|
|
2973
|
+
isError = true;
|
|
2974
|
+
} else {
|
|
2975
|
+
throw err;
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
} else {
|
|
2979
|
+
if (context.finalized === false && onNotFound) {
|
|
2980
|
+
res = await onNotFound(context);
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
if (res && (context.finalized === false || isError)) {
|
|
2984
|
+
context.res = res;
|
|
2985
|
+
}
|
|
2986
|
+
return context;
|
|
2987
|
+
}
|
|
2988
|
+
};
|
|
2989
|
+
};
|
|
2990
|
+
|
|
2991
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/context.js
|
|
2992
|
+
init_cjs_shims();
|
|
2993
|
+
|
|
2994
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/request.js
|
|
2995
|
+
init_cjs_shims();
|
|
2996
|
+
|
|
2997
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/utils/body.js
|
|
2998
|
+
init_cjs_shims();
|
|
2999
|
+
var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) => {
|
|
3000
|
+
const { all = false, dot = false } = options;
|
|
3001
|
+
const headers = request instanceof HonoRequest ? request.raw.headers : request.headers;
|
|
3002
|
+
const contentType = headers.get("Content-Type");
|
|
3003
|
+
if (contentType?.startsWith("multipart/form-data") || contentType?.startsWith("application/x-www-form-urlencoded")) {
|
|
3004
|
+
return parseFormData(request, { all, dot });
|
|
3005
|
+
}
|
|
3006
|
+
return {};
|
|
3007
|
+
};
|
|
3008
|
+
async function parseFormData(request, options) {
|
|
3009
|
+
const formData = await request.formData();
|
|
3010
|
+
if (formData) {
|
|
3011
|
+
return convertFormDataToBodyData(formData, options);
|
|
3012
|
+
}
|
|
3013
|
+
return {};
|
|
3014
|
+
}
|
|
3015
|
+
function convertFormDataToBodyData(formData, options) {
|
|
3016
|
+
const form = /* @__PURE__ */ Object.create(null);
|
|
3017
|
+
formData.forEach((value, key) => {
|
|
3018
|
+
const shouldParseAllValues = options.all || key.endsWith("[]");
|
|
3019
|
+
if (!shouldParseAllValues) {
|
|
3020
|
+
form[key] = value;
|
|
3021
|
+
} else {
|
|
3022
|
+
handleParsingAllValues(form, key, value);
|
|
3023
|
+
}
|
|
3024
|
+
});
|
|
3025
|
+
if (options.dot) {
|
|
3026
|
+
Object.entries(form).forEach(([key, value]) => {
|
|
3027
|
+
const shouldParseDotValues = key.includes(".");
|
|
3028
|
+
if (shouldParseDotValues) {
|
|
3029
|
+
handleParsingNestedValues(form, key, value);
|
|
3030
|
+
delete form[key];
|
|
3031
|
+
}
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
return form;
|
|
3035
|
+
}
|
|
3036
|
+
var handleParsingAllValues = (form, key, value) => {
|
|
3037
|
+
if (form[key] !== void 0) {
|
|
3038
|
+
if (Array.isArray(form[key])) {
|
|
3039
|
+
;
|
|
3040
|
+
form[key].push(value);
|
|
3041
|
+
} else {
|
|
3042
|
+
form[key] = [form[key], value];
|
|
3043
|
+
}
|
|
3044
|
+
} else {
|
|
3045
|
+
form[key] = value;
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
var handleParsingNestedValues = (form, key, value) => {
|
|
3049
|
+
let nestedForm = form;
|
|
3050
|
+
const keys = key.split(".");
|
|
3051
|
+
keys.forEach((key2, index) => {
|
|
3052
|
+
if (index === keys.length - 1) {
|
|
3053
|
+
nestedForm[key2] = value;
|
|
3054
|
+
} else {
|
|
3055
|
+
if (!nestedForm[key2] || typeof nestedForm[key2] !== "object" || Array.isArray(nestedForm[key2]) || nestedForm[key2] instanceof File) {
|
|
3056
|
+
nestedForm[key2] = /* @__PURE__ */ Object.create(null);
|
|
3057
|
+
}
|
|
3058
|
+
nestedForm = nestedForm[key2];
|
|
3059
|
+
}
|
|
3060
|
+
});
|
|
3061
|
+
};
|
|
3062
|
+
|
|
3063
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/utils/url.js
|
|
3064
|
+
init_cjs_shims();
|
|
3065
|
+
var splitPath = (path2) => {
|
|
3066
|
+
const paths = path2.split("/");
|
|
3067
|
+
if (paths[0] === "") {
|
|
3068
|
+
paths.shift();
|
|
3069
|
+
}
|
|
3070
|
+
return paths;
|
|
3071
|
+
};
|
|
3072
|
+
var splitRoutingPath = (routePath) => {
|
|
3073
|
+
const { groups, path: path2 } = extractGroupsFromPath(routePath);
|
|
3074
|
+
const paths = splitPath(path2);
|
|
3075
|
+
return replaceGroupMarks(paths, groups);
|
|
3076
|
+
};
|
|
3077
|
+
var extractGroupsFromPath = (path2) => {
|
|
3078
|
+
const groups = [];
|
|
3079
|
+
path2 = path2.replace(/\{[^}]+\}/g, (match, index) => {
|
|
3080
|
+
const mark = `@${index}`;
|
|
3081
|
+
groups.push([mark, match]);
|
|
3082
|
+
return mark;
|
|
3083
|
+
});
|
|
3084
|
+
return { groups, path: path2 };
|
|
3085
|
+
};
|
|
3086
|
+
var replaceGroupMarks = (paths, groups) => {
|
|
3087
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
3088
|
+
const [mark] = groups[i];
|
|
3089
|
+
for (let j = paths.length - 1; j >= 0; j--) {
|
|
3090
|
+
if (paths[j].includes(mark)) {
|
|
3091
|
+
paths[j] = paths[j].replace(mark, groups[i][1]);
|
|
3092
|
+
break;
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
return paths;
|
|
3097
|
+
};
|
|
3098
|
+
var patternCache = {};
|
|
3099
|
+
var getPattern = (label, next) => {
|
|
3100
|
+
if (label === "*") {
|
|
3101
|
+
return "*";
|
|
3102
|
+
}
|
|
3103
|
+
const match = label.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
3104
|
+
if (match) {
|
|
3105
|
+
const cacheKey2 = `${label}#${next}`;
|
|
3106
|
+
if (!patternCache[cacheKey2]) {
|
|
3107
|
+
if (match[2]) {
|
|
3108
|
+
patternCache[cacheKey2] = next && next[0] !== ":" && next[0] !== "*" ? [cacheKey2, match[1], new RegExp(`^${match[2]}(?=/${next})`)] : [label, match[1], new RegExp(`^${match[2]}$`)];
|
|
3109
|
+
} else {
|
|
3110
|
+
patternCache[cacheKey2] = [label, match[1], true];
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
return patternCache[cacheKey2];
|
|
3114
|
+
}
|
|
3115
|
+
return null;
|
|
3116
|
+
};
|
|
3117
|
+
var tryDecode = (str, decoder) => {
|
|
3118
|
+
try {
|
|
3119
|
+
return decoder(str);
|
|
3120
|
+
} catch {
|
|
3121
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
3122
|
+
try {
|
|
3123
|
+
return decoder(match);
|
|
3124
|
+
} catch {
|
|
3125
|
+
return match;
|
|
3126
|
+
}
|
|
3127
|
+
});
|
|
3128
|
+
}
|
|
3129
|
+
};
|
|
3130
|
+
var tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
3131
|
+
var getPath = (request) => {
|
|
3132
|
+
const url = request.url;
|
|
3133
|
+
const start = url.indexOf("/", 8);
|
|
3134
|
+
let i = start;
|
|
3135
|
+
for (; i < url.length; i++) {
|
|
3136
|
+
const charCode = url.charCodeAt(i);
|
|
3137
|
+
if (charCode === 37) {
|
|
3138
|
+
const queryIndex = url.indexOf("?", i);
|
|
3139
|
+
const path2 = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
|
3140
|
+
return tryDecodeURI(path2.includes("%25") ? path2.replace(/%25/g, "%2525") : path2);
|
|
3141
|
+
} else if (charCode === 63) {
|
|
3142
|
+
break;
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
return url.slice(start, i);
|
|
3146
|
+
};
|
|
3147
|
+
var getPathNoStrict = (request) => {
|
|
3148
|
+
const result = getPath(request);
|
|
3149
|
+
return result.length > 1 && result.at(-1) === "/" ? result.slice(0, -1) : result;
|
|
3150
|
+
};
|
|
3151
|
+
var mergePath = (base, sub, ...rest) => {
|
|
3152
|
+
if (rest.length) {
|
|
3153
|
+
sub = mergePath(sub, ...rest);
|
|
3154
|
+
}
|
|
3155
|
+
return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
|
|
3156
|
+
};
|
|
3157
|
+
var checkOptionalParameter = (path2) => {
|
|
3158
|
+
if (path2.charCodeAt(path2.length - 1) !== 63 || !path2.includes(":")) {
|
|
3159
|
+
return null;
|
|
3160
|
+
}
|
|
3161
|
+
const segments = path2.split("/");
|
|
3162
|
+
const results = [];
|
|
3163
|
+
let basePath = "";
|
|
3164
|
+
segments.forEach((segment) => {
|
|
3165
|
+
if (segment !== "" && !/\:/.test(segment)) {
|
|
3166
|
+
basePath += "/" + segment;
|
|
3167
|
+
} else if (/\:/.test(segment)) {
|
|
3168
|
+
if (/\?/.test(segment)) {
|
|
3169
|
+
if (results.length === 0 && basePath === "") {
|
|
3170
|
+
results.push("/");
|
|
3171
|
+
} else {
|
|
3172
|
+
results.push(basePath);
|
|
3173
|
+
}
|
|
3174
|
+
const optionalSegment = segment.replace("?", "");
|
|
3175
|
+
basePath += "/" + optionalSegment;
|
|
3176
|
+
results.push(basePath);
|
|
3177
|
+
} else {
|
|
3178
|
+
basePath += "/" + segment;
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
});
|
|
3182
|
+
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
3183
|
+
};
|
|
3184
|
+
var _decodeURI = (value) => {
|
|
3185
|
+
if (!/[%+]/.test(value)) {
|
|
3186
|
+
return value;
|
|
3187
|
+
}
|
|
3188
|
+
if (value.indexOf("+") !== -1) {
|
|
3189
|
+
value = value.replace(/\+/g, " ");
|
|
3190
|
+
}
|
|
3191
|
+
return value.indexOf("%") !== -1 ? decodeURIComponent_(value) : value;
|
|
3192
|
+
};
|
|
3193
|
+
var _getQueryParam = (url, key, multiple) => {
|
|
3194
|
+
let encoded;
|
|
3195
|
+
if (!multiple && key && !/[%+]/.test(key)) {
|
|
3196
|
+
let keyIndex2 = url.indexOf(`?${key}`, 8);
|
|
3197
|
+
if (keyIndex2 === -1) {
|
|
3198
|
+
keyIndex2 = url.indexOf(`&${key}`, 8);
|
|
3199
|
+
}
|
|
3200
|
+
while (keyIndex2 !== -1) {
|
|
3201
|
+
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
|
3202
|
+
if (trailingKeyCode === 61) {
|
|
3203
|
+
const valueIndex = keyIndex2 + key.length + 2;
|
|
3204
|
+
const endIndex = url.indexOf("&", valueIndex);
|
|
3205
|
+
return _decodeURI(url.slice(valueIndex, endIndex === -1 ? void 0 : endIndex));
|
|
3206
|
+
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
3207
|
+
return "";
|
|
3208
|
+
}
|
|
3209
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
3210
|
+
}
|
|
3211
|
+
encoded = /[%+]/.test(url);
|
|
3212
|
+
if (!encoded) {
|
|
3213
|
+
return void 0;
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
const results = {};
|
|
3217
|
+
encoded ??= /[%+]/.test(url);
|
|
3218
|
+
let keyIndex = url.indexOf("?", 8);
|
|
3219
|
+
while (keyIndex !== -1) {
|
|
3220
|
+
const nextKeyIndex = url.indexOf("&", keyIndex + 1);
|
|
3221
|
+
let valueIndex = url.indexOf("=", keyIndex);
|
|
3222
|
+
if (valueIndex > nextKeyIndex && nextKeyIndex !== -1) {
|
|
3223
|
+
valueIndex = -1;
|
|
3224
|
+
}
|
|
3225
|
+
let name = url.slice(
|
|
3226
|
+
keyIndex + 1,
|
|
3227
|
+
valueIndex === -1 ? nextKeyIndex === -1 ? void 0 : nextKeyIndex : valueIndex
|
|
3228
|
+
);
|
|
3229
|
+
if (encoded) {
|
|
3230
|
+
name = _decodeURI(name);
|
|
3231
|
+
}
|
|
3232
|
+
keyIndex = nextKeyIndex;
|
|
3233
|
+
if (name === "") {
|
|
3234
|
+
continue;
|
|
3235
|
+
}
|
|
3236
|
+
let value;
|
|
3237
|
+
if (valueIndex === -1) {
|
|
3238
|
+
value = "";
|
|
3239
|
+
} else {
|
|
3240
|
+
value = url.slice(valueIndex + 1, nextKeyIndex === -1 ? void 0 : nextKeyIndex);
|
|
3241
|
+
if (encoded) {
|
|
3242
|
+
value = _decodeURI(value);
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
if (multiple) {
|
|
3246
|
+
if (!(results[name] && Array.isArray(results[name]))) {
|
|
3247
|
+
results[name] = [];
|
|
3248
|
+
}
|
|
3249
|
+
;
|
|
3250
|
+
results[name].push(value);
|
|
3251
|
+
} else {
|
|
3252
|
+
results[name] ??= value;
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
return key ? results[key] : results;
|
|
3256
|
+
};
|
|
3257
|
+
var getQueryParam = _getQueryParam;
|
|
3258
|
+
var getQueryParams = (url, key) => {
|
|
3259
|
+
return _getQueryParam(url, key, true);
|
|
3260
|
+
};
|
|
3261
|
+
var decodeURIComponent_ = decodeURIComponent;
|
|
3262
|
+
|
|
3263
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/request.js
|
|
3264
|
+
var tryDecodeURIComponent = (str) => tryDecode(str, decodeURIComponent_);
|
|
3265
|
+
var HonoRequest = class {
|
|
3266
|
+
raw;
|
|
3267
|
+
#validatedData;
|
|
3268
|
+
#matchResult;
|
|
3269
|
+
routeIndex = 0;
|
|
3270
|
+
path;
|
|
3271
|
+
bodyCache = {};
|
|
3272
|
+
constructor(request, path2 = "/", matchResult = [[]]) {
|
|
3273
|
+
this.raw = request;
|
|
3274
|
+
this.path = path2;
|
|
3275
|
+
this.#matchResult = matchResult;
|
|
3276
|
+
this.#validatedData = {};
|
|
3277
|
+
}
|
|
3278
|
+
param(key) {
|
|
3279
|
+
return key ? this.#getDecodedParam(key) : this.#getAllDecodedParams();
|
|
3280
|
+
}
|
|
3281
|
+
#getDecodedParam(key) {
|
|
3282
|
+
const paramKey = this.#matchResult[0][this.routeIndex][1][key];
|
|
3283
|
+
const param = this.#getParamValue(paramKey);
|
|
3284
|
+
return param ? /\%/.test(param) ? tryDecodeURIComponent(param) : param : void 0;
|
|
3285
|
+
}
|
|
3286
|
+
#getAllDecodedParams() {
|
|
3287
|
+
const decoded = {};
|
|
3288
|
+
const keys = Object.keys(this.#matchResult[0][this.routeIndex][1]);
|
|
3289
|
+
for (const key of keys) {
|
|
3290
|
+
const value = this.#getParamValue(this.#matchResult[0][this.routeIndex][1][key]);
|
|
3291
|
+
if (value && typeof value === "string") {
|
|
3292
|
+
decoded[key] = /\%/.test(value) ? tryDecodeURIComponent(value) : value;
|
|
3293
|
+
}
|
|
3294
|
+
}
|
|
3295
|
+
return decoded;
|
|
3296
|
+
}
|
|
3297
|
+
#getParamValue(paramKey) {
|
|
3298
|
+
return this.#matchResult[1] ? this.#matchResult[1][paramKey] : paramKey;
|
|
3299
|
+
}
|
|
3300
|
+
query(key) {
|
|
3301
|
+
return getQueryParam(this.url, key);
|
|
3302
|
+
}
|
|
3303
|
+
queries(key) {
|
|
3304
|
+
return getQueryParams(this.url, key);
|
|
3305
|
+
}
|
|
3306
|
+
header(name) {
|
|
3307
|
+
if (name) {
|
|
3308
|
+
return this.raw.headers.get(name) ?? void 0;
|
|
3309
|
+
}
|
|
3310
|
+
const headerData = {};
|
|
3311
|
+
this.raw.headers.forEach((value, key) => {
|
|
3312
|
+
headerData[key] = value;
|
|
3313
|
+
});
|
|
3314
|
+
return headerData;
|
|
3315
|
+
}
|
|
3316
|
+
async parseBody(options) {
|
|
3317
|
+
return this.bodyCache.parsedBody ??= await parseBody(this, options);
|
|
3318
|
+
}
|
|
3319
|
+
#cachedBody = (key) => {
|
|
3320
|
+
const { bodyCache, raw: raw2 } = this;
|
|
3321
|
+
const cachedBody = bodyCache[key];
|
|
3322
|
+
if (cachedBody) {
|
|
3323
|
+
return cachedBody;
|
|
3324
|
+
}
|
|
3325
|
+
const anyCachedKey = Object.keys(bodyCache)[0];
|
|
3326
|
+
if (anyCachedKey) {
|
|
3327
|
+
return bodyCache[anyCachedKey].then((body) => {
|
|
3328
|
+
if (anyCachedKey === "json") {
|
|
3329
|
+
body = JSON.stringify(body);
|
|
3330
|
+
}
|
|
3331
|
+
return new Response(body)[key]();
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3334
|
+
return bodyCache[key] = raw2[key]();
|
|
3335
|
+
};
|
|
3336
|
+
json() {
|
|
3337
|
+
return this.#cachedBody("json");
|
|
3338
|
+
}
|
|
3339
|
+
text() {
|
|
3340
|
+
return this.#cachedBody("text");
|
|
3341
|
+
}
|
|
3342
|
+
arrayBuffer() {
|
|
3343
|
+
return this.#cachedBody("arrayBuffer");
|
|
3344
|
+
}
|
|
3345
|
+
blob() {
|
|
3346
|
+
return this.#cachedBody("blob");
|
|
3347
|
+
}
|
|
3348
|
+
formData() {
|
|
3349
|
+
return this.#cachedBody("formData");
|
|
3350
|
+
}
|
|
3351
|
+
addValidatedData(target, data) {
|
|
3352
|
+
this.#validatedData[target] = data;
|
|
3353
|
+
}
|
|
3354
|
+
valid(target) {
|
|
3355
|
+
return this.#validatedData[target];
|
|
3356
|
+
}
|
|
3357
|
+
get url() {
|
|
3358
|
+
return this.raw.url;
|
|
3359
|
+
}
|
|
3360
|
+
get method() {
|
|
3361
|
+
return this.raw.method;
|
|
3362
|
+
}
|
|
3363
|
+
get matchedRoutes() {
|
|
3364
|
+
return this.#matchResult[0].map(([[, route]]) => route);
|
|
3365
|
+
}
|
|
3366
|
+
get routePath() {
|
|
3367
|
+
return this.#matchResult[0].map(([[, route]]) => route)[this.routeIndex].path;
|
|
3368
|
+
}
|
|
3369
|
+
};
|
|
3370
|
+
|
|
3371
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/utils/html.js
|
|
3372
|
+
init_cjs_shims();
|
|
3373
|
+
var HtmlEscapedCallbackPhase = {
|
|
3374
|
+
Stringify: 1,
|
|
3375
|
+
BeforeStream: 2,
|
|
3376
|
+
Stream: 3
|
|
3377
|
+
};
|
|
3378
|
+
var raw = (value, callbacks) => {
|
|
3379
|
+
const escapedString = new String(value);
|
|
3380
|
+
escapedString.isEscaped = true;
|
|
3381
|
+
escapedString.callbacks = callbacks;
|
|
3382
|
+
return escapedString;
|
|
3383
|
+
};
|
|
3384
|
+
var resolveCallback = async (str, phase, preserveCallbacks, context, buffer) => {
|
|
3385
|
+
if (typeof str === "object" && !(str instanceof String)) {
|
|
3386
|
+
if (!(str instanceof Promise)) {
|
|
3387
|
+
str = str.toString();
|
|
3388
|
+
}
|
|
3389
|
+
if (str instanceof Promise) {
|
|
3390
|
+
str = await str;
|
|
3391
|
+
}
|
|
3392
|
+
}
|
|
3393
|
+
const callbacks = str.callbacks;
|
|
3394
|
+
if (!callbacks?.length) {
|
|
3395
|
+
return Promise.resolve(str);
|
|
3396
|
+
}
|
|
3397
|
+
if (buffer) {
|
|
3398
|
+
buffer[0] += str;
|
|
3399
|
+
} else {
|
|
3400
|
+
buffer = [str];
|
|
3401
|
+
}
|
|
3402
|
+
const resStr = Promise.all(callbacks.map((c) => c({ phase, buffer, context }))).then(
|
|
3403
|
+
(res) => Promise.all(
|
|
3404
|
+
res.filter(Boolean).map((str2) => resolveCallback(str2, phase, false, context, buffer))
|
|
3405
|
+
).then(() => buffer[0])
|
|
3406
|
+
);
|
|
3407
|
+
if (preserveCallbacks) {
|
|
3408
|
+
return raw(await resStr, callbacks);
|
|
3409
|
+
} else {
|
|
3410
|
+
return resStr;
|
|
3411
|
+
}
|
|
3412
|
+
};
|
|
3413
|
+
|
|
3414
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/context.js
|
|
3415
|
+
var TEXT_PLAIN = "text/plain; charset=UTF-8";
|
|
3416
|
+
var setHeaders = (headers, map = {}) => {
|
|
3417
|
+
for (const key of Object.keys(map)) {
|
|
3418
|
+
headers.set(key, map[key]);
|
|
3419
|
+
}
|
|
3420
|
+
return headers;
|
|
3421
|
+
};
|
|
3422
|
+
var Context = class {
|
|
3423
|
+
#rawRequest;
|
|
3424
|
+
#req;
|
|
3425
|
+
env = {};
|
|
3426
|
+
#var;
|
|
3427
|
+
finalized = false;
|
|
3428
|
+
error;
|
|
3429
|
+
#status = 200;
|
|
3430
|
+
#executionCtx;
|
|
3431
|
+
#headers;
|
|
3432
|
+
#preparedHeaders;
|
|
3433
|
+
#res;
|
|
3434
|
+
#isFresh = true;
|
|
3435
|
+
#layout;
|
|
3436
|
+
#renderer;
|
|
3437
|
+
#notFoundHandler;
|
|
3438
|
+
#matchResult;
|
|
3439
|
+
#path;
|
|
3440
|
+
constructor(req, options) {
|
|
3441
|
+
this.#rawRequest = req;
|
|
3442
|
+
if (options) {
|
|
3443
|
+
this.#executionCtx = options.executionCtx;
|
|
3444
|
+
this.env = options.env;
|
|
3445
|
+
this.#notFoundHandler = options.notFoundHandler;
|
|
3446
|
+
this.#path = options.path;
|
|
3447
|
+
this.#matchResult = options.matchResult;
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
get req() {
|
|
3451
|
+
this.#req ??= new HonoRequest(this.#rawRequest, this.#path, this.#matchResult);
|
|
3452
|
+
return this.#req;
|
|
3453
|
+
}
|
|
3454
|
+
get event() {
|
|
3455
|
+
if (this.#executionCtx && "respondWith" in this.#executionCtx) {
|
|
3456
|
+
return this.#executionCtx;
|
|
3457
|
+
} else {
|
|
3458
|
+
throw Error("This context has no FetchEvent");
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
get executionCtx() {
|
|
3462
|
+
if (this.#executionCtx) {
|
|
3463
|
+
return this.#executionCtx;
|
|
3464
|
+
} else {
|
|
3465
|
+
throw Error("This context has no ExecutionContext");
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
get res() {
|
|
3469
|
+
this.#isFresh = false;
|
|
3470
|
+
return this.#res ||= new Response("404 Not Found", { status: 404 });
|
|
3471
|
+
}
|
|
3472
|
+
set res(_res) {
|
|
3473
|
+
this.#isFresh = false;
|
|
3474
|
+
if (this.#res && _res) {
|
|
3475
|
+
try {
|
|
3476
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
3477
|
+
if (k === "content-type") {
|
|
3478
|
+
continue;
|
|
3479
|
+
}
|
|
3480
|
+
if (k === "set-cookie") {
|
|
3481
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
3482
|
+
_res.headers.delete("set-cookie");
|
|
3483
|
+
for (const cookie of cookies) {
|
|
3484
|
+
_res.headers.append("set-cookie", cookie);
|
|
3485
|
+
}
|
|
3486
|
+
} else {
|
|
3487
|
+
_res.headers.set(k, v);
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
} catch (e) {
|
|
3491
|
+
if (e instanceof TypeError && e.message.includes("immutable")) {
|
|
3492
|
+
this.res = new Response(_res.body, {
|
|
3493
|
+
headers: _res.headers,
|
|
3494
|
+
status: _res.status
|
|
3495
|
+
});
|
|
3496
|
+
return;
|
|
3497
|
+
} else {
|
|
3498
|
+
throw e;
|
|
3499
|
+
}
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
this.#res = _res;
|
|
3503
|
+
this.finalized = true;
|
|
3504
|
+
}
|
|
3505
|
+
render = (...args) => {
|
|
3506
|
+
this.#renderer ??= (content) => this.html(content);
|
|
3507
|
+
return this.#renderer(...args);
|
|
3508
|
+
};
|
|
3509
|
+
setLayout = (layout) => this.#layout = layout;
|
|
3510
|
+
getLayout = () => this.#layout;
|
|
3511
|
+
setRenderer = (renderer) => {
|
|
3512
|
+
this.#renderer = renderer;
|
|
3513
|
+
};
|
|
3514
|
+
header = (name, value, options) => {
|
|
3515
|
+
if (value === void 0) {
|
|
3516
|
+
if (this.#headers) {
|
|
3517
|
+
this.#headers.delete(name);
|
|
3518
|
+
} else if (this.#preparedHeaders) {
|
|
3519
|
+
delete this.#preparedHeaders[name.toLocaleLowerCase()];
|
|
3520
|
+
}
|
|
3521
|
+
if (this.finalized) {
|
|
3522
|
+
this.res.headers.delete(name);
|
|
3523
|
+
}
|
|
3524
|
+
return;
|
|
3525
|
+
}
|
|
3526
|
+
if (options?.append) {
|
|
3527
|
+
if (!this.#headers) {
|
|
3528
|
+
this.#isFresh = false;
|
|
3529
|
+
this.#headers = new Headers(this.#preparedHeaders);
|
|
3530
|
+
this.#preparedHeaders = {};
|
|
3531
|
+
}
|
|
3532
|
+
this.#headers.append(name, value);
|
|
3533
|
+
} else {
|
|
3534
|
+
if (this.#headers) {
|
|
3535
|
+
this.#headers.set(name, value);
|
|
3536
|
+
} else {
|
|
3537
|
+
this.#preparedHeaders ??= {};
|
|
3538
|
+
this.#preparedHeaders[name.toLowerCase()] = value;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
if (this.finalized) {
|
|
3542
|
+
if (options?.append) {
|
|
3543
|
+
this.res.headers.append(name, value);
|
|
3544
|
+
} else {
|
|
3545
|
+
this.res.headers.set(name, value);
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
};
|
|
3549
|
+
status = (status) => {
|
|
3550
|
+
this.#isFresh = false;
|
|
3551
|
+
this.#status = status;
|
|
3552
|
+
};
|
|
3553
|
+
set = (key, value) => {
|
|
3554
|
+
this.#var ??= /* @__PURE__ */ new Map();
|
|
3555
|
+
this.#var.set(key, value);
|
|
3556
|
+
};
|
|
3557
|
+
get = (key) => {
|
|
3558
|
+
return this.#var ? this.#var.get(key) : void 0;
|
|
3559
|
+
};
|
|
3560
|
+
get var() {
|
|
3561
|
+
if (!this.#var) {
|
|
3562
|
+
return {};
|
|
3563
|
+
}
|
|
3564
|
+
return Object.fromEntries(this.#var);
|
|
3565
|
+
}
|
|
3566
|
+
#newResponse(data, arg, headers) {
|
|
3567
|
+
if (this.#isFresh && !headers && !arg && this.#status === 200) {
|
|
3568
|
+
return new Response(data, {
|
|
3569
|
+
headers: this.#preparedHeaders
|
|
3570
|
+
});
|
|
3571
|
+
}
|
|
3572
|
+
if (arg && typeof arg !== "number") {
|
|
3573
|
+
const header = new Headers(arg.headers);
|
|
3574
|
+
if (this.#headers) {
|
|
3575
|
+
this.#headers.forEach((v, k) => {
|
|
3576
|
+
if (k === "set-cookie") {
|
|
3577
|
+
header.append(k, v);
|
|
3578
|
+
} else {
|
|
3579
|
+
header.set(k, v);
|
|
3580
|
+
}
|
|
3581
|
+
});
|
|
3582
|
+
}
|
|
3583
|
+
const headers2 = setHeaders(header, this.#preparedHeaders);
|
|
3584
|
+
return new Response(data, {
|
|
3585
|
+
headers: headers2,
|
|
3586
|
+
status: arg.status ?? this.#status
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
const status = typeof arg === "number" ? arg : this.#status;
|
|
3590
|
+
this.#preparedHeaders ??= {};
|
|
3591
|
+
this.#headers ??= new Headers();
|
|
3592
|
+
setHeaders(this.#headers, this.#preparedHeaders);
|
|
3593
|
+
if (this.#res) {
|
|
3594
|
+
this.#res.headers.forEach((v, k) => {
|
|
3595
|
+
if (k === "set-cookie") {
|
|
3596
|
+
this.#headers?.append(k, v);
|
|
3597
|
+
} else {
|
|
3598
|
+
this.#headers?.set(k, v);
|
|
3599
|
+
}
|
|
3600
|
+
});
|
|
3601
|
+
setHeaders(this.#headers, this.#preparedHeaders);
|
|
3602
|
+
}
|
|
3603
|
+
headers ??= {};
|
|
3604
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
3605
|
+
if (typeof v === "string") {
|
|
3606
|
+
this.#headers.set(k, v);
|
|
3607
|
+
} else {
|
|
3608
|
+
this.#headers.delete(k);
|
|
3609
|
+
for (const v2 of v) {
|
|
3610
|
+
this.#headers.append(k, v2);
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
return new Response(data, {
|
|
3615
|
+
status,
|
|
3616
|
+
headers: this.#headers
|
|
3617
|
+
});
|
|
3618
|
+
}
|
|
3619
|
+
newResponse = (...args) => this.#newResponse(...args);
|
|
3620
|
+
body = (data, arg, headers) => {
|
|
3621
|
+
return typeof arg === "number" ? this.#newResponse(data, arg, headers) : this.#newResponse(data, arg);
|
|
3622
|
+
};
|
|
3623
|
+
text = (text, arg, headers) => {
|
|
3624
|
+
if (!this.#preparedHeaders) {
|
|
3625
|
+
if (this.#isFresh && !headers && !arg) {
|
|
3626
|
+
return new Response(text);
|
|
3627
|
+
}
|
|
3628
|
+
this.#preparedHeaders = {};
|
|
3629
|
+
}
|
|
3630
|
+
this.#preparedHeaders["content-type"] = TEXT_PLAIN;
|
|
3631
|
+
if (typeof arg === "number") {
|
|
3632
|
+
return this.#newResponse(text, arg, headers);
|
|
3633
|
+
}
|
|
3634
|
+
return this.#newResponse(text, arg);
|
|
3635
|
+
};
|
|
3636
|
+
json = (object, arg, headers) => {
|
|
3637
|
+
const body = JSON.stringify(object);
|
|
3638
|
+
this.#preparedHeaders ??= {};
|
|
3639
|
+
this.#preparedHeaders["content-type"] = "application/json";
|
|
3640
|
+
return typeof arg === "number" ? this.#newResponse(body, arg, headers) : this.#newResponse(body, arg);
|
|
3641
|
+
};
|
|
3642
|
+
html = (html, arg, headers) => {
|
|
3643
|
+
this.#preparedHeaders ??= {};
|
|
3644
|
+
this.#preparedHeaders["content-type"] = "text/html; charset=UTF-8";
|
|
3645
|
+
if (typeof html === "object") {
|
|
3646
|
+
return resolveCallback(html, HtmlEscapedCallbackPhase.Stringify, false, {}).then((html2) => {
|
|
3647
|
+
return typeof arg === "number" ? this.#newResponse(html2, arg, headers) : this.#newResponse(html2, arg);
|
|
3648
|
+
});
|
|
3649
|
+
}
|
|
3650
|
+
return typeof arg === "number" ? this.#newResponse(html, arg, headers) : this.#newResponse(html, arg);
|
|
3651
|
+
};
|
|
3652
|
+
redirect = (location, status) => {
|
|
3653
|
+
this.#headers ??= new Headers();
|
|
3654
|
+
this.#headers.set("Location", String(location));
|
|
3655
|
+
return this.newResponse(null, status ?? 302);
|
|
3656
|
+
};
|
|
3657
|
+
notFound = () => {
|
|
3658
|
+
this.#notFoundHandler ??= () => new Response();
|
|
3659
|
+
return this.#notFoundHandler(this);
|
|
3660
|
+
};
|
|
3661
|
+
};
|
|
3662
|
+
|
|
3663
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router.js
|
|
3664
|
+
init_cjs_shims();
|
|
3665
|
+
var METHOD_NAME_ALL = "ALL";
|
|
3666
|
+
var METHOD_NAME_ALL_LOWERCASE = "all";
|
|
3667
|
+
var METHODS = ["get", "post", "put", "delete", "options", "patch"];
|
|
3668
|
+
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
3669
|
+
var UnsupportedPathError = class extends Error {
|
|
3670
|
+
};
|
|
3671
|
+
|
|
3672
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/utils/constants.js
|
|
3673
|
+
init_cjs_shims();
|
|
3674
|
+
var COMPOSED_HANDLER = "__COMPOSED_HANDLER";
|
|
3675
|
+
|
|
3676
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/hono-base.js
|
|
3677
|
+
var notFoundHandler = (c) => {
|
|
3678
|
+
return c.text("404 Not Found", 404);
|
|
3679
|
+
};
|
|
3680
|
+
var errorHandler = (err, c) => {
|
|
3681
|
+
if ("getResponse" in err) {
|
|
3682
|
+
return err.getResponse();
|
|
3683
|
+
}
|
|
3684
|
+
console.error(err);
|
|
3685
|
+
return c.text("Internal Server Error", 500);
|
|
3686
|
+
};
|
|
3687
|
+
var Hono = class {
|
|
3688
|
+
get;
|
|
3689
|
+
post;
|
|
3690
|
+
put;
|
|
3691
|
+
delete;
|
|
3692
|
+
options;
|
|
3693
|
+
patch;
|
|
3694
|
+
all;
|
|
3695
|
+
on;
|
|
3696
|
+
use;
|
|
3697
|
+
router;
|
|
3698
|
+
getPath;
|
|
3699
|
+
_basePath = "/";
|
|
3700
|
+
#path = "/";
|
|
3701
|
+
routes = [];
|
|
3702
|
+
constructor(options = {}) {
|
|
3703
|
+
const allMethods = [...METHODS, METHOD_NAME_ALL_LOWERCASE];
|
|
3704
|
+
allMethods.forEach((method) => {
|
|
3705
|
+
this[method] = (args1, ...args) => {
|
|
3706
|
+
if (typeof args1 === "string") {
|
|
3707
|
+
this.#path = args1;
|
|
3708
|
+
} else {
|
|
3709
|
+
this.#addRoute(method, this.#path, args1);
|
|
3710
|
+
}
|
|
3711
|
+
args.forEach((handler) => {
|
|
3712
|
+
this.#addRoute(method, this.#path, handler);
|
|
3713
|
+
});
|
|
3714
|
+
return this;
|
|
3715
|
+
};
|
|
3716
|
+
});
|
|
3717
|
+
this.on = (method, path2, ...handlers) => {
|
|
3718
|
+
for (const p of [path2].flat()) {
|
|
3719
|
+
this.#path = p;
|
|
3720
|
+
for (const m of [method].flat()) {
|
|
3721
|
+
handlers.map((handler) => {
|
|
3722
|
+
this.#addRoute(m.toUpperCase(), this.#path, handler);
|
|
3723
|
+
});
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
return this;
|
|
3727
|
+
};
|
|
3728
|
+
this.use = (arg1, ...handlers) => {
|
|
3729
|
+
if (typeof arg1 === "string") {
|
|
3730
|
+
this.#path = arg1;
|
|
3731
|
+
} else {
|
|
3732
|
+
this.#path = "*";
|
|
3733
|
+
handlers.unshift(arg1);
|
|
3734
|
+
}
|
|
3735
|
+
handlers.forEach((handler) => {
|
|
3736
|
+
this.#addRoute(METHOD_NAME_ALL, this.#path, handler);
|
|
3737
|
+
});
|
|
3738
|
+
return this;
|
|
3739
|
+
};
|
|
3740
|
+
const { strict, ...optionsWithoutStrict } = options;
|
|
3741
|
+
Object.assign(this, optionsWithoutStrict);
|
|
3742
|
+
this.getPath = strict ?? true ? options.getPath ?? getPath : getPathNoStrict;
|
|
3743
|
+
}
|
|
3744
|
+
#clone() {
|
|
3745
|
+
const clone = new Hono({
|
|
3746
|
+
router: this.router,
|
|
3747
|
+
getPath: this.getPath
|
|
3748
|
+
});
|
|
3749
|
+
clone.routes = this.routes;
|
|
3750
|
+
return clone;
|
|
3751
|
+
}
|
|
3752
|
+
#notFoundHandler = notFoundHandler;
|
|
3753
|
+
errorHandler = errorHandler;
|
|
3754
|
+
route(path2, app2) {
|
|
3755
|
+
const subApp = this.basePath(path2);
|
|
3756
|
+
app2.routes.map((r) => {
|
|
3757
|
+
let handler;
|
|
3758
|
+
if (app2.errorHandler === errorHandler) {
|
|
3759
|
+
handler = r.handler;
|
|
3760
|
+
} else {
|
|
3761
|
+
handler = async (c, next) => (await compose([], app2.errorHandler)(c, () => r.handler(c, next))).res;
|
|
3762
|
+
handler[COMPOSED_HANDLER] = r.handler;
|
|
3763
|
+
}
|
|
3764
|
+
subApp.#addRoute(r.method, r.path, handler);
|
|
3765
|
+
});
|
|
3766
|
+
return this;
|
|
3767
|
+
}
|
|
3768
|
+
basePath(path2) {
|
|
3769
|
+
const subApp = this.#clone();
|
|
3770
|
+
subApp._basePath = mergePath(this._basePath, path2);
|
|
3771
|
+
return subApp;
|
|
3772
|
+
}
|
|
3773
|
+
onError = (handler) => {
|
|
3774
|
+
this.errorHandler = handler;
|
|
3775
|
+
return this;
|
|
3776
|
+
};
|
|
3777
|
+
notFound = (handler) => {
|
|
3778
|
+
this.#notFoundHandler = handler;
|
|
3779
|
+
return this;
|
|
3780
|
+
};
|
|
3781
|
+
mount(path2, applicationHandler, options) {
|
|
3782
|
+
let replaceRequest;
|
|
3783
|
+
let optionHandler;
|
|
3784
|
+
if (options) {
|
|
3785
|
+
if (typeof options === "function") {
|
|
3786
|
+
optionHandler = options;
|
|
3787
|
+
} else {
|
|
3788
|
+
optionHandler = options.optionHandler;
|
|
3789
|
+
replaceRequest = options.replaceRequest;
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
const getOptions = optionHandler ? (c) => {
|
|
3793
|
+
const options2 = optionHandler(c);
|
|
3794
|
+
return Array.isArray(options2) ? options2 : [options2];
|
|
3795
|
+
} : (c) => {
|
|
3796
|
+
let executionContext = void 0;
|
|
3797
|
+
try {
|
|
3798
|
+
executionContext = c.executionCtx;
|
|
3799
|
+
} catch {
|
|
3800
|
+
}
|
|
3801
|
+
return [c.env, executionContext];
|
|
3802
|
+
};
|
|
3803
|
+
replaceRequest ||= (() => {
|
|
3804
|
+
const mergedPath = mergePath(this._basePath, path2);
|
|
3805
|
+
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
3806
|
+
return (request) => {
|
|
3807
|
+
const url = new URL(request.url);
|
|
3808
|
+
url.pathname = url.pathname.slice(pathPrefixLength) || "/";
|
|
3809
|
+
return new Request(url, request);
|
|
3810
|
+
};
|
|
3811
|
+
})();
|
|
3812
|
+
const handler = async (c, next) => {
|
|
3813
|
+
const res = await applicationHandler(replaceRequest(c.req.raw), ...getOptions(c));
|
|
3814
|
+
if (res) {
|
|
3815
|
+
return res;
|
|
3816
|
+
}
|
|
3817
|
+
await next();
|
|
3818
|
+
};
|
|
3819
|
+
this.#addRoute(METHOD_NAME_ALL, mergePath(path2, "*"), handler);
|
|
3820
|
+
return this;
|
|
3821
|
+
}
|
|
3822
|
+
#addRoute(method, path2, handler) {
|
|
3823
|
+
method = method.toUpperCase();
|
|
3824
|
+
path2 = mergePath(this._basePath, path2);
|
|
3825
|
+
const r = { path: path2, method, handler };
|
|
3826
|
+
this.router.add(method, path2, [handler, r]);
|
|
3827
|
+
this.routes.push(r);
|
|
3828
|
+
}
|
|
3829
|
+
#handleError(err, c) {
|
|
3830
|
+
if (err instanceof Error) {
|
|
3831
|
+
return this.errorHandler(err, c);
|
|
3832
|
+
}
|
|
3833
|
+
throw err;
|
|
3834
|
+
}
|
|
3835
|
+
#dispatch(request, executionCtx, env, method) {
|
|
3836
|
+
if (method === "HEAD") {
|
|
3837
|
+
return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
|
|
3838
|
+
}
|
|
3839
|
+
const path2 = this.getPath(request, { env });
|
|
3840
|
+
const matchResult = this.router.match(method, path2);
|
|
3841
|
+
const c = new Context(request, {
|
|
3842
|
+
path: path2,
|
|
3843
|
+
matchResult,
|
|
3844
|
+
env,
|
|
3845
|
+
executionCtx,
|
|
3846
|
+
notFoundHandler: this.#notFoundHandler
|
|
3847
|
+
});
|
|
3848
|
+
if (matchResult[0].length === 1) {
|
|
3849
|
+
let res;
|
|
3850
|
+
try {
|
|
3851
|
+
res = matchResult[0][0][0][0](c, async () => {
|
|
3852
|
+
c.res = await this.#notFoundHandler(c);
|
|
3853
|
+
});
|
|
3854
|
+
} catch (err) {
|
|
3855
|
+
return this.#handleError(err, c);
|
|
3856
|
+
}
|
|
3857
|
+
return res instanceof Promise ? res.then(
|
|
3858
|
+
(resolved) => resolved || (c.finalized ? c.res : this.#notFoundHandler(c))
|
|
3859
|
+
).catch((err) => this.#handleError(err, c)) : res ?? this.#notFoundHandler(c);
|
|
3860
|
+
}
|
|
3861
|
+
const composed = compose(matchResult[0], this.errorHandler, this.#notFoundHandler);
|
|
3862
|
+
return (async () => {
|
|
3863
|
+
try {
|
|
3864
|
+
const context = await composed(c);
|
|
3865
|
+
if (!context.finalized) {
|
|
3866
|
+
throw new Error(
|
|
3867
|
+
"Context is not finalized. Did you forget to return a Response object or `await next()`?"
|
|
3868
|
+
);
|
|
3869
|
+
}
|
|
3870
|
+
return context.res;
|
|
3871
|
+
} catch (err) {
|
|
3872
|
+
return this.#handleError(err, c);
|
|
3873
|
+
}
|
|
3874
|
+
})();
|
|
3875
|
+
}
|
|
3876
|
+
fetch = (request, ...rest) => {
|
|
3877
|
+
return this.#dispatch(request, rest[1], rest[0], request.method);
|
|
3878
|
+
};
|
|
3879
|
+
request = (input, requestInit, Env, executionCtx) => {
|
|
3880
|
+
if (input instanceof Request) {
|
|
3881
|
+
return this.fetch(requestInit ? new Request(input, requestInit) : input, Env, executionCtx);
|
|
3882
|
+
}
|
|
3883
|
+
input = input.toString();
|
|
3884
|
+
return this.fetch(
|
|
3885
|
+
new Request(
|
|
3886
|
+
/^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`,
|
|
3887
|
+
requestInit
|
|
3888
|
+
),
|
|
3889
|
+
Env,
|
|
3890
|
+
executionCtx
|
|
3891
|
+
);
|
|
3892
|
+
};
|
|
3893
|
+
fire = () => {
|
|
3894
|
+
addEventListener("fetch", (event) => {
|
|
3895
|
+
event.respondWith(this.#dispatch(event.request, event, void 0, event.request.method));
|
|
3896
|
+
});
|
|
3897
|
+
};
|
|
3898
|
+
};
|
|
3899
|
+
|
|
3900
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/reg-exp-router/index.js
|
|
3901
|
+
init_cjs_shims();
|
|
3902
|
+
|
|
3903
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
3904
|
+
init_cjs_shims();
|
|
3905
|
+
|
|
3906
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
3907
|
+
init_cjs_shims();
|
|
3908
|
+
var LABEL_REG_EXP_STR = "[^/]+";
|
|
3909
|
+
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
3910
|
+
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
3911
|
+
var PATH_ERROR = Symbol();
|
|
3912
|
+
var regExpMetaChars = new Set(".\\+*[^]$()");
|
|
3913
|
+
function compareKey(a, b) {
|
|
3914
|
+
if (a.length === 1) {
|
|
3915
|
+
return b.length === 1 ? a < b ? -1 : 1 : -1;
|
|
3916
|
+
}
|
|
3917
|
+
if (b.length === 1) {
|
|
3918
|
+
return 1;
|
|
3919
|
+
}
|
|
3920
|
+
if (a === ONLY_WILDCARD_REG_EXP_STR || a === TAIL_WILDCARD_REG_EXP_STR) {
|
|
3921
|
+
return 1;
|
|
3922
|
+
} else if (b === ONLY_WILDCARD_REG_EXP_STR || b === TAIL_WILDCARD_REG_EXP_STR) {
|
|
3923
|
+
return -1;
|
|
3924
|
+
}
|
|
3925
|
+
if (a === LABEL_REG_EXP_STR) {
|
|
3926
|
+
return 1;
|
|
3927
|
+
} else if (b === LABEL_REG_EXP_STR) {
|
|
3928
|
+
return -1;
|
|
3929
|
+
}
|
|
3930
|
+
return a.length === b.length ? a < b ? -1 : 1 : b.length - a.length;
|
|
3931
|
+
}
|
|
3932
|
+
var Node = class {
|
|
3933
|
+
#index;
|
|
3934
|
+
#varIndex;
|
|
3935
|
+
#children = /* @__PURE__ */ Object.create(null);
|
|
3936
|
+
insert(tokens, index, paramMap, context, pathErrorCheckOnly) {
|
|
3937
|
+
if (tokens.length === 0) {
|
|
3938
|
+
if (this.#index !== void 0) {
|
|
3939
|
+
throw PATH_ERROR;
|
|
3940
|
+
}
|
|
3941
|
+
if (pathErrorCheckOnly) {
|
|
3942
|
+
return;
|
|
3943
|
+
}
|
|
3944
|
+
this.#index = index;
|
|
3945
|
+
return;
|
|
3946
|
+
}
|
|
3947
|
+
const [token, ...restTokens] = tokens;
|
|
3948
|
+
const pattern = token === "*" ? restTokens.length === 0 ? ["", "", ONLY_WILDCARD_REG_EXP_STR] : ["", "", LABEL_REG_EXP_STR] : token === "/*" ? ["", "", TAIL_WILDCARD_REG_EXP_STR] : token.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
|
|
3949
|
+
let node;
|
|
3950
|
+
if (pattern) {
|
|
3951
|
+
const name = pattern[1];
|
|
3952
|
+
let regexpStr = pattern[2] || LABEL_REG_EXP_STR;
|
|
3953
|
+
if (name && pattern[2]) {
|
|
3954
|
+
regexpStr = regexpStr.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:");
|
|
3955
|
+
if (/\((?!\?:)/.test(regexpStr)) {
|
|
3956
|
+
throw PATH_ERROR;
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
node = this.#children[regexpStr];
|
|
3960
|
+
if (!node) {
|
|
3961
|
+
if (Object.keys(this.#children).some(
|
|
3962
|
+
(k) => k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
3963
|
+
)) {
|
|
3964
|
+
throw PATH_ERROR;
|
|
3965
|
+
}
|
|
3966
|
+
if (pathErrorCheckOnly) {
|
|
3967
|
+
return;
|
|
3968
|
+
}
|
|
3969
|
+
node = this.#children[regexpStr] = new Node();
|
|
3970
|
+
if (name !== "") {
|
|
3971
|
+
node.#varIndex = context.varIndex++;
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
if (!pathErrorCheckOnly && name !== "") {
|
|
3975
|
+
paramMap.push([name, node.#varIndex]);
|
|
3976
|
+
}
|
|
3977
|
+
} else {
|
|
3978
|
+
node = this.#children[token];
|
|
3979
|
+
if (!node) {
|
|
3980
|
+
if (Object.keys(this.#children).some(
|
|
3981
|
+
(k) => k.length > 1 && k !== ONLY_WILDCARD_REG_EXP_STR && k !== TAIL_WILDCARD_REG_EXP_STR
|
|
3982
|
+
)) {
|
|
3983
|
+
throw PATH_ERROR;
|
|
3984
|
+
}
|
|
3985
|
+
if (pathErrorCheckOnly) {
|
|
3986
|
+
return;
|
|
3987
|
+
}
|
|
3988
|
+
node = this.#children[token] = new Node();
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
node.insert(restTokens, index, paramMap, context, pathErrorCheckOnly);
|
|
3992
|
+
}
|
|
3993
|
+
buildRegExpStr() {
|
|
3994
|
+
const childKeys = Object.keys(this.#children).sort(compareKey);
|
|
3995
|
+
const strList = childKeys.map((k) => {
|
|
3996
|
+
const c = this.#children[k];
|
|
3997
|
+
return (typeof c.#varIndex === "number" ? `(${k})@${c.#varIndex}` : regExpMetaChars.has(k) ? `\\${k}` : k) + c.buildRegExpStr();
|
|
3998
|
+
});
|
|
3999
|
+
if (typeof this.#index === "number") {
|
|
4000
|
+
strList.unshift(`#${this.#index}`);
|
|
4001
|
+
}
|
|
4002
|
+
if (strList.length === 0) {
|
|
4003
|
+
return "";
|
|
4004
|
+
}
|
|
4005
|
+
if (strList.length === 1) {
|
|
4006
|
+
return strList[0];
|
|
4007
|
+
}
|
|
4008
|
+
return "(?:" + strList.join("|") + ")";
|
|
4009
|
+
}
|
|
4010
|
+
};
|
|
4011
|
+
|
|
4012
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
4013
|
+
init_cjs_shims();
|
|
4014
|
+
var Trie = class {
|
|
4015
|
+
#context = { varIndex: 0 };
|
|
4016
|
+
#root = new Node();
|
|
4017
|
+
insert(path2, index, pathErrorCheckOnly) {
|
|
4018
|
+
const paramAssoc = [];
|
|
4019
|
+
const groups = [];
|
|
4020
|
+
for (let i = 0; ; ) {
|
|
4021
|
+
let replaced = false;
|
|
4022
|
+
path2 = path2.replace(/\{[^}]+\}/g, (m) => {
|
|
4023
|
+
const mark = `@\\${i}`;
|
|
4024
|
+
groups[i] = [mark, m];
|
|
4025
|
+
i++;
|
|
4026
|
+
replaced = true;
|
|
4027
|
+
return mark;
|
|
4028
|
+
});
|
|
4029
|
+
if (!replaced) {
|
|
4030
|
+
break;
|
|
4031
|
+
}
|
|
4032
|
+
}
|
|
4033
|
+
const tokens = path2.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
4034
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
4035
|
+
const [mark] = groups[i];
|
|
4036
|
+
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
4037
|
+
if (tokens[j].indexOf(mark) !== -1) {
|
|
4038
|
+
tokens[j] = tokens[j].replace(mark, groups[i][1]);
|
|
4039
|
+
break;
|
|
4040
|
+
}
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
this.#root.insert(tokens, index, paramAssoc, this.#context, pathErrorCheckOnly);
|
|
4044
|
+
return paramAssoc;
|
|
4045
|
+
}
|
|
4046
|
+
buildRegExp() {
|
|
4047
|
+
let regexp = this.#root.buildRegExpStr();
|
|
4048
|
+
if (regexp === "") {
|
|
4049
|
+
return [/^$/, [], []];
|
|
4050
|
+
}
|
|
4051
|
+
let captureIndex = 0;
|
|
4052
|
+
const indexReplacementMap = [];
|
|
4053
|
+
const paramReplacementMap = [];
|
|
4054
|
+
regexp = regexp.replace(/#(\d+)|@(\d+)|\.\*\$/g, (_, handlerIndex, paramIndex) => {
|
|
4055
|
+
if (handlerIndex !== void 0) {
|
|
4056
|
+
indexReplacementMap[++captureIndex] = Number(handlerIndex);
|
|
4057
|
+
return "$()";
|
|
4058
|
+
}
|
|
4059
|
+
if (paramIndex !== void 0) {
|
|
4060
|
+
paramReplacementMap[Number(paramIndex)] = ++captureIndex;
|
|
4061
|
+
return "";
|
|
4062
|
+
}
|
|
4063
|
+
return "";
|
|
4064
|
+
});
|
|
4065
|
+
return [new RegExp(`^${regexp}`), indexReplacementMap, paramReplacementMap];
|
|
4066
|
+
}
|
|
4067
|
+
};
|
|
4068
|
+
|
|
4069
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
4070
|
+
var emptyParam = [];
|
|
4071
|
+
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
4072
|
+
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
4073
|
+
function buildWildcardRegExp(path2) {
|
|
4074
|
+
return wildcardRegExpCache[path2] ??= new RegExp(
|
|
4075
|
+
path2 === "*" ? "" : `^${path2.replace(
|
|
4076
|
+
/\/\*$|([.\\+*[^\]$()])/g,
|
|
4077
|
+
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
4078
|
+
)}$`
|
|
4079
|
+
);
|
|
4080
|
+
}
|
|
4081
|
+
function clearWildcardRegExpCache() {
|
|
4082
|
+
wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
4083
|
+
}
|
|
4084
|
+
function buildMatcherFromPreprocessedRoutes(routes) {
|
|
4085
|
+
const trie = new Trie();
|
|
4086
|
+
const handlerData = [];
|
|
4087
|
+
if (routes.length === 0) {
|
|
4088
|
+
return nullMatcher;
|
|
4089
|
+
}
|
|
4090
|
+
const routesWithStaticPathFlag = routes.map(
|
|
4091
|
+
(route) => [!/\*|\/:/.test(route[0]), ...route]
|
|
4092
|
+
).sort(
|
|
4093
|
+
([isStaticA, pathA], [isStaticB, pathB]) => isStaticA ? 1 : isStaticB ? -1 : pathA.length - pathB.length
|
|
4094
|
+
);
|
|
4095
|
+
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
4096
|
+
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
4097
|
+
const [pathErrorCheckOnly, path2, handlers] = routesWithStaticPathFlag[i];
|
|
4098
|
+
if (pathErrorCheckOnly) {
|
|
4099
|
+
staticMap[path2] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
4100
|
+
} else {
|
|
4101
|
+
j++;
|
|
4102
|
+
}
|
|
4103
|
+
let paramAssoc;
|
|
4104
|
+
try {
|
|
4105
|
+
paramAssoc = trie.insert(path2, j, pathErrorCheckOnly);
|
|
4106
|
+
} catch (e) {
|
|
4107
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path2) : e;
|
|
4108
|
+
}
|
|
4109
|
+
if (pathErrorCheckOnly) {
|
|
4110
|
+
continue;
|
|
4111
|
+
}
|
|
4112
|
+
handlerData[j] = handlers.map(([h, paramCount]) => {
|
|
4113
|
+
const paramIndexMap = /* @__PURE__ */ Object.create(null);
|
|
4114
|
+
paramCount -= 1;
|
|
4115
|
+
for (; paramCount >= 0; paramCount--) {
|
|
4116
|
+
const [key, value] = paramAssoc[paramCount];
|
|
4117
|
+
paramIndexMap[key] = value;
|
|
4118
|
+
}
|
|
4119
|
+
return [h, paramIndexMap];
|
|
4120
|
+
});
|
|
4121
|
+
}
|
|
4122
|
+
const [regexp, indexReplacementMap, paramReplacementMap] = trie.buildRegExp();
|
|
4123
|
+
for (let i = 0, len = handlerData.length; i < len; i++) {
|
|
4124
|
+
for (let j = 0, len2 = handlerData[i].length; j < len2; j++) {
|
|
4125
|
+
const map = handlerData[i][j]?.[1];
|
|
4126
|
+
if (!map) {
|
|
4127
|
+
continue;
|
|
4128
|
+
}
|
|
4129
|
+
const keys = Object.keys(map);
|
|
4130
|
+
for (let k = 0, len3 = keys.length; k < len3; k++) {
|
|
4131
|
+
map[keys[k]] = paramReplacementMap[map[keys[k]]];
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
}
|
|
4135
|
+
const handlerMap = [];
|
|
4136
|
+
for (const i in indexReplacementMap) {
|
|
4137
|
+
handlerMap[i] = handlerData[indexReplacementMap[i]];
|
|
4138
|
+
}
|
|
4139
|
+
return [regexp, handlerMap, staticMap];
|
|
4140
|
+
}
|
|
4141
|
+
function findMiddleware(middleware, path2) {
|
|
4142
|
+
if (!middleware) {
|
|
4143
|
+
return void 0;
|
|
4144
|
+
}
|
|
4145
|
+
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
4146
|
+
if (buildWildcardRegExp(k).test(path2)) {
|
|
4147
|
+
return [...middleware[k]];
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
4150
|
+
return void 0;
|
|
4151
|
+
}
|
|
4152
|
+
var RegExpRouter = class {
|
|
4153
|
+
name = "RegExpRouter";
|
|
4154
|
+
#middleware;
|
|
4155
|
+
#routes;
|
|
4156
|
+
constructor() {
|
|
4157
|
+
this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
4158
|
+
this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
4159
|
+
}
|
|
4160
|
+
add(method, path2, handler) {
|
|
4161
|
+
const middleware = this.#middleware;
|
|
4162
|
+
const routes = this.#routes;
|
|
4163
|
+
if (!middleware || !routes) {
|
|
4164
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
4165
|
+
}
|
|
4166
|
+
if (!middleware[method]) {
|
|
4167
|
+
;
|
|
4168
|
+
[middleware, routes].forEach((handlerMap) => {
|
|
4169
|
+
handlerMap[method] = /* @__PURE__ */ Object.create(null);
|
|
4170
|
+
Object.keys(handlerMap[METHOD_NAME_ALL]).forEach((p) => {
|
|
4171
|
+
handlerMap[method][p] = [...handlerMap[METHOD_NAME_ALL][p]];
|
|
4172
|
+
});
|
|
4173
|
+
});
|
|
4174
|
+
}
|
|
4175
|
+
if (path2 === "/*") {
|
|
4176
|
+
path2 = "*";
|
|
4177
|
+
}
|
|
4178
|
+
const paramCount = (path2.match(/\/:/g) || []).length;
|
|
4179
|
+
if (/\*$/.test(path2)) {
|
|
4180
|
+
const re = buildWildcardRegExp(path2);
|
|
4181
|
+
if (method === METHOD_NAME_ALL) {
|
|
4182
|
+
Object.keys(middleware).forEach((m) => {
|
|
4183
|
+
middleware[m][path2] ||= findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
|
|
4184
|
+
});
|
|
4185
|
+
} else {
|
|
4186
|
+
middleware[method][path2] ||= findMiddleware(middleware[method], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
|
|
4187
|
+
}
|
|
4188
|
+
Object.keys(middleware).forEach((m) => {
|
|
4189
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
4190
|
+
Object.keys(middleware[m]).forEach((p) => {
|
|
4191
|
+
re.test(p) && middleware[m][p].push([handler, paramCount]);
|
|
4192
|
+
});
|
|
4193
|
+
}
|
|
4194
|
+
});
|
|
4195
|
+
Object.keys(routes).forEach((m) => {
|
|
4196
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
4197
|
+
Object.keys(routes[m]).forEach(
|
|
4198
|
+
(p) => re.test(p) && routes[m][p].push([handler, paramCount])
|
|
4199
|
+
);
|
|
4200
|
+
}
|
|
4201
|
+
});
|
|
4202
|
+
return;
|
|
4203
|
+
}
|
|
4204
|
+
const paths = checkOptionalParameter(path2) || [path2];
|
|
4205
|
+
for (let i = 0, len = paths.length; i < len; i++) {
|
|
4206
|
+
const path22 = paths[i];
|
|
4207
|
+
Object.keys(routes).forEach((m) => {
|
|
4208
|
+
if (method === METHOD_NAME_ALL || method === m) {
|
|
4209
|
+
routes[m][path22] ||= [
|
|
4210
|
+
...findMiddleware(middleware[m], path22) || findMiddleware(middleware[METHOD_NAME_ALL], path22) || []
|
|
4211
|
+
];
|
|
4212
|
+
routes[m][path22].push([handler, paramCount - len + i + 1]);
|
|
4213
|
+
}
|
|
4214
|
+
});
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
match(method, path2) {
|
|
4218
|
+
clearWildcardRegExpCache();
|
|
4219
|
+
const matchers = this.#buildAllMatchers();
|
|
4220
|
+
this.match = (method2, path22) => {
|
|
4221
|
+
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
4222
|
+
const staticMatch = matcher[2][path22];
|
|
4223
|
+
if (staticMatch) {
|
|
4224
|
+
return staticMatch;
|
|
4225
|
+
}
|
|
4226
|
+
const match = path22.match(matcher[0]);
|
|
4227
|
+
if (!match) {
|
|
4228
|
+
return [[], emptyParam];
|
|
4229
|
+
}
|
|
4230
|
+
const index = match.indexOf("", 1);
|
|
4231
|
+
return [matcher[1][index], match];
|
|
4232
|
+
};
|
|
4233
|
+
return this.match(method, path2);
|
|
4234
|
+
}
|
|
4235
|
+
#buildAllMatchers() {
|
|
4236
|
+
const matchers = /* @__PURE__ */ Object.create(null);
|
|
4237
|
+
Object.keys(this.#routes).concat(Object.keys(this.#middleware)).forEach((method) => {
|
|
4238
|
+
matchers[method] ||= this.#buildMatcher(method);
|
|
4239
|
+
});
|
|
4240
|
+
this.#middleware = this.#routes = void 0;
|
|
4241
|
+
return matchers;
|
|
4242
|
+
}
|
|
4243
|
+
#buildMatcher(method) {
|
|
4244
|
+
const routes = [];
|
|
4245
|
+
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
4246
|
+
[this.#middleware, this.#routes].forEach((r) => {
|
|
4247
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path2) => [path2, r[method][path2]]) : [];
|
|
4248
|
+
if (ownRoute.length !== 0) {
|
|
4249
|
+
hasOwnRoute ||= true;
|
|
4250
|
+
routes.push(...ownRoute);
|
|
4251
|
+
} else if (method !== METHOD_NAME_ALL) {
|
|
4252
|
+
routes.push(
|
|
4253
|
+
...Object.keys(r[METHOD_NAME_ALL]).map((path2) => [path2, r[METHOD_NAME_ALL][path2]])
|
|
4254
|
+
);
|
|
4255
|
+
}
|
|
4256
|
+
});
|
|
4257
|
+
if (!hasOwnRoute) {
|
|
4258
|
+
return null;
|
|
4259
|
+
} else {
|
|
4260
|
+
return buildMatcherFromPreprocessedRoutes(routes);
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
};
|
|
4264
|
+
|
|
4265
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/smart-router/index.js
|
|
4266
|
+
init_cjs_shims();
|
|
4267
|
+
|
|
4268
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/smart-router/router.js
|
|
4269
|
+
init_cjs_shims();
|
|
4270
|
+
var SmartRouter = class {
|
|
4271
|
+
name = "SmartRouter";
|
|
4272
|
+
#routers = [];
|
|
4273
|
+
#routes = [];
|
|
4274
|
+
constructor(init) {
|
|
4275
|
+
this.#routers = init.routers;
|
|
4276
|
+
}
|
|
4277
|
+
add(method, path2, handler) {
|
|
4278
|
+
if (!this.#routes) {
|
|
4279
|
+
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
4280
|
+
}
|
|
4281
|
+
this.#routes.push([method, path2, handler]);
|
|
4282
|
+
}
|
|
4283
|
+
match(method, path2) {
|
|
4284
|
+
if (!this.#routes) {
|
|
4285
|
+
throw new Error("Fatal error");
|
|
4286
|
+
}
|
|
4287
|
+
const routers = this.#routers;
|
|
4288
|
+
const routes = this.#routes;
|
|
4289
|
+
const len = routers.length;
|
|
4290
|
+
let i = 0;
|
|
4291
|
+
let res;
|
|
4292
|
+
for (; i < len; i++) {
|
|
4293
|
+
const router = routers[i];
|
|
4294
|
+
try {
|
|
4295
|
+
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
|
4296
|
+
router.add(...routes[i2]);
|
|
4297
|
+
}
|
|
4298
|
+
res = router.match(method, path2);
|
|
4299
|
+
} catch (e) {
|
|
4300
|
+
if (e instanceof UnsupportedPathError) {
|
|
4301
|
+
continue;
|
|
4302
|
+
}
|
|
4303
|
+
throw e;
|
|
4304
|
+
}
|
|
4305
|
+
this.match = router.match.bind(router);
|
|
4306
|
+
this.#routers = [router];
|
|
4307
|
+
this.#routes = void 0;
|
|
4308
|
+
break;
|
|
4309
|
+
}
|
|
4310
|
+
if (i === len) {
|
|
4311
|
+
throw new Error("Fatal error");
|
|
4312
|
+
}
|
|
4313
|
+
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
|
4314
|
+
return res;
|
|
4315
|
+
}
|
|
4316
|
+
get activeRouter() {
|
|
4317
|
+
if (this.#routes || this.#routers.length !== 1) {
|
|
4318
|
+
throw new Error("No active router has been determined yet.");
|
|
4319
|
+
}
|
|
4320
|
+
return this.#routers[0];
|
|
4321
|
+
}
|
|
4322
|
+
};
|
|
4323
|
+
|
|
4324
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/trie-router/index.js
|
|
4325
|
+
init_cjs_shims();
|
|
4326
|
+
|
|
4327
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/trie-router/router.js
|
|
4328
|
+
init_cjs_shims();
|
|
4329
|
+
|
|
4330
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/trie-router/node.js
|
|
4331
|
+
init_cjs_shims();
|
|
4332
|
+
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
4333
|
+
var Node2 = class {
|
|
4334
|
+
#methods;
|
|
4335
|
+
#children;
|
|
4336
|
+
#patterns;
|
|
4337
|
+
#order = 0;
|
|
4338
|
+
#params = emptyParams;
|
|
4339
|
+
constructor(method, handler, children) {
|
|
4340
|
+
this.#children = children || /* @__PURE__ */ Object.create(null);
|
|
4341
|
+
this.#methods = [];
|
|
4342
|
+
if (method && handler) {
|
|
4343
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
4344
|
+
m[method] = { handler, possibleKeys: [], score: 0 };
|
|
4345
|
+
this.#methods = [m];
|
|
4346
|
+
}
|
|
4347
|
+
this.#patterns = [];
|
|
4348
|
+
}
|
|
4349
|
+
insert(method, path2, handler) {
|
|
4350
|
+
this.#order = ++this.#order;
|
|
4351
|
+
let curNode = this;
|
|
4352
|
+
const parts = splitRoutingPath(path2);
|
|
4353
|
+
const possibleKeys = [];
|
|
4354
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
4355
|
+
const p = parts[i];
|
|
4356
|
+
const nextP = parts[i + 1];
|
|
4357
|
+
const pattern = getPattern(p, nextP);
|
|
4358
|
+
const key = Array.isArray(pattern) ? pattern[0] : p;
|
|
4359
|
+
if (Object.keys(curNode.#children).includes(key)) {
|
|
4360
|
+
curNode = curNode.#children[key];
|
|
4361
|
+
const pattern2 = getPattern(p, nextP);
|
|
4362
|
+
if (pattern2) {
|
|
4363
|
+
possibleKeys.push(pattern2[1]);
|
|
4364
|
+
}
|
|
4365
|
+
continue;
|
|
4366
|
+
}
|
|
4367
|
+
curNode.#children[key] = new Node2();
|
|
4368
|
+
if (pattern) {
|
|
4369
|
+
curNode.#patterns.push(pattern);
|
|
4370
|
+
possibleKeys.push(pattern[1]);
|
|
4371
|
+
}
|
|
4372
|
+
curNode = curNode.#children[key];
|
|
4373
|
+
}
|
|
4374
|
+
const m = /* @__PURE__ */ Object.create(null);
|
|
4375
|
+
const handlerSet = {
|
|
4376
|
+
handler,
|
|
4377
|
+
possibleKeys: possibleKeys.filter((v, i, a) => a.indexOf(v) === i),
|
|
4378
|
+
score: this.#order
|
|
4379
|
+
};
|
|
4380
|
+
m[method] = handlerSet;
|
|
4381
|
+
curNode.#methods.push(m);
|
|
4382
|
+
return curNode;
|
|
4383
|
+
}
|
|
4384
|
+
#getHandlerSets(node, method, nodeParams, params) {
|
|
4385
|
+
const handlerSets = [];
|
|
4386
|
+
for (let i = 0, len = node.#methods.length; i < len; i++) {
|
|
4387
|
+
const m = node.#methods[i];
|
|
4388
|
+
const handlerSet = m[method] || m[METHOD_NAME_ALL];
|
|
4389
|
+
const processedSet = {};
|
|
4390
|
+
if (handlerSet !== void 0) {
|
|
4391
|
+
handlerSet.params = /* @__PURE__ */ Object.create(null);
|
|
4392
|
+
handlerSets.push(handlerSet);
|
|
4393
|
+
if (nodeParams !== emptyParams || params && params !== emptyParams) {
|
|
4394
|
+
for (let i2 = 0, len2 = handlerSet.possibleKeys.length; i2 < len2; i2++) {
|
|
4395
|
+
const key = handlerSet.possibleKeys[i2];
|
|
4396
|
+
const processed = processedSet[handlerSet.score];
|
|
4397
|
+
handlerSet.params[key] = params?.[key] && !processed ? params[key] : nodeParams[key] ?? params?.[key];
|
|
4398
|
+
processedSet[handlerSet.score] = true;
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
}
|
|
4402
|
+
}
|
|
4403
|
+
return handlerSets;
|
|
4404
|
+
}
|
|
4405
|
+
search(method, path2) {
|
|
4406
|
+
const handlerSets = [];
|
|
4407
|
+
this.#params = emptyParams;
|
|
4408
|
+
const curNode = this;
|
|
4409
|
+
let curNodes = [curNode];
|
|
4410
|
+
const parts = splitPath(path2);
|
|
4411
|
+
const curNodesQueue = [];
|
|
4412
|
+
for (let i = 0, len = parts.length; i < len; i++) {
|
|
4413
|
+
const part = parts[i];
|
|
4414
|
+
const isLast = i === len - 1;
|
|
4415
|
+
const tempNodes = [];
|
|
4416
|
+
for (let j = 0, len2 = curNodes.length; j < len2; j++) {
|
|
4417
|
+
const node = curNodes[j];
|
|
4418
|
+
const nextNode = node.#children[part];
|
|
4419
|
+
if (nextNode) {
|
|
4420
|
+
nextNode.#params = node.#params;
|
|
4421
|
+
if (isLast) {
|
|
4422
|
+
if (nextNode.#children["*"]) {
|
|
4423
|
+
handlerSets.push(
|
|
4424
|
+
...this.#getHandlerSets(nextNode.#children["*"], method, node.#params)
|
|
4425
|
+
);
|
|
4426
|
+
}
|
|
4427
|
+
handlerSets.push(...this.#getHandlerSets(nextNode, method, node.#params));
|
|
4428
|
+
} else {
|
|
4429
|
+
tempNodes.push(nextNode);
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
for (let k = 0, len3 = node.#patterns.length; k < len3; k++) {
|
|
4433
|
+
const pattern = node.#patterns[k];
|
|
4434
|
+
const params = node.#params === emptyParams ? {} : { ...node.#params };
|
|
4435
|
+
if (pattern === "*") {
|
|
4436
|
+
const astNode = node.#children["*"];
|
|
4437
|
+
if (astNode) {
|
|
4438
|
+
handlerSets.push(...this.#getHandlerSets(astNode, method, node.#params));
|
|
4439
|
+
astNode.#params = params;
|
|
4440
|
+
tempNodes.push(astNode);
|
|
4441
|
+
}
|
|
4442
|
+
continue;
|
|
4443
|
+
}
|
|
4444
|
+
if (part === "") {
|
|
4445
|
+
continue;
|
|
4446
|
+
}
|
|
4447
|
+
const [key, name, matcher] = pattern;
|
|
4448
|
+
const child = node.#children[key];
|
|
4449
|
+
const restPathString = parts.slice(i).join("/");
|
|
4450
|
+
if (matcher instanceof RegExp) {
|
|
4451
|
+
const m = matcher.exec(restPathString);
|
|
4452
|
+
if (m) {
|
|
4453
|
+
params[name] = m[0];
|
|
4454
|
+
handlerSets.push(...this.#getHandlerSets(child, method, node.#params, params));
|
|
4455
|
+
if (Object.keys(child.#children).length) {
|
|
4456
|
+
child.#params = params;
|
|
4457
|
+
const componentCount = m[0].match(/\//)?.length ?? 0;
|
|
4458
|
+
const targetCurNodes = curNodesQueue[componentCount] ||= [];
|
|
4459
|
+
targetCurNodes.push(child);
|
|
4460
|
+
}
|
|
4461
|
+
continue;
|
|
4462
|
+
}
|
|
4463
|
+
}
|
|
4464
|
+
if (matcher === true || matcher.test(part)) {
|
|
4465
|
+
params[name] = part;
|
|
4466
|
+
if (isLast) {
|
|
4467
|
+
handlerSets.push(...this.#getHandlerSets(child, method, params, node.#params));
|
|
4468
|
+
if (child.#children["*"]) {
|
|
4469
|
+
handlerSets.push(
|
|
4470
|
+
...this.#getHandlerSets(child.#children["*"], method, params, node.#params)
|
|
4471
|
+
);
|
|
4472
|
+
}
|
|
4473
|
+
} else {
|
|
4474
|
+
child.#params = params;
|
|
4475
|
+
tempNodes.push(child);
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
}
|
|
4479
|
+
}
|
|
4480
|
+
curNodes = tempNodes.concat(curNodesQueue.shift() ?? []);
|
|
4481
|
+
}
|
|
4482
|
+
if (handlerSets.length > 1) {
|
|
4483
|
+
handlerSets.sort((a, b) => {
|
|
4484
|
+
return a.score - b.score;
|
|
4485
|
+
});
|
|
4486
|
+
}
|
|
4487
|
+
return [handlerSets.map(({ handler, params }) => [handler, params])];
|
|
4488
|
+
}
|
|
4489
|
+
};
|
|
4490
|
+
|
|
4491
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/router/trie-router/router.js
|
|
4492
|
+
var TrieRouter = class {
|
|
4493
|
+
name = "TrieRouter";
|
|
4494
|
+
#node;
|
|
4495
|
+
constructor() {
|
|
4496
|
+
this.#node = new Node2();
|
|
4497
|
+
}
|
|
4498
|
+
add(method, path2, handler) {
|
|
4499
|
+
const results = checkOptionalParameter(path2);
|
|
4500
|
+
if (results) {
|
|
4501
|
+
for (let i = 0, len = results.length; i < len; i++) {
|
|
4502
|
+
this.#node.insert(method, results[i], handler);
|
|
4503
|
+
}
|
|
4504
|
+
return;
|
|
4505
|
+
}
|
|
4506
|
+
this.#node.insert(method, path2, handler);
|
|
4507
|
+
}
|
|
4508
|
+
match(method, path2) {
|
|
4509
|
+
return this.#node.search(method, path2);
|
|
4510
|
+
}
|
|
4511
|
+
};
|
|
4512
|
+
|
|
4513
|
+
// ../../.yarn/cache/hono-npm-4.7.4-9bd547bbac-b189c5b755.zip/node_modules/hono/dist/hono.js
|
|
4514
|
+
var Hono2 = class extends Hono {
|
|
4515
|
+
constructor(options = {}) {
|
|
4516
|
+
super(options);
|
|
4517
|
+
this.router = options.router ?? new SmartRouter({
|
|
4518
|
+
routers: [new RegExpRouter(), new TrieRouter()]
|
|
4519
|
+
});
|
|
4520
|
+
}
|
|
4521
|
+
};
|
|
4522
|
+
|
|
4523
|
+
// src/server.ts
|
|
4524
|
+
var app = new Hono2();
|
|
4525
|
+
app.get("/status", (c) => {
|
|
4526
|
+
c.header("X-React-Native-Project-Root", import_path.default.resolve(__dirname, "..", "react-native"));
|
|
4527
|
+
return c.text("packager-status:running");
|
|
4528
|
+
});
|
|
4529
|
+
app.get("/permissions", (c) => {
|
|
4530
|
+
return c.text("contacts:rw");
|
|
4531
|
+
});
|
|
4532
|
+
app.get("/oauth/scope", (c) => {
|
|
4533
|
+
return c.text("user_email;user_name");
|
|
4534
|
+
});
|
|
4535
|
+
app.get("/index.bundle", async (c) => {
|
|
4536
|
+
const platform = c.req.query("platform");
|
|
4537
|
+
const bundle = import_fs.default.readFileSync(import_path.default.resolve(__dirname, "..", "dist", `app-name.${platform}.js`), "utf-8");
|
|
4538
|
+
c.header("Surrogate-Control", "no-store");
|
|
4539
|
+
c.header("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate");
|
|
4540
|
+
c.header("Pragma", "no-cache");
|
|
4541
|
+
c.header("Expires", "0");
|
|
4542
|
+
c.header("Content-Type", "application/javascript");
|
|
4543
|
+
const result = await (0, import_core2.transform)(bundle, {
|
|
4544
|
+
plugins: [
|
|
4545
|
+
[
|
|
4546
|
+
"@apps-in-toss/babel-plugin-json",
|
|
4547
|
+
{
|
|
4548
|
+
json: {
|
|
4549
|
+
appName: "web-framework",
|
|
4550
|
+
webPort: 5173
|
|
4551
|
+
},
|
|
4552
|
+
identifierName: "Ait"
|
|
4553
|
+
}
|
|
4554
|
+
]
|
|
4555
|
+
]
|
|
4556
|
+
});
|
|
4557
|
+
if (!result?.code) {
|
|
4558
|
+
return c.text("Error", 500);
|
|
4559
|
+
}
|
|
4560
|
+
return c.body(result.code);
|
|
4561
|
+
});
|
|
4562
|
+
|
|
4563
|
+
// src/commands/DevCommand.ts
|
|
4564
|
+
var DevCommand = class extends Command {
|
|
4565
|
+
static paths = [[`dev`]];
|
|
4566
|
+
static usage = Command.Usage({
|
|
4567
|
+
category: "Development",
|
|
4568
|
+
description: "Bedrock \uAC1C\uBC1C \uC11C\uBC84\uB97C \uC2E4\uD589\uD569\uB2C8\uB2E4",
|
|
4569
|
+
examples: [["\uAC1C\uBC1C \uC11C\uBC84 \uC2E4\uD589\uD558\uAE30", "bedrock dev"]]
|
|
4570
|
+
});
|
|
4571
|
+
async execute() {
|
|
4572
|
+
serve(
|
|
4573
|
+
{
|
|
4574
|
+
hostname: "0.0.0.0",
|
|
4575
|
+
fetch: app.fetch,
|
|
4576
|
+
port: 8081
|
|
4577
|
+
},
|
|
4578
|
+
(info) => {
|
|
4579
|
+
console.log(`Listening on http://localhost:${info.port}`);
|
|
4580
|
+
}
|
|
4581
|
+
);
|
|
4582
|
+
}
|
|
4583
|
+
};
|
|
4584
|
+
|
|
4585
|
+
// src/cli.ts
|
|
4586
|
+
var cli = new Cli({
|
|
4587
|
+
binaryLabel: "bedrock",
|
|
4588
|
+
binaryName: "bedrock",
|
|
4589
|
+
enableCapture: true
|
|
4590
|
+
});
|
|
4591
|
+
async function initialize() {
|
|
4592
|
+
cli.register(DevCommand);
|
|
4593
|
+
cli.runExit(process.argv.slice(2));
|
|
4594
|
+
}
|
|
4595
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4596
|
+
0 && (module.exports = {
|
|
4597
|
+
initialize
|
|
4598
|
+
});
|