@mastra/dsql 1.5.2 → 1.5.3-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/index.cjs +61 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +61 -2
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +2 -3
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +8 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +8 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -668,8 +668,9 @@ var DsqlDB = class extends MastraBase {
|
|
|
668
668
|
indexName: tableName,
|
|
669
669
|
schemaName: getSchemaName$1(this.schemaName)
|
|
670
670
|
});
|
|
671
|
-
|
|
672
|
-
|
|
671
|
+
const key = tableName === TABLE_SPANS ? "\"traceId\", \"spanId\"" : "\"runId\"";
|
|
672
|
+
return (await this.client.query(`DELETE FROM ${table} WHERE (${key}) IN (
|
|
673
|
+
SELECT ${key} FROM ${table} WHERE "${column}" < $1 ORDER BY "${column}" LIMIT $2
|
|
673
674
|
)`, [cutoff, limit])).rowCount ?? 0;
|
|
674
675
|
}
|
|
675
676
|
async clearTable({ tableName }) {
|
|
@@ -1896,6 +1897,17 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
1896
1897
|
TABLE_MESSAGES,
|
|
1897
1898
|
TABLE_RESOURCES
|
|
1898
1899
|
];
|
|
1900
|
+
/**
|
|
1901
|
+
* Tables `prune()` can clean up. Run fences anchor on `retiredAt` (epoch ms), which stays NULL until the
|
|
1902
|
+
* execution holding the fence settles, so a running execution's fence is
|
|
1903
|
+
* never pruned.
|
|
1904
|
+
*/
|
|
1905
|
+
static retentionTables = { runFences: {
|
|
1906
|
+
table: TABLE_MEMORY_RUN_FENCES,
|
|
1907
|
+
column: "retiredAt",
|
|
1908
|
+
indexed: false,
|
|
1909
|
+
anchorType: "epoch-ms"
|
|
1910
|
+
} };
|
|
1899
1911
|
constructor(config) {
|
|
1900
1912
|
super();
|
|
1901
1913
|
const { client, schemaName, skipDefaultIndexes, indexes } = resolveDsqlConfig(config);
|
|
@@ -1971,6 +1983,24 @@ var MemoryDSQL = class MemoryDSQL extends MemoryStorage {
|
|
|
1971
1983
|
this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
|
|
1972
1984
|
}
|
|
1973
1985
|
}
|
|
1986
|
+
async prune(policies, options) {
|
|
1987
|
+
return executeRetentionPrune({
|
|
1988
|
+
domain: "memory",
|
|
1989
|
+
targets: resolveRetentionTargets({
|
|
1990
|
+
policies,
|
|
1991
|
+
descriptor: MemoryDSQL.retentionTables,
|
|
1992
|
+
order: ["runFences"]
|
|
1993
|
+
}),
|
|
1994
|
+
options,
|
|
1995
|
+
cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
|
|
1996
|
+
deleteBatch: (target, cutoff, limit) => this.#db.pruneBatch({
|
|
1997
|
+
tableName: target.table,
|
|
1998
|
+
column: target.column,
|
|
1999
|
+
cutoff,
|
|
2000
|
+
limit
|
|
2001
|
+
})
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
1974
2004
|
async dangerouslyClearAll() {
|
|
1975
2005
|
await this.#db.clearTable({ tableName: TABLE_MESSAGES });
|
|
1976
2006
|
await this.#db.clearTable({ tableName: TABLE_THREADS });
|
|
@@ -3883,6 +3913,17 @@ var WorkflowsDSQL = class WorkflowsDSQL extends WorkflowsStorage {
|
|
|
3883
3913
|
#indexes;
|
|
3884
3914
|
/** Tables managed by this domain */
|
|
3885
3915
|
static MANAGED_TABLES = [TABLE_WORKFLOW_SNAPSHOT];
|
|
3916
|
+
/**
|
|
3917
|
+
* Tables `prune()` can clean up. Run ownership rows anchor on `updatedAt` (epoch ms), which every
|
|
3918
|
+
* claim, renewal and release refreshes, so a live execution's row is never
|
|
3919
|
+
* older than its renew interval.
|
|
3920
|
+
*/
|
|
3921
|
+
static retentionTables = { runOwnership: {
|
|
3922
|
+
table: TABLE_WORKFLOW_RUN_OWNERS,
|
|
3923
|
+
column: "updatedAt",
|
|
3924
|
+
indexed: false,
|
|
3925
|
+
anchorType: "epoch-ms"
|
|
3926
|
+
} };
|
|
3886
3927
|
constructor(config) {
|
|
3887
3928
|
super();
|
|
3888
3929
|
const { client, schemaName, skipDefaultIndexes, indexes } = resolveDsqlConfig(config);
|
|
@@ -3939,6 +3980,24 @@ var WorkflowsDSQL = class WorkflowsDSQL extends WorkflowsStorage {
|
|
|
3939
3980
|
this.logger?.warn?.(`Failed to create custom index ${indexDef.name}:`, error);
|
|
3940
3981
|
}
|
|
3941
3982
|
}
|
|
3983
|
+
async prune(policies, options) {
|
|
3984
|
+
return executeRetentionPrune({
|
|
3985
|
+
domain: "workflows",
|
|
3986
|
+
targets: resolveRetentionTargets({
|
|
3987
|
+
policies,
|
|
3988
|
+
descriptor: WorkflowsDSQL.retentionTables,
|
|
3989
|
+
order: ["runOwnership"]
|
|
3990
|
+
}),
|
|
3991
|
+
options,
|
|
3992
|
+
cutoffFor: (target, now) => retentionCutoffMs(target.policy, now),
|
|
3993
|
+
deleteBatch: (target, cutoff, limit) => this.#db.pruneBatch({
|
|
3994
|
+
tableName: target.table,
|
|
3995
|
+
column: target.column,
|
|
3996
|
+
cutoff,
|
|
3997
|
+
limit
|
|
3998
|
+
})
|
|
3999
|
+
});
|
|
4000
|
+
}
|
|
3942
4001
|
async dangerouslyClearAll() {
|
|
3943
4002
|
await this.#db.clearTable({ tableName: TABLE_WORKFLOW_SNAPSHOT });
|
|
3944
4003
|
await this.#db.clearTable({ tableName: TABLE_WORKFLOW_RUN_OWNERS });
|