@sinclair/typebox 0.25.9 → 0.25.10

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,6 +1,6 @@
1
1
  import { ValueError } from '../errors/index';
2
2
  import * as Types from '../typebox';
3
- export declare type CheckFunction = (value: unknown) => boolean;
3
+ export type CheckFunction = (value: unknown) => boolean;
4
4
  export declare class TypeCheck<T extends Types.TSchema> {
5
5
  private readonly schema;
6
6
  private readonly references;
@@ -237,11 +237,11 @@ var TypeCompiler;
237
237
  // Reference: If we have seen this reference before we can just yield and return
238
238
  // the function call. If this isn't the case we defer to visit to generate and
239
239
  // set the function for subsequent passes. Consider for refactor.
240
- if (names.has(schema.$ref))
240
+ if (state_local_function_names.has(schema.$ref))
241
241
  return yield `(${CreateFunctionName(schema.$ref)}(${value}))`;
242
- if (!referenceMap.has(schema.$ref))
242
+ if (!state_reference_map.has(schema.$ref))
243
243
  throw Error(`TypeCompiler.Ref: Cannot de-reference schema with $id '${schema.$ref}'`);
244
- const reference = referenceMap.get(schema.$ref);
244
+ const reference = state_reference_map.get(schema.$ref);
245
245
  yield* Visit(reference, value);
246
246
  }
