@sinclair/typebox 0.34.15 → 0.34.17

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.
Files changed (141) hide show
  1. package/build/cjs/compiler/compiler.js +5 -0
  2. package/build/cjs/errors/errors.js +3 -0
  3. package/build/cjs/index.d.ts +3 -0
  4. package/build/cjs/index.js +3 -0
  5. package/build/cjs/syntax/index.d.ts +1 -1
  6. package/build/cjs/syntax/index.js +1 -1
  7. package/build/cjs/syntax/runtime.d.ts +40 -54
  8. package/build/cjs/syntax/runtime.js +91 -203
  9. package/build/cjs/syntax/static.d.ts +80 -146
  10. package/build/cjs/syntax/syntax.d.ts +33 -0
  11. package/build/cjs/syntax/syntax.js +37 -0
  12. package/build/cjs/type/argument/argument.d.ts +9 -0
  13. package/build/cjs/type/argument/argument.js +10 -0
  14. package/build/cjs/type/argument/index.d.ts +1 -0
  15. package/build/cjs/type/argument/index.js +18 -0
  16. package/build/cjs/type/constructor-parameters/constructor-parameters.d.ts +3 -3
  17. package/build/cjs/type/constructor-parameters/constructor-parameters.js +3 -1
  18. package/build/cjs/type/guard/kind.d.ts +9 -6
  19. package/build/cjs/type/guard/kind.js +6 -0
  20. package/build/cjs/type/guard/type.d.ts +9 -6
  21. package/build/cjs/type/guard/type.js +9 -0
  22. package/build/cjs/type/index.d.ts +2 -0
  23. package/build/cjs/type/index.js +2 -0
  24. package/build/cjs/type/instance-type/instance-type.d.ts +5 -4
  25. package/build/cjs/type/instance-type/instance-type.js +3 -1
  26. package/build/cjs/type/instantiate/index.d.ts +1 -0
  27. package/build/cjs/type/instantiate/index.js +18 -0
  28. package/build/cjs/type/instantiate/instantiate.d.ts +25 -0
  29. package/build/cjs/type/instantiate/instantiate.js +32 -0
  30. package/build/cjs/type/parameters/parameters.d.ts +3 -3
  31. package/build/cjs/type/parameters/parameters.js +3 -1
  32. package/build/cjs/type/record/record.d.ts +16 -1
  33. package/build/cjs/type/record/record.js +53 -23
  34. package/build/cjs/type/remap/index.d.ts +1 -0
  35. package/build/cjs/type/remap/index.js +18 -0
  36. package/build/cjs/type/remap/remap.d.ts +19 -0
  37. package/build/cjs/type/remap/remap.js +35 -0
  38. package/build/cjs/type/return-type/return-type.d.ts +5 -4
  39. package/build/cjs/type/return-type/return-type.js +3 -1
  40. package/build/cjs/type/type/javascript.d.ts +10 -4
  41. package/build/cjs/type/type/javascript.js +44 -34
  42. package/build/cjs/type/type/type.d.ts +3 -0
  43. package/build/cjs/type/type/type.js +123 -117
  44. package/build/cjs/value/check/check.js +5 -0
  45. package/build/cjs/value/create/create.js +5 -0
  46. package/build/esm/compiler/compiler.mjs +5 -0
  47. package/build/esm/errors/errors.mjs +3 -0
  48. package/build/esm/index.d.mts +3 -0
  49. package/build/esm/index.mjs +3 -0
  50. package/build/esm/syntax/index.d.mts +1 -1
  51. package/build/esm/syntax/index.mjs +1 -1
  52. package/build/esm/syntax/runtime.d.mts +40 -54
  53. package/build/esm/syntax/runtime.mjs +91 -203
  54. package/build/esm/syntax/static.d.mts +80 -146
  55. package/build/esm/syntax/syntax.d.mts +33 -0
  56. package/build/esm/syntax/syntax.mjs +30 -0
  57. package/build/esm/type/argument/argument.d.mts +9 -0
  58. package/build/esm/type/argument/argument.mjs +6 -0
  59. package/build/esm/type/argument/index.d.mts +1 -0
  60. package/build/esm/type/argument/index.mjs +1 -0
  61. package/build/esm/type/constructor-parameters/constructor-parameters.d.mts +3 -3
  62. package/build/esm/type/constructor-parameters/constructor-parameters.mjs +3 -1
  63. package/build/esm/type/guard/kind.d.mts +9 -6
  64. package/build/esm/type/guard/kind.mjs +5 -0
  65. package/build/esm/type/guard/type.d.mts +9 -6
  66. package/build/esm/type/guard/type.mjs +8 -0
  67. package/build/esm/type/index.d.mts +2 -0
  68. package/build/esm/type/index.mjs +2 -0
  69. package/build/esm/type/instance-type/instance-type.d.mts +5 -4
  70. package/build/esm/type/instance-type/instance-type.mjs +3 -1
  71. package/build/esm/type/instantiate/index.d.mts +1 -0
  72. package/build/esm/type/instantiate/index.mjs +1 -0
  73. package/build/esm/type/instantiate/instantiate.d.mts +25 -0
  74. package/build/esm/type/instantiate/instantiate.mjs +28 -0
  75. package/build/esm/type/parameters/parameters.d.mts +3 -3
  76. package/build/esm/type/parameters/parameters.mjs +3 -1
  77. package/build/esm/type/record/record.d.mts +16 -1
  78. package/build/esm/type/record/record.mjs +35 -8
  79. package/build/esm/type/remap/index.d.mts +1 -0
  80. package/build/esm/type/remap/index.mjs +1 -0
  81. package/build/esm/type/remap/remap.d.mts +19 -0
  82. package/build/esm/type/remap/remap.mjs +31 -0
  83. package/build/esm/type/return-type/return-type.d.mts +5 -4
  84. package/build/esm/type/return-type/return-type.mjs +3 -1
  85. package/build/esm/type/type/javascript.d.mts +10 -4
  86. package/build/esm/type/type/javascript.mjs +10 -0
  87. package/build/esm/type/type/type.d.mts +3 -0
  88. package/build/esm/type/type/type.mjs +3 -0
  89. package/build/esm/value/check/check.mjs +5 -0
  90. package/build/esm/value/create/create.mjs +5 -0
  91. package/package.json +11 -1
  92. package/parser/package.json +4 -0
  93. package/readme.md +107 -184
  94. package/build/cjs/syntax/parse.d.ts +0 -15
  95. package/build/cjs/syntax/parse.js +0 -19
  96. package/build/esm/syntax/parse.d.mts +0 -15
  97. package/build/esm/syntax/parse.mjs +0 -14
  98. /package/build/cjs/{syntax/parsebox → parser}/index.d.ts +0 -0
  99. /package/build/cjs/{syntax/parsebox → parser}/index.js +0 -0
  100. /package/build/cjs/{syntax/parsebox → parser}/runtime/guard.d.ts +0 -0
  101. /package/build/cjs/{syntax/parsebox → parser}/runtime/guard.js +0 -0
  102. /package/build/cjs/{syntax/parsebox → parser}/runtime/index.d.ts +0 -0
  103. /package/build/cjs/{syntax/parsebox → parser}/runtime/index.js +0 -0
  104. /package/build/cjs/{syntax/parsebox → parser}/runtime/module.d.ts +0 -0
  105. /package/build/cjs/{syntax/parsebox → parser}/runtime/module.js +0 -0
  106. /package/build/cjs/{syntax/parsebox → parser}/runtime/parse.d.ts +0 -0
  107. /package/build/cjs/{syntax/parsebox → parser}/runtime/parse.js +0 -0
  108. /package/build/cjs/{syntax/parsebox → parser}/runtime/token.d.ts +0 -0
  109. /package/build/cjs/{syntax/parsebox → parser}/runtime/token.js +0 -0
  110. /package/build/cjs/{syntax/parsebox → parser}/runtime/types.d.ts +0 -0
  111. /package/build/cjs/{syntax/parsebox → parser}/runtime/types.js +0 -0
  112. /package/build/cjs/{syntax/parsebox → parser}/static/index.d.ts +0 -0
  113. /package/build/cjs/{syntax/parsebox → parser}/static/index.js +0 -0
  114. /package/build/cjs/{syntax/parsebox → parser}/static/parse.d.ts +0 -0
  115. /package/build/cjs/{syntax/parsebox → parser}/static/parse.js +0 -0
  116. /package/build/cjs/{syntax/parsebox → parser}/static/token.d.ts +0 -0
  117. /package/build/cjs/{syntax/parsebox → parser}/static/token.js +0 -0
  118. /package/build/cjs/{syntax/parsebox → parser}/static/types.d.ts +0 -0
  119. /package/build/cjs/{syntax/parsebox → parser}/static/types.js +0 -0
  120. /package/build/esm/{syntax/parsebox → parser}/index.d.mts +0 -0
  121. /package/build/esm/{syntax/parsebox → parser}/index.mjs +0 -0
  122. /package/build/esm/{syntax/parsebox → parser}/runtime/guard.d.mts +0 -0
  123. /package/build/esm/{syntax/parsebox → parser}/runtime/guard.mjs +0 -0
  124. /package/build/esm/{syntax/parsebox → parser}/runtime/index.d.mts +0 -0
  125. /package/build/esm/{syntax/parsebox → parser}/runtime/index.mjs +0 -0
  126. /package/build/esm/{syntax/parsebox → parser}/runtime/module.d.mts +0 -0
  127. /package/build/esm/{syntax/parsebox → parser}/runtime/module.mjs +0 -0
  128. /package/build/esm/{syntax/parsebox → parser}/runtime/parse.d.mts +0 -0
  129. /package/build/esm/{syntax/parsebox → parser}/runtime/parse.mjs +0 -0
  130. /package/build/esm/{syntax/parsebox → parser}/runtime/token.d.mts +0 -0
  131. /package/build/esm/{syntax/parsebox → parser}/runtime/token.mjs +0 -0
  132. /package/build/esm/{syntax/parsebox → parser}/runtime/types.d.mts +0 -0
  133. /package/build/esm/{syntax/parsebox → parser}/runtime/types.mjs +0 -0
  134. /package/build/esm/{syntax/parsebox → parser}/static/index.d.mts +0 -0
  135. /package/build/esm/{syntax/parsebox → parser}/static/index.mjs +0 -0
  136. /package/build/esm/{syntax/parsebox → parser}/static/parse.d.mts +0 -0
  137. /package/build/esm/{syntax/parsebox → parser}/static/parse.mjs +0 -0
  138. /package/build/esm/{syntax/parsebox → parser}/static/token.d.mts +0 -0
  139. /package/build/esm/{syntax/parsebox → parser}/static/token.mjs +0 -0
  140. /package/build/esm/{syntax/parsebox → parser}/static/types.d.mts +0 -0
  141. /package/build/esm/{syntax/parsebox → parser}/static/types.mjs +0 -0
