Comparing version 1.8.7 to 1.8.8
import { IntersectionType } from './types'; | ||
import { ValidationError, Type, StringType, NumberType, LiteralType, ObjectType, ArrayType, UnionType, PartialType, TupleType, DateType, LazyType, UndefinedType, NullType, NullableType, EnumType, BooleanType, UnknownType, NumberOptions, Literal, ObjectShape, ObjectOptions, AnyType, ArrayOptions, UnionOptions, PartialOpts, IntersectionResult, DeepPartialShape, PartialShape, Eval, ToUnion, keySignature, StringTypes, OptionalType, BigIntOptions, BigIntType, StringOptions, EnumOptions } from './types'; | ||
export { ValidationError, Type, Infer, keySignature, AnyType, ObjectShape, NumberType, BooleanType, StringType, UndefinedType, NullType, ObjectType, ArrayType, TupleType, NullableType, OptionalType, MappedType, DateType, UnknownType, UnionType, IntersectionType, } from './types'; | ||
import { ValidationError, Type, StringType, NumberType, LiteralType, ObjectType, ArrayType, UnionType, PartialType, TupleType, DateType, LazyType, UndefinedType, NullType, NullableType, EnumType, BooleanType, UnknownType, NumberOptions, Literal, ObjectShape, ObjectOptions, AnyType, ArrayOptions, UnionOptions, PartialOpts, IntersectionResult, DeepPartialShape, PartialShape, Eval, ToUnion, StringTypes, OptionalType, BigIntOptions, BigIntType, StringOptions, EnumOptions } from './types'; | ||
export { ValidationError, Type, Infer, AnyType, ObjectShape, NumberType, BooleanType, StringType, UndefinedType, NullType, ObjectType, ArrayType, TupleType, NullableType, OptionalType, MappedType, DateType, UnknownType, UnionType, IntersectionType, } from './types'; | ||
declare const keySignature: unique symbol; | ||
export { keySignature }; | ||
export declare const string: (opts?: StringOptions | undefined) => StringType; | ||
@@ -5,0 +7,0 @@ export declare const boolean: () => BooleanType; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.required = exports.enum = exports.null = exports.undefined = exports.omit = exports.pick = exports.partial = exports.lazy = exports.date = exports.tuple = exports.dictionary = exports.record = exports.literals = exports.intersection = exports.union = exports.array = exports.object = exports.literal = exports.unknown = exports.bigint = exports.number = exports.boolean = exports.string = exports.IntersectionType = exports.UnionType = exports.UnknownType = exports.DateType = exports.OptionalType = exports.NullableType = exports.TupleType = exports.ArrayType = exports.ObjectType = exports.NullType = exports.UndefinedType = exports.StringType = exports.BooleanType = exports.NumberType = exports.keySignature = exports.Type = exports.ValidationError = void 0; | ||
exports.required = exports.enum = exports.null = exports.undefined = exports.omit = exports.pick = exports.partial = exports.lazy = exports.date = exports.tuple = exports.dictionary = exports.record = exports.literals = exports.intersection = exports.union = exports.array = exports.object = exports.literal = exports.unknown = exports.bigint = exports.number = exports.boolean = exports.string = exports.keySignature = exports.IntersectionType = exports.UnionType = exports.UnknownType = exports.DateType = exports.OptionalType = exports.NullableType = exports.TupleType = exports.ArrayType = exports.ObjectType = exports.NullType = exports.UndefinedType = exports.StringType = exports.BooleanType = exports.NumberType = exports.Type = exports.ValidationError = void 0; | ||
const types_1 = require("./types"); | ||
@@ -9,3 +9,2 @@ const types_2 = require("./types"); | ||
Object.defineProperty(exports, "Type", { enumerable: true, get: function () { return types_3.Type; } }); | ||
Object.defineProperty(exports, "keySignature", { enumerable: true, get: function () { return types_3.keySignature; } }); | ||
// Types | ||
@@ -26,2 +25,4 @@ Object.defineProperty(exports, "NumberType", { enumerable: true, get: function () { return types_3.NumberType; } }); | ||
Object.defineProperty(exports, "IntersectionType", { enumerable: true, get: function () { return types_3.IntersectionType; } }); | ||
const keySignature = Symbol('keySignature'); | ||
exports.keySignature = keySignature; | ||
const string = (opts) => new types_2.StringType(opts); | ||
@@ -49,9 +50,9 @@ exports.string = string; | ||
exports.literals = literals; | ||
const record = (schema) => new types_2.ObjectType({ [types_2.keySignature]: schema }); | ||
const record = (schema) => new types_2.ObjectType({ [keySignature]: schema }); | ||
exports.record = record; | ||
const dictionary = (schema) => { | ||
if (schema instanceof types_2.OptionalType) { | ||
return new types_2.ObjectType({ [types_2.keySignature]: schema }); | ||
return new types_2.ObjectType({ [keySignature]: schema }); | ||
} | ||
return new types_2.ObjectType({ [types_2.keySignature]: new types_2.OptionalType(schema) }); | ||
return new types_2.ObjectType({ [keySignature]: new types_2.OptionalType(schema) }); | ||
}; | ||
@@ -113,3 +114,3 @@ exports.dictionary = dictionary; | ||
ValidationError: types_2.ValidationError, | ||
keySignature: types_2.keySignature, | ||
keySignature: keySignature, | ||
// types | ||
@@ -116,0 +117,0 @@ NumberType: types_2.NumberType, |
@@ -0,1 +1,2 @@ | ||
import { keySignature } from './index'; | ||
declare const typeErrSym: unique symbol; | ||
@@ -186,3 +187,2 @@ declare const coercionTypeSymbol: unique symbol; | ||
} | ||
export declare const keySignature: unique symbol; | ||
export declare type ObjectShape = { | ||
@@ -189,0 +189,0 @@ [key: string]: AnyType; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LazyType = exports.PartialType = exports.EnumType = exports.IntersectionType = exports.UnionType = exports.TupleType = exports.ArrayType = exports.ObjectType = exports.keySignature = exports.DateType = exports.NullableType = exports.OptionalType = exports.UnknownType = exports.LiteralType = exports.NullType = exports.UndefinedType = exports.BigIntType = exports.NumberType = exports.BooleanType = exports.StringType = exports.ValidationError = exports.Type = void 0; | ||
exports.LazyType = exports.PartialType = exports.EnumType = exports.IntersectionType = exports.UnionType = exports.TupleType = exports.ArrayType = exports.ObjectType = exports.DateType = exports.NullableType = exports.OptionalType = exports.UnknownType = exports.LiteralType = exports.NullType = exports.UndefinedType = exports.BigIntType = exports.NumberType = exports.BooleanType = exports.StringType = exports.ValidationError = exports.Type = void 0; | ||
const index_1 = require("./index"); | ||
function clone(value) { | ||
@@ -511,3 +512,2 @@ if (typeof value !== 'object' || value === null) { | ||
exports.DateType = DateType; | ||
exports.keySignature = Symbol('keySignature'); | ||
class ObjectType extends Type { | ||
@@ -521,3 +521,3 @@ constructor(objectShape, opts) { | ||
const keys = Object.keys(this.objectShape); | ||
this[exports.keySignature] = this.objectShape[exports.keySignature]; | ||
this[index_1.keySignature] = this.objectShape[index_1.keySignature]; | ||
this[allowUnknownSymbol] = (opts === null || opts === void 0 ? void 0 : opts.allowUnknown) === true; | ||
@@ -529,3 +529,3 @@ this[shapekeysSymbol] = keys; | ||
Object.values(this.objectShape).some(schema => schema[coercionTypeSymbol]) || | ||
!!(this.objectShape[exports.keySignature] && this.objectShape[exports.keySignature][coercionTypeSymbol]); | ||
!!(this.objectShape[index_1.keySignature] && this.objectShape[index_1.keySignature][coercionTypeSymbol]); | ||
this._parse = this.selectParser(); | ||
@@ -539,3 +539,3 @@ } | ||
const allowUnknown = parseOpts.allowUnknown || this[allowUnknownSymbol]; | ||
if (!allowUnknown && !this.objectShape[exports.keySignature]) { | ||
if (!allowUnknown && !this.objectShape[index_1.keySignature]) { | ||
const illegalKeys = []; | ||
@@ -561,3 +561,3 @@ for (const k in value) { | ||
selectParser() { | ||
if (this[shapekeysSymbol].length === 0 && this[exports.keySignature]) { | ||
if (this[shapekeysSymbol].length === 0 && this[index_1.keySignature]) { | ||
if (this[coercionTypeSymbol] && this.shouldCollectErrors) { | ||
@@ -574,3 +574,3 @@ return this.parseRecordConvCollect; | ||
} | ||
if (this[exports.keySignature]) { | ||
if (this[index_1.keySignature]) { | ||
if (this[coercionTypeSymbol] && this.shouldCollectErrors) { | ||
@@ -690,3 +690,3 @@ return this.parseMixRecordConvCollect; | ||
try { | ||
this[exports.keySignature].parse(value[key], { suppressPathErrMsg: true }); | ||
this[index_1.keySignature].parse(value[key], { suppressPathErrMsg: true }); | ||
} | ||
@@ -706,3 +706,3 @@ catch (err) { | ||
for (const key in value) { | ||
const result = this[exports.keySignature].try(value[key], { suppressPathErrMsg: true }); | ||
const result = this[index_1.keySignature].try(value[key], { suppressPathErrMsg: true }); | ||
if (result instanceof ValidationError) { | ||
@@ -725,3 +725,3 @@ hasError = true; | ||
try { | ||
convVal[key] = this[exports.keySignature].parse(value[key], { suppressPathErrMsg: true }); | ||
convVal[key] = this[index_1.keySignature].parse(value[key], { suppressPathErrMsg: true }); | ||
} | ||
@@ -742,3 +742,3 @@ catch (err) { | ||
for (const key in value) { | ||
const result = this[exports.keySignature].try(value[key], { suppressPathErrMsg: true }); | ||
const result = this[index_1.keySignature].try(value[key], { suppressPathErrMsg: true }); | ||
if (result instanceof ValidationError) { | ||
@@ -763,3 +763,3 @@ hasError = true; | ||
try { | ||
(this.objectShape[key] || this[exports.keySignature]).parse(value[key], { suppressPathErrMsg: true }); | ||
(this.objectShape[key] || this[index_1.keySignature]).parse(value[key], { suppressPathErrMsg: true }); | ||
} | ||
@@ -779,3 +779,3 @@ catch (err) { | ||
for (const key of new Set(Object.keys(value).concat(this[shapekeysSymbol]))) { | ||
const result = (this.objectShape[key] || this[exports.keySignature]).try(value[key], { | ||
const result = (this.objectShape[key] || this[index_1.keySignature]).try(value[key], { | ||
suppressPathErrMsg: true, | ||
@@ -800,3 +800,3 @@ }); | ||
try { | ||
convVal[key] = (this.objectShape[key] || this[exports.keySignature]).parse(value[key], { | ||
convVal[key] = (this.objectShape[key] || this[index_1.keySignature]).parse(value[key], { | ||
suppressPathErrMsg: true, | ||
@@ -819,3 +819,3 @@ }); | ||
for (const key of new Set(Object.keys(value).concat(this[shapekeysSymbol]))) { | ||
const result = (this.objectShape[key] || this[exports.keySignature]).try(value[key], { | ||
const result = (this.objectShape[key] || this[index_1.keySignature]).try(value[key], { | ||
suppressPathErrMsg: true, | ||
@@ -854,9 +854,9 @@ }); | ||
}, {}); | ||
const selfKeySig = this.objectShape[exports.keySignature]; | ||
const targetKeySig = schema[exports.keySignature]; | ||
const selfKeySig = this.objectShape[index_1.keySignature]; | ||
const targetKeySig = schema[index_1.keySignature]; | ||
if (selfKeySig && targetKeySig) { | ||
intersectShape[exports.keySignature] = selfKeySig.and(targetKeySig); | ||
intersectShape[index_1.keySignature] = selfKeySig.and(targetKeySig); | ||
} | ||
else if (selfKeySig || targetKeySig) { | ||
intersectShape[exports.keySignature] = selfKeySig || targetKeySig; | ||
intersectShape[index_1.keySignature] = selfKeySig || targetKeySig; | ||
} | ||
@@ -869,4 +869,4 @@ return new ObjectType(intersectShape); | ||
const pickedShape = keys.reduce((acc, key) => { | ||
if (this.objectShape[key] || this.objectShape[exports.keySignature]) { | ||
acc[key] = this.objectShape[key] || this.objectShape[exports.keySignature]; | ||
if (this.objectShape[key] || this.objectShape[index_1.keySignature]) { | ||
acc[key] = this.objectShape[key] || this.objectShape[index_1.keySignature]; | ||
} | ||
@@ -879,6 +879,6 @@ return acc; | ||
const pickedKeys = this[shapekeysSymbol].filter((x) => !keys.includes(x)); | ||
if (!this[exports.keySignature]) { | ||
if (!this[index_1.keySignature]) { | ||
return this.pick(pickedKeys, opts); | ||
} | ||
return this.pick(pickedKeys, opts).and(new ObjectType({ [exports.keySignature]: this[exports.keySignature] })); | ||
return this.pick(pickedKeys, opts).and(new ObjectType({ [index_1.keySignature]: this[index_1.keySignature] })); | ||
} | ||
@@ -896,9 +896,9 @@ partial(opts) { | ||
}, {}); | ||
const keysig = originalShape[exports.keySignature]; | ||
const keysig = originalShape[index_1.keySignature]; | ||
if (keysig) { | ||
if (opts === null || opts === void 0 ? void 0 : opts.deep) { | ||
shape[exports.keySignature] = toPartialSchema(keysig, opts).optional(); | ||
shape[index_1.keySignature] = toPartialSchema(keysig, opts).optional(); | ||
} | ||
else { | ||
shape[exports.keySignature] = keysig.optional(); | ||
shape[index_1.keySignature] = keysig.optional(); | ||
} | ||
@@ -905,0 +905,0 @@ } |
{ | ||
"name": "myzod", | ||
"version": "1.8.7", | ||
"version": "1.8.8", | ||
"description": "", | ||
@@ -8,3 +8,3 @@ "main": "./libs/index.js", | ||
"scripts": { | ||
"test": "nyc mocha \"test/**/*test.ts\"", | ||
"test": "mocha \"test/**/*test.ts\"", | ||
"build": "rm -rf ./libs && tsc", | ||
@@ -33,3 +33,3 @@ "pub": "npm t && npm run build && npm publish", | ||
"benchmonkey": "^0.0.8", | ||
"mocha": "^9.2.1", | ||
"mocha": "^10.0.0", | ||
"nyc": "^15.1.0", | ||
@@ -36,0 +36,0 @@ "prettier": "^2.5.1", |
1929
111633