Socket
Socket
Sign inDemoInstall

zod

Package Overview
Dependencies
0
Maintainers
1
Versions
361
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.10.0-alpha.2 to 1.10.0

CHANGELOG.md

3

lib/src/codegen.js

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

return _this.setType(id, _this.generate(lazyType).id);
case z.ZodTypes.codec:
var codecOutput = def.output;
return _this.setType(id, _this.generate(codecOutput).id);
default:

@@ -138,0 +135,0 @@ util_1.util.assertNever(def);

@@ -9,3 +9,8 @@ "use strict";

case ZodError_1.ZodErrorCode.invalid_type:
message = "Invalid input: expected " + error.expected + ", received " + error.received;
if (error.received === 'undefined') {
message = 'Required';
}
else {
message = "Expected " + error.expected + ", received " + error.received;
}
break;

@@ -12,0 +17,0 @@ case ZodError_1.ZodErrorCode.nonempty_array_is_empty:

import { Primitive } from './primitive';
type AnyObject = {
declare type AnyObject = {
[k: string]: any;
};
type IsAny<T> = any extends T ? (T extends any ? true : false) : false;
type IsNever<T> = never extends T ? (T extends never ? true : false) : false;
type IsTrue<T> = true extends T ? (T extends true ? true : false) : false;
type IsObject<T> = T extends {
declare type IsAny<T> = any extends T ? (T extends any ? true : false) : false;
declare type IsNever<T> = never extends T ? (T extends never ? true : false) : false;
declare type IsTrue<T> = true extends T ? (T extends true ? true : false) : false;
declare type IsObject<T> = T extends {
[k: string]: any;
} ? (T extends Array<any> ? false : true) : false;
type IsObjectArray<T> = T extends Array<{
declare type IsObjectArray<T> = T extends Array<{
[k: string]: any;

@@ -13,0 +13,0 @@ }> ? true : false;

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

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

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

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

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

@@ -6,3 +6,4 @@ export declare namespace util {

type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
type MakePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
const arrayToEnum: <T extends string, U extends [T, ...T[]]>(items: U) => { [k in U[number]]: k; };
}

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

import { ZodPromise, ZodPromiseDef } from './types/promise';
import { ZodCodec, ZodCodecDef } from './types/codec';
import { TypeOf, ZodType, ZodTypeAny, ZodTypeDef, ZodTypes } from './types/base';

@@ -30,3 +29,3 @@ import { ZodError, ZodErrorCode } from './ZodError';

export { ZodTypeDef, ZodTypes };
declare type ZodDef = ZodStringDef | ZodNumberDef | ZodBigIntDef | ZodBooleanDef | ZodDateDef | ZodUndefinedDef | ZodNullDef | ZodAnyDef | ZodUnknownDef | ZodVoidDef | ZodArrayDef | ZodObjectDef | ZodUnionDef | ZodIntersectionDef | ZodTupleDef | ZodRecordDef | ZodFunctionDef | ZodLazyDef | ZodLiteralDef | ZodEnumDef | ZodPromiseDef | ZodCodecDef;
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;

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

declare const promiseType: <T extends ZodType<any, ZodTypeDef>>(schema: T) => ZodPromise<T>;
declare const codecType: <T extends ZodType<any, ZodTypeDef>, U extends ZodType<any, ZodTypeDef>>(input: T, output: U, transformer: (arg: T["_type"]) => U["_type"]) => ZodCodec<T, U>;
declare const ostring: () => ZodUnion<[ZodString, ZodUndefined]>;

@@ -65,3 +63,3 @@ declare const onumber: () => ZodUnion<[ZodNumber, ZodUndefined]>;

} & Pick<import("./ZodError").CustomError, "message" | "params">, "message" | "path" | "params"> | undefined) => ZodType<InstanceType<T>, ZodTypeDef>;
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, lazyType as lazy, literalType as literal, enumType as enum, promiseType as promise, codecType as codec, instanceOfType as instanceof, ostring, onumber, oboolean, codegen, };
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, lazyType as lazy, literalType as literal, enumType as enum, promiseType as promise, instanceOfType as instanceof, ostring, onumber, oboolean, codegen, };
export declare const late: {

@@ -72,3 +70,3 @@ object: <T extends import("./types/base").ZodRawShape>(shape: () => T) => ZodObject<T, {

};
export { ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodIntersection, ZodTuple, ZodRecord, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodPromise, ZodCodec, ZodType, ZodType as Schema, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodError, ZodErrorMap, ZodErrorCode, ZodParsedType, ZodCodeGenerator, };
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, ZodType as ZodSchema, ZodTypeAny, ZodDef, ZodError, ZodErrorMap, ZodErrorCode, ZodParsedType, ZodCodeGenerator, };
export { TypeOf, TypeOf as infer };

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