@@ -1,71 +1,57 @@
1
- import { Runtime } from './parsebox/index.mjs';
2
- import * as Types from '../type/index.mjs';
1
+ import { Runtime } from '../parser/index.mjs';
2
+ import * as t from '../type/index.mjs';
3
3
  export declare const Module: Runtime.Module<{
4
- ExportModifier: Runtime.IUnion<boolean>;
5
- HeritageList: Runtime.IUnion<Types.TSchema[]>;
6
- Heritage: Runtime.IUnion<unknown[]>;
7
- InterfaceDeclaration: Runtime.ITuple<{
8
- [x: string]: Types.TIntersect<[...Types.TRef<string>[], Types.TObject<Types.TProperties>]>;
9
- }>;
10
- TypeAliasDeclaration: Runtime.ITuple<{
11
- [x: string]: Types.TSchema;
12
- }>;
13
- ModuleType: Runtime.IUnion<unknown>;
14
- ModuleProperties: Runtime.IUnion<Types.TProperties>;
15
- ModuleDeclaration: Runtime.ITuple<Types.TModule<Types.TProperties, {
16
- [x: string]: Types.TSchema;
17
- [x: number]: Types.TSchema;
18
- }>>;
19
- Literal: Runtime.IUnion<Types.TLiteral<string> | Types.TLiteral<number> | Types.TLiteral<boolean>>;
20
- Keyword: Runtime.IUnion<Types.TAny | Types.TNever | Types.TString | Types.TBoolean | Types.TNumber | Types.TInteger | Types.TBigInt | Types.TNull | Types.TSymbol | Types.TUndefined | Types.TUnknown | Types.TVoid>;
4
+ Literal: Runtime.IUnion<t.TLiteral<string> | t.TLiteral<number> | t.TLiteral<boolean>>;
5
+ Keyword: Runtime.IUnion<t.TAny | t.TBoolean | t.TBigInt | t.TNever | t.TString | t.TNumber | t.TInteger | t.TNull | t.TSymbol | t.TUndefined | t.TUnknown | t.TVoid>;
21
6
  KeyOf: Runtime.IUnion<boolean>;
22
7
  IndexArray: Runtime.IUnion<unknown[]>;
23
8
  Extends: Runtime.IUnion<unknown[]>;
24
9
  Base: Runtime.IUnion<unknown>;
25
- Factor: Runtime.ITuple<Types.TSchema>;
10
+ Factor: Runtime.ITuple<t.TSchema>;
26
11
  ExprTermTail: Runtime.IUnion<[] | ["&", unknown, unknown]>;
27
- ExprTerm: Runtime.ITuple<Types.TSchema>;
12
+ ExprTerm: Runtime.ITuple<t.TSchema>;
28
13
  ExprTail: Runtime.IUnion<[] | ["|", unknown, unknown]>;
29
- Expr: Runtime.ITuple<Types.TSchema>;
14
+ Expr: Runtime.ITuple<t.TSchema>;
30
15
  Type: Runtime.IRef<unknown>;
31
16
  PropertyKey: Runtime.IUnion<string>;
32
17
  Readonly: Runtime.IUnion<boolean>;
33
18
  Optional: Runtime.IUnion<boolean>;
34
19
  Property: Runtime.ITuple<{
35
- [x: string]: Types.TSchema;
20
+ [x: string]: t.TSchema;
36
21
  }>;
37
22
  PropertyDelimiter: Runtime.IUnion<[","] | [",", "\n"] | [";"] | [";", "\n"] | ["\n"]>;
38
- Properties: Runtime.IUnion<Types.TProperties>;
39
- Object: Runtime.ITuple<Types.TObject<Types.TProperties>>;
23
+ Properties: Runtime.IUnion<t.TProperties>;
24
+ Object: Runtime.ITuple<t.TObject<t.TProperties>>;
40
25
  Elements: Runtime.IUnion<unknown[]>;
41
- Tuple: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
42
- Parameter: Runtime.ITuple<Types.TSchema>;
43
- Function: Runtime.ITuple<Types.TFunction<Types.TSchema[], Types.TSchema>>;
26
+ Tuple: Runtime.ITuple<t.TTuple<t.TSchema[]>>;
27
+ Parameter: Runtime.ITuple<t.TSchema>;
28
+ Function: Runtime.ITuple<t.TFunction<t.TSchema[], t.TSchema>>;
44
29
  Parameters: Runtime.IUnion<unknown[]>;
45
- Constructor: Runtime.ITuple<Types.TConstructor<Types.TSchema[], Types.TSchema>>;
46
- Mapped: Runtime.ITuple<Types.TLiteral<"Mapped types not supported">>;
47
- AsyncIterator: Runtime.ITuple<Types.TAsyncIterator<Types.TSchema>>;
48
- Iterator: Runtime.ITuple<Types.TIterator<Types.TSchema>>;
49
- Awaited: Runtime.ITuple<Types.TSchema>;
50
- Array: Runtime.ITuple<Types.TArray<Types.TSchema>>;
51
- Record: Runtime.ITuple<Types.TNever>;
52
- Promise: Runtime.ITuple<Types.TPromise<Types.TSchema>>;
53
- ConstructorParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
54
- FunctionParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
55
- InstanceType: Runtime.ITuple<Types.TSchema>;
56
- ReturnType: Runtime.ITuple<Types.TSchema>;
57
- Partial: Runtime.ITuple<Types.TObject<{}>>;
58
- Required: Runtime.ITuple<Types.TObject<{}>>;
59
- Pick: Runtime.ITuple<Types.TObject<{}>>;
60
- Omit: Runtime.ITuple<Types.TObject<{}>>;
61
- Exclude: Runtime.ITuple<Types.TNever>;
62
- Extract: Runtime.ITuple<Types.TSchema>;
63
- Uppercase: Runtime.ITuple<Types.TSchema>;
64
- Lowercase: Runtime.ITuple<Types.TSchema>;
65
- Capitalize: Runtime.ITuple<Types.TSchema>;
66
- Uncapitalize: Runtime.ITuple<Types.TSchema>;
67
- Date: Runtime.IConst<Types.TDate>;
68
- Uint8Array: Runtime.IConst<Types.TUint8Array>;
69
- Reference: Runtime.IIdent<Types.TSchema>;
70
- Main: Runtime.IUnion<unknown>;
30
+ Constructor: Runtime.ITuple<t.TConstructor<t.TSchema[], t.TSchema>>;
31
+ Mapped: Runtime.ITuple<t.TLiteral<"Mapped types not supported">>;
32
+ AsyncIterator: Runtime.ITuple<t.TAsyncIterator<t.TSchema>>;
33
+ Iterator: Runtime.ITuple<t.TIterator<t.TSchema>>;
34
+ Argument: Runtime.ITuple<t.TNever | t.TArgument<number>>;
35
+ Awaited: Runtime.ITuple<t.TSchema>;
36
+ Array: Runtime.ITuple<t.TArray<t.TSchema>>;
37
+ Record: Runtime.ITuple<t.TNever>;
38
+ Promise: Runtime.ITuple<t.TPromise<t.TSchema>>;
39
+ ConstructorParameters: Runtime.ITuple<t.TTuple<t.TSchema[]>>;
40
+ FunctionParameters: Runtime.ITuple<t.TTuple<t.TSchema[]>>;
41
+ InstanceType: Runtime.ITuple<t.TSchema>;
42
+ ReturnType: Runtime.ITuple<t.TSchema>;
43
+ Partial: Runtime.ITuple<t.TObject<{}>>;
44
+ Required: Runtime.ITuple<t.TObject<{}>>;
45
+ Pick: Runtime.ITuple<t.TObject<{}>>;
46
+ Omit: Runtime.ITuple<t.TObject<{}>>;
47
+ Exclude: Runtime.ITuple<t.TNever>;
48
+ Extract: Runtime.ITuple<t.TSchema>;
49
+ Uppercase: Runtime.ITuple<t.TSchema>;
50
+ Lowercase: Runtime.ITuple<t.TSchema>;
51
+ Capitalize: Runtime.ITuple<t.TSchema>;
52
+ Uncapitalize: Runtime.ITuple<t.TSchema>;
53
+ Date: Runtime.IConst<t.TDate>;
54
+ Uint8Array: Runtime.IConst<t.TUint8Array>;
55
+ GenericReference: Runtime.ITuple<t.TSchema>;
56
+ Reference: Runtime.IIdent<t.TSchema>;
71
57
  }>;
