1- import type { Route } from '@seamapi/blueprint'
1+ import type { Endpoint , Route } from '@seamapi/blueprint'
22
33import {
44 type EndpointLayoutContext ,
99
1010export interface EndpointsLayoutContext {
1111 className : string
12+ typeNamePrefix : string
13+ withoutWorkspace : boolean
1214 endpoints : EndpointLayoutContext [ ]
1315 endpointReadPaths : string [ ]
1416 endpointPaginatedPaths : string [ ]
@@ -26,21 +28,33 @@ interface RouteImportLayoutContext {
2628export const setEndpointsLayoutContext = (
2729 file : Partial < EndpointsLayoutContext > ,
2830 routes : Route [ ] ,
31+ { withoutWorkspace = false } : { withoutWorkspace ?: boolean } = { } ,
2932) : void => {
30- file . className = getClassName ( 'Endpoints' )
33+ const endpointFilter = ( endpoint : Endpoint ) : boolean =>
34+ withoutWorkspace ? endpoint . workspaceScope !== 'required' : true
35+
36+ file . withoutWorkspace = withoutWorkspace
37+ file . className = getClassName (
38+ `Endpoints${ withoutWorkspace ? 'WithoutWorkspace' : '' } ` ,
39+ )
40+ file . typeNamePrefix = getClassName (
41+ `Endpoint${ withoutWorkspace ? 'WithoutWorkspace' : '' } ` ,
42+ )
3143 file . skipClientSessionImport = true
3244 file . endpoints = routes . flatMap ( ( route ) =>
33- route . endpoints . map ( ( endpoint ) =>
34- getEndpointLayoutContext ( endpoint , route ) ,
35- ) ,
45+ route . endpoints
46+ . filter ( endpointFilter )
47+ . map ( ( endpoint ) => getEndpointLayoutContext ( endpoint , route ) ) ,
3648 )
3749 file . endpointReadPaths = routes . flatMap ( ( route ) =>
3850 route . endpoints
51+ . filter ( endpointFilter )
3952 . filter ( ( { request } ) => request . semanticMethod === 'GET' )
4053 . map ( ( { path } ) => path ) ,
4154 )
4255 file . endpointPaginatedPaths = routes . flatMap ( ( route ) =>
4356 route . endpoints
57+ . filter ( endpointFilter )
4458 . filter (
4559 ( { request, hasPagination } ) =>
4660 request . semanticMethod === 'GET' && hasPagination ,
@@ -49,21 +63,25 @@ export const setEndpointsLayoutContext = (
4963 )
5064 file . endpointWritePaths = routes . flatMap ( ( route ) =>
5165 route . endpoints
66+ . filter ( endpointFilter )
5267 . filter ( ( { request } ) => request . semanticMethod !== 'GET' )
5368 . map ( ( { path } ) => path ) ,
5469 )
55- file . routeImports = routes . map ( ( route ) => {
56- const endpoints = route . endpoints . map ( ( endpoint ) =>
57- getEndpointLayoutContext ( endpoint , route ) ,
58- )
59- return {
60- className : getClassName ( route . path ) ,
61- fileName : `${ toFilePath ( route . path ) } /index.js` ,
62- typeNames : endpoints . flatMap ( ( endpoint ) => [
63- endpoint . parametersTypeName ,
64- endpoint . optionsTypeName ,
65- endpoint . requestTypeName ,
66- ] ) ,
67- }
68- } )
70+ file . routeImports = routes
71+ . filter ( ( route ) => route . endpoints . some ( endpointFilter ) )
72+ . map ( ( route ) => {
73+ const endpoints = route . endpoints
74+ . filter ( endpointFilter )
75+ . map ( ( endpoint ) => getEndpointLayoutContext ( endpoint , route ) )
76+
77+ return {
78+ className : getClassName ( route . path ) ,
79+ fileName : `${ toFilePath ( route . path ) } /index.js` ,
80+ typeNames : endpoints . flatMap ( ( endpoint ) => [
81+ endpoint . parametersTypeName ,
82+ endpoint . optionsTypeName ,
83+ endpoint . requestTypeName ,
84+ ] ) ,
85+ }
86+ } )
6987}
0 commit comments