@sinclair/typebox 0.33.6 → 0.33.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,7 +18,8 @@ const kind_1 = require("../../type/guard/kind");
|
|
|
18
18
|
// ValueOrDefault
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
function ValueOrDefault(schema, value) {
|
|
21
|
-
|
|
21
|
+
const clone = (0, index_5.HasPropertyKey)(schema, 'default') ? (0, index_2.Clone)(schema.default) : undefined;
|
|
22
|
+
return (0, index_5.IsUndefined)(value) ? clone : (0, index_5.IsObject)(value) && (0, index_5.IsObject)(clone) ? Object.assign(clone, value) : value;
|
|
22
23
|
}
|
|
23
24
|
// ------------------------------------------------------------------
|
|
24
25
|
// HasDefaultProperty
|
|
@@ -47,6 +48,7 @@ function FromIntersect(schema, references, value) {
|
|
|
47
48
|
}
|
|
48
49
|
function FromObject(schema, references, value) {
|
|
49
50
|
const defaulted = ValueOrDefault(schema, value);
|
|
51
|
+
// return defaulted
|
|
50
52
|
if (!(0, index_5.IsObject)(defaulted))
|
|
51
53
|
return defaulted;
|
|
52
54
|
const knownPropertyKeys = Object.getOwnPropertyNames(schema.properties);
|
|
@@ -58,7 +60,7 @@ function FromObject(schema, references, value) {
|
|
|
58
60
|
const propertyValue = Visit(schema.properties[key], references, defaulted[key]);
|
|
59
61
|
if ((0, index_5.IsUndefined)(propertyValue))
|
|
60
62
|
continue;
|
|
61
|
-
defaulted[key] =
|
|
63
|
+
defaulted[key] = Visit(schema.properties[key], references, defaulted[key]);
|
|
62
64
|
}
|
|
63
65
|
// return if not additional properties
|
|
64
66
|
if (!HasDefaultProperty(schema.additionalProperties))
|
|
@@ -5,7 +5,7 @@ import { Kind } from '../../type/symbols/index.mjs';
|
|
|
5
5
|
// ------------------------------------------------------------------
|
|
6
6
|
// ValueGuard
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
|
-
import { IsString, IsObject, IsArray, IsUndefined } from '../guard/index.mjs';
|
|
8
|
+
import { IsString, IsObject, IsArray, IsUndefined, HasPropertyKey } from '../guard/index.mjs';
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
// TypeGuard
|
|
11
11
|
// ------------------------------------------------------------------
|
|
@@ -14,7 +14,8 @@ import { IsKind } from '../../type/guard/kind.mjs';
|
|
|
14
14
|
// ValueOrDefault
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
16
|
function ValueOrDefault(schema, value) {
|
|
17
|
-
|
|
17
|
+
const clone = HasPropertyKey(schema, 'default') ? Clone(schema.default) : undefined;
|
|
18
|
+
return IsUndefined(value) ? clone : IsObject(value) && IsObject(clone) ? Object.assign(clone, value) : value;
|
|
18
19
|
}
|
|
19
20
|
// ------------------------------------------------------------------
|
|
20
21
|
// HasDefaultProperty
|
|
@@ -43,6 +44,7 @@ function FromIntersect(schema, references, value) {
|
|
|
43
44
|
}
|
|
44
45
|
function FromObject(schema, references, value) {
|
|
45
46
|
const defaulted = ValueOrDefault(schema, value);
|
|
47
|
+
// return defaulted
|
|
46
48
|
if (!IsObject(defaulted))
|
|
47
49
|
return defaulted;
|
|
48
50
|
const knownPropertyKeys = Object.getOwnPropertyNames(schema.properties);
|
|
@@ -54,7 +56,7 @@ function FromObject(schema, references, value) {
|
|
|
54
56
|
const propertyValue = Visit(schema.properties[key], references, defaulted[key]);
|
|
55
57
|
if (IsUndefined(propertyValue))
|
|
56
58
|
continue;
|
|
57
|
-
defaulted[key] =
|
|
59
|
+
defaulted[key] = Visit(schema.properties[key], references, defaulted[key]);
|
|
58
60
|
}
|
|
59
61
|
// return if not additional properties
|
|
60
62
|
if (!HasDefaultProperty(schema.additionalProperties))
|