UNPKG

13 kBTypeScriptView Raw
1import * as reflect from 'jsii-reflect';
2import { JsiiEntity, TypeSchema } from '../schema';
3/**
4 * Supported languages to generate documentation in.
5 */
6export declare class Language {
7 /**
8 * TypeScript.
9 */
10 static readonly TYPESCRIPT: Language;
11 /**
12 * Python.
13 */
14 static readonly PYTHON: Language;
15 /**
16 * Java.
17 */
18 static readonly JAVA: Language;
19 /**
20 * C#
21 */
22 static readonly CSHARP: Language;
23 /**
24 *
25 * Go
26 */
27 static readonly GO: Language;
28 /**
29 * Transform a literal string to the `Language` object.
30 *
31 * Throws an `UnsupportedLanguageError` if the language is not supported.
32 */
33 static fromString(lang: string): Language;
34 static values(): Language[];
35 readonly name: string;
36 readonly targetName: string;
37 private readonly validator;
38 private constructor();
39 isValidConfiguration(config: Record<string, unknown> | undefined): boolean;
40 toString(): string;
41}
42export declare class UnsupportedLanguageError extends Error {
43 constructor(lang: string, supported: Language[]);
44}
45/**
46 * Outcome of transpiling a jsii struct.
47 */
48export interface TranspiledStruct {
49 /**
50 * The (transpiled) type.
51 */
52 readonly type: TranspiledType;
53 /**
54 * The name.
55 */
56 readonly name: string;
57 /**
58 * The import statement needed in order to use this struct.
59 */
60 readonly import: string;
61 /**
62 * How to initialize this struct.
63 */
64 readonly initialization: string;
65}
66/**
67 * Outcome of transpiling a jsii class.
68 */
69export interface TranspiledClass {
70 /**
71 * The (transpiled) type.
72 */
73 readonly type: TranspiledType;
74 /**
75 * The name.
76 */
77 readonly name: string;
78}
79/**
80 * Outcome of transpiling a jsii callable.
81 */
82export interface TranspiledCallable {
83 /**
84 * The (transpiled) parent type.
85 */
86 readonly parentType: TranspiledType;
87 /**
88 * How a signature of the callable looks like. In some languages
89 * (like Java), a callable may be transliterated to multiple overloaded
90 * methods, so there may be multiple signatures
91 */
92 readonly signatures: string[];
93 /**
94 * The name.
95 */
96 readonly name: string;
97 /**
98 * The import statement needed in order to use this callable.
99 */
100 readonly import: string;
101 /**
102 * How a invocations of this callable look like. In some languages
103 * (like Java), a callable may be transliterated to multiple overloaded
104 * methods, so there may be multiple invocations.
105 */
106 readonly invocations: string[];
107 /**
108 * The jsii parameters this callable accepts.
109 */
110 readonly parameters: reflect.Parameter[];
111 /**
112 * The (transpiled) return type - this is undefined if void or initializer.
113 */
114 readonly returnType?: TranspiledTypeReference;
115}
116/**
117 * Outcome of transpiling a jsii parameter.
118 */
119export interface TranspiledParameter extends TranspiledProperty {
120 /**
121 * Whether or not the parameter is variadic.
122 */
123 readonly variadic: boolean;
124}
125/**
126 * Outcome of transpiling a jsii interface (not data type).
127 */
128export interface TranspiledInterface {
129 /**
130 * The (transpiled) type.
131 */
132 readonly type: TranspiledType;
133 /**
134 * The name.
135 */
136 readonly name: string;
137}
138/**
139 * Outcome of transpiling a generic jsii type.
140 */
141export declare class TranspiledType {
142 /**
143 * The source type this was transliterated from.
144 */
145 readonly source: reflect.Type;
146 /**
147 * The transliteration language.
148 */
149 readonly language: Language;
150 /**
151 * The language specific fqn.
152 */
153 readonly fqn: string;
154 /**
155 * Simple name of the type.
156 */
157 readonly name: string;
158 /**
159 * Namespace of the type.
160 */
161 readonly namespace?: string;
162 /**
163 * The language specific module name the type belongs to.
164 */
165 readonly module: string;
166 /**
167 * The language specific submodule name the type belongs to.
168 */
169 readonly submodule?: string;
170 /**
171 * The language-independent name of the submodule the type belongs to.
172 */
173 readonly submodulePath?: string;
174 constructor(options: {
175 source: reflect.Type;
176 language: Language;
177 fqn: string;
178 name: string;
179 namespace?: string;
180 module: string;
181 submodule?: string;
182 submodulePath?: string;
183 });
184 toJson(): JsiiEntity;
185}
186/**
187 * Options for how to render a string representation of a type reference.
188 */
189export interface TranspiledTypeReferenceToStringOptions {
190 /**
191 * Type formatter.
192 */
193 typeFormatter?: (type: TranspiledType) => string;
194 /**
195 * String formatter.
196 */
197 stringFormatter?: (typeName: string) => string;
198}
199/**
200 * Outcome of transpiling a jsii type reference.
201 */
202export declare class TranspiledTypeReference {
203 /**
204 * A transpiler
205 */
206 private readonly transpile;
207 /**
208 * The original type reference.
209 */
210 private readonly ref;
211 /**
212 * Primitive type ref.
213 */
214 private readonly primitive?;
215 /**
216 * 'Any' type ref
217 */
218 private readonly isAny?;
219 /**
220 * Concrete type.
221 */
222 private readonly type?;
223 /**
224 * Array of ref.
225 */
226 private readonly arrayOfType?;
227 /**
228 * Map of ref.
229 */
230 private readonly mapOfType?;
231 /**
232 * Union of ref.
233 */
234 private readonly unionOfTypes?;
235 /**
236 * 'Void' type ref.
237 */
238 private readonly isVoid?;
239 /**
240 * Create a type reference that represents a primitive.
241 */
242 static primitive(transpile: Transpile, ref: reflect.TypeReference, primitive: string): TranspiledTypeReference;
243 /**
244 * Create a type reference that represents any type.
245 */
246 static any(transpile: Transpile, ref: reflect.TypeReference): TranspiledTypeReference;
247 /**
248 * Create a type reference that represents the void (return) type.
249 */
250 static void(transpile: Transpile, ref: reflect.TypeReference): TranspiledTypeReference;
251 /**
252 * Create a type reference that represents a concrete type.
253 */
254 static type(transpile: Transpile, ref: reflect.TypeReference, type: TranspiledType): TranspiledTypeReference;
255 /**
256 * Create a type reference that represents an array of a type reference.
257 */
258 static arrayOfType(transpile: Transpile, ref: reflect.TypeReference, tf: TranspiledTypeReference): TranspiledTypeReference;
259 /**
260 * Create a type reference that represents a map of a type reference.
261 */
262 static mapOfType(transpile: Transpile, ref: reflect.TypeReference, tf: TranspiledTypeReference): TranspiledTypeReference;
263 /**
264 * Create a type reference that represents a union of a type references.
265 */
266 static unionOfTypes(transpile: Transpile, ref: reflect.TypeReference, tfs: TranspiledTypeReference[]): TranspiledTypeReference;
267 private constructor();
268 toString(options?: TranspiledTypeReferenceToStringOptions): string;
269 toJson(): TypeSchema;
270}
271/**
272 * Outcome of transpiling a jsii property.
273 */
274export interface TranspiledProperty {
275 /**
276 * The name.
277 */
278 readonly name: string;
279 /**
280 * The (transpiled) parent type.
281 */
282 readonly parentType: TranspiledType;
283 /**
284 * The (transpiled) type reference.
285 */
286 readonly typeReference: TranspiledTypeReference;
287 /**
288 * Whether or not the parameter is optional.
289 */
290 readonly optional: boolean;
291 /**
292 * The signature of the property, or its getter if the language
293 * supports that.
294 */
295 readonly declaration: string;
296}
297/**
298 * Outcome of transpiling a jsii enum.
299 */
300export interface TranspiledEnum {
301 /**
302 * The language specific fqn.
303 */
304 readonly fqn: string;
305 /**
306 * The name.
307 */
308 readonly name: string;
309}
310/**
311 * Outcome of transpiling a specific enum member.
312 */
313export interface TranspiledEnumMember {
314 /**
315 * The language specific fqn.
316 */
317 readonly fqn: string;
318 /**
319 * The name.
320 */
321 readonly name: string;
322}
323/**
324 * Outcome of transpiling a module like object. (Assembly | Submodule)
325 */
326export interface TranspiledModuleLike {
327 /**
328 * The language specific module name.
329 *
330 * In case the module like object is a submodule, this should contain
331 * only the root module name.
332 *
333 * In case the module like object is the root module, this should contain
334 * the module fqn.
335 *
336 * Examples:
337 *
338 * `aws-cdk-lib` -> `aws_cdk`
339 * `aws-cdk-lib.aws_eks` -> `aws_cdk`
340 * `@aws-cdk/aws-eks` -> `aws_cdk.aws_eks`
341 */
342 readonly name: string;
343 /**
344 * The language specific submodule name.
345 *
346 * In case the module like object is a submodule, this should contain
347 * only the submodule name.
348 *
349 * In case the module like object is the root module, this should be undefined
350 *
351 * Examples:
352 *
353 * `aws-cdk-lib` -> undefined
354 * `aws-cdk-lib.aws_eks` -> `aws_eks`
355 * `@aws-cdk/aws-eks` -> undefined
356 */
357 readonly submodule?: string;
358}
359/**
360 * Language transpiling for jsii types.
361 */
362export interface Transpile {
363 /**
364 * The language of the transpiler.
365 */
366 readonly language: Language;
367 /**
368 * How links to types should be formatted.
369 *
370 * @default '#{fqn}'
371 */
372 readonly linkFormatter?: (type: TranspiledType) => string;
373 /**
374 * Transpile a module like object (Assembly | Submodule)
375 */
376 moduleLike(moduleLike: reflect.ModuleLike): TranspiledModuleLike;
377 /**
378 * Transpile a callable (method, static function, initializer).
379 * In some languages such as Java, a single callable may generate multiple
380 * overloaded methods to support optional parameters.
381 */
382 callable(callable: reflect.Callable): TranspiledCallable;
383 /**
384 * Transpile a class.
385 */
386 class(klass: reflect.ClassType): TranspiledClass;
387 /**
388 * Transpile a struct (data type interface).
389 */
390 struct(struct: reflect.InterfaceType): TranspiledStruct;
391 /**
392 * Transpile an interface (non data type).
393 */
394 interface(iface: reflect.InterfaceType): TranspiledInterface;
395 /**
396 * Transpile a parameter.
397 */
398 parameter(parameter: reflect.Parameter): TranspiledParameter;
399 /**
400 * Transpile a property.
401 */
402 property(property: reflect.Property): TranspiledProperty;
403 /**
404 * Transpile an enum.
405 */
406 enum(enu: reflect.EnumType): TranspiledEnum;
407 /**
408 * Transpile an enum member.
409 */
410 enumMember(em: reflect.EnumMember): TranspiledEnumMember;
411 /**
412 * Transpile a type.
413 */
414 type(type: reflect.Type): TranspiledType;
415 /**
416 * Transpile (recursively) a type reference.
417 */
418 typeReference(typeReference: reflect.TypeReference): TranspiledTypeReference;
419 /**
420 * How a union looks like in the target language.
421 */
422 unionOf(types: string[]): string;
423 /**
424 * How a variadic parameter looks in the target language.
425 */
426 variadicOf(type: string): string;
427 /**
428 * How a list looks like in the target language.
429 */
430 listOf(type: string): string;
431 /**
432 * How a map looks like in the target language.
433 */
434 mapOf(type: string): string;
435 /**
436 * How the 'any' type is represented in the target language.
437 */
438 any(): string;
439 /**
440 * How the 'void' (return) type is represented in the target language.
441 */
442 void(): string;
443 /**
444 * How the 'string' type is represented in the target language.
445 */
446 str(): string;
447 /**
448 * How the 'number' type is represented in the target language.
449 */
450 number(): string;
451 /**
452 * How the 'boolean' type is represented in the target language.
453 */
454 boolean(): string;
455 /**
456 * How the 'json' type is represented in the target language.
457 */
458 json(): string;
459 /**
460 * How the 'date' type is represented in the target language.
461 */
462 date(): string;
463 /**
464 * How a readme is displayed in the target language.
465 */
466 readme(readme: string): string;
467}
468export interface TranspileBase extends Transpile {
469}
470/**
471 * Common functionality between different transpilers.
472 */
473export declare abstract class TranspileBase implements Transpile {
474 readonly language: Language;
475 private readonly parentModulesCache;
476 private readonly submodulesCache;
477 constructor(language: Language);
478 typeReference(ref: reflect.TypeReference): TranspiledTypeReference;
479 protected findSubmodule(type: reflect.Type): reflect.Submodule | undefined;
480 protected getParentModule(moduleLike: reflect.ModuleLike): reflect.Assembly;
481 protected optionalityCompare(p1: reflect.Parameter, p2: reflect.Parameter): number;
482}
483/**
484 * Return the root-relative name for a submodule
485 *
486 * Ex: for a submodule `asm.sub1.sub2`, return `sub1.sub2`.
487 */
488export declare function submoduleRelName(submodule: reflect.Submodule): string;