Socket
Socket
Sign inDemoInstall

zod

Package Overview
Dependencies
Maintainers
1
Versions
361
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod - npm Package Compare versions

Comparing version 1.11.0-alpha.5 to 1.11.0-alpha.6

3

lib/src/defaultErrorMap.js

@@ -83,2 +83,5 @@ "use strict";

break;
case ZodError_1.ZodErrorCode.invalid_intersection_types:
message = "Intersections only support ";
break;
default:

@@ -85,0 +88,0 @@ message = "Invalid input.";

@@ -28,2 +28,8 @@ import { ZodRawShape } from '../types/base';

}>;
type ObjectIntersectionInput<T extends ZodRawShape> = AddQuestionMarks<{
[k in keyof T]: T[k]['_input'];
}>;
type ObjectIntersectionOutput<T extends ZodRawShape> = AddQuestionMarks<{
[k in keyof T]: T[k]['_input'];
}>;
type Identity<T> = T;

@@ -40,4 +46,6 @@ type FlattenObject<T extends ZodRawShape> = Identity<{

type ObjectType<T extends ZodRawShape> = FlattenObject<ObjectIntersection<NoNever<T>>>;
type ObjectTypeInput<T extends ZodRawShape> = FlattenObject<ObjectIntersectionInput<NoNever<T>>>;
type ObjectTypeOutput<T extends ZodRawShape> = FlattenObject<ObjectIntersectionOutput<NoNever<T>>>;
const mergeShapes: <U extends ZodRawShape, T extends ZodRawShape>(first: U, second: T) => T & U;
const mergeObjects: <First extends ZodObject<any, any, any>>(first: First) => <Second extends ZodObject<any, any, any>>(second: Second) => ZodObject<First["_shape"] & Second["_shape"], MergeObjectParams<First["_params"], Second["_params"]>, First["_type"] & Second["_type"]>;
}

8

lib/src/index.d.ts

@@ -23,3 +23,3 @@ import { ZodString, ZodStringDef } from './types/string';

import { ZodTransformer, ZodTransformerDef } from './types/transformer';
import { TypeOf, ZodType, ZodTypeAny, ZodTypeDef, ZodTypes } from './types/base';
import { TypeOf, input, output, ZodType, ZodTypeAny, ZodTypeDef, ZodTypes } from './types/base';
import { ZodError, ZodErrorCode } from './ZodError';

@@ -45,5 +45,5 @@ import { ZodParsedType } from './parser';

}, { [k in keyof ({ [k in { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]]?: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] | undefined; } & { [k in Exclude<{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T], { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]>]: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k]; })]: ({ [k in { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]]?: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] | undefined; } & { [k in Exclude<{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T], { [k in keyof { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }]: undefined extends { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k] ? k : never; }[{ [k in keyof T]: T[k] extends never ? never : k; }[keyof T]]>]: { [k in keyof import("./helpers/objectUtil").objectUtil.NoNever<T>]: import("./helpers/objectUtil").objectUtil.NoNever<T>[k]["_type"]; }[k]; })[k]; }>;
declare const unionType: <T extends [ZodType<any, any>, ZodType<any, any>, ...ZodType<any, any>[]]>(types: T) => ZodUnion<T>;
declare const unionType: <T extends [ZodType<any, any>, ...ZodType<any, any>[]]>(types: T) => ZodUnion<T>;
declare const intersectionType: <T extends ZodType<any, any>, U extends ZodType<any, any>>(left: T, right: U) => ZodIntersection<T, U>;
declare const tupleType: <T extends [] | [ZodType<any, any>, ...ZodType<any, any>[]]>(schemas: T) => ZodTuple<T>;
declare const tupleType: <T extends [ZodType<any, any>, ...ZodType<any, any>[]] | []>(schemas: T) => ZodTuple<T>;
declare const recordType: <Value extends ZodType<any, any> = ZodType<any, any>>(valueType: Value) => ZodRecord<Value>;

