@appweaver/client 1.3.0 → 1.4.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 (43) hide show
  1. package/cjs/clients/modules/resource-client.d.ts +12 -11
  2. package/cjs/clients/modules/resource-client.js +6 -6
  3. package/cjs/commands/generate-command.js +3 -1
  4. package/cjs/constants.d.ts +9 -0
  5. package/cjs/constants.js +28 -1
  6. package/cjs/generators/generate-types.d.ts +3 -1
  7. package/cjs/generators/generate-types.js +99 -9
  8. package/cjs/index.d.ts +1 -0
  9. package/cjs/index.js +1 -0
  10. package/cjs/types/generator.d.ts +6 -0
  11. package/cjs/types/generator.js +2 -0
  12. package/cjs/types/index.d.ts +2 -0
  13. package/cjs/types/index.js +2 -0
  14. package/cjs/types/resource.d.ts +2 -0
  15. package/cjs/types/resource.js +2 -0
  16. package/cjs/utils/enum-util.d.ts +17 -17
  17. package/cjs/utils/enum-util.js +50 -170
  18. package/cjs/utils/hoist-util.d.ts +29 -0
  19. package/cjs/utils/hoist-util.js +338 -0
  20. package/cjs/utils/index.d.ts +1 -0
  21. package/cjs/utils/index.js +1 -0
  22. package/esm/clients/modules/resource-client.d.ts +12 -11
  23. package/esm/clients/modules/resource-client.js +6 -6
  24. package/esm/commands/generate-command.js +3 -1
  25. package/esm/constants.d.ts +9 -0
  26. package/esm/constants.js +27 -0
  27. package/esm/generators/generate-types.d.ts +3 -1
  28. package/esm/generators/generate-types.js +100 -10
  29. package/esm/index.d.ts +1 -0
  30. package/esm/index.js +1 -0
  31. package/esm/types/generator.d.ts +6 -0
  32. package/esm/types/generator.js +1 -0
  33. package/esm/types/index.d.ts +2 -0
  34. package/esm/types/index.js +2 -0
  35. package/esm/types/resource.d.ts +2 -0
  36. package/esm/types/resource.js +1 -0
  37. package/esm/utils/enum-util.d.ts +17 -17
  38. package/esm/utils/enum-util.js +49 -169
  39. package/esm/utils/hoist-util.d.ts +29 -0
  40. package/esm/utils/hoist-util.js +335 -0
  41. package/esm/utils/index.d.ts +1 -0
  42. package/esm/utils/index.js +1 -0
  43. package/package.json +3 -2
@@ -2,6 +2,7 @@ import { BaseModule, RequestOptions } from './base-module.js';
2
2
  import { BaseClientInterface } from '../base-client-interface.js';
3
3
  import { FileDataResponse } from '../responses/index.js';
4
4
  import { RESOURCE_OPERATIONS, RESOURCE_TYPES } from '../../constants.js';
5
+ import { ResourceId } from '../../types/index.js';
5
6
  export type ResourceType = Record<(typeof RESOURCE_TYPES)[number], unknown>;
