@vielzeug/spell 2.1.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/core.cjs.map +1 -1
  2. package/dist/core.d.ts +2 -2
  3. package/dist/core.d.ts.map +1 -1
  4. package/dist/core.js.map +1 -1
  5. package/dist/errors.cjs +1 -1
  6. package/dist/errors.cjs.map +1 -1
  7. package/dist/errors.d.ts +0 -1
  8. package/dist/errors.d.ts.map +1 -1
  9. package/dist/errors.js +1 -1
  10. package/dist/errors.js.map +1 -1
  11. package/dist/s.cjs.map +1 -1
  12. package/dist/s.d.ts +2 -2
  13. package/dist/s.d.ts.map +1 -1
  14. package/dist/s.js.map +1 -1
  15. package/dist/schemas/array.cjs.map +1 -1
  16. package/dist/schemas/array.d.ts +4 -4
  17. package/dist/schemas/array.d.ts.map +1 -1
  18. package/dist/schemas/array.js.map +1 -1
  19. package/dist/schemas/bigint.cjs.map +1 -1
  20. package/dist/schemas/bigint.d.ts +4 -4
  21. package/dist/schemas/bigint.d.ts.map +1 -1
  22. package/dist/schemas/bigint.js.map +1 -1
  23. package/dist/schemas/boolean.cjs.map +1 -1
  24. package/dist/schemas/boolean.d.ts +4 -4
  25. package/dist/schemas/boolean.d.ts.map +1 -1
  26. package/dist/schemas/boolean.js.map +1 -1
  27. package/dist/schemas/date.cjs.map +1 -1
  28. package/dist/schemas/date.d.ts +4 -4
  29. package/dist/schemas/date.d.ts.map +1 -1
  30. package/dist/schemas/date.js.map +1 -1
  31. package/dist/schemas/enum.cjs.map +1 -1
  32. package/dist/schemas/enum.d.ts +4 -4
  33. package/dist/schemas/enum.d.ts.map +1 -1
  34. package/dist/schemas/enum.js.map +1 -1
  35. package/dist/schemas/instanceof.cjs.map +1 -1
  36. package/dist/schemas/instanceof.d.ts +6 -6
  37. package/dist/schemas/instanceof.d.ts.map +1 -1
  38. package/dist/schemas/instanceof.js.map +1 -1
  39. package/dist/schemas/intersect.cjs.map +1 -1
  40. package/dist/schemas/intersect.d.ts +4 -4
  41. package/dist/schemas/intersect.d.ts.map +1 -1
  42. package/dist/schemas/intersect.js.map +1 -1
  43. package/dist/schemas/lazy.cjs.map +1 -1
  44. package/dist/schemas/lazy.d.ts +4 -4
  45. package/dist/schemas/lazy.d.ts.map +1 -1
  46. package/dist/schemas/lazy.js.map +1 -1
  47. package/dist/schemas/literal.cjs.map +1 -1
  48. package/dist/schemas/literal.d.ts +4 -4
  49. package/dist/schemas/literal.d.ts.map +1 -1
  50. package/dist/schemas/literal.js.map +1 -1
  51. package/dist/schemas/map.cjs.map +1 -1
  52. package/dist/schemas/map.d.ts +4 -4
  53. package/dist/schemas/map.d.ts.map +1 -1
  54. package/dist/schemas/map.js.map +1 -1
  55. package/dist/schemas/never.cjs.map +1 -1
  56. package/dist/schemas/never.d.ts +4 -4
  57. package/dist/schemas/never.d.ts.map +1 -1
  58. package/dist/schemas/never.js.map +1 -1
  59. package/dist/schemas/number.cjs.map +1 -1
  60. package/dist/schemas/number.d.ts +4 -4
  61. package/dist/schemas/number.d.ts.map +1 -1
  62. package/dist/schemas/number.js.map +1 -1
  63. package/dist/schemas/object.cjs +1 -1
  64. package/dist/schemas/object.cjs.map +1 -1
  65. package/dist/schemas/object.d.ts +7 -7
  66. package/dist/schemas/object.d.ts.map +1 -1
  67. package/dist/schemas/object.js +1 -1
  68. package/dist/schemas/object.js.map +1 -1
  69. package/dist/schemas/record.cjs +1 -1
  70. package/dist/schemas/record.cjs.map +1 -1
  71. package/dist/schemas/record.d.ts +4 -4
  72. package/dist/schemas/record.d.ts.map +1 -1
  73. package/dist/schemas/record.js +1 -1
  74. package/dist/schemas/record.js.map +1 -1
  75. package/dist/schemas/set.cjs.map +1 -1
  76. package/dist/schemas/set.d.ts +4 -4
  77. package/dist/schemas/set.d.ts.map +1 -1
  78. package/dist/schemas/set.js.map +1 -1
  79. package/dist/schemas/string.cjs +1 -1
  80. package/dist/schemas/string.cjs.map +1 -1
  81. package/dist/schemas/string.d.ts +4 -12
  82. package/dist/schemas/string.d.ts.map +1 -1
  83. package/dist/schemas/string.js +1 -1
  84. package/dist/schemas/string.js.map +1 -1
  85. package/dist/schemas/tuple.cjs.map +1 -1
  86. package/dist/schemas/tuple.d.ts +5 -5
  87. package/dist/schemas/tuple.d.ts.map +1 -1
  88. package/dist/schemas/tuple.js.map +1 -1
  89. package/dist/schemas/union.cjs.map +1 -1
  90. package/dist/schemas/union.d.ts +4 -4
  91. package/dist/schemas/union.d.ts.map +1 -1
  92. package/dist/schemas/union.js.map +1 -1
  93. package/dist/schemas/variant.cjs.map +1 -1
  94. package/dist/schemas/variant.d.ts +4 -4
  95. package/dist/schemas/variant.d.ts.map +1 -1
  96. package/dist/schemas/variant.js.map +1 -1
  97. package/dist/spell.cjs +2 -2
  98. package/dist/spell.cjs.map +1 -1
  99. package/dist/spell.iife.js +2 -2
  100. package/dist/spell.iife.js.map +1 -1
  101. package/dist/spell.js +2 -2
  102. package/dist/spell.js.map +1 -1
  103. package/package.json +2 -1
  104. package/dist/schemas/pipe.d.ts +0 -2
  105. package/dist/schemas/pipe.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"union.js","names":[],"sources":["../../src/schemas/union.ts"],"sourcesContent":["import type { AnySchema, InferOutput, Issue, ParseContext, ParseValue, SchemaDescriptor } from '../core';\n\nimport { _makeCtx, ErrorCode, Schema, SpellValidationError } from '../core';\n\nexport class UnionSchema<\n T extends readonly AnySchema[],\n Mode extends import('../core').SchemaMode = import('../core').MergeSchemaModes<\n import('../core').InferSchemaMode<T[number]>\n >,\n> extends Schema<InferOutput<T[number]>, unknown, Mode> {\n readonly schemas: T;\n\n protected override get _kind(): string {\n return 'union';\n }\n\n override checkAsync(\n this: UnionSchema<T, 'sync'>,\n fn: (\n value: InferOutput<T[number]>,\n ctx: import('../core').CheckContext,\n ) => Promise<import('../core').ValidateResult>,\n ): UnionSchema<T, 'async'> {\n return this._addCheck(fn, true) as unknown as UnionSchema<T, 'async'>;\n }\n\n constructor(schemas: T) {\n super();\n this.schemas = Object.freeze([...schemas]) as T;\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): ParseValue | Promise<ParseValue> {\n const branchErrors: Issue[][] = [];\n\n for (const schema of this.schemas) {\n const result = schema._parseFullSync(value, ctx);\n\n if (result.issues.length === 0) return { data: result.data, issues: [], typeOk: true };\n\n branchErrors.push(result.issues);\n }\n\n return {\n data: value,\n issues: [\n {\n code: ErrorCode.invalid_union,\n message: ctx.messages.union.invalid(),\n params: { errors: branchErrors },\n path: [],\n },\n ],\n typeOk: false,\n };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferOutput<T[number]>> {\n const c = ctx ?? _makeCtx();\n\n return this._withCatchAsync(async () => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as InferOutput<T[number]>;\n\n const v = prepared.value;\n\n const branchErrors: Issue[][] = [];\n\n for (const schema of this.schemas) {\n const result = await schema._parseFullAsync(v, c);\n\n if (result.issues.length > 0) {\n branchErrors.push(result.issues);\n continue;\n }\n\n const validationIssues = await this._runValidatorsAsync(result.data, c);\n\n if (validationIssues.length > 0) throw new SpellValidationError(validationIssues);\n\n return this._runPostprocessors(result.data) as InferOutput<T[number]>;\n }\n\n throw new SpellValidationError([\n {\n code: ErrorCode.invalid_union,\n message: c.messages.union.invalid(),\n params: { errors: branchErrors },\n path: [],\n },\n ]);\n });\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n return { ...this._describeBase(), branches: this.schemas.map((s) => s.definition()), kind: 'union' };\n }\n\n protected override _walk<R>(visitor: import('../core').SchemaWalker<R>): R | null {\n const branches = this.schemas.map((s) => s.walk(visitor));\n\n if (visitor.union) return visitor.union(this, branches);\n\n return super._walk(visitor);\n }\n}\n"],"mappings":"8IAIA,IAAa,EAAb,cAKU,CAA8C,CACtD,QAEA,IAAuB,OAAgB,CACrC,MAAO,OACT,CAEA,WAEE,EAIyB,CACzB,OAA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Aa,EAC/B,KAAM,CAAC,CACT,CACF,CAAC,CACH,CAAC,CACH,CAEA,mBAAyD,CACvD,MAAO,CAAE,GAAG,KAAK,cAAc,EAAG,SAAU,KAAK,QAAQ,IAAK,GAAM,EAAE,WAAW,CAAC,EAAG,KAAM,OAAQ,CACrG,CAEA,MAA4B,EAAsD,CAChF,IAAM,EAAW,KAAK,QAAQ,IAAK,GAAM,EAAE,KAAK,CAAO,CAAC,EAIxD,OAFI,EAAQ,MAAc,EAAQ,MAAM,KAAM,CAAQ,EAE/C,MAAM,MAAM,CAAO,CAC5B,CACF"}
