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:
+199
-436
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodUnion = exports.$ZodObjectJIT = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodMAC = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
|
||||
exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodFunction = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodCodec = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = void 0;
|
||||
exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodUnion = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
|
||||
exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = void 0;
|
||||
exports.isValidBase64 = isValidBase64;
|
||||
exports.isValidBase64URL = isValidBase64URL;
|
||||
exports.isValidJWT = isValidJWT;
|
||||
@@ -46,6 +46,7 @@ exports.$ZodType = 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);
|
||||
@@ -102,47 +103,7 @@ exports.$ZodType = 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)
|
||||
@@ -226,10 +187,9 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
|
||||
exports.$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)) {
|
||||
@@ -237,7 +197,7 @@ exports.$ZodURL = 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,
|
||||
@@ -258,14 +218,12 @@ exports.$ZodURL = 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;
|
||||
}
|
||||
@@ -327,15 +285,20 @@ exports.$ZodISODuration = core.$constructor("$ZodISODuration", (inst, def) => {
|
||||
exports.$ZodIPv4 = core.$constructor("$ZodIPv4", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.ipv4);
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `ipv4`;
|
||||
inst._zod.onattach.push((inst) => {
|
||||
const bag = inst._zod.bag;
|
||||
bag.format = `ipv4`;
|
||||
});
|
||||
});
|
||||
exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.ipv6);
|
||||
exports.$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;
|
||||
}
|
||||
@@ -350,11 +313,6 @@ exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
|
||||
}
|
||||
};
|
||||
});
|
||||
exports.$ZodMAC = core.$constructor("$ZodMAC", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
inst._zod.bag.format = `mac`;
|
||||
});
|
||||
exports.$ZodCIDRv4 = core.$constructor("$ZodCIDRv4", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.cidrv4);
|
||||
exports.$ZodStringFormat.init(inst, def);
|
||||
@@ -363,11 +321,8 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.cidrv6); // not used for validation
|
||||
exports.$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);
|
||||
@@ -375,7 +330,6 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
|
||||
throw new Error();
|
||||
if (prefixNum < 0 || prefixNum > 128)
|
||||
throw new Error();
|
||||
// @ts-ignore
|
||||
new URL(`http://[${address}]`);
|
||||
}
|
||||
catch {
|
||||
@@ -396,7 +350,6 @@ function isValidBase64(data) {
|
||||
if (data.length % 4 !== 0)
|
||||
return false;
|
||||
try {
|
||||
// @ts-ignore
|
||||
atob(data);
|
||||
return true;
|
||||
}
|
||||
@@ -407,7 +360,9 @@ function isValidBase64(data) {
|
||||
exports.$ZodBase64 = core.$constructor("$ZodBase64", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.base64);
|
||||
exports.$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;
|
||||
@@ -431,7 +386,9 @@ function isValidBase64URL(data) {
|
||||
exports.$ZodBase64URL = core.$constructor("$ZodBase64URL", (inst, def) => {
|
||||
def.pattern ?? (def.pattern = regexes.base64url);
|
||||
exports.$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;
|
||||
@@ -457,7 +414,6 @@ 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;
|
||||
@@ -529,9 +485,9 @@ exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
exports.$ZodNumberFormat = core.$constructor("$ZodNumberFormat", (inst, def) => {
|
||||
exports.$ZodNumberFormat = core.$constructor("$ZodNumber", (inst, def) => {
|
||||
checks.$ZodCheckNumberFormat.init(inst, def);
|
||||
exports.$ZodNumber.init(inst, def); // no format checks
|
||||
exports.$ZodNumber.init(inst, def); // no format checksp
|
||||
});
|
||||
exports.$ZodBoolean = core.$constructor("$ZodBoolean", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
@@ -574,7 +530,7 @@ exports.$ZodBigInt = core.$constructor("$ZodBigInt", (inst, def) => {
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
exports.$ZodBigIntFormat = core.$constructor("$ZodBigIntFormat", (inst, def) => {
|
||||
exports.$ZodBigIntFormat = core.$constructor("$ZodBigInt", (inst, def) => {
|
||||
checks.$ZodCheckBigIntFormat.init(inst, def);
|
||||
exports.$ZodBigInt.init(inst, def); // no format checks
|
||||
});
|
||||
@@ -728,88 +684,58 @@ exports.$ZodArray = 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;
|
||||
});
|
||||
}
|
||||
exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
|
||||
// requires cast because technically $ZodObject doesn't extend
|
||||
exports.$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 exports.$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 = {};
|
||||
@@ -823,45 +749,6 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
|
||||
}
|
||||
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);
|
||||
};
|
||||
});
|
||||
exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
||||
// requires cast because technically $ZodObject doesn't extend
|
||||
exports.$ZodObject.init(inst, def);
|
||||
const superParse = inst._zod.parse;
|
||||
const _normalized = util.cached(() => normalizeDef(def));
|
||||
const generateFastpass = (shape) => {
|
||||
const doc = new doc_js_1.Doc(["shape", "payload", "ctx"]);
|
||||
const normalized = _normalized.value;
|
||||
@@ -876,29 +763,44 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
||||
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;`);
|
||||
@@ -924,16 +826,80 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
|
||||
});
|
||||
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) {
|
||||
@@ -943,11 +909,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,
|
||||
@@ -973,12 +934,7 @@ exports.$ZodUnion = 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) {
|
||||
@@ -1028,7 +984,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) {
|
||||
@@ -1063,7 +1019,6 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
||||
code: "invalid_union",
|
||||
errors: [],
|
||||
note: "No matching discriminator",
|
||||
discriminator: def.discriminator,
|
||||
input,
|
||||
path: [def.discriminator],
|
||||
inst,
|
||||
@@ -1151,6 +1106,7 @@ function handleIntersectionResults(result, left, right) {
|
||||
exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
|
||||
exports.$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)) {
|
||||
@@ -1164,17 +1120,15 @@ exports.$ZodTuple = 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;
|
||||
}
|
||||
@@ -1237,13 +1191,11 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
|
||||
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) => {
|
||||
@@ -1263,7 +1215,7 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
|
||||
}
|
||||
let unrecognized;
|
||||
for (const key in input) {
|
||||
if (!recordKeys.has(key)) {
|
||||
if (!values.has(key)) {
|
||||
unrecognized = unrecognized ?? [];
|
||||
unrecognized.push(key);
|
||||
}
|
||||
@@ -1288,8 +1240,8 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
|
||||
}
|
||||
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],
|
||||
@@ -1360,8 +1312,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())),
|
||||
@@ -1422,15 +1374,14 @@ function handleSetResult(result, final) {
|
||||
exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
|
||||
exports.$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({
|
||||
@@ -1444,17 +1395,13 @@ exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
|
||||
});
|
||||
exports.$ZodLiteral = core.$constructor("$ZodLiteral", (inst, def) => {
|
||||
exports.$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({
|
||||
@@ -1470,7 +1417,6 @@ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, _ctx) => {
|
||||
const input = payload.value;
|
||||
// @ts-ignore
|
||||
if (input instanceof File)
|
||||
return payload;
|
||||
payload.issues.push({
|
||||
@@ -1484,12 +1430,9 @@ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
|
||||
});
|
||||
exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
|
||||
exports.$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;
|
||||
@@ -1503,12 +1446,6 @@ exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
function handleOptionalResult(result, input) {
|
||||
if (result.issues.length && input === undefined) {
|
||||
return { issues: [], value: undefined };
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.$ZodOptional = core.$constructor("$ZodOptional", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.optin = "optional";
|
||||
@@ -1522,10 +1459,7 @@ exports.$ZodOptional = core.$constructor("$ZodOptional", (inst, def) => {
|
||||
});
|
||||
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;
|
||||
@@ -1545,7 +1479,6 @@ exports.$ZodNullable = core.$constructor("$ZodNullable", (inst, def) => {
|
||||
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);
|
||||
@@ -1557,18 +1490,13 @@ exports.$ZodDefault = core.$constructor("$ZodDefault", (inst, def) => {
|
||||
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));
|
||||
@@ -1587,10 +1515,6 @@ exports.$ZodPrefault = core.$constructor("$ZodPrefault", (inst, def) => {
|
||||
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;
|
||||
}
|
||||
@@ -1625,9 +1549,6 @@ function handleNonOptionalResult(payload, inst) {
|
||||
exports.$ZodSuccess = core.$constructor("$ZodSuccess", (inst, def) => {
|
||||
exports.$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) => {
|
||||
@@ -1641,14 +1562,10 @@ exports.$ZodSuccess = core.$constructor("$ZodSuccess", (inst, def) => {
|
||||
});
|
||||
exports.$ZodCatch = core.$constructor("$ZodCatch", (inst, def) => {
|
||||
exports.$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) => {
|
||||
@@ -1700,94 +1617,27 @@ exports.$ZodPipe = 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);
|
||||
}
|
||||
exports.$ZodCodec = core.$constructor("$ZodCodec", (inst, def) => {
|
||||
exports.$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);
|
||||
}
|
||||
exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
|
||||
exports.$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);
|
||||
@@ -1803,8 +1653,7 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
|
||||
exports.$ZodType.init(inst, def);
|
||||
const regexParts = [];
|
||||
for (const part of def.parts) {
|
||||
if (typeof part === "object" && part !== null) {
|
||||
// is Zod schema
|
||||
if (part instanceof exports.$ZodType) {
|
||||
if (!part._zod.pattern) {
|
||||
// if (!source)
|
||||
throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
|
||||
@@ -1840,7 +1689,7 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
|
||||
input: payload.value,
|
||||
inst,
|
||||
code: "invalid_format",
|
||||
format: def.format ?? "template_literal",
|
||||
format: "template_literal",
|
||||
pattern: inst._zod.pattern.source,
|
||||
});
|
||||
return payload;
|
||||
@@ -1848,85 +1697,6 @@ exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, de
|
||||
return payload;
|
||||
};
|
||||
});
|
||||
exports.$ZodFunction = core.$constructor("$ZodFunction", (inst, def) => {
|
||||
exports.$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 ? (0, parse_js_1.parse)(inst._def.input, args) : args;
|
||||
const result = Reflect.apply(func, this, parsedArgs);
|
||||
if (inst._def.output) {
|
||||
return (0, parse_js_1.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 (0, parse_js_1.parseAsync)(inst._def.input, args) : args;
|
||||
const result = await Reflect.apply(func, this, parsedArgs);
|
||||
if (inst._def.output) {
|
||||
return await (0, parse_js_1.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 exports.$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;
|
||||
});
|
||||
exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
|
||||
exports.$ZodType.init(inst, def);
|
||||
inst._zod.parse = (payload, ctx) => {
|
||||
@@ -1935,18 +1705,11 @@ exports.$ZodPromise = core.$constructor("$ZodPromise", (inst, def) => {
|
||||
});
|
||||
exports.$ZodLazy = core.$constructor("$ZodLazy", (inst, def) => {
|
||||
exports.$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);
|
||||
|
||||
Reference in New Issue
Block a user