better-cf 0.1.0

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 ADDED
@@ -0,0 +1,172 @@
1
+ # better-cf
2
+
3
+ Type-safe Cloudflare Queue SDK + CLI.
4
+
5
+ `better-cf` removes queue binding boilerplate by scanning `defineQueue` exports, generating `.better-cf/entry.ts`, and patching Wrangler queue config.
6
+
7
+ ## Why better-cf
8
+
9
+ Cloudflare Queues are great, but setup usually repeats:
10
+
11
+ - Manual queue binding names.
12
+ - Manual `wrangler.toml` or `wrangler.jsonc` queue blocks.
13
+ - Manual worker queue consumer plumbing.
14
+
15
+ `better-cf` keeps queue code in plain functions and auto-generates runtime wiring.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm i better-cf zod
21
+ npm i -D wrangler @cloudflare/workers-types typescript
22
+ ```
23
+
24
+ ## Quickstart
25
+
26
+ ```bash
27
+ npx better-cf init
28
+ ```
29
+
30
+ Create queue:
31
+
32
+ ```ts
33
+ import { z } from 'zod';
34
+ import { defineQueue } from './better-cf.config';
35
+
36
+ export const signupQueue = defineQueue({
37
+ message: z.object({ email: z.string().email(), userId: z.string() }),
38
+ process: async (ctx, msg) => {
39
+ await fetch('https://example.com', {
40
+ method: 'POST',
41
+ body: JSON.stringify(msg)
42
+ });
43
+ },
44
+ retry: 3
45
+ });
46
+ ```
47
+
48
+ Run dev:
49
+
50
+ ```bash
51
+ npm run dev
52
+ ```
53
+
54
+ Deploy:
55
+
56
+ ```bash
57
+ npm run deploy
58
+ ```
59
+
60
+ ## Canonical Imports
61
+
62
+ - Queue SDK: `better-cf/queue`
63
+ - Testing helpers: `better-cf/testing`
64
+
65
+ ## Type Safety Guarantees
66
+
67
+ `createSDK<Env>()` propagates `Env` types into `ctx.env` for queue and worker handlers.
68
+
69
+ ```ts
70
+ import { createSDK } from 'better-cf/queue';
71
+
72
+ type Env = {
73
+ DB: D1Database;
74
+ EMAIL_QUEUE: Queue;
75
+ };
76
+
77
+ export const { defineQueue } = createSDK<Env>();
78
+ ```
79
+
80
+ Payload types are inferred from Zod schemas for `send`, `sendBatch`, `process`, and multi-job queue APIs.
81
+
82
+ ## Hono Example
83
+
84
+ `better-cf` supports Hono default exports.
85
+
86
+ ```ts
87
+ import { Hono } from 'hono';
88
+
89
+ const app = new Hono();
90
+ app.get('/', (ctx) => ctx.text('ok'));
91
+
92
+ export default app;
93
+ ```
94
+
95
+ The generated `.better-cf/entry.ts` resolves fetch handlers for object/function/named exports.
96
+
97
+ ## Legacy Cloudflare Compatibility (Service Worker Adapter)
98
+
99
+ Set compatibility mode in `better-cf.config.ts`:
100
+
101
+ ```ts
102
+ export const betterCfConfig = {
103
+ legacyServiceWorker: true
104
+ };
105
+ ```
106
+
107
+ This mode is adapter-only and not feature-parity guaranteed with module worker patterns.
108
+
109
+ ## CLI Commands
110
+
111
+ - `better-cf init`: scaffold config, worker, scripts.
112
+ - `better-cf generate`: scan + generate `.better-cf/*` + patch Wrangler config.
113
+ - `better-cf dev`: generate + watch + run `wrangler dev` (local only for queues).
114
+ - `better-cf deploy`: generate + run `wrangler deploy`.
115
+
116
+ ## Queue Config Mapping
117
+
118
+ | better-cf | Wrangler |
119
+ |---|---|
120
+ | `retry` | `max_retries` |
121
+ | `retryDelay` | `retry_delay` |
122
+ | `deadLetter` | `dead_letter_queue` |
123
+ | `batch.maxSize` | `max_batch_size` |
124
+ | `batch.timeout` | `max_batch_timeout` |
125
+ | `batch.maxConcurrency` | `max_concurrency` |
126
+
127
+ ## Local Dev Constraints
128
+
129
+ Cloudflare queue local development does not support `wrangler dev --remote` for queue consumers. `better-cf dev --remote` is blocked intentionally.
130
+
131
+ ## Testing Queues
132
+
133
+ Use `better-cf/testing`:
134
+
135
+ ```ts
136
+ import { testQueue } from 'better-cf/testing';
137
+
138
+ const result = await testQueue(queueHandle, {
139
+ env: mockEnv,
140
+ message: { id: '1' }
141
+ });
142
+ ```
143
+
144
+ ## Compatibility Matrix
145
+
146
+ - Wrangler: `>=3.91.0 <5`
147
+ - Node: `>=18.18`
148
+ - Config formats: `wrangler.toml`, `wrangler.json`, `wrangler.jsonc`
149
+ - Runtime styles: module worker (first-class), service-worker adapter (compatibility mode)
150
+ - Frameworks: Workers + Hono
151
+
152
+ ## Not Supported (v1)
153
+
154
+ - Pull consumers / HTTP pull consumers.
155
+ - Queue create/delete lifecycle outside deploy workflow.
156
+ - Queue metrics dashboard/API abstraction.
157
+ - Runtime dynamic queue registration.
158
+ - Remote queue local-dev parity for unsupported Cloudflare modes.
159
+
160
+ ## Known Gaps
161
+
162
+ - Non-literal config expressions reduce static wrangler extraction quality.
163
+ - Legacy adapter mode may not match every service-worker edge case.
164
+ - Non-standard worker export patterns beyond documented variants are out of scope.
165
+ - Monorepo autodetection is basic; explicit `workerEntry` may be needed.
166
+
167
+ ## Roadmap
168
+
169
+ Planned future namespaces:
170
+
171
+ - `better-cf/workflow`
172
+ - `better-cf/durable-object`
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from '../dist/cli/index.js';
3
+
4
+ run(process.argv.slice(2));
@@ -0,0 +1,3 @@
1
+ declare function run(argv?: string[]): Promise<void>;
2
+
3
+ export { run };