alchemy 0.12.21 → 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 +3 -4
  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 +13 -14
  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,13 +1,13 @@
1
- /**
2
- * Copied from https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts#L17
3
- */
4
-
5
1
  import type { Plugin, PluginBuild } from "esbuild";
6
2
  import assert from "node:assert";
7
3
  import { builtinModules } from "node:module";
8
4
  import nodePath from "node:path";
9
5
  import { dedent } from "../../util/dedent.js";
10
6
 
7
+ /**
8
+ * Copied from https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/deployment-bundle/esbuild-plugins/hybrid-nodejs-compat.ts#L17
9
+ */
10
+
11
11
  const REQUIRED_NODE_BUILT_IN_NAMESPACE = "node-built-in-modules";
12
12
  const REQUIRED_UNENV_ALIAS_NAMESPACE = "required-unenv-alias";
13
13
 
@@ -56,7 +56,7 @@ function errorOnServiceWorkerFormat(build: PluginBuild) {
56
56
  const pathList = new Intl.ListFormat("en-US").format(
57
57
  Array.from(paths.keys())
58
58
  .map((p) => `"${p}"`)
59
- .sort()
59
+ .sort(),
60
60
  );
61
61
  return {
62
62
  errors: [
@@ -98,7 +98,7 @@ function handleRequireCallsToNodeJSBuiltins(build: PluginBuild) {
98
98
  module.exports = libDefault;`,
99
99
  loader: "js",
100
100
  };
101
- }
101
+ },
102
102
  );
103
103
  }
104
104
 
@@ -112,7 +112,7 @@ function handleRequireCallsToNodeJSBuiltins(build: PluginBuild) {
112
112
  function handleUnenvAliasedPackages(
113
113
  build: PluginBuild,
114
114
  alias: Record<string, string>,
115
- external: readonly string[]
115
+ external: readonly string[],
116
116
  ) {
117
117
  // esbuild expects alias paths to be absolute
118
118
  const aliasAbsolute: Record<string, string> = {};
@@ -125,7 +125,7 @@ function handleUnenvAliasedPackages(
125
125
  }
126
126
 
127
127
  const UNENV_ALIAS_RE = new RegExp(
128
- `^(${Object.keys(aliasAbsolute).join("|")})$`
128
+ `^(${Object.keys(aliasAbsolute).join("|")})$`,
129
129
  );
130
130
 
131
131
  build.onResolve({ filter: UNENV_ALIAS_RE }, (args) => {
@@ -164,7 +164,7 @@ function handleUnenvAliasedPackages(
164
164
  );`,
165
165
  loader: "js",
166
166
  };
167
- }
167
+ },
168
168
  );
169
169
  }
170
170
 
