@mastra/cloudflare-d1 0.12.4 → 0.12.5
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.
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/storage/domains/legacy-evals/index.d.ts +20 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +82 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/operations/index.d.ts +72 -0
- package/dist/storage/domains/operations/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +49 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/traces/index.d.ts +18 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +3 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +33 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +256 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/sql-builder.d.ts +128 -0
- package/dist/storage/sql-builder.d.ts.map +1 -0
- package/dist/storage/test-utils.d.ts +19 -0
- package/dist/storage/test-utils.d.ts.map +1 -0
- package/package.json +10 -9
- package/dist/_tsup-dts-rollup.d.cts +0 -707
- package/dist/_tsup-dts-rollup.d.ts +0 -707
- package/dist/index.d.cts +0 -7
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { D1Database } from '@cloudflare/workers-types';
|
|
2
|
+
import { StoreOperations } from '@mastra/core/storage';
|
|
3
|
+
import type { TABLE_NAMES, StorageColumn } from '@mastra/core/storage';
|
|
4
|
+
import type Cloudflare from 'cloudflare';
|
|
5
|
+
import type { SqlQueryOptions } from '../../sql-builder.js';
|
|
6
|
+
export type D1QueryResult = Awaited<ReturnType<Cloudflare['d1']['database']['query']>>['result'];
|
|
7
|
+
export interface D1Client {
|
|
8
|
+
query(args: {
|
|
9
|
+
sql: string;
|
|
10
|
+
params: string[];
|
|
11
|
+
}): Promise<{
|
|
12
|
+
result: D1QueryResult;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export interface StoreOperationsD1Config {
|
|
16
|
+
client?: D1Client;
|
|
17
|
+
binding?: D1Database;
|
|
18
|
+
tablePrefix?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class StoreOperationsD1 extends StoreOperations {
|
|
21
|
+
private client?;
|
|
22
|
+
private binding?;
|
|
23
|
+
private tablePrefix;
|
|
24
|
+
constructor(config: StoreOperationsD1Config);
|
|
25
|
+
hasColumn(table: string, column: string): Promise<boolean>;
|
|
26
|
+
getTableName(tableName: TABLE_NAMES): string;
|
|
27
|
+
private formatSqlParams;
|
|
28
|
+
private executeWorkersBindingQuery;
|
|
29
|
+
private executeRestQuery;
|
|
30
|
+
executeQuery(options: SqlQueryOptions): Promise<Record<string, any>[] | Record<string, any> | null>;
|
|
31
|
+
private getTableColumns;
|
|
32
|
+
private serializeValue;
|
|
33
|
+
protected getSqlType(type: StorageColumn['type']): string;
|
|
34
|
+
createTable({ tableName, schema, }: {
|
|
35
|
+
tableName: TABLE_NAMES;
|
|
36
|
+
schema: Record<string, StorageColumn>;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
clearTable({ tableName }: {
|
|
39
|
+
tableName: TABLE_NAMES;
|
|
40
|
+
}): Promise<void>;
|
|
41
|
+
dropTable({ tableName }: {
|
|
42
|
+
tableName: TABLE_NAMES;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
alterTable(args: {
|
|
45
|
+
tableName: TABLE_NAMES;
|
|
46
|
+
schema: Record<string, StorageColumn>;
|
|
47
|
+
ifNotExists: string[];
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
insert({ tableName, record }: {
|
|
50
|
+
tableName: TABLE_NAMES;
|
|
51
|
+
record: Record<string, any>;
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
batchInsert({ tableName, records }: {
|
|
54
|
+
tableName: TABLE_NAMES;
|
|
55
|
+
records: Record<string, any>[];
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
load<R>({ tableName, keys }: {
|
|
58
|
+
tableName: TABLE_NAMES;
|
|
59
|
+
keys: Record<string, string>;
|
|
60
|
+
}): Promise<R | null>;
|
|
61
|
+
processRecord(record: Record<string, any>): Promise<Record<string, any>>;
|
|
62
|
+
/**
|
|
63
|
+
* Upsert multiple records in a batch operation
|
|
64
|
+
* @param tableName The table to insert into
|
|
65
|
+
* @param records The records to insert
|
|
66
|
+
*/
|
|
67
|
+
batchUpsert({ tableName, records }: {
|
|
68
|
+
tableName: TABLE_NAMES;
|
|
69
|
+
records: Record<string, any>[];
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/operations/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGnE,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEjG,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,IAAI,EAAE;QAAE,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1
|
+
import type { ScoreRowData } from '@mastra/core/scores';
|
|
2
|
+
import { ScoresStorage } from '@mastra/core/storage';
|
|
3
|
+
import type { StoragePagination, PaginationInfo } from '@mastra/core/storage';
|
|
4
|
+
import type Cloudflare from 'cloudflare';
|
|
5
|
+
import type { StoreOperationsD1 } from '../operations/index.js';
|
|
6
|
+
export type D1QueryResult = Awaited<ReturnType<Cloudflare['d1']['database']['query']>>['result'];
|
|
7
|
+
export interface D1Client {
|
|
8
|
+
query(args: {
|
|
9
|
+
sql: string;
|
|
10
|
+
params: string[];
|
|
11
|
+
}): Promise<{
|
|
12
|
+
result: D1QueryResult;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export declare class ScoresStorageD1 extends ScoresStorage {
|
|
16
|
+
private operations;
|
|
17
|
+
constructor({ operations }: {
|
|
18
|
+
operations: StoreOperationsD1;
|
|
19
|
+
});
|
|
20
|
+
getScoreById({ id }: {
|
|
21
|
+
id: string;
|
|
22
|
+
}): Promise<ScoreRowData | null>;
|
|
23
|
+
saveScore(score: Omit<ScoreRowData, 'createdAt' | 'updatedAt'>): Promise<{
|
|
24
|
+
score: ScoreRowData;
|
|
25
|
+
}>;
|
|
26
|
+
getScoresByScorerId({ scorerId, pagination, }: {
|
|
27
|
+
scorerId: string;
|
|
28
|
+
pagination: StoragePagination;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
pagination: PaginationInfo;
|
|
31
|
+
scores: ScoreRowData[];
|
|
32
|
+
}>;
|
|
33
|
+
getScoresByRunId({ runId, pagination, }: {
|
|
34
|
+
runId: string;
|
|
35
|
+
pagination: StoragePagination;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
pagination: PaginationInfo;
|
|
38
|
+
scores: ScoreRowData[];
|
|
39
|
+
}>;
|
|
40
|
+
getScoresByEntityId({ entityId, entityType, pagination, }: {
|
|
41
|
+
pagination: StoragePagination;
|
|
42
|
+
entityId: string;
|
|
43
|
+
entityType: string;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
pagination: PaginationInfo;
|
|
46
|
+
scores: ScoreRowData[];
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAiB,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AAEjG,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,aAAa,CAAA;KAAE,CAAC,CAAC;CACpF;AAoBD,qBAAa,eAAgB,SAAQ,aAAa;IAChD,OAAO,CAAC,UAAU,CAAoB;gBAE1B,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,iBAAiB,CAAA;KAAE;IAKvD,YAAY,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAyBlE,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,WAAW,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;IA6CjG,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,GACX,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAuD7D,gBAAgB,CAAC,EACrB,KAAK,EACL,UAAU,GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAuD7D,mBAAmB,CAAC,EACxB,QAAQ,EACR,UAAU,EACV,UAAU,GACX,EAAE;QACD,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;CA2DpE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { PaginationInfo, StorageGetTracesArg, StorageGetTracesPaginatedArg } from '@mastra/core/storage';
|
|
2
|
+
import { TracesStorage } from '@mastra/core/storage';
|
|
3
|
+
import type { Trace } from '@mastra/core/telemetry';
|
|
4
|
+
import type { StoreOperationsD1 } from '../operations/index.js';
|
|
5
|
+
export declare class TracesStorageD1 extends TracesStorage {
|
|
6
|
+
private operations;
|
|
7
|
+
constructor({ operations }: {
|
|
8
|
+
operations: StoreOperationsD1;
|
|
9
|
+
});
|
|
10
|
+
getTraces(args: StorageGetTracesArg): Promise<Trace[]>;
|
|
11
|
+
getTracesPaginated(args: StorageGetTracesPaginatedArg): Promise<PaginationInfo & {
|
|
12
|
+
traces: Trace[];
|
|
13
|
+
}>;
|
|
14
|
+
batchTraceInsert({ records }: {
|
|
15
|
+
records: Record<string, any>[];
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/traces/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAgB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAOvD,qBAAa,eAAgB,SAAQ,aAAa;IAChD,OAAO,CAAC,UAAU,CAAoB;gBAE1B,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,iBAAiB,CAAA;KAAE;IAKvD,SAAS,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAsCtD,kBAAkB,CAAC,IAAI,EAAE,4BAA4B,GAAG,OAAO,CAAC,cAAc,GAAG;QAAE,MAAM,EAAE,KAAK,EAAE,CAAA;KAAE,CAAC;IA+FrG,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAOvF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/storage/domains/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAE3E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,CAwB/D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { WorkflowRun, WorkflowRuns } from '@mastra/core/storage';
|
|
2
|
+
import { WorkflowsStorage } from '@mastra/core/storage';
|
|
3
|
+
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
4
|
+
import type { StoreOperationsD1 } from '../operations/index.js';
|
|
5
|
+
export declare class WorkflowsStorageD1 extends WorkflowsStorage {
|
|
6
|
+
private operations;
|
|
7
|
+
constructor({ operations }: {
|
|
8
|
+
operations: StoreOperationsD1;
|
|
9
|
+
});
|
|
10
|
+
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
11
|
+
workflowName: string;
|
|
12
|
+
runId: string;
|
|
13
|
+
snapshot: WorkflowRunState;
|
|
14
|
+
}): Promise<void>;
|
|
15
|
+
loadWorkflowSnapshot(params: {
|
|
16
|
+
workflowName: string;
|
|
17
|
+
runId: string;
|
|
18
|
+
}): Promise<WorkflowRunState | null>;
|
|
19
|
+
private parseWorkflowRun;
|
|
20
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
|
|
21
|
+
workflowName?: string;
|
|
22
|
+
fromDate?: Date;
|
|
23
|
+
toDate?: Date;
|
|
24
|
+
limit?: number;
|
|
25
|
+
offset?: number;
|
|
26
|
+
resourceId?: string;
|
|
27
|
+
}): Promise<WorkflowRuns>;
|
|
28
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
29
|
+
runId: string;
|
|
30
|
+
workflowName?: string;
|
|
31
|
+
}): Promise<WorkflowRun | null>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/workflows/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,E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W,GAAG,IAAI,CAAC;CA+BhC"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import type { D1Database } from '@cloudflare/workers-types';
|
|
2
|
+
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
3
|
+
import type { StorageThreadType, MastraMessageV1, MastraMessageV2 } from '@mastra/core/memory';
|
|
4
|
+
import type { ScoreRowData } from '@mastra/core/scores';
|
|
5
|
+
import { MastraStorage } from '@mastra/core/storage';
|
|
6
|
+
import type { EvalRow, PaginationInfo, StorageColumn, StorageGetMessagesArg, StorageGetTracesPaginatedArg, StorageResourceType, TABLE_NAMES, WorkflowRun, StoragePagination, WorkflowRuns, StorageDomains, PaginationArgs } from '@mastra/core/storage';
|
|
7
|
+
import type { Trace } from '@mastra/core/telemetry';
|
|
8
|
+
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
9
|
+
import Cloudflare from 'cloudflare';
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for D1 using the REST API
|
|
12
|
+
*/
|
|
13
|
+
export interface D1Config {
|
|
14
|
+
/** Cloudflare account ID */
|
|
15
|
+
accountId: string;
|
|
16
|
+
/** Cloudflare API token with D1 access */
|
|
17
|
+
apiToken: string;
|
|
18
|
+
/** D1 database ID */
|
|
19
|
+
databaseId: string;
|
|
20
|
+
/** Optional prefix for table names */
|
|
21
|
+
tablePrefix?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface D1ClientConfig {
|
|
24
|
+
/** Optional prefix for table names */
|
|
25
|
+
tablePrefix?: string;
|
|
26
|
+
/** D1 Client */
|
|
27
|
+
client: D1Client;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for D1 using the Workers Binding API
|
|
31
|
+
*/
|
|
32
|
+
export interface D1WorkersConfig {
|
|
33
|
+
/** D1 database binding from Workers environment */
|
|
34
|
+
binding: D1Database;
|
|
35
|
+
/** Optional prefix for table names */
|
|
36
|
+
tablePrefix?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Combined configuration type supporting both REST API and Workers Binding API
|
|
40
|
+
*/
|
|
41
|
+
export type D1StoreConfig = D1Config | D1WorkersConfig | D1ClientConfig;
|
|
42
|
+
export type D1QueryResult = Awaited<ReturnType<Cloudflare['d1']['database']['query']>>['result'];
|
|
43
|
+
export interface D1Client {
|
|
44
|
+
query(args: {
|
|
45
|
+
sql: string;
|
|
46
|
+
params: string[];
|
|
47
|
+
}): Promise<{
|
|
48
|
+
result: D1QueryResult;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
export declare class D1Store extends MastraStorage {
|
|
52
|
+
private client?;
|
|
53
|
+
private binding?;
|
|
54
|
+
private tablePrefix;
|
|
55
|
+
stores: StorageDomains;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new D1Store instance
|
|
58
|
+
* @param config Configuration for D1 access (either REST API or Workers Binding API)
|
|
59
|
+
*/
|
|
60
|
+
constructor(config: D1StoreConfig);
|
|
61
|
+
get supports(): {
|
|
62
|
+
selectByIncludeResourceScope: boolean;
|
|
63
|
+
resourceWorkingMemory: boolean;
|
|
64
|
+
hasColumn: boolean;
|
|
65
|
+
createTable: boolean;
|
|
66
|
+
deleteMessages: boolean;
|
|
67
|
+
};
|
|
68
|
+
createTable({ tableName, schema, }: {
|
|
69
|
+
tableName: TABLE_NAMES;
|
|
70
|
+
schema: Record<string, StorageColumn>;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Alters table schema to add columns if they don't exist
|
|
74
|
+
* @param tableName Name of the table
|
|
75
|
+
* @param schema Schema of the table
|
|
76
|
+
* @param ifNotExists Array of column names to add if they don't exist
|
|
77
|
+
*/
|
|
78
|
+
alterTable({ tableName, schema, ifNotExists, }: {
|
|
79
|
+
tableName: TABLE_NAMES;
|
|
80
|
+
schema: Record<string, StorageColumn>;
|
|
81
|
+
ifNotExists: string[];
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
clearTable({ tableName }: {
|
|
84
|
+
tableName: TABLE_NAMES;
|
|
85
|
+
}): Promise<void>;
|
|
86
|
+
dropTable({ tableName }: {
|
|
87
|
+
tableName: TABLE_NAMES;
|
|
88
|
+
}): Promise<void>;
|
|
89
|
+
hasColumn(table: string, column: string): Promise<boolean>;
|
|
90
|
+
insert({ tableName, record }: {
|
|
91
|
+
tableName: TABLE_NAMES;
|
|
92
|
+
record: Record<string, any>;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
load<R>({ tableName, keys }: {
|
|
95
|
+
tableName: TABLE_NAMES;
|
|
96
|
+
keys: Record<string, string>;
|
|
97
|
+
}): Promise<R | null>;
|
|
98
|
+
getThreadById({ threadId }: {
|
|
99
|
+
threadId: string;
|
|
100
|
+
}): Promise<StorageThreadType | null>;
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated use getThreadsByResourceIdPaginated instead
|
|
103
|
+
*/
|
|
104
|
+
getThreadsByResourceId({ resourceId }: {
|
|
105
|
+
resourceId: string;
|
|
106
|
+
}): Promise<StorageThreadType[]>;
|
|
107
|
+
getThreadsByResourceIdPaginated(args: {
|
|
108
|
+
resourceId: string;
|
|
109
|
+
page: number;
|
|
110
|
+
perPage: number;
|
|
111
|
+
}): Promise<PaginationInfo & {
|
|
112
|
+
threads: StorageThreadType[];
|
|
113
|
+
}>;
|
|
114
|
+
saveThread({ thread }: {
|
|
115
|
+
thread: StorageThreadType;
|
|
116
|
+
}): Promise<StorageThreadType>;
|
|
117
|
+
updateThread({ id, title, metadata, }: {
|
|
118
|
+
id: string;
|
|
119
|
+
title: string;
|
|
120
|
+
metadata: Record<string, unknown>;
|
|
121
|
+
}): Promise<StorageThreadType>;
|
|
122
|
+
deleteThread({ threadId }: {
|
|
123
|
+
threadId: string;
|
|
124
|
+
}): Promise<void>;
|
|
125
|
+
saveMessages(args: {
|
|
126
|
+
messages: MastraMessageV1[];
|
|
127
|
+
format?: undefined | 'v1';
|
|
128
|
+
}): Promise<MastraMessageV1[]>;
|
|
129
|
+
saveMessages(args: {
|
|
130
|
+
messages: MastraMessageV2[];
|
|
131
|
+
format: 'v2';
|
|
132
|
+
}): Promise<MastraMessageV2[]>;
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated use getMessagesPaginated instead
|
|
135
|
+
*/
|
|
136
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
137
|
+
format?: 'v1';
|
|
138
|
+
}): Promise<MastraMessageV1[]>;
|
|
139
|
+
getMessages(args: StorageGetMessagesArg & {
|
|
140
|
+
format: 'v2';
|
|
141
|
+
}): Promise<MastraMessageV2[]>;
|
|
142
|
+
getMessagesPaginated({ threadId, selectBy, format, }: StorageGetMessagesArg & {
|
|
143
|
+
format?: 'v1' | 'v2';
|
|
144
|
+
}): Promise<PaginationInfo & {
|
|
145
|
+
messages: MastraMessageV1[] | MastraMessageV2[];
|
|
146
|
+
}>;
|
|
147
|
+
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
148
|
+
workflowName: string;
|
|
149
|
+
runId: string;
|
|
150
|
+
snapshot: WorkflowRunState;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
loadWorkflowSnapshot(params: {
|
|
153
|
+
workflowName: string;
|
|
154
|
+
runId: string;
|
|
155
|
+
}): Promise<WorkflowRunState | null>;
|
|
156
|
+
getWorkflowRuns({ workflowName, fromDate, toDate, limit, offset, resourceId, }?: {
|
|
157
|
+
workflowName?: string;
|
|
158
|
+
fromDate?: Date;
|
|
159
|
+
toDate?: Date;
|
|
160
|
+
limit?: number;
|
|
161
|
+
offset?: number;
|
|
162
|
+
resourceId?: string;
|
|
163
|
+
}): Promise<WorkflowRuns>;
|
|
164
|
+
getWorkflowRunById({ runId, workflowName, }: {
|
|
165
|
+
runId: string;
|
|
166
|
+
workflowName?: string;
|
|
167
|
+
}): Promise<WorkflowRun | null>;
|
|
168
|
+
/**
|
|
169
|
+
* Insert multiple records in a batch operation
|
|
170
|
+
* @param tableName The table to insert into
|
|
171
|
+
* @param records The records to insert
|
|
172
|
+
*/
|
|
173
|
+
batchInsert({ tableName, records }: {
|
|
174
|
+
tableName: TABLE_NAMES;
|
|
175
|
+
records: Record<string, any>[];
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* @deprecated use getTracesPaginated instead
|
|
179
|
+
*/
|
|
180
|
+
getTraces(args: {
|
|
181
|
+
name?: string;
|
|
182
|
+
scope?: string;
|
|
183
|
+
page: number;
|
|
184
|
+
perPage: number;
|
|
185
|
+
attributes?: Record<string, string>;
|
|
186
|
+
fromDate?: Date;
|
|
187
|
+
toDate?: Date;
|
|
188
|
+
}): Promise<Trace[]>;
|
|
189
|
+
getTracesPaginated(args: StorageGetTracesPaginatedArg): Promise<PaginationInfo & {
|
|
190
|
+
traces: Trace[];
|
|
191
|
+
}>;
|
|
192
|
+
/**
|
|
193
|
+
* @deprecated use getEvals instead
|
|
194
|
+
*/
|
|
195
|
+
getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
196
|
+
getEvals(options: {
|
|
197
|
+
agentName?: string;
|
|
198
|
+
type?: 'test' | 'live';
|
|
199
|
+
} & PaginationArgs): Promise<PaginationInfo & {
|
|
200
|
+
evals: EvalRow[];
|
|
201
|
+
}>;
|
|
202
|
+
updateMessages(_args: {
|
|
203
|
+
messages: Partial<Omit<MastraMessageV2, 'createdAt'>> & {
|
|
204
|
+
id: string;
|
|
205
|
+
content?: {
|
|
206
|
+
metadata?: MastraMessageContentV2['metadata'];
|
|
207
|
+
content?: MastraMessageContentV2['content'];
|
|
208
|
+
};
|
|
209
|
+
}[];
|
|
210
|
+
}): Promise<MastraMessageV2[]>;
|
|
211
|
+
getResourceById({ resourceId }: {
|
|
212
|
+
resourceId: string;
|
|
213
|
+
}): Promise<StorageResourceType | null>;
|
|
214
|
+
saveResource({ resource }: {
|
|
215
|
+
resource: StorageResourceType;
|
|
216
|
+
}): Promise<StorageResourceType>;
|
|
217
|
+
updateResource({ resourceId, workingMemory, metadata, }: {
|
|
218
|
+
resourceId: string;
|
|
219
|
+
workingMemory?: string;
|
|
220
|
+
metadata?: Record<string, unknown>;
|
|
221
|
+
}): Promise<StorageResourceType>;
|
|
222
|
+
getScoreById({ id: _id }: {
|
|
223
|
+
id: string;
|
|
224
|
+
}): Promise<ScoreRowData | null>;
|
|
225
|
+
saveScore(_score: ScoreRowData): Promise<{
|
|
226
|
+
score: ScoreRowData;
|
|
227
|
+
}>;
|
|
228
|
+
getScoresByRunId({ runId: _runId, pagination: _pagination, }: {
|
|
229
|
+
runId: string;
|
|
230
|
+
pagination: StoragePagination;
|
|
231
|
+
}): Promise<{
|
|
232
|
+
pagination: PaginationInfo;
|
|
233
|
+
scores: ScoreRowData[];
|
|
234
|
+
}>;
|
|
235
|
+
getScoresByEntityId({ entityId: _entityId, entityType: _entityType, pagination: _pagination, }: {
|
|
236
|
+
pagination: StoragePagination;
|
|
237
|
+
entityId: string;
|
|
238
|
+
entityType: string;
|
|
239
|
+
}): Promise<{
|
|
240
|
+
pagination: PaginationInfo;
|
|
241
|
+
scores: ScoreRowData[];
|
|
242
|
+
}>;
|
|
243
|
+
getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination, }: {
|
|
244
|
+
scorerId: string;
|
|
245
|
+
pagination: StoragePagination;
|
|
246
|
+
}): Promise<{
|
|
247
|
+
pagination: PaginationInfo;
|
|
248
|
+
scores: ScoreRowData[];
|
|
249
|
+
}>;
|
|
250
|
+
/**
|
|
251
|
+
* Close the database connection
|
|
252
|
+
* No explicit cleanup needed for D1 in either REST or Workers Binding mode
|
|
253
|
+
*/
|
|
254
|
+
close(): Promise<void>;
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,sBA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AAS,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,YAAY,CAAA;KAAE,CAAC;IAIjE,gBAAgB,CAAC,EACrB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,WAAW,GACxB,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAI7D,mBAAmB,CAAC,EACxB,QAAQ,EAAE,SAAS,EACnB,UAAU,EAAE,WAAW,EACvB,UAAU,EAAE,WAAW,GACxB,EAAE;QACD,UAAU,EAAE,iBAAiB,CAAC;QAC9B,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAQ7D,mBAAmB,CAAC,EACxB,QAAQ,EAAE,SAAS,EACnB,UAAU,EAAE,WAAW,GACxB,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,cAAc,CAAC;QAAC,MAAM,EAAE,YAAY,EAAE,CAAA;KAAE,CAAC;IAInE;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for SQL query parameters
|
|
3
|
+
*/
|
|
4
|
+
export type SqlParam = string | number | boolean | null | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Interface for SQL query options with generic type support
|
|
7
|
+
*/
|
|
8
|
+
export interface SqlQueryOptions {
|
|
9
|
+
/** SQL query to execute */
|
|
10
|
+
sql: string;
|
|
11
|
+
/** Parameters to bind to the query */
|
|
12
|
+
params?: SqlParam[];
|
|
13
|
+
/** Whether to return only the first result */
|
|
14
|
+
first?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* SQL Builder class for constructing type-safe SQL queries
|
|
18
|
+
* This helps create maintainable and secure SQL queries with proper parameter handling
|
|
19
|
+
*/
|
|
20
|
+
export declare class SqlBuilder {
|
|
21
|
+
private sql;
|
|
22
|
+
private params;
|
|
23
|
+
private whereAdded;
|
|
24
|
+
select(columns?: string | string[]): SqlBuilder;
|
|
25
|
+
from(table: string): SqlBuilder;
|
|
26
|
+
/**
|
|
27
|
+
* Add a WHERE clause to the query
|
|
28
|
+
* @param condition The condition to add
|
|
29
|
+
* @param params Parameters to bind to the condition
|
|
30
|
+
*/
|
|
31
|
+
where(condition: string, ...params: SqlParam[]): SqlBuilder;
|
|
32
|
+
/**
|
|
33
|
+
* Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
|
|
34
|
+
* @param condition The condition to add
|
|
35
|
+
* @param params Parameters to bind to the condition
|
|
36
|
+
*/
|
|
37
|
+
whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
|
|
38
|
+
andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
|
|
39
|
+
orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
|
|
40
|
+
orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
|
|
41
|
+
limit(count: number): SqlBuilder;
|
|
42
|
+
offset(count: number): SqlBuilder;
|
|
43
|
+
count(): SqlBuilder;
|
|
44
|
+
/**
|
|
45
|
+
* Insert a row, or update specific columns on conflict (upsert).
|
|
46
|
+
* @param table Table name
|
|
47
|
+
* @param columns Columns to insert
|
|
48
|
+
* @param values Values to insert
|
|
49
|
+
* @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
|
|
50
|
+
* @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
|
|
51
|
+
*/
|
|
52
|
+
insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
|
|
53
|
+
update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
|
|
54
|
+
delete(table: string): SqlBuilder;
|
|
55
|
+
/**
|
|
56
|
+
* Create a table if it doesn't exist
|
|
57
|
+
* @param table The table name
|
|
58
|
+
* @param columnDefinitions The column definitions as an array of strings
|
|
59
|
+
* @param tableConstraints Optional constraints for the table
|
|
60
|
+
* @returns The builder instance
|
|
61
|
+
*/
|
|
62
|
+
createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
|
|
63
|
+
/**
|
|
64
|
+
* Check if an index exists in the database
|
|
65
|
+
* @param indexName The name of the index to check
|
|
66
|
+
* @param tableName The table the index is on
|
|
67
|
+
* @returns The builder instance
|
|
68
|
+
*/
|
|
69
|
+
checkIndexExists(indexName: string, tableName: string): SqlBuilder;
|
|
70
|
+
/**
|
|
71
|
+
* Create an index if it doesn't exist
|
|
72
|
+
* @param indexName The name of the index to create
|
|
73
|
+
* @param tableName The table to create the index on
|
|
74
|
+
* @param columnName The column to index
|
|
75
|
+
* @param indexType Optional index type (e.g., 'UNIQUE')
|
|
76
|
+
* @returns The builder instance
|
|
77
|
+
*/
|
|
78
|
+
createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
|
|
79
|
+
/**
|
|
80
|
+
* Add a LIKE condition to the query
|
|
81
|
+
* @param column The column to check
|
|
82
|
+
* @param value The value to match (will be wrapped with % for LIKE)
|
|
83
|
+
* @param exact If true, will not add % wildcards
|
|
84
|
+
*/
|
|
85
|
+
like(column: string, value: string, exact?: boolean): SqlBuilder;
|
|
86
|
+
/**
|
|
87
|
+
* Add a JSON LIKE condition for searching in JSON fields
|
|
88
|
+
* @param column The JSON column to search in
|
|
89
|
+
* @param key The JSON key to match
|
|
90
|
+
* @param value The value to match
|
|
91
|
+
*/
|
|
92
|
+
jsonLike(column: string, key: string, value: string): SqlBuilder;
|
|
93
|
+
/**
|
|
94
|
+
* Get the built query
|
|
95
|
+
* @returns Object containing the SQL string and parameters array
|
|
96
|
+
*/
|
|
97
|
+
build(): {
|
|
98
|
+
sql: string;
|
|
99
|
+
params: SqlParam[];
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Reset the builder for reuse
|
|
103
|
+
* @returns The reset builder instance
|
|
104
|
+
*/
|
|
105
|
+
reset(): SqlBuilder;
|
|
106
|
+
}
|
|
107
|
+
export declare function createSqlBuilder(): SqlBuilder;
|
|
108
|
+
/** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
|
|
109
|
+
type SelectIdentifier = string & {
|
|
110
|
+
__brand: 'SelectIdentifier';
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Parses and returns a valid SQL SELECT column identifier.
|
|
114
|
+
* Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
|
|
115
|
+
*
|
|
116
|
+
* @param column - The column identifier string to parse.
|
|
117
|
+
* @returns The validated column identifier as a branded type.
|
|
118
|
+
* @throws {Error} If invalid.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const col = parseSelectIdentifier('user_id'); // Ok
|
|
122
|
+
* parseSelectIdentifier('user_id AS uid'); // Ok
|
|
123
|
+
* parseSelectIdentifier('*'); // Ok
|
|
124
|
+
* parseSelectIdentifier('user id'); // Throws error
|
|
125
|
+
*/
|
|
126
|
+
export declare function parseSelectIdentifier(column: string): SelectIdentifier;
|
|
127
|
+
export {};
|
|
128
|
+
//# sourceMappingURL=sql-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-builder.d.ts","sourceRoot":"","sources":["../../src/storage/sql-builder.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW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
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"}
|