From f9e795519a98335c5a959cb97ba1349778589f14 Mon Sep 17 00:00:00 2001 From: Wendelin Peleska Date: Mon, 29 Apr 2024 15:27:07 +0200 Subject: [PATCH] add dist to webserver --- homedocs/webserver/.gitignore | 3 +- homedocs/webserver/dist/index.js | 18089 +++++++++++++++++++ homedocs/webserver/dist/templates/404.html | 37 + 3 files changed, 18127 insertions(+), 2 deletions(-) create mode 100644 homedocs/webserver/dist/index.js create mode 100644 homedocs/webserver/dist/templates/404.html diff --git a/homedocs/webserver/.gitignore b/homedocs/webserver/.gitignore index c0fb069..f3b9f9a 100644 --- a/homedocs/webserver/.gitignore +++ b/homedocs/webserver/.gitignore @@ -41,5 +41,4 @@ yarn-error.log* package-lock.json **/*.bun -public -dist \ No newline at end of file +public \ No newline at end of file diff --git a/homedocs/webserver/dist/index.js b/homedocs/webserver/dist/index.js new file mode 100644 index 0000000..85e8055 --- /dev/null +++ b/homedocs/webserver/dist/index.js @@ -0,0 +1,18089 @@ +// @bun +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getProtoOf = Object.getPrototypeOf; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __toESM = (mod, isNodeMode, target) => { + target = mod != null ? __create(__getProtoOf(mod)) : {}; + const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target; + for (let key of __getOwnPropNames(mod)) + if (!__hasOwnProp.call(to, key)) + __defProp(to, key, { + get: () => mod[key], + enumerable: true + }); + return to; +}; +var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports); +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { + get: all[name], + enumerable: true, + configurable: true, + set: (newValue) => all[name] = () => newValue + }); +}; + +// node_modules/eventemitter3/index.js +var require_eventemitter3 = __commonJS((exports, module) => { + var Events = function() { + }; + var EE = function(fn, context, once) { + this.fn = fn; + this.context = context; + this.once = once || false; + }; + var addListener = function(emitter, event, fn, context, once) { + if (typeof fn !== "function") { + throw new TypeError("The listener must be a function"); + } + var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event; + if (!emitter._events[evt]) + emitter._events[evt] = listener, emitter._eventsCount++; + else if (!emitter._events[evt].fn) + emitter._events[evt].push(listener); + else + emitter._events[evt] = [emitter._events[evt], listener]; + return emitter; + }; + var clearEvent = function(emitter, evt) { + if (--emitter._eventsCount === 0) + emitter._events = new Events; + else + delete emitter._events[evt]; + }; + var EventEmitter = function() { + this._events = new Events; + this._eventsCount = 0; + }; + var has = Object.prototype.hasOwnProperty; + var prefix = "~"; + if (Object.create) { + Events.prototype = Object.create(null); + if (!new Events().__proto__) + prefix = false; + } + EventEmitter.prototype.eventNames = function eventNames() { + var names = [], events, name; + if (this._eventsCount === 0) + return names; + for (name in events = this._events) { + if (has.call(events, name)) + names.push(prefix ? name.slice(1) : name); + } + if (Object.getOwnPropertySymbols) { + return names.concat(Object.getOwnPropertySymbols(events)); + } + return names; + }; + EventEmitter.prototype.listeners = function listeners(event) { + var evt = prefix ? prefix + event : event, handlers = this._events[evt]; + if (!handlers) + return []; + if (handlers.fn) + return [handlers.fn]; + for (var i = 0, l = handlers.length, ee = new Array(l);i < l; i++) { + ee[i] = handlers[i].fn; + } + return ee; + }; + EventEmitter.prototype.listenerCount = function listenerCount(event) { + var evt = prefix ? prefix + event : event, listeners = this._events[evt]; + if (!listeners) + return 0; + if (listeners.fn) + return 1; + return listeners.length; + }; + EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { + var evt = prefix ? prefix + event : event; + if (!this._events[evt]) + return false; + var listeners = this._events[evt], len = arguments.length, args, i; + if (listeners.fn) { + if (listeners.once) + this.removeListener(event, listeners.fn, undefined, true); + switch (len) { + case 1: + return listeners.fn.call(listeners.context), true; + case 2: + return listeners.fn.call(listeners.context, a1), true; + case 3: + return listeners.fn.call(listeners.context, a1, a2), true; + case 4: + return listeners.fn.call(listeners.context, a1, a2, a3), true; + case 5: + return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; + case 6: + return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; + } + for (i = 1, args = new Array(len - 1);i < len; i++) { + args[i - 1] = arguments[i]; + } + listeners.fn.apply(listeners.context, args); + } else { + var length = listeners.length, j; + for (i = 0;i < length; i++) { + if (listeners[i].once) + this.removeListener(event, listeners[i].fn, undefined, true); + switch (len) { + case 1: + listeners[i].fn.call(listeners[i].context); + break; + case 2: + listeners[i].fn.call(listeners[i].context, a1); + break; + case 3: + listeners[i].fn.call(listeners[i].context, a1, a2); + break; + case 4: + listeners[i].fn.call(listeners[i].context, a1, a2, a3); + break; + default: + if (!args) + for (j = 1, args = new Array(len - 1);j < len; j++) { + args[j - 1] = arguments[j]; + } + listeners[i].fn.apply(listeners[i].context, args); + } + } + } + return true; + }; + EventEmitter.prototype.on = function on(event, fn, context) { + return addListener(this, event, fn, context, false); + }; + EventEmitter.prototype.once = function once(event, fn, context) { + return addListener(this, event, fn, context, true); + }; + EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) { + var evt = prefix ? prefix + event : event; + if (!this._events[evt]) + return this; + if (!fn) { + clearEvent(this, evt); + return this; + } + var listeners = this._events[evt]; + if (listeners.fn) { + if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) { + clearEvent(this, evt); + } + } else { + for (var i = 0, events = [], length = listeners.length;i < length; i++) { + if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) { + events.push(listeners[i]); + } + } + if (events.length) + this._events[evt] = events.length === 1 ? events[0] : events; + else + clearEvent(this, evt); + } + return this; + }; + EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) { + var evt; + if (event) { + evt = prefix ? prefix + event : event; + if (this._events[evt]) + clearEvent(this, evt); + } else { + this._events = new Events; + this._eventsCount = 0; + } + return this; + }; + EventEmitter.prototype.off = EventEmitter.prototype.removeListener; + EventEmitter.prototype.addListener = EventEmitter.prototype.on; + EventEmitter.prefixed = prefix; + EventEmitter.EventEmitter = EventEmitter; + if (typeof module !== "undefined") { + module.exports = EventEmitter; + } +}); + +// node_modules/fast-decode-uri-component/index.js +var require_fast_decode_uri_component = __commonJS((exports, module) => { + var decodeURIComponent2 = function(uri) { + var percentPosition = uri.indexOf("%"); + if (percentPosition === -1) + return uri; + var length = uri.length; + var decoded = ""; + var last = 0; + var codepoint = 0; + var startOfOctets = percentPosition; + var state = UTF8_ACCEPT; + while (percentPosition > -1 && percentPosition < length) { + var high = hexCodeToInt(uri[percentPosition + 1], 4); + var low = hexCodeToInt(uri[percentPosition + 2], 0); + var byte = high | low; + var type74 = UTF8_DATA[byte]; + state = UTF8_DATA[256 + state + type74]; + codepoint = codepoint << 6 | byte & UTF8_DATA[364 + type74]; + if (state === UTF8_ACCEPT) { + decoded += uri.slice(last, startOfOctets); + decoded += codepoint <= 65535 ? String.fromCharCode(codepoint) : String.fromCharCode(55232 + (codepoint >> 10), 56320 + (codepoint & 1023)); + codepoint = 0; + last = percentPosition + 3; + percentPosition = startOfOctets = uri.indexOf("%", last); + } else if (state === UTF8_REJECT) { + return null; + } else { + percentPosition += 3; + if (percentPosition < length && uri.charCodeAt(percentPosition) === 37) + continue; + return null; + } + } + return decoded + uri.slice(last); + }; + var hexCodeToInt = function(c, shift) { + var i = HEX[c]; + return i === undefined ? 255 : i << shift; + }; + var UTF8_ACCEPT = 12; + var UTF8_REJECT = 0; + var UTF8_DATA = [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 3, + 4, + 4, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 6, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 7, + 8, + 7, + 7, + 10, + 9, + 9, + 9, + 11, + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 4, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 12, + 0, + 0, + 0, + 0, + 24, + 36, + 48, + 60, + 72, + 84, + 96, + 0, + 12, + 12, + 12, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 24, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 24, + 24, + 24, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 24, + 24, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 48, + 48, + 48, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 48, + 48, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 48, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 127, + 63, + 63, + 63, + 0, + 31, + 15, + 15, + 15, + 7, + 7, + 7 + ]; + var HEX = { + "0": 0, + "1": 1, + "2": 2, + "3": 3, + "4": 4, + "5": 5, + "6": 6, + "7": 7, + "8": 8, + "9": 9, + a: 10, + A: 10, + b: 11, + B: 11, + c: 12, + C: 12, + d: 13, + D: 13, + e: 14, + E: 14, + f: 15, + F: 15 + }; + module.exports = decodeURIComponent2; +}); + +// node_modules/fast-querystring/lib/parse.js +var require_parse = __commonJS((exports, module) => { + var parse5 = function(input) { + const result = new Empty; + if (typeof input !== "string") { + return result; + } + let inputLength = input.length; + let key = ""; + let value11 = ""; + let startingIndex = -1; + let equalityIndex = -1; + let shouldDecodeKey = false; + let shouldDecodeValue = false; + let keyHasPlus = false; + let valueHasPlus = false; + let hasBothKeyValuePair = false; + let c = 0; + for (let i = 0;i < inputLength + 1; i++) { + c = i !== inputLength ? input.charCodeAt(i) : 38; + if (c === 38) { + hasBothKeyValuePair = equalityIndex > startingIndex; + if (!hasBothKeyValuePair) { + equalityIndex = i; + } + key = input.slice(startingIndex + 1, equalityIndex); + if (hasBothKeyValuePair || key.length > 0) { + if (keyHasPlus) { + key = key.replace(plusRegex, " "); + } + if (shouldDecodeKey) { + key = fastDecode(key) || key; + } + if (hasBothKeyValuePair) { + value11 = input.slice(equalityIndex + 1, i); + if (valueHasPlus) { + value11 = value11.replace(plusRegex, " "); + } + if (shouldDecodeValue) { + value11 = fastDecode(value11) || value11; + } + } + const currentValue = result[key]; + if (currentValue === undefined) { + result[key] = value11; + } else { + if (currentValue.pop) { + currentValue.push(value11); + } else { + result[key] = [currentValue, value11]; + } + } + } + value11 = ""; + startingIndex = i; + equalityIndex = i; + shouldDecodeKey = false; + shouldDecodeValue = false; + keyHasPlus = false; + valueHasPlus = false; + } else if (c === 61) { + if (equalityIndex <= startingIndex) { + equalityIndex = i; + } else { + shouldDecodeValue = true; + } + } else if (c === 43) { + if (equalityIndex > startingIndex) { + valueHasPlus = true; + } else { + keyHasPlus = true; + } + } else if (c === 37) { + if (equalityIndex > startingIndex) { + shouldDecodeValue = true; + } else { + shouldDecodeKey = true; + } + } + } + return result; + }; + var fastDecode = require_fast_decode_uri_component(); + var plusRegex = /\+/g; + var Empty = function() { + }; + Empty.prototype = Object.create(null); + module.exports = parse5; +}); + +// node_modules/fast-querystring/lib/internals/querystring.js +var require_querystring = __commonJS((exports, module) => { + var encodeString = function(str) { + const len = str.length; + if (len === 0) + return ""; + let out = ""; + let lastPos = 0; + let i = 0; + outer: + for (;i < len; i++) { + let c = str.charCodeAt(i); + while (c < 128) { + if (noEscape[c] !== 1) { + if (lastPos < i) + out += str.slice(lastPos, i); + lastPos = i + 1; + out += hexTable[c]; + } + if (++i === len) + break outer; + c = str.charCodeAt(i); + } + if (lastPos < i) + out += str.slice(lastPos, i); + if (c < 2048) { + lastPos = i + 1; + out += hexTable[192 | c >> 6] + hexTable[128 | c & 63]; + continue; + } + if (c < 55296 || c >= 57344) { + lastPos = i + 1; + out += hexTable[224 | c >> 12] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63]; + continue; + } + ++i; + if (i >= len) { + throw new Error("URI malformed"); + } + const c2 = str.charCodeAt(i) & 1023; + lastPos = i + 1; + c = 65536 + ((c & 1023) << 10 | c2); + out += hexTable[240 | c >> 18] + hexTable[128 | c >> 12 & 63] + hexTable[128 | c >> 6 & 63] + hexTable[128 | c & 63]; + } + if (lastPos === 0) + return str; + if (lastPos < len) + return out + str.slice(lastPos); + return out; + }; + var hexTable = Array.from({ length: 256 }, (_, i) => "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase()); + var noEscape = new Int8Array([ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 0, + 0, + 1, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0, + 1, + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 1, + 0 + ]); + module.exports = { encodeString }; +}); + +// node_modules/fast-querystring/lib/stringify.js +var require_stringify = __commonJS((exports, module) => { + var getAsPrimitive = function(value11) { + const type74 = typeof value11; + if (type74 === "string") { + return encodeString(value11); + } else if (type74 === "bigint") { + return value11.toString(); + } else if (type74 === "boolean") { + return value11 ? "true" : "false"; + } else if (type74 === "number" && Number.isFinite(value11)) { + return value11 < 1000000000000000000000 ? "" + value11 : encodeString("" + value11); + } + return ""; + }; + var stringify = function(input) { + let result = ""; + if (input === null || typeof input !== "object") { + return result; + } + const separator = "&"; + const keys = Object.keys(input); + const keyLength = keys.length; + let valueLength = 0; + for (let i = 0;i < keyLength; i++) { + const key = keys[i]; + const value11 = input[key]; + const encodedKey = encodeString(key) + "="; + if (i) { + result += separator; + } + if (Array.isArray(value11)) { + valueLength = value11.length; + for (let j = 0;j < valueLength; j++) { + if (j) { + result += separator; + } + result += encodedKey; + result += getAsPrimitive(value11[j]); + } + } else { + result += encodedKey; + result += getAsPrimitive(value11); + } + } + return result; + }; + var { encodeString } = require_querystring(); + module.exports = stringify; +}); + +// node_modules/fast-querystring/lib/index.js +var require_lib = __commonJS((exports, module) => { + var parse5 = require_parse(); + var stringify = require_stringify(); + var fastQuerystring = { + parse: parse5, + stringify + }; + module.exports = fastQuerystring; + module.exports.default = fastQuerystring; + module.exports.parse = parse5; + module.exports.stringify = stringify; +}); + +// node_modules/clone/clone.js +var require_clone = __commonJS((exports, module) => { + var clone13 = function() { + function _instanceof(obj, type74) { + return type74 != null && obj instanceof type74; + } + var nativeMap; + try { + nativeMap = Map; + } catch (_) { + nativeMap = function() { + }; + } + var nativeSet; + try { + nativeSet = Set; + } catch (_) { + nativeSet = function() { + }; + } + var nativePromise; + try { + nativePromise = Promise; + } catch (_) { + nativePromise = function() { + }; + } + function clone14(parent, circular, depth, prototype, includeNonEnumerable) { + if (typeof circular === "object") { + depth = circular.depth; + prototype = circular.prototype; + includeNonEnumerable = circular.includeNonEnumerable; + circular = circular.circular; + } + var allParents = []; + var allChildren = []; + var useBuffer = typeof Buffer != "undefined"; + if (typeof circular == "undefined") + circular = true; + if (typeof depth == "undefined") + depth = Infinity; + function _clone(parent2, depth2) { + if (parent2 === null) + return null; + if (depth2 === 0) + return parent2; + var child; + var proto; + if (typeof parent2 != "object") { + return parent2; + } + if (_instanceof(parent2, nativeMap)) { + child = new nativeMap; + } else if (_instanceof(parent2, nativeSet)) { + child = new nativeSet; + } else if (_instanceof(parent2, nativePromise)) { + child = new nativePromise(function(resolve, reject) { + parent2.then(function(value15) { + resolve(_clone(value15, depth2 - 1)); + }, function(err) { + reject(_clone(err, depth2 - 1)); + }); + }); + } else if (clone14.__isArray(parent2)) { + child = []; + } else if (clone14.__isRegExp(parent2)) { + child = new RegExp(parent2.source, __getRegExpFlags(parent2)); + if (parent2.lastIndex) + child.lastIndex = parent2.lastIndex; + } else if (clone14.__isDate(parent2)) { + child = new Date(parent2.getTime()); + } else if (useBuffer && Buffer.isBuffer(parent2)) { + if (Buffer.allocUnsafe) { + child = Buffer.allocUnsafe(parent2.length); + } else { + child = new Buffer(parent2.length); + } + parent2.copy(child); + return child; + } else if (_instanceof(parent2, Error)) { + child = Object.create(parent2); + } else { + if (typeof prototype == "undefined") { + proto = Object.getPrototypeOf(parent2); + child = Object.create(proto); + } else { + child = Object.create(prototype); + proto = prototype; + } + } + if (circular) { + var index = allParents.indexOf(parent2); + if (index != -1) { + return allChildren[index]; + } + allParents.push(parent2); + allChildren.push(child); + } + if (_instanceof(parent2, nativeMap)) { + parent2.forEach(function(value15, key) { + var keyChild = _clone(key, depth2 - 1); + var valueChild = _clone(value15, depth2 - 1); + child.set(keyChild, valueChild); + }); + } + if (_instanceof(parent2, nativeSet)) { + parent2.forEach(function(value15) { + var entryChild = _clone(value15, depth2 - 1); + child.add(entryChild); + }); + } + for (var i in parent2) { + var attrs; + if (proto) { + attrs = Object.getOwnPropertyDescriptor(proto, i); + } + if (attrs && attrs.set == null) { + continue; + } + child[i] = _clone(parent2[i], depth2 - 1); + } + if (Object.getOwnPropertySymbols) { + var symbols68 = Object.getOwnPropertySymbols(parent2); + for (var i = 0;i < symbols68.length; i++) { + var symbol5 = symbols68[i]; + var descriptor = Object.getOwnPropertyDescriptor(parent2, symbol5); + if (descriptor && !descriptor.enumerable && !includeNonEnumerable) { + continue; + } + child[symbol5] = _clone(parent2[symbol5], depth2 - 1); + if (!descriptor.enumerable) { + Object.defineProperty(child, symbol5, { + enumerable: false + }); + } + } + } + if (includeNonEnumerable) { + var allPropertyNames = Object.getOwnPropertyNames(parent2); + for (var i = 0;i < allPropertyNames.length; i++) { + var propertyName = allPropertyNames[i]; + var descriptor = Object.getOwnPropertyDescriptor(parent2, propertyName); + if (descriptor && descriptor.enumerable) { + continue; + } + child[propertyName] = _clone(parent2[propertyName], depth2 - 1); + Object.defineProperty(child, propertyName, { + enumerable: false + }); + } + } + return child; + } + return _clone(parent, depth); + } + clone14.clonePrototype = function clonePrototype(parent) { + if (parent === null) + return null; + var c = function() { + }; + c.prototype = parent; + return new c; + }; + function __objToStr(o) { + return Object.prototype.toString.call(o); + } + clone14.__objToStr = __objToStr; + function __isDate(o) { + return typeof o === "object" && __objToStr(o) === "[object Date]"; + } + clone14.__isDate = __isDate; + function __isArray(o) { + return typeof o === "object" && __objToStr(o) === "[object Array]"; + } + clone14.__isArray = __isArray; + function __isRegExp(o) { + return typeof o === "object" && __objToStr(o) === "[object RegExp]"; + } + clone14.__isRegExp = __isRegExp; + function __getRegExpFlags(re) { + var flags = ""; + if (re.global) + flags += "g"; + if (re.ignoreCase) + flags += "i"; + if (re.multiline) + flags += "m"; + return flags; + } + clone14.__getRegExpFlags = __getRegExpFlags; + return clone14; + }(); + if (typeof module === "object" && exports) { + module.exports = clone13; + } +}); + +// node_modules/node-cache/lib/node_cache.js +var require_node_cache = __commonJS((exports, module) => { + (function() { + var EventEmitter2, NodeCache, clone13, splice = [].splice, boundMethodCheck = function(instance, Constructor2) { + if (!(instance instanceof Constructor2)) { + throw new Error("Bound instance method accessed before binding"); + } + }, indexOf = [].indexOf; + clone13 = require_clone(); + EventEmitter2 = import.meta.require("events").EventEmitter; + module.exports = NodeCache = function() { + + class NodeCache2 extends EventEmitter2 { + constructor(options = {}) { + super(); + this.get = this.get.bind(this); + this.mget = this.mget.bind(this); + this.set = this.set.bind(this); + this.mset = this.mset.bind(this); + this.del = this.del.bind(this); + this.take = this.take.bind(this); + this.ttl = this.ttl.bind(this); + this.getTtl = this.getTtl.bind(this); + this.keys = this.keys.bind(this); + this.has = this.has.bind(this); + this.getStats = this.getStats.bind(this); + this.flushAll = this.flushAll.bind(this); + this.flushStats = this.flushStats.bind(this); + this.close = this.close.bind(this); + this._checkData = this._checkData.bind(this); + this._check = this._check.bind(this); + this._isInvalidKey = this._isInvalidKey.bind(this); + this._wrap = this._wrap.bind(this); + this._getValLength = this._getValLength.bind(this); + this._error = this._error.bind(this); + this._initErrors = this._initErrors.bind(this); + this.options = options; + this._initErrors(); + this.data = {}; + this.options = Object.assign({ + forceString: false, + objectValueSize: 80, + promiseValueSize: 80, + arrayValueSize: 40, + stdTTL: 0, + checkperiod: 600, + useClones: true, + deleteOnExpire: true, + enableLegacyCallbacks: false, + maxKeys: -1 + }, this.options); + if (this.options.enableLegacyCallbacks) { + console.warn("WARNING! node-cache legacy callback support will drop in v6.x"); + ["get", "mget", "set", "del", "ttl", "getTtl", "keys", "has"].forEach((methodKey) => { + var oldMethod; + oldMethod = this[methodKey]; + this[methodKey] = function(...args) { + var cb, err, ref4, res; + ref4 = args, [...args] = ref4, [cb] = splice.call(args, -1); + if (typeof cb === "function") { + try { + res = oldMethod(...args); + cb(null, res); + } catch (error1) { + err = error1; + cb(err); + } + } else { + return oldMethod(...args, cb); + } + }; + }); + } + this.stats = { + hits: 0, + misses: 0, + keys: 0, + ksize: 0, + vsize: 0 + }; + this.validKeyTypes = ["string", "number"]; + this._checkData(); + return; + } + get(key) { + var _ret, err; + boundMethodCheck(this, NodeCache2); + if ((err = this._isInvalidKey(key)) != null) { + throw err; + } + if (this.data[key] != null && this._check(key, this.data[key])) { + this.stats.hits++; + _ret = this._unwrap(this.data[key]); + return _ret; + } else { + this.stats.misses++; + return; + } + } + mget(keys) { + var _err, err, i, key, len, oRet; + boundMethodCheck(this, NodeCache2); + if (!Array.isArray(keys)) { + _err = this._error("EKEYSTYPE"); + throw _err; + } + oRet = {}; + for (i = 0, len = keys.length;i < len; i++) { + key = keys[i]; + if ((err = this._isInvalidKey(key)) != null) { + throw err; + } + if (this.data[key] != null && this._check(key, this.data[key])) { + this.stats.hits++; + oRet[key] = this._unwrap(this.data[key]); + } else { + this.stats.misses++; + } + } + return oRet; + } + set(key, value15, ttl) { + var _err, err, existent; + boundMethodCheck(this, NodeCache2); + if (this.options.maxKeys > -1 && this.stats.keys >= this.options.maxKeys) { + _err = this._error("ECACHEFULL"); + throw _err; + } + if (this.options.forceString && false === "string") { + value15 = JSON.stringify(value15); + } + if (ttl == null) { + ttl = this.options.stdTTL; + } + if ((err = this._isInvalidKey(key)) != null) { + throw err; + } + existent = false; + if (this.data[key]) { + existent = true; + this.stats.vsize -= this._getValLength(this._unwrap(this.data[key], false)); + } + this.data[key] = this._wrap(value15, ttl); + this.stats.vsize += this._getValLength(value15); + if (!existent) { + this.stats.ksize += this._getKeyLength(key); + this.stats.keys++; + } + this.emit("set", key, value15); + return true; + } + mset(keyValueSet) { + var _err, err, i, j, key, keyValuePair, len, len1, ttl, val; + boundMethodCheck(this, NodeCache2); + if (this.options.maxKeys > -1 && this.stats.keys + keyValueSet.length >= this.options.maxKeys) { + _err = this._error("ECACHEFULL"); + throw _err; + } + for (i = 0, len = keyValueSet.length;i < len; i++) { + keyValuePair = keyValueSet[i]; + ({ key, val, ttl } = keyValuePair); + if (ttl && typeof ttl !== "number") { + _err = this._error("ETTLTYPE"); + throw _err; + } + if ((err = this._isInvalidKey(key)) != null) { + throw err; + } + } + for (j = 0, len1 = keyValueSet.length;j < len1; j++) { + keyValuePair = keyValueSet[j]; + ({ key, val, ttl } = keyValuePair); + this.set(key, val, ttl); + } + return true; + } + del(keys) { + var delCount, err, i, key, len, oldVal; + boundMethodCheck(this, NodeCache2); + if (!Array.isArray(keys)) { + keys = [keys]; + } + delCount = 0; + for (i = 0, len = keys.length;i < len; i++) { + key = keys[i]; + if ((err = this._isInvalidKey(key)) != null) { + throw err; + } + if (this.data[key] != null) { + this.stats.vsize -= this._getValLength(this._unwrap(this.data[key], false)); + this.stats.ksize -= this._getKeyLength(key); + this.stats.keys--; + delCount++; + oldVal = this.data[key]; + delete this.data[key]; + this.emit("del", key, oldVal.v); + } + } + return delCount; + } + take(key) { + var _ret; + boundMethodCheck(this, NodeCache2); + _ret = this.get(key); + if (_ret != null) { + this.del(key); + } + return _ret; + } + ttl(key, ttl) { + var err; + boundMethodCheck(this, NodeCache2); + ttl || (ttl = this.options.stdTTL); + if (!key) { + return false; + } + if ((err = this._isInvalidKey(key)) != null) { + throw err; + } + if (this.data[key] != null && this._check(key, this.data[key])) { + if (ttl >= 0) { + this.data[key] = this._wrap(this.data[key].v, ttl, false); + } else { + this.del(key); + } + return true; + } else { + return false; + } + } + getTtl(key) { + var _ttl, err; + boundMethodCheck(this, NodeCache2); + if (!key) { + return; + } + if ((err = this._isInvalidKey(key)) != null) { + throw err; + } + if (this.data[key] != null && this._check(key, this.data[key])) { + _ttl = this.data[key].t; + return _ttl; + } else { + return; + } + } + keys() { + var _keys; + boundMethodCheck(this, NodeCache2); + _keys = Object.keys(this.data); + return _keys; + } + has(key) { + var _exists; + boundMethodCheck(this, NodeCache2); + _exists = this.data[key] != null && this._check(key, this.data[key]); + return _exists; + } + getStats() { + boundMethodCheck(this, NodeCache2); + return this.stats; + } + flushAll(_startPeriod = true) { + boundMethodCheck(this, NodeCache2); + this.data = {}; + this.stats = { + hits: 0, + misses: 0, + keys: 0, + ksize: 0, + vsize: 0 + }; + this._killCheckPeriod(); + this._checkData(_startPeriod); + this.emit("flush"); + } + flushStats() { + boundMethodCheck(this, NodeCache2); + this.stats = { + hits: 0, + misses: 0, + keys: 0, + ksize: 0, + vsize: 0 + }; + this.emit("flush_stats"); + } + close() { + boundMethodCheck(this, NodeCache2); + this._killCheckPeriod(); + } + _checkData(startPeriod = true) { + var key, ref4, value15; + boundMethodCheck(this, NodeCache2); + ref4 = this.data; + for (key in ref4) { + value15 = ref4[key]; + this._check(key, value15); + } + if (startPeriod && this.options.checkperiod > 0) { + this.checkTimeout = setTimeout(this._checkData, this.options.checkperiod * 1000, startPeriod); + if (this.checkTimeout != null && this.checkTimeout.unref != null) { + this.checkTimeout.unref(); + } + } + } + _killCheckPeriod() { + if (this.checkTimeout != null) { + return clearTimeout(this.checkTimeout); + } + } + _check(key, data) { + var _retval; + boundMethodCheck(this, NodeCache2); + _retval = true; + if (data.t !== 0 && data.t < Date.now()) { + if (this.options.deleteOnExpire) { + _retval = false; + this.del(key); + } + this.emit("expired", key, this._unwrap(data)); + } + return _retval; + } + _isInvalidKey(key) { + var ref4; + boundMethodCheck(this, NodeCache2); + if (ref4 = typeof key, indexOf.call(this.validKeyTypes, ref4) < 0) { + return this._error("EKEYTYPE", { + type: typeof key + }); + } + } + _wrap(value15, ttl, asClone = true) { + var livetime, now, oReturn, ttlMultiplicator; + boundMethodCheck(this, NodeCache2); + if (!this.options.useClones) { + asClone = false; + } + now = Date.now(); + livetime = 0; + ttlMultiplicator = 1000; + if (ttl === 0) { + livetime = 0; + } else if (ttl) { + livetime = now + ttl * ttlMultiplicator; + } else { + if (this.options.stdTTL === 0) { + livetime = this.options.stdTTL; + } else { + livetime = now + this.options.stdTTL * ttlMultiplicator; + } + } + return oReturn = { + t: livetime, + v: asClone ? clone13(value15) : value15 + }; + } + _unwrap(value15, asClone = true) { + if (!this.options.useClones) { + asClone = false; + } + if (value15.v != null) { + if (asClone) { + return clone13(value15.v); + } else { + return value15.v; + } + } + return null; + } + _getKeyLength(key) { + return key.toString().length; + } + _getValLength(value15) { + boundMethodCheck(this, NodeCache2); + if (typeof value15 === "string") { + return value15.length; + } else if (this.options.forceString) { + return JSON.stringify(value15).length; + } else if (Array.isArray(value15)) { + return this.options.arrayValueSize * value15.length; + } else if (typeof value15 === "number") { + return 8; + } else if (typeof (value15 != null ? value15.then : undefined) === "function") { + return this.options.promiseValueSize; + } else if (typeof Buffer !== "undefined" && Buffer !== null ? Buffer.isBuffer(value15) : undefined) { + return value15.length; + } else if (value15 != null && typeof value15 === "object") { + return this.options.objectValueSize * Object.keys(value15).length; + } else if (typeof value15 === "boolean") { + return 8; + } else { + return 0; + } + } + _error(type74, data = {}) { + var error23; + boundMethodCheck(this, NodeCache2); + error23 = new Error; + error23.name = type74; + error23.errorcode = type74; + error23.message = this.ERRORS[type74] != null ? this.ERRORS[type74](data) : "-"; + error23.data = data; + return error23; + } + _initErrors() { + var _errMsg, _errT, ref4; + boundMethodCheck(this, NodeCache2); + this.ERRORS = {}; + ref4 = this._ERRORS; + for (_errT in ref4) { + _errMsg = ref4[_errT]; + this.ERRORS[_errT] = this.createErrorMessage(_errMsg); + } + } + createErrorMessage(errMsg) { + return function(args) { + return errMsg.replace("__key", args.type); + }; + } + } + NodeCache2.prototype._ERRORS = { + ENOTFOUND: "Key `__key` not found", + ECACHEFULL: "Cache max keys amount exceeded", + EKEYTYPE: "The key argument has to be of type `string` or `number`. Found: `__key`", + EKEYSTYPE: "The keys argument has to be an array.", + ETTLTYPE: "The ttl argument has to be a number." + }; + return NodeCache2; + }.call(this); + }).call(exports); +}); + +// node_modules/node-cache/index.js +var require_node_cache2 = __commonJS((exports, module) => { + (function() { + var exports2; + exports2 = module.exports = require_node_cache(); + exports2.version = "5.1.2"; + }).call(exports); +}); + +// src/build.ts +var {$ } = globalThis.Bun; +var buildRunning = false; +var buildQueued = false; +var triggerBuild = () => { + if (!buildRunning) { + buildDocs(); + } else { + buildQueued = true; + } +}; +var buildDocs = async () => { + buildRunning = true; + console.time("\uD83D\uDE80 build runtime"); + try { + console.log("\uD83D\uDE80 build started"); + await $`cd ../starlight && bun run build`.quiet(); + console.log("\uD83D\uDE80 build finished"); + await $`rm -rf ./public`; + await $`cp -r ../starlight/dist ./public`; + console.log("\uD83D\uDE80 copied build to public folder"); + } catch (error) { + console.log("\uD83D\uDEAB Build failed"); + try { + const shellError = error; + const output = shellError.stderr.toJSON(); + console.error(output); + } catch (error2) { + console.error("Failed to parse shell error"); + console.error(error2); + } + } + console.timeEnd("\uD83D\uDE80 build runtime"); + if (buildQueued) { + buildQueued = false; + buildDocs(); + } else { + buildRunning = false; + } +}; + +// node_modules/eventemitter3/index.mjs +var import_ = __toESM(require_eventemitter3(), 1); +var eventemitter3_default = import_.default; + +// node_modules/@sinclair/typebox/build/import/value/guard/guard.mjs +function IsAsyncIterator(value) { + return IsObject(value) && Symbol.asyncIterator in value; +} +function IsIterator(value) { + return IsObject(value) && Symbol.iterator in value; +} +function IsStandardObject(value) { + return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name === "Object"; +} +function IsPromise(value) { + return value instanceof Promise; +} +function IsDate(value) { + return value instanceof Date && Number.isFinite(value.getTime()); +} +function IsTypedArray(value) { + return ArrayBuffer.isView(value); +} +function IsUint8Array(value) { + return value instanceof globalThis.Uint8Array; +} +function HasPropertyKey(value, key) { + return key in value; +} +function IsObject(value) { + return value !== null && typeof value === "object"; +} +function IsArray(value) { + return Array.isArray(value) && !ArrayBuffer.isView(value); +} +function IsUndefined(value) { + return value === undefined; +} +function IsNull(value) { + return value === null; +} +function IsBoolean(value) { + return typeof value === "boolean"; +} +function IsNumber(value) { + return typeof value === "number"; +} +function IsInteger(value) { + return IsNumber(value) && Number.isInteger(value); +} +function IsBigInt(value) { + return typeof value === "bigint"; +} +function IsString(value) { + return typeof value === "string"; +} +function IsFunction(value) { + return typeof value === "function"; +} +function IsSymbol(value) { + return typeof value === "symbol"; +} +function IsValueType(value) { + return IsBigInt(value) || IsBoolean(value) || IsNull(value) || IsNumber(value) || IsString(value) || IsSymbol(value) || IsUndefined(value); +} +// node_modules/@sinclair/typebox/build/import/system/policy.mjs +var TypeSystemPolicy; +(function(TypeSystemPolicy2) { + TypeSystemPolicy2.ExactOptionalPropertyTypes = false; + TypeSystemPolicy2.AllowArrayObject = false; + TypeSystemPolicy2.AllowNaN = false; + TypeSystemPolicy2.AllowNullVoid = false; + function IsExactOptionalProperty(value, key) { + return TypeSystemPolicy2.ExactOptionalPropertyTypes ? key in value : value[key] !== undefined; + } + TypeSystemPolicy2.IsExactOptionalProperty = IsExactOptionalProperty; + function IsObjectLike(value) { + const isObject = IsObject(value); + return TypeSystemPolicy2.AllowArrayObject ? isObject : isObject && !IsArray(value); + } + TypeSystemPolicy2.IsObjectLike = IsObjectLike; + function IsRecordLike(value) { + return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array); + } + TypeSystemPolicy2.IsRecordLike = IsRecordLike; + function IsNumberLike(value) { + const isNumber = IsNumber(value); + return TypeSystemPolicy2.AllowNaN ? isNumber : isNumber && Number.isFinite(value); + } + TypeSystemPolicy2.IsNumberLike = IsNumberLike; + function IsVoidLike(value) { + const isUndefined = IsUndefined(value); + return TypeSystemPolicy2.AllowNullVoid ? isUndefined || value === null : isUndefined; + } + TypeSystemPolicy2.IsVoidLike = IsVoidLike; +})(TypeSystemPolicy || (TypeSystemPolicy = {})); +// node_modules/@sinclair/typebox/build/import/type/registry/format.mjs +var exports_format = {}; +__export(exports_format, { + Set: () => { + { + return Set2; + } + }, + Has: () => { + { + return Has; + } + }, + Get: () => { + { + return Get; + } + }, + Entries: () => { + { + return Entries; + } + }, + Delete: () => { + { + return Delete; + } + }, + Clear: () => { + { + return Clear; + } + } +}); +function Entries() { + return new Map(map); +} +function Clear() { + return map.clear(); +} +function Delete(format) { + return map.delete(format); +} +function Has(format) { + return map.has(format); +} +function Set2(format, func) { + map.set(format, func); +} +function Get(format) { + return map.get(format); +} +var map = new Map; +// node_modules/@sinclair/typebox/build/import/type/registry/type.mjs +var exports_type = {}; +__export(exports_type, { + Set: () => { + { + return Set3; + } + }, + Has: () => { + { + return Has2; + } + }, + Get: () => { + { + return Get2; + } + }, + Entries: () => { + { + return Entries2; + } + }, + Delete: () => { + { + return Delete2; + } + }, + Clear: () => { + { + return Clear2; + } + } +}); +function Entries2() { + return new Map(map2); +} +function Clear2() { + return map2.clear(); +} +function Delete2(kind) { + return map2.delete(kind); +} +function Has2(kind) { + return map2.has(kind); +} +function Set3(kind, func) { + map2.set(kind, func); +} +function Get2(kind) { + return map2.get(kind); +} +var map2 = new Map; +// node_modules/@sinclair/typebox/build/import/type/symbols/symbols.mjs +var TransformKind = Symbol.for("TypeBox.Transform"); +var ReadonlyKind = Symbol.for("TypeBox.Readonly"); +var OptionalKind = Symbol.for("TypeBox.Optional"); +var Hint = Symbol.for("TypeBox.Hint"); +var Kind = Symbol.for("TypeBox.Kind"); +// node_modules/@sinclair/typebox/build/import/type/unsafe/unsafe.mjs +function Unsafe(options = {}) { + return { + ...options, + [Kind]: options[Kind] ?? "Unsafe" + }; +} +// node_modules/@sinclair/typebox/build/import/type/error/error.mjs +class TypeBoxError extends Error { + constructor(message) { + super(message); + } +} +// node_modules/@sinclair/typebox/build/import/system/system.mjs +class TypeSystemDuplicateTypeKind extends TypeBoxError { + constructor(kind) { + super(`Duplicate type kind '${kind}' detected`); + } +} + +class TypeSystemDuplicateFormat extends TypeBoxError { + constructor(kind) { + super(`Duplicate string format '${kind}' detected`); + } +} +var TypeSystem; +(function(TypeSystem2) { + function Type(kind, check) { + if (exports_type.Has(kind)) + throw new TypeSystemDuplicateTypeKind(kind); + exports_type.Set(kind, check); + return (options = {}) => Unsafe({ ...options, [Kind]: kind }); + } + TypeSystem2.Type = Type; + function Format(format, check) { + if (exports_format.Has(format)) + throw new TypeSystemDuplicateFormat(format); + exports_format.Set(format, check); + return format; + } + TypeSystem2.Format = Format; +})(TypeSystem || (TypeSystem = {})); +// node_modules/@sinclair/typebox/build/import/type/mapped/mapped-result.mjs +function MappedResult(properties) { + return { + [Kind]: "MappedResult", + properties + }; +} +// node_modules/@sinclair/typebox/build/import/type/guard/value.mjs +var exports_value = {}; +__export(exports_value, { + IsUndefined: () => { + { + return IsUndefined2; + } + }, + IsUint8Array: () => { + { + return IsUint8Array2; + } + }, + IsSymbol: () => { + { + return IsSymbol2; + } + }, + IsString: () => { + { + return IsString2; + } + }, + IsRegExp: () => { + { + return IsRegExp; + } + }, + IsObject: () => { + { + return IsObject2; + } + }, + IsNumber: () => { + { + return IsNumber2; + } + }, + IsNull: () => { + { + return IsNull2; + } + }, + IsIterator: () => { + { + return IsIterator2; + } + }, + IsFunction: () => { + { + return IsFunction2; + } + }, + IsDate: () => { + { + return IsDate2; + } + }, + IsBoolean: () => { + { + return IsBoolean2; + } + }, + IsBigInt: () => { + { + return IsBigInt2; + } + }, + IsAsyncIterator: () => { + { + return IsAsyncIterator2; + } + }, + IsArray: () => { + { + return IsArray2; + } + } +}); +function IsAsyncIterator2(value) { + return IsObject2(value) && !IsArray2(value) && !IsUint8Array2(value) && Symbol.asyncIterator in value; +} +function IsArray2(value) { + return Array.isArray(value); +} +function IsBigInt2(value) { + return typeof value === "bigint"; +} +function IsBoolean2(value) { + return typeof value === "boolean"; +} +function IsDate2(value) { + return value instanceof globalThis.Date; +} +function IsFunction2(value) { + return typeof value === "function"; +} +function IsIterator2(value) { + return IsObject2(value) && !IsArray2(value) && !IsUint8Array2(value) && Symbol.iterator in value; +} +function IsNull2(value) { + return value === null; +} +function IsNumber2(value) { + return typeof value === "number"; +} +function IsObject2(value) { + return typeof value === "object" && value !== null; +} +function IsRegExp(value) { + return value instanceof globalThis.RegExp; +} +function IsString2(value) { + return typeof value === "string"; +} +function IsSymbol2(value) { + return typeof value === "symbol"; +} +function IsUint8Array2(value) { + return value instanceof globalThis.Uint8Array; +} +function IsUndefined2(value) { + return value === undefined; +} + +// node_modules/@sinclair/typebox/build/import/type/clone/value.mjs +var ArrayType = function(value) { + return value.map((value2) => Visit(value2)); +}; +var DateType = function(value) { + return new Date(value.getTime()); +}; +var Uint8ArrayType = function(value) { + return new Uint8Array(value); +}; +var RegExpType = function(value) { + return new RegExp(value.source, value.flags); +}; +var ObjectType = function(value) { + const clonedProperties = Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {}); + const clonedSymbols = Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {}); + return { ...clonedProperties, ...clonedSymbols }; +}; +var Visit = function(value) { + return IsArray2(value) ? ArrayType(value) : IsDate2(value) ? DateType(value) : IsUint8Array2(value) ? Uint8ArrayType(value) : IsRegExp(value) ? RegExpType(value) : IsObject2(value) ? ObjectType(value) : value; +}; +function Clone(value) { + return Visit(value); +} + +// node_modules/@sinclair/typebox/build/import/type/clone/type.mjs +function CloneRest(schemas) { + return schemas.map((schema) => CloneType(schema)); +} +function CloneType(schema, options = {}) { + return { ...Clone(schema), ...options }; +} + +// node_modules/@sinclair/typebox/build/import/type/discard/discard.mjs +var DiscardKey = function(value2, key) { + const { [key]: _, ...rest } = value2; + return rest; +}; +function Discard(value2, keys) { + return keys.reduce((acc, key) => DiscardKey(acc, key), value2); +} +// node_modules/@sinclair/typebox/build/import/type/array/array.mjs +function Array2(schema, options = {}) { + return { + ...options, + [Kind]: "Array", + type: "array", + items: CloneType(schema) + }; +} +// node_modules/@sinclair/typebox/build/import/type/async-iterator/async-iterator.mjs +function AsyncIterator(items, options = {}) { + return { + ...options, + [Kind]: "AsyncIterator", + type: "AsyncIterator", + items: CloneType(items) + }; +} +// node_modules/@sinclair/typebox/build/import/type/constructor/constructor.mjs +function Constructor(parameters, returns, options) { + return { + ...options, + [Kind]: "Constructor", + type: "Constructor", + parameters: CloneRest(parameters), + returns: CloneType(returns) + }; +} +// node_modules/@sinclair/typebox/build/import/type/function/function.mjs +function Function2(parameters, returns, options) { + return { + ...options, + [Kind]: "Function", + type: "Function", + parameters: CloneRest(parameters), + returns: CloneType(returns) + }; +} +// node_modules/@sinclair/typebox/build/import/type/never/never.mjs +function Never(options = {}) { + return { + ...options, + [Kind]: "Never", + not: {} + }; +} +// node_modules/@sinclair/typebox/build/import/type/guard/type.mjs +var exports_type2 = {}; +__export(exports_type2, { + TypeGuardUnknownTypeError: () => { + { + return TypeGuardUnknownTypeError; + } + }, + IsVoid: () => { + { + return IsVoid; + } + }, + IsUnsafe: () => { + { + return IsUnsafe; + } + }, + IsUnknown: () => { + { + return IsUnknown; + } + }, + IsUnionLiteral: () => { + { + return IsUnionLiteral; + } + }, + IsUnion: () => { + { + return IsUnion; + } + }, + IsUndefined: () => { + { + return IsUndefined3; + } + }, + IsUint8Array: () => { + { + return IsUint8Array3; + } + }, + IsTuple: () => { + { + return IsTuple; + } + }, + IsTransform: () => { + { + return IsTransform; + } + }, + IsThis: () => { + { + return IsThis; + } + }, + IsTemplateLiteral: () => { + { + return IsTemplateLiteral; + } + }, + IsSymbol: () => { + { + return IsSymbol3; + } + }, + IsString: () => { + { + return IsString3; + } + }, + IsSchema: () => { + { + return IsSchema; + } + }, + IsRegExp: () => { + { + return IsRegExp2; + } + }, + IsRef: () => { + { + return IsRef; + } + }, + IsRecursive: () => { + { + return IsRecursive; + } + }, + IsRecord: () => { + { + return IsRecord; + } + }, + IsReadonly: () => { + { + return IsReadonly; + } + }, + IsProperties: () => { + { + return IsProperties; + } + }, + IsPromise: () => { + { + return IsPromise2; + } + }, + IsOptional: () => { + { + return IsOptional; + } + }, + IsObject: () => { + { + return IsObject3; + } + }, + IsNumber: () => { + { + return IsNumber3; + } + }, + IsNull: () => { + { + return IsNull3; + } + }, + IsNot: () => { + { + return IsNot; + } + }, + IsNever: () => { + { + return IsNever; + } + }, + IsMappedResult: () => { + { + return IsMappedResult; + } + }, + IsMappedKey: () => { + { + return IsMappedKey; + } + }, + IsLiteralValue: () => { + { + return IsLiteralValue; + } + }, + IsLiteralString: () => { + { + return IsLiteralString; + } + }, + IsLiteralNumber: () => { + { + return IsLiteralNumber; + } + }, + IsLiteralBoolean: () => { + { + return IsLiteralBoolean; + } + }, + IsLiteral: () => { + { + return IsLiteral; + } + }, + IsKindOf: () => { + { + return IsKindOf; + } + }, + IsKind: () => { + { + return IsKind; + } + }, + IsIterator: () => { + { + return IsIterator3; + } + }, + IsIntersect: () => { + { + return IsIntersect; + } + }, + IsInteger: () => { + { + return IsInteger2; + } + }, + IsFunction: () => { + { + return IsFunction3; + } + }, + IsDate: () => { + { + return IsDate3; + } + }, + IsConstructor: () => { + { + return IsConstructor; + } + }, + IsBoolean: () => { + { + return IsBoolean3; + } + }, + IsBigInt: () => { + { + return IsBigInt3; + } + }, + IsAsyncIterator: () => { + { + return IsAsyncIterator3; + } + }, + IsArray: () => { + { + return IsArray3; + } + }, + IsAny: () => { + { + return IsAny; + } + } +}); +var IsPattern = function(value2) { + try { + new RegExp(value2); + return true; + } catch { + return false; + } +}; +var IsControlCharacterFree = function(value2) { + if (!IsString2(value2)) + return false; + for (let i = 0;i < value2.length; i++) { + const code = value2.charCodeAt(i); + if (code >= 7 && code <= 13 || code === 27 || code === 127) { + return false; + } + } + return true; +}; +var IsAdditionalProperties = function(value2) { + return IsOptionalBoolean(value2) || IsSchema(value2); +}; +var IsOptionalBigInt = function(value2) { + return IsUndefined2(value2) || IsBigInt2(value2); +}; +var IsOptionalNumber = function(value2) { + return IsUndefined2(value2) || IsNumber2(value2); +}; +var IsOptionalBoolean = function(value2) { + return IsUndefined2(value2) || IsBoolean2(value2); +}; +var IsOptionalString = function(value2) { + return IsUndefined2(value2) || IsString2(value2); +}; +var IsOptionalPattern = function(value2) { + return IsUndefined2(value2) || IsString2(value2) && IsControlCharacterFree(value2) && IsPattern(value2); +}; +var IsOptionalFormat = function(value2) { + return IsUndefined2(value2) || IsString2(value2) && IsControlCharacterFree(value2); +}; +var IsOptionalSchema = function(value2) { + return IsUndefined2(value2) || IsSchema(value2); +}; +function IsReadonly(value2) { + return IsObject2(value2) && value2[ReadonlyKind] === "Readonly"; +} +function IsOptional(value2) { + return IsObject2(value2) && value2[OptionalKind] === "Optional"; +} +function IsAny(value2) { + return IsKindOf(value2, "Any") && IsOptionalString(value2.$id); +} +function IsArray3(value2) { + return IsKindOf(value2, "Array") && value2.type === "array" && IsOptionalString(value2.$id) && IsSchema(value2.items) && IsOptionalNumber(value2.minItems) && IsOptionalNumber(value2.maxItems) && IsOptionalBoolean(value2.uniqueItems) && IsOptionalSchema(value2.contains) && IsOptionalNumber(value2.minContains) && IsOptionalNumber(value2.maxContains); +} +function IsAsyncIterator3(value2) { + return IsKindOf(value2, "AsyncIterator") && value2.type === "AsyncIterator" && IsOptionalString(value2.$id) && IsSchema(value2.items); +} +function IsBigInt3(value2) { + return IsKindOf(value2, "BigInt") && value2.type === "bigint" && IsOptionalString(value2.$id) && IsOptionalBigInt(value2.exclusiveMaximum) && IsOptionalBigInt(value2.exclusiveMinimum) && IsOptionalBigInt(value2.maximum) && IsOptionalBigInt(value2.minimum) && IsOptionalBigInt(value2.multipleOf); +} +function IsBoolean3(value2) { + return IsKindOf(value2, "Boolean") && value2.type === "boolean" && IsOptionalString(value2.$id); +} +function IsConstructor(value2) { + return IsKindOf(value2, "Constructor") && value2.type === "Constructor" && IsOptionalString(value2.$id) && IsArray2(value2.parameters) && value2.parameters.every((schema) => IsSchema(schema)) && IsSchema(value2.returns); +} +function IsDate3(value2) { + return IsKindOf(value2, "Date") && value2.type === "Date" && IsOptionalString(value2.$id) && IsOptionalNumber(value2.exclusiveMaximumTimestamp) && IsOptionalNumber(value2.exclusiveMinimumTimestamp) && IsOptionalNumber(value2.maximumTimestamp) && IsOptionalNumber(value2.minimumTimestamp) && IsOptionalNumber(value2.multipleOfTimestamp); +} +function IsFunction3(value2) { + return IsKindOf(value2, "Function") && value2.type === "Function" && IsOptionalString(value2.$id) && IsArray2(value2.parameters) && value2.parameters.every((schema) => IsSchema(schema)) && IsSchema(value2.returns); +} +function IsInteger2(value2) { + return IsKindOf(value2, "Integer") && value2.type === "integer" && IsOptionalString(value2.$id) && IsOptionalNumber(value2.exclusiveMaximum) && IsOptionalNumber(value2.exclusiveMinimum) && IsOptionalNumber(value2.maximum) && IsOptionalNumber(value2.minimum) && IsOptionalNumber(value2.multipleOf); +} +function IsProperties(value2) { + return IsObject2(value2) && Object.entries(value2).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema(schema)); +} +function IsIntersect(value2) { + return IsKindOf(value2, "Intersect") && (IsString2(value2.type) && value2.type !== "object" ? false : true) && IsArray2(value2.allOf) && value2.allOf.every((schema) => IsSchema(schema) && !IsTransform(schema)) && IsOptionalString(value2.type) && (IsOptionalBoolean(value2.unevaluatedProperties) || IsOptionalSchema(value2.unevaluatedProperties)) && IsOptionalString(value2.$id); +} +function IsIterator3(value2) { + return IsKindOf(value2, "Iterator") && value2.type === "Iterator" && IsOptionalString(value2.$id) && IsSchema(value2.items); +} +function IsKindOf(value2, kind) { + return IsObject2(value2) && Kind in value2 && value2[Kind] === kind; +} +function IsLiteralString(value2) { + return IsLiteral(value2) && IsString2(value2.const); +} +function IsLiteralNumber(value2) { + return IsLiteral(value2) && IsNumber2(value2.const); +} +function IsLiteralBoolean(value2) { + return IsLiteral(value2) && IsBoolean2(value2.const); +} +function IsLiteral(value2) { + return IsKindOf(value2, "Literal") && IsOptionalString(value2.$id) && IsLiteralValue(value2.const); +} +function IsLiteralValue(value2) { + return IsBoolean2(value2) || IsNumber2(value2) || IsString2(value2); +} +function IsMappedKey(value2) { + return IsKindOf(value2, "MappedKey") && IsArray2(value2.keys) && value2.keys.every((key) => IsNumber2(key) || IsString2(key)); +} +function IsMappedResult(value2) { + return IsKindOf(value2, "MappedResult") && IsProperties(value2.properties); +} +function IsNever(value2) { + return IsKindOf(value2, "Never") && IsObject2(value2.not) && Object.getOwnPropertyNames(value2.not).length === 0; +} +function IsNot(value2) { + return IsKindOf(value2, "Not") && IsSchema(value2.not); +} +function IsNull3(value2) { + return IsKindOf(value2, "Null") && value2.type === "null" && IsOptionalString(value2.$id); +} +function IsNumber3(value2) { + return IsKindOf(value2, "Number") && value2.type === "number" && IsOptionalString(value2.$id) && IsOptionalNumber(value2.exclusiveMaximum) && IsOptionalNumber(value2.exclusiveMinimum) && IsOptionalNumber(value2.maximum) && IsOptionalNumber(value2.minimum) && IsOptionalNumber(value2.multipleOf); +} +function IsObject3(value2) { + return IsKindOf(value2, "Object") && value2.type === "object" && IsOptionalString(value2.$id) && IsProperties(value2.properties) && IsAdditionalProperties(value2.additionalProperties) && IsOptionalNumber(value2.minProperties) && IsOptionalNumber(value2.maxProperties); +} +function IsPromise2(value2) { + return IsKindOf(value2, "Promise") && value2.type === "Promise" && IsOptionalString(value2.$id) && IsSchema(value2.item); +} +function IsRecord(value2) { + return IsKindOf(value2, "Record") && value2.type === "object" && IsOptionalString(value2.$id) && IsAdditionalProperties(value2.additionalProperties) && IsObject2(value2.patternProperties) && ((schema) => { + const keys = Object.getOwnPropertyNames(schema.patternProperties); + return keys.length === 1 && IsPattern(keys[0]) && IsObject2(schema.patternProperties) && IsSchema(schema.patternProperties[keys[0]]); + })(value2); +} +function IsRecursive(value2) { + return IsObject2(value2) && Hint in value2 && value2[Hint] === "Recursive"; +} +function IsRef(value2) { + return IsKindOf(value2, "Ref") && IsOptionalString(value2.$id) && IsString2(value2.$ref); +} +function IsRegExp2(value2) { + return IsKindOf(value2, "RegExp") && IsOptionalString(value2.$id) && IsString2(value2.source) && IsString2(value2.flags) && IsOptionalNumber(value2.maxLength) && IsOptionalNumber(value2.minLength); +} +function IsString3(value2) { + return IsKindOf(value2, "String") && value2.type === "string" && IsOptionalString(value2.$id) && IsOptionalNumber(value2.minLength) && IsOptionalNumber(value2.maxLength) && IsOptionalPattern(value2.pattern) && IsOptionalFormat(value2.format); +} +function IsSymbol3(value2) { + return IsKindOf(value2, "Symbol") && value2.type === "symbol" && IsOptionalString(value2.$id); +} +function IsTemplateLiteral(value2) { + return IsKindOf(value2, "TemplateLiteral") && value2.type === "string" && IsString2(value2.pattern) && value2.pattern[0] === "^" && value2.pattern[value2.pattern.length - 1] === "$"; +} +function IsThis(value2) { + return IsKindOf(value2, "This") && IsOptionalString(value2.$id) && IsString2(value2.$ref); +} +function IsTransform(value2) { + return IsObject2(value2) && TransformKind in value2; +} +function IsTuple(value2) { + return IsKindOf(value2, "Tuple") && value2.type === "array" && IsOptionalString(value2.$id) && IsNumber2(value2.minItems) && IsNumber2(value2.maxItems) && value2.minItems === value2.maxItems && (IsUndefined2(value2.items) && IsUndefined2(value2.additionalItems) && value2.minItems === 0 || IsArray2(value2.items) && value2.items.every((schema) => IsSchema(schema))); +} +function IsUndefined3(value2) { + return IsKindOf(value2, "Undefined") && value2.type === "undefined" && IsOptionalString(value2.$id); +} +function IsUnionLiteral(value2) { + return IsUnion(value2) && value2.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema)); +} +function IsUnion(value2) { + return IsKindOf(value2, "Union") && IsOptionalString(value2.$id) && IsObject2(value2) && IsArray2(value2.anyOf) && value2.anyOf.every((schema) => IsSchema(schema)); +} +function IsUint8Array3(value2) { + return IsKindOf(value2, "Uint8Array") && value2.type === "Uint8Array" && IsOptionalString(value2.$id) && IsOptionalNumber(value2.minByteLength) && IsOptionalNumber(value2.maxByteLength); +} +function IsUnknown(value2) { + return IsKindOf(value2, "Unknown") && IsOptionalString(value2.$id); +} +function IsUnsafe(value2) { + return IsKindOf(value2, "Unsafe"); +} +function IsVoid(value2) { + return IsKindOf(value2, "Void") && value2.type === "void" && IsOptionalString(value2.$id); +} +function IsKind(value2) { + return IsObject2(value2) && Kind in value2 && IsString2(value2[Kind]) && !KnownTypes.includes(value2[Kind]); +} +function IsSchema(value2) { + return IsObject2(value2) && (IsAny(value2) || IsArray3(value2) || IsBoolean3(value2) || IsBigInt3(value2) || IsAsyncIterator3(value2) || IsConstructor(value2) || IsDate3(value2) || IsFunction3(value2) || IsInteger2(value2) || IsIntersect(value2) || IsIterator3(value2) || IsLiteral(value2) || IsMappedKey(value2) || IsMappedResult(value2) || IsNever(value2) || IsNot(value2) || IsNull3(value2) || IsNumber3(value2) || IsObject3(value2) || IsPromise2(value2) || IsRecord(value2) || IsRef(value2) || IsRegExp2(value2) || IsString3(value2) || IsSymbol3(value2) || IsTemplateLiteral(value2) || IsThis(value2) || IsTuple(value2) || IsUndefined3(value2) || IsUnion(value2) || IsUint8Array3(value2) || IsUnknown(value2) || IsUnsafe(value2) || IsVoid(value2) || IsKind(value2)); +} + +class TypeGuardUnknownTypeError extends TypeBoxError { +} +var KnownTypes = [ + "Any", + "Array", + "AsyncIterator", + "BigInt", + "Boolean", + "Constructor", + "Date", + "Enum", + "Function", + "Integer", + "Intersect", + "Iterator", + "Literal", + "MappedKey", + "MappedResult", + "Not", + "Null", + "Number", + "Object", + "Promise", + "Record", + "Ref", + "RegExp", + "String", + "Symbol", + "TemplateLiteral", + "This", + "Tuple", + "Undefined", + "Union", + "Uint8Array", + "Unknown", + "Void" +]; + +// node_modules/@sinclair/typebox/build/import/type/optional/optional.mjs +var RemoveOptional = function(schema) { + return Discard(CloneType(schema), [OptionalKind]); +}; +var AddOptional = function(schema) { + return { ...CloneType(schema), [OptionalKind]: "Optional" }; +}; +var OptionalWithFlag = function(schema, F) { + return F === false ? RemoveOptional(schema) : AddOptional(schema); +}; +function Optional(schema, enable) { + const F = enable ?? true; + return IsMappedResult(schema) ? OptionalFromMappedResult(schema, F) : OptionalWithFlag(schema, F); +} + +// node_modules/@sinclair/typebox/build/import/type/optional/optional-from-mapped-result.mjs +var FromProperties = function(P, F) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Optional(P[K2], F) }; + }, {}); +}; +var FromMappedResult = function(R, F) { + return FromProperties(R.properties, F); +}; +function OptionalFromMappedResult(R, F) { + const P = FromMappedResult(R, F); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/intersect/intersect-create.mjs +function IntersectCreate(T, options) { + const allObjects = T.every((schema) => IsObject3(schema)); + const clonedUnevaluatedProperties = IsSchema(options.unevaluatedProperties) ? { unevaluatedProperties: CloneType(options.unevaluatedProperties) } : {}; + return options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects ? { ...options, ...clonedUnevaluatedProperties, [Kind]: "Intersect", type: "object", allOf: CloneRest(T) } : { ...options, ...clonedUnevaluatedProperties, [Kind]: "Intersect", allOf: CloneRest(T) }; +} + +// node_modules/@sinclair/typebox/build/import/type/intersect/intersect-evaluated.mjs +var IsIntersectOptional = function(T) { + return T.every((L) => IsOptional(L)); +}; +var RemoveOptionalFromType = function(T) { + return Discard(T, [OptionalKind]); +}; +var RemoveOptionalFromRest = function(T) { + return T.map((L) => IsOptional(L) ? RemoveOptionalFromType(L) : L); +}; +var ResolveIntersect = function(T, options) { + return IsIntersectOptional(T) ? Optional(IntersectCreate(RemoveOptionalFromRest(T), options)) : IntersectCreate(RemoveOptionalFromRest(T), options); +}; +function IntersectEvaluated(T, options = {}) { + if (T.length === 0) + return Never(options); + if (T.length === 1) + return CloneType(T[0], options); + if (T.some((schema) => IsTransform(schema))) + throw new Error("Cannot intersect transform types"); + return ResolveIntersect(T, options); +} +// node_modules/@sinclair/typebox/build/import/type/intersect/intersect.mjs +function Intersect(T, options = {}) { + if (T.length === 0) + return Never(options); + if (T.length === 1) + return CloneType(T[0], options); + if (T.some((schema) => IsTransform(schema))) + throw new Error("Cannot intersect transform types"); + return IntersectCreate(T, options); +} +// node_modules/@sinclair/typebox/build/import/type/union/union-create.mjs +function UnionCreate(T, options) { + return { ...options, [Kind]: "Union", anyOf: CloneRest(T) }; +} + +// node_modules/@sinclair/typebox/build/import/type/union/union-evaluated.mjs +var IsUnionOptional = function(T) { + return T.some((L) => IsOptional(L)); +}; +var RemoveOptionalFromRest2 = function(T) { + return T.map((L) => IsOptional(L) ? RemoveOptionalFromType2(L) : L); +}; +var RemoveOptionalFromType2 = function(T) { + return Discard(T, [OptionalKind]); +}; +var ResolveUnion = function(T, options) { + return IsUnionOptional(T) ? Optional(UnionCreate(RemoveOptionalFromRest2(T), options)) : UnionCreate(RemoveOptionalFromRest2(T), options); +}; +function UnionEvaluated(T, options = {}) { + return T.length === 0 ? Never(options) : T.length === 1 ? CloneType(T[0], options) : ResolveUnion(T, options); +} +// node_modules/@sinclair/typebox/build/import/type/union/union.mjs +function Union(T, options = {}) { + return T.length === 0 ? Never(options) : T.length === 1 ? CloneType(T[0], options) : UnionCreate(T, options); +} +// node_modules/@sinclair/typebox/build/import/type/template-literal/parse.mjs +var Unescape = function(pattern) { + return pattern.replace(/\\\$/g, "$").replace(/\\\*/g, "*").replace(/\\\^/g, "^").replace(/\\\|/g, "|").replace(/\\\(/g, "(").replace(/\\\)/g, ")"); +}; +var IsNonEscaped = function(pattern, index, char) { + return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92; +}; +var IsOpenParen = function(pattern, index) { + return IsNonEscaped(pattern, index, "("); +}; +var IsCloseParen = function(pattern, index) { + return IsNonEscaped(pattern, index, ")"); +}; +var IsSeparator = function(pattern, index) { + return IsNonEscaped(pattern, index, "|"); +}; +var IsGroup = function(pattern) { + if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1))) + return false; + let count = 0; + for (let index = 0;index < pattern.length; index++) { + if (IsOpenParen(pattern, index)) + count += 1; + if (IsCloseParen(pattern, index)) + count -= 1; + if (count === 0 && index !== pattern.length - 1) + return false; + } + return true; +}; +var InGroup = function(pattern) { + return pattern.slice(1, pattern.length - 1); +}; +var IsPrecedenceOr = function(pattern) { + let count = 0; + for (let index = 0;index < pattern.length; index++) { + if (IsOpenParen(pattern, index)) + count += 1; + if (IsCloseParen(pattern, index)) + count -= 1; + if (IsSeparator(pattern, index) && count === 0) + return true; + } + return false; +}; +var IsPrecedenceAnd = function(pattern) { + for (let index = 0;index < pattern.length; index++) { + if (IsOpenParen(pattern, index)) + return true; + } + return false; +}; +var Or = function(pattern) { + let [count, start] = [0, 0]; + const expressions = []; + for (let index = 0;index < pattern.length; index++) { + if (IsOpenParen(pattern, index)) + count += 1; + if (IsCloseParen(pattern, index)) + count -= 1; + if (IsSeparator(pattern, index) && count === 0) { + const range2 = pattern.slice(start, index); + if (range2.length > 0) + expressions.push(TemplateLiteralParse(range2)); + start = index + 1; + } + } + const range = pattern.slice(start); + if (range.length > 0) + expressions.push(TemplateLiteralParse(range)); + if (expressions.length === 0) + return { type: "const", const: "" }; + if (expressions.length === 1) + return expressions[0]; + return { type: "or", expr: expressions }; +}; +var And = function(pattern) { + function Group(value2, index) { + if (!IsOpenParen(value2, index)) + throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`); + let count = 0; + for (let scan = index;scan < value2.length; scan++) { + if (IsOpenParen(value2, scan)) + count += 1; + if (IsCloseParen(value2, scan)) + count -= 1; + if (count === 0) + return [index, scan]; + } + throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`); + } + function Range(pattern2, index) { + for (let scan = index;scan < pattern2.length; scan++) { + if (IsOpenParen(pattern2, scan)) + return [index, scan]; + } + return [index, pattern2.length]; + } + const expressions = []; + for (let index = 0;index < pattern.length; index++) { + if (IsOpenParen(pattern, index)) { + const [start, end] = Group(pattern, index); + const range = pattern.slice(start, end + 1); + expressions.push(TemplateLiteralParse(range)); + index = end; + } else { + const [start, end] = Range(pattern, index); + const range = pattern.slice(start, end); + if (range.length > 0) + expressions.push(TemplateLiteralParse(range)); + index = end - 1; + } + } + return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions }; +}; +function TemplateLiteralParse(pattern) { + return IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: Unescape(pattern) }; +} +function TemplateLiteralParseExact(pattern) { + return TemplateLiteralParse(pattern.slice(1, pattern.length - 1)); +} + +class TemplateLiteralParserError extends TypeBoxError { +} + +// node_modules/@sinclair/typebox/build/import/type/template-literal/finite.mjs +var IsNumberExpression = function(expression) { + return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "0" && expression.expr[1].type === "const" && expression.expr[1].const === "[1-9][0-9]*"; +}; +var IsBooleanExpression = function(expression) { + return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "true" && expression.expr[1].type === "const" && expression.expr[1].const === "false"; +}; +var IsStringExpression = function(expression) { + return expression.type === "const" && expression.const === ".*"; +}; +function IsTemplateLiteralExpressionFinite(expression) { + return IsNumberExpression(expression) || IsStringExpression(expression) ? false : IsBooleanExpression(expression) ? true : expression.type === "and" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "or" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "const" ? true : (() => { + throw new TemplateLiteralFiniteError(`Unknown expression type`); + })(); +} +function IsTemplateLiteralFinite(schema) { + const expression = TemplateLiteralParseExact(schema.pattern); + return IsTemplateLiteralExpressionFinite(expression); +} + +class TemplateLiteralFiniteError extends TypeBoxError { +} +// node_modules/@sinclair/typebox/build/import/type/template-literal/generate.mjs +function* GenerateReduce(buffer) { + if (buffer.length === 1) + return yield* buffer[0]; + for (const left of buffer[0]) { + for (const right of GenerateReduce(buffer.slice(1))) { + yield `${left}${right}`; + } + } +} +function* GenerateAnd(expression) { + return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)])); +} +function* GenerateOr(expression) { + for (const expr of expression.expr) + yield* TemplateLiteralExpressionGenerate(expr); +} +function* GenerateConst(expression) { + return yield expression.const; +} +function* TemplateLiteralExpressionGenerate(expression) { + return expression.type === "and" ? yield* GenerateAnd(expression) : expression.type === "or" ? yield* GenerateOr(expression) : expression.type === "const" ? yield* GenerateConst(expression) : (() => { + throw new TemplateLiteralGenerateError("Unknown expression"); + })(); +} +function TemplateLiteralGenerate(schema) { + const expression = TemplateLiteralParseExact(schema.pattern); + return IsTemplateLiteralExpressionFinite(expression) ? [...TemplateLiteralExpressionGenerate(expression)] : []; +} + +class TemplateLiteralGenerateError extends TypeBoxError { +} +// node_modules/@sinclair/typebox/build/import/type/literal/literal.mjs +function Literal(value2, options = {}) { + return { + ...options, + [Kind]: "Literal", + const: value2, + type: typeof value2 + }; +} +// node_modules/@sinclair/typebox/build/import/type/boolean/boolean.mjs +function Boolean2(options = {}) { + return { + ...options, + [Kind]: "Boolean", + type: "boolean" + }; +} +// node_modules/@sinclair/typebox/build/import/type/bigint/bigint.mjs +function BigInt2(options = {}) { + return { + ...options, + [Kind]: "BigInt", + type: "bigint" + }; +} +// node_modules/@sinclair/typebox/build/import/type/number/number.mjs +function Number2(options = {}) { + return { + ...options, + [Kind]: "Number", + type: "number" + }; +} +// node_modules/@sinclair/typebox/build/import/type/string/string.mjs +function String2(options = {}) { + return { ...options, [Kind]: "String", type: "string" }; +} +// node_modules/@sinclair/typebox/build/import/type/template-literal/syntax.mjs +function* FromUnion(syntax) { + const trim = syntax.trim().replace(/"|'/g, ""); + return trim === "boolean" ? yield Boolean2() : trim === "number" ? yield Number2() : trim === "bigint" ? yield BigInt2() : trim === "string" ? yield String2() : yield (() => { + const literals = trim.split("|").map((literal3) => Literal(literal3.trim())); + return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals); + })(); +} +function* FromTerminal(syntax) { + if (syntax[1] !== "{") { + const L = Literal("$"); + const R = FromSyntax(syntax.slice(1)); + return yield* [L, ...R]; + } + for (let i = 2;i < syntax.length; i++) { + if (syntax[i] === "}") { + const L = FromUnion(syntax.slice(2, i)); + const R = FromSyntax(syntax.slice(i + 1)); + return yield* [...L, ...R]; + } + } + yield Literal(syntax); +} +function* FromSyntax(syntax) { + for (let i = 0;i < syntax.length; i++) { + if (syntax[i] === "$") { + const L = Literal(syntax.slice(0, i)); + const R = FromTerminal(syntax.slice(i)); + return yield* [L, ...R]; + } + } + yield Literal(syntax); +} +function TemplateLiteralSyntax(syntax) { + return [...FromSyntax(syntax)]; +} +// node_modules/@sinclair/typebox/build/import/type/patterns/patterns.mjs +var PatternBoolean = "(true|false)"; +var PatternNumber = "(0|[1-9][0-9]*)"; +var PatternString = "(.*)"; +var PatternBooleanExact = `^${PatternBoolean}\$`; +var PatternNumberExact = `^${PatternNumber}\$`; +var PatternStringExact = `^${PatternString}\$`; +// node_modules/@sinclair/typebox/build/import/type/template-literal/pattern.mjs +var Escape = function(value2) { + return value2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +}; +var Visit2 = function(schema, acc) { + return IsTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : IsUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit2(schema2, acc)).join("|")})` : IsNumber3(schema) ? `${acc}${PatternNumber}` : IsInteger2(schema) ? `${acc}${PatternNumber}` : IsBigInt3(schema) ? `${acc}${PatternNumber}` : IsString3(schema) ? `${acc}${PatternString}` : IsLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` : IsBoolean3(schema) ? `${acc}${PatternBoolean}` : (() => { + throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`); + })(); +}; +function TemplateLiteralPattern(kinds) { + return `^${kinds.map((schema) => Visit2(schema, "")).join("")}$`; +} + +class TemplateLiteralPatternError extends TypeBoxError { +} +// node_modules/@sinclair/typebox/build/import/type/template-literal/union.mjs +function TemplateLiteralToUnion(schema) { + const R = TemplateLiteralGenerate(schema); + const L = R.map((S) => Literal(S)); + return UnionEvaluated(L); +} +// node_modules/@sinclair/typebox/build/import/type/template-literal/template-literal.mjs +function TemplateLiteral(unresolved, options = {}) { + const pattern2 = IsString2(unresolved) ? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved)) : TemplateLiteralPattern(unresolved); + return { ...options, [Kind]: "TemplateLiteral", type: "string", pattern: pattern2 }; +} +// node_modules/@sinclair/typebox/build/import/type/indexed/indexed-property-keys.mjs +var FromTemplateLiteral = function(T) { + const R = TemplateLiteralGenerate(T); + return R.map((S) => S.toString()); +}; +var FromUnion2 = function(T) { + return T.reduce((Acc, L) => { + return [...Acc, ...IndexPropertyKeys(L)]; + }, []); +}; +var FromLiteral = function(T) { + return [T.toString()]; +}; +function IndexPropertyKeys(T) { + return [...new Set(IsTemplateLiteral(T) ? FromTemplateLiteral(T) : IsUnion(T) ? FromUnion2(T.anyOf) : IsLiteral(T) ? FromLiteral(T.const) : IsNumber3(T) ? ["[number]"] : IsInteger2(T) ? ["[number]"] : [])]; +} + +// node_modules/@sinclair/typebox/build/import/type/indexed/indexed-from-mapped-result.mjs +var FromProperties2 = function(T, P, options) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Index(T, IndexPropertyKeys(P[K2]), options) }; + }, {}); +}; +var FromMappedResult2 = function(T, R, options) { + return FromProperties2(T, R.properties, options); +}; +function IndexFromMappedResult(T, R, options) { + const P = FromMappedResult2(T, R, options); + return MappedResult(P); +} + +// node_modules/@sinclair/typebox/build/import/type/indexed/indexed.mjs +var FromRest = function(T, K) { + return T.map((L) => IndexFromPropertyKey(L, K)); +}; +var FromIntersectRest = function(T) { + return T.filter((L) => !IsNever(L)); +}; +var FromIntersect = function(T, K) { + return IntersectEvaluated(FromIntersectRest(FromRest(T, K))); +}; +var FromUnionRest = function(T) { + return T.some((L) => IsNever(L)) ? [] : T; +}; +var FromUnion3 = function(T, K) { + return UnionEvaluated(FromUnionRest(FromRest(T, K))); +}; +var FromTuple = function(T, K) { + return K in T ? T[K] : K === "[number]" ? UnionEvaluated(T) : Never(); +}; +var FromArray = function(T, K) { + return K === "[number]" ? T : Never(); +}; +var FromProperty = function(T, K) { + return K in T ? T[K] : Never(); +}; +function IndexFromPropertyKey(T, K) { + return IsIntersect(T) ? FromIntersect(T.allOf, K) : IsUnion(T) ? FromUnion3(T.anyOf, K) : IsTuple(T) ? FromTuple(T.items ?? [], K) : IsArray3(T) ? FromArray(T.items, K) : IsObject3(T) ? FromProperty(T.properties, K) : Never(); +} +function IndexFromPropertyKeys(T, K) { + return K.map((L) => IndexFromPropertyKey(T, L)); +} +var FromSchema = function(T, K) { + return UnionEvaluated(IndexFromPropertyKeys(T, K)); +}; +function Index(T, K, options = {}) { + return IsMappedResult(K) ? CloneType(IndexFromMappedResult(T, K, options)) : IsMappedKey(K) ? CloneType(IndexFromMappedKey(T, K, options)) : IsSchema(K) ? CloneType(FromSchema(T, IndexPropertyKeys(K)), options) : CloneType(FromSchema(T, K), options); +} + +// node_modules/@sinclair/typebox/build/import/type/indexed/indexed-from-mapped-key.mjs +var MappedIndexPropertyKey = function(T, K, options) { + return { [K]: Index(T, [K], options) }; +}; +var MappedIndexPropertyKeys = function(T, K, options) { + return K.reduce((Acc, L) => { + return { ...Acc, ...MappedIndexPropertyKey(T, L, options) }; + }, {}); +}; +var MappedIndexProperties = function(T, K, options) { + return MappedIndexPropertyKeys(T, K.keys, options); +}; +function IndexFromMappedKey(T, K, options) { + const P = MappedIndexProperties(T, K, options); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/iterator/iterator.mjs +function Iterator(items, options = {}) { + return { + ...options, + [Kind]: "Iterator", + type: "Iterator", + items: CloneType(items) + }; +} +// node_modules/@sinclair/typebox/build/import/type/object/object.mjs +var _Object = function(properties, options = {}) { + const propertyKeys = globalThis.Object.getOwnPropertyNames(properties); + const optionalKeys = propertyKeys.filter((key) => IsOptional(properties[key])); + const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name)); + const clonedAdditionalProperties = IsSchema(options.additionalProperties) ? { additionalProperties: CloneType(options.additionalProperties) } : {}; + const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: CloneType(properties[key]) }), {}); + return requiredKeys.length > 0 ? { ...options, ...clonedAdditionalProperties, [Kind]: "Object", type: "object", properties: clonedProperties, required: requiredKeys } : { ...options, ...clonedAdditionalProperties, [Kind]: "Object", type: "object", properties: clonedProperties }; +}; +var Object2 = _Object; +// node_modules/@sinclair/typebox/build/import/type/promise/promise.mjs +function Promise2(item, options = {}) { + return { + ...options, + [Kind]: "Promise", + type: "Promise", + item: CloneType(item) + }; +} +// node_modules/@sinclair/typebox/build/import/type/readonly/readonly.mjs +var RemoveReadonly = function(schema) { + return Discard(CloneType(schema), [ReadonlyKind]); +}; +var AddReadonly = function(schema) { + return { ...CloneType(schema), [ReadonlyKind]: "Readonly" }; +}; +var ReadonlyWithFlag = function(schema, F) { + return F === false ? RemoveReadonly(schema) : AddReadonly(schema); +}; +function Readonly(schema, enable) { + const F = enable ?? true; + return IsMappedResult(schema) ? ReadonlyFromMappedResult(schema, F) : ReadonlyWithFlag(schema, F); +} + +// node_modules/@sinclair/typebox/build/import/type/readonly/readonly-from-mapped-result.mjs +var FromProperties3 = function(K, F) { + return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => { + return { ...Acc, [K2]: Readonly(K[K2], F) }; + }, {}); +}; +var FromMappedResult3 = function(R, F) { + return FromProperties3(R.properties, F); +}; +function ReadonlyFromMappedResult(R, F) { + const P = FromMappedResult3(R, F); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/tuple/tuple.mjs +function Tuple(items, options = {}) { + const [additionalItems, minItems, maxItems] = [false, items.length, items.length]; + return items.length > 0 ? { ...options, [Kind]: "Tuple", type: "array", items: CloneRest(items), additionalItems, minItems, maxItems } : { ...options, [Kind]: "Tuple", type: "array", minItems, maxItems }; +} +// node_modules/@sinclair/typebox/build/import/type/sets/set.mjs +function SetIncludes(T, S) { + return T.includes(S); +} +function SetDistinct(T) { + return [...new Set(T)]; +} +function SetIntersect(T, S) { + return T.filter((L) => S.includes(L)); +} +var SetIntersectManyResolve = function(T, Init) { + return T.reduce((Acc, L) => { + return SetIntersect(Acc, L); + }, Init); +}; +function SetIntersectMany(T) { + return T.length === 1 ? T[0] : T.length > 1 ? SetIntersectManyResolve(T.slice(1), T[0]) : []; +} +function SetUnionMany(T) { + return T.reduce((Acc, L) => [...Acc, ...L], []); +} +// node_modules/@sinclair/typebox/build/import/type/mapped/mapped.mjs +var FromMappedResult4 = function(K, P) { + return K in P ? FromSchemaType(K, P[K]) : MappedResult(P); +}; +var MappedKeyToKnownMappedResultProperties = function(K) { + return { [K]: Literal(K) }; +}; +var MappedKeyToUnknownMappedResultProperties = function(P) { + return P.reduce((Acc, L) => { + return { ...Acc, [L]: Literal(L) }; + }, {}); +}; +var MappedKeyToMappedResultProperties = function(K, P) { + return SetIncludes(P, K) ? MappedKeyToKnownMappedResultProperties(K) : MappedKeyToUnknownMappedResultProperties(P); +}; +var FromMappedKey = function(K, P) { + const R = MappedKeyToMappedResultProperties(K, P); + return FromMappedResult4(K, R); +}; +var FromRest2 = function(K, T) { + return T.map((L) => FromSchemaType(K, L)); +}; +var FromProperties4 = function(K, T) { + return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K2) => { + return { ...Acc, [K2]: FromSchemaType(K, T[K2]) }; + }, {}); +}; +var FromSchemaType = function(K, T) { + return IsOptional(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) : IsReadonly(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) : IsMappedResult(T) ? FromMappedResult4(K, T.properties) : IsMappedKey(T) ? FromMappedKey(K, T.keys) : IsConstructor(T) ? Constructor(FromRest2(K, T.parameters), FromSchemaType(K, T.returns)) : IsFunction3(T) ? Function2(FromRest2(K, T.parameters), FromSchemaType(K, T.returns)) : IsAsyncIterator3(T) ? AsyncIterator(FromSchemaType(K, T.items)) : IsIterator3(T) ? Iterator(FromSchemaType(K, T.items)) : IsIntersect(T) ? Intersect(FromRest2(K, T.allOf)) : IsUnion(T) ? Union(FromRest2(K, T.anyOf)) : IsTuple(T) ? Tuple(FromRest2(K, T.items ?? [])) : IsObject3(T) ? Object2(FromProperties4(K, T.properties)) : IsArray3(T) ? Array2(FromSchemaType(K, T.items)) : IsPromise2(T) ? Promise2(FromSchemaType(K, T.item)) : T; +}; +function MappedFunctionReturnType(K, T, Acc = {}) { + return K.reduce((Acc2, L) => { + return { ...Acc2, [L]: FromSchemaType(L, T) }; + }, {}); +} +function Mapped(key, map3, options = {}) { + const K = IsSchema(key) ? IndexPropertyKeys(key) : key; + const RT = map3({ [Kind]: "MappedKey", keys: K }); + const R = MappedFunctionReturnType(K, RT); + return CloneType(Object2(R), options); +} +// node_modules/@sinclair/typebox/build/import/type/keyof/keyof-property-keys.mjs +var FromRest3 = function(T) { + return T.reduce((Acc, L) => { + return [...Acc, KeyOfPropertyKeys(L)]; + }, []); +}; +var FromIntersect2 = function(T) { + const C = FromRest3(T); + const R = SetUnionMany(C); + return R; +}; +var FromUnion4 = function(T) { + const C = FromRest3(T); + const R = SetIntersectMany(C); + return R; +}; +var FromTuple2 = function(T) { + return T.map((_, I) => I.toString()); +}; +var FromArray2 = function(_) { + return ["[number]"]; +}; +var FromProperties5 = function(T) { + return globalThis.Object.getOwnPropertyNames(T); +}; +var FromPatternProperties = function(patternProperties) { + if (!includePatternProperties) + return []; + const patternPropertyKeys = globalThis.Object.getOwnPropertyNames(patternProperties); + return patternPropertyKeys.map((key) => { + return key[0] === "^" && key[key.length - 1] === "$" ? key.slice(1, key.length - 1) : key; + }); +}; +function KeyOfPropertyKeys(T) { + return IsIntersect(T) ? FromIntersect2(T.allOf) : IsUnion(T) ? FromUnion4(T.anyOf) : IsTuple(T) ? FromTuple2(T.items ?? []) : IsArray3(T) ? FromArray2(T.items) : IsObject3(T) ? FromProperties5(T.properties) : IsRecord(T) ? FromPatternProperties(T.patternProperties) : []; +} +function KeyOfPattern(schema) { + includePatternProperties = true; + const keys = KeyOfPropertyKeys(schema); + includePatternProperties = false; + const pattern3 = keys.map((key) => `(${key})`); + return `^(${pattern3.join("|")})\$`; +} +var includePatternProperties = false; + +// node_modules/@sinclair/typebox/build/import/type/keyof/keyof.mjs +function KeyOfPropertyKeysToRest(T) { + return T.map((L) => L === "[number]" ? Number2() : Literal(L)); +} +function KeyOf(T, options = {}) { + if (IsMappedResult(T)) { + return KeyOfFromMappedResult(T, options); + } else { + const K = KeyOfPropertyKeys(T); + const S = KeyOfPropertyKeysToRest(K); + const U = UnionEvaluated(S); + return CloneType(U, options); + } +} + +// node_modules/@sinclair/typebox/build/import/type/keyof/keyof-from-mapped-result.mjs +var FromProperties6 = function(K, options) { + return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => { + return { ...Acc, [K2]: KeyOf(K[K2], options) }; + }, {}); +}; +var FromMappedResult5 = function(R, options) { + return FromProperties6(R.properties, options); +}; +function KeyOfFromMappedResult(R, options) { + const P = FromMappedResult5(R, options); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/extends/extends-undefined.mjs +var Intersect2 = function(schema) { + return schema.allOf.every((schema2) => ExtendsUndefinedCheck(schema2)); +}; +var Union2 = function(schema) { + return schema.anyOf.some((schema2) => ExtendsUndefinedCheck(schema2)); +}; +var Not = function(schema) { + return !ExtendsUndefinedCheck(schema.not); +}; +function ExtendsUndefinedCheck(schema) { + return schema[Kind] === "Intersect" ? Intersect2(schema) : schema[Kind] === "Union" ? Union2(schema) : schema[Kind] === "Not" ? Not(schema) : schema[Kind] === "Undefined" ? true : false; +} + +// node_modules/@sinclair/typebox/build/import/errors/function.mjs +function DefaultErrorFunction(error8) { + switch (error8.errorType) { + case ValueErrorType.ArrayContains: + return "Expected array to contain at least one matching value"; + case ValueErrorType.ArrayMaxContains: + return `Expected array to contain no more than ${error8.schema.maxContains} matching values`; + case ValueErrorType.ArrayMinContains: + return `Expected array to contain at least ${error8.schema.minContains} matching values`; + case ValueErrorType.ArrayMaxItems: + return `Expected array length to be less or equal to ${error8.schema.maxItems}`; + case ValueErrorType.ArrayMinItems: + return `Expected array length to be greater or equal to ${error8.schema.minItems}`; + case ValueErrorType.ArrayUniqueItems: + return "Expected array elements to be unique"; + case ValueErrorType.Array: + return "Expected array"; + case ValueErrorType.AsyncIterator: + return "Expected AsyncIterator"; + case ValueErrorType.BigIntExclusiveMaximum: + return `Expected bigint to be less than ${error8.schema.exclusiveMaximum}`; + case ValueErrorType.BigIntExclusiveMinimum: + return `Expected bigint to be greater than ${error8.schema.exclusiveMinimum}`; + case ValueErrorType.BigIntMaximum: + return `Expected bigint to be less or equal to ${error8.schema.maximum}`; + case ValueErrorType.BigIntMinimum: + return `Expected bigint to be greater or equal to ${error8.schema.minimum}`; + case ValueErrorType.BigIntMultipleOf: + return `Expected bigint to be a multiple of ${error8.schema.multipleOf}`; + case ValueErrorType.BigInt: + return "Expected bigint"; + case ValueErrorType.Boolean: + return "Expected boolean"; + case ValueErrorType.DateExclusiveMinimumTimestamp: + return `Expected Date timestamp to be greater than ${error8.schema.exclusiveMinimumTimestamp}`; + case ValueErrorType.DateExclusiveMaximumTimestamp: + return `Expected Date timestamp to be less than ${error8.schema.exclusiveMaximumTimestamp}`; + case ValueErrorType.DateMinimumTimestamp: + return `Expected Date timestamp to be greater or equal to ${error8.schema.minimumTimestamp}`; + case ValueErrorType.DateMaximumTimestamp: + return `Expected Date timestamp to be less or equal to ${error8.schema.maximumTimestamp}`; + case ValueErrorType.DateMultipleOfTimestamp: + return `Expected Date timestamp to be a multiple of ${error8.schema.multipleOfTimestamp}`; + case ValueErrorType.Date: + return "Expected Date"; + case ValueErrorType.Function: + return "Expected function"; + case ValueErrorType.IntegerExclusiveMaximum: + return `Expected integer to be less than ${error8.schema.exclusiveMaximum}`; + case ValueErrorType.IntegerExclusiveMinimum: + return `Expected integer to be greater than ${error8.schema.exclusiveMinimum}`; + case ValueErrorType.IntegerMaximum: + return `Expected integer to be less or equal to ${error8.schema.maximum}`; + case ValueErrorType.IntegerMinimum: + return `Expected integer to be greater or equal to ${error8.schema.minimum}`; + case ValueErrorType.IntegerMultipleOf: + return `Expected integer to be a multiple of ${error8.schema.multipleOf}`; + case ValueErrorType.Integer: + return "Expected integer"; + case ValueErrorType.IntersectUnevaluatedProperties: + return "Unexpected property"; + case ValueErrorType.Intersect: + return "Expected all values to match"; + case ValueErrorType.Iterator: + return "Expected Iterator"; + case ValueErrorType.Literal: + return `Expected ${typeof error8.schema.const === "string" ? `'${error8.schema.const}'` : error8.schema.const}`; + case ValueErrorType.Never: + return "Never"; + case ValueErrorType.Not: + return "Value should not match"; + case ValueErrorType.Null: + return "Expected null"; + case ValueErrorType.NumberExclusiveMaximum: + return `Expected number to be less than ${error8.schema.exclusiveMaximum}`; + case ValueErrorType.NumberExclusiveMinimum: + return `Expected number to be greater than ${error8.schema.exclusiveMinimum}`; + case ValueErrorType.NumberMaximum: + return `Expected number to be less or equal to ${error8.schema.maximum}`; + case ValueErrorType.NumberMinimum: + return `Expected number to be greater or equal to ${error8.schema.minimum}`; + case ValueErrorType.NumberMultipleOf: + return `Expected number to be a multiple of ${error8.schema.multipleOf}`; + case ValueErrorType.Number: + return "Expected number"; + case ValueErrorType.Object: + return "Expected object"; + case ValueErrorType.ObjectAdditionalProperties: + return "Unexpected property"; + case ValueErrorType.ObjectMaxProperties: + return `Expected object to have no more than ${error8.schema.maxProperties} properties`; + case ValueErrorType.ObjectMinProperties: + return `Expected object to have at least ${error8.schema.minProperties} properties`; + case ValueErrorType.ObjectRequiredProperty: + return "Required property"; + case ValueErrorType.Promise: + return "Expected Promise"; + case ValueErrorType.RegExp: + return "Expected string to match regular expression"; + case ValueErrorType.StringFormatUnknown: + return `Unknown format '${error8.schema.format}'`; + case ValueErrorType.StringFormat: + return `Expected string to match '${error8.schema.format}' format`; + case ValueErrorType.StringMaxLength: + return `Expected string length less or equal to ${error8.schema.maxLength}`; + case ValueErrorType.StringMinLength: + return `Expected string length greater or equal to ${error8.schema.minLength}`; + case ValueErrorType.StringPattern: + return `Expected string to match '${error8.schema.pattern}'`; + case ValueErrorType.String: + return "Expected string"; + case ValueErrorType.Symbol: + return "Expected symbol"; + case ValueErrorType.TupleLength: + return `Expected tuple to have ${error8.schema.maxItems || 0} elements`; + case ValueErrorType.Tuple: + return "Expected tuple"; + case ValueErrorType.Uint8ArrayMaxByteLength: + return `Expected byte length less or equal to ${error8.schema.maxByteLength}`; + case ValueErrorType.Uint8ArrayMinByteLength: + return `Expected byte length greater or equal to ${error8.schema.minByteLength}`; + case ValueErrorType.Uint8Array: + return "Expected Uint8Array"; + case ValueErrorType.Undefined: + return "Expected undefined"; + case ValueErrorType.Union: + return "Expected union value"; + case ValueErrorType.Void: + return "Expected void"; + case ValueErrorType.Kind: + return `Expected kind '${error8.schema[Kind]}'`; + default: + return "Unknown error type"; + } +} +function GetErrorFunction() { + return errorFunction; +} +var errorFunction = DefaultErrorFunction; + +// node_modules/@sinclair/typebox/build/import/value/deref/deref.mjs +function Deref(schema, references) { + const index = references.findIndex((target) => target.$id === schema.$ref); + if (index === -1) + throw new TypeDereferenceError(schema); + return references[index]; +} + +class TypeDereferenceError extends TypeBoxError { + schema; + constructor(schema) { + super(`Unable to dereference schema with \$id '${schema.$id}'`); + this.schema = schema; + } +} +// node_modules/@sinclair/typebox/build/import/value/hash/hash.mjs +function* NumberToBytes(value3) { + const byteCount = value3 === 0 ? 1 : Math.ceil(Math.floor(Math.log2(value3) + 1) / 8); + for (let i = 0;i < byteCount; i++) { + yield value3 >> 8 * (byteCount - 1 - i) & 255; + } +} +var ArrayType2 = function(value3) { + FNV1A64(ByteMarker.Array); + for (const item of value3) { + Visit3(item); + } +}; +var BooleanType = function(value3) { + FNV1A64(ByteMarker.Boolean); + FNV1A64(value3 ? 1 : 0); +}; +var BigIntType = function(value3) { + FNV1A64(ByteMarker.BigInt); + F64In.setBigInt64(0, value3); + for (const byte of F64Out) { + FNV1A64(byte); + } +}; +var DateType2 = function(value3) { + FNV1A64(ByteMarker.Date); + Visit3(value3.getTime()); +}; +var NullType = function(value3) { + FNV1A64(ByteMarker.Null); +}; +var NumberType = function(value3) { + FNV1A64(ByteMarker.Number); + F64In.setFloat64(0, value3); + for (const byte of F64Out) { + FNV1A64(byte); + } +}; +var ObjectType2 = function(value3) { + FNV1A64(ByteMarker.Object); + for (const key of globalThis.Object.keys(value3).sort()) { + Visit3(key); + Visit3(value3[key]); + } +}; +var StringType = function(value3) { + FNV1A64(ByteMarker.String); + for (let i = 0;i < value3.length; i++) { + for (const byte of NumberToBytes(value3.charCodeAt(i))) { + FNV1A64(byte); + } + } +}; +var SymbolType = function(value3) { + FNV1A64(ByteMarker.Symbol); + Visit3(value3.description); +}; +var Uint8ArrayType2 = function(value3) { + FNV1A64(ByteMarker.Uint8Array); + for (let i = 0;i < value3.length; i++) { + FNV1A64(value3[i]); + } +}; +var UndefinedType = function(value3) { + return FNV1A64(ByteMarker.Undefined); +}; +var Visit3 = function(value3) { + if (IsArray(value3)) + return ArrayType2(value3); + if (IsBoolean(value3)) + return BooleanType(value3); + if (IsBigInt(value3)) + return BigIntType(value3); + if (IsDate(value3)) + return DateType2(value3); + if (IsNull(value3)) + return NullType(value3); + if (IsNumber(value3)) + return NumberType(value3); + if (IsStandardObject(value3)) + return ObjectType2(value3); + if (IsString(value3)) + return StringType(value3); + if (IsSymbol(value3)) + return SymbolType(value3); + if (IsUint8Array(value3)) + return Uint8ArrayType2(value3); + if (IsUndefined(value3)) + return UndefinedType(value3); + throw new ValueHashError(value3); +}; +var FNV1A64 = function(byte) { + Accumulator = Accumulator ^ Bytes[byte]; + Accumulator = Accumulator * Prime % Size; +}; +function Hash(value3) { + Accumulator = BigInt("14695981039346656037"); + Visit3(value3); + return Accumulator; +} + +class ValueHashError extends TypeBoxError { + value; + constructor(value3) { + super(`Unable to hash value`); + this.value = value3; + } +} +var ByteMarker; +(function(ByteMarker2) { + ByteMarker2[ByteMarker2["Undefined"] = 0] = "Undefined"; + ByteMarker2[ByteMarker2["Null"] = 1] = "Null"; + ByteMarker2[ByteMarker2["Boolean"] = 2] = "Boolean"; + ByteMarker2[ByteMarker2["Number"] = 3] = "Number"; + ByteMarker2[ByteMarker2["String"] = 4] = "String"; + ByteMarker2[ByteMarker2["Object"] = 5] = "Object"; + ByteMarker2[ByteMarker2["Array"] = 6] = "Array"; + ByteMarker2[ByteMarker2["Date"] = 7] = "Date"; + ByteMarker2[ByteMarker2["Uint8Array"] = 8] = "Uint8Array"; + ByteMarker2[ByteMarker2["Symbol"] = 9] = "Symbol"; + ByteMarker2[ByteMarker2["BigInt"] = 10] = "BigInt"; +})(ByteMarker || (ByteMarker = {})); +var Accumulator = BigInt("14695981039346656037"); +var [Prime, Size] = [BigInt("1099511628211"), BigInt("2") ** BigInt("64")]; +var Bytes = Array.from({ length: 256 }).map((_, i) => BigInt(i)); +var F64 = new Float64Array(1); +var F64In = new DataView(F64.buffer); +var F64Out = new Uint8Array(F64.buffer); +// node_modules/@sinclair/typebox/build/import/errors/errors.mjs +var EscapeKey = function(key) { + return key.replace(/~/g, "~0").replace(/\//g, "~1"); +}; +var IsDefined = function(value3) { + return value3 !== undefined; +}; +var Create = function(errorType, schema, path, value3) { + return { type: errorType, schema, path, value: value3, message: GetErrorFunction()({ errorType, path, schema, value: value3 }) }; +}; +function* FromAny(schema, references, path, value3) { +} +function* FromArray3(schema, references, path, value3) { + if (!IsArray(value3)) { + return yield Create(ValueErrorType.Array, schema, path, value3); + } + if (IsDefined(schema.minItems) && !(value3.length >= schema.minItems)) { + yield Create(ValueErrorType.ArrayMinItems, schema, path, value3); + } + if (IsDefined(schema.maxItems) && !(value3.length <= schema.maxItems)) { + yield Create(ValueErrorType.ArrayMaxItems, schema, path, value3); + } + for (let i = 0;i < value3.length; i++) { + yield* Visit4(schema.items, references, `${path}/${i}`, value3[i]); + } + if (schema.uniqueItems === true && !function() { + const set2 = new Set; + for (const element of value3) { + const hashed = Hash(element); + if (set2.has(hashed)) { + return false; + } else { + set2.add(hashed); + } + } + return true; + }()) { + yield Create(ValueErrorType.ArrayUniqueItems, schema, path, value3); + } + if (!(IsDefined(schema.contains) || IsDefined(schema.minContains) || IsDefined(schema.maxContains))) { + return; + } + const containsSchema = IsDefined(schema.contains) ? schema.contains : Never(); + const containsCount = value3.reduce((acc, value4, index) => Visit4(containsSchema, references, `${path}${index}`, value4).next().done === true ? acc + 1 : acc, 0); + if (containsCount === 0) { + yield Create(ValueErrorType.ArrayContains, schema, path, value3); + } + if (IsNumber(schema.minContains) && containsCount < schema.minContains) { + yield Create(ValueErrorType.ArrayMinContains, schema, path, value3); + } + if (IsNumber(schema.maxContains) && containsCount > schema.maxContains) { + yield Create(ValueErrorType.ArrayMaxContains, schema, path, value3); + } +} +function* FromAsyncIterator(schema, references, path, value3) { + if (!IsAsyncIterator(value3)) + yield Create(ValueErrorType.AsyncIterator, schema, path, value3); +} +function* FromBigInt(schema, references, path, value3) { + if (!IsBigInt(value3)) + return yield Create(ValueErrorType.BigInt, schema, path, value3); + if (IsDefined(schema.exclusiveMaximum) && !(value3 < schema.exclusiveMaximum)) { + yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path, value3); + } + if (IsDefined(schema.exclusiveMinimum) && !(value3 > schema.exclusiveMinimum)) { + yield Create(ValueErrorType.BigIntExclusiveMinimum, schema, path, value3); + } + if (IsDefined(schema.maximum) && !(value3 <= schema.maximum)) { + yield Create(ValueErrorType.BigIntMaximum, schema, path, value3); + } + if (IsDefined(schema.minimum) && !(value3 >= schema.minimum)) { + yield Create(ValueErrorType.BigIntMinimum, schema, path, value3); + } + if (IsDefined(schema.multipleOf) && !(value3 % schema.multipleOf === BigInt(0))) { + yield Create(ValueErrorType.BigIntMultipleOf, schema, path, value3); + } +} +function* FromBoolean(schema, references, path, value3) { + if (!IsBoolean(value3)) + yield Create(ValueErrorType.Boolean, schema, path, value3); +} +function* FromConstructor(schema, references, path, value3) { + yield* Visit4(schema.returns, references, path, value3.prototype); +} +function* FromDate(schema, references, path, value3) { + if (!IsDate(value3)) + return yield Create(ValueErrorType.Date, schema, path, value3); + if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value3.getTime() < schema.exclusiveMaximumTimestamp)) { + yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value3); + } + if (IsDefined(schema.exclusiveMinimumTimestamp) && !(value3.getTime() > schema.exclusiveMinimumTimestamp)) { + yield Create(ValueErrorType.DateExclusiveMinimumTimestamp, schema, path, value3); + } + if (IsDefined(schema.maximumTimestamp) && !(value3.getTime() <= schema.maximumTimestamp)) { + yield Create(ValueErrorType.DateMaximumTimestamp, schema, path, value3); + } + if (IsDefined(schema.minimumTimestamp) && !(value3.getTime() >= schema.minimumTimestamp)) { + yield Create(ValueErrorType.DateMinimumTimestamp, schema, path, value3); + } + if (IsDefined(schema.multipleOfTimestamp) && !(value3.getTime() % schema.multipleOfTimestamp === 0)) { + yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path, value3); + } +} +function* FromFunction(schema, references, path, value3) { + if (!IsFunction(value3)) + yield Create(ValueErrorType.Function, schema, path, value3); +} +function* FromInteger(schema, references, path, value3) { + if (!IsInteger(value3)) + return yield Create(ValueErrorType.Integer, schema, path, value3); + if (IsDefined(schema.exclusiveMaximum) && !(value3 < schema.exclusiveMaximum)) { + yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path, value3); + } + if (IsDefined(schema.exclusiveMinimum) && !(value3 > schema.exclusiveMinimum)) { + yield Create(ValueErrorType.IntegerExclusiveMinimum, schema, path, value3); + } + if (IsDefined(schema.maximum) && !(value3 <= schema.maximum)) { + yield Create(ValueErrorType.IntegerMaximum, schema, path, value3); + } + if (IsDefined(schema.minimum) && !(value3 >= schema.minimum)) { + yield Create(ValueErrorType.IntegerMinimum, schema, path, value3); + } + if (IsDefined(schema.multipleOf) && !(value3 % schema.multipleOf === 0)) { + yield Create(ValueErrorType.IntegerMultipleOf, schema, path, value3); + } +} +function* FromIntersect3(schema, references, path, value3) { + for (const inner of schema.allOf) { + const next = Visit4(inner, references, path, value3).next(); + if (!next.done) { + yield Create(ValueErrorType.Intersect, schema, path, value3); + yield next.value; + } + } + if (schema.unevaluatedProperties === false) { + const keyCheck = new RegExp(KeyOfPattern(schema)); + for (const valueKey of Object.getOwnPropertyNames(value3)) { + if (!keyCheck.test(valueKey)) { + yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value3); + } + } + } + if (typeof schema.unevaluatedProperties === "object") { + const keyCheck = new RegExp(KeyOfPattern(schema)); + for (const valueKey of Object.getOwnPropertyNames(value3)) { + if (!keyCheck.test(valueKey)) { + const next = Visit4(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value3[valueKey]).next(); + if (!next.done) + yield next.value; + } + } + } +} +function* FromIterator(schema, references, path, value3) { + if (!IsIterator(value3)) + yield Create(ValueErrorType.Iterator, schema, path, value3); +} +function* FromLiteral2(schema, references, path, value3) { + if (!(value3 === schema.const)) + yield Create(ValueErrorType.Literal, schema, path, value3); +} +function* FromNever(schema, references, path, value3) { + yield Create(ValueErrorType.Never, schema, path, value3); +} +function* FromNot(schema, references, path, value3) { + if (Visit4(schema.not, references, path, value3).next().done === true) + yield Create(ValueErrorType.Not, schema, path, value3); +} +function* FromNull(schema, references, path, value3) { + if (!IsNull(value3)) + yield Create(ValueErrorType.Null, schema, path, value3); +} +function* FromNumber(schema, references, path, value3) { + if (!TypeSystemPolicy.IsNumberLike(value3)) + return yield Create(ValueErrorType.Number, schema, path, value3); + if (IsDefined(schema.exclusiveMaximum) && !(value3 < schema.exclusiveMaximum)) { + yield Create(ValueErrorType.NumberExclusiveMaximum, schema, path, value3); + } + if (IsDefined(schema.exclusiveMinimum) && !(value3 > schema.exclusiveMinimum)) { + yield Create(ValueErrorType.NumberExclusiveMinimum, schema, path, value3); + } + if (IsDefined(schema.maximum) && !(value3 <= schema.maximum)) { + yield Create(ValueErrorType.NumberMaximum, schema, path, value3); + } + if (IsDefined(schema.minimum) && !(value3 >= schema.minimum)) { + yield Create(ValueErrorType.NumberMinimum, schema, path, value3); + } + if (IsDefined(schema.multipleOf) && !(value3 % schema.multipleOf === 0)) { + yield Create(ValueErrorType.NumberMultipleOf, schema, path, value3); + } +} +function* FromObject(schema, references, path, value3) { + if (!TypeSystemPolicy.IsObjectLike(value3)) + return yield Create(ValueErrorType.Object, schema, path, value3); + if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value3).length >= schema.minProperties)) { + yield Create(ValueErrorType.ObjectMinProperties, schema, path, value3); + } + if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value3).length <= schema.maxProperties)) { + yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value3); + } + const requiredKeys = Array.isArray(schema.required) ? schema.required : []; + const knownKeys = Object.getOwnPropertyNames(schema.properties); + const unknownKeys = Object.getOwnPropertyNames(value3); + for (const requiredKey of requiredKeys) { + if (unknownKeys.includes(requiredKey)) + continue; + yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path}/${EscapeKey(requiredKey)}`, undefined); + } + if (schema.additionalProperties === false) { + for (const valueKey of unknownKeys) { + if (!knownKeys.includes(valueKey)) { + yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(valueKey)}`, value3[valueKey]); + } + } + } + if (typeof schema.additionalProperties === "object") { + for (const valueKey of unknownKeys) { + if (knownKeys.includes(valueKey)) + continue; + yield* Visit4(schema.additionalProperties, references, `${path}/${EscapeKey(valueKey)}`, value3[valueKey]); + } + } + for (const knownKey of knownKeys) { + const property = schema.properties[knownKey]; + if (schema.required && schema.required.includes(knownKey)) { + yield* Visit4(property, references, `${path}/${EscapeKey(knownKey)}`, value3[knownKey]); + if (ExtendsUndefinedCheck(schema) && !(knownKey in value3)) { + yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path}/${EscapeKey(knownKey)}`, undefined); + } + } else { + if (TypeSystemPolicy.IsExactOptionalProperty(value3, knownKey)) { + yield* Visit4(property, references, `${path}/${EscapeKey(knownKey)}`, value3[knownKey]); + } + } + } +} +function* FromPromise(schema, references, path, value3) { + if (!IsPromise(value3)) + yield Create(ValueErrorType.Promise, schema, path, value3); +} +function* FromRecord(schema, references, path, value3) { + if (!TypeSystemPolicy.IsRecordLike(value3)) + return yield Create(ValueErrorType.Object, schema, path, value3); + if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value3).length >= schema.minProperties)) { + yield Create(ValueErrorType.ObjectMinProperties, schema, path, value3); + } + if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value3).length <= schema.maxProperties)) { + yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value3); + } + const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0]; + const regex = new RegExp(patternKey); + for (const [propertyKey, propertyValue] of Object.entries(value3)) { + if (regex.test(propertyKey)) + yield* Visit4(patternSchema, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue); + } + if (typeof schema.additionalProperties === "object") { + for (const [propertyKey, propertyValue] of Object.entries(value3)) { + if (!regex.test(propertyKey)) + yield* Visit4(schema.additionalProperties, references, `${path}/${EscapeKey(propertyKey)}`, propertyValue); + } + } + if (schema.additionalProperties === false) { + for (const [propertyKey, propertyValue] of Object.entries(value3)) { + if (regex.test(propertyKey)) + continue; + return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${EscapeKey(propertyKey)}`, propertyValue); + } + } +} +function* FromRef(schema, references, path, value3) { + yield* Visit4(Deref(schema, references), references, path, value3); +} +function* FromRegExp(schema, references, path, value3) { + if (!IsString(value3)) + return yield Create(ValueErrorType.String, schema, path, value3); + if (IsDefined(schema.minLength) && !(value3.length >= schema.minLength)) { + yield Create(ValueErrorType.StringMinLength, schema, path, value3); + } + if (IsDefined(schema.maxLength) && !(value3.length <= schema.maxLength)) { + yield Create(ValueErrorType.StringMaxLength, schema, path, value3); + } + const regex = new RegExp(schema.source, schema.flags); + if (!regex.test(value3)) { + return yield Create(ValueErrorType.RegExp, schema, path, value3); + } +} +function* FromString(schema, references, path, value3) { + if (!IsString(value3)) + return yield Create(ValueErrorType.String, schema, path, value3); + if (IsDefined(schema.minLength) && !(value3.length >= schema.minLength)) { + yield Create(ValueErrorType.StringMinLength, schema, path, value3); + } + if (IsDefined(schema.maxLength) && !(value3.length <= schema.maxLength)) { + yield Create(ValueErrorType.StringMaxLength, schema, path, value3); + } + if (IsString(schema.pattern)) { + const regex = new RegExp(schema.pattern); + if (!regex.test(value3)) { + yield Create(ValueErrorType.StringPattern, schema, path, value3); + } + } + if (IsString(schema.format)) { + if (!exports_format.Has(schema.format)) { + yield Create(ValueErrorType.StringFormatUnknown, schema, path, value3); + } else { + const format = exports_format.Get(schema.format); + if (!format(value3)) { + yield Create(ValueErrorType.StringFormat, schema, path, value3); + } + } + } +} +function* FromSymbol(schema, references, path, value3) { + if (!IsSymbol(value3)) + yield Create(ValueErrorType.Symbol, schema, path, value3); +} +function* FromTemplateLiteral2(schema, references, path, value3) { + if (!IsString(value3)) + return yield Create(ValueErrorType.String, schema, path, value3); + const regex = new RegExp(schema.pattern); + if (!regex.test(value3)) { + yield Create(ValueErrorType.StringPattern, schema, path, value3); + } +} +function* FromThis(schema, references, path, value3) { + yield* Visit4(Deref(schema, references), references, path, value3); +} +function* FromTuple3(schema, references, path, value3) { + if (!IsArray(value3)) + return yield Create(ValueErrorType.Tuple, schema, path, value3); + if (schema.items === undefined && !(value3.length === 0)) { + return yield Create(ValueErrorType.TupleLength, schema, path, value3); + } + if (!(value3.length === schema.maxItems)) { + return yield Create(ValueErrorType.TupleLength, schema, path, value3); + } + if (!schema.items) { + return; + } + for (let i = 0;i < schema.items.length; i++) { + yield* Visit4(schema.items[i], references, `${path}/${i}`, value3[i]); + } +} +function* FromUndefined(schema, references, path, value3) { + if (!IsUndefined(value3)) + yield Create(ValueErrorType.Undefined, schema, path, value3); +} +function* FromUnion5(schema, references, path, value3) { + let count = 0; + for (const subschema of schema.anyOf) { + const errors2 = [...Visit4(subschema, references, path, value3)]; + if (errors2.length === 0) + return; + count += errors2.length; + } + if (count > 0) { + yield Create(ValueErrorType.Union, schema, path, value3); + } +} +function* FromUint8Array(schema, references, path, value3) { + if (!IsUint8Array(value3)) + return yield Create(ValueErrorType.Uint8Array, schema, path, value3); + if (IsDefined(schema.maxByteLength) && !(value3.length <= schema.maxByteLength)) { + yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value3); + } + if (IsDefined(schema.minByteLength) && !(value3.length >= schema.minByteLength)) { + yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path, value3); + } +} +function* FromUnknown(schema, references, path, value3) { +} +function* FromVoid(schema, references, path, value3) { + if (!TypeSystemPolicy.IsVoidLike(value3)) + yield Create(ValueErrorType.Void, schema, path, value3); +} +function* FromKind(schema, references, path, value3) { + const check = exports_type.Get(schema[Kind]); + if (!check(schema, value3)) + yield Create(ValueErrorType.Kind, schema, path, value3); +} +function* Visit4(schema, references, path, value3) { + const references_ = IsDefined(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + switch (schema_[Kind]) { + case "Any": + return yield* FromAny(schema_, references_, path, value3); + case "Array": + return yield* FromArray3(schema_, references_, path, value3); + case "AsyncIterator": + return yield* FromAsyncIterator(schema_, references_, path, value3); + case "BigInt": + return yield* FromBigInt(schema_, references_, path, value3); + case "Boolean": + return yield* FromBoolean(schema_, references_, path, value3); + case "Constructor": + return yield* FromConstructor(schema_, references_, path, value3); + case "Date": + return yield* FromDate(schema_, references_, path, value3); + case "Function": + return yield* FromFunction(schema_, references_, path, value3); + case "Integer": + return yield* FromInteger(schema_, references_, path, value3); + case "Intersect": + return yield* FromIntersect3(schema_, references_, path, value3); + case "Iterator": + return yield* FromIterator(schema_, references_, path, value3); + case "Literal": + return yield* FromLiteral2(schema_, references_, path, value3); + case "Never": + return yield* FromNever(schema_, references_, path, value3); + case "Not": + return yield* FromNot(schema_, references_, path, value3); + case "Null": + return yield* FromNull(schema_, references_, path, value3); + case "Number": + return yield* FromNumber(schema_, references_, path, value3); + case "Object": + return yield* FromObject(schema_, references_, path, value3); + case "Promise": + return yield* FromPromise(schema_, references_, path, value3); + case "Record": + return yield* FromRecord(schema_, references_, path, value3); + case "Ref": + return yield* FromRef(schema_, references_, path, value3); + case "RegExp": + return yield* FromRegExp(schema_, references_, path, value3); + case "String": + return yield* FromString(schema_, references_, path, value3); + case "Symbol": + return yield* FromSymbol(schema_, references_, path, value3); + case "TemplateLiteral": + return yield* FromTemplateLiteral2(schema_, references_, path, value3); + case "This": + return yield* FromThis(schema_, references_, path, value3); + case "Tuple": + return yield* FromTuple3(schema_, references_, path, value3); + case "Undefined": + return yield* FromUndefined(schema_, references_, path, value3); + case "Union": + return yield* FromUnion5(schema_, references_, path, value3); + case "Uint8Array": + return yield* FromUint8Array(schema_, references_, path, value3); + case "Unknown": + return yield* FromUnknown(schema_, references_, path, value3); + case "Void": + return yield* FromVoid(schema_, references_, path, value3); + default: + if (!exports_type.Has(schema_[Kind])) + throw new ValueErrorsUnknownTypeError(schema); + return yield* FromKind(schema_, references_, path, value3); + } +} +function Errors(...args) { + const iterator3 = args.length === 3 ? Visit4(args[0], args[1], "", args[2]) : Visit4(args[0], [], "", args[1]); + return new ValueErrorIterator(iterator3); +} +var ValueErrorType; +(function(ValueErrorType2) { + ValueErrorType2[ValueErrorType2["ArrayContains"] = 0] = "ArrayContains"; + ValueErrorType2[ValueErrorType2["ArrayMaxContains"] = 1] = "ArrayMaxContains"; + ValueErrorType2[ValueErrorType2["ArrayMaxItems"] = 2] = "ArrayMaxItems"; + ValueErrorType2[ValueErrorType2["ArrayMinContains"] = 3] = "ArrayMinContains"; + ValueErrorType2[ValueErrorType2["ArrayMinItems"] = 4] = "ArrayMinItems"; + ValueErrorType2[ValueErrorType2["ArrayUniqueItems"] = 5] = "ArrayUniqueItems"; + ValueErrorType2[ValueErrorType2["Array"] = 6] = "Array"; + ValueErrorType2[ValueErrorType2["AsyncIterator"] = 7] = "AsyncIterator"; + ValueErrorType2[ValueErrorType2["BigIntExclusiveMaximum"] = 8] = "BigIntExclusiveMaximum"; + ValueErrorType2[ValueErrorType2["BigIntExclusiveMinimum"] = 9] = "BigIntExclusiveMinimum"; + ValueErrorType2[ValueErrorType2["BigIntMaximum"] = 10] = "BigIntMaximum"; + ValueErrorType2[ValueErrorType2["BigIntMinimum"] = 11] = "BigIntMinimum"; + ValueErrorType2[ValueErrorType2["BigIntMultipleOf"] = 12] = "BigIntMultipleOf"; + ValueErrorType2[ValueErrorType2["BigInt"] = 13] = "BigInt"; + ValueErrorType2[ValueErrorType2["Boolean"] = 14] = "Boolean"; + ValueErrorType2[ValueErrorType2["DateExclusiveMaximumTimestamp"] = 15] = "DateExclusiveMaximumTimestamp"; + ValueErrorType2[ValueErrorType2["DateExclusiveMinimumTimestamp"] = 16] = "DateExclusiveMinimumTimestamp"; + ValueErrorType2[ValueErrorType2["DateMaximumTimestamp"] = 17] = "DateMaximumTimestamp"; + ValueErrorType2[ValueErrorType2["DateMinimumTimestamp"] = 18] = "DateMinimumTimestamp"; + ValueErrorType2[ValueErrorType2["DateMultipleOfTimestamp"] = 19] = "DateMultipleOfTimestamp"; + ValueErrorType2[ValueErrorType2["Date"] = 20] = "Date"; + ValueErrorType2[ValueErrorType2["Function"] = 21] = "Function"; + ValueErrorType2[ValueErrorType2["IntegerExclusiveMaximum"] = 22] = "IntegerExclusiveMaximum"; + ValueErrorType2[ValueErrorType2["IntegerExclusiveMinimum"] = 23] = "IntegerExclusiveMinimum"; + ValueErrorType2[ValueErrorType2["IntegerMaximum"] = 24] = "IntegerMaximum"; + ValueErrorType2[ValueErrorType2["IntegerMinimum"] = 25] = "IntegerMinimum"; + ValueErrorType2[ValueErrorType2["IntegerMultipleOf"] = 26] = "IntegerMultipleOf"; + ValueErrorType2[ValueErrorType2["Integer"] = 27] = "Integer"; + ValueErrorType2[ValueErrorType2["IntersectUnevaluatedProperties"] = 28] = "IntersectUnevaluatedProperties"; + ValueErrorType2[ValueErrorType2["Intersect"] = 29] = "Intersect"; + ValueErrorType2[ValueErrorType2["Iterator"] = 30] = "Iterator"; + ValueErrorType2[ValueErrorType2["Kind"] = 31] = "Kind"; + ValueErrorType2[ValueErrorType2["Literal"] = 32] = "Literal"; + ValueErrorType2[ValueErrorType2["Never"] = 33] = "Never"; + ValueErrorType2[ValueErrorType2["Not"] = 34] = "Not"; + ValueErrorType2[ValueErrorType2["Null"] = 35] = "Null"; + ValueErrorType2[ValueErrorType2["NumberExclusiveMaximum"] = 36] = "NumberExclusiveMaximum"; + ValueErrorType2[ValueErrorType2["NumberExclusiveMinimum"] = 37] = "NumberExclusiveMinimum"; + ValueErrorType2[ValueErrorType2["NumberMaximum"] = 38] = "NumberMaximum"; + ValueErrorType2[ValueErrorType2["NumberMinimum"] = 39] = "NumberMinimum"; + ValueErrorType2[ValueErrorType2["NumberMultipleOf"] = 40] = "NumberMultipleOf"; + ValueErrorType2[ValueErrorType2["Number"] = 41] = "Number"; + ValueErrorType2[ValueErrorType2["ObjectAdditionalProperties"] = 42] = "ObjectAdditionalProperties"; + ValueErrorType2[ValueErrorType2["ObjectMaxProperties"] = 43] = "ObjectMaxProperties"; + ValueErrorType2[ValueErrorType2["ObjectMinProperties"] = 44] = "ObjectMinProperties"; + ValueErrorType2[ValueErrorType2["ObjectRequiredProperty"] = 45] = "ObjectRequiredProperty"; + ValueErrorType2[ValueErrorType2["Object"] = 46] = "Object"; + ValueErrorType2[ValueErrorType2["Promise"] = 47] = "Promise"; + ValueErrorType2[ValueErrorType2["RegExp"] = 48] = "RegExp"; + ValueErrorType2[ValueErrorType2["StringFormatUnknown"] = 49] = "StringFormatUnknown"; + ValueErrorType2[ValueErrorType2["StringFormat"] = 50] = "StringFormat"; + ValueErrorType2[ValueErrorType2["StringMaxLength"] = 51] = "StringMaxLength"; + ValueErrorType2[ValueErrorType2["StringMinLength"] = 52] = "StringMinLength"; + ValueErrorType2[ValueErrorType2["StringPattern"] = 53] = "StringPattern"; + ValueErrorType2[ValueErrorType2["String"] = 54] = "String"; + ValueErrorType2[ValueErrorType2["Symbol"] = 55] = "Symbol"; + ValueErrorType2[ValueErrorType2["TupleLength"] = 56] = "TupleLength"; + ValueErrorType2[ValueErrorType2["Tuple"] = 57] = "Tuple"; + ValueErrorType2[ValueErrorType2["Uint8ArrayMaxByteLength"] = 58] = "Uint8ArrayMaxByteLength"; + ValueErrorType2[ValueErrorType2["Uint8ArrayMinByteLength"] = 59] = "Uint8ArrayMinByteLength"; + ValueErrorType2[ValueErrorType2["Uint8Array"] = 60] = "Uint8Array"; + ValueErrorType2[ValueErrorType2["Undefined"] = 61] = "Undefined"; + ValueErrorType2[ValueErrorType2["Union"] = 62] = "Union"; + ValueErrorType2[ValueErrorType2["Void"] = 63] = "Void"; +})(ValueErrorType || (ValueErrorType = {})); + +class ValueErrorsUnknownTypeError extends TypeBoxError { + schema; + constructor(schema) { + super("Unknown type"); + this.schema = schema; + } +} + +class ValueErrorIterator { + iterator; + constructor(iterator3) { + this.iterator = iterator3; + } + [Symbol.iterator]() { + return this.iterator; + } + First() { + const next = this.iterator.next(); + return next.done ? undefined : next.value; + } +} +// node_modules/@sinclair/typebox/build/import/type/any/any.mjs +function Any(options = {}) { + return { ...options, [Kind]: "Any" }; +} +// node_modules/@sinclair/typebox/build/import/type/unknown/unknown.mjs +function Unknown(options = {}) { + return { + ...options, + [Kind]: "Unknown" + }; +} +// node_modules/@sinclair/typebox/build/import/type/extends/extends-check.mjs +var IntoBooleanResult = function(result) { + return result === ExtendsResult.False ? result : ExtendsResult.True; +}; +var Throw = function(message) { + throw new ExtendsResolverError(message); +}; +var IsStructuralRight = function(right) { + return exports_type2.IsNever(right) || exports_type2.IsIntersect(right) || exports_type2.IsUnion(right) || exports_type2.IsUnknown(right) || exports_type2.IsAny(right); +}; +var StructuralRight = function(left, right) { + return exports_type2.IsNever(right) ? FromNeverRight(left, right) : exports_type2.IsIntersect(right) ? FromIntersectRight(left, right) : exports_type2.IsUnion(right) ? FromUnionRight(left, right) : exports_type2.IsUnknown(right) ? FromUnknownRight(left, right) : exports_type2.IsAny(right) ? FromAnyRight(left, right) : Throw("StructuralRight"); +}; +var FromAnyRight = function(left, right) { + return ExtendsResult.True; +}; +var FromAny2 = function(left, right) { + return exports_type2.IsIntersect(right) ? FromIntersectRight(left, right) : exports_type2.IsUnion(right) && right.anyOf.some((schema) => exports_type2.IsAny(schema) || exports_type2.IsUnknown(schema)) ? ExtendsResult.True : exports_type2.IsUnion(right) ? ExtendsResult.Union : exports_type2.IsUnknown(right) ? ExtendsResult.True : exports_type2.IsAny(right) ? ExtendsResult.True : ExtendsResult.Union; +}; +var FromArrayRight = function(left, right) { + return exports_type2.IsUnknown(left) ? ExtendsResult.False : exports_type2.IsAny(left) ? ExtendsResult.Union : exports_type2.IsNever(left) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromArray4 = function(left, right) { + return exports_type2.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : !exports_type2.IsArray(right) ? ExtendsResult.False : IntoBooleanResult(Visit5(left.items, right.items)); +}; +var FromAsyncIterator2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : !exports_type2.IsAsyncIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit5(left.items, right.items)); +}; +var FromBigInt2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsBigInt(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromBooleanRight = function(left, right) { + return exports_type2.IsLiteralBoolean(left) ? ExtendsResult.True : exports_type2.IsBoolean(left) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromBoolean2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsBoolean(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromConstructor2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : !exports_type2.IsConstructor(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit5(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit5(left.returns, right.returns)); +}; +var FromDate2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsDate(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromFunction2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : !exports_type2.IsFunction(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit5(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit5(left.returns, right.returns)); +}; +var FromIntegerRight = function(left, right) { + return exports_type2.IsLiteral(left) && exports_value.IsNumber(left.const) ? ExtendsResult.True : exports_type2.IsNumber(left) || exports_type2.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromInteger2 = function(left, right) { + return exports_type2.IsInteger(right) || exports_type2.IsNumber(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : ExtendsResult.False; +}; +var FromIntersectRight = function(left, right) { + return right.allOf.every((schema) => Visit5(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromIntersect4 = function(left, right) { + return left.allOf.some((schema) => Visit5(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromIterator2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : !exports_type2.IsIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit5(left.items, right.items)); +}; +var FromLiteral3 = function(left, right) { + return exports_type2.IsLiteral(right) && right.const === left.const ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsString(right) ? FromStringRight(left, right) : exports_type2.IsNumber(right) ? FromNumberRight(left, right) : exports_type2.IsInteger(right) ? FromIntegerRight(left, right) : exports_type2.IsBoolean(right) ? FromBooleanRight(left, right) : ExtendsResult.False; +}; +var FromNeverRight = function(left, right) { + return ExtendsResult.False; +}; +var FromNever2 = function(left, right) { + return ExtendsResult.True; +}; +var UnwrapTNot = function(schema) { + let [current, depth] = [schema, 0]; + while (true) { + if (!exports_type2.IsNot(current)) + break; + current = current.not; + depth += 1; + } + return depth % 2 === 0 ? current : Unknown(); +}; +var FromNot2 = function(left, right) { + return exports_type2.IsNot(left) ? Visit5(UnwrapTNot(left), right) : exports_type2.IsNot(right) ? Visit5(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not"); +}; +var FromNull2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsNull(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromNumberRight = function(left, right) { + return exports_type2.IsLiteralNumber(left) ? ExtendsResult.True : exports_type2.IsNumber(left) || exports_type2.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromNumber2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsInteger(right) || exports_type2.IsNumber(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var IsObjectPropertyCount = function(schema, count) { + return Object.getOwnPropertyNames(schema.properties).length === count; +}; +var IsObjectStringLike = function(schema) { + return IsObjectArrayLike(schema); +}; +var IsObjectSymbolLike = function(schema) { + return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "description" in schema.properties && exports_type2.IsUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && (exports_type2.IsString(schema.properties.description.anyOf[0]) && exports_type2.IsUndefined(schema.properties.description.anyOf[1]) || exports_type2.IsString(schema.properties.description.anyOf[1]) && exports_type2.IsUndefined(schema.properties.description.anyOf[0])); +}; +var IsObjectNumberLike = function(schema) { + return IsObjectPropertyCount(schema, 0); +}; +var IsObjectBooleanLike = function(schema) { + return IsObjectPropertyCount(schema, 0); +}; +var IsObjectBigIntLike = function(schema) { + return IsObjectPropertyCount(schema, 0); +}; +var IsObjectDateLike = function(schema) { + return IsObjectPropertyCount(schema, 0); +}; +var IsObjectUint8ArrayLike = function(schema) { + return IsObjectArrayLike(schema); +}; +var IsObjectFunctionLike = function(schema) { + const length = Number2(); + return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit5(schema.properties["length"], length)) === ExtendsResult.True; +}; +var IsObjectConstructorLike = function(schema) { + return IsObjectPropertyCount(schema, 0); +}; +var IsObjectArrayLike = function(schema) { + const length = Number2(); + return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit5(schema.properties["length"], length)) === ExtendsResult.True; +}; +var IsObjectPromiseLike = function(schema) { + const then = Function2([Any()], Any()); + return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit5(schema.properties["then"], then)) === ExtendsResult.True; +}; +var Property = function(left, right) { + return Visit5(left, right) === ExtendsResult.False ? ExtendsResult.False : exports_type2.IsOptional(left) && !exports_type2.IsOptional(right) ? ExtendsResult.False : ExtendsResult.True; +}; +var FromObjectRight = function(left, right) { + return exports_type2.IsUnknown(left) ? ExtendsResult.False : exports_type2.IsAny(left) ? ExtendsResult.Union : exports_type2.IsNever(left) || exports_type2.IsLiteralString(left) && IsObjectStringLike(right) || exports_type2.IsLiteralNumber(left) && IsObjectNumberLike(right) || exports_type2.IsLiteralBoolean(left) && IsObjectBooleanLike(right) || exports_type2.IsSymbol(left) && IsObjectSymbolLike(right) || exports_type2.IsBigInt(left) && IsObjectBigIntLike(right) || exports_type2.IsString(left) && IsObjectStringLike(right) || exports_type2.IsSymbol(left) && IsObjectSymbolLike(right) || exports_type2.IsNumber(left) && IsObjectNumberLike(right) || exports_type2.IsInteger(left) && IsObjectNumberLike(right) || exports_type2.IsBoolean(left) && IsObjectBooleanLike(right) || exports_type2.IsUint8Array(left) && IsObjectUint8ArrayLike(right) || exports_type2.IsDate(left) && IsObjectDateLike(right) || exports_type2.IsConstructor(left) && IsObjectConstructorLike(right) || exports_type2.IsFunction(left) && IsObjectFunctionLike(right) ? ExtendsResult.True : exports_type2.IsRecord(left) && exports_type2.IsString(RecordKey(left)) ? (() => { + return right[Hint] === "Record" ? ExtendsResult.True : ExtendsResult.False; + })() : exports_type2.IsRecord(left) && exports_type2.IsNumber(RecordKey(left)) ? (() => { + return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False; + })() : ExtendsResult.False; +}; +var FromObject2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : !exports_type2.IsObject(right) ? ExtendsResult.False : (() => { + for (const key of Object.getOwnPropertyNames(right.properties)) { + if (!(key in left.properties) && !exports_type2.IsOptional(right.properties[key])) { + return ExtendsResult.False; + } + if (exports_type2.IsOptional(right.properties[key])) { + return ExtendsResult.True; + } + if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) { + return ExtendsResult.False; + } + } + return ExtendsResult.True; + })(); +}; +var FromPromise2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True : !exports_type2.IsPromise(right) ? ExtendsResult.False : IntoBooleanResult(Visit5(left.item, right.item)); +}; +var RecordKey = function(schema) { + return PatternNumberExact in schema.patternProperties ? Number2() : (PatternStringExact in schema.patternProperties) ? String2() : Throw("Unknown record key pattern"); +}; +var RecordValue = function(schema) { + return PatternNumberExact in schema.patternProperties ? schema.patternProperties[PatternNumberExact] : (PatternStringExact in schema.patternProperties) ? schema.patternProperties[PatternStringExact] : Throw("Unable to get record value schema"); +}; +var FromRecordRight = function(left, right) { + const [Key, Value] = [RecordKey(right), RecordValue(right)]; + return exports_type2.IsLiteralString(left) && exports_type2.IsNumber(Key) && IntoBooleanResult(Visit5(left, Value)) === ExtendsResult.True ? ExtendsResult.True : exports_type2.IsUint8Array(left) && exports_type2.IsNumber(Key) ? Visit5(left, Value) : exports_type2.IsString(left) && exports_type2.IsNumber(Key) ? Visit5(left, Value) : exports_type2.IsArray(left) && exports_type2.IsNumber(Key) ? Visit5(left, Value) : exports_type2.IsObject(left) ? (() => { + for (const key of Object.getOwnPropertyNames(left.properties)) { + if (Property(Value, left.properties[key]) === ExtendsResult.False) { + return ExtendsResult.False; + } + } + return ExtendsResult.True; + })() : ExtendsResult.False; +}; +var FromRecord2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : !exports_type2.IsRecord(right) ? ExtendsResult.False : Visit5(RecordValue(left), RecordValue(right)); +}; +var FromRegExp2 = function(left, right) { + const L = exports_type2.IsRegExp(left) ? String2() : left; + const R = exports_type2.IsRegExp(right) ? String2() : right; + return Visit5(L, R); +}; +var FromStringRight = function(left, right) { + return exports_type2.IsLiteral(left) && exports_value.IsString(left.const) ? ExtendsResult.True : exports_type2.IsString(left) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromString2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsString(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromSymbol2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsSymbol(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromTemplateLiteral3 = function(left, right) { + return exports_type2.IsTemplateLiteral(left) ? Visit5(TemplateLiteralToUnion(left), right) : exports_type2.IsTemplateLiteral(right) ? Visit5(left, TemplateLiteralToUnion(right)) : Throw("Invalid fallthrough for TemplateLiteral"); +}; +var IsArrayOfTuple = function(left, right) { + return exports_type2.IsArray(right) && left.items !== undefined && left.items.every((schema) => Visit5(schema, right.items) === ExtendsResult.True); +}; +var FromTupleRight = function(left, right) { + return exports_type2.IsNever(left) ? ExtendsResult.True : exports_type2.IsUnknown(left) ? ExtendsResult.False : exports_type2.IsAny(left) ? ExtendsResult.Union : ExtendsResult.False; +}; +var FromTuple4 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : exports_type2.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True : !exports_type2.IsTuple(right) ? ExtendsResult.False : exports_value.IsUndefined(left.items) && !exports_value.IsUndefined(right.items) || !exports_value.IsUndefined(left.items) && exports_value.IsUndefined(right.items) ? ExtendsResult.False : exports_value.IsUndefined(left.items) && !exports_value.IsUndefined(right.items) ? ExtendsResult.True : left.items.every((schema, index) => Visit5(schema, right.items[index]) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromUint8Array2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsUint8Array(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromUndefined2 = function(left, right) { + return IsStructuralRight(right) ? StructuralRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsRecord(right) ? FromRecordRight(left, right) : exports_type2.IsVoid(right) ? FromVoidRight(left, right) : exports_type2.IsUndefined(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromUnionRight = function(left, right) { + return right.anyOf.some((schema) => Visit5(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromUnion6 = function(left, right) { + return left.anyOf.every((schema) => Visit5(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromUnknownRight = function(left, right) { + return ExtendsResult.True; +}; +var FromUnknown2 = function(left, right) { + return exports_type2.IsNever(right) ? FromNeverRight(left, right) : exports_type2.IsIntersect(right) ? FromIntersectRight(left, right) : exports_type2.IsUnion(right) ? FromUnionRight(left, right) : exports_type2.IsAny(right) ? FromAnyRight(left, right) : exports_type2.IsString(right) ? FromStringRight(left, right) : exports_type2.IsNumber(right) ? FromNumberRight(left, right) : exports_type2.IsInteger(right) ? FromIntegerRight(left, right) : exports_type2.IsBoolean(right) ? FromBooleanRight(left, right) : exports_type2.IsArray(right) ? FromArrayRight(left, right) : exports_type2.IsTuple(right) ? FromTupleRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsUnknown(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromVoidRight = function(left, right) { + return exports_type2.IsUndefined(left) ? ExtendsResult.True : exports_type2.IsUndefined(left) ? ExtendsResult.True : ExtendsResult.False; +}; +var FromVoid2 = function(left, right) { + return exports_type2.IsIntersect(right) ? FromIntersectRight(left, right) : exports_type2.IsUnion(right) ? FromUnionRight(left, right) : exports_type2.IsUnknown(right) ? FromUnknownRight(left, right) : exports_type2.IsAny(right) ? FromAnyRight(left, right) : exports_type2.IsObject(right) ? FromObjectRight(left, right) : exports_type2.IsVoid(right) ? ExtendsResult.True : ExtendsResult.False; +}; +var Visit5 = function(left, right) { + return exports_type2.IsTemplateLiteral(left) || exports_type2.IsTemplateLiteral(right) ? FromTemplateLiteral3(left, right) : exports_type2.IsRegExp(left) || exports_type2.IsRegExp(right) ? FromRegExp2(left, right) : exports_type2.IsNot(left) || exports_type2.IsNot(right) ? FromNot2(left, right) : exports_type2.IsAny(left) ? FromAny2(left, right) : exports_type2.IsArray(left) ? FromArray4(left, right) : exports_type2.IsBigInt(left) ? FromBigInt2(left, right) : exports_type2.IsBoolean(left) ? FromBoolean2(left, right) : exports_type2.IsAsyncIterator(left) ? FromAsyncIterator2(left, right) : exports_type2.IsConstructor(left) ? FromConstructor2(left, right) : exports_type2.IsDate(left) ? FromDate2(left, right) : exports_type2.IsFunction(left) ? FromFunction2(left, right) : exports_type2.IsInteger(left) ? FromInteger2(left, right) : exports_type2.IsIntersect(left) ? FromIntersect4(left, right) : exports_type2.IsIterator(left) ? FromIterator2(left, right) : exports_type2.IsLiteral(left) ? FromLiteral3(left, right) : exports_type2.IsNever(left) ? FromNever2(left, right) : exports_type2.IsNull(left) ? FromNull2(left, right) : exports_type2.IsNumber(left) ? FromNumber2(left, right) : exports_type2.IsObject(left) ? FromObject2(left, right) : exports_type2.IsRecord(left) ? FromRecord2(left, right) : exports_type2.IsString(left) ? FromString2(left, right) : exports_type2.IsSymbol(left) ? FromSymbol2(left, right) : exports_type2.IsTuple(left) ? FromTuple4(left, right) : exports_type2.IsPromise(left) ? FromPromise2(left, right) : exports_type2.IsUint8Array(left) ? FromUint8Array2(left, right) : exports_type2.IsUndefined(left) ? FromUndefined2(left, right) : exports_type2.IsUnion(left) ? FromUnion6(left, right) : exports_type2.IsUnknown(left) ? FromUnknown2(left, right) : exports_type2.IsVoid(left) ? FromVoid2(left, right) : Throw(`Unknown left type operand '${left[Kind]}'`); +}; +function ExtendsCheck(left, right) { + return Visit5(left, right); +} + +class ExtendsResolverError extends TypeBoxError { +} +var ExtendsResult; +(function(ExtendsResult2) { + ExtendsResult2[ExtendsResult2["Union"] = 0] = "Union"; + ExtendsResult2[ExtendsResult2["True"] = 1] = "True"; + ExtendsResult2[ExtendsResult2["False"] = 2] = "False"; +})(ExtendsResult || (ExtendsResult = {})); +// node_modules/@sinclair/typebox/build/import/type/extends/extends-from-mapped-result.mjs +var FromProperties7 = function(P, Right, True, False, options) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Extends(P[K2], Right, True, False, options) }; + }, {}); +}; +var FromMappedResult6 = function(Left, Right, True, False, options) { + return FromProperties7(Left.properties, Right, True, False, options); +}; +function ExtendsFromMappedResult(Left, Right, True, False, options) { + const P = FromMappedResult6(Left, Right, True, False, options); + return MappedResult(P); +} + +// node_modules/@sinclair/typebox/build/import/type/extends/extends.mjs +var ExtendsResolve = function(left, right, trueType, falseType) { + const R = ExtendsCheck(left, right); + return R === ExtendsResult.Union ? Union([trueType, falseType]) : R === ExtendsResult.True ? trueType : falseType; +}; +function Extends(L, R, T, F, options = {}) { + return IsMappedResult(L) ? ExtendsFromMappedResult(L, R, T, F, options) : IsMappedKey(L) ? CloneType(ExtendsFromMappedKey(L, R, T, F, options)) : CloneType(ExtendsResolve(L, R, T, F), options); +} + +// node_modules/@sinclair/typebox/build/import/type/extends/extends-from-mapped-key.mjs +var FromPropertyKey = function(K, U, L, R, options) { + return { + [K]: Extends(Literal(K), U, L, R, options) + }; +}; +var FromPropertyKeys = function(K, U, L, R, options) { + return K.reduce((Acc, LK) => { + return { ...Acc, ...FromPropertyKey(LK, U, L, R, options) }; + }, {}); +}; +var FromMappedKey2 = function(K, U, L, R, options) { + return FromPropertyKeys(K.keys, U, L, R, options); +}; +function ExtendsFromMappedKey(T, U, L, R, options) { + const P = FromMappedKey2(T, U, L, R, options); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/value/check/check.mjs +var IsAnyOrUnknown = function(schema) { + return schema[Kind] === "Any" || schema[Kind] === "Unknown"; +}; +var IsDefined2 = function(value3) { + return value3 !== undefined; +}; +var FromAny3 = function(schema, references, value3) { + return true; +}; +var FromArray5 = function(schema, references, value3) { + if (!IsArray(value3)) + return false; + if (IsDefined2(schema.minItems) && !(value3.length >= schema.minItems)) { + return false; + } + if (IsDefined2(schema.maxItems) && !(value3.length <= schema.maxItems)) { + return false; + } + if (!value3.every((value4) => Visit6(schema.items, references, value4))) { + return false; + } + if (schema.uniqueItems === true && !function() { + const set2 = new Set; + for (const element of value3) { + const hashed = Hash(element); + if (set2.has(hashed)) { + return false; + } else { + set2.add(hashed); + } + } + return true; + }()) { + return false; + } + if (!(IsDefined2(schema.contains) || IsNumber(schema.minContains) || IsNumber(schema.maxContains))) { + return true; + } + const containsSchema = IsDefined2(schema.contains) ? schema.contains : Never(); + const containsCount = value3.reduce((acc, value4) => Visit6(containsSchema, references, value4) ? acc + 1 : acc, 0); + if (containsCount === 0) { + return false; + } + if (IsNumber(schema.minContains) && containsCount < schema.minContains) { + return false; + } + if (IsNumber(schema.maxContains) && containsCount > schema.maxContains) { + return false; + } + return true; +}; +var FromAsyncIterator3 = function(schema, references, value3) { + return IsAsyncIterator(value3); +}; +var FromBigInt3 = function(schema, references, value3) { + if (!IsBigInt(value3)) + return false; + if (IsDefined2(schema.exclusiveMaximum) && !(value3 < schema.exclusiveMaximum)) { + return false; + } + if (IsDefined2(schema.exclusiveMinimum) && !(value3 > schema.exclusiveMinimum)) { + return false; + } + if (IsDefined2(schema.maximum) && !(value3 <= schema.maximum)) { + return false; + } + if (IsDefined2(schema.minimum) && !(value3 >= schema.minimum)) { + return false; + } + if (IsDefined2(schema.multipleOf) && !(value3 % schema.multipleOf === BigInt(0))) { + return false; + } + return true; +}; +var FromBoolean3 = function(schema, references, value3) { + return IsBoolean(value3); +}; +var FromConstructor3 = function(schema, references, value3) { + return Visit6(schema.returns, references, value3.prototype); +}; +var FromDate3 = function(schema, references, value3) { + if (!IsDate(value3)) + return false; + if (IsDefined2(schema.exclusiveMaximumTimestamp) && !(value3.getTime() < schema.exclusiveMaximumTimestamp)) { + return false; + } + if (IsDefined2(schema.exclusiveMinimumTimestamp) && !(value3.getTime() > schema.exclusiveMinimumTimestamp)) { + return false; + } + if (IsDefined2(schema.maximumTimestamp) && !(value3.getTime() <= schema.maximumTimestamp)) { + return false; + } + if (IsDefined2(schema.minimumTimestamp) && !(value3.getTime() >= schema.minimumTimestamp)) { + return false; + } + if (IsDefined2(schema.multipleOfTimestamp) && !(value3.getTime() % schema.multipleOfTimestamp === 0)) { + return false; + } + return true; +}; +var FromFunction3 = function(schema, references, value3) { + return IsFunction(value3); +}; +var FromInteger3 = function(schema, references, value3) { + if (!IsInteger(value3)) { + return false; + } + if (IsDefined2(schema.exclusiveMaximum) && !(value3 < schema.exclusiveMaximum)) { + return false; + } + if (IsDefined2(schema.exclusiveMinimum) && !(value3 > schema.exclusiveMinimum)) { + return false; + } + if (IsDefined2(schema.maximum) && !(value3 <= schema.maximum)) { + return false; + } + if (IsDefined2(schema.minimum) && !(value3 >= schema.minimum)) { + return false; + } + if (IsDefined2(schema.multipleOf) && !(value3 % schema.multipleOf === 0)) { + return false; + } + return true; +}; +var FromIntersect5 = function(schema, references, value3) { + const check1 = schema.allOf.every((schema2) => Visit6(schema2, references, value3)); + if (schema.unevaluatedProperties === false) { + const keyPattern = new RegExp(KeyOfPattern(schema)); + const check2 = Object.getOwnPropertyNames(value3).every((key) => keyPattern.test(key)); + return check1 && check2; + } else if (IsSchema(schema.unevaluatedProperties)) { + const keyCheck = new RegExp(KeyOfPattern(schema)); + const check2 = Object.getOwnPropertyNames(value3).every((key) => keyCheck.test(key) || Visit6(schema.unevaluatedProperties, references, value3[key])); + return check1 && check2; + } else { + return check1; + } +}; +var FromIterator3 = function(schema, references, value3) { + return IsIterator(value3); +}; +var FromLiteral4 = function(schema, references, value3) { + return value3 === schema.const; +}; +var FromNever3 = function(schema, references, value3) { + return false; +}; +var FromNot3 = function(schema, references, value3) { + return !Visit6(schema.not, references, value3); +}; +var FromNull3 = function(schema, references, value3) { + return IsNull(value3); +}; +var FromNumber3 = function(schema, references, value3) { + if (!TypeSystemPolicy.IsNumberLike(value3)) + return false; + if (IsDefined2(schema.exclusiveMaximum) && !(value3 < schema.exclusiveMaximum)) { + return false; + } + if (IsDefined2(schema.exclusiveMinimum) && !(value3 > schema.exclusiveMinimum)) { + return false; + } + if (IsDefined2(schema.minimum) && !(value3 >= schema.minimum)) { + return false; + } + if (IsDefined2(schema.maximum) && !(value3 <= schema.maximum)) { + return false; + } + if (IsDefined2(schema.multipleOf) && !(value3 % schema.multipleOf === 0)) { + return false; + } + return true; +}; +var FromObject3 = function(schema, references, value3) { + if (!TypeSystemPolicy.IsObjectLike(value3)) + return false; + if (IsDefined2(schema.minProperties) && !(Object.getOwnPropertyNames(value3).length >= schema.minProperties)) { + return false; + } + if (IsDefined2(schema.maxProperties) && !(Object.getOwnPropertyNames(value3).length <= schema.maxProperties)) { + return false; + } + const knownKeys = Object.getOwnPropertyNames(schema.properties); + for (const knownKey of knownKeys) { + const property = schema.properties[knownKey]; + if (schema.required && schema.required.includes(knownKey)) { + if (!Visit6(property, references, value3[knownKey])) { + return false; + } + if ((ExtendsUndefinedCheck(property) || IsAnyOrUnknown(property)) && !(knownKey in value3)) { + return false; + } + } else { + if (TypeSystemPolicy.IsExactOptionalProperty(value3, knownKey) && !Visit6(property, references, value3[knownKey])) { + return false; + } + } + } + if (schema.additionalProperties === false) { + const valueKeys = Object.getOwnPropertyNames(value3); + if (schema.required && schema.required.length === knownKeys.length && valueKeys.length === knownKeys.length) { + return true; + } else { + return valueKeys.every((valueKey) => knownKeys.includes(valueKey)); + } + } else if (typeof schema.additionalProperties === "object") { + const valueKeys = Object.getOwnPropertyNames(value3); + return valueKeys.every((key) => knownKeys.includes(key) || Visit6(schema.additionalProperties, references, value3[key])); + } else { + return true; + } +}; +var FromPromise3 = function(schema, references, value3) { + return IsPromise(value3); +}; +var FromRecord3 = function(schema, references, value3) { + if (!TypeSystemPolicy.IsRecordLike(value3)) { + return false; + } + if (IsDefined2(schema.minProperties) && !(Object.getOwnPropertyNames(value3).length >= schema.minProperties)) { + return false; + } + if (IsDefined2(schema.maxProperties) && !(Object.getOwnPropertyNames(value3).length <= schema.maxProperties)) { + return false; + } + const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0]; + const regex = new RegExp(patternKey); + const check1 = Object.entries(value3).every(([key, value4]) => { + return regex.test(key) ? Visit6(patternSchema, references, value4) : true; + }); + const check2 = typeof schema.additionalProperties === "object" ? Object.entries(value3).every(([key, value4]) => { + return !regex.test(key) ? Visit6(schema.additionalProperties, references, value4) : true; + }) : true; + const check3 = schema.additionalProperties === false ? Object.getOwnPropertyNames(value3).every((key) => { + return regex.test(key); + }) : true; + return check1 && check2 && check3; +}; +var FromRef2 = function(schema, references, value3) { + return Visit6(Deref(schema, references), references, value3); +}; +var FromRegExp3 = function(schema, references, value3) { + const regex = new RegExp(schema.source, schema.flags); + if (IsDefined2(schema.minLength)) { + if (!(value3.length >= schema.minLength)) + return false; + } + if (IsDefined2(schema.maxLength)) { + if (!(value3.length <= schema.maxLength)) + return false; + } + return regex.test(value3); +}; +var FromString3 = function(schema, references, value3) { + if (!IsString(value3)) { + return false; + } + if (IsDefined2(schema.minLength)) { + if (!(value3.length >= schema.minLength)) + return false; + } + if (IsDefined2(schema.maxLength)) { + if (!(value3.length <= schema.maxLength)) + return false; + } + if (IsDefined2(schema.pattern)) { + const regex = new RegExp(schema.pattern); + if (!regex.test(value3)) + return false; + } + if (IsDefined2(schema.format)) { + if (!exports_format.Has(schema.format)) + return false; + const func = exports_format.Get(schema.format); + return func(value3); + } + return true; +}; +var FromSymbol3 = function(schema, references, value3) { + return IsSymbol(value3); +}; +var FromTemplateLiteral4 = function(schema, references, value3) { + return IsString(value3) && new RegExp(schema.pattern).test(value3); +}; +var FromThis2 = function(schema, references, value3) { + return Visit6(Deref(schema, references), references, value3); +}; +var FromTuple5 = function(schema, references, value3) { + if (!IsArray(value3)) { + return false; + } + if (schema.items === undefined && !(value3.length === 0)) { + return false; + } + if (!(value3.length === schema.maxItems)) { + return false; + } + if (!schema.items) { + return true; + } + for (let i = 0;i < schema.items.length; i++) { + if (!Visit6(schema.items[i], references, value3[i])) + return false; + } + return true; +}; +var FromUndefined3 = function(schema, references, value3) { + return IsUndefined(value3); +}; +var FromUnion7 = function(schema, references, value3) { + return schema.anyOf.some((inner) => Visit6(inner, references, value3)); +}; +var FromUint8Array3 = function(schema, references, value3) { + if (!IsUint8Array(value3)) { + return false; + } + if (IsDefined2(schema.maxByteLength) && !(value3.length <= schema.maxByteLength)) { + return false; + } + if (IsDefined2(schema.minByteLength) && !(value3.length >= schema.minByteLength)) { + return false; + } + return true; +}; +var FromUnknown3 = function(schema, references, value3) { + return true; +}; +var FromVoid3 = function(schema, references, value3) { + return TypeSystemPolicy.IsVoidLike(value3); +}; +var FromKind2 = function(schema, references, value3) { + if (!exports_type.Has(schema[Kind])) + return false; + const func = exports_type.Get(schema[Kind]); + return func(schema, value3); +}; +var Visit6 = function(schema, references, value3) { + const references_ = IsDefined2(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + switch (schema_[Kind]) { + case "Any": + return FromAny3(schema_, references_, value3); + case "Array": + return FromArray5(schema_, references_, value3); + case "AsyncIterator": + return FromAsyncIterator3(schema_, references_, value3); + case "BigInt": + return FromBigInt3(schema_, references_, value3); + case "Boolean": + return FromBoolean3(schema_, references_, value3); + case "Constructor": + return FromConstructor3(schema_, references_, value3); + case "Date": + return FromDate3(schema_, references_, value3); + case "Function": + return FromFunction3(schema_, references_, value3); + case "Integer": + return FromInteger3(schema_, references_, value3); + case "Intersect": + return FromIntersect5(schema_, references_, value3); + case "Iterator": + return FromIterator3(schema_, references_, value3); + case "Literal": + return FromLiteral4(schema_, references_, value3); + case "Never": + return FromNever3(schema_, references_, value3); + case "Not": + return FromNot3(schema_, references_, value3); + case "Null": + return FromNull3(schema_, references_, value3); + case "Number": + return FromNumber3(schema_, references_, value3); + case "Object": + return FromObject3(schema_, references_, value3); + case "Promise": + return FromPromise3(schema_, references_, value3); + case "Record": + return FromRecord3(schema_, references_, value3); + case "Ref": + return FromRef2(schema_, references_, value3); + case "RegExp": + return FromRegExp3(schema_, references_, value3); + case "String": + return FromString3(schema_, references_, value3); + case "Symbol": + return FromSymbol3(schema_, references_, value3); + case "TemplateLiteral": + return FromTemplateLiteral4(schema_, references_, value3); + case "This": + return FromThis2(schema_, references_, value3); + case "Tuple": + return FromTuple5(schema_, references_, value3); + case "Undefined": + return FromUndefined3(schema_, references_, value3); + case "Union": + return FromUnion7(schema_, references_, value3); + case "Uint8Array": + return FromUint8Array3(schema_, references_, value3); + case "Unknown": + return FromUnknown3(schema_, references_, value3); + case "Void": + return FromVoid3(schema_, references_, value3); + default: + if (!exports_type.Has(schema_[Kind])) + throw new ValueCheckUnknownTypeError(schema_); + return FromKind2(schema_, references_, value3); + } +}; +function Check(...args) { + return args.length === 3 ? Visit6(args[0], args[1], args[2]) : Visit6(args[0], [], args[1]); +} + +class ValueCheckUnknownTypeError extends TypeBoxError { + schema; + constructor(schema) { + super(`Unknown type`); + this.schema = schema; + } +} +// node_modules/@sinclair/typebox/build/import/value/clone/clone.mjs +var ObjectType3 = function(value3) { + const keys = [...Object.getOwnPropertyNames(value3), ...Object.getOwnPropertySymbols(value3)]; + return keys.reduce((acc, key) => ({ ...acc, [key]: Clone2(value3[key]) }), {}); +}; +var ArrayType3 = function(value3) { + return value3.map((element) => Clone2(element)); +}; +var TypedArrayType = function(value3) { + return value3.slice(); +}; +var DateType3 = function(value3) { + return new Date(value3.toISOString()); +}; +var ValueType = function(value3) { + return value3; +}; +function Clone2(value3) { + if (IsArray(value3)) + return ArrayType3(value3); + if (IsDate(value3)) + return DateType3(value3); + if (IsStandardObject(value3)) + return ObjectType3(value3); + if (IsTypedArray(value3)) + return TypedArrayType(value3); + if (IsValueType(value3)) + return ValueType(value3); + throw new Error("ValueClone: Unable to clone value"); +} +// node_modules/@sinclair/typebox/build/import/value/create/create.mjs +var FromDefault = function(value3) { + return typeof value3 === "function" ? value3 : Clone2(value3); +}; +var FromAny4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return {}; + } +}; +var FromArray6 = function(schema, references) { + if (schema.uniqueItems === true && !HasPropertyKey(schema, "default")) { + throw new ValueCreateError(schema, "Array with the uniqueItems constraint requires a default value"); + } else if ("contains" in schema && !HasPropertyKey(schema, "default")) { + throw new ValueCreateError(schema, "Array with the contains constraint requires a default value"); + } else if ("default" in schema) { + return FromDefault(schema.default); + } else if (schema.minItems !== undefined) { + return Array.from({ length: schema.minItems }).map((item) => { + return Visit7(schema.items, references); + }); + } else { + return []; + } +}; +var FromAsyncIterator4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return async function* () { + }(); + } +}; +var FromBigInt4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return BigInt(0); + } +}; +var FromBoolean4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return false; + } +}; +var FromConstructor4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + const value3 = Visit7(schema.returns, references); + if (typeof value3 === "object" && !Array.isArray(value3)) { + return class { + constructor() { + for (const [key, val] of Object.entries(value3)) { + const self = this; + self[key] = val; + } + } + }; + } else { + return class { + }; + } + } +}; +var FromDate4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if (schema.minimumTimestamp !== undefined) { + return new Date(schema.minimumTimestamp); + } else { + return new Date; + } +}; +var FromFunction4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return () => Visit7(schema.returns, references); + } +}; +var FromInteger4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if (schema.minimum !== undefined) { + return schema.minimum; + } else { + return 0; + } +}; +var FromIntersect6 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + const value3 = schema.allOf.reduce((acc, schema2) => { + const next = Visit7(schema2, references); + return typeof next === "object" ? { ...acc, ...next } : next; + }, {}); + if (!Check(schema, references, value3)) + throw new ValueCreateError(schema, "Intersect produced invalid value. Consider using a default value."); + return value3; + } +}; +var FromIterator4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return function* () { + }(); + } +}; +var FromLiteral5 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return schema.const; + } +}; +var FromNever4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + throw new ValueCreateError(schema, "Never types cannot be created. Consider using a default value."); + } +}; +var FromNot4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + throw new ValueCreateError(schema, "Not types must have a default value"); + } +}; +var FromNull4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return null; + } +}; +var FromNumber4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if (schema.minimum !== undefined) { + return schema.minimum; + } else { + return 0; + } +}; +var FromObject4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + const required = new Set(schema.required); + return FromDefault(schema.default) || Object.entries(schema.properties).reduce((acc, [key, schema2]) => { + return required.has(key) ? { ...acc, [key]: Visit7(schema2, references) } : { ...acc }; + }, {}); + } +}; +var FromPromise4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return Promise.resolve(Visit7(schema.item, references)); + } +}; +var FromRecord4 = function(schema, references) { + const [keyPattern, valueSchema] = Object.entries(schema.patternProperties)[0]; + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if (!(keyPattern === PatternStringExact || keyPattern === PatternNumberExact)) { + const propertyKeys = keyPattern.slice(1, keyPattern.length - 1).split("|"); + return propertyKeys.reduce((acc, key) => { + return { ...acc, [key]: Visit7(valueSchema, references) }; + }, {}); + } else { + return {}; + } +}; +var FromRef3 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return Visit7(Deref(schema, references), references); + } +}; +var FromRegExp4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + throw new ValueCreateError(schema, "RegExp types cannot be created. Consider using a default value."); + } +}; +var FromString4 = function(schema, references) { + if (schema.pattern !== undefined) { + if (!HasPropertyKey(schema, "default")) { + throw new ValueCreateError(schema, "String types with patterns must specify a default value"); + } else { + return FromDefault(schema.default); + } + } else if (schema.format !== undefined) { + if (!HasPropertyKey(schema, "default")) { + throw new ValueCreateError(schema, "String types with formats must specify a default value"); + } else { + return FromDefault(schema.default); + } + } else { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if (schema.minLength !== undefined) { + return Array.from({ length: schema.minLength }).map(() => " ").join(""); + } else { + return ""; + } + } +}; +var FromSymbol4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if ("value" in schema) { + return Symbol.for(schema.value); + } else { + return Symbol(); + } +}; +var FromTemplateLiteral5 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } + if (!IsTemplateLiteralFinite(schema)) + throw new ValueCreateError(schema, "Can only create template literals that produce a finite variants. Consider using a default value."); + const generated = TemplateLiteralGenerate(schema); + return generated[0]; +}; +var FromThis3 = function(schema, references) { + if (recursiveDepth++ > recursiveMaxDepth) + throw new ValueCreateError(schema, "Cannot create recursive type as it appears possibly infinite. Consider using a default."); + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return Visit7(Deref(schema, references), references); + } +}; +var FromTuple6 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } + if (schema.items === undefined) { + return []; + } else { + return Array.from({ length: schema.minItems }).map((_, index) => Visit7(schema.items[index], references)); + } +}; +var FromUndefined4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return; + } +}; +var FromUnion8 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if (schema.anyOf.length === 0) { + throw new Error("ValueCreate.Union: Cannot create Union with zero variants"); + } else { + return Visit7(schema.anyOf[0], references); + } +}; +var FromUint8Array4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else if (schema.minByteLength !== undefined) { + return new Uint8Array(schema.minByteLength); + } else { + return new Uint8Array(0); + } +}; +var FromUnknown4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return {}; + } +}; +var FromVoid4 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + return; + } +}; +var FromKind3 = function(schema, references) { + if (HasPropertyKey(schema, "default")) { + return FromDefault(schema.default); + } else { + throw new Error("User defined types must specify a default value"); + } +}; +var Visit7 = function(schema, references) { + const references_ = IsString(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + switch (schema_[Kind]) { + case "Any": + return FromAny4(schema_, references_); + case "Array": + return FromArray6(schema_, references_); + case "AsyncIterator": + return FromAsyncIterator4(schema_, references_); + case "BigInt": + return FromBigInt4(schema_, references_); + case "Boolean": + return FromBoolean4(schema_, references_); + case "Constructor": + return FromConstructor4(schema_, references_); + case "Date": + return FromDate4(schema_, references_); + case "Function": + return FromFunction4(schema_, references_); + case "Integer": + return FromInteger4(schema_, references_); + case "Intersect": + return FromIntersect6(schema_, references_); + case "Iterator": + return FromIterator4(schema_, references_); + case "Literal": + return FromLiteral5(schema_, references_); + case "Never": + return FromNever4(schema_, references_); + case "Not": + return FromNot4(schema_, references_); + case "Null": + return FromNull4(schema_, references_); + case "Number": + return FromNumber4(schema_, references_); + case "Object": + return FromObject4(schema_, references_); + case "Promise": + return FromPromise4(schema_, references_); + case "Record": + return FromRecord4(schema_, references_); + case "Ref": + return FromRef3(schema_, references_); + case "RegExp": + return FromRegExp4(schema_, references_); + case "String": + return FromString4(schema_, references_); + case "Symbol": + return FromSymbol4(schema_, references_); + case "TemplateLiteral": + return FromTemplateLiteral5(schema_, references_); + case "This": + return FromThis3(schema_, references_); + case "Tuple": + return FromTuple6(schema_, references_); + case "Undefined": + return FromUndefined4(schema_, references_); + case "Union": + return FromUnion8(schema_, references_); + case "Uint8Array": + return FromUint8Array4(schema_, references_); + case "Unknown": + return FromUnknown4(schema_, references_); + case "Void": + return FromVoid4(schema_, references_); + default: + if (!exports_type.Has(schema_[Kind])) + throw new ValueCreateError(schema_, "Unknown type"); + return FromKind3(schema_, references_); + } +}; +function Create2(...args) { + recursiveDepth = 0; + return args.length === 2 ? Visit7(args[0], args[1]) : Visit7(args[0], []); +} + +class ValueCreateError extends TypeBoxError { + schema; + constructor(schema, message) { + super(message); + this.schema = schema; + } +} +var recursiveMaxDepth = 512; +var recursiveDepth = 0; +// node_modules/@sinclair/typebox/build/import/value/cast/cast.mjs +var ScoreUnion = function(schema, references, value3) { + if (schema[Kind] === "Object" && typeof value3 === "object" && !IsNull(value3)) { + const object3 = schema; + const keys = Object.getOwnPropertyNames(value3); + const entries = Object.entries(object3.properties); + const [point, max] = [1 / entries.length, entries.length]; + return entries.reduce((acc, [key, schema2]) => { + const literal7 = schema2[Kind] === "Literal" && schema2.const === value3[key] ? max : 0; + const checks = Check(schema2, references, value3[key]) ? point : 0; + const exists = keys.includes(key) ? point : 0; + return acc + (literal7 + checks + exists); + }, 0); + } else { + return Check(schema, references, value3) ? 1 : 0; + } +}; +var SelectUnion = function(union9, references, value3) { + let [select, best] = [union9.anyOf[0], 0]; + for (const schema of union9.anyOf) { + const score = ScoreUnion(schema, references, value3); + if (score > best) { + select = schema; + best = score; + } + } + return select; +}; +var CastUnion = function(union9, references, value3) { + if ("default" in union9) { + return typeof value3 === "function" ? union9.default : Clone2(union9.default); + } else { + const schema = SelectUnion(union9, references, value3); + return Cast(schema, references, value3); + } +}; +var DefaultClone = function(schema, references, value3) { + return Check(schema, references, value3) ? Clone2(value3) : Create2(schema, references); +}; +var Default = function(schema, references, value3) { + return Check(schema, references, value3) ? value3 : Create2(schema, references); +}; +var FromArray7 = function(schema, references, value3) { + if (Check(schema, references, value3)) + return Clone2(value3); + const created = IsArray(value3) ? Clone2(value3) : Create2(schema, references); + const minimum = IsNumber(schema.minItems) && created.length < schema.minItems ? [...created, ...Array.from({ length: schema.minItems - created.length }, () => null)] : created; + const maximum = IsNumber(schema.maxItems) && minimum.length > schema.maxItems ? minimum.slice(0, schema.maxItems) : minimum; + const casted = maximum.map((value4) => Visit8(schema.items, references, value4)); + if (schema.uniqueItems !== true) + return casted; + const unique = [...new Set(casted)]; + if (!Check(schema, references, unique)) + throw new ValueCastError(schema, "Array cast produced invalid data due to uniqueItems constraint"); + return unique; +}; +var FromConstructor5 = function(schema, references, value3) { + if (Check(schema, references, value3)) + return Create2(schema, references); + const required = new Set(schema.returns.required || []); + const result = function() { + }; + for (const [key, property] of Object.entries(schema.returns.properties)) { + if (!required.has(key) && value3.prototype[key] === undefined) + continue; + result.prototype[key] = Visit8(property, references, value3.prototype[key]); + } + return result; +}; +var FromIntersect7 = function(schema, references, value3) { + const created = Create2(schema, references); + const mapped9 = IsStandardObject(created) && IsStandardObject(value3) ? { ...created, ...value3 } : value3; + return Check(schema, references, mapped9) ? mapped9 : Create2(schema, references); +}; +var FromNever5 = function(schema, references, value3) { + throw new ValueCastError(schema, "Never types cannot be cast"); +}; +var FromObject5 = function(schema, references, value3) { + if (Check(schema, references, value3)) + return value3; + if (value3 === null || typeof value3 !== "object") + return Create2(schema, references); + const required = new Set(schema.required || []); + const result = {}; + for (const [key, property] of Object.entries(schema.properties)) { + if (!required.has(key) && value3[key] === undefined) + continue; + result[key] = Visit8(property, references, value3[key]); + } + if (typeof schema.additionalProperties === "object") { + const propertyNames = Object.getOwnPropertyNames(schema.properties); + for (const propertyName of Object.getOwnPropertyNames(value3)) { + if (propertyNames.includes(propertyName)) + continue; + result[propertyName] = Visit8(schema.additionalProperties, references, value3[propertyName]); + } + } + return result; +}; +var FromRecord5 = function(schema, references, value3) { + if (Check(schema, references, value3)) + return Clone2(value3); + if (value3 === null || typeof value3 !== "object" || Array.isArray(value3) || value3 instanceof Date) + return Create2(schema, references); + const subschemaPropertyName = Object.getOwnPropertyNames(schema.patternProperties)[0]; + const subschema = schema.patternProperties[subschemaPropertyName]; + const result = {}; + for (const [propKey, propValue] of Object.entries(value3)) { + result[propKey] = Visit8(subschema, references, propValue); + } + return result; +}; +var FromRef4 = function(schema, references, value3) { + return Visit8(Deref(schema, references), references, value3); +}; +var FromThis4 = function(schema, references, value3) { + return Visit8(Deref(schema, references), references, value3); +}; +var FromTuple7 = function(schema, references, value3) { + if (Check(schema, references, value3)) + return Clone2(value3); + if (!IsArray(value3)) + return Create2(schema, references); + if (schema.items === undefined) + return []; + return schema.items.map((schema2, index) => Visit8(schema2, references, value3[index])); +}; +var FromUnion9 = function(schema, references, value3) { + return Check(schema, references, value3) ? Clone2(value3) : CastUnion(schema, references, value3); +}; +var Visit8 = function(schema, references, value3) { + const references_ = IsString(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + switch (schema[Kind]) { + case "Array": + return FromArray7(schema_, references_, value3); + case "Constructor": + return FromConstructor5(schema_, references_, value3); + case "Intersect": + return FromIntersect7(schema_, references_, value3); + case "Never": + return FromNever5(schema_, references_, value3); + case "Object": + return FromObject5(schema_, references_, value3); + case "Record": + return FromRecord5(schema_, references_, value3); + case "Ref": + return FromRef4(schema_, references_, value3); + case "This": + return FromThis4(schema_, references_, value3); + case "Tuple": + return FromTuple7(schema_, references_, value3); + case "Union": + return FromUnion9(schema_, references_, value3); + case "Date": + case "Symbol": + case "Uint8Array": + return DefaultClone(schema, references, value3); + default: + return Default(schema_, references_, value3); + } +}; +function Cast(...args) { + return args.length === 3 ? Visit8(args[0], args[1], args[2]) : Visit8(args[0], [], args[1]); +} + +class ValueCastError extends TypeBoxError { + schema; + constructor(schema, message) { + super(message); + this.schema = schema; + } +} +// node_modules/@sinclair/typebox/build/import/value/clean/clean.mjs +var IsCheckable = function(schema) { + return IsSchema(schema) && schema[Kind] !== "Unsafe"; +}; +var FromArray8 = function(schema, references, value3) { + if (!IsArray(value3)) + return value3; + return value3.map((value4) => Visit9(schema.items, references, value4)); +}; +var FromIntersect8 = function(schema, references, value3) { + const unevaluatedProperties = schema.unevaluatedProperties; + const intersections = schema.allOf.map((schema2) => Visit9(schema2, references, Clone2(value3))); + const composite = intersections.reduce((acc, value4) => IsObject(value4) ? { ...acc, ...value4 } : value4, {}); + if (!IsObject(value3) || !IsObject(composite) || !IsSchema(unevaluatedProperties)) + return composite; + const knownkeys = KeyOfPropertyKeys(schema); + for (const key of Object.getOwnPropertyNames(value3)) { + if (knownkeys.includes(key)) + continue; + if (Check(unevaluatedProperties, references, value3[key])) { + composite[key] = Visit9(unevaluatedProperties, references, value3[key]); + } + } + return composite; +}; +var FromObject6 = function(schema, references, value3) { + if (!IsObject(value3) || IsArray(value3)) + return value3; + const additionalProperties = schema.additionalProperties; + for (const key of Object.getOwnPropertyNames(value3)) { + if (key in schema.properties) { + value3[key] = Visit9(schema.properties[key], references, value3[key]); + continue; + } + if (IsSchema(additionalProperties) && Check(additionalProperties, references, value3[key])) { + value3[key] = Visit9(additionalProperties, references, value3[key]); + continue; + } + delete value3[key]; + } + return value3; +}; +var FromRecord6 = function(schema, references, value3) { + if (!IsObject(value3)) + return value3; + const additionalProperties = schema.additionalProperties; + const propertyKeys = Object.keys(value3); + const [propertyKey, propertySchema] = Object.entries(schema.patternProperties)[0]; + const propertyKeyTest = new RegExp(propertyKey); + for (const key of propertyKeys) { + if (propertyKeyTest.test(key)) { + value3[key] = Visit9(propertySchema, references, value3[key]); + continue; + } + if (IsSchema(additionalProperties) && Check(additionalProperties, references, value3[key])) { + value3[key] = Visit9(additionalProperties, references, value3[key]); + continue; + } + delete value3[key]; + } + return value3; +}; +var FromRef5 = function(schema, references, value3) { + return Visit9(Deref(schema, references), references, value3); +}; +var FromThis5 = function(schema, references, value3) { + return Visit9(Deref(schema, references), references, value3); +}; +var FromTuple8 = function(schema, references, value3) { + if (!IsArray(value3)) + return value3; + if (IsUndefined(schema.items)) + return []; + const length = Math.min(value3.length, schema.items.length); + for (let i = 0;i < length; i++) { + value3[i] = Visit9(schema.items[i], references, value3[i]); + } + return value3.length > length ? value3.slice(0, length) : value3; +}; +var FromUnion10 = function(schema, references, value3) { + for (const inner of schema.anyOf) { + if (IsCheckable(inner) && Check(inner, value3)) { + return Visit9(inner, references, value3); + } + } + return value3; +}; +var Visit9 = function(schema, references, value3) { + const references_ = IsString(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + switch (schema_[Kind]) { + case "Array": + return FromArray8(schema_, references_, value3); + case "Intersect": + return FromIntersect8(schema_, references_, value3); + case "Object": + return FromObject6(schema_, references_, value3); + case "Record": + return FromRecord6(schema_, references_, value3); + case "Ref": + return FromRef5(schema_, references_, value3); + case "This": + return FromThis5(schema_, references_, value3); + case "Tuple": + return FromTuple8(schema_, references_, value3); + case "Union": + return FromUnion10(schema_, references_, value3); + default: + return value3; + } +}; +function Clean(...args) { + return args.length === 3 ? Visit9(args[0], args[1], args[2]) : Visit9(args[0], [], args[1]); +} +// node_modules/@sinclair/typebox/build/import/value/convert/convert.mjs +var IsStringNumeric = function(value3) { + return IsString(value3) && !isNaN(value3) && !isNaN(parseFloat(value3)); +}; +var IsValueToString = function(value3) { + return IsBigInt(value3) || IsBoolean(value3) || IsNumber(value3); +}; +var IsValueTrue = function(value3) { + return value3 === true || IsNumber(value3) && value3 === 1 || IsBigInt(value3) && value3 === BigInt("1") || IsString(value3) && (value3.toLowerCase() === "true" || value3 === "1"); +}; +var IsValueFalse = function(value3) { + return value3 === false || IsNumber(value3) && (value3 === 0 || Object.is(value3, -0)) || IsBigInt(value3) && value3 === BigInt("0") || IsString(value3) && (value3.toLowerCase() === "false" || value3 === "0" || value3 === "-0"); +}; +var IsTimeStringWithTimeZone = function(value3) { + return IsString(value3) && /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i.test(value3); +}; +var IsTimeStringWithoutTimeZone = function(value3) { + return IsString(value3) && /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)?$/i.test(value3); +}; +var IsDateTimeStringWithTimeZone = function(value3) { + return IsString(value3) && /^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d(?::?\d\d)?)$/i.test(value3); +}; +var IsDateTimeStringWithoutTimeZone = function(value3) { + return IsString(value3) && /^\d\d\d\d-[0-1]\d-[0-3]\dt(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)?$/i.test(value3); +}; +var IsDateString = function(value3) { + return IsString(value3) && /^\d\d\d\d-[0-1]\d-[0-3]\d$/i.test(value3); +}; +var TryConvertLiteralString = function(value3, target) { + const conversion = TryConvertString(value3); + return conversion === target ? conversion : value3; +}; +var TryConvertLiteralNumber = function(value3, target) { + const conversion = TryConvertNumber(value3); + return conversion === target ? conversion : value3; +}; +var TryConvertLiteralBoolean = function(value3, target) { + const conversion = TryConvertBoolean(value3); + return conversion === target ? conversion : value3; +}; +var TryConvertLiteral = function(schema, value3) { + return IsString(schema.const) ? TryConvertLiteralString(value3, schema.const) : IsNumber(schema.const) ? TryConvertLiteralNumber(value3, schema.const) : IsBoolean(schema.const) ? TryConvertLiteralBoolean(value3, schema.const) : Clone2(value3); +}; +var TryConvertBoolean = function(value3) { + return IsValueTrue(value3) ? true : IsValueFalse(value3) ? false : value3; +}; +var TryConvertBigInt = function(value3) { + return IsStringNumeric(value3) ? BigInt(parseInt(value3)) : IsNumber(value3) ? BigInt(value3 | 0) : IsValueFalse(value3) ? BigInt(0) : IsValueTrue(value3) ? BigInt(1) : value3; +}; +var TryConvertString = function(value3) { + return IsValueToString(value3) ? value3.toString() : IsSymbol(value3) && value3.description !== undefined ? value3.description.toString() : value3; +}; +var TryConvertNumber = function(value3) { + return IsStringNumeric(value3) ? parseFloat(value3) : IsValueTrue(value3) ? 1 : IsValueFalse(value3) ? 0 : value3; +}; +var TryConvertInteger = function(value3) { + return IsStringNumeric(value3) ? parseInt(value3) : IsNumber(value3) ? value3 | 0 : IsValueTrue(value3) ? 1 : IsValueFalse(value3) ? 0 : value3; +}; +var TryConvertNull = function(value3) { + return IsString(value3) && value3.toLowerCase() === "null" ? null : value3; +}; +var TryConvertUndefined = function(value3) { + return IsString(value3) && value3 === "undefined" ? undefined : value3; +}; +var TryConvertDate = function(value3) { + return IsDate(value3) ? value3 : IsNumber(value3) ? new Date(value3) : IsValueTrue(value3) ? new Date(1) : IsValueFalse(value3) ? new Date(0) : IsStringNumeric(value3) ? new Date(parseInt(value3)) : IsTimeStringWithoutTimeZone(value3) ? new Date(`1970-01-01T${value3}.000Z`) : IsTimeStringWithTimeZone(value3) ? new Date(`1970-01-01T${value3}`) : IsDateTimeStringWithoutTimeZone(value3) ? new Date(`${value3}.000Z`) : IsDateTimeStringWithTimeZone(value3) ? new Date(value3) : IsDateString(value3) ? new Date(`${value3}T00:00:00.000Z`) : value3; +}; +var Default2 = function(value3) { + return value3; +}; +var FromArray9 = function(schema, references, value3) { + if (IsArray(value3)) { + return value3.map((value4) => Visit10(schema.items, references, value4)); + } + return value3; +}; +var FromBigInt5 = function(schema, references, value3) { + return TryConvertBigInt(value3); +}; +var FromBoolean5 = function(schema, references, value3) { + return TryConvertBoolean(value3); +}; +var FromDate5 = function(schema, references, value3) { + return TryConvertDate(value3); +}; +var FromInteger5 = function(schema, references, value3) { + return TryConvertInteger(value3); +}; +var FromIntersect9 = function(schema, references, value3) { + return schema.allOf.reduce((value4, schema2) => Visit10(schema2, references, value4), value3); +}; +var FromLiteral6 = function(schema, references, value3) { + return TryConvertLiteral(schema, value3); +}; +var FromNull5 = function(schema, references, value3) { + return TryConvertNull(value3); +}; +var FromNumber5 = function(schema, references, value3) { + return TryConvertNumber(value3); +}; +var FromObject7 = function(schema, references, value3) { + const isConvertable = IsObject(value3); + if (!isConvertable) + return value3; + return Object.getOwnPropertyNames(schema.properties).reduce((value4, key) => { + return !IsUndefined(value4[key]) ? { ...value4, [key]: Visit10(schema.properties[key], references, value4[key]) } : { ...value4 }; + }, value3); +}; +var FromRecord7 = function(schema, references, value3) { + const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0]; + const property = schema.patternProperties[propertyKey]; + const result = {}; + for (const [propKey, propValue] of Object.entries(value3)) { + result[propKey] = Visit10(property, references, propValue); + } + return result; +}; +var FromRef6 = function(schema, references, value3) { + return Visit10(Deref(schema, references), references, value3); +}; +var FromString5 = function(schema, references, value3) { + return TryConvertString(value3); +}; +var FromSymbol5 = function(schema, references, value3) { + return IsString(value3) || IsNumber(value3) ? Symbol(value3) : value3; +}; +var FromThis6 = function(schema, references, value3) { + return Visit10(Deref(schema, references), references, value3); +}; +var FromTuple9 = function(schema, references, value3) { + const isConvertable = IsArray(value3) && !IsUndefined(schema.items); + if (!isConvertable) + return value3; + return value3.map((value4, index) => { + return index < schema.items.length ? Visit10(schema.items[index], references, value4) : value4; + }); +}; +var FromUndefined5 = function(schema, references, value3) { + return TryConvertUndefined(value3); +}; +var FromUnion11 = function(schema, references, value3) { + for (const subschema of schema.anyOf) { + const converted = Visit10(subschema, references, value3); + if (!Check(subschema, references, converted)) + continue; + return converted; + } + return value3; +}; +var Visit10 = function(schema, references, value3) { + const references_ = IsString(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + switch (schema[Kind]) { + case "Array": + return FromArray9(schema_, references_, value3); + case "BigInt": + return FromBigInt5(schema_, references_, value3); + case "Boolean": + return FromBoolean5(schema_, references_, value3); + case "Date": + return FromDate5(schema_, references_, value3); + case "Integer": + return FromInteger5(schema_, references_, value3); + case "Intersect": + return FromIntersect9(schema_, references_, value3); + case "Literal": + return FromLiteral6(schema_, references_, value3); + case "Null": + return FromNull5(schema_, references_, value3); + case "Number": + return FromNumber5(schema_, references_, value3); + case "Object": + return FromObject7(schema_, references_, value3); + case "Record": + return FromRecord7(schema_, references_, value3); + case "Ref": + return FromRef6(schema_, references_, value3); + case "String": + return FromString5(schema_, references_, value3); + case "Symbol": + return FromSymbol5(schema_, references_, value3); + case "This": + return FromThis6(schema_, references_, value3); + case "Tuple": + return FromTuple9(schema_, references_, value3); + case "Undefined": + return FromUndefined5(schema_, references_, value3); + case "Union": + return FromUnion11(schema_, references_, value3); + default: + return Default2(value3); + } +}; +function Convert(...args) { + return args.length === 3 ? Visit10(args[0], args[1], args[2]) : Visit10(args[0], [], args[1]); +} +// node_modules/@sinclair/typebox/build/import/value/default/default.mjs +var ValueOrDefault = function(schema, value3) { + return value3 === undefined && "default" in schema ? Clone2(schema.default) : value3; +}; +var IsCheckable2 = function(schema) { + return IsSchema(schema) && schema[Kind] !== "Unsafe"; +}; +var IsDefaultSchema = function(value3) { + return IsSchema(value3) && "default" in value3; +}; +var FromArray10 = function(schema, references, value3) { + const defaulted = ValueOrDefault(schema, value3); + if (!IsArray(defaulted)) + return defaulted; + for (let i = 0;i < defaulted.length; i++) { + defaulted[i] = Visit11(schema.items, references, defaulted[i]); + } + return defaulted; +}; +var FromIntersect10 = function(schema, references, value3) { + const defaulted = ValueOrDefault(schema, value3); + return schema.allOf.reduce((acc, schema2) => { + const next = Visit11(schema2, references, defaulted); + return IsObject(next) ? { ...acc, ...next } : next; + }, {}); +}; +var FromObject8 = function(schema, references, value3) { + const defaulted = ValueOrDefault(schema, value3); + if (!IsObject(defaulted)) + return defaulted; + const additionalPropertiesSchema = schema.additionalProperties; + const knownPropertyKeys = Object.getOwnPropertyNames(schema.properties); + for (const key of knownPropertyKeys) { + if (!IsDefaultSchema(schema.properties[key])) + continue; + defaulted[key] = Visit11(schema.properties[key], references, defaulted[key]); + } + if (!IsDefaultSchema(additionalPropertiesSchema)) + return defaulted; + for (const key of Object.getOwnPropertyNames(defaulted)) { + if (knownPropertyKeys.includes(key)) + continue; + defaulted[key] = Visit11(additionalPropertiesSchema, references, defaulted[key]); + } + return defaulted; +}; +var FromRecord8 = function(schema, references, value3) { + const defaulted = ValueOrDefault(schema, value3); + if (!IsObject(defaulted)) + return defaulted; + const additionalPropertiesSchema = schema.additionalProperties; + const [propertyKeyPattern, propertySchema] = Object.entries(schema.patternProperties)[0]; + const knownPropertyKey = new RegExp(propertyKeyPattern); + for (const key of Object.getOwnPropertyNames(defaulted)) { + if (!(knownPropertyKey.test(key) && IsDefaultSchema(propertySchema))) + continue; + defaulted[key] = Visit11(propertySchema, references, defaulted[key]); + } + if (!IsDefaultSchema(additionalPropertiesSchema)) + return defaulted; + for (const key of Object.getOwnPropertyNames(defaulted)) { + if (knownPropertyKey.test(key)) + continue; + defaulted[key] = Visit11(additionalPropertiesSchema, references, defaulted[key]); + } + return defaulted; +}; +var FromRef7 = function(schema, references, value3) { + return Visit11(Deref(schema, references), references, ValueOrDefault(schema, value3)); +}; +var FromThis7 = function(schema, references, value3) { + return Visit11(Deref(schema, references), references, value3); +}; +var FromTuple10 = function(schema, references, value3) { + const defaulted = ValueOrDefault(schema, value3); + if (!IsArray(defaulted) || IsUndefined(schema.items)) + return defaulted; + const [items, max] = [schema.items, Math.max(schema.items.length, defaulted.length)]; + for (let i = 0;i < max; i++) { + if (i < items.length) + defaulted[i] = Visit11(items[i], references, defaulted[i]); + } + return defaulted; +}; +var FromUnion12 = function(schema, references, value3) { + const defaulted = ValueOrDefault(schema, value3); + for (const inner of schema.anyOf) { + const result = Visit11(inner, references, defaulted); + if (IsCheckable2(inner) && Check(inner, result)) { + return result; + } + } + return defaulted; +}; +var Visit11 = function(schema, references, value3) { + const references_ = IsString(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + switch (schema_[Kind]) { + case "Array": + return FromArray10(schema_, references_, value3); + case "Intersect": + return FromIntersect10(schema_, references_, value3); + case "Object": + return FromObject8(schema_, references_, value3); + case "Record": + return FromRecord8(schema_, references_, value3); + case "Ref": + return FromRef7(schema_, references_, value3); + case "This": + return FromThis7(schema_, references_, value3); + case "Tuple": + return FromTuple10(schema_, references_, value3); + case "Union": + return FromUnion12(schema_, references_, value3); + default: + return ValueOrDefault(schema_, value3); + } +}; +function Default3(...args) { + return args.length === 3 ? Visit11(args[0], args[1], args[2]) : Visit11(args[0], [], args[1]); +} +// node_modules/@sinclair/typebox/build/import/value/pointer/pointer.mjs +var exports_pointer = {}; +__export(exports_pointer, { + ValuePointerRootSetError: () => { + { + return ValuePointerRootSetError; + } + }, + ValuePointerRootDeleteError: () => { + { + return ValuePointerRootDeleteError; + } + }, + Set: () => { + { + return Set4; + } + }, + Has: () => { + { + return Has3; + } + }, + Get: () => { + { + return Get3; + } + }, + Format: () => { + { + return Format; + } + }, + Delete: () => { + { + return Delete3; + } + } +}); +var Escape2 = function(component) { + return component.indexOf("~") === -1 ? component : component.replace(/~1/g, "/").replace(/~0/g, "~"); +}; +function* Format(pointer) { + if (pointer === "") + return; + let [start, end] = [0, 0]; + for (let i = 0;i < pointer.length; i++) { + const char = pointer.charAt(i); + if (char === "/") { + if (i === 0) { + start = i + 1; + } else { + end = i; + yield Escape2(pointer.slice(start, end)); + start = i + 1; + } + } else { + end = i; + } + } + yield Escape2(pointer.slice(start)); +} +function Set4(value3, pointer, update) { + if (pointer === "") + throw new ValuePointerRootSetError(value3, pointer, update); + let [owner, next, key] = [null, value3, ""]; + for (const component of Format(pointer)) { + if (next[component] === undefined) + next[component] = {}; + owner = next; + next = next[component]; + key = component; + } + owner[key] = update; +} +function Delete3(value3, pointer) { + if (pointer === "") + throw new ValuePointerRootDeleteError(value3, pointer); + let [owner, next, key] = [null, value3, ""]; + for (const component of Format(pointer)) { + if (next[component] === undefined || next[component] === null) + return; + owner = next; + next = next[component]; + key = component; + } + if (Array.isArray(owner)) { + const index = parseInt(key); + owner.splice(index, 1); + } else { + delete owner[key]; + } +} +function Has3(value3, pointer) { + if (pointer === "") + return true; + let [owner, next, key] = [null, value3, ""]; + for (const component of Format(pointer)) { + if (next[component] === undefined) + return false; + owner = next; + next = next[component]; + key = component; + } + return Object.getOwnPropertyNames(owner).includes(key); +} +function Get3(value3, pointer) { + if (pointer === "") + return value3; + let current = value3; + for (const component of Format(pointer)) { + if (current[component] === undefined) + return; + current = current[component]; + } + return current; +} + +class ValuePointerRootSetError extends TypeBoxError { + value; + path; + update; + constructor(value3, path, update) { + super("Cannot set root value"); + this.value = value3; + this.path = path; + this.update = update; + } +} + +class ValuePointerRootDeleteError extends TypeBoxError { + value; + path; + constructor(value3, path) { + super("Cannot delete root value"); + this.value = value3; + this.path = path; + } +} +// node_modules/@sinclair/typebox/build/import/value/delta/delta.mjs +var CreateUpdate = function(path, value3) { + return { type: "update", path, value: value3 }; +}; +var CreateInsert = function(path, value3) { + return { type: "insert", path, value: value3 }; +}; +var CreateDelete = function(path) { + return { type: "delete", path }; +}; +function* ObjectType4(path, current, next) { + if (!IsStandardObject(next)) + return yield CreateUpdate(path, next); + const currentKeys = [...globalThis.Object.keys(current), ...globalThis.Object.getOwnPropertySymbols(current)]; + const nextKeys = [...globalThis.Object.keys(next), ...globalThis.Object.getOwnPropertySymbols(next)]; + for (const key of currentKeys) { + if (IsSymbol(key)) + throw new ValueDeltaSymbolError(key); + if (IsUndefined(next[key]) && nextKeys.includes(key)) + yield CreateUpdate(`${path}/${globalThis.String(key)}`, undefined); + } + for (const key of nextKeys) { + if (IsUndefined(current[key]) || IsUndefined(next[key])) + continue; + if (IsSymbol(key)) + throw new ValueDeltaSymbolError(key); + yield* Visit12(`${path}/${globalThis.String(key)}`, current[key], next[key]); + } + for (const key of nextKeys) { + if (IsSymbol(key)) + throw new ValueDeltaSymbolError(key); + if (IsUndefined(current[key])) + yield CreateInsert(`${path}/${globalThis.String(key)}`, next[key]); + } + for (const key of currentKeys.reverse()) { + if (IsSymbol(key)) + throw new ValueDeltaSymbolError(key); + if (IsUndefined(next[key]) && !nextKeys.includes(key)) + yield CreateDelete(`${path}/${globalThis.String(key)}`); + } +} +function* ArrayType4(path, current, next) { + if (!IsArray(next)) + return yield CreateUpdate(path, next); + for (let i = 0;i < Math.min(current.length, next.length); i++) { + yield* Visit12(`${path}/${i}`, current[i], next[i]); + } + for (let i = 0;i < next.length; i++) { + if (i < current.length) + continue; + yield CreateInsert(`${path}/${i}`, next[i]); + } + for (let i = current.length - 1;i >= 0; i--) { + if (i < next.length) + continue; + yield CreateDelete(`${path}/${i}`); + } +} +function* TypedArrayType2(path, current, next) { + if (!IsTypedArray(next) || current.length !== next.length || globalThis.Object.getPrototypeOf(current).constructor.name !== globalThis.Object.getPrototypeOf(next).constructor.name) + return yield CreateUpdate(path, next); + for (let i = 0;i < Math.min(current.length, next.length); i++) { + yield* Visit12(`${path}/${i}`, current[i], next[i]); + } +} +function* ValueType2(path, current, next) { + if (current === next) + return; + yield CreateUpdate(path, next); +} +function* Visit12(path, current, next) { + if (IsStandardObject(current)) + return yield* ObjectType4(path, current, next); + if (IsArray(current)) + return yield* ArrayType4(path, current, next); + if (IsTypedArray(current)) + return yield* TypedArrayType2(path, current, next); + if (IsValueType(current)) + return yield* ValueType2(path, current, next); + throw new ValueDeltaError(current, "Unable to create diff edits for unknown value"); +} +function Diff(current, next) { + return [...Visit12("", current, next)]; +} +var IsRootUpdate = function(edits) { + return edits.length > 0 && edits[0].path === "" && edits[0].type === "update"; +}; +var IsIdentity = function(edits) { + return edits.length === 0; +}; +function Patch(current, edits) { + if (IsRootUpdate(edits)) { + return Clone2(edits[0].value); + } + if (IsIdentity(edits)) { + return Clone2(current); + } + const clone8 = Clone2(current); + for (const edit of edits) { + switch (edit.type) { + case "insert": { + exports_pointer.Set(clone8, edit.path, edit.value); + break; + } + case "update": { + exports_pointer.Set(clone8, edit.path, edit.value); + break; + } + case "delete": { + exports_pointer.Delete(clone8, edit.path); + break; + } + } + } + return clone8; +} +var Insert = Object2({ + type: Literal("insert"), + path: String2(), + value: Unknown() +}); +var Update = Object2({ + type: Literal("update"), + path: String2(), + value: Unknown() +}); +var Delete4 = Object2({ + type: Literal("delete"), + path: String2() +}); +var Edit = Union([Insert, Update, Delete4]); + +class ValueDeltaError extends TypeBoxError { + value; + constructor(value3, message) { + super(message); + this.value = value3; + } +} + +class ValueDeltaSymbolError extends ValueDeltaError { + value; + constructor(value3) { + super(value3, "Cannot diff objects with symbol keys"); + this.value = value3; + } +} +// node_modules/@sinclair/typebox/build/import/value/equal/equal.mjs +var ObjectType5 = function(left, right) { + if (!IsStandardObject(right)) + return false; + const leftKeys = [...Object.keys(left), ...Object.getOwnPropertySymbols(left)]; + const rightKeys = [...Object.keys(right), ...Object.getOwnPropertySymbols(right)]; + if (leftKeys.length !== rightKeys.length) + return false; + return leftKeys.every((key) => Equal(left[key], right[key])); +}; +var DateType4 = function(left, right) { + return IsDate(right) && left.getTime() === right.getTime(); +}; +var ArrayType5 = function(left, right) { + if (!IsArray(right) || left.length !== right.length) + return false; + return left.every((value3, index) => Equal(value3, right[index])); +}; +var TypedArrayType3 = function(left, right) { + if (!IsTypedArray(right) || left.length !== right.length || Object.getPrototypeOf(left).constructor.name !== Object.getPrototypeOf(right).constructor.name) + return false; + return left.every((value3, index) => Equal(value3, right[index])); +}; +var ValueType3 = function(left, right) { + return left === right; +}; +function Equal(left, right) { + if (IsStandardObject(left)) + return ObjectType5(left, right); + if (IsDate(left)) + return DateType4(left, right); + if (IsTypedArray(left)) + return TypedArrayType3(left, right); + if (IsArray(left)) + return ArrayType5(left, right); + if (IsValueType(left)) + return ValueType3(left, right); + throw new Error("ValueEquals: Unable to compare value"); +} +// node_modules/@sinclair/typebox/build/import/value/mutate/mutate.mjs +var ObjectType6 = function(root, path, current, next) { + if (!IsStandardObject(current)) { + exports_pointer.Set(root, path, Clone2(next)); + } else { + const currentKeys = Object.keys(current); + const nextKeys = Object.keys(next); + for (const currentKey of currentKeys) { + if (!nextKeys.includes(currentKey)) { + delete current[currentKey]; + } + } + for (const nextKey of nextKeys) { + if (!currentKeys.includes(nextKey)) { + current[nextKey] = null; + } + } + for (const nextKey of nextKeys) { + Visit13(root, `${path}/${nextKey}`, current[nextKey], next[nextKey]); + } + } +}; +var ArrayType6 = function(root, path, current, next) { + if (!IsArray(current)) { + exports_pointer.Set(root, path, Clone2(next)); + } else { + for (let index = 0;index < next.length; index++) { + Visit13(root, `${path}/${index}`, current[index], next[index]); + } + current.splice(next.length); + } +}; +var TypedArrayType4 = function(root, path, current, next) { + if (IsTypedArray(current) && current.length === next.length) { + for (let i = 0;i < current.length; i++) { + current[i] = next[i]; + } + } else { + exports_pointer.Set(root, path, Clone2(next)); + } +}; +var ValueType4 = function(root, path, current, next) { + if (current === next) + return; + exports_pointer.Set(root, path, next); +}; +var Visit13 = function(root, path, current, next) { + if (IsArray(next)) + return ArrayType6(root, path, current, next); + if (IsTypedArray(next)) + return TypedArrayType4(root, path, current, next); + if (IsStandardObject(next)) + return ObjectType6(root, path, current, next); + if (IsValueType(next)) + return ValueType4(root, path, current, next); +}; +var IsNonMutableValue = function(value3) { + return IsTypedArray(value3) || IsValueType(value3); +}; +var IsMismatchedValue = function(current, next) { + return IsStandardObject(current) && IsArray(next) || IsArray(current) && IsStandardObject(next); +}; +function Mutate(current, next) { + if (IsNonMutableValue(current) || IsNonMutableValue(next)) + throw new ValueMutateError("Only object and array types can be mutated at the root level"); + if (IsMismatchedValue(current, next)) + throw new ValueMutateError("Cannot assign due type mismatch of assignable values"); + Visit13(current, "", current, next); +} + +class ValueMutateError extends TypeBoxError { + constructor(message) { + super(message); + } +} +// node_modules/@sinclair/typebox/build/import/value/transform/decode.mjs +var Default4 = function(schema, path, value3) { + try { + return IsTransform(schema) ? schema[TransformKind].Decode(value3) : value3; + } catch (error19) { + throw new TransformDecodeError(schema, path, value3, error19); + } +}; +var FromArray11 = function(schema, references, path, value3) { + return IsArray(value3) ? Default4(schema, path, value3.map((value4, index) => Visit14(schema.items, references, `${path}/${index}`, value4))) : Default4(schema, path, value3); +}; +var FromIntersect11 = function(schema, references, path, value3) { + if (!IsStandardObject(value3) || IsValueType(value3)) + return Default4(schema, path, value3); + const knownKeys = KeyOfPropertyKeys(schema); + const knownProperties = knownKeys.reduce((value4, key) => { + return key in value4 ? { ...value4, [key]: Visit14(Index(schema, [key]), references, `${path}/${key}`, value4[key]) } : value4; + }, value3); + if (!IsTransform(schema.unevaluatedProperties)) { + return Default4(schema, path, knownProperties); + } + const unknownKeys = Object.getOwnPropertyNames(knownProperties); + const unevaluatedProperties = schema.unevaluatedProperties; + const unknownProperties = unknownKeys.reduce((value4, key) => { + return !knownKeys.includes(key) ? { ...value4, [key]: Default4(unevaluatedProperties, `${path}/${key}`, value4[key]) } : value4; + }, knownProperties); + return Default4(schema, path, unknownProperties); +}; +var FromNot5 = function(schema, references, path, value3) { + return Default4(schema, path, Visit14(schema.not, references, path, value3)); +}; +var FromObject9 = function(schema, references, path, value3) { + if (!IsStandardObject(value3)) + return Default4(schema, path, value3); + const knownKeys = KeyOfPropertyKeys(schema); + const knownProperties = knownKeys.reduce((value4, key) => { + return key in value4 ? { ...value4, [key]: Visit14(schema.properties[key], references, `${path}/${key}`, value4[key]) } : value4; + }, value3); + if (!IsSchema(schema.additionalProperties)) { + return Default4(schema, path, knownProperties); + } + const unknownKeys = Object.getOwnPropertyNames(knownProperties); + const additionalProperties = schema.additionalProperties; + const unknownProperties = unknownKeys.reduce((value4, key) => { + return !knownKeys.includes(key) ? { ...value4, [key]: Default4(additionalProperties, `${path}/${key}`, value4[key]) } : value4; + }, knownProperties); + return Default4(schema, path, unknownProperties); +}; +var FromRecord9 = function(schema, references, path, value3) { + if (!IsStandardObject(value3)) + return Default4(schema, path, value3); + const pattern3 = Object.getOwnPropertyNames(schema.patternProperties)[0]; + const knownKeys = new RegExp(pattern3); + const knownProperties = Object.getOwnPropertyNames(value3).reduce((value4, key) => { + return knownKeys.test(key) ? { ...value4, [key]: Visit14(schema.patternProperties[pattern3], references, `${path}/${key}`, value4[key]) } : value4; + }, value3); + if (!IsSchema(schema.additionalProperties)) { + return Default4(schema, path, knownProperties); + } + const unknownKeys = Object.getOwnPropertyNames(knownProperties); + const additionalProperties = schema.additionalProperties; + const unknownProperties = unknownKeys.reduce((value4, key) => { + return !knownKeys.test(key) ? { ...value4, [key]: Default4(additionalProperties, `${path}/${key}`, value4[key]) } : value4; + }, knownProperties); + return Default4(schema, path, unknownProperties); +}; +var FromRef8 = function(schema, references, path, value3) { + const target = Deref(schema, references); + return Default4(schema, path, Visit14(target, references, path, value3)); +}; +var FromThis8 = function(schema, references, path, value3) { + const target = Deref(schema, references); + return Default4(schema, path, Visit14(target, references, path, value3)); +}; +var FromTuple11 = function(schema, references, path, value3) { + return IsArray(value3) && IsArray(schema.items) ? Default4(schema, path, schema.items.map((schema2, index) => Visit14(schema2, references, `${path}/${index}`, value3[index]))) : Default4(schema, path, value3); +}; +var FromUnion13 = function(schema, references, path, value3) { + for (const subschema of schema.anyOf) { + if (!Check(subschema, references, value3)) + continue; + const decoded = Visit14(subschema, references, path, value3); + return Default4(schema, path, decoded); + } + return Default4(schema, path, value3); +}; +var Visit14 = function(schema, references, path, value3) { + const references_ = typeof schema.$id === "string" ? [...references, schema] : references; + const schema_ = schema; + switch (schema[Kind]) { + case "Array": + return FromArray11(schema_, references_, path, value3); + case "Intersect": + return FromIntersect11(schema_, references_, path, value3); + case "Not": + return FromNot5(schema_, references_, path, value3); + case "Object": + return FromObject9(schema_, references_, path, value3); + case "Record": + return FromRecord9(schema_, references_, path, value3); + case "Ref": + return FromRef8(schema_, references_, path, value3); + case "Symbol": + return Default4(schema_, path, value3); + case "This": + return FromThis8(schema_, references_, path, value3); + case "Tuple": + return FromTuple11(schema_, references_, path, value3); + case "Union": + return FromUnion13(schema_, references_, path, value3); + default: + return Default4(schema_, path, value3); + } +}; +function TransformDecode(schema, references, value3) { + return Visit14(schema, references, "", value3); +} + +class TransformDecodeCheckError extends TypeBoxError { + schema; + value; + error; + constructor(schema, value3, error19) { + super(`Unable to decode value as it does not match the expected schema`); + this.schema = schema; + this.value = value3; + this.error = error19; + } +} + +class TransformDecodeError extends TypeBoxError { + schema; + path; + value; + error; + constructor(schema, path, value3, error19) { + super(error19 instanceof Error ? error19.message : "Unknown error"); + this.schema = schema; + this.path = path; + this.value = value3; + this.error = error19; + } +} +// node_modules/@sinclair/typebox/build/import/value/transform/encode.mjs +var Default5 = function(schema, path, value3) { + try { + return IsTransform(schema) ? schema[TransformKind].Encode(value3) : value3; + } catch (error20) { + throw new TransformEncodeError(schema, path, value3, error20); + } +}; +var FromArray12 = function(schema, references, path, value3) { + const defaulted = Default5(schema, path, value3); + return IsArray(defaulted) ? defaulted.map((value4, index) => Visit15(schema.items, references, `${path}/${index}`, value4)) : defaulted; +}; +var FromIntersect12 = function(schema, references, path, value3) { + const defaulted = Default5(schema, path, value3); + if (!IsStandardObject(value3) || IsValueType(value3)) + return defaulted; + const knownKeys = KeyOfPropertyKeys(schema); + const knownProperties = knownKeys.reduce((value4, key) => { + return key in defaulted ? { ...value4, [key]: Visit15(Index(schema, [key]), references, `${path}/${key}`, value4[key]) } : value4; + }, defaulted); + if (!IsTransform(schema.unevaluatedProperties)) { + return Default5(schema, path, knownProperties); + } + const unknownKeys = Object.getOwnPropertyNames(knownProperties); + const unevaluatedProperties = schema.unevaluatedProperties; + return unknownKeys.reduce((value4, key) => { + return !knownKeys.includes(key) ? { ...value4, [key]: Default5(unevaluatedProperties, `${path}/${key}`, value4[key]) } : value4; + }, knownProperties); +}; +var FromNot6 = function(schema, references, path, value3) { + return Default5(schema.not, path, Default5(schema, path, value3)); +}; +var FromObject10 = function(schema, references, path, value3) { + const defaulted = Default5(schema, path, value3); + if (!IsStandardObject(value3)) + return defaulted; + const knownKeys = KeyOfPropertyKeys(schema); + const knownProperties = knownKeys.reduce((value4, key) => { + return key in value4 ? { ...value4, [key]: Visit15(schema.properties[key], references, `${path}/${key}`, value4[key]) } : value4; + }, defaulted); + if (!IsSchema(schema.additionalProperties)) { + return knownProperties; + } + const unknownKeys = Object.getOwnPropertyNames(knownProperties); + const additionalProperties = schema.additionalProperties; + return unknownKeys.reduce((value4, key) => { + return !knownKeys.includes(key) ? { ...value4, [key]: Default5(additionalProperties, `${path}/${key}`, value4[key]) } : value4; + }, knownProperties); +}; +var FromRecord10 = function(schema, references, path, value3) { + const defaulted = Default5(schema, path, value3); + if (!IsStandardObject(value3)) + return defaulted; + const pattern3 = Object.getOwnPropertyNames(schema.patternProperties)[0]; + const knownKeys = new RegExp(pattern3); + const knownProperties = Object.getOwnPropertyNames(value3).reduce((value4, key) => { + return knownKeys.test(key) ? { ...value4, [key]: Visit15(schema.patternProperties[pattern3], references, `${path}/${key}`, value4[key]) } : value4; + }, defaulted); + if (!IsSchema(schema.additionalProperties)) { + return Default5(schema, path, knownProperties); + } + const unknownKeys = Object.getOwnPropertyNames(knownProperties); + const additionalProperties = schema.additionalProperties; + return unknownKeys.reduce((value4, key) => { + return !knownKeys.test(key) ? { ...value4, [key]: Default5(additionalProperties, `${path}/${key}`, value4[key]) } : value4; + }, knownProperties); +}; +var FromRef9 = function(schema, references, path, value3) { + const target = Deref(schema, references); + const resolved = Visit15(target, references, path, value3); + return Default5(schema, path, resolved); +}; +var FromThis9 = function(schema, references, path, value3) { + const target = Deref(schema, references); + const resolved = Visit15(target, references, path, value3); + return Default5(schema, path, resolved); +}; +var FromTuple12 = function(schema, references, path, value3) { + const value1 = Default5(schema, path, value3); + return IsArray(schema.items) ? schema.items.map((schema2, index) => Visit15(schema2, references, `${path}/${index}`, value1[index])) : []; +}; +var FromUnion14 = function(schema, references, path, value3) { + for (const subschema of schema.anyOf) { + if (!Check(subschema, references, value3)) + continue; + const value1 = Visit15(subschema, references, path, value3); + return Default5(schema, path, value1); + } + for (const subschema of schema.anyOf) { + const value1 = Visit15(subschema, references, path, value3); + if (!Check(schema, references, value1)) + continue; + return Default5(schema, path, value1); + } + return Default5(schema, path, value3); +}; +var Visit15 = function(schema, references, path, value3) { + const references_ = typeof schema.$id === "string" ? [...references, schema] : references; + const schema_ = schema; + switch (schema[Kind]) { + case "Array": + return FromArray12(schema_, references_, path, value3); + case "Intersect": + return FromIntersect12(schema_, references_, path, value3); + case "Not": + return FromNot6(schema_, references_, path, value3); + case "Object": + return FromObject10(schema_, references_, path, value3); + case "Record": + return FromRecord10(schema_, references_, path, value3); + case "Ref": + return FromRef9(schema_, references_, path, value3); + case "This": + return FromThis9(schema_, references_, path, value3); + case "Tuple": + return FromTuple12(schema_, references_, path, value3); + case "Union": + return FromUnion14(schema_, references_, path, value3); + default: + return Default5(schema_, path, value3); + } +}; +function TransformEncode(schema, references, value3) { + return Visit15(schema, references, "", value3); +} + +class TransformEncodeCheckError extends TypeBoxError { + schema; + value; + error; + constructor(schema, value3, error20) { + super(`The encoded value does not match the expected schema`); + this.schema = schema; + this.value = value3; + this.error = error20; + } +} + +class TransformEncodeError extends TypeBoxError { + schema; + path; + value; + error; + constructor(schema, path, value3, error20) { + super(`${error20 instanceof Error ? error20.message : "Unknown error"}`); + this.schema = schema; + this.path = path; + this.value = value3; + this.error = error20; + } +} +// node_modules/@sinclair/typebox/build/import/value/transform/has.mjs +var FromArray13 = function(schema, references) { + return IsTransform(schema) || Visit16(schema.items, references); +}; +var FromAsyncIterator5 = function(schema, references) { + return IsTransform(schema) || Visit16(schema.items, references); +}; +var FromConstructor6 = function(schema, references) { + return IsTransform(schema) || Visit16(schema.returns, references) || schema.parameters.some((schema2) => Visit16(schema2, references)); +}; +var FromFunction5 = function(schema, references) { + return IsTransform(schema) || Visit16(schema.returns, references) || schema.parameters.some((schema2) => Visit16(schema2, references)); +}; +var FromIntersect13 = function(schema, references) { + return IsTransform(schema) || IsTransform(schema.unevaluatedProperties) || schema.allOf.some((schema2) => Visit16(schema2, references)); +}; +var FromIterator5 = function(schema, references) { + return IsTransform(schema) || Visit16(schema.items, references); +}; +var FromNot7 = function(schema, references) { + return IsTransform(schema) || Visit16(schema.not, references); +}; +var FromObject11 = function(schema, references) { + return IsTransform(schema) || Object.values(schema.properties).some((schema2) => Visit16(schema2, references)) || IsSchema(schema.additionalProperties) && Visit16(schema.additionalProperties, references); +}; +var FromPromise5 = function(schema, references) { + return IsTransform(schema) || Visit16(schema.item, references); +}; +var FromRecord11 = function(schema, references) { + const pattern3 = Object.getOwnPropertyNames(schema.patternProperties)[0]; + const property = schema.patternProperties[pattern3]; + return IsTransform(schema) || Visit16(property, references) || IsSchema(schema.additionalProperties) && IsTransform(schema.additionalProperties); +}; +var FromRef10 = function(schema, references) { + if (IsTransform(schema)) + return true; + return Visit16(Deref(schema, references), references); +}; +var FromThis10 = function(schema, references) { + if (IsTransform(schema)) + return true; + return Visit16(Deref(schema, references), references); +}; +var FromTuple13 = function(schema, references) { + return IsTransform(schema) || !IsUndefined(schema.items) && schema.items.some((schema2) => Visit16(schema2, references)); +}; +var FromUnion15 = function(schema, references) { + return IsTransform(schema) || schema.anyOf.some((schema2) => Visit16(schema2, references)); +}; +var Visit16 = function(schema, references) { + const references_ = IsString(schema.$id) ? [...references, schema] : references; + const schema_ = schema; + if (schema.$id && visited.has(schema.$id)) + return false; + if (schema.$id) + visited.add(schema.$id); + switch (schema[Kind]) { + case "Array": + return FromArray13(schema_, references_); + case "AsyncIterator": + return FromAsyncIterator5(schema_, references_); + case "Constructor": + return FromConstructor6(schema_, references_); + case "Function": + return FromFunction5(schema_, references_); + case "Intersect": + return FromIntersect13(schema_, references_); + case "Iterator": + return FromIterator5(schema_, references_); + case "Not": + return FromNot7(schema_, references_); + case "Object": + return FromObject11(schema_, references_); + case "Promise": + return FromPromise5(schema_, references_); + case "Record": + return FromRecord11(schema_, references_); + case "Ref": + return FromRef10(schema_, references_); + case "This": + return FromThis10(schema_, references_); + case "Tuple": + return FromTuple13(schema_, references_); + case "Union": + return FromUnion15(schema_, references_); + default: + return IsTransform(schema); + } +}; +function HasTransform(schema, references) { + visited.clear(); + return Visit16(schema, references); +} +var visited = new Set; +// node_modules/@sinclair/typebox/build/import/value/value/value.mjs +var exports_value2 = {}; +__export(exports_value2, { + Patch: () => { + { + return Patch2; + } + }, + Mutate: () => { + { + return Mutate2; + } + }, + Hash: () => { + { + return Hash2; + } + }, + Errors: () => { + { + return Errors2; + } + }, + Equal: () => { + { + return Equal2; + } + }, + Encode: () => { + { + return Encode; + } + }, + Diff: () => { + { + return Diff2; + } + }, + Default: () => { + { + return Default6; + } + }, + Decode: () => { + { + return Decode; + } + }, + Create: () => { + { + return Create3; + } + }, + Convert: () => { + { + return Convert2; + } + }, + Clone: () => { + { + return Clone3; + } + }, + Clean: () => { + { + return Clean2; + } + }, + Check: () => { + { + return Check2; + } + }, + Cast: () => { + { + return Cast2; + } + } +}); +function Cast2(...args) { + return Cast.apply(Cast, args); +} +function Create3(...args) { + return Create2.apply(Create2, args); +} +function Check2(...args) { + return Check.apply(Check, args); +} +function Clean2(...args) { + return Clean.apply(Clean, args); +} +function Convert2(...args) { + return Convert.apply(Convert, args); +} +function Clone3(value3) { + return Clone2(value3); +} +function Decode(...args) { + const [schema, references, value3] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]]; + if (!Check2(schema, references, value3)) + throw new TransformDecodeCheckError(schema, value3, Errors2(schema, references, value3).First()); + return TransformDecode(schema, references, value3); +} +function Default6(...args) { + return Default3.apply(Default3, args); +} +function Encode(...args) { + const [schema, references, value3] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]]; + const encoded = TransformEncode(schema, references, value3); + if (!Check2(schema, references, encoded)) + throw new TransformEncodeCheckError(schema, encoded, Errors2(schema, references, encoded).First()); + return encoded; +} +function Errors2(...args) { + return Errors.apply(Errors, args); +} +function Equal2(left, right) { + return Equal(left, right); +} +function Diff2(current, next) { + return Diff(current, next); +} +function Hash2(value3) { + return Hash(value3); +} +function Patch2(current, edits) { + return Patch(current, edits); +} +function Mutate2(current, next) { + Mutate(current, next); +} +// node_modules/@sinclair/typebox/build/import/type/awaited/awaited.mjs +var FromRest4 = function(T) { + return T.map((L) => AwaitedResolve(L)); +}; +var FromIntersect14 = function(T) { + return Intersect(FromRest4(T)); +}; +var FromUnion16 = function(T) { + return Union(FromRest4(T)); +}; +var FromPromise6 = function(T) { + return AwaitedResolve(T); +}; +var AwaitedResolve = function(T) { + return IsIntersect(T) ? FromIntersect14(T.allOf) : IsUnion(T) ? FromUnion16(T.anyOf) : IsPromise2(T) ? FromPromise6(T.item) : T; +}; +function Awaited(T, options = {}) { + return CloneType(AwaitedResolve(T), options); +} +// node_modules/@sinclair/typebox/build/import/type/composite/composite.mjs +var CompositeKeys = function(T) { + return T.reduce((Acc, L) => { + return SetDistinct([...Acc, ...KeyOfPropertyKeys(L)]); + }, []); +}; +var FilterNever = function(T) { + return T.filter((L) => !IsNever(L)); +}; +var CompositeProperty = function(T, K) { + return T.reduce((Acc, L) => { + return FilterNever([...Acc, ...IndexFromPropertyKeys(L, [K])]); + }, []); +}; +var CompositeProperties = function(T, K) { + return K.reduce((Acc, L) => { + return { ...Acc, [L]: IntersectEvaluated(CompositeProperty(T, L)) }; + }, {}); +}; +function Composite(T, options = {}) { + const K = CompositeKeys(T); + const P = CompositeProperties(T, K); + const R = Object2(P, options); + return R; +} +// node_modules/@sinclair/typebox/build/import/type/date/date.mjs +function Date2(options = {}) { + return { + ...options, + [Kind]: "Date", + type: "Date" + }; +} +// node_modules/@sinclair/typebox/build/import/type/null/null.mjs +function Null(options = {}) { + return { + ...options, + [Kind]: "Null", + type: "null" + }; +} +// node_modules/@sinclair/typebox/build/import/type/symbol/symbol.mjs +function Symbol2(options) { + return { ...options, [Kind]: "Symbol", type: "symbol" }; +} +// node_modules/@sinclair/typebox/build/import/type/undefined/undefined.mjs +function Undefined(options = {}) { + return { ...options, [Kind]: "Undefined", type: "undefined" }; +} +// node_modules/@sinclair/typebox/build/import/type/uint8array/uint8array.mjs +function Uint8Array2(options = {}) { + return { ...options, [Kind]: "Uint8Array", type: "Uint8Array" }; +} +// node_modules/@sinclair/typebox/build/import/type/const/const.mjs +var FromArray14 = function(T) { + return T.map((L) => FromValue(L, false)); +}; +var FromProperties8 = function(value5) { + return globalThis.Object.getOwnPropertyNames(value5).reduce((acc, key) => { + return { ...acc, [key]: Readonly(FromValue(value5[key], false)) }; + }, {}); +}; +var ConditionalReadonly = function(T, root) { + return root === true ? T : Readonly(T); +}; +var FromValue = function(value5, root) { + return IsAsyncIterator2(value5) ? ConditionalReadonly(Any(), root) : IsIterator2(value5) ? ConditionalReadonly(Any(), root) : IsArray2(value5) ? Readonly(Tuple(FromArray14(value5))) : IsUint8Array2(value5) ? Uint8Array2() : IsDate2(value5) ? Date2() : IsObject2(value5) ? ConditionalReadonly(Object2(FromProperties8(value5)), root) : IsFunction2(value5) ? ConditionalReadonly(Function2([], Unknown()), root) : IsUndefined2(value5) ? Undefined() : IsNull2(value5) ? Null() : IsSymbol2(value5) ? Symbol2() : IsBigInt2(value5) ? BigInt2() : IsNumber2(value5) ? Literal(value5) : IsBoolean2(value5) ? Literal(value5) : IsString2(value5) ? Literal(value5) : Object2({}); +}; +function Const(T, options = {}) { + return CloneType(FromValue(T, true), options); +} +// node_modules/@sinclair/typebox/build/import/type/constructor-parameters/constructor-parameters.mjs +function ConstructorParameters(schema, options = {}) { + return Tuple(CloneRest(schema.parameters), { ...options }); +} +// node_modules/@sinclair/typebox/build/import/type/deref/deref.mjs +var FromRest5 = function(schema, references) { + return schema.map((schema2) => Deref2(schema2, references)); +}; +var FromProperties9 = function(properties, references) { + return globalThis.Object.getOwnPropertyNames(properties).reduce((acc, key) => { + return { ...acc, [key]: Deref2(properties[key], references) }; + }, {}); +}; +var FromConstructor7 = function(schema, references) { + schema.parameters = FromRest5(schema.parameters, references); + schema.returns = Deref2(schema.returns, references); + return schema; +}; +var FromFunction6 = function(schema, references) { + schema.parameters = FromRest5(schema.parameters, references); + schema.returns = Deref2(schema.returns, references); + return schema; +}; +var FromIntersect15 = function(schema, references) { + schema.allOf = FromRest5(schema.allOf, references); + return schema; +}; +var FromUnion17 = function(schema, references) { + schema.anyOf = FromRest5(schema.anyOf, references); + return schema; +}; +var FromTuple14 = function(schema, references) { + if (IsUndefined2(schema.items)) + return schema; + schema.items = FromRest5(schema.items, references); + return schema; +}; +var FromArray15 = function(schema, references) { + schema.items = Deref2(schema.items, references); + return schema; +}; +var FromObject12 = function(schema, references) { + schema.properties = FromProperties9(schema.properties, references); + return schema; +}; +var FromPromise7 = function(schema, references) { + schema.item = Deref2(schema.item, references); + return schema; +}; +var FromAsyncIterator6 = function(schema, references) { + schema.items = Deref2(schema.items, references); + return schema; +}; +var FromIterator6 = function(schema, references) { + schema.items = Deref2(schema.items, references); + return schema; +}; +var FromRef11 = function(schema, references) { + const target = references.find((remote) => remote.$id === schema.$ref); + if (target === undefined) + throw Error(`Unable to dereference schema with \$id ${schema.$ref}`); + const discard8 = Discard(target, ["$id"]); + return Deref2(discard8, references); +}; +var DerefResolve = function(schema, references) { + return IsConstructor(schema) ? FromConstructor7(schema, references) : IsFunction3(schema) ? FromFunction6(schema, references) : IsIntersect(schema) ? FromIntersect15(schema, references) : IsUnion(schema) ? FromUnion17(schema, references) : IsTuple(schema) ? FromTuple14(schema, references) : IsArray3(schema) ? FromArray15(schema, references) : IsObject3(schema) ? FromObject12(schema, references) : IsPromise2(schema) ? FromPromise7(schema, references) : IsAsyncIterator3(schema) ? FromAsyncIterator6(schema, references) : IsIterator3(schema) ? FromIterator6(schema, references) : IsRef(schema) ? FromRef11(schema, references) : schema; +}; +function Deref2(schema, references) { + return DerefResolve(CloneType(schema), CloneRest(references)); +} +// node_modules/@sinclair/typebox/build/import/type/enum/enum.mjs +function Enum(item, options = {}) { + if (IsUndefined2(item)) + throw new Error("Enum undefined or empty"); + const values1 = globalThis.Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]); + const values2 = [...new Set(values1)]; + const anyOf = values2.map((value7) => Literal(value7)); + return Union(anyOf, { ...options, [Hint]: "Enum" }); +} +// node_modules/@sinclair/typebox/build/import/type/exclude/exclude-from-template-literal.mjs +function ExcludeFromTemplateLiteral(L, R) { + return Exclude(TemplateLiteralToUnion(L), R); +} + +// node_modules/@sinclair/typebox/build/import/type/exclude/exclude.mjs +var ExcludeRest = function(L, R) { + const excluded = L.filter((inner) => ExtendsCheck(inner, R) === ExtendsResult.False); + return excluded.length === 1 ? excluded[0] : Union(excluded); +}; +function Exclude(L, R, options = {}) { + if (IsTemplateLiteral(L)) + return CloneType(ExcludeFromTemplateLiteral(L, R), options); + if (IsMappedResult(L)) + return CloneType(ExcludeFromMappedResult(L, R), options); + return CloneType(IsUnion(L) ? ExcludeRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options); +} + +// node_modules/@sinclair/typebox/build/import/type/exclude/exclude-from-mapped-result.mjs +var FromProperties10 = function(P, U) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Exclude(P[K2], U) }; + }, {}); +}; +var FromMappedResult7 = function(R, T) { + return FromProperties10(R.properties, T); +}; +function ExcludeFromMappedResult(R, T) { + const P = FromMappedResult7(R, T); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/extract/extract-from-template-literal.mjs +function ExtractFromTemplateLiteral(L, R) { + return Extract(TemplateLiteralToUnion(L), R); +} + +// node_modules/@sinclair/typebox/build/import/type/extract/extract.mjs +var ExtractRest = function(L, R) { + const extracted = L.filter((inner) => ExtendsCheck(inner, R) !== ExtendsResult.False); + return extracted.length === 1 ? extracted[0] : Union(extracted); +}; +function Extract(L, R, options = {}) { + if (IsTemplateLiteral(L)) + return CloneType(ExtractFromTemplateLiteral(L, R), options); + if (IsMappedResult(L)) + return CloneType(ExtractFromMappedResult(L, R), options); + return CloneType(IsUnion(L) ? ExtractRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options); +} + +// node_modules/@sinclair/typebox/build/import/type/extract/extract-from-mapped-result.mjs +var FromProperties11 = function(P, T) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Extract(P[K2], T) }; + }, {}); +}; +var FromMappedResult8 = function(R, T) { + return FromProperties11(R.properties, T); +}; +function ExtractFromMappedResult(R, T) { + const P = FromMappedResult8(R, T); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/instance-type/instance-type.mjs +function InstanceType(schema, options = {}) { + return CloneType(schema.returns, options); +} +// node_modules/@sinclair/typebox/build/import/type/integer/integer.mjs +function Integer(options = {}) { + return { + ...options, + [Kind]: "Integer", + type: "integer" + }; +} +// node_modules/@sinclair/typebox/build/import/type/intrinsic/intrinsic-from-mapped-key.mjs +var MappedIntrinsicPropertyKey = function(K, M, options) { + return { + [K]: Intrinsic(Literal(K), M, options) + }; +}; +var MappedIntrinsicPropertyKeys = function(K, M, options) { + return K.reduce((Acc, L) => { + return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) }; + }, {}); +}; +var MappedIntrinsicProperties = function(T, M, options) { + return MappedIntrinsicPropertyKeys(T["keys"], M, options); +}; +function IntrinsicFromMappedKey(T, M, options) { + const P = MappedIntrinsicProperties(T, M, options); + return MappedResult(P); +} + +// node_modules/@sinclair/typebox/build/import/type/intrinsic/intrinsic.mjs +var ApplyUncapitalize = function(value7) { + const [first, rest] = [value7.slice(0, 1), value7.slice(1)]; + return [first.toLowerCase(), rest].join(""); +}; +var ApplyCapitalize = function(value7) { + const [first, rest] = [value7.slice(0, 1), value7.slice(1)]; + return [first.toUpperCase(), rest].join(""); +}; +var ApplyUppercase = function(value7) { + return value7.toUpperCase(); +}; +var ApplyLowercase = function(value7) { + return value7.toLowerCase(); +}; +var FromTemplateLiteral6 = function(schema, mode, options) { + const expression = TemplateLiteralParseExact(schema.pattern); + const finite3 = IsTemplateLiteralExpressionFinite(expression); + if (!finite3) + return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) }; + const strings = [...TemplateLiteralExpressionGenerate(expression)]; + const literals = strings.map((value7) => Literal(value7)); + const mapped12 = FromRest6(literals, mode); + const union15 = Union(mapped12); + return TemplateLiteral([union15], options); +}; +var FromLiteralValue = function(value7, mode) { + return typeof value7 === "string" ? mode === "Uncapitalize" ? ApplyUncapitalize(value7) : mode === "Capitalize" ? ApplyCapitalize(value7) : mode === "Uppercase" ? ApplyUppercase(value7) : mode === "Lowercase" ? ApplyLowercase(value7) : value7 : value7.toString(); +}; +var FromRest6 = function(T, M) { + return T.map((L) => Intrinsic(L, M)); +}; +function Intrinsic(schema, mode, options = {}) { + return IsMappedKey(schema) ? IntrinsicFromMappedKey(schema, mode, options) : IsTemplateLiteral(schema) ? FromTemplateLiteral6(schema, mode, schema) : IsUnion(schema) ? Union(FromRest6(schema.anyOf, mode), options) : IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) : schema; +} + +// node_modules/@sinclair/typebox/build/import/type/intrinsic/capitalize.mjs +function Capitalize(T, options = {}) { + return Intrinsic(T, "Capitalize", options); +} +// node_modules/@sinclair/typebox/build/import/type/intrinsic/lowercase.mjs +function Lowercase(T, options = {}) { + return Intrinsic(T, "Lowercase", options); +} +// node_modules/@sinclair/typebox/build/import/type/intrinsic/uncapitalize.mjs +function Uncapitalize(T, options = {}) { + return Intrinsic(T, "Uncapitalize", options); +} +// node_modules/@sinclair/typebox/build/import/type/intrinsic/uppercase.mjs +function Uppercase(T, options = {}) { + return Intrinsic(T, "Uppercase", options); +} +// node_modules/@sinclair/typebox/build/import/type/not/not.mjs +function Not2(schema, options) { + return { + ...options, + [Kind]: "Not", + not: CloneType(schema) + }; +} +// node_modules/@sinclair/typebox/build/import/type/omit/omit-from-mapped-result.mjs +var FromProperties12 = function(P, K, options) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Omit(P[K2], K, options) }; + }, {}); +}; +var FromMappedResult9 = function(R, K, options) { + return FromProperties12(R.properties, K, options); +}; +function OmitFromMappedResult(R, K, options) { + const P = FromMappedResult9(R, K, options); + return MappedResult(P); +} + +// node_modules/@sinclair/typebox/build/import/type/omit/omit.mjs +var FromIntersect16 = function(T, K) { + return T.map((T2) => OmitResolve(T2, K)); +}; +var FromUnion18 = function(T, K) { + return T.map((T2) => OmitResolve(T2, K)); +}; +var FromProperty2 = function(T, K) { + const { [K]: _, ...R } = T; + return R; +}; +var FromProperties13 = function(T, K) { + return K.reduce((T2, K2) => { + return FromProperty2(T2, K2); + }, T); +}; +var OmitResolve = function(T, K) { + return IsIntersect(T) ? Intersect(FromIntersect16(T.allOf, K)) : IsUnion(T) ? Union(FromUnion18(T.anyOf, K)) : IsObject3(T) ? Object2(FromProperties13(T.properties, K)) : Object2({}); +}; +function Omit(T, K, options = {}) { + if (IsMappedKey(K)) + return OmitFromMappedKey(T, K, options); + if (IsMappedResult(T)) + return OmitFromMappedResult(T, K, options); + const I = IsSchema(K) ? IndexPropertyKeys(K) : K; + const D = Discard(T, [TransformKind, "$id", "required"]); + const R = CloneType(OmitResolve(T, I), options); + return { ...D, ...R }; +} + +// node_modules/@sinclair/typebox/build/import/type/omit/omit-from-mapped-key.mjs +var FromPropertyKey2 = function(T, K, options) { + return { + [K]: Omit(T, [K], options) + }; +}; +var FromPropertyKeys2 = function(T, K, options) { + return K.reduce((Acc, LK) => { + return { ...Acc, ...FromPropertyKey2(T, LK, options) }; + }, {}); +}; +var FromMappedKey3 = function(T, K, options) { + return FromPropertyKeys2(T, K.keys, options); +}; +function OmitFromMappedKey(T, K, options) { + const P = FromMappedKey3(T, K, options); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/parameters/parameters.mjs +function Parameters(schema, options = {}) { + return Tuple(CloneRest(schema.parameters), { ...options }); +} +// node_modules/@sinclair/typebox/build/import/type/partial/partial.mjs +var FromRest7 = function(T) { + return T.map((L) => PartialResolve(L)); +}; +var FromProperties14 = function(T) { + return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K) => { + return { ...Acc, [K]: Optional(T[K]) }; + }, {}); +}; +var PartialResolve = function(T) { + return IsIntersect(T) ? Intersect(FromRest7(T.allOf)) : IsUnion(T) ? Union(FromRest7(T.anyOf)) : IsObject3(T) ? Object2(FromProperties14(T.properties)) : Object2({}); +}; +function Partial(T, options = {}) { + if (IsMappedResult(T)) + return PartialFromMappedResult(T, options); + const D = Discard(T, [TransformKind, "$id", "required"]); + const R = CloneType(PartialResolve(T), options); + return { ...D, ...R }; +} + +// node_modules/@sinclair/typebox/build/import/type/partial/partial-from-mapped-result.mjs +var FromProperties15 = function(K, options) { + return globalThis.Object.getOwnPropertyNames(K).reduce((Acc, K2) => { + return { ...Acc, [K2]: Partial(K[K2], options) }; + }, {}); +}; +var FromMappedResult10 = function(R, options) { + return FromProperties15(R.properties, options); +}; +function PartialFromMappedResult(R, options) { + const P = FromMappedResult10(R, options); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/pick/pick-from-mapped-result.mjs +var FromProperties16 = function(P, K, options) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Pick(P[K2], K, options) }; + }, {}); +}; +var FromMappedResult11 = function(R, K, options) { + return FromProperties16(R.properties, K, options); +}; +function PickFromMappedResult(R, K, options) { + const P = FromMappedResult11(R, K, options); + return MappedResult(P); +} + +// node_modules/@sinclair/typebox/build/import/type/pick/pick.mjs +var FromIntersect17 = function(T, K) { + return T.map((T2) => PickResolve(T2, K)); +}; +var FromUnion19 = function(T, K) { + return T.map((T2) => PickResolve(T2, K)); +}; +var FromProperties17 = function(T, K) { + return K.reduce((Acc, K2) => { + return K2 in T ? { ...Acc, [K2]: T[K2] } : Acc; + }, {}); +}; +var PickResolve = function(T, K) { + return IsIntersect(T) ? Intersect(FromIntersect17(T.allOf, K)) : IsUnion(T) ? Union(FromUnion19(T.anyOf, K)) : IsObject3(T) ? Object2(FromProperties17(T.properties, K)) : Object2({}); +}; +function Pick(T, K, options = {}) { + if (IsMappedKey(K)) + return PickFromMappedKey(T, K, options); + if (IsMappedResult(T)) + return PickFromMappedResult(T, K, options); + const I = IsSchema(K) ? IndexPropertyKeys(K) : K; + const D = Discard(T, [TransformKind, "$id", "required"]); + const R = CloneType(PickResolve(T, I), options); + return { ...D, ...R }; +} + +// node_modules/@sinclair/typebox/build/import/type/pick/pick-from-mapped-key.mjs +var FromPropertyKey3 = function(T, K, options) { + return { + [K]: Pick(T, [K], options) + }; +}; +var FromPropertyKeys3 = function(T, K, options) { + return K.reduce((Acc, LK) => { + return { ...Acc, ...FromPropertyKey3(T, LK, options) }; + }, {}); +}; +var FromMappedKey4 = function(T, K, options) { + return FromPropertyKeys3(T, K.keys, options); +}; +function PickFromMappedKey(T, K, options) { + const P = FromMappedKey4(T, K, options); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/readonly-optional/readonly-optional.mjs +function ReadonlyOptional(schema) { + return Readonly(Optional(schema)); +} +// node_modules/@sinclair/typebox/build/import/type/record/record.mjs +var RecordCreateFromPattern = function(pattern3, T, options) { + return { + ...options, + [Kind]: "Record", + type: "object", + patternProperties: { [pattern3]: CloneType(T) } + }; +}; +var RecordCreateFromKeys = function(K, T, options) { + const P = K.reduce((Acc, K2) => ({ ...Acc, [K2]: CloneType(T) }), {}); + return Object2(P, { ...options, [Hint]: "Record" }); +}; +var FromTemplateLiteralKey = function(K, T, options) { + return IsTemplateLiteralFinite(K) ? RecordCreateFromKeys(IndexPropertyKeys(K), T, options) : RecordCreateFromPattern(K.pattern, T, options); +}; +var FromUnionKey = function(K, T, options) { + return RecordCreateFromKeys(IndexPropertyKeys(Union(K)), T, options); +}; +var FromLiteralKey = function(K, T, options) { + return RecordCreateFromKeys([K.toString()], T, options); +}; +var FromRegExpKey = function(K, T, options) { + return RecordCreateFromPattern(K.source, T, options); +}; +var FromStringKey = function(K, T, options) { + const pattern3 = IsUndefined2(K.pattern) ? PatternStringExact : K.pattern; + return RecordCreateFromPattern(pattern3, T, options); +}; +var FromIntegerKey = function(_, T, options) { + return RecordCreateFromPattern(PatternNumberExact, T, options); +}; +var FromNumberKey = function(_, T, options) { + return RecordCreateFromPattern(PatternNumberExact, T, options); +}; +function Record(K, T, options = {}) { + return IsUnion(K) ? FromUnionKey(K.anyOf, T, options) : IsTemplateLiteral(K) ? FromTemplateLiteralKey(K, T, options) : IsLiteral(K) ? FromLiteralKey(K.const, T, options) : IsInteger2(K) ? FromIntegerKey(K, T, options) : IsNumber3(K) ? FromNumberKey(K, T, options) : IsRegExp2(K) ? FromRegExpKey(K, T, options) : IsString3(K) ? FromStringKey(K, T, options) : Never(options); +} +// node_modules/@sinclair/typebox/build/import/type/recursive/recursive.mjs +function Recursive(callback, options = {}) { + if (IsUndefined2(options.$id)) + options.$id = `T${Ordinal++}`; + const thisType = callback({ [Kind]: "This", $ref: `${options.$id}` }); + thisType.$id = options.$id; + return CloneType({ ...options, [Hint]: "Recursive", ...thisType }); +} +var Ordinal = 0; +// node_modules/@sinclair/typebox/build/import/type/ref/ref.mjs +function Ref(unresolved, options = {}) { + if (IsString2(unresolved)) + return { ...options, [Kind]: "Ref", $ref: unresolved }; + if (IsUndefined2(unresolved.$id)) + throw new Error("Reference target type must specify an $id"); + return { + ...options, + [Kind]: "Ref", + $ref: unresolved.$id + }; +} +// node_modules/@sinclair/typebox/build/import/type/regexp/regexp.mjs +function RegExp2(unresolved, options = {}) { + const expr = IsString2(unresolved) ? new globalThis.RegExp(unresolved) : unresolved; + return { ...options, [Kind]: "RegExp", type: "RegExp", source: expr.source, flags: expr.flags }; +} +// node_modules/@sinclair/typebox/build/import/type/required/required.mjs +var FromRest8 = function(T) { + return T.map((L) => RequiredResolve(L)); +}; +var FromProperties18 = function(T) { + return globalThis.Object.getOwnPropertyNames(T).reduce((Acc, K) => { + return { ...Acc, [K]: Discard(T[K], [OptionalKind]) }; + }, {}); +}; +var RequiredResolve = function(T) { + return IsIntersect(T) ? Intersect(FromRest8(T.allOf)) : IsUnion(T) ? Union(FromRest8(T.anyOf)) : IsObject3(T) ? Object2(FromProperties18(T.properties)) : Object2({}); +}; +function Required(T, options = {}) { + if (IsMappedResult(T)) { + return RequiredFromMappedResult(T, options); + } else { + const D = Discard(T, [TransformKind, "$id", "required"]); + const R = CloneType(RequiredResolve(T), options); + return { ...D, ...R }; + } +} + +// node_modules/@sinclair/typebox/build/import/type/required/required-from-mapped-result.mjs +var FromProperties19 = function(P, options) { + return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => { + return { ...Acc, [K2]: Required(P[K2], options) }; + }, {}); +}; +var FromMappedResult12 = function(R, options) { + return FromProperties19(R.properties, options); +}; +function RequiredFromMappedResult(R, options) { + const P = FromMappedResult12(R, options); + return MappedResult(P); +} +// node_modules/@sinclair/typebox/build/import/type/rest/rest.mjs +var RestResolve = function(T) { + return IsIntersect(T) ? [...T.allOf] : IsUnion(T) ? [...T.anyOf] : IsTuple(T) ? [...T.items ?? []] : []; +}; +function Rest(T) { + return CloneRest(RestResolve(T)); +} +// node_modules/@sinclair/typebox/build/import/type/return-type/return-type.mjs +function ReturnType(schema, options = {}) { + return CloneType(schema.returns, options); +} +// node_modules/@sinclair/typebox/build/import/type/strict/strict.mjs +function Strict(schema2) { + return JSON.parse(JSON.stringify(schema2)); +} +// node_modules/@sinclair/typebox/build/import/type/transform/transform.mjs +function Transform(schema2) { + return new TransformDecodeBuilder(schema2); +} + +class TransformDecodeBuilder { + schema; + constructor(schema2) { + this.schema = schema2; + } + Decode(decode2) { + return new TransformEncodeBuilder(this.schema, decode2); + } +} + +class TransformEncodeBuilder { + schema; + decode; + constructor(schema2, decode2) { + this.schema = schema2; + this.decode = decode2; + } + EncodeTransform(encode2, schema2) { + const Encode2 = (value11) => schema2[TransformKind].Encode(encode2(value11)); + const Decode2 = (value11) => this.decode(schema2[TransformKind].Decode(value11)); + const Codec = { Encode: Encode2, Decode: Decode2 }; + return { ...schema2, [TransformKind]: Codec }; + } + EncodeSchema(encode2, schema2) { + const Codec = { Decode: this.decode, Encode: encode2 }; + return { ...schema2, [TransformKind]: Codec }; + } + Encode(encode2) { + const schema2 = CloneType(this.schema); + return IsTransform(schema2) ? this.EncodeTransform(encode2, schema2) : this.EncodeSchema(encode2, schema2); + } +} +// node_modules/@sinclair/typebox/build/import/type/void/void.mjs +function Void(options = {}) { + return { + ...options, + [Kind]: "Void", + type: "void" + }; +} +// node_modules/@sinclair/typebox/build/import/type/type/type.mjs +var exports_type3 = {}; +__export(exports_type3, { + Void: () => { + { + return Void; + } + }, + Uppercase: () => { + { + return Uppercase; + } + }, + Unsafe: () => { + { + return Unsafe; + } + }, + Unknown: () => { + { + return Unknown; + } + }, + Union: () => { + { + return Union; + } + }, + Undefined: () => { + { + return Undefined; + } + }, + Uncapitalize: () => { + { + return Uncapitalize; + } + }, + Uint8Array: () => { + { + return Uint8Array2; + } + }, + Tuple: () => { + { + return Tuple; + } + }, + Transform: () => { + { + return Transform; + } + }, + TemplateLiteral: () => { + { + return TemplateLiteral; + } + }, + Symbol: () => { + { + return Symbol2; + } + }, + String: () => { + { + return String2; + } + }, + Strict: () => { + { + return Strict; + } + }, + ReturnType: () => { + { + return ReturnType; + } + }, + Rest: () => { + { + return Rest; + } + }, + Required: () => { + { + return Required; + } + }, + RegExp: () => { + { + return RegExp2; + } + }, + Ref: () => { + { + return Ref; + } + }, + Recursive: () => { + { + return Recursive; + } + }, + Record: () => { + { + return Record; + } + }, + ReadonlyOptional: () => { + { + return ReadonlyOptional; + } + }, + Readonly: () => { + { + return Readonly; + } + }, + Promise: () => { + { + return Promise2; + } + }, + Pick: () => { + { + return Pick; + } + }, + Partial: () => { + { + return Partial; + } + }, + Parameters: () => { + { + return Parameters; + } + }, + Optional: () => { + { + return Optional; + } + }, + Omit: () => { + { + return Omit; + } + }, + Object: () => { + { + return Object2; + } + }, + Number: () => { + { + return Number2; + } + }, + Null: () => { + { + return Null; + } + }, + Not: () => { + { + return Not2; + } + }, + Never: () => { + { + return Never; + } + }, + Mapped: () => { + { + return Mapped; + } + }, + Lowercase: () => { + { + return Lowercase; + } + }, + Literal: () => { + { + return Literal; + } + }, + KeyOf: () => { + { + return KeyOf; + } + }, + Iterator: () => { + { + return Iterator; + } + }, + Intersect: () => { + { + return Intersect; + } + }, + Integer: () => { + { + return Integer; + } + }, + InstanceType: () => { + { + return InstanceType; + } + }, + Index: () => { + { + return Index; + } + }, + Function: () => { + { + return Function2; + } + }, + Extract: () => { + { + return Extract; + } + }, + Extends: () => { + { + return Extends; + } + }, + Exclude: () => { + { + return Exclude; + } + }, + Enum: () => { + { + return Enum; + } + }, + Deref: () => { + { + return Deref2; + } + }, + Date: () => { + { + return Date2; + } + }, + ConstructorParameters: () => { + { + return ConstructorParameters; + } + }, + Constructor: () => { + { + return Constructor; + } + }, + Const: () => { + { + return Const; + } + }, + Composite: () => { + { + return Composite; + } + }, + Capitalize: () => { + { + return Capitalize; + } + }, + Boolean: () => { + { + return Boolean2; + } + }, + BigInt: () => { + { + return BigInt2; + } + }, + Awaited: () => { + { + return Awaited; + } + }, + AsyncIterator: () => { + { + return AsyncIterator; + } + }, + Array: () => { + { + return Array2; + } + }, + Any: () => { + { + return Any; + } + } +}); + +// node_modules/@sinclair/typebox/build/import/type/type/index.mjs +var Type = exports_type3; +// node_modules/@sinclair/typebox/build/import/compiler/compiler.mjs +class TypeCheck { + schema; + references; + checkFunc; + code; + hasTransform; + constructor(schema3, references, checkFunc, code) { + this.schema = schema3; + this.references = references; + this.checkFunc = checkFunc; + this.code = code; + this.hasTransform = HasTransform(schema3, references); + } + Code() { + return this.code; + } + Errors(value11) { + return Errors(this.schema, this.references, value11); + } + Check(value11) { + return this.checkFunc(value11); + } + Decode(value11) { + if (!this.checkFunc(value11)) + throw new TransformDecodeCheckError(this.schema, value11, this.Errors(value11).First()); + return this.hasTransform ? TransformDecode(this.schema, this.references, value11) : value11; + } + Encode(value11) { + const encoded = this.hasTransform ? TransformEncode(this.schema, this.references, value11) : value11; + if (!this.checkFunc(encoded)) + throw new TransformEncodeCheckError(this.schema, value11, this.Errors(value11).First()); + return encoded; + } +} +var Character; +(function(Character2) { + function DollarSign(code) { + return code === 36; + } + Character2.DollarSign = DollarSign; + function IsUnderscore(code) { + return code === 95; + } + Character2.IsUnderscore = IsUnderscore; + function IsAlpha(code) { + return code >= 65 && code <= 90 || code >= 97 && code <= 122; + } + Character2.IsAlpha = IsAlpha; + function IsNumeric(code) { + return code >= 48 && code <= 57; + } + Character2.IsNumeric = IsNumeric; +})(Character || (Character = {})); +var MemberExpression; +(function(MemberExpression2) { + function IsFirstCharacterNumeric(value11) { + if (value11.length === 0) + return false; + return Character.IsNumeric(value11.charCodeAt(0)); + } + function IsAccessor(value11) { + if (IsFirstCharacterNumeric(value11)) + return false; + for (let i = 0;i < value11.length; i++) { + const code = value11.charCodeAt(i); + const check11 = Character.IsAlpha(code) || Character.IsNumeric(code) || Character.DollarSign(code) || Character.IsUnderscore(code); + if (!check11) + return false; + } + return true; + } + function EscapeHyphen(key) { + return key.replace(/'/g, "\\'"); + } + function Encode2(object13, key) { + return IsAccessor(key) ? `${object13}.${key}` : `${object13}['${EscapeHyphen(key)}']`; + } + MemberExpression2.Encode = Encode2; +})(MemberExpression || (MemberExpression = {})); +var Identifier; +(function(Identifier2) { + function Encode2($id) { + const buffer = []; + for (let i = 0;i < $id.length; i++) { + const code = $id.charCodeAt(i); + if (Character.IsNumeric(code) || Character.IsAlpha(code)) { + buffer.push($id.charAt(i)); + } else { + buffer.push(`_${code}_`); + } + } + return buffer.join("").replace(/__/g, "_"); + } + Identifier2.Encode = Encode2; +})(Identifier || (Identifier = {})); +var LiteralString; +(function(LiteralString2) { + function Escape3(content) { + return content.replace(/'/g, "\\'"); + } + LiteralString2.Escape = Escape3; +})(LiteralString || (LiteralString = {})); + +class TypeCompilerUnknownTypeError extends TypeBoxError { + schema; + constructor(schema3) { + super("Unknown type"); + this.schema = schema3; + } +} + +class TypeCompilerTypeGuardError extends TypeBoxError { + schema; + constructor(schema3) { + super("Preflight validation check failed to guard for the given schema"); + this.schema = schema3; + } +} +var Policy; +(function(Policy2) { + function IsExactOptionalProperty(value11, key, expression) { + return TypeSystemPolicy.ExactOptionalPropertyTypes ? `('${key}' in ${value11} ? ${expression} : true)` : `(${MemberExpression.Encode(value11, key)} !== undefined ? ${expression} : true)`; + } + Policy2.IsExactOptionalProperty = IsExactOptionalProperty; + function IsObjectLike(value11) { + return !TypeSystemPolicy.AllowArrayObject ? `(typeof ${value11} === 'object' && ${value11} !== null && !Array.isArray(${value11}))` : `(typeof ${value11} === 'object' && ${value11} !== null)`; + } + Policy2.IsObjectLike = IsObjectLike; + function IsRecordLike(value11) { + return !TypeSystemPolicy.AllowArrayObject ? `(typeof ${value11} === 'object' && ${value11} !== null && !Array.isArray(${value11}) && !(${value11} instanceof Date) && !(${value11} instanceof Uint8Array))` : `(typeof ${value11} === 'object' && ${value11} !== null && !(${value11} instanceof Date) && !(${value11} instanceof Uint8Array))`; + } + Policy2.IsRecordLike = IsRecordLike; + function IsNumberLike(value11) { + return !TypeSystemPolicy.AllowNaN ? `(typeof ${value11} === 'number' && Number.isFinite(${value11}))` : `typeof ${value11} === 'number'`; + } + Policy2.IsNumberLike = IsNumberLike; + function IsVoidLike(value11) { + return TypeSystemPolicy.AllowNullVoid ? `(${value11} === undefined || ${value11} === null)` : `${value11} === undefined`; + } + Policy2.IsVoidLike = IsVoidLike; +})(Policy || (Policy = {})); +var TypeCompiler; +(function(TypeCompiler2) { + function IsAnyOrUnknown2(schema3) { + return schema3[Kind] === "Any" || schema3[Kind] === "Unknown"; + } + function* FromAny5(schema3, references, value11) { + yield "true"; + } + function* FromArray16(schema3, references, value11) { + yield `Array.isArray(${value11})`; + const [parameter, accumulator] = [CreateParameter("value", "any"), CreateParameter("acc", "number")]; + if (IsNumber(schema3.maxItems)) + yield `${value11}.length <= ${schema3.maxItems}`; + if (IsNumber(schema3.minItems)) + yield `${value11}.length >= ${schema3.minItems}`; + const elementExpression = CreateExpression(schema3.items, references, "value"); + yield `${value11}.every((${parameter}) => ${elementExpression})`; + if (IsSchema(schema3.contains) || IsNumber(schema3.minContains) || IsNumber(schema3.maxContains)) { + const containsSchema = IsSchema(schema3.contains) ? schema3.contains : Never(); + const checkExpression = CreateExpression(containsSchema, references, "value"); + const checkMinContains = IsNumber(schema3.minContains) ? [`(count >= ${schema3.minContains})`] : []; + const checkMaxContains = IsNumber(schema3.maxContains) ? [`(count <= ${schema3.maxContains})`] : []; + const checkCount = `const count = value.reduce((${accumulator}, ${parameter}) => ${checkExpression} ? acc + 1 : acc, 0)`; + const check11 = [`(count > 0)`, ...checkMinContains, ...checkMaxContains].join(" && "); + yield `((${parameter}) => { ${checkCount}; return ${check11}})(${value11})`; + } + if (schema3.uniqueItems === true) { + const check11 = `const hashed = hash(element); if(set.has(hashed)) { return false } else { set.add(hashed) } } return true`; + const block = `const set = new Set(); for(const element of value) { ${check11} }`; + yield `((${parameter}) => { ${block} )(${value11})`; + } + } + function* FromAsyncIterator7(schema3, references, value11) { + yield `(typeof value === 'object' && Symbol.asyncIterator in ${value11})`; + } + function* FromBigInt6(schema3, references, value11) { + yield `(typeof ${value11} === 'bigint')`; + if (IsBigInt(schema3.exclusiveMaximum)) + yield `${value11} < BigInt(${schema3.exclusiveMaximum})`; + if (IsBigInt(schema3.exclusiveMinimum)) + yield `${value11} > BigInt(${schema3.exclusiveMinimum})`; + if (IsBigInt(schema3.maximum)) + yield `${value11} <= BigInt(${schema3.maximum})`; + if (IsBigInt(schema3.minimum)) + yield `${value11} >= BigInt(${schema3.minimum})`; + if (IsBigInt(schema3.multipleOf)) + yield `(${value11} % BigInt(${schema3.multipleOf})) === 0`; + } + function* FromBoolean6(schema3, references, value11) { + yield `(typeof ${value11} === 'boolean')`; + } + function* FromConstructor8(schema3, references, value11) { + yield* Visit17(schema3.returns, references, `${value11}.prototype`); + } + function* FromDate6(schema3, references, value11) { + yield `(${value11} instanceof Date) && Number.isFinite(${value11}.getTime())`; + if (IsNumber(schema3.exclusiveMaximumTimestamp)) + yield `${value11}.getTime() < ${schema3.exclusiveMaximumTimestamp}`; + if (IsNumber(schema3.exclusiveMinimumTimestamp)) + yield `${value11}.getTime() > ${schema3.exclusiveMinimumTimestamp}`; + if (IsNumber(schema3.maximumTimestamp)) + yield `${value11}.getTime() <= ${schema3.maximumTimestamp}`; + if (IsNumber(schema3.minimumTimestamp)) + yield `${value11}.getTime() >= ${schema3.minimumTimestamp}`; + if (IsNumber(schema3.multipleOfTimestamp)) + yield `(${value11}.getTime() % ${schema3.multipleOfTimestamp}) === 0`; + } + function* FromFunction7(schema3, references, value11) { + yield `(typeof ${value11} === 'function')`; + } + function* FromInteger6(schema3, references, value11) { + yield `(typeof ${value11} === 'number' && Number.isInteger(${value11}))`; + if (IsNumber(schema3.exclusiveMaximum)) + yield `${value11} < ${schema3.exclusiveMaximum}`; + if (IsNumber(schema3.exclusiveMinimum)) + yield `${value11} > ${schema3.exclusiveMinimum}`; + if (IsNumber(schema3.maximum)) + yield `${value11} <= ${schema3.maximum}`; + if (IsNumber(schema3.minimum)) + yield `${value11} >= ${schema3.minimum}`; + if (IsNumber(schema3.multipleOf)) + yield `(${value11} % ${schema3.multipleOf}) === 0`; + } + function* FromIntersect18(schema3, references, value11) { + const check1 = schema3.allOf.map((schema4) => CreateExpression(schema4, references, value11)).join(" && "); + if (schema3.unevaluatedProperties === false) { + const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema3))};`); + const check22 = `Object.getOwnPropertyNames(${value11}).every(key => ${keyCheck}.test(key))`; + yield `(${check1} && ${check22})`; + } else if (IsSchema(schema3.unevaluatedProperties)) { + const keyCheck = CreateVariable(`${new RegExp(KeyOfPattern(schema3))};`); + const check22 = `Object.getOwnPropertyNames(${value11}).every(key => ${keyCheck}.test(key) || ${CreateExpression(schema3.unevaluatedProperties, references, `${value11}[key]`)})`; + yield `(${check1} && ${check22})`; + } else { + yield `(${check1})`; + } + } + function* FromIterator7(schema3, references, value11) { + yield `(typeof value === 'object' && Symbol.iterator in ${value11})`; + } + function* FromLiteral7(schema3, references, value11) { + if (typeof schema3.const === "number" || typeof schema3.const === "boolean") { + yield `(${value11} === ${schema3.const})`; + } else { + yield `(${value11} === '${LiteralString.Escape(schema3.const)}')`; + } + } + function* FromNever6(schema3, references, value11) { + yield `false`; + } + function* FromNot8(schema3, references, value11) { + const expression = CreateExpression(schema3.not, references, value11); + yield `(!${expression})`; + } + function* FromNull6(schema3, references, value11) { + yield `(${value11} === null)`; + } + function* FromNumber6(schema3, references, value11) { + yield Policy.IsNumberLike(value11); + if (IsNumber(schema3.exclusiveMaximum)) + yield `${value11} < ${schema3.exclusiveMaximum}`; + if (IsNumber(schema3.exclusiveMinimum)) + yield `${value11} > ${schema3.exclusiveMinimum}`; + if (IsNumber(schema3.maximum)) + yield `${value11} <= ${schema3.maximum}`; + if (IsNumber(schema3.minimum)) + yield `${value11} >= ${schema3.minimum}`; + if (IsNumber(schema3.multipleOf)) + yield `(${value11} % ${schema3.multipleOf}) === 0`; + } + function* FromObject13(schema3, references, value11) { + yield Policy.IsObjectLike(value11); + if (IsNumber(schema3.minProperties)) + yield `Object.getOwnPropertyNames(${value11}).length >= ${schema3.minProperties}`; + if (IsNumber(schema3.maxProperties)) + yield `Object.getOwnPropertyNames(${value11}).length <= ${schema3.maxProperties}`; + const knownKeys = Object.getOwnPropertyNames(schema3.properties); + for (const knownKey of knownKeys) { + const memberExpression = MemberExpression.Encode(value11, knownKey); + const property = schema3.properties[knownKey]; + if (schema3.required && schema3.required.includes(knownKey)) { + yield* Visit17(property, references, memberExpression); + if (ExtendsUndefinedCheck(property) || IsAnyOrUnknown2(property)) + yield `('${knownKey}' in ${value11})`; + } else { + const expression = CreateExpression(property, references, memberExpression); + yield Policy.IsExactOptionalProperty(value11, knownKey, expression); + } + } + if (schema3.additionalProperties === false) { + if (schema3.required && schema3.required.length === knownKeys.length) { + yield `Object.getOwnPropertyNames(${value11}).length === ${knownKeys.length}`; + } else { + const keys = `[${knownKeys.map((key) => `'${key}'`).join(", ")}]`; + yield `Object.getOwnPropertyNames(${value11}).every(key => ${keys}.includes(key))`; + } + } + if (typeof schema3.additionalProperties === "object") { + const expression = CreateExpression(schema3.additionalProperties, references, `${value11}[key]`); + const keys = `[${knownKeys.map((key) => `'${key}'`).join(", ")}]`; + yield `(Object.getOwnPropertyNames(${value11}).every(key => ${keys}.includes(key) || ${expression}))`; + } + } + function* FromPromise8(schema3, references, value11) { + yield `(typeof value === 'object' && typeof ${value11}.then === 'function')`; + } + function* FromRecord12(schema3, references, value11) { + yield Policy.IsRecordLike(value11); + if (IsNumber(schema3.minProperties)) + yield `Object.getOwnPropertyNames(${value11}).length >= ${schema3.minProperties}`; + if (IsNumber(schema3.maxProperties)) + yield `Object.getOwnPropertyNames(${value11}).length <= ${schema3.maxProperties}`; + const [patternKey, patternSchema] = Object.entries(schema3.patternProperties)[0]; + const variable = CreateVariable(`${new RegExp(patternKey)}`); + const check1 = CreateExpression(patternSchema, references, "value"); + const check22 = IsSchema(schema3.additionalProperties) ? CreateExpression(schema3.additionalProperties, references, value11) : schema3.additionalProperties === false ? "false" : "true"; + const expression = `(${variable}.test(key) ? ${check1} : ${check22})`; + yield `(Object.entries(${value11}).every(([key, value]) => ${expression}))`; + } + function* FromRef12(schema3, references, value11) { + const target = Deref(schema3, references); + if (state.functions.has(schema3.$ref)) + return yield `${CreateFunctionName(schema3.$ref)}(${value11})`; + yield* Visit17(target, references, value11); + } + function* FromRegExp5(schema3, references, value11) { + const variable = CreateVariable(`${new RegExp(schema3.source, schema3.flags)};`); + yield `(typeof ${value11} === 'string')`; + if (IsNumber(schema3.maxLength)) + yield `${value11}.length <= ${schema3.maxLength}`; + if (IsNumber(schema3.minLength)) + yield `${value11}.length >= ${schema3.minLength}`; + yield `${variable}.test(${value11})`; + } + function* FromString6(schema3, references, value11) { + yield `(typeof ${value11} === 'string')`; + if (IsNumber(schema3.maxLength)) + yield `${value11}.length <= ${schema3.maxLength}`; + if (IsNumber(schema3.minLength)) + yield `${value11}.length >= ${schema3.minLength}`; + if (schema3.pattern !== undefined) { + const variable = CreateVariable(`${new RegExp(schema3.pattern)};`); + yield `${variable}.test(${value11})`; + } + if (schema3.format !== undefined) { + yield `format('${schema3.format}', ${value11})`; + } + } + function* FromSymbol6(schema3, references, value11) { + yield `(typeof ${value11} === 'symbol')`; + } + function* FromTemplateLiteral7(schema3, references, value11) { + yield `(typeof ${value11} === 'string')`; + const variable = CreateVariable(`${new RegExp(schema3.pattern)};`); + yield `${variable}.test(${value11})`; + } + function* FromThis11(schema3, references, value11) { + yield `${CreateFunctionName(schema3.$ref)}(${value11})`; + } + function* FromTuple15(schema3, references, value11) { + yield `Array.isArray(${value11})`; + if (schema3.items === undefined) + return yield `${value11}.length === 0`; + yield `(${value11}.length === ${schema3.maxItems})`; + for (let i = 0;i < schema3.items.length; i++) { + const expression = CreateExpression(schema3.items[i], references, `${value11}[${i}]`); + yield `${expression}`; + } + } + function* FromUndefined6(schema3, references, value11) { + yield `${value11} === undefined`; + } + function* FromUnion20(schema3, references, value11) { + const expressions = schema3.anyOf.map((schema4) => CreateExpression(schema4, references, value11)); + yield `(${expressions.join(" || ")})`; + } + function* FromUint8Array5(schema3, references, value11) { + yield `${value11} instanceof Uint8Array`; + if (IsNumber(schema3.maxByteLength)) + yield `(${value11}.length <= ${schema3.maxByteLength})`; + if (IsNumber(schema3.minByteLength)) + yield `(${value11}.length >= ${schema3.minByteLength})`; + } + function* FromUnknown5(schema3, references, value11) { + yield "true"; + } + function* FromVoid5(schema3, references, value11) { + yield Policy.IsVoidLike(value11); + } + function* FromKind4(schema3, references, value11) { + const instance = state.instances.size; + state.instances.set(instance, schema3); + yield `kind('${schema3[Kind]}', ${instance}, ${value11})`; + } + function* Visit17(schema3, references, value11, useHoisting = true) { + const references_ = IsString(schema3.$id) ? [...references, schema3] : references; + const schema_ = schema3; + if (useHoisting && IsString(schema3.$id)) { + const functionName = CreateFunctionName(schema3.$id); + if (state.functions.has(functionName)) { + return yield `${functionName}(${value11})`; + } else { + const functionCode = CreateFunction(functionName, schema3, references, "value", false); + state.functions.set(functionName, functionCode); + return yield `${functionName}(${value11})`; + } + } + switch (schema_[Kind]) { + case "Any": + return yield* FromAny5(schema_, references_, value11); + case "Array": + return yield* FromArray16(schema_, references_, value11); + case "AsyncIterator": + return yield* FromAsyncIterator7(schema_, references_, value11); + case "BigInt": + return yield* FromBigInt6(schema_, references_, value11); + case "Boolean": + return yield* FromBoolean6(schema_, references_, value11); + case "Constructor": + return yield* FromConstructor8(schema_, references_, value11); + case "Date": + return yield* FromDate6(schema_, references_, value11); + case "Function": + return yield* FromFunction7(schema_, references_, value11); + case "Integer": + return yield* FromInteger6(schema_, references_, value11); + case "Intersect": + return yield* FromIntersect18(schema_, references_, value11); + case "Iterator": + return yield* FromIterator7(schema_, references_, value11); + case "Literal": + return yield* FromLiteral7(schema_, references_, value11); + case "Never": + return yield* FromNever6(schema_, references_, value11); + case "Not": + return yield* FromNot8(schema_, references_, value11); + case "Null": + return yield* FromNull6(schema_, references_, value11); + case "Number": + return yield* FromNumber6(schema_, references_, value11); + case "Object": + return yield* FromObject13(schema_, references_, value11); + case "Promise": + return yield* FromPromise8(schema_, references_, value11); + case "Record": + return yield* FromRecord12(schema_, references_, value11); + case "Ref": + return yield* FromRef12(schema_, references_, value11); + case "RegExp": + return yield* FromRegExp5(schema_, references_, value11); + case "String": + return yield* FromString6(schema_, references_, value11); + case "Symbol": + return yield* FromSymbol6(schema_, references_, value11); + case "TemplateLiteral": + return yield* FromTemplateLiteral7(schema_, references_, value11); + case "This": + return yield* FromThis11(schema_, references_, value11); + case "Tuple": + return yield* FromTuple15(schema_, references_, value11); + case "Undefined": + return yield* FromUndefined6(schema_, references_, value11); + case "Union": + return yield* FromUnion20(schema_, references_, value11); + case "Uint8Array": + return yield* FromUint8Array5(schema_, references_, value11); + case "Unknown": + return yield* FromUnknown5(schema_, references_, value11); + case "Void": + return yield* FromVoid5(schema_, references_, value11); + default: + if (!exports_type.Has(schema_[Kind])) + throw new TypeCompilerUnknownTypeError(schema3); + return yield* FromKind4(schema_, references_, value11); + } + } + const state = { + language: "javascript", + functions: new Map, + variables: new Map, + instances: new Map + }; + function CreateExpression(schema3, references, value11, useHoisting = true) { + return `(${[...Visit17(schema3, references, value11, useHoisting)].join(" && ")})`; + } + function CreateFunctionName($id) { + return `check_${Identifier.Encode($id)}`; + } + function CreateVariable(expression) { + const variableName = `local_${state.variables.size}`; + state.variables.set(variableName, `const ${variableName} = ${expression}`); + return variableName; + } + function CreateFunction(name, schema3, references, value11, useHoisting = true) { + const [newline, pad] = ["\n", (length) => "".padStart(length, " ")]; + const parameter = CreateParameter("value", "any"); + const returns = CreateReturns("boolean"); + const expression = [...Visit17(schema3, references, value11, useHoisting)].map((expression2) => `${pad(4)}${expression2}`).join(` &&${newline}`); + return `function ${name}(${parameter})${returns} {${newline}${pad(2)}return (${newline}${expression}${newline}${pad(2)})\n}`; + } + function CreateParameter(name, type74) { + const annotation = state.language === "typescript" ? `: ${type74}` : ""; + return `${name}${annotation}`; + } + function CreateReturns(type74) { + return state.language === "typescript" ? `: ${type74}` : ""; + } + function Build(schema3, references, options) { + const functionCode = CreateFunction("check", schema3, references, "value"); + const parameter = CreateParameter("value", "any"); + const returns = CreateReturns("boolean"); + const functions = [...state.functions.values()]; + const variables = [...state.variables.values()]; + const checkFunction = IsString(schema3.$id) ? `return function check(${parameter})${returns} {\n return ${CreateFunctionName(schema3.$id)}(value)\n}` : `return ${functionCode}`; + return [...variables, ...functions, checkFunction].join("\n"); + } + function Code(...args) { + const defaults = { language: "javascript" }; + const [schema3, references, options] = args.length === 2 && IsArray(args[1]) ? [args[0], args[1], defaults] : args.length === 2 && !IsArray(args[1]) ? [args[0], [], args[1]] : args.length === 3 ? [args[0], args[1], args[2]] : args.length === 1 ? [args[0], [], defaults] : [null, [], defaults]; + state.language = options.language; + state.variables.clear(); + state.functions.clear(); + state.instances.clear(); + if (!IsSchema(schema3)) + throw new TypeCompilerTypeGuardError(schema3); + for (const schema4 of references) + if (!IsSchema(schema4)) + throw new TypeCompilerTypeGuardError(schema4); + return Build(schema3, references, options); + } + TypeCompiler2.Code = Code; + function Compile(schema3, references = []) { + const generatedCode = Code(schema3, references, { language: "javascript" }); + const compiledFunction = globalThis.Function("kind", "format", "hash", generatedCode); + const instances = new Map(state.instances); + function typeRegistryFunction(kind, instance, value11) { + if (!exports_type.Has(kind) || !instances.has(instance)) + return false; + const checkFunc = exports_type.Get(kind); + const schema4 = instances.get(instance); + return checkFunc(schema4, value11); + } + function formatRegistryFunction(format, value11) { + if (!exports_format.Has(format)) + return false; + const checkFunc = exports_format.Get(format); + return checkFunc(value11); + } + function hashFunction(value11) { + return Hash(value11); + } + const checkFunction = compiledFunction(typeRegistryFunction, formatRegistryFunction, hashFunction); + return new TypeCheck(schema3, references, checkFunction, generatedCode); + } + TypeCompiler2.Compile = Compile; +})(TypeCompiler || (TypeCompiler = {})); +// node_modules/cookie/index.js +var parse4 = function(str, options) { + if (typeof str !== "string") { + throw new TypeError("argument str must be a string"); + } + var obj = {}; + var opt = options || {}; + var dec = opt.decode || decode2; + var index = 0; + while (index < str.length) { + var eqIdx = str.indexOf("=", index); + if (eqIdx === -1) { + break; + } + var endIdx = str.indexOf(";", index); + if (endIdx === -1) { + endIdx = str.length; + } else if (endIdx < eqIdx) { + index = str.lastIndexOf(";", eqIdx - 1) + 1; + continue; + } + var key = str.slice(index, eqIdx).trim(); + if (obj[key] === undefined) { + var val = str.slice(eqIdx + 1, endIdx).trim(); + if (val.charCodeAt(0) === 34) { + val = val.slice(1, -1); + } + obj[key] = tryDecode(val, dec); + } + index = endIdx + 1; + } + return obj; +}; +var serialize = function(name, val, options) { + var opt = options || {}; + var enc = opt.encode || encode2; + if (typeof enc !== "function") { + throw new TypeError("option encode is invalid"); + } + if (!fieldContentRegExp.test(name)) { + throw new TypeError("argument name is invalid"); + } + var value11 = enc(val); + if (value11 && !fieldContentRegExp.test(value11)) { + throw new TypeError("argument val is invalid"); + } + var str = name + "=" + value11; + if (opt.maxAge != null) { + var maxAge = opt.maxAge - 0; + if (isNaN(maxAge) || !isFinite(maxAge)) { + throw new TypeError("option maxAge is invalid"); + } + str += "; Max-Age=" + Math.floor(maxAge); + } + if (opt.domain) { + if (!fieldContentRegExp.test(opt.domain)) { + throw new TypeError("option domain is invalid"); + } + str += "; Domain=" + opt.domain; + } + if (opt.path) { + if (!fieldContentRegExp.test(opt.path)) { + throw new TypeError("option path is invalid"); + } + str += "; Path=" + opt.path; + } + if (opt.expires) { + var expires = opt.expires; + if (!isDate(expires) || isNaN(expires.valueOf())) { + throw new TypeError("option expires is invalid"); + } + str += "; Expires=" + expires.toUTCString(); + } + if (opt.httpOnly) { + str += "; HttpOnly"; + } + if (opt.secure) { + str += "; Secure"; + } + if (opt.partitioned) { + str += "; Partitioned"; + } + if (opt.priority) { + var priority = typeof opt.priority === "string" ? opt.priority.toLowerCase() : opt.priority; + switch (priority) { + case "low": + str += "; Priority=Low"; + break; + case "medium": + str += "; Priority=Medium"; + break; + case "high": + str += "; Priority=High"; + break; + default: + throw new TypeError("option priority is invalid"); + } + } + if (opt.sameSite) { + var sameSite = typeof opt.sameSite === "string" ? opt.sameSite.toLowerCase() : opt.sameSite; + switch (sameSite) { + case true: + str += "; SameSite=Strict"; + break; + case "lax": + str += "; SameSite=Lax"; + break; + case "strict": + str += "; SameSite=Strict"; + break; + case "none": + str += "; SameSite=None"; + break; + default: + throw new TypeError("option sameSite is invalid"); + } + } + return str; +}; +var decode2 = function(str) { + return str.indexOf("%") !== -1 ? decodeURIComponent(str) : str; +}; +var encode2 = function(val) { + return encodeURIComponent(val); +}; +var isDate = function(val) { + return __toString.call(val) === "[object Date]" || val instanceof Date; +}; +var tryDecode = function(str, decode3) { + try { + return decode3(str); + } catch (e) { + return str; + } +}; +/*! + * cookie + * Copyright(c) 2012-2014 Roman Shtylman + * Copyright(c) 2015 Douglas Christopher Wilson + * MIT Licensed + */ +var $parse = parse4; +var $serialize = serialize; +var __toString = Object.prototype.toString; +var fieldContentRegExp = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/; + +// node_modules/elysia/dist/index.mjs +var import_fast_decode_uri_component = __toESM(require_fast_decode_uri_component(), 1); +var removeTrailingEquals = function(digest) { + let trimmedDigest = digest; + while (trimmedDigest.endsWith("=")) { + trimmedDigest = trimmedDigest.slice(0, -1); + } + return trimmedDigest; +}; +var import_fast_querystring = __toESM(require_lib(), 1); +var import_fast_decode_uri_component2 = __toESM(require_fast_decode_uri_component(), 1); +var import_fast_querystring2 = __toESM(require_lib(), 1); +var isLeapYear = function(year) { + return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); +}; +var date5 = function(str) { + const matches = DATE.exec(str); + if (!matches) + return false; + const year = +matches[1]; + const month = +matches[2]; + const day = +matches[3]; + return month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month]); +}; +var getTime = function(strictTimeZone) { + return function time(str) { + const matches = TIME.exec(str); + if (!matches) + return false; + const hr = +matches[1]; + const min = +matches[2]; + const sec = +matches[3]; + const tz = matches[4]; + const tzSign = matches[5] === "-" ? -1 : 1; + const tzH = +(matches[6] || 0); + const tzM = +(matches[7] || 0); + if (tzH > 23 || tzM > 59 || strictTimeZone && !tz) + return false; + if (hr <= 23 && min <= 59 && sec < 60) + return true; + const utcMin = min - tzM * tzSign; + const utcHr = hr - tzH * tzSign - (utcMin < 0 ? 1 : 0); + return (utcHr === 23 || utcHr === -1) && (utcMin === 59 || utcMin === -1) && sec < 61; + }; +}; +var getDateTime = function(strictTimeZone) { + const time = getTime(strictTimeZone); + return function date_time(str) { + const dateTime = str.split(DATE_TIME_SEPARATOR); + return dateTime.length === 2 && date5(dateTime[0]) && time(dateTime[1]); + }; +}; +var uri = function(str) { + return NOT_URI_FRAGMENT.test(str) && URI.test(str); +}; +var byte = function(str) { + BYTE.lastIndex = 0; + return BYTE.test(str); +}; +var validateInt32 = function(value15) { + return Number.isInteger(value15) && value15 <= MAX_INT32 && value15 >= MIN_INT32; +}; +var validateInt64 = function(value15) { + return Number.isInteger(value15); +}; +var validateNumber = function() { + return true; +}; +var regex = function(str) { + if (Z_ANCHOR.test(str)) + return false; + try { + new RegExp(str); + return true; + } catch (e2) { + return false; + } +}; +var e = (e2, t3) => ({ part: e2, store: null, inert: t3 !== undefined ? new Map(t3.map((e3) => [e3.part.charCodeAt(0), e3])) : null, params: null, wildcardStore: null }); +var t = (e2, t3) => ({ ...e2, part: t3 }); +var r = (e2) => ({ paramName: e2, store: null, inert: null }); +var Memoirist = class _Memoirist { + root = {}; + history = []; + static regex = { static: /:.+?(?=\/|$)/, params: /:.+?(?=\/|$)/g }; + add(a2, l, i) { + let s; + if (typeof l != "string") + throw TypeError("Route path must be a string"); + l === "" ? l = "/" : l[0] !== "/" && (l = `/${l}`), this.history.push([a2, l, i]); + let n = l[l.length - 1] === "*"; + n && (l = l.slice(0, -1)); + let o = l.split(_Memoirist.regex.static), u = l.match(_Memoirist.regex.params) || []; + o[o.length - 1] === "" && o.pop(), s = this.root[a2] ? this.root[a2] : this.root[a2] = e("/"); + let p = 0; + for (let a3 = 0;a3 < o.length; ++a3) { + let i2 = o[a3]; + if (a3 > 0) { + let t3 = u[p++].slice(1); + if (s.params === null) + s.params = r(t3); + else if (s.params.paramName !== t3) + throw Error(`Cannot create route "${l}" with parameter "${t3}" because a route already exists with a different parameter name ("${s.params.paramName}") in the same location`); + let a4 = s.params; + if (a4.inert === null) { + s = a4.inert = e(i2); + continue; + } + s = a4.inert; + } + for (let r2 = 0;; ) { + if (r2 === i2.length) { + if (r2 < s.part.length) { + let a4 = t(s, s.part.slice(r2)); + Object.assign(s, e(i2, [a4])); + } + break; + } + if (r2 === s.part.length) { + if (s.inert === null) + s.inert = new Map; + else if (s.inert.has(i2.charCodeAt(r2))) { + s = s.inert.get(i2.charCodeAt(r2)), i2 = i2.slice(r2), r2 = 0; + continue; + } + let t3 = e(i2.slice(r2)); + s.inert.set(i2.charCodeAt(r2), t3), s = t3; + break; + } + if (i2[r2] !== s.part[r2]) { + let a4 = t(s, s.part.slice(r2)), l2 = e(i2.slice(r2)); + Object.assign(s, e(s.part.slice(0, r2), [a4, l2])), s = l2; + break; + } + ++r2; + } + } + if (p < u.length) { + let e2 = u[p], t3 = e2.slice(1); + if (s.params === null) + s.params = r(t3); + else if (s.params.paramName !== t3) + throw Error(`Cannot create route "${l}" with parameter "${t3}" because a route already exists with a different parameter name ("${s.params.paramName}") in the same location`); + return s.params.store === null && (s.params.store = i), s.params.store; + } + return n ? (s.wildcardStore === null && (s.wildcardStore = i), s.wildcardStore) : (s.store === null && (s.store = i), s.store); + } + find(e2, t3) { + let r2 = this.root[e2]; + return r2 ? a(t3, t3.length, r2, 0) : null; + } +}; +var a = (e2, t3, r2, l) => { + let i = r2?.part, s = l + i.length; + if (i.length > 1) { + if (s > t3) + return null; + if (i.length < 15) { + for (let t4 = 1, r3 = l + 1;t4 < i.length; ++t4, ++r3) + if (i.charCodeAt(t4) !== e2.charCodeAt(r3)) + return null; + } else if (e2.substring(l, s) !== i) + return null; + } + if (s === t3) + return r2.store !== null ? { store: r2.store, params: {} } : r2.wildcardStore !== null ? { store: r2.wildcardStore, params: { "*": "" } } : null; + if (r2.inert !== null) { + let l2 = r2.inert.get(e2.charCodeAt(s)); + if (l2 !== undefined) { + let r3 = a(e2, t3, l2, s); + if (r3 !== null) + return r3; + } + } + if (r2.params !== null) { + let l2 = r2.params, i2 = e2.indexOf("/", s); + if (i2 !== s) { + if (i2 === -1 || i2 >= t3) { + if (l2.store !== null) { + let r3 = {}; + return r3[l2.paramName] = e2.substring(s, t3), { store: l2.store, params: r3 }; + } + } else if (l2.inert !== null) { + let r3 = a(e2, t3, l2.inert, i2); + if (r3 !== null) + return r3.params[l2.paramName] = e2.substring(s, i2), r3; + } + } + } + return r2.wildcardStore !== null ? { store: r2.wildcardStore, params: { "*": e2.substring(s, t3) } } : null; +}; +var resolver = () => { + let resolve; + const promise5 = new Promise((r2) => { + resolve = r2; + }); + return [promise5, resolve]; +}; +var createSignal = () => { + const [start, resolveStart] = resolver(); + const [end, resolveEnd] = resolver(); + const children = []; + const resolvers = []; + return { + signal: start, + consume: (trace) => { + switch (trace.type) { + case "begin": + if (trace.unit && children.length === 0) + for (let i = 0;i < trace.unit; i++) { + const [start2, resolveStart2] = resolver(); + const [end2, resolveEnd2] = resolver(); + children.push(start2); + resolvers.push([ + (trace2) => { + resolveStart2({ + children: [], + end: end2, + name: trace2.name ?? "", + skip: false, + time: trace2.time + }); + }, + (time) => { + resolveEnd2(time); + } + ]); + } + resolveStart({ + children, + end, + name: trace.name ?? "", + skip: false, + time: trace.time + }); + break; + case "end": + resolveEnd(trace.time); + break; + } + }, + consumeChild(trace) { + switch (trace.type) { + case "begin": + if (!resolvers[0]) + return; + const [resolveStart2] = resolvers[0]; + resolveStart2({ + children: [], + end, + name: trace.name ?? "", + skip: false, + time: trace.time + }); + break; + case "end": + const child = resolvers.shift(); + if (!child) + return; + child[1](trace.time); + } + }, + resolve() { + resolveStart({ + children: [], + end: new Promise((resolve) => resolve(0)), + name: "", + skip: true, + time: 0 + }); + for (const [resolveStart2, resolveEnd2] of resolvers) { + resolveStart2({ + children: [], + end: new Promise((resolve) => resolve(0)), + name: "", + skip: true, + time: 0 + }); + resolveEnd2(0); + } + resolveEnd(0); + } + }; +}; +var createTraceListener = (getReporter, totalListener, handler) => { + if (typeof handler === "object") + handler = handler.fn; + return async function trace(trace) { + if (trace.event !== "request" || trace.type !== "begin") + return; + const id = trace.id; + const reporter = getReporter(); + const request = createSignal(); + const parse22 = createSignal(); + const transform7 = createSignal(); + const beforeHandle = createSignal(); + const handle = createSignal(); + const afterHandle = createSignal(); + const error22 = createSignal(); + const response = createSignal(); + request.consume(trace); + const reducer = (event) => { + if (event.id === id) + switch (event.event) { + case "request": + request.consume(event); + break; + case "request.unit": + request.consumeChild(event); + break; + case "parse": + parse22.consume(event); + break; + case "parse.unit": + parse22.consumeChild(event); + break; + case "transform": + transform7.consume(event); + break; + case "transform.unit": + transform7.consumeChild(event); + break; + case "beforeHandle": + beforeHandle.consume(event); + break; + case "beforeHandle.unit": + beforeHandle.consumeChild(event); + break; + case "handle": + handle.consume(event); + break; + case "afterHandle": + afterHandle.consume(event); + break; + case "afterHandle.unit": + afterHandle.consumeChild(event); + break; + case "error": + error22.consume(event); + break; + case "error.unit": + error22.consumeChild(event); + break; + case "response": + if (event.type === "begin") { + request.resolve(); + parse22.resolve(); + transform7.resolve(); + beforeHandle.resolve(); + handle.resolve(); + afterHandle.resolve(); + error22.resolve(); + } else + reporter.off("event", reducer); + response.consume(event); + break; + case "response.unit": + response.consumeChild(event); + break; + case "exit": + request.resolve(); + parse22.resolve(); + transform7.resolve(); + beforeHandle.resolve(); + handle.resolve(); + afterHandle.resolve(); + error22.resolve(); + break; + } + }; + reporter.on("event", reducer); + await handler({ + id, + context: trace.ctx, + set: trace.ctx?.set, + store: trace.ctx?.store, + time: trace.time, + request: request.signal, + parse: parse22.signal, + transform: transform7.signal, + beforeHandle: beforeHandle.signal, + handle: handle.signal, + afterHandle: afterHandle.signal, + error: error22.signal, + response: response.signal + }); + reporter.emit(`res${id}.${totalListener}`, undefined); + }; +}; +var separateFunction = (code) => { + if (code.startsWith("async")) + code = code.slice(6); + let index = -1; + if (code.charCodeAt(0) === 40) { + index = code.indexOf(") => {\n"); + if (index !== -1) + return [ + code.slice(1, index), + code.slice(index + 5), + { isArrowReturn: false } + ]; + index = code.indexOf(") => "); + if (index !== -1) + return [ + code.slice(1, index), + code.slice(index + 5), + { isArrowReturn: true } + ]; + } + if (code.startsWith("function")) { + index = code.indexOf("("); + const end = code.indexOf(")"); + return [ + code.slice(index + 1, end), + code.slice(end + 2), + { + isArrowReturn: false + } + ]; + } + const start = code.indexOf("("); + if (start !== -1) { + const [parameter, body] = code.split("\n", 2); + const end = parameter.lastIndexOf(")") + 1; + return [ + parameter.slice(start, end), + "{" + body, + { + isArrowReturn: false + } + ]; + } + const x = code.split("\n", 2); + return [x[0], x[1], { isArrowReturn: false }]; +}; +var bracketPairRange = (parameter) => { + const start = parameter.indexOf("{"); + if (start === -1) + return [-1, 0]; + let end = start + 1; + let deep = 1; + for (;end < parameter.length; end++) { + const char = parameter.charCodeAt(end); + if (char === 123) + deep++; + else if (char === 125) + deep--; + if (deep === 0) + break; + } + if (deep !== 0) + return [0, parameter.length]; + return [start, end + 1]; +}; +var bracketPairRangeReverse = (parameter) => { + const end = parameter.lastIndexOf("}"); + if (end === -1) + return [-1, 0]; + let start = end - 1; + let deep = 1; + for (;start >= 0; start--) { + const char = parameter.charCodeAt(start); + if (char === 125) + deep++; + else if (char === 123) + deep--; + if (deep === 0) + break; + } + if (deep !== 0) + return [-1, 0]; + return [start, end + 1]; +}; +var retrieveRootParamters = (parameter) => { + if (parameter.charCodeAt(0) === 40) + parameter = parameter.slice(1, -1); + if (parameter.charCodeAt(0) === 123) + parameter = parameter.slice(2, -2); + while (true) { + const [start, end] = bracketPairRange(parameter); + if (start === -1) + break; + parameter = parameter.slice(0, start - 2) + parameter.slice(end + 1); + } + return parameter.replace(/:/g, "").trim(); +}; +var findParameterReference = (parameter, inference) => { + const root = retrieveRootParamters(parameter); + if (!inference.query && root.includes("query")) + inference.query = true; + if (!inference.headers && root.includes("headers")) + inference.headers = true; + if (!inference.body && root.includes("body")) + inference.body = true; + if (!inference.cookie && root.includes("cookie")) + inference.cookie = true; + if (!inference.set && root.includes("set")) + inference.set = true; + return root; +}; +var findTraceParameterReference = (parameter, inference) => { + const root = retrieveRootParamters(parameter); + if (!inference.request && root.includes("request")) + inference.request = true; + if (!inference.parse && root.includes("parse")) + inference.parse = true; + if (!inference.transform && root.includes("transform")) + inference.transform = true; + if (!inference.handle && root.includes("handle")) + inference.handle = true; + if (!inference.beforeHandle && root.includes("beforeHandle")) + inference.beforeHandle = true; + if (!inference.afterHandle && root.includes("afterHandle")) + inference.afterHandle = true; + if (!inference.error && root.includes("error")) + inference.error = true; + if (!inference.context && root.includes("context")) + inference.context = true; + if (!inference.store && root.includes("store")) + inference.store = true; + if (!inference.set && root.includes("set")) + inference.set = true; + return root; +}; +var findEndIndex = (type74, content, index) => { + const newLineIndex = content.indexOf(type74 + "\n", index); + const newTabIndex = content.indexOf(type74 + " ", index); + const commaIndex = content.indexOf(type74 + ",", index); + const semicolonIndex = content.indexOf(type74 + ";", index); + const emptyIndex = content.indexOf(type74 + " ", index); + return [newLineIndex, newTabIndex, commaIndex, semicolonIndex, emptyIndex].filter((i) => i > 0).sort((a2, b) => a2 - b)[0] || -1; +}; +var findAlias = (type74, body, depth = 0) => { + if (depth > 5) + return []; + const aliases = []; + let content = body; + while (true) { + let index = findEndIndex(" = " + type74, content); + if (index === -1) { + const lastIndex = content.indexOf(" = " + type74); + if (lastIndex + 3 + type74.length !== content.length) + break; + index = lastIndex; + } + const part = content.slice(0, index); + let variable = part.slice(part.lastIndexOf(" ") + 1); + if (variable === "}") { + const [start, end] = bracketPairRangeReverse(part); + aliases.push(content.slice(start, end)); + content = content.slice(index + 3 + type74.length); + continue; + } + while (variable.charCodeAt(0) === 44) + variable = variable.slice(1); + while (variable.charCodeAt(0) === 9) + variable = variable.slice(1); + aliases.push(variable); + content = content.slice(index + 3 + type74.length); + } + for (const alias of aliases) { + if (alias.charCodeAt(0) === 123) + continue; + const deepAlias = findAlias(alias, body); + if (deepAlias.length > 0) + aliases.push(...deepAlias); + } + return aliases; +}; +var extractMainParameter = (parameter) => { + if (!parameter) + return; + const hasComma = parameter.includes(","); + if (!hasComma) { + if (parameter.includes("...")) + return parameter.slice(parameter.indexOf("...") + 3); + return parameter; + } + const spreadIndex = parameter.indexOf("..."); + if (spreadIndex === -1) + return; + return parameter.slice(spreadIndex + 3).trimEnd(); +}; +var inferBodyReference = (code, aliases, inference) => { + const access = (type74, alias) => code.includes(alias + "." + type74) || code.includes(alias + '["' + type74 + '"]') || code.includes(alias + "['" + type74 + "']"); + for (let alias of aliases) { + if (!alias) + continue; + if (alias.charCodeAt(0) === 123) { + alias = retrieveRootParamters(alias); + if (!inference.query && alias.includes("query")) + inference.query = true; + if (!inference.headers && alias.includes("headers")) + inference.headers = true; + if (!inference.body && alias.includes("body")) + inference.body = true; + if (!inference.cookie && alias.includes("cookie")) + inference.cookie = true; + if (!inference.set && alias.includes("set")) + inference.set = true; + continue; + } + if (code.includes("(" + alias + ")")) { + inference.query = true; + inference.headers = true; + inference.body = true; + inference.cookie = true; + inference.set = true; + inference.queries = []; + inference.unknownQueries = true; + break; + } + if (!inference.query && access("query", alias)) + inference.query = true; + if (code.includes("return " + alias) || code.includes("return " + alias + ".query")) { + inference.query = true; + inference.unknownQueries = true; + inference.queries = []; + } + if (!inference.unknownQueries && inference.query) { + let keyword = alias + "."; + if (code.includes(keyword + "query")) + keyword = alias + ".query"; + while (true) { + let start = code.indexOf(keyword); + if (start === -1 && code.indexOf(alias + "[") !== -1) { + inference.queries = []; + inference.unknownQueries = true; + break; + } + if (start !== -1) { + let end = findEndIndex("", code, start + keyword.length + 1); + if (end === -1) + end = undefined; + const index = start + alias.length + 1; + code = code.slice(start + alias.length + 1); + let query = code.slice(0, end ? end - index : end).trimEnd(); + while (start !== -1) { + start = query.indexOf("."); + if (start !== -1) + query = query.slice(start + 1); + } + if (query.charCodeAt(query.length - 1) === 59) + query = query.slice(0, -1); + if (query.charCodeAt(query.length - 1) === 44) + query = query.slice(0, -1); + if (query.charCodeAt(query.length - 1) === 93) + query = query.slice(0, -1); + if (query.charCodeAt(query.length - 1) === 41) + query = query.slice(0, -1); + if (query && !inference.queries.includes(query)) { + inference.queries.push(query); + continue; + } + } + break; + } + } + if (!inference.headers && access("headers", alias)) + inference.headers = true; + if (!inference.body && access("body", alias)) + inference.body = true; + if (!inference.cookie && access("cookie", alias)) + inference.cookie = true; + if (!inference.set && access("set", alias)) + inference.set = true; + if (inference.query && inference.headers && inference.body && inference.cookie && inference.set) + break; + } + return aliases; +}; +var removeDefaultParameter = (parameter) => { + while (true) { + const index = parameter.indexOf("="); + if (index === -1) + break; + const commaIndex = parameter.indexOf(",", index); + const bracketIndex = parameter.indexOf("}", index); + const end = [commaIndex, bracketIndex].filter((i) => i > 0).sort((a2, b) => a2 - b)[0] || -1; + if (end === -1) { + parameter = parameter.slice(0, index); + break; + } + parameter = parameter.slice(0, index) + parameter.slice(end); + } + return parameter.split(",").map((i) => i.trim()).join(", "); +}; +var validateInferencedQueries = (queries) => { + for (const query of queries) { + if (query.charCodeAt(0) === 123) + return false; + if (query.indexOf("'") !== -1) + return false; + if (query.indexOf('"') !== -1) + return false; + if (query.indexOf("\n") !== -1) + return false; + if (query.indexOf(" ") !== -1) + return false; + } + return true; +}; +var inferTraceBodyReference = (code, aliases, inference) => { + const access = (type74, alias) => code.includes(type74 + "." + alias) || code.includes(type74 + '["' + alias + '"]') || code.includes(type74 + "['" + alias + "']"); + for (let alias of aliases) { + if (alias.charCodeAt(0) === 123) { + alias = retrieveRootParamters(alias); + if (!inference.request && alias.includes("request")) + inference.request = true; + if (!inference.parse && alias.includes("parse")) + inference.parse = true; + if (!inference.transform && alias.includes("transform")) + inference.transform = true; + if (!inference.handle && alias.includes("handle")) + inference.handle = true; + if (!inference.beforeHandle && alias.includes("beforeHandle")) + inference.beforeHandle = true; + if (!inference.afterHandle && alias.includes("afterHandle")) + inference.afterHandle = true; + if (!inference.error && alias.includes("error")) + inference.error = true; + if (!inference.context && alias.includes("context")) + inference.context = true; + if (!inference.store && alias.includes("store")) + inference.store = true; + if (!inference.set && alias.includes("set")) + inference.set = true; + continue; + } + if (code.includes("(" + alias + ")")) { + inference.request = true; + inference.parse = true; + inference.transform = true; + inference.handle = true; + inference.beforeHandle = true; + inference.afterHandle = true; + inference.error = true; + inference.context = true; + inference.store = true; + inference.set = true; + break; + } + if (!inference.request && access("request", alias)) + inference.request = true; + if (!inference.parse && access("parse", alias)) + inference.parse = true; + if (!inference.transform && access("transform", alias)) + inference.transform = true; + if (!inference.handle && access("handle", alias)) + inference.handle = true; + if (!inference.beforeHandle && access("beforeHandle", alias)) + inference.beforeHandle = true; + if (!inference.afterHandle && access("afterHandle", alias)) + inference.afterHandle = true; + if (!inference.error && access("error", alias)) + inference.error = true; + if (!inference.context && access("context", alias)) + inference.context = true; + if (!inference.store && access("store", alias)) + inference.store = true; + if (!inference.set && access("set", alias)) + inference.set = true; + if (inference.request && inference.parse && inference.transform && inference.handle && inference.beforeHandle && inference.afterHandle && inference.error && inference.context && inference.store && inference.set) + break; + } + return aliases; +}; +var sucrose = (lifeCycle, inference = { + queries: [], + query: false, + headers: false, + body: false, + cookie: false, + set: false, + unknownQueries: false +}) => { + const events = []; + if (lifeCycle.handler && typeof lifeCycle.handler === "function") + events.push(lifeCycle.handler); + if (lifeCycle.beforeHandle?.length) + events.push(...lifeCycle.beforeHandle); + if (lifeCycle.parse?.length) + events.push(...lifeCycle.parse); + if (lifeCycle.error?.length) + events.push(...lifeCycle.error); + if (lifeCycle.transform?.length) + events.push(...lifeCycle.transform); + if (lifeCycle.afterHandle?.length) + events.push(...lifeCycle.afterHandle); + if (lifeCycle.mapResponse?.length) + events.push(...lifeCycle.mapResponse); + if (lifeCycle.request?.length) + events.push(...lifeCycle.request); + if (lifeCycle.onResponse?.length) + events.push(...lifeCycle.onResponse); + for (const e2 of events) { + if (!e2) + continue; + const event = "fn" in e2 ? e2.fn : e2; + const [parameter, body, { isArrowReturn }] = separateFunction(event.toString()); + const rootParameters = findParameterReference(parameter, inference); + const mainParameter = extractMainParameter(rootParameters); + if (isArrowReturn && (body === "query" || rootParameters && body.startsWith(rootParameters + ".query"))) { + inference.query = true; + inference.unknownQueries = true; + inference.queries = []; + } + if (mainParameter) { + const aliases = findAlias(mainParameter, body); + aliases.splice(0, -1, mainParameter); + inferBodyReference(body, aliases, inference); + } + const context = rootParameters || mainParameter; + if (context && body.includes("return " + context + ".query")) { + inference.query = true; + inference.unknownQueries = true; + inference.queries = []; + } + if (inference.query) { + inferBodyReference(body, ["query"], inference); + const queryIndex = parameter.indexOf("query: {"); + if (queryIndex !== -1) { + const part = parameter.slice(queryIndex + 7); + const [start, end] = bracketPairRange(part); + const queryBracket = removeDefaultParameter(part.slice(start, end)); + for (let query of queryBracket.slice(1, -1).split(",")) { + const index = query.indexOf(":"); + if (index !== -1) + query = query.slice(0, index); + query = query.trim(); + if (query && !inference.queries.includes(query)) + inference.queries.push(query.trim()); + } + } + } + if (inference.query && inference.headers && inference.body && inference.cookie && inference.set) + break; + } + if (!validateInferencedQueries(inference.queries)) { + inference.unknownQueries = true; + inference.queries = []; + } + return inference; +}; +var sucroseTrace = (traces, inference = { + request: false, + parse: false, + transform: false, + handle: false, + beforeHandle: false, + afterHandle: false, + error: false, + context: false, + store: false, + set: false +}) => { + for (const handler of traces) { + const [parameter, body] = separateFunction(handler.toString()); + const rootParameters = findTraceParameterReference(parameter, inference); + const mainParameter = extractMainParameter(rootParameters); + if (mainParameter) { + const aliases = findAlias(mainParameter, body); + aliases.splice(0, -1, mainParameter); + inferTraceBodyReference(body, aliases, inference); + continue; + } + if (inference.request && inference.parse && inference.transform && inference.handle && inference.beforeHandle && inference.afterHandle && inference.error && inference.context && inference.store && inference.set) + break; + } + return inference; +}; +var Cookie = class { + constructor(name, jar, initial = {}) { + this.name = name; + this.jar = jar; + this.initial = initial; + } + get cookie() { + if (!(this.name in this.jar)) + return this.initial; + return this.jar[this.name]; + } + set cookie(jar) { + if (!(this.name in this.jar)) + this.jar[this.name] = this.initial; + this.jar[this.name] = jar; + } + get value() { + return this.cookie.value; + } + set value(value15) { + if (!(this.name in this.jar)) + this.jar[this.name] = this.initial; + this.jar[this.name].value = value15; + } + get expires() { + return this.cookie.expires; + } + set expires(expires) { + this.cookie.expires = expires; + } + get maxAge() { + return this.cookie.maxAge; + } + set maxAge(maxAge) { + this.cookie.maxAge = maxAge; + } + get domain() { + return this.cookie.domain; + } + set domain(domain) { + this.cookie.domain = domain; + } + get path() { + return this.cookie.path; + } + set path(path) { + this.cookie.path = path; + } + get secure() { + return this.cookie.secure; + } + set secure(secure) { + this.cookie.secure = secure; + } + get httpOnly() { + return this.cookie.httpOnly; + } + set httpOnly(httpOnly) { + this.cookie.httpOnly = httpOnly; + } + get sameSite() { + return this.cookie.sameSite; + } + set sameSite(sameSite) { + this.cookie.sameSite = sameSite; + } + get priority() { + return this.cookie.priority; + } + set priority(priority) { + this.cookie.priority = priority; + } + get secrets() { + return this.cookie.secrets; + } + set secrets(secrets) { + this.cookie.secrets = secrets; + } + update(config) { + this.cookie = Object.assign(this.cookie, typeof config === "function" ? config(this.cookie) : config); + return this; + } + set(config) { + this.cookie = Object.assign({ + ...this.initial, + value: this.value + }, typeof config === "function" ? config(this.cookie) : config); + return this; + } + remove() { + if (this.value === undefined) + return; + this.set({ + expires: new Date(0), + maxAge: 0, + value: "" + }); + return this; + } + toString() { + return typeof this.value === "object" ? JSON.stringify(this.value) : this.value?.toString() ?? ""; + } +}; +var createCookieJar = (set2, store, initial) => { + if (!set2.cookie) + set2.cookie = {}; + return new Proxy(store, { + get(_, key) { + if (key in store) + return new Cookie(key, set2.cookie, Object.assign({}, initial ?? {}, store[key])); + return new Cookie(key, set2.cookie, Object.assign({}, initial)); + } + }); +}; +var parseCookie = async (set2, cookieString, { + secrets, + sign, + ...initial +} = {}) => { + if (!cookieString) + return createCookieJar(set2, {}, initial); + const isStringKey = typeof secrets === "string"; + if (sign && sign !== true && !Array.isArray(sign)) + sign = [sign]; + const jar = {}; + const cookies = $parse(cookieString); + for (const [name, v] of Object.entries(cookies)) { + let value15 = import_fast_decode_uri_component.default(v); + if (sign === true || sign?.includes(name)) { + if (!secrets) + throw new Error("No secret is provided to cookie plugin"); + if (isStringKey) { + const temp = await unsignCookie(value15, secrets); + if (temp === false) + throw new InvalidCookieSignature(name); + value15 = temp; + } else { + let decoded = true; + for (let i = 0;i < secrets.length; i++) { + const temp = await unsignCookie(value15, secrets[i]); + if (temp !== false) { + decoded = true; + value15 = temp; + break; + } + } + if (!decoded) + throw new InvalidCookieSignature(name); + } + } + const start = value15.charCodeAt(0); + if (start === 123 || start === 91) + try { + jar[name] = { + value: JSON.parse(value15) + }; + continue; + } catch { + } + if (isNumericString(value15)) { + jar[name] = { + value: parseInt(value15) + }; + continue; + } + if (value15 === "true") { + jar[name] = { + value: true + }; + continue; + } + if (value15 === "false") { + jar[name] = { + value: false + }; + continue; + } + jar[name] = { + value: value15 + }; + } + return createCookieJar(set2, jar, initial); +}; +var hasHeaderShorthand = "toJSON" in new Headers; +var isNotEmpty = (obj) => { + if (!obj) + return false; + for (const x in obj) + return true; + return false; +}; +var handleFile = (response, set2) => { + const size = response.size; + if (!set2 && size || size && set2 && set2.status !== 206 && set2.status !== 304 && set2.status !== 412 && set2.status !== 416) { + if (set2) { + if (set2.headers instanceof Headers) { + if (hasHeaderShorthand) + set2.headers = set2.headers.toJSON(); + else + for (const [key, value15] of set2.headers.entries()) + if (key in set2.headers) + set2.headers[key] = value15; + } + return new Response(response, { + status: set2.status, + headers: Object.assign({ + "accept-ranges": "bytes", + "content-range": `bytes 0-${size - 1}/${size}` + }, set2.headers) + }); + } + return new Response(response, { + headers: { + "accept-ranges": "bytes", + "content-range": `bytes 0-${size - 1}/${size}` + } + }); + } + return new Response(response); +}; +var parseSetCookies = (headers, setCookie) => { + if (!headers) + return headers; + headers.delete("Set-Cookie"); + for (let i = 0;i < setCookie.length; i++) { + const index = setCookie[i].indexOf("="); + headers.append("Set-Cookie", `${setCookie[i].slice(0, index)}=${setCookie[i].slice(index + 1) || ""}`); + } + return headers; +}; +var serializeCookie = (cookies) => { + if (!cookies || !isNotEmpty(cookies)) + return; + const set2 = []; + for (const [key, property] of Object.entries(cookies)) { + if (!key || !property) + continue; + const value15 = property.value; + if (value15 === undefined || value15 === null) + continue; + set2.push($serialize(key, typeof value15 === "object" ? JSON.stringify(value15) : value15 + "", property)); + } + if (set2.length === 0) + return; + if (set2.length === 1) + return set2[0]; + return set2; +}; +var mapResponse = (response, set2, request) => { + if (response?.$passthrough) + response = response?.[response.$passthrough]; + if (response?.[ELYSIA_RESPONSE]) { + set2.status = response[ELYSIA_RESPONSE]; + response = response.response; + } + if (isNotEmpty(set2.headers) || set2.status !== 200 || set2.redirect || set2.cookie) { + if (typeof set2.status === "string") + set2.status = StatusMap[set2.status]; + if (set2.redirect) { + set2.headers.Location = set2.redirect; + if (!set2.status || set2.status < 300 || set2.status >= 400) + set2.status = 302; + } + if (set2.cookie && isNotEmpty(set2.cookie)) + set2.headers["Set-Cookie"] = serializeCookie(set2.cookie); + if (set2.headers["Set-Cookie"] && Array.isArray(set2.headers["Set-Cookie"])) + set2.headers = parseSetCookies(new Headers(set2.headers), set2.headers["Set-Cookie"]); + switch (response?.constructor?.name) { + case "String": + return new Response(response, set2); + case "Blob": + return handleFile(response, set2); + case "Object": + case "Array": + return Response.json(response, set2); + case "ReadableStream": + if (!set2.headers["content-type"]?.startsWith("text/event-stream")) + set2.headers["content-type"] = "text/event-stream; charset=utf-8"; + request?.signal.addEventListener("abort", { + handleEvent() { + if (!request?.signal.aborted) + response.cancel(request); + } + }, { + once: true + }); + return new Response(response, set2); + case undefined: + if (!response) + return new Response("", set2); + return Response.json(response, set2); + case "Response": + const inherits = { ...set2.headers }; + if (hasHeaderShorthand) + set2.headers = response.headers.toJSON(); + else + for (const [key, value15] of response.headers.entries()) + if (key in set2.headers) + set2.headers[key] = value15; + for (const key in inherits) + response.headers.append(key, inherits[key]); + return response; + case "Error": + return errorToResponse(response, set2); + case "Promise": + return response.then((x) => mapResponse(x, set2)); + case "Function": + return mapResponse(response(), set2); + case "Number": + case "Boolean": + return new Response(response.toString(), set2); + case "Cookie": + if (response instanceof Cookie) + return new Response(response.value, set2); + return new Response(response?.toString(), set2); + default: + if (response instanceof Response) { + const inherits2 = Object.assign({}, set2.headers); + if (hasHeaderShorthand) + set2.headers = response.headers.toJSON(); + else + for (const [key, value15] of response.headers.entries()) + if (key in set2.headers) + set2.headers[key] = value15; + for (const key in inherits2) + response.headers.append(key, inherits2[key]); + return response; + } + if (response instanceof Promise) + return response.then((x) => mapResponse(x, set2)); + if (response instanceof Error) + return errorToResponse(response, set2); + if ("charCodeAt" in response) { + const code = response.charCodeAt(0); + if (code === 123 || code === 91) { + if (!set2.headers["Content-Type"]) + set2.headers["Content-Type"] = "application/json"; + return new Response(JSON.stringify(response), set2); + } + } + return new Response(response, set2); + } + } else + switch (response?.constructor?.name) { + case "String": + return new Response(response); + case "Blob": + return handleFile(response, set2); + case "Object": + case "Array": + return new Response(JSON.stringify(response), { + headers: { + "content-type": "application/json" + } + }); + case "ReadableStream": + request?.signal.addEventListener("abort", { + handleEvent() { + if (!request?.signal.aborted) + response.cancel(request); + } + }, { + once: true + }); + return new Response(response, { + headers: { + "Content-Type": "text/event-stream; charset=utf-8" + } + }); + case undefined: + if (!response) + return new Response(""); + return new Response(JSON.stringify(response), { + headers: { + "content-type": "application/json" + } + }); + case "Response": + return response; + case "Error": + return errorToResponse(response, set2); + case "Promise": + return response.then((x) => { + const r2 = mapCompactResponse(x); + if (r2 !== undefined) + return r2; + return new Response(""); + }); + case "Function": + return mapCompactResponse(response()); + case "Number": + case "Boolean": + return new Response(response.toString()); + case "Cookie": + if (response instanceof Cookie) + return new Response(response.value, set2); + return new Response(response?.toString(), set2); + default: + if (response instanceof Response) + return new Response(response.body, { + headers: { + "Content-Type": "application/json" + } + }); + if (response instanceof Promise) + return response.then((x) => mapResponse(x, set2)); + if (response instanceof Error) + return errorToResponse(response, set2); + if ("charCodeAt" in response) { + const code = response.charCodeAt(0); + if (code === 123 || code === 91) { + if (!set2.headers["Content-Type"]) + set2.headers["Content-Type"] = "application/json"; + return new Response(JSON.stringify(response), set2); + } + } + return new Response(response); + } +}; +var mapEarlyResponse = (response, set2, request) => { + if (response === undefined || response === null) + return; + if (response?.$passthrough) + response = response?.[response.$passthrough]; + if (response?.[ELYSIA_RESPONSE]) { + set2.status = response[ELYSIA_RESPONSE]; + response = response.response; + } + if (isNotEmpty(set2.headers) || set2.status !== 200 || set2.redirect || set2.cookie) { + if (typeof set2.status === "string") + set2.status = StatusMap[set2.status]; + if (set2.redirect) { + set2.headers.Location = set2.redirect; + if (!set2.status || set2.status < 300 || set2.status >= 400) + set2.status = 302; + } + if (set2.cookie && isNotEmpty(set2.cookie)) + set2.headers["Set-Cookie"] = serializeCookie(set2.cookie); + if (set2.headers["Set-Cookie"] && Array.isArray(set2.headers["Set-Cookie"])) + set2.headers = parseSetCookies(new Headers(set2.headers), set2.headers["Set-Cookie"]); + switch (response?.constructor?.name) { + case "String": + return new Response(response, set2); + case "Blob": + return handleFile(response, set2); + case "Object": + case "Array": + return Response.json(response, set2); + case "ReadableStream": + if (!set2.headers["content-type"]?.startsWith("text/event-stream")) + set2.headers["content-type"] = "text/event-stream; charset=utf-8"; + request?.signal.addEventListener("abort", { + handleEvent() { + if (!request?.signal.aborted) + response.cancel(request); + } + }, { + once: true + }); + return new Response(response, set2); + case undefined: + if (!response) + return; + return Response.json(response, set2); + case "Response": + const inherits = Object.assign({}, set2.headers); + if (hasHeaderShorthand) + set2.headers = response.headers.toJSON(); + else + for (const [key, value15] of response.headers.entries()) + if (!(key in set2.headers)) + set2.headers[key] = value15; + for (const key in inherits) + response.headers.append(key, inherits[key]); + if (response.status !== set2.status) + set2.status = response.status; + return response; + case "Promise": + return response.then((x) => { + const r2 = mapEarlyResponse(x, set2); + if (r2 !== undefined) + return r2; + }); + case "Error": + return errorToResponse(response, set2); + case "Function": + return mapEarlyResponse(response(), set2); + case "Number": + case "Boolean": + return new Response(response.toString(), set2); + case "Cookie": + if (response instanceof Cookie) + return new Response(response.value, set2); + return new Response(response?.toString(), set2); + default: + if (response instanceof Response) { + const inherits2 = { ...set2.headers }; + if (hasHeaderShorthand) + set2.headers = response.headers.toJSON(); + else + for (const [key, value15] of response.headers.entries()) + if (key in set2.headers) + set2.headers[key] = value15; + for (const key in inherits2) + response.headers.append(key, inherits2[key]); + return response; + } + if (response instanceof Promise) + return response.then((x) => mapEarlyResponse(x, set2)); + if (response instanceof Error) + return errorToResponse(response, set2); + if ("charCodeAt" in response) { + const code = response.charCodeAt(0); + if (code === 123 || code === 91) { + if (!set2.headers["Content-Type"]) + set2.headers["Content-Type"] = "application/json"; + return new Response(JSON.stringify(response), set2); + } + } + return new Response(response, set2); + } + } else + switch (response?.constructor?.name) { + case "String": + return new Response(response); + case "Blob": + return handleFile(response, set2); + case "Object": + case "Array": + return new Response(JSON.stringify(response), { + headers: { + "content-type": "application/json" + } + }); + case "ReadableStream": + request?.signal.addEventListener("abort", { + handleEvent() { + if (!request?.signal.aborted) + response.cancel(request); + } + }, { + once: true + }); + return new Response(response, { + headers: { + "Content-Type": "text/event-stream; charset=utf-8" + } + }); + case undefined: + if (!response) + return new Response(""); + return new Response(JSON.stringify(response), { + headers: { + "content-type": "application/json" + } + }); + case "Response": + return response; + case "Promise": + return response.then((x) => { + const r2 = mapEarlyResponse(x, set2); + if (r2 !== undefined) + return r2; + }); + case "Error": + return errorToResponse(response, set2); + case "Function": + return mapCompactResponse(response()); + case "Number": + case "Boolean": + return new Response(response.toString()); + case "Cookie": + if (response instanceof Cookie) + return new Response(response.value, set2); + return new Response(response?.toString(), set2); + default: + if (response instanceof Response) + return new Response(response.body, { + headers: { + "Content-Type": "application/json" + } + }); + if (response instanceof Promise) + return response.then((x) => mapEarlyResponse(x, set2)); + if (response instanceof Error) + return errorToResponse(response, set2); + if ("charCodeAt" in response) { + const code = response.charCodeAt(0); + if (code === 123 || code === 91) { + if (!set2.headers["Content-Type"]) + set2.headers["Content-Type"] = "application/json"; + return new Response(JSON.stringify(response), set2); + } + } + return new Response(response); + } +}; +var mapCompactResponse = (response, request) => { + if (response?.$passthrough) + response = response?.[response.$passthrough]; + if (response?.[ELYSIA_RESPONSE]) + return mapResponse(response.response, { + status: response[ELYSIA_RESPONSE], + headers: {} + }); + switch (response?.constructor?.name) { + case "String": + return new Response(response); + case "Blob": + return handleFile(response); + case "Object": + case "Array": + return new Response(JSON.stringify(response), { + headers: { + "content-type": "application/json" + } + }); + case "ReadableStream": + request?.signal.addEventListener("abort", { + handleEvent() { + if (!request?.signal.aborted) + response.cancel(request); + } + }, { + once: true + }); + return new Response(response, { + headers: { + "Content-Type": "text/event-stream; charset=utf-8" + } + }); + case undefined: + if (!response) + return new Response(""); + return new Response(JSON.stringify(response), { + headers: { + "content-type": "application/json" + } + }); + case "Response": + return response; + case "Error": + return errorToResponse(response); + case "Promise": + return response.then(mapCompactResponse); + case "Function": + return mapCompactResponse(response()); + case "Number": + case "Boolean": + return new Response(response.toString()); + default: + if (response instanceof Response) + return new Response(response.body, { + headers: { + "Content-Type": "application/json" + } + }); + if (response instanceof Promise) + return response.then(mapCompactResponse); + if (response instanceof Error) + return errorToResponse(response); + if ("charCodeAt" in response) { + const code = response.charCodeAt(0); + if (code === 123 || code === 91) { + return new Response(JSON.stringify(response), { + headers: { + "Content-Type": "application/json" + } + }); + } + } + return new Response(response); + } +}; +var errorToResponse = (error22, set2) => new Response(JSON.stringify({ + name: error22?.name, + message: error22?.message, + cause: error22?.cause +}), { + status: set2?.status !== 200 ? set2?.status ?? 500 : 500, + headers: set2?.headers +}); +var replaceUrlPath = (url, pathname) => { + const urlObject = new URL(url); + urlObject.pathname = pathname; + return urlObject.toString(); +}; +var isClass = (v) => typeof v === "function" && /^\s*class\s+/.test(v.toString()) || v.toString().startsWith("[object ") || isNotEmpty(Object.getPrototypeOf(v)); +var isObject = (item) => item && typeof item === "object" && !Array.isArray(item); +var mergeDeep = (target, source, { + skipKeys +} = {}) => { + if (isObject(target) && isObject(source)) + for (const [key, value15] of Object.entries(source)) { + if (skipKeys?.includes(key)) + continue; + if (!isObject(value15) || !(key in target) || isClass(value15)) { + target[key] = value15; + continue; + } + target[key] = mergeDeep(target[key], value15); + } + return target; +}; +var mergeCookie = (a2, b) => { + const { properties: _, ...target } = a2 ?? {}; + const { properties: __, ...source } = b ?? {}; + return mergeDeep(target, source); +}; +var mergeObjectArray = (a2 = [], b = []) => { + if (!a2) + return []; + if (!b) + return a2; + const array5 = []; + const checksums = []; + if (!Array.isArray(a2)) + a2 = [a2]; + if (!Array.isArray(b)) + b = [b]; + for (const item of a2) { + array5.push(item); + if (item.checksum) + checksums.push(item.checksum); + } + for (const item of b) + if (!checksums.includes(item.checksum)) + array5.push(item); + return array5; +}; +var primitiveHooks = [ + "start", + "request", + "parse", + "transform", + "resolve", + "beforeHandle", + "afterHandle", + "onResponse", + "mapResponse", + "trace", + "error", + "stop", + "body", + "headers", + "params", + "query", + "response", + "type", + "detail" +]; +var primitiveHookMap = primitiveHooks.reduce((acc, x) => (acc[x] = true, acc), {}); +var mergeResponse = (a2, b) => { + const isRecordNumber = (x) => typeof x === "object" && Object.keys(x).every(isNumericString); + if (isRecordNumber(a2) && isRecordNumber(b)) + return { ...a2, ...b }; + return b ?? a2; +}; +var mergeHook = (a2, b, { allowMacro = false } = {}) => { + const rest4 = allowMacro ? { + ...a2, + ...b + } : undefined; + return { + ...rest4, + body: b?.body ?? a2?.body, + headers: b?.headers ?? a2?.headers, + params: b?.params ?? a2?.params, + query: b?.query ?? a2?.query, + response: mergeResponse(a2?.response, b?.response), + type: a2?.type || b?.type, + detail: mergeDeep(b?.detail ?? {}, a2?.detail ?? {}), + parse: mergeObjectArray(a2?.parse, b?.parse), + transform: mergeObjectArray(a2?.transform, b?.transform), + beforeHandle: mergeObjectArray(a2?.beforeHandle, b?.beforeHandle), + afterHandle: mergeObjectArray(a2?.afterHandle, b?.afterHandle), + onResponse: mergeObjectArray(a2?.onResponse, b?.onResponse), + mapResponse: mergeObjectArray(a2?.mapResponse, b?.mapResponse), + trace: mergeObjectArray(a2?.trace, b?.trace), + error: mergeObjectArray(a2?.error, b?.error) + }; +}; +var getSchemaValidator = (s, { + models = {}, + dynamic = false, + normalize = false, + additionalProperties = normalize +}) => { + if (!s) + return; + if (typeof s === "string" && !(s in models)) + return; + const schema3 = typeof s === "string" ? models[s] : s; + if (schema3.type === "object" && "additionalProperties" in schema3 === false) + schema3.additionalProperties = additionalProperties; + const cleaner = (value15) => exports_value2.Clean(schema3, value15); + if (dynamic) { + const validator = { + schema: schema3, + references: "", + checkFunc: () => { + }, + code: "", + Check: (value15) => exports_value2.Check(schema3, value15), + Errors: (value15) => exports_value2.Errors(schema3, value15), + Code: () => "" + }; + if (normalize && schema3.additionalProperties === true) + validator.Clean = cleaner; + if (schema3.config) { + validator.config = schema3.config; + if (validator?.schema?.config) + delete validator.schema.config; + } + return validator; + } + const compiled = TypeCompiler.Compile(schema3, Object.values(models)); + compiled.Clean = cleaner; + if (schema3.config) { + compiled.config = schema3.config; + if (compiled?.schema?.config) + delete compiled.schema.config; + } + return compiled; +}; +var getResponseSchemaValidator = (s, { + models = {}, + dynamic = false, + normalize = false, + additionalProperties = normalize +}) => { + if (!s) + return; + if (typeof s === "string" && !(s in models)) + return; + const maybeSchemaOrRecord = typeof s === "string" ? models[s] : s; + const compile = (schema3, references) => { + const cleaner = (value15) => exports_value2.Clean(schema3, value15); + if (dynamic) + return { + schema: schema3, + references: "", + checkFunc: () => { + }, + code: "", + Check: (value15) => exports_value2.Check(schema3, value15), + Errors: (value15) => exports_value2.Errors(schema3, value15), + Code: () => "" + }; + const compiledValidator = TypeCompiler.Compile(schema3, references); + if (normalize && schema3.additionalProperties === true) + compiledValidator.Clean = cleaner; + return compiledValidator; + }; + if (Kind in maybeSchemaOrRecord) { + if ("additionalProperties" in maybeSchemaOrRecord === false) + maybeSchemaOrRecord.additionalProperties = additionalProperties; + return { + 200: compile(maybeSchemaOrRecord, Object.values(models)) + }; + } + const record4 = {}; + Object.keys(maybeSchemaOrRecord).forEach((status) => { + const maybeNameOrSchema = maybeSchemaOrRecord[+status]; + if (typeof maybeNameOrSchema === "string") { + if (maybeNameOrSchema in models) { + const schema3 = models[maybeNameOrSchema]; + schema3.type === "object" && "additionalProperties" in schema3; + record4[+status] = Kind in schema3 ? compile(schema3, Object.values(models)) : schema3; + } + return; + } + if (maybeNameOrSchema.type === "object" && "additionalProperties" in maybeNameOrSchema === false) + maybeNameOrSchema.additionalProperties = additionalProperties; + record4[+status] = Kind in maybeNameOrSchema ? compile(maybeNameOrSchema, Object.values(models)) : maybeNameOrSchema; + }); + return record4; +}; +var isBun = typeof Bun !== "undefined"; +var hasHash = isBun && typeof Bun.hash === "function"; +var checksum = (s) => { + if (hasHash) + return Bun.hash(s); + let h = 9; + for (let i = 0;i < s.length; ) + h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9); + return h = h ^ h >>> 9; +}; +var getCookieValidator = ({ + validator, + defaultConfig = {}, + config, + dynamic, + models +}) => { + let cookieValidator = getSchemaValidator(validator, { + dynamic, + models, + additionalProperties: true + }); + if (isNotEmpty(defaultConfig)) { + if (cookieValidator) { + cookieValidator.config = mergeCookie(cookieValidator.config, config); + } else { + cookieValidator = getSchemaValidator(t2.Cookie({}), { + dynamic, + models, + additionalProperties: true + }); + cookieValidator.config = defaultConfig; + } + } + return cookieValidator; +}; +var mergeLifeCycle = (a2, b, checksum2) => { + const injectChecksum = (x) => { + if (!x) + return; + if (!Array.isArray(x)) { + const fn = x; + if (checksum2 && !fn.checksum) + fn.checksum = checksum2; + if (fn.scope === "scoped") + fn.scope = "local"; + return fn; + } + const fns = [...x]; + for (const fn of fns) { + if (checksum2 && !fn.checksum) + fn.checksum = checksum2; + if (fn.scope === "scoped") + fn.scope = "local"; + } + return fns; + }; + return { + start: mergeObjectArray(a2.start, injectChecksum(b?.start)), + request: mergeObjectArray(a2.request, injectChecksum(b?.request)), + parse: mergeObjectArray(a2.parse, injectChecksum(b?.parse)), + transform: mergeObjectArray(a2.transform, injectChecksum(b?.transform)), + beforeHandle: mergeObjectArray(a2.beforeHandle, injectChecksum(b?.beforeHandle)), + afterHandle: mergeObjectArray(a2.afterHandle, injectChecksum(b?.afterHandle)), + mapResponse: mergeObjectArray(a2.mapResponse, injectChecksum(b?.mapResponse)), + onResponse: mergeObjectArray(a2.onResponse, injectChecksum(b?.onResponse)), + trace: a2.trace, + error: mergeObjectArray(a2.error, injectChecksum(b?.error)), + stop: mergeObjectArray(a2.stop, injectChecksum(b?.stop)) + }; +}; +var asHookType = (fn, inject, { skipIfHasType = false } = {}) => { + if (!fn) + return fn; + if (!Array.isArray(fn)) { + if (skipIfHasType) + fn.scope ??= inject; + else + fn.scope = inject; + return fn; + } + for (const x of fn) + if (skipIfHasType) + x.scope ??= inject; + else + x.scope = inject; + return fn; +}; +var filterGlobal = (fn) => { + if (!fn) + return fn; + if (!Array.isArray(fn)) + switch (fn.scope) { + case "global": + case "scoped": + return { ...fn }; + default: + return { fn }; + } + const array5 = []; + for (const x of fn) + switch (x.scope) { + case "global": + case "scoped": + array5.push({ + ...x + }); + break; + } + return array5; +}; +var filterGlobalHook = (hook) => { + return { + ...hook, + type: hook?.type, + detail: hook?.detail, + parse: filterGlobal(hook?.parse), + transform: filterGlobal(hook?.transform), + beforeHandle: filterGlobal(hook?.beforeHandle), + afterHandle: filterGlobal(hook?.afterHandle), + onResponse: filterGlobal(hook?.onResponse), + error: filterGlobal(hook?.error), + mapResponse: filterGlobal(hook?.mapResponse) + }; +}; +var StatusMap = { + Continue: 100, + "Switching Protocols": 101, + Processing: 102, + "Early Hints": 103, + OK: 200, + Created: 201, + Accepted: 202, + "Non-Authoritative Information": 203, + "No Content": 204, + "Reset Content": 205, + "Partial Content": 206, + "Multi-Status": 207, + "Already Reported": 208, + "Multiple Choices": 300, + "Moved Permanently": 301, + Found: 302, + "See Other": 303, + "Not Modified": 304, + "Temporary Redirect": 307, + "Permanent Redirect": 308, + "Bad Request": 400, + Unauthorized: 401, + "Payment Required": 402, + Forbidden: 403, + "Not Found": 404, + "Method Not Allowed": 405, + "Not Acceptable": 406, + "Proxy Authentication Required": 407, + "Request Timeout": 408, + Conflict: 409, + Gone: 410, + "Length Required": 411, + "Precondition Failed": 412, + "Payload Too Large": 413, + "URI Too Long": 414, + "Unsupported Media Type": 415, + "Range Not Satisfiable": 416, + "Expectation Failed": 417, + "I'm a teapot": 418, + "Misdirected Request": 421, + "Unprocessable Content": 422, + Locked: 423, + "Failed Dependency": 424, + "Too Early": 425, + "Upgrade Required": 426, + "Precondition Required": 428, + "Too Many Requests": 429, + "Request Header Fields Too Large": 431, + "Unavailable For Legal Reasons": 451, + "Internal Server Error": 500, + "Not Implemented": 501, + "Bad Gateway": 502, + "Service Unavailable": 503, + "Gateway Timeout": 504, + "HTTP Version Not Supported": 505, + "Variant Also Negotiates": 506, + "Insufficient Storage": 507, + "Loop Detected": 508, + "Not Extended": 510, + "Network Authentication Required": 511 +}; +var InvertedStatusMap = Object.fromEntries(Object.entries(StatusMap).map(([k, v]) => [v, k])); +var encoder = new TextEncoder; +var signCookie = async (val, secret) => { + if (typeof val !== "string") + throw new TypeError("Cookie value must be provided as a string."); + if (secret === null) + throw new TypeError("Secret key must be provided."); + const secretKey = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]); + const hmacBuffer = await crypto.subtle.sign("HMAC", secretKey, encoder.encode(val)); + return val + "." + removeTrailingEquals(Buffer.from(hmacBuffer).toString("base64")); +}; +var unsignCookie = async (input, secret) => { + if (typeof input !== "string") + throw new TypeError("Signed cookie string must be provided."); + if (secret === null) + throw new TypeError("Secret key must be provided."); + const tentativeValue = input.slice(0, input.lastIndexOf(".")); + const expectedInput = await signCookie(tentativeValue, secret); + return expectedInput === input ? tentativeValue : false; +}; +var traceBackMacro = (extension, property, hooks = property) => { + if (!extension || typeof extension !== "object" || !property) + return; + for (const [key, value15] of Object.entries(property)) { + if (key in primitiveHookMap || !(key in extension)) + continue; + const v = extension[key]; + if (typeof v === "function") { + v(value15); + } else if (typeof v === "object") + traceBackMacro(v, value15, hooks); + } +}; +var createMacroManager = ({ + globalHook, + localHook +}) => (stackName) => (type74, fn) => { + if (typeof type74 === "function") + type74 = { + fn: type74 + }; + if ("fn" in type74 || Array.isArray(type74)) { + if (!localHook[stackName]) + localHook[stackName] = []; + if (typeof localHook[stackName] === "function") + localHook[stackName] = [localHook[stackName]]; + if (Array.isArray(type74)) + localHook[stackName] = localHook[stackName].concat(type74); + else + localHook[stackName].push(type74); + return; + } + const { insert = "after", stack = "local" } = type74; + if (typeof fn === "function") + fn = { fn }; + if (stack === "global") { + if (!Array.isArray(fn)) { + if (insert === "before") { + globalHook[stackName].unshift(fn); + } else { + globalHook[stackName].push(fn); + } + } else { + if (insert === "before") { + globalHook[stackName] = fn.concat(globalHook[stackName]); + } else { + globalHook[stackName] = globalHook[stackName].concat(fn); + } + } + } else { + if (!localHook[stackName]) + localHook[stackName] = []; + if (typeof localHook[stackName] === "function") + localHook[stackName] = [localHook[stackName]]; + if (!Array.isArray(fn)) { + if (insert === "before") { + localHook[stackName].unshift(fn); + } else { + localHook[stackName].push(fn); + } + } else { + if (insert === "before") { + localHook[stackName] = fn.concat(localHook[stackName]); + } else { + localHook[stackName] = localHook[stackName].concat(fn); + } + } + } +}; +var isNumericString = (message) => { + if (message.length < 16) + return message.trim().length !== 0 && !Number.isNaN(Number(message)); + if (message.length === 16) { + const numVal = Number(message); + if (numVal.toString() === message) + return message.trim().length !== 0 && !Number.isNaN(numVal); + } + return false; +}; +var PromiseGroup = class { + constructor(onError = console.error) { + this.onError = onError; + this.root = null; + this.promises = []; + } + get size() { + return this.promises.length; + } + add(promise5) { + this.promises.push(promise5); + this.root ||= this.drain(); + return promise5; + } + async drain() { + while (this.promises.length > 0) { + try { + await this.promises[0]; + } catch (error22) { + this.onError(error22); + } + this.promises.shift(); + } + this.root = null; + } + then(onfulfilled, onrejected) { + return (this.root ?? Promise.resolve()).then(onfulfilled, onrejected); + } +}; +var fnToContainer = (fn) => { + if (!fn) + return fn; + if (!Array.isArray(fn)) { + if (typeof fn === "function") + return { fn }; + else if ("fn" in fn) + return fn; + } + const fns = []; + for (const x of fn) { + if (typeof x === "function") + fns.push({ fn: x }); + else if ("fn" in x) + fns.push(x); + } + return fns; +}; +var localHookToLifeCycleStore = (a2) => { + return { + ...a2, + start: fnToContainer(a2?.start), + request: fnToContainer(a2?.request), + parse: fnToContainer(a2?.parse), + transform: fnToContainer(a2?.transform), + beforeHandle: fnToContainer(a2?.beforeHandle), + afterHandle: fnToContainer(a2?.afterHandle), + onResponse: fnToContainer(a2?.onResponse), + mapResponse: fnToContainer(a2?.mapResponse), + trace: fnToContainer(a2?.trace), + error: fnToContainer(a2?.error), + stop: fnToContainer(a2?.stop) + }; +}; +var lifeCycleToFn = (a2) => { + return { + ...a2, + start: a2.start?.map((x) => x.fn), + request: a2.request?.map((x) => x.fn), + parse: a2.parse?.map((x) => x.fn), + transform: a2.transform?.map((x) => x.fn), + beforeHandle: a2.beforeHandle?.map((x) => x.fn), + afterHandle: a2.afterHandle?.map((x) => x.fn), + onResponse: a2.onResponse?.map((x) => x.fn), + mapResponse: a2.mapResponse?.map((x) => x.fn), + trace: a2.trace?.map((x) => x.fn), + error: a2.error?.map((x) => x.fn), + stop: a2.stop?.map((x) => x.fn) + }; +}; +var cloneInference = (inference) => ({ + event: { + body: inference.event.body, + cookie: inference.event.cookie, + headers: inference.event.headers, + queries: [...inference.event.queries], + query: inference.event.query, + set: inference.event.set, + unknownQueries: inference.event.unknownQueries + }, + trace: { + request: inference.trace.request, + parse: inference.trace.parse, + transform: inference.trace.transform, + handle: inference.trace.handle, + beforeHandle: inference.trace.beforeHandle, + afterHandle: inference.trace.afterHandle, + error: inference.trace.error, + context: inference.trace.context, + store: inference.trace.store, + set: inference.trace.set + } +}); +var redirect = (url, status = 301) => new Response(null, { + status, + headers: { + Location: url + } +}); +var env = typeof Bun !== "undefined" ? Bun.env : typeof process !== "undefined" ? process?.env : undefined; +var ERROR_CODE = Symbol("ElysiaErrorCode"); +var ELYSIA_RESPONSE = Symbol("ElysiaResponse"); +var isProduction = (env?.NODE_ENV ?? env?.ENV) === "production"; +var error22 = (code, response) => ({ + [ELYSIA_RESPONSE]: StatusMap[code] ?? code, + response: response ?? (code in InvertedStatusMap ? InvertedStatusMap[code] : code), + _type: undefined +}); +var InternalServerError = class extends Error { + constructor(message) { + super(message ?? "INTERNAL_SERVER_ERROR"); + this.code = "INTERNAL_SERVER_ERROR"; + this.status = 500; + } +}; +var NotFoundError = class extends Error { + constructor(message) { + super(message ?? "NOT_FOUND"); + this.code = "NOT_FOUND"; + this.status = 404; + } +}; +var ParseError = class extends Error { + constructor(message, body) { + super(message ?? "PARSE"); + this.body = body; + this.code = "PARSE"; + this.status = 400; + } +}; +var InvalidCookieSignature = class extends Error { + constructor(key, message) { + super(message ?? `"${key}" has invalid cookie signature`); + this.key = key; + this.code = "INVALID_COOKIE_SIGNATURE"; + this.status = 400; + } +}; +var ValidationError = class _ValidationError extends Error { + constructor(type74, validator, value15) { + if (typeof value15 === "object" && ELYSIA_RESPONSE in value15) + value15 = value15.response; + const error23 = isProduction ? undefined : ("Errors" in validator) ? validator.Errors(value15).First() : exports_value2.Errors(validator, value15).First(); + const customError = error23?.schema.error ? typeof error23.schema.error === "function" ? error23.schema.error(type74, validator, value15) : error23.schema.error : undefined; + const accessor = error23?.path || "root"; + let message = ""; + if (customError) { + message = typeof customError === "object" ? JSON.stringify(customError) : customError + ""; + } else if (isProduction) { + message = JSON.stringify({ + type: "validation", + on: type74, + message: error23?.message, + found: value15 + }); + } else { + const schema3 = validator?.schema ?? validator; + const errors5 = "Errors" in validator ? [...validator.Errors(value15)] : [...exports_value2.Errors(validator, value15)]; + let expected; + try { + expected = exports_value2.Create(schema3); + } catch (error32) { + expected = { + type: "Could not create expected value", + message: error32?.message, + error: error32 + }; + } + message = JSON.stringify({ + type: "validation", + on: type74, + property: accessor, + message: error23?.message, + expected, + found: value15, + errors: errors5 + }, null, 2); + } + super(message); + this.type = type74; + this.validator = validator; + this.value = value15; + this.code = "VALIDATION"; + this.status = 422; + Object.setPrototypeOf(this, _ValidationError.prototype); + } + get all() { + return [...this.validator.Errors(this.value)]; + } + static simplifyModel(validator) { + const model = "schema" in validator ? validator.schema : validator; + try { + return exports_value2.Create(model); + } catch { + return model; + } + } + get model() { + return _ValidationError.simplifyModel(this.validator); + } + toResponse(headers) { + return new Response(this.message, { + status: 400, + headers: { + ...headers, + "content-type": "application/json" + } + }); + } +}; +var websocket = { + open(ws) { + ws.data.open?.(ws); + }, + message(ws, message) { + ws.data.message?.(ws, message); + }, + drain(ws) { + ws.data.drain?.(ws); + }, + close(ws, code, reason) { + ws.data.close?.(ws, code, reason); + } +}; +var ElysiaWS = class { + constructor(raw, data) { + this.raw = raw; + this.data = data; + this.validator = raw.data.validator; + if (raw.data.id) { + this.id = raw.data.id; + } else { + const array5 = new Uint32Array(1); + crypto.getRandomValues(array5); + this.id = array5[0].toString(); + } + } + get id() { + return this.raw.data.id; + } + set id(newID) { + this.raw.data.id = newID; + } + get publish() { + return (topic, data = undefined, compress) => { + if (this.validator?.Check(data) === false) + throw new ValidationError("message", this.validator, data); + if (typeof data === "object") + data = JSON.stringify(data); + this.raw.publish(topic, data, compress); + return this; + }; + } + get send() { + return (data) => { + if (this.validator?.Check(data) === false) + throw new ValidationError("message", this.validator, data); + if (Buffer.isBuffer(data)) { + this.raw.send(data); + return this; + } + if (typeof data === "object") + data = JSON.stringify(data); + this.raw.send(data); + return this; + }; + } + get subscribe() { + return (room) => { + this.raw.subscribe(room); + return this; + }; + } + get unsubscribe() { + return (room) => { + this.raw.unsubscribe(room); + return this; + }; + } + get cork() { + return (callback) => { + this.raw.cork(callback); + return this; + }; + } + get close() { + return () => { + this.raw.close(); + return this; + }; + } + get terminate() { + return this.raw.terminate.bind(this.raw); + } + get isSubscribed() { + return this.raw.isSubscribed.bind(this.raw); + } + get remoteAddress() { + return this.raw.remoteAddress; + } +}; +var headersHasToJSON = new Headers().toJSON; +var requestId = { value: 0 }; +var createReport = ({ + hasTrace, + hasTraceSet = false, + addFn, + condition = {} +}) => { + if (hasTrace) { + addFn(` +const reporter = getReporter() +`); + return (event, { + name, + attribute = "", + unit = 0 + } = {}) => { + const dotIndex = event.indexOf("."); + const isGroup = dotIndex === -1; + if (event !== "request" && event !== "response" && !condition[isGroup ? event : event.slice(0, dotIndex)]) + return () => { + if (hasTraceSet && event === "afterHandle") + addFn(` +await traceDone +`); + }; + if (isGroup) + name ||= event; + else + name ||= "anonymous"; + addFn("\n" + `reporter.emit('event', { + id, + event: '${event}', + type: 'begin', + name: '${name}', + time: performance.now(), + ${isGroup ? `unit: ${unit},` : ""} + ${attribute} + })`.replace(/(\t| |\n)/g, "") + "\n"); + return () => { + addFn("\n" + `reporter.emit('event', { + id, + event: '${event}', + type: 'end', + time: performance.now() + })`.replace(/(\t| |\n)/g, "") + "\n"); + if (hasTraceSet && event === "afterHandle") + addFn(` +await traceDone +`); + }; + }; + } else { + return () => () => { + }; + } +}; +var hasReturn = (fnLiteral) => { + const parenthesisEnd = fnLiteral.indexOf(")"); + if (fnLiteral.charCodeAt(parenthesisEnd + 2) === 61 && fnLiteral.charCodeAt(parenthesisEnd + 5) !== 123) { + return true; + } + return fnLiteral.includes("return"); +}; +var composeValidationFactory = (hasErrorHandler, { + injectResponse = "", + normalize = false +} = {}) => ({ + composeValidation: (type74, value15 = `c.${type74}`) => hasErrorHandler ? `c.set.status = 422; throw new ValidationError('${type74}', ${type74}, ${value15})` : `c.set.status = 422; return new ValidationError('${type74}', ${type74}, ${value15}).toResponse(c.set.headers)`, + composeResponseValidation: (name = "r") => { + const returnError = hasErrorHandler ? `throw new ValidationError('response', response[c.set.status], ${name})` : `return new ValidationError('response', response[c.set.status], ${name}).toResponse(c.set.headers)`; + let code = "\n" + injectResponse + "\n"; + code += `let er + + if(${name} && typeof ${name} === "object" && ELYSIA_RESPONSE in ${name}) + er = ${name}[ELYSIA_RESPONSE] +`; + if (normalize) + code += ` + if(!er && response[c.set.status]?.Clean) + ${name} = response[c.set.status]?.Clean(${name}) + else if(response[er]?.Clean) + ${name}.response = response[er]?.Clean(${name}.response)`; + code += ` + if(er) { + if(!(${name} instanceof Response) && response[er]?.Check(${name}.response) === false) { + if(!(response instanceof Error)) { + c.set.status = ${name}[ELYSIA_RESPONSE] + + ${returnError} + } + } + } else if(!(${name} instanceof Response) && response[c.set.status]?.Check(${name}) === false) { + if(!(response instanceof Error)) + ${returnError} + } +`; + return code; + } +}); +var KindSymbol = Symbol.for("TypeBox.Kind"); +var hasProperty = (expectedProperty, schema3) => { + if (!schema3) + return; + if (schema3.type === "object") { + const properties = schema3.properties; + if (!properties) + return false; + for (const key of Object.keys(properties)) { + const property = properties[key]; + if (expectedProperty in property) + return true; + if (property.type === "object") { + if (hasProperty(expectedProperty, property)) + return true; + } else if (property.anyOf) { + for (let i = 0;i < property.anyOf.length; i++) { + if (hasProperty(expectedProperty, property.anyOf[i])) + return true; + } + } + } + return false; + } + return expectedProperty in schema3; +}; +var TransformSymbol = Symbol.for("TypeBox.Transform"); +var hasTransform = (schema3) => { + if (!schema3) + return; + if (schema3.type === "object" && schema3.properties) { + const properties = schema3.properties; + for (const key of Object.keys(properties)) { + const property = properties[key]; + if (property.type === "object") { + if (hasTransform(property)) + return true; + } else if (property.anyOf) { + for (let i = 0;i < property.anyOf.length; i++) + if (hasTransform(property.anyOf[i])) + return true; + } + const hasTransformSymbol = TransformSymbol in property; + if (hasTransformSymbol) + return true; + } + return false; + } + return TransformSymbol in schema3 || schema3.properties && TransformSymbol in schema3.properties; +}; +var matchFnReturn = /(?:return|=>) \S+\(/g; +var isAsync = (v) => { + const fn = "fn" in v ? v.fn : v; + if (fn.constructor.name === "AsyncFunction") + return true; + const literal14 = fn.toString(); + if (literal14.includes("=> response.clone(")) + return false; + if (literal14.includes("await")) + return true; + if (literal14.includes("async")) + return true; + return !!literal14.match(matchFnReturn); +}; +var composeHandler = ({ + app, + path, + method, + localHook, + hooks, + validator, + handler, + allowMeta = false, + appInference: { event: eventInference, trace: traceInference } +}) => { + const isHandleFn = typeof handler === "function"; + if (!isHandleFn) + handler = mapResponse(handler, { + headers: app.setHeaders ?? {} + }); + const hasErrorHandler = app.config.forceErrorEncapsulation && (isHandleFn || hooks.afterHandle.length > 0 || hooks.beforeHandle.length > 0 || hooks.transform.length > 0) || hooks.error.length > 0 || app.event.error.length > 0 || typeof Bun === "undefined" || hooks.onResponse.length > 0 || !!hooks.trace.length; + const handle = isHandleFn ? `handler(c)` : `handler`; + const handleResponse = hooks.onResponse.length ? ` +;(async () => {${hooks.onResponse.map((_, i) => `await res${i}(c)`).join(";")}})(); +` : ""; + const traceConditions = traceInference; + const hasTrace = hooks.trace.length > 0; + let fnLiteral = ""; + const inference = sucrose(Object.assign(localHook, { + handler + }), eventInference); + const hasQuery = inference.query || !!validator.query; + const hasBody = method !== "$INTERNALWS" && method !== "GET" && method !== "HEAD" && hooks.type !== "none" && (inference.body || !!validator.body); + const defaultHeaders = app.setHeaders; + const hasDefaultHeaders = defaultHeaders && !!Object.keys(defaultHeaders).length; + const hasHeaders = inference.headers || validator.headers; + const hasCookie = inference.cookie || !!validator.cookie; + const cookieValidator = hasCookie ? getCookieValidator({ + validator: validator.cookie, + defaultConfig: app.config.cookie, + dynamic: !!app.config.aot, + config: validator.cookie?.config ?? {}, + models: app.definitions.type + }) : undefined; + const cookieMeta = cookieValidator?.config; + let encodeCookie = ""; + if (cookieMeta?.sign) { + if (!cookieMeta.secrets) + throw new Error(`t.Cookie required secret which is not set in (${method}) ${path}.`); + const secret = !cookieMeta.secrets ? undefined : typeof cookieMeta.secrets === "string" ? cookieMeta.secrets : cookieMeta.secrets[0]; + encodeCookie += `const _setCookie = c.set.cookie + if(_setCookie) {`; + if (cookieMeta.sign === true) { + encodeCookie += `for(const [key, cookie] of Object.entries(_setCookie)) { + c.set.cookie[key].value = await signCookie(cookie.value, '${secret}') + }`; + } else + for (const name of cookieMeta.sign) { + encodeCookie += `if(_setCookie['${name}']?.value) { c.set.cookie['${name}'].value = await signCookie(_setCookie['${name}'].value, '${secret}') } +`; + } + encodeCookie += "}\n"; + } + const normalize = app.config.normalize; + const { composeValidation, composeResponseValidation } = composeValidationFactory(hasErrorHandler, { + normalize + }); + if (hasHeaders) { + fnLiteral += headersHasToJSON ? `c.headers = c.request.headers.toJSON() +` : `c.headers = {} + for (const [key, value] of c.request.headers.entries()) + c.headers[key] = value + `; + } + if (hasCookie) { + const get = (name, defaultValue) => { + const value15 = cookieMeta?.[name] ?? defaultValue; + if (!value15) + return typeof defaultValue === "string" ? `${name}: "${defaultValue}",` : `${name}: ${defaultValue},`; + if (typeof value15 === "string") + return `${name}: '${value15}',`; + if (value15 instanceof Date) + return `${name}: new Date(${value15.getTime()}),`; + return `${name}: ${value15},`; + }; + const options = cookieMeta ? `{ + secrets: ${cookieMeta.secrets !== undefined ? typeof cookieMeta.secrets === "string" ? `'${cookieMeta.secrets}'` : "[" + cookieMeta.secrets.reduce((a2, b) => a2 + `'${b}',`, "") + "]" : "undefined"}, + sign: ${cookieMeta.sign === true ? true : cookieMeta.sign !== undefined ? "[" + cookieMeta.sign.reduce((a2, b) => a2 + `'${b}',`, "") + "]" : "undefined"}, + ${get("domain")} + ${get("expires")} + ${get("httpOnly")} + ${get("maxAge")} + ${get("path", "/")} + ${get("priority")} + ${get("sameSite")} + ${get("secure")} + }` : "undefined"; + if (hasHeaders) + fnLiteral += ` +c.cookie = await parseCookie(c.set, c.headers.cookie, ${options}) +`; + else + fnLiteral += ` +c.cookie = await parseCookie(c.set, c.request.headers.get('cookie'), ${options}) +`; + } + if (hasQuery) { + let destructured = []; + if (validator.query && validator.query.schema.type === "object") { + destructured = Object.keys(validator.query.schema.properties); + } else + for (const query of inference.queries) + if (destructured.indexOf(query) === -1) + destructured.push(query); + if (app.config.forceDynamicQuery === true || inference.unknownQueries === true || !destructured.length) { + fnLiteral += `if(c.qi !== -1) { + c.query = parseQuery(c.request.url.slice(c.qi + 1).replace(/\\+/g, ' ')) + + for(const key of Object.keys(c.query)) + c.query[key] = decodeURIComponent(c.query[key]) + } else c.query = {}`; + } else { + fnLiteral += `if(c.qi !== -1) { + let url = c.request.url.slice(c.qi).replace(/\\+/g, ' ') + + ${destructured.map((name, index) => ` + ${index === 0 ? "let" : ""} memory = url.indexOf('&${name}=') + if(memory === -1) memory = url.indexOf('?${name}=') + let a${index} + + if(memory !== -1) { + const start = memory + ${name.length + 2} + memory = url.indexOf('&', start) + + if(memory === -1) a${index} = decodeURIComponent(url.slice(start)) + else a${index} = decodeURIComponent(url.slice(start, memory)) + }`).join("\n")} + + c.query = { + ${destructured.map((name, index) => `'${name}': a${index}`).join(", ")} + } + } else { + c.query = {} + }`; + } + } + const hasTraceSet = traceInference.set; + const hasSet = inference.cookie || inference.set || hasTraceSet || hasHeaders || isHandleFn && hasDefaultHeaders; + if (hasTrace) + fnLiteral += "\nconst id = c.$$requestId\n"; + const report = createReport({ + hasTrace, + hasTraceSet, + condition: traceConditions, + addFn: (word) => { + fnLiteral += word; + } + }); + fnLiteral += hasErrorHandler ? "\n try {\n" : ""; + if (hasTraceSet) { + fnLiteral += ` +const traceDone = Promise.all([`; + for (let i = 0;i < hooks.trace.length; i++) { + fnLiteral += `new Promise(r => { reporter.once(\`res\${id}.${i}\`, r) }),`; + } + fnLiteral += `]) +`; + } + const isAsyncHandler = typeof handler === "function" && isAsync(handler); + const maybeAsync = hasCookie || hasBody || hasTraceSet || isAsyncHandler || !!hooks.mapResponse.length || hooks.parse.length > 0 || hooks.afterHandle.some(isAsync) || hooks.beforeHandle.some(isAsync) || hooks.transform.some(isAsync); + const endParse = report("parse", { + unit: hooks.parse.length + }); + if (hasBody) { + const hasBodyInference = hooks.parse.length || inference.body || validator.body; + if (hooks.type && !hooks.parse.length) { + switch (hooks.type) { + case "json": + case "application/json": + if (hasErrorHandler) + fnLiteral += `const tempBody = await c.request.text() + + try { + c.body = JSON.parse(tempBody) + } catch { + throw new ParseError('Failed to parse body as found: ' + (typeof body === "string" ? "'" + body + "'" : body), body) + }`; + else + fnLiteral += `c.body = await c.request.json()`; + break; + case "text": + case "text/plain": + fnLiteral += `c.body = await c.request.text() +`; + break; + case "urlencoded": + case "application/x-www-form-urlencoded": + fnLiteral += `c.body = parseQuery(await c.request.text()) +`; + break; + case "arrayBuffer": + case "application/octet-stream": + fnLiteral += `c.body = await c.request.arrayBuffer() +`; + break; + case "formdata": + case "multipart/form-data": + fnLiteral += `c.body = {} + + const form = await c.request.formData() + for (const key of form.keys()) { + if (c.body[key]) + continue + + const value = form.getAll(key) + if (value.length === 1) + c.body[key] = value[0] + else c.body[key] = value + } +`; + break; + } + } else if (hasBodyInference) { + fnLiteral += "\n"; + fnLiteral += hasHeaders ? `let contentType = c.headers['content-type']` : `let contentType = c.request.headers.get('content-type')`; + fnLiteral += ` + if (contentType) { + const index = contentType.indexOf(';') + if (index !== -1) contentType = contentType.substring(0, index) + + c.contentType = contentType +`; + if (hooks.parse.length) { + fnLiteral += `let used = false +`; + const endReport = report("parse", { + unit: hooks.parse.length + }); + for (let i = 0;i < hooks.parse.length; i++) { + const endUnit = report("parse.unit", { + name: hooks.parse[i].fn.name + }); + const name = `bo${i}`; + if (i !== 0) + fnLiteral += `if(!used) { +`; + fnLiteral += `let ${name} = parse[${i}](c, contentType) +`; + fnLiteral += `if(${name} instanceof Promise) ${name} = await ${name} +`; + fnLiteral += `if(${name} !== undefined) { c.body = ${name}; used = true } +`; + endUnit(); + if (i !== 0) + fnLiteral += `}`; + } + endReport(); + } + fnLiteral += "\ndelete c.contentType\n"; + if (hooks.parse.length) + fnLiteral += `if (!used) {`; + if (hooks.type && !Array.isArray(hooks.type)) { + switch (hooks.type) { + case "json": + case "application/json": + if (hasErrorHandler) + fnLiteral += `const tempBody = await c.request.text() + + try { + c.body = JSON.parse(tempBody) + } catch { + throw new ParseError('Failed to parse body as found: ' + (typeof body === "string" ? "'" + body + "'" : body), body) + }`; + else + fnLiteral += `c.body = await c.request.json()`; + break; + case "text": + case "text/plain": + fnLiteral += `c.body = await c.request.text() +`; + break; + case "urlencoded": + case "application/x-www-form-urlencoded": + fnLiteral += `c.body = parseQuery(await c.request.text()) +`; + break; + case "arrayBuffer": + case "application/octet-stream": + fnLiteral += `c.body = await c.request.arrayBuffer() +`; + break; + case "formdata": + case "multipart/form-data": + fnLiteral += `c.body = {} + + const form = await c.request.formData() + for (const key of form.keys()) { + if (c.body[key]) + continue + + const value = form.getAll(key) + if (value.length === 1) + c.body[key] = value[0] + else c.body[key] = value + } +`; + break; + } + } else { + fnLiteral += ` + switch (contentType) { + case 'application/json': + ${hasErrorHandler ? ` + const tempBody = await c.request.text() + + try { + c.body = JSON.parse(tempBody) + } catch { + throw new ParseError('Failed to parse body as found: ' + (typeof body === "string" ? "'" + body + "'" : body), body) + } + ` : `c.body = await c.request.json() +`} + break + + case 'text/plain': + c.body = await c.request.text() + break + + case 'application/x-www-form-urlencoded': + c.body = parseQuery(await c.request.text()) + break + + case 'application/octet-stream': + c.body = await c.request.arrayBuffer(); + break + + case 'multipart/form-data': + c.body = {} + + const form = await c.request.formData() + for (const key of form.keys()) { + if (c.body[key]) + continue + + const value = form.getAll(key) + if (value.length === 1) + c.body[key] = value[0] + else c.body[key] = value + } + + break + }`; + } + if (hooks.parse.length) + fnLiteral += `}`; + fnLiteral += "}\n"; + } + fnLiteral += "\n"; + } + endParse(); + if (hooks?.transform) { + const endTransform = report("transform", { + unit: hooks.transform.length + }); + if (hooks.transform.length) + fnLiteral += "\nlet transformed\n"; + for (let i = 0;i < hooks.transform.length; i++) { + const transform7 = hooks.transform[i]; + const endUnit = report("transform.unit", { + name: transform7.fn.name + }); + fnLiteral += isAsync(transform7) ? `transformed = await transform[${i}](c) +` : `transformed = transform[${i}](c) +`; + fnLiteral += `if(transformed?.[ELYSIA_RESPONSE]) + throw transformed + else + Object.assign(c, transformed) +`; + endUnit(); + } + endTransform(); + } + if (validator) { + fnLiteral += "\n"; + if (validator.headers) { + if (hasProperty("default", validator.headers.params)) + for (const [key, value15] of Object.entries(exports_value2.Default(validator.headers.schema, {}))) { + const parsed = typeof value15 === "object" ? JSON.stringify(value15) : `'${value15}'`; + if (parsed) + fnLiteral += `c.headers['${key}'] ??= ${parsed} +`; + } + fnLiteral += `if(headers.Check(c.headers) === false) { + ${composeValidation("headers")} + }`; + if (hasTransform(validator.headers.schema)) + fnLiteral += ` +c.headers = headers.Decode(c.headers) +`; + } + if (validator.params) { + if (hasProperty("default", validator.params.schema)) + for (const [key, value15] of Object.entries(exports_value2.Default(validator.params.schema, {}))) { + const parsed = typeof value15 === "object" ? JSON.stringify(value15) : `'${value15}'`; + if (parsed) + fnLiteral += `c.params['${key}'] ??= ${parsed} +`; + } + fnLiteral += `if(params.Check(c.params) === false) { + ${composeValidation("params")} + }`; + if (hasTransform(validator.params.schema)) + fnLiteral += ` +c.params = params.Decode(c.params) +`; + } + if (validator.query) { + if (normalize) + fnLiteral += "c.query = query.Clean(c.query);\n"; + if (hasProperty("default", validator.query.schema)) + for (const [key, value15] of Object.entries(exports_value2.Default(validator.query.schema, {}))) { + const parsed = typeof value15 === "object" ? JSON.stringify(value15) : `'${value15}'`; + if (parsed) + fnLiteral += `c.query['${key}'] ??= ${parsed} +`; + } + fnLiteral += `if(query.Check(c.query) === false) { + ${composeValidation("query")} + }`; + if (hasTransform(validator.query.schema)) + fnLiteral += ` +c.query = query.Decode(Object.assign({}, c.query)) +`; + } + if (validator.body) { + if (normalize) + fnLiteral += "c.body = body.Clean(c.body);\n"; + if (hasProperty("default", validator.body.schema)) + fnLiteral += `if(body.Check(c.body) === false) { + c.body = Object.assign(${JSON.stringify(exports_value2.Default(validator.body.schema, null) ?? {})}, c.body) + + if(body.Check(c.query) === false) { + ${composeValidation("body")} + } + }`; + else + fnLiteral += `if(body.Check(c.body) === false) { + ${composeValidation("body")} + }`; + if (hasTransform(validator.body.schema)) + fnLiteral += ` +c.body = body.Decode(c.body) +`; + } + if (isNotEmpty(cookieValidator?.schema.properties ?? {})) { + fnLiteral += `const cookieValue = {} + for(const [key, value] of Object.entries(c.cookie)) + cookieValue[key] = value.value +`; + if (hasProperty("default", cookieValidator.schema)) + for (const [key, value15] of Object.entries(exports_value2.Default(cookieValidator.schema, {}))) { + fnLiteral += `cookieValue['${key}'] = ${typeof value15 === "object" ? JSON.stringify(value15) : value15} +`; + } + fnLiteral += `if(cookie.Check(cookieValue) === false) { + ${composeValidation("cookie", "cookieValue")} + }`; + } + } + if (hooks?.beforeHandle) { + const endBeforeHandle = report("beforeHandle", { + unit: hooks.beforeHandle.length + }); + let hasResolve = false; + for (let i = 0;i < hooks.beforeHandle.length; i++) { + const beforeHandle = hooks.beforeHandle[i]; + const endUnit = report("beforeHandle.unit", { + name: beforeHandle.fn.name + }); + const returning = hasReturn(beforeHandle.fn.toString()); + const isResolver = beforeHandle.subType === "resolve"; + if (isResolver) { + if (!hasResolve) { + hasResolve = true; + fnLiteral += "\nlet resolved\n"; + } + fnLiteral += isAsync(beforeHandle) ? `resolved = await beforeHandle[${i}](c); +` : `resolved = beforeHandle[${i}](c); +`; + fnLiteral += `if(resolved[ELYSIA_RESPONSE]) + throw resolved + else + Object.assign(c, resolved) +`; + } else if (!returning) { + fnLiteral += isAsync(beforeHandle) ? `await beforeHandle[${i}](c); +` : `beforeHandle[${i}](c); +`; + endUnit(); + } else { + fnLiteral += `Object.assign(c, be);`; + fnLiteral += isAsync(beforeHandle) ? `be = await beforeHandle[${i}](c); +` : `be = beforeHandle[${i}](c); +`; + endUnit(); + fnLiteral += `if(be !== undefined) { +`; + endBeforeHandle(); + const endAfterHandle = report("afterHandle", { + unit: hooks.transform.length + }); + if (hooks.afterHandle) { + report("handle", { + name: isHandleFn ? handler.name : undefined + })(); + for (let i2 = 0;i2 < hooks.afterHandle.length; i2++) { + const hook = hooks.afterHandle[i2]; + const returning2 = hasReturn(hook.fn.toString()); + const endUnit2 = report("afterHandle.unit", { + name: hook.fn.name + }); + fnLiteral += `c.response = be +`; + if (!returning2) { + fnLiteral += isAsync(hook.fn) ? `await afterHandle[${i2}](c, be) +` : `afterHandle[${i2}](c, be) +`; + } else { + fnLiteral += isAsync(hook.fn) ? `af = await afterHandle[${i2}](c) +` : `af = afterHandle[${i2}](c) +`; + fnLiteral += `if(af !== undefined) { c.response = be = af } +`; + } + endUnit2(); + } + } + endAfterHandle(); + if (validator.response) + fnLiteral += composeResponseValidation("be"); + if (hooks.mapResponse.length) { + fnLiteral += `c.response = be`; + for (let i2 = 0;i2 < hooks.mapResponse.length; i2++) { + fnLiteral += ` +if(mr === undefined) { + mr = onMapResponse[${i2}](c) + if(mr instanceof Promise) mr = await mr + if(mr !== undefined) c.response = mr + } +`; + } + } + fnLiteral += encodeCookie; + fnLiteral += `return mapEarlyResponse(be, c.set, c.request)} +`; + } + } + endBeforeHandle(); + } + if (hooks?.afterHandle.length) { + const endHandle = report("handle", { + name: isHandleFn ? handler.name : undefined + }); + if (hooks.afterHandle.length) + fnLiteral += isAsyncHandler ? `let r = c.response = await ${handle}; +` : `let r = c.response = ${handle}; +`; + else + fnLiteral += isAsyncHandler ? `let r = await ${handle}; +` : `let r = ${handle}; +`; + endHandle(); + const endAfterHandle = report("afterHandle", { + unit: hooks.afterHandle.length + }); + for (let i = 0;i < hooks.afterHandle.length; i++) { + const hook = hooks.afterHandle[i]; + const returning = hasReturn(hook.fn.toString()); + const endUnit = report("afterHandle.unit", { + name: hook.fn.name + }); + if (!returning) { + fnLiteral += isAsync(hook.fn) ? `await afterHandle[${i}](c) +` : `afterHandle[${i}](c) +`; + endUnit(); + } else { + fnLiteral += isAsync(hook.fn) ? `af = await afterHandle[${i}](c) +` : `af = afterHandle[${i}](c) +`; + endUnit(); + if (validator.response) { + fnLiteral += `if(af !== undefined) {`; + endAfterHandle(); + fnLiteral += composeResponseValidation("af"); + fnLiteral += `c.response = af }`; + } else { + fnLiteral += `if(af !== undefined) {`; + endAfterHandle(); + fnLiteral += `c.response = af} +`; + } + } + } + endAfterHandle(); + fnLiteral += `r = c.response +`; + if (validator.response) + fnLiteral += composeResponseValidation(); + fnLiteral += encodeCookie; + if (hooks.mapResponse.length) { + for (let i = 0;i < hooks.mapResponse.length; i++) { + fnLiteral += ` +mr = onMapResponse[${i}](c) + if(mr instanceof Promise) mr = await mr + if(mr !== undefined) c.response = mr +`; + } + } + if (hasSet) + fnLiteral += `return mapResponse(r, c.set, c.request) +`; + else + fnLiteral += `return mapCompactResponse(r, c.request) +`; + } else { + const endHandle = report("handle", { + name: isHandleFn ? handler.name : undefined + }); + if (validator.response || hooks.mapResponse.length) { + fnLiteral += isAsyncHandler ? `let r = await ${handle}; +` : `let r = ${handle}; +`; + endHandle(); + if (validator.response) + fnLiteral += composeResponseValidation(); + report("afterHandle")(); + if (hooks.mapResponse.length) { + fnLiteral += "c.response = r"; + for (let i = 0;i < hooks.mapResponse.length; i++) { + fnLiteral += ` +if(mr === undefined) { + mr = onMapResponse[${i}](c) + if(mr instanceof Promise) mr = await mr + if(mr !== undefined) r = c.response = mr + } +`; + } + } + fnLiteral += encodeCookie; + if (handler instanceof Response) { + fnLiteral += inference.set ? `if( + isNotEmpty(c.set.headers) || + c.set.status !== 200 || + c.set.redirect || + c.set.cookie + ) + return mapResponse(${handle}.clone(), c.set, c.request) + else + return ${handle}.clone()` : `return ${handle}.clone()`; + fnLiteral += "\n"; + } else if (hasSet) + fnLiteral += `return mapResponse(r, c.set, c.request) +`; + else + fnLiteral += `return mapCompactResponse(r, c.request) +`; + } else if (traceConditions.handle || hasCookie) { + fnLiteral += isAsyncHandler ? `let r = await ${handle}; +` : `let r = ${handle}; +`; + endHandle(); + report("afterHandle")(); + if (hooks.mapResponse.length) { + fnLiteral += "c.response = r"; + for (let i = 0;i < hooks.mapResponse.length; i++) { + fnLiteral += ` +if(mr === undefined) { + mr = onMapResponse[${i}](c) + if(mr instanceof Promise) mr = await mr + if(mr !== undefined) r = c.response = mr + } +`; + } + } + fnLiteral += encodeCookie; + if (hasSet) + fnLiteral += `return mapResponse(r, c.set, c.request) +`; + else + fnLiteral += `return mapCompactResponse(r, c.request) +`; + } else { + endHandle(); + const handled = isAsyncHandler ? `await ${handle}` : handle; + report("afterHandle")(); + if (handler instanceof Response) { + fnLiteral += inference.set ? `if( + isNotEmpty(c.set.headers) || + c.set.status !== 200 || + c.set.redirect || + c.set.cookie + ) + return mapResponse(${handle}.clone(), c.set, c.request) + else + return ${handle}.clone()` : `return ${handle}.clone()`; + fnLiteral += "\n"; + } else if (hasSet) + fnLiteral += `return mapResponse(${handled}, c.set, c.request) +`; + else + fnLiteral += `return mapCompactResponse(${handled}, c.request) +`; + } + } + if (hasErrorHandler || handleResponse) { + fnLiteral += ` +} catch(error) {`; + if (!maybeAsync) + fnLiteral += `return (async () => {`; + fnLiteral += `const set = c.set +if (!set.status || set.status < 300) set.status = error?.status || 500 +`; + const endError = report("error", { + unit: hooks.error.length + }); + if (hooks.error.length) { + fnLiteral += ` + c.error = error + c.code = error.code ?? error[ERROR_CODE] ?? "UNKNOWN" + `; + for (let i = 0;i < hooks.error.length; i++) { + const name = `er${i}`; + const endUnit = report("error.unit", { + name: hooks.error[i].fn.name + }); + fnLiteral += ` +let ${name} = handleErrors[${i}](c) +`; + if (isAsync(hooks.error[i])) + fnLiteral += `if (${name} instanceof Promise) ${name} = await ${name} +`; + endUnit(); + fnLiteral += `${name} = mapEarlyResponse(${name}, set, c.request) +`; + fnLiteral += `if (${name}) {`; + fnLiteral += `return ${name} } +`; + } + } + endError(); + fnLiteral += `return handleError(c, error, true) + +`; + if (!maybeAsync) + fnLiteral += "})()"; + fnLiteral += "}"; + if (handleResponse || hasTrace) { + fnLiteral += ` finally { `; + const endResponse = report("response", { + unit: hooks.onResponse.length + }); + fnLiteral += handleResponse; + endResponse(); + fnLiteral += `}`; + } + } + fnLiteral = `const { + handler, + handleError, + hooks: { + transform, + resolve, + beforeHandle, + afterHandle, + mapResponse: onMapResponse, + parse, + error: handleErrors, + onResponse + }, + validator: { + body, + headers, + params, + query, + response, + cookie + }, + utils: { + mapResponse, + mapCompactResponse, + mapEarlyResponse, + parseQuery, + isNotEmpty + }, + error: { + NotFoundError, + ValidationError, + InternalServerError, + ParseError + }, + schema, + definitions, + ERROR_CODE, + getReporter, + requestId, + parseCookie, + signCookie, + decodeURIComponent, + ELYSIA_RESPONSE + } = hooks + + ${hooks.onResponse.length ? `const ${hooks.onResponse.map((x, i) => `res${i} = onResponse[${i}]`).join(",")}` : ""} + + return ${maybeAsync ? "async" : ""} function handle(c) { + ${hooks.beforeHandle.length ? "let be" : ""} + ${hooks.afterHandle.length ? "let af" : ""} + ${hooks.mapResponse.length ? "let mr" : ""} + + ${allowMeta ? "c.schema = schema; c.defs = definitions" : ""} + ${fnLiteral} + }`; + const createHandler = Function("hooks", fnLiteral); + return createHandler({ + handler, + hooks: lifeCycleToFn(hooks), + validator, + handleError: app.handleError, + utils: { + mapResponse, + mapCompactResponse, + mapEarlyResponse, + parseQuery: import_fast_querystring.parse, + isNotEmpty + }, + error: { + NotFoundError, + ValidationError, + InternalServerError, + ParseError + }, + schema: app.router.history, + definitions: app.definitions.type, + ERROR_CODE, + getReporter: () => app.reporter, + requestId, + parseCookie, + signCookie, + decodeURIComponent: import_fast_decode_uri_component2.default, + ELYSIA_RESPONSE + }); +}; +var composeGeneralHandler = (app) => { + const inference = { + event: { + ...app.inference.event, + queries: [...app.inference.event.queries] + }, + trace: { ...app.inference.trace } + }; + let decoratorsLiteral = ""; + let fnLiteral = ""; + const defaultHeaders = app.setHeaders; + for (const key of Object.keys(app.singleton.decorator)) + decoratorsLiteral += `,${key}: app.singleton.decorator.${key}`; + const router = app.router; + const hasTrace = app.event.trace.length > 0; + let findDynamicRoute = ` + const route = router.find(request.method, path) ${router.http.root.ALL ? '?? router.find("ALL", path)' : ""} + + if (route === null) + return ${app.event.error.length ? `app.handleError(ctx, notFound)` : app.event.request.length ? `new Response(error404Message, { + status: ctx.set.status === 200 ? 404 : ctx.set.status, + headers: ctx.set.headers + })` : `error404.clone()`} + + ctx.params = route.params +`; + const shouldPrecompile = app.config.precompile === true || typeof app.config.precompile === "object" && app.config.precompile.compose === true; + if (!shouldPrecompile) + findDynamicRoute += ` + if(route.store.composed) + return route.store.composed(ctx) + + if(route.store.compose) + return (route.store.compose())(ctx)`; + else + findDynamicRoute += `return route.store(ctx)`; + findDynamicRoute += "\n"; + let switchMap = ``; + for (const [path, { code, all }] of Object.entries(router.static.http.map)) + switchMap += `case '${path}': +switch(request.method) { +${code} +${all ?? `default: break map`}} + +`; + const maybeAsync = app.event.request.some(isAsync); + const init = ` + + const url = request.url + const s = url.indexOf('/', 11) + const qi = url.indexOf('?', s + 1) + let path + if(qi === -1) + path = url.substring(s) + else + path = url.substring(s, qi) +`; + fnLiteral += `const { + app, + mapEarlyResponse, + NotFoundError, + requestId, + getReporter, + handleError, + error, + redirect + } = data + + const store = app.singleton.store + const staticRouter = app.router.static.http + const wsRouter = app.router.ws + const router = app.router.http + + const notFound = new NotFoundError() + + ${app.event.request.length ? `const onRequest = app.event.request.map(x => x.fn)` : ""} + ${router.static.http.variables} + ${app.event.error.length ? "" : ` + const error404Message = notFound.message.toString() + const error404 = new Response(error404Message, { status: 404 }); + `} + + return ${maybeAsync ? "async" : ""} function map(request) { +`; + if (app.event.request.length) + fnLiteral += `let re`; + const report = createReport({ + hasTrace, + hasTraceSet: inference.trace.set, + condition: { + request: inference.trace.request + }, + addFn: (word) => { + fnLiteral += word; + } + }); + if (app.event.request.length) { + fnLiteral += ` + ${hasTrace ? "const id = +requestId.value++" : ""} + + const ctx = { + request, + store, + redirect, + set: { + headers: ${Object.keys(defaultHeaders ?? {}).length ? "Object.assign({}, app.setHeaders)" : "{}"}, + status: 200 + }, + error + ${hasTrace ? ",$$requestId: +id" : ""} + ${decoratorsLiteral} + } + `; + const endReport = report("request", { + attribute: "ctx", + unit: app.event.request.length + }); + fnLiteral += ` + try { +`; + for (let i = 0;i < app.event.request.length; i++) { + const hook = app.event.request[i]; + const withReturn = hasReturn(hook.fn.toString()); + const maybeAsync2 = isAsync(hook); + const endUnit = report("request.unit", { + name: app.event.request[i].fn.name + }); + if (withReturn) { + fnLiteral += `re = mapEarlyResponse( + ${maybeAsync2 ? "await" : ""} onRequest[${i}](ctx), + ctx.set, + request + ) +`; + endUnit(); + fnLiteral += `if(re !== undefined) return re +`; + } else { + fnLiteral += `${maybeAsync2 ? "await" : ""} onRequest[${i}](ctx) +`; + endUnit(); + } + } + fnLiteral += `} catch (error) { + return app.handleError(ctx, error) + }`; + endReport(); + fnLiteral += init; + fnLiteral += ` +ctx.qi = qi + ctx.path = path +`; + } else { + fnLiteral += init; + fnLiteral += `${hasTrace ? "const id = +requestId.value++" : ""} + const ctx = { + request, + store, + qi, + path, + redirect, + set: { + headers: ${Object.keys(defaultHeaders ?? {}).length ? "Object.assign({}, app.setHeaders)" : "{}"}, + status: 200 + }, + error + ${hasTrace ? ",$$requestId: id" : ""} + ${decoratorsLiteral} + }`; + report("request", { + unit: app.event.request.length, + attribute: inference.trace.context || inference.trace.store || inference.trace.set ? "ctx" : "" + })(); + } + const wsPaths = app.router.static.ws; + const wsRouter = app.router.ws; + if (Object.keys(wsPaths).length || wsRouter.history.length) { + fnLiteral += ` + if(request.method === 'GET') { + switch(path) {`; + for (const [path, index] of Object.entries(wsPaths)) { + fnLiteral += ` + case '${path}': + if(request.headers.get('upgrade') === 'websocket') + return st${index}(ctx) + + break`; + } + fnLiteral += ` + default: + if(request.headers.get('upgrade') === 'websocket') { + const route = wsRouter.find('ws', path) + + if(route) { + ctx.params = route.params + + return route.store(ctx) + } + } + + break + } + } +`; + } + fnLiteral += ` + map: switch(path) { + ${switchMap} + + default: + break + } + + ${findDynamicRoute} + }`; + const handleError = composeErrorHandler(app); + app.handleError = handleError; + return Function("data", fnLiteral)({ + app, + mapEarlyResponse, + NotFoundError, + getReporter: () => app.reporter, + requestId, + handleError, + error: error22, + redirect + }); +}; +var composeErrorHandler = (app) => { + let fnLiteral = `const { + app: { event: { error: onErrorContainer, onResponse: resContainer } }, + mapResponse, + ERROR_CODE, + ELYSIA_RESPONSE + } = inject + + const onError = onErrorContainer.map(x => x.fn) + const res = resContainer.map(x => x.fn) + + return ${app.event.error.find(isAsync) ? "async" : ""} function(context, error, skipGlobal) { + let r + + const { set } = context + + context.code = error.code + context.error = error + + if(typeof error === "object" && ELYSIA_RESPONSE in error) { + error.status = error[ELYSIA_RESPONSE] + error.message = error.response + } +`; + for (let i = 0;i < app.event.error.length; i++) { + const handler = app.event.error[i]; + const response = `${isAsync(handler) ? "await " : ""}onError[${i}](context)`; + fnLiteral += "\nif(skipGlobal !== true) {\n"; + if (hasReturn(handler.fn.toString())) + fnLiteral += `r = ${response}; if(r !== undefined) { + if(r instanceof Response) return r + + if(r[ELYSIA_RESPONSE]) { + error.status = error[ELYSIA_RESPONSE] + error.message = error.response + } + + if(set.status === 200) set.status = error.status + return mapResponse(r, set, context.request) + } +`; + else + fnLiteral += response + "\n"; + fnLiteral += "\n}\n"; + } + fnLiteral += `if(error.constructor.name === "ValidationError" || error.constructor.name === "TransformDecodeError") { + set.status = error.status ?? 422 + return new Response( + error.message, + { + headers: Object.assign( + { 'content-type': 'application/json'}, + set.headers + ), + status: set.status + } + ) + } else { + if(error.code && typeof error.status === "number") + return new Response( + error.message, + { headers: set.headers, status: error.status } + ) + + return mapResponse(error, set, context.request) + } +}`; + return Function("inject", fnLiteral)({ + app, + mapResponse, + ERROR_CODE, + ELYSIA_RESPONSE + }); +}; +var jitRoute = (index) => `if(stc${index}) return stc${index}(ctx) +if(st${index}.compose) return (stc${index} = st${index}.compose())(ctx) + +return st${index}(ctx)`; +var createDynamicHandler = (app) => async (request) => { + const url = request.url, s = url.indexOf("/", 11), qi = url.indexOf("?", s + 1), path = qi === -1 ? url.substring(s) : url.substring(s, qi); + const set2 = { + cookie: {}, + status: 200, + headers: {} + }; + const context = Object.assign({}, app.singleton.decorator, { + set: set2, + store: app.singleton.store, + request, + path, + qi + }); + try { + for (let i = 0;i < app.event.request.length; i++) { + const onRequest = app.event.request[i].fn; + let response2 = onRequest(context); + if (response2 instanceof Promise) + response2 = await response2; + response2 = mapEarlyResponse(response2, set2); + if (response2) + return response2; + } + const handler = app.router.dynamic.find(request.method, path) ?? app.router.dynamic.find("ALL", path); + if (!handler) + throw new NotFoundError; + const { handle, hooks, validator, content } = handler.store; + let body; + if (request.method !== "GET" && request.method !== "HEAD") { + if (content) { + switch (content) { + case "application/json": + body = await request.json(); + break; + case "text/plain": + body = await request.text(); + break; + case "application/x-www-form-urlencoded": + body = import_fast_querystring2.parse(await request.text()); + break; + case "application/octet-stream": + body = await request.arrayBuffer(); + break; + case "multipart/form-data": + body = {}; + const form = await request.formData(); + for (const key of form.keys()) { + if (body[key]) + continue; + const value15 = form.getAll(key); + if (value15.length === 1) + body[key] = value15[0]; + else + body[key] = value15; + } + break; + } + } else { + let contentType = request.headers.get("content-type"); + if (contentType) { + const index = contentType.indexOf(";"); + if (index !== -1) + contentType = contentType.slice(0, index); + context.contentType = contentType; + for (let i = 0;i < hooks.parse.length; i++) { + const hook = hooks.parse[i].fn; + let temp = hook(context, contentType); + if (temp instanceof Promise) + temp = await temp; + if (temp) { + body = temp; + break; + } + } + delete context.contentType; + if (body === undefined) { + switch (contentType) { + case "application/json": + body = await request.json(); + break; + case "text/plain": + body = await request.text(); + break; + case "application/x-www-form-urlencoded": + body = import_fast_querystring2.parse(await request.text()); + break; + case "application/octet-stream": + body = await request.arrayBuffer(); + break; + case "multipart/form-data": + body = {}; + const form = await request.formData(); + for (const key of form.keys()) { + if (body[key]) + continue; + const value15 = form.getAll(key); + if (value15.length === 1) + body[key] = value15[0]; + else + body[key] = value15; + } + break; + } + } + } + } + } + context.body = body; + context.params = handler?.params || undefined; + context.query = qi === -1 ? {} : import_fast_querystring2.parse(url.substring(qi + 1)); + context.headers = {}; + for (const [key, value15] of request.headers.entries()) + context.headers[key] = value15; + const cookieMeta = Object.assign({}, app.config?.cookie, validator?.cookie?.config); + const cookieHeaderValue = request.headers.get("cookie"); + context.cookie = await parseCookie(context.set, cookieHeaderValue, cookieMeta ? { + secrets: cookieMeta.secrets !== undefined ? typeof cookieMeta.secrets === "string" ? cookieMeta.secrets : cookieMeta.secrets.join(",") : undefined, + sign: cookieMeta.sign === true ? true : cookieMeta.sign !== undefined ? typeof cookieMeta.sign === "string" ? cookieMeta.sign : cookieMeta.sign.join(",") : undefined + } : undefined); + for (let i = 0;i < hooks.transform.length; i++) { + const hook = hooks.transform[i]; + const operation = hook.fn(context); + if (hook.subType === "derive") { + if (operation instanceof Promise) + Object.assign(context, await operation); + else + Object.assign(context, operation); + } else if (operation instanceof Promise) + await operation; + } + if (validator) { + if (validator.headers) { + const _header = {}; + for (const key in request.headers) + _header[key] = request.headers.get(key); + if (validator.headers.Check(_header) === false) + throw new ValidationError("header", validator.headers, _header); + } + if (validator.params?.Check(context.params) === false) + throw new ValidationError("params", validator.params, context.params); + if (validator.query?.Check(context.query) === false) + throw new ValidationError("query", validator.query, context.query); + if (validator.cookie) { + const cookieValue = {}; + for (const [key, value15] of Object.entries(context.cookie)) + cookieValue[key] = value15.value; + if (validator.cookie?.Check(cookieValue) === false) + throw new ValidationError("cookie", validator.cookie, cookieValue); + } + if (validator.body?.Check(body) === false) + throw new ValidationError("body", validator.body, body); + } + for (let i = 0;i < hooks.beforeHandle.length; i++) { + let response2 = hooks.beforeHandle[i].fn(context); + if (response2 instanceof Promise) + response2 = await response2; + if (response2 !== undefined) { + context.response = response2; + for (let i2 = 0;i2 < hooks.afterHandle.length; i2++) { + let newResponse = hooks.afterHandle[i2].fn(context); + if (newResponse instanceof Promise) + newResponse = await newResponse; + if (newResponse) + response2 = newResponse; + } + const result = mapEarlyResponse(response2, context.set); + if (result) + return result; + } + } + let response = handle(context); + if (response instanceof Promise) + response = await response; + if (!hooks.afterHandle.length) { + const responseValidator = validator?.response?.[response.status]; + if (responseValidator?.Check(response) === false) + throw new ValidationError("response", responseValidator, response); + } else { + context.response = response; + for (let i = 0;i < hooks.afterHandle.length; i++) { + let newResponse = hooks.afterHandle[i].fn(context); + if (newResponse instanceof Promise) + newResponse = await newResponse; + const result = mapEarlyResponse(newResponse, context.set); + if (result !== undefined) { + const responseValidator = validator?.response?.[response.status]; + if (responseValidator?.Check(result) === false) + throw new ValidationError("response", responseValidator, result); + return result; + } + } + } + if (context.set.cookie && cookieMeta?.sign) { + const secret = !cookieMeta.secrets ? undefined : typeof cookieMeta.secrets === "string" ? cookieMeta.secrets : cookieMeta.secrets[0]; + if (cookieMeta.sign === true) + for (const [key, cookie] of Object.entries(context.set.cookie)) + context.set.cookie[key].value = await signCookie(cookie.value, "${secret}"); + else { + const properties = validator?.cookie?.schema?.properties; + for (const name of cookieMeta.sign) { + if (!(name in properties)) + continue; + if (context.set.cookie[name]?.value) { + context.set.cookie[name].value = await signCookie(context.set.cookie[name].value, secret); + } + } + } + } + return mapResponse(response, context.set); + } catch (error23) { + if (error23.status) + set2.status = error23.status; + return app.handleError(context, error23); + } finally { + for (const onResponse of app.event.onResponse) + await onResponse.fn(context); + } +}; +var createDynamicErrorHandler = (app) => async (context, error23) => { + const errorContext = Object.assign(context, { error: error23, code: error23.code }); + errorContext.set = context.set; + for (let i = 0;i < app.event.error.length; i++) { + const hook = app.event.error[i]; + let response = hook.fn(errorContext); + if (response instanceof Promise) + response = await response; + if (response !== undefined && response !== null) + return mapResponse(response, context.set); + } + return new Response(typeof error23.cause === "string" ? error23.cause : error23.message, { + headers: context.set.headers, + status: error23.status ?? 500 + }); +}; +var fullFormats = { + date: date5, + time: getTime(true), + "date-time": getDateTime(true), + "iso-time": getTime(false), + "iso-date-time": getDateTime(false), + duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/, + uri, + "uri-reference": /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'"()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i, + "uri-template": /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i, + url: /^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu, + email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i, + hostname: /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i, + ipv4: /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/, + ipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i, + regex, + uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i, + "json-pointer": /^(?:\/(?:[^~/]|~0|~1)*)*$/, + "json-pointer-uri-fragment": /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i, + "relative-json-pointer": /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/, + byte, + int32: { type: "number", validate: validateInt32 }, + int64: { type: "number", validate: validateInt64 }, + float: { type: "number", validate: validateNumber }, + double: { type: "number", validate: validateNumber }, + password: true, + binary: true +}; +var DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; +var DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; +var TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i; +var DATE_TIME_SEPARATOR = /t|\s/i; +var NOT_URI_FRAGMENT = /\/|:/; +var URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i; +var BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm; +var MIN_INT32 = -(2 ** 31); +var MAX_INT32 = 2 ** 31 - 1; +var Z_ANCHOR = /[^\\]\\Z/; +var isISO8601 = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/; +var isFormalDate = /(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s\d{2}\s\d{4}\s\d{2}:\d{2}:\d{2}\sGMT(?:\+|-)\d{4}\s\([^)]+\)/; +var isShortenDate = /^(?:(?:(?:(?:0?[1-9]|[12][0-9]|3[01])[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:19|20)\d{2})|(?:(?:19|20)\d{2}[/\s-](?:0?[1-9]|1[0-2])[/\s-](?:0?[1-9]|[12][0-9]|3[01]))))(?:\s(?:1[012]|0?[1-9]):[0-5][0-9](?::[0-5][0-9])?(?:\s[AP]M)?)?$/; +var _validateDate = fullFormats.date; +var _validateDateTime = fullFormats["date-time"]; +if (!exports_format.Has("date")) + TypeSystem.Format("date", (value15) => { + const temp = value15.replace(/"/g, ""); + if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) { + const date22 = new Date(temp); + if (!Number.isNaN(date22.getTime())) + return true; + } + return false; + }); +if (!exports_format.Has("date-time")) + TypeSystem.Format("date-time", (value15) => { + const temp = value15.replace(/"/g, ""); + if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) { + const date22 = new Date(temp); + if (!Number.isNaN(date22.getTime())) + return true; + } + return false; + }); +Object.entries(fullFormats).forEach((formatEntry) => { + const [formatName, formatValue] = formatEntry; + if (!exports_format.Has(formatName)) { + if (formatValue instanceof RegExp) + TypeSystem.Format(formatName, (value15) => formatValue.test(value15)); + else if (typeof formatValue === "function") + TypeSystem.Format(formatName, formatValue); + } +}); +var t2 = Object.assign({}, Type); +var parseFileUnit = (size) => { + if (typeof size === "string") + switch (size.slice(-1)) { + case "k": + return +size.slice(0, size.length - 1) * 1024; + case "m": + return +size.slice(0, size.length - 1) * 1048576; + default: + return +size; + } + return size; +}; +var validateFile = (options, value15) => { + if (!(value15 instanceof Blob)) + return false; + if (options.minSize && value15.size < parseFileUnit(options.minSize)) + return false; + if (options.maxSize && value15.size > parseFileUnit(options.maxSize)) + return false; + if (options.extension) + if (typeof options.extension === "string") { + if (!value15.type.startsWith(options.extension)) + return false; + } else { + for (let i = 0;i < options.extension.length; i++) + if (value15.type.startsWith(options.extension[i])) + return true; + return false; + } + return true; +}; +var File = exports_type.Get("Files") ?? TypeSystem.Type("File", validateFile); +var Files = exports_type.Get("Files") ?? TypeSystem.Type("Files", (options, value15) => { + if (!Array.isArray(value15)) + return validateFile(options, value15); + if (options.minItems && value15.length < options.minItems) + return false; + if (options.maxItems && value15.length > options.maxItems) + return false; + for (let i = 0;i < value15.length; i++) + if (!validateFile(options, value15[i])) + return false; + return true; +}); +if (!exports_format.Has("numeric")) + exports_format.Set("numeric", (value15) => !!value15 && !isNaN(+value15)); +if (!exports_format.Has("boolean")) + exports_format.Set("boolean", (value15) => value15 === "true" || value15 === "false"); +if (!exports_format.Has("ObjectString")) + exports_format.Set("ObjectString", (value15) => { + let start = value15.charCodeAt(0); + if (start === 9 || start === 10 || start === 32) + start = value15.trimStart().charCodeAt(0); + if (start !== 123 && start !== 91) + return false; + try { + JSON.parse(value15); + return true; + } catch { + return false; + } + }); +var ElysiaType = { + Numeric: (property) => { + const schema3 = Type.Number(property); + return t2.Transform(t2.Union([ + t2.String({ + format: "numeric", + default: 0 + }), + t2.Number(property) + ], property)).Decode((value15) => { + const number7 = +value15; + if (isNaN(number7)) + return value15; + if (property && !exports_value2.Check(schema3, number7)) + throw new ValidationError("property", schema3, number7); + return number7; + }).Encode((value15) => value15); + }, + Date: (property) => { + const schema3 = Type.Date(property); + return t2.Transform(t2.Union([ + Type.Date(property), + t2.String({ + format: "date", + default: (new Date()).toISOString() + }), + t2.String({ + format: "date-time", + default: (new Date()).toISOString() + }) + ], property)).Decode((value15) => { + if (value15 instanceof Date) + return value15; + const date22 = new Date(value15); + if (!exports_value2.Check(schema3, date22)) + throw new ValidationError("property", schema3, date22); + return date22; + }).Encode((value15) => { + if (typeof value15 === "string") + return new Date(value15); + return value15; + }); + }, + BooleanString: (property) => { + const schema3 = Type.Boolean(property); + return t2.Transform(t2.Union([ + t2.String({ + format: "boolean", + default: false + }), + t2.Boolean(property) + ], property)).Decode((value15) => { + if (typeof value15 === "string") + return value15 === "true"; + if (property && !exports_value2.Check(schema3, value15)) + throw new ValidationError("property", schema3, value15); + return value15; + }).Encode((value15) => value15); + }, + ObjectString: (properties = {}, options) => { + const schema3 = t2.Object(properties, options); + const defaultValue = JSON.stringify(exports_value2.Create(schema3)); + return t2.Transform(t2.Union([ + t2.String({ + format: "ObjectString", + default: defaultValue + }), + schema3 + ])).Decode((value15) => { + if (typeof value15 === "string") { + try { + value15 = JSON.parse(value15); + } catch { + throw new ValidationError("property", schema3, value15); + } + if (!exports_value2.Check(schema3, value15)) + throw new ValidationError("property", schema3, value15); + return value15; + } + return value15; + }).Encode((value15) => { + if (typeof value15 === "string") + try { + value15 = JSON.parse(value15); + } catch { + throw new ValidationError("property", schema3, value15); + } + if (!exports_value2.Check(schema3, value15)) + throw new ValidationError("property", schema3, value15); + return JSON.stringify(value15); + }); + }, + File, + Files: (options = {}) => t2.Transform(Files(options)).Decode((value15) => { + if (Array.isArray(value15)) + return value15; + return [value15]; + }).Encode((value15) => value15), + Nullable: (schema3) => t2.Union([t2.Null(), schema3]), + MaybeEmpty: (schema3) => t2.Union([t2.Null(), t2.Undefined(), schema3]), + Cookie: (properties, { + domain, + expires, + httpOnly, + maxAge, + path, + priority, + sameSite, + secure, + secrets, + sign, + ...options + } = {}) => { + const v = t2.Object(properties, options); + v.config = { + domain, + expires, + httpOnly, + maxAge, + path, + priority, + sameSite, + secure, + secrets, + sign + }; + return v; + } +}; +t2.BooleanString = ElysiaType.BooleanString; +t2.ObjectString = ElysiaType.ObjectString; +t2.Numeric = ElysiaType.Numeric; +t2.File = (arg = {}) => ElysiaType.File({ + default: "File", + ...arg, + extension: arg?.type, + type: "string", + format: "binary" +}); +t2.Files = (arg = {}) => ElysiaType.Files({ + ...arg, + elysiaMeta: "Files", + default: "Files", + extension: arg?.type, + type: "array", + items: { + ...arg, + default: "Files", + type: "string", + format: "binary" + } +}); +t2.Nullable = (schema3) => ElysiaType.Nullable(schema3); +t2.MaybeEmpty = ElysiaType.MaybeEmpty; +t2.Cookie = ElysiaType.Cookie; +t2.Date = ElysiaType.Date; +var Elysia = class _Elysia { + constructor(config) { + this.server = null; + this.dependencies = {}; + this.reporter = new eventemitter3_default; + this._routes = {}; + this._types = { + Prefix: "", + Scoped: false, + Singleton: {}, + Definitions: {}, + Metadata: {} + }; + this._ephemeral = {}; + this._volatile = {}; + this.singleton = { + decorator: {}, + store: {}, + derive: {}, + resolve: {} + }; + this.definitions = { + type: {}, + error: {} + }; + this.extender = { + macros: [] + }; + this.validator = null; + this.event = { + start: [], + request: [], + parse: [], + transform: [], + beforeHandle: [], + afterHandle: [], + mapResponse: [], + onResponse: [], + trace: [], + error: [], + stop: [] + }; + this.telemetry = { + stack: undefined + }; + this.router = { + http: new Memoirist, + ws: new Memoirist, + dynamic: new Memoirist, + static: { + http: { + handlers: [], + variables: "", + map: {}, + all: "" + }, + ws: {} + }, + history: [] + }; + this.inference = { + event: { + body: false, + cookie: false, + headers: false, + queries: [], + query: false, + set: false, + unknownQueries: false + }, + trace: { + request: false, + parse: false, + transform: false, + handle: false, + beforeHandle: false, + afterHandle: false, + error: false, + context: false, + store: false, + set: false + } + }; + this.promisedModules = new PromiseGroup; + this.routeTree = new Map; + this.handle = async (request) => this.fetch(request); + this.fetch = (request) => { + if (false) + ; + return (this.fetch = this.config.aot ? composeGeneralHandler(this) : createDynamicHandler(this))(request); + }; + this.handleError = async (context, error23) => (this.handleError = this.config.aot ? composeErrorHandler(this) : createDynamicErrorHandler(this))(context, error23); + this.outerErrorHandler = (error23) => new Response(error23.message || error23.name || "Error", { + status: error23?.status ?? 500 + }); + this.listen = (options, callback) => { + if (typeof Bun === "undefined") + throw new Error(".listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch"); + this.compile(); + if (typeof options === "string") { + if (!isNumericString(options)) + throw new Error("Port must be a numeric value"); + options = parseInt(options); + } + const fetch = this.fetch; + const serve = typeof options === "object" ? { + development: !isProduction, + reusePort: true, + ...this.config.serve || {}, + ...options || {}, + websocket: { + ...this.config.websocket || {}, + ...websocket || {} + }, + fetch, + error: this.outerErrorHandler + } : { + development: !isProduction, + reusePort: true, + ...this.config.serve || {}, + websocket: { + ...this.config.websocket || {}, + ...websocket || {} + }, + port: options, + fetch, + error: this.outerErrorHandler + }; + this.server = Bun?.serve(serve); + for (let i = 0;i < this.event.start.length; i++) + this.event.start[i].fn(this); + if (callback) + callback(this.server); + process.on("beforeExit", () => { + if (this.server) { + this.server.stop(); + this.server = null; + for (let i = 0;i < this.event.stop.length; i++) + this.event.stop[i].fn(this); + } + }); + this.promisedModules.then(() => { + Bun?.gc(false); + }); + return this; + }; + this.stop = async () => { + if (!this.server) + throw new Error("Elysia isn't running. Call `app.listen` to start the server."); + if (this.server) { + this.server.stop(); + this.server = null; + if (this.event.stop.length) + for (let i = 0;i < this.event.stop.length; i++) + this.event.stop[i].fn(this); + } + }; + if (config?.tags) { + if (!config.detail) + config.detail = { + tags: config.tags + }; + else + config.detail.tags = config.tags; + } + this.config = { + forceErrorEncapsulation: true, + prefix: "", + aot: true, + strictPath: false, + global: false, + cookie: {}, + analytic: false, + ...config, + experimental: config?.experimental ?? {}, + seed: config?.seed === undefined ? "" : config?.seed + }; + if (config?.analytic && (config?.name || config?.seed !== undefined)) + this.telemetry.stack = new Error().stack; + } + get store() { + return this.singleton.store; + } + get decorator() { + return this.singleton.decorator; + } + get _scoped() { + return this.config.scoped; + } + getServer() { + return this.server; + } + get routes() { + return this.router.history; + } + applyMacro(localHook) { + if (this.extender.macros.length) { + const manage = createMacroManager({ + globalHook: this.event, + localHook + }); + const manager = { + events: { + global: this.event, + local: localHook + }, + onParse: manage("parse"), + onTransform: manage("transform"), + onBeforeHandle: manage("beforeHandle"), + onAfterHandle: manage("afterHandle"), + onResponse: manage("onResponse"), + mapResponse: manage("mapResponse"), + onError: manage("error") + }; + for (const macro of this.extender.macros) + traceBackMacro(macro.fn(manager), localHook); + } + } + add(method, path, handle, localHook, { allowMeta = false, skipPrefix = false } = { + allowMeta: false, + skipPrefix: false + }) { + localHook = localHookToLifeCycleStore(localHook); + if (path !== "" && path.charCodeAt(0) !== 47) + path = "/" + path; + if (this.config.prefix && !skipPrefix && !this.config.scoped) + path = this.config.prefix + path; + if (localHook?.type) + switch (localHook.type) { + case "text": + localHook.type = "text/plain"; + break; + case "json": + localHook.type = "application/json"; + break; + case "formdata": + localHook.type = "multipart/form-data"; + break; + case "urlencoded": + localHook.type = "application/x-www-form-urlencoded"; + break; + case "arrayBuffer": + localHook.type = "application/octet-stream"; + break; + default: + break; + } + const models = this.definitions.type; + let _body, _headers, _params, _query, _cookie, _response; + const dynamic = !this.config.aot; + const cloned = { + body: localHook?.body ?? this.validator?.body, + headers: localHook?.headers ?? this.validator?.headers, + params: localHook?.params ?? this.validator?.params, + query: localHook?.query ?? this.validator?.query, + cookie: localHook?.cookie ?? this.validator?.cookie, + response: localHook?.response ?? this.validator?.response + }; + const cookieValidator = () => cloned.cookie ? getCookieValidator({ + validator: cloned.cookie, + defaultConfig: this.config.cookie, + config: cloned.cookie?.config ?? {}, + dynamic, + models + }) : undefined; + const normalize = this.config.normalize; + const validator = this.config.precompile === true || typeof this.config.precompile === "object" && this.config.precompile.schema === true ? { + body: getSchemaValidator(cloned.body, { + dynamic, + models, + normalize + }), + headers: getSchemaValidator(cloned.headers, { + dynamic, + models, + additionalProperties: true + }), + params: getSchemaValidator(cloned.params, { + dynamic, + models + }), + query: getSchemaValidator(cloned.query, { + dynamic, + models, + normalize + }), + cookie: cookieValidator(), + response: getResponseSchemaValidator(cloned.response, { + dynamic, + models, + normalize + }) + } : { + get body() { + if (_body) + return _body; + return _body = getSchemaValidator(cloned.body, { + dynamic, + models, + normalize + }); + }, + get headers() { + if (_headers) + return _headers; + return getSchemaValidator(cloned.headers, { + dynamic, + models, + additionalProperties: true + }); + }, + get params() { + if (_params) + return _params; + return _params = getSchemaValidator(cloned.params, { + dynamic, + models + }); + }, + get query() { + if (_query) + return _query; + return _query = getSchemaValidator(cloned.query, { + dynamic, + models + }); + }, + get cookie() { + if (_cookie) + return _cookie; + return _cookie = cookieValidator(); + }, + get response() { + if (_response) + return _response; + return _response = getResponseSchemaValidator(cloned.response, { + dynamic, + models, + normalize + }); + } + }; + const loosePath = path.endsWith("/") ? path.slice(0, path.length - 1) : path + "/"; + localHook = mergeHook(localHook, {}, { allowMacro: true }); + if (localHook.tags) { + if (!localHook.detail) + localHook.detail = { + tags: localHook.tags + }; + else + localHook.detail.tags = localHook.tags; + } + if (isNotEmpty(this.config.detail)) + localHook.detail = mergeDeep(Object.assign({}, this.config.detail), localHook.detail); + this.applyMacro(localHook); + const hooks = mergeHook(this.event, localHook); + if (this.config.aot === false) { + this.router.dynamic.add(method, path, { + validator, + hooks, + content: localHook?.type, + handle + }); + if (this.config.strictPath === false) { + this.router.dynamic.add(method, loosePath, { + validator, + hooks, + content: localHook?.type, + handle + }); + } + this.router.history.push({ + method, + path, + composed: null, + handler: handle, + hooks + }); + return; + } + let composed = undefined; + const shouldPrecompile = this.config.precompile === true || typeof this.config.precompile === "object" && this.config.precompile.compose === true; + const appInference = cloneInference(this.inference); + const mainHandler = shouldPrecompile ? composeHandler({ + app: this, + path, + method, + localHook: mergeHook(localHook), + hooks, + validator, + handler: handle, + allowMeta, + appInference + }) : (context) => { + if (composed) + return composed(context); + return (composed = composeHandler({ + app: this, + path, + method, + localHook: mergeHook(localHook), + hooks, + validator, + handler: handle, + allowMeta, + appInference + }))(context); + }; + if (!shouldPrecompile) + mainHandler.compose = () => { + return mainHandler.composed = composeHandler({ + app: this, + path, + method, + localHook: mergeHook(localHook), + hooks, + validator, + handler: handle, + allowMeta, + appInference + }); + }; + let routeIndex = this.router.history.length; + if (this.routeTree.has(method + path)) { + routeIndex = this.router.history.findIndex((route) => route.path === path && route.method === method); + if (routeIndex !== -1) { + const removed = this.router.history.splice(routeIndex, 1)[0]; + if (removed && this.routeTree.has(removed?.method + removed?.path)) + this.routeTree.delete(removed.method + removed.path); + } + } + this.routeTree.set(method + path, routeIndex); + this.router.history.push({ + method, + path, + composed: mainHandler, + handler: handle, + hooks + }); + const staticRouter = this.router.static.http; + if (method === "$INTERNALWS") { + const loose = this.config.strictPath ? undefined : path.endsWith("/") ? path.slice(0, path.length - 1) : path + "/"; + if (path.indexOf(":") === -1 && path.indexOf("*") === -1) { + const index = staticRouter.handlers.length; + staticRouter.handlers.push(mainHandler); + staticRouter.variables += `const st${index} = staticRouter.handlers[${index}] +`; + this.router.static.ws[path] = index; + if (loose) + this.router.static.ws[loose] = index; + } else { + this.router.ws.add("ws", path, mainHandler); + if (loose) + this.router.ws.add("ws", loose, mainHandler); + } + return; + } + if (path.indexOf(":") === -1 && path.indexOf("*") === -1) { + const index = staticRouter.handlers.length; + staticRouter.handlers.push(mainHandler); + staticRouter.variables += shouldPrecompile ? `const st${index} = staticRouter.handlers[${index}] +` : `let st${index} = staticRouter.handlers[${index}] +let stc${index} +`; + if (!staticRouter.map[path]) + staticRouter.map[path] = { + code: "" + }; + if (method === "ALL") + staticRouter.map[path].all = shouldPrecompile ? `default: return st${index}(ctx) +` : `default: ${jitRoute(index)} +`; + else + staticRouter.map[path].code = shouldPrecompile ? `case '${method}': return st${index}(ctx) +${staticRouter.map[path].code}` : `case '${method}': ${jitRoute(index)} +${staticRouter.map[path].code}`; + if (!this.config.strictPath) { + if (!staticRouter.map[loosePath]) + staticRouter.map[loosePath] = { + code: "" + }; + if (method === "ALL") + staticRouter.map[loosePath].all = shouldPrecompile ? `default: return st${index}(ctx) +` : `default: ${jitRoute(index)} +`; + else + staticRouter.map[loosePath].code = shouldPrecompile ? `case '${method}': return st${index}(ctx) +${staticRouter.map[loosePath].code}` : `case '${method}': ${jitRoute(index)} +${staticRouter.map[loosePath].code}`; + } + } else { + this.router.http.add(method, path, mainHandler); + if (!this.config.strictPath) + this.router.http.add(method, path.endsWith("/") ? path.slice(0, path.length - 1) : path + "/", mainHandler); + } + } + headers(header) { + if (!header) + return this; + if (!this.setHeaders) + this.setHeaders = {}; + this.setHeaders = mergeDeep(this.setHeaders, header); + return this; + } + onStart(handler) { + this.on("start", handler); + return this; + } + onRequest(handler) { + this.on("request", handler); + return this; + } + onParse(options, handler) { + if (!handler) + return this.on("parse", options); + return this.on(options, "parse", handler); + } + onTransform(options, handler) { + if (!handler) + return this.on("transform", options); + return this.on(options, "transform", handler); + } + resolve(optionsOrResolve, resolve) { + if (!resolve) { + resolve = optionsOrResolve; + optionsOrResolve = { as: "local" }; + } + const hook = { + subType: "resolve", + fn: resolve + }; + return this.onBeforeHandle(optionsOrResolve, hook); + } + mapResolve(optionsOrResolve, mapper) { + if (!mapper) { + mapper = optionsOrResolve; + optionsOrResolve = { as: "local" }; + } + const hook = { + subType: "resolve", + fn: mapper + }; + return this.onBeforeHandle(optionsOrResolve, hook); + } + onBeforeHandle(options, handler) { + if (!handler) + return this.on("beforeHandle", options); + return this.on(options, "beforeHandle", handler); + } + onAfterHandle(options, handler) { + if (!handler) + return this.on("afterHandle", options); + return this.on(options, "afterHandle", handler); + } + mapResponse(options, handler) { + if (!handler) + return this.on("mapResponse", options); + return this.on(options, "mapResponse", handler); + } + onResponse(options, handler) { + if (!handler) + return this.on("response", options); + return this.on(options, "response", handler); + } + trace(options, handler) { + if (!handler) { + handler = options; + options = { as: "local" }; + } + if (!Array.isArray(handler)) + handler = [handler]; + for (const fn of handler) + this.reporter.on("event", createTraceListener(() => this.reporter, this.event.trace.length, fn)); + this.on(options, "trace", handler); + return this; + } + error(name, error23) { + switch (typeof name) { + case "string": + error23.prototype[ERROR_CODE] = name; + this.definitions.error[name] = error23; + return this; + case "function": + this.definitions.error = name(this.definitions.error); + return this; + } + for (const [code, error32] of Object.entries(name)) { + error32.prototype[ERROR_CODE] = code; + this.definitions.error[code] = error32; + } + return this; + } + onError(options, handler) { + if (!handler) + return this.on("error", options); + return this.on(options, "error", handler); + } + onStop(handler) { + this.on("stop", handler); + return this; + } + on(optionsOrType, typeOrHandlers, handlers) { + let type74; + switch (typeof optionsOrType) { + case "string": + type74 = optionsOrType; + handlers = typeOrHandlers; + break; + case "object": + type74 = typeOrHandlers; + break; + } + if (type74 === "response") + type74 = "onResponse"; + if (Array.isArray(handlers)) + handlers = fnToContainer(handlers); + else { + if (typeof handlers === "function") + handlers = [ + { + fn: handlers + } + ]; + else + handlers = [handlers]; + } + const handles = handlers; + for (const handle of handles) + handle.scope = typeof optionsOrType === "string" ? "local" : optionsOrType?.as ?? "local"; + if (type74 === "trace") + sucroseTrace(handles.map((x) => x.fn), this.inference.trace); + else + sucrose({ + [type74]: handles.map((x) => x.fn) + }, this.inference.event); + for (const handle of handles) { + const fn = asHookType(handle, "global", { skipIfHasType: true }); + switch (type74) { + case "start": + this.event.start.push(fn); + break; + case "request": + this.event.request.push(fn); + break; + case "parse": + this.event.parse.push(fn); + break; + case "transform": + this.event.transform.push(fn); + break; + case "beforeHandle": + this.event.beforeHandle.push(fn); + break; + case "afterHandle": + this.event.afterHandle.push(fn); + break; + case "mapResponse": + this.event.mapResponse.push(fn); + break; + case "onResponse": + this.event.onResponse.push(fn); + break; + case "trace": + this.event.trace.push(fn); + break; + case "error": + this.event.error.push(fn); + break; + case "stop": + this.event.stop.push(fn); + break; + } + } + return this; + } + propagate() { + const promoteEvent = (events) => { + for (const event of events) { + if ("scope" in event && event.scope === "local") + event.scope = "scoped"; + } + }; + promoteEvent(this.event.parse); + promoteEvent(this.event.transform); + promoteEvent(this.event.beforeHandle); + promoteEvent(this.event.afterHandle); + promoteEvent(this.event.mapResponse); + promoteEvent(this.event.onResponse); + promoteEvent(this.event.trace); + promoteEvent(this.event.error); + return this; + } + group(prefix, schemaOrRun, run) { + const instance = new _Elysia({ + ...this.config, + prefix: "" + }); + instance.singleton = { ...this.singleton }; + instance.definitions = { ...this.definitions }; + instance.getServer = () => this.server; + instance.inference = cloneInference(this.inference); + const isSchema = typeof schemaOrRun === "object"; + const sandbox = (isSchema ? run : schemaOrRun)(instance); + this.singleton = mergeDeep(this.singleton, instance.singleton); + this.definitions = mergeDeep(this.definitions, instance.definitions); + if (sandbox.event.request.length) + this.event.request = [ + ...this.event.request || [], + ...sandbox.event.request || [] + ]; + if (sandbox.event.onResponse.length) + this.event.onResponse = [ + ...this.event.onResponse || [], + ...sandbox.event.onResponse || [] + ]; + this.model(sandbox.definitions.type); + Object.values(instance.router.history).forEach(({ method, path, handler, hooks }) => { + path = (isSchema ? "" : this.config.prefix) + prefix + path; + if (isSchema) { + const hook = schemaOrRun; + const localHook = hooks; + this.add(method, path, handler, mergeHook(hook, { + ...localHook || {}, + error: !localHook.error ? sandbox.event.error : Array.isArray(localHook.error) ? [ + ...localHook.error || {}, + ...sandbox.event.error || {} + ] : [ + localHook.error, + ...sandbox.event.error || {} + ] + })); + } else { + this.add(method, path, handler, mergeHook(hooks, { + error: sandbox.event.error + }), { + skipPrefix: true + }); + } + }); + return this; + } + guard(hook, run) { + if (!run) { + if (typeof hook === "object") { + this.applyMacro(hook); + this.event = mergeLifeCycle(this.event, hook); + this.validator = { + body: hook.body ?? this.validator?.body, + headers: hook.headers ?? this.validator?.headers, + params: hook.params ?? this.validator?.params, + query: hook.query ?? this.validator?.query, + response: hook.response ?? this.validator?.response, + cookie: hook.cookie ?? this.validator?.cookie + }; + if (hook.detail) { + if (this.config.detail) + this.config.detail = mergeDeep(Object.assign({}, this.config.detail), hook.detail); + else + this.config.detail = hook.detail; + } + if (hook?.tags) { + if (!this.config.detail) + this.config.detail = { + tags: hook.tags + }; + else + this.config.detail.tags = hook.tags; + } + return this; + } + return this.guard({}, hook); + } + const instance = new _Elysia({ + ...this.config, + prefix: "" + }); + instance.singleton = { ...this.singleton }; + instance.definitions = { ...this.definitions }; + instance.inference = cloneInference(this.inference); + const sandbox = run(instance); + this.singleton = mergeDeep(this.singleton, instance.singleton); + this.definitions = mergeDeep(this.definitions, instance.definitions); + sandbox.getServer = () => this.server; + if (sandbox.event.request.length) + this.event.request = [ + ...this.event.request || [], + ...sandbox.event.request || [] + ]; + if (sandbox.event.onResponse.length) + this.event.onResponse = [ + ...this.event.onResponse || [], + ...sandbox.event.onResponse || [] + ]; + this.model(sandbox.definitions.type); + Object.values(instance.router.history).forEach(({ method, path, handler, hooks: localHook }) => { + this.add(method, path, handler, mergeHook(hook, { + ...localHook || {}, + error: !localHook.error ? sandbox.event.error : Array.isArray(localHook.error) ? [ + ...localHook.error || {}, + ...sandbox.event.error || [] + ] : [ + localHook.error, + ...sandbox.event.error || [] + ] + }, { + allowMacro: true + })); + }); + return this; + } + use(plugin, options) { + if (options?.scoped) + return this.guard({}, (app) => app.use(plugin)); + if (Array.isArray(plugin)) { + let current = this; + for (const p of plugin) + current = this.use(p); + return current; + } + if (plugin instanceof Promise) { + this.promisedModules.add(plugin.then((plugin2) => { + if (typeof plugin2 === "function") + return plugin2(this); + if (plugin2 instanceof _Elysia) + return this._use(plugin2); + if (typeof plugin2.default === "function") + return plugin2.default(this); + if (plugin2.default instanceof _Elysia) + return this._use(plugin2.default); + throw new Error('Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.'); + }).then((x) => x.compile())); + return this; + } + return this._use(plugin); + } + _use(plugin) { + if (typeof plugin === "function") { + const instance = plugin(this); + if (instance instanceof Promise) { + this.promisedModules.add(instance.then((plugin2) => { + if (plugin2 instanceof _Elysia) { + this.compile(); + for (const { + method, + path, + handler, + hooks + } of Object.values(plugin2.router.history)) { + this.add(method, path, handler, mergeHook(hooks, { + error: plugin2.event.error + })); + } + return plugin2; + } + if (typeof plugin2 === "function") + return plugin2(this); + if (typeof plugin2.default === "function") + return plugin2.default(this); + return this._use(plugin2); + }).then((x) => x.compile())); + return this; + } + return instance; + } + if (plugin.promisedModules.size) { + this.promisedModules.add(plugin.modules.then(() => this._use(plugin)).then((x) => x.compile())); + return this; + } + const { name, seed } = plugin.config; + plugin.getServer = () => this.getServer(); + plugin.model(this.definitions.type); + plugin.error(this.definitions.error); + const isScoped = plugin.config.scoped; + if (isScoped) { + if (name) { + if (!(name in this.dependencies)) + this.dependencies[name] = []; + const current = seed !== undefined ? checksum(name + JSON.stringify(seed)) : 0; + if (this.dependencies[name].some(({ checksum: checksum2 }) => current === checksum2)) + return this; + this.dependencies[name].push(!this.config?.analytic ? { + name: plugin.config.name, + seed: plugin.config.seed, + checksum: current, + dependencies: plugin.dependencies + } : { + name: plugin.config.name, + seed: plugin.config.seed, + checksum: current, + dependencies: plugin.dependencies, + stack: plugin.telemetry.stack, + routes: plugin.router.history, + decorators: plugin.singleton.decorator, + store: plugin.singleton.store, + type: plugin.definitions.type, + error: plugin.definitions.error, + derive: plugin.event.transform.filter((x) => x.subType === "derive").map((x) => ({ + fn: x.fn.toString(), + stack: new Error().stack ?? "" + })), + resolve: plugin.event.transform.filter((x) => x.subType === "derive").map((x) => ({ + fn: x.fn.toString(), + stack: new Error().stack ?? "" + })) + }); + } + plugin.extender.macros = this.extender.macros.concat(plugin.extender.macros); + const macroHashes = []; + for (let i = 0;i < plugin.extender.macros.length; i++) { + const macro = this.extender.macros[i]; + if (macroHashes.includes(macro.checksum)) { + plugin.extender.macros.splice(i, 1); + i--; + } + macroHashes.push(macro.checksum); + } + plugin.onRequest((context) => { + Object.assign(context, this.singleton.decorator); + Object.assign(context.store, this.singleton.store); + }); + if (plugin.event.trace.length) + plugin.event.trace.push(...plugin.event.trace); + if (!plugin.config.prefix) + console.warn("It's recommended to use scoped instance with a prefix to prevent collision routing with other instance."); + if (plugin.event.error.length) + plugin.event.error.push(...this.event.error); + if (plugin.config.aot) + plugin.compile(); + if (isScoped === true && plugin.config.prefix) { + this.mount(plugin.config.prefix + "/", plugin.fetch); + for (const route of plugin.router.history) { + this.routeTree.set(route.method + `${plugin.config.prefix}${route.path}`, this.router.history.length); + this.router.history.push({ + ...route, + path: `${plugin.config.prefix}${route.path}`, + hooks: mergeHook(route.hooks, { + error: this.event.error + }) + }); + } + } else { + this.mount(plugin.fetch); + for (const route of plugin.router.history) { + this.routeTree.set(route.method + `${plugin.config.prefix}${route.path}`, this.router.history.length); + this.router.history.push({ + ...route, + path: `${plugin.config.prefix}${route.path}`, + hooks: mergeHook(route.hooks, { + error: this.event.error + }) + }); + } + } + return this; + } else { + this.headers(plugin.setHeaders); + plugin.reporter = this.reporter; + for (const trace of plugin.event.trace) + if (trace.scope && trace.scope !== "local") + this.trace(trace); + if (name) { + if (!(name in this.dependencies)) + this.dependencies[name] = []; + const current = seed !== undefined ? checksum(name + JSON.stringify(seed)) : 0; + if (!this.dependencies[name].some(({ checksum: checksum2 }) => current === checksum2)) + this.extender.macros = this.extender.macros.concat(plugin.extender.macros); + } else { + this.extender.macros = this.extender.macros.concat(plugin.extender.macros); + } + const macroHashes = []; + for (let i = 0;i < this.extender.macros.length; i++) { + const macro = this.extender.macros[i]; + if (macro.checksum) { + if (macroHashes.includes(macro.checksum)) { + this.extender.macros.splice(i, 1); + i--; + } + macroHashes.push(macro.checksum); + } + } + this.inference = { + event: { + body: this.inference.event.body || plugin.inference.event.body, + cookie: this.inference.event.cookie || plugin.inference.event.cookie, + headers: this.inference.event.headers || plugin.inference.event.headers, + queries: [ + ...this.inference.event.queries, + ...plugin.inference.event.queries + ], + query: this.inference.event.query || plugin.inference.event.query, + set: this.inference.event.set || plugin.inference.event.set, + unknownQueries: this.inference.event.unknownQueries || plugin.inference.event.unknownQueries + }, + trace: { + request: this.inference.trace.request || plugin.inference.trace.request, + parse: this.inference.trace.parse || plugin.inference.trace.parse, + transform: this.inference.trace.transform || plugin.inference.trace.transform, + handle: this.inference.trace.handle || plugin.inference.trace.handle, + beforeHandle: this.inference.trace.beforeHandle || plugin.inference.trace.beforeHandle, + afterHandle: this.inference.trace.afterHandle || plugin.inference.trace.afterHandle, + error: this.inference.trace.error || plugin.inference.trace.error, + context: this.inference.trace.context || plugin.inference.trace.context, + store: this.inference.trace.store || plugin.inference.trace.store, + set: this.inference.trace.set || plugin.inference.trace.set + } + }; + } + this.decorate(plugin.singleton.decorator); + this.state(plugin.singleton.store); + this.model(plugin.definitions.type); + this.error(plugin.definitions.error); + for (const { method, path, handler, hooks } of Object.values(plugin.router.history)) { + this.add(method, path, handler, mergeHook(hooks, { + error: plugin.event.error + })); + } + if (!isScoped) + if (name) { + if (!(name in this.dependencies)) + this.dependencies[name] = []; + const current = seed !== undefined ? checksum(name + JSON.stringify(seed)) : 0; + if (this.dependencies[name].some(({ checksum: checksum2 }) => current === checksum2)) + return this; + this.dependencies[name].push(!this.config?.analytic ? { + name: plugin.config.name, + seed: plugin.config.seed, + checksum: current, + dependencies: plugin.dependencies + } : { + name: plugin.config.name, + seed: plugin.config.seed, + checksum: current, + dependencies: plugin.dependencies, + stack: plugin.telemetry.stack, + routes: plugin.router.history, + decorators: plugin.singleton, + store: plugin.singleton.store, + type: plugin.definitions.type, + error: plugin.definitions.error, + derive: plugin.event.transform.filter((x) => x?.subType === "derive").map((x) => ({ + fn: x.toString(), + stack: new Error().stack ?? "" + })), + resolve: plugin.event.transform.filter((x) => x?.subType === "resolve").map((x) => ({ + fn: x.toString(), + stack: new Error().stack ?? "" + })) + }); + this.event = mergeLifeCycle(this.event, filterGlobalHook(plugin.event), current); + } else { + this.event = mergeLifeCycle(this.event, filterGlobalHook(plugin.event)); + } + return this; + } + macro(macro) { + const hook = { + checksum: checksum(JSON.stringify({ + name: this.config.name, + seed: this.config.seed, + content: macro.toString() + })), + fn: macro + }; + this.extender.macros.push(hook); + return this; + } + mount(path, handle) { + if (path instanceof _Elysia || typeof path === "function" || path.length === 0 || path === "/") { + const run = typeof path === "function" ? path : path instanceof _Elysia ? path.compile().fetch : handle instanceof _Elysia ? handle.compile().fetch : handle; + const handler2 = async ({ request, path: path2 }) => run(new Request(replaceUrlPath(request.url, path2 || "/"), request)); + this.all("/*", handler2, { + type: "none" + }); + return this; + } + const length = path.length; + if (handle instanceof _Elysia) + handle = handle.compile().fetch; + const handler = async ({ request, path: path2 }) => handle(new Request(replaceUrlPath(request.url, path2.slice(length) || "/"), request)); + this.all(path, handler, { + type: "none" + }); + this.all(path + (path.endsWith("/") ? "*" : "/*"), handler, { + type: "none" + }); + return this; + } + get(path, handler, hook) { + this.add("GET", path, handler, hook); + return this; + } + post(path, handler, hook) { + this.add("POST", path, handler, hook); + return this; + } + put(path, handler, hook) { + this.add("PUT", path, handler, hook); + return this; + } + patch(path, handler, hook) { + this.add("PATCH", path, handler, hook); + return this; + } + delete(path, handler, hook) { + this.add("DELETE", path, handler, hook); + return this; + } + options(path, handler, hook) { + this.add("OPTIONS", path, handler, hook); + return this; + } + all(path, handler, hook) { + this.add("ALL", path, handler, hook); + return this; + } + head(path, handler, hook) { + this.add("HEAD", path, handler, hook); + return this; + } + connect(path, handler, hook) { + this.add("CONNECT", path, handler, hook); + return this; + } + route(method, path, handler, hook) { + this.add(method.toUpperCase(), path, handler, hook, hook?.config); + return this; + } + ws(path, options) { + const transform7 = options.transformMessage ? Array.isArray(options.transformMessage) ? options.transformMessage : [options.transformMessage] : undefined; + let server = null; + const validateMessage = getSchemaValidator(options?.body, { + models: this.definitions.type, + normalize: this.config.normalize + }); + const validateResponse = getSchemaValidator(options?.response, { + models: this.definitions.type, + normalize: this.config.normalize + }); + const parseMessage = (message) => { + if (typeof message === "string") { + const start = message?.charCodeAt(0); + if (start === 47 || start === 123) + try { + message = JSON.parse(message); + } catch { + } + else if (isNumericString(message)) + message = +message; + } + if (transform7?.length) + for (let i = 0;i < transform7.length; i++) { + const temp = transform7[i](message); + if (temp !== undefined) + message = temp; + } + return message; + }; + this.route("$INTERNALWS", path, (context) => { + const { set: set2, path: path2, qi, headers, query, params } = context; + if (server === null) + server = this.getServer(); + if (server?.upgrade(context.request, { + headers: typeof options.upgrade === "function" ? options.upgrade(context) : options.upgrade, + data: { + validator: validateResponse, + open(ws) { + options.open?.(new ElysiaWS(ws, context)); + }, + message: (ws, msg) => { + const message = parseMessage(msg); + if (validateMessage?.Check(message) === false) + return void ws.send(new ValidationError("message", validateMessage, message).message); + options.message?.(new ElysiaWS(ws, context), message); + }, + drain(ws) { + options.drain?.(new ElysiaWS(ws, context)); + }, + close(ws, code, reason) { + options.close?.(new ElysiaWS(ws, context), code, reason); + } + } + })) + return; + set2.status = 400; + return "Expected a websocket connection"; + }, { + beforeHandle: options.beforeHandle, + transform: options.transform, + headers: options.headers, + params: options.params, + query: options.query + }); + return this; + } + state(name, value15) { + switch (typeof name) { + case "object": + this.singleton.store = mergeDeep(this.singleton.store, name); + return this; + case "function": + this.singleton.store = name(this.singleton.store); + return this; + } + if (!(name in this.singleton.store)) { + this.singleton.store[name] = value15; + } + return this; + } + decorate(name, value15) { + switch (typeof name) { + case "object": + this.singleton.decorator = mergeDeep(this.singleton.decorator, name); + return this; + case "function": + this.singleton.decorator = name(this.singleton.decorator); + return this; + } + if (!(name in this.singleton.decorator)) + this.singleton.decorator[name] = value15; + return this; + } + derive(optionsOrTransform, transform7) { + if (!transform7) { + transform7 = optionsOrTransform; + optionsOrTransform = { as: "local" }; + } + const hook = { + subType: "derive", + fn: transform7 + }; + return this.onTransform(optionsOrTransform, hook); + } + model(name, model) { + switch (typeof name) { + case "object": + Object.entries(name).forEach(([key, value15]) => { + if (!(key in this.definitions.type)) + this.definitions.type[key] = value15; + }); + return this; + case "function": + this.definitions.type = name(this.definitions.type); + return this; + } + this.definitions.type[name] = model; + return this; + } + mapDerive(optionsOrDerive, mapper) { + if (!mapper) { + mapper = optionsOrDerive; + optionsOrDerive = { as: "local" }; + } + const hook = { + subType: "derive", + fn: mapper + }; + return this.onTransform(optionsOrDerive, hook); + } + affix(base, type74, word) { + if (word === "") + return this; + const delimieter = ["_", "-", " "]; + const capitalize2 = (word2) => word2[0].toUpperCase() + word2.slice(1); + const joinKey = base === "prefix" ? (prefix, word2) => delimieter.includes(prefix.at(-1) ?? "") ? prefix + word2 : prefix + capitalize2(word2) : delimieter.includes(word.at(-1) ?? "") ? (suffix, word2) => word2 + suffix : (suffix, word2) => word2 + capitalize2(suffix); + const remap = (type210) => { + const store = {}; + switch (type210) { + case "decorator": + for (const key in this.singleton.decorator) { + store[joinKey(word, key)] = this.singleton.decorator[key]; + } + this.singleton.decorator = store; + break; + case "state": + for (const key in this.singleton.store) + store[joinKey(word, key)] = this.singleton.store[key]; + this.singleton.store = store; + break; + case "model": + for (const key in this.definitions.type) + store[joinKey(word, key)] = this.definitions.type[key]; + this.definitions.type = store; + break; + case "error": + for (const key in this.definitions.error) + store[joinKey(word, key)] = this.definitions.error[key]; + this.definitions.error = store; + break; + } + }; + const types = Array.isArray(type74) ? type74 : [type74]; + for (const type210 of types.some((x) => x === "all") ? ["decorator", "state", "model", "error"] : types) + remap(type210); + return this; + } + prefix(type74, word) { + return this.affix("prefix", type74, word); + } + suffix(type74, word) { + return this.affix("suffix", type74, word); + } + compile() { + this.fetch = this.config.aot ? composeGeneralHandler(this) : createDynamicHandler(this); + if (typeof this.server?.reload === "function") + this.server.reload({ + ...this.server || {}, + fetch: this.fetch + }); + return this; + } + get modules() { + return Promise.all(this.promisedModules.promises); + } +}; + +// node_modules/@elysiajs/static/dist/index.js +var import_node_cache = __toESM(require_node_cache2(), 1); +import {readdir, stat as stat2} from "fs/promises"; +import {resolve, resolve as resolveFn, join, sep} from "path"; + +// node_modules/@elysiajs/static/dist/cache.js +import {stat} from "fs/promises"; +async function isCached(headers, etag, filePath) { + if (headers["cache-control"] && headers["cache-control"].indexOf("no-cache") !== -1) + return false; + if ("if-none-match" in headers) { + const ifNoneMatch = headers["if-none-match"]; + if (ifNoneMatch === "*") + return true; + if (ifNoneMatch === null) + return false; + if (typeof etag !== "string") + return false; + const isMatching = ifNoneMatch === etag; + if (isMatching) + return true; + return false; + } + if (headers["if-modified-since"]) { + const ifModifiedSince = headers["if-modified-since"]; + let lastModified; + try { + lastModified = (await stat(filePath)).mtime; + } catch { + } + if (lastModified !== undefined && lastModified.getTime() <= Date.parse(ifModifiedSince)) + return true; + } + return false; +} +async function generateETag(file) { + const hash7 = new Bun.CryptoHasher("md5"); + hash7.update(await file.arrayBuffer()); + return hash7.digest("base64"); +} + +// node_modules/@elysiajs/static/dist/index.js +var URL_PATH_SEP = "/"; +var fileExists = (path) => stat2(path).then(() => true, () => false); +var statCache = new import_node_cache.default({ + useClones: false, + checkperiod: 5 * 60, + stdTTL: 3 * 60 * 60, + maxKeys: 250 +}); +var fileCache = new import_node_cache.default({ + useClones: false, + checkperiod: 5 * 60, + stdTTL: 3 * 60 * 60, + maxKeys: 250 +}); +var htmlCache = new import_node_cache.default({ + useClones: false, + checkperiod: 5 * 60, + stdTTL: 3 * 60 * 60, + maxKeys: 250 +}); +var listFiles = async (dir) => { + const files = await readdir(dir); + const all = await Promise.all(files.map(async (name) => { + const file = dir + sep + name; + const stats = await stat2(file); + return stats && stats.isDirectory() ? await listFiles(file) : [resolve(dir, file)]; + })); + return all.flat(); +}; +var staticPlugin = async ({ assets = "public", prefix = "/public", staticLimit = 1024, alwaysStatic = false, ignorePatterns = [".DS_Store", ".git", ".env"], noExtension = false, enableDecodeURI = false, resolve: resolve2 = resolveFn, headers = {}, noCache = false, maxAge = 86400, directive = "public", indexHTML = true } = { + assets: "public", + prefix: "/public", + staticLimit: 1024, + alwaysStatic: false, + ignorePatterns: [], + noExtension: false, + enableDecodeURI: false, + resolve: resolveFn, + headers: {}, + noCache: false, + indexHTML: true +}) => { + const files = await listFiles(resolveFn(assets)); + const isFSSepUnsafe = sep !== URL_PATH_SEP; + if (prefix === URL_PATH_SEP) + prefix = ""; + const shouldIgnore = (file) => { + if (!ignorePatterns.length) + return false; + return ignorePatterns.find((pattern3) => { + if (typeof pattern3 === "string") + return pattern3.includes(file); + else + return pattern3.test(file); + }); + }; + const app = new Elysia({ + name: "static", + seed: { + assets, + prefix, + staticLimit, + alwaysStatic, + ignorePatterns, + noExtension, + enableDecodeURI, + resolve: resolve2.toString(), + headers, + noCache, + maxAge, + directive, + indexHTML + } + }); + if (alwaysStatic || process.env.ENV === "production" && files.length <= staticLimit) + for (let i = 0;i < files.length; i++) { + const filePath = files[i]; + if (!filePath || shouldIgnore(filePath)) + continue; + let fileName = filePath.replace(resolve2(), "").replace(`${assets}${sep}`, ""); + if (noExtension) { + const temp = fileName.split("."); + temp.splice(-1); + fileName = temp.join("."); + } + const file = Bun.file(filePath); + const etag = await generateETag(file); + const pathName = isFSSepUnsafe ? prefix + fileName.split(sep).join(URL_PATH_SEP) : join(prefix, fileName); + app.get(pathName, noCache ? new Response(file, { + headers + }) : async ({ headers: reqHeaders }) => { + if (await isCached(reqHeaders, etag, filePath)) { + return new Response(null, { + status: 304, + headers + }); + } + headers["Etag"] = etag; + headers["Cache-Control"] = directive; + if (maxAge !== null) + headers["Cache-Control"] += `, max-age=${maxAge}`; + return new Response(file, { + headers + }); + }); + if (indexHTML && pathName.endsWith("/index.html")) + app.get(join(prefix, pathName.replace("/index.html", "")), noCache ? new Response(file, { + headers + }) : async ({ headers: reqHeaders }) => { + if (await isCached(reqHeaders, etag, pathName)) { + return new Response(null, { + status: 304, + headers + }); + } + headers["Etag"] = etag; + headers["Cache-Control"] = directive; + if (maxAge !== null) + headers["Cache-Control"] += `, max-age=${maxAge}`; + return new Response(file, { + headers + }); + }); + } + else { + if (!app.router.history.find(({ method, path }) => path === `${prefix}/*` && method === "GET")) + app.onError(() => { + }).get(`${prefix}/*`, async ({ params, headers: reqHeaders }) => { + let path = enableDecodeURI ? decodeURI(`${assets}/${decodeURI(params["*"])}`) : `${assets}/${params["*"]}`; + if (isFSSepUnsafe) { + path = path.replace(URL_PATH_SEP, sep); + } + if (shouldIgnore(path)) + throw new NotFoundError; + try { + let status = statCache.get(path); + if (!status) { + status = await stat2(path); + statCache.set(path, status); + } + let file = fileCache.get(path); + if (!file) { + if (status.isDirectory()) { + let hasCache = false; + if (indexHTML && (hasCache = htmlCache.get(`${path}${sep}index.html`) ?? await fileExists(`${path}${sep}index.html`))) { + if (hasCache === undefined) + htmlCache.set(`${path}${sep}index.html`, true); + file = Bun.file(`${path}${sep}index.html`); + } else { + if (indexHTML && hasCache === undefined) + htmlCache.set(`${path}${sep}index.html`, false); + throw new NotFoundError; + } + } + file ??= Bun.file(path); + fileCache.set(path, file); + } + if (noCache) + return new Response(file, { + headers + }); + const etag = await generateETag(file); + if (await isCached(reqHeaders, etag, path)) + return new Response(null, { + status: 304, + headers + }); + headers["Etag"] = etag; + headers["Cache-Control"] = directive; + if (maxAge !== null) + headers["Cache-Control"] += `, max-age=${maxAge}`; + return new Response(file, { + headers + }); + } catch (error23) { + throw new NotFoundError; + } + }); + } + return app; +}; + +// node_modules/zod/lib/index.mjs +var setErrorMap = function(map3) { + overrideErrorMap = map3; +}; +var getErrorMap = function() { + return overrideErrorMap; +}; +var addIssueToContext = function(ctx, issueData) { + const overrideMap = getErrorMap(); + const issue = makeIssue({ + issueData, + data: ctx.data, + path: ctx.path, + errorMaps: [ + ctx.common.contextualErrorMap, + ctx.schemaErrorMap, + overrideMap, + overrideMap === errorMap ? undefined : errorMap + ].filter((x) => !!x) + }); + ctx.common.issues.push(issue); +}; +var __classPrivateFieldGet = function(receiver, state, kind, f) { + if (kind === "a" && !f) + throw new TypeError("Private accessor was defined without a getter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) + throw new TypeError("Cannot read private member from an object whose class did not declare it"); + return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); +}; +var __classPrivateFieldSet = function(receiver, state, value15, kind, f) { + if (kind === "m") + throw new TypeError("Private method is not writable"); + if (kind === "a" && !f) + throw new TypeError("Private accessor was defined without a setter"); + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) + throw new TypeError("Cannot write private member to an object whose class did not declare it"); + return kind === "a" ? f.call(receiver, value15) : f ? f.value = value15 : state.set(receiver, value15), value15; +}; +var processCreateParams = function(params) { + if (!params) + return {}; + const { errorMap, invalid_type_error, required_error, description } = params; + if (errorMap && (invalid_type_error || required_error)) { + throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`); + } + if (errorMap) + return { errorMap, description }; + const customMap = (iss, ctx) => { + var _a, _b; + const { message } = params; + if (iss.code === "invalid_enum_value") { + return { message: message !== null && message !== undefined ? message : ctx.defaultError }; + } + if (typeof ctx.data === "undefined") { + return { message: (_a = message !== null && message !== undefined ? message : required_error) !== null && _a !== undefined ? _a : ctx.defaultError }; + } + if (iss.code !== "invalid_type") + return { message: ctx.defaultError }; + return { message: (_b = message !== null && message !== undefined ? message : invalid_type_error) !== null && _b !== undefined ? _b : ctx.defaultError }; + }; + return { errorMap: customMap, description }; +}; +var timeRegexSource = function(args) { + let regex2 = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`; + if (args.precision) { + regex2 = `${regex2}\\.\\d{${args.precision}}`; + } else if (args.precision == null) { + regex2 = `${regex2}(\\.\\d+)?`; + } + return regex2; +}; +var timeRegex = function(args) { + return new RegExp(`^${timeRegexSource(args)}\$`); +}; +var datetimeRegex = function(args) { + let regex2 = `${dateRegexSource}T${timeRegexSource(args)}`; + const opts = []; + opts.push(args.local ? `Z?` : `Z`); + if (args.offset) + opts.push(`([+-]\\d{2}:?\\d{2})`); + regex2 = `${regex2}(${opts.join("|")})`; + return new RegExp(`^${regex2}\$`); +}; +var isValidIP = function(ip, version) { + if ((version === "v4" || !version) && ipv4Regex.test(ip)) { + return true; + } + if ((version === "v6" || !version) && ipv6Regex.test(ip)) { + return true; + } + return false; +}; +var floatSafeRemainder = function(val, step) { + const valDecCount = (val.toString().split(".")[1] || "").length; + const stepDecCount = (step.toString().split(".")[1] || "").length; + const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount; + const valInt = parseInt(val.toFixed(decCount).replace(".", "")); + const stepInt = parseInt(step.toFixed(decCount).replace(".", "")); + return valInt % stepInt / Math.pow(10, decCount); +}; +var deepPartialify = function(schema3) { + if (schema3 instanceof ZodObject) { + const newShape = {}; + for (const key in schema3.shape) { + const fieldSchema = schema3.shape[key]; + newShape[key] = ZodOptional.create(deepPartialify(fieldSchema)); + } + return new ZodObject({ + ...schema3._def, + shape: () => newShape + }); + } else if (schema3 instanceof ZodArray) { + return new ZodArray({ + ...schema3._def, + type: deepPartialify(schema3.element) + }); + } else if (schema3 instanceof ZodOptional) { + return ZodOptional.create(deepPartialify(schema3.unwrap())); + } else if (schema3 instanceof ZodNullable) { + return ZodNullable.create(deepPartialify(schema3.unwrap())); + } else if (schema3 instanceof ZodTuple) { + return ZodTuple.create(schema3.items.map((item) => deepPartialify(item))); + } else { + return schema3; + } +}; +var mergeValues = function(a2, b) { + const aType = getParsedType(a2); + const bType = getParsedType(b); + if (a2 === b) { + return { valid: true, data: a2 }; + } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) { + const bKeys = util.objectKeys(b); + const sharedKeys = util.objectKeys(a2).filter((key) => bKeys.indexOf(key) !== -1); + const newObj = { ...a2, ...b }; + for (const key of sharedKeys) { + const sharedValue = mergeValues(a2[key], b[key]); + if (!sharedValue.valid) { + return { valid: false }; + } + newObj[key] = sharedValue.data; + } + return { valid: true, data: newObj }; + } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) { + if (a2.length !== b.length) { + return { valid: false }; + } + const newArray = []; + for (let index = 0;index < a2.length; index++) { + const itemA = a2[index]; + const itemB = b[index]; + const sharedValue = mergeValues(itemA, itemB); + if (!sharedValue.valid) { + return { valid: false }; + } + newArray.push(sharedValue.data); + } + return { valid: true, data: newArray }; + } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a2 === +b) { + return { valid: true, data: a2 }; + } else { + return { valid: false }; + } +}; +var createZodEnum = function(values, params) { + return new ZodEnum({ + values, + typeName: ZodFirstPartyTypeKind.ZodEnum, + ...processCreateParams(params) + }); +}; +var custom = function(check11, params = {}, fatal) { + if (check11) + return ZodAny.create().superRefine((data, ctx) => { + var _a, _b; + if (!check11(data)) { + const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params; + const _fatal = (_b = (_a = p.fatal) !== null && _a !== undefined ? _a : fatal) !== null && _b !== undefined ? _b : true; + const p2 = typeof p === "string" ? { message: p } : p; + ctx.addIssue({ code: "custom", ...p2, fatal: _fatal }); + } + }); + return ZodAny.create(); +}; +var util; +(function(util2) { + util2.assertEqual = (val) => val; + function assertIs(_arg) { + } + util2.assertIs = assertIs; + function assertNever(_x) { + throw new Error; + } + util2.assertNever = assertNever; + util2.arrayToEnum = (items) => { + const obj = {}; + for (const item of items) { + obj[item] = item; + } + return obj; + }; + util2.getValidEnumValues = (obj) => { + const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number"); + const filtered = {}; + for (const k of validKeys) { + filtered[k] = obj[k]; + } + return util2.objectValues(filtered); + }; + util2.objectValues = (obj) => { + return util2.objectKeys(obj).map(function(e2) { + return obj[e2]; + }); + }; + util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object13) => { + const keys = []; + for (const key in object13) { + if (Object.prototype.hasOwnProperty.call(object13, key)) { + keys.push(key); + } + } + return keys; + }; + util2.find = (arr, checker) => { + for (const item of arr) { + if (checker(item)) + return item; + } + return; + }; + util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val; + function joinValues(array5, separator = " | ") { + return array5.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator); + } + util2.joinValues = joinValues; + util2.jsonStringifyReplacer = (_, value15) => { + if (typeof value15 === "bigint") { + return value15.toString(); + } + return value15; + }; +})(util || (util = {})); +var objectUtil; +(function(objectUtil2) { + objectUtil2.mergeShapes = (first, second) => { + return { + ...first, + ...second + }; + }; +})(objectUtil || (objectUtil = {})); +var ZodParsedType = util.arrayToEnum([ + "string", + "nan", + "number", + "integer", + "float", + "boolean", + "date", + "bigint", + "symbol", + "function", + "undefined", + "null", + "array", + "object", + "unknown", + "promise", + "void", + "never", + "map", + "set" +]); +var getParsedType = (data) => { + const t3 = typeof data; + switch (t3) { + case "undefined": + return ZodParsedType.undefined; + case "string": + return ZodParsedType.string; + case "number": + return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number; + case "boolean": + return ZodParsedType.boolean; + case "function": + return ZodParsedType.function; + case "bigint": + return ZodParsedType.bigint; + case "symbol": + return ZodParsedType.symbol; + case "object": + if (Array.isArray(data)) { + return ZodParsedType.array; + } + if (data === null) { + return ZodParsedType.null; + } + if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") { + return ZodParsedType.promise; + } + if (typeof Map !== "undefined" && data instanceof Map) { + return ZodParsedType.map; + } + if (typeof Set !== "undefined" && data instanceof Set) { + return ZodParsedType.set; + } + if (typeof Date !== "undefined" && data instanceof Date) { + return ZodParsedType.date; + } + return ZodParsedType.object; + default: + return ZodParsedType.unknown; + } +}; +var ZodIssueCode = util.arrayToEnum([ + "invalid_type", + "invalid_literal", + "custom", + "invalid_union", + "invalid_union_discriminator", + "invalid_enum_value", + "unrecognized_keys", + "invalid_arguments", + "invalid_return_type", + "invalid_date", + "invalid_string", + "too_small", + "too_big", + "invalid_intersection_types", + "not_multiple_of", + "not_finite" +]); +var quotelessJson = (obj) => { + const json2 = JSON.stringify(obj, null, 2); + return json2.replace(/"([^"]+)":/g, "$1:"); +}; + +class ZodError extends Error { + constructor(issues) { + super(); + this.issues = []; + this.addIssue = (sub) => { + this.issues = [...this.issues, sub]; + }; + this.addIssues = (subs = []) => { + this.issues = [...this.issues, ...subs]; + }; + const actualProto = new.target.prototype; + if (Object.setPrototypeOf) { + Object.setPrototypeOf(this, actualProto); + } else { + this.__proto__ = actualProto; + } + this.name = "ZodError"; + this.issues = issues; + } + get errors() { + return this.issues; + } + format(_mapper) { + const mapper = _mapper || function(issue) { + return issue.message; + }; + const fieldErrors = { _errors: [] }; + const processError = (error23) => { + for (const issue of error23.issues) { + if (issue.code === "invalid_union") { + issue.unionErrors.map(processError); + } else if (issue.code === "invalid_return_type") { + processError(issue.returnTypeError); + } else if (issue.code === "invalid_arguments") { + processError(issue.argumentsError); + } else if (issue.path.length === 0) { + fieldErrors._errors.push(mapper(issue)); + } else { + let curr = fieldErrors; + let i = 0; + while (i < issue.path.length) { + const el = issue.path[i]; + const terminal = i === issue.path.length - 1; + if (!terminal) { + curr[el] = curr[el] || { _errors: [] }; + } else { + curr[el] = curr[el] || { _errors: [] }; + curr[el]._errors.push(mapper(issue)); + } + curr = curr[el]; + i++; + } + } + } + }; + processError(this); + return fieldErrors; + } + static assert(value15) { + if (!(value15 instanceof ZodError)) { + throw new Error(`Not a ZodError: ${value15}`); + } + } + toString() { + return this.message; + } + get message() { + return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2); + } + get isEmpty() { + return this.issues.length === 0; + } + flatten(mapper = (issue) => issue.message) { + const fieldErrors = {}; + const formErrors = []; + for (const sub of this.issues) { + if (sub.path.length > 0) { + fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || []; + fieldErrors[sub.path[0]].push(mapper(sub)); + } else { + formErrors.push(mapper(sub)); + } + } + return { formErrors, fieldErrors }; + } + get formErrors() { + return this.flatten(); + } +} +ZodError.create = (issues) => { + const error23 = new ZodError(issues); + return error23; +}; +var errorMap = (issue, _ctx) => { + let message; + switch (issue.code) { + case ZodIssueCode.invalid_type: + if (issue.received === ZodParsedType.undefined) { + message = "Required"; + } else { + message = `Expected ${issue.expected}, received ${issue.received}`; + } + break; + case ZodIssueCode.invalid_literal: + message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`; + break; + case ZodIssueCode.unrecognized_keys: + message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`; + break; + case ZodIssueCode.invalid_union: + message = `Invalid input`; + break; + case ZodIssueCode.invalid_union_discriminator: + message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`; + break; + case ZodIssueCode.invalid_enum_value: + message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`; + break; + case ZodIssueCode.invalid_arguments: + message = `Invalid function arguments`; + break; + case ZodIssueCode.invalid_return_type: + message = `Invalid function return type`; + break; + case ZodIssueCode.invalid_date: + message = `Invalid date`; + break; + case ZodIssueCode.invalid_string: + if (typeof issue.validation === "object") { + if ("includes" in issue.validation) { + message = `Invalid input: must include "${issue.validation.includes}"`; + if (typeof issue.validation.position === "number") { + message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`; + } + } else if ("startsWith" in issue.validation) { + message = `Invalid input: must start with "${issue.validation.startsWith}"`; + } else if ("endsWith" in issue.validation) { + message = `Invalid input: must end with "${issue.validation.endsWith}"`; + } else { + util.assertNever(issue.validation); + } + } else if (issue.validation !== "regex") { + message = `Invalid ${issue.validation}`; + } else { + message = "Invalid"; + } + break; + case ZodIssueCode.too_small: + if (issue.type === "array") + message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`; + else if (issue.type === "string") + message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`; + else if (issue.type === "number") + message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`; + else if (issue.type === "date") + message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`; + else + message = "Invalid input"; + break; + case ZodIssueCode.too_big: + if (issue.type === "array") + message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`; + else if (issue.type === "string") + message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`; + else if (issue.type === "number") + message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`; + else if (issue.type === "bigint") + message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`; + else if (issue.type === "date") + message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`; + else + message = "Invalid input"; + break; + case ZodIssueCode.custom: + message = `Invalid input`; + break; + case ZodIssueCode.invalid_intersection_types: + message = `Intersection results could not be merged`; + break; + case ZodIssueCode.not_multiple_of: + message = `Number must be a multiple of ${issue.multipleOf}`; + break; + case ZodIssueCode.not_finite: + message = "Number must be finite"; + break; + default: + message = _ctx.defaultError; + util.assertNever(issue); + } + return { message }; +}; +var overrideErrorMap = errorMap; +var makeIssue = (params) => { + const { data, path, errorMaps, issueData } = params; + const fullPath = [...path, ...issueData.path || []]; + const fullIssue = { + ...issueData, + path: fullPath + }; + if (issueData.message !== undefined) { + return { + ...issueData, + path: fullPath, + message: issueData.message + }; + } + let errorMessage = ""; + const maps = errorMaps.filter((m) => !!m).slice().reverse(); + for (const map3 of maps) { + errorMessage = map3(fullIssue, { data, defaultError: errorMessage }).message; + } + return { + ...issueData, + path: fullPath, + message: errorMessage + }; +}; +var EMPTY_PATH = []; + +class ParseStatus { + constructor() { + this.value = "valid"; + } + dirty() { + if (this.value === "valid") + this.value = "dirty"; + } + abort() { + if (this.value !== "aborted") + this.value = "aborted"; + } + static mergeArray(status, results) { + const arrayValue = []; + for (const s of results) { + if (s.status === "aborted") + return INVALID; + if (s.status === "dirty") + status.dirty(); + arrayValue.push(s.value); + } + return { status: status.value, value: arrayValue }; + } + static async mergeObjectAsync(status, pairs) { + const syncPairs = []; + for (const pair of pairs) { + const key = await pair.key; + const value15 = await pair.value; + syncPairs.push({ + key, + value: value15 + }); + } + return ParseStatus.mergeObjectSync(status, syncPairs); + } + static mergeObjectSync(status, pairs) { + const finalObject = {}; + for (const pair of pairs) { + const { key, value: value15 } = pair; + if (key.status === "aborted") + return INVALID; + if (value15.status === "aborted") + return INVALID; + if (key.status === "dirty") + status.dirty(); + if (value15.status === "dirty") + status.dirty(); + if (key.value !== "__proto__" && (typeof value15.value !== "undefined" || pair.alwaysSet)) { + finalObject[key.value] = value15.value; + } + } + return { status: status.value, value: finalObject }; + } +} +var INVALID = Object.freeze({ + status: "aborted" +}); +var DIRTY = (value15) => ({ status: "dirty", value: value15 }); +var OK = (value15) => ({ status: "valid", value: value15 }); +var isAborted = (x) => x.status === "aborted"; +var isDirty = (x) => x.status === "dirty"; +var isValid = (x) => x.status === "valid"; +var isAsync2 = (x) => typeof Promise !== "undefined" && x instanceof Promise; +var errorUtil; +(function(errorUtil2) { + errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {}; + errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === undefined ? undefined : message.message; +})(errorUtil || (errorUtil = {})); +var _ZodEnum_cache; +var _ZodNativeEnum_cache; + +class ParseInputLazyPath { + constructor(parent, value15, path, key) { + this._cachedPath = []; + this.parent = parent; + this.data = value15; + this._path = path; + this._key = key; + } + get path() { + if (!this._cachedPath.length) { + if (this._key instanceof Array) { + this._cachedPath.push(...this._path, ...this._key); + } else { + this._cachedPath.push(...this._path, this._key); + } + } + return this._cachedPath; + } +} +var handleResult = (ctx, result) => { + if (isValid(result)) { + return { success: true, data: result.value }; + } else { + if (!ctx.common.issues.length) { + throw new Error("Validation failed but no issues detected."); + } + return { + success: false, + get error() { + if (this._error) + return this._error; + const error23 = new ZodError(ctx.common.issues); + this._error = error23; + return this._error; + } + }; + } +}; + +class ZodType { + constructor(def) { + this.spa = this.safeParseAsync; + this._def = def; + this.parse = this.parse.bind(this); + this.safeParse = this.safeParse.bind(this); + this.parseAsync = this.parseAsync.bind(this); + this.safeParseAsync = this.safeParseAsync.bind(this); + this.spa = this.spa.bind(this); + this.refine = this.refine.bind(this); + this.refinement = this.refinement.bind(this); + this.superRefine = this.superRefine.bind(this); + this.optional = this.optional.bind(this); + this.nullable = this.nullable.bind(this); + this.nullish = this.nullish.bind(this); + this.array = this.array.bind(this); + this.promise = this.promise.bind(this); + this.or = this.or.bind(this); + this.and = this.and.bind(this); + this.transform = this.transform.bind(this); + this.brand = this.brand.bind(this); + this.default = this.default.bind(this); + this.catch = this.catch.bind(this); + this.describe = this.describe.bind(this); + this.pipe = this.pipe.bind(this); + this.readonly = this.readonly.bind(this); + this.isNullable = this.isNullable.bind(this); + this.isOptional = this.isOptional.bind(this); + } + get description() { + return this._def.description; + } + _getType(input) { + return getParsedType(input.data); + } + _getOrReturnCtx(input, ctx) { + return ctx || { + common: input.parent.common, + data: input.data, + parsedType: getParsedType(input.data), + schemaErrorMap: this._def.errorMap, + path: input.path, + parent: input.parent + }; + } + _processInputParams(input) { + return { + status: new ParseStatus, + ctx: { + common: input.parent.common, + data: input.data, + parsedType: getParsedType(input.data), + schemaErrorMap: this._def.errorMap, + path: input.path, + parent: input.parent + } + }; + } + _parseSync(input) { + const result = this._parse(input); + if (isAsync2(result)) { + throw new Error("Synchronous parse encountered promise."); + } + return result; + } + _parseAsync(input) { + const result = this._parse(input); + return Promise.resolve(result); + } + parse(data, params) { + const result = this.safeParse(data, params); + if (result.success) + return result.data; + throw result.error; + } + safeParse(data, params) { + var _a; + const ctx = { + common: { + issues: [], + async: (_a = params === null || params === undefined ? undefined : params.async) !== null && _a !== undefined ? _a : false, + contextualErrorMap: params === null || params === undefined ? undefined : params.errorMap + }, + path: (params === null || params === undefined ? undefined : params.path) || [], + schemaErrorMap: this._def.errorMap, + parent: null, + data, + parsedType: getParsedType(data) + }; + const result = this._parseSync({ data, path: ctx.path, parent: ctx }); + return handleResult(ctx, result); + } + async parseAsync(data, params) { + const result = await this.safeParseAsync(data, params); + if (result.success) + return result.data; + throw result.error; + } + async safeParseAsync(data, params) { + const ctx = { + common: { + issues: [], + contextualErrorMap: params === null || params === undefined ? undefined : params.errorMap, + async: true + }, + path: (params === null || params === undefined ? undefined : params.path) || [], + schemaErrorMap: this._def.errorMap, + parent: null, + data, + parsedType: getParsedType(data) + }; + const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx }); + const result = await (isAsync2(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult)); + return handleResult(ctx, result); + } + refine(check11, message) { + const getIssueProperties = (val) => { + if (typeof message === "string" || typeof message === "undefined") { + return { message }; + } else if (typeof message === "function") { + return message(val); + } else { + return message; + } + }; + return this._refinement((val, ctx) => { + const result = check11(val); + const setError = () => ctx.addIssue({ + code: ZodIssueCode.custom, + ...getIssueProperties(val) + }); + if (typeof Promise !== "undefined" && result instanceof Promise) { + return result.then((data) => { + if (!data) { + setError(); + return false; + } else { + return true; + } + }); + } + if (!result) { + setError(); + return false; + } else { + return true; + } + }); + } + refinement(check11, refinementData) { + return this._refinement((val, ctx) => { + if (!check11(val)) { + ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData); + return false; + } else { + return true; + } + }); + } + _refinement(refinement) { + return new ZodEffects({ + schema: this, + typeName: ZodFirstPartyTypeKind.ZodEffects, + effect: { type: "refinement", refinement } + }); + } + superRefine(refinement) { + return this._refinement(refinement); + } + optional() { + return ZodOptional.create(this, this._def); + } + nullable() { + return ZodNullable.create(this, this._def); + } + nullish() { + return this.nullable().optional(); + } + array() { + return ZodArray.create(this, this._def); + } + promise() { + return ZodPromise.create(this, this._def); + } + or(option) { + return ZodUnion.create([this, option], this._def); + } + and(incoming) { + return ZodIntersection.create(this, incoming, this._def); + } + transform(transform7) { + return new ZodEffects({ + ...processCreateParams(this._def), + schema: this, + typeName: ZodFirstPartyTypeKind.ZodEffects, + effect: { type: "transform", transform: transform7 } + }); + } + default(def) { + const defaultValueFunc = typeof def === "function" ? def : () => def; + return new ZodDefault({ + ...processCreateParams(this._def), + innerType: this, + defaultValue: defaultValueFunc, + typeName: ZodFirstPartyTypeKind.ZodDefault + }); + } + brand() { + return new ZodBranded({ + typeName: ZodFirstPartyTypeKind.ZodBranded, + type: this, + ...processCreateParams(this._def) + }); + } + catch(def) { + const catchValueFunc = typeof def === "function" ? def : () => def; + return new ZodCatch({ + ...processCreateParams(this._def), + innerType: this, + catchValue: catchValueFunc, + typeName: ZodFirstPartyTypeKind.ZodCatch + }); + } + describe(description) { + const This = this.constructor; + return new This({ + ...this._def, + description + }); + } + pipe(target) { + return ZodPipeline.create(this, target); + } + readonly() { + return ZodReadonly.create(this); + } + isOptional() { + return this.safeParse(undefined).success; + } + isNullable() { + return this.safeParse(null).success; + } +} +var cuidRegex = /^c[^\s-]{8,}$/i; +var cuid2Regex = /^[0-9a-z]+$/; +var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/; +var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i; +var nanoidRegex = /^[a-z0-9_-]{21}$/i; +var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/; +var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i; +var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+\$`; +var emojiRegex; +var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/; +var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/; +var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/; +var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`; +var dateRegex = new RegExp(`^${dateRegexSource}\$`); + +class ZodString extends ZodType { + _parse(input) { + if (this._def.coerce) { + input.data = String(input.data); + } + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.string) { + const ctx2 = this._getOrReturnCtx(input); + addIssueToContext(ctx2, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.string, + received: ctx2.parsedType + }); + return INVALID; + } + const status = new ParseStatus; + let ctx = undefined; + for (const check11 of this._def.checks) { + if (check11.kind === "min") { + if (input.data.length < check11.value) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + minimum: check11.value, + type: "string", + inclusive: true, + exact: false, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "max") { + if (input.data.length > check11.value) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + maximum: check11.value, + type: "string", + inclusive: true, + exact: false, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "length") { + const tooBig = input.data.length > check11.value; + const tooSmall = input.data.length < check11.value; + if (tooBig || tooSmall) { + ctx = this._getOrReturnCtx(input, ctx); + if (tooBig) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + maximum: check11.value, + type: "string", + inclusive: true, + exact: true, + message: check11.message + }); + } else if (tooSmall) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + minimum: check11.value, + type: "string", + inclusive: true, + exact: true, + message: check11.message + }); + } + status.dirty(); + } + } else if (check11.kind === "email") { + if (!emailRegex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "email", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "emoji") { + if (!emojiRegex) { + emojiRegex = new RegExp(_emojiRegex, "u"); + } + if (!emojiRegex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "emoji", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "uuid") { + if (!uuidRegex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "uuid", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "nanoid") { + if (!nanoidRegex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "nanoid", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "cuid") { + if (!cuidRegex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "cuid", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "cuid2") { + if (!cuid2Regex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "cuid2", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "ulid") { + if (!ulidRegex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "ulid", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "url") { + try { + new URL(input.data); + } catch (_a) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "url", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "regex") { + check11.regex.lastIndex = 0; + const testResult = check11.regex.test(input.data); + if (!testResult) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "regex", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "trim") { + input.data = input.data.trim(); + } else if (check11.kind === "includes") { + if (!input.data.includes(check11.value, check11.position)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_string, + validation: { includes: check11.value, position: check11.position }, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "toLowerCase") { + input.data = input.data.toLowerCase(); + } else if (check11.kind === "toUpperCase") { + input.data = input.data.toUpperCase(); + } else if (check11.kind === "startsWith") { + if (!input.data.startsWith(check11.value)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_string, + validation: { startsWith: check11.value }, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "endsWith") { + if (!input.data.endsWith(check11.value)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_string, + validation: { endsWith: check11.value }, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "datetime") { + const regex2 = datetimeRegex(check11); + if (!regex2.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_string, + validation: "datetime", + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "date") { + const regex2 = dateRegex; + if (!regex2.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_string, + validation: "date", + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "time") { + const regex2 = timeRegex(check11); + if (!regex2.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_string, + validation: "time", + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "duration") { + if (!durationRegex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "duration", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "ip") { + if (!isValidIP(input.data, check11.version)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "ip", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "base64") { + if (!base64Regex.test(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + validation: "base64", + code: ZodIssueCode.invalid_string, + message: check11.message + }); + status.dirty(); + } + } else { + util.assertNever(check11); + } + } + return { status: status.value, value: input.data }; + } + _regex(regex2, validation, message) { + return this.refinement((data) => regex2.test(data), { + validation, + code: ZodIssueCode.invalid_string, + ...errorUtil.errToObj(message) + }); + } + _addCheck(check11) { + return new ZodString({ + ...this._def, + checks: [...this._def.checks, check11] + }); + } + email(message) { + return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) }); + } + url(message) { + return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) }); + } + emoji(message) { + return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) }); + } + uuid(message) { + return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) }); + } + nanoid(message) { + return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) }); + } + cuid(message) { + return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) }); + } + cuid2(message) { + return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) }); + } + ulid(message) { + return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) }); + } + base64(message) { + return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) }); + } + ip(options) { + return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) }); + } + datetime(options) { + var _a, _b; + if (typeof options === "string") { + return this._addCheck({ + kind: "datetime", + precision: null, + offset: false, + local: false, + message: options + }); + } + return this._addCheck({ + kind: "datetime", + precision: typeof (options === null || options === undefined ? undefined : options.precision) === "undefined" ? null : options === null || options === undefined ? undefined : options.precision, + offset: (_a = options === null || options === undefined ? undefined : options.offset) !== null && _a !== undefined ? _a : false, + local: (_b = options === null || options === undefined ? undefined : options.local) !== null && _b !== undefined ? _b : false, + ...errorUtil.errToObj(options === null || options === undefined ? undefined : options.message) + }); + } + date(message) { + return this._addCheck({ kind: "date", message }); + } + time(options) { + if (typeof options === "string") { + return this._addCheck({ + kind: "time", + precision: null, + message: options + }); + } + return this._addCheck({ + kind: "time", + precision: typeof (options === null || options === undefined ? undefined : options.precision) === "undefined" ? null : options === null || options === undefined ? undefined : options.precision, + ...errorUtil.errToObj(options === null || options === undefined ? undefined : options.message) + }); + } + duration(message) { + return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) }); + } + regex(regex2, message) { + return this._addCheck({ + kind: "regex", + regex: regex2, + ...errorUtil.errToObj(message) + }); + } + includes(value15, options) { + return this._addCheck({ + kind: "includes", + value: value15, + position: options === null || options === undefined ? undefined : options.position, + ...errorUtil.errToObj(options === null || options === undefined ? undefined : options.message) + }); + } + startsWith(value15, message) { + return this._addCheck({ + kind: "startsWith", + value: value15, + ...errorUtil.errToObj(message) + }); + } + endsWith(value15, message) { + return this._addCheck({ + kind: "endsWith", + value: value15, + ...errorUtil.errToObj(message) + }); + } + min(minLength, message) { + return this._addCheck({ + kind: "min", + value: minLength, + ...errorUtil.errToObj(message) + }); + } + max(maxLength, message) { + return this._addCheck({ + kind: "max", + value: maxLength, + ...errorUtil.errToObj(message) + }); + } + length(len, message) { + return this._addCheck({ + kind: "length", + value: len, + ...errorUtil.errToObj(message) + }); + } + nonempty(message) { + return this.min(1, errorUtil.errToObj(message)); + } + trim() { + return new ZodString({ + ...this._def, + checks: [...this._def.checks, { kind: "trim" }] + }); + } + toLowerCase() { + return new ZodString({ + ...this._def, + checks: [...this._def.checks, { kind: "toLowerCase" }] + }); + } + toUpperCase() { + return new ZodString({ + ...this._def, + checks: [...this._def.checks, { kind: "toUpperCase" }] + }); + } + get isDatetime() { + return !!this._def.checks.find((ch) => ch.kind === "datetime"); + } + get isDate() { + return !!this._def.checks.find((ch) => ch.kind === "date"); + } + get isTime() { + return !!this._def.checks.find((ch) => ch.kind === "time"); + } + get isDuration() { + return !!this._def.checks.find((ch) => ch.kind === "duration"); + } + get isEmail() { + return !!this._def.checks.find((ch) => ch.kind === "email"); + } + get isURL() { + return !!this._def.checks.find((ch) => ch.kind === "url"); + } + get isEmoji() { + return !!this._def.checks.find((ch) => ch.kind === "emoji"); + } + get isUUID() { + return !!this._def.checks.find((ch) => ch.kind === "uuid"); + } + get isNANOID() { + return !!this._def.checks.find((ch) => ch.kind === "nanoid"); + } + get isCUID() { + return !!this._def.checks.find((ch) => ch.kind === "cuid"); + } + get isCUID2() { + return !!this._def.checks.find((ch) => ch.kind === "cuid2"); + } + get isULID() { + return !!this._def.checks.find((ch) => ch.kind === "ulid"); + } + get isIP() { + return !!this._def.checks.find((ch) => ch.kind === "ip"); + } + get isBase64() { + return !!this._def.checks.find((ch) => ch.kind === "base64"); + } + get minLength() { + let min = null; + for (const ch of this._def.checks) { + if (ch.kind === "min") { + if (min === null || ch.value > min) + min = ch.value; + } + } + return min; + } + get maxLength() { + let max = null; + for (const ch of this._def.checks) { + if (ch.kind === "max") { + if (max === null || ch.value < max) + max = ch.value; + } + } + return max; + } +} +ZodString.create = (params) => { + var _a; + return new ZodString({ + checks: [], + typeName: ZodFirstPartyTypeKind.ZodString, + coerce: (_a = params === null || params === undefined ? undefined : params.coerce) !== null && _a !== undefined ? _a : false, + ...processCreateParams(params) + }); +}; + +class ZodNumber extends ZodType { + constructor() { + super(...arguments); + this.min = this.gte; + this.max = this.lte; + this.step = this.multipleOf; + } + _parse(input) { + if (this._def.coerce) { + input.data = Number(input.data); + } + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.number) { + const ctx2 = this._getOrReturnCtx(input); + addIssueToContext(ctx2, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.number, + received: ctx2.parsedType + }); + return INVALID; + } + let ctx = undefined; + const status = new ParseStatus; + for (const check11 of this._def.checks) { + if (check11.kind === "int") { + if (!util.isInteger(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: "integer", + received: "float", + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "min") { + const tooSmall = check11.inclusive ? input.data < check11.value : input.data <= check11.value; + if (tooSmall) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + minimum: check11.value, + type: "number", + inclusive: check11.inclusive, + exact: false, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "max") { + const tooBig = check11.inclusive ? input.data > check11.value : input.data >= check11.value; + if (tooBig) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + maximum: check11.value, + type: "number", + inclusive: check11.inclusive, + exact: false, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "multipleOf") { + if (floatSafeRemainder(input.data, check11.value) !== 0) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.not_multiple_of, + multipleOf: check11.value, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "finite") { + if (!Number.isFinite(input.data)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.not_finite, + message: check11.message + }); + status.dirty(); + } + } else { + util.assertNever(check11); + } + } + return { status: status.value, value: input.data }; + } + gte(value15, message) { + return this.setLimit("min", value15, true, errorUtil.toString(message)); + } + gt(value15, message) { + return this.setLimit("min", value15, false, errorUtil.toString(message)); + } + lte(value15, message) { + return this.setLimit("max", value15, true, errorUtil.toString(message)); + } + lt(value15, message) { + return this.setLimit("max", value15, false, errorUtil.toString(message)); + } + setLimit(kind, value15, inclusive, message) { + return new ZodNumber({ + ...this._def, + checks: [ + ...this._def.checks, + { + kind, + value: value15, + inclusive, + message: errorUtil.toString(message) + } + ] + }); + } + _addCheck(check11) { + return new ZodNumber({ + ...this._def, + checks: [...this._def.checks, check11] + }); + } + int(message) { + return this._addCheck({ + kind: "int", + message: errorUtil.toString(message) + }); + } + positive(message) { + return this._addCheck({ + kind: "min", + value: 0, + inclusive: false, + message: errorUtil.toString(message) + }); + } + negative(message) { + return this._addCheck({ + kind: "max", + value: 0, + inclusive: false, + message: errorUtil.toString(message) + }); + } + nonpositive(message) { + return this._addCheck({ + kind: "max", + value: 0, + inclusive: true, + message: errorUtil.toString(message) + }); + } + nonnegative(message) { + return this._addCheck({ + kind: "min", + value: 0, + inclusive: true, + message: errorUtil.toString(message) + }); + } + multipleOf(value15, message) { + return this._addCheck({ + kind: "multipleOf", + value: value15, + message: errorUtil.toString(message) + }); + } + finite(message) { + return this._addCheck({ + kind: "finite", + message: errorUtil.toString(message) + }); + } + safe(message) { + return this._addCheck({ + kind: "min", + inclusive: true, + value: Number.MIN_SAFE_INTEGER, + message: errorUtil.toString(message) + })._addCheck({ + kind: "max", + inclusive: true, + value: Number.MAX_SAFE_INTEGER, + message: errorUtil.toString(message) + }); + } + get minValue() { + let min = null; + for (const ch of this._def.checks) { + if (ch.kind === "min") { + if (min === null || ch.value > min) + min = ch.value; + } + } + return min; + } + get maxValue() { + let max = null; + for (const ch of this._def.checks) { + if (ch.kind === "max") { + if (max === null || ch.value < max) + max = ch.value; + } + } + return max; + } + get isInt() { + return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value)); + } + get isFinite() { + let max = null, min = null; + for (const ch of this._def.checks) { + if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") { + return true; + } else if (ch.kind === "min") { + if (min === null || ch.value > min) + min = ch.value; + } else if (ch.kind === "max") { + if (max === null || ch.value < max) + max = ch.value; + } + } + return Number.isFinite(min) && Number.isFinite(max); + } +} +ZodNumber.create = (params) => { + return new ZodNumber({ + checks: [], + typeName: ZodFirstPartyTypeKind.ZodNumber, + coerce: (params === null || params === undefined ? undefined : params.coerce) || false, + ...processCreateParams(params) + }); +}; + +class ZodBigInt extends ZodType { + constructor() { + super(...arguments); + this.min = this.gte; + this.max = this.lte; + } + _parse(input) { + if (this._def.coerce) { + input.data = BigInt(input.data); + } + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.bigint) { + const ctx2 = this._getOrReturnCtx(input); + addIssueToContext(ctx2, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.bigint, + received: ctx2.parsedType + }); + return INVALID; + } + let ctx = undefined; + const status = new ParseStatus; + for (const check11 of this._def.checks) { + if (check11.kind === "min") { + const tooSmall = check11.inclusive ? input.data < check11.value : input.data <= check11.value; + if (tooSmall) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + type: "bigint", + minimum: check11.value, + inclusive: check11.inclusive, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "max") { + const tooBig = check11.inclusive ? input.data > check11.value : input.data >= check11.value; + if (tooBig) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + type: "bigint", + maximum: check11.value, + inclusive: check11.inclusive, + message: check11.message + }); + status.dirty(); + } + } else if (check11.kind === "multipleOf") { + if (input.data % check11.value !== BigInt(0)) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.not_multiple_of, + multipleOf: check11.value, + message: check11.message + }); + status.dirty(); + } + } else { + util.assertNever(check11); + } + } + return { status: status.value, value: input.data }; + } + gte(value15, message) { + return this.setLimit("min", value15, true, errorUtil.toString(message)); + } + gt(value15, message) { + return this.setLimit("min", value15, false, errorUtil.toString(message)); + } + lte(value15, message) { + return this.setLimit("max", value15, true, errorUtil.toString(message)); + } + lt(value15, message) { + return this.setLimit("max", value15, false, errorUtil.toString(message)); + } + setLimit(kind, value15, inclusive, message) { + return new ZodBigInt({ + ...this._def, + checks: [ + ...this._def.checks, + { + kind, + value: value15, + inclusive, + message: errorUtil.toString(message) + } + ] + }); + } + _addCheck(check11) { + return new ZodBigInt({ + ...this._def, + checks: [...this._def.checks, check11] + }); + } + positive(message) { + return this._addCheck({ + kind: "min", + value: BigInt(0), + inclusive: false, + message: errorUtil.toString(message) + }); + } + negative(message) { + return this._addCheck({ + kind: "max", + value: BigInt(0), + inclusive: false, + message: errorUtil.toString(message) + }); + } + nonpositive(message) { + return this._addCheck({ + kind: "max", + value: BigInt(0), + inclusive: true, + message: errorUtil.toString(message) + }); + } + nonnegative(message) { + return this._addCheck({ + kind: "min", + value: BigInt(0), + inclusive: true, + message: errorUtil.toString(message) + }); + } + multipleOf(value15, message) { + return this._addCheck({ + kind: "multipleOf", + value: value15, + message: errorUtil.toString(message) + }); + } + get minValue() { + let min = null; + for (const ch of this._def.checks) { + if (ch.kind === "min") { + if (min === null || ch.value > min) + min = ch.value; + } + } + return min; + } + get maxValue() { + let max = null; + for (const ch of this._def.checks) { + if (ch.kind === "max") { + if (max === null || ch.value < max) + max = ch.value; + } + } + return max; + } +} +ZodBigInt.create = (params) => { + var _a; + return new ZodBigInt({ + checks: [], + typeName: ZodFirstPartyTypeKind.ZodBigInt, + coerce: (_a = params === null || params === undefined ? undefined : params.coerce) !== null && _a !== undefined ? _a : false, + ...processCreateParams(params) + }); +}; + +class ZodBoolean extends ZodType { + _parse(input) { + if (this._def.coerce) { + input.data = Boolean(input.data); + } + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.boolean) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.boolean, + received: ctx.parsedType + }); + return INVALID; + } + return OK(input.data); + } +} +ZodBoolean.create = (params) => { + return new ZodBoolean({ + typeName: ZodFirstPartyTypeKind.ZodBoolean, + coerce: (params === null || params === undefined ? undefined : params.coerce) || false, + ...processCreateParams(params) + }); +}; + +class ZodDate extends ZodType { + _parse(input) { + if (this._def.coerce) { + input.data = new Date(input.data); + } + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.date) { + const ctx2 = this._getOrReturnCtx(input); + addIssueToContext(ctx2, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.date, + received: ctx2.parsedType + }); + return INVALID; + } + if (isNaN(input.data.getTime())) { + const ctx2 = this._getOrReturnCtx(input); + addIssueToContext(ctx2, { + code: ZodIssueCode.invalid_date + }); + return INVALID; + } + const status = new ParseStatus; + let ctx = undefined; + for (const check11 of this._def.checks) { + if (check11.kind === "min") { + if (input.data.getTime() < check11.value) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + message: check11.message, + inclusive: true, + exact: false, + minimum: check11.value, + type: "date" + }); + status.dirty(); + } + } else if (check11.kind === "max") { + if (input.data.getTime() > check11.value) { + ctx = this._getOrReturnCtx(input, ctx); + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + message: check11.message, + inclusive: true, + exact: false, + maximum: check11.value, + type: "date" + }); + status.dirty(); + } + } else { + util.assertNever(check11); + } + } + return { + status: status.value, + value: new Date(input.data.getTime()) + }; + } + _addCheck(check11) { + return new ZodDate({ + ...this._def, + checks: [...this._def.checks, check11] + }); + } + min(minDate, message) { + return this._addCheck({ + kind: "min", + value: minDate.getTime(), + message: errorUtil.toString(message) + }); + } + max(maxDate, message) { + return this._addCheck({ + kind: "max", + value: maxDate.getTime(), + message: errorUtil.toString(message) + }); + } + get minDate() { + let min = null; + for (const ch of this._def.checks) { + if (ch.kind === "min") { + if (min === null || ch.value > min) + min = ch.value; + } + } + return min != null ? new Date(min) : null; + } + get maxDate() { + let max = null; + for (const ch of this._def.checks) { + if (ch.kind === "max") { + if (max === null || ch.value < max) + max = ch.value; + } + } + return max != null ? new Date(max) : null; + } +} +ZodDate.create = (params) => { + return new ZodDate({ + checks: [], + coerce: (params === null || params === undefined ? undefined : params.coerce) || false, + typeName: ZodFirstPartyTypeKind.ZodDate, + ...processCreateParams(params) + }); +}; + +class ZodSymbol extends ZodType { + _parse(input) { + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.symbol) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.symbol, + received: ctx.parsedType + }); + return INVALID; + } + return OK(input.data); + } +} +ZodSymbol.create = (params) => { + return new ZodSymbol({ + typeName: ZodFirstPartyTypeKind.ZodSymbol, + ...processCreateParams(params) + }); +}; + +class ZodUndefined extends ZodType { + _parse(input) { + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.undefined) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.undefined, + received: ctx.parsedType + }); + return INVALID; + } + return OK(input.data); + } +} +ZodUndefined.create = (params) => { + return new ZodUndefined({ + typeName: ZodFirstPartyTypeKind.ZodUndefined, + ...processCreateParams(params) + }); +}; + +class ZodNull extends ZodType { + _parse(input) { + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.null) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.null, + received: ctx.parsedType + }); + return INVALID; + } + return OK(input.data); + } +} +ZodNull.create = (params) => { + return new ZodNull({ + typeName: ZodFirstPartyTypeKind.ZodNull, + ...processCreateParams(params) + }); +}; + +class ZodAny extends ZodType { + constructor() { + super(...arguments); + this._any = true; + } + _parse(input) { + return OK(input.data); + } +} +ZodAny.create = (params) => { + return new ZodAny({ + typeName: ZodFirstPartyTypeKind.ZodAny, + ...processCreateParams(params) + }); +}; + +class ZodUnknown extends ZodType { + constructor() { + super(...arguments); + this._unknown = true; + } + _parse(input) { + return OK(input.data); + } +} +ZodUnknown.create = (params) => { + return new ZodUnknown({ + typeName: ZodFirstPartyTypeKind.ZodUnknown, + ...processCreateParams(params) + }); +}; + +class ZodNever extends ZodType { + _parse(input) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.never, + received: ctx.parsedType + }); + return INVALID; + } +} +ZodNever.create = (params) => { + return new ZodNever({ + typeName: ZodFirstPartyTypeKind.ZodNever, + ...processCreateParams(params) + }); +}; + +class ZodVoid extends ZodType { + _parse(input) { + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.undefined) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.void, + received: ctx.parsedType + }); + return INVALID; + } + return OK(input.data); + } +} +ZodVoid.create = (params) => { + return new ZodVoid({ + typeName: ZodFirstPartyTypeKind.ZodVoid, + ...processCreateParams(params) + }); +}; + +class ZodArray extends ZodType { + _parse(input) { + const { ctx, status } = this._processInputParams(input); + const def = this._def; + if (ctx.parsedType !== ZodParsedType.array) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.array, + received: ctx.parsedType + }); + return INVALID; + } + if (def.exactLength !== null) { + const tooBig = ctx.data.length > def.exactLength.value; + const tooSmall = ctx.data.length < def.exactLength.value; + if (tooBig || tooSmall) { + addIssueToContext(ctx, { + code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small, + minimum: tooSmall ? def.exactLength.value : undefined, + maximum: tooBig ? def.exactLength.value : undefined, + type: "array", + inclusive: true, + exact: true, + message: def.exactLength.message + }); + status.dirty(); + } + } + if (def.minLength !== null) { + if (ctx.data.length < def.minLength.value) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + minimum: def.minLength.value, + type: "array", + inclusive: true, + exact: false, + message: def.minLength.message + }); + status.dirty(); + } + } + if (def.maxLength !== null) { + if (ctx.data.length > def.maxLength.value) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + maximum: def.maxLength.value, + type: "array", + inclusive: true, + exact: false, + message: def.maxLength.message + }); + status.dirty(); + } + } + if (ctx.common.async) { + return Promise.all([...ctx.data].map((item, i) => { + return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i)); + })).then((result2) => { + return ParseStatus.mergeArray(status, result2); + }); + } + const result = [...ctx.data].map((item, i) => { + return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i)); + }); + return ParseStatus.mergeArray(status, result); + } + get element() { + return this._def.type; + } + min(minLength, message) { + return new ZodArray({ + ...this._def, + minLength: { value: minLength, message: errorUtil.toString(message) } + }); + } + max(maxLength, message) { + return new ZodArray({ + ...this._def, + maxLength: { value: maxLength, message: errorUtil.toString(message) } + }); + } + length(len, message) { + return new ZodArray({ + ...this._def, + exactLength: { value: len, message: errorUtil.toString(message) } + }); + } + nonempty(message) { + return this.min(1, message); + } +} +ZodArray.create = (schema3, params) => { + return new ZodArray({ + type: schema3, + minLength: null, + maxLength: null, + exactLength: null, + typeName: ZodFirstPartyTypeKind.ZodArray, + ...processCreateParams(params) + }); +}; + +class ZodObject extends ZodType { + constructor() { + super(...arguments); + this._cached = null; + this.nonstrict = this.passthrough; + this.augment = this.extend; + } + _getCached() { + if (this._cached !== null) + return this._cached; + const shape = this._def.shape(); + const keys = util.objectKeys(shape); + return this._cached = { shape, keys }; + } + _parse(input) { + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.object) { + const ctx2 = this._getOrReturnCtx(input); + addIssueToContext(ctx2, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.object, + received: ctx2.parsedType + }); + return INVALID; + } + const { status, ctx } = this._processInputParams(input); + const { shape, keys: shapeKeys } = this._getCached(); + const extraKeys = []; + if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) { + for (const key in ctx.data) { + if (!shapeKeys.includes(key)) { + extraKeys.push(key); + } + } + } + const pairs = []; + for (const key of shapeKeys) { + const keyValidator = shape[key]; + const value15 = ctx.data[key]; + pairs.push({ + key: { status: "valid", value: key }, + value: keyValidator._parse(new ParseInputLazyPath(ctx, value15, ctx.path, key)), + alwaysSet: key in ctx.data + }); + } + if (this._def.catchall instanceof ZodNever) { + const unknownKeys = this._def.unknownKeys; + if (unknownKeys === "passthrough") { + for (const key of extraKeys) { + pairs.push({ + key: { status: "valid", value: key }, + value: { status: "valid", value: ctx.data[key] } + }); + } + } else if (unknownKeys === "strict") { + if (extraKeys.length > 0) { + addIssueToContext(ctx, { + code: ZodIssueCode.unrecognized_keys, + keys: extraKeys + }); + status.dirty(); + } + } else if (unknownKeys === "strip") + ; + else { + throw new Error(`Internal ZodObject error: invalid unknownKeys value.`); + } + } else { + const catchall = this._def.catchall; + for (const key of extraKeys) { + const value15 = ctx.data[key]; + pairs.push({ + key: { status: "valid", value: key }, + value: catchall._parse(new ParseInputLazyPath(ctx, value15, ctx.path, key)), + alwaysSet: key in ctx.data + }); + } + } + if (ctx.common.async) { + return Promise.resolve().then(async () => { + const syncPairs = []; + for (const pair of pairs) { + const key = await pair.key; + const value15 = await pair.value; + syncPairs.push({ + key, + value: value15, + alwaysSet: pair.alwaysSet + }); + } + return syncPairs; + }).then((syncPairs) => { + return ParseStatus.mergeObjectSync(status, syncPairs); + }); + } else { + return ParseStatus.mergeObjectSync(status, pairs); + } + } + get shape() { + return this._def.shape(); + } + strict(message) { + errorUtil.errToObj; + return new ZodObject({ + ...this._def, + unknownKeys: "strict", + ...message !== undefined ? { + errorMap: (issue, ctx) => { + var _a, _b, _c, _d; + const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === undefined ? undefined : _b.call(_a, issue, ctx).message) !== null && _c !== undefined ? _c : ctx.defaultError; + if (issue.code === "unrecognized_keys") + return { + message: (_d = errorUtil.errToObj(message).message) !== null && _d !== undefined ? _d : defaultError + }; + return { + message: defaultError + }; + } + } : {} + }); + } + strip() { + return new ZodObject({ + ...this._def, + unknownKeys: "strip" + }); + } + passthrough() { + return new ZodObject({ + ...this._def, + unknownKeys: "passthrough" + }); + } + extend(augmentation) { + return new ZodObject({ + ...this._def, + shape: () => ({ + ...this._def.shape(), + ...augmentation + }) + }); + } + merge(merging) { + const merged = new ZodObject({ + unknownKeys: merging._def.unknownKeys, + catchall: merging._def.catchall, + shape: () => ({ + ...this._def.shape(), + ...merging._def.shape() + }), + typeName: ZodFirstPartyTypeKind.ZodObject + }); + return merged; + } + setKey(key, schema3) { + return this.augment({ [key]: schema3 }); + } + catchall(index) { + return new ZodObject({ + ...this._def, + catchall: index + }); + } + pick(mask) { + const shape = {}; + util.objectKeys(mask).forEach((key) => { + if (mask[key] && this.shape[key]) { + shape[key] = this.shape[key]; + } + }); + return new ZodObject({ + ...this._def, + shape: () => shape + }); + } + omit(mask) { + const shape = {}; + util.objectKeys(this.shape).forEach((key) => { + if (!mask[key]) { + shape[key] = this.shape[key]; + } + }); + return new ZodObject({ + ...this._def, + shape: () => shape + }); + } + deepPartial() { + return deepPartialify(this); + } + partial(mask) { + const newShape = {}; + util.objectKeys(this.shape).forEach((key) => { + const fieldSchema = this.shape[key]; + if (mask && !mask[key]) { + newShape[key] = fieldSchema; + } else { + newShape[key] = fieldSchema.optional(); + } + }); + return new ZodObject({ + ...this._def, + shape: () => newShape + }); + } + required(mask) { + const newShape = {}; + util.objectKeys(this.shape).forEach((key) => { + if (mask && !mask[key]) { + newShape[key] = this.shape[key]; + } else { + const fieldSchema = this.shape[key]; + let newField = fieldSchema; + while (newField instanceof ZodOptional) { + newField = newField._def.innerType; + } + newShape[key] = newField; + } + }); + return new ZodObject({ + ...this._def, + shape: () => newShape + }); + } + keyof() { + return createZodEnum(util.objectKeys(this.shape)); + } +} +ZodObject.create = (shape, params) => { + return new ZodObject({ + shape: () => shape, + unknownKeys: "strip", + catchall: ZodNever.create(), + typeName: ZodFirstPartyTypeKind.ZodObject, + ...processCreateParams(params) + }); +}; +ZodObject.strictCreate = (shape, params) => { + return new ZodObject({ + shape: () => shape, + unknownKeys: "strict", + catchall: ZodNever.create(), + typeName: ZodFirstPartyTypeKind.ZodObject, + ...processCreateParams(params) + }); +}; +ZodObject.lazycreate = (shape, params) => { + return new ZodObject({ + shape, + unknownKeys: "strip", + catchall: ZodNever.create(), + typeName: ZodFirstPartyTypeKind.ZodObject, + ...processCreateParams(params) + }); +}; + +class ZodUnion extends ZodType { + _parse(input) { + const { ctx } = this._processInputParams(input); + const options = this._def.options; + function handleResults(results) { + for (const result of results) { + if (result.result.status === "valid") { + return result.result; + } + } + for (const result of results) { + if (result.result.status === "dirty") { + ctx.common.issues.push(...result.ctx.common.issues); + return result.result; + } + } + const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues)); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_union, + unionErrors + }); + return INVALID; + } + if (ctx.common.async) { + return Promise.all(options.map(async (option) => { + const childCtx = { + ...ctx, + common: { + ...ctx.common, + issues: [] + }, + parent: null + }; + return { + result: await option._parseAsync({ + data: ctx.data, + path: ctx.path, + parent: childCtx + }), + ctx: childCtx + }; + })).then(handleResults); + } else { + let dirty = undefined; + const issues = []; + for (const option of options) { + const childCtx = { + ...ctx, + common: { + ...ctx.common, + issues: [] + }, + parent: null + }; + const result = option._parseSync({ + data: ctx.data, + path: ctx.path, + parent: childCtx + }); + if (result.status === "valid") { + return result; + } else if (result.status === "dirty" && !dirty) { + dirty = { result, ctx: childCtx }; + } + if (childCtx.common.issues.length) { + issues.push(childCtx.common.issues); + } + } + if (dirty) { + ctx.common.issues.push(...dirty.ctx.common.issues); + return dirty.result; + } + const unionErrors = issues.map((issues2) => new ZodError(issues2)); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_union, + unionErrors + }); + return INVALID; + } + } + get options() { + return this._def.options; + } +} +ZodUnion.create = (types, params) => { + return new ZodUnion({ + options: types, + typeName: ZodFirstPartyTypeKind.ZodUnion, + ...processCreateParams(params) + }); +}; +var getDiscriminator = (type74) => { + if (type74 instanceof ZodLazy) { + return getDiscriminator(type74.schema); + } else if (type74 instanceof ZodEffects) { + return getDiscriminator(type74.innerType()); + } else if (type74 instanceof ZodLiteral) { + return [type74.value]; + } else if (type74 instanceof ZodEnum) { + return type74.options; + } else if (type74 instanceof ZodNativeEnum) { + return util.objectValues(type74.enum); + } else if (type74 instanceof ZodDefault) { + return getDiscriminator(type74._def.innerType); + } else if (type74 instanceof ZodUndefined) { + return [undefined]; + } else if (type74 instanceof ZodNull) { + return [null]; + } else if (type74 instanceof ZodOptional) { + return [undefined, ...getDiscriminator(type74.unwrap())]; + } else if (type74 instanceof ZodNullable) { + return [null, ...getDiscriminator(type74.unwrap())]; + } else if (type74 instanceof ZodBranded) { + return getDiscriminator(type74.unwrap()); + } else if (type74 instanceof ZodReadonly) { + return getDiscriminator(type74.unwrap()); + } else if (type74 instanceof ZodCatch) { + return getDiscriminator(type74._def.innerType); + } else { + return []; + } +}; + +class ZodDiscriminatedUnion extends ZodType { + _parse(input) { + const { ctx } = this._processInputParams(input); + if (ctx.parsedType !== ZodParsedType.object) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.object, + received: ctx.parsedType + }); + return INVALID; + } + const discriminator = this.discriminator; + const discriminatorValue = ctx.data[discriminator]; + const option = this.optionsMap.get(discriminatorValue); + if (!option) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_union_discriminator, + options: Array.from(this.optionsMap.keys()), + path: [discriminator] + }); + return INVALID; + } + if (ctx.common.async) { + return option._parseAsync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }); + } else { + return option._parseSync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }); + } + } + get discriminator() { + return this._def.discriminator; + } + get options() { + return this._def.options; + } + get optionsMap() { + return this._def.optionsMap; + } + static create(discriminator, options, params) { + const optionsMap = new Map; + for (const type74 of options) { + const discriminatorValues = getDiscriminator(type74.shape[discriminator]); + if (!discriminatorValues.length) { + throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`); + } + for (const value15 of discriminatorValues) { + if (optionsMap.has(value15)) { + throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value15)}`); + } + optionsMap.set(value15, type74); + } + } + return new ZodDiscriminatedUnion({ + typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion, + discriminator, + options, + optionsMap, + ...processCreateParams(params) + }); + } +} + +class ZodIntersection extends ZodType { + _parse(input) { + const { status, ctx } = this._processInputParams(input); + const handleParsed = (parsedLeft, parsedRight) => { + if (isAborted(parsedLeft) || isAborted(parsedRight)) { + return INVALID; + } + const merged = mergeValues(parsedLeft.value, parsedRight.value); + if (!merged.valid) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_intersection_types + }); + return INVALID; + } + if (isDirty(parsedLeft) || isDirty(parsedRight)) { + status.dirty(); + } + return { status: status.value, value: merged.data }; + }; + if (ctx.common.async) { + return Promise.all([ + this._def.left._parseAsync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }), + this._def.right._parseAsync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }) + ]).then(([left, right]) => handleParsed(left, right)); + } else { + return handleParsed(this._def.left._parseSync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }), this._def.right._parseSync({ + data: ctx.data, + path: ctx.path, + parent: ctx + })); + } + } +} +ZodIntersection.create = (left, right, params) => { + return new ZodIntersection({ + left, + right, + typeName: ZodFirstPartyTypeKind.ZodIntersection, + ...processCreateParams(params) + }); +}; + +class ZodTuple extends ZodType { + _parse(input) { + const { status, ctx } = this._processInputParams(input); + if (ctx.parsedType !== ZodParsedType.array) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.array, + received: ctx.parsedType + }); + return INVALID; + } + if (ctx.data.length < this._def.items.length) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + minimum: this._def.items.length, + inclusive: true, + exact: false, + type: "array" + }); + return INVALID; + } + const rest4 = this._def.rest; + if (!rest4 && ctx.data.length > this._def.items.length) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + maximum: this._def.items.length, + inclusive: true, + exact: false, + type: "array" + }); + status.dirty(); + } + const items = [...ctx.data].map((item, itemIndex) => { + const schema3 = this._def.items[itemIndex] || this._def.rest; + if (!schema3) + return null; + return schema3._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex)); + }).filter((x) => !!x); + if (ctx.common.async) { + return Promise.all(items).then((results) => { + return ParseStatus.mergeArray(status, results); + }); + } else { + return ParseStatus.mergeArray(status, items); + } + } + get items() { + return this._def.items; + } + rest(rest4) { + return new ZodTuple({ + ...this._def, + rest: rest4 + }); + } +} +ZodTuple.create = (schemas, params) => { + if (!Array.isArray(schemas)) { + throw new Error("You must pass an array of schemas to z.tuple([ ... ])"); + } + return new ZodTuple({ + items: schemas, + typeName: ZodFirstPartyTypeKind.ZodTuple, + rest: null, + ...processCreateParams(params) + }); +}; + +class ZodRecord extends ZodType { + get keySchema() { + return this._def.keyType; + } + get valueSchema() { + return this._def.valueType; + } + _parse(input) { + const { status, ctx } = this._processInputParams(input); + if (ctx.parsedType !== ZodParsedType.object) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.object, + received: ctx.parsedType + }); + return INVALID; + } + const pairs = []; + const keyType = this._def.keyType; + const valueType = this._def.valueType; + for (const key in ctx.data) { + pairs.push({ + key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)), + value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)), + alwaysSet: key in ctx.data + }); + } + if (ctx.common.async) { + return ParseStatus.mergeObjectAsync(status, pairs); + } else { + return ParseStatus.mergeObjectSync(status, pairs); + } + } + get element() { + return this._def.valueType; + } + static create(first, second, third) { + if (second instanceof ZodType) { + return new ZodRecord({ + keyType: first, + valueType: second, + typeName: ZodFirstPartyTypeKind.ZodRecord, + ...processCreateParams(third) + }); + } + return new ZodRecord({ + keyType: ZodString.create(), + valueType: first, + typeName: ZodFirstPartyTypeKind.ZodRecord, + ...processCreateParams(second) + }); + } +} + +class ZodMap extends ZodType { + get keySchema() { + return this._def.keyType; + } + get valueSchema() { + return this._def.valueType; + } + _parse(input) { + const { status, ctx } = this._processInputParams(input); + if (ctx.parsedType !== ZodParsedType.map) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.map, + received: ctx.parsedType + }); + return INVALID; + } + const keyType = this._def.keyType; + const valueType = this._def.valueType; + const pairs = [...ctx.data.entries()].map(([key, value15], index) => { + return { + key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])), + value: valueType._parse(new ParseInputLazyPath(ctx, value15, ctx.path, [index, "value"])) + }; + }); + if (ctx.common.async) { + const finalMap = new Map; + return Promise.resolve().then(async () => { + for (const pair of pairs) { + const key = await pair.key; + const value15 = await pair.value; + if (key.status === "aborted" || value15.status === "aborted") { + return INVALID; + } + if (key.status === "dirty" || value15.status === "dirty") { + status.dirty(); + } + finalMap.set(key.value, value15.value); + } + return { status: status.value, value: finalMap }; + }); + } else { + const finalMap = new Map; + for (const pair of pairs) { + const key = pair.key; + const value15 = pair.value; + if (key.status === "aborted" || value15.status === "aborted") { + return INVALID; + } + if (key.status === "dirty" || value15.status === "dirty") { + status.dirty(); + } + finalMap.set(key.value, value15.value); + } + return { status: status.value, value: finalMap }; + } + } +} +ZodMap.create = (keyType, valueType, params) => { + return new ZodMap({ + valueType, + keyType, + typeName: ZodFirstPartyTypeKind.ZodMap, + ...processCreateParams(params) + }); +}; + +class ZodSet extends ZodType { + _parse(input) { + const { status, ctx } = this._processInputParams(input); + if (ctx.parsedType !== ZodParsedType.set) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.set, + received: ctx.parsedType + }); + return INVALID; + } + const def = this._def; + if (def.minSize !== null) { + if (ctx.data.size < def.minSize.value) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_small, + minimum: def.minSize.value, + type: "set", + inclusive: true, + exact: false, + message: def.minSize.message + }); + status.dirty(); + } + } + if (def.maxSize !== null) { + if (ctx.data.size > def.maxSize.value) { + addIssueToContext(ctx, { + code: ZodIssueCode.too_big, + maximum: def.maxSize.value, + type: "set", + inclusive: true, + exact: false, + message: def.maxSize.message + }); + status.dirty(); + } + } + const valueType = this._def.valueType; + function finalizeSet(elements2) { + const parsedSet = new Set; + for (const element of elements2) { + if (element.status === "aborted") + return INVALID; + if (element.status === "dirty") + status.dirty(); + parsedSet.add(element.value); + } + return { status: status.value, value: parsedSet }; + } + const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i))); + if (ctx.common.async) { + return Promise.all(elements).then((elements2) => finalizeSet(elements2)); + } else { + return finalizeSet(elements); + } + } + min(minSize, message) { + return new ZodSet({ + ...this._def, + minSize: { value: minSize, message: errorUtil.toString(message) } + }); + } + max(maxSize, message) { + return new ZodSet({ + ...this._def, + maxSize: { value: maxSize, message: errorUtil.toString(message) } + }); + } + size(size, message) { + return this.min(size, message).max(size, message); + } + nonempty(message) { + return this.min(1, message); + } +} +ZodSet.create = (valueType, params) => { + return new ZodSet({ + valueType, + minSize: null, + maxSize: null, + typeName: ZodFirstPartyTypeKind.ZodSet, + ...processCreateParams(params) + }); +}; + +class ZodFunction extends ZodType { + constructor() { + super(...arguments); + this.validate = this.implement; + } + _parse(input) { + const { ctx } = this._processInputParams(input); + if (ctx.parsedType !== ZodParsedType.function) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.function, + received: ctx.parsedType + }); + return INVALID; + } + function makeArgsIssue(args, error23) { + return makeIssue({ + data: args, + path: ctx.path, + errorMaps: [ + ctx.common.contextualErrorMap, + ctx.schemaErrorMap, + getErrorMap(), + errorMap + ].filter((x) => !!x), + issueData: { + code: ZodIssueCode.invalid_arguments, + argumentsError: error23 + } + }); + } + function makeReturnsIssue(returns, error23) { + return makeIssue({ + data: returns, + path: ctx.path, + errorMaps: [ + ctx.common.contextualErrorMap, + ctx.schemaErrorMap, + getErrorMap(), + errorMap + ].filter((x) => !!x), + issueData: { + code: ZodIssueCode.invalid_return_type, + returnTypeError: error23 + } + }); + } + const params = { errorMap: ctx.common.contextualErrorMap }; + const fn = ctx.data; + if (this._def.returns instanceof ZodPromise) { + const me = this; + return OK(async function(...args) { + const error23 = new ZodError([]); + const parsedArgs = await me._def.args.parseAsync(args, params).catch((e2) => { + error23.addIssue(makeArgsIssue(args, e2)); + throw error23; + }); + const result = await Reflect.apply(fn, this, parsedArgs); + const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e2) => { + error23.addIssue(makeReturnsIssue(result, e2)); + throw error23; + }); + return parsedReturns; + }); + } else { + const me = this; + return OK(function(...args) { + const parsedArgs = me._def.args.safeParse(args, params); + if (!parsedArgs.success) { + throw new ZodError([makeArgsIssue(args, parsedArgs.error)]); + } + const result = Reflect.apply(fn, this, parsedArgs.data); + const parsedReturns = me._def.returns.safeParse(result, params); + if (!parsedReturns.success) { + throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]); + } + return parsedReturns.data; + }); + } + } + parameters() { + return this._def.args; + } + returnType() { + return this._def.returns; + } + args(...items) { + return new ZodFunction({ + ...this._def, + args: ZodTuple.create(items).rest(ZodUnknown.create()) + }); + } + returns(returnType) { + return new ZodFunction({ + ...this._def, + returns: returnType + }); + } + implement(func) { + const validatedFunc = this.parse(func); + return validatedFunc; + } + strictImplement(func) { + const validatedFunc = this.parse(func); + return validatedFunc; + } + static create(args, returns, params) { + return new ZodFunction({ + args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()), + returns: returns || ZodUnknown.create(), + typeName: ZodFirstPartyTypeKind.ZodFunction, + ...processCreateParams(params) + }); + } +} + +class ZodLazy extends ZodType { + get schema() { + return this._def.getter(); + } + _parse(input) { + const { ctx } = this._processInputParams(input); + const lazySchema = this._def.getter(); + return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx }); + } +} +ZodLazy.create = (getter, params) => { + return new ZodLazy({ + getter, + typeName: ZodFirstPartyTypeKind.ZodLazy, + ...processCreateParams(params) + }); +}; + +class ZodLiteral extends ZodType { + _parse(input) { + if (input.data !== this._def.value) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + received: ctx.data, + code: ZodIssueCode.invalid_literal, + expected: this._def.value + }); + return INVALID; + } + return { status: "valid", value: input.data }; + } + get value() { + return this._def.value; + } +} +ZodLiteral.create = (value15, params) => { + return new ZodLiteral({ + value: value15, + typeName: ZodFirstPartyTypeKind.ZodLiteral, + ...processCreateParams(params) + }); +}; + +class ZodEnum extends ZodType { + constructor() { + super(...arguments); + _ZodEnum_cache.set(this, undefined); + } + _parse(input) { + if (typeof input.data !== "string") { + const ctx = this._getOrReturnCtx(input); + const expectedValues = this._def.values; + addIssueToContext(ctx, { + expected: util.joinValues(expectedValues), + received: ctx.parsedType, + code: ZodIssueCode.invalid_type + }); + return INVALID; + } + if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) { + __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f"); + } + if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) { + const ctx = this._getOrReturnCtx(input); + const expectedValues = this._def.values; + addIssueToContext(ctx, { + received: ctx.data, + code: ZodIssueCode.invalid_enum_value, + options: expectedValues + }); + return INVALID; + } + return OK(input.data); + } + get options() { + return this._def.values; + } + get enum() { + const enumValues = {}; + for (const val of this._def.values) { + enumValues[val] = val; + } + return enumValues; + } + get Values() { + const enumValues = {}; + for (const val of this._def.values) { + enumValues[val] = val; + } + return enumValues; + } + get Enum() { + const enumValues = {}; + for (const val of this._def.values) { + enumValues[val] = val; + } + return enumValues; + } + extract(values, newDef = this._def) { + return ZodEnum.create(values, { + ...this._def, + ...newDef + }); + } + exclude(values, newDef = this._def) { + return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), { + ...this._def, + ...newDef + }); + } +} +_ZodEnum_cache = new WeakMap; +ZodEnum.create = createZodEnum; + +class ZodNativeEnum extends ZodType { + constructor() { + super(...arguments); + _ZodNativeEnum_cache.set(this, undefined); + } + _parse(input) { + const nativeEnumValues = util.getValidEnumValues(this._def.values); + const ctx = this._getOrReturnCtx(input); + if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) { + const expectedValues = util.objectValues(nativeEnumValues); + addIssueToContext(ctx, { + expected: util.joinValues(expectedValues), + received: ctx.parsedType, + code: ZodIssueCode.invalid_type + }); + return INVALID; + } + if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) { + __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f"); + } + if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) { + const expectedValues = util.objectValues(nativeEnumValues); + addIssueToContext(ctx, { + received: ctx.data, + code: ZodIssueCode.invalid_enum_value, + options: expectedValues + }); + return INVALID; + } + return OK(input.data); + } + get enum() { + return this._def.values; + } +} +_ZodNativeEnum_cache = new WeakMap; +ZodNativeEnum.create = (values, params) => { + return new ZodNativeEnum({ + values, + typeName: ZodFirstPartyTypeKind.ZodNativeEnum, + ...processCreateParams(params) + }); +}; + +class ZodPromise extends ZodType { + unwrap() { + return this._def.type; + } + _parse(input) { + const { ctx } = this._processInputParams(input); + if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) { + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.promise, + received: ctx.parsedType + }); + return INVALID; + } + const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data); + return OK(promisified.then((data) => { + return this._def.type.parseAsync(data, { + path: ctx.path, + errorMap: ctx.common.contextualErrorMap + }); + })); + } +} +ZodPromise.create = (schema3, params) => { + return new ZodPromise({ + type: schema3, + typeName: ZodFirstPartyTypeKind.ZodPromise, + ...processCreateParams(params) + }); +}; + +class ZodEffects extends ZodType { + innerType() { + return this._def.schema; + } + sourceType() { + return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema; + } + _parse(input) { + const { status, ctx } = this._processInputParams(input); + const effect = this._def.effect || null; + const checkCtx = { + addIssue: (arg) => { + addIssueToContext(ctx, arg); + if (arg.fatal) { + status.abort(); + } else { + status.dirty(); + } + }, + get path() { + return ctx.path; + } + }; + checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx); + if (effect.type === "preprocess") { + const processed = effect.transform(ctx.data, checkCtx); + if (ctx.common.async) { + return Promise.resolve(processed).then(async (processed2) => { + if (status.value === "aborted") + return INVALID; + const result = await this._def.schema._parseAsync({ + data: processed2, + path: ctx.path, + parent: ctx + }); + if (result.status === "aborted") + return INVALID; + if (result.status === "dirty") + return DIRTY(result.value); + if (status.value === "dirty") + return DIRTY(result.value); + return result; + }); + } else { + if (status.value === "aborted") + return INVALID; + const result = this._def.schema._parseSync({ + data: processed, + path: ctx.path, + parent: ctx + }); + if (result.status === "aborted") + return INVALID; + if (result.status === "dirty") + return DIRTY(result.value); + if (status.value === "dirty") + return DIRTY(result.value); + return result; + } + } + if (effect.type === "refinement") { + const executeRefinement = (acc) => { + const result = effect.refinement(acc, checkCtx); + if (ctx.common.async) { + return Promise.resolve(result); + } + if (result instanceof Promise) { + throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead."); + } + return acc; + }; + if (ctx.common.async === false) { + const inner = this._def.schema._parseSync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }); + if (inner.status === "aborted") + return INVALID; + if (inner.status === "dirty") + status.dirty(); + executeRefinement(inner.value); + return { status: status.value, value: inner.value }; + } else { + return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => { + if (inner.status === "aborted") + return INVALID; + if (inner.status === "dirty") + status.dirty(); + return executeRefinement(inner.value).then(() => { + return { status: status.value, value: inner.value }; + }); + }); + } + } + if (effect.type === "transform") { + if (ctx.common.async === false) { + const base = this._def.schema._parseSync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }); + if (!isValid(base)) + return base; + const result = effect.transform(base.value, checkCtx); + if (result instanceof Promise) { + throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`); + } + return { status: status.value, value: result }; + } else { + return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => { + if (!isValid(base)) + return base; + return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result })); + }); + } + } + util.assertNever(effect); + } +} +ZodEffects.create = (schema3, effect, params) => { + return new ZodEffects({ + schema: schema3, + typeName: ZodFirstPartyTypeKind.ZodEffects, + effect, + ...processCreateParams(params) + }); +}; +ZodEffects.createWithPreprocess = (preprocess, schema3, params) => { + return new ZodEffects({ + schema: schema3, + effect: { type: "preprocess", transform: preprocess }, + typeName: ZodFirstPartyTypeKind.ZodEffects, + ...processCreateParams(params) + }); +}; + +class ZodOptional extends ZodType { + _parse(input) { + const parsedType = this._getType(input); + if (parsedType === ZodParsedType.undefined) { + return OK(undefined); + } + return this._def.innerType._parse(input); + } + unwrap() { + return this._def.innerType; + } +} +ZodOptional.create = (type74, params) => { + return new ZodOptional({ + innerType: type74, + typeName: ZodFirstPartyTypeKind.ZodOptional, + ...processCreateParams(params) + }); +}; + +class ZodNullable extends ZodType { + _parse(input) { + const parsedType = this._getType(input); + if (parsedType === ZodParsedType.null) { + return OK(null); + } + return this._def.innerType._parse(input); + } + unwrap() { + return this._def.innerType; + } +} +ZodNullable.create = (type74, params) => { + return new ZodNullable({ + innerType: type74, + typeName: ZodFirstPartyTypeKind.ZodNullable, + ...processCreateParams(params) + }); +}; + +class ZodDefault extends ZodType { + _parse(input) { + const { ctx } = this._processInputParams(input); + let data = ctx.data; + if (ctx.parsedType === ZodParsedType.undefined) { + data = this._def.defaultValue(); + } + return this._def.innerType._parse({ + data, + path: ctx.path, + parent: ctx + }); + } + removeDefault() { + return this._def.innerType; + } +} +ZodDefault.create = (type74, params) => { + return new ZodDefault({ + innerType: type74, + typeName: ZodFirstPartyTypeKind.ZodDefault, + defaultValue: typeof params.default === "function" ? params.default : () => params.default, + ...processCreateParams(params) + }); +}; + +class ZodCatch extends ZodType { + _parse(input) { + const { ctx } = this._processInputParams(input); + const newCtx = { + ...ctx, + common: { + ...ctx.common, + issues: [] + } + }; + const result = this._def.innerType._parse({ + data: newCtx.data, + path: newCtx.path, + parent: { + ...newCtx + } + }); + if (isAsync2(result)) { + return result.then((result2) => { + return { + status: "valid", + value: result2.status === "valid" ? result2.value : this._def.catchValue({ + get error() { + return new ZodError(newCtx.common.issues); + }, + input: newCtx.data + }) + }; + }); + } else { + return { + status: "valid", + value: result.status === "valid" ? result.value : this._def.catchValue({ + get error() { + return new ZodError(newCtx.common.issues); + }, + input: newCtx.data + }) + }; + } + } + removeCatch() { + return this._def.innerType; + } +} +ZodCatch.create = (type74, params) => { + return new ZodCatch({ + innerType: type74, + typeName: ZodFirstPartyTypeKind.ZodCatch, + catchValue: typeof params.catch === "function" ? params.catch : () => params.catch, + ...processCreateParams(params) + }); +}; + +class ZodNaN extends ZodType { + _parse(input) { + const parsedType = this._getType(input); + if (parsedType !== ZodParsedType.nan) { + const ctx = this._getOrReturnCtx(input); + addIssueToContext(ctx, { + code: ZodIssueCode.invalid_type, + expected: ZodParsedType.nan, + received: ctx.parsedType + }); + return INVALID; + } + return { status: "valid", value: input.data }; + } +} +ZodNaN.create = (params) => { + return new ZodNaN({ + typeName: ZodFirstPartyTypeKind.ZodNaN, + ...processCreateParams(params) + }); +}; +var BRAND = Symbol("zod_brand"); + +class ZodBranded extends ZodType { + _parse(input) { + const { ctx } = this._processInputParams(input); + const data = ctx.data; + return this._def.type._parse({ + data, + path: ctx.path, + parent: ctx + }); + } + unwrap() { + return this._def.type; + } +} + +class ZodPipeline extends ZodType { + _parse(input) { + const { status, ctx } = this._processInputParams(input); + if (ctx.common.async) { + const handleAsync = async () => { + const inResult = await this._def.in._parseAsync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }); + if (inResult.status === "aborted") + return INVALID; + if (inResult.status === "dirty") { + status.dirty(); + return DIRTY(inResult.value); + } else { + return this._def.out._parseAsync({ + data: inResult.value, + path: ctx.path, + parent: ctx + }); + } + }; + return handleAsync(); + } else { + const inResult = this._def.in._parseSync({ + data: ctx.data, + path: ctx.path, + parent: ctx + }); + if (inResult.status === "aborted") + return INVALID; + if (inResult.status === "dirty") { + status.dirty(); + return { + status: "dirty", + value: inResult.value + }; + } else { + return this._def.out._parseSync({ + data: inResult.value, + path: ctx.path, + parent: ctx + }); + } + } + } + static create(a2, b) { + return new ZodPipeline({ + in: a2, + out: b, + typeName: ZodFirstPartyTypeKind.ZodPipeline + }); + } +} + +class ZodReadonly extends ZodType { + _parse(input) { + const result = this._def.innerType._parse(input); + if (isValid(result)) { + result.value = Object.freeze(result.value); + } + return result; + } + unwrap() { + return this._def.innerType; + } +} +ZodReadonly.create = (type74, params) => { + return new ZodReadonly({ + innerType: type74, + typeName: ZodFirstPartyTypeKind.ZodReadonly, + ...processCreateParams(params) + }); +}; +var late = { + object: ZodObject.lazycreate +}; +var ZodFirstPartyTypeKind; +(function(ZodFirstPartyTypeKind2) { + ZodFirstPartyTypeKind2["ZodString"] = "ZodString"; + ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber"; + ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN"; + ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt"; + ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean"; + ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate"; + ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol"; + ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined"; + ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull"; + ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny"; + ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown"; + ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever"; + ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid"; + ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray"; + ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject"; + ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion"; + ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion"; + ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection"; + ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple"; + ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord"; + ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap"; + ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet"; + ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction"; + ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy"; + ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral"; + ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum"; + ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects"; + ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum"; + ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional"; + ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable"; + ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault"; + ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch"; + ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise"; + ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded"; + ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline"; + ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly"; +})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {})); +var instanceOfType = (cls, params = { + message: `Input not instance of ${cls.name}` +}) => custom((data) => data instanceof cls, params); +var stringType = ZodString.create; +var numberType = ZodNumber.create; +var nanType = ZodNaN.create; +var bigIntType = ZodBigInt.create; +var booleanType = ZodBoolean.create; +var dateType = ZodDate.create; +var symbolType = ZodSymbol.create; +var undefinedType = ZodUndefined.create; +var nullType = ZodNull.create; +var anyType = ZodAny.create; +var unknownType = ZodUnknown.create; +var neverType = ZodNever.create; +var voidType = ZodVoid.create; +var arrayType = ZodArray.create; +var objectType = ZodObject.create; +var strictObjectType = ZodObject.strictCreate; +var unionType = ZodUnion.create; +var discriminatedUnionType = ZodDiscriminatedUnion.create; +var intersectionType = ZodIntersection.create; +var tupleType = ZodTuple.create; +var recordType = ZodRecord.create; +var mapType = ZodMap.create; +var setType = ZodSet.create; +var functionType = ZodFunction.create; +var lazyType = ZodLazy.create; +var literalType = ZodLiteral.create; +var enumType = ZodEnum.create; +var nativeEnumType = ZodNativeEnum.create; +var promiseType = ZodPromise.create; +var effectsType = ZodEffects.create; +var optionalType = ZodOptional.create; +var nullableType = ZodNullable.create; +var preprocessType = ZodEffects.createWithPreprocess; +var pipelineType = ZodPipeline.create; +var ostring = () => stringType().optional(); +var onumber = () => numberType().optional(); +var oboolean = () => booleanType().optional(); +var coerce = { + string: (arg) => ZodString.create({ ...arg, coerce: true }), + number: (arg) => ZodNumber.create({ ...arg, coerce: true }), + boolean: (arg) => ZodBoolean.create({ + ...arg, + coerce: true + }), + bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }), + date: (arg) => ZodDate.create({ ...arg, coerce: true }) +}; +var NEVER = INVALID; +var z = Object.freeze({ + __proto__: null, + defaultErrorMap: errorMap, + setErrorMap, + getErrorMap, + makeIssue, + EMPTY_PATH, + addIssueToContext, + ParseStatus, + INVALID, + DIRTY, + OK, + isAborted, + isDirty, + isValid, + isAsync: isAsync2, + get util() { + return util; + }, + get objectUtil() { + return objectUtil; + }, + ZodParsedType, + getParsedType, + ZodType, + datetimeRegex, + ZodString, + ZodNumber, + ZodBigInt, + ZodBoolean, + ZodDate, + ZodSymbol, + ZodUndefined, + ZodNull, + ZodAny, + ZodUnknown, + ZodNever, + ZodVoid, + ZodArray, + ZodObject, + ZodUnion, + ZodDiscriminatedUnion, + ZodIntersection, + ZodTuple, + ZodRecord, + ZodMap, + ZodSet, + ZodFunction, + ZodLazy, + ZodLiteral, + ZodEnum, + ZodNativeEnum, + ZodPromise, + ZodEffects, + ZodTransformer: ZodEffects, + ZodOptional, + ZodNullable, + ZodDefault, + ZodCatch, + ZodNaN, + BRAND, + ZodBranded, + ZodPipeline, + ZodReadonly, + custom, + Schema: ZodType, + ZodSchema: ZodType, + late, + get ZodFirstPartyTypeKind() { + return ZodFirstPartyTypeKind; + }, + coerce, + any: anyType, + array: arrayType, + bigint: bigIntType, + boolean: booleanType, + date: dateType, + discriminatedUnion: discriminatedUnionType, + effect: effectsType, + enum: enumType, + function: functionType, + instanceof: instanceOfType, + intersection: intersectionType, + lazy: lazyType, + literal: literalType, + map: mapType, + nan: nanType, + nativeEnum: nativeEnumType, + never: neverType, + null: nullType, + nullable: nullableType, + number: numberType, + object: objectType, + oboolean, + onumber, + optional: optionalType, + ostring, + pipeline: pipelineType, + preprocess: preprocessType, + promise: promiseType, + record: recordType, + set: setType, + strictObject: strictObjectType, + string: stringType, + symbol: symbolType, + transformer: effectsType, + tuple: tupleType, + undefined: undefinedType, + union: unionType, + unknown: unknownType, + void: voidType, + NEVER, + ZodIssueCode, + quotelessJson, + ZodError +}); + +// src/utils/environmentVariables.ts +var environmentVariablesSchema = z.object({ + BUILD_PATH: z.string().default("../starlight/dist"), + DOCS_PATH: z.string().default("../starlight/src"), + FILES_PATH: z.string().default("../starlight/public/files"), + BUILD_TIMEOUT_IN_SECONDS: z.coerce.number().min(10).default(60), + INGRESS_ENTRY: z.coerce.string().min(1).default("/") +}); +var parsedEnvironmentVariables = environmentVariablesSchema.parse(process.env); +var environmentVariables = { + buildPath: parsedEnvironmentVariables.BUILD_PATH, + docsPath: parsedEnvironmentVariables.DOCS_PATH, + filesPath: parsedEnvironmentVariables.FILES_PATH, + buildTimeoutInSeconds: parsedEnvironmentVariables.BUILD_TIMEOUT_IN_SECONDS, + ingressEntry: parsedEnvironmentVariables.INGRESS_ENTRY +}; +var environmentVariables_default = environmentVariables; + +// src/server.ts +var startServer = async (port) => { + const webserver = new Elysia().use(staticPlugin({ + prefix: "/" + })).use(staticPlugin({ + prefix: environmentVariables_default.ingressEntry + })).onRequest(({ set: set2 }) => { + set2.headers["Surrogate-Control"] = "no-store"; + set2.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, proxy-revalidate"; + set2.headers.Pragma = "no-cache"; + set2.headers.Expires = "0"; + }).onError(async ({ code }) => { + if (code === "NOT_FOUND") { + const file = Bun.file(`${environmentVariables_default.buildPath}/404.html`); + if (await file.exists()) { + return file; + } + return Bun.file("./templates/404.html"); + } + }).listen(4321); + return webserver; +}; + +// src/watcher.ts +import {watch} from "fs"; +var timeout = null; +var docsWatcher = null; +var filesWatcher = null; +var setBuildTimeout = () => { + if (timeout) { + clearTimeout(timeout); + console.log("\u23F0 Canceled previous timeout"); + } + console.log(`\u23F0 Next build will start in ${environmentVariables_default.buildTimeoutInSeconds}s`); + timeout = setTimeout(() => { + triggerBuild(); + }, Number(environmentVariables_default.buildTimeoutInSeconds) * 1000); +}; +var onChange = (event, filename) => { + console.log(`\uD83D\uDD0D Detected ${event} in ${filename}`); + setBuildTimeout(); +}; +var startWatcher = () => { + docsWatcher = watch(environmentVariables_default.docsPath ?? "", { recursive: true }, onChange); + console.log(`\uD83D\uDC40 Watching ${environmentVariables_default.docsPath} for changes`); + filesWatcher = watch(environmentVariables_default.filesPath ?? "", { recursive: true }, onChange); + console.log(`\uD83D\uDC40 Watching ${environmentVariables_default.filesPath} for changes`); +}; + +// src/index.ts +await buildDocs(); +var server2 = await startServer(4321); +var serverAddress = server2.server?.url.toString() ?? "--unknown--"; +console.log(`\uD83C\uDFE0\uD83D\uDCC3 Webserver is running at ${serverAddress}`); +startWatcher(); diff --git a/homedocs/webserver/dist/templates/404.html b/homedocs/webserver/dist/templates/404.html new file mode 100644 index 0000000..d6ef90f --- /dev/null +++ b/homedocs/webserver/dist/templates/404.html @@ -0,0 +1,37 @@ + + + + + + 404 Page Not Found + + + +

404 - Page Not Found

+

The page you are looking for does not exist.

+

Maybe there is an issue with your markdown files. Check the logs if there are any errors.

+ + \ No newline at end of file