@@ -177,13 +177,13 @@ function handleUnenvAliasedPackages(
177
177
  function handleNodeJSGlobals(
178
178
  build: PluginBuild,
179
179
  inject: Record<string, string | readonly string[]>,
180
- polyfill: readonly string[]
180
+ polyfill: readonly string[],
181
181
  ) {
182
182
  const UNENV_VIRTUAL_MODULE_RE = /_virtual_unenv_global_polyfill-(.+)$/;
183
183
  const prefix = nodePath.resolve(
184
184
  // getBasePath(),
185
185
  import.meta.dirname,
186
- "_virtual_unenv_global_polyfill-"
186
+ "_virtual_unenv_global_polyfill-",
187
187
  );
188
188
 
189
189
  /**
@@ -209,10 +209,9 @@ function handleNodeJSGlobals(
209
209
  injectsByModule.set(module, []);
210
210
  virtualModulePathToSpecifier.set(
211
211
  prefix + module.replaceAll("/", "-"),
212
- module
212
+ module,
213
213
  );
214
214
  }
215
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
216
215
  injectsByModule.get(module)!.push({ injectedName, exportName, importName });
217
216
  }
218
217
 
@@ -235,7 +234,7 @@ function handleNodeJSGlobals(
235
234
  assert(injects, `Expected ${module} to inject values`);
236
235
 
237
236
  const imports = injects.map(({ exportName, importName }) =>
238
- importName === exportName ? exportName : `${exportName} as ${importName}`
237
+ importName === exportName ? exportName : `${exportName} as ${importName}`,
239
238
  );
240
239
 
241
240
  return {
@@ -2,7 +2,7 @@ import type { Context } from "../context.js";
2
2
  import { Resource } from "../resource.js";
3
3
  import { handleApiError } from "./api-error.js";
4
4
  import {
5
- CloudflareApi,
5
+ type CloudflareApi,
6
6
  createCloudflareApi,
7
7
  type CloudflareApiOptions,
8
8
  } from "./api.js";
@@ -91,7 +91,7 @@ export const CustomDomain = Resource(
91
91
  async function (
92
92
  this: Context<CustomDomain>,
93
93
  logicalId: string, // Changed param name from id to logicalId for clarity
94
- props: CustomDomainProps
94
+ props: CustomDomainProps,
95
95
  ): Promise<CustomDomain> {
96
96
  // Create Cloudflare API client with automatic account discovery
97
97
  const api = await createCloudflareApi(props);
@@ -110,11 +110,10 @@ export const CustomDomain = Resource(
110
110
  if (this.phase === "delete") {
111
111
  await deleteCustomDomain(this, api, logicalId, props);
112
112
  return this.destroy();
113
- } else {
114
- // Create or Update phase
115
- return await ensureCustomDomain(this, api, logicalId, props);
116
113
  }
117
- }
114
+ // Create or Update phase
115
+ return await ensureCustomDomain(this, api, logicalId, props);
116
+ },
118
117
  );
119
118
 
120
119
  // Helper function to delete the custom domain binding
@@ -122,29 +121,29 @@ async function deleteCustomDomain(
122
121
  context: Context<CustomDomain>,
123
122
  api: CloudflareApi,
124
123
  logicalId: string,
125
- props: CustomDomainProps
124
+ props: CustomDomainProps,
126
125
  ): Promise<void> {
127
126
  const domainHostname = props.name;
128
127
  const domainIdToDelete = context.output?.id;
129
128
 
130
129
  if (!domainIdToDelete) {
131
130
  console.warn(
132
- `Cannot delete CustomDomain ${logicalId} (${domainHostname}): Missing domain ID in state. Assuming already deleted.`
131
+ `Cannot delete CustomDomain ${logicalId} (${domainHostname}): Missing domain ID in state. Assuming already deleted.`,
133
132
  );
134
133
  return; // Exit early if no ID
135
134
  }
136
135
 
137
136
  console.log(
138
- `Deleting CustomDomain binding ${domainIdToDelete} for ${domainHostname}`
137
+ `Deleting CustomDomain binding ${domainIdToDelete} for ${domainHostname}`,
139
138
  );
140
139
  const response = await api.delete(
141
- `/accounts/${api.accountId}/workers/domains/${domainIdToDelete}`
140
+ `/accounts/${api.accountId}/workers/domains/${domainIdToDelete}`,
142
141
  );
143
142
 
144
143
  console.log(
145
144
  `Delete result for ${domainIdToDelete} (${domainHostname}):`,
146
145
  response.status,
147
- response.statusText
146
+ response.statusText,
148
147
  );
149
148
 
150
149
  // 404 is acceptable during deletion for idempotency
@@ -153,11 +152,11 @@ async function deleteCustomDomain(
153
152
  response,
154
153
  "deleting",
155
154
  "custom domain binding",
156
- domainIdToDelete
155
+ domainIdToDelete,
157
156
  );
158
157
  // Throw after handling to ensure failure is reported
159
158
  throw new Error(
160
- `Failed to delete custom domain binding ${domainIdToDelete}: ${response.statusText}`
159
+ `Failed to delete custom domain binding ${domainIdToDelete}: ${response.statusText}`,
161
160
  );
162
161
  }
163
162
  }
@@ -167,7 +166,7 @@ async function ensureCustomDomain(
167
166
  context: Context<CustomDomain>,
168
167
  api: CloudflareApi,
169
168
  logicalId: string,
170
- props: CustomDomainProps
169
+ props: CustomDomainProps,
171
170
  ): Promise<CustomDomain> {
172
171
  const environment = props.environment || "production";
173
172
  const domainHostname = props.name;
@@ -175,7 +174,7 @@ async function ensureCustomDomain(
175
174
  // Check if domain binding already exists for this account
176
175
  console.log(`Checking existing domain bindings for account ${api.accountId}`);
177
176
  const listResponse = await api.get(
178
- `/accounts/${api.accountId}/workers/domains`
177
+ `/accounts/${api.accountId}/workers/domains`,
179
178
  );
180
179
 
181
180
  if (!listResponse.ok) {
@@ -184,11 +183,11 @@ async function ensureCustomDomain(
184
183
  listResponse,
185
184
  "listing",
186
185
  "worker domains",
187
- `Account ${api.accountId}`
186
+ `Account ${api.accountId}`,
188
187
  );
189
188
  // If listing fails, we cannot proceed reliably
190
189
  throw new Error(
191
- `Failed to list worker domains for account ${api.accountId}: ${listResponse.statusText}`
190
+ `Failed to list worker domains for account ${api.accountId}: ${listResponse.statusText}`,
192
191
  );
193
192
  }
194
193
 
@@ -199,13 +198,13 @@ async function ensureCustomDomain(
199
198
 
200
199
  if (!listData.success || !listData.result) {
201
200
  throw new Error(
202
- `Failed to parse list worker domains response: ${JSON.stringify(listData)}`
201
+ `Failed to parse list worker domains response: ${JSON.stringify(listData)}`,
203
202
  );
204
203
  }
205
204
 
206
205
  // Find the specific binding by hostname AND zoneId
207
206
  const existingBinding = listData.result.find(
208
- (b) => b.hostname === domainHostname && b.zone_id === props.zoneId
207
+ (b) => b.hostname === domainHostname && b.zone_id === props.zoneId,
209
208
  );
210
209
 
211
210
  let currentDomainId = existingBinding?.id;
@@ -215,7 +214,7 @@ async function ensureCustomDomain(
215
214
  `Domain binding status for ${domainHostname} (Zone: ${props.zoneId}):`,
216
215
  bindingExists
217
216
  ? `Found (ID: ${currentDomainId}, Worker: ${existingBinding.service}, Env: ${existingBinding.environment})`
218
- : "Not found"
217
+ : "Not found",
219
218
  );
220
219
 
221
220
  // Determine if we need to update (binding exists but has different service or environment)
@@ -232,7 +231,7 @@ async function ensureCustomDomain(
232
231
  if (!bindingExists || needsUpdate) {
233
232
  operationPerformed = bindingExists ? "update" : "create";
234
233
  console.log(
235
- `${operationPerformed === "update" ? "Updating" : "Creating"} domain binding: ${domainHostname} (Zone: ${props.zoneId}) → ${props.workerName}:${environment}`
234
+ `${operationPerformed === "update" ? "Updating" : "Creating"} domain binding: ${domainHostname} (Zone: ${props.zoneId}) → ${props.workerName}:${environment}`,
236
235
  );
237
236
 
238
237
  const putPayload = {
@@ -244,7 +243,7 @@ async function ensureCustomDomain(
244
243
 
245
244
  const putResponse = await api.put(
246
245
  `/accounts/${api.accountId}/workers/domains`,
247
- putPayload
246
+ putPayload,
248
247
  );
249
248
 
250
249
  if (!putResponse.ok) {
@@ -252,11 +251,11 @@ async function ensureCustomDomain(
252
251
  putResponse,
253
252
  operationPerformed === "update" ? "updating" : "creating",
254
253
  "custom domain binding",
255
- domainHostname
254
+ domainHostname,
256
255
  );
257
256
  // Throw after handling to prevent inconsistent state
258
257
  throw new Error(
259
- `Failed to ${operationPerformed} custom domain binding: ${putResponse.statusText}`
258
+ `Failed to ${operationPerformed} custom domain binding: ${putResponse.statusText}`,
260
259
  );
261
260
  }
262
261
 
@@ -267,18 +266,18 @@ async function ensureCustomDomain(
267
266
 
268
267
  if (!putResult.success || !putResult.result) {
269
268
  throw new Error(
270
- `Failed to parse ${operationPerformed} domain binding response: ${JSON.stringify(putResult)}`
269
+ `Failed to parse ${operationPerformed} domain binding response: ${JSON.stringify(putResult)}`,
271
270
  );
272
271
  }
273
272
 
274
273
  resultantBinding = putResult.result;
275
274
  currentDomainId = resultantBinding.id; // Update ID from the PUT response
276
275
  console.log(
277
- `Successfully ${operationPerformed}d binding, new ID: ${currentDomainId}`
276
+ `Successfully ${operationPerformed}d binding, new ID: ${currentDomainId}`,
278
277
  );
279
278
  } else {
280
279
  console.log(
281
- `Domain binding already exists and is up to date: ${domainHostname} (ID: ${currentDomainId}) → ${props.workerName}:${environment}`
280
+ `Domain binding already exists and is up to date: ${domainHostname} (ID: ${currentDomainId}) → ${props.workerName}:${environment}`,
282
281
  );
283
282
  }
284
283
 
@@ -291,7 +290,7 @@ async function ensureCustomDomain(
291
290
  currentDomainId,
292
291
  });
293
292
  throw new Error(
294
- `Failed to get final state for custom domain ${domainHostname}`
293
+ `Failed to get final state for custom domain ${domainHostname}`,
295
294
  );
296
295
  }
297
296
 
@@ -2,7 +2,7 @@ import type { Context } from "../context.js";
2
2
  import { Resource } from "../resource.js";
3
3
  import { CloudflareApiError, handleApiError } from "./api-error.js";
4
4
  import {
5
- CloudflareApi,
5
+ type CloudflareApi,
6
6
  createCloudflareApi,
7
7
  type CloudflareApiOptions,
8
8
  } from "./api.js";
@@ -125,7 +125,7 @@ export type D1Database = Resource<"cloudflare::D1Database"> &
125
125
 
126
126
  export async function D1Database(
127
127
  id: string,
128
- props: Omit<D1DatabaseProps, "migrationsFiles">
128
+ props: Omit<D1DatabaseProps, "migrationsFiles">,
129
129
  ) {
130
130
  const migrationsFiles = props.migrationsDir
131
131
  ? await listMigrationsFiles(props.migrationsDir)
@@ -180,7 +180,7 @@ export const D1DatabaseResource = Resource(
180
180
  async function (
181
181
  this: Context<D1Database>,
182
182
  id: string,
183
- props: D1DatabaseProps = {}
183
+ props: D1DatabaseProps = {},
184
184
  ): Promise<D1Database> {
185
185
  const api = await createCloudflareApi(props);
186
186
  const databaseName = props.name ?? id;
@@ -195,99 +195,98 @@ export const D1DatabaseResource = Resource(
195
195
 
196
196
  // Return void (a deleted database has no content)
197
197
  return this.destroy();
198
- } else {
199
- let dbData: CloudflareD1Response;
200
-
201
- if (this.phase === "create") {
202
- console.log("Creating D1 database:", databaseName);
203
- try {
204
- dbData = await createDatabase(api, databaseName, props);
205
- } catch (error) {
206
- // Check if this is a "database already exists" error and adopt is enabled
207
- if (
208
- props.adopt &&
209
- error instanceof CloudflareApiError &&
210
- error.message.includes("already exists")
211
- ) {
212
- console.log(`Database ${databaseName} already exists, adopting it`);
213
- // Find the existing database by name
214
- const databases = await listDatabases(api, databaseName);
215
- const existingDb = databases.find((db) => db.name === databaseName);
216
-
217
- if (!existingDb) {
218
- throw new Error(
219
- `Failed to find existing database '${databaseName}' for adoption`
220
- );
221
- }
222
-
223
- // Get the database details using its ID
224
- dbData = await getDatabase(api, existingDb.id);
225
-
226
- // Update the database with the provided properties
227
- if (props.readReplication) {
228
- console.log(
229
- `Updating adopted database ${databaseName} with new properties`
230
- );
231
- dbData = await updateDatabase(api, existingDb.id, props);
232
- }
233
- } else {
234
- // Re-throw the error if adopt is false or it's not a "database already exists" error
235
- throw error;
198
+ }
199
+ let dbData: CloudflareD1Response;
200
+
201
+ if (this.phase === "create") {
202
+ console.log("Creating D1 database:", databaseName);
203
+ try {
204
+ dbData = await createDatabase(api, databaseName, props);
205
+ } catch (error) {
206
+ // Check if this is a "database already exists" error and adopt is enabled
207
+ if (
208
+ props.adopt &&
209
+ error instanceof CloudflareApiError &&
210
+ error.message.includes("already exists")
211
+ ) {
212
+ console.log(`Database ${databaseName} already exists, adopting it`);
213
+ // Find the existing database by name
214
+ const databases = await listDatabases(api, databaseName);
215
+ const existingDb = databases.find((db) => db.name === databaseName);
216
+
217
+ if (!existingDb) {
218
+ throw new Error(
219
+ `Failed to find existing database '${databaseName}' for adoption`,
220
+ );
221
+ }
222
+
223
+ // Get the database details using its ID
224
+ dbData = await getDatabase(api, existingDb.id);
225
+
226
+ // Update the database with the provided properties
227
+ if (props.readReplication) {
228
+ console.log(
229
+ `Updating adopted database ${databaseName} with new properties`,
230
+ );
231
+ dbData = await updateDatabase(api, existingDb.id, props);
236
232
  }
237
- }
238
- } else {
239
- // Update operation
240
- if (this.output?.id) {
241
- console.log("Updating D1 database:", databaseName);
242
- // Update the database with new properties
243
- dbData = await updateDatabase(api, this.output.id, props);
244
233
  } else {
245
- // If no ID exists, fall back to creating a new database
246
- console.log(
247
- "No existing database ID found, creating new D1 database:",
248
- databaseName
249
- );
250
- dbData = await createDatabase(api, databaseName, props);
234
+ // Re-throw the error if adopt is false or it's not a "database already exists" error
235
+ throw error;
251
236
  }
252
237
  }
238
+ } else {
239
+ // Update operation
240
+ if (this.output?.id) {
241
+ console.log("Updating D1 database:", databaseName);
242
+ // Update the database with new properties
243
+ dbData = await updateDatabase(api, this.output.id, props);
244
+ } else {
245
+ // If no ID exists, fall back to creating a new database
246
+ console.log(
247
+ "No existing database ID found, creating new D1 database:",
248
+ databaseName,
249
+ );
250
+ dbData = await createDatabase(api, databaseName, props);
251
+ }
252
+ }
253
253
 
254
- // Run migrations if provided
255
- if (props.migrationsFiles && props.migrationsFiles.length > 0) {
256
- try {
257
- const migrationsTable = props.migrationsTable || "d1_migrations";
258
- const databaseId = dbData.result.uuid || this.output?.id;
259
-
260
- if (!databaseId) {
261
- throw new Error("Database ID not found for migrations");
262
- }
254
+ // Run migrations if provided
255
+ if (props.migrationsFiles && props.migrationsFiles.length > 0) {
256
+ try {
257
+ const migrationsTable = props.migrationsTable || "d1_migrations";
258
+ const databaseId = dbData.result.uuid || this.output?.id;
263
259
 
264
- await applyMigrations({
265
- migrationsFiles: props.migrationsFiles,
266
- migrationsTable,
267
- accountId: api.accountId,
268
- databaseId,
269
- api,
270
- });
271
- } catch (migrationErr) {
272
- console.error("Failed to apply D1 migrations:", migrationErr);
273
- throw migrationErr;
260
+ if (!databaseId) {
261
+ throw new Error("Database ID not found for migrations");
274
262
  }
275
- }
276
263
 
277
- return this({
278
- type: "d1",
279
- id: dbData.result.uuid || "",
280
- name: databaseName,
281
- fileSize: dbData.result.file_size,
282
- numTables: dbData.result.num_tables,
283
- version: dbData.result.version,
284
- readReplication: dbData.result.read_replication,
285
- primaryLocationHint: props.primaryLocationHint,
286
- accountId: api.accountId,
287
- migrationsDir: props.migrationsDir,
288
- });
264
+ await applyMigrations({
265
+ migrationsFiles: props.migrationsFiles,
266
+ migrationsTable,
267
+ accountId: api.accountId,
268
+ databaseId,
269
+ api,
270
+ });
271
+ } catch (migrationErr) {
272
+ console.error("Failed to apply D1 migrations:", migrationErr);
273
+ throw migrationErr;
274
+ }
289
275
  }
290
- }
276
+
277
+ return this({
278
+ type: "d1",
279
+ id: dbData.result.uuid || "",
280
+ name: databaseName,
281
+ fileSize: dbData.result.file_size,
282
+ numTables: dbData.result.num_tables,
283
+ version: dbData.result.version,
284
+ readReplication: dbData.result.read_replication,
285
+ primaryLocationHint: props.primaryLocationHint,
286
+ accountId: api.accountId,
287
+ migrationsDir: props.migrationsDir,
288
+ });
289
+ },
291
290
  );
292
291
 
293
292
  interface CloudflareD1Response {
@@ -313,7 +312,7 @@ interface CloudflareD1Response {
313
312
  export async function createDatabase(
314
313
  api: CloudflareApi,
315
314
  databaseName: string,
316
- props: D1DatabaseProps
315
+ props: D1DatabaseProps,
317
316
  ): Promise<CloudflareD1Response> {
318
317
  // Create new D1 database
319
318
  const createPayload: any = {
@@ -326,7 +325,7 @@ export async function createDatabase(
326
325
 
327
326
  const createResponse = await api.post(
328
327
  `/accounts/${api.accountId}/d1/database`,
329
- createPayload
328
+ createPayload,
330
329
  );
331
330
 
332
331
  if (!createResponse.ok) {
@@ -334,7 +333,7 @@ export async function createDatabase(
334
333
  createResponse,
335
334
  "creating",
336
335
  "D1 database",
337
- databaseName
336
+ databaseName,
338
337
  );
339
338
  }
340
339
 
@@ -346,14 +345,14 @@ export async function createDatabase(
346
345
  */
347
346
  export async function getDatabase(
348
347
  api: CloudflareApi,
349
- databaseId?: string
348
+ databaseId?: string,
350
349
  ): Promise<CloudflareD1Response> {
351
350
  if (!databaseId) {
352
351
  throw new Error("Database ID is required");
353
352
  }
354
353
 
355
354
  const response = await api.get(
356
- `/accounts/${api.accountId}/d1/database/${databaseId}`
355
+ `/accounts/${api.accountId}/d1/database/${databaseId}`,
357
356
  );
358
357
 
359
358
  if (!response.ok) {
@@ -368,7 +367,7 @@ export async function getDatabase(
368
367
  */
369
368
  export async function deleteDatabase(
370
369
  api: CloudflareApi,
371
- databaseId?: string
370
+ databaseId?: string,
372
371
  ): Promise<void> {
373
372
  if (!databaseId) {
374
373
  console.log("No database ID provided, skipping delete");
@@ -377,7 +376,7 @@ export async function deleteDatabase(
377
376
 
378
377
  // Delete D1 database
379
378
  const deleteResponse = await api.delete(
380
- `/accounts/${api.accountId}/d1/database/${databaseId}`
379
+ `/accounts/${api.accountId}/d1/database/${databaseId}`,
381
380
  );
382
381
 
383
382
  if (!deleteResponse.ok && deleteResponse.status !== 404) {
@@ -386,7 +385,7 @@ export async function deleteDatabase(
386
385
  }));
387
386
  throw new CloudflareApiError(
388
387
  `Error deleting D1 database '${databaseId}': ${errorData.errors?.[0]?.message || deleteResponse.statusText}`,
389
- deleteResponse
388
+ deleteResponse,
390
389
  );
391
390
  }
392
391
  }
@@ -396,19 +395,19 @@ export async function deleteDatabase(
396
395
  */
397
396
  export async function listDatabases(
398
397
  api: CloudflareApi,
399
- name?: string
398
+ name?: string,
400
399
  ): Promise<{ name: string; id: string }[]> {
401
400
  // Construct query string if name is provided
402
401
  const queryParams = name ? `?name=${encodeURIComponent(name)}` : "";
403
402
 
404
403
  const response = await api.get(
405
- `/accounts/${api.accountId}/d1/database${queryParams}`
404
+ `/accounts/${api.accountId}/d1/database${queryParams}`,
406
405
  );
407
406
 
408
407
  if (!response.ok) {
409
408
  throw new CloudflareApiError(
410
409
  `Failed to list databases: ${response.statusText}`,
411
- response
410
+ response,
412
411
  );
413
412
  }
414
413
 
@@ -441,7 +440,7 @@ export async function listDatabases(
441
440
  export async function updateDatabase(
442
441
  api: CloudflareApi,
443
442
  databaseId: string,
444
- props: D1DatabaseProps
443
+ props: D1DatabaseProps,
445
444
  ): Promise<CloudflareD1Response> {
446
445
  // Get current database state to check for non-mutable changes
447
446
  const currentDB = await getDatabase(api, databaseId);
@@ -452,7 +451,7 @@ export async function updateDatabase(
452
451
  props.primaryLocationHint !== currentDB.result.primary_location_hint
453
452
  ) {
454
453
  throw new Error(
455
- "Cannot update primaryLocationHint after database creation. Only readReplication.mode can be modified."
454
+ "Cannot update primaryLocationHint after database creation. Only readReplication.mode can be modified.",
456
455
  );
457
456
  }
458
457
 
@@ -467,7 +466,7 @@ export async function updateDatabase(
467
466
 
468
467
  const updateResponse = await api.patch(
469
468
  `/accounts/${api.accountId}/d1/database/${databaseId}`,
470
- updatePayload
469
+ updatePayload,
471
470
  );
472
471
 
473
472
  if (!updateResponse.ok) {
@@ -475,7 +474,7 @@ export async function updateDatabase(
475
474
  updateResponse,
476
475
  "updating",
477
476
  "D1 database",
478
- databaseId
477
+ databaseId,
479
478
  );
480
479
  }
481
480