@mastra/cloudflare-d1 0.0.0-redis-cloud-transporter-20250508203756 → 0.0.0-remove-unused-import-20250909212718

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 (33) hide show
  1. package/CHANGELOG.md +1078 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +15 -0
  4. package/dist/index.cjs +1979 -586
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.ts +2 -5
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +1967 -574
  9. package/dist/index.js.map +1 -0
  10. package/dist/storage/domains/legacy-evals/index.d.ts +20 -0
  11. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  12. package/dist/storage/domains/memory/index.d.ts +90 -0
  13. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  14. package/dist/storage/domains/operations/index.d.ts +72 -0
  15. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  16. package/dist/storage/domains/scores/index.d.ts +52 -0
  17. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  18. package/dist/storage/domains/traces/index.d.ts +18 -0
  19. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  20. package/dist/storage/domains/utils.d.ts +3 -0
  21. package/dist/storage/domains/utils.d.ts.map +1 -0
  22. package/dist/storage/domains/workflows/index.d.ts +51 -0
  23. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  24. package/dist/storage/index.d.ts +285 -0
  25. package/dist/storage/index.d.ts.map +1 -0
  26. package/dist/storage/sql-builder.d.ts +128 -0
  27. package/dist/storage/sql-builder.d.ts.map +1 -0
  28. package/dist/storage/test-utils.d.ts +19 -0
  29. package/dist/storage/test-utils.d.ts.map +1 -0
  30. package/package.json +32 -17
  31. package/dist/_tsup-dts-rollup.d.cts +0 -331
  32. package/dist/_tsup-dts-rollup.d.ts +0 -331
  33. package/dist/index.d.cts +0 -5
@@ -0,0 +1,19 @@
1
+ export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
2
+ id: string;
3
+ parentSpanId: string;
4
+ traceId: string;
5
+ name: string;
6
+ scope: string | undefined;
7
+ kind: string;
8
+ status: string;
9
+ events: string;
10
+ links: string;
11
+ attributes: string | undefined;
12
+ startTime: string;
13
+ endTime: string;
14
+ other: string;
15
+ createdAt: string;
16
+ };
17
+ export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
18
+ interval?: number) => Promise<T>;
19
+ //# sourceMappingURL=test-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../src/storage/test-utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,EAAE,aAAa,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;;;;;;;;;;;;;;;CAejG,CAAC;AAGH,eAAO,MAAM,UAAU,GAAU,CAAC,EAChC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,EACjC,gBAAe,EAAE,sDAAsD;AACvE,iBAAe,KACd,OAAO,CAAC,CAAC,CAYX,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@mastra/cloudflare-d1",
3
- "version": "0.0.0-redis-cloud-transporter-20250508203756",
3
+ "version": "0.0.0-remove-unused-import-20250909212718",
4
4
  "description": "D1 provider for Mastra - includes db storage capabilities",
5
5
  "type": "module",
6
6
  "files": [
7
- "dist"
7
+ "dist",
8
+ "CHANGELOG.md"
8
9
  ],
9
10
  "main": "dist/index.js",
10
11
  "types": "dist/index.d.ts",
@@ -15,31 +16,45 @@
15
16
  "default": "./dist/index.js"
16
17
  },
17
18
  "require": {
18
- "types": "./dist/index.d.cts",
19
+ "types": "./dist/index.d.ts",
19
20
  "default": "./dist/index.cjs"
20
21
  }
21
22
  },
22
23
  "./package.json": "./package.json"
23
24
  },
24
25
  "dependencies": {
25
- "cloudflare": "^4.1.0",
26
- "@mastra/core": "0.0.0-redis-cloud-transporter-20250508203756"
26
+ "cloudflare": "^4.5.0"
27
27
  },
