@sinclair/typebox 0.33.21 → 0.34.0

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 (142) hide show
  1. package/build/cjs/compiler/compiler.d.ts +2 -2
  2. package/build/cjs/compiler/compiler.js +13 -2
  3. package/build/cjs/errors/errors.js +7 -0
  4. package/build/cjs/index.d.ts +1 -3
  5. package/build/cjs/index.js +1 -6
  6. package/build/cjs/syntax/parse.d.ts +15 -0
  7. package/build/cjs/{parse → syntax}/parse.js +6 -5
  8. package/build/cjs/{parse → syntax}/runtime.d.ts +17 -4
  9. package/build/cjs/{parse → syntax}/runtime.js +180 -27
  10. package/build/cjs/{parse → syntax}/static.d.ts +104 -20
  11. package/build/cjs/type/guard/kind.d.ts +3 -0
  12. package/build/cjs/type/guard/kind.js +5 -0
  13. package/build/cjs/type/guard/type.d.ts +3 -0
  14. package/build/cjs/type/guard/type.js +13 -0
  15. package/build/cjs/type/index.d.ts +1 -2
  16. package/build/cjs/type/index.js +1 -2
  17. package/build/cjs/type/module/index.d.ts +1 -0
  18. package/build/cjs/type/{deref → module}/index.js +1 -1
  19. package/build/cjs/type/module/module.d.ts +71 -0
  20. package/build/cjs/type/module/module.js +34 -0
  21. package/build/cjs/type/ref/ref.d.ts +4 -7
  22. package/build/cjs/type/ref/ref.js +3 -11
  23. package/build/cjs/type/static/static.d.ts +1 -1
  24. package/build/cjs/type/type/json.d.ts +4 -17
  25. package/build/cjs/type/type/json.js +52 -68
  26. package/build/cjs/type/type/type.d.ts +1 -2
  27. package/build/cjs/type/type/type.js +55 -57
  28. package/build/cjs/value/cast/cast.js +8 -1
  29. package/build/cjs/value/check/check.js +8 -1
  30. package/build/cjs/value/clean/clean.js +8 -1
  31. package/build/cjs/value/convert/convert.js +7 -0
  32. package/build/cjs/value/create/create.js +7 -0
  33. package/build/cjs/value/default/default.js +7 -0
  34. package/build/cjs/value/transform/decode.js +11 -0
  35. package/build/cjs/value/transform/encode.js +11 -0
  36. package/build/esm/compiler/compiler.d.mts +2 -2
  37. package/build/esm/compiler/compiler.mjs +13 -2
  38. package/build/esm/errors/errors.mjs +7 -0
  39. package/build/esm/index.d.mts +1 -3
  40. package/build/esm/index.mjs +1 -6
  41. package/build/esm/syntax/parse.d.mts +15 -0
  42. package/build/esm/syntax/parse.mjs +14 -0
  43. package/build/esm/{parse → syntax}/runtime.d.mts +17 -4
  44. package/build/esm/{parse → syntax}/runtime.mjs +180 -27
  45. package/build/esm/{parse → syntax}/static.d.mts +104 -20
  46. package/build/esm/type/guard/kind.d.mts +3 -0
  47. package/build/esm/type/guard/kind.mjs +4 -0
  48. package/build/esm/type/guard/type.d.mts +3 -0
  49. package/build/esm/type/guard/type.mjs +12 -0
  50. package/build/esm/type/index.d.mts +1 -2
  51. package/build/esm/type/index.mjs +1 -2
  52. package/build/esm/type/module/index.d.mts +1 -0
  53. package/build/esm/type/module/index.mjs +1 -0
  54. package/build/esm/type/module/module.d.mts +71 -0
  55. package/build/esm/type/module/module.mjs +28 -0
  56. package/build/esm/type/ref/ref.d.mts +4 -7
  57. package/build/esm/type/ref/ref.mjs +3 -11
  58. package/build/esm/type/static/static.d.mts +1 -1
  59. package/build/esm/type/type/json.d.mts +4 -17
  60. package/build/esm/type/type/json.mjs +7 -23
  61. package/build/esm/type/type/type.d.mts +1 -2
  62. package/build/esm/type/type/type.mjs +1 -2
  63. package/build/esm/value/cast/cast.mjs +9 -2
  64. package/build/esm/value/check/check.mjs +9 -2
  65. package/build/esm/value/clean/clean.mjs +9 -2
  66. package/build/esm/value/convert/convert.mjs +7 -0
  67. package/build/esm/value/create/create.mjs +7 -0
  68. package/build/esm/value/default/default.mjs +7 -0
  69. package/build/esm/value/transform/decode.mjs +11 -0
  70. package/build/esm/value/transform/encode.mjs +11 -0
  71. package/package.json +6 -6
  72. package/readme.md +219 -97
  73. package/syntax/package.json +4 -0
  74. package/build/cjs/parse/parse.d.ts +0 -11
  75. package/build/cjs/type/deref/deref.d.ts +0 -22
  76. package/build/cjs/type/deref/deref.js +0 -106
  77. package/build/cjs/type/deref/index.d.ts +0 -1
  78. package/build/cjs/type/strict/index.d.ts +0 -1
  79. package/build/cjs/type/strict/index.js +0 -18
  80. package/build/cjs/type/strict/strict.d.ts +0 -12
  81. package/build/cjs/type/strict/strict.js +0 -16
  82. package/build/esm/parse/parse.d.mts +0 -11
  83. package/build/esm/parse/parse.mjs +0 -13
  84. package/build/esm/type/deref/deref.d.mts +0 -22
  85. package/build/esm/type/deref/deref.mjs +0 -102
  86. package/build/esm/type/deref/index.d.mts +0 -1
  87. package/build/esm/type/deref/index.mjs +0 -1
  88. package/build/esm/type/strict/index.d.mts +0 -1
  89. package/build/esm/type/strict/index.mjs +0 -1
  90. package/build/esm/type/strict/strict.d.mts +0 -12
  91. package/build/esm/type/strict/strict.mjs +0 -12
  92. package/parse/package.json +0 -4
  93. /package/build/cjs/{parse → syntax}/index.d.ts +0 -0
  94. /package/build/cjs/{parse → syntax}/index.js +0 -0
  95. /package/build/cjs/{parse → syntax}/parsebox/index.d.ts +0 -0
  96. /package/build/cjs/{parse → syntax}/parsebox/index.js +0 -0
  97. /package/build/cjs/{parse → syntax}/parsebox/runtime/guard.d.ts +0 -0
  98. /package/build/cjs/{parse → syntax}/parsebox/runtime/guard.js +0 -0
  99. /package/build/cjs/{parse → syntax}/parsebox/runtime/index.d.ts +0 -0
  100. /package/build/cjs/{parse → syntax}/parsebox/runtime/index.js +0 -0
  101. /package/build/cjs/{parse → syntax}/parsebox/runtime/module.d.ts +0 -0
  102. /package/build/cjs/{parse → syntax}/parsebox/runtime/module.js +0 -0
  103. /package/build/cjs/{parse → syntax}/parsebox/runtime/parse.d.ts +0 -0
  104. /package/build/cjs/{parse → syntax}/parsebox/runtime/parse.js +0 -0
  105. /package/build/cjs/{parse → syntax}/parsebox/runtime/token.d.ts +0 -0
  106. /package/build/cjs/{parse → syntax}/parsebox/runtime/token.js +0 -0
  107. /package/build/cjs/{parse → syntax}/parsebox/runtime/types.d.ts +0 -0
  108. /package/build/cjs/{parse → syntax}/parsebox/runtime/types.js +0 -0
  109. /package/build/cjs/{parse → syntax}/parsebox/static/index.d.ts +0 -0
  110. /package/build/cjs/{parse → syntax}/parsebox/static/index.js +0 -0
  111. /package/build/cjs/{parse → syntax}/parsebox/static/parse.d.ts +0 -0
  112. /package/build/cjs/{parse → syntax}/parsebox/static/parse.js +0 -0
  113. /package/build/cjs/{parse → syntax}/parsebox/static/token.d.ts +0 -0
  114. /package/build/cjs/{parse → syntax}/parsebox/static/token.js +0 -0
  115. /package/build/cjs/{parse → syntax}/parsebox/static/types.d.ts +0 -0
  116. /package/build/cjs/{parse → syntax}/parsebox/static/types.js +0 -0
  117. /package/build/cjs/{parse → syntax}/static.js +0 -0
  118. /package/build/esm/{parse → syntax}/index.d.mts +0 -0
  119. /package/build/esm/{parse → syntax}/index.mjs +0 -0
  120. /package/build/esm/{parse → syntax}/parsebox/index.d.mts +0 -0
  121. /package/build/esm/{parse → syntax}/parsebox/index.mjs +0 -0
  122. /package/build/esm/{parse → syntax}/parsebox/runtime/guard.d.mts +0 -0
  123. /package/build/esm/{parse → syntax}/parsebox/runtime/guard.mjs +0 -0
  124. /package/build/esm/{parse → syntax}/parsebox/runtime/index.d.mts +0 -0
  125. /package/build/esm/{parse → syntax}/parsebox/runtime/index.mjs +0 -0
  126. /package/build/esm/{parse → syntax}/parsebox/runtime/module.d.mts +0 -0
  127. /package/build/esm/{parse → syntax}/parsebox/runtime/module.mjs +0 -0
  128. /package/build/esm/{parse → syntax}/parsebox/runtime/parse.d.mts +0 -0
  129. /package/build/esm/{parse → syntax}/parsebox/runtime/parse.mjs +0 -0
  130. /package/build/esm/{parse → syntax}/parsebox/runtime/token.d.mts +0 -0
  131. /package/build/esm/{parse → syntax}/parsebox/runtime/token.mjs +0 -0
  132. /package/build/esm/{parse → syntax}/parsebox/runtime/types.d.mts +0 -0
  133. /package/build/esm/{parse → syntax}/parsebox/runtime/types.mjs +0 -0
  134. /package/build/esm/{parse → syntax}/parsebox/static/index.d.mts +0 -0
  135. /package/build/esm/{parse → syntax}/parsebox/static/index.mjs +0 -0
  136. /package/build/esm/{parse → syntax}/parsebox/static/parse.d.mts +0 -0
  137. /package/build/esm/{parse → syntax}/parsebox/static/parse.mjs +0 -0
  138. /package/build/esm/{parse → syntax}/parsebox/static/token.d.mts +0 -0
  139. /package/build/esm/{parse → syntax}/parsebox/static/token.mjs +0 -0
  140. /package/build/esm/{parse → syntax}/parsebox/static/types.d.mts +0 -0
  141. /package/build/esm/{parse → syntax}/parsebox/static/types.mjs +0 -0
  142. /package/build/esm/{parse → syntax}/static.mjs +0 -0
