UNPKG

elysia-oauth2-resource-server

Version:
1,463 lines (1,433 loc) 567 kB
var __create = Object.create; var __getProtoOf = Object.getPrototypeOf; var __defProp = Object.defineProperty; 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/cookie/dist/index.js var require_dist = __commonJS((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.parse = parse2; exports.serialize = serialize; var cookieNameRegExp = /^[\u0021-\u003A\u003C\u003E-\u007E]+$/; var cookieValueRegExp = /^[\u0021-\u003A\u003C-\u007E]*$/; var domainValueRegExp = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i; var pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/; var __toString = Object.prototype.toString; var NullObject = /* @__PURE__ */ (() => { const C = function() {}; C.prototype = Object.create(null); return C; })(); function parse2(str, options) { const obj = new NullObject; const len = str.length; if (len < 2) return obj; const dec = options?.decode || decode2; let index = 0; do { const eqIdx = str.indexOf("=", index); if (eqIdx === -1) break; const colonIdx = str.indexOf(";", index); const endIdx = colonIdx === -1 ? len : colonIdx; if (eqIdx > endIdx) { index = str.lastIndexOf(";", eqIdx - 1) + 1; continue; } const keyStartIdx = startIndex(str, index, eqIdx); const keyEndIdx = endIndex(str, eqIdx, keyStartIdx); const key = str.slice(keyStartIdx, keyEndIdx); if (obj[key] === undefined) { let valStartIdx = startIndex(str, eqIdx + 1, endIdx); let valEndIdx = endIndex(str, endIdx, valStartIdx); const value = dec(str.slice(valStartIdx, valEndIdx)); obj[key] = value; } index = endIdx + 1; } while (index < len); return obj; } function startIndex(str, index, max) { do { const code = str.charCodeAt(index); if (code !== 32 && code !== 9) return index; } while (++index < max); return max; } function endIndex(str, index, min) { while (index > min) { const code = str.charCodeAt(--index); if (code !== 32 && code !== 9) return index + 1; } return min; } function serialize(name, val, options) { const enc = options?.encode || encodeURIComponent; if (!cookieNameRegExp.test(name)) { throw new TypeError(`argument name is invalid: ${name}`); } const value = enc(val); if (!cookieValueRegExp.test(value)) { throw new TypeError(`argument val is invalid: ${val}`); } let str = name + "=" + value; if (!options) return str; if (options.maxAge !== undefined) { if (!Number.isInteger(options.maxAge)) { throw new TypeError(`option maxAge is invalid: ${options.maxAge}`); } str += "; Max-Age=" + options.maxAge; } if (options.domain) { if (!domainValueRegExp.test(options.domain)) { throw new TypeError(`option domain is invalid: ${options.domain}`); } str += "; Domain=" + options.domain; } if (options.path) { if (!pathValueRegExp.test(options.path)) { throw new TypeError(`option path is invalid: ${options.path}`); } str += "; Path=" + options.path; } if (options.expires) { if (!isDate(options.expires) || !Number.isFinite(options.expires.valueOf())) { throw new TypeError(`option expires is invalid: ${options.expires}`); } str += "; Expires=" + options.expires.toUTCString(); } if (options.httpOnly) { str += "; HttpOnly"; } if (options.secure) { str += "; Secure"; } if (options.partitioned) { str += "; Partitioned"; } if (options.priority) { const priority = typeof options.priority === "string" ? options.priority.toLowerCase() : undefined; 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: ${options.priority}`); } } if (options.sameSite) { const sameSite = typeof options.sameSite === "string" ? options.sameSite.toLowerCase() : options.sameSite; switch (sameSite) { case true: case "strict": str += "; SameSite=Strict"; break; case "lax": str += "; SameSite=Lax"; break; case "none": str += "; SameSite=None"; break; default: throw new TypeError(`option sameSite is invalid: ${options.sameSite}`); } } return str; } function decode2(str) { if (str.indexOf("%") === -1) return str; try { return decodeURIComponent(str); } catch (e) { return str; } } function isDate(val) { return __toString.call(val) === "[object Date]"; } }); // node_modules/memoirist/dist/index.mjs var createNode = (part, inert) => { const inertMap = inert?.length ? {} : null; if (inertMap) for (const child of inert) inertMap[child.part.charCodeAt(0)] = child; return { part, store: null, inert: inertMap, params: null, wildcardStore: null }; }; var cloneNode = (node, part) => ({ ...node, part }); var createParamNode = (name) => ({ name, store: null, inert: null }); var Memoirist = class _Memoirist { constructor(config = {}) { this.config = config; if (config.lazy) this.find = this.lazyFind; } root = {}; history = []; deferred = []; static regex = { static: /:.+?(?=\/|$)/, params: /:.+?(?=\/|$)/g, optionalParams: /:.+?\?(?=\/|$)/g }; lazyFind = (method, url) => { if (!this.config.lazy) return this.find; this.build(); return this.find(method, url); }; build() { if (!this.config.lazy) return; for (const [method, path, store] of this.deferred) this.add(method, path, store, { lazy: false, ignoreHistory: true }); this.deferred = []; this.find = (method, url) => { const root = this.root[method]; if (!root) return null; return matchRoute(url, url.length, root, 0); }; } add(method, path, store, { ignoreError = false, ignoreHistory = false, lazy = this.config.lazy } = {}) { if (lazy) { this.find = this.lazyFind; this.deferred.push([method, path, store]); return store; } if (typeof path !== "string") throw new TypeError("Route path must be a string"); if (path === "") path = "/"; else if (path[0] !== "/") path = `/${path}`; const isWildcard = path[path.length - 1] === "*"; const optionalParams = path.match(_Memoirist.regex.optionalParams); if (optionalParams) { const originalPath = path.replaceAll("?", ""); this.add(method, originalPath, store, { ignoreError, ignoreHistory, lazy }); for (let i = 0;i < optionalParams.length; i++) { let newPath = path.replace("/" + optionalParams[i], ""); this.add(method, newPath, store, { ignoreError: true, ignoreHistory, lazy }); } return store; } if (optionalParams) path = path.replaceAll("?", ""); if (this.history.find(([m, p, s]) => m === method && p === path)) return store; if (isWildcard || optionalParams && path.charCodeAt(path.length - 1) === 63) path = path.slice(0, -1); if (!ignoreHistory) this.history.push([method, path, store]); const inertParts = path.split(_Memoirist.regex.static); const paramParts = path.match(_Memoirist.regex.params) || []; if (inertParts[inertParts.length - 1] === "") inertParts.pop(); let node; if (!this.root[method]) node = this.root[method] = createNode("/"); else node = this.root[method]; let paramPartsIndex = 0; for (let i = 0;i < inertParts.length; ++i) { let part = inertParts[i]; if (i > 0) { const param = paramParts[paramPartsIndex++].slice(1); if (node.params === null) node.params = createParamNode(param); else if (node.params.name !== param) { if (ignoreError) return store; else throw new Error(`Cannot create route "${path}" with parameter "${param}" because a route already exists with a different parameter name ("${node.params.name}") in the same location`); } const params = node.params; if (params.inert === null) { node = params.inert = createNode(part); continue; } node = params.inert; } for (let j = 0;; ) { if (j === part.length) { if (j < node.part.length) { const childNode = cloneNode(node, node.part.slice(j)); Object.assign(node, createNode(part, [childNode])); } break; } if (j === node.part.length) { if (node.inert === null) node.inert = {}; const inert = node.inert[part.charCodeAt(j)]; if (inert) { node = inert; part = part.slice(j); j = 0; continue; } const childNode = createNode(part.slice(j)); node.inert[part.charCodeAt(j)] = childNode; node = childNode; break; } if (part[j] !== node.part[j]) { const existingChild = cloneNode(node, node.part.slice(j)); const newChild = createNode(part.slice(j)); Object.assign(node, createNode(node.part.slice(0, j), [ existingChild, newChild ])); node = newChild; break; } ++j; } } if (paramPartsIndex < paramParts.length) { const param = paramParts[paramPartsIndex]; const name = param.slice(1); if (node.params === null) node.params = createParamNode(name); else if (node.params.name !== name) { if (ignoreError) return store; else throw new Error(`Cannot create route "${path}" with parameter "${name}" because a route already exists with a different parameter name ("${node.params.name}") in the same location`); } if (node.params.store === null) node.params.store = store; return node.params.store; } if (isWildcard) { if (node.wildcardStore === null) node.wildcardStore = store; return node.wildcardStore; } if (node.store === null) node.store = store; return node.store; } find(method, url) { const root = this.root[method]; if (!root) return null; return matchRoute(url, url.length, root, 0); } }; var matchRoute = (url, urlLength, node, startIndex) => { const part = node.part; const length = part.length; const endIndex = startIndex + length; if (length > 1) { if (endIndex > urlLength) return null; if (length < 15) { for (let i = 1, j = startIndex + 1;i < length; ++i, ++j) if (part.charCodeAt(i) !== url.charCodeAt(j)) return null; } else if (url.slice(startIndex, endIndex) !== part) return null; } if (endIndex === urlLength) { if (node.store !== null) return { store: node.store, params: {} }; if (node.wildcardStore !== null) return { store: node.wildcardStore, params: { "*": "" } }; return null; } if (node.inert !== null) { const inert = node.inert[url.charCodeAt(endIndex)]; if (inert !== undefined) { const route = matchRoute(url, urlLength, inert, endIndex); if (route !== null) return route; } } if (node.params !== null) { const { store, name, inert } = node.params; const slashIndex = url.indexOf("/", endIndex); if (slashIndex !== endIndex) { if (slashIndex === -1 || slashIndex >= urlLength) { if (store !== null) { const params = {}; params[name] = url.substring(endIndex, urlLength); return { store, params }; } } else if (inert !== null) { const route = matchRoute(url, urlLength, inert, slashIndex); if (route !== null) { route.params[name] = url.substring(endIndex, slashIndex); return route; } } } } if (node.wildcardStore !== null) return { store: node.wildcardStore, params: { "*": url.substring(endIndex, urlLength) } }; return null; }; // node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs var exports_value = {}; __export(exports_value, { IsUndefined: () => IsUndefined, IsUint8Array: () => IsUint8Array, IsSymbol: () => IsSymbol, IsString: () => IsString, IsRegExp: () => IsRegExp, IsObject: () => IsObject, IsNumber: () => IsNumber, IsNull: () => IsNull, IsIterator: () => IsIterator, IsFunction: () => IsFunction, IsDate: () => IsDate, IsBoolean: () => IsBoolean, IsBigInt: () => IsBigInt, IsAsyncIterator: () => IsAsyncIterator, IsArray: () => IsArray, HasPropertyKey: () => HasPropertyKey }); function HasPropertyKey(value, key) { return key in value; } function IsAsyncIterator(value) { return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value; } function IsArray(value) { return Array.isArray(value); } function IsBigInt(value) { return typeof value === "bigint"; } function IsBoolean(value) { return typeof value === "boolean"; } function IsDate(value) { return value instanceof globalThis.Date; } function IsFunction(value) { return typeof value === "function"; } function IsIterator(value) { return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.iterator in value; } function IsNull(value) { return value === null; } function IsNumber(value) { return typeof value === "number"; } function IsObject(value) { return typeof value === "object" && value !== null; } function IsRegExp(value) { return value instanceof globalThis.RegExp; } function IsString(value) { return typeof value === "string"; } function IsSymbol(value) { return typeof value === "symbol"; } function IsUint8Array(value) { return value instanceof globalThis.Uint8Array; } function IsUndefined(value) { return value === undefined; } // node_modules/@sinclair/typebox/build/esm/type/clone/value.mjs function ArrayType(value) { return value.map((value2) => Visit(value2)); } function DateType(value) { return new Date(value.getTime()); } function Uint8ArrayType(value) { return new Uint8Array(value); } function RegExpType(value) { return new RegExp(value.source, value.flags); } function ObjectType(value) { const result = {}; for (const key of Object.getOwnPropertyNames(value)) { result[key] = Visit(value[key]); } for (const key of Object.getOwnPropertySymbols(value)) { result[key] = Visit(value[key]); } return result; } function Visit(value) { return IsArray(value) ? ArrayType(value) : IsDate(value) ? DateType(value) : IsUint8Array(value) ? Uint8ArrayType(value) : IsRegExp(value) ? RegExpType(value) : IsObject(value) ? ObjectType(value) : value; } function Clone(value) { return Visit(value); } // node_modules/@sinclair/typebox/build/esm/type/clone/type.mjs function CloneType(schema, options) { return options === undefined ? Clone(schema) : Clone({ ...options, ...schema }); } // node_modules/@sinclair/typebox/build/esm/value/guard/guard.mjs function IsAsyncIterator2(value) { return IsObject2(value) && globalThis.Symbol.asyncIterator in value; } function IsIterator2(value) { return IsObject2(value) && globalThis.Symbol.iterator in value; } function IsStandardObject(value) { return IsObject2(value) && (globalThis.Object.getPrototypeOf(value) === Object.prototype || globalThis.Object.getPrototypeOf(value) === null); } function IsPromise(value) { return value instanceof globalThis.Promise; } function IsDate2(value) { return value instanceof Date && globalThis.Number.isFinite(value.getTime()); } function IsMap(value) { return value instanceof globalThis.Map; } function IsSet(value) { return value instanceof globalThis.Set; } function IsTypedArray(value) { return globalThis.ArrayBuffer.isView(value); } function IsUint8Array2(value) { return value instanceof globalThis.Uint8Array; } function HasPropertyKey2(value, key) { return key in value; } function IsObject2(value) { return value !== null && typeof value === "object"; } function IsArray2(value) { return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value); } function IsUndefined2(value) { return value === undefined; } function IsNull2(value) { return value === null; } function IsBoolean2(value) { return typeof value === "boolean"; } function IsNumber2(value) { return typeof value === "number"; } function IsInteger(value) { return globalThis.Number.isInteger(value); } function IsBigInt2(value) { return typeof value === "bigint"; } function IsString2(value) { return typeof value === "string"; } function IsFunction2(value) { return typeof value === "function"; } function IsSymbol2(value) { return typeof value === "symbol"; } function IsValueType(value) { return IsBigInt2(value) || IsBoolean2(value) || IsNull2(value) || IsNumber2(value) || IsString2(value) || IsSymbol2(value) || IsUndefined2(value); } // node_modules/@sinclair/typebox/build/esm/system/policy.mjs var TypeSystemPolicy; (function(TypeSystemPolicy2) { TypeSystemPolicy2.InstanceMode = "default"; 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 = IsObject2(value); return TypeSystemPolicy2.AllowArrayObject ? isObject : isObject && !IsArray2(value); } TypeSystemPolicy2.IsObjectLike = IsObjectLike; function IsRecordLike(value) { return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array); } TypeSystemPolicy2.IsRecordLike = IsRecordLike; function IsNumberLike(value) { return TypeSystemPolicy2.AllowNaN ? IsNumber2(value) : Number.isFinite(value); } TypeSystemPolicy2.IsNumberLike = IsNumberLike; function IsVoidLike(value) { const isUndefined = IsUndefined2(value); return TypeSystemPolicy2.AllowNullVoid ? isUndefined || value === null : isUndefined; } TypeSystemPolicy2.IsVoidLike = IsVoidLike; })(TypeSystemPolicy || (TypeSystemPolicy = {})); // node_modules/@sinclair/typebox/build/esm/type/create/immutable.mjs function ImmutableArray(value) { return globalThis.Object.freeze(value).map((value2) => Immutable(value2)); } function ImmutableDate(value) { return value; } function ImmutableUint8Array(value) { return value; } function ImmutableRegExp(value) { return value; } function ImmutableObject(value) { const result = {}; for (const key of Object.getOwnPropertyNames(value)) { result[key] = Immutable(value[key]); } for (const key of Object.getOwnPropertySymbols(value)) { result[key] = Immutable(value[key]); } return globalThis.Object.freeze(result); } function Immutable(value) { return IsArray(value) ? ImmutableArray(value) : IsDate(value) ? ImmutableDate(value) : IsUint8Array(value) ? ImmutableUint8Array(value) : IsRegExp(value) ? ImmutableRegExp(value) : IsObject(value) ? ImmutableObject(value) : value; } // node_modules/@sinclair/typebox/build/esm/type/create/type.mjs function CreateType(schema, options) { const result = options !== undefined ? { ...options, ...schema } : schema; switch (TypeSystemPolicy.InstanceMode) { case "freeze": return Immutable(result); case "clone": return Clone(result); default: return result; } } // node_modules/@sinclair/typebox/build/esm/type/error/error.mjs class TypeBoxError extends Error { constructor(message) { super(message); } } // node_modules/@sinclair/typebox/build/esm/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/esm/type/guard/kind.mjs function IsReadonly(value) { return IsObject(value) && value[ReadonlyKind] === "Readonly"; } function IsOptional(value) { return IsObject(value) && value[OptionalKind] === "Optional"; } function IsAny(value) { return IsKindOf(value, "Any"); } function IsArgument(value) { return IsKindOf(value, "Argument"); } function IsArray3(value) { return IsKindOf(value, "Array"); } function IsAsyncIterator3(value) { return IsKindOf(value, "AsyncIterator"); } function IsBigInt3(value) { return IsKindOf(value, "BigInt"); } function IsBoolean3(value) { return IsKindOf(value, "Boolean"); } function IsComputed(value) { return IsKindOf(value, "Computed"); } function IsConstructor(value) { return IsKindOf(value, "Constructor"); } function IsDate3(value) { return IsKindOf(value, "Date"); } function IsFunction3(value) { return IsKindOf(value, "Function"); } function IsInteger2(value) { return IsKindOf(value, "Integer"); } function IsIntersect(value) { return IsKindOf(value, "Intersect"); } function IsIterator3(value) { return IsKindOf(value, "Iterator"); } function IsKindOf(value, kind) { return IsObject(value) && Kind in value && value[Kind] === kind; } function IsLiteralValue(value) { return IsBoolean(value) || IsNumber(value) || IsString(value); } function IsLiteral(value) { return IsKindOf(value, "Literal"); } function IsMappedKey(value) { return IsKindOf(value, "MappedKey"); } function IsMappedResult(value) { return IsKindOf(value, "MappedResult"); } function IsNever(value) { return IsKindOf(value, "Never"); } function IsNot(value) { return IsKindOf(value, "Not"); } function IsNull3(value) { return IsKindOf(value, "Null"); } function IsNumber3(value) { return IsKindOf(value, "Number"); } function IsObject3(value) { return IsKindOf(value, "Object"); } function IsPromise2(value) { return IsKindOf(value, "Promise"); } function IsRecord(value) { return IsKindOf(value, "Record"); } function IsRef(value) { return IsKindOf(value, "Ref"); } function IsRegExp2(value) { return IsKindOf(value, "RegExp"); } function IsString3(value) { return IsKindOf(value, "String"); } function IsSymbol3(value) { return IsKindOf(value, "Symbol"); } function IsTemplateLiteral(value) { return IsKindOf(value, "TemplateLiteral"); } function IsThis(value) { return IsKindOf(value, "This"); } function IsTransform(value) { return IsObject(value) && TransformKind in value; } function IsTuple(value) { return IsKindOf(value, "Tuple"); } function IsUndefined3(value) { return IsKindOf(value, "Undefined"); } function IsUnion(value) { return IsKindOf(value, "Union"); } function IsUint8Array3(value) { return IsKindOf(value, "Uint8Array"); } function IsUnknown(value) { return IsKindOf(value, "Unknown"); } function IsUnsafe(value) { return IsKindOf(value, "Unsafe"); } function IsVoid(value) { return IsKindOf(value, "Void"); } function IsKind(value) { return IsObject(value) && Kind in value && IsString(value[Kind]); } function IsSchema(value) { return IsAny(value) || IsArgument(value) || IsArray3(value) || IsBoolean3(value) || IsBigInt3(value) || IsAsyncIterator3(value) || IsComputed(value) || IsConstructor(value) || IsDate3(value) || IsFunction3(value) || IsInteger2(value) || IsIntersect(value) || IsIterator3(value) || IsLiteral(value) || IsMappedKey(value) || IsMappedResult(value) || IsNever(value) || IsNot(value) || IsNull3(value) || IsNumber3(value) || IsObject3(value) || IsPromise2(value) || IsRecord(value) || IsRef(value) || IsRegExp2(value) || IsString3(value) || IsSymbol3(value) || IsTemplateLiteral(value) || IsThis(value) || IsTuple(value) || IsUndefined3(value) || IsUnion(value) || IsUint8Array3(value) || IsUnknown(value) || IsUnsafe(value) || IsVoid(value) || IsKind(value); } // node_modules/@sinclair/typebox/build/esm/type/guard/type.mjs var exports_type = {}; __export(exports_type, { TypeGuardUnknownTypeError: () => TypeGuardUnknownTypeError, IsVoid: () => IsVoid2, IsUnsafe: () => IsUnsafe2, IsUnknown: () => IsUnknown2, IsUnionLiteral: () => IsUnionLiteral, IsUnion: () => IsUnion2, IsUndefined: () => IsUndefined4, IsUint8Array: () => IsUint8Array4, IsTuple: () => IsTuple2, IsTransform: () => IsTransform2, IsThis: () => IsThis2, IsTemplateLiteral: () => IsTemplateLiteral2, IsSymbol: () => IsSymbol4, IsString: () => IsString4, IsSchema: () => IsSchema2, IsRegExp: () => IsRegExp3, IsRef: () => IsRef2, IsRecursive: () => IsRecursive, IsRecord: () => IsRecord2, IsReadonly: () => IsReadonly2, IsProperties: () => IsProperties, IsPromise: () => IsPromise3, IsOptional: () => IsOptional2, IsObject: () => IsObject4, IsNumber: () => IsNumber4, IsNull: () => IsNull4, IsNot: () => IsNot2, IsNever: () => IsNever2, IsMappedResult: () => IsMappedResult2, IsMappedKey: () => IsMappedKey2, IsLiteralValue: () => IsLiteralValue2, IsLiteralString: () => IsLiteralString, IsLiteralNumber: () => IsLiteralNumber, IsLiteralBoolean: () => IsLiteralBoolean, IsLiteral: () => IsLiteral2, IsKindOf: () => IsKindOf2, IsKind: () => IsKind2, IsIterator: () => IsIterator4, IsIntersect: () => IsIntersect2, IsInteger: () => IsInteger3, IsImport: () => IsImport, IsFunction: () => IsFunction4, IsDate: () => IsDate4, IsConstructor: () => IsConstructor2, IsComputed: () => IsComputed2, IsBoolean: () => IsBoolean4, IsBigInt: () => IsBigInt4, IsAsyncIterator: () => IsAsyncIterator4, IsArray: () => IsArray4, IsArgument: () => IsArgument2, IsAny: () => IsAny2 }); class TypeGuardUnknownTypeError extends TypeBoxError { } var KnownTypes = [ "Argument", "Any", "Array", "AsyncIterator", "BigInt", "Boolean", "Computed", "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" ]; function IsPattern(value) { try { new RegExp(value); return true; } catch { return false; } } function IsControlCharacterFree(value) { if (!IsString(value)) return false; for (let i = 0;i < value.length; i++) { const code = value.charCodeAt(i); if (code >= 7 && code <= 13 || code === 27 || code === 127) { return false; } } return true; } function IsAdditionalProperties(value) { return IsOptionalBoolean(value) || IsSchema2(value); } function IsOptionalBigInt(value) { return IsUndefined(value) || IsBigInt(value); } function IsOptionalNumber(value) { return IsUndefined(value) || IsNumber(value); } function IsOptionalBoolean(value) { return IsUndefined(value) || IsBoolean(value); } function IsOptionalString(value) { return IsUndefined(value) || IsString(value); } function IsOptionalPattern(value) { return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value) && IsPattern(value); } function IsOptionalFormat(value) { return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value); } function IsOptionalSchema(value) { return IsUndefined(value) || IsSchema2(value); } function IsReadonly2(value) { return IsObject(value) && value[ReadonlyKind] === "Readonly"; } function IsOptional2(value) { return IsObject(value) && value[OptionalKind] === "Optional"; } function IsAny2(value) { return IsKindOf2(value, "Any") && IsOptionalString(value.$id); } function IsArgument2(value) { return IsKindOf2(value, "Argument") && IsNumber(value.index); } function IsArray4(value) { return IsKindOf2(value, "Array") && value.type === "array" && IsOptionalString(value.$id) && IsSchema2(value.items) && IsOptionalNumber(value.minItems) && IsOptionalNumber(value.maxItems) && IsOptionalBoolean(value.uniqueItems) && IsOptionalSchema(value.contains) && IsOptionalNumber(value.minContains) && IsOptionalNumber(value.maxContains); } function IsAsyncIterator4(value) { return IsKindOf2(value, "AsyncIterator") && value.type === "AsyncIterator" && IsOptionalString(value.$id) && IsSchema2(value.items); } function IsBigInt4(value) { return IsKindOf2(value, "BigInt") && value.type === "bigint" && IsOptionalString(value.$id) && IsOptionalBigInt(value.exclusiveMaximum) && IsOptionalBigInt(value.exclusiveMinimum) && IsOptionalBigInt(value.maximum) && IsOptionalBigInt(value.minimum) && IsOptionalBigInt(value.multipleOf); } function IsBoolean4(value) { return IsKindOf2(value, "Boolean") && value.type === "boolean" && IsOptionalString(value.$id); } function IsComputed2(value) { return IsKindOf2(value, "Computed") && IsString(value.target) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)); } function IsConstructor2(value) { return IsKindOf2(value, "Constructor") && value.type === "Constructor" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns); } function IsDate4(value) { return IsKindOf2(value, "Date") && value.type === "Date" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximumTimestamp) && IsOptionalNumber(value.exclusiveMinimumTimestamp) && IsOptionalNumber(value.maximumTimestamp) && IsOptionalNumber(value.minimumTimestamp) && IsOptionalNumber(value.multipleOfTimestamp); } function IsFunction4(value) { return IsKindOf2(value, "Function") && value.type === "Function" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns); } function IsImport(value) { return IsKindOf2(value, "Import") && HasPropertyKey(value, "$defs") && IsObject(value.$defs) && IsProperties(value.$defs) && HasPropertyKey(value, "$ref") && IsString(value.$ref) && value.$ref in value.$defs; } function IsInteger3(value) { return IsKindOf2(value, "Integer") && value.type === "integer" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf); } function IsProperties(value) { return IsObject(value) && Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema2(schema)); } function IsIntersect2(value) { return IsKindOf2(value, "Intersect") && (IsString(value.type) && value.type !== "object" ? false : true) && IsArray(value.allOf) && value.allOf.every((schema) => IsSchema2(schema) && !IsTransform2(schema)) && IsOptionalString(value.type) && (IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) && IsOptionalString(value.$id); } function IsIterator4(value) { return IsKindOf2(value, "Iterator") && value.type === "Iterator" && IsOptionalString(value.$id) && IsSchema2(value.items); } function IsKindOf2(value, kind) { return IsObject(value) && Kind in value && value[Kind] === kind; } function IsLiteralString(value) { return IsLiteral2(value) && IsString(value.const); } function IsLiteralNumber(value) { return IsLiteral2(value) && IsNumber(value.const); } function IsLiteralBoolean(value) { return IsLiteral2(value) && IsBoolean(value.const); } function IsLiteral2(value) { return IsKindOf2(value, "Literal") && IsOptionalString(value.$id) && IsLiteralValue2(value.const); } function IsLiteralValue2(value) { return IsBoolean(value) || IsNumber(value) || IsString(value); } function IsMappedKey2(value) { return IsKindOf2(value, "MappedKey") && IsArray(value.keys) && value.keys.every((key) => IsNumber(key) || IsString(key)); } function IsMappedResult2(value) { return IsKindOf2(value, "MappedResult") && IsProperties(value.properties); } function IsNever2(value) { return IsKindOf2(value, "Never") && IsObject(value.not) && Object.getOwnPropertyNames(value.not).length === 0; } function IsNot2(value) { return IsKindOf2(value, "Not") && IsSchema2(value.not); } function IsNull4(value) { return IsKindOf2(value, "Null") && value.type === "null" && IsOptionalString(value.$id); } function IsNumber4(value) { return IsKindOf2(value, "Number") && value.type === "number" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf); } function IsObject4(value) { return IsKindOf2(value, "Object") && value.type === "object" && IsOptionalString(value.$id) && IsProperties(value.properties) && IsAdditionalProperties(value.additionalProperties) && IsOptionalNumber(value.minProperties) && IsOptionalNumber(value.maxProperties); } function IsPromise3(value) { return IsKindOf2(value, "Promise") && value.type === "Promise" && IsOptionalString(value.$id) && IsSchema2(value.item); } function IsRecord2(value) { return IsKindOf2(value, "Record") && value.type === "object" && IsOptionalString(value.$id) && IsAdditionalProperties(value.additionalProperties) && IsObject(value.patternProperties) && ((schema) => { const keys = Object.getOwnPropertyNames(schema.patternProperties); return keys.length === 1 && IsPattern(keys[0]) && IsObject(schema.patternProperties) && IsSchema2(schema.patternProperties[keys[0]]); })(value); } function IsRecursive(value) { return IsObject(value) && Hint in value && value[Hint] === "Recursive"; } function IsRef2(value) { return IsKindOf2(value, "Ref") && IsOptionalString(value.$id) && IsString(value.$ref); } function IsRegExp3(value) { return IsKindOf2(value, "RegExp") && IsOptionalString(value.$id) && IsString(value.source) && IsString(value.flags) && IsOptionalNumber(value.maxLength) && IsOptionalNumber(value.minLength); } function IsString4(value) { return IsKindOf2(value, "String") && value.type === "string" && IsOptionalString(value.$id) && IsOptionalNumber(value.minLength) && IsOptionalNumber(value.maxLength) && IsOptionalPattern(value.pattern) && IsOptionalFormat(value.format); } function IsSymbol4(value) { return IsKindOf2(value, "Symbol") && value.type === "symbol" && IsOptionalString(value.$id); } function IsTemplateLiteral2(value) { return IsKindOf2(value, "TemplateLiteral") && value.type === "string" && IsString(value.pattern) && value.pattern[0] === "^" && value.pattern[value.pattern.length - 1] === "$"; } function IsThis2(value) { return IsKindOf2(value, "This") && IsOptionalString(value.$id) && IsString(value.$ref); } function IsTransform2(value) { return IsObject(value) && TransformKind in value; } function IsTuple2(value) { return IsKindOf2(value, "Tuple") && value.type === "array" && IsOptionalString(value.$id) && IsNumber(value.minItems) && IsNumber(value.maxItems) && value.minItems === value.maxItems && (IsUndefined(value.items) && IsUndefined(value.additionalItems) && value.minItems === 0 || IsArray(value.items) && value.items.every((schema) => IsSchema2(schema))); } function IsUndefined4(value) { return IsKindOf2(value, "Undefined") && value.type === "undefined" && IsOptionalString(value.$id); } function IsUnionLiteral(value) { return IsUnion2(value) && value.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema)); } function IsUnion2(value) { return IsKindOf2(value, "Union") && IsOptionalString(value.$id) && IsObject(value) && IsArray(value.anyOf) && value.anyOf.every((schema) => IsSchema2(schema)); } function IsUint8Array4(value) { return IsKindOf2(value, "Uint8Array") && value.type === "Uint8Array" && IsOptionalString(value.$id) && IsOptionalNumber(value.minByteLength) && IsOptionalNumber(value.maxByteLength); } function IsUnknown2(value) { return IsKindOf2(value, "Unknown") && IsOptionalString(value.$id); } function IsUnsafe2(value) { return IsKindOf2(value, "Unsafe"); } function IsVoid2(value) { return IsKindOf2(value, "Void") && value.type === "void" && IsOptionalString(value.$id); } function IsKind2(value) { return IsObject(value) && Kind in value && IsString(value[Kind]) && !KnownTypes.includes(value[Kind]); } function IsSchema2(value) { return IsObject(value) && (IsAny2(value) || IsArgument2(value) || IsArray4(value) || IsBoolean4(value) || IsBigInt4(value) || IsAsyncIterator4(value) || IsComputed2(value) || IsConstructor2(value) || IsDate4(value) || IsFunction4(value) || IsInteger3(value) || IsIntersect2(value) || IsIterator4(value) || IsLiteral2(value) || IsMappedKey2(value) || IsMappedResult2(value) || IsNever2(value) || IsNot2(value) || IsNull4(value) || IsNumber4(value) || IsObject4(value) || IsPromise3(value) || IsRecord2(value) || IsRef2(value) || IsRegExp3(value) || IsString4(value) || IsSymbol4(value) || IsTemplateLiteral2(value) || IsThis2(value) || IsTuple2(value) || IsUndefined4(value) || IsUnion2(value) || IsUint8Array4(value) || IsUnknown2(value) || IsUnsafe2(value) || IsVoid2(value) || IsKind2(value)); } // node_modules/@sinclair/typebox/build/esm/type/patterns/patterns.mjs var PatternBoolean = "(true|false)"; var PatternNumber = "(0|[1-9][0-9]*)"; var PatternString = "(.*)"; var PatternNever = "(?!.*)"; var PatternBooleanExact = `^${PatternBoolean}$`; var PatternNumberExact = `^${PatternNumber}$`; var PatternStringExact = `^${PatternString}$`; var PatternNeverExact = `^${PatternNever}$`; // node_modules/@sinclair/typebox/build/esm/type/registry/format.mjs var exports_format = {}; __export(exports_format, { Set: () => Set2, Has: () => Has, Get: () => Get, Entries: () => Entries, Delete: () => Delete, Clear: () => Clear }); var map = new Map; 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); } // node_modules/@sinclair/typebox/build/esm/type/registry/type.mjs var exports_type2 = {}; __export(exports_type2, { Set: () => Set3, Has: () => Has2, Get: () => Get2, Entries: () => Entries2, Delete: () => Delete2, Clear: () => Clear2 }); var map2 = new Map; 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); } // node_modules/@sinclair/typebox/build/esm/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)); } function SetIntersectManyResolve(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) { const Acc = []; for (const L of T) Acc.push(...L); return Acc; } // node_modules/@sinclair/typebox/build/esm/type/any/any.mjs function Any(options) { return CreateType({ [Kind]: "Any" }, options); } // node_modules/@sinclair/typebox/build/esm/type/array/array.mjs function Array2(items, options) { return CreateType({ [Kind]: "Array", type: "array", items }, options); } // node_modules/@sinclair/typebox/build/esm/type/argument/argument.mjs function Argument(index) { return CreateType({ [Kind]: "Argument", index }); } // node_modules/@sinclair/typebox/build/esm/type/async-iterator/async-iterator.mjs function AsyncIterator(items, options) { return CreateType({ [Kind]: "AsyncIterator", type: "AsyncIterator", items }, options); } // node_modules/@sinclair/typebox/build/esm/type/computed/computed.mjs function Computed(target, parameters, options) { return CreateType({ [Kind]: "Computed", target, parameters }, options); } // node_modules/@sinclair/typebox/build/esm/type/discard/discard.mjs function DiscardKey(value, key) { const { [key]: _, ...rest } = value; return rest; } function Discard(value, keys) { return keys.reduce((acc, key) => DiscardKey(acc, key), value); } // node_modules/@sinclair/typebox/build/esm/type/never/never.mjs function Never(options) { return CreateType({ [Kind]: "Never", not: {} }, options); } // node_modules/@sinclair/typebox/build/esm/type/mapped/mapped-result.mjs function MappedResult(properties) { return CreateType({ [Kind]: "MappedResult", properties }); } // node_modules/@sinclair/typebox/build/esm/type/constructor/constructor.mjs function Constructor(parameters, returns, options) { return CreateType({ [Kind]: "Constructor", type: "Constructor", parameters, returns }, options); } // node_modules/@sinclair/typebox/build/esm/type/function/function.mjs function Function2(parameters, returns, options) { return CreateType({ [Kind]: "Function", type: "Function", parameters, returns }, options); } // node_modules/@sinclair/typebox/build/esm/type/union/union-create.mjs function UnionCreate(T, options) { return CreateType({ [Kind]: "Union", anyOf: T }, options); } // node_modules/@sinclair/typebox/build/esm/type/union/union-evaluated.mjs function IsUnionOptional(types) { return types.some((type) => IsOptional(type)); } function RemoveOptionalFromRest(types) { return types.map((left) => IsOptional(left) ? RemoveOptionalFromType(left) : left); } function RemoveOptionalFromType(T) { return Discard(T, [OptionalKind]); } function ResolveUnion(types, options) { const isOptional = IsUnionOptional(types); return isOptional ? Optional(UnionCreate(RemoveOptionalFromRest(types), options)) : UnionCreate(RemoveOptionalFromRest(types), options); } function UnionEvaluated(T, options) { return T.length === 1 ? CreateType(T[0], options) : T.length === 0 ? Never(options) : ResolveUnion(T, options); } // node_modules/@sinclair/typebox/build/esm/type/union/union.mjs function Union(types, options) { return types.length === 0 ? Never(options) : types.length === 1 ? CreateType(types[0], options) : UnionCreate(types, options); } // node_modules/@sinclair/typebox/build/esm/type/template-literal/parse.mjs class TemplateLiteralParserError extends TypeBoxError { } function Unescape(pattern) { return pattern.replace(/\\\$/g, "$").replace(/\\\*/g, "*").replace(/\\\^/g, "^").replace(/\\\|/g, "|").replace(/\\\(/g, "(").replace(/\\\)/g, ")"); } function IsNonEscaped(pattern, index, char) { return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92; } function IsOpenParen(pattern, index) { return IsNonEscaped(pattern, index, "("); } function IsCloseParen(pattern, index) { return IsNonEscaped(pattern, index, ")"); } function IsSeparator(pattern, index) { return IsNonEscaped(pattern, index, "|"); } function IsGroup(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; } function InGroup(pattern) { return pattern.slice(1, pattern.length - 1); } function IsPrecedenceOr(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; } function IsPrecedenceAnd(pattern) { for (let index = 0;index < pattern.length; index++) { if (IsOpenParen(pattern, index)) return true; } return false; } function Or(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 }; } function And(pattern) { function Group(value, index) { if (!IsOpenParen(value, index)) throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`); let count = 0; for (let scan = index;scan < value.length; scan++) { if (IsOpenParen(value, scan)) count += 1; if (IsCloseParen(value, 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)); } // node_modules/@sinclair/typebox/build/esm/type/template-literal/finite.mjs class TemplateLiteralFiniteError extends TypeBoxError { } function IsNumberExpression(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]*"; } function IsBooleanExpression(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"; } function IsStringExpression(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); } // node_modules/@sinclair/typebox/build/esm/type/template-literal/generate.mjs class TemplateLiteralGenerateError extends TypeBoxError { } 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) {