typebox 1.0.9 → 1.0.10
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TObject, type TProperties } from '../../type/index.mjs';
|
|
2
2
|
export declare function FromObject(context: TProperties, type: TObject, value: unknown): unknown;
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
+
import { IsOptional } from '../../type/index.mjs';
|
|
2
3
|
import { Guard } from '../../guard/index.mjs';
|
|
3
4
|
import { FromType } from './from-type.mjs';
|
|
4
5
|
import { FromAdditionalProperties } from './from-additional.mjs';
|
|
6
|
+
// ------------------------------------------------------------------
|
|
7
|
+
// IsOptionalUndefined
|
|
8
|
+
//
|
|
9
|
+
// Determines whether a property should be excluded from conversion
|
|
10
|
+
// because it is both optional and has an undefined value. This case
|
|
11
|
+
// cannot be safely converted, since it introduces ambiguity between
|
|
12
|
+
// an omitted optional property and a property explicitly set to the
|
|
13
|
+
// value undefined.
|
|
14
|
+
// ------------------------------------------------------------------
|
|
15
|
+
function IsOptionalUndefined(property, key, value) {
|
|
16
|
+
return IsOptional(property) && Guard.IsUndefined(value[key]);
|
|
17
|
+
}
|
|
18
|
+
// ------------------------------------------------------------------
|
|
19
|
+
// FromProperties
|
|
20
|
+
// ------------------------------------------------------------------
|
|
5
21
|
function FromProperties(context, type, value) {
|
|
6
22
|
const entries = Guard.EntriesRegExp(type.properties);
|
|
7
23
|
const keys = Guard.Keys(value);
|
|
8
|
-
for (const [regexp,
|
|
24
|
+
for (const [regexp, property] of entries) {
|
|
9
25
|
for (const key of keys) {
|
|
10
|
-
if
|
|
11
|
-
|
|
26
|
+
// Only convert the property if the value key matches a schema key,
|
|
27
|
+
// and the property is not optional with an undefined value.
|
|
28
|
+
if (regexp.test(key) && !IsOptionalUndefined(property, key, value)) {
|
|
29
|
+
value[key] = FromType(context, property, value[key]);
|
|
12
30
|
}
|
|
13
31
|
}
|
|
14
32
|
}
|