Skip to content

Commit 404817d

Browse files
committed
fix: Generate static signature for SeamHttpEndpoints methods
1 parent caf754c commit 404817d

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

codegen/layouts/endpoints.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class SeamHttpEndpoints {
1818
{{> route-class-methods }}
1919

2020
{{#each endpoints}}
21-
get['{{path}}'](): {{className}}['{{methodName}}']
21+
get['{{path}}'](): {{> endpont-method-signature isFnType=true }}
2222
{
2323
const { client, defaults } = this
2424
{{#if isUndocumented}}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(
22
parameters{{#if isOptionalParamsOk}}?{{/if}}: {{parametersTypeName}},
3-
options: {{optionsTypeName}} = {},
4-
): SeamHttpRequest<{{#if returnsVoid}}void, undefined{{else}}{{responseTypeName}}, '{{responseKey}}'{{/if}}>
3+
options{{#if isFnType}}?{{/if}}: {{optionsTypeName}}{{#unless isFnType}} = {}{{/unless}},
4+
){{#if isFnType}} => {{else}}: {{/if}} SeamHttpRequest<{{#if returnsVoid}}void, undefined{{else}}{{responseTypeName}}, '{{responseKey}}'{{/if}}>

codegen/lib/layouts/endpoints.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ import {
44
type EndpointLayoutContext,
55
getClassName,
66
getEndpointLayoutContext,
7-
type SubrouteLayoutContext,
87
toFilePath,
98
} from './route.js'
109

1110
export interface EndpointsLayoutContext {
1211
className: string
1312
endpoints: EndpointLayoutContext[]
14-
routeImports: Array<Pick<SubrouteLayoutContext, 'className' | 'fileName'>>
13+
routeImports: RouteImportLayoutContext[]
1514
skipClientSessionImport: boolean
1615
}
1716

17+
interface RouteImportLayoutContext {
18+
className: string
19+
fileName: string
20+
typeNames: string[]
21+
}
22+
1823
export const setEndpointsLayoutContext = (
1924
file: Partial<EndpointsLayoutContext>,
2025
routes: Route[],
@@ -27,9 +32,17 @@ export const setEndpointsLayoutContext = (
2732
),
2833
)
2934
file.routeImports = routes.map((route) => {
35+
const endpoints = route.endpoints.map((endpoint) =>
36+
getEndpointLayoutContext(endpoint, route),
37+
)
3038
return {
3139
className: getClassName(route.path),
3240
fileName: `${toFilePath(route.path)}/index.js`,
41+
typeNames: endpoints.flatMap((endpoint) => [
42+
endpoint.parametersTypeName,
43+
endpoint.optionsTypeName,
44+
endpoint.responseTypeName,
45+
]),
3346
}
3447
})
3548
}

0 commit comments

Comments
 (0)