alchemy 0.12.20 → 0.13.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.
Files changed (269) hide show
  1. package/lib/ai/client.d.ts.map +1 -1
  2. package/lib/ai/client.js +3 -5
  3. package/lib/ai/client.js.map +1 -1
  4. package/lib/alchemy.d.ts +2 -1
  5. package/lib/alchemy.d.ts.map +1 -1
  6. package/lib/alchemy.js +87 -92
  7. package/lib/alchemy.js.map +1 -1
  8. package/lib/apply.d.ts.map +1 -1
  9. package/lib/apply.js +6 -0
  10. package/lib/apply.js.map +1 -1
  11. package/lib/aws/bucket.d.ts.map +1 -1
  12. package/lib/aws/bucket.js +55 -57
  13. package/lib/aws/bucket.js.map +1 -1
  14. package/lib/aws/function.d.ts.map +1 -1
  15. package/lib/aws/function.js +250 -252
  16. package/lib/aws/function.js.map +1 -1
  17. package/lib/aws/policy-attachment.d.ts.map +1 -1
  18. package/lib/aws/policy-attachment.js +4 -6
  19. package/lib/aws/policy-attachment.js.map +1 -1
  20. package/lib/aws/policy.d.ts.map +1 -1
  21. package/lib/aws/policy.js +63 -65
  22. package/lib/aws/policy.js.map +1 -1
  23. package/lib/aws/queue.js +88 -90
  24. package/lib/aws/queue.js.map +1 -1
  25. package/lib/aws/table.d.ts.map +1 -1
  26. package/lib/aws/table.js +95 -99
  27. package/lib/aws/table.js.map +1 -1
  28. package/lib/cloudflare/account-api-token.d.ts +1 -1
  29. package/lib/cloudflare/account-api-token.d.ts.map +1 -1
  30. package/lib/cloudflare/account-api-token.js +0 -1
  31. package/lib/cloudflare/account-api-token.js.map +1 -1
  32. package/lib/cloudflare/ai-gateway.js.map +1 -1
  33. package/lib/cloudflare/ai.d.ts +1 -1
  34. package/lib/cloudflare/ai.d.ts.map +1 -1
  35. package/lib/cloudflare/ai.js.map +1 -1
  36. package/lib/cloudflare/api.js +1 -5
  37. package/lib/cloudflare/api.js.map +1 -1
  38. package/lib/cloudflare/bucket.d.ts +2 -2
  39. package/lib/cloudflare/bucket.d.ts.map +1 -1
  40. package/lib/cloudflare/bucket.js +22 -24
  41. package/lib/cloudflare/bucket.js.map +1 -1
  42. package/lib/cloudflare/bundle/hybrid-nodejs-compat.d.ts +0 -3
  43. package/lib/cloudflare/bundle/hybrid-nodejs-compat.d.ts.map +1 -1
  44. package/lib/cloudflare/bundle/hybrid-nodejs-compat.js +4 -7
  45. package/lib/cloudflare/bundle/hybrid-nodejs-compat.js.map +1 -1
  46. package/lib/cloudflare/custom-domain.d.ts.map +1 -1
  47. package/lib/cloudflare/custom-domain.js +3 -5
  48. package/lib/cloudflare/custom-domain.js.map +1 -1
  49. package/lib/cloudflare/d1-database.d.ts +1 -1
  50. package/lib/cloudflare/d1-database.d.ts.map +1 -1
  51. package/lib/cloudflare/d1-database.js +70 -72
  52. package/lib/cloudflare/d1-database.js.map +1 -1
  53. package/lib/cloudflare/d1-migrations.d.ts +1 -1
  54. package/lib/cloudflare/d1-migrations.d.ts.map +1 -1
  55. package/lib/cloudflare/d1-migrations.js +2 -3
  56. package/lib/cloudflare/d1-migrations.js.map +1 -1
  57. package/lib/cloudflare/dns-records.d.ts.map +1 -1
  58. package/lib/cloudflare/dns-records.js +2 -4
  59. package/lib/cloudflare/dns-records.js.map +1 -1
  60. package/lib/cloudflare/kv-namespace.d.ts +1 -1
  61. package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
  62. package/lib/cloudflare/kv-namespace.js +24 -27
  63. package/lib/cloudflare/kv-namespace.js.map +1 -1
  64. package/lib/cloudflare/pipeline.d.ts +1 -1
  65. package/lib/cloudflare/pipeline.d.ts.map +1 -1
  66. package/lib/cloudflare/pipeline.js +32 -34
  67. package/lib/cloudflare/pipeline.js.map +1 -1
  68. package/lib/cloudflare/queue-consumer.d.ts +1 -1
  69. package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
  70. package/lib/cloudflare/queue-consumer.js +31 -33
  71. package/lib/cloudflare/queue-consumer.js.map +1 -1
  72. package/lib/cloudflare/queue.d.ts +1 -1
  73. package/lib/cloudflare/queue.d.ts.map +1 -1
  74. package/lib/cloudflare/queue.js +36 -38
  75. package/lib/cloudflare/queue.js.map +1 -1
  76. package/lib/cloudflare/r2-rest-state-store.js +4 -8
  77. package/lib/cloudflare/r2-rest-state-store.js.map +1 -1
  78. package/lib/cloudflare/types.d.ts.map +1 -1
  79. package/lib/cloudflare/types.js +1 -3
  80. package/lib/cloudflare/types.js.map +1 -1
  81. package/lib/cloudflare/vectorize-index.d.ts.map +1 -1
  82. package/lib/cloudflare/vectorize-index.js +37 -39
  83. package/lib/cloudflare/vectorize-index.js.map +1 -1
  84. package/lib/cloudflare/vectorize-metadata-index.d.ts +1 -1
  85. package/lib/cloudflare/vectorize-metadata-index.d.ts.map +1 -1
  86. package/lib/cloudflare/vectorize-metadata-index.js +10 -13
  87. package/lib/cloudflare/vectorize-metadata-index.js.map +1 -1
  88. package/lib/cloudflare/worker.js +6 -12
  89. package/lib/cloudflare/worker.js.map +1 -1
  90. package/lib/cloudflare/workflow.d.ts +1 -1
  91. package/lib/cloudflare/workflow.d.ts.map +1 -1
  92. package/lib/cloudflare/workflow.js.map +1 -1
  93. package/lib/cloudflare/zone.d.ts.map +1 -1
  94. package/lib/cloudflare/zone.js +48 -50
  95. package/lib/cloudflare/zone.js.map +1 -1
  96. package/lib/dns/godaddy.js +1 -1
  97. package/lib/dns/import-dns.js +1 -1
  98. package/lib/dns/import-dns.js.map +1 -1
  99. package/lib/env.js +7 -9
  100. package/lib/env.js.map +1 -1
  101. package/lib/esbuild/bundle.js +8 -10
  102. package/lib/esbuild/bundle.js.map +1 -1
  103. package/lib/fs/copy-file.d.ts.map +1 -1
  104. package/lib/fs/copy-file.js +27 -29
  105. package/lib/fs/copy-file.js.map +1 -1
  106. package/lib/fs/file.d.ts +1 -1
  107. package/lib/fs/file.d.ts.map +1 -1
  108. package/lib/fs/file.js +1 -1
  109. package/lib/fs/file.js.map +1 -1
  110. package/lib/fs/folder.d.ts.map +1 -1
  111. package/lib/fs/folder.js +1 -3
  112. package/lib/fs/folder.js.map +1 -1
  113. package/lib/github/client.d.ts.map +1 -1
  114. package/lib/github/client.js +3 -5
  115. package/lib/github/client.js.map +1 -1
  116. package/lib/github/repository-environment.d.ts.map +1 -1
  117. package/lib/github/repository-environment.js +173 -176
  118. package/lib/github/repository-environment.js.map +1 -1
  119. package/lib/github/secret.d.ts.map +1 -1
  120. package/lib/github/secret.js +97 -99
  121. package/lib/github/secret.js.map +1 -1
  122. package/lib/internal/docs/providers.d.ts.map +1 -1
  123. package/lib/internal/docs/providers.js +5 -7
  124. package/lib/internal/docs/providers.js.map +1 -1
  125. package/lib/neon/api.js +1 -2
  126. package/lib/neon/api.js.map +1 -1
  127. package/lib/neon/project.js +2 -2
  128. package/lib/neon/project.js.map +1 -1
  129. package/lib/os/exec.d.ts +5 -0
  130. package/lib/os/exec.d.ts.map +1 -1
  131. package/lib/os/exec.js +88 -56
  132. package/lib/os/exec.js.map +1 -1
  133. package/lib/scope.d.ts +3 -0
  134. package/lib/scope.d.ts.map +1 -1
  135. package/lib/scope.js +10 -3
  136. package/lib/scope.js.map +1 -1
  137. package/lib/secret.d.ts.map +1 -1
  138. package/lib/secret.js +1 -3
  139. package/lib/secret.js.map +1 -1
  140. package/lib/serde.d.ts.map +1 -1
  141. package/lib/serde.js +13 -15
  142. package/lib/serde.js.map +1 -1
  143. package/lib/stripe/price.d.ts.map +1 -1
  144. package/lib/stripe/price.js +69 -73
  145. package/lib/stripe/price.js.map +1 -1
  146. package/lib/stripe/product.d.ts.map +1 -1
  147. package/lib/stripe/product.js +50 -52
  148. package/lib/stripe/product.js.map +1 -1
  149. package/lib/stripe/webhook.d.ts.map +1 -1
  150. package/lib/stripe/webhook.js +51 -53
  151. package/lib/stripe/webhook.js.map +1 -1
  152. package/lib/test/bun.d.ts +1 -1
  153. package/lib/test/bun.d.ts.map +1 -1
  154. package/lib/test/bun.js +1 -0
  155. package/lib/test/bun.js.map +1 -1
  156. package/lib/test/prune.d.ts.map +1 -1
  157. package/lib/test/prune.js.map +1 -1
  158. package/lib/util/dedent.js +4 -4
  159. package/lib/util/dedent.js.map +1 -1
  160. package/lib/web/astro.js +1 -1
  161. package/lib/web/shadcn.js +4 -4
  162. package/lib/web/shadcn.js.map +1 -1
  163. package/lib/web/tailwind.d.ts.map +1 -1
  164. package/lib/web/tailwind.js +0 -1
  165. package/lib/web/tailwind.js.map +1 -1
  166. package/lib/web/vite.js +3 -3
  167. package/lib/web/vitepress/home-page.d.ts.map +1 -1
  168. package/lib/web/vitepress/home-page.js +6 -8
  169. package/lib/web/vitepress/home-page.js.map +1 -1
  170. package/lib/web/vitepress/process-front-matter-files.js +1 -1
  171. package/lib/web/vitepress/process-front-matter-files.js.map +1 -1
  172. package/lib/web/vitepress/vitepress.js +2 -2
  173. package/lib/web/vitepress/vitepress.js.map +1 -1
  174. package/package.json +1 -1
  175. package/src/ai/astro-file.ts +4 -4
  176. package/src/ai/client.ts +4 -5
  177. package/src/ai/css-file.ts +4 -4
  178. package/src/ai/document.ts +3 -3
  179. package/src/ai/html-file.ts +4 -4
  180. package/src/ai/json-file.ts +1 -1
  181. package/src/ai/typescript-file.ts +4 -4
  182. package/src/ai/vue-file.ts +4 -4
  183. package/src/ai/yaml-file.ts +1 -1
  184. package/src/alchemy.ts +111 -104
  185. package/src/apply.ts +13 -5
  186. package/src/aws/bucket.ts +72 -75
  187. package/src/aws/function.ts +296 -297
  188. package/src/aws/oidc/github-oidc-provider.ts +1 -1
  189. package/src/aws/oidc/oidc-provider.ts +15 -15
  190. package/src/aws/policy-attachment.ts +10 -11
  191. package/src/aws/policy.ts +91 -94
  192. package/src/aws/queue.ts +111 -111
  193. package/src/aws/role.ts +24 -24
  194. package/src/aws/ses.ts +17 -17
  195. package/src/aws/table.ts +114 -115
  196. package/src/cloudflare/account-api-token.ts +11 -11
  197. package/src/cloudflare/account-id.ts +1 -1
  198. package/src/cloudflare/ai-gateway.ts +4 -4
  199. package/src/cloudflare/ai.ts +1 -1
  200. package/src/cloudflare/api-error.ts +1 -1
  201. package/src/cloudflare/api.ts +7 -11
  202. package/src/cloudflare/assets.ts +4 -4
  203. package/src/cloudflare/auth.ts +13 -13
  204. package/src/cloudflare/bucket.ts +62 -63
  205. package/src/cloudflare/bundle/hybrid-nodejs-compat.ts +14 -17
  206. package/src/cloudflare/custom-domain.ts +27 -28
  207. package/src/cloudflare/d1-database.ts +101 -102
  208. package/src/cloudflare/d1-migrations.ts +10 -10
  209. package/src/cloudflare/dns-records.ts +23 -24
  210. package/src/cloudflare/durable-object-namespace.ts +1 -1
  211. package/src/cloudflare/event-source.ts +1 -1
  212. package/src/cloudflare/hyperdrive.ts +3 -3
  213. package/src/cloudflare/kv-namespace.ts +36 -37
  214. package/src/cloudflare/nuxt.ts +1 -1
  215. package/src/cloudflare/permission-groups.ts +7 -7
  216. package/src/cloudflare/pipeline.ts +55 -56
  217. package/src/cloudflare/queue-consumer.ts +53 -54
  218. package/src/cloudflare/queue.ts +56 -57
  219. package/src/cloudflare/r2-rest-state-store.ts +11 -11
  220. package/src/cloudflare/redwood.ts +1 -1
  221. package/src/cloudflare/tanstack-start.ts +1 -1
  222. package/src/cloudflare/types.ts +1 -2
  223. package/src/cloudflare/vectorize-index.ts +60 -61
  224. package/src/cloudflare/vectorize-metadata-index.ts +25 -25
  225. package/src/cloudflare/vite.ts +1 -1
  226. package/src/cloudflare/website.ts +3 -3
  227. package/src/cloudflare/worker.ts +61 -61
  228. package/src/cloudflare/workflow.ts +4 -4
  229. package/src/cloudflare/wrangler.json.ts +4 -4
  230. package/src/cloudflare/zone.ts +69 -70
  231. package/src/destroy.ts +4 -4
  232. package/src/dns/godaddy.ts +1 -1
  233. package/src/dns/import-dns.ts +5 -5
  234. package/src/encrypt.ts +6 -6
  235. package/src/env.ts +10 -10
  236. package/src/esbuild/bundle.ts +14 -14
  237. package/src/fs/copy-file.ts +35 -36
  238. package/src/fs/file-system-state-store.ts +4 -4
  239. package/src/fs/file.ts +9 -8
  240. package/src/fs/folder.ts +6 -7
  241. package/src/github/client.ts +15 -14
  242. package/src/github/repository-environment.ts +206 -210
  243. package/src/github/secret.ts +111 -116
  244. package/src/internal/docs/providers.ts +16 -17
  245. package/src/neon/api-error.ts +1 -1
  246. package/src/neon/api.ts +6 -6
  247. package/src/neon/project.ts +18 -17
  248. package/src/os/exec.ts +107 -66
  249. package/src/resource.ts +3 -3
  250. package/src/scope.ts +14 -4
  251. package/src/secret.ts +2 -3
  252. package/src/serde.ts +30 -22
  253. package/src/stripe/price.ts +74 -77
  254. package/src/stripe/product.ts +55 -56
  255. package/src/stripe/webhook.ts +56 -57
  256. package/src/test/bun.ts +7 -6
  257. package/src/test/prune.ts +4 -4
  258. package/src/util/dedent.ts +4 -4
  259. package/src/web/astro.ts +10 -10
  260. package/src/web/shadcn-component.ts +4 -4
  261. package/src/web/shadcn.ts +10 -10
  262. package/src/web/tailwind.ts +2 -3
  263. package/src/web/vite.ts +11 -11
  264. package/src/web/vitepress/config.ts +2 -2
  265. package/src/web/vitepress/custom-theme.ts +7 -7
  266. package/src/web/vitepress/dependencies.ts +4 -4
  267. package/src/web/vitepress/home-page.ts +8 -9
  268. package/src/web/vitepress/process-front-matter-files.ts +5 -5
  269. package/src/web/vitepress/vitepress.ts +7 -7
