@mastra/cloudflare-d1 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-tsconfig-compile-20250703214351

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.
@@ -1,42 +1,18 @@
1
1
  import type { D1Database as D1Database_2 } from '@cloudflare/workers-types';
2
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';
3
6
  import { MastraStorage } from '@mastra/core/storage';
4
- import type { MessageType } from '@mastra/core/memory';
5
- import type { MessageType as MessageType_2 } from '@mastra/core';
7
+ import type { PaginationInfo } from '@mastra/core/storage';
6
8
  import type { StorageColumn } from '@mastra/core/storage';
7
9
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
8
10
  import type { StorageThreadType } from '@mastra/core/memory';
9
11
  import type { TABLE_NAMES } from '@mastra/core/storage';
12
+ import type { Trace } from '@mastra/core/telemetry';
10
13
  import type { WorkflowRun } from '@mastra/core/storage';
11
14
  import type { WorkflowRuns } from '@mastra/core/storage';
12
15
  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
16
 
41
17
  export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
42
18
  id: string;
@@ -55,12 +31,6 @@ export declare const createSampleTrace: (name: string, scope?: string, attribute
55
31
  createdAt: string;
56
32
  };
57
33
 
58
- export declare const createSampleWorkflowSnapshot: (threadId: string, status: string, createdAt?: Date) => {
59
- snapshot: WorkflowRunState_2;
60
- runId: string;
61
- stepId: string;
62
- };
63
-
64
34
  export declare function createSqlBuilder(): SqlBuilder;
65
35
 
66
36
  /**
@@ -92,7 +62,6 @@ declare class D1Store extends MastraStorage {
92
62
  constructor(config: D1StoreConfig);
93
63
  private getTableName;
94
64
  private formatSqlParams;
95
- private createIndexIfNotExists;
96
65
  private executeWorkersBindingQuery;
97
66
  private executeRestQuery;
98
67
  /**
@@ -101,15 +70,25 @@ declare class D1Store extends MastraStorage {
101
70
  * @returns Query results as an array or a single object if first=true
102
71
  */
103
72
  private executeQuery;
104
- private getSqlType;
105
- private ensureDate;
106
- private serializeDate;
73
+ private getTableColumns;
107
74
  private serializeValue;
108
75
  private deserializeValue;
