From ff7f0bc95085e7efae58f889c0834800ca63690a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:27:08 +0000 Subject: [PATCH 1/2] build(deps): bump valibot from 0.27.1 to 0.28.1 Bumps [valibot](https://github.com/fabian-hiller/valibot) from 0.27.1 to 0.28.1. - [Release notes](https://github.com/fabian-hiller/valibot/releases) - [Commits](https://github.com/fabian-hiller/valibot/compare/v0.27.1...v0.28.1) --- updated-dependencies: - dependency-name: valibot dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e87e62f..f7b9765 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "dependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", - "valibot": "^0.27.1" + "valibot": "^0.28.1" }, "devDependencies": { "@octokit/openapi-types": "^19.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1d1513b..192fa50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,8 +12,8 @@ dependencies: specifier: ^6.0.0 version: 6.0.0 valibot: - specifier: ^0.27.1 - version: 0.27.1 + specifier: ^0.28.1 + version: 0.28.1 devDependencies: '@octokit/openapi-types': @@ -4270,8 +4270,8 @@ packages: convert-source-map: 1.9.0 dev: true - /valibot@0.27.1: - resolution: {integrity: sha512-k57/5/kMwMjiVP0LUMpa+n4ihSemuXshz1ND4fftKw1bkHZYN/TnHcbjaEie3K7FwAceiOgugLZPjSaNxdygeg==} + /valibot@0.28.1: + resolution: {integrity: sha512-zQnjwNJuXk6362Leu0+4eFa/SMwRom3/hEvH6s1EGf3oXIPbo2WFKDra9ymnbVh3clLRvd8hw4sKF5ruI2Lyvw==} dev: false /vue-eslint-parser@9.4.1(eslint@8.56.0): From 9ca1e46119b7dbbf4b5de94c55fdb2b1e0cdc80b Mon Sep 17 00:00:00 2001 From: Mogyuchi Date: Tue, 13 Feb 2024 06:00:58 +0900 Subject: [PATCH 2/2] fixup! build(deps): bump valibot from 0.27.1 to 0.28.1 --- dist/index.js | 3147 ++++++++++++++++++++++++++++--------------------- 1 file changed, 1802 insertions(+), 1345 deletions(-) diff --git a/dist/index.js b/dist/index.js index f9301df..7240213 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29760,7 +29760,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getRef = void 0; -const v = __importStar(__nccwpck_require__(6786)); +const v = __importStar(__nccwpck_require__(7085)); const schema_1 = __nccwpck_require__(3731); const utils_1 = __nccwpck_require__(1356); const getRef = ({ eventName, payload }) => { @@ -29821,7 +29821,7 @@ exports.getRef = getRef; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.NullableStringSchema = exports.OptionalStringSchema = exports.StringSchema = void 0; -const valibot_1 = __nccwpck_require__(6786); +const valibot_1 = __nccwpck_require__(7085); exports.StringSchema = (0, valibot_1.string)(); exports.OptionalStringSchema = (0, valibot_1.optional)((0, valibot_1.string)()); exports.NullableStringSchema = (0, valibot_1.nullable)((0, valibot_1.string)()); @@ -31672,7 +31672,7 @@ module.exports = parseParams /***/ }), -/***/ 6786: +/***/ 7085: /***/ ((module) => { "use strict"; @@ -31746,6 +31746,10 @@ __export(src_exports, { dateAsync: () => dateAsync, decimal: () => decimal, defaultArgs: () => defaultArgs, + deleteGlobalConfig: () => deleteGlobalConfig, + deleteGlobalMessage: () => deleteGlobalMessage, + deleteSchemaMessage: () => deleteSchemaMessage, + deleteSpecificMessage: () => deleteSpecificMessage, discriminatedUnion: () => discriminatedUnion, discriminatedUnionAsync: () => discriminatedUnionAsync, email: () => email, @@ -31762,6 +31766,7 @@ __export(src_exports, { finite: () => finite, flatten: () => flatten, forward: () => forward, + forwardAsync: () => forwardAsync, getDefault: () => getDefault, getDefaultAsync: () => getDefaultAsync, getDefaults: () => getDefaults, @@ -31770,8 +31775,14 @@ __export(src_exports, { getFallbackAsync: () => getFallbackAsync, getFallbacks: () => getFallbacks, getFallbacksAsync: () => getFallbacksAsync, + getGlobalConfig: () => getGlobalConfig, + getGlobalMessage: () => getGlobalMessage, + getSchemaMessage: () => getSchemaMessage, + getSpecificMessage: () => getSpecificMessage, + hash: () => hash, hexColor: () => hexColor, hexadecimal: () => hexadecimal, + i18n: () => i18n, imei: () => imei, includes: () => includes, instance: () => instance, @@ -31848,7 +31859,6 @@ __export(src_exports, { optionalAsync: () => optionalAsync, parse: () => parse, parseAsync: () => parseAsync, - parseResult: () => parseResult, partial: () => partial, partialAsync: () => partialAsync, passthrough: () => passthrough, @@ -31871,8 +31881,13 @@ __export(src_exports, { safeParse: () => safeParse, safeParseAsync: () => safeParseAsync, schemaIssue: () => schemaIssue, + schemaResult: () => schemaResult, set: () => set, setAsync: () => setAsync, + setGlobalConfig: () => setGlobalConfig, + setGlobalMessage: () => setGlobalMessage, + setSchemaMessage: () => setSchemaMessage, + setSpecificMessage: () => setSpecificMessage, size: () => size, special: () => special, specialAsync: () => specialAsync, @@ -31881,6 +31896,7 @@ __export(src_exports, { strictAsync: () => strictAsync, string: () => string, stringAsync: () => stringAsync, + stringify: () => stringify, strip: () => strip, stripAsync: () => stripAsync, symbol: () => symbol, @@ -31975,8 +31991,8 @@ function brand(schema, name) { function coerce(schema, action) { return { ...schema, - _parse(input, info) { - return schema._parse(action(input), info); + _parse(input, config) { + return schema._parse(action(input), config); } }; } @@ -31985,29 +32001,16 @@ function coerce(schema, action) { function coerceAsync(schema, action) { return { ...schema, - async _parse(input, info) { - return schema._parse(await action(input), info); + async _parse(input, config) { + return schema._parse(await action(input), config); } }; } -// src/utils/errorMessage/errorMessage.ts -function errorMessage(message) { - return typeof message === "function" ? message() : message; -} - // src/utils/actionIssue/actionIssue.ts -function actionIssue(validation, message, input, requirement, path) { +function actionIssue(context, reference, input, label, received) { return { - issues: [ - { - validation, - message: errorMessage(message), - input, - requirement, - path - } - ] + issues: [{ context, reference, input, label, received }] }; } @@ -32021,22 +32024,72 @@ function defaultArgs(arg1, arg2) { return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2]; } -// src/utils/parseResult/parseResult.ts -function parseResult(typed, output, issues) { - return { typed, output, issues }; +// src/storages/globalConfig/globalConfig.ts +var store; +function setGlobalConfig(config) { + store = { ...store, ...config }; +} +function getGlobalConfig(config) { + return { + lang: config?.lang ?? store?.lang, + message: config?.message, + abortEarly: config?.abortEarly ?? store?.abortEarly, + abortPipeEarly: config?.abortPipeEarly ?? store?.abortPipeEarly, + skipPipe: config?.skipPipe ?? store?.skipPipe + }; +} +function deleteGlobalConfig() { + store = void 0; } -// src/utils/restAndDefaultArgs/restAndDefaultArgs.ts -function restAndDefaultArgs(arg1, arg2, arg3) { - if (!arg1 || typeof arg1 === "object" && !Array.isArray(arg1)) { - const [error2, pipe2] = defaultArgs(arg2, arg3); - return [arg1, error2, pipe2]; - } - const [error, pipe] = defaultArgs( - arg1, - arg2 - ); - return [void 0, error, pipe]; +// src/storages/globalMessage/globalMessage.ts +var store2; +function setGlobalMessage(message, lang) { + if (!store2) + store2 = /* @__PURE__ */ new Map(); + store2.set(lang, message); +} +function getGlobalMessage(lang) { + return store2?.get(lang); +} +function deleteGlobalMessage(lang) { + store2?.delete(lang); +} + +// src/storages/schemaMessage/schemaMessage.ts +var store3; +function setSchemaMessage(message, lang) { + if (!store3) + store3 = /* @__PURE__ */ new Map(); + store3.set(lang, message); +} +function getSchemaMessage(lang) { + return store3?.get(lang); +} +function deleteSchemaMessage(lang) { + store3?.delete(lang); +} + +// src/storages/specificMessage/specificMessage.ts +var store4; +function setSpecificMessage(reference, message, lang) { + if (!store4) + store4 = /* @__PURE__ */ new Map(); + if (!store4.get(reference)) + store4.set(reference, /* @__PURE__ */ new Map()); + store4.get(reference).set(lang, message); +} +function getSpecificMessage(reference, lang) { + return store4?.get(reference)?.get(lang); +} +function deleteSpecificMessage(reference, lang) { + store4?.get(reference)?.delete(lang); +} + +// src/utils/i18n/i18n.ts +function i18n(context, reference, config, issue) { + const message = context.message ?? getSpecificMessage(reference, issue.lang) ?? (context.type === "type" ? getSchemaMessage(issue.lang) : null) ?? config?.message ?? getGlobalMessage(issue.lang) ?? issue.message; + return typeof message === "function" ? message(issue) : message; } // src/utils/isLuhnAlgo/isLuhnAlgo.ts @@ -32054,101 +32107,121 @@ function isLuhnAlgo(input) { return sum % 10 === 0; } +// src/utils/schemaResult/schemaResult.ts +function schemaResult(typed, output, issues) { + return { typed, output, issues }; +} + +// src/utils/stringify/stringify.ts +function stringify(input) { + let type = typeof input; + if (type === "object") { + type = input ? Object.getPrototypeOf(input).constructor.name : "null"; + } + return type === "string" ? `"${input}"` : type === "number" || type === "bigint" || type === "boolean" ? `${input}` : type; +} + // src/utils/pipeResult/utils/pipeIssue/pipeIssue.ts -function pipeIssue(info, issue) { - return { - reason: info?.reason, - validation: issue.validation, - origin: info?.origin || "value", - message: issue.message, +function pipeIssue(context, config, issue) { + const received = issue.received ?? stringify(issue.input); + const schemaIssue2 = { + reason: context.type, + context: issue.context.type, + expected: issue.context.expects, + received, + message: `Invalid ${issue.label}: ${issue.context.expects ? `Expected ${issue.context.expects} but r` : "R"}eceived ${received}`, input: issue.input, - requirement: issue?.requirement, + requirement: issue.context.requirement, path: issue.path, - abortEarly: info?.abortEarly, - abortPipeEarly: info?.abortPipeEarly, - skipPipe: info?.skipPipe - }; -} - -// src/utils/pipeResult/utils/pipeInfo/pipeInfo.ts -function pipeInfo(info, reason) { - return { - reason, - origin: info?.origin, - abortEarly: info?.abortEarly, - abortPipeEarly: info?.abortPipeEarly, - skipPipe: info?.skipPipe + lang: config?.lang, + abortEarly: config?.abortEarly, + abortPipeEarly: config?.abortPipeEarly, + skipPipe: config?.skipPipe }; + schemaIssue2.message = i18n( + issue.context, + issue.reference, + config, + schemaIssue2 + ); + return schemaIssue2; } // src/utils/pipeResult/pipeResult.ts -function pipeResult(input, pipe, parseInfo, reason, issues) { - let info; - let output = input; - if (pipe?.length && !parseInfo?.skipPipe) { - for (const action of pipe) { - const result = action._parse(output); +function pipeResult(context, input, config, issues) { + if (context.pipe && !config?.skipPipe) { + for (const action of context.pipe) { + const result = action._parse(input); if (result.issues) { - info = info || pipeInfo(parseInfo, reason); - for (const issueInfo of result.issues) { - const issue = pipeIssue(info, issueInfo); - issues ? issues.push(issue) : issues = [issue]; + for (const actionIssue2 of result.issues) { + const schemaIssue2 = pipeIssue(context, config, actionIssue2); + issues ? issues.push(schemaIssue2) : issues = [schemaIssue2]; } - if (info.abortEarly || info.abortPipeEarly) { + if (config?.abortEarly || config?.abortPipeEarly) { break; } } else { - output = result.output; + input = result.output; } } } - return parseResult(true, output, issues); + return schemaResult(true, input, issues); } // src/utils/pipeResult/pipeResultAsync.ts -async function pipeResultAsync(input, pipe, parseInfo, reason, issues) { - let info; - let output = input; - if (pipe?.length && !parseInfo?.skipPipe) { - for (const action of pipe) { - const result = await action._parse(output); +async function pipeResultAsync(context, input, config, issues) { + if (context.pipe && !config?.skipPipe) { + for (const action of context.pipe) { + const result = await action._parse(input); if (result.issues) { - info = info || pipeInfo(parseInfo, reason); - for (const issueInfo of result.issues) { - const issue = pipeIssue(info, issueInfo); - issues ? issues.push(issue) : issues = [issue]; + for (const actionIssue2 of result.issues) { + const schemaIssue2 = pipeIssue(context, config, actionIssue2); + issues ? issues.push(schemaIssue2) : issues = [schemaIssue2]; } - if (info.abortEarly || info.abortPipeEarly) { + if (config?.abortEarly || config?.abortPipeEarly) { break; } } else { - output = result.output; + input = result.output; } } } - return parseResult(true, output, issues); + return schemaResult(true, input, issues); +} + +// src/utils/restAndDefaultArgs/restAndDefaultArgs.ts +function restAndDefaultArgs(arg1, arg2, arg3) { + if (!arg1 || typeof arg1 === "object" && !Array.isArray(arg1)) { + const [error2, pipe2] = defaultArgs(arg2, arg3); + return [arg1, error2, pipe2]; + } + const [error, pipe] = defaultArgs( + arg1, + arg2 + ); + return [void 0, error, pipe]; } // src/utils/schemaIssue/schemaIssue.ts -function schemaIssue(info, reason, validation, message, input, path, issues) { - return { - typed: false, - output: input, - issues: [ - { - reason, - validation, - origin: info?.origin || "value", - message: errorMessage(message), - input, - path, - issues, - abortEarly: info?.abortEarly, - abortPipeEarly: info?.abortPipeEarly, - skipPipe: info?.skipPipe - } - ] +function schemaIssue(context, reference, input, config, other) { + const received = stringify(input); + const expected = other?.expected ?? context.expects; + const issue = { + reason: other?.reason ?? "type", + context: context.type, + expected, + received, + message: `Invalid type: Expected ${expected} but received ${received}`, + input, + path: other?.path, + issues: other?.issues, + lang: config?.lang, + abortEarly: config?.abortEarly, + abortPipeEarly: config?.abortPipeEarly, + skipPipe: config?.skipPipe }; + issue.message = i18n(context, reference, config, issue); + return { typed: false, output: input, issues: [issue] }; } // src/methods/getFallback/getFallback.ts @@ -32166,9 +32239,12 @@ function fallback(schema, fallback2) { return { ...schema, fallback: fallback2, - _parse(input, info) { - const result = schema._parse(input, info); - return result.issues ? parseResult(true, getFallback(this, { input, issues: result.issues })) : result; + _parse(input, config) { + const result = schema._parse(input, config); + return result.issues ? schemaResult( + true, + getFallback(this, { input, issues: result.issues }) + ) : result; } }; } @@ -32178,9 +32254,9 @@ function fallbackAsync(schema, fallback2) { return { ...schema, fallback: fallback2, - async _parse(input, info) { - const result = await schema._parse(input, info); - return result.issues ? parseResult( + async _parse(input, config) { + const result = await schema._parse(input, config); + return result.issues ? schemaResult( true, await getFallbackAsync(this, { input, issues: result.issues }) ) : result; @@ -32202,6 +32278,39 @@ function forward(validation, pathList) { issue.input = pathValue; const pathItem = { type: "unknown", + origin: "value", + input: pathInput, + key, + value: pathValue + }; + issue.path ? issue.path.push(pathItem) : issue.path = [pathItem]; + if (!pathValue) { + break; + } + pathInput = pathValue; + } + } + } + return result; + } + }; +} + +// src/methods/forward/forwardAsync.ts +function forwardAsync(validation, pathList) { + return { + ...validation, + async _parse(input) { + const result = await validation._parse(input); + if (result.issues) { + for (const issue of result.issues) { + let pathInput = input; + for (const key of pathList) { + const pathValue = pathInput[key]; + issue.input = pathValue; + const pathItem = { + type: "unknown", + origin: "value", input: pathInput, key, value: pathValue @@ -32315,10 +32424,10 @@ async function getFallbacksAsync(schema) { } // src/methods/is/is.ts -function is(schema, input, info) { +function is(schema, input, config) { return !schema._parse(input, { abortEarly: true, - skipPipe: info?.skipPipe + skipPipe: getGlobalConfig(config)?.skipPipe }).issues; } @@ -32326,10 +32435,11 @@ function is(schema, input, info) { function any(pipe) { return { type: "any", + expects: "any", async: false, pipe, - _parse(input, info) { - return pipeResult(input, this.pipe, info, "any"); + _parse(input, config) { + return pipeResult(this, input, config); } }; } @@ -32338,310 +32448,316 @@ function any(pipe) { function anyAsync(pipe) { return { type: "any", + expects: "any", async: true, pipe, - async _parse(input, info) { - return pipeResultAsync(input, this.pipe, info, "any"); + async _parse(input, config) { + return pipeResultAsync(this, input, config); } }; } // src/schemas/array/array.ts function array(item, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "array", + expects: "Array", async: false, item, message, pipe, - _parse(input, info) { - if (!Array.isArray(input)) { - return schemaIssue(info, "type", "array", this.message, input); - } - let typed = true; - let issues; - const output = []; - for (let key = 0; key < input.length; key++) { - const value2 = input[key]; - const result = this.item._parse(value2, info); - if (result.issues) { - const pathItem = { - type: "array", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + _parse(input, config) { + if (Array.isArray(input)) { + let typed = true; + let issues; + const output = []; + for (let key = 0; key < input.length; key++) { + const value2 = input[key]; + const result = this.item._parse(value2, config); + if (result.issues) { + const pathItem = { + type: "array", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + break; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - break; } + output.push(result.output); } - if (!result.typed) { - typed = false; + if (typed) { + return pipeResult(this, output, config, issues); } - output.push(result.output); - } - if (typed) { - return pipeResult( - output, - this.pipe, - info, - "array", - issues - ); + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, array, input, config); } }; } // src/schemas/array/arrayAsync.ts function arrayAsync(item, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "array", + expects: "Array", async: true, item, message, pipe, - async _parse(input, info) { - if (!Array.isArray(input)) { - return schemaIssue(info, "type", "array", this.message, input); - } - let typed = true; - let issues; - const output = []; - await Promise.all( - input.map(async (value2, key) => { - if (!(info?.abortEarly && issues)) { - const result = await this.item._parse(value2, info); - if (!(info?.abortEarly && issues)) { - if (result.issues) { - const pathItem = { - type: "array", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + async _parse(input, config) { + if (Array.isArray(input)) { + let typed = true; + let issues; + const output = []; + await Promise.all( + input.map(async (value2, key) => { + if (!(config?.abortEarly && issues)) { + const result = await this.item._parse(value2, config); + if (!(config?.abortEarly && issues)) { + if (result.issues) { + const pathItem = { + type: "array", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + throw null; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - throw null; } + output[key] = result.output; } - if (!result.typed) { - typed = false; - } - output[key] = result.output; } - } - }) - ).catch(() => null); - if (typed) { - return pipeResultAsync( - output, - this.pipe, - info, - "array", - issues - ); + }) + ).catch(() => null); + if (typed) { + return pipeResultAsync( + this, + output, + config, + issues + ); + } + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, arrayAsync, input, config); } }; } // src/schemas/bigint/bigint.ts function bigint(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "bigint", + expects: "bigint", async: false, message, pipe, - _parse(input, info) { - if (typeof input !== "bigint") { - return schemaIssue(info, "type", "bigint", this.message, input); + _parse(input, config) { + if (typeof input === "bigint") { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "bigint"); + return schemaIssue(this, bigint, input, config); } }; } // src/schemas/bigint/bigintAsync.ts function bigintAsync(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "bigint", + expects: "bigint", async: true, message, pipe, - async _parse(input, info) { - if (typeof input !== "bigint") { - return schemaIssue(info, "type", "bigint", this.message, input); + async _parse(input, config) { + if (typeof input === "bigint") { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "bigint"); + return schemaIssue(this, bigintAsync, input, config); } }; } // src/schemas/blob/blob.ts function blob(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "blob", + expects: "Blob", async: false, message, pipe, - _parse(input, info) { - if (!(input instanceof Blob)) { - return schemaIssue(info, "type", "blob", this.message, input); + _parse(input, config) { + if (input instanceof Blob) { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "blob"); + return schemaIssue(this, blob, input, config); } }; } // src/schemas/blob/blobAsync.ts function blobAsync(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "blob", + expects: "Blob", async: true, message, pipe, - async _parse(input, info) { - if (!(input instanceof Blob)) { - return schemaIssue(info, "type", "blob", this.message, input); + async _parse(input, config) { + if (input instanceof Blob) { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "blob"); + return schemaIssue(this, blobAsync, input, config); } }; } // src/schemas/boolean/boolean.ts function boolean(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "boolean", + expects: "boolean", async: false, message, pipe, - _parse(input, info) { - if (typeof input !== "boolean") { - return schemaIssue(info, "type", "boolean", this.message, input); + _parse(input, config) { + if (typeof input === "boolean") { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "boolean"); + return schemaIssue(this, boolean, input, config); } }; } // src/schemas/boolean/booleanAsync.ts function booleanAsync(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "boolean", + expects: "boolean", async: true, message, pipe, - async _parse(input, info) { - if (typeof input !== "boolean") { - return schemaIssue(info, "type", "boolean", this.message, input); + async _parse(input, config) { + if (typeof input === "boolean") { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "boolean"); + return schemaIssue(this, booleanAsync, input, config); } }; } // src/schemas/date/date.ts function date(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "date", + expects: "Date", async: false, message, pipe, - _parse(input, info) { - if (!(input instanceof Date) || isNaN(input.getTime())) { - return schemaIssue(info, "type", "date", this.message, input); + _parse(input, config) { + if (input instanceof Date && !isNaN(input.getTime())) { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "date"); + return schemaIssue(this, date, input, config); } }; } // src/schemas/date/dateAsync.ts function dateAsync(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "date", + expects: "Date", async: true, message, pipe, - async _parse(input, info) { - if (!(input instanceof Date) || isNaN(input.getTime())) { - return schemaIssue(info, "type", "date", this.message, input); + async _parse(input, config) { + if (input instanceof Date && !isNaN(input.getTime())) { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "date"); + return schemaIssue(this, dateAsync, input, config); } }; } // src/schemas/enum/enum.ts -function enum_(enum_2, message = "Invalid type") { - let cachedValues; +function enum_(enum__, message) { + const values = Object.values(enum__); return { type: "enum", + expects: values.map(stringify).join(" | "), async: false, - enum: enum_2, + enum: enum__, message, - _parse(input, info) { - cachedValues = cachedValues || Object.values(this.enum); - if (!cachedValues.includes(input)) { - return schemaIssue(info, "type", "enum", this.message, input); + _parse(input, config) { + if (values.includes(input)) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, enum_, input, config); } }; } var nativeEnum = enum_; // src/schemas/enum/enumAsync.ts -function enumAsync(enum_2, message = "Invalid type") { - let cachedValues; +function enumAsync(enum_2, message) { + const values = Object.values(enum_2); return { type: "enum", + expects: values.map(stringify).join(" | "), async: true, enum: enum_2, message, - async _parse(input, info) { - cachedValues = cachedValues || Object.values(this.enum); - if (!cachedValues.includes(input)) { - return schemaIssue(info, "type", "enum", this.message, input); + async _parse(input, config) { + if (values.includes(input)) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, enumAsync, input, config); } }; } @@ -32649,36 +32765,38 @@ var nativeEnumAsync = enumAsync; // src/schemas/instance/instance.ts function instance(class_, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "instance", + expects: class_.name, async: false, class: class_, message, pipe, - _parse(input, info) { - if (!(input instanceof this.class)) { - return schemaIssue(info, "type", "instance", this.message, input); + _parse(input, config) { + if (input instanceof this.class) { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "instance"); + return schemaIssue(this, instance, input, config); } }; } // src/schemas/instance/instanceAsync.ts function instanceAsync(class_, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "instance", + expects: class_.name, async: true, class: class_, message, pipe, - async _parse(input, info) { - if (!(input instanceof this.class)) { - return schemaIssue(info, "type", "instance", this.message, input); + async _parse(input, config) { + if (input instanceof this.class) { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "instance"); + return schemaIssue(this, instanceAsync, input, config); } }; } @@ -32722,20 +32840,21 @@ function mergeOutputs(output1, output2) { // src/schemas/intersect/intersect.ts function intersect(options, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "intersect", + expects: [...new Set(options.map((option) => option.expects))].join(" & "), async: false, options, message, pipe, - _parse(input, info) { + _parse(input, config) { let typed = true; let issues; let output; const outputs = []; for (const schema of this.options) { - const result = schema._parse(input, info); + const result = schema._parse(input, config); if (result.issues) { if (issues) { for (const issue of result.issues) { @@ -32744,7 +32863,7 @@ function intersect(options, arg2, arg3) { } else { issues = result.issues; } - if (info?.abortEarly) { + if (config?.abortEarly) { typed = false; break; } @@ -32759,357 +32878,364 @@ function intersect(options, arg2, arg3) { for (let index = 1; index < outputs.length; index++) { const result = mergeOutputs(output, outputs[index]); if (result.invalid) { - return schemaIssue(info, "type", "intersect", this.message, input); + return schemaIssue(this, intersect, input, config); } output = result.output; } - return pipeResult(output, this.pipe, info, "intersect", issues); + return pipeResult(this, output, config, issues); } - return parseResult(false, output, issues); + return schemaResult(false, output, issues); } }; } var intersection = intersect; // src/schemas/literal/literal.ts -function literal(literal2, message = "Invalid type") { +function literal(literal_, message) { return { type: "literal", + expects: stringify(literal_), async: false, - literal: literal2, + literal: literal_, message, - _parse(input, info) { - if (input !== this.literal) { - return schemaIssue(info, "type", "literal", this.message, input); + _parse(input, config) { + if (input === this.literal) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, literal, input, config); } }; } // src/schemas/literal/literalAsync.ts -function literalAsync(literal2, message = "Invalid type") { +function literalAsync(literal2, message) { return { type: "literal", + expects: stringify(literal2), async: true, literal: literal2, message, - async _parse(input, info) { - if (input !== this.literal) { - return schemaIssue(info, "type", "literal", this.message, input); + async _parse(input, config) { + if (input === this.literal) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, literalAsync, input, config); } }; } // src/schemas/map/map.ts function map(key, value2, arg3, arg4) { - const [message = "Invalid type", pipe] = defaultArgs(arg3, arg4); + const [message, pipe] = defaultArgs(arg3, arg4); return { type: "map", + expects: "Map", async: false, key, value: value2, message, pipe, - _parse(input, info) { - if (!(input instanceof Map)) { - return schemaIssue(info, "type", "map", this.message, input); - } - let typed = true; - let issues; - const output = /* @__PURE__ */ new Map(); - for (const [inputKey, inputValue] of input.entries()) { - let pathItem; - const keyResult = this.key._parse(inputKey, { - origin: "key", - abortEarly: info?.abortEarly, - abortPipeEarly: info?.abortPipeEarly, - skipPipe: info?.skipPipe - }); - if (keyResult.issues) { - pathItem = { - type: "map", - input, - key: inputKey, - value: inputValue - }; - for (const issue of keyResult.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + _parse(input, config) { + if (input instanceof Map) { + let typed = true; + let issues; + const output = /* @__PURE__ */ new Map(); + for (const [inputKey, inputValue] of input.entries()) { + let pathItem; + const keyResult = this.key._parse(inputKey, config); + if (keyResult.issues) { + pathItem = { + type: "map", + origin: "key", + input, + key: inputKey, + value: inputValue + }; + for (const issue of keyResult.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); } - issues?.push(issue); - } - if (!issues) { - issues = keyResult.issues; - } - if (info?.abortEarly) { - typed = false; - break; - } - } - const valueResult = this.value._parse(inputValue, info); - if (valueResult.issues) { - pathItem = pathItem || { - type: "map", - input, - key: inputKey, - value: inputValue - }; - for (const issue of valueResult.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + if (!issues) { + issues = keyResult.issues; + } + if (config?.abortEarly) { + typed = false; + break; } - issues?.push(issue); } - if (!issues) { - issues = valueResult.issues; + const valueResult = this.value._parse(inputValue, config); + if (valueResult.issues) { + pathItem = pathItem ?? { + type: "map", + origin: "value", + input, + key: inputKey, + value: inputValue + }; + for (const issue of valueResult.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = valueResult.issues; + } + if (config?.abortEarly) { + typed = false; + break; + } } - if (info?.abortEarly) { + if (!keyResult.typed || !valueResult.typed) { typed = false; - break; } + output.set(keyResult.output, valueResult.output); } - if (!keyResult.typed || !valueResult.typed) { - typed = false; + if (typed) { + return pipeResult(this, output, config, issues); } - output.set(keyResult.output, valueResult.output); - } - if (typed) { - return pipeResult(output, this.pipe, info, "map", issues); + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, map, input, config); } }; } // src/schemas/map/mapAsync.ts function mapAsync(key, value2, arg3, arg4) { - const [message = "Invalid type", pipe] = defaultArgs(arg3, arg4); + const [message, pipe] = defaultArgs(arg3, arg4); return { type: "map", + expects: "Map", async: true, key, value: value2, message, pipe, - async _parse(input, info) { - if (!(input instanceof Map)) { - return schemaIssue(info, "type", "map", this.message, input); - } - let typed = true; - let issues; - const output = /* @__PURE__ */ new Map(); - await Promise.all( - Array.from(input.entries()).map(async ([inputKey, inputValue]) => { - let pathItem; - const [keyResult, valueResult] = await Promise.all( - [ - { schema: this.key, value: inputKey, origin: "key" }, - { schema: this.value, value: inputValue, origin: "value" } - ].map(async ({ schema, value: value3, origin }) => { - if (!(info?.abortEarly && issues)) { - const result = await schema._parse(value3, { - origin, - abortEarly: info?.abortEarly, - abortPipeEarly: info?.abortPipeEarly, - skipPipe: info?.skipPipe - }); - if (!(info?.abortEarly && issues)) { - if (result.issues) { - pathItem = pathItem || { - type: "map", - input, - key: inputKey, - value: inputValue - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + async _parse(input, config) { + if (input instanceof Map) { + let typed = true; + let issues; + const output = /* @__PURE__ */ new Map(); + await Promise.all( + Array.from(input.entries()).map(async ([inputKey, inputValue]) => { + let pathItem; + const [keyResult, valueResult] = await Promise.all( + [ + { schema: this.key, value: inputKey, origin: "key" }, + { schema: this.value, value: inputValue, origin: "value" } + ].map(async ({ schema, value: value3, origin }) => { + if (!(config?.abortEarly && issues)) { + const result = await schema._parse(value3, config); + if (!(config?.abortEarly && issues)) { + if (result.issues) { + pathItem = pathItem ?? { + type: "map", + origin, + input, + key: inputKey, + value: inputValue + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + throw null; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; - } - if (info?.abortEarly) { - throw null; } + return result; } - return result; } - } - }) - ).catch(() => []); - if (!keyResult?.typed || !valueResult?.typed) { - typed = false; - } - if (keyResult && valueResult) { - output.set(keyResult.output, valueResult.output); - } - }) - ); - if (typed) { - return pipeResultAsync(output, this.pipe, info, "map", issues); + }) + ).catch(() => []); + if (!keyResult?.typed || !valueResult?.typed) { + typed = false; + } + if (keyResult && valueResult) { + output.set(keyResult.output, valueResult.output); + } + }) + ); + if (typed) { + return pipeResultAsync(this, output, config, issues); + } + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, mapAsync, input, config); } }; } // src/schemas/nan/nan.ts -function nan(message = "Invalid type") { +function nan(message) { return { type: "nan", + expects: "NaN", async: false, message, - _parse(input, info) { - if (!Number.isNaN(input)) { - return schemaIssue(info, "type", "nan", this.message, input); + _parse(input, config) { + if (Number.isNaN(input)) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, nan, input, config); } }; } // src/schemas/nan/nanAsync.ts -function nanAsync(message = "Invalid type") { +function nanAsync(message) { return { type: "nan", + expects: "NaN", async: true, message, - async _parse(input, info) { - if (!Number.isNaN(input)) { - return schemaIssue(info, "type", "nan", this.message, input); + async _parse(input, config) { + if (Number.isNaN(input)) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, nanAsync, input, config); } }; } // src/schemas/never/never.ts -function never(message = "Invalid type") { +function never(message) { return { type: "never", + expects: "never", async: false, message, - _parse(input, info) { - return schemaIssue(info, "type", "never", this.message, input); + _parse(input, config) { + return schemaIssue(this, never, input, config); } }; } // src/schemas/never/neverAsync.ts -function neverAsync(message = "Invalid type") { +function neverAsync(message) { return { type: "never", + expects: "never", async: true, message, - async _parse(input, info) { - return schemaIssue(info, "type", "never", this.message, input); + async _parse(input, config) { + return schemaIssue(this, neverAsync, input, config); } }; } // src/schemas/nonNullable/nonNullable.ts -function nonNullable(wrapped, message = "Invalid type") { +function nonNullable(wrapped, message) { return { type: "non_nullable", + expects: "!null", async: false, wrapped, message, - _parse(input, info) { + _parse(input, config) { if (input === null) { - return schemaIssue(info, "type", "non_nullable", this.message, input); + return schemaIssue(this, nonNullable, input, config); } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } // src/schemas/nonNullable/nonNullableAsync.ts -function nonNullableAsync(wrapped, message = "Invalid type") { +function nonNullableAsync(wrapped, message) { return { type: "non_nullable", + expects: "!null", async: true, wrapped, message, - async _parse(input, info) { + async _parse(input, config) { if (input === null) { - return schemaIssue(info, "type", "non_nullable", this.message, input); + return schemaIssue(this, nonNullableAsync, input, config); } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } // src/schemas/nonNullish/nonNullish.ts -function nonNullish(wrapped, message = "Invalid type") { +function nonNullish(wrapped, message) { return { type: "non_nullish", + expects: "!null & !undefined", async: false, wrapped, message, - _parse(input, info) { + _parse(input, config) { if (input === null || input === void 0) { - return schemaIssue(info, "type", "non_nullish", this.message, input); + return schemaIssue(this, nonNullish, input, config); } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } // src/schemas/nonNullish/nonNullishAsync.ts -function nonNullishAsync(wrapped, message = "Invalid type") { +function nonNullishAsync(wrapped, message) { return { type: "non_nullish", + expects: "!null & !undefined", async: true, wrapped, message, - async _parse(input, info) { + async _parse(input, config) { if (input === null || input === void 0) { - return schemaIssue(info, "type", "non_nullish", this.message, input); + return schemaIssue(this, nonNullishAsync, input, config); } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } // src/schemas/nonOptional/nonOptional.ts -function nonOptional(wrapped, message = "Invalid type") { +function nonOptional(wrapped, message) { return { type: "non_optional", + expects: "!undefined", async: false, wrapped, message, - _parse(input, info) { + _parse(input, config) { if (input === void 0) { - return schemaIssue(info, "type", "non_optional", this.message, input); + return schemaIssue(this, nonOptional, input, config); } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } // src/schemas/nonOptional/nonOptionalAsync.ts -function nonOptionalAsync(wrapped, message = "Invalid type") { +function nonOptionalAsync(wrapped, message) { return { type: "non_optional", + expects: "!undefined", async: true, wrapped, message, - async _parse(input, info) { + async _parse(input, config) { if (input === void 0) { - return schemaIssue(info, "type", "non_optional", this.message, input); + return schemaIssue(this, nonOptionalAsync, input, config); } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } @@ -33118,18 +33244,19 @@ function nonOptionalAsync(wrapped, message = "Invalid type") { function nullable(wrapped, default_) { return { type: "nullable", + expects: `${wrapped.expects} | null`, async: false, wrapped, default: default_, - _parse(input, info) { + _parse(input, config) { if (input === null) { const override = getDefault(this); if (override === void 0) { - return parseResult(true, input); + return schemaResult(true, input); } input = override; } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } @@ -33138,18 +33265,19 @@ function nullable(wrapped, default_) { function nullableAsync(wrapped, default_) { return { type: "nullable", + expects: `${wrapped.expects} | null`, async: true, wrapped, default: default_, - async _parse(input, info) { + async _parse(input, config) { if (input === null) { const override = await getDefaultAsync(this); if (override === void 0) { - return parseResult(true, input); + return schemaResult(true, input); } input = override; } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } @@ -33158,18 +33286,19 @@ function nullableAsync(wrapped, default_) { function nullish(wrapped, default_) { return { type: "nullish", + expects: `${wrapped.expects} | null | undefined`, async: false, wrapped, default: default_, - _parse(input, info) { + _parse(input, config) { if (input === null || input === void 0) { const override = getDefault(this); if (override === void 0) { - return parseResult(true, input); + return schemaResult(true, input); } input = override; } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } @@ -33178,49 +33307,52 @@ function nullish(wrapped, default_) { function nullishAsync(wrapped, default_) { return { type: "nullish", + expects: `${wrapped.expects} | null | undefined`, async: true, wrapped, default: default_, - async _parse(input, info) { + async _parse(input, config) { if (input === null || input === void 0) { const override = await getDefaultAsync(this); if (override === void 0) { - return parseResult(true, input); + return schemaResult(true, input); } input = override; } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } // src/schemas/null/null.ts -function null_(message = "Invalid type") { +function null_(message) { return { type: "null", + expects: "null", async: false, message, - _parse(input, info) { - if (input !== null) { - return schemaIssue(info, "type", "null", this.message, input); + _parse(input, config) { + if (input === null) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, null_, input, config); } }; } var nullType = null_; // src/schemas/null/nullAsync.ts -function nullAsync(message = "Invalid type") { +function nullAsync(message) { return { type: "null", + expects: "null", async: true, message, - async _parse(input, info) { - if (input !== null) { - return schemaIssue(info, "type", "null", this.message, input); + async _parse(input, config) { + if (input === null) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, nullAsync, input, config); } }; } @@ -33228,207 +33360,172 @@ var nullTypeAsync = nullAsync; // src/schemas/number/number.ts function number(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "number", + expects: "number", async: false, message, pipe, - _parse(input, info) { - if (typeof input !== "number" || isNaN(input)) { - return schemaIssue(info, "type", "number", this.message, input); + _parse(input, config) { + if (typeof input === "number" && !isNaN(input)) { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "number"); + return schemaIssue(this, number, input, config); } }; } // src/schemas/number/numberAsync.ts function numberAsync(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "number", + expects: "number", async: true, message, pipe, - async _parse(input, info) { - if (typeof input !== "number" || isNaN(input)) { - return schemaIssue(info, "type", "number", this.message, input); + async _parse(input, config) { + if (typeof input === "number" && !isNaN(input)) { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "number"); + return schemaIssue(this, numberAsync, input, config); } }; } // src/schemas/object/object.ts function object(entries, arg2, arg3, arg4) { - const [rest, message = "Invalid type", pipe] = restAndDefaultArgs(arg2, arg3, arg4); + const [rest, message, pipe] = restAndDefaultArgs(arg2, arg3, arg4); let cachedEntries; return { type: "object", + expects: "Object", async: false, entries, rest, message, pipe, - _parse(input, info) { - if (!input || typeof input !== "object") { - return schemaIssue(info, "type", "object", this.message, input); - } - cachedEntries = cachedEntries || Object.entries(this.entries); - let typed = true; - let issues; - const output = {}; - for (const [key, schema] of cachedEntries) { - const value2 = input[key]; - const result = schema._parse(value2, info); - if (result.issues) { - const pathItem = { - type: "object", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + _parse(input, config) { + if (input && typeof input === "object") { + cachedEntries = cachedEntries ?? Object.entries(this.entries); + let typed = true; + let issues; + const output = {}; + for (const [key, schema] of cachedEntries) { + const value2 = input[key]; + const result = schema._parse(value2, config); + if (result.issues) { + const pathItem = { + type: "object", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + break; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - break; + } + if (result.output !== void 0 || key in input) { + output[key] = result.output; } } - if (!result.typed) { - typed = false; - } - if (result.output !== void 0 || key in input) { - output[key] = result.output; - } - } - if (this.rest && !(info?.abortEarly && issues)) { - for (const key in input) { - if (!(key in this.entries)) { - const value2 = input[key]; - const result = this.rest._parse(value2, info); - if (result.issues) { - const pathItem = { - type: "object", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + if (this.rest && !(config?.abortEarly && issues)) { + for (const key in input) { + if (!(key in this.entries)) { + const value2 = input[key]; + const result = this.rest._parse(value2, config); + if (result.issues) { + const pathItem = { + type: "object", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + break; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - break; } + output[key] = result.output; } - if (!result.typed) { - typed = false; - } - output[key] = result.output; } } + if (typed) { + return pipeResult( + this, + output, + config, + issues + ); + } + return schemaResult(false, output, issues); } - if (typed) { - return pipeResult( - output, - this.pipe, - info, - "object", - issues - ); - } - return parseResult(false, output, issues); + return schemaIssue(this, object, input, config); } }; } // src/schemas/object/objectAsync.ts function objectAsync(entries, arg2, arg3, arg4) { - const [rest, message = "Invalid type", pipe] = restAndDefaultArgs(arg2, arg3, arg4); + const [rest, message, pipe] = restAndDefaultArgs(arg2, arg3, arg4); let cachedEntries; return { type: "object", + expects: "Object", async: true, entries, rest, message, pipe, - async _parse(input, info) { - if (!input || typeof input !== "object") { - return schemaIssue(info, "type", "object", this.message, input); - } - cachedEntries = cachedEntries || Object.entries(this.entries); - let typed = true; - let issues; - const output = {}; - await Promise.all([ - Promise.all( - cachedEntries.map(async ([key, schema]) => { - if (!(info?.abortEarly && issues)) { - const value2 = input[key]; - const result = await schema._parse(value2, info); - if (!(info?.abortEarly && issues)) { - if (result.issues) { - const pathItem = { - type: "object", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; - } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; - } - if (info?.abortEarly) { - typed = false; - throw null; - } - } - if (!result.typed) { - typed = false; - } - if (result.output !== void 0 || key in input) { - output[key] = result.output; - } - } - } - }) - ), - this.rest && Promise.all( - Object.entries(input).map(async ([key, value2]) => { - if (!(info?.abortEarly && issues)) { - if (!(key in this.entries)) { - const result = await this.rest._parse(value2, info); - if (!(info?.abortEarly && issues)) { + async _parse(input, config) { + if (input && typeof input === "object") { + cachedEntries = cachedEntries ?? Object.entries(this.entries); + let typed = true; + let issues; + const output = {}; + await Promise.all([ + Promise.all( + cachedEntries.map(async ([key, schema]) => { + if (!(config?.abortEarly && issues)) { + const value2 = input[key]; + const result = await schema._parse(value2, config); + if (!(config?.abortEarly && issues)) { if (result.issues) { const pathItem = { type: "object", + origin: "value", input, key, value: value2 @@ -33444,7 +33541,7 @@ function objectAsync(entries, arg2, arg3, arg4) { if (!issues) { issues = result.issues; } - if (info?.abortEarly) { + if (config?.abortEarly) { typed = false; throw null; } @@ -33452,23 +33549,64 @@ function objectAsync(entries, arg2, arg3, arg4) { if (!result.typed) { typed = false; } - output[key] = result.output; + if (result.output !== void 0 || key in input) { + output[key] = result.output; + } } } - } - }) - ) - ]).catch(() => null); - if (typed) { - return pipeResultAsync( - output, - this.pipe, - info, - "object", - issues - ); + }) + ), + this.rest && Promise.all( + Object.entries(input).map(async ([key, value2]) => { + if (!(config?.abortEarly && issues)) { + if (!(key in this.entries)) { + const result = await this.rest._parse(value2, config); + if (!(config?.abortEarly && issues)) { + if (result.issues) { + const pathItem = { + type: "object", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + throw null; + } + } + if (!result.typed) { + typed = false; + } + output[key] = result.output; + } + } + } + }) + ) + ]).catch(() => null); + if (typed) { + return pipeResultAsync( + this, + output, + config, + issues + ); + } + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, objectAsync, input, config); } }; } @@ -33477,18 +33615,19 @@ function objectAsync(entries, arg2, arg3, arg4) { function optional(wrapped, default_) { return { type: "optional", + expects: `${wrapped.expects} | undefined`, async: false, wrapped, default: default_, - _parse(input, info) { + _parse(input, config) { if (input === void 0) { const override = getDefault(this); if (override === void 0) { - return parseResult(true, input); + return schemaResult(true, input); } input = override; } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } @@ -33497,51 +33636,54 @@ function optional(wrapped, default_) { function optionalAsync(wrapped, default_) { return { type: "optional", + expects: `${wrapped.expects} | undefined`, async: true, wrapped, default: default_, - async _parse(input, info) { + async _parse(input, config) { if (input === void 0) { const override = await getDefaultAsync(this); if (override === void 0) { - return parseResult(true, input); + return schemaResult(true, input); } input = override; } - return this.wrapped._parse(input, info); + return this.wrapped._parse(input, config); } }; } // src/schemas/picklist/picklist.ts -function picklist(options, message = "Invalid type") { +function picklist(options, message) { return { type: "picklist", + expects: options.map(stringify).join(" | "), async: false, options, message, - _parse(input, info) { - if (!this.options.includes(input)) { - return schemaIssue(info, "type", "picklist", this.message, input); + _parse(input, config) { + if (this.options.includes(input)) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, picklist, input, config); } }; } var enumType = picklist; // src/schemas/picklist/picklistAsync.ts -function picklistAsync(options, message = "Invalid type") { +function picklistAsync(options, message) { return { type: "picklist", + expects: options.map(stringify).join(" | "), async: true, options, message, - async _parse(input, info) { - if (!this.options.includes(input)) { - return schemaIssue(info, "type", "picklist", this.message, input); + async _parse(input, config) { + if (this.options.includes(input)) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, picklistAsync, input, config); } }; } @@ -33549,34 +33691,36 @@ var enumTypeAsync = picklistAsync; // src/schemas/string/string.ts function string(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "string", + expects: "string", async: false, message, pipe, - _parse(input, info) { - if (typeof input !== "string") { - return schemaIssue(info, "type", "string", this.message, input); + _parse(input, config) { + if (typeof input === "string") { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "string"); + return schemaIssue(this, string, input, config); } }; } // src/schemas/string/stringAsync.ts function stringAsync(arg1, arg2) { - const [message = "Invalid type", pipe] = defaultArgs(arg1, arg2); + const [message, pipe] = defaultArgs(arg1, arg2); return { type: "string", + expects: "string", async: true, message, pipe, - async _parse(input, info) { - if (typeof input !== "string") { - return schemaIssue(info, "type", "string", this.message, input); + async _parse(input, config) { + if (typeof input === "string") { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "string"); + return schemaIssue(this, stringAsync, input, config); } }; } @@ -33599,176 +33743,169 @@ var BLOCKED_KEYS = ["__proto__", "prototype", "constructor"]; // src/schemas/record/record.ts function record(arg1, arg2, arg3, arg4) { - const [key, value2, message = "Invalid type", pipe] = recordArgs(arg1, arg2, arg3, arg4); + const [key, value2, message, pipe] = recordArgs(arg1, arg2, arg3, arg4); return { type: "record", + expects: "Object", async: false, key, value: value2, message, pipe, - _parse(input, info) { - if (!input || typeof input !== "object") { - return schemaIssue(info, "type", "record", this.message, input); - } - let typed = true; - let issues; - const output = {}; - for (const [inputKey, inputValue] of Object.entries(input)) { - if (!BLOCKED_KEYS.includes(inputKey)) { - let pathItem; - const keyResult = this.key._parse(inputKey, { - origin: "key", - abortEarly: info?.abortEarly, - abortPipeEarly: info?.abortPipeEarly, - skipPipe: info?.skipPipe - }); - if (keyResult.issues) { - pathItem = { - type: "record", - input, - key: inputKey, - value: inputValue - }; - for (const issue of keyResult.issues) { - issue.path = [pathItem]; - issues?.push(issue); - } - if (!issues) { - issues = keyResult.issues; - } - if (info?.abortEarly) { - typed = false; - break; - } - } - const valueResult = this.value._parse(inputValue, info); - if (valueResult.issues) { - pathItem = pathItem || { - type: "record", - input, - key: inputKey, - value: inputValue - }; - for (const issue of valueResult.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { + _parse(input, config) { + if (input && typeof input === "object") { + let typed = true; + let issues; + const output = {}; + for (const [inputKey, inputValue] of Object.entries(input)) { + if (!BLOCKED_KEYS.includes(inputKey)) { + let pathItem; + const keyResult = this.key._parse(inputKey, config); + if (keyResult.issues) { + pathItem = { + type: "record", + origin: "key", + input, + key: inputKey, + value: inputValue + }; + for (const issue of keyResult.issues) { issue.path = [pathItem]; + issues?.push(issue); + } + if (!issues) { + issues = keyResult.issues; + } + if (config?.abortEarly) { + typed = false; + break; } - issues?.push(issue); } - if (!issues) { - issues = valueResult.issues; + const valueResult = this.value._parse(inputValue, config); + if (valueResult.issues) { + pathItem = pathItem ?? { + type: "record", + origin: "value", + input, + key: inputKey, + value: inputValue + }; + for (const issue of valueResult.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = valueResult.issues; + } + if (config?.abortEarly) { + typed = false; + break; + } } - if (info?.abortEarly) { + if (!keyResult.typed || !valueResult.typed) { typed = false; - break; } - } - if (!keyResult.typed || !valueResult.typed) { - typed = false; - } - if (keyResult.typed) { - output[keyResult.output] = valueResult.output; + if (keyResult.typed) { + output[keyResult.output] = valueResult.output; + } } } + if (typed) { + return pipeResult( + this, + output, + config, + issues + ); + } + return schemaResult(false, output, issues); } - if (typed) { - return pipeResult( - output, - this.pipe, - info, - "record", - issues - ); - } - return parseResult(false, output, issues); + return schemaIssue(this, record, input, config); } }; } // src/schemas/record/recordAsync.ts function recordAsync(arg1, arg2, arg3, arg4) { - const [key, value2, message = "Invalid type", pipe] = recordArgs(arg1, arg2, arg3, arg4); + const [key, value2, message, pipe] = recordArgs(arg1, arg2, arg3, arg4); return { type: "record", + expects: "Object", async: true, key, value: value2, message, pipe, - async _parse(input, info) { - if (!input || typeof input !== "object") { - return schemaIssue(info, "type", "record", this.message, input); - } - let typed = true; - let issues; - const output = {}; - await Promise.all( - // Note: `Object.entries(...)` converts each key to a string - Object.entries(input).map(async ([inputKey, inputValue]) => { - if (!BLOCKED_KEYS.includes(inputKey)) { - let pathItem; - const [keyResult, valueResult] = await Promise.all( - [ - { schema: this.key, value: inputKey, origin: "key" }, - { schema: this.value, value: inputValue, origin: "value" } - ].map(async ({ schema, value: value3, origin }) => { - if (!(info?.abortEarly && issues)) { - const result = await schema._parse(value3, { - origin, - abortEarly: info?.abortEarly, - abortPipeEarly: info?.abortPipeEarly, - skipPipe: info?.skipPipe - }); - if (!(info?.abortEarly && issues)) { - if (result.issues) { - pathItem = pathItem || { - type: "record", - input, - key: inputKey, - value: inputValue - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + async _parse(input, config) { + if (input && typeof input === "object") { + let typed = true; + let issues; + const output = {}; + await Promise.all( + // Note: `Object.entries(...)` converts each key to a string + Object.entries(input).map(async ([inputKey, inputValue]) => { + if (!BLOCKED_KEYS.includes(inputKey)) { + let pathItem; + const [keyResult, valueResult] = await Promise.all( + [ + { schema: this.key, value: inputKey, origin: "key" }, + { schema: this.value, value: inputValue, origin: "value" } + ].map(async ({ schema, value: value3, origin }) => { + if (!(config?.abortEarly && issues)) { + const result = await schema._parse(value3, config); + if (!(config?.abortEarly && issues)) { + if (result.issues) { + pathItem = pathItem ?? { + type: "record", + origin, + input, + key: inputKey, + value: inputValue + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + throw null; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; - } - if (info?.abortEarly) { - throw null; } + return result; } - return result; } - } - }) - ).catch(() => []); - if (!keyResult?.typed || !valueResult?.typed) { - typed = false; - } - if (keyResult?.typed && valueResult) { - output[keyResult.output] = valueResult.output; + }) + ).catch(() => []); + if (!keyResult?.typed || !valueResult?.typed) { + typed = false; + } + if (keyResult?.typed && valueResult) { + output[keyResult.output] = valueResult.output; + } } - } - }) - ); - if (typed) { - return pipeResultAsync( - output, - this.pipe, - info, - "record", - issues + }) ); + if (typed) { + return pipeResultAsync( + this, + output, + config, + issues + ); + } + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, recordAsync, input, config); } }; } @@ -33777,10 +33914,11 @@ function recordAsync(arg1, arg2, arg3, arg4) { function recursive(getter) { return { type: "recursive", + expects: "unknown", async: false, getter, - _parse(input, info) { - return this.getter()._parse(input, info); + _parse(input, config) { + return this.getter()._parse(input, config); } }; } @@ -33789,251 +33927,228 @@ function recursive(getter) { function recursiveAsync(getter) { return { type: "recursive", + expects: "unknown", async: true, getter, - async _parse(input, info) { - return this.getter()._parse(input, info); + async _parse(input, config) { + return this.getter()._parse(input, config); } }; } // src/schemas/set/set.ts function set(value2, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "set", + expects: "Set", async: false, value: value2, message, pipe, - _parse(input, info) { - if (!(input instanceof Set)) { - return schemaIssue(info, "type", "set", this.message, input); - } - let key = 0; - let typed = true; - let issues; - const output = /* @__PURE__ */ new Set(); - for (const inputValue of input) { - const result = this.value._parse(inputValue, info); - if (result.issues) { - const pathItem = { - type: "set", - input, - key, - value: inputValue - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + _parse(input, config) { + if (input instanceof Set) { + let key = 0; + let typed = true; + let issues; + const output = /* @__PURE__ */ new Set(); + for (const inputValue of input) { + const result = this.value._parse(inputValue, config); + if (result.issues) { + const pathItem = { + type: "set", + origin: "value", + input, + key, + value: inputValue + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + break; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - break; } + output.add(result.output); + key++; } - if (!result.typed) { - typed = false; + if (typed) { + return pipeResult(this, output, config, issues); } - output.add(result.output); - key++; - } - if (typed) { - return pipeResult(output, this.pipe, info, "set", issues); + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, set, input, config); } }; } // src/schemas/set/setAsync.ts function setAsync(value2, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "set", + expects: "Set", async: true, value: value2, message, pipe, - async _parse(input, info) { - if (!(input instanceof Set)) { - return schemaIssue(info, "type", "set", this.message, input); - } - let typed = true; - let issues; - const output = /* @__PURE__ */ new Set(); - await Promise.all( - Array.from(input.values()).map(async (inputValue, key) => { - if (!(info?.abortEarly && issues)) { - const result = await this.value._parse(inputValue, info); - if (!(info?.abortEarly && issues)) { - if (result.issues) { - const pathItem = { - type: "set", - input, - key, - value: inputValue - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + async _parse(input, config) { + if (input instanceof Set) { + let typed = true; + let issues; + const output = /* @__PURE__ */ new Set(); + await Promise.all( + Array.from(input.values()).map(async (inputValue, key) => { + if (!(config?.abortEarly && issues)) { + const result = await this.value._parse(inputValue, config); + if (!(config?.abortEarly && issues)) { + if (result.issues) { + const pathItem = { + type: "set", + origin: "value", + input, + key, + value: inputValue + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + throw null; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - throw null; } + output.add(result.output); } - if (!result.typed) { - typed = false; - } - output.add(result.output); } - } - }) - ).catch(() => null); - if (typed) { - return pipeResultAsync(output, this.pipe, info, "set", issues); + }) + ).catch(() => null); + if (typed) { + return pipeResultAsync(this, output, config, issues); + } + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, setAsync, input, config); } }; } // src/schemas/special/special.ts function special(check, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "special", + expects: "unknown", async: false, check, message, pipe, - _parse(input, info) { - if (!this.check(input)) { - return schemaIssue(info, "type", "special", this.message, input); + _parse(input, config) { + if (this.check(input)) { + return pipeResult(this, input, config); } - return pipeResult(input, this.pipe, info, "special"); + return schemaIssue(this, special, input, config); } }; } // src/schemas/special/specialAsync.ts function specialAsync(check, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "special", + expects: "unknown", async: true, check, message, pipe, - async _parse(input, info) { - if (!await this.check(input)) { - return schemaIssue(info, "type", "special", this.message, input); + async _parse(input, config) { + if (await this.check(input)) { + return pipeResultAsync(this, input, config); } - return pipeResultAsync(input, this.pipe, info, "special"); + return schemaIssue(this, specialAsync, input, config); } }; } // src/schemas/symbol/symbol.ts -function symbol(message = "Invalid type") { +function symbol(message) { return { type: "symbol", + expects: "symbol", async: false, message, - _parse(input, info) { - if (typeof input !== "symbol") { - return schemaIssue(info, "type", "symbol", this.message, input); + _parse(input, config) { + if (typeof input === "symbol") { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, symbol, input, config); } }; } // src/schemas/symbol/symbolAsync.ts -function symbolAsync(message = "Invalid type") { +function symbolAsync(message) { return { type: "symbol", + expects: "symbol", async: true, message, - async _parse(input, info) { - if (typeof input !== "symbol") { - return schemaIssue(info, "type", "symbol", this.message, input); + async _parse(input, config) { + if (typeof input === "symbol") { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, symbolAsync, input, config); } }; } // src/schemas/tuple/tuple.ts function tuple(items, arg2, arg3, arg4) { - const [rest, message = "Invalid type", pipe] = restAndDefaultArgs(arg2, arg3, arg4); + const [rest, message, pipe] = restAndDefaultArgs(arg2, arg3, arg4); return { type: "tuple", + expects: "Array", async: false, items, rest, message, pipe, - _parse(input, info) { - if (!Array.isArray(input) || this.items.length > input.length) { - return schemaIssue(info, "type", "tuple", this.message, input); - } - let typed = true; - let issues; - const output = []; - for (let key = 0; key < this.items.length; key++) { - const value2 = input[key]; - const result = this.items[key]._parse(value2, info); - if (result.issues) { - const pathItem = { - type: "tuple", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; - } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; - } - if (info?.abortEarly) { - typed = false; - break; - } - } - if (!result.typed) { - typed = false; - } - output[key] = result.output; - } - if (this.rest && !(info?.abortEarly && issues)) { - for (let key = this.items.length; key < input.length; key++) { + _parse(input, config) { + if (Array.isArray(input)) { + let typed = true; + let issues; + const output = []; + for (let key = 0; key < this.items.length; key++) { const value2 = input[key]; - const result = this.rest._parse(value2, info); + const result = this.items[key]._parse(value2, config); if (result.issues) { const pathItem = { type: "tuple", + origin: "value", input, key, value: value2 @@ -34044,172 +34159,210 @@ function tuple(items, arg2, arg3, arg4) { } else { issue.path = [pathItem]; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + break; + } + } + if (!result.typed) { + typed = false; + } + output[key] = result.output; + } + if (this.rest && !(config?.abortEarly && issues)) { + for (let key = this.items.length; key < input.length; key++) { + const value2 = input[key]; + const result = this.rest._parse(value2, config); + if (result.issues) { + const pathItem = { + type: "tuple", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + break; + } } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - break; } + output[key] = result.output; } - if (!result.typed) { - typed = false; - } - output[key] = result.output; } + if (typed) { + return pipeResult( + this, + output, + config, + issues + ); + } + return schemaResult(false, output, issues); } - if (typed) { - return pipeResult( - output, - this.pipe, - info, - "tuple", - issues - ); - } - return parseResult(false, output, issues); + return schemaIssue(this, tuple, input, config); } }; } // src/schemas/tuple/tupleAsync.ts function tupleAsync(items, arg2, arg3, arg4) { - const [rest, message = "Invalid type", pipe] = restAndDefaultArgs(arg2, arg3, arg4); + const [rest, message, pipe] = restAndDefaultArgs(arg2, arg3, arg4); return { type: "tuple", + expects: "Array", async: true, items, rest, message, pipe, - async _parse(input, info) { - if (!Array.isArray(input) || this.items.length > input.length) { - return schemaIssue(info, "type", "tuple", this.message, input); - } - let typed = true; - let issues; - const output = []; - await Promise.all([ - // Parse schema of each tuple item - Promise.all( - this.items.map(async (schema, key) => { - if (!(info?.abortEarly && issues)) { - const value2 = input[key]; - const result = await schema._parse(value2, info); - if (!(info?.abortEarly && issues)) { - if (result.issues) { - const pathItem = { - type: "tuple", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + async _parse(input, config) { + if (Array.isArray(input)) { + let typed = true; + let issues; + const output = []; + await Promise.all([ + // Parse schema of each tuple item + Promise.all( + this.items.map(async (schema, key) => { + if (!(config?.abortEarly && issues)) { + const value2 = input[key]; + const result = await schema._parse(value2, config); + if (!(config?.abortEarly && issues)) { + if (result.issues) { + const pathItem = { + type: "tuple", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + throw null; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - throw null; } + output[key] = result.output; } - if (!result.typed) { - typed = false; - } - output[key] = result.output; } - } - }) - ), - // If necessary parse schema of each rest item - this.rest && Promise.all( - input.slice(this.items.length).map(async (value2, index) => { - if (!(info?.abortEarly && issues)) { - const key = this.items.length + index; - const result = await this.rest._parse(value2, info); - if (!(info?.abortEarly && issues)) { - if (result.issues) { - const pathItem = { - type: "tuple", - input, - key, - value: value2 - }; - for (const issue of result.issues) { - if (issue.path) { - issue.path.unshift(pathItem); - } else { - issue.path = [pathItem]; + }) + ), + // If necessary parse schema of each rest item + this.rest && Promise.all( + input.slice(this.items.length).map(async (value2, index) => { + if (!(config?.abortEarly && issues)) { + const key = this.items.length + index; + const result = await this.rest._parse(value2, config); + if (!(config?.abortEarly && issues)) { + if (result.issues) { + const pathItem = { + type: "tuple", + origin: "value", + input, + key, + value: value2 + }; + for (const issue of result.issues) { + if (issue.path) { + issue.path.unshift(pathItem); + } else { + issue.path = [pathItem]; + } + issues?.push(issue); + } + if (!issues) { + issues = result.issues; + } + if (config?.abortEarly) { + typed = false; + throw null; } - issues?.push(issue); - } - if (!issues) { - issues = result.issues; } - if (info?.abortEarly) { + if (!result.typed) { typed = false; - throw null; } + output[key] = result.output; } - if (!result.typed) { - typed = false; - } - output[key] = result.output; } - } - }) - ) - ]).catch(() => null); - if (typed) { - return pipeResultAsync( - output, - this.pipe, - info, - "tuple", - issues - ); + }) + ) + ]).catch(() => null); + if (typed) { + return pipeResultAsync( + this, + output, + config, + issues + ); + } + return schemaResult(false, output, issues); } - return parseResult(false, output, issues); + return schemaIssue(this, tupleAsync, input, config); } }; } // src/schemas/undefined/undefined.ts -function undefined_(message = "Invalid type") { +function undefined_(message) { return { type: "undefined", + expects: "undefined", async: false, message, - _parse(input, info) { - if (typeof input !== "undefined") { - return schemaIssue(info, "type", "undefined", this.message, input); + _parse(input, config) { + if (input === void 0) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, undefined_, input, config); } }; } var undefinedType = undefined_; // src/schemas/undefined/undefinedAsync.ts -function undefinedAsync(message = "Invalid type") { +function undefinedAsync(message) { return { type: "undefined", + expects: "undefined", async: true, message, - async _parse(input, info) { - if (typeof input !== "undefined") { - return schemaIssue(info, "type", "undefined", this.message, input); + async _parse(input, config) { + if (input === void 0) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, undefinedAsync, input, config); } }; } @@ -34234,19 +34387,20 @@ function subissues(results) { // src/schemas/union/union.ts function union(options, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "union", + expects: [...new Set(options.map((option) => option.expects))].join(" | "), async: false, options, message, pipe, - _parse(input, info) { + _parse(input, config) { let validResult; let untypedResults; let typedResults; for (const schema of this.options) { - const result = schema._parse(input, info); + const result = schema._parse(input, config); if (result.typed) { if (!result.issues) { validResult = result; @@ -34259,60 +34413,49 @@ function union(options, arg2, arg3) { } } if (validResult) { - return pipeResult(validResult.output, this.pipe, info, "union"); + return pipeResult(this, validResult.output, config); } if (typedResults?.length) { const firstResult = typedResults[0]; return pipeResult( + this, firstResult.output, - this.pipe, - info, - "union", + config, // Hint: If there is more than one typed result, we use a general // union issue with subissues because the issues could contradict // each other. - typedResults.length === 1 ? firstResult.issues : schemaIssue( - info, - "union", - "union", - this.message, - input, - void 0, - subissues(typedResults) - ).issues + typedResults.length === 1 ? firstResult.issues : schemaIssue(this, union, input, config, { + reason: "union", + issues: subissues(typedResults) + }).issues ); } if (untypedResults?.length === 1) { return untypedResults[0]; } - return schemaIssue( - info, - "type", - "union", - this.message, - input, - void 0, - subissues(untypedResults) - ); + return schemaIssue(this, union, input, config, { + issues: subissues(untypedResults) + }); } }; } // src/schemas/union/unionAsync.ts function unionAsync(options, arg2, arg3) { - const [message = "Invalid type", pipe] = defaultArgs(arg2, arg3); + const [message, pipe] = defaultArgs(arg2, arg3); return { type: "union", + expects: [...new Set(options.map((option) => option.expects))].join(" | "), async: true, options, message, pipe, - async _parse(input, info) { + async _parse(input, config) { let validResult; let untypedResults; let typedResults; for (const schema of this.options) { - const result = await schema._parse(input, info); + const result = await schema._parse(input, config); if (result.typed) { if (!result.issues) { validResult = result; @@ -34325,41 +34468,29 @@ function unionAsync(options, arg2, arg3) { } } if (validResult) { - return pipeResultAsync(validResult.output, this.pipe, info, "union"); + return pipeResultAsync(this, validResult.output, config); } if (typedResults?.length) { const firstResult = typedResults[0]; return pipeResultAsync( + this, firstResult.output, - this.pipe, - info, - "union", + config, // Hint: If there is more than one typed result, we use a general // union issue with subissues because the issues could contradict // each other. - typedResults.length === 1 ? firstResult.issues : schemaIssue( - info, - "union", - "union", - this.message, - input, - void 0, - subissues(typedResults) - ).issues + typedResults.length === 1 ? firstResult.issues : schemaIssue(this, unionAsync, input, config, { + reason: "union", + issues: subissues(typedResults) + }).issues ); } if (untypedResults?.length === 1) { return untypedResults[0]; } - return schemaIssue( - info, - "type", - "union", - this.message, - input, - void 0, - subissues(untypedResults) - ); + return schemaIssue(this, unionAsync, input, config, { + issues: subissues(untypedResults) + }); } }; } @@ -34368,10 +34499,11 @@ function unionAsync(options, arg2, arg3) { function unknown(pipe) { return { type: "unknown", + expects: "unknown", async: false, pipe, - _parse(input, info) { - return pipeResult(input, this.pipe, info, "unknown"); + _parse(input, config) { + return pipeResult(this, input, config); } }; } @@ -34380,77 +34512,90 @@ function unknown(pipe) { function unknownAsync(pipe) { return { type: "unknown", + expects: "unknown", async: true, pipe, - async _parse(input, info) { - return pipeResultAsync(input, this.pipe, info, "unknown"); + async _parse(input, config) { + return pipeResultAsync(this, input, config); } }; } // src/schemas/variant/variant.ts function variant(key, options, arg3, arg4) { - const [message = "Invalid type", pipe] = defaultArgs(arg3, arg4); + const [message, pipe] = defaultArgs(arg3, arg4); + let cachedExpectedKey; return { type: "variant", + expects: "Object", async: false, key, options, message, pipe, - _parse(input, info) { - if (!input || typeof input !== "object") { - return schemaIssue(info, "type", "variant", this.message, input); - } - if (this.key in input) { - let variantResult; - const parseOptions = (options2) => { - for (const schema of options2) { - if (schema.type === "object") { - const keyResult = schema.entries[this.key]._parse( - input[this.key], - info - ); - if (!keyResult.issues) { - const dataResult = schema._parse(input, info); - if (!dataResult.issues) { - variantResult = dataResult; - break; + _parse(input, config) { + if (input && typeof input === "object") { + if (this.key in input || !cachedExpectedKey) { + let expectedKey; + let variantResult; + const parseOptions = (options2) => { + for (const schema of options2) { + if (schema.type === "object") { + const keySchema = schema.entries[this.key]; + const keyResult = keySchema._parse( + input[this.key], + config + ); + if (!cachedExpectedKey) { + expectedKey ? expectedKey.push(keySchema.expects) : expectedKey = [keySchema.expects]; } - if (!variantResult || !variantResult.typed && dataResult.typed) { - variantResult = dataResult; + if (!keyResult.issues) { + const dataResult = schema._parse(input, config); + if (!dataResult.issues) { + variantResult = dataResult; + break; + } + if (!variantResult || !variantResult.typed && dataResult.typed) { + variantResult = dataResult; + } + } + } else if (schema.type === "variant") { + parseOptions(schema.options); + if (variantResult && !variantResult.issues) { + break; } - } - } else if (schema.type === "variant") { - parseOptions(schema.options); - if (variantResult && !variantResult.issues) { - break; } } + }; + parseOptions(this.options); + cachedExpectedKey = cachedExpectedKey || [...new Set(expectedKey)].join(" | "); + if (variantResult) { + if (variantResult.typed) { + return pipeResult( + this, + variantResult.output, + config, + variantResult.issues + ); + } + return variantResult; } - }; - parseOptions(this.options); - if (variantResult) { - if (variantResult.typed) { - return pipeResult( - variantResult.output, - this.pipe, - info, - "variant", - variantResult.issues - ); - } - return variantResult; } + const value2 = input[this.key]; + return schemaIssue(this, variant, value2, config, { + expected: cachedExpectedKey, + path: [ + { + type: "object", + origin: "value", + input, + key: this.key, + value: value2 + } + ] + }); } - return schemaIssue(info, "type", "variant", this.message, input, [ - { - type: "object", - input, - key: this.key, - value: void 0 - } - ]); + return schemaIssue(this, variant, input, config); } }; } @@ -34458,99 +34603,113 @@ var discriminatedUnion = variant; // src/schemas/variant/variantAsync.ts function variantAsync(key, options, arg3, arg4) { - const [message = "Invalid type", pipe] = defaultArgs(arg3, arg4); + const [message, pipe] = defaultArgs(arg3, arg4); + let cachedExpectedKey; return { type: "variant", + expects: "Object", async: true, key, options, message, pipe, - async _parse(input, info) { - if (!input || typeof input !== "object") { - return schemaIssue(info, "type", "variant", this.message, input); - } - if (this.key in input) { - let variantResult; - const parseOptions = async (options2) => { - for (const schema of options2) { - if (schema.type === "object") { - const keyResult = await schema.entries[this.key]._parse( - input[this.key], - info - ); - if (!keyResult.issues) { - const dataResult = await schema._parse(input, info); - if (!dataResult.issues) { - variantResult = dataResult; - break; + async _parse(input, config) { + if (input && typeof input === "object") { + if (this.key in input || !cachedExpectedKey) { + let expectedKey; + let variantResult; + const parseOptions = async (options2) => { + for (const schema of options2) { + if (schema.type === "object") { + const keySchema = schema.entries[this.key]; + const keyResult = await keySchema._parse( + input[this.key], + config + ); + if (!cachedExpectedKey) { + expectedKey ? expectedKey.push(keySchema.expects) : expectedKey = [keySchema.expects]; } - if (!variantResult || !variantResult.typed && dataResult.typed) { - variantResult = dataResult; + if (!keyResult.issues) { + const dataResult = await schema._parse(input, config); + if (!dataResult.issues) { + variantResult = dataResult; + break; + } + if (!variantResult || !variantResult.typed && dataResult.typed) { + variantResult = dataResult; + } + } + } else if (schema.type === "variant") { + await parseOptions(schema.options); + if (variantResult && !variantResult.issues) { + break; } - } - } else if (schema.type === "variant") { - await parseOptions(schema.options); - if (variantResult && !variantResult.issues) { - break; } } + }; + await parseOptions(this.options); + cachedExpectedKey = cachedExpectedKey || [...new Set(expectedKey)].join(" | "); + if (variantResult) { + if (variantResult.typed) { + return pipeResultAsync( + this, + variantResult.output, + config, + variantResult.issues + ); + } + return variantResult; } - }; - await parseOptions(this.options); - if (variantResult) { - if (variantResult.typed) { - return pipeResultAsync( - variantResult.output, - this.pipe, - info, - "variant", - variantResult.issues - ); - } - return variantResult; } + const value2 = input[this.key]; + return schemaIssue(this, variantAsync, value2, config, { + expected: cachedExpectedKey, + path: [ + { + type: "object", + origin: "value", + input, + key: this.key, + value: value2 + } + ] + }); } - return schemaIssue(info, "type", "variant", this.message, input, [ - { - type: "object", - input, - key: this.key, - value: void 0 - } - ]); + return schemaIssue(this, variantAsync, input, config); } }; } var discriminatedUnionAsync = variantAsync; // src/schemas/void/void.ts -function void_(message = "Invalid type") { +function void_(message) { return { type: "void", + expects: "void", async: false, message, - _parse(input, info) { - if (typeof input !== "undefined") { - return schemaIssue(info, "type", "void", this.message, input); + _parse(input, config) { + if (input === void 0) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, void_, input, config); } }; } var voidType = void_; // src/schemas/void/voidAsync.ts -function voidAsync(message = "Invalid type") { +function voidAsync(message) { return { type: "void", + expects: "void", async: true, message, - async _parse(input, info) { - if (typeof input !== "undefined") { - return schemaIssue(info, "type", "void", this.message, input); + async _parse(input, config) { + if (input === void 0) { + return schemaResult(true, input); } - return parseResult(true, input); + return schemaIssue(this, voidAsync, input, config); } }; } @@ -34620,8 +34779,8 @@ function omitAsync(schema, keys, arg3, arg4, arg5) { } // src/methods/parse/parse.ts -function parse(schema, input, info) { - const result = schema._parse(input, info); +function parse(schema, input, config) { + const result = schema._parse(input, getGlobalConfig(config)); if (result.issues) { throw new ValiError(result.issues); } @@ -34629,8 +34788,8 @@ function parse(schema, input, info) { } // src/methods/parse/parseAsync.ts -async function parseAsync(schema, input, info) { - const result = await schema._parse(input, info); +async function parseAsync(schema, input, config) { + const result = await schema._parse(input, getGlobalConfig(config)); if (result.issues) { throw new ValiError(result.issues); } @@ -34675,8 +34834,8 @@ function partialAsync(schema, arg2, arg3, arg4) { function passthrough(schema) { return { ...schema, - _parse(input, info) { - const result = schema._parse(input, info); + _parse(input, config) { + const result = schema._parse(input, config); if (result.typed) { result.output = { ...input, ...result.output }; } @@ -34689,8 +34848,8 @@ function passthrough(schema) { function passthroughAsync(schema) { return { ...schema, - async _parse(input, info) { - const result = await schema._parse(input, info); + async _parse(input, config) { + const result = await schema._parse(input, config); if (result.typed) { result.output = { ...input, ...result.output }; } @@ -34762,8 +34921,8 @@ function requiredAsync(schema, arg2, arg3, arg4) { } // src/methods/safeParse/safeParse.ts -function safeParse(schema, input, info) { - const result = schema._parse(input, info); +function safeParse(schema, input, config) { + const result = schema._parse(input, getGlobalConfig(config)); return { typed: result.typed, success: !result.issues, @@ -34775,8 +34934,8 @@ function safeParse(schema, input, info) { } // src/methods/safeParse/safeParseAsync.ts -async function safeParseAsync(schema, input, info) { - const result = await schema._parse(input, info); +async function safeParseAsync(schema, input, config) { + const result = await schema._parse(input, getGlobalConfig(config)); return { typed: result.typed, success: !result.issues, @@ -34788,24 +34947,23 @@ async function safeParseAsync(schema, input, info) { } // src/methods/strict/strict.ts -function strict(schema, message = "Invalid keys") { +function strict(schema) { return { ...schema, - _parse(input, info) { - const result = schema._parse(input, info); - return !result.issues && Object.keys(input).some((key) => !(key in schema.entries)) ? schemaIssue(info, "object", "strict", message, input) : result; + _parse(input, config) { + const result = schema._parse(input, config); + return !result.issues && Object.keys(input).some((key) => !(key in schema.entries)) ? schemaIssue(this, object, input, config) : result; } }; } // src/methods/strict/strictAsync.ts -function strictAsync(schema, message = "Invalid keys") { +function strictAsync(schema) { return { ...schema, - message, - async _parse(input, info) { - const result = await schema._parse(input, info); - return !result.issues && Object.keys(input).some((key) => !(key in schema.entries)) ? schemaIssue(info, "object", "strict", message, input) : result; + async _parse(input, config) { + const result = await schema._parse(input, config); + return !result.issues && Object.keys(input).some((key) => !(key in schema.entries)) ? schemaIssue(this, objectAsync, input, config) : result; } }; } @@ -34815,10 +34973,10 @@ function strip(schema) { let cachedKeys; return { ...schema, - _parse(input, info) { - const result = schema._parse(input, info); + _parse(input, config) { + const result = schema._parse(input, config); if (result.typed) { - cachedKeys = cachedKeys || Object.keys(schema.entries); + cachedKeys = cachedKeys ?? Object.keys(schema.entries); const output = {}; for (const key of cachedKeys) { output[key] = result.output[key]; @@ -34835,10 +34993,10 @@ function stripAsync(schema) { let cachedKeys; return { ...schema, - async _parse(input, info) { - const result = await schema._parse(input, info); + async _parse(input, config) { + const result = await schema._parse(input, config); if (result.typed) { - cachedKeys = cachedKeys || Object.keys(schema.entries); + cachedKeys = cachedKeys ?? Object.keys(schema.entries); const output = {}; for (const key of cachedKeys) { output[key] = result.output[key]; @@ -34854,17 +35012,21 @@ function stripAsync(schema) { function transform(schema, action, arg1) { return { ...schema, - _parse(input, info) { - const result = schema._parse(input, info); + _parse(input, config) { + const result = schema._parse(input, config); if (result.typed) { result.output = action(result.output, { issues: result.issues }); if (result.issues || !arg1) { return result; } if (Array.isArray(arg1)) { - return pipeResult(result.output, arg1, info, typeof result.output); + return pipeResult( + { type: typeof result.output, pipe: arg1 }, + result.output, + config + ); } - return arg1._parse(result.output, info); + return arg1._parse(result.output, config); } return result; } @@ -34876,8 +35038,8 @@ function transformAsync(schema, action, arg1) { return { ...schema, async: true, - async _parse(input, info) { - const result = await schema._parse(input, info); + async _parse(input, config) { + const result = await schema._parse(input, config); if (result.typed) { result.output = await action(result.output, { issues: result.issues }); if (result.issues || !arg1) { @@ -34885,13 +35047,12 @@ function transformAsync(schema, action, arg1) { } if (Array.isArray(arg1)) { return pipeResultAsync( + { type: typeof result.output, pipe: arg1 }, result.output, - arg1, - info, - typeof result.output + config ); } - return arg1._parse(result.output, info); + return arg1._parse(result.output, config); } return result; } @@ -34907,10 +35068,10 @@ function unwrap(schema) { function withDefault(schema, value2) { return { ...schema, - _parse(input, info) { + _parse(input, config) { return schema._parse( input === void 0 ? typeof value2 === "function" ? value2() : value2 : input, - info + config ); } }; @@ -35045,27 +35206,36 @@ function toUpperCase() { } // src/validations/bic/bic.ts -function bic(message = "Invalid BIC") { +function bic(message) { return { type: "bic", + expects: null, async: false, message, requirement: BIC_REGEX, _parse(input) { - return !this.requirement.test(input.toUpperCase()) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, bic, input, "BIC"); } }; } // src/validations/bytes/bytes.ts -function bytes(requirement, message = "Invalid byte length") { +function bytes(requirement, message) { return { type: "bytes", + expects: `${requirement}`, async: false, message, requirement, _parse(input) { - return new TextEncoder().encode(input).length !== this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + const length2 = new TextEncoder().encode(input).length; + if (length2 === this.requirement) { + return actionOutput(input); + } + return actionIssue(this, bytes, input, "bytes", `${length2}`); } }; } @@ -35088,9 +35258,10 @@ var PROVIDER_REGEX_LIST = [ // Visa /^4\d{12}(?:\d{3,6})?$/u ]; -function creditCard(message = "Invalid credit card") { +function creditCard(message) { return { type: "credit_card", + expects: null, async: false, message, requirement: (input) => { @@ -35098,641 +35269,910 @@ function creditCard(message = "Invalid credit card") { return PROVIDER_REGEX_LIST.some((regex2) => regex2.test(sanitized)) && isLuhnAlgo(sanitized); }, _parse(input) { - return !this.requirement(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement(input)) { + return actionOutput(input); + } + return actionIssue(this, creditCard, input, "credit card"); } }; } // src/validations/cuid2/cuid2.ts -function cuid2(message = "Invalid Cuid2") { +function cuid2(message) { return { type: "cuid2", + expects: null, async: false, message, requirement: CUID2_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, cuid2, input, "Cuid2"); } }; } // src/validations/custom/custom.ts -function custom(requirement, message = "Invalid input") { +function custom(requirement, message) { return { type: "custom", + expects: null, async: false, message, requirement, _parse(input) { - return !this.requirement(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement(input)) { + return actionOutput(input); + } + return actionIssue(this, custom, input, "input"); } }; } // src/validations/custom/customAsync.ts -function customAsync(requirement, message = "Invalid input") { +function customAsync(requirement, message) { return { type: "custom", + expects: null, async: true, message, requirement, async _parse(input) { - return !await this.requirement(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (await this.requirement(input)) { + return actionOutput(input); + } + return actionIssue(this, customAsync, input, "input"); } }; } // src/validations/decimal/decimal.ts -function decimal(message = "Invalid decimal") { +function decimal(message) { return { type: "decimal", + expects: null, async: false, message, requirement: DECIMAL_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, decimal, input, "decimal"); } }; } // src/validations/email/email.ts -function email(message = "Invalid email") { +function email(message) { return { type: "email", + expects: null, async: false, message, requirement: EMAIL_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, email, input, "email"); } }; } // src/validations/emoji/emoji.ts -function emoji(message = "Invalid emoji") { +function emoji(message) { return { type: "emoji", + expects: null, async: false, message, requirement: EMOJI_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, emoji, input, "emoji"); } }; } // src/validations/endsWith/endsWith.ts -function endsWith(requirement, message = "Invalid end") { +function endsWith(requirement, message) { return { type: "ends_with", + expects: `"${requirement}"`, async: false, message, requirement, _parse(input) { - return !input.endsWith(this.requirement) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.endsWith(this.requirement)) { + return actionOutput(input); + } + return actionIssue( + this, + endsWith, + input, + "end", + `"${input.slice(-this.requirement.length)}"` + ); } }; } // src/validations/equal/equal.ts -function equal(requirement, message = "Invalid input") { +function equal(requirement, message) { return { type: "equal", + expects: stringify(requirement), async: false, message, requirement, _parse(input) { - return input !== this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input === this.requirement) { + return actionOutput(input); + } + return actionIssue(this, equal, input, "value"); } }; } // src/validations/excludes/excludes.ts -function excludes(requirement, message = "Invalid content") { +function excludes(requirement, message) { + const received = stringify(requirement); return { type: "excludes", + expects: `!${received}`, async: false, message, requirement, _parse(input) { - return input.includes(this.requirement) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (!input.includes(this.requirement)) { + return actionOutput(input); + } + return actionIssue(this, excludes, input, "content", received); } }; } // src/validations/finite/finite.ts -function finite(message = "Invalid finite number") { +function finite(message) { return { type: "finite", + expects: null, async: false, message, requirement: Number.isFinite, _parse(input) { - return !this.requirement(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement(input)) { + return actionOutput(input); + } + return actionIssue(this, finite, input, "finite"); + } + }; +} + +// src/validations/hash/hash.ts +var HASH_LENGTHS = { + md4: 32, + md5: 32, + sha1: 40, + sha256: 64, + sha384: 96, + sha512: 128, + ripemd128: 32, + ripemd160: 40, + tiger128: 32, + tiger160: 40, + tiger192: 48, + crc32: 8, + crc32b: 8, + adler32: 8 +}; +function hash(types, message) { + return { + type: "hash", + expects: null, + async: false, + message, + requirement: RegExp( + types.map((type) => `^[a-f0-9]{${HASH_LENGTHS[type]}}$`).join("|"), + "iu" + ), + _parse(input) { + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, hash, input, "hash"); } }; } // src/validations/hexadecimal/hexadecimal.ts -function hexadecimal(message = "Invalid hexadecimal") { +function hexadecimal(message) { return { type: "hexadecimal", + expects: null, async: false, message, requirement: HEXADECIMAL_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, hexadecimal, input, "hexadecimal"); } }; } // src/validations/hexColor/hexColor.ts -function hexColor(message = "Invalid hex color") { +function hexColor(message) { return { type: "hex_color", + expects: null, async: false, message, requirement: HEX_COLOR_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, hexColor, input, "hex color"); } }; } // src/validations/imei/imei.ts -function imei(message = "Invalid IMEI") { +function imei(message) { return { type: "imei", + expects: null, async: false, message, requirement: [IMEI_REGEX, isLuhnAlgo], _parse(input) { - return !this.requirement[0].test(input) || !this.requirement[1](input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement[0].test(input) && this.requirement[1](input)) { + return actionOutput(input); + } + return actionIssue(this, imei, input, "IMEI"); } }; } // src/validations/includes/includes.ts -function includes(requirement, message = "Invalid content") { +function includes(requirement, message) { + const expects = stringify(requirement); return { type: "includes", + expects, async: false, message, requirement, _parse(input) { - return !input.includes(requirement) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.includes(this.requirement)) { + return actionOutput(input); + } + return actionIssue(this, includes, input, "content", `!${expects}`); } }; } // src/validations/integer/integer.ts -function integer(message = "Invalid integer") { +function integer(message) { return { type: "integer", + expects: null, async: false, message, requirement: Number.isInteger, _parse(input) { - return !this.requirement(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement(input)) { + return actionOutput(input); + } + return actionIssue(this, integer, input, "integer"); } }; } // src/validations/ip/ip.ts -function ip(message = "Invalid IP") { +function ip(message) { return { type: "ip", + expects: null, async: false, message, + // TODO: It is strange that we have an OR relationship between requirements requirement: [IPV4_REGEX, IPV6_REGEX], _parse(input) { - return !this.requirement[0].test(input) && !this.requirement[1].test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement[0].test(input) || this.requirement[1].test(input)) { + return actionOutput(input); + } + return actionIssue(this, ip, input, "IP"); } }; } // src/validations/ipv4/ipv4.ts -function ipv4(message = "Invalid IPv4") { +function ipv4(message) { return { type: "ipv4", + expects: null, async: false, message, requirement: IPV4_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, ipv4, input, "IPv4"); } }; } // src/validations/ipv6/ipv6.ts -function ipv6(message = "Invalid IPv6") { +function ipv6(message) { return { type: "ipv6", + expects: null, async: false, message, requirement: IPV6_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, ipv6, input, "IPv6"); } }; } // src/validations/isoDate/isoDate.ts -function isoDate(message = "Invalid date") { +function isoDate(message) { return { type: "iso_date", + expects: null, async: false, message, requirement: ISO_DATE_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, isoDate, input, "date"); } }; } // src/validations/isoDateTime/isoDateTime.ts -function isoDateTime(message = "Invalid date-time") { +function isoDateTime(message) { return { type: "iso_date_time", + expects: null, async: false, message, requirement: ISO_DATE_TIME_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, isoDateTime, input, "date-time"); } }; } // src/validations/isoTime/isoTime.ts -function isoTime(message = "Invalid time") { +function isoTime(message) { return { type: "iso_time", + expects: null, async: false, message, requirement: ISO_TIME_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, isoTime, input, "time"); } }; } // src/validations/isoTimeSecond/isoTimeSecond.ts -function isoTimeSecond(message = "Invalid time second") { +function isoTimeSecond(message) { return { type: "iso_time_second", + expects: null, async: false, message, requirement: ISO_TIME_SECOND_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, isoTimeSecond, input, "time second"); } }; } // src/validations/isoTimestamp/isoTimestamp.ts -function isoTimestamp(message = "Invalid timestamp") { +function isoTimestamp(message) { return { type: "iso_timestamp", + expects: null, async: false, message, requirement: ISO_TIMESTAMP_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, isoTimestamp, input, "timestamp"); } }; } // src/validations/isoWeek/isoWeek.ts -function isoWeek(message = "Invalid week") { +function isoWeek(message) { return { type: "iso_week", + expects: null, async: false, message, requirement: ISO_WEEK_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, isoWeek, input, "week"); } }; } // src/validations/length/length.ts -function length(requirement, message = "Invalid length") { +function length(requirement, message) { return { type: "length", + expects: `${requirement}`, async: false, message, requirement, _parse(input) { - return input.length !== this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.length === this.requirement) { + return actionOutput(input); + } + return actionIssue(this, length, input, "length", `${input.length}`); } }; } // src/validations/mac/mac.ts -function mac(message = "Invalid MAC") { +function mac(message) { return { type: "mac", + expects: null, async: false, message, + // TODO: It is strange that we have an OR relationship between requirements requirement: [MAC48_REGEX, MAC64_REGEX], _parse(input) { - return !this.requirement[0].test(input) && !this.requirement[1].test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement[0].test(input) || this.requirement[1].test(input)) { + return actionOutput(input); + } + return actionIssue(this, mac, input, "MAC"); } }; } // src/validations/mac48/mac48.ts -function mac48(message = "Invalid 48 bit MAC") { +function mac48(message) { return { type: "mac48", + expects: null, async: false, message, requirement: MAC48_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, mac48, input, "48-bit MAC"); } }; } // src/validations/mac64/mac64.ts -function mac64(message = "Invalid 64 bit MAC") { +function mac64(message) { return { type: "mac64", + expects: null, async: false, message, requirement: MAC64_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, mac64, input, "64-bit MAC"); } }; } // src/validations/maxBytes/maxBytes.ts -function maxBytes(requirement, message = "Invalid byte length") { +function maxBytes(requirement, message) { return { type: "max_bytes", + expects: `<=${requirement}`, async: false, message, requirement, _parse(input) { - return new TextEncoder().encode(input).length > this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + const length2 = new TextEncoder().encode(input).length; + if (length2 <= this.requirement) { + return actionOutput(input); + } + return actionIssue(this, maxBytes, input, "bytes", `${length2}`); } }; } // src/validations/maxLength/maxLength.ts -function maxLength(requirement, message = "Invalid length") { +function maxLength(requirement, message) { return { type: "max_length", + expects: `<=${requirement}`, async: false, message, requirement, _parse(input) { - return input.length > this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.length <= this.requirement) { + return actionOutput(input); + } + return actionIssue(this, maxLength, input, "length", `${input.length}`); } }; } // src/validations/maxSize/maxSize.ts -function maxSize(requirement, message = "Invalid size") { +function maxSize(requirement, message) { return { type: "max_size", + expects: `<=${requirement}`, async: false, message, requirement, _parse(input) { - return input.size > this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.size <= this.requirement) { + return actionOutput(input); + } + return actionIssue(this, maxSize, input, "size", `${input.size}`); } }; } // src/validations/maxValue/maxValue.ts -function maxValue(requirement, message = "Invalid value") { +function maxValue(requirement, message) { return { type: "max_value", + expects: `<=${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`, async: false, message, requirement, _parse(input) { - return input > this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input <= this.requirement) { + return actionOutput(input); + } + return actionIssue( + this, + maxValue, + input, + "value", + input instanceof Date ? input.toJSON() : stringify(input) + ); } }; } var maxRange = maxValue; // src/validations/minBytes/minBytes.ts -function minBytes(requirement, message = "Invalid byte length") { +function minBytes(requirement, message) { return { type: "min_bytes", + expects: `>=${requirement}`, async: false, message, requirement, _parse(input) { - return new TextEncoder().encode(input).length < this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + const length2 = new TextEncoder().encode(input).length; + if (length2 >= this.requirement) { + return actionOutput(input); + } + return actionIssue(this, minBytes, input, "bytes", `${length2}`); } }; } // src/validations/mimeType/mimeType.ts -function mimeType(requirement, message = "Invalid MIME type") { +function mimeType(requirement, message) { return { type: "mime_type", + expects: requirement.map((option) => `"${option}"`).join(" | "), async: false, message, requirement, _parse(input) { - return !this.requirement.includes(input.type) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.includes(input.type)) { + return actionOutput(input); + } + return actionIssue(this, mimeType, input, "MIME type"); } }; } // src/validations/minLength/minLength.ts -function minLength(requirement, message = "Invalid length") { +function minLength(requirement, message) { return { type: "min_length", + expects: `>=${requirement}`, async: false, message, requirement, _parse(input) { - return input.length < this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.length >= this.requirement) { + return actionOutput(input); + } + return actionIssue(this, minLength, input, "length", `${input.length}`); } }; } // src/validations/minSize/minSize.ts -function minSize(requirement, message = "Invalid size") { +function minSize(requirement, message) { return { type: "min_size", + expects: `>=${requirement}`, async: false, message, requirement, _parse(input) { - return input.size < this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.size >= this.requirement) { + return actionOutput(input); + } + return actionIssue(this, minSize, input, "size", `${input.size}`); } }; } // src/validations/minValue/minValue.ts -function minValue(requirement, message = "Invalid value") { +function minValue(requirement, message) { return { type: "min_value", + expects: `>=${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`, async: false, message, requirement, _parse(input) { - return input < this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input >= this.requirement) { + return actionOutput(input); + } + return actionIssue( + this, + minValue, + input, + "value", + input instanceof Date ? input.toJSON() : stringify(input) + ); } }; } var minRange = minValue; // src/validations/multipleOf/multipleOf.ts -function multipleOf(requirement, message = "Invalid multiple") { +function multipleOf(requirement, message) { return { type: "multiple_of", + expects: `%${requirement}`, async: false, message, requirement, _parse(input) { - return input % this.requirement !== 0 ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input % this.requirement === 0) { + return actionOutput(input); + } + return actionIssue(this, multipleOf, input, "multiple", `${input}`); } }; } // src/validations/notBytes/notBytes.ts -function notBytes(requirement, message = "Invalid byte length") { +function notBytes(requirement, message) { return { type: "not_bytes", + expects: `!${requirement}`, async: false, message, requirement, _parse(input) { - return new TextEncoder().encode(input).length === this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + const length2 = new TextEncoder().encode(input).length; + if (length2 !== this.requirement) { + return actionOutput(input); + } + return actionIssue(this, notBytes, input, "bytes", `${length2}`); } }; } // src/validations/notLength/notLength.ts -function notLength(requirement, message = "Invalid length") { +function notLength(requirement, message) { return { type: "not_length", + expects: `!${requirement}`, async: false, message, requirement, _parse(input) { - return input.length === this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.length !== this.requirement) { + return actionOutput(input); + } + return actionIssue(this, notLength, input, "length", `${input.length}`); } }; } // src/validations/notSize/notSize.ts -function notSize(requirement, message = "Invalid size") { +function notSize(requirement, message) { return { type: "not_size", + expects: `!${requirement}`, async: false, message, requirement, _parse(input) { - return input.size === this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.size !== this.requirement) { + return actionOutput(input); + } + return actionIssue(this, notSize, input, "size", `${input.size}`); } }; } // src/validations/notValue/notValue.ts -function notValue(requirement, message = "Invalid value") { +function notValue(requirement, message) { return { type: "not_value", + expects: `!${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`, async: false, message, requirement, _parse(input) { - return input === this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input < this.requirement || input > this.requirement) { + return actionOutput(input); + } + return actionIssue( + this, + notValue, + input, + "value", + input instanceof Date ? input.toJSON() : stringify(input) + ); } }; } // src/validations/octal/octal.ts -function octal(message = "Invalid octal") { +function octal(message) { return { type: "octal", + expects: null, async: false, message, requirement: OCTAL_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, octal, input, "octal"); } }; } // src/validations/regex/regex.ts -function regex(requirement, message = "Invalid regex") { +function regex(requirement, message) { return { type: "regex", + expects: `${requirement}`, async: false, message, requirement, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, regex, input, "format"); } }; } // src/validations/safeInteger/safeInteger.ts -function safeInteger(message = "Invalid safe integer") { +function safeInteger(message) { return { type: "safe_integer", + expects: null, async: false, message, requirement: Number.isSafeInteger, _parse(input) { - return !this.requirement(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement(input)) { + return actionOutput(input); + } + return actionIssue(this, safeInteger, input, "safe integer"); } }; } // src/validations/size/size.ts -function size(requirement, message = "Invalid size") { +function size(requirement, message) { return { type: "size", + expects: `${requirement}`, async: false, message, requirement, _parse(input) { - return input.size !== this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.size === this.requirement) { + return actionOutput(input); + } + return actionIssue(this, size, input, "size", `${input.size}`); } }; } // src/validations/startsWith/startsWith.ts -function startsWith(requirement, message = "Invalid start") { +function startsWith(requirement, message) { return { type: "starts_with", + expects: `"${requirement}"`, async: false, message, requirement, _parse(input) { - return !input.startsWith(this.requirement) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input.startsWith(this.requirement)) { + return actionOutput(input); + } + return actionIssue( + this, + startsWith, + input, + "start", + `"${input.slice(0, this.requirement.length)}"` + ); } }; } // src/validations/ulid/ulid.ts -function ulid(message = "Invalid ULID") { +function ulid(message) { return { type: "ulid", + expects: null, async: false, message, requirement: ULID_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, ulid, input, "ULID"); } }; } // src/validations/url/url.ts -function url(message = "Invalid URL") { +function url(message) { return { type: "url", + expects: null, async: false, message, requirement(input) { @@ -35744,33 +36184,50 @@ function url(message = "Invalid URL") { } }, _parse(input) { - return !this.requirement(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement(input)) { + return actionOutput(input); + } + return actionIssue(this, url, input, "URL"); } }; } // src/validations/uuid/uuid.ts -function uuid(message = "Invalid UUID") { +function uuid(message) { return { type: "uuid", + expects: null, async: false, message, requirement: UUID_REGEX, _parse(input) { - return !this.requirement.test(input) ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (this.requirement.test(input)) { + return actionOutput(input); + } + return actionIssue(this, uuid, input, "UUID"); } }; } // src/validations/value/value.ts -function value(requirement, message = "Invalid value") { +function value(requirement, message) { return { type: "value", + expects: `${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`, async: false, message, requirement, _parse(input) { - return input !== this.requirement ? actionIssue(this.type, this.message, input, this.requirement) : actionOutput(input); + if (input <= this.requirement && input >= this.requirement) { + return actionOutput(input); + } + return actionIssue( + this, + value, + input, + "value", + input instanceof Date ? input.toJSON() : stringify(input) + ); } }; }