6
7
  export type ResourceInterface = {
7
8
  [K in keyof typeof RESOURCE_OPERATIONS]: (...args: any[]) => Promise<any>;
@@ -10,13 +11,13 @@ export declare class ResourceClient<Resource extends ResourceType> extends BaseM
10
11
  readonly basePath: string;
11
12
  constructor(client: BaseClientInterface, basePath: string);
12
13
  /**
13
- * Fetches a single resource by its numeric ID.
14
+ * Fetches a single resource by its ID.
14
15
  *
15
- * @param {number} id - The ID of the resource to retrieve.
16
+ * @param {ResourceId} id - The ID of the resource to retrieve.
16
17
  * @param {RequestOptions} options - Additional request options (headers, query params, etc.).
17
18
  * @returns The resource record matching the given ID.
18
19
  */
19
- find(id: number, options?: RequestOptions): Promise<Resource['single']>;
20
+ find(id: ResourceId, options?: RequestOptions): Promise<Resource['single']>;
20
21
  /**
21
22
  * Executes a query against the resource collection.
22
23
  *
@@ -49,16 +50,16 @@ export declare class ResourceClient<Resource extends ResourceType> extends BaseM
49
50
  * @returns The updated resource record.
50
51
  */
51
52
  update(resource: Resource['update'] & {
52
- id: number;
53
+ id: ResourceId;
53
54
  }, options?: RequestOptions): Promise<Resource['single']>;
54
55
  /**
55
- * Deletes a resource record by its numeric ID.
56
+ * Deletes a resource record by its ID.
56
57
  *
57
- * @param {number} id - The ID of the resource to delete.
58
+ * @param {ResourceId} id - The ID of the resource to delete.
58
59
  * @param {RequestOptions} options - Additional request options.
59
60
  * @returns The deleted resource record.
60
61
  */
61
- delete(id: number, options?: RequestOptions): Promise<Resource['single']>;
62
+ delete(id: ResourceId, options?: RequestOptions): Promise<Resource['single']>;
62
63
  /**
63
64
  * Exports resource records as a file (e.g., CSV) and returns a streaming response.
64
65
  *
@@ -72,19 +73,19 @@ export declare class ResourceClient<Resource extends ResourceType> extends BaseM
72
73
  *
73
74
  * Each entry in `files` maps a field name to a single `File` or an array of `File` objects.
74
75
  *
75
- * @param {number} id - The ID of the resource for which to upload files.
76
+ * @param {ResourceId} id - The ID of the resource for which to upload files.
76
77
  * @param {Object} files - A map of field names to the file(s) to upload.
77
78
  * @param {RequestOptions} options - Additional request options.
78
79
  * @returns The updated file metadata for the resource.
79
80
  */
80
- uploadFiles(id: number, files: Resource['fileUpload'], options?: RequestOptions): Promise<Resource['files']>;
81
+ uploadFiles(id: ResourceId, files: Resource['fileUpload'], options?: RequestOptions): Promise<Resource['files']>;
81
82
  /**
82
83
  * Removes specific files from the resource record.
83
84
  *
84
- * @param {number} id - The ID of the resource for which to delete files.
85
+ * @param {ResourceId} id - The ID of the resource for which to delete files.
85
86
  * @param {Object} files - The file deletion payload identifying which files to remove.
86
87
  * @param {RequestOptions} options - Additional request options.
87
88
  * @returns The updated file metadata for the resource after deletion.
88
89
  */
89
- deleteFiles(id: number, files: Resource['fileDelete'], options?: RequestOptions): Promise<Resource['files']>;
90
+ deleteFiles(id: ResourceId, files: Resource['fileDelete'], options?: RequestOptions): Promise<Resource['files']>;
90
91
  }
@@ -6,9 +6,9 @@ export class ResourceClient extends BaseModule {
6
6
  this.basePath = basePath;
7
7
  }
8
8
  /**
9
- * Fetches a single resource by its numeric ID.
9
+ * Fetches a single resource by its ID.
10
10
  *
11
- * @param {number} id - The ID of the resource to retrieve.
11
+ * @param {ResourceId} id - The ID of the resource to retrieve.
12
12
  * @param {RequestOptions} options - Additional request options (headers, query params, etc.).
13
13
  * @returns The resource record matching the given ID.
14
14
  */
@@ -82,9 +82,9 @@ export class ResourceClient extends BaseModule {
82
82
  });
83
83
  }
84
84
  /**
85
- * Deletes a resource record by its numeric ID.
85
+ * Deletes a resource record by its ID.
86
86
  *
87
- * @param {number} id - The ID of the resource to delete.
87
+ * @param {ResourceId} id - The ID of the resource to delete.
88
88
  * @param {RequestOptions} options - Additional request options.
89
89
  * @returns The deleted resource record.
90
90
  */
