Skip to content

Migrate to TypeScript with esbuild bundling and Vitest smoke tests#3

Open
Valamorde wants to merge 1 commit into
refactor/phase-2-node22-sdk-v3from
refactor/phase-3-typescript
Open

Migrate to TypeScript with esbuild bundling and Vitest smoke tests#3
Valamorde wants to merge 1 commit into
refactor/phase-2-node22-sdk-v3from
refactor/phase-3-typescript

Conversation

@Valamorde
Copy link
Copy Markdown
Owner

Summary

  • Converts all Lambda functions from plain JS to TypeScript
  • Switches CDK to NodejsFunction (esbuild bundling) — no per-function package.json needed
  • Introduces a src/shared/ module for the DDB client singleton, ApiGW factory, key builders, and domain types
  • Decomposes the 300-line sendmessage if-chain into a typed dispatch map with one handler file per event type
  • Adds Vitest smoke tests (20 tests) covering connect, disconnect, services, and all sendmessage handlers
  • Fixes several bugs from the original JS code:
    • objectid declared without const (implicit global) in onconnect
    • for(tokenid in tokens) implicit global in services
    • Batch slice overlap (slice(i, i+21) with i+=20) causing duplicated writes
    • Hardcoded table name "abovevtt" instead of TABLE_NAME env var
    • Dead imports removed (PRIORITY_ABOVE_NORMAL, require('http'))
    • tsconfig.json typo noFalltriganCasesInSwitch corrected

Wire protocol

All HTTP paths, WebSocket eventType values, and JSON response shapes are preserved exactly. The browser extension requires no changes.

Test plan

  • pnpm test — all 20 smoke tests pass
  • cdk diff — Lambda functions replaced (expected), DynamoDB table unchanged
  • End-to-end: WebSocket session with DM + player, scene switch, token move

- Convert all 5 Lambdas from AssetCode/JS to NodejsFunction/TS with esbuild bundling
  (externalModules: ['@aws-sdk/*'] — runtime provides SDK v3 on Node 22)
- Add src/ layout: shared/{types,keys,db,apigw}, connect, disconnect, keepalive,
  services, sendmessage (router + 7 sub-handlers)
- Decompose 300-line sendmessage if-chain into dispatch map + NO_FORWARD set
- Add src/shared/keys.ts — canonical objectId key builders (wire-safe)
- Add 20 Vitest smoke tests across 8 test files; all pass
- Fix noImplicitReturns in forward.ts catch callback
- Add skipLibCheck to tsconfig to resolve vitest/vite type conflicts
- Add pnpm.onlyBuiltDependencies to allow esbuild native build scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant