@vielzeug/spell 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/core.cjs.map +1 -1
  2. package/dist/core.d.ts +4 -4
  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.js +1 -1
  8. package/dist/errors.js.map +1 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/json-schema.cjs.map +1 -1
  14. package/dist/json-schema.d.ts +2 -2
  15. package/dist/json-schema.d.ts.map +1 -1
  16. package/dist/json-schema.js.map +1 -1
  17. package/dist/messages.cjs +1 -1
  18. package/dist/messages.cjs.map +1 -1
  19. package/dist/messages.d.ts.map +1 -1
  20. package/dist/messages.js +1 -1
  21. package/dist/messages.js.map +1 -1
  22. package/dist/schemas/array.cjs.map +1 -1
  23. package/dist/schemas/array.d.ts.map +1 -1
  24. package/dist/schemas/array.js.map +1 -1
  25. package/dist/schemas/bigint.cjs +1 -1
  26. package/dist/schemas/bigint.cjs.map +1 -1
  27. package/dist/schemas/bigint.d.ts.map +1 -1
  28. package/dist/schemas/bigint.js +1 -1
  29. package/dist/schemas/bigint.js.map +1 -1
  30. package/dist/schemas/instanceof.cjs.map +1 -1
  31. package/dist/schemas/instanceof.d.ts.map +1 -1
  32. package/dist/schemas/instanceof.js.map +1 -1
  33. package/dist/schemas/intersect.cjs.map +1 -1
  34. package/dist/schemas/intersect.d.ts.map +1 -1
  35. package/dist/schemas/intersect.js.map +1 -1
  36. package/dist/schemas/lazy.cjs.map +1 -1
  37. package/dist/schemas/lazy.d.ts.map +1 -1
  38. package/dist/schemas/lazy.js.map +1 -1
  39. package/dist/schemas/map.cjs.map +1 -1
  40. package/dist/schemas/map.d.ts.map +1 -1
  41. package/dist/schemas/map.js.map +1 -1
  42. package/dist/schemas/object.cjs.map +1 -1
  43. package/dist/schemas/object.d.ts.map +1 -1
  44. package/dist/schemas/object.js.map +1 -1
  45. package/dist/schemas/record.cjs.map +1 -1
  46. package/dist/schemas/record.d.ts.map +1 -1
  47. package/dist/schemas/record.js.map +1 -1
  48. package/dist/schemas/set.cjs.map +1 -1
  49. package/dist/schemas/set.d.ts.map +1 -1
  50. package/dist/schemas/set.js.map +1 -1
  51. package/dist/schemas/string.cjs +1 -1
  52. package/dist/schemas/string.cjs.map +1 -1
  53. package/dist/schemas/string.d.ts.map +1 -1
  54. package/dist/schemas/string.js +1 -1
  55. package/dist/schemas/string.js.map +1 -1
  56. package/dist/schemas/tuple.cjs.map +1 -1
  57. package/dist/schemas/tuple.d.ts.map +1 -1
  58. package/dist/schemas/tuple.js.map +1 -1
  59. package/dist/schemas/union.cjs.map +1 -1
  60. package/dist/schemas/union.d.ts.map +1 -1
  61. package/dist/schemas/union.js.map +1 -1
  62. package/dist/schemas/variant.cjs +1 -1
  63. package/dist/schemas/variant.cjs.map +1 -1
  64. package/dist/schemas/variant.d.ts +1 -1
  65. package/dist/schemas/variant.d.ts.map +1 -1
  66. package/dist/schemas/variant.js +1 -1
  67. package/dist/schemas/variant.js.map +1 -1
  68. package/dist/spell.cjs +1 -1
  69. package/dist/spell.cjs.map +1 -1
  70. package/dist/spell.iife.js +1 -1
  71. package/dist/spell.iife.js.map +1 -1
  72. package/dist/spell.js +1 -1
  73. package/dist/spell.js.map +1 -1
  74. package/dist/types.cjs.map +1 -1
  75. package/dist/types.d.ts +2 -4
  76. package/dist/types.d.ts.map +1 -1
  77. package/dist/types.js.map +1 -1
  78. package/package.json +31 -24