1
+ {"version":3,"file":"union.js","names":[],"sources":["../../src/schemas/union.ts"],"sourcesContent":["import type {\n AnySchema,\n CheckContext,\n InferOutput,\n InferSchemaMode,\n Issue,\n MergeSchemaModes,\n ParseContext,\n ParseValue,\n SchemaDescriptor,\n SchemaMode,\n SchemaWalker,\n ValidateResult,\n} from '../core';\n\nimport { _makeCtx, ErrorCode, Schema, SpellValidationError } from '../core';\n\nexport class UnionSchema<\n T extends readonly AnySchema[],\n Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<T[number]>>,\n> extends Schema<InferOutput<T[number]>, unknown, Mode> {\n readonly schemas: T;\n\n protected override get _kind(): string {\n return 'union';\n }\n\n override checkAsync(\n this: UnionSchema<T, 'sync'>,\n fn: (value: InferOutput<T[number]>, ctx: CheckContext) => Promise<ValidateResult>,\n ): UnionSchema<T, 'async'> {\n return this._addCheck(fn, true) as unknown as UnionSchema<T, 'async'>;\n }\n\n constructor(schemas: T) {\n super();\n this.schemas = Object.freeze([...schemas]) as T;\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): ParseValue | Promise<ParseValue> {\n const branchErrors: Issue[][] = [];\n\n for (const schema of this.schemas) {\n const result = schema._parseFullSync(value, ctx);\n\n if (result.issues.length === 0) return { data: result.data, issues: [], typeOk: true };\n\n branchErrors.push(result.issues);\n }\n\n return {\n data: value,\n issues: [\n {\n code: ErrorCode.invalid_union,\n message: ctx.messages.union.invalid(),\n params: { errors: branchErrors },\n path: [],\n },\n ],\n typeOk: false,\n };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferOutput<T[number]>> {\n const c = ctx ?? _makeCtx();\n\n return this._withCatchAsync(async () => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as InferOutput<T[number]>;\n\n const v = prepared.value;\n\n const branchErrors: Issue[][] = [];\n\n for (const schema of this.schemas) {\n const result = await schema._parseFullAsync(v, c);\n\n if (result.issues.length > 0) {\n branchErrors.push(result.issues);\n continue;\n }\n\n const validationIssues = await this._runValidatorsAsync(result.data, c);\n\n if (validationIssues.length > 0) throw new SpellValidationError(validationIssues);\n\n return this._runPostprocessors(result.data) as InferOutput<T[number]>;\n }\n\n throw new SpellValidationError([\n {\n code: ErrorCode.invalid_union,\n message: c.messages.union.invalid(),\n params: { errors: branchErrors },\n path: [],\n },\n ]);\n });\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n return { ...this._describeBase(), branches: this.schemas.map((s) => s.definition()), kind: 'union' };\n }\n\n protected override _walk<R>(visitor: SchemaWalker<R>): R | null {\n const branches = this.schemas.map((s) => s.walk(visitor));\n\n if (visitor.union) return visitor.union(this, branches);\n\n return super._walk(visitor);\n }\n}\n"],"mappings":"8IAiBA,IAAa,EAAb,cAGU,CAA8C,CACtD,QAEA,IAAuB,OAAgB,CACrC,MAAO,OACT,CAEA,WAEE,EACyB,CACzB,OAAO,KAAK,UAAU,EAAI,EAAI,CAChC,CAEA,YAAY,EAAY,CACtB,MAAM,EACN,KAAK,QAAU,OAAO,OAAO,CAAC,GAAG,CAAO,CAAC,CAC3C,CAEA,OAA0B,EAAgB,EAAqD,CAC7F,IAAM,EAA0B,CAAC,EAEjC,IAAK,IAAM,KAAU,KAAK,QAAS,CACjC,IAAM,EAAS,EAAO,eAAe,EAAO,CAAG,EAE/C,GAAI,EAAO,OAAO,SAAW,EAAG,MAAO,CAAE,KAAM,EAAO,KAAM,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Q,EAE/C,MAAM,MAAM,CAAO,CAC5B,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"variant.cjs","names":[],"sources":["../../src/schemas/variant.ts"],"sourcesContent":["import type { AnySchema, Issue, ParseContext, ParseValue, SchemaDescriptor } from '../core';\n\nimport { _makeCtx, ErrorCode, Schema, SpellValidationError } from '../core';\nimport { SpellError } from '../errors';\nimport { defineOwnProperty, objectFromEntries } from '../safe-object';\nimport { LiteralSchema } from './literal';\nimport type { InferObject, ObjectSchema, ObjectShape } from './object';\n\ntype VariantMap = Record<string, ObjectSchema<any, any>>;\ntype InferVariantMap<K extends string, M extends VariantMap> = {\n [Tag in keyof M & string]: M[Tag] extends { shape: infer S extends ObjectShape }\n ? InferObject<S> & { [P in K]: Tag }\n : never;\n}[keyof M & string];\n\nexport class VariantSchema<\n K extends string,\n M extends VariantMap,\n Mode extends import('../core').SchemaMode = import('../core').MergeSchemaModes<\n import('../core').InferSchemaMode<M[keyof M]>\n >,\n> extends Schema<InferVariantMap<K, M>, unknown, Mode> {\n private readonly _map: Map<string, VariantMap[string]>;\n private readonly _discriminator: K;\n\n protected override get _kind(): string {\n return 'variant';\n }\n\n override checkAsync(\n this: VariantSchema<K, M, 'sync'>,\n fn: (\n value: InferVariantMap<K, M>,\n ctx: import('../core').CheckContext,\n ) => Promise<import('../core').ValidateResult>,\n ): VariantSchema<K, M, 'async'> {\n return this._addCheck(fn, true) as unknown as VariantSchema<K, M, 'async'>;\n }\n\n constructor(discriminator: K, variantMap: M) {\n const map = new Map<string, VariantMap[string]>();\n\n for (const [tag, schema] of Object.entries(variantMap)) {\n const discriminatorSchema = new LiteralSchema(tag);\n const existingDiscriminator = schema.shape[discriminator];\n\n if (\n existingDiscriminator &&\n (!(existingDiscriminator instanceof LiteralSchema) || existingDiscriminator.value !== tag)\n ) {\n throw new SpellError(\n `s.discriminatedUnion(): branch \"${tag}\" defines a conflicting discriminator schema for \"${discriminator}\".`,\n );\n }\n\n const discriminatorShape = {\n [discriminator]: discriminatorSchema,\n } as unknown as Record<K, AnySchema>;\n\n map.set(tag, existingDiscriminator ? schema : schema.extend(discriminatorShape));\n }\n\n super();\n this._discriminator = discriminator;\n this._map = map;\n }\n\n /** The discriminator field key used to select the matching variant. */\n get discriminator(): K {\n return this._discriminator;\n }\n\n /** Map from discriminator tag value to the extended ObjectSchema for that variant. */\n get variantMap(): ReadonlyMap<string, VariantMap[string]> {\n return new Map(this._map);\n }\n\n private _resolveVariant(\n value: unknown,\n ctx: ParseContext,\n ): { matched: VariantMap[string]; obj: Record<string, unknown> } | { issues: Issue[] } {\n if (value == null || typeof value !== 'object' || Array.isArray(value)) {\n return {\n issues: [{ code: ErrorCode.invalid_type, message: ctx.messages.variant.type(), path: [] }],\n };\n }\n\n const obj = value as Record<string, unknown>;\n const discValue = obj[this._discriminator] as string;\n const matched = this._map.get(discValue);\n\n if (!matched) {\n const expected = [...this._map.keys()];\n\n return {\n issues: [\n {\n code: ErrorCode.invalid_variant,\n message: ctx.messages.variant.invalidDiscriminator({\n discriminator: this._discriminator,\n expected,\n }),\n params: { discriminator: this._discriminator, expected },\n path: [],\n },\n ],\n };\n }\n\n return { matched, obj };\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): ParseValue {\n const resolved = this._resolveVariant(value, ctx);\n\n if ('issues' in resolved) return { data: value, issues: resolved.issues, typeOk: false };\n\n const result = resolved.matched._parseFullSync(value, ctx);\n\n return result.issues.length === 0\n ? { data: result.data, issues: [], typeOk: true }\n : { data: value, issues: result.issues, typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferVariantMap<K, M>> {\n const c = ctx ?? _makeCtx();\n\n return this._withCatchAsync(async () => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as unknown as InferVariantMap<K, M>;\n\n const resolved = this._resolveVariant(prepared.value, c);\n\n if ('issues' in resolved) throw new SpellValidationError(resolved.issues);\n\n const branch = await resolved.matched.safeParseAsync(prepared.value, c);\n\n if (!branch.success) throw branch.error;\n\n const validationIssues = await this._runValidatorsAsync(branch.data, c);\n\n if (validationIssues.length > 0) throw new SpellValidationError(validationIssues);\n\n return this._runPostprocessors(branch.data) as InferVariantMap<K, M>;\n });\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n const branches: Record<string, SchemaDescriptor> = {};\n\n for (const [key, schema] of this._map.entries()) {\n defineOwnProperty(branches, key, schema.definition());\n }\n\n return { ...this._describeBase(), branches, discriminator: this._discriminator, kind: 'variant' };\n }\n\n protected override _walk<R>(visitor: import('../core').SchemaWalker<R>): R | null {\n const branches = objectFromEntries([...this._map.entries()].map(([k, s]) => [k, s.walk(visitor)]));\n\n if (visitor.variant) return visitor.variant(this, branches);\n\n return super._walk(visitor);\n }\n}\n"],"mappings":"+IAeA,IAAa,EAAb,cAMU,EAAA,MAA6C,CACrD,KACA,eAEA,IAAuB,OAAgB,CACrC,MAAO,SACT,CAEA,WAEE,EAI8B,CAC9B,OAAO,KAAK,UAAU,EAAI,EAAI,CAChC,CAEA,YAAY,EAAkB,EAAe,CAC3C,IAAM,EAAM,IAAI,IAEhB,IAAK,GAAM,CAAC,EAAK,KAAW,OAAO,QAAQ,CAAU,EAAG,CACtD,IAAM,EAAsB,IAAI,EAAA,cAAc,CAAG,EAC3C,EAAwB,EAAO,MAAM,GAE3C,GACE,IACC,EAAE,aAAiC,EAAA,gBAAkB,EAAsB,QAAU,GAEtF,MAAM,IAAI,EAAA,WACR,mCAAmC,EAAI,oDAAoD,EAAc,GAC3G,EAGF,IAAM,EAAqB,EACxB,GAAgB,CACnB,EAEA,EAAI,IAAI,EAAK,EAAwB,EAAS,EAAO,OAAO,CAAkB,CAAC,CACjF,CAEA,MAAM,EACN,KAAK,eAAiB,EACtB,KAAK,KAAO,CACd,CAGA,IAAI,eAAmB,CACrB,OAAO,KAAK,cACd,CAGA,IAAI,YAAsD,CACxD,OAAO,IAAI,IAAI,KAAK,IAAI,CAC1B,CAEA,gBACE,EACA,EACqF,CACrF,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AS,MAAM,EAExE,IAAM,EAAS,MAAM,EAAS,QAAQ,eAAe,EAAS,MAAO,CAAC,EAEtE,GAAI,CAAC,EAAO,QAAS,MAAM,EAAO,MAElC,IAAM,EAAmB,MAAM,KAAK,oBAAoB,EAAO,KAAM,CAAC,EAEtE,GAAI,EAAiB,OAAS,EAAG,MAAM,IAAI,EAAA,qBAAqB,CAAgB,EAEhF,OAAO,KAAK,mBAAmB,EAAO,IAAI,CAC5C,CAAC,CACH,CAEA,mBAAyD,CACvD,IAAM,EAA6C,CAAC,EAEpD,IAAK,GAAM,CAAC,EAAK,KAAW,KAAK,KAAK,QAAQ,EAC5C,EAAA,kBAAkB,EAAU,EAAK,EAAO,WAAW,CAAC,EAGtD,MAAO,CAAE,GAAG,KAAK,cAAc,EAAG,WAAU,cAAe,KAAK,eAAgB,KAAM,SAAU,CAClG,CAEA,MAA4B,EAAsD,CAChF,IAAM,EAAW,EAAA,kBAAkB,CAAC,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,KAAK,CAAO,CAAC,CAAC,CAAC,EAIjG,OAFI,EAAQ,QAAgB,EAAQ,QAAQ,KAAM,CAAQ,EAEnD,MAAM,MAAM,CAAO,CAC5B,CACF"}
1
+ {"version":3,"file":"variant.cjs","names":[],"sources":["../../src/schemas/variant.ts"],"sourcesContent":["import type {\n AnySchema,\n CheckContext,\n InferSchemaMode,\n Issue,\n MergeSchemaModes,\n ParseContext,\n ParseValue,\n SchemaDescriptor,\n SchemaMode,\n SchemaWalker,\n ValidateResult,\n} from '../core';\n\nimport { _makeCtx, ErrorCode, Schema, SpellValidationError } from '../core';\nimport { SpellError } from '../errors';\nimport { defineOwnProperty, objectFromEntries } from '../safe-object';\nimport { LiteralSchema } from './literal';\nimport type { InferObject, ObjectSchema, ObjectShape } from './object';\n\ntype VariantMap = Record<string, ObjectSchema<any, any>>;\ntype InferVariantMap<K extends string, M extends VariantMap> = {\n [Tag in keyof M & string]: M[Tag] extends { shape: infer S extends ObjectShape }\n ? InferObject<S> & { [P in K]: Tag }\n : never;\n}[keyof M & string];\n\nexport class VariantSchema<\n K extends string,\n M extends VariantMap,\n Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<M[keyof M]>>,\n> extends Schema<InferVariantMap<K, M>, unknown, Mode> {\n private readonly _map: Map<string, VariantMap[string]>;\n private readonly _discriminator: K;\n\n protected override get _kind(): string {\n return 'variant';\n }\n\n override checkAsync(\n this: VariantSchema<K, M, 'sync'>,\n fn: (value: InferVariantMap<K, M>, ctx: CheckContext) => Promise<ValidateResult>,\n ): VariantSchema<K, M, 'async'> {\n return this._addCheck(fn, true) as unknown as VariantSchema<K, M, 'async'>;\n }\n\n constructor(discriminator: K, variantMap: M) {\n const map = new Map<string, VariantMap[string]>();\n\n for (const [tag, schema] of Object.entries(variantMap)) {\n const discriminatorSchema = new LiteralSchema(tag);\n const existingDiscriminator = schema.shape[discriminator];\n\n if (\n existingDiscriminator &&\n (!(existingDiscriminator instanceof LiteralSchema) || existingDiscriminator.value !== tag)\n ) {\n throw new SpellError(\n `s.discriminatedUnion(): branch \"${tag}\" defines a conflicting discriminator schema for \"${discriminator}\".`,\n );\n }\n\n const discriminatorShape = {\n [discriminator]: discriminatorSchema,\n } as unknown as Record<K, AnySchema>;\n\n map.set(tag, existingDiscriminator ? schema : schema.extend(discriminatorShape));\n }\n\n super();\n this._discriminator = discriminator;\n this._map = map;\n }\n\n /** The discriminator field key used to select the matching variant. */\n get discriminator(): K {\n return this._discriminator;\n }\n\n /** Map from discriminator tag value to the extended ObjectSchema for that variant. */\n get variantMap(): ReadonlyMap<string, VariantMap[string]> {\n return new Map(this._map);\n }\n\n private _resolveVariant(\n value: unknown,\n ctx: ParseContext,\n ): { matched: VariantMap[string]; obj: Record<string, unknown> } | { issues: Issue[] } {\n if (value == null || typeof value !== 'object' || Array.isArray(value)) {\n return {\n issues: [{ code: ErrorCode.invalid_type, message: ctx.messages.variant.type(), path: [] }],\n };\n }\n\n const obj = value as Record<string, unknown>;\n const discValue = obj[this._discriminator] as string;\n const matched = this._map.get(discValue);\n\n if (!matched) {\n const expected = [...this._map.keys()];\n\n return {\n issues: [\n {\n code: ErrorCode.invalid_variant,\n message: ctx.messages.variant.invalidDiscriminator({\n discriminator: this._discriminator,\n expected,\n }),\n params: { discriminator: this._discriminator, expected },\n path: [],\n },\n ],\n };\n }\n\n return { matched, obj };\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): ParseValue {\n const resolved = this._resolveVariant(value, ctx);\n\n if ('issues' in resolved) return { data: value, issues: resolved.issues, typeOk: false };\n\n const result = resolved.matched._parseFullSync(value, ctx);\n\n return result.issues.length === 0\n ? { data: result.data, issues: [], typeOk: true }\n : { data: value, issues: result.issues, typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferVariantMap<K, M>> {\n const c = ctx ?? _makeCtx();\n\n return this._withCatchAsync(async () => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as unknown as InferVariantMap<K, M>;\n\n const resolved = this._resolveVariant(prepared.value, c);\n\n if ('issues' in resolved) throw new SpellValidationError(resolved.issues);\n\n const branch = await resolved.matched.safeParseAsync(prepared.value, c);\n\n if (!branch.success) throw branch.error;\n\n const validationIssues = await this._runValidatorsAsync(branch.data, c);\n\n if (validationIssues.length > 0) throw new SpellValidationError(validationIssues);\n\n return this._runPostprocessors(branch.data) as InferVariantMap<K, M>;\n });\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n const branches: Record<string, SchemaDescriptor> = {};\n\n for (const [key, schema] of this._map.entries()) {\n defineOwnProperty(branches, key, schema.definition());\n }\n\n return { ...this._describeBase(), branches, discriminator: this._discriminator, kind: 'variant' };\n }\n\n protected override _walk<R>(visitor: SchemaWalker<R>): R | null {\n const branches = objectFromEntries([...this._map.entries()].map(([k, s]) => [k, s.walk(visitor)]));\n\n if (visitor.variant) return visitor.variant(this, branches);\n\n return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MAAO,CAAE,GAAG,KAAK,cAAc,EAAG,WAAU,cAAe,KAAK,eAAgB,KAAM,SAAU,CAClG,CAEA,MAA4B,EAAoC,CAC9D,IAAM,EAAW,EAAA,kBAAkB,CAAC,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,KAAK,CAAO,CAAC,CAAC,CAAC,EAIjG,OAFI,EAAQ,QAAgB,EAAQ,QAAQ,KAAM,CAAQ,EAEnD,MAAM,MAAM,CAAO,CAC5B,CACF"}
@@ -1,4 +1,4 @@
1
- import type { ParseContext, ParseValue, SchemaDescriptor } from '../core';
1
+ import type { CheckContext, InferSchemaMode, MergeSchemaModes, ParseContext, ParseValue, SchemaDescriptor, SchemaMode, SchemaWalker, ValidateResult } from '../core';
2
2
  import { Schema } from '../core';
3
3
  import type { InferObject, ObjectSchema, ObjectShape } from './object';
4
4
  type VariantMap = Record<string, ObjectSchema<any, any>>;
@@ -9,11 +9,11 @@ type InferVariantMap<K extends string, M extends VariantMap> = {
9
9
  [P in K]: Tag;
10
10
  } : never;
11
11
  }[keyof M & string];
12
- export declare class VariantSchema<K extends string, M extends VariantMap, Mode extends import('../core').SchemaMode = import('../core').MergeSchemaModes<import('../core').InferSchemaMode<M[keyof M]>>> extends Schema<InferVariantMap<K, M>, unknown, Mode> {
12
+ export declare class VariantSchema<K extends string, M extends VariantMap, Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<M[keyof M]>>> extends Schema<InferVariantMap<K, M>, unknown, Mode> {
13
13
  private readonly _map;
14
14
  private readonly _discriminator;
15
15
  protected get _kind(): string;
16
- checkAsync(this: VariantSchema<K, M, 'sync'>, fn: (value: InferVariantMap<K, M>, ctx: import('../core').CheckContext) => Promise<import('../core').ValidateResult>): VariantSchema<K, M, 'async'>;
16
+ checkAsync(this: VariantSchema<K, M, 'sync'>, fn: (value: InferVariantMap<K, M>, ctx: CheckContext) => Promise<ValidateResult>): VariantSchema<K, M, 'async'>;
17
17
  constructor(discriminator: K, variantMap: M);
18
18
  /** The discriminator field key used to select the matching variant. */
19
19
  get discriminator(): K;
@@ -23,7 +23,7 @@ export declare class VariantSchema<K extends string, M extends VariantMap, Mode
23
23
  protected _parse(value: unknown, ctx: ParseContext): ParseValue;
24
24
  parseAsync(value: unknown, ctx?: ParseContext): Promise<InferVariantMap<K, M>>;
25
25
  protected _toDescriptorImpl(): SchemaDescriptor;
26
- protected _walk<R>(visitor: import('../core').SchemaWalker<R>): R | null;
26
+ protected _walk<R>(visitor: SchemaWalker<R>): R | null;
27
27
  }
28
28
  export {};
29
29
  //# sourceMappingURL=variant.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variant.d.ts","sourceRoot":"","sources":["../../src/schemas/variant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE5F,OAAO,EAAuB,MAAM,EAAwB,MAAM,SAAS,CAAC;AAI5E,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACzD,KAAK,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,UAAU,IAAI;KAC5D,GAAG,IAAI,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS;QAAE,KAAK,EAAE,MAAM,CAAC,SAAS,WAAW,CAAA;KAAE,GAC5E,WAAW,CAAC,CAAC,CAAC,GAAG;SAAG,CAAC,IAAI,CAAC,GAAG,GAAG;KAAE,GAClC,KAAK;CACV,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;AAEpB,qBAAa,aAAa,CACxB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,UAAU,EACpB,IAAI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,EAAE,CAAC,EAAE,MAAM,CAAC,EACjC,EAAE,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,cAAc,CAAC,GAC/E,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC;gBAInB,aAAa,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC;IA4B3C,uEAAuE;IACvE,IAAI,aAAa,IAAI,CAAC,CAErB;IAED,sFAAsF;IACtF,IAAI,UAAU,IAAI,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAExD;IAED,OAAO,CAAC,eAAe;cAmCJ,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,GAAG,UAAU;IAYzD,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;cAwB1E,iBAAiB,IAAI,gBAAgB;cAUrC,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI;CAOhE"}
@@ -1 +1 @@
1
- {"version":3,"file":"variant.js","names":[],"sources":["../../src/schemas/variant.ts"],"sourcesContent":["import type { AnySchema, Issue, ParseContext, ParseValue, SchemaDescriptor } from '../core';\n\nimport { _makeCtx, ErrorCode, Schema, SpellValidationError } from '../core';\nimport { SpellError } from '../errors';\nimport { defineOwnProperty, objectFromEntries } from '../safe-object';\nimport { LiteralSchema } from './literal';\nimport type { InferObject, ObjectSchema, ObjectShape } from './object';\n\ntype VariantMap = Record<string, ObjectSchema<any, any>>;\ntype InferVariantMap<K extends string, M extends VariantMap> = {\n [Tag in keyof M & string]: M[Tag] extends { shape: infer S extends ObjectShape }\n ? InferObject<S> & { [P in K]: Tag }\n : never;\n}[keyof M & string];\n\nexport class VariantSchema<\n K extends string,\n M extends VariantMap,\n Mode extends import('../core').SchemaMode = import('../core').MergeSchemaModes<\n import('../core').InferSchemaMode<M[keyof M]>\n >,\n> extends Schema<InferVariantMap<K, M>, unknown, Mode> {\n private readonly _map: Map<string, VariantMap[string]>;\n private readonly _discriminator: K;\n\n protected override get _kind(): string {\n return 'variant';\n }\n\n override checkAsync(\n this: VariantSchema<K, M, 'sync'>,\n fn: (\n value: InferVariantMap<K, M>,\n ctx: import('../core').CheckContext,\n ) => Promise<import('../core').ValidateResult>,\n ): VariantSchema<K, M, 'async'> {\n return this._addCheck(fn, true) as unknown as VariantSchema<K, M, 'async'>;\n }\n\n constructor(discriminator: K, variantMap: M) {\n const map = new Map<string, VariantMap[string]>();\n\n for (const [tag, schema] of Object.entries(variantMap)) {\n const discriminatorSchema = new LiteralSchema(tag);\n const existingDiscriminator = schema.shape[discriminator];\n\n if (\n existingDiscriminator &&\n (!(existingDiscriminator instanceof LiteralSchema) || existingDiscriminator.value !== tag)\n ) {\n throw new SpellError(\n `s.discriminatedUnion(): branch \"${tag}\" defines a conflicting discriminator schema for \"${discriminator}\".`,\n );\n }\n\n const discriminatorShape = {\n [discriminator]: discriminatorSchema,\n } as unknown as Record<K, AnySchema>;\n\n map.set(tag, existingDiscriminator ? schema : schema.extend(discriminatorShape));\n }\n\n super();\n this._discriminator = discriminator;\n this._map = map;\n }\n\n /** The discriminator field key used to select the matching variant. */\n get discriminator(): K {\n return this._discriminator;\n }\n\n /** Map from discriminator tag value to the extended ObjectSchema for that variant. */\n get variantMap(): ReadonlyMap<string, VariantMap[string]> {\n return new Map(this._map);\n }\n\n private _resolveVariant(\n value: unknown,\n ctx: ParseContext,\n ): { matched: VariantMap[string]; obj: Record<string, unknown> } | { issues: Issue[] } {\n if (value == null || typeof value !== 'object' || Array.isArray(value)) {\n return {\n issues: [{ code: ErrorCode.invalid_type, message: ctx.messages.variant.type(), path: [] }],\n };\n }\n\n const obj = value as Record<string, unknown>;\n const discValue = obj[this._discriminator] as string;\n const matched = this._map.get(discValue);\n\n if (!matched) {\n const expected = [...this._map.keys()];\n\n return {\n issues: [\n {\n code: ErrorCode.invalid_variant,\n message: ctx.messages.variant.invalidDiscriminator({\n discriminator: this._discriminator,\n expected,\n }),\n params: { discriminator: this._discriminator, expected },\n path: [],\n },\n ],\n };\n }\n\n return { matched, obj };\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): ParseValue {\n const resolved = this._resolveVariant(value, ctx);\n\n if ('issues' in resolved) return { data: value, issues: resolved.issues, typeOk: false };\n\n const result = resolved.matched._parseFullSync(value, ctx);\n\n return result.issues.length === 0\n ? { data: result.data, issues: [], typeOk: true }\n : { data: value, issues: result.issues, typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferVariantMap<K, M>> {\n const c = ctx ?? _makeCtx();\n\n return this._withCatchAsync(async () => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as unknown as InferVariantMap<K, M>;\n\n const resolved = this._resolveVariant(prepared.value, c);\n\n if ('issues' in resolved) throw new SpellValidationError(resolved.issues);\n\n const branch = await resolved.matched.safeParseAsync(prepared.value, c);\n\n if (!branch.success) throw branch.error;\n\n const validationIssues = await this._runValidatorsAsync(branch.data, c);\n\n if (validationIssues.length > 0) throw new SpellValidationError(validationIssues);\n\n return this._runPostprocessors(branch.data) as InferVariantMap<K, M>;\n });\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n const branches: Record<string, SchemaDescriptor> = {};\n\n for (const [key, schema] of this._map.entries()) {\n defineOwnProperty(branches, key, schema.definition());\n }\n\n return { ...this._describeBase(), branches, discriminator: this._discriminator, kind: 'variant' };\n }\n\n protected override _walk<R>(visitor: import('../core').SchemaWalker<R>): R | null {\n const branches = objectFromEntries([...this._map.entries()].map(([k, s]) => [k, s.walk(visitor)]));\n\n if (visitor.variant) return visitor.variant(this, branches);\n\n return super._walk(visitor);\n }\n}\n"],"mappings":"wRAeA,IAAa,EAAb,cAMU,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kB,CAAC,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,KAAK,CAAO,CAAC,CAAC,CAAC,EAIjG,OAFI,EAAQ,QAAgB,EAAQ,QAAQ,KAAM,CAAQ,EAEnD,MAAM,MAAM,CAAO,CAC5B,CACF"}
1
+ {"version":3,"file":"variant.js","names":[],"sources":["../../src/schemas/variant.ts"],"sourcesContent":["import type {\n AnySchema,\n CheckContext,\n InferSchemaMode,\n Issue,\n MergeSchemaModes,\n ParseContext,\n ParseValue,\n SchemaDescriptor,\n SchemaMode,\n SchemaWalker,\n ValidateResult,\n} from '../core';\n\nimport { _makeCtx, ErrorCode, Schema, SpellValidationError } from '../core';\nimport { SpellError } from '../errors';\nimport { defineOwnProperty, objectFromEntries } from '../safe-object';\nimport { LiteralSchema } from './literal';\nimport type { InferObject, ObjectSchema, ObjectShape } from './object';\n\ntype VariantMap = Record<string, ObjectSchema<any, any>>;\ntype InferVariantMap<K extends string, M extends VariantMap> = {\n [Tag in keyof M & string]: M[Tag] extends { shape: infer S extends ObjectShape }\n ? InferObject<S> & { [P in K]: Tag }\n : never;\n}[keyof M & string];\n\nexport class VariantSchema<\n K extends string,\n M extends VariantMap,\n Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<M[keyof M]>>,\n> extends Schema<InferVariantMap<K, M>, unknown, Mode> {\n private readonly _map: Map<string, VariantMap[string]>;\n private readonly _discriminator: K;\n\n protected override get _kind(): string {\n return 'variant';\n }\n\n override checkAsync(\n this: VariantSchema<K, M, 'sync'>,\n fn: (value: InferVariantMap<K, M>, ctx: CheckContext) => Promise<ValidateResult>,\n ): VariantSchema<K, M, 'async'> {\n return this._addCheck(fn, true) as unknown as VariantSchema<K, M, 'async'>;\n }\n\n constructor(discriminator: K, variantMap: M) {\n const map = new Map<string, VariantMap[string]>();\n\n for (const [tag, schema] of Object.entries(variantMap)) {\n const discriminatorSchema = new LiteralSchema(tag);\n const existingDiscriminator = schema.shape[discriminator];\n\n if (\n existingDiscriminator &&\n (!(existingDiscriminator instanceof LiteralSchema) || existingDiscriminator.value !== tag)\n ) {\n throw new SpellError(\n `s.discriminatedUnion(): branch \"${tag}\" defines a conflicting discriminator schema for \"${discriminator}\".`,\n );\n }\n\n const discriminatorShape = {\n [discriminator]: discriminatorSchema,\n } as unknown as Record<K, AnySchema>;\n\n map.set(tag, existingDiscriminator ? schema : schema.extend(discriminatorShape));\n }\n\n super();\n this._discriminator = discriminator;\n this._map = map;\n }\n\n /** The discriminator field key used to select the matching variant. */\n get discriminator(): K {\n return this._discriminator;\n }\n\n /** Map from discriminator tag value to the extended ObjectSchema for that variant. */\n get variantMap(): ReadonlyMap<string, VariantMap[string]> {\n return new Map(this._map);\n }\n\n private _resolveVariant(\n value: unknown,\n ctx: ParseContext,\n ): { matched: VariantMap[string]; obj: Record<string, unknown> } | { issues: Issue[] } {\n if (value == null || typeof value !== 'object' || Array.isArray(value)) {\n return {\n issues: [{ code: ErrorCode.invalid_type, message: ctx.messages.variant.type(), path: [] }],\n };\n }\n\n const obj = value as Record<string, unknown>;\n const discValue = obj[this._discriminator] as string;\n const matched = this._map.get(discValue);\n\n if (!matched) {\n const expected = [...this._map.keys()];\n\n return {\n issues: [\n {\n code: ErrorCode.invalid_variant,\n message: ctx.messages.variant.invalidDiscriminator({\n discriminator: this._discriminator,\n expected,\n }),\n params: { discriminator: this._discriminator, expected },\n path: [],\n },\n ],\n };\n }\n\n return { matched, obj };\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): ParseValue {\n const resolved = this._resolveVariant(value, ctx);\n\n if ('issues' in resolved) return { data: value, issues: resolved.issues, typeOk: false };\n\n const result = resolved.matched._parseFullSync(value, ctx);\n\n return result.issues.length === 0\n ? { data: result.data, issues: [], typeOk: true }\n : { data: value, issues: result.issues, typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferVariantMap<K, M>> {\n const c = ctx ?? _makeCtx();\n\n return this._withCatchAsync(async () => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as unknown as InferVariantMap<K, M>;\n\n const resolved = this._resolveVariant(prepared.value, c);\n\n if ('issues' in resolved) throw new SpellValidationError(resolved.issues);\n\n const branch = await resolved.matched.safeParseAsync(prepared.value, c);\n\n if (!branch.success) throw branch.error;\n\n const validationIssues = await this._runValidatorsAsync(branch.data, c);\n\n if (validationIssues.length > 0) throw new SpellValidationError(validationIssues);\n\n return this._runPostprocessors(branch.data) as InferVariantMap<K, M>;\n });\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n const branches: Record<string, SchemaDescriptor> = {};\n\n for (const [key, schema] of this._map.entries()) {\n defineOwnProperty(branches, key, schema.definition());\n }\n\n return { ...this._describeBase(), branches, discriminator: this._discriminator, kind: 'variant' };\n }\n\n protected override _walk<R>(visitor: SchemaWalker<R>): R | null {\n const branches = objectFromEntries([...this._map.entries()].map(([k, s]) => [k, s.walk(visitor)]));\n\n if (visitor.variant) return visitor.variant(this, branches);\n\n return super._walk(visitor);\n }\n}\n"],"mappings":"wRA2BA,IAAa,EAAb,cAIU,CAA6C,CACrD,KACA,eAEA,IAAuB,OAAgB,CACrC,MAAO,SACT,CAEA,WAEE,EAC8B,CAC9B,OAAO,KAAK,UAAU,EAAI,EAAI,CAChC,CAEA,YAAY,EAAkB,EAAe,CAC3C,IAAM,EAAM,IAAI,IAEhB,IAAK,GAAM,CAAC,EAAK,KAAW,OAAO,QAAQ,CAAU,EAAG,CACtD,IAAM,EAAsB,IAAI,EAAc,CAAG,EAC3C,EAAwB,EAAO,MAAM,GAE3C,GACE,IACC,EAAE,aAAiC,IAAkB,EAAsB,QAAU,GAEtF,MAAM,IAAI,EACR,mCAAmC,EAAI,oDAAoD,EAAc,GAC3G,EAGF,IAAM,EAAqB,EACxB,GAAgB,CACnB,EAEA,EAAI,IAAI,EAAK,EAAwB,EAAS,EAAO,OAAO,CAAkB,CAAC,CACjF,CAEA,MAAM,E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cAAc,CAAK,EAEzC,GAAI,EAAS,KAAM,OAAO,EAAS,MAEnC,IAAM,EAAW,KAAK,gBAAgB,EAAS,MAAO,CAAC,EAEvD,GAAI,WAAY,EAAU,MAAM,IAAI,EAAqB,EAAS,MAAM,EAExE,IAAM,EAAS,MAAM,EAAS,QAAQ,eAAe,EAAS,MAAO,CAAC,EAEtE,GAAI,CAAC,EAAO,QAAS,MAAM,EAAO,MAElC,IAAM,EAAmB,MAAM,KAAK,oBAAoB,EAAO,KAAM,CAAC,EAEtE,GAAI,EAAiB,OAAS,EAAG,MAAM,IAAI,EAAqB,CAAgB,EAEhF,OAAO,KAAK,mBAAmB,EAAO,IAAI,CAC5C,CAAC,CACH,CAEA,mBAAyD,CACvD,IAAM,EAA6C,CAAC,EAEpD,IAAK,GAAM,CAAC,EAAK,KAAW,KAAK,KAAK,QAAQ,EAC5C,EAAkB,EAAU,EAAK,EAAO,WAAW,CAAC,EAGtD,MAAO,CAAE,GAAG,KAAK,cAAc,EAAG,WAAU,cAAe,KAAK,eAAgB,KAAM,SAAU,CAClG,CAEA,MAA4B,EAAoC,CAC9D,IAAM,EAAW,EAAkB,CAAC,GAAG,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,KAAK,CAAO,CAAC,CAAC,CAAC,EAIjG,OAFI,EAAQ,QAAgB,EAAQ,QAAQ,KAAM,CAAQ,EAEnD,MAAM,MAAM,CAAO,CAC5B,CACF"}
package/dist/spell.cjs CHANGED
@@ -1,3 +1,3 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e={custom:`custom`,invalid_base64:`invalid_base64`,invalid_date:`invalid_date`,invalid_duration:`invalid_duration`,invalid_enum:`invalid_enum`,invalid_finite:`invalid_finite`,invalid_integer:`invalid_integer`,invalid_keys:`invalid_keys`,invalid_length:`invalid_length`,invalid_literal:`invalid_literal`,invalid_multiple_of:`invalid_multiple_of`,invalid_safe:`invalid_safe`,invalid_string:`invalid_string`,invalid_type:`invalid_type`,invalid_union:`invalid_union`,invalid_unique:`invalid_unique`,invalid_url:`invalid_url`,invalid_variant:`invalid_variant`,too_big:`too_big`,too_small:`too_small`},t=Symbol(`spell.schemaMode`);function n(e,t,n){return[{code:e,message:t,params:n,path:[]}]}function r(e,t){return typeof e==`function`?e(t):e}function i(e,t){return e.map(e=>({...e,path:[t,...e.path]}))}var a=class e extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}static is(t){return t instanceof e}};function o(e){return e.map(({code:e,message:t,path:n})=>`${n.length?n.join(`.`):`value`}: ${t} [${e}]`).join(`
2
- `)}function s(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var c=class extends a{},l=class extends a{issues;constructor(e,t){super(o(e),{cause:t}),this.issues=e}bestMatch(t){let n=t??this.issues.find(t=>t.code===e.invalid_union);if(!n)return null;let r=n.params.errors;if(r.length===0)return null;let i=r.map(e=>({issues:e,score:e.reduce((e,t)=>Math.max(e,t.path.length),0)*1e3-e.length}));return i.sort((e,t)=>t.score-e.score),i[0]?.issues}flatten(){let e=[],t=[],n=new Map;for(let r of this.issues)if(r.path.length===0)t.push(r.message);else{let t=JSON.stringify(r.path),i=n.get(t);i===void 0?(n.set(t,e.length),e.push({messages:[r.message],path:[...r.path]})):e[i]?.messages.push(r.message)}return{fieldErrors:e,formErrors:t}}flattenFirst(){let{fieldErrors:e,formErrors:t}=this.flatten();return{fieldErrors:e.map(e=>({message:e.messages[0],path:e.path})),formErrors:t}}messagesAt(...e){return this.issues.filter(t=>s(t.path,e)).map(e=>e.message)}},u=new Set([`__proto__`,`constructor`,`prototype`]);function d(e){return u.has(e)}function f(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function p(e){let t={};for(let[n,r]of e)f(t,n,r);return t}function m(e){return p(Object.entries(e))}var h={array:{length:({exact:e})=>`Must have exactly ${e} items`,max:({max:e})=>`Must have at most ${e} items`,min:({min:e})=>`Must have at least ${e} items`,nonEmpty:()=>`Cannot be empty`,type:()=>`Expected array`,unique:()=>`All items must be unique`},bigint:{max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,type:()=>`Expected bigint`},boolean:{type:()=>`Expected boolean`},check:{default:()=>`Invalid value`},date:{max:({max:e})=>`Must be before ${e.toISOString()}`,min:({min:e})=>`Must be after ${e.toISOString()}`,type:()=>`Expected valid date`},enum:{invalid:({values:e})=>`Expected one of: ${e.map(e=>JSON.stringify(e)).join(`, `)}`},instanceof:{type:({className:e})=>`Expected instance of ${e}`},literal:{expected:({expected:e})=>`Expected ${JSON.stringify(e)}`},map:{max:({max:e})=>`Must contain at most ${e} entries`,min:({min:e})=>`Must contain at least ${e} entries`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} entries`,type:()=>`Expected map`},never:{invalid:()=>`Value is not allowed`},number:{finite:()=>`Must be finite`,int:()=>`Must be an integer`,max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,safe:()=>`Must be a safe integer`,type:()=>`Expected number`},object:{invalidKeys:({keys:e})=>`Unrecognized keys: ${e.join(`, `)}`,type:()=>`Expected object`},set:{max:({max:e})=>`Must contain at most ${e} items`,min:({min:e})=>`Must contain at least ${e} items`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} items`,type:()=>`Expected set`},string:{base64:()=>`Invalid base64`,base64url:()=>`Invalid base64url`,cuid:()=>`Invalid CUID`,cuid2:()=>`Invalid CUID2`,date:()=>`Invalid date`,dateTime:()=>`Invalid datetime`,duration:()=>`Invalid ISO 8601 duration`,email:()=>`Invalid email address`,emoji:()=>`Invalid emoji sequence`,endsWith:({suffix:e})=>`Must end with "${e}"`,hex:()=>`Invalid hex`,hexColor:()=>`Invalid hex color`,includes:({substr:e})=>`Must include "${e}"`,ip:()=>`Invalid IP address`,jwt:()=>`Invalid JWT`,length:({exact:e})=>`Must be exactly ${e} characters`,max:({max:e})=>`Must be at most ${e} characters`,min:({min:e})=>`Must be at least ${e} characters`,nanoid:()=>`Invalid NanoID`,nonEmpty:()=>`Cannot be empty`,numeric:()=>`Invalid numeric string`,regex:()=>`Invalid format`,semver:()=>`Invalid semver`,slug:()=>`Invalid slug`,startsWith:({prefix:e})=>`Must start with "${e}"`,time:()=>`Invalid time`,type:()=>`Expected string`,ulid:()=>`Invalid ULID`,url:()=>`Invalid URL`,uuid:()=>`Invalid UUID`},tuple:{length:({exact:e})=>`Expected tuple of length ${e}`,min:({min:e})=>`Expected tuple with at least ${e} items`,type:()=>`Expected array`},union:{invalid:()=>`Does not match any of the expected types`},variant:{invalidDiscriminator:({discriminator:e,expected:t})=>`Invalid discriminator value at "${e}": expected ${t.map(e=>JSON.stringify(e)).join(` | `)}`,type:()=>`Expected object`}};function g(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _(e,t){let n=m(e);for(let[e,r]of Object.entries(t)){if(r===void 0)continue;if(d(e)){`${e}`;continue}let t=n[e];g(t)&&g(r)?f(n,e,_(t,r)):f(n,e,r)}return n}function v(e={}){return{messages:_(h,e)}}function y(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function b(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;for(let t of Object.values(e))b(t);return Object.freeze(e)}function x(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(e=>x(e));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){let t=new Map;for(let[n,r]of e.entries())t.set(x(n),x(r));return t}if(e instanceof Set)return new Set([...e.values()].map(e=>x(e)));if(y(e)){let t={};for(let[n,r]of Object.entries(e))f(t,n,x(r));return t}return e}function ee(){return{hasAsyncChecks:!1,hasRuntimeChecks:!1,isNullable:!1,isOptional:!1,postprocessors:[],preprocessors:[],validators:[]}}function S(e){return{catch:e.catch,defaultValue:e.defaultValue,description:e.description,hasAsyncChecks:e.hasAsyncChecks,hasRuntimeChecks:e.hasRuntimeChecks,isNullable:e.isNullable,isOptional:e.isOptional,postprocessors:[...e.postprocessors],preprocessors:[...e.preprocessors],validators:[...e.validators]}}function C(e){return e?{messages:e}:v()}function w(t,n,r){let i=[...n];return typeof t==`string`?i.push({code:e.custom,message:t,path:[]}):t===!1&&i.length===0&&i.push({code:e.custom,message:r.messages.check.default(),path:[]}),i.length?i:null}var T=class{state;_annotations={};_typeValidator=null;constructor(e){this.state=ee(),this._typeValidator=e??null}parse(t,n){if(this.state.hasAsyncChecks)throw new l([{code:e.custom,message:`parse() cannot evaluate async checks. Use parseAsync().`,path:[]}]);let r=n??C();return this._withCatch(()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let i=this._parse(n.value,r);if(i instanceof Promise)throw new l([{code:e.custom,message:`parse() received an async schema. Use parseAsync() instead.`,path:[]}]);let a=i,o=a.typeOk?this._runValidatorsSync(a.data,r):[],s=[...a.issues,...o];if(s.length)throw new l(s);return this._runPostprocessors(a.data)})}safeParse(e,t){try{return{data:this.parse(e,t),success:!0}}catch(e){if(e instanceof l)return{error:e,success:!1};throw e}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=await this._parse(t.value,n),i=r.typeOk?await this._runValidatorsAsync(r.data,n):[],a=[...r.issues,...i];if(a.length)throw new l(a);return this._runPostprocessors(r.data)})}async safeParseAsync(e,t){try{return{data:await this.parseAsync(e,t),success:!0}}catch(e){if(e instanceof l)return{error:e,success:!1};throw e}}_parseFullSync(t,n){if(this.state.hasAsyncChecks)throw new l([{code:e.custom,message:`Sync parsing cannot evaluate async checks. Use parseAsync().`,path:[]}]);let r=n??C(),i=this._prepareInput(t);if(i.skip)return{data:i.value,issues:[]};let a=this._parse(i.value,r);if(a instanceof Promise)throw new l([{code:e.custom,message:`Sync parse path received an async schema. Use parseAsync() instead.`,path:[]}]);let o=a,s=o.typeOk?this._runValidatorsSync(o.data,r):[],c=[...o.issues,...s];return c.length>0?this.state.catch?{data:this.state.catch(),issues:[]}:{data:o.data,issues:c}:{data:this._runPostprocessors(o.data),issues:[]}}async _parseFullAsync(e,t){let n=t??C(),r=this._prepareInput(e);if(r.skip)return{data:r.value,issues:[]};let i=await this._parse(r.value,n),a=i.typeOk?await this._runValidatorsAsync(i.data,n):[],o=[...i.issues,...a];return o.length>0?this.state.catch?{data:this.state.catch(),issues:[]}:{data:i.data,issues:o}:{data:this._runPostprocessors(i.data),issues:[]}}check(e){return this._addCheck(e,!1)}checkAsync(e){return this._addCheck(e,!0)}_addCheck(e,t){let n=this._addConstraint((t,n)=>{let r=[],i=e(t,{addIssue:e=>r.push({...e,path:e.path??[]})});return i instanceof Promise?i.then(e=>w(e,r,n)):w(i,r,n)});return n.state.hasRuntimeChecks=!0,t&&(n.state.hasAsyncChecks=!0),n}optional(){let e=this._clone();return e.state.isOptional=!0,e}nullable(){let e=this._clone();return e.state.isNullable=!0,e}nullish(){let e=this._clone();return e.state.isOptional=!0,e.state.isNullable=!0,e}required(){let e=this._clone();return e.state.isOptional=!1,e}default(e){let t=this._clone();return t.state.defaultValue=typeof e==`function`?e:()=>x(e),t}catch(e){let t=this._clone();return t.state.catch=typeof e==`function`?e:()=>x(e),t}transform(e){let t=this._clone();return t.state.postprocessors.push(e),t}preprocess(e){let t=this._clone();return t.state.preprocessors.push(e),t}pipe(e){return new E(this,e)}label(e){let t=this._clone();return t.state.description=e,t}definition(){if(this.state.catch||this.state.defaultValue||this.state.postprocessors.length>0||this.state.preprocessors.length>0||this.state.hasRuntimeChecks)throw new c(`Schemas with checks, transforms, defaults, catches, or preprocessors have no declarative definition.`);return b(this._toDescriptorImpl())}get description(){return this.state.description}get isOptional(){return this.state.isOptional}get isNullable(){return this.state.isNullable}is(e){return this.safeParse(e).success}assert(e,t){let n=this._parseFullSync(e);if(n.issues.length!==0)throw new l(t?n.issues.map(e=>({...e,message:e.path.length===0?`${t}: ${e.message}`:e.message})):n.issues)}walk(e){return this._walk(e)}get kind(){return this._kind}get _kind(){return`any`}_describeBase(){return{...this.state.description===void 0?{}:{description:this.state.description},...this.state.isNullable?{isNullable:!0}:{},...this.state.isOptional?{isOptional:!0}:{}}}_addConstraint(e,t){let n=this._clone();return n.state.validators.push(e),t&&(n._annotations=t({...n._annotations})),n}_construct(e){let t=Object.assign(Object.create(Object.getPrototypeOf(this)),this,{state:e});return t._annotations={...this._annotations},t}_clone(){return this._construct(S(this.state))}_copyStateTo(e){return e.state=S(this.state),e}_walk(e){return e.unknown?e.unknown(this):null}_toDescriptorImpl(){return{...this._describeBase(),kind:`any`}}_withCatch(e){if(!this.state.catch)return e();try{return e()}catch(e){if(e instanceof l)return this.state.catch();throw e}}async _withCatchAsync(e){if(!this.state.catch)return e();try{return await e()}catch(e){if(e instanceof l)return this.state.catch();throw e}}_prepareInput(e){let t=this._runPreprocessors(e),n=t===void 0&&this.state.defaultValue?this.state.defaultValue():t;return this.state.isOptional&&n===void 0||this.state.isNullable&&n===null?{skip:!0,value:n}:{skip:!1,value:n}}_runPreprocessors(e){let t=e;for(let e of this.state.preprocessors)t=e(t);return t}_runPostprocessors(e){let t=e;for(let e of this.state.postprocessors)t=e(t);return t}_runValidatorsSync(t,n){if(this._typeValidator){let r=this._typeValidator(t,n);if(r instanceof Promise)throw new l([{code:e.custom,message:`Type validator returned a Promise. Use parseAsync() for async validation.`,path:[]}]);if(r&&r.length>0)return r}let r=[];for(let i of this.state.validators){let a=i(t,n);if(a instanceof Promise)throw new l([{code:e.custom,message:`Sync parsing received an async check. Use checkAsync() and parseAsync().`,path:[]}]);a&&r.push(...a)}return r}async _runValidatorsAsync(e,t){if(this._typeValidator){let n=await this._typeValidator(e,t);if(n&&n.length>0)return n}let n=[];for(let r of this.state.validators){let i=await r(e,t);i&&n.push(...i)}return n}_parse(e,t){return{data:e,issues:[],typeOk:!0}}},E=class extends T{from;to;get _kind(){return`pipe`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.from=e,this.to=t}_parse(e,t){let n=this.from._parseFullSync(e,t);if(n instanceof Promise)return n.then(n=>n.issues.length>0?{data:e,issues:n.issues,typeOk:!1}:this.to._parseFullAsync(n.data,t).then(e=>e.issues.length>0?{data:n.data,issues:e.issues,typeOk:!1}:{data:e.data,issues:[],typeOk:!0}));if(n.issues.length>0)return{data:e,issues:n.issues,typeOk:!1};let r=this.to._parseFullSync(n.data,t);return r instanceof Promise?r.then(e=>e.issues.length>0?{data:n.data,issues:e.issues,typeOk:!1}:{data:e.data,issues:[],typeOk:!0}):r.issues.length>0?{data:n.data,issues:r.issues,typeOk:!1}:{data:r.data,issues:[],typeOk:!0}}async parseAsync(e,t){let n=t??C(),r=await this.from._parseFullAsync(e,n);if(r.issues.length>0)throw new l(r.issues);let i=await this.to._parseFullAsync(r.data,n);if(i.issues.length>0)throw new l(i.issues);let a=await this._runValidatorsAsync(i.data,n);if(a.length>0)throw new l(a);return this._runPostprocessors(i.data)}_walk(e){let t=this.from.walk(e),n=this.to.walk(e);return e.pipe?e.pipe(this,t,n):super._walk(e)}_toDescriptorImpl(){return{...this._describeBase(),from:this.from.definition(),kind:`pipe`,to:this.to.definition()}}},D=class extends T{itemSchema;get _kind(){return`array`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.itemSchema=e}_parseItemsSync(e,t){let n=[],r=[];for(let a=0;a<e.length;a++){let o=this.itemSchema._parseFullSync(e[a],t);o.issues.length===0?r.push(o.data):(n.push(...i(o.issues,a)),r.push(e[a]))}return{data:r,issues:n}}_parse(t,r){if(!Array.isArray(t))return{data:t,issues:n(e.invalid_type,r.messages.array.type()),typeOk:!1};let{data:i,issues:a}=this._parseItemsSync(t,r);return{data:i,issues:a,typeOk:!0}}async parseAsync(t,r){let a=r??C();return this._withCatchAsync(async()=>{let r=this._prepareInput(t);if(r.skip)return r.value;let o=r.value;if(!Array.isArray(o))throw new l(n(e.invalid_type,a.messages.array.type()));let s=await Promise.all(o.map(e=>this.itemSchema._parseFullAsync(e,a))),c=[],u=[];for(let e=0;e<s.length;e++){let t=s[e];t.issues.length===0?u.push(t.data):(c.push(...i(t.issues,e)),u.push(o[e]))}let d=await this._runValidatorsAsync(u,a),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>a.length>=t?null:n(e.too_small,r(i??o.messages.array.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minItems:n.minItems===void 0?t:Math.max(n.minItems,t)}})}max(t,i){return this._addConstraint((a,o)=>a.length<=t?null:n(e.too_big,r(i??o.messages.array.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maxItems:n.maxItems===void 0?t:Math.min(n.maxItems,t)}})}length(t,i){return this._addConstraint((a,o)=>a.length===t?null:n(e.invalid_length,r(i??o.messages.array.length,{exact:t,value:a}),{exact:t}),e=>({...e,maxItems:t,minItems:t}))}nonEmpty(t){return this._addConstraint((i,a)=>{let o=i;return o.length>0?null:n(e.too_small,r(t??a.messages.array.nonEmpty,{min:1,value:o}),{min:1})})}unique(t,i){let a=typeof t==`function`&&t.length===2,o=a?t:null,s=a?i:typeof t==`function`?t:void 0;return this._addConstraint((t,i)=>{let a=t,c;return c=o?a.every((e,t)=>a.slice(0,t).every(t=>!o(e,t))):new Set(a).size===a.length,c?null:n(e.invalid_unique,r(s??i.messages.array.unique,{value:a}),{unique:!0})})}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.maxItems===void 0?{}:{maxItems:e.maxItems},...e.minItems===void 0?{}:{minItems:e.minItems},items:this.itemSchema.definition(),kind:`array`}}_walk(e){let t=this.itemSchema.walk(e);return e.array?e.array(this,t):super._walk(e)}},O=class t extends T{get _kind(){return`bigint`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`bigint`?null:n(e.invalid_type,r.messages.bigint.type()))}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s>=t?null:n(e.too_small,r(i??o.messages.bigint.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s<=t?null:n(e.too_big,r(i??o.messages.bigint.max,{max:t,value:s}),{max:t})})}positive(t){return this._addConstraint((i,a)=>{let o=i;return o>0n?null:n(e.too_small,r(t??a.messages.bigint.positive,{value:o}),{exclusive:!0,min:0n})})}negative(t){return this._addConstraint((i,a)=>{let o=i;return o<0n?null:n(e.too_big,r(t??a.messages.bigint.negative,{value:o}),{exclusive:!0,max:0n})})}nonNegative(t){return this._addConstraint((i,a)=>{let o=i;return o>=0n?null:n(e.too_small,r(t??a.messages.bigint.nonNegative,{value:o}),{min:0n})})}nonPositive(t){return this._addConstraint((i,a)=>{let o=i;return o<=0n?null:n(e.too_big,r(t??a.messages.bigint.nonPositive,{value:o}),{max:0n})})}multipleOf(t,i){return this._addConstraint((a,o)=>{let s=a;return s%t===0n?null:n(e.invalid_multiple_of,r(i??o.messages.bigint.multipleOf,{step:t,value:s}),{step:t})})}_walk(e){return e.bigint?e.bigint(this):super._walk(e)}coerce(){return t.coerce()}_toDescriptorImpl(){return this.state.validators.length,{...this._describeBase(),kind:`bigint`}}static coerce(){return new t().preprocess(e=>{if(typeof e==`bigint`)return e;if(typeof e==`number`){if(!Number.isFinite(e)||!Number.isInteger(e))return e;try{return BigInt(e)}catch{return e}}if(typeof e==`string`){let t=e.trim();if(t.length===0||t.length>1e3)return e;try{return BigInt(t)}catch{return e}}return e})}},k=class t extends T{get _kind(){return`boolean`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,n)=>typeof t==`boolean`?null:[{code:e.invalid_type,message:n.messages.boolean.type(),path:[]}])}coerce(){return t.coerce()}_toDescriptorImpl(){return{...this._describeBase(),kind:`boolean`}}_walk(e){return e.boolean?e.boolean(this):super._walk(e)}static coerce(){return new t().preprocess(e=>typeof e==`boolean`?e:e===`true`||e===`1`||e===1?!0:e===`false`||e===`0`||e===0?!1:e)}},A=class t extends T{get _kind(){return`date`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>t instanceof Date&&!Number.isNaN(t.getTime())?null:n(e.invalid_date,r.messages.date.type()))}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s>=t?null:n(e.too_small,r(i??o.messages.date.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s<=t?null:n(e.too_big,r(i??o.messages.date.max,{max:t,value:s}),{max:t})})}coerce(){return t.coerce()}_toDescriptorImpl(){return{...this._describeBase(),kind:`date`}}_walk(e){return e.date?e.date(this):super._walk(e)}static coerce(){return new t().preprocess(e=>e instanceof Date?e:typeof e==`string`||typeof e==`number`?new Date(e):e)}};function j(t){let n=new Set(t);return(r,i)=>n.has(r)?null:[{code:e.invalid_enum,message:i.messages.enum.invalid({values:t}),params:{values:t},path:[]}]}var M=class extends T{values;get _kind(){return`enum`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(j(e)),this.values=e}_toDescriptorImpl(){return{...this._describeBase(),kind:`enum`,values:this.values}}_walk(e){return e.enum?e.enum(this):super._walk(e)}},te=class extends T{cls;get _kind(){return`instanceof`}checkAsync(e){return this._addCheck(e,!0)}constructor(t){super((n,r)=>n instanceof t?null:[{code:e.invalid_type,message:r.messages.instanceof.type({className:t.name}),path:[]}]),this.cls=t}_toDescriptorImpl(){return{...this._describeBase(),className:this.cls.name,kind:`instanceof`}}_walk(e){return e.instanceof?e.instanceof(this):super._walk(e)}};function N(e,t){if(y(e)&&y(t)){let n=m(e);for(let[r,i]of Object.entries(t))f(n,r,N(e[r],i));return n}return t}var P=class extends T{schemas;get _kind(){return`intersect`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.schemas=Object.freeze([...e])}_parse(e,t){let n={hasOutput:!1,issues:[],output:e};for(let r=0;r<this.schemas.length;r++){let i=this.schemas[r]._parseFullSync(e,t);i.issues.length>0?n.issues.push(...i.issues):n.hasOutput?n.output=N(n.output,i.data):(n.hasOutput=!0,n.output=i.data)}return{data:n.output,issues:n.issues,typeOk:n.issues.length===0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r={hasOutput:!1,issues:[],output:t.value};for(let e=0;e<this.schemas.length;e++){let i=await this.schemas[e]._parseFullAsync(t.value,n);i.issues.length>0?r.issues.push(...i.issues):r.hasOutput?r.output=N(r.output,i.data):(r.hasOutput=!0,r.output=i.data)}if(r.issues.length>0)throw new l(r.issues);let i=await this._runValidatorsAsync(r.output,n);if(i.length)throw new l(i);return this._runPostprocessors(r.output)})}_toDescriptorImpl(){return{...this._describeBase(),branches:this.schemas.map(e=>e.definition()),kind:`intersect`}}_walk(e){let t=this.schemas.map(t=>t.walk(e));return e.intersect?e.intersect(this,t):super._walk(e)}},F=class e extends T{_getter;_resolved;get _kind(){return`lazy`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this._getter=e}_resolve(){return this._resolved??=this._getter()}_parse(e,t){let n=this._resolve()._parseFullSync(e,t);return n.issues.length===0?{data:n.data,issues:[],typeOk:!0}:{data:e,issues:n.issues,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=await this._resolve()._parseFullAsync(t.value,n);if(r.issues.length>0)throw new l(r.issues);let i=await this._runValidatorsAsync(r.data,n);if(i.length>0)throw new l(i);return this._runPostprocessors(r.data)})}_toDescriptorImpl(){return{...this._describeBase(),kind:`lazy`}}_walk(e){return e.lazy?e.lazy(this):super._walk(e)}_construct(t){let n=new e(this._getter);return n.state=t,n}},I=class extends T{value;get _kind(){return`literal`}checkAsync(e){return this._addCheck(e,!0)}constructor(t){super((n,r)=>n===t?null:[{code:e.invalid_literal,message:r.messages.literal.expected({expected:t}),params:{expected:t},path:[]}]),this.value=t}_toDescriptorImpl(){return{...this._describeBase(),kind:`literal`,value:this.value}}_walk(e){return e.literal?e.literal(this):super._walk(e)}},L=class extends T{keySchema;valueSchema;get _kind(){return`map`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.keySchema=e,this.valueSchema=t}_parse(t,n){if(!(t instanceof Map))return{data:t,issues:[{code:e.invalid_type,message:n.messages.map.type(),path:[]}],typeOk:!1};let r=new Map,a=[],o=0;for(let[e,s]of t){let t=this.keySchema._parseFullSync(e,n),c=this.valueSchema._parseFullSync(s,n);t.issues.length>0&&a.push(...i(t.issues,o)),c.issues.length>0&&a.push(...i(c.issues,o)),t.issues.length===0&&c.issues.length===0&&r.set(t.data,c.data),o+=1}return{data:r,issues:a,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!(a instanceof Map))throw new l([{code:e.invalid_type,message:r.messages.map.type(),path:[]}]);let o=[...a],s=await Promise.all(o.map(([e,t])=>Promise.all([this.keySchema._parseFullAsync(e,r),this.valueSchema._parseFullAsync(t,r)]))),c=[],u=new Map;for(let e=0;e<s.length;e++){let[t,n]=s[e];t.issues.length>0&&c.push(...i(t.issues,e)),n.issues.length>0&&c.push(...i(n.issues,e)),t.issues.length===0&&n.issues.length===0&&u.set(t.data,n.data)}let d=await this._runValidatorsAsync(u,r),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size>=t?null:n(e.too_small,r(i??o.messages.map.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size<=t?null:n(e.too_big,r(i??o.messages.map.max,{max:t,value:s}),{max:t})})}size(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size===t?null:n(e.invalid_length,r(i??o.messages.map.size,{exact:t,value:s}),{exact:t})})}nonEmpty(t){return this._addConstraint((i,a)=>i.size>0?null:n(e.too_small,r(t??a.messages.map.nonEmpty,{min:1}),{min:1}))}_toDescriptorImpl(){return{...this._describeBase(),key:this.keySchema.definition(),kind:`map`,value:this.valueSchema.definition()}}_walk(e){let t=this.keySchema.walk(e),n=this.valueSchema.walk(e);return e.map?e.map(this,t,n):super._walk(e)}},R=class extends T{get _kind(){return`never`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,n)=>[{code:e.invalid_type,message:n.messages.never.invalid(),path:[]}])}_toDescriptorImpl(){return{...this._describeBase(),kind:`never`}}_walk(e){return e.never?e.never(this):super._walk(e)}},z=class t extends T{get _kind(){return`number`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`number`&&!Number.isNaN(t)?null:n(e.invalid_type,r.messages.number.type()))}min(t,i){return this._addConstraint((a,o)=>a>=t?null:n(e.too_small,r(i??o.messages.number.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minimum:n.minimum===void 0?t:Math.max(n.minimum,t)}})}max(t,i){return this._addConstraint((a,o)=>a<=t?null:n(e.too_big,r(i??o.messages.number.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maximum:n.maximum===void 0?t:Math.min(n.maximum,t)}})}int(t){return this._addConstraint((i,a)=>Number.isInteger(i)?null:n(e.invalid_integer,r(t??a.messages.number.int,{value:i})),e=>({...e,typeHint:`integer`}))}positive(t){return this._addConstraint((i,a)=>i>0?null:n(e.too_small,r(t??a.messages.number.positive,{value:i}),{exclusive:!0,min:0}),e=>{let t=e;return{...t,exclusiveMinimum:t.exclusiveMinimum===void 0?0:Math.max(t.exclusiveMinimum,0)}})}negative(t){return this._addConstraint((i,a)=>i<0?null:n(e.too_big,r(t??a.messages.number.negative,{value:i}),{exclusive:!0,max:0}),e=>{let t=e;return{...t,exclusiveMaximum:t.exclusiveMaximum===void 0?0:Math.min(t.exclusiveMaximum,0)}})}nonNegative(t){return this._addConstraint((i,a)=>i>=0?null:n(e.too_small,r(t??a.messages.number.nonNegative,{value:i}),{min:0}),e=>{let t=e;return{...t,minimum:t.minimum===void 0?0:Math.max(t.minimum,0)}})}nonPositive(t){return this._addConstraint((i,a)=>i<=0?null:n(e.too_big,r(t??a.messages.number.nonPositive,{value:i}),{max:0}),e=>{let t=e;return{...t,maximum:t.maximum===void 0?0:Math.min(t.maximum,0)}})}multipleOf(t,i){return this._addConstraint((a,o)=>Math.abs(Math.round(a/t)-a/t)<1e-9?null:n(e.invalid_multiple_of,r(i??o.messages.number.multipleOf,{step:t,value:a}),{step:t}),e=>({...e,multipleOf:t}))}safe(t){return this._addConstraint((i,a)=>Number.isSafeInteger(i)?null:n(e.invalid_safe,r(t??a.messages.number.safe,{value:i})))}finite(t){return this._addConstraint((i,a)=>Number.isFinite(i)?null:n(e.invalid_finite,r(t??a.messages.number.finite,{value:i})))}coerce(){return t.coerce()}_walk(e){return e.number?e.number(this):super._walk(e)}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.exclusiveMaximum===void 0?{}:{exclusiveMaximum:e.exclusiveMaximum},...e.exclusiveMinimum===void 0?{}:{exclusiveMinimum:e.exclusiveMinimum},...e.maximum===void 0?{}:{maximum:e.maximum},...e.minimum===void 0?{}:{minimum:e.minimum},...e.multipleOf===void 0?{}:{multipleOf:e.multipleOf},...e.typeHint===void 0?{}:{typeHint:e.typeHint},kind:`number`}}static coerce(){return new t().preprocess(e=>{if(typeof e==`number`)return e;if(typeof e==`string`||typeof e==`boolean`){let t=Number(e);return Number.isNaN(t)?e:t}return e})}},B=class extends T{schemas;get _kind(){return`union`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.schemas=Object.freeze([...e])}_parse(t,n){let r=[];for(let e of this.schemas){let i=e._parseFullSync(t,n);if(i.issues.length===0)return{data:i.data,issues:[],typeOk:!0};r.push(i.issues)}return{data:t,issues:[{code:e.invalid_union,message:n.messages.union.invalid(),params:{errors:r},path:[]}],typeOk:!1}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let i=n.value,a=[];for(let e of this.schemas){let t=await e._parseFullAsync(i,r);if(t.issues.length>0){a.push(t.issues);continue}let n=await this._runValidatorsAsync(t.data,r);if(n.length>0)throw new l(n);return this._runPostprocessors(t.data)}throw new l([{code:e.invalid_union,message:r.messages.union.invalid(),params:{errors:a},path:[]}])})}_toDescriptorImpl(){return{...this._describeBase(),branches:this.schemas.map(e=>e.definition()),kind:`union`}}_walk(e){let t=this.schemas.map(t=>t.walk(e));return e.union?e.union(this,t):super._walk(e)}},V=class t extends T{shape;_isRelaxed;get _kind(){return`object`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t=!1){super(),this.shape=Object.freeze(p(Object.entries(e))),this._isRelaxed=t}_unknownKeys(e){return Object.keys(e).filter(e=>!Object.hasOwn(this.shape,e))}_strictUnknownKeyIssues(t,n){if(this._isRelaxed)return[];let r=this._unknownKeys(t);return r.length===0?[]:[{code:e.invalid_keys,message:n.messages.object.invalidKeys({keys:r}),params:{keys:r},path:[]}]}_copyRelaxedUnknownKeys(e,t){if(this._isRelaxed)for(let n of this._unknownKeys(e))d(n)||Object.defineProperty(t,n,{configurable:!0,enumerable:!0,value:e[n],writable:!0})}_guardObjectInput(t,n){return typeof t!=`object`||!t||Array.isArray(t)?{issues:[{code:e.invalid_type,message:n.messages.object.type(),path:[]}],ok:!1}:{obj:t,ok:!0}}_createObjectParseContext(e,t){return{issues:[...this._strictUnknownKeyIssues(e,t)],output:{}}}_rebuildWith(e,n=this._isRelaxed){return this._copyStateTo(new t(e,n))}_parse(e,t){let n=this._guardObjectInput(e,t);if(!n.ok)return{data:e,issues:n.issues,typeOk:!1};let{obj:r}=n,{issues:a,output:o}=this._createObjectParseContext(r,t);for(let e of Object.keys(this.shape)){let n=this.shape[e]._parseFullSync(r[e],t);n.issues.length===0?f(o,e,n.data):a.push(...i(n.issues,e))}return this._copyRelaxedUnknownKeys(r,o),{data:o,issues:a,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._guardObjectInput(t.value,n);if(!r.ok)throw new l(r.issues);let{obj:a}=r,{issues:o,output:s}=this._createObjectParseContext(a,n),c=Object.keys(this.shape),u=await Promise.all(c.map(e=>this.shape[e]._parseFullAsync(a[e],n)));for(let e=0;e<c.length;e++){let t=c[e],n=u[e];n.issues.length===0?f(s,t,n.data):o.push(...i(n.issues,t))}this._copyRelaxedUnknownKeys(a,s);let d=await this._runValidatorsAsync(s,n),p=[...o,...d];if(p.length>0)throw new l(p);return this._runPostprocessors(s)})}partial(...e){let t=e.length>0?new Set(e):null;return this._rebuildWith(p(Object.entries(this.shape).map(([e,n])=>[e,t===null||t.has(e)?n.optional():n])),this._isRelaxed)}optional(){return super.optional()}nullable(){return super.nullable()}nullish(){return super.nullish()}required(){return this._rebuildWith(p(Object.entries(this.shape).map(([e,t])=>[e,t.required()])),this._isRelaxed)}extend(e){return this._rebuildWith(p([...Object.entries(this.shape),...Object.entries(e)]),this._isRelaxed)}pick(...e){let t=new Set(e);return this._rebuildWith(p(Object.entries(this.shape).filter(([e])=>t.has(e))))}omit(...e){let t=new Set(e);return this._rebuildWith(p(Object.entries(this.shape).filter(([e])=>!t.has(e))))}defaults(){return this.parse({})}partialDefaults(){let e={};for(let t of Object.keys(this.shape)){let n=this.shape[t]._parseFullSync(void 0);n.issues.length===0&&f(e,t,n.data)}return e}requiredFields(){return Object.keys(this.shape).filter(e=>!this.shape[e].isOptional)}optionalFields(){return Object.keys(this.shape).filter(e=>this.shape[e].isOptional)}relaxed(){return this._rebuildWith(this.shape,!0)}strict(){return this._rebuildWith(this.shape,!1)}keyof(){return new B(Object.keys(this.shape).map(e=>new I(e)))}_toDescriptorImpl(){let e={};for(let[t,n]of Object.entries(this.shape))f(e,t,n.definition());return{...this._describeBase(),fields:e,kind:`object`,strict:!this._isRelaxed}}_walk(e){let t=p(Object.entries(this.shape).map(([t,n])=>[t,n.walk(e)]));return e.object?e.object(this,t):super._walk(e)}merge(e){return this._rebuildWith(p([...Object.entries(this.shape),...Object.entries(e.shape)]),e._isRelaxed)}};function H(e){return e.map(e=>e instanceof T?e:new I(e))}var U=class extends T{keySchema;valueSchema;get _kind(){return`record`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.keySchema=e,this.valueSchema=t}_guardRecordInput(t,n){return typeof t!=`object`||!t||Array.isArray(t)?{issues:[{code:e.invalid_type,message:n.messages.object.type(),path:[]}],ok:!1}:{ok:!0,value:t}}_parseRecordEntries(e,t){let n=[],r={};for(let a of Object.keys(e)){let o=this.keySchema._parseFullSync(a,t);if(o.issues.length>0){n.push(...i(o.issues,a));continue}let s=o.data;if(d(s))continue;let c=this.valueSchema._parseFullSync(e[a],t);c.issues.length===0?Object.defineProperty(r,s,{configurable:!0,enumerable:!0,value:c.data,writable:!0}):n.push(...i(c.issues,a))}return{issues:n,output:r}}_parse(e,t){let n=this._guardRecordInput(e,t);if(!n.ok)return{data:e,issues:n.issues,typeOk:!1};let{issues:r,output:i}=this._parseRecordEntries(n.value,t);return{data:i,issues:r,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._guardRecordInput(t.value,n);if(!r.ok)throw new l(r.issues);let a=r.value,o=Object.keys(a),s=await Promise.all(o.map(e=>Promise.all([this.keySchema._parseFullAsync(e,n),this.valueSchema._parseFullAsync(a[e],n)]))),c=[],u={};for(let e=0;e<o.length;e++){let t=o[e],[n,r]=s[e];if(n.issues.length>0){c.push(...i(n.issues,t));continue}let a=n.data;d(a)||(r.issues.length===0?Object.defineProperty(u,a,{configurable:!0,enumerable:!0,value:r.data,writable:!0}):c.push(...i(r.issues,t)))}let f=await this._runValidatorsAsync(u,n),p=[...c,...f];if(p.length>0)throw new l(p);return this._runPostprocessors(u)})}_toDescriptorImpl(){return{...this._describeBase(),key:this.keySchema.definition(),kind:`record`,value:this.valueSchema.definition()}}_walk(e){let t=this.keySchema.walk(e),n=this.valueSchema.walk(e);return e.record?e.record(this,t,n):super._walk(e)}},W=class extends T{itemSchema;get _kind(){return`set`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.itemSchema=e}_parse(t,n){if(!(t instanceof Set))return{data:t,issues:[{code:e.invalid_type,message:n.messages.set.type(),path:[]}],typeOk:!1};let r=[],a=new Set,o=0;for(let e of t){let t=this.itemSchema._parseFullSync(e,n);t.issues.length===0?a.add(t.data):r.push(...i(t.issues,o)),o+=1}return{data:a,issues:r,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!(a instanceof Set))throw new l([{code:e.invalid_type,message:r.messages.set.type(),path:[]}]);let o=[...a],s=await Promise.all(o.map(e=>this.itemSchema._parseFullAsync(e,r))),c=[],u=new Set;for(let e=0;e<s.length;e++){let t=s[e];t.issues.length===0?u.add(t.data):c.push(...i(t.issues,e))}let d=await this._runValidatorsAsync(u,r),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size>=t?null:n(e.too_small,r(i??o.messages.set.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size<=t?null:n(e.too_big,r(i??o.messages.set.max,{max:t,value:s}),{max:t})})}size(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size===t?null:n(e.invalid_length,r(i??o.messages.set.size,{exact:t,value:s}),{exact:t})})}nonEmpty(t){return this._addConstraint((i,a)=>i.size>0?null:n(e.too_small,r(t??a.messages.set.nonEmpty,{min:1}),{min:1}))}_toDescriptorImpl(){return{...this._describeBase(),items:this.itemSchema.definition(),kind:`set`}}_walk(e){let t=this.itemSchema.walk(e);return e.set?e.set(this,t):super._walk(e)}};function G(e){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)}var K=new Set([`http`,`https`]);function q(e,t){try{let n=new URL(e);return(t?new Set(t.map(e=>e.toLowerCase())):K).has(n.protocol.replace(`:`,``).toLowerCase())}catch{return!1}}function J(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}function Y(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;let t=new Date(e);return!Number.isNaN(t.getTime())&&t.toISOString().startsWith(e)}function ne(e){return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})?$/.test(e)&&!Number.isNaN(new Date(e).getTime())}function X(e){if(/^(\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>{let t=parseInt(e,10);return t>=0&&t<=255});try{return new URL(`http://[${e}]/`),!0}catch{return!1}}function Z(e){return/^c[a-z0-9]{8,}$/.test(e)}function re(e){return/^[a-z][a-z0-9]{23}$/.test(e)}function ie(e){return/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(e)}function ae(e,t=21){return e.length===t&&/^[A-Za-z0-9_-]+$/.test(e)}function oe(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(e)}function se(e){return e.length===0||e.length%4==1?!1:/^[A-Za-z0-9_-]*={0,2}$/.test(e)}function ce(e){return/^[A-Fa-f0-9]+$/.test(e)}function le(e){return/^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)}function ue(e){return/^\p{Extended_Pictographic}+$/u.test(e)}function de(e){return/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e)}function fe(e){return/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(e)}function pe(e){return/^P(?=\d|T\d)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+(?:\.\d+)?S)?)?$/.test(e)}function me(e){return/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/.test(e)}function Q(e){return/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e)}function he(e){return/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i.test(e)}var $=class t extends T{get _kind(){return`string`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`string`?null:n(e.invalid_type,r.messages.string.type()))}min(t,i){return this._addConstraint((a,o)=>a.length>=t?null:n(e.too_small,r(i??o.messages.string.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minLength:n.minLength===void 0?t:Math.max(n.minLength,t)}})}max(t,i){return this._addConstraint((a,o)=>a.length<=t?null:n(e.too_big,r(i??o.messages.string.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maxLength:n.maxLength===void 0?t:Math.min(n.maxLength,t)}})}length(t,i){return this._addConstraint((a,o)=>a.length===t?null:n(e.invalid_length,r(i??o.messages.string.length,{exact:t,value:a}),{exact:t}),e=>({...e,maxLength:t,minLength:t}))}nonempty(e){return this.nonEmpty(e)}nonEmpty(t){return this._addConstraint((i,a)=>i.length>0?null:n(e.too_small,r(t??a.messages.string.nonEmpty,{min:1,value:i}),{min:1}),e=>{let t=e;return{...t,minLength:Math.max(t.minLength??0,1)}})}startsWith(t,i){return this._addConstraint((a,o)=>a.startsWith(t)?null:n(e.invalid_string,r(i??o.messages.string.startsWith,{prefix:t,value:a}),{prefix:t}))}endsWith(t,i){return this._addConstraint((a,o)=>a.endsWith(t)?null:n(e.invalid_string,r(i??o.messages.string.endsWith,{suffix:t,value:a}),{suffix:t}))}includes(t,i){return this._addConstraint((a,o)=>a.includes(t)?null:n(e.invalid_string,r(i??o.messages.string.includes,{substr:t,value:a}),{includes:t}))}regex(t,i){let a=new RegExp(t.source,t.flags.replace(/[gy]/g,``));return this._addConstraint((t,o)=>a.test(t)?null:n(e.invalid_string,r(i??o.messages.string.regex,{value:t}),{pattern:a.source}),e=>{let t=e;return t.pattern===null?t:t.pattern===void 0?{...t,pattern:a.source}:t.pattern===a.source?t:{...t,pattern:null}})}email(t){return this._addConstraint((i,a)=>G(i)?null:n(e.invalid_string,r(t??a.messages.string.email,{value:i}),{format:`email`}),e=>({...e,format:`email`}))}url(t={}){let{message:i,protocols:a=[`http`,`https`]}=t;return this._addConstraint((t,o)=>q(t,a)?null:n(e.invalid_url,r(i??o.messages.string.url,{value:t}),{format:`url`}),e=>({...e,format:`uri`}))}uuid(t){return this._addConstraint((i,a)=>J(i)?null:n(e.invalid_string,r(t??a.messages.string.uuid,{value:i}),{format:`uuid`}),e=>({...e,format:`uuid`}))}isoDate(t){return this._addConstraint((i,a)=>Y(i)?null:n(e.invalid_string,r(t??a.messages.string.date,{value:i}),{format:`iso-date`}),e=>({...e,format:`date`}))}isoDateTime(t){return this._addConstraint((i,a)=>ne(i)?null:n(e.invalid_string,r(t??a.messages.string.dateTime,{value:i}),{format:`iso-datetime`}),e=>({...e,format:`date-time`}))}ip(t){return this._addConstraint((i,a)=>X(i)?null:n(e.invalid_string,r(t??a.messages.string.ip,{value:i}),{format:`ip`}))}cuid(t){return this._addConstraint((i,a)=>Z(i)?null:n(e.invalid_string,r(t??a.messages.string.cuid,{value:i}),{format:`cuid`}))}cuid2(t){return this._addConstraint((i,a)=>re(i)?null:n(e.invalid_string,r(t??a.messages.string.cuid2,{value:i}),{format:`cuid2`}))}ulid(t){return this._addConstraint((i,a)=>ie(i)?null:n(e.invalid_string,r(t??a.messages.string.ulid,{value:i}),{format:`ulid`}))}nanoid(t,i){return this._addConstraint((a,o)=>ae(a,t)?null:n(e.invalid_string,r(i??o.messages.string.nanoid,{value:a}),{format:`nanoid`}))}base64(t){return this._addConstraint((i,a)=>oe(i)?null:n(e.invalid_base64,r(t??a.messages.string.base64,{value:i}),{format:`base64`}),e=>({...e,contentEncoding:`base64`}))}base64url(t){return this._addConstraint((i,a)=>se(i)?null:n(e.invalid_base64,r(t??a.messages.string.base64url,{value:i}),{format:`base64url`}))}hex(t){return this._addConstraint((i,a)=>ce(i)?null:n(e.invalid_string,r(t??a.messages.string.hex,{value:i}),{format:`hex`}))}hexColor(t){return this._addConstraint((i,a)=>le(i)?null:n(e.invalid_string,r(t??a.messages.string.hexColor,{value:i}),{format:`hex-color`}))}emoji(t){return this._addConstraint((i,a)=>ue(i)?null:n(e.invalid_string,r(t??a.messages.string.emoji,{value:i}),{format:`emoji`}))}jwt(t){return this._addConstraint((i,a)=>de(i)?null:n(e.invalid_string,r(t??a.messages.string.jwt,{value:i}),{format:`jwt`}))}time(t){return this._addConstraint((i,a)=>fe(i)?null:n(e.invalid_string,r(t??a.messages.string.time,{value:i}),{format:`time`}))}duration(t){return this._addConstraint((i,a)=>pe(i)?null:n(e.invalid_duration,r(t??a.messages.string.duration,{value:i}),{format:`duration`}),e=>({...e,format:`duration`}))}semver(t){return this._addConstraint((i,a)=>me(i)?null:n(e.invalid_string,r(t??a.messages.string.semver,{value:i}),{format:`semver`}))}slug(t){return this._addConstraint((i,a)=>Q(i)?null:n(e.invalid_string,r(t??a.messages.string.slug,{value:i}),{format:`slug`}))}numeric(t){return this._addConstraint((i,a)=>he(i)?null:n(e.invalid_string,r(t??a.messages.string.numeric,{value:i}),{format:`numeric`}))}coerce(){return t.coerce()}trim(){return this.preprocess(e=>typeof e==`string`?e.trim():e)}lowercase(){return this.preprocess(e=>typeof e==`string`?e.toLowerCase():e)}uppercase(){return this.preprocess(e=>typeof e==`string`?e.toUpperCase():e)}_walk(e){return e.string?e.string(this):super._walk(e)}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.contentEncoding===void 0?{}:{contentEncoding:e.contentEncoding},...e.format===void 0?{}:{format:e.format},...e.maxLength===void 0?{}:{maxLength:e.maxLength},...e.minLength===void 0?{}:{minLength:e.minLength},...e.pattern===void 0?{}:{pattern:e.pattern},kind:`string`}}static coerce(){return new t().preprocess(e=>e==null?e:String(e))}},ge=class t extends T{items;restSchema;get _kind(){return`tuple`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t=null){super(),this.items=e,this.restSchema=t}rest(e){return this._copyStateTo(new t(this.items,e))}_guardTupleInput(t,n){return this.restSchema===null&&t.length!==this.items.length?{issues:[{code:e.invalid_length,message:n.messages.tuple.length({exact:this.items.length}),params:{exact:this.items.length},path:[]}],ok:!1}:this.restSchema!==null&&t.length<this.items.length?{issues:[{code:e.too_small,message:n.messages.tuple.min({min:this.items.length}),params:{min:this.items.length},path:[]}],ok:!1}:{ok:!0,value:t}}_parse(t,n){if(!Array.isArray(t))return{data:t,issues:[{code:e.invalid_type,message:n.messages.tuple.type(),path:[]}],typeOk:!1};let r=this._guardTupleInput(t,n);if(!r.ok)return{data:t,issues:r.issues,typeOk:!1};let a=[],o=[],s=r.value;for(let e=0;e<this.items.length;e++){let t=this.items[e]._parseFullSync(s[e],n);t.issues.length===0?o.push(t.data):(a.push(...i(t.issues,e)),o.push(s[e]))}if(this.restSchema!==null)for(let e=this.items.length;e<s.length;e++){let t=this.restSchema._parseFullSync(s[e],n);t.issues.length===0?o.push(t.data):(a.push(...i(t.issues,e)),o.push(s[e]))}return{data:o,issues:a,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!Array.isArray(a))throw new l([{code:e.invalid_type,message:r.messages.tuple.type(),path:[]}]);let o=this._guardTupleInput(a,r);if(!o.ok)throw new l(o.issues);let s=o.value,c=[],u=[],d=await Promise.all(this.items.map((e,t)=>e._parseFullAsync(s[t],r)));for(let e=0;e<d.length;e++){let t=d[e];t.issues.length===0?u.push(t.data):(c.push(...i(t.issues,e)),u.push(s[e]))}let f=this.restSchema;if(f!==null){let e=s.slice(this.items.length),t=await Promise.all(e.map(e=>f._parseFullAsync(e,r)));for(let e=0;e<t.length;e++){let n=t[e],r=this.items.length+e;n.issues.length===0?u.push(n.data):(c.push(...i(n.issues,r)),u.push(s[r]))}}let p=await this._runValidatorsAsync(u,r),m=[...c,...p];if(m.length>0)throw new l(m);return this._runPostprocessors(u)})}_toDescriptorImpl(){return{...this._describeBase(),items:this.items.map(e=>e.definition()),kind:`tuple`,rest:this.restSchema===null?null:this.restSchema.definition()}}_walk(e){let t=this.items.map(t=>t.walk(e)),n=this.restSchema===null?null:this.restSchema.walk(e);return e.tuple?e.tuple(this,t,n):super._walk(e)}},_e=class extends T{_map;_discriminator;get _kind(){return`variant`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){let n=new Map;for(let[r,i]of Object.entries(t)){let t=new I(r),o=i.shape[e];if(o&&(!(o instanceof I)||o.value!==r))throw new a(`s.discriminatedUnion(): branch "${r}" defines a conflicting discriminator schema for "${e}".`);let s={[e]:t};n.set(r,o?i:i.extend(s))}super(),this._discriminator=e,this._map=n}get discriminator(){return this._discriminator}get variantMap(){return new Map(this._map)}_resolveVariant(t,n){if(typeof t!=`object`||!t||Array.isArray(t))return{issues:[{code:e.invalid_type,message:n.messages.variant.type(),path:[]}]};let r=t,i=r[this._discriminator],a=this._map.get(i);if(!a){let t=[...this._map.keys()];return{issues:[{code:e.invalid_variant,message:n.messages.variant.invalidDiscriminator({discriminator:this._discriminator,expected:t}),params:{discriminator:this._discriminator,expected:t},path:[]}]}}return{matched:a,obj:r}}_parse(e,t){let n=this._resolveVariant(e,t);if(`issues`in n)return{data:e,issues:n.issues,typeOk:!1};let r=n.matched._parseFullSync(e,t);return r.issues.length===0?{data:r.data,issues:[],typeOk:!0}:{data:e,issues:r.issues,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._resolveVariant(t.value,n);if(`issues`in r)throw new l(r.issues);let i=await r.matched.safeParseAsync(t.value,n);if(!i.success)throw i.error;let a=await this._runValidatorsAsync(i.data,n);if(a.length>0)throw new l(a);return this._runPostprocessors(i.data)})}_toDescriptorImpl(){let e={};for(let[t,n]of this._map.entries())f(e,t,n.definition());return{...this._describeBase(),branches:e,discriminator:this._discriminator,kind:`variant`}}_walk(e){let t=p([...this._map.entries()].map(([t,n])=>[t,n.walk(e)]));return e.variant?e.variant(this,t):super._walk(e)}},ve={any:()=>new T,array:e=>new D(e),bigint:()=>new O,boolean:()=>new k,coerce:{bigint:()=>O.coerce(),boolean:()=>k.coerce(),date:()=>A.coerce(),number:()=>z.coerce(),string:()=>$.coerce()},date:()=>new A,discriminatedUnion:(e,t)=>new _e(e,t),enum:e=>new M(e),instanceof:e=>new te(e),intersect:(...e)=>new P(H(e)),lazy:e=>new F(e),literal:e=>new I(e),map:(e,t)=>new L(e,t),never:()=>new R,null:()=>new I(null),number:()=>new z,object:e=>new V(e),record:(e,t)=>new U(e,t),set:e=>new W(e),string:()=>new $,tuple:e=>new ge(e),undefined:()=>new I(void 0),union:(...e)=>new B(H(e)),unknown:()=>new T},ye={createParseContext:v,fail:n,prependIssuePath:i};exports.ErrorCode=e,exports.PipeSchema=E,exports.Schema=T,exports.SpellDefinitionError=c,exports.SpellError=a,exports.SpellValidationError=l,exports.diagnostics=ye,exports.s=ve,exports.schemaMode=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e={custom:`custom`,invalid_base64:`invalid_base64`,invalid_date:`invalid_date`,invalid_duration:`invalid_duration`,invalid_enum:`invalid_enum`,invalid_finite:`invalid_finite`,invalid_integer:`invalid_integer`,invalid_keys:`invalid_keys`,invalid_length:`invalid_length`,invalid_literal:`invalid_literal`,invalid_multiple_of:`invalid_multiple_of`,invalid_safe:`invalid_safe`,invalid_string:`invalid_string`,invalid_type:`invalid_type`,invalid_union:`invalid_union`,invalid_unique:`invalid_unique`,invalid_url:`invalid_url`,invalid_variant:`invalid_variant`,too_big:`too_big`,too_small:`too_small`},t=Symbol(`spell.schemaMode`);function n(e,t,n){return[{code:e,message:t,params:n,path:[]}]}function r(e,t){return typeof e==`function`?e(t):e}function i(e,t){return e.map(e=>({...e,path:[t,...e.path]}))}var a=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}};function o(e){return e.map(({code:e,message:t,path:n})=>`${n.length?n.join(`.`):`value`}: ${t} [${e}]`).join(`
2
+ `)}function s(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var c=class extends a{},l=class extends a{issues;constructor(e,t){super(o(e),{cause:t}),this.issues=e}bestMatch(t){let n=t??this.issues.find(t=>t.code===e.invalid_union);if(!n)return null;let r=n.params.errors;if(r.length===0)return null;let i=r.map(e=>({issues:e,score:e.reduce((e,t)=>Math.max(e,t.path.length),0)*1e3-e.length}));return i.sort((e,t)=>t.score-e.score),i[0]?.issues}flatten(){let e=[],t=[],n=new Map;for(let r of this.issues)if(r.path.length===0)t.push(r.message);else{let t=JSON.stringify(r.path),i=n.get(t);i===void 0?(n.set(t,e.length),e.push({messages:[r.message],path:[...r.path]})):e[i]?.messages.push(r.message)}return{fieldErrors:e,formErrors:t}}flattenFirst(){let{fieldErrors:e,formErrors:t}=this.flatten();return{fieldErrors:e.map(e=>({message:e.messages[0],path:e.path})),formErrors:t}}messagesAt(...e){return this.issues.filter(t=>s(t.path,e)).map(e=>e.message)}},u=new Set([`__proto__`,`constructor`,`prototype`]);function d(e){return u.has(e)}function f(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function p(e){let t={};for(let[n,r]of e)f(t,n,r);return t}function m(e){return p(Object.entries(e))}var h={array:{length:({exact:e})=>`Must have exactly ${e} items`,max:({max:e})=>`Must have at most ${e} items`,min:({min:e})=>`Must have at least ${e} items`,nonEmpty:()=>`Cannot be empty`,type:()=>`Expected array`,unique:()=>`All items must be unique`},bigint:{max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,type:()=>`Expected bigint`},boolean:{type:()=>`Expected boolean`},check:{default:()=>`Invalid value`},date:{max:({max:e})=>`Must be before ${e.toISOString()}`,min:({min:e})=>`Must be after ${e.toISOString()}`,type:()=>`Expected valid date`},enum:{invalid:({values:e})=>`Expected one of: ${e.map(e=>JSON.stringify(e)).join(`, `)}`},instanceof:{type:({className:e})=>`Expected instance of ${e}`},literal:{expected:({expected:e})=>`Expected ${JSON.stringify(e)}`},map:{max:({max:e})=>`Must contain at most ${e} entries`,min:({min:e})=>`Must contain at least ${e} entries`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} entries`,type:()=>`Expected map`},never:{invalid:()=>`Value is not allowed`},number:{finite:()=>`Must be finite`,int:()=>`Must be an integer`,max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,safe:()=>`Must be a safe integer`,type:()=>`Expected number`},object:{invalidKeys:({keys:e})=>`Unrecognized keys: ${e.join(`, `)}`,type:()=>`Expected object`},set:{max:({max:e})=>`Must contain at most ${e} items`,min:({min:e})=>`Must contain at least ${e} items`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} items`,type:()=>`Expected set`},string:{base64:()=>`Invalid base64`,base64url:()=>`Invalid base64url`,cuid:()=>`Invalid CUID`,cuid2:()=>`Invalid CUID2`,date:()=>`Invalid date`,dateTime:()=>`Invalid datetime`,duration:()=>`Invalid ISO 8601 duration`,email:()=>`Invalid email address`,emoji:()=>`Invalid emoji sequence`,endsWith:({suffix:e})=>`Must end with "${e}"`,hex:()=>`Invalid hex`,hexColor:()=>`Invalid hex color`,includes:({substr:e})=>`Must include "${e}"`,ip:()=>`Invalid IP address`,jwt:()=>`Invalid JWT`,length:({exact:e})=>`Must be exactly ${e} characters`,max:({max:e})=>`Must be at most ${e} characters`,min:({min:e})=>`Must be at least ${e} characters`,nanoid:()=>`Invalid NanoID`,nonEmpty:()=>`Cannot be empty`,numeric:()=>`Invalid numeric string`,regex:()=>`Invalid format`,semver:()=>`Invalid semver`,slug:()=>`Invalid slug`,startsWith:({prefix:e})=>`Must start with "${e}"`,time:()=>`Invalid time`,type:()=>`Expected string`,ulid:()=>`Invalid ULID`,url:()=>`Invalid URL`,uuid:()=>`Invalid UUID`},tuple:{length:({exact:e})=>`Expected tuple of length ${e}`,min:({min:e})=>`Expected tuple with at least ${e} items`,type:()=>`Expected array`},union:{invalid:()=>`Does not match any of the expected types`},variant:{invalidDiscriminator:({discriminator:e,expected:t})=>`Invalid discriminator value at "${e}": expected ${t.map(e=>JSON.stringify(e)).join(` | `)}`,type:()=>`Expected object`}};function g(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _(e,t){let n=m(e);for(let[e,r]of Object.entries(t)){if(r===void 0)continue;if(d(e)){`${e}`;continue}let t=n[e];g(t)&&g(r)?f(n,e,_(t,r)):f(n,e,r)}return n}function v(e={}){return{messages:_(h,e)}}function y(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function b(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;for(let t of Object.values(e))b(t);return Object.freeze(e)}function x(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(e=>x(e));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){let t=new Map;for(let[n,r]of e.entries())t.set(x(n),x(r));return t}if(e instanceof Set)return new Set([...e.values()].map(e=>x(e)));if(y(e)){let t={};for(let[n,r]of Object.entries(e))f(t,n,x(r));return t}return e}function ee(){return{hasAsyncChecks:!1,hasRuntimeChecks:!1,isNullable:!1,isOptional:!1,postprocessors:[],preprocessors:[],validators:[]}}function S(e){return{catch:e.catch,defaultValue:e.defaultValue,description:e.description,hasAsyncChecks:e.hasAsyncChecks,hasRuntimeChecks:e.hasRuntimeChecks,isNullable:e.isNullable,isOptional:e.isOptional,postprocessors:[...e.postprocessors],preprocessors:[...e.preprocessors],validators:[...e.validators]}}function C(e){return e?{messages:e}:v()}function w(t,n,r){let i=[...n];return typeof t==`string`?i.push({code:e.custom,message:t,path:[]}):t===!1&&i.length===0&&i.push({code:e.custom,message:r.messages.check.default(),path:[]}),i.length?i:null}var T=class{state;_annotations={};_typeValidator=null;constructor(e){this.state=ee(),this._typeValidator=e??null}parse(t,n){if(this.state.hasAsyncChecks)throw new l([{code:e.custom,message:`parse() cannot evaluate async checks. Use parseAsync().`,path:[]}]);let r=n??C();return this._withCatch(()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let i=this._parse(n.value,r);if(i instanceof Promise)throw new l([{code:e.custom,message:`parse() received an async schema. Use parseAsync() instead.`,path:[]}]);let a=i,o=a.typeOk?this._runValidatorsSync(a.data,r):[],s=[...a.issues,...o];if(s.length)throw new l(s);return this._runPostprocessors(a.data)})}safeParse(e,t){try{return{data:this.parse(e,t),success:!0}}catch(e){if(e instanceof l)return{error:e,success:!1};throw e}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=await this._parse(t.value,n),i=r.typeOk?await this._runValidatorsAsync(r.data,n):[],a=[...r.issues,...i];if(a.length)throw new l(a);return this._runPostprocessors(r.data)})}async safeParseAsync(e,t){try{return{data:await this.parseAsync(e,t),success:!0}}catch(e){if(e instanceof l)return{error:e,success:!1};throw e}}_parseFullSync(t,n){if(this.state.hasAsyncChecks)throw new l([{code:e.custom,message:`Sync parsing cannot evaluate async checks. Use parseAsync().`,path:[]}]);let r=n??C(),i=this._prepareInput(t);if(i.skip)return{data:i.value,issues:[]};let a=this._parse(i.value,r);if(a instanceof Promise)throw new l([{code:e.custom,message:`Sync parse path received an async schema. Use parseAsync() instead.`,path:[]}]);let o=a,s=o.typeOk?this._runValidatorsSync(o.data,r):[],c=[...o.issues,...s];return c.length>0?this.state.catch?{data:this.state.catch(),issues:[]}:{data:o.data,issues:c}:{data:this._runPostprocessors(o.data),issues:[]}}async _parseFullAsync(e,t){let n=t??C(),r=this._prepareInput(e);if(r.skip)return{data:r.value,issues:[]};let i=await this._parse(r.value,n),a=i.typeOk?await this._runValidatorsAsync(i.data,n):[],o=[...i.issues,...a];return o.length>0?this.state.catch?{data:this.state.catch(),issues:[]}:{data:i.data,issues:o}:{data:this._runPostprocessors(i.data),issues:[]}}check(e){return this._addCheck(e,!1)}checkAsync(e){return this._addCheck(e,!0)}_addCheck(e,t){let n=this._addConstraint((t,n)=>{let r=[],i=e(t,{addIssue:e=>r.push({...e,path:e.path??[]})});return i instanceof Promise?i.then(e=>w(e,r,n)):w(i,r,n)});return n.state.hasRuntimeChecks=!0,t&&(n.state.hasAsyncChecks=!0),n}optional(){let e=this._clone();return e.state.isOptional=!0,e}nullable(){let e=this._clone();return e.state.isNullable=!0,e}nullish(){let e=this._clone();return e.state.isOptional=!0,e.state.isNullable=!0,e}required(){let e=this._clone();return e.state.isOptional=!1,e}default(e){let t=this._clone();return t.state.defaultValue=typeof e==`function`?e:()=>x(e),t}catch(e){let t=this._clone();return t.state.catch=typeof e==`function`?e:()=>x(e),t}transform(e){let t=this._clone();return t.state.postprocessors.push(e),t}preprocess(e){let t=this._clone();return t.state.preprocessors.push(e),t}pipe(e){return new E(this,e)}label(e){let t=this._clone();return t.state.description=e,t}definition(){if(this.state.catch||this.state.defaultValue||this.state.postprocessors.length>0||this.state.preprocessors.length>0||this.state.hasRuntimeChecks)throw new c(`Schemas with checks, transforms, defaults, catches, or preprocessors have no declarative definition.`);return b(this._toDescriptorImpl())}get description(){return this.state.description}get isOptional(){return this.state.isOptional}get isNullable(){return this.state.isNullable}is(e){return this.safeParse(e).success}assert(e,t){let n=this._parseFullSync(e);if(n.issues.length!==0)throw new l(t?n.issues.map(e=>({...e,message:e.path.length===0?`${t}: ${e.message}`:e.message})):n.issues)}walk(e){return this._walk(e)}get kind(){return this._kind}get _kind(){return`any`}_describeBase(){return{...this.state.description===void 0?{}:{description:this.state.description},...this.state.isNullable?{isNullable:!0}:{},...this.state.isOptional?{isOptional:!0}:{}}}_addConstraint(e,t){let n=this._clone();return n.state.validators.push(e),t&&(n._annotations=t({...n._annotations})),n}_construct(e){let t=Object.assign(Object.create(Object.getPrototypeOf(this)),this,{state:e});return t._annotations={...this._annotations},t}_clone(){return this._construct(S(this.state))}_copyStateTo(e){return e.state=S(this.state),e}_walk(e){return e.unknown?e.unknown(this):null}_toDescriptorImpl(){return{...this._describeBase(),kind:`any`}}_withCatch(e){if(!this.state.catch)return e();try{return e()}catch(e){if(e instanceof l)return this.state.catch();throw e}}async _withCatchAsync(e){if(!this.state.catch)return e();try{return await e()}catch(e){if(e instanceof l)return this.state.catch();throw e}}_prepareInput(e){let t=this._runPreprocessors(e),n=t===void 0&&this.state.defaultValue?this.state.defaultValue():t;return this.state.isOptional&&n===void 0||this.state.isNullable&&n===null?{skip:!0,value:n}:{skip:!1,value:n}}_runPreprocessors(e){let t=e;for(let e of this.state.preprocessors)t=e(t);return t}_runPostprocessors(e){let t=e;for(let e of this.state.postprocessors)t=e(t);return t}_runValidatorsSync(t,n){if(this._typeValidator){let r=this._typeValidator(t,n);if(r instanceof Promise)throw new l([{code:e.custom,message:`Type validator returned a Promise. Use parseAsync() for async validation.`,path:[]}]);if(r&&r.length>0)return r}let r=[];for(let i of this.state.validators){let a=i(t,n);if(a instanceof Promise)throw new l([{code:e.custom,message:`Sync parsing received an async check. Use checkAsync() and parseAsync().`,path:[]}]);a&&r.push(...a)}return r}async _runValidatorsAsync(e,t){if(this._typeValidator){let n=await this._typeValidator(e,t);if(n&&n.length>0)return n}let n=[];for(let r of this.state.validators){let i=await r(e,t);i&&n.push(...i)}return n}_parse(e,t){return{data:e,issues:[],typeOk:!0}}},E=class extends T{from;to;get _kind(){return`pipe`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.from=e,this.to=t}_parse(e,t){let n=this.from._parseFullSync(e,t);if(n instanceof Promise)return n.then(n=>n.issues.length>0?{data:e,issues:n.issues,typeOk:!1}:this.to._parseFullAsync(n.data,t).then(e=>e.issues.length>0?{data:n.data,issues:e.issues,typeOk:!1}:{data:e.data,issues:[],typeOk:!0}));if(n.issues.length>0)return{data:e,issues:n.issues,typeOk:!1};let r=this.to._parseFullSync(n.data,t);return r instanceof Promise?r.then(e=>e.issues.length>0?{data:n.data,issues:e.issues,typeOk:!1}:{data:e.data,issues:[],typeOk:!0}):r.issues.length>0?{data:n.data,issues:r.issues,typeOk:!1}:{data:r.data,issues:[],typeOk:!0}}async parseAsync(e,t){let n=t??C(),r=await this.from._parseFullAsync(e,n);if(r.issues.length>0)throw new l(r.issues);let i=await this.to._parseFullAsync(r.data,n);if(i.issues.length>0)throw new l(i.issues);let a=await this._runValidatorsAsync(i.data,n);if(a.length>0)throw new l(a);return this._runPostprocessors(i.data)}_walk(e){let t=this.from.walk(e),n=this.to.walk(e);return e.pipe?e.pipe(this,t,n):super._walk(e)}_toDescriptorImpl(){return{...this._describeBase(),from:this.from.definition(),kind:`pipe`,to:this.to.definition()}}},D=class extends T{itemSchema;get _kind(){return`array`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.itemSchema=e}_parseItemsSync(e,t){let n=[],r=[];for(let a=0;a<e.length;a++){let o=this.itemSchema._parseFullSync(e[a],t);o.issues.length===0?r.push(o.data):(n.push(...i(o.issues,a)),r.push(e[a]))}return{data:r,issues:n}}_parse(t,r){if(!Array.isArray(t))return{data:t,issues:n(e.invalid_type,r.messages.array.type()),typeOk:!1};let{data:i,issues:a}=this._parseItemsSync(t,r);return{data:i,issues:a,typeOk:!0}}async parseAsync(t,r){let a=r??C();return this._withCatchAsync(async()=>{let r=this._prepareInput(t);if(r.skip)return r.value;let o=r.value;if(!Array.isArray(o))throw new l(n(e.invalid_type,a.messages.array.type()));let s=await Promise.all(o.map(e=>this.itemSchema._parseFullAsync(e,a))),c=[],u=[];for(let e=0;e<s.length;e++){let t=s[e];t.issues.length===0?u.push(t.data):(c.push(...i(t.issues,e)),u.push(o[e]))}let d=await this._runValidatorsAsync(u,a),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>a.length>=t?null:n(e.too_small,r(i??o.messages.array.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minItems:n.minItems===void 0?t:Math.max(n.minItems,t)}})}max(t,i){return this._addConstraint((a,o)=>a.length<=t?null:n(e.too_big,r(i??o.messages.array.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maxItems:n.maxItems===void 0?t:Math.min(n.maxItems,t)}})}length(t,i){return this._addConstraint((a,o)=>a.length===t?null:n(e.invalid_length,r(i??o.messages.array.length,{exact:t,value:a}),{exact:t}),e=>({...e,maxItems:t,minItems:t}))}nonEmpty(t){return this._addConstraint((i,a)=>{let o=i;return o.length>0?null:n(e.too_small,r(t??a.messages.array.nonEmpty,{min:1,value:o}),{min:1})})}unique(t,i){let a=typeof t==`function`&&t.length===2,o=a?t:null,s=a?i:typeof t==`function`?t:void 0;return this._addConstraint((t,i)=>{let a=t,c;return c=o?a.every((e,t)=>a.slice(0,t).every(t=>!o(e,t))):new Set(a).size===a.length,c?null:n(e.invalid_unique,r(s??i.messages.array.unique,{value:a}),{unique:!0})})}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.maxItems===void 0?{}:{maxItems:e.maxItems},...e.minItems===void 0?{}:{minItems:e.minItems},items:this.itemSchema.definition(),kind:`array`}}_walk(e){let t=this.itemSchema.walk(e);return e.array?e.array(this,t):super._walk(e)}},O=class t extends T{get _kind(){return`bigint`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`bigint`?null:n(e.invalid_type,r.messages.bigint.type()))}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s>=t?null:n(e.too_small,r(i??o.messages.bigint.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s<=t?null:n(e.too_big,r(i??o.messages.bigint.max,{max:t,value:s}),{max:t})})}positive(t){return this._addConstraint((i,a)=>{let o=i;return o>0n?null:n(e.too_small,r(t??a.messages.bigint.positive,{value:o}),{exclusive:!0,min:0n})})}negative(t){return this._addConstraint((i,a)=>{let o=i;return o<0n?null:n(e.too_big,r(t??a.messages.bigint.negative,{value:o}),{exclusive:!0,max:0n})})}nonNegative(t){return this._addConstraint((i,a)=>{let o=i;return o>=0n?null:n(e.too_small,r(t??a.messages.bigint.nonNegative,{value:o}),{min:0n})})}nonPositive(t){return this._addConstraint((i,a)=>{let o=i;return o<=0n?null:n(e.too_big,r(t??a.messages.bigint.nonPositive,{value:o}),{max:0n})})}multipleOf(t,i){return this._addConstraint((a,o)=>{let s=a;return s%t===0n?null:n(e.invalid_multiple_of,r(i??o.messages.bigint.multipleOf,{step:t,value:s}),{step:t})})}_walk(e){return e.bigint?e.bigint(this):super._walk(e)}coerce(){return t.coerce()}_toDescriptorImpl(){return this.state.validators.length,{...this._describeBase(),kind:`bigint`}}static coerce(){return new t().preprocess(e=>{if(typeof e==`bigint`)return e;if(typeof e==`number`){if(!Number.isFinite(e)||!Number.isInteger(e))return e;try{return BigInt(e)}catch{return e}}if(typeof e==`string`){let t=e.trim();if(t.length===0||t.length>1e3)return e;try{return BigInt(t)}catch{return e}}return e})}},k=class t extends T{get _kind(){return`boolean`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,n)=>typeof t==`boolean`?null:[{code:e.invalid_type,message:n.messages.boolean.type(),path:[]}])}coerce(){return t.coerce()}_toDescriptorImpl(){return{...this._describeBase(),kind:`boolean`}}_walk(e){return e.boolean?e.boolean(this):super._walk(e)}static coerce(){return new t().preprocess(e=>typeof e==`boolean`?e:e===`true`||e===`1`||e===1?!0:e===`false`||e===`0`||e===0?!1:e)}},A=class t extends T{get _kind(){return`date`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>t instanceof Date&&!Number.isNaN(t.getTime())?null:n(e.invalid_date,r.messages.date.type()))}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s>=t?null:n(e.too_small,r(i??o.messages.date.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s<=t?null:n(e.too_big,r(i??o.messages.date.max,{max:t,value:s}),{max:t})})}coerce(){return t.coerce()}_toDescriptorImpl(){return{...this._describeBase(),kind:`date`}}_walk(e){return e.date?e.date(this):super._walk(e)}static coerce(){return new t().preprocess(e=>e instanceof Date?e:typeof e==`string`||typeof e==`number`?new Date(e):e)}};function j(t){let n=new Set(t);return(r,i)=>n.has(r)?null:[{code:e.invalid_enum,message:i.messages.enum.invalid({values:t}),params:{values:t},path:[]}]}var M=class extends T{values;get _kind(){return`enum`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(j(e)),this.values=e}_toDescriptorImpl(){return{...this._describeBase(),kind:`enum`,values:this.values}}_walk(e){return e.enum?e.enum(this):super._walk(e)}},te=class extends T{cls;get _kind(){return`instanceof`}checkAsync(e){return this._addCheck(e,!0)}constructor(t){super((n,r)=>n instanceof t?null:[{code:e.invalid_type,message:r.messages.instanceof.type({className:t.name}),path:[]}]),this.cls=t}_toDescriptorImpl(){return{...this._describeBase(),className:this.cls.name,kind:`instanceof`}}_walk(e){return e.instanceof?e.instanceof(this):super._walk(e)}};function N(e,t){if(y(e)&&y(t)){let n=m(e);for(let[r,i]of Object.entries(t))f(n,r,N(e[r],i));return n}return t}var P=class extends T{schemas;get _kind(){return`intersect`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.schemas=Object.freeze([...e])}_parse(e,t){let n={hasOutput:!1,issues:[],output:e};for(let r=0;r<this.schemas.length;r++){let i=this.schemas[r]._parseFullSync(e,t);i.issues.length>0?n.issues.push(...i.issues):n.hasOutput?n.output=N(n.output,i.data):(n.hasOutput=!0,n.output=i.data)}return{data:n.output,issues:n.issues,typeOk:n.issues.length===0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r={hasOutput:!1,issues:[],output:t.value};for(let e=0;e<this.schemas.length;e++){let i=await this.schemas[e]._parseFullAsync(t.value,n);i.issues.length>0?r.issues.push(...i.issues):r.hasOutput?r.output=N(r.output,i.data):(r.hasOutput=!0,r.output=i.data)}if(r.issues.length>0)throw new l(r.issues);let i=await this._runValidatorsAsync(r.output,n);if(i.length)throw new l(i);return this._runPostprocessors(r.output)})}_toDescriptorImpl(){return{...this._describeBase(),branches:this.schemas.map(e=>e.definition()),kind:`intersect`}}_walk(e){let t=this.schemas.map(t=>t.walk(e));return e.intersect?e.intersect(this,t):super._walk(e)}},F=class e extends T{_getter;_resolved;get _kind(){return`lazy`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this._getter=e}_resolve(){return this._resolved??=this._getter()}_parse(e,t){let n=this._resolve()._parseFullSync(e,t);return n.issues.length===0?{data:n.data,issues:[],typeOk:!0}:{data:e,issues:n.issues,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=await this._resolve()._parseFullAsync(t.value,n);if(r.issues.length>0)throw new l(r.issues);let i=await this._runValidatorsAsync(r.data,n);if(i.length>0)throw new l(i);return this._runPostprocessors(r.data)})}_toDescriptorImpl(){return{...this._describeBase(),kind:`lazy`}}_walk(e){return e.lazy?e.lazy(this):super._walk(e)}_construct(t){let n=new e(this._getter);return n.state=t,n}},I=class extends T{value;get _kind(){return`literal`}checkAsync(e){return this._addCheck(e,!0)}constructor(t){super((n,r)=>n===t?null:[{code:e.invalid_literal,message:r.messages.literal.expected({expected:t}),params:{expected:t},path:[]}]),this.value=t}_toDescriptorImpl(){return{...this._describeBase(),kind:`literal`,value:this.value}}_walk(e){return e.literal?e.literal(this):super._walk(e)}},L=class extends T{keySchema;valueSchema;get _kind(){return`map`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.keySchema=e,this.valueSchema=t}_parse(t,n){if(!(t instanceof Map))return{data:t,issues:[{code:e.invalid_type,message:n.messages.map.type(),path:[]}],typeOk:!1};let r=new Map,a=[],o=0;for(let[e,s]of t){let t=this.keySchema._parseFullSync(e,n),c=this.valueSchema._parseFullSync(s,n);t.issues.length>0&&a.push(...i(t.issues,o)),c.issues.length>0&&a.push(...i(c.issues,o)),t.issues.length===0&&c.issues.length===0&&r.set(t.data,c.data),o+=1}return{data:r,issues:a,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!(a instanceof Map))throw new l([{code:e.invalid_type,message:r.messages.map.type(),path:[]}]);let o=[...a],s=await Promise.all(o.map(([e,t])=>Promise.all([this.keySchema._parseFullAsync(e,r),this.valueSchema._parseFullAsync(t,r)]))),c=[],u=new Map;for(let e=0;e<s.length;e++){let[t,n]=s[e];t.issues.length>0&&c.push(...i(t.issues,e)),n.issues.length>0&&c.push(...i(n.issues,e)),t.issues.length===0&&n.issues.length===0&&u.set(t.data,n.data)}let d=await this._runValidatorsAsync(u,r),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size>=t?null:n(e.too_small,r(i??o.messages.map.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size<=t?null:n(e.too_big,r(i??o.messages.map.max,{max:t,value:s}),{max:t})})}size(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size===t?null:n(e.invalid_length,r(i??o.messages.map.size,{exact:t,value:s}),{exact:t})})}nonEmpty(t){return this._addConstraint((i,a)=>i.size>0?null:n(e.too_small,r(t??a.messages.map.nonEmpty,{min:1}),{min:1}))}_toDescriptorImpl(){return{...this._describeBase(),key:this.keySchema.definition(),kind:`map`,value:this.valueSchema.definition()}}_walk(e){let t=this.keySchema.walk(e),n=this.valueSchema.walk(e);return e.map?e.map(this,t,n):super._walk(e)}},R=class extends T{get _kind(){return`never`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,n)=>[{code:e.invalid_type,message:n.messages.never.invalid(),path:[]}])}_toDescriptorImpl(){return{...this._describeBase(),kind:`never`}}_walk(e){return e.never?e.never(this):super._walk(e)}},z=class t extends T{get _kind(){return`number`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`number`&&!Number.isNaN(t)?null:n(e.invalid_type,r.messages.number.type()))}min(t,i){return this._addConstraint((a,o)=>a>=t?null:n(e.too_small,r(i??o.messages.number.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minimum:n.minimum===void 0?t:Math.max(n.minimum,t)}})}max(t,i){return this._addConstraint((a,o)=>a<=t?null:n(e.too_big,r(i??o.messages.number.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maximum:n.maximum===void 0?t:Math.min(n.maximum,t)}})}int(t){return this._addConstraint((i,a)=>Number.isInteger(i)?null:n(e.invalid_integer,r(t??a.messages.number.int,{value:i})),e=>({...e,typeHint:`integer`}))}positive(t){return this._addConstraint((i,a)=>i>0?null:n(e.too_small,r(t??a.messages.number.positive,{value:i}),{exclusive:!0,min:0}),e=>{let t=e;return{...t,exclusiveMinimum:t.exclusiveMinimum===void 0?0:Math.max(t.exclusiveMinimum,0)}})}negative(t){return this._addConstraint((i,a)=>i<0?null:n(e.too_big,r(t??a.messages.number.negative,{value:i}),{exclusive:!0,max:0}),e=>{let t=e;return{...t,exclusiveMaximum:t.exclusiveMaximum===void 0?0:Math.min(t.exclusiveMaximum,0)}})}nonNegative(t){return this._addConstraint((i,a)=>i>=0?null:n(e.too_small,r(t??a.messages.number.nonNegative,{value:i}),{min:0}),e=>{let t=e;return{...t,minimum:t.minimum===void 0?0:Math.max(t.minimum,0)}})}nonPositive(t){return this._addConstraint((i,a)=>i<=0?null:n(e.too_big,r(t??a.messages.number.nonPositive,{value:i}),{max:0}),e=>{let t=e;return{...t,maximum:t.maximum===void 0?0:Math.min(t.maximum,0)}})}multipleOf(t,i){return this._addConstraint((a,o)=>Math.abs(Math.round(a/t)-a/t)<1e-9?null:n(e.invalid_multiple_of,r(i??o.messages.number.multipleOf,{step:t,value:a}),{step:t}),e=>({...e,multipleOf:t}))}safe(t){return this._addConstraint((i,a)=>Number.isSafeInteger(i)?null:n(e.invalid_safe,r(t??a.messages.number.safe,{value:i})))}finite(t){return this._addConstraint((i,a)=>Number.isFinite(i)?null:n(e.invalid_finite,r(t??a.messages.number.finite,{value:i})))}coerce(){return t.coerce()}_walk(e){return e.number?e.number(this):super._walk(e)}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.exclusiveMaximum===void 0?{}:{exclusiveMaximum:e.exclusiveMaximum},...e.exclusiveMinimum===void 0?{}:{exclusiveMinimum:e.exclusiveMinimum},...e.maximum===void 0?{}:{maximum:e.maximum},...e.minimum===void 0?{}:{minimum:e.minimum},...e.multipleOf===void 0?{}:{multipleOf:e.multipleOf},...e.typeHint===void 0?{}:{typeHint:e.typeHint},kind:`number`}}static coerce(){return new t().preprocess(e=>{if(typeof e==`number`)return e;if(typeof e==`string`||typeof e==`boolean`){let t=Number(e);return Number.isNaN(t)?e:t}return e})}},B=class extends T{schemas;get _kind(){return`union`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.schemas=Object.freeze([...e])}_parse(t,n){let r=[];for(let e of this.schemas){let i=e._parseFullSync(t,n);if(i.issues.length===0)return{data:i.data,issues:[],typeOk:!0};r.push(i.issues)}return{data:t,issues:[{code:e.invalid_union,message:n.messages.union.invalid(),params:{errors:r},path:[]}],typeOk:!1}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let i=n.value,a=[];for(let e of this.schemas){let t=await e._parseFullAsync(i,r);if(t.issues.length>0){a.push(t.issues);continue}let n=await this._runValidatorsAsync(t.data,r);if(n.length>0)throw new l(n);return this._runPostprocessors(t.data)}throw new l([{code:e.invalid_union,message:r.messages.union.invalid(),params:{errors:a},path:[]}])})}_toDescriptorImpl(){return{...this._describeBase(),branches:this.schemas.map(e=>e.definition()),kind:`union`}}_walk(e){let t=this.schemas.map(t=>t.walk(e));return e.union?e.union(this,t):super._walk(e)}},V=class t extends T{shape;_isRelaxed;get _kind(){return`object`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t=!1){super(),this.shape=Object.freeze(p(Object.entries(e))),this._isRelaxed=t}_unknownKeys(e){return Object.keys(e).filter(e=>!Object.hasOwn(this.shape,e))}_strictUnknownKeyIssues(t,n){if(this._isRelaxed)return[];let r=this._unknownKeys(t);return r.length===0?[]:[{code:e.invalid_keys,message:n.messages.object.invalidKeys({keys:r}),params:{keys:r},path:[]}]}_copyRelaxedUnknownKeys(e,t){if(this._isRelaxed)for(let n of this._unknownKeys(e))d(n)||f(t,n,e[n])}_guardObjectInput(t,n){return typeof t!=`object`||!t||Array.isArray(t)?{issues:[{code:e.invalid_type,message:n.messages.object.type(),path:[]}],ok:!1}:{obj:t,ok:!0}}_createObjectParseContext(e,t){return{issues:[...this._strictUnknownKeyIssues(e,t)],output:{}}}_rebuildWith(e,n=this._isRelaxed){return this._copyStateTo(new t(e,n))}_parse(e,t){let n=this._guardObjectInput(e,t);if(!n.ok)return{data:e,issues:n.issues,typeOk:!1};let{obj:r}=n,{issues:a,output:o}=this._createObjectParseContext(r,t);for(let e of Object.keys(this.shape)){let n=this.shape[e]._parseFullSync(r[e],t);n.issues.length===0?f(o,e,n.data):a.push(...i(n.issues,e))}return this._copyRelaxedUnknownKeys(r,o),{data:o,issues:a,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._guardObjectInput(t.value,n);if(!r.ok)throw new l(r.issues);let{obj:a}=r,{issues:o,output:s}=this._createObjectParseContext(a,n),c=Object.keys(this.shape),u=await Promise.all(c.map(e=>this.shape[e]._parseFullAsync(a[e],n)));for(let e=0;e<c.length;e++){let t=c[e],n=u[e];n.issues.length===0?f(s,t,n.data):o.push(...i(n.issues,t))}this._copyRelaxedUnknownKeys(a,s);let d=await this._runValidatorsAsync(s,n),p=[...o,...d];if(p.length>0)throw new l(p);return this._runPostprocessors(s)})}partial(...e){let t=e.length>0?new Set(e):null;return this._rebuildWith(p(Object.entries(this.shape).map(([e,n])=>[e,t===null||t.has(e)?n.optional():n])),this._isRelaxed)}optional(){return super.optional()}nullable(){return super.nullable()}nullish(){return super.nullish()}required(){return this._rebuildWith(p(Object.entries(this.shape).map(([e,t])=>[e,t.required()])),this._isRelaxed)}extend(e){return this._rebuildWith(p([...Object.entries(this.shape),...Object.entries(e)]),this._isRelaxed)}pick(...e){let t=new Set(e);return this._rebuildWith(p(Object.entries(this.shape).filter(([e])=>t.has(e))))}omit(...e){let t=new Set(e);return this._rebuildWith(p(Object.entries(this.shape).filter(([e])=>!t.has(e))))}defaults(){return this.parse({})}partialDefaults(){let e={};for(let t of Object.keys(this.shape)){let n=this.shape[t]._parseFullSync(void 0);n.issues.length===0&&f(e,t,n.data)}return e}requiredFields(){return Object.keys(this.shape).filter(e=>!this.shape[e].isOptional)}optionalFields(){return Object.keys(this.shape).filter(e=>this.shape[e].isOptional)}relaxed(){return this._rebuildWith(this.shape,!0)}strict(){return this._rebuildWith(this.shape,!1)}keyof(){return new B(Object.keys(this.shape).map(e=>new I(e)))}_toDescriptorImpl(){let e={};for(let[t,n]of Object.entries(this.shape))f(e,t,n.definition());return{...this._describeBase(),fields:e,kind:`object`,strict:!this._isRelaxed}}_walk(e){let t=p(Object.entries(this.shape).map(([t,n])=>[t,n.walk(e)]));return e.object?e.object(this,t):super._walk(e)}merge(e){return this._rebuildWith(p([...Object.entries(this.shape),...Object.entries(e.shape)]),e._isRelaxed)}};function H(e){return e.map(e=>e instanceof T?e:new I(e))}var U=class extends T{keySchema;valueSchema;get _kind(){return`record`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.keySchema=e,this.valueSchema=t}_guardRecordInput(t,n){return typeof t!=`object`||!t||Array.isArray(t)?{issues:[{code:e.invalid_type,message:n.messages.object.type(),path:[]}],ok:!1}:{ok:!0,value:t}}_parseRecordEntries(e,t){let n=[],r={};for(let a of Object.keys(e)){let o=this.keySchema._parseFullSync(a,t);if(o.issues.length>0){n.push(...i(o.issues,a));continue}let s=o.data;if(d(s))continue;let c=this.valueSchema._parseFullSync(e[a],t);c.issues.length===0?f(r,s,c.data):n.push(...i(c.issues,a))}return{issues:n,output:r}}_parse(e,t){let n=this._guardRecordInput(e,t);if(!n.ok)return{data:e,issues:n.issues,typeOk:!1};let{issues:r,output:i}=this._parseRecordEntries(n.value,t);return{data:i,issues:r,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._guardRecordInput(t.value,n);if(!r.ok)throw new l(r.issues);let a=r.value,o=Object.keys(a),s=await Promise.all(o.map(e=>Promise.all([this.keySchema._parseFullAsync(e,n),this.valueSchema._parseFullAsync(a[e],n)]))),c=[],u={};for(let e=0;e<o.length;e++){let t=o[e],[n,r]=s[e];if(n.issues.length>0){c.push(...i(n.issues,t));continue}let a=n.data;d(a)||(r.issues.length===0?f(u,a,r.data):c.push(...i(r.issues,t)))}let p=await this._runValidatorsAsync(u,n),m=[...c,...p];if(m.length>0)throw new l(m);return this._runPostprocessors(u)})}_toDescriptorImpl(){return{...this._describeBase(),key:this.keySchema.definition(),kind:`record`,value:this.valueSchema.definition()}}_walk(e){let t=this.keySchema.walk(e),n=this.valueSchema.walk(e);return e.record?e.record(this,t,n):super._walk(e)}},W=class extends T{itemSchema;get _kind(){return`set`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.itemSchema=e}_parse(t,n){if(!(t instanceof Set))return{data:t,issues:[{code:e.invalid_type,message:n.messages.set.type(),path:[]}],typeOk:!1};let r=[],a=new Set,o=0;for(let e of t){let t=this.itemSchema._parseFullSync(e,n);t.issues.length===0?a.add(t.data):r.push(...i(t.issues,o)),o+=1}return{data:a,issues:r,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!(a instanceof Set))throw new l([{code:e.invalid_type,message:r.messages.set.type(),path:[]}]);let o=[...a],s=await Promise.all(o.map(e=>this.itemSchema._parseFullAsync(e,r))),c=[],u=new Set;for(let e=0;e<s.length;e++){let t=s[e];t.issues.length===0?u.add(t.data):c.push(...i(t.issues,e))}let d=await this._runValidatorsAsync(u,r),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size>=t?null:n(e.too_small,r(i??o.messages.set.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size<=t?null:n(e.too_big,r(i??o.messages.set.max,{max:t,value:s}),{max:t})})}size(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size===t?null:n(e.invalid_length,r(i??o.messages.set.size,{exact:t,value:s}),{exact:t})})}nonEmpty(t){return this._addConstraint((i,a)=>i.size>0?null:n(e.too_small,r(t??a.messages.set.nonEmpty,{min:1}),{min:1}))}_toDescriptorImpl(){return{...this._describeBase(),items:this.itemSchema.definition(),kind:`set`}}_walk(e){let t=this.itemSchema.walk(e);return e.set?e.set(this,t):super._walk(e)}};function G(e){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)}var K=new Set([`http`,`https`]);function q(e,t){try{let n=new URL(e);return(t?new Set(t.map(e=>e.toLowerCase())):K).has(n.protocol.replace(`:`,``).toLowerCase())}catch{return!1}}function J(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}function Y(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;let t=new Date(e);return!Number.isNaN(t.getTime())&&t.toISOString().startsWith(e)}function ne(e){return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})?$/.test(e)&&!Number.isNaN(new Date(e).getTime())}function X(e){if(/^(\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>{let t=parseInt(e,10);return t>=0&&t<=255});try{return new URL(`http://[${e}]/`),!0}catch{return!1}}function Z(e){return/^c[a-z0-9]{8,}$/.test(e)}function re(e){return/^[a-z][a-z0-9]{23}$/.test(e)}function ie(e){return/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(e)}function ae(e,t=21){return e.length===t&&/^[A-Za-z0-9_-]+$/.test(e)}function oe(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(e)}function se(e){return e.length===0||e.length%4==1?!1:/^[A-Za-z0-9_-]*={0,2}$/.test(e)}function ce(e){return/^[A-Fa-f0-9]+$/.test(e)}function le(e){return/^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)}function ue(e){return/^\p{Extended_Pictographic}+$/u.test(e)}function de(e){return/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e)}function fe(e){return/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(e)}function pe(e){return/^P(?=\d|T\d)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+(?:\.\d+)?S)?)?$/.test(e)}function me(e){return/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/.test(e)}function Q(e){return/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e)}function he(e){return/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i.test(e)}var $=class t extends T{get _kind(){return`string`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`string`?null:n(e.invalid_type,r.messages.string.type()))}min(t,i){return this._addConstraint((a,o)=>a.length>=t?null:n(e.too_small,r(i??o.messages.string.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minLength:n.minLength===void 0?t:Math.max(n.minLength,t)}})}max(t,i){return this._addConstraint((a,o)=>a.length<=t?null:n(e.too_big,r(i??o.messages.string.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maxLength:n.maxLength===void 0?t:Math.min(n.maxLength,t)}})}length(t,i){return this._addConstraint((a,o)=>a.length===t?null:n(e.invalid_length,r(i??o.messages.string.length,{exact:t,value:a}),{exact:t}),e=>({...e,maxLength:t,minLength:t}))}nonEmpty(t){return this._addConstraint((i,a)=>i.length>0?null:n(e.too_small,r(t??a.messages.string.nonEmpty,{min:1,value:i}),{min:1}),e=>{let t=e;return{...t,minLength:Math.max(t.minLength??0,1)}})}startsWith(t,i){return this._addConstraint((a,o)=>a.startsWith(t)?null:n(e.invalid_string,r(i??o.messages.string.startsWith,{prefix:t,value:a}),{prefix:t}))}endsWith(t,i){return this._addConstraint((a,o)=>a.endsWith(t)?null:n(e.invalid_string,r(i??o.messages.string.endsWith,{suffix:t,value:a}),{suffix:t}))}includes(t,i){return this._addConstraint((a,o)=>a.includes(t)?null:n(e.invalid_string,r(i??o.messages.string.includes,{substr:t,value:a}),{includes:t}))}regex(t,i){let a=new RegExp(t.source,t.flags.replace(/[gy]/g,``));return this._addConstraint((t,o)=>a.test(t)?null:n(e.invalid_string,r(i??o.messages.string.regex,{value:t}),{pattern:a.source}),e=>{let t=e;return t.pattern===null?t:t.pattern===void 0?{...t,pattern:a.source}:t.pattern===a.source?t:{...t,pattern:null}})}email(t){return this._addConstraint((i,a)=>G(i)?null:n(e.invalid_string,r(t??a.messages.string.email,{value:i}),{format:`email`}),e=>({...e,format:`email`}))}url(t={}){let{message:i,protocols:a=[`http`,`https`]}=t;return this._addConstraint((t,o)=>q(t,a)?null:n(e.invalid_url,r(i??o.messages.string.url,{value:t}),{format:`url`}),e=>({...e,format:`uri`}))}uuid(t){return this._addConstraint((i,a)=>J(i)?null:n(e.invalid_string,r(t??a.messages.string.uuid,{value:i}),{format:`uuid`}),e=>({...e,format:`uuid`}))}isoDate(t){return this._addConstraint((i,a)=>Y(i)?null:n(e.invalid_string,r(t??a.messages.string.date,{value:i}),{format:`iso-date`}),e=>({...e,format:`date`}))}isoDateTime(t){return this._addConstraint((i,a)=>ne(i)?null:n(e.invalid_string,r(t??a.messages.string.dateTime,{value:i}),{format:`iso-datetime`}),e=>({...e,format:`date-time`}))}ip(t){return this._addConstraint((i,a)=>X(i)?null:n(e.invalid_string,r(t??a.messages.string.ip,{value:i}),{format:`ip`}))}cuid(t){return this._addConstraint((i,a)=>Z(i)?null:n(e.invalid_string,r(t??a.messages.string.cuid,{value:i}),{format:`cuid`}))}cuid2(t){return this._addConstraint((i,a)=>re(i)?null:n(e.invalid_string,r(t??a.messages.string.cuid2,{value:i}),{format:`cuid2`}))}ulid(t){return this._addConstraint((i,a)=>ie(i)?null:n(e.invalid_string,r(t??a.messages.string.ulid,{value:i}),{format:`ulid`}))}nanoid(t,i){return this._addConstraint((a,o)=>ae(a,t)?null:n(e.invalid_string,r(i??o.messages.string.nanoid,{value:a}),{format:`nanoid`}))}base64(t){return this._addConstraint((i,a)=>oe(i)?null:n(e.invalid_base64,r(t??a.messages.string.base64,{value:i}),{format:`base64`}),e=>({...e,contentEncoding:`base64`}))}base64url(t){return this._addConstraint((i,a)=>se(i)?null:n(e.invalid_base64,r(t??a.messages.string.base64url,{value:i}),{format:`base64url`}))}hex(t){return this._addConstraint((i,a)=>ce(i)?null:n(e.invalid_string,r(t??a.messages.string.hex,{value:i}),{format:`hex`}))}hexColor(t){return this._addConstraint((i,a)=>le(i)?null:n(e.invalid_string,r(t??a.messages.string.hexColor,{value:i}),{format:`hex-color`}))}emoji(t){return this._addConstraint((i,a)=>ue(i)?null:n(e.invalid_string,r(t??a.messages.string.emoji,{value:i}),{format:`emoji`}))}jwt(t){return this._addConstraint((i,a)=>de(i)?null:n(e.invalid_string,r(t??a.messages.string.jwt,{value:i}),{format:`jwt`}))}time(t){return this._addConstraint((i,a)=>fe(i)?null:n(e.invalid_string,r(t??a.messages.string.time,{value:i}),{format:`time`}))}duration(t){return this._addConstraint((i,a)=>pe(i)?null:n(e.invalid_duration,r(t??a.messages.string.duration,{value:i}),{format:`duration`}),e=>({...e,format:`duration`}))}semver(t){return this._addConstraint((i,a)=>me(i)?null:n(e.invalid_string,r(t??a.messages.string.semver,{value:i}),{format:`semver`}))}slug(t){return this._addConstraint((i,a)=>Q(i)?null:n(e.invalid_string,r(t??a.messages.string.slug,{value:i}),{format:`slug`}))}numeric(t){return this._addConstraint((i,a)=>he(i)?null:n(e.invalid_string,r(t??a.messages.string.numeric,{value:i}),{format:`numeric`}))}coerce(){return t.coerce()}trim(){return this.preprocess(e=>typeof e==`string`?e.trim():e)}lowercase(){return this.preprocess(e=>typeof e==`string`?e.toLowerCase():e)}uppercase(){return this.preprocess(e=>typeof e==`string`?e.toUpperCase():e)}_walk(e){return e.string?e.string(this):super._walk(e)}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.contentEncoding===void 0?{}:{contentEncoding:e.contentEncoding},...e.format===void 0?{}:{format:e.format},...e.maxLength===void 0?{}:{maxLength:e.maxLength},...e.minLength===void 0?{}:{minLength:e.minLength},...e.pattern===void 0?{}:{pattern:e.pattern},kind:`string`}}static coerce(){return new t().preprocess(e=>e==null?e:String(e))}},ge=class t extends T{items;restSchema;get _kind(){return`tuple`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t=null){super(),this.items=e,this.restSchema=t}rest(e){return this._copyStateTo(new t(this.items,e))}_guardTupleInput(t,n){return this.restSchema===null&&t.length!==this.items.length?{issues:[{code:e.invalid_length,message:n.messages.tuple.length({exact:this.items.length}),params:{exact:this.items.length},path:[]}],ok:!1}:this.restSchema!==null&&t.length<this.items.length?{issues:[{code:e.too_small,message:n.messages.tuple.min({min:this.items.length}),params:{min:this.items.length},path:[]}],ok:!1}:{ok:!0,value:t}}_parse(t,n){if(!Array.isArray(t))return{data:t,issues:[{code:e.invalid_type,message:n.messages.tuple.type(),path:[]}],typeOk:!1};let r=this._guardTupleInput(t,n);if(!r.ok)return{data:t,issues:r.issues,typeOk:!1};let a=[],o=[],s=r.value;for(let e=0;e<this.items.length;e++){let t=this.items[e]._parseFullSync(s[e],n);t.issues.length===0?o.push(t.data):(a.push(...i(t.issues,e)),o.push(s[e]))}if(this.restSchema!==null)for(let e=this.items.length;e<s.length;e++){let t=this.restSchema._parseFullSync(s[e],n);t.issues.length===0?o.push(t.data):(a.push(...i(t.issues,e)),o.push(s[e]))}return{data:o,issues:a,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!Array.isArray(a))throw new l([{code:e.invalid_type,message:r.messages.tuple.type(),path:[]}]);let o=this._guardTupleInput(a,r);if(!o.ok)throw new l(o.issues);let s=o.value,c=[],u=[],d=await Promise.all(this.items.map((e,t)=>e._parseFullAsync(s[t],r)));for(let e=0;e<d.length;e++){let t=d[e];t.issues.length===0?u.push(t.data):(c.push(...i(t.issues,e)),u.push(s[e]))}let f=this.restSchema;if(f!==null){let e=s.slice(this.items.length),t=await Promise.all(e.map(e=>f._parseFullAsync(e,r)));for(let e=0;e<t.length;e++){let n=t[e],r=this.items.length+e;n.issues.length===0?u.push(n.data):(c.push(...i(n.issues,r)),u.push(s[r]))}}let p=await this._runValidatorsAsync(u,r),m=[...c,...p];if(m.length>0)throw new l(m);return this._runPostprocessors(u)})}_toDescriptorImpl(){return{...this._describeBase(),items:this.items.map(e=>e.definition()),kind:`tuple`,rest:this.restSchema===null?null:this.restSchema.definition()}}_walk(e){let t=this.items.map(t=>t.walk(e)),n=this.restSchema===null?null:this.restSchema.walk(e);return e.tuple?e.tuple(this,t,n):super._walk(e)}},_e=class extends T{_map;_discriminator;get _kind(){return`variant`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){let n=new Map;for(let[r,i]of Object.entries(t)){let t=new I(r),o=i.shape[e];if(o&&(!(o instanceof I)||o.value!==r))throw new a(`s.discriminatedUnion(): branch "${r}" defines a conflicting discriminator schema for "${e}".`);let s={[e]:t};n.set(r,o?i:i.extend(s))}super(),this._discriminator=e,this._map=n}get discriminator(){return this._discriminator}get variantMap(){return new Map(this._map)}_resolveVariant(t,n){if(typeof t!=`object`||!t||Array.isArray(t))return{issues:[{code:e.invalid_type,message:n.messages.variant.type(),path:[]}]};let r=t,i=r[this._discriminator],a=this._map.get(i);if(!a){let t=[...this._map.keys()];return{issues:[{code:e.invalid_variant,message:n.messages.variant.invalidDiscriminator({discriminator:this._discriminator,expected:t}),params:{discriminator:this._discriminator,expected:t},path:[]}]}}return{matched:a,obj:r}}_parse(e,t){let n=this._resolveVariant(e,t);if(`issues`in n)return{data:e,issues:n.issues,typeOk:!1};let r=n.matched._parseFullSync(e,t);return r.issues.length===0?{data:r.data,issues:[],typeOk:!0}:{data:e,issues:r.issues,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._resolveVariant(t.value,n);if(`issues`in r)throw new l(r.issues);let i=await r.matched.safeParseAsync(t.value,n);if(!i.success)throw i.error;let a=await this._runValidatorsAsync(i.data,n);if(a.length>0)throw new l(a);return this._runPostprocessors(i.data)})}_toDescriptorImpl(){let e={};for(let[t,n]of this._map.entries())f(e,t,n.definition());return{...this._describeBase(),branches:e,discriminator:this._discriminator,kind:`variant`}}_walk(e){let t=p([...this._map.entries()].map(([t,n])=>[t,n.walk(e)]));return e.variant?e.variant(this,t):super._walk(e)}},ve={any:()=>new T,array:e=>new D(e),bigint:()=>new O,boolean:()=>new k,coerce:{bigint:()=>O.coerce(),boolean:()=>k.coerce(),date:()=>A.coerce(),number:()=>z.coerce(),string:()=>$.coerce()},date:()=>new A,discriminatedUnion:(e,t)=>new _e(e,t),enum:e=>new M(e),instanceof:e=>new te(e),intersect:(...e)=>new P(H(e)),lazy:e=>new F(e),literal:e=>new I(e),map:(e,t)=>new L(e,t),never:()=>new R,null:()=>new I(null),number:()=>new z,object:e=>new V(e),record:(e,t)=>new U(e,t),set:e=>new W(e),string:()=>new $,tuple:e=>new ge(e),undefined:()=>new I(void 0),union:(...e)=>new B(H(e)),unknown:()=>new T},ye={createParseContext:v,fail:n,prependIssuePath:i};exports.ErrorCode=e,exports.PipeSchema=E,exports.Schema=T,exports.SpellDefinitionError=c,exports.SpellError=a,exports.SpellValidationError=l,exports.diagnostics=ye,exports.s=ve,exports.schemaMode=t;
3
3
  //# sourceMappingURL=spell.cjs.map