@ahoo-wang/wow-generator 9.2.0-rc.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/LICENSE +201 -0
- package/README.md +177 -0
- package/README.zh-CN.md +149 -0
- package/dist/analysis/aggregates.d.cts +21 -0
- package/dist/analysis/aggregates.d.ts +21 -0
- package/dist/analysis/analyze.d.cts +18 -0
- package/dist/analysis/analyze.d.ts +18 -0
- package/dist/analysis/apiClients.d.cts +14 -0
- package/dist/analysis/apiClients.d.ts +14 -0
- package/dist/analysis/clientNames.d.cts +55 -0
- package/dist/analysis/clientNames.d.ts +55 -0
- package/dist/analysis/model.d.cts +212 -0
- package/dist/analysis/model.d.ts +212 -0
- package/dist/analysis/modelInfo.d.cts +23 -0
- package/dist/analysis/modelInfo.d.ts +23 -0
- package/dist/analysis/models.d.cts +17 -0
- package/dist/analysis/models.d.ts +17 -0
- package/dist/api/configuration.d.cts +30 -0
- package/dist/api/configuration.d.ts +30 -0
- package/dist/api/errors.d.cts +41 -0
- package/dist/api/errors.d.ts +41 -0
- package/dist/api/logger.d.cts +61 -0
- package/dist/api/logger.d.ts +61 -0
- package/dist/api/options.d.cts +47 -0
- package/dist/api/options.d.ts +47 -0
- package/dist/cli/program.d.cts +35 -0
- package/dist/cli/program.d.ts +35 -0
- package/dist/cli/runGenerate.d.cts +65 -0
- package/dist/cli/runGenerate.d.ts +65 -0
- package/dist/cli.cjs +3 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +6 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +98 -0
- package/dist/cli.js.map +1 -0
- package/dist/codeGenerator-DpDTDC4o.cjs +23 -0
- package/dist/codeGenerator-DpDTDC4o.cjs.map +1 -0
- package/dist/codeGenerator-kyY9eLML.js +2583 -0
- package/dist/codeGenerator-kyY9eLML.js.map +1 -0
- package/dist/emit/importRegistry.d.cts +50 -0
- package/dist/emit/importRegistry.d.ts +50 -0
- package/dist/emit/imports.d.cts +49 -0
- package/dist/emit/imports.d.ts +49 -0
- package/dist/emit/jsdoc.d.cts +38 -0
- package/dist/emit/jsdoc.d.ts +38 -0
- package/dist/emit/moduleBuilder.d.cts +80 -0
- package/dist/emit/moduleBuilder.d.ts +80 -0
- package/dist/emitters/apiClients.d.cts +10 -0
- package/dist/emitters/apiClients.d.ts +10 -0
- package/dist/emitters/commandClients.d.cts +14 -0
- package/dist/emitters/commandClients.d.ts +14 -0
- package/dist/emitters/decorators.d.cts +83 -0
- package/dist/emitters/decorators.d.ts +83 -0
- package/dist/emitters/emit.d.cts +15 -0
- package/dist/emitters/emit.d.ts +15 -0
- package/dist/emitters/indexFiles.d.cts +12 -0
- package/dist/emitters/indexFiles.d.ts +12 -0
- package/dist/emitters/models.d.cts +77 -0
- package/dist/emitters/models.d.ts +77 -0
- package/dist/emitters/queryClients.d.cts +11 -0
- package/dist/emitters/queryClients.d.ts +11 -0
- package/dist/emitters/target.d.cts +14 -0
- package/dist/emitters/target.d.ts +14 -0
- package/dist/finalize/finalize.d.cts +16 -0
- package/dist/finalize/finalize.d.ts +16 -0
- package/dist/finalize/typeOnlyImports.d.cts +13 -0
- package/dist/finalize/typeOnlyImports.d.ts +13 -0
- package/dist/finalize/verification.d.cts +14 -0
- package/dist/finalize/verification.d.ts +14 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +2 -0
- package/dist/input/configuration.d.cts +87 -0
- package/dist/input/configuration.d.ts +87 -0
- package/dist/input/parsers.d.cts +39 -0
- package/dist/input/parsers.d.ts +39 -0
- package/dist/input/resources.d.cts +36 -0
- package/dist/input/resources.d.ts +36 -0
- package/dist/naming/modelInfo.d.cts +10 -0
- package/dist/naming/modelInfo.d.ts +10 -0
- package/dist/naming/naming.d.cts +102 -0
- package/dist/naming/naming.d.ts +102 -0
- package/dist/naming/order.d.cts +2 -0
- package/dist/naming/order.d.ts +2 -0
- package/dist/naming/paths.d.cts +27 -0
- package/dist/naming/paths.d.ts +27 -0
- package/dist/openapi/components.d.cts +55 -0
- package/dist/openapi/components.d.ts +55 -0
- package/dist/openapi/document.d.cts +25 -0
- package/dist/openapi/document.d.ts +25 -0
- package/dist/openapi/operations.d.cts +78 -0
- package/dist/openapi/operations.d.ts +78 -0
- package/dist/openapi/references.d.cts +28 -0
- package/dist/openapi/references.d.ts +28 -0
- package/dist/openapi/responses.d.cts +44 -0
- package/dist/openapi/responses.d.ts +44 -0
- package/dist/openapi/schemas.d.cts +112 -0
- package/dist/openapi/schemas.d.ts +112 -0
- package/dist/output/outputStore.d.cts +92 -0
- package/dist/output/outputStore.d.ts +92 -0
- package/dist/pipeline/codeGenerator.d.cts +61 -0
- package/dist/pipeline/codeGenerator.d.ts +61 -0
- package/dist/pipeline/seams.d.cts +29 -0
- package/dist/pipeline/seams.d.ts +29 -0
- package/dist/types/typeResolver.d.cts +124 -0
- package/dist/types/typeResolver.d.ts +124 -0
- package/dist/version.d.cts +2 -0
- package/dist/version.d.ts +2 -0
- package/dist/wow/conventions.d.cts +154 -0
- package/dist/wow/conventions.d.ts +154 -0
- package/dist/wow/model.d.cts +116 -0
- package/dist/wow/model.d.ts +116 -0
- package/dist/wow/resolveWowModel.d.cts +21 -0
- package/dist/wow/resolveWowModel.d.ts +21 -0
- package/package.json +108 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ImportDeclarationStructure, OptionalKind } from 'ts-morph';
|
|
2
|
+
/** A name one module imports from another, under an alias or its own name. */
|
|
3
|
+
export interface NamedImport {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
alias?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The imports of one generated module, kept in memory until the module is
|
|
9
|
+
* written.
|
|
10
|
+
*
|
|
11
|
+
* Declarations stay in the order their modules were first imported, and
|
|
12
|
+
* names in the order they were first asked for, as the file would have
|
|
13
|
+
* received them one by one; `organizeImports` sorts them when the file is
|
|
14
|
+
* finished.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ImportRegistry {
|
|
17
|
+
private readonly declarations;
|
|
18
|
+
/**
|
|
19
|
+
* Imports names from a module, keeping the ones it already imports.
|
|
20
|
+
*
|
|
21
|
+
* @param moduleSpecifier - The module to import from
|
|
22
|
+
* @param names - The names to import
|
|
23
|
+
* @returns The names the module now imports
|
|
24
|
+
*/
|
|
25
|
+
add(moduleSpecifier: string, names: readonly string[]): readonly NamedImport[];
|
|
26
|
+
/**
|
|
27
|
+
* Applies imports a resolved type asks for, in order: each name is
|
|
28
|
+
* imported, and takes the alias the request gives it.
|
|
29
|
+
*
|
|
30
|
+
* @param requests - The imports, as `types/typeResolver.ts` returns them
|
|
31
|
+
*/
|
|
32
|
+
apply(requests: readonly {
|
|
33
|
+
moduleSpecifier: string;
|
|
34
|
+
name: string;
|
|
35
|
+
alias?: string;
|
|
36
|
+
}[]): void;
|
|
37
|
+
/** Every name imported, with its module and alias, in the order first asked for. */
|
|
38
|
+
entries(): {
|
|
39
|
+
moduleSpecifier: string;
|
|
40
|
+
name: string;
|
|
41
|
+
alias?: string;
|
|
42
|
+
}[];
|
|
43
|
+
/**
|
|
44
|
+
* The local names every import binds, the ones of `except` aside: an
|
|
45
|
+
* alias where it has one, else the name.
|
|
46
|
+
*/
|
|
47
|
+
localNames(except?: NamedImport): string[];
|
|
48
|
+
/** The import declarations, in the order they were first asked for. */
|
|
49
|
+
structures(): OptionalKind<ImportDeclarationStructure>[];
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ImportDeclarationStructure, OptionalKind } from 'ts-morph';
|
|
2
|
+
/** A name one module imports from another, under an alias or its own name. */
|
|
3
|
+
export interface NamedImport {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
alias?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The imports of one generated module, kept in memory until the module is
|
|
9
|
+
* written.
|
|
10
|
+
*
|
|
11
|
+
* Declarations stay in the order their modules were first imported, and
|
|
12
|
+
* names in the order they were first asked for, as the file would have
|
|
13
|
+
* received them one by one; `organizeImports` sorts them when the file is
|
|
14
|
+
* finished.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ImportRegistry {
|
|
17
|
+
private readonly declarations;
|
|
18
|
+
/**
|
|
19
|
+
* Imports names from a module, keeping the ones it already imports.
|
|
20
|
+
*
|
|
21
|
+
* @param moduleSpecifier - The module to import from
|
|
22
|
+
* @param names - The names to import
|
|
23
|
+
* @returns The names the module now imports
|
|
24
|
+
*/
|
|
25
|
+
add(moduleSpecifier: string, names: readonly string[]): readonly NamedImport[];
|
|
26
|
+
/**
|
|
27
|
+
* Applies imports a resolved type asks for, in order: each name is
|
|
28
|
+
* imported, and takes the alias the request gives it.
|
|
29
|
+
*
|
|
30
|
+
* @param requests - The imports, as `types/typeResolver.ts` returns them
|
|
31
|
+
*/
|
|
32
|
+
apply(requests: readonly {
|
|
33
|
+
moduleSpecifier: string;
|
|
34
|
+
name: string;
|
|
35
|
+
alias?: string;
|
|
36
|
+
}[]): void;
|
|
37
|
+
/** Every name imported, with its module and alias, in the order first asked for. */
|
|
38
|
+
entries(): {
|
|
39
|
+
moduleSpecifier: string;
|
|
40
|
+
name: string;
|
|
41
|
+
alias?: string;
|
|
42
|
+
}[];
|
|
43
|
+
/**
|
|
44
|
+
* The local names every import binds, the ones of `except` aside: an
|
|
45
|
+
* alias where it has one, else the name.
|
|
46
|
+
*/
|
|
47
|
+
localNames(except?: NamedImport): string[];
|
|
48
|
+
/** The import declarations, in the order they were first asked for. */
|
|
49
|
+
structures(): OptionalKind<ImportDeclarationStructure>[];
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ModelInfo } from '../naming/modelInfo.cjs';
|
|
2
|
+
import { NamedImport } from './importRegistry.cjs';
|
|
3
|
+
import { ModuleBuilder } from './moduleBuilder.cjs';
|
|
4
|
+
/**
|
|
5
|
+
* Adds named imports to a module.
|
|
6
|
+
* @param module - The module to modify
|
|
7
|
+
* @param moduleSpecifier - The module to import from
|
|
8
|
+
* @param namedImports - Array of named imports to add
|
|
9
|
+
* @returns The names the module now imports from `moduleSpecifier`
|
|
10
|
+
*/
|
|
11
|
+
export declare function addImport(module: ModuleBuilder, moduleSpecifier: string, namedImports: string[]): readonly NamedImport[];
|
|
12
|
+
/**
|
|
13
|
+
* Adds an import for a referenced model.
|
|
14
|
+
* @param module - The module to modify
|
|
15
|
+
* @param outputDir - The output directory
|
|
16
|
+
* @param refModelInfo - The referenced model information
|
|
17
|
+
*/
|
|
18
|
+
export declare function addImportRefModel(module: ModuleBuilder, outputDir: string, refModelInfo: ModelInfo): readonly NamedImport[];
|
|
19
|
+
/**
|
|
20
|
+
* The specifier a module imports a model by: the package of a model imported
|
|
21
|
+
* from one (a path starting with `@`), else the relative path of the
|
|
22
|
+
* `types.ts` that declares it.
|
|
23
|
+
*
|
|
24
|
+
* @param module - The importing module
|
|
25
|
+
* @param outputDir - The output directory
|
|
26
|
+
* @param model - The model
|
|
27
|
+
*/
|
|
28
|
+
export declare function modelModuleSpecifier(module: ModuleBuilder, outputDir: string, model: ModelInfo): string;
|
|
29
|
+
/**
|
|
30
|
+
* The specifier a source file imports another generated file by.
|
|
31
|
+
*
|
|
32
|
+
* Relative specifiers carry the `.js` extension, which every module
|
|
33
|
+
* resolution TypeScript offers accepts for a `.ts` file: `NodeNext` and
|
|
34
|
+
* `Node16` require it, and `bundler` and `node10` map it back to the source.
|
|
35
|
+
*
|
|
36
|
+
* @param fromDirectory - The directory of the importing file
|
|
37
|
+
* @param targetFilePath - The imported `.ts` file, or a directory holding an `index.ts`
|
|
38
|
+
* @returns A specifier starting with `./` or `../` and ending with `.js`
|
|
39
|
+
*/
|
|
40
|
+
export declare function relativeModuleSpecifier(fromDirectory: string, targetFilePath: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Imports a bounded context's alias constant into a generated file.
|
|
43
|
+
*
|
|
44
|
+
* @param module - The importing module
|
|
45
|
+
* @param outputDir - The output directory
|
|
46
|
+
* @param contextAlias - The bounded context alias
|
|
47
|
+
* @param declarationName - The name of the alias constant
|
|
48
|
+
*/
|
|
49
|
+
export declare function addImportBoundedContext(module: ModuleBuilder, outputDir: string, contextAlias: string, declarationName: string): readonly NamedImport[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ModelInfo } from '../naming/modelInfo.js';
|
|
2
|
+
import { NamedImport } from './importRegistry.js';
|
|
3
|
+
import { ModuleBuilder } from './moduleBuilder.js';
|
|
4
|
+
/**
|
|
5
|
+
* Adds named imports to a module.
|
|
6
|
+
* @param module - The module to modify
|
|
7
|
+
* @param moduleSpecifier - The module to import from
|
|
8
|
+
* @param namedImports - Array of named imports to add
|
|
9
|
+
* @returns The names the module now imports from `moduleSpecifier`
|
|
10
|
+
*/
|
|
11
|
+
export declare function addImport(module: ModuleBuilder, moduleSpecifier: string, namedImports: string[]): readonly NamedImport[];
|
|
12
|
+
/**
|
|
13
|
+
* Adds an import for a referenced model.
|
|
14
|
+
* @param module - The module to modify
|
|
15
|
+
* @param outputDir - The output directory
|
|
16
|
+
* @param refModelInfo - The referenced model information
|
|
17
|
+
*/
|
|
18
|
+
export declare function addImportRefModel(module: ModuleBuilder, outputDir: string, refModelInfo: ModelInfo): readonly NamedImport[];
|
|
19
|
+
/**
|
|
20
|
+
* The specifier a module imports a model by: the package of a model imported
|
|
21
|
+
* from one (a path starting with `@`), else the relative path of the
|
|
22
|
+
* `types.ts` that declares it.
|
|
23
|
+
*
|
|
24
|
+
* @param module - The importing module
|
|
25
|
+
* @param outputDir - The output directory
|
|
26
|
+
* @param model - The model
|
|
27
|
+
*/
|
|
28
|
+
export declare function modelModuleSpecifier(module: ModuleBuilder, outputDir: string, model: ModelInfo): string;
|
|
29
|
+
/**
|
|
30
|
+
* The specifier a source file imports another generated file by.
|
|
31
|
+
*
|
|
32
|
+
* Relative specifiers carry the `.js` extension, which every module
|
|
33
|
+
* resolution TypeScript offers accepts for a `.ts` file: `NodeNext` and
|
|
34
|
+
* `Node16` require it, and `bundler` and `node10` map it back to the source.
|
|
35
|
+
*
|
|
36
|
+
* @param fromDirectory - The directory of the importing file
|
|
37
|
+
* @param targetFilePath - The imported `.ts` file, or a directory holding an `index.ts`
|
|
38
|
+
* @returns A specifier starting with `./` or `../` and ending with `.js`
|
|
39
|
+
*/
|
|
40
|
+
export declare function relativeModuleSpecifier(fromDirectory: string, targetFilePath: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Imports a bounded context's alias constant into a generated file.
|
|
43
|
+
*
|
|
44
|
+
* @param module - The importing module
|
|
45
|
+
* @param outputDir - The output directory
|
|
46
|
+
* @param contextAlias - The bounded context alias
|
|
47
|
+
* @param declarationName - The name of the alias constant
|
|
48
|
+
*/
|
|
49
|
+
export declare function addImportBoundedContext(module: ModuleBuilder, outputDir: string, contextAlias: string, declarationName: string): readonly NamedImport[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Reference, Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { JSDocableNodeStructure } from 'ts-morph';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a JSDoc comment string from a title and description.
|
|
5
|
+
* @returns The formatted JSDoc string or undefined if both title and description are empty
|
|
6
|
+
*/
|
|
7
|
+
export declare function jsDoc(descriptions: (string | undefined)[], separator?: string): string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Keeps document text from ending the comment it is written into: a
|
|
10
|
+
* description holding `*` followed by `/` - a cron expression such as
|
|
11
|
+
* `*` `/5 * * * *`, a glob - would otherwise close the JSDoc early.
|
|
12
|
+
*
|
|
13
|
+
* @param text - Text taken from the document
|
|
14
|
+
* @returns The text with every comment terminator broken up
|
|
15
|
+
*/
|
|
16
|
+
export declare function escapeJsDoc(text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Adds a JSDoc comment to a declaration with the provided title and
|
|
19
|
+
* description, after the ones it already has.
|
|
20
|
+
*/
|
|
21
|
+
export declare function addJSDoc(node: JSDocableNodeStructure, descriptions: (string | undefined)[]): void;
|
|
22
|
+
export declare function schemaJSDoc(schema: Schema, key?: string): (string | undefined)[];
|
|
23
|
+
/**
|
|
24
|
+
* Adds a JSDoc comment to a declaration based on the schema's title and description.
|
|
25
|
+
* @param node - The declaration to add the JSDoc comment to
|
|
26
|
+
* @param schema - The schema containing title and description
|
|
27
|
+
* @param key - The key associated with the schema
|
|
28
|
+
*/
|
|
29
|
+
export declare function addSchemaJSDoc(node: JSDocableNodeStructure, schema: Schema | Reference, key?: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Adds the doc comment of a model.
|
|
32
|
+
*
|
|
33
|
+
* @param node - The model declaration
|
|
34
|
+
* @param schema - The schema it is generated from
|
|
35
|
+
* @param key - The schema's component key
|
|
36
|
+
* @param includeSchema - Also embed the complete JSON schema
|
|
37
|
+
*/
|
|
38
|
+
export declare function addMainSchemaJSDoc(node: JSDocableNodeStructure, schema: Schema | Reference, key?: string, includeSchema?: boolean): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Reference, Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { JSDocableNodeStructure } from 'ts-morph';
|
|
3
|
+
/**
|
|
4
|
+
* Generates a JSDoc comment string from a title and description.
|
|
5
|
+
* @returns The formatted JSDoc string or undefined if both title and description are empty
|
|
6
|
+
*/
|
|
7
|
+
export declare function jsDoc(descriptions: (string | undefined)[], separator?: string): string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Keeps document text from ending the comment it is written into: a
|
|
10
|
+
* description holding `*` followed by `/` - a cron expression such as
|
|
11
|
+
* `*` `/5 * * * *`, a glob - would otherwise close the JSDoc early.
|
|
12
|
+
*
|
|
13
|
+
* @param text - Text taken from the document
|
|
14
|
+
* @returns The text with every comment terminator broken up
|
|
15
|
+
*/
|
|
16
|
+
export declare function escapeJsDoc(text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Adds a JSDoc comment to a declaration with the provided title and
|
|
19
|
+
* description, after the ones it already has.
|
|
20
|
+
*/
|
|
21
|
+
export declare function addJSDoc(node: JSDocableNodeStructure, descriptions: (string | undefined)[]): void;
|
|
22
|
+
export declare function schemaJSDoc(schema: Schema, key?: string): (string | undefined)[];
|
|
23
|
+
/**
|
|
24
|
+
* Adds a JSDoc comment to a declaration based on the schema's title and description.
|
|
25
|
+
* @param node - The declaration to add the JSDoc comment to
|
|
26
|
+
* @param schema - The schema containing title and description
|
|
27
|
+
* @param key - The key associated with the schema
|
|
28
|
+
*/
|
|
29
|
+
export declare function addSchemaJSDoc(node: JSDocableNodeStructure, schema: Schema | Reference, key?: string): void;
|
|
30
|
+
/**
|
|
31
|
+
* Adds the doc comment of a model.
|
|
32
|
+
*
|
|
33
|
+
* @param node - The model declaration
|
|
34
|
+
* @param schema - The schema it is generated from
|
|
35
|
+
* @param key - The schema's component key
|
|
36
|
+
* @param includeSchema - Also embed the complete JSON schema
|
|
37
|
+
*/
|
|
38
|
+
export declare function addMainSchemaJSDoc(node: JSDocableNodeStructure, schema: Schema | Reference, key?: string, includeSchema?: boolean): void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ClassDeclarationStructure, EnumDeclarationStructure, EnumMemberStructure, InterfaceDeclarationStructure, OptionalKind, SourceFile, TypeAliasDeclarationStructure, VariableStatementStructure } from 'ts-morph';
|
|
2
|
+
import { ImportRegistry } from './importRegistry.cjs';
|
|
3
|
+
/** A top-level statement of a generated module. */
|
|
4
|
+
export type ModuleStatement = ClassDeclarationStructure | EnumDeclarationStructure | InterfaceDeclarationStructure | TypeAliasDeclarationStructure | VariableStatementStructure | string;
|
|
5
|
+
/**
|
|
6
|
+
* A generated module, collected in memory and written into its source file
|
|
7
|
+
* once.
|
|
8
|
+
*
|
|
9
|
+
* ts-morph re-parses the whole file on every change, so a file written a
|
|
10
|
+
* declaration, a property and a doc comment at a time costs time that grows
|
|
11
|
+
* with the square of its length: the root `types.ts` of a large document runs
|
|
12
|
+
* to 20,000 lines. Here the emitters describe each declaration as a ts-morph
|
|
13
|
+
* structure, with its members and docs, and {@link build} inserts the lot in
|
|
14
|
+
* one change, printed by the same printers.
|
|
15
|
+
*
|
|
16
|
+
* The blank lines between statements are the ones the file would have got
|
|
17
|
+
* receiving the statements one by one, so the output is byte for byte the
|
|
18
|
+
* same: a type alias follows a type alias, and a variable statement a
|
|
19
|
+
* variable statement, on the next line; anything else is set off by a blank
|
|
20
|
+
* line.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ModuleBuilder {
|
|
23
|
+
readonly sourceFile: SourceFile;
|
|
24
|
+
/** The imports of the module. */
|
|
25
|
+
readonly imports: ImportRegistry;
|
|
26
|
+
private readonly statements;
|
|
27
|
+
/**
|
|
28
|
+
* @param sourceFile - The file the module is written into; it stays empty
|
|
29
|
+
* until {@link build}.
|
|
30
|
+
*/
|
|
31
|
+
constructor(sourceFile: SourceFile);
|
|
32
|
+
/** The directory of the module's file, which relative imports start from. */
|
|
33
|
+
get directoryPath(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Adds a top-level statement. A structure stays open to changes until the
|
|
36
|
+
* module is built.
|
|
37
|
+
*
|
|
38
|
+
* @returns The statement added
|
|
39
|
+
*/
|
|
40
|
+
add<T extends ModuleStatement>(statement: T): T;
|
|
41
|
+
/** Writes the imports and the statements into the file in one change. */
|
|
42
|
+
build(): SourceFile;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The modules of one generation, one builder per file, written together at
|
|
46
|
+
* the end.
|
|
47
|
+
*/
|
|
48
|
+
export declare class ModuleSet {
|
|
49
|
+
private readonly open;
|
|
50
|
+
private readonly modules;
|
|
51
|
+
/**
|
|
52
|
+
* @param open - Returns the source file a path relative to the output
|
|
53
|
+
* directory is written to, claiming it for the generation
|
|
54
|
+
*/
|
|
55
|
+
constructor(open: (filePath: string) => SourceFile);
|
|
56
|
+
/**
|
|
57
|
+
* The module written to a path under the output directory, created the
|
|
58
|
+
* first time it is asked for.
|
|
59
|
+
*/
|
|
60
|
+
module(filePath: string): ModuleBuilder;
|
|
61
|
+
/** Writes every module into its file, each in one go. */
|
|
62
|
+
build(): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Enum members printed as adding them one at a time to an enum leaves them:
|
|
66
|
+
* each one followed by a comma, the last one too. The printer separates
|
|
67
|
+
* members with commas only where a member does not already end with one.
|
|
68
|
+
*
|
|
69
|
+
* @param members - The members, each with a string initializer
|
|
70
|
+
*/
|
|
71
|
+
export declare function membersWithTrailingComma(members: readonly OptionalKind<EnumMemberStructure>[]): OptionalKind<EnumMemberStructure>[];
|
|
72
|
+
/**
|
|
73
|
+
* The index signature of an interface, as a member printed after its
|
|
74
|
+
* properties, where adding it after them puts it: a structure's
|
|
75
|
+
* `indexSignatures` are printed first.
|
|
76
|
+
*
|
|
77
|
+
* @param returnType - The type of the additional properties
|
|
78
|
+
* @param docs - Its doc comments
|
|
79
|
+
*/
|
|
80
|
+
export declare function indexSignatureMember(returnType: string, docs?: string[]): OptionalKind<NonNullable<InterfaceDeclarationStructure['properties']>[number]>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ClassDeclarationStructure, EnumDeclarationStructure, EnumMemberStructure, InterfaceDeclarationStructure, OptionalKind, SourceFile, TypeAliasDeclarationStructure, VariableStatementStructure } from 'ts-morph';
|
|
2
|
+
import { ImportRegistry } from './importRegistry.js';
|
|
3
|
+
/** A top-level statement of a generated module. */
|
|
4
|
+
export type ModuleStatement = ClassDeclarationStructure | EnumDeclarationStructure | InterfaceDeclarationStructure | TypeAliasDeclarationStructure | VariableStatementStructure | string;
|
|
5
|
+
/**
|
|
6
|
+
* A generated module, collected in memory and written into its source file
|
|
7
|
+
* once.
|
|
8
|
+
*
|
|
9
|
+
* ts-morph re-parses the whole file on every change, so a file written a
|
|
10
|
+
* declaration, a property and a doc comment at a time costs time that grows
|
|
11
|
+
* with the square of its length: the root `types.ts` of a large document runs
|
|
12
|
+
* to 20,000 lines. Here the emitters describe each declaration as a ts-morph
|
|
13
|
+
* structure, with its members and docs, and {@link build} inserts the lot in
|
|
14
|
+
* one change, printed by the same printers.
|
|
15
|
+
*
|
|
16
|
+
* The blank lines between statements are the ones the file would have got
|
|
17
|
+
* receiving the statements one by one, so the output is byte for byte the
|
|
18
|
+
* same: a type alias follows a type alias, and a variable statement a
|
|
19
|
+
* variable statement, on the next line; anything else is set off by a blank
|
|
20
|
+
* line.
|
|
21
|
+
*/
|
|
22
|
+
export declare class ModuleBuilder {
|
|
23
|
+
readonly sourceFile: SourceFile;
|
|
24
|
+
/** The imports of the module. */
|
|
25
|
+
readonly imports: ImportRegistry;
|
|
26
|
+
private readonly statements;
|
|
27
|
+
/**
|
|
28
|
+
* @param sourceFile - The file the module is written into; it stays empty
|
|
29
|
+
* until {@link build}.
|
|
30
|
+
*/
|
|
31
|
+
constructor(sourceFile: SourceFile);
|
|
32
|
+
/** The directory of the module's file, which relative imports start from. */
|
|
33
|
+
get directoryPath(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Adds a top-level statement. A structure stays open to changes until the
|
|
36
|
+
* module is built.
|
|
37
|
+
*
|
|
38
|
+
* @returns The statement added
|
|
39
|
+
*/
|
|
40
|
+
add<T extends ModuleStatement>(statement: T): T;
|
|
41
|
+
/** Writes the imports and the statements into the file in one change. */
|
|
42
|
+
build(): SourceFile;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The modules of one generation, one builder per file, written together at
|
|
46
|
+
* the end.
|
|
47
|
+
*/
|
|
48
|
+
export declare class ModuleSet {
|
|
49
|
+
private readonly open;
|
|
50
|
+
private readonly modules;
|
|
51
|
+
/**
|
|
52
|
+
* @param open - Returns the source file a path relative to the output
|
|
53
|
+
* directory is written to, claiming it for the generation
|
|
54
|
+
*/
|
|
55
|
+
constructor(open: (filePath: string) => SourceFile);
|
|
56
|
+
/**
|
|
57
|
+
* The module written to a path under the output directory, created the
|
|
58
|
+
* first time it is asked for.
|
|
59
|
+
*/
|
|
60
|
+
module(filePath: string): ModuleBuilder;
|
|
61
|
+
/** Writes every module into its file, each in one go. */
|
|
62
|
+
build(): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Enum members printed as adding them one at a time to an enum leaves them:
|
|
66
|
+
* each one followed by a comma, the last one too. The printer separates
|
|
67
|
+
* members with commas only where a member does not already end with one.
|
|
68
|
+
*
|
|
69
|
+
* @param members - The members, each with a string initializer
|
|
70
|
+
*/
|
|
71
|
+
export declare function membersWithTrailingComma(members: readonly OptionalKind<EnumMemberStructure>[]): OptionalKind<EnumMemberStructure>[];
|
|
72
|
+
/**
|
|
73
|
+
* The index signature of an interface, as a member printed after its
|
|
74
|
+
* properties, where adding it after them puts it: a structure's
|
|
75
|
+
* `indexSignatures` are printed first.
|
|
76
|
+
*
|
|
77
|
+
* @param returnType - The type of the additional properties
|
|
78
|
+
* @param docs - Its doc comments
|
|
79
|
+
*/
|
|
80
|
+
export declare function indexSignatureMember(returnType: string, docs?: string[]): OptionalKind<NonNullable<InterfaceDeclarationStructure['properties']>[number]>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiClientModel } from '../analysis/model.cjs';
|
|
2
|
+
import { EmitTarget } from './target.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the API client of a tag: a decorated class with a method per
|
|
5
|
+
* operation.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The client
|
|
8
|
+
* @param target - Where it is written
|
|
9
|
+
*/
|
|
10
|
+
export declare function emitApiClient(client: ApiClientModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ApiClientModel } from '../analysis/model.js';
|
|
2
|
+
import { EmitTarget } from './target.js';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the API client of a tag: a decorated class with a method per
|
|
5
|
+
* operation.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The client
|
|
8
|
+
* @param target - Where it is written
|
|
9
|
+
*/
|
|
10
|
+
export declare function emitApiClient(client: ApiClientModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AggregateModel } from '../analysis/model.cjs';
|
|
2
|
+
import { EmitTarget } from './target.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the command client of an aggregate: the enum of its command routes,
|
|
5
|
+
* a type per command body whose name does not already end in `Command`, the client, whose methods send the commands, and
|
|
6
|
+
* the streaming client, which waits on their results as server-sent events.
|
|
7
|
+
* An aggregate the document routes no command to (every command route
|
|
8
|
+
* disabled or closed by the service) gets none: a client without a method
|
|
9
|
+
* sends nothing, and its result type would go unused.
|
|
10
|
+
*
|
|
11
|
+
* @param aggregate - The aggregate
|
|
12
|
+
* @param target - Where it is written
|
|
13
|
+
*/
|
|
14
|
+
export declare function emitCommandClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AggregateModel } from '../analysis/model.js';
|
|
2
|
+
import { EmitTarget } from './target.js';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the command client of an aggregate: the enum of its command routes,
|
|
5
|
+
* a type per command body whose name does not already end in `Command`, the client, whose methods send the commands, and
|
|
6
|
+
* the streaming client, which waits on their results as server-sent events.
|
|
7
|
+
* An aggregate the document routes no command to (every command route
|
|
8
|
+
* disabled or closed by the service) gets none: a client without a method
|
|
9
|
+
* sends nothing, and its result type would go unused.
|
|
10
|
+
*
|
|
11
|
+
* @param aggregate - The aggregate
|
|
12
|
+
* @param target - Where it is written
|
|
13
|
+
*/
|
|
14
|
+
export declare function emitCommandClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ClassDeclarationStructure } from 'ts-morph';
|
|
2
|
+
import { ModuleBuilder } from '../emit/moduleBuilder.cjs';
|
|
3
|
+
export declare const FETCHER_MODULE_SPECIFIER = "@ahoo-wang/fetcher";
|
|
4
|
+
export declare const FETCHER_NAMED_IMPORTS: string[];
|
|
5
|
+
/**
|
|
6
|
+
* The module specifier for the fetcher-decorator package.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DECORATOR_MODULE_SPECIFIER = "@ahoo-wang/fetcher-decorator";
|
|
9
|
+
/**
|
|
10
|
+
* Named imports from the fetcher-decorator package.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DECORATOR_NAMED_IMPORTS: string[];
|
|
13
|
+
export interface MethodReturnType {
|
|
14
|
+
type: string;
|
|
15
|
+
metadata?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_RETURN_TYPE: MethodReturnType;
|
|
18
|
+
export declare const STRING_RETURN_TYPE: MethodReturnType;
|
|
19
|
+
/**
|
|
20
|
+
* Metadata configuration for stream result extraction.
|
|
21
|
+
*/
|
|
22
|
+
export declare const STREAM_RESULT_EXTRACTOR_METADATA = "{\n headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },\n resultExtractor: JsonEventStreamResultExtractor,\n}";
|
|
23
|
+
/**
|
|
24
|
+
* The endpoint options of a streaming command client, imported from
|
|
25
|
+
* `@ahoo-wang/wow-client`: `Accept: text/event-stream` and a result
|
|
26
|
+
* extractor that errors the stream with a `WowError` when the server sends an
|
|
27
|
+
* error event instead of passing the event on as a result.
|
|
28
|
+
*/
|
|
29
|
+
export declare const COMMAND_STREAM_ENDPOINT_METADATA = "COMMAND_STREAM_ENDPOINT";
|
|
30
|
+
export declare function addImportFetcher(module: ModuleBuilder): void;
|
|
31
|
+
/**
|
|
32
|
+
* Adds the necessary imports for decorator functionality to a module.
|
|
33
|
+
*
|
|
34
|
+
* @param module - The module to add imports to
|
|
35
|
+
*/
|
|
36
|
+
export declare function addImportDecorator(module: ModuleBuilder): void;
|
|
37
|
+
/**
|
|
38
|
+
* Adds a class declaration with the @api decorator to a module.
|
|
39
|
+
*
|
|
40
|
+
* @param className - The name of the class to create
|
|
41
|
+
* @param module - The module to add the class to
|
|
42
|
+
* @param apiArgs - Optional arguments for the @api decorator
|
|
43
|
+
* @param typeParameters - Optional type parameters for the class
|
|
44
|
+
* @param extendsClass - Optional class to extend
|
|
45
|
+
* @returns The class declaration, open to members until the module is built
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const classDecl = createDecoratorClass('UserApi', module, ['baseUrl']);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function createDecoratorClass(className: string, module: ModuleBuilder, apiArgs?: string[], typeParameters?: string[], extendsClass?: string): ClassDeclarationStructure;
|
|
53
|
+
/**
|
|
54
|
+
* Adds the ApiMetadataCapable interface implementation and constructor to a class declaration.
|
|
55
|
+
*
|
|
56
|
+
* With defaults, the constructor merges what the caller passes over them, so
|
|
57
|
+
* `new CartCommandClient({ fetcher })` keeps the bounded context's base path:
|
|
58
|
+
*
|
|
59
|
+
* ```typescript
|
|
60
|
+
* readonly apiMetadata: ApiMetadata;
|
|
61
|
+
* constructor(apiMetadata?: ApiMetadata) {
|
|
62
|
+
* this.apiMetadata = { ...DEFAULT_COMMAND_CLIENT_OPTIONS, ...apiMetadata };
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @param classDeclaration - The class declaration to modify
|
|
67
|
+
* @param defaults - Object literal entries the constructor starts from, such
|
|
68
|
+
* as `...DEFAULT_COMMAND_CLIENT_OPTIONS` or `basePath: X`; none by default
|
|
69
|
+
*/
|
|
70
|
+
export declare function addApiMetadataCtor(classDeclaration: ClassDeclarationStructure, defaults?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* The decorator of an HTTP method: its name, but `del` for `delete`, a
|
|
73
|
+
* reserved word.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* methodToDecorator('get'); // 'get'
|
|
78
|
+
* methodToDecorator('delete'); // 'del'
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function methodToDecorator(method: string): string;
|
|
82
|
+
export declare const EVENTSTREAM_MODULE_SPECIFIER = "@ahoo-wang/fetcher-eventstream";
|
|
83
|
+
export declare function addImportEventStream(module: ModuleBuilder): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ClassDeclarationStructure } from 'ts-morph';
|
|
2
|
+
import { ModuleBuilder } from '../emit/moduleBuilder.js';
|
|
3
|
+
export declare const FETCHER_MODULE_SPECIFIER = "@ahoo-wang/fetcher";
|
|
4
|
+
export declare const FETCHER_NAMED_IMPORTS: string[];
|
|
5
|
+
/**
|
|
6
|
+
* The module specifier for the fetcher-decorator package.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DECORATOR_MODULE_SPECIFIER = "@ahoo-wang/fetcher-decorator";
|
|
9
|
+
/**
|
|
10
|
+
* Named imports from the fetcher-decorator package.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DECORATOR_NAMED_IMPORTS: string[];
|
|
13
|
+
export interface MethodReturnType {
|
|
14
|
+
type: string;
|
|
15
|
+
metadata?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_RETURN_TYPE: MethodReturnType;
|
|
18
|
+
export declare const STRING_RETURN_TYPE: MethodReturnType;
|
|
19
|
+
/**
|
|
20
|
+
* Metadata configuration for stream result extraction.
|
|
21
|
+
*/
|
|
22
|
+
export declare const STREAM_RESULT_EXTRACTOR_METADATA = "{\n headers: { Accept: ContentTypeValues.TEXT_EVENT_STREAM },\n resultExtractor: JsonEventStreamResultExtractor,\n}";
|
|
23
|
+
/**
|
|
24
|
+
* The endpoint options of a streaming command client, imported from
|
|
25
|
+
* `@ahoo-wang/wow-client`: `Accept: text/event-stream` and a result
|
|
26
|
+
* extractor that errors the stream with a `WowError` when the server sends an
|
|
27
|
+
* error event instead of passing the event on as a result.
|
|
28
|
+
*/
|
|
29
|
+
export declare const COMMAND_STREAM_ENDPOINT_METADATA = "COMMAND_STREAM_ENDPOINT";
|
|
30
|
+
export declare function addImportFetcher(module: ModuleBuilder): void;
|
|
31
|
+
/**
|
|
32
|
+
* Adds the necessary imports for decorator functionality to a module.
|
|
33
|
+
*
|
|
34
|
+
* @param module - The module to add imports to
|
|
35
|
+
*/
|
|
36
|
+
export declare function addImportDecorator(module: ModuleBuilder): void;
|
|
37
|
+
/**
|
|
38
|
+
* Adds a class declaration with the @api decorator to a module.
|
|
39
|
+
*
|
|
40
|
+
* @param className - The name of the class to create
|
|
41
|
+
* @param module - The module to add the class to
|
|
42
|
+
* @param apiArgs - Optional arguments for the @api decorator
|
|
43
|
+
* @param typeParameters - Optional type parameters for the class
|
|
44
|
+
* @param extendsClass - Optional class to extend
|
|
45
|
+
* @returns The class declaration, open to members until the module is built
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const classDecl = createDecoratorClass('UserApi', module, ['baseUrl']);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function createDecoratorClass(className: string, module: ModuleBuilder, apiArgs?: string[], typeParameters?: string[], extendsClass?: string): ClassDeclarationStructure;
|
|
53
|
+
/**
|
|
54
|
+
* Adds the ApiMetadataCapable interface implementation and constructor to a class declaration.
|
|
55
|
+
*
|
|
56
|
+
* With defaults, the constructor merges what the caller passes over them, so
|
|
57
|
+
* `new CartCommandClient({ fetcher })` keeps the bounded context's base path:
|
|
58
|
+
*
|
|
59
|
+
* ```typescript
|
|
60
|
+
* readonly apiMetadata: ApiMetadata;
|
|
61
|
+
* constructor(apiMetadata?: ApiMetadata) {
|
|
62
|
+
* this.apiMetadata = { ...DEFAULT_COMMAND_CLIENT_OPTIONS, ...apiMetadata };
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @param classDeclaration - The class declaration to modify
|
|
67
|
+
* @param defaults - Object literal entries the constructor starts from, such
|
|
68
|
+
* as `...DEFAULT_COMMAND_CLIENT_OPTIONS` or `basePath: X`; none by default
|
|
69
|
+
*/
|
|
70
|
+
export declare function addApiMetadataCtor(classDeclaration: ClassDeclarationStructure, defaults?: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* The decorator of an HTTP method: its name, but `del` for `delete`, a
|
|
73
|
+
* reserved word.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* methodToDecorator('get'); // 'get'
|
|
78
|
+
* methodToDecorator('delete'); // 'del'
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function methodToDecorator(method: string): string;
|
|
82
|
+
export declare const EVENTSTREAM_MODULE_SPECIFIER = "@ahoo-wang/fetcher-eventstream";
|
|
83
|
+
export declare function addImportEventStream(module: ModuleBuilder): void;
|