Skip to content

Commit 9fb7ad7

Browse files
committed
feat: Add SeamHttpEndpointsWithoutWorkspace
1 parent 21a27ff commit 9fb7ad7

12 files changed

+309
-30
lines changed

codegen/layouts/endpoints.hbs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
{{> route-imports }}
7+
{{> route-imports-without-workspace }}
78

89
{{#each routeImports}}
910
import {
@@ -15,7 +16,11 @@ import {
1516
{{/each}}
1617

1718
export class {{className}} {
19+
{{#if withoutWorkspace}}
20+
{{> route-class-methods-without-workspace }}
21+
{{else}}
1822
{{> route-class-methods }}
23+
{{/if}}
1924

2025
{{#each endpoints}}
2126
get['{{path}}'](): {{> endpont-method-signature isFnType=true }}
@@ -36,8 +41,14 @@ export class {{className}} {
3641
{{/each}}
3742
}
3843

44+
{{#if endpointReadPaths.length}}
3945
export type {{typeNamePrefix}}QueryPaths = {{#each endpointReadPaths}}'{{.}}' {{#unless @last}} | {{/unless}}{{/each}}
46+
{{/if}}
4047

48+
{{#if endpointPaginatedPaths.length}}
4149
export type {{typeNamePrefix}}PaginatedQueryPaths = {{#each endpointPaginatedPaths}}'{{.}}' {{#unless @last}} | {{/unless}}{{/each}}
50+
{{/if}}
4251

52+
{{#if endpointWritePaths.length}}
4353
export type {{typeNamePrefix}}MutationPaths = {{#each endpointWritePaths}}'{{.}}' {{#unless @last}} | {{/unless}}{{/each}}
54+
{{/if}}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
client: Client
2+
readonly defaults: Required<SeamHttpRequestOptions>
3+
readonly ltsVersion = seamApiLtsVersion
4+
static ltsVersion = seamApiLtsVersion
5+
6+
constructor(options: SeamHttpWithoutWorkspaceOptions = {}) {
7+
const opts = parseOptions(options)
8+
this.client = 'client' in opts ? opts.client : createClient(opts)
9+
this.defaults = limitToSeamHttpRequestOptions(opts)
10+
}
11+
12+
static fromClient(
13+
client: SeamHttpWithoutWorkspaceOptionsWithClient['client'],
14+
options: Omit<SeamHttpWithoutWorkspaceOptionsWithClient, 'client'> = {},
15+
): {{className}}{
16+
const constructorOptions = { ...options, client }
17+
if (!isSeamHttpWithoutWorkspaceOptionsWithClient(constructorOptions)) {
18+
throw new SeamHttpWithoutWorkspaceInvalidOptionsError('Missing client')
19+
}
20+
return new {{className}}(constructorOptions)
21+
}
22+
23+
static fromConsoleSessionToken(
24+
consoleSessionToken: SeamHttpWithoutWorkspaceOptionsWithConsoleSessionToken['consoleSessionToken'],
25+
options: Omit<
26+
SeamHttpWithoutWorkspaceOptionsWithConsoleSessionToken,
27+
'consoleSessionToken'
28+
> = {},
29+
): {{className}}{
30+
const constructorOptions = { ...options, consoleSessionToken }
31+
if (
32+
!isSeamHttpWithoutWorkspaceOptionsWithConsoleSessionToken(
33+
constructorOptions,
34+
)
35+
) {
36+
throw new SeamHttpWithoutWorkspaceInvalidOptionsError(
37+
'Missing consoleSessionToken',
38+
)
39+
}
40+
return new {{className}}(constructorOptions)
41+
}
42+
43+
static fromPersonalAccessToken(
44+
personalAccessToken: SeamHttpWithoutWorkspaceOptionsWithPersonalAccessToken['personalAccessToken'],
45+
options: Omit<
46+
SeamHttpWithoutWorkspaceOptionsWithPersonalAccessToken,
47+
'personalAccessToken'
48+
> = {},
49+
): {{className}}{
50+
const constructorOptions = { ...options, personalAccessToken }
51+
if (
52+
!isSeamHttpWithoutWorkspaceOptionsWithPersonalAccessToken(
53+
constructorOptions,
54+
)
55+
) {
56+
throw new SeamHttpWithoutWorkspaceInvalidOptionsError(
57+
'Missing personalAccessToken',
58+
)
59+
}
60+
return new {{className}}(constructorOptions)
61+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { seamApiLtsVersion } from 'lib/lts-version.js'
2+
import { type Client, createClient } from 'lib/seam/connect/client.js'
3+
import {
4+
isSeamHttpWithoutWorkspaceOptionsWithClient,
5+
isSeamHttpWithoutWorkspaceOptionsWithConsoleSessionToken,
6+
isSeamHttpWithoutWorkspaceOptionsWithPersonalAccessToken,
7+
type SeamHttpRequestOptions,
8+
SeamHttpWithoutWorkspaceInvalidOptionsError,
9+
type SeamHttpWithoutWorkspaceOptions,
10+
type SeamHttpWithoutWorkspaceOptionsWithClient,
11+
type SeamHttpWithoutWorkspaceOptionsWithConsoleSessionToken,
12+
type SeamHttpWithoutWorkspaceOptionsWithPersonalAccessToken,
13+
} from 'lib/seam/connect/options.js'
14+
import { limitToSeamHttpRequestOptions, parseOptions } from 'lib/seam/connect/parse-options.js'

codegen/layouts/without-workspace.hbs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Automatically generated by codegen/smith.ts.
3+
* Do not edit this file or add other files to this directory.
4+
*/
5+
6+
{{> route-imports-without-workspace }}
7+
8+
import { SeamHttpWorkspaces } from 'lib/seam/connect/routes/workspaces/index.js'
9+
10+
export class SeamHttpWithoutWorkspace {
11+
{{> route-class-methods-without-workspace }}
12+
13+
get workspaces(): Pick<SeamHttpWorkspaces, 'create' | 'list'> {
14+
return SeamHttpWorkspaces.fromClient(this.client, this.defaults)
15+
}
16+
}
17+
18+
/**
19+
* @deprecated Use SeamHttpWithoutWorkspace instead.
20+
*/
21+
export const SeamHttpMultiWorkspace = SeamHttpWithoutWorkspace

codegen/lib/connect.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ export const connect = (
7272
setEndpointsLayoutContext(endpointFile, routes)
7373
routeIndexes['']?.add('seam-http-endpoints.js')
7474

75+
const withoutWorkspaceKey = `${rootPath}/seam-http-without-workspace.ts`
76+
files[withoutWorkspaceKey] = { contents: Buffer.from('\n') }
77+
const withoutWorkspaceFile = files[withoutWorkspaceKey] as unknown as File
78+
withoutWorkspaceFile.layout = 'without-workspace.hbs'
79+
withoutWorkspaceFile.className = 'SeamHttpWithoutWorkspace'
80+
routeIndexes['']?.add('seam-http-without-workspace.js')
81+
82+
const endpointsWithoutWorkspaceKey = `${rootPath}/seam-http-endpoints-without-workspace.ts`
83+
files[endpointsWithoutWorkspaceKey] = { contents: Buffer.from('\n') }
84+
const endpointWithoutWorkspaceFile = files[
85+
endpointsWithoutWorkspaceKey
86+
] as unknown as File
87+
endpointWithoutWorkspaceFile.layout = 'endpoints.hbs'
88+
setEndpointsLayoutContext(endpointWithoutWorkspaceFile, routes, {
89+
withoutWorkspace: true,
90+
})
91+
routeIndexes['']?.add('seam-http-endpoints-without-workspace.js')
92+
7593
for (const node of nodes) {
7694
const path = toFilePath(node.path)
7795
const name = kebabCase(node.name)

codegen/lib/layouts/endpoints.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Route } from '@seamapi/blueprint'
1+
import type { Endpoint, Route } from '@seamapi/blueprint'
22

33
import {
44
type EndpointLayoutContext,
@@ -10,6 +10,7 @@ import {
1010
export interface EndpointsLayoutContext {
1111
className: string
1212
typeNamePrefix: string
13+
withoutWorkspace: boolean
1314
endpoints: EndpointLayoutContext[]
1415
endpointReadPaths: string[]
1516
endpointPaginatedPaths: string[]
@@ -27,22 +28,33 @@ interface RouteImportLayoutContext {
2728
export const setEndpointsLayoutContext = (
2829
file: Partial<EndpointsLayoutContext>,
2930
routes: Route[],
31+
{ withoutWorkspace = false }: { withoutWorkspace?: boolean } = {},
3032
): void => {
31-
file.className = getClassName('Endpoints')
32-
file.typeNamePrefix = getClassName('Endpoint')
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+
)
3343
file.skipClientSessionImport = true
3444
file.endpoints = routes.flatMap((route) =>
35-
route.endpoints.map((endpoint) =>
36-
getEndpointLayoutContext(endpoint, route),
37-
),
45+
route.endpoints
46+
.filter(endpointFilter)
47+
.map((endpoint) => getEndpointLayoutContext(endpoint, route)),
3848
)
3949
file.endpointReadPaths = routes.flatMap((route) =>
4050
route.endpoints
51+
.filter(endpointFilter)
4152
.filter(({ request }) => request.semanticMethod === 'GET')
4253
.map(({ path }) => path),
4354
)
4455
file.endpointPaginatedPaths = routes.flatMap((route) =>
4556
route.endpoints
57+
.filter(endpointFilter)
4658
.filter(
4759
({ request, hasPagination }) =>
4860
request.semanticMethod === 'GET' && hasPagination,
@@ -51,21 +63,25 @@ export const setEndpointsLayoutContext = (
5163
)
5264
file.endpointWritePaths = routes.flatMap((route) =>
5365
route.endpoints
66+
.filter(endpointFilter)
5467
.filter(({ request }) => request.semanticMethod !== 'GET')
5568
.map(({ path }) => path),
5669
)
57-
file.routeImports = routes.map((route) => {
58-
const endpoints = route.endpoints.map((endpoint) =>
59-
getEndpointLayoutContext(endpoint, route),
60-
)
61-
return {
62-
className: getClassName(route.path),
63-
fileName: `${toFilePath(route.path)}/index.js`,
64-
typeNames: endpoints.flatMap((endpoint) => [
65-
endpoint.parametersTypeName,
66-
endpoint.optionsTypeName,
67-
endpoint.requestTypeName,
68-
]),
69-
}
70-
})
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+
})
7187
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"axios-retry": "^4.4.2"
9999
},
100100
"devDependencies": {
101-
"@seamapi/blueprint": "^0.51.0",
101+
"@seamapi/blueprint": "^0.51.1",
102102
"@seamapi/fake-seam-connect": "^1.77.0",
103103
"@seamapi/smith": "^0.4.4",
104104
"@seamapi/types": "1.420.2",

src/lib/seam/connect/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export {
1313
export * from './routes/index.js'
1414
export * from './seam-http-error.js'
1515
export * from './seam-http-request.js'
16-
export * from './seam-http-without-workspace.js'
1716
export * from './seam-paginator.js'
1817
export * from './seam-paginator.js'
1918
export {

src/lib/seam/connect/routes/index.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)