feat(planning): grille hebdomadaire complète avec API et filtres

- Connexion API via proxy Angular (résolution CORS, base path /api)
- Import CSS ng-zorro global pour les modales et composants
- Filtres Camion/Show câblés sur l'affichage de la grille
- Camions affichés via TrucksService (linkés au show du même créneau)
- Panneau de détails : spectacles + camions du jour sélectionné
- Modale de création de spectacle stylisée avec fond et centrage
- Positionnement précis des events à la minute dans leur créneau
- Auto-scroll vers l'heure courante au chargement
- Ligne "maintenant" sur la colonne du jour actuel
- Régénération des services OpenAPI (nouveaux noms de types)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 20:36:03 +02:00
parent 150b97cd2e
commit 654b297e2e
3131 changed files with 149304 additions and 104334 deletions
+198 -435
View File
@@ -1,7 +1,7 @@
import * as checks from "./checks.js";
import * as core from "./core.js";
import { Doc } from "./doc.js";
import { parse, parseAsync, safeParse, safeParseAsync } from "./parse.js";
import { safeParse, safeParseAsync } from "./parse.js";
import * as regexes from "./regexes.js";
import * as util from "./util.js";
import { version } from "./versions.js";
@@ -16,6 +16,7 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
if (inst._zod.traits.has("$ZodCheck")) {
checks.unshift(inst);
}
//
for (const ch of checks) {
for (const fn of ch._zod.onattach) {
fn(inst);
@@ -72,47 +73,7 @@ export const $ZodType = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def)
}
return payload;
};
// const handleChecksResult = (
// checkResult: ParsePayload,
// originalResult: ParsePayload,
// ctx: ParseContextInternal
// ): util.MaybeAsync<ParsePayload> => {
// // if the checks mutated the value && there are no issues, re-parse the result
// if (checkResult.value !== originalResult.value && !checkResult.issues.length)
// return inst._zod.parse(checkResult, ctx);
// return originalResult;
// };
const handleCanaryResult = (canary, payload, ctx) => {
// abort if the canary is aborted
if (util.aborted(canary)) {
canary.aborted = true;
return canary;
}
// run checks first, then
const checkResult = runChecks(payload, checks, ctx);
if (checkResult instanceof Promise) {
if (ctx.async === false)
throw new core.$ZodAsyncError();
return checkResult.then((checkResult) => inst._zod.parse(checkResult, ctx));
}
return inst._zod.parse(checkResult, ctx);
};
inst._zod.run = (payload, ctx) => {
if (ctx.skipChecks) {
return inst._zod.parse(payload, ctx);
}
if (ctx.direction === "backward") {
// run canary
// initial pass (no checks)
const canary = inst._zod.parse({ value: payload.value, issues: [] }, { ...ctx, skipChecks: true });
if (canary instanceof Promise) {
return canary.then((canary) => {
return handleCanaryResult(canary, payload, ctx);
});
}
return handleCanaryResult(canary, payload, ctx);
}
// forward
const result = inst._zod.parse(payload, ctx);
if (result instanceof Promise) {
if (ctx.async === false)
@@ -195,10 +156,9 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
try {
// Trim whitespace from input
const trimmed = payload.value.trim();
// @ts-ignore
const url = new URL(trimmed);
const orig = payload.value;
const url = new URL(orig);
const href = url.href;
if (def.hostname) {
def.hostname.lastIndex = 0;
if (!def.hostname.test(url.hostname)) {
@@ -206,7 +166,7 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
code: "invalid_format",
format: "url",
note: "Invalid hostname",
pattern: def.hostname.source,
pattern: regexes.hostname.source,
input: payload.value,
inst,
continue: !def.abort,
@@ -227,14 +187,12 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
});
}
}
// Set the output value based on normalize flag
if (def.normalize) {
// Use normalized URL
payload.value = url.href;
// payload.value = url.href;
if (!orig.endsWith("/") && href.endsWith("/")) {
payload.value = href.slice(0, -1);
}
else {
// Preserve the original input (trimmed)
payload.value = trimmed;
payload.value = href;
}
return;
}
@@ -296,15 +254,20 @@ export const $ZodISODuration = /*@__PURE__*/ core.$constructor("$ZodISODuration"
export const $ZodIPv4 = /*@__PURE__*/ core.$constructor("$ZodIPv4", (inst, def) => {
def.pattern ?? (def.pattern = regexes.ipv4);
$ZodStringFormat.init(inst, def);
inst._zod.bag.format = `ipv4`;
inst._zod.onattach.push((inst) => {
const bag = inst._zod.bag;
bag.format = `ipv4`;
});
});
export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def) => {
def.pattern ?? (def.pattern = regexes.ipv6);
$ZodStringFormat.init(inst, def);
inst._zod.bag.format = `ipv6`;
inst._zod.onattach.push((inst) => {
const bag = inst._zod.bag;
bag.format = `ipv6`;
});
inst._zod.check = (payload) => {
try {
// @ts-ignore
new URL(`http://[${payload.value}]`);
// return;
}
@@ -319,11 +282,6 @@ export const $ZodIPv6 = /*@__PURE__*/ core.$constructor("$ZodIPv6", (inst, def)
}
};
});
export const $ZodMAC = /*@__PURE__*/ core.$constructor("$ZodMAC", (inst, def) => {
def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
$ZodStringFormat.init(inst, def);
inst._zod.bag.format = `mac`;
});
export const $ZodCIDRv4 = /*@__PURE__*/ core.$constructor("$ZodCIDRv4", (inst, def) => {
def.pattern ?? (def.pattern = regexes.cidrv4);
$ZodStringFormat.init(inst, def);
@@ -332,11 +290,8 @@ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, d
def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
$ZodStringFormat.init(inst, def);
inst._zod.check = (payload) => {
const parts = payload.value.split("/");
const [address, prefix] = payload.value.split("/");
try {
if (parts.length !== 2)
throw new Error();
const [address, prefix] = parts;
if (!prefix)
throw new Error();
const prefixNum = Number(prefix);
@@ -344,7 +299,6 @@ export const $ZodCIDRv6 = /*@__PURE__*/ core.$constructor("$ZodCIDRv6", (inst, d
throw new Error();
if (prefixNum < 0 || prefixNum > 128)
throw new Error();
// @ts-ignore
new URL(`http://[${address}]`);
}
catch {
@@ -365,7 +319,6 @@ export function isValidBase64(data) {
if (data.length % 4 !== 0)
return false;
try {
// @ts-ignore
atob(data);
return true;
}
@@ -376,7 +329,9 @@ export function isValidBase64(data) {
export const $ZodBase64 = /*@__PURE__*/ core.$constructor("$ZodBase64", (inst, def) => {
def.pattern ?? (def.pattern = regexes.base64);
$ZodStringFormat.init(inst, def);
inst._zod.bag.contentEncoding = "base64";
inst._zod.onattach.push((inst) => {
inst._zod.bag.contentEncoding = "base64";
});
inst._zod.check = (payload) => {
if (isValidBase64(payload.value))
return;
@@ -400,7 +355,9 @@ export function isValidBase64URL(data) {
export const $ZodBase64URL = /*@__PURE__*/ core.$constructor("$ZodBase64URL", (inst, def) => {
def.pattern ?? (def.pattern = regexes.base64url);
$ZodStringFormat.init(inst, def);
inst._zod.bag.contentEncoding = "base64url";
inst._zod.onattach.push((inst) => {
inst._zod.bag.contentEncoding = "base64url";
});
inst._zod.check = (payload) => {
if (isValidBase64URL(payload.value))
return;
@@ -426,7 +383,6 @@ export function isValidJWT(token, algorithm = null) {
const [header] = tokensParts;
if (!header)
return false;
// @ts-ignore
const parsedHeader = JSON.parse(atob(header));
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
return false;
@@ -498,9 +454,9 @@ export const $ZodNumber = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, d
return payload;
};
});
export const $ZodNumberFormat = /*@__PURE__*/ core.$constructor("$ZodNumberFormat", (inst, def) => {
export const $ZodNumberFormat = /*@__PURE__*/ core.$constructor("$ZodNumber", (inst, def) => {
checks.$ZodCheckNumberFormat.init(inst, def);
$ZodNumber.init(inst, def); // no format checks
$ZodNumber.init(inst, def); // no format checksp
});
export const $ZodBoolean = /*@__PURE__*/ core.$constructor("$ZodBoolean", (inst, def) => {
$ZodType.init(inst, def);
@@ -543,7 +499,7 @@ export const $ZodBigInt = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, d
return payload;
};
});
export const $ZodBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodBigIntFormat", (inst, def) => {
export const $ZodBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, def) => {
checks.$ZodCheckBigIntFormat.init(inst, def);
$ZodBigInt.init(inst, def); // no format checks
});
@@ -697,88 +653,58 @@ export const $ZodArray = /*@__PURE__*/ core.$constructor("$ZodArray", (inst, def
return payload; //handleArrayResultsAsync(parseResults, final);
};
});
function handlePropertyResult(result, final, key, input) {
function handleObjectResult(result, final, key) {
// if(isOptional)
if (result.issues.length) {
final.issues.push(...util.prefixIssues(key, result.issues));
}
if (result.value === undefined) {
if (key in input) {
final.value[key] = undefined;
}
}
else {
final.value[key] = result.value;
}
final.value[key] = result.value;
}
function normalizeDef(def) {
const keys = Object.keys(def.shape);
for (const k of keys) {
if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) {
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
}
}
const okeys = util.optionalKeys(def.shape);
return {
...def,
keys,
keySet: new Set(keys),
numKeys: keys.length,
optionalKeys: new Set(okeys),
};
}
function handleCatchall(proms, input, payload, ctx, def, inst) {
const unrecognized = [];
// iterate over input keys
const keySet = def.keySet;
const _catchall = def.catchall._zod;
const t = _catchall.def.type;
for (const key in input) {
if (keySet.has(key))
continue;
if (t === "never") {
unrecognized.push(key);
continue;
}
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
if (r instanceof Promise) {
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
function handleOptionalObjectResult(result, final, key, input) {
if (result.issues.length) {
// validation failed against value schema
if (input[key] === undefined) {
// if input was undefined, ignore the error
if (key in input) {
final.value[key] = undefined;
}
else {
final.value[key] = result.value;
}
}
else {
handlePropertyResult(r, payload, key, input);
final.issues.push(...util.prefixIssues(key, result.issues));
}
}
if (unrecognized.length) {
payload.issues.push({
code: "unrecognized_keys",
keys: unrecognized,
input,
inst,
});
else if (result.value === undefined) {
// validation returned `undefined`
if (key in input)
final.value[key] = undefined;
}
else {
// non-undefined value
final.value[key] = result.value;
}
if (!proms.length)
return payload;
return Promise.all(proms).then(() => {
return payload;
});
}
export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, def) => {
// requires cast because technically $ZodObject doesn't extend
$ZodType.init(inst, def);
// const sh = def.shape;
const desc = Object.getOwnPropertyDescriptor(def, "shape");
if (!desc?.get) {
const sh = def.shape;
Object.defineProperty(def, "shape", {
get: () => {
const newSh = { ...sh };
Object.defineProperty(def, "shape", {
value: newSh,
});
return newSh;
},
});
}
const _normalized = util.cached(() => normalizeDef(def));
const _normalized = util.cached(() => {
const keys = Object.keys(def.shape);
for (const k of keys) {
if (!(def.shape[k] instanceof $ZodType)) {
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
}
}
const okeys = util.optionalKeys(def.shape);
return {
shape: def.shape,
keys,
keySet: new Set(keys),
numKeys: keys.length,
optionalKeys: new Set(okeys),
};
});
util.defineLazy(inst._zod, "propValues", () => {
const shape = def.shape;
const propValues = {};
@@ -792,45 +718,6 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
}
return propValues;
});
const isObject = util.isObject;
const catchall = def.catchall;
let value;
inst._zod.parse = (payload, ctx) => {
value ?? (value = _normalized.value);
const input = payload.value;
if (!isObject(input)) {
payload.issues.push({
expected: "object",
code: "invalid_type",
input,
inst,
});
return payload;
}
payload.value = {};
const proms = [];
const shape = value.shape;
for (const key of value.keys) {
const el = shape[key];
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
if (r instanceof Promise) {
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input)));
}
else {
handlePropertyResult(r, payload, key, input);
}
}
if (!catchall) {
return proms.length ? Promise.all(proms).then(() => payload) : payload;
}
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
};
});
export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (inst, def) => {
// requires cast because technically $ZodObject doesn't extend
$ZodObject.init(inst, def);
const superParse = inst._zod.parse;
const _normalized = util.cached(() => normalizeDef(def));
const generateFastpass = (shape) => {
const doc = new Doc(["shape", "payload", "ctx"]);
const normalized = _normalized.value;
@@ -845,29 +732,44 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
ids[key] = `key_${counter++}`;
}
// A: preserve key order {
doc.write(`const newResult = {};`);
doc.write(`const newResult = {}`);
for (const key of normalized.keys) {
const id = ids[key];
const k = util.esc(key);
doc.write(`const ${id} = ${parseStr(key)};`);
doc.write(`
if (normalized.optionalKeys.has(key)) {
const id = ids[key];
doc.write(`const ${id} = ${parseStr(key)};`);
const k = util.esc(key);
doc.write(`
if (${id}.issues.length) {
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
...iss,
path: iss.path ? [${k}, ...iss.path] : [${k}]
})));
}
if (${id}.value === undefined) {
if (${k} in input) {
newResult[${k}] = undefined;
if (input[${k}] === undefined) {
if (${k} in input) {
newResult[${k}] = undefined;
}
} else {
payload.issues = payload.issues.concat(
${id}.issues.map((iss) => ({
...iss,
path: iss.path ? [${k}, ...iss.path] : [${k}],
}))
);
}
} else if (${id}.value === undefined) {
if (${k} in input) newResult[${k}] = undefined;
} else {
newResult[${k}] = ${id}.value;
}
`);
`);
}
else {
const id = ids[key];
// const id = ids[key];
doc.write(`const ${id} = ${parseStr(key)};`);
doc.write(`
if (${id}.issues.length) payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
...iss,
path: iss.path ? [${util.esc(key)}, ...iss.path] : [${util.esc(key)}]
})));`);
doc.write(`newResult[${util.esc(key)}] = ${id}.value`);
}
}
doc.write(`payload.value = newResult;`);
doc.write(`return payload;`);
@@ -893,16 +795,80 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
});
return payload;
}
const proms = [];
if (jit && fastEnabled && ctx?.async === false && ctx.jitless !== true) {
// always synchronous
if (!fastpass)
fastpass = generateFastpass(def.shape);
payload = fastpass(payload, ctx);
if (!catchall)
return payload;
return handleCatchall([], input, payload, ctx, value, inst);
}
return superParse(payload, ctx);
else {
payload.value = {};
const shape = value.shape;
for (const key of value.keys) {
const el = shape[key];
// do not add omitted optional keys
// if (!(key in input)) {
// if (optionalKeys.has(key)) continue;
// payload.issues.push({
// code: "invalid_type",
// path: [key],
// expected: "nonoptional",
// note: `Missing required key: "${key}"`,
// input,
// inst,
// });
// }
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
const isOptional = el._zod.optin === "optional" && el._zod.optout === "optional";
if (r instanceof Promise) {
proms.push(r.then((r) => isOptional ? handleOptionalObjectResult(r, payload, key, input) : handleObjectResult(r, payload, key)));
}
else if (isOptional) {
handleOptionalObjectResult(r, payload, key, input);
}
else {
handleObjectResult(r, payload, key);
}
}
}
if (!catchall) {
// return payload;
return proms.length ? Promise.all(proms).then(() => payload) : payload;
}
const unrecognized = [];
// iterate over input keys
const keySet = value.keySet;
const _catchall = catchall._zod;
const t = _catchall.def.type;
for (const key of Object.keys(input)) {
if (keySet.has(key))
continue;
if (t === "never") {
unrecognized.push(key);
continue;
}
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
if (r instanceof Promise) {
proms.push(r.then((r) => handleObjectResult(r, payload, key)));
}
else {
handleObjectResult(r, payload, key);
}
}
if (unrecognized.length) {
payload.issues.push({
code: "unrecognized_keys",
keys: unrecognized,
input,
inst,
});
}
if (!proms.length)
return payload;
return Promise.all(proms).then(() => {
return payload;
});
};
});
function handleUnionResults(results, final, inst, ctx) {
@@ -912,11 +878,6 @@ function handleUnionResults(results, final, inst, ctx) {
return final;
}
}
const nonaborted = results.filter((r) => !util.aborted(r));
if (nonaborted.length === 1) {
final.value = nonaborted[0].value;
return nonaborted[0];
}
final.issues.push({
code: "invalid_union",
input: final.value,
@@ -942,12 +903,7 @@ export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def
}
return undefined;
});
const single = def.options.length === 1;
const first = def.options[0]._zod.run;
inst._zod.parse = (payload, ctx) => {
if (single) {
return first(payload, ctx);
}
let async = false;
const results = [];
for (const option of def.options) {
@@ -997,7 +953,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
const opts = def.options;
const map = new Map();
for (const o of opts) {
const values = o._zod.propValues?.[def.discriminator];
const values = o._zod.propValues[def.discriminator];
if (!values || values.size === 0)
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
for (const v of values) {
@@ -1032,7 +988,6 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
code: "invalid_union",
errors: [],
note: "No matching discriminator",
discriminator: def.discriminator,
input,
path: [def.discriminator],
inst,
@@ -1120,6 +1075,7 @@ function handleIntersectionResults(result, left, right) {
export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def) => {
$ZodType.init(inst, def);
const items = def.items;
const optStart = items.length - [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
inst._zod.parse = (payload, ctx) => {
const input = payload.value;
if (!Array.isArray(input)) {
@@ -1133,17 +1089,15 @@ export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def
}
payload.value = [];
const proms = [];
const reversedIndex = [...items].reverse().findIndex((item) => item._zod.optin !== "optional");
const optStart = reversedIndex === -1 ? 0 : items.length - reversedIndex;
if (!def.rest) {
const tooBig = input.length > items.length;
const tooSmall = input.length < optStart - 1;
if (tooBig || tooSmall) {
payload.issues.push({
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
input,
inst,
origin: "array",
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
});
return payload;
}
@@ -1206,13 +1160,11 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
return payload;
}
const proms = [];
const values = def.keyType._zod.values;
if (values) {
if (def.keyType._zod.values) {
const values = def.keyType._zod.values;
payload.value = {};
const recordKeys = new Set();
for (const key of values) {
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
recordKeys.add(typeof key === "number" ? key.toString() : key);
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
if (result instanceof Promise) {
proms.push(result.then((result) => {
@@ -1232,7 +1184,7 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
}
let unrecognized;
for (const key in input) {
if (!recordKeys.has(key)) {
if (!values.has(key)) {
unrecognized = unrecognized ?? [];
unrecognized.push(key);
}
@@ -1257,8 +1209,8 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
}
if (keyResult.issues.length) {
payload.issues.push({
code: "invalid_key",
origin: "record",
code: "invalid_key",
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
input: key,
path: [key],
@@ -1329,8 +1281,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
}
else {
final.issues.push({
code: "invalid_key",
origin: "map",
code: "invalid_key",
input,
inst,
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
@@ -1391,15 +1343,14 @@ function handleSetResult(result, final) {
export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def) => {
$ZodType.init(inst, def);
const values = util.getEnumValues(def.entries);
const valuesSet = new Set(values);
inst._zod.values = valuesSet;
inst._zod.values = new Set(values);
inst._zod.pattern = new RegExp(`^(${values
.filter((k) => util.propertyKeyTypes.has(typeof k))
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o.toString()))
.join("|")})$`);
inst._zod.parse = (payload, _ctx) => {
const input = payload.value;
if (valuesSet.has(input)) {
if (inst._zod.values.has(input)) {
return payload;
}
payload.issues.push({
@@ -1413,17 +1364,13 @@ export const $ZodEnum = /*@__PURE__*/ core.$constructor("$ZodEnum", (inst, def)
});
export const $ZodLiteral = /*@__PURE__*/ core.$constructor("$ZodLiteral", (inst, def) => {
$ZodType.init(inst, def);
if (def.values.length === 0) {
throw new Error("Cannot create literal schema with no valid values");
}
const values = new Set(def.values);
inst._zod.values = values;
inst._zod.values = new Set(def.values);
inst._zod.pattern = new RegExp(`^(${def.values
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
.map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? o.toString() : String(o)))
.join("|")})$`);
inst._zod.parse = (payload, _ctx) => {
const input = payload.value;
if (values.has(input)) {
if (inst._zod.values.has(input)) {
return payload;
}
payload.issues.push({
@@ -1439,7 +1386,6 @@ export const $ZodFile = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def)
$ZodType.init(inst, def);
inst._zod.parse = (payload, _ctx) => {
const input = payload.value;
// @ts-ignore
if (input instanceof File)
return payload;
payload.issues.push({
@@ -1453,12 +1399,9 @@ export const $ZodFile = /*@__PURE__*/ core.$constructor("$ZodFile", (inst, def)
});
export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
throw new core.$ZodEncodeError(inst.constructor.name);
}
inst._zod.parse = (payload, _ctx) => {
const _out = def.transform(payload.value, payload);
if (ctx.async) {
if (_ctx.async) {
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
return output.then((output) => {
payload.value = output;
@@ -1472,12 +1415,6 @@ export const $ZodTransform = /*@__PURE__*/ core.$constructor("$ZodTransform", (i
return payload;
};
});
function handleOptionalResult(result, input) {
if (result.issues.length && input === undefined) {
return { issues: [], value: undefined };
}
return result;
}
export const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.optin = "optional";
@@ -1491,10 +1428,7 @@ export const $ZodOptional = /*@__PURE__*/ core.$constructor("$ZodOptional", (ins
});
inst._zod.parse = (payload, ctx) => {
if (def.innerType._zod.optin === "optional") {
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise)
return result.then((r) => handleOptionalResult(r, payload.value));
return handleOptionalResult(result, payload.value);
return def.innerType._zod.run(payload, ctx);
}
if (payload.value === undefined) {
return payload;
@@ -1514,7 +1448,6 @@ export const $ZodNullable = /*@__PURE__*/ core.$constructor("$ZodNullable", (ins
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : undefined;
});
inst._zod.parse = (payload, ctx) => {
// Forward direction (decode): allow null to pass through
if (payload.value === null)
return payload;
return def.innerType._zod.run(payload, ctx);
@@ -1526,18 +1459,13 @@ export const $ZodDefault = /*@__PURE__*/ core.$constructor("$ZodDefault", (inst,
inst._zod.optin = "optional";
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
return def.innerType._zod.run(payload, ctx);
}
// Forward direction (decode): apply defaults for undefined input
if (payload.value === undefined) {
payload.value = def.defaultValue;
/**
* $ZodDefault returns the default value immediately in forward direction.
* $ZodDefault always returns the default value immediately.
* It doesn't pass the default value into the validator ("prefault"). There's no reason to pass the default value through validation. The validity of the default is enforced by TypeScript statically. Otherwise, it's the responsibility of the user to ensure the default is valid. In the case of pipes with divergent in/out types, you can specify the default on the `in` schema of your ZodPipe to set a "prefault" for the pipe. */
return payload;
}
// Forward direction: continue with default handling
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise) {
return result.then((result) => handleDefaultResult(result, def));
@@ -1556,10 +1484,6 @@ export const $ZodPrefault = /*@__PURE__*/ core.$constructor("$ZodPrefault", (ins
inst._zod.optin = "optional";
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
return def.innerType._zod.run(payload, ctx);
}
// Forward direction (decode): apply prefault for undefined input
if (payload.value === undefined) {
payload.value = def.defaultValue;
}
@@ -1594,9 +1518,6 @@ function handleNonOptionalResult(payload, inst) {
export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
throw new core.$ZodEncodeError("ZodSuccess");
}
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise) {
return result.then((result) => {
@@ -1610,14 +1531,10 @@ export const $ZodSuccess = /*@__PURE__*/ core.$constructor("$ZodSuccess", (inst,
});
export const $ZodCatch = /*@__PURE__*/ core.$constructor("$ZodCatch", (inst, def) => {
$ZodType.init(inst, def);
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
inst._zod.optin = "optional";
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
return def.innerType._zod.run(payload, ctx);
}
// Forward direction (decode): apply catch logic
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise) {
return result.then((result) => {
@@ -1669,94 +1586,27 @@ export const $ZodPipe = /*@__PURE__*/ core.$constructor("$ZodPipe", (inst, def)
util.defineLazy(inst._zod, "values", () => def.in._zod.values);
util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
const right = def.out._zod.run(payload, ctx);
if (right instanceof Promise) {
return right.then((right) => handlePipeResult(right, def.in, ctx));
}
return handlePipeResult(right, def.in, ctx);
}
const left = def.in._zod.run(payload, ctx);
if (left instanceof Promise) {
return left.then((left) => handlePipeResult(left, def.out, ctx));
return left.then((left) => handlePipeResult(left, def, ctx));
}
return handlePipeResult(left, def.out, ctx);
return handlePipeResult(left, def, ctx);
};
});
function handlePipeResult(left, next, ctx) {
if (left.issues.length) {
// prevent further checks
left.aborted = true;
function handlePipeResult(left, def, ctx) {
if (util.aborted(left)) {
return left;
}
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
}
export const $ZodCodec = /*@__PURE__*/ core.$constructor("$ZodCodec", (inst, def) => {
$ZodType.init(inst, def);
util.defineLazy(inst._zod, "values", () => def.in._zod.values);
util.defineLazy(inst._zod, "optin", () => def.in._zod.optin);
util.defineLazy(inst._zod, "optout", () => def.out._zod.optout);
util.defineLazy(inst._zod, "propValues", () => def.in._zod.propValues);
inst._zod.parse = (payload, ctx) => {
const direction = ctx.direction || "forward";
if (direction === "forward") {
const left = def.in._zod.run(payload, ctx);
if (left instanceof Promise) {
return left.then((left) => handleCodecAResult(left, def, ctx));
}
return handleCodecAResult(left, def, ctx);
}
else {
const right = def.out._zod.run(payload, ctx);
if (right instanceof Promise) {
return right.then((right) => handleCodecAResult(right, def, ctx));
}
return handleCodecAResult(right, def, ctx);
}
};
});
function handleCodecAResult(result, def, ctx) {
if (result.issues.length) {
// prevent further checks
result.aborted = true;
return result;
}
const direction = ctx.direction || "forward";
if (direction === "forward") {
const transformed = def.transform(result.value, result);
if (transformed instanceof Promise) {
return transformed.then((value) => handleCodecTxResult(result, value, def.out, ctx));
}
return handleCodecTxResult(result, transformed, def.out, ctx);
}
else {
const transformed = def.reverseTransform(result.value, result);
if (transformed instanceof Promise) {
return transformed.then((value) => handleCodecTxResult(result, value, def.in, ctx));
}
return handleCodecTxResult(result, transformed, def.in, ctx);
}
}
function handleCodecTxResult(left, value, nextSchema, ctx) {
// Check if transform added any issues
if (left.issues.length) {
left.aborted = true;
return left;
}
return nextSchema._zod.run({ value, issues: left.issues }, ctx);
return def.out._zod.run({ value: left.value, issues: left.issues }, ctx);
}
export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (inst, def) => {
$ZodType.init(inst, def);
util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
return def.innerType._zod.run(payload, ctx);
}
const result = def.innerType._zod.run(payload, ctx);
if (result instanceof Promise) {
return result.then(handleReadonlyResult);
@@ -1772,8 +1622,7 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
$ZodType.init(inst, def);
const regexParts = [];
for (const part of def.parts) {
if (typeof part === "object" && part !== null) {
// is Zod schema
if (part instanceof $ZodType) {
if (!part._zod.pattern) {
// if (!source)
throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
@@ -1809,7 +1658,7 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
input: payload.value,
inst,
code: "invalid_format",
format: def.format ?? "template_literal",
format: "template_literal",
pattern: inst._zod.pattern.source,
});
return payload;
@@ -1817,85 +1666,6 @@ export const $ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("$ZodTemplate
return payload;
};
});
export const $ZodFunction = /*@__PURE__*/ core.$constructor("$ZodFunction", (inst, def) => {
$ZodType.init(inst, def);
inst._def = def;
inst._zod.def = def;
inst.implement = (func) => {
if (typeof func !== "function") {
throw new Error("implement() must be called with a function");
}
return function (...args) {
const parsedArgs = inst._def.input ? parse(inst._def.input, args) : args;
const result = Reflect.apply(func, this, parsedArgs);
if (inst._def.output) {
return parse(inst._def.output, result);
}
return result;
};
};
inst.implementAsync = (func) => {
if (typeof func !== "function") {
throw new Error("implementAsync() must be called with a function");
}
return async function (...args) {
const parsedArgs = inst._def.input ? await parseAsync(inst._def.input, args) : args;
const result = await Reflect.apply(func, this, parsedArgs);
if (inst._def.output) {
return await parseAsync(inst._def.output, result);
}
return result;
};
};
inst._zod.parse = (payload, _ctx) => {
if (typeof payload.value !== "function") {
payload.issues.push({
code: "invalid_type",
expected: "function",
input: payload.value,
inst,
});
return payload;
}
// Check if output is a promise type to determine if we should use async implementation
const hasPromiseOutput = inst._def.output && inst._def.output._zod.def.type === "promise";
if (hasPromiseOutput) {
payload.value = inst.implementAsync(payload.value);
}
else {
payload.value = inst.implement(payload.value);
}
return payload;
};
inst.input = (...args) => {
const F = inst.constructor;
if (Array.isArray(args[0])) {
return new F({
type: "function",
input: new $ZodTuple({
type: "tuple",
items: args[0],
rest: args[1],
}),
output: inst._def.output,
});
}
return new F({
type: "function",
input: args[0],
output: inst._def.output,
});
};
inst.output = (output) => {
const F = inst.constructor;
return new F({
type: "function",
input: inst._def.input,
output,
});
};
return inst;
});
export const $ZodPromise = /*@__PURE__*/ core.$constructor("$ZodPromise", (inst, def) => {
$ZodType.init(inst, def);
inst._zod.parse = (payload, ctx) => {
@@ -1904,18 +1674,11 @@ export const $ZodPromise = /*@__PURE__*/ core.$constructor("$ZodPromise", (inst,
});
export const $ZodLazy = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def) => {
$ZodType.init(inst, def);
// let _innerType!: any;
// util.defineLazy(def, "getter", () => {
// if (!_innerType) {
// _innerType = def.getter();
// }
// return () => _innerType;
// });
util.defineLazy(inst._zod, "innerType", () => def.getter());
util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType._zod.propValues);
util.defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin);
util.defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout);
inst._zod.parse = (payload, ctx) => {
const inner = inst._zod.innerType;
return inner._zod.run(payload, ctx);