@@ -1,5 +1,5 @@
1
- import { Runtime } from './parsebox/index.mjs';
2
- import * as Types from '../type/index.mjs';
1
+ import { Runtime } from '../parser/index.mjs';
2
+ import * as t from '../type/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // Tokens
5
5
  // ------------------------------------------------------------------
@@ -30,159 +30,54 @@ function DestructureRight(values) {
30
30
  : [values, undefined];
31
31
  }
32
32
  // ------------------------------------------------------------------
33
- // Deref
33
+ // Dereference
34
34
  // ------------------------------------------------------------------
35
- const Deref = (context, key) => {
36
- return key in context ? context[key] : Types.Ref(key);
35
+ const Dereference = (context, key) => {
36
+ return key in context ? context[key] : t.Ref(key);
37
37
  };
38
38
  // ------------------------------------------------------------------
39
- // ExportModifier
39
+ // GenericReference
40
40
  // ------------------------------------------------------------------
41
- // prettier-ignore
42
- const ExportModifierMapping = (values) => {
43
- return values.length === 1;
44
- };
45
- // prettier-ignore
46
- const ExportModifier = Runtime.Union([
47
- Runtime.Tuple([Runtime.Const('export')]), Runtime.Tuple([])
48
- ], ExportModifierMapping);
49
- // ------------------------------------------------------------------
50
- // TypeAliasDeclaration
51
- // ------------------------------------------------------------------
52
- // prettier-ignore
53
- const TypeAliasDeclarationMapping = (_Export, _Keyword, Ident, _Equals, Type) => {
54
- return { [Ident]: Type };
55
- };
56
- // prettier-ignore
57
- const TypeAliasDeclaration = Runtime.Tuple([
58
- Runtime.Ref('ExportModifier'),
59
- Runtime.Const('type'),
60
- Runtime.Ident(),
61
- Runtime.Const(Equals),
62
- Runtime.Ref('Type')
63
- ], value => TypeAliasDeclarationMapping(...value));
64
- // ------------------------------------------------------------------
65
- // HeritageList
66
- // ------------------------------------------------------------------
67
- // prettier-ignore (note, heritage list should disallow trailing comma)
68
- const HeritageListDelimiter = Runtime.Union([Runtime.Tuple([Runtime.Const(Comma), Runtime.Const(Newline)]), Runtime.Tuple([Runtime.Const(Comma)])]);
69
- // prettier-ignore
70
- const HeritageListMapping = (values, context) => {
71
- return (values.length === 3 ? [Deref(context, values[0]), ...values[2]] :
72
- values.length === 1 ? [Deref(context, values[0])] :
73
- []);
74
- };
75
- // prettier-ignore
76
- const HeritageList = Runtime.Union([
77
- Runtime.Tuple([Runtime.Ident(), HeritageListDelimiter, Runtime.Ref('HeritageList')]),
78
- Runtime.Tuple([Runtime.Ident()]),
79
- Runtime.Tuple([])
80
- ], HeritageListMapping);
81
- // ------------------------------------------------------------------
82
- // Heritage
83
- // ------------------------------------------------------------------
84
- // prettier-ignore
85
- const HeritageMapping = (values) => {
86
- return (values.length === 2 ? values[1] : []);
87
- };
88
- // prettier-ignore
89
- const Heritage = Runtime.Union([
90
- Runtime.Tuple([Runtime.Const('extends'), Runtime.Ref('HeritageList')]),
91
- Runtime.Tuple([])
92
- ], HeritageMapping);
93
- // ------------------------------------------------------------------
94
- // InterfaceDeclaration
95
- // ------------------------------------------------------------------
96
- // prettier-ignore
97
- const InterfaceDeclarationMapping = (_0, _1, Ident, Heritage, _4, Properties, _6) => {
98
- return { [Ident]: Types.Intersect([...Heritage, Types.Object(Properties)]) };
99
- };
100
- // prettier-ignore
101
- const InterfaceDeclaration = Runtime.Tuple([
102
- Runtime.Ref('ExportModifier'),
103
- Runtime.Const('interface'),
104
- Runtime.Ident(),
105
- Runtime.Ref('Heritage'),
106
- Runtime.Const(LBrace),
107
- Runtime.Ref('Properties'),
108
- Runtime.Const(RBrace),
109
- ], values => InterfaceDeclarationMapping(...values));
110
- // ------------------------------------------------------------------
111
- // ModuleType
112
- // ------------------------------------------------------------------
113
- // prettier-ignore
114
- const ModuleType = Runtime.Union([
115
- Runtime.Ref('InterfaceDeclaration'),
116
- Runtime.Ref('TypeAliasDeclaration')
117
- ]);
118
- // ------------------------------------------------------------------
119
- // ModuleProperties
120
- // ------------------------------------------------------------------
121
- // prettier-ignore
122
- const ModulePropertiesDelimiter = Runtime.Union([
123
- Runtime.Tuple([Runtime.Const(SemiColon), Runtime.Const(Newline)]),
124
- Runtime.Tuple([Runtime.Const(SemiColon)]),
125
- Runtime.Tuple([Runtime.Const(Newline)]),
126
- ]);
127
- // prettier-ignore
128
- const ModulePropertiesMapping = (values) => {
129
- return (values.length === 3 ? { ...values[0], ...values[2] } :
130
- values.length === 1 ? values[0] :
131
- {});
132
- };
133
- // prettier-ignore
134
- const ModuleProperties = Runtime.Union([
135
- Runtime.Tuple([Runtime.Ref('ModuleType'), ModulePropertiesDelimiter, Runtime.Ref('ModuleProperties')]),
136
- Runtime.Tuple([Runtime.Ref('ModuleType')]),
137
- Runtime.Tuple([]),
138
- ], ModulePropertiesMapping);
139
- // ------------------------------------------------------------------
140
- // ModuleDeclaration
141
- // ------------------------------------------------------------------
142
- // prettier-ignore
143
- const ModuleIdentifier = Runtime.Union([
144
- Runtime.Tuple([Runtime.Ident()]),
145
- Runtime.Tuple([])
146
- ]);
147
- // prettier-ignore
148
- const ModuleDeclarationMapping = (_1, _2, _Ident, _3, Properties, _5) => {
149
- return Types.Module(Properties);
150
- };
151
- // prettier-ignore
152
- const ModuleDeclaration = Runtime.Tuple([
153
- Runtime.Ref('ExportModifier'), Runtime.Const('module'), ModuleIdentifier, Runtime.Const(LBrace), Runtime.Ref('ModuleProperties'), Runtime.Const(RBrace)
154
- ], values => ModuleDeclarationMapping(...values));
41
+ function GenericReferenceMapping(results, context) {
42
+ const target = Dereference(context, results[0]);
43
+ return t.Instantiate(target, results[2]);
44
+ }
45
+ const GenericReference = Runtime.Tuple([Runtime.Ident(), Runtime.Const(LAngle), Runtime.Ref('Elements'), Runtime.Const(RAngle)], (results, context) => GenericReferenceMapping(results, context));
155
46
  // ------------------------------------------------------------------
156
47
  // Reference
157
48
  // ------------------------------------------------------------------
49
+ function ReferenceMapping(result, context) {
50
+ const target = Dereference(context, result);
51
+ return target;
52
+ }
158
53
  // prettier-ignore
159
- const Reference = Runtime.Ident((value, context) => Deref(context, value));
54
+ const Reference = Runtime.Ident((result, context) => ReferenceMapping(result, context));
160
55
  // ------------------------------------------------------------------
161
56
  // Literal
162
57
  // ------------------------------------------------------------------
163
58
  // prettier-ignore
164
59
  const Literal = Runtime.Union([
165
- Runtime.Union([Runtime.Const('true'), Runtime.Const('false')], value => Types.Literal(value === 'true')),
166
- Runtime.Number(value => Types.Literal(parseFloat(value))),
167
- Runtime.String([SingleQuote, DoubleQuote, Tilde], value => Types.Literal(value))
60
+ Runtime.Union([Runtime.Const('true'), Runtime.Const('false')], value => t.Literal(value === 'true')),
61
+ Runtime.Number(value => t.Literal(parseFloat(value))),
62
+ Runtime.String([SingleQuote, DoubleQuote, Tilde], value => t.Literal(value))
168
63
  ]);
169
64
  // ------------------------------------------------------------------
170
65
  // Keyword
171
66
  // ------------------------------------------------------------------
172
67
  // prettier-ignore
173
68
  const Keyword = Runtime.Union([
174
- Runtime.Const('any', Runtime.As(Types.Any())),
175
- Runtime.Const('bigint', Runtime.As(Types.BigInt())),
176
- Runtime.Const('boolean', Runtime.As(Types.Boolean())),
177
- Runtime.Const('integer', Runtime.As(Types.Integer())),
178
- Runtime.Const('never', Runtime.As(Types.Never())),
179
- Runtime.Const('null', Runtime.As(Types.Null())),
180
- Runtime.Const('number', Runtime.As(Types.Number())),
181
- Runtime.Const('string', Runtime.As(Types.String())),
182
- Runtime.Const('symbol', Runtime.As(Types.Symbol())),
183
- Runtime.Const('undefined', Runtime.As(Types.Undefined())),
184
- Runtime.Const('unknown', Runtime.As(Types.Unknown())),
185
- Runtime.Const('void', Runtime.As(Types.Void())),
69
+ Runtime.Const('any', Runtime.As(t.Any())),
70
+ Runtime.Const('bigint', Runtime.As(t.BigInt())),
71
+ Runtime.Const('boolean', Runtime.As(t.Boolean())),
72
+ Runtime.Const('integer', Runtime.As(t.Integer())),
73
+ Runtime.Const('never', Runtime.As(t.Never())),
74
+ Runtime.Const('null', Runtime.As(t.Null())),
75
+ Runtime.Const('number', Runtime.As(t.Number())),
76
+ Runtime.Const('string', Runtime.As(t.String())),
77
+ Runtime.Const('symbol', Runtime.As(t.Symbol())),
78
+ Runtime.Const('undefined', Runtime.As(t.Undefined())),
79
+ Runtime.Const('unknown', Runtime.As(t.Unknown())),
80
+ Runtime.Const('void', Runtime.As(t.Void())),
186
81
  ]);
187
82
  // ------------------------------------------------------------------
188
83
  // KeyOf
@@ -248,6 +143,7 @@ const Base = Runtime.Union([
248
143
  Runtime.Ref('FunctionParameters'),
249
144
  Runtime.Ref('InstanceType'),
250
145
  Runtime.Ref('ReturnType'),
146
+ Runtime.Ref('Argument'),
251
147
  Runtime.Ref('Awaited'),
252
148
  Runtime.Ref('Array'),
253
149
  Runtime.Ref('Record'),
@@ -264,6 +160,7 @@ const Base = Runtime.Union([
264
160
  Runtime.Ref('Uncapitalize'),
265
161
  Runtime.Ref('Date'),
266
162
  Runtime.Ref('Uint8Array'),
163
+ Runtime.Ref('GenericReference'),
267
164
  Runtime.Ref('Reference')
268
165
  ])])
269
166
  ], BaseMapping);
