pi-cloudflare 0.10.2 → 0.11.1

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.
Files changed (293) hide show
  1. package/README.md +78 -180
  2. package/package.json +7 -42
  3. package/plugin.json +3 -3
  4. package/skills/agents-sdk/SKILL.md +17 -36
  5. package/skills/agents-sdk/references/client-sdk.md +7 -106
  6. package/skills/agents-sdk/references/human-in-the-loop.md +6 -63
  7. package/skills/agents-sdk/references/mcp.md +9 -184
  8. package/skills/agents-sdk/references/queue-retries.md +12 -73
  9. package/skills/agents-sdk/references/server-driven-messages.md +4 -60
  10. package/skills/agents-sdk/references/state-scheduling.md +10 -166
  11. package/skills/agents-sdk/references/streaming-chat.md +11 -193
  12. package/skills/agents-sdk/references/webhooks-push.md +2 -2
  13. package/skills/agents-sdk/references/workflows.md +14 -125
  14. package/skills/cloudflare/SKILL.md +135 -248
  15. package/skills/cloudflare/references/ai-gateway/README.md +17 -165
  16. package/skills/cloudflare/references/ai-gateway/configuration.md +14 -107
  17. package/skills/cloudflare/references/ai-gateway/dynamic-routing.md +12 -79
  18. package/skills/cloudflare/references/ai-gateway/features.md +22 -96
  19. package/skills/cloudflare/references/ai-gateway/sdk-integration.md +17 -112
  20. package/skills/cloudflare/references/ai-gateway/troubleshooting.md +14 -86
  21. package/skills/cloudflare/references/ai-search/README.md +17 -130
  22. package/skills/cloudflare/references/ai-search/api.md +10 -84
  23. package/skills/cloudflare/references/ai-search/configuration.md +16 -88
  24. package/skills/cloudflare/references/ai-search/gotchas.md +13 -81
  25. package/skills/cloudflare/references/ai-search/patterns.md +12 -82
  26. package/skills/cloudflare/references/analytics-engine/api.md +1 -1
  27. package/skills/cloudflare/references/api/README.md +2 -2
  28. package/skills/cloudflare/references/api/configuration.md +1 -1
  29. package/skills/cloudflare/references/bindings/README.md +11 -117
  30. package/skills/cloudflare/references/bindings/api.md +17 -201
  31. package/skills/cloudflare/references/bindings/configuration.md +20 -188
  32. package/skills/cloudflare/references/bindings/gotchas.md +16 -206
  33. package/skills/cloudflare/references/bindings/patterns.md +15 -195
  34. package/skills/cloudflare/references/bot-management/README.md +1 -1
  35. package/skills/cloudflare/references/browser-rendering/README.md +13 -73
  36. package/skills/cloudflare/references/browser-rendering/api.md +9 -105
  37. package/skills/cloudflare/references/browser-rendering/configuration.md +9 -75
  38. package/skills/cloudflare/references/browser-rendering/gotchas.md +12 -85
  39. package/skills/cloudflare/references/browser-rendering/patterns.md +9 -88
  40. package/skills/cloudflare/references/c3/README.md +6 -5
  41. package/skills/cloudflare/references/c3/api.md +3 -4
  42. package/skills/cloudflare/references/c3/patterns.md +4 -6
  43. package/skills/cloudflare/references/cache-reserve/README.md +1 -1
  44. package/skills/cloudflare/references/containers/README.md +15 -77
  45. package/skills/cloudflare/references/containers/api.md +13 -187
  46. package/skills/cloudflare/references/containers/configuration.md +15 -188
  47. package/skills/cloudflare/references/containers/gotchas.md +16 -178
  48. package/skills/cloudflare/references/containers/patterns.md +14 -198
  49. package/skills/cloudflare/references/cron-triggers/README.md +13 -92
  50. package/skills/cloudflare/references/cron-triggers/api.md +11 -191
  51. package/skills/cloudflare/references/cron-triggers/configuration.md +11 -175
  52. package/skills/cloudflare/references/cron-triggers/gotchas.md +13 -195
  53. package/skills/cloudflare/references/cron-triggers/patterns.md +12 -184
  54. package/skills/cloudflare/references/d1/README.md +9 -127
  55. package/skills/cloudflare/references/d1/api.md +16 -194
  56. package/skills/cloudflare/references/d1/configuration.md +16 -189
  57. package/skills/cloudflare/references/d1/gotchas.md +16 -96
  58. package/skills/cloudflare/references/d1/patterns.md +14 -183
  59. package/skills/cloudflare/references/do-storage/README.md +11 -70
  60. package/skills/cloudflare/references/do-storage/api.md +11 -99
  61. package/skills/cloudflare/references/do-storage/configuration.md +11 -107
  62. package/skills/cloudflare/references/do-storage/gotchas.md +12 -147
  63. package/skills/cloudflare/references/do-storage/patterns.md +11 -190
  64. package/skills/cloudflare/references/do-storage/testing.md +8 -178
  65. package/skills/cloudflare/references/email-routing/README.md +14 -84
  66. package/skills/cloudflare/references/email-routing/api.md +10 -192
  67. package/skills/cloudflare/references/email-routing/configuration.md +13 -186
  68. package/skills/cloudflare/references/email-routing/gotchas.md +12 -193
  69. package/skills/cloudflare/references/email-routing/patterns.md +10 -226
  70. package/skills/cloudflare/references/email-workers/README.md +13 -146
  71. package/skills/cloudflare/references/email-workers/api.md +12 -234
  72. package/skills/cloudflare/references/email-workers/configuration.md +14 -110
  73. package/skills/cloudflare/references/email-workers/gotchas.md +15 -125
  74. package/skills/cloudflare/references/email-workers/patterns.md +14 -100
  75. package/skills/cloudflare/references/flagship/README.md +2 -2
  76. package/skills/cloudflare/references/hyperdrive/README.md +17 -72
  77. package/skills/cloudflare/references/hyperdrive/api.md +19 -136
  78. package/skills/cloudflare/references/hyperdrive/configuration.md +27 -159
  79. package/skills/cloudflare/references/hyperdrive/gotchas.md +15 -72
  80. package/skills/cloudflare/references/hyperdrive/patterns.md +12 -187
  81. package/skills/cloudflare/references/images/README.md +9 -58
  82. package/skills/cloudflare/references/images/api.md +13 -96
  83. package/skills/cloudflare/references/images/configuration.md +17 -211
  84. package/skills/cloudflare/references/images/gotchas.md +16 -99
  85. package/skills/cloudflare/references/images/patterns.md +16 -115
  86. package/skills/cloudflare/references/kv/README.md +9 -83
  87. package/skills/cloudflare/references/kv/api.md +12 -154
  88. package/skills/cloudflare/references/kv/configuration.md +11 -139
  89. package/skills/cloudflare/references/kv/gotchas.md +15 -129
  90. package/skills/cloudflare/references/kv/patterns.md +15 -190
  91. package/skills/cloudflare/references/miniflare/README.md +15 -98
  92. package/skills/cloudflare/references/miniflare/api.md +16 -187
  93. package/skills/cloudflare/references/miniflare/configuration.md +12 -169
  94. package/skills/cloudflare/references/miniflare/gotchas.md +15 -160
  95. package/skills/cloudflare/references/miniflare/patterns.md +15 -177
  96. package/skills/cloudflare/references/network-interconnect/README.md +1 -1
  97. package/skills/cloudflare/references/network-interconnect/gotchas.md +1 -1
  98. package/skills/cloudflare/references/network-interconnect/patterns.md +1 -1
  99. package/skills/cloudflare/references/observability/README.md +20 -81
  100. package/skills/cloudflare/references/observability/api.md +20 -164
  101. package/skills/cloudflare/references/observability/configuration.md +18 -164
  102. package/skills/cloudflare/references/observability/gotchas.md +19 -109
  103. package/skills/cloudflare/references/observability/patterns.md +12 -103
  104. package/skills/cloudflare/references/pages/README.md +13 -81
  105. package/skills/cloudflare/references/pages/api.md +10 -201
  106. package/skills/cloudflare/references/pages/configuration.md +16 -201
  107. package/skills/cloudflare/references/pages/gotchas.md +13 -197
  108. package/skills/cloudflare/references/pages/patterns.md +11 -200
  109. package/skills/cloudflare/references/pages-functions/README.md +13 -91
  110. package/skills/cloudflare/references/pages-functions/api.md +10 -140
  111. package/skills/cloudflare/references/pages-functions/configuration.md +11 -119
  112. package/skills/cloudflare/references/pages-functions/gotchas.md +17 -94
  113. package/skills/cloudflare/references/pages-functions/patterns.md +12 -133
  114. package/skills/cloudflare/references/pipelines/README.md +1 -1
  115. package/skills/cloudflare/references/pulumi/README.md +2 -2
  116. package/skills/cloudflare/references/queues/README.md +15 -87
  117. package/skills/cloudflare/references/queues/api.md +10 -200
  118. package/skills/cloudflare/references/queues/configuration.md +18 -142
  119. package/skills/cloudflare/references/queues/gotchas.md +16 -204
  120. package/skills/cloudflare/references/queues/patterns.md +19 -218
  121. package/skills/cloudflare/references/r2/README.md +17 -86
  122. package/skills/cloudflare/references/r2/api.md +14 -198
  123. package/skills/cloudflare/references/r2/configuration.md +17 -163
  124. package/skills/cloudflare/references/r2/gotchas.md +15 -188
  125. package/skills/cloudflare/references/r2/patterns.md +16 -191
  126. package/skills/cloudflare/references/r2-data-catalog/README.md +11 -70
  127. package/skills/cloudflare/references/r2-data-catalog/api.md +14 -89
  128. package/skills/cloudflare/references/r2-data-catalog/configuration.md +15 -96
  129. package/skills/cloudflare/references/r2-data-catalog/gotchas.md +14 -51
  130. package/skills/cloudflare/references/r2-data-catalog/patterns.md +11 -116
  131. package/skills/cloudflare/references/realtime-sfu/README.md +1 -1
  132. package/skills/cloudflare/references/realtimekit/README.md +1 -1
  133. package/skills/cloudflare/references/secrets-store/README.md +14 -66
  134. package/skills/cloudflare/references/secrets-store/api.md +14 -193
  135. package/skills/cloudflare/references/secrets-store/configuration.md +16 -176
  136. package/skills/cloudflare/references/secrets-store/gotchas.md +14 -92
  137. package/skills/cloudflare/references/secrets-store/patterns.md +14 -194
  138. package/skills/cloudflare/references/smart-placement/README.md +2 -2
  139. package/skills/cloudflare/references/static-assets/README.md +15 -59
  140. package/skills/cloudflare/references/static-assets/api.md +12 -195
  141. package/skills/cloudflare/references/static-assets/configuration.md +16 -186
  142. package/skills/cloudflare/references/static-assets/gotchas.md +18 -162
  143. package/skills/cloudflare/references/static-assets/patterns.md +13 -185
  144. package/skills/cloudflare/references/stream/README.md +15 -107
  145. package/skills/cloudflare/references/stream/api-live.md +16 -193
  146. package/skills/cloudflare/references/stream/api.md +19 -197
  147. package/skills/cloudflare/references/stream/configuration.md +16 -139
  148. package/skills/cloudflare/references/stream/gotchas.md +16 -128
  149. package/skills/cloudflare/references/stream/patterns.md +20 -182
  150. package/skills/cloudflare/references/tail-workers/README.md +14 -82
  151. package/skills/cloudflare/references/tail-workers/api.md +10 -197
  152. package/skills/cloudflare/references/tail-workers/configuration.md +13 -174
  153. package/skills/cloudflare/references/tail-workers/gotchas.md +12 -188
  154. package/skills/cloudflare/references/tail-workers/patterns.md +11 -176
  155. package/skills/cloudflare/references/terraform/README.md +2 -2
  156. package/skills/cloudflare/references/tunnel/README.md +13 -122
  157. package/skills/cloudflare/references/tunnel/api.md +11 -190
  158. package/skills/cloudflare/references/tunnel/configuration.md +12 -155
  159. package/skills/cloudflare/references/tunnel/gotchas.md +12 -144
  160. package/skills/cloudflare/references/tunnel/networking.md +12 -166
  161. package/skills/cloudflare/references/tunnel/patterns.md +12 -189
  162. package/skills/cloudflare/references/vectorize/README.md +15 -126
  163. package/skills/cloudflare/references/vectorize/api.md +14 -84
  164. package/skills/cloudflare/references/vectorize/configuration.md +14 -83
  165. package/skills/cloudflare/references/vectorize/gotchas.md +12 -73
  166. package/skills/cloudflare/references/vectorize/patterns.md +17 -83
  167. package/skills/cloudflare/references/waf/README.md +15 -107
  168. package/skills/cloudflare/references/waf/api.md +17 -202
  169. package/skills/cloudflare/references/waf/configuration.md +14 -199
  170. package/skills/cloudflare/references/waf/gotchas.md +15 -200
  171. package/skills/cloudflare/references/waf/patterns.md +13 -193
  172. package/skills/cloudflare/references/workerd/README.md +2 -2
  173. package/skills/cloudflare/references/workers-ai/README.md +14 -187
  174. package/skills/cloudflare/references/workers-ai/api.md +10 -109
  175. package/skills/cloudflare/references/workers-ai/configuration.md +11 -92
  176. package/skills/cloudflare/references/workers-ai/gotchas.md +12 -111
  177. package/skills/cloudflare/references/workers-ai/patterns.md +9 -115
  178. package/skills/cloudflare/references/workers-for-platforms/README.md +3 -3
  179. package/skills/cloudflare/references/workers-vpc/README.md +1 -1
  180. package/skills/cloudflare/references/workflows/README.md +15 -69
  181. package/skills/cloudflare/references/workflows/api.md +12 -213
  182. package/skills/cloudflare/references/workflows/configuration.md +16 -150
  183. package/skills/cloudflare/references/workflows/gotchas.md +17 -88
  184. package/skills/cloudflare/references/workflows/patterns.md +19 -164
  185. package/skills/cloudflare-api-token/SKILL.md +1 -1
  186. package/skills/cloudflare-cf-cli/SKILL.md +44 -13
  187. package/skills/cloudflare-email-service/SKILL.md +6 -36
  188. package/skills/cloudflare-email-service/references/rest-api.md +12 -179
  189. package/skills/cloudflare-email-service/references/sending.md +17 -250
  190. package/skills/cloudflare-one/SKILL.md +4 -2
  191. package/skills/cloudflare-one-migrations/SKILL.md +1 -1
  192. package/skills/cloudflare-token-roll/SKILL.md +2 -5
  193. package/skills/durable-objects/SKILL.md +10 -16
  194. package/skills/durable-objects/references/rules.md +17 -293
  195. package/skills/durable-objects/references/testing.md +16 -257
  196. package/skills/nextjs-on-cloudflare/SKILL.md +33 -0
  197. package/skills/sandbox-migrate-to-next/SKILL.md +2 -2
  198. package/skills/sandbox-next/SKILL.md +3 -2
  199. package/skills/sandbox-next/references/api-quick-ref.md +15 -90
  200. package/skills/sandbox-stable/SKILL.md +1 -1
  201. package/skills/turnstile-spin/SKILL.md +14 -8
  202. package/skills/workers-best-practices/SKILL.md +36 -103
  203. package/skills/workers-best-practices/references/configuration.md +139 -0
  204. package/skills/workers-best-practices/references/platform-apis.md +51 -0
  205. package/skills/workers-best-practices/references/{rules.md → runtime-patterns.md} +9 -134
  206. package/skills/wrangler/SKILL.md +48 -901
  207. package/bin/setup.mjs +0 -119
  208. package/dist/api-token.d.ts +0 -12
  209. package/dist/api-token.d.ts.map +0 -1
  210. package/dist/api-token.js +0 -23
  211. package/dist/api-token.js.map +0 -1
  212. package/dist/auth-flow.d.ts +0 -15
  213. package/dist/auth-flow.d.ts.map +0 -1
  214. package/dist/auth-flow.js +0 -90
  215. package/dist/auth-flow.js.map +0 -1
  216. package/dist/client.d.ts +0 -18
  217. package/dist/client.d.ts.map +0 -1
  218. package/dist/client.js +0 -47
  219. package/dist/client.js.map +0 -1
  220. package/dist/config.d.ts +0 -20
  221. package/dist/config.d.ts.map +0 -1
  222. package/dist/config.js +0 -10
  223. package/dist/config.js.map +0 -1
  224. package/dist/index.d.ts +0 -22
  225. package/dist/index.d.ts.map +0 -1
  226. package/dist/index.js +0 -65
  227. package/dist/index.js.map +0 -1
  228. package/dist/mcp-server.d.ts +0 -2
  229. package/dist/mcp-server.d.ts.map +0 -1
  230. package/dist/mcp-server.js +0 -106
  231. package/dist/mcp-server.js.map +0 -1
  232. package/dist/oauth.d.ts +0 -44
  233. package/dist/oauth.d.ts.map +0 -1
  234. package/dist/oauth.js +0 -135
  235. package/dist/oauth.js.map +0 -1
  236. package/dist/proxy.d.ts +0 -30
  237. package/dist/proxy.d.ts.map +0 -1
  238. package/dist/proxy.js +0 -41
  239. package/dist/proxy.js.map +0 -1
  240. package/dist/result-caps.d.ts +0 -23
  241. package/dist/result-caps.d.ts.map +0 -1
  242. package/dist/result-caps.js +0 -75
  243. package/dist/result-caps.js.map +0 -1
  244. package/dist/runtime.d.ts +0 -72
  245. package/dist/runtime.d.ts.map +0 -1
  246. package/dist/runtime.js +0 -249
  247. package/dist/runtime.js.map +0 -1
  248. package/dist/servers.d.ts +0 -19
  249. package/dist/servers.d.ts.map +0 -1
  250. package/dist/servers.js +0 -40
  251. package/dist/servers.js.map +0 -1
  252. package/dist/token-store.d.ts +0 -32
  253. package/dist/token-store.d.ts.map +0 -1
  254. package/dist/token-store.js +0 -61
  255. package/dist/token-store.js.map +0 -1
  256. package/dist/tool-cache.d.ts +0 -25
  257. package/dist/tool-cache.d.ts.map +0 -1
  258. package/dist/tool-cache.js +0 -43
  259. package/dist/tool-cache.js.map +0 -1
  260. package/mcp.json +0 -15
  261. package/skills/cloudflare/references/agents-sdk/README.md +0 -89
  262. package/skills/cloudflare/references/agents-sdk/api.md +0 -190
  263. package/skills/cloudflare/references/agents-sdk/configuration.md +0 -182
  264. package/skills/cloudflare/references/agents-sdk/gotchas.md +0 -158
  265. package/skills/cloudflare/references/agents-sdk/patterns.md +0 -192
  266. package/skills/cloudflare/references/durable-objects/README.md +0 -185
  267. package/skills/cloudflare/references/durable-objects/api.md +0 -187
  268. package/skills/cloudflare/references/durable-objects/configuration.md +0 -160
  269. package/skills/cloudflare/references/durable-objects/gotchas.md +0 -197
  270. package/skills/cloudflare/references/durable-objects/patterns.md +0 -201
  271. package/skills/cloudflare/references/sandbox/README.md +0 -96
  272. package/skills/cloudflare/references/sandbox/api.md +0 -198
  273. package/skills/cloudflare/references/sandbox/configuration.md +0 -143
  274. package/skills/cloudflare/references/sandbox/gotchas.md +0 -194
  275. package/skills/cloudflare/references/sandbox/patterns.md +0 -201
  276. package/skills/cloudflare/references/turnstile/README.md +0 -99
  277. package/skills/cloudflare/references/turnstile/api.md +0 -240
  278. package/skills/cloudflare/references/turnstile/configuration.md +0 -222
  279. package/skills/cloudflare/references/turnstile/gotchas.md +0 -218
  280. package/skills/cloudflare/references/turnstile/patterns.md +0 -193
  281. package/skills/cloudflare/references/workers/README.md +0 -108
  282. package/skills/cloudflare/references/workers/api.md +0 -195
  283. package/skills/cloudflare/references/workers/configuration.md +0 -185
  284. package/skills/cloudflare/references/workers/frameworks.md +0 -197
  285. package/skills/cloudflare/references/workers/gotchas.md +0 -137
  286. package/skills/cloudflare/references/workers/patterns.md +0 -198
  287. package/skills/cloudflare/references/wrangler/README.md +0 -135
  288. package/skills/cloudflare/references/wrangler/api.md +0 -188
  289. package/skills/cloudflare/references/wrangler/configuration.md +0 -197
  290. package/skills/cloudflare/references/wrangler/gotchas.md +0 -197
  291. package/skills/cloudflare/references/wrangler/patterns.md +0 -209
  292. package/skills/cloudflare-auth-setup/SKILL.md +0 -59
  293. package/skills/workers-best-practices/references/review.md +0 -174
