|
1 |
| -require('./out.js'); |
| 1 | +require("./out.js"); |
2 | 2 |
|
3 | 3 | export function reflect(declarationBody: string): ReflectionResult {
|
4 |
| - // @ts-expect-error "reflect" is added to self by the "out" module |
5 |
| - return JSON.parse(self.reflect(declarationBody)) as ReflectionResult; |
| 4 | + // @ts-expect-error "reflect" is added to self by the "out" module |
| 5 | + return JSON.parse(self.reflect(declarationBody)) as ReflectionResult; |
| 6 | +} |
| 7 | + |
| 8 | +export async function reflectAsync(declarationBody: string): Promise<ReflectionResult> { |
| 9 | + // @ts-expect-error "reflectAsync" is added to self by the "out" module |
| 10 | + const result = await self.reflectAsync(declarationBody) as string; |
| 11 | + return JSON.parse(result) as ReflectionResult; |
6 | 12 | }
|
7 | 13 |
|
8 | 14 | export interface ParamAnnotation {
|
9 |
| - bodyLines: string[]; |
10 |
| - paramName: string; |
| 15 | + bodyLines: string[]; |
| 16 | + paramName: string; |
11 | 17 | }
|
12 | 18 |
|
13 | 19 | export interface ReturnAnnotation {
|
14 |
| - bodyLines: string[]; |
| 20 | + bodyLines: string[]; |
15 | 21 | }
|
16 | 22 |
|
17 | 23 | export interface ExampleAnnotation {
|
18 |
| - bodyLines: string[]; |
| 24 | + bodyLines: string[]; |
19 | 25 | }
|
20 | 26 |
|
21 | 27 | export interface ThrowsAnnotation {
|
22 |
| - bodyLines: string[]; |
23 |
| - exceptionName: string; |
| 28 | + bodyLines: string[]; |
| 29 | + exceptionName: string; |
24 | 30 | }
|
25 | 31 |
|
26 | 32 | export interface DocCommentAnnotation {
|
27 |
| - name: string; |
28 |
| - bodyLines: string[]; |
29 |
| - body: string; |
| 33 | + name: string; |
| 34 | + bodyLines: string[]; |
| 35 | + body: string; |
30 | 36 | }
|
31 | 37 |
|
32 | 38 | export interface DocComment {
|
33 |
| - rawDeclaration?: string; |
34 |
| - paramAnnotations: ParamAnnotation[]; |
35 |
| - returnAnnotation: ReturnAnnotation | null; |
36 |
| - exampleAnnotation: ExampleAnnotation | null; |
37 |
| - throwsAnnotations: ThrowsAnnotation[]; |
38 |
| - annotations: DocCommentAnnotation[]; |
39 |
| - descriptionLines: string[]; |
40 |
| - description: string; |
41 |
| - error?: string; |
| 39 | + rawDeclaration?: string; |
| 40 | + paramAnnotations: ParamAnnotation[]; |
| 41 | + returnAnnotation: ReturnAnnotation | null; |
| 42 | + exampleAnnotation: ExampleAnnotation | null; |
| 43 | + throwsAnnotations: ThrowsAnnotation[]; |
| 44 | + annotations: DocCommentAnnotation[]; |
| 45 | + descriptionLines: string[]; |
| 46 | + description: string; |
| 47 | + error?: string; |
42 | 48 | }
|
43 | 49 |
|
44 | 50 | export interface AnnotationElementValue {
|
45 |
| - key: string; |
46 |
| - value: string; |
| 51 | + key: string; |
| 52 | + value: string; |
47 | 53 | }
|
48 | 54 |
|
49 | 55 | export interface Annotation {
|
50 |
| - rawDeclaration: string; |
51 |
| - name: string; |
52 |
| - type: string; |
53 |
| - elementValues?: AnnotationElementValue[]; |
| 56 | + rawDeclaration: string; |
| 57 | + name: string; |
| 58 | + type: string; |
| 59 | + elementValues?: AnnotationElementValue[]; |
54 | 60 | }
|
55 | 61 |
|
56 | 62 | export type ReferencedType = ReferenceObjectType | ListObjectType | SetObjectType | MapObjectType | GenericObjectType;
|
57 | 63 |
|
58 | 64 | export interface ReferenceObjectType {
|
59 |
| - type: string; |
60 |
| - rawDeclaration: string; |
| 65 | + type: string; |
| 66 | + rawDeclaration: string; |
61 | 67 | }
|
62 | 68 |
|
63 | 69 | export interface ListObjectType extends ReferenceObjectType {
|
64 |
| - ofType: ReferenceObjectType; |
| 70 | + ofType: ReferenceObjectType; |
65 | 71 | }
|
66 | 72 |
|
67 | 73 | export interface SetObjectType extends ReferenceObjectType {
|
68 |
| - ofType: ReferenceObjectType; |
| 74 | + ofType: ReferenceObjectType; |
69 | 75 | }
|
70 | 76 |
|
71 | 77 | export interface MapObjectType extends ReferenceObjectType {
|
72 |
| - keyType: ReferenceObjectType; |
73 |
| - valueType: ReferenceObjectType; |
| 78 | + keyType: ReferenceObjectType; |
| 79 | + valueType: ReferenceObjectType; |
74 | 80 | }
|
75 | 81 |
|
76 | 82 | export interface GenericObjectType extends ReferenceObjectType {
|
77 |
| - ofType: ReferenceObjectType; |
| 83 | + ofType: ReferenceObjectType; |
78 | 84 | }
|
79 | 85 |
|
80 | 86 | export interface EnumValue {
|
81 |
| - name: string; |
82 |
| - docComment?: DocComment; |
| 87 | + name: string; |
| 88 | + docComment?: DocComment; |
83 | 89 | }
|
84 | 90 |
|
85 | 91 | export interface ParameterMirror {
|
86 |
| - memberModifiers: string[]; |
87 |
| - name: string; |
88 |
| - typeReference: ReferencedType; |
89 |
| - docComment?: DocComment; |
| 92 | + memberModifiers: string[]; |
| 93 | + name: string; |
| 94 | + typeReference: ReferencedType; |
| 95 | + docComment?: DocComment; |
90 | 96 | }
|
91 | 97 |
|
92 | 98 | export interface MethodMirror {
|
93 |
| - access_modifier: string; |
94 |
| - annotations: Annotation[]; |
95 |
| - name: string; |
96 |
| - memberModifiers: string[]; |
97 |
| - typeReference: ReferencedType; |
98 |
| - parameters: ParameterMirror[]; |
99 |
| - docComment?: DocComment; |
100 |
| - group?: string; |
101 |
| - groupDescription?: string; |
| 99 | + access_modifier: string; |
| 100 | + annotations: Annotation[]; |
| 101 | + name: string; |
| 102 | + memberModifiers: string[]; |
| 103 | + typeReference: ReferencedType; |
| 104 | + parameters: ParameterMirror[]; |
| 105 | + docComment?: DocComment; |
| 106 | + group?: string; |
| 107 | + groupDescription?: string; |
102 | 108 | }
|
103 | 109 |
|
104 | 110 | export interface PropertyMirror {
|
105 |
| - access_modifier: string; |
106 |
| - annotations: Annotation[]; |
107 |
| - name: string; |
108 |
| - memberModifiers: string[]; |
109 |
| - typeReference: ReferencedType; |
110 |
| - docComment?: DocComment; |
111 |
| - group?: string; |
112 |
| - groupDescription?: string; |
| 111 | + access_modifier: string; |
| 112 | + annotations: Annotation[]; |
| 113 | + name: string; |
| 114 | + memberModifiers: string[]; |
| 115 | + typeReference: ReferencedType; |
| 116 | + docComment?: DocComment; |
| 117 | + group?: string; |
| 118 | + groupDescription?: string; |
113 | 119 | }
|
114 | 120 |
|
115 | 121 | export interface FieldMirror {
|
116 |
| - access_modifier: string; |
117 |
| - annotations: Annotation[]; |
118 |
| - name: string; |
119 |
| - memberModifiers: string[]; |
120 |
| - typeReference: ReferencedType; |
121 |
| - docComment?: DocComment; |
122 |
| - group?: string; |
123 |
| - groupDescription?: string; |
| 122 | + access_modifier: string; |
| 123 | + annotations: Annotation[]; |
| 124 | + name: string; |
| 125 | + memberModifiers: string[]; |
| 126 | + typeReference: ReferencedType; |
| 127 | + docComment?: DocComment; |
| 128 | + group?: string; |
| 129 | + groupDescription?: string; |
124 | 130 | }
|
125 | 131 |
|
126 | 132 | export interface ConstructorMirror {
|
127 |
| - access_modifier: string; |
128 |
| - annotations: Annotation[]; |
129 |
| - parameters: ParameterMirror[]; |
130 |
| - docComment?: DocComment; |
131 |
| - group?: string; |
132 |
| - groupDescription?: string; |
| 133 | + access_modifier: string; |
| 134 | + annotations: Annotation[]; |
| 135 | + parameters: ParameterMirror[]; |
| 136 | + docComment?: DocComment; |
| 137 | + group?: string; |
| 138 | + groupDescription?: string; |
133 | 139 | }
|
134 | 140 |
|
135 | 141 | export interface ReflectionResult {
|
136 |
| - typeMirror?: Type; |
137 |
| - error?: ParsingError; |
| 142 | + typeMirror?: Type; |
| 143 | + error?: ParsingError; |
138 | 144 | }
|
139 | 145 |
|
140 | 146 | export interface ParsingError {
|
141 |
| - message: string; |
| 147 | + message: string; |
142 | 148 | }
|
143 | 149 |
|
144 | 150 | // Types
|
145 | 151 |
|
146 |
| -type TypeName = 'class' | 'interface' | 'enum'; |
| 152 | +type TypeName = "class" | "interface" | "enum"; |
147 | 153 | export type Type = InterfaceMirror | ClassMirror | EnumMirror;
|
148 | 154 |
|
149 | 155 | export interface EnumMirror {
|
150 |
| - annotations: Annotation[]; |
151 |
| - name: string; |
152 |
| - type_name: TypeName; |
153 |
| - access_modifier: string; |
154 |
| - docComment?: DocComment; |
155 |
| - group?: string; |
156 |
| - groupDescription?: string; |
157 |
| - values: EnumValue[]; |
| 156 | + annotations: Annotation[]; |
| 157 | + name: string; |
| 158 | + type_name: TypeName; |
| 159 | + access_modifier: string; |
| 160 | + docComment?: DocComment; |
| 161 | + group?: string; |
| 162 | + groupDescription?: string; |
| 163 | + values: EnumValue[]; |
158 | 164 | }
|
159 | 165 |
|
160 | 166 | export interface InterfaceMirror {
|
161 |
| - annotations: Annotation[]; |
162 |
| - name: string; |
163 |
| - type_name: TypeName; |
164 |
| - methods: MethodMirror[]; |
165 |
| - extended_interfaces: string[]; |
166 |
| - access_modifier: string; |
167 |
| - docComment?: DocComment; |
168 |
| - sharingModifier?: string; |
169 |
| - group?: string; |
170 |
| - groupDescription?: string; |
| 167 | + annotations: Annotation[]; |
| 168 | + name: string; |
| 169 | + type_name: TypeName; |
| 170 | + methods: MethodMirror[]; |
| 171 | + extended_interfaces: string[]; |
| 172 | + access_modifier: string; |
| 173 | + docComment?: DocComment; |
| 174 | + sharingModifier?: string; |
| 175 | + group?: string; |
| 176 | + groupDescription?: string; |
171 | 177 | }
|
172 | 178 |
|
173 | 179 | export interface ClassMirror {
|
174 |
| - annotations: Annotation[]; |
175 |
| - name: string; |
176 |
| - type_name: TypeName; |
177 |
| - methods: MethodMirror[]; |
178 |
| - sharingModifier?: string; |
179 |
| - classModifier?: string; |
180 |
| - extended_class?: string; |
181 |
| - implemented_interfaces: string[]; |
182 |
| - properties: PropertyMirror[]; |
183 |
| - fields: FieldMirror[]; |
184 |
| - constructors: ConstructorMirror[]; |
185 |
| - enums: EnumMirror[]; |
186 |
| - interfaces: InterfaceMirror[]; |
187 |
| - classes: ClassMirror[]; |
188 |
| - access_modifier: string; |
189 |
| - docComment?: DocComment; |
190 |
| - group?: string; |
191 |
| - groupDescription?: string; |
| 180 | + annotations: Annotation[]; |
| 181 | + name: string; |
| 182 | + type_name: TypeName; |
| 183 | + methods: MethodMirror[]; |
| 184 | + sharingModifier?: string; |
| 185 | + classModifier?: string; |
| 186 | + extended_class?: string; |
| 187 | + implemented_interfaces: string[]; |
| 188 | + properties: PropertyMirror[]; |
| 189 | + fields: FieldMirror[]; |
| 190 | + constructors: ConstructorMirror[]; |
| 191 | + enums: EnumMirror[]; |
| 192 | + interfaces: InterfaceMirror[]; |
| 193 | + classes: ClassMirror[]; |
| 194 | + access_modifier: string; |
| 195 | + docComment?: DocComment; |
| 196 | + group?: string; |
| 197 | + groupDescription?: string; |
192 | 198 | }
|
0 commit comments