@@ -273,22 +170,22 @@ const Base = Runtime.Union([
273
170
  // prettier-ignore
274
171
  const FactorExtends = (Type, Extends) => {
275
172
  return Extends.length === 3
276
- ? Types.Extends(Type, Extends[0], Extends[1], Extends[2])
173
+ ? t.Extends(Type, Extends[0], Extends[1], Extends[2])
277
174
  : Type;
278
175
  };
279
176
  // prettier-ignore
280
177
  const FactorIndexArray = (Type, IndexArray) => {
281
178
  const [Left, Right] = DestructureRight(IndexArray);
282
- return (!Types.ValueGuard.IsUndefined(Right) ? (
179
+ return (!t.ValueGuard.IsUndefined(Right) ? (
283
180
  // note: Indexed types require reimplementation to replace `[number]` indexers
284
- Right.length === 1 ? Types.Index(FactorIndexArray(Type, Left), Right[0]) :
285
- Right.length === 0 ? Types.Array(FactorIndexArray(Type, Left)) :
286
- Types.Never()) : Type);
181
+ Right.length === 1 ? t.Index(FactorIndexArray(Type, Left), Right[0]) :
182
+ Right.length === 0 ? t.Array(FactorIndexArray(Type, Left)) :
183
+ t.Never()) : Type);
287
184
  };
288
185
  // prettier-ignore
289
186
  const FactorMapping = (KeyOf, Type, IndexArray, Extends) => {
290
187
  return KeyOf
291
- ? FactorExtends(Types.KeyOf(FactorIndexArray(Type, IndexArray)), Extends)
188
+ ? FactorExtends(t.KeyOf(FactorIndexArray(Type, IndexArray)), Extends)
292
189
  : FactorExtends(FactorIndexArray(Type, IndexArray), Extends);
293
190
  };
294
191
  // prettier-ignore
@@ -307,14 +204,14 @@ function ExprBinaryMapping(Left, Rest) {
307
204
  const [Operator, Right, Next] = Rest;
308
205
  const Schema = ExprBinaryMapping(Right, Next);
309
206
  if (Operator === '&') {
310
- return Types.TypeGuard.IsIntersect(Schema)
311
- ? Types.Intersect([Left, ...Schema.allOf])
312
- : Types.Intersect([Left, Schema]);
207
+ return t.TypeGuard.IsIntersect(Schema)
208
+ ? t.Intersect([Left, ...Schema.allOf])
209
+ : t.Intersect([Left, Schema]);
313
210
  }
314
211
  if (Operator === '|') {
315
- return Types.TypeGuard.IsUnion(Schema)
316
- ? Types.Union([Left, ...Schema.anyOf])
317
- : Types.Union([Left, Schema]);
212
+ return t.TypeGuard.IsUnion(Schema)
213
+ ? t.Union([Left, ...Schema.anyOf])
214
+ : t.Union([Left, Schema]);
318
215
  }
319
216
  throw 1;
320
217
  })() : Left);
