zod 3.13.3 → 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 +6 -0
- package/lib/index.mjs +13 -5
- package/lib/types.d.ts +1 -0
- package/lib/types.js +13 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -555,6 +555,12 @@ FruitEnum.parse(3); // passes
|
|
|
555
555
|
FruitEnum.parse("Cantaloupe"); // fails
|
|
556
556
|
```
|
|
557
557
|
|
|
558
|
+
You can access the underlying object with the `.enum` property:
|
|
559
|
+
|
|
560
|
+
```ts
|
|
561
|
+
FruitEnum.enum.Apple; // "apple"
|
|
562
|
+
```
|
|
563
|
+
|
|
558
564
|
## Optionals
|
|
559
565
|
|
|
560
566
|
You can make any schema optional with `z.optional()`:
|
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
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -572,6 +572,7 @@ declare type EnumLike = {
|
|
|
572
572
|
};
|
|
573
573
|
export declare class ZodNativeEnum<T extends EnumLike> extends ZodType<T[keyof T], ZodNativeEnumDef<T>> {
|
|
574
574
|
_parse(input: ParseInput): ParseReturnType<T[keyof T]>;
|
|
575
|
+
get enum(): T;
|
|
575
576
|
static create: <T_1 extends EnumLike>(values: T_1, params?: RawCreateParams) => ZodNativeEnum<T_1>;
|
|
576
577
|
}
|
|
577
578
|
export interface ZodPromiseDef<T extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
|
package/lib/types.js
CHANGED
|
@@ -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
|
};
|