···55import { debug } from '../debug';
66import type { Language } from '../languages/types';
77import type { INode } from '../nodes/node';
88-import type { NameScopes } from '../planner/types';
88+import type { NameScopes } from '../planner/scope';
99import type { IProject } from '../project/types';
1010import type { Renderer } from '../renderer';
1111import type { IFileIn } from './types';
+6-10
packages/codegen-core/src/planner/analyzer.ts
···33import { fromRef, isRef, ref } from '../refs/refs';
44import type { Ref } from '../refs/types';
55import type { Symbol } from '../symbols/symbol';
66-import type { IAnalysisContext, Input, NameScopes, Scope } from './types';
77-88-const createScope = (parent?: Scope): Scope => ({
99- children: [],
1010- localNames: new Map(),
1111- parent,
1212- symbols: [],
1313-});
66+import type { NameScopes, Scope } from './scope';
77+import { createScope } from './scope';
88+import type { IAnalysisContext, Input } from './types';
1491510export class AnalysisContext implements IAnalysisContext {
1111+ scope: Scope;
1612 scopes: Scope = createScope();
1713 symbol?: Symbol;
1818- scope: Scope = this.scopes;
19142015 constructor(symbol?: Symbol) {
1616+ this.scope = this.scopes;
2117 this.symbol = symbol;
2218 }
2319···6258 }
63596460 pushScope(): void {
6565- const scope = createScope(this.scope);
6161+ const scope = createScope({ parent: this.scope });
6662 this.scope.children.push(scope);
6763 this.scope = scope;
6864 }
···11+import type { Ref } from '../refs/types';
22+import type { Symbol } from '../symbols/symbol';
33+import type { SymbolKind } from '../symbols/types';
44+55+export type NameScopes = Map<string, Set<SymbolKind>>;
66+77+export type Scope = {
88+ /** Child scopes. */
99+ children: Array<Scope>;
1010+ /** Resolved names in this scope. */
1111+ localNames: NameScopes;
1212+ /** Parent scope, if any. */
1313+ parent?: Scope;
1414+ /** Symbols registered in this scope. */
1515+ symbols: Array<Ref<Symbol>>;
1616+};
1717+1818+export type AssignOptions = {
1919+ /** The primary scope in which to assign a symbol's final name. */
2020+ scope: Scope;
2121+ /** Additional scopes to update as side effects when assigning a symbol's final name. */
2222+ scopesToUpdate: ReadonlyArray<Scope>;
2323+};
2424+2525+export const createScope = (
2626+ args: {
2727+ localNames?: NameScopes;
2828+ parent?: Scope;
2929+ } = {},
3030+): Scope => ({
3131+ children: [],
3232+ localNames: args.localNames || new Map(),
3333+ parent: args.parent,
3434+ symbols: [],
3535+});
+1-21
packages/codegen-core/src/planner/types.d.ts
···11import type { Ref } from '../refs/types';
22import type { Symbol } from '../symbols/symbol';
33-import type { SymbolKind } from '../symbols/types';
44-55-export type AssignOptions = {
66- /** The primary scope in which to assign a symbol's final name. */
77- scope: NameScopes;
88- /** Additional scopes to update as side effects when assigning a symbol's final name. */
99- scopesToUpdate: ReadonlyArray<NameScopes>;
1010-};
33+import type { NameScopes, Scope } from './scope';
114125export type Input = Ref<object> | object | string | number | undefined;
1313-1414-export type NameScopes = Map<string, Set<SymbolKind>>;
156167export type NameConflictResolver = (args: {
178 attempt: number;
189 baseName: string;
1910}) => string | null;
2020-2121-export type Scope = {
2222- /** Child scopes. */
2323- children: Array<Scope>;
2424- /** Resolved names in this scope. */
2525- localNames: NameScopes;
2626- /** Parent scope, if any. */
2727- parent?: Scope;
2828- /** Symbols registered in this scope. */
2929- symbols: Array<Ref<Symbol>>;
3030-};
31113212export interface IAnalysisContext {
3313 /** Register a dependency on another symbol. */
···11import type { IR } from '~/ir/types';
22import type { PluginInstance } from '~/plugins/shared/utils/instance';
33import { refToName } from '~/utils/ref';
44-import { stringCase } from '~/utils/stringCase';
44+import { toCase } from '~/utils/to-case';
5566import type { Field } from '../../client-core/bundle/params';
77···8383 } else if (operation.body.schema.$ref) {
8484 // alias body for more ergonomic naming, e.g. user if the type is User
8585 const name = refToName(operation.body.schema.$ref);
8686- const key = stringCase({ case: 'camelCase', value: name });
8686+ const key = toCase(name, 'camelCase');
8787 addParameter(key, 'body');
8888 } else {
8989 addParameter('body', 'body');
···157157 }
158158 } else if (operation.body.schema.$ref) {
159159 const value = refToName(operation.body.schema.$ref);
160160- const originalName = stringCase({ case: 'camelCase', value });
160160+ const originalName = toCase(value, 'camelCase');
161161 const name = conflicts.has(originalName)
162162 ? `${location}_${originalName}`
163163 : originalName;
···11import { registryName } from '~/plugins/@hey-api/sdk/shared/class';
22import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation';
33import { $ } from '~/ts-dsl';
44-import { stringCase } from '~/utils/stringCase';
44+import { toCase } from '~/utils/to-case';
5566import type { PluginHandler } from '../types';
77import { createInfiniteQueryOptions } from './infiniteQueryOptions';
···100100 e.attr(registryName).attr('get').call(),
101101 );
102102 for (const className of entry.path.slice(1)) {
103103- const cls = stringCase({
104104- case: 'camelCase',
105105- value: className,
106106- });
103103+ const cls = toCase(className, 'camelCase');
107104 queryFn = queryFn.attr(cls);
108105 }
109106 queryFn = queryFn.attr(entry.methodName);
+2-5
packages/openapi-ts/src/plugins/swr/v2/plugin.ts
···11import { registryName } from '~/plugins/@hey-api/sdk/shared/class';
22import { operationClasses } from '~/plugins/@hey-api/sdk/shared/operation';
33import { $ } from '~/ts-dsl';
44-import { stringCase } from '~/utils/stringCase';
44+import { toCase } from '~/utils/to-case';
5566import type { SwrPlugin } from '../types';
77import { createUseSwr } from './useSwr';
···4141 e.attr(registryName).attr('get').call(),
4242 );
4343 for (const className of entry.path.slice(1)) {
4444- const cls = stringCase({
4545- case: 'camelCase',
4646- value: className,
4747- });
4444+ const cls = toCase(className, 'camelCase');
4845 queryFn = queryFn.attr(cls);
4946 }
5047 queryFn = queryFn.attr(entry.methodName);
+4-4
packages/openapi-ts/src/ts-dsl/base.ts
···135135 if (value instanceof Array) {
136136 return value.map((item) => {
137137 if (isRef(item)) item = fromRef(item);
138138- return this.unwrap(item, ctx);
138138+ return this.unwrap(ctx, item);
139139 }) as NodeOfMaybe<I>;
140140 }
141141- return this.unwrap(value as any, ctx) as NodeOfMaybe<I>;
141141+ return this.unwrap(ctx, value as any) as NodeOfMaybe<I>;
142142 }
143143144144 protected $type<I>(
···174174 if (value instanceof Array) {
175175 return value.map((item) => this.$type(ctx, item, args)) as TypeOfMaybe<I>;
176176 }
177177- return this.unwrap(value as any, ctx) as TypeOfMaybe<I>;
177177+ return this.unwrap(ctx, value as any) as TypeOfMaybe<I>;
178178 }
179179180180 /** Unwraps nested nodes into raw TypeScript AST. */
181181 private unwrap<I>(
182182- value: I,
183182 ctx: AstContext,
183183+ value: I,
184184 ): I extends TsDsl<infer N> ? N : I {
185185 return (isNode(value) ? value.toAst(ctx) : value) as I extends TsDsl<
186186 infer N
+10-3
packages/openapi-ts/src/ts-dsl/decl/class.ts
···1818import type { FieldName } from './field';
1919import { FieldTsDsl } from './field';
2020import { InitTsDsl } from './init';
2121+import type { MethodName } from './method';
2122import { MethodTsDsl } from './method';
22232324type Base = Symbol | string;
···6364 }
6465 }
65666767+ /** Returns true if the class has any members. */
6868+ get hasBody(): boolean {
6969+ return this.body.length > 0;
7070+ }
7171+6672 /** Adds one or more class members (fields, methods, etc.). */
6773 do(...items: Body): this {
6874 this.body.push(...items);
···8389 }
84908591 /** Adds a class constructor. */
8686- init(fn?: (i: InitTsDsl) => void): this {
8787- const i = new InitTsDsl(fn);
9292+ init(fn?: InitTsDsl | ((i: InitTsDsl) => void)): this {
9393+ const i =
9494+ typeof fn === 'function' ? new InitTsDsl(fn) : fn || new InitTsDsl();
8895 this.body.push(i);
8996 return this;
9097 }
91989299 /** Adds a class method. */
9393- method(name: string, fn?: (m: MethodTsDsl) => void): this {
100100+ method(name: MethodName, fn?: (m: MethodTsDsl) => void): this {
94101 const m = new MethodTsDsl(name, fn);
95102 this.body.push(m);
96103 return this;