diff --git a/.changeset/hungry-tomatoes-remember.md b/.changeset/hungry-tomatoes-remember.md new file mode 100644 index 00000000..c7be3be9 --- /dev/null +++ b/.changeset/hungry-tomatoes-remember.md @@ -0,0 +1,5 @@ +--- +"@codedazur/cdk-rpc-api": major +--- + +stable release diff --git a/apps/infrastructure/stacks/Storybook.ts b/apps/infrastructure/stacks/Storybook.ts index 43e3536b..9a86b5af 100644 --- a/apps/infrastructure/stacks/Storybook.ts +++ b/apps/infrastructure/stacks/Storybook.ts @@ -1,6 +1,5 @@ -import { StaticSite } from "@codedazur/cdk-static-site"; -import { App, Stack, StackProps } from "aws-cdk-lib"; import { env } from "@codedazur/essentials"; +import { App, Stack, StackProps } from "aws-cdk-lib"; import { ToolkitSite } from "../constructs/ToolkitSite"; export class Storybook extends Stack { diff --git a/apps/infrastructure/stacks/Website.ts b/apps/infrastructure/stacks/Website.ts index 1614854b..81533319 100644 --- a/apps/infrastructure/stacks/Website.ts +++ b/apps/infrastructure/stacks/Website.ts @@ -1,6 +1,5 @@ -import { StaticSite } from "@codedazur/cdk-static-site"; -import { App, Stack, StackProps } from "aws-cdk-lib"; import { env } from "@codedazur/essentials"; +import { App, Stack, StackProps } from "aws-cdk-lib"; import { ToolkitSite } from "../constructs/ToolkitSite"; export class Website extends Stack { diff --git a/packages/cdk-api/README.md b/packages/cdk-api/README.md deleted file mode 100644 index dc4f52da..00000000 --- a/packages/cdk-api/README.md +++ /dev/null @@ -1 +0,0 @@ -# @codedazur/cdk-api diff --git a/packages/cdk-api/index.ts b/packages/cdk-api/index.ts deleted file mode 100644 index c78af47c..00000000 --- a/packages/cdk-api/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./constructs/RestApi"; diff --git a/packages/cdk-api/LICENSE.md b/packages/cdk-rpc-api/LICENSE.md similarity index 100% rename from packages/cdk-api/LICENSE.md rename to packages/cdk-rpc-api/LICENSE.md diff --git a/packages/cdk-rpc-api/README.md b/packages/cdk-rpc-api/README.md new file mode 100644 index 00000000..adf35dda --- /dev/null +++ b/packages/cdk-rpc-api/README.md @@ -0,0 +1 @@ +# @codedazur/cdk-rpc-api diff --git a/packages/cdk-api/constructs/RestApi.ts b/packages/cdk-rpc-api/constructs/RpcApi.ts similarity index 64% rename from packages/cdk-api/constructs/RestApi.ts rename to packages/cdk-rpc-api/constructs/RpcApi.ts index e9b763a9..484ecda5 100644 --- a/packages/cdk-api/constructs/RestApi.ts +++ b/packages/cdk-rpc-api/constructs/RpcApi.ts @@ -17,8 +17,8 @@ import { import { ApiGateway } from "aws-cdk-lib/aws-route53-targets"; import { Construct } from "constructs"; -export interface ApiProps extends RestApiProps { - endpoints: Record; +export interface RpcApiProps extends RestApiProps { + procedures: Record; domain?: DomainProps; } @@ -27,33 +27,64 @@ interface DomainProps { subdomain?: string; } -interface ResourceProps { +interface ProcedureProps { method?: HttpMethod; handler?: IFunction; - endpoints?: Record; + procedures?: Record; } -export class Api extends RestApi { - constructor(scope: Construct, id: string, { endpoints, ...props }: ApiProps) { +/** + * A construct to create a Remote Procedure Call API on API Gateway. + * + * @example + * new RpcApi(this, "MyRpcApi", { + * procedures: { + * helloWorld: { + * method: HttpMethod.GET, + * handler: helloWorldHandler, + * }, + * search: { + * method: HttpMethod.GET, + * handler: searchHandler, + * procedures: { + * createIndex: { + * method: HttpMethod.POST, + * handler: createIndexHandler, + * }, + * flushIndex: { + * method: HttpMethod.DELETE, + * handler: flushIndexHandler, + * }, + * }, + * }, + * }, + * }); + */ +export class RpcApi extends RestApi { + constructor( + scope: Construct, + id: string, + { procedures: endpoints, ...props }: RpcApiProps, + ) { super(scope, id, props); - this.createEndpoints(this.root, endpoints); + this.createProcedures(this.root, endpoints); this.createDomain(props.domain); } - protected createEndpoints( + protected createProcedures( parent: IResource, - children: Record, + children: Record, ) { Object.entries(children).forEach(([slug, child]) => - this.createEndpoint(parent, slug, child), + this.createProcedure(parent, slug, child), ); } - protected createEndpoint( + protected createProcedure( parent: IResource, slug: string, - { method, handler, endpoints }: ResourceProps, + { method, handler, procedures: endpoints }: ProcedureProps, ) { const resource = parent.addResource(slug, { defaultIntegration: @@ -65,7 +96,7 @@ export class Api extends RestApi { } if (endpoints) { - this.createEndpoints(resource, endpoints); + this.createProcedures(resource, endpoints); } } diff --git a/packages/cdk-rpc-api/index.ts b/packages/cdk-rpc-api/index.ts new file mode 100644 index 00000000..086276cf --- /dev/null +++ b/packages/cdk-rpc-api/index.ts @@ -0,0 +1 @@ +export * from "./constructs/RpcApi"; diff --git a/packages/cdk-api/package.json b/packages/cdk-rpc-api/package.json similarity index 93% rename from packages/cdk-api/package.json rename to packages/cdk-rpc-api/package.json index f0445e21..7fa408a5 100644 --- a/packages/cdk-api/package.json +++ b/packages/cdk-rpc-api/package.json @@ -1,5 +1,5 @@ { - "name": "@codedazur/cdk-rest-api", + "name": "@codedazur/cdk-rpc-api", "version": "0.0.0", "main": "./index.ts", "types": "./index.ts", diff --git a/packages/cdk-api/tsconfig.json b/packages/cdk-rpc-api/tsconfig.json similarity index 100% rename from packages/cdk-api/tsconfig.json rename to packages/cdk-rpc-api/tsconfig.json