Skip to content

Commit

Permalink
fix(type-safe-api): fix websocket api issues (#738)
Browse files Browse the repository at this point in the history
* fix(type-safe-api): use service namespace in prelude and fix docs

* fix(type-safe-api): ensure smithy async transformer jar is included in cache

Addresses a bug where the smithy async transformer was not published as part of the release build,
since build artifacts were loaded from the cache which didn't include the jar
  • Loading branch information
cogwirrel authored Mar 28, 2024
1 parent 8662693 commit 696d2e1
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The `TypeSafeApiProject` projen project sets up the project structure for you. C
1.) To start an empty `monorepo` project, use this command:

```bash
pdk new monorepo-ts
pdk new monorepo-ts --package-manager=pnpm
```

2.) Edit your `.projenrc` and configure `TypeSafeApiProject`.
Expand All @@ -47,13 +47,15 @@ pdk new monorepo-ts
TypeSafeApiProject,
} from "@aws/pdk/type-safe-api";
import { InfrastructureTsProject } from "@aws/pdk/infrastructure";
import { NodePackageManager } from "projen/lib/javascript";

// Create the monorepo
const monorepo = new MonorepoTsProject({
name: "my-project",
devDeps: [
"@aws/pdk",
],
packageManager: NodePackageManager.PNPM,
});

// Create the API project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The `TypeSafeWebSocketApiProject` projen project sets up the project structure f
1.) To start an empty `monorepo` project, use this command:

```bash
pdk new monorepo-ts
pdk new monorepo-ts --package-manager=pnpm
```

2.) Edit your `.projenrc` and configure `TypeSafeWebSocketApiProject`.
Expand All @@ -35,13 +35,13 @@ pdk new monorepo-ts
```ts
import { MonorepoTsProject } from "@aws/pdk/monorepo";
import {
DocumentationFormat,
Language,
Library,
ModelLanguage,
TypeSafeWebSocketApiProject,
WebSocketLibrary,
} from "@aws/pdk/type-safe-api";
import { InfrastructureTsProject } from "@aws/pdk/infrastructure";
import { CloudscapeReactTsWebsiteProject } from "@aws/pdk/cloudscape-react-ts-website";

// Create the monorepo
const monorepo = new MonorepoTsProject({
Expand Down Expand Up @@ -75,10 +75,10 @@ pdk new monorepo-ts
// Lambda handlers in TypeScript
handlers: {
languages: [Language.TYPESCRIPT],
}
},
// Generate react hooks to interact with the API from a React website
library: {
libraries: [Library.TYPESCRIPT_WEBSOCKET_HOOKS],
libraries: [WebSocketLibrary.TYPESCRIPT_WEBSOCKET_HOOKS],
},
});

Expand Down Expand Up @@ -124,9 +124,11 @@ The generated runtime projects include lambda handler wrappers which provide typ

=== "SMITHY"

Use the `@async` trait to select the operation direction. Choose between `client_to_server`, `server_to_client` or `bidirectional`

Use the `@handler` trait, and specify the language you wish to implement this operation in.

```smithy hl_lines="2"
```smithy hl_lines="1-2"
@async(direction: "client_to_server")
@handler(language: "typescript")
operation SubscribeToNotifications {
Expand All @@ -143,9 +145,11 @@ The generated runtime projects include lambda handler wrappers which provide typ

=== "OPENAPI"

Use the `x-async` vendor extension to select the operation direction. Choose between `client_to_server`, `server_to_client` or `bidirectional`

Use the `x-handler` vendor extension, specifying the language you wish to implement this operation in.

```yaml hl_lines="4-5"
```yaml hl_lines="4-7"
/SubscribeToNotifications:
post:
operationId: SubscribeToNotifications
Expand Down
3 changes: 2 additions & 1 deletion packages/type-safe-api/project.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ metadata validators = [
message: "Operation is missing @async trait"
configuration: {
selector: """
operation :not([trait|com.aws#async])
operation :not([trait|${this.options.serviceNamespace}#async])
"""
}
}
Expand All @@ -65,7 +65,9 @@ metadata validators = [
message: "Service is missing @websocketJson trait"
configuration: {
selector: """
service :not([trait|com.aws#websocketJson])
service :not([trait|${
this.options.serviceNamespace
}#websocketJson])
"""
}
}
Expand Down Expand Up @@ -99,8 +101,10 @@ metadata validators = [
configuration: {
selector: """
operation
[@trait|com.aws#async: @{direction} = server_to_client]
[trait|com.aws#handler]
[@trait|${
this.options.serviceNamespace
}#async: @{direction} = server_to_client]
[trait|${this.options.serviceNamespace}#handler]
"""
}
}
Expand Down
Loading

0 comments on commit 696d2e1

Please sign in to comment.