@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.
Files changed (116) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +177 -0
  3. package/README.zh-CN.md +149 -0
  4. package/dist/analysis/aggregates.d.cts +21 -0
  5. package/dist/analysis/aggregates.d.ts +21 -0
  6. package/dist/analysis/analyze.d.cts +18 -0
  7. package/dist/analysis/analyze.d.ts +18 -0
  8. package/dist/analysis/apiClients.d.cts +14 -0
  9. package/dist/analysis/apiClients.d.ts +14 -0
  10. package/dist/analysis/clientNames.d.cts +55 -0
  11. package/dist/analysis/clientNames.d.ts +55 -0
  12. package/dist/analysis/model.d.cts +212 -0
  13. package/dist/analysis/model.d.ts +212 -0
  14. package/dist/analysis/modelInfo.d.cts +23 -0
  15. package/dist/analysis/modelInfo.d.ts +23 -0
  16. package/dist/analysis/models.d.cts +17 -0
  17. package/dist/analysis/models.d.ts +17 -0
  18. package/dist/api/configuration.d.cts +30 -0
  19. package/dist/api/configuration.d.ts +30 -0
  20. package/dist/api/errors.d.cts +41 -0
  21. package/dist/api/errors.d.ts +41 -0
  22. package/dist/api/logger.d.cts +61 -0
  23. package/dist/api/logger.d.ts +61 -0
  24. package/dist/api/options.d.cts +47 -0
  25. package/dist/api/options.d.ts +47 -0
  26. package/dist/cli/program.d.cts +35 -0
  27. package/dist/cli/program.d.ts +35 -0
  28. package/dist/cli/runGenerate.d.cts +65 -0
  29. package/dist/cli/runGenerate.d.ts +65 -0
  30. package/dist/cli.cjs +3 -0
  31. package/dist/cli.cjs.map +1 -0
  32. package/dist/cli.d.cts +6 -0
  33. package/dist/cli.d.ts +6 -0
  34. package/dist/cli.js +98 -0
  35. package/dist/cli.js.map +1 -0
  36. package/dist/codeGenerator-DpDTDC4o.cjs +23 -0
  37. package/dist/codeGenerator-DpDTDC4o.cjs.map +1 -0
  38. package/dist/codeGenerator-kyY9eLML.js +2583 -0
  39. package/dist/codeGenerator-kyY9eLML.js.map +1 -0
  40. package/dist/emit/importRegistry.d.cts +50 -0
  41. package/dist/emit/importRegistry.d.ts +50 -0
  42. package/dist/emit/imports.d.cts +49 -0
  43. package/dist/emit/imports.d.ts +49 -0
  44. package/dist/emit/jsdoc.d.cts +38 -0
  45. package/dist/emit/jsdoc.d.ts +38 -0
  46. package/dist/emit/moduleBuilder.d.cts +80 -0
  47. package/dist/emit/moduleBuilder.d.ts +80 -0
  48. package/dist/emitters/apiClients.d.cts +10 -0
  49. package/dist/emitters/apiClients.d.ts +10 -0
  50. package/dist/emitters/commandClients.d.cts +14 -0
  51. package/dist/emitters/commandClients.d.ts +14 -0
  52. package/dist/emitters/decorators.d.cts +83 -0
  53. package/dist/emitters/decorators.d.ts +83 -0
  54. package/dist/emitters/emit.d.cts +15 -0
  55. package/dist/emitters/emit.d.ts +15 -0
  56. package/dist/emitters/indexFiles.d.cts +12 -0
  57. package/dist/emitters/indexFiles.d.ts +12 -0
  58. package/dist/emitters/models.d.cts +77 -0
  59. package/dist/emitters/models.d.ts +77 -0
  60. package/dist/emitters/queryClients.d.cts +11 -0
  61. package/dist/emitters/queryClients.d.ts +11 -0
  62. package/dist/emitters/target.d.cts +14 -0
  63. package/dist/emitters/target.d.ts +14 -0
  64. package/dist/finalize/finalize.d.cts +16 -0
  65. package/dist/finalize/finalize.d.ts +16 -0
  66. package/dist/finalize/typeOnlyImports.d.cts +13 -0
  67. package/dist/finalize/typeOnlyImports.d.ts +13 -0
  68. package/dist/finalize/verification.d.cts +14 -0
  69. package/dist/finalize/verification.d.ts +14 -0
  70. package/dist/index.cjs +1 -0
  71. package/dist/index.d.cts +8 -0
  72. package/dist/index.d.ts +8 -0
  73. package/dist/index.js +2 -0
  74. package/dist/input/configuration.d.cts +87 -0
  75. package/dist/input/configuration.d.ts +87 -0
  76. package/dist/input/parsers.d.cts +39 -0
  77. package/dist/input/parsers.d.ts +39 -0
  78. package/dist/input/resources.d.cts +36 -0
  79. package/dist/input/resources.d.ts +36 -0
  80. package/dist/naming/modelInfo.d.cts +10 -0
  81. package/dist/naming/modelInfo.d.ts +10 -0
  82. package/dist/naming/naming.d.cts +102 -0
  83. package/dist/naming/naming.d.ts +102 -0
  84. package/dist/naming/order.d.cts +2 -0
  85. package/dist/naming/order.d.ts +2 -0
  86. package/dist/naming/paths.d.cts +27 -0
  87. package/dist/naming/paths.d.ts +27 -0
  88. package/dist/openapi/components.d.cts +55 -0
  89. package/dist/openapi/components.d.ts +55 -0
  90. package/dist/openapi/document.d.cts +25 -0
  91. package/dist/openapi/document.d.ts +25 -0
  92. package/dist/openapi/operations.d.cts +78 -0
  93. package/dist/openapi/operations.d.ts +78 -0
  94. package/dist/openapi/references.d.cts +28 -0
  95. package/dist/openapi/references.d.ts +28 -0
  96. package/dist/openapi/responses.d.cts +44 -0
  97. package/dist/openapi/responses.d.ts +44 -0
  98. package/dist/openapi/schemas.d.cts +112 -0
  99. package/dist/openapi/schemas.d.ts +112 -0
  100. package/dist/output/outputStore.d.cts +92 -0
  101. package/dist/output/outputStore.d.ts +92 -0
  102. package/dist/pipeline/codeGenerator.d.cts +61 -0
  103. package/dist/pipeline/codeGenerator.d.ts +61 -0
  104. package/dist/pipeline/seams.d.cts +29 -0
  105. package/dist/pipeline/seams.d.ts +29 -0
  106. package/dist/types/typeResolver.d.cts +124 -0
  107. package/dist/types/typeResolver.d.ts +124 -0
  108. package/dist/version.d.cts +2 -0
  109. package/dist/version.d.ts +2 -0
  110. package/dist/wow/conventions.d.cts +154 -0
  111. package/dist/wow/conventions.d.ts +154 -0
  112. package/dist/wow/model.d.cts +116 -0
  113. package/dist/wow/model.d.ts +116 -0
  114. package/dist/wow/resolveWowModel.d.cts +21 -0
  115. package/dist/wow/resolveWowModel.d.ts +21 -0
  116. package/package.json +108 -0