@@ -71,2 +71,2 @@ declare const functionType: <T extends ZodTuple<any> = ZodTuple<[]>, U extends ZodType<any, any> = ZodVoid>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;

export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodTransformer, ZodType, ZodType as Schema, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodError, ZodErrorMap, ZodErrorCode, ZodParsedType, ZodCodeGenerator, };
export { TypeOf, TypeOf as infer };
export { TypeOf, TypeOf as infer, input, output };

@@ -37,3 +37,3 @@ import * as z from './types/base';

};
export declare const ZodParser: (schemaDef: z.ZodTypeDef) => (obj: any, baseParams?: ParseParams) => any;
export declare const ZodParser: (schemaDef: z.ZodTypeDef) => (data: any, baseParams?: ParseParams) => any;
export {};

@@ -122,3 +122,3 @@ "use strict";

]);
exports.ZodParser = function (schemaDef) { return function (obj, baseParams) {
exports.ZodParser = function (schemaDef) { return function (data, baseParams) {
if (baseParams === void 0) { baseParams = { seen: [], errorMap: defaultErrorMap_1.defaultErrorMap, path: [] }; }

@@ -132,3 +132,3 @@ var params = {

var errorArg = __assign({}, errorData, { path: params.path });
var ctxArg = { data: obj };
var ctxArg = { data: data };
var defaultError = defaultErrorMap_1.defaultErrorMap === params.errorMap

@@ -142,16 +142,16 @@ ? { message: "Invalid value." }

if (schemaSeen) {
if (schemaSeen.objects.indexOf(obj) !== -1) {
return obj;
if (schemaSeen.objects.indexOf(data) !== -1) {
return data;
}
else {
schemaSeen.objects.push(obj);
schemaSeen.objects.push(data);
}
}
else {
params.seen.push({ schema: schemaDef, objects: [obj] });
params.seen.push({ schema: schemaDef, objects: [data] });
}
// }
var error = new ZodError_1.ZodError([]);
var returnValue = obj;
var parsedType = exports.getParsedType(obj);
var returnValue = data;
var parsedType = exports.getParsedType(data);
switch (def.t) {

@@ -169,3 +169,3 @@ case z.ZodTypes.string:

}
if (Number.isNaN(obj)) {
if (Number.isNaN(data)) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ZodParsedType.number, received: exports.ZodParsedType.nan }));

@@ -214,11 +214,10 @@ throw error;

}
var data = obj;
if (def.nonempty === true && obj.length === 0) {
// const data: any[] = data;
if (def.nonempty === true && data.length === 0) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.nonempty_array_is_empty }));
throw error;
}
data.map(function (item, i) {
returnValue = data.map(function (item, i) {
try {
var parsedItem = def.type.parse(item, __assign({}, params, { path: params.path.concat([i]) }));
return parsedItem;
return def.type.parse(item, __assign({}, params, { path: params.path.concat([i]) }));
}

@@ -239,14 +238,21 @@ catch (err) {

}
var parsedobject = {};
var shape = def.shape();
if (def.params.strict) {
var shapeKeys_1 = Object.keys(shape);
var objKeys = Object.keys(obj);
var extraKeys = objKeys.filter(function (k) { return shapeKeys_1.indexOf(k) === -1; });
if (extraKeys.length) {
var shapeKeys_1 = Object.keys(shape);
var dataKeys = Object.keys(data);
var extraKeys = dataKeys.filter(function (k) { return shapeKeys_1.indexOf(k) === -1; });
if (extraKeys.length) {
if (def.params.strict) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.unrecognized_keys, keys: extraKeys }));
}
else {
for (var _i = 0, extraKeys_1 = extraKeys; _i < extraKeys_1.length; _i++) {
var key = extraKeys_1[_i];
parsedobject[key] = data[key];
}
}
}
for (var key in shape) {
try {
def.shape()[key].parse(obj[key], __assign({}, params, { path: params.path.concat([key]) }));
parsedobject[key] = def.shape()[key].parse(data[key], __assign({}, params, { path: params.path.concat([key]) }));
}

@@ -258,11 +264,14 @@ catch (err) {

}
returnValue = parsedobject;
break;
case z.ZodTypes.union:
var parsedUnion = void 0;
var isValid = false;
var unionErrors = [];
for (var _i = 0, _a = def.options; _i < _a.length; _i++) {
var option = _a[_i];
for (var _a = 0, _b = def.options; _a < _b.length; _a++) {
var option = _b[_a];
try {
option.parse(obj, params);
parsedUnion = option.parse(data, params);
isValid = true;
break;
}

@@ -287,6 +296,10 @@ catch (err) {

}
returnValue = parsedUnion;
break;
case z.ZodTypes.intersection:
// let parsedIntersection:any;
var parsedLeft = void 0;
var parsedRight = void 0;
try {
def.left.parse(obj, params);
parsedLeft = def.left.parse(data, params);
}

@@ -297,3 +310,3 @@ catch (err) {

try {
def.right.parse(obj, params);
parsedRight = def.right.parse(data, params);
}

@@ -303,2 +316,15 @@ catch (err) {

}
var parsedLeftType = exports.getParsedType(parsedLeft);
var parsedRightType = exports.getParsedType(parsedRight);
if (parsedLeft === parsedRight) {
returnValue = parsedLeft;
}
else if (parsedLeftType === exports.ZodParsedType.object && parsedRightType === exports.ZodParsedType.object) {
returnValue = __assign({}, parsedLeft, parsedRight);
}
else {
error.addError(makeError({
code: ZodError_1.ZodErrorCode.invalid_intersection_types,
}));
}
break;

@@ -310,10 +336,11 @@ case z.ZodTypes.tuple:

}
if (obj.length > def.items.length) {
if (data.length > def.items.length) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.too_big, maximum: def.items.length, inclusive: true, type: 'array' }));
}
else if (obj.length < def.items.length) {
else if (data.length < def.items.length) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.too_small, minimum: def.items.length, inclusive: true, type: 'array' }));
}
// const parsedTuple: any[] = [];
var tupleData = data;
var parsedTuple = [];
var tupleData = obj;
for (var index in tupleData) {

@@ -329,14 +356,16 @@ var item = tupleData[index];

}
returnValue = parsedTuple;
break;
case z.ZodTypes.lazy:
var lazySchema = def.getter();
lazySchema.parse(obj, params);
returnValue = lazySchema.parse(data, params);
break;
case z.ZodTypes.literal:
if (obj !== def.value) {
if (data !== def.value) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_literal_value, expected: def.value }));
}
returnValue = data;
break;
case z.ZodTypes.enum:
if (def.values.indexOf(obj) === -1) {
if (def.values.indexOf(data) === -1) {
error.addError(makeError({

@@ -347,2 +376,3 @@ code: ZodError_1.ZodErrorCode.invalid_enum_value,

}
returnValue = data;
break;

@@ -377,3 +407,3 @@ case z.ZodTypes.function:

}
var result = obj.apply(void 0, args);
var result = data.apply(void 0, args);
try {

@@ -394,3 +424,5 @@ return def.returns.parse(result);

};
return validatedFunc;
returnValue = validatedFunc;
// return validatedFunc;
break;
case z.ZodTypes.record:

@@ -405,5 +437,6 @@ if (parsedType !== exports.ZodParsedType.object) {

}
for (var key in obj) {
var parsedRecord = {};
for (var key in data) {
try {
def.valueType.parse(obj[key], __assign({}, params, { path: params.path.concat([key]) }));
parsedRecord[key] = def.valueType.parse(data[key], __assign({}, params, { path: params.path.concat([key]) }));
}

@@ -414,5 +447,6 @@ catch (err) {

}
returnValue = parsedRecord;
break;
case z.ZodTypes.date:
if (!(obj instanceof Date)) {
if (!(data instanceof Date)) {
error.addError(makeError({

@@ -425,3 +459,3 @@ code: ZodError_1.ZodErrorCode.invalid_type,

}
if (isNaN(obj.getTime())) {
if (isNaN(data.getTime())) {
console.log('NAN');

@@ -433,2 +467,3 @@ error.addError(makeError({

}
returnValue = data;
break;

@@ -444,11 +479,11 @@ case z.ZodTypes.promise:

}
return new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
var objValue, parsed;
returnValue = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
var dataValue, parsed;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, obj];
case 0: return [4 /*yield*/, data];
case 1:
objValue = _a.sent();
dataValue = _a.sent();
try {
parsed = def.type.parse(objValue, params);
parsed = def.type.parse(dataValue, params);
res(parsed);

@@ -463,5 +498,6 @@ }

}); });
break;
case z.ZodTypes.transformer:
// console.log(`input: "${obj}"`);
var inputParseResult = def.input.parse(obj);
// console.log(`input: "${data}"`);
var inputParseResult = def.input.parse(data);
// console.log(`inputParseResult: "${inputParseResult}"`);

@@ -476,4 +512,4 @@ var transformedResult = def.transformer(inputParseResult);

var customChecks = def.checks || [];
for (var _b = 0, customChecks_1 = customChecks; _b < customChecks_1.length; _b++) {
var check = customChecks_1[_b];
for (var _c = 0, customChecks_1 = customChecks; _c < customChecks_1.length; _c++) {
var check = customChecks_1[_c];
if (!check.check(returnValue)) {

@@ -480,0 +516,0 @@ var checkMethod = check.check, noMethodCheck = __rest(check, ["check"]);

"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var z = __importStar(require("."));
var trimAndMultiply = z
.transformer(z.string(), z.string(), function (x) {
return x.trim();
})
.transform(z.number(), function (x) {
return parseFloat(x);
})
.transform(z.number(), function (num) {
return num * 5;
})
.refine(function (x) {
return x > 20;
}, 'Number is too small');
console.log(trimAndMultiply.parse(' 5 '));
var stringToNumber = z.transformer(z.string(), z.number(), function (data) { return parseFloat(data); });
var myFunc = z
.function()
.args(stringToNumber)
.returns(z.boolean())
.implement(function (num) { return num > 5; });
myFunc(8);
// myFunc("8");
//# sourceMappingURL=playground.js.map
import { ParseParams, MakeErrorData } from '../parser';
import { util } from '../helpers/util';
import { ZodArray, ZodUnion, ZodNull, ZodUndefined } from '..';
import { ZodArray, ZodUnion, ZodNull, ZodUndefined, ZodTransformer } from '..';
import { CustomError } from '../ZodError';

@@ -48,6 +48,14 @@ export declare enum ZodTypes {

}> = T['_type'];
export declare type Infer<T extends {
export declare type input<T extends {
_input: any;
}> = T['_input'];
export declare type output<T extends {
_output: any;
}> = T['_output'];
export declare type infer<T extends {
_type: any;
}> = T['_type'];
export declare abstract class ZodType<Type, Def extends ZodTypeDef = ZodTypeDef> {
readonly _input: Type;
readonly _output: Type;
readonly _type: Type;

@@ -67,4 +75,6 @@ readonly _def: Def;

array: () => ZodArray<this>;
transform: <This extends this, U extends ZodType<any>, Tx extends (arg: This['_type']) => U['_type']>(x: U, transformer: Tx) => ZodTransformer<This, U>;
default: <T extends Type = Type, Opt extends ZodUnion<[this, ZodUndefined]> = ZodUnion<[this, ZodUndefined]>>(def: T) => ZodTransformer<Opt, this>;
or: <U extends ZodType<any>>(arg: U) => ZodUnion<[this, U]>;
}
export {};

@@ -76,8 +76,27 @@ "use strict";

// ) => any = (input, transformer) => 'adsf';
// accepts: <U extends ZodType<any>, Tx extends (arg: U['_type']) => this['_type']>(
// transformFrom: <U extends ZodType<any>, Tx extends (arg: U['_type']) => this['_type']>(
// x: U,
// transformer: Tx,
// ) => ZodCodec<U, this> = (input, transformer) => {
// return ZodCodec.create(input, this, transformer);
// ) => ZodTransformer<U, this> = (input, transformer) => {
// return ZodTransformer.create(input, this, transformer);
// };
// transformFrom: <This extends this, U extends ZodType<any>, Tx extends (arg: U['_type']) => this['_type']>(
// x: U,
// transformer: Tx,
// ) => ZodTransformer<This, U> = (input, transformer) => {
// return ZodTransformer.create(this as any, input, transformer) as any;
// };
this.transform = function (input, transformer) {
return __1.ZodTransformer.create(_this, input, transformer);
};
this.default = function (def) {
return __1.ZodTransformer.create(_this.optional(), _this, function (x) {
return (x || def);
});
};
// default: (val: Type) => ZodTransformer<ZodType<Type | undefined>, this> = val => {
// return ZodTransformer.create(this.optional(), this, x => {
// return (x || val) as any;
// }) as any;
// };
// codec = (): ZodCodec<this, this> => {

@@ -84,0 +103,0 @@ // return ZodCodec.create(this, this, x => x);

@@ -13,3 +13,3 @@ import * as z from './base';

readonly _type: TypeOfFunction<Args, Returns>;
args: <Items extends [] | [z.ZodType<any, any>, ...z.ZodType<any, any>[]]>(...items: Items) => ZodFunction<ZodTuple<Items>, Returns>;
args: <Items extends [z.ZodType<any, any>, ...z.ZodType<any, any>[]] | []>(...items: Items) => ZodFunction<ZodTuple<Items>, Returns>;
returns: <NewReturnType extends z.ZodType<any, any>>(returnType: NewReturnType) => ZodFunction<Args, NewReturnType>;

@@ -16,0 +16,0 @@ implement: (func: TypeOfFunction<Args, Returns>) => TypeOfFunction<Args, Returns>;

@@ -14,2 +14,6 @@ import * as z from './base';

}
declare type makeKeysRequired<T extends ZodObject<any, any>> = T extends ZodObject<infer U, infer P> ? ZodObject<objectUtil.NoNever<{
[k in keyof U]: makeRequired<U[k]>;
}>, P> : never;
declare type makeRequired<T extends z.ZodType<any>> = T extends ZodUnion<infer U> ? U extends [infer Y, ZodUndefined] ? Y : U extends [ZodUndefined, infer Z] ? Z : T : T;
declare type ZodObjectType<T extends z.ZodRawShape, Params extends ZodObjectParams> = Params['strict'] extends true ? objectUtil.ObjectType<T> : objectUtil.Flatten<objectUtil.ObjectType<T> & {

@@ -25,2 +29,3 @@ [k: string]: any;

readonly params: Params;
readonly t: this;
toJSON: () => {

@@ -48,2 +53,3 @@ t: z.ZodTypes.object;

partial: () => ZodObject<{ [k in keyof T]: ZodUnion<[T[k], ZodUndefined]>; }, Params, ZodObjectType<{ [k in keyof T]: ZodUnion<[T[k], ZodUndefined]>; }, Params>>;
require: () => makeKeysRequired<this>;
deepPartial: () => partialUtil.RootDeepPartial<this>;

@@ -50,0 +56,0 @@ static create: <T_1 extends z.ZodRawShape>(shape: T_1) => ZodObject<T_1, {

@@ -35,2 +35,5 @@ "use strict";

var z = __importStar(require("./base"));
var undefined_1 = require("./undefined");
// import { ZodNull } from './null';
var union_1 = require("./union");
var objectUtil_1 = require("../helpers/objectUtil");

@@ -94,2 +97,20 @@ var AugmentFactory = function (def) { return function (augmentation) {

};
_this.require = function () {
var newShape = {};
for (var key in _this.shape) {
var val = _this.shape[key];
if (val instanceof union_1.ZodUnion && val.options.length === 2) {
if (val.options[0] instanceof undefined_1.ZodUndefined) {
newShape[key] = val.options[1];
}
else if (val.options[1] instanceof undefined_1.ZodUndefined) {
newShape[key] = val.options[0];
}
}
else {
newShape[key] = val;
}
}
return new ZodObject(__assign({}, _this._def, { shape: function () { return newShape; } }));
};
_this.deepPartial = function () {

@@ -124,2 +145,9 @@ var newShape = {};

});
Object.defineProperty(ZodObject.prototype, "t", {
get: function () {
return this;
},
enumerable: true,
configurable: true
});
ZodObject.create = function (shape) {

@@ -126,0 +154,0 @@ return new ZodObject({

@@ -6,5 +6,7 @@ import * as z from './base';

output: U;
transformer: (arg: T['_type']) => U['_type'];
transformer: (arg: T['_input']) => U['_output'];
}
export declare class ZodTransformer<T extends z.ZodTypeAny, U extends z.ZodTypeAny> extends z.ZodType<U['_type'], ZodTransformerDef<T, U>> {
readonly _input: T['_input'];
readonly _output: U['_output'];
readonly input: T;

@@ -17,5 +19,4 @@ readonly output: U;

};
transform: <Out extends z.ZodTypeAny>(output: Out, transformer: (arg: U['_type']) => Out['_type']) => ZodTransformer<this, Out>;
static create: <I extends z.ZodType<any, any>, O extends z.ZodType<any, any>>(input: I, output: O, transformer: (arg: I["_type"]) => O["_type"]) => ZodTransformer<I, O>;
static fromSchema: <I extends z.ZodType<any, any>>(input: I) => ZodTransformer<I, I>;
}

@@ -33,5 +33,2 @@ "use strict";

}); };
_this.transform = function (output, transformer) {
return ZodTransformer.create(_this, output, transformer);
};
return _this;

@@ -55,2 +52,8 @@ }

});
// transformTo: <Out extends z.ZodTypeAny>(
// output: Out,
// transformer: (arg: U['_type']) => Out['_type'],
// ) => ZodTransformer<this, Out> = (output, transformer) => {
// return ZodTransformer.create(this as any, output, transformer) as any;
// };
ZodTransformer.create = function (input, output, transformer) {

@@ -57,0 +60,0 @@ return new ZodTransformer({

@@ -14,3 +14,3 @@ import * as z from './base';

};
static create: <T_1 extends [] | [z.ZodType<any, any>, ...z.ZodType<any, any>[]]>(schemas: T_1) => ZodTuple<T_1>;
static create: <T_1 extends [z.ZodType<any, any>, ...z.ZodType<any, any>[]] | []>(schemas: T_1) => ZodTuple<T_1>;
}
import * as z from './base';
export interface ZodUnionDef<T extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]] = [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodTypeDef {
export interface ZodUnionDef<T extends [z.ZodTypeAny, ...z.ZodTypeAny[]] = [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodTypeDef {
t: z.ZodTypes.union;
options: T;
}
export declare class ZodUnion<T extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodType<T[number]['_type'], ZodUnionDef<T>> {
export declare class ZodUnion<T extends [z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodType<T[number]['_type'], ZodUnionDef<T>> {
readonly options: T;
toJSON: () => {

@@ -11,3 +12,3 @@ t: z.ZodTypes.union;

};
static create: <T_1 extends [z.ZodType<any, any>, z.ZodType<any, any>, ...z.ZodType<any, any>[]]>(types: T_1) => ZodUnion<T_1>;
static create: <T_1 extends [z.ZodType<any, any>, ...z.ZodType<any, any>[]]>(types: T_1) => ZodUnion<T_1>;
}

@@ -27,4 +27,4 @@ "use strict";

function ZodUnion() {
var _this = _super !== null && _super.apply(this, arguments) || this;
// opt optional: () => ZodUnion<[this, ZodUndefined]> = () => ZodUnion.create([this, ZodUndefined.create()]);
var _this = _super !== null && _super.apply(this, arguments) || this;
// null nullable: () => ZodUnion<[this, ZodNull]> = () => ZodUnion.create([this, ZodNull.create()]);

@@ -37,2 +37,9 @@ _this.toJSON = function () { return ({

}
Object.defineProperty(ZodUnion.prototype, "options", {
get: function () {
return this._def.options;
},
enumerable: true,
configurable: true
});
// distribute = <F extends (arg: T[number]) => z.ZodTypeAny>(f: F): ZodUnion<{ [k in keyof T]: ReturnType<F> }> => {

@@ -39,0 +46,0 @@ // return ZodUnion.create(this._def.options.map(f) as any);

@@ -16,2 +16,3 @@ import { ZodParsedType } from './parser';

too_big: "too_big";
invalid_intersection_types: "invalid_intersection_types";
};

@@ -75,2 +76,5 @@ export declare type ZodErrorCode = keyof typeof ZodErrorCode;

}
interface InvalidIntersectionTypesError extends ZodSuberrorBase {
code: typeof ZodErrorCode.invalid_intersection_types;
}
export interface CustomError extends ZodSuberrorBase {

@@ -82,3 +86,3 @@ code: typeof ZodErrorCode.custom_error;

}
export declare type ZodSuberrorOptionalMessage = InvalidTypeError | NonEmptyArrayIsEmptyError | UnrecognizedKeysError | InvalidUnionError | InvalidLiteralValueError | InvalidEnumValueError | InvalidArgumentsError | InvalidReturnTypeError | InvalidDateError | InvalidStringError | TooSmallError | TooBigError | CustomError;
export declare type ZodSuberrorOptionalMessage = InvalidTypeError | NonEmptyArrayIsEmptyError | UnrecognizedKeysError | InvalidUnionError | InvalidLiteralValueError | InvalidEnumValueError | InvalidArgumentsError | InvalidReturnTypeError | InvalidDateError | InvalidStringError | TooSmallError | TooBigError | InvalidIntersectionTypesError | CustomError;
export declare type ZodSuberror = ZodSuberrorOptionalMessage & {

@@ -85,0 +89,0 @@ message: string;

@@ -31,2 +31,3 @@ "use strict";

'too_big',
'invalid_intersection_types',
]);

@@ -33,0 +34,0 @@ exports.quotelessJson = function (obj) {

{
"name": "zod",
"version": "1.11.0-alpha.5",
"version": "1.11.0-alpha.6",
"description": "TypeScript-first schema declaration and validation library with static type inference",

@@ -5,0 +5,0 @@ "main": "./lib/src/index.js",

@@ -907,14 +907,14 @@ <p align="center">

This is particularly useful for defining "schema mixins" that you can apply to multiple schemas.
Intersections in Zod are not smart. Whatever data you pass into `.parse()` gets passed into the two intersected schemas. Because Zod object schemas don't allow any unknown keys by default, there are some unintuitive behavior surrounding intersections of object schemas.
```ts
const HasId = z.object({
id: z.string(),
const A = z.object({
a: z.string(),
});
const BaseTeacher = z.object({
name: z.string(),
const B = z.object({
b: z.string(),
});
const Teacher = z.intersection(BaseTeacher, HasId);
const AB = z.intersection(A, B);

@@ -921,0 +921,0 @@ type Teacher = z.infer<typeof Teacher>;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc