alchemy 0.44.4 → 0.45.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 (263) hide show
  1. package/drizzle/0000_busy_mauler.sql +19 -0
  2. package/drizzle/0001_concerned_iceman.sql +20 -0
  3. package/drizzle/meta/0000_snapshot.json +137 -0
  4. package/drizzle/meta/0001_snapshot.json +106 -0
  5. package/drizzle/meta/_journal.json +20 -0
  6. package/lib/alchemy.d.ts +3 -3
  7. package/lib/alchemy.d.ts.map +1 -1
  8. package/lib/alchemy.js +5 -2
  9. package/lib/alchemy.js.map +1 -1
  10. package/lib/build-date.d.ts +1 -1
  11. package/lib/build-date.js +1 -1
  12. package/lib/cloudflare/auth.js +1 -1
  13. package/lib/cloudflare/auth.js.map +1 -1
  14. package/lib/cloudflare/bundle/esbuild.d.ts +16 -0
  15. package/lib/cloudflare/bundle/esbuild.d.ts.map +1 -0
  16. package/lib/cloudflare/bundle/esbuild.js +159 -0
  17. package/lib/cloudflare/bundle/esbuild.js.map +1 -0
  18. package/lib/cloudflare/bundle/fs.d.ts +18 -0
  19. package/lib/cloudflare/bundle/fs.d.ts.map +1 -0
  20. package/lib/cloudflare/bundle/fs.js +75 -0
  21. package/lib/cloudflare/bundle/fs.js.map +1 -0
  22. package/lib/cloudflare/bundle/index.d.ts +3 -0
  23. package/lib/cloudflare/bundle/index.d.ts.map +1 -0
  24. package/lib/cloudflare/bundle/index.js +2 -0
  25. package/lib/cloudflare/bundle/index.js.map +1 -0
  26. package/lib/cloudflare/bundle/inline.d.ts +12 -0
  27. package/lib/cloudflare/bundle/inline.d.ts.map +1 -0
  28. package/lib/cloudflare/bundle/inline.js +32 -0
  29. package/lib/cloudflare/bundle/inline.js.map +1 -0
  30. package/lib/cloudflare/bundle/normalize.d.ts +21 -0
  31. package/lib/cloudflare/bundle/normalize.d.ts.map +1 -0
  32. package/lib/cloudflare/bundle/normalize.js +49 -0
  33. package/lib/cloudflare/bundle/normalize.js.map +1 -0
  34. package/lib/cloudflare/bundle/{nodejs-import-warning-plugin.d.ts → plugin-compat-warning.d.ts} +2 -2
  35. package/lib/cloudflare/bundle/plugin-compat-warning.d.ts.map +1 -0
  36. package/lib/cloudflare/bundle/{nodejs-import-warning-plugin.js → plugin-compat-warning.js} +3 -3
  37. package/lib/cloudflare/bundle/plugin-compat-warning.js.map +1 -0
  38. package/lib/cloudflare/bundle/plugin-hot-reload.d.ts +8 -0
  39. package/lib/cloudflare/bundle/plugin-hot-reload.d.ts.map +1 -0
  40. package/lib/cloudflare/bundle/plugin-hot-reload.js +19 -0
  41. package/lib/cloudflare/bundle/plugin-hot-reload.js.map +1 -0
  42. package/lib/cloudflare/bundle/{nodejs-compat.d.ts → plugin-hybrid-node-compat.d.ts} +2 -2
  43. package/lib/cloudflare/bundle/plugin-hybrid-node-compat.d.ts.map +1 -0
  44. package/lib/cloudflare/bundle/{nodejs-compat.js → plugin-hybrid-node-compat.js} +10 -10
  45. package/lib/cloudflare/bundle/plugin-hybrid-node-compat.js.map +1 -0
  46. package/lib/cloudflare/bundle/plugin-wasm.d.ts +3 -0
  47. package/lib/cloudflare/bundle/plugin-wasm.d.ts.map +1 -0
  48. package/lib/cloudflare/bundle/plugin-wasm.js +55 -0
  49. package/lib/cloudflare/bundle/plugin-wasm.js.map +1 -0
  50. package/lib/cloudflare/bundle/shared.d.ts +30 -0
  51. package/lib/cloudflare/bundle/shared.d.ts.map +1 -0
  52. package/lib/cloudflare/bundle/shared.js +34 -0
  53. package/lib/cloudflare/bundle/shared.js.map +1 -0
  54. package/lib/cloudflare/bundle/{nodejs-compat-mode.d.ts → validate-node-compat.d.ts} +8 -4
  55. package/lib/cloudflare/bundle/validate-node-compat.d.ts.map +1 -0
  56. package/lib/cloudflare/bundle/{nodejs-compat-mode.js → validate-node-compat.js} +27 -7
  57. package/lib/cloudflare/bundle/validate-node-compat.js.map +1 -0
  58. package/lib/cloudflare/container.d.ts +231 -0
  59. package/lib/cloudflare/container.d.ts.map +1 -1
  60. package/lib/cloudflare/container.js +7 -0
  61. package/lib/cloudflare/container.js.map +1 -1
  62. package/lib/cloudflare/d1-migrations.d.ts +1 -0
  63. package/lib/cloudflare/d1-migrations.d.ts.map +1 -1
  64. package/lib/cloudflare/d1-migrations.js +18 -6
  65. package/lib/cloudflare/d1-migrations.js.map +1 -1
  66. package/lib/cloudflare/d1-state-store.d.ts +10 -0
  67. package/lib/cloudflare/d1-state-store.d.ts.map +1 -0
  68. package/lib/cloudflare/d1-state-store.js +70 -0
  69. package/lib/cloudflare/d1-state-store.js.map +1 -0
  70. package/lib/cloudflare/do-state-store/internal.js +1 -1
  71. package/lib/cloudflare/do-state-store/internal.js.map +1 -1
  72. package/lib/cloudflare/do-state-store/store.js +1 -1
  73. package/lib/cloudflare/do-state-store/store.js.map +1 -1
  74. package/lib/cloudflare/index.d.ts +3 -2
  75. package/lib/cloudflare/index.d.ts.map +1 -1
  76. package/lib/cloudflare/index.js +3 -2
  77. package/lib/cloudflare/index.js.map +1 -1
  78. package/lib/cloudflare/local-dev-cloudflare-shim.d.ts.map +1 -0
  79. package/lib/cloudflare/{bundle/local-dev-cloudflare-shim.js → local-dev-cloudflare-shim.js} +1 -1
  80. package/lib/cloudflare/local-dev-cloudflare-shim.js.map +1 -0
  81. package/lib/cloudflare/miniflare/http-server.d.ts.map +1 -0
  82. package/lib/cloudflare/miniflare/http-server.js.map +1 -0
  83. package/lib/cloudflare/{worker → miniflare}/miniflare-worker-options.d.ts +4 -3
  84. package/lib/cloudflare/miniflare/miniflare-worker-options.d.ts.map +1 -0
  85. package/lib/cloudflare/{worker → miniflare}/miniflare-worker-options.js +6 -3
  86. package/lib/cloudflare/miniflare/miniflare-worker-options.js.map +1 -0
  87. package/lib/cloudflare/miniflare/miniflare.d.ts.map +1 -0
  88. package/lib/cloudflare/{worker → miniflare}/miniflare.js +1 -1
  89. package/lib/cloudflare/miniflare/miniflare.js.map +1 -0
  90. package/lib/cloudflare/miniflare/mixed-mode.d.ts.map +1 -0
  91. package/lib/cloudflare/{worker → miniflare}/mixed-mode.js +1 -2
  92. package/lib/cloudflare/miniflare/mixed-mode.js.map +1 -0
  93. package/lib/cloudflare/user.js +1 -1
  94. package/lib/cloudflare/user.js.map +1 -1
  95. package/lib/cloudflare/worker/shared.d.ts +4 -0
  96. package/lib/cloudflare/worker/shared.d.ts.map +1 -0
  97. package/lib/cloudflare/worker/{get-worker-template.js → shared.js} +10 -1
  98. package/lib/cloudflare/worker/shared.js.map +1 -0
  99. package/lib/cloudflare/worker/tail.d.ts +18 -0
  100. package/lib/cloudflare/worker/tail.d.ts.map +1 -0
  101. package/lib/cloudflare/worker/tail.js +140 -0
  102. package/lib/cloudflare/worker/tail.js.map +1 -0
  103. package/lib/cloudflare/worker-metadata.d.ts +6 -2
  104. package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
  105. package/lib/cloudflare/worker-metadata.js +7 -23
  106. package/lib/cloudflare/worker-metadata.js.map +1 -1
  107. package/lib/cloudflare/worker-stub.d.ts.map +1 -1
  108. package/lib/cloudflare/worker-stub.js +8 -7
  109. package/lib/cloudflare/worker-stub.js.map +1 -1
  110. package/lib/cloudflare/worker-subdomain.d.ts +31 -0
  111. package/lib/cloudflare/worker-subdomain.d.ts.map +1 -0
  112. package/lib/cloudflare/worker-subdomain.js +55 -0
  113. package/lib/cloudflare/worker-subdomain.js.map +1 -0
  114. package/lib/cloudflare/worker.d.ts +30 -36
  115. package/lib/cloudflare/worker.d.ts.map +1 -1
  116. package/lib/cloudflare/worker.js +641 -569
  117. package/lib/cloudflare/worker.js.map +1 -1
  118. package/lib/fs/file-system-state-store.js +1 -1
  119. package/lib/fs/file-system-state-store.js.map +1 -1
  120. package/lib/scope.d.ts +2 -2
  121. package/lib/scope.d.ts.map +1 -1
  122. package/lib/scope.js +23 -8
  123. package/lib/scope.js.map +1 -1
  124. package/lib/serde.d.ts +1 -1
  125. package/lib/serde.d.ts.map +1 -1
  126. package/lib/serde.js +4 -4
  127. package/lib/serde.js.map +1 -1
  128. package/lib/sqlite/base-sqlite-state-store.d.ts +31 -0
  129. package/lib/sqlite/base-sqlite-state-store.d.ts.map +1 -0
  130. package/lib/sqlite/base-sqlite-state-store.js +124 -0
  131. package/lib/sqlite/base-sqlite-state-store.js.map +1 -0
  132. package/lib/sqlite/index.d.ts +2 -0
  133. package/lib/sqlite/index.d.ts.map +1 -0
  134. package/lib/sqlite/index.js +2 -0
  135. package/lib/sqlite/index.js.map +1 -0
  136. package/lib/sqlite/schema.d.ts +198 -0
  137. package/lib/sqlite/schema.d.ts.map +1 -0
  138. package/lib/sqlite/schema.js +23 -0
  139. package/lib/sqlite/schema.js.map +1 -0
  140. package/lib/sqlite/sqlite-state-store.d.ts +60 -0
  141. package/lib/sqlite/sqlite-state-store.d.ts.map +1 -0
  142. package/lib/sqlite/sqlite-state-store.js +83 -0
  143. package/lib/sqlite/sqlite-state-store.js.map +1 -0
  144. package/lib/test/bun.d.ts.map +1 -1
  145. package/lib/test/bun.js +0 -6
  146. package/lib/test/bun.js.map +1 -1
  147. package/lib/test/vitest.d.ts.map +1 -1
  148. package/lib/test/vitest.js +19 -5
  149. package/lib/test/vitest.js.map +1 -1
  150. package/lib/util/memoize.d.ts +1 -1
  151. package/lib/util/memoize.d.ts.map +1 -1
  152. package/lib/util/memoize.js +11 -1
  153. package/lib/util/memoize.js.map +1 -1
  154. package/package.json +13 -3
  155. package/src/alchemy.ts +8 -6
  156. package/src/build-date.ts +1 -1
  157. package/src/cloudflare/auth.ts +1 -1
  158. package/src/cloudflare/bundle/esbuild.ts +194 -0
  159. package/src/cloudflare/bundle/fs.ts +98 -0
  160. package/src/cloudflare/bundle/index.ts +6 -0
  161. package/src/cloudflare/bundle/inline.ts +42 -0
  162. package/src/cloudflare/bundle/normalize.ts +76 -0
  163. package/src/cloudflare/bundle/{nodejs-import-warning-plugin.ts → plugin-compat-warning.ts} +4 -2
  164. package/src/cloudflare/bundle/plugin-hot-reload.ts +27 -0
  165. package/src/cloudflare/bundle/{nodejs-compat.ts → plugin-hybrid-node-compat.ts} +10 -10
  166. package/src/cloudflare/bundle/plugin-wasm.ts +62 -0
  167. package/src/cloudflare/bundle/shared.ts +73 -0
  168. package/src/cloudflare/bundle/{nodejs-compat-mode.ts → validate-node-compat.ts} +41 -16
  169. package/src/cloudflare/container.ts +296 -0
  170. package/src/cloudflare/d1-migrations.ts +29 -16
  171. package/src/cloudflare/d1-state-store.ts +105 -0
  172. package/src/cloudflare/do-state-store/internal.ts +1 -1
  173. package/src/cloudflare/do-state-store/store.ts +1 -1
  174. package/src/cloudflare/index.ts +3 -2
  175. package/src/cloudflare/{bundle/local-dev-cloudflare-shim.ts → local-dev-cloudflare-shim.ts} +1 -1
  176. package/src/cloudflare/{worker → miniflare}/miniflare-worker-options.ts +14 -6
  177. package/src/cloudflare/{worker → miniflare}/miniflare.ts +1 -1
  178. package/src/cloudflare/{worker → miniflare}/mixed-mode.ts +1 -2
  179. package/src/cloudflare/user.ts +1 -1
  180. package/src/cloudflare/worker/{subdomain.ts → shared.ts} +14 -0
  181. package/src/cloudflare/worker/tail.ts +287 -0
  182. package/src/cloudflare/worker-metadata.ts +18 -26
  183. package/src/cloudflare/worker-stub.ts +9 -7
  184. package/src/cloudflare/worker-subdomain.ts +123 -0
  185. package/src/cloudflare/worker.ts +863 -760
  186. package/src/fs/file-system-state-store.ts +1 -1
  187. package/src/scope.ts +30 -11
  188. package/src/serde.ts +4 -4
  189. package/src/sqlite/base-sqlite-state-store.ts +199 -0
  190. package/src/sqlite/index.ts +1 -0
  191. package/src/sqlite/schema.ts +37 -0
  192. package/src/sqlite/sqlite-state-store.ts +174 -0
  193. package/src/test/bun.ts +0 -8
  194. package/src/test/vitest.ts +19 -8
  195. package/src/util/memoize.ts +13 -1
  196. package/templates/astro/types/env.d.ts +1 -1
  197. package/templates/nuxt/types/env.d.ts +1 -1
  198. package/templates/react-router/types/env.d.ts +1 -1
  199. package/templates/rwsdk/types/env.d.ts +1 -1
  200. package/templates/sveltekit/types/env.d.ts +1 -1
  201. package/templates/tanstack-start/types/env.d.ts +1 -1
  202. package/templates/typescript/types/env.d.ts +1 -1
  203. package/templates/vite/types/env.d.ts +1 -1
  204. package/lib/cloudflare/bundle/alias-plugin.d.ts +0 -6
  205. package/lib/cloudflare/bundle/alias-plugin.d.ts.map +0 -1
  206. package/lib/cloudflare/bundle/alias-plugin.js +0 -36
  207. package/lib/cloudflare/bundle/alias-plugin.js.map +0 -1
  208. package/lib/cloudflare/bundle/build-failures.d.ts +0 -12
  209. package/lib/cloudflare/bundle/build-failures.d.ts.map +0 -1
  210. package/lib/cloudflare/bundle/build-failures.js +0 -45
  211. package/lib/cloudflare/bundle/build-failures.js.map +0 -1
  212. package/lib/cloudflare/bundle/bundle-worker-dev.d.ts +0 -26
  213. package/lib/cloudflare/bundle/bundle-worker-dev.d.ts.map +0 -1
  214. package/lib/cloudflare/bundle/bundle-worker-dev.js +0 -88
  215. package/lib/cloudflare/bundle/bundle-worker-dev.js.map +0 -1
  216. package/lib/cloudflare/bundle/bundle-worker.d.ts +0 -13
  217. package/lib/cloudflare/bundle/bundle-worker.d.ts.map +0 -1
  218. package/lib/cloudflare/bundle/bundle-worker.js +0 -98
  219. package/lib/cloudflare/bundle/bundle-worker.js.map +0 -1
  220. package/lib/cloudflare/bundle/external.d.ts +0 -4
  221. package/lib/cloudflare/bundle/external.d.ts.map +0 -1
  222. package/lib/cloudflare/bundle/external.js +0 -40
  223. package/lib/cloudflare/bundle/external.js.map +0 -1
  224. package/lib/cloudflare/bundle/local-dev-cloudflare-shim.d.ts.map +0 -1
  225. package/lib/cloudflare/bundle/local-dev-cloudflare-shim.js.map +0 -1
  226. package/lib/cloudflare/bundle/nodejs-compat-mode.d.ts.map +0 -1
  227. package/lib/cloudflare/bundle/nodejs-compat-mode.js.map +0 -1
  228. package/lib/cloudflare/bundle/nodejs-compat.d.ts.map +0 -1
  229. package/lib/cloudflare/bundle/nodejs-compat.js.map +0 -1
  230. package/lib/cloudflare/bundle/nodejs-import-warning-plugin.d.ts.map +0 -1
  231. package/lib/cloudflare/bundle/nodejs-import-warning-plugin.js.map +0 -1
  232. package/lib/cloudflare/bundle/wasm-plugin.d.ts +0 -3
  233. package/lib/cloudflare/bundle/wasm-plugin.d.ts.map +0 -1
  234. package/lib/cloudflare/bundle/wasm-plugin.js +0 -53
  235. package/lib/cloudflare/bundle/wasm-plugin.js.map +0 -1
  236. package/lib/cloudflare/worker/get-worker-template.d.ts +0 -2
  237. package/lib/cloudflare/worker/get-worker-template.d.ts.map +0 -1
  238. package/lib/cloudflare/worker/get-worker-template.js.map +0 -1
  239. package/lib/cloudflare/worker/http-server.d.ts.map +0 -1
  240. package/lib/cloudflare/worker/http-server.js.map +0 -1
  241. package/lib/cloudflare/worker/miniflare-worker-options.d.ts.map +0 -1
  242. package/lib/cloudflare/worker/miniflare-worker-options.js.map +0 -1
  243. package/lib/cloudflare/worker/miniflare.d.ts.map +0 -1
  244. package/lib/cloudflare/worker/miniflare.js.map +0 -1
  245. package/lib/cloudflare/worker/mixed-mode.d.ts.map +0 -1
  246. package/lib/cloudflare/worker/mixed-mode.js.map +0 -1
  247. package/lib/cloudflare/worker/subdomain.d.ts +0 -3
  248. package/lib/cloudflare/worker/subdomain.d.ts.map +0 -1
  249. package/lib/cloudflare/worker/subdomain.js +0 -10
  250. package/lib/cloudflare/worker/subdomain.js.map +0 -1
  251. package/src/cloudflare/bundle/alias-plugin.ts +0 -48
  252. package/src/cloudflare/bundle/build-failures.ts +0 -55
  253. package/src/cloudflare/bundle/bundle-worker-dev.ts +0 -129
  254. package/src/cloudflare/bundle/bundle-worker.ts +0 -150
  255. package/src/cloudflare/bundle/external.ts +0 -41
  256. package/src/cloudflare/bundle/wasm-plugin.ts +0 -57
  257. package/src/cloudflare/worker/get-worker-template.ts +0 -14
  258. /package/lib/cloudflare/{bundle/local-dev-cloudflare-shim.d.ts → local-dev-cloudflare-shim.d.ts} +0 -0
  259. /package/lib/cloudflare/{worker → miniflare}/http-server.d.ts +0 -0
  260. /package/lib/cloudflare/{worker → miniflare}/http-server.js +0 -0
  261. /package/lib/cloudflare/{worker → miniflare}/miniflare.d.ts +0 -0
  262. /package/lib/cloudflare/{worker → miniflare}/mixed-mode.d.ts +0 -0
  263. /package/src/cloudflare/{worker → miniflare}/http-server.ts +0 -0
@@ -1,5 +1,11 @@
1
1
  import { logger } from "../../util/logger.ts";
2
2
 
3
+ interface ValidateNodeCompatProps {
4
+ compatibilityDate: string;
5
+ compatibilityFlags: string[];
6
+ noBundle: boolean;
7
+ }
8
+
3
9
  /**
4
10
  * Computes and validates the Node.js compatibility mode we are running.
5
11
  *
@@ -12,25 +18,32 @@ import { logger } from "../../util/logger.ts";
12
18
  * @param noBundle Whether to skip internal build steps and directly deploy script
13
19
  *
14
20
  */
15
- export async function getNodeJSCompatMode(
16
- compatibilityDateStr: string,
17
- compatibilityFlags: string[],
18
- props?: {
19
- noBundle?: boolean;
20
- },
21
- ) {
22
- const { getNodeCompat } = await import("miniflare").catch(() => {
23
- throw new Error(
24
- "Miniflare is not installed, but is required to determine the Node.js compatibility mode for Workers. Please run `npm install miniflare`.",
25
- );
26
- });
21
+ export function validateNodeCompat({
22
+ compatibilityDate,
23
+ compatibilityFlags,
24
+ noBundle,
25
+ }: ValidateNodeCompatProps) {
27
26
  const {
28
- mode,
27
+ hasNodejsAlsFlag,
29
28
  hasNodejsCompatFlag,
30
29
  hasNodejsCompatV2Flag,
30
+ hasNoNodejsCompatV2Flag,
31
31
  hasExperimentalNodejsCompatV2Flag,
32
- } = getNodeCompat(compatibilityDateStr, compatibilityFlags);
33
-
32
+ } = parseNodeCompatibilityFlags(compatibilityFlags);
33
+ const nodeCompatSwitchOverDate = "2024-09-23";
34
+ let mode: "v1" | "v2" | "als" | null = null;
35
+ if (
36
+ hasNodejsCompatV2Flag ||
37
+ (hasNodejsCompatFlag &&
38
+ compatibilityDate >= nodeCompatSwitchOverDate &&
39
+ !hasNoNodejsCompatV2Flag)
40
+ ) {
41
+ mode = "v2";
42
+ } else if (hasNodejsCompatFlag) {
43
+ mode = "v1";
44
+ } else if (hasNodejsAlsFlag) {
45
+ mode = "als";
46
+ }
34
47
  if (hasExperimentalNodejsCompatV2Flag) {
35
48
  throw new Error(
36
49
  "The `experimental:` prefix on `nodejs_compat_v2` is no longer valid. Please remove it and try again.",
@@ -43,7 +56,7 @@ export async function getNodeJSCompatMode(
43
56
  );
44
57
  }
45
58
 
46
- if (props?.noBundle && hasNodejsCompatV2Flag) {
59
+ if (noBundle && hasNodejsCompatV2Flag) {
47
60
  logger.warn(
48
61
  "`nodejs_compat_v2` compatibility flag and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.",
49
62
  );
@@ -57,3 +70,15 @@ export async function getNodeJSCompatMode(
57
70
 
58
71
  return mode;
59
72
  }
73
+
74
+ function parseNodeCompatibilityFlags(compatibilityFlags: string[]) {
75
+ return {
76
+ hasNodejsAlsFlag: compatibilityFlags.includes("nodejs_als"),
77
+ hasNodejsCompatFlag: compatibilityFlags.includes("nodejs_compat"),
78
+ hasNodejsCompatV2Flag: compatibilityFlags.includes("nodejs_compat_v2"),
79
+ hasNoNodejsCompatV2Flag: compatibilityFlags.includes("no_nodejs_compat_v2"),
80
+ hasExperimentalNodejsCompatV2Flag: compatibilityFlags.includes(
81
+ "experimental:nodejs_compat_v2",
82
+ ),
83
+ };
84
+ }
@@ -9,46 +9,159 @@ import {
9
9
  createCloudflareApi,
10
10
  } from "./api.ts";
11
11
 
12
+ /**
13
+ * Properties for creating a Container binding or ContainerApplication
14
+ *
15
+ * Extends ImageProps for Docker image configuration and CloudflareApiOptions
16
+ * for Cloudflare API authentication.
17
+ */
12
18
  export interface ContainerProps
13
19
  extends Omit<ImageProps, "registry" | "skipPush">,
14
20
  Partial<CloudflareApiOptions> {
21
+ /**
22
+ * The class name for the container binding.
23
+ * This is used to identify the container class in Worker bindings.
24
+ */
15
25
  className: string;
26
+
27
+ /**
28
+ * Maximum number of container instances that can be running.
29
+ * Controls horizontal scaling limits.
30
+ *
31
+ * @default 10
32
+ */
16
33
  maxInstances?: number;
34
+
35
+ /**
36
+ * Optional name for the Worker script that will use this container.
37
+ * Used for organizing and identifying container deployments.
38
+ */
17
39
  scriptName?: string;
40
+
41
+ /**
42
+ * The instance type determines the compute resources allocated to the container.
43
+ * Different types offer different CPU, memory, and pricing characteristics.
44
+ *
45
+ * @default "dev"
46
+ */
18
47
  instanceType?: InstanceType;
48
+
49
+ /**
50
+ * Configuration for observability features like logging and monitoring.
51
+ * Controls what telemetry data is collected from the container.
52
+ */
19
53
  observability?: DeploymentObservability;
54
+
55
+ /**
56
+ * Scheduling policy controls where and how containers are deployed.
57
+ * Affects placement, resource allocation, and geographic distribution.
58
+ *
59
+ * @default "default"
60
+ */
20
61
  schedulingPolicy?: SchedulingPolicy;
62
+
63
+ /**
64
+ * Whether to adopt an existing container application with the same name.
65
+ *
66
+ * If `true`, the resource will attempt to adopt an existing container application
67
+ * instead of failing when one already exists with the same name.
68
+ *
69
+ * @default false
70
+ */
71
+ adopt?: boolean;
72
+
73
+ /**
74
+ * Development-specific configuration options.
75
+ */
21
76
  dev?: {
77
+ /**
78
+ * Whether to use remote container deployment even in development mode.
79
+ * When false, containers run locally using Miniflare.
80
+ * When true, containers are deployed to Cloudflare's edge even in dev mode.
81
+ *
82
+ * @default false
83
+ */
22
84
  remote?: boolean;
23
85
  };
24
86
  }
25
87
 
26
88
  /**
89
+ * Instance types for Cloudflare Container deployments.
90
+ *
91
+ * Each type offers different compute resources and pricing:
92
+ * - `dev`: Development instances with minimal resources, suitable for testing
93
+ * - `basic`: Basic production instances with standard resources
94
+ * - `standard`: Standard production instances with enhanced resources
95
+ *
27
96
  * @see https://developers.cloudflare.com/containers/pricing/
28
97
  */
29
98
  export type InstanceType = "dev" | "basic" | "standard" | (string & {});
30
99
 
100
+ /**
101
+ * Type guard to check if a binding is a Container binding.
102
+ *
103
+ * @param binding - The binding to check
104
+ * @returns True if the binding is a Container binding
105
+ */
31
106
  export function isContainer(binding: any): binding is Container {
32
107
  return binding.type === "container";
33
108
  }
34
109
 
110
+ /**
111
+ * A Container binding that can be used in Cloudflare Workers.
112
+ *
113
+ * Container bindings allow Workers to communicate with containerized applications
114
+ * running on Cloudflare's global network. The container can be called from the
115
+ * Worker using the binding name.
116
+ *
117
+ * @template T - Type parameter for additional container-specific properties
118
+ */
35
119
  export type Container<T = any> = {
120
+ /** Identifies this as a container binding type */
36
121
  type: "container";
122
+
123
+ /** Unique identifier for the container */
37
124
  id: string;
125
+
126
+ /** Optional human-readable name for the container */
38
127
  name?: string;
128
+
129
+ /** Class name used to identify the container in Worker bindings */
39
130
  className: string;
131
+
132
+ /** Docker image configuration for the container */
40
133
  image: Image;
134
+
135
+ /** Maximum number of container instances that can be running */
41
136
  maxInstances?: number;
137
+
138
+ /** Optional name for the Worker script that will use this container */
42
139
  scriptName?: string;
140
+
141
+ /** Whether SQLite is enabled for the container (always true for containers) */
43
142
  sqlite?: true;
143
+
144
+ /** The instance type determining compute resources */
44
145
  instanceType?: InstanceType;
146
+
147
+ /** Observability configuration for logging and monitoring */
45
148
  observability?: DeploymentObservability;
149
+
150
+ /** Scheduling policy for container placement */
46
151
  schedulingPolicy?: SchedulingPolicy;
152
+
153
+ /** Whether this container was adopted from an existing deployment */
154
+ adopt?: boolean;
155
+
156
+ /** Development-specific configuration */
47
157
  dev?: {
158
+ /** Whether to use remote deployment in development mode */
48
159
  remote?: boolean;
49
160
  };
161
+
50
162
  /**
51
163
  * @internal
164
+ * Phantom type parameter for additional type safety
52
165
  */
53
166
  __phantom?: T;
54
167
  };
@@ -75,6 +188,7 @@ export async function Container<T>(
75
188
  schedulingPolicy: props.schedulingPolicy,
76
189
  sqlite: true,
77
190
  dev: props.dev,
191
+ adopt: props.adopt,
78
192
  };
79
193
 
80
194
  if (Scope.current.dev && !props.dev?.remote) {
@@ -110,45 +224,137 @@ export async function Container<T>(
110
224
  };
111
225
  }
112
226
 
227
+ /**
228
+ * Configuration for progressive rollout strategy when updating container applications.
229
+ *
230
+ * Rollouts allow you to gradually deploy new container configurations, reducing
231
+ * risk by updating instances incrementally rather than all at once.
232
+ */
113
233
  export interface ContainerApplicationRollout {
234
+ /**
235
+ * The rollout strategy to use.
236
+ * Currently only "rolling" strategy is supported, which updates instances gradually.
237
+ */
114
238
  strategy: "rolling";
239
+
240
+ /**
241
+ * The rollout automation level.
242
+ * "full_auto" means the rollout proceeds automatically without manual intervention.
243
+ *
244
+ * @default "full_auto"
245
+ */
115
246
  kind?: "full_auto";
247
+
248
+ /**
249
+ * Percentage of instances to update in each step of the rollout.
250
+ * For example, 25 means 25% of instances are updated in each step.
251
+ *
252
+ * @minimum 1
253
+ * @maximum 100
254
+ */
116
255
  stepPercentage: number;
256
+
257
+ /**
258
+ * The target configuration that instances will be updated to.
259
+ * This defines the final state after the rollout completes.
260
+ */
117
261
  targetConfiguration: {
262
+ /** The container image to deploy */
118
263
  image: string;
264
+
265
+ /** The instance type for the new deployment */
119
266
  instance_type?: InstanceType;
267
+
268
+ /** Observability configuration for the new deployment */
120
269
  observability: {
270
+ /** Logging configuration */
121
271
  logs: {
272
+ /** Whether logging is enabled */
122
273
  enabled: boolean;
123
274
  };
124
275
  };
125
276
  };
126
277
  }
127
278
 
279
+ /**
280
+ * Properties for creating a ContainerApplication resource.
281
+ *
282
+ * ContainerApplication represents a managed container deployment that runs your
283
+ * Docker images with automatic scaling, scheduling, and integration with
284
+ * Cloudflare's services.
285
+ */
128
286
  export interface ContainerApplicationProps extends CloudflareApiOptions {
287
+ /**
288
+ * The name of the container application.
289
+ * Must be unique within your Cloudflare account.
290
+ */
129
291
  name: string;
292
+
293
+ /**
294
+ * Scheduling policy that controls where and how containers are deployed.
295
+ * Affects placement, resource allocation, and geographic distribution.
296
+ *
297
+ * @default "default"
298
+ */
130
299
  schedulingPolicy?: SchedulingPolicy;
300
+
301
+ /**
302
+ * The initial number of container instances to deploy.
303
+ * Can be scaled up or down after deployment.
304
+ *
305
+ * @default 1
306
+ */
131
307
  instances?: number;
308
+
132
309
  /**
133
310
  * The instance type to be used for the deployment.
311
+ * Determines the compute resources (CPU, memory) allocated to each instance.
134
312
  *
135
313
  * @default "dev"
136
314
  */
137
315
  instanceType?: InstanceType;
316
+
138
317
  /**
139
318
  * The observability configuration for the deployment.
319
+ * Controls logging, monitoring, and telemetry collection.
140
320
  */
141
321
  observability?: DeploymentObservability;
322
+
142
323
  /**
143
324
  * The maximum number of instances to be used for the deployment.
325
+ * Acts as an upper limit for auto-scaling.
326
+ *
327
+ * @default 1
144
328
  */
145
329
  maxInstances?: number;
330
+
331
+ /**
332
+ * The Docker image to deploy in the container application.
333
+ * Must be built and available in a container registry.
334
+ */
146
335
  image: Image;
336
+
337
+ /**
338
+ * Optional registry ID for custom container registries.
339
+ * If not specified, uses Cloudflare's default registry.
340
+ */
147
341
  registryId?: string;
342
+
343
+ /**
344
+ * Configuration for Durable Objects integration.
345
+ * Allows the container to interact with Cloudflare Durable Objects.
346
+ */
148
347
  durableObjects?: {
348
+ /** The namespace ID of the Durable Objects namespace to bind */
149
349
  namespaceId: string;
150
350
  };
351
+
352
+ /**
353
+ * Configuration for progressive rollout when updating the application.
354
+ * Defines how updates are deployed across instances.
355
+ */
151
356
  rollout?: ContainerApplicationRollout;
357
+
152
358
  /**
153
359
  * Whether to adopt an existing container application with the same name.
154
360
  *
@@ -160,6 +366,16 @@ export interface ContainerApplicationProps extends CloudflareApiOptions {
160
366
  adopt?: boolean;
161
367
  }
162
368
 
369
+ /**
370
+ * Scheduling policies that control container placement and resource allocation.
371
+ *
372
+ * Different policies optimize for different use cases:
373
+ * - `moon`: Optimized for latency-sensitive applications
374
+ * - `gpu`: Routes to locations with GPU resources available
375
+ * - `regional`: Keeps containers within specific geographic regions
376
+ * - `fill_metals`: Optimizes for resource utilization on dedicated hardware
377
+ * - `default`: Uses Cloudflare's standard scheduling algorithm
378
+ */
163
379
  export type SchedulingPolicy =
164
380
  | "moon"
165
381
  | "gpu"
@@ -168,9 +384,18 @@ export type SchedulingPolicy =
168
384
  | "default"
169
385
  | (string & {});
170
386
 
387
+ /**
388
+ * A ContainerApplication resource representing a managed container deployment.
389
+ *
390
+ * This resource manages the lifecycle of containerized applications running on
391
+ * Cloudflare's global network with automatic scaling and scheduling.
392
+ */
171
393
  export interface ContainerApplication
172
394
  extends Resource<"cloudflare::ContainerApplication"> {
395
+ /** Unique identifier for the container application */
173
396
  id: string;
397
+
398
+ /** Human-readable name of the container application */
174
399
  name: string;
175
400
  }
176
401
 
@@ -394,43 +619,114 @@ export const ContainerApplication = Resource(
394
619
  },
395
620
  );
396
621
 
622
+ /**
623
+ * Complete data structure returned by the Cloudflare API for container applications.
624
+ *
625
+ * This interface represents the full state of a container application as stored
626
+ * and managed by Cloudflare's container service. It includes both user-configured
627
+ * properties and system-managed metadata.
628
+ */
397
629
  export interface ContainerApplicationData {
630
+ /** Human-readable name of the container application */
398
631
  name: string;
632
+
633
+ /** Scheduling policy controlling container placement and resource allocation */
399
634
  scheduling_policy: SchedulingPolicy;
635
+
636
+ /** Current number of running container instances */
400
637
  instances: number;
638
+
639
+ /** Maximum number of instances allowed for this application */
401
640
  max_instances: number;
641
+
642
+ /** Resource and placement constraints for the application */
402
643
  constraints: {
644
+ /** Infrastructure tier level (higher numbers indicate more resources) */
403
645
  tier: number;
646
+
647
+ /** Additional constraint properties that may be added by Cloudflare */
404
648
  [key: string]: any;
405
649
  };
650
+
651
+ /**
652
+ * The deployment configuration defining how containers should run.
653
+ * This includes image, compute resources, networking, and other runtime settings.
654
+ */
406
655
  configuration: {
656
+ /** Container image reference (tag or digest) */
407
657
  image: string;
658
+
659
+ /** Geographic location preference for deployment */
408
660
  location: string;
661
+
662
+ /** Number of virtual CPU cores allocated to each instance */
409
663
  vcpu: number;
664
+
665
+ /** Memory allocation in mebibytes (MiB) */
410
666
  memory_mib: number;
667
+
668
+ /** Disk configuration for persistent storage */
411
669
  disk: any;
670
+
671
+ /** Network configuration and policies */
412
672
  network: any;
673
+
674
+ /** Command to run when starting the container */
413
675
  command: string[];
676
+
677
+ /** Entrypoint command for the container */
414
678
  entrypoint: string[];
679
+
680
+ /** Container runtime to use (e.g., "runc") */
415
681
  runtime: string;
682
+
683
+ /** Type of deployment strategy */
416
684
  deployment_type: string;
685
+
686
+ /** Observability and monitoring configuration */
417
687
  observability: any;
688
+
689
+ /** Human-readable memory allocation (e.g., "512MB") */
418
690
  memory: string;
691
+
692
+ /** Additional configuration properties */
419
693
  [key: string]: any;
420
694
  };
695
+
696
+ /** Durable Objects integration configuration */
421
697
  durable_objects: {
698
+ /** ID of the Durable Objects namespace */
422
699
  namespace_id: string;
700
+
701
+ /** Additional Durable Objects properties */
423
702
  [key: string]: any;
424
703
  };
704
+
705
+ /** Unique identifier for the container application */
425
706
  id: string;
707
+
708
+ /** Cloudflare account ID that owns this application */
426
709
  account_id: string;
710
+
711
+ /** ISO 8601 timestamp when the application was created */
427
712
  created_at: string;
713
+
714
+ /** Version number of the application configuration */
428
715
  version: number;
716
+
717
+ /** Legacy field - ID of the Durable Objects namespace */
429
718
  durable_object_namespace_id: string;
719
+
720
+ /** Health status and metrics for all instances */
430
721
  health: {
722
+ /** Health information for individual instances */
431
723
  instances: any;
724
+
725
+ /** Additional health metrics */
432
726
  [key: string]: any;
433
727
  };
728
+
729
+ /** Additional properties that may be returned by the API */
434
730
  [key: string]: any;
435
731
  }
436
732
 
@@ -10,6 +10,7 @@ export interface D1MigrationOptions {
10
10
  accountId: string;
11
11
  databaseId: string;
12
12
  api: CloudflareApi;
13
+ quiet?: boolean;
13
14
  }
14
15
 
15
16
  const getPrefix = (name: string) => {
@@ -91,9 +92,11 @@ async function migrateLegacySchema(
91
92
  options: D1MigrationOptions,
92
93
  schema: { columns: Array<{ name: string; type: string; pk: number }> },
93
94
  ): Promise<void> {
94
- logger.log(
95
- `Migrating legacy migration table ${options.migrationsTable} to wrangler-compatible schema...`,
96
- );
95
+ if (!options.quiet) {
96
+ logger.log(
97
+ `Migrating legacy migration table ${options.migrationsTable} to wrangler-compatible schema...`,
98
+ );
99
+ }
97
100
 
98
101
  // Determine the current primary column name (could be 'id' or something else)
99
102
  const primaryColumn =
@@ -135,9 +138,11 @@ async function migrateLegacySchema(
135
138
  const renameTableSQL = `ALTER TABLE ${tempTableName} RENAME TO ${options.migrationsTable};`;
136
139
  await executeD1SQL(options, renameTableSQL);
137
140
 
138
- logger.log(
139
- "Successfully migrated migration table to wrangler-compatible schema",
140
- );
141
+ if (!options.quiet) {
142
+ logger.log(
143
+ "Successfully migrated migration table to wrangler-compatible schema",
144
+ );
145
+ }
141
146
  } catch (error) {
142
147
  // If migration fails, try to clean up temp table
143
148
  try {
@@ -195,9 +200,11 @@ export async function ensureMigrationsTable(
195
200
  applied_at TEXT NOT NULL
196
201
  );`;
197
202
  await executeD1SQL(options, createTableSQL);
198
- logger.log(
199
- `Created migration table ${options.migrationsTable} with wrangler-compatible schema`,
200
- );
203
+ if (!options.quiet) {
204
+ logger.log(
205
+ `Created migration table ${options.migrationsTable} with wrangler-compatible schema`,
206
+ );
207
+ }
201
208
  return;
202
209
  }
203
210
 
@@ -209,17 +216,21 @@ export async function ensureMigrationsTable(
209
216
 
210
217
  // If table exists but doesn't have the correct 3-column structure, we need to handle it
211
218
  if (!schema.hasIdColumn || !schema.hasNameColumn) {
212
- logger.log(
213
- `Migration table ${options.migrationsTable} has incomplete schema - attempting migration...`,
214
- );
219
+ if (!options.quiet) {
220
+ logger.log(
221
+ `Migration table ${options.migrationsTable} has incomplete schema - attempting migration...`,
222
+ );
223
+ }
215
224
  await migrateLegacySchema(options, schema);
216
225
  return;
217
226
  }
218
227
 
219
228
  // Table already has correct schema
220
- logger.log(
221
- `Migration table ${options.migrationsTable} already has correct schema`,
222
- );
229
+ if (!options.quiet) {
230
+ logger.log(
231
+ `Migration table ${options.migrationsTable} already has correct schema`,
232
+ );
233
+ }
223
234
  }
224
235
 
225
236
  /**
@@ -343,6 +354,8 @@ export async function applyMigrations(
343
354
  );
344
355
  }
345
356
 
346
- logger.log(`Applied migration: ${migrationName}`);
357
+ if (!options.quiet) {
358
+ logger.log(`Applied migration: ${migrationName}`);
359
+ }
347
360
  }
348
361
  }