@@ -1,193 +1,18 @@
1
1
  # R2 Patterns & Best Practices
2
2
 
3
- ## Streaming Large Files
4
-
5
- ```typescript
6
- const object = await env.MY_BUCKET.get(key);
7
- if (!object) return new Response('Not found', { status: 404 });
8
-
9
- const headers = new Headers();
10
- object.writeHttpMetadata(headers);
11
- headers.set('etag', object.httpEtag);
12
-
13
- return new Response(object.body, { headers });
14
- ```
15
-
16
- ## Conditional GET (304 Not Modified)
17
-
18
- ```typescript
19
- const ifNoneMatch = request.headers.get('if-none-match');
20
- const object = await env.MY_BUCKET.get(key, {
21
- onlyIf: { etagDoesNotMatch: ifNoneMatch?.replace(/"/g, '') || '' }
22
- });
23
-
24
- if (!object) return new Response('Not found', { status: 404 });
25
- if (!object.body) return new Response(null, { status: 304, headers: { 'etag': object.httpEtag } });
26
-
27
- return new Response(object.body, { headers: { 'etag': object.httpEtag } });
28
- ```
29
-
30
- ## Upload with Validation
31
-
32
- ```typescript
33
- const key = url.pathname.slice(1);
34
- if (!key || key.includes('..')) return new Response('Invalid key', { status: 400 });
35
-
36
- const object = await env.MY_BUCKET.put(key, request.body, {
37
- httpMetadata: { contentType: request.headers.get('content-type') || 'application/octet-stream' },
38
- customMetadata: { uploadedAt: new Date().toISOString(), ip: request.headers.get('cf-connecting-ip') || 'unknown' }
39
- });
40
-
41
- return Response.json({ key: object.key, size: object.size, etag: object.httpEtag });
42
- ```
43
-
44
- ## Multipart with Progress
45
-
46
- ```typescript
47
- const PART_SIZE = 5 * 1024 * 1024; // 5MB
48
- const partCount = Math.ceil(file.size / PART_SIZE);
49
- const multipart = await env.MY_BUCKET.createMultipartUpload(key, { httpMetadata: { contentType: file.type } });
50
-
51
- const uploadedParts: R2UploadedPart[] = [];
52
- try {
53
- for (let i = 0; i < partCount; i++) {
54
- const start = i * PART_SIZE;
55
- const part = await multipart.uploadPart(i + 1, file.slice(start, start + PART_SIZE));
56
- uploadedParts.push(part);
57
- onProgress?.(Math.round(((i + 1) / partCount) * 100));
58
- }
59
- return await multipart.complete(uploadedParts);
60
- } catch (error) {
61
- await multipart.abort();
62
- throw error;
63
- }
64
- ```
65
-
66
- ## Batch Delete
67
-
68
- ```typescript
69
- async function deletePrefix(prefix: string, env: Env) {
70
- let cursor: string | undefined;
71
- let truncated = true;
72
-
73
- while (truncated) {
74
- const listed = await env.MY_BUCKET.list({ prefix, limit: 1000, cursor });
75
- if (listed.objects.length > 0) {
76
- await env.MY_BUCKET.delete(listed.objects.map(o => o.key));
77
- }
78
- truncated = listed.truncated;
79
- cursor = listed.cursor;
80
- }
81
- }
82
- ```
83
-
84
- ## Checksum Validation & Storage Transitions
85
-
86
- ```typescript
87
- // Upload with checksum
88
- const hash = await crypto.subtle.digest('SHA-256', data);
89
- await env.MY_BUCKET.put(key, data, { sha256: hash });
90
-
91
- // Transition storage class (requires S3 SDK)
92
- import { S3Client, CopyObjectCommand } from '@aws-sdk/client-s3';
93
- await s3.send(new CopyObjectCommand({
94
- Bucket: 'my-bucket', Key: key,
95
- CopySource: `/my-bucket/${key}`,
96
- StorageClass: 'STANDARD_IA'
97
- }));
98
- ```
99
-
100
- ## Client-Side Uploads (Presigned URLs)
101
-
102
- ```typescript
103
- import { S3Client } from '@aws-sdk/client-s3';
104
- import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
105
- import { PutObjectCommand } from '@aws-sdk/client-s3';
106
-
107
- // Worker: Generate presigned upload URL
108
- const s3 = new S3Client({
109
- region: 'auto',
110
- endpoint: `https://${env.ACCOUNT_ID}.r2.cloudflarestorage.com`,
111
- credentials: { accessKeyId: env.R2_ACCESS_KEY_ID, secretAccessKey: env.R2_SECRET_ACCESS_KEY }
112
- });
113
-
114
- const url = await getSignedUrl(s3, new PutObjectCommand({ Bucket: 'my-bucket', Key: key }), { expiresIn: 3600 });
115
- return Response.json({ uploadUrl: url });
116
-
117
- // Client: Upload directly
118
- const { uploadUrl } = await fetch('/api/upload-url').then(r => r.json());
119
- await fetch(uploadUrl, { method: 'PUT', body: file });
120
- ```
121
-
122
- ## Caching with Cache API
123
-
124
- ```typescript
125
- export default {
126
- async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
127
- const cache = caches.default;
128
- const url = new URL(request.url);
129
- const cacheKey = new Request(url.toString(), request);
130
-
131
- // Check cache first
132
- let response = await cache.match(cacheKey);
133
- if (response) return response;
134
-
135
- // Fetch from R2
136
- const key = url.pathname.slice(1);
137
- const object = await env.MY_BUCKET.get(key);
138
- if (!object) return new Response('Not found', { status: 404 });
139
-
140
- const headers = new Headers();
141
- object.writeHttpMetadata(headers);
142
- headers.set('etag', object.httpEtag);
143
- headers.set('cache-control', 'public, max-age=31536000, immutable');
144
-
145
- response = new Response(object.body, { headers });
146
-
147
- // Cache for subsequent requests
148
- ctx.waitUntil(cache.put(cacheKey, response.clone()));
149
-
150
- return response;
151
- }
152
- };
153
- ```
154
-
155
- ## Public Bucket with Custom Domain
156
-
157
- ```typescript
158
- export default {
159
- async fetch(request: Request, env: Env): Promise<Response> {
160
- // CORS preflight
161
- if (request.method === 'OPTIONS') {
162
- return new Response(null, {
163
- headers: {
164
- 'access-control-allow-origin': '*',
165
- 'access-control-allow-methods': 'GET, HEAD',
166
- 'access-control-max-age': '86400'
167
- }
168
- });
169
- }
170
-
171
- const key = new URL(request.url).pathname.slice(1);
172
- if (!key) return Response.redirect('/index.html', 302);
173
-
174
- const object = await env.MY_BUCKET.get(key);
175
- if (!object) return new Response('Not found', { status: 404 });
176
-
177
- const headers = new Headers();
178
- object.writeHttpMetadata(headers);
179
- headers.set('etag', object.httpEtag);
180
- headers.set('access-control-allow-origin', '*');
181
- headers.set('cache-control', 'public, max-age=31536000, immutable');
182
-
183
- return new Response(object.body, { headers });
184
- }
185
- };
186
- ```
187
-
188
- ## r2.dev Public URLs
189
-
190
- Enable r2.dev in dashboard for simple public access: `https://pub-${hashId}.r2.dev/${key}`
191
- Or add custom domain via dashboard: `https://files.example.com/${key}`
192
-
193
- **Limitations:** No auth, bucket-level CORS, no cache override.
3
+ Choose the access and delivery model, then fetch the implementation guide.
4
+
5
+ | Task | Current documentation |
6
+ |------|-----------------------|
7
+ | Stream object downloads or accept uploads through a Worker | [Use R2 from Workers](https://developers.cloudflare.com/r2/api/workers/workers-api-usage/) |
8
+ | Add conditional reads/writes, range handling, checksums, or batch deletion | [Workers API reference](https://developers.cloudflare.com/r2/api/workers/workers-api-reference/) |
9
+ | Upload large files with multipart state tracked by the client | [Multipart Worker and client example](https://developers.cloudflare.com/r2/api/workers/workers-multipart-usage/) |
10
+ | Upload directly from a browser or share a temporary download | [Presigned URLs](https://developers.cloudflare.com/r2/api/s3/presigned-urls/) and [CORS](https://developers.cloudflare.com/r2/buckets/cors/) |
11
+ | Cache responses served by a Worker | [Cache API example](https://developers.cloudflare.com/r2/examples/cache-api/) |
12
+ | Deliver public objects through a custom domain or evaluate r2.dev | [Public buckets](https://developers.cloudflare.com/r2/buckets/public-buckets/) |
13
+ | Process object changes asynchronously | [Event notifications](https://developers.cloudflare.com/r2/buckets/event-notifications/) and [Queues](../queues/) |
14
+ | Expire objects or transition storage classes | [Object lifecycles](https://developers.cloudflare.com/r2/buckets/object-lifecycles/) and [storage classes](https://developers.cloudflare.com/r2/buckets/storage-classes/) |
15
+
16
+ Authorize the caller for the selected object key and operation before exposing a Worker endpoint or issuing a presigned URL. A key-format check alone does not establish access rights. Set the intended expiry and signed request constraints for temporary access; configure browser CORS separately.
17
+
18
+ Keep private responses out of shared public caches. Choose cache keys and invalidation around the application's access model, and check [R2 consistency and caching behavior](https://developers.cloudflare.com/r2/reference/consistency/) when objects can change. For multipart uploads, plan for failed parts, completion, and cleanup using the linked guide.
@@ -1,75 +1,16 @@
1
- # Cloudflare R2 Data Catalog
1
+ # R2 Data Catalog
2
2
 
3
- Managed Apache Iceberg REST catalog built into R2 buckets. No catalog servers to run.
3
+ Use R2 Data Catalog for Iceberg analytics and data pipelines on object storage. For transactional application queries, consider a database; for unstructured objects, use [R2](../r2/).
4
4
 
5
- ## Documentation
5
+ Distinguish the Iceberg REST catalog used by query engines from Cloudflare's control-plane API for catalog administration. Start with the workflow you need:
6
6
 
7
- This reference is a fast-start with verified connection details and code. For limits, maintenance settings, engine config examples, and pricing, **retrieve the live docs** — use the Cloudflare MCP `docs` tool if available, otherwise `webfetch` the URL. Docs are source of truth over this file.
7
+ | Task | Reference |
8
+ |------|-----------|
9
+ | Enable a catalog, discover connection values, and choose credentials | [Configuration](configuration.md) |
10
+ | Select administration or engine APIs | [API selection](api.md) |
11
+ | Choose a Python, Spark, or SQL workflow | [Patterns](patterns.md) |
12
+ | Diagnose authentication, maintenance, or client problems | [Troubleshooting](gotchas.md) |
8
13
 
9
- | Topic | URL |
10
- |-------|-----|
11
- | Overview / get started | `https://developers.cloudflare.com/r2/data-catalog/get-started/` |
12
- | Manage catalogs (enable, tokens) | `https://developers.cloudflare.com/r2/data-catalog/manage-catalogs/` |
13
- | Engine config examples | `https://developers.cloudflare.com/r2/data-catalog/config-examples/` (`pyiceberg/`, `spark-python/`, `spark-scala/`, `duckdb/`, `snowflake/`, `trino/`, `starrocks/`) |
14
- | Table maintenance (compaction, snapshots) | `https://developers.cloudflare.com/r2/data-catalog/table-maintenance/` |
15
- | Deleting data | `https://developers.cloudflare.com/r2/data-catalog/deleting-data/` |
16
- | Metrics (GraphQL) | `https://developers.cloudflare.com/r2/data-catalog/observability/metrics/` |
17
- | Pricing | `https://developers.cloudflare.com/r2/data-catalog/platform/pricing/` |
18
- | Iceberg spec | `https://iceberg.apache.org/spec/` |
14
+ Copy the actual **Catalog URI** and **Warehouse name** from the catalog detail page or Wrangler's enable output. Pass both to the selected engine; do not reconstruct them from an assumed bucket naming convention. Retrieve [Manage catalogs](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/) before setup or permission changes.
19
15
 
20
- ## Connection Values
21
-
22
- Use the exact **Catalog URI** and **Warehouse** printed by `npx wrangler r2 bucket catalog enable <bucket>` (also shown in the dashboard). They follow these formats:
23
-
24
- | Value | Format | Example |
25
- |-------|--------|---------|
26
- | Catalog URI | `https://catalog.cloudflarestorage.com/{ACCOUNT_ID}/{BUCKET}` | `https://catalog.cloudflarestorage.com/4482a1.../live-data` |
27
- | Warehouse | `{ACCOUNT_ID}_{BUCKET}` (hyphens preserved) | `4482a1..._live-data` |
28
- | Token | R2 API token (Admin R&W on Storage + R&W on Data Catalog) | `cfut_...` |
29
-
30
- The Iceberg `/config` route needs `?warehouse={WAREHOUSE}`.
31
-
32
- ## Architecture
33
-
34
- ```
35
- Engines (PyIceberg, PySpark, Trino, Snowflake, DuckDB, R2 SQL)
36
- │ Iceberg REST API (Bearer token)
37
- ▼
38
- R2 Data Catalog ── namespace/table metadata, snapshots, txn coordination
39
- │ vended S3 credentials
40
- ▼
41
- R2 Bucket ── Parquet data files + Iceberg metadata
42
- ```
43
-
44
- - **Warehouse** — top-level catalog grouping (`{ACCOUNT_ID}_{BUCKET}`)
45
- - **Namespace** — schema/database; nested namespaces supported
46
- - **Table** — Iceberg table (schema, partition spec, snapshots)
47
- - **Vended credentials** — temp S3 creds the catalog hands engines (`X-Iceberg-Access-Delegation: vended-credentials`)
48
-
49
- ## When to Use
50
-
51
- **Use for:** log/analytics data lakes, BI pipelines, time-series/event data, multi-cloud or multi-engine analytics needing ACID + schema evolution on object storage.
52
-
53
- **Don't use for:** OLTP (use D1/a database), sub-second point lookups, tiny datasets (<1 GB), or unstructured blobs (store directly in R2).
54
-
55
- ## Two APIs — Don't Confuse Them
56
-
57
- | API | Base | Use for |
58
- |-----|------|---------|
59
- | **Iceberg REST catalog** | `https://catalog.cloudflarestorage.com/{ACCOUNT_ID}/{BUCKET}` | Table reads/writes via PyIceberg, PySpark, Trino, etc. |
60
- | **Control-plane REST API** | `https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/r2-catalog/{BUCKET}` | Enable/disable, maintenance config, list namespaces/tables, get-table |
61
-
62
- **Status:** Open beta. Available to all R2 subscribers; verify pricing/billing status in docs.
63
-
64
- ## Reading Order
65
-
66
- 1. [configuration.md](configuration.md) — enable catalog, tokens, maintenance, client connection
67
- 2. [api.md](api.md) — control-plane REST (incl. get-table), PyIceberg client, maintenance
68
- 3. [patterns.md](patterns.md) — PyIceberg + PySpark templates, partitioning, external engines
69
- 4. [gotchas.md](gotchas.md) — auth errors, maintenance behavior, troubleshooting
70
-
71
- ## See Also
72
-
73
- - [pipelines](../pipelines/) — stream events into Iceberg tables
74
- - [r2-sql](../r2-sql/) — serverless SQL over these tables
75
- - [r2](../r2/) — underlying object storage
16
+ Related workflows: [Pipelines](../pipelines/) for ingest and [R2 SQL](../r2-sql/) for querying tables.
@@ -1,44 +1,22 @@
1
- # R2 Data Catalog API Reference
1
+ # R2 Data Catalog API Selection
2
2
 
3
- Two APIs: the **control-plane REST API** (Cloudflare-specific) and the **Iceberg REST catalog API** (standard, used via PyIceberg/PySpark). For PyIceberg method details pull `https://py.iceberg.apache.org/`; for engine configs see `https://developers.cloudflare.com/r2/data-catalog/config-examples/`.
3
+ Use the Iceberg REST catalog through an engine for table reads and writes; use the Cloudflare control-plane API for catalog administration. Copy the catalog connection values from the actual environment as described in [configuration](configuration.md).
4
4
 
5
- ## Control-Plane REST API
5
+ | Task | Documentation |
6
+ |------|---------------|
7
+ | Enable or disable catalogs; inspect status, credentials, namespaces, tables, and maintenance configuration | [R2 Data Catalog control-plane API](https://developers.cloudflare.com/api/resources/r2_data_catalog/) — select the affected operation for its schema, pagination, and namespace encoding |
8
+ | Connect and create tables through Python | [PyIceberg configuration](https://developers.cloudflare.com/r2-data-catalog/config-examples/pyiceberg/) |
9
+ | Connect, create, write, and query through Spark | [PySpark configuration](https://developers.cloudflare.com/r2-data-catalog/config-examples/spark-python/) |
10
+ | Plan automatic compaction and snapshot expiration | [Table maintenance](https://developers.cloudflare.com/r2-data-catalog/table-maintenance/) |
11
+ | Delete rows, tables, or associated files | [Deleting data](https://developers.cloudflare.com/r2-data-catalog/deleting-data/) |
6
12
 
7
- Base: `https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/r2-catalog/{BUCKET}`
8
- Auth: `Authorization: Bearer $API_TOKEN`
13
+ For engine-specific operations beyond these Cloudflare examples, follow the upstream engine documentation linked from the relevant configuration guide and check the installed version. Do not infer engine method signatures from the control-plane API.
9
14
 
10
- | Operation | Method | Path |
11
- |-----------|--------|------|
12
- | Get catalog details | GET | `/r2-catalog/{bucket}` |
13
- | Enable / disable | POST | `/r2-catalog/{bucket}/enable` · `/disable` |
14
- | Store compaction credential | POST | `/r2-catalog/{bucket}/credential` |
15
- | List namespaces | GET | `/namespaces` |
16
- | List tables | GET | `/namespaces/{ns}/tables` |
17
- | **Get table metadata** | GET | `/namespaces/{ns}/tables/{table}` |
18
- | Get/update maintenance config | GET/POST | `/maintenance-configs` and `/namespaces/{ns}/tables/{table}/maintenance-configs` |
15
+ ## Get Table (repository-specific metadata introspection note)
19
16
 
20
- List endpoints accept `?return_uuids=true`, `?return_details=true`, `?parent={ns}`, and pagination. **Nested namespaces use `%1F` (Unit Separator)**, not `/` or `.`: `/namespaces/parent%1Fchild/tables`.
17
+ This existing repository note is retained because the published control-plane API reference does not document this operation or its snapshot-pruning response. Verify availability and response behavior against the target service or authoritative implementation before relying on it; it is not a documented API guarantee. Do not substitute the documented list-tables response for this metadata response.
21
18
 
22
- ```bash
23
- # Catalog details (status, maintenance_config, credential_status)
24
- curl -s "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/r2-catalog/$BUCKET" \
25
- -H "Authorization: Bearer $API_TOKEN"
26
-
27
- # Store token for compaction (pure-API setups)
28
- curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/r2-catalog/$BUCKET/credential" \
29
- -H "Authorization: Bearer $API_TOKEN" -H "Content-Type: application/json" \
30
- -d '{"token": "'$API_TOKEN'"}'
31
-
32
- # Update maintenance config (all fields optional; table-level overrides catalog-level)
33
- curl -s -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/r2-catalog/$BUCKET/maintenance-configs" \
34
- -H "Authorization: Bearer $API_TOKEN" -H "Content-Type: application/json" \
35
- -d '{"compaction": {"state": "enabled", "target_size_mb": "256"},
36
- "snapshot_expiration": {"state": "enabled", "min_snapshots_to_keep": 10, "max_snapshot_age": "7d"}}'
37
- ```
38
-
39
- ### Get Table (metadata introspection)
40
-
41
- `GET /namespaces/{ns}/tables/{table}` returns schema, partition spec, sort order, and snapshot info — like Iceberg "load table" but on the control plane, with snapshots pruned to the most recent 10. (Newer than the published API docs.)
19
+ `GET /namespaces/{ns}/tables/{table}` returns schema, partition spec, sort order, and snapshot info — like Iceberg "load table" but on the control plane, with snapshots pruned to the most recent 10.
42
20
 
43
21
  ```bash
44
22
  curl -s "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/r2-catalog/$BUCKET/namespaces/live/tables/earthquakes" \
@@ -66,57 +44,4 @@ curl -s "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/r2-catalog/$B
66
44
  | `returned_snapshots` | Count in `metadata.snapshots` (max 10) |
67
45
  | `metadata` | Standard [Iceberg TableMetadata](https://iceberg.apache.org/spec/#table-metadata-fields), arrays pruned to 10 |
68
46
 
69
- ### Error Format
70
-
71
- ```json
72
- {"success": false, "errors": [{"code": 10000, "message": "Authentication error"}]}
73
- ```
74
-
75
- Standard HTTP codes (401 auth, 403 perms, 404 not enabled/found, 409 conflict).
76
-
77
- ## Iceberg REST Catalog API (via PyIceberg)
78
-
79
- Standard [Iceberg REST Catalog](https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml). Base: `https://catalog.cloudflarestorage.com/{ACCOUNT_ID}/{BUCKET}`. The `/config` route needs `?warehouse={WAREHOUSE}`.
80
-
81
- ```python
82
- from pyiceberg.catalog.rest import RestCatalog
83
- catalog = RestCatalog(name="r2", warehouse=WAREHOUSE, uri=CATALOG_URI, token=TOKEN)
84
- ```
85
-
86
- Common operations (see PyIceberg docs for full signatures):
87
-
88
- ```python
89
- catalog.create_namespace_if_not_exists("logs")
90
- catalog.list_tables("logs")
91
- table = catalog.create_table(("logs", "events"), schema=schema) # pyiceberg.schema.Schema
92
- table = catalog.load_table(("logs", "events"))
93
- table.append(pyarrow_table) # also .overwrite(...)
94
- table.scan(row_filter="id > 100").to_pandas()
95
- ```
96
-
97
- Schema evolution (add nullable columns; widen types only):
98
- ```python
99
- with table.update_schema() as u:
100
- u.add_column("user_id", LongType(), doc="User ID")
101
- u.rename_column("msg", "message")
102
- ```
103
-
104
- Time-travel:
105
- ```python
106
- table.scan(snapshot_id=table.snapshots()[-2].snapshot_id)
107
- table.scan(as_of_timestamp=ms_epoch)
108
- ```
109
-
110
- ## Manual Maintenance (PySpark)
111
-
112
- Prefer automatic maintenance (control-plane API/wrangler). For manual control or very large tables, use Spark procedures (`rewrite_data_files`, `rewrite_manifests`, `expire_snapshots`, `remove_orphan_files`). See `https://developers.cloudflare.com/r2/data-catalog/table-maintenance/`.
113
-
114
- ```python
115
- spark.sql("CALL r2dc.system.rewrite_data_files(table => 'ns.tbl')")
116
- # Orphan removal REQUIRES S3 credentials (vended creds fail with NoAuthWithAWSException)
117
- spark.sql("CALL r2dc.system.remove_orphan_files(table => 'ns.tbl', older_than => TIMESTAMP '2026-02-28 00:00:00')")
118
- ```
119
-
120
- ## See Also
121
-
122
- - [configuration.md](configuration.md) · [patterns.md](patterns.md) · [gotchas.md](gotchas.md)
47
+ See [patterns](patterns.md) for engine selection and [troubleshooting](gotchas.md) for diagnosis.
@@ -1,98 +1,17 @@
1
1
  # R2 Data Catalog Configuration
2
2
 
3
- Enable the catalog, create tokens, turn on automatic maintenance, connect clients. For exhaustive token/permission options and maintenance settings, pull `https://developers.cloudflare.com/r2/data-catalog/manage-catalogs/` and `.../table-maintenance/`.
4
-
5
- ## Step 1: Create Bucket + Enable Catalog
6
-
7
- ```bash
8
- npx wrangler r2 bucket create my-bucket
9
- npx wrangler r2 bucket catalog enable my-bucket
10
- ```
11
-
12
- `enable` outputs the two values used everywhere:
13
-
14
- ```
15
- Warehouse: 4482a1cd43bf5197657ae1d8636c414a_my-bucket # {ACCOUNT_ID}_{BUCKET}
16
- Catalog URI: https://catalog.cloudflarestorage.com/4482a1cd43bf5197657ae1d8636c414a/my-bucket
17
- ```
18
-
19
- Enabling creates `__r2_data_catalog/` metadata in the bucket; existing objects are untouched.
20
-
21
- ## Step 2: Create an API Token
22
-
23
- Dashboard → **R2** → **Manage R2 API tokens** → **Create API token**.
24
-
25
- **Simplest:** one token with **R2 Storage Admin Read & Write** + **R2 Data Catalog Read & Write**, scoped to your bucket(s). Add **R2 SQL Read** if you also query. This token works for the Iceberg REST API, control-plane API, R2 SQL, and GraphQL Analytics. Token creation also yields S3 Access Key ID / Secret (needed only for Spark orphan-file removal).
26
-
27
- > Open-beta limitation: R2 Storage **Admin Write is required even for read-only data access**. See the manage-catalogs doc for the current permission matrix.
28
-
29
- ## Step 3: Enable Automatic Maintenance (Recommended)
30
-
31
- R2 Data Catalog runs compaction and snapshot expiration for you.
32
-
33
- ```bash
34
- # Compaction — merges small files (target size MB; default 128)
35
- npx wrangler r2 bucket catalog compaction enable my-bucket \
36
- --target-size 128 --token $API_TOKEN
37
-
38
- # Snapshot expiration — removes old snapshots AND their unreferenced data files
39
- npx wrangler r2 bucket catalog snapshot-expiration enable my-bucket \
40
- --token $API_TOKEN --older-than-days 7 --retain-last 10
41
- ```
42
-
43
- Compaction needs a **stored credential** to access files. `compaction enable` (and the dashboard wizard) stores it automatically; pure-API setups must call `/credential` (see [api.md](api.md)).
44
-
45
- > Compaction triggers **hourly** with **no hard throughput cap** (the former 2 GB/hour limit was lifted). Snapshot expiration deletes unreferenced data files automatically (since April 2026) — manual orphan cleanup is rarely needed. For target-size guidance per workload, see the table-maintenance doc.
46
-
47
- ## Step 4: Verify
48
-
49
- ```bash
50
- npx wrangler r2 bucket catalog status my-bucket
51
- # or control-plane API:
52
- curl -s "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/r2-catalog/$BUCKET" \
53
- -H "Authorization: Bearer $API_TOKEN"
54
- ```
55
-
56
- Expect `"status": "active"`, `compaction.state: "enabled"`, `credential_status: "present"`.
57
-
58
- ## Client Connection
59
-
60
- ### PyIceberg
61
-
62
- ```python
63
- import os
64
- from pyiceberg.catalog.rest import RestCatalog
65
-
66
- catalog = RestCatalog(
67
- name="r2_catalog",
68
- warehouse=os.environ["R2_WAREHOUSE"], # {ACCOUNT_ID}_{BUCKET}
69
- uri=os.environ["R2_CATALOG_URI"], # https://catalog.cloudflarestorage.com/{ACCOUNT_ID}/{BUCKET}
70
- token=os.environ["R2_TOKEN"],
71
- )
72
- print(catalog.list_namespaces()) # connection test
73
- ```
74
-
75
- ### PySpark / DuckDB / Trino / Snowflake
76
-
77
- Full, current engine configs live at `https://developers.cloudflare.com/r2/data-catalog/config-examples/`. A verified PySpark session template is in [patterns.md](patterns.md#pyspark-session) (needs Iceberg 1.6.1 and `X-Iceberg-Access-Delegation: vended-credentials`).
78
-
79
- ## Environment Variables Pattern
80
-
81
- ```bash
82
- # .env (never commit)
83
- R2_CATALOG_URI=https://catalog.cloudflarestorage.com/<ACCOUNT_ID>/<BUCKET>
84
- R2_WAREHOUSE=<ACCOUNT_ID>_<BUCKET>
85
- R2_TOKEN=<api-token>
86
- ```
87
-
88
- ## Disable Catalog
89
-
90
- ```bash
91
- npx wrangler r2 bucket catalog disable my-bucket
92
- ```
93
-
94
- Preserves data and metadata; tables become inaccessible via the catalog until re-enabled.
95
-
96
- ## See Also
97
-
98
- - [api.md](api.md) — control-plane + PyIceberg API · [gotchas.md](gotchas.md) — auth & maintenance troubleshooting
3
+ Inspect the existing bucket, catalog, engine versions, and credential configuration before making changes. Use the project's installed tools and preserve its environment-variable or secret-management conventions.
4
+
5
+ | Task | Documentation |
6
+ |------|---------------|
7
+ | Enable a catalog and obtain connection details | [Enable R2 Data Catalog](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/#enable-r2-data-catalog-on-a-bucket) |
8
+ | Select credentials for readers, writers, or maintenance | [Authenticate your Iceberg engine](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/#authenticate-your-iceberg-engine) |
9
+ | Configure compaction and its service credential | [Enable compaction](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/#enable-compaction) |
10
+ | Configure snapshot retention | [Enable snapshot expiration](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/#enable-snapshot-expiration) |
11
+ | Choose file sizes, retention policy, and maintenance scope | [Table maintenance](https://developers.cloudflare.com/r2-data-catalog/table-maintenance/) |
12
+ | Connect a Python client | [PyIceberg](https://developers.cloudflare.com/r2-data-catalog/config-examples/pyiceberg/) |
13
+ | Connect Spark | [PySpark](https://developers.cloudflare.com/r2-data-catalog/config-examples/spark-python/) |
14
+ | Connect another query engine | [Engine configuration guides](https://developers.cloudflare.com/r2-data-catalog/config-examples/) |
15
+ | Disable catalog access | [Disable R2 Data Catalog](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/#disable-r2-data-catalog-on-a-bucket) |
16
+
17
+ Copy the Catalog URI and Warehouse name exactly from the catalog detail page or Wrangler enable output. Scope both catalog and storage permissions to the operations the client needs; readers do not need a blanket write-enabled token. Treat maintenance credentials separately from reader credentials. Verify connectivity with a read operation before attempting writes, then check catalog and credential status through the [control-plane API](api.md).
@@ -1,55 +1,18 @@
1
- # R2 Data Catalog Gotchas
1
+ # R2 Data Catalog Troubleshooting
2
2
 
3
- Common failure modes and operational behavior. For limits, recommendations, and supported settings, pull `https://developers.cloudflare.com/r2/data-catalog/` and `.../table-maintenance/`.
3
+ Identify whether the failure occurs in catalog administration, engine metadata access, or underlying object access before changing permissions or client settings.
4
4
 
5
- ## Connection / Auth
5
+ | Check | Documentation |
6
+ |-------|---------------|
7
+ | Catalog enablement, Catalog URI, or Warehouse mismatch | [Manage catalogs](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/) |
8
+ | Reader/writer token scope or file-access denial | [Engine authentication](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/#authenticate-your-iceberg-engine) — inspect both catalog and storage permissions |
9
+ | Missing maintenance credentials or wrong table/catalog configuration | [Control-plane API](https://developers.cloudflare.com/api/resources/r2_data_catalog/) and [enable compaction](https://developers.cloudflare.com/r2-data-catalog/manage-catalogs/#enable-compaction) |
10
+ | Compaction backlog, retention, or orphaned files | [Table maintenance](https://developers.cloudflare.com/r2-data-catalog/table-maintenance/) |
11
+ | PyIceberg connection or table creation | [PyIceberg configuration](https://developers.cloudflare.com/r2-data-catalog/config-examples/pyiceberg/) |
12
+ | Spark dependency, credential-vending, or signing configuration | [PySpark configuration](https://developers.cloudflare.com/r2-data-catalog/config-examples/spark-python/) |
13
+ | Deleted data is still present | [Deleting data](https://developers.cloudflare.com/r2-data-catalog/deleting-data/) |
14
+ | Catalog request or maintenance-job diagnosis | [Metrics and analytics](https://developers.cloudflare.com/r2-data-catalog/observability/metrics/) |
6
15
 
7
- - **Catalog URI / warehouse mismatch (most common).** Copy both values exactly from `wrangler r2 bucket catalog enable` (Catalog URI `https://catalog.cloudflarestorage.com/{ACCOUNT_ID}/{BUCKET}`, warehouse `{ACCOUNT_ID}_{BUCKET}`). Mismatched values fail to connect.
8
- - **401 Unauthorized** — token lacks Data Catalog R&W. Test with `catalog.list_namespaces()`.
9
- - **403 on data files** — token lacks R2 Storage. Open beta requires **Admin Read & Write on R2 Storage even for read-only** data access.
10
- - **`/config` "Warehouse name missing in query param"** — the Iceberg `/v1/config` route needs `?warehouse={ACCOUNT_ID}_{BUCKET}`. PyIceberg/PySpark add it automatically when you set `warehouse=`.
16
+ Compare the client's configured URI and warehouse with the actual catalog values. Test a read operation first; do not grant write access merely to resolve a reader's failure. For schema or concurrency errors, inspect the installed engine's behavior and current table metadata before retrying. The [get-table note](api.md#get-table-repository-specific-metadata-introspection-note) is not a substitute for verifying the service's response contract.
11
17
 
12
- ## Maintenance Behavior (updated)
13
-
14
- - **No throughput cap on compaction.** The former 2 GB/hour/table limit is **lifted** — compaction triggers hourly and processes the backlog with no hard cap. Large small-file backlogs still take multiple hourly cycles.
15
- - **Snapshot expiration deletes data files** (since April 2026), not just metadata. Manual `remove_orphan_files` is rarely needed.
16
- - **Compaction requires a stored credential.** `wrangler ... compaction enable` and the dashboard wizard store it automatically; pure-API setups must POST `/credential`.
17
- - Compaction is **Parquet-only**.
18
-
19
- ## Tables & Schema
20
-
21
- - `TableAlreadyExistsError` / `NamespaceAlreadyExistsError` → use `create_*_if_not_exists` / load existing.
22
- - `422 Validation` on schema update → only add nullable columns and widen types (int→long, float→double).
23
- - `TypeError: Cannot cast` on append → PyArrow type ≠ Iceberg schema; cast to int64 (Iceberg default); check `table.schema()`.
24
-
25
- ## Concurrency
26
-
27
- - `CommitFailedException` → optimistic-locking conflict; retry with backoff (see [patterns.md](patterns.md#concurrent-writes-with-retry-pyiceberg)).
28
- - Stale metadata after external writes → reload: `table = catalog.load_table(("ns","tbl"))`.
29
-
30
- ## PySpark / Iceberg
31
-
32
- | Issue | Fix |
33
- |-------|-----|
34
- | Catalog auth fails | Add header `X-Iceberg-Access-Delegation: vended-credentials` |
35
- | `NoAuthWithAWSException` on orphan removal | Supply S3 access/secret keys (vended creds don't work here) |
36
- | Version mismatch | Use Iceberg `1.6.1` |
37
- | Slow first run (~30–60s) | JAR download; cached after |
38
- | Remote signing errors | Set `s3.remote-signing-enabled=false` |
39
-
40
- ## Nested Namespaces
41
-
42
- Control-plane URL separator for nested namespaces is **`%1F`** (Unit Separator), not `/` or `.`: `/namespaces/parent%1Fchild/tables`.
43
-
44
- ## Debug Checklist
45
-
46
- 1. `npx wrangler r2 bucket catalog status <bucket>` — enabled?
47
- 2. Token has R2 Storage (Admin R&W) + R2 Data Catalog (R&W)?
48
- 3. `catalog.list_namespaces()` succeeds?
49
- 4. Catalog URI = `catalog.cloudflarestorage.com/{ACCOUNT_ID}/{BUCKET}`, warehouse = `{ACCOUNT_ID}_{BUCKET}`?
50
- 5. Namespace created before `create_table`?
51
- 6. Compaction enabled + `credential_status: present`?
52
-
53
- ## See Also
54
-
55
- - [configuration.md](configuration.md) · [api.md](api.md) · [patterns.md](patterns.md)
18
+ See [configuration](configuration.md) and [patterns](patterns.md) for implementation choices.