@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/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
- if (a === b) return true;
116
- if (!strict && isNullable(a) && isNullable(b)) return true;
117
- if (typeof a !== typeof b) return false;
118
- if (typeof a !== "object") return false;
119
- if (!a || !b) return false;
120
- function check(test, then) {
121
- return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
122
- }
123
- return check(Array.isArray, (a2, b2) => a2.length === b2.length && a2.every((item, index) => deepEqual(item, b2[index]))) ?? check(is("Date"), (a2, b2) => a2.valueOf() === b2.valueOf()) ?? check(is("RegExp"), (a2, b2) => a2.source === b2.source && a2.flags === b2.flags) ?? check(isArrayBufferLike, (a2, b2) => {
124
- if (a2.byteLength !== b2.byteLength) return false;
125
- const viewA = new Uint8Array(a2);
126
- const viewB = new Uint8Array(b2);
127
- for (let i = 0; i < viewA.length; i++) {
128
- if (viewA[i] !== viewB[i]) return false;
129
- }
130
- return true;
131
- }) ?? Object.keys({ ...a, ...b }).every((key) => deepEqual(a[key], b[key], strict));
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/lib/index.mjs
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 || []) if (typeof segment === "string") prefix += "." + segment;
225
- else if (typeof segment === "number") prefix += "[" + segment + "]";
226
- else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
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, { value: true });
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") try {
254
- schema.callback = new Function("return " + schema.callback)();
255
- } catch {
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", { get() {
266
- return {
267
- version: 1,
268
- vendor: "schemastery",
269
- validate: (value) => {
270
- try {
271
- return { value: Schema.resolve(value, this, {})[0] };
272
- } catch (error) {
273
- if (ValidationError.is(error)) return { issues: [{
274
- message: error.message,
275
- path: error.options.path
276
- }] };
277
- throw error;
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) result[locale] = value.$description || value.$desc;
310
- else if (typeof value === "string") result[locale] = value;
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) schema.dict = mapValues(schema.dict, (inner, key) => {
325
- return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
326
- });
327
- if (schema.list) schema.list = schema.list.map((inner, index) => {
328
- return inner.i18n(mapValues(messages, (data = {}) => {
329
- if (Array.isArray(getInner(data))) return getInner(data)[index];
330
- if (Array.isArray(data)) return data[index];
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.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
335
- if (getInner(data)) return getInner(data);
336
- return extractKeys(data);
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
- "required",
351
- "disabled",
352
- "collapse",
353
- "hidden",
354
- "loose"
355
- ]) Object.assign(Schema.prototype, { [key](value = true) {
356
- const schema = Schema(this);
357
- schema.meta = {
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 item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
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) Object.assign(result, item.simplify(value));
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") for (const schema of this.list) try {
414
- Schema.resolve(value, schema, {});
415
- return schema.simplify(value);
416
- } catch {
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
- "default",
434
- "link",
435
- "comment",
436
- "description",
437
- "max",
438
- "min",
439
- "step"
440
- ]) Object.assign(Schema.prototype, { [key](value) {
441
- const schema = Schema(this);
442
- schema.meta = {
443
- ...schema.meta,
444
- [key]: value
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)) return Schema.any();
477
- else if ([
478
- "string",
479
- "number",
480
- "boolean"
481
- ].includes(typeof source)) return Schema.const(source).required();
482
- else if (source[kSchema]) return source;
483
- else if (typeof source === "function") switch (source) {
484
- case String:
485
- return Schema.string().required();
486
- case Number:
487
- return Schema.number().required();
488
- case Boolean:
489
- return Schema.boolean().required();
490
- case Function:
491
- return Schema.function().required();
492
- default:
493
- return Schema.is(source).required();
494
- }
495
- else throw new TypeError(`cannot infer schema from ${source}`);
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([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
523
- const date2 = new Date(value);
524
- if (isNaN(+date2)) throw new ValidationError(`invalid date "${value}"`, options);
525
- return date2;
526
- }, true)]);
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([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
530
- try {
531
- return new RegExp(value, flag);
532
- } catch (e) {
533
- throw new ValidationError(e.message, options);
534
- }
535
- }, true)]);
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
- ...schema.meta,
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())) return (data - min) % step === 0;
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)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
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) if (data & bits[key]) keys.push(key);
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 throw new ValidationError(`expected number or array but got ${data}`, options);
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)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
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) result[key] = value;
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) try {
711
- return Schema.resolve(data, inner, options, strict);
712
- } catch (error) {
713
- messages.push(error);
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)) result = value;
724
- else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
725
- else if (typeof value === "object") merge(result ??= {}, value);
726
- else if (result !== value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
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) return [callback(result)];
734
- else return [callback(result), callback(adapted)];
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, { [name2](...args) {
740
- const schema = new Schema({ type: name2 });
741
- keys.forEach((key, index) => {
742
- switch (key) {
743
- case "sKey":
744
- schema.sKey = args[index] ?? Schema.string();
745
- break;
746
- case "inner":
747
- schema.inner = Schema.from(args[index]);
748
- break;
749
- case "list":
750
- schema.list = args[index].map(Schema.from);
751
- break;
752
- case "dict":
753
- schema.dict = mapValues(args[index], Schema.from);
754
- break;
755
- case "bits":
756
- schema.bits = {};
757
- for (const key2 in args[index]) {
758
- if (typeof args[index][key2] !== "number") continue;
759
- schema.bits[key2] = args[index][key2];
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
- break;
762
- case "callback": {
763
- const callback = schema.callback = args[index];
764
- callback["toJSON"] ||= () => callback.toString();
765
- break;
766
- }
767
- case "constructor": {
768
- const constructor = schema.constructor = args[index];
769
- if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
770
- break;
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
- default:
773
- schema[key] = args[index];
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
- if (name2 === "object" || name2 === "dict") schema.meta.default = {};
777
- else if (name2 === "array" || name2 === "tuple") schema.meta.default = [];
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") return constructor.name;
784
- else return constructor;
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
- "inner",
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 = Schema.object({
822
- host: Schema.string().default("127.0.0.1"),
823
- port: Schema.number().default(4097),
824
- upstreamHost: Schema.string().default("opencode.ai"),
825
- upstreamBasePath: Schema.string().default("/zen/v1"),
826
- userAgent: Schema.string().default("opencode/1.18.30"),
827
- clientHeader: Schema.string().default("cli"),
828
- projectHeader: Schema.string().default("global")
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")}`;