Skip to content

Commit 0669da0

Browse files
authored
Merge pull request #11 from seamapi/handle-all-options
Add tests for option parsing
2 parents 7a9ec54 + a00807b commit 0669da0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+626
-463
lines changed

ava.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
import { env } from 'node:process'
2+
13
export default () => {
4+
delete env.SEAM_API_KEY
5+
delete env.SEAM_ENDPOINT
6+
delete env.SEAM_API_URL
7+
28
return {
39
ignoredByWatcher: ['tmp/**/*'],
410
files: ['**/*.test.ts', '!package/**/*'],

examples/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ export type Handler<Options = EmptyOptions> = DefaultHandler<Options, Context>
1919
type Context = DefaultContext & ClientContext
2020

2121
interface ClientContext {
22-
client: SeamHttp
22+
seam: SeamHttp
2323
}
2424

2525
const commands = [workspace]
2626

2727
const createAppContext: MiddlewareFunction = async (argv) => {
2828
const apiKey = argv['api-key']
2929
if (typeof apiKey !== 'string') throw new Error('Missing Seam API key')
30-
const client = SeamHttp.fromApiKey(apiKey)
31-
argv['client'] = client
30+
const seam = SeamHttp.fromApiKey(apiKey)
31+
argv['seam'] = seam
3232
}
3333

3434
const middleware = [...defaultMiddleware, createAppContext]
3535

3636
await landlubber<Context>(commands, { middleware })
3737
.describe('api-key', 'Seam API key')
3838
.string('api-key')
39-
.default('api-key', env['SEAM_API_KEY'], 'SEAM_API_KEY')
39+
.default('api-key', env.SEAM_API_KEY, 'SEAM_API_KEY')
4040
.demandOption('api-key')
4141
.parse()

examples/workspace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const describe: Describe = 'Get workspace'
1111

1212
export const builder: Builder = {}
1313

14-
export const handler: Handler<Options> = async ({ client, logger }) => {
15-
const workspace = await client.workspaces.get()
14+
export const handler: Handler<Options> = async ({ seam, logger }) => {
15+
const workspace = await seam.workspaces.get()
1616
logger.info({ workspace }, 'workspace')
1717
}

generate-routes.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { readFile, writeFile } from 'node:fs/promises'
22
import { resolve } from 'node:path'
33

44
import { openapi } from '@seamapi/types/connect'
5-
import { camelCase, paramCase, pascalCase, snakeCase } from 'change-case'
5+
import { camelCase, kebabCase, pascalCase, snakeCase } from 'change-case'
66
import { ESLint } from 'eslint'
77
import { format, resolveConfig } from 'prettier'
88

9-
const rootClassPath = resolve('src', 'lib', 'seam', 'connect', 'client.ts')
9+
const rootClassPath = resolve('src', 'lib', 'seam', 'connect', 'seam-http.ts')
1010
const routeOutputPath = resolve('src', 'lib', 'seam', 'connect', 'routes')
1111

1212
const routePaths = [
@@ -237,7 +237,7 @@ import type { RouteRequestParams, RouteResponse, RouteRequestBody } from '@seama
237237
import { Axios } from 'axios'
238238
import type { SetNonNullable } from 'type-fest'
239239
240-
import { createAxiosClient } from 'lib/seam/connect/axios.js'
240+
import { createClient } from 'lib/seam/connect/client.js'
241241
import {
242242
isSeamHttpOptionsWithApiKey,
243243
isSeamHttpOptionsWithClient,
@@ -247,7 +247,7 @@ import {
247247
type SeamHttpOptionsWithApiKey,
248248
type SeamHttpOptionsWithClient,
249249
type SeamHttpOptionsWithClientSessionToken,
250-
} from 'lib/seam/connect/client-options.js'
250+
} from 'lib/seam/connect/options.js'
251251
import { parseOptions } from 'lib/seam/connect/parse-options.js'
252252
${subresources
253253
.map((subresource) => renderSubresourceImport(subresource, namespace))
@@ -259,7 +259,7 @@ const renderSubresourceImport = (
259259
): string => `
260260
import {
261261
SeamHttp${pascalCase(namespace)}${pascalCase(subresource)}
262-
} from './${paramCase(namespace)}-${paramCase(subresource)}.js'
262+
} from './${kebabCase(namespace)}-${kebabCase(subresource)}.js'
263263
`
264264

265265
const renderClass = (
@@ -389,13 +389,13 @@ const writeRoute = async (route: Route): Promise<void> => {
389389
await write(
390390
renderRoute(route, { constructors }),
391391
routeOutputPath,
392-
`${paramCase(route.namespace)}.ts`,
392+
`${kebabCase(route.namespace)}.ts`,
393393
)
394394
}
395395

396396
const writeRoutesIndex = async (routes: Route[]): Promise<void> => {
397397
const exports = routes.map(
398-
(route) => `export * from './${paramCase(route.namespace)}.js'`,
398+
(route) => `export * from './${kebabCase(route.namespace)}.js'`,
399399
)
400400
await write(exports.join('\n'), routeOutputPath, `index.ts`)
401401
}

0 commit comments

Comments
 (0)