@vielzeug/spell 2.1.1 → 2.2.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.
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/spell.cjs +1 -1
- package/dist/spell.cjs.map +1 -1
- package/dist/spell.iife.js +1 -1
- package/dist/spell.iife.js.map +1 -1
- package/dist/spell.js +1 -1
- package/dist/spell.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +1 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -1
package/dist/errors.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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
|
|
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 extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}};function a(e){return e.map(({code:e,message:t,path:n})=>`${n.length?n.join(`.`):`value`}: ${t} [${e}]`).join(`
|
|
2
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
|
package/dist/errors.cjs.map
CHANGED
|
@@ -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
|
|
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\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,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,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,KAAK,OAAO,KACT,GAA8D,EAAM,OAAS,EAAA,UAAU,aAC1F,EAEF,GAAI,CAAC,EAAY,OAAO,KAExB,IAAM,EAAW,EAAW,OAAO,OAEnC,GAAI,EAAS,SAAW,EAAG,OAAO,KAElC,IAAM,EAAS,EAAS,IAAK,IAGpB,CAAE,OAAQ,EAAc,MAFd,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.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export declare function prependIssuePath(issues: Issue[], prefix: string | numbe
|
|
|
14
14
|
/** Base class for all spell errors. Use `instanceof SpellError` to catch any spell-originated error. */
|
|
15
15
|
export declare class SpellError extends Error {
|
|
16
16
|
constructor(message: string, opts?: ErrorOptions);
|
|
17
|
-
static is(err: unknown): err is SpellError;
|
|
18
17
|
}
|
|
19
18
|
export type FlatError = {
|
|
20
19
|
messages: string[];
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,KAAK,EAAkB,MAAM,SAAS,CAAC;AAIhE,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAE7G;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;AACrG,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,EAAE,CAAC;AAU/F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,EAAE,CAElF;AAID,wGAAwG;AACxG,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,KAAK,EAAkB,MAAM,SAAS,CAAC;AAIhE,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAE7G;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;AACrG,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,KAAK,EAAE,CAAC;AAU/F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,EAAE,CAElF;AAID,wGAAwG;AACxG,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAkBD,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CAAE,CAAC;AAC1E,MAAM,MAAM,cAAc,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;CAAE,CAAC;AAE5E,qBAAa,oBAAqB,SAAQ,UAAU;CAAG;AAEvD,qBAAa,oBAAqB,SAAQ,UAAU;IAClD,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;gBAEb,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO;IAK5C;;;OAGG;IACH,SAAS,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,eAAe,CAAA;KAAE,CAAC,GAAG,KAAK,EAAE,GAAG,IAAI;IAwB5E,OAAO,IAAI;QAAE,WAAW,EAAE,SAAS,EAAE,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE;IAwB7D,YAAY,IAAI;QAAE,WAAW,EAAE,cAAc,EAAE,CAAC;QAAC,UAAU,EAAE,MAAM,EAAE,CAAA;KAAE;IASvE,wEAAwE;IACxE,UAAU,CAAC,GAAG,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,MAAM,EAAE;CAGnD"}
|
package/dist/errors.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
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
|
|
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 extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}};function a(e){return e.map(({code:e,message:t,path:n})=>`${n.length?n.join(`.`):`value`}: ${t} [${e}]`).join(`
|
|
2
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
|
package/dist/errors.js.map
CHANGED
|
@@ -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
|
|
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\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,cAAgC,KAAM,CACpC,YAAY,EAAiB,EAAqB,CAChD,MAAM,EAAS,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,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,KAAK,OAAO,KACT,GAA8D,EAAM,OAAS,EAAU,aAC1F,EAEF,GAAI,CAAC,EAAY,OAAO,KAExB,IAAM,EAAW,EAAW,OAAO,OAEnC,GAAI,EAAS,SAAW,EAAG,OAAO,KAElC,IAAM,EAAS,EAAS,IAAK,IAGpB,CAAE,OAAQ,EAAc,MAFd,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/spell.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e={custom:`custom`,invalid_base64:`invalid_base64`,invalid_date:`invalid_date`,invalid_duration:`invalid_duration`,invalid_enum:`invalid_enum`,invalid_finite:`invalid_finite`,invalid_integer:`invalid_integer`,invalid_keys:`invalid_keys`,invalid_length:`invalid_length`,invalid_literal:`invalid_literal`,invalid_multiple_of:`invalid_multiple_of`,invalid_safe:`invalid_safe`,invalid_string:`invalid_string`,invalid_type:`invalid_type`,invalid_union:`invalid_union`,invalid_unique:`invalid_unique`,invalid_url:`invalid_url`,invalid_variant:`invalid_variant`,too_big:`too_big`,too_small:`too_small`},t=Symbol(`spell.schemaMode`);function n(e,t,n){return[{code:e,message:t,params:n,path:[]}]}function r(e,t){return typeof e==`function`?e(t):e}function i(e,t){return e.map(e=>({...e,path:[t,...e.path]}))}var a=class
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e={custom:`custom`,invalid_base64:`invalid_base64`,invalid_date:`invalid_date`,invalid_duration:`invalid_duration`,invalid_enum:`invalid_enum`,invalid_finite:`invalid_finite`,invalid_integer:`invalid_integer`,invalid_keys:`invalid_keys`,invalid_length:`invalid_length`,invalid_literal:`invalid_literal`,invalid_multiple_of:`invalid_multiple_of`,invalid_safe:`invalid_safe`,invalid_string:`invalid_string`,invalid_type:`invalid_type`,invalid_union:`invalid_union`,invalid_unique:`invalid_unique`,invalid_url:`invalid_url`,invalid_variant:`invalid_variant`,too_big:`too_big`,too_small:`too_small`},t=Symbol(`spell.schemaMode`);function n(e,t,n){return[{code:e,message:t,params:n,path:[]}]}function r(e,t){return typeof e==`function`?e(t):e}function i(e,t){return e.map(e=>({...e,path:[t,...e.path]}))}var a=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}};function o(e){return e.map(({code:e,message:t,path:n})=>`${n.length?n.join(`.`):`value`}: ${t} [${e}]`).join(`
|
|
2
2
|
`)}function s(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var c=class extends a{},l=class extends a{issues;constructor(e,t){super(o(e),{cause:t}),this.issues=e}bestMatch(t){let n=t??this.issues.find(t=>t.code===e.invalid_union);if(!n)return null;let r=n.params.errors;if(r.length===0)return null;let i=r.map(e=>({issues:e,score:e.reduce((e,t)=>Math.max(e,t.path.length),0)*1e3-e.length}));return i.sort((e,t)=>t.score-e.score),i[0]?.issues}flatten(){let e=[],t=[],n=new Map;for(let r of this.issues)if(r.path.length===0)t.push(r.message);else{let t=JSON.stringify(r.path),i=n.get(t);i===void 0?(n.set(t,e.length),e.push({messages:[r.message],path:[...r.path]})):e[i]?.messages.push(r.message)}return{fieldErrors:e,formErrors:t}}flattenFirst(){let{fieldErrors:e,formErrors:t}=this.flatten();return{fieldErrors:e.map(e=>({message:e.messages[0],path:e.path})),formErrors:t}}messagesAt(...e){return this.issues.filter(t=>s(t.path,e)).map(e=>e.message)}},u=new Set([`__proto__`,`constructor`,`prototype`]);function d(e){return u.has(e)}function f(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}function p(e){let t={};for(let[n,r]of e)f(t,n,r);return t}function m(e){return p(Object.entries(e))}var h={array:{length:({exact:e})=>`Must have exactly ${e} items`,max:({max:e})=>`Must have at most ${e} items`,min:({min:e})=>`Must have at least ${e} items`,nonEmpty:()=>`Cannot be empty`,type:()=>`Expected array`,unique:()=>`All items must be unique`},bigint:{max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,type:()=>`Expected bigint`},boolean:{type:()=>`Expected boolean`},check:{default:()=>`Invalid value`},date:{max:({max:e})=>`Must be before ${e.toISOString()}`,min:({min:e})=>`Must be after ${e.toISOString()}`,type:()=>`Expected valid date`},enum:{invalid:({values:e})=>`Expected one of: ${e.map(e=>JSON.stringify(e)).join(`, `)}`},instanceof:{type:({className:e})=>`Expected instance of ${e}`},literal:{expected:({expected:e})=>`Expected ${JSON.stringify(e)}`},map:{max:({max:e})=>`Must contain at most ${e} entries`,min:({min:e})=>`Must contain at least ${e} entries`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} entries`,type:()=>`Expected map`},never:{invalid:()=>`Value is not allowed`},number:{finite:()=>`Must be finite`,int:()=>`Must be an integer`,max:({max:e})=>`Must be at most ${e}`,min:({min:e})=>`Must be at least ${e}`,multipleOf:({step:e})=>`Must be a multiple of ${e}`,negative:()=>`Must be negative`,nonNegative:()=>`Must be non-negative`,nonPositive:()=>`Must be non-positive`,positive:()=>`Must be positive`,safe:()=>`Must be a safe integer`,type:()=>`Expected number`},object:{invalidKeys:({keys:e})=>`Unrecognized keys: ${e.join(`, `)}`,type:()=>`Expected object`},set:{max:({max:e})=>`Must contain at most ${e} items`,min:({min:e})=>`Must contain at least ${e} items`,nonEmpty:()=>`Cannot be empty`,size:({exact:e})=>`Must contain exactly ${e} items`,type:()=>`Expected set`},string:{base64:()=>`Invalid base64`,base64url:()=>`Invalid base64url`,cuid:()=>`Invalid CUID`,cuid2:()=>`Invalid CUID2`,date:()=>`Invalid date`,dateTime:()=>`Invalid datetime`,duration:()=>`Invalid ISO 8601 duration`,email:()=>`Invalid email address`,emoji:()=>`Invalid emoji sequence`,endsWith:({suffix:e})=>`Must end with "${e}"`,hex:()=>`Invalid hex`,hexColor:()=>`Invalid hex color`,includes:({substr:e})=>`Must include "${e}"`,ip:()=>`Invalid IP address`,jwt:()=>`Invalid JWT`,length:({exact:e})=>`Must be exactly ${e} characters`,max:({max:e})=>`Must be at most ${e} characters`,min:({min:e})=>`Must be at least ${e} characters`,nanoid:()=>`Invalid NanoID`,nonEmpty:()=>`Cannot be empty`,numeric:()=>`Invalid numeric string`,regex:()=>`Invalid format`,semver:()=>`Invalid semver`,slug:()=>`Invalid slug`,startsWith:({prefix:e})=>`Must start with "${e}"`,time:()=>`Invalid time`,type:()=>`Expected string`,ulid:()=>`Invalid ULID`,url:()=>`Invalid URL`,uuid:()=>`Invalid UUID`},tuple:{length:({exact:e})=>`Expected tuple of length ${e}`,min:({min:e})=>`Expected tuple with at least ${e} items`,type:()=>`Expected array`},union:{invalid:()=>`Does not match any of the expected types`},variant:{invalidDiscriminator:({discriminator:e,expected:t})=>`Invalid discriminator value at "${e}": expected ${t.map(e=>JSON.stringify(e)).join(` | `)}`,type:()=>`Expected object`}};function g(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function _(e,t){let n=m(e);for(let[e,r]of Object.entries(t)){if(r===void 0)continue;if(d(e)){`${e}`;continue}let t=n[e];g(t)&&g(r)?f(n,e,_(t,r)):f(n,e,r)}return n}function v(e={}){return{messages:_(h,e)}}function y(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function b(e){if(typeof e!=`object`||!e||Object.isFrozen(e))return e;for(let t of Object.values(e))b(t);return Object.freeze(e)}function x(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(e=>x(e));if(e instanceof Date)return new Date(e.getTime());if(e instanceof Map){let t=new Map;for(let[n,r]of e.entries())t.set(x(n),x(r));return t}if(e instanceof Set)return new Set([...e.values()].map(e=>x(e)));if(y(e)){let t={};for(let[n,r]of Object.entries(e))f(t,n,x(r));return t}return e}function ee(){return{hasAsyncChecks:!1,hasRuntimeChecks:!1,isNullable:!1,isOptional:!1,postprocessors:[],preprocessors:[],validators:[]}}function S(e){return{catch:e.catch,defaultValue:e.defaultValue,description:e.description,hasAsyncChecks:e.hasAsyncChecks,hasRuntimeChecks:e.hasRuntimeChecks,isNullable:e.isNullable,isOptional:e.isOptional,postprocessors:[...e.postprocessors],preprocessors:[...e.preprocessors],validators:[...e.validators]}}function C(e){return e?{messages:e}:v()}function w(t,n,r){let i=[...n];return typeof t==`string`?i.push({code:e.custom,message:t,path:[]}):t===!1&&i.length===0&&i.push({code:e.custom,message:r.messages.check.default(),path:[]}),i.length?i:null}var T=class{state;_annotations={};_typeValidator=null;constructor(e){this.state=ee(),this._typeValidator=e??null}parse(t,n){if(this.state.hasAsyncChecks)throw new l([{code:e.custom,message:`parse() cannot evaluate async checks. Use parseAsync().`,path:[]}]);let r=n??C();return this._withCatch(()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let i=this._parse(n.value,r);if(i instanceof Promise)throw new l([{code:e.custom,message:`parse() received an async schema. Use parseAsync() instead.`,path:[]}]);let a=i,o=a.typeOk?this._runValidatorsSync(a.data,r):[],s=[...a.issues,...o];if(s.length)throw new l(s);return this._runPostprocessors(a.data)})}safeParse(e,t){try{return{data:this.parse(e,t),success:!0}}catch(e){if(e instanceof l)return{error:e,success:!1};throw e}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=await this._parse(t.value,n),i=r.typeOk?await this._runValidatorsAsync(r.data,n):[],a=[...r.issues,...i];if(a.length)throw new l(a);return this._runPostprocessors(r.data)})}async safeParseAsync(e,t){try{return{data:await this.parseAsync(e,t),success:!0}}catch(e){if(e instanceof l)return{error:e,success:!1};throw e}}_parseFullSync(t,n){if(this.state.hasAsyncChecks)throw new l([{code:e.custom,message:`Sync parsing cannot evaluate async checks. Use parseAsync().`,path:[]}]);let r=n??C(),i=this._prepareInput(t);if(i.skip)return{data:i.value,issues:[]};let a=this._parse(i.value,r);if(a instanceof Promise)throw new l([{code:e.custom,message:`Sync parse path received an async schema. Use parseAsync() instead.`,path:[]}]);let o=a,s=o.typeOk?this._runValidatorsSync(o.data,r):[],c=[...o.issues,...s];return c.length>0?this.state.catch?{data:this.state.catch(),issues:[]}:{data:o.data,issues:c}:{data:this._runPostprocessors(o.data),issues:[]}}async _parseFullAsync(e,t){let n=t??C(),r=this._prepareInput(e);if(r.skip)return{data:r.value,issues:[]};let i=await this._parse(r.value,n),a=i.typeOk?await this._runValidatorsAsync(i.data,n):[],o=[...i.issues,...a];return o.length>0?this.state.catch?{data:this.state.catch(),issues:[]}:{data:i.data,issues:o}:{data:this._runPostprocessors(i.data),issues:[]}}check(e){return this._addCheck(e,!1)}checkAsync(e){return this._addCheck(e,!0)}_addCheck(e,t){let n=this._addConstraint((t,n)=>{let r=[],i=e(t,{addIssue:e=>r.push({...e,path:e.path??[]})});return i instanceof Promise?i.then(e=>w(e,r,n)):w(i,r,n)});return n.state.hasRuntimeChecks=!0,t&&(n.state.hasAsyncChecks=!0),n}optional(){let e=this._clone();return e.state.isOptional=!0,e}nullable(){let e=this._clone();return e.state.isNullable=!0,e}nullish(){let e=this._clone();return e.state.isOptional=!0,e.state.isNullable=!0,e}required(){let e=this._clone();return e.state.isOptional=!1,e}default(e){let t=this._clone();return t.state.defaultValue=typeof e==`function`?e:()=>x(e),t}catch(e){let t=this._clone();return t.state.catch=typeof e==`function`?e:()=>x(e),t}transform(e){let t=this._clone();return t.state.postprocessors.push(e),t}preprocess(e){let t=this._clone();return t.state.preprocessors.push(e),t}pipe(e){return new E(this,e)}label(e){let t=this._clone();return t.state.description=e,t}definition(){if(this.state.catch||this.state.defaultValue||this.state.postprocessors.length>0||this.state.preprocessors.length>0||this.state.hasRuntimeChecks)throw new c(`Schemas with checks, transforms, defaults, catches, or preprocessors have no declarative definition.`);return b(this._toDescriptorImpl())}get description(){return this.state.description}get isOptional(){return this.state.isOptional}get isNullable(){return this.state.isNullable}is(e){return this.safeParse(e).success}assert(e,t){let n=this._parseFullSync(e);if(n.issues.length!==0)throw new l(t?n.issues.map(e=>({...e,message:e.path.length===0?`${t}: ${e.message}`:e.message})):n.issues)}walk(e){return this._walk(e)}get kind(){return this._kind}get _kind(){return`any`}_describeBase(){return{...this.state.description===void 0?{}:{description:this.state.description},...this.state.isNullable?{isNullable:!0}:{},...this.state.isOptional?{isOptional:!0}:{}}}_addConstraint(e,t){let n=this._clone();return n.state.validators.push(e),t&&(n._annotations=t({...n._annotations})),n}_construct(e){let t=Object.assign(Object.create(Object.getPrototypeOf(this)),this,{state:e});return t._annotations={...this._annotations},t}_clone(){return this._construct(S(this.state))}_copyStateTo(e){return e.state=S(this.state),e}_walk(e){return e.unknown?e.unknown(this):null}_toDescriptorImpl(){return{...this._describeBase(),kind:`any`}}_withCatch(e){if(!this.state.catch)return e();try{return e()}catch(e){if(e instanceof l)return this.state.catch();throw e}}async _withCatchAsync(e){if(!this.state.catch)return e();try{return await e()}catch(e){if(e instanceof l)return this.state.catch();throw e}}_prepareInput(e){let t=this._runPreprocessors(e),n=t===void 0&&this.state.defaultValue?this.state.defaultValue():t;return this.state.isOptional&&n===void 0||this.state.isNullable&&n===null?{skip:!0,value:n}:{skip:!1,value:n}}_runPreprocessors(e){let t=e;for(let e of this.state.preprocessors)t=e(t);return t}_runPostprocessors(e){let t=e;for(let e of this.state.postprocessors)t=e(t);return t}_runValidatorsSync(t,n){if(this._typeValidator){let r=this._typeValidator(t,n);if(r instanceof Promise)throw new l([{code:e.custom,message:`Type validator returned a Promise. Use parseAsync() for async validation.`,path:[]}]);if(r&&r.length>0)return r}let r=[];for(let i of this.state.validators){let a=i(t,n);if(a instanceof Promise)throw new l([{code:e.custom,message:`Sync parsing received an async check. Use checkAsync() and parseAsync().`,path:[]}]);a&&r.push(...a)}return r}async _runValidatorsAsync(e,t){if(this._typeValidator){let n=await this._typeValidator(e,t);if(n&&n.length>0)return n}let n=[];for(let r of this.state.validators){let i=await r(e,t);i&&n.push(...i)}return n}_parse(e,t){return{data:e,issues:[],typeOk:!0}}},E=class extends T{from;to;get _kind(){return`pipe`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.from=e,this.to=t}_parse(e,t){let n=this.from._parseFullSync(e,t);if(n instanceof Promise)return n.then(n=>n.issues.length>0?{data:e,issues:n.issues,typeOk:!1}:this.to._parseFullAsync(n.data,t).then(e=>e.issues.length>0?{data:n.data,issues:e.issues,typeOk:!1}:{data:e.data,issues:[],typeOk:!0}));if(n.issues.length>0)return{data:e,issues:n.issues,typeOk:!1};let r=this.to._parseFullSync(n.data,t);return r instanceof Promise?r.then(e=>e.issues.length>0?{data:n.data,issues:e.issues,typeOk:!1}:{data:e.data,issues:[],typeOk:!0}):r.issues.length>0?{data:n.data,issues:r.issues,typeOk:!1}:{data:r.data,issues:[],typeOk:!0}}async parseAsync(e,t){let n=t??C(),r=await this.from._parseFullAsync(e,n);if(r.issues.length>0)throw new l(r.issues);let i=await this.to._parseFullAsync(r.data,n);if(i.issues.length>0)throw new l(i.issues);let a=await this._runValidatorsAsync(i.data,n);if(a.length>0)throw new l(a);return this._runPostprocessors(i.data)}_walk(e){let t=this.from.walk(e),n=this.to.walk(e);return e.pipe?e.pipe(this,t,n):super._walk(e)}_toDescriptorImpl(){return{...this._describeBase(),from:this.from.definition(),kind:`pipe`,to:this.to.definition()}}},D=class extends T{itemSchema;get _kind(){return`array`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.itemSchema=e}_parseItemsSync(e,t){let n=[],r=[];for(let a=0;a<e.length;a++){let o=this.itemSchema._parseFullSync(e[a],t);o.issues.length===0?r.push(o.data):(n.push(...i(o.issues,a)),r.push(e[a]))}return{data:r,issues:n}}_parse(t,r){if(!Array.isArray(t))return{data:t,issues:n(e.invalid_type,r.messages.array.type()),typeOk:!1};let{data:i,issues:a}=this._parseItemsSync(t,r);return{data:i,issues:a,typeOk:!0}}async parseAsync(t,r){let a=r??C();return this._withCatchAsync(async()=>{let r=this._prepareInput(t);if(r.skip)return r.value;let o=r.value;if(!Array.isArray(o))throw new l(n(e.invalid_type,a.messages.array.type()));let s=await Promise.all(o.map(e=>this.itemSchema._parseFullAsync(e,a))),c=[],u=[];for(let e=0;e<s.length;e++){let t=s[e];t.issues.length===0?u.push(t.data):(c.push(...i(t.issues,e)),u.push(o[e]))}let d=await this._runValidatorsAsync(u,a),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>a.length>=t?null:n(e.too_small,r(i??o.messages.array.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minItems:n.minItems===void 0?t:Math.max(n.minItems,t)}})}max(t,i){return this._addConstraint((a,o)=>a.length<=t?null:n(e.too_big,r(i??o.messages.array.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maxItems:n.maxItems===void 0?t:Math.min(n.maxItems,t)}})}length(t,i){return this._addConstraint((a,o)=>a.length===t?null:n(e.invalid_length,r(i??o.messages.array.length,{exact:t,value:a}),{exact:t}),e=>({...e,maxItems:t,minItems:t}))}nonEmpty(t){return this._addConstraint((i,a)=>{let o=i;return o.length>0?null:n(e.too_small,r(t??a.messages.array.nonEmpty,{min:1,value:o}),{min:1})})}unique(t,i){let a=typeof t==`function`&&t.length===2,o=a?t:null,s=a?i:typeof t==`function`?t:void 0;return this._addConstraint((t,i)=>{let a=t,c;return c=o?a.every((e,t)=>a.slice(0,t).every(t=>!o(e,t))):new Set(a).size===a.length,c?null:n(e.invalid_unique,r(s??i.messages.array.unique,{value:a}),{unique:!0})})}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.maxItems===void 0?{}:{maxItems:e.maxItems},...e.minItems===void 0?{}:{minItems:e.minItems},items:this.itemSchema.definition(),kind:`array`}}_walk(e){let t=this.itemSchema.walk(e);return e.array?e.array(this,t):super._walk(e)}},O=class t extends T{get _kind(){return`bigint`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`bigint`?null:n(e.invalid_type,r.messages.bigint.type()))}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s>=t?null:n(e.too_small,r(i??o.messages.bigint.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s<=t?null:n(e.too_big,r(i??o.messages.bigint.max,{max:t,value:s}),{max:t})})}positive(t){return this._addConstraint((i,a)=>{let o=i;return o>0n?null:n(e.too_small,r(t??a.messages.bigint.positive,{value:o}),{exclusive:!0,min:0n})})}negative(t){return this._addConstraint((i,a)=>{let o=i;return o<0n?null:n(e.too_big,r(t??a.messages.bigint.negative,{value:o}),{exclusive:!0,max:0n})})}nonNegative(t){return this._addConstraint((i,a)=>{let o=i;return o>=0n?null:n(e.too_small,r(t??a.messages.bigint.nonNegative,{value:o}),{min:0n})})}nonPositive(t){return this._addConstraint((i,a)=>{let o=i;return o<=0n?null:n(e.too_big,r(t??a.messages.bigint.nonPositive,{value:o}),{max:0n})})}multipleOf(t,i){return this._addConstraint((a,o)=>{let s=a;return s%t===0n?null:n(e.invalid_multiple_of,r(i??o.messages.bigint.multipleOf,{step:t,value:s}),{step:t})})}_walk(e){return e.bigint?e.bigint(this):super._walk(e)}coerce(){return t.coerce()}_toDescriptorImpl(){return this.state.validators.length,{...this._describeBase(),kind:`bigint`}}static coerce(){return new t().preprocess(e=>{if(typeof e==`bigint`)return e;if(typeof e==`number`){if(!Number.isFinite(e)||!Number.isInteger(e))return e;try{return BigInt(e)}catch{return e}}if(typeof e==`string`){let t=e.trim();if(t.length===0||t.length>1e3)return e;try{return BigInt(t)}catch{return e}}return e})}},k=class t extends T{get _kind(){return`boolean`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,n)=>typeof t==`boolean`?null:[{code:e.invalid_type,message:n.messages.boolean.type(),path:[]}])}coerce(){return t.coerce()}_toDescriptorImpl(){return{...this._describeBase(),kind:`boolean`}}_walk(e){return e.boolean?e.boolean(this):super._walk(e)}static coerce(){return new t().preprocess(e=>typeof e==`boolean`?e:e===`true`||e===`1`||e===1?!0:e===`false`||e===`0`||e===0?!1:e)}},A=class t extends T{get _kind(){return`date`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>t instanceof Date&&!Number.isNaN(t.getTime())?null:n(e.invalid_date,r.messages.date.type()))}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s>=t?null:n(e.too_small,r(i??o.messages.date.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s<=t?null:n(e.too_big,r(i??o.messages.date.max,{max:t,value:s}),{max:t})})}coerce(){return t.coerce()}_toDescriptorImpl(){return{...this._describeBase(),kind:`date`}}_walk(e){return e.date?e.date(this):super._walk(e)}static coerce(){return new t().preprocess(e=>e instanceof Date?e:typeof e==`string`||typeof e==`number`?new Date(e):e)}};function j(t){let n=new Set(t);return(r,i)=>n.has(r)?null:[{code:e.invalid_enum,message:i.messages.enum.invalid({values:t}),params:{values:t},path:[]}]}var M=class extends T{values;get _kind(){return`enum`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(j(e)),this.values=e}_toDescriptorImpl(){return{...this._describeBase(),kind:`enum`,values:this.values}}_walk(e){return e.enum?e.enum(this):super._walk(e)}},te=class extends T{cls;get _kind(){return`instanceof`}checkAsync(e){return this._addCheck(e,!0)}constructor(t){super((n,r)=>n instanceof t?null:[{code:e.invalid_type,message:r.messages.instanceof.type({className:t.name}),path:[]}]),this.cls=t}_toDescriptorImpl(){return{...this._describeBase(),className:this.cls.name,kind:`instanceof`}}_walk(e){return e.instanceof?e.instanceof(this):super._walk(e)}};function N(e,t){if(y(e)&&y(t)){let n=m(e);for(let[r,i]of Object.entries(t))f(n,r,N(e[r],i));return n}return t}var P=class extends T{schemas;get _kind(){return`intersect`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.schemas=Object.freeze([...e])}_parse(e,t){let n={hasOutput:!1,issues:[],output:e};for(let r=0;r<this.schemas.length;r++){let i=this.schemas[r]._parseFullSync(e,t);i.issues.length>0?n.issues.push(...i.issues):n.hasOutput?n.output=N(n.output,i.data):(n.hasOutput=!0,n.output=i.data)}return{data:n.output,issues:n.issues,typeOk:n.issues.length===0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r={hasOutput:!1,issues:[],output:t.value};for(let e=0;e<this.schemas.length;e++){let i=await this.schemas[e]._parseFullAsync(t.value,n);i.issues.length>0?r.issues.push(...i.issues):r.hasOutput?r.output=N(r.output,i.data):(r.hasOutput=!0,r.output=i.data)}if(r.issues.length>0)throw new l(r.issues);let i=await this._runValidatorsAsync(r.output,n);if(i.length)throw new l(i);return this._runPostprocessors(r.output)})}_toDescriptorImpl(){return{...this._describeBase(),branches:this.schemas.map(e=>e.definition()),kind:`intersect`}}_walk(e){let t=this.schemas.map(t=>t.walk(e));return e.intersect?e.intersect(this,t):super._walk(e)}},F=class e extends T{_getter;_resolved;get _kind(){return`lazy`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this._getter=e}_resolve(){return this._resolved??=this._getter()}_parse(e,t){let n=this._resolve()._parseFullSync(e,t);return n.issues.length===0?{data:n.data,issues:[],typeOk:!0}:{data:e,issues:n.issues,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=await this._resolve()._parseFullAsync(t.value,n);if(r.issues.length>0)throw new l(r.issues);let i=await this._runValidatorsAsync(r.data,n);if(i.length>0)throw new l(i);return this._runPostprocessors(r.data)})}_toDescriptorImpl(){return{...this._describeBase(),kind:`lazy`}}_walk(e){return e.lazy?e.lazy(this):super._walk(e)}_construct(t){let n=new e(this._getter);return n.state=t,n}},I=class extends T{value;get _kind(){return`literal`}checkAsync(e){return this._addCheck(e,!0)}constructor(t){super((n,r)=>n===t?null:[{code:e.invalid_literal,message:r.messages.literal.expected({expected:t}),params:{expected:t},path:[]}]),this.value=t}_toDescriptorImpl(){return{...this._describeBase(),kind:`literal`,value:this.value}}_walk(e){return e.literal?e.literal(this):super._walk(e)}},L=class extends T{keySchema;valueSchema;get _kind(){return`map`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.keySchema=e,this.valueSchema=t}_parse(t,n){if(!(t instanceof Map))return{data:t,issues:[{code:e.invalid_type,message:n.messages.map.type(),path:[]}],typeOk:!1};let r=new Map,a=[],o=0;for(let[e,s]of t){let t=this.keySchema._parseFullSync(e,n),c=this.valueSchema._parseFullSync(s,n);t.issues.length>0&&a.push(...i(t.issues,o)),c.issues.length>0&&a.push(...i(c.issues,o)),t.issues.length===0&&c.issues.length===0&&r.set(t.data,c.data),o+=1}return{data:r,issues:a,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!(a instanceof Map))throw new l([{code:e.invalid_type,message:r.messages.map.type(),path:[]}]);let o=[...a],s=await Promise.all(o.map(([e,t])=>Promise.all([this.keySchema._parseFullAsync(e,r),this.valueSchema._parseFullAsync(t,r)]))),c=[],u=new Map;for(let e=0;e<s.length;e++){let[t,n]=s[e];t.issues.length>0&&c.push(...i(t.issues,e)),n.issues.length>0&&c.push(...i(n.issues,e)),t.issues.length===0&&n.issues.length===0&&u.set(t.data,n.data)}let d=await this._runValidatorsAsync(u,r),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size>=t?null:n(e.too_small,r(i??o.messages.map.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size<=t?null:n(e.too_big,r(i??o.messages.map.max,{max:t,value:s}),{max:t})})}size(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size===t?null:n(e.invalid_length,r(i??o.messages.map.size,{exact:t,value:s}),{exact:t})})}nonEmpty(t){return this._addConstraint((i,a)=>i.size>0?null:n(e.too_small,r(t??a.messages.map.nonEmpty,{min:1}),{min:1}))}_toDescriptorImpl(){return{...this._describeBase(),key:this.keySchema.definition(),kind:`map`,value:this.valueSchema.definition()}}_walk(e){let t=this.keySchema.walk(e),n=this.valueSchema.walk(e);return e.map?e.map(this,t,n):super._walk(e)}},R=class extends T{get _kind(){return`never`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,n)=>[{code:e.invalid_type,message:n.messages.never.invalid(),path:[]}])}_toDescriptorImpl(){return{...this._describeBase(),kind:`never`}}_walk(e){return e.never?e.never(this):super._walk(e)}},z=class t extends T{get _kind(){return`number`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`number`&&!Number.isNaN(t)?null:n(e.invalid_type,r.messages.number.type()))}min(t,i){return this._addConstraint((a,o)=>a>=t?null:n(e.too_small,r(i??o.messages.number.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minimum:n.minimum===void 0?t:Math.max(n.minimum,t)}})}max(t,i){return this._addConstraint((a,o)=>a<=t?null:n(e.too_big,r(i??o.messages.number.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maximum:n.maximum===void 0?t:Math.min(n.maximum,t)}})}int(t){return this._addConstraint((i,a)=>Number.isInteger(i)?null:n(e.invalid_integer,r(t??a.messages.number.int,{value:i})),e=>({...e,typeHint:`integer`}))}positive(t){return this._addConstraint((i,a)=>i>0?null:n(e.too_small,r(t??a.messages.number.positive,{value:i}),{exclusive:!0,min:0}),e=>{let t=e;return{...t,exclusiveMinimum:t.exclusiveMinimum===void 0?0:Math.max(t.exclusiveMinimum,0)}})}negative(t){return this._addConstraint((i,a)=>i<0?null:n(e.too_big,r(t??a.messages.number.negative,{value:i}),{exclusive:!0,max:0}),e=>{let t=e;return{...t,exclusiveMaximum:t.exclusiveMaximum===void 0?0:Math.min(t.exclusiveMaximum,0)}})}nonNegative(t){return this._addConstraint((i,a)=>i>=0?null:n(e.too_small,r(t??a.messages.number.nonNegative,{value:i}),{min:0}),e=>{let t=e;return{...t,minimum:t.minimum===void 0?0:Math.max(t.minimum,0)}})}nonPositive(t){return this._addConstraint((i,a)=>i<=0?null:n(e.too_big,r(t??a.messages.number.nonPositive,{value:i}),{max:0}),e=>{let t=e;return{...t,maximum:t.maximum===void 0?0:Math.min(t.maximum,0)}})}multipleOf(t,i){return this._addConstraint((a,o)=>Math.abs(Math.round(a/t)-a/t)<1e-9?null:n(e.invalid_multiple_of,r(i??o.messages.number.multipleOf,{step:t,value:a}),{step:t}),e=>({...e,multipleOf:t}))}safe(t){return this._addConstraint((i,a)=>Number.isSafeInteger(i)?null:n(e.invalid_safe,r(t??a.messages.number.safe,{value:i})))}finite(t){return this._addConstraint((i,a)=>Number.isFinite(i)?null:n(e.invalid_finite,r(t??a.messages.number.finite,{value:i})))}coerce(){return t.coerce()}_walk(e){return e.number?e.number(this):super._walk(e)}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.exclusiveMaximum===void 0?{}:{exclusiveMaximum:e.exclusiveMaximum},...e.exclusiveMinimum===void 0?{}:{exclusiveMinimum:e.exclusiveMinimum},...e.maximum===void 0?{}:{maximum:e.maximum},...e.minimum===void 0?{}:{minimum:e.minimum},...e.multipleOf===void 0?{}:{multipleOf:e.multipleOf},...e.typeHint===void 0?{}:{typeHint:e.typeHint},kind:`number`}}static coerce(){return new t().preprocess(e=>{if(typeof e==`number`)return e;if(typeof e==`string`||typeof e==`boolean`){let t=Number(e);return Number.isNaN(t)?e:t}return e})}},B=class extends T{schemas;get _kind(){return`union`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.schemas=Object.freeze([...e])}_parse(t,n){let r=[];for(let e of this.schemas){let i=e._parseFullSync(t,n);if(i.issues.length===0)return{data:i.data,issues:[],typeOk:!0};r.push(i.issues)}return{data:t,issues:[{code:e.invalid_union,message:n.messages.union.invalid(),params:{errors:r},path:[]}],typeOk:!1}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let i=n.value,a=[];for(let e of this.schemas){let t=await e._parseFullAsync(i,r);if(t.issues.length>0){a.push(t.issues);continue}let n=await this._runValidatorsAsync(t.data,r);if(n.length>0)throw new l(n);return this._runPostprocessors(t.data)}throw new l([{code:e.invalid_union,message:r.messages.union.invalid(),params:{errors:a},path:[]}])})}_toDescriptorImpl(){return{...this._describeBase(),branches:this.schemas.map(e=>e.definition()),kind:`union`}}_walk(e){let t=this.schemas.map(t=>t.walk(e));return e.union?e.union(this,t):super._walk(e)}},V=class t extends T{shape;_isRelaxed;get _kind(){return`object`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t=!1){super(),this.shape=Object.freeze(p(Object.entries(e))),this._isRelaxed=t}_unknownKeys(e){return Object.keys(e).filter(e=>!Object.hasOwn(this.shape,e))}_strictUnknownKeyIssues(t,n){if(this._isRelaxed)return[];let r=this._unknownKeys(t);return r.length===0?[]:[{code:e.invalid_keys,message:n.messages.object.invalidKeys({keys:r}),params:{keys:r},path:[]}]}_copyRelaxedUnknownKeys(e,t){if(this._isRelaxed)for(let n of this._unknownKeys(e))d(n)||Object.defineProperty(t,n,{configurable:!0,enumerable:!0,value:e[n],writable:!0})}_guardObjectInput(t,n){return typeof t!=`object`||!t||Array.isArray(t)?{issues:[{code:e.invalid_type,message:n.messages.object.type(),path:[]}],ok:!1}:{obj:t,ok:!0}}_createObjectParseContext(e,t){return{issues:[...this._strictUnknownKeyIssues(e,t)],output:{}}}_rebuildWith(e,n=this._isRelaxed){return this._copyStateTo(new t(e,n))}_parse(e,t){let n=this._guardObjectInput(e,t);if(!n.ok)return{data:e,issues:n.issues,typeOk:!1};let{obj:r}=n,{issues:a,output:o}=this._createObjectParseContext(r,t);for(let e of Object.keys(this.shape)){let n=this.shape[e]._parseFullSync(r[e],t);n.issues.length===0?f(o,e,n.data):a.push(...i(n.issues,e))}return this._copyRelaxedUnknownKeys(r,o),{data:o,issues:a,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._guardObjectInput(t.value,n);if(!r.ok)throw new l(r.issues);let{obj:a}=r,{issues:o,output:s}=this._createObjectParseContext(a,n),c=Object.keys(this.shape),u=await Promise.all(c.map(e=>this.shape[e]._parseFullAsync(a[e],n)));for(let e=0;e<c.length;e++){let t=c[e],n=u[e];n.issues.length===0?f(s,t,n.data):o.push(...i(n.issues,t))}this._copyRelaxedUnknownKeys(a,s);let d=await this._runValidatorsAsync(s,n),p=[...o,...d];if(p.length>0)throw new l(p);return this._runPostprocessors(s)})}partial(...e){let t=e.length>0?new Set(e):null;return this._rebuildWith(p(Object.entries(this.shape).map(([e,n])=>[e,t===null||t.has(e)?n.optional():n])),this._isRelaxed)}optional(){return super.optional()}nullable(){return super.nullable()}nullish(){return super.nullish()}required(){return this._rebuildWith(p(Object.entries(this.shape).map(([e,t])=>[e,t.required()])),this._isRelaxed)}extend(e){return this._rebuildWith(p([...Object.entries(this.shape),...Object.entries(e)]),this._isRelaxed)}pick(...e){let t=new Set(e);return this._rebuildWith(p(Object.entries(this.shape).filter(([e])=>t.has(e))))}omit(...e){let t=new Set(e);return this._rebuildWith(p(Object.entries(this.shape).filter(([e])=>!t.has(e))))}defaults(){return this.parse({})}partialDefaults(){let e={};for(let t of Object.keys(this.shape)){let n=this.shape[t]._parseFullSync(void 0);n.issues.length===0&&f(e,t,n.data)}return e}requiredFields(){return Object.keys(this.shape).filter(e=>!this.shape[e].isOptional)}optionalFields(){return Object.keys(this.shape).filter(e=>this.shape[e].isOptional)}relaxed(){return this._rebuildWith(this.shape,!0)}strict(){return this._rebuildWith(this.shape,!1)}keyof(){return new B(Object.keys(this.shape).map(e=>new I(e)))}_toDescriptorImpl(){let e={};for(let[t,n]of Object.entries(this.shape))f(e,t,n.definition());return{...this._describeBase(),fields:e,kind:`object`,strict:!this._isRelaxed}}_walk(e){let t=p(Object.entries(this.shape).map(([t,n])=>[t,n.walk(e)]));return e.object?e.object(this,t):super._walk(e)}merge(e){return this._rebuildWith(p([...Object.entries(this.shape),...Object.entries(e.shape)]),e._isRelaxed)}};function H(e){return e.map(e=>e instanceof T?e:new I(e))}var U=class extends T{keySchema;valueSchema;get _kind(){return`record`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){super(),this.keySchema=e,this.valueSchema=t}_guardRecordInput(t,n){return typeof t!=`object`||!t||Array.isArray(t)?{issues:[{code:e.invalid_type,message:n.messages.object.type(),path:[]}],ok:!1}:{ok:!0,value:t}}_parseRecordEntries(e,t){let n=[],r={};for(let a of Object.keys(e)){let o=this.keySchema._parseFullSync(a,t);if(o.issues.length>0){n.push(...i(o.issues,a));continue}let s=o.data;if(d(s))continue;let c=this.valueSchema._parseFullSync(e[a],t);c.issues.length===0?Object.defineProperty(r,s,{configurable:!0,enumerable:!0,value:c.data,writable:!0}):n.push(...i(c.issues,a))}return{issues:n,output:r}}_parse(e,t){let n=this._guardRecordInput(e,t);if(!n.ok)return{data:e,issues:n.issues,typeOk:!1};let{issues:r,output:i}=this._parseRecordEntries(n.value,t);return{data:i,issues:r,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._guardRecordInput(t.value,n);if(!r.ok)throw new l(r.issues);let a=r.value,o=Object.keys(a),s=await Promise.all(o.map(e=>Promise.all([this.keySchema._parseFullAsync(e,n),this.valueSchema._parseFullAsync(a[e],n)]))),c=[],u={};for(let e=0;e<o.length;e++){let t=o[e],[n,r]=s[e];if(n.issues.length>0){c.push(...i(n.issues,t));continue}let a=n.data;d(a)||(r.issues.length===0?Object.defineProperty(u,a,{configurable:!0,enumerable:!0,value:r.data,writable:!0}):c.push(...i(r.issues,t)))}let f=await this._runValidatorsAsync(u,n),p=[...c,...f];if(p.length>0)throw new l(p);return this._runPostprocessors(u)})}_toDescriptorImpl(){return{...this._describeBase(),key:this.keySchema.definition(),kind:`record`,value:this.valueSchema.definition()}}_walk(e){let t=this.keySchema.walk(e),n=this.valueSchema.walk(e);return e.record?e.record(this,t,n):super._walk(e)}},W=class extends T{itemSchema;get _kind(){return`set`}checkAsync(e){return this._addCheck(e,!0)}constructor(e){super(),this.itemSchema=e}_parse(t,n){if(!(t instanceof Set))return{data:t,issues:[{code:e.invalid_type,message:n.messages.set.type(),path:[]}],typeOk:!1};let r=[],a=new Set,o=0;for(let e of t){let t=this.itemSchema._parseFullSync(e,n);t.issues.length===0?a.add(t.data):r.push(...i(t.issues,o)),o+=1}return{data:a,issues:r,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!(a instanceof Set))throw new l([{code:e.invalid_type,message:r.messages.set.type(),path:[]}]);let o=[...a],s=await Promise.all(o.map(e=>this.itemSchema._parseFullAsync(e,r))),c=[],u=new Set;for(let e=0;e<s.length;e++){let t=s[e];t.issues.length===0?u.add(t.data):c.push(...i(t.issues,e))}let d=await this._runValidatorsAsync(u,r),f=[...c,...d];if(f.length>0)throw new l(f);return this._runPostprocessors(u)})}min(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size>=t?null:n(e.too_small,r(i??o.messages.set.min,{min:t,value:s}),{min:t})})}max(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size<=t?null:n(e.too_big,r(i??o.messages.set.max,{max:t,value:s}),{max:t})})}size(t,i){return this._addConstraint((a,o)=>{let s=a;return s.size===t?null:n(e.invalid_length,r(i??o.messages.set.size,{exact:t,value:s}),{exact:t})})}nonEmpty(t){return this._addConstraint((i,a)=>i.size>0?null:n(e.too_small,r(t??a.messages.set.nonEmpty,{min:1}),{min:1}))}_toDescriptorImpl(){return{...this._describeBase(),items:this.itemSchema.definition(),kind:`set`}}_walk(e){let t=this.itemSchema.walk(e);return e.set?e.set(this,t):super._walk(e)}};function G(e){return/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(e)}var K=new Set([`http`,`https`]);function q(e,t){try{let n=new URL(e);return(t?new Set(t.map(e=>e.toLowerCase())):K).has(n.protocol.replace(`:`,``).toLowerCase())}catch{return!1}}function J(e){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}function Y(e){if(!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;let t=new Date(e);return!Number.isNaN(t.getTime())&&t.toISOString().startsWith(e)}function ne(e){return/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})?$/.test(e)&&!Number.isNaN(new Date(e).getTime())}function X(e){if(/^(\d{1,3}\.){3}\d{1,3}$/.test(e))return e.split(`.`).every(e=>{let t=parseInt(e,10);return t>=0&&t<=255});try{return new URL(`http://[${e}]/`),!0}catch{return!1}}function Z(e){return/^c[a-z0-9]{8,}$/.test(e)}function re(e){return/^[a-z][a-z0-9]{23}$/.test(e)}function ie(e){return/^[0-7][0-9A-HJKMNP-TV-Z]{25}$/.test(e)}function ae(e,t=21){return e.length===t&&/^[A-Za-z0-9_-]+$/.test(e)}function oe(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$/.test(e)}function se(e){return e.length===0||e.length%4==1?!1:/^[A-Za-z0-9_-]*={0,2}$/.test(e)}function ce(e){return/^[A-Fa-f0-9]+$/.test(e)}function le(e){return/^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/.test(e)}function ue(e){return/^\p{Extended_Pictographic}+$/u.test(e)}function de(e){return/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(e)}function fe(e){return/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/.test(e)}function pe(e){return/^P(?=\d|T\d)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+(?:\.\d+)?S)?)?$/.test(e)}function me(e){return/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/.test(e)}function Q(e){return/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(e)}function he(e){return/^[-+]?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?$/i.test(e)}var $=class t extends T{get _kind(){return`string`}checkAsync(e){return this._addCheck(e,!0)}constructor(){super((t,r)=>typeof t==`string`?null:n(e.invalid_type,r.messages.string.type()))}min(t,i){return this._addConstraint((a,o)=>a.length>=t?null:n(e.too_small,r(i??o.messages.string.min,{min:t,value:a}),{min:t}),e=>{let n=e;return{...n,minLength:n.minLength===void 0?t:Math.max(n.minLength,t)}})}max(t,i){return this._addConstraint((a,o)=>a.length<=t?null:n(e.too_big,r(i??o.messages.string.max,{max:t,value:a}),{max:t}),e=>{let n=e;return{...n,maxLength:n.maxLength===void 0?t:Math.min(n.maxLength,t)}})}length(t,i){return this._addConstraint((a,o)=>a.length===t?null:n(e.invalid_length,r(i??o.messages.string.length,{exact:t,value:a}),{exact:t}),e=>({...e,maxLength:t,minLength:t}))}nonempty(e){return this.nonEmpty(e)}nonEmpty(t){return this._addConstraint((i,a)=>i.length>0?null:n(e.too_small,r(t??a.messages.string.nonEmpty,{min:1,value:i}),{min:1}),e=>{let t=e;return{...t,minLength:Math.max(t.minLength??0,1)}})}startsWith(t,i){return this._addConstraint((a,o)=>a.startsWith(t)?null:n(e.invalid_string,r(i??o.messages.string.startsWith,{prefix:t,value:a}),{prefix:t}))}endsWith(t,i){return this._addConstraint((a,o)=>a.endsWith(t)?null:n(e.invalid_string,r(i??o.messages.string.endsWith,{suffix:t,value:a}),{suffix:t}))}includes(t,i){return this._addConstraint((a,o)=>a.includes(t)?null:n(e.invalid_string,r(i??o.messages.string.includes,{substr:t,value:a}),{includes:t}))}regex(t,i){let a=new RegExp(t.source,t.flags.replace(/[gy]/g,``));return this._addConstraint((t,o)=>a.test(t)?null:n(e.invalid_string,r(i??o.messages.string.regex,{value:t}),{pattern:a.source}),e=>{let t=e;return t.pattern===null?t:t.pattern===void 0?{...t,pattern:a.source}:t.pattern===a.source?t:{...t,pattern:null}})}email(t){return this._addConstraint((i,a)=>G(i)?null:n(e.invalid_string,r(t??a.messages.string.email,{value:i}),{format:`email`}),e=>({...e,format:`email`}))}url(t={}){let{message:i,protocols:a=[`http`,`https`]}=t;return this._addConstraint((t,o)=>q(t,a)?null:n(e.invalid_url,r(i??o.messages.string.url,{value:t}),{format:`url`}),e=>({...e,format:`uri`}))}uuid(t){return this._addConstraint((i,a)=>J(i)?null:n(e.invalid_string,r(t??a.messages.string.uuid,{value:i}),{format:`uuid`}),e=>({...e,format:`uuid`}))}isoDate(t){return this._addConstraint((i,a)=>Y(i)?null:n(e.invalid_string,r(t??a.messages.string.date,{value:i}),{format:`iso-date`}),e=>({...e,format:`date`}))}isoDateTime(t){return this._addConstraint((i,a)=>ne(i)?null:n(e.invalid_string,r(t??a.messages.string.dateTime,{value:i}),{format:`iso-datetime`}),e=>({...e,format:`date-time`}))}ip(t){return this._addConstraint((i,a)=>X(i)?null:n(e.invalid_string,r(t??a.messages.string.ip,{value:i}),{format:`ip`}))}cuid(t){return this._addConstraint((i,a)=>Z(i)?null:n(e.invalid_string,r(t??a.messages.string.cuid,{value:i}),{format:`cuid`}))}cuid2(t){return this._addConstraint((i,a)=>re(i)?null:n(e.invalid_string,r(t??a.messages.string.cuid2,{value:i}),{format:`cuid2`}))}ulid(t){return this._addConstraint((i,a)=>ie(i)?null:n(e.invalid_string,r(t??a.messages.string.ulid,{value:i}),{format:`ulid`}))}nanoid(t,i){return this._addConstraint((a,o)=>ae(a,t)?null:n(e.invalid_string,r(i??o.messages.string.nanoid,{value:a}),{format:`nanoid`}))}base64(t){return this._addConstraint((i,a)=>oe(i)?null:n(e.invalid_base64,r(t??a.messages.string.base64,{value:i}),{format:`base64`}),e=>({...e,contentEncoding:`base64`}))}base64url(t){return this._addConstraint((i,a)=>se(i)?null:n(e.invalid_base64,r(t??a.messages.string.base64url,{value:i}),{format:`base64url`}))}hex(t){return this._addConstraint((i,a)=>ce(i)?null:n(e.invalid_string,r(t??a.messages.string.hex,{value:i}),{format:`hex`}))}hexColor(t){return this._addConstraint((i,a)=>le(i)?null:n(e.invalid_string,r(t??a.messages.string.hexColor,{value:i}),{format:`hex-color`}))}emoji(t){return this._addConstraint((i,a)=>ue(i)?null:n(e.invalid_string,r(t??a.messages.string.emoji,{value:i}),{format:`emoji`}))}jwt(t){return this._addConstraint((i,a)=>de(i)?null:n(e.invalid_string,r(t??a.messages.string.jwt,{value:i}),{format:`jwt`}))}time(t){return this._addConstraint((i,a)=>fe(i)?null:n(e.invalid_string,r(t??a.messages.string.time,{value:i}),{format:`time`}))}duration(t){return this._addConstraint((i,a)=>pe(i)?null:n(e.invalid_duration,r(t??a.messages.string.duration,{value:i}),{format:`duration`}),e=>({...e,format:`duration`}))}semver(t){return this._addConstraint((i,a)=>me(i)?null:n(e.invalid_string,r(t??a.messages.string.semver,{value:i}),{format:`semver`}))}slug(t){return this._addConstraint((i,a)=>Q(i)?null:n(e.invalid_string,r(t??a.messages.string.slug,{value:i}),{format:`slug`}))}numeric(t){return this._addConstraint((i,a)=>he(i)?null:n(e.invalid_string,r(t??a.messages.string.numeric,{value:i}),{format:`numeric`}))}coerce(){return t.coerce()}trim(){return this.preprocess(e=>typeof e==`string`?e.trim():e)}lowercase(){return this.preprocess(e=>typeof e==`string`?e.toLowerCase():e)}uppercase(){return this.preprocess(e=>typeof e==`string`?e.toUpperCase():e)}_walk(e){return e.string?e.string(this):super._walk(e)}_toDescriptorImpl(){let e=this._annotations;return{...this._describeBase(),...e.contentEncoding===void 0?{}:{contentEncoding:e.contentEncoding},...e.format===void 0?{}:{format:e.format},...e.maxLength===void 0?{}:{maxLength:e.maxLength},...e.minLength===void 0?{}:{minLength:e.minLength},...e.pattern===void 0?{}:{pattern:e.pattern},kind:`string`}}static coerce(){return new t().preprocess(e=>e==null?e:String(e))}},ge=class t extends T{items;restSchema;get _kind(){return`tuple`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t=null){super(),this.items=e,this.restSchema=t}rest(e){return this._copyStateTo(new t(this.items,e))}_guardTupleInput(t,n){return this.restSchema===null&&t.length!==this.items.length?{issues:[{code:e.invalid_length,message:n.messages.tuple.length({exact:this.items.length}),params:{exact:this.items.length},path:[]}],ok:!1}:this.restSchema!==null&&t.length<this.items.length?{issues:[{code:e.too_small,message:n.messages.tuple.min({min:this.items.length}),params:{min:this.items.length},path:[]}],ok:!1}:{ok:!0,value:t}}_parse(t,n){if(!Array.isArray(t))return{data:t,issues:[{code:e.invalid_type,message:n.messages.tuple.type(),path:[]}],typeOk:!1};let r=this._guardTupleInput(t,n);if(!r.ok)return{data:t,issues:r.issues,typeOk:!1};let a=[],o=[],s=r.value;for(let e=0;e<this.items.length;e++){let t=this.items[e]._parseFullSync(s[e],n);t.issues.length===0?o.push(t.data):(a.push(...i(t.issues,e)),o.push(s[e]))}if(this.restSchema!==null)for(let e=this.items.length;e<s.length;e++){let t=this.restSchema._parseFullSync(s[e],n);t.issues.length===0?o.push(t.data):(a.push(...i(t.issues,e)),o.push(s[e]))}return{data:o,issues:a,typeOk:!0}}async parseAsync(t,n){let r=n??C();return this._withCatchAsync(async()=>{let n=this._prepareInput(t);if(n.skip)return n.value;let a=n.value;if(!Array.isArray(a))throw new l([{code:e.invalid_type,message:r.messages.tuple.type(),path:[]}]);let o=this._guardTupleInput(a,r);if(!o.ok)throw new l(o.issues);let s=o.value,c=[],u=[],d=await Promise.all(this.items.map((e,t)=>e._parseFullAsync(s[t],r)));for(let e=0;e<d.length;e++){let t=d[e];t.issues.length===0?u.push(t.data):(c.push(...i(t.issues,e)),u.push(s[e]))}let f=this.restSchema;if(f!==null){let e=s.slice(this.items.length),t=await Promise.all(e.map(e=>f._parseFullAsync(e,r)));for(let e=0;e<t.length;e++){let n=t[e],r=this.items.length+e;n.issues.length===0?u.push(n.data):(c.push(...i(n.issues,r)),u.push(s[r]))}}let p=await this._runValidatorsAsync(u,r),m=[...c,...p];if(m.length>0)throw new l(m);return this._runPostprocessors(u)})}_toDescriptorImpl(){return{...this._describeBase(),items:this.items.map(e=>e.definition()),kind:`tuple`,rest:this.restSchema===null?null:this.restSchema.definition()}}_walk(e){let t=this.items.map(t=>t.walk(e)),n=this.restSchema===null?null:this.restSchema.walk(e);return e.tuple?e.tuple(this,t,n):super._walk(e)}},_e=class extends T{_map;_discriminator;get _kind(){return`variant`}checkAsync(e){return this._addCheck(e,!0)}constructor(e,t){let n=new Map;for(let[r,i]of Object.entries(t)){let t=new I(r),o=i.shape[e];if(o&&(!(o instanceof I)||o.value!==r))throw new a(`s.discriminatedUnion(): branch "${r}" defines a conflicting discriminator schema for "${e}".`);let s={[e]:t};n.set(r,o?i:i.extend(s))}super(),this._discriminator=e,this._map=n}get discriminator(){return this._discriminator}get variantMap(){return new Map(this._map)}_resolveVariant(t,n){if(typeof t!=`object`||!t||Array.isArray(t))return{issues:[{code:e.invalid_type,message:n.messages.variant.type(),path:[]}]};let r=t,i=r[this._discriminator],a=this._map.get(i);if(!a){let t=[...this._map.keys()];return{issues:[{code:e.invalid_variant,message:n.messages.variant.invalidDiscriminator({discriminator:this._discriminator,expected:t}),params:{discriminator:this._discriminator,expected:t},path:[]}]}}return{matched:a,obj:r}}_parse(e,t){let n=this._resolveVariant(e,t);if(`issues`in n)return{data:e,issues:n.issues,typeOk:!1};let r=n.matched._parseFullSync(e,t);return r.issues.length===0?{data:r.data,issues:[],typeOk:!0}:{data:e,issues:r.issues,typeOk:!0}}async parseAsync(e,t){let n=t??C();return this._withCatchAsync(async()=>{let t=this._prepareInput(e);if(t.skip)return t.value;let r=this._resolveVariant(t.value,n);if(`issues`in r)throw new l(r.issues);let i=await r.matched.safeParseAsync(t.value,n);if(!i.success)throw i.error;let a=await this._runValidatorsAsync(i.data,n);if(a.length>0)throw new l(a);return this._runPostprocessors(i.data)})}_toDescriptorImpl(){let e={};for(let[t,n]of this._map.entries())f(e,t,n.definition());return{...this._describeBase(),branches:e,discriminator:this._discriminator,kind:`variant`}}_walk(e){let t=p([...this._map.entries()].map(([t,n])=>[t,n.walk(e)]));return e.variant?e.variant(this,t):super._walk(e)}},ve={any:()=>new T,array:e=>new D(e),bigint:()=>new O,boolean:()=>new k,coerce:{bigint:()=>O.coerce(),boolean:()=>k.coerce(),date:()=>A.coerce(),number:()=>z.coerce(),string:()=>$.coerce()},date:()=>new A,discriminatedUnion:(e,t)=>new _e(e,t),enum:e=>new M(e),instanceof:e=>new te(e),intersect:(...e)=>new P(H(e)),lazy:e=>new F(e),literal:e=>new I(e),map:(e,t)=>new L(e,t),never:()=>new R,null:()=>new I(null),number:()=>new z,object:e=>new V(e),record:(e,t)=>new U(e,t),set:e=>new W(e),string:()=>new $,tuple:e=>new ge(e),undefined:()=>new I(void 0),union:(...e)=>new B(H(e)),unknown:()=>new T},ye={createParseContext:v,fail:n,prependIssuePath:i};exports.ErrorCode=e,exports.PipeSchema=E,exports.Schema=T,exports.SpellDefinitionError=c,exports.SpellError=a,exports.SpellValidationError=l,exports.diagnostics=ye,exports.s=ve,exports.schemaMode=t;
|
|
3
3
|
//# sourceMappingURL=spell.cjs.map
|