avancement planning

This commit is contained in:
2026-05-26 11:58:39 +02:00
parent 619a2b240a
commit 150b97cd2e
4892 changed files with 99214 additions and 429382 deletions
+76 -23
View File
@@ -6,6 +6,7 @@ export const ZodMiniType = /*@__PURE__*/ core.$constructor("ZodMiniType", (inst,
throw new Error("Uninitialized schema in ZodMiniType.");
core.$ZodType.init(inst, def);
inst.def = def;
inst.type = def.type;
inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
@@ -78,6 +79,13 @@ export const ZodMiniURL = /*@__PURE__*/ core.$constructor("ZodMiniURL", (inst, d
export function url(params) {
return core._url(ZodMiniURL, params);
}
export function httpUrl(params) {
return core._url(ZodMiniURL, {
protocol: /^https?$/,
hostname: core.regexes.domain,
...util.normalizeParams(params),
});
}
export const ZodMiniEmoji = /*@__PURE__*/ core.$constructor("ZodMiniEmoji", (inst, def) => {
core.$ZodEmoji.init(inst, def);
ZodMiniStringFormat.init(inst, def);
@@ -155,6 +163,13 @@ export const ZodMiniCIDRv6 = /*@__PURE__*/ core.$constructor("ZodMiniCIDRv6", (i
export function cidrv6(params) {
return core._cidrv6(ZodMiniCIDRv6, params);
}
export const ZodMiniMAC = /*@__PURE__*/ core.$constructor("ZodMiniMAC", (inst, def) => {
core.$ZodMAC.init(inst, def);
ZodMiniStringFormat.init(inst, def);
});
export function mac(params) {
return core._mac(ZodMiniMAC, params);
}
export const ZodMiniBase64 = /*@__PURE__*/ core.$constructor("ZodMiniBase64", (inst, def) => {
core.$ZodBase64.init(inst, def);
ZodMiniStringFormat.init(inst, def);
@@ -190,6 +205,21 @@ export const ZodMiniCustomStringFormat = /*@__PURE__*/ core.$constructor("ZodMin
export function stringFormat(format, fnOrRegex, _params = {}) {
return core._stringFormat(ZodMiniCustomStringFormat, format, fnOrRegex, _params);
}
export function hostname(_params) {
return core._stringFormat(ZodMiniCustomStringFormat, "hostname", core.regexes.hostname, _params);
}
export function hex(_params) {
return core._stringFormat(ZodMiniCustomStringFormat, "hex", core.regexes.hex, _params);
}
export function hash(alg, params) {
const enc = params?.enc ?? "hex";
const format = `${alg}_${enc}`;
const regex = core.regexes[format];
// check for unrecognized format
if (!regex)
throw new Error(`Unrecognized hash format: ${format}`);
return core._stringFormat(ZodMiniCustomStringFormat, format, regex, params);
}
export const ZodMiniNumber = /*@__PURE__*/ core.$constructor("ZodMiniNumber", (inst, def) => {
core.$ZodNumber.init(inst, def);
ZodMiniType.init(inst, def);
@@ -320,7 +350,7 @@ export function array(element, params) {
// .keyof
export function keyof(schema) {
const shape = schema._zod.def.shape;
return literal(Object.keys(shape));
return _enum(Object.keys(shape));
}
export const ZodMiniObject = /*@__PURE__*/ core.$constructor("ZodMiniObject", (inst, def) => {
core.$ZodObject.init(inst, def);
@@ -330,10 +360,7 @@ export const ZodMiniObject = /*@__PURE__*/ core.$constructor("ZodMiniObject", (i
export function object(shape, params) {
const def = {
type: "object",
get shape() {
util.assignProp(this, "shape", { ...shape });
return this.shape;
},
shape: shape ?? {},
...util.normalizeParams(params),
};
return new ZodMiniObject(def);
@@ -342,11 +369,7 @@ export function object(shape, params) {
export function strictObject(shape, params) {
return new ZodMiniObject({
type: "object",
// shape: shape as core.$ZodLooseShape,
get shape() {
util.assignProp(this, "shape", { ...shape });
return this.shape;
},
shape,
catchall: never(),
...util.normalizeParams(params),
});
@@ -355,14 +378,7 @@ export function strictObject(shape, params) {
export function looseObject(shape, params) {
return new ZodMiniObject({
type: "object",
// shape: shape as core.$ZodLooseShape,
get shape() {
util.assignProp(this, "shape", { ...shape });
return this.shape;
},
// get optional() {
// return util.optionalKeys(shape);
// },
shape,
catchall: unknown(),
...util.normalizeParams(params),
});
@@ -371,6 +387,9 @@ export function looseObject(shape, params) {
export function extend(schema, shape) {
return util.extend(schema, shape);
}
export function safeExtend(schema, shape) {
return util.safeExtend(schema, shape);
}
export function merge(schema, shape) {
return util.extend(schema, shape);
}
@@ -452,9 +471,11 @@ export function record(keyType, valueType, params) {
});
}
export function partialRecord(keyType, valueType, params) {
const k = core.clone(keyType);
k._zod.values = undefined;
return new ZodMiniRecord({
type: "record",
keyType: union([keyType, never()]),
keyType: k,
valueType: valueType,
...util.normalizeParams(params),
});
@@ -485,6 +506,7 @@ export function set(valueType, params) {
export const ZodMiniEnum = /*@__PURE__*/ core.$constructor("ZodMiniEnum", (inst, def) => {
core.$ZodEnum.init(inst, def);
ZodMiniType.init(inst, def);
inst.options = Object.values(def.entries);
});
function _enum(values, params) {
const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
@@ -570,7 +592,7 @@ export function _default(innerType, defaultValue) {
type: "default",
innerType: innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
},
});
}
@@ -583,7 +605,7 @@ export function prefault(innerType, defaultValue) {
type: "prefault",
innerType: innerType,
get defaultValue() {
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
return typeof defaultValue === "function" ? defaultValue() : util.shallowClone(defaultValue);
},
});
}
@@ -638,6 +660,19 @@ export function pipe(in_, out) {
out: out,
});
}
export const ZodMiniCodec = /*@__PURE__*/ core.$constructor("ZodMiniCodec", (inst, def) => {
ZodMiniPipe.init(inst, def);
core.$ZodCodec.init(inst, def);
});
export function codec(in_, out, params) {
return new ZodMiniCodec({
type: "pipe",
in: in_,
out: out,
transform: params.decode,
reverseTransform: params.encode,
});
}
export const ZodMiniReadonly = /*@__PURE__*/ core.$constructor("ZodMiniReadonly", (inst, def) => {
core.$ZodReadonly.init(inst, def);
ZodMiniType.init(inst, def);
@@ -705,6 +740,13 @@ export function custom(fn, _params) {
export function refine(fn, _params = {}) {
return core._refine(ZodMiniCustom, fn, _params);
}
// superRefine
export function superRefine(fn) {
return core._superRefine(fn);
}
// Re-export describe and meta from core
export const describe = core.describe;
export const meta = core.meta;
// instanceof
class Class {
constructor(..._args) { }
@@ -719,10 +761,9 @@ function _instanceof(cls, params = {
export { _instanceof as instanceof };
// stringbool
export const stringbool = (...args) => core._stringbool({
Pipe: ZodMiniPipe,
Codec: ZodMiniCodec,
Boolean: ZodMiniBoolean,
String: ZodMiniString,
Transform: ZodMiniTransform,
}, ...args);
export function json() {
const jsonSchema = _lazy(() => {
@@ -730,3 +771,15 @@ export function json() {
});
return jsonSchema;
}
export const ZodMiniFunction = /*@__PURE__*/ core.$constructor("ZodMiniFunction", (inst, def) => {
core.$ZodFunction.init(inst, def);
ZodMiniType.init(inst, def);
});
export function _function(params) {
return new ZodMiniFunction({
type: "function",
input: Array.isArray(params?.input) ? tuple(params?.input) : (params?.input ?? array(unknown())),
output: params?.output ?? unknown(),
});
}
export { _function as function };