typebox 1.3.10 → 1.3.11
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.
|
@@ -13,24 +13,27 @@ function FromClassInstance(value) {
|
|
|
13
13
|
return value; // atomic
|
|
14
14
|
}
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
|
-
//
|
|
16
|
+
// SchemaObject
|
|
17
17
|
//
|
|
18
|
-
//
|
|
19
|
-
// The following is the optimal path
|
|
18
|
+
// Schema objects have non-enumerable properties that MUST be preserved
|
|
19
|
+
// on Clone. The following is the optimal path these objects.
|
|
20
20
|
// ------------------------------------------------------------------
|
|
21
|
-
function
|
|
21
|
+
function IsSchemaObject(value) {
|
|
22
22
|
return (Guard.HasPropertyKey(value, '~kind') ||
|
|
23
23
|
Guard.HasPropertyKey(value, '~unsafe'));
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function FromSchemaObject(value) {
|
|
26
26
|
const result = {};
|
|
27
|
-
const
|
|
28
|
-
for (const key of Object.keys(descriptors)) {
|
|
27
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
29
28
|
if (Guard.IsUnsafePropertyKey(key))
|
|
30
29
|
continue; // (ignore: prototype-pollution)
|
|
31
|
-
const descriptor =
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key); // safe-name!
|
|
31
|
+
descriptor.value = FromValue(descriptor.value);
|
|
32
|
+
if (Guard.IsEqual(descriptor.enumerable, true)) {
|
|
33
|
+
result[key] = descriptor.value;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
Object.defineProperty(result, key, descriptor);
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
return result;
|
|
@@ -55,7 +58,7 @@ function FromPlainObject(value) {
|
|
|
55
58
|
// ------------------------------------------------------------------
|
|
56
59
|
function FromObject(value) {
|
|
57
60
|
return (Guard.IsClassInstance(value) ? FromClassInstance(value) :
|
|
58
|
-
|
|
61
|
+
IsSchemaObject(value) ? FromSchemaObject(value) :
|
|
59
62
|
FromPlainObject(value));
|
|
60
63
|
}
|
|
61
64
|
// ------------------------------------------------------------------
|
|
@@ -6,12 +6,12 @@ import { Clone } from './clone.mjs';
|
|
|
6
6
|
export function Discard(value, propertyKeys) {
|
|
7
7
|
Metrics.discard += 1;
|
|
8
8
|
const result = {};
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
for (const key of Object.keys(descriptors)) {
|
|
12
|
-
if (keysToDiscard.has(key))
|
|
9
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
10
|
+
if (propertyKeys.includes(key))
|
|
13
11
|
continue;
|
|
14
|
-
Object.
|
|
12
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key); // safe-name!
|
|
13
|
+
descriptor.value = Clone(descriptor.value);
|
|
14
|
+
Object.defineProperty(result, key, descriptor);
|
|
15
15
|
}
|
|
16
16
|
return result;
|
|
17
17
|
}
|