@mastra/cloudflare-d1 0.0.0-pass-headers-for-create-mastra-client-20250530010057 → 0.0.0-pgvector-index-fix-20250905222058

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 +1085 -0
  2. package/LICENSE.md +11 -42
  3. package/README.md +15 -0
  4. package/dist/index.cjs +1924 -563
  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 +1909 -548
  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 +30 -18
  31. package/dist/_tsup-dts-rollup.d.cts +0 -349
  32. package/dist/_tsup-dts-rollup.d.ts +0 -349
  33. package/dist/index.d.cts +0 -4
@@ -1,349 +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
- /**
217
- * Parses and returns a valid SQL SELECT column identifier.
218
- * Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
219
- *
220
- * @param column - The column identifier string to parse.
221
- * @returns The validated column identifier as a branded type.
222
- * @throws {Error} If invalid.
223
- *
224
- * @example
225
- * const col = parseSelectIdentifier('user_id'); // Ok
226
- * parseSelectIdentifier('user_id AS uid'); // Ok
227
- * parseSelectIdentifier('*'); // Ok
228
- * parseSelectIdentifier('user id'); // Throws error
229
- */
230
- export declare function parseSelectIdentifier(column: string): SelectIdentifier;
231
-
232
- export declare const retryUntil: <T>(fn: () => Promise<T>, condition: (result: T) => boolean, timeout?: number, // REST API needs longer timeout due to higher latency
233
- interval?: number) => Promise<T>;
234
-
235
- /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
236
- declare type SelectIdentifier = string & {
237
- __brand: 'SelectIdentifier';
238
- };
239
-
240
- /**
241
- * SQL Builder class for constructing type-safe SQL queries
242
- * This helps create maintainable and secure SQL queries with proper parameter handling
243
- */
244
- export declare class SqlBuilder {
245
- private sql;
246
- private params;
247
- private whereAdded;
248
- select(columns?: string | string[]): SqlBuilder;
249
- from(table: string): SqlBuilder;
250
- /**
251
- * Add a WHERE clause to the query
252
- * @param condition The condition to add
253
- * @param params Parameters to bind to the condition
254
- */
255
- where(condition: string, ...params: SqlParam[]): SqlBuilder;
256
- /**
257
- * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
258
- * @param condition The condition to add
259
- * @param params Parameters to bind to the condition
260
- */
261
- whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
262
- andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
263
- orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
264
- orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
265
- limit(count: number): SqlBuilder;
266
- offset(count: number): SqlBuilder;
267
- count(): SqlBuilder;
268
- /**
269
- * Insert a row, or update specific columns on conflict (upsert).
270
- * @param table Table name
271
- * @param columns Columns to insert
272
- * @param values Values to insert
273
- * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
274
- * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
275
- */
276
- insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
277
- update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
278
- delete(table: string): SqlBuilder;
279
- /**
280
- * Create a table if it doesn't exist
281
- * @param table The table name
282
- * @param columnDefinitions The column definitions as an array of strings
283
- * @param tableConstraints Optional constraints for the table
284
- * @returns The builder instance
285
- */
286
- createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
287
- /**
288
- * Check if an index exists in the database
289
- * @param indexName The name of the index to check
290
- * @param tableName The table the index is on
291
- * @returns The builder instance
292
- */
293
- checkIndexExists(indexName: string, tableName: string): SqlBuilder;
294
- /**
295
- * Create an index if it doesn't exist
296
- * @param indexName The name of the index to create
297
- * @param tableName The table to create the index on
298
- * @param columnName The column to index
299
- * @param indexType Optional index type (e.g., 'UNIQUE')
300
- * @returns The builder instance
301
- */
302
- createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
303
- /**
304
- * Add a LIKE condition to the query
305
- * @param column The column to check
306
- * @param value The value to match (will be wrapped with % for LIKE)
307
- * @param exact If true, will not add % wildcards
308
- */
309
- like(column: string, value: string, exact?: boolean): SqlBuilder;
310
- /**
311
- * Add a JSON LIKE condition for searching in JSON fields
312
- * @param column The JSON column to search in
313
- * @param key The JSON key to match
314
- * @param value The value to match
315
- */
316
- jsonLike(column: string, key: string, value: string): SqlBuilder;
317
- /**
318
- * Get the built query
319
- * @returns Object containing the SQL string and parameters array
320
- */
321
- build(): {
322
- sql: string;
323
- params: SqlParam[];
324
- };
325
- /**
326
- * Reset the builder for reuse
327
- * @returns The reset builder instance
328
- */
329
- reset(): SqlBuilder;
330
- }
331
-
332
- /**
333
- * Type definition for SQL query parameters
334
- */
335
- export declare type SqlParam = string | number | boolean | null | undefined;
336
-
337
- /**
338
- * Interface for SQL query options with generic type support
339
- */
340
- export declare interface SqlQueryOptions {
341
- /** SQL query to execute */
342
- sql: string;
343
- /** Parameters to bind to the query */
344
- params?: SqlParam[];
345
- /** Whether to return only the first result */
346
- first?: boolean;
347
- }
348
-
349
- 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';