@mastra/dsql 1.4.0 → 1.5.0-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 +40 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +41 -2
- package/dist/index.js.map +1 -1
- package/dist/shared/config.d.ts +3 -1
- package/dist/shared/config.d.ts.map +1 -1
- package/dist/storage/db/index.d.ts +7 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +3 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -663,6 +663,16 @@ var DsqlDB = class extends _mastra_core_base.MastraBase {
|
|
|
663
663
|
}, error);
|
|
664
664
|
});
|
|
665
665
|
}
|
|
666
|
+
async pruneBatch({ tableName, column, cutoff, limit }) {
|
|
667
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(column)) throw new Error(`Invalid retention identifier: ${tableName}.${column}`);
|
|
668
|
+
const table = getTableName$1({
|
|
669
|
+
indexName: tableName,
|
|
670
|
+
schemaName: getSchemaName$1(this.schemaName)
|
|
671
|
+
});
|
|
672
|
+
return (await this.client.query(`DELETE FROM ${table} WHERE ("traceId", "spanId") IN (
|
|
673
|
+
SELECT "traceId", "spanId" FROM ${table} WHERE "${column}" < $1 ORDER BY "${column}" LIMIT $2
|
|
674
|
+
)`, [cutoff, limit])).rowCount ?? 0;
|
|
675
|
+
}
|
|
666
676
|
async clearTable({ tableName }) {
|
|
667
677
|
try {
|
|
668
678
|
await withRetry(async () => {
|
|
@@ -2774,6 +2784,11 @@ var MemoryDSQL = class MemoryDSQL extends _mastra_core_storage.MemoryStorage {
|
|
|
2774
2784
|
//#endregion
|
|
2775
2785
|
//#region src/storage/domains/observability/index.ts
|
|
2776
2786
|
var ObservabilityDSQL = class ObservabilityDSQL extends _mastra_core_storage.ObservabilityStorage {
|
|
2787
|
+
static retentionTables = { spans: {
|
|
2788
|
+
table: _mastra_core_storage.TABLE_SPANS,
|
|
2789
|
+
column: "startedAtZ",
|
|
2790
|
+
indexed: true
|
|
2791
|
+
} };
|
|
2777
2792
|
#db;
|
|
2778
2793
|
#schema;
|
|
2779
2794
|
#skipDefaultIndexes;
|
|
@@ -2792,6 +2807,24 @@ var ObservabilityDSQL = class ObservabilityDSQL extends _mastra_core_storage.Obs
|
|
|
2792
2807
|
this.#skipDefaultIndexes = skipDefaultIndexes;
|
|
2793
2808
|
this.#indexes = indexes?.filter((idx) => ObservabilityDSQL.MANAGED_TABLES.includes(idx.table));
|
|
2794
2809
|
}
|
|
2810
|
+
async prune(policies, options) {
|
|
2811
|
+
return (0, _mastra_core_storage.executeRetentionPrune)({
|
|
2812
|
+
domain: "observability",
|
|
2813
|
+
targets: (0, _mastra_core_storage.resolveRetentionTargets)({
|
|
2814
|
+
policies,
|
|
2815
|
+
descriptor: ObservabilityDSQL.retentionTables,
|
|
2816
|
+
order: ["spans"]
|
|
2817
|
+
}),
|
|
2818
|
+
options,
|
|
2819
|
+
cutoffFor: (target, now) => new Date((0, _mastra_core_storage.retentionCutoffMs)(target.policy, now)),
|
|
2820
|
+
deleteBatch: (target, cutoff, limit) => this.#db.pruneBatch({
|
|
2821
|
+
tableName: target.table,
|
|
2822
|
+
column: target.column,
|
|
2823
|
+
cutoff,
|
|
2824
|
+
limit
|
|
2825
|
+
})
|
|
2826
|
+
});
|
|
2827
|
+
}
|
|
2795
2828
|
async init() {
|
|
2796
2829
|
await this.#db.createTable({
|
|
2797
2830
|
tableName: _mastra_core_storage.TABLE_SPANS,
|
|
@@ -2806,6 +2839,11 @@ var ObservabilityDSQL = class ObservabilityDSQL extends _mastra_core_storage.Obs
|
|
|
2806
2839
|
getDefaultIndexDefinitions() {
|
|
2807
2840
|
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
2808
2841
|
return [
|
|
2842
|
+
{
|
|
2843
|
+
name: `${schemaPrefix}mastra_ai_spans_startedatz_idx`,
|
|
2844
|
+
table: _mastra_core_storage.TABLE_SPANS,
|
|
2845
|
+
columns: ["startedAtZ"]
|
|
2846
|
+
},
|
|
2809
2847
|
{
|
|
2810
2848
|
name: `${schemaPrefix}mastra_ai_spans_traceid_startedat_idx`,
|
|
2811
2849
|
table: _mastra_core_storage.TABLE_SPANS,
|
|
@@ -4054,7 +4092,8 @@ var DSQLStore = class extends _mastra_core_storage.MastraStorage {
|
|
|
4054
4092
|
super({
|
|
4055
4093
|
id: config.id,
|
|
4056
4094
|
name: "DSQLStore",
|
|
4057
|
-
disableInit: config.disableInit
|
|
4095
|
+
disableInit: config.disableInit,
|
|
4096
|
+
retention: config.retention
|
|
4058
4097
|
});
|
|
4059
4098
|
this.schema = config.schemaName || "public";
|
|
4060
4099
|
if (isPoolConfig(config)) {
|