28
28
  "devDependencies": {
29
- "@cloudflare/workers-types": "^4.20250417.0",
30
- "@microsoft/api-extractor": "^7.52.5",
31
- "@types/node": "^20.17.27",
32
- "dotenv": "^16.4.7",
33
- "eslint": "^9.23.0",
34
- "miniflare": "^4.20250410.1",
35
- "tsup": "^8.4.0",
36
- "typescript": "^5.8.2",
37
- "vitest": "^3.1.2",
38
- "@internal/lint": "0.0.0-redis-cloud-transporter-20250508203756"
29
+ "@cloudflare/workers-types": "^4.20250823.0",
30
+ "@microsoft/api-extractor": "^7.52.8",
31
+ "@types/node": "^20.19.0",
32
+ "dotenv": "^17.0.0",
33
+ "eslint": "^9.30.1",
34
+ "miniflare": "^4.20250816.1",
35
+ "tsup": "^8.5.0",
36
+ "typescript": "^5.8.3",
37
+ "vitest": "^3.2.4",
38
+ "@internal/storage-test-utils": "0.0.32",
39
+ "@internal/lint": "0.0.0-remove-unused-import-20250909212718",
40
+ "@mastra/core": "0.0.0-remove-unused-import-20250909212718",
41
+ "@internal/types-builder": "0.0.0-remove-unused-import-20250909212718"
42
+ },
43
+ "peerDependencies": {
44
+ "@mastra/core": "0.0.0-remove-unused-import-20250909212718"
45
+ },
46
+ "homepage": "https://mastra.ai",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/mastra-ai/mastra.git",
50
+ "directory": "stores/cloudflare-d1"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/mastra-ai/mastra/issues"
39
54
  },
40
55
  "scripts": {
41
- "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
42
- "build:watch": "pnpm build --watch",
56
+ "build": "tsup --silent --config tsup.config.ts",
57
+ "build:watch": "tsup --watch --silent --config tsup.config.ts",
43
58
  "test": "vitest run",
44
59
  "lint": "eslint ."
45
60
  }