@@ -1,7 +1,7 @@
1
1
  import { ValueErrorIterator } from '../errors/index';
2
2
  import { TypeBoxError } from '../type/error/index';
3
3
  import type { TSchema } from '../type/schema/index';
4
- import type { Static, StaticDecode } from '../type/static/index';
4
+ import type { Static, StaticDecode, StaticEncode } from '../type/static/index';
5
5
  export type CheckFunction = (value: unknown) => boolean;
6
6
  export declare class TypeCheck<T extends TSchema> {
7
7
  private readonly schema;
@@ -19,7 +19,7 @@ export declare class TypeCheck<T extends TSchema> {
19
19
  /** Decodes a value or throws if error */
20
20
  Decode<Static = StaticDecode<T>, Result extends Static = Static>(value: unknown): Result;
21
21
  /** Encodes a value or throws if error */
22
- Encode<Static = StaticDecode<T>, Result extends Static = Static>(value: unknown): Result;
22
+ Encode<Static = StaticEncode<T>, Result extends Static = Static>(value: unknown): Result;
23
23
  }
24
24
  export declare class TypeCompilerUnknownTypeError extends TypeBoxError {
25
25
  readonly schema: TSchema;
@@ -262,6 +262,11 @@ var TypeCompiler;
262
262
  function* FromFunction(schema, references, value) {
263
263
  yield `(typeof ${value} === 'function')`;
264
264
  }
265
+ function* FromImport(schema, references, value) {
266
+ const definitions = globalThis.Object.values(schema.$defs);
267
+ const target = schema.$defs[schema.$ref];
268
+ yield* Visit(target, [...references, ...definitions], value);
269
+ }
265
270
  function* FromInteger(schema, references, value) {
266
271
  yield `Number.isInteger(${value})`;
267
272
  if ((0, index_11.IsNumber)(schema.exclusiveMaximum))
@@ -379,9 +384,13 @@ var TypeCompiler;
379
384
  function* FromRef(schema, references, value) {
380
385
  const target = (0, index_5.Deref)(schema, references);
381
386
  // Reference: If we have seen this reference before we can just yield and return the function call.
382
- // If this isn't the case we defer to visit to generate and set the function for subsequent passes.
383
- if (state.functions.has(schema.$ref))
387
+ // If this isn't the case we defer to visit to generate and set the _recursion_end_for_ for subsequent
388
+ // passes. This operation is very awkward as we are using the functions state to store values to
389
+ // enable self referential types to terminate. This needs to be refactored.
390
+ const recursiveEnd = `_recursion_end_for_${schema.$ref}`;
391
+ if (state.functions.has(recursiveEnd))
384
392
  return yield `${CreateFunctionName(schema.$ref)}(${value})`;
393
+ state.functions.set(recursiveEnd, ''); // terminate recursion here by setting the name.
385
394
  yield* Visit(target, references, value);
386
395
  }
387
396
  function* FromRegExp(schema, references, value) {
@@ -488,6 +497,8 @@ var TypeCompiler;
488
497
  return yield* FromDate(schema_, references_, value);
489
498
  case 'Function':
490
499
  return yield* FromFunction(schema_, references_, value);
500
+ case 'Import':
501
+ return yield* FromImport(schema_, references_, value);
491
502
  case 'Integer':
492
503
  return yield* FromInteger(schema_, references_, value);
493
504
  case 'Intersect':
@@ -239,6 +239,11 @@ function* FromFunction(schema, references, path, value) {
239
239
  if (!(0, index_10.IsFunction)(value))
240
240
  yield Create(ValueErrorType.Function, schema, path, value);
241
241
  }
242
+ function* FromImport(schema, references, path, value) {
243
+ const definitions = globalThis.Object.values(schema.$defs);
244
+ const target = schema.$defs[schema.$ref];
245
+ yield* Visit(target, [...references, ...definitions], path, value);
246
+ }
242
247
  function* FromInteger(schema, references, path, value) {
243
248
  if (!(0, index_10.IsInteger)(value))
244
249
  return yield Create(ValueErrorType.Integer, schema, path, value);
@@ -530,6 +535,8 @@ function* Visit(schema, references, path, value) {
530
535
  return yield* FromDate(schema_, references_, path, value);
531
536
  case 'Function':
532
537
  return yield* FromFunction(schema_, references_, path, value);
538
+ case 'Import':
539
+ return yield* FromImport(schema_, references_, path, value);
533
540
  case 'Integer':
534
541
  return yield* FromInteger(schema_, references_, path, value);
535
542
  case 'Intersect':
@@ -7,7 +7,6 @@ export * from './type/patterns/index';
7
7
  export * from './type/registry/index';
8
8
  export * from './type/sets/index';
9
9
  export * from './type/symbols/index';
10
- export * from './parse/index';
11
10
  export * from './type/any/index';
12
11
  export * from './type/array/index';
13
12
  export * from './type/async-iterator/index';
@@ -19,7 +18,6 @@ export * from './type/const/index';
19
18
  export * from './type/constructor/index';
20
19
  export * from './type/constructor-parameters/index';
21
20
  export * from './type/date/index';
22
- export * from './type/deref/index';
23
21
  export * from './type/enum/index';
24
22
  export * from './type/exclude/index';
25
23
  export * from './type/extends/index';
@@ -33,6 +31,7 @@ export * from './type/iterator/index';
33
31
  export * from './type/intrinsic/index';
34
32
  export * from './type/keyof/index';
35
33
  export * from './type/literal/index';
34
+ export * from './type/module/index';
36
35
  export * from './type/mapped/index';
37
36
  export * from './type/never/index';
38
37
  export * from './type/not/index';
@@ -56,7 +55,6 @@ export * from './type/rest/index';
56
55
  export * from './type/return-type/index';
57
56
  export * from './type/schema/index';
58
57
  export * from './type/static/index';
59
- export * from './type/strict/index';
60
58
  export * from './type/string/index';
61
59
  export * from './type/symbol/index';
62
60
  export * from './type/template-literal/index';
@@ -28,10 +28,6 @@ __exportStar(require("./type/registry/index"), exports);
28
28
  __exportStar(require("./type/sets/index"), exports);
29
29
  __exportStar(require("./type/symbols/index"), exports);
30
30
  // ------------------------------------------------------------------
31
- // Parse
32
- // ------------------------------------------------------------------
33
- __exportStar(require("./parse/index"), exports);
34
- // ------------------------------------------------------------------
35
31
  // Types
36
32
  // ------------------------------------------------------------------
37
33
  __exportStar(require("./type/any/index"), exports);
@@ -45,7 +41,6 @@ __exportStar(require("./type/const/index"), exports);
45
41
  __exportStar(require("./type/constructor/index"), exports);
46
42
  __exportStar(require("./type/constructor-parameters/index"), exports);
47
43
  __exportStar(require("./type/date/index"), exports);
48
- __exportStar(require("./type/deref/index"), exports);
49
44
  __exportStar(require("./type/enum/index"), exports);
50
45
  __exportStar(require("./type/exclude/index"), exports);
51
46
  __exportStar(require("./type/extends/index"), exports);
@@ -59,6 +54,7 @@ __exportStar(require("./type/iterator/index"), exports);
59
54
  __exportStar(require("./type/intrinsic/index"), exports);
60
55
  __exportStar(require("./type/keyof/index"), exports);
61
56
  __exportStar(require("./type/literal/index"), exports);
57
+ __exportStar(require("./type/module/index"), exports);
62
58
  __exportStar(require("./type/mapped/index"), exports);
63
59
  __exportStar(require("./type/never/index"), exports);
64
60
  __exportStar(require("./type/not/index"), exports);
@@ -82,7 +78,6 @@ __exportStar(require("./type/rest/index"), exports);
82
78
  __exportStar(require("./type/return-type/index"), exports);
83
79
  __exportStar(require("./type/schema/index"), exports);
84
80
  __exportStar(require("./type/static/index"), exports);
85
- __exportStar(require("./type/strict/index"), exports);
86
81
  __exportStar(require("./type/string/index"), exports);
87
82
  __exportStar(require("./type/symbol/index"), exports);
88
83
  __exportStar(require("./type/template-literal/index"), exports);
@@ -0,0 +1,15 @@
1
+ import * as Types from '../type/index';
2
+ import { Static } from './parsebox/index';
3
+ import { Main } from './static';
4
+ /** `[Syntax]` Infers a TypeBox type from TypeScript syntax. */
5
+ export type StaticParseAsSchema<Context extends Record<PropertyKey, Types.TSchema>, Code extends string> = Static.Parse<Main, Code, Context>[0];
6
+ /** `[Syntax]` Infers a TypeScript type from TypeScript syntax. */
7
+ export type StaticParseAsType<Context extends Record<PropertyKey, Types.TSchema>, Code extends string> = StaticParseAsSchema<Context, Code> extends infer Type extends Types.TSchema ? Types.StaticDecode<Type> : undefined;
8
+ /** `[Syntax]` Parses a TypeBox type from TypeScript syntax. */
9
+ export declare function Parse<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): StaticParseAsSchema<Context, Code>;
10
+ /** `[Syntax]` Parses a TypeBox type from TypeScript syntax. */
11
+ export declare function Parse<Code extends string>(code: Code, options?: Types.SchemaOptions): StaticParseAsSchema<{}, Code>;
12
+ /** `[Syntax]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */
13
+ export declare function ParseOnly<Context extends Record<PropertyKey, Types.TSchema>, Code extends string>(context: Context, code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
14
+ /** `[Syntax]` Parses a TypeBox TSchema from TypeScript syntax */
15
+ export declare function ParseOnly<Code extends string>(code: Code, options?: Types.SchemaOptions): Types.TSchema | undefined;
@@ -3,16 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Parse = Parse;
5
5
  exports.ParseOnly = ParseOnly;
6
- const type_1 = require("../type/create/type");
6
+ const Types = require("../type/index");
7
7
  const runtime_1 = require("./runtime");
8
- /** `[Experimental]` Parses a TypeScript type annotation as an inferred TypeBox type */
8
+ /** `[Syntax]` Parses a TypeBox type from TypeScript syntax. */
9
9
  function Parse(...args) {
10
10
  return ParseOnly.apply(null, args);
11
11
  }
12
- /** `[Experimental]` Parses a TypeScript type annotation as TSchema */
12
+ /** `[Syntax]` Parses a TypeBox TSchema from TypeScript syntax. This function does not infer the type. */
13
13
  function ParseOnly(...args) {
14
14
  const withContext = typeof args[0] === 'string' ? false : true;
15
15
  const [context, code, options] = withContext ? [args[0], args[1], args[2] || {}] : [{}, args[0], args[1] || {}];
16
- const type = runtime_1.Module.Parse('Type', code, context)[0];
17
- return (type !== undefined ? (0, type_1.CreateType)(type, options) : undefined);
16
+ const type = runtime_1.Module.Parse('Main', code, context)[0];
17
+ // Note: Parsing may return either a ModuleInstance or Type. We only apply options on the Type.
18
+ return Types.KindGuard.IsSchema(type) ? Types.CloneType(type, options) : type;
18
19
  }
@@ -1,6 +1,18 @@
1
1
  import { Runtime } from './parsebox/index';
2
2
  import * as Types from '../type/index';
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>>;
4
16
  Literal: Runtime.IUnion<Types.TLiteral<string> | Types.TLiteral<number> | Types.TLiteral<boolean>>;
5
17
  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>;
6
18
  KeyOf: Runtime.IUnion<boolean>;
@@ -14,14 +26,14 @@ export declare const Module: Runtime.Module<{
14
26
  Expr: Runtime.ITuple<Types.TSchema>;
15
27
  Type: Runtime.IRef<unknown>;
16
28
  PropertyKey: Runtime.IUnion<string>;
17
- PropertyReadonly: Runtime.IUnion<boolean>;
18
- PropertyOptional: Runtime.IUnion<boolean>;
29
+ Readonly: Runtime.IUnion<boolean>;
30
+ Optional: Runtime.IUnion<boolean>;
19
31
  Property: Runtime.ITuple<{
20
32
  [x: string]: Types.TSchema;
21
33
  }>;
22
34
  PropertyDelimiter: Runtime.IUnion<[","] | [",", "\n"] | [";"] | [";", "\n"] | ["\n"]>;
23
- Properties: Runtime.IUnion<unknown[]>;
24
- Object: Runtime.ITuple<Types.TObject<Record<string, Types.TSchema>>>;
35
+ Properties: Runtime.IUnion<Types.TProperties>;
36
+ Object: Runtime.ITuple<Types.TObject<Types.TProperties>>;
25
37
  Elements: Runtime.IUnion<unknown[]>;
26
38
  Tuple: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
27
39
  Parameter: Runtime.ITuple<Types.TSchema>;
@@ -52,4 +64,5 @@ export declare const Module: Runtime.Module<{
52
64
  Date: Runtime.IConst<Types.TDate>;
53
65
  Uint8Array: Runtime.IConst<Types.TUint8Array>;
54
66
  Reference: Runtime.IIdent<Types.TSchema>;
67
+ Main: Runtime.IUnion<unknown>;
55
68
  }>;
@@ -23,6 +23,7 @@ const SemiColon = ';';
23
23
  const SingleQuote = "'";
24
24
  const DoubleQuote = '"';
25
25
  const Tilde = '`';
26
+ const Equals = '=';
26
27
  // ------------------------------------------------------------------
27
28
  // DestructureRight
28
29
  // ------------------------------------------------------------------
@@ -33,12 +34,133 @@ function DestructureRight(values) {
33
34
  : [values, undefined];
34
35
  }
35
36
  // ------------------------------------------------------------------
37
+ // Deref
38
+ // ------------------------------------------------------------------
39
+ const Deref = (context, key) => {
40
+ return key in context ? context[key] : Types.Ref(key);
41
+ };
42
+ // ------------------------------------------------------------------
43
+ // ExportModifier
44
+ // ------------------------------------------------------------------
45
+ // prettier-ignore
46
+ const ExportModifierMapping = (values) => {
47
+ return values.length === 1;
48
+ };
49
+ // prettier-ignore
50
+ const ExportModifier = index_1.Runtime.Union([
51
+ index_1.Runtime.Tuple([index_1.Runtime.Const('export')]), index_1.Runtime.Tuple([])
52
+ ], ExportModifierMapping);
53
+ // ------------------------------------------------------------------
54
+ // TypeAliasDeclaration
55
+ // ------------------------------------------------------------------
56
+ // prettier-ignore
57
+ const TypeAliasDeclarationMapping = (_Export, _Keyword, Ident, _Equals, Type) => {
58
+ return { [Ident]: Type };
59
+ };
60
+ // prettier-ignore
61
+ const TypeAliasDeclaration = index_1.Runtime.Tuple([
62
+ index_1.Runtime.Ref('ExportModifier'),
63
+ index_1.Runtime.Const('type'),
64
+ index_1.Runtime.Ident(),
65
+ index_1.Runtime.Const(Equals),
66
+ index_1.Runtime.Ref('Type')
67
+ ], value => TypeAliasDeclarationMapping(...value));
68
+ // ------------------------------------------------------------------
69
+ // HeritageList
70
+ // ------------------------------------------------------------------
71
+ // prettier-ignore (note, heritage list should disallow trailing comma)
72
+ const HeritageListDelimiter = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const(Comma), index_1.Runtime.Const(Newline)]), index_1.Runtime.Tuple([index_1.Runtime.Const(Comma)])]);
73
+ // prettier-ignore
74
+ const HeritageListMapping = (values, context) => {
75
+ return (values.length === 3 ? [Deref(context, values[0]), ...values[2]] :
76
+ values.length === 1 ? [Deref(context, values[0])] :
77
+ []);
78
+ };
79
+ // prettier-ignore
80
+ const HeritageList = index_1.Runtime.Union([
81
+ index_1.Runtime.Tuple([index_1.Runtime.Ident(), HeritageListDelimiter, index_1.Runtime.Ref('HeritageList')]),
82
+ index_1.Runtime.Tuple([index_1.Runtime.Ident()]),
83
+ index_1.Runtime.Tuple([])
84
+ ], HeritageListMapping);
85
+ // ------------------------------------------------------------------
86
+ // Heritage
87
+ // ------------------------------------------------------------------
88
+ // prettier-ignore
89
+ const HeritageMapping = (values) => {
90
+ return (values.length === 2 ? values[1] : []);
91
+ };
92
+ // prettier-ignore
93
+ const Heritage = index_1.Runtime.Union([
94
+ index_1.Runtime.Tuple([index_1.Runtime.Const('extends'), index_1.Runtime.Ref('HeritageList')]),
95
+ index_1.Runtime.Tuple([])
96
+ ], HeritageMapping);
97
+ // ------------------------------------------------------------------
98
+ // InterfaceDeclaration
99
+ // ------------------------------------------------------------------
100
+ // prettier-ignore
101
+ const InterfaceDeclarationMapping = (_0, _1, Ident, Heritage, _4, Properties, _6) => {
102
+ return { [Ident]: Types.Intersect([...Heritage, Types.Object(Properties)]) };
103
+ };
104
+ // prettier-ignore
105
+ const InterfaceDeclaration = index_1.Runtime.Tuple([
106
+ index_1.Runtime.Ref('ExportModifier'),
107
+ index_1.Runtime.Const('interface'),
108
+ index_1.Runtime.Ident(),
109
+ index_1.Runtime.Ref('Heritage'),
110
+ index_1.Runtime.Const(LBrace),
111
+ index_1.Runtime.Ref('Properties'),
112
+ index_1.Runtime.Const(RBrace),
113
+ ], values => InterfaceDeclarationMapping(...values));
114
+ // ------------------------------------------------------------------
115
+ // ModuleType
116
+ // ------------------------------------------------------------------
117
+ // prettier-ignore
118
+ const ModuleType = index_1.Runtime.Union([
119
+ index_1.Runtime.Ref('InterfaceDeclaration'),
120
+ index_1.Runtime.Ref('TypeAliasDeclaration')
121
+ ]);
122
+ // ------------------------------------------------------------------
123
+ // ModuleProperties
124
+ // ------------------------------------------------------------------
125
+ // prettier-ignore
126
+ const ModulePropertiesDelimiter = index_1.Runtime.Union([
127
+ index_1.Runtime.Tuple([index_1.Runtime.Const(SemiColon), index_1.Runtime.Const(Newline)]),
128
+ index_1.Runtime.Tuple([index_1.Runtime.Const(SemiColon)]),
129
+ index_1.Runtime.Tuple([index_1.Runtime.Const(Newline)]),
130
+ ]);
131
+ // prettier-ignore
132
+ const ModulePropertiesMapping = (values) => {
133
+ return (values.length === 3 ? { ...values[0], ...values[2] } :
134
+ values.length === 1 ? values[0] :
135
+ {});
136
+ };
137
+ // prettier-ignore
138
+ const ModuleProperties = index_1.Runtime.Union([
139
+ index_1.Runtime.Tuple([index_1.Runtime.Ref('ModuleType'), ModulePropertiesDelimiter, index_1.Runtime.Ref('ModuleProperties')]),
140
+ index_1.Runtime.Tuple([index_1.Runtime.Ref('ModuleType')]),
141
+ index_1.Runtime.Tuple([]),
142
+ ], ModulePropertiesMapping);
143
+ // ------------------------------------------------------------------
144
+ // ModuleDeclaration
145
+ // ------------------------------------------------------------------
146
+ // prettier-ignore
147
+ const ModuleIdentifier = index_1.Runtime.Union([
148
+ index_1.Runtime.Tuple([index_1.Runtime.Ident()]),
149
+ index_1.Runtime.Tuple([])
150
+ ]);
151
+ // prettier-ignore
152
+ const ModuleDeclarationMapping = (_1, _2, _Ident, _3, Properties, _5) => {
153
+ return Types.Module(Properties);
154
+ };
155
+ // prettier-ignore
156
+ const ModuleDeclaration = index_1.Runtime.Tuple([
157
+ index_1.Runtime.Ref('ExportModifier'), index_1.Runtime.Const('module'), ModuleIdentifier, index_1.Runtime.Const(LBrace), index_1.Runtime.Ref('ModuleProperties'), index_1.Runtime.Const(RBrace)
158
+ ], values => ModuleDeclarationMapping(...values));
159
+ // ------------------------------------------------------------------
36
160
  // Reference
37
161
  // ------------------------------------------------------------------
38
162
  // prettier-ignore
39
- const Reference = index_1.Runtime.Ident((value, context) => {
40
- return value in context ? context[value] : Types.Ref(value);
41
- });
163
+ const Reference = index_1.Runtime.Ident((value, context) => Deref(context, value));
42
164
  // ------------------------------------------------------------------
43
165
  // Literal
44
166
  // ------------------------------------------------------------------
@@ -224,24 +346,21 @@ const Type = index_1.Runtime.Ref('Expr');
224
346
  // ------------------------------------------------------------------
225
347
  // Properties
226
348
  // ------------------------------------------------------------------
227
- // prettier-ignore
228
349
  const PropertyKey = index_1.Runtime.Union([index_1.Runtime.Ident(), index_1.Runtime.String([SingleQuote, DoubleQuote])]);
350
+ const Readonly = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const('readonly')]), index_1.Runtime.Tuple([])], (value) => value.length > 0);
351
+ const Optional = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const(Question)]), index_1.Runtime.Tuple([])], (value) => value.length > 0);
229
352
  // prettier-ignore
