zod 3.13.0 → 3.13.2

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/README.md CHANGED
@@ -43,6 +43,7 @@ These docs have been translated into [Chinese](./README_ZH.md).
43
43
  - [Literals](#literals)
44
44
  - [Strings](#strings)
45
45
  - [Numbers](#numbers)
46
+ - [NaNs](#nans)
46
47
  - [Booleans](#booleans)
47
48
  - [Dates](#dates)
48
49
  - [Zod enums](#zod-enums)
@@ -403,6 +404,17 @@ Optionally, you can pass in a second argument to provide a custom error message.
403
404
  z.number().lte(5, { message: "this👏is👏too👏big" });
404
405
  ```
405
406
 
407
+ ## NaNs
408
+
409
+ You can customize certain error messages when creating a nan schema.
410
+
411
+ ```ts
412
+ const isNaN = z.nan({
413
+ required_error: "isNaN is required",
414
+ invalid_type_error: "isNaN must be not a number",
415
+ });
416
+ ```
417
+
406
418
  ## Booleans
407
419
 
408
420
  You can customize certain error messages when creating a boolean schema.
package/lib/index.mjs CHANGED
@@ -3207,6 +3207,28 @@ var ZodDefault = /** @class */ (function (_super) {
3207
3207
  };
3208
3208
  return ZodDefault;
3209
3209
  }(ZodType));
3210
+ var ZodNaN = /** @class */ (function (_super) {
3211
+ __extends(ZodNaN, _super);
3212
+ function ZodNaN() {
3213
+ return _super !== null && _super.apply(this, arguments) || this;
3214
+ }
3215
+ ZodNaN.prototype._parse = function (input) {
3216
+ var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
3217
+ if (ctx.parsedType !== ZodParsedType.nan) {
3218
+ addIssueToContext(ctx, {
3219
+ code: ZodIssueCode.invalid_type,
3220
+ expected: ZodParsedType.nan,
3221
+ received: ctx.parsedType,
3222
+ });
3223
+ return INVALID;
3224
+ }
3225
+ return { status: status.value, value: ctx.data };
3226
+ };
3227
+ ZodNaN.create = function (params) {
3228
+ return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
3229
+ };
3230
+ return ZodNaN;
3231
+ }(ZodType));
3210
3232
  var custom = function (check, params) {
3211
3233
  if (check)
3212
3234
  return ZodAny.create().refine(check, params);
@@ -3219,6 +3241,7 @@ var ZodFirstPartyTypeKind;
3219
3241
  (function (ZodFirstPartyTypeKind) {
3220
3242
  ZodFirstPartyTypeKind["ZodString"] = "ZodString";
3221
3243
  ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
3244
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
3222
3245
  ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
3223
3246
  ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
3224
3247
  ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
@@ -3256,6 +3279,7 @@ var instanceOfType = function (cls, params) {
3256
3279
  };
3257
3280
  var stringType = ZodString.create;
3258
3281
  var numberType = ZodNumber.create;
3282
+ var nanType = ZodNaN.create;
3259
3283
  var bigIntType = ZodBigInt.create;
3260
3284
  var booleanType = ZodBoolean.create;
3261
3285
  var dateType = ZodDate.create;
@@ -3337,6 +3361,7 @@ var mod = /*#__PURE__*/Object.freeze({
3337
3361
  ZodOptional: ZodOptional,
3338
3362
  ZodNullable: ZodNullable,
3339
3363
  ZodDefault: ZodDefault,
3364
+ ZodNaN: ZodNaN,
3340
3365
  custom: custom,
3341
3366
  Schema: ZodType,
3342
3367
  ZodSchema: ZodType,
@@ -3356,6 +3381,7 @@ var mod = /*#__PURE__*/Object.freeze({
3356
3381
  lazy: lazyType,
3357
3382
  literal: literalType,
3358
3383
  map: mapType,
3384
+ nan: nanType,
3359
3385
  nativeEnum: nativeEnumType,
3360
3386
  never: neverType,
3361
3387
  'null': nullType,
@@ -3387,4 +3413,4 @@ var mod = /*#__PURE__*/Object.freeze({
3387
3413
  });
3388
3414
 
3389
3415
  export default mod;
3390
- export { DIRTY, EMPTY_PATH, INVALID, OK, ParseStatus, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodError, ZodFirstPartyTypeKind, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNativeEnum, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPromise, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, addIssueToContext, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, custom, dateType as date, defaultErrorMap, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAborted, isAsync, isDirty, isValid, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, overrideErrorMap, preprocessType as preprocess, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, mod as z };
3416
+ export { DIRTY, EMPTY_PATH, INVALID, OK, ParseStatus, ZodType as Schema, ZodAny, ZodArray, ZodBigInt, ZodBoolean, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodError, ZodFirstPartyTypeKind, ZodFunction, ZodIntersection, ZodIssueCode, ZodLazy, ZodLiteral, ZodMap, ZodNaN, ZodNativeEnum, ZodNever, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodParsedType, ZodPromise, ZodRecord, ZodType as ZodSchema, ZodSet, ZodString, ZodEffects as ZodTransformer, ZodTuple, ZodType, ZodUndefined, ZodUnion, ZodUnknown, ZodVoid, addIssueToContext, anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, custom, dateType as date, defaultErrorMap, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, getParsedType, instanceOfType as instanceof, intersectionType as intersection, isAborted, isAsync, isDirty, isValid, late, lazyType as lazy, literalType as literal, makeIssue, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, objectUtil, oboolean, onumber, optionalType as optional, ostring, overrideErrorMap, preprocessType as preprocess, promiseType as promise, quotelessJson, recordType as record, setType as set, setErrorMap, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, mod as z };
package/lib/types.d.ts CHANGED
@@ -465,7 +465,7 @@ export interface ZodRecordDef<Key extends KeySchema = ZodString, Value extends Z
465
465
  typeName: ZodFirstPartyTypeKind.ZodRecord;
466
466
  }
467
467
  declare type KeySchema = ZodType<string | number | symbol, any, any>;
468
- export declare class ZodRecord<Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny> extends ZodType<Record<Key["_output"], Value["_output"]>, ZodRecordDef<Key, Value>, Record<Key["_input"], Value["_input"]>> {
468
+ export declare class ZodRecord<Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny> extends ZodType<Partial<Record<Key["_output"], Value["_output"]>>, ZodRecordDef<Key, Value>, Partial<Record<Key["_input"], Value["_input"]>>> {
469
469
  get keySchema(): Key;
470
470
  get valueSchema(): Value;
471
471
  _parse(input: ParseInput): ParseReturnType<this["_output"]>;
@@ -638,6 +638,13 @@ export declare class ZodDefault<T extends ZodTypeAny> extends ZodType<util.noUnd
638
638
  removeDefault(): T;
639
639
  static create: <T_1 extends ZodTypeAny>(type: T_1, params?: RawCreateParams) => ZodOptional<T_1>;
640
640
  }
641
+ export interface ZodNaNDef extends ZodTypeDef {
642
+ typeName: ZodFirstPartyTypeKind.ZodNaN;
643
+ }
644
+ export declare class ZodNaN extends ZodType<number, ZodNaNDef> {
645
+ _parse(input: ParseInput): ParseReturnType<any>;
646
+ static create: (params?: RawCreateParams) => ZodNaN;
647
+ }
641
648
  export declare const custom: <T>(check?: ((data: unknown) => any) | undefined, params?: Parameters<ZodTypeAny["refine"]>[1]) => ZodType<T, ZodTypeDef, T>;
642
649
  export { ZodType as Schema, ZodType as ZodSchema };
643
650
  export declare const late: {
@@ -646,6 +653,7 @@ export declare const late: {
646
653
  export declare enum ZodFirstPartyTypeKind {
647
654
  ZodString = "ZodString",
648
655
  ZodNumber = "ZodNumber",
656
+ ZodNaN = "ZodNaN",
649
657
  ZodBigInt = "ZodBigInt",
650
658
  ZodBoolean = "ZodBoolean",
651
659
  ZodDate = "ZodDate",
@@ -675,10 +683,11 @@ export declare enum ZodFirstPartyTypeKind {
675
683
  ZodDefault = "ZodDefault",
676
684
  ZodPromise = "ZodPromise"
677
685
  }
678
- export declare type ZodFirstPartySchemaTypes = ZodString | ZodNumber | ZodBigInt | ZodBoolean | ZodDate | ZodUndefined | ZodNull | ZodAny | ZodUnknown | ZodNever | ZodVoid | ZodArray<any, any> | ZodObject<any, any, any, any, any> | ZodUnion<any> | ZodIntersection<any, any> | ZodTuple<any, any> | ZodRecord<any, any> | ZodMap<any> | ZodSet<any> | ZodFunction<any, any> | ZodLazy<any> | ZodLiteral<any> | ZodEnum<any> | ZodEffects<any, any, any> | ZodNativeEnum<any> | ZodOptional<any> | ZodNullable<any> | ZodDefault<any> | ZodPromise<any>;
686
+ export declare type ZodFirstPartySchemaTypes = ZodString | ZodNumber | ZodNaN | ZodBigInt | ZodBoolean | ZodDate | ZodUndefined | ZodNull | ZodAny | ZodUnknown | ZodNever | ZodVoid | ZodArray<any, any> | ZodObject<any, any, any, any, any> | ZodUnion<any> | ZodIntersection<any, any> | ZodTuple<any, any> | ZodRecord<any, any> | ZodMap<any> | ZodSet<any> | ZodFunction<any, any> | ZodLazy<any> | ZodLiteral<any> | ZodEnum<any> | ZodEffects<any, any, any> | ZodNativeEnum<any> | ZodOptional<any> | ZodNullable<any> | ZodDefault<any> | ZodPromise<any>;
679
687
  declare const instanceOfType: <T extends new (...args: any[]) => any>(cls: T, params?: Parameters<ZodTypeAny["refine"]>[1]) => ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;
680
688
  declare const stringType: (params?: RawCreateParams) => ZodString;
681
689
  declare const numberType: (params?: RawCreateParams) => ZodNumber;
690
+ declare const nanType: (params?: RawCreateParams) => ZodNaN;
682
691
  declare const bigIntType: (params?: RawCreateParams) => ZodBigInt;
683
692
  declare const booleanType: (params?: RawCreateParams) => ZodBoolean;
684
693
  declare const dateType: (params?: RawCreateParams) => ZodDate;
@@ -711,4 +720,4 @@ declare const preprocessType: <I extends ZodTypeAny>(preprocess: (arg: unknown)
711
720
  declare const ostring: () => ZodOptional<ZodString>;
712
721
  declare const onumber: () => ZodOptional<ZodNumber>;
713
722
  declare const oboolean: () => ZodOptional<ZodBoolean>;
714
- export { anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, dateType as date, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, instanceOfType as instanceof, intersectionType as intersection, lazyType as lazy, literalType as literal, mapType as map, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, oboolean, onumber, optionalType as optional, ostring, preprocessType as preprocess, promiseType as promise, recordType as record, setType as set, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, };
723
+ export { anyType as any, arrayType as array, bigIntType as bigint, booleanType as boolean, dateType as date, discriminatedUnionType as discriminatedUnion, effectsType as effect, enumType as enum, functionType as function, instanceOfType as instanceof, intersectionType as intersection, lazyType as lazy, literalType as literal, mapType as map, nanType as nan, nativeEnumType as nativeEnum, neverType as never, nullType as null, nullableType as nullable, numberType as number, objectType as object, oboolean, onumber, optionalType as optional, ostring, preprocessType as preprocess, promiseType as promise, recordType as record, setType as set, strictObjectType as strictObject, stringType as string, effectsType as transformer, tupleType as tuple, undefinedType as undefined, unionType as union, unknownType as unknown, voidType as void, };
package/lib/types.js CHANGED
@@ -98,8 +98,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
98
98
  return to.concat(ar || Array.prototype.slice.call(from));
99
99
  };
100
100
  Object.defineProperty(exports, "__esModule", { value: true });
101
- exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = exports.discriminatedUnion = exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.custom = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.objectUtil = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
102
- exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.map = exports.literal = void 0;
101
+ exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = exports.discriminatedUnion = exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.custom = exports.ZodNaN = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.objectUtil = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
102
+ exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = void 0;
103
103
  var errorUtil_1 = require("./helpers/errorUtil");
104
104
  var parseUtil_1 = require("./helpers/parseUtil");
105
105
  var util_1 = require("./helpers/util");
@@ -2648,6 +2648,29 @@ var ZodDefault = /** @class */ (function (_super) {
2648
2648
  return ZodDefault;
2649
2649
  }(ZodType));
2650
2650
  exports.ZodDefault = ZodDefault;
2651
+ var ZodNaN = /** @class */ (function (_super) {
2652
+ __extends(ZodNaN, _super);
2653
+ function ZodNaN() {
2654
+ return _super !== null && _super.apply(this, arguments) || this;
2655
+ }
2656
+ ZodNaN.prototype._parse = function (input) {
2657
+ var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
2658
+ if (ctx.parsedType !== parseUtil_1.ZodParsedType.nan) {
2659
+ (0, parseUtil_1.addIssueToContext)(ctx, {
2660
+ code: ZodError_1.ZodIssueCode.invalid_type,
2661
+ expected: parseUtil_1.ZodParsedType.nan,
2662
+ received: ctx.parsedType,
2663
+ });
2664
+ return parseUtil_1.INVALID;
2665
+ }
2666
+ return { status: status.value, value: ctx.data };
2667
+ };
2668
+ ZodNaN.create = function (params) {
2669
+ return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
2670
+ };
2671
+ return ZodNaN;
2672
+ }(ZodType));
2673
+ exports.ZodNaN = ZodNaN;
2651
2674
  var custom = function (check, params) {
2652
2675
  if (check)
2653
2676
  return ZodAny.create().refine(check, params);
@@ -2661,6 +2684,7 @@ var ZodFirstPartyTypeKind;
2661
2684
  (function (ZodFirstPartyTypeKind) {
2662
2685
  ZodFirstPartyTypeKind["ZodString"] = "ZodString";
2663
2686
  ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
2687
+ ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
2664
2688
  ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
2665
2689
  ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
2666
2690
  ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
@@ -2701,6 +2725,8 @@ var stringType = ZodString.create;
2701
2725
  exports.string = stringType;
2702
2726
  var numberType = ZodNumber.create;
2703
2727
  exports.number = numberType;
2728
+ var nanType = ZodNaN.create;
2729
+ exports.nan = nanType;
2704
2730
  var bigIntType = ZodBigInt.create;
2705
2731
  exports.bigint = bigIntType;
2706
2732
  var booleanType = ZodBoolean.create;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.13.0",
3
+ "version": "3.13.2",
4
4
  "description": "TypeScript-first schema declaration and validation library with static type inference",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -8,7 +8,8 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "require": "./lib/index.js",
11
- "import": "./lib/index.mjs"
11
+ "import": "./lib/index.mjs",
12
+ "types": "./lib/index.d.ts"
12
13
  },
13
14
  "./package.json": "./package.json"
14
15
  },