@humanwhocodes/object-schema
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "@humanwhocodes/object-schema", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "An object schema merger/validator", | ||
@@ -33,2 +33,2 @@ "main": "src/index.js", | ||
} | ||
} | ||
} |
@@ -107,8 +107,4 @@ /** | ||
...definitions[key], | ||
merge(first, second) { | ||
if (first && second) { | ||
return schema.merge(first, second); | ||
} | ||
return MergeStrategy.assign(first, second); | ||
merge(first = {}, second = {}) { | ||
return schema.merge(first, second); | ||
}, | ||
@@ -115,0 +111,0 @@ validate(value) { |
@@ -269,2 +269,49 @@ /** | ||
it("should return separate objects when using subschema", () => { | ||
schema = new ObjectSchema({ | ||
age: { | ||
merge: "replace", | ||
validate: "number" | ||
}, | ||
address: { | ||
schema: { | ||
street: { | ||
schema: { | ||
number: { | ||
merge: "replace", | ||
validate: "number" | ||
}, | ||
streetName: { | ||
merge: "replace", | ||
validate: "string" | ||
} | ||
} | ||
}, | ||
state: { | ||
merge: "replace", | ||
validate: "string" | ||
} | ||
} | ||
} | ||
}); | ||
const baseObject = { | ||
address: { | ||
street: { | ||
number: 100, | ||
streetName: "Foo St" | ||
}, | ||
state: "HA" | ||
} | ||
}; | ||
const result = schema.merge(baseObject, { | ||
age: 29 | ||
}); | ||
assert.notStrictEqual(result.address.street, baseObject.address.street); | ||
assert.deepStrictEqual(result.address, baseObject.address); | ||
}); | ||
it("should not error when calling the merge strategy when there's a subschema and no matching key in second object", () => { | ||
@@ -299,3 +346,39 @@ | ||
it("should not error when calling the merge strategy when there's multiple subschemas and no matching key in second object", () => { | ||
schema = new ObjectSchema({ | ||
user: { | ||
schema: { | ||
name: { | ||
schema: { | ||
first: { | ||
merge: "replace", | ||
validate: "string" | ||
}, | ||
last: { | ||
merge: "replace", | ||
validate: "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
const result = schema.merge({ | ||
user: { | ||
name: { | ||
first: "n", | ||
last: "z" | ||
} | ||
} | ||
}, { | ||
}); | ||
assert.strictEqual(result.user.name.first, "n"); | ||
assert.strictEqual(result.user.name.last, "z"); | ||
}); | ||
}); | ||
@@ -302,0 +385,0 @@ |
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
49395
14
1079