@sinclair/typebox 0.34.37 → 0.34.39

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.
@@ -149,7 +149,7 @@ function FromNumber(schema, references, value) {
149
149
  }
150
150
  // prettier-ignore
151
151
  function FromObject(schema, references, value) {
152
- if (!(0, index_5.IsObject)(value))
152
+ if (!(0, index_5.IsObject)(value) || (0, index_5.IsArray)(value))
153
153
  return value;
154
154
  for (const propertyKey of Object.getOwnPropertyNames(schema.properties)) {
155
155
  if (!(0, index_5.HasPropertyKey)(value, propertyKey))
@@ -159,7 +159,7 @@ function FromObject(schema, references, value) {
159
159
  return value;
160
160
  }
161
161
  function FromRecord(schema, references, value) {
162
- const isConvertable = (0, index_5.IsObject)(value);
162
+ const isConvertable = (0, index_5.IsObject)(value) && !(0, index_5.IsArray)(value);
163
163
  if (!isConvertable)
164
164
  return value;
165
165
  const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
@@ -196,6 +196,13 @@ function FromUndefined(schema, references, value) {
196
196
  return TryConvertUndefined(value);
197
197
  }
198
198
  function FromUnion(schema, references, value) {
199
+ // Check if original value already matches one of the union variants
200
+ for (const subschema of schema.anyOf) {
201
+ if ((0, index_2.Check)(subschema, references, value)) {
202
+ return value;
203
+ }
204
+ }
205
+ // Attempt conversion for each variant
199
206
  for (const subschema of schema.anyOf) {
200
207
  const converted = Visit(subschema, references, (0, index_1.Clone)(value));
201
208
  if (!(0, index_2.Check)(subschema, references, converted))
@@ -145,7 +145,7 @@ function FromNumber(schema, references, value) {
145
145
  }
146
146
  // prettier-ignore
147
147
  function FromObject(schema, references, value) {
148
- if (!IsObject(value))
148
+ if (!IsObject(value) || IsArray(value))
149
149
  return value;
150
150
  for (const propertyKey of Object.getOwnPropertyNames(schema.properties)) {
151
151
  if (!HasPropertyKey(value, propertyKey))
@@ -155,7 +155,7 @@ function FromObject(schema, references, value) {
155
155
  return value;
156
156
  }
157
157
  function FromRecord(schema, references, value) {
158
- const isConvertable = IsObject(value);
158
+ const isConvertable = IsObject(value) && !IsArray(value);
159
159
  if (!isConvertable)
160
160
  return value;
161
161
  const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
@@ -192,6 +192,13 @@ function FromUndefined(schema, references, value) {
192
192
  return TryConvertUndefined(value);
193
193
  }
194
194
  function FromUnion(schema, references, value) {
195
+ // Check if original value already matches one of the union variants
196
+ for (const subschema of schema.anyOf) {
197
+ if (Check(subschema, references, value)) {
198
+ return value;
199
+ }
200
+ }
201
+ // Attempt conversion for each variant
195
202
  for (const subschema of schema.anyOf) {
196
203
  const converted = Visit(subschema, references, Clone(value));
197
204
  if (!Check(subschema, references, converted))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.37",
3
+ "version": "0.34.39",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",