@mastra/cloudflare-d1 0.0.0-tsconfig-compile-20250703214351 → 0.0.0-unified-sidebar-20251010130811

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 +1182 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +15 -0
  4. package/dist/index.cjs +1581 -680
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.ts +2 -4
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +1582 -681
  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 +60 -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 +52 -0
  23. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  24. package/dist/storage/index.d.ts +295 -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 +25 -14
  31. package/dist/_tsup-dts-rollup.d.cts +0 -399
  32. package/dist/_tsup-dts-rollup.d.ts +0 -399
  33. package/dist/index.d.cts +0 -4
@@ -1,399 +0,0 @@
1
- import type { D1Database as D1Database_2 } from '@cloudflare/workers-types';
2
- import type { EvalRow } from '@mastra/core/storage';
3
- import type { MastraMessageContentV2 } from '@mastra/core/agent';
4
- import type { MastraMessageV1 } from '@mastra/core/memory';
5
- import type { MastraMessageV2 } from '@mastra/core/memory';
6
- import { MastraStorage } from '@mastra/core/storage';
7
- import type { PaginationInfo } from '@mastra/core/storage';
8
- import type { StorageColumn } from '@mastra/core/storage';
9
- import type { StorageGetMessagesArg } from '@mastra/core/storage';
10
- import type { StorageThreadType } from '@mastra/core/memory';
11
- import type { TABLE_NAMES } from '@mastra/core/storage';
12
- import type { Trace } from '@mastra/core/telemetry';
13
- import type { WorkflowRun } from '@mastra/core/storage';
14
- import type { WorkflowRuns } from '@mastra/core/storage';
15
- import type { WorkflowRunState } from '@mastra/core/workflows';
16
-
17
- export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
18
- id: string;
19
- parentSpanId: string;
20
- traceId: string;
21
- name: string;
22
- scope: string | undefined;
23
- kind: string;
24
- status: string;
25
- events: string;
26
- links: string;
27
- attributes: string | undefined;
28
- startTime: string;
29
- endTime: string;
30
- other: string;
31
- createdAt: string;
32
- };
33
-
34
- export declare function createSqlBuilder(): SqlBuilder;
35
-
36
- /**
37
- * Configuration for D1 using the REST API
38
- */
39
- declare interface D1Config {
40
- /** Cloudflare account ID */
41
- accountId: string;
42
- /** Cloudflare API token with D1 access */
43
- apiToken: string;
44
- /** D1 database ID */
45
- databaseId: string;
46
- /** Optional prefix for table names */
47
- tablePrefix?: string;
48
- }
49
- export { D1Config }
50
- export { D1Config as D1Config_alias_1 }
51
-
52
- declare class D1Store extends MastraStorage {
53
- private client?;
54
- private accountId?;
55
- private databaseId?;
56
- private binding?;
57
- private tablePrefix;
58
- /**
59
- * Creates a new D1Store instance
60
- * @param config Configuration for D1 access (either REST API or Workers Binding API)
61
- */
62
- constructor(config: D1StoreConfig);
63
- private getTableName;
64
- private formatSqlParams;
65
- private executeWorkersBindingQuery;
66
- private executeRestQuery;
67
- /**
68
- * Execute a SQL query against the D1 database
69
- * @param options Query options including SQL, parameters, and whether to return only the first result
70
- * @returns Query results as an array or a single object if first=true
71
- */
72
- private executeQuery;
73
- private getTableColumns;
74
- private serializeValue;
75
- private deserializeValue;
76
- protected getSqlType(type: StorageColumn['type']): string;
77
- createTable({ tableName, schema, }: {
78
- tableName: TABLE_NAMES;
79
- schema: Record<string, StorageColumn>;
80
- }): Promise<void>;
81
- /**
82
- * Alters table schema to add columns if they don't exist
83
- * @param tableName Name of the table
84
- * @param schema Schema of the table
85
- * @param ifNotExists Array of column names to add if they don't exist
86
- */
87
- alterTable({ tableName, schema, ifNotExists, }: {
88
- tableName: TABLE_NAMES;
89
- schema: Record<string, StorageColumn>;
90
- ifNotExists: string[];
91
- }): Promise<void>;
92
- clearTable({ tableName }: {
93
- tableName: TABLE_NAMES;
94
- }): Promise<void>;
95
- private processRecord;
96
- insert({ tableName, record }: {
97
- tableName: TABLE_NAMES;
98
- record: Record<string, any>;
99
- }): Promise<void>;
100
- load<R>({ tableName, keys }: {
101
- tableName: TABLE_NAMES;
102
- keys: Record<string, string>;
103
- }): Promise<R | null>;
104
- getThreadById({ threadId }: {
105
- threadId: string;
106
- }): Promise<StorageThreadType | null>;
107
- /**
108
- * @deprecated use getThreadsByResourceIdPaginated instead
109
- */
110
- getThreadsByResourceId({ resourceId }: {
111
- resourceId: string;
112
- }): Promise<StorageThreadType[]>;
113
- getThreadsByResourceIdPaginated(args: {
114
- resourceId: string;
115
- page: number;
116
- perPage: number;
117
- }): Promise<PaginationInfo & {
118
- threads: StorageThreadType[];
119
- }>;
120
- saveThread({ thread }: {
121
- thread: StorageThreadType;
122
- }): Promise<StorageThreadType>;
123
- updateThread({ id, title, metadata, }: {
124
- id: string;
125
- title: string;
126
- metadata: Record<string, unknown>;
127
- }): Promise<StorageThreadType>;
128
- deleteThread({ threadId }: {
129
- threadId: string;
130
- }): Promise<void>;
131
- saveMessages(args: {
132
- messages: MastraMessageV1[];
133
- format?: undefined | 'v1';
134
- }): Promise<MastraMessageV1[]>;
135
- saveMessages(args: {
136
- messages: MastraMessageV2[];
137
- format: 'v2';
138
- }): Promise<MastraMessageV2[]>;
139
- private _getIncludedMessages;
140
- /**
141
- * @deprecated use getMessagesPaginated instead
142
- */
143
- getMessages(args: StorageGetMessagesArg & {
144
- format?: 'v1';
145
- }): Promise<MastraMessageV1[]>;
146
- getMessages(args: StorageGetMessagesArg & {
147
- format: 'v2';
148
- }): Promise<MastraMessageV2[]>;
149
- getMessagesPaginated({ threadId, selectBy, format, }: StorageGetMessagesArg & {
150
- format?: 'v1' | 'v2';
151
- }): Promise<PaginationInfo & {
152
- messages: MastraMessageV1[] | MastraMessageV2[];
153
- }>;
154
- persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
155
- workflowName: string;
156
- runId: string;
157
- snapshot: WorkflowRunState;
158
- }): Promise<void>;
159
- loadWorkflowSnapshot(params: {
160
- workflowName: string;
161
- runId: string;
162
- }): Promise<WorkflowRunState | null>;
163
- /**
164
- * Insert multiple records in a batch operation
165
- * @param tableName The table to insert into
166
- * @param records The records to insert
167
- */
168
- batchInsert({ tableName, records }: {
169
- tableName: TABLE_NAMES;
170
- records: Record<string, any>[];
171
- }): Promise<void>;
172
- /**
173
- * Upsert multiple records in a batch operation
174
- * @param tableName The table to insert into
175
- * @param records The records to insert
176
- */
177
- private batchUpsert;
178
- /**
179
- * @deprecated use getTracesPaginated instead
180
- */
181
- getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
182
- name?: string;
183
- scope?: string;
184
- page: number;
185
- perPage: number;
186
- attributes?: Record<string, string>;
187
- fromDate?: Date;
188
- toDate?: Date;
189
- }): Promise<Trace[]>;
190
- getTracesPaginated(args: {
191
- name?: string;
192
- scope?: string;
193
- attributes?: Record<string, string>;
194
- page: number;
195
- perPage: number;
196
- fromDate?: Date;
197
- toDate?: Date;
198
- }): Promise<PaginationInfo & {
199
- traces: Trace[];
200
- }>;
201
- /**
202
- * @deprecated use getEvals instead
203
- */
204
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
205
- getEvals(options?: {
206
- agentName?: string;
207
- type?: 'test' | 'live';
208
- page?: number;
209
- perPage?: number;
210
- fromDate?: Date;
211
- toDate?: Date;
212
- }): Promise<PaginationInfo & {
213
- evals: EvalRow[];
214
- }>;
215
- private parseWorkflowRun;
216
- private hasColumn;
217
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
218
- workflowName?: string;
219
- fromDate?: Date;
220
- toDate?: Date;
221
- limit?: number;
222
- offset?: number;
223
- resourceId?: string;
224
- }): Promise<WorkflowRuns>;
225
- getWorkflowRunById({ runId, workflowName, }: {
226
- runId: string;
227
- workflowName?: string;
228
- }): Promise<WorkflowRun | null>;
229
- /**
230
- * Close the database connection
231
- * No explicit cleanup needed for D1 in either REST or Workers Binding mode
232
- */
233
- close(): Promise<void>;
234
- updateMessages(_args: {
235
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
236
- id: string;
237
- content?: {
238
- metadata?: MastraMessageContentV2['metadata'];
239
- content?: MastraMessageContentV2['content'];
240
- };
241
- }[];
242
- }): Promise<MastraMessageV2[]>;
243
- }
244
- export { D1Store }
245
- export { D1Store as D1Store_alias_1 }
246
-
247
- /**
248
- * Combined configuration type supporting both REST API and Workers Binding API
249
- */
250
- declare type D1StoreConfig = D1Config | D1WorkersConfig;
251
- export { D1StoreConfig }
252
- export { D1StoreConfig as D1StoreConfig_alias_1 }
253
-
254
- /**
255
- * Configuration for D1 using the Workers Binding API
256
- */
257
- declare interface D1WorkersConfig {
258
- /** D1 database binding from Workers environment */
259
- binding: D1Database_2;
260
- /** Optional prefix for table names */
261
- tablePrefix?: string;
262
- }
263
- export { D1WorkersConfig }
264
- export { D1WorkersConfig as D1WorkersConfig_alias_1 }
265
-
266
- /**
267
- * Parses and returns a valid SQL SELECT column identifier.
268
- * Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
269
- *
270
- * @param column - The column identifier string to parse.
271
- * @returns The validated column identifier as a branded type.
272
- * @throws {Error} If invalid.
273
- *
274
- * @example
275
- * const col = parseSelectIdentifier('user_id'); // Ok
276
- * parseSelectIdentifier('user_id AS uid'); // Ok
277
- * parseSelectIdentifier('*'); // Ok
278
- * parseSelectIdentifier('user id'); // Throws error
279
- */
280
- export declare function parseSelectIdentifier(column: string): SelectIdentifier;
281
-
282
- export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
283
- interval?: number) => Promise<T>;
284
-
285
- /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
286
- declare type SelectIdentifier = string & {
287
- __brand: 'SelectIdentifier';
288
- };
289
-
290
- /**
291
- * SQL Builder class for constructing type-safe SQL queries
292
- * This helps create maintainable and secure SQL queries with proper parameter handling
293
- */
294
- export declare class SqlBuilder {
295
- private sql;
296
- private params;
297
- private whereAdded;
298
- select(columns?: string | string[]): SqlBuilder;
299
- from(table: string): SqlBuilder;
300
- /**
301
- * Add a WHERE clause to the query
302
- * @param condition The condition to add
303
- * @param params Parameters to bind to the condition
304
- */
305
- where(condition: string, ...params: SqlParam[]): SqlBuilder;
306
- /**
307
- * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
308
- * @param condition The condition to add
309
- * @param params Parameters to bind to the condition
310
- */
311
- whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
312
- andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
313
- orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
314
- orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
315
- limit(count: number): SqlBuilder;
316
- offset(count: number): SqlBuilder;
317
- count(): SqlBuilder;
318
- /**
319
- * Insert a row, or update specific columns on conflict (upsert).
320
- * @param table Table name
321
- * @param columns Columns to insert
322
- * @param values Values to insert
323
- * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
324
- * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
325
- */
326
- insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
327
- update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
328
- delete(table: string): SqlBuilder;
329
- /**
330
- * Create a table if it doesn't exist
331
- * @param table The table name
332
- * @param columnDefinitions The column definitions as an array of strings
333
- * @param tableConstraints Optional constraints for the table
334
- * @returns The builder instance
335
- */
336
- createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
337
- /**
338
- * Check if an index exists in the database
339
- * @param indexName The name of the index to check
340
- * @param tableName The table the index is on
341
- * @returns The builder instance
342
- */
343
- checkIndexExists(indexName: string, tableName: string): SqlBuilder;
344
- /**
345
- * Create an index if it doesn't exist
346
- * @param indexName The name of the index to create
347
- * @param tableName The table to create the index on
348
- * @param columnName The column to index
349
- * @param indexType Optional index type (e.g., 'UNIQUE')
350
- * @returns The builder instance
351
- */
352
- createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
353
- /**
354
- * Add a LIKE condition to the query
355
- * @param column The column to check
356
- * @param value The value to match (will be wrapped with % for LIKE)
357
- * @param exact If true, will not add % wildcards
358
- */
359
- like(column: string, value: string, exact?: boolean): SqlBuilder;
360
- /**
361
- * Add a JSON LIKE condition for searching in JSON fields
362
- * @param column The JSON column to search in
363
- * @param key The JSON key to match
364
- * @param value The value to match
365
- */
366
- jsonLike(column: string, key: string, value: string): SqlBuilder;
367
- /**
368
- * Get the built query
369
- * @returns Object containing the SQL string and parameters array
370
- */
371
- build(): {
372
- sql: string;
373
- params: SqlParam[];
374
- };
375
- /**
376
- * Reset the builder for reuse
377
- * @returns The reset builder instance
378
- */
379
- reset(): SqlBuilder;
380
- }
381
-
382
- /**
383
- * Type definition for SQL query parameters
384
- */
385
- export declare type SqlParam = string | number | boolean | null | undefined;
386
-
387
- /**
388
- * Interface for SQL query options with generic type support
389
- */
390
- export declare interface SqlQueryOptions {
391
- /** SQL query to execute */
392
- sql: string;
393
- /** Parameters to bind to the query */
394
- params?: SqlParam[];
395
- /** Whether to return only the first result */
396
- first?: boolean;
397
- }
398
-
399
- export { }
package/dist/index.d.cts DELETED
@@ -1,4 +0,0 @@
1
- export { D1Config } from './_tsup-dts-rollup.cjs';
2
- export { D1WorkersConfig } from './_tsup-dts-rollup.cjs';
3
- export { D1StoreConfig } from './_tsup-dts-rollup.cjs';
4
- export { D1Store } from './_tsup-dts-rollup.cjs';