package/dist/core.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { isPlainObject } from '@vielzeug/arsenal/guards';\n\nimport { SpellDefinitionError, SpellValidationError } from './errors';\nimport { createParseContext } from './messages';\nimport { defineOwnProperty } from './safe-object';\nimport {\n type AnySchema,\n type CheckContext,\n ErrorCode,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type MergeSchemaModes,\n type SchemaMode,\n type Issue,\n type JsonSchema,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDefinition,\n type SchemaDescriptor,\n type SchemaWalker,\n schemaInput,\n schemaMode,\n schemaOutput,\n type ValidateFn,\n type ValidateResult,\n} from './types';\n\nexport {\n ErrorCode,\n type AnySchema,\n type CheckContext,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type MergeSchemaModes,\n type SchemaMode,\n type Issue,\n type JsonSchema,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDefinition,\n type SchemaDescriptor,\n type SchemaWalker,\n schemaMode,\n type ValidateFn,\n type ValidateResult,\n};\n\nexport {\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n fail,\n prependIssuePath,\n resolveMessage,\n} from './errors';\n\nfunction deepFreeze<T>(value: T): T {\n if (value === null || typeof value !== 'object' || Object.isFrozen(value)) return value;\n\n for (const child of Object.values(value as Record<string, unknown>)) deepFreeze(child);\n\n return Object.freeze(value);\n}\n\nfunction materializeValue<T>(value: T): T {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => materializeValue(item)) as T;\n\n if (value instanceof Date) return new Date(value.getTime()) as T;\n\n if (value instanceof Map) {\n const out = new Map<unknown, unknown>();\n\n for (const [key, mapValue] of value.entries()) out.set(materializeValue(key), materializeValue(mapValue));\n\n return out as T;\n }\n\n if (value instanceof Set) return new Set([...value.values()].map((item) => materializeValue(item))) as T;\n\n if (isPlainObject(value)) {\n const out: Record<string, unknown> = {};\n\n for (const [key, entry] of Object.entries(value)) defineOwnProperty(out, key, materializeValue(entry));\n\n return out as T;\n }\n\n return value;\n}\n\n/* -------------------- Schema State -------------------- */\n\ntype Preprocessor = (value: unknown) => unknown;\ntype Postprocessor = (value: unknown) => unknown;\n\nexport interface SchemaState<Output = unknown> {\n catch?: () => Output;\n defaultValue?: () => Output;\n description?: string;\n hasAsyncChecks: boolean;\n hasRuntimeChecks: boolean;\n isNullable: boolean;\n isOptional: boolean;\n postprocessors: Postprocessor[];\n preprocessors: Preprocessor[];\n validators: ValidateFn[];\n}\n\nfunction defaultState<Output>(): SchemaState<Output> {\n return {\n hasAsyncChecks: false,\n hasRuntimeChecks: false,\n isNullable: false,\n isOptional: false,\n postprocessors: [],\n preprocessors: [],\n validators: [],\n };\n}\n\nfunction cloneState<Output>(state: SchemaState<Output>): SchemaState<Output> {\n return {\n catch: state.catch,\n defaultValue: state.defaultValue,\n description: state.description,\n hasAsyncChecks: state.hasAsyncChecks,\n hasRuntimeChecks: state.hasRuntimeChecks,\n isNullable: state.isNullable,\n isOptional: state.isOptional,\n postprocessors: [...state.postprocessors],\n preprocessors: [...state.preprocessors],\n validators: [...state.validators],\n };\n}\n\n/* -------------------- Internal parse-value return type -------------------- */\n\n/** @internal */\nexport type ParseValue = { data: unknown; issues: Issue[]; typeOk: boolean };\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/* -------------------- ParseContext default -------------------- */\n\n/** @internal */\nexport function _makeCtx(messages?: Messages): ParseContext {\n return messages ? { messages } : createParseContext();\n}\n\n/* -------------------- ValidateResult normalizer -------------------- */\n\nfunction normalizeValidateResult(result: ValidateResult, ctxIssues: Issue[], ctx: ParseContext): Issue[] | null {\n const issues = [...ctxIssues];\n\n if (typeof result === 'string') {\n issues.push({ code: ErrorCode.custom, message: result, path: [] });\n } else if (result === false && issues.length === 0) {\n issues.push({ code: ErrorCode.custom, message: ctx.messages.check.default(), path: [] });\n }\n\n return issues.length ? issues : null;\n}\n\n/* -------------------- Base Schema -------------------- */\n\nexport class Schema<Output = unknown, Input = Output, Mode extends SchemaMode = 'sync'> {\n declare readonly [schemaInput]: Input;\n declare readonly [schemaMode]: Mode;\n declare readonly [schemaOutput]: Output;\n\n protected state: SchemaState<Output>;\n\n protected _annotations: Record<string, unknown> = {};\n\n private _typeValidator: ValidateFn | null = null;\n\n constructor(typeValidator?: ValidateFn) {\n this.state = defaultState<Output>();\n this._typeValidator = typeValidator ?? null;\n }\n\n /* -------------------- Parse -------------------- */\n\n parse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): Output;\n parse(value: unknown, ctx?: ParseContext): Output {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'parse() cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n\n return this._withCatch(() => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as Output;\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'parse() received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n safeParse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): ParseResult<Output>;\n safeParse(value: unknown, ctx?: ParseContext): ParseResult<Output> {\n try {\n return {\n data: (this.parse as unknown as (value: unknown, ctx?: ParseContext) => Output)(value, ctx),\n success: true,\n };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n async parseAsync(value: unknown, ctx?: ParseContext): Promise<Output> {\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 Output;\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n async safeParseAsync(value: unknown, ctx?: ParseContext): Promise<ParseResult<Output>> {\n try {\n return { data: await this.parseAsync(value, ctx), success: true };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n /**\n * Internal full parse without throwing. Returns { data, issues }.\n * Used by composite schemas (array, object, union, etc.) to avoid\n * the try/catch + object allocation overhead of safeParse().\n * @internal\n */\n _parseFullSync(value: unknown, ctx?: ParseContext): { data: unknown; issues: Issue[] } {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'Sync parsing cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parse path received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /**\n * Async version of _parseFullSync.\n * @internal\n */\n async _parseFullAsync(value: unknown, ctx?: ParseContext): Promise<{ data: unknown; issues: Issue[] }> {\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /* -------------------- Validators -------------------- */\n\n /**\n * Add a synchronous domain rule. For asynchronous work, use `checkAsync()`;\n * making execution mode explicit prevents unchecked Promise-returning callbacks.\n */\n check<F extends (value: Output, ctx: CheckContext) => ValidateResult | Promise<ValidateResult>>(\n fn: ReturnType<F> extends PromiseLike<unknown> ? never : F,\n ): this {\n return this._addCheck(fn as (value: Output, ctx: CheckContext) => ValidateResult, false);\n }\n\n checkAsync(\n this: Schema<Output, Input, 'sync'>,\n fn: (value: Output, ctx: CheckContext) => Promise<ValidateResult>,\n ): Schema<Output, Input, 'async'> {\n return this._addCheck(fn, true) as unknown as Schema<Output, Input, 'async'>;\n }\n\n protected _addCheck(\n fn:\n | ((value: Output, ctx: CheckContext) => ValidateResult)\n | ((value: Output, ctx: CheckContext) => Promise<ValidateResult>),\n async: boolean,\n ): this {\n const validator: ValidateFn = (value, ctx) => {\n const ctxIssues: Issue[] = [];\n const checkCtx: CheckContext = {\n addIssue: (issue) => ctxIssues.push({ ...issue, path: issue.path ?? [] } as Issue),\n };\n const result = fn(value as Output, checkCtx);\n\n if (result instanceof Promise) {\n return result.then((r) => normalizeValidateResult(r, ctxIssues, ctx!));\n }\n\n return normalizeValidateResult(result, ctxIssues, ctx!);\n };\n\n const next = this._addConstraint(validator);\n\n next.state.hasRuntimeChecks = true;\n\n if (async) next.state.hasAsyncChecks = true;\n\n return next;\n }\n\n /* -------------------- Nullability / Optionality -------------------- */\n\n optional(): Schema<Output | undefined, Input | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | undefined, Input | undefined, Mode>;\n\n cloned.state.isOptional = true;\n\n return cloned;\n }\n\n nullable(): Schema<Output | null, Input | null, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null, Input | null, Mode>;\n\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n nullish(): Schema<Output | null | undefined, Input | null | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null | undefined, Input | null | undefined, Mode>;\n\n cloned.state.isOptional = true;\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n required(): Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode> {\n const cloned = this._clone() as unknown as Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode>;\n\n cloned.state.isOptional = false;\n\n return cloned;\n }\n\n /* -------------------- Transforms -------------------- */\n\n default(defaultValue: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.defaultValue =\n typeof defaultValue === 'function' ? (defaultValue as () => Output) : () => materializeValue(defaultValue);\n\n return cloned;\n }\n\n catch(fallback: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.catch = typeof fallback === 'function' ? (fallback as () => Output) : () => materializeValue(fallback);\n\n return cloned;\n }\n\n transform<NewOutput>(fn: (value: Output) => NewOutput): Schema<NewOutput, Input, Mode> {\n const next = this._clone() as unknown as Schema<NewOutput, Input, Mode>;\n\n next.state.postprocessors.push(fn as (v: unknown) => unknown);\n\n return next;\n }\n\n preprocess(fn: (value: unknown) => unknown): this {\n const cloned = this._clone();\n\n cloned.state.preprocessors.push(fn);\n\n return cloned;\n }\n\n pipe<B extends AnySchema>(next: B): PipeSchema<B, this, MergeSchemaModes<Mode | InferSchemaMode<B>>> {\n return new PipeSchema(this, next);\n }\n\n /* -------------------- Introspection -------------------- */\n\n label(description: string): this {\n const cloned = this._clone();\n\n cloned.state.description = description;\n\n return cloned;\n }\n\n definition(): SchemaDefinition {\n if (\n this.state.catch ||\n this.state.defaultValue ||\n this.state.postprocessors.length > 0 ||\n this.state.preprocessors.length > 0 ||\n this.state.hasRuntimeChecks\n ) {\n throw new SpellDefinitionError(\n 'Schemas with checks, transforms, defaults, catches, or preprocessors have no declarative definition.',\n );\n }\n\n return deepFreeze(this._toDescriptorImpl()) as SchemaDefinition;\n }\n\n get description(): string | undefined {\n return this.state.description;\n }\n\n get isOptional(): boolean {\n return this.state.isOptional;\n }\n\n get isNullable(): boolean {\n return this.state.isNullable;\n }\n\n is(value: unknown): value is Output {\n return (this.safeParse as unknown as (value: unknown) => ParseResult<Output>)(value).success;\n }\n\n assert(value: unknown, label?: string): asserts value is Output {\n const result = this._parseFullSync(value);\n\n if (result.issues.length === 0) return;\n\n const issues = label\n ? result.issues.map((issue) => ({\n ...issue,\n message: issue.path.length === 0 ? `${label}: ${issue.message}` : issue.message,\n }))\n : result.issues;\n\n throw new SpellValidationError(issues);\n }\n\n walk<R>(visitor: SchemaWalker<R>): R | null {\n return this._walk(visitor);\n }\n\n get kind(): string {\n return this._kind;\n }\n\n protected get _kind(): string {\n return 'any';\n }\n\n /* -------------------- Protected helpers -------------------- */\n\n protected _describeBase(): { description?: string; isNullable?: true; isOptional?: true } {\n return {\n ...(this.state.description !== undefined ? { description: this.state.description } : {}),\n ...(this.state.isNullable ? { isNullable: true as const } : {}),\n ...(this.state.isOptional ? { isOptional: true as const } : {}),\n };\n }\n\n protected _addConstraint(\n validator: ValidateFn,\n mergeAnnotations?: (current: Record<string, unknown>) => Record<string, unknown>,\n ): this {\n const next = this._clone();\n\n next.state.validators.push(validator);\n\n if (mergeAnnotations) {\n next._annotations = mergeAnnotations({ ...next._annotations });\n }\n\n return next;\n }\n\n protected _construct(state: SchemaState<any>): this {\n const next = Object.assign(Object.create(Object.getPrototypeOf(this)), this, { state }) as this;\n\n next._annotations = { ...this._annotations };\n\n return next;\n }\n\n protected _clone(): this {\n return this._construct(cloneState(this.state));\n }\n\n protected _copyStateTo<T extends Schema<any, any>>(target: T): T {\n target.state = cloneState(this.state);\n\n return target;\n }\n\n protected _walk<R>(visitor: SchemaWalker<R>): R | null {\n if (visitor.unknown) return visitor.unknown(this);\n\n return null;\n }\n\n protected _toDescriptorImpl(): SchemaDescriptor {\n return { ...this._describeBase(), kind: 'any' };\n }\n\n /* -------------------- Private -------------------- */\n\n private _withCatch<T>(fn: () => T): T {\n if (!this.state.catch) return fn();\n\n try {\n return fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected async _withCatchAsync<T>(fn: () => Promise<T>): Promise<T> {\n if (!this.state.catch) return fn();\n\n try {\n return await fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected _prepareInput(value: unknown): { skip: true; value: null | undefined } | { skip: false; value: unknown } {\n const processed = this._runPreprocessors(value);\n const withDefault = processed === undefined && this.state.defaultValue ? this.state.defaultValue() : processed;\n\n if ((this.state.isOptional && withDefault === undefined) || (this.state.isNullable && withDefault === null)) {\n return { skip: true, value: withDefault };\n }\n\n return { skip: false, value: withDefault };\n }\n\n protected _runPreprocessors(value: unknown): unknown {\n let current = value;\n\n for (const preprocess of this.state.preprocessors) current = preprocess(current);\n\n return current;\n }\n\n protected _runPostprocessors(value: unknown): unknown {\n let current = value;\n\n for (const postprocess of this.state.postprocessors) current = postprocess(current);\n\n return current;\n }\n\n private _runValidatorsSync(value: unknown, ctx: ParseContext): Issue[] {\n if (this._typeValidator) {\n const typeResult = this._typeValidator(value, ctx);\n\n if (typeResult instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Type validator returned a Promise. Use parseAsync() for async validation.',\n path: [],\n },\n ]);\n }\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = validate(value, ctx);\n\n if (result instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parsing received an async check. Use checkAsync() and parseAsync().',\n path: [],\n },\n ]);\n }\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected async _runValidatorsAsync(value: unknown, ctx: ParseContext): Promise<Issue[]> {\n if (this._typeValidator) {\n const typeResult = await this._typeValidator(value, ctx);\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = await validate(value, ctx);\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected _parse(_value: unknown, _ctx: ParseContext): MaybePromise<ParseValue> {\n return { data: _value, issues: [], typeOk: true };\n }\n}\n\n/* -------------------- PipeSchema -------------------- */\n\nexport class PipeSchema<\n To extends AnySchema,\n From extends AnySchema,\n Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<To | From>>,\n> extends Schema<InferOutput<To>, InferInput<From>, Mode> {\n readonly from: From;\n readonly to: To;\n\n protected override get _kind(): string {\n return 'pipe';\n }\n\n override checkAsync(\n this: PipeSchema<To, From, 'sync'>,\n fn: (value: InferOutput<To>, ctx: CheckContext) => Promise<ValidateResult>,\n ): PipeSchema<To, From, 'async'> {\n return this._addCheck(fn, true) as unknown as PipeSchema<To, From, 'async'>;\n }\n\n constructor(from: From, to: To) {\n super();\n this.from = from;\n this.to = to;\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): MaybePromise<ParseValue> {\n const r1OrPromise = this.from._parseFullSync(value, ctx);\n\n if (r1OrPromise instanceof Promise) {\n return (r1OrPromise as Promise<{ data: unknown; issues: Issue[] }>).then((r1) => {\n if (r1.issues.length > 0) return { data: value, issues: r1.issues, typeOk: false };\n\n return this.to\n ._parseFullAsync(r1.data, ctx)\n .then((r2) =>\n r2.issues.length > 0\n ? { data: r1.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n });\n }\n\n if (r1OrPromise.issues.length > 0) return { data: value, issues: r1OrPromise.issues, typeOk: false };\n\n const r2OrPromise = this.to._parseFullSync(r1OrPromise.data, ctx);\n\n if (r2OrPromise instanceof Promise) {\n return r2OrPromise.then((r2) =>\n r2.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n }\n\n return r2OrPromise.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2OrPromise.issues, typeOk: false }\n : { data: r2OrPromise.data, issues: [], typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferOutput<To>> {\n const c = ctx ?? _makeCtx();\n const first = await this.from._parseFullAsync(value, c);\n\n if (first.issues.length > 0) throw new SpellValidationError(first.issues);\n\n const second = await this.to._parseFullAsync(first.data, c);\n\n if (second.issues.length > 0) throw new SpellValidationError(second.issues);\n\n const issues = await this._runValidatorsAsync(second.data, c);\n\n if (issues.length > 0) throw new SpellValidationError(issues);\n\n return this._runPostprocessors(second.data) as InferOutput<To>;\n }\n\n protected override _walk<R>(visitor: SchemaWalker<R>): R | null {\n const fromR = this.from.walk(visitor);\n const toR = this.to.walk(visitor);\n\n if (visitor.pipe) return visitor.pipe(this, fromR, toR);\n\n return super._walk(visitor);\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n return {\n ...this._describeBase(),\n from: this.from.definition(),\n kind: 'pipe',\n to: this.to.definition(),\n };\n }\n}\n"],"mappings":"8JAoEA,SAAS,EAAc,EAAa,CAClC,GAAsB,OAAO,GAAU,WAAnC,GAA+C,OAAO,SAAS,CAAK,EAAG,OAAO,EAElF,IAAK,IAAM,KAAS,OAAO,OAAO,CAAgC,EAAG,EAAW,CAAK,EAErF,OAAO,OAAO,OAAO,CAAK,CAC5B,CAEA,SAAS,EAAoB,EAAa,CACxC,GAAqB,OAAO,GAAU,WAAlC,EAA4C,OAAO,EAEvD,GAAI,MAAM,QAAQ,CAAK,EAAG,OAAO,EAAM,IAAK,GAAS,EAAiB,CAAI,CAAC,EAE3E,GAAI,aAAiB,KAAM,OAAO,IAAI,KAAK,EAAM,QAAQ,CAAC,EAE1D,GAAI,aAAiB,IAAK,CACxB,IAAM,EAAM,IAAI,IAEhB,IAAK,GAAM,CAAC,EAAK,KAAa,EAAM,QAAQ,EAAG,EAAI,IAAI,EAAiB,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M,CAAC,EAE1D,GAAI,EAAO,OAAO,OAAS,EAAG,MAAM,IAAI,EAAA,qBAAqB,EAAO,MAAM,EAE1E,IAAM,EAAS,MAAM,KAAK,oBAAoB,EAAO,KAAM,CAAC,EAE5D,GAAI,EAAO,OAAS,EAAG,MAAM,IAAI,EAAA,qBAAqB,CAAM,EAE5D,OAAO,KAAK,mBAAmB,EAAO,IAAI,CAC5C,CAEA,MAA4B,EAAoC,CAC9D,IAAM,EAAQ,KAAK,KAAK,KAAK,CAAO,EAC9B,EAAM,KAAK,GAAG,KAAK,CAAO,EAIhC,OAFI,EAAQ,KAAa,EAAQ,KAAK,KAAM,EAAO,CAAG,EAE/C,MAAM,MAAM,CAAO,CAC5B,CAEA,mBAAyD,CACvD,MAAO,CACL,GAAG,KAAK,cAAc,EACtB,KAAM,KAAK,KAAK,WAAW,EAC3B,KAAM,OACN,GAAI,KAAK,GAAG,WAAW,CACzB,CACF,CACF"}
1
+ {"version":3,"file":"core.cjs","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { isPlainObject } from '@vielzeug/arsenal/guards';\n\nimport { SpellDefinitionError, SpellValidationError } from './errors';\nimport { createParseContext } from './messages';\nimport { defineOwnProperty } from './safe-object';\nimport {\n type AnySchema,\n type CheckContext,\n ErrorCode,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type Issue,\n type JsonSchema,\n type MergeSchemaModes,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDescriptor,\n type SchemaMode,\n type SchemaWalker,\n schemaInput,\n schemaMode,\n schemaOutput,\n type ValidateFn,\n type ValidateResult,\n} from './types';\n\nexport {\n fail,\n prependIssuePath,\n resolveMessage,\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n} from './errors';\nexport {\n type AnySchema,\n type CheckContext,\n ErrorCode,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type Issue,\n type JsonSchema,\n type MergeSchemaModes,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDescriptor,\n type SchemaMode,\n type SchemaWalker,\n schemaMode,\n type ValidateFn,\n type ValidateResult,\n};\n\nfunction deepFreeze<T>(value: T): T {\n if (value === null || typeof value !== 'object' || Object.isFrozen(value)) return value;\n\n for (const child of Object.values(value as Record<string, unknown>)) deepFreeze(child);\n\n return Object.freeze(value);\n}\n\nfunction materializeValue<T>(value: T): T {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => materializeValue(item)) as T;\n\n if (value instanceof Date) return new Date(value.getTime()) as T;\n\n if (value instanceof Map) {\n const out = new Map<unknown, unknown>();\n\n for (const [key, mapValue] of value.entries()) out.set(materializeValue(key), materializeValue(mapValue));\n\n return out as T;\n }\n\n if (value instanceof Set) return new Set([...value.values()].map((item) => materializeValue(item))) as T;\n\n if (isPlainObject(value)) {\n const out: Record<string, unknown> = {};\n\n for (const [key, entry] of Object.entries(value)) defineOwnProperty(out, key, materializeValue(entry));\n\n return out as T;\n }\n\n return value;\n}\n\n/* -------------------- Schema State -------------------- */\n\ntype Preprocessor = (value: unknown) => unknown;\ntype Postprocessor = (value: unknown) => unknown;\n\nexport interface SchemaState<Output = unknown> {\n catch?: () => Output;\n defaultValue?: () => Output;\n description?: string;\n hasAsyncChecks: boolean;\n hasRuntimeChecks: boolean;\n isNullable: boolean;\n isOptional: boolean;\n postprocessors: Postprocessor[];\n preprocessors: Preprocessor[];\n validators: ValidateFn[];\n}\n\nfunction defaultState<Output>(): SchemaState<Output> {\n return {\n hasAsyncChecks: false,\n hasRuntimeChecks: false,\n isNullable: false,\n isOptional: false,\n postprocessors: [],\n preprocessors: [],\n validators: [],\n };\n}\n\nfunction cloneState<Output>(state: SchemaState<Output>): SchemaState<Output> {\n return {\n catch: state.catch,\n defaultValue: state.defaultValue,\n description: state.description,\n hasAsyncChecks: state.hasAsyncChecks,\n hasRuntimeChecks: state.hasRuntimeChecks,\n isNullable: state.isNullable,\n isOptional: state.isOptional,\n postprocessors: [...state.postprocessors],\n preprocessors: [...state.preprocessors],\n validators: [...state.validators],\n };\n}\n\n/* -------------------- Internal parse-value return type -------------------- */\n\n/** @internal */\nexport type ParseValue = { data: unknown; issues: Issue[]; typeOk: boolean };\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/* -------------------- ParseContext default -------------------- */\n\n/** @internal */\nexport function _makeCtx(messages?: Messages): ParseContext {\n return messages ? { messages } : createParseContext();\n}\n\n/* -------------------- ValidateResult normalizer -------------------- */\n\nfunction normalizeValidateResult(result: ValidateResult, ctxIssues: Issue[], ctx: ParseContext): Issue[] | null {\n const issues = [...ctxIssues];\n\n if (typeof result === 'string') {\n issues.push({ code: ErrorCode.custom, message: result, path: [] });\n } else if (result === false && issues.length === 0) {\n issues.push({ code: ErrorCode.custom, message: ctx.messages.check.default(), path: [] });\n }\n\n return issues.length ? issues : null;\n}\n\n/* -------------------- Base Schema -------------------- */\n\nexport class Schema<Output = unknown, Input = Output, Mode extends SchemaMode = 'sync'> {\n declare readonly [schemaInput]: Input;\n declare readonly [schemaMode]: Mode;\n declare readonly [schemaOutput]: Output;\n\n protected state: SchemaState<Output>;\n\n protected _annotations: Record<string, unknown> = {};\n\n private _typeValidator: ValidateFn | null = null;\n\n constructor(typeValidator?: ValidateFn) {\n this.state = defaultState<Output>();\n this._typeValidator = typeValidator ?? null;\n }\n\n /* -------------------- Parse -------------------- */\n\n parse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): Output;\n parse(value: unknown, ctx?: ParseContext): Output {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'parse() cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n\n return this._withCatch(() => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as Output;\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'parse() received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n safeParse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): ParseResult<Output>;\n safeParse(value: unknown, ctx?: ParseContext): ParseResult<Output> {\n try {\n return {\n data: (this.parse as unknown as (value: unknown, ctx?: ParseContext) => Output)(value, ctx),\n success: true,\n };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n async parseAsync(value: unknown, ctx?: ParseContext): Promise<Output> {\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 Output;\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n async safeParseAsync(value: unknown, ctx?: ParseContext): Promise<ParseResult<Output>> {\n try {\n return { data: await this.parseAsync(value, ctx), success: true };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n /**\n * Internal full parse without throwing. Returns { data, issues }.\n * Used by composite schemas (array, object, union, etc.) to avoid\n * the try/catch + object allocation overhead of safeParse().\n * @internal\n */\n _parseFullSync(value: unknown, ctx?: ParseContext): { data: unknown; issues: Issue[] } {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'Sync parsing cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parse path received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /**\n * Async version of _parseFullSync.\n * @internal\n */\n async _parseFullAsync(value: unknown, ctx?: ParseContext): Promise<{ data: unknown; issues: Issue[] }> {\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /* -------------------- Validators -------------------- */\n\n /**\n * Add a synchronous domain rule. For asynchronous work, use `checkAsync()`;\n * making execution mode explicit prevents unchecked Promise-returning callbacks.\n */\n check<F extends (value: Output, ctx: CheckContext) => ValidateResult | Promise<ValidateResult>>(\n fn: ReturnType<F> extends PromiseLike<unknown> ? never : F,\n ): this {\n return this._addCheck(fn as (value: Output, ctx: CheckContext) => ValidateResult, false);\n }\n\n checkAsync(\n this: Schema<Output, Input, 'sync'>,\n fn: (value: Output, ctx: CheckContext) => Promise<ValidateResult>,\n ): Schema<Output, Input, 'async'> {\n return this._addCheck(fn, true) as unknown as Schema<Output, Input, 'async'>;\n }\n\n protected _addCheck(\n fn:\n | ((value: Output, ctx: CheckContext) => ValidateResult)\n | ((value: Output, ctx: CheckContext) => Promise<ValidateResult>),\n async: boolean,\n ): this {\n const validator: ValidateFn = (value, ctx) => {\n const ctxIssues: Issue[] = [];\n const checkCtx: CheckContext = {\n addIssue: (issue) => ctxIssues.push({ ...issue, path: issue.path ?? [] } as Issue),\n };\n const result = fn(value as Output, checkCtx);\n\n if (result instanceof Promise) {\n return result.then((r) => normalizeValidateResult(r, ctxIssues, ctx!));\n }\n\n return normalizeValidateResult(result, ctxIssues, ctx!);\n };\n\n const next = this._addConstraint(validator);\n\n next.state.hasRuntimeChecks = true;\n\n if (async) next.state.hasAsyncChecks = true;\n\n return next;\n }\n\n /* -------------------- Nullability / Optionality -------------------- */\n\n optional(): Schema<Output | undefined, Input | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | undefined, Input | undefined, Mode>;\n\n cloned.state.isOptional = true;\n\n return cloned;\n }\n\n nullable(): Schema<Output | null, Input | null, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null, Input | null, Mode>;\n\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n nullish(): Schema<Output | null | undefined, Input | null | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null | undefined, Input | null | undefined, Mode>;\n\n cloned.state.isOptional = true;\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n required(): Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode> {\n const cloned = this._clone() as unknown as Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode>;\n\n cloned.state.isOptional = false;\n\n return cloned;\n }\n\n /* -------------------- Transforms -------------------- */\n\n default(defaultValue: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.defaultValue =\n typeof defaultValue === 'function' ? (defaultValue as () => Output) : () => materializeValue(defaultValue);\n\n return cloned;\n }\n\n catch(fallback: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.catch = typeof fallback === 'function' ? (fallback as () => Output) : () => materializeValue(fallback);\n\n return cloned;\n }\n\n transform<NewOutput>(fn: (value: Output) => NewOutput): Schema<NewOutput, Input, Mode> {\n const next = this._clone() as unknown as Schema<NewOutput, Input, Mode>;\n\n next.state.postprocessors.push(fn as (v: unknown) => unknown);\n\n return next;\n }\n\n preprocess(fn: (value: unknown) => unknown): this {\n const cloned = this._clone();\n\n cloned.state.preprocessors.push(fn);\n\n return cloned;\n }\n\n pipe<B extends AnySchema>(next: B): PipeSchema<B, this, MergeSchemaModes<Mode | InferSchemaMode<B>>> {\n return new PipeSchema(this, next);\n }\n\n /* -------------------- Introspection -------------------- */\n\n label(description: string): this {\n const cloned = this._clone();\n\n cloned.state.description = description;\n\n return cloned;\n }\n\n definition(): SchemaDescriptor {\n if (\n this.state.catch ||\n this.state.defaultValue ||\n this.state.postprocessors.length > 0 ||\n this.state.preprocessors.length > 0 ||\n this.state.hasRuntimeChecks\n ) {\n throw new SpellDefinitionError(\n 'Schemas with checks, transforms, defaults, catches, or preprocessors have no declarative definition.',\n );\n }\n\n return deepFreeze(this._toDescriptorImpl()) as SchemaDescriptor;\n }\n\n get description(): string | undefined {\n return this.state.description;\n }\n\n get isOptional(): boolean {\n return this.state.isOptional;\n }\n\n get isNullable(): boolean {\n return this.state.isNullable;\n }\n\n is(value: unknown): value is Output {\n return (this.safeParse as unknown as (value: unknown) => ParseResult<Output>)(value).success;\n }\n\n assert(value: unknown, label?: string): asserts value is Output {\n const result = this._parseFullSync(value);\n\n if (result.issues.length === 0) return;\n\n const issues = label\n ? result.issues.map((issue) => ({\n ...issue,\n message: issue.path.length === 0 ? `${label}: ${issue.message}` : issue.message,\n }))\n : result.issues;\n\n throw new SpellValidationError(issues);\n }\n\n walk<R>(visitor: SchemaWalker<R>): R | null {\n return this._walk(visitor);\n }\n\n get kind(): string {\n return this._kind;\n }\n\n protected get _kind(): string {\n return 'any';\n }\n\n /* -------------------- Protected helpers -------------------- */\n\n protected _describeBase(): { description?: string; isNullable?: true; isOptional?: true } {\n return {\n ...(this.state.description !== undefined ? { description: this.state.description } : {}),\n ...(this.state.isNullable ? { isNullable: true as const } : {}),\n ...(this.state.isOptional ? { isOptional: true as const } : {}),\n };\n }\n\n protected _addConstraint(\n validator: ValidateFn,\n mergeAnnotations?: (current: Record<string, unknown>) => Record<string, unknown>,\n ): this {\n const next = this._clone();\n\n next.state.validators.push(validator);\n\n if (mergeAnnotations) {\n next._annotations = mergeAnnotations({ ...next._annotations });\n }\n\n return next;\n }\n\n protected _construct(state: SchemaState<any>): this {\n const next = Object.assign(Object.create(Object.getPrototypeOf(this)), this, { state }) as this;\n\n next._annotations = { ...this._annotations };\n\n return next;\n }\n\n protected _clone(): this {\n return this._construct(cloneState(this.state));\n }\n\n protected _copyStateTo<T extends Schema<any, any>>(target: T): T {\n target.state = cloneState(this.state);\n\n return target;\n }\n\n protected _walk<R>(visitor: SchemaWalker<R>): R | null {\n if (visitor.unknown) return visitor.unknown(this);\n\n return null;\n }\n\n protected _toDescriptorImpl(): SchemaDescriptor {\n return { ...this._describeBase(), kind: 'any' };\n }\n\n /* -------------------- Private -------------------- */\n\n private _withCatch<T>(fn: () => T): T {\n if (!this.state.catch) return fn();\n\n try {\n return fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected async _withCatchAsync<T>(fn: () => Promise<T>): Promise<T> {\n if (!this.state.catch) return fn();\n\n try {\n return await fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected _prepareInput(value: unknown): { skip: true; value: null | undefined } | { skip: false; value: unknown } {\n const processed = this._runPreprocessors(value);\n const withDefault = processed === undefined && this.state.defaultValue ? this.state.defaultValue() : processed;\n\n if ((this.state.isOptional && withDefault === undefined) || (this.state.isNullable && withDefault === null)) {\n return { skip: true, value: withDefault };\n }\n\n return { skip: false, value: withDefault };\n }\n\n protected _runPreprocessors(value: unknown): unknown {\n let current = value;\n\n for (const preprocess of this.state.preprocessors) current = preprocess(current);\n\n return current;\n }\n\n protected _runPostprocessors(value: unknown): unknown {\n let current = value;\n\n for (const postprocess of this.state.postprocessors) current = postprocess(current);\n\n return current;\n }\n\n private _runValidatorsSync(value: unknown, ctx: ParseContext): Issue[] {\n if (this._typeValidator) {\n const typeResult = this._typeValidator(value, ctx);\n\n if (typeResult instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Type validator returned a Promise. Use parseAsync() for async validation.',\n path: [],\n },\n ]);\n }\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = validate(value, ctx);\n\n if (result instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parsing received an async check. Use checkAsync() and parseAsync().',\n path: [],\n },\n ]);\n }\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected async _runValidatorsAsync(value: unknown, ctx: ParseContext): Promise<Issue[]> {\n if (this._typeValidator) {\n const typeResult = await this._typeValidator(value, ctx);\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = await validate(value, ctx);\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected _parse(_value: unknown, _ctx: ParseContext): MaybePromise<ParseValue> {\n return { data: _value, issues: [], typeOk: true };\n }\n}\n\n/* -------------------- PipeSchema -------------------- */\n\nexport class PipeSchema<\n To extends AnySchema,\n From extends AnySchema,\n Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<To | From>>,\n> extends Schema<InferOutput<To>, InferInput<From>, Mode> {\n readonly from: From;\n readonly to: To;\n\n protected override get _kind(): string {\n return 'pipe';\n }\n\n override checkAsync(\n this: PipeSchema<To, From, 'sync'>,\n fn: (value: InferOutput<To>, ctx: CheckContext) => Promise<ValidateResult>,\n ): PipeSchema<To, From, 'async'> {\n return this._addCheck(fn, true) as unknown as PipeSchema<To, From, 'async'>;\n }\n\n constructor(from: From, to: To) {\n super();\n this.from = from;\n this.to = to;\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): MaybePromise<ParseValue> {\n const r1OrPromise = this.from._parseFullSync(value, ctx);\n\n if (r1OrPromise instanceof Promise) {\n return (r1OrPromise as Promise<{ data: unknown; issues: Issue[] }>).then((r1) => {\n if (r1.issues.length > 0) return { data: value, issues: r1.issues, typeOk: false };\n\n return this.to\n ._parseFullAsync(r1.data, ctx)\n .then((r2) =>\n r2.issues.length > 0\n ? { data: r1.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n });\n }\n\n if (r1OrPromise.issues.length > 0) return { data: value, issues: r1OrPromise.issues, typeOk: false };\n\n const r2OrPromise = this.to._parseFullSync(r1OrPromise.data, ctx);\n\n if (r2OrPromise instanceof Promise) {\n return r2OrPromise.then((r2) =>\n r2.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n }\n\n return r2OrPromise.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2OrPromise.issues, typeOk: false }\n : { data: r2OrPromise.data, issues: [], typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferOutput<To>> {\n const c = ctx ?? _makeCtx();\n const first = await this.from._parseFullAsync(value, c);\n\n if (first.issues.length > 0) throw new SpellValidationError(first.issues);\n\n const second = await this.to._parseFullAsync(first.data, c);\n\n if (second.issues.length > 0) throw new SpellValidationError(second.issues);\n\n const issues = await this._runValidatorsAsync(second.data, c);\n\n if (issues.length > 0) throw new SpellValidationError(issues);\n\n return this._runPostprocessors(second.data) as InferOutput<To>;\n }\n\n protected override _walk<R>(visitor: SchemaWalker<R>): R | null {\n const fromR = this.from.walk(visitor);\n const toR = this.to.walk(visitor);\n\n if (visitor.pipe) return visitor.pipe(this, fromR, toR);\n\n return super._walk(visitor);\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n return {\n ...this._describeBase(),\n from: this.from.definition(),\n kind: 'pipe',\n to: this.to.definition(),\n };\n }\n}\n"],"mappings":"8JAiEA,SAAS,EAAc,EAAa,CAClC,GAAsB,OAAO,GAAU,WAAnC,GAA+C,OAAO,SAAS,CAAK,EAAG,OAAO,EAElF,IAAK,IAAM,KAAS,OAAO,OAAO,CAAgC,EAAG,EAAW,CAAK,EAErF,OAAO,OAAO,OAAO,CAAK,CAC5B,CAEA,SAAS,EAAoB,EAAa,CACxC,GAAqB,OAAO,GAAU,WAAlC,EAA4C,OAAO,EAEvD,GAAI,MAAM,QAAQ,CAAK,EAAG,OAAO,EAAM,IAAK,GAAS,EAAiB,CAAI,CAAC,EAE3E,GAAI,aAAiB,KAAM,OAAO,IAAI,KAAK,EAAM,QAAQ,CAAC,EAE1D,GAAI,aAAiB,IAAK,CACxB,IAAM,EAAM,IAAI,IAEhB,IAAK,GAAM,CAAC,EAAK,KAAa,EAAM,QAAQ,EAAG,EAAI,IAAI,EAAiB,CAAG,EAAG,EAAiB,CAAQ,CAAC,EAExG,OAAO,CACT,CAEA,GAAI,aAAiB,IAAK,OAAO,IAAI,IAAI,CAAC,GAAG,EAAM,OAAO,CAAC,CAAC,CAAC,IAAK,GAAS,EAAiB,CAAI,CAAC,CAAC,EAElG,IAAA,EAAI,EAAA,cAAA,CAAc,CAAK,EAAG,CACxB,IAAM,EAA+B,CAAC,EAEtC,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,CAAK,EAAG,EAAA,kBAAkB,EAAK,EAAK,EAAiB,CAAK,CAAC,EAErG,OAAO,CACT,CAEA,OAAO,CACT,CAoBA,SAAS,GAA4C,CACnD,MAAO,CACL,eAAgB,GAChB,iBAAkB,GAClB,WAAY,GACZ,WAAY,GACZ,eAAgB,CAAC,EACjB,cAAe,CAAC,EAChB,WAAY,CAAC,CACf,CACF,CAEA,SAAS,EAAmB,EAAiD,CA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W,CACzB,CACF,CACF"}
package/dist/core.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { type AnySchema, type CheckContext, ErrorCode, type FlatError, type FlatErrorFirst, type Infer, type InferInput, type InferOutput, type InferSchemaMode, type MergeSchemaModes, type SchemaMode, type Issue, type JsonSchema, type MessageFn, type Messages, type ParseContext, type ParseResult, type SchemaDefinition, type SchemaDescriptor, type SchemaWalker, schemaInput, schemaMode, schemaOutput, type ValidateFn, type ValidateResult } from './types';
2
- export { ErrorCode, type AnySchema, type CheckContext, type FlatError, type FlatErrorFirst, type Infer, type InferInput, type InferOutput, type InferSchemaMode, type MergeSchemaModes, type SchemaMode, type Issue, type JsonSchema, type MessageFn, type Messages, type ParseContext, type ParseResult, type SchemaDefinition, type SchemaDescriptor, type SchemaWalker, schemaMode, type ValidateFn, type ValidateResult, };
3
- export { SpellDefinitionError, SpellError, SpellValidationError, fail, prependIssuePath, resolveMessage, } from './errors';
1
+ import { type AnySchema, type CheckContext, ErrorCode, type FlatError, type FlatErrorFirst, type Infer, type InferInput, type InferOutput, type InferSchemaMode, type Issue, type JsonSchema, type MergeSchemaModes, type MessageFn, type Messages, type ParseContext, type ParseResult, type SchemaDescriptor, type SchemaMode, type SchemaWalker, schemaInput, schemaMode, schemaOutput, type ValidateFn, type ValidateResult } from './types';
2
+ export { fail, prependIssuePath, resolveMessage, SpellDefinitionError, SpellError, SpellValidationError, } from './errors';
3
+ export { type AnySchema, type CheckContext, ErrorCode, type FlatError, type FlatErrorFirst, type Infer, type InferInput, type InferOutput, type InferSchemaMode, type Issue, type JsonSchema, type MergeSchemaModes, type MessageFn, type Messages, type ParseContext, type ParseResult, type SchemaDescriptor, type SchemaMode, type SchemaWalker, schemaMode, type ValidateFn, type ValidateResult, };
4
4
  type Preprocessor = (value: unknown) => unknown;
5
5
  type Postprocessor = (value: unknown) => unknown;
6
6
  export interface SchemaState<Output = unknown> {
@@ -45,7 +45,7 @@ export declare class Schema<Output = unknown, Input = Output, Mode extends Schem
45
45
  preprocess(fn: (value: unknown) => unknown): this;
46
46
  pipe<B extends AnySchema>(next: B): PipeSchema<B, this, MergeSchemaModes<Mode | InferSchemaMode<B>>>;
47
47
  label(description: string): this;
48
- definition(): SchemaDefinition;
48
+ definition(): SchemaDescriptor;
49
49
  get description(): string | undefined;
50
50
  get isOptional(): boolean;
51
51
  get isNullable(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,WAAW,EACX,UAAU,EACV,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,SAAS,EACT,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,UAAU,EACV,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,CAAC;AAEF,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,oBAAo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C,CAAC;cAiBpE,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI;cAS5C,iBAAiB,IAAI,gBAAgB;CAQzD"}
1
+ {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,WAAW,EACX,UAAU,EACV,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,IAAI,EACJ,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,SAAS,EACT,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,UAAU,EACV,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,CAAC;AAwCF,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;AAChD,KAAK,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dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { isPlainObject } from '@vielzeug/arsenal/guards';\n\nimport { SpellDefinitionError, SpellValidationError } from './errors';\nimport { createParseContext } from './messages';\nimport { defineOwnProperty } from './safe-object';\nimport {\n type AnySchema,\n type CheckContext,\n ErrorCode,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type MergeSchemaModes,\n type SchemaMode,\n type Issue,\n type JsonSchema,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDefinition,\n type SchemaDescriptor,\n type SchemaWalker,\n schemaInput,\n schemaMode,\n schemaOutput,\n type ValidateFn,\n type ValidateResult,\n} from './types';\n\nexport {\n ErrorCode,\n type AnySchema,\n type CheckContext,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type MergeSchemaModes,\n type SchemaMode,\n type Issue,\n type JsonSchema,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDefinition,\n type SchemaDescriptor,\n type SchemaWalker,\n schemaMode,\n type ValidateFn,\n type ValidateResult,\n};\n\nexport {\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n fail,\n prependIssuePath,\n resolveMessage,\n} from './errors';\n\nfunction deepFreeze<T>(value: T): T {\n if (value === null || typeof value !== 'object' || Object.isFrozen(value)) return value;\n\n for (const child of Object.values(value as Record<string, unknown>)) deepFreeze(child);\n\n return Object.freeze(value);\n}\n\nfunction materializeValue<T>(value: T): T {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => materializeValue(item)) as T;\n\n if (value instanceof Date) return new Date(value.getTime()) as T;\n\n if (value instanceof Map) {\n const out = new Map<unknown, unknown>();\n\n for (const [key, mapValue] of value.entries()) out.set(materializeValue(key), materializeValue(mapValue));\n\n return out as T;\n }\n\n if (value instanceof Set) return new Set([...value.values()].map((item) => materializeValue(item))) as T;\n\n if (isPlainObject(value)) {\n const out: Record<string, unknown> = {};\n\n for (const [key, entry] of Object.entries(value)) defineOwnProperty(out, key, materializeValue(entry));\n\n return out as T;\n }\n\n return value;\n}\n\n/* -------------------- Schema State -------------------- */\n\ntype Preprocessor = (value: unknown) => unknown;\ntype Postprocessor = (value: unknown) => unknown;\n\nexport interface SchemaState<Output = unknown> {\n catch?: () => Output;\n defaultValue?: () => Output;\n description?: string;\n hasAsyncChecks: boolean;\n hasRuntimeChecks: boolean;\n isNullable: boolean;\n isOptional: boolean;\n postprocessors: Postprocessor[];\n preprocessors: Preprocessor[];\n validators: ValidateFn[];\n}\n\nfunction defaultState<Output>(): SchemaState<Output> {\n return {\n hasAsyncChecks: false,\n hasRuntimeChecks: false,\n isNullable: false,\n isOptional: false,\n postprocessors: [],\n preprocessors: [],\n validators: [],\n };\n}\n\nfunction cloneState<Output>(state: SchemaState<Output>): SchemaState<Output> {\n return {\n catch: state.catch,\n defaultValue: state.defaultValue,\n description: state.description,\n hasAsyncChecks: state.hasAsyncChecks,\n hasRuntimeChecks: state.hasRuntimeChecks,\n isNullable: state.isNullable,\n isOptional: state.isOptional,\n postprocessors: [...state.postprocessors],\n preprocessors: [...state.preprocessors],\n validators: [...state.validators],\n };\n}\n\n/* -------------------- Internal parse-value return type -------------------- */\n\n/** @internal */\nexport type ParseValue = { data: unknown; issues: Issue[]; typeOk: boolean };\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/* -------------------- ParseContext default -------------------- */\n\n/** @internal */\nexport function _makeCtx(messages?: Messages): ParseContext {\n return messages ? { messages } : createParseContext();\n}\n\n/* -------------------- ValidateResult normalizer -------------------- */\n\nfunction normalizeValidateResult(result: ValidateResult, ctxIssues: Issue[], ctx: ParseContext): Issue[] | null {\n const issues = [...ctxIssues];\n\n if (typeof result === 'string') {\n issues.push({ code: ErrorCode.custom, message: result, path: [] });\n } else if (result === false && issues.length === 0) {\n issues.push({ code: ErrorCode.custom, message: ctx.messages.check.default(), path: [] });\n }\n\n return issues.length ? issues : null;\n}\n\n/* -------------------- Base Schema -------------------- */\n\nexport class Schema<Output = unknown, Input = Output, Mode extends SchemaMode = 'sync'> {\n declare readonly [schemaInput]: Input;\n declare readonly [schemaMode]: Mode;\n declare readonly [schemaOutput]: Output;\n\n protected state: SchemaState<Output>;\n\n protected _annotations: Record<string, unknown> = {};\n\n private _typeValidator: ValidateFn | null = null;\n\n constructor(typeValidator?: ValidateFn) {\n this.state = defaultState<Output>();\n this._typeValidator = typeValidator ?? null;\n }\n\n /* -------------------- Parse -------------------- */\n\n parse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): Output;\n parse(value: unknown, ctx?: ParseContext): Output {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'parse() cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n\n return this._withCatch(() => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as Output;\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'parse() received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n safeParse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): ParseResult<Output>;\n safeParse(value: unknown, ctx?: ParseContext): ParseResult<Output> {\n try {\n return {\n data: (this.parse as unknown as (value: unknown, ctx?: ParseContext) => Output)(value, ctx),\n success: true,\n };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n async parseAsync(value: unknown, ctx?: ParseContext): Promise<Output> {\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 Output;\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n async safeParseAsync(value: unknown, ctx?: ParseContext): Promise<ParseResult<Output>> {\n try {\n return { data: await this.parseAsync(value, ctx), success: true };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n /**\n * Internal full parse without throwing. Returns { data, issues }.\n * Used by composite schemas (array, object, union, etc.) to avoid\n * the try/catch + object allocation overhead of safeParse().\n * @internal\n */\n _parseFullSync(value: unknown, ctx?: ParseContext): { data: unknown; issues: Issue[] } {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'Sync parsing cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parse path received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /**\n * Async version of _parseFullSync.\n * @internal\n */\n async _parseFullAsync(value: unknown, ctx?: ParseContext): Promise<{ data: unknown; issues: Issue[] }> {\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /* -------------------- Validators -------------------- */\n\n /**\n * Add a synchronous domain rule. For asynchronous work, use `checkAsync()`;\n * making execution mode explicit prevents unchecked Promise-returning callbacks.\n */\n check<F extends (value: Output, ctx: CheckContext) => ValidateResult | Promise<ValidateResult>>(\n fn: ReturnType<F> extends PromiseLike<unknown> ? never : F,\n ): this {\n return this._addCheck(fn as (value: Output, ctx: CheckContext) => ValidateResult, false);\n }\n\n checkAsync(\n this: Schema<Output, Input, 'sync'>,\n fn: (value: Output, ctx: CheckContext) => Promise<ValidateResult>,\n ): Schema<Output, Input, 'async'> {\n return this._addCheck(fn, true) as unknown as Schema<Output, Input, 'async'>;\n }\n\n protected _addCheck(\n fn:\n | ((value: Output, ctx: CheckContext) => ValidateResult)\n | ((value: Output, ctx: CheckContext) => Promise<ValidateResult>),\n async: boolean,\n ): this {\n const validator: ValidateFn = (value, ctx) => {\n const ctxIssues: Issue[] = [];\n const checkCtx: CheckContext = {\n addIssue: (issue) => ctxIssues.push({ ...issue, path: issue.path ?? [] } as Issue),\n };\n const result = fn(value as Output, checkCtx);\n\n if (result instanceof Promise) {\n return result.then((r) => normalizeValidateResult(r, ctxIssues, ctx!));\n }\n\n return normalizeValidateResult(result, ctxIssues, ctx!);\n };\n\n const next = this._addConstraint(validator);\n\n next.state.hasRuntimeChecks = true;\n\n if (async) next.state.hasAsyncChecks = true;\n\n return next;\n }\n\n /* -------------------- Nullability / Optionality -------------------- */\n\n optional(): Schema<Output | undefined, Input | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | undefined, Input | undefined, Mode>;\n\n cloned.state.isOptional = true;\n\n return cloned;\n }\n\n nullable(): Schema<Output | null, Input | null, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null, Input | null, Mode>;\n\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n nullish(): Schema<Output | null | undefined, Input | null | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null | undefined, Input | null | undefined, Mode>;\n\n cloned.state.isOptional = true;\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n required(): Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode> {\n const cloned = this._clone() as unknown as Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode>;\n\n cloned.state.isOptional = false;\n\n return cloned;\n }\n\n /* -------------------- Transforms -------------------- */\n\n default(defaultValue: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.defaultValue =\n typeof defaultValue === 'function' ? (defaultValue as () => Output) : () => materializeValue(defaultValue);\n\n return cloned;\n }\n\n catch(fallback: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.catch = typeof fallback === 'function' ? (fallback as () => Output) : () => materializeValue(fallback);\n\n return cloned;\n }\n\n transform<NewOutput>(fn: (value: Output) => NewOutput): Schema<NewOutput, Input, Mode> {\n const next = this._clone() as unknown as Schema<NewOutput, Input, Mode>;\n\n next.state.postprocessors.push(fn as (v: unknown) => unknown);\n\n return next;\n }\n\n preprocess(fn: (value: unknown) => unknown): this {\n const cloned = this._clone();\n\n cloned.state.preprocessors.push(fn);\n\n return cloned;\n }\n\n pipe<B extends AnySchema>(next: B): PipeSchema<B, this, MergeSchemaModes<Mode | InferSchemaMode<B>>> {\n return new PipeSchema(this, next);\n }\n\n /* -------------------- Introspection -------------------- */\n\n label(description: string): this {\n const cloned = this._clone();\n\n cloned.state.description = description;\n\n return cloned;\n }\n\n definition(): SchemaDefinition {\n if (\n this.state.catch ||\n this.state.defaultValue ||\n this.state.postprocessors.length > 0 ||\n this.state.preprocessors.length > 0 ||\n this.state.hasRuntimeChecks\n ) {\n throw new SpellDefinitionError(\n 'Schemas with checks, transforms, defaults, catches, or preprocessors have no declarative definition.',\n );\n }\n\n return deepFreeze(this._toDescriptorImpl()) as SchemaDefinition;\n }\n\n get description(): string | undefined {\n return this.state.description;\n }\n\n get isOptional(): boolean {\n return this.state.isOptional;\n }\n\n get isNullable(): boolean {\n return this.state.isNullable;\n }\n\n is(value: unknown): value is Output {\n return (this.safeParse as unknown as (value: unknown) => ParseResult<Output>)(value).success;\n }\n\n assert(value: unknown, label?: string): asserts value is Output {\n const result = this._parseFullSync(value);\n\n if (result.issues.length === 0) return;\n\n const issues = label\n ? result.issues.map((issue) => ({\n ...issue,\n message: issue.path.length === 0 ? `${label}: ${issue.message}` : issue.message,\n }))\n : result.issues;\n\n throw new SpellValidationError(issues);\n }\n\n walk<R>(visitor: SchemaWalker<R>): R | null {\n return this._walk(visitor);\n }\n\n get kind(): string {\n return this._kind;\n }\n\n protected get _kind(): string {\n return 'any';\n }\n\n /* -------------------- Protected helpers -------------------- */\n\n protected _describeBase(): { description?: string; isNullable?: true; isOptional?: true } {\n return {\n ...(this.state.description !== undefined ? { description: this.state.description } : {}),\n ...(this.state.isNullable ? { isNullable: true as const } : {}),\n ...(this.state.isOptional ? { isOptional: true as const } : {}),\n };\n }\n\n protected _addConstraint(\n validator: ValidateFn,\n mergeAnnotations?: (current: Record<string, unknown>) => Record<string, unknown>,\n ): this {\n const next = this._clone();\n\n next.state.validators.push(validator);\n\n if (mergeAnnotations) {\n next._annotations = mergeAnnotations({ ...next._annotations });\n }\n\n return next;\n }\n\n protected _construct(state: SchemaState<any>): this {\n const next = Object.assign(Object.create(Object.getPrototypeOf(this)), this, { state }) as this;\n\n next._annotations = { ...this._annotations };\n\n return next;\n }\n\n protected _clone(): this {\n return this._construct(cloneState(this.state));\n }\n\n protected _copyStateTo<T extends Schema<any, any>>(target: T): T {\n target.state = cloneState(this.state);\n\n return target;\n }\n\n protected _walk<R>(visitor: SchemaWalker<R>): R | null {\n if (visitor.unknown) return visitor.unknown(this);\n\n return null;\n }\n\n protected _toDescriptorImpl(): SchemaDescriptor {\n return { ...this._describeBase(), kind: 'any' };\n }\n\n /* -------------------- Private -------------------- */\n\n private _withCatch<T>(fn: () => T): T {\n if (!this.state.catch) return fn();\n\n try {\n return fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected async _withCatchAsync<T>(fn: () => Promise<T>): Promise<T> {\n if (!this.state.catch) return fn();\n\n try {\n return await fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected _prepareInput(value: unknown): { skip: true; value: null | undefined } | { skip: false; value: unknown } {\n const processed = this._runPreprocessors(value);\n const withDefault = processed === undefined && this.state.defaultValue ? this.state.defaultValue() : processed;\n\n if ((this.state.isOptional && withDefault === undefined) || (this.state.isNullable && withDefault === null)) {\n return { skip: true, value: withDefault };\n }\n\n return { skip: false, value: withDefault };\n }\n\n protected _runPreprocessors(value: unknown): unknown {\n let current = value;\n\n for (const preprocess of this.state.preprocessors) current = preprocess(current);\n\n return current;\n }\n\n protected _runPostprocessors(value: unknown): unknown {\n let current = value;\n\n for (const postprocess of this.state.postprocessors) current = postprocess(current);\n\n return current;\n }\n\n private _runValidatorsSync(value: unknown, ctx: ParseContext): Issue[] {\n if (this._typeValidator) {\n const typeResult = this._typeValidator(value, ctx);\n\n if (typeResult instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Type validator returned a Promise. Use parseAsync() for async validation.',\n path: [],\n },\n ]);\n }\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = validate(value, ctx);\n\n if (result instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parsing received an async check. Use checkAsync() and parseAsync().',\n path: [],\n },\n ]);\n }\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected async _runValidatorsAsync(value: unknown, ctx: ParseContext): Promise<Issue[]> {\n if (this._typeValidator) {\n const typeResult = await this._typeValidator(value, ctx);\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = await validate(value, ctx);\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected _parse(_value: unknown, _ctx: ParseContext): MaybePromise<ParseValue> {\n return { data: _value, issues: [], typeOk: true };\n }\n}\n\n/* -------------------- PipeSchema -------------------- */\n\nexport class PipeSchema<\n To extends AnySchema,\n From extends AnySchema,\n Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<To | From>>,\n> extends Schema<InferOutput<To>, InferInput<From>, Mode> {\n readonly from: From;\n readonly to: To;\n\n protected override get _kind(): string {\n return 'pipe';\n }\n\n override checkAsync(\n this: PipeSchema<To, From, 'sync'>,\n fn: (value: InferOutput<To>, ctx: CheckContext) => Promise<ValidateResult>,\n ): PipeSchema<To, From, 'async'> {\n return this._addCheck(fn, true) as unknown as PipeSchema<To, From, 'async'>;\n }\n\n constructor(from: From, to: To) {\n super();\n this.from = from;\n this.to = to;\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): MaybePromise<ParseValue> {\n const r1OrPromise = this.from._parseFullSync(value, ctx);\n\n if (r1OrPromise instanceof Promise) {\n return (r1OrPromise as Promise<{ data: unknown; issues: Issue[] }>).then((r1) => {\n if (r1.issues.length > 0) return { data: value, issues: r1.issues, typeOk: false };\n\n return this.to\n ._parseFullAsync(r1.data, ctx)\n .then((r2) =>\n r2.issues.length > 0\n ? { data: r1.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n });\n }\n\n if (r1OrPromise.issues.length > 0) return { data: value, issues: r1OrPromise.issues, typeOk: false };\n\n const r2OrPromise = this.to._parseFullSync(r1OrPromise.data, ctx);\n\n if (r2OrPromise instanceof Promise) {\n return r2OrPromise.then((r2) =>\n r2.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n }\n\n return r2OrPromise.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2OrPromise.issues, typeOk: false }\n : { data: r2OrPromise.data, issues: [], typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferOutput<To>> {\n const c = ctx ?? _makeCtx();\n const first = await this.from._parseFullAsync(value, c);\n\n if (first.issues.length > 0) throw new SpellValidationError(first.issues);\n\n const second = await this.to._parseFullAsync(first.data, c);\n\n if (second.issues.length > 0) throw new SpellValidationError(second.issues);\n\n const issues = await this._runValidatorsAsync(second.data, c);\n\n if (issues.length > 0) throw new SpellValidationError(issues);\n\n return this._runPostprocessors(second.data) as InferOutput<To>;\n }\n\n protected override _walk<R>(visitor: SchemaWalker<R>): R | null {\n const fromR = this.from.walk(visitor);\n const toR = this.to.walk(visitor);\n\n if (visitor.pipe) return visitor.pipe(this, fromR, toR);\n\n return super._walk(visitor);\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n return {\n ...this._describeBase(),\n from: this.from.definition(),\n kind: 'pipe',\n to: this.to.definition(),\n };\n }\n}\n"],"mappings":"yWAoEA,SAAS,EAAc,EAAa,CAClC,GAAsB,OAAO,GAAU,WAAnC,GAA+C,OAAO,SAAS,CAAK,EAAG,OAAO,EAElF,IAAK,IAAM,KAAS,OAAO,OAAO,CAAgC,EAAG,EAAW,CAAK,EAErF,OAAO,OAAO,OAAO,CAAK,CAC5B,CAEA,SAAS,EAAoB,EAAa,CACxC,GAAqB,OAAO,GAAU,WAAlC,EAA4C,OAAO,EAEvD,GAAI,MAAM,QAAQ,CAAK,EAAG,OAAO,EAAM,IAAK,GAAS,EAAiB,CAAI,CAAC,EAE3E,GAAI,aAAiB,KAAM,OAAO,IAAI,KAAK,EAAM,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M,IAAI,EAAqB,EAAO,MAAM,EAE1E,IAAM,EAAS,MAAM,KAAK,oBAAoB,EAAO,KAAM,CAAC,EAE5D,GAAI,EAAO,OAAS,EAAG,MAAM,IAAI,EAAqB,CAAM,EAE5D,OAAO,KAAK,mBAAmB,EAAO,IAAI,CAC5C,CAEA,MAA4B,EAAoC,CAC9D,IAAM,EAAQ,KAAK,KAAK,KAAK,CAAO,EAC9B,EAAM,KAAK,GAAG,KAAK,CAAO,EAIhC,OAFI,EAAQ,KAAa,EAAQ,KAAK,KAAM,EAAO,CAAG,EAE/C,MAAM,MAAM,CAAO,CAC5B,CAEA,mBAAyD,CACvD,MAAO,CACL,GAAG,KAAK,cAAc,EACtB,KAAM,KAAK,KAAK,WAAW,EAC3B,KAAM,OACN,GAAI,KAAK,GAAG,WAAW,CACzB,CACF,CACF"}
1
+ {"version":3,"file":"core.js","names":[],"sources":["../src/core.ts"],"sourcesContent":["import { isPlainObject } from '@vielzeug/arsenal/guards';\n\nimport { SpellDefinitionError, SpellValidationError } from './errors';\nimport { createParseContext } from './messages';\nimport { defineOwnProperty } from './safe-object';\nimport {\n type AnySchema,\n type CheckContext,\n ErrorCode,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type Issue,\n type JsonSchema,\n type MergeSchemaModes,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDescriptor,\n type SchemaMode,\n type SchemaWalker,\n schemaInput,\n schemaMode,\n schemaOutput,\n type ValidateFn,\n type ValidateResult,\n} from './types';\n\nexport {\n fail,\n prependIssuePath,\n resolveMessage,\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n} from './errors';\nexport {\n type AnySchema,\n type CheckContext,\n ErrorCode,\n type FlatError,\n type FlatErrorFirst,\n type Infer,\n type InferInput,\n type InferOutput,\n type InferSchemaMode,\n type Issue,\n type JsonSchema,\n type MergeSchemaModes,\n type MessageFn,\n type Messages,\n type ParseContext,\n type ParseResult,\n type SchemaDescriptor,\n type SchemaMode,\n type SchemaWalker,\n schemaMode,\n type ValidateFn,\n type ValidateResult,\n};\n\nfunction deepFreeze<T>(value: T): T {\n if (value === null || typeof value !== 'object' || Object.isFrozen(value)) return value;\n\n for (const child of Object.values(value as Record<string, unknown>)) deepFreeze(child);\n\n return Object.freeze(value);\n}\n\nfunction materializeValue<T>(value: T): T {\n if (value == null || typeof value !== 'object') return value;\n\n if (Array.isArray(value)) return value.map((item) => materializeValue(item)) as T;\n\n if (value instanceof Date) return new Date(value.getTime()) as T;\n\n if (value instanceof Map) {\n const out = new Map<unknown, unknown>();\n\n for (const [key, mapValue] of value.entries()) out.set(materializeValue(key), materializeValue(mapValue));\n\n return out as T;\n }\n\n if (value instanceof Set) return new Set([...value.values()].map((item) => materializeValue(item))) as T;\n\n if (isPlainObject(value)) {\n const out: Record<string, unknown> = {};\n\n for (const [key, entry] of Object.entries(value)) defineOwnProperty(out, key, materializeValue(entry));\n\n return out as T;\n }\n\n return value;\n}\n\n/* -------------------- Schema State -------------------- */\n\ntype Preprocessor = (value: unknown) => unknown;\ntype Postprocessor = (value: unknown) => unknown;\n\nexport interface SchemaState<Output = unknown> {\n catch?: () => Output;\n defaultValue?: () => Output;\n description?: string;\n hasAsyncChecks: boolean;\n hasRuntimeChecks: boolean;\n isNullable: boolean;\n isOptional: boolean;\n postprocessors: Postprocessor[];\n preprocessors: Preprocessor[];\n validators: ValidateFn[];\n}\n\nfunction defaultState<Output>(): SchemaState<Output> {\n return {\n hasAsyncChecks: false,\n hasRuntimeChecks: false,\n isNullable: false,\n isOptional: false,\n postprocessors: [],\n preprocessors: [],\n validators: [],\n };\n}\n\nfunction cloneState<Output>(state: SchemaState<Output>): SchemaState<Output> {\n return {\n catch: state.catch,\n defaultValue: state.defaultValue,\n description: state.description,\n hasAsyncChecks: state.hasAsyncChecks,\n hasRuntimeChecks: state.hasRuntimeChecks,\n isNullable: state.isNullable,\n isOptional: state.isOptional,\n postprocessors: [...state.postprocessors],\n preprocessors: [...state.preprocessors],\n validators: [...state.validators],\n };\n}\n\n/* -------------------- Internal parse-value return type -------------------- */\n\n/** @internal */\nexport type ParseValue = { data: unknown; issues: Issue[]; typeOk: boolean };\n\ntype MaybePromise<T> = T | Promise<T>;\n\n/* -------------------- ParseContext default -------------------- */\n\n/** @internal */\nexport function _makeCtx(messages?: Messages): ParseContext {\n return messages ? { messages } : createParseContext();\n}\n\n/* -------------------- ValidateResult normalizer -------------------- */\n\nfunction normalizeValidateResult(result: ValidateResult, ctxIssues: Issue[], ctx: ParseContext): Issue[] | null {\n const issues = [...ctxIssues];\n\n if (typeof result === 'string') {\n issues.push({ code: ErrorCode.custom, message: result, path: [] });\n } else if (result === false && issues.length === 0) {\n issues.push({ code: ErrorCode.custom, message: ctx.messages.check.default(), path: [] });\n }\n\n return issues.length ? issues : null;\n}\n\n/* -------------------- Base Schema -------------------- */\n\nexport class Schema<Output = unknown, Input = Output, Mode extends SchemaMode = 'sync'> {\n declare readonly [schemaInput]: Input;\n declare readonly [schemaMode]: Mode;\n declare readonly [schemaOutput]: Output;\n\n protected state: SchemaState<Output>;\n\n protected _annotations: Record<string, unknown> = {};\n\n private _typeValidator: ValidateFn | null = null;\n\n constructor(typeValidator?: ValidateFn) {\n this.state = defaultState<Output>();\n this._typeValidator = typeValidator ?? null;\n }\n\n /* -------------------- Parse -------------------- */\n\n parse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): Output;\n parse(value: unknown, ctx?: ParseContext): Output {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'parse() cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n\n return this._withCatch(() => {\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return prepared.value as Output;\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'parse() received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n safeParse(this: Schema<Output, Input, 'sync'>, value: unknown, ctx?: ParseContext): ParseResult<Output>;\n safeParse(value: unknown, ctx?: ParseContext): ParseResult<Output> {\n try {\n return {\n data: (this.parse as unknown as (value: unknown, ctx?: ParseContext) => Output)(value, ctx),\n success: true,\n };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n async parseAsync(value: unknown, ctx?: ParseContext): Promise<Output> {\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 Output;\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length) throw new SpellValidationError(allIssues);\n\n return this._runPostprocessors(core.data) as Output;\n });\n }\n\n async safeParseAsync(value: unknown, ctx?: ParseContext): Promise<ParseResult<Output>> {\n try {\n return { data: await this.parseAsync(value, ctx), success: true };\n } catch (error) {\n if (error instanceof SpellValidationError) return { error, success: false };\n\n throw error;\n }\n }\n\n /**\n * Internal full parse without throwing. Returns { data, issues }.\n * Used by composite schemas (array, object, union, etc.) to avoid\n * the try/catch + object allocation overhead of safeParse().\n * @internal\n */\n _parseFullSync(value: unknown, ctx?: ParseContext): { data: unknown; issues: Issue[] } {\n if (this.state.hasAsyncChecks) {\n throw new SpellValidationError([\n { code: ErrorCode.custom, message: 'Sync parsing cannot evaluate async checks. Use parseAsync().', path: [] },\n ]);\n }\n\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const coreOrPromise = this._parse(prepared.value, c);\n\n if (coreOrPromise instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parse path received an async schema. Use parseAsync() instead.',\n path: [],\n },\n ]);\n }\n\n const core = coreOrPromise;\n const validationIssues = core.typeOk ? this._runValidatorsSync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /**\n * Async version of _parseFullSync.\n * @internal\n */\n async _parseFullAsync(value: unknown, ctx?: ParseContext): Promise<{ data: unknown; issues: Issue[] }> {\n const c = ctx ?? _makeCtx();\n const prepared = this._prepareInput(value);\n\n if (prepared.skip) return { data: prepared.value, issues: [] };\n\n const core = await this._parse(prepared.value, c);\n const validationIssues = core.typeOk ? await this._runValidatorsAsync(core.data, c) : [];\n const allIssues = [...core.issues, ...validationIssues];\n\n if (allIssues.length > 0) {\n if (this.state.catch) return { data: this.state.catch(), issues: [] };\n\n return { data: core.data, issues: allIssues };\n }\n\n return { data: this._runPostprocessors(core.data), issues: [] };\n }\n\n /* -------------------- Validators -------------------- */\n\n /**\n * Add a synchronous domain rule. For asynchronous work, use `checkAsync()`;\n * making execution mode explicit prevents unchecked Promise-returning callbacks.\n */\n check<F extends (value: Output, ctx: CheckContext) => ValidateResult | Promise<ValidateResult>>(\n fn: ReturnType<F> extends PromiseLike<unknown> ? never : F,\n ): this {\n return this._addCheck(fn as (value: Output, ctx: CheckContext) => ValidateResult, false);\n }\n\n checkAsync(\n this: Schema<Output, Input, 'sync'>,\n fn: (value: Output, ctx: CheckContext) => Promise<ValidateResult>,\n ): Schema<Output, Input, 'async'> {\n return this._addCheck(fn, true) as unknown as Schema<Output, Input, 'async'>;\n }\n\n protected _addCheck(\n fn:\n | ((value: Output, ctx: CheckContext) => ValidateResult)\n | ((value: Output, ctx: CheckContext) => Promise<ValidateResult>),\n async: boolean,\n ): this {\n const validator: ValidateFn = (value, ctx) => {\n const ctxIssues: Issue[] = [];\n const checkCtx: CheckContext = {\n addIssue: (issue) => ctxIssues.push({ ...issue, path: issue.path ?? [] } as Issue),\n };\n const result = fn(value as Output, checkCtx);\n\n if (result instanceof Promise) {\n return result.then((r) => normalizeValidateResult(r, ctxIssues, ctx!));\n }\n\n return normalizeValidateResult(result, ctxIssues, ctx!);\n };\n\n const next = this._addConstraint(validator);\n\n next.state.hasRuntimeChecks = true;\n\n if (async) next.state.hasAsyncChecks = true;\n\n return next;\n }\n\n /* -------------------- Nullability / Optionality -------------------- */\n\n optional(): Schema<Output | undefined, Input | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | undefined, Input | undefined, Mode>;\n\n cloned.state.isOptional = true;\n\n return cloned;\n }\n\n nullable(): Schema<Output | null, Input | null, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null, Input | null, Mode>;\n\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n nullish(): Schema<Output | null | undefined, Input | null | undefined, Mode> {\n const cloned = this._clone() as unknown as Schema<Output | null | undefined, Input | null | undefined, Mode>;\n\n cloned.state.isOptional = true;\n cloned.state.isNullable = true;\n\n return cloned;\n }\n\n required(): Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode> {\n const cloned = this._clone() as unknown as Schema<Exclude<Output, undefined>, Exclude<Input, undefined>, Mode>;\n\n cloned.state.isOptional = false;\n\n return cloned;\n }\n\n /* -------------------- Transforms -------------------- */\n\n default(defaultValue: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.defaultValue =\n typeof defaultValue === 'function' ? (defaultValue as () => Output) : () => materializeValue(defaultValue);\n\n return cloned;\n }\n\n catch(fallback: Output | (() => Output)): this {\n const cloned = this._clone();\n\n cloned.state.catch = typeof fallback === 'function' ? (fallback as () => Output) : () => materializeValue(fallback);\n\n return cloned;\n }\n\n transform<NewOutput>(fn: (value: Output) => NewOutput): Schema<NewOutput, Input, Mode> {\n const next = this._clone() as unknown as Schema<NewOutput, Input, Mode>;\n\n next.state.postprocessors.push(fn as (v: unknown) => unknown);\n\n return next;\n }\n\n preprocess(fn: (value: unknown) => unknown): this {\n const cloned = this._clone();\n\n cloned.state.preprocessors.push(fn);\n\n return cloned;\n }\n\n pipe<B extends AnySchema>(next: B): PipeSchema<B, this, MergeSchemaModes<Mode | InferSchemaMode<B>>> {\n return new PipeSchema(this, next);\n }\n\n /* -------------------- Introspection -------------------- */\n\n label(description: string): this {\n const cloned = this._clone();\n\n cloned.state.description = description;\n\n return cloned;\n }\n\n definition(): SchemaDescriptor {\n if (\n this.state.catch ||\n this.state.defaultValue ||\n this.state.postprocessors.length > 0 ||\n this.state.preprocessors.length > 0 ||\n this.state.hasRuntimeChecks\n ) {\n throw new SpellDefinitionError(\n 'Schemas with checks, transforms, defaults, catches, or preprocessors have no declarative definition.',\n );\n }\n\n return deepFreeze(this._toDescriptorImpl()) as SchemaDescriptor;\n }\n\n get description(): string | undefined {\n return this.state.description;\n }\n\n get isOptional(): boolean {\n return this.state.isOptional;\n }\n\n get isNullable(): boolean {\n return this.state.isNullable;\n }\n\n is(value: unknown): value is Output {\n return (this.safeParse as unknown as (value: unknown) => ParseResult<Output>)(value).success;\n }\n\n assert(value: unknown, label?: string): asserts value is Output {\n const result = this._parseFullSync(value);\n\n if (result.issues.length === 0) return;\n\n const issues = label\n ? result.issues.map((issue) => ({\n ...issue,\n message: issue.path.length === 0 ? `${label}: ${issue.message}` : issue.message,\n }))\n : result.issues;\n\n throw new SpellValidationError(issues);\n }\n\n walk<R>(visitor: SchemaWalker<R>): R | null {\n return this._walk(visitor);\n }\n\n get kind(): string {\n return this._kind;\n }\n\n protected get _kind(): string {\n return 'any';\n }\n\n /* -------------------- Protected helpers -------------------- */\n\n protected _describeBase(): { description?: string; isNullable?: true; isOptional?: true } {\n return {\n ...(this.state.description !== undefined ? { description: this.state.description } : {}),\n ...(this.state.isNullable ? { isNullable: true as const } : {}),\n ...(this.state.isOptional ? { isOptional: true as const } : {}),\n };\n }\n\n protected _addConstraint(\n validator: ValidateFn,\n mergeAnnotations?: (current: Record<string, unknown>) => Record<string, unknown>,\n ): this {\n const next = this._clone();\n\n next.state.validators.push(validator);\n\n if (mergeAnnotations) {\n next._annotations = mergeAnnotations({ ...next._annotations });\n }\n\n return next;\n }\n\n protected _construct(state: SchemaState<any>): this {\n const next = Object.assign(Object.create(Object.getPrototypeOf(this)), this, { state }) as this;\n\n next._annotations = { ...this._annotations };\n\n return next;\n }\n\n protected _clone(): this {\n return this._construct(cloneState(this.state));\n }\n\n protected _copyStateTo<T extends Schema<any, any>>(target: T): T {\n target.state = cloneState(this.state);\n\n return target;\n }\n\n protected _walk<R>(visitor: SchemaWalker<R>): R | null {\n if (visitor.unknown) return visitor.unknown(this);\n\n return null;\n }\n\n protected _toDescriptorImpl(): SchemaDescriptor {\n return { ...this._describeBase(), kind: 'any' };\n }\n\n /* -------------------- Private -------------------- */\n\n private _withCatch<T>(fn: () => T): T {\n if (!this.state.catch) return fn();\n\n try {\n return fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected async _withCatchAsync<T>(fn: () => Promise<T>): Promise<T> {\n if (!this.state.catch) return fn();\n\n try {\n return await fn();\n } catch (error) {\n if (error instanceof SpellValidationError) return this.state.catch() as unknown as T;\n\n throw error;\n }\n }\n\n protected _prepareInput(value: unknown): { skip: true; value: null | undefined } | { skip: false; value: unknown } {\n const processed = this._runPreprocessors(value);\n const withDefault = processed === undefined && this.state.defaultValue ? this.state.defaultValue() : processed;\n\n if ((this.state.isOptional && withDefault === undefined) || (this.state.isNullable && withDefault === null)) {\n return { skip: true, value: withDefault };\n }\n\n return { skip: false, value: withDefault };\n }\n\n protected _runPreprocessors(value: unknown): unknown {\n let current = value;\n\n for (const preprocess of this.state.preprocessors) current = preprocess(current);\n\n return current;\n }\n\n protected _runPostprocessors(value: unknown): unknown {\n let current = value;\n\n for (const postprocess of this.state.postprocessors) current = postprocess(current);\n\n return current;\n }\n\n private _runValidatorsSync(value: unknown, ctx: ParseContext): Issue[] {\n if (this._typeValidator) {\n const typeResult = this._typeValidator(value, ctx);\n\n if (typeResult instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Type validator returned a Promise. Use parseAsync() for async validation.',\n path: [],\n },\n ]);\n }\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = validate(value, ctx);\n\n if (result instanceof Promise) {\n throw new SpellValidationError([\n {\n code: ErrorCode.custom,\n message: 'Sync parsing received an async check. Use checkAsync() and parseAsync().',\n path: [],\n },\n ]);\n }\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected async _runValidatorsAsync(value: unknown, ctx: ParseContext): Promise<Issue[]> {\n if (this._typeValidator) {\n const typeResult = await this._typeValidator(value, ctx);\n\n if (typeResult && typeResult.length > 0) return typeResult;\n }\n\n const issues: Issue[] = [];\n\n for (const validate of this.state.validators) {\n const result = await validate(value, ctx);\n\n if (result) issues.push(...result);\n }\n\n return issues;\n }\n\n protected _parse(_value: unknown, _ctx: ParseContext): MaybePromise<ParseValue> {\n return { data: _value, issues: [], typeOk: true };\n }\n}\n\n/* -------------------- PipeSchema -------------------- */\n\nexport class PipeSchema<\n To extends AnySchema,\n From extends AnySchema,\n Mode extends SchemaMode = MergeSchemaModes<InferSchemaMode<To | From>>,\n> extends Schema<InferOutput<To>, InferInput<From>, Mode> {\n readonly from: From;\n readonly to: To;\n\n protected override get _kind(): string {\n return 'pipe';\n }\n\n override checkAsync(\n this: PipeSchema<To, From, 'sync'>,\n fn: (value: InferOutput<To>, ctx: CheckContext) => Promise<ValidateResult>,\n ): PipeSchema<To, From, 'async'> {\n return this._addCheck(fn, true) as unknown as PipeSchema<To, From, 'async'>;\n }\n\n constructor(from: From, to: To) {\n super();\n this.from = from;\n this.to = to;\n }\n\n protected override _parse(value: unknown, ctx: ParseContext): MaybePromise<ParseValue> {\n const r1OrPromise = this.from._parseFullSync(value, ctx);\n\n if (r1OrPromise instanceof Promise) {\n return (r1OrPromise as Promise<{ data: unknown; issues: Issue[] }>).then((r1) => {\n if (r1.issues.length > 0) return { data: value, issues: r1.issues, typeOk: false };\n\n return this.to\n ._parseFullAsync(r1.data, ctx)\n .then((r2) =>\n r2.issues.length > 0\n ? { data: r1.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n });\n }\n\n if (r1OrPromise.issues.length > 0) return { data: value, issues: r1OrPromise.issues, typeOk: false };\n\n const r2OrPromise = this.to._parseFullSync(r1OrPromise.data, ctx);\n\n if (r2OrPromise instanceof Promise) {\n return r2OrPromise.then((r2) =>\n r2.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2.issues, typeOk: false }\n : { data: r2.data, issues: [], typeOk: true },\n );\n }\n\n return r2OrPromise.issues.length > 0\n ? { data: r1OrPromise.data, issues: r2OrPromise.issues, typeOk: false }\n : { data: r2OrPromise.data, issues: [], typeOk: true };\n }\n\n override async parseAsync(value: unknown, ctx?: ParseContext): Promise<InferOutput<To>> {\n const c = ctx ?? _makeCtx();\n const first = await this.from._parseFullAsync(value, c);\n\n if (first.issues.length > 0) throw new SpellValidationError(first.issues);\n\n const second = await this.to._parseFullAsync(first.data, c);\n\n if (second.issues.length > 0) throw new SpellValidationError(second.issues);\n\n const issues = await this._runValidatorsAsync(second.data, c);\n\n if (issues.length > 0) throw new SpellValidationError(issues);\n\n return this._runPostprocessors(second.data) as InferOutput<To>;\n }\n\n protected override _walk<R>(visitor: SchemaWalker<R>): R | null {\n const fromR = this.from.walk(visitor);\n const toR = this.to.walk(visitor);\n\n if (visitor.pipe) return visitor.pipe(this, fromR, toR);\n\n return super._walk(visitor);\n }\n\n protected override _toDescriptorImpl(): SchemaDescriptor {\n return {\n ...this._describeBase(),\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AAQ,EAAK,CAChD,EAGK,EAAY,OAAO,OAAS,EAC/B,CAAE,KAAM,EAAY,KAAM,OAAQ,EAAY,OAAQ,OAAQ,EAAM,EACpE,CAAE,KAAM,EAAY,KAAM,OAAQ,CAAC,EAAG,OAAQ,EAAK,CACzD,CAEA,MAAe,WAAW,EAAgB,EAA8C,CACtF,IAAM,EAAI,GAAO,EAAS,EACpB,EAAQ,MAAM,KAAK,KAAK,gBAAgB,EAAO,CAAC,EAEtD,GAAI,EAAM,OAAO,OAAS,EAAG,MAAM,IAAI,EAAqB,EAAM,MAAM,EAExE,IAAM,EAAS,MAAM,KAAK,GAAG,gBAAgB,EAAM,KAAM,CAAC,EAE1D,GAAI,EAAO,OAAO,OAAS,EAAG,MAAM,IAAI,EAAqB,EAAO,MAAM,EAE1E,IAAM,EAAS,MAAM,KAAK,oBAAoB,EAAO,KAAM,CAAC,EAE5D,GAAI,EAAO,OAAS,EAAG,MAAM,IAAI,EAAqB,CAAM,EAE5D,OAAO,KAAK,mBAAmB,EAAO,IAAI,CAC5C,CAEA,MAA4B,EAAoC,CAC9D,IAAM,EAAQ,KAAK,KAAK,KAAK,CAAO,EAC9B,EAAM,KAAK,GAAG,KAAK,CAAO,EAIhC,OAFI,EAAQ,KAAa,EAAQ,KAAK,KAAM,EAAO,CAAG,EAE/C,MAAM,MAAM,CAAO,CAC5B,CAEA,mBAAyD,CACvD,MAAO,CACL,GAAG,KAAK,cAAc,EACtB,KAAM,KAAK,KAAK,WAAW,EAC3B,KAAM,OACN,GAAI,KAAK,GAAG,WAAW,CACzB,CACF,CACF"}
package/dist/errors.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  const e=require("./types.cjs");function t(e,t,n){return[{code:e,message:t,params:n,path:[]}]}function n(e,t){return typeof e==`function`?e(t):e}function r(e,t){return e.map(e=>({...e,path:[t,...e.path]}))}var i=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 a(e){return e.map(({code:e,message:t,path:n})=>`${n.length?n.join(`.`):`value`}: ${t} [${e}]`).join(`
2
- `)}function o(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var s=class extends i{},c=class extends i{issues;constructor(e,t){super(a(e),{cause:t}),this.issues=e}bestMatch(t){let n=t??this.issues.find(t=>t.code===e.ErrorCode.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=>o(t.path,e)).map(e=>e.message)}};exports.SpellDefinitionError=s,exports.SpellError=i,exports.SpellValidationError=c,exports.fail=t,exports.prependIssuePath=r,exports.resolveMessage=n;
2
+ `)}function o(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var s=class extends i{},c=class extends i{issues;constructor(e,t){super(a(e),{cause:t}),this.issues=e}bestMatch(t){let n=t??this.issues.find(t=>t.code===e.ErrorCode.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=>o(t.path,e)).map(e=>e.message)}};exports.SpellDefinitionError=s,exports.SpellError=i,exports.SpellValidationError=c,exports.fail=t,exports.prependIssuePath=r,exports.resolveMessage=n;
3
3
  //# sourceMappingURL=errors.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ErrorCode, type Issue, type MessageFn } from './types';\n\n/* -------------------- Helpers -------------------- */\n\ntype IssueParams<C extends string> = Extract<Issue, { code: C }> extends { params: infer P } ? P : undefined;\n\n/**\n * Creates a single-error failure array. Use in validator functions instead of building the array manually.\n * Typed overloads ensure params match the given error code.\n */\nexport function fail<C extends ErrorCode>(code: C, message: string, params: IssueParams<C>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[] {\n return [{ code, message, params, path: [] } as Issue];\n}\n\n/** @internal */\nexport function resolveMessage<Ctx extends Record<string, unknown>>(msg: MessageFn<Ctx>, ctx: Ctx): string {\n return typeof msg === 'function' ? msg(ctx) : msg;\n}\n\nexport function prependIssuePath(issues: Issue[], prefix: string | number): Issue[] {\n return issues.map((issue) => ({ ...issue, path: [prefix, ...issue.path] }));\n}\n\n/* -------------------- SpellError -------------------- */\n\n/** Base class for all spell errors. Use `instanceof SpellError` to catch any spell-originated error. */\nexport class SpellError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is SpellError {\n return err instanceof SpellError;\n }\n}\n\n/* -------------------- SpellValidationError -------------------- */\n\nfunction formatIssues(issues: Issue[]): string {\n return issues\n .map(({ code, message, path }) => {\n const pathStr = path.length ? path.join('.') : 'value';\n\n return `${pathStr}: ${message} [${code}]`;\n })\n .join('\\n');\n}\n\nfunction pathsEqual(left: readonly (string | number)[], right: readonly (string | number)[]): boolean {\n return left.length === right.length && left.every((segment, index) => segment === right[index]);\n}\n\nexport type FlatError = { messages: string[]; path: (string | number)[] };\nexport type FlatErrorFirst = { message: string; path: (string | number)[] };\n\nexport class SpellDefinitionError extends SpellError {}\n\nexport class SpellValidationError extends SpellError {\n readonly issues: Issue[];\n\n constructor(issues: Issue[], cause?: unknown) {\n super(formatIssues(issues), { cause });\n this.issues = issues;\n }\n\n /**\n * Returns the most-specific branch errors for `issue`, or the first union issue when omitted.\n * Surfaces the branch with the fewest issues at the deepest path — the one that \"came closest\" to matching.\n */\n bestMatch(issue?: Extract<Issue, { code: 'invalid_union' }>): Issue[] | null {\n const unionIssue =\n issue ??\n this.issues.find(\n (entry): entry is Extract<Issue, { code: 'invalid_union' }> => entry.code === ErrorCode.invalid_union,\n );\n\n if (!unionIssue) return null;\n\n const branches = unionIssue.params.errors;\n\n if (branches.length === 0) return null;\n\n const scored = branches.map((branchIssues) => {\n const maxDepth = branchIssues.reduce((d, i) => Math.max(d, i.path.length), 0);\n\n return { issues: branchIssues, score: maxDepth * 1000 - branchIssues.length };\n });\n\n scored.sort((a, b) => b.score - a.score);\n\n return scored[0]!.issues;\n }\n\n flatten(): { fieldErrors: FlatError[]; formErrors: string[] } {\n const fieldErrors: FlatError[] = [];\n const formErrors: string[] = [];\n const pathMap = new Map<string, number>();\n\n for (const issue of this.issues) {\n if (issue.path.length === 0) {\n formErrors.push(issue.message);\n } else {\n const key = JSON.stringify(issue.path);\n const existing = pathMap.get(key);\n\n if (existing !== undefined) {\n fieldErrors[existing]!.messages.push(issue.message);\n } else {\n pathMap.set(key, fieldErrors.length);\n fieldErrors.push({ messages: [issue.message], path: [...issue.path] });\n }\n }\n }\n\n return { fieldErrors, formErrors };\n }\n\n flattenFirst(): { fieldErrors: FlatErrorFirst[]; formErrors: string[] } {\n const { fieldErrors, formErrors } = this.flatten();\n\n return {\n fieldErrors: fieldErrors.map((fe) => ({ message: fe.messages[0]!, path: fe.path })),\n formErrors,\n };\n }\n\n /** Returns every message attached to exactly `path`, in issue order. */\n messagesAt(...path: (string | number)[]): string[] {\n return this.issues.filter((issue) => pathsEqual(issue.path, path)).map((issue) => issue.message);\n }\n}\n"],"mappings":"+BAYA,SAAgB,EAAK,EAAc,EAAiB,EAA2C,CAC7F,MAAO,CAAC,CAAE,OAAM,UAAS,SAAQ,KAAM,CAAC,CAAE,CAAU,CACtD,CAGA,SAAgB,EAAoD,EAAqB,EAAkB,CACzG,OAAO,OAAO,GAAQ,WAAa,EAAI,CAAG,EAAI,CAChD,CAEA,SAAgB,EAAiB,EAAiB,EAAkC,CAClF,OAAO,EAAO,IAAK,IAAW,CAAE,GAAG,EAAO,KAAM,CAAC,EAAQ,GAAG,EAAM,IAAI,CAAE,EAAE,CAC5E,CAKA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAiC,CACzC,OAAO,aAAe,CACxB,CACF,EAIA,SAAS,EAAa,EAAyB,CAC7C,OAAO,EACJ,KAAK,CAAE,OAAM,UAAS,UAGd,GAFS,EAAK,OAAS,EAAK,KAAK,GAAG,EAAI,QAE7B,IAAI,EAAQ,IAAI,EAAK,EACxC,CAAC,CACD,KAAK;CAAI,CACd,CAEA,SAAS,EAAW,EAAoC,EAA8C,CACpG,OAAO,EAAK,SAAW,EAAM,QAAU,EAAK,OAAO,EAAS,IAAU,IAAY,EAAM,EAAM,CAChG,CAKA,IAAa,EAAb,cAA0C,CAAW,CAAC,EAEzC,EAAb,cAA0C,CAAW,CACnD,OAEA,YAAY,EAAiB,EAAiB,CAC5C,MAAM,EAAa,CAAM,EAAG,CAAE,OAAM,CAAC,EACrC,KAAK,OAAS,CAChB,CAMA,UAAU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AAO,CACjG,CACF"}
1
+ {"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ErrorCode, type Issue, type MessageFn } from './types';\n\n/* -------------------- Helpers -------------------- */\n\ntype IssueParams<C extends string> = Extract<Issue, { code: C }> extends { params: infer P } ? P : undefined;\n\n/**\n * Creates a single-error failure array. Use in validator functions instead of building the array manually.\n * Typed overloads ensure params match the given error code.\n */\nexport function fail<C extends ErrorCode>(code: C, message: string, params: IssueParams<C>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[] {\n return [{ code, message, params, path: [] } as Issue];\n}\n\n/** @internal */\nexport function resolveMessage<Ctx extends Record<string, unknown>>(msg: MessageFn<Ctx>, ctx: Ctx): string {\n return typeof msg === 'function' ? msg(ctx) : msg;\n}\n\nexport function prependIssuePath(issues: Issue[], prefix: string | number): Issue[] {\n return issues.map((issue) => ({ ...issue, path: [prefix, ...issue.path] }));\n}\n\n/* -------------------- SpellError -------------------- */\n\n/** Base class for all spell errors. Use `instanceof SpellError` to catch any spell-originated error. */\nexport class SpellError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is SpellError {\n return err instanceof SpellError;\n }\n}\n\n/* -------------------- SpellValidationError -------------------- */\n\nfunction formatIssues(issues: Issue[]): string {\n return issues\n .map(({ code, message, path }) => {\n const pathStr = path.length ? path.join('.') : 'value';\n\n return `${pathStr}: ${message} [${code}]`;\n })\n .join('\\n');\n}\n\nfunction pathsEqual(left: readonly (string | number)[], right: readonly (string | number)[]): boolean {\n return left.length === right.length && left.every((segment, index) => segment === right[index]);\n}\n\nexport type FlatError = { messages: string[]; path: (string | number)[] };\nexport type FlatErrorFirst = { message: string; path: (string | number)[] };\n\nexport class SpellDefinitionError extends SpellError {}\n\nexport class SpellValidationError extends SpellError {\n readonly issues: Issue[];\n\n constructor(issues: Issue[], cause?: unknown) {\n super(formatIssues(issues), { cause });\n this.issues = issues;\n }\n\n /**\n * Returns the most-specific branch errors for `issue`, or the first union issue when omitted.\n * Surfaces the branch with the fewest issues at the deepest path — the one that \"came closest\" to matching.\n */\n bestMatch(issue?: Extract<Issue, { code: 'invalid_union' }>): Issue[] | null {\n const unionIssue =\n issue ??\n this.issues.find(\n (entry): entry is Extract<Issue, { code: 'invalid_union' }> => entry.code === ErrorCode.invalid_union,\n );\n\n if (!unionIssue) return null;\n\n const branches = unionIssue.params.errors;\n\n if (branches.length === 0) return null;\n\n const scored = branches.map((branchIssues) => {\n const maxDepth = branchIssues.reduce((d, i) => Math.max(d, i.path.length), 0);\n\n return { issues: branchIssues, score: maxDepth * 1000 - branchIssues.length };\n });\n\n scored.sort((a, b) => b.score - a.score);\n\n return scored[0]?.issues;\n }\n\n flatten(): { fieldErrors: FlatError[]; formErrors: string[] } {\n const fieldErrors: FlatError[] = [];\n const formErrors: string[] = [];\n const pathMap = new Map<string, number>();\n\n for (const issue of this.issues) {\n if (issue.path.length === 0) {\n formErrors.push(issue.message);\n } else {\n const key = JSON.stringify(issue.path);\n const existing = pathMap.get(key);\n\n if (existing !== undefined) {\n fieldErrors[existing]?.messages.push(issue.message);\n } else {\n pathMap.set(key, fieldErrors.length);\n fieldErrors.push({ messages: [issue.message], path: [...issue.path] });\n }\n }\n }\n\n return { fieldErrors, formErrors };\n }\n\n flattenFirst(): { fieldErrors: FlatErrorFirst[]; formErrors: string[] } {\n const { fieldErrors, formErrors } = this.flatten();\n\n return {\n fieldErrors: fieldErrors.map((fe) => ({ message: fe.messages[0]!, path: fe.path })),\n formErrors,\n };\n }\n\n /** Returns every message attached to exactly `path`, in issue order. */\n messagesAt(...path: (string | number)[]): string[] {\n return this.issues.filter((issue) => pathsEqual(issue.path, path)).map((issue) => issue.message);\n }\n}\n"],"mappings":"+BAYA,SAAgB,EAAK,EAAc,EAAiB,EAA2C,CAC7F,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,EAAa,QAAQ,EAAG,IAAM,KAAK,IAAI,EAAG,EAAE,KAAK,MAAM,EAAG,CAErC,EAAW,IAAO,EAAa,MAAO,EAC7E,EAID,OAFA,EAAO,MAAM,EAAG,IAAM,EAAE,MAAQ,EAAE,KAAK,EAEhC,EAAO,EAAE,EAAE,MACpB,CAEA,SAA8D,CAC5D,IAAM,EAA2B,CAAC,EAC5B,EAAuB,CAAC,EACxB,EAAU,IAAI,IAEpB,IAAK,IAAM,KAAS,KAAK,OACvB,GAAI,EAAM,KAAK,SAAW,EACxB,EAAW,KAAK,EAAM,OAAO,MACxB,CACL,IAAM,EAAM,KAAK,UAAU,EAAM,IAAI,EAC/B,EAAW,EAAQ,IAAI,CAAG,EAE5B,IAAa,IAAA,IAGf,EAAQ,IAAI,EAAK,EAAY,MAAM,EACnC,EAAY,KAAK,CAAE,SAAU,CAAC,EAAM,OAAO,EAAG,KAAM,CAAC,GAAG,EAAM,IAAI,CAAE,CAAC,GAHrE,EAAY,EAAS,EAAE,SAAS,KAAK,EAAM,OAAO,CAKtD,CAGF,MAAO,CAAE,cAAa,YAAW,CACnC,CAEA,cAAwE,CACtE,GAAM,CAAE,cAAa,cAAe,KAAK,QAAQ,EAEjD,MAAO,CACL,YAAa,EAAY,IAAK,IAAQ,CAAE,QAAS,EAAG,SAAS,GAAK,KAAM,EAAG,IAAK,EAAE,EAClF,YACF,CACF,CAGA,WAAW,GAAG,EAAqC,CACjD,OAAO,KAAK,OAAO,OAAQ,GAAU,EAAW,EAAM,KAAM,CAAI,CAAC,CAAC,CAAC,IAAK,GAAU,EAAM,OAAO,CACjG,CACF"}
package/dist/errors.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import{ErrorCode as e}from"./types.js";function t(e,t,n){return[{code:e,message:t,params:n,path:[]}]}function n(e,t){return typeof e==`function`?e(t):e}function r(e,t){return e.map(e=>({...e,path:[t,...e.path]}))}var i=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 a(e){return e.map(({code:e,message:t,path:n})=>`${n.length?n.join(`.`):`value`}: ${t} [${e}]`).join(`
2
- `)}function o(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var s=class extends i{},c=class extends i{issues;constructor(e,t){super(a(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=>o(t.path,e)).map(e=>e.message)}};export{s as SpellDefinitionError,i as SpellError,c as SpellValidationError,t as fail,r as prependIssuePath,n as resolveMessage};
2
+ `)}function o(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var s=class extends i{},c=class extends i{issues;constructor(e,t){super(a(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=>o(t.path,e)).map(e=>e.message)}};export{s as SpellDefinitionError,i as SpellError,c as SpellValidationError,t as fail,r as prependIssuePath,n as resolveMessage};
3
3
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ErrorCode, type Issue, type MessageFn } from './types';\n\n/* -------------------- Helpers -------------------- */\n\ntype IssueParams<C extends string> = Extract<Issue, { code: C }> extends { params: infer P } ? P : undefined;\n\n/**\n * Creates a single-error failure array. Use in validator functions instead of building the array manually.\n * Typed overloads ensure params match the given error code.\n */\nexport function fail<C extends ErrorCode>(code: C, message: string, params: IssueParams<C>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[] {\n return [{ code, message, params, path: [] } as Issue];\n}\n\n/** @internal */\nexport function resolveMessage<Ctx extends Record<string, unknown>>(msg: MessageFn<Ctx>, ctx: Ctx): string {\n return typeof msg === 'function' ? msg(ctx) : msg;\n}\n\nexport function prependIssuePath(issues: Issue[], prefix: string | number): Issue[] {\n return issues.map((issue) => ({ ...issue, path: [prefix, ...issue.path] }));\n}\n\n/* -------------------- SpellError -------------------- */\n\n/** Base class for all spell errors. Use `instanceof SpellError` to catch any spell-originated error. */\nexport class SpellError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is SpellError {\n return err instanceof SpellError;\n }\n}\n\n/* -------------------- SpellValidationError -------------------- */\n\nfunction formatIssues(issues: Issue[]): string {\n return issues\n .map(({ code, message, path }) => {\n const pathStr = path.length ? path.join('.') : 'value';\n\n return `${pathStr}: ${message} [${code}]`;\n })\n .join('\\n');\n}\n\nfunction pathsEqual(left: readonly (string | number)[], right: readonly (string | number)[]): boolean {\n return left.length === right.length && left.every((segment, index) => segment === right[index]);\n}\n\nexport type FlatError = { messages: string[]; path: (string | number)[] };\nexport type FlatErrorFirst = { message: string; path: (string | number)[] };\n\nexport class SpellDefinitionError extends SpellError {}\n\nexport class SpellValidationError extends SpellError {\n readonly issues: Issue[];\n\n constructor(issues: Issue[], cause?: unknown) {\n super(formatIssues(issues), { cause });\n this.issues = issues;\n }\n\n /**\n * Returns the most-specific branch errors for `issue`, or the first union issue when omitted.\n * Surfaces the branch with the fewest issues at the deepest path — the one that \"came closest\" to matching.\n */\n bestMatch(issue?: Extract<Issue, { code: 'invalid_union' }>): Issue[] | null {\n const unionIssue =\n issue ??\n this.issues.find(\n (entry): entry is Extract<Issue, { code: 'invalid_union' }> => entry.code === ErrorCode.invalid_union,\n );\n\n if (!unionIssue) return null;\n\n const branches = unionIssue.params.errors;\n\n if (branches.length === 0) return null;\n\n const scored = branches.map((branchIssues) => {\n const maxDepth = branchIssues.reduce((d, i) => Math.max(d, i.path.length), 0);\n\n return { issues: branchIssues, score: maxDepth * 1000 - branchIssues.length };\n });\n\n scored.sort((a, b) => b.score - a.score);\n\n return scored[0]!.issues;\n }\n\n flatten(): { fieldErrors: FlatError[]; formErrors: string[] } {\n const fieldErrors: FlatError[] = [];\n const formErrors: string[] = [];\n const pathMap = new Map<string, number>();\n\n for (const issue of this.issues) {\n if (issue.path.length === 0) {\n formErrors.push(issue.message);\n } else {\n const key = JSON.stringify(issue.path);\n const existing = pathMap.get(key);\n\n if (existing !== undefined) {\n fieldErrors[existing]!.messages.push(issue.message);\n } else {\n pathMap.set(key, fieldErrors.length);\n fieldErrors.push({ messages: [issue.message], path: [...issue.path] });\n }\n }\n }\n\n return { fieldErrors, formErrors };\n }\n\n flattenFirst(): { fieldErrors: FlatErrorFirst[]; formErrors: string[] } {\n const { fieldErrors, formErrors } = this.flatten();\n\n return {\n fieldErrors: fieldErrors.map((fe) => ({ message: fe.messages[0]!, path: fe.path })),\n formErrors,\n };\n }\n\n /** Returns every message attached to exactly `path`, in issue order. */\n messagesAt(...path: (string | number)[]): string[] {\n return this.issues.filter((issue) => pathsEqual(issue.path, path)).map((issue) => issue.message);\n }\n}\n"],"mappings":"uCAYA,SAAgB,EAAK,EAAc,EAAiB,EAA2C,CAC7F,MAAO,CAAC,CAAE,OAAM,UAAS,SAAQ,KAAM,CAAC,CAAE,CAAU,CACtD,CAGA,SAAgB,EAAoD,EAAqB,EAAkB,CACzG,OAAO,OAAO,GAAQ,WAAa,EAAI,CAAG,EAAI,CAChD,CAEA,SAAgB,EAAiB,EAAiB,EAAkC,CAClF,OAAO,EAAO,IAAK,IAAW,CAAE,GAAG,EAAO,KAAM,CAAC,EAAQ,GAAG,EAAM,IAAI,CAAE,EAAE,CAC5E,CAKA,IAAa,EAAb,MAAa,UAAmB,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CAEA,OAAO,GAAG,EAAiC,CACzC,OAAO,aAAe,CACxB,CACF,EAIA,SAAS,EAAa,EAAyB,CAC7C,OAAO,EACJ,KAAK,CAAE,OAAM,UAAS,UAGd,GAFS,EAAK,OAAS,EAAK,KAAK,GAAG,EAAI,QAE7B,IAAI,EAAQ,IAAI,EAAK,EACxC,CAAC,CACD,KAAK;CAAI,CACd,CAEA,SAAS,EAAW,EAAoC,EAA8C,CACpG,OAAO,EAAK,SAAW,EAAM,QAAU,EAAK,OAAO,EAAS,IAAU,IAAY,EAAM,EAAM,CAChG,CAKA,IAAa,EAAb,cAA0C,CAAW,CAAC,EAEzC,EAAb,cAA0C,CAAW,CACnD,OAEA,YAAY,EAAiB,EAAiB,CAC5C,MAAM,EAAa,CAAM,EAAG,CAAE,OAAM,CAAC,EACrC,KAAK,OAAS,CAChB,CAMA,UAAU,EAAmE,CAC3E,IAAM,EACJ,GACA,KA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names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { ErrorCode, type Issue, type MessageFn } from './types';\n\n/* -------------------- Helpers -------------------- */\n\ntype IssueParams<C extends string> = Extract<Issue, { code: C }> extends { params: infer P } ? P : undefined;\n\n/**\n * Creates a single-error failure array. Use in validator functions instead of building the array manually.\n * Typed overloads ensure params match the given error code.\n */\nexport function fail<C extends ErrorCode>(code: C, message: string, params: IssueParams<C>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[];\nexport function fail(code: string, message: string, params?: Record<string, unknown>): Issue[] {\n return [{ code, message, params, path: [] } as Issue];\n}\n\n/** @internal */\nexport function resolveMessage<Ctx extends Record<string, unknown>>(msg: MessageFn<Ctx>, ctx: Ctx): string {\n return typeof msg === 'function' ? msg(ctx) : msg;\n}\n\nexport function prependIssuePath(issues: Issue[], prefix: string | number): Issue[] {\n return issues.map((issue) => ({ ...issue, path: [prefix, ...issue.path] }));\n}\n\n/* -------------------- SpellError -------------------- */\n\n/** Base class for all spell errors. Use `instanceof SpellError` to catch any spell-originated error. */\nexport class SpellError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n static is(err: unknown): err is SpellError {\n return err instanceof SpellError;\n }\n}\n\n/* -------------------- SpellValidationError -------------------- */\n\nfunction formatIssues(issues: Issue[]): string {\n return issues\n .map(({ code, message, path }) => {\n const pathStr = path.length ? path.join('.') : 'value';\n\n return `${pathStr}: ${message} [${code}]`;\n })\n .join('\\n');\n}\n\nfunction pathsEqual(left: readonly (string | number)[], right: readonly (string | number)[]): boolean {\n return left.length === right.length && left.every((segment, index) => segment === right[index]);\n}\n\nexport type FlatError = { messages: string[]; path: (string | number)[] };\nexport type FlatErrorFirst = { message: string; path: (string | number)[] };\n\nexport class SpellDefinitionError extends SpellError {}\n\nexport class SpellValidationError extends SpellError {\n readonly issues: Issue[];\n\n constructor(issues: Issue[], cause?: unknown) {\n super(formatIssues(issues), { cause });\n this.issues = issues;\n }\n\n /**\n * Returns the most-specific branch errors for `issue`, or the first union issue when omitted.\n * Surfaces the branch with the fewest issues at the deepest path — the one that \"came closest\" to matching.\n */\n bestMatch(issue?: Extract<Issue, { code: 'invalid_union' }>): Issue[] | null {\n const unionIssue =\n issue ??\n this.issues.find(\n (entry): entry is Extract<Issue, { code: 'invalid_union' }> => entry.code === ErrorCode.invalid_union,\n );\n\n if (!unionIssue) return null;\n\n const branches = unionIssue.params.errors;\n\n if (branches.length === 0) return null;\n\n const scored = branches.map((branchIssues) => {\n const maxDepth = branchIssues.reduce((d, i) => Math.max(d, i.path.length), 0);\n\n return { issues: branchIssues, score: maxDepth * 1000 - branchIssues.length };\n });\n\n scored.sort((a, b) => b.score - a.score);\n\n return scored[0]?.issues;\n }\n\n flatten(): { fieldErrors: FlatError[]; formErrors: string[] } {\n const fieldErrors: FlatError[] = [];\n const formErrors: string[] = [];\n const pathMap = new Map<string, number>();\n\n for (const issue of this.issues) {\n if (issue.path.length === 0) {\n formErrors.push(issue.message);\n } else {\n const key = JSON.stringify(issue.path);\n const existing = pathMap.get(key);\n\n if (existing !== undefined) {\n fieldErrors[existing]?.messages.push(issue.message);\n } else {\n pathMap.set(key, fieldErrors.length);\n fieldErrors.push({ messages: [issue.message], path: [...issue.path] });\n }\n }\n }\n\n return { fieldErrors, formErrors };\n }\n\n flattenFirst(): { fieldErrors: FlatErrorFirst[]; formErrors: string[] } {\n const { fieldErrors, formErrors } = this.flatten();\n\n return {\n fieldErrors: fieldErrors.map((fe) => ({ message: fe.messages[0]!, path: fe.path })),\n formErrors,\n };\n }\n\n /** Returns every message attached to exactly `path`, in issue order. */\n messagesAt(...path: (string | number)[]): string[] {\n return this.issues.filter((issue) => pathsEqual(issue.path, path)).map((issue) => issue.message);\n }\n}\n"],"mappings":"uCAYA,SAAgB,EAAK,EAAc,EAAiB,EAA2C,CAC7F,MAAO,CAAC,CAAE,OAAM,UAAS,SAAQ,KAAM,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,KAAK,MAAM,EAAG,CAErC,EAAW,IAAO,EAAa,MAAO,EAC7E,EAID,OAFA,EAAO,MAAM,EAAG,IAAM,EAAE,MAAQ,EAAE,KAAK,EAEhC,EAAO,EAAE,EAAE,MACpB,CAEA,SAA8D,CAC5D,IAAM,EAA2B,CAAC,EAC5B,EAAuB,CAAC,EACxB,EAAU,IAAI,IAEpB,IAAK,IAAM,KAAS,KAAK,OACvB,GAAI,EAAM,KAAK,SAAW,EACxB,EAAW,KAAK,EAAM,OAAO,MACxB,CACL,IAAM,EAAM,KAAK,UAAU,EAAM,IAAI,EAC/B,EAAW,EAAQ,IAAI,CAAG,EAE5B,IAAa,IAAA,IAGf,EAAQ,IAAI,EAAK,EAAY,MAAM,EACnC,EAAY,KAAK,CAAE,SAAU,CAAC,EAAM,OAAO,EAAG,KAAM,CAAC,GAAG,EAAM,IAAI,CAAE,CAAC,GAHrE,EAAY,EAAS,EAAE,SAAS,KAAK,EAAM,OAAO,CAKtD,CAGF,MAAO,CAAE,cAAa,YAAW,CACnC,CAEA,cAAwE,CACtE,GAAM,CAAE,cAAa,cAAe,KAAK,QAAQ,EAEjD,MAAO,CACL,YAAa,EAAY,IAAK,IAAQ,CAAE,QAAS,EAAG,SAAS,GAAK,KAAM,EAAG,IAAK,EAAE,EAClF,YACF,CACF,CAGA,WAAW,GAAG,EAAqC,CACjD,OAAO,KAAK,OAAO,OAAQ,GAAU,EAAW,EAAM,KAAM,CAAI,CAAC,CAAC,CAAC,IAAK,GAAU,EAAM,OAAO,CACjG,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { fail, prependIssuePath } from './errors';\nimport { createParseContext } from './messages';\n\nexport {\n ErrorCode,\n PipeSchema,\n Schema,\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n schemaMode,\n} from './core';\nexport type {\n AnySchema,\n CheckContext,\n FlatError,\n FlatErrorFirst,\n Infer,\n InferInput,\n InferOutput,\n InferSchemaMode,\n Issue,\n MergeSchemaModes,\n SchemaMode,\n JsonSchema,\n MessageFn,\n Messages,\n ParseContext,\n ParseResult,\n SchemaDefinition,\n SchemaDescriptor,\n SchemaWalker,\n ValidateFn,\n ValidateResult,\n} from './core';\nexport { s } from './s';\nexport type { DeepPartial } from './messages';\n\n/** Error helpers and immutable parse-context creation are secondary operations. */\nexport const diagnostics = {\n createParseContext,\n fail,\n prependIssuePath,\n};\n"],"mappings":"qMAuCA,IAAa,EAAc,CACzB,mBAAA,EAAA,mBACA,KAAA,EAAA,KACA,iBAAA,EAAA,gBACF"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { fail, prependIssuePath } from './errors';\nimport { createParseContext } from './messages';\n\nexport type {\n AnySchema,\n CheckContext,\n FlatError,\n FlatErrorFirst,\n Infer,\n InferInput,\n InferOutput,\n InferSchemaMode,\n Issue,\n JsonSchema,\n MergeSchemaModes,\n MessageFn,\n Messages,\n ParseContext,\n ParseResult,\n SchemaDescriptor,\n SchemaMode,\n SchemaWalker,\n ValidateFn,\n ValidateResult,\n} from './core';\nexport {\n ErrorCode,\n PipeSchema,\n Schema,\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n schemaMode,\n} from './core';\nexport type { DeepPartial } from './messages';\nexport { s } from './s';\n\n/** Error helpers and immutable parse-context creation are secondary operations. */\nexport const diagnostics = {\n createParseContext,\n fail,\n prependIssuePath,\n};\n"],"mappings":"qMAsCA,IAAa,EAAc,CACzB,mBAAA,EAAA,mBACA,KAAA,EAAA,KACA,iBAAA,EAAA,gBACF"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { fail, prependIssuePath } from './errors';
2
2
  import { createParseContext } from './messages';
3
+ export type { AnySchema, CheckContext, FlatError, FlatErrorFirst, Infer, InferInput, InferOutput, InferSchemaMode, Issue, JsonSchema, MergeSchemaModes, MessageFn, Messages, ParseContext, ParseResult, SchemaDescriptor, SchemaMode, SchemaWalker, ValidateFn, ValidateResult, } from './core';
3
4
  export { ErrorCode, PipeSchema, Schema, SpellDefinitionError, SpellError, SpellValidationError, schemaMode, } from './core';
4
- export type { AnySchema, CheckContext, FlatError, FlatErrorFirst, Infer, InferInput, InferOutput, InferSchemaMode, Issue, MergeSchemaModes, SchemaMode, JsonSchema, MessageFn, Messages, ParseContext, ParseResult, SchemaDefinition, SchemaDescriptor, SchemaWalker, ValidateFn, ValidateResult, } from './core';
5
- export { s } from './s';
6
5
  export type { DeepPartial } from './messages';
6
+ export { s } from './s';
7
7
  /** Error helpers and immutable parse-context creation are secondary operations. */
8
8
  export declare const diagnostics: {
9
9
  createParseContext: typeof createParseContext;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EACL,SAAS,EACT,UAAU,EACV,MAAM,EACN,oBAAoB,EACpB,UAAU,EACV,oBAAoB,EACpB,UAAU,GACX,MAAM,QAAQ,CAAC;AAChB,YAAY,EACV,SAAS,EACT,YAAY,EACZ,SAAS,EACT,cAAc,EACd,KAAK,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,KAAK,EACL,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,mFAAmF;AACnF,eAAO,MAAM,WAAW;;;;CAIvB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,YAAY,EACV,SAAS,EACT,YAAY,EACZ,SAAS,EACT,cAAc,EACd,KAAK,EACL,UAAU,EACV,WAAW,EACX,eAAe,EACf,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,UAAU,EACV,cAAc,GACf,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,SAAS,EACT,UAAU,EACV,MAAM,EACN,oBAAoB,EACpB,UAAU,EACV,oBAAoB,EACpB,UAAU,GACX,MAAM,QAAQ,CAAC;AAChB,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,mFAAmF;AACnF,eAAO,MAAM,WAAW;;;;CAIvB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { fail, prependIssuePath } from './errors';\nimport { createParseContext } from './messages';\n\nexport {\n ErrorCode,\n PipeSchema,\n Schema,\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n schemaMode,\n} from './core';\nexport type {\n AnySchema,\n CheckContext,\n FlatError,\n FlatErrorFirst,\n Infer,\n InferInput,\n InferOutput,\n InferSchemaMode,\n Issue,\n MergeSchemaModes,\n SchemaMode,\n JsonSchema,\n MessageFn,\n Messages,\n ParseContext,\n ParseResult,\n SchemaDefinition,\n SchemaDescriptor,\n SchemaWalker,\n ValidateFn,\n ValidateResult,\n} from './core';\nexport { s } from './s';\nexport type { DeepPartial } from './messages';\n\n/** Error helpers and immutable parse-context creation are secondary operations. */\nexport const diagnostics = {\n createParseContext,\n fail,\n prependIssuePath,\n};\n"],"mappings":"qTAuCA,IAAa,EAAc,CACzB,qBACA,OACA,kBACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { fail, prependIssuePath } from './errors';\nimport { createParseContext } from './messages';\n\nexport type {\n AnySchema,\n CheckContext,\n FlatError,\n FlatErrorFirst,\n Infer,\n InferInput,\n InferOutput,\n InferSchemaMode,\n Issue,\n JsonSchema,\n MergeSchemaModes,\n MessageFn,\n Messages,\n ParseContext,\n ParseResult,\n SchemaDescriptor,\n SchemaMode,\n SchemaWalker,\n ValidateFn,\n ValidateResult,\n} from './core';\nexport {\n ErrorCode,\n PipeSchema,\n Schema,\n SpellDefinitionError,\n SpellError,\n SpellValidationError,\n schemaMode,\n} from './core';\nexport type { DeepPartial } from './messages';\nexport { s } from './s';\n\n/** Error helpers and immutable parse-context creation are secondary operations. */\nexport const diagnostics = {\n createParseContext,\n fail,\n prependIssuePath,\n};\n"],"mappings":"qTAsCA,IAAa,EAAc,CACzB,qBACA,OACA,kBACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"json-schema.cjs","names":[],"sources":["../src/json-schema.ts"],"sourcesContent":["import type { JsonSchema, SchemaDefinition, SchemaDescriptor } from './types';\n\nimport { defineOwnProperty } from './safe-object';\n\nexport function definitionToJsonSchema(definition: SchemaDefinition): JsonSchema {\n return descriptorToJsonSchema(definition);\n}\n\n/** Converts a schema definition to a draft 2020-12-compatible JSON Schema object. */\nexport function descriptorToJsonSchema(d: SchemaDescriptor): JsonSchema {\n const base = _descriptorToBase(d);\n let result: JsonSchema = base;\n\n if (d.isNullable) result = { anyOf: [base, { type: 'null' }] };\n\n if (d.description) result = { ...result, description: d.description };\n\n return result;\n}\n\nfunction _descriptorToBase(d: SchemaDescriptor): JsonSchema {\n switch (d.kind) {\n case 'any':\n case 'unknown':\n return {};\n\n case 'array': {\n const out: JsonSchema = { items: descriptorToJsonSchema(d.items), type: 'array' };\n\n if (d.minItems !== undefined) out['minItems'] = d.minItems;\n\n if (d.maxItems !== undefined) out['maxItems'] = d.maxItems;\n\n return out;\n }\n\n case 'bigint':\n return { type: 'integer' };\n\n case 'boolean':\n return { type: 'boolean' };\n\n case 'date':\n return {\n $comment:\n 'Date objects are not representable in JSON Schema. Validate as a string with a date format in JSON contexts.',\n };\n\n case 'enum':\n return { enum: [...d.values] };\n\n case 'instanceof':\n return {\n $comment: `Instances of \"${d.className}\" are not representable in JSON Schema.`,\n };\n\n case 'intersect':\n return { allOf: d.branches.map(descriptorToJsonSchema) };\n\n case 'lazy':\n return {};\n\n case 'literal':\n if (d.value === null) return { type: 'null' };\n\n if (d.value === undefined) return {};\n\n return { const: d.value };\n\n case 'map':\n return {\n $comment: 'Map type — represented as an object with arbitrary string keys.',\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'never':\n return { not: {} };\n\n case 'number': {\n const out: JsonSchema = { type: d.typeHint === 'integer' ? 'integer' : 'number' };\n\n if (d.minimum !== undefined) out['minimum'] = d.minimum;\n\n if (d.maximum !== undefined) out['maximum'] = d.maximum;\n\n if (d.exclusiveMinimum !== undefined) out['exclusiveMinimum'] = d.exclusiveMinimum;\n\n if (d.exclusiveMaximum !== undefined) out['exclusiveMaximum'] = d.exclusiveMaximum;\n\n if (d.multipleOf !== undefined) out['multipleOf'] = d.multipleOf;\n\n return out;\n }\n\n case 'object': {\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n for (const [key, fieldDescriptor] of Object.entries(d.fields)) {\n defineOwnProperty(properties, key, descriptorToJsonSchema(fieldDescriptor));\n\n if (!fieldDescriptor.isOptional) required.push(key);\n }\n\n const out: JsonSchema = { properties, type: 'object' };\n\n if (required.length > 0) out['required'] = required;\n\n if (d.strict) out['additionalProperties'] = false;\n\n return out;\n }\n\n case 'pipe':\n return descriptorToJsonSchema(d.to);\n\n case 'record':\n return {\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'set':\n return {\n $comment: 'Set<T> — no standard JSON Schema equivalent; treated as an ordered unique-item array.',\n items: descriptorToJsonSchema(d.items),\n type: 'array',\n uniqueItems: true,\n };\n\n case 'string': {\n const out: JsonSchema = { type: 'string' };\n\n if (d.minLength !== undefined) out['minLength'] = d.minLength;\n\n if (d.maxLength !== undefined) out['maxLength'] = d.maxLength;\n\n if (d.pattern != null) out['pattern'] = d.pattern;\n\n if (d.format !== undefined) out['format'] = d.format;\n\n if (d.contentEncoding !== undefined) out['contentEncoding'] = d.contentEncoding;\n\n return out;\n }\n\n case 'tuple': {\n const out: JsonSchema = {\n prefixItems: d.items.map(descriptorToJsonSchema),\n type: 'array',\n };\n\n if (d.rest !== null) {\n out['items'] = descriptorToJsonSchema(d.rest);\n } else {\n out['items'] = false;\n }\n\n return out;\n }\n\n case 'union':\n return { anyOf: d.branches.map(descriptorToJsonSchema) };\n case 'variant':\n return {\n discriminator: { propertyName: d.discriminator },\n oneOf: Object.values(d.branches).map(descriptorToJsonSchema),\n };\n }\n}\n"],"mappings":"qCAIA,SAAgB,EAAuB,EAA0C,CAC/E,OAAO,EAAuB,CAAU,CAC1C,CAGA,SAAgB,EAAuB,EAAiC,CACtE,IAAM,EAAO,EAAkB,CAAC,EAC5B,EAAqB,EAMzB,OAJI,EAAE,aAAY,EAAS,CAAE,MAAO,CAAC,EAAM,CAAE,KAAM,MAAO,CAAC,CAAE,GAEzD,EAAE,cAAa,EAAS,CAAE,GAAG,EAAQ,YAAa,EAAE,WAAY,GAE7D,CACT,CAEA,SAAS,EAAkB,EAAiC,CAC1D,OAAQ,EAAE,KAAV,CACE,IAAK,MACL,IAAK,UACH,MAAO,CAAC,EAEV,IAAK,QAAS,CACZ,IAAM,EAAkB,CAAE,MAAO,EAAuB,EAAE,KAAK,EAAG,KAAM,OAAQ,EAMhF,OAJI,EAAE,WAAa,IAAA,KAAW,EAAI,SAAc,EAAE,UAE9C,EAAE,WAAa,IAAA,KAAW,EAAI,SAAc,EAAE,UAE3C,CACT,CAEA,IAAK,SACH,MAAO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AAG,EAAI,SAAc,GAEvC,EAAE,SAAQ,EAAI,qBAA0B,IAErC,CACT,CAEA,IAAK,OACH,OAAO,EAAuB,EAAE,EAAE,EAEpC,IAAK,SACH,MAAO,CACL,qBAAsB,EAAuB,EAAE,KAAK,EACpD,KAAM,QACR,EAEF,IAAK,MACH,MAAO,CACL,SAAU,wFACV,MAAO,EAAuB,EAAE,KAAK,EACrC,KAAM,QACN,YAAa,EACf,EAEF,IAAK,SAAU,CACb,IAAM,EAAkB,CAAE,KAAM,QAAS,EAYzC,OAVI,EAAE,YAAc,IAAA,KAAW,EAAI,UAAe,EAAE,WAEhD,EAAE,YAAc,IAAA,KAAW,EAAI,UAAe,EAAE,WAEhD,EAAE,SAAW,OAAM,EAAI,QAAa,EAAE,SAEtC,EAAE,SAAW,IAAA,KAAW,EAAI,OAAY,EAAE,QAE1C,EAAE,kBAAoB,IAAA,KAAW,EAAI,gBAAqB,EAAE,iBAEzD,CACT,CAEA,IAAK,QAAS,CACZ,IAAM,EAAkB,CACtB,YAAa,EAAE,MAAM,IAAI,CAAsB,EAC/C,KAAM,OACR,EAQA,MANA,CACE,EAAI,MADF,EAAE,OAAS,MACE,EAAuB,EAAE,IAAI,EAKvC,CACT,CAEA,IAAK,QACH,MAAO,CAAE,MAAO,EAAE,SAAS,IAAI,CAAsB,CAAE,EACzD,IAAK,UACH,MAAO,CACL,cAAe,CAAE,aAAc,EAAE,aAAc,EAC/C,MAAO,OAAO,OAAO,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAsB,CAC7D,CACJ,CACF"}
1
+ {"version":3,"file":"json-schema.cjs","names":[],"sources":["../src/json-schema.ts"],"sourcesContent":["import { defineOwnProperty } from './safe-object';\nimport type { JsonSchema, SchemaDescriptor } from './types';\n\nexport function definitionToJsonSchema(definition: SchemaDescriptor): JsonSchema {\n return descriptorToJsonSchema(definition);\n}\n\n/** Converts a schema definition to a draft 2020-12-compatible JSON Schema object. */\nexport function descriptorToJsonSchema(d: SchemaDescriptor): JsonSchema {\n const base = _descriptorToBase(d);\n let result: JsonSchema = base;\n\n if (d.isNullable) result = { anyOf: [base, { type: 'null' }] };\n\n if (d.description) result = { ...result, description: d.description };\n\n return result;\n}\n\nfunction _descriptorToBase(d: SchemaDescriptor): JsonSchema {\n switch (d.kind) {\n case 'any':\n case 'unknown':\n return {};\n\n case 'array': {\n const out: JsonSchema = { items: descriptorToJsonSchema(d.items), type: 'array' };\n\n if (d.minItems !== undefined) out.minItems = d.minItems;\n\n if (d.maxItems !== undefined) out.maxItems = d.maxItems;\n\n return out;\n }\n\n case 'bigint':\n return { type: 'integer' };\n\n case 'boolean':\n return { type: 'boolean' };\n\n case 'date':\n return {\n $comment:\n 'Date objects are not representable in JSON Schema. Validate as a string with a date format in JSON contexts.',\n };\n\n case 'enum':\n return { enum: [...d.values] };\n\n case 'instanceof':\n return {\n $comment: `Instances of \"${d.className}\" are not representable in JSON Schema.`,\n };\n\n case 'intersect':\n return { allOf: d.branches.map(descriptorToJsonSchema) };\n\n case 'lazy':\n return {};\n\n case 'literal':\n if (d.value === null) return { type: 'null' };\n\n if (d.value === undefined) return {};\n\n return { const: d.value };\n\n case 'map':\n return {\n $comment: 'Map type — represented as an object with arbitrary string keys.',\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'never':\n return { not: {} };\n\n case 'number': {\n const out: JsonSchema = { type: d.typeHint === 'integer' ? 'integer' : 'number' };\n\n if (d.minimum !== undefined) out.minimum = d.minimum;\n\n if (d.maximum !== undefined) out.maximum = d.maximum;\n\n if (d.exclusiveMinimum !== undefined) out.exclusiveMinimum = d.exclusiveMinimum;\n\n if (d.exclusiveMaximum !== undefined) out.exclusiveMaximum = d.exclusiveMaximum;\n\n if (d.multipleOf !== undefined) out.multipleOf = d.multipleOf;\n\n return out;\n }\n\n case 'object': {\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n for (const [key, fieldDescriptor] of Object.entries(d.fields)) {\n defineOwnProperty(properties, key, descriptorToJsonSchema(fieldDescriptor));\n\n if (!fieldDescriptor.isOptional) required.push(key);\n }\n\n const out: JsonSchema = { properties, type: 'object' };\n\n if (required.length > 0) out.required = required;\n\n if (d.strict) out.additionalProperties = false;\n\n return out;\n }\n\n case 'pipe':\n return descriptorToJsonSchema(d.to);\n\n case 'record':\n return {\n additionalProperties: descriptorToJsonSchema(d.value),\n type: 'object',\n };\n\n case 'set':\n return {\n $comment: 'Set<T> — no standard JSON Schema equivalent; treated as an ordered unique-item array.',\n items: descriptorToJsonSchema(d.items),\n type: 'array',\n uniqueItems: true,\n };\n\n case 'string': {\n const out: JsonSchema = { type: 'string' };\n\n if (d.minLength !== undefined) out.minLength = d.minLength;\n\n if (d.maxLength !== undefined) out.maxLength = d.maxLength;\n\n if (d.pattern != null) out.pattern = d.pattern;\n\n if (d.format !== undefined) out.format = d.format;\n\n if (d.contentEncoding !== undefined) out.contentEncoding = d.contentEncoding;\n\n return out;\n }\n\n case 'tuple': {\n const out: JsonSchema = {\n prefixItems: d.items.map(descriptorToJsonSchema),\n type: 'array',\n };\n\n if (d.rest !== null) {\n out.items = descriptorToJsonSchema(d.rest);\n } else {\n out.items = false;\n }\n\n return out;\n }\n\n case 'union':\n return { anyOf: d.branches.map(descriptorToJsonSchema) };\n case 'variant':\n return {\n discriminator: { propertyName: d.discriminator },\n oneOf: Object.values(d.branches).map(descriptorToJsonSchema),\n };\n }\n}\n"],"mappings":"qCAGA,SAAgB,EAAuB,EAA0C,CAC/E,OAAO,EAAuB,CAAU,CAC1C,CAGA,SAAgB,EAAuB,EAAiC,CACtE,IAAM,EAAO,EAAkB,CAAC,EAC5B,EAAqB,EAMzB,OAJI,EAAE,aAAY,EAAS,CAAE,MAAO,CAAC,EAAM,CAAE,KAAM,MAAO,CAAC,CAAE,GAEzD,EAAE,cAAa,EAAS,CAAE,GAAG,EAAQ,YAAa,EAAE,WAAY,GAE7D,CACT,CAEA,SAAS,EAAkB,EAAiC,CAC1D,OAAQ,EAAE,KAAV,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1,5 +1,5 @@
1
- import type { JsonSchema, SchemaDefinition, SchemaDescriptor } from './types';
2
- export declare function definitionToJsonSchema(definition: SchemaDefinition): JsonSchema;
1
+ import type { JsonSchema, SchemaDescriptor } from './types';
2
+ export declare function definitionToJsonSchema(definition: SchemaDescriptor): JsonSchema;
3
3
  /** Converts a schema definition to a draft 2020-12-compatible JSON Schema object. */
4
4
  export declare function descriptorToJsonSchema(d: SchemaDescriptor): JsonSchema;
5
5
  //# sourceMappingURL=json-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAI9E,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,gBAAgB,GAAG,UAAU,CAE/E;AAED,qFAAqF;AACrF,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAStE"}
1
+ {"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE5D,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,gBAAgB,GAAG,UAAU,CAE/E;AAED,qFAAqF;AACrF,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,gBAAgB,GAAG,UAAU,CAStE"}