@@ -0,0 +1,78 @@
1
+ import { Components, HTTPMethod, Operation, Parameter, PathItem, Paths, Reference, Response, Schema } from '@ahoo-wang/fetcher-openapi';
2
+ /**
3
+ * Represents an HTTP method and its associated operation.
4
+ */
5
+ export interface MethodOperation {
6
+ /** The HTTP method */
7
+ method: HTTPMethod;
8
+ /** The OpenAPI operation */
9
+ operation: Operation;
10
+ }
11
+ export interface OperationEndpoint extends MethodOperation {
12
+ path: string;
13
+ }
14
+ export declare function operationEndpointComparator(left: OperationEndpoint, right: OperationEndpoint): number;
15
+ export declare function extractOperationEndpoints(paths: Paths, components?: Components): Array<OperationEndpoint>;
16
+ /**
17
+ * Extracts all operations from a path item.
18
+ * @param pathItem - The OpenAPI path item
19
+ * @returns Array of method-operation pairs
20
+ */
21
+ export declare function extractOperations(pathItem: PathItem): MethodOperation[];
22
+ /**
23
+ * Picks the status code of an operation's success response: `200`, else the
24
+ * lowest other 2xx code, else `2XX`.
25
+ *
26
+ * @param operation - The OpenAPI operation
27
+ * @returns The status code key, or undefined when no 2xx response is declared
28
+ */
29
+ export declare function okResponseStatus(operation: Operation): string | undefined;
30
+ /**
31
+ * Extracts the success response from an operation: `200`, else the lowest
32
+ * other 2xx response, else `2XX`.
33
+ * @param operation - The OpenAPI operation
34
+ * @param components - Optional components used to resolve response references
35
+ * @returns The success response or undefined if not found
36
+ */
37
+ export declare function extractOkResponse(operation: Operation, components?: Components): Response | Reference | undefined;
38
+ /**
39
+ * Extracts the JSON schema from the OK response of an operation.
40
+ * @param operation - The OpenAPI operation
41
+ * @param components - Optional components used to resolve response references
42
+ * @returns The JSON schema from the OK response or undefined if not found
43
+ */
44
+ export declare function extractOperationOkResponseJsonSchema(operation: Operation, components?: Components): Schema | Reference | undefined;
45
+ /**
46
+ * Extracts the parameters of an operation, references resolved, in document
47
+ * order.
48
+ * @param operation - The OpenAPI operation
49
+ * @param components - The OpenAPI components object used to resolve references
50
+ * @returns The parameters
51
+ */
52
+ export declare function extractParameters(operation: Operation, components: Components): Parameter[];
53
+ /**
54
+ * Extracts path parameters from an operation.
55
+ * @param operation - The OpenAPI operation to extract path parameters from
56
+ * @param components - The OpenAPI components object used to resolve references
57
+ * @returns Array of path parameters
58
+ */
59
+ export declare function extractPathParameters(operation: Operation, components: Components): Parameter[];
60
+ /**
61
+ * Orders path parameters as the path holds them, whatever order the document
62
+ * lists them in: `/cart/{id}/{customerId}` gives `id`, then `customerId`.
63
+ * A method takes them in this order, so a route that gains a variable keeps
64
+ * the arguments before it where they were. Parameters the path does not
65
+ * hold keep their order, after the others.
66
+ *
67
+ * @param path - The route, with `{name}` variables
68
+ * @param parameters - Its path parameters
69
+ * @returns A new array, sorted
70
+ */
71
+ export declare function inPathOrder<P extends Pick<Parameter, 'name'>>(path: string, parameters: readonly P[]): P[];
72
+ /**
73
+ * Resolves the type of a path parameter.
74
+ * @param parameter - The path parameter to resolve the type for
75
+ * @returns The resolved primitive type as a string, or the default path parameter type if the schema is missing,
76
+ * is a reference, lacks a type, or the type is not primitive
77
+ */
78
+ export declare function resolvePathParameterType(parameter: Parameter): string;
@@ -0,0 +1,28 @@
1
+ import { Reference } from '@ahoo-wang/fetcher-openapi';
2
+ export declare function isReference(schema: any): schema is Reference;
3
+ /**
4
+ * Resolves a local JSON pointer (`#/components/schemas/Item`) in a document.
5
+ *
6
+ * @param document - The document the pointer points into
7
+ * @param ref - The `$ref` value, starting with `#`
8
+ * @returns The value it points at, or undefined when there is none
9
+ */
10
+ export declare function resolveLocalPointer(document: unknown, ref: string): unknown;
11
+ /**
12
+ * Finds every reference to a component (`#/components/...`) that points at
13
+ * nothing.
14
+ *
15
+ * A dangling schema reference would otherwise generate a type that names an
16
+ * undeclared model, and a dangling parameter reference would silently drop
17
+ * the parameter. Other references are left alone: a reference to another
18
+ * document is refused where it is read, with a request to bundle it, and a
19
+ * schema may carry JSON Schema `definitions` it references relative to
20
+ * itself (`#/definitions/...`), as Wow 8.11 writes its filter schema.
21
+ *
22
+ * @param document - The parsed OpenAPI document
23
+ * @returns Each dangling reference with the JSON path of the object holding it
24
+ */
25
+ export declare function findDanglingReferences(document: unknown): {
26
+ ref: string;
27
+ location: string;
28
+ }[];
@@ -0,0 +1,28 @@
1
+ import { Reference } from '@ahoo-wang/fetcher-openapi';
2
+ export declare function isReference(schema: any): schema is Reference;
3
+ /**
4
+ * Resolves a local JSON pointer (`#/components/schemas/Item`) in a document.
5
+ *
6
+ * @param document - The document the pointer points into
7
+ * @param ref - The `$ref` value, starting with `#`
8
+ * @returns The value it points at, or undefined when there is none
9
+ */
10
+ export declare function resolveLocalPointer(document: unknown, ref: string): unknown;
11
+ /**
12
+ * Finds every reference to a component (`#/components/...`) that points at
13
+ * nothing.
14
+ *
15
+ * A dangling schema reference would otherwise generate a type that names an
16
+ * undeclared model, and a dangling parameter reference would silently drop
17
+ * the parameter. Other references are left alone: a reference to another
18
+ * document is refused where it is read, with a request to bundle it, and a
19
+ * schema may carry JSON Schema `definitions` it references relative to
20
+ * itself (`#/definitions/...`), as Wow 8.11 writes its filter schema.
21
+ *
22
+ * @param document - The parsed OpenAPI document
23
+ * @returns Each dangling reference with the JSON path of the object holding it
24
+ */
25
+ export declare function findDanglingReferences(document: unknown): {
26
+ ref: string;
27
+ location: string;
28
+ }[];
@@ -0,0 +1,44 @@
1
+ import { MediaType, Reference, Response, Schema } from '@ahoo-wang/fetcher-openapi';
2
+ /** The media type of JSON. */
3
+ export declare const APPLICATION_JSON = "application/json";
4
+ /** The media type of a server-sent event stream. */
5
+ export declare const TEXT_EVENT_STREAM = "text/event-stream";
6
+ /**
7
+ * The media type part of a content type, without parameters and in lower
8
+ * case: `application/json;charset=UTF-8` → `application/json`.
9
+ */
10
+ export declare function mediaTypeOf(contentType: string): string;
11
+ /**
12
+ * Tells whether a content type carries JSON: `application/json`, or any
13
+ * `+json` type such as `application/hal+json` or `application/problem+json`,
14
+ * with or without parameters.
15
+ */
16
+ export declare function isJsonContentType(contentType: string): boolean;
17
+ /**
18
+ * Tells whether a content type is text other than an event stream.
19
+ */
20
+ export declare function isTextContentType(contentType: string): boolean;
21
+ /**
22
+ * Finds the entry of a content map that matches, preferring an exact key.
23
+ *
24
+ * @param content - The content map of a request body or a response
25
+ * @param exact - The content type to prefer as written
26
+ * @param matches - What else qualifies
27
+ * @returns The media type object, or undefined
28
+ */
29
+ export declare function findMediaType(content: Record<string, MediaType> | undefined, exact: string, matches?: (contentType: string) => boolean): MediaType | undefined;
30
+ export declare function extractResponseSchema(contentType: string, response?: Response | Reference): Schema | Reference | undefined;
31
+ /**
32
+ * Extracts the JSON schema of a response: `application/json` or any `+json`
33
+ * type, with or without parameters.
34
+ * @param response - The response object or reference
35
+ * @returns The JSON schema from the response content or undefined if not found
36
+ */
37
+ export declare function extractResponseJsonSchema(response?: Response | Reference): Schema | Reference | undefined;
38
+ export declare function extractResponseEventStreamSchema(response?: Response | Reference): Schema | Reference | undefined;
39
+ export declare function extractResponseWildcardSchema(response?: Response | Reference): Schema | Reference | undefined;
40
+ /**
41
+ * Tells whether a response carries text other than an event stream, such as
42
+ * `text/plain`.
43
+ */
44
+ export declare function hasTextResponse(response?: Response | Reference): boolean;
@@ -0,0 +1,44 @@
1
+ import { MediaType, Reference, Response, Schema } from '@ahoo-wang/fetcher-openapi';
2
+ /** The media type of JSON. */
3
+ export declare const APPLICATION_JSON = "application/json";
4
+ /** The media type of a server-sent event stream. */
5
+ export declare const TEXT_EVENT_STREAM = "text/event-stream";
6
+ /**
7
+ * The media type part of a content type, without parameters and in lower
8
+ * case: `application/json;charset=UTF-8` → `application/json`.
9
+ */
10
+ export declare function mediaTypeOf(contentType: string): string;
11
+ /**
12
+ * Tells whether a content type carries JSON: `application/json`, or any
13
+ * `+json` type such as `application/hal+json` or `application/problem+json`,
14
+ * with or without parameters.
15
+ */
16
+ export declare function isJsonContentType(contentType: string): boolean;
17
+ /**
18
+ * Tells whether a content type is text other than an event stream.
19
+ */
20
+ export declare function isTextContentType(contentType: string): boolean;
21
+ /**
22
+ * Finds the entry of a content map that matches, preferring an exact key.
23
+ *
24
+ * @param content - The content map of a request body or a response
25
+ * @param exact - The content type to prefer as written
26
+ * @param matches - What else qualifies
27
+ * @returns The media type object, or undefined
28
+ */
29
+ export declare function findMediaType(content: Record<string, MediaType> | undefined, exact: string, matches?: (contentType: string) => boolean): MediaType | undefined;
30
+ export declare function extractResponseSchema(contentType: string, response?: Response | Reference): Schema | Reference | undefined;
31
+ /**
32
+ * Extracts the JSON schema of a response: `application/json` or any `+json`
33
+ * type, with or without parameters.
34
+ * @param response - The response object or reference
35
+ * @returns The JSON schema from the response content or undefined if not found
36
+ */
37
+ export declare function extractResponseJsonSchema(response?: Response | Reference): Schema | Reference | undefined;
38
+ export declare function extractResponseEventStreamSchema(response?: Response | Reference): Schema | Reference | undefined;
39
+ export declare function extractResponseWildcardSchema(response?: Response | Reference): Schema | Reference | undefined;
40
+ /**
41
+ * Tells whether a response carries text other than an event stream, such as
42
+ * `text/plain`.
43
+ */
44
+ export declare function hasTextResponse(response?: Response | Reference): boolean;
@@ -0,0 +1,112 @@
1
+ import { Components, Reference, Schema, SchemaType } from '@ahoo-wang/fetcher-openapi';
2
+ /**
3
+ * Checks if a schema type is primitive.
4
+ * @param type - The schema type to check
5
+ * @returns True if the type is primitive, false otherwise
6
+ */
7
+ export declare function isPrimitive(type: SchemaType | SchemaType[]): boolean;
8
+ export type EnumSchema = Schema & {
9
+ enum: any[];
10
+ };
11
+ /**
12
+ * Checks if a schema represents an enum.
13
+ * @param schema - The schema to check
14
+ * @returns True if the schema has an enum property, false otherwise
15
+ */
16
+ export declare function isEnum(schema: Schema): schema is EnumSchema;
17
+ export type EnumText = Record<string, string>;
18
+ export declare function getEnumText(schema: EnumSchema): EnumText | undefined;
19
+ export type ObjectSchema = Schema & {
20
+ type: 'object';
21
+ properties: Record<string, Schema | Reference>;
22
+ };
23
+ export declare function isObject(schema: Schema): schema is ObjectSchema;
24
+ export type ArraySchema = Schema & {
25
+ type: 'array';
26
+ items: Schema | Reference;
27
+ };
28
+ /**
29
+ * Checks if a schema is an array type.
30
+ * @param schema - The schema to check
31
+ * @returns True if the schema is an array type, false otherwise
32
+ */
33
+ export declare function isArray(schema: Schema): schema is ArraySchema;
34
+ export type AnyOfSchema = Schema & {
35
+ anyOf: any[];
36
+ };
37
+ /**
38
+ * Checks if a schema is an anyOf composition.
39
+ * @param schema - The schema to check
40
+ * @returns True if the schema has a non-empty anyOf property, false otherwise
41
+ */
42
+ export declare function isAnyOf(schema: Schema): schema is AnyOfSchema;
43
+ export type OneOfSchema = Schema & {
44
+ oneOf: any[];
45
+ };
46
+ /**
47
+ * Checks if a schema is a oneOf composition.
48
+ * @param schema - The schema to check
49
+ * @returns True if the schema has a non-empty oneOf property, false otherwise
50
+ */
51
+ export declare function isOneOf(schema: Schema): schema is OneOfSchema;
52
+ export type AllOfSchema = Schema & {
53
+ allOf: any[];
54
+ };
55
+ /**
56
+ * Checks if a schema is an allOf composition.
57
+ * @param schema - The schema to check
58
+ * @returns True if the schema has a non-empty allOf property, false otherwise
59
+ */
60
+ export declare function isAllOf(schema: Schema): schema is AllOfSchema;
61
+ export type CompositionSchema = AnyOfSchema | OneOfSchema | AllOfSchema;
62
+ /**
63
+ * Checks if a schema is a composition (anyOf, oneOf, or allOf).
64
+ * @param schema - The schema to check
65
+ * @returns True if the schema is anyOf, oneOf, or allOf composition, false otherwise
66
+ */
67
+ export declare function isComposition(schema: Schema): schema is CompositionSchema;
68
+ /**
69
+ * Converts a type string to an array type.
70
+ * Wraps complex types (containing | or &) in parentheses before adding array notation.
71
+ * @param type - The type string to convert to an array type
72
+ * @returns The array type string
73
+ */
74
+ export declare function toArrayType(type: string): string;
75
+ export type MapSchema = Schema & {
76
+ type: 'object';
77
+ additionalProperties: boolean | Schema | Reference;
78
+ };
79
+ export declare function isMap(schema: Schema): schema is MapSchema;
80
+ export declare function getMapKeySchema(schema: Schema): Schema | Reference | undefined;
81
+ /**
82
+ * Checks if a schema represents an empty object.
83
+ * @param schema - The schema to check
84
+ * @returns True if the schema represents an empty object, false otherwise
85
+ */
86
+ export declare function isEmptyObject(schema: Schema): boolean;
87
+ export declare function isReadOnly(schema: Schema | Reference): boolean;
88
+ /**
89
+ * Resolves a schema type to its TypeScript equivalent.
90
+ * @param type - The schema type(s) to resolve
91
+ * @returns The TypeScript type string
92
+ */
93
+ export declare function resolvePrimitiveType(type: SchemaType | SchemaType[]): string;
94
+ /**
95
+ * Lists the property names a command body may omit.
96
+ *
97
+ * A command type wraps its body in `PartialBy<Command, ...>` built from this
98
+ * list, which is where a request's declared optionality lives: generated model
99
+ * properties are always required. The walk follows `allOf` branches and
100
+ * references, because a command that inherits a base schema declares its
101
+ * properties there - reading only the top level would demand fields the
102
+ * document leaves optional.
103
+ *
104
+ * A property is optional when no branch requires it. `anyOf` and `oneOf` are
105
+ * not followed: a branch an instance need not match says nothing about the
106
+ * properties a command carries.
107
+ *
108
+ * @param schema - The command body schema, or a reference to it
109
+ * @param components - The components a reference resolves against
110
+ * @returns The declared property names absent from every `required` list
111
+ */
112
+ export declare function resolveOptionalFields(schema: Schema | Reference, components?: Components): string[];
@@ -0,0 +1,112 @@
1
+ import { Components, Reference, Schema, SchemaType } from '@ahoo-wang/fetcher-openapi';
2
+ /**
3
+ * Checks if a schema type is primitive.
4
+ * @param type - The schema type to check
5
+ * @returns True if the type is primitive, false otherwise
6
+ */
7
+ export declare function isPrimitive(type: SchemaType | SchemaType[]): boolean;
8
+ export type EnumSchema = Schema & {
9
+ enum: any[];
10
+ };
11
+ /**
12
+ * Checks if a schema represents an enum.
13
+ * @param schema - The schema to check
14
+ * @returns True if the schema has an enum property, false otherwise
15
+ */
16
+ export declare function isEnum(schema: Schema): schema is EnumSchema;
17
+ export type EnumText = Record<string, string>;
18
+ export declare function getEnumText(schema: EnumSchema): EnumText | undefined;
19
+ export type ObjectSchema = Schema & {
20
+ type: 'object';
21
+ properties: Record<string, Schema | Reference>;
22
+ };
23
+ export declare function isObject(schema: Schema): schema is ObjectSchema;
24
+ export type ArraySchema = Schema & {
25
+ type: 'array';
26
+ items: Schema | Reference;
27
+ };
28
+ /**
29
+ * Checks if a schema is an array type.
30
+ * @param schema - The schema to check
31
+ * @returns True if the schema is an array type, false otherwise
32
+ */
33
+ export declare function isArray(schema: Schema): schema is ArraySchema;
34
+ export type AnyOfSchema = Schema & {
35
+ anyOf: any[];
36
+ };
37
+ /**
38
+ * Checks if a schema is an anyOf composition.
39
+ * @param schema - The schema to check
40
+ * @returns True if the schema has a non-empty anyOf property, false otherwise
41
+ */
42
+ export declare function isAnyOf(schema: Schema): schema is AnyOfSchema;
43
+ export type OneOfSchema = Schema & {
44
+ oneOf: any[];
45
+ };
46
+ /**
47
+ * Checks if a schema is a oneOf composition.
48
+ * @param schema - The schema to check
49
+ * @returns True if the schema has a non-empty oneOf property, false otherwise
50
+ */
51
+ export declare function isOneOf(schema: Schema): schema is OneOfSchema;
52
+ export type AllOfSchema = Schema & {
53
+ allOf: any[];
54
+ };
55
+ /**
56
+ * Checks if a schema is an allOf composition.
57
+ * @param schema - The schema to check
58
+ * @returns True if the schema has a non-empty allOf property, false otherwise
59
+ */
60
+ export declare function isAllOf(schema: Schema): schema is AllOfSchema;
61
+ export type CompositionSchema = AnyOfSchema | OneOfSchema | AllOfSchema;
62
+ /**
63
+ * Checks if a schema is a composition (anyOf, oneOf, or allOf).
64
+ * @param schema - The schema to check
65
+ * @returns True if the schema is anyOf, oneOf, or allOf composition, false otherwise
66
+ */
67
+ export declare function isComposition(schema: Schema): schema is CompositionSchema;
68
+ /**
69
+ * Converts a type string to an array type.
70
+ * Wraps complex types (containing | or &) in parentheses before adding array notation.
71
+ * @param type - The type string to convert to an array type
72
+ * @returns The array type string
73
+ */
74
+ export declare function toArrayType(type: string): string;
75
+ export type MapSchema = Schema & {
76
+ type: 'object';
77
+ additionalProperties: boolean | Schema | Reference;
78
+ };
79
+ export declare function isMap(schema: Schema): schema is MapSchema;
80
+ export declare function getMapKeySchema(schema: Schema): Schema | Reference | undefined;
81
+ /**
82
+ * Checks if a schema represents an empty object.
83
+ * @param schema - The schema to check
84
+ * @returns True if the schema represents an empty object, false otherwise
85
+ */
86
+ export declare function isEmptyObject(schema: Schema): boolean;
87
+ export declare function isReadOnly(schema: Schema | Reference): boolean;
88
+ /**
89
+ * Resolves a schema type to its TypeScript equivalent.
90
+ * @param type - The schema type(s) to resolve
91
+ * @returns The TypeScript type string
92
+ */
93
+ export declare function resolvePrimitiveType(type: SchemaType | SchemaType[]): string;
94
+ /**
95
+ * Lists the property names a command body may omit.
96
+ *
97
+ * A command type wraps its body in `PartialBy<Command, ...>` built from this
98
+ * list, which is where a request's declared optionality lives: generated model
99
+ * properties are always required. The walk follows `allOf` branches and
100
+ * references, because a command that inherits a base schema declares its
101
+ * properties there - reading only the top level would demand fields the
102
+ * document leaves optional.
103
+ *
104
+ * A property is optional when no branch requires it. `anyOf` and `oneOf` are
105
+ * not followed: a branch an instance need not match says nothing about the
106
+ * properties a command carries.
107
+ *
108
+ * @param schema - The command body schema, or a reference to it
109
+ * @param components - The components a reference resolves against
110
+ * @returns The declared property names absent from every `required` list
111
+ */
112
+ export declare function resolveOptionalFields(schema: Schema | Reference, components?: Components): string[];
@@ -0,0 +1,92 @@
1
+ import { Project, SourceFile } from 'ts-morph';
2
+ /** The manifest that records the files a generation wrote, and their hashes. */
3
+ export declare const GENERATION_MANIFEST = ".wow-generator.json";
4
+ export declare const LEGACY_GENERATION_MANIFEST = ".fetcher-generator.json";
5
+ /**
6
+ * The version of the manifest format this generator reads and writes. A
7
+ * change a reader of this version would misread bumps it; see section 3 of
8
+ * docs/design/architecture.md.
9
+ */
10
+ export declare const MANIFEST_VERSION = 1;
11
+ /**
12
+ * The output directory of one generation: which files it owns, which of the
13
+ * files an earlier run wrote it may remove, and writing them.
14
+ *
15
+ * The manifest (`.wow-generator.json`) records every file a run wrote and
16
+ * the hash it wrote. A file of the last run that this run does not write is
17
+ * stale; it is removed only if its bytes are still the ones recorded, so a
18
+ * hand-edited file is never lost. A file the manifest does not name is never
19
+ * touched.
20
+ *
21
+ * One store per run: {@link open} reads the manifest, {@link claim} hands
22
+ * out the files the run writes, {@link commit} writes them, removes the stale
23
+ * ones and writes the new manifest.
24
+ */
25
+ export declare class OutputStore {
26
+ private readonly project;
27
+ /** The output directory as the caller named it. */
28
+ private readonly outputPath;
29
+ /** The output directory, absolute. */
30
+ private readonly outputDir;
31
+ /** The files of the last run, with the hash each was written with. */
32
+ private readonly previous;
33
+ /** A pre-Wow manifest to delete once the new one is written. */
34
+ private readonly legacyManifest;
35
+ /** The files this run writes, by absolute path. */
36
+ private readonly written;
37
+ /** Files of the last run this run does not write and may remove. */
38
+ private readonly stale;
39
+ private constructor();
40
+ /**
41
+ * Reads the manifest of an output directory, the pre-Wow one when the new
42
+ * one is absent, and takes the files it names out of the project: a run
43
+ * writes its files afresh.
44
+ *
45
+ * @param project - The project the run writes into
46
+ * @param outputDir - The output directory, absolute or relative to the
47
+ * project's working directory
48
+ * @param last - The store of the last run into the same project, whose
49
+ * files, written or only drafted, leave the project too
50
+ * @throws GeneratorError (`output`) when the manifest cannot be parsed, was
51
+ * written by a newer generator, is not one, or names a file outside the
52
+ * output directory
53
+ */
54
+ static open(project: Project, outputDir: string, last?: OutputStore): OutputStore;
55
+ /** The files this run writes, by absolute path. */
56
+ get files(): ReadonlySet<string>;
57
+ /**
58
+ * The source file of a path under a directory of the output, claimed for
59
+ * this run: the first claim empties it, and {@link commit} writes it.
60
+ *
61
+ * @param filePath - The path, relative to `directory`
62
+ * @param directory - The output directory as the caller named it, or a
63
+ * directory under it
64
+ * @throws GeneratorError (`output`) when the path resolves outside it
65
+ */
66
+ claim(filePath: string, directory?: string): SourceFile;
67
+ /**
68
+ * Takes the files of the last run this run does not write out of the
69
+ * project, when they are still as that run wrote them, so the indexes do
70
+ * not export them; {@link commit} removes them. Nothing on disk changes.
71
+ */
72
+ forgetStale(): void;
73
+ /**
74
+ * Writes the files this run claimed, then removes the stale ones that are
75
+ * still as the last run wrote them, then writes the manifest and deletes a
76
+ * pre-Wow one. A stale file this run writes again under a name that
77
+ * differs only in case is removed before the writing instead.
78
+ *
79
+ * @param signal - Stops the run after the files are written: nothing is
80
+ * removed and the manifest stays the last run's, so an interrupted run
81
+ * never records files it did not finish
82
+ * @throws GeneratorError (`output`) when writing or removing a file fails;
83
+ * the signal's reason when it was aborted
84
+ */
85
+ commit(signal?: AbortSignal): Promise<void>;
86
+ /**
87
+ * Tells whether a file of the last run is still as it wrote it: present,
88
+ * inside the output directory once links are followed, and of the hash the
89
+ * manifest records.
90
+ */
91
+ private isUnchanged;
92
+ }
@@ -0,0 +1,92 @@
1
+ import { Project, SourceFile } from 'ts-morph';
2
+ /** The manifest that records the files a generation wrote, and their hashes. */
3
+ export declare const GENERATION_MANIFEST = ".wow-generator.json";
4
+ export declare const LEGACY_GENERATION_MANIFEST = ".fetcher-generator.json";
5
+ /**
6
+ * The version of the manifest format this generator reads and writes. A
7
+ * change a reader of this version would misread bumps it; see section 3 of
8
+ * docs/design/architecture.md.
9
+ */
10
+ export declare const MANIFEST_VERSION = 1;
11
+ /**
12
+ * The output directory of one generation: which files it owns, which of the
13
+ * files an earlier run wrote it may remove, and writing them.
14
+ *
15
+ * The manifest (`.wow-generator.json`) records every file a run wrote and
16
+ * the hash it wrote. A file of the last run that this run does not write is
17
+ * stale; it is removed only if its bytes are still the ones recorded, so a
18
+ * hand-edited file is never lost. A file the manifest does not name is never
19
+ * touched.
20
+ *
21
+ * One store per run: {@link open} reads the manifest, {@link claim} hands
22
+ * out the files the run writes, {@link commit} writes them, removes the stale
23
+ * ones and writes the new manifest.
24
+ */
25
+ export declare class OutputStore {
26
+ private readonly project;
27
+ /** The output directory as the caller named it. */
28
+ private readonly outputPath;
29
+ /** The output directory, absolute. */
30
+ private readonly outputDir;
31
+ /** The files of the last run, with the hash each was written with. */
32
+ private readonly previous;
33
+ /** A pre-Wow manifest to delete once the new one is written. */
34
+ private readonly legacyManifest;
35
+ /** The files this run writes, by absolute path. */
36
+ private readonly written;
37
+ /** Files of the last run this run does not write and may remove. */
38
+ private readonly stale;
39
+ private constructor();
40
+ /**
41
+ * Reads the manifest of an output directory, the pre-Wow one when the new
42
+ * one is absent, and takes the files it names out of the project: a run
43
+ * writes its files afresh.
44
+ *
45
+ * @param project - The project the run writes into
46
+ * @param outputDir - The output directory, absolute or relative to the
47
+ * project's working directory
48
+ * @param last - The store of the last run into the same project, whose
49
+ * files, written or only drafted, leave the project too
50
+ * @throws GeneratorError (`output`) when the manifest cannot be parsed, was
51
+ * written by a newer generator, is not one, or names a file outside the
52
+ * output directory
53
+ */
54
+ static open(project: Project, outputDir: string, last?: OutputStore): OutputStore;
55
+ /** The files this run writes, by absolute path. */
56
+ get files(): ReadonlySet<string>;
57
+ /**
58
+ * The source file of a path under a directory of the output, claimed for
59
+ * this run: the first claim empties it, and {@link commit} writes it.
60
+ *
61
+ * @param filePath - The path, relative to `directory`
62
+ * @param directory - The output directory as the caller named it, or a
63
+ * directory under it
64
+ * @throws GeneratorError (`output`) when the path resolves outside it
65
+ */
66
+ claim(filePath: string, directory?: string): SourceFile;
67
+ /**
68
+ * Takes the files of the last run this run does not write out of the
69
+ * project, when they are still as that run wrote them, so the indexes do
70
+ * not export them; {@link commit} removes them. Nothing on disk changes.
71
+ */
72
+ forgetStale(): void;
73
+ /**
74
+ * Writes the files this run claimed, then removes the stale ones that are
75
+ * still as the last run wrote them, then writes the manifest and deletes a
76
+ * pre-Wow one. A stale file this run writes again under a name that
77
+ * differs only in case is removed before the writing instead.
78
+ *
79
+ * @param signal - Stops the run after the files are written: nothing is
80
+ * removed and the manifest stays the last run's, so an interrupted run
81
+ * never records files it did not finish
82
+ * @throws GeneratorError (`output`) when writing or removing a file fails;
83
+ * the signal's reason when it was aborted
84
+ */
85
+ commit(signal?: AbortSignal): Promise<void>;
86
+ /**
87
+ * Tells whether a file of the last run is still as it wrote it: present,
88
+ * inside the output directory once links are followed, and of the hash the
89
+ * manifest records.
90
+ */
91
+ private isUnchanged;
92
+ }