alchemy 0.51.3 → 0.53.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 (91) hide show
  1. package/lib/cloudflare/assets.d.ts +1 -1
  2. package/lib/cloudflare/assets.d.ts.map +1 -1
  3. package/lib/cloudflare/bindings.d.ts +12 -11
  4. package/lib/cloudflare/bindings.d.ts.map +1 -1
  5. package/lib/cloudflare/bindings.js.map +1 -1
  6. package/lib/cloudflare/bound.d.ts +11 -18
  7. package/lib/cloudflare/bound.d.ts.map +1 -1
  8. package/lib/cloudflare/bucket.d.ts +4 -5
  9. package/lib/cloudflare/bucket.d.ts.map +1 -1
  10. package/lib/cloudflare/bucket.js +1 -16
  11. package/lib/cloudflare/bucket.js.map +1 -1
  12. package/lib/cloudflare/compatibility-date.gen.d.ts +1 -1
  13. package/lib/cloudflare/compatibility-date.gen.js +1 -1
  14. package/lib/cloudflare/d1-database.d.ts +85 -26
  15. package/lib/cloudflare/d1-database.d.ts.map +1 -1
  16. package/lib/cloudflare/d1-database.js +66 -47
  17. package/lib/cloudflare/d1-database.js.map +1 -1
  18. package/lib/cloudflare/d1-local-migrations.d.ts +10 -0
  19. package/lib/cloudflare/d1-local-migrations.d.ts.map +1 -0
  20. package/lib/cloudflare/d1-local-migrations.js +39 -0
  21. package/lib/cloudflare/d1-local-migrations.js.map +1 -0
  22. package/lib/cloudflare/dispatch-namespace.d.ts +4 -6
  23. package/lib/cloudflare/dispatch-namespace.d.ts.map +1 -1
  24. package/lib/cloudflare/dispatch-namespace.js +1 -11
  25. package/lib/cloudflare/dispatch-namespace.js.map +1 -1
  26. package/lib/cloudflare/event-source.d.ts +3 -3
  27. package/lib/cloudflare/event-source.d.ts.map +1 -1
  28. package/lib/cloudflare/hyperdrive.d.ts +3 -4
  29. package/lib/cloudflare/hyperdrive.d.ts.map +1 -1
  30. package/lib/cloudflare/hyperdrive.js +1 -9
  31. package/lib/cloudflare/hyperdrive.js.map +1 -1
  32. package/lib/cloudflare/index.d.ts +1 -0
  33. package/lib/cloudflare/index.d.ts.map +1 -1
  34. package/lib/cloudflare/index.js +1 -0
  35. package/lib/cloudflare/index.js.map +1 -1
  36. package/lib/cloudflare/kv-namespace.d.ts +4 -5
  37. package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
  38. package/lib/cloudflare/kv-namespace.js +1 -14
  39. package/lib/cloudflare/kv-namespace.js.map +1 -1
  40. package/lib/cloudflare/pipeline.d.ts +4 -5
  41. package/lib/cloudflare/pipeline.d.ts.map +1 -1
  42. package/lib/cloudflare/pipeline.js +1 -12
  43. package/lib/cloudflare/pipeline.js.map +1 -1
  44. package/lib/cloudflare/queue-consumer.d.ts +3 -3
  45. package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
  46. package/lib/cloudflare/queue.d.ts +3 -4
  47. package/lib/cloudflare/queue.d.ts.map +1 -1
  48. package/lib/cloudflare/queue.js +1 -11
  49. package/lib/cloudflare/queue.js.map +1 -1
  50. package/lib/cloudflare/vectorize-index.d.ts +4 -5
  51. package/lib/cloudflare/vectorize-index.d.ts.map +1 -1
  52. package/lib/cloudflare/vectorize-index.js +1 -15
  53. package/lib/cloudflare/vectorize-index.js.map +1 -1
  54. package/lib/cloudflare/vectorize-metadata-index.d.ts +2 -2
  55. package/lib/cloudflare/vectorize-metadata-index.d.ts.map +1 -1
  56. package/lib/cloudflare/worker-ref.d.ts +41 -0
  57. package/lib/cloudflare/worker-ref.d.ts.map +1 -0
  58. package/lib/cloudflare/worker-ref.js +27 -0
  59. package/lib/cloudflare/worker-ref.js.map +1 -0
  60. package/lib/cloudflare/worker.d.ts +6 -68
  61. package/lib/cloudflare/worker.d.ts.map +1 -1
  62. package/lib/cloudflare/worker.js +5 -198
  63. package/lib/cloudflare/worker.js.map +1 -1
  64. package/lib/cloudflare/wrangler.json.js +2 -2
  65. package/lib/cloudflare/wrangler.json.js.map +1 -1
  66. package/lib/esbuild/bundle.d.ts +2 -2
  67. package/lib/state/instrumented-state-store.d.ts +2 -0
  68. package/lib/state/instrumented-state-store.d.ts.map +1 -1
  69. package/lib/state/instrumented-state-store.js +2 -0
  70. package/lib/state/instrumented-state-store.js.map +1 -1
  71. package/package.json +1 -1
  72. package/src/cloudflare/bindings.ts +18 -17
  73. package/src/cloudflare/bound.ts +35 -18
  74. package/src/cloudflare/bucket.ts +5 -27
  75. package/src/cloudflare/compatibility-date.gen.ts +1 -1
  76. package/src/cloudflare/d1-database.ts +107 -100
  77. package/src/cloudflare/d1-local-migrations.ts +52 -0
  78. package/src/cloudflare/dispatch-namespace.ts +6 -25
  79. package/src/cloudflare/event-source.ts +3 -3
  80. package/src/cloudflare/hyperdrive.ts +4 -19
  81. package/src/cloudflare/index.ts +1 -0
  82. package/src/cloudflare/kv-namespace.ts +5 -28
  83. package/src/cloudflare/pipeline.ts +8 -27
  84. package/src/cloudflare/queue-consumer.ts +3 -3
  85. package/src/cloudflare/queue.ts +4 -22
  86. package/src/cloudflare/vectorize-index.ts +5 -27
  87. package/src/cloudflare/vectorize-metadata-index.ts +2 -2
  88. package/src/cloudflare/worker-ref.ts +51 -0
  89. package/src/cloudflare/worker.ts +16 -332
  90. package/src/cloudflare/wrangler.json.ts +2 -2
  91. package/src/state/instrumented-state-store.ts +2 -0
