@ahoo-wang/wow-generator 10.0.0-beta.1 → 10.0.0-beta.10
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/README.md +2 -1
- package/README.zh-CN.md +1 -1
- package/dist/analysis/clientNames.d.cts +0 -9
- package/dist/analysis/clientNames.d.ts +0 -9
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2 -2
- package/dist/{codeGenerator-Cxlr_VOh.js → codeGenerator-CXowDsB9.js} +1233 -867
- package/dist/codeGenerator-CXowDsB9.js.map +1 -0
- package/dist/codeGenerator-q59QJpfT.cjs +38 -0
- package/dist/codeGenerator-q59QJpfT.cjs.map +1 -0
- package/dist/emitters/manifest/aggregate.d.cts +4 -0
- package/dist/emitters/manifest/aggregate.d.ts +4 -0
- package/dist/emitters/manifest/commandClient.d.cts +4 -0
- package/dist/emitters/manifest/commandClient.d.ts +4 -0
- package/dist/emitters/manifest/contextClient.d.cts +8 -0
- package/dist/emitters/manifest/contextClient.d.ts +8 -0
- package/dist/emitters/manifest/contract.d.cts +17 -0
- package/dist/emitters/manifest/contract.d.ts +17 -0
- package/dist/emitters/manifest/generatedModule.d.cts +19 -0
- package/dist/emitters/manifest/generatedModule.d.ts +19 -0
- package/dist/emitters/manifest/queryClient.d.cts +4 -0
- package/dist/emitters/manifest/queryClient.d.ts +4 -0
- package/dist/emitters/manifest/routing.d.cts +9 -0
- package/dist/emitters/manifest/routing.d.ts +9 -0
- package/dist/emitters/manifest/serviceRoutes.d.cts +11 -0
- package/dist/emitters/manifest/serviceRoutes.d.ts +11 -0
- package/dist/emitters/manifest/textNumbers.d.cts +24 -0
- package/dist/emitters/manifest/textNumbers.d.ts +24 -0
- package/dist/emitters/manifest/typeDeclarations.d.cts +4 -0
- package/dist/emitters/manifest/typeDeclarations.d.ts +4 -0
- package/dist/emitters/manifestClients.d.cts +1 -5
- package/dist/emitters/manifestClients.d.ts +1 -5
- package/dist/emitters/models.d.cts +1 -1
- package/dist/emitters/models.d.ts +1 -1
- package/dist/emitters/target.d.cts +1 -1
- package/dist/emitters/target.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/manifest/aggregates.d.cts +6 -0
- package/dist/manifest/aggregates.d.ts +6 -0
- package/dist/manifest/analyze.d.cts +1 -186
- package/dist/manifest/analyze.d.ts +1 -186
- package/dist/manifest/document.d.cts +4 -0
- package/dist/manifest/document.d.ts +4 -0
- package/dist/manifest/model.d.cts +180 -0
- package/dist/manifest/model.d.ts +180 -0
- package/dist/manifest/names.d.cts +30 -0
- package/dist/manifest/names.d.ts +30 -0
- package/dist/manifest/schemaTypes.d.cts +46 -0
- package/dist/manifest/schemaTypes.d.ts +46 -0
- package/dist/manifest/serviceRoutes.d.cts +45 -0
- package/dist/manifest/serviceRoutes.d.ts +45 -0
- package/dist/manifest/textNumbers.d.cts +108 -0
- package/dist/manifest/textNumbers.d.ts +108 -0
- package/dist/manifest/typeText.d.cts +11 -0
- package/dist/manifest/typeText.d.ts +11 -0
- package/dist/naming/naming.d.cts +9 -0
- package/dist/naming/naming.d.ts +9 -0
- package/dist/types/indexSignature.d.cts +18 -0
- package/dist/types/indexSignature.d.ts +18 -0
- package/dist/types/literalTypes.d.cts +11 -0
- package/dist/types/literalTypes.d.ts +11 -0
- package/dist/types/typeContext.d.cts +66 -0
- package/dist/types/typeContext.d.ts +66 -0
- package/dist/types/typeResolver.d.cts +2 -101
- package/dist/types/typeResolver.d.ts +2 -101
- package/package.json +14 -14
- package/dist/codeGenerator-CADTvm2G.cjs +0 -37
- package/dist/codeGenerator-CADTvm2G.cjs.map +0 -1
- package/dist/codeGenerator-Cxlr_VOh.js.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { JsonSchema } from './document.cjs';
|
|
2
|
+
import { PropertyModel } from './model.cjs';
|
|
3
|
+
/**
|
|
4
|
+
* Turns the schemas of a Manifest into types: names for `$defs` keys and
|
|
5
|
+
* type text for any schema.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SchemaTypes {
|
|
8
|
+
readonly defs: Readonly<Record<string, JsonSchema>>;
|
|
9
|
+
readonly names: Map<string, string>;
|
|
10
|
+
readonly warnings: string[];
|
|
11
|
+
constructor(defs: Readonly<Record<string, JsonSchema>>);
|
|
12
|
+
/**
|
|
13
|
+
* Whether `key` is a parameterized type's, such as
|
|
14
|
+
* `java.util.Map(java.lang.String,java.lang.Object)`: its schema is written
|
|
15
|
+
* in place (`Record<string, unknown>`), never declared, since a name taken
|
|
16
|
+
* from its last type argument would shadow a global such as `Object`.
|
|
17
|
+
*/
|
|
18
|
+
inlined(key: string): boolean;
|
|
19
|
+
/** Names each key after its simple class name, qualified as far as needed to be unique and not `reserved`. */
|
|
20
|
+
name(keys: readonly string[], reserved: ReadonlySet<string>): void;
|
|
21
|
+
/** The schema of a key, or undefined with a warning. */
|
|
22
|
+
schemaOf(key: string): JsonSchema | undefined;
|
|
23
|
+
/** The schema a reference resolves to, through `$ref`s. */
|
|
24
|
+
resolve(schema: JsonSchema, seen?: Set<string>): JsonSchema;
|
|
25
|
+
/** The keys a schema refers to, directly. */
|
|
26
|
+
references(schema: unknown, into?: Set<string>): Set<string>;
|
|
27
|
+
/** The keys a schema refers to by name: an inlined key's own, in its place. */
|
|
28
|
+
namedReferences(schema: unknown): Set<string>;
|
|
29
|
+
/** Every key reachable from `roots`. */
|
|
30
|
+
closure(roots: Iterable<string>): string[];
|
|
31
|
+
/** The type of a reference to `key`. */
|
|
32
|
+
refType(key: string, where: string): string;
|
|
33
|
+
/** The type text of a schema. */
|
|
34
|
+
type(schema: unknown, where: string): string;
|
|
35
|
+
private primitive;
|
|
36
|
+
/** An inline object type. */
|
|
37
|
+
private objectType;
|
|
38
|
+
/** The properties of an object schema, in their order. */
|
|
39
|
+
properties(schema: JsonSchema, where: string): PropertyModel[];
|
|
40
|
+
/** The type of an object's additional properties, if it allows a typed set. */
|
|
41
|
+
additional(schema: JsonSchema, where: string): string | undefined;
|
|
42
|
+
/** Whether a schema is an object with properties, so it names an interface. */
|
|
43
|
+
isInterface(schema: JsonSchema): boolean;
|
|
44
|
+
/** The `state.*` paths of a state schema a query can filter and sort on. */
|
|
45
|
+
fields(schema: JsonSchema, prefix: string, depth?: number, seen?: Set<string>): string[];
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { JsonSchema } from './document.js';
|
|
2
|
+
import { PropertyModel } from './model.js';
|
|
3
|
+
/**
|
|
4
|
+
* Turns the schemas of a Manifest into types: names for `$defs` keys and
|
|
5
|
+
* type text for any schema.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SchemaTypes {
|
|
8
|
+
readonly defs: Readonly<Record<string, JsonSchema>>;
|
|
9
|
+
readonly names: Map<string, string>;
|
|
10
|
+
readonly warnings: string[];
|
|
11
|
+
constructor(defs: Readonly<Record<string, JsonSchema>>);
|
|
12
|
+
/**
|
|
13
|
+
* Whether `key` is a parameterized type's, such as
|
|
14
|
+
* `java.util.Map(java.lang.String,java.lang.Object)`: its schema is written
|
|
15
|
+
* in place (`Record<string, unknown>`), never declared, since a name taken
|
|
16
|
+
* from its last type argument would shadow a global such as `Object`.
|
|
17
|
+
*/
|
|
18
|
+
inlined(key: string): boolean;
|
|
19
|
+
/** Names each key after its simple class name, qualified as far as needed to be unique and not `reserved`. */
|
|
20
|
+
name(keys: readonly string[], reserved: ReadonlySet<string>): void;
|
|
21
|
+
/** The schema of a key, or undefined with a warning. */
|
|
22
|
+
schemaOf(key: string): JsonSchema | undefined;
|
|
23
|
+
/** The schema a reference resolves to, through `$ref`s. */
|
|
24
|
+
resolve(schema: JsonSchema, seen?: Set<string>): JsonSchema;
|
|
25
|
+
/** The keys a schema refers to, directly. */
|
|
26
|
+
references(schema: unknown, into?: Set<string>): Set<string>;
|
|
27
|
+
/** The keys a schema refers to by name: an inlined key's own, in its place. */
|
|
28
|
+
namedReferences(schema: unknown): Set<string>;
|
|
29
|
+
/** Every key reachable from `roots`. */
|
|
30
|
+
closure(roots: Iterable<string>): string[];
|
|
31
|
+
/** The type of a reference to `key`. */
|
|
32
|
+
refType(key: string, where: string): string;
|
|
33
|
+
/** The type text of a schema. */
|
|
34
|
+
type(schema: unknown, where: string): string;
|
|
35
|
+
private primitive;
|
|
36
|
+
/** An inline object type. */
|
|
37
|
+
private objectType;
|
|
38
|
+
/** The properties of an object schema, in their order. */
|
|
39
|
+
properties(schema: JsonSchema, where: string): PropertyModel[];
|
|
40
|
+
/** The type of an object's additional properties, if it allows a typed set. */
|
|
41
|
+
additional(schema: JsonSchema, where: string): string | undefined;
|
|
42
|
+
/** Whether a schema is an object with properties, so it names an interface. */
|
|
43
|
+
isInterface(schema: JsonSchema): boolean;
|
|
44
|
+
/** The `state.*` paths of a state schema a query can filter and sort on. */
|
|
45
|
+
fields(schema: JsonSchema, prefix: string, depth?: number, seen?: Set<string>): string[];
|
|
46
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ServiceRouteManifest } from '@ahoo-wang/wow-client';
|
|
2
|
+
import { ManifestContext } from './document.cjs';
|
|
3
|
+
import { TextNumbers, TextNumbersModel } from './textNumbers.cjs';
|
|
4
|
+
/** A parameter of a service route: a path variable or a query parameter, and its TypeScript type. */
|
|
5
|
+
export interface RouteParameterModel {
|
|
6
|
+
/** As the route names it: its path variable or its query parameter. */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** Its name in the method ({@link routeParameterIdentifier}). */
|
|
9
|
+
readonly identifier: string;
|
|
10
|
+
readonly location: 'path' | 'query';
|
|
11
|
+
readonly type: string;
|
|
12
|
+
readonly required: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** A service route: its name, where it is served, its parameters and the types of its body and its answer. */
|
|
15
|
+
export interface ServiceRouteModel {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly method: string;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly description?: string;
|
|
20
|
+
readonly deprecated: boolean;
|
|
21
|
+
readonly parameters: readonly RouteParameterModel[];
|
|
22
|
+
/** The body's type; absent when the route takes none. */
|
|
23
|
+
readonly requestType?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The answer's type, `| undefined` when the route may answer `204 No
|
|
26
|
+
* Content` for an absent answer (`responseOptional`); absent when the route
|
|
27
|
+
* answers 204 alone.
|
|
28
|
+
*/
|
|
29
|
+
readonly responseType?: string;
|
|
30
|
+
/** The exact numbers of its body and of its answer. */
|
|
31
|
+
readonly textNumbers?: {
|
|
32
|
+
readonly request?: TextNumbersModel;
|
|
33
|
+
readonly response?: TextNumbersModel;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** What a service route's model needs of a Manifest's types: the TypeScript type of a schema. */
|
|
37
|
+
interface RouteTypes {
|
|
38
|
+
type(schema: unknown, where: string): string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The model of one service route of `context`, its types read by `types`
|
|
42
|
+
* and its exact numbers by `numbers`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function serviceRouteModel(types: RouteTypes, numbers: Pick<TextNumbers, 'marks'>, context: Pick<ManifestContext, 'name'>, route: ServiceRouteManifest): ServiceRouteModel;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ServiceRouteManifest } from '@ahoo-wang/wow-client';
|
|
2
|
+
import { ManifestContext } from './document.js';
|
|
3
|
+
import { TextNumbers, TextNumbersModel } from './textNumbers.js';
|
|
4
|
+
/** A parameter of a service route: a path variable or a query parameter, and its TypeScript type. */
|
|
5
|
+
export interface RouteParameterModel {
|
|
6
|
+
/** As the route names it: its path variable or its query parameter. */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** Its name in the method ({@link routeParameterIdentifier}). */
|
|
9
|
+
readonly identifier: string;
|
|
10
|
+
readonly location: 'path' | 'query';
|
|
11
|
+
readonly type: string;
|
|
12
|
+
readonly required: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** A service route: its name, where it is served, its parameters and the types of its body and its answer. */
|
|
15
|
+
export interface ServiceRouteModel {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly method: string;
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly description?: string;
|
|
20
|
+
readonly deprecated: boolean;
|
|
21
|
+
readonly parameters: readonly RouteParameterModel[];
|
|
22
|
+
/** The body's type; absent when the route takes none. */
|
|
23
|
+
readonly requestType?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The answer's type, `| undefined` when the route may answer `204 No
|
|
26
|
+
* Content` for an absent answer (`responseOptional`); absent when the route
|
|
27
|
+
* answers 204 alone.
|
|
28
|
+
*/
|
|
29
|
+
readonly responseType?: string;
|
|
30
|
+
/** The exact numbers of its body and of its answer. */
|
|
31
|
+
readonly textNumbers?: {
|
|
32
|
+
readonly request?: TextNumbersModel;
|
|
33
|
+
readonly response?: TextNumbersModel;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** What a service route's model needs of a Manifest's types: the TypeScript type of a schema. */
|
|
37
|
+
interface RouteTypes {
|
|
38
|
+
type(schema: unknown, where: string): string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The model of one service route of `context`, its types read by `types`
|
|
42
|
+
* and its exact numbers by `numbers`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function serviceRouteModel(types: RouteTypes, numbers: Pick<TextNumbers, 'marks'>, context: Pick<ManifestContext, 'name'>, route: ServiceRouteManifest): ServiceRouteModel;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { JsonSchema } from './document.cjs';
|
|
2
|
+
/** The number formats a client reads and writes as their exact text: a `string` in the generated types. */
|
|
3
|
+
export declare const TEXT_NUMBER_FORMATS: ReadonlySet<string>;
|
|
4
|
+
/**
|
|
5
|
+
* The exact numbers of a value, as `@ahoo-wang/wow-client`'s `TextNumbers`
|
|
6
|
+
* holds them:
|
|
7
|
+
*
|
|
8
|
+
* - `true`: the value is such a number;
|
|
9
|
+
* - `members`: its members' marks by name, `'*'` for every item or map value;
|
|
10
|
+
* - `lazy`: the marks of a recursive type, the constant that holds them;
|
|
11
|
+
* - `or`: an exact number, or an object or array marked `or`;
|
|
12
|
+
* - `by`: an object's marks chosen by the string value of its member `by`.
|
|
13
|
+
*/
|
|
14
|
+
export type TextNumbersModel = true | {
|
|
15
|
+
readonly members: Readonly<Record<string, TextNumbersModel>>;
|
|
16
|
+
} | {
|
|
17
|
+
readonly lazy: TextNumbersConstant;
|
|
18
|
+
} | {
|
|
19
|
+
readonly or: TextNumbersModel;
|
|
20
|
+
} | {
|
|
21
|
+
readonly by: string;
|
|
22
|
+
readonly cases: Readonly<Record<string, TextNumbersModel>>;
|
|
23
|
+
};
|
|
24
|
+
/** Where a recursive type's marks are declared: a constant of its context's `textNumbers.ts`. */
|
|
25
|
+
export interface TextNumbersConstant {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly file: string;
|
|
28
|
+
}
|
|
29
|
+
/** A declared recursive type's marks. */
|
|
30
|
+
export interface TextNumbersDeclaration extends TextNumbersConstant {
|
|
31
|
+
/** The type's `$defs` key. */
|
|
32
|
+
readonly key: string;
|
|
33
|
+
/** It is the type with what an `allOf` says beside it, not the type alone. */
|
|
34
|
+
readonly beside?: true;
|
|
35
|
+
readonly marks: TextNumbersModel;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Derives the exact numbers of a Manifest's schemas: each `integer` or
|
|
39
|
+
* `number` of a {@link TEXT_NUMBER_FORMATS} format, through objects, arrays,
|
|
40
|
+
* maps, references and their recursion, and the alternatives of a union,
|
|
41
|
+
* kept apart by their JSON kind or by a member with a constant value. A
|
|
42
|
+
* union whose alternatives read one number differently, with no such member,
|
|
43
|
+
* is a specification error: no reader could tell which applies.
|
|
44
|
+
*/
|
|
45
|
+
export declare class TextNumbers {
|
|
46
|
+
private readonly defs;
|
|
47
|
+
private readonly constantOf;
|
|
48
|
+
private readonly shapes;
|
|
49
|
+
private readonly reading;
|
|
50
|
+
private readonly lazy;
|
|
51
|
+
/**
|
|
52
|
+
* The alternatives set beside a union's cases, which may keep their own
|
|
53
|
+
* number only; whether they hold more is asked once every type they reach
|
|
54
|
+
* is read ({@link settle}).
|
|
55
|
+
*/
|
|
56
|
+
private readonly setAside;
|
|
57
|
+
/**
|
|
58
|
+
* A recursive type with what an `allOf` says beside it, by an id of both:
|
|
59
|
+
* its type's key, and its own shape. It recurs as its type does, so it is
|
|
60
|
+
* declared as a constant of its own.
|
|
61
|
+
*/
|
|
62
|
+
private readonly variants;
|
|
63
|
+
/**
|
|
64
|
+
* @param defs - The Manifest's `$defs`
|
|
65
|
+
* @param constantOf - Where the marks of the recursive type `key` are declared
|
|
66
|
+
*/
|
|
67
|
+
constructor(defs: Readonly<Record<string, JsonSchema>>, constantOf: (key: string) => TextNumbersConstant);
|
|
68
|
+
/**
|
|
69
|
+
* The marks of `schema`, or undefined when it has no exact number.
|
|
70
|
+
*
|
|
71
|
+
* @param where - What the schema is, for an error
|
|
72
|
+
* @throws GeneratorError of kind `specification` for a union no member tells apart
|
|
73
|
+
*/
|
|
74
|
+
marks(schema: unknown, where: string): TextNumbersModel | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Refuses an alternative set beside a union's cases that holds exact numbers
|
|
77
|
+
* besides its own, which no mark could choose. {@link marks} runs it once its
|
|
78
|
+
* schema is read: every type an alternative reaches is then known, where a
|
|
79
|
+
* type still being read would have answered that it holds none.
|
|
80
|
+
*/
|
|
81
|
+
private settle;
|
|
82
|
+
/**
|
|
83
|
+
* The marks of every recursive type a mark refers to, in the order of their
|
|
84
|
+
* names, each declared once.
|
|
85
|
+
*/
|
|
86
|
+
declarations(): TextNumbersDeclaration[];
|
|
87
|
+
private shape;
|
|
88
|
+
/** The shape of the type `key`: a reference while it is still being read. */
|
|
89
|
+
private shapeOf;
|
|
90
|
+
/** The shape of a value any one of `alternatives` describes. */
|
|
91
|
+
private either;
|
|
92
|
+
/**
|
|
93
|
+
* The member every object among `alternatives` has a constant string value
|
|
94
|
+
* of, a different one each: the discriminator Jackson writes them by.
|
|
95
|
+
*/
|
|
96
|
+
private discriminant;
|
|
97
|
+
/** The constant string value of `alternative`'s member `name`, if it has one. */
|
|
98
|
+
private constant;
|
|
99
|
+
/** The properties of an object schema, through its references and `allOf` parts. */
|
|
100
|
+
private properties;
|
|
101
|
+
/** The shape of a value either `left` or `right` describes; a {@link Disagreement} where they read a number differently. */
|
|
102
|
+
private merge;
|
|
103
|
+
/** A reference's shape where it is known; else a disagreement unless the other side reads no number. */
|
|
104
|
+
private expand;
|
|
105
|
+
private toMarks;
|
|
106
|
+
/** Whether a shape reaches an exact number, following its references once each. */
|
|
107
|
+
private exact;
|
|
108
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { JsonSchema } from './document.js';
|
|
2
|
+
/** The number formats a client reads and writes as their exact text: a `string` in the generated types. */
|
|
3
|
+
export declare const TEXT_NUMBER_FORMATS: ReadonlySet<string>;
|
|
4
|
+
/**
|
|
5
|
+
* The exact numbers of a value, as `@ahoo-wang/wow-client`'s `TextNumbers`
|
|
6
|
+
* holds them:
|
|
7
|
+
*
|
|
8
|
+
* - `true`: the value is such a number;
|
|
9
|
+
* - `members`: its members' marks by name, `'*'` for every item or map value;
|
|
10
|
+
* - `lazy`: the marks of a recursive type, the constant that holds them;
|
|
11
|
+
* - `or`: an exact number, or an object or array marked `or`;
|
|
12
|
+
* - `by`: an object's marks chosen by the string value of its member `by`.
|
|
13
|
+
*/
|
|
14
|
+
export type TextNumbersModel = true | {
|
|
15
|
+
readonly members: Readonly<Record<string, TextNumbersModel>>;
|
|
16
|
+
} | {
|
|
17
|
+
readonly lazy: TextNumbersConstant;
|
|
18
|
+
} | {
|
|
19
|
+
readonly or: TextNumbersModel;
|
|
20
|
+
} | {
|
|
21
|
+
readonly by: string;
|
|
22
|
+
readonly cases: Readonly<Record<string, TextNumbersModel>>;
|
|
23
|
+
};
|
|
24
|
+
/** Where a recursive type's marks are declared: a constant of its context's `textNumbers.ts`. */
|
|
25
|
+
export interface TextNumbersConstant {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly file: string;
|
|
28
|
+
}
|
|
29
|
+
/** A declared recursive type's marks. */
|
|
30
|
+
export interface TextNumbersDeclaration extends TextNumbersConstant {
|
|
31
|
+
/** The type's `$defs` key. */
|
|
32
|
+
readonly key: string;
|
|
33
|
+
/** It is the type with what an `allOf` says beside it, not the type alone. */
|
|
34
|
+
readonly beside?: true;
|
|
35
|
+
readonly marks: TextNumbersModel;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Derives the exact numbers of a Manifest's schemas: each `integer` or
|
|
39
|
+
* `number` of a {@link TEXT_NUMBER_FORMATS} format, through objects, arrays,
|
|
40
|
+
* maps, references and their recursion, and the alternatives of a union,
|
|
41
|
+
* kept apart by their JSON kind or by a member with a constant value. A
|
|
42
|
+
* union whose alternatives read one number differently, with no such member,
|
|
43
|
+
* is a specification error: no reader could tell which applies.
|
|
44
|
+
*/
|
|
45
|
+
export declare class TextNumbers {
|
|
46
|
+
private readonly defs;
|
|
47
|
+
private readonly constantOf;
|
|
48
|
+
private readonly shapes;
|
|
49
|
+
private readonly reading;
|
|
50
|
+
private readonly lazy;
|
|
51
|
+
/**
|
|
52
|
+
* The alternatives set beside a union's cases, which may keep their own
|
|
53
|
+
* number only; whether they hold more is asked once every type they reach
|
|
54
|
+
* is read ({@link settle}).
|
|
55
|
+
*/
|
|
56
|
+
private readonly setAside;
|
|
57
|
+
/**
|
|
58
|
+
* A recursive type with what an `allOf` says beside it, by an id of both:
|
|
59
|
+
* its type's key, and its own shape. It recurs as its type does, so it is
|
|
60
|
+
* declared as a constant of its own.
|
|
61
|
+
*/
|
|
62
|
+
private readonly variants;
|
|
63
|
+
/**
|
|
64
|
+
* @param defs - The Manifest's `$defs`
|
|
65
|
+
* @param constantOf - Where the marks of the recursive type `key` are declared
|
|
66
|
+
*/
|
|
67
|
+
constructor(defs: Readonly<Record<string, JsonSchema>>, constantOf: (key: string) => TextNumbersConstant);
|
|
68
|
+
/**
|
|
69
|
+
* The marks of `schema`, or undefined when it has no exact number.
|
|
70
|
+
*
|
|
71
|
+
* @param where - What the schema is, for an error
|
|
72
|
+
* @throws GeneratorError of kind `specification` for a union no member tells apart
|
|
73
|
+
*/
|
|
74
|
+
marks(schema: unknown, where: string): TextNumbersModel | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Refuses an alternative set beside a union's cases that holds exact numbers
|
|
77
|
+
* besides its own, which no mark could choose. {@link marks} runs it once its
|
|
78
|
+
* schema is read: every type an alternative reaches is then known, where a
|
|
79
|
+
* type still being read would have answered that it holds none.
|
|
80
|
+
*/
|
|
81
|
+
private settle;
|
|
82
|
+
/**
|
|
83
|
+
* The marks of every recursive type a mark refers to, in the order of their
|
|
84
|
+
* names, each declared once.
|
|
85
|
+
*/
|
|
86
|
+
declarations(): TextNumbersDeclaration[];
|
|
87
|
+
private shape;
|
|
88
|
+
/** The shape of the type `key`: a reference while it is still being read. */
|
|
89
|
+
private shapeOf;
|
|
90
|
+
/** The shape of a value any one of `alternatives` describes. */
|
|
91
|
+
private either;
|
|
92
|
+
/**
|
|
93
|
+
* The member every object among `alternatives` has a constant string value
|
|
94
|
+
* of, a different one each: the discriminator Jackson writes them by.
|
|
95
|
+
*/
|
|
96
|
+
private discriminant;
|
|
97
|
+
/** The constant string value of `alternative`'s member `name`, if it has one. */
|
|
98
|
+
private constant;
|
|
99
|
+
/** The properties of an object schema, through its references and `allOf` parts. */
|
|
100
|
+
private properties;
|
|
101
|
+
/** The shape of a value either `left` or `right` describes; a {@link Disagreement} where they read a number differently. */
|
|
102
|
+
private merge;
|
|
103
|
+
/** A reference's shape where it is known; else a disagreement unless the other side reads no number. */
|
|
104
|
+
private expand;
|
|
105
|
+
private toMarks;
|
|
106
|
+
/** Whether a shape reaches an exact number, following its references once each. */
|
|
107
|
+
private exact;
|
|
108
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a type's text is a union or an intersection at its top level, so
|
|
3
|
+
* it needs parentheses to be one member of another: a `|` or `&` inside an
|
|
4
|
+
* object type, a type argument or a string literal does not count, nor the
|
|
5
|
+
* `>` of an arrow (`=>`) as a closing bracket. A literal left open runs to
|
|
6
|
+
* the end of the text, so nothing after its quote counts.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compound(type: string): boolean;
|
|
9
|
+
/** A union or an intersection, its members set apart when they are compound. */
|
|
10
|
+
export declare function join(members: string[], separator: ' | ' | ' & '): string;
|
|
11
|
+
export declare function literal(value: unknown): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a type's text is a union or an intersection at its top level, so
|
|
3
|
+
* it needs parentheses to be one member of another: a `|` or `&` inside an
|
|
4
|
+
* object type, a type argument or a string literal does not count, nor the
|
|
5
|
+
* `>` of an arrow (`=>`) as a closing bracket. A literal left open runs to
|
|
6
|
+
* the end of the text, so nothing after its quote counts.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compound(type: string): boolean;
|
|
9
|
+
/** A union or an intersection, its members set apart when they are compound. */
|
|
10
|
+
export declare function join(members: string[], separator: ' | ' | ' & '): string;
|
|
11
|
+
export declare function literal(value: unknown): string;
|
package/dist/naming/naming.d.cts
CHANGED
|
@@ -100,3 +100,12 @@ export declare function enumMemberKey(name: string): string;
|
|
|
100
100
|
* @returns The escaped string literal, quotes included
|
|
101
101
|
*/
|
|
102
102
|
export declare function quoteStringLiteral(value: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Turns a parameter name from the document into a unique parameter
|
|
105
|
+
* identifier: `item-id` → `itemId`, and `id` twice → `id`, `id2`.
|
|
106
|
+
*
|
|
107
|
+
* @param name - The name the document uses
|
|
108
|
+
* @param used - The identifiers the method already uses; updated
|
|
109
|
+
* @returns The identifier
|
|
110
|
+
*/
|
|
111
|
+
export declare function uniqueParameterName(name: string, used: Set<string>): string;
|
package/dist/naming/naming.d.ts
CHANGED
|
@@ -100,3 +100,12 @@ export declare function enumMemberKey(name: string): string;
|
|
|
100
100
|
* @returns The escaped string literal, quotes included
|
|
101
101
|
*/
|
|
102
102
|
export declare function quoteStringLiteral(value: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Turns a parameter name from the document into a unique parameter
|
|
105
|
+
* identifier: `item-id` → `itemId`, and `id` twice → `id`, `id2`.
|
|
106
|
+
*
|
|
107
|
+
* @param name - The name the document uses
|
|
108
|
+
* @param used - The identifiers the method already uses; updated
|
|
109
|
+
* @returns The identifier
|
|
110
|
+
*/
|
|
111
|
+
export declare function uniqueParameterName(name: string, used: Set<string>): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Components, Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
/**
|
|
3
|
+
* Chooses the intersection representation over an interface with an index
|
|
4
|
+
* signature.
|
|
5
|
+
*
|
|
6
|
+
* An interface may only carry a named property whose type is assignable to
|
|
7
|
+
* its index signature (TS2411). Every generated property is required, so
|
|
8
|
+
* only a clash that can be PROVEN off the schemas moves one - see
|
|
9
|
+
* {@link clashesWithIndexSignature}. Anything undecided keeps the interface,
|
|
10
|
+
* which is the only form that can reference itself through an index
|
|
11
|
+
* signature: an alias reaching itself through `Record` is circular (TS2456),
|
|
12
|
+
* which is what a dictionary of its own type would generate.
|
|
13
|
+
*
|
|
14
|
+
* @param schema - The object schema to represent
|
|
15
|
+
* @param components - The components a reference resolves against
|
|
16
|
+
* @returns True when the schema needs the intersection form
|
|
17
|
+
*/
|
|
18
|
+
export declare function requiresAdditionalPropertiesIntersection(schema: Schema, components?: Components): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Components, Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
/**
|
|
3
|
+
* Chooses the intersection representation over an interface with an index
|
|
4
|
+
* signature.
|
|
5
|
+
*
|
|
6
|
+
* An interface may only carry a named property whose type is assignable to
|
|
7
|
+
* its index signature (TS2411). Every generated property is required, so
|
|
8
|
+
* only a clash that can be PROVEN off the schemas moves one - see
|
|
9
|
+
* {@link clashesWithIndexSignature}. Anything undecided keeps the interface,
|
|
10
|
+
* which is the only form that can reference itself through an index
|
|
11
|
+
* signature: an alias reaching itself through `Record` is circular (TS2456),
|
|
12
|
+
* which is what a dictionary of its own type would generate.
|
|
13
|
+
*
|
|
14
|
+
* @param schema - The object schema to represent
|
|
15
|
+
* @param components - The components a reference resolves against
|
|
16
|
+
* @returns True when the schema needs the intersection form
|
|
17
|
+
*/
|
|
18
|
+
export declare function requiresAdditionalPropertiesIntersection(schema: Schema, components?: Components): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
export declare function matchesLiteralType(value: unknown, schema: Schema): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Renders a JSON value as a TypeScript literal type: a string in single
|
|
5
|
+
* quotes, escaped as ts-morph's printer escapes it, an array as a tuple, an
|
|
6
|
+
* object as an object type that no array matches.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value from the document
|
|
9
|
+
* @returns The literal type
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveLiteral(value: unknown): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schema } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
export declare function matchesLiteralType(value: unknown, schema: Schema): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Renders a JSON value as a TypeScript literal type: a string in single
|
|
5
|
+
* quotes, escaped as ts-morph's printer escapes it, an array as a tuple, an
|
|
6
|
+
* object as an object type that no array matches.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value from the document
|
|
9
|
+
* @returns The literal type
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveLiteral(value: unknown): string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Components, Reference } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { ModelInfo } from '../naming/modelInfo.cjs';
|
|
3
|
+
/** An import a resolved type needs: a name, and the alias it goes by. */
|
|
4
|
+
export interface ImportRequest {
|
|
5
|
+
readonly moduleSpecifier: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly alias?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A type expression, and the imports it needs. */
|
|
10
|
+
export interface ResolvedType {
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly imports: readonly ImportRequest[];
|
|
13
|
+
}
|
|
14
|
+
/** The imports a module already holds, as the resolver reads them. */
|
|
15
|
+
export interface ImportLookup {
|
|
16
|
+
entries(): readonly ImportRequest[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* What stays the same for every type of one document: its components, how a
|
|
20
|
+
* component names its model, and the model names declared at each path.
|
|
21
|
+
*/
|
|
22
|
+
export interface TypeContext {
|
|
23
|
+
readonly components?: Components;
|
|
24
|
+
/** The model a reference names. */
|
|
25
|
+
modelOf(reference: Reference): ModelInfo;
|
|
26
|
+
/** The models declared at a path, with their `EnumText` companions. */
|
|
27
|
+
namesAt(path: string): readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* How a document's component keys name models: `resolveModelInfo` and
|
|
31
|
+
* `resolveReferenceModelInfo` of `analysis/modelInfo.ts`.
|
|
32
|
+
*/
|
|
33
|
+
export interface ModelNaming {
|
|
34
|
+
ofKey(key: string): ModelInfo;
|
|
35
|
+
ofReference(reference: Reference, components?: Components): ModelInfo;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds the context of a document. The model names of each path are read
|
|
39
|
+
* once, on first use, rather than from every component for every reference.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTypeContext(components: Components | undefined, naming: ModelNaming): TypeContext;
|
|
42
|
+
/** Where a type is written. */
|
|
43
|
+
export interface TypeScope {
|
|
44
|
+
readonly context: TypeContext;
|
|
45
|
+
/**
|
|
46
|
+
* The declaration the type belongs to. An import never takes its name.
|
|
47
|
+
* With a `path`, it is a model: the models of that path are declared beside
|
|
48
|
+
* it, so a reference to one needs no import, and an import takes none of
|
|
49
|
+
* their names. Without, every referenced model is imported.
|
|
50
|
+
*/
|
|
51
|
+
readonly owner: {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly path?: string;
|
|
54
|
+
};
|
|
55
|
+
/** The specifier the module imports a model by. */
|
|
56
|
+
specifierOf(model: ModelInfo): string;
|
|
57
|
+
/** The imports the module holds. */
|
|
58
|
+
readonly imports: ImportLookup;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Global names generated code relies on. A model imported under one of these
|
|
62
|
+
* names would shadow the global, so the import is aliased instead: a model
|
|
63
|
+
* named `Response` must not turn `Promise<Response>` into a promise of the
|
|
64
|
+
* model.
|
|
65
|
+
*/
|
|
66
|
+
export declare const GLOBAL_TYPE_NAMES: readonly string[];
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Components, Reference } from '@ahoo-wang/fetcher-openapi';
|
|
2
|
+
import { ModelInfo } from '../naming/modelInfo.js';
|
|
3
|
+
/** An import a resolved type needs: a name, and the alias it goes by. */
|
|
4
|
+
export interface ImportRequest {
|
|
5
|
+
readonly moduleSpecifier: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly alias?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A type expression, and the imports it needs. */
|
|
10
|
+
export interface ResolvedType {
|
|
11
|
+
readonly text: string;
|
|
12
|
+
readonly imports: readonly ImportRequest[];
|
|
13
|
+
}
|
|
14
|
+
/** The imports a module already holds, as the resolver reads them. */
|
|
15
|
+
export interface ImportLookup {
|
|
16
|
+
entries(): readonly ImportRequest[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* What stays the same for every type of one document: its components, how a
|
|
20
|
+
* component names its model, and the model names declared at each path.
|
|
21
|
+
*/
|
|
22
|
+
export interface TypeContext {
|
|
23
|
+
readonly components?: Components;
|
|
24
|
+
/** The model a reference names. */
|
|
25
|
+
modelOf(reference: Reference): ModelInfo;
|
|
26
|
+
/** The models declared at a path, with their `EnumText` companions. */
|
|
27
|
+
namesAt(path: string): readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* How a document's component keys name models: `resolveModelInfo` and
|
|
31
|
+
* `resolveReferenceModelInfo` of `analysis/modelInfo.ts`.
|
|
32
|
+
*/
|
|
33
|
+
export interface ModelNaming {
|
|
34
|
+
ofKey(key: string): ModelInfo;
|
|
35
|
+
ofReference(reference: Reference, components?: Components): ModelInfo;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Builds the context of a document. The model names of each path are read
|
|
39
|
+
* once, on first use, rather than from every component for every reference.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createTypeContext(components: Components | undefined, naming: ModelNaming): TypeContext;
|
|
42
|
+
/** Where a type is written. */
|
|
43
|
+
export interface TypeScope {
|
|
44
|
+
readonly context: TypeContext;
|
|
45
|
+
/**
|
|
46
|
+
* The declaration the type belongs to. An import never takes its name.
|
|
47
|
+
* With a `path`, it is a model: the models of that path are declared beside
|
|
48
|
+
* it, so a reference to one needs no import, and an import takes none of
|
|
49
|
+
* their names. Without, every referenced model is imported.
|
|
50
|
+
*/
|
|
51
|
+
readonly owner: {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly path?: string;
|
|
54
|
+
};
|
|
55
|
+
/** The specifier the module imports a model by. */
|
|
56
|
+
specifierOf(model: ModelInfo): string;
|
|
57
|
+
/** The imports the module holds. */
|
|
58
|
+
readonly imports: ImportLookup;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Global names generated code relies on. A model imported under one of these
|
|
62
|
+
* names would shadow the global, so the import is aliased instead: a model
|
|
63
|
+
* named `Response` must not turn `Promise<Response>` into a promise of the
|
|
64
|
+
* model.
|
|
65
|
+
*/
|
|
66
|
+
export declare const GLOBAL_TYPE_NAMES: readonly string[];
|