@@ -349,9 +246,9 @@ const Readonly = Runtime.Union([Runtime.Tuple([Runtime.Const('readonly')]), Runt
349
246
  const Optional = Runtime.Union([Runtime.Tuple([Runtime.Const(Question)]), Runtime.Tuple([])], (value) => value.length > 0);
350
247
  // prettier-ignore
351
248
  const PropertyMapping = (IsReadonly, Key, IsOptional, _, Type) => ({
352
- [Key]: (IsReadonly && IsOptional ? Types.ReadonlyOptional(Type) :
353
- IsReadonly && !IsOptional ? Types.Readonly(Type) :
354
- !IsReadonly && IsOptional ? Types.Optional(Type) :
249
+ [Key]: (IsReadonly && IsOptional ? t.ReadonlyOptional(Type) :
250
+ IsReadonly && !IsOptional ? t.Readonly(Type) :
251
+ !IsReadonly && IsOptional ? t.Optional(Type) :
355
252
  Type)
356
253
  });
357
254
  // prettier-ignore
@@ -384,7 +281,7 @@ const Properties = Runtime.Union([
384
281
  // Object
385
282
  // ------------------------------------------------------------------
386
283
  // prettier-ignore
387
- const ObjectMapping = (_0, Properties, _2) => Types.Object(Properties);
284
+ const ObjectMapping = (_0, Properties, _2) => t.Object(Properties);
388
285
  // prettier-ignore
389
286
  const _Object = Runtime.Tuple([
390
287
  Runtime.Const(LBrace),
@@ -409,7 +306,7 @@ const Tuple = Runtime.Tuple([
409
306
  Runtime.Const(LBracket),
410
307
  Runtime.Ref('Elements'),
411
308
  Runtime.Const(RBracket)
412
- ], value => Types.Tuple(value[1]));
309
+ ], value => t.Tuple(value[1]));
413
310
  // ------------------------------------------------------------------
414
311
  // Parameters
415
312
  // ------------------------------------------------------------------
@@ -438,7 +335,7 @@ const Constructor = Runtime.Tuple([
438
335
  Runtime.Const(RParen),
439
336
  Runtime.Const('=>'),
440
337
  Runtime.Ref('Type')
441
- ], value => Types.Constructor(value[2], value[5]));
338
+ ], value => t.Constructor(value[2], value[5]));
442
339
  // ------------------------------------------------------------------
443
340
  // Function
444
341
  // ------------------------------------------------------------------
@@ -449,13 +346,13 @@ const Function = Runtime.Tuple([
449
346
  Runtime.Const(RParen),
450
347
  Runtime.Const('=>'),
451
348
  Runtime.Ref('Type')
452
- ], value => Types.Function(value[1], value[4]));
349
+ ], value => t.Function(value[1], value[4]));
453
350
  // ------------------------------------------------------------------
454
351
  // Mapped (requires deferred types)
455
352
  // ------------------------------------------------------------------
456
353
  // prettier-ignore
457
354
  const MappedMapping = (values) => {
458
- return Types.Literal('Mapped types not supported');
355
+ return t.Literal('Mapped types not supported');
459
356
  };
460
357
  // prettier-ignore
461
358
  const Mapped = Runtime.Tuple([
@@ -478,7 +375,7 @@ const AsyncIterator = Runtime.Tuple([
478
375
  Runtime.Const(LAngle),
479
376
  Runtime.Ref('Type'),
480
377
  Runtime.Const(RAngle),
481
- ], value => Types.AsyncIterator(value[2]));
378
+ ], value => t.AsyncIterator(value[2]));
482
379
  // ------------------------------------------------------------------
483
380
  // Iterator
484
381
  // ------------------------------------------------------------------
@@ -488,7 +385,7 @@ const Iterator = Runtime.Tuple([
488
385
  Runtime.Const(LAngle),
489
386
  Runtime.Ref('Type'),
490
387
  Runtime.Const(RAngle),
491
- ], value => Types.Iterator(value[2]));
388
+ ], value => t.Iterator(value[2]));
492
389
  // ------------------------------------------------------------------
