@sinclair/typebox 0.32.6 → 0.32.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.
@@ -1,4 +1,5 @@
1
1
  import { Check } from '../check/index.mjs';
2
+ import { Clone } from '../clone/index.mjs';
2
3
  import { Deref } from '../deref/index.mjs';
3
4
  import { Kind } from '../../type/symbols/index.mjs';
4
5
  // ------------------------------------------------------------------
@@ -13,7 +14,7 @@ import { IsSchema } from '../../type/guard/type.mjs';
13
14
  // ValueOrDefault
14
15
  // ------------------------------------------------------------------
15
16
  function ValueOrDefault(schema, value) {
16
- return !(value === undefined) || !('default' in schema) ? value : schema.default;
17
+ return value === undefined && 'default' in schema ? Clone(schema.default) : value;
17
18
  }
18
19
  // ------------------------------------------------------------------
19
20
  // IsCheckable
@@ -3,12 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Default = void 0;
5
5
  const index_1 = require("../check/index");
6
- const index_2 = require("../deref/index");
7
- const index_3 = require("../../type/symbols/index");
6
+ const index_2 = require("../clone/index");
7
+ const index_3 = require("../deref/index");
8
+ const index_4 = require("../../type/symbols/index");
8
9
  // ------------------------------------------------------------------
9
10
  // ValueGuard
10
11
  // ------------------------------------------------------------------
11
- const index_4 = require("../guard/index");
12
+ const index_5 = require("../guard/index");
12
13
  // ------------------------------------------------------------------
13
14
  // TypeGuard
14
15
  // ------------------------------------------------------------------
@@ -17,13 +18,13 @@ const type_1 = require("../../type/guard/type");
17
18
  // ValueOrDefault
18
19
  // ------------------------------------------------------------------
19
20
  function ValueOrDefault(schema, value) {
20
- return !(value === undefined) || !('default' in schema) ? value : schema.default;
21
+ return value === undefined && 'default' in schema ? (0, index_2.Clone)(schema.default) : value;
21
22
  }
22
23
  // ------------------------------------------------------------------
23
24
  // IsCheckable
24
25
  // ------------------------------------------------------------------
25
26
  function IsCheckable(schema) {
26
- return (0, type_1.IsSchema)(schema) && schema[index_3.Kind] !== 'Unsafe';
27
+ return (0, type_1.IsSchema)(schema) && schema[index_4.Kind] !== 'Unsafe';
27
28
  }
28
29
  // ------------------------------------------------------------------
29
30
  // IsDefaultSchema
@@ -36,7 +37,7 @@ function IsDefaultSchema(value) {
36
37
  // ------------------------------------------------------------------
37
38
  function FromArray(schema, references, value) {
38
39
  const defaulted = ValueOrDefault(schema, value);
39
- if (!(0, index_4.IsArray)(defaulted))
40
+ if (!(0, index_5.IsArray)(defaulted))
40
41
  return defaulted;
41
42
  for (let i = 0; i < defaulted.length; i++) {
42
43
  defaulted[i] = Visit(schema.items, references, defaulted[i]);
@@ -47,12 +48,12 @@ function FromIntersect(schema, references, value) {
47
48
  const defaulted = ValueOrDefault(schema, value);
48
49
  return schema.allOf.reduce((acc, schema) => {
49
50
  const next = Visit(schema, references, defaulted);
50
- return (0, index_4.IsObject)(next) ? { ...acc, ...next } : next;
51
+ return (0, index_5.IsObject)(next) ? { ...acc, ...next } : next;
51
52
  }, {});
52
53
  }
53
54
  function FromObject(schema, references, value) {
54
55
  const defaulted = ValueOrDefault(schema, value);
55
- if (!(0, index_4.IsObject)(defaulted))
56
+ if (!(0, index_5.IsObject)(defaulted))
56
57
  return defaulted;
57
58
  const additionalPropertiesSchema = schema.additionalProperties;
58
59
  const knownPropertyKeys = Object.getOwnPropertyNames(schema.properties);
@@ -75,7 +76,7 @@ function FromObject(schema, references, value) {
75
76
  }
76
77
  function FromRecord(schema, references, value) {
77
78
  const defaulted = ValueOrDefault(schema, value);
78
- if (!(0, index_4.IsObject)(defaulted))
79
+ if (!(0, index_5.IsObject)(defaulted))
79
80
  return defaulted;
80
81
  const additionalPropertiesSchema = schema.additionalProperties;
81
82
  const [propertyKeyPattern, propertySchema] = Object.entries(schema.patternProperties)[0];
@@ -98,14 +99,14 @@ function FromRecord(schema, references, value) {
98
99
  return defaulted;
99
100
  }
100
101
  function FromRef(schema, references, value) {
101
- return Visit((0, index_2.Deref)(schema, references), references, ValueOrDefault(schema, value));
102
+ return Visit((0, index_3.Deref)(schema, references), references, ValueOrDefault(schema, value));
102
103
  }
103
104
  function FromThis(schema, references, value) {
104
- return Visit((0, index_2.Deref)(schema, references), references, value);
105
+ return Visit((0, index_3.Deref)(schema, references), references, value);
105
106
  }
106
107
  function FromTuple(schema, references, value) {
107
108
  const defaulted = ValueOrDefault(schema, value);
108
- if (!(0, index_4.IsArray)(defaulted) || (0, index_4.IsUndefined)(schema.items))
109
+ if (!(0, index_5.IsArray)(defaulted) || (0, index_5.IsUndefined)(schema.items))
109
110
  return defaulted;
110
111
  const [items, max] = [schema.items, Math.max(schema.items.length, defaulted.length)];
111
112
  for (let i = 0; i < max; i++) {
@@ -125,9 +126,9 @@ function FromUnion(schema, references, value) {
125
126
  return defaulted;
126
127
  }
127
128
  function Visit(schema, references, value) {
128
- const references_ = (0, index_4.IsString)(schema.$id) ? [...references, schema] : references;
129
+ const references_ = (0, index_5.IsString)(schema.$id) ? [...references, schema] : references;
129
130
  const schema_ = schema;
130
- switch (schema_[index_3.Kind]) {
131
+ switch (schema_[index_4.Kind]) {
131
132
  case 'Array':
132
133
  return FromArray(schema_, references_, value);
133
134
  case 'Intersect':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.32.6",
3
+ "version": "0.32.7",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",