@sinclair/typebox 0.34.1 → 0.34.3
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.
|
@@ -15,7 +15,7 @@ const symbols_1 = require("../symbols/symbols");
|
|
|
15
15
|
// Guards
|
|
16
16
|
// ------------------------------------------------------------------
|
|
17
17
|
const kind_1 = require("../guard/kind");
|
|
18
|
-
const
|
|
18
|
+
const value_1 = require("../guard/value");
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
// Infrastructure
|
|
21
21
|
// ------------------------------------------------------------------
|
|
@@ -57,7 +57,7 @@ function PickResolve(properties, propertyKeys) {
|
|
|
57
57
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
58
58
|
// prettier-ignore
|
|
59
59
|
function Pick(type, key, options) {
|
|
60
|
-
const typeKey = (0,
|
|
60
|
+
const typeKey = (0, value_1.IsArray)(key) ? UnionFromPropertyKeys(key) : key;
|
|
61
61
|
const propertyKeys = (0, kind_1.IsSchema)(key) ? (0, index_6.IndexPropertyKeys)(key) : key;
|
|
62
62
|
const isTypeRef = (0, kind_1.IsRef)(type);
|
|
63
63
|
const isKeyRef = (0, kind_1.IsRef)(key);
|
|
@@ -32,6 +32,14 @@ function HasDefaultProperty(schema) {
|
|
|
32
32
|
// Types
|
|
33
33
|
// ------------------------------------------------------------------
|
|
34
34
|
function FromArray(schema, references, value) {
|
|
35
|
+
// if the value is an array, we attempt to initialize it's elements
|
|
36
|
+
if ((0, index_5.IsArray)(value)) {
|
|
37
|
+
for (let i = 0; i < value.length; i++) {
|
|
38
|
+
value[i] = Visit(schema.items, references, value[i]);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
// ... otherwise use default initialization
|
|
35
43
|
const defaulted = ValueOrDefault(schema, value);
|
|
36
44
|
if (!(0, index_5.IsArray)(defaulted))
|
|
37
45
|
return defaulted;
|
|
@@ -11,7 +11,7 @@ import { TransformKind } from '../symbols/symbols.mjs';
|
|
|
11
11
|
// Guards
|
|
12
12
|
// ------------------------------------------------------------------
|
|
13
13
|
import { IsMappedKey, IsMappedResult, IsIntersect, IsUnion, IsObject, IsSchema, IsLiteralValue, IsRef } from '../guard/kind.mjs';
|
|
14
|
-
import { IsArray as IsArrayValue } from '
|
|
14
|
+
import { IsArray as IsArrayValue } from '../guard/value.mjs';
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
16
|
// Infrastructure
|
|
17
17
|
// ------------------------------------------------------------------
|
|
@@ -28,6 +28,14 @@ function HasDefaultProperty(schema) {
|
|
|
28
28
|
// Types
|
|
29
29
|
// ------------------------------------------------------------------
|
|
30
30
|
function FromArray(schema, references, value) {
|
|
31
|
+
// if the value is an array, we attempt to initialize it's elements
|
|
32
|
+
if (IsArray(value)) {
|
|
33
|
+
for (let i = 0; i < value.length; i++) {
|
|
34
|
+
value[i] = Visit(schema.items, references, value[i]);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
// ... otherwise use default initialization
|
|
31
39
|
const defaulted = ValueOrDefault(schema, value);
|
|
32
40
|
if (!IsArray(defaulted))
|
|
33
41
|
return defaulted;
|