493
390
  // ConstructorParameters
494
391
  // ------------------------------------------------------------------
@@ -498,7 +395,7 @@ const ConstructorParameters = Runtime.Tuple([
498
395
  Runtime.Const(LAngle),
499
396
  Runtime.Ref('Type'),
500
397
  Runtime.Const(RAngle),
501
- ], value => Types.ConstructorParameters(value[2]));
398
+ ], value => t.ConstructorParameters(value[2]));
502
399
  // ------------------------------------------------------------------
503
400
  // Parameters
504
401
  // ------------------------------------------------------------------
@@ -508,7 +405,7 @@ const FunctionParameters = Runtime.Tuple([
508
405
  Runtime.Const(LAngle),
509
406
  Runtime.Ref('Type'),
510
407
  Runtime.Const(RAngle),
511
- ], value => Types.Parameters(value[2]));
408
+ ], value => t.Parameters(value[2]));
512
409
  // ------------------------------------------------------------------
513
410
  // InstanceType
514
411
  // ------------------------------------------------------------------
@@ -518,7 +415,7 @@ const InstanceType = Runtime.Tuple([
518
415
  Runtime.Const(LAngle),
519
416
  Runtime.Ref('Type'),
520
417
  Runtime.Const(RAngle),
521
- ], value => Types.InstanceType(value[2]));
418
+ ], value => t.InstanceType(value[2]));
522
419
  // ------------------------------------------------------------------