230
- const PropertyReadonly = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const('readonly')]), index_1.Runtime.Tuple([])], value => value.length > 0);
231
- // prettier-ignore
232
- const PropertyOptional = index_1.Runtime.Union([index_1.Runtime.Tuple([index_1.Runtime.Const(Question)]), index_1.Runtime.Tuple([])], value => value.length > 0);
233
- // prettier-ignore
234
- const PropertyMapping = (Readonly, Key, Optional, _, Type) => ({
235
- [Key]: (Readonly && Optional ? Types.ReadonlyOptional(Type) :
236
- Readonly && !Optional ? Types.Readonly(Type) :
237
- !Readonly && Optional ? Types.Optional(Type) :
353
+ const PropertyMapping = (IsReadonly, Key, IsOptional, _, Type) => ({
354
+ [Key]: (IsReadonly && IsOptional ? Types.ReadonlyOptional(Type) :
355
+ IsReadonly && !IsOptional ? Types.Readonly(Type) :
356
+ !IsReadonly && IsOptional ? Types.Optional(Type) :
238
357
  Type)
239
358
  });
240
359
  // prettier-ignore
241
360
  const Property = index_1.Runtime.Tuple([
242
- index_1.Runtime.Ref('PropertyReadonly'),
361
+ index_1.Runtime.Ref('Readonly'),
243
362
  index_1.Runtime.Ref('PropertyKey'),
244
- index_1.Runtime.Ref('PropertyOptional'),
363
+ index_1.Runtime.Ref('Optional'),
245
364
  index_1.Runtime.Const(Colon),
246
365
  index_1.Runtime.Ref('Type'),
247
366
  ], value => PropertyMapping(...value));
@@ -259,23 +378,21 @@ const Properties = index_1.Runtime.Union([
259
378
  index_1.Runtime.Tuple([index_1.Runtime.Ref('Property'), index_1.Runtime.Ref('PropertyDelimiter')]),
260
379
  index_1.Runtime.Tuple([index_1.Runtime.Ref('Property')]),
261
380
  index_1.Runtime.Tuple([])
262
- ], values => (values.length === 3 ? [values[0], ...values[2]] :
263
- values.length === 2 ? [values[0]] :
264
- values.length === 1 ? [values[0]] :
265
- []));
381
+ ], values => (values.length === 3 ? { ...values[0], ...values[2] } :
382
+ values.length === 2 ? values[0] :
383
+ values.length === 1 ? values[0] :
384
+ {}));
266
385
  // ------------------------------------------------------------------
267
386
  // Object
268
387
  // ------------------------------------------------------------------
269
388
  // prettier-ignore
270
- const ObjectMapping = (values) => Types.Object(values.reduce((properties, record) => {
271
- return { ...properties, ...record };
272
- }, {}));
389
+ const ObjectMapping = (_0, Properties, _2) => Types.Object(Properties);
273
390
  // prettier-ignore
274
391
  const _Object = index_1.Runtime.Tuple([
275
392
  index_1.Runtime.Const(LBrace),
276
393
  index_1.Runtime.Ref('Properties'),
277
394
  index_1.Runtime.Const(RBrace)
278
- ], values => ObjectMapping(values[1]));
395
+ ], values => ObjectMapping(...values));
279
396
  // ------------------------------------------------------------------
