@mastra/cloudflare-d1 0.0.0-working-memory-per-user-20250620161509 → 0.0.0-zod-v4-compat-part-2-20250820135355

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,393 +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
- * @deprecated use getTracesPaginated instead
174
- */
175
- getTraces({ name, scope, page, perPage, attributes, fromDate, toDate, }: {
176
- name?: string;
177
- scope?: string;
178
- page: number;
179
- perPage: number;
180
- attributes?: Record<string, string>;
181
- fromDate?: Date;
182
- toDate?: Date;
183
- }): Promise<Trace[]>;
184
- getTracesPaginated(args: {
185
- name?: string;
186
- scope?: string;
187
- attributes?: Record<string, string>;
188
- page: number;
189
- perPage: number;
190
- fromDate?: Date;
191
- toDate?: Date;
192
- }): Promise<PaginationInfo & {
193
- traces: Trace[];
194
- }>;
195
- /**
196
- * @deprecated use getEvals instead
197
- */
198
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
199
- getEvals(options?: {
200
- agentName?: string;
201
- type?: 'test' | 'live';
202
- page?: number;
203
- perPage?: number;
204
- fromDate?: Date;
205
- toDate?: Date;
206
- }): Promise<PaginationInfo & {
207
- evals: EvalRow[];
208
- }>;
209
- private parseWorkflowRun;
210
- private hasColumn;
211
- getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
212
- workflowName?: string;
213
- fromDate?: Date;
214
- toDate?: Date;
215
- limit?: number;
216
- offset?: number;
217
- resourceId?: string;
218
- }): Promise<WorkflowRuns>;
219
- getWorkflowRunById({ runId, workflowName, }: {
220
- runId: string;
221
- workflowName?: string;
222
- }): Promise<WorkflowRun | null>;
223
- /**
224
- * Close the database connection
225
- * No explicit cleanup needed for D1 in either REST or Workers Binding mode
226
- */
227
- close(): Promise<void>;
228
- updateMessages(_args: {
229
- messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
230
- id: string;
231
- content?: {
232
- metadata?: MastraMessageContentV2['metadata'];
233
- content?: MastraMessageContentV2['content'];
234
- };
235
- }[];
236
- }): Promise<MastraMessageV2[]>;
237
- }
238
- export { D1Store }
239
- export { D1Store as D1Store_alias_1 }
240
-
241
- /**
242
- * Combined configuration type supporting both REST API and Workers Binding API
243
- */
244
- declare type D1StoreConfig = D1Config | D1WorkersConfig;
245
- export { D1StoreConfig }
246
- export { D1StoreConfig as D1StoreConfig_alias_1 }
247
-
248
- /**
249
- * Configuration for D1 using the Workers Binding API
250
- */
251
- declare interface D1WorkersConfig {
252
- /** D1 database binding from Workers environment */
253
- binding: D1Database_2;
254
- /** Optional prefix for table names */
255
- tablePrefix?: string;
256
- }
257
- export { D1WorkersConfig }
258
- export { D1WorkersConfig as D1WorkersConfig_alias_1 }
259
-
260
- /**
261
- * Parses and returns a valid SQL SELECT column identifier.
262
- * Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
263
- *
264
- * @param column - The column identifier string to parse.
265
- * @returns The validated column identifier as a branded type.
266
- * @throws {Error} If invalid.
267
- *
268
- * @example
269
- * const col = parseSelectIdentifier('user_id'); // Ok
270
- * parseSelectIdentifier('user_id AS uid'); // Ok
271
- * parseSelectIdentifier('*'); // Ok
272
- * parseSelectIdentifier('user id'); // Throws error
273
- */
274
- export declare function parseSelectIdentifier(column: string): SelectIdentifier;
275
-
276
- export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
277
- interval?: number) => Promise<T>;
278
-
279
- /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
280
- declare type SelectIdentifier = string & {
281
- __brand: 'SelectIdentifier';
282
- };
283
-
284
- /**
285
- * SQL Builder class for constructing type-safe SQL queries
286
- * This helps create maintainable and secure SQL queries with proper parameter handling
287
- */
288
- export declare class SqlBuilder {
289
- private sql;
290
- private params;
291
- private whereAdded;
292
- select(columns?: string | string[]): SqlBuilder;
293
- from(table: string): SqlBuilder;
294
- /**
295
- * Add a WHERE clause to the query
296
- * @param condition The condition to add
297
- * @param params Parameters to bind to the condition
298
- */
299
- where(condition: string, ...params: SqlParam[]): SqlBuilder;
300
- /**
301
- * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
302
- * @param condition The condition to add
303
- * @param params Parameters to bind to the condition
304
- */
305
- whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
306
- andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
307
- orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
308
- orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
309
- limit(count: number): SqlBuilder;
310
- offset(count: number): SqlBuilder;
311
- count(): SqlBuilder;
312
- /**
313
- * Insert a row, or update specific columns on conflict (upsert).
314
- * @param table Table name
315
- * @param columns Columns to insert
316
- * @param values Values to insert
317
- * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
318
- * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
319
- */
320
- insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
321
- update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
322
- delete(table: string): SqlBuilder;
323
- /**
324
- * Create a table if it doesn't exist
325
- * @param table The table name
326
- * @param columnDefinitions The column definitions as an array of strings
327
- * @param tableConstraints Optional constraints for the table
328
- * @returns The builder instance
329
- */
330
- createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
331
- /**
332
- * Check if an index exists in the database
333
- * @param indexName The name of the index to check
334
- * @param tableName The table the index is on
335
- * @returns The builder instance
336
- */
337
- checkIndexExists(indexName: string, tableName: string): SqlBuilder;
338
- /**
339
- * Create an index if it doesn't exist
340
- * @param indexName The name of the index to create
341
- * @param tableName The table to create the index on
342
- * @param columnName The column to index
343
- * @param indexType Optional index type (e.g., 'UNIQUE')
344
- * @returns The builder instance
345
- */
346
- createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
347
- /**
348
- * Add a LIKE condition to the query
349
- * @param column The column to check
350
- * @param value The value to match (will be wrapped with % for LIKE)
351
- * @param exact If true, will not add % wildcards
352
- */
353
- like(column: string, value: string, exact?: boolean): SqlBuilder;
354
- /**
355
- * Add a JSON LIKE condition for searching in JSON fields
356
- * @param column The JSON column to search in
357
- * @param key The JSON key to match
358
- * @param value The value to match
359
- */
360
- jsonLike(column: string, key: string, value: string): SqlBuilder;
361
- /**
362
- * Get the built query
363
- * @returns Object containing the SQL string and parameters array
364
- */
365
- build(): {
366
- sql: string;
367
- params: SqlParam[];
368
- };
369
- /**
370
- * Reset the builder for reuse
371
- * @returns The reset builder instance
372
- */
373
- reset(): SqlBuilder;
374
- }
375
-
376
- /**
377
- * Type definition for SQL query parameters
378
- */
379
- export declare type SqlParam = string | number | boolean | null | undefined;
380
-
381
- /**
382
- * Interface for SQL query options with generic type support
383
- */
384
- export declare interface SqlQueryOptions {
385
- /** SQL query to execute */
386
- sql: string;
387
- /** Parameters to bind to the query */
388
- params?: SqlParam[];
389
- /** Whether to return only the first result */
390
- first?: boolean;
391
- }
392
-
393
- 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';