UEA-PRODEM

This commit is contained in:
2026-06-10 12:14:46 -03:00
parent f54126b9d8
commit 9947565694
5319 changed files with 148520 additions and 129332 deletions
+214 -70
View File
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodXor = 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.$ZodExactOptional = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = void 0;
exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodFunction = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPreprocess = exports.$ZodCodec = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodExactOptional = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = void 0;
exports.isValidBase64 = isValidBase64;
exports.isValidBase64URL = isValidBase64URL;
exports.isValidJWT = isValidJWT;
@@ -65,6 +65,8 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
let asyncResult;
for (const ch of checks) {
if (ch._zod.def.when) {
if (util.explicitlyAborted(payload))
continue;
const shouldRun = ch._zod.def.when(payload);
if (!shouldRun)
continue;
@@ -219,6 +221,21 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
try {
// Trim whitespace from input
const trimmed = payload.value.trim();
// When normalize is off, require :// for http/https URLs
// This prevents strings like "http:example.com" or "https:/path" from being silently accepted
if (!def.normalize && def.protocol?.source === regexes.httpProtocol.source) {
if (!/^https?:\/\//i.test(trimmed)) {
payload.issues.push({
code: "invalid_format",
format: "url",
note: "Invalid URL format",
input: payload.value,
inst,
continue: !def.abort,
});
return;
}
}
// @ts-ignore
const url = new URL(trimmed);
if (def.hostname) {
@@ -279,6 +296,11 @@ exports.$ZodNanoID = core.$constructor("$ZodNanoID", (inst, def) => {
def.pattern ?? (def.pattern = regexes.nanoid);
exports.$ZodStringFormat.init(inst, def);
});
/**
* @deprecated CUID v1 is deprecated by its authors due to information leakage
* (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
* See https://github.com/paralleldrive/cuid.
*/
exports.$ZodCUID = core.$constructor("$ZodCUID", (inst, def) => {
def.pattern ?? (def.pattern = regexes.cuid);
exports.$ZodStringFormat.init(inst, def);
@@ -384,6 +406,9 @@ exports.$ZodCIDRv6 = core.$constructor("$ZodCIDRv6", (inst, def) => {
function isValidBase64(data) {
if (data === "")
return true;
// atob ignores whitespace, so reject it up front.
if (/\s/.test(data))
return false;
if (data.length % 4 !== 0)
return false;
try {
@@ -588,8 +613,6 @@ exports.$ZodUndefined = core.$constructor("$ZodUndefined", (inst, def) => {
exports.$ZodType.init(inst, def);
inst._zod.pattern = regexes.undefined;
inst._zod.values = new Set([undefined]);
inst._zod.optin = "optional";
inst._zod.optout = "optional";
inst._zod.parse = (payload, _ctx) => {
const input = payload.value;
if (typeof input === "undefined")
@@ -719,16 +742,28 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
return payload; //handleArrayResultsAsync(parseResults, final);
};
});
function handlePropertyResult(result, final, key, input, isOptionalOut) {
function handlePropertyResult(result, final, key, input, isOptionalIn, isOptionalOut) {
const isPresent = key in input;
if (result.issues.length) {
// For optional-out schemas, ignore errors on absent keys
if (isOptionalOut && !(key in input)) {
// For optional-in/out schemas, ignore errors on absent keys.
if (isOptionalIn && isOptionalOut && !isPresent) {
return;
}
final.issues.push(...util.prefixIssues(key, result.issues));
}
if (!isPresent && !isOptionalIn) {
if (!result.issues.length) {
final.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: undefined,
path: [key],
});
}
return;
}
if (result.value === undefined) {
if (key in input) {
if (isPresent) {
final.value[key] = undefined;
}
}
@@ -754,12 +789,16 @@ function normalizeDef(def) {
}
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;
const isOptionalIn = _catchall.optin === "optional";
const isOptionalOut = _catchall.optout === "optional";
for (const key in input) {
// skip __proto__ so it can't replace the result prototype via the
// assignment setter on the plain {} we build into
if (key === "__proto__")
continue;
if (keySet.has(key))
continue;
if (t === "never") {
@@ -768,10 +807,10 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
}
const r = _catchall.run({ value: input[key], issues: [] }, ctx);
if (r instanceof Promise) {
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
}
else {
handlePropertyResult(r, payload, key, input, isOptionalOut);
handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
}
}
if (unrecognized.length) {
@@ -839,13 +878,14 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
const shape = value.shape;
for (const key of value.keys) {
const el = shape[key];
const isOptionalIn = el._zod.optin === "optional";
const isOptionalOut = el._zod.optout === "optional";
const r = el._zod.run({ value: input[key], issues: [] }, ctx);
if (r instanceof Promise) {
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalOut)));
proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut)));
}
else {
handlePropertyResult(r, payload, key, input, isOptionalOut);
handlePropertyResult(r, payload, key, input, isOptionalIn, isOptionalOut);
}
}
if (!catchall) {
@@ -878,10 +918,11 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
const id = ids[key];
const k = util.esc(key);
const schema = shape[key];
const isOptionalIn = schema?._zod?.optin === "optional";
const isOptionalOut = schema?._zod?.optout === "optional";
doc.write(`const ${id} = ${parseStr(key)};`);
if (isOptionalOut) {
// For optional-out schemas, ignore errors on absent keys
if (isOptionalIn && isOptionalOut) {
// For optional-in/out schemas, ignore errors on absent keys
doc.write(`
if (${id}.issues.length) {
if (${k} in input) {
@@ -900,6 +941,34 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
newResult[${k}] = ${id}.value;
}
`);
}
else if (!isOptionalIn) {
doc.write(`
const ${id}_present = ${k} in input;
if (${id}.issues.length) {
payload.issues = payload.issues.concat(${id}.issues.map(iss => ({
...iss,
path: iss.path ? [${k}, ...iss.path] : [${k}]
})));
}
if (!${id}_present && !${id}.issues.length) {
payload.issues.push({
code: "invalid_type",
expected: "nonoptional",
input: undefined,
path: [${k}]
});
}
if (${id}_present) {
if (${id}.value === undefined) {
newResult[${k}] = undefined;
} else {
newResult[${k}] = ${id}.value;
}
}
`);
}
else {
@@ -995,10 +1064,9 @@ exports.$ZodUnion = core.$constructor("$ZodUnion", (inst, def) => {
}
return undefined;
});
const single = def.options.length === 1;
const first = def.options[0]._zod.run;
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
inst._zod.parse = (payload, ctx) => {
if (single) {
if (first) {
return first(payload, ctx);
}
let async = false;
@@ -1055,10 +1123,9 @@ function handleExclusiveUnionResults(results, final, inst, ctx) {
exports.$ZodXor = core.$constructor("$ZodXor", (inst, def) => {
exports.$ZodUnion.init(inst, def);
def.inclusive = false;
const single = def.options.length === 1;
const first = def.options[0]._zod.run;
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
inst._zod.parse = (payload, ctx) => {
if (single) {
if (first) {
return first(payload, ctx);
}
let async = false;
@@ -1136,7 +1203,11 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
if (opt) {
return opt._zod.run(payload, ctx);
}
if (def.unionFallback) {
// Fall back to union matching when the fast discriminator path fails:
// - explicitly enabled via unionFallback, or
// - during backward direction (encode), since codec-based discriminators
// have different values in forward vs backward directions
if (def.unionFallback || ctx.direction === "backward") {
return _super(payload, ctx);
}
// no matching discriminator
@@ -1145,6 +1216,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
errors: [],
note: "No matching discriminator",
discriminator: def.discriminator,
options: Array.from(disc.value.keys()),
input,
path: [def.discriminator],
inst,
@@ -1272,67 +1344,112 @@ 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;
const optinStart = getTupleOptStart(items, "optin");
const optoutStart = getTupleOptStart(items, "optout");
if (!def.rest) {
const tooBig = input.length > items.length;
const tooSmall = input.length < optStart - 1;
if (tooBig || tooSmall) {
if (input.length < optinStart) {
payload.issues.push({
...(tooBig
? { code: "too_big", maximum: items.length, inclusive: true }
: { code: "too_small", minimum: items.length }),
code: "too_small",
minimum: optinStart,
inclusive: true,
input,
inst,
origin: "array",
});
return payload;
}
if (input.length > items.length) {
payload.issues.push({
code: "too_big",
maximum: items.length,
inclusive: true,
input,
inst,
origin: "array",
});
}
}
let i = -1;
for (const item of items) {
i++;
if (i >= input.length)
if (i >= optStart)
continue;
const result = item._zod.run({
value: input[i],
issues: [],
}, ctx);
if (result instanceof Promise) {
proms.push(result.then((result) => handleTupleResult(result, payload, i)));
// Run every item in parallel, collecting results into an indexed
// array. The post-processing in `handleTupleResults` walks them in
// order so it can decide whether an absent optional-output error can
// truncate the tail or must be reported to preserve required output.
const itemResults = new Array(items.length);
for (let i = 0; i < items.length; i++) {
const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
if (r instanceof Promise) {
proms.push(r.then((rr) => {
itemResults[i] = rr;
}));
}
else {
handleTupleResult(result, payload, i);
itemResults[i] = r;
}
}
if (def.rest) {
let i = items.length - 1;
const rest = input.slice(items.length);
for (const el of rest) {
i++;
const result = def.rest._zod.run({
value: el,
issues: [],
}, ctx);
const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
if (result instanceof Promise) {
proms.push(result.then((result) => handleTupleResult(result, payload, i)));
proms.push(result.then((r) => handleTupleResult(r, payload, i)));
}
else {
handleTupleResult(result, payload, i);
}
}
}
if (proms.length)
return Promise.all(proms).then(() => payload);
return payload;
if (proms.length) {
return Promise.all(proms).then(() => handleTupleResults(itemResults, payload, items, input, optoutStart));
}
return handleTupleResults(itemResults, payload, items, input, optoutStart);
};
});
function getTupleOptStart(items, key) {
for (let i = items.length - 1; i >= 0; i--) {
if (items[i]._zod[key] !== "optional")
return i + 1;
}
return 0;
}
function handleTupleResult(result, final, index) {
if (result.issues.length) {
final.issues.push(...util.prefixIssues(index, result.issues));
}
final.value[index] = result.value;
}
function handleTupleResults(itemResults, final, items, input, optoutStart) {
// Walk results in order. Mirror $ZodObject's swallow-on-absent-optional
// rule, but only after `optoutStart`: the first index where the output
// tuple tail can be absent.
for (let i = 0; i < items.length; i++) {
const r = itemResults[i];
const isPresent = i < input.length;
if (r.issues.length) {
if (!isPresent && i >= optoutStart) {
final.value.length = i;
break;
}
final.issues.push(...util.prefixIssues(i, r.issues));
}
final.value[i] = r.value;
}
// Drop trailing slots that produced `undefined` for absent input
// (the array analog of an absent optional key on an object). The
// `i >= input.length` floor is critical: an explicit `undefined`
// *inside* the input must be preserved even when the schema is
// optional-out (e.g. `z.string().or(z.undefined())` accepting an
// explicit undefined value).
for (let i = final.value.length - 1; i >= input.length; i--) {
if (items[i]._zod.optout === "optional" && final.value[i] === undefined) {
final.value.length = i;
}
else {
break;
}
}
return final;
}
exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
exports.$ZodType.init(inst, def);
inst._zod.parse = (payload, ctx) => {
@@ -1354,20 +1471,36 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
for (const key of values) {
if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
recordKeys.add(typeof key === "number" ? key.toString() : key);
const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
if (keyResult instanceof Promise) {
throw new Error("Async schemas not supported in object keys currently");
}
if (keyResult.issues.length) {
payload.issues.push({
code: "invalid_key",
origin: "record",
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
input: key,
path: [key],
inst,
});
continue;
}
const outKey = keyResult.value;
const result = def.valueType._zod.run({ value: input[key], issues: [] }, ctx);
if (result instanceof Promise) {
proms.push(result.then((result) => {
if (result.issues.length) {
payload.issues.push(...util.prefixIssues(key, result.issues));
}
payload.value[key] = result.value;
payload.value[outKey] = result.value;
}));
}
else {
if (result.issues.length) {
payload.issues.push(...util.prefixIssues(key, result.issues));
}
payload.value[key] = result.value;
payload.value[outKey] = result.value;
}
}
}
@@ -1389,18 +1522,19 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
}
else {
payload.value = {};
// Reflect.ownKeys for Symbol-key support; filter non-enumerable to match z.object()
for (const key of Reflect.ownKeys(input)) {
if (key === "__proto__")
continue;
if (!Object.prototype.propertyIsEnumerable.call(input, key))
continue;
let keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
if (keyResult instanceof Promise) {
throw new Error("Async schemas not supported in object keys currently");
}
// Numeric string fallback: if key failed with "expected number", retry with Number(key)
const checkNumericKey = typeof key === "string" &&
regexes.number.test(key) &&
keyResult.issues.length &&
keyResult.issues.some((iss) => iss.code === "invalid_type" && iss.expected === "number");
// Numeric string fallback: if key is a numeric string and failed, retry with Number(key)
// This handles z.number(), z.literal([1, 2, 3]), and unions containing numeric literals
const checkNumericKey = typeof key === "string" && regexes.number.test(key) && keyResult.issues.length;
if (checkNumericKey) {
const retryResult = def.keyType._zod.run({ value: Number(key), issues: [] }, ctx);
if (retryResult instanceof Promise) {
@@ -1614,6 +1748,7 @@ exports.$ZodFile = core.$constructor("$ZodFile", (inst, def) => {
});
exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
exports.$ZodType.init(inst, def);
inst._zod.optin = "optional";
inst._zod.parse = (payload, ctx) => {
if (ctx.direction === "backward") {
throw new core.$ZodEncodeError(inst.constructor.name);
@@ -1623,6 +1758,7 @@ exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
const output = _out instanceof Promise ? _out : Promise.resolve(_out);
return output.then((output) => {
payload.value = output;
payload.fallback = true;
return payload;
});
}
@@ -1630,11 +1766,12 @@ exports.$ZodTransform = core.$constructor("$ZodTransform", (inst, def) => {
throw new core.$ZodAsyncError();
}
payload.value = _out;
payload.fallback = true;
return payload;
};
});
function handleOptionalResult(result, input) {
if (result.issues.length && input === undefined) {
if (input === undefined && (result.issues.length || result.fallback)) {
return { issues: [], value: undefined };
}
return result;
@@ -1652,10 +1789,11 @@ exports.$ZodOptional = core.$constructor("$ZodOptional", (inst, def) => {
});
inst._zod.parse = (payload, ctx) => {
if (def.innerType._zod.optin === "optional") {
const input = payload.value;
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 result.then((r) => handleOptionalResult(r, input));
return handleOptionalResult(result, input);
}
if (payload.value === undefined) {
return payload;
@@ -1782,7 +1920,7 @@ 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) => {
@@ -1803,6 +1941,7 @@ exports.$ZodCatch = core.$constructor("$ZodCatch", (inst, def) => {
input: payload.value,
});
payload.issues = [];
payload.fallback = true;
}
return payload;
});
@@ -1817,6 +1956,7 @@ exports.$ZodCatch = core.$constructor("$ZodCatch", (inst, def) => {
input: payload.value,
});
payload.issues = [];
payload.fallback = true;
}
return payload;
};
@@ -1863,7 +2003,7 @@ function handlePipeResult(left, next, ctx) {
left.aborted = true;
return left;
}
return next._zod.run({ value: left.value, issues: left.issues }, ctx);
return next._zod.run({ value: left.value, issues: left.issues, fallback: left.fallback }, ctx);
}
exports.$ZodCodec = core.$constructor("$ZodCodec", (inst, def) => {
exports.$ZodType.init(inst, def);
@@ -1919,6 +2059,9 @@ function handleCodecTxResult(left, value, nextSchema, ctx) {
}
return nextSchema._zod.run({ value, issues: left.issues }, ctx);
}
exports.$ZodPreprocess = core.$constructor("$ZodPreprocess", (inst, def) => {
exports.$ZodPipe.init(inst, def);
});
exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
exports.$ZodType.init(inst, def);
util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
@@ -2076,14 +2219,15 @@ 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());
// Cache the resolved inner type on the shared `def` so all clones of this
// lazy (e.g. via `.describe()`/`.meta()`) share the same inner instance,
// preserving identity for cycle detection on recursive schemas.
util.defineLazy(inst._zod, "innerType", () => {
const d = def;
if (!d._cachedInner)
d._cachedInner = def.getter();
return d._cachedInner;
});
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);