@player-tools/xlr-converters 0.0.2-next.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.
@@ -0,0 +1,86 @@
1
+ import ts from 'typescript';
2
+ import { NodeType, NamedType, ObjectType, NamedTypeWithGenerics } from '@player-tools/xlr';
3
+ import { TopLevelDeclaration } from '@player-tools/xlr-utils';
4
+
5
+ interface TSConverterContext {
6
+ /** */
7
+ customPrimitives: Array<string>;
8
+ /** */
9
+ typeChecker: ts.TypeChecker;
10
+ /** */
11
+ throwError: (message: string) => never;
12
+ /** Cached conversion operations */
13
+ cache: {
14
+ /** Converted TS Nodes */
15
+ convertedNodes: Map<ts.TypeNode, NodeType | undefined>;
16
+ /** Processed Template Strings */
17
+ convertedTemplates: Map<ts.TemplateLiteralTypeNode, string>;
18
+ };
19
+ }
20
+ /** Converts TS Nodes/Files to XLRs */
21
+ declare class TsConverter {
22
+ private context;
23
+ constructor(typeChecker: ts.TypeChecker, customPrimitives?: Array<string>);
24
+ /** Converts all exported objects to a XLR representation */
25
+ convertSourceFile(sourceFile: ts.SourceFile): {
26
+ data: {
27
+ version: number;
28
+ types: NamedType<NodeType>[];
29
+ };
30
+ convertedTypes: string[];
31
+ };
32
+ /** Converts a single type/interface declaration to XLRs */
33
+ convertDeclaration(node: TopLevelDeclaration): NamedType<ObjectType> | NamedTypeWithGenerics<ObjectType>;
34
+ /** Converts an arbitrary ts.TypeNode to XLRs */
35
+ convertTsTypeNode(node: ts.TypeNode): NodeType | undefined;
36
+ private tsNodeToType;
37
+ private fromTsObjectMembers;
38
+ private fromTsTuple;
39
+ private handleHeritageClauses;
40
+ private solveGenerics;
41
+ private generateGenerics;
42
+ private resolveRefNode;
43
+ }
44
+
45
+ interface ConvertedType {
46
+ /** Converted input type represented as in TS Nodes */
47
+ type: TopLevelDeclaration;
48
+ /** Types that may require import statements to be added */
49
+ referencedTypes?: Set<string>;
50
+ /** Any additionally referenced types that were deserialized that should be separate declarations */
51
+ additionalTypes?: Map<string, TopLevelDeclaration>;
52
+ }
53
+ /** */
54
+ declare class TSWriter {
55
+ private context;
56
+ private importSet;
57
+ private additionalTypes;
58
+ constructor(factory?: ts.NodeFactory);
59
+ convertNamedType(type: NamedType): ConvertedType;
60
+ private convertNamedTypeNode;
61
+ private convertTypeNode;
62
+ private createRefNode;
63
+ private createPrimitiveNode;
64
+ private createLiteralTypeNode;
65
+ private createTupleNode;
66
+ private createFunctionDeclarationNode;
67
+ private createRecordNode;
68
+ private createConditionalTypeNode;
69
+ private createObjectNode;
70
+ private createTemplateLiteral;
71
+ private createGenericArgumentNode;
72
+ private makeAnnotations;
73
+ private createTypeParameters;
74
+ private makeInterfaceDeclaration;
75
+ private makeTypeDeclaration;
76
+ }
77
+
78
+ /**
79
+ * Specific error that can be caught to indicate an error in conversion
80
+ */
81
+ declare class ConversionError extends Error {
82
+ constructor(msg: string);
83
+ toString(): string;
84
+ }
85
+
86
+ export { ConversionError, ConvertedType, TSConverterContext, TSWriter, TsConverter };