Comparing version 4.0.0-1 to 4.0.0-2
@@ -433,2 +433,11 @@ function _defineProperty(obj, key, value) { | ||
function logUnknown(unknownFields, pathPrefix) { | ||
var unknownKeys = Object.keys(unknownFields); | ||
if (unknownKeys.length > 0) { | ||
var message = pathPrefix ? "Unknown \"" + pathPrefix + "\" fields" : 'Unknown fields'; | ||
throw new Error(message + ": " + unknownKeys.join(', ') + "."); | ||
} | ||
} | ||
var Schema = function () { | ||
@@ -499,8 +508,3 @@ function Schema(blueprint) { | ||
} else if ("production" !== process.env.NODE_ENV) { | ||
var unknownKeys = Object.keys(unknownFields); | ||
if (unknownKeys.length > 0) { | ||
var message = pathPrefix ? "Unknown \"" + pathPrefix + "\" fields" : 'Unknown fields'; | ||
throw new Error(message + ": " + unknownKeys.join(', ') + "."); | ||
} | ||
logUnknown(unknownFields, pathPrefix); | ||
} | ||
@@ -1059,14 +1063,27 @@ | ||
_proto.run = function run(value, path, schema) { | ||
var object = value || this.getDefaultValue() || {}; | ||
var _this2 = this; | ||
if ("production" !== process.env.NODE_ENV) { | ||
this.invariant(isObject(object), 'Value passed to shape must be an object.', path); | ||
if ("production" !== process.env.NODE_ENV && value) { | ||
this.invariant(isObject(value), 'Value passed to shape must be an object.', path); | ||
} | ||
return optimal(object, this.contents, { | ||
file: schema.filePath, | ||
name: schema.schemaName, | ||
prefix: path, | ||
unknown: !this.isExact | ||
var unknownFields = _extends({}, value); | ||
var struct = {}; | ||
Object.keys(this.contents).forEach(function (baseKey) { | ||
var key = baseKey; | ||
var content = _this2.contents[key]; | ||
struct[key] = content.run(value === null || value === void 0 ? void 0 : value[key], path + "." + key, schema); | ||
delete unknownFields[key]; | ||
}); | ||
if (this.isExact) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
logUnknown(unknownFields, path); | ||
} | ||
} else { | ||
Object.assign(struct, unknownFields); | ||
} | ||
return struct; | ||
}; | ||
@@ -1073,0 +1090,0 @@ |
@@ -437,2 +437,11 @@ 'use strict'; | ||
function logUnknown(unknownFields, pathPrefix) { | ||
var unknownKeys = Object.keys(unknownFields); | ||
if (unknownKeys.length > 0) { | ||
var message = pathPrefix ? "Unknown \"" + pathPrefix + "\" fields" : 'Unknown fields'; | ||
throw new Error(message + ": " + unknownKeys.join(', ') + "."); | ||
} | ||
} | ||
var Schema = function () { | ||
@@ -503,8 +512,3 @@ function Schema(blueprint) { | ||
} else if ("production" !== process.env.NODE_ENV) { | ||
var unknownKeys = Object.keys(unknownFields); | ||
if (unknownKeys.length > 0) { | ||
var message = pathPrefix ? "Unknown \"" + pathPrefix + "\" fields" : 'Unknown fields'; | ||
throw new Error(message + ": " + unknownKeys.join(', ') + "."); | ||
} | ||
logUnknown(unknownFields, pathPrefix); | ||
} | ||
@@ -1063,14 +1067,27 @@ | ||
_proto.run = function run(value, path, schema) { | ||
var object = value || this.getDefaultValue() || {}; | ||
var _this2 = this; | ||
if ("production" !== process.env.NODE_ENV) { | ||
this.invariant(isObject(object), 'Value passed to shape must be an object.', path); | ||
if ("production" !== process.env.NODE_ENV && value) { | ||
this.invariant(isObject(value), 'Value passed to shape must be an object.', path); | ||
} | ||
return optimal(object, this.contents, { | ||
file: schema.filePath, | ||
name: schema.schemaName, | ||
prefix: path, | ||
unknown: !this.isExact | ||
var unknownFields = _extends({}, value); | ||
var struct = {}; | ||
Object.keys(this.contents).forEach(function (baseKey) { | ||
var key = baseKey; | ||
var content = _this2.contents[key]; | ||
struct[key] = content.run(value === null || value === void 0 ? void 0 : value[key], path + "." + key, schema); | ||
delete unknownFields[key]; | ||
}); | ||
if (this.isExact) { | ||
if ("production" !== process.env.NODE_ENV) { | ||
logUnknown(unknownFields, path); | ||
} | ||
} else { | ||
Object.assign(struct, unknownFields); | ||
} | ||
return struct; | ||
}; | ||
@@ -1077,0 +1094,0 @@ |
@@ -66,3 +66,3 @@ import Schema from './Schema'; | ||
*/ | ||
required(state?: boolean): Predicate<NonNullable<T>>; | ||
required(state?: boolean): this; | ||
/** | ||
@@ -108,3 +108,3 @@ * Run all validation checks that have been enqueued and return a type casted value. | ||
} | ||
export declare function custom<T, S extends object = object>(callback: CustomCallback<T, S>, defaultValue: DefaultValue<T>): Predicate<T>; | ||
export declare function func<T = FuncOf>(defaultValue?: T | null): Predicate<T | null>; | ||
export declare function custom<T, S extends object = {}>(callback: CustomCallback<T, S>, defaultValue: DefaultValue<T>): Predicate<T>; | ||
export declare function func<T extends FuncOf = FuncOf>(defaultValue?: T | null): Predicate<T | null>; |
@@ -9,4 +9,4 @@ import Predicate from '../Predicate'; | ||
exact(): this; | ||
run(value: T | undefined, path: string, schema: Schema<{}>): Required<T>; | ||
run(value: T | undefined, path: string, schema: Schema<{}>): T; | ||
} | ||
export declare function shape<T extends object>(contents: Blueprint<T>): ShapePredicate<T>; |
{ | ||
"name": "optimal", | ||
"version": "4.0.0-1", | ||
"version": "4.0.0-2", | ||
"description": "A system for building and validating defined object structures.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
100320
29
2501
0