Skip to content

Commit 34ee973

Browse files
committed
fix: remove most of readonly properties to allow mutating in place
1 parent aad818f commit 34ee973

File tree

9 files changed

+106
-475
lines changed

9 files changed

+106
-475
lines changed

.changeset/little-owls-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/codegen-core': patch
3+
---
4+
5+
fix: remove most of readonly properties to allow mutating in place

dev/openapi-ts.config.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,26 @@ export default defineConfig(() => {
3232
// openapi: '3.1.0',
3333
// paths: {},
3434
// },
35-
path: path.resolve(
36-
getSpecsPath(),
37-
// '3.0.x',
38-
'3.1.x',
39-
// 'circular.yaml',
40-
// 'dutchie.json',
41-
// 'invalid',
42-
// 'openai.yaml',
43-
// 'full.yaml',
44-
// 'opencode.yaml',
45-
// 'sdk-instance.yaml',
46-
// 'string-with-format.yaml',
47-
// 'transformers.json',
48-
// 'type-format.yaml',
49-
'validators.yaml',
50-
// 'validators-circular-ref.json',
51-
// 'validators-circular-ref-2.yaml',
52-
// 'zoom-video-sdk.json',
53-
),
35+
path: 'https://gist.githubusercontent.com/nghiepdev/b2c9996750505ec82adb04fdc9b95ea6/raw/ebe990458001a5c4d3e1de0218f93dcb8f132db8/test-openapi.json',
36+
// path: path.resolve(
37+
// getSpecsPath(),
38+
// // '3.0.x',
39+
// '3.1.x',
40+
// // 'circular.yaml',
41+
// // 'dutchie.json',
42+
// // 'invalid',
43+
// // 'openai.yaml',
44+
// // 'full.yaml',
45+
// // 'opencode.yaml',
46+
// // 'sdk-instance.yaml',
47+
// // 'string-with-format.yaml',
48+
// // 'transformers.json',
49+
// // 'type-format.yaml',
50+
// 'validators.yaml',
51+
// // 'validators-circular-ref.json',
52+
// // 'validators-circular-ref-2.yaml',
53+
// // 'zoom-video-sdk.json',
54+
// ),
5455
// path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0',
5556
// path: 'http://localhost:4000/',
5657
// path: 'http://localhost:8000/openapi.json',
@@ -259,16 +260,17 @@ export default defineConfig(() => {
259260
// fields.unwrap('path')
260261
// },
261262
// include...
262-
instance: true,
263-
// name: '@hey-api/sdk',
263+
// instance: true,
264+
name: '@hey-api/sdk',
264265
// operationId: false,
265-
paramsStructure: 'flat',
266+
// paramsStructure: 'flat',
266267
// responseStyle: 'data',
267268
// signature: 'auto',
268269
// signature: 'client',
269270
// signature: 'object',
270271
// transformer: '@hey-api/transformers',
271-
// transformer: true,
272+
transformer: true,
273+
validator: true,
272274
// validator: {
273275
// request: 'zod',
274276
// response: 'zod',
@@ -290,7 +292,7 @@ export default defineConfig(() => {
290292
{
291293
// bigInt: true,
292294
// dates: true,
293-
// name: '@hey-api/transformers',
295+
name: '@hey-api/transformers',
294296
},
295297
{
296298
// name: 'fastify',
@@ -308,7 +310,7 @@ export default defineConfig(() => {
308310
// mutationOptions: {
309311
// name: '{{name}}MO',
310312
// },
311-
// name: '@tanstack/react-query',
313+
name: '@tanstack/react-query',
312314
// queryKeys: {
313315
// name: '{{name}}QK',
314316
// },

packages/codegen-core/src/__tests__/bindings.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ const makeSymbol = (
6868
): ISymbolOut => {
6969
const { importKind, kind, ...restMeta } = meta as any;
7070
return {
71-
exportFrom: [],
7271
id,
7372
importKind,
7473
kind,

packages/codegen-core/src/__tests__/symbols.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ describe('SymbolRegistry', () => {
1919
placeholder: 'Foo',
2020
});
2121
expect(symbol1).toEqual({
22-
exportFrom: [],
2322
id: expect.any(Number),
2423
meta: {
2524
foo: 'bar',

packages/codegen-core/src/files/types.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ export type IFileSelector = ReadonlyArray<string>;
99

1010
export type IFileIdentifier = number | IFileSelector;
1111

12-
export interface IFileIn {
12+
export type IFileIn = {
1313
/**
1414
* File extension, if any.
1515
*/
16-
readonly extension?: string;
16+
extension?: string;
1717
/**
1818
* Indicates whether the file is external, meaning it is not generated
1919
* as part of the project but is referenced (e.g., a module from
2020
* node_modules).
2121
*
2222
* @example true
2323
*/
24-
readonly external?: boolean;
24+
external?: boolean;
2525
/**
2626
* Unique file ID. If one is not provided, it will be auto-generated.
2727
*/
@@ -32,22 +32,22 @@ export interface IFileIn {
3232
*
3333
* @example "UserModel"
3434
*/
35-
readonly name?: string;
35+
name?: string;
3636
/**
3737
* Absolute logical output path for the file.
3838
*
3939
* @example "/src/models/user.ts"
4040
*/
41-
readonly path?: string;
41+
path?: string;
4242
/**
4343
* Selector array used to select this file.
4444
*
4545
* @example ["foo", "bar"]
4646
*/
4747
readonly selector?: IFileSelector;
48-
}
48+
};
4949

50-
export interface IFileOut extends IFileIn {
50+
export type IFileOut = IFileIn & {
5151
/**
5252
* Unique file ID.
5353
*/
@@ -73,7 +73,7 @@ export interface IFileOut extends IFileIn {
7373
*/
7474
imports: Array<number>;
7575
};
76-
}
76+
};
7777

7878
export interface IFileRegistry {
7979
/**

packages/codegen-core/src/project/project.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ export class Project implements IProject {
5050
symbolIdToFileIds.add(file.id);
5151
this.symbolIdToFileIds.set(symbol.id, symbolIdToFileIds);
5252
// update re-exports
53-
for (const exportFrom of symbol.exportFrom) {
54-
const exportSelector = [exportFrom];
55-
const exportFile = this.files.reference(exportSelector);
56-
if (exportFile.id !== file.id) {
57-
exportFile.symbols.exports.push(symbol.id);
53+
if (symbol.exportFrom) {
54+
for (const exportFrom of symbol.exportFrom) {
55+
const exportSelector = [exportFrom];
56+
const exportFile = this.files.reference(exportSelector);
57+
if (exportFile.id !== file.id) {
58+
exportFile.symbols.exports.push(symbol.id);
59+
}
5860
}
5961
}
6062
}

packages/codegen-core/src/symbols/registry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export class SymbolRegistry implements ISymbolRegistry {
9595
if (cachedId !== undefined) return this.values.get(cachedId)!;
9696
const id = this.id;
9797
const stub: ISymbolOut = {
98-
exportFrom: [],
9998
id,
10099
meta,
101100
placeholder: wrapId(String(id)),
@@ -110,7 +109,6 @@ export class SymbolRegistry implements ISymbolRegistry {
110109
const id = symbol.id !== undefined ? symbol.id : this.id;
111110
const result: ISymbolOut = {
112111
...symbol, // clone to avoid mutation
113-
exportFrom: symbol.exportFrom ?? [],
114112
id,
115113
placeholder: symbol.placeholder ?? wrapId(String(id)),
116114
};

packages/codegen-core/src/symbols/types.d.ts

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,67 @@ import type { ISymbolMeta } from '../extensions/types';
22

33
export type ISymbolIdentifier = number | ISymbolMeta;
44

5-
export interface ISymbolIn {
5+
export type ISymbolIn = {
66
/**
77
* Array of file names (without extensions) from which this symbol is re-exported.
88
*
99
* @default undefined
1010
*/
11-
readonly exportFrom?: ReadonlyArray<string>;
11+
exportFrom?: ReadonlyArray<string>;
1212
/**
1313
* Whether this symbol is exported from its own file.
1414
*
1515
* @default false
1616
*/
17-
readonly exported?: boolean;
17+
exported?: boolean;
1818
/**
1919
* External module name if this symbol is imported from a module not managed
2020
* by the project (e.g. "zod", "lodash").
2121
*
2222
* @default undefined
2323
*/
24-
readonly external?: string;
24+
external?: string;
2525
/**
2626
* Optional output strategy to override default behavior.
2727
*
2828
* @returns The file path to output the symbol to, or undefined to fallback to default behavior.
2929
*/
30-
readonly getFilePath?: (symbol: ISymbolOut) => string | undefined;
30+
getFilePath?: (symbol: ISymbolOut) => string | undefined;
3131
/**
3232
* Unique symbol ID. If one is not provided, it will be auto-generated.
3333
*/
3434
readonly id?: number;
3535
/**
3636
* Kind of import if this symbol represents an import.
3737
*/
38-
readonly importKind?: 'namespace' | 'default' | 'named';
38+
importKind?: 'namespace' | 'default' | 'named';
3939
/**
4040
* Kind of symbol.
4141
*/
42-
readonly kind?: 'class' | 'function' | 'type';
42+
kind?: 'class' | 'function' | 'type';
4343
/**
4444
* Arbitrary metadata about the symbol.
4545
*
4646
* @default undefined
4747
*/
48-
readonly meta?: ISymbolMeta;
48+
meta?: ISymbolMeta;
4949
/**
5050
* The desired name for the symbol within its file. If there are multiple symbols
5151
* with the same desired name, this might not end up being the actual name.
5252
*
5353
* @example "UserModel"
5454
*/
55-
readonly name?: string;
55+
name?: string;
5656
/**
5757
* Placeholder name for the symbol to be replaced later with the final value.
5858
*
5959
* @example "_heyapi_31_"
6060
*/
6161
readonly placeholder?: string;
62-
}
62+
};
6363

64-
export interface ISymbolOut extends ISymbolIn {
65-
/**
66-
* Array of file names (without extensions) from which this symbol is re-exported.
67-
*/
68-
readonly exportFrom: ReadonlyArray<string>;
69-
/**
70-
* Unique symbol ID.
71-
*/
72-
readonly id: number;
73-
/**
74-
* Placeholder name for the symbol to be replaced later with the final value.
75-
*
76-
* @example "_heyapi_31_"
77-
*/
78-
readonly placeholder: string;
79-
}
64+
export type ISymbolOut = Omit<ISymbolIn, 'id' | 'placeholder'> &
65+
Pick<Required<ISymbolIn>, 'id' | 'placeholder'>;
8066

8167
export interface ISymbolRegistry {
8268
/**

0 commit comments

Comments
 (0)