280
397
  // Tuple
281
398
  // ------------------------------------------------------------------
@@ -344,7 +461,15 @@ const MappedMapping = (values) => {
344
461
  };
345
462
  // prettier-ignore
346
463
  const Mapped = index_1.Runtime.Tuple([
347
- index_1.Runtime.Const(LBrace), index_1.Runtime.Const(LBracket), index_1.Runtime.Ident(), index_1.Runtime.Const('in'), index_1.Runtime.Ref('Type'), index_1.Runtime.Const(RBracket), index_1.Runtime.Const(Colon), index_1.Runtime.Ref('Type'), index_1.Runtime.Const(RBrace)
464
+ index_1.Runtime.Const(LBrace),
465
+ index_1.Runtime.Const(LBracket),
466
+ index_1.Runtime.Ident(),
467
+ index_1.Runtime.Const('in'),
468
+ index_1.Runtime.Ref('Type'),
469
+ index_1.Runtime.Const(RBracket),
470
+ index_1.Runtime.Const(Colon),
471
+ index_1.Runtime.Ref('Type'),
472
+ index_1.Runtime.Const(RBrace)
348
473
  ], MappedMapping);
349
474
  // ------------------------------------------------------------------
350
475
  // AsyncIterator
@@ -565,10 +690,34 @@ const Date = index_1.Runtime.Const('Date', index_1.Runtime.As(Types.Date()));
565
690
  // ------------------------------------------------------------------
