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