@mastra/cloudflare-d1 1.3.2-alpha.0 → 1.3.2
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/README.md +8 -135
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -2,30 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
A Mastra store for Cloudflare D1 SQL databases, supporting threads, messages, workflows, evaluations, and traces with robust SQL features.
|
|
4
4
|
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Thread and message storage using SQL tables
|
|
8
|
-
- True sorted order and filtering via SQL queries
|
|
9
|
-
- Rich metadata support (JSON-encoded)
|
|
10
|
-
- Timestamp tracking for all records
|
|
11
|
-
- Workflow snapshot persistence
|
|
12
|
-
- Trace and evaluation storage
|
|
13
|
-
- Efficient batch operations (with prepared statements)
|
|
14
|
-
- Automatic JSON serialization/deserialization for metadata and custom fields
|
|
15
|
-
- Error handling and logging for all operations
|
|
16
|
-
- Supports both Cloudflare Workers D1 Binding and REST API
|
|
17
|
-
|
|
18
|
-
## Prerequisites
|
|
19
|
-
|
|
20
|
-
- Access to a Cloudflare account with D1 enabled
|
|
21
|
-
- D1 database created and configured
|
|
22
|
-
- For Workers binding: Worker configured with D1 binding
|
|
23
|
-
- For REST API: Cloudflare API Token with D1 permissions
|
|
24
|
-
|
|
25
5
|
## Installation
|
|
26
6
|
|
|
27
7
|
```bash
|
|
28
|
-
|
|
8
|
+
npm install @mastra/cloudflare-d1
|
|
29
9
|
```
|
|
30
10
|
|
|
31
11
|
## Usage
|
|
@@ -41,122 +21,15 @@ const store = new D1Store({
|
|
|
41
21
|
});
|
|
42
22
|
```
|
|
43
23
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { D1Store } from '@mastra/cloudflare-d1';
|
|
48
|
-
|
|
49
|
-
const store = new D1Store({
|
|
50
|
-
accountId: '<your-account-id>',
|
|
51
|
-
databaseId: '<your-d1-database-id>',
|
|
52
|
-
apiToken: '<your-api-token>',
|
|
53
|
-
tablePrefix: 'mastra_', // optional
|
|
54
|
-
});
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Or you can pass any client implementation you want
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
import { D1Store } from '@mastra/cloudflare-d1';
|
|
61
|
-
|
|
62
|
-
const store = new D1Store({
|
|
63
|
-
client: {
|
|
64
|
-
query: ({ sql, params }) => {
|
|
65
|
-
// do something
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
tablePrefix: 'mastra_', // optional
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Supported Methods
|
|
73
|
-
|
|
74
|
-
### Thread Operations
|
|
75
|
-
|
|
76
|
-
- `saveThread(thread)`: Create or update a thread
|
|
77
|
-
- `getThreadById({ threadId })`: Get a thread by ID
|
|
78
|
-
- `listThreadsByResourceId({ resourceId, offset, limit, orderBy? })`: List paginated threads for a resource
|
|
79
|
-
- `updateThread({ id, title, metadata })`: Update the title and/or metadata of a thread.
|
|
80
|
-
- `deleteThread({ threadId })`: Delete a thread and all its messages.
|
|
81
|
-
|
|
82
|
-
### Message Operations
|
|
83
|
-
|
|
84
|
-
- `saveMessages({ messages })`: Save multiple messages in a batch operation (uses prepared statements).
|
|
85
|
-
- `listMessages({ threadId, perPage?, page? })`: Retrieve messages for a thread with pagination.
|
|
86
|
-
- `listMessagesById({ messageIds })`: Get specific messages by their IDs
|
|
87
|
-
- `updateMessages({ messages })`: Update existing messages
|
|
88
|
-
|
|
89
|
-
### Workflow Operations
|
|
90
|
-
|
|
91
|
-
- `persistWorkflowSnapshot({ workflowName, runId, snapshot })`: Save workflow state for a given workflow/run.
|
|
92
|
-
- `loadWorkflowSnapshot({ workflowName, runId })`: Load persisted workflow state.
|
|
93
|
-
- `listWorkflowRuns({ workflowName, pagination })`: List workflow runs with pagination
|
|
94
|
-
- `getWorkflowRunById({ workflowName, runId })`: Get a specific workflow run
|
|
95
|
-
|
|
96
|
-
### Operations Not Currently Supported
|
|
97
|
-
|
|
98
|
-
- `deleteMessages(messageIds)`: Message deletion is not currently supported
|
|
99
|
-
- AI Observability (traces/spans): Not currently supported
|
|
100
|
-
- Evaluation/Scoring: Not currently supported
|
|
101
|
-
|
|
102
|
-
### Utility
|
|
103
|
-
|
|
104
|
-
- `clearTable({ tableName })`: Remove all records from a logical table.
|
|
105
|
-
- `batchInsert({ tableName, records })`: Batch insert multiple records.
|
|
106
|
-
- `insert({ tableName, record })`: Insert a single record into a table.
|
|
107
|
-
|
|
108
|
-
---
|
|
109
|
-
|
|
110
|
-
## Data Types
|
|
111
|
-
|
|
112
|
-
The D1 store supports the following data types:
|
|
113
|
-
|
|
114
|
-
- `text`: String
|
|
115
|
-
- `timestamp`: ISO8601 string (converted to/from Date)
|
|
116
|
-
- `uuid`: String
|
|
117
|
-
- `jsonb`: JSON-encoded object
|
|
118
|
-
- `integer`: Integer (for internal counters, etc)
|
|
119
|
-
|
|
120
|
-
All metadata and custom fields are automatically serialized/deserialized as JSON.
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## Configuration Reference
|
|
125
|
-
|
|
126
|
-
| Option | Type | Description |
|
|
127
|
-
| ----------- | ---------- | ------------------------------------ |
|
|
128
|
-
| binding | D1Database | D1 Workers binding (for Workers) |
|
|
129
|
-
| accountId | string | Cloudflare Account ID (for REST API) |
|
|
130
|
-
| databaseId | string | D1 Database ID (for REST API) |
|
|
131
|
-
| apiToken | string | Cloudflare API Token (for REST API) |
|
|
132
|
-
| tablePrefix | string | Optional prefix for all table names |
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## Table/Namespace Mapping
|
|
137
|
-
|
|
138
|
-
Each logical Mastra table maps to a SQL table in D1 (with optional prefix):
|
|
139
|
-
|
|
140
|
-
- `mastra_threads` — stores threads
|
|
141
|
-
- `mastra_messages` — stores messages
|
|
142
|
-
- `mastra_workflow_snapshot` — stores workflow snapshots
|
|
143
|
-
- `mastra_evals` — stores evaluations
|
|
144
|
-
- `mastra_traces` — stores traces
|
|
145
|
-
|
|
146
|
-
(The prefix is configurable via `tablePrefix`.)
|
|
24
|
+
## Documentation
|
|
147
25
|
|
|
148
|
-
|
|
26
|
+
- [Cloudflare D1 integration guide](https://mastra.ai/integrations/databases/cloudflare-d1)
|
|
27
|
+
- [Storage reference](https://mastra.ai/reference/storage/overview)
|
|
149
28
|
|
|
150
|
-
##
|
|
29
|
+
## Changelog
|
|
151
30
|
|
|
152
|
-
|
|
153
|
-
- No advanced SQL joins (D1 is SQLite-based, but some features may be limited)
|
|
154
|
-
- Batch operations are processed in chunks, not truly atomic
|
|
155
|
-
- Some REST API operations may be slower than Workers binding
|
|
156
|
-
- D1 is in beta and may have evolving limitations
|
|
157
|
-
- No vector search capabilities
|
|
158
|
-
- Note: D1 has specific limitations and behaviors, please refer to the official Cloudflare D1 documentation for more information.
|
|
31
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/cloudflare-d1/CHANGELOG.md) for version history and release notes.
|
|
159
32
|
|
|
160
|
-
##
|
|
33
|
+
## Support
|
|
161
34
|
|
|
162
|
-
|
|
35
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
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.3.2
|
|
6
|
+
version: "1.3.2"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/cloudflare-d1",
|
|
3
|
-
"version": "1.3.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "D1 provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"tsx": "^4.23.1",
|
|
37
37
|
"typescript": "^7.0.2",
|
|
38
38
|
"vitest": "4.1.10",
|
|
39
|
-
"@internal/
|
|
40
|
-
"@
|
|
41
|
-
"@internal/
|
|
42
|
-
"@
|
|
39
|
+
"@internal/lint": "0.0.130",
|
|
40
|
+
"@mastra/core": "1.64.0",
|
|
41
|
+
"@internal/storage-test-utils": "0.0.126",
|
|
42
|
+
"@internal/types-builder": "0.0.105"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@mastra/core": ">=1.54.0-0 <2.0.0-0",
|