@@ -1,7 +1,7 @@
1
1
  import * as fs from "node:fs/promises";
2
2
  import * as path from "node:path";
3
3
  import { handleApiError } from "./api-error.js";
4
- import { CloudflareApi } from "./api.js";
4
+ import type { CloudflareApi } from "./api.js";
5
5
 
6
6
  export interface D1MigrationOptions {
7
7
  migrationsFiles: Array<{ id: string; sql: string }>;
@@ -13,8 +13,8 @@ export interface D1MigrationOptions {
13
13
 
14
14
  const getPrefix = (name: string) => {
15
15
  const prefix = name.split("_")[0];
16
- const num = parseInt(prefix, 10);
17
- return isNaN(num) ? null : num;
16
+ const num = Number.parseInt(prefix, 10);
17
+ return Number.isNaN(num) ? null : num;
18
18
  };
19
19
 
20
20
  async function readMigrationFile(filePath: string): Promise<string> {
@@ -26,7 +26,7 @@ async function readMigrationFile(filePath: string): Promise<string> {
26
26
  * @param migrationsDir Directory containing .sql migration files
27
27
  */
28
28
  export async function listMigrationsFiles(
29
- migrationsDir: string
29
+ migrationsDir: string,
30
30
  ): Promise<Array<{ id: string; sql: string }>> {
31
31
  const entries = await fs.readdir(migrationsDir);
32
32
 
@@ -56,7 +56,7 @@ export async function listMigrationsFiles(
56
56
  * Ensures the migrations table exists in the D1 database.
57
57
  */
58
58
  export async function ensureMigrationsTable(
59
- options: D1MigrationOptions
59
+ options: D1MigrationOptions,
60
60
  ): Promise<void> {
61
61
  const createTableSQL = `CREATE TABLE IF NOT EXISTS ${options.migrationsTable} (id TEXT PRIMARY KEY, applied_at TEXT);`;
62
62
 
@@ -67,7 +67,7 @@ export async function ensureMigrationsTable(
67
67
  * Gets the list of applied migration IDs from the migrations table.
68
68
  */
69
69
  export async function getAppliedMigrations(
70
- options: D1MigrationOptions
70
+ options: D1MigrationOptions,
71
71
  ): Promise<Set<string>> {
72
72
  const sql = `SELECT id FROM ${options.migrationsTable};`;
73
73
 
@@ -82,7 +82,7 @@ export async function getAppliedMigrations(
82
82
  */
83
83
  export async function executeD1SQL(
84
84
  options: D1MigrationOptions,
85
- sql: string
85
+ sql: string,
86
86
  ): Promise<{
87
87
  result: [
88
88
  {
@@ -97,7 +97,7 @@ export async function executeD1SQL(
97
97
  }> {
98
98
  const response = await options.api.post(
99
99
  `/accounts/${options.accountId}/d1/database/${options.databaseId}/query`,
100
- { sql }
100
+ { sql },
101
101
  );
102
102
 
103
103
  if (!response.ok) {
@@ -105,7 +105,7 @@ export async function executeD1SQL(
105
105
  response,
106
106
  "executing migration SQL",
107
107
  "D1 database",
108
- options.databaseId
108
+ options.databaseId,
109
109
  );
110
110
  }
111
111
 
@@ -116,7 +116,7 @@ export async function executeD1SQL(
116
116
  * Applies all pending migrations from the provided files to the D1 database.
117
117
  */
118
118
  export async function applyMigrations(
119
- options: D1MigrationOptions
119
+ options: D1MigrationOptions,
120
120
  ): Promise<void> {
121
121
  await ensureMigrationsTable(options);
122
122
  const applied = await getAppliedMigrations(options);
@@ -128,7 +128,7 @@ export const DnsRecords = Resource(
128
128
  async function (
129
129
  this: Context<DnsRecords>,
130
130
  id: string,
131
- props: DnsRecordsProps
131
+ props: DnsRecordsProps,
132
132
  ): Promise<DnsRecords> {
133
133
  // Create Cloudflare API client
134
134
  const api = await createCloudflareApi(props);
@@ -143,17 +143,17 @@ export const DnsRecords = Resource(
143
143
  this.output.records.map(async (record) => {
144
144
  try {
145
145
  const response = await api.delete(
146
- `/zones/${zoneId}/dns_records/${record.id}`
146
+ `/zones/${zoneId}/dns_records/${record.id}`,
147
147
  );
148
148
  if (!response.ok && response.status !== 404) {
149
149
  console.error(
150
- `Failed to delete DNS record ${record.name}: ${response.statusText}`
150
+ `Failed to delete DNS record ${record.name}: ${response.statusText}`,
151
151
  );
152
152
  }
153
153
  } catch (error) {
154
154
  console.error(`Error deleting DNS record ${record.name}:`, error);
155
155
  }
156
- })
156
+ }),
157
157
  );
158
158
  }
159
159
  return this.destroy();
@@ -169,8 +169,8 @@ export const DnsRecords = Resource(
169
169
  (current) =>
170
170
  !desiredRecords.some(
171
171
  (desired) =>
172
- desired.name === current.name && desired.type === current.type
173
- )
172
+ desired.name === current.name && desired.type === current.type,
173
+ ),
174
174
  );
175
175
 
176
176
  // Delete orphaned records
@@ -178,17 +178,17 @@ export const DnsRecords = Resource(
178
178
  recordsToDelete.map(async (record) => {
179
179
  try {
180
180
  const response = await api.delete(
181
- `/zones/${zoneId}/dns_records/${record.id}`
181
+ `/zones/${zoneId}/dns_records/${record.id}`,
182
182
  );
183
183
  if (!response.ok && response.status !== 404) {
184
184
  console.error(
185
- `Failed to delete DNS record ${record.name}: ${response.statusText}`
185
+ `Failed to delete DNS record ${record.name}: ${response.statusText}`,
186
186
  );
187
187
  }
188
188
  } catch (error) {
189
189
  console.error(`Error deleting DNS record ${record.name}:`, error);
190
190
  }
191
- })
191
+ }),
192
192
  );
193
193
 
194
194
  // Update or create records
@@ -197,7 +197,7 @@ export const DnsRecords = Resource(
197
197
  // Find matching existing record
198
198
  const existing = currentRecords.find(
199
199
  (current) =>
200
- current.name === desired.name && current.type === desired.type
200
+ current.name === desired.name && current.type === desired.type,
201
201
  );
202
202
 
203
203
  if (existing) {
@@ -212,11 +212,10 @@ export const DnsRecords = Resource(
212
212
  return createOrUpdateRecord(api, zoneId, desired, existing.id);
213
213
  }
214
214
  return existing;
215
- } else {
216
- // Create new record
217
- return createOrUpdateRecord(api, zoneId, desired);
218
215
  }
219
- })
216
+ // Create new record
217
+ return createOrUpdateRecord(api, zoneId, desired);
218
+ }),
220
219
  );
221
220
 
222
221
  return this({
@@ -246,18 +245,18 @@ export const DnsRecords = Resource(
246
245
  acc[key] = record;
247
246
  return acc;
248
247
  },
249
- {} as Record<string, DnsRecordProps>
248
+ {} as Record<string, DnsRecordProps>,
250
249
  );
251
250
 
252
251
  const createdRecords = await Promise.all(
253
252
  Object.values(uniqueRecords).map(async (record) => {
254
253
  // First check if record exists
255
254
  const listResponse = await api.get(
256
- `/zones/${zoneId}/dns_records?type=${record.type}&name=${record.name}`
255
+ `/zones/${zoneId}/dns_records?type=${record.type}&name=${record.name}`,
257
256
  );
258
257
  if (!listResponse.ok) {
259
258
  throw new Error(
260
- `Failed to check existing DNS records: ${listResponse.statusText}`
259
+ `Failed to check existing DNS records: ${listResponse.statusText}`,
261
260
  );
262
261
  }
263
262
 
@@ -267,14 +266,14 @@ export const DnsRecords = Resource(
267
266
  const existingRecord = listResult.result[0];
268
267
 
269
268
  return createOrUpdateRecord(api, zoneId, record, existingRecord?.id);
270
- })
269
+ }),
271
270
  );
272
271
 
273
272
  return this({
274
273
  zoneId,
275
274
  records: createdRecords,
276
275
  });
277
- }
276
+ },
278
277
  );
279
278
 
280
279
  /**
@@ -284,7 +283,7 @@ async function createOrUpdateRecord(
284
283
  api: CloudflareApi,
285
284
  zoneId: string,
286
285
  record: DnsRecordProps,
287
- existingId?: string
286
+ existingId?: string,
288
287
  ): Promise<DnsRecord> {
289
288
  const payload = getRecordPayload(record);
290
289
 
@@ -300,12 +299,12 @@ async function createOrUpdateRecord(
300
299
  try {
301
300
  const createResponse = await api.post(
302
301
  `/zones/${zoneId}/dns_records`,
303
- payload
302
+ payload,
304
303
  );
305
304
  if (createResponse.ok) {
306
305
  return convertCloudflareRecord(
307
306
  ((await createResponse.json()) as any).result,
308
- zoneId
307
+ zoneId,
309
308
  );
310
309
  }
311
310
  } catch (err) {
@@ -314,7 +313,7 @@ async function createOrUpdateRecord(
314
313
  }
315
314
 
316
315
  throw new Error(
317
- `Failed to ${existingId ? "update" : "create"} DNS record ${record.name}: ${response.statusText}\nResponse: ${errorBody}`
316
+ `Failed to ${existingId ? "update" : "create"} DNS record ${record.name}: ${response.statusText}\nResponse: ${errorBody}`,
318
317
  );
319
318
  }
320
319
 
@@ -343,7 +342,7 @@ function getRecordPayload(record: DnsRecordProps) {
343
342
  */
344
343
  function convertCloudflareRecord(
345
344
  record: CloudflareDnsRecord,
346
- zoneId: string
345
+ zoneId: string,
347
346
  ): DnsRecord {
348
347
  return {
349
348
  id: record.id,
@@ -42,7 +42,7 @@ export class DurableObjectNamespace implements DurableObjectNamespaceInput {
42
42
 
43
43
  constructor(
44
44
  public readonly id: string,
45
- input: DurableObjectNamespaceInput
45
+ input: DurableObjectNamespaceInput,
46
46
  ) {
47
47
  this.className = input.className;
48
48
  this.scriptName = input.scriptName;
@@ -27,7 +27,7 @@ export interface QueueEventSource {
27
27
  * @returns true if the event source is a QueueEventSource, false otherwise
28
28
  */
29
29
  export function isQueueEventSource(
30
- eventSource: any
30
+ eventSource: any,
31
31
  ): eventSource is QueueEventSource {
32
32
  return "queue" in eventSource;
33
33
  }
@@ -247,7 +247,7 @@ export const Hyperdrive = Resource(
247
247
  async function (
248
248
  this: Context<Hyperdrive>,
249
249
  id: string,
250
- props: HyperdriveProps
250
+ props: HyperdriveProps,
251
251
  ): Promise<Hyperdrive> {
252
252
  const api = await createCloudflareApi(props);
253
253
  const configsPath = `/accounts/${api.accountId}/hyperdrive/configs`;
@@ -297,7 +297,7 @@ export const Hyperdrive = Resource(
297
297
  if (getResponse.status === 200) {
298
298
  // Hyperdrive exists, update it
299
299
  console.log(
300
- `Hyperdrive '${id}' already exists. Updating existing resource.`
300
+ `Hyperdrive '${id}' already exists. Updating existing resource.`,
301
301
  );
302
302
  response = await api.put(configPath, requestBody);
303
303
  } else if (getResponse.status === 404) {
@@ -343,7 +343,7 @@ export const Hyperdrive = Resource(
343
343
  mtls: apiResource.mtls,
344
344
  type: "hyperdrive",
345
345
  });
346
- }
346
+ },
347
347
  );
348
348
 
349
349
  /**
@@ -3,7 +3,7 @@ import { Resource } from "../resource.js";
3
3
  import { withExponentialBackoff } from "../util/retry.js";
4
4
  import { handleApiError } from "./api-error.js";
5
5
  import {
6
- CloudflareApi,
6
+ type CloudflareApi,
7
7
  createCloudflareApi,
8
8
  type CloudflareApiOptions,
9
9
  } from "./api.js";
@@ -118,7 +118,7 @@ export const KVNamespace = Resource(
118
118
  async function (
119
119
  this: Context<KVNamespace>,
120
120
  id: string,
121
- props: KVNamespaceProps
121
+ props: KVNamespaceProps,
122
122
  ) {
123
123
  // Create Cloudflare API client with automatic account discovery
124
124
  const api = await createCloudflareApi(props);
@@ -132,48 +132,47 @@ export const KVNamespace = Resource(
132
132
 
133
133
  // Return minimal output for deleted state
134
134
  return this.destroy();
135
+ }
136
+ // For create or update operations
137
+ // If this.phase is "update", we expect this.output to exist
138
+ let namespaceId =
139
+ this.phase === "update" ? this.output?.namespaceId || "" : "";
140
+ let createdAt =
141
+ this.phase === "update"
142
+ ? this.output?.createdAt || Date.now()
143
+ : Date.now();
144
+
145
+ if (this.phase === "update" && namespaceId) {
146
+ // Can't update a KV namespace title directly, just work with existing ID
135
147
  } else {
136
- // For create or update operations
137
- // If this.phase is "update", we expect this.output to exist
138
- let namespaceId =
139
- this.phase === "update" ? this.output?.namespaceId || "" : "";
140
- let createdAt =
141
- this.phase === "update"
142
- ? this.output?.createdAt || Date.now()
143
- : Date.now();
144
-
145
- if (this.phase === "update" && namespaceId) {
146
- // Can't update a KV namespace title directly, just work with existing ID
147
- } else {
148
- // TODO: if it already exists, then check the tags to see if we own it and continue
149
- const { id } = await createKVNamespace(api, props);
150
- createdAt = Date.now();
151
- namespaceId = id;
152
- }
148
+ // TODO: if it already exists, then check the tags to see if we own it and continue
149
+ const { id } = await createKVNamespace(api, props);
150
+ createdAt = Date.now();
151
+ namespaceId = id;
152
+ }
153
153
 
154
- await insertKVRecords(api, namespaceId, props);
154
+ await insertKVRecords(api, namespaceId, props);
155
155
 
156
- return this({
157
- type: "kv_namespace",
158
- namespaceId: namespaceId,
159
- title: props.title,
160
- values: props.values,
161
- createdAt: createdAt,
162
- modifiedAt: Date.now(),
163
- });
164
- }
165
- }
156
+ return this({
157
+ type: "kv_namespace",
158
+ namespaceId: namespaceId,
159
+ title: props.title,
160
+ values: props.values,
161
+ createdAt: createdAt,
162
+ modifiedAt: Date.now(),
163
+ });
164
+ },
166
165
  );
167
166
 
168
167
  export async function createKVNamespace(
169
168
  api: CloudflareApi,
170
- props: KVNamespaceProps
169
+ props: KVNamespaceProps,
171
170
  ): Promise<{ id: string }> {
172
171
  const createResponse = await api.post(
173
172
  `/accounts/${api.accountId}/storage/kv/namespaces`,
174
173
  {
175
174
  title: props.title,
176
- }
175
+ },
177
176
  );
178
177
 
179
178
  if (!createResponse.ok) {
@@ -185,11 +184,11 @@ export async function createKVNamespace(
185
184
 
186
185
  export async function deleteKVNamespace(
187
186
  api: CloudflareApi,
188
- namespaceId: string
187
+ namespaceId: string,
189
188
  ) {
190
189
  // Delete KV namespace
191
190
  const deleteResponse = await api.delete(
192
- `/accounts/${api.accountId}/storage/kv/namespaces/${namespaceId}`
191
+ `/accounts/${api.accountId}/storage/kv/namespaces/${namespaceId}`,
193
192
  );
194
193
 
195
194
  if (!deleteResponse.ok && deleteResponse.status !== 404) {
@@ -200,7 +199,7 @@ export async function deleteKVNamespace(
200
199
  export async function insertKVRecords(
201
200
  api: CloudflareApi,
202
201
  namespaceId: string,
203
- props: KVNamespaceProps
202
+ props: KVNamespaceProps,
204
203
  ) {
205
204
  if (props.values && props.values.length > 0) {
206
205
  // Process KV pairs in batches of 10000 (API limit)
@@ -238,7 +237,7 @@ export async function insertKVRecords(
238
237
  async () => {
239
238
  const bulkResponse = await api.put(
240
239
  `/accounts/${api.accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
241
- bulkPayload
240
+ bulkPayload,
242
241
  );
243
242
 
244
243
  if (!bulkResponse.ok) {
@@ -259,7 +258,7 @@ export async function insertKVRecords(
259
258
  return error.message?.includes("not found");
260
259
  },
261
260
  5, // 5 retry attempts
262
- 1000 // Start with 1 second delay
261
+ 1000, // Start with 1 second delay
263
262
  );
264
263
  } catch (error: any) {
265
264
  console.warn(error.message);
@@ -47,7 +47,7 @@ export type Nuxt<B extends Bindings> = B extends { ASSETS: any }
47
47
  */
48
48
  export async function Nuxt<B extends Bindings>(
49
49
  id: string,
50
- props?: Partial<NuxtProps<B>>
50
+ props?: Partial<NuxtProps<B>>,
51
51
  ): Promise<Nuxt<B>> {
52
52
  // Call the underlying Website resource with Nuxt defaults
53
53
  return Website(id, {
@@ -103,7 +103,7 @@ export const PermissionGroups = Resource(
103
103
  async function (
104
104
  this: Context<PermissionGroups>,
105
105
  id: string,
106
- options: CloudflareApiOptions = {}
106
+ options: CloudflareApiOptions = {},
107
107
  ): Promise<PermissionGroups> {
108
108
  // Only create and update phases are supported
109
109
  if (this.phase === "delete") {
@@ -115,12 +115,12 @@ export const PermissionGroups = Resource(
115
115
 
116
116
  // Fetch permission groups from Cloudflare API
117
117
  const response = await api.get(
118
- `/accounts/${api.accountId}/tokens/permission_groups`
118
+ `/accounts/${api.accountId}/tokens/permission_groups`,
119
119
  );
120
120
 
121
121
  if (!response.ok) {
122
122
  throw new Error(
123
- `Failed to fetch permission groups: ${response.statusText}`
123
+ `Failed to fetch permission groups: ${response.statusText}`,
124
124
  );
125
125
  }
126
126
 
@@ -128,14 +128,14 @@ export const PermissionGroups = Resource(
128
128
 
129
129
  if (!data.success || !data.result) {
130
130
  throw new Error(
131
- `API returned error: ${data.errors?.[0]?.message || "Unknown error"}`
131
+ `API returned error: ${data.errors?.[0]?.message || "Unknown error"}`,
132
132
  );
133
133
  }
134
134
 
135
135
  return this(
136
136
  Object.fromEntries(
137
- data.result.map((group) => [group.name, group])
138
- ) as PermissionGroups
137
+ data.result.map((group) => [group.name, group]),
138
+ ) as PermissionGroups,
139
139
  );
140
- }
140
+ },
141
141
  );