Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zod

Package Overview
Dependencies
Maintainers
1
Versions
364
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 2.0.0-alpha.3 to 2.0.0-alpha.4

lib/src/types/void.d.ts

10

lib/src/index.d.ts

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

import { ZodUnknown, ZodUnknownDef } from './types/unknown';
import { ZodVoid, ZodVoidDef } from './types/void';
import { ZodArray, ZodArrayDef } from './types/array';

@@ -25,3 +26,3 @@ import { ZodObject, ZodObjectDef } from './types/object';

import { toZod } from './toZod';
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef;
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodVoidDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef;
declare const stringType: () => ZodString;

@@ -36,2 +37,3 @@ declare const numberType: () => ZodNumber;

declare const unknownType: () => ZodUnknown;
declare const voidType: () => ZodVoid;
declare const arrayType: <T extends ZodType<any, import("./types/base").ZodTypeDef>>(schema: T) => ZodArray<T>;

@@ -45,3 +47,3 @@ declare const objectType: <T extends import("./types/base").ZodRawShape>(shape: T) => ZodObject<T, {

declare const recordType: <Value extends ZodType<any, import("./types/base").ZodTypeDef> = ZodType<any, import("./types/base").ZodTypeDef>>(valueType: Value) => ZodRecord<Value>;
declare const functionType: <T extends ZodTuple<any>, U extends ZodType<any, import("./types/base").ZodTypeDef>>(args: T, returns: U) => ZodFunction<T, U>;
declare const functionType: <T extends ZodTuple<any>, U extends ZodType<any, import("./types/base").ZodTypeDef>>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;
declare const literalType: <T extends import("./helpers/primitive").Primitive>(value: T) => ZodLiteral<T>;

@@ -53,3 +55,3 @@ declare const enumType: <U extends string, T extends [U, ...U[]]>(values: T) => ZodEnum<T>;

declare const oboolean: () => ZodUnion<[ZodBoolean, ZodUndefined]>;
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, literalType as literal, enumType as enum, promiseType as promise, ostring, onumber, oboolean, };
export { stringType as string, numberType as number, bigIntType as bigint, booleanType as boolean, dateType as date, undefinedType as undefined, nullType as null, anyType as any, unknownType as unknown, voidType as void, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, literalType as literal, enumType as enum, promiseType as promise, ostring, onumber, oboolean, };
export { toZod };

@@ -61,3 +63,3 @@ export declare const lazy: {

};
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodType, ZodType as Schema, ZodTypeAny, ZodDef, ZodError, };
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodType, ZodType as Schema, ZodTypeAny, ZodDef, ZodError, };
export declare type lazyobject<T extends object> = ZodObject<{

@@ -64,0 +66,0 @@ [k in keyof T]: ZodType<T[k], any>;

4

lib/src/index.js

@@ -22,2 +22,4 @@ "use strict";

exports.ZodUnknown = unknown_1.ZodUnknown;
var void_1 = require("./types/void");
exports.ZodVoid = void_1.ZodVoid;
var array_1 = require("./types/array");

@@ -68,2 +70,4 @@ exports.ZodArray = array_1.ZodArray;

exports.unknown = unknownType;
var voidType = void_1.ZodVoid.create;
exports.void = voidType;
var arrayType = array_1.ZodArray.create;

@@ -70,0 +74,0 @@ exports.array = arrayType;

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

};
export declare const getParsedType: (data: any) => "object" | "symbol" | "unknown" | "function" | "string" | "number" | "nan" | "boolean" | "array" | "bigint" | "date" | "undefined" | "null" | "promise";
export declare const getParsedType: (data: any) => "object" | "symbol" | "unknown" | "function" | "string" | "number" | "nan" | "boolean" | "array" | "bigint" | "date" | "undefined" | "null" | "promise" | "void";
export declare const ParsedType: {

@@ -28,4 +28,5 @@ object: "object";

promise: "promise";
void: "void";
};
export declare type ParsedType = keyof typeof ParsedType;
export declare const ZodParser: (schemaDef: z.ZodTypeDef) => (obj: any, baseParams?: ParseParams) => any;

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

'promise',
'void',
]);

@@ -220,2 +221,8 @@ exports.ZodParser = function (schemaDef) { return function (obj, baseParams) {

break;
case z.ZodTypes.void:
if (parsedType !== exports.ParsedType.undefined && parsedType !== exports.ParsedType.null) {
error.addError(makeError({ code: ZodError_1.ZodErrorCode.invalid_type, expected: exports.ParsedType.void, received: parsedType }));
throw error;
}
break;
case z.ZodTypes.array:

@@ -222,0 +229,0 @@ if (parsedType !== exports.ParsedType.array) {

@@ -23,3 +23,4 @@ import { ParseParams } from '../parser';

any = "any",
unknown = "unknown"
unknown = "unknown",
void = "void"
}

@@ -55,3 +56,2 @@ export declare type ZodTypeAny = ZodType<any>;

refinement: (refinement: Check<Type>) => this;
wrap: (value: Type, params?: ParseParams) => ZodValue<this>;
constructor(def: Def);

@@ -62,7 +62,2 @@ abstract toJSON: () => object;

}
export declare class ZodValue<S extends ZodType<any, any>> {
value: S['_type'];
schema: S;
constructor(schema: S, value: S['_type']);
}
export {};

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

ZodTypes["unknown"] = "unknown";
ZodTypes["void"] = "void";
})(ZodTypes = exports.ZodTypes || (exports.ZodTypes = {}));