exports.ZodPromise = promise_1.ZodPromise;
var codec_1 = require("./types/codec");
exports.ZodCodec = codec_1.ZodCodec;
var base_1 = require("./types/base");

@@ -103,4 +101,2 @@ exports.ZodType = base_1.ZodType;

exports.promise = promiseType;
var codecType = codec_1.ZodCodec.create;
exports.codec = codecType;
var ostring = function () { return stringType().optional(); };

@@ -107,0 +103,0 @@ exports.ostring = ostring;

@@ -33,4 +33,4 @@ import * as z from './types/base';

export declare type ZodParsedType = keyof typeof ZodParsedType;
declare type StripErrorKeys<T extends object> = T extends any ? util.OmitKeys<T, 'path'> : never;
export declare type MakeErrorData = StripErrorKeys<ZodSuberrorOptionalMessage> & {
declare type stripPath<T extends object> = T extends any ? util.OmitKeys<T, 'path'> : never;
export declare type MakeErrorData = stripPath<ZodSuberrorOptionalMessage> & {
path?: (string | number)[];

@@ -37,0 +37,0 @@ };

@@ -48,2 +48,11 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -436,6 +445,2 @@ if (mod && mod.__esModule) return mod;

}); });
case z.ZodTypes.codec:
def.input.parse(obj);
var transformed = def.transformer(obj);
return def.output.parse(transformed);
default:

@@ -448,4 +453,3 @@ util_1.util.assertNever(def);

if (!check.check(obj)) {
var noMethodCheck = __assign({}, check);
delete noMethodCheck.check;
var checkMethod = check.check, noMethodCheck = __rest(check, ["check"]);
error.addError(makeError(noMethodCheck));

@@ -452,0 +456,0 @@ }

"use strict";
// import * as z from '.';
// // import { ZodCodec } from './types/codec';
// const test = z.codec(z.string(), z.string(), x => x.trim().toUpperCase());
// const adsf = test.parse(' asdf ');
// console.log(adsf); // => 'ASDF'
// const stringToNumber = z.number().accepts(z.string().or(z.number()), data => parseFloat(`${data}`));
// console.log(stringToNumber.parse('5') * 5); // 25
// const FormData = z
// .object({
// email: z.string().email(),
// password: z.string().min(10),
// confirm: z.string().min(10),
// })
// .refine(obj => obj.password === obj.confirm, {
// message: 'Passwords do not match',
// path: ['confirm'], // sets the path of the error thrown by this refinement
// });
// try {
// FormData.parse({
// email: 'not an email',
// password: 'tooshort',
// confirm: 'nomatch',
// });
// } catch (err) {
// if (!(err instanceof z.ZodError)) throw err;
// console.log(err.errors);
// /*
// [
// { code: 'invalid_string', validation: 'email', path: ['email'], message: 'Invalid email' },
// {
// code: 'too_small',
// minimum: 10,
// type: 'string',
// inclusive: true,
// path: ['password'],
// message: 'Should be at least 10 characters',
// },
// {
// code: 'too_small',
// minimum: 10,
// type: 'string',
// inclusive: true,
// path: ['confirm'],
// message: 'Should be at least 10 characters',
// },
// { code: 'custom_error', message: 'Passwords do not match', path: ['confirm'] },
// ];
// */
// console.log(err.formErrors);
// /*
// {
// formErrors: [],
// fieldErrors: {
// email: ['Invalid email'],
// password: ['Should be at least 10 characters'],
// confirm: ['Should be at least 10 characters', 'Passwords do not match'],
// },
// const ZodRHF = <T extends z.ZodType<any,any>>(schema:T)=>(values:any)=>{
// try{
// schema.parse(values)
// return {}
// }catch(err){
// return (err as z.ZodError).formErrors.fieldErrors;
// }
// */
// }
//
// z.string()
// .parseAsync(undefined)
// .catch(err => console.log(JSON.stringify(err.errors, null, 2)));
// export const errorMap: z.ZodErrorMap = (err, ctx) => {
// if (err.code === z.ZodErrorCode.invalid_type) {
// if (err.received === 'undefined') {
// return { message: 'Required.' };
// }
// }
// return { message: ctx.defaultError };
// };
//# sourceMappingURL=playground.js.map
import { ParseParams, MakeErrorData } from '../parser';
import { util } from '../helpers/util';
import { ZodArray, ZodUnion, ZodNull, ZodUndefined, ZodCodec } from '..';
import { ZodArray, ZodUnion, ZodNull, ZodUndefined } from '..';
import { CustomError } from '../ZodError';

