@mastra/cloudflare-d1 1.4.1 → 1.4.2-alpha.0
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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +378 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +379 -73
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +4 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/run-fencing.d.ts +36 -0
- package/dist/storage/db/run-fencing.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +15 -5
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +12 -3
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/sql-builder.d.ts +7 -1
- package/dist/storage/sql-builder.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -3,6 +3,7 @@ import { MastraBase } from '@mastra/core/base';
|
|
|
3
3
|
import type { TABLE_NAMES, StorageColumn } from '@mastra/core/storage';
|
|
4
4
|
import Cloudflare from 'cloudflare';
|
|
5
5
|
import type { SqlQueryOptions } from '../sql-builder.js';
|
|
6
|
+
import type { RunFenceCheck } from './run-fencing.js';
|
|
6
7
|
export type D1QueryResult = Awaited<ReturnType<Cloudflare['d1']['database']['query']>>['result'];
|
|
7
8
|
export interface D1Client {
|
|
8
9
|
query(args: {
|
|
@@ -111,10 +112,12 @@ export declare class D1DB extends MastraBase {
|
|
|
111
112
|
* Upsert multiple records in a batch operation
|
|
112
113
|
* @param tableName The table to insert into
|
|
113
114
|
* @param records The records to insert
|
|
115
|
+
* @param check Run fence every upsert must hold; a refused upsert throws and stops the batch
|
|
114
116
|
*/
|
|
115
|
-
batchUpsert({ tableName, records }: {
|
|
117
|
+
batchUpsert({ tableName, records, check, }: {
|
|
116
118
|
tableName: TABLE_NAMES;
|
|
117
119
|
records: Record<string, any>[];
|
|
120
|
+
check?: RunFenceCheck;
|
|
118
121
|
}): Promise<void>;
|
|
119
122
|
}
|
|
120
123
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/storage/db/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAS/C,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,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;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED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EAAE,IAAI,EAAE,EAAE;QAAE,SAAS,EAAE,WAAW,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CA6C9G;IAEK,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAM7E;IAED;;;;;OAKG;IACG,WAAW,CAAC,EAChB,SAAS,EACT,OAAO,EACP,KAAK,GACN,EAAE;QACD,SAAS,EAAE,WAAW,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,KAAK,CAAC,EAAE,aAAa,CAAC;KACvB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgEhB;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RunFence } from '@mastra/core/storage';
|
|
2
|
+
import type { SqlCondition, SqlQueryOptions } from '../sql-builder.js';
|
|
3
|
+
import type { D1DB } from './index.js';
|
|
4
|
+
/** A write's fence, and the table holding the run's current claim to check it against. */
|
|
5
|
+
export interface RunFenceCheck {
|
|
6
|
+
claimsTable: string;
|
|
7
|
+
fence: RunFence;
|
|
8
|
+
operation: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Epoch milliseconds on the database clock. `julianday('now')` rather than
|
|
12
|
+
* `unixepoch('subsec')`, which needs SQLite 3.42.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DB_NOW_MS = "CAST(ROUND((julianday('now') - 2440587.5) * 86400000) AS INTEGER)";
|
|
15
|
+
/**
|
|
16
|
+
* The condition a fenced statement writes under: the check's fence is the
|
|
17
|
+
* run's current claim. D1 has no interactive transactions, so a fenced write
|
|
18
|
+
* can't check the claim first and write second; each of its statements
|
|
19
|
+
* carries this condition instead, and SQLite evaluates it atomically with the
|
|
20
|
+
* write.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runFenceGuard(check: RunFenceCheck | undefined): SqlCondition | undefined;
|
|
23
|
+
/** Throws `RunFenceConflictError` unless the check's fence is the run's current claim. */
|
|
24
|
+
export declare function assertRunFence(db: D1DB, { claimsTable, fence, operation }: RunFenceCheck): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Runs one statement of a fenced write. With a check, `statement` must carry
|
|
27
|
+
* `runFenceGuard(check)`. A guarded statement that changes no row either
|
|
28
|
+
* found no target or was refused by its guard; re-reading the claim tells
|
|
29
|
+
* which, and a refusal throws `RunFenceConflictError`.
|
|
30
|
+
*
|
|
31
|
+
* A write made of several statements stops at the first refused one, so a
|
|
32
|
+
* takeover that lands between them leaves the earlier statements applied.
|
|
33
|
+
* None of the refused writer's statements land after the takeover.
|
|
34
|
+
*/
|
|
35
|
+
export declare function executeFenced(db: D1DB, check: RunFenceCheck | undefined, { sql, params }: SqlQueryOptions): Promise<void>;
|
|
36
|
+
//# sourceMappingURL=run-fencing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-fencing.d.ts","sourceRoot":"","sources":["../../../src/storage/db/run-fencing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC,0FAA0F;AAC1F,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,sEAAsE,CAAC;AAE7F;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAOxF;AAED,0FAA0F;AAC1F,wBAAsB,cAAc,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAU9G;AAED;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,IAAI,EACR,KAAK,EAAE,aAAa,GAAG,SAAS,EAChC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,eAAe,GAC/B,OAAO,CAAC,IAAI,CAAC,CASf"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
2
2
|
import type { MastraDBMessage, StorageThreadType } from '@mastra/core/memory';
|
|
3
3
|
import { MemoryStorage } from '@mastra/core/storage';
|
|
4
|
-
import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput } from '@mastra/core/storage';
|
|
4
|
+
import type { RunFence, StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput } from '@mastra/core/storage';
|
|
5
5
|
import type { D1DomainConfig } from '../../db/index.js';
|
|
6
6
|
export declare class MemoryStorageD1 extends MemoryStorage {
|
|
7
7
|
#private;
|
|
@@ -9,35 +9,42 @@ export declare class MemoryStorageD1 extends MemoryStorage {
|
|
|
9
9
|
constructor(config: D1DomainConfig);
|
|
10
10
|
init(): Promise<void>;
|
|
11
11
|
dangerouslyClearAll(): Promise<void>;
|
|
12
|
+
supportsRunFencing(): boolean;
|
|
13
|
+
raiseRunFence(fence: RunFence): Promise<boolean>;
|
|
14
|
+
retireRunFence(fence: RunFence): Promise<boolean>;
|
|
12
15
|
getResourceById({ resourceId }: {
|
|
13
16
|
resourceId: string;
|
|
14
17
|
}): Promise<StorageResourceType | null>;
|
|
15
18
|
saveResource({ resource }: {
|
|
16
19
|
resource: StorageResourceType;
|
|
17
20
|
}): Promise<StorageResourceType>;
|
|
18
|
-
updateResource({ resourceId, workingMemory, metadata, }: {
|
|
21
|
+
updateResource({ resourceId, workingMemory, metadata, fence, }: {
|
|
19
22
|
resourceId: string;
|
|
20
23
|
workingMemory?: string;
|
|
21
24
|
metadata?: Record<string, unknown>;
|
|
25
|
+
fence?: RunFence;
|
|
22
26
|
}): Promise<StorageResourceType>;
|
|
23
27
|
getThreadById({ threadId, resourceId, }: {
|
|
24
28
|
threadId: string;
|
|
25
29
|
resourceId?: string;
|
|
26
30
|
}): Promise<StorageThreadType | null>;
|
|
27
31
|
listThreads(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
|
|
28
|
-
saveThread({ thread }: {
|
|
32
|
+
saveThread({ thread, fence }: {
|
|
29
33
|
thread: StorageThreadType;
|
|
34
|
+
fence?: RunFence;
|
|
30
35
|
}): Promise<StorageThreadType>;
|
|
31
|
-
updateThread({ id, title, metadata, }: {
|
|
36
|
+
updateThread({ id, title, metadata, fence, }: {
|
|
32
37
|
id: string;
|
|
33
38
|
title?: string;
|
|
34
39
|
metadata?: Record<string, unknown>;
|
|
40
|
+
fence?: RunFence;
|
|
35
41
|
}): Promise<StorageThreadType>;
|
|
36
42
|
deleteThread({ threadId }: {
|
|
37
43
|
threadId: string;
|
|
38
44
|
}): Promise<void>;
|
|
39
45
|
saveMessages(args: {
|
|
40
46
|
messages: MastraDBMessage[];
|
|
47
|
+
fence?: RunFence;
|
|
41
48
|
}): Promise<{
|
|
42
49
|
messages: MastraDBMessage[];
|
|
43
50
|
}>;
|
|
@@ -64,7 +71,10 @@ export declare class MemoryStorageD1 extends MemoryStorage {
|
|
|
64
71
|
content?: MastraMessageContentV2['content'];
|
|
65
72
|
};
|
|
66
73
|
}[];
|
|
74
|
+
fence?: RunFence;
|
|
67
75
|
}): Promise<MastraDBMessage[]>;
|
|
68
|
-
deleteMessages(messageIds: string[]
|
|
76
|
+
deleteMessages(messageIds: string[], options?: {
|
|
77
|
+
fence?: RunFence;
|
|
78
|
+
}): Promise<void>;
|
|
69
79
|
}
|
|
70
80
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAIL,aAAa,EAYd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,QAAQ,EACR,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EAGzB,uBAAuB,EACvB,wBAAwB,EAEzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAuD/C,qBAAa,eAAgB,SAAQ,aAAa;;IAChD,SAAkB,2BAA2B,QAAQ;IAGrD,YAAY,MAAM,EAAE,cAAc,EAGjC;IAEK,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAc1B;IAEK,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKzC;IAEQ,kBAAkB,IAAI,OAAO,CAErC;IAMc,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CA0B9D;IAEc,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB/D;IAQK,eAAe,CAAC,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EA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'@mastra/core/storage';
|
|
1
|
+
import type { ClaimRunOwnershipInput, ClaimRunOwnershipResult, RenewRunOwnershipInput, RenewRunOwnershipResult, RunFence, RunOwnershipRecord, WorkflowRun, WorkflowRuns, StorageListWorkflowRunsInput, UpdateWorkflowStateOptions } from '@mastra/core/storage';
|
|
2
2
|
import { WorkflowsStorage } from '@mastra/core/storage';
|
|
3
3
|
import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
|
|
4
4
|
import type { D1DomainConfig } from '../../db/index.js';
|
|
@@ -8,6 +8,13 @@ export declare class WorkflowsStorageD1 extends WorkflowsStorage {
|
|
|
8
8
|
supportsConcurrentUpdates(): boolean;
|
|
9
9
|
init(): Promise<void>;
|
|
10
10
|
dangerouslyClearAll(): Promise<void>;
|
|
11
|
+
supportsRunFencing(): boolean;
|
|
12
|
+
claimRunOwnership({ runId, ownerId, leaseMs, force, expectedGeneration, }: ClaimRunOwnershipInput): Promise<ClaimRunOwnershipResult>;
|
|
13
|
+
renewRunOwnership({ leaseMs, ...fence }: RenewRunOwnershipInput): Promise<RenewRunOwnershipResult>;
|
|
14
|
+
releaseRunOwnership(fence: RunFence): Promise<boolean>;
|
|
15
|
+
getRunOwnership({ runId }: {
|
|
16
|
+
runId: string;
|
|
17
|
+
}): Promise<RunOwnershipRecord | null>;
|
|
11
18
|
updateWorkflowResults(_args: {
|
|
12
19
|
workflowName: string;
|
|
13
20
|
runId: string;
|
|
@@ -20,13 +27,14 @@ export declare class WorkflowsStorageD1 extends WorkflowsStorage {
|
|
|
20
27
|
runId: string;
|
|
21
28
|
opts: UpdateWorkflowStateOptions;
|
|
22
29
|
}): Promise<WorkflowRunState | undefined>;
|
|
23
|
-
persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, }: {
|
|
30
|
+
persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, fence, }: {
|
|
24
31
|
workflowName: string;
|
|
25
32
|
runId: string;
|
|
26
33
|
resourceId?: string;
|
|
27
34
|
snapshot: WorkflowRunState;
|
|
28
35
|
createdAt?: Date;
|
|
29
36
|
updatedAt?: Date;
|
|
37
|
+
fence?: RunFence;
|
|
30
38
|
}): Promise<void>;
|
|
31
39
|
loadWorkflowSnapshot(params: {
|
|
32
40
|
workflowName: string;
|
|
@@ -38,9 +46,10 @@ export declare class WorkflowsStorageD1 extends WorkflowsStorage {
|
|
|
38
46
|
runId: string;
|
|
39
47
|
workflowName?: string;
|
|
40
48
|
}): Promise<WorkflowRun | null>;
|
|
41
|
-
deleteWorkflowRunById({ runId, workflowName }: {
|
|
49
|
+
deleteWorkflowRunById({ runId, workflowName, fence, }: {
|
|
42
50
|
runId: string;
|
|
43
51
|
workflowName: string;
|
|
52
|
+
fence?: RunFence;
|
|
44
53
|
}): Promise<void>;
|
|
45
54
|
}
|
|
46
55
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/workflows/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,4BAA4B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/workflows/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,QAAQ,EACR,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,4BAA4B,EAE5B,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EASL,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA0B/C,qBAAa,kBAAmB,SAAQ,gBAAgB;;IAGtD,YAAY,MAAM,EAAE,c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EAC5B,YAAY,EACZ,KAAK,EACL,UAAU,EACV,QAAQ,EACR,SAAS,EACT,SAAS,EACT,KAAK,GACN,EAAE;QACD,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,gBAAgB,CAAC;QAC3B,SAAS,CAAC,EAAE,IAAI,CAAC;QACjB,SAAS,CAAC,EAAE,IAAI,CAAC;QACjB,KAAK,CAAC,EAAE,QAAQ,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiEhB;IAEK,oBAAoB,CAAC,MAAM,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA2B5G;IAED,OAAO,CAAC,gBAAgB;IAqBlB,gBAAgB,CAAC,EACrB,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,OAAO,EACP,UAAU,EACV,MAAM,GACP,GAAE,4BAAiC,GAAG,OAAO,CAAC,YAAY,CAAC,CAoE3D;IAEK,kBAAkB,CAAC,EACvB,KAAK,EACL,YAAY,GACb,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CA8B9B;IAEK,qBAAqB,CAAC,EAC1B,KAAK,EACL,YAAY,EACZ,KAAK,GACN,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,QAAQ,CAAC;KAClB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBhB;CACF"}
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
* Type definition for SQL query parameters
|
|
3
3
|
*/
|
|
4
4
|
export type SqlParam = string | number | boolean | null | undefined;
|
|
5
|
+
/** A SQL boolean expression and the parameters it binds. */
|
|
6
|
+
export interface SqlCondition {
|
|
7
|
+
sql: string;
|
|
8
|
+
params: SqlParam[];
|
|
9
|
+
}
|
|
5
10
|
/**
|
|
6
11
|
* Interface for SQL query options with generic type support
|
|
7
12
|
*/
|
|
@@ -48,8 +53,9 @@ export declare class SqlBuilder {
|
|
|
48
53
|
* @param values Values to insert
|
|
49
54
|
* @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
|
|
50
55
|
* @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
|
|
56
|
+
* @param guard Condition the statement writes under: when it is false, neither the insert nor the conflict update happens
|
|
51
57
|
*/
|
|
52
|
-
insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string
|
|
58
|
+
insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>, guard?: SqlCondition): SqlBuilder;
|
|
53
59
|
update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
|
|
54
60
|
delete(table: string): SqlBuilder;
|
|
55
61
|
/**
|
|
@@ -1 +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,eAAe;IAC9B,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IACpB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,UAAU,CAAkB;IAGpC,MAAM,CAAC,OAAO,CAAC,E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": "1.4.2-alpha.0",
|
|
4
4
|
"description": "D1 provider for Mastra - includes db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"tsx": "^4.23.1",
|
|
37
37
|
"typescript": "^7.0.2",
|
|
38
38
|
"vitest": "4.1.11",
|
|
39
|
-
"@internal/lint": "0.0.
|
|
40
|
-
"@internal/storage-test-utils": "0.0.
|
|
41
|
-
"@internal/types-builder": "0.0.
|
|
42
|
-
"@mastra/core": "1.
|
|
39
|
+
"@internal/lint": "0.0.142",
|
|
40
|
+
"@internal/storage-test-utils": "0.0.138",
|
|
41
|
+
"@internal/types-builder": "0.0.117",
|
|
42
|
+
"@mastra/core": "1.77.0-alpha.4"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@mastra/core": ">=1.
|
|
45
|
+
"@mastra/core": ">=1.76.0-0 <2.0.0-0",
|
|
46
46
|
"@cloudflare/workers-types": "^4.20240919.0"
|
|
47
47
|
},
|
|
48
48
|
"homepage": "https://mastra.ai",
|