247
247
  function* Self(schema, value) {
@@ -292,15 +292,17 @@ var TypeCompiler;
292
292
  function* Void(schema, value) {
293
293
  yield `(${value} === null)`;
294
294
  }
295
- function* Kind(schema, value) {
296
- yield `(custom('${schema[Types.Kind]}', ${value}))`;
295
+ function* UserDefined(schema, value) {
296
+ const schema_key = `schema_key_${state_remote_custom_types.size}`;
297
+ state_remote_custom_types.set(schema_key, schema);
298
+ yield `(custom('${schema[Types.Kind]}', '${schema_key}', ${value}))`;
297
299
  }
298
300
  function* Visit(schema, value) {
299
301
  // Reference: Referenced schemas can originate from either additional schemas
300
302
  // or inline in the schema itself. Ideally the recursive path should align to
301
303
  // reference path. Consider for refactor.
302
- if (schema.$id && !names.has(schema.$id)) {
303
- names.add(schema.$id);
304
+ if (schema.$id && !state_local_function_names.has(schema.$id)) {
305
+ state_local_function_names.add(schema.$id);
304
306
  const name = CreateFunctionName(schema.$id);
305
307
  const body = CreateFunction(name, schema, 'value');
306
308
  PushFunction(body);
@@ -358,27 +360,29 @@ var TypeCompiler;
358
360
  default:
359
361
  if (!index_4.Custom.Has(anySchema[Types.Kind]))
360
362
  throw new TypeCompilerUnknownTypeError(schema);
361
- return yield* Kind(anySchema, value);
363
+ return yield* UserDefined(anySchema, value);
362
364
  }
363
365
  }
364
366
  // -------------------------------------------------------------------
365
- // Compile State
367
+ // Compiler State
366
368
  // -------------------------------------------------------------------
367
- const referenceMap = new Map();
368
- const locals = new Set(); // local variables and functions
369
- const names = new Set(); // cache of local functions
369
+ const state_reference_map = new Map(); // tracks schemas with identifiers
370
+ const state_local_variables = new Set(); // local variables and functions
371
+ const state_local_function_names = new Set(); // local function names used call ref validators
372
+ const state_remote_custom_types = new Map(); // remote custom types used during compilation
370
373
  function ResetCompiler() {
371
- referenceMap.clear();
372
- locals.clear();
373
- names.clear();
374
+ state_reference_map.clear();
375
+ state_local_variables.clear();
376
+ state_local_function_names.clear();
377
+ state_remote_custom_types.clear();
374
378
  }
375
379
  function AddReferences(schemas = []) {
376
380
  for (const schema of schemas) {
377
381
  if (!schema.$id)
378
382
  throw new Error(`TypeCompiler: Referenced schemas must specify an $id.`);
379
- if (referenceMap.has(schema.$id))
383
+ if (state_reference_map.has(schema.$id))
380
384
  throw new Error(`TypeCompiler: Duplicate schema $id found for '${schema.$id}'`);
381
- referenceMap.set(schema.$id, schema);
385
+ state_reference_map.set(schema.$id, schema);
382
386
  }
383
387
  }
384
388
  function CreateExpression(schema, value) {
@@ -392,15 +396,15 @@ var TypeCompiler;
392
396
  return `function ${name}(value) {\n return (\n${expression}\n )\n}`;
393
397
  }
394
398
  function PushFunction(functionBody) {
395
- locals.add(functionBody);
399
+ state_local_variables.add(functionBody);
396
400
  }
397
401
  function PushLocal(expression) {
398
- const local = `local_${locals.size}`;
399
- locals.add(`const ${local} = ${expression}`);
402
+ const local = `local_${state_local_variables.size}`;
403
+ state_local_variables.add(`const ${local} = ${expression}`);
400
404
  return local;
401
405
  }
402
406
  function GetLocals() {
403
- return [...locals.values()];
407
+ return [...state_local_variables.values()];
404
408
  }
405
409
  // -------------------------------------------------------------------
406
410
  // Compile
@@ -416,12 +420,14 @@ var TypeCompiler;
416
420
  function Compile(schema, references = []) {
417
421
  index_2.TypeGuard.Assert(schema, references);
418
422
  const code = Build(schema, references);
423
+ const custom_schemas = new Map(state_remote_custom_types);
419
424
  const compiledFunction = globalThis.Function('custom', 'format', code);
420
- const checkFunction = compiledFunction((kind, value) => {
421
- if (!index_4.Custom.Has(kind))
425
+ const checkFunction = compiledFunction((kind, schema_key, value) => {
426
+ if (!index_4.Custom.Has(kind) || !custom_schemas.has(schema_key))
422
427
  return false;
428
+ const schema = custom_schemas.get(schema_key);
423
429
  const func = index_4.Custom.Get(kind);
424
- return func(value);
430
+ return func(schema, value);
425
431
  }, (format, value) => {
426
432
  if (!index_3.Format.Has(format))
427
433
  return false;
@@ -1,5 +1,5 @@
1
1
  import * as Types from '../typebox';
2
- export declare type TExtends<L extends Types.TSchema, R extends Types.TSchema, T extends Types.TSchema, U extends Types.TSchema> = Types.Static<L> extends Types.Static<R> ? T : U;
2
+ export type TExtends<L extends Types.TSchema, R extends Types.TSchema, T extends Types.TSchema, U extends Types.TSchema> = Types.Static<L> extends Types.Static<R> ? T : U;
3
3
  export interface TExclude<T extends Types.TUnion, U extends Types.TUnion> extends Types.TUnion<any[]> {
4
4
  static: Exclude<Types.Static<T, this['params']>, Types.Static<U, this['params']>>;
5
5
  }
@@ -57,7 +57,7 @@ var Structural;
57
57
  return true;
58
58
  if (guard_1.TypeGuard.TAny(right))
59
59
  return true;
60
- if (guard_1.TypeGuard.TCustom(right))
60
+ if (guard_1.TypeGuard.TUserDefined(right))
61
61
  throw Error(`Structural: Cannot structurally compare custom type '${right[Types.Kind]}'`);
62
62
  return false;
63
63
  }
@@ -668,7 +668,7 @@ var Structural;
668
668
  else if (guard_1.TypeGuard.TVoid(left)) {
669
669
  return Void(left, resolvedRight);
670
670
  }
671
- else if (guard_1.TypeGuard.TCustom(left)) {
671
+ else if (guard_1.TypeGuard.TUserDefined(left)) {
672
672
  throw Error(`Structural: Cannot structurally compare custom type '${left[Types.Kind]}'`);
673
673
  }
674
674
  else {
@@ -1,12 +1,12 @@
1
- export declare type CustomValidationFunction = (value: unknown) => boolean;
2
- /** Provides functions to create custom types */
1
+ export type CustomValidationFunction<TSchema> = (schema: TSchema, value: unknown) => boolean;
2
+ /** Provides functions to create user defined types */
3
3
  export declare namespace Custom {
4
- /** Clears all custom types */
4
+ /** Clears all user defined types */
5
5
  function Clear(): void;
6
- /** Returns true if this kind exists */
6
+ /** Returns true if this user defined type exists */
7
7
  function Has(kind: string): boolean;
8
- /** Sets a validation function for a custom kind */
9
- function Set(kind: string, func: CustomValidationFunction): void;
10
- /** Gets a custom validation function */
11
- function Get(kind: string): CustomValidationFunction | undefined;
8
+ /** Sets a validation function for a user defined type */
9
+ function Set<TSchema = unknown>(kind: string, func: CustomValidationFunction<TSchema>): void;
10
+ /** Gets a custom validation function for a user defined type */
11
+ function Get(kind: string): CustomValidationFunction<any> | undefined;
12
12
  }
package/custom/custom.js CHANGED
@@ -28,26 +28,26 @@ THE SOFTWARE.
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.Custom = void 0;
31
- /** Provides functions to create custom types */
31
+ /** Provides functions to create user defined types */
32
32
  var Custom;
33
33
  (function (Custom) {
34
34
  const customs = new Map();
35
- /** Clears all custom types */
35
+ /** Clears all user defined types */
36
36
  function Clear() {
37
37
  return customs.clear();
38
38
  }
39
39
  Custom.Clear = Clear;
40
- /** Returns true if this kind exists */
40
+ /** Returns true if this user defined type exists */
41
41
  function Has(kind) {
42
42
  return customs.has(kind);
43
43
  }
44
44
  Custom.Has = Has;
45
- /** Sets a validation function for a custom kind */
45
+ /** Sets a validation function for a user defined type */
46
46
  function Set(kind, func) {
47
47
  customs.set(kind, func);
48
48
  }
49
49
  Custom.Set = Set;
50
- /** Gets a custom validation function */
50
+ /** Gets a custom validation function for a user defined type */
51
51
  function Get(kind) {
52
52
  return customs.get(kind);
53
53
  }
package/errors/errors.js CHANGED
@@ -367,9 +367,9 @@ var ValueErrors;
367
367
  return yield { type: ValueErrorType.Void, schema, path, value, message: `Expected null` };
368
368
  }
369
369
  }
370
- function* CustomType(schema, references, path, value) {
370
+ function* UserDefined(schema, references, path, value) {
371
371
  const func = index_2.Custom.Get(schema[Types.Kind]);
372
- if (!func(value)) {
372
+ if (!func(schema, value)) {
373
373
  return yield { type: ValueErrorType.Custom, schema, path, value, message: `Expected kind ${schema[Types.Kind]}` };
374
374
  }
375
375
  }
@@ -426,7 +426,7 @@ var ValueErrors;
426
426
  default:
427
427
  if (!index_2.Custom.Has(anySchema[Types.Kind]))
428
428
  throw new ValueErrorsUnknownTypeError(schema);
429
- return yield* CustomType(anySchema, anyReferences, path, value);
429
+ return yield* UserDefined(anySchema, anyReferences, path, value);
430
430
  }
431
431
  }
432
432
  function* Errors(schema, references, value) {
@@ -1,12 +1,12 @@
1
- export declare type FormatValidationFunction = (value: string) => boolean;
2
- /** Provides functions to create custom string formats */
1
+ export type FormatValidationFunction = (value: string) => boolean;
2
+ /** Provides functions to create user defined string formats */
3
3
  export declare namespace Format {
4
- /** Clears all formats */
4
+ /** Clears all user defined string formats */
5
5
  function Clear(): void;
6
- /** Returns true if the string format exists */
6
+ /** Returns true if the user defined string format exists */
7
7
  function Has(format: string): boolean;
8
- /** Sets a string format validation function */
8
+ /** Sets a validation function for a user defined string format */
9
9
  function Set(format: string, func: FormatValidationFunction): void;
10
- /** Gets a string format validation function */
10
+ /** Gets a validation function for a user defined string format */
11
11
  function Get(format: string): FormatValidationFunction | undefined;
12
12
  }
package/format/format.js CHANGED
@@ -28,26 +28,26 @@ THE SOFTWARE.
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.Format = void 0;
31
- /** Provides functions to create custom string formats */
31
+ /** Provides functions to create user defined string formats */
32
32
  var Format;
33
33
  (function (Format) {
34
34
  const formats = new Map();
35
- /** Clears all formats */
35
+ /** Clears all user defined string formats */
36
36
  function Clear() {
37
37
  return formats.clear();
38
38
  }
39
39
  Format.Clear = Clear;
40
- /** Returns true if the string format exists */
40
+ /** Returns true if the user defined string format exists */
41
41
  function Has(format) {
42
42
  return formats.has(format);
43
43
  }
44
44
  Format.Has = Has;
45
- /** Sets a string format validation function */
45
+ /** Sets a validation function for a user defined string format */
46
46
  function Set(format, func) {
47
47
  formats.set(format, func);
48
48
  }
49
49
  Format.Set = Set;
50
- /** Gets a string format validation function */
50
+ /** Gets a validation function for a user defined string format */
51
51
  function Get(format) {
52
52
  return formats.get(format);
53
53
  }
package/guard/guard.d.ts CHANGED
@@ -51,8 +51,8 @@ export declare namespace TypeGuard {
51
51
  function TUnknown(schema: unknown): schema is Types.TUnknown;
52
52
  /** Returns true if the given schema is TVoid */
53
53
  function TVoid(schema: unknown): schema is Types.TVoid;
54
- /** Returns true if the given schema is a registered custom type */
55
- function TCustom(schema: unknown): schema is Types.TSchema;
54
+ /** Returns true if the given schema is a registered user defined type */
55
+ function TUserDefined(schema: unknown): schema is Types.TSchema;
56
56
  /** Returns true if the given schema is TSchema */
57
57
  function TSchema(schema: unknown): schema is Types.TSchema;
58
58
  /** Asserts if this schema and associated references are valid. */
package/guard/guard.js CHANGED
@@ -394,11 +394,11 @@ var TypeGuard;
394
394
  IsOptionalString(schema.$id));
395
395
  }
396
396
  TypeGuard.TVoid = TVoid;
397
- /** Returns true if the given schema is a registered custom type */
398
- function TCustom(schema) {
397
+ /** Returns true if the given schema is a registered user defined type */
398
+ function TUserDefined(schema) {
399
399
  return IsObject(schema) && IsString(schema[Types.Kind]) && index_1.Custom.Has(schema[Types.Kind]);
400
400
  }
401
- TypeGuard.TCustom = TCustom;
401
+ TypeGuard.TUserDefined = TUserDefined;
402
402
  /** Returns true if the given schema is TSchema */
403
403
  function TSchema(schema) {
404
404
  return (TAny(schema) ||
@@ -424,7 +424,7 @@ var TypeGuard;
424
424
  TUint8Array(schema) ||
425
425
  TUnknown(schema) ||
426
426
  TVoid(schema) ||
427
- TCustom(schema));
427
+ TUserDefined(schema));
428
428
  }
429
429
  TypeGuard.TSchema = TSchema;
430
430
  /** Asserts if this schema and associated references are valid. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.25.9",
3
+ "version": "0.25.10",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
@@ -39,12 +39,12 @@
39
39
  "@sinclair/hammer": "^0.17.1",
40
40
  "@types/chai": "^4.3.3",
41
41
  "@types/mocha": "^9.1.1",
42
- "@types/node": "^18.7.13",
43
- "ajv": "^8.11.0",
42
+ "@types/node": "^18.11.9",
43
+ "ajv": "^8.11.2",
44
44
  "ajv-formats": "^2.1.1",
45
45
  "chai": "^4.3.6",
46
46
  "mocha": "^9.2.2",
47
47
  "prettier": "^2.7.1",
48
- "typescript": "^4.8.2"
48
+ "typescript": "^4.9.3"
49
49
  }
50
50
  }
package/readme.md CHANGED
@@ -97,8 +97,8 @@ License MIT
97
97
  - [TypeCheck](#typecheck)
98
98
  - [Ajv](#typecheck-ajv)
99
99
  - [TypeCompiler](#typecheck-typecompiler)
100
- - [Custom](#typecheck-custom)
101
- - [Formats](#typecheck-formats)
100
+ - [Custom Types](#typecheck-custom-types)
101
+ - [Custom Formats](#typecheck-custom-formats)
102
102
  - [Benchmark](#benchmark)
103
103
  - [Compile](#benchmark-compile)
104
104
  - [Validate](#benchmark-validate)
@@ -1118,11 +1118,11 @@ console.log(C.Code()) // return function check(va
1118
1118
  // }
1119
1119
  ```
1120
1120
 
1121
- <a name='typecheck-custom'></a>
1121
+ <a name='typecheck-custom-types'></a>
1122
1122
 
1123
- ### Custom
1123
+ ### Custom Types
1124
1124
 
1125
- Use custom module to create a custom types. When creating a custom type you must specify a `Kind` symbol property on the types schema. The `Kind` symbol property should match the name used to register the type. Custom types are used by the Value and TypeCompiler modules only.
1125
+ Use the custom module to create user defined types. User defined types require a `[Kind]` symbol property which is used to match the schema against a registered type. Custom types are specific to TypeBox and can only be used with the TypeCompiler and Value modules.
1126
1126
 
1127
1127
  The custom module is an optional import.
1128
1128
 
@@ -1130,23 +1130,27 @@ The custom module is an optional import.
1130
1130
  import { Custom } from '@sinclair/typebox/custom'
1131
1131
  ```
1132
1132
 
1133
- The following registers a BigInt custom type.
1133
+ The following creates a `BigInt` type.
1134
1134
 
1135
1135
  ```typescript
1136
1136
  import { Type, Kind } from '@sinclair/typebox'
1137
1137
 
1138
- Custom.Set('BigInt', value => typeof value === 'bigint')
1139
-
1138
+ Custom.Set('BigInt', (schema, value) => typeof value === 'bigint')
1139
+ // │
1140
+ // └────────────────────────────┐ The [Kind] is used to match registered type
1141
+ // │
1140
1142
  const T = Type.Unsafe<bigint>({ [Kind]: 'BigInt' }) // const T = { [Kind]: 'BigInt' }
1141
1143
 
1142
- const R = Value.Check(T, 65536n) // const R = true
1144
+ const A = TypeCompiler.Compile(T).Check(65536) // const A = false
1145
+
1146
+ const B = Value.Check(T, 65536n) // const B = true
1143
1147
  ```
1144
1148
 
1145
- <a name='typecheck-formats'></a>
1149
+ <a name='typecheck-custom-formats'></a>
1146
1150
 
1147
- ### Formats
1151
+ ### Custom Formats
1148
1152
 
1149
- Use the format module to create user defined string formats. The format module is used by the Value and TypeCompiler modules only. If using Ajv, please refer to the official Ajv format documentation located [here](https://ajv.js.org/guide/formats.html).
1153
+ Use the format module to create user defined string formats. If using Ajv, please refer to the official Ajv format documentation located [here](https://ajv.js.org/guide/formats.html). The format module is specific to TypeBox can only be used with the TypeCompiler and Value modules.
1150
1154
 
1151
1155
  The format module is an optional import.
1152
1156
 
@@ -1154,7 +1158,7 @@ The format module is an optional import.
1154
1158
  import { Format } from '@sinclair/typebox/format'
1155
1159
  ```
1156
1160
 
1157
- The following creates a `palindrome` string format.
1161
+ The following creates a palindrome string format.
1158
1162
 
1159
1163
  ```typescript
1160
1164
  Format.Set('palindrome', value => value === value.split('').reverse().join(''))
@@ -1174,7 +1178,7 @@ const B = Value.Check(T, 'kayak') // const B = true
1174
1178
 
1175
1179
  ## Benchmark
1176
1180
 
1177
- This project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. The results below show for Ajv version 8.11.0.
1181
+ This project maintains a set of benchmarks that measure Ajv, Value and TypeCompiler compilation and validation performance. These benchmarks can be run locally by cloning this repository and running `npm run benchmark`. The results below show for Ajv version 8.11.2.
1178
1182
 
1179
1183
  For additional comparative benchmarks, please refer to [typescript-runtime-type-benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/).
1180
1184
 
@@ -1188,29 +1192,29 @@ This benchmark measures compilation performance for varying types. You can revie
1188
1192
  ┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
1189
1193
  │ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
1190
1194
  ├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
1191
- │ Number │ 2000 │ ' 427 ms' │ ' 13 ms' │ ' 32.85 x' │
1192
- │ String │ 2000 │ ' 367 ms' │ ' 12 ms' │ ' 30.58 x' │
1193
- │ Boolean │ 2000 │ ' 297 ms' │ ' 13 ms' │ ' 22.85 x' │
1194
- │ Null │ 2000 │ ' 255 ms' │ ' 9 ms' │ ' 28.33 x' │
1195
- │ RegEx │ 2000 │ ' 487 ms' │ ' 17 ms' │ ' 28.65 x' │
1196
- │ ObjectA │ 2000 │ ' 2718 ms' │ ' 53 ms' │ ' 51.28 x' │
1197
- │ ObjectB │ 2000 │ ' 2874 ms' │ ' 36 ms' │ ' 79.83 x' │
1198
- │ Tuple │ 2000 │ ' 1221 ms' │ ' 22 ms' │ ' 55.50 x' │
1199
- │ Union │ 2000 │ ' 1223 ms' │ ' 24 ms' │ ' 50.96 x' │
1200
- │ Vector4 │ 2000 │ ' 1517 ms' │ ' 21 ms' │ ' 72.24 x' │
1195
+ │ Number │ 2000 │ ' 414 ms' │ ' 14 ms' │ ' 29.57 x' │
1196
+ │ String │ 2000 │ ' 326 ms' │ ' 12 ms' │ ' 27.17 x' │
1197
+ │ Boolean │ 2000 │ ' 301 ms' │ ' 11 ms' │ ' 27.36 x' │
1198
+ │ Null │ 2000 │ ' 253 ms' │ ' 8 ms' │ ' 31.63 x' │
1199
+ │ RegEx │ 2000 │ ' 480 ms' │ ' 18 ms' │ ' 26.67 x' │
1200
+ │ ObjectA │ 2000 │ ' 2704 ms' │ ' 53 ms' │ ' 51.02 x' │
1201
+ │ ObjectB │ 2000 │ ' 2846 ms' │ ' 35 ms' │ ' 81.31 x' │
1202
+ │ Tuple │ 2000 │ ' 1244 ms' │ ' 23 ms' │ ' 54.09 x' │
1203
+ │ Union │ 2000 │ ' 1222 ms' │ ' 26 ms' │ ' 47.00 x' │
1204
+ │ Vector4 │ 2000 │ ' 1522 ms' │ ' 22 ms' │ ' 69.18 x' │
1201
1205
  │ Matrix4 │ 2000 │ ' 830 ms' │ ' 10 ms' │ ' 83.00 x' │
1202
- │ Literal_String │ 2000 │ ' 334 ms' │ ' 8 ms' │ ' 41.75 x' │
1203
- │ Literal_Number │ 2000 │ ' 357 ms' │ ' 6 ms' │ ' 59.50 x' │
1204
- │ Literal_Boolean │ 2000 │ ' 353 ms' │ ' 7 ms' │ ' 50.43 x' │
1205
- │ Array_Number │ 2000 │ ' 679 ms' │ ' 11 ms' │ ' 61.73 x' │
1206
- │ Array_String │ 2000 │ ' 713 ms' │ ' 10 ms' │ ' 71.30 x' │
1207
- │ Array_Boolean │ 2000 │ ' 710 ms' │ ' 7 ms' │ ' 101.43 x' │
1208
- │ Array_ObjectA │ 2000 │ ' 3571 ms' │ ' 35 ms' │ ' 102.03 x' │
1209
- │ Array_ObjectB │ 2000 │ ' 3567 ms' │ ' 41 ms' │ ' 87.00 x' │
1210
- │ Array_Tuple │ 2000 │ ' 2083 ms' │ ' 19 ms' │ ' 109.63 x' │
1211
- │ Array_Union │ 2000 │ ' 1559 ms' │ ' 23 ms' │ ' 67.78 x' │
1212
- │ Array_Vector4 │ 2000 │ ' 2156 ms' │ ' 19 ms' │ ' 113.47 x' │
1213
- │ Array_Matrix4 │ 2000 │ ' 1483 ms' │ ' 13 ms' │ ' 114.08 x' │
1206
+ │ Literal_String │ 2000 │ ' 348 ms' │ ' 9 ms' │ ' 38.67 x' │
1207
+ │ Literal_Number │ 2000 │ ' 356 ms' │ ' 9 ms' │ ' 39.56 x' │
1208
+ │ Literal_Boolean │ 2000 │ ' 353 ms' │ ' 6 ms' │ ' 58.83 x' │
1209
+ │ Array_Number │ 2000 │ ' 686 ms' │ ' 11 ms' │ ' 62.36 x' │
1210
+ │ Array_String │ 2000 │ ' 722 ms' │ ' 11 ms' │ ' 65.64 x' │
1211
+ │ Array_Boolean │ 2000 │ ' 724 ms' │ ' 9 ms' │ ' 80.44 x' │
1212
+ │ Array_ObjectA │ 2000 │ ' 3706 ms' │ ' 36 ms' │ ' 102.94 x' │
1213
+ │ Array_ObjectB │ 2000 │ ' 3678 ms' │ ' 38 ms' │ ' 96.79 x' │
1214
+ │ Array_Tuple │ 2000 │ ' 2217 ms' │ ' 23 ms' │ ' 96.39 x' │
1215
+ │ Array_Union │ 2000 │ ' 1654 ms' │ ' 24 ms' │ ' 68.92 x' │
1216
+ │ Array_Vector4 │ 2000 │ ' 2283 ms' │ ' 20 ms' │ ' 114.15 x' │
1217
+ │ Array_Matrix4 │ 2000 │ ' 1567 ms' │ ' 19 ms' │ ' 82.47 x' │
1214
1218
  └──────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
1215
1219
  ```
1216
1220
 
@@ -1224,31 +1228,31 @@ This benchmark measures validation performance for varying types. You can review
1224
1228
  ┌──────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
1225
1229
  │ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
1226
1230
  ├──────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
1227
- │ Number │ 1000000 │ ' 25 ms' │ ' 6 ms' │ ' 5 ms' │ ' 1.20 x' │
1228
- │ String │ 1000000 │ ' 22 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
1229
- │ Boolean │ 1000000 │ ' 21 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
1230
- │ Null │ 1000000 │ ' 24 ms' │ ' 21 ms' │ ' 9 ms' │ ' 2.33 x' │
1231
- │ RegEx │ 1000000 │ ' 158 ms' │ ' 46 ms' │ ' 37 ms' │ ' 1.24 x' │
1232
- │ ObjectA │ 1000000 │ ' 566 ms' │ ' 36 ms' │ ' 24 ms' │ ' 1.50 x' │
1233
- │ ObjectB │ 1000000 │ ' 1026 ms' │ ' 52 ms' │ ' 40 ms' │ ' 1.30 x' │
1234
- │ Tuple │ 1000000 │ ' 121 ms' │ ' 23 ms' │ ' 14 ms' │ ' 1.64 x' │
1235
- │ Union │ 1000000 │ ' 299 ms' │ ' 26 ms' │ ' 16 ms' │ ' 1.63 x' │
1236
- │ Recursive │ 1000000 │ ' 3168 ms' │ ' 414 ms' │ ' 97 ms' │ ' 4.27 x' │
1237
- │ Vector4 │ 1000000 │ ' 147 ms' │ ' 22 ms' │ ' 11 ms' │ ' 2.00 x' │
1238
- │ Matrix4 │ 1000000 │ ' 573 ms' │ ' 40 ms' │ ' 29 ms' │ ' 1.38 x' │
1239
- │ Literal_String │ 1000000 │ ' 48 ms' │ ' 19 ms' │ ' 10 ms' │ ' 1.90 x' │
1240
- │ Literal_Number │ 1000000 │ ' 46 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
1241
- │ Literal_Boolean │ 1000000 │ ' 48 ms' │ ' 20 ms' │ ' 10 ms' │ ' 2.00 x' │
1242
- │ Array_Number │ 1000000 │ ' 454 ms' │ ' 32 ms' │ ' 18 ms' │ ' 1.78 x' │
1243
- │ Array_String │ 1000000 │ ' 481 ms' │ ' 32 ms' │ ' 22 ms' │ ' 1.45 x' │
1244
- │ Array_Boolean │ 1000000 │ ' 448 ms' │ ' 34 ms' │ ' 27 ms' │ ' 1.26 x' │
1245
- │ Array_ObjectA │ 1000000 │ ' 13709 ms' │ ' 2360 ms' │ ' 1548 ms' │ ' 1.52 x' │
1246
- │ Array_ObjectB │ 1000000 │ ' 16602 ms' │ ' 2585 ms' │ ' 1904 ms' │ ' 1.36 x' │
1247
- │ Array_Tuple │ 1000000 │ ' 1831 ms' │ ' 96 ms' │ ' 63 ms' │ ' 1.52 x' │
1248
- │ Array_Union │ 1000000 │ ' 4958 ms' │ ' 234 ms' │ ' 86 ms' │ ' 2.72 x' │
1249
- │ Array_Recursive │ 1000000 │ ' 55876 ms' │ ' 7160 ms' │ ' 1138 ms' │ ' 6.29 x' │
1250
- │ Array_Vector4 │ 1000000 │ ' 2381 ms' │ ' 99 ms' │ ' 47 ms' │ ' 2.11 x' │
1251
- │ Array_Matrix4 │ 1000000 │ ' 11670 ms' │ ' 383 ms' │ ' 228 ms' │ ' 1.68 x' │
1231
+ │ Number │ 1000000 │ ' 33 ms' │ ' 6 ms' │ ' 5 ms' │ ' 1.20 x' │
1232
+ │ String │ 1000000 │ ' 26 ms' │ ' 24 ms' │ ' 12 ms' │ ' 2.00 x' │
1233
+ │ Boolean │ 1000000 │ ' 24 ms' │ ' 22 ms' │ ' 11 ms' │ ' 2.00 x' │
1234
+ │ Null │ 1000000 │ ' 28 ms' │ ' 24 ms' │ ' 11 ms' │ ' 2.18 x' │
1235
+ │ RegEx │ 1000000 │ ' 171 ms' │ ' 56 ms' │ ' 41 ms' │ ' 1.37 x' │
1236
+ │ ObjectA │ 1000000 │ ' 614 ms' │ ' 42 ms' │ ' 24 ms' │ ' 1.75 x' │
1237
+ │ ObjectB │ 1000000 │ ' 1109 ms' │ ' 59 ms' │ ' 45 ms' │ ' 1.31 x' │
1238
+ │ Tuple │ 1000000 │ ' 122 ms' │ ' 25 ms' │ ' 13 ms' │ ' 1.92 x' │
1239
+ │ Union │ 1000000 │ ' 316 ms' │ ' 26 ms' │ ' 16 ms' │ ' 1.63 x' │
1240
+ │ Recursive │ 1000000 │ ' 3219 ms' │ ' 453 ms' │ ' 128 ms' │ ' 3.54 x' │
1241
+ │ Vector4 │ 1000000 │ ' 145 ms' │ ' 26 ms' │ ' 13 ms' │ ' 2.00 x' │
1242
+ │ Matrix4 │ 1000000 │ ' 537 ms' │ ' 42 ms' │ ' 28 ms' │ ' 1.50 x' │
1243
+ │ Literal_String │ 1000000 │ ' 51 ms' │ ' 21 ms' │ ' 11 ms' │ ' 1.91 x' │
1244
+ │ Literal_Number │ 1000000 │ ' 48 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
1245
+ │ Literal_Boolean │ 1000000 │ ' 49 ms' │ ' 20 ms' │ ' 11 ms' │ ' 1.82 x' │
1246
+ │ Array_Number │ 1000000 │ ' 438 ms' │ ' 35 ms' │ ' 19 ms' │ ' 1.84 x' │
1247
+ │ Array_String │ 1000000 │ ' 468 ms' │ ' 33 ms' │ ' 23 ms' │ ' 1.43 x' │
1248
+ │ Array_Boolean │ 1000000 │ ' 448 ms' │ ' 36 ms' │ ' 29 ms' │ ' 1.24 x' │
1249
+ │ Array_ObjectA │ 1000000 │ ' 13904 ms' │ ' 2536 ms' │ ' 1530 ms' │ ' 1.66 x' │
1250
+ │ Array_ObjectB │ 1000000 │ ' 16188 ms' │ ' 2724 ms' │ ' 1834 ms' │ ' 1.49 x' │
1251
+ │ Array_Tuple │ 1000000 │ ' 1725 ms' │ ' 98 ms' │ ' 64 ms' │ ' 1.53 x' │
1252
+ │ Array_Union │ 1000000 │ ' 4762 ms' │ ' 237 ms' │ ' 87 ms' │ ' 2.72 x' │
1253
+ │ Array_Recursive │ 1000000 │ ' 54754 ms' │ ' 7707 ms' │ ' 1152 ms' │ ' 6.69 x' │
1254
+ │ Array_Vector4 │ 1000000 │ ' 2485 ms' │ ' 100 ms' │ ' 48 ms' │ ' 2.08 x' │
1255
+ │ Array_Matrix4 │ 1000000 │ ' 13116 ms' │ ' 387 ms' │ ' 232 ms' │ ' 1.67 x' │
1252
1256
  └──────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
1253
1257
  ```
1254
1258
 
@@ -1262,12 +1266,12 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
1262
1266
  ┌──────────────────────┬────────────┬────────────┬─────────────┐
1263
1267
  │ (index) │ Compiled │ Minified │ Compression │
1264
1268
  ├──────────────────────┼────────────┼────────────┼─────────────┤
1265
- │ typebox/compiler │ ' 55 kb' │ ' 27 kb' │ '2.00 x' │
1269
+ │ typebox/compiler │ ' 56 kb' │ ' 28 kb' │ '2.01 x' │
1266
1270
  │ typebox/conditional │ ' 45 kb' │ ' 18 kb' │ '2.44 x' │
1267
1271
  │ typebox/custom │ ' 0 kb' │ ' 0 kb' │ '2.61 x' │
1268
1272
  │ typebox/format │ ' 0 kb' │ ' 0 kb' │ '2.66 x' │
1269
1273
  │ typebox/guard │ ' 23 kb' │ ' 11 kb' │ '2.07 x' │
1270
- │ typebox/value │ ' 80 kb' │ ' 37 kb' │ '2.15 x' │
1274
+ │ typebox/value │ ' 80 kb' │ ' 37 kb' │ '2.16 x' │
1271
1275
  │ typebox │ ' 12 kb' │ ' 6 kb' │ '1.89 x' │
1272
1276
  └──────────────────────┴────────────┴────────────┴─────────────┘
1273
1277
  ```
package/typebox.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export declare const Kind: unique symbol;
2
2
  export declare const Hint: unique symbol;
3
3
  export declare const Modifier: unique symbol;
4
- export declare type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
5
- export declare type TReadonly<T extends TSchema> = T & {
4
+ export type TModifier = TReadonlyOptional<TSchema> | TOptional<TSchema> | TReadonly<TSchema>;
5
+ export type TReadonly<T extends TSchema> = T & {
6
6
  [Modifier]: 'Readonly';
7
7
  };
8
- export declare type TOptional<T extends TSchema> = T & {
8
+ export type TOptional<T extends TSchema> = T & {
9
9
  [Modifier]: 'Optional';
10
10
  };
11
- export declare type TReadonlyOptional<T extends TSchema> = T & {
11
+ export type TReadonlyOptional<T extends TSchema> = T & {
12
12
  [Modifier]: 'ReadonlyOptional';
13
13
  };
14
14
  export interface SchemaOptions {
@@ -32,7 +32,7 @@ export interface TSchema extends SchemaOptions {
32
32
  params: unknown[];
33
33
  static: unknown;
34
34
  }
35
- export declare type TAnySchema = TSchema | TAny | TArray | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TLiteral | TNull | TNumber | TObject | TPromise | TRecord | TSelf | TRef | TString | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
35
+ export type TAnySchema = TSchema | TAny | TArray | TBoolean | TConstructor | TDate | TEnum | TFunction | TInteger | TLiteral | TNull | TNumber | TObject | TPromise | TRecord | TSelf | TRef | TString | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
36
36
  export interface NumericOptions extends SchemaOptions {
37
37
  exclusiveMaximum?: number;
38
38
  exclusiveMinimum?: number;
@@ -40,7 +40,7 @@ export interface NumericOptions extends SchemaOptions {
40
40
  minimum?: number;
41
41
  multipleOf?: number;
42
42
  }
43
- export declare type TNumeric = TInteger | TNumber;
43
+ export type TNumeric = TInteger | TNumber;
44
44
  export interface TAny extends TSchema {
45
45
  [Kind]: 'Any';
46
46
  static: any;
@@ -61,9 +61,9 @@ export interface TBoolean extends TSchema {
61
61
  static: boolean;
62
62
  type: 'boolean';
63
63
  }
64
- export declare type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
65
- export declare type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
66
- export declare type StaticContructorParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
64
+ export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
65
+ export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
66
+ export type StaticContructorParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
67
67
  [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
68
68
  }];
69
69
  export interface TConstructor<T extends TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
@@ -95,9 +95,9 @@ export interface TEnum<T extends Record<string, string | number> = Record<string
95
95
  static: T[keyof T];
96
96
  anyOf: TLiteral<string | number>[];
97
97
  }
98
- export declare type TParameters<T extends TFunction> = TTuple<T['parameters']>;
99
- export declare type TReturnType<T extends TFunction> = T['returns'];
100
- export declare type StaticFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
98
+ export type TParameters<T extends TFunction> = TTuple<T['parameters']>;
99
+ export type TReturnType<T extends TFunction> = T['returns'];
100
+ export type StaticFunctionParameters<T extends readonly TSchema[], P extends unknown[]> = [...{
101
101
  [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
102
102
  }];
103
103
  export interface TFunction<T extends readonly TSchema[] = TSchema[], U extends TSchema = TSchema> extends TSchema {
@@ -113,29 +113,29 @@ export interface TInteger extends TSchema, NumericOptions {
113
113
  static: number;
114
114
  type: 'integer';
115
115
  }
116
- export declare type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I extends object ? I : {};
117
- export declare type IntersectEvaluate<T extends readonly TSchema[], P extends unknown[]> = {
116
+ export type IntersectReduce<I extends unknown, T extends readonly any[]> = T extends [infer A, ...infer B] ? IntersectReduce<I & A, B> : I extends object ? I : {};
117
+ export type IntersectEvaluate<T extends readonly TSchema[], P extends unknown[]> = {
118
118
  [K in keyof T]: T[K] extends TSchema ? Static<T[K], P> : never;
119
119
  };
120
- export declare type IntersectProperties<T extends readonly TObject[]> = {
120
+ export type IntersectProperties<T extends readonly TObject[]> = {
121
121
  [K in keyof T]: T[K] extends TObject<infer P> ? P : {};
122
122
  };
123
123
  export interface TIntersect<T extends TObject[] = TObject[]> extends TObject {
124
124
  static: IntersectReduce<unknown, IntersectEvaluate<T, this['params']>>;
125
125
  properties: IntersectReduce<unknown, IntersectProperties<T>>;
126
126
  }
127
- export declare type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
128
- export declare type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
129
- export declare type UnionToTuple<U, L = UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, L>>, L];
130
- export declare type UnionStringLiteralToTuple<T> = T extends TUnion<infer L> ? {
127
+ export type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
128
+ export type UnionLast<U> = UnionToIntersect<U extends unknown ? (x: U) => 0 : never> extends (x: infer L) => 0 ? L : never;
129
+ export type UnionToTuple<U, L = UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, L>>, L];
130
+ export type UnionStringLiteralToTuple<T> = T extends TUnion<infer L> ? {
131
131
  [I in keyof L]: L[I] extends TLiteral<infer C> ? C : never;
132
132
  } : never;
133
- export declare type UnionLiteralsFromObject<T extends TObject> = {
133
+ export type UnionLiteralsFromObject<T extends TObject> = {
134
134
  [K in ObjectPropertyKeys<T>]: TLiteral<K>;
135
135
  } extends infer R ? UnionToTuple<R[keyof R]> : never;
136
136
  export interface TKeyOf<T extends TObject> extends TUnion<UnionLiteralsFromObject<T>> {
137
137
  }
138
- export declare type TLiteralValue = string | number | boolean;
138
+ export type TLiteralValue = string | number | boolean;
139
139
  export interface TLiteral<T extends TLiteralValue = TLiteralValue> extends TSchema {
140
140
  [Kind]: 'Literal';
141
141
  static: T;
@@ -162,17 +162,17 @@ export interface TNumber extends TSchema, NumericOptions {
162
162
  static: number;
163
163
  type: 'number';
164
164
  }
165
- export declare type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
165
+ export type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
166
166
  [K in keyof T]: T[K] extends TReadonlyOptional<TSchema> ? K : never;
167
167
  }[keyof T];
168
- export declare type ReadonlyPropertyKeys<T extends TProperties> = {
168
+ export type ReadonlyPropertyKeys<T extends TProperties> = {
169
169
  [K in keyof T]: T[K] extends TReadonly<TSchema> ? K : never;
170
170
  }[keyof T];
171
- export declare type OptionalPropertyKeys<T extends TProperties> = {
171
+ export type OptionalPropertyKeys<T extends TProperties> = {
172
172
  [K in keyof T]: T[K] extends TOptional<TSchema> ? K : never;
173
173
  }[keyof T];
174
- export declare type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
175
- export declare type PropertiesReduce<T extends TProperties, P extends unknown[]> = {
174
+ export type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
175
+ export type PropertiesReduce<T extends TProperties, P extends unknown[]> = {
176
176
  readonly [K in ReadonlyOptionalPropertyKeys<T>]?: Static<T[K], P>;
177
177
  } & {
178
178
  readonly [K in ReadonlyPropertyKeys<T>]: Static<T[K], P>;
@@ -183,15 +183,15 @@ export declare type PropertiesReduce<T extends TProperties, P extends unknown[]>
183
183
  } extends infer R ? {
184
184
  [K in keyof R]: R[K];
185
185
  } : never;
186
- export declare type TRecordProperties<K extends TUnion<TLiteral[]>, T extends TSchema> = Static<K> extends string ? {
186
+ export type TRecordProperties<K extends TUnion<TLiteral[]>, T extends TSchema> = Static<K> extends string ? {
187
187
  [X in Static<K>]: T;
188
188
  } : never;
189
189
  export interface TProperties {
190
190
  [key: string]: TSchema;
191
191
  }
192
- export declare type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
193
- export declare type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
194
- export declare type TAdditionalProperties = undefined | TSchema | boolean;
192
+ export type ObjectProperties<T> = T extends TObject<infer U> ? U : never;
193
+ export type ObjectPropertyKeys<T> = T extends TObject<infer U> ? keyof U : never;
194
+ export type TAdditionalProperties = undefined | TSchema | boolean;
195
195
  export interface ObjectOptions extends SchemaOptions {
196
196
  additionalProperties?: TAdditionalProperties;
197
197
  minProperties?: number;
@@ -215,7 +215,7 @@ export interface TPartial<T extends TObject> extends TObject {
215
215
  [K in keyof T['properties']]: T['properties'][K] extends TReadonlyOptional<infer U> ? TReadonlyOptional<U> : T['properties'][K] extends TReadonly<infer U> ? TReadonlyOptional<U> : T['properties'][K] extends TOptional<infer U> ? TOptional<U> : TOptional<T['properties'][K]>;
216
216
  };
217
217
  }
218
- export declare type TPick<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> = TObject<{
218
+ export type TPick<T extends TObject, Properties extends ObjectPropertyKeys<T>[]> = TObject<{
219
219
  [K in Properties[number]]: T['properties'][K];
220
220
  }>;
221
221
  export interface TPromise<T extends TSchema = TSchema> extends TSchema {
@@ -225,7 +225,7 @@ export interface TPromise<T extends TSchema = TSchema> extends TSchema {
225
225
  instanceOf: 'Promise';
226
226
  item: TSchema;
227
227
  }
228
- export declare type TRecordKey = TString | TNumeric | TUnion<TLiteral<any>[]>;
228
+ export type TRecordKey = TString | TNumeric | TUnion<TLiteral<any>[]>;
229
229
  export interface TRecord<K extends TRecordKey = TRecordKey, T extends TSchema = TSchema> extends TSchema {
230
230
  [Kind]: 'Record';
231
231
  static: Record<Static<K>, Static<T, this['params']>>;
@@ -240,7 +240,7 @@ export interface TSelf extends TSchema {
240
240
  static: this['params'][0];
241
241
  $ref: string;
242
242
  }
243
- export declare type TRecursiveReduce<T extends TSchema> = Static<T, [TRecursiveReduce<T>]>;
243
+ export type TRecursiveReduce<T extends TSchema> = Static<T, [TRecursiveReduce<T>]>;
244
244
  export interface TRecursive<T extends TSchema> extends TSchema {
245
245
  static: TRecursiveReduce<T>;
246
246
  }
@@ -255,7 +255,7 @@ export interface TRequired<T extends TObject | TRef<TObject>> extends TObject {
255
255
  [K in keyof T['properties']]: T['properties'][K] extends TReadonlyOptional<infer U> ? TReadonly<U> : T['properties'][K] extends TReadonly<infer U> ? TReadonly<U> : T['properties'][K] extends TOptional<infer U> ? U : T['properties'][K];
256
256
  };
257
257
  }
258
- export declare type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex';
258
+ export type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex';
259
259
  export interface StringOptions<Format extends string> extends SchemaOptions {
260
260
  minLength?: number;
261
261
  maxLength?: number;
@@ -269,7 +269,7 @@ export interface TString<Format extends string = string> extends TSchema, String
269
269
  static: string;
270
270
  type: 'string';
271
271
  }
272
- export declare type TupleToArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? R : never;
272
+ export type TupleToArray<T extends TTuple<TSchema[]>> = T extends TTuple<infer R> ? R : never;
273
273
  export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
274
274
  [Kind]: 'Tuple';
275
275
  static: {
@@ -322,7 +322,7 @@ export interface TVoid extends TSchema {
322
322
  typeOf: 'Void';
323
323
  }
324
324
  /** Creates a static type from a TypeBox type */
325
- export declare type Static<T extends TSchema, P extends unknown[] = []> = (T & {
325
+ export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
326
326
  params: P;
327
327
  })['static'];
328
328
  export declare class TypeBuilder {
package/value/cast.js CHANGED
@@ -307,7 +307,7 @@ var ValueCast;
307
307
  function Void(schema, references, value) {
308
308
  return check_1.ValueCheck.Check(schema, references, value) ? clone_1.ValueClone.Clone(value) : create_1.ValueCreate.Create(schema, references);
309
309
  }
310
- function Kind(schema, references, value) {
310
+ function UserDefined(schema, references, value) {
311
311
  return check_1.ValueCheck.Check(schema, references, value) ? clone_1.ValueClone.Clone(value) : create_1.ValueCreate.Create(schema, references);
312
312
  }
313
313
  function Visit(schema, references, value) {
@@ -365,7 +365,7 @@ var ValueCast;
365
365
  default:
366
366
  if (!index_1.Custom.Has(anySchema[Types.Kind]))
367
367
  throw new ValueCastUnknownTypeError(anySchema);
368
- return Kind(anySchema, anyReferences, value);
368
+ return UserDefined(anySchema, anyReferences, value);
369
369
  }
370
370
  }
371
371
  ValueCast.Visit = Visit;
package/value/check.js CHANGED
@@ -33,7 +33,7 @@ const index_1 = require("../format/index");
33
33
  const index_2 = require("../custom/index");
34
34
  class ValueCheckUnknownTypeError extends Error {
35
35
  constructor(schema) {
36
- super('ValueCheck: Unknown type');
36
+ super(`ValueCheck: ${schema[Types.Kind] ? `Unknown type '${schema[Types.Kind]}'` : 'Unknown type'}`);
37
37
  this.schema = schema;
38
38
  }
39
39
  }
@@ -291,11 +291,11 @@ var ValueCheck;
291
291
  function Void(schema, references, value) {
292
292
  return value === null;
293
293
  }
294
- function Kind(schema, references, value) {
294
+ function UserDefined(schema, references, value) {
295
295
  if (!index_2.Custom.Has(schema[Types.Kind]))
296
296
  return false;
297
297
  const func = index_2.Custom.Get(schema[Types.Kind]);
298
- return func(value);
298
+ return func(schema, value);
299
299
  }
300
300
  function Visit(schema, references, value) {
301
301
  const anyReferences = schema.$id === undefined ? references : [schema, ...references];
@@ -350,7 +350,7 @@ var ValueCheck;
350
350
  default:
351
351
  if (!index_2.Custom.Has(anySchema[Types.Kind]))
352
352
  throw new ValueCheckUnknownTypeError(anySchema);
353
- return Kind(anySchema, anyReferences, value);
353
+ return UserDefined(anySchema, anyReferences, value);
354
354
  }
355
355
  }
356
356
  // -------------------------------------------------------------------------
package/value/create.js CHANGED
@@ -293,12 +293,12 @@ var ValueCreate;
293
293
  function Void(schema, references) {
294
294
  return null;
295
295
  }
296
- function Kind(schema, references) {
296
+ function UserDefined(schema, references) {
297
297
  if (schema.default !== undefined) {
298
298
  return schema.default;
299
299
  }
300
300
  else {
301
- throw new Error('ValueCreate.Kind: Custom types must specify a default value');
301
+ throw new Error('ValueCreate.UserDefined: User defined types must specify a default value');
302
302
  }
303
303
  }
304
304
  /** Creates a value from the given schema. If the schema specifies a default value, then that value is returned. */
@@ -357,7 +357,7 @@ var ValueCreate;
357
357
  default:
358
358
  if (!index_1.Custom.Has(anySchema[Types.Kind]))
359
359
  throw new ValueCreateUnknownTypeError(anySchema);
360
- return Kind(anySchema, anyReferences);
360
+ return UserDefined(anySchema, anyReferences);
361
361
  }
362
362
  }
363
363
  ValueCreate.Visit = Visit;
package/value/delta.d.ts CHANGED
@@ -1,22 +1,22 @@
1
1
  import { Static } from '../typebox';
2
- export declare type Insert = Static<typeof Insert>;
2
+ export type Insert = Static<typeof Insert>;
3
3
  export declare const Insert: import("../typebox").TObject<{
4
4
  type: import("../typebox").TLiteral<"insert">;
5
5
  path: import("../typebox").TString<string>;
6
6
  value: import("../typebox").TUnknown;
7
7
  }>;
8
- export declare type Update = Static<typeof Update>;
8
+ export type Update = Static<typeof Update>;
9
9
  export declare const Update: import("../typebox").TObject<{
10
10
  type: import("../typebox").TLiteral<"update">;
11
11
  path: import("../typebox").TString<string>;
12
12
  value: import("../typebox").TUnknown;
13
13
  }>;
14
- export declare type Delete = Static<typeof Delete>;
14
+ export type Delete = Static<typeof Delete>;
15
15
  export declare const Delete: import("../typebox").TObject<{
16
16
  type: import("../typebox").TLiteral<"delete">;
17
17
  path: import("../typebox").TString<string>;
18
18
  }>;
19
- export declare type Edit = Static<typeof Edit>;
19
+ export type Edit = Static<typeof Edit>;
20
20
  export declare const Edit: import("../typebox").TUnion<[import("../typebox").TObject<{
21
21
  type: import("../typebox").TLiteral<"insert">;
22
22
  path: import("../typebox").TString<string>;
package/value/is.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export declare type ValueType = null | undefined | Function | symbol | bigint | number | boolean | string;
2
- export declare type ObjectType = Record<string | number | symbol, unknown>;
3
- export declare type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
4
- export declare type ArrayType = unknown[];
1
+ export type ValueType = null | undefined | Function | symbol | bigint | number | boolean | string;
2
+ export type ObjectType = Record<string | number | symbol, unknown>;
3
+ export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
4
+ export type ArrayType = unknown[];
5
5
  export declare namespace Is {
6
6
  function Object(value: unknown): value is ObjectType;
7
7
  function Date(value: unknown): value is Date;