zod 3.25.48 → 3.25.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/v4/classic/schemas.js +1 -1
- package/dist/cjs/v4/core/api.js +19 -3
- package/dist/cjs/v4/core/checks.js +2 -1
- package/dist/cjs/v4/core/doc.js +0 -1
- package/dist/cjs/v4/core/to-json-schema.js +9 -0
- package/dist/cjs/v4/mini/schemas.js +5 -15
- package/dist/esm/v4/classic/schemas.js +1 -1
- package/dist/esm/v4/core/api.js +19 -3
- package/dist/esm/v4/core/checks.js +2 -1
- package/dist/esm/v4/core/doc.js +0 -1
- package/dist/esm/v4/core/to-json-schema.js +9 -0
- package/dist/esm/v4/mini/schemas.js +4 -14
- package/dist/types/v4/core/api.d.ts +1 -1
- package/dist/types/v4/mini/schemas.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1042,7 +1042,7 @@ function custom(fn, _params) {
|
|
|
1042
1042
|
return core._custom(exports.ZodCustom, fn ?? (() => true), _params);
|
|
1043
1043
|
}
|
|
1044
1044
|
function refine(fn, _params = {}) {
|
|
1045
|
-
return core.
|
|
1045
|
+
return core._refine(exports.ZodCustom, fn, _params);
|
|
1046
1046
|
}
|
|
1047
1047
|
// superRefine
|
|
1048
1048
|
function superRefine(fn, params) {
|
package/dist/cjs/v4/core/api.js
CHANGED
|
@@ -928,16 +928,32 @@ function _promise(Class, innerType) {
|
|
|
928
928
|
});
|
|
929
929
|
}
|
|
930
930
|
function _custom(Class, fn, _params) {
|
|
931
|
+
const norm = util.normalizeParams(_params);
|
|
932
|
+
norm.abort ?? (norm.abort = true); // default to abort:false
|
|
931
933
|
const schema = new Class({
|
|
932
934
|
type: "custom",
|
|
933
935
|
check: "custom",
|
|
934
936
|
fn: fn,
|
|
935
|
-
...
|
|
937
|
+
...norm,
|
|
936
938
|
});
|
|
937
939
|
return schema;
|
|
938
940
|
}
|
|
939
|
-
function _refine(
|
|
940
|
-
|
|
941
|
+
// export function _refine<T>(
|
|
942
|
+
// Class: util.SchemaClass<schemas.$ZodCustom>,
|
|
943
|
+
// fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
|
|
944
|
+
// _params: string | $ZodCustomParams = {}
|
|
945
|
+
// ): checks.$ZodCheck<T> {
|
|
946
|
+
// return _custom(Class, fn, _params);
|
|
947
|
+
// }
|
|
948
|
+
// same as _custom but deafults to abort:false
|
|
949
|
+
function _refine(Class, fn, _params) {
|
|
950
|
+
const schema = new Class({
|
|
951
|
+
type: "custom",
|
|
952
|
+
check: "custom",
|
|
953
|
+
fn: fn,
|
|
954
|
+
...util.normalizeParams(_params),
|
|
955
|
+
});
|
|
956
|
+
return schema;
|
|
941
957
|
}
|
|
942
958
|
function _stringbool(Classes, _params) {
|
|
943
959
|
const { case: _case, error, truthy, falsy } = util.normalizeParams(_params);
|
|
@@ -463,7 +463,8 @@ exports.$ZodCheckUpperCase = core.$constructor("$ZodCheckUpperCase", (inst, def)
|
|
|
463
463
|
});
|
|
464
464
|
exports.$ZodCheckIncludes = core.$constructor("$ZodCheckIncludes", (inst, def) => {
|
|
465
465
|
exports.$ZodCheck.init(inst, def);
|
|
466
|
-
const
|
|
466
|
+
const escapedRegex = util.escapeRegex(def.includes);
|
|
467
|
+
const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
|
|
467
468
|
def.pattern = pattern;
|
|
468
469
|
inst._zod.onattach.push((inst) => {
|
|
469
470
|
const bag = inst._zod.bag;
|
package/dist/cjs/v4/core/doc.js
CHANGED
|
@@ -361,9 +361,18 @@ class JSONSchemaGenerator {
|
|
|
361
361
|
}
|
|
362
362
|
else if (vals.length === 1) {
|
|
363
363
|
const val = vals[0];
|
|
364
|
+
json.type = val === null ? "null" : typeof val;
|
|
364
365
|
json.const = val;
|
|
365
366
|
}
|
|
366
367
|
else {
|
|
368
|
+
if (vals.every((v) => typeof v === "number"))
|
|
369
|
+
json.type = "number";
|
|
370
|
+
if (vals.every((v) => typeof v === "string"))
|
|
371
|
+
json.type = "string";
|
|
372
|
+
if (vals.every((v) => typeof v === "boolean"))
|
|
373
|
+
json.type = "string";
|
|
374
|
+
if (vals.every((v) => v === null))
|
|
375
|
+
json.type = "null";
|
|
367
376
|
json.enum = vals;
|
|
368
377
|
}
|
|
369
378
|
break;
|
|
@@ -105,8 +105,8 @@ exports.templateLiteral = templateLiteral;
|
|
|
105
105
|
exports.lazy = _lazy;
|
|
106
106
|
exports.promise = promise;
|
|
107
107
|
exports.check = check;
|
|
108
|
-
exports.refine = refine;
|
|
109
108
|
exports.custom = custom;
|
|
109
|
+
exports.refine = refine;
|
|
110
110
|
exports.instanceof = _instanceof;
|
|
111
111
|
exports.json = json;
|
|
112
112
|
const core = __importStar(require("zod/v4/core"));
|
|
@@ -797,23 +797,13 @@ function check(fn, params) {
|
|
|
797
797
|
return ch;
|
|
798
798
|
}
|
|
799
799
|
// ZodCustom
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
type: "custom",
|
|
804
|
-
check: "custom",
|
|
805
|
-
fn: fn,
|
|
806
|
-
...params,
|
|
807
|
-
});
|
|
808
|
-
return schema;
|
|
800
|
+
// custom schema
|
|
801
|
+
function custom(fn, _params) {
|
|
802
|
+
return core._custom(exports.ZodMiniCustom, fn ?? (() => true), _params);
|
|
809
803
|
}
|
|
810
804
|
// refine
|
|
811
805
|
function refine(fn, _params = {}) {
|
|
812
|
-
return
|
|
813
|
-
}
|
|
814
|
-
// custom schema
|
|
815
|
-
function custom(fn, _params) {
|
|
816
|
-
return _custom(fn ?? (() => true), _params, exports.ZodMiniCustom);
|
|
806
|
+
return core._refine(exports.ZodMiniCustom, fn, _params);
|
|
817
807
|
}
|
|
818
808
|
// instanceof
|
|
819
809
|
class Class {
|
|
@@ -940,7 +940,7 @@ export function custom(fn, _params) {
|
|
|
940
940
|
return core._custom(ZodCustom, fn ?? (() => true), _params);
|
|
941
941
|
}
|
|
942
942
|
export function refine(fn, _params = {}) {
|
|
943
|
-
return core.
|
|
943
|
+
return core._refine(ZodCustom, fn, _params);
|
|
944
944
|
}
|
|
945
945
|
// superRefine
|
|
946
946
|
export function superRefine(fn, params) {
|
package/dist/esm/v4/core/api.js
CHANGED
|
@@ -797,16 +797,32 @@ export function _promise(Class, innerType) {
|
|
|
797
797
|
});
|
|
798
798
|
}
|
|
799
799
|
export function _custom(Class, fn, _params) {
|
|
800
|
+
const norm = util.normalizeParams(_params);
|
|
801
|
+
norm.abort ?? (norm.abort = true); // default to abort:false
|
|
800
802
|
const schema = new Class({
|
|
801
803
|
type: "custom",
|
|
802
804
|
check: "custom",
|
|
803
805
|
fn: fn,
|
|
804
|
-
...
|
|
806
|
+
...norm,
|
|
805
807
|
});
|
|
806
808
|
return schema;
|
|
807
809
|
}
|
|
808
|
-
export function _refine(
|
|
809
|
-
|
|
810
|
+
// export function _refine<T>(
|
|
811
|
+
// Class: util.SchemaClass<schemas.$ZodCustom>,
|
|
812
|
+
// fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
|
|
813
|
+
// _params: string | $ZodCustomParams = {}
|
|
814
|
+
// ): checks.$ZodCheck<T> {
|
|
815
|
+
// return _custom(Class, fn, _params);
|
|
816
|
+
// }
|
|
817
|
+
// same as _custom but deafults to abort:false
|
|
818
|
+
export function _refine(Class, fn, _params) {
|
|
819
|
+
const schema = new Class({
|
|
820
|
+
type: "custom",
|
|
821
|
+
check: "custom",
|
|
822
|
+
fn: fn,
|
|
823
|
+
...util.normalizeParams(_params),
|
|
824
|
+
});
|
|
825
|
+
return schema;
|
|
810
826
|
}
|
|
811
827
|
export function _stringbool(Classes, _params) {
|
|
812
828
|
const { case: _case, error, truthy, falsy } = util.normalizeParams(_params);
|
|
@@ -437,7 +437,8 @@ export const $ZodCheckUpperCase = /*@__PURE__*/ core.$constructor("$ZodCheckUppe
|
|
|
437
437
|
});
|
|
438
438
|
export const $ZodCheckIncludes = /*@__PURE__*/ core.$constructor("$ZodCheckIncludes", (inst, def) => {
|
|
439
439
|
$ZodCheck.init(inst, def);
|
|
440
|
-
const
|
|
440
|
+
const escapedRegex = util.escapeRegex(def.includes);
|
|
441
|
+
const pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position}}${escapedRegex}` : escapedRegex);
|
|
441
442
|
def.pattern = pattern;
|
|
442
443
|
inst._zod.onattach.push((inst) => {
|
|
443
444
|
const bag = inst._zod.bag;
|
package/dist/esm/v4/core/doc.js
CHANGED
|
@@ -357,9 +357,18 @@ export class JSONSchemaGenerator {
|
|
|
357
357
|
}
|
|
358
358
|
else if (vals.length === 1) {
|
|
359
359
|
const val = vals[0];
|
|
360
|
+
json.type = val === null ? "null" : typeof val;
|
|
360
361
|
json.const = val;
|
|
361
362
|
}
|
|
362
363
|
else {
|
|
364
|
+
if (vals.every((v) => typeof v === "number"))
|
|
365
|
+
json.type = "number";
|
|
366
|
+
if (vals.every((v) => typeof v === "string"))
|
|
367
|
+
json.type = "string";
|
|
368
|
+
if (vals.every((v) => typeof v === "boolean"))
|
|
369
|
+
json.type = "string";
|
|
370
|
+
if (vals.every((v) => v === null))
|
|
371
|
+
json.type = "null";
|
|
363
372
|
json.enum = vals;
|
|
364
373
|
}
|
|
365
374
|
break;
|
|
@@ -692,23 +692,13 @@ export function check(fn, params) {
|
|
|
692
692
|
return ch;
|
|
693
693
|
}
|
|
694
694
|
// ZodCustom
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
type: "custom",
|
|
699
|
-
check: "custom",
|
|
700
|
-
fn: fn,
|
|
701
|
-
...params,
|
|
702
|
-
});
|
|
703
|
-
return schema;
|
|
695
|
+
// custom schema
|
|
696
|
+
export function custom(fn, _params) {
|
|
697
|
+
return core._custom(ZodMiniCustom, fn ?? (() => true), _params);
|
|
704
698
|
}
|
|
705
699
|
// refine
|
|
706
700
|
export function refine(fn, _params = {}) {
|
|
707
|
-
return
|
|
708
|
-
}
|
|
709
|
-
// custom schema
|
|
710
|
-
export function custom(fn, _params) {
|
|
711
|
-
return _custom(fn ?? (() => true), _params, ZodMiniCustom);
|
|
701
|
+
return core._refine(ZodMiniCustom, fn, _params);
|
|
712
702
|
}
|
|
713
703
|
// instanceof
|
|
714
704
|
class Class {
|
|
@@ -255,7 +255,7 @@ export type $ZodPromiseParams = TypeParams<schemas.$ZodPromise, "innerType">;
|
|
|
255
255
|
export declare function _promise<T extends schemas.$ZodObject>(Class: util.SchemaClass<schemas.$ZodPromise>, innerType: T): schemas.$ZodPromise<T>;
|
|
256
256
|
export type $ZodCustomParams = CheckTypeParams<schemas.$ZodCustom, "fn">;
|
|
257
257
|
export declare function _custom<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
|
258
|
-
export declare function _refine<
|
|
258
|
+
export declare function _refine<O = unknown, I = O>(Class: util.SchemaClass<schemas.$ZodCustom>, fn: (data: O) => unknown, _params: string | $ZodCustomParams | undefined): schemas.$ZodCustom<O, I>;
|
|
259
259
|
export interface $ZodStringBoolParams extends TypeParams {
|
|
260
260
|
truthy?: string[];
|
|
261
261
|
falsy?: string[];
|
|
@@ -375,8 +375,8 @@ export interface ZodMiniCustom<O = unknown, I = unknown> extends ZodMiniType {
|
|
|
375
375
|
}
|
|
376
376
|
export declare const ZodMiniCustom: core.$constructor<ZodMiniCustom>;
|
|
377
377
|
export declare function check<O = unknown>(fn: core.CheckFn<O>, params?: string | core.$ZodCustomParams): core.$ZodCheck<O>;
|
|
378
|
-
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
379
378
|
export declare function custom<O = unknown, I = O>(fn?: (data: O) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodMiniCustom<O, I>;
|
|
379
|
+
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
380
380
|
declare abstract class Class {
|
|
381
381
|
constructor(..._args: any[]);
|
|
382
382
|
}
|
package/package.json
CHANGED