@mastra/cloudflare-d1 1.0.0-beta.7 → 1.0.0-beta.9

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,94 @@
1
1
  # @mastra/cloudflare-d1
2
2
 
3
+ ## 1.0.0-beta.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Add embedded documentation support for Mastra packages ([#11472](https://github.com/mastra-ai/mastra/pull/11472))
8
+
9
+ Mastra packages now include embedded documentation in the published npm package under `dist/docs/`. This enables coding agents and AI assistants to understand and use the framework by reading documentation directly from `node_modules`.
10
+
11
+ Each package includes:
12
+ - **SKILL.md** - Entry point explaining the package's purpose and capabilities
13
+ - **SOURCE_MAP.json** - Machine-readable index mapping exports to types and implementation files
14
+ - **Topic folders** - Conceptual documentation organized by feature area
15
+
16
+ Documentation is driven by the `packages` frontmatter field in MDX files, which maps docs to their corresponding packages. CI validation ensures all docs include this field.
17
+
18
+ - Added `startExclusive` and `endExclusive` options to `dateRange` filter for message queries. ([#11479](https://github.com/mastra-ai/mastra/pull/11479))
19
+
20
+ **What changed:** The `filter.dateRange` parameter in `listMessages()` and `Memory.recall()` now supports `startExclusive` and `endExclusive` boolean options. When set to `true`, messages with timestamps exactly matching the boundary are excluded from results.
21
+
22
+ **Why this matters:** Enables cursor-based pagination for chat applications. When new messages arrive during a session, offset-based pagination can skip or duplicate messages. Using `endExclusive: true` with the oldest message's timestamp as a cursor ensures consistent pagination without gaps or duplicates.
23
+
24
+ **Example:**
25
+
26
+ ```typescript
27
+ // Get first page
28
+ const page1 = await memory.recall({
29
+ threadId: 'thread-123',
30
+ perPage: 10,
31
+ orderBy: { field: 'createdAt', direction: 'DESC' },
32
+ });
33
+
34
+ // Get next page using cursor-based pagination
35
+ const oldestMessage = page1.messages[page1.messages.length - 1];
36
+ const page2 = await memory.recall({
37
+ threadId: 'thread-123',
38
+ perPage: 10,
39
+ orderBy: { field: 'createdAt', direction: 'DESC' },
40
+ filter: {
41
+ dateRange: {
42
+ end: oldestMessage.createdAt,
43
+ endExclusive: true, // Excludes the cursor message
44
+ },
45
+ },
46
+ });
47
+ ```
48
+
49
+ - Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
50
+ - @mastra/core@1.0.0-beta.20
51
+
52
+ ## 1.0.0-beta.8
53
+
54
+ ### Patch Changes
55
+
56
+ - Add storage composition to MastraStorage ([#11401](https://github.com/mastra-ai/mastra/pull/11401))
57
+
58
+ `MastraStorage` can now compose storage domains from different adapters. Use it when you need different databases for different purposes - for example, PostgreSQL for memory and workflows, but a different database for observability.
59
+
60
+ ```typescript
61
+ import { MastraStorage } from '@mastra/core/storage';
62
+ import { MemoryPG, WorkflowsPG, ScoresPG } from '@mastra/pg';
63
+ import { MemoryLibSQL } from '@mastra/libsql';
64
+
65
+ // Compose domains from different stores
66
+ const storage = new MastraStorage({
67
+ id: 'composite',
68
+ domains: {
69
+ memory: new MemoryLibSQL({ url: 'file:./local.db' }),
70
+ workflows: new WorkflowsPG({ connectionString: process.env.DATABASE_URL }),
71
+ scores: new ScoresPG({ connectionString: process.env.DATABASE_URL }),
72
+ },
73
+ });
74
+ ```
75
+
76
+ **Breaking changes:**
77
+ - `storage.supports` property no longer exists
78
+ - `StorageSupports` type is no longer exported from `@mastra/core/storage`
79
+
80
+ All stores now support the same features. For domain availability, use `getStore()`:
81
+
82
+ ```typescript
83
+ const store = await storage.getStore('memory');
84
+ if (store) {
85
+ // domain is available
86
+ }
87
+ ```
88
+
89
+ - Updated dependencies [[`3d93a15`](https://github.com/mastra-ai/mastra/commit/3d93a15796b158c617461c8b98bede476ebb43e2), [`efe406a`](https://github.com/mastra-ai/mastra/commit/efe406a1353c24993280ebc2ed61dd9f65b84b26), [`119e5c6`](https://github.com/mastra-ai/mastra/commit/119e5c65008f3e5cfca954eefc2eb85e3bf40da4), [`74e504a`](https://github.com/mastra-ai/mastra/commit/74e504a3b584eafd2f198001c6a113bbec589fd3), [`e33fdbd`](https://github.com/mastra-ai/mastra/commit/e33fdbd07b33920d81e823122331b0c0bee0bb59), [`929f69c`](https://github.com/mastra-ai/mastra/commit/929f69c3436fa20dd0f0e2f7ebe8270bd82a1529), [`8a73529`](https://github.com/mastra-ai/mastra/commit/8a73529ca01187f604b1f3019d0a725ac63ae55f)]:
90
+ - @mastra/core@1.0.0-beta.16
91
+
3
92
  ## 1.0.0-beta.7
4
93
 
5
94
  ### Minor Changes
@@ -0,0 +1,31 @@
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-beta.9
@@ -0,0 +1,32 @@
1
+ ---
2
+ name: mastra-cloudflare-d1-docs
3
+ description: Documentation for @mastra/cloudflare-d1. Includes links to type definitions and readable implementation code in dist/.
4
+ ---
5
+
6
+ # @mastra/cloudflare-d1 Documentation
7
+
8
+ > **Version**: 1.0.0-beta.9
9
+ > **Package**: @mastra/cloudflare-d1
10
+
11
+ ## Quick Navigation
12
+
13
+ Use SOURCE_MAP.json to find any export:
14
+
15
+ ```bash
16
+ cat docs/SOURCE_MAP.json
17
+ ```
18
+
19
+ Each export maps to:
20
+ - **types**: `.d.ts` file with JSDoc and API signatures
21
+ - **implementation**: `.js` chunk file with readable source
22
+ - **docs**: Conceptual documentation in `docs/`
23
+
24
+ ## Top Exports
25
+
26
+
27
+
28
+ See SOURCE_MAP.json for the complete list.
29
+
30
+ ## Available Topics
31
+
32
+ - [Storage](storage/) - 1 file(s)
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": "1.0.0-beta.9",
3
+ "package": "@mastra/cloudflare-d1",
4
+ "exports": {},
5
+ "modules": {}
6
+ }
@@ -0,0 +1,110 @@
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.
package/dist/index.cjs CHANGED
@@ -1211,12 +1211,14 @@ var MemoryStorageD1 = class extends storage.MemoryStorage {
1211
1211
  const dateRange = filter?.dateRange;
1212
1212
  if (dateRange?.start) {
1213
1213
  const startDate = dateRange.start instanceof Date ? storage.serializeDate(dateRange.start) : storage.serializeDate(new Date(dateRange.start));
1214
- query += ` AND createdAt >= ?`;
1214
+ const startOp = dateRange.startExclusive ? ">" : ">=";
1215
+ query += ` AND createdAt ${startOp} ?`;
1215
1216
  queryParams.push(startDate);
1216
1217
  }
1217
1218
  if (dateRange?.end) {
1218
1219
  const endDate = dateRange.end instanceof Date ? storage.serializeDate(dateRange.end) : storage.serializeDate(new Date(dateRange.end));
1219
- query += ` AND createdAt <= ?`;
1220
+ const endOp = dateRange.endExclusive ? "<" : "<=";
1221
+ query += ` AND createdAt ${endOp} ?`;
1220
1222
  queryParams.push(endDate);
1221
1223
  }
1222
1224
  const { field, direction } = this.parseOrderBy(orderBy, "ASC");
@@ -1243,12 +1245,14 @@ var MemoryStorageD1 = class extends storage.MemoryStorage {
1243
1245
  }
1244
1246
  if (dateRange?.start) {
1245
1247
  const startDate = dateRange.start instanceof Date ? storage.serializeDate(dateRange.start) : storage.serializeDate(new Date(dateRange.start));
1246
- countQuery += ` AND createdAt >= ?`;
1248
+ const startOp = dateRange.startExclusive ? ">" : ">=";
1249
+ countQuery += ` AND createdAt ${startOp} ?`;
1247
1250
  countParams.push(startDate);
1248
1251
  }
1249
1252
  if (dateRange?.end) {
1250
1253
  const endDate = dateRange.end instanceof Date ? storage.serializeDate(dateRange.end) : storage.serializeDate(new Date(dateRange.end));
1251
- countQuery += ` AND createdAt <= ?`;
1254
+ const endOp = dateRange.endExclusive ? "<" : "<=";
1255
+ countQuery += ` AND createdAt ${endOp} ?`;
1252
1256
  countParams.push(endDate);
1253
1257
  }
1254
1258
  const countResult = await this.#db.executeQuery({ sql: countQuery, params: countParams });
@@ -2103,19 +2107,6 @@ var D1Store = class extends storage.MastraStorage {
2103
2107
  memory
2104
2108
  };
2105
2109
  }
2106
- get supports() {
2107
- return {
2108
- selectByIncludeResourceScope: true,
2109
- resourceWorkingMemory: true,
2110
- hasColumn: true,
2111
- createTable: true,
2112
- deleteMessages: true,
2113
- observability: false,
2114
- indexManagement: false,
2115
- listScoresBySpan: true,
2116
- agents: false
2117
- };
2118
- }
2119
2110
  /**
2120
2111
  * Close the database connection
2121
2112
  * No explicit cleanup needed for D1 in either REST or Workers Binding mode
@@ -2126,5 +2117,8 @@ var D1Store = class extends storage.MastraStorage {
2126
2117
  };
2127
2118
 
2128
2119
  exports.D1Store = D1Store;
2120
+ exports.MemoryStorageD1 = MemoryStorageD1;
2121
+ exports.ScoresStorageD1 = ScoresStorageD1;
2122
+ exports.WorkflowsStorageD1 = WorkflowsStorageD1;
2129
2123
  //# sourceMappingURL=index.cjs.map
2130
2124
  //# sourceMappingURL=index.cjs.map