523
420
  // ReturnType
524
421
  // ------------------------------------------------------------------
@@ -528,7 +425,21 @@ const ReturnType = Runtime.Tuple([
528
425
  Runtime.Const(LAngle),
529
426
  Runtime.Ref('Type'),
530
427
  Runtime.Const(RAngle),
531
- ], value => Types.ReturnType(value[2]));
428
+ ], value => t.ReturnType(value[2]));
429
+ // ------------------------------------------------------------------
430
+ // Argument
431
+ // ------------------------------------------------------------------
432
+ // prettier-ignore
433
+ const Argument = Runtime.Tuple([
434
+ Runtime.Const('Argument'),
435
+ Runtime.Const(LAngle),
436
+ Runtime.Ref('Type'),
437
+ Runtime.Const(RAngle),
438
+ ], results => {
439
+ return t.KindGuard.IsLiteralNumber(results[2])
440
+ ? t.Argument(Math.trunc(results[2].const))
441
+ : t.Never();
442
+ });
532
443
  // ------------------------------------------------------------------
533
444
  // Awaited
534
445
  // ------------------------------------------------------------------
@@ -538,7 +449,7 @@ const Awaited = Runtime.Tuple([
538
449
  Runtime.Const(LAngle),
539
450
  Runtime.Ref('Type'),
540
451
  Runtime.Const(RAngle),
541
- ], value => Types.Awaited(value[2]));
452
+ ], value => t.Awaited(value[2]));
542
453
  // ------------------------------------------------------------------
543
454
  // Array
544
455
  // ------------------------------------------------------------------
@@ -548,7 +459,7 @@ const Array = Runtime.Tuple([
548
459
  Runtime.Const(LAngle),
549
460
  Runtime.Ref('Type'),
550
461
  Runtime.Const(RAngle),
551
- ], value => Types.Array(value[2]));
462
+ ], value => t.Array(value[2]));
552
463
  // ------------------------------------------------------------------
553
464
  // Record
554
465
  // ------------------------------------------------------------------
@@ -560,7 +471,7 @@ const Record = Runtime.Tuple([
560
471
  Runtime.Const(Comma),
561
472
  Runtime.Ref('Type'),
562
473
  Runtime.Const(RAngle),
563
- ], value => Types.Record(value[2], value[4]));
474
+ ], value => t.Record(value[2], value[4]));
564
475
  // ------------------------------------------------------------------
565
476
  // Promise
566
477
  // ------------------------------------------------------------------
@@ -570,7 +481,7 @@ const Promise = Runtime.Tuple([
570
481
  Runtime.Const(LAngle),
571
482
  Runtime.Ref('Type'),
572
483
  Runtime.Const(RAngle),
573
- ], value => Types.Promise(value[2]));
484
+ ], value => t.Promise(value[2]));
574
485
  // ------------------------------------------------------------------
575
486
  // Partial
576
487
  // ------------------------------------------------------------------
@@ -580,7 +491,7 @@ const Partial = Runtime.Tuple([
580
491
  Runtime.Const(LAngle),
581
492
  Runtime.Ref('Type'),
582
493
  Runtime.Const(RAngle),
583
- ], value => Types.Partial(value[2]));
494
+ ], value => t.Partial(value[2]));
584
495
  // ------------------------------------------------------------------
585
496
  // Required
586
497
  // ------------------------------------------------------------------
@@ -590,7 +501,7 @@ const Required = Runtime.Tuple([
590
501
  Runtime.Const(LAngle),
591
502
  Runtime.Ref('Type'),
592
503
  Runtime.Const(RAngle),
593
- ], value => Types.Required(value[2]));
504
+ ], value => t.Required(value[2]));
594
505
  // ------------------------------------------------------------------