@@ -1,331 +0,0 @@
1
- import type { D1Database as D1Database_2 } from '@cloudflare/workers-types';
2
- import type { EvalRow } from '@mastra/core/storage';
3
- import { MastraStorage } from '@mastra/core/storage';
4
- import type { MessageType } from '@mastra/core/memory';
5
- import type { MessageType as MessageType_2 } from '@mastra/core';
6
- import type { StorageColumn } from '@mastra/core/storage';
7
- import type { StorageGetMessagesArg } from '@mastra/core/storage';
8
- import type { StorageThreadType } from '@mastra/core/memory';
9
- import type { TABLE_NAMES } from '@mastra/core/storage';
10
- import type { WorkflowRun } from '@mastra/core/storage';
11
- import type { WorkflowRuns } from '@mastra/core/storage';
12
- import type { WorkflowRunState } from '@mastra/core/workflows';
13
- import type { WorkflowRunState as WorkflowRunState_2 } from '@mastra/core';
14
-
15
- export declare const checkWorkflowSnapshot: (snapshot: WorkflowRunState_2 | string, stepId: string, status: string) => void;
16
-
17
- export declare const createSampleMessage: (threadId: string) => MessageType_2;
18
-
19
- export declare const createSampleThread: () => {
20
- id: string;
21
- resourceId: string;
22
- title: string;
23
- createdAt: Date;
24
- updatedAt: Date;
25
- metadata: {
26
- key: string;
27
- };
28
- };
29
-
30
- export declare const createSampleThreadWithParams: (threadId: string, resourceId: string, createdAt: Date, updatedAt: Date) => {
31
- id: string;
32
- resourceId: string;
33
- title: string;
34
- createdAt: Date;
35
- updatedAt: Date;
36
- metadata: {
37
- key: string;
38
- };
39
- };
40
-
41
- export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
42
- id: string;
43
- parentSpanId: string;
44
- traceId: string;
45
- name: string;
46
- scope: string | undefined;
47
- kind: string;
48
- status: string;
49
- events: string;
50
- links: string;
51
- attributes: string | undefined;
52
- startTime: string;
53
- endTime: string;
54
- other: string;
55
- createdAt: string;
56
- };
57
-
58
- export declare const createSampleWorkflowSnapshot: (threadId: string, status: string, createdAt?: Date) => {
59
- snapshot: WorkflowRunState_2;
60
- runId: string;
61
- stepId: string;
62
- };
63
-
64
- export declare function createSqlBuilder(): SqlBuilder;
65
-
66
- /**
67
- * Configuration for D1 using the REST API
68
- */
69
- declare interface D1Config {
70
- /** Cloudflare account ID */
71
- accountId: string;
72
- /** Cloudflare API token with D1 access */
73
- apiToken: string;
74
- /** D1 database ID */
75
- databaseId: string;
76
- /** Optional prefix for table names */
77
- tablePrefix?: string;
78
- }
79
- export { D1Config }
80
- export { D1Config as D1Config_alias_1 }
81
-
82
- declare class D1Store extends MastraStorage {
83
- private client?;
84
- private accountId?;
85
- private databaseId?;
86
- private binding?;
87
- private tablePrefix;
88
- /**
89
- * Creates a new D1Store instance
90
- * @param config Configuration for D1 access (either REST API or Workers Binding API)
91
- */
92
- constructor(config: D1StoreConfig);
93
- private getTableName;
94
- private formatSqlParams;
95
- private createIndexIfNotExists;
96
- private executeWorkersBindingQuery;
97
- private executeRestQuery;
98
- /**
99
- * Execute a SQL query against the D1 database
100
- * @param options Query options including SQL, parameters, and whether to return only the first result
101
- * @returns Query results as an array or a single object if first=true
102
- */
103
- private executeQuery;
104
- private getSqlType;
105
- private ensureDate;
106
- private serializeDate;
107
- private serializeValue;
108
- private deserializeValue;
109
- createTable({ tableName, schema, }: {
110
- tableName: TABLE_NAMES;
111
- schema: Record<string, StorageColumn>;
112
- }): Promise<void>;
113
- clearTable({ tableName }: {
114
- tableName: TABLE_NAMES;
115
- }): Promise<void>;
116
- private processRecord;
117
- insert({ tableName, record }: {
118
- tableName: TABLE_NAMES;
119
- record: Record<string, any>;
120
- }): Promise<void>;
121
- load<R>({ tableName, keys }: {
122
- tableName: TABLE_NAMES;
123
- keys: Record<string, string>;
124
- }): Promise<R | null>;
125
- getThreadById({ threadId }: {
126
- threadId: string;
127
- }): Promise<StorageThreadType | null>;
128
- getThreadsByResourceId({ resourceId }: {
129
- resourceId: string;
130
- }): Promise<StorageThreadType[]>;
131
- saveThread({ thread }: {
132
- thread: StorageThreadType;
133
- }): Promise<StorageThreadType>;
134
- updateThread({ id, title, metadata, }: {
135
- id: string;
136
- title: string;
137
- metadata: Record<string, unknown>;
138
- }): Promise<StorageThreadType>;
139
- deleteThread({ threadId }: {
140
- threadId: string;
141
- }): Promise<void>;
142
- saveMessages({ messages }: {
143
- messages: MessageType[];
144
- }): Promise<MessageType[]>;
145
- getMessages<T = MessageType>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
146
- persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
147
- workflowName: string;
148
- runId: string;
149
- snapshot: WorkflowRunState;
150
- }): Promise<void>;
151
- loadWorkflowSnapshot(params: {
152
- workflowName: string;
153
- runId: string;
154
- }): Promise<WorkflowRunState | null>;
155
- /**
156
- * Insert multiple records in a batch operation
157
- * @param tableName The table to insert into
158
- * @param records The records to insert
159
- */
160
- batchInsert({ tableName, records }: {
161
- tableName: TABLE_NAMES;
162
- records: Record<string, any>[];
163
- }): Promise<void>;
164
- getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
165
- name?: string;
166
- scope?: string;
167
- page: number;
168
- perPage: number;
169
- attributes?: Record<string, string>;
170
- fromDate?: Date;
171
- toDate?: Date;
172
- }): Promise<Record<string, any>[]>;
173
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
174
- private parseWorkflowRun;
175
- private hasColumn;
176
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
177
- workflowName?: string;
178
- fromDate?: Date;
179
- toDate?: Date;
180
- limit?: number;
181
- offset?: number;
182
- resourceId?: string;
183
- }): Promise<WorkflowRuns>;
184
- getWorkflowRunById({ runId, workflowName, }: {
185
- runId: string;
186
- workflowName?: string;
187
- }): Promise<WorkflowRun | null>;
188
- /**
189
- * Close the database connection
190
- * No explicit cleanup needed for D1 in either REST or Workers Binding mode
191
- */
192
- close(): Promise<void>;
193
- }
194
- export { D1Store }
195
- export { D1Store as D1Store_alias_1 }
196
-
197
- /**
198
- * Combined configuration type supporting both REST API and Workers Binding API
199
- */
200
- declare type D1StoreConfig = D1Config | D1WorkersConfig;
201
- export { D1StoreConfig }
202
- export { D1StoreConfig as D1StoreConfig_alias_1 }
203
-
204
- /**
205
- * Configuration for D1 using the Workers Binding API
206
- */
207
- declare interface D1WorkersConfig {
208
- /** D1 database binding from Workers environment */
209
- binding: D1Database_2;
210
- /** Optional prefix for table names */
211
- tablePrefix?: string;
212
- }
213
- export { D1WorkersConfig }
214
- export { D1WorkersConfig as D1WorkersConfig_alias_1 }
215
-
216
- export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
217
- interval?: number) => Promise<T>;
218
-
219
- /**
220
- * SQL Builder class for constructing type-safe SQL queries
221
- * This helps create maintainable and secure SQL queries with proper parameter handling
222
- */
223
- export declare class SqlBuilder {
224
- private sql;
225
- private params;
226
- private whereAdded;
227
- select(columns?: string | string[]): SqlBuilder;
228
- from(table: string): SqlBuilder;
229
- /**
230
- * Add a WHERE clause to the query
231
- * @param condition The condition to add
232
- * @param params Parameters to bind to the condition
233
- */
234
- where(condition: string, ...params: SqlParam[]): SqlBuilder;
235
- /**
236
- * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
237
- * @param condition The condition to add
238
- * @param params Parameters to bind to the condition
239
- */
240
- whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
241
- andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
242
- orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
243
- orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
244
- limit(count: number): SqlBuilder;
245
- offset(count: number): SqlBuilder;
246
- count(): SqlBuilder;
247
- /**
248
- * Insert a row, or update specific columns on conflict (upsert).
249
- * @param table Table name
250
- * @param columns Columns to insert
251
- * @param values Values to insert
252
- * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
253
- * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
254
- */
255
- insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
256
- update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
257
- delete(table: string): SqlBuilder;
258
- /**
259
- * Create a table if it doesn't exist
260
- * @param table The table name
261
- * @param columnDefinitions The column definitions as an array of strings
262
- * @param tableConstraints Optional constraints for the table
263
- * @returns The builder instance
264
- */
265
- createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
266
- /**
267
- * Check if an index exists in the database
268
- * @param indexName The name of the index to check
269
- * @param tableName The table the index is on
270
- * @returns The builder instance
271
- */
272
- checkIndexExists(indexName: string, tableName: string): SqlBuilder;
273
- /**
274
- * Create an index if it doesn't exist
275
- * @param indexName The name of the index to create
276
- * @param tableName The table to create the index on
277
- * @param columnName The column to index
278
- * @param indexType Optional index type (e.g., 'UNIQUE')
279
- * @returns The builder instance
280
- */
281
- createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
282
- raw(sql: string, ...params: SqlParam[]): SqlBuilder;
283
- /**
284
- * Add a LIKE condition to the query
285
- * @param column The column to check
286
- * @param value The value to match (will be wrapped with % for LIKE)
287
- * @param exact If true, will not add % wildcards
288
- */
289
- like(column: string, value: string, exact?: boolean): SqlBuilder;
290
- /**
291
- * Add a JSON LIKE condition for searching in JSON fields
292
- * @param column The JSON column to search in
293
- * @param key The JSON key to match
294
- * @param value The value to match
295
- */
296
- jsonLike(column: string, key: string, value: string): SqlBuilder;
297
- /**
298
- * Get the built query
299
- * @returns Object containing the SQL string and parameters array
300
- */
301
- build(): {
302
- sql: string;
303
- params: SqlParam[];
304
- };
305
- /**
306
- * Reset the builder for reuse
307
- * @returns The reset builder instance
308
- */
309
- reset(): SqlBuilder;
310
- }
311
-
312
- /**
313
- * Type definition for SQL query parameters
314
- */
315
- export declare type SqlParam = string | number | boolean | null | undefined;
316
-
317
- /**
318
- * Interface for SQL query options with generic type support
319
- */
320
- declare interface SqlQueryOptions {
321
- /** SQL query to execute */
322
- sql: string;
323
- /** Parameters to bind to the query */
324
- params?: SqlParam[];
325
- /** Whether to return only the first result */
326
- first?: boolean;
327
- }
328
- export { SqlQueryOptions }
329
- export { SqlQueryOptions as SqlQueryOptions_alias_1 }
330
-
331
- export { }