@rdlabo/workers-hono-kit 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/db/connection.d.ts +2 -10
- package/dist/http/execution-context.d.ts +11 -0
- package/dist/http/execution-context.js +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/db/connection.ts +3 -11
- package/src/http/execution-context.ts +11 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -66,12 +66,16 @@ npm install ai ai-gateway-provider # createAiGatewayProvider
|
|
|
66
66
|
| `HttpStatus` | HTTP status enum identical to NestJS `@nestjs/common`. |
|
|
67
67
|
| `createNestErrorHandler(options?)` / `NestErrorHandlerOptions` | `app.onError()` handler that maps a thrown `HTTPException` to the NestJS exception-filter body (`{ statusCode, message, error? }`; `401` omits `error`). Configurable field order, reason phrases, error predicate, and unhandled-error report hook. |
|
|
68
68
|
| `nestNotFoundHandler(c)` | `app.notFound()` handler with the Express/Nest default `{ message: 'Cannot METHOD path', error, statusCode }` 404 body. |
|
|
69
|
+
| `normalizeTrailingSlash(request)` | Strip trailing slash(es) from the request URL before routing (Express/Nest parity). Does **not** 301-redirect — preserves POST/PUT/DELETE bodies. |
|
|
69
70
|
| `NEST_REASON_PHRASES` | `{ 400, 401, 403, 404 }` → NestJS reason phrases. |
|
|
70
71
|
| `createAuthMiddleware(options)` / `AuthMiddlewareOptions` | Factory for a Firebase-token auth middleware: reads the token header, verifies, resolves the DB user id, and stashes the result on the context. Omit `resolveUserId` for a token-only (login) guard. |
|
|
71
72
|
| `ErrorReporter` / `ErrorReportContext` | Types for a `reportError`-style unhandled-error reporter (e.g. wired to Sentry), paired with `createNestErrorHandler`'s `onUnhandledError`. |
|
|
72
73
|
| `createAiGatewayProvider(config)` / `AiGatewayConfig` / `AiGatewayProvider` | Route `@ai-sdk` models through the Cloudflare AI Gateway, via either a Workers `AI` binding or REST credentials (`accountId` / `gateway` / `token`). |
|
|
73
74
|
| `KVCache` / `KVNamespace` / `KVCacheOptions` | Workers-KV cache-aside helper (key `appName+version+table_type_column`, sha256 for string ids, TTL clamped ≥60s). Set `appName` / `version` per application. |
|
|
74
75
|
| `createStripeClient(secret, opts?)` / `verifyStripeWebhook(...)` / `CreateStripeClientOptions` | Workers-native Stripe client (fetch transport) + async webhook verification (SubtleCrypto). `apiVersion` optional (pin to a fixed Stripe API version). |
|
|
76
|
+
| `sendInChunks(queue, messages, chunkSize?)` / `QueueLike` / `QueueSendMessage` | Send queue messages in bounded chunks to stay under the Workers subrequest cap per invocation. |
|
|
77
|
+
| `processBatch(batch, handler, options?)` / `MessageBatchLike` / `QueueMessageLike` / `ProcessBatchOptions` / `ProcessBatchResult` | Process a queue batch with bounded concurrency (consumer-side counterpart to `sendInChunks`). |
|
|
78
|
+
| `ExecutionContextLike` | Minimal `waitUntil`-only Workers execution context shape (for `withMysqlConnections` in worker entry modules without importing `./db`). |
|
|
75
79
|
|
|
76
80
|
### Data layer — `@rdlabo/workers-hono-kit/db`
|
|
77
81
|
|
|
@@ -81,6 +85,7 @@ Requires the `drizzle-orm` and `mysql2` peers. Reads run against a replica via r
|
|
|
81
85
|
| --- | --- |
|
|
82
86
|
| `createHyperdriveDatabase(options)` | `DisposableDatabase` that lazily opens primary/replica connections from Hyperdrive bindings per request; `dispose()` closes them. |
|
|
83
87
|
| `createMysqlDatabase(options)` | Assemble a `Database` from an already-connected Drizzle ORM + replica `QueryRunner`. |
|
|
88
|
+
| `databaseFrom(orm, replica)` | Build a `Database` from an existing Drizzle instance + replica handle. |
|
|
84
89
|
| `Database` / `DisposableDatabase` / `QueryRunner` / `TxOf` | The `read` / `write` / `transaction` API and its supporting types. |
|
|
85
90
|
| `hyperdriveConnectionOptions(hyperdrive, overrides?)` / `HyperdriveLike` / `ExecutionContextLike` | Build mysql2 `createConnection` options from a Hyperdrive binding (`disableEval`, `decimalNumbers`, `timezone '+09:00'` by default). |
|
|
86
91
|
| `withMysqlConnections(...)` | Open primary/replica connections, run a function, close them in `finally` (via `ctx.waitUntil`). |
|
|
@@ -88,6 +93,8 @@ Requires the `drizzle-orm` and `mysql2` peers. Reads run against a replica via r
|
|
|
88
93
|
| `insertIdOf` / `affectedRowsOf` / `insertedIdsOf` / `DzWriteResult` | Extract `insertId` / `affectedRows` (and derive contiguous bulk-insert ids) from a mysql2 write result. |
|
|
89
94
|
| `toJstDate` / `jstTimestampParams` / `jstDatetimeParams` / `jstDateParams` | JST date/time normalization applied at the Drizzle `customType` column boundary. |
|
|
90
95
|
| `DRIZZLE_ORM_OPTIONS` / `honoDrizzleConfig(options)` / `HonoDrizzleConfigOptions` | Shared Drizzle casing (`snake_case`) for both the runtime `drizzle()` call and `drizzle.config.ts`, keeping config ↔ runtime in sync. |
|
|
96
|
+
| `resolveDbSecret(options, secretId?)` / `ResolvedDbSecret` | Resolve RDS-managed or plain DB credentials from AWS Secrets Manager for CI migrate / local tooling. |
|
|
97
|
+
| `baselineMigrations(options)` / `readBaselineEntry(migrationsFolder)` / `BaselineMigrationsOptions` / `BaselineResult` / `BaselineEntry` | Brownfield first-deploy helper: mark an existing `0000_*` migration as applied without re-running DDL. |
|
|
91
98
|
|
|
92
99
|
### Testing — `@rdlabo/workers-hono-kit/testing`
|
|
93
100
|
|
package/dist/db/connection.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Connection } from 'mysql2/promise';
|
|
2
|
+
import type { ExecutionContextLike } from '../http/execution-context.js';
|
|
3
|
+
export type { ExecutionContextLike } from '../http/execution-context.js';
|
|
2
4
|
/**
|
|
3
5
|
* Minimal structural shape of a Cloudflare Hyperdrive binding.
|
|
4
6
|
*
|
|
@@ -40,16 +42,6 @@ export interface HyperdriveLike {
|
|
|
40
42
|
* @returns a plain options object to pass to mysql2 `createConnection`.
|
|
41
43
|
*/
|
|
42
44
|
export declare function hyperdriveConnectionOptions(hyperdrive: HyperdriveLike, extra?: Record<string, unknown>): Record<string, unknown>;
|
|
43
|
-
/**
|
|
44
|
-
* Minimal structural shape of a Workers `ExecutionContext`, limited to `waitUntil`.
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* Declared structurally to avoid a dependency on `@cloudflare/workers-types`.
|
|
48
|
-
*/
|
|
49
|
-
export interface ExecutionContextLike {
|
|
50
|
-
/** Extend the request's lifetime until `promise` settles (used to close connections after the response). */
|
|
51
|
-
waitUntil(promise: Promise<unknown>): void;
|
|
52
|
-
}
|
|
53
45
|
/**
|
|
54
46
|
* Open primary and replica connections, run `fn` with them, and close both afterwards.
|
|
55
47
|
*
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal structural shape of a Workers `ExecutionContext`, limited to `waitUntil`.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Declared structurally to avoid a dependency on `@cloudflare/workers-types`.
|
|
6
|
+
* Lives in the root export path so worker entry modules can import it without pulling in `./db`.
|
|
7
|
+
*/
|
|
8
|
+
export interface ExecutionContextLike {
|
|
9
|
+
/** Extend the request's lifetime until `promise` settles (used to close connections after the response). */
|
|
10
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export { HttpStatus } from './http/http-status.js';
|
|
|
25
25
|
export { createNestErrorHandler, nestNotFoundHandler, NEST_REASON_PHRASES } from './http/nest-error.js';
|
|
26
26
|
export type { NestErrorHandlerOptions, ErrorReportContext, ErrorReporter } from './http/nest-error.js';
|
|
27
27
|
export { normalizeTrailingSlash } from './http/trailing-slash.js';
|
|
28
|
+
export type { ExecutionContextLike } from './http/execution-context.js';
|
|
28
29
|
export { KVCache } from './cache/kv-cache.js';
|
|
29
30
|
export type { KVNamespace, KVCacheOptions } from './cache/kv-cache.js';
|
|
30
31
|
export { createStripeClient, verifyStripeWebhook } from './stripe/client.js';
|
package/package.json
CHANGED
package/src/db/connection.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createConnection } from 'mysql2/promise';
|
|
2
2
|
import type { Connection } from 'mysql2/promise';
|
|
3
|
+
import type { ExecutionContextLike } from '../http/execution-context.js';
|
|
4
|
+
|
|
5
|
+
export type { ExecutionContextLike } from '../http/execution-context.js';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Minimal structural shape of a Cloudflare Hyperdrive binding.
|
|
@@ -59,17 +62,6 @@ export function hyperdriveConnectionOptions(
|
|
|
59
62
|
};
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
/**
|
|
63
|
-
* Minimal structural shape of a Workers `ExecutionContext`, limited to `waitUntil`.
|
|
64
|
-
*
|
|
65
|
-
* @remarks
|
|
66
|
-
* Declared structurally to avoid a dependency on `@cloudflare/workers-types`.
|
|
67
|
-
*/
|
|
68
|
-
export interface ExecutionContextLike {
|
|
69
|
-
/** Extend the request's lifetime until `promise` settles (used to close connections after the response). */
|
|
70
|
-
waitUntil(promise: Promise<unknown>): void;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
65
|
/**
|
|
74
66
|
* Open primary and replica connections, run `fn` with them, and close both afterwards.
|
|
75
67
|
*
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal structural shape of a Workers `ExecutionContext`, limited to `waitUntil`.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Declared structurally to avoid a dependency on `@cloudflare/workers-types`.
|
|
6
|
+
* Lives in the root export path so worker entry modules can import it without pulling in `./db`.
|
|
7
|
+
*/
|
|
8
|
+
export interface ExecutionContextLike {
|
|
9
|
+
/** Extend the request's lifetime until `promise` settles (used to close connections after the response). */
|
|
10
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
11
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ export { HttpStatus } from './http/http-status.js';
|
|
|
35
35
|
export { createNestErrorHandler, nestNotFoundHandler, NEST_REASON_PHRASES } from './http/nest-error.js';
|
|
36
36
|
export type { NestErrorHandlerOptions, ErrorReportContext, ErrorReporter } from './http/nest-error.js';
|
|
37
37
|
export { normalizeTrailingSlash } from './http/trailing-slash.js';
|
|
38
|
+
export type { ExecutionContextLike } from './http/execution-context.js';
|
|
38
39
|
|
|
39
40
|
// cache
|
|
40
41
|
export { KVCache } from './cache/kv-cache.js';
|