Skip to content

PR 2: Hono Ecosystem Integrations (Vitest + Queue + Durable Objects + Prisma Context + RPC Authenticated Client) #1242

@jaypatrick

Description

@jaypatrick

PR 2: Hono Ecosystem Integrations (Vitest + Queue + Durable Objects + Prisma Context + RPC Authenticated Client)

Overview

A set of Hono ecosystem improvements discussed and planned. Each item is independent but grouped here for efficiency. Implement all items below.

  1. Cloudflare Vitest Worker Testing (@cloudflare/vitest-pool-workers)

Reference: https://hono.dev/examples/cloudflare-vitest

• Add @cloudflare/vitest-pool-workers to the project

• Create vitest.worker.config.ts using defineWorkersConfig pointing at wrangler.toml

• Migrate worker/ integration tests that touch Cloudflare bindings (KV, D1, Queue, R2) from manual stubs in worker/test-helpers.ts to real binding stubs via the Workers runtime

• Keep Deno test runner for src/ pure unit tests

• Document in docs/development/testing.md — when to use Deno tests vs. Vitest Worker tests

  1. Prisma into Hono Context

Reference: https://hono.dev/examples/prisma

• Add prisma to AppVars interface in worker/middleware/hono-middleware.ts

• In the global middleware in worker/hono-app.ts, set c.set('prisma', createPrisma(env)) so route handlers get it via c.get('prisma') rather than instantiating per-handler

• Update existing route handlers that currently call createPrisma(env) directly to use c.get('prisma')

  1. Cloudflare Queue Handler under Hono Routing

Reference: https://hono.dev/examples/cloudflare-queue

• Mount queue handling as a Hono route so async compilation handlers get the same middleware pipeline (auth, tracing, timing, Zod validation) as HTTP handlers

• Update worker/handlers/queue.ts to integrate with the Hono router

• Ensures POST /api/compile/async and batch queue handlers go through requireAuthMiddleware() and c.get('authContext') consistently

  1. Durable Objects with Hono Routing

Reference: https://hono.dev/examples/cloudflare-durable-objects

• Wire Hono routing inside the existing Durable Object fetch() handlers

• Allows DO handlers to use the same Hono middleware factories (requireAuthMiddleware(), turnstileMiddleware(), timing, etc.) as the main worker

• Start with the ADBLOCK_COMPILER DO binding

  1. Hono RPC Authenticated Client (AuthedApiClientService)

Context: Follows from the Better Auth migration in PR 1. Build after PR 1 is merged so token acquisition is against stable Better Auth tokens.

• Create frontend/src/app/services/authed-api-client.service.ts

• Injects AuthFacadeService and LogService

• getHeaders() private method: resolves Bearer token + X-Trace-ID

• Typed wrapper methods for each authenticated endpoint (e.g. compile(), validateRule(), listRules()) that call this.rpc.client.api.[endpoint] with headers injected

• Expand AppType in frontend/src/app/services/api-client.ts to include authenticated routes (POST /api/compile, POST /api/validate-rule, GET /api/rules, etc.)

• Add unit tests for AuthedApiClientService — token attachment, missing token, trace ID injection

Documentation Required

• docs/development/testing.md — Vitest Worker vs. Deno test guidance

• docs/architecture/hono-rpc-client.md — update to cover authenticated endpoints via AuthedApiClientService

• docs/architecture/hono-routing.md — update to cover Queue and DO Hono integration

• Inline JSDoc on all new services and middleware

Metadata

Metadata

Labels

cloudflareCloudflare Workers / CDNenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions