@sinclair/typebox 0.32.22 → 0.32.24

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.
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
10
10
  Static<T, P>
11
11
  ];
12
12
  type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
- type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
13
+ type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
14
14
  export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
15
15
  [Kind]: 'Constructor';
16
16
  static: StaticConstructor<T, U, this['params']>;
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
10
10
  Static<T, P>
11
11
  ];
12
12
  type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
- type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
13
+ type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
14
14
  export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
15
15
  [Kind]: 'Function';
16
16
  static: StaticFunction<T, U, this['params']>;
@@ -102,7 +102,7 @@ function FromTuple(schema, references, value) {
102
102
  }
103
103
  function FromUnion(schema, references, value) {
104
104
  for (const inner of schema.anyOf) {
105
- if (IsCheckable(inner) && Check(inner, value)) {
105
+ if (IsCheckable(inner) && Check(inner, references, value)) {
106
106
  return Visit(inner, references, value);
107
107
  }
108
108
  }
@@ -5,7 +5,7 @@ import { Kind } from '../../type/symbols/index.mjs';
5
5
  // ------------------------------------------------------------------
6
6
  // ValueGuard
7
7
  // ------------------------------------------------------------------
8
- import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol } from '../guard/index.mjs';
8
+ import { IsArray, IsObject, IsDate, IsUndefined, IsString, IsNumber, IsBoolean, IsBigInt, IsSymbol, HasPropertyKey } from '../guard/index.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  // Conversions
11
11
  // ------------------------------------------------------------------
@@ -142,11 +142,13 @@ function FromObject(schema, references, value) {
142
142
  const isConvertable = IsObject(value);
143
143
  if (!isConvertable)
144
144
  return value;
145
- return Object.getOwnPropertyNames(schema.properties).reduce((value, key) => {
146
- return !IsUndefined(value[key])
147
- ? ({ ...value, [key]: Visit(schema.properties[key], references, value[key]) })
148
- : ({ ...value });
149
- }, value);
145
+ const result = {};
146
+ for (const key of Object.keys(value)) {
147
+ result[key] = HasPropertyKey(schema.properties, key)
148
+ ? Visit(schema.properties[key], references, value[key])
149
+ : value[key];
150
+ }
151
+ return result;
150
152
  }
151
153
  function FromRecord(schema, references, value) {
152
154
  const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
@@ -19,9 +19,9 @@ export declare function Check<T extends TSchema>(schema: T, value: unknown): val
19
19
  export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
20
20
  /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
21
21
  export declare function Clean(schema: TSchema, value: unknown): unknown;
22
- /** Converts any type mismatched values to their target type if a reasonable conversion is possible */
22
+ /** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
23
23
  export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
24
- /** Converts any type mismatched values to their target type if a reasonable conversion is possibl. */
24
+ /** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
25
25
  export declare function Convert(schema: TSchema, value: unknown): unknown;
26
26
  /** Returns a structural clone of the given value */
27
27
  export declare function Clone<T>(value: T): T;
@@ -27,7 +27,7 @@ export function Check(...args) {
27
27
  export function Clean(...args) {
28
28
  return CleanValue.apply(CleanValue, args);
29
29
  }
30
- /** Converts any type mismatched values to their target type if a reasonable conversion is possible */
30
+ /** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
31
31
  export function Convert(...args) {
32
32
  return ConvertValue.apply(ConvertValue, args);
33
33
  }
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
10
10
  Static<T, P>
11
11
  ];
12
12
  type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
- type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
13
+ type StaticConstructor<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<new (...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
14
14
  export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
15
15
  [Kind]: 'Constructor';
16
16
  static: StaticConstructor<T, U, this['params']>;
@@ -10,7 +10,7 @@ type StaticParameter<T extends TSchema, P extends unknown[]> = T extends TReadon
10
10
  Static<T, P>
11
11
  ];
12
12
  type StaticParameters<T extends TSchema[], P extends unknown[], Acc extends unknown[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? StaticParameters<R, P, [...Acc, ...StaticParameter<L, P>]> : Acc);
13
- type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...params: StaticParameters<T, P>) => StaticReturnType<U, P>>;
13
+ type StaticFunction<T extends TSchema[], U extends TSchema, P extends unknown[]> = Ensure<(...param: StaticParameters<T, P>) => StaticReturnType<U, P>>;
14
14
  export interface TFunction<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
15
15
  [Kind]: 'Function';
16
16
  static: StaticFunction<T, U, this['params']>;
@@ -106,7 +106,7 @@ function FromTuple(schema, references, value) {
106
106
  }
107
107
  function FromUnion(schema, references, value) {
108
108
  for (const inner of schema.anyOf) {
109
- if (IsCheckable(inner) && (0, index_2.Check)(inner, value)) {
109
+ if (IsCheckable(inner) && (0, index_2.Check)(inner, references, value)) {
110
110
  return Visit(inner, references, value);
111
111
  }
112
112
  }
@@ -146,11 +146,13 @@ function FromObject(schema, references, value) {
146
146
  const isConvertable = (0, index_5.IsObject)(value);
147
147
  if (!isConvertable)
148
148
  return value;
149
- return Object.getOwnPropertyNames(schema.properties).reduce((value, key) => {
150
- return !(0, index_5.IsUndefined)(value[key])
151
- ? ({ ...value, [key]: Visit(schema.properties[key], references, value[key]) })
152
- : ({ ...value });
153
- }, value);
149
+ const result = {};
150
+ for (const key of Object.keys(value)) {
151
+ result[key] = (0, index_5.HasPropertyKey)(schema.properties, key)
152
+ ? Visit(schema.properties[key], references, value[key])
153
+ : value[key];
154
+ }
155
+ return result;
154
156
  }
155
157
  function FromRecord(schema, references, value) {
156
158
  const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
@@ -19,9 +19,9 @@ export declare function Check<T extends TSchema>(schema: T, value: unknown): val
19
19
  export declare function Clean(schema: TSchema, references: TSchema[], value: unknown): unknown;
20
20
  /** `[Mutable]` Removes excess properties from a value and returns the result. This function does not check the value and returns an unknown type. You should Check the result before use. Clean is a mutable operation. To avoid mutation, Clone the value first. */
21
21
  export declare function Clean(schema: TSchema, value: unknown): unknown;
22
- /** Converts any type mismatched values to their target type if a reasonable conversion is possible */
22
+ /** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
23
23
  export declare function Convert(schema: TSchema, references: TSchema[], value: unknown): unknown;
24
- /** Converts any type mismatched values to their target type if a reasonable conversion is possibl. */
24
+ /** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
25
25
  export declare function Convert(schema: TSchema, value: unknown): unknown;
26
26
  /** Returns a structural clone of the given value */
27
27
  export declare function Clone<T>(value: T): T;
@@ -35,7 +35,7 @@ function Clean(...args) {
35
35
  return index_9.Clean.apply(index_9.Clean, args);
36
36
  }
37
37
  exports.Clean = Clean;
38
- /** Converts any type mismatched values to their target type if a reasonable conversion is possible */
38
+ /** Converts any type mismatched values to their target type if a reasonable conversion is possible. */
39
39
  function Convert(...args) {
40
40
  return index_7.Convert.apply(index_7.Convert, args);
41
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.32.22",
3
+ "version": "0.32.24",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",