@@ -102,12 +102,12 @@ export declare function bundle(props: BundleProps): Promise<esbuild.BuildResult<
102
102
  outdir: string | undefined;
103
103
  outfile: string | undefined;
104
104
  bundle: boolean;
105
- format: "esm" | "cjs" | "iife" | undefined;
105
+ format: "iife" | "cjs" | "esm" | undefined;
106
106
  target: string | string[] | undefined;
107
107
  minify: boolean | undefined;
108
108
  sourcemap: boolean | "external" | "inline" | "both" | undefined;
109
109
  external: string[] | undefined;
110
- platform: "browser" | "node" | "neutral" | undefined;
110
+ platform: "node" | "browser" | "neutral" | undefined;
111
111
  metafile: boolean;
112
112
  splitting?: boolean | undefined;
113
113
  preserveSymlinks?: boolean | undefined;
@@ -1,6 +1,8 @@
1
1
  import type { State, StateStore } from "../state.ts";
2
2
  import type { ITelemetryClient } from "../util/telemetry/client.ts";
3
3
  export declare class InstrumentedStateStore<T extends StateStore> implements StateStore {
4
+ /** @internal */
5
+ __phantom?: T;
4
6
  private readonly stateStore;
5
7
  private readonly telemetryClient;
6
8
  private readonly stateStoreClass;
@@ -1 +1 @@
1
- {"version":3,"file":"instrumented-state-store.d.ts","sourceRoot":"","sources":["../../src/state/instrumented-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAIpE,qBAAa,sBAAsB,CAAC,CAAC,SAAS,UAAU,CACtD,YAAW,UAAU;IAErB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmB;IACnD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,gBAAgB;YAMvD,iBAAiB;IAkBzB,IAAI;IASJ,MAAM;IASN,IAAI;IAMJ,KAAK;IAML,GAAG,CAAC,GAAG,EAAE,MAAM;IAMf,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE;IAMtB,GAAG;IAMH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAM7B,MAAM,CAAC,GAAG,EAAE,MAAM;CAMzB"}
1
+ {"version":3,"file":"instrumented-state-store.d.ts","sourceRoot":"","sources":["../../src/state/instrumented-state-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAIpE,qBAAa,sBAAsB,CAAC,CAAC,SAAS,UAAU,CACtD,YAAW,UAAU;IAErB,gBAAgB;IAChB,SAAS,CAAC,EAAE,CAAC,CAAC;IACd,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAmB;IACnD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,gBAAgB;YAMvD,iBAAiB;IAkBzB,IAAI;IASJ,MAAM;IASN,IAAI;IAMJ,KAAK;IAML,GAAG,CAAC,GAAG,EAAE,MAAM;IAMf,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE;IAMtB,GAAG;IAMH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAM7B,MAAM,CAAC,GAAG,EAAE,MAAM;CAMzB"}
@@ -1,5 +1,7 @@
1
1
  //todo(michael): we should also handle serde here
2
2
  export class InstrumentedStateStore {
3
+ /** @internal */
4
+ __phantom;
3
5
  stateStore;
4
6
  telemetryClient;
5
7
  stateStoreClass;
@@ -1 +1 @@
1
- {"version":3,"file":"instrumented-state-store.js","sourceRoot":"","sources":["../../src/state/instrumented-state-store.ts"],"names":[],"mappings":"AAIA,iDAAiD;AACjD,MAAM,OAAO,sBAAsB;IAGhB,UAAU,CAAa;IACvB,eAAe,CAAmB;IAClC,eAAe,CAAS;IAEzC,YAAY,UAAsB,EAAE,eAAiC;QACnE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC;IACrD,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAC7B,KAAyC,EACzC,EAAoB;QAEpB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAChC,IAAI,KAAc,CAAC;QACnB,OAAO,MAAM,EAAE,EAAE;aACd,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC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IACJ,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,MAAM,IAAI,CAAC,iBAAiB,CACjC,gBAAgB,EAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAC/C,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,QAAQ,CAAC,GAAa;QAC1B,OAAO,MAAM,IAAI,CAAC,iBAAiB,CACjC,qBAAqB,EACrB,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CACpD,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,GAAG;QACP,OAAO,MAAM,IAAI,CAAC,iBAAiB,CACjC,gBAAgB,EAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAC1C,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAY;QACjC,MAAM,IAAI,CAAC,iBAAiB,CAC1B,gBAAgB,EAChB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,CACtD,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,IAAI,CAAC,iBAAiB,CAC1B,mBAAmB,EACnB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAClD,CAAC;IACJ,CAAC;CACF"}
1
+ {"version":3,"file":"instrumented-state-store.js","sourceRoot":"","sources":["../../src/state/instrumented-state-store.ts"],"names":[],"mappings":"AAIA,iDAAiD;AACjD,MAAM,OAAO,sBAAsB;IAGjC,gBAAgB;IAChB,SAAS,CAAK;IACG,UAAU,CAAa;IACvB,eAAe,CAAmB;IAClC,eAAe,CA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AAC,CACtD,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,IAAI,CAAC,iBAAiB,CAC1B,mBAAmB,EACnB,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAClD,CAAC;IACJ,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alchemy",
3
- "version": "0.51.3",
3
+ "version": "0.53.0",
4
4
  "license": "Apache-2.0",
5
5
  "author": "Sam Goodwin <sam@alchemy.run>",
6
6
  "homepage": "https://alchemy.run",
@@ -10,23 +10,24 @@ import type { AnalyticsEngineDataset } from "./analytics-engine.ts";
10
10
  import type { Assets } from "./assets.ts";
11
11
  import type { Bound } from "./bound.ts";
12
12
  import type { BrowserRendering } from "./browser-rendering.ts";
13
- import type { R2BucketResource } from "./bucket.ts";
13
+ import type { R2Bucket } from "./bucket.ts";
14
14
  import type { Container } from "./container.ts";
15
- import type { D1DatabaseResource } from "./d1-database.ts";
16
- import type { DispatchNamespaceResource } from "./dispatch-namespace.ts";
15
+ import type { D1Database } from "./d1-database.ts";
16
+ import type { DispatchNamespace } from "./dispatch-namespace.ts";
17
17
  import type { DurableObjectNamespace } from "./durable-object-namespace.ts";
18
- import type { HyperdriveResource } from "./hyperdrive.ts";
18
+ import type { Hyperdrive } from "./hyperdrive.ts";
19
19
  import type { Images } from "./images.ts";
20
- import type { KVNamespaceResource } from "./kv-namespace.ts";
21
- import type { PipelineResource } from "./pipeline.ts";
22
- import type { QueueResource } from "./queue.ts";
20
+ import type { KVNamespace } from "./kv-namespace.ts";
21
+ import type { Pipeline } from "./pipeline.ts";
22
+ import type { Queue } from "./queue.ts";
23
23
  import type { RateLimit } from "./rate-limit.ts";
24
24
  import type { SecretKey } from "./secret-key.ts";
25
25
  import type { Secret as CloudflareSecret } from "./secret.ts";
26
- import type { VectorizeIndexResource } from "./vectorize-index.ts";
26
+ import type { VectorizeIndex } from "./vectorize-index.ts";
27
27
  import type { VersionMetadata } from "./version-metadata.ts";
28
+ import type { WorkerRef } from "./worker-ref.ts";
28
29
  import type { WorkerStub } from "./worker-stub.ts";
29
- import type { Worker, WorkerRef } from "./worker.ts";
30
+ import type { Worker } from "./worker.ts";
30
31
  import type { Workflow } from "./workflow.ts";
31
32
 
32
33
  export type Bindings = {
@@ -48,17 +49,17 @@ export type Binding =
48
49
  | Assets
49
50
  | Container
50
51
  | CloudflareSecret
51
- | D1DatabaseResource
52
- | DispatchNamespaceResource
52
+ | D1Database
53
+ | DispatchNamespace
53
54
  | AnalyticsEngineDataset
54
55
  | DurableObjectNamespace<any>
55
- | HyperdriveResource
56
+ | Hyperdrive
56
57
  | Images
57
- | KVNamespaceResource
58
- | PipelineResource
59
- | QueueResource
58
+ | KVNamespace
59
+ | Pipeline
60
+ | Queue
60
61
  | RateLimit
61
- | R2BucketResource
62
+ | R2Bucket
62
63
  | {
63
64
  type: "kv_namespace";
64
65
  id: string;
@@ -66,7 +67,7 @@ export type Binding =
66
67
  | Secret
67
68
  | SecretKey
68
69
  | string
69
- | VectorizeIndexResource
70
+ | VectorizeIndex
70
71
  | Worker
71
72
  | WorkerStub
72
73
  | WorkerRef
@@ -1,3 +1,24 @@
1
+ import type {
2
+ Ai,
3
+ AiGateway,
4
+ AnalyticsEngineDataset,
5
+ D1Database,
6
+ DispatchNamespace,
7
+ DurableObjectNamespace,
8
+ Fetcher,
9
+ Hyperdrive,
10
+ ImagesBinding,
11
+ KVNamespace,
12
+ Queue,
13
+ R2Bucket,
14
+ RateLimit,
15
+ Rpc,
16
+ SecretsStoreSecret,
17
+ Service,
18
+ VectorizeIndex,
19
+ WorkerVersionMetadata,
20
+ Workflow,
21
+ } from "@cloudflare/workers-types";
1
22
  import type { Pipeline } from "cloudflare:pipelines";
2
23
  import type { Secret } from "../secret.ts";
3
24
  import type { AiGatewayResource as _AiGateway } from "./ai-gateway.ts";
@@ -6,22 +27,22 @@ import type { AnalyticsEngineDataset as _AnalyticsEngineDataset } from "./analyt
6
27
  import type { Assets } from "./assets.ts";
7
28
  import type { Binding, Json, Self } from "./bindings.ts";
8
29
  import type { BrowserRendering } from "./browser-rendering.ts";
9
- import type { R2BucketResource as _R2Bucket } from "./bucket.ts";
30
+ import type { R2Bucket as _R2Bucket } from "./bucket.ts";
10
31
  import type { Container as _Container } from "./container.ts";
11
- import type { D1DatabaseResource } from "./d1-database.ts";
12
- import type { DispatchNamespaceResource } from "./dispatch-namespace.ts";
32
+ import type { D1Database as _D1Database } from "./d1-database.ts";
13
33
  import type { DurableObjectNamespace as _DurableObjectNamespace } from "./durable-object-namespace.ts";
14
- import type { HyperdriveResource as _Hyperdrive } from "./hyperdrive.ts";
34
+ import type { Hyperdrive as _Hyperdrive } from "./hyperdrive.ts";
15
35
  import type { Images as _Images } from "./images.ts";
16
- import type { PipelineResource as _Pipeline } from "./pipeline.ts";
17
- import type { QueueResource as _Queue } from "./queue.ts";
18
- import type { RateLimit } from "./rate-limit.ts";
36
+ import type { Pipeline as _Pipeline } from "./pipeline.ts";
37
+ import type { Queue as _Queue } from "./queue.ts";
38
+ import type { RateLimit as _RateLimit } from "./rate-limit.ts";
19
39
  import type { SecretKey } from "./secret-key.ts";
20
40
  import type { Secret as CloudflareSecret } from "./secret.ts";
21
- import type { VectorizeIndexResource as _VectorizeIndex } from "./vectorize-index.ts";
41
+ import type { VectorizeIndex as _VectorizeIndex } from "./vectorize-index.ts";
22
42
  import type { VersionMetadata as _VersionMetadata } from "./version-metadata.ts";
43
+ import type { WorkerRef } from "./worker-ref.ts";
23
44
  import type { WorkerStub } from "./worker-stub.ts";
24
- import type { Worker as _Worker, WorkerRef } from "./worker.ts";
45
+ import type { Worker as _Worker } from "./worker.ts";
25
46
  import type { Workflow as _Workflow } from "./workflow.ts";
26
47
 
27
48
  type BoundWorker<
@@ -63,10 +84,10 @@ export type Bound<T extends Binding> = T extends _DurableObjectNamespace<
63
84
  ? Service
64
85
  : T extends _Workflow<infer P>
65
86
  ? Workflow<P>
66
- : T extends D1DatabaseResource
87
+ : T extends _D1Database
67
88
  ? D1Database
68
- : T extends DispatchNamespaceResource
69
- ? { get(name: string): Fetcher }
89
+ : T extends DispatchNamespace
90
+ ? DispatchNamespace
70
91
  : T extends _VectorizeIndex
71
92
  ? VectorizeIndex
72
93
  : T extends _Queue<infer Body>
@@ -75,12 +96,8 @@ export type Bound<T extends Binding> = T extends _DurableObjectNamespace<
75
96
  ? AnalyticsEngineDataset
76
97
  : T extends _Pipeline<infer R>
77
98
  ? Pipeline<R>
78
- : T extends RateLimit
79
- ? {
80
- limit(options: {
81
- key: string;
82
- }): Promise<{ success: boolean }>;
83
- }
99
+ : T extends _RateLimit
100
+ ? RateLimit
84
101
  : T extends string
85
102
  ? string
86
103
  : T extends BrowserRendering
@@ -1,7 +1,6 @@
1
1
  import { isDeepStrictEqual } from "node:util";
2
2
  import type { Context } from "../context.ts";
3
3
  import { Resource, ResourceKind } from "../resource.ts";
4
- import { bind } from "../runtime/bind.ts";
5
4
  import { withExponentialBackoff } from "../util/retry.ts";
6
5
  import { CloudflareApiError } from "./api-error.ts";
7
6
  import {
@@ -13,7 +12,6 @@ import {
13
12
  type CloudflareApi,
14
13
  type CloudflareApiOptions,
15
14
  } from "./api.ts";
16
- import type { Bound } from "./bound.ts";
17
15
 
18
16
  /**
19
17
  * Properties for creating or updating an R2 Bucket
@@ -128,7 +126,7 @@ interface R2BucketCORSRule {
128
126
  /**
129
127
  * Output returned after R2 Bucket creation/update
130
128
  */
131
- export type R2BucketResource = Resource<"cloudflare::R2Bucket"> &
129
+ export type R2Bucket = Resource<"cloudflare::R2Bucket"> &
132
130
  Omit<BucketProps, "delete"> & {
133
131
  /**
134
132
  * Resource type identifier
@@ -156,12 +154,10 @@ export type R2BucketResource = Resource<"cloudflare::R2Bucket"> &
156
154
  domain: string | undefined;
157
155
  };
158
156
 
159
- export function isBucket(resource: Resource): resource is R2BucketResource {
157
+ export function isBucket(resource: Resource): resource is R2Bucket {
160
158
  return resource[ResourceKind] === "cloudflare::R2Bucket";
161
159
  }
162
160
 
163
- export type R2Bucket = R2BucketResource & Bound<R2BucketResource>;
164
-
165
161
  /**
166
162
  * Creates and manages Cloudflare R2 Buckets for object storage.
167
163
  *
@@ -206,31 +202,13 @@ export type R2Bucket = R2BucketResource & Bound<R2BucketResource>;
206
202
  *
207
203
  * @see https://developers.cloudflare.com/r2/buckets/
208
204
  */
209
- export async function R2Bucket(
210
- name: string,
211
- props: BucketProps = {},
212
- ): Promise<R2Bucket> {
213
- const bucket = await R2BucketResource(name, props);
214
- const binding = await bind(bucket);
215
- return {
216
- ...bucket,
217
- createMultipartUpload: binding.createMultipartUpload,
218
- delete: binding.delete,
219
- get: binding.get,
220
- list: binding.list,
221
- put: binding.put,
222
- head: binding.head,
223
- resumeMultipartUpload: binding.resumeMultipartUpload,
224
- };
225
- }
226
-
227
- const R2BucketResource = Resource(
205
+ export const R2Bucket = Resource(
228
206
  "cloudflare::R2Bucket",
229
207
  async function (
230
- this: Context<R2BucketResource>,
208
+ this: Context<R2Bucket>,
231
209
  _id: string,
232
210
  props: BucketProps = {},
233
- ): Promise<R2BucketResource> {
211
+ ): Promise<R2Bucket> {
234
212
  const api = await createCloudflareApi(props);
235
213
  const bucketName = props.name || this.id;
236
214
  const allowPublicAccess = props.allowPublicAccess === true;
@@ -4,4 +4,4 @@
4
4
  /**
5
5
  * The default Cloudflare Workers compatibility date, set based on the latest workerd release at the time of build.
6
6
  */
7
- export const DEFAULT_COMPATIBILITY_DATE = "2025-07-23";
7
+ export const DEFAULT_COMPATIBILITY_DATE = "2025-07-24";
@@ -1,6 +1,6 @@
1
1
  import type { Context } from "../context.ts";
2
2
  import { Resource, ResourceKind } from "../resource.ts";
3
- import { bind, type Bound } from "../runtime/bind.ts";
3
+ import { Scope } from "../scope.ts";
4
4
  import { logger } from "../util/logger.ts";
5
5
  import { CloudflareApiError, handleApiError } from "./api-error.ts";
6
6
  import {
@@ -9,8 +9,20 @@ import {
9
9
  type CloudflareApiOptions,
10
10
  } from "./api.ts";
11
11
  import { cloneD1Database } from "./d1-clone.ts";
12
+ import { applyLocalD1Migrations } from "./d1-local-migrations.ts";
12
13
  import { applyMigrations, listMigrationsFiles } from "./d1-migrations.ts";
13
14
 
15
+ const DEFAULT_MIGRATIONS_TABLE = "d1_migrations";
16
+
17
+ type PrimaryLocationHint =
18
+ | "wnam"
19
+ | "enam"
20
+ | "weur"
21
+ | "eeur"
22
+ | "apac"
23
+ | "auto"
24
+ | (string & {});
25
+
14
26
  /**
15
27
  * Properties for creating or updating a D1 Database
16
28
  */
@@ -26,14 +38,7 @@ export interface D1DatabaseProps extends CloudflareApiOptions {
26
38
  * Optional primary location hint for the database
27
39
  * Indicates the primary geographical location data will be stored
28
40
  */
29
- primaryLocationHint?:
30
- | "wnam"
31
- | "enam"
32
- | "weur"
33
- | "eeur"
34
- | "apac"
35
- | "auto"
36
- | string;
41
+ primaryLocationHint?: PrimaryLocationHint;
37
42
 
38
43
  /**
39
44
  * Read replication configuration
@@ -102,20 +107,31 @@ export interface D1DatabaseProps extends CloudflareApiOptions {
102
107
  * @default false
103
108
  */
104
109
  remote?: boolean;
110
+
111
+ /**
112
+ * Set when `Scope.local` is true to force update to the database even if it was already deployed live.
113
+ * @internal
114
+ */
115
+ force?: boolean;
105
116
  };
106
117
  }
107
118
 
108
- export function isD1Database(
109
- resource: Resource,
110
- ): resource is D1DatabaseResource {
119
+ export function isD1Database(resource: Resource): resource is D1Database {
111
120
  return resource[ResourceKind] === "cloudflare::D1Database";
112
121
  }
113
122
 
114
123
  /**
115
124
  * Output returned after D1 Database creation/update
116
125
  */
117
- export type D1DatabaseResource = Resource<"cloudflare::D1Database"> &
118
- D1DatabaseProps & {
126
+ export type D1Database = Resource<"cloudflare::D1Database"> &
127
+ Pick<
128
+ D1DatabaseProps,
129
+ | "dev"
130
+ | "migrationsDir"
131
+ | "migrationsTable"
132
+ | "primaryLocationHint"
133
+ | "readReplication"
134
+ > & {
119
135
  type: "d1";
120
136
  /**
121
137
  * The unique ID of the database (UUID)
@@ -126,61 +142,8 @@ export type D1DatabaseResource = Resource<"cloudflare::D1Database"> &
126
142
  * The name of the database
127
143
  */
128
144
  name: string;
129
-
130
- /**
131
- * File size of the database
132
- */
133
- fileSize: number;
134
-
135
- /**
136
- * Number of tables in the database
137
- */
138
- numTables: number;
139
-
140
- /**
141
- * Version of the database
142
- */
143
- version: string;
144
-
145
- /**
146
- * Read replication configuration
147
- */
148
- readReplication?: {
149
- /**
150
- * Read replication mode
151
- */
152
- mode: "auto" | "disabled";
153
- };
154
145
  };
155
146
 
156
- export type D1Database = D1DatabaseResource & Bound<D1DatabaseResource>;
157
-
158
- export async function D1Database(
159
- id: string,
160
- props: Omit<D1DatabaseProps, "migrationsFiles"> = {},
161
- ): Promise<D1Database> {
162
- const migrationsFiles = props.migrationsDir
163
- ? await listMigrationsFiles(props.migrationsDir)
164
- : [];
165
-
166
- const db = await D1DatabaseResource(id, {
167
- ...props,
168
- migrationsFiles,
169
- });
170
- const binding = await bind(db);
171
- return {
172
- ...db,
173
- batch: binding.batch,
174
- exec: binding.exec,
175
- prepare: binding.prepare,
176
- withSession: binding.withSession,
177
- /**
178
- * @deprecated
179
- */
180
- dump: binding.dump,
181
- };
182
- }
183
-
184
147
  /**
185
148
  * Creates and manages Cloudflare D1 Databases.
186
149
  *
@@ -257,13 +220,33 @@ export async function D1Database(
257
220
  *
258
221
  * @see https://developers.cloudflare.com/d1/
259
222
  */
260
- const D1DatabaseResource = Resource(
223
+ export async function D1Database(
224
+ id: string,
225
+ props: Omit<D1DatabaseProps, "migrationsFiles"> = {},
226
+ ): Promise<D1Database> {
227
+ const migrationsFiles = props.migrationsDir
228
+ ? await listMigrationsFiles(props.migrationsDir)
229
+ : [];
230
+
231
+ return _D1Database(id, {
232
+ ...props,
233
+ migrationsFiles,
234
+ dev: {
235
+ ...(props.dev ?? {}),
236
+ // force local migrations to run even if the database was already deployed live
237
+ // this property will oscillate from true to false depending on the dev vs live deployment
238
+ force: Scope.current.local,
239
+ },
240
+ });
241
+ }
242
+
243
+ const _D1Database = Resource(
261
244
  "cloudflare::D1Database",
262
245
  async function (
263
- this: Context<D1DatabaseResource>,
246
+ this: Context<D1Database>,
264
247
  id: string,
265
248
  props: D1DatabaseProps = {},
266
- ): Promise<D1DatabaseResource> {
249
+ ): Promise<D1Database> {
267
250
  const api = await createCloudflareApi(props);
268
251
  const databaseName = props.name ?? id;
269
252
 
@@ -276,7 +259,33 @@ const D1DatabaseResource = Resource(
276
259
  }
277
260
  let dbData: CloudflareD1Response;
278
261
 
279
- if (this.phase === "create") {
262
+ if (this.scope.local && !props.dev?.remote) {
263
+ if (props.migrationsFiles && props.migrationsFiles.length > 0) {
264
+ await applyLocalD1Migrations({
265
+ databaseId: this.output?.id ?? id,
266
+ migrationsTable: props.migrationsTable ?? DEFAULT_MIGRATIONS_TABLE,
267
+ migrations: props.migrationsFiles,
268
+ });
269
+ }
270
+ return this({
271
+ type: "d1",
272
+ // we may not have an ID yet if we're creating a new database locally first
273
+ // so set it to the resource ID which we can later use to detect that a DB needs to be created during an `update`
274
+ id: this.output?.id ?? id,
275
+ name: databaseName,
276
+ readReplication: props.readReplication,
277
+ primaryLocationHint: props.primaryLocationHint,
278
+ migrationsDir: props.migrationsDir,
279
+ migrationsTable: props.migrationsTable ?? DEFAULT_MIGRATIONS_TABLE,
280
+ dev: props.dev,
281
+ });
282
+ } else if (
283
+ this.phase === "create" ||
284
+ // this is true IFF the database was created locally before any live deployment
285
+ // in that case, we should still go through the create flow for "update"
286
+ // after that, the ID will remain the UUID for the lifetime of the database
287
+ this.output.id === id
288
+ ) {
280
289
  logger.log("Creating D1 database:", databaseName);
281
290
  try {
282
291
  dbData = await createDatabase(api, databaseName, props);
@@ -323,35 +332,33 @@ const D1DatabaseResource = Resource(
323
332
  throw error;
324
333
  }
325
334
  }
326
- } else {
327
- // Update operation
328
- if (this.output?.id) {
329
- // Only read_replication can be modified in update
330
- if (
331
- props.primaryLocationHint &&
332
- props.primaryLocationHint !== this.output?.primaryLocationHint
333
- ) {
334
- throw new Error(
335
- `Cannot update primaryLocationHint from '${this.output.primaryLocationHint}' to '${props.primaryLocationHint}' after database creation.`,
336
- );
337
- }
338
- logger.log("Updating D1 database:", databaseName);
339
- // Update the database with new properties
340
- dbData = await updateDatabase(api, this.output.id, props);
341
- } else {
342
- // If no ID exists, fall back to creating a new database
343
- logger.log(
344
- "No existing database ID found, creating new D1 database:",
345
- databaseName,
335
+ } else if (this.output?.id) {
336
+ // Only read_replication can be modified in update
337
+ if (
338
+ props.primaryLocationHint &&
339
+ props.primaryLocationHint !== this.output?.primaryLocationHint
340
+ ) {
341
+ throw new Error(
342
+ `Cannot update primaryLocationHint from '${this.output.primaryLocationHint}' to '${props.primaryLocationHint}' after database creation.`,
346
343
  );
347
- dbData = await createDatabase(api, databaseName, props);
348
344
  }
345
+ logger.log("Updating D1 database:", databaseName);
346
+ // Update the database with new properties
347
+ dbData = await updateDatabase(api, this.output.id, props);
348
+ } else {
349
+ // If no ID exists, fall back to creating a new database
350
+ logger.log(
351
+ "No existing database ID found, creating new D1 database:",
352
+ databaseName,
353
+ );
354
+ dbData = await createDatabase(api, databaseName, props);
349
355
  }
350
356
 
351
357
  // Run migrations if provided
352
358
  if (props.migrationsFiles && props.migrationsFiles.length > 0) {
353
359
  try {
354
- const migrationsTable = props.migrationsTable || "d1_migrations";
360
+ const migrationsTable =
361
+ props.migrationsTable || DEFAULT_MIGRATIONS_TABLE;
355
362
  const databaseId = dbData.result.uuid || this.output?.id;
356
363
 
357
364
  if (!databaseId) {
@@ -370,19 +377,19 @@ const D1DatabaseResource = Resource(
370
377
  throw migrationErr;
371
378
  }
372
379
  }
373
-
380
+ if (!dbData.result.uuid) {
381
+ // TODO(sam): why would this ever happen?
382
+ throw new Error("Database ID not found");
383
+ }
374
384
  return this({
375
385
  type: "d1",
376
- id: dbData.result.uuid || "",
386
+ id: dbData.result.uuid!,
377
387
  name: databaseName,
378
- dev: props.dev,
379
- fileSize: dbData.result.file_size,
380
- numTables: dbData.result.num_tables,
381
- version: dbData.result.version,
382
388
  readReplication: dbData.result.read_replication,
383
389
  primaryLocationHint: props.primaryLocationHint,
384
- accountId: api.accountId,
390
+ dev: props.dev,
385
391
  migrationsDir: props.migrationsDir,
392
+ migrationsTable: props.migrationsTable ?? DEFAULT_MIGRATIONS_TABLE,
386
393
  });
387
394
  },
388
395
  );
@@ -0,0 +1,52 @@
1
+ import * as mf from "miniflare";
2
+ import path from "node:path";
3
+
4
+ export interface D1LocalMigrationOptions {
5
+ databaseId: string;
6
+ migrationsTable: string;
7
+ migrations: { id: string; sql: string }[];
8
+ }
9
+
10
+ export const applyLocalD1Migrations = async (
11
+ options: D1LocalMigrationOptions,
12
+ ) => {
13
+ const miniflare = new mf.Miniflare({
14
+ script: "",
15
+ modules: true,
16
+ defaultPersistRoot: path.join(process.cwd(), ".alchemy/miniflare"),
17
+ d1Persist: true,
18
+ d1Databases: { DB: options.databaseId },
19
+ log: process.env.DEBUG ? new mf.Log(mf.LogLevel.DEBUG) : undefined,
20
+ });
21
+ try {
22
+ await miniflare.ready;
23
+ const db = await miniflare.getD1Database("DB");
24
+ const session = db.withSession("first-primary");
25
+ await session
26
+ .prepare(
27
+ `CREATE TABLE IF NOT EXISTS ${options.migrationsTable} (
28
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
29
+ name TEXT NOT NULL,
30
+ applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
31
+ )`,
32
+ )
33
+ .run();
34
+ const appliedMigrations = await session
35
+ .prepare(
36
+ `SELECT name FROM ${options.migrationsTable} ORDER BY applied_at ASC`,
37
+ )
38
+ .all<{ name: string }>();
39
+ const insertRecord = session.prepare(
40
+ `INSERT INTO ${options.migrationsTable} (name) VALUES (?)`,
41
+ );
42
+ for (const migration of options.migrations) {
43
+ if (appliedMigrations.results.some((m) => m.name === migration.id)) {
44
+ continue;
45
+ }
46
+ await session.prepare(migration.sql).run();
47
+ await insertRecord.bind(migration.id).run();
48
+ }
49
+ } finally {
50
+ await miniflare.dispose();
51
+ }
52
+ };