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.4.1 to 1.5.0

lib/src/types/any.d.ts

6

lib/src/helpers/partialUtil.d.ts

@@ -1,5 +0,5 @@

import { ZodAny } from '../types/base';
import { ZodTypeAny } from '../types/base';
import * as z from '..';
export declare namespace partialUtil {
type RootDeepPartial<T extends ZodAny> = {
type RootDeepPartial<T extends ZodTypeAny> = {
object: T extends z.ZodObject<infer Shape, infer Params> ? z.ZodObject<{

@@ -10,3 +10,3 @@ [k in keyof Shape]: DeepPartial<Shape[k]>;

}[T extends z.ZodObject<any> ? 'object' : 'rest'];
type DeepPartial<T extends ZodAny> = {
type DeepPartial<T extends ZodTypeAny> = {
object: T extends z.ZodObject<infer Shape, infer Params> ? z.ZodUnion<[z.ZodObject<{

@@ -13,0 +13,0 @@ [k in keyof Shape]: DeepPartial<Shape[k]>;

"use strict";
// import { ZodAny } from '../types/base';
// import { ZodTypeAny } from '../types/base';
// import { ZodObject } from '../types/object';

@@ -7,3 +7,3 @@ // import { ZodArray } from '..';

// export namespace zodmaskUtil {
// export type Params<T extends ZodAny> = {
// export type Params<T extends ZodTypeAny> = {
// object: true | (T extends ZodObject<infer U, any> ? { [k in keyof U]?: Params<U[k]> } : 'objectnever');

@@ -13,3 +13,3 @@ // array: true | (T extends ZodArray<ZodObject<infer U, any>> ? Params<ZodObject<U, any>> : 'arraynever');

// }[T extends ZodObject<any, any> ? 'object' : T extends ZodArray<ZodObject<any>> ? 'array' : 'rest'];
// export type pick<T extends ZodAny, P extends Params<T>> = {
// export type pick<T extends ZodTypeAny, P extends Params<T>> = {
// false: never;

@@ -37,3 +37,3 @@ // true: T;

// : 'never'];
// export type omit<T extends ZodAny, P extends Params<T>> = {
// export type omit<T extends ZodTypeAny, P extends Params<T>> = {
// false: T;

@@ -40,0 +40,0 @@ // true: never;

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

import { ZodNull, ZodNullDef } from './types/null';
import { ZodAny, ZodAnyDef } from './types/any';
import { ZodUnknown, ZodUnknownDef } from './types/unknown';
import { ZodArray, ZodArrayDef } from './types/array';

@@ -20,5 +22,5 @@ import { ZodObject, ZodObjectDef } from './types/object';

import { ZodPromise, ZodPromiseDef } from './types/promise';
import { TypeOf, ZodType, ZodAny } from './types/base';
import { TypeOf, ZodType, ZodTypeAny } from './types/base';
import { ZodError } from './ZodError';
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef;
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef;
declare const stringType: () => ZodString;

@@ -31,2 +33,4 @@ declare const numberType: () => ZodNumber;

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

@@ -48,4 +52,4 @@ declare const objectType: <T extends import("./types/base").ZodRawShape>(shape: T) => ZodObject<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, arrayType as array, objectType as object, unionType as union, intersectionType as intersection, tupleType as tuple, recordType as record, functionType as function, lazyType as lazy, literalType as literal, enumType as enum, promiseType as promise, ostring, onumber, oboolean, };
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodType, ZodAny, ZodDef, ZodError, };
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, lazyType as lazy, literalType as literal, enumType as enum, promiseType as promise, ostring, onumber, oboolean, };
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodType, ZodTypeAny, ZodDef, ZodError, };
export { TypeOf, TypeOf as infer };

@@ -18,2 +18,6 @@ "use strict";

exports.ZodNull = null_1.ZodNull;
var any_1 = require("./types/any");
exports.ZodAny = any_1.ZodAny;
var unknown_1 = require("./types/unknown");
exports.ZodUnknown = unknown_1.ZodUnknown;
var array_1 = require("./types/array");

@@ -59,2 +63,6 @@ exports.ZodArray = array_1.ZodArray;

exports.null = nullType;
var anyType = any_1.ZodAny.create;
exports.any = anyType;
var unknownType = unknown_1.ZodUnknown.create;
exports.unknown = unknownType;
var arrayType = array_1.ZodArray.create;

@@ -61,0 +69,0 @@ exports.array = arrayType;

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

// });
// // export const Masker = (visit: (_schema: z.ZodAny, params: Params) => z.ZodAny) => (
// // schema: z.ZodAny,
// // export const Masker = (visit: (_schema: z.ZodTypeAny, params: Params) => z.ZodTypeAny) => (
// // schema: z.ZodTypeAny,
// // params: Params,

@@ -38,0 +38,0 @@ // // ) => {

@@ -103,4 +103,7 @@ "use strict";

throw ZodError_1.ZodError.fromString("Non-null type: " + typeof obj);
// return null;
break;
case z.ZodTypes.any:
break;
case z.ZodTypes.unknown:
break;
case z.ZodTypes.array:

@@ -107,0 +110,0 @@ if (!Array.isArray(obj))

@@ -14,6 +14,6 @@ "use strict";

// type Params = any;
// export const ParamVisitor = (visit: (_schema: z.ZodAny, params: Params) => z.ZodAny) => (
// schema: z.ZodAny,
// export const ParamVisitor = (visit: (_schema: z.ZodTypeAny, params: Params) => z.ZodTypeAny) => (
// schema: z.ZodTypeAny,
// params: Params,
// ): z.ZodAny => {
// ): z.ZodTypeAny => {
// const def: ZodDef = schema._def as any;

@@ -20,0 +20,0 @@ // switch (def.t) {

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

// import { util } from './helpers/util';
// export const sampleVisitor = (schema: z.ZodAny) => {
// export const sampleVisitor = (schema: z.ZodTypeAny) => {
// const _def = schema._def;

@@ -8,0 +8,0 @@ // const def: ZodDef = _def as any;

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

import { ZodUnion } from './union';
export interface ZodArrayDef<T extends z.ZodAny = z.ZodAny> extends z.ZodTypeDef {
export interface ZodArrayDef<T extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {
t: z.ZodTypes.array;

@@ -11,3 +11,3 @@ type: T;

}
export declare class ZodArray<T extends z.ZodAny> extends z.ZodType<T['_type'][], ZodArrayDef<T>> {
export declare class ZodArray<T extends z.ZodTypeAny> extends z.ZodType<T['_type'][], ZodArrayDef<T>> {
toJSON: () => {

@@ -23,3 +23,3 @@ t: z.ZodTypes.array;

}
export declare class ZodNonEmptyArray<T extends z.ZodAny> extends z.ZodType<[T['_type'], ...T['_type'][]], ZodArrayDef<T>> {
export declare class ZodNonEmptyArray<T extends z.ZodTypeAny> extends z.ZodType<[T['_type'], ...T['_type'][]], ZodArrayDef<T>> {
toJSON: () => {

@@ -26,0 +26,0 @@ t: z.ZodTypes.array;

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

return _this;
// static create = <T extends z.ZodAny>(schema: T): ZodArray<T> => {
// static create = <T extends z.ZodTypeAny>(schema: T): ZodArray<T> => {
// return new ZodArray({

@@ -88,0 +88,0 @@ // t: z.ZodTypes.array,

@@ -21,7 +21,9 @@ import { ParseParams } from '../parser';

enum = "enum",
promise = "promise"
promise = "promise",
any = "any",
unknown = "unknown"
}
export declare type ZodAny = ZodType<any>;
export declare type ZodTypeAny = ZodType<any>;
export declare type ZodRawShape = {
[k: string]: ZodAny;
[k: string]: ZodTypeAny;
};

@@ -28,0 +30,0 @@ declare type Check<T> = {

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

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

@@ -28,0 +30,0 @@ // interface Assertable<T> {

import * as z from './base';
import { ZodTuple } from './tuple';
export interface ZodFunctionDef<Args extends ZodTuple<any> = ZodTuple<any>, Returns extends z.ZodAny = z.ZodAny> extends z.ZodTypeDef {
export interface ZodFunctionDef<Args extends ZodTuple<any> = ZodTuple<any>, Returns extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {
t: z.ZodTypes.function;

@@ -8,4 +8,4 @@ args: Args;

}
export declare type TypeOfFunction<Args extends ZodTuple<any>, Returns extends z.ZodAny> = Args['_type'] extends Array<any> ? (...args: Args['_type']) => Returns['_type'] : never;
export declare class ZodFunction<Args extends ZodTuple<any>, Returns extends z.ZodAny> {
export declare type TypeOfFunction<Args extends ZodTuple<any>, Returns extends z.ZodTypeAny> = Args['_type'] extends Array<any> ? (...args: Args['_type']) => Returns['_type'] : never;
export declare class ZodFunction<Args extends ZodTuple<any>, Returns extends z.ZodTypeAny> {
readonly _def: ZodFunctionDef<Args, Returns>;

@@ -12,0 +12,0 @@ readonly _type: TypeOfFunction<Args, Returns>;

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

import { ZodUnion } from './union';
export interface ZodIntersectionDef<T extends z.ZodAny = z.ZodAny, U extends z.ZodAny = z.ZodAny> extends z.ZodTypeDef {
export interface ZodIntersectionDef<T extends z.ZodTypeAny = z.ZodTypeAny, U extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {
t: z.ZodTypes.intersection;

@@ -11,3 +11,3 @@ left: T;

}
export declare class ZodIntersection<T extends z.ZodAny, U extends z.ZodAny> extends z.ZodType<T['_type'] & U['_type'], ZodIntersectionDef<T, U>> {
export declare class ZodIntersection<T extends z.ZodTypeAny, U extends z.ZodTypeAny> extends z.ZodType<T['_type'] & U['_type'], ZodIntersectionDef<T, U>> {
optional: () => ZodUnion<[this, ZodUndefined]>;

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

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

import { ZodUnion } from './union';
export interface ZodLazyDef<T extends z.ZodAny = z.ZodAny> extends z.ZodTypeDef {
export interface ZodLazyDef<T extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {
t: z.ZodTypes.lazy;
getter: () => T;
}
export declare class ZodLazy<T extends z.ZodAny> extends z.ZodType<z.TypeOf<T>, ZodLazyDef<T>> {
export declare class ZodLazy<T extends z.ZodTypeAny> extends z.ZodType<z.TypeOf<T>, ZodLazyDef<T>> {
readonly schema: T;

@@ -12,0 +12,0 @@ optional: () => ZodUnion<[this, ZodUndefined]>;

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

import { ZodUnion } from './union';
export interface ZodPromiseDef<T extends z.ZodAny = z.ZodAny> extends z.ZodTypeDef {
export interface ZodPromiseDef<T extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {
t: z.ZodTypes.promise;
type: T;
}
export declare class ZodPromise<T extends z.ZodAny> extends z.ZodType<Promise<T['_type']>, ZodPromiseDef<T>> {
export declare class ZodPromise<T extends z.ZodTypeAny> extends z.ZodType<Promise<T['_type']>, ZodPromiseDef<T>> {
toJSON: () => {

@@ -12,0 +12,0 @@ t: z.ZodTypes.promise;

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

import { ZodUnion } from './union';
export interface ZodRecordDef<Value extends z.ZodAny = z.ZodAny> extends z.ZodTypeDef {
export interface ZodRecordDef<Value extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {
t: z.ZodTypes.record;
valueType: Value;
}
export declare class ZodRecord<Value extends z.ZodAny = z.ZodAny> extends z.ZodType<Record<string, Value['_type']>, // { [k in keyof T]: T[k]['_type'] },
export declare class ZodRecord<Value extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodType<Record<string, Value['_type']>, // { [k in keyof T]: T[k]['_type'] },
ZodRecordDef<Value>> {

@@ -12,0 +12,0 @@ readonly _value: Value;

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

import { ZodNull } from './null';
export declare type TypeOfTuple<T extends [z.ZodAny, ...z.ZodAny[]] | []> = {
export declare type TypeOfTuple<T extends [z.ZodTypeAny, ...z.ZodTypeAny[]] | []> = {
[k in keyof T]: T[k] extends z.ZodType<infer U> ? U : never;
};
export interface ZodTupleDef<T extends [z.ZodAny, ...z.ZodAny[]] | [] = [z.ZodAny, ...z.ZodAny[]]> extends z.ZodTypeDef {
export interface ZodTupleDef<T extends [z.ZodTypeAny, ...z.ZodTypeAny[]] | [] = [z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodTypeDef {
t: z.ZodTypes.tuple;
items: T;
}
export declare class ZodTuple<T extends [z.ZodAny, ...z.ZodAny[]] | [] = [z.ZodAny, ...z.ZodAny[]]> extends z.ZodType<TypeOfTuple<T>, ZodTupleDef<T>> {
export declare class ZodTuple<T extends [z.ZodTypeAny, ...z.ZodTypeAny[]] | [] = [z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodType<TypeOfTuple<T>, ZodTupleDef<T>> {
toJSON: () => {

@@ -15,0 +15,0 @@ t: z.ZodTypes.tuple;

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

declare type RecordKey = ZodString | ZodNumber;
export interface ZodRecordDef<Key extends RecordKey = ZodString, Value extends z.ZodAny = z.ZodAny> extends z.ZodTypeDef {
export interface ZodRecordDef<Key extends RecordKey = ZodString, Value extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodTypeDef {
t: z.ZodTypes.record;

@@ -14,3 +14,3 @@ keyType: Key;

}
declare type ZodRecordType<Key extends RecordKey = ZodString, Value extends z.ZodAny = z.ZodAny> = Key extends ZodString ? Key extends ZodNumber ? Record<string | number, Value['_type']> : Record<string, Value['_type']> & {
declare type ZodRecordType<Key extends RecordKey = ZodString, Value extends z.ZodTypeAny = z.ZodTypeAny> = Key extends ZodString ? Key extends ZodNumber ? Record<string | number, Value['_type']> : Record<string, Value['_type']> & {
[k: number]: never;

@@ -20,3 +20,3 @@ } : Key extends ZodNumber ? Record<number, Value['_type']> & {

} : never;
export declare class ZodRecord<Key extends RecordKey = ZodString, Value extends z.ZodAny = z.ZodAny> extends z.ZodType<ZodRecordType<Key, Value>, // { [k in keyof T]: T[k]['_type'] },
export declare class ZodRecord<Key extends RecordKey = ZodString, Value extends z.ZodTypeAny = z.ZodTypeAny> extends z.ZodType<ZodRecordType<Key, Value>, // { [k in keyof T]: T[k]['_type'] },
ZodRecordDef<Key, Value>> {

@@ -23,0 +23,0 @@ readonly _key: Key;

import * as z from './base';
import { ZodUndefined } from './undefined';
import { ZodNull } from './null';
export interface ZodUnionDef<T extends [z.ZodAny, z.ZodAny, ...z.ZodAny[]] = [z.ZodAny, z.ZodAny, ...z.ZodAny[]]> extends z.ZodTypeDef {
export interface ZodUnionDef<T extends [z.ZodTypeAny, 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.ZodAny, z.ZodAny, ...z.ZodAny[]]> extends z.ZodType<T[number]['_type'], ZodUnionDef<T>> {
export declare class ZodUnion<T extends [z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]> extends z.ZodType<T[number]['_type'], ZodUnionDef<T>> {
optional: () => ZodUnion<[this, ZodUndefined]>;

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

@@ -50,2 +50,6 @@ "use strict";

return visit(schema);
case z.ZodTypes.any:
return visit(schema);
case z.ZodTypes.unknown:
return visit(schema);
case z.ZodTypes.array:

@@ -52,0 +56,0 @@ return visit(new array_1.ZodArray(__assign({}, def, { type: visit(def.type) })));

{
"name": "zod",
"version": "1.4.1",
"version": "1.5.0",
"description": "TypeScript-first schema declaration and validation library with static type inference",

@@ -64,2 +64,2 @@ "main": "./lib/src/index.js",

}
}
}

@@ -101,4 +101,8 @@ <p align="center">

const dateSchema = z.date(); // => ZodType<Date>
const undefinedSchema = z.undefined(); // => ZodType<undefined>
const nullTypeSchema = z.null(); // => ZodType<null>
const nullSchema = z.null(); // => ZodType<null>
const anySchema = z.any(); // => ZodType<any>
const unknownSchema = z.unknown(); // => ZodType<unknown>
```

@@ -440,3 +444,3 @@

`objectSchema` only accepts objects with single key: `name`. You could use `.nonstrict()` to create a schema that accepts unknown keys, but that schema won't validated the values associated with those unknown keys.
`objectSchema` only accepts objects with single key: `name`. You could use `.nonstrict()` to create a schema that accepts unknown keys, but that schema doesn't enforce a type on the _values_ associated with those unknown keys.

@@ -446,3 +450,3 @@ ```ts

type nonstrict = z.infer<typeof nonstrict>;
// => { name: string, [k:string]: any}
// => { name: string, [k:string]: any }

@@ -1125,2 +1129,3 @@ const parsed = nonstrict.parse({ name: 'Serena', bar: ['whatever'] });

| ----------- | ------------------------------------------------------------------- |
| zod@1.5 | Any and unknown types |
| zod@1.4 | Refinement types (`.refine`), `.parse` no longer returns deep clone |

@@ -1127,0 +1132,0 @@ | zod@1.3 | Promise schemas |

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

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