@sinclair/typebox 0.33.22 → 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.
- package/build/cjs/compiler/compiler.d.ts +2 -2
- package/build/cjs/compiler/compiler.js +13 -2
- package/build/cjs/errors/errors.js +7 -0
- package/build/cjs/index.d.ts +1 -2
- package/build/cjs/index.js +1 -2
- package/build/cjs/syntax/parse.d.ts +14 -15
- package/build/cjs/syntax/parse.js +6 -5
- package/build/cjs/syntax/runtime.d.ts +17 -4
- package/build/cjs/syntax/runtime.js +180 -27
- package/build/cjs/syntax/static.d.ts +104 -20
- package/build/cjs/type/guard/kind.d.ts +3 -0
- package/build/cjs/type/guard/kind.js +5 -0
- package/build/cjs/type/guard/type.d.ts +3 -0
- package/build/cjs/type/guard/type.js +13 -0
- package/build/cjs/type/index.d.ts +1 -2
- package/build/cjs/type/index.js +1 -2
- package/build/cjs/type/module/index.d.ts +1 -0
- package/build/cjs/type/{strict → module}/index.js +1 -1
- package/build/cjs/type/module/module.d.ts +71 -0
- package/build/cjs/type/module/module.js +34 -0
- package/build/cjs/type/ref/ref.d.ts +4 -7
- package/build/cjs/type/ref/ref.js +3 -11
- package/build/cjs/type/static/static.d.ts +1 -1
- package/build/cjs/type/type/json.d.ts +4 -17
- package/build/cjs/type/type/json.js +52 -68
- package/build/cjs/type/type/type.d.ts +1 -2
- package/build/cjs/type/type/type.js +55 -57
- package/build/cjs/value/cast/cast.js +8 -1
- package/build/cjs/value/check/check.js +8 -1
- package/build/cjs/value/clean/clean.js +8 -1
- package/build/cjs/value/convert/convert.js +7 -0
- package/build/cjs/value/create/create.js +7 -0
- package/build/cjs/value/default/default.js +7 -0
- package/build/cjs/value/transform/decode.js +11 -0
- package/build/cjs/value/transform/encode.js +11 -0
- package/build/esm/compiler/compiler.d.mts +2 -2
- package/build/esm/compiler/compiler.mjs +13 -2
- package/build/esm/errors/errors.mjs +7 -0
- package/build/esm/index.d.mts +1 -2
- package/build/esm/index.mjs +1 -2
- package/build/esm/syntax/parse.d.mts +14 -15
- package/build/esm/syntax/parse.mjs +6 -5
- package/build/esm/syntax/runtime.d.mts +17 -4
- package/build/esm/syntax/runtime.mjs +180 -27
- package/build/esm/syntax/static.d.mts +104 -20
- package/build/esm/type/guard/kind.d.mts +3 -0
- package/build/esm/type/guard/kind.mjs +4 -0
- package/build/esm/type/guard/type.d.mts +3 -0
- package/build/esm/type/guard/type.mjs +12 -0
- package/build/esm/type/index.d.mts +1 -2
- package/build/esm/type/index.mjs +1 -2
- package/build/esm/type/module/index.d.mts +1 -0
- package/build/esm/type/module/index.mjs +1 -0
- package/build/esm/type/module/module.d.mts +71 -0
- package/build/esm/type/module/module.mjs +28 -0
- package/build/esm/type/ref/ref.d.mts +4 -7
- package/build/esm/type/ref/ref.mjs +3 -11
- package/build/esm/type/static/static.d.mts +1 -1
- package/build/esm/type/type/json.d.mts +4 -17
- package/build/esm/type/type/json.mjs +7 -23
- package/build/esm/type/type/type.d.mts +1 -2
- package/build/esm/type/type/type.mjs +1 -2
- package/build/esm/value/cast/cast.mjs +9 -2
- package/build/esm/value/check/check.mjs +9 -2
- package/build/esm/value/clean/clean.mjs +9 -2
- package/build/esm/value/convert/convert.mjs +7 -0
- package/build/esm/value/create/create.mjs +7 -0
- package/build/esm/value/default/default.mjs +7 -0
- package/build/esm/value/transform/decode.mjs +11 -0
- package/build/esm/value/transform/encode.mjs +11 -0
- package/package.json +1 -1
- package/readme.md +219 -97
- package/build/cjs/type/deref/deref.d.ts +0 -22
- package/build/cjs/type/deref/deref.js +0 -106
- package/build/cjs/type/deref/index.d.ts +0 -1
- package/build/cjs/type/deref/index.js +0 -18
- package/build/cjs/type/strict/index.d.ts +0 -1
- package/build/cjs/type/strict/strict.d.ts +0 -12
- package/build/cjs/type/strict/strict.js +0 -16
- package/build/esm/type/deref/deref.d.mts +0 -22
- package/build/esm/type/deref/deref.mjs +0 -102
- package/build/esm/type/deref/index.d.mts +0 -1
- package/build/esm/type/deref/index.mjs +0 -1
- package/build/esm/type/strict/index.d.mts +0 -1
- package/build/esm/type/strict/index.mjs +0 -1
- package/build/esm/type/strict/strict.d.mts +0 -12
- package/build/esm/type/strict/strict.mjs +0 -12
|
@@ -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 =
|
|
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
|
|
383
|
-
|
|
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':
|
package/build/cjs/index.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ export * from './type/const/index';
|
|
|
18
18
|
export * from './type/constructor/index';
|
|
19
19
|
export * from './type/constructor-parameters/index';
|
|
20
20
|
export * from './type/date/index';
|
|
21
|
-
export * from './type/deref/index';
|
|
22
21
|
export * from './type/enum/index';
|
|
23
22
|
export * from './type/exclude/index';
|
|
24
23
|
export * from './type/extends/index';
|
|
@@ -32,6 +31,7 @@ export * from './type/iterator/index';
|
|
|
32
31
|
export * from './type/intrinsic/index';
|
|
33
32
|
export * from './type/keyof/index';
|
|
34
33
|
export * from './type/literal/index';
|
|
34
|
+
export * from './type/module/index';
|
|
35
35
|
export * from './type/mapped/index';
|
|
36
36
|
export * from './type/never/index';
|
|
37
37
|
export * from './type/not/index';
|
|
@@ -55,7 +55,6 @@ export * from './type/rest/index';
|
|
|
55
55
|
export * from './type/return-type/index';
|
|
56
56
|
export * from './type/schema/index';
|
|
57
57
|
export * from './type/static/index';
|
|
58
|
-
export * from './type/strict/index';
|
|
59
58
|
export * from './type/string/index';
|
|
60
59
|
export * from './type/symbol/index';
|
|
61
60
|
export * from './type/template-literal/index';
|
package/build/cjs/index.js
CHANGED
|
@@ -41,7 +41,6 @@ __exportStar(require("./type/const/index"), exports);
|
|
|
41
41
|
__exportStar(require("./type/constructor/index"), exports);
|
|
42
42
|
__exportStar(require("./type/constructor-parameters/index"), exports);
|
|
43
43
|
__exportStar(require("./type/date/index"), exports);
|
|
44
|
-
__exportStar(require("./type/deref/index"), exports);
|
|
45
44
|
__exportStar(require("./type/enum/index"), exports);
|
|
46
45
|
__exportStar(require("./type/exclude/index"), exports);
|
|
47
46
|
__exportStar(require("./type/extends/index"), exports);
|
|
@@ -55,6 +54,7 @@ __exportStar(require("./type/iterator/index"), exports);
|
|
|
55
54
|
__exportStar(require("./type/intrinsic/index"), exports);
|
|
56
55
|
__exportStar(require("./type/keyof/index"), exports);
|
|
57
56
|
__exportStar(require("./type/literal/index"), exports);
|
|
57
|
+
__exportStar(require("./type/module/index"), exports);
|
|
58
58
|
__exportStar(require("./type/mapped/index"), exports);
|
|
59
59
|
__exportStar(require("./type/never/index"), exports);
|
|
60
60
|
__exportStar(require("./type/not/index"), exports);
|
|
@@ -78,7 +78,6 @@ __exportStar(require("./type/rest/index"), exports);
|
|
|
78
78
|
__exportStar(require("./type/return-type/index"), exports);
|
|
79
79
|
__exportStar(require("./type/schema/index"), exports);
|
|
80
80
|
__exportStar(require("./type/static/index"), exports);
|
|
81
|
-
__exportStar(require("./type/strict/index"), exports);
|
|
82
81
|
__exportStar(require("./type/string/index"), exports);
|
|
83
82
|
__exportStar(require("./type/symbol/index"), exports);
|
|
84
83
|
__exportStar(require("./type/template-literal/index"), exports);
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import * as Types from '../type/index';
|
|
1
2
|
import { Static } from './parsebox/index';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** `[
|
|
6
|
-
export type
|
|
7
|
-
/** `[
|
|
8
|
-
export
|
|
9
|
-
/** `[
|
|
10
|
-
export declare function Parse<
|
|
11
|
-
/** `[
|
|
12
|
-
export declare function
|
|
13
|
-
/** `[
|
|
14
|
-
export declare function ParseOnly<
|
|
15
|
-
/** `[Experimental]` Parses a TypeBox TSchema from TypeScript syntax */
|
|
16
|
-
export declare function ParseOnly<Code extends string>(code: Code, options?: SchemaOptions): TSchema | undefined;
|
|
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
|
|
6
|
+
const Types = require("../type/index");
|
|
7
7
|
const runtime_1 = require("./runtime");
|
|
8
|
-
/** `[
|
|
8
|
+
/** `[Syntax]` Parses a TypeBox type from TypeScript syntax. */
|
|
9
9
|
function Parse(...args) {
|
|
10
10
|
return ParseOnly.apply(null, args);
|
|
11
11
|
}
|
|
12
|
-
/** `[
|
|
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('
|
|
17
|
-
return
|
|
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
|
-
|
|
18
|
-
|
|
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<
|
|
24
|
-
Object: Runtime.ITuple<Types.TObject<
|
|
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
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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('
|
|
361
|
+
index_1.Runtime.Ref('Readonly'),
|
|
243
362
|
index_1.Runtime.Ref('PropertyKey'),
|
|
244
|
-
index_1.Runtime.Ref('
|
|
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 ?
|
|
263
|
-
values.length === 2 ?
|
|
264
|
-
values.length === 1 ?
|
|
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 = (
|
|
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
|
|
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),
|
|
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
|
-
|
|
586
|
-
|
|
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
|
});
|