@mastra/cloudflare-d1 1.0.5-alpha.0 → 1.0.5
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.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/cloudflare-d1
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `BackgroundTasksStorage` domain implementation so `@mastra/core` background task execution works with any storage adapter. ([#15307](https://github.com/mastra-ai/mastra/pull/15307))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`20f59b8`](https://github.com/mastra-ai/mastra/commit/20f59b876cf91199efbc49a0e36b391240708f08), [`aba393e`](https://github.com/mastra-ai/mastra/commit/aba393e2da7390c69b80e516a4f153cda6f09376), [`3d83d06`](https://github.com/mastra-ai/mastra/commit/3d83d06f776f00fb5f4163dddd32a030c5c20844), [`e2687a7`](https://github.com/mastra-ai/mastra/commit/e2687a7408790c384563816a9a28ed06735684c9), [`fdd54cf`](https://github.com/mastra-ai/mastra/commit/fdd54cf612a9af876e9fdd85e534454f6e7dd518), [`6315317`](https://github.com/mastra-ai/mastra/commit/63153175fe9a7b224e5be7c209bbebc01dd9b0d5), [`a371ac5`](https://github.com/mastra-ai/mastra/commit/a371ac534aa1bb368a1acf9d8b313378dfdc787e), [`0474c2b`](https://github.com/mastra-ai/mastra/commit/0474c2b2e7c7e1ad8691dca031284841391ff1ef), [`0a5fa1d`](https://github.com/mastra-ai/mastra/commit/0a5fa1d3cb0583889d06687155f26fd7d2edc76c), [`7e0e63e`](https://github.com/mastra-ai/mastra/commit/7e0e63e2e485e84442351f4c7a79a424c83539dc), [`ea43e64`](https://github.com/mastra-ai/mastra/commit/ea43e646dd95d507694b6112b0bf1df22ad552b2), [`f607106`](https://github.com/mastra-ai/mastra/commit/f607106854c6416c4a07d4082604b9f66d047221), [`30456b6`](https://github.com/mastra-ai/mastra/commit/30456b6b08c8fd17e109dd093b73d93b65e83bc5), [`9d11a8c`](https://github.com/mastra-ai/mastra/commit/9d11a8c1c8924eb975a245a5884d40ca1b7e0491), [`9d3b24b`](https://github.com/mastra-ai/mastra/commit/9d3b24b19407ae9c09586cf7766d38dc4dff4a69), [`00d1b16`](https://github.com/mastra-ai/mastra/commit/00d1b16b401199cb294fa23f43336547db4dca9b), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`62919a6`](https://github.com/mastra-ai/mastra/commit/62919a6ee0fbf3779ad21a97b1ec6696515d5104), [`d246696`](https://github.com/mastra-ai/mastra/commit/d246696139a3144a5b21b042d41c532688e957e1), [`354f9ce`](https://github.com/mastra-ai/mastra/commit/354f9ce1ca6af2074b6a196a23f8ec30012dccca), [`16e34ca`](https://github.com/mastra-ai/mastra/commit/16e34caa98b9a114b17a6125e4e3fd87f169d0d0), [`7020c06`](https://github.com/mastra-ai/mastra/commit/7020c0690b199d9da337f0e805f16948e557922e), [`8786a61`](https://github.com/mastra-ai/mastra/commit/8786a61fa54ba265f85eeff9985ca39863d18bb6), [`9467ea8`](https://github.com/mastra-ai/mastra/commit/9467ea87695749a53dfc041576410ebf9ee7bb67), [`7338d94`](https://github.com/mastra-ai/mastra/commit/7338d949380cf68b095342e8e42610dc51d557c1), [`c80dc16`](https://github.com/mastra-ai/mastra/commit/c80dc16e113e6cc159f510ffde501ad4711b2189), [`af8a57e`](https://github.com/mastra-ai/mastra/commit/af8a57ed9ba9685ad8601d5b71ae3706da6222f9), [`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`1bd5104`](https://github.com/mastra-ai/mastra/commit/1bd51048b6da93507276d6623e3fd96a9e1a8944), [`e9837b5`](https://github.com/mastra-ai/mastra/commit/e9837b53699e18711b09e0ca010a4106376f2653), [`8f1b280`](https://github.com/mastra-ai/mastra/commit/8f1b280b7fe6999ec654f160cb69c1a8719e7a57), [`92dcf02`](https://github.com/mastra-ai/mastra/commit/92dcf029294210ac91b090900c1a0555a425c57a), [`0fd90a2`](https://github.com/mastra-ai/mastra/commit/0fd90a215caf5fca8099c15a67ca03e4427747a3), [`8fb2405`](https://github.com/mastra-ai/mastra/commit/8fb2405138f2d208b7962ad03f121ca25bcc28c5), [`12df98c`](https://github.com/mastra-ai/mastra/commit/12df98c4904643d9481f5c78f3bed443725b4c96)]:
|
|
10
|
+
- @mastra/core@1.26.0
|
|
11
|
+
|
|
3
12
|
## 1.0.5-alpha.0
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-cloudflare-d1
|
|
|
3
3
|
description: Documentation for @mastra/cloudflare-d1. Use when working with @mastra/cloudflare-d1 APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/cloudflare-d1"
|
|
6
|
-
version: "1.0.5
|
|
6
|
+
version: "1.0.5"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -34,59 +34,59 @@ bun add @mastra/cloudflare-d1@latest
|
|
|
34
34
|
|
|
35
35
|
## Usage
|
|
36
36
|
|
|
37
|
-
### Using with
|
|
37
|
+
### Using with Mastra CloudflareDeployer
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
The standard way to use D1Store with Mastra on Cloudflare is with `CloudflareDeployer`. Import `env` from `cloudflare:workers` and initialize `D1Store` inline inside `new Mastra({...})`.
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
+
import { env } from 'cloudflare:workers'
|
|
42
43
|
import { D1Store } from '@mastra/cloudflare-d1'
|
|
43
44
|
import { Mastra } from '@mastra/core'
|
|
44
45
|
import { CloudflareDeployer } from '@mastra/deployer-cloudflare'
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
export const mastra = new Mastra({
|
|
48
|
+
storage: new D1Store({ binding: env.DB }),
|
|
49
|
+
deployer: new CloudflareDeployer({
|
|
50
|
+
name: 'my-worker',
|
|
51
|
+
d1_databases: [
|
|
52
|
+
{
|
|
53
|
+
binding: 'DB',
|
|
54
|
+
database_name: 'your-database-name',
|
|
55
|
+
database_id: 'your-database-id',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
> **Note:** When using `import { env } from 'cloudflare:workers'`, `D1Store` must be initialized inline inside `new Mastra({...})` — not extracted to a module-level variable. Alternatively, initialize `D1Store` inside the `fetch` handler after `env` is available. See [CloudflareDeployer reference](https://mastra.ai/reference/deployer/cloudflare) for details.
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
name: 'my-worker',
|
|
61
|
-
d1_databases: [
|
|
62
|
-
{
|
|
63
|
-
binding: 'D1Database', // Must match the property name in Env type
|
|
64
|
-
database_name: 'your-database-name',
|
|
65
|
-
database_id: 'your-database-id',
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
}),
|
|
69
|
-
})
|
|
64
|
+
### Using in a Cloudflare Worker without HTTP routes
|
|
65
|
+
|
|
66
|
+
If you want to call Mastra directly in a Worker — for example, to run an agent or trigger a workflow — without serving HTTP routes, you don't need `CloudflareDeployer`. Access the D1 binding from the worker's `env` parameter and call Mastra programmatically.
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import { D1Store } from '@mastra/cloudflare-d1'
|
|
70
|
+
import { Mastra } from '@mastra/core'
|
|
71
|
+
|
|
72
|
+
type Env = {
|
|
73
|
+
DB: D1Database
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
// Cloudflare Worker export
|
|
73
76
|
export default {
|
|
74
77
|
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
75
|
-
const mastra =
|
|
78
|
+
const mastra = new Mastra({
|
|
79
|
+
storage: new D1Store({ binding: env.DB }),
|
|
80
|
+
})
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
const agent = mastra.getAgent('my-agent')
|
|
83
|
+
const result = await agent.generate('Hello')
|
|
84
|
+
|
|
85
|
+
return Response.json({ text: result.text })
|
|
79
86
|
},
|
|
80
87
|
}
|
|
81
88
|
```
|
|
82
89
|
|
|
83
|
-
> **Important: Understanding D1 Bindings:** In the `Env` type definition, `D1Database: D1Database` serves two purposes:
|
|
84
|
-
>
|
|
85
|
-
> - The **property name** (`D1Database`) must match the `binding` name in your `wrangler.toml`
|
|
86
|
-
> - The **type** (`: D1Database`) is from `@cloudflare/workers-types` for TypeScript type checking
|
|
87
|
-
>
|
|
88
|
-
> At runtime, Cloudflare Workers provides the actual D1 database instance via `env.D1Database`. You can't use `D1Database` directly outside of the worker's context.
|
|
89
|
-
|
|
90
90
|
### Using with REST API
|
|
91
91
|
|
|
92
92
|
For non-Workers environments (Node.js, serverless functions, etc.), use the REST API approach:
|
|
@@ -108,7 +108,7 @@ Add the D1 database binding to your `wrangler.toml`:
|
|
|
108
108
|
|
|
109
109
|
```toml
|
|
110
110
|
[[d1_databases]]
|
|
111
|
-
binding = "
|
|
111
|
+
binding = "DB"
|
|
112
112
|
database_name = "your-database-name"
|
|
113
113
|
database_id = "your-database-id"
|
|
114
114
|
```
|
|
@@ -119,7 +119,7 @@ Or in `wrangler.jsonc`:
|
|
|
119
119
|
{
|
|
120
120
|
"d1_databases": [
|
|
121
121
|
{
|
|
122
|
-
"binding": "
|
|
122
|
+
"binding": "DB",
|
|
123
123
|
"database_name": "your-database-name",
|
|
124
124
|
"database_id": "your-database-id",
|
|
125
125
|
},
|
|
@@ -158,14 +158,14 @@ import { Mastra } from '@mastra/core'
|
|
|
158
158
|
import { D1Store } from '@mastra/cloudflare-d1'
|
|
159
159
|
|
|
160
160
|
type Env = {
|
|
161
|
-
|
|
161
|
+
DB: D1Database
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// In a Cloudflare Worker
|
|
165
165
|
export default {
|
|
166
166
|
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
167
167
|
const storage = new D1Store({
|
|
168
|
-
binding: env.
|
|
168
|
+
binding: env.DB,
|
|
169
169
|
})
|
|
170
170
|
|
|
171
171
|
const mastra = new Mastra({
|
|
@@ -184,7 +184,7 @@ If you're using storage directly without Mastra, you must call `init()` explicit
|
|
|
184
184
|
import { D1Store } from '@mastra/cloudflare-d1'
|
|
185
185
|
|
|
186
186
|
type Env = {
|
|
187
|
-
|
|
187
|
+
DB: D1Database
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
// In a Cloudflare Worker
|
|
@@ -192,7 +192,7 @@ export default {
|
|
|
192
192
|
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
193
193
|
const storage = new D1Store({
|
|
194
194
|
id: 'd1-storage',
|
|
195
|
-
binding: env.
|
|
195
|
+
binding: env.DB,
|
|
196
196
|
})
|
|
197
197
|
|
|
198
198
|
// Required when using storage directly
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/cloudflare-d1",
|
|
3
|
-
"version": "1.0.5
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "D1 provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -28,18 +28,18 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@cloudflare/workers-types": "^4.20260317.1",
|
|
30
30
|
"@types/node": "22.19.15",
|
|
31
|
-
"@vitest/coverage-v8": "4.
|
|
32
|
-
"@vitest/ui": "4.
|
|
31
|
+
"@vitest/coverage-v8": "4.1.4",
|
|
32
|
+
"@vitest/ui": "4.1.4",
|
|
33
33
|
"dotenv": "^17.3.1",
|
|
34
|
-
"eslint": "^
|
|
34
|
+
"eslint": "^10.2.1",
|
|
35
35
|
"miniflare": "^4.20260317.3",
|
|
36
36
|
"tsup": "^8.5.1",
|
|
37
37
|
"typescript": "^5.9.3",
|
|
38
|
-
"vitest": "4.
|
|
39
|
-
"@internal/
|
|
40
|
-
"@mastra/core": "1.
|
|
41
|
-
"@internal/
|
|
42
|
-
"@internal/
|
|
38
|
+
"vitest": "4.1.4",
|
|
39
|
+
"@internal/lint": "0.0.84",
|
|
40
|
+
"@mastra/core": "1.26.0",
|
|
41
|
+
"@internal/storage-test-utils": "0.0.80",
|
|
42
|
+
"@internal/types-builder": "0.0.59"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|