@@ -46,2 +47,26 @@ // interface Assertable<T> {

var ZodType = /** @class */ (function () {
// mask = <P extends maskUtil.Params<Type>>(_params: P): ZodType<maskUtil.Pick<Type, P>> => {
// return Masker(this, _params) as any;
// };
// pick = <Params extends maskUtil.Params<Type>>(_params: Params): maskUtil.Mask<Type, Params> => {
// return 'asdf' as any;
// };
// Wrapper = class<Type, Schema> {
// value: Type;
// schema: Schema;
// constructor(schema: Schema, value: Type) {
// this.value = value;
// this.schema = schema;
// }
// };
// wrap: (value: this['_type'], params?: ParseParams) => any = (value, params) => {
// const parsed = this.parse(value, params);
// return new this.Wrapper<this['_type'], this>(this, parsed);
// // return new ZodValue(this, this.parse(value, params));
// };
// wrap: (value: Type, params?: ParseParams) => ZodValue<this> = (value, params) => {
// const parsed = this.parse(value, params);
// return new ZodValue(this, parsed);
// // return new ZodValue(this, this.parse(value, params));
// };
function ZodType(def) {

@@ -67,26 +92,2 @@ var _this = this;

};
// mask = <P extends maskUtil.Params<Type>>(_params: P): ZodType<maskUtil.Pick<Type, P>> => {
// return Masker(this, _params) as any;
// };
// pick = <Params extends maskUtil.Params<Type>>(_params: Params): maskUtil.Mask<Type, Params> => {
// return 'asdf' as any;
// };
// Wrapper = class<Type, Schema> {
// value: Type;
// schema: Schema;
// constructor(schema: Schema, value: Type) {
// this.value = value;
// this.schema = schema;
// }
// };
// wrap: (value: this['_type'], params?: ParseParams) => any = (value, params) => {
// const parsed = this.parse(value, params);
// return new this.Wrapper<this['_type'], this>(this, parsed);
// // return new ZodValue(this, this.parse(value, params));
// };
this.wrap = function (value, params) {
var parsed = _this.parse(value, params);
return new ZodValue(_this, parsed);
// return new ZodValue(this, this.parse(value, params));
};
this.parse = parser_1.ZodParser(def);

@@ -116,10 +117,10 @@ this._def = def;

exports.ZodType = ZodType;
var ZodValue = /** @class */ (function () {
function ZodValue(schema, value) {
this.value = value;
this.schema = schema;
}
return ZodValue;
}());
exports.ZodValue = ZodValue;
// export class ZodWrappedTypeBase<Type, Def extends ZodTypeDef = ZodTypeDef> extends ZodType<Type, Def> {
// value: Type;
// constructor(def:Def,value: Type) {
// super(def);
// this.value = value;
// };
// toJSON =()=>this.toJSON();
// }
//# sourceMappingURL=base.js.map

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

readonly _type: TypeOfFunction<Args, Returns>;
args: <Items extends [] | [z.ZodType<any, z.ZodTypeDef>, ...z.ZodType<any, z.ZodTypeDef>[]]>(...items: Items) => ZodFunction<ZodTuple<Items>, Returns>;
returns: <NewReturnType extends z.ZodType<any, any>>(returnType: NewReturnType) => ZodFunction<Args, NewReturnType>;
implement: (func: TypeOfFunction<Args, Returns>) => TypeOfFunction<Args, Returns>;
validate: (func: TypeOfFunction<Args, Returns>) => TypeOfFunction<Args, Returns>;
static create: <T extends ZodTuple<any>, U extends z.ZodType<any, z.ZodTypeDef>>(args: T, returns: U) => ZodFunction<T, U>;
static create: <T extends ZodTuple<any>, U extends z.ZodType<any, z.ZodTypeDef>>(args?: T | undefined, returns?: U | undefined) => ZodFunction<T, U>;
optional: () => ZodUnion<[this, ZodUndefined]>;

@@ -20,0 +22,0 @@ nullable: () => ZodUnion<[this, ZodNull]>;

@@ -15,2 +15,13 @@ "use strict";

})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -25,5 +36,7 @@ if (mod && mod.__esModule) return mod;

var z = __importStar(require("./base"));
var tuple_1 = require("./tuple");
var undefined_1 = require("./undefined");
var null_1 = require("./null");
var union_1 = require("./union");
var void_1 = require("./void");
var ZodFunction = /** @class */ (function (_super) {

@@ -33,2 +46,12 @@ __extends(ZodFunction, _super);

var _this = _super !== null && _super.apply(this, arguments) || this;
_this.args = function () {
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
return new ZodFunction(__assign({}, _this._def, { args: tuple_1.ZodTuple.create(items) }));
};
_this.returns = function (returnType) {
return new ZodFunction(__assign({}, _this._def, { returns: returnType }));
};
// implement = this.parse;

@@ -64,4 +87,4 @@ _this.implement = function (func) {

t: z.ZodTypes.function,
args: args,
returns: returns,
args: args || tuple_1.ZodTuple.create([]),
returns: returns || void_1.ZodVoid.create(),
});

@@ -68,0 +91,0 @@ };

{
"name": "zod",
"version": "2.0.0-alpha.3",
"version": "2.0.0-alpha.4",
"description": "TypeScript-first schema declaration and validation library with static type inference",

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

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