@sinclair/typebox 0.30.2 → 0.30.3

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.
@@ -429,7 +429,9 @@ var TypeCompiler;
429
429
  yield IsVoidCheck(value);
430
430
  }
431
431
  function* TKind(schema, references, value) {
432
- yield `kind('${schema[Types.Kind]}', ${value})`;
432
+ const instance = state.instances.size;
433
+ state.instances.set(instance, schema);
434
+ yield `kind('${schema[Types.Kind]}', ${instance}, ${value})`;
433
435
  }
434
436
  function* Visit(schema, references, value, useHoisting = true) {
435
437
  const references_ = ValueGuard.IsString(schema.$id) ? [...references, schema] : references;
@@ -525,7 +527,8 @@ var TypeCompiler;
525
527
  const state = {
526
528
  language: 'javascript',
527
529
  functions: new Map(),
528
- variables: new Map(), // local variables
530
+ variables: new Map(),
531
+ instances: new Map() // exterior kind instances
529
532
  };
530
533
  // -------------------------------------------------------------------
531
534
  // Compiler Factory
@@ -583,6 +586,7 @@ var TypeCompiler;
583
586
  state.language = options.language;
584
587
  state.variables.clear();
585
588
  state.functions.clear();
589
+ state.instances.clear();
586
590
  if (!Types.TypeGuard.TSchema(schema))
587
591
  throw new TypeCompilerTypeGuardError(schema);
588
592
  for (const schema of references)
@@ -595,9 +599,10 @@ var TypeCompiler;
595
599
  function Compile(schema, references = []) {
596
600
  const generatedCode = Code(schema, references, { language: 'javascript' });
597
601
  const compiledFunction = globalThis.Function('kind', 'format', 'hash', generatedCode);
598
- function typeRegistryFunction(kind, value) {
599
- if (!Types.TypeRegistry.Has(kind))
602
+ function typeRegistryFunction(kind, instance, value) {
603
+ if (!Types.TypeRegistry.Has(kind) || !state.instances.has(instance))
600
604
  return false;
605
+ const schema = state.instances.get(instance);
601
606
  const checkFunc = Types.TypeRegistry.Get(kind);
602
607
  return checkFunc(schema, value);
603
608
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.30.2",
3
+ "version": "0.30.3",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -72,7 +72,6 @@ License MIT
72
72
  ## Contents
73
73
  - [Install](#install)
74
74
  - [Overview](#overview)
75
- - [Features](#features)
76
75
  - [Usage](#usage)
77
76
  - [Types](#types)
78
77
  - [Standard](#types-standard)
@@ -84,9 +83,9 @@ License MIT
84
83
  - [Recursive](#types-recursive)
85
84
  - [Conditional](#types-conditional)
86
85
  - [Template Literal](#types-template-literal)
87
- - [Intrinsic String](#types-intrinsic-string)
88
86
  - [Indexed](#types-indexed)
89
87
  - [Negated](#types-negated)
88
+ - [Intrinsic](#types-intrinsic)
90
89
  - [Rest](#types-rest)
91
90
  - [Guards](#types-guards)
92
91
  - [Unsafe](#types-unsafe)
@@ -876,34 +875,6 @@ const R = Type.Record(T, Type.String()) // const R = {
876
875
  // }
877
876
  ```
878
877
 
879
- <a name='types-intrinsic-string'></a>
880
-
881
- ### Intrinsic String Types
882
-
883
- TypeBox supports a set of intrinsic string mapping functions which can be used on string literals. These functions match the TypeScript string intrinsic types `Uppercase`, `Lowercase`, `Capitalize` and `Uncapitalize`. These functions are supported for literal strings, template literals and union types. The following shows the literal string usage.
884
-
885
- ```typescript
886
- // TypeScript
887
-
888
- type A = Uncapitalize<'HELLO'> // type A = 'hELLO'
889
-
890
- type B = Capitalize<'hello'> // type B = 'Hello'
891
-
892
- type C = Uppercase<'hello'> // type C = 'HELLO'
893
-
894
- type D = Lowercase<'HELLO'> // type D = 'hello'
895
-
896
- // TypeBox
897
-
898
- const A = Type.Uncapitalize(Type.Literal('HELLO')) // const A: TLiteral<'hELLO'>
899
-
900
- const B = Type.Capitalize(Type.Literal('hello')) // const B: TLiteral<'Hello'>
901
-
902
- const C = Type.Uppercase(Type.Literal('hello')) // const C: TLiteral<'HELLO'>
903
-
904
- const D = Type.Lowercase(Type.Literal('HELLO')) // const D: TLiteral<'hello'>
905
- ```
906
-
907
878
  <a name='types-indexed'></a>
908
879
 
909
880
  ### Indexed Access Types
@@ -986,6 +957,41 @@ const Even = Type.Number({ multipleOf: 2 })
986
957
 
987
958
  const Odd = Type.Intersect([Type.Number(), Type.Not(Even)])
988
959
  ```
960
+
961
+ <a name='types-intrinsic'></a>
962
+
963
+ ### Intrinsic String Types
964
+
965
+ TypeBox supports TypeScript intrinsic string manipulation types `Uppercase`, `Lowercase`, `Capitalize` and `Uncapitalize`. These can be applied to string literals, template literals and unions. The following shows general usage.
966
+
967
+ ```typescript
968
+ // TypeScript
969
+
970
+ type A = Capitalize<'hello'> // type A = 'Hello'
971
+
972
+ type B = Capitalize<'hello' | 'world'> // type C = 'Hello' | 'World'
973
+
974
+ type C = Capitalize<`hello${1|2|3}`> // type B = 'Hello1' | 'Hello2' | 'Hello3'
975
+
976
+ // TypeBox
977
+
978
+ const A = Type.Capitalize(Type.Literal('hello')) // const A: TLiteral<'Hello'>
979
+
980
+ const B = Type.Capitalize(Type.Union([ // const B: TUnion<[
981
+ Type.Literal('hello'), // TLiteral<'Hello'>,
982
+ Type.Literal('world') // TLiteral<'World'>
983
+ ])) // ]>
984
+
985
+ const C = Type.Capitalize( // const C: TTemplateLiteral<[
986
+ Type.TemplateLiteral('hello${1|2|3}') // TLiteral<'Hello'>,
987
+ ) // TUnion<[
988
+ // TLiteral<'1'>,
989
+ // TLiteral<'2'>,
990
+ // TLiteral<'3'>
991
+ // ]>
992
+ // ]>
993
+ ```
994
+
989
995
  <a name='types-rest'></a>
990
996
 
991
997
  ### Rest Types