-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Usage * Add test fixture * Add @seamapi/types * Export blueprint API * Remove todo module * Update describe
- Loading branch information
Showing
25 changed files
with
288 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Builder, Command, Describe, Handler } from 'landlubber' | ||
|
||
import { createBlueprint, type TypesModule } from '@seamapi/blueprint' | ||
|
||
interface Options { | ||
moduleName: string | ||
} | ||
|
||
export const command: Command = 'blueprint [moduleName]' | ||
|
||
export const describe: Describe = 'Create a blueprint from a module' | ||
|
||
export const builder: Builder = { | ||
moduleName: { | ||
type: 'string', | ||
default: '@seamapi/types/connect', | ||
describe: 'Module name or path to import', | ||
}, | ||
} | ||
|
||
export const handler: Handler<Options> = async ({ moduleName, logger }) => { | ||
const types = (await import(moduleName)) as TypesModule | ||
logger.info({ data: createBlueprint(types) }, 'blueprint') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Openapi } from './openapi.js' | ||
|
||
export interface Blueprint { | ||
name: string | ||
} | ||
|
||
export interface TypesModule { | ||
openapi: Openapi | ||
} | ||
|
||
export const createBlueprint = ({ openapi }: TypesModule): Blueprint => { | ||
return { | ||
name: openapi.info.title, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export { todo } from './todo.js' | ||
export { | ||
type Blueprint, | ||
createBlueprint, | ||
type TypesModule, | ||
} from './blueprint.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Openapi { | ||
info: { | ||
title: string | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import test from 'ava' | ||
|
||
import { createBlueprint } from '@seamapi/blueprint' | ||
|
||
import * as types from './fixtures/types/index.js' | ||
|
||
test('createBlueprint', (t) => { | ||
const blueprint = createBlueprint(types) | ||
t.snapshot(blueprint, 'blueprint') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as schemas from './schemas.js' | ||
|
||
export { schemas } | ||
|
||
export * from './model-types.js' | ||
export { default as openapi } from './openapi.js' | ||
export * from './route-schemas.js' | ||
export * from './route-types.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { z } from 'zod' | ||
|
||
import type { foo } from './schemas.js' | ||
|
||
export type Foo = z.infer<typeof foo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
export default { | ||
openapi: '3.0.0', | ||
info: { title: 'Foo', version: '1.0.0' }, | ||
servers: [{ url: 'https://example.com' }], | ||
tags: [{ description: 'foos', name: '/foos' }], | ||
components: { | ||
schemas: { | ||
foo: { | ||
type: 'object', | ||
properties: { | ||
foo_id: { | ||
description: 'Foo id', | ||
format: 'uuid', | ||
type: 'string', | ||
}, | ||
name: { | ||
description: 'Foo name', | ||
type: 'string', | ||
}, | ||
}, | ||
required: ['foo_id', 'name'], | ||
}, | ||
}, | ||
}, | ||
paths: { | ||
'/foos/get': { | ||
get: { | ||
operationId: 'foosGetGet', | ||
responses: { | ||
200: { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
properties: { | ||
ok: { type: 'boolean' }, | ||
foo: { $ref: '#/components/schemas/foo' }, | ||
}, | ||
required: ['foo', 'ok'], | ||
type: 'object', | ||
}, | ||
}, | ||
}, | ||
description: 'OK', | ||
}, | ||
400: { description: 'Bad Request' }, | ||
401: { description: 'Unauthorized' }, | ||
}, | ||
security: [], | ||
summary: '/foos/get', | ||
tags: ['/foos'], | ||
}, | ||
post: { | ||
operationId: 'foosGetPost', | ||
responses: { | ||
200: { | ||
content: { | ||
'application/json': { | ||
schema: { | ||
properties: { | ||
ok: { type: 'boolean' }, | ||
foo: { $ref: '#/components/schemas/foo' }, | ||
}, | ||
required: ['foo', 'ok'], | ||
type: 'object', | ||
}, | ||
}, | ||
}, | ||
description: 'OK', | ||
}, | ||
400: { description: 'Bad Request' }, | ||
401: { description: 'Unauthorized' }, | ||
}, | ||
security: [], | ||
summary: '/foos/get', | ||
tags: ['/foos'], | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { z } from 'zod' | ||
|
||
import * as schemas from './schemas.js' | ||
|
||
export const routes = { | ||
'/foos/get': { | ||
auth: 'none', | ||
methods: ['GET', 'POST'], | ||
jsonResponse: z.object({ | ||
foo: schemas.foo, | ||
}), | ||
}, | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { z } from 'zod' | ||
|
||
import * as schemas from './schemas.js' | ||
|
||
export const routes = { | ||
'/foos/get': { | ||
auth: 'none', | ||
methods: ['GET', 'POST'], | ||
jsonResponse: z.object({ | ||
foo: schemas.foo, | ||
}), | ||
}, | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export interface Routes { | ||
'/foos/get': { | ||
route: '/foos/get' | ||
method: 'GET' | 'POST' | ||
queryParams: Record<string, unknown> | ||
jsonBody: Record<string, unknown> | ||
commonParams: Record<string, unknown> | ||
formData: Record<string, unknown> | ||
jsonResponse: { | ||
foo: { | ||
foo_id: string | ||
name: string | ||
} | ||
} | ||
} | ||
} | ||
|
||
export type RouteResponse<Path extends keyof Routes> = | ||
Routes[Path]['jsonResponse'] | ||
|
||
export type RouteRequestBody<Path extends keyof Routes> = | ||
Routes[Path]['jsonBody'] & Routes[Path]['commonParams'] | ||
|
||
export type RouteRequestParams<Path extends keyof Routes> = | ||
Routes[Path]['queryParams'] & Routes[Path]['commonParams'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { z } from 'zod' | ||
|
||
export const foo = z.object({ | ||
foo_id: z.string().uuid(), | ||
name: z.string(), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { openapi } from '@seamapi/types/connect' | ||
import test from 'ava' | ||
|
||
import { createBlueprint } from '@seamapi/blueprint' | ||
|
||
test('createBlueprint', (t) => { | ||
const blueprint = createBlueprint({ openapi }) | ||
t.snapshot(blueprint, 'blueprint') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Snapshot report for `test/blueprint.test.ts` | ||
|
||
The actual snapshot is saved in `blueprint.test.ts.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## createBlueprint | ||
|
||
> blueprint | ||
{ | ||
name: 'Foo', | ||
} |
Binary file not shown.
Oops, something went wrong.