76
+ protected getSqlType(type: StorageColumn['type']): string;
109
77
  createTable({ tableName, schema, }: {
110
78
  tableName: TABLE_NAMES;
111
79
  schema: Record<string, StorageColumn>;
112
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>;
113
92
  clearTable({ tableName }: {
114
93
  tableName: TABLE_NAMES;
115
94
  }): Promise<void>;
@@ -125,9 +104,19 @@ declare class D1Store extends MastraStorage {
125
104
  getThreadById({ threadId }: {
126
105
  threadId: string;
127
106
  }): Promise<StorageThreadType | null>;
107
+ /**
108
+ * @deprecated use getThreadsByResourceIdPaginated instead
109
+ */
128
110
  getThreadsByResourceId({ resourceId }: {
129
111
  resourceId: string;
130
112
  }): Promise<StorageThreadType[]>;
113
+ getThreadsByResourceIdPaginated(args: {
114
+ resourceId: string;
115
+ page: number;
116
+ perPage: number;
117
+ }): Promise<PaginationInfo & {
118
+ threads: StorageThreadType[];
119
+ }>;
131
120
  saveThread({ thread }: {
132
121
  thread: StorageThreadType;
133
122
  }): Promise<StorageThreadType>;
@@ -139,10 +128,29 @@ declare class D1Store extends MastraStorage {
139
128
  deleteThread({ threadId }: {
140
129
  threadId: string;
141
130
  }): Promise<void>;
142
- saveMessages({ messages }: {
143
- messages: MessageType[];
144
- }): Promise<MessageType[]>;
145
- getMessages<T = MessageType>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
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
+ }>;
146
154
  persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
147
155
  workflowName: string;
148
156
  runId: string;
@@ -161,6 +169,15 @@ declare class D1Store extends MastraStorage {
161
169
  tableName: TABLE_NAMES;
162
170
  records: Record<string, any>[];
163
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
+ */
164
181
  getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
165
182
  name?: string;
166
183
  scope?: string;
@@ -169,8 +186,32 @@ declare class D1Store extends MastraStorage {
169
186
  attributes?: Record<string, string>;
170
187
  fromDate?: Date;
171
188
  toDate?: Date;
172
- }): Promise<Record<string, any>[]>;
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
+ */
173
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
+ }>;
174
215
  private parseWorkflowRun;
175
216
  private hasColumn;
176
217
  getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
@@ -190,6 +231,15 @@ declare class D1Store extends MastraStorage {
190
231
  * No explicit cleanup needed for D1 in either REST or Workers Binding mode
191
232
  */
192
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[]>;
193
243
  }
194
244
  export { D1Store }
195
245
  export { D1Store as D1Store_alias_1 }
@@ -213,9 +263,30 @@ declare interface D1WorkersConfig {
213
263
  export { D1WorkersConfig }
214
264
  export { D1WorkersConfig as D1WorkersConfig_alias_1 }
215
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
+
216
282
  export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
217
283
  interval?: number) => Promise<T>;
218
284
 
285
+ /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
286
+ declare type SelectIdentifier = string & {
287
+ __brand: 'SelectIdentifier';
288
+ };
289
+
219
290
  /**
220
291
  * SQL Builder class for constructing type-safe SQL queries
221
292
  * This helps create maintainable and secure SQL queries with proper parameter handling
@@ -279,7 +350,6 @@ export declare class SqlBuilder {
279
350
  * @returns The builder instance
280
351
  */
281
352
  createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
282
- raw(sql: string, ...params: SqlParam[]): SqlBuilder;
283
353
  /**
284
354
  * Add a LIKE condition to the query
285
355
  * @param column The column to check
@@ -317,7 +387,7 @@ export declare type SqlParam = string | number | boolean | null | undefined;
317
387
  /**
318
388
  * Interface for SQL query options with generic type support
319
389
  */
320
- declare interface SqlQueryOptions {
390
+ export declare interface SqlQueryOptions {
321
391
  /** SQL query to execute */
322
392
  sql: string;
323
393
  /** Parameters to bind to the query */
@@ -325,7 +395,5 @@ declare interface SqlQueryOptions {
325
395
  /** Whether to return only the first result */
326
396
  first?: boolean;
327
397
  }
328
- export { SqlQueryOptions }
329
- export { SqlQueryOptions as SqlQueryOptions_alias_1 }
330
398
 
331
399
  export { }
@@ -1,42 +1,18 @@
1
1
  import type { D1Database as D1Database_2 } from '@cloudflare/workers-types';
2
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';
3
6
  import { MastraStorage } from '@mastra/core/storage';
4
- import type { MessageType } from '@mastra/core/memory';
5
- import type { MessageType as MessageType_2 } from '@mastra/core';
7
+ import type { PaginationInfo } from '@mastra/core/storage';
6
8
  import type { StorageColumn } from '@mastra/core/storage';
7
9
  import type { StorageGetMessagesArg } from '@mastra/core/storage';
8
10
  import type { StorageThreadType } from '@mastra/core/memory';
9
11
  import type { TABLE_NAMES } from '@mastra/core/storage';
12
+ import type { Trace } from '@mastra/core/telemetry';
10
13
  import type { WorkflowRun } from '@mastra/core/storage';
11
14
  import type { WorkflowRuns } from '@mastra/core/storage';
12
15
  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
16
 
41
17
  export declare const createSampleTrace: (name: string, scope?: string, attributes?: Record<string, string>) => {
42
18
  id: string;
@@ -55,12 +31,6 @@ export declare const createSampleTrace: (name: string, scope?: string, attribute
55
31
  createdAt: string;
56
32
  };
57
33
 
58
- export declare const createSampleWorkflowSnapshot: (threadId: string, status: string, createdAt?: Date) => {
59
- snapshot: WorkflowRunState_2;
60
- runId: string;
61
- stepId: string;
62
- };
63
-
64
34
  export declare function createSqlBuilder(): SqlBuilder;
65
35
 
66
36
  /**
@@ -92,7 +62,6 @@ declare class D1Store extends MastraStorage {
92
62
  constructor(config: D1StoreConfig);
93
63
  private getTableName;
94
64
  private formatSqlParams;
95
- private createIndexIfNotExists;
96
65
  private executeWorkersBindingQuery;
97
66
  private executeRestQuery;
98
67
  /**
@@ -101,15 +70,25 @@ declare class D1Store extends MastraStorage {
101
70
  * @returns Query results as an array or a single object if first=true
102
71
  */
103
72
  private executeQuery;
104
- private getSqlType;
105
- private ensureDate;
106
- private serializeDate;
73
+ private getTableColumns;
107
74
  private serializeValue;
108
75
  private deserializeValue;
76
+ protected getSqlType(type: StorageColumn['type']): string;
109
77
  createTable({ tableName, schema, }: {
110
78
  tableName: TABLE_NAMES;
111
79
  schema: Record<string, StorageColumn>;
112
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>;
113
92
  clearTable({ tableName }: {
114
93
  tableName: TABLE_NAMES;
115
94
  }): Promise<void>;
@@ -125,9 +104,19 @@ declare class D1Store extends MastraStorage {
125
104
  getThreadById({ threadId }: {
126
105
  threadId: string;
127
106
  }): Promise<StorageThreadType | null>;
107
+ /**
108
+ * @deprecated use getThreadsByResourceIdPaginated instead
109
+ */
128
110
  getThreadsByResourceId({ resourceId }: {
129
111
  resourceId: string;
130
112
  }): Promise<StorageThreadType[]>;
113
+ getThreadsByResourceIdPaginated(args: {
114
+ resourceId: string;
115
+ page: number;
116
+ perPage: number;
117
+ }): Promise<PaginationInfo & {
118
+ threads: StorageThreadType[];
119
+ }>;
131
120
  saveThread({ thread }: {
132
121
  thread: StorageThreadType;
133
122
  }): Promise<StorageThreadType>;
@@ -139,10 +128,29 @@ declare class D1Store extends MastraStorage {
139
128
  deleteThread({ threadId }: {
140
129
  threadId: string;
141
130
  }): Promise<void>;
142
- saveMessages({ messages }: {
143
- messages: MessageType[];
144
- }): Promise<MessageType[]>;
145
- getMessages<T = MessageType>({ threadId, selectBy }: StorageGetMessagesArg): Promise<T[]>;
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
+ }>;
146
154
  persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
147
155
  workflowName: string;
148
156
  runId: string;
@@ -161,6 +169,15 @@ declare class D1Store extends MastraStorage {
161
169
  tableName: TABLE_NAMES;
162
170
  records: Record<string, any>[];
163
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
+ */
164
181
  getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
165
182
  name?: string;
166
183
  scope?: string;
@@ -169,8 +186,32 @@ declare class D1Store extends MastraStorage {
169
186
  attributes?: Record<string, string>;
170
187
  fromDate?: Date;
171
188
  toDate?: Date;
172
- }): Promise<Record<string, any>[]>;
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
+ */
173
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
+ }>;
174
215
  private parseWorkflowRun;
175
216
  private hasColumn;
176
217
  getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
@@ -190,6 +231,15 @@ declare class D1Store extends MastraStorage {
190
231
  * No explicit cleanup needed for D1 in either REST or Workers Binding mode
191
232
  */
192
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[]>;
193
243
  }
194
244
  export { D1Store }
195
245
  export { D1Store as D1Store_alias_1 }
@@ -213,9 +263,30 @@ declare interface D1WorkersConfig {
213
263
  export { D1WorkersConfig }
214
264
  export { D1WorkersConfig as D1WorkersConfig_alias_1 }
215
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
+
216
282
  export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
217
283
  interval?: number) => Promise<T>;
218
284
 
285
+ /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
286
+ declare type SelectIdentifier = string & {
287
+ __brand: 'SelectIdentifier';
288
+ };
289
+
219
290
  /**
220
291
  * SQL Builder class for constructing type-safe SQL queries
221
292
  * This helps create maintainable and secure SQL queries with proper parameter handling
@@ -279,7 +350,6 @@ export declare class SqlBuilder {
279
350
  * @returns The builder instance
280
351
  */
281
352
  createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
282
- raw(sql: string, ...params: SqlParam[]): SqlBuilder;
283
353
  /**
284
354
  * Add a LIKE condition to the query
285
355
  * @param column The column to check
@@ -317,7 +387,7 @@ export declare type SqlParam = string | number | boolean | null | undefined;
317
387
  /**
318
388
  * Interface for SQL query options with generic type support
319
389
  */
320
- declare interface SqlQueryOptions {
390
+ export declare interface SqlQueryOptions {
321
391
  /** SQL query to execute */
322
392
  sql: string;
323
393
  /** Parameters to bind to the query */
@@ -325,7 +395,5 @@ declare interface SqlQueryOptions {
325
395
  /** Whether to return only the first result */
326
396
  first?: boolean;
327
397
  }
328
- export { SqlQueryOptions }
329
- export { SqlQueryOptions as SqlQueryOptions_alias_1 }
330
398
 
331
399
  export { }