Skip to content

feat: Use smith and blueprint to generate SDK #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
!src/**/*.d.ts
!ava.config.js

# Codegen
CODEGEN.md

# Build directories
docs
package
Expand Down
223 changes: 223 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
# Parts of this file were adapted from
# GitHub’s collection of .gitignore file templates
# which are Copyright (c) 2023 GitHub, Inc.
# and released under the MIT License.
# For more details, visit the project page:
# https://github.com/github/gitignore

# TypeScript build output
*.d.ts
*.js
*.js.map
!src/**/*.d.ts
!ava.config.js

# Build directories
docs
package

# Environment versions file
.versions

# Tern
.tern-project
.tern-port

# npm config
.npmrc

# Temporary development files
tmp

# Yarn lockfile (only package-lock.json supported)
yarn.lock

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Windows

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# macOS

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Prettier exceptions
*.hbs
Expand Down
1 change: 1 addition & 0 deletions codegen/content/CODEGEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Codegen
1 change: 1 addition & 0 deletions codegen/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
1 change: 1 addition & 0 deletions codegen/layouts/default.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{contents}}
7 changes: 7 additions & 0 deletions codegen/layouts/partials/route-class-endpoint-export.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type {{requestTypeName}} = RouteRequest{{requestFormatSuffix}}<'{{path}}'>

export type {{responseTypeName}} = SetNonNullable<
Required<RouteResponse<'{{path}}'>>
>

export type {{optionsTypeName}} = {{#if returnsActionAttempt}}Pick<SeamHttpRequestOptions, 'waitForActionAttempt'>{{else}}never{{/if}}
13 changes: 13 additions & 0 deletions codegen/layouts/partials/route-class-endpoint.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{methodName}}(
{{methodParamName}}{{#if isOptionalParamsOk}}?{{/if}}: {{requestTypeName}},
{{#if hasOptions}}options: {{optionsTypeName}} = {},{{/if}}
): SeamHttpRequest<{{#if returnsVoid}}void, undefined{{else}}{{responseTypeName}}, '{{responseKey}}'{{/if}}>
{
return new SeamHttpRequest(this, {
pathname: '{{path}}',
method: '{{method}}',
{{requestFormat}}: {{methodParamName}},
responseKey: {{#if returnsVoid}}undefined{{else}}'{{responseKey}}'{{/if}},
{{#if hasOptions}}options,{{/if}}
})
}
125 changes: 125 additions & 0 deletions codegen/layouts/partials/route-class-methods.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
client: Client
readonly defaults: Required<SeamHttpRequestOptions>
readonly ltsVersion = seamApiLtsVersion
static ltsVersion = seamApiLtsVersion

constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
const options = parseOptions(apiKeyOrOptions)
this.client = 'client' in options ? options.client : createClient(options)
this.defaults = limitToSeamHttpRequestOptions(options)
}

static fromClient(
client: SeamHttpOptionsWithClient['client'],
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
): {{className}} {
const constructorOptions = { ...options, client }
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
throw new SeamHttpInvalidOptionsError('Missing client')
}
return new {{className}}(constructorOptions)
}

static fromApiKey(
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
): {{className}} {
const constructorOptions = { ...options, apiKey }
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
throw new SeamHttpInvalidOptionsError('Missing apiKey')
}
return new {{className}}(constructorOptions)
}

static fromClientSessionToken(
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
options: Omit<
SeamHttpOptionsWithClientSessionToken,
'clientSessionToken'
> = {},
): {{className}} {
const constructorOptions = { ...options, clientSessionToken }
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
}
return new {{className}}(constructorOptions)
}

static async fromPublishableKey(
publishableKey: string,
userIdentifierKey: string,
options: SeamHttpFromPublishableKeyOptions = {},
): Promise<{{className}}> {
warnOnInsecureuserIdentifierKey(userIdentifierKey)
const clientOptions = parseOptions({ ...options, publishableKey })
if (isSeamHttpOptionsWithClient(clientOptions)) {
throw new SeamHttpInvalidOptionsError(
'The client option cannot be used with {{className}}.fromPublishableKey',
)
}
const client = createClient(clientOptions)
const clientSessions = SeamHttpClientSessions.fromClient(client)
const { token } = await clientSessions.getOrCreate({
user_identifier_key: userIdentifierKey,
})
return {{className}}.fromClientSessionToken(token, options)
}

static fromConsoleSessionToken(
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
options: Omit<
SeamHttpOptionsWithConsoleSessionToken,
'consoleSessionToken' | 'workspaceId'
> = {},
): {{className}} {
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
throw new SeamHttpInvalidOptionsError(
'Missing consoleSessionToken or workspaceId',
)
}
return new {{className}}(constructorOptions)
}

static fromPersonalAccessToken(
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
options: Omit<
SeamHttpOptionsWithPersonalAccessToken,
'personalAccessToken' | 'workspaceId'
> = {},
): {{className}} {
const constructorOptions = { ...options, personalAccessToken, workspaceId }
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
throw new SeamHttpInvalidOptionsError(
'Missing personalAccessToken or workspaceId',
)
}
return new {{className}}(constructorOptions)
}

createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
request: SeamHttpRequest<TResponse, TResponseKey>,
): SeamPaginator<TResponse, TResponseKey> {
return new SeamPaginator<TResponse, TResponseKey>(this, request)
}

async updateClientSessionToken(
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
): Promise<void> {
const { headers } = this.client.defaults
const authHeaders = getAuthHeadersForClientSessionToken({
clientSessionToken,
})
for (const key of Object.keys(authHeaders)) {
if (headers[key] == null) {
throw new Error(
'Cannot update a clientSessionToken on a client created without a clientSessionToken',
)
}
}
this.client.defaults.headers = { ...headers, ...authHeaders }
const clientSessions = SeamHttpClientSessions.fromClient(this.client)
await clientSessions.get()
}
3 changes: 3 additions & 0 deletions codegen/layouts/partials/route-class-subroute.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
get {{ methodName }}(): {{ className }} {
return {{ className }}.fromClient(this.client, this.defaults)
}
Loading