@@ -122,7 +122,7 @@ export class ResourceClient extends BaseModule {
122
122
  *
123
123
  * Each entry in `files` maps a field name to a single `File` or an array of `File` objects.
124
124
  *
125
- * @param {number} id - The ID of the resource for which to upload files.
125
+ * @param {ResourceId} id - The ID of the resource for which to upload files.
126
126
  * @param {Object} files - A map of field names to the file(s) to upload.
127
127
  * @param {RequestOptions} options - Additional request options.
128
128
  * @returns The updated file metadata for the resource.
@@ -153,7 +153,7 @@ export class ResourceClient extends BaseModule {
153
153
  /**
154
154
  * Removes specific files from the resource record.
155
155
  *
156
- * @param {number} id - The ID of the resource for which to delete files.
156
+ * @param {ResourceId} id - The ID of the resource for which to delete files.
157
157
  * @param {Object} files - The file deletion payload identifying which files to remove.
158
158
  * @param {RequestOptions} options - Additional request options.
159
159
  * @returns The updated file metadata for the resource after deletion.
@@ -33,7 +33,9 @@ export function generateCommand(program) {
33
33
  const schemaContent = await readSchemaContent(schemaPath);
34
34
  const schemaObject = await toSchemaObject(schemaContent);
35
35
  if (!clientOnly && !noTypes) {
36
- const typesContent = await generateTypes(schemaObject);
36
+ const typesContent = await generateTypes(schemaObject, {
37
+ declaration: typesPath.endsWith('.d.ts')
38
+ });
37
39
  await formatAndWriteFile(typesPath, typesContent, typesOnly || typesPath !== clientPath);
38
40
  console.log(`Generated types to ${path.relative(cwd, typesPath)}`);
39
41
  }
@@ -8,6 +8,15 @@ export declare const CONFIG_RESOURCE_FIELD = "x-appweaver-resource";
8
8
  * The key is the enum values joined by a `|`; the value is the name of the shared type generated
9
9
  * for them. Enums that are not listed here are named after the definitions declaring them. */
10
10
  export declare const SHARED_ENUM_NAMES: Record<string, string>;
11
+ /** Shapes an Appweaver schema repeats inline across its definitions, and the name of the shared
12
+ * definition each of them is hoisted into. A `$ref` names the title of the definition it points
13
+ * to, since the keys the definitions are generated under vary per document. The shapes are
14
+ * matched in the order they are declared, so an outer shape is hoisted before the shapes nested
15
+ * inside it (i.e. `QueryFilterValue` before the `QueryFilterScalar` it is built from). */
16
+ export declare const SHARED_SCHEMA_SHAPES: {
17
+ name: string;
18
+ schema: unknown;
19
+ }[];
11
20
  /** Suffix used when generating the TypeScript module type name for a resource. */
12
21
  export declare const RESOURCE_MODULE_TYPE = "ResourceModuleType";
13
22
  /** Maps CRUD operation names to HTTP methods used for matching OpenAPI paths to `ResourceClient` methods. */
package/esm/constants.js CHANGED
@@ -13,6 +13,33 @@ export const CONFIG_RESOURCE_FIELD = 'x-appweaver-resource';
13
13
  export const SHARED_ENUM_NAMES = {
14
14
  'asc|desc': 'SortDirection'
15
15
  };
16
+ /** The primitive types a plain filter value takes, as an Appweaver schema declares them. */
17
+ const FILTER_SCALAR = {
18
+ anyOf: [
19
+ { type: 'string' },
20
+ { type: 'number' },
21
+ { type: 'boolean' },
22
+ { type: 'null' }
23
+ ]
24
+ };
25
+ /** Shapes an Appweaver schema repeats inline across its definitions, and the name of the shared
26
+ * definition each of them is hoisted into. A `$ref` names the title of the definition it points
27
+ * to, since the keys the definitions are generated under vary per document. The shapes are
28
+ * matched in the order they are declared, so an outer shape is hoisted before the shapes nested
29
+ * inside it (i.e. `QueryFilterValue` before the `QueryFilterScalar` it is built from). */
30
+ export const SHARED_SCHEMA_SHAPES = [
31
+ {
32
+ name: 'QueryFilterValue',
33
+ schema: {
34
+ anyOf: [
35
+ FILTER_SCALAR,
36
+ { type: 'array', items: FILTER_SCALAR },
37
+ { $ref: 'QueryCondition' }
38
+ ]
39
+ }
40
+ },
41
+ { name: 'QueryFilterScalar', schema: FILTER_SCALAR }
42
+ ];
16
43
  /** Suffix used when generating the TypeScript module type name for a resource. */
17
44
  export const RESOURCE_MODULE_TYPE = 'ResourceModuleType';
18
45
  /** Maps CRUD operation names to HTTP methods used for matching OpenAPI paths to `ResourceClient` methods. */
@@ -1,9 +1,11 @@
1
1
  import { OpenAPI3 } from 'openapi-typescript';
2
+ import { GenerateTypesOptions } from '../types/index.js';
2
3
  /**
3
4
  * Generates TypeScript types based on an OpenAPI V3 schema content.
4
5
  *
5
6
  * @param {string | OpenAPI3} schema - The OpenAPI V3 schema to generate types from. The value can be a string
6
7
  * representing JSON or YAML format, or an already parsed OpenAPI3 object.
8
+ * @param {GenerateTypesOptions} [options] - Options controlling how the types are emitted.
7
9
  * @return {Promise<string>} A promise that resolves to a string containing the generated TypeScript types.
8
10
  */
9
- export declare function generateTypes(schema: string | OpenAPI3): Promise<string>;
11
+ export declare function generateTypes(schema: string | OpenAPI3, options?: GenerateTypesOptions): Promise<string>;
@@ -1,21 +1,22 @@
1
1
  import openapiTS, { astToString } from 'openapi-typescript';
2
2
  import ts from 'typescript';
3
- import { hoistSharedEnums, toSchemaObject } from '../utils/index.js';
3
+ import { hoistSharedTypes, rewriteEnumsAsObjects, toSchemaObject } from '../utils/index.js';
4
4
  import { ACCOUNT_MODULE_TYPE, ACCOUNT_TYPES, AUTH_MODULE_TYPE, AUTH_TYPES, CONFIG_FIELD, HEALTH_MODULE_TYPE, HEALTH_TYPES, RESOURCE_MODULE_TYPE, RESOURCE_TYPES } from '../constants.js';
5
5
  /**
6
6
  * Generates TypeScript types based on an OpenAPI V3 schema content.
7
7
  *
8
8
  * @param {string | OpenAPI3} schema - The OpenAPI V3 schema to generate types from. The value can be a string
9
9
  * representing JSON or YAML format, or an already parsed OpenAPI3 object.
10
+ * @param {GenerateTypesOptions} [options] - Options controlling how the types are emitted.
10
11
  * @return {Promise<string>} A promise that resolves to a string containing the generated TypeScript types.
11
12
  */
12
- export async function generateTypes(schema) {
13
- // The schema is copied before the shared enums are hoisted into it, so the
14
- // caller keeps the schema it passed in unchanged
13
+ export async function generateTypes(schema, options = {}) {
14
+ // The schema is copied before the shared definitions are hoisted into it, so
15
+ // the caller keeps the schema it passed in unchanged
15
16
  const schemaObject = typeof schema === 'string'
16
17
  ? await toSchemaObject(schema)
17
18
  : structuredClone(schema);
18
- const sharedEnums = hoistSharedEnums(schemaObject);
19
+ const sharedTypes = hoistSharedTypes(schemaObject);
19
20
  const ast = await openapiTS(schemaObject, {
20
21
  exportType: true,
21
22
  emptyObjectsUnknown: true,
@@ -52,10 +53,11 @@ export async function generateTypes(schema) {
52
53
  }
53
54
  });
54
55
  let typesContent = astToString(deduplicateUnionConstituents(ast));
55
- typesContent = extractSchemaTypes(typesContent, sharedEnums);
56
+ typesContent = extractSchemaTypes(typesContent, sharedTypes);
56
57
  typesContent = combineModuleTypes(typesContent, schemaObject);
57
58
  typesContent = deduplicateExportedTypes(typesContent);
58
- return replaceFileUploadTypes(typesContent);
59
+ typesContent = replaceFileUploadTypes(typesContent);
60
+ return rewriteEnumsAsObjects(typesContent, options.declaration);
59
61
  }
60
62
  /**
61
63
  * Extracts inline schema types from the generated `schemas` block.
@@ -69,12 +71,16 @@ export async function generateTypes(schema) {
69
71
  *
70
72
  * And replaces the inline body in `schemas` with a reference to the new type.
71
73
  *
74
+ * The definitions holding the schemas shared between the other definitions are lifted the
75
+ * same way, whether they hold an object or, as the hoisted enums and filter values do, a
76
+ * union of their own.
77
+ *
72
78
  * @param {string} typeContent - The generated TypeScript type content as a string.
73
- * @param {string[]} sharedEnums - The names of the definitions holding the enums shared
79
+ * @param {string[]} sharedTypes - The names of the definitions holding the schemas shared
74
80
  * between the other definitions, whose references are replaced by the name alone.
75
81
  * @return {string} The transformed types content with extracted schema types.
76
82
  */
77
- function extractSchemaTypes(typeContent, sharedEnums = []) {
83
+ function extractSchemaTypes(typeContent, sharedTypes = []) {
78
84
  const extractedTypes = [];
79
85
  const typeNames = new Set();
80
86
  const entries = [];
@@ -140,8 +146,11 @@ function extractSchemaTypes(typeContent, sharedEnums = []) {
140
146
  }
141
147
  }
142
148
  updatedBaseContent += normalizedTypes.slice(cursor);
149
+ // Lift the shared definitions holding a union rather than an object, which the
150
+ // entries above leave in place (i.e. `QueryFilterValue: QueryFilterScalar | ...;`)
151
+ updatedBaseContent = extractSharedTypes(updatedBaseContent, sharedTypes, extractedTypes, typeNames);
143
152
  // Replace all cross-references like components["schemas"]["def-89"] with the type name
144
- const references = new Map(sharedEnums.map((name) => [`"${name}"`, name]));
153
+ const references = new Map(sharedTypes.map((name) => [`"${name}"`, name]));
145
154
  for (const [defKey, typeName] of defToTypeName) {
146
155
  references.set(defKey, typeName);
147
156
  }
@@ -176,6 +185,87 @@ function extractSchemaTypes(typeContent, sharedEnums = []) {
176
185
  const mergedExtractedTypes = stripFormat(joined.replace(doubleCommentsRegex, '$1*'));
177
186
  return updatedBaseContent + '\n' + mergedExtractedTypes;
178
187
  }
188
+ /**
189
+ * Lifts the shared definitions holding a type of their own out of the generated `schemas`
190
+ * block, so the type they hold is declared once and referenced by name everywhere else.
191
+ *
192
+ * Finds entries like:
193
+ * QueryFilterValue: QueryFilterScalar | QueryFilterScalar[] | QueryCondition;
194
+ *
195
+ * Lifts each one into:
196
+ * export type QueryFilterValue = QueryFilterScalar | QueryFilterScalar[] | QueryCondition;
197
+ *
198
+ * The definitions holding nothing but a reference to a type declared elsewhere, as the hoisted
199
+ * enums do, are left alone.
200
+ *
201
+ * @param {string} content - The generated types, with the object definitions already extracted.
202
+ * @param {string[]} names - The names of the shared definitions to lift.
203
+ * @param {string[]} extractedTypes - The extracted types, appended to for every lifted entry.
204
+ * @param {Set<string>} typeNames - The names already extracted, added to for every lifted entry.
205
+ * @return {string} The types with the body of every lifted entry replaced by its name.
206
+ */
207
+ function extractSharedTypes(content, names, extractedTypes, typeNames) {
208
+ // The definitions live in the components block, so a property named after one of them
209
+ // elsewhere in the types is never mistaken for its declaration
210
+ const componentsStart = content.indexOf('export type components');
211
+ if (componentsStart < 0) {
212
+ return content;
213
+ }
214
+ for (const name of names) {
215
+ if (typeNames.has(name)) {
216
+ continue;
217
+ }
218
+ // The entry starts on a line of its own, optionally preceded by the JSDoc header
219
+ // holding the name of the definition
220
+ const entry = new RegExp(String.raw `\n[ \t]*(?:\/\*\*(?:(?!\*\/)[\s\S])*\*\/\s*)?${name}: `).exec(content.slice(componentsStart));
221
+ if (!entry) {
222
+ continue;
223
+ }
224
+ const start = componentsStart + entry.index + entry[0].length;
225
+ const end = findTypeEnd(content, start);
226
+ const body = content.slice(start, end).trim();
227
+ // A definition referencing a type declared elsewhere holds nothing to lift
228
+ if (!body || body === name) {
229
+ continue;
230
+ }
231
+ typeNames.add(name);
232
+ extractedTypes.push(`export type ${name} = ${body};\n`);
233
+ content = content.slice(0, start) + name + content.slice(end);
234
+ }
235
+ return content;
236
+ }
237
+ /**
238
+ * Finds the end of the type starting at the given index, which is the first semicolon that is
239
+ * not nested inside braces, brackets, parentheses or a string literal.
240
+ *
241
+ * @param {string} content - The content holding the type.
242
+ * @param {number} start - The index the type starts at.
243
+ * @return {number} The index of the semicolon terminating the type.
244
+ */
245
+ function findTypeEnd(content, start) {
246
+ const closing = { '{': '}', '[': ']', '(': ')' };
247
+ const stack = [];
248
+ for (let i = start; i < content.length; i++) {
249
+ const character = content[i];
250
+ if (character === '"' || character === "'") {
251
+ i = content.indexOf(character, i + 1);
252
+ if (i < 0) {
253
+ return content.length;
254
+ }
255
+ continue;
256
+ }
257
+ if (closing[character]) {
258
+ stack.push(closing[character]);
259
+ }
260
+ else if (character === stack[stack.length - 1]) {
261
+ stack.pop();
262
+ }
263
+ else if (character === ';' && stack.length === 0) {
264
+ return i;
265
+ }
266
+ }
267
+ return content.length;
268
+ }
179
269
  /**
180
270
  * Deduplicates and simplifies union type constituents in the provided TypeScript Abstract Syntax Tree (AST).
181
271
  * Ensures that duplicate constituents are removed and shared types across parenthesized union branches are hoisted.
package/esm/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './clients/index.js';
2
2
  export * from './errors/index.js';
3
+ export * from './types/resource.js';
package/esm/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './clients/index.js';
2
2
  export * from './errors/index.js';
3
+ export * from './types/resource.js';
@@ -0,0 +1,6 @@
1
+ /** Options controlling how the TypeScript types are generated from an OpenAPI schema. */
2
+ export type GenerateTypesOptions = {
3
+ /** Whether the types are written into a declaration (`.d.ts`) file, which holds no runtime
4
+ * values and so declares the enum constants instead of initializing them. (default: false) */
5
+ declaration?: boolean;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1,3 @@
1
+ export * from './generator.js';
2
+ export * from './resource.js';
1
3
  export * from './routes.js';
@@ -1 +1,3 @@
1
+ export * from './generator.js';
2
+ export * from './resource.js';
1
3
  export * from './routes.js';
@@ -0,0 +1,2 @@
1
+ /** Primary key value: a number for `int` and `bigInt` ids, a string for `string` ids */
2
+ export type ResourceId = number | string;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,22 +1,22 @@
1
- import { OpenAPI3 } from 'openapi-typescript';
2
1
  /**
3
- * Hoists the inline enums a schema repeats across its definitions into shared definitions
4
- * of their own, replacing every occurrence with a reference to the hoisted definition.
2
+ * Rewrites the TypeScript enums of the generated types into a constant object holding the
3
+ * members and a type alias of their values, so both forms are accepted wherever the enum is
4
+ * used (i.e. `SortDirection.asc` and the plain `'asc'` literal alike).
5
5
  *
6
- * An Appweaver schema declares the same enum inline over and over, once per property that
7
- * accepts it, and each of them would otherwise become an enum of its own in the generated
8
- * types (i.e. a separate `asc | desc` enum for every sortable field of every resource).
6
+ * A TypeScript `enum` declares a nominal type, which rejects the very literals it is built
7
+ * from, forcing users of the generated client to import the enum for a value the API
8
+ * documents as a string. The rewritten declaration keeps the member access working while
9
+ * typing the property as the union of its values:
9
10
  *
10
- * Only enums that are byte for byte identical are hoisted, so no property loses its
11
- * description, example or nullability along the way. The hoisted definition is named after
12
- * {@link SHARED_ENUM_NAMES} when its values are well known, and otherwise after the part
13
- * the declaring definitions have in common followed by the property name (i.e. `PostCreate`
14
- * and `PostSingle` declaring `status` give `PostStatus`). Enums whose name cannot be
15
- * resolved, or whose name is already taken, are left inline.
11
+ * ```ts
12
+ * export const SortDirection = { asc: 'asc', desc: 'desc' } as const;
13
+ * export type SortDirection = (typeof SortDirection)[keyof typeof SortDirection];
14
+ * ```
16
15
  *
17
- * The given schema is mutated in place.
18
- *
19
- * @param {OpenAPI3} schema The OpenAPI v3 schema to hoist the shared enums of.
20
- * @return {string[]} The names of the hoisted definitions, in the order they were created.
16
+ * @param {string} content The generated TypeScript types to rewrite the enums of.
17
+ * @param {boolean} [declaration=false] Whether the types are emitted into a declaration
18
+ * (`.d.ts`) file, which holds no runtime values and so declares the constant instead of
19
+ * initializing it.
20
+ * @return {string} The types with every enum declaration rewritten.
21
21
  */
22
- export declare function hoistSharedEnums(schema: OpenAPI3): string[];
22
+ export declare function rewriteEnumsAsObjects(content: string, declaration?: boolean): string;