@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,15 @@
|
|
|
1
|
+
import { GenerationModel } from '../analysis/model.cjs';
|
|
2
|
+
import { EmitTarget } from './target.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Describes every file of a generation to its module: the bounded contexts,
|
|
5
|
+
* the models, the query and command clients of each aggregate, then the API
|
|
6
|
+
* clients. Nothing reaches a source file until the modules are built.
|
|
7
|
+
*
|
|
8
|
+
* The order is the one the files have always been written in, so the
|
|
9
|
+
* imports of a module, and the aliases a name clash gives them, come out
|
|
10
|
+
* the same.
|
|
11
|
+
*
|
|
12
|
+
* @param model - What the document generates
|
|
13
|
+
* @param target - Where it is written
|
|
14
|
+
*/
|
|
15
|
+
export declare function emitGeneration(model: GenerationModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GenerationModel } from '../analysis/model.js';
|
|
2
|
+
import { EmitTarget } from './target.js';
|
|
3
|
+
/**
|
|
4
|
+
* Describes every file of a generation to its module: the bounded contexts,
|
|
5
|
+
* the models, the query and command clients of each aggregate, then the API
|
|
6
|
+
* clients. Nothing reaches a source file until the modules are built.
|
|
7
|
+
*
|
|
8
|
+
* The order is the one the files have always been written in, so the
|
|
9
|
+
* imports of a module, and the aliases a name clash gives them, come out
|
|
10
|
+
* the same.
|
|
11
|
+
*
|
|
12
|
+
* @param model - What the document generates
|
|
13
|
+
* @param target - Where it is written
|
|
14
|
+
*/
|
|
15
|
+
export declare function emitGeneration(model: GenerationModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Directory, SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Writes an `index.ts` into the output directory and each directory under
|
|
4
|
+
* it, re-exporting its files and the indexes of its subdirectories.
|
|
5
|
+
*
|
|
6
|
+
* @param outputDir - The output directory, holding the files written
|
|
7
|
+
* @param claim - Returns the index file of a directory, emptied and claimed
|
|
8
|
+
* for the generation
|
|
9
|
+
* @returns A warning for every name an index leaves out because two of its
|
|
10
|
+
* children export it
|
|
11
|
+
*/
|
|
12
|
+
export declare function emitIndexFiles(outputDir: Directory, claim: (directoryPath: string) => SourceFile): string[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Directory, SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Writes an `index.ts` into the output directory and each directory under
|
|
4
|
+
* it, re-exporting its files and the indexes of its subdirectories.
|
|
5
|
+
*
|
|
6
|
+
* @param outputDir - The output directory, holding the files written
|
|
7
|
+
* @param claim - Returns the index file of a directory, emptied and claimed
|
|
8
|
+
* for the generation
|
|
9
|
+
* @returns A warning for every name an index leaves out because two of its
|
|
10
|
+
* children export it
|
|
11
|
+
*/
|
|
12
|
+
export declare function emitIndexFiles(outputDir: Directory, claim: (directoryPath: string) => SourceFile): string[];
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Components, Reference, Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { ModelDeclaration } from '../analysis/model.cjs';
|
|
3
|
+
import { ModuleBuilder } from '../emit/moduleBuilder.cjs';
|
|
4
|
+
import { TypeContext } from '../types/typeResolver.cjs';
|
|
5
|
+
import { EmitTarget } from './target.cjs';
|
|
6
|
+
/**
|
|
7
|
+
* The type context of a document: its components, named the way the
|
|
8
|
+
* generator names models. Build it once per generation and share it, so the
|
|
9
|
+
* model names of each path are read once.
|
|
10
|
+
*
|
|
11
|
+
* @param components - The document's components
|
|
12
|
+
*/
|
|
13
|
+
export declare function documentTypeContext(components?: Components): TypeContext;
|
|
14
|
+
/**
|
|
15
|
+
* Writes a model into the `types.ts` of its package: an interface, an enum or
|
|
16
|
+
* a type alias, with its doc comment, and imports the models it uses.
|
|
17
|
+
*
|
|
18
|
+
* @param declaration - The model
|
|
19
|
+
* @param target - Where it is written
|
|
20
|
+
*/
|
|
21
|
+
export declare function emitModel(declaration: ModelDeclaration, target: EmitTarget): void;
|
|
22
|
+
/**
|
|
23
|
+
* Names the members of an enum. Each value takes its UPPER_SNAKE_CASE form;
|
|
24
|
+
* when another value already took that form - `in-progress`, `IN_PROGRESS`
|
|
25
|
+
* and `inProgress` all give `IN_PROGRESS` - it takes its own value as a
|
|
26
|
+
* quoted member name, or else a numbered form.
|
|
27
|
+
*
|
|
28
|
+
* @param values - The distinct values, in document order
|
|
29
|
+
* @returns The member name of each value, quoted where it has to be
|
|
30
|
+
*/
|
|
31
|
+
export declare function uniqueEnumMemberNames(values: readonly string[]): Map<string, string>;
|
|
32
|
+
/** The model a {@link ModelEmitter} writes. */
|
|
33
|
+
export type ModelSource = Pick<ModelDeclaration, 'key' | 'info' | 'schema' | 'docSchema'>;
|
|
34
|
+
/**
|
|
35
|
+
* Writes one model into a module: the declaration its schema calls for,
|
|
36
|
+
* with the model's doc comment.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ModelEmitter {
|
|
39
|
+
private readonly model;
|
|
40
|
+
readonly module: ModuleBuilder;
|
|
41
|
+
private readonly target;
|
|
42
|
+
private readonly modelInfo;
|
|
43
|
+
private readonly components?;
|
|
44
|
+
/**
|
|
45
|
+
* @param model - The model
|
|
46
|
+
* @param module - The module the model is written into, which also
|
|
47
|
+
* receives its imports
|
|
48
|
+
* @param target - The output directory, the document's type context and
|
|
49
|
+
* how much of the schema the doc comment carries
|
|
50
|
+
*/
|
|
51
|
+
constructor(model: ModelSource, module: ModuleBuilder, target: Pick<EmitTarget, 'outputDir' | 'types' | 'schemaDocs'>);
|
|
52
|
+
/** Writes the model's declaration and its doc comment. */
|
|
53
|
+
write(): void;
|
|
54
|
+
private process;
|
|
55
|
+
/** Where the types of this model are written. */
|
|
56
|
+
private readonly scope;
|
|
57
|
+
/** Applies the imports a resolved type needs to the module. */
|
|
58
|
+
private emit;
|
|
59
|
+
/** The type a schema generates in this model's module, its imports added. */
|
|
60
|
+
resolveType(schema: Schema | Reference): string;
|
|
61
|
+
private processEnum;
|
|
62
|
+
/**
|
|
63
|
+
* Adds a declared property. Property names are distinct, and
|
|
64
|
+
* `resolvePropertyName` keeps them distinct: a name is kept or quoted.
|
|
65
|
+
*/
|
|
66
|
+
private addPropertyToInterface;
|
|
67
|
+
private processInterface;
|
|
68
|
+
private processArray;
|
|
69
|
+
/**
|
|
70
|
+
* A string-keyed map is an interface with an index signature rather than an
|
|
71
|
+
* alias of `Record`: an alias may not reference itself through `Record`
|
|
72
|
+
* (TS2456), and a map of its own type - a tree of dictionaries - does.
|
|
73
|
+
*/
|
|
74
|
+
private processIndexSignature;
|
|
75
|
+
private processComposition;
|
|
76
|
+
private processTypeAlias;
|
|
77
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Components, Reference, Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { ModelDeclaration } from '../analysis/model.js';
|
|
3
|
+
import { ModuleBuilder } from '../emit/moduleBuilder.js';
|
|
4
|
+
import { TypeContext } from '../types/typeResolver.js';
|
|
5
|
+
import { EmitTarget } from './target.js';
|
|
6
|
+
/**
|
|
7
|
+
* The type context of a document: its components, named the way the
|
|
8
|
+
* generator names models. Build it once per generation and share it, so the
|
|
9
|
+
* model names of each path are read once.
|
|
10
|
+
*
|
|
11
|
+
* @param components - The document's components
|
|
12
|
+
*/
|
|
13
|
+
export declare function documentTypeContext(components?: Components): TypeContext;
|
|
14
|
+
/**
|
|
15
|
+
* Writes a model into the `types.ts` of its package: an interface, an enum or
|
|
16
|
+
* a type alias, with its doc comment, and imports the models it uses.
|
|
17
|
+
*
|
|
18
|
+
* @param declaration - The model
|
|
19
|
+
* @param target - Where it is written
|
|
20
|
+
*/
|
|
21
|
+
export declare function emitModel(declaration: ModelDeclaration, target: EmitTarget): void;
|
|
22
|
+
/**
|
|
23
|
+
* Names the members of an enum. Each value takes its UPPER_SNAKE_CASE form;
|
|
24
|
+
* when another value already took that form - `in-progress`, `IN_PROGRESS`
|
|
25
|
+
* and `inProgress` all give `IN_PROGRESS` - it takes its own value as a
|
|
26
|
+
* quoted member name, or else a numbered form.
|
|
27
|
+
*
|
|
28
|
+
* @param values - The distinct values, in document order
|
|
29
|
+
* @returns The member name of each value, quoted where it has to be
|
|
30
|
+
*/
|
|
31
|
+
export declare function uniqueEnumMemberNames(values: readonly string[]): Map<string, string>;
|
|
32
|
+
/** The model a {@link ModelEmitter} writes. */
|
|
33
|
+
export type ModelSource = Pick<ModelDeclaration, 'key' | 'info' | 'schema' | 'docSchema'>;
|
|
34
|
+
/**
|
|
35
|
+
* Writes one model into a module: the declaration its schema calls for,
|
|
36
|
+
* with the model's doc comment.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ModelEmitter {
|
|
39
|
+
private readonly model;
|
|
40
|
+
readonly module: ModuleBuilder;
|
|
41
|
+
private readonly target;
|
|
42
|
+
private readonly modelInfo;
|
|
43
|
+
private readonly components?;
|
|
44
|
+
/**
|
|
45
|
+
* @param model - The model
|
|
46
|
+
* @param module - The module the model is written into, which also
|
|
47
|
+
* receives its imports
|
|
48
|
+
* @param target - The output directory, the document's type context and
|
|
49
|
+
* how much of the schema the doc comment carries
|
|
50
|
+
*/
|
|
51
|
+
constructor(model: ModelSource, module: ModuleBuilder, target: Pick<EmitTarget, 'outputDir' | 'types' | 'schemaDocs'>);
|
|
52
|
+
/** Writes the model's declaration and its doc comment. */
|
|
53
|
+
write(): void;
|
|
54
|
+
private process;
|
|
55
|
+
/** Where the types of this model are written. */
|
|
56
|
+
private readonly scope;
|
|
57
|
+
/** Applies the imports a resolved type needs to the module. */
|
|
58
|
+
private emit;
|
|
59
|
+
/** The type a schema generates in this model's module, its imports added. */
|
|
60
|
+
resolveType(schema: Schema | Reference): string;
|
|
61
|
+
private processEnum;
|
|
62
|
+
/**
|
|
63
|
+
* Adds a declared property. Property names are distinct, and
|
|
64
|
+
* `resolvePropertyName` keeps them distinct: a name is kept or quoted.
|
|
65
|
+
*/
|
|
66
|
+
private addPropertyToInterface;
|
|
67
|
+
private processInterface;
|
|
68
|
+
private processArray;
|
|
69
|
+
/**
|
|
70
|
+
* A string-keyed map is an interface with an index signature rather than an
|
|
71
|
+
* alias of `Record`: an alias may not reference itself through `Record`
|
|
72
|
+
* (TS2456), and a map of its own type - a tree of dictionaries - does.
|
|
73
|
+
*/
|
|
74
|
+
private processIndexSignature;
|
|
75
|
+
private processComposition;
|
|
76
|
+
private processTypeAlias;
|
|
77
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AggregateModel } from '../analysis/model.cjs';
|
|
2
|
+
import { EmitTarget } from './target.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the query client of an aggregate: the enum of its event titles, the
|
|
5
|
+
* union of its event types, and the factory of its snapshot and event
|
|
6
|
+
* stream query clients.
|
|
7
|
+
*
|
|
8
|
+
* @param aggregate - The aggregate
|
|
9
|
+
* @param target - Where it is written
|
|
10
|
+
*/
|
|
11
|
+
export declare function emitQueryClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AggregateModel } from '../analysis/model.js';
|
|
2
|
+
import { EmitTarget } from './target.js';
|
|
3
|
+
/**
|
|
4
|
+
* Writes the query client of an aggregate: the enum of its event titles, the
|
|
5
|
+
* union of its event types, and the factory of its snapshot and event
|
|
6
|
+
* stream query clients.
|
|
7
|
+
*
|
|
8
|
+
* @param aggregate - The aggregate
|
|
9
|
+
* @param target - Where it is written
|
|
10
|
+
*/
|
|
11
|
+
export declare function emitQueryClient(aggregate: AggregateModel, target: EmitTarget): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SchemaDocs } from '../api/options.cjs';
|
|
2
|
+
import { ModuleSet } from '../emit/moduleBuilder.cjs';
|
|
3
|
+
import { TypeContext } from '../types/typeResolver.cjs';
|
|
4
|
+
/** Where the emitters write, and what every module of a run shares. */
|
|
5
|
+
export interface EmitTarget {
|
|
6
|
+
/** The module of each file, claimed from the output the first time asked. */
|
|
7
|
+
readonly modules: ModuleSet;
|
|
8
|
+
/** The output directory, which relative imports are computed under. */
|
|
9
|
+
readonly outputDir: string;
|
|
10
|
+
/** What every schema of the document resolves against. */
|
|
11
|
+
readonly types: TypeContext;
|
|
12
|
+
/** How much of each schema a model's doc comment carries. */
|
|
13
|
+
readonly schemaDocs: SchemaDocs;
|
|
14
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SchemaDocs } from '../api/options.js';
|
|
2
|
+
import { ModuleSet } from '../emit/moduleBuilder.js';
|
|
3
|
+
import { TypeContext } from '../types/typeResolver.js';
|
|
4
|
+
/** Where the emitters write, and what every module of a run shares. */
|
|
5
|
+
export interface EmitTarget {
|
|
6
|
+
/** The module of each file, claimed from the output the first time asked. */
|
|
7
|
+
readonly modules: ModuleSet;
|
|
8
|
+
/** The output directory, which relative imports are computed under. */
|
|
9
|
+
readonly outputDir: string;
|
|
10
|
+
/** What every schema of the document resolves against. */
|
|
11
|
+
readonly types: TypeContext;
|
|
12
|
+
/** How much of each schema a model's doc comment carries. */
|
|
13
|
+
readonly schemaDocs: SchemaDocs;
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SourceFile } from 'ts-morph';
|
|
2
|
+
import { Logger } from '../api/logger.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Finishes the files a generation wrote: formats them, organizes and types
|
|
5
|
+
* their imports, checks that the result declares or imports every name it
|
|
6
|
+
* uses, and adds the generated-file header.
|
|
7
|
+
*
|
|
8
|
+
* Imports are written explicitly while generating, never inferred from
|
|
9
|
+
* whatever the output directory happens to resolve, so the output is the
|
|
10
|
+
* same wherever it is written.
|
|
11
|
+
*
|
|
12
|
+
* @param sourceFiles - The files to finish, each written by this generation
|
|
13
|
+
* @param logger - Receives a debug line for each file
|
|
14
|
+
* @throws Error listing each diagnostic when the code does not compile
|
|
15
|
+
*/
|
|
16
|
+
export declare function finalizeSourceFiles(sourceFiles: readonly SourceFile[], logger: Logger): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SourceFile } from 'ts-morph';
|
|
2
|
+
import { Logger } from '../api/logger.js';
|
|
3
|
+
/**
|
|
4
|
+
* Finishes the files a generation wrote: formats them, organizes and types
|
|
5
|
+
* their imports, checks that the result declares or imports every name it
|
|
6
|
+
* uses, and adds the generated-file header.
|
|
7
|
+
*
|
|
8
|
+
* Imports are written explicitly while generating, never inferred from
|
|
9
|
+
* whatever the output directory happens to resolve, so the output is the
|
|
10
|
+
* same wherever it is written.
|
|
11
|
+
*
|
|
12
|
+
* @param sourceFiles - The files to finish, each written by this generation
|
|
13
|
+
* @param logger - Receives a debug line for each file
|
|
14
|
+
* @throws Error listing each diagnostic when the code does not compile
|
|
15
|
+
*/
|
|
16
|
+
export declare function finalizeSourceFiles(sourceFiles: readonly SourceFile[], logger: Logger): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Rewrites named imports by how each file uses them, as
|
|
4
|
+
* `@typescript-eslint/consistent-type-imports` expects:
|
|
5
|
+
*
|
|
6
|
+
* - every specifier used only as a type: `import type { A, B } from '…'`;
|
|
7
|
+
* - values and types mixed: `import { type A, b } from '…'`;
|
|
8
|
+
* - values only: `import { a, b } from '…'`.
|
|
9
|
+
*
|
|
10
|
+
* Usage alone decides, so an existing `type` modifier that a value use
|
|
11
|
+
* contradicts is removed. Default and namespace imports are left as they are.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyTypeOnlyImports(sourceFiles: readonly SourceFile[]): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Rewrites named imports by how each file uses them, as
|
|
4
|
+
* `@typescript-eslint/consistent-type-imports` expects:
|
|
5
|
+
*
|
|
6
|
+
* - every specifier used only as a type: `import type { A, B } from '…'`;
|
|
7
|
+
* - values and types mixed: `import { type A, b } from '…'`;
|
|
8
|
+
* - values only: `import { a, b } from '…'`.
|
|
9
|
+
*
|
|
10
|
+
* Usage alone decides, so an existing `type` modifier that a value use
|
|
11
|
+
* contradicts is removed. Default and namespace imports are left as they are.
|
|
12
|
+
*/
|
|
13
|
+
export declare function applyTypeOnlyImports(sourceFiles: readonly SourceFile[]): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Fails when generated code references a name it does not declare or import,
|
|
4
|
+
* or declares one twice.
|
|
5
|
+
*
|
|
6
|
+
* This is a safety net under the emitters, which write every import
|
|
7
|
+
* explicitly: the output must be the same whether or not its directory
|
|
8
|
+
* resolves `@ahoo-wang/*`, and it must never be saved in a state that cannot
|
|
9
|
+
* compile.
|
|
10
|
+
*
|
|
11
|
+
* @param sourceFiles - The generated files
|
|
12
|
+
* @throws Error listing each diagnostic with its file and line
|
|
13
|
+
*/
|
|
14
|
+
export declare function verifyGeneratedCode(sourceFiles: readonly SourceFile[]): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SourceFile } from 'ts-morph';
|
|
2
|
+
/**
|
|
3
|
+
* Fails when generated code references a name it does not declare or import,
|
|
4
|
+
* or declares one twice.
|
|
5
|
+
*
|
|
6
|
+
* This is a safety net under the emitters, which write every import
|
|
7
|
+
* explicitly: the output must be the same whether or not its directory
|
|
8
|
+
* resolves `@ahoo-wang/*`, and it must never be saved in a state that cannot
|
|
9
|
+
* compile.
|
|
10
|
+
*
|
|
11
|
+
* @param sourceFiles - The generated files
|
|
12
|
+
* @throws Error listing each diagnostic with its file and line
|
|
13
|
+
*/
|
|
14
|
+
export declare function verifyGeneratedCode(sourceFiles: readonly SourceFile[]): void;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./codeGenerator-DpDTDC4o.cjs");exports.CodeGenerator=e.t,exports.ConsoleLogger=e.i,exports.DEFAULT_CONFIG_PATH=e.c,exports.EXIT_CODES=e.o,exports.GeneratorError=e.s,exports.SilentLogger=e.a;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { ApiClientConfiguration, GeneratorConfiguration, } from './api/configuration.cjs';
|
|
2
|
+
export { DEFAULT_CONFIG_PATH } from './api/configuration.cjs';
|
|
3
|
+
export type { GeneratorErrorKind } from './api/errors.cjs';
|
|
4
|
+
export { EXIT_CODES, GeneratorError } from './api/errors.cjs';
|
|
5
|
+
export type { ConsoleLoggerOptions, LogLevel, Logger } from './api/logger.cjs';
|
|
6
|
+
export { ConsoleLogger, SilentLogger } from './api/logger.cjs';
|
|
7
|
+
export type { GenerationResult, GeneratorOptions } from './api/options.cjs';
|
|
8
|
+
export { CodeGenerator } from './pipeline/codeGenerator.cjs';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { ApiClientConfiguration, GeneratorConfiguration, } from './api/configuration.js';
|
|
2
|
+
export { DEFAULT_CONFIG_PATH } from './api/configuration.js';
|
|
3
|
+
export type { GeneratorErrorKind } from './api/errors.js';
|
|
4
|
+
export { EXIT_CODES, GeneratorError } from './api/errors.js';
|
|
5
|
+
export type { ConsoleLoggerOptions, LogLevel, Logger } from './api/logger.js';
|
|
6
|
+
export { ConsoleLogger, SilentLogger } from './api/logger.js';
|
|
7
|
+
export type { GenerationResult, GeneratorOptions } from './api/options.js';
|
|
8
|
+
export { CodeGenerator } from './pipeline/codeGenerator.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { GeneratorConfiguration } from '../api/configuration.cjs';
|
|
2
|
+
import { Logger } from '../api/logger.cjs';
|
|
3
|
+
import { LoadResourceOptions } from './resources.cjs';
|
|
4
|
+
export declare const LEGACY_CONFIG_PATH = "./fetcher-generator.config.json";
|
|
5
|
+
/**
|
|
6
|
+
* A configuration, and the warnings reading it gave: keys the generator does
|
|
7
|
+
* not read, an empty file.
|
|
8
|
+
*/
|
|
9
|
+
export interface LoadedConfiguration {
|
|
10
|
+
readonly config: GeneratorConfiguration;
|
|
11
|
+
/** One line each, in the order they arose. */
|
|
12
|
+
readonly warnings: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A configuration, the place it was read from, and the warnings reading it
|
|
16
|
+
* gave.
|
|
17
|
+
*/
|
|
18
|
+
export interface ResolvedConfiguration extends LoadedConfiguration {
|
|
19
|
+
/** The absolute path or URL read, or undefined when there was none. */
|
|
20
|
+
readonly origin?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Finds and loads the generator configuration.
|
|
24
|
+
*
|
|
25
|
+
* A path the caller names has to exist. Without one the generator reads
|
|
26
|
+
* {@link DEFAULT_CONFIG_PATH}, then the pre-Wow name
|
|
27
|
+
* {@link LEGACY_CONFIG_PATH} with a deprecation warning, and generates with
|
|
28
|
+
* the defaults when neither exists.
|
|
29
|
+
*
|
|
30
|
+
* @param configPath - The path or URL the caller named, if any
|
|
31
|
+
* @param logger - Receives what was read, at `debug`
|
|
32
|
+
* @param options - Headers and timeout for a configuration read over http(s)
|
|
33
|
+
* @returns The configuration, where it came from and the warnings it gave
|
|
34
|
+
* @throws GeneratorError of kind `configuration` when it cannot be read,
|
|
35
|
+
* parsed or understood
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveConfiguration(configPath: string | undefined, logger: Logger, options?: LoadResourceOptions): Promise<ResolvedConfiguration>;
|
|
38
|
+
/**
|
|
39
|
+
* Where a configuration is read from, and whether the caller chose that place.
|
|
40
|
+
*/
|
|
41
|
+
export interface ConfigurationSource {
|
|
42
|
+
/** A file path, or an http(s) URL. */
|
|
43
|
+
readonly path: string;
|
|
44
|
+
/**
|
|
45
|
+
* True when the caller asked for this path. An absent file is then a
|
|
46
|
+
* mistake worth failing on; under the default path it is merely the common
|
|
47
|
+
* case of a project that has no configuration.
|
|
48
|
+
*/
|
|
49
|
+
readonly explicit: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads, validates and reports a generator configuration.
|
|
53
|
+
*
|
|
54
|
+
* A configuration that fails to load used to degrade to the defaults with a
|
|
55
|
+
* single line among hundreds of progress lines, so a misplaced file looked
|
|
56
|
+
* exactly like a generator that ignores its options. Loading now either
|
|
57
|
+
* succeeds and says what it read, or fails loudly - with the sole exception of
|
|
58
|
+
* the default path being absent, which stays a normal, quiet outcome.
|
|
59
|
+
*
|
|
60
|
+
* @param source - Where to read the configuration from
|
|
61
|
+
* @param logger - Receives what was read and the settings it resolved to, at
|
|
62
|
+
* `debug`
|
|
63
|
+
* @param options - Headers and timeout for a configuration read over http(s)
|
|
64
|
+
* @returns The validated configuration and the warnings about it; undefined
|
|
65
|
+
* when a path the caller did not name does not exist
|
|
66
|
+
* @throws GeneratorError of kind `configuration` when the configuration
|
|
67
|
+
* cannot be read, parsed or understood
|
|
68
|
+
*/
|
|
69
|
+
export declare function loadConfiguration(source: ConfigurationSource & {
|
|
70
|
+
explicit: true;
|
|
71
|
+
}, logger: Logger, options?: LoadResourceOptions): Promise<LoadedConfiguration>;
|
|
72
|
+
export declare function loadConfiguration(source: ConfigurationSource, logger: Logger, options?: LoadResourceOptions): Promise<LoadedConfiguration | undefined>;
|
|
73
|
+
/**
|
|
74
|
+
* Checks a parsed configuration against the options the generator reads.
|
|
75
|
+
*
|
|
76
|
+
* Shape errors throw: a block the generator cannot read is a request the user
|
|
77
|
+
* made and the generator would otherwise drop. Unknown keys only warn, so a
|
|
78
|
+
* configuration written for a newer version still generates.
|
|
79
|
+
*
|
|
80
|
+
* @param parsed - The parsed configuration document
|
|
81
|
+
* @param origin - Where it was read from, for messages
|
|
82
|
+
* @returns The same configuration, typed, and a warning for every key the
|
|
83
|
+
* generator ignores
|
|
84
|
+
* @throws GeneratorError of kind `configuration` when a block or option has
|
|
85
|
+
* a shape the generator cannot read
|
|
86
|
+
*/
|
|
87
|
+
export declare function validateConfiguration(parsed: unknown, origin: string): LoadedConfiguration;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { GeneratorConfiguration } from '../api/configuration.js';
|
|
2
|
+
import { Logger } from '../api/logger.js';
|
|
3
|
+
import { LoadResourceOptions } from './resources.js';
|
|
4
|
+
export declare const LEGACY_CONFIG_PATH = "./fetcher-generator.config.json";
|
|
5
|
+
/**
|
|
6
|
+
* A configuration, and the warnings reading it gave: keys the generator does
|
|
7
|
+
* not read, an empty file.
|
|
8
|
+
*/
|
|
9
|
+
export interface LoadedConfiguration {
|
|
10
|
+
readonly config: GeneratorConfiguration;
|
|
11
|
+
/** One line each, in the order they arose. */
|
|
12
|
+
readonly warnings: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A configuration, the place it was read from, and the warnings reading it
|
|
16
|
+
* gave.
|
|
17
|
+
*/
|
|
18
|
+
export interface ResolvedConfiguration extends LoadedConfiguration {
|
|
19
|
+
/** The absolute path or URL read, or undefined when there was none. */
|
|
20
|
+
readonly origin?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Finds and loads the generator configuration.
|
|
24
|
+
*
|
|
25
|
+
* A path the caller names has to exist. Without one the generator reads
|
|
26
|
+
* {@link DEFAULT_CONFIG_PATH}, then the pre-Wow name
|
|
27
|
+
* {@link LEGACY_CONFIG_PATH} with a deprecation warning, and generates with
|
|
28
|
+
* the defaults when neither exists.
|
|
29
|
+
*
|
|
30
|
+
* @param configPath - The path or URL the caller named, if any
|
|
31
|
+
* @param logger - Receives what was read, at `debug`
|
|
32
|
+
* @param options - Headers and timeout for a configuration read over http(s)
|
|
33
|
+
* @returns The configuration, where it came from and the warnings it gave
|
|
34
|
+
* @throws GeneratorError of kind `configuration` when it cannot be read,
|
|
35
|
+
* parsed or understood
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveConfiguration(configPath: string | undefined, logger: Logger, options?: LoadResourceOptions): Promise<ResolvedConfiguration>;
|
|
38
|
+
/**
|
|
39
|
+
* Where a configuration is read from, and whether the caller chose that place.
|
|
40
|
+
*/
|
|
41
|
+
export interface ConfigurationSource {
|
|
42
|
+
/** A file path, or an http(s) URL. */
|
|
43
|
+
readonly path: string;
|
|
44
|
+
/**
|
|
45
|
+
* True when the caller asked for this path. An absent file is then a
|
|
46
|
+
* mistake worth failing on; under the default path it is merely the common
|
|
47
|
+
* case of a project that has no configuration.
|
|
48
|
+
*/
|
|
49
|
+
readonly explicit: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads, validates and reports a generator configuration.
|
|
53
|
+
*
|
|
54
|
+
* A configuration that fails to load used to degrade to the defaults with a
|
|
55
|
+
* single line among hundreds of progress lines, so a misplaced file looked
|
|
56
|
+
* exactly like a generator that ignores its options. Loading now either
|
|
57
|
+
* succeeds and says what it read, or fails loudly - with the sole exception of
|
|
58
|
+
* the default path being absent, which stays a normal, quiet outcome.
|
|
59
|
+
*
|
|
60
|
+
* @param source - Where to read the configuration from
|
|
61
|
+
* @param logger - Receives what was read and the settings it resolved to, at
|
|
62
|
+
* `debug`
|
|
63
|
+
* @param options - Headers and timeout for a configuration read over http(s)
|
|
64
|
+
* @returns The validated configuration and the warnings about it; undefined
|
|
65
|
+
* when a path the caller did not name does not exist
|
|
66
|
+
* @throws GeneratorError of kind `configuration` when the configuration
|
|
67
|
+
* cannot be read, parsed or understood
|
|
68
|
+
*/
|
|
69
|
+
export declare function loadConfiguration(source: ConfigurationSource & {
|
|
70
|
+
explicit: true;
|
|
71
|
+
}, logger: Logger, options?: LoadResourceOptions): Promise<LoadedConfiguration>;
|
|
72
|
+
export declare function loadConfiguration(source: ConfigurationSource, logger: Logger, options?: LoadResourceOptions): Promise<LoadedConfiguration | undefined>;
|
|
73
|
+
/**
|
|
74
|
+
* Checks a parsed configuration against the options the generator reads.
|
|
75
|
+
*
|
|
76
|
+
* Shape errors throw: a block the generator cannot read is a request the user
|
|
77
|
+
* made and the generator would otherwise drop. Unknown keys only warn, so a
|
|
78
|
+
* configuration written for a newer version still generates.
|
|
79
|
+
*
|
|
80
|
+
* @param parsed - The parsed configuration document
|
|
81
|
+
* @param origin - Where it was read from, for messages
|
|
82
|
+
* @returns The same configuration, typed, and a warning for every key the
|
|
83
|
+
* generator ignores
|
|
84
|
+
* @throws GeneratorError of kind `configuration` when a block or option has
|
|
85
|
+
* a shape the generator cannot read
|
|
86
|
+
*/
|
|
87
|
+
export declare function validateConfiguration(parsed: unknown, origin: string): LoadedConfiguration;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OpenAPI } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { LoadResourceOptions } from './resources.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Loads and parses an OpenAPI 3 document.
|
|
5
|
+
*
|
|
6
|
+
* Every failure is a {@link GeneratorError} of kind `input` whose message
|
|
7
|
+
* names the document: it cannot be read or fetched, it is neither JSON nor
|
|
8
|
+
* YAML, or it is not an OpenAPI 3 document. A Swagger 2.0 document is
|
|
9
|
+
* refused rather than generated into clients without models.
|
|
10
|
+
*
|
|
11
|
+
* @param inputPath - The path or http(s) URL of the document
|
|
12
|
+
* @param options - Headers and timeout for an http(s) document
|
|
13
|
+
* @returns The parsed document; `paths` is an empty object when it has none
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseOpenAPI(inputPath: string, options?: LoadResourceOptions): Promise<OpenAPI>;
|
|
16
|
+
/**
|
|
17
|
+
* Checks that a parsed document is an OpenAPI 3 document the generator reads.
|
|
18
|
+
*
|
|
19
|
+
* @param document - The parsed document
|
|
20
|
+
* @param source - Where it came from, for messages
|
|
21
|
+
* @returns The document, with `paths` defaulted to an empty object
|
|
22
|
+
* @throws GeneratorError when it is not an OpenAPI 3.x document
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateOpenAPIDocument(document: unknown, source: string): OpenAPI;
|
|
25
|
+
/**
|
|
26
|
+
* Parses already-loaded document content in whichever format it is written.
|
|
27
|
+
*
|
|
28
|
+
* Callers name the source in their own error, so a failure here carries only
|
|
29
|
+
* what went wrong with the text.
|
|
30
|
+
*
|
|
31
|
+
* @param content - The document text
|
|
32
|
+
* @returns The parsed document
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseContent<T>(content: string): T;
|
|
35
|
+
export declare enum FileFormat {
|
|
36
|
+
JSON = "json",
|
|
37
|
+
YAML = "yaml"
|
|
38
|
+
}
|
|
39
|
+
export declare function inferFileFormat(content: string): FileFormat;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OpenAPI } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { LoadResourceOptions } from './resources.js';
|
|
3
|
+
/**
|
|
4
|
+
* Loads and parses an OpenAPI 3 document.
|
|
5
|
+
*
|
|
6
|
+
* Every failure is a {@link GeneratorError} of kind `input` whose message
|
|
7
|
+
* names the document: it cannot be read or fetched, it is neither JSON nor
|
|
8
|
+
* YAML, or it is not an OpenAPI 3 document. A Swagger 2.0 document is
|
|
9
|
+
* refused rather than generated into clients without models.
|
|
10
|
+
*
|
|
11
|
+
* @param inputPath - The path or http(s) URL of the document
|
|
12
|
+
* @param options - Headers and timeout for an http(s) document
|
|
13
|
+
* @returns The parsed document; `paths` is an empty object when it has none
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseOpenAPI(inputPath: string, options?: LoadResourceOptions): Promise<OpenAPI>;
|
|
16
|
+
/**
|
|
17
|
+
* Checks that a parsed document is an OpenAPI 3 document the generator reads.
|
|
18
|
+
*
|
|
19
|
+
* @param document - The parsed document
|
|
20
|
+
* @param source - Where it came from, for messages
|
|
21
|
+
* @returns The document, with `paths` defaulted to an empty object
|
|
22
|
+
* @throws GeneratorError when it is not an OpenAPI 3.x document
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateOpenAPIDocument(document: unknown, source: string): OpenAPI;
|
|
25
|
+
/**
|
|
26
|
+
* Parses already-loaded document content in whichever format it is written.
|
|
27
|
+
*
|
|
28
|
+
* Callers name the source in their own error, so a failure here carries only
|
|
29
|
+
* what went wrong with the text.
|
|
30
|
+
*
|
|
31
|
+
* @param content - The document text
|
|
32
|
+
* @returns The parsed document
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseContent<T>(content: string): T;
|
|
35
|
+
export declare enum FileFormat {
|
|
36
|
+
JSON = "json",
|
|
37
|
+
YAML = "yaml"
|
|
38
|
+
}
|
|
39
|
+
export declare function inferFileFormat(content: string): FileFormat;
|