@crazyhappyone/dsh-tui 0.1.0-alpha.49 → 0.1.0-alpha.50
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 +49 -0
- package/README.i18n.yaml +2 -2
- package/README.md +116 -31
- package/README.zh.md +115 -30
- package/assets/screenshots/dsh-tui-settings.png +0 -0
- package/bin/dsh-tui.js +4 -3
- package/cordis.patch.yml +65 -59
- package/dist/index.js +22846 -4975
- package/dist/schedule.js +36041 -0
- package/dist/settings.js +961 -0
- package/dist/zen-proxy.js +353 -235
- package/package.json +79 -6
- package/presets/base-disable.patch.yml +82 -0
- package/presets/cordis.patch.yml +136 -0
- package/presets/minimal.patch.yml +78 -0
- package/presets/ptc.patch.yml +134 -0
- package/presets/registry.patch.yml +12 -0
- package/presets/standard.patch.yml +128 -0
- package/src/launcher.js +146 -64
- package/src/release-patch.js +0 -23
- package/tui/README.md +0 -146
- package/tui/README.zh.md +0 -146
- package/tui/cordis.patch.yml +0 -161
package/dist/zen-proxy.js
CHANGED
|
@@ -22,6 +22,36 @@ function pick(source, keys, forced) {
|
|
|
22
22
|
return result;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// vendor/cosmokit/src/volatile.ts
|
|
26
|
+
var write = /* @__PURE__ */ Symbol.for("cosmokit.volatile.write");
|
|
27
|
+
function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
28
|
+
if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
|
|
29
|
+
if (value === null || typeof value !== "object") return value;
|
|
30
|
+
if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
|
|
31
|
+
ancestors.add(value);
|
|
32
|
+
try {
|
|
33
|
+
if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
|
|
34
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) {
|
|
35
|
+
throw new TypeError("volatile config objects must be plain objects or arrays");
|
|
36
|
+
}
|
|
37
|
+
return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
|
|
38
|
+
} finally {
|
|
39
|
+
ancestors.delete(value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function createVolatile(value) {
|
|
43
|
+
let current = snapshot(value);
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
get: () => current,
|
|
46
|
+
[write]: (value2) => {
|
|
47
|
+
current = value2;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function isVolatile(value) {
|
|
52
|
+
return typeof value === "object" && value !== null && write in value;
|
|
53
|
+
}
|
|
54
|
+
|
|
25
55
|
// vendor/cosmokit/src/types.ts
|
|
26
56
|
function is(type, value) {
|
|
27
57
|
if (arguments.length === 1) return (value2) => is(type, value2);
|
|
@@ -112,23 +142,38 @@ function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
|
112
142
|
return result;
|
|
113
143
|
}
|
|
114
144
|
function deepEqual(a, b, strict) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
145
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
146
|
+
function compare(a2, b2) {
|
|
147
|
+
if (a2 === b2) return true;
|
|
148
|
+
if (isVolatile(a2) || isVolatile(b2)) return isVolatile(a2) && isVolatile(b2);
|
|
149
|
+
if (!strict && isNullable(a2) && isNullable(b2)) return true;
|
|
150
|
+
if (typeof a2 !== typeof b2 || typeof a2 !== "object" || !a2 || !b2) return false;
|
|
151
|
+
if (ancestors.has(a2)) return false;
|
|
152
|
+
function check(test, then) {
|
|
153
|
+
return test(a2) ? test(b2) ? then(a2, b2) : false : test(b2) ? false : void 0;
|
|
154
|
+
}
|
|
155
|
+
ancestors.add(a2);
|
|
156
|
+
try {
|
|
157
|
+
return check(Array.isArray, (a3, b3) => {
|
|
158
|
+
if (a3.length !== b3.length) return false;
|
|
159
|
+
for (let index = 0; index < a3.length; index++) {
|
|
160
|
+
if (!compare(a3[index], b3[index])) return false;
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
}) ?? check(is("Date"), (a3, b3) => a3.valueOf() === b3.valueOf()) ?? check(is("URL"), (a3, b3) => a3.href === b3.href) ?? check(is("RegExp"), (a3, b3) => a3.source === b3.source && a3.flags === b3.flags) ?? check(isArrayBufferLike, (a3, b3) => {
|
|
164
|
+
if (a3.byteLength !== b3.byteLength) return false;
|
|
165
|
+
const viewA = new Uint8Array(a3);
|
|
166
|
+
const viewB = new Uint8Array(b3);
|
|
167
|
+
for (let i = 0; i < viewA.length; i++) {
|
|
168
|
+
if (viewA[i] !== viewB[i]) return false;
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}) ?? ((!strict || [a2, b2].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({ ...a2, ...b2 }).every((key) => compare(a2[key], b2[key])));
|
|
172
|
+
} finally {
|
|
173
|
+
ancestors.delete(a2);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return compare(a, b);
|
|
132
177
|
}
|
|
133
178
|
|
|
134
179
|
// vendor/cosmokit/src/time.ts
|
|
@@ -211,28 +256,36 @@ var Time;
|
|
|
211
256
|
Time2.template = template;
|
|
212
257
|
})(Time || (Time = {}));
|
|
213
258
|
|
|
214
|
-
// vendor/schemastery/
|
|
259
|
+
// vendor/schemastery/src/index.ts
|
|
215
260
|
var kSchema = /* @__PURE__ */ Symbol.for("schemastery");
|
|
216
261
|
var kValidationError = /* @__PURE__ */ Symbol.for("ValidationError");
|
|
217
262
|
globalThis.__schemastery_index__ ??= 0;
|
|
218
263
|
globalThis.__schemastery_refs__ = void 0;
|
|
219
264
|
var ValidationError = class extends TypeError {
|
|
220
|
-
options;
|
|
221
|
-
name = "ValidationError";
|
|
222
265
|
constructor(message, options) {
|
|
223
266
|
let prefix = "$";
|
|
224
|
-
for (const segment of options.path || [])
|
|
225
|
-
|
|
226
|
-
|
|
267
|
+
for (const segment of options.path || []) {
|
|
268
|
+
if (typeof segment === "string") {
|
|
269
|
+
prefix += "." + segment;
|
|
270
|
+
} else if (typeof segment === "number") {
|
|
271
|
+
prefix += "[" + segment + "]";
|
|
272
|
+
} else if (typeof segment === "symbol") {
|
|
273
|
+
prefix += `[Symbol(${segment.toString()})]`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
227
276
|
if (prefix.startsWith(".")) prefix = prefix.slice(1);
|
|
228
277
|
super((prefix === "$" ? "" : `${prefix} `) + message);
|
|
229
278
|
this.options = options;
|
|
230
279
|
}
|
|
280
|
+
options;
|
|
281
|
+
name = "ValidationError";
|
|
231
282
|
static is(error) {
|
|
232
283
|
return !!error?.[kValidationError];
|
|
233
284
|
}
|
|
234
285
|
};
|
|
235
|
-
Object.defineProperty(ValidationError.prototype, kValidationError, {
|
|
286
|
+
Object.defineProperty(ValidationError.prototype, kValidationError, {
|
|
287
|
+
value: true
|
|
288
|
+
});
|
|
236
289
|
var Schema = function(options) {
|
|
237
290
|
const schema = function(data, options2 = {}) {
|
|
238
291
|
return Schema.resolve(data, schema, options2)[0];
|
|
@@ -250,9 +303,11 @@ var Schema = function(options) {
|
|
|
250
303
|
return refs[options.uid];
|
|
251
304
|
}
|
|
252
305
|
Object.assign(schema, options);
|
|
253
|
-
if (typeof schema.callback === "string")
|
|
254
|
-
|
|
255
|
-
|
|
306
|
+
if (typeof schema.callback === "string") {
|
|
307
|
+
try {
|
|
308
|
+
schema.callback = new Function("return " + schema.callback)();
|
|
309
|
+
} catch {
|
|
310
|
+
}
|
|
256
311
|
}
|
|
257
312
|
Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
|
|
258
313
|
Object.setPrototypeOf(schema, Schema.prototype);
|
|
@@ -262,23 +317,24 @@ var Schema = function(options) {
|
|
|
262
317
|
};
|
|
263
318
|
Schema.prototype = Object.create(Function.prototype);
|
|
264
319
|
Schema.prototype[kSchema] = true;
|
|
265
|
-
Object.defineProperty(Schema.prototype, "~standard", {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
320
|
+
Object.defineProperty(Schema.prototype, "~standard", {
|
|
321
|
+
get() {
|
|
322
|
+
return {
|
|
323
|
+
version: 1,
|
|
324
|
+
vendor: "schemastery",
|
|
325
|
+
validate: (value) => {
|
|
326
|
+
try {
|
|
327
|
+
return { value: Schema.resolve(value, this, {})[0] };
|
|
328
|
+
} catch (error) {
|
|
329
|
+
if (ValidationError.is(error)) {
|
|
330
|
+
return { issues: [{ message: error.message, path: error.options.path }] };
|
|
331
|
+
}
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
278
334
|
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
});
|
|
282
338
|
Schema.ValidationError = ValidationError;
|
|
283
339
|
Schema.prototype.toJSON = function toJSON() {
|
|
284
340
|
if (globalThis.__schemastery_refs__) {
|
|
@@ -287,10 +343,7 @@ Schema.prototype.toJSON = function toJSON() {
|
|
|
287
343
|
}
|
|
288
344
|
globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
|
|
289
345
|
globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
|
|
290
|
-
const result = {
|
|
291
|
-
uid: this.uid,
|
|
292
|
-
refs: globalThis.__schemastery_refs__
|
|
293
|
-
};
|
|
346
|
+
const result = { uid: this.uid, refs: globalThis.__schemastery_refs__ };
|
|
294
347
|
globalThis.__schemastery_refs__ = void 0;
|
|
295
348
|
return result;
|
|
296
349
|
};
|
|
@@ -306,8 +359,11 @@ function mergeDesc(original, messages) {
|
|
|
306
359
|
const result = typeof original === "string" ? { "": original } : { ...original };
|
|
307
360
|
for (const locale in messages) {
|
|
308
361
|
const value = messages[locale];
|
|
309
|
-
if (value?.$description || value?.$desc)
|
|
310
|
-
|
|
362
|
+
if (value?.$description || value?.$desc) {
|
|
363
|
+
result[locale] = value.$description || value.$desc;
|
|
364
|
+
} else if (typeof value === "string") {
|
|
365
|
+
result[locale] = value;
|
|
366
|
+
}
|
|
311
367
|
}
|
|
312
368
|
return result;
|
|
313
369
|
}
|
|
@@ -321,79 +377,72 @@ Schema.prototype.i18n = function i18n(messages) {
|
|
|
321
377
|
const schema = Schema(this);
|
|
322
378
|
const desc = mergeDesc(schema.meta.description, messages);
|
|
323
379
|
if (Object.keys(desc).length) schema.meta.description = desc;
|
|
324
|
-
if (schema.dict)
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
380
|
+
if (schema.dict) {
|
|
381
|
+
schema.dict = mapValues(schema.dict, (inner, key) => {
|
|
382
|
+
return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
if (schema.list) {
|
|
386
|
+
schema.list = schema.list.map((inner, index) => {
|
|
387
|
+
return inner.i18n(mapValues(messages, (data = {}) => {
|
|
388
|
+
if (Array.isArray(getInner(data))) return getInner(data)[index];
|
|
389
|
+
if (Array.isArray(data)) return data[index];
|
|
390
|
+
return extractKeys(data);
|
|
391
|
+
}));
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
if (schema.inner) {
|
|
395
|
+
schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
|
|
396
|
+
if (getInner(data)) return getInner(data);
|
|
331
397
|
return extractKeys(data);
|
|
332
398
|
}));
|
|
333
|
-
}
|
|
334
|
-
if (schema.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}));
|
|
338
|
-
if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
|
|
399
|
+
}
|
|
400
|
+
if (schema.sKey) {
|
|
401
|
+
schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
|
|
402
|
+
}
|
|
339
403
|
return schema;
|
|
340
404
|
};
|
|
341
405
|
Schema.prototype.extra = function extra(key, value) {
|
|
342
406
|
const schema = Schema(this);
|
|
343
|
-
schema.meta = {
|
|
344
|
-
...schema.meta,
|
|
345
|
-
[key]: value
|
|
346
|
-
};
|
|
407
|
+
schema.meta = { ...schema.meta, [key]: value };
|
|
347
408
|
return schema;
|
|
348
409
|
};
|
|
349
|
-
for (const key of [
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
...schema.meta,
|
|
359
|
-
[key]: value
|
|
360
|
-
};
|
|
361
|
-
return schema;
|
|
362
|
-
} });
|
|
410
|
+
for (const key of ["required", "disabled", "collapse", "hidden", "loose"]) {
|
|
411
|
+
Object.assign(Schema.prototype, {
|
|
412
|
+
[key](value = true) {
|
|
413
|
+
const schema = Schema(this);
|
|
414
|
+
schema.meta = { ...schema.meta, [key]: value };
|
|
415
|
+
return schema;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
363
419
|
Schema.prototype.deprecated = function deprecated() {
|
|
364
420
|
const schema = Schema(this);
|
|
365
421
|
schema.meta.badges ||= [];
|
|
366
|
-
schema.meta.badges.push({
|
|
367
|
-
text: "deprecated",
|
|
368
|
-
type: "danger"
|
|
369
|
-
});
|
|
422
|
+
schema.meta.badges.push({ text: "deprecated", type: "danger" });
|
|
370
423
|
return schema;
|
|
371
424
|
};
|
|
372
425
|
Schema.prototype.experimental = function experimental() {
|
|
373
426
|
const schema = Schema(this);
|
|
374
427
|
schema.meta.badges ||= [];
|
|
375
|
-
schema.meta.badges.push({
|
|
376
|
-
text: "experimental",
|
|
377
|
-
type: "warning"
|
|
378
|
-
});
|
|
428
|
+
schema.meta.badges.push({ text: "experimental", type: "warning" });
|
|
379
429
|
return schema;
|
|
380
430
|
};
|
|
381
431
|
Schema.prototype.pattern = function pattern(regexp) {
|
|
382
432
|
const schema = Schema(this);
|
|
383
433
|
const pattern2 = pick(regexp, ["source", "flags"]);
|
|
384
|
-
schema.meta = {
|
|
385
|
-
...schema.meta,
|
|
386
|
-
pattern: pattern2
|
|
387
|
-
};
|
|
434
|
+
schema.meta = { ...schema.meta, pattern: pattern2 };
|
|
388
435
|
return schema;
|
|
389
436
|
};
|
|
390
437
|
Schema.prototype.simplify = function simplify(value) {
|
|
438
|
+
if (isVolatile(value)) value = value.get();
|
|
391
439
|
if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
|
|
392
440
|
if (isNullable(value)) return value;
|
|
393
441
|
if (this.type === "object" || this.type === "dict") {
|
|
394
442
|
const result = {};
|
|
395
443
|
for (const key in value) {
|
|
396
|
-
const
|
|
444
|
+
const schema = this.type === "object" ? this.dict[key] : this.inner;
|
|
445
|
+
const item = schema?.simplify(value[key]);
|
|
397
446
|
if (this.type === "dict" || !isNullable(item)) result[key] = item;
|
|
398
447
|
}
|
|
399
448
|
if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
|
|
@@ -408,12 +457,18 @@ Schema.prototype.simplify = function simplify(value) {
|
|
|
408
457
|
return result;
|
|
409
458
|
} else if (this.type === "intersect") {
|
|
410
459
|
const result = {};
|
|
411
|
-
for (const item of this.list)
|
|
460
|
+
for (const item of this.list) {
|
|
461
|
+
Object.assign(result, item.simplify(value));
|
|
462
|
+
}
|
|
412
463
|
return result;
|
|
413
|
-
} else if (this.type === "union")
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
464
|
+
} else if (this.type === "union") {
|
|
465
|
+
for (const schema of this.list) {
|
|
466
|
+
try {
|
|
467
|
+
Schema.resolve(value, schema, {});
|
|
468
|
+
return schema.simplify(value);
|
|
469
|
+
} catch {
|
|
470
|
+
}
|
|
471
|
+
}
|
|
417
472
|
}
|
|
418
473
|
return value;
|
|
419
474
|
};
|
|
@@ -422,35 +477,65 @@ Schema.prototype.toString = function toString(inline) {
|
|
|
422
477
|
};
|
|
423
478
|
Schema.prototype.role = function role(role, extra2) {
|
|
424
479
|
const schema = Schema(this);
|
|
425
|
-
schema.meta = {
|
|
426
|
-
...schema.meta,
|
|
427
|
-
role,
|
|
428
|
-
extra: extra2
|
|
429
|
-
};
|
|
480
|
+
schema.meta = { ...schema.meta, role, extra: extra2 };
|
|
430
481
|
return schema;
|
|
431
482
|
};
|
|
432
|
-
for (const key of [
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
};
|
|
446
|
-
return schema;
|
|
447
|
-
} });
|
|
483
|
+
for (const key of ["default", "link", "comment", "description", "max", "min", "step"]) {
|
|
484
|
+
Object.assign(Schema.prototype, {
|
|
485
|
+
[key](value) {
|
|
486
|
+
const schema = Schema(this);
|
|
487
|
+
schema.meta = { ...schema.meta, [key]: value };
|
|
488
|
+
return schema;
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
Schema.prototype.volatile = function volatile() {
|
|
493
|
+
if (this.meta.volatile) throw new TypeError("volatile schema is already wrapped");
|
|
494
|
+
return this.extra("volatile", true);
|
|
495
|
+
};
|
|
448
496
|
var resolvers = {};
|
|
497
|
+
var checkedVolatile = /* @__PURE__ */ Symbol("checked-volatile-schema");
|
|
498
|
+
function validateVolatileSchema(schema, path = [], blocked = false, seen = /* @__PURE__ */ new Map()) {
|
|
499
|
+
const states = seen.get(schema) ?? /* @__PURE__ */ new Set();
|
|
500
|
+
if (states.has(blocked)) return;
|
|
501
|
+
states.add(blocked);
|
|
502
|
+
seen.set(schema, states);
|
|
503
|
+
if (schema.meta?.volatile && blocked) {
|
|
504
|
+
throw new ValidationError("volatile fields require a fixed object path without an enclosing volatile field", { path });
|
|
505
|
+
}
|
|
506
|
+
const nested = blocked || !!schema.meta?.volatile;
|
|
507
|
+
if (schema.dict) {
|
|
508
|
+
for (const [key, child] of Object.entries(schema.dict)) validateVolatileSchema(child, [...path, key], nested, seen);
|
|
509
|
+
}
|
|
510
|
+
if (schema.sKey) validateVolatileSchema(schema.sKey, [...path, "<key>"], true, seen);
|
|
511
|
+
if (schema.inner && (schema.type !== "lazy" || schema.inner[kSchema])) {
|
|
512
|
+
validateVolatileSchema(schema.inner, [...path, "*"], true, seen);
|
|
513
|
+
}
|
|
514
|
+
if (schema.list) {
|
|
515
|
+
for (let index = 0; index < schema.list.length; index++) {
|
|
516
|
+
validateVolatileSchema(schema.list[index], [...path, String(index)], true, seen);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
449
520
|
Schema.extend = function extend(type, resolve2) {
|
|
450
521
|
resolvers[type] = resolve2;
|
|
451
522
|
};
|
|
452
523
|
Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
|
|
453
524
|
if (!schema) return [data];
|
|
525
|
+
if (!options[checkedVolatile]) {
|
|
526
|
+
validateVolatileSchema(schema, options.path);
|
|
527
|
+
options = { ...options, [checkedVolatile]: true };
|
|
528
|
+
}
|
|
529
|
+
if (schema.meta?.volatile) {
|
|
530
|
+
const inner = Schema(schema);
|
|
531
|
+
inner.meta = { ...schema.meta, volatile: false };
|
|
532
|
+
const [value, adapted] = Schema.resolve(data, inner, options, strict);
|
|
533
|
+
try {
|
|
534
|
+
return [createVolatile(value), adapted];
|
|
535
|
+
} catch (error) {
|
|
536
|
+
throw new ValidationError(error instanceof Error ? error.message : String(error), options);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
454
539
|
if (options.ignore?.(data, schema)) return [data];
|
|
455
540
|
if (isNullable(data) && schema.type !== "lazy") {
|
|
456
541
|
if (schema.meta.required) throw new ValidationError(`missing required value`, options);
|
|
@@ -473,43 +558,38 @@ Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
|
|
|
473
558
|
}
|
|
474
559
|
};
|
|
475
560
|
Schema.from = function from(source) {
|
|
476
|
-
if (isNullable(source))
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
else if (source
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
else
|
|
561
|
+
if (isNullable(source)) {
|
|
562
|
+
return Schema.any();
|
|
563
|
+
} else if (["string", "number", "boolean"].includes(typeof source)) {
|
|
564
|
+
return Schema.const(source).required();
|
|
565
|
+
} else if (source[kSchema]) {
|
|
566
|
+
return source;
|
|
567
|
+
} else if (typeof source === "function") {
|
|
568
|
+
switch (source) {
|
|
569
|
+
case String:
|
|
570
|
+
return Schema.string().required();
|
|
571
|
+
case Number:
|
|
572
|
+
return Schema.number().required();
|
|
573
|
+
case Boolean:
|
|
574
|
+
return Schema.boolean().required();
|
|
575
|
+
case Function:
|
|
576
|
+
return Schema.function().required();
|
|
577
|
+
default:
|
|
578
|
+
return Schema.is(source).required();
|
|
579
|
+
}
|
|
580
|
+
} else {
|
|
581
|
+
throw new TypeError(`cannot infer schema from ${source}`);
|
|
582
|
+
}
|
|
496
583
|
};
|
|
497
584
|
Schema.lazy = function lazy(builder) {
|
|
498
585
|
const toJSON2 = () => {
|
|
499
586
|
if (!schema.inner[kSchema]) {
|
|
500
587
|
schema.inner = schema.builder();
|
|
501
|
-
schema.inner.meta = {
|
|
502
|
-
...schema.meta,
|
|
503
|
-
...schema.inner.meta
|
|
504
|
-
};
|
|
588
|
+
schema.inner.meta = { ...schema.meta, ...schema.inner.meta };
|
|
505
589
|
}
|
|
506
590
|
return schema.inner.toJSON();
|
|
507
591
|
};
|
|
508
|
-
const schema = new Schema({
|
|
509
|
-
type: "lazy",
|
|
510
|
-
builder,
|
|
511
|
-
inner: { toJSON: toJSON2 }
|
|
512
|
-
});
|
|
592
|
+
const schema = new Schema({ type: "lazy", builder, inner: { toJSON: toJSON2 } });
|
|
513
593
|
return schema;
|
|
514
594
|
};
|
|
515
595
|
Schema.natural = function natural() {
|
|
@@ -519,20 +599,26 @@ Schema.percent = function percent() {
|
|
|
519
599
|
return Schema.number().step(0.01).min(0).max(1).role("slider");
|
|
520
600
|
};
|
|
521
601
|
Schema.date = function date() {
|
|
522
|
-
return Schema.union([
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
602
|
+
return Schema.union([
|
|
603
|
+
Schema.is(Date),
|
|
604
|
+
Schema.transform(Schema.string().role("datetime"), (value, options) => {
|
|
605
|
+
const date2 = new Date(value);
|
|
606
|
+
if (isNaN(+date2)) throw new ValidationError(`invalid date "${value}"`, options);
|
|
607
|
+
return date2;
|
|
608
|
+
}, true)
|
|
609
|
+
]);
|
|
527
610
|
};
|
|
528
611
|
Schema.regExp = function regExp(flag = "") {
|
|
529
|
-
return Schema.union([
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
612
|
+
return Schema.union([
|
|
613
|
+
Schema.is(RegExp),
|
|
614
|
+
Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
|
|
615
|
+
try {
|
|
616
|
+
return new RegExp(value, flag);
|
|
617
|
+
} catch (e) {
|
|
618
|
+
throw new ValidationError(e.message, options);
|
|
619
|
+
}
|
|
620
|
+
}, true)
|
|
621
|
+
]);
|
|
536
622
|
};
|
|
537
623
|
Schema.arrayBuffer = function arrayBuffer(encoding) {
|
|
538
624
|
return Schema.union([
|
|
@@ -554,10 +640,8 @@ Schema.arrayBuffer = function arrayBuffer(encoding) {
|
|
|
554
640
|
Schema.extend("lazy", (data, schema, options, strict) => {
|
|
555
641
|
if (!schema.inner[kSchema]) {
|
|
556
642
|
schema.inner = schema.builder();
|
|
557
|
-
schema.inner.meta = {
|
|
558
|
-
|
|
559
|
-
...schema.inner.meta
|
|
560
|
-
};
|
|
643
|
+
schema.inner.meta = { ...schema.meta, ...schema.inner.meta };
|
|
644
|
+
validateVolatileSchema(schema.inner, options.path, true);
|
|
561
645
|
}
|
|
562
646
|
return Schema.resolve(data, schema.inner, options, strict);
|
|
563
647
|
});
|
|
@@ -597,7 +681,9 @@ function decimalShift(data, digits) {
|
|
|
597
681
|
}
|
|
598
682
|
function isMultipleOf(data, min, step) {
|
|
599
683
|
step = Math.abs(step);
|
|
600
|
-
if (!/^\d+\.\d+$/.test(step.toString()))
|
|
684
|
+
if (!/^\d+\.\d+$/.test(step.toString())) {
|
|
685
|
+
return (data - min) % step === 0;
|
|
686
|
+
}
|
|
601
687
|
const index = step.toString().indexOf(".");
|
|
602
688
|
const digits = step.toString().slice(index + 1).length;
|
|
603
689
|
return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
|
|
@@ -606,7 +692,9 @@ Schema.extend("number", (data, { meta }, options) => {
|
|
|
606
692
|
if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
|
|
607
693
|
checkWithinRange(data, meta, "number", options);
|
|
608
694
|
const { step } = meta;
|
|
609
|
-
if (step && !isMultipleOf(data, meta.min ?? 0, step))
|
|
695
|
+
if (step && !isMultipleOf(data, meta.min ?? 0, step)) {
|
|
696
|
+
throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
|
|
697
|
+
}
|
|
610
698
|
return [data];
|
|
611
699
|
});
|
|
612
700
|
Schema.extend("boolean", (data, _, options) => {
|
|
@@ -617,14 +705,20 @@ Schema.extend("bitset", (data, { bits, meta }, options) => {
|
|
|
617
705
|
let value = 0, keys = [];
|
|
618
706
|
if (typeof data === "number") {
|
|
619
707
|
value = data;
|
|
620
|
-
for (const key in bits)
|
|
708
|
+
for (const key in bits) {
|
|
709
|
+
if (data & bits[key]) {
|
|
710
|
+
keys.push(key);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
621
713
|
} else if (Array.isArray(data)) {
|
|
622
714
|
keys = data;
|
|
623
715
|
for (const key of keys) {
|
|
624
716
|
if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
|
|
625
717
|
if (key in bits) value |= bits[key];
|
|
626
718
|
}
|
|
627
|
-
} else
|
|
719
|
+
} else {
|
|
720
|
+
throw new ValidationError(`expected number or array but got ${data}`, options);
|
|
721
|
+
}
|
|
628
722
|
if (value === meta.default) return [value];
|
|
629
723
|
return [value, keys];
|
|
630
724
|
});
|
|
@@ -637,7 +731,9 @@ Schema.extend("is", (data, { constructor }, options) => {
|
|
|
637
731
|
if (data instanceof constructor) return [data];
|
|
638
732
|
throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
|
|
639
733
|
} else {
|
|
640
|
-
if (isNullable(data))
|
|
734
|
+
if (isNullable(data)) {
|
|
735
|
+
throw new ValidationError(`expected ${constructor} but got ${data}`, options);
|
|
736
|
+
}
|
|
641
737
|
let prototype = Object.getPrototypeOf(data);
|
|
642
738
|
while (prototype) {
|
|
643
739
|
if (prototype.constructor?.name === constructor) return [data];
|
|
@@ -657,7 +753,7 @@ function property(data, key, schema, options) {
|
|
|
657
753
|
} catch (e) {
|
|
658
754
|
if (!options?.autofix) throw e;
|
|
659
755
|
delete data[key];
|
|
660
|
-
return schema.meta.default;
|
|
756
|
+
return schema.meta.volatile ? createVolatile(schema.meta.default) : schema.meta.default;
|
|
661
757
|
}
|
|
662
758
|
}
|
|
663
759
|
Schema.extend("array", (data, { inner, meta }, options) => {
|
|
@@ -700,17 +796,21 @@ Schema.extend("object", (data, { dict }, options, strict) => {
|
|
|
700
796
|
const result = {};
|
|
701
797
|
for (const key in dict) {
|
|
702
798
|
const value = property(data, key, dict[key], options);
|
|
703
|
-
if (!isNullable(value) || key in data)
|
|
799
|
+
if (!isNullable(value) || key in data) {
|
|
800
|
+
result[key] = value;
|
|
801
|
+
}
|
|
704
802
|
}
|
|
705
803
|
if (!strict) merge(result, data);
|
|
706
804
|
return [result];
|
|
707
805
|
});
|
|
708
806
|
Schema.extend("union", (data, { list, toString: toString2 }, options, strict) => {
|
|
709
807
|
const messages = [];
|
|
710
|
-
for (const inner of list)
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
808
|
+
for (const inner of list) {
|
|
809
|
+
try {
|
|
810
|
+
return Schema.resolve(data, inner, options, strict);
|
|
811
|
+
} catch (error) {
|
|
812
|
+
messages.push(error);
|
|
813
|
+
}
|
|
714
814
|
}
|
|
715
815
|
throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
|
|
716
816
|
});
|
|
@@ -720,68 +820,89 @@ Schema.extend("intersect", (data, { list, toString: toString2 }, options, strict
|
|
|
720
820
|
for (const inner of list) {
|
|
721
821
|
const value = Schema.resolve(data, inner, options, true)[0];
|
|
722
822
|
if (isNullable(value)) continue;
|
|
723
|
-
if (isNullable(result))
|
|
724
|
-
|
|
725
|
-
else if (typeof
|
|
726
|
-
|
|
823
|
+
if (isNullable(result)) {
|
|
824
|
+
result = value;
|
|
825
|
+
} else if (typeof result !== typeof value) {
|
|
826
|
+
throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
|
|
827
|
+
} else if (typeof value === "object") {
|
|
828
|
+
merge(result ??= {}, value);
|
|
829
|
+
} else if (result !== value) {
|
|
830
|
+
throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
|
|
831
|
+
}
|
|
727
832
|
}
|
|
728
833
|
if (!strict && isPlainObject(data)) merge(result, data);
|
|
729
834
|
return [result];
|
|
730
835
|
});
|
|
731
836
|
Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
|
|
732
837
|
const [result, adapted = data] = Schema.resolve(data, inner, options, true);
|
|
733
|
-
if (preserve)
|
|
734
|
-
|
|
838
|
+
if (preserve) {
|
|
839
|
+
return [callback(result)];
|
|
840
|
+
} else {
|
|
841
|
+
return [callback(result), callback(adapted)];
|
|
842
|
+
}
|
|
735
843
|
});
|
|
736
844
|
var formatters = {};
|
|
737
845
|
function defineMethod(name2, keys, format) {
|
|
738
846
|
formatters[name2] = format;
|
|
739
|
-
Object.assign(Schema, {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
847
|
+
Object.assign(Schema, {
|
|
848
|
+
[name2](...args) {
|
|
849
|
+
const schema = new Schema({ type: name2 });
|
|
850
|
+
keys.forEach((key, index) => {
|
|
851
|
+
switch (key) {
|
|
852
|
+
case "sKey":
|
|
853
|
+
schema.sKey = args[index] ?? Schema.string();
|
|
854
|
+
break;
|
|
855
|
+
case "inner":
|
|
856
|
+
schema.inner = Schema.from(args[index]);
|
|
857
|
+
break;
|
|
858
|
+
case "list":
|
|
859
|
+
schema.list = args[index].map(Schema.from);
|
|
860
|
+
break;
|
|
861
|
+
case "dict":
|
|
862
|
+
schema.dict = mapValues(args[index], Schema.from);
|
|
863
|
+
break;
|
|
864
|
+
case "bits": {
|
|
865
|
+
schema.bits = {};
|
|
866
|
+
for (const key2 in args[index]) {
|
|
867
|
+
if (typeof args[index][key2] !== "number") continue;
|
|
868
|
+
schema.bits[key2] = args[index][key2];
|
|
869
|
+
}
|
|
870
|
+
break;
|
|
760
871
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
872
|
+
case "callback": {
|
|
873
|
+
const callback = schema.callback = args[index];
|
|
874
|
+
callback["toJSON"] ||= () => callback.toString();
|
|
875
|
+
break;
|
|
876
|
+
}
|
|
877
|
+
case "constructor": {
|
|
878
|
+
const constructor = schema.constructor = args[index];
|
|
879
|
+
if (typeof constructor === "function") {
|
|
880
|
+
;
|
|
881
|
+
constructor["toJSON"] ||= () => constructor["name"];
|
|
882
|
+
}
|
|
883
|
+
break;
|
|
884
|
+
}
|
|
885
|
+
default:
|
|
886
|
+
schema[key] = args[index];
|
|
771
887
|
}
|
|
772
|
-
|
|
773
|
-
|
|
888
|
+
});
|
|
889
|
+
if (name2 === "object" || name2 === "dict") {
|
|
890
|
+
schema.meta.default = {};
|
|
891
|
+
} else if (name2 === "array" || name2 === "tuple") {
|
|
892
|
+
schema.meta.default = [];
|
|
893
|
+
} else if (name2 === "bitset") {
|
|
894
|
+
schema.meta.default = 0;
|
|
774
895
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
else if (name2 === "bitset") schema.meta.default = 0;
|
|
779
|
-
return schema;
|
|
780
|
-
} });
|
|
896
|
+
return schema;
|
|
897
|
+
}
|
|
898
|
+
});
|
|
781
899
|
}
|
|
782
900
|
defineMethod("is", ["constructor"], ({ constructor }) => {
|
|
783
|
-
if (typeof constructor === "function")
|
|
784
|
-
|
|
901
|
+
if (typeof constructor === "function") {
|
|
902
|
+
return constructor.name;
|
|
903
|
+
} else {
|
|
904
|
+
return constructor;
|
|
905
|
+
}
|
|
785
906
|
});
|
|
786
907
|
defineMethod("any", [], () => "any");
|
|
787
908
|
defineMethod("never", [], () => "never");
|
|
@@ -807,25 +928,22 @@ defineMethod("union", ["list"], ({ list }, inline) => {
|
|
|
807
928
|
defineMethod("intersect", ["list"], ({ list }) => {
|
|
808
929
|
return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
|
|
809
930
|
});
|
|
810
|
-
defineMethod("transform", [
|
|
811
|
-
|
|
812
|
-
"callback",
|
|
813
|
-
"preserve"
|
|
814
|
-
], ({ inner }, isInner) => inner.toString(isInner));
|
|
931
|
+
defineMethod("transform", ["inner", "callback", "preserve"], ({ inner }, isInner) => inner.toString(isInner));
|
|
932
|
+
var src_default = Schema;
|
|
815
933
|
|
|
816
934
|
// ../dsh-tui/plugins/zen-proxy/index.js
|
|
817
935
|
import crypto from "node:crypto";
|
|
818
936
|
import http from "node:http";
|
|
819
937
|
import https from "node:https";
|
|
820
938
|
var name = "zen-proxy";
|
|
821
|
-
var Config =
|
|
822
|
-
host:
|
|
823
|
-
port:
|
|
824
|
-
upstreamHost:
|
|
825
|
-
upstreamBasePath:
|
|
826
|
-
userAgent:
|
|
827
|
-
clientHeader:
|
|
828
|
-
projectHeader:
|
|
939
|
+
var Config = src_default.object({
|
|
940
|
+
host: src_default.string().default("127.0.0.1"),
|
|
941
|
+
port: src_default.number().default(4097),
|
|
942
|
+
upstreamHost: src_default.string().default("opencode.ai"),
|
|
943
|
+
upstreamBasePath: src_default.string().default("/zen/v1"),
|
|
944
|
+
userAgent: src_default.string().default("opencode/1.18.30"),
|
|
945
|
+
clientHeader: src_default.string().default("cli"),
|
|
946
|
+
projectHeader: src_default.string().default("global")
|
|
829
947
|
});
|
|
830
948
|
var inject = [];
|
|
831
949
|
var rnd = (p) => `${p}${crypto.randomBytes(13).toString("hex")}`;
|