566
691
  const Uint8Array = index_1.Runtime.Const('Uint8Array', index_1.Runtime.As(Types.Uint8Array()));
567
692
  // ------------------------------------------------------------------
693
+ // Main
694
+ // ------------------------------------------------------------------
695
+ // prettier-ignore
696
+ const Main = index_1.Runtime.Union([
697
+ ModuleDeclaration,
698
+ TypeAliasDeclaration,
699
+ InterfaceDeclaration,
700
+ Type
701
+ ]);
702
+ // ------------------------------------------------------------------
568
703
  // Module
569
704
  // ------------------------------------------------------------------
570
705
  // prettier-ignore
571
706
  exports.Module = new index_1.Runtime.Module({
707
+ // ----------------------------------------------------------------
708
+ // Modules, Interfaces and Type Aliases
709
+ // ----------------------------------------------------------------
710
+ ExportModifier,
711
+ HeritageList,
712
+ Heritage,
713
+ InterfaceDeclaration,
714
+ TypeAliasDeclaration,
715
+ ModuleType,
716
+ ModuleProperties,
717
+ ModuleDeclaration,
718
+ // ----------------------------------------------------------------
719
+ // Type Expressions
720
+ // ----------------------------------------------------------------
572
721
  Literal,
573
722
  Keyword,
574
723
  KeyOf,
@@ -580,10 +729,10 @@ exports.Module = new index_1.Runtime.Module({
580
729
  ExprTerm,
581
730
  ExprTail,
582
731
  Expr,
583
- Type,
732
+ Type, // Alias for Expr
584
733
  PropertyKey,
585
- PropertyReadonly,
586
- PropertyOptional,
734
+ Readonly,
735
+ Optional,
587
736
  Property,
588
737
  PropertyDelimiter,
589
738
  Properties,
@@ -617,5 +766,9 @@ exports.Module = new index_1.Runtime.Module({
617
766
  Uncapitalize,
618
767
  Date,
619
768
  Uint8Array,
620
- Reference
769
+ Reference,
770
+ // ----------------------------------------------------------------
771
+ // Main
772
+ // ----------------------------------------------------------------
773
+ Main
621
774
  });