zod 3.13.0 → 3.13.4
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 +45 -28
- package/lib/external.js +5 -1
- package/lib/index.js +5 -1
- package/lib/index.mjs +40 -7
- package/lib/types.d.ts +14 -3
- package/lib/types.js +41 -7
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -10,23 +10,19 @@
|
|
|
10
10
|
<a href="./src/__tests__" rel="nofollow"><img src="./coverage.svg" alt="coverage"></a>
|
|
11
11
|
<a href="https://discord.gg/KaSRdyX2vc" rel="nofollow"><img src="https://img.shields.io/discord/893487829802418277?label=Discord&logo=discord&logoColor=white" alt="discord server"></a>
|
|
12
12
|
</p>
|
|
13
|
-
<p align="center">
|
|
14
|
-
by <a href="https://twitter.com/colinhacks">@colinhacks</a>
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
> Hi! Colin here, creator of Zod. I hope you find it easy to use and powerful enough for all your use cases. If you have any issues or suggestions, please [open an issue](https://github.com/colinhacks/zod/issues/new)!
|
|
18
|
-
>
|
|
19
|
-
> If you like typesafety, check out my other library [tRPC](https://trpc.io). It works in concert with Zod to provide a seamless way to build end-to-end typesafe APIs without GraphQL or code generation — just TypeScript.
|
|
20
|
-
>
|
|
21
|
-
> Colin (AKA [@colinhacks](https://twitter.com/colinhacks))
|
|
22
13
|
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
14
|
+
<div align="center">
|
|
15
|
+
<a href="https://discord.gg/RcG33DQJdf">Discord</a>
|
|
16
|
+
<span> • </span>
|
|
17
|
+
<a href="https://www.npmjs.com/package/zod">NPM</a>
|
|
18
|
+
<span> • </span>
|
|
19
|
+
<a href="https://github.com/colinhacks/zod/issues/new">Issues</a>
|
|
20
|
+
<span> • </span>
|
|
21
|
+
<a href="https://twitter.com/colinhacks">@colinhacks</a>
|
|
22
|
+
<span> • </span>
|
|
23
|
+
<a href="https://trpc.io">tRPC</a>
|
|
24
|
+
<br />
|
|
25
|
+
</div>
|
|
30
26
|
|
|
31
27
|
<br/>
|
|
32
28
|
|
|
@@ -34,6 +30,10 @@ These docs have been translated into [Chinese](./README_ZH.md).
|
|
|
34
30
|
|
|
35
31
|
# Table of contents
|
|
36
32
|
|
|
33
|
+
The full documentation is available both on the [official documentation site](https://zod.js.org/) (recommended) and in `README.md`.
|
|
34
|
+
|
|
35
|
+
### Go to [zod.js.org](https://zod.js.org) >>
|
|
36
|
+
|
|
37
37
|
- [What is Zod](#what-is-zod)
|
|
38
38
|
- [Installation](#installation)
|
|
39
39
|
- [Ecosystem](#ecosystem)
|
|
@@ -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.
|
|
@@ -415,26 +427,25 @@ const isActive = z.boolean({
|
|
|
415
427
|
```
|
|
416
428
|
|
|
417
429
|
## Dates
|
|
430
|
+
|
|
418
431
|
z.date() accepts a date, not a date string
|
|
432
|
+
|
|
419
433
|
```ts
|
|
420
|
-
z.date().safeParse(
|
|
421
|
-
z.date().safeParse(
|
|
434
|
+
z.date().safeParse(new Date()); // success: true
|
|
435
|
+
z.date().safeParse("2022-01-12T00:00:00.000Z"); // success: false
|
|
422
436
|
```
|
|
423
437
|
|
|
424
438
|
To allow for dates or date strings, you can use preprocess
|
|
439
|
+
|
|
425
440
|
```ts
|
|
426
|
-
const dateSchema = z.preprocess(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
},
|
|
431
|
-
z.date()
|
|
432
|
-
)
|
|
433
|
-
type DateSchema = z.infer<typeof dateSchema>
|
|
441
|
+
const dateSchema = z.preprocess((arg) => {
|
|
442
|
+
if (typeof arg == "string" || arg instanceof Date) return new Date(arg);
|
|
443
|
+
}, z.date());
|
|
444
|
+
type DateSchema = z.infer<typeof dateSchema>;
|
|
434
445
|
// type DateSchema = Date
|
|
435
446
|
|
|
436
|
-
dateSchema.safeParse(
|
|
437
|
-
dateSchema.safeParse(
|
|
447
|
+
dateSchema.safeParse(new Date("1/12/22")); // success: true
|
|
448
|
+
dateSchema.safeParse("2022-01-12T00:00:00.000Z"); // success: true
|
|
438
449
|
```
|
|
439
450
|
|
|
440
451
|
## Zod enums
|
|
@@ -544,6 +555,12 @@ FruitEnum.parse(3); // passes
|
|
|
544
555
|
FruitEnum.parse("Cantaloupe"); // fails
|
|
545
556
|
```
|
|
546
557
|
|
|
558
|
+
You can access the underlying object with the `.enum` property:
|
|
559
|
+
|
|
560
|
+
```ts
|
|
561
|
+
FruitEnum.enum.Apple; // "apple"
|
|
562
|
+
```
|
|
563
|
+
|
|
547
564
|
## Optionals
|
|
548
565
|
|
|
549
566
|
You can make any schema optional with `z.optional()`:
|
package/lib/external.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/index.mjs
CHANGED
|
@@ -1690,9 +1690,11 @@ var objectUtil;
|
|
|
1690
1690
|
return __assign(__assign({}, first), second);
|
|
1691
1691
|
};
|
|
1692
1692
|
})(objectUtil || (objectUtil = {}));
|
|
1693
|
-
var AugmentFactory = function (def) {
|
|
1694
|
-
return
|
|
1695
|
-
}; };
|
|
1693
|
+
var AugmentFactory = function (def) {
|
|
1694
|
+
return function (augmentation) {
|
|
1695
|
+
return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
|
|
1696
|
+
};
|
|
1697
|
+
};
|
|
1696
1698
|
function deepPartialify(schema) {
|
|
1697
1699
|
if (schema instanceof ZodObject) {
|
|
1698
1700
|
var newShape_1 = {};
|
|
@@ -2737,8 +2739,7 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2737
2739
|
return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
|
|
2738
2740
|
case 2:
|
|
2739
2741
|
result = _a.sent();
|
|
2740
|
-
return [4 /*yield*/, this._def
|
|
2741
|
-
.returns._def.type
|
|
2742
|
+
return [4 /*yield*/, this._def.returns._def.type
|
|
2742
2743
|
.parseAsync(result, params)
|
|
2743
2744
|
.catch(function (e) {
|
|
2744
2745
|
error.addIssue(makeReturnsIssue(result, e));
|
|
@@ -2968,6 +2969,13 @@ var ZodNativeEnum = /** @class */ (function (_super) {
|
|
|
2968
2969
|
}
|
|
2969
2970
|
return OK(ctx.data);
|
|
2970
2971
|
};
|
|
2972
|
+
Object.defineProperty(ZodNativeEnum.prototype, "enum", {
|
|
2973
|
+
get: function () {
|
|
2974
|
+
return this._def.values;
|
|
2975
|
+
},
|
|
2976
|
+
enumerable: false,
|
|
2977
|
+
configurable: true
|
|
2978
|
+
});
|
|
2971
2979
|
ZodNativeEnum.create = function (values, params) {
|
|
2972
2980
|
return new ZodNativeEnum(__assign({ values: values, typeName: ZodFirstPartyTypeKind.ZodNativeEnum }, processCreateParams(params)));
|
|
2973
2981
|
};
|
|
@@ -3207,6 +3215,28 @@ var ZodDefault = /** @class */ (function (_super) {
|
|
|
3207
3215
|
};
|
|
3208
3216
|
return ZodDefault;
|
|
3209
3217
|
}(ZodType));
|
|
3218
|
+
var ZodNaN = /** @class */ (function (_super) {
|
|
3219
|
+
__extends(ZodNaN, _super);
|
|
3220
|
+
function ZodNaN() {
|
|
3221
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
3222
|
+
}
|
|
3223
|
+
ZodNaN.prototype._parse = function (input) {
|
|
3224
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
3225
|
+
if (ctx.parsedType !== ZodParsedType.nan) {
|
|
3226
|
+
addIssueToContext(ctx, {
|
|
3227
|
+
code: ZodIssueCode.invalid_type,
|
|
3228
|
+
expected: ZodParsedType.nan,
|
|
3229
|
+
received: ctx.parsedType,
|
|
3230
|
+
});
|
|
3231
|
+
return INVALID;
|
|
3232
|
+
}
|
|
3233
|
+
return { status: status.value, value: ctx.data };
|
|
3234
|
+
};
|
|
3235
|
+
ZodNaN.create = function (params) {
|
|
3236
|
+
return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
|
|
3237
|
+
};
|
|
3238
|
+
return ZodNaN;
|
|
3239
|
+
}(ZodType));
|
|
3210
3240
|
var custom = function (check, params) {
|
|
3211
3241
|
if (check)
|
|
3212
3242
|
return ZodAny.create().refine(check, params);
|
|
@@ -3219,6 +3249,7 @@ var ZodFirstPartyTypeKind;
|
|
|
3219
3249
|
(function (ZodFirstPartyTypeKind) {
|
|
3220
3250
|
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
3221
3251
|
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
3252
|
+
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
3222
3253
|
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
3223
3254
|
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
3224
3255
|
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
@@ -3256,6 +3287,7 @@ var instanceOfType = function (cls, params) {
|
|
|
3256
3287
|
};
|
|
3257
3288
|
var stringType = ZodString.create;
|
|
3258
3289
|
var numberType = ZodNumber.create;
|
|
3290
|
+
var nanType = ZodNaN.create;
|
|
3259
3291
|
var bigIntType = ZodBigInt.create;
|
|
3260
3292
|
var booleanType = ZodBoolean.create;
|
|
3261
3293
|
var dateType = ZodDate.create;
|
|
@@ -3337,6 +3369,7 @@ var mod = /*#__PURE__*/Object.freeze({
|
|
|
3337
3369
|
ZodOptional: ZodOptional,
|
|
3338
3370
|
ZodNullable: ZodNullable,
|
|
3339
3371
|
ZodDefault: ZodDefault,
|
|
3372
|
+
ZodNaN: ZodNaN,
|
|
3340
3373
|
custom: custom,
|
|
3341
3374
|
Schema: ZodType,
|
|
3342
3375
|
ZodSchema: ZodType,
|
|
@@ -3356,6 +3389,7 @@ var mod = /*#__PURE__*/Object.freeze({
|
|
|
3356
3389
|
lazy: lazyType,
|
|
3357
3390
|
literal: literalType,
|
|
3358
3391
|
map: mapType,
|
|
3392
|
+
nan: nanType,
|
|
3359
3393
|
nativeEnum: nativeEnumType,
|
|
3360
3394
|
never: neverType,
|
|
3361
3395
|
'null': nullType,
|
|
@@ -3386,5 +3420,4 @@ var mod = /*#__PURE__*/Object.freeze({
|
|
|
3386
3420
|
setErrorMap: setErrorMap
|
|
3387
3421
|
});
|
|
3388
3422
|
|
|
3389
|
-
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 };
|
|
3423
|
+
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, mod as default, 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,8 @@ 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
|
-
|
|
468
|
+
declare type RecordType<K extends string | number | symbol, V> = [string] extends [K] ? Record<K, V> : [number] extends [K] ? Record<K, V> : [symbol] extends [K] ? Record<K, V> : Partial<Record<K, V>>;
|
|
469
|
+
export declare class ZodRecord<Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny> extends ZodType<RecordType<Key["_output"], Value["_output"]>, ZodRecordDef<Key, Value>, RecordType<Key["_input"], Value["_input"]>> {
|
|
469
470
|
get keySchema(): Key;
|
|
470
471
|
get valueSchema(): Value;
|
|
471
472
|
_parse(input: ParseInput): ParseReturnType<this["_output"]>;
|
|
@@ -571,6 +572,7 @@ declare type EnumLike = {
|
|
|
571
572
|
};
|
|
572
573
|
export declare class ZodNativeEnum<T extends EnumLike> extends ZodType<T[keyof T], ZodNativeEnumDef<T>> {
|
|
573
574
|
_parse(input: ParseInput): ParseReturnType<T[keyof T]>;
|
|
575
|
+
get enum(): T;
|
|
574
576
|
static create: <T_1 extends EnumLike>(values: T_1, params?: RawCreateParams) => ZodNativeEnum<T_1>;
|
|
575
577
|
}
|
|
576
578
|
export interface ZodPromiseDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
|
|
@@ -638,6 +640,13 @@ export declare class ZodDefault<T extends ZodTypeAny> extends ZodType<util.noUnd
|
|
|
638
640
|
removeDefault(): T;
|
|
639
641
|
static create: <T_1 extends ZodTypeAny>(type: T_1, params?: RawCreateParams) => ZodOptional<T_1>;
|
|
640
642
|
}
|
|
643
|
+
export interface ZodNaNDef extends ZodTypeDef {
|
|
644
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN;
|
|
645
|
+
}
|
|
646
|
+
export declare class ZodNaN extends ZodType<number, ZodNaNDef> {
|
|
647
|
+
_parse(input: ParseInput): ParseReturnType<any>;
|
|
648
|
+
static create: (params?: RawCreateParams) => ZodNaN;
|
|
649
|
+
}
|
|
641
650
|
export declare const custom: <T>(check?: ((data: unknown) => any) | undefined, params?: Parameters<ZodTypeAny["refine"]>[1]) => ZodType<T, ZodTypeDef, T>;
|
|
642
651
|
export { ZodType as Schema, ZodType as ZodSchema };
|
|
643
652
|
export declare const late: {
|
|
@@ -646,6 +655,7 @@ export declare const late: {
|
|
|
646
655
|
export declare enum ZodFirstPartyTypeKind {
|
|
647
656
|
ZodString = "ZodString",
|
|
648
657
|
ZodNumber = "ZodNumber",
|
|
658
|
+
ZodNaN = "ZodNaN",
|
|
649
659
|
ZodBigInt = "ZodBigInt",
|
|
650
660
|
ZodBoolean = "ZodBoolean",
|
|
651
661
|
ZodDate = "ZodDate",
|
|
@@ -675,10 +685,11 @@ export declare enum ZodFirstPartyTypeKind {
|
|
|
675
685
|
ZodDefault = "ZodDefault",
|
|
676
686
|
ZodPromise = "ZodPromise"
|
|
677
687
|
}
|
|
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>;
|
|
688
|
+
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
689
|
declare const instanceOfType: <T extends new (...args: any[]) => any>(cls: T, params?: Parameters<ZodTypeAny["refine"]>[1]) => ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;
|
|
680
690
|
declare const stringType: (params?: RawCreateParams) => ZodString;
|
|
681
691
|
declare const numberType: (params?: RawCreateParams) => ZodNumber;
|
|
692
|
+
declare const nanType: (params?: RawCreateParams) => ZodNaN;
|
|
682
693
|
declare const bigIntType: (params?: RawCreateParams) => ZodBigInt;
|
|
683
694
|
declare const booleanType: (params?: RawCreateParams) => ZodBoolean;
|
|
684
695
|
declare const dateType: (params?: RawCreateParams) => ZodDate;
|
|
@@ -711,4 +722,4 @@ declare const preprocessType: <I extends ZodTypeAny>(preprocess: (arg: unknown)
|
|
|
711
722
|
declare const ostring: () => ZodOptional<ZodString>;
|
|
712
723
|
declare const onumber: () => ZodOptional<ZodNumber>;
|
|
713
724
|
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, };
|
|
725
|
+
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.
|
|
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");
|
|
@@ -1111,9 +1111,11 @@ var objectUtil;
|
|
|
1111
1111
|
return __assign(__assign({}, first), second);
|
|
1112
1112
|
};
|
|
1113
1113
|
})(objectUtil = exports.objectUtil || (exports.objectUtil = {}));
|
|
1114
|
-
var AugmentFactory = function (def) {
|
|
1115
|
-
return
|
|
1116
|
-
}; };
|
|
1114
|
+
var AugmentFactory = function (def) {
|
|
1115
|
+
return function (augmentation) {
|
|
1116
|
+
return new ZodObject(__assign(__assign({}, def), { shape: function () { return (__assign(__assign({}, def.shape()), augmentation)); } }));
|
|
1117
|
+
};
|
|
1118
|
+
};
|
|
1117
1119
|
function deepPartialify(schema) {
|
|
1118
1120
|
if (schema instanceof ZodObject) {
|
|
1119
1121
|
var newShape_1 = {};
|
|
@@ -2167,8 +2169,7 @@ var ZodFunction = /** @class */ (function (_super) {
|
|
|
2167
2169
|
return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(parsedArgs), false))];
|
|
2168
2170
|
case 2:
|
|
2169
2171
|
result = _a.sent();
|
|
2170
|
-
return [4 /*yield*/, this._def
|
|
2171
|
-
.returns._def.type
|
|
2172
|
+
return [4 /*yield*/, this._def.returns._def.type
|
|
2172
2173
|
.parseAsync(result, params)
|
|
2173
2174
|
.catch(function (e) {
|
|
2174
2175
|
error.addIssue(makeReturnsIssue(result, e));
|
|
@@ -2402,6 +2403,13 @@ var ZodNativeEnum = /** @class */ (function (_super) {
|
|
|
2402
2403
|
}
|
|
2403
2404
|
return (0, parseUtil_1.OK)(ctx.data);
|
|
2404
2405
|
};
|
|
2406
|
+
Object.defineProperty(ZodNativeEnum.prototype, "enum", {
|
|
2407
|
+
get: function () {
|
|
2408
|
+
return this._def.values;
|
|
2409
|
+
},
|
|
2410
|
+
enumerable: false,
|
|
2411
|
+
configurable: true
|
|
2412
|
+
});
|
|
2405
2413
|
ZodNativeEnum.create = function (values, params) {
|
|
2406
2414
|
return new ZodNativeEnum(__assign({ values: values, typeName: ZodFirstPartyTypeKind.ZodNativeEnum }, processCreateParams(params)));
|
|
2407
2415
|
};
|
|
@@ -2648,6 +2656,29 @@ var ZodDefault = /** @class */ (function (_super) {
|
|
|
2648
2656
|
return ZodDefault;
|
|
2649
2657
|
}(ZodType));
|
|
2650
2658
|
exports.ZodDefault = ZodDefault;
|
|
2659
|
+
var ZodNaN = /** @class */ (function (_super) {
|
|
2660
|
+
__extends(ZodNaN, _super);
|
|
2661
|
+
function ZodNaN() {
|
|
2662
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2663
|
+
}
|
|
2664
|
+
ZodNaN.prototype._parse = function (input) {
|
|
2665
|
+
var _a = this._processInputParams(input), status = _a.status, ctx = _a.ctx;
|
|
2666
|
+
if (ctx.parsedType !== parseUtil_1.ZodParsedType.nan) {
|
|
2667
|
+
(0, parseUtil_1.addIssueToContext)(ctx, {
|
|
2668
|
+
code: ZodError_1.ZodIssueCode.invalid_type,
|
|
2669
|
+
expected: parseUtil_1.ZodParsedType.nan,
|
|
2670
|
+
received: ctx.parsedType,
|
|
2671
|
+
});
|
|
2672
|
+
return parseUtil_1.INVALID;
|
|
2673
|
+
}
|
|
2674
|
+
return { status: status.value, value: ctx.data };
|
|
2675
|
+
};
|
|
2676
|
+
ZodNaN.create = function (params) {
|
|
2677
|
+
return new ZodNaN(__assign({ typeName: ZodFirstPartyTypeKind.ZodNaN }, processCreateParams(params)));
|
|
2678
|
+
};
|
|
2679
|
+
return ZodNaN;
|
|
2680
|
+
}(ZodType));
|
|
2681
|
+
exports.ZodNaN = ZodNaN;
|
|
2651
2682
|
var custom = function (check, params) {
|
|
2652
2683
|
if (check)
|
|
2653
2684
|
return ZodAny.create().refine(check, params);
|
|
@@ -2661,6 +2692,7 @@ var ZodFirstPartyTypeKind;
|
|
|
2661
2692
|
(function (ZodFirstPartyTypeKind) {
|
|
2662
2693
|
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
2663
2694
|
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
2695
|
+
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
2664
2696
|
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
2665
2697
|
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
2666
2698
|
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
@@ -2701,6 +2733,8 @@ var stringType = ZodString.create;
|
|
|
2701
2733
|
exports.string = stringType;
|
|
2702
2734
|
var numberType = ZodNumber.create;
|
|
2703
2735
|
exports.number = numberType;
|
|
2736
|
+
var nanType = ZodNaN.create;
|
|
2737
|
+
exports.nan = nanType;
|
|
2704
2738
|
var bigIntType = ZodBigInt.create;
|
|
2705
2739
|
exports.bigint = bigIntType;
|
|
2706
2740
|
var booleanType = ZodBoolean.create;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "3.13.
|
|
3
|
+
"version": "3.13.4",
|
|
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
|
},
|
|
@@ -100,6 +101,5 @@
|
|
|
100
101
|
"yarn fix:lint",
|
|
101
102
|
"yarn fix:format"
|
|
102
103
|
]
|
|
103
|
-
}
|
|
104
|
-
"dependencies": {}
|
|
104
|
+
}
|
|
105
105
|
}
|