-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(type-safe-api): faster code generation for typescript websocket …
…projects (#846) * feat(type-safe-api): faster codegen for typescript async infra Move typescript async infrastructure to the new codegen * feat(type-safe-api): faster codegen for typescript async handlers Move typescript async handlers to the new codegen * feat(type-safe-api): faster codegen for typescript async runtime Move typescript async runtime to the new codegen * feat(type-safe-api): faster codegen for typescript websocket client library Move typescript websocket client library to new codegen * feat(type-safe-api): faster codegen for typescript async websocket hooks Move typescript async websocket hooks to the new codegen
- Loading branch information
Showing
56 changed files
with
902 additions
and
4,556 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
13 changes: 0 additions & 13 deletions
13
...safe-api/scripts/type-safe-api/generators/typescript-async-cdk-infrastructure/config.yaml
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
159 changes: 159 additions & 0 deletions
159
...ipts/type-safe-api/generators/typescript-async-cdk-infrastructure/templates/functions.ejs
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,159 @@ | ||
###TSAPI_WRITE_FILE### | ||
{ | ||
"dir": "<%- metadata.srcDir || 'src' %>", | ||
"name": "functions", | ||
"ext": ".ts", | ||
"overwrite": true | ||
} | ||
###/TSAPI_WRITE_FILE###import { Construct } from "constructs"; | ||
import { Duration } from "aws-cdk-lib"; | ||
import { SnapStartFunction, SnapStartFunctionProps } from "@aws/pdk/type-safe-api"; | ||
import { Code, Function, Runtime, Tracing, FunctionProps } from "aws-cdk-lib/aws-lambda"; | ||
import * as path from "path"; | ||
|
||
<%_ if (vendorExtensions['x-connect-handler']) { _%> | ||
<%_ const language = vendorExtensions['x-connect-handler'].language; _%> | ||
<%_ const isTypeScript = language === 'typescript'; _%> | ||
<%_ const isJava = language === 'java'; _%> | ||
<%_ const isPython = language === 'python'; _%> | ||
/** | ||
* Options for the $ConnectFunction construct | ||
*/ | ||
export interface $ConnectFunctionProps extends Omit<<% if (isJava) { %>SnapStart<% } %>FunctionProps, 'code' | 'handler' | 'runtime'> {} | ||
/** | ||
* Lambda function construct which points to the <%- language %> implementation for the websocket connect event | ||
*/ | ||
export class $ConnectFunction extends <% if (isJava) { %>SnapStart<% } %>Function { | ||
constructor(scope: Construct, id: string, props?: $ConnectFunctionProps) { | ||
super(scope, id, { | ||
<%_ if (isTypeScript) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-node-lambda-runtime-version'] %>, | ||
<%_ } else if (isPython) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-python-lambda-runtime-version'] %>, | ||
<%_ } else if (isJava) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-java-lambda-runtime-version'] %>, | ||
<%_ } _%> | ||
<%_ if (isTypeScript) { _%> | ||
handler: "index.handler", | ||
<%_ } else if (isPython) { _%> | ||
handler: "<%- metadata['x-handlers-python-module'] %>.__connect.handler", | ||
<%_ } else if (isJava) { _%> | ||
handler: "<%- metadata['x-handlers-java-package'] %>.$ConnectHandler", | ||
<%_ } _%> | ||
code: Code.fromAsset(path.resolve(__dirname, "..", | ||
<%_ if (isTypeScript) { _%> | ||
"<%- metadata['x-handlers-typescript-asset-path'] %>", | ||
"$connect", | ||
<%_ } else if (isPython) { _%> | ||
"<%- metadata['x-handlers-python-asset-path'] %>", | ||
<%_ } else if (isJava) { _%> | ||
"<%- metadata['x-handlers-java-asset-path'] %>", | ||
<%_ } _%> | ||
)), | ||
tracing: Tracing.ACTIVE, | ||
timeout: Duration.seconds(30), | ||
...props, | ||
}); | ||
} | ||
} | ||
<%_ } _%> | ||
|
||
<%_ if (vendorExtensions['x-disconnect-handler']) { _%> | ||
<%_ const language = vendorExtensions['x-disconnect-handler'].language; _%> | ||
<%_ const isTypeScript = language === 'typescript'; _%> | ||
<%_ const isJava = language === 'java'; _%> | ||
<%_ const isPython = language === 'python'; _%> | ||
/** | ||
* Options for the $DisconnectFunction construct | ||
*/ | ||
export interface $DisconnectFunctionProps extends Omit<<% if (isJava) { %>SnapStart<% } %>FunctionProps, 'code' | 'handler' | 'runtime'> {} | ||
/** | ||
* Lambda function construct which points to the <%- language %> implementation for the websocket disconnect event | ||
*/ | ||
export class $DisconnectFunction extends <% if (isJava) { %>SnapStart<% } %>Function { | ||
constructor(scope: Construct, id: string, props?: $DisconnectFunctionProps) { | ||
super(scope, id, { | ||
<%_ if (isTypeScript) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-node-lambda-runtime-version'] %>, | ||
<%_ } else if (isPython) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-python-lambda-runtime-version'] %>, | ||
<%_ } else if (isJava) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-java-lambda-runtime-version'] %>, | ||
<%_ } _%> | ||
<%_ if (isTypeScript) { _%> | ||
handler: "index.handler", | ||
<%_ } else if (isPython) { _%> | ||
handler: "<%- metadata['x-handlers-python-module'] %>.__disconnect.handler", | ||
<%_ } else if (isJava) { _%> | ||
handler: "<%- metadata['x-handlers-java-package'] %>.$DisconnectHandler", | ||
<%_ } _%> | ||
code: Code.fromAsset(path.resolve(__dirname, "..", | ||
<%_ if (isTypeScript) { _%> | ||
"<%- metadata['x-handlers-typescript-asset-path'] %>", | ||
"$disconnect", | ||
<%_ } else if (isPython) { _%> | ||
"<%- metadata['x-handlers-python-asset-path'] %>", | ||
<%_ } else if (isJava) { _%> | ||
"<%- metadata['x-handlers-java-asset-path'] %>", | ||
<%_ } _%> | ||
)), | ||
tracing: Tracing.ACTIVE, | ||
timeout: Duration.seconds(30), | ||
...props, | ||
}); | ||
} | ||
} | ||
<%_ } _%> | ||
<%_ allOperations.forEach((operation) => { _%> | ||
<%_ if (operation.vendorExtensions && operation.vendorExtensions['x-handler']) { _%> | ||
<%_ const language = operation.vendorExtensions['x-handler'].language; _%> | ||
<%_ const isTypeScript = language === 'typescript'; _%> | ||
<%_ const isJava = language === 'java'; _%> | ||
<%_ const isPython = language === 'python'; _%> | ||
/** | ||
* Options for the <%- operation.operationIdPascalCase %>Function construct | ||
*/ | ||
export interface <%- operation.operationIdPascalCase %>FunctionProps extends Omit<<% if (isJava) { %>SnapStart<% } %>FunctionProps, 'code' | 'handler' | 'runtime'> {} | ||
/** | ||
* Lambda function construct which points to the <%- language %> implementation of <%- operation.operationIdPascalCase %> | ||
*/ | ||
export class <%- operation.operationIdPascalCase %>Function extends <% if (isJava) { %>SnapStart<% } %>Function { | ||
constructor(scope: Construct, id: string, props?: <%- operation.operationIdPascalCase %>FunctionProps) { | ||
super(scope, id, { | ||
<%_ if (isTypeScript) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-node-lambda-runtime-version'] %>, | ||
<%_ } else if (isPython) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-python-lambda-runtime-version'] %>, | ||
<%_ } else if (isJava) { _%> | ||
runtime: Runtime.<%- metadata['x-handlers-java-lambda-runtime-version'] %>, | ||
<%_ } _%> | ||
<%_ if (isTypeScript) { _%> | ||
handler: "index.handler", | ||
<%_ } else if (isPython) { _%> | ||
handler: "<%- metadata['x-handlers-python-module'] %>.<%- operation.operationIdSnakeCase %>.handler", | ||
<%_ } else if (isJava) { _%> | ||
handler: "<%- metadata['x-handlers-java-package'] %>.<%- operation.operationIdPascalCase %>Handler", | ||
<%_ } _%> | ||
code: Code.fromAsset(path.resolve(__dirname, "..", | ||
<%_ if (isTypeScript) { _%> | ||
"<%- metadata['x-handlers-typescript-asset-path'] %>", | ||
"<%- operation.operationIdKebabCase %>", | ||
<%_ } else if (isPython) { _%> | ||
"<%- metadata['x-handlers-python-asset-path'] %>", | ||
<%_ } else if (isJava) { _%> | ||
"<%- metadata['x-handlers-java-asset-path'] %>", | ||
<%_ } _%> | ||
)), | ||
tracing: Tracing.ACTIVE, | ||
timeout: Duration.seconds(30), | ||
...props, | ||
}); | ||
} | ||
} | ||
<%_ } _%> | ||
<%_ }); _%> |
153 changes: 0 additions & 153 deletions
153
...pe-safe-api/generators/typescript-async-cdk-infrastructure/templates/functions.handlebars
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.