pi-cloudflare 0.10.1 → 0.11.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 +78 -177
- package/package.json +7 -42
- package/plugin.json +3 -3
- package/skills/agents-sdk/SKILL.md +17 -36
- package/skills/agents-sdk/references/client-sdk.md +7 -106
- package/skills/agents-sdk/references/human-in-the-loop.md +6 -63
- package/skills/agents-sdk/references/mcp.md +9 -184
- package/skills/agents-sdk/references/queue-retries.md +12 -73
- package/skills/agents-sdk/references/server-driven-messages.md +4 -60
- package/skills/agents-sdk/references/state-scheduling.md +10 -166
- package/skills/agents-sdk/references/streaming-chat.md +11 -193
- package/skills/agents-sdk/references/webhooks-push.md +2 -2
- package/skills/agents-sdk/references/workflows.md +14 -125
- package/skills/cloudflare/SKILL.md +135 -248
- package/skills/cloudflare/references/ai-gateway/README.md +17 -165
- package/skills/cloudflare/references/ai-gateway/configuration.md +14 -107
- package/skills/cloudflare/references/ai-gateway/dynamic-routing.md +12 -79
- package/skills/cloudflare/references/ai-gateway/features.md +22 -96
- package/skills/cloudflare/references/ai-gateway/sdk-integration.md +17 -112
- package/skills/cloudflare/references/ai-gateway/troubleshooting.md +14 -86
- package/skills/cloudflare/references/ai-search/README.md +17 -130
- package/skills/cloudflare/references/ai-search/api.md +10 -84
- package/skills/cloudflare/references/ai-search/configuration.md +16 -88
- package/skills/cloudflare/references/ai-search/gotchas.md +13 -81
- package/skills/cloudflare/references/ai-search/patterns.md +12 -82
- package/skills/cloudflare/references/analytics-engine/api.md +1 -1
- package/skills/cloudflare/references/api/README.md +2 -2
- package/skills/cloudflare/references/api/configuration.md +1 -1
- package/skills/cloudflare/references/bindings/README.md +11 -117
- package/skills/cloudflare/references/bindings/api.md +17 -201
- package/skills/cloudflare/references/bindings/configuration.md +20 -188
- package/skills/cloudflare/references/bindings/gotchas.md +16 -206
- package/skills/cloudflare/references/bindings/patterns.md +15 -195
- package/skills/cloudflare/references/bot-management/README.md +1 -1
- package/skills/cloudflare/references/browser-rendering/README.md +13 -73
- package/skills/cloudflare/references/browser-rendering/api.md +9 -105
- package/skills/cloudflare/references/browser-rendering/configuration.md +9 -75
- package/skills/cloudflare/references/browser-rendering/gotchas.md +12 -85
- package/skills/cloudflare/references/browser-rendering/patterns.md +9 -88
- package/skills/cloudflare/references/c3/README.md +6 -5
- package/skills/cloudflare/references/c3/api.md +3 -4
- package/skills/cloudflare/references/c3/patterns.md +4 -6
- package/skills/cloudflare/references/cache-reserve/README.md +1 -1
- package/skills/cloudflare/references/containers/README.md +15 -77
- package/skills/cloudflare/references/containers/api.md +13 -187
- package/skills/cloudflare/references/containers/configuration.md +15 -188
- package/skills/cloudflare/references/containers/gotchas.md +16 -178
- package/skills/cloudflare/references/containers/patterns.md +14 -198
- package/skills/cloudflare/references/cron-triggers/README.md +13 -92
- package/skills/cloudflare/references/cron-triggers/api.md +11 -191
- package/skills/cloudflare/references/cron-triggers/configuration.md +11 -175
- package/skills/cloudflare/references/cron-triggers/gotchas.md +13 -195
- package/skills/cloudflare/references/cron-triggers/patterns.md +12 -184
- package/skills/cloudflare/references/d1/README.md +9 -127
- package/skills/cloudflare/references/d1/api.md +16 -194
- package/skills/cloudflare/references/d1/configuration.md +16 -189
- package/skills/cloudflare/references/d1/gotchas.md +16 -96
- package/skills/cloudflare/references/d1/patterns.md +14 -183
- package/skills/cloudflare/references/do-storage/README.md +11 -70
- package/skills/cloudflare/references/do-storage/api.md +11 -99
- package/skills/cloudflare/references/do-storage/configuration.md +11 -107
- package/skills/cloudflare/references/do-storage/gotchas.md +12 -147
- package/skills/cloudflare/references/do-storage/patterns.md +11 -190
- package/skills/cloudflare/references/do-storage/testing.md +8 -178
- package/skills/cloudflare/references/email-routing/README.md +14 -84
- package/skills/cloudflare/references/email-routing/api.md +10 -192
- package/skills/cloudflare/references/email-routing/configuration.md +13 -186
- package/skills/cloudflare/references/email-routing/gotchas.md +12 -193
- package/skills/cloudflare/references/email-routing/patterns.md +10 -226
- package/skills/cloudflare/references/email-workers/README.md +13 -146
- package/skills/cloudflare/references/email-workers/api.md +12 -234
- package/skills/cloudflare/references/email-workers/configuration.md +14 -110
- package/skills/cloudflare/references/email-workers/gotchas.md +15 -125
- package/skills/cloudflare/references/email-workers/patterns.md +14 -100
- package/skills/cloudflare/references/flagship/README.md +2 -2
- package/skills/cloudflare/references/hyperdrive/README.md +17 -72
- package/skills/cloudflare/references/hyperdrive/api.md +19 -136
- package/skills/cloudflare/references/hyperdrive/configuration.md +27 -159
- package/skills/cloudflare/references/hyperdrive/gotchas.md +15 -72
- package/skills/cloudflare/references/hyperdrive/patterns.md +12 -187
- package/skills/cloudflare/references/images/README.md +9 -58
- package/skills/cloudflare/references/images/api.md +13 -96
- package/skills/cloudflare/references/images/configuration.md +17 -211
- package/skills/cloudflare/references/images/gotchas.md +16 -99
- package/skills/cloudflare/references/images/patterns.md +16 -115
- package/skills/cloudflare/references/kv/README.md +9 -83
- package/skills/cloudflare/references/kv/api.md +12 -154
- package/skills/cloudflare/references/kv/configuration.md +11 -139
- package/skills/cloudflare/references/kv/gotchas.md +15 -129
- package/skills/cloudflare/references/kv/patterns.md +15 -190
- package/skills/cloudflare/references/miniflare/README.md +15 -98
- package/skills/cloudflare/references/miniflare/api.md +16 -187
- package/skills/cloudflare/references/miniflare/configuration.md +12 -169
- package/skills/cloudflare/references/miniflare/gotchas.md +15 -160
- package/skills/cloudflare/references/miniflare/patterns.md +15 -177
- package/skills/cloudflare/references/network-interconnect/README.md +1 -1
- package/skills/cloudflare/references/network-interconnect/gotchas.md +1 -1
- package/skills/cloudflare/references/network-interconnect/patterns.md +1 -1
- package/skills/cloudflare/references/observability/README.md +20 -81
- package/skills/cloudflare/references/observability/api.md +20 -164
- package/skills/cloudflare/references/observability/configuration.md +18 -164
- package/skills/cloudflare/references/observability/gotchas.md +19 -109
- package/skills/cloudflare/references/observability/patterns.md +12 -103
- package/skills/cloudflare/references/pages/README.md +13 -81
- package/skills/cloudflare/references/pages/api.md +10 -201
- package/skills/cloudflare/references/pages/configuration.md +16 -201
- package/skills/cloudflare/references/pages/gotchas.md +13 -197
- package/skills/cloudflare/references/pages/patterns.md +11 -200
- package/skills/cloudflare/references/pages-functions/README.md +13 -91
- package/skills/cloudflare/references/pages-functions/api.md +10 -140
- package/skills/cloudflare/references/pages-functions/configuration.md +11 -119
- package/skills/cloudflare/references/pages-functions/gotchas.md +17 -94
- package/skills/cloudflare/references/pages-functions/patterns.md +12 -133
- package/skills/cloudflare/references/pipelines/README.md +1 -1
- package/skills/cloudflare/references/pulumi/README.md +2 -2
- package/skills/cloudflare/references/queues/README.md +15 -87
- package/skills/cloudflare/references/queues/api.md +10 -200
- package/skills/cloudflare/references/queues/configuration.md +18 -142
- package/skills/cloudflare/references/queues/gotchas.md +16 -204
- package/skills/cloudflare/references/queues/patterns.md +19 -218
- package/skills/cloudflare/references/r2/README.md +17 -86
- package/skills/cloudflare/references/r2/api.md +14 -198
- package/skills/cloudflare/references/r2/configuration.md +17 -163
- package/skills/cloudflare/references/r2/gotchas.md +15 -188
- package/skills/cloudflare/references/r2/patterns.md +16 -191
- package/skills/cloudflare/references/r2-data-catalog/README.md +11 -70
- package/skills/cloudflare/references/r2-data-catalog/api.md +14 -89
- package/skills/cloudflare/references/r2-data-catalog/configuration.md +15 -96
- package/skills/cloudflare/references/r2-data-catalog/gotchas.md +14 -51
- package/skills/cloudflare/references/r2-data-catalog/patterns.md +11 -116
- package/skills/cloudflare/references/realtime-sfu/README.md +1 -1
- package/skills/cloudflare/references/realtimekit/README.md +1 -1
- package/skills/cloudflare/references/secrets-store/README.md +14 -66
- package/skills/cloudflare/references/secrets-store/api.md +14 -193
- package/skills/cloudflare/references/secrets-store/configuration.md +16 -176
- package/skills/cloudflare/references/secrets-store/gotchas.md +14 -92
- package/skills/cloudflare/references/secrets-store/patterns.md +14 -194
- package/skills/cloudflare/references/smart-placement/README.md +2 -2
- package/skills/cloudflare/references/static-assets/README.md +15 -59
- package/skills/cloudflare/references/static-assets/api.md +12 -195
- package/skills/cloudflare/references/static-assets/configuration.md +16 -186
- package/skills/cloudflare/references/static-assets/gotchas.md +18 -162
- package/skills/cloudflare/references/static-assets/patterns.md +13 -185
- package/skills/cloudflare/references/stream/README.md +15 -107
- package/skills/cloudflare/references/stream/api-live.md +16 -193
- package/skills/cloudflare/references/stream/api.md +19 -197
- package/skills/cloudflare/references/stream/configuration.md +16 -139
- package/skills/cloudflare/references/stream/gotchas.md +16 -128
- package/skills/cloudflare/references/stream/patterns.md +20 -182
- package/skills/cloudflare/references/tail-workers/README.md +14 -82
- package/skills/cloudflare/references/tail-workers/api.md +10 -197
- package/skills/cloudflare/references/tail-workers/configuration.md +13 -174
- package/skills/cloudflare/references/tail-workers/gotchas.md +12 -188
- package/skills/cloudflare/references/tail-workers/patterns.md +11 -176
- package/skills/cloudflare/references/terraform/README.md +2 -2
- package/skills/cloudflare/references/tunnel/README.md +13 -122
- package/skills/cloudflare/references/tunnel/api.md +11 -190
- package/skills/cloudflare/references/tunnel/configuration.md +12 -155
- package/skills/cloudflare/references/tunnel/gotchas.md +12 -144
- package/skills/cloudflare/references/tunnel/networking.md +12 -166
- package/skills/cloudflare/references/tunnel/patterns.md +12 -189
- package/skills/cloudflare/references/vectorize/README.md +15 -126
- package/skills/cloudflare/references/vectorize/api.md +14 -84
- package/skills/cloudflare/references/vectorize/configuration.md +14 -83
- package/skills/cloudflare/references/vectorize/gotchas.md +12 -73
- package/skills/cloudflare/references/vectorize/patterns.md +17 -83
- package/skills/cloudflare/references/waf/README.md +15 -107
- package/skills/cloudflare/references/waf/api.md +17 -202
- package/skills/cloudflare/references/waf/configuration.md +14 -199
- package/skills/cloudflare/references/waf/gotchas.md +15 -200
- package/skills/cloudflare/references/waf/patterns.md +13 -193
- package/skills/cloudflare/references/workerd/README.md +2 -2
- package/skills/cloudflare/references/workers-ai/README.md +14 -187
- package/skills/cloudflare/references/workers-ai/api.md +10 -109
- package/skills/cloudflare/references/workers-ai/configuration.md +11 -92
- package/skills/cloudflare/references/workers-ai/gotchas.md +12 -111
- package/skills/cloudflare/references/workers-ai/patterns.md +9 -115
- package/skills/cloudflare/references/workers-for-platforms/README.md +3 -3
- package/skills/cloudflare/references/workers-vpc/README.md +1 -1
- package/skills/cloudflare/references/workflows/README.md +15 -69
- package/skills/cloudflare/references/workflows/api.md +12 -213
- package/skills/cloudflare/references/workflows/configuration.md +16 -150
- package/skills/cloudflare/references/workflows/gotchas.md +17 -88
- package/skills/cloudflare/references/workflows/patterns.md +19 -164
- package/skills/cloudflare-api-token/SKILL.md +1 -1
- package/skills/cloudflare-cf-cli/SKILL.md +44 -13
- package/skills/cloudflare-email-service/SKILL.md +6 -36
- package/skills/cloudflare-email-service/references/rest-api.md +12 -179
- package/skills/cloudflare-email-service/references/sending.md +17 -250
- package/skills/cloudflare-one/SKILL.md +4 -2
- package/skills/cloudflare-one-migrations/SKILL.md +1 -1
- package/skills/cloudflare-token-roll/SKILL.md +2 -5
- package/skills/durable-objects/SKILL.md +10 -16
- package/skills/durable-objects/references/rules.md +17 -293
- package/skills/durable-objects/references/testing.md +16 -257
- package/skills/nextjs-on-cloudflare/SKILL.md +33 -0
- package/skills/sandbox-migrate-to-next/SKILL.md +2 -2
- package/skills/sandbox-next/SKILL.md +3 -2
- package/skills/sandbox-next/references/api-quick-ref.md +15 -90
- package/skills/sandbox-stable/SKILL.md +1 -1
- package/skills/turnstile-spin/SKILL.md +14 -8
- package/skills/workers-best-practices/SKILL.md +36 -103
- package/skills/workers-best-practices/references/configuration.md +139 -0
- package/skills/workers-best-practices/references/platform-apis.md +51 -0
- package/skills/workers-best-practices/references/{rules.md → runtime-patterns.md} +9 -134
- package/skills/wrangler/SKILL.md +48 -901
- package/bin/setup.mjs +0 -119
- package/dist/api-token.d.ts +0 -12
- package/dist/api-token.d.ts.map +0 -1
- package/dist/api-token.js +0 -23
- package/dist/api-token.js.map +0 -1
- package/dist/auth-flow.d.ts +0 -15
- package/dist/auth-flow.d.ts.map +0 -1
- package/dist/auth-flow.js +0 -90
- package/dist/auth-flow.js.map +0 -1
- package/dist/client.d.ts +0 -18
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -47
- package/dist/client.js.map +0 -1
- package/dist/config.d.ts +0 -20
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -10
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -22
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -65
- package/dist/index.js.map +0 -1
- package/dist/mcp-server.d.ts +0 -2
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js +0 -106
- package/dist/mcp-server.js.map +0 -1
- package/dist/oauth.d.ts +0 -44
- package/dist/oauth.d.ts.map +0 -1
- package/dist/oauth.js +0 -135
- package/dist/oauth.js.map +0 -1
- package/dist/proxy.d.ts +0 -30
- package/dist/proxy.d.ts.map +0 -1
- package/dist/proxy.js +0 -41
- package/dist/proxy.js.map +0 -1
- package/dist/result-caps.d.ts +0 -23
- package/dist/result-caps.d.ts.map +0 -1
- package/dist/result-caps.js +0 -75
- package/dist/result-caps.js.map +0 -1
- package/dist/runtime.d.ts +0 -72
- package/dist/runtime.d.ts.map +0 -1
- package/dist/runtime.js +0 -249
- package/dist/runtime.js.map +0 -1
- package/dist/servers.d.ts +0 -19
- package/dist/servers.d.ts.map +0 -1
- package/dist/servers.js +0 -40
- package/dist/servers.js.map +0 -1
- package/dist/token-store.d.ts +0 -32
- package/dist/token-store.d.ts.map +0 -1
- package/dist/token-store.js +0 -61
- package/dist/token-store.js.map +0 -1
- package/dist/tool-cache.d.ts +0 -25
- package/dist/tool-cache.d.ts.map +0 -1
- package/dist/tool-cache.js +0 -43
- package/dist/tool-cache.js.map +0 -1
- package/mcp.json +0 -15
- package/skills/cloudflare/references/agents-sdk/README.md +0 -89
- package/skills/cloudflare/references/agents-sdk/api.md +0 -190
- package/skills/cloudflare/references/agents-sdk/configuration.md +0 -182
- package/skills/cloudflare/references/agents-sdk/gotchas.md +0 -158
- package/skills/cloudflare/references/agents-sdk/patterns.md +0 -192
- package/skills/cloudflare/references/durable-objects/README.md +0 -185
- package/skills/cloudflare/references/durable-objects/api.md +0 -187
- package/skills/cloudflare/references/durable-objects/configuration.md +0 -160
- package/skills/cloudflare/references/durable-objects/gotchas.md +0 -197
- package/skills/cloudflare/references/durable-objects/patterns.md +0 -201
- package/skills/cloudflare/references/sandbox/README.md +0 -96
- package/skills/cloudflare/references/sandbox/api.md +0 -198
- package/skills/cloudflare/references/sandbox/configuration.md +0 -143
- package/skills/cloudflare/references/sandbox/gotchas.md +0 -194
- package/skills/cloudflare/references/sandbox/patterns.md +0 -201
- package/skills/cloudflare/references/turnstile/README.md +0 -99
- package/skills/cloudflare/references/turnstile/api.md +0 -240
- package/skills/cloudflare/references/turnstile/configuration.md +0 -222
- package/skills/cloudflare/references/turnstile/gotchas.md +0 -218
- package/skills/cloudflare/references/turnstile/patterns.md +0 -193
- package/skills/cloudflare/references/workers/README.md +0 -108
- package/skills/cloudflare/references/workers/api.md +0 -195
- package/skills/cloudflare/references/workers/configuration.md +0 -185
- package/skills/cloudflare/references/workers/frameworks.md +0 -197
- package/skills/cloudflare/references/workers/gotchas.md +0 -137
- package/skills/cloudflare/references/workers/patterns.md +0 -198
- package/skills/cloudflare/references/wrangler/README.md +0 -135
- package/skills/cloudflare/references/wrangler/api.md +0 -188
- package/skills/cloudflare/references/wrangler/configuration.md +0 -197
- package/skills/cloudflare/references/wrangler/gotchas.md +0 -197
- package/skills/cloudflare/references/wrangler/patterns.md +0 -209
- package/skills/cloudflare-auth-setup/SKILL.md +0 -59
- package/skills/workers-best-practices/references/review.md +0 -174
|
@@ -1,159 +1,27 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
See [README.md](./README.md) for
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## wrangler.jsonc
|
|
31
|
-
|
|
32
|
-
```jsonc
|
|
33
|
-
{
|
|
34
|
-
"compatibility_date": "2025-01-01", // Use latest for new projects
|
|
35
|
-
"compatibility_flags": ["nodejs_compat"],
|
|
36
|
-
"hyperdrive": [
|
|
37
|
-
{
|
|
38
|
-
"binding": "HYPERDRIVE",
|
|
39
|
-
"id": "<HYPERDRIVE_ID>",
|
|
40
|
-
"localConnectionString": "postgres://user:pass@localhost:5432/dev"
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
**Generate TypeScript types:** Run `npx wrangler types` to auto-generate `worker-configuration.d.ts` from your wrangler.jsonc.
|
|
47
|
-
|
|
48
|
-
**Multiple configs:**
|
|
49
|
-
```jsonc
|
|
50
|
-
{
|
|
51
|
-
"hyperdrive": [
|
|
52
|
-
{"binding": "HYPERDRIVE_CACHED", "id": "<ID1>"},
|
|
53
|
-
{"binding": "HYPERDRIVE_NO_CACHE", "id": "<ID2>"}
|
|
54
|
-
]
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## Management
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
npx wrangler hyperdrive list
|
|
62
|
-
npx wrangler hyperdrive get <ID>
|
|
63
|
-
npx wrangler hyperdrive update <ID> --max-age=180
|
|
64
|
-
npx wrangler hyperdrive delete <ID>
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Config Options
|
|
68
|
-
|
|
69
|
-
Hyperdrive create/update CLI flags:
|
|
70
|
-
|
|
71
|
-
| Option | Default | Notes |
|
|
72
|
-
|--------|---------|-------|
|
|
73
|
-
| `--caching-disabled` | `false` | Disable caching |
|
|
74
|
-
| `--max-age` | `60` | Cache TTL (max 3600s) |
|
|
75
|
-
| `--swr` | `15` | Stale-while-revalidate |
|
|
76
|
-
| `--origin-connection-limit` | 20/100 | Free/paid |
|
|
77
|
-
| `--access-client-id` | - | Tunnel auth |
|
|
78
|
-
| `--access-client-secret` | - | Tunnel auth |
|
|
79
|
-
| `--sslmode` | `require` | PostgreSQL only |
|
|
80
|
-
|
|
81
|
-
## Smart Placement Integration
|
|
82
|
-
|
|
83
|
-
For Workers making **multiple queries** per request, enable Smart Placement to execute near your database:
|
|
84
|
-
|
|
85
|
-
```jsonc
|
|
86
|
-
{
|
|
87
|
-
"compatibility_date": "2025-01-01",
|
|
88
|
-
"compatibility_flags": ["nodejs_compat"],
|
|
89
|
-
"placement": {
|
|
90
|
-
"mode": "smart"
|
|
91
|
-
},
|
|
92
|
-
"hyperdrive": [
|
|
93
|
-
{
|
|
94
|
-
"binding": "HYPERDRIVE",
|
|
95
|
-
"id": "<HYPERDRIVE_ID>"
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
**Benefits:** Multi-query Workers run closer to DB, reducing round-trip latency. See [patterns.md](./patterns.md) for examples.
|
|
102
|
-
|
|
103
|
-
## Private DB via Tunnel
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
Worker → Hyperdrive → Access → Tunnel → Private Network → DB
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
**Setup:**
|
|
110
|
-
```bash
|
|
111
|
-
# 1. Create tunnel
|
|
112
|
-
cloudflared tunnel create my-db-tunnel
|
|
113
|
-
|
|
114
|
-
# 2. Configure hostname in Zero Trust dashboard
|
|
115
|
-
# Domain: db-tunnel.example.com
|
|
116
|
-
# Service: TCP -> localhost:5432
|
|
117
|
-
|
|
118
|
-
# 3. Create service token (Zero Trust > Service Auth)
|
|
119
|
-
# Save Client ID/Secret
|
|
120
|
-
|
|
121
|
-
# 4. Create Access app (db-tunnel.example.com)
|
|
122
|
-
# Policy: Service Auth token from step 3
|
|
123
|
-
|
|
124
|
-
# 5. Create Hyperdrive
|
|
125
|
-
npx wrangler hyperdrive create my-private-db \
|
|
126
|
-
--host=db-tunnel.example.com \
|
|
127
|
-
--user=dbuser --password=dbpass --database=prod \
|
|
128
|
-
--access-client-id=<ID> --access-client-secret=<SECRET>
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
**⚠️ Don't specify `--port` with Tunnel** - port configured in tunnel service settings.
|
|
132
|
-
|
|
133
|
-
## Local Dev
|
|
134
|
-
|
|
135
|
-
**Option 1: Local (RECOMMENDED):**
|
|
136
|
-
```bash
|
|
137
|
-
# Env var (takes precedence)
|
|
138
|
-
export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="postgres://user:pass@localhost:5432/dev"
|
|
139
|
-
npx wrangler dev
|
|
140
|
-
|
|
141
|
-
# wrangler.jsonc
|
|
142
|
-
{"hyperdrive": [{"binding": "HYPERDRIVE", "localConnectionString": "postgres://..."}]}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
**Remote DB locally:**
|
|
146
|
-
```bash
|
|
147
|
-
# PostgreSQL
|
|
148
|
-
export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="postgres://user:pass@remote:5432/db?sslmode=require"
|
|
149
|
-
|
|
150
|
-
# MySQL
|
|
151
|
-
export CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE="mysql://user:pass@remote:3306/db?sslMode=REQUIRED"
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
**Option 2: Remote execution:**
|
|
155
|
-
```bash
|
|
156
|
-
npx wrangler dev --remote # Uses deployed config, affects production
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
See [api.md](./api.md), [patterns.md](./patterns.md), [gotchas.md](./gotchas.md).
|
|
1
|
+
# Hyperdrive configuration
|
|
2
|
+
|
|
3
|
+
See [README.md](./README.md) for the retrieval workflow. Fetch the relevant guide before creating or changing resources; use current configuration fields and CLI syntax from these sources.
|
|
4
|
+
|
|
5
|
+
| Task | Official documentation |
|
|
6
|
+
|------|------------------------|
|
|
7
|
+
| Create the first configuration and bind it to a Worker | [Get started](https://developers.cloudflare.com/hyperdrive/get-started/) |
|
|
8
|
+
| Create, inspect, update, or delete configurations; set cache or pool options | [Wrangler commands](https://developers.cloudflare.com/hyperdrive/reference/wrangler-commands/) |
|
|
9
|
+
| Generate TypeScript types from Worker configuration | [Workers TypeScript](https://developers.cloudflare.com/workers/languages/typescript/) |
|
|
10
|
+
| Connect a private database using the recommended Workers VPC route | [Workers VPC integration](https://developers.cloudflare.com/hyperdrive/configuration/connect-to-private-database-vpc/) |
|
|
11
|
+
| Maintain a private database connection using Tunnel and Access | [Tunnel integration](https://developers.cloudflare.com/hyperdrive/configuration/connect-to-private-database/) |
|
|
12
|
+
| Configure database network access | [Firewall and networking](https://developers.cloudflare.com/hyperdrive/configuration/firewall-and-networking-configuration/) |
|
|
13
|
+
| Configure server verification or client certificates | [SSL/TLS certificates](https://developers.cloudflare.com/hyperdrive/configuration/tls-ssl-certificates-for-hyperdrive/) |
|
|
14
|
+
| Rotate origin database credentials | [Credential rotation](https://developers.cloudflare.com/hyperdrive/configuration/rotate-credentials/) |
|
|
15
|
+
| Configure cache freshness or separate cached and fresh-read bindings | [Query caching](https://developers.cloudflare.com/hyperdrive/concepts/query-caching/) |
|
|
16
|
+
| Budget origin connections across configurations | [Tune connection pooling](https://developers.cloudflare.com/hyperdrive/configuration/tune-connection-pool/) |
|
|
17
|
+
| Choose local database access or remote Hyperdrive testing | [Local development](https://developers.cloudflare.com/hyperdrive/configuration/local-development/) |
|
|
18
|
+
| Evaluate Worker placement for multiple database round trips | [Smart Placement](https://developers.cloudflare.com/workers/configuration/placement/) |
|
|
19
|
+
|
|
20
|
+
## Setup decisions
|
|
21
|
+
|
|
22
|
+
- Identify the database engine, provider, and network path first. The [PostgreSQL](https://developers.cloudflare.com/hyperdrive/examples/connect-to-postgres/) and [MySQL](https://developers.cloudflare.com/hyperdrive/examples/connect-to-mysql/) indexes route to provider-specific instructions.
|
|
23
|
+
- For private connectivity, choose Workers VPC or the existing Tunnel/Access integration before configuring credentials. Follow the selected guide's prerequisites and TLS guidance.
|
|
24
|
+
- Decide which reads may be stale before selecting cache settings. Multiple configurations against one database contribute to its total origin connection usage.
|
|
25
|
+
- Local direct database access does not exercise Hyperdrive pooling or caching. Use the local-development guide's remote option when verifying those behaviors, and identify the database that option targets before running writes.
|
|
26
|
+
|
|
27
|
+
See [api.md](./api.md) for drivers and [gotchas.md](./gotchas.md) for diagnosis.
|
|
@@ -1,77 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Hyperdrive troubleshooting
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Start with the actual error and the affected configuration. Fetch [Troubleshoot and debug](https://developers.cloudflare.com/hyperdrive/observability/troubleshooting/) for current error codes and diagnosis rather than guessing from a generic connection failure.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
| Symptom | What to inspect and where to read |
|
|
6
|
+
|---------|----------------------------------|
|
|
7
|
+
| Connection refused or authentication failure | Check origin reachability and credentials using [troubleshooting](https://developers.cloudflare.com/hyperdrive/observability/troubleshooting/) and [firewall/networking configuration](https://developers.cloudflare.com/hyperdrive/configuration/firewall-and-networking-configuration/). |
|
|
8
|
+
| Private database or TLS failure | Follow the selected [Workers VPC](https://developers.cloudflare.com/hyperdrive/configuration/connect-to-private-database-vpc/) or [Tunnel/Access](https://developers.cloudflare.com/hyperdrive/configuration/connect-to-private-database/) path and its certificate prerequisites; see [SSL/TLS configuration](https://developers.cloudflare.com/hyperdrive/configuration/tls-ssl-certificates-for-hyperdrive/). |
|
|
9
|
+
| Pool exhaustion or too many connections | Distinguish client connection lifetime from origin pool capacity. Read [connection lifecycle](https://developers.cloudflare.com/hyperdrive/concepts/connection-lifecycle/), [pool tuning](https://developers.cloudflare.com/hyperdrive/configuration/tune-connection-pool/), and [limits](https://developers.cloudflare.com/hyperdrive/platform/limits/). |
|
|
10
|
+
| Query timeout | Check the current [limits](https://developers.cloudflare.com/hyperdrive/platform/limits/) and [metrics](https://developers.cloudflare.com/hyperdrive/observability/metrics/) before changing query or transaction design. |
|
|
11
|
+
| Stale reads or unexpectedly uncached queries | Inspect the binding's cache configuration and query eligibility in [query caching](https://developers.cloudflare.com/hyperdrive/concepts/query-caching/). Writes do not purge cached reads; do not treat prepared-statement settings as cache controls. |
|
|
12
|
+
| Slow multi-query requests | Inspect [metrics](https://developers.cloudflare.com/hyperdrive/observability/metrics/) and evaluate [Smart Placement](https://developers.cloudflare.com/workers/configuration/placement/). |
|
|
13
|
+
| Local connection failure, ignored environment variable, or absent cache behavior | Check binding names, local connection overrides, precedence, and remote testing in [local development](https://developers.cloudflare.com/hyperdrive/configuration/local-development/). |
|
|
14
|
+
| Unsupported driver or SQL feature | Check [supported databases and features](https://developers.cloudflare.com/hyperdrive/reference/supported-databases-and-features/) and the selected [driver guide](./api.md). |
|
|
6
15
|
|
|
7
|
-
|
|
16
|
+
## Capacity and changes
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
**Solution:** Set `max: 5` in driver config, reuse connections, ensure proper cleanup with `client.end()` or `ctx.waitUntil(conn.end())`
|
|
18
|
+
Retrieve [limits](https://developers.cloudflare.com/hyperdrive/platform/limits/) and [pricing](https://developers.cloudflare.com/hyperdrive/platform/pricing/) for current plan allowances, connection and query bounds, and limit-increase guidance. Check [release notes](https://developers.cloudflare.com/hyperdrive/platform/release-notes/) when behavior changes after an upgrade.
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
**Cause:** All connections in pool are in use, often due to long-running transactions
|
|
15
|
-
**Solution:** Reduce transaction duration, avoid queries >60s, don't hold connections during external calls, or upgrade to paid plan for more connections
|
|
16
|
-
|
|
17
|
-
### "connection_refused"
|
|
18
|
-
|
|
19
|
-
**Cause:** Database refusing connections due to firewall, connection limits, or service down
|
|
20
|
-
**Solution:** Check firewall allows Cloudflare IPs, verify DB listening on port, confirm service running, and validate credentials
|
|
21
|
-
|
|
22
|
-
### "Query timeout (deadline exceeded)"
|
|
23
|
-
|
|
24
|
-
**Cause:** Query execution exceeding 60s timeout limit
|
|
25
|
-
**Solution:** Optimize with indexes, reduce dataset with LIMIT, break into smaller queries, or use async processing
|
|
26
|
-
|
|
27
|
-
### "password authentication failed"
|
|
28
|
-
|
|
29
|
-
**Cause:** Invalid credentials in Hyperdrive configuration
|
|
30
|
-
**Solution:** Check username and password in Hyperdrive config match database credentials
|
|
31
|
-
|
|
32
|
-
### "SSL/TLS connection error"
|
|
33
|
-
|
|
34
|
-
**Cause:** SSL/TLS configuration mismatch between Hyperdrive and database
|
|
35
|
-
**Solution:** Add `sslmode=require` (Postgres) or `sslMode=REQUIRED` (MySQL), upload CA cert if self-signed, verify DB has SSL enabled, and check cert expiry
|
|
36
|
-
|
|
37
|
-
### "Queries not being cached"
|
|
38
|
-
|
|
39
|
-
**Cause:** Query is mutating (INSERT/UPDATE/DELETE), contains volatile functions (NOW(), RANDOM()), or caching disabled
|
|
40
|
-
**Solution:** Verify query is non-mutating SELECT, avoid volatile functions, confirm caching enabled, use `wrangler dev --remote` to test, and set `prepare=true` for postgres.js
|
|
41
|
-
|
|
42
|
-
### "Slow multi-query Workers despite Hyperdrive"
|
|
43
|
-
|
|
44
|
-
**Cause:** Worker executing at edge, each query round-trips to DB region
|
|
45
|
-
**Solution:** Enable Smart Placement (`"placement": {"mode": "smart"}` in wrangler.jsonc) to execute Worker near DB. See [patterns.md](./patterns.md) Multi-Query pattern.
|
|
46
|
-
|
|
47
|
-
### "Local database connection failed"
|
|
48
|
-
|
|
49
|
-
**Cause:** `localConnectionString` incorrect or database not running
|
|
50
|
-
**Solution:** Verify `localConnectionString` correct, check DB running, confirm env var name matches binding, and test with psql/mysql client
|
|
51
|
-
|
|
52
|
-
### "Environment variable not working"
|
|
53
|
-
|
|
54
|
-
**Cause:** Environment variable format incorrect or not exported
|
|
55
|
-
**Solution:** Use format `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING>`, ensure binding matches wrangler.jsonc, export variable in shell, and restart wrangler dev
|
|
56
|
-
|
|
57
|
-
## Limits
|
|
58
|
-
|
|
59
|
-
| Limit | Free | Paid | Notes |
|
|
60
|
-
|-------|------|------|-------|
|
|
61
|
-
| Max configs | 10 | 25 | Hyperdrive configurations per account |
|
|
62
|
-
| Worker connections | 6 | 6 | Max concurrent connections per Worker invocation |
|
|
63
|
-
| Username/DB name | 63 bytes | 63 bytes | Maximum length |
|
|
64
|
-
| Connection timeout | 15s | 15s | Time to establish connection |
|
|
65
|
-
| Idle timeout | 10 min | 10 min | Connection idle timeout |
|
|
66
|
-
| Max origin connections | ~20 | ~100 | Connections to origin database |
|
|
67
|
-
| Query duration max | 60s | 60s | Queries >60s terminated |
|
|
68
|
-
| Cached response max | 50 MB | 50 MB | Responses >50MB returned but not cached |
|
|
69
|
-
|
|
70
|
-
## Resources
|
|
71
|
-
|
|
72
|
-
- [Docs](https://developers.cloudflare.com/hyperdrive/)
|
|
73
|
-
- [Getting Started](https://developers.cloudflare.com/hyperdrive/get-started/)
|
|
74
|
-
- [Wrangler Reference](https://developers.cloudflare.com/hyperdrive/reference/wrangler-commands/)
|
|
75
|
-
- [Supported DBs](https://developers.cloudflare.com/hyperdrive/reference/supported-databases-and-features/)
|
|
76
|
-
- [Discord #hyperdrive](https://discord.cloudflare.com)
|
|
77
|
-
- [Limit Increase Form](https://forms.gle/ukpeZVLWLnKeixDu7)
|
|
20
|
+
See [configuration.md](./configuration.md) to change a configuration and [patterns.md](./patterns.md) to revisit freshness or connection decisions.
|
|
@@ -1,190 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Hyperdrive design patterns
|
|
2
2
|
|
|
3
|
-
See [
|
|
3
|
+
See [api.md](./api.md) for maintained driver and ORM examples. Use the following decisions to select a pattern, then fetch its linked documentation for implementation.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
| Workload or decision | Guidance and documentation |
|
|
6
|
+
|----------------------|----------------------------|
|
|
7
|
+
| Popular content or analytics dashboards | Cache only when the product can tolerate the configured stale window. Use [query caching](https://developers.cloudflare.com/hyperdrive/concepts/query-caching/) for eligibility, parameters, and settings. |
|
|
8
|
+
| Mixed cached reads and fresh reads | Route authentication, permissions, and reads after writes through a cache-disabled configuration. Writes do not invalidate cached results; see [read-after-write behavior](https://developers.cloudflare.com/hyperdrive/concepts/query-caching/#read-after-write-behavior). |
|
|
9
|
+
| Multi-tenant queries | Derive tenant scope from authenticated application context and apply it to every query. A cache is not an authorization boundary. Review [query caching](https://developers.cloudflare.com/hyperdrive/concepts/query-caching/) for the selected query's behavior. |
|
|
10
|
+
| Globally distributed callers | Understand the distinction between fast connection setup and the remaining query round trip in [how Hyperdrive works](https://developers.cloudflare.com/hyperdrive/concepts/how-hyperdrive-works/). |
|
|
11
|
+
| Multiple sequential database queries | Measure placement rather than assuming the nearest user location is best. Consult [Smart Placement](https://developers.cloudflare.com/workers/configuration/placement/) and [Hyperdrive metrics](https://developers.cloudflare.com/hyperdrive/observability/metrics/). |
|
|
12
|
+
| Transactions or connection-local state | Keep transactions short and do not assume state survives across transactions. Fetch [connection pooling](https://developers.cloudflare.com/hyperdrive/concepts/connection-pooling/) and [supported features](https://developers.cloudflare.com/hyperdrive/reference/supported-databases-and-features/) before relying on session settings. |
|
|
13
|
+
| Client lifetime and pool sizing | Create clients per handler invocation; Hyperdrive owns the origin pool. Use [connection lifecycle](https://developers.cloudflare.com/hyperdrive/concepts/connection-lifecycle/) and [pool tuning](https://developers.cloudflare.com/hyperdrive/configuration/tune-connection-pool/) instead of a global driver pool or copied connection counts. |
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
const sql = postgres(env.HYPERDRIVE.connectionString, {max: 5, prepare: true});
|
|
9
|
-
|
|
10
|
-
// Cacheable: popular content
|
|
11
|
-
const posts = await sql`SELECT * FROM posts WHERE published = true ORDER BY views DESC LIMIT 20`;
|
|
12
|
-
|
|
13
|
-
// Cacheable: user profiles
|
|
14
|
-
const [user] = await sql`SELECT id, username, bio FROM users WHERE id = ${userId}`;
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
**Benefits:** Trending/profiles cached (60s), connection pooling handles spikes.
|
|
18
|
-
|
|
19
|
-
## Mixed Read/Write
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
interface Env {
|
|
23
|
-
HYPERDRIVE_CACHED: Hyperdrive; // max_age=120
|
|
24
|
-
HYPERDRIVE_REALTIME: Hyperdrive; // caching disabled
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Reads: cached
|
|
28
|
-
if (req.method === "GET") {
|
|
29
|
-
const sql = postgres(env.HYPERDRIVE_CACHED.connectionString, {prepare: true});
|
|
30
|
-
const products = await sql`SELECT * FROM products WHERE category = ${cat}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Writes: no cache (immediate consistency)
|
|
34
|
-
if (req.method === "POST") {
|
|
35
|
-
const sql = postgres(env.HYPERDRIVE_REALTIME.connectionString, {prepare: true});
|
|
36
|
-
await sql`INSERT INTO orders ${sql(data)}`;
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Analytics Dashboard
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
const client = new Client({connectionString: env.HYPERDRIVE.connectionString});
|
|
44
|
-
await client.connect();
|
|
45
|
-
|
|
46
|
-
// Aggregate queries cached (use fixed timestamps for caching)
|
|
47
|
-
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString();
|
|
48
|
-
const dailyStats = await client.query(`
|
|
49
|
-
SELECT DATE(created_at) as date, COUNT(*) as orders, SUM(amount) as revenue
|
|
50
|
-
FROM orders WHERE created_at >= $1
|
|
51
|
-
GROUP BY DATE(created_at) ORDER BY date DESC
|
|
52
|
-
`, [thirtyDaysAgo]);
|
|
53
|
-
|
|
54
|
-
const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString();
|
|
55
|
-
const topProducts = await client.query(`
|
|
56
|
-
SELECT p.name, COUNT(oi.id) as count, SUM(oi.quantity * oi.price) as revenue
|
|
57
|
-
FROM order_items oi JOIN products p ON oi.product_id = p.id
|
|
58
|
-
WHERE oi.created_at >= $1
|
|
59
|
-
GROUP BY p.id, p.name ORDER BY revenue DESC LIMIT 10
|
|
60
|
-
`, [sevenDaysAgo]);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**Benefits:** Expensive aggregations cached (avoid NOW() for cacheability), dashboard instant, reduced DB load.
|
|
64
|
-
|
|
65
|
-
## Multi-Tenant
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
const tenantId = req.headers.get("X-Tenant-ID");
|
|
69
|
-
const sql = postgres(env.HYPERDRIVE.connectionString, {prepare: true});
|
|
70
|
-
|
|
71
|
-
// Tenant-scoped queries cached separately
|
|
72
|
-
const docs = await sql`
|
|
73
|
-
SELECT * FROM documents
|
|
74
|
-
WHERE tenant_id = ${tenantId} AND deleted_at IS NULL
|
|
75
|
-
ORDER BY updated_at DESC LIMIT 50
|
|
76
|
-
`;
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
**Benefits:** Per-tenant caching, shared connection pool, protects DB from multi-tenant load.
|
|
80
|
-
|
|
81
|
-
## Geographically Distributed
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
// Worker runs at edge nearest user
|
|
85
|
-
// Connection setup at edge (fast), pooling near DB (efficient)
|
|
86
|
-
const sql = postgres(env.HYPERDRIVE.connectionString, {prepare: true});
|
|
87
|
-
const [user] = await sql`SELECT * FROM users WHERE id = ${userId}`;
|
|
88
|
-
|
|
89
|
-
return Response.json({
|
|
90
|
-
user,
|
|
91
|
-
serverRegion: req.cf?.colo, // Edge location
|
|
92
|
-
});
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Benefits:** Edge setup + DB pooling = global → single-region DB without replication.
|
|
96
|
-
|
|
97
|
-
## Multi-Query + Smart Placement
|
|
98
|
-
|
|
99
|
-
For Workers making **multiple queries** per request, enable Smart Placement to execute near DB:
|
|
100
|
-
|
|
101
|
-
```jsonc
|
|
102
|
-
// wrangler.jsonc
|
|
103
|
-
{
|
|
104
|
-
"placement": {"mode": "smart"},
|
|
105
|
-
"hyperdrive": [{"binding": "HYPERDRIVE", "id": "<ID>"}]
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
const sql = postgres(env.HYPERDRIVE.connectionString, {prepare: true});
|
|
111
|
-
|
|
112
|
-
// Multiple queries benefit from Smart Placement
|
|
113
|
-
const [user] = await sql`SELECT * FROM users WHERE id = ${userId}`;
|
|
114
|
-
const orders = await sql`SELECT * FROM orders WHERE user_id = ${userId} ORDER BY created_at DESC LIMIT 10`;
|
|
115
|
-
const stats = await sql`SELECT COUNT(*) as total, SUM(amount) as spent FROM orders WHERE user_id = ${userId}`;
|
|
116
|
-
|
|
117
|
-
return Response.json({user, orders, stats});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
**Benefits:** Worker executes near DB → reduces latency for each query. Without Smart Placement, each query round-trips from edge.
|
|
121
|
-
|
|
122
|
-
## Connection Pooling
|
|
123
|
-
|
|
124
|
-
Operates in **transaction mode**: connection acquired per transaction, `RESET` on return.
|
|
125
|
-
|
|
126
|
-
**SET statements:**
|
|
127
|
-
```typescript
|
|
128
|
-
// ✅ Within transaction
|
|
129
|
-
await client.query("BEGIN");
|
|
130
|
-
await client.query("SET work_mem = '256MB'");
|
|
131
|
-
await client.query("SELECT * FROM large_table"); // Uses SET
|
|
132
|
-
await client.query("COMMIT"); // RESET after
|
|
133
|
-
|
|
134
|
-
// ✅ Single statement
|
|
135
|
-
await client.query("SET work_mem = '256MB'; SELECT * FROM large_table");
|
|
136
|
-
|
|
137
|
-
// ❌ Across queries (may get different connection)
|
|
138
|
-
await client.query("SET work_mem = '256MB'");
|
|
139
|
-
await client.query("SELECT * FROM large_table"); // SET not applied
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**Best practices:**
|
|
143
|
-
```typescript
|
|
144
|
-
// ❌ Long transactions block pooling
|
|
145
|
-
await client.query("BEGIN");
|
|
146
|
-
await processThousands(); // Connection held entire time
|
|
147
|
-
await client.query("COMMIT");
|
|
148
|
-
|
|
149
|
-
// ✅ Short transactions
|
|
150
|
-
await client.query("BEGIN");
|
|
151
|
-
await client.query("UPDATE users SET status = $1 WHERE id = $2", [status, id]);
|
|
152
|
-
await client.query("COMMIT");
|
|
153
|
-
|
|
154
|
-
// ✅ SET LOCAL within transaction
|
|
155
|
-
await client.query("BEGIN");
|
|
156
|
-
await client.query("SET LOCAL work_mem = '256MB'");
|
|
157
|
-
await client.query("SELECT * FROM large_table");
|
|
158
|
-
await client.query("COMMIT");
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## Performance Tips
|
|
162
|
-
|
|
163
|
-
**Enable prepared statements (required for caching):**
|
|
164
|
-
```typescript
|
|
165
|
-
const sql = postgres(connectionString, {prepare: true}); // Default, enables caching
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
**Optimize connection settings:**
|
|
169
|
-
```typescript
|
|
170
|
-
const sql = postgres(connectionString, {
|
|
171
|
-
max: 5, // Stay under Workers' 6 connection limit
|
|
172
|
-
fetch_types: false, // Reduce latency if not using arrays
|
|
173
|
-
idle_timeout: 60, // Match Worker lifetime
|
|
174
|
-
});
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
**Write cache-friendly queries:**
|
|
178
|
-
```typescript
|
|
179
|
-
// ✅ Cacheable (deterministic)
|
|
180
|
-
await sql`SELECT * FROM products WHERE category = 'electronics' LIMIT 10`;
|
|
181
|
-
|
|
182
|
-
// ❌ Not cacheable (volatile NOW())
|
|
183
|
-
await sql`SELECT * FROM logs WHERE created_at > NOW()`;
|
|
184
|
-
|
|
185
|
-
// ✅ Cacheable (parameterized timestamp)
|
|
186
|
-
const ts = Date.now();
|
|
187
|
-
await sql`SELECT * FROM logs WHERE created_at > ${ts}`;
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
See [gotchas.md](./gotchas.md) for limits, troubleshooting.
|
|
15
|
+
Separate application correctness from acceleration: use parameterized queries, enforce tenant access in the application, and select freshness before tuning cache hit rate. See [gotchas.md](./gotchas.md) when observed behavior differs from the design.
|
|
@@ -1,61 +1,12 @@
|
|
|
1
|
-
# Cloudflare Images
|
|
1
|
+
# Cloudflare Images
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Choose the image source and operation before selecting an API. Hosted-image management, remote URL transformations, and the Workers optimization binding have different contracts. Retrieve the documentation for the path the project uses.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
| Task | Start here |
|
|
6
|
+
|------|------------|
|
|
7
|
+
| Optimize image bytes in a Worker or manage hosted images | [API selection](api.md) |
|
|
8
|
+
| Configure a binding, variants, or private delivery | [Configuration](configuration.md) |
|
|
9
|
+
| Accept client uploads, serve responsive images, watermark, or store results in R2 | [Patterns](patterns.md) |
|
|
10
|
+
| Diagnose failures, check limits, or investigate caching | [Troubleshooting](gotchas.md) |
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
- **Transform in Worker?** → [api.md](api.md#workers-binding-api-2026-primary-method) (Workers Binding API)
|
|
9
|
-
- **Upload from Worker?** → [api.md](api.md#upload-from-worker) (REST API)
|
|
10
|
-
- **Upload from client?** → [patterns.md](patterns.md#upload-from-client-direct-creator-upload) (Direct Creator Upload)
|
|
11
|
-
- **Set up variants?** → [configuration.md](configuration.md#variants-configuration)
|
|
12
|
-
- **Serve responsive images?** → [patterns.md](patterns.md#responsive-images)
|
|
13
|
-
- **Add watermarks?** → [patterns.md](patterns.md#watermarking)
|
|
14
|
-
- **Fix errors?** → [gotchas.md](gotchas.md#common-errors)
|
|
15
|
-
|
|
16
|
-
## Reading Order
|
|
17
|
-
|
|
18
|
-
**For building image upload/transform feature:**
|
|
19
|
-
1. [configuration.md](configuration.md) - Setup Workers binding
|
|
20
|
-
2. [api.md](api.md#workers-binding-api-2026-primary-method) - Learn transform API
|
|
21
|
-
3. [patterns.md](patterns.md#upload-from-client-direct-creator-upload) - Direct upload pattern
|
|
22
|
-
4. [gotchas.md](gotchas.md) - Check limits and errors
|
|
23
|
-
|
|
24
|
-
**For URL-based transforms:**
|
|
25
|
-
1. [configuration.md](configuration.md#variants-configuration) - Create variants
|
|
26
|
-
2. [api.md](api.md#url-transform-api) - URL syntax
|
|
27
|
-
3. [patterns.md](patterns.md#responsive-images) - Responsive patterns
|
|
28
|
-
|
|
29
|
-
**For troubleshooting:**
|
|
30
|
-
1. [gotchas.md](gotchas.md#common-errors) - Error messages
|
|
31
|
-
2. [gotchas.md](gotchas.md#limits) - Size/format limits
|
|
32
|
-
|
|
33
|
-
## Core Methods
|
|
34
|
-
|
|
35
|
-
| Method | Use Case | Location |
|
|
36
|
-
|--------|----------|----------|
|
|
37
|
-
| `env.IMAGES.input().transform()` | Transform in Worker | [api.md:11](api.md) |
|
|
38
|
-
| REST API `/images/v1` | Upload images | [api.md:57](api.md) |
|
|
39
|
-
| Direct Creator Upload | Client-side upload | [api.md:127](api.md) |
|
|
40
|
-
| URL transforms | Static image delivery | [api.md:112](api.md) |
|
|
41
|
-
|
|
42
|
-
## In This Reference
|
|
43
|
-
|
|
44
|
-
- **[api.md](api.md)** - Complete API: Workers binding, REST endpoints, URL transforms
|
|
45
|
-
- **[configuration.md](configuration.md)** - Setup: wrangler.toml, variants, auth, signed URLs
|
|
46
|
-
- **[patterns.md](patterns.md)** - Patterns: responsive images, watermarks, format negotiation, caching
|
|
47
|
-
- **[gotchas.md](gotchas.md)** - Troubleshooting: limits, errors, best practices
|
|
48
|
-
|
|
49
|
-
## Key Features
|
|
50
|
-
|
|
51
|
-
- **Automatic Optimization** - AVIF/WebP format negotiation
|
|
52
|
-
- **On-the-fly Transforms** - Resize, crop, blur, sharpen via URL or API
|
|
53
|
-
- **Workers Binding** - Transform images in Workers (2026 primary method)
|
|
54
|
-
- **Direct Upload** - Secure client-side uploads without backend proxy
|
|
55
|
-
- **Global Delivery** - Cached at 300+ Cloudflare data centers
|
|
56
|
-
- **Watermarking** - Overlay images programmatically
|
|
57
|
-
|
|
58
|
-
## See Also
|
|
59
|
-
|
|
60
|
-
- [Official Docs](https://developers.cloudflare.com/images/)
|
|
61
|
-
- [Workers Examples](https://developers.cloudflare.com/images/tutorials/)
|
|
12
|
+
For new work, inspect the project's installed Wrangler version, compatibility settings, existing image storage, and public/private access requirements. Read only the relevant linked pages and adapt them to the project; preserve existing conventions and verify behavior with representative images.
|
|
@@ -1,96 +1,13 @@
|
|
|
1
|
-
# API
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[images
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const imageResponse = await env.IMAGES
|
|
15
|
-
.input(fileBuffer)
|
|
16
|
-
.transform({ width: 800, height: 600, fit: "cover", quality: 85, format: "avif" })
|
|
17
|
-
.output();
|
|
18
|
-
return imageResponse.response();
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Transform Options
|
|
22
|
-
|
|
23
|
-
```typescript
|
|
24
|
-
interface TransformOptions {
|
|
25
|
-
width?: number; height?: number;
|
|
26
|
-
fit?: "scale-down" | "contain" | "cover" | "crop" | "pad";
|
|
27
|
-
quality?: number; // 1-100
|
|
28
|
-
format?: "avif" | "webp" | "jpeg" | "png";
|
|
29
|
-
dpr?: number; // 1-3
|
|
30
|
-
gravity?: "auto" | "left" | "right" | "top" | "bottom" | "face" | string;
|
|
31
|
-
sharpen?: number; // 0-10
|
|
32
|
-
blur?: number; // 1-250
|
|
33
|
-
rotate?: 90 | 180 | 270;
|
|
34
|
-
background?: string; // CSS color for pad
|
|
35
|
-
metadata?: "none" | "copyright" | "keep";
|
|
36
|
-
brightness?: number; contrast?: number; gamma?: number; // 0-2
|
|
37
|
-
}
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### Draw/Watermark
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
await env.IMAGES.input(baseImage)
|
|
44
|
-
.draw(env.IMAGES.input(watermark).transform({ width: 100 }), { top: 10, left: 10, opacity: 0.8 })
|
|
45
|
-
.output();
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## REST API
|
|
49
|
-
|
|
50
|
-
### Upload Image
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/images/v1 \
|
|
54
|
-
-H "Authorization: Bearer {token}" -F file=@image.jpg -F metadata='{"key":"value"}'
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Other Operations
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
GET /accounts/{account_id}/images/v1/{image_id} # Get details
|
|
61
|
-
DELETE /accounts/{account_id}/images/v1/{image_id} # Delete
|
|
62
|
-
GET /accounts/{account_id}/images/v1?page=1 # List
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## URL Transform API
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
https://imagedelivery.net/{hash}/{id}/width=800,height=600,fit=cover,format=avif
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
**Params:** `w=`, `h=`, `fit=`, `q=`, `f=`, `dpr=`, `gravity=`, `sharpen=`, `blur=`, `rotate=`, `background=`, `metadata=`
|
|
72
|
-
|
|
73
|
-
## Direct Creator Upload
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
// 1. Get upload URL (backend)
|
|
77
|
-
const { result } = await fetch(
|
|
78
|
-
`https://api.cloudflare.com/client/v4/accounts/${accountId}/images/v2/direct_upload`,
|
|
79
|
-
{ method: 'POST', headers: { 'Authorization': `Bearer ${token}` },
|
|
80
|
-
body: JSON.stringify({ requireSignedURLs: false }) }
|
|
81
|
-
).then(r => r.json());
|
|
82
|
-
|
|
83
|
-
// 2. Client uploads to result.uploadURL
|
|
84
|
-
const formData = new FormData();
|
|
85
|
-
formData.append('file', file);
|
|
86
|
-
await fetch(result.uploadURL, { method: 'POST', body: formData });
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## Error Codes
|
|
90
|
-
|
|
91
|
-
| Code | Message | Solution |
|
|
92
|
-
|------|---------|----------|
|
|
93
|
-
| 5400 | Invalid format | Use JPEG, PNG, GIF, WebP |
|
|
94
|
-
| 5401 | Too large | Max 100MB |
|
|
95
|
-
| 5403 | Invalid transform | Check params |
|
|
96
|
-
| 9413 | Rate limit | Implement backoff |
|
|
1
|
+
# Images API Selection
|
|
2
|
+
|
|
3
|
+
| Operation | Documentation |
|
|
4
|
+
|-----------|---------------|
|
|
5
|
+
| Optimize image bytes in a Worker; select input, transform, output, and response methods | [Optimize with Workers](https://developers.cloudflare.com/images/optimization/binding/#methods) |
|
|
6
|
+
| Upload, list, retrieve, update, or delete hosted images from a Worker | [Manage hosted images with Workers](https://developers.cloudflare.com/images/storage/binding/) |
|
|
7
|
+
| Upload or manage images through HTTP | [Upload methods](https://developers.cloudflare.com/images/storage/upload-images/methods/#upload-using-api) and its linked Images API reference |
|
|
8
|
+
| Accept uploads directly from a client | [Direct Creator Upload](https://developers.cloudflare.com/images/storage/upload-images/direct-creator-upload/) |
|
|
9
|
+
| Construct hosted-image delivery URLs | [Serve uploaded images](https://developers.cloudflare.com/images/optimization/hosted-images/serve-uploaded-images/) |
|
|
10
|
+
| Apply URL optimization parameters or select fit, quality, and format | [Optimization features](https://developers.cloudflare.com/images/optimization/features/) |
|
|
11
|
+
| Draw overlays or watermarks | [Draw overlays](https://developers.cloudflare.com/images/optimization/draw-overlays/) |
|
|
12
|
+
|
|
13
|
+
Do not transfer URL parameters or HTTP request shapes directly into binding calls. Read the contract for the selected interface, including output format handling. Use the project's generated binding types and existing error handling. See [configuration](configuration.md) for setup and [troubleshooting](gotchas.md) for failures and limits.
|