@mastra/cloudflare-d1 1.0.0 → 1.0.1-alpha.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.
- package/CHANGELOG.md +9 -0
- package/LICENSE.md +15 -0
- package/dist/docs/SKILL.md +12 -22
- package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
- package/dist/docs/references/reference-storage-cloudflare-d1.md +218 -0
- package/dist/index.cjs +11 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -14
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +3 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +11 -12
- package/dist/docs/README.md +0 -31
- package/dist/docs/storage/01-reference.md +0 -110
|
@@ -5,16 +5,17 @@ import type { D1DomainConfig } from '../../db/index.js';
|
|
|
5
5
|
export declare class WorkflowsStorageD1 extends WorkflowsStorage {
|
|
6
6
|
#private;
|
|
7
7
|
constructor(config: D1DomainConfig);
|
|
8
|
+
supportsConcurrentUpdates(): boolean;
|
|
8
9
|
init(): Promise<void>;
|
|
9
10
|
dangerouslyClearAll(): Promise<void>;
|
|
10
|
-
updateWorkflowResults(
|
|
11
|
+
updateWorkflowResults(_args: {
|
|
11
12
|
workflowName: string;
|
|
12
13
|
runId: string;
|
|
13
14
|
stepId: string;
|
|
14
15
|
result: StepResult<any, any, any, any>;
|
|
15
16
|
requestContext: Record<string, any>;
|
|
16
17
|
}): Promise<Record<string, StepResult<any, any, any, any>>>;
|
|
17
|
-
updateWorkflowState(
|
|
18
|
+
updateWorkflowState(_args: {
|
|
18
19
|
workflowName: string;
|
|
19
20
|
runId: string;
|
|
20
21
|
opts: UpdateWorkflowStateOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/workflows/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,E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@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/cloudflare-d1",
|
|
3
|
-
"version": "1.0.0",
|
|
3
|
+
"version": "1.0.1-alpha.0",
|
|
4
4
|
"description": "D1 provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@cloudflare/workers-types": "^4.20251111.0",
|
|
30
|
-
"@types/node": "22.
|
|
31
|
-
"@vitest/coverage-v8": "4.0.
|
|
32
|
-
"@vitest/ui": "4.0.
|
|
33
|
-
"dotenv": "^17.
|
|
30
|
+
"@types/node": "22.19.7",
|
|
31
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
32
|
+
"@vitest/ui": "4.0.18",
|
|
33
|
+
"dotenv": "^17.2.3",
|
|
34
34
|
"eslint": "^9.37.0",
|
|
35
35
|
"miniflare": "^4.20251109.0",
|
|
36
|
-
"tsup": "^8.5.
|
|
36
|
+
"tsup": "^8.5.1",
|
|
37
37
|
"typescript": "^5.9.3",
|
|
38
|
-
"vitest": "4.0.
|
|
39
|
-
"@internal/lint": "0.0.
|
|
40
|
-
"@internal/types-builder": "0.0.
|
|
41
|
-
"@internal/storage-test-utils": "0.0.
|
|
42
|
-
"@mastra/core": "1.0.0"
|
|
38
|
+
"vitest": "4.0.18",
|
|
39
|
+
"@internal/lint": "0.0.63",
|
|
40
|
+
"@internal/types-builder": "0.0.38",
|
|
41
|
+
"@internal/storage-test-utils": "0.0.59",
|
|
42
|
+
"@mastra/core": "1.9.0-alpha.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"build:lib": "tsup --silent --config tsup.config.ts",
|
|
61
|
-
"build:docs": "pnpx tsx ../../scripts/generate-package-docs.ts stores/cloudflare-d1",
|
|
62
61
|
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
63
62
|
"test": "vitest run",
|
|
64
63
|
"lint": "eslint ."
|
package/dist/docs/README.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# @mastra/cloudflare-d1 Documentation
|
|
2
|
-
|
|
3
|
-
> Embedded documentation for coding agents
|
|
4
|
-
|
|
5
|
-
## Quick Start
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Read the skill overview
|
|
9
|
-
cat docs/SKILL.md
|
|
10
|
-
|
|
11
|
-
# Get the source map
|
|
12
|
-
cat docs/SOURCE_MAP.json
|
|
13
|
-
|
|
14
|
-
# Read topic documentation
|
|
15
|
-
cat docs/<topic>/01-overview.md
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Structure
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
docs/
|
|
22
|
-
├── SKILL.md # Entry point
|
|
23
|
-
├── README.md # This file
|
|
24
|
-
├── SOURCE_MAP.json # Export index
|
|
25
|
-
├── storage/ (1 files)
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Version
|
|
29
|
-
|
|
30
|
-
Package: @mastra/cloudflare-d1
|
|
31
|
-
Version: 1.0.0
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
# Storage API Reference
|
|
2
|
-
|
|
3
|
-
> API reference for storage - 1 entries
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## Reference: Cloudflare D1 Storage
|
|
9
|
-
|
|
10
|
-
> Documentation for the Cloudflare D1 SQL storage implementation in Mastra.
|
|
11
|
-
|
|
12
|
-
The Cloudflare D1 storage implementation provides a serverless SQL database solution using Cloudflare D1, supporting relational operations and transactional consistency.
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npm install @mastra/cloudflare-d1@beta
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## Usage
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
import { D1Store } from "@mastra/cloudflare-d1";
|
|
24
|
-
|
|
25
|
-
type Env = {
|
|
26
|
-
// Add your bindings here, e.g. Workers KV, D1, Workers AI, etc.
|
|
27
|
-
D1Database: D1Database;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// --- Example 1: Using Workers Binding ---
|
|
31
|
-
const storageWorkers = new D1Store({
|
|
32
|
-
binding: D1Database, // D1Database binding provided by the Workers runtime
|
|
33
|
-
tablePrefix: "dev_", // Optional: isolate tables per environment
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// --- Example 2: Using REST API ---
|
|
37
|
-
const storageRest = new D1Store({
|
|
38
|
-
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!, // Cloudflare Account ID
|
|
39
|
-
databaseId: process.env.CLOUDFLARE_D1_DATABASE_ID!, // D1 Database ID
|
|
40
|
-
apiToken: process.env.CLOUDFLARE_API_TOKEN!, // Cloudflare API Token
|
|
41
|
-
tablePrefix: "dev_", // Optional: isolate tables per environment
|
|
42
|
-
});
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
And add the following to your `wrangler.toml` or `wrangler.jsonc` file:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
[[d1_databases]]
|
|
49
|
-
binding = "D1Database"
|
|
50
|
-
database_name = "db-name"
|
|
51
|
-
database_id = "db-id"
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Parameters
|
|
55
|
-
|
|
56
|
-
## Additional Notes
|
|
57
|
-
|
|
58
|
-
### Schema Management
|
|
59
|
-
|
|
60
|
-
The storage implementation handles schema creation and updates automatically. It creates the following tables:
|
|
61
|
-
|
|
62
|
-
- `threads`: Stores conversation threads
|
|
63
|
-
- `messages`: Stores individual messages
|
|
64
|
-
- `metadata`: Stores additional metadata for threads and messages
|
|
65
|
-
|
|
66
|
-
### Initialization
|
|
67
|
-
|
|
68
|
-
When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import { Mastra } from "@mastra/core";
|
|
72
|
-
import { D1Store } from "@mastra/cloudflare-d1";
|
|
73
|
-
|
|
74
|
-
const storage = new D1Store({
|
|
75
|
-
binding: D1Database,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const mastra = new Mastra({
|
|
79
|
-
storage, // init() is called automatically
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
If you're using storage directly without Mastra, you must call `init()` explicitly to create the tables:
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
import { D1Store } from "@mastra/cloudflare-d1";
|
|
87
|
-
|
|
88
|
-
const storage = new D1Store({
|
|
89
|
-
id: 'd1-storage',
|
|
90
|
-
binding: D1Database,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Required when using storage directly
|
|
94
|
-
await storage.init();
|
|
95
|
-
|
|
96
|
-
// Access domain-specific stores via getStore()
|
|
97
|
-
const memoryStore = await storage.getStore('memory');
|
|
98
|
-
const thread = await memoryStore?.getThreadById({ threadId: "..." });
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
> **Note:**
|
|
102
|
-
If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
|
|
103
|
-
|
|
104
|
-
### Transactions & Consistency
|
|
105
|
-
|
|
106
|
-
Cloudflare D1 provides transactional guarantees for single-row operations. This means that multiple operations can be executed as a single, all-or-nothing unit of work.
|
|
107
|
-
|
|
108
|
-
### Table Creation & Migrations
|
|
109
|
-
|
|
110
|
-
Tables are created automatically when storage is initialized (and can be isolated per environment using the `tablePrefix` option), but advanced schema changes—such as adding columns, changing data types, or modifying indexes—require manual migration and careful planning to avoid data loss.
|