595
506
  // Pick
596
507
  // ------------------------------------------------------------------
@@ -602,7 +513,7 @@ const Pick = Runtime.Tuple([
602
513
  Runtime.Const(Comma),
603
514
  Runtime.Ref('Type'),
604
515
  Runtime.Const(RAngle),
605
- ], value => Types.Pick(value[2], value[4]));
516
+ ], value => t.Pick(value[2], value[4]));
606
517
  // ------------------------------------------------------------------
607
518
  // Omit
608
519
  // ------------------------------------------------------------------
@@ -614,7 +525,7 @@ const Omit = Runtime.Tuple([
614
525
  Runtime.Const(Comma),
615
526
  Runtime.Ref('Type'),
616
527
  Runtime.Const(RAngle),
617
- ], value => Types.Omit(value[2], value[4]));
528
+ ], value => t.Omit(value[2], value[4]));
618
529
  // ------------------------------------------------------------------
619
530
  // Exclude
620
531
  // ------------------------------------------------------------------
@@ -626,7 +537,7 @@ const Exclude = Runtime.Tuple([
626
537
  Runtime.Const(Comma),
627
538
  Runtime.Ref('Type'),
628
539
  Runtime.Const(RAngle),
629
- ], value => Types.Exclude(value[2], value[4]));
540
+ ], value => t.Exclude(value[2], value[4]));
630
541
  // ------------------------------------------------------------------
631
542
  // Extract
632
543
  // ------------------------------------------------------------------
@@ -638,7 +549,7 @@ const Extract = Runtime.Tuple([
638
549
  Runtime.Const(Comma),
639
550
  Runtime.Ref('Type'),
640
551
  Runtime.Const(RAngle),
641
- ], value => Types.Extract(value[2], value[4]));
552
+ ], value => t.Extract(value[2], value[4]));
642
553
  // ------------------------------------------------------------------
643
554
  // Uppercase
644
555
  // ------------------------------------------------------------------
@@ -648,7 +559,7 @@ const Uppercase = Runtime.Tuple([
648
559
  Runtime.Const(LAngle),
649
560
  Runtime.Ref('Type'),
650
561
  Runtime.Const(RAngle),
651
- ], value => Types.Uppercase(value[2]));
562
+ ], value => t.Uppercase(value[2]));
652
563
  // ------------------------------------------------------------------
653
564
  // Lowercase
654
565
  // ------------------------------------------------------------------
@@ -658,7 +569,7 @@ const Lowercase = Runtime.Tuple([
658
569
  Runtime.Const(LAngle),
659
570
  Runtime.Ref('Type'),
660
571
  Runtime.Const(RAngle),
661
- ], value => Types.Lowercase(value[2]));
572
+ ], value => t.Lowercase(value[2]));
662
573
  // ------------------------------------------------------------------
663
574
  // Capitalize
664
575
  // ------------------------------------------------------------------
@@ -668,7 +579,7 @@ const Capitalize = Runtime.Tuple([
668
579
  Runtime.Const(LAngle),
669
580
  Runtime.Ref('Type'),
670
581
  Runtime.Const(RAngle),
671
- ], value => Types.Capitalize(value[2]));
582
+ ], value => t.Capitalize(value[2]));
672
583
  // ------------------------------------------------------------------
673
584
  // Uncapitalize
674
585
  // ------------------------------------------------------------------
@@ -678,41 +589,20 @@ const Uncapitalize = Runtime.Tuple([
678
589
  Runtime.Const(LAngle),
679
590
  Runtime.Ref('Type'),
680
591
  Runtime.Const(RAngle),
681
- ], value => Types.Uncapitalize(value[2]));
592
+ ], value => t.Uncapitalize(value[2]));
682
593
  // ------------------------------------------------------------------
683
594
  // Date
684
595
  // ------------------------------------------------------------------
685
- const Date = Runtime.Const('Date', Runtime.As(Types.Date()));
596
+ const Date = Runtime.Const('Date', Runtime.As(t.Date()));
686
597
  // ------------------------------------------------------------------
687
598
  // Uint8Array
688
599
  // ------------------------------------------------------------------
689
- const Uint8Array = Runtime.Const('Uint8Array', Runtime.As(Types.Uint8Array()));
690
- // ------------------------------------------------------------------
691
- // Main
692
- // ------------------------------------------------------------------
693
- // prettier-ignore
694
- const Main = Runtime.Union([
695
- ModuleDeclaration,
696
- TypeAliasDeclaration,
697
- InterfaceDeclaration,
698
- Type
699
- ]);
600
+ const Uint8Array = Runtime.Const('Uint8Array', Runtime.As(t.Uint8Array()));
700
601
  // ------------------------------------------------------------------
701
602
  // Module
702
603
  // ------------------------------------------------------------------
703
604
  // prettier-ignore
704
605
  export const Module = new Runtime.Module({
705
- // ----------------------------------------------------------------
706
- // Modules, Interfaces and Type Aliases
707
- // ----------------------------------------------------------------
708
- ExportModifier,
709
- HeritageList,
710
- Heritage,
711
- InterfaceDeclaration,
712
- TypeAliasDeclaration,
713
- ModuleType,
714
- ModuleProperties,
715
- ModuleDeclaration,
716
606
  // ----------------------------------------------------------------
717
607
  // Type Expressions
718
608
  // ----------------------------------------------------------------
@@ -744,6 +634,7 @@ export const Module = new Runtime.Module({
744
634
  Mapped,
745
635
  AsyncIterator,
746
636
  Iterator,
637
+ Argument,
747
638
  Awaited,
748
639
  Array,
749
640
  Record,
@@ -764,9 +655,6 @@ export const Module = new Runtime.Module({
764
655
  Uncapitalize,
765
656
  Date,
766
657
  Uint8Array,
658
+ GenericReference,
767
659
  Reference,
768
- // ----------------------------------------------------------------
769
- // Main
770
- // ----------------------------------------------------------------
771
- Main
772
660
  });