@eduwork/dsh-mail 0.1.0-alpha.5 → 0.1.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/lib/index.js CHANGED
@@ -54,732 +54,480 @@ const DEFAULTS = Object.freeze({
54
54
  maxAttachmentBytes: 20971520
55
55
  });
56
56
  //#endregion
57
- //#region node_modules/cosmokit/lib/index.cjs
58
- var require_lib$7 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
59
- var __defProp = Object.defineProperty;
60
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
61
- var __getOwnPropNames = Object.getOwnPropertyNames;
62
- var __hasOwnProp = Object.prototype.hasOwnProperty;
63
- var __export = (target, all) => {
64
- for (var name in all) __defProp(target, name, {
65
- get: all[name],
66
- enumerable: true
67
- });
68
- };
69
- var __copyProps = (to, from, except, desc) => {
70
- if (from && typeof from === "object" || typeof from === "function") {
71
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
72
- get: () => from[key],
73
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
74
- });
75
- }
76
- return to;
77
- };
78
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
79
- var index_exports = {};
80
- __export(index_exports, {
81
- Binary: () => Binary,
82
- Time: () => Time,
83
- arrayBufferToBase64: () => arrayBufferToBase64,
84
- arrayBufferToHex: () => arrayBufferToHex,
85
- base64ToArrayBuffer: () => base64ToArrayBuffer,
86
- camelCase: () => camelCase,
87
- camelize: () => camelize,
88
- capitalize: () => capitalize,
89
- clone: () => clone,
90
- contain: () => contain,
91
- deduplicate: () => deduplicate,
92
- deepEqual: () => deepEqual,
93
- defineProperty: () => defineProperty,
94
- difference: () => difference,
95
- filterKeys: () => filterKeys,
96
- formatProperty: () => formatProperty,
97
- hexToArrayBuffer: () => hexToArrayBuffer,
98
- hyphenate: () => hyphenate,
99
- intersection: () => intersection,
100
- is: () => is,
101
- isNonNullable: () => isNonNullable,
102
- isNullable: () => isNullable,
103
- isPlainObject: () => isPlainObject,
104
- makeArray: () => makeArray,
105
- mapValues: () => mapValues,
106
- noop: () => noop,
107
- omit: () => omit,
108
- paramCase: () => paramCase,
109
- pick: () => pick,
110
- remove: () => remove,
111
- sanitize: () => sanitize,
112
- snakeCase: () => snakeCase,
113
- trimSlash: () => trimSlash,
114
- uncapitalize: () => uncapitalize,
115
- union: () => union,
116
- valueMap: () => mapValues
117
- });
118
- module.exports = __toCommonJS(index_exports);
119
- function noop() {}
120
- function isNullable(value) {
121
- return value === null || value === void 0;
122
- }
123
- function isNonNullable(value) {
124
- return !isNullable(value);
125
- }
126
- function isPlainObject(data) {
127
- return data && typeof data === "object" && !Array.isArray(data);
128
- }
129
- function filterKeys(object, filter) {
130
- return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
131
- }
132
- function mapValues(object, transform) {
133
- return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
134
- }
135
- function pick(source, keys, forced) {
136
- if (!keys) return { ...source };
137
- const result = {};
138
- for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
139
- return result;
140
- }
141
- function omit(source, keys) {
142
- if (!keys) return { ...source };
143
- const result = { ...source };
144
- for (const key of keys) Reflect.deleteProperty(result, key);
145
- return result;
146
- }
147
- function defineProperty(object, key, value) {
148
- return Object.defineProperty(object, key, {
149
- writable: true,
150
- value,
151
- enumerable: false
152
- });
153
- }
154
- function contain(array1, array2) {
155
- return array2.every((item) => array1.includes(item));
156
- }
157
- function intersection(array1, array2) {
158
- return array1.filter((item) => array2.includes(item));
159
- }
160
- function difference(array1, array2) {
161
- return array1.filter((item) => !array2.includes(item));
162
- }
163
- function union(array1, array2) {
164
- return Array.from(/* @__PURE__ */ new Set([...array1, ...array2]));
165
- }
166
- function deduplicate(array) {
167
- return [...new Set(array)];
168
- }
169
- function remove(list, item) {
170
- const index = list?.indexOf(item);
171
- if (index >= 0) {
172
- list.splice(index, 1);
173
- return true;
174
- } else return false;
175
- }
176
- function makeArray(source) {
177
- return Array.isArray(source) ? source : isNullable(source) ? [] : [source];
178
- }
179
- function is(type, value) {
180
- if (arguments.length === 1) return (value2) => is(type, value2);
181
- return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
182
- }
183
- function isArrayBufferLike(value) {
184
- return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
185
- }
186
- function isArrayBufferSource(value) {
187
- return isArrayBufferLike(value) || ArrayBuffer.isView(value);
188
- }
189
- var Binary;
190
- ((Binary2) => {
191
- Binary2.is = isArrayBufferLike;
192
- Binary2.isSource = isArrayBufferSource;
193
- function fromSource(source) {
194
- if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
195
- else return source;
196
- }
197
- Binary2.fromSource = fromSource;
198
- function toBase64(source) {
199
- source = fromSource(source);
200
- if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
201
- let binary = "";
202
- const bytes = new Uint8Array(source);
203
- for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
204
- return btoa(binary);
205
- }
206
- Binary2.toBase64 = toBase64;
207
- function fromBase64(source) {
208
- if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
209
- return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
210
- }
211
- Binary2.fromBase64 = fromBase64;
212
- function toHex(source) {
213
- source = fromSource(source);
214
- if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
215
- return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
216
- }
217
- Binary2.toHex = toHex;
218
- function fromHex(source) {
219
- if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
220
- const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
221
- const buffer = [];
222
- for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
223
- return Uint8Array.from(buffer).buffer;
224
- }
225
- Binary2.fromHex = fromHex;
226
- })(Binary || (Binary = {}));
227
- var base64ToArrayBuffer = Binary.fromBase64;
228
- var arrayBufferToBase64 = Binary.toBase64;
229
- var hexToArrayBuffer = Binary.fromHex;
230
- var arrayBufferToHex = Binary.toHex;
231
- function clone(source, refs = /* @__PURE__ */ new Map()) {
232
- if (!source || typeof source !== "object") return source;
233
- if (is("Date", source)) return new Date(source.valueOf());
234
- if (is("RegExp", source)) return new RegExp(source.source, source.flags);
235
- if (isArrayBufferLike(source)) return source.slice(0);
57
+ //#region node_modules/@deepseek-ai/cosmokit/lib/index.js
58
+ /** Return true when a value is `null` or `undefined`. */
59
+ function isNullable(value) {
60
+ return value === null || value === void 0;
61
+ }
62
+ /** Return true for non-array object values. */
63
+ function isPlainObject(data) {
64
+ return data && typeof data === "object" && !Array.isArray(data);
65
+ }
66
+ /** Filter object entries and return a new object. */
67
+ function filterKeys(object, filter) {
68
+ return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
69
+ }
70
+ /** Map object values while preserving the original key set. */
71
+ function mapValues(object, transform) {
72
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
73
+ }
74
+ /** Pick selected keys from an object, optionally including `undefined` values. */
75
+ function pick(source, keys, forced) {
76
+ if (!keys) return { ...source };
77
+ const result = {};
78
+ for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
79
+ return result;
80
+ }
81
+ /** Test values using `instanceof` with a `toStringTag` fallback. */
82
+ function is(type, value) {
83
+ if (arguments.length === 1) return (value) => is(type, value);
84
+ return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
85
+ }
86
+ function isArrayBufferLike(value) {
87
+ return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
88
+ }
89
+ function isArrayBufferSource(value) {
90
+ return isArrayBufferLike(value) || ArrayBuffer.isView(value);
91
+ }
92
+ /** Binary source detection and base64/hex conversion helpers. */
93
+ var Binary;
94
+ (function(Binary) {
95
+ Binary.is = isArrayBufferLike;
96
+ Binary.isSource = isArrayBufferSource;
97
+ function fromSource(source) {
236
98
  if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
237
- const cached = refs.get(source);
238
- if (cached) return cached;
239
- if (Array.isArray(source)) {
240
- const result2 = [];
241
- refs.set(source, result2);
242
- source.forEach((value, index) => {
243
- result2[index] = Reflect.apply(clone, null, [value, refs]);
244
- });
245
- return result2;
246
- }
247
- const result = Object.create(Object.getPrototypeOf(source));
99
+ else return source;
100
+ }
101
+ Binary.fromSource = fromSource;
102
+ function toBase64(source) {
103
+ source = fromSource(source);
104
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
105
+ let binary = "";
106
+ const bytes = new Uint8Array(source);
107
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
108
+ return btoa(binary);
109
+ }
110
+ Binary.toBase64 = toBase64;
111
+ function fromBase64(source) {
112
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
113
+ return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
114
+ }
115
+ Binary.fromBase64 = fromBase64;
116
+ function toHex(source) {
117
+ source = fromSource(source);
118
+ if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
119
+ return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
120
+ }
121
+ Binary.toHex = toHex;
122
+ function fromHex(source) {
123
+ if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
124
+ const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
125
+ const buffer = [];
126
+ for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
127
+ return Uint8Array.from(buffer).buffer;
128
+ }
129
+ Binary.fromHex = fromHex;
130
+ })(Binary || (Binary = {}));
131
+ Binary.fromBase64;
132
+ Binary.toBase64;
133
+ Binary.fromHex;
134
+ Binary.toHex;
135
+ /** Deep-clone common JavaScript values while preserving prototypes and cycles. */
136
+ function clone(source, refs = /* @__PURE__ */ new Map()) {
137
+ if (!source || typeof source !== "object") return source;
138
+ if (is("Date", source)) return new Date(source.valueOf());
139
+ if (is("RegExp", source)) return new RegExp(source.source, source.flags);
140
+ if (isArrayBufferLike(source)) return source.slice(0);
141
+ if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
142
+ const cached = refs.get(source);
143
+ if (cached) return cached;
144
+ if (Array.isArray(source)) {
145
+ const result = [];
248
146
  refs.set(source, result);
249
- for (const key of Reflect.ownKeys(source)) {
250
- const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
251
- if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
252
- Reflect.defineProperty(result, key, descriptor);
253
- }
147
+ source.forEach((value, index) => {
148
+ result[index] = Reflect.apply(clone, null, [value, refs]);
149
+ });
254
150
  return result;
255
151
  }
256
- function deepEqual(a, b, strict) {
257
- if (a === b) return true;
258
- if (!strict && isNullable(a) && isNullable(b)) return true;
259
- if (typeof a !== typeof b) return false;
260
- if (typeof a !== "object") return false;
261
- if (!a || !b) return false;
262
- function check(test, then) {
263
- return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
264
- }
265
- 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) => {
266
- if (a2.byteLength !== b2.byteLength) return false;
267
- const viewA = new Uint8Array(a2);
268
- const viewB = new Uint8Array(b2);
269
- for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
270
- return true;
271
- }) ?? Object.keys({
272
- ...a,
273
- ...b
274
- }).every((key) => deepEqual(a[key], b[key], strict));
152
+ const result = Object.create(Object.getPrototypeOf(source));
153
+ refs.set(source, result);
154
+ for (const key of Reflect.ownKeys(source)) {
155
+ const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
156
+ if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
157
+ Reflect.defineProperty(result, key, descriptor);
275
158
  }
276
- function capitalize(source) {
277
- return source.charAt(0).toUpperCase() + source.slice(1);
278
- }
279
- function uncapitalize(source) {
280
- return source.charAt(0).toLowerCase() + source.slice(1);
281
- }
282
- function camelCase(source) {
283
- return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
159
+ return result;
160
+ }
161
+ /** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
162
+ function deepEqual(a, b, strict) {
163
+ if (a === b) return true;
164
+ if (!strict && isNullable(a) && isNullable(b)) return true;
165
+ if (typeof a !== typeof b) return false;
166
+ if (typeof a !== "object") return false;
167
+ if (!a || !b) return false;
168
+ function check(test, then) {
169
+ return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
170
+ }
171
+ return check(Array.isArray, (a, b) => a.length === b.length && a.every((item, index) => deepEqual(item, b[index]))) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
172
+ if (a.byteLength !== b.byteLength) return false;
173
+ const viewA = new Uint8Array(a);
174
+ const viewB = new Uint8Array(b);
175
+ for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
176
+ return true;
177
+ }) ?? Object.keys({
178
+ ...a,
179
+ ...b
180
+ }).every((key) => deepEqual(a[key], b[key], strict));
181
+ }
182
+ /** Time constants plus parsing and formatting helpers. */
183
+ var Time;
184
+ (function(Time) {
185
+ Time.millisecond = 1;
186
+ Time.second = 1e3;
187
+ Time.minute = Time.second * 60;
188
+ Time.hour = Time.minute * 60;
189
+ Time.day = Time.hour * 24;
190
+ Time.week = Time.day * 7;
191
+ let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
192
+ function setTimezoneOffset(offset) {
193
+ timezoneOffset = offset;
194
+ }
195
+ Time.setTimezoneOffset = setTimezoneOffset;
196
+ function getTimezoneOffset() {
197
+ return timezoneOffset;
198
+ }
199
+ Time.getTimezoneOffset = getTimezoneOffset;
200
+ function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
201
+ if (typeof date === "number") date = new Date(date);
202
+ if (offset === void 0) offset = timezoneOffset;
203
+ return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
204
+ }
205
+ Time.getDateNumber = getDateNumber;
206
+ function fromDateNumber(value, offset) {
207
+ const date = new Date(value * Time.day);
208
+ if (offset === void 0) offset = timezoneOffset;
209
+ return new Date(+date + offset * Time.minute);
210
+ }
211
+ Time.fromDateNumber = fromDateNumber;
212
+ const numeric = /\d+(?:\.\d+)?/.source;
213
+ const timeRegExp = new RegExp(`^${[
214
+ "w(?:eek(?:s)?)?",
215
+ "d(?:ay(?:s)?)?",
216
+ "h(?:our(?:s)?)?",
217
+ "m(?:in(?:ute)?(?:s)?)?",
218
+ "s(?:ec(?:ond)?(?:s)?)?"
219
+ ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
220
+ function parseTime(source) {
221
+ const capture = timeRegExp.exec(source);
222
+ if (!capture) return 0;
223
+ return (parseFloat(capture[1]) * Time.week || 0) + (parseFloat(capture[2]) * Time.day || 0) + (parseFloat(capture[3]) * Time.hour || 0) + (parseFloat(capture[4]) * Time.minute || 0) + (parseFloat(capture[5]) * Time.second || 0);
224
+ }
225
+ Time.parseTime = parseTime;
226
+ function parseDate(date) {
227
+ const parsed = parseTime(date);
228
+ if (parsed) date = Date.now() + parsed;
229
+ else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
230
+ else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
231
+ return date ? new Date(date) : /* @__PURE__ */ new Date();
232
+ }
233
+ Time.parseDate = parseDate;
234
+ function format(ms) {
235
+ const abs = Math.abs(ms);
236
+ if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
237
+ else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
238
+ else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
239
+ else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
240
+ return ms + "ms";
241
+ }
242
+ Time.format = format;
243
+ function toDigits(source, length = 2) {
244
+ return source.toString().padStart(length, "0");
245
+ }
246
+ Time.toDigits = toDigits;
247
+ function template(template, time = /* @__PURE__ */ new Date()) {
248
+ return template.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
249
+ }
250
+ Time.template = template;
251
+ })(Time || (Time = {}));
252
+ //#endregion
253
+ //#region node_modules/@deepseek-ai/schemastery/lib/index.mjs
254
+ const kSchema = Symbol.for("schemastery");
255
+ const kValidationError = Symbol.for("ValidationError");
256
+ globalThis.__schemastery_index__ ??= 0;
257
+ globalThis.__schemastery_refs__ = void 0;
258
+ var ValidationError = class extends TypeError {
259
+ options;
260
+ name = "ValidationError";
261
+ constructor(message, options) {
262
+ let prefix = "$";
263
+ for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
264
+ else if (typeof segment === "number") prefix += "[" + segment + "]";
265
+ else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
266
+ if (prefix.startsWith(".")) prefix = prefix.slice(1);
267
+ super((prefix === "$" ? "" : `${prefix} `) + message);
268
+ this.options = options;
269
+ }
270
+ static is(error) {
271
+ return !!error?.[kValidationError];
284
272
  }
285
- function tokenize(source, delimiters, delimiter) {
286
- const output = [];
287
- let state = 0;
288
- for (let i = 0; i < source.length; i++) {
289
- const code = source.charCodeAt(i);
290
- if (code >= 65 && code <= 90) {
291
- if (state === 1) {
292
- const next = source.charCodeAt(i + 1);
293
- if (next >= 97 && next <= 122) output.push(delimiter);
294
- output.push(code + 32);
295
- } else {
296
- if (state !== 0) output.push(delimiter);
297
- output.push(code + 32);
298
- }
299
- state = 1;
300
- } else if (code >= 97 && code <= 122) {
301
- output.push(code);
302
- state = 2;
303
- } else if (delimiters.includes(code)) {
304
- if (state !== 0) output.push(delimiter);
305
- state = 0;
306
- } else output.push(code);
307
- }
308
- return String.fromCharCode(...output);
309
- }
310
- function paramCase(source) {
311
- return tokenize(source, [45, 95], 45);
312
- }
313
- function snakeCase(source) {
314
- return tokenize(source, [45, 95], 95);
315
- }
316
- var camelize = camelCase;
317
- var hyphenate = paramCase;
318
- function formatProperty(key) {
319
- if (typeof key !== "string") return `[${key.toString()}]`;
320
- return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
321
- }
322
- function trimSlash(source) {
323
- return source.replace(/\/$/, "");
324
- }
325
- function sanitize(source) {
326
- if (!source.startsWith("/")) source = "/" + source;
327
- return trimSlash(source);
328
- }
329
- var Time;
330
- ((Time2) => {
331
- Time2.millisecond = 1;
332
- Time2.second = 1e3;
333
- Time2.minute = Time2.second * 60;
334
- Time2.hour = Time2.minute * 60;
335
- Time2.day = Time2.hour * 24;
336
- Time2.week = Time2.day * 7;
337
- let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
338
- function setTimezoneOffset(offset) {
339
- timezoneOffset = offset;
340
- }
341
- Time2.setTimezoneOffset = setTimezoneOffset;
342
- function getTimezoneOffset() {
343
- return timezoneOffset;
344
- }
345
- Time2.getTimezoneOffset = getTimezoneOffset;
346
- function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
347
- if (typeof date === "number") date = new Date(date);
348
- if (offset === void 0) offset = timezoneOffset;
349
- return Math.floor((date.valueOf() / Time2.minute - offset) / 1440);
350
- }
351
- Time2.getDateNumber = getDateNumber;
352
- function fromDateNumber(value, offset) {
353
- const date = new Date(value * Time2.day);
354
- if (offset === void 0) offset = timezoneOffset;
355
- return new Date(+date + offset * Time2.minute);
356
- }
357
- Time2.fromDateNumber = fromDateNumber;
358
- const numeric = /\d+(?:\.\d+)?/.source;
359
- const timeRegExp = new RegExp(`^${[
360
- "w(?:eek(?:s)?)?",
361
- "d(?:ay(?:s)?)?",
362
- "h(?:our(?:s)?)?",
363
- "m(?:in(?:ute)?(?:s)?)?",
364
- "s(?:ec(?:ond)?(?:s)?)?"
365
- ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
366
- function parseTime(source) {
367
- const capture = timeRegExp.exec(source);
368
- if (!capture) return 0;
369
- return (parseFloat(capture[1]) * Time2.week || 0) + (parseFloat(capture[2]) * Time2.day || 0) + (parseFloat(capture[3]) * Time2.hour || 0) + (parseFloat(capture[4]) * Time2.minute || 0) + (parseFloat(capture[5]) * Time2.second || 0);
370
- }
371
- Time2.parseTime = parseTime;
372
- function parseDate(date) {
373
- const parsed = parseTime(date);
374
- if (parsed) date = Date.now() + parsed;
375
- else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
376
- else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
377
- return date ? new Date(date) : /* @__PURE__ */ new Date();
378
- }
379
- Time2.parseDate = parseDate;
380
- function format(ms) {
381
- const abs = Math.abs(ms);
382
- if (abs >= Time2.day - Time2.hour / 2) return Math.round(ms / Time2.day) + "d";
383
- else if (abs >= Time2.hour - Time2.minute / 2) return Math.round(ms / Time2.hour) + "h";
384
- else if (abs >= Time2.minute - Time2.second / 2) return Math.round(ms / Time2.minute) + "m";
385
- else if (abs >= Time2.second) return Math.round(ms / Time2.second) + "s";
386
- return ms + "ms";
387
- }
388
- Time2.format = format;
389
- function toDigits(source, length = 2) {
390
- return source.toString().padStart(length, "0");
391
- }
392
- Time2.toDigits = toDigits;
393
- function template(template2, time = /* @__PURE__ */ new Date()) {
394
- return template2.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
395
- }
396
- Time2.template = template;
397
- })(Time || (Time = {}));
398
- 0 && (module.exports = {
399
- Binary,
400
- Time,
401
- arrayBufferToBase64,
402
- arrayBufferToHex,
403
- base64ToArrayBuffer,
404
- camelCase,
405
- camelize,
406
- capitalize,
407
- clone,
408
- contain,
409
- deduplicate,
410
- deepEqual,
411
- defineProperty,
412
- difference,
413
- filterKeys,
414
- formatProperty,
415
- hexToArrayBuffer,
416
- hyphenate,
417
- intersection,
418
- is,
419
- isNonNullable,
420
- isNullable,
421
- isPlainObject,
422
- makeArray,
423
- mapValues,
424
- noop,
425
- omit,
426
- paramCase,
427
- pick,
428
- remove,
429
- sanitize,
430
- snakeCase,
431
- trimSlash,
432
- uncapitalize,
433
- union,
434
- valueMap
273
+ };
274
+ Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
275
+ const Schema = function(options) {
276
+ const schema = function(data, options = {}) {
277
+ return Schema.resolve(data, schema, options)[0];
278
+ };
279
+ if (options.refs) {
280
+ const refs = mapValues(options.refs, (options) => new Schema(options));
281
+ const getRef = (uid) => refs[uid];
282
+ for (const key in refs) {
283
+ const options = refs[key];
284
+ options.sKey = getRef(options.sKey);
285
+ options.inner = getRef(options.inner);
286
+ options.list = options.list && options.list.map(getRef);
287
+ options.dict = options.dict && mapValues(options.dict, getRef);
288
+ }
289
+ return refs[options.uid];
290
+ }
291
+ Object.assign(schema, options);
292
+ if (typeof schema.callback === "string") try {
293
+ schema.callback = new Function("return " + schema.callback)();
294
+ } catch {}
295
+ Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
296
+ Object.setPrototypeOf(schema, Schema.prototype);
297
+ schema.meta ||= {};
298
+ schema.toString = schema.toString.bind(schema);
299
+ return schema;
300
+ };
301
+ Schema.prototype = Object.create(Function.prototype);
302
+ Schema.prototype[kSchema] = true;
303
+ Object.defineProperty(Schema.prototype, "~standard", { get() {
304
+ return {
305
+ version: 1,
306
+ vendor: "schemastery",
307
+ validate: (value) => {
308
+ try {
309
+ return { value: Schema.resolve(value, this, {})[0] };
310
+ } catch (error) {
311
+ if (ValidationError.is(error)) return { issues: [{
312
+ message: error.message,
313
+ path: error.options.path
314
+ }] };
315
+ throw error;
316
+ }
317
+ }
318
+ };
319
+ } });
320
+ Schema.ValidationError = ValidationError;
321
+ Schema.prototype.toJSON = function toJSON() {
322
+ if (globalThis.__schemastery_refs__) {
323
+ globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
324
+ return this.uid;
325
+ }
326
+ globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
327
+ globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
328
+ const result = {
329
+ uid: this.uid,
330
+ refs: globalThis.__schemastery_refs__
331
+ };
332
+ globalThis.__schemastery_refs__ = void 0;
333
+ return result;
334
+ };
335
+ Schema.prototype.set = function set(key, value) {
336
+ this.dict[key] = value;
337
+ return this;
338
+ };
339
+ Schema.prototype.push = function push(value) {
340
+ this.list.push(value);
341
+ return this;
342
+ };
343
+ function mergeDesc(original, messages) {
344
+ const result = typeof original === "string" ? { "": original } : { ...original };
345
+ for (const locale in messages) {
346
+ const value = messages[locale];
347
+ if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
348
+ else if (typeof value === "string") result[locale] = value;
349
+ }
350
+ return result;
351
+ }
352
+ function getInner(value) {
353
+ return value?.$value ?? value?.$inner;
354
+ }
355
+ function extractKeys(data) {
356
+ return filterKeys(data ?? {}, (key) => !key.startsWith("$"));
357
+ }
358
+ Schema.prototype.i18n = function i18n(messages) {
359
+ const schema = Schema(this);
360
+ const desc = mergeDesc(schema.meta.description, messages);
361
+ if (Object.keys(desc).length) schema.meta.description = desc;
362
+ if (schema.dict) schema.dict = mapValues(schema.dict, (inner, key) => {
363
+ return inner.i18n(mapValues(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
435
364
  });
436
- }));
437
- //#endregion
438
- //#region src/host/config.js
439
- var import_lib = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
440
- var __defProp = Object.defineProperty;
441
- var __name = (target, value) => __defProp(target, "name", {
442
- value,
443
- configurable: true
365
+ if (schema.list) schema.list = schema.list.map((inner, index) => {
366
+ return inner.i18n(mapValues(messages, (data = {}) => {
367
+ if (Array.isArray(getInner(data))) return getInner(data)[index];
368
+ if (Array.isArray(data)) return data[index];
369
+ return extractKeys(data);
370
+ }));
444
371
  });
445
- var import_cosmokit = require_lib$7();
446
- var kSchema = Symbol.for("schemastery");
447
- var kValidationError = Symbol.for("ValidationError");
448
- globalThis.__schemastery_index__ ??= 0;
449
- globalThis.__schemastery_refs__ = void 0;
450
- var ValidationError = class extends TypeError {
451
- constructor(message, options) {
452
- let prefix = "$";
453
- for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
454
- else if (typeof segment === "number") prefix += "[" + segment + "]";
455
- else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
456
- if (prefix.startsWith(".")) prefix = prefix.slice(1);
457
- super((prefix === "$" ? "" : `${prefix} `) + message);
458
- this.options = options;
459
- }
460
- static {
461
- __name(this, "ValidationError");
462
- }
463
- name = "ValidationError";
464
- static is(error) {
465
- return !!error?.[kValidationError];
466
- }
372
+ if (schema.inner) schema.inner = schema.inner.i18n(mapValues(messages, (data) => {
373
+ if (getInner(data)) return getInner(data);
374
+ return extractKeys(data);
375
+ }));
376
+ if (schema.sKey) schema.sKey = schema.sKey.i18n(mapValues(messages, (data) => data?.$key));
377
+ return schema;
378
+ };
379
+ Schema.prototype.extra = function extra(key, value) {
380
+ const schema = Schema(this);
381
+ schema.meta = {
382
+ ...schema.meta,
383
+ [key]: value
467
384
  };
468
- Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
469
- var Schema = /* @__PURE__ */ __name(function(options) {
470
- const schema = /* @__PURE__ */ __name(function(data, options2 = {}) {
471
- return Schema.resolve(data, schema, options2)[0];
472
- }, "schema");
473
- if (options.refs) {
474
- const refs = (0, import_cosmokit.valueMap)(options.refs, (options2) => new Schema(options2));
475
- const getRef = /* @__PURE__ */ __name((uid) => refs[uid], "getRef");
476
- for (const key in refs) {
477
- const options2 = refs[key];
478
- options2.sKey = getRef(options2.sKey);
479
- options2.inner = getRef(options2.inner);
480
- options2.list = options2.list && options2.list.map(getRef);
481
- options2.dict = options2.dict && (0, import_cosmokit.valueMap)(options2.dict, getRef);
482
- }
483
- return refs[options.uid];
484
- }
485
- Object.assign(schema, options);
486
- if (typeof schema.callback === "string") try {
487
- schema.callback = new Function("return " + schema.callback)();
488
- } catch {}
489
- Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
490
- Object.setPrototypeOf(schema, Schema.prototype);
491
- schema.meta ||= {};
492
- schema.toString = schema.toString.bind(schema);
493
- return schema;
494
- }, "Schema");
495
- Schema.prototype = Object.create(Function.prototype);
496
- Schema.prototype[kSchema] = true;
497
- Object.defineProperty(Schema.prototype, "~standard", { get() {
498
- return {
499
- version: 1,
500
- vendor: "schemastery",
501
- validate: /* @__PURE__ */ __name((value) => {
502
- try {
503
- return { value: Schema.resolve(value, this, {})[0] };
504
- } catch (error) {
505
- if (ValidationError.is(error)) return { issues: [{
506
- message: error.message,
507
- path: error.options.path
508
- }] };
509
- throw error;
510
- }
511
- }, "validate")
512
- };
513
- } });
514
- Schema.ValidationError = ValidationError;
515
- Schema.prototype.toJSON = /* @__PURE__ */ __name(function toJSON() {
516
- if (globalThis.__schemastery_refs__) {
517
- globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
518
- return this.uid;
519
- }
520
- globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
521
- globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
522
- const result = {
523
- uid: this.uid,
524
- refs: globalThis.__schemastery_refs__
525
- };
526
- globalThis.__schemastery_refs__ = void 0;
527
- return result;
528
- }, "toJSON");
529
- Schema.prototype.set = /* @__PURE__ */ __name(function set(key, value) {
530
- this.dict[key] = value;
531
- return this;
532
- }, "set");
533
- Schema.prototype.push = /* @__PURE__ */ __name(function push(value) {
534
- this.list.push(value);
535
- return this;
536
- }, "push");
537
- function mergeDesc(original, messages) {
538
- const result = typeof original === "string" ? { "": original } : { ...original };
539
- for (const locale in messages) {
540
- const value = messages[locale];
541
- if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
542
- else if (typeof value === "string") result[locale] = value;
385
+ return schema;
386
+ };
387
+ for (const key of [
388
+ "required",
389
+ "disabled",
390
+ "collapse",
391
+ "hidden",
392
+ "loose"
393
+ ]) Object.assign(Schema.prototype, { [key](value = true) {
394
+ const schema = Schema(this);
395
+ schema.meta = {
396
+ ...schema.meta,
397
+ [key]: value
398
+ };
399
+ return schema;
400
+ } });
401
+ Schema.prototype.deprecated = function deprecated() {
402
+ const schema = Schema(this);
403
+ schema.meta.badges ||= [];
404
+ schema.meta.badges.push({
405
+ text: "deprecated",
406
+ type: "danger"
407
+ });
408
+ return schema;
409
+ };
410
+ Schema.prototype.experimental = function experimental() {
411
+ const schema = Schema(this);
412
+ schema.meta.badges ||= [];
413
+ schema.meta.badges.push({
414
+ text: "experimental",
415
+ type: "warning"
416
+ });
417
+ return schema;
418
+ };
419
+ Schema.prototype.pattern = function pattern(regexp) {
420
+ const schema = Schema(this);
421
+ const pattern = pick(regexp, ["source", "flags"]);
422
+ schema.meta = {
423
+ ...schema.meta,
424
+ pattern
425
+ };
426
+ return schema;
427
+ };
428
+ Schema.prototype.simplify = function simplify(value) {
429
+ if (deepEqual(value, this.meta.default, this.type === "dict")) return null;
430
+ if (isNullable(value)) return value;
431
+ if (this.type === "object" || this.type === "dict") {
432
+ const result = {};
433
+ for (const key in value) {
434
+ const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
435
+ if (this.type === "dict" || !isNullable(item)) result[key] = item;
543
436
  }
437
+ if (deepEqual(result, this.meta.default, this.type === "dict")) return null;
544
438
  return result;
545
- }
546
- __name(mergeDesc, "mergeDesc");
547
- function getInner(value) {
548
- return value?.$value ?? value?.$inner;
549
- }
550
- __name(getInner, "getInner");
551
- function extractKeys(data) {
552
- return (0, import_cosmokit.filterKeys)(data ?? {}, (key) => !key.startsWith("$"));
553
- }
554
- __name(extractKeys, "extractKeys");
555
- Schema.prototype.i18n = /* @__PURE__ */ __name(function i18n(messages) {
556
- const schema = Schema(this);
557
- const desc = mergeDesc(schema.meta.description, messages);
558
- if (Object.keys(desc).length) schema.meta.description = desc;
559
- if (schema.dict) schema.dict = (0, import_cosmokit.valueMap)(schema.dict, (inner, key) => {
560
- return inner.i18n((0, import_cosmokit.valueMap)(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
561
- });
562
- if (schema.list) schema.list = schema.list.map((inner, index) => {
563
- return inner.i18n((0, import_cosmokit.valueMap)(messages, (data = {}) => {
564
- if (Array.isArray(getInner(data))) return getInner(data)[index];
565
- if (Array.isArray(data)) return data[index];
566
- return extractKeys(data);
567
- }));
568
- });
569
- if (schema.inner) schema.inner = schema.inner.i18n((0, import_cosmokit.valueMap)(messages, (data) => {
570
- if (getInner(data)) return getInner(data);
571
- return extractKeys(data);
572
- }));
573
- if (schema.sKey) schema.sKey = schema.sKey.i18n((0, import_cosmokit.valueMap)(messages, (data) => data?.$key));
574
- return schema;
575
- }, "i18n");
576
- Schema.prototype.extra = /* @__PURE__ */ __name(function extra(key, value) {
577
- const schema = Schema(this);
578
- schema.meta = {
579
- ...schema.meta,
580
- [key]: value
581
- };
582
- return schema;
583
- }, "extra");
584
- for (const key of [
585
- "required",
586
- "disabled",
587
- "collapse",
588
- "hidden",
589
- "loose"
590
- ]) Object.assign(Schema.prototype, { [key](value = true) {
591
- const schema = Schema(this);
592
- schema.meta = {
593
- ...schema.meta,
594
- [key]: value
595
- };
596
- return schema;
597
- } });
598
- Schema.prototype.deprecated = /* @__PURE__ */ __name(function deprecated() {
599
- const schema = Schema(this);
600
- schema.meta.badges ||= [];
601
- schema.meta.badges.push({
602
- text: "deprecated",
603
- type: "danger"
604
- });
605
- return schema;
606
- }, "deprecated");
607
- Schema.prototype.experimental = /* @__PURE__ */ __name(function experimental() {
608
- const schema = Schema(this);
609
- schema.meta.badges ||= [];
610
- schema.meta.badges.push({
611
- text: "experimental",
612
- type: "warning"
613
- });
614
- return schema;
615
- }, "experimental");
616
- Schema.prototype.pattern = /* @__PURE__ */ __name(function pattern(regexp) {
617
- const schema = Schema(this);
618
- const pattern2 = (0, import_cosmokit.pick)(regexp, ["source", "flags"]);
619
- schema.meta = {
620
- ...schema.meta,
621
- pattern: pattern2
622
- };
623
- return schema;
624
- }, "pattern");
625
- Schema.prototype.simplify = /* @__PURE__ */ __name(function simplify(value) {
626
- if ((0, import_cosmokit.deepEqual)(value, this.meta.default, this.type === "dict")) return null;
627
- if ((0, import_cosmokit.isNullable)(value)) return value;
628
- if (this.type === "object" || this.type === "dict") {
629
- const result = {};
630
- for (const key in value) {
631
- const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
632
- if (this.type === "dict" || !(0, import_cosmokit.isNullable)(item)) result[key] = item;
633
- }
634
- if ((0, import_cosmokit.deepEqual)(result, this.meta.default, this.type === "dict")) return null;
635
- return result;
636
- } else if (this.type === "array" || this.type === "tuple") {
637
- const result = [];
638
- value.forEach((value2, index) => {
639
- const schema = this.type === "array" ? this.inner : this.list[index];
640
- const item = schema ? schema.simplify(value2) : value2;
641
- result.push(item);
642
- });
643
- return result;
644
- } else if (this.type === "intersect") {
645
- const result = {};
646
- for (const item of this.list) Object.assign(result, item.simplify(value));
647
- return result;
648
- } else if (this.type === "union") for (const schema of this.list) try {
649
- Schema.resolve(value, schema, {});
650
- return schema.simplify(value);
651
- } catch {}
652
- return value;
653
- }, "simplify");
654
- Schema.prototype.toString = /* @__PURE__ */ __name(function toString(inline) {
655
- return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
656
- }, "toString");
657
- Schema.prototype.role = /* @__PURE__ */ __name(function role(role, extra2) {
658
- const schema = Schema(this);
659
- schema.meta = {
660
- ...schema.meta,
661
- role,
662
- extra: extra2
663
- };
664
- return schema;
665
- }, "role");
666
- for (const key of [
667
- "default",
668
- "link",
669
- "comment",
670
- "description",
671
- "max",
672
- "min",
673
- "step"
674
- ]) Object.assign(Schema.prototype, { [key](value) {
675
- const schema = Schema(this);
676
- schema.meta = {
677
- ...schema.meta,
678
- [key]: value
679
- };
680
- return schema;
681
- } });
682
- var resolvers = {};
683
- Schema.extend = /* @__PURE__ */ __name(function extend(type, resolve2) {
684
- resolvers[type] = resolve2;
685
- }, "extend");
686
- Schema.resolve = /* @__PURE__ */ __name(function resolve(data, schema, options = {}, strict = false) {
687
- if (!schema) return [data];
688
- if (options.ignore?.(data, schema)) return [data];
689
- if ((0, import_cosmokit.isNullable)(data) && schema.type !== "lazy") {
690
- if (schema.meta.required) throw new ValidationError(`missing required value`, options);
691
- let current = schema;
692
- let fallback = schema.meta.default;
693
- while (current?.type === "intersect" && (0, import_cosmokit.isNullable)(fallback)) {
694
- current = current.list[0];
695
- fallback = current?.meta.default;
696
- }
697
- if ((0, import_cosmokit.isNullable)(fallback)) return [data];
698
- data = (0, import_cosmokit.clone)(fallback);
699
- }
700
- const callback = resolvers[schema.type];
701
- if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
702
- try {
703
- return callback(data, schema, options, strict);
704
- } catch (error) {
705
- if (!schema.meta.loose) throw error;
706
- return [schema.meta.default];
707
- }
708
- }, "resolve");
709
- Schema.from = /* @__PURE__ */ __name(function from(source) {
710
- if ((0, import_cosmokit.isNullable)(source)) return Schema.any();
711
- else if ([
712
- "string",
713
- "number",
714
- "boolean"
715
- ].includes(typeof source)) return Schema.const(source).required();
716
- else if (source[kSchema]) return source;
717
- else if (typeof source === "function") switch (source) {
718
- case String: return Schema.string().required();
719
- case Number: return Schema.number().required();
720
- case Boolean: return Schema.boolean().required();
721
- case Function: return Schema.function().required();
722
- default: return Schema.is(source).required();
723
- }
724
- else throw new TypeError(`cannot infer schema from ${source}`);
725
- }, "from");
726
- Schema.lazy = /* @__PURE__ */ __name(function lazy(builder) {
727
- const schema = new Schema({
728
- type: "lazy",
729
- builder,
730
- inner: { toJSON: /* @__PURE__ */ __name(() => {
731
- if (!schema.inner[kSchema]) {
732
- schema.inner = schema.builder();
733
- schema.inner.meta = {
734
- ...schema.meta,
735
- ...schema.inner.meta
736
- };
737
- }
738
- return schema.inner.toJSON();
739
- }, "toJSON") }
439
+ } else if (this.type === "array" || this.type === "tuple") {
440
+ const result = [];
441
+ value.forEach((value, index) => {
442
+ const schema = this.type === "array" ? this.inner : this.list[index];
443
+ const item = schema ? schema.simplify(value) : value;
444
+ result.push(item);
740
445
  });
741
- return schema;
742
- }, "lazy");
743
- Schema.natural = /* @__PURE__ */ __name(function natural() {
744
- return Schema.number().step(1).min(0);
745
- }, "natural");
746
- Schema.percent = /* @__PURE__ */ __name(function percent() {
747
- return Schema.number().step(.01).min(0).max(1).role("slider");
748
- }, "percent");
749
- Schema.date = /* @__PURE__ */ __name(function date() {
750
- return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
751
- const date2 = new Date(value);
752
- if (isNaN(+date2)) throw new ValidationError(`invalid date "${value}"`, options);
753
- return date2;
754
- }, true)]);
755
- }, "date");
756
- Schema.regExp = /* @__PURE__ */ __name(function regExp(flag = "") {
757
- return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
758
- try {
759
- return new RegExp(value, flag);
760
- } catch (e) {
761
- throw new ValidationError(e.message, options);
762
- }
763
- }, true)]);
764
- }, "regExp");
765
- Schema.arrayBuffer = /* @__PURE__ */ __name(function arrayBuffer(encoding) {
766
- return Schema.union([
767
- Schema.is(ArrayBuffer),
768
- Schema.is(SharedArrayBuffer),
769
- Schema.transform(Schema.any(), (value, options) => {
770
- if (import_cosmokit.Binary.isSource(value)) return import_cosmokit.Binary.fromSource(value);
771
- throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
772
- }, true),
773
- ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
774
- try {
775
- return encoding === "base64" ? import_cosmokit.Binary.fromBase64(value) : import_cosmokit.Binary.fromHex(value);
776
- } catch (e) {
777
- throw new ValidationError(e.message, options);
778
- }
779
- }, true)] : []
780
- ]);
781
- }, "arrayBuffer");
782
- Schema.extend("lazy", (data, schema, options, strict) => {
446
+ return result;
447
+ } else if (this.type === "intersect") {
448
+ const result = {};
449
+ for (const item of this.list) Object.assign(result, item.simplify(value));
450
+ return result;
451
+ } else if (this.type === "union") for (const schema of this.list) try {
452
+ Schema.resolve(value, schema, {});
453
+ return schema.simplify(value);
454
+ } catch {}
455
+ return value;
456
+ };
457
+ Schema.prototype.toString = function toString(inline) {
458
+ return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
459
+ };
460
+ Schema.prototype.role = function role(role, extra) {
461
+ const schema = Schema(this);
462
+ schema.meta = {
463
+ ...schema.meta,
464
+ role,
465
+ extra
466
+ };
467
+ return schema;
468
+ };
469
+ for (const key of [
470
+ "default",
471
+ "link",
472
+ "comment",
473
+ "description",
474
+ "max",
475
+ "min",
476
+ "step"
477
+ ]) Object.assign(Schema.prototype, { [key](value) {
478
+ const schema = Schema(this);
479
+ schema.meta = {
480
+ ...schema.meta,
481
+ [key]: value
482
+ };
483
+ return schema;
484
+ } });
485
+ const resolvers = {};
486
+ Schema.extend = function extend(type, resolve) {
487
+ resolvers[type] = resolve;
488
+ };
489
+ Schema.resolve = function resolve(data, schema, options = {}, strict = false) {
490
+ if (!schema) return [data];
491
+ if (options.ignore?.(data, schema)) return [data];
492
+ if (isNullable(data) && schema.type !== "lazy") {
493
+ if (schema.meta.required) throw new ValidationError(`missing required value`, options);
494
+ let current = schema;
495
+ let fallback = schema.meta.default;
496
+ while (current?.type === "intersect" && isNullable(fallback)) {
497
+ current = current.list[0];
498
+ fallback = current?.meta.default;
499
+ }
500
+ if (isNullable(fallback)) return [data];
501
+ data = clone(fallback);
502
+ }
503
+ const callback = resolvers[schema.type];
504
+ if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
505
+ try {
506
+ return callback(data, schema, options, strict);
507
+ } catch (error) {
508
+ if (!schema.meta.loose) throw error;
509
+ return [schema.meta.default];
510
+ }
511
+ };
512
+ Schema.from = function from(source) {
513
+ if (isNullable(source)) return Schema.any();
514
+ else if ([
515
+ "string",
516
+ "number",
517
+ "boolean"
518
+ ].includes(typeof source)) return Schema.const(source).required();
519
+ else if (source[kSchema]) return source;
520
+ else if (typeof source === "function") switch (source) {
521
+ case String: return Schema.string().required();
522
+ case Number: return Schema.number().required();
523
+ case Boolean: return Schema.boolean().required();
524
+ case Function: return Schema.function().required();
525
+ default: return Schema.is(source).required();
526
+ }
527
+ else throw new TypeError(`cannot infer schema from ${source}`);
528
+ };
529
+ Schema.lazy = function lazy(builder) {
530
+ const toJSON = () => {
783
531
  if (!schema.inner[kSchema]) {
784
532
  schema.inner = schema.builder();
785
533
  schema.inner.meta = {
@@ -787,282 +535,332 @@ var import_lib = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((export
787
535
  ...schema.inner.meta
788
536
  };
789
537
  }
790
- return Schema.resolve(data, schema.inner, options, strict);
791
- });
792
- Schema.extend("any", (data) => {
793
- return [data];
794
- });
795
- Schema.extend("never", (data, _, options) => {
796
- throw new ValidationError(`expected nullable but got ${data}`, options);
797
- });
798
- Schema.extend("const", (data, { value }, options) => {
799
- if ((0, import_cosmokit.deepEqual)(data, value)) return [value];
800
- throw new ValidationError(`expected ${value} but got ${data}`, options);
801
- });
802
- function checkWithinRange(data, meta, description, options, skipMin = false) {
803
- const { max = Infinity, min = -Infinity } = meta;
804
- if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
805
- if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
806
- }
807
- __name(checkWithinRange, "checkWithinRange");
808
- Schema.extend("string", (data, { meta }, options) => {
809
- if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
810
- if (meta.pattern) {
811
- const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
812
- if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
813
- }
814
- checkWithinRange(data.length, meta, "string length", options);
815
- return [data];
816
- });
817
- function decimalShift(data, digits) {
818
- const str = data.toString();
819
- if (str.includes("e")) return data * Math.pow(10, digits);
820
- const index = str.indexOf(".");
821
- if (index === -1) return data * Math.pow(10, digits);
822
- const frac = str.slice(index + 1);
823
- const integer = str.slice(0, index);
824
- if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
825
- return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
826
- }
827
- __name(decimalShift, "decimalShift");
828
- function isMultipleOf(data, min, step) {
829
- step = Math.abs(step);
830
- if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
831
- const index = step.toString().indexOf(".");
832
- const digits = step.toString().slice(index + 1).length;
833
- return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
834
- }
835
- __name(isMultipleOf, "isMultipleOf");
836
- Schema.extend("number", (data, { meta }, options) => {
837
- if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
838
- checkWithinRange(data, meta, "number", options);
839
- const { step } = meta;
840
- if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
841
- return [data];
842
- });
843
- Schema.extend("boolean", (data, _, options) => {
844
- if (typeof data === "boolean") return [data];
845
- throw new ValidationError(`expected boolean but got ${data}`, options);
846
- });
847
- Schema.extend("bitset", (data, { bits, meta }, options) => {
848
- let value = 0, keys = [];
849
- if (typeof data === "number") {
850
- value = data;
851
- for (const key in bits) if (data & bits[key]) keys.push(key);
852
- } else if (Array.isArray(data)) {
853
- keys = data;
854
- for (const key of keys) {
855
- if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
856
- if (key in bits) value |= bits[key];
857
- }
858
- } else throw new ValidationError(`expected number or array but got ${data}`, options);
859
- if (value === meta.default) return [value];
860
- return [value, keys];
861
- });
862
- Schema.extend("function", (data, _, options) => {
863
- if (typeof data === "function") return [data];
864
- throw new ValidationError(`expected function but got ${data}`, options);
865
- });
866
- Schema.extend("is", (data, { constructor }, options) => {
867
- if (typeof constructor === "function") {
868
- if (data instanceof constructor) return [data];
869
- throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
870
- } else {
871
- if ((0, import_cosmokit.isNullable)(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
872
- let prototype = Object.getPrototypeOf(data);
873
- while (prototype) {
874
- if (prototype.constructor?.name === constructor) return [data];
875
- prototype = Object.getPrototypeOf(prototype);
876
- }
877
- throw new ValidationError(`expected ${constructor} but got ${data}`, options);
878
- }
538
+ return schema.inner.toJSON();
539
+ };
540
+ const schema = new Schema({
541
+ type: "lazy",
542
+ builder,
543
+ inner: { toJSON }
879
544
  });
880
- function property(data, key, schema, options) {
545
+ return schema;
546
+ };
547
+ Schema.natural = function natural() {
548
+ return Schema.number().step(1).min(0);
549
+ };
550
+ Schema.percent = function percent() {
551
+ return Schema.number().step(.01).min(0).max(1).role("slider");
552
+ };
553
+ Schema.date = function date() {
554
+ return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
555
+ const date = new Date(value);
556
+ if (isNaN(+date)) throw new ValidationError(`invalid date "${value}"`, options);
557
+ return date;
558
+ }, true)]);
559
+ };
560
+ Schema.regExp = function regExp(flag = "") {
561
+ return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
881
562
  try {
882
- const [value, adapted] = Schema.resolve(data[key], schema, {
883
- ...options,
884
- path: [...options.path || [], key]
885
- });
886
- if (adapted !== void 0) data[key] = adapted;
887
- return value;
563
+ return new RegExp(value, flag);
888
564
  } catch (e) {
889
- if (!options?.autofix) throw e;
890
- delete data[key];
891
- return schema.meta.default;
565
+ throw new ValidationError(e.message, options);
892
566
  }
893
- }
894
- __name(property, "property");
895
- Schema.extend("array", (data, { inner, meta }, options) => {
896
- if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
897
- checkWithinRange(data.length, meta, "array length", options, !(0, import_cosmokit.isNullable)(inner.meta.default));
898
- return [data.map((_, index) => property(data, index, inner, options))];
899
- });
900
- Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
901
- if (!(0, import_cosmokit.isPlainObject)(data)) throw new ValidationError(`expected object but got ${data}`, options);
902
- const result = {};
903
- for (const key in data) {
904
- let rKey;
567
+ }, true)]);
568
+ };
569
+ Schema.arrayBuffer = function arrayBuffer(encoding) {
570
+ return Schema.union([
571
+ Schema.is(ArrayBuffer),
572
+ Schema.is(SharedArrayBuffer),
573
+ Schema.transform(Schema.any(), (value, options) => {
574
+ if (Binary.isSource(value)) return Binary.fromSource(value);
575
+ throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
576
+ }, true),
577
+ ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
905
578
  try {
906
- rKey = Schema.resolve(key, sKey, options)[0];
907
- } catch (error) {
908
- if (strict) continue;
909
- throw error;
579
+ return encoding === "base64" ? Binary.fromBase64(value) : Binary.fromHex(value);
580
+ } catch (e) {
581
+ throw new ValidationError(e.message, options);
910
582
  }
911
- result[rKey] = property(data, key, inner, options);
912
- data[rKey] = data[key];
913
- if (key !== rKey) delete data[key];
914
- }
915
- return [result];
916
- });
917
- Schema.extend("tuple", (data, { list }, options, strict) => {
918
- if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
919
- const result = list.map((inner, index) => property(data, index, inner, options));
920
- if (strict) return [result];
921
- result.push(...data.slice(list.length));
922
- return [result];
923
- });
924
- function merge(result, data) {
925
- for (const key in data) {
926
- if (key in result) continue;
927
- result[key] = data[key];
928
- }
583
+ }, true)] : []
584
+ ]);
585
+ };
586
+ Schema.extend("lazy", (data, schema, options, strict) => {
587
+ if (!schema.inner[kSchema]) {
588
+ schema.inner = schema.builder();
589
+ schema.inner.meta = {
590
+ ...schema.meta,
591
+ ...schema.inner.meta
592
+ };
929
593
  }
930
- __name(merge, "merge");
931
- Schema.extend("object", (data, { dict }, options, strict) => {
932
- if (!(0, import_cosmokit.isPlainObject)(data)) throw new ValidationError(`expected object but got ${data}`, options);
933
- const result = {};
934
- for (const key in dict) {
935
- const value = property(data, key, dict[key], options);
936
- if (!(0, import_cosmokit.isNullable)(value) || key in data) result[key] = value;
594
+ return Schema.resolve(data, schema.inner, options, strict);
595
+ });
596
+ Schema.extend("any", (data) => {
597
+ return [data];
598
+ });
599
+ Schema.extend("never", (data, _, options) => {
600
+ throw new ValidationError(`expected nullable but got ${data}`, options);
601
+ });
602
+ Schema.extend("const", (data, { value }, options) => {
603
+ if (deepEqual(data, value)) return [value];
604
+ throw new ValidationError(`expected ${value} but got ${data}`, options);
605
+ });
606
+ function checkWithinRange(data, meta, description, options, skipMin = false) {
607
+ const { max = Infinity, min = -Infinity } = meta;
608
+ if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
609
+ if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
610
+ }
611
+ Schema.extend("string", (data, { meta }, options) => {
612
+ if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
613
+ if (meta.pattern) {
614
+ const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
615
+ if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
616
+ }
617
+ checkWithinRange(data.length, meta, "string length", options);
618
+ return [data];
619
+ });
620
+ function decimalShift(data, digits) {
621
+ const str = data.toString();
622
+ if (str.includes("e")) return data * Math.pow(10, digits);
623
+ const index = str.indexOf(".");
624
+ if (index === -1) return data * Math.pow(10, digits);
625
+ const frac = str.slice(index + 1);
626
+ const integer = str.slice(0, index);
627
+ if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
628
+ return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
629
+ }
630
+ function isMultipleOf(data, min, step) {
631
+ step = Math.abs(step);
632
+ if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
633
+ const index = step.toString().indexOf(".");
634
+ const digits = step.toString().slice(index + 1).length;
635
+ return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
636
+ }
637
+ Schema.extend("number", (data, { meta }, options) => {
638
+ if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
639
+ checkWithinRange(data, meta, "number", options);
640
+ const { step } = meta;
641
+ if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
642
+ return [data];
643
+ });
644
+ Schema.extend("boolean", (data, _, options) => {
645
+ if (typeof data === "boolean") return [data];
646
+ throw new ValidationError(`expected boolean but got ${data}`, options);
647
+ });
648
+ Schema.extend("bitset", (data, { bits, meta }, options) => {
649
+ let value = 0, keys = [];
650
+ if (typeof data === "number") {
651
+ value = data;
652
+ for (const key in bits) if (data & bits[key]) keys.push(key);
653
+ } else if (Array.isArray(data)) {
654
+ keys = data;
655
+ for (const key of keys) {
656
+ if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
657
+ if (key in bits) value |= bits[key];
658
+ }
659
+ } else throw new ValidationError(`expected number or array but got ${data}`, options);
660
+ if (value === meta.default) return [value];
661
+ return [value, keys];
662
+ });
663
+ Schema.extend("function", (data, _, options) => {
664
+ if (typeof data === "function") return [data];
665
+ throw new ValidationError(`expected function but got ${data}`, options);
666
+ });
667
+ Schema.extend("is", (data, { constructor }, options) => {
668
+ if (typeof constructor === "function") {
669
+ if (data instanceof constructor) return [data];
670
+ throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
671
+ } else {
672
+ if (isNullable(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
673
+ let prototype = Object.getPrototypeOf(data);
674
+ while (prototype) {
675
+ if (prototype.constructor?.name === constructor) return [data];
676
+ prototype = Object.getPrototypeOf(prototype);
937
677
  }
938
- if (!strict) merge(result, data);
939
- return [result];
940
- });
941
- Schema.extend("union", (data, { list, toString: toString2 }, options, strict) => {
942
- const messages = [];
943
- for (const inner of list) try {
944
- return Schema.resolve(data, inner, options, strict);
678
+ throw new ValidationError(`expected ${constructor} but got ${data}`, options);
679
+ }
680
+ });
681
+ function property(data, key, schema, options) {
682
+ try {
683
+ const [value, adapted] = Schema.resolve(data[key], schema, {
684
+ ...options,
685
+ path: [...options.path || [], key]
686
+ });
687
+ if (adapted !== void 0) data[key] = adapted;
688
+ return value;
689
+ } catch (e) {
690
+ if (!options?.autofix) throw e;
691
+ delete data[key];
692
+ return schema.meta.default;
693
+ }
694
+ }
695
+ Schema.extend("array", (data, { inner, meta }, options) => {
696
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
697
+ checkWithinRange(data.length, meta, "array length", options, !isNullable(inner.meta.default));
698
+ return [data.map((_, index) => property(data, index, inner, options))];
699
+ });
700
+ Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
701
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
702
+ const result = {};
703
+ for (const key in data) {
704
+ let rKey;
705
+ try {
706
+ rKey = Schema.resolve(key, sKey, options)[0];
945
707
  } catch (error) {
946
- messages.push(error);
708
+ if (strict) continue;
709
+ throw error;
947
710
  }
948
- throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
949
- });
950
- Schema.extend("intersect", (data, { list, toString: toString2 }, options, strict) => {
951
- if (!list.length) return [data];
952
- let result;
953
- for (const inner of list) {
954
- const value = Schema.resolve(data, inner, options, true)[0];
955
- if ((0, import_cosmokit.isNullable)(value)) continue;
956
- if ((0, import_cosmokit.isNullable)(result)) result = value;
957
- else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
958
- else if (typeof value === "object") merge(result ??= {}, value);
959
- else if (result !== value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
960
- }
961
- if (!strict && (0, import_cosmokit.isPlainObject)(data)) merge(result, data);
962
- return [result];
963
- });
964
- Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
965
- const [result, adapted = data] = Schema.resolve(data, inner, options, true);
966
- if (preserve) return [callback(result)];
967
- else return [callback(result), callback(adapted)];
968
- });
969
- var formatters = {};
970
- function defineMethod(name, keys, format) {
971
- formatters[name] = format;
972
- Object.assign(Schema, { [name](...args) {
973
- const schema = new Schema({ type: name });
974
- keys.forEach((key, index) => {
975
- switch (key) {
976
- case "sKey":
977
- schema.sKey = args[index] ?? Schema.string();
978
- break;
979
- case "inner":
980
- schema.inner = Schema.from(args[index]);
981
- break;
982
- case "list":
983
- schema.list = args[index].map(Schema.from);
984
- break;
985
- case "dict":
986
- schema.dict = (0, import_cosmokit.valueMap)(args[index], Schema.from);
987
- break;
988
- case "bits":
989
- schema.bits = {};
990
- for (const key2 in args[index]) {
991
- if (typeof args[index][key2] !== "number") continue;
992
- schema.bits[key2] = args[index][key2];
993
- }
994
- break;
995
- case "callback": {
996
- const callback = schema.callback = args[index];
997
- callback["toJSON"] ||= () => callback.toString();
998
- break;
999
- }
1000
- case "constructor": {
1001
- const constructor = schema.constructor = args[index];
1002
- if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
1003
- break;
711
+ result[rKey] = property(data, key, inner, options);
712
+ data[rKey] = data[key];
713
+ if (key !== rKey) delete data[key];
714
+ }
715
+ return [result];
716
+ });
717
+ Schema.extend("tuple", (data, { list }, options, strict) => {
718
+ if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
719
+ const result = list.map((inner, index) => property(data, index, inner, options));
720
+ if (strict) return [result];
721
+ result.push(...data.slice(list.length));
722
+ return [result];
723
+ });
724
+ function merge(result, data) {
725
+ for (const key in data) {
726
+ if (key in result) continue;
727
+ result[key] = data[key];
728
+ }
729
+ }
730
+ Schema.extend("object", (data, { dict }, options, strict) => {
731
+ if (!isPlainObject(data)) throw new ValidationError(`expected object but got ${data}`, options);
732
+ const result = {};
733
+ for (const key in dict) {
734
+ const value = property(data, key, dict[key], options);
735
+ if (!isNullable(value) || key in data) result[key] = value;
736
+ }
737
+ if (!strict) merge(result, data);
738
+ return [result];
739
+ });
740
+ Schema.extend("union", (data, { list, toString }, options, strict) => {
741
+ const messages = [];
742
+ for (const inner of list) try {
743
+ return Schema.resolve(data, inner, options, strict);
744
+ } catch (error) {
745
+ messages.push(error);
746
+ }
747
+ throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
748
+ });
749
+ Schema.extend("intersect", (data, { list, toString }, options, strict) => {
750
+ if (!list.length) return [data];
751
+ let result;
752
+ for (const inner of list) {
753
+ const value = Schema.resolve(data, inner, options, true)[0];
754
+ if (isNullable(value)) continue;
755
+ if (isNullable(result)) result = value;
756
+ else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
757
+ else if (typeof value === "object") merge(result ??= {}, value);
758
+ else if (result !== value) throw new ValidationError(`expected ${toString()} but got ${JSON.stringify(data)}`, options);
759
+ }
760
+ if (!strict && isPlainObject(data)) merge(result, data);
761
+ return [result];
762
+ });
763
+ Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
764
+ const [result, adapted = data] = Schema.resolve(data, inner, options, true);
765
+ if (preserve) return [callback(result)];
766
+ else return [callback(result), callback(adapted)];
767
+ });
768
+ const formatters = {};
769
+ function defineMethod(name, keys, format) {
770
+ formatters[name] = format;
771
+ Object.assign(Schema, { [name](...args) {
772
+ const schema = new Schema({ type: name });
773
+ keys.forEach((key, index) => {
774
+ switch (key) {
775
+ case "sKey":
776
+ schema.sKey = args[index] ?? Schema.string();
777
+ break;
778
+ case "inner":
779
+ schema.inner = Schema.from(args[index]);
780
+ break;
781
+ case "list":
782
+ schema.list = args[index].map(Schema.from);
783
+ break;
784
+ case "dict":
785
+ schema.dict = mapValues(args[index], Schema.from);
786
+ break;
787
+ case "bits":
788
+ schema.bits = {};
789
+ for (const key in args[index]) {
790
+ if (typeof args[index][key] !== "number") continue;
791
+ schema.bits[key] = args[index][key];
1004
792
  }
1005
- default: schema[key] = args[index];
793
+ break;
794
+ case "callback": {
795
+ const callback = schema.callback = args[index];
796
+ callback["toJSON"] ||= () => callback.toString();
797
+ break;
1006
798
  }
1007
- });
1008
- if (name === "object" || name === "dict") schema.meta.default = {};
1009
- else if (name === "array" || name === "tuple") schema.meta.default = [];
1010
- else if (name === "bitset") schema.meta.default = 0;
1011
- return schema;
1012
- } });
1013
- }
1014
- __name(defineMethod, "defineMethod");
1015
- defineMethod("is", ["constructor"], ({ constructor }) => {
1016
- if (typeof constructor === "function") return constructor.name;
1017
- else return constructor;
1018
- });
1019
- defineMethod("any", [], () => "any");
1020
- defineMethod("never", [], () => "never");
1021
- defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
1022
- defineMethod("string", [], () => "string");
1023
- defineMethod("number", [], () => "number");
1024
- defineMethod("boolean", [], () => "boolean");
1025
- defineMethod("bitset", ["bits"], () => "bitset");
1026
- defineMethod("function", [], () => "function");
1027
- defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
1028
- defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
1029
- defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
1030
- defineMethod("object", ["dict"], ({ dict }) => {
1031
- if (Object.keys(dict).length === 0) return "{}";
1032
- return `{ ${Object.entries(dict).map(([key, inner]) => {
1033
- return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
1034
- }).join(", ")} }`;
1035
- });
1036
- defineMethod("union", ["list"], ({ list }, inline) => {
1037
- const result = list.map(({ toString: format }) => format()).join(" | ");
1038
- return inline ? `(${result})` : result;
1039
- });
1040
- defineMethod("intersect", ["list"], ({ list }) => {
1041
- return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
1042
- });
1043
- defineMethod("transform", [
1044
- "inner",
1045
- "callback",
1046
- "preserve"
1047
- ], ({ inner }, isInner) => inner.toString(isInner));
1048
- module.exports = Schema;
1049
- })))(), 1);
1050
- const MailSettingsSchema = import_lib.default.object({
1051
- readEnabled: import_lib.default.boolean().default(DEFAULTS.readEnabled),
1052
- sendEnabled: import_lib.default.boolean().default(DEFAULTS.sendEnabled),
1053
- email: import_lib.default.string().default(DEFAULTS.email),
1054
- username: import_lib.default.string().default(DEFAULTS.username),
1055
- fromName: import_lib.default.string().default(DEFAULTS.fromName),
1056
- inboxFolder: import_lib.default.string().default(DEFAULTS.inboxFolder),
1057
- imapHost: import_lib.default.string().default(DEFAULTS.imapHost),
1058
- imapPort: import_lib.default.number().default(DEFAULTS.imapPort),
1059
- imapTls: import_lib.default.union(["implicit", "starttls"]).default(DEFAULTS.imapTls),
1060
- smtpHost: import_lib.default.string().default(DEFAULTS.smtpHost),
1061
- smtpPort: import_lib.default.number().default(DEFAULTS.smtpPort),
1062
- smtpTls: import_lib.default.union(["implicit", "starttls"]).default(DEFAULTS.smtpTls),
1063
- maxBodyChars: import_lib.default.number().default(DEFAULTS.maxBodyChars),
1064
- maxMessageBytes: import_lib.default.number().default(DEFAULTS.maxMessageBytes),
1065
- maxAttachmentBytes: import_lib.default.number().default(DEFAULTS.maxAttachmentBytes)
799
+ case "constructor": {
800
+ const constructor = schema.constructor = args[index];
801
+ if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
802
+ break;
803
+ }
804
+ default: schema[key] = args[index];
805
+ }
806
+ });
807
+ if (name === "object" || name === "dict") schema.meta.default = {};
808
+ else if (name === "array" || name === "tuple") schema.meta.default = [];
809
+ else if (name === "bitset") schema.meta.default = 0;
810
+ return schema;
811
+ } });
812
+ }
813
+ defineMethod("is", ["constructor"], ({ constructor }) => {
814
+ if (typeof constructor === "function") return constructor.name;
815
+ else return constructor;
816
+ });
817
+ defineMethod("any", [], () => "any");
818
+ defineMethod("never", [], () => "never");
819
+ defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
820
+ defineMethod("string", [], () => "string");
821
+ defineMethod("number", [], () => "number");
822
+ defineMethod("boolean", [], () => "boolean");
823
+ defineMethod("bitset", ["bits"], () => "bitset");
824
+ defineMethod("function", [], () => "function");
825
+ defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
826
+ defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
827
+ defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
828
+ defineMethod("object", ["dict"], ({ dict }) => {
829
+ if (Object.keys(dict).length === 0) return "{}";
830
+ return `{ ${Object.entries(dict).map(([key, inner]) => {
831
+ return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
832
+ }).join(", ")} }`;
833
+ });
834
+ defineMethod("union", ["list"], ({ list }, inline) => {
835
+ const result = list.map(({ toString: format }) => format()).join(" | ");
836
+ return inline ? `(${result})` : result;
837
+ });
838
+ defineMethod("intersect", ["list"], ({ list }) => {
839
+ return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
840
+ });
841
+ defineMethod("transform", [
842
+ "inner",
843
+ "callback",
844
+ "preserve"
845
+ ], ({ inner }, isInner) => inner.toString(isInner));
846
+ //#endregion
847
+ //#region src/host/config.js
848
+ const MailSettingsSchema = Schema.object({
849
+ readEnabled: Schema.boolean().default(DEFAULTS.readEnabled),
850
+ sendEnabled: Schema.boolean().default(DEFAULTS.sendEnabled),
851
+ email: Schema.string().default(DEFAULTS.email),
852
+ username: Schema.string().default(DEFAULTS.username),
853
+ fromName: Schema.string().default(DEFAULTS.fromName),
854
+ inboxFolder: Schema.string().default(DEFAULTS.inboxFolder),
855
+ imapHost: Schema.string().default(DEFAULTS.imapHost),
856
+ imapPort: Schema.number().default(DEFAULTS.imapPort),
857
+ imapTls: Schema.union(["implicit", "starttls"]).default(DEFAULTS.imapTls),
858
+ smtpHost: Schema.string().default(DEFAULTS.smtpHost),
859
+ smtpPort: Schema.number().default(DEFAULTS.smtpPort),
860
+ smtpTls: Schema.union(["implicit", "starttls"]).default(DEFAULTS.smtpTls),
861
+ maxBodyChars: Schema.number().default(DEFAULTS.maxBodyChars),
862
+ maxMessageBytes: Schema.number().default(DEFAULTS.maxMessageBytes),
863
+ maxAttachmentBytes: Schema.number().default(DEFAULTS.maxAttachmentBytes)
1066
864
  });
1067
865
  function settingsBase(config = {}) {
1068
866
  const base = { ...DEFAULTS };