@tmturtle/cli 1.0.0
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/CHANGELOG.md +12 -0
- package/README.md +38 -0
- package/dist/tt.js +3812 -0
- package/package.json +31 -0
package/dist/tt.js
ADDED
|
@@ -0,0 +1,3812 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/objectSpread2-BvkFp-_Y.mjs
|
|
5
|
+
var __create = Object.create;
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __commonJS = (cb, mod) => function() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
16
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key;i < n; i++) {
|
|
17
|
+
key = keys[i];
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, {
|
|
20
|
+
get: ((k) => from[k]).bind(null, key),
|
|
21
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
27
|
+
value: mod,
|
|
28
|
+
enumerable: true
|
|
29
|
+
}) : target, mod));
|
|
30
|
+
var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
31
|
+
function _typeof$2(o) {
|
|
32
|
+
"@babel/helpers - typeof";
|
|
33
|
+
return module.exports = _typeof$2 = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(o$1) {
|
|
34
|
+
return typeof o$1;
|
|
35
|
+
} : function(o$1) {
|
|
36
|
+
return o$1 && typeof Symbol == "function" && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
37
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
38
|
+
}
|
|
39
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
40
|
+
} });
|
|
41
|
+
var require_toPrimitive = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
42
|
+
var _typeof$1 = require_typeof()["default"];
|
|
43
|
+
function toPrimitive$1(t, r) {
|
|
44
|
+
if (_typeof$1(t) != "object" || !t)
|
|
45
|
+
return t;
|
|
46
|
+
var e = t[Symbol.toPrimitive];
|
|
47
|
+
if (e !== undefined) {
|
|
48
|
+
var i = e.call(t, r || "default");
|
|
49
|
+
if (_typeof$1(i) != "object")
|
|
50
|
+
return i;
|
|
51
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
52
|
+
}
|
|
53
|
+
return (r === "string" ? String : Number)(t);
|
|
54
|
+
}
|
|
55
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
56
|
+
} });
|
|
57
|
+
var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
58
|
+
var _typeof = require_typeof()["default"];
|
|
59
|
+
var toPrimitive = require_toPrimitive();
|
|
60
|
+
function toPropertyKey$1(t) {
|
|
61
|
+
var i = toPrimitive(t, "string");
|
|
62
|
+
return _typeof(i) == "symbol" ? i : i + "";
|
|
63
|
+
}
|
|
64
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
65
|
+
} });
|
|
66
|
+
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
67
|
+
var toPropertyKey = require_toPropertyKey();
|
|
68
|
+
function _defineProperty(e, r, t) {
|
|
69
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
70
|
+
value: t,
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true
|
|
74
|
+
}) : e[r] = t, e;
|
|
75
|
+
}
|
|
76
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
77
|
+
} });
|
|
78
|
+
var require_objectSpread2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
79
|
+
var defineProperty = require_defineProperty();
|
|
80
|
+
function ownKeys(e, r) {
|
|
81
|
+
var t = Object.keys(e);
|
|
82
|
+
if (Object.getOwnPropertySymbols) {
|
|
83
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
84
|
+
r && (o = o.filter(function(r$1) {
|
|
85
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
86
|
+
})), t.push.apply(t, o);
|
|
87
|
+
}
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
function _objectSpread2(e) {
|
|
91
|
+
for (var r = 1;r < arguments.length; r++) {
|
|
92
|
+
var t = arguments[r] != null ? arguments[r] : {};
|
|
93
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
94
|
+
defineProperty(e, r$1, t[r$1]);
|
|
95
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
96
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return e;
|
|
100
|
+
}
|
|
101
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
102
|
+
} });
|
|
103
|
+
|
|
104
|
+
// ../../node_modules/.bun/@trpc+server@11.18.0+ff0372d108591aba/node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
|
|
105
|
+
function observable(subscribe) {
|
|
106
|
+
const self = {
|
|
107
|
+
subscribe(observer) {
|
|
108
|
+
let teardownRef = null;
|
|
109
|
+
let isDone = false;
|
|
110
|
+
let unsubscribed = false;
|
|
111
|
+
let teardownImmediately = false;
|
|
112
|
+
function unsubscribe() {
|
|
113
|
+
if (teardownRef === null) {
|
|
114
|
+
teardownImmediately = true;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (unsubscribed)
|
|
118
|
+
return;
|
|
119
|
+
unsubscribed = true;
|
|
120
|
+
if (typeof teardownRef === "function")
|
|
121
|
+
teardownRef();
|
|
122
|
+
else if (teardownRef)
|
|
123
|
+
teardownRef.unsubscribe();
|
|
124
|
+
}
|
|
125
|
+
teardownRef = subscribe({
|
|
126
|
+
next(value) {
|
|
127
|
+
var _observer$next;
|
|
128
|
+
if (isDone)
|
|
129
|
+
return;
|
|
130
|
+
(_observer$next = observer.next) === null || _observer$next === undefined || _observer$next.call(observer, value);
|
|
131
|
+
},
|
|
132
|
+
error(err) {
|
|
133
|
+
var _observer$error;
|
|
134
|
+
if (isDone)
|
|
135
|
+
return;
|
|
136
|
+
isDone = true;
|
|
137
|
+
(_observer$error = observer.error) === null || _observer$error === undefined || _observer$error.call(observer, err);
|
|
138
|
+
unsubscribe();
|
|
139
|
+
},
|
|
140
|
+
complete() {
|
|
141
|
+
var _observer$complete;
|
|
142
|
+
if (isDone)
|
|
143
|
+
return;
|
|
144
|
+
isDone = true;
|
|
145
|
+
(_observer$complete = observer.complete) === null || _observer$complete === undefined || _observer$complete.call(observer);
|
|
146
|
+
unsubscribe();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
if (teardownImmediately)
|
|
150
|
+
unsubscribe();
|
|
151
|
+
return { unsubscribe };
|
|
152
|
+
},
|
|
153
|
+
pipe(...operations) {
|
|
154
|
+
return operations.reduce(pipeReducer, self);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
return self;
|
|
158
|
+
}
|
|
159
|
+
function pipeReducer(prev, fn) {
|
|
160
|
+
return fn(prev);
|
|
161
|
+
}
|
|
162
|
+
function observableToPromise(observable$1) {
|
|
163
|
+
const ac = new AbortController;
|
|
164
|
+
const promise = new Promise((resolve, reject) => {
|
|
165
|
+
let isDone = false;
|
|
166
|
+
function onDone() {
|
|
167
|
+
if (isDone)
|
|
168
|
+
return;
|
|
169
|
+
isDone = true;
|
|
170
|
+
obs$.unsubscribe();
|
|
171
|
+
}
|
|
172
|
+
ac.signal.addEventListener("abort", () => {
|
|
173
|
+
reject(ac.signal.reason);
|
|
174
|
+
});
|
|
175
|
+
const obs$ = observable$1.subscribe({
|
|
176
|
+
next(data) {
|
|
177
|
+
isDone = true;
|
|
178
|
+
resolve(data);
|
|
179
|
+
onDone();
|
|
180
|
+
},
|
|
181
|
+
error(data) {
|
|
182
|
+
reject(data);
|
|
183
|
+
},
|
|
184
|
+
complete() {
|
|
185
|
+
ac.abort();
|
|
186
|
+
onDone();
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
return promise;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ../../node_modules/.bun/@trpc+server@11.18.0+ff0372d108591aba/node_modules/@trpc/server/dist/observable-CUiPknO-.mjs
|
|
194
|
+
function share(_opts) {
|
|
195
|
+
return (source) => {
|
|
196
|
+
let refCount = 0;
|
|
197
|
+
let subscription = null;
|
|
198
|
+
const observers = [];
|
|
199
|
+
function startIfNeeded() {
|
|
200
|
+
if (subscription)
|
|
201
|
+
return;
|
|
202
|
+
subscription = source.subscribe({
|
|
203
|
+
next(value) {
|
|
204
|
+
for (const observer of observers) {
|
|
205
|
+
var _observer$next;
|
|
206
|
+
(_observer$next = observer.next) === null || _observer$next === undefined || _observer$next.call(observer, value);
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
error(error) {
|
|
210
|
+
for (const observer of observers) {
|
|
211
|
+
var _observer$error;
|
|
212
|
+
(_observer$error = observer.error) === null || _observer$error === undefined || _observer$error.call(observer, error);
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
complete() {
|
|
216
|
+
for (const observer of observers) {
|
|
217
|
+
var _observer$complete;
|
|
218
|
+
(_observer$complete = observer.complete) === null || _observer$complete === undefined || _observer$complete.call(observer);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function resetIfNeeded() {
|
|
224
|
+
if (refCount === 0 && subscription) {
|
|
225
|
+
const _sub = subscription;
|
|
226
|
+
subscription = null;
|
|
227
|
+
_sub.unsubscribe();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return observable((subscriber) => {
|
|
231
|
+
refCount++;
|
|
232
|
+
observers.push(subscriber);
|
|
233
|
+
startIfNeeded();
|
|
234
|
+
return { unsubscribe() {
|
|
235
|
+
refCount--;
|
|
236
|
+
resetIfNeeded();
|
|
237
|
+
const index = observers.findIndex((v) => v === subscriber);
|
|
238
|
+
if (index > -1)
|
|
239
|
+
observers.splice(index, 1);
|
|
240
|
+
} };
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
var distinctUnsetMarker = Symbol();
|
|
245
|
+
function behaviorSubject(initialValue) {
|
|
246
|
+
let value = initialValue;
|
|
247
|
+
const observerList = [];
|
|
248
|
+
const addObserver = (observer) => {
|
|
249
|
+
if (value !== undefined)
|
|
250
|
+
observer.next(value);
|
|
251
|
+
observerList.push(observer);
|
|
252
|
+
};
|
|
253
|
+
const removeObserver = (observer) => {
|
|
254
|
+
observerList.splice(observerList.indexOf(observer), 1);
|
|
255
|
+
};
|
|
256
|
+
const obs = observable((observer) => {
|
|
257
|
+
addObserver(observer);
|
|
258
|
+
return () => {
|
|
259
|
+
removeObserver(observer);
|
|
260
|
+
};
|
|
261
|
+
});
|
|
262
|
+
obs.next = (nextValue) => {
|
|
263
|
+
if (value === nextValue)
|
|
264
|
+
return;
|
|
265
|
+
value = nextValue;
|
|
266
|
+
for (const observer of observerList)
|
|
267
|
+
observer.next(nextValue);
|
|
268
|
+
};
|
|
269
|
+
obs.get = () => value;
|
|
270
|
+
return obs;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/splitLink-B7Cuf2c_.mjs
|
|
274
|
+
function createChain(opts) {
|
|
275
|
+
return observable((observer) => {
|
|
276
|
+
function execute(index = 0, op = opts.op) {
|
|
277
|
+
const next = opts.links[index];
|
|
278
|
+
if (!next)
|
|
279
|
+
throw new Error("No more links to execute - did you forget to add an ending link?");
|
|
280
|
+
const subscription = next({
|
|
281
|
+
op,
|
|
282
|
+
next(nextOp) {
|
|
283
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
284
|
+
return nextObserver;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
return subscription;
|
|
288
|
+
}
|
|
289
|
+
const obs$ = execute();
|
|
290
|
+
return obs$.subscribe(observer);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// ../../node_modules/.bun/@trpc+server@11.18.0+ff0372d108591aba/node_modules/@trpc/server/dist/codes-DagpWZLc.mjs
|
|
295
|
+
function isObject(value) {
|
|
296
|
+
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
297
|
+
}
|
|
298
|
+
function emptyObject() {
|
|
299
|
+
return Object.create(null);
|
|
300
|
+
}
|
|
301
|
+
var TRPC_ERROR_CODES_BY_KEY = {
|
|
302
|
+
PARSE_ERROR: -32700,
|
|
303
|
+
BAD_REQUEST: -32600,
|
|
304
|
+
INTERNAL_SERVER_ERROR: -32603,
|
|
305
|
+
NOT_IMPLEMENTED: -32603,
|
|
306
|
+
BAD_GATEWAY: -32603,
|
|
307
|
+
SERVICE_UNAVAILABLE: -32603,
|
|
308
|
+
GATEWAY_TIMEOUT: -32603,
|
|
309
|
+
UNAUTHORIZED: -32001,
|
|
310
|
+
PAYMENT_REQUIRED: -32002,
|
|
311
|
+
FORBIDDEN: -32003,
|
|
312
|
+
NOT_FOUND: -32004,
|
|
313
|
+
METHOD_NOT_SUPPORTED: -32005,
|
|
314
|
+
TIMEOUT: -32008,
|
|
315
|
+
CONFLICT: -32009,
|
|
316
|
+
PRECONDITION_FAILED: -32012,
|
|
317
|
+
PAYLOAD_TOO_LARGE: -32013,
|
|
318
|
+
UNSUPPORTED_MEDIA_TYPE: -32015,
|
|
319
|
+
UNPROCESSABLE_CONTENT: -32022,
|
|
320
|
+
PRECONDITION_REQUIRED: -32028,
|
|
321
|
+
TOO_MANY_REQUESTS: -32029,
|
|
322
|
+
CLIENT_CLOSED_REQUEST: -32099
|
|
323
|
+
};
|
|
324
|
+
var retryableRpcCodes = [
|
|
325
|
+
TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
|
|
326
|
+
TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
|
|
327
|
+
TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
|
|
328
|
+
TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
|
|
329
|
+
];
|
|
330
|
+
|
|
331
|
+
// ../../node_modules/.bun/@trpc+server@11.18.0+ff0372d108591aba/node_modules/@trpc/server/dist/getErrorShape-BPSzUA7W.mjs
|
|
332
|
+
var __create2 = Object.create;
|
|
333
|
+
var __defProp2 = Object.defineProperty;
|
|
334
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
335
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
336
|
+
var __getProtoOf2 = Object.getPrototypeOf;
|
|
337
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
338
|
+
var __commonJS2 = (cb, mod) => function() {
|
|
339
|
+
return mod || (0, cb[__getOwnPropNames2(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
340
|
+
};
|
|
341
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
342
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
343
|
+
for (var keys = __getOwnPropNames2(from), i = 0, n = keys.length, key;i < n; i++) {
|
|
344
|
+
key = keys[i];
|
|
345
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
346
|
+
__defProp2(to, key, {
|
|
347
|
+
get: ((k) => from[k]).bind(null, key),
|
|
348
|
+
enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
return to;
|
|
352
|
+
};
|
|
353
|
+
var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create2(__getProtoOf2(mod)) : {}, __copyProps2(isNodeMode || !mod || !mod.__esModule ? __defProp2(target, "default", {
|
|
354
|
+
value: mod,
|
|
355
|
+
enumerable: true
|
|
356
|
+
}) : target, mod));
|
|
357
|
+
var noop = () => {};
|
|
358
|
+
var freezeIfAvailable = (obj) => {
|
|
359
|
+
if (Object.freeze)
|
|
360
|
+
Object.freeze(obj);
|
|
361
|
+
};
|
|
362
|
+
function createInnerProxy(callback, path, memo) {
|
|
363
|
+
var _memo$cacheKey;
|
|
364
|
+
const cacheKey = path.join(".");
|
|
365
|
+
(_memo$cacheKey = memo[cacheKey]) !== null && _memo$cacheKey !== undefined || (memo[cacheKey] = new Proxy(noop, {
|
|
366
|
+
get(_obj, key) {
|
|
367
|
+
if (typeof key !== "string" || key === "then")
|
|
368
|
+
return;
|
|
369
|
+
return createInnerProxy(callback, [...path, key], memo);
|
|
370
|
+
},
|
|
371
|
+
apply(_1, _2, args) {
|
|
372
|
+
const lastOfPath = path[path.length - 1];
|
|
373
|
+
if (lastOfPath === "valueOf" || lastOfPath === "toString" || lastOfPath === "toJSON") {
|
|
374
|
+
const debugPath = path.slice(0, -1).join(".");
|
|
375
|
+
return `tRPC.proxy(${debugPath})`;
|
|
376
|
+
}
|
|
377
|
+
let opts = {
|
|
378
|
+
args,
|
|
379
|
+
path
|
|
380
|
+
};
|
|
381
|
+
if (lastOfPath === "call")
|
|
382
|
+
opts = {
|
|
383
|
+
args: args.length >= 2 ? [args[1]] : [],
|
|
384
|
+
path: path.slice(0, -1)
|
|
385
|
+
};
|
|
386
|
+
else if (lastOfPath === "apply")
|
|
387
|
+
opts = {
|
|
388
|
+
args: args.length >= 2 ? args[1] : [],
|
|
389
|
+
path: path.slice(0, -1)
|
|
390
|
+
};
|
|
391
|
+
freezeIfAvailable(opts.args);
|
|
392
|
+
freezeIfAvailable(opts.path);
|
|
393
|
+
return callback(opts);
|
|
394
|
+
}
|
|
395
|
+
}));
|
|
396
|
+
return memo[cacheKey];
|
|
397
|
+
}
|
|
398
|
+
var createRecursiveProxy = (callback) => createInnerProxy(callback, [], emptyObject());
|
|
399
|
+
var createFlatProxy = (callback) => {
|
|
400
|
+
return new Proxy(noop, { get(_obj, name) {
|
|
401
|
+
if (name === "then")
|
|
402
|
+
return;
|
|
403
|
+
return callback(name);
|
|
404
|
+
} });
|
|
405
|
+
};
|
|
406
|
+
var require_typeof2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
407
|
+
function _typeof$2(o) {
|
|
408
|
+
"@babel/helpers - typeof";
|
|
409
|
+
return module.exports = _typeof$2 = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(o$1) {
|
|
410
|
+
return typeof o$1;
|
|
411
|
+
} : function(o$1) {
|
|
412
|
+
return o$1 && typeof Symbol == "function" && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
413
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
414
|
+
}
|
|
415
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
416
|
+
} });
|
|
417
|
+
var require_toPrimitive2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
418
|
+
var _typeof$1 = require_typeof2()["default"];
|
|
419
|
+
function toPrimitive$1(t, r) {
|
|
420
|
+
if (_typeof$1(t) != "object" || !t)
|
|
421
|
+
return t;
|
|
422
|
+
var e = t[Symbol.toPrimitive];
|
|
423
|
+
if (e !== undefined) {
|
|
424
|
+
var i = e.call(t, r || "default");
|
|
425
|
+
if (_typeof$1(i) != "object")
|
|
426
|
+
return i;
|
|
427
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
428
|
+
}
|
|
429
|
+
return (r === "string" ? String : Number)(t);
|
|
430
|
+
}
|
|
431
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
432
|
+
} });
|
|
433
|
+
var require_toPropertyKey2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
434
|
+
var _typeof = require_typeof2()["default"];
|
|
435
|
+
var toPrimitive = require_toPrimitive2();
|
|
436
|
+
function toPropertyKey$1(t) {
|
|
437
|
+
var i = toPrimitive(t, "string");
|
|
438
|
+
return _typeof(i) == "symbol" ? i : i + "";
|
|
439
|
+
}
|
|
440
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
441
|
+
} });
|
|
442
|
+
var require_defineProperty2 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
443
|
+
var toPropertyKey = require_toPropertyKey2();
|
|
444
|
+
function _defineProperty(e, r, t) {
|
|
445
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
446
|
+
value: t,
|
|
447
|
+
enumerable: true,
|
|
448
|
+
configurable: true,
|
|
449
|
+
writable: true
|
|
450
|
+
}) : e[r] = t, e;
|
|
451
|
+
}
|
|
452
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
453
|
+
} });
|
|
454
|
+
var require_objectSpread22 = __commonJS2({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
455
|
+
var defineProperty = require_defineProperty2();
|
|
456
|
+
function ownKeys(e, r) {
|
|
457
|
+
var t = Object.keys(e);
|
|
458
|
+
if (Object.getOwnPropertySymbols) {
|
|
459
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
460
|
+
r && (o = o.filter(function(r$1) {
|
|
461
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
462
|
+
})), t.push.apply(t, o);
|
|
463
|
+
}
|
|
464
|
+
return t;
|
|
465
|
+
}
|
|
466
|
+
function _objectSpread2(e) {
|
|
467
|
+
for (var r = 1;r < arguments.length; r++) {
|
|
468
|
+
var t = arguments[r] != null ? arguments[r] : {};
|
|
469
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function(r$1) {
|
|
470
|
+
defineProperty(e, r$1, t[r$1]);
|
|
471
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
472
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
return e;
|
|
476
|
+
}
|
|
477
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
478
|
+
} });
|
|
479
|
+
var import_objectSpread2 = __toESM2(require_objectSpread22(), 1);
|
|
480
|
+
|
|
481
|
+
// ../../node_modules/.bun/@trpc+server@11.18.0+ff0372d108591aba/node_modules/@trpc/server/dist/tracked-DWInO6EQ.mjs
|
|
482
|
+
var import_defineProperty = __toESM2(require_defineProperty2(), 1);
|
|
483
|
+
var import_objectSpread2$1 = __toESM2(require_objectSpread22(), 1);
|
|
484
|
+
function transformResultInner(response, transformer) {
|
|
485
|
+
if ("error" in response) {
|
|
486
|
+
const error = transformer.deserialize(response.error);
|
|
487
|
+
return {
|
|
488
|
+
ok: false,
|
|
489
|
+
error: (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, response), {}, { error })
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
const result = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, response.result), (!response.result.type || response.result.type === "data") && {
|
|
493
|
+
type: "data",
|
|
494
|
+
data: transformer.deserialize(response.result.data)
|
|
495
|
+
});
|
|
496
|
+
return {
|
|
497
|
+
ok: true,
|
|
498
|
+
result
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
var TransformResultError = class extends Error {
|
|
502
|
+
constructor() {
|
|
503
|
+
super("Unable to transform response from server");
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
function transformResult(response, transformer) {
|
|
507
|
+
let result;
|
|
508
|
+
try {
|
|
509
|
+
result = transformResultInner(response, transformer);
|
|
510
|
+
} catch (_unused) {
|
|
511
|
+
throw new TransformResultError;
|
|
512
|
+
}
|
|
513
|
+
if (!result.ok && (!isObject(result.error.error) || typeof result.error.error["code"] !== "number"))
|
|
514
|
+
throw new TransformResultError;
|
|
515
|
+
if (result.ok && !isObject(result.result))
|
|
516
|
+
throw new TransformResultError;
|
|
517
|
+
return result;
|
|
518
|
+
}
|
|
519
|
+
var import_objectSpread22 = __toESM2(require_objectSpread22(), 1);
|
|
520
|
+
var trackedSymbol = Symbol();
|
|
521
|
+
|
|
522
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/TRPCClientError-apv8gw59.mjs
|
|
523
|
+
var import_defineProperty2 = __toESM(require_defineProperty(), 1);
|
|
524
|
+
var import_objectSpread23 = __toESM(require_objectSpread2(), 1);
|
|
525
|
+
function isTRPCClientError(cause) {
|
|
526
|
+
return cause instanceof TRPCClientError;
|
|
527
|
+
}
|
|
528
|
+
function isTRPCErrorResponse(obj) {
|
|
529
|
+
return isObject(obj) && isObject(obj["error"]) && typeof obj["error"]["code"] === "number" && typeof obj["error"]["message"] === "string";
|
|
530
|
+
}
|
|
531
|
+
function getMessageFromUnknownError(err, fallback) {
|
|
532
|
+
if (typeof err === "string")
|
|
533
|
+
return err;
|
|
534
|
+
if (isObject(err) && typeof err["message"] === "string")
|
|
535
|
+
return err["message"];
|
|
536
|
+
return fallback;
|
|
537
|
+
}
|
|
538
|
+
var TRPCClientError = class TRPCClientError2 extends Error {
|
|
539
|
+
constructor(message, opts) {
|
|
540
|
+
var _opts$result, _opts$result2;
|
|
541
|
+
const cause = opts === null || opts === undefined ? undefined : opts.cause;
|
|
542
|
+
super(message, { cause });
|
|
543
|
+
(0, import_defineProperty2.default)(this, "cause", undefined);
|
|
544
|
+
(0, import_defineProperty2.default)(this, "shape", undefined);
|
|
545
|
+
(0, import_defineProperty2.default)(this, "data", undefined);
|
|
546
|
+
(0, import_defineProperty2.default)(this, "meta", undefined);
|
|
547
|
+
this.meta = opts === null || opts === undefined ? undefined : opts.meta;
|
|
548
|
+
this.cause = cause;
|
|
549
|
+
this.shape = opts === null || opts === undefined || (_opts$result = opts.result) === null || _opts$result === undefined ? undefined : _opts$result.error;
|
|
550
|
+
this.data = opts === null || opts === undefined || (_opts$result2 = opts.result) === null || _opts$result2 === undefined ? undefined : _opts$result2.error.data;
|
|
551
|
+
this.name = "TRPCClientError";
|
|
552
|
+
Object.setPrototypeOf(this, TRPCClientError2.prototype);
|
|
553
|
+
}
|
|
554
|
+
static from(_cause, opts = {}) {
|
|
555
|
+
const cause = _cause;
|
|
556
|
+
if (isTRPCClientError(cause)) {
|
|
557
|
+
if (opts.meta)
|
|
558
|
+
cause.meta = (0, import_objectSpread23.default)((0, import_objectSpread23.default)({}, cause.meta), opts.meta);
|
|
559
|
+
return cause;
|
|
560
|
+
}
|
|
561
|
+
if (isTRPCErrorResponse(cause))
|
|
562
|
+
return new TRPCClientError2(cause.error.message, (0, import_objectSpread23.default)((0, import_objectSpread23.default)({}, opts), {}, {
|
|
563
|
+
result: cause,
|
|
564
|
+
cause: opts.cause
|
|
565
|
+
}));
|
|
566
|
+
return new TRPCClientError2(getMessageFromUnknownError(cause, "Unknown error"), (0, import_objectSpread23.default)((0, import_objectSpread23.default)({}, opts), {}, { cause }));
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/unstable-internals-Bg7n9BBj.mjs
|
|
571
|
+
function getTransformer(transformer) {
|
|
572
|
+
const _transformer = transformer;
|
|
573
|
+
if (!_transformer)
|
|
574
|
+
return {
|
|
575
|
+
input: {
|
|
576
|
+
serialize: (data) => data,
|
|
577
|
+
deserialize: (data) => data
|
|
578
|
+
},
|
|
579
|
+
output: {
|
|
580
|
+
serialize: (data) => data,
|
|
581
|
+
deserialize: (data) => data
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
if ("input" in _transformer)
|
|
585
|
+
return _transformer;
|
|
586
|
+
return {
|
|
587
|
+
input: _transformer,
|
|
588
|
+
output: _transformer
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/httpUtils-BNq9QC3d.mjs
|
|
593
|
+
var isFunction2 = (fn) => typeof fn === "function";
|
|
594
|
+
function getFetch(customFetchImpl) {
|
|
595
|
+
if (customFetchImpl)
|
|
596
|
+
return customFetchImpl;
|
|
597
|
+
if (typeof window !== "undefined" && isFunction2(window.fetch))
|
|
598
|
+
return window.fetch;
|
|
599
|
+
if (typeof globalThis !== "undefined" && isFunction2(globalThis.fetch))
|
|
600
|
+
return globalThis.fetch;
|
|
601
|
+
throw new Error("No fetch implementation found");
|
|
602
|
+
}
|
|
603
|
+
var import_objectSpread24 = __toESM(require_objectSpread2());
|
|
604
|
+
function resolveHTTPLinkOptions(opts) {
|
|
605
|
+
return {
|
|
606
|
+
url: opts.url.toString(),
|
|
607
|
+
fetch: opts.fetch,
|
|
608
|
+
transformer: getTransformer(opts.transformer),
|
|
609
|
+
methodOverride: opts.methodOverride
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function arrayToDict(array) {
|
|
613
|
+
const dict = {};
|
|
614
|
+
for (let index = 0;index < array.length; index++) {
|
|
615
|
+
const element = array[index];
|
|
616
|
+
dict[index] = element;
|
|
617
|
+
}
|
|
618
|
+
return dict;
|
|
619
|
+
}
|
|
620
|
+
var METHOD = {
|
|
621
|
+
query: "GET",
|
|
622
|
+
mutation: "POST",
|
|
623
|
+
subscription: "PATCH"
|
|
624
|
+
};
|
|
625
|
+
function getInput(opts) {
|
|
626
|
+
return "input" in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input) => opts.transformer.input.serialize(_input)));
|
|
627
|
+
}
|
|
628
|
+
var getUrl = (opts) => {
|
|
629
|
+
const parts = opts.url.split("?");
|
|
630
|
+
const base = parts[0].replace(/\/$/, "");
|
|
631
|
+
let url = base + "/" + opts.path;
|
|
632
|
+
const queryParts = [];
|
|
633
|
+
if (parts[1])
|
|
634
|
+
queryParts.push(parts[1]);
|
|
635
|
+
if ("inputs" in opts)
|
|
636
|
+
queryParts.push("batch=1");
|
|
637
|
+
if (opts.type === "query" || opts.type === "subscription") {
|
|
638
|
+
const input = getInput(opts);
|
|
639
|
+
if (input !== undefined && opts.methodOverride !== "POST")
|
|
640
|
+
queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
641
|
+
}
|
|
642
|
+
if (queryParts.length)
|
|
643
|
+
url += "?" + queryParts.join("&");
|
|
644
|
+
return url;
|
|
645
|
+
};
|
|
646
|
+
var getBody = (opts) => {
|
|
647
|
+
if (opts.type === "query" && opts.methodOverride !== "POST")
|
|
648
|
+
return;
|
|
649
|
+
const input = getInput(opts);
|
|
650
|
+
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
651
|
+
};
|
|
652
|
+
var jsonHttpRequester = (opts) => {
|
|
653
|
+
return httpRequest((0, import_objectSpread24.default)((0, import_objectSpread24.default)({}, opts), {}, {
|
|
654
|
+
contentTypeHeader: "application/json",
|
|
655
|
+
getUrl,
|
|
656
|
+
getBody
|
|
657
|
+
}));
|
|
658
|
+
};
|
|
659
|
+
var AbortError = class extends Error {
|
|
660
|
+
constructor() {
|
|
661
|
+
const name = "AbortError";
|
|
662
|
+
super(name);
|
|
663
|
+
this.name = name;
|
|
664
|
+
this.message = name;
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
var throwIfAborted = (signal) => {
|
|
668
|
+
var _signal$throwIfAborte;
|
|
669
|
+
if (!(signal === null || signal === undefined ? undefined : signal.aborted))
|
|
670
|
+
return;
|
|
671
|
+
(_signal$throwIfAborte = signal.throwIfAborted) === null || _signal$throwIfAborte === undefined || _signal$throwIfAborte.call(signal);
|
|
672
|
+
if (typeof DOMException !== "undefined")
|
|
673
|
+
throw new DOMException("AbortError", "AbortError");
|
|
674
|
+
throw new AbortError;
|
|
675
|
+
};
|
|
676
|
+
async function fetchHTTPResponse(opts) {
|
|
677
|
+
var _opts$methodOverride, _opts$trpcAcceptHeade;
|
|
678
|
+
throwIfAborted(opts.signal);
|
|
679
|
+
const url = opts.getUrl(opts);
|
|
680
|
+
const body = opts.getBody(opts);
|
|
681
|
+
const method = (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== undefined ? _opts$methodOverride : METHOD[opts.type];
|
|
682
|
+
const resolvedHeaders = await (async () => {
|
|
683
|
+
const heads = await opts.headers();
|
|
684
|
+
if (Symbol.iterator in heads)
|
|
685
|
+
return Object.fromEntries(heads);
|
|
686
|
+
return heads;
|
|
687
|
+
})();
|
|
688
|
+
const headers = (0, import_objectSpread24.default)((0, import_objectSpread24.default)((0, import_objectSpread24.default)({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { [(_opts$trpcAcceptHeade = opts.trpcAcceptHeaderKey) !== null && _opts$trpcAcceptHeade !== undefined ? _opts$trpcAcceptHeade : "trpc-accept"]: opts.trpcAcceptHeader } : undefined), resolvedHeaders);
|
|
689
|
+
return getFetch(opts.fetch)(url, {
|
|
690
|
+
method,
|
|
691
|
+
signal: opts.signal,
|
|
692
|
+
body,
|
|
693
|
+
headers
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
async function httpRequest(opts) {
|
|
697
|
+
const meta = {};
|
|
698
|
+
const res = await fetchHTTPResponse(opts);
|
|
699
|
+
meta.response = res;
|
|
700
|
+
const json = await res.json();
|
|
701
|
+
meta.responseJSON = json;
|
|
702
|
+
return {
|
|
703
|
+
json,
|
|
704
|
+
meta
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/httpLink-oiU8eqFi.mjs
|
|
709
|
+
function isOctetType(input) {
|
|
710
|
+
return input instanceof Uint8Array || input instanceof Blob;
|
|
711
|
+
}
|
|
712
|
+
function isFormData(input) {
|
|
713
|
+
return input instanceof FormData;
|
|
714
|
+
}
|
|
715
|
+
var import_objectSpread25 = __toESM(require_objectSpread2(), 1);
|
|
716
|
+
var universalRequester = (opts) => {
|
|
717
|
+
if ("input" in opts) {
|
|
718
|
+
const { input } = opts;
|
|
719
|
+
if (isFormData(input)) {
|
|
720
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST")
|
|
721
|
+
throw new Error("FormData is only supported for mutations");
|
|
722
|
+
return httpRequest((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, opts), {}, {
|
|
723
|
+
contentTypeHeader: undefined,
|
|
724
|
+
getUrl,
|
|
725
|
+
getBody: () => input
|
|
726
|
+
}));
|
|
727
|
+
}
|
|
728
|
+
if (isOctetType(input)) {
|
|
729
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST")
|
|
730
|
+
throw new Error("Octet type input is only supported for mutations");
|
|
731
|
+
return httpRequest((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, opts), {}, {
|
|
732
|
+
contentTypeHeader: "application/octet-stream",
|
|
733
|
+
getUrl,
|
|
734
|
+
getBody: () => input
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return jsonHttpRequester(opts);
|
|
739
|
+
};
|
|
740
|
+
function httpLink(opts) {
|
|
741
|
+
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
742
|
+
return () => {
|
|
743
|
+
return (operationOpts) => {
|
|
744
|
+
const { op } = operationOpts;
|
|
745
|
+
return observable((observer) => {
|
|
746
|
+
const { path, input, type } = op;
|
|
747
|
+
if (type === "subscription")
|
|
748
|
+
throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
749
|
+
const request = universalRequester((0, import_objectSpread25.default)((0, import_objectSpread25.default)({}, resolvedOpts), {}, {
|
|
750
|
+
type,
|
|
751
|
+
path,
|
|
752
|
+
input,
|
|
753
|
+
signal: op.signal,
|
|
754
|
+
headers() {
|
|
755
|
+
if (!opts.headers)
|
|
756
|
+
return {};
|
|
757
|
+
if (typeof opts.headers === "function")
|
|
758
|
+
return opts.headers({ op });
|
|
759
|
+
return opts.headers;
|
|
760
|
+
}
|
|
761
|
+
}));
|
|
762
|
+
let meta = undefined;
|
|
763
|
+
request.then((res) => {
|
|
764
|
+
meta = res.meta;
|
|
765
|
+
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
766
|
+
if (!transformed.ok) {
|
|
767
|
+
observer.error(TRPCClientError.from(transformed.error, { meta }));
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
observer.next({
|
|
771
|
+
context: res.meta,
|
|
772
|
+
result: transformed.result
|
|
773
|
+
});
|
|
774
|
+
observer.complete();
|
|
775
|
+
}).catch((cause) => {
|
|
776
|
+
observer.error(TRPCClientError.from(cause, { meta }));
|
|
777
|
+
});
|
|
778
|
+
return () => {};
|
|
779
|
+
});
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/httpBatchLink-CaWjh1oW.mjs
|
|
785
|
+
var import_objectSpread26 = __toESM(require_objectSpread2(), 1);
|
|
786
|
+
|
|
787
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/loggerLink-ineCN1PO.mjs
|
|
788
|
+
var import_objectSpread27 = __toESM(require_objectSpread2(), 1);
|
|
789
|
+
|
|
790
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/wsLink-DSf4KOdW.mjs
|
|
791
|
+
var resultOf = (value, ...args) => {
|
|
792
|
+
return typeof value === "function" ? value(...args) : value;
|
|
793
|
+
};
|
|
794
|
+
var import_defineProperty$3 = __toESM(require_defineProperty(), 1);
|
|
795
|
+
function withResolvers() {
|
|
796
|
+
let resolve;
|
|
797
|
+
let reject;
|
|
798
|
+
const promise = new Promise((res, rej) => {
|
|
799
|
+
resolve = res;
|
|
800
|
+
reject = rej;
|
|
801
|
+
});
|
|
802
|
+
return {
|
|
803
|
+
promise,
|
|
804
|
+
resolve,
|
|
805
|
+
reject
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
async function prepareUrl(urlOptions) {
|
|
809
|
+
const url = await resultOf(urlOptions.url);
|
|
810
|
+
if (!urlOptions.connectionParams)
|
|
811
|
+
return url;
|
|
812
|
+
const prefix = url.includes("?") ? "&" : "?";
|
|
813
|
+
const connectionParams = `${prefix}connectionParams=1`;
|
|
814
|
+
return url + connectionParams;
|
|
815
|
+
}
|
|
816
|
+
async function buildConnectionMessage(connectionParams, encoder) {
|
|
817
|
+
const message = {
|
|
818
|
+
method: "connectionParams",
|
|
819
|
+
data: await resultOf(connectionParams)
|
|
820
|
+
};
|
|
821
|
+
return encoder.encode(message);
|
|
822
|
+
}
|
|
823
|
+
var import_defineProperty$2 = __toESM(require_defineProperty(), 1);
|
|
824
|
+
var import_defineProperty$1 = __toESM(require_defineProperty(), 1);
|
|
825
|
+
function asyncWsOpen(ws) {
|
|
826
|
+
const { promise, resolve, reject } = withResolvers();
|
|
827
|
+
ws.addEventListener("open", () => {
|
|
828
|
+
ws.removeEventListener("error", reject);
|
|
829
|
+
resolve();
|
|
830
|
+
});
|
|
831
|
+
ws.addEventListener("error", reject);
|
|
832
|
+
return promise;
|
|
833
|
+
}
|
|
834
|
+
function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
|
|
835
|
+
let pingTimeout;
|
|
836
|
+
let pongTimeout;
|
|
837
|
+
function start() {
|
|
838
|
+
pingTimeout = setTimeout(() => {
|
|
839
|
+
ws.send("PING");
|
|
840
|
+
pongTimeout = setTimeout(() => {
|
|
841
|
+
ws.close();
|
|
842
|
+
}, pongTimeoutMs);
|
|
843
|
+
}, intervalMs);
|
|
844
|
+
}
|
|
845
|
+
function reset() {
|
|
846
|
+
clearTimeout(pingTimeout);
|
|
847
|
+
start();
|
|
848
|
+
}
|
|
849
|
+
function pong() {
|
|
850
|
+
clearTimeout(pongTimeout);
|
|
851
|
+
reset();
|
|
852
|
+
}
|
|
853
|
+
ws.addEventListener("open", start);
|
|
854
|
+
ws.addEventListener("message", ({ data }) => {
|
|
855
|
+
clearTimeout(pingTimeout);
|
|
856
|
+
start();
|
|
857
|
+
if (data === "PONG")
|
|
858
|
+
pong();
|
|
859
|
+
});
|
|
860
|
+
ws.addEventListener("close", () => {
|
|
861
|
+
clearTimeout(pingTimeout);
|
|
862
|
+
clearTimeout(pongTimeout);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
var WsConnection = class WsConnection2 {
|
|
866
|
+
constructor(opts) {
|
|
867
|
+
var _opts$WebSocketPonyfi;
|
|
868
|
+
(0, import_defineProperty$1.default)(this, "id", ++WsConnection2.connectCount);
|
|
869
|
+
(0, import_defineProperty$1.default)(this, "WebSocketPonyfill", undefined);
|
|
870
|
+
(0, import_defineProperty$1.default)(this, "urlOptions", undefined);
|
|
871
|
+
(0, import_defineProperty$1.default)(this, "keepAliveOpts", undefined);
|
|
872
|
+
(0, import_defineProperty$1.default)(this, "encoder", undefined);
|
|
873
|
+
(0, import_defineProperty$1.default)(this, "wsObservable", behaviorSubject(null));
|
|
874
|
+
(0, import_defineProperty$1.default)(this, "openPromise", null);
|
|
875
|
+
this.WebSocketPonyfill = (_opts$WebSocketPonyfi = opts.WebSocketPonyfill) !== null && _opts$WebSocketPonyfi !== undefined ? _opts$WebSocketPonyfi : WebSocket;
|
|
876
|
+
if (!this.WebSocketPonyfill)
|
|
877
|
+
throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill");
|
|
878
|
+
this.urlOptions = opts.urlOptions;
|
|
879
|
+
this.keepAliveOpts = opts.keepAlive;
|
|
880
|
+
this.encoder = opts.encoder;
|
|
881
|
+
}
|
|
882
|
+
get ws() {
|
|
883
|
+
return this.wsObservable.get();
|
|
884
|
+
}
|
|
885
|
+
set ws(ws) {
|
|
886
|
+
this.wsObservable.next(ws);
|
|
887
|
+
}
|
|
888
|
+
isOpen() {
|
|
889
|
+
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise;
|
|
890
|
+
}
|
|
891
|
+
isClosed() {
|
|
892
|
+
return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
|
|
893
|
+
}
|
|
894
|
+
async open() {
|
|
895
|
+
var _this = this;
|
|
896
|
+
if (_this.openPromise)
|
|
897
|
+
return _this.openPromise;
|
|
898
|
+
_this.id = ++WsConnection2.connectCount;
|
|
899
|
+
const wsPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url));
|
|
900
|
+
_this.openPromise = wsPromise.then(async (ws) => {
|
|
901
|
+
_this.ws = ws;
|
|
902
|
+
ws.binaryType = "arraybuffer";
|
|
903
|
+
ws.addEventListener("message", function({ data }) {
|
|
904
|
+
if (data === "PING")
|
|
905
|
+
this.send("PONG");
|
|
906
|
+
});
|
|
907
|
+
if (_this.keepAliveOpts.enabled)
|
|
908
|
+
setupPingInterval(ws, _this.keepAliveOpts);
|
|
909
|
+
ws.addEventListener("close", () => {
|
|
910
|
+
if (_this.ws === ws)
|
|
911
|
+
_this.ws = null;
|
|
912
|
+
});
|
|
913
|
+
await asyncWsOpen(ws);
|
|
914
|
+
if (_this.urlOptions.connectionParams)
|
|
915
|
+
ws.send(await buildConnectionMessage(_this.urlOptions.connectionParams, _this.encoder));
|
|
916
|
+
});
|
|
917
|
+
try {
|
|
918
|
+
await _this.openPromise;
|
|
919
|
+
} finally {
|
|
920
|
+
_this.openPromise = null;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
async close() {
|
|
924
|
+
var _this2 = this;
|
|
925
|
+
try {
|
|
926
|
+
await _this2.openPromise;
|
|
927
|
+
} finally {
|
|
928
|
+
var _this$ws;
|
|
929
|
+
(_this$ws = _this2.ws) === null || _this$ws === undefined || _this$ws.close();
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
(0, import_defineProperty$1.default)(WsConnection, "connectCount", 0);
|
|
934
|
+
var import_defineProperty3 = __toESM(require_defineProperty(), 1);
|
|
935
|
+
var import_objectSpread28 = __toESM(require_objectSpread2(), 1);
|
|
936
|
+
|
|
937
|
+
// ../../node_modules/.bun/@trpc+client@11.18.0+7b465c878e2c7c1e/node_modules/@trpc/client/dist/index.mjs
|
|
938
|
+
var import_defineProperty4 = __toESM(require_defineProperty(), 1);
|
|
939
|
+
var import_objectSpread2$4 = __toESM(require_objectSpread2(), 1);
|
|
940
|
+
var TRPCUntypedClient = class {
|
|
941
|
+
constructor(opts) {
|
|
942
|
+
(0, import_defineProperty4.default)(this, "links", undefined);
|
|
943
|
+
(0, import_defineProperty4.default)(this, "runtime", undefined);
|
|
944
|
+
(0, import_defineProperty4.default)(this, "requestId", undefined);
|
|
945
|
+
this.requestId = 0;
|
|
946
|
+
this.runtime = {};
|
|
947
|
+
this.links = opts.links.map((link) => link(this.runtime));
|
|
948
|
+
}
|
|
949
|
+
$request(opts) {
|
|
950
|
+
var _opts$context;
|
|
951
|
+
const chain$ = createChain({
|
|
952
|
+
links: this.links,
|
|
953
|
+
op: (0, import_objectSpread2$4.default)((0, import_objectSpread2$4.default)({}, opts), {}, {
|
|
954
|
+
context: (_opts$context = opts.context) !== null && _opts$context !== undefined ? _opts$context : {},
|
|
955
|
+
id: ++this.requestId
|
|
956
|
+
})
|
|
957
|
+
});
|
|
958
|
+
return chain$.pipe(share());
|
|
959
|
+
}
|
|
960
|
+
async requestAsPromise(opts) {
|
|
961
|
+
var _this = this;
|
|
962
|
+
try {
|
|
963
|
+
const req$ = _this.$request(opts);
|
|
964
|
+
const envelope = await observableToPromise(req$);
|
|
965
|
+
const data = envelope.result.data;
|
|
966
|
+
return data;
|
|
967
|
+
} catch (err) {
|
|
968
|
+
throw TRPCClientError.from(err);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
query(path, input, opts) {
|
|
972
|
+
return this.requestAsPromise({
|
|
973
|
+
type: "query",
|
|
974
|
+
path,
|
|
975
|
+
input,
|
|
976
|
+
context: opts === null || opts === undefined ? undefined : opts.context,
|
|
977
|
+
signal: opts === null || opts === undefined ? undefined : opts.signal
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
mutation(path, input, opts) {
|
|
981
|
+
return this.requestAsPromise({
|
|
982
|
+
type: "mutation",
|
|
983
|
+
path,
|
|
984
|
+
input,
|
|
985
|
+
context: opts === null || opts === undefined ? undefined : opts.context,
|
|
986
|
+
signal: opts === null || opts === undefined ? undefined : opts.signal
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
subscription(path, input, opts) {
|
|
990
|
+
const observable$ = this.$request({
|
|
991
|
+
type: "subscription",
|
|
992
|
+
path,
|
|
993
|
+
input,
|
|
994
|
+
context: opts.context,
|
|
995
|
+
signal: opts.signal
|
|
996
|
+
});
|
|
997
|
+
return observable$.subscribe({
|
|
998
|
+
next(envelope) {
|
|
999
|
+
switch (envelope.result.type) {
|
|
1000
|
+
case "state": {
|
|
1001
|
+
var _opts$onConnectionSta;
|
|
1002
|
+
(_opts$onConnectionSta = opts.onConnectionStateChange) === null || _opts$onConnectionSta === undefined || _opts$onConnectionSta.call(opts, envelope.result);
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
case "started": {
|
|
1006
|
+
var _opts$onStarted;
|
|
1007
|
+
(_opts$onStarted = opts.onStarted) === null || _opts$onStarted === undefined || _opts$onStarted.call(opts, { context: envelope.context });
|
|
1008
|
+
break;
|
|
1009
|
+
}
|
|
1010
|
+
case "stopped": {
|
|
1011
|
+
var _opts$onStopped;
|
|
1012
|
+
(_opts$onStopped = opts.onStopped) === null || _opts$onStopped === undefined || _opts$onStopped.call(opts);
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
case "data":
|
|
1016
|
+
case undefined: {
|
|
1017
|
+
var _opts$onData;
|
|
1018
|
+
(_opts$onData = opts.onData) === null || _opts$onData === undefined || _opts$onData.call(opts, envelope.result.data);
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
},
|
|
1023
|
+
error(err) {
|
|
1024
|
+
var _opts$onError;
|
|
1025
|
+
(_opts$onError = opts.onError) === null || _opts$onError === undefined || _opts$onError.call(opts, err);
|
|
1026
|
+
},
|
|
1027
|
+
complete() {
|
|
1028
|
+
var _opts$onComplete;
|
|
1029
|
+
(_opts$onComplete = opts.onComplete) === null || _opts$onComplete === undefined || _opts$onComplete.call(opts);
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
var untypedClientSymbol = Symbol.for("trpc_untypedClient");
|
|
1035
|
+
var clientCallTypeMap = {
|
|
1036
|
+
query: "query",
|
|
1037
|
+
mutate: "mutation",
|
|
1038
|
+
subscribe: "subscription"
|
|
1039
|
+
};
|
|
1040
|
+
var clientCallTypeToProcedureType = (clientCallType) => {
|
|
1041
|
+
return clientCallTypeMap[clientCallType];
|
|
1042
|
+
};
|
|
1043
|
+
function createTRPCClientProxy(client) {
|
|
1044
|
+
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
1045
|
+
const pathCopy = [...path];
|
|
1046
|
+
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
1047
|
+
const fullPath = pathCopy.join(".");
|
|
1048
|
+
return client[procedureType](fullPath, ...args);
|
|
1049
|
+
});
|
|
1050
|
+
return createFlatProxy((key) => {
|
|
1051
|
+
if (key === untypedClientSymbol)
|
|
1052
|
+
return client;
|
|
1053
|
+
return proxy[key];
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
function createTRPCClient(opts) {
|
|
1057
|
+
const client = new TRPCUntypedClient(opts);
|
|
1058
|
+
const proxy = createTRPCClientProxy(client);
|
|
1059
|
+
return proxy;
|
|
1060
|
+
}
|
|
1061
|
+
var import_objectSpread2$3 = __toESM(require_objectSpread2(), 1);
|
|
1062
|
+
var import_objectSpread2$2 = __toESM(require_objectSpread2(), 1);
|
|
1063
|
+
var require_asyncIterator = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
|
|
1064
|
+
function _asyncIterator$1(r) {
|
|
1065
|
+
var n, t, o, e = 2;
|
|
1066
|
+
for (typeof Symbol != "undefined" && (t = Symbol.asyncIterator, o = Symbol.iterator);e--; ) {
|
|
1067
|
+
if (t && (n = r[t]) != null)
|
|
1068
|
+
return n.call(r);
|
|
1069
|
+
if (o && (n = r[o]) != null)
|
|
1070
|
+
return new AsyncFromSyncIterator(n.call(r));
|
|
1071
|
+
t = "@@asyncIterator", o = "@@iterator";
|
|
1072
|
+
}
|
|
1073
|
+
throw new TypeError("Object is not async iterable");
|
|
1074
|
+
}
|
|
1075
|
+
function AsyncFromSyncIterator(r) {
|
|
1076
|
+
function AsyncFromSyncIteratorContinuation(r$1) {
|
|
1077
|
+
if (Object(r$1) !== r$1)
|
|
1078
|
+
return Promise.reject(new TypeError(r$1 + " is not an object."));
|
|
1079
|
+
var n = r$1.done;
|
|
1080
|
+
return Promise.resolve(r$1.value).then(function(r$2) {
|
|
1081
|
+
return {
|
|
1082
|
+
value: r$2,
|
|
1083
|
+
done: n
|
|
1084
|
+
};
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
|
|
1088
|
+
this.s = r$1, this.n = r$1.next;
|
|
1089
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
1090
|
+
s: null,
|
|
1091
|
+
n: null,
|
|
1092
|
+
next: function next() {
|
|
1093
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
1094
|
+
},
|
|
1095
|
+
return: function _return(r$1) {
|
|
1096
|
+
var n = this.s["return"];
|
|
1097
|
+
return n === undefined ? Promise.resolve({
|
|
1098
|
+
value: r$1,
|
|
1099
|
+
done: true
|
|
1100
|
+
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
1101
|
+
},
|
|
1102
|
+
throw: function _throw(r$1) {
|
|
1103
|
+
var n = this.s["return"];
|
|
1104
|
+
return n === undefined ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
1105
|
+
}
|
|
1106
|
+
}, new AsyncFromSyncIterator(r);
|
|
1107
|
+
}
|
|
1108
|
+
module.exports = _asyncIterator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1109
|
+
} });
|
|
1110
|
+
var import_asyncIterator = __toESM(require_asyncIterator(), 1);
|
|
1111
|
+
var import_objectSpread2$12 = __toESM(require_objectSpread2(), 1);
|
|
1112
|
+
var require_usingCtx = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
|
|
1113
|
+
function _usingCtx() {
|
|
1114
|
+
var r = typeof SuppressedError == "function" ? SuppressedError : function(r$1, e$1) {
|
|
1115
|
+
var n$1 = Error();
|
|
1116
|
+
return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
|
|
1117
|
+
}, e = {}, n = [];
|
|
1118
|
+
function using(r$1, e$1) {
|
|
1119
|
+
if (e$1 != null) {
|
|
1120
|
+
if (Object(e$1) !== e$1)
|
|
1121
|
+
throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
1122
|
+
if (r$1)
|
|
1123
|
+
var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
1124
|
+
if (o === undefined && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1))
|
|
1125
|
+
var t = o;
|
|
1126
|
+
if (typeof o != "function")
|
|
1127
|
+
throw new TypeError("Object is not disposable.");
|
|
1128
|
+
t && (o = function o$1() {
|
|
1129
|
+
try {
|
|
1130
|
+
t.call(e$1);
|
|
1131
|
+
} catch (r$2) {
|
|
1132
|
+
return Promise.reject(r$2);
|
|
1133
|
+
}
|
|
1134
|
+
}), n.push({
|
|
1135
|
+
v: e$1,
|
|
1136
|
+
d: o,
|
|
1137
|
+
a: r$1
|
|
1138
|
+
});
|
|
1139
|
+
} else
|
|
1140
|
+
r$1 && n.push({
|
|
1141
|
+
d: e$1,
|
|
1142
|
+
a: r$1
|
|
1143
|
+
});
|
|
1144
|
+
return e$1;
|
|
1145
|
+
}
|
|
1146
|
+
return {
|
|
1147
|
+
e,
|
|
1148
|
+
u: using.bind(null, false),
|
|
1149
|
+
a: using.bind(null, true),
|
|
1150
|
+
d: function d() {
|
|
1151
|
+
var o, t = this.e, s = 0;
|
|
1152
|
+
function next() {
|
|
1153
|
+
for (;o = n.pop(); )
|
|
1154
|
+
try {
|
|
1155
|
+
if (!o.a && s === 1)
|
|
1156
|
+
return s = 0, n.push(o), Promise.resolve().then(next);
|
|
1157
|
+
if (o.d) {
|
|
1158
|
+
var r$1 = o.d.call(o.v);
|
|
1159
|
+
if (o.a)
|
|
1160
|
+
return s |= 2, Promise.resolve(r$1).then(next, err);
|
|
1161
|
+
} else
|
|
1162
|
+
s |= 1;
|
|
1163
|
+
} catch (r$2) {
|
|
1164
|
+
return err(r$2);
|
|
1165
|
+
}
|
|
1166
|
+
if (s === 1)
|
|
1167
|
+
return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
1168
|
+
if (t !== e)
|
|
1169
|
+
throw t;
|
|
1170
|
+
}
|
|
1171
|
+
function err(n$1) {
|
|
1172
|
+
return t = t !== e ? new r(n$1, t) : n$1, next();
|
|
1173
|
+
}
|
|
1174
|
+
return next();
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1179
|
+
} });
|
|
1180
|
+
var require_OverloadYield = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js"(exports, module) {
|
|
1181
|
+
function _OverloadYield(e, d) {
|
|
1182
|
+
this.v = e, this.k = d;
|
|
1183
|
+
}
|
|
1184
|
+
module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1185
|
+
} });
|
|
1186
|
+
var require_awaitAsyncGenerator = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js"(exports, module) {
|
|
1187
|
+
var OverloadYield$1 = require_OverloadYield();
|
|
1188
|
+
function _awaitAsyncGenerator$1(e) {
|
|
1189
|
+
return new OverloadYield$1(e, 0);
|
|
1190
|
+
}
|
|
1191
|
+
module.exports = _awaitAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1192
|
+
} });
|
|
1193
|
+
var require_wrapAsyncGenerator = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js"(exports, module) {
|
|
1194
|
+
var OverloadYield = require_OverloadYield();
|
|
1195
|
+
function _wrapAsyncGenerator$1(e) {
|
|
1196
|
+
return function() {
|
|
1197
|
+
return new AsyncGenerator(e.apply(this, arguments));
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
function AsyncGenerator(e) {
|
|
1201
|
+
var r, t;
|
|
1202
|
+
function resume(r$1, t$1) {
|
|
1203
|
+
try {
|
|
1204
|
+
var n = e[r$1](t$1), o = n.value, u = o instanceof OverloadYield;
|
|
1205
|
+
Promise.resolve(u ? o.v : o).then(function(t$2) {
|
|
1206
|
+
if (u) {
|
|
1207
|
+
var i = r$1 === "return" ? "return" : "next";
|
|
1208
|
+
if (!o.k || t$2.done)
|
|
1209
|
+
return resume(i, t$2);
|
|
1210
|
+
t$2 = e[i](t$2).value;
|
|
1211
|
+
}
|
|
1212
|
+
settle(n.done ? "return" : "normal", t$2);
|
|
1213
|
+
}, function(e$1) {
|
|
1214
|
+
resume("throw", e$1);
|
|
1215
|
+
});
|
|
1216
|
+
} catch (e$1) {
|
|
1217
|
+
settle("throw", e$1);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function settle(e$1, n) {
|
|
1221
|
+
switch (e$1) {
|
|
1222
|
+
case "return":
|
|
1223
|
+
r.resolve({
|
|
1224
|
+
value: n,
|
|
1225
|
+
done: true
|
|
1226
|
+
});
|
|
1227
|
+
break;
|
|
1228
|
+
case "throw":
|
|
1229
|
+
r.reject(n);
|
|
1230
|
+
break;
|
|
1231
|
+
default:
|
|
1232
|
+
r.resolve({
|
|
1233
|
+
value: n,
|
|
1234
|
+
done: false
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
1238
|
+
}
|
|
1239
|
+
this._invoke = function(e$1, n) {
|
|
1240
|
+
return new Promise(function(o, u) {
|
|
1241
|
+
var i = {
|
|
1242
|
+
key: e$1,
|
|
1243
|
+
arg: n,
|
|
1244
|
+
resolve: o,
|
|
1245
|
+
reject: u,
|
|
1246
|
+
next: null
|
|
1247
|
+
};
|
|
1248
|
+
t ? t = t.next = i : (r = t = i, resume(e$1, n));
|
|
1249
|
+
});
|
|
1250
|
+
}, typeof e["return"] != "function" && (this["return"] = undefined);
|
|
1251
|
+
}
|
|
1252
|
+
AsyncGenerator.prototype[typeof Symbol == "function" && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
1253
|
+
return this;
|
|
1254
|
+
}, AsyncGenerator.prototype.next = function(e) {
|
|
1255
|
+
return this._invoke("next", e);
|
|
1256
|
+
}, AsyncGenerator.prototype["throw"] = function(e) {
|
|
1257
|
+
return this._invoke("throw", e);
|
|
1258
|
+
}, AsyncGenerator.prototype["return"] = function(e) {
|
|
1259
|
+
return this._invoke("return", e);
|
|
1260
|
+
};
|
|
1261
|
+
module.exports = _wrapAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
1262
|
+
} });
|
|
1263
|
+
var import_usingCtx = __toESM(require_usingCtx(), 1);
|
|
1264
|
+
var import_awaitAsyncGenerator = __toESM(require_awaitAsyncGenerator(), 1);
|
|
1265
|
+
var import_wrapAsyncGenerator = __toESM(require_wrapAsyncGenerator(), 1);
|
|
1266
|
+
var import_objectSpread29 = __toESM(require_objectSpread2(), 1);
|
|
1267
|
+
|
|
1268
|
+
// ../http-client/dist/index.mjs
|
|
1269
|
+
function createTmturtleClient({ apiKey, baseUrl }) {
|
|
1270
|
+
const client = createTRPCClient({ links: [httpLink({
|
|
1271
|
+
headers: { authorization: `Bearer ${apiKey}` },
|
|
1272
|
+
url: new URL("/api/trpc", baseUrl).toString()
|
|
1273
|
+
})] });
|
|
1274
|
+
return {
|
|
1275
|
+
account: client.account,
|
|
1276
|
+
reports: client.reports,
|
|
1277
|
+
status: client.sync.status,
|
|
1278
|
+
trademarks: {
|
|
1279
|
+
get: client.marks.get,
|
|
1280
|
+
getByRegistration: client.marks["get-by-registration"],
|
|
1281
|
+
latest: client.marks.latest,
|
|
1282
|
+
matchText: client.marks["match-text"],
|
|
1283
|
+
search: client.marks.search
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
// package.json
|
|
1288
|
+
var package_default = {
|
|
1289
|
+
name: "@tmturtle/cli",
|
|
1290
|
+
version: "1.0.0",
|
|
1291
|
+
description: "Command-line access to Trademark Turtle search, reports, and service status",
|
|
1292
|
+
repository: {
|
|
1293
|
+
type: "git",
|
|
1294
|
+
url: "git+https://github.com/merchbaseco/tmturtle.git",
|
|
1295
|
+
directory: "packages/cli"
|
|
1296
|
+
},
|
|
1297
|
+
homepage: "https://github.com/merchbaseco/tmturtle#readme",
|
|
1298
|
+
bugs: "https://github.com/merchbaseco/tmturtle/issues",
|
|
1299
|
+
publishConfig: {
|
|
1300
|
+
access: "public"
|
|
1301
|
+
},
|
|
1302
|
+
type: "module",
|
|
1303
|
+
files: [
|
|
1304
|
+
"dist",
|
|
1305
|
+
"CHANGELOG.md"
|
|
1306
|
+
],
|
|
1307
|
+
bin: {
|
|
1308
|
+
tt: "dist/tt.js"
|
|
1309
|
+
},
|
|
1310
|
+
scripts: {
|
|
1311
|
+
build: "rm -rf dist && bun build src/tt.ts --outdir dist --target bun",
|
|
1312
|
+
prepack: "bun run build"
|
|
1313
|
+
},
|
|
1314
|
+
devDependencies: {
|
|
1315
|
+
"@tmturtle/http-client": "workspace:*",
|
|
1316
|
+
commander: "15.0.0"
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
// src/keychain.ts
|
|
1321
|
+
var service = "co.merchbase.tmturtle";
|
|
1322
|
+
var passwordPromptScript = `
|
|
1323
|
+
log_user 0
|
|
1324
|
+
set timeout 10
|
|
1325
|
+
set input [split [string trimright [read stdin] "\\r\\n"] "\\n"]
|
|
1326
|
+
set password [lindex $input 0]
|
|
1327
|
+
set arguments [lrange $input 1 end]
|
|
1328
|
+
spawn /usr/bin/security {*}$arguments
|
|
1329
|
+
expect {
|
|
1330
|
+
"password data for new item:" {
|
|
1331
|
+
send -- "$password\\r"
|
|
1332
|
+
exp_continue
|
|
1333
|
+
}
|
|
1334
|
+
"retype password for new item:" {
|
|
1335
|
+
send -- "$password\\r"
|
|
1336
|
+
exp_continue
|
|
1337
|
+
}
|
|
1338
|
+
eof {
|
|
1339
|
+
set result [wait]
|
|
1340
|
+
exit [lindex $result 3]
|
|
1341
|
+
}
|
|
1342
|
+
timeout { exit 124 }
|
|
1343
|
+
}
|
|
1344
|
+
`;
|
|
1345
|
+
async function security(args, stdin) {
|
|
1346
|
+
const command = stdin === undefined ? ["/usr/bin/security", ...args] : ["/usr/bin/expect", "-c", passwordPromptScript];
|
|
1347
|
+
const child = Bun.spawn(command, {
|
|
1348
|
+
stderr: "pipe",
|
|
1349
|
+
stdin: "pipe",
|
|
1350
|
+
stdout: "pipe"
|
|
1351
|
+
});
|
|
1352
|
+
if (stdin) {
|
|
1353
|
+
child.stdin.write(`${stdin.trimEnd()}
|
|
1354
|
+
${args.join(`
|
|
1355
|
+
`)}
|
|
1356
|
+
`);
|
|
1357
|
+
}
|
|
1358
|
+
child.stdin.end();
|
|
1359
|
+
const [exitCode, stderr, stdout] = await Promise.all([
|
|
1360
|
+
child.exited,
|
|
1361
|
+
new Response(child.stderr).text(),
|
|
1362
|
+
new Response(child.stdout).text()
|
|
1363
|
+
]);
|
|
1364
|
+
return { exitCode, stderr, stdout };
|
|
1365
|
+
}
|
|
1366
|
+
function failed(result) {
|
|
1367
|
+
return new Error(result.stderr.trim() || "macOS Keychain command failed");
|
|
1368
|
+
}
|
|
1369
|
+
function createMacOsKeychain(command = security) {
|
|
1370
|
+
return {
|
|
1371
|
+
async clear(origin) {
|
|
1372
|
+
const result = await command(["delete-generic-password", "-a", origin, "-s", service]);
|
|
1373
|
+
if (result.exitCode === 44) {
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
if (result.exitCode !== 0) {
|
|
1377
|
+
throw failed(result);
|
|
1378
|
+
}
|
|
1379
|
+
},
|
|
1380
|
+
async get(origin) {
|
|
1381
|
+
const result = await command(["find-generic-password", "-a", origin, "-s", service, "-w"]);
|
|
1382
|
+
if (result.exitCode === 44) {
|
|
1383
|
+
return null;
|
|
1384
|
+
}
|
|
1385
|
+
if (result.exitCode !== 0) {
|
|
1386
|
+
throw failed(result);
|
|
1387
|
+
}
|
|
1388
|
+
return result.stdout.trim();
|
|
1389
|
+
},
|
|
1390
|
+
async set(origin, token) {
|
|
1391
|
+
const result = await command(["add-generic-password", "-a", origin, "-s", service, "-U", "-w"], `${token}
|
|
1392
|
+
`);
|
|
1393
|
+
if (result.exitCode !== 0) {
|
|
1394
|
+
throw failed(result);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
// src/cli-error.ts
|
|
1401
|
+
class CliError extends Error {
|
|
1402
|
+
code;
|
|
1403
|
+
constructor(code, message, options) {
|
|
1404
|
+
super(message, options);
|
|
1405
|
+
this.code = code;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
class BadRequestError extends CliError {
|
|
1410
|
+
constructor(message, options) {
|
|
1411
|
+
super("BAD_REQUEST", message, options);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/lib/error.js
|
|
1416
|
+
class CommanderError extends Error {
|
|
1417
|
+
constructor(exitCode, code, message) {
|
|
1418
|
+
super(message);
|
|
1419
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1420
|
+
this.name = this.constructor.name;
|
|
1421
|
+
this.code = code;
|
|
1422
|
+
this.exitCode = exitCode;
|
|
1423
|
+
this.nestedError = undefined;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
class InvalidArgumentError extends CommanderError {
|
|
1428
|
+
constructor(message) {
|
|
1429
|
+
super(1, "commander.invalidArgument", message);
|
|
1430
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1431
|
+
this.name = this.constructor.name;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/lib/argument.js
|
|
1436
|
+
class Argument {
|
|
1437
|
+
constructor(name, description) {
|
|
1438
|
+
this.description = description || "";
|
|
1439
|
+
this.variadic = false;
|
|
1440
|
+
this.parseArg = undefined;
|
|
1441
|
+
this.defaultValue = undefined;
|
|
1442
|
+
this.defaultValueDescription = undefined;
|
|
1443
|
+
this.argChoices = undefined;
|
|
1444
|
+
switch (name[0]) {
|
|
1445
|
+
case "<":
|
|
1446
|
+
this.required = true;
|
|
1447
|
+
this._name = name.slice(1, -1);
|
|
1448
|
+
break;
|
|
1449
|
+
case "[":
|
|
1450
|
+
this.required = false;
|
|
1451
|
+
this._name = name.slice(1, -1);
|
|
1452
|
+
break;
|
|
1453
|
+
default:
|
|
1454
|
+
this.required = true;
|
|
1455
|
+
this._name = name;
|
|
1456
|
+
break;
|
|
1457
|
+
}
|
|
1458
|
+
if (this._name.endsWith("...")) {
|
|
1459
|
+
this.variadic = true;
|
|
1460
|
+
this._name = this._name.slice(0, -3);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
name() {
|
|
1464
|
+
return this._name;
|
|
1465
|
+
}
|
|
1466
|
+
_collectValue(value, previous) {
|
|
1467
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
1468
|
+
return [value];
|
|
1469
|
+
}
|
|
1470
|
+
previous.push(value);
|
|
1471
|
+
return previous;
|
|
1472
|
+
}
|
|
1473
|
+
default(value, description) {
|
|
1474
|
+
this.defaultValue = value;
|
|
1475
|
+
this.defaultValueDescription = description;
|
|
1476
|
+
return this;
|
|
1477
|
+
}
|
|
1478
|
+
argParser(fn) {
|
|
1479
|
+
this.parseArg = fn;
|
|
1480
|
+
return this;
|
|
1481
|
+
}
|
|
1482
|
+
choices(values) {
|
|
1483
|
+
this.argChoices = values.slice();
|
|
1484
|
+
this.parseArg = (arg, previous) => {
|
|
1485
|
+
if (!this.argChoices.includes(arg)) {
|
|
1486
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
1487
|
+
}
|
|
1488
|
+
if (this.variadic) {
|
|
1489
|
+
return this._collectValue(arg, previous);
|
|
1490
|
+
}
|
|
1491
|
+
return arg;
|
|
1492
|
+
};
|
|
1493
|
+
return this;
|
|
1494
|
+
}
|
|
1495
|
+
argRequired() {
|
|
1496
|
+
this.required = true;
|
|
1497
|
+
return this;
|
|
1498
|
+
}
|
|
1499
|
+
argOptional() {
|
|
1500
|
+
this.required = false;
|
|
1501
|
+
return this;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
function humanReadableArgName(arg) {
|
|
1505
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
1506
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/lib/command.js
|
|
1510
|
+
import { EventEmitter } from "events";
|
|
1511
|
+
import childProcess from "child_process";
|
|
1512
|
+
import path from "path";
|
|
1513
|
+
import fs from "fs";
|
|
1514
|
+
import process2 from "process";
|
|
1515
|
+
import { stripVTControlCharacters as stripVTControlCharacters2 } from "util";
|
|
1516
|
+
|
|
1517
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/lib/help.js
|
|
1518
|
+
import { stripVTControlCharacters } from "util";
|
|
1519
|
+
|
|
1520
|
+
class Help {
|
|
1521
|
+
constructor() {
|
|
1522
|
+
this.helpWidth = undefined;
|
|
1523
|
+
this.minWidthToWrap = 40;
|
|
1524
|
+
this.sortSubcommands = false;
|
|
1525
|
+
this.sortOptions = false;
|
|
1526
|
+
this.showGlobalOptions = false;
|
|
1527
|
+
}
|
|
1528
|
+
prepareContext(contextOptions) {
|
|
1529
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
1530
|
+
}
|
|
1531
|
+
visibleCommands(cmd) {
|
|
1532
|
+
const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
|
|
1533
|
+
const helpCommand = cmd._getHelpCommand();
|
|
1534
|
+
if (helpCommand && !helpCommand._hidden) {
|
|
1535
|
+
visibleCommands.push(helpCommand);
|
|
1536
|
+
}
|
|
1537
|
+
if (this.sortSubcommands) {
|
|
1538
|
+
visibleCommands.sort((a, b) => {
|
|
1539
|
+
return a.name().localeCompare(b.name());
|
|
1540
|
+
});
|
|
1541
|
+
}
|
|
1542
|
+
return visibleCommands;
|
|
1543
|
+
}
|
|
1544
|
+
compareOptions(a, b) {
|
|
1545
|
+
const getSortKey = (option) => {
|
|
1546
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
1547
|
+
};
|
|
1548
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
1549
|
+
}
|
|
1550
|
+
visibleOptions(cmd) {
|
|
1551
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
1552
|
+
const helpOption = cmd._getHelpOption();
|
|
1553
|
+
if (helpOption && !helpOption.hidden) {
|
|
1554
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
1555
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
1556
|
+
if (!removeShort && !removeLong) {
|
|
1557
|
+
visibleOptions.push(helpOption);
|
|
1558
|
+
} else if (helpOption.long && !removeLong) {
|
|
1559
|
+
visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
1560
|
+
} else if (helpOption.short && !removeShort) {
|
|
1561
|
+
visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
if (this.sortOptions) {
|
|
1565
|
+
visibleOptions.sort(this.compareOptions);
|
|
1566
|
+
}
|
|
1567
|
+
return visibleOptions;
|
|
1568
|
+
}
|
|
1569
|
+
visibleGlobalOptions(cmd) {
|
|
1570
|
+
if (!this.showGlobalOptions)
|
|
1571
|
+
return [];
|
|
1572
|
+
const globalOptions = [];
|
|
1573
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
1574
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
1575
|
+
globalOptions.push(...visibleOptions);
|
|
1576
|
+
}
|
|
1577
|
+
if (this.sortOptions) {
|
|
1578
|
+
globalOptions.sort(this.compareOptions);
|
|
1579
|
+
}
|
|
1580
|
+
return globalOptions;
|
|
1581
|
+
}
|
|
1582
|
+
visibleArguments(cmd) {
|
|
1583
|
+
if (cmd._argsDescription) {
|
|
1584
|
+
cmd.registeredArguments.forEach((argument) => {
|
|
1585
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) {
|
|
1589
|
+
return cmd.registeredArguments;
|
|
1590
|
+
}
|
|
1591
|
+
return [];
|
|
1592
|
+
}
|
|
1593
|
+
subcommandTerm(cmd) {
|
|
1594
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
1595
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
1596
|
+
}
|
|
1597
|
+
optionTerm(option) {
|
|
1598
|
+
return option.flags;
|
|
1599
|
+
}
|
|
1600
|
+
argumentTerm(argument) {
|
|
1601
|
+
return argument.name();
|
|
1602
|
+
}
|
|
1603
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
1604
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
1605
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
1606
|
+
}, 0);
|
|
1607
|
+
}
|
|
1608
|
+
longestOptionTermLength(cmd, helper) {
|
|
1609
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
1610
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
1611
|
+
}, 0);
|
|
1612
|
+
}
|
|
1613
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
1614
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
1615
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
1616
|
+
}, 0);
|
|
1617
|
+
}
|
|
1618
|
+
longestArgumentTermLength(cmd, helper) {
|
|
1619
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
1620
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
1621
|
+
}, 0);
|
|
1622
|
+
}
|
|
1623
|
+
commandUsage(cmd) {
|
|
1624
|
+
let cmdName = cmd._name;
|
|
1625
|
+
if (cmd._aliases[0]) {
|
|
1626
|
+
cmdName = cmdName + "|" + cmd._aliases[0];
|
|
1627
|
+
}
|
|
1628
|
+
let ancestorCmdNames = "";
|
|
1629
|
+
for (let ancestorCmd = cmd.parent;ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
1630
|
+
ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
1631
|
+
}
|
|
1632
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
1633
|
+
}
|
|
1634
|
+
commandDescription(cmd) {
|
|
1635
|
+
return cmd.description();
|
|
1636
|
+
}
|
|
1637
|
+
subcommandDescription(cmd) {
|
|
1638
|
+
return cmd.summary() || cmd.description();
|
|
1639
|
+
}
|
|
1640
|
+
optionDescription(option) {
|
|
1641
|
+
const extraInfo = [];
|
|
1642
|
+
if (option.argChoices) {
|
|
1643
|
+
extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
1644
|
+
}
|
|
1645
|
+
if (option.defaultValue !== undefined) {
|
|
1646
|
+
const showDefault = option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean";
|
|
1647
|
+
if (showDefault) {
|
|
1648
|
+
extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
if (option.presetArg !== undefined && option.optional) {
|
|
1652
|
+
extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
1653
|
+
}
|
|
1654
|
+
if (option.envVar !== undefined) {
|
|
1655
|
+
extraInfo.push(`env: ${option.envVar}`);
|
|
1656
|
+
}
|
|
1657
|
+
if (extraInfo.length > 0) {
|
|
1658
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
1659
|
+
if (option.description) {
|
|
1660
|
+
return `${option.description} ${extraDescription}`;
|
|
1661
|
+
}
|
|
1662
|
+
return extraDescription;
|
|
1663
|
+
}
|
|
1664
|
+
return option.description;
|
|
1665
|
+
}
|
|
1666
|
+
argumentDescription(argument) {
|
|
1667
|
+
const extraInfo = [];
|
|
1668
|
+
if (argument.argChoices) {
|
|
1669
|
+
extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
1670
|
+
}
|
|
1671
|
+
if (argument.defaultValue !== undefined) {
|
|
1672
|
+
extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
1673
|
+
}
|
|
1674
|
+
if (extraInfo.length > 0) {
|
|
1675
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
1676
|
+
if (argument.description) {
|
|
1677
|
+
return `${argument.description} ${extraDescription}`;
|
|
1678
|
+
}
|
|
1679
|
+
return extraDescription;
|
|
1680
|
+
}
|
|
1681
|
+
return argument.description;
|
|
1682
|
+
}
|
|
1683
|
+
formatItemList(heading, items, helper) {
|
|
1684
|
+
if (items.length === 0)
|
|
1685
|
+
return [];
|
|
1686
|
+
return [helper.styleTitle(heading), ...items, ""];
|
|
1687
|
+
}
|
|
1688
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
1689
|
+
const result = new Map;
|
|
1690
|
+
unsortedItems.forEach((item) => {
|
|
1691
|
+
const group = getGroup(item);
|
|
1692
|
+
if (!result.has(group))
|
|
1693
|
+
result.set(group, []);
|
|
1694
|
+
});
|
|
1695
|
+
visibleItems.forEach((item) => {
|
|
1696
|
+
const group = getGroup(item);
|
|
1697
|
+
if (!result.has(group)) {
|
|
1698
|
+
result.set(group, []);
|
|
1699
|
+
}
|
|
1700
|
+
result.get(group).push(item);
|
|
1701
|
+
});
|
|
1702
|
+
return result;
|
|
1703
|
+
}
|
|
1704
|
+
formatHelp(cmd, helper) {
|
|
1705
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
1706
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
1707
|
+
function callFormatItem(term, description) {
|
|
1708
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
1709
|
+
}
|
|
1710
|
+
let output = [
|
|
1711
|
+
`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
|
|
1712
|
+
""
|
|
1713
|
+
];
|
|
1714
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
1715
|
+
if (commandDescription.length > 0) {
|
|
1716
|
+
output = output.concat([
|
|
1717
|
+
helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
|
|
1718
|
+
""
|
|
1719
|
+
]);
|
|
1720
|
+
}
|
|
1721
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
1722
|
+
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
1723
|
+
});
|
|
1724
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
1725
|
+
const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
|
|
1726
|
+
optionGroups.forEach((options, group) => {
|
|
1727
|
+
const optionList = options.map((option) => {
|
|
1728
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
1729
|
+
});
|
|
1730
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
1731
|
+
});
|
|
1732
|
+
if (helper.showGlobalOptions) {
|
|
1733
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
1734
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
1735
|
+
});
|
|
1736
|
+
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
1737
|
+
}
|
|
1738
|
+
const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
|
|
1739
|
+
commandGroups.forEach((commands, group) => {
|
|
1740
|
+
const commandList = commands.map((sub) => {
|
|
1741
|
+
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
|
|
1742
|
+
});
|
|
1743
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
1744
|
+
});
|
|
1745
|
+
return output.join(`
|
|
1746
|
+
`);
|
|
1747
|
+
}
|
|
1748
|
+
displayWidth(str) {
|
|
1749
|
+
return stripVTControlCharacters(str).length;
|
|
1750
|
+
}
|
|
1751
|
+
styleTitle(str) {
|
|
1752
|
+
return str;
|
|
1753
|
+
}
|
|
1754
|
+
styleUsage(str) {
|
|
1755
|
+
return str.split(" ").map((word) => {
|
|
1756
|
+
if (word === "[options]")
|
|
1757
|
+
return this.styleOptionText(word);
|
|
1758
|
+
if (word === "[command]")
|
|
1759
|
+
return this.styleSubcommandText(word);
|
|
1760
|
+
if (word[0] === "[" || word[0] === "<")
|
|
1761
|
+
return this.styleArgumentText(word);
|
|
1762
|
+
return this.styleCommandText(word);
|
|
1763
|
+
}).join(" ");
|
|
1764
|
+
}
|
|
1765
|
+
styleCommandDescription(str) {
|
|
1766
|
+
return this.styleDescriptionText(str);
|
|
1767
|
+
}
|
|
1768
|
+
styleOptionDescription(str) {
|
|
1769
|
+
return this.styleDescriptionText(str);
|
|
1770
|
+
}
|
|
1771
|
+
styleSubcommandDescription(str) {
|
|
1772
|
+
return this.styleDescriptionText(str);
|
|
1773
|
+
}
|
|
1774
|
+
styleArgumentDescription(str) {
|
|
1775
|
+
return this.styleDescriptionText(str);
|
|
1776
|
+
}
|
|
1777
|
+
styleDescriptionText(str) {
|
|
1778
|
+
return str;
|
|
1779
|
+
}
|
|
1780
|
+
styleOptionTerm(str) {
|
|
1781
|
+
return this.styleOptionText(str);
|
|
1782
|
+
}
|
|
1783
|
+
styleSubcommandTerm(str) {
|
|
1784
|
+
return str.split(" ").map((word) => {
|
|
1785
|
+
if (word === "[options]")
|
|
1786
|
+
return this.styleOptionText(word);
|
|
1787
|
+
if (word[0] === "[" || word[0] === "<")
|
|
1788
|
+
return this.styleArgumentText(word);
|
|
1789
|
+
return this.styleSubcommandText(word);
|
|
1790
|
+
}).join(" ");
|
|
1791
|
+
}
|
|
1792
|
+
styleArgumentTerm(str) {
|
|
1793
|
+
return this.styleArgumentText(str);
|
|
1794
|
+
}
|
|
1795
|
+
styleOptionText(str) {
|
|
1796
|
+
return str;
|
|
1797
|
+
}
|
|
1798
|
+
styleArgumentText(str) {
|
|
1799
|
+
return str;
|
|
1800
|
+
}
|
|
1801
|
+
styleSubcommandText(str) {
|
|
1802
|
+
return str;
|
|
1803
|
+
}
|
|
1804
|
+
styleCommandText(str) {
|
|
1805
|
+
return str;
|
|
1806
|
+
}
|
|
1807
|
+
padWidth(cmd, helper) {
|
|
1808
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
1809
|
+
}
|
|
1810
|
+
preformatted(str) {
|
|
1811
|
+
return /\n[^\S\r\n]/.test(str);
|
|
1812
|
+
}
|
|
1813
|
+
formatItem(term, termWidth, description, helper) {
|
|
1814
|
+
const itemIndent = 2;
|
|
1815
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
1816
|
+
if (!description)
|
|
1817
|
+
return itemIndentStr + term;
|
|
1818
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
1819
|
+
const spacerWidth = 2;
|
|
1820
|
+
const helpWidth = this.helpWidth ?? 80;
|
|
1821
|
+
const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
|
|
1822
|
+
let formattedDescription;
|
|
1823
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
|
|
1824
|
+
formattedDescription = description;
|
|
1825
|
+
} else {
|
|
1826
|
+
const wrappedDescription = helper.boxWrap(description, remainingWidth);
|
|
1827
|
+
formattedDescription = wrappedDescription.replace(/\n/g, `
|
|
1828
|
+
` + " ".repeat(termWidth + spacerWidth));
|
|
1829
|
+
}
|
|
1830
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
|
|
1831
|
+
${itemIndentStr}`);
|
|
1832
|
+
}
|
|
1833
|
+
boxWrap(str, width) {
|
|
1834
|
+
if (width < this.minWidthToWrap)
|
|
1835
|
+
return str;
|
|
1836
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
1837
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
1838
|
+
const wrappedLines = [];
|
|
1839
|
+
rawLines.forEach((line) => {
|
|
1840
|
+
const chunks = line.match(chunkPattern);
|
|
1841
|
+
if (chunks === null) {
|
|
1842
|
+
wrappedLines.push("");
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
let sumChunks = [chunks.shift()];
|
|
1846
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
1847
|
+
chunks.forEach((chunk) => {
|
|
1848
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
1849
|
+
if (sumWidth + visibleWidth <= width) {
|
|
1850
|
+
sumChunks.push(chunk);
|
|
1851
|
+
sumWidth += visibleWidth;
|
|
1852
|
+
return;
|
|
1853
|
+
}
|
|
1854
|
+
wrappedLines.push(sumChunks.join(""));
|
|
1855
|
+
const nextChunk = chunk.trimStart();
|
|
1856
|
+
sumChunks = [nextChunk];
|
|
1857
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
1858
|
+
});
|
|
1859
|
+
wrappedLines.push(sumChunks.join(""));
|
|
1860
|
+
});
|
|
1861
|
+
return wrappedLines.join(`
|
|
1862
|
+
`);
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
|
|
1866
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/lib/option.js
|
|
1867
|
+
class Option {
|
|
1868
|
+
constructor(flags, description) {
|
|
1869
|
+
this.flags = flags;
|
|
1870
|
+
this.description = description || "";
|
|
1871
|
+
this.required = flags.includes("<");
|
|
1872
|
+
this.optional = flags.includes("[");
|
|
1873
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
1874
|
+
this.mandatory = false;
|
|
1875
|
+
const optionFlags = splitOptionFlags(flags);
|
|
1876
|
+
this.short = optionFlags.shortFlag;
|
|
1877
|
+
this.long = optionFlags.longFlag;
|
|
1878
|
+
this.negate = false;
|
|
1879
|
+
if (this.long) {
|
|
1880
|
+
this.negate = this.long.startsWith("--no-");
|
|
1881
|
+
}
|
|
1882
|
+
this.defaultValue = undefined;
|
|
1883
|
+
this.defaultValueDescription = undefined;
|
|
1884
|
+
this.presetArg = undefined;
|
|
1885
|
+
this.envVar = undefined;
|
|
1886
|
+
this.parseArg = undefined;
|
|
1887
|
+
this.hidden = false;
|
|
1888
|
+
this.argChoices = undefined;
|
|
1889
|
+
this.conflictsWith = [];
|
|
1890
|
+
this.implied = undefined;
|
|
1891
|
+
this.helpGroupHeading = undefined;
|
|
1892
|
+
}
|
|
1893
|
+
default(value, description) {
|
|
1894
|
+
this.defaultValue = value;
|
|
1895
|
+
this.defaultValueDescription = description;
|
|
1896
|
+
return this;
|
|
1897
|
+
}
|
|
1898
|
+
preset(arg) {
|
|
1899
|
+
this.presetArg = arg;
|
|
1900
|
+
return this;
|
|
1901
|
+
}
|
|
1902
|
+
conflicts(names) {
|
|
1903
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
1904
|
+
return this;
|
|
1905
|
+
}
|
|
1906
|
+
implies(impliedOptionValues) {
|
|
1907
|
+
let newImplied = impliedOptionValues;
|
|
1908
|
+
if (typeof impliedOptionValues === "string") {
|
|
1909
|
+
newImplied = { [impliedOptionValues]: true };
|
|
1910
|
+
}
|
|
1911
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
1912
|
+
return this;
|
|
1913
|
+
}
|
|
1914
|
+
env(name) {
|
|
1915
|
+
this.envVar = name;
|
|
1916
|
+
return this;
|
|
1917
|
+
}
|
|
1918
|
+
argParser(fn) {
|
|
1919
|
+
this.parseArg = fn;
|
|
1920
|
+
return this;
|
|
1921
|
+
}
|
|
1922
|
+
makeOptionMandatory(mandatory = true) {
|
|
1923
|
+
this.mandatory = !!mandatory;
|
|
1924
|
+
return this;
|
|
1925
|
+
}
|
|
1926
|
+
hideHelp(hide = true) {
|
|
1927
|
+
this.hidden = !!hide;
|
|
1928
|
+
return this;
|
|
1929
|
+
}
|
|
1930
|
+
_collectValue(value, previous) {
|
|
1931
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) {
|
|
1932
|
+
return [value];
|
|
1933
|
+
}
|
|
1934
|
+
previous.push(value);
|
|
1935
|
+
return previous;
|
|
1936
|
+
}
|
|
1937
|
+
choices(values) {
|
|
1938
|
+
this.argChoices = values.slice();
|
|
1939
|
+
this.parseArg = (arg, previous) => {
|
|
1940
|
+
if (!this.argChoices.includes(arg)) {
|
|
1941
|
+
throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
1942
|
+
}
|
|
1943
|
+
if (this.variadic) {
|
|
1944
|
+
return this._collectValue(arg, previous);
|
|
1945
|
+
}
|
|
1946
|
+
return arg;
|
|
1947
|
+
};
|
|
1948
|
+
return this;
|
|
1949
|
+
}
|
|
1950
|
+
name() {
|
|
1951
|
+
if (this.long) {
|
|
1952
|
+
return this.long.replace(/^--/, "");
|
|
1953
|
+
}
|
|
1954
|
+
return this.short.replace(/^-/, "");
|
|
1955
|
+
}
|
|
1956
|
+
attributeName() {
|
|
1957
|
+
if (this.negate) {
|
|
1958
|
+
return camelcase(this.name().replace(/^no-/, ""));
|
|
1959
|
+
}
|
|
1960
|
+
return camelcase(this.name());
|
|
1961
|
+
}
|
|
1962
|
+
helpGroup(heading) {
|
|
1963
|
+
this.helpGroupHeading = heading;
|
|
1964
|
+
return this;
|
|
1965
|
+
}
|
|
1966
|
+
is(arg) {
|
|
1967
|
+
return this.short === arg || this.long === arg;
|
|
1968
|
+
}
|
|
1969
|
+
isBoolean() {
|
|
1970
|
+
return !this.required && !this.optional && !this.negate;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
class DualOptions {
|
|
1975
|
+
constructor(options) {
|
|
1976
|
+
this.positiveOptions = new Map;
|
|
1977
|
+
this.negativeOptions = new Map;
|
|
1978
|
+
this.dualOptions = new Set;
|
|
1979
|
+
options.forEach((option) => {
|
|
1980
|
+
if (option.negate) {
|
|
1981
|
+
this.negativeOptions.set(option.attributeName(), option);
|
|
1982
|
+
} else {
|
|
1983
|
+
this.positiveOptions.set(option.attributeName(), option);
|
|
1984
|
+
}
|
|
1985
|
+
});
|
|
1986
|
+
this.negativeOptions.forEach((value, key) => {
|
|
1987
|
+
if (this.positiveOptions.has(key)) {
|
|
1988
|
+
this.dualOptions.add(key);
|
|
1989
|
+
}
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
valueFromOption(value, option) {
|
|
1993
|
+
const optionKey = option.attributeName();
|
|
1994
|
+
if (!this.dualOptions.has(optionKey))
|
|
1995
|
+
return true;
|
|
1996
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
1997
|
+
const negativeValue = preset !== undefined ? preset : false;
|
|
1998
|
+
return option.negate === (negativeValue === value);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
function camelcase(str) {
|
|
2002
|
+
return str.split("-").reduce((str2, word) => {
|
|
2003
|
+
return str2 + word[0].toUpperCase() + word.slice(1);
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
2006
|
+
function splitOptionFlags(flags) {
|
|
2007
|
+
let shortFlag;
|
|
2008
|
+
let longFlag;
|
|
2009
|
+
const shortFlagExp = /^-[^-]$/;
|
|
2010
|
+
const longFlagExp = /^--[^-]/;
|
|
2011
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
2012
|
+
if (shortFlagExp.test(flagParts[0]))
|
|
2013
|
+
shortFlag = flagParts.shift();
|
|
2014
|
+
if (longFlagExp.test(flagParts[0]))
|
|
2015
|
+
longFlag = flagParts.shift();
|
|
2016
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0]))
|
|
2017
|
+
shortFlag = flagParts.shift();
|
|
2018
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
2019
|
+
shortFlag = longFlag;
|
|
2020
|
+
longFlag = flagParts.shift();
|
|
2021
|
+
}
|
|
2022
|
+
if (flagParts[0].startsWith("-")) {
|
|
2023
|
+
const unsupportedFlag = flagParts[0];
|
|
2024
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
2025
|
+
if (/^-[^-][^-]/.test(unsupportedFlag))
|
|
2026
|
+
throw new Error(`${baseError}
|
|
2027
|
+
- a short flag is a single dash and a single character
|
|
2028
|
+
- either use a single dash and a single character (for a short flag)
|
|
2029
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
2030
|
+
if (shortFlagExp.test(unsupportedFlag))
|
|
2031
|
+
throw new Error(`${baseError}
|
|
2032
|
+
- too many short flags`);
|
|
2033
|
+
if (longFlagExp.test(unsupportedFlag))
|
|
2034
|
+
throw new Error(`${baseError}
|
|
2035
|
+
- too many long flags`);
|
|
2036
|
+
throw new Error(`${baseError}
|
|
2037
|
+
- unrecognised flag format`);
|
|
2038
|
+
}
|
|
2039
|
+
if (shortFlag === undefined && longFlag === undefined)
|
|
2040
|
+
throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
2041
|
+
return { shortFlag, longFlag };
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/lib/suggestSimilar.js
|
|
2045
|
+
var maxDistance = 3;
|
|
2046
|
+
function editDistance(a, b) {
|
|
2047
|
+
if (Math.abs(a.length - b.length) > maxDistance)
|
|
2048
|
+
return Math.max(a.length, b.length);
|
|
2049
|
+
const d = [];
|
|
2050
|
+
for (let i = 0;i <= a.length; i++) {
|
|
2051
|
+
d[i] = [i];
|
|
2052
|
+
}
|
|
2053
|
+
for (let j = 0;j <= b.length; j++) {
|
|
2054
|
+
d[0][j] = j;
|
|
2055
|
+
}
|
|
2056
|
+
for (let j = 1;j <= b.length; j++) {
|
|
2057
|
+
for (let i = 1;i <= a.length; i++) {
|
|
2058
|
+
let cost;
|
|
2059
|
+
if (a[i - 1] === b[j - 1]) {
|
|
2060
|
+
cost = 0;
|
|
2061
|
+
} else {
|
|
2062
|
+
cost = 1;
|
|
2063
|
+
}
|
|
2064
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
2065
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {
|
|
2066
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
return d[a.length][b.length];
|
|
2071
|
+
}
|
|
2072
|
+
function suggestSimilar(word, candidates) {
|
|
2073
|
+
if (!candidates || candidates.length === 0)
|
|
2074
|
+
return "";
|
|
2075
|
+
candidates = Array.from(new Set(candidates));
|
|
2076
|
+
const searchingOptions = word.startsWith("--");
|
|
2077
|
+
if (searchingOptions) {
|
|
2078
|
+
word = word.slice(2);
|
|
2079
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
2080
|
+
}
|
|
2081
|
+
let similar = [];
|
|
2082
|
+
let bestDistance = maxDistance;
|
|
2083
|
+
const minSimilarity = 0.4;
|
|
2084
|
+
candidates.forEach((candidate) => {
|
|
2085
|
+
if (candidate.length <= 1)
|
|
2086
|
+
return;
|
|
2087
|
+
const distance = editDistance(word, candidate);
|
|
2088
|
+
const length = Math.max(word.length, candidate.length);
|
|
2089
|
+
const similarity = (length - distance) / length;
|
|
2090
|
+
if (similarity > minSimilarity) {
|
|
2091
|
+
if (distance < bestDistance) {
|
|
2092
|
+
bestDistance = distance;
|
|
2093
|
+
similar = [candidate];
|
|
2094
|
+
} else if (distance === bestDistance) {
|
|
2095
|
+
similar.push(candidate);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
2100
|
+
if (searchingOptions) {
|
|
2101
|
+
similar = similar.map((candidate) => `--${candidate}`);
|
|
2102
|
+
}
|
|
2103
|
+
if (similar.length > 1) {
|
|
2104
|
+
return `
|
|
2105
|
+
(Did you mean one of ${similar.join(", ")}?)`;
|
|
2106
|
+
}
|
|
2107
|
+
if (similar.length === 1) {
|
|
2108
|
+
return `
|
|
2109
|
+
(Did you mean ${similar[0]}?)`;
|
|
2110
|
+
}
|
|
2111
|
+
return "";
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/lib/command.js
|
|
2115
|
+
class Command extends EventEmitter {
|
|
2116
|
+
constructor(name) {
|
|
2117
|
+
super();
|
|
2118
|
+
this.commands = [];
|
|
2119
|
+
this.options = [];
|
|
2120
|
+
this.parent = null;
|
|
2121
|
+
this._allowUnknownOption = false;
|
|
2122
|
+
this._allowExcessArguments = false;
|
|
2123
|
+
this.registeredArguments = [];
|
|
2124
|
+
this._args = this.registeredArguments;
|
|
2125
|
+
this.args = [];
|
|
2126
|
+
this.rawArgs = [];
|
|
2127
|
+
this.processedArgs = [];
|
|
2128
|
+
this._scriptPath = null;
|
|
2129
|
+
this._name = name || "";
|
|
2130
|
+
this._optionValues = {};
|
|
2131
|
+
this._optionValueSources = {};
|
|
2132
|
+
this._storeOptionsAsProperties = false;
|
|
2133
|
+
this._actionHandler = null;
|
|
2134
|
+
this._executableHandler = false;
|
|
2135
|
+
this._executableFile = null;
|
|
2136
|
+
this._executableDir = null;
|
|
2137
|
+
this._defaultCommandName = null;
|
|
2138
|
+
this._exitCallback = null;
|
|
2139
|
+
this._aliases = [];
|
|
2140
|
+
this._combineFlagAndOptionalValue = true;
|
|
2141
|
+
this._description = "";
|
|
2142
|
+
this._summary = "";
|
|
2143
|
+
this._argsDescription = undefined;
|
|
2144
|
+
this._enablePositionalOptions = false;
|
|
2145
|
+
this._passThroughOptions = false;
|
|
2146
|
+
this._lifeCycleHooks = {};
|
|
2147
|
+
this._showHelpAfterError = false;
|
|
2148
|
+
this._showSuggestionAfterError = true;
|
|
2149
|
+
this._savedState = null;
|
|
2150
|
+
this._outputConfiguration = {
|
|
2151
|
+
writeOut: (str) => process2.stdout.write(str),
|
|
2152
|
+
writeErr: (str) => process2.stderr.write(str),
|
|
2153
|
+
outputError: (str, write) => write(str),
|
|
2154
|
+
getOutHelpWidth: () => process2.stdout.isTTY ? process2.stdout.columns : undefined,
|
|
2155
|
+
getErrHelpWidth: () => process2.stderr.isTTY ? process2.stderr.columns : undefined,
|
|
2156
|
+
getOutHasColors: () => useColor() ?? (process2.stdout.isTTY && process2.stdout.hasColors?.()),
|
|
2157
|
+
getErrHasColors: () => useColor() ?? (process2.stderr.isTTY && process2.stderr.hasColors?.()),
|
|
2158
|
+
stripColor: (str) => stripVTControlCharacters2(str)
|
|
2159
|
+
};
|
|
2160
|
+
this._hidden = false;
|
|
2161
|
+
this._helpOption = undefined;
|
|
2162
|
+
this._addImplicitHelpCommand = undefined;
|
|
2163
|
+
this._helpCommand = undefined;
|
|
2164
|
+
this._helpConfiguration = {};
|
|
2165
|
+
this._helpGroupHeading = undefined;
|
|
2166
|
+
this._defaultCommandGroup = undefined;
|
|
2167
|
+
this._defaultOptionGroup = undefined;
|
|
2168
|
+
}
|
|
2169
|
+
copyInheritedSettings(sourceCommand) {
|
|
2170
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
2171
|
+
this._helpOption = sourceCommand._helpOption;
|
|
2172
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
2173
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
2174
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
2175
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
2176
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
2177
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
2178
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
2179
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
2180
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
2181
|
+
return this;
|
|
2182
|
+
}
|
|
2183
|
+
_getCommandAndAncestors() {
|
|
2184
|
+
const result = [];
|
|
2185
|
+
for (let command = this;command; command = command.parent) {
|
|
2186
|
+
result.push(command);
|
|
2187
|
+
}
|
|
2188
|
+
return result;
|
|
2189
|
+
}
|
|
2190
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
2191
|
+
let desc = actionOptsOrExecDesc;
|
|
2192
|
+
let opts = execOpts;
|
|
2193
|
+
if (typeof desc === "object" && desc !== null) {
|
|
2194
|
+
opts = desc;
|
|
2195
|
+
desc = null;
|
|
2196
|
+
}
|
|
2197
|
+
opts = opts || {};
|
|
2198
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
2199
|
+
const cmd = this.createCommand(name);
|
|
2200
|
+
if (desc) {
|
|
2201
|
+
cmd.description(desc);
|
|
2202
|
+
cmd._executableHandler = true;
|
|
2203
|
+
}
|
|
2204
|
+
if (opts.isDefault)
|
|
2205
|
+
this._defaultCommandName = cmd._name;
|
|
2206
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
2207
|
+
cmd._executableFile = opts.executableFile || null;
|
|
2208
|
+
if (args)
|
|
2209
|
+
cmd.arguments(args);
|
|
2210
|
+
this._registerCommand(cmd);
|
|
2211
|
+
cmd.parent = this;
|
|
2212
|
+
cmd.copyInheritedSettings(this);
|
|
2213
|
+
if (desc)
|
|
2214
|
+
return this;
|
|
2215
|
+
return cmd;
|
|
2216
|
+
}
|
|
2217
|
+
createCommand(name) {
|
|
2218
|
+
return new Command(name);
|
|
2219
|
+
}
|
|
2220
|
+
createHelp() {
|
|
2221
|
+
return Object.assign(new Help, this.configureHelp());
|
|
2222
|
+
}
|
|
2223
|
+
configureHelp(configuration) {
|
|
2224
|
+
if (configuration === undefined)
|
|
2225
|
+
return this._helpConfiguration;
|
|
2226
|
+
this._helpConfiguration = configuration;
|
|
2227
|
+
return this;
|
|
2228
|
+
}
|
|
2229
|
+
configureOutput(configuration) {
|
|
2230
|
+
if (configuration === undefined)
|
|
2231
|
+
return this._outputConfiguration;
|
|
2232
|
+
this._outputConfiguration = {
|
|
2233
|
+
...this._outputConfiguration,
|
|
2234
|
+
...configuration
|
|
2235
|
+
};
|
|
2236
|
+
return this;
|
|
2237
|
+
}
|
|
2238
|
+
showHelpAfterError(displayHelp = true) {
|
|
2239
|
+
if (typeof displayHelp !== "string")
|
|
2240
|
+
displayHelp = !!displayHelp;
|
|
2241
|
+
this._showHelpAfterError = displayHelp;
|
|
2242
|
+
return this;
|
|
2243
|
+
}
|
|
2244
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
2245
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
2246
|
+
return this;
|
|
2247
|
+
}
|
|
2248
|
+
addCommand(cmd, opts) {
|
|
2249
|
+
if (!cmd._name) {
|
|
2250
|
+
throw new Error(`Command passed to .addCommand() must have a name
|
|
2251
|
+
- specify the name in Command constructor or using .name()`);
|
|
2252
|
+
}
|
|
2253
|
+
opts = opts || {};
|
|
2254
|
+
if (opts.isDefault)
|
|
2255
|
+
this._defaultCommandName = cmd._name;
|
|
2256
|
+
if (opts.noHelp || opts.hidden)
|
|
2257
|
+
cmd._hidden = true;
|
|
2258
|
+
this._registerCommand(cmd);
|
|
2259
|
+
cmd.parent = this;
|
|
2260
|
+
cmd._checkForBrokenPassThrough();
|
|
2261
|
+
return this;
|
|
2262
|
+
}
|
|
2263
|
+
createArgument(name, description) {
|
|
2264
|
+
return new Argument(name, description);
|
|
2265
|
+
}
|
|
2266
|
+
argument(name, description, parseArg, defaultValue) {
|
|
2267
|
+
const argument = this.createArgument(name, description);
|
|
2268
|
+
if (typeof parseArg === "function") {
|
|
2269
|
+
argument.default(defaultValue).argParser(parseArg);
|
|
2270
|
+
} else {
|
|
2271
|
+
argument.default(parseArg);
|
|
2272
|
+
}
|
|
2273
|
+
this.addArgument(argument);
|
|
2274
|
+
return this;
|
|
2275
|
+
}
|
|
2276
|
+
arguments(names) {
|
|
2277
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
2278
|
+
this.argument(detail);
|
|
2279
|
+
});
|
|
2280
|
+
return this;
|
|
2281
|
+
}
|
|
2282
|
+
addArgument(argument) {
|
|
2283
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
2284
|
+
if (previousArgument?.variadic) {
|
|
2285
|
+
throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
2286
|
+
}
|
|
2287
|
+
if (argument.required && argument.defaultValue !== undefined && argument.parseArg === undefined) {
|
|
2288
|
+
throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
2289
|
+
}
|
|
2290
|
+
this.registeredArguments.push(argument);
|
|
2291
|
+
return this;
|
|
2292
|
+
}
|
|
2293
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
2294
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
2295
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
2296
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) {
|
|
2297
|
+
this._initCommandGroup(this._getHelpCommand());
|
|
2298
|
+
}
|
|
2299
|
+
return this;
|
|
2300
|
+
}
|
|
2301
|
+
const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
|
|
2302
|
+
const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
2303
|
+
const helpDescription = description ?? "display help for command";
|
|
2304
|
+
const helpCommand = this.createCommand(helpName);
|
|
2305
|
+
helpCommand.helpOption(false);
|
|
2306
|
+
if (helpArgs)
|
|
2307
|
+
helpCommand.arguments(helpArgs);
|
|
2308
|
+
if (helpDescription)
|
|
2309
|
+
helpCommand.description(helpDescription);
|
|
2310
|
+
this._addImplicitHelpCommand = true;
|
|
2311
|
+
this._helpCommand = helpCommand;
|
|
2312
|
+
if (enableOrNameAndArgs || description)
|
|
2313
|
+
this._initCommandGroup(helpCommand);
|
|
2314
|
+
return this;
|
|
2315
|
+
}
|
|
2316
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
2317
|
+
if (typeof helpCommand !== "object") {
|
|
2318
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
2319
|
+
return this;
|
|
2320
|
+
}
|
|
2321
|
+
this._addImplicitHelpCommand = true;
|
|
2322
|
+
this._helpCommand = helpCommand;
|
|
2323
|
+
this._initCommandGroup(helpCommand);
|
|
2324
|
+
return this;
|
|
2325
|
+
}
|
|
2326
|
+
_getHelpCommand() {
|
|
2327
|
+
const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
|
|
2328
|
+
if (hasImplicitHelpCommand) {
|
|
2329
|
+
if (this._helpCommand === undefined) {
|
|
2330
|
+
this.helpCommand(undefined, undefined);
|
|
2331
|
+
}
|
|
2332
|
+
return this._helpCommand;
|
|
2333
|
+
}
|
|
2334
|
+
return null;
|
|
2335
|
+
}
|
|
2336
|
+
hook(event, listener) {
|
|
2337
|
+
const allowedValues = ["preSubcommand", "preAction", "postAction"];
|
|
2338
|
+
if (!allowedValues.includes(event)) {
|
|
2339
|
+
throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
2340
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2341
|
+
}
|
|
2342
|
+
if (this._lifeCycleHooks[event]) {
|
|
2343
|
+
this._lifeCycleHooks[event].push(listener);
|
|
2344
|
+
} else {
|
|
2345
|
+
this._lifeCycleHooks[event] = [listener];
|
|
2346
|
+
}
|
|
2347
|
+
return this;
|
|
2348
|
+
}
|
|
2349
|
+
exitOverride(fn) {
|
|
2350
|
+
if (fn) {
|
|
2351
|
+
this._exitCallback = fn;
|
|
2352
|
+
} else {
|
|
2353
|
+
this._exitCallback = (err) => {
|
|
2354
|
+
if (err.code !== "commander.executeSubCommandAsync") {
|
|
2355
|
+
throw err;
|
|
2356
|
+
} else {}
|
|
2357
|
+
};
|
|
2358
|
+
}
|
|
2359
|
+
return this;
|
|
2360
|
+
}
|
|
2361
|
+
_exit(exitCode, code, message) {
|
|
2362
|
+
if (this._exitCallback) {
|
|
2363
|
+
this._exitCallback(new CommanderError(exitCode, code, message));
|
|
2364
|
+
}
|
|
2365
|
+
process2.exit(exitCode);
|
|
2366
|
+
}
|
|
2367
|
+
action(fn) {
|
|
2368
|
+
const listener = (args) => {
|
|
2369
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
2370
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
2371
|
+
if (this._storeOptionsAsProperties) {
|
|
2372
|
+
actionArgs[expectedArgsCount] = this;
|
|
2373
|
+
} else {
|
|
2374
|
+
actionArgs[expectedArgsCount] = this.opts();
|
|
2375
|
+
}
|
|
2376
|
+
actionArgs.push(this);
|
|
2377
|
+
return fn.apply(this, actionArgs);
|
|
2378
|
+
};
|
|
2379
|
+
this._actionHandler = listener;
|
|
2380
|
+
return this;
|
|
2381
|
+
}
|
|
2382
|
+
createOption(flags, description) {
|
|
2383
|
+
return new Option(flags, description);
|
|
2384
|
+
}
|
|
2385
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
2386
|
+
try {
|
|
2387
|
+
return target.parseArg(value, previous);
|
|
2388
|
+
} catch (err) {
|
|
2389
|
+
if (err.code === "commander.invalidArgument") {
|
|
2390
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
2391
|
+
this.error(message, { exitCode: err.exitCode, code: err.code });
|
|
2392
|
+
}
|
|
2393
|
+
throw err;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
_registerOption(option) {
|
|
2397
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
2398
|
+
if (matchingOption) {
|
|
2399
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
2400
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
2401
|
+
- already used by option '${matchingOption.flags}'`);
|
|
2402
|
+
}
|
|
2403
|
+
this._initOptionGroup(option);
|
|
2404
|
+
this.options.push(option);
|
|
2405
|
+
}
|
|
2406
|
+
_registerCommand(command) {
|
|
2407
|
+
const knownBy = (cmd) => {
|
|
2408
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
2409
|
+
};
|
|
2410
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
2411
|
+
if (alreadyUsed) {
|
|
2412
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
2413
|
+
const newCmd = knownBy(command).join("|");
|
|
2414
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
2415
|
+
}
|
|
2416
|
+
this._initCommandGroup(command);
|
|
2417
|
+
this.commands.push(command);
|
|
2418
|
+
}
|
|
2419
|
+
addOption(option) {
|
|
2420
|
+
this._registerOption(option);
|
|
2421
|
+
const oname = option.name();
|
|
2422
|
+
const name = option.attributeName();
|
|
2423
|
+
if (option.defaultValue !== undefined) {
|
|
2424
|
+
this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
2425
|
+
}
|
|
2426
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
2427
|
+
if (val == null && option.presetArg !== undefined) {
|
|
2428
|
+
val = option.presetArg;
|
|
2429
|
+
}
|
|
2430
|
+
const oldValue = this.getOptionValue(name);
|
|
2431
|
+
if (val !== null && option.parseArg) {
|
|
2432
|
+
val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
2433
|
+
} else if (val !== null && option.variadic) {
|
|
2434
|
+
val = option._collectValue(val, oldValue);
|
|
2435
|
+
}
|
|
2436
|
+
if (val == null) {
|
|
2437
|
+
if (option.negate) {
|
|
2438
|
+
val = false;
|
|
2439
|
+
} else if (option.isBoolean() || option.optional) {
|
|
2440
|
+
val = true;
|
|
2441
|
+
} else {
|
|
2442
|
+
val = "";
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
2446
|
+
};
|
|
2447
|
+
this.on("option:" + oname, (val) => {
|
|
2448
|
+
const invalidValueMessage = `error: option '${option.flags}' argument '${val}' is invalid.`;
|
|
2449
|
+
handleOptionValue(val, invalidValueMessage, "cli");
|
|
2450
|
+
});
|
|
2451
|
+
if (option.envVar) {
|
|
2452
|
+
this.on("optionEnv:" + oname, (val) => {
|
|
2453
|
+
const invalidValueMessage = `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`;
|
|
2454
|
+
handleOptionValue(val, invalidValueMessage, "env");
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
return this;
|
|
2458
|
+
}
|
|
2459
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
2460
|
+
if (typeof flags === "object" && flags instanceof Option) {
|
|
2461
|
+
throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
2462
|
+
}
|
|
2463
|
+
const option = this.createOption(flags, description);
|
|
2464
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
2465
|
+
if (typeof fn === "function") {
|
|
2466
|
+
option.default(defaultValue).argParser(fn);
|
|
2467
|
+
} else if (fn instanceof RegExp) {
|
|
2468
|
+
const regex = fn;
|
|
2469
|
+
fn = (val, def) => {
|
|
2470
|
+
const m = regex.exec(val);
|
|
2471
|
+
return m ? m[0] : def;
|
|
2472
|
+
};
|
|
2473
|
+
option.default(defaultValue).argParser(fn);
|
|
2474
|
+
} else {
|
|
2475
|
+
option.default(fn);
|
|
2476
|
+
}
|
|
2477
|
+
return this.addOption(option);
|
|
2478
|
+
}
|
|
2479
|
+
option(flags, description, parseArg, defaultValue) {
|
|
2480
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
2481
|
+
}
|
|
2482
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
2483
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
2484
|
+
}
|
|
2485
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
2486
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
2487
|
+
return this;
|
|
2488
|
+
}
|
|
2489
|
+
allowUnknownOption(allowUnknown = true) {
|
|
2490
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
2491
|
+
return this;
|
|
2492
|
+
}
|
|
2493
|
+
allowExcessArguments(allowExcess = true) {
|
|
2494
|
+
this._allowExcessArguments = !!allowExcess;
|
|
2495
|
+
return this;
|
|
2496
|
+
}
|
|
2497
|
+
enablePositionalOptions(positional = true) {
|
|
2498
|
+
this._enablePositionalOptions = !!positional;
|
|
2499
|
+
return this;
|
|
2500
|
+
}
|
|
2501
|
+
passThroughOptions(passThrough = true) {
|
|
2502
|
+
this._passThroughOptions = !!passThrough;
|
|
2503
|
+
this._checkForBrokenPassThrough();
|
|
2504
|
+
return this;
|
|
2505
|
+
}
|
|
2506
|
+
_checkForBrokenPassThrough() {
|
|
2507
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
|
|
2508
|
+
throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
2512
|
+
if (this.options.length) {
|
|
2513
|
+
throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
2514
|
+
}
|
|
2515
|
+
if (Object.keys(this._optionValues).length) {
|
|
2516
|
+
throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
2517
|
+
}
|
|
2518
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
2519
|
+
return this;
|
|
2520
|
+
}
|
|
2521
|
+
getOptionValue(key) {
|
|
2522
|
+
if (this._storeOptionsAsProperties) {
|
|
2523
|
+
return this[key];
|
|
2524
|
+
}
|
|
2525
|
+
return this._optionValues[key];
|
|
2526
|
+
}
|
|
2527
|
+
setOptionValue(key, value) {
|
|
2528
|
+
return this.setOptionValueWithSource(key, value, undefined);
|
|
2529
|
+
}
|
|
2530
|
+
setOptionValueWithSource(key, value, source) {
|
|
2531
|
+
if (this._storeOptionsAsProperties) {
|
|
2532
|
+
this[key] = value;
|
|
2533
|
+
} else {
|
|
2534
|
+
this._optionValues[key] = value;
|
|
2535
|
+
}
|
|
2536
|
+
this._optionValueSources[key] = source;
|
|
2537
|
+
return this;
|
|
2538
|
+
}
|
|
2539
|
+
getOptionValueSource(key) {
|
|
2540
|
+
return this._optionValueSources[key];
|
|
2541
|
+
}
|
|
2542
|
+
getOptionValueSourceWithGlobals(key) {
|
|
2543
|
+
let source;
|
|
2544
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2545
|
+
if (cmd.getOptionValueSource(key) !== undefined) {
|
|
2546
|
+
source = cmd.getOptionValueSource(key);
|
|
2547
|
+
}
|
|
2548
|
+
});
|
|
2549
|
+
return source;
|
|
2550
|
+
}
|
|
2551
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
2552
|
+
if (argv !== undefined && !Array.isArray(argv)) {
|
|
2553
|
+
throw new Error("first parameter to parse must be array or undefined");
|
|
2554
|
+
}
|
|
2555
|
+
parseOptions = parseOptions || {};
|
|
2556
|
+
if (argv === undefined && parseOptions.from === undefined) {
|
|
2557
|
+
if (process2.versions?.electron) {
|
|
2558
|
+
parseOptions.from = "electron";
|
|
2559
|
+
}
|
|
2560
|
+
const execArgv = process2.execArgv ?? [];
|
|
2561
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
2562
|
+
parseOptions.from = "eval";
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
if (argv === undefined) {
|
|
2566
|
+
argv = process2.argv;
|
|
2567
|
+
}
|
|
2568
|
+
this.rawArgs = argv.slice();
|
|
2569
|
+
let userArgs;
|
|
2570
|
+
switch (parseOptions.from) {
|
|
2571
|
+
case undefined:
|
|
2572
|
+
case "node":
|
|
2573
|
+
this._scriptPath = argv[1];
|
|
2574
|
+
userArgs = argv.slice(2);
|
|
2575
|
+
break;
|
|
2576
|
+
case "electron":
|
|
2577
|
+
if (process2.defaultApp) {
|
|
2578
|
+
this._scriptPath = argv[1];
|
|
2579
|
+
userArgs = argv.slice(2);
|
|
2580
|
+
} else {
|
|
2581
|
+
userArgs = argv.slice(1);
|
|
2582
|
+
}
|
|
2583
|
+
break;
|
|
2584
|
+
case "user":
|
|
2585
|
+
userArgs = argv.slice(0);
|
|
2586
|
+
break;
|
|
2587
|
+
case "eval":
|
|
2588
|
+
userArgs = argv.slice(1);
|
|
2589
|
+
break;
|
|
2590
|
+
default:
|
|
2591
|
+
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
2592
|
+
}
|
|
2593
|
+
if (!this._name && this._scriptPath)
|
|
2594
|
+
this.nameFromFilename(this._scriptPath);
|
|
2595
|
+
this._name = this._name || "program";
|
|
2596
|
+
return userArgs;
|
|
2597
|
+
}
|
|
2598
|
+
parse(argv, parseOptions) {
|
|
2599
|
+
this._prepareForParse();
|
|
2600
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
2601
|
+
this._parseCommand([], userArgs);
|
|
2602
|
+
return this;
|
|
2603
|
+
}
|
|
2604
|
+
async parseAsync(argv, parseOptions) {
|
|
2605
|
+
this._prepareForParse();
|
|
2606
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
2607
|
+
await this._parseCommand([], userArgs);
|
|
2608
|
+
return this;
|
|
2609
|
+
}
|
|
2610
|
+
_prepareForParse() {
|
|
2611
|
+
if (this._savedState === null) {
|
|
2612
|
+
this.options.filter((option) => option.negate && option.defaultValue === undefined && this.getOptionValue(option.attributeName()) === undefined).forEach((option) => {
|
|
2613
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
2614
|
+
if (!this._findOption(positiveLongFlag)) {
|
|
2615
|
+
this.setOptionValueWithSource(option.attributeName(), true, "default");
|
|
2616
|
+
}
|
|
2617
|
+
});
|
|
2618
|
+
this.saveStateBeforeParse();
|
|
2619
|
+
} else {
|
|
2620
|
+
this.restoreStateBeforeParse();
|
|
2621
|
+
}
|
|
2622
|
+
}
|
|
2623
|
+
saveStateBeforeParse() {
|
|
2624
|
+
this._savedState = {
|
|
2625
|
+
_name: this._name,
|
|
2626
|
+
_optionValues: { ...this._optionValues },
|
|
2627
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
2628
|
+
};
|
|
2629
|
+
}
|
|
2630
|
+
restoreStateBeforeParse() {
|
|
2631
|
+
if (this._storeOptionsAsProperties)
|
|
2632
|
+
throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
2633
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
2634
|
+
this._name = this._savedState._name;
|
|
2635
|
+
this._scriptPath = null;
|
|
2636
|
+
this.rawArgs = [];
|
|
2637
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
2638
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
2639
|
+
this.args = [];
|
|
2640
|
+
this.processedArgs = [];
|
|
2641
|
+
}
|
|
2642
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
2643
|
+
if (fs.existsSync(executableFile))
|
|
2644
|
+
return;
|
|
2645
|
+
const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
|
|
2646
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
2647
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
2648
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
2649
|
+
- ${executableDirMessage}`;
|
|
2650
|
+
throw new Error(executableMissing);
|
|
2651
|
+
}
|
|
2652
|
+
_executeSubCommand(subcommand, args) {
|
|
2653
|
+
args = args.slice();
|
|
2654
|
+
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2655
|
+
function findFile(baseDir, baseName) {
|
|
2656
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
2657
|
+
if (fs.existsSync(localBin))
|
|
2658
|
+
return localBin;
|
|
2659
|
+
if (sourceExt.includes(path.extname(baseName)))
|
|
2660
|
+
return;
|
|
2661
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
2662
|
+
if (foundExt)
|
|
2663
|
+
return `${localBin}${foundExt}`;
|
|
2664
|
+
return;
|
|
2665
|
+
}
|
|
2666
|
+
this._checkForMissingMandatoryOptions();
|
|
2667
|
+
this._checkForConflictingOptions();
|
|
2668
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
2669
|
+
let executableDir = this._executableDir || "";
|
|
2670
|
+
if (this._scriptPath) {
|
|
2671
|
+
let resolvedScriptPath;
|
|
2672
|
+
try {
|
|
2673
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
2674
|
+
} catch {
|
|
2675
|
+
resolvedScriptPath = this._scriptPath;
|
|
2676
|
+
}
|
|
2677
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
2678
|
+
}
|
|
2679
|
+
if (executableDir) {
|
|
2680
|
+
let localFile = findFile(executableDir, executableFile);
|
|
2681
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2682
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
2683
|
+
if (legacyName !== this._name) {
|
|
2684
|
+
localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
executableFile = localFile || executableFile;
|
|
2688
|
+
}
|
|
2689
|
+
const launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
2690
|
+
let proc;
|
|
2691
|
+
if (process2.platform !== "win32") {
|
|
2692
|
+
if (launchWithNode) {
|
|
2693
|
+
args.unshift(executableFile);
|
|
2694
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
2695
|
+
proc = childProcess.spawn(process2.argv[0], args, { stdio: "inherit" });
|
|
2696
|
+
} else {
|
|
2697
|
+
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
2698
|
+
}
|
|
2699
|
+
} else {
|
|
2700
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
2701
|
+
args.unshift(executableFile);
|
|
2702
|
+
args = incrementNodeInspectorPort(process2.execArgv).concat(args);
|
|
2703
|
+
proc = childProcess.spawn(process2.execPath, args, { stdio: "inherit" });
|
|
2704
|
+
}
|
|
2705
|
+
if (!proc.killed) {
|
|
2706
|
+
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
2707
|
+
signals.forEach((signal) => {
|
|
2708
|
+
process2.on(signal, () => {
|
|
2709
|
+
if (proc.killed === false && proc.exitCode === null) {
|
|
2710
|
+
proc.kill(signal);
|
|
2711
|
+
}
|
|
2712
|
+
});
|
|
2713
|
+
});
|
|
2714
|
+
}
|
|
2715
|
+
const exitCallback = this._exitCallback;
|
|
2716
|
+
proc.on("close", (code) => {
|
|
2717
|
+
code = code ?? 1;
|
|
2718
|
+
if (!exitCallback) {
|
|
2719
|
+
process2.exit(code);
|
|
2720
|
+
} else {
|
|
2721
|
+
exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
2722
|
+
}
|
|
2723
|
+
});
|
|
2724
|
+
proc.on("error", (err) => {
|
|
2725
|
+
if (err.code === "ENOENT") {
|
|
2726
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
2727
|
+
} else if (err.code === "EACCES") {
|
|
2728
|
+
throw new Error(`'${executableFile}' not executable`);
|
|
2729
|
+
}
|
|
2730
|
+
if (!exitCallback) {
|
|
2731
|
+
process2.exit(1);
|
|
2732
|
+
} else {
|
|
2733
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
2734
|
+
wrappedError.nestedError = err;
|
|
2735
|
+
exitCallback(wrappedError);
|
|
2736
|
+
}
|
|
2737
|
+
});
|
|
2738
|
+
this.runningCommand = proc;
|
|
2739
|
+
}
|
|
2740
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
2741
|
+
const subCommand = this._findCommand(commandName);
|
|
2742
|
+
if (!subCommand)
|
|
2743
|
+
this.help({ error: true });
|
|
2744
|
+
subCommand._prepareForParse();
|
|
2745
|
+
let promiseChain;
|
|
2746
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
2747
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2748
|
+
if (subCommand._executableHandler) {
|
|
2749
|
+
this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
2750
|
+
} else {
|
|
2751
|
+
return subCommand._parseCommand(operands, unknown);
|
|
2752
|
+
}
|
|
2753
|
+
});
|
|
2754
|
+
return promiseChain;
|
|
2755
|
+
}
|
|
2756
|
+
_dispatchHelpCommand(subcommandName) {
|
|
2757
|
+
if (!subcommandName) {
|
|
2758
|
+
this.help();
|
|
2759
|
+
}
|
|
2760
|
+
const subCommand = this._findCommand(subcommandName);
|
|
2761
|
+
if (subCommand && !subCommand._executableHandler) {
|
|
2762
|
+
subCommand.help();
|
|
2763
|
+
}
|
|
2764
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
2765
|
+
}
|
|
2766
|
+
_checkNumberOfArguments() {
|
|
2767
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
2768
|
+
if (arg.required && this.args[i] == null) {
|
|
2769
|
+
this.missingArgument(arg.name());
|
|
2770
|
+
}
|
|
2771
|
+
});
|
|
2772
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) {
|
|
2773
|
+
return;
|
|
2774
|
+
}
|
|
2775
|
+
if (this.args.length > this.registeredArguments.length) {
|
|
2776
|
+
this._excessArguments(this.args);
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
_processArguments() {
|
|
2780
|
+
const myParseArg = (argument, value, previous) => {
|
|
2781
|
+
let parsedValue = value;
|
|
2782
|
+
if (value !== null && argument.parseArg) {
|
|
2783
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
2784
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
2785
|
+
}
|
|
2786
|
+
return parsedValue;
|
|
2787
|
+
};
|
|
2788
|
+
this._checkNumberOfArguments();
|
|
2789
|
+
const processedArgs = [];
|
|
2790
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
2791
|
+
let value = declaredArg.defaultValue;
|
|
2792
|
+
if (declaredArg.variadic) {
|
|
2793
|
+
if (index < this.args.length) {
|
|
2794
|
+
value = this.args.slice(index);
|
|
2795
|
+
if (declaredArg.parseArg) {
|
|
2796
|
+
value = value.reduce((processed, v) => {
|
|
2797
|
+
return myParseArg(declaredArg, v, processed);
|
|
2798
|
+
}, declaredArg.defaultValue);
|
|
2799
|
+
}
|
|
2800
|
+
} else if (value === undefined) {
|
|
2801
|
+
value = [];
|
|
2802
|
+
}
|
|
2803
|
+
} else if (index < this.args.length) {
|
|
2804
|
+
value = this.args[index];
|
|
2805
|
+
if (declaredArg.parseArg) {
|
|
2806
|
+
value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2807
|
+
}
|
|
2808
|
+
}
|
|
2809
|
+
processedArgs[index] = value;
|
|
2810
|
+
});
|
|
2811
|
+
this.processedArgs = processedArgs;
|
|
2812
|
+
}
|
|
2813
|
+
_chainOrCall(promise, fn) {
|
|
2814
|
+
if (promise?.then && typeof promise.then === "function") {
|
|
2815
|
+
return promise.then(() => fn());
|
|
2816
|
+
}
|
|
2817
|
+
return fn();
|
|
2818
|
+
}
|
|
2819
|
+
_chainOrCallHooks(promise, event) {
|
|
2820
|
+
let result = promise;
|
|
2821
|
+
const hooks = [];
|
|
2822
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== undefined).forEach((hookedCommand) => {
|
|
2823
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
2824
|
+
hooks.push({ hookedCommand, callback });
|
|
2825
|
+
});
|
|
2826
|
+
});
|
|
2827
|
+
if (event === "postAction") {
|
|
2828
|
+
hooks.reverse();
|
|
2829
|
+
}
|
|
2830
|
+
hooks.forEach((hookDetail) => {
|
|
2831
|
+
result = this._chainOrCall(result, () => {
|
|
2832
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
2833
|
+
});
|
|
2834
|
+
});
|
|
2835
|
+
return result;
|
|
2836
|
+
}
|
|
2837
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
2838
|
+
let result = promise;
|
|
2839
|
+
if (this._lifeCycleHooks[event] !== undefined) {
|
|
2840
|
+
this._lifeCycleHooks[event].forEach((hook) => {
|
|
2841
|
+
result = this._chainOrCall(result, () => {
|
|
2842
|
+
return hook(this, subCommand);
|
|
2843
|
+
});
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
return result;
|
|
2847
|
+
}
|
|
2848
|
+
_parseCommand(operands, unknown) {
|
|
2849
|
+
const parsed = this.parseOptions(unknown);
|
|
2850
|
+
this._parseOptionsEnv();
|
|
2851
|
+
this._parseOptionsImplied();
|
|
2852
|
+
operands = operands.concat(parsed.operands);
|
|
2853
|
+
unknown = parsed.unknown;
|
|
2854
|
+
this.args = operands.concat(unknown);
|
|
2855
|
+
if (operands && this._findCommand(operands[0])) {
|
|
2856
|
+
return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
2857
|
+
}
|
|
2858
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
|
|
2859
|
+
return this._dispatchHelpCommand(operands[1]);
|
|
2860
|
+
}
|
|
2861
|
+
if (this._defaultCommandName) {
|
|
2862
|
+
this._outputHelpIfRequested(unknown);
|
|
2863
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
2864
|
+
}
|
|
2865
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
|
|
2866
|
+
this.help({ error: true });
|
|
2867
|
+
}
|
|
2868
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
2869
|
+
this._checkForMissingMandatoryOptions();
|
|
2870
|
+
this._checkForConflictingOptions();
|
|
2871
|
+
const checkForUnknownOptions = () => {
|
|
2872
|
+
if (parsed.unknown.length > 0) {
|
|
2873
|
+
this.unknownOption(parsed.unknown[0]);
|
|
2874
|
+
}
|
|
2875
|
+
};
|
|
2876
|
+
const commandEvent = `command:${this.name()}`;
|
|
2877
|
+
if (this._actionHandler) {
|
|
2878
|
+
checkForUnknownOptions();
|
|
2879
|
+
this._processArguments();
|
|
2880
|
+
let promiseChain;
|
|
2881
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
2882
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
2883
|
+
if (this.parent) {
|
|
2884
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2885
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2886
|
+
});
|
|
2887
|
+
}
|
|
2888
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
2889
|
+
return promiseChain;
|
|
2890
|
+
}
|
|
2891
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
2892
|
+
checkForUnknownOptions();
|
|
2893
|
+
this._processArguments();
|
|
2894
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2895
|
+
} else if (operands.length) {
|
|
2896
|
+
if (this._findCommand("*")) {
|
|
2897
|
+
return this._dispatchSubcommand("*", operands, unknown);
|
|
2898
|
+
}
|
|
2899
|
+
if (this.listenerCount("command:*")) {
|
|
2900
|
+
this.emit("command:*", operands, unknown);
|
|
2901
|
+
} else if (this.commands.length) {
|
|
2902
|
+
this.unknownCommand();
|
|
2903
|
+
} else {
|
|
2904
|
+
checkForUnknownOptions();
|
|
2905
|
+
this._processArguments();
|
|
2906
|
+
}
|
|
2907
|
+
} else if (this.commands.length) {
|
|
2908
|
+
checkForUnknownOptions();
|
|
2909
|
+
this.help({ error: true });
|
|
2910
|
+
} else {
|
|
2911
|
+
checkForUnknownOptions();
|
|
2912
|
+
this._processArguments();
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
_findCommand(name) {
|
|
2916
|
+
if (!name)
|
|
2917
|
+
return;
|
|
2918
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
2919
|
+
}
|
|
2920
|
+
_findOption(arg) {
|
|
2921
|
+
return this.options.find((option) => option.is(arg));
|
|
2922
|
+
}
|
|
2923
|
+
_checkForMissingMandatoryOptions() {
|
|
2924
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2925
|
+
cmd.options.forEach((anOption) => {
|
|
2926
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === undefined) {
|
|
2927
|
+
cmd.missingMandatoryOptionValue(anOption);
|
|
2928
|
+
}
|
|
2929
|
+
});
|
|
2930
|
+
});
|
|
2931
|
+
}
|
|
2932
|
+
_checkForConflictingLocalOptions() {
|
|
2933
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
2934
|
+
const optionKey = option.attributeName();
|
|
2935
|
+
if (this.getOptionValue(optionKey) === undefined) {
|
|
2936
|
+
return false;
|
|
2937
|
+
}
|
|
2938
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
2939
|
+
});
|
|
2940
|
+
const optionsWithConflicting = definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0);
|
|
2941
|
+
optionsWithConflicting.forEach((option) => {
|
|
2942
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
2943
|
+
if (conflictingAndDefined) {
|
|
2944
|
+
this._conflictingOption(option, conflictingAndDefined);
|
|
2945
|
+
}
|
|
2946
|
+
});
|
|
2947
|
+
}
|
|
2948
|
+
_checkForConflictingOptions() {
|
|
2949
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2950
|
+
cmd._checkForConflictingLocalOptions();
|
|
2951
|
+
});
|
|
2952
|
+
}
|
|
2953
|
+
parseOptions(args) {
|
|
2954
|
+
const operands = [];
|
|
2955
|
+
const unknown = [];
|
|
2956
|
+
let dest = operands;
|
|
2957
|
+
function maybeOption(arg) {
|
|
2958
|
+
return arg.length > 1 && arg[0] === "-";
|
|
2959
|
+
}
|
|
2960
|
+
const negativeNumberArg = (arg) => {
|
|
2961
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg))
|
|
2962
|
+
return false;
|
|
2963
|
+
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
2964
|
+
};
|
|
2965
|
+
let activeVariadicOption = null;
|
|
2966
|
+
let activeGroup = null;
|
|
2967
|
+
let i = 0;
|
|
2968
|
+
while (i < args.length || activeGroup) {
|
|
2969
|
+
const arg = activeGroup ?? args[i++];
|
|
2970
|
+
activeGroup = null;
|
|
2971
|
+
if (arg === "--") {
|
|
2972
|
+
if (dest === unknown)
|
|
2973
|
+
dest.push(arg);
|
|
2974
|
+
dest.push(...args.slice(i));
|
|
2975
|
+
break;
|
|
2976
|
+
}
|
|
2977
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
2978
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2979
|
+
continue;
|
|
2980
|
+
}
|
|
2981
|
+
activeVariadicOption = null;
|
|
2982
|
+
if (maybeOption(arg)) {
|
|
2983
|
+
const option = this._findOption(arg);
|
|
2984
|
+
if (option) {
|
|
2985
|
+
if (option.required) {
|
|
2986
|
+
const value = args[i++];
|
|
2987
|
+
if (value === undefined)
|
|
2988
|
+
this.optionMissingArgument(option);
|
|
2989
|
+
this.emit(`option:${option.name()}`, value);
|
|
2990
|
+
} else if (option.optional) {
|
|
2991
|
+
let value = null;
|
|
2992
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) {
|
|
2993
|
+
value = args[i++];
|
|
2994
|
+
}
|
|
2995
|
+
this.emit(`option:${option.name()}`, value);
|
|
2996
|
+
} else {
|
|
2997
|
+
this.emit(`option:${option.name()}`);
|
|
2998
|
+
}
|
|
2999
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
3000
|
+
continue;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
3004
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
3005
|
+
if (option) {
|
|
3006
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) {
|
|
3007
|
+
this.emit(`option:${option.name()}`, arg.slice(2));
|
|
3008
|
+
} else {
|
|
3009
|
+
this.emit(`option:${option.name()}`);
|
|
3010
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
3011
|
+
}
|
|
3012
|
+
continue;
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
3016
|
+
const index = arg.indexOf("=");
|
|
3017
|
+
const option = this._findOption(arg.slice(0, index));
|
|
3018
|
+
if (option && (option.required || option.optional)) {
|
|
3019
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
3020
|
+
continue;
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
|
|
3024
|
+
dest = unknown;
|
|
3025
|
+
}
|
|
3026
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
3027
|
+
if (this._findCommand(arg)) {
|
|
3028
|
+
operands.push(arg);
|
|
3029
|
+
unknown.push(...args.slice(i));
|
|
3030
|
+
break;
|
|
3031
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
3032
|
+
operands.push(arg, ...args.slice(i));
|
|
3033
|
+
break;
|
|
3034
|
+
} else if (this._defaultCommandName) {
|
|
3035
|
+
unknown.push(arg, ...args.slice(i));
|
|
3036
|
+
break;
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
if (this._passThroughOptions) {
|
|
3040
|
+
dest.push(arg, ...args.slice(i));
|
|
3041
|
+
break;
|
|
3042
|
+
}
|
|
3043
|
+
dest.push(arg);
|
|
3044
|
+
}
|
|
3045
|
+
return { operands, unknown };
|
|
3046
|
+
}
|
|
3047
|
+
opts() {
|
|
3048
|
+
if (this._storeOptionsAsProperties) {
|
|
3049
|
+
const result = {};
|
|
3050
|
+
const len = this.options.length;
|
|
3051
|
+
for (let i = 0;i < len; i++) {
|
|
3052
|
+
const key = this.options[i].attributeName();
|
|
3053
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
3054
|
+
}
|
|
3055
|
+
return result;
|
|
3056
|
+
}
|
|
3057
|
+
return this._optionValues;
|
|
3058
|
+
}
|
|
3059
|
+
optsWithGlobals() {
|
|
3060
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
3061
|
+
}
|
|
3062
|
+
error(message, errorOptions) {
|
|
3063
|
+
this._outputConfiguration.outputError(`${message}
|
|
3064
|
+
`, this._outputConfiguration.writeErr);
|
|
3065
|
+
if (typeof this._showHelpAfterError === "string") {
|
|
3066
|
+
this._outputConfiguration.writeErr(`${this._showHelpAfterError}
|
|
3067
|
+
`);
|
|
3068
|
+
} else if (this._showHelpAfterError) {
|
|
3069
|
+
this._outputConfiguration.writeErr(`
|
|
3070
|
+
`);
|
|
3071
|
+
this.outputHelp({ error: true });
|
|
3072
|
+
}
|
|
3073
|
+
const config = errorOptions || {};
|
|
3074
|
+
const exitCode = config.exitCode || 1;
|
|
3075
|
+
const code = config.code || "commander.error";
|
|
3076
|
+
this._exit(exitCode, code, message);
|
|
3077
|
+
}
|
|
3078
|
+
_parseOptionsEnv() {
|
|
3079
|
+
this.options.forEach((option) => {
|
|
3080
|
+
if (option.envVar && option.envVar in process2.env) {
|
|
3081
|
+
const optionKey = option.attributeName();
|
|
3082
|
+
if (this.getOptionValue(optionKey) === undefined || ["default", "config", "env"].includes(this.getOptionValueSource(optionKey))) {
|
|
3083
|
+
if (option.required || option.optional) {
|
|
3084
|
+
this.emit(`optionEnv:${option.name()}`, process2.env[option.envVar]);
|
|
3085
|
+
} else {
|
|
3086
|
+
this.emit(`optionEnv:${option.name()}`);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
_parseOptionsImplied() {
|
|
3093
|
+
const dualHelper = new DualOptions(this.options);
|
|
3094
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
3095
|
+
return this.getOptionValue(optionKey) !== undefined && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
3096
|
+
};
|
|
3097
|
+
this.options.filter((option) => option.implied !== undefined && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
3098
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
3099
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
3100
|
+
});
|
|
3101
|
+
});
|
|
3102
|
+
}
|
|
3103
|
+
missingArgument(name) {
|
|
3104
|
+
const message = `error: missing required argument '${name}'`;
|
|
3105
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
3106
|
+
}
|
|
3107
|
+
optionMissingArgument(option) {
|
|
3108
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
3109
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
3110
|
+
}
|
|
3111
|
+
missingMandatoryOptionValue(option) {
|
|
3112
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
3113
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
3114
|
+
}
|
|
3115
|
+
_conflictingOption(option, conflictingOption) {
|
|
3116
|
+
const findBestOptionFromValue = (option2) => {
|
|
3117
|
+
const optionKey = option2.attributeName();
|
|
3118
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
3119
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
3120
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
3121
|
+
if (negativeOption && (negativeOption.presetArg === undefined && optionValue === false || negativeOption.presetArg !== undefined && optionValue === negativeOption.presetArg)) {
|
|
3122
|
+
return negativeOption;
|
|
3123
|
+
}
|
|
3124
|
+
return positiveOption || option2;
|
|
3125
|
+
};
|
|
3126
|
+
const getErrorMessage = (option2) => {
|
|
3127
|
+
const bestOption = findBestOptionFromValue(option2);
|
|
3128
|
+
const optionKey = bestOption.attributeName();
|
|
3129
|
+
const source = this.getOptionValueSource(optionKey);
|
|
3130
|
+
if (source === "env") {
|
|
3131
|
+
return `environment variable '${bestOption.envVar}'`;
|
|
3132
|
+
}
|
|
3133
|
+
return `option '${bestOption.flags}'`;
|
|
3134
|
+
};
|
|
3135
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
3136
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
3137
|
+
}
|
|
3138
|
+
unknownOption(flag) {
|
|
3139
|
+
if (this._allowUnknownOption)
|
|
3140
|
+
return;
|
|
3141
|
+
let suggestion = "";
|
|
3142
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
3143
|
+
let candidateFlags = [];
|
|
3144
|
+
let command = this;
|
|
3145
|
+
do {
|
|
3146
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
3147
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
3148
|
+
command = command.parent;
|
|
3149
|
+
} while (command && !command._enablePositionalOptions);
|
|
3150
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
3151
|
+
}
|
|
3152
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
3153
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
3154
|
+
}
|
|
3155
|
+
_excessArguments(receivedArgs) {
|
|
3156
|
+
if (this._allowExcessArguments)
|
|
3157
|
+
return;
|
|
3158
|
+
const expected = this.registeredArguments.length;
|
|
3159
|
+
const s = expected === 1 ? "" : "s";
|
|
3160
|
+
const received = receivedArgs.length;
|
|
3161
|
+
const forSubcommand = this.parent ? ` for '${this.name()}'` : "";
|
|
3162
|
+
const details = receivedArgs.join(", ");
|
|
3163
|
+
const message = `error: too many arguments${forSubcommand}. Expected ${expected} argument${s} but got ${received}: ${details}.`;
|
|
3164
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
3165
|
+
}
|
|
3166
|
+
unknownCommand() {
|
|
3167
|
+
const unknownName = this.args[0];
|
|
3168
|
+
let suggestion = "";
|
|
3169
|
+
if (this._showSuggestionAfterError) {
|
|
3170
|
+
const candidateNames = [];
|
|
3171
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
3172
|
+
candidateNames.push(command.name());
|
|
3173
|
+
if (command.alias())
|
|
3174
|
+
candidateNames.push(command.alias());
|
|
3175
|
+
});
|
|
3176
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
3177
|
+
}
|
|
3178
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
3179
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
3180
|
+
}
|
|
3181
|
+
version(str, flags, description) {
|
|
3182
|
+
if (str === undefined)
|
|
3183
|
+
return this._version;
|
|
3184
|
+
this._version = str;
|
|
3185
|
+
flags = flags || "-V, --version";
|
|
3186
|
+
description = description || "output the version number";
|
|
3187
|
+
const versionOption = this.createOption(flags, description);
|
|
3188
|
+
this._versionOptionName = versionOption.attributeName();
|
|
3189
|
+
this._registerOption(versionOption);
|
|
3190
|
+
this.on("option:" + versionOption.name(), () => {
|
|
3191
|
+
this._outputConfiguration.writeOut(`${str}
|
|
3192
|
+
`);
|
|
3193
|
+
this._exit(0, "commander.version", str);
|
|
3194
|
+
});
|
|
3195
|
+
return this;
|
|
3196
|
+
}
|
|
3197
|
+
description(str, argsDescription) {
|
|
3198
|
+
if (str === undefined && argsDescription === undefined)
|
|
3199
|
+
return this._description;
|
|
3200
|
+
this._description = str;
|
|
3201
|
+
if (argsDescription) {
|
|
3202
|
+
this._argsDescription = argsDescription;
|
|
3203
|
+
}
|
|
3204
|
+
return this;
|
|
3205
|
+
}
|
|
3206
|
+
summary(str) {
|
|
3207
|
+
if (str === undefined)
|
|
3208
|
+
return this._summary;
|
|
3209
|
+
this._summary = str;
|
|
3210
|
+
return this;
|
|
3211
|
+
}
|
|
3212
|
+
alias(alias) {
|
|
3213
|
+
if (alias === undefined)
|
|
3214
|
+
return this._aliases[0];
|
|
3215
|
+
let command = this;
|
|
3216
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) {
|
|
3217
|
+
command = this.commands[this.commands.length - 1];
|
|
3218
|
+
}
|
|
3219
|
+
if (alias === command._name)
|
|
3220
|
+
throw new Error("Command alias can't be the same as its name");
|
|
3221
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
3222
|
+
if (matchingCommand) {
|
|
3223
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
3224
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
3225
|
+
}
|
|
3226
|
+
command._aliases.push(alias);
|
|
3227
|
+
return this;
|
|
3228
|
+
}
|
|
3229
|
+
aliases(aliases) {
|
|
3230
|
+
if (aliases === undefined)
|
|
3231
|
+
return this._aliases;
|
|
3232
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
3233
|
+
return this;
|
|
3234
|
+
}
|
|
3235
|
+
usage(str) {
|
|
3236
|
+
if (str === undefined) {
|
|
3237
|
+
if (this._usage)
|
|
3238
|
+
return this._usage;
|
|
3239
|
+
const args = this.registeredArguments.map((arg) => {
|
|
3240
|
+
return humanReadableArgName(arg);
|
|
3241
|
+
});
|
|
3242
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
3243
|
+
}
|
|
3244
|
+
this._usage = str;
|
|
3245
|
+
return this;
|
|
3246
|
+
}
|
|
3247
|
+
name(str) {
|
|
3248
|
+
if (str === undefined)
|
|
3249
|
+
return this._name;
|
|
3250
|
+
this._name = str;
|
|
3251
|
+
return this;
|
|
3252
|
+
}
|
|
3253
|
+
helpGroup(heading) {
|
|
3254
|
+
if (heading === undefined)
|
|
3255
|
+
return this._helpGroupHeading ?? "";
|
|
3256
|
+
this._helpGroupHeading = heading;
|
|
3257
|
+
return this;
|
|
3258
|
+
}
|
|
3259
|
+
commandsGroup(heading) {
|
|
3260
|
+
if (heading === undefined)
|
|
3261
|
+
return this._defaultCommandGroup ?? "";
|
|
3262
|
+
this._defaultCommandGroup = heading;
|
|
3263
|
+
return this;
|
|
3264
|
+
}
|
|
3265
|
+
optionsGroup(heading) {
|
|
3266
|
+
if (heading === undefined)
|
|
3267
|
+
return this._defaultOptionGroup ?? "";
|
|
3268
|
+
this._defaultOptionGroup = heading;
|
|
3269
|
+
return this;
|
|
3270
|
+
}
|
|
3271
|
+
_initOptionGroup(option) {
|
|
3272
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading)
|
|
3273
|
+
option.helpGroup(this._defaultOptionGroup);
|
|
3274
|
+
}
|
|
3275
|
+
_initCommandGroup(cmd) {
|
|
3276
|
+
if (this._defaultCommandGroup && !cmd.helpGroup())
|
|
3277
|
+
cmd.helpGroup(this._defaultCommandGroup);
|
|
3278
|
+
}
|
|
3279
|
+
nameFromFilename(filename) {
|
|
3280
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
3281
|
+
return this;
|
|
3282
|
+
}
|
|
3283
|
+
executableDir(path2) {
|
|
3284
|
+
if (path2 === undefined)
|
|
3285
|
+
return this._executableDir;
|
|
3286
|
+
this._executableDir = path2;
|
|
3287
|
+
return this;
|
|
3288
|
+
}
|
|
3289
|
+
helpInformation(contextOptions) {
|
|
3290
|
+
const helper = this.createHelp();
|
|
3291
|
+
const context = this._getOutputContext(contextOptions);
|
|
3292
|
+
helper.prepareContext({
|
|
3293
|
+
error: context.error,
|
|
3294
|
+
helpWidth: context.helpWidth,
|
|
3295
|
+
outputHasColors: context.hasColors
|
|
3296
|
+
});
|
|
3297
|
+
const text = helper.formatHelp(this, helper);
|
|
3298
|
+
if (context.hasColors)
|
|
3299
|
+
return text;
|
|
3300
|
+
return this._outputConfiguration.stripColor(text);
|
|
3301
|
+
}
|
|
3302
|
+
_getOutputContext(contextOptions) {
|
|
3303
|
+
contextOptions = contextOptions || {};
|
|
3304
|
+
const error = !!contextOptions.error;
|
|
3305
|
+
let baseWrite;
|
|
3306
|
+
let hasColors;
|
|
3307
|
+
let helpWidth;
|
|
3308
|
+
if (error) {
|
|
3309
|
+
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
3310
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
3311
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
3312
|
+
} else {
|
|
3313
|
+
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
3314
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
3315
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
3316
|
+
}
|
|
3317
|
+
const write = (str) => {
|
|
3318
|
+
if (!hasColors)
|
|
3319
|
+
str = this._outputConfiguration.stripColor(str);
|
|
3320
|
+
return baseWrite(str);
|
|
3321
|
+
};
|
|
3322
|
+
return { error, write, hasColors, helpWidth };
|
|
3323
|
+
}
|
|
3324
|
+
outputHelp(contextOptions) {
|
|
3325
|
+
let deprecatedCallback;
|
|
3326
|
+
if (typeof contextOptions === "function") {
|
|
3327
|
+
deprecatedCallback = contextOptions;
|
|
3328
|
+
contextOptions = undefined;
|
|
3329
|
+
}
|
|
3330
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
3331
|
+
const eventContext = {
|
|
3332
|
+
error: outputContext.error,
|
|
3333
|
+
write: outputContext.write,
|
|
3334
|
+
command: this
|
|
3335
|
+
};
|
|
3336
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
3337
|
+
this.emit("beforeHelp", eventContext);
|
|
3338
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
3339
|
+
if (deprecatedCallback) {
|
|
3340
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
3341
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
|
|
3342
|
+
throw new Error("outputHelp callback must return a string or a Buffer");
|
|
3343
|
+
}
|
|
3344
|
+
}
|
|
3345
|
+
outputContext.write(helpInformation);
|
|
3346
|
+
if (this._getHelpOption()?.long) {
|
|
3347
|
+
this.emit(this._getHelpOption().long);
|
|
3348
|
+
}
|
|
3349
|
+
this.emit("afterHelp", eventContext);
|
|
3350
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
3351
|
+
}
|
|
3352
|
+
helpOption(flags, description) {
|
|
3353
|
+
if (typeof flags === "boolean") {
|
|
3354
|
+
if (flags) {
|
|
3355
|
+
if (this._helpOption === null)
|
|
3356
|
+
this._helpOption = undefined;
|
|
3357
|
+
if (this._defaultOptionGroup) {
|
|
3358
|
+
this._initOptionGroup(this._getHelpOption());
|
|
3359
|
+
}
|
|
3360
|
+
} else {
|
|
3361
|
+
this._helpOption = null;
|
|
3362
|
+
}
|
|
3363
|
+
return this;
|
|
3364
|
+
}
|
|
3365
|
+
this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
|
|
3366
|
+
if (flags || description)
|
|
3367
|
+
this._initOptionGroup(this._helpOption);
|
|
3368
|
+
return this;
|
|
3369
|
+
}
|
|
3370
|
+
_getHelpOption() {
|
|
3371
|
+
if (this._helpOption === undefined) {
|
|
3372
|
+
this.helpOption(undefined, undefined);
|
|
3373
|
+
}
|
|
3374
|
+
return this._helpOption;
|
|
3375
|
+
}
|
|
3376
|
+
addHelpOption(option) {
|
|
3377
|
+
this._helpOption = option;
|
|
3378
|
+
this._initOptionGroup(option);
|
|
3379
|
+
return this;
|
|
3380
|
+
}
|
|
3381
|
+
help(contextOptions) {
|
|
3382
|
+
this.outputHelp(contextOptions);
|
|
3383
|
+
let exitCode = Number(process2.exitCode ?? 0);
|
|
3384
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
3385
|
+
exitCode = 1;
|
|
3386
|
+
}
|
|
3387
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
3388
|
+
}
|
|
3389
|
+
addHelpText(position, text) {
|
|
3390
|
+
const allowedValues = ["beforeAll", "before", "after", "afterAll"];
|
|
3391
|
+
if (!allowedValues.includes(position)) {
|
|
3392
|
+
throw new Error(`Unexpected value for position to addHelpText.
|
|
3393
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
3394
|
+
}
|
|
3395
|
+
const helpEvent = `${position}Help`;
|
|
3396
|
+
this.on(helpEvent, (context) => {
|
|
3397
|
+
let helpStr;
|
|
3398
|
+
if (typeof text === "function") {
|
|
3399
|
+
helpStr = text({ error: context.error, command: context.command });
|
|
3400
|
+
} else {
|
|
3401
|
+
helpStr = text;
|
|
3402
|
+
}
|
|
3403
|
+
if (helpStr) {
|
|
3404
|
+
context.write(`${helpStr}
|
|
3405
|
+
`);
|
|
3406
|
+
}
|
|
3407
|
+
});
|
|
3408
|
+
return this;
|
|
3409
|
+
}
|
|
3410
|
+
_outputHelpIfRequested(args) {
|
|
3411
|
+
const helpOption = this._getHelpOption();
|
|
3412
|
+
const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
|
|
3413
|
+
if (helpRequested) {
|
|
3414
|
+
this.outputHelp();
|
|
3415
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
3416
|
+
}
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
function incrementNodeInspectorPort(args) {
|
|
3420
|
+
return args.map((arg) => {
|
|
3421
|
+
if (!arg.startsWith("--inspect")) {
|
|
3422
|
+
return arg;
|
|
3423
|
+
}
|
|
3424
|
+
let debugOption;
|
|
3425
|
+
let debugHost = "127.0.0.1";
|
|
3426
|
+
let debugPort = "9229";
|
|
3427
|
+
let match;
|
|
3428
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) {
|
|
3429
|
+
debugOption = match[1];
|
|
3430
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
3431
|
+
debugOption = match[1];
|
|
3432
|
+
if (/^\d+$/.test(match[3])) {
|
|
3433
|
+
debugPort = match[3];
|
|
3434
|
+
} else {
|
|
3435
|
+
debugHost = match[3];
|
|
3436
|
+
}
|
|
3437
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
3438
|
+
debugOption = match[1];
|
|
3439
|
+
debugHost = match[3];
|
|
3440
|
+
debugPort = match[4];
|
|
3441
|
+
}
|
|
3442
|
+
if (debugOption && debugPort !== "0") {
|
|
3443
|
+
return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
3444
|
+
}
|
|
3445
|
+
return arg;
|
|
3446
|
+
});
|
|
3447
|
+
}
|
|
3448
|
+
function useColor() {
|
|
3449
|
+
if (process2.env.NO_COLOR || process2.env.FORCE_COLOR === "0" || process2.env.FORCE_COLOR === "false")
|
|
3450
|
+
return false;
|
|
3451
|
+
if (process2.env.FORCE_COLOR || process2.env.CLICOLOR_FORCE !== undefined)
|
|
3452
|
+
return true;
|
|
3453
|
+
return;
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3456
|
+
// ../../node_modules/.bun/commander@15.0.0/node_modules/commander/index.js
|
|
3457
|
+
var program = new Command;
|
|
3458
|
+
|
|
3459
|
+
// src/program.ts
|
|
3460
|
+
var digitsPattern = /^\d+$/;
|
|
3461
|
+
var serialNumberPattern = /^\d{8}$/;
|
|
3462
|
+
var registrationNumberPattern = /^\d{7}$/;
|
|
3463
|
+
var unicodeWordCharacter = /[\p{Letter}\p{Mark}\p{Number}]/u;
|
|
3464
|
+
var commanderErrorPrefix = /^error:\s*/u;
|
|
3465
|
+
function nonnegativeInteger(value) {
|
|
3466
|
+
const parsed = Number(value);
|
|
3467
|
+
if (!(digitsPattern.test(value) && Number.isSafeInteger(parsed))) {
|
|
3468
|
+
throw new InvalidArgumentError("must be a nonnegative integer");
|
|
3469
|
+
}
|
|
3470
|
+
return parsed;
|
|
3471
|
+
}
|
|
3472
|
+
function dataVersion(value) {
|
|
3473
|
+
if (!digitsPattern.test(value)) {
|
|
3474
|
+
throw new InvalidArgumentError("must contain only digits");
|
|
3475
|
+
}
|
|
3476
|
+
return value;
|
|
3477
|
+
}
|
|
3478
|
+
function pageOptions(options) {
|
|
3479
|
+
if (options.offset > 0 && !options.dataVersion) {
|
|
3480
|
+
throw new BadRequestError("--data-version is required when --offset is greater than 0");
|
|
3481
|
+
}
|
|
3482
|
+
return {
|
|
3483
|
+
...options.dataVersion ? { expectedDataVersion: options.dataVersion } : {},
|
|
3484
|
+
limit: 25,
|
|
3485
|
+
offset: options.offset
|
|
3486
|
+
};
|
|
3487
|
+
}
|
|
3488
|
+
function searchInput(query, options) {
|
|
3489
|
+
if (query.trim().length === 0 || query.trim().length > 200) {
|
|
3490
|
+
throw new BadRequestError("Search query must contain between 1 and 200 characters");
|
|
3491
|
+
}
|
|
3492
|
+
if (options.mode !== "multi" && options.match) {
|
|
3493
|
+
throw new BadRequestError("--match is valid only for Multi search");
|
|
3494
|
+
}
|
|
3495
|
+
const normalizedQuery = query.trim().normalize("NFKC");
|
|
3496
|
+
if (options.mode === "split" && !unicodeWordCharacter.test(normalizedQuery)) {
|
|
3497
|
+
throw new BadRequestError("Split search requires at least one word token");
|
|
3498
|
+
}
|
|
3499
|
+
if (options.mode === "wildcard" && normalizedQuery.includes("*")) {
|
|
3500
|
+
const longestLiteralWordRun = normalizedQuery.split("*").flatMap((part) => part.match(/[\p{Letter}\p{Mark}\p{Number}]+/gu) ?? []).reduce((longest, part) => Math.max(longest, Array.from(part).length), 0);
|
|
3501
|
+
if (longestLiteralWordRun < 3) {
|
|
3502
|
+
throw new BadRequestError("Wildcard patterns must contain at least three consecutive literal word characters");
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
const common = {
|
|
3506
|
+
...pageOptions(options),
|
|
3507
|
+
query,
|
|
3508
|
+
registered: options.registered,
|
|
3509
|
+
sort: options.sort,
|
|
3510
|
+
status: options.status,
|
|
3511
|
+
type: options.type
|
|
3512
|
+
};
|
|
3513
|
+
return options.mode === "multi" ? { ...common, match: options.match ?? "both", mode: options.mode } : { ...common, mode: options.mode };
|
|
3514
|
+
}
|
|
3515
|
+
function reportInput(options) {
|
|
3516
|
+
if (!options.event) {
|
|
3517
|
+
throw new BadRequestError("--event is required");
|
|
3518
|
+
}
|
|
3519
|
+
const common = {
|
|
3520
|
+
...pageOptions(options),
|
|
3521
|
+
registered: options.registered,
|
|
3522
|
+
sort: options.sort,
|
|
3523
|
+
status: options.status,
|
|
3524
|
+
type: options.type
|
|
3525
|
+
};
|
|
3526
|
+
if (options.event === "published-for-opposition") {
|
|
3527
|
+
if (options.window || options.from || options.to) {
|
|
3528
|
+
throw new BadRequestError("Published-for-opposition reports do not use a window");
|
|
3529
|
+
}
|
|
3530
|
+
return { ...common, event: options.event };
|
|
3531
|
+
}
|
|
3532
|
+
if (options.window !== "previous-week") {
|
|
3533
|
+
throw new BadRequestError("Filed and registered reports require --window previous-week");
|
|
3534
|
+
}
|
|
3535
|
+
const hasCompleteWindow = Boolean(options.from && options.to);
|
|
3536
|
+
if (Boolean(options.from || options.to) !== hasCompleteWindow || Boolean(options.dataVersion) !== hasCompleteWindow) {
|
|
3537
|
+
throw new BadRequestError("--data-version, --from, and --to must be supplied together");
|
|
3538
|
+
}
|
|
3539
|
+
return {
|
|
3540
|
+
...common,
|
|
3541
|
+
...options.from && options.to ? { expectedFrom: options.from, expectedTo: options.to } : {},
|
|
3542
|
+
event: options.event,
|
|
3543
|
+
window: "previous-week"
|
|
3544
|
+
};
|
|
3545
|
+
}
|
|
3546
|
+
function choices(flags, values) {
|
|
3547
|
+
return new Option(flags).choices(values);
|
|
3548
|
+
}
|
|
3549
|
+
function addPageOptions(command) {
|
|
3550
|
+
return command.option("--offset <number>", "Result offset", nonnegativeInteger, 0).option("--data-version <version>", "Expected Data Version", dataVersion);
|
|
3551
|
+
}
|
|
3552
|
+
function normalizeHelpArgs(args) {
|
|
3553
|
+
if (args.length === 0) {
|
|
3554
|
+
return ["--help"];
|
|
3555
|
+
}
|
|
3556
|
+
if (args[0] === "help") {
|
|
3557
|
+
return args.length === 1 ? ["--help"] : [...args.slice(1), "--help"];
|
|
3558
|
+
}
|
|
3559
|
+
const helpIndex = args.findIndex((arg) => arg === "-h" || arg === "--help");
|
|
3560
|
+
if (helpIndex >= 0) {
|
|
3561
|
+
return args.slice(0, helpIndex + 1);
|
|
3562
|
+
}
|
|
3563
|
+
return args.includes("--version") ? ["--version"] : args;
|
|
3564
|
+
}
|
|
3565
|
+
function commanderMessage(error) {
|
|
3566
|
+
return error.message.replace(commanderErrorPrefix, "");
|
|
3567
|
+
}
|
|
3568
|
+
async function parseCli(args, version) {
|
|
3569
|
+
let command;
|
|
3570
|
+
let stdout = "";
|
|
3571
|
+
const program2 = new Command().name("tt").description("Search and inspect United States trademark records").version(version).option("--base-url <origin>", "Trademark Turtle service origin").showSuggestionAfterError().configureHelp({ sortOptions: true, sortSubcommands: true }).configureOutput({
|
|
3572
|
+
writeErr: () => {
|
|
3573
|
+
return;
|
|
3574
|
+
},
|
|
3575
|
+
writeOut: (value) => {
|
|
3576
|
+
stdout += value;
|
|
3577
|
+
}
|
|
3578
|
+
}).exitOverride().addHelpText("after", `
|
|
3579
|
+
Examples:
|
|
3580
|
+
tt search "TURTLE CLUB" --status live
|
|
3581
|
+
tt get --serial 60146682
|
|
3582
|
+
printf '%s' "shirt title" | tt match --stdin
|
|
3583
|
+
`);
|
|
3584
|
+
const auth = program2.command("auth").description("Manage the selected API credential");
|
|
3585
|
+
auth.command("set").description("Store an API key read from stdin").requiredOption("--stdin", "Read the API key from stdin").action(() => {
|
|
3586
|
+
command = { kind: "auth-set" };
|
|
3587
|
+
});
|
|
3588
|
+
auth.command("status").description("Validate and describe the selected credential").action(() => {
|
|
3589
|
+
command = { kind: "auth-status" };
|
|
3590
|
+
});
|
|
3591
|
+
auth.command("clear").description("Remove the stored credential for the selected origin").action(() => {
|
|
3592
|
+
command = { kind: "auth-clear" };
|
|
3593
|
+
});
|
|
3594
|
+
addPageOptions(program2.command("search").description("Search word trademarks").argument("<query>", "Word trademark query").addOption(choices("--mode <mode>", ["multi", "split", "wildcard"]).default("multi")).addOption(choices("--match <match>", ["both", "exact", "partial"])).addOption(choices("--status <status>", ["all", "live", "dead"]).default("all")).addOption(choices("--type <type>", ["all", "design", "typeset", "text", "other"]).default("all")).addOption(choices("--registered <value>", ["all", "yes", "no"]).default("all")).addOption(choices("--sort <sort>", ["relevance", "newest-activity", "oldest-activity"]).default("relevance"))).action((query, options) => {
|
|
3595
|
+
command = { input: searchInput(query, options), kind: "search" };
|
|
3596
|
+
});
|
|
3597
|
+
program2.command("get").description("Get one trademark by exact identity").option("--serial <number>", "Eight-digit serial number").option("--registration <number>", "Seven-digit registration number").action((options) => {
|
|
3598
|
+
if (Boolean(options.serial) === Boolean(options.registration)) {
|
|
3599
|
+
throw new BadRequestError("Supply exactly one of --serial or --registration");
|
|
3600
|
+
}
|
|
3601
|
+
if (options.serial) {
|
|
3602
|
+
if (!serialNumberPattern.test(options.serial)) {
|
|
3603
|
+
throw new BadRequestError("Serial number must be exactly 8 digits");
|
|
3604
|
+
}
|
|
3605
|
+
command = { input: { serialNumber: options.serial }, kind: "get" };
|
|
3606
|
+
return;
|
|
3607
|
+
}
|
|
3608
|
+
if (!registrationNumberPattern.test(options.registration ?? "")) {
|
|
3609
|
+
throw new BadRequestError("Registration number must be exactly 7 digits");
|
|
3610
|
+
}
|
|
3611
|
+
command = {
|
|
3612
|
+
input: { registrationNumber: options.registration ?? "" },
|
|
3613
|
+
kind: "get-by-registration"
|
|
3614
|
+
};
|
|
3615
|
+
});
|
|
3616
|
+
program2.command("match").description("Match listing text against live trademarks").option("--text <text>", "Text to inspect").option("--stdin", "Read text from stdin").addOption(choices("--type <type>", ["all", "design", "typeset", "text", "other"]).default("all")).action((options) => {
|
|
3617
|
+
if (Boolean(options.text) === Boolean(options.stdin)) {
|
|
3618
|
+
throw new BadRequestError("Supply exactly one of --text or --stdin");
|
|
3619
|
+
}
|
|
3620
|
+
command = {
|
|
3621
|
+
kind: "match",
|
|
3622
|
+
readsStdin: options.stdin === true,
|
|
3623
|
+
...options.text ? { text: options.text } : {},
|
|
3624
|
+
type: options.type
|
|
3625
|
+
};
|
|
3626
|
+
});
|
|
3627
|
+
addPageOptions(program2.command("latest").description("List recent trademark activity")).action((options) => {
|
|
3628
|
+
command = { input: pageOptions(options), kind: "latest" };
|
|
3629
|
+
});
|
|
3630
|
+
const reports = program2.command("reports").description("Generate trademark reports");
|
|
3631
|
+
addPageOptions(reports.command("run").description("Run one generated report").addOption(choices("--event <event>", ["filed", "registered", "published-for-opposition"])).option("--window <window>", "Report window").addOption(choices("--status <status>", ["all", "live", "dead"]).default("all")).addOption(choices("--type <type>", ["all", "design", "typeset", "text", "other"]).default("all")).addOption(choices("--registered <value>", ["all", "yes", "no"]).default("all")).addOption(choices("--sort <sort>", ["newest-activity", "oldest-activity"]).default("newest-activity")).option("--from <date>", "Resolved report start date").option("--to <date>", "Resolved report end date")).action((options) => {
|
|
3632
|
+
command = { input: reportInput(options), kind: "report" };
|
|
3633
|
+
});
|
|
3634
|
+
program2.command("status").description("Show safe service and ingestion status").action(() => {
|
|
3635
|
+
command = { kind: "status" };
|
|
3636
|
+
});
|
|
3637
|
+
try {
|
|
3638
|
+
await program2.parseAsync(normalizeHelpArgs(args), { from: "user" });
|
|
3639
|
+
} catch (error) {
|
|
3640
|
+
if (error instanceof CommanderError) {
|
|
3641
|
+
if (error.exitCode === 0) {
|
|
3642
|
+
return { kind: "text", text: stdout };
|
|
3643
|
+
}
|
|
3644
|
+
throw new BadRequestError(`${commanderMessage(error)}. Run 'tt --help' for usage.`, {
|
|
3645
|
+
cause: error
|
|
3646
|
+
});
|
|
3647
|
+
}
|
|
3648
|
+
throw error;
|
|
3649
|
+
}
|
|
3650
|
+
if (!command) {
|
|
3651
|
+
throw new BadRequestError("Missing command. Run 'tt --help' for usage.");
|
|
3652
|
+
}
|
|
3653
|
+
return {
|
|
3654
|
+
...program2.opts().baseUrl ? { baseUrl: program2.opts().baseUrl } : {},
|
|
3655
|
+
command,
|
|
3656
|
+
kind: "command"
|
|
3657
|
+
};
|
|
3658
|
+
}
|
|
3659
|
+
|
|
3660
|
+
// src/run.ts
|
|
3661
|
+
var defaultOrigin = "https://tmturtle.merchbase.co";
|
|
3662
|
+
var tokenPattern = /^ttk_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}_[A-Za-z0-9_-]{43}$/;
|
|
3663
|
+
var unicodeWordTokens = /[\p{Letter}\p{Mark}\p{Number}]+/gu;
|
|
3664
|
+
function normalizeOrigin(value) {
|
|
3665
|
+
let url;
|
|
3666
|
+
try {
|
|
3667
|
+
url = new URL(value);
|
|
3668
|
+
} catch (cause) {
|
|
3669
|
+
throw new BadRequestError("Base URL must be an HTTP origin", { cause });
|
|
3670
|
+
}
|
|
3671
|
+
if (url.protocol !== "http:" && url.protocol !== "https:" || url.username || url.password || url.pathname !== "/" || url.search || url.hash) {
|
|
3672
|
+
throw new BadRequestError("Base URL must be an HTTP origin");
|
|
3673
|
+
}
|
|
3674
|
+
return url.origin;
|
|
3675
|
+
}
|
|
3676
|
+
function success(data) {
|
|
3677
|
+
return { exitCode: 0, stderr: "", stdout: `${JSON.stringify({ ok: true, data })}
|
|
3678
|
+
` };
|
|
3679
|
+
}
|
|
3680
|
+
function failureResult(code, message) {
|
|
3681
|
+
return {
|
|
3682
|
+
exitCode: 1,
|
|
3683
|
+
stderr: `${JSON.stringify({ ok: false, error: { code, message, details: {} } })}
|
|
3684
|
+
`,
|
|
3685
|
+
stdout: ""
|
|
3686
|
+
};
|
|
3687
|
+
}
|
|
3688
|
+
function configuredOrigin(dependencies, explicitOrigin) {
|
|
3689
|
+
return normalizeOrigin(explicitOrigin ?? dependencies.env.TMTURTLE_BASE_URL ?? defaultOrigin);
|
|
3690
|
+
}
|
|
3691
|
+
async function credential(dependencies, origin) {
|
|
3692
|
+
if (dependencies.env.TMTURTLE_API_KEY !== undefined) {
|
|
3693
|
+
return { source: "environment", token: dependencies.env.TMTURTLE_API_KEY };
|
|
3694
|
+
}
|
|
3695
|
+
const token = await dependencies.keychain.get(origin);
|
|
3696
|
+
if (!token) {
|
|
3697
|
+
throw new CliError("UNAUTHORIZED", "Authentication required");
|
|
3698
|
+
}
|
|
3699
|
+
return { source: "keychain", token };
|
|
3700
|
+
}
|
|
3701
|
+
async function authenticatedClient(dependencies, explicitOrigin) {
|
|
3702
|
+
const origin = configuredOrigin(dependencies, explicitOrigin);
|
|
3703
|
+
const selected = await credential(dependencies, origin);
|
|
3704
|
+
const client = dependencies.createClient({ apiKey: selected.token, baseUrl: origin });
|
|
3705
|
+
return { client, origin, selected };
|
|
3706
|
+
}
|
|
3707
|
+
function remoteFailure(error) {
|
|
3708
|
+
if (!(error instanceof Error)) {
|
|
3709
|
+
return null;
|
|
3710
|
+
}
|
|
3711
|
+
const data = "data" in error ? error.data : null;
|
|
3712
|
+
const code = data && typeof data === "object" && "code" in data ? data.code : null;
|
|
3713
|
+
return typeof code === "string" ? failureResult(code, error.message) : null;
|
|
3714
|
+
}
|
|
3715
|
+
function matchInput(invocation, stdin) {
|
|
3716
|
+
const text = invocation.readsStdin ? stdin : invocation.text ?? "";
|
|
3717
|
+
if (text.trim().length === 0) {
|
|
3718
|
+
throw new BadRequestError("Match text is required");
|
|
3719
|
+
}
|
|
3720
|
+
if (text.length > 4096) {
|
|
3721
|
+
throw new BadRequestError("Match text must contain at most 4096 UTF-16 code units");
|
|
3722
|
+
}
|
|
3723
|
+
if ((text.match(unicodeWordTokens) ?? []).length > 128) {
|
|
3724
|
+
throw new BadRequestError("Match text must contain at most 128 Unicode word tokens");
|
|
3725
|
+
}
|
|
3726
|
+
return { text, type: invocation.type };
|
|
3727
|
+
}
|
|
3728
|
+
async function runCli(args, dependencies) {
|
|
3729
|
+
try {
|
|
3730
|
+
const parsed = await parseCli(args, dependencies.version);
|
|
3731
|
+
if (parsed.kind === "text") {
|
|
3732
|
+
return { exitCode: 0, stderr: "", stdout: parsed.text };
|
|
3733
|
+
}
|
|
3734
|
+
const invocation = parsed.command;
|
|
3735
|
+
if (invocation.kind === "auth-set") {
|
|
3736
|
+
const origin = configuredOrigin(dependencies, parsed.baseUrl);
|
|
3737
|
+
const token = dependencies.stdin.trim();
|
|
3738
|
+
if (!tokenPattern.test(token)) {
|
|
3739
|
+
throw new BadRequestError("Invalid Trademark Turtle API key");
|
|
3740
|
+
}
|
|
3741
|
+
await dependencies.keychain.set(origin, token);
|
|
3742
|
+
return success({ origin });
|
|
3743
|
+
}
|
|
3744
|
+
if (invocation.kind === "auth-clear") {
|
|
3745
|
+
const origin = configuredOrigin(dependencies, parsed.baseUrl);
|
|
3746
|
+
await dependencies.keychain.clear(origin);
|
|
3747
|
+
return success({ origin });
|
|
3748
|
+
}
|
|
3749
|
+
const authenticated = await authenticatedClient(dependencies, parsed.baseUrl);
|
|
3750
|
+
switch (invocation.kind) {
|
|
3751
|
+
case "auth-status": {
|
|
3752
|
+
const account = await authenticated.client.account.me.query();
|
|
3753
|
+
if (account.credential.type !== "api-key") {
|
|
3754
|
+
throw new CliError("INTERNAL_ERROR", "API key validation returned an invalid credential context");
|
|
3755
|
+
}
|
|
3756
|
+
return success({
|
|
3757
|
+
origin: authenticated.origin,
|
|
3758
|
+
credentialSource: authenticated.selected.source,
|
|
3759
|
+
keySuffix: account.credential.suffix,
|
|
3760
|
+
accountId: account.accountId
|
|
3761
|
+
});
|
|
3762
|
+
}
|
|
3763
|
+
case "get":
|
|
3764
|
+
return success(await authenticated.client.trademarks.get.query(invocation.input));
|
|
3765
|
+
case "get-by-registration":
|
|
3766
|
+
return success(await authenticated.client.trademarks.getByRegistration.query(invocation.input));
|
|
3767
|
+
case "latest":
|
|
3768
|
+
return success(await authenticated.client.trademarks.latest.query(invocation.input));
|
|
3769
|
+
case "match":
|
|
3770
|
+
return success(await authenticated.client.trademarks.matchText.query(matchInput(invocation, dependencies.stdin)));
|
|
3771
|
+
case "report":
|
|
3772
|
+
return success(await authenticated.client.reports.run.query(invocation.input));
|
|
3773
|
+
case "search":
|
|
3774
|
+
return success(await authenticated.client.trademarks.search.query(invocation.input));
|
|
3775
|
+
case "status":
|
|
3776
|
+
return success(await authenticated.client.status.query());
|
|
3777
|
+
default:
|
|
3778
|
+
throw new CliError("INTERNAL_ERROR", "Unsupported command");
|
|
3779
|
+
}
|
|
3780
|
+
} catch (error) {
|
|
3781
|
+
if (error instanceof CliError) {
|
|
3782
|
+
return failureResult(error.code, error.message);
|
|
3783
|
+
}
|
|
3784
|
+
const remote = remoteFailure(error);
|
|
3785
|
+
return remote ?? failureResult("INTERNAL_ERROR", "Command failed");
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
// src/tt.ts
|
|
3790
|
+
function write(output) {
|
|
3791
|
+
if (output.stdout) {
|
|
3792
|
+
process.stdout.write(output.stdout);
|
|
3793
|
+
}
|
|
3794
|
+
if (output.stderr) {
|
|
3795
|
+
process.stderr.write(output.stderr);
|
|
3796
|
+
}
|
|
3797
|
+
process.exitCode = output.exitCode;
|
|
3798
|
+
}
|
|
3799
|
+
var args = process.argv.slice(2);
|
|
3800
|
+
var result;
|
|
3801
|
+
try {
|
|
3802
|
+
result = await runCli(args, {
|
|
3803
|
+
createClient: createTmturtleClient,
|
|
3804
|
+
env: process.env,
|
|
3805
|
+
keychain: createMacOsKeychain(),
|
|
3806
|
+
stdin: args.includes("--stdin") ? await new Response(Bun.stdin.stream()).text() : "",
|
|
3807
|
+
version: package_default.version
|
|
3808
|
+
});
|
|
3809
|
+
} catch {
|
|
3810
|
+
result = failureResult("INTERNAL_ERROR", "Command failed");
|
|
3811
|
+
}
|
|
3812
|
+
write(result);
|