UNPKG

@vecrea/oid4vc-prex

Version:

A TypeScript library for handling OpenID for Verifiable Credentials (OID4VC) Presentation Exchange operations

1,538 lines 154 kB
var It = Object.defineProperty; var Rt = (r, e, t) => e in r ? It(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t; var I = (r, e, t) => Rt(r, typeof e != "symbol" ? e + "" : e, t); const Pt = (r) => r === void 0 ? "undefined" : r === null ? "null" : typeof r == "string" ? r : r instanceof Error ? r.message : JSON.stringify(r), mt = (r) => r instanceof Error ? r : new Error(Pt(r)); class j { /** * Constructs a new instance of the Result class. * @param {T | undefined} value The value associated with the result, if successful. * @param {Error | undefined} error The error associated with the result, if failed. * @throws {Error} If both value and error are provided. */ constructor(e, t) { if (this.value = e, this.error = t, e && t) throw new Error("Result cannot be both success and failure"); } /** * Creates a successful result with the specified value. * @template T The type of the value. * @param {T} value The value to be wrapped in the successful result. * @returns {Result<T>} A successful result containing the value. */ static success(e) { return new j(e, void 0); } /** * Creates a failure result with the specified error. * @template T The type of the value. * @param {Error} error The error to be wrapped in the failure result. * @returns {Result<T>} A failure result containing the error. */ static failure(e) { return new j(void 0, e); } /** * Checks if the result is successful. * @returns {this is { value: T }} True if the result is successful, false otherwise. */ isSuccess() { return this.error === void 0; } /** * Checks if the result is a failure. * @returns {this is { error: Error }} True if the result is a failure, false otherwise. */ isFailure() { return !this.isSuccess(); } /** * Returns the value if the result is successful, or throws the error if it is a failure. * @returns {T} The value, if the result is successful. * @throws {Error} The error, if the result is a failure. */ getOrThrow() { if (this.isSuccess()) return this.value; throw this.error; } /** * Returns the value if the result is successful, or the specified default value if it is a failure. * * @param {T} defaultValue - The default value to return if the result is a failure. * @returns {T} The value if the result is successful, or the default value if it is a failure. */ getOrDefault(e) { return this.isSuccess() ? this.value : e; } /** * Returns the value if the result is successful, or the result of the transfer function if it is a failure. * @param {(error: Error) => T} transfer A function that transfers the error to a value. * @returns {T} The value, if the result is successful, or the result of the transfer function if it is a failure. */ getOrElse(e) { return this.isSuccess() ? this.value : e(this.error); } /** * Executes the specified function if the result is successful. * @param {(value: T) => void} f A function to be executed if the result is successful. * @returns {Result<T>} The current result instance. */ onSuccess(e) { return this.isSuccess() && e(this.value), this; } /** * Executes the specified function if the result is a failure. * @param {(error: Error) => void} f A function to be executed if the result is a failure. * @returns {Result<T>} The current result instance. */ onFailure(e) { return this.isFailure() && e(this.error), this; } /** * Recovers from a failure by applying the specified transform function. * @param {(error: Error) => T} transform A function that transforms the error to a value. * @returns {Result<T>} A new successful result with the transformed value if the current result is a failure, or the current result if it is already successful. */ recover(e) { return this.isFailure() ? Ke(() => e(this.error)) : this; } /** * Recovers from a failure by applying the specified asynchronous transform function. * @param {(error: Error) => Promise<T>} transform An asynchronous function that transforms the error to a value. * @returns {Promise<Result<T>>} A promise that resolves to a new successful result with the transformed value if the current result is a failure, or the current result if it is already successful. */ async recoverAsync(e) { return this.isFailure() ? Dt(() => e(this.error)) : this; } } const Ke = (r, ...e) => { try { const t = r(...e); return t instanceof j ? t : j.success(t); } catch (t) { return j.failure(mt(t)); } }, Dt = async (r, ...e) => { try { const t = await r(...e); return t instanceof j ? t : j.success(t); } catch (t) { return j.failure(mt(t)); } }; var O; (function(r) { r.assertEqual = (n) => { }; function e(n) { } r.assertIs = e; function t(n) { throw new Error(); } r.assertNever = t, r.arrayToEnum = (n) => { const i = {}; for (const a of n) i[a] = a; return i; }, r.getValidEnumValues = (n) => { const i = r.objectKeys(n).filter((o) => typeof n[n[o]] != "number"), a = {}; for (const o of i) a[o] = n[o]; return r.objectValues(a); }, r.objectValues = (n) => r.objectKeys(n).map(function(i) { return n[i]; }), r.objectKeys = typeof Object.keys == "function" ? (n) => Object.keys(n) : (n) => { const i = []; for (const a in n) Object.prototype.hasOwnProperty.call(n, a) && i.push(a); return i; }, r.find = (n, i) => { for (const a of n) if (i(a)) return a; }, r.isInteger = typeof Number.isInteger == "function" ? (n) => Number.isInteger(n) : (n) => typeof n == "number" && Number.isFinite(n) && Math.floor(n) === n; function s(n, i = " | ") { return n.map((a) => typeof a == "string" ? `'${a}'` : a).join(i); } r.joinValues = s, r.jsonStringifyReplacer = (n, i) => typeof i == "bigint" ? i.toString() : i; })(O || (O = {})); var nt; (function(r) { r.mergeShapes = (e, t) => ({ ...e, ...t // second overwrites first }); })(nt || (nt = {})); const p = O.arrayToEnum([ "string", "nan", "number", "integer", "float", "boolean", "date", "bigint", "symbol", "function", "undefined", "null", "array", "object", "unknown", "promise", "void", "never", "map", "set" ]), B = (r) => { switch (typeof r) { case "undefined": return p.undefined; case "string": return p.string; case "number": return Number.isNaN(r) ? p.nan : p.number; case "boolean": return p.boolean; case "function": return p.function; case "bigint": return p.bigint; case "symbol": return p.symbol; case "object": return Array.isArray(r) ? p.array : r === null ? p.null : r.then && typeof r.then == "function" && r.catch && typeof r.catch == "function" ? p.promise : typeof Map < "u" && r instanceof Map ? p.map : typeof Set < "u" && r instanceof Set ? p.set : typeof Date < "u" && r instanceof Date ? p.date : p.object; default: return p.unknown; } }, l = O.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" ]); class U extends Error { get errors() { return this.issues; } constructor(e) { super(), this.issues = [], this.addIssue = (s) => { this.issues = [...this.issues, s]; }, this.addIssues = (s = []) => { this.issues = [...this.issues, ...s]; }; const t = new.target.prototype; Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e; } format(e) { const t = e || function(i) { return i.message; }, s = { _errors: [] }, n = (i) => { for (const a of i.issues) if (a.code === "invalid_union") a.unionErrors.map(n); else if (a.code === "invalid_return_type") n(a.returnTypeError); else if (a.code === "invalid_arguments") n(a.argumentsError); else if (a.path.length === 0) s._errors.push(t(a)); else { let o = s, d = 0; for (; d < a.path.length; ) { const u = a.path[d]; d === a.path.length - 1 ? (o[u] = o[u] || { _errors: [] }, o[u]._errors.push(t(a))) : o[u] = o[u] || { _errors: [] }, o = o[u], d++; } } }; return n(this), s; } static assert(e) { if (!(e instanceof U)) throw new Error(`Not a ZodError: ${e}`); } toString() { return this.message; } get message() { return JSON.stringify(this.issues, O.jsonStringifyReplacer, 2); } get isEmpty() { return this.issues.length === 0; } flatten(e = (t) => t.message) { const t = {}, s = []; for (const n of this.issues) n.path.length > 0 ? (t[n.path[0]] = t[n.path[0]] || [], t[n.path[0]].push(e(n))) : s.push(e(n)); return { formErrors: s, fieldErrors: t }; } get formErrors() { return this.flatten(); } } U.create = (r) => new U(r); const $e = (r, e) => { let t; switch (r.code) { case l.invalid_type: r.received === p.undefined ? t = "Required" : t = `Expected ${r.expected}, received ${r.received}`; break; case l.invalid_literal: t = `Invalid literal value, expected ${JSON.stringify(r.expected, O.jsonStringifyReplacer)}`; break; case l.unrecognized_keys: t = `Unrecognized key(s) in object: ${O.joinValues(r.keys, ", ")}`; break; case l.invalid_union: t = "Invalid input"; break; case l.invalid_union_discriminator: t = `Invalid discriminator value. Expected ${O.joinValues(r.options)}`; break; case l.invalid_enum_value: t = `Invalid enum value. Expected ${O.joinValues(r.options)}, received '${r.received}'`; break; case l.invalid_arguments: t = "Invalid function arguments"; break; case l.invalid_return_type: t = "Invalid function return type"; break; case l.invalid_date: t = "Invalid date"; break; case l.invalid_string: typeof r.validation == "object" ? "includes" in r.validation ? (t = `Invalid input: must include "${r.validation.includes}"`, typeof r.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${r.validation.position}`)) : "startsWith" in r.validation ? t = `Invalid input: must start with "${r.validation.startsWith}"` : "endsWith" in r.validation ? t = `Invalid input: must end with "${r.validation.endsWith}"` : O.assertNever(r.validation) : r.validation !== "regex" ? t = `Invalid ${r.validation}` : t = "Invalid"; break; case l.too_small: r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "more than"} ${r.minimum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "over"} ${r.minimum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${r.minimum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(r.minimum))}` : t = "Invalid input"; break; case l.too_big: r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "less than"} ${r.maximum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "under"} ${r.maximum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "bigint" ? t = `BigInt must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly" : r.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(r.maximum))}` : t = "Invalid input"; break; case l.custom: t = "Invalid input"; break; case l.invalid_intersection_types: t = "Intersection results could not be merged"; break; case l.not_multiple_of: t = `Number must be a multiple of ${r.multipleOf}`; break; case l.not_finite: t = "Number must be finite"; break; default: t = e.defaultError, O.assertNever(r); } return { message: t }; }; let Zt = $e; function $t() { return Zt; } const Mt = (r) => { const { data: e, path: t, errorMaps: s, issueData: n } = r, i = [...t, ...n.path || []], a = { ...n, path: i }; if (n.message !== void 0) return { ...n, path: i, message: n.message }; let o = ""; const d = s.filter((u) => !!u).slice().reverse(); for (const u of d) o = u(a, { data: e, defaultError: o }).message; return { ...n, path: i, message: o }; }; function h(r, e) { const t = $t(), s = Mt({ issueData: e, data: r.data, path: r.path, errorMaps: [ r.common.contextualErrorMap, // contextual error map is first priority r.schemaErrorMap, // then schema-bound map if available t, // then global override map t === $e ? void 0 : $e // then global default map ].filter((n) => !!n) }); r.common.issues.push(s); } class N { constructor() { this.value = "valid"; } dirty() { this.value === "valid" && (this.value = "dirty"); } abort() { this.value !== "aborted" && (this.value = "aborted"); } static mergeArray(e, t) { const s = []; for (const n of t) { if (n.status === "aborted") return y; n.status === "dirty" && e.dirty(), s.push(n.value); } return { status: e.value, value: s }; } static async mergeObjectAsync(e, t) { const s = []; for (const n of t) { const i = await n.key, a = await n.value; s.push({ key: i, value: a }); } return N.mergeObjectSync(e, s); } static mergeObjectSync(e, t) { const s = {}; for (const n of t) { const { key: i, value: a } = n; if (i.status === "aborted" || a.status === "aborted") return y; i.status === "dirty" && e.dirty(), a.status === "dirty" && e.dirty(), i.value !== "__proto__" && (typeof a.value < "u" || n.alwaysSet) && (s[i.value] = a.value); } return { status: e.value, value: s }; } } const y = Object.freeze({ status: "aborted" }), se = (r) => ({ status: "dirty", value: r }), T = (r) => ({ status: "valid", value: r }), it = (r) => r.status === "aborted", at = (r) => r.status === "dirty", Q = (r) => r.status === "valid", de = (r) => typeof Promise < "u" && r instanceof Promise; var m; (function(r) { r.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, r.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message; })(m || (m = {})); var le = function(r, e, t, s) { if (t === "a" && !s) throw new TypeError("Private accessor was defined without a getter"); if (typeof e == "function" ? r !== e || !s : !e.has(r)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return t === "m" ? s : t === "a" ? s.call(r) : s ? s.value : e.get(r); }, gt = function(r, e, t, s, n) { if (s === "m") throw new TypeError("Private method is not writable"); if (s === "a" && !n) throw new TypeError("Private accessor was defined without a setter"); if (typeof e == "function" ? r !== e || !n : !e.has(r)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return s === "a" ? n.call(r, t) : n ? n.value = t : e.set(r, t), t; }, ne, ie; class Z { constructor(e, t, s, n) { this._cachedPath = [], this.parent = e, this.data = t, this._path = s, this._key = n; } get path() { return this._cachedPath.length || (Array.isArray(this._key) ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath; } } const ot = (r, e) => { if (Q(e)) return { success: !0, data: e.value }; if (!r.common.issues.length) throw new Error("Validation failed but no issues detected."); return { success: !1, get error() { if (this._error) return this._error; const t = new U(r.common.issues); return this._error = t, this._error; } }; }; function v(r) { if (!r) return {}; const { errorMap: e, invalid_type_error: t, required_error: s, description: n } = r; if (e && (t || s)) throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`); return e ? { errorMap: e, description: n } : { errorMap: (a, o) => { const { message: d } = r; return a.code === "invalid_enum_value" ? { message: d ?? o.defaultError } : typeof o.data > "u" ? { message: d ?? s ?? o.defaultError } : a.code !== "invalid_type" ? { message: o.defaultError } : { message: d ?? t ?? o.defaultError }; }, description: n }; } class x { get description() { return this._def.description; } _getType(e) { return B(e.data); } _getOrReturnCtx(e, t) { return t || { common: e.parent.common, data: e.data, parsedType: B(e.data), schemaErrorMap: this._def.errorMap, path: e.path, parent: e.parent }; } _processInputParams(e) { return { status: new N(), ctx: { common: e.parent.common, data: e.data, parsedType: B(e.data), schemaErrorMap: this._def.errorMap, path: e.path, parent: e.parent } }; } _parseSync(e) { const t = this._parse(e); if (de(t)) throw new Error("Synchronous parse encountered promise."); return t; } _parseAsync(e) { const t = this._parse(e); return Promise.resolve(t); } parse(e, t) { const s = this.safeParse(e, t); if (s.success) return s.data; throw s.error; } safeParse(e, t) { const s = { common: { issues: [], async: (t == null ? void 0 : t.async) ?? !1, contextualErrorMap: t == null ? void 0 : t.errorMap }, path: (t == null ? void 0 : t.path) || [], schemaErrorMap: this._def.errorMap, parent: null, data: e, parsedType: B(e) }, n = this._parseSync({ data: e, path: s.path, parent: s }); return ot(s, n); } "~validate"(e) { var s, n; const t = { common: { issues: [], async: !!this["~standard"].async }, path: [], schemaErrorMap: this._def.errorMap, parent: null, data: e, parsedType: B(e) }; if (!this["~standard"].async) try { const i = this._parseSync({ data: e, path: [], parent: t }); return Q(i) ? { value: i.value } : { issues: t.common.issues }; } catch (i) { (n = (s = i == null ? void 0 : i.message) == null ? void 0 : s.toLowerCase()) != null && n.includes("encountered") && (this["~standard"].async = !0), t.common = { issues: [], async: !0 }; } return this._parseAsync({ data: e, path: [], parent: t }).then((i) => Q(i) ? { value: i.value } : { issues: t.common.issues }); } async parseAsync(e, t) { const s = await this.safeParseAsync(e, t); if (s.success) return s.data; throw s.error; } async safeParseAsync(e, t) { const s = { common: { issues: [], contextualErrorMap: t == null ? void 0 : t.errorMap, async: !0 }, path: (t == null ? void 0 : t.path) || [], schemaErrorMap: this._def.errorMap, parent: null, data: e, parsedType: B(e) }, n = this._parse({ data: e, path: s.path, parent: s }), i = await (de(n) ? n : Promise.resolve(n)); return ot(s, i); } refine(e, t) { const s = (n) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(n) : t; return this._refinement((n, i) => { const a = e(n), o = () => i.addIssue({ code: l.custom, ...s(n) }); return typeof Promise < "u" && a instanceof Promise ? a.then((d) => d ? !0 : (o(), !1)) : a ? !0 : (o(), !1); }); } refinement(e, t) { return this._refinement((s, n) => e(s) ? !0 : (n.addIssue(typeof t == "function" ? t(s, n) : t), !1)); } _refinement(e) { return new H({ schema: this, typeName: g.ZodEffects, effect: { type: "refinement", refinement: e } }); } superRefine(e) { return this._refinement(e); } constructor(e) { this.spa = this.safeParseAsync, this._def = e, 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), this["~standard"] = { version: 1, vendor: "zod", validate: (t) => this["~validate"](t) }; } optional() { return L.create(this, this._def); } nullable() { return K.create(this, this._def); } nullish() { return this.nullable().optional(); } array() { return D.create(this); } promise() { return _e.create(this, this._def); } or(e) { return fe.create([this, e], this._def); } and(e) { return pe.create(this, e, this._def); } transform(e) { return new H({ ...v(this._def), schema: this, typeName: g.ZodEffects, effect: { type: "transform", transform: e } }); } default(e) { const t = typeof e == "function" ? e : () => e; return new ve({ ...v(this._def), innerType: this, defaultValue: t, typeName: g.ZodDefault }); } brand() { return new xt({ typeName: g.ZodBranded, type: this, ...v(this._def) }); } catch(e) { const t = typeof e == "function" ? e : () => e; return new xe({ ...v(this._def), innerType: this, catchValue: t, typeName: g.ZodCatch }); } describe(e) { const t = this.constructor; return new t({ ...this._def, description: e }); } pipe(e) { return Ge.create(this, e); } readonly() { return be.create(this); } isOptional() { return this.safeParse(void 0).success; } isNullable() { return this.safeParse(null).success; } } const jt = /^c[^\s-]{8,}$/i, Lt = /^[0-9a-z]+$/, Ut = /^[0-9A-HJKMNP-TV-Z]{26}$/i, Ft = /^[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, Vt = /^[a-z0-9_-]{21}$/i, Bt = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/, zt = /^[-+]?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)?)??$/, qt = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, Wt = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$"; let Pe; const Ht = /^(?:(?: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])$/, Kt = /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/, Xt = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/, Gt = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/, Yt = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, Qt = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/, yt = "((\\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])))", Jt = new RegExp(`^${yt}$`); function _t(r) { let e = "[0-5]\\d"; r.precision ? e = `${e}\\.\\d{${r.precision}}` : r.precision == null && (e = `${e}(\\.\\d+)?`); const t = r.precision ? "+" : "?"; return `([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`; } function er(r) { return new RegExp(`^${_t(r)}$`); } function tr(r) { let e = `${yt}T${_t(r)}`; const t = []; return t.push(r.local ? "Z?" : "Z"), r.offset && t.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${t.join("|")})`, new RegExp(`^${e}$`); } function rr(r, e) { return !!((e === "v4" || !e) && Ht.test(r) || (e === "v6" || !e) && Xt.test(r)); } function sr(r, e) { if (!Bt.test(r)) return !1; try { const [t] = r.split("."), s = t.replace(/-/g, "+").replace(/_/g, "/").padEnd(t.length + (4 - t.length % 4) % 4, "="), n = JSON.parse(atob(s)); return !(typeof n != "object" || n === null || "typ" in n && (n == null ? void 0 : n.typ) !== "JWT" || !n.alg || e && n.alg !== e); } catch { return !1; } } function nr(r, e) { return !!((e === "v4" || !e) && Kt.test(r) || (e === "v6" || !e) && Gt.test(r)); } class M extends x { _parse(e) { if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== p.string) { const i = this._getOrReturnCtx(e); return h(i, { code: l.invalid_type, expected: p.string, received: i.parsedType }), y; } const s = new N(); let n; for (const i of this._def.checks) if (i.kind === "min") e.data.length < i.value && (n = this._getOrReturnCtx(e, n), h(n, { code: l.too_small, minimum: i.value, type: "string", inclusive: !0, exact: !1, message: i.message }), s.dirty()); else if (i.kind === "max") e.data.length > i.value && (n = this._getOrReturnCtx(e, n), h(n, { code: l.too_big, maximum: i.value, type: "string", inclusive: !0, exact: !1, message: i.message }), s.dirty()); else if (i.kind === "length") { const a = e.data.length > i.value, o = e.data.length < i.value; (a || o) && (n = this._getOrReturnCtx(e, n), a ? h(n, { code: l.too_big, maximum: i.value, type: "string", inclusive: !0, exact: !0, message: i.message }) : o && h(n, { code: l.too_small, minimum: i.value, type: "string", inclusive: !0, exact: !0, message: i.message }), s.dirty()); } else if (i.kind === "email") qt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "email", code: l.invalid_string, message: i.message }), s.dirty()); else if (i.kind === "emoji") Pe || (Pe = new RegExp(Wt, "u")), Pe.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "emoji", code: l.invalid_string, message: i.message }), s.dirty()); else if (i.kind === "uuid") Ft.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "uuid", code: l.invalid_string, message: i.message }), s.dirty()); else if (i.kind === "nanoid") Vt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "nanoid", code: l.invalid_string, message: i.message }), s.dirty()); else if (i.kind === "cuid") jt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "cuid", code: l.invalid_string, message: i.message }), s.dirty()); else if (i.kind === "cuid2") Lt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "cuid2", code: l.invalid_string, message: i.message }), s.dirty()); else if (i.kind === "ulid") Ut.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "ulid", code: l.invalid_string, message: i.message }), s.dirty()); else if (i.kind === "url") try { new URL(e.data); } catch { n = this._getOrReturnCtx(e, n), h(n, { validation: "url", code: l.invalid_string, message: i.message }), s.dirty(); } else i.kind === "regex" ? (i.regex.lastIndex = 0, i.regex.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "regex", code: l.invalid_string, message: i.message }), s.dirty())) : i.kind === "trim" ? e.data = e.data.trim() : i.kind === "includes" ? e.data.includes(i.value, i.position) || (n = this._getOrReturnCtx(e, n), h(n, { code: l.invalid_string, validation: { includes: i.value, position: i.position }, message: i.message }), s.dirty()) : i.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : i.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : i.kind === "startsWith" ? e.data.startsWith(i.value) || (n = this._getOrReturnCtx(e, n), h(n, { code: l.invalid_string, validation: { startsWith: i.value }, message: i.message }), s.dirty()) : i.kind === "endsWith" ? e.data.endsWith(i.value) || (n = this._getOrReturnCtx(e, n), h(n, { code: l.invalid_string, validation: { endsWith: i.value }, message: i.message }), s.dirty()) : i.kind === "datetime" ? tr(i).test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { code: l.invalid_string, validation: "datetime", message: i.message }), s.dirty()) : i.kind === "date" ? Jt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { code: l.invalid_string, validation: "date", message: i.message }), s.dirty()) : i.kind === "time" ? er(i).test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { code: l.invalid_string, validation: "time", message: i.message }), s.dirty()) : i.kind === "duration" ? zt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "duration", code: l.invalid_string, message: i.message }), s.dirty()) : i.kind === "ip" ? rr(e.data, i.version) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "ip", code: l.invalid_string, message: i.message }), s.dirty()) : i.kind === "jwt" ? sr(e.data, i.alg) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "jwt", code: l.invalid_string, message: i.message }), s.dirty()) : i.kind === "cidr" ? nr(e.data, i.version) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "cidr", code: l.invalid_string, message: i.message }), s.dirty()) : i.kind === "base64" ? Yt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "base64", code: l.invalid_string, message: i.message }), s.dirty()) : i.kind === "base64url" ? Qt.test(e.data) || (n = this._getOrReturnCtx(e, n), h(n, { validation: "base64url", code: l.invalid_string, message: i.message }), s.dirty()) : O.assertNever(i); return { status: s.value, value: e.data }; } _regex(e, t, s) { return this.refinement((n) => e.test(n), { validation: t, code: l.invalid_string, ...m.errToObj(s) }); } _addCheck(e) { return new M({ ...this._def, checks: [...this._def.checks, e] }); } email(e) { return this._addCheck({ kind: "email", ...m.errToObj(e) }); } url(e) { return this._addCheck({ kind: "url", ...m.errToObj(e) }); } emoji(e) { return this._addCheck({ kind: "emoji", ...m.errToObj(e) }); } uuid(e) { return this._addCheck({ kind: "uuid", ...m.errToObj(e) }); } nanoid(e) { return this._addCheck({ kind: "nanoid", ...m.errToObj(e) }); } cuid(e) { return this._addCheck({ kind: "cuid", ...m.errToObj(e) }); } cuid2(e) { return this._addCheck({ kind: "cuid2", ...m.errToObj(e) }); } ulid(e) { return this._addCheck({ kind: "ulid", ...m.errToObj(e) }); } base64(e) { return this._addCheck({ kind: "base64", ...m.errToObj(e) }); } base64url(e) { return this._addCheck({ kind: "base64url", ...m.errToObj(e) }); } jwt(e) { return this._addCheck({ kind: "jwt", ...m.errToObj(e) }); } ip(e) { return this._addCheck({ kind: "ip", ...m.errToObj(e) }); } cidr(e) { return this._addCheck({ kind: "cidr", ...m.errToObj(e) }); } datetime(e) { return typeof e == "string" ? this._addCheck({ kind: "datetime", precision: null, offset: !1, local: !1, message: e }) : this._addCheck({ kind: "datetime", precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision, offset: (e == null ? void 0 : e.offset) ?? !1, local: (e == null ? void 0 : e.local) ?? !1, ...m.errToObj(e == null ? void 0 : e.message) }); } date(e) { return this._addCheck({ kind: "date", message: e }); } time(e) { return typeof e == "string" ? this._addCheck({ kind: "time", precision: null, message: e }) : this._addCheck({ kind: "time", precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision, ...m.errToObj(e == null ? void 0 : e.message) }); } duration(e) { return this._addCheck({ kind: "duration", ...m.errToObj(e) }); } regex(e, t) { return this._addCheck({ kind: "regex", regex: e, ...m.errToObj(t) }); } includes(e, t) { return this._addCheck({ kind: "includes", value: e, position: t == null ? void 0 : t.position, ...m.errToObj(t == null ? void 0 : t.message) }); } startsWith(e, t) { return this._addCheck({ kind: "startsWith", value: e, ...m.errToObj(t) }); } endsWith(e, t) { return this._addCheck({ kind: "endsWith", value: e, ...m.errToObj(t) }); } min(e, t) { return this._addCheck({ kind: "min", value: e, ...m.errToObj(t) }); } max(e, t) { return this._addCheck({ kind: "max", value: e, ...m.errToObj(t) }); } length(e, t) { return this._addCheck({ kind: "length", value: e, ...m.errToObj(t) }); } /** * Equivalent to `.min(1)` */ nonempty(e) { return this.min(1, m.errToObj(e)); } trim() { return new M({ ...this._def, checks: [...this._def.checks, { kind: "trim" }] }); } toLowerCase() { return new M({ ...this._def, checks: [...this._def.checks, { kind: "toLowerCase" }] }); } toUpperCase() { return new M({ ...this._def, checks: [...this._def.checks, { kind: "toUpperCase" }] }); } get isDatetime() { return !!this._def.checks.find((e) => e.kind === "datetime"); } get isDate() { return !!this._def.checks.find((e) => e.kind === "date"); } get isTime() { return !!this._def.checks.find((e) => e.kind === "time"); } get isDuration() { return !!this._def.checks.find((e) => e.kind === "duration"); } get isEmail() { return !!this._def.checks.find((e) => e.kind === "email"); } get isURL() { return !!this._def.checks.find((e) => e.kind === "url"); } get isEmoji() { return !!this._def.checks.find((e) => e.kind === "emoji"); } get isUUID() { return !!this._def.checks.find((e) => e.kind === "uuid"); } get isNANOID() { return !!this._def.checks.find((e) => e.kind === "nanoid"); } get isCUID() { return !!this._def.checks.find((e) => e.kind === "cuid"); } get isCUID2() { return !!this._def.checks.find((e) => e.kind === "cuid2"); } get isULID() { return !!this._def.checks.find((e) => e.kind === "ulid"); } get isIP() { return !!this._def.checks.find((e) => e.kind === "ip"); } get isCIDR() { return !!this._def.checks.find((e) => e.kind === "cidr"); } get isBase64() { return !!this._def.checks.find((e) => e.kind === "base64"); } get isBase64url() { return !!this._def.checks.find((e) => e.kind === "base64url"); } get minLength() { let e = null; for (const t of this._def.checks) t.kind === "min" && (e === null || t.value > e) && (e = t.value); return e; } get maxLength() { let e = null; for (const t of this._def.checks) t.kind === "max" && (e === null || t.value < e) && (e = t.value); return e; } } M.create = (r) => new M({ checks: [], typeName: g.ZodString, coerce: (r == null ? void 0 : r.coerce) ?? !1, ...v(r) }); function ir(r, e) { const t = (r.toString().split(".")[1] || "").length, s = (e.toString().split(".")[1] || "").length, n = t > s ? t : s, i = Number.parseInt(r.toFixed(n).replace(".", "")), a = Number.parseInt(e.toFixed(n).replace(".", "")); return i % a / 10 ** n; } class J extends x { constructor() { super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf; } _parse(e) { if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== p.number) { const i = this._getOrReturnCtx(e); return h(i, { code: l.invalid_type, expected: p.number, received: i.parsedType }), y; } let s; const n = new N(); for (const i of this._def.checks) i.kind === "int" ? O.isInteger(e.data) || (s = this._getOrReturnCtx(e, s), h(s, { code: l.invalid_type, expected: "integer", received: "float", message: i.message }), n.dirty()) : i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (s = this._getOrReturnCtx(e, s), h(s, { code: l.too_small, minimum: i.value, type: "number", inclusive: i.inclusive, exact: !1, message: i.message }), n.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (s = this._getOrReturnCtx(e, s), h(s, { code: l.too_big, maximum: i.value, type: "number", inclusive: i.inclusive, exact: !1, message: i.message }), n.dirty()) : i.kind === "multipleOf" ? ir(e.data, i.value) !== 0 && (s = this._getOrReturnCtx(e, s), h(s, { code: l.not_multiple_of, multipleOf: i.value, message: i.message }), n.dirty()) : i.kind === "finite" ? Number.isFinite(e.data) || (s = this._getOrReturnCtx(e, s), h(s, { code: l.not_finite, message: i.message }), n.dirty()) : O.assertNever(i); return { status: n.value, value: e.data }; } gte(e, t) { return this.setLimit("min", e, !0, m.toString(t)); } gt(e, t) { return this.setLimit("min", e, !1, m.toString(t)); } lte(e, t) { return this.setLimit("max", e, !0, m.toString(t)); } lt(e, t) { return this.setLimit("max", e, !1, m.toString(t)); } setLimit(e, t, s, n) { return new J({ ...this._def, checks: [ ...this._def.checks, { kind: e, value: t, inclusive: s, message: m.toString(n) } ] }); } _addCheck(e) { return new J({ ...this._def, checks: [...this._def.checks, e] }); } int(e) { return this._addCheck({ kind: "int", message: m.toString(e) }); } positive(e) { return this._addCheck({ kind: "min", value: 0, inclusive: !1, message: m.toString(e) }); } negative(e) { return this._addCheck({ kind: "max", value: 0, inclusive: !1, message: m.toString(e) }); } nonpositive(e) { return this._addCheck({ kind: "max", value: 0, inclusive: !0, message: m.toString(e) }); } nonnegative(e) { return this._addCheck({ kind: "min", value: 0, inclusive: !0, message: m.toString(e) }); } multipleOf(e, t) { return this._addCheck({ kind: "multipleOf", value: e, message: m.toString(t) }); } finite(e) { return this._addCheck({ kind: "finite", message: m.toString(e) }); } safe(e) { return this._addCheck({ kind: "min", inclusive: !0, value: Number.MIN_SAFE_INTEGER, message: m.toString(e) })._addCheck({ kind: "max", inclusive: !0, value: Number.MAX_SAFE_INTEGER, message: m.toString(e) }); } get minValue() { let e = null; for (const t of this._def.checks) t.kind === "min" && (e === null || t.value > e) && (e = t.value); return e; } get maxValue() { let e = null; for (const t of this._def.checks) t.kind === "max" && (e === null || t.value < e) && (e = t.value); return e; } get isInt() { return !!this._def.checks.find((e) => e.kind === "int" || e.kind === "multipleOf" && O.isInteger(e.value)); } get isFinite() { let e = null, t = null; for (const s of this._def.checks) { if (s.kind === "finite" || s.kind === "int" || s.kind === "multipleOf") return !0; s.kind === "min" ? (t === null || s.value > t) && (t = s.value) : s.kind === "max" && (e === null || s.value < e) && (e = s.value); } return Number.isFinite(t) && Number.isFinite(e); } } J.create = (r) => new J({ checks: [], typeName: g.ZodNumber, coerce: (r == null ? void 0 : r.coerce) || !1, ...v(r) }); class oe extends x { constructor() { super(...arguments), this.min = this.gte, this.max = this.lte; } _parse(e) { if (this._def.coerce) try { e.data = BigInt(e.data); } catch { return this._getInvalidInput(e); } if (this._getType(e) !== p.bigint) return this._getInvalidInput(e); let s; const n = new N(); for (const i of this._def.checks) i.kind === "min" ? (i.inclusive ? e.data < i.value : e.data <= i.value) && (s = this._getOrReturnCtx(e, s), h(s, { code: l.too_small, type: "bigint", minimum: i.value, inclusive: i.inclusive, message: i.message }), n.dirty()) : i.kind === "max" ? (i.inclusive ? e.data > i.value : e.data >= i.value) && (s = this._getOrReturnCtx(e, s), h(s, { code: l.too_big, type: "bigint", maximum: i.value, inclusive: i.inclusive, message: i.message }), n.dirty()) : i.kind === "multipleOf" ? e.data % i.value !== BigInt(0) && (s = this._getOrReturnCtx(e, s), h(s, { code: l.not_multiple_of, multipleOf: i.value, message: i.message }), n.dirty()) : O.assertNever(i); return { status: n.value, value: e.data }; } _getInvalidInput(e) { const t = this._getOrReturnCtx(e); return h(t, { code: l.invalid_type, expected: p.bigint, received: t.parsedType }), y; } gte(e, t) { return this.setLimit("min", e, !0, m.toString(t)); } gt(e, t) { return this.setLimit("min", e, !1, m.toString(t)); } lte(e, t) { return this.setLimit("max", e, !0, m.toString(t)); } lt(e, t) { return this.setLimit("max", e, !1, m.toString(t)); } setLimit(e, t, s, n) { return new oe({ ...this._def, checks: [ ...this._def.checks, { kind: e, value: t, inclusive: s, message: m.toString(n) } ] }); } _addCheck(e) { return new oe({ ...this._def, checks: [...this._def.checks, e] }); } positive(e) { return this._addCheck({ kind: "min", value: BigInt(0), inclusive: !1, message: m.toString(e) }); } negative(e) { return this._addCheck({ kind: "max", value: BigInt(0), inclusive: !1, message: m.toString(e) }); } nonpositive(e) { return this._addCheck({ kind: "max", value: BigInt(0), inclusive: !0, message: m.toString(e) }); } nonnegative(e) { return this._addCheck({ kind: "min", value: BigInt(0), inclusive: !0, message: m.toString(e) }); } multipleOf(e, t) { return this._addCheck({ kind: "multipleOf", value: e, message: m.toString(t) }); } get minValue() { let e = null; for (const t of this._def.checks) t.kind === "min" && (e === null || t.value > e) && (e = t.value); return e; } get maxValue() { let e = null; for (const t of this._def.checks) t.kind === "max" && (e === null || t.value < e) && (e = t.value); return e; } } oe.create = (r) => new oe({ checks: [], typeName: g.ZodBigInt, coerce: (r == null ? void 0 : r.coerce) ?? !1, ...v(r) }); class Me extends x { _parse(e) { if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== p.boolean) { const s = this._getOrReturnCtx(e); return h(s, { code: l.invalid_type, expected: p.boolean, received: s.parsedType }), y; } return T(e.data); } } Me.create = (r) => new Me({ typeName: g.ZodBoolean, coerce: (r == null ? void 0 : r.coerce) || !1, ...v(r) }); class he extends x { _parse(e) { if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== p.date) { const i = this._getOrReturnCtx(e); return h(i, { code: l.invalid_type, expected: p.date, received: i.parsedType }), y; } if (Number.isNaN(e.data.getTime())) { const i = this._getOrReturnCtx(e); return h(i, { code: l.invalid_date }), y; } const s = new N(); let n; for (const i of this._def.checks) i.kind === "min" ? e.data.getTime() < i.value && (n = this._getOrReturnCtx(e, n), h(n, { code: l.too_small, message: i.message, inclusive: !0, exact: !1, minimum: i.value, type: "date" }), s.dirty()) : i.kind === "max" ? e.data.getTime() > i.value && (n = this._getOrReturnCtx(e, n), h(n, { code: l.too_big, message: i.message, inclusive: !0, exact: !1, maximum: i.value, type: "date" }), s.dirty()) : O.assertNever(i); return { status: s.value, value: new Date(e.data.getTime()) }; } _addCheck(e) { return new he({ ...this._def, checks: [...this._def.checks, e] }); } min(e, t) { return this._addCheck({ kind: "min", value: e.getTime(), message: m.toString(t) }); } max(e, t) { return this._addCheck({ kind: "max", value: e.getTime(), message: m.toString(t) }); } get minDate() { let e = null; for (const t of this._def.checks) t.kind === "min" && (e === null || t.value > e) && (e = t.value); return e != null ? new Date(e) : null; } get maxDate() { let e = null; for (const t of this._def.checks) t.kind === "max" && (e === null || t.value < e) && (e = t.value); return e != null ? new Date(e) : null; } } he.create = (r) => new he({ checks: [], coerce: (r == null ? void 0 : r.coerce) || !1, typeName: g.ZodDate, ...v(r) }); class ct extends x { _parse(e) { if (this._getType(e) !== p.symbol) { const s = this._getOrReturnCtx(e); return h(s, { code: l.invalid_type, expected: p.symbol, received: s.parsedType }), y; } return T(e.data); } } ct.create = (r) => new ct({ typeName: g.ZodSymbol, ...v(r) }); class je extends x { _parse(e) { if