@@ -26,4 +26,3 @@ export declare enum ZodTypes {

unknown = "unknown",
void = "void",
codec = "codec"
void = "void"
}

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

checks?: InternalCheck<any>[];
accepts?: ZodType<any, any>;
}

@@ -68,5 +66,3 @@ export declare type TypeOf<T extends {

array: () => ZodArray<this>;
accepts: <U extends ZodType<any>, Tx extends (arg: U['_type']) => this['_type']>(x: U, transformer: Tx) => ZodCodec<U, this>;
or: <U extends ZodType<any>>(arg: U) => ZodUnion<[this, U]>;
}
export {};

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

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

@@ -73,12 +72,2 @@ var ZodType = /** @class */ (function () {

this.array = function () { return __1.ZodArray.create(_this); };
// pre: <T extends string>(
// input: T,
// transformer: (arg: T) => Type,
// ) => any = (input, transformer) => 'adsf';
this.accepts = function (input, transformer) {
return __1.ZodCodec.create(input, _this, transformer);
};
this.or = function (arg) {
return __1.ZodUnion.create([_this, arg]);
};
this.parse = parser_1.ZodParser(def);

@@ -85,0 +74,0 @@ this._def = def;

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

strict: false;
}>, Type & {
[k: string]: any;
}>;
}>, ZodObjectType<T, objectUtil.Flatten<{ [k in Exclude<keyof Params, "strict">]: Params[k]; } & {
strict: false;
}>>>;
augment: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params, ZodObjectType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params>>;

@@ -47,3 +47,3 @@ extend: <Augmentation extends z.ZodRawShape>(augmentation: Augmentation) => ZodObject<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params, ZodObjectType<{ [k in Exclude<keyof T, keyof Augmentation>]: T[k]; } & { [k in keyof Augmentation]: Augmentation[k]; }, Params>>;

partial: () => ZodObject<{ [k in keyof T]: ZodUnion<[T[k], ZodUndefined]>; }, Params, ZodObjectType<{ [k in keyof T]: ZodUnion<[T[k], ZodUndefined]>; }, Params>>;
deepPartial: () => partialUtil.RootDeepPartial<ZodObject<T>>;
deepPartial: () => partialUtil.RootDeepPartial<this>;
static create: <T_1 extends z.ZodRawShape>(shape: T_1) => ZodObject<T_1, {

@@ -50,0 +50,0 @@ strict: true;

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

var urlRegex = /^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
var uuidRegex = /([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}/g;
var uuidRegex = /([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}){1}/i;
var ZodString = /** @class */ (function (_super) {

@@ -45,0 +45,0 @@ __extends(ZodString, _super);

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

@@ -56,4 +56,4 @@ "main": "./lib/src/index.js",

"tslint-config-prettier": "^1.18.0",
"typescript": "3.2"
"typescript": "3.3"
}
}
}

@@ -128,3 +128,4 @@ <p align="center">

1. Zod 1.x requires TypeScript 3.2+
1. Zod 1.x requires TypeScript 3.3+
> Support for TS 3.2 was dropped with the release of zod@1.10 on 19 July 2020
2. You must enable `strictNullChecks` or use `strict` mode which includes `strictNullChecks`. Otherwise Zod can't correctly infer the types of your schemas!

@@ -261,3 +262,3 @@ ```ts

// override error path
// appended to error path
path?: (string | number)[];

@@ -299,4 +300,2 @@

j
## Type inference

@@ -303,0 +302,0 @@

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc