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
- // TypeObject
16
+ // SchemaObject
17
17
  //
18
- // Types have non-enumerable properties that MUST be preserved on Clone.
19
- // The following is the optimal path for TypeBox types.
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 IsTypeObject(value) {
21
+ function IsSchemaObject(value) {
22
22
  return (Guard.HasPropertyKey(value, '~kind') ||
23
23
  Guard.HasPropertyKey(value, '~unsafe'));
24
24
  }
25
- function FromTypeObject(value) {
25
+ function FromSchemaObject(value) {
26
26
  const result = {};
27
- const descriptors = Object.getOwnPropertyDescriptors(value);
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 = descriptors[key];
32
- if (Guard.HasPropertyKey(descriptor, 'value')) {
33
- Object.defineProperty(result, key, { ...descriptor, value: FromValue(descriptor.value) });
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
- IsTypeObject(value) ? FromTypeObject(value) :
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 descriptors = Object.getOwnPropertyDescriptors(Clone(value));
10
- const keysToDiscard = new Set(propertyKeys);
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.defineProperty(result, key, descriptors[key]);
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.3.10",
4
+ "version": "1.3.11",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"