Comparing version 1.11.2 to 1.11.3
@@ -37,2 +37,3 @@ import * as z from './types/base'; | ||
export declare type ZodParsedType = keyof typeof ZodParsedType; | ||
export declare const find: (arr: any[], checker: (arg: any) => any) => any; | ||
declare type stripPath<T extends object> = T extends any ? util.OmitKeys<T, 'path'> : never; | ||
@@ -39,0 +40,0 @@ export declare type MakeErrorData = stripPath<ZodSuberrorOptionalMessage> & { |
@@ -122,3 +122,3 @@ "use strict"; | ||
]); | ||
var find = function (arr, checker) { | ||
exports.find = function (arr, checker) { | ||
for (var _i = 0, arr_1 = arr; _i < arr_1.length; _i++) { | ||
@@ -148,25 +148,27 @@ var item = arr_1[_i]; | ||
var parsedType = exports.getParsedType(obj); | ||
var schemaSeen = find(params.seen, function (x) { return x.schema === schemaDef; }); | ||
var isPrimitive = typeof obj !== 'object' || obj === null; | ||
if (schemaSeen) { | ||
var found = find(schemaSeen.objects, function (x) { return x.data === obj; }); | ||
if (found) { | ||
if (found.error) { | ||
throw found.error; | ||
var schemaSeen = exports.find(params.seen, function (x) { return x.schema === schemaDef; }); | ||
var isNonprimitive = ['array', 'object'].indexOf(parsedType) !== -1; | ||
if (isNonprimitive) { | ||
if (schemaSeen) { | ||
var found = exports.find(schemaSeen.objects, function (x) { return x.data === obj; }); | ||
if (found) { | ||
if (found.error) { | ||
throw found.error; | ||
} | ||
found.times = found.times + 1; | ||
if (found.times > 5 && isNonprimitive) { | ||
return Symbol('recursion depth exceeded.'); | ||
} | ||
else if (found.times > 2) { | ||
} | ||
} | ||
found.times = found.times + 1; | ||
if (found.times > 2 && !isPrimitive) { | ||
return Symbol('recursion depth exceeded.'); | ||
else { | ||
// | ||
schemaSeen.objects.push(obj); | ||
} | ||
else if (found.times > 2) { | ||
} | ||
} | ||
else { | ||
// | ||
schemaSeen.objects.push(obj); | ||
params.seen.push({ schema: schemaDef, objects: [{ data: obj, error: undefined, times: 1 }] }); | ||
} | ||
} | ||
else { | ||
params.seen.push({ schema: schemaDef, objects: [{ data: obj, error: undefined, times: 1 }] }); | ||
} | ||
// const setError = (error: Error) => { | ||
@@ -173,0 +175,0 @@ // const schemaSeen = params.seen.find(x => x.schema === schemaDef); |
"use strict"; | ||
// import * as z from '.'; | ||
// try { | ||
// z.string().parse(1345); | ||
// } catch (err) { | ||
// console.log(err.message); | ||
// console.log(err.flatten()); | ||
// } | ||
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 rawServiceSchema = z.object({ | ||
// configPath: z.string(), | ||
port: z.number().positive(), | ||
}); | ||
var rawNcdcConfigSchema = z.record(rawServiceSchema); | ||
var rawDataToParse = { | ||
Config1: { | ||
// configPath: './my-file.yml', | ||
port: 5001, | ||
}, | ||
Config2: { | ||
// configPath: './my-file.yml', | ||
port: 5002, | ||
}, | ||
// this one is missing a port so I expect a validation error to be thrown | ||
'Another Config': { | ||
// configPath: './my-file.yml', | ||
// realApi: 'http://example.com', | ||
}, | ||
}; | ||
var parsed = rawNcdcConfigSchema.safeParse(rawDataToParse); | ||
console.log(JSON.stringify(parsed, null, 2)); | ||
//# sourceMappingURL=playground.js.map |
@@ -81,3 +81,3 @@ "use strict"; | ||
Object.keys(_this.shape).map(function (key) { | ||
if (!Object.keys(mask).includes(key)) { | ||
if (Object.keys(mask).indexOf(key) === -1) { | ||
shape[key] = _this.shape[key]; | ||
@@ -84,0 +84,0 @@ } |
{ | ||
"name": "zod", | ||
"version": "1.11.2", | ||
"version": "1.11.3", | ||
"description": "TypeScript-first schema declaration and validation library with static type inference", | ||
@@ -59,2 +59,2 @@ "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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
277528
3633