@mastra/pg 1.14.3-alpha.0 → 1.15.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/CHANGELOG.md +37 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-memory-semantic-recall.md +8 -0
- package/dist/docs/references/docs-memory-storage.md +6 -0
- package/dist/docs/references/docs-memory-working-memory.md +2 -0
- package/dist/docs/references/docs-rag-overview.md +2 -0
- package/dist/docs/references/docs-rag-retrieval.md +2 -0
- package/dist/docs/references/docs-rag-vector-databases.md +2 -0
- package/dist/docs/references/reference-memory-memory-class.md +3 -0
- package/dist/docs/references/reference-processors-message-history-processor.md +3 -0
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +3 -0
- package/dist/docs/references/reference-processors-working-memory-processor.md +3 -0
- package/dist/docs/references/reference-rag-metadata-filters.md +2 -0
- package/dist/docs/references/reference-storage-composite.md +2 -0
- package/dist/docs/references/reference-storage-dynamodb.md +2 -0
- package/dist/docs/references/reference-storage-postgresql.md +2 -0
- package/dist/docs/references/reference-storage-retention.md +180 -0
- package/dist/docs/references/reference-tools-vector-query-tool.md +2 -0
- package/dist/docs/references/reference-vectors-pg.md +2 -0
- package/dist/index.cjs +749 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +750 -3
- package/dist/index.js.map +1 -1
- package/dist/shared/config.d.ts +8 -1
- package/dist/shared/config.d.ts.map +1 -1
- package/dist/storage/db/index.d.ts +51 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +19 -1
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
- package/dist/storage/domains/experiments/index.d.ts +31 -1
- package/dist/storage/domains/experiments/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts +39 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/notifications/index.d.ts +18 -1
- package/dist/storage/domains/notifications/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +22 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +17 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/retention.d.ts +64 -0
- package/dist/storage/domains/observability/v-next/retention.d.ts.map +1 -0
- package/dist/storage/domains/schedules/index.d.ts +23 -1
- package/dist/storage/domains/schedules/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +18 -1
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +19 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/retention.d.ts +76 -0
- package/dist/storage/retention.d.ts.map +1 -0
- package/package.json +5 -5
package/dist/shared/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConnectionOptions } from 'node:tls';
|
|
2
|
-
import type { CreateIndexOptions } from '@mastra/core/storage';
|
|
2
|
+
import type { CreateIndexOptions, RetentionConfig } from '@mastra/core/storage';
|
|
3
3
|
import type { ClientConfig, Pool, PoolConfig } from 'pg';
|
|
4
4
|
/**
|
|
5
5
|
* Base configuration options shared across PostgreSQL configs.
|
|
@@ -56,6 +56,13 @@ export interface PostgresBaseConfig {
|
|
|
56
56
|
* ```
|
|
57
57
|
*/
|
|
58
58
|
indexes?: CreateIndexOptions[];
|
|
59
|
+
/**
|
|
60
|
+
* Opt-in, table-granular, age-based retention policies. Declare per-table
|
|
61
|
+
* `maxAge` per domain (e.g. `{ memory: { messages: { maxAge: '30d' } } }`);
|
|
62
|
+
* unset tables are kept forever. Wire `storage.prune()` to your own cron to
|
|
63
|
+
* apply them. See {@link RetentionConfig}.
|
|
64
|
+
*/
|
|
65
|
+
retention?: RetentionConfig;
|
|
59
66
|
}
|
|
60
67
|
/**
|
|
61
68
|
* Connection string configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/shared/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/shared/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC/B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,kBAAkB;IAChE,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IAClC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,UAAW,SAAQ,kBAAkB;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CA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>;
|
|
248
|
+
/**
|
|
249
|
+
* Deletes up to `limit` rows from `tableName` whose `column` value is strictly
|
|
250
|
+
* older than `cutoff`, in a single bounded statement. Returns the number of
|
|
251
|
+
* rows deleted so the caller's batch loop can decide whether the table is
|
|
252
|
+
* drained.
|
|
253
|
+
*
|
|
254
|
+
* PostgreSQL has no `DELETE ... LIMIT`, so this targets a bounded set of
|
|
255
|
+
* physical rows via the `ctid` system column (PG's row identity, analogous to
|
|
256
|
+
* SQLite's `rowid`). `cutoff` is bound as a parameter — a `Date`/ISO-8601
|
|
257
|
+
* string compared against a `timestamptz` anchor column, or a `number`
|
|
258
|
+
* compared against a `bigint` epoch-ms anchor column.
|
|
259
|
+
*/
|
|
260
|
+
pruneBatch({ tableName, column, cutoff, limit, }: {
|
|
261
|
+
tableName: TABLE_NAMES;
|
|
262
|
+
column: string;
|
|
263
|
+
cutoff: Date | string | number;
|
|
264
|
+
limit: number;
|
|
265
|
+
}): Promise<number>;
|
|
266
|
+
/**
|
|
267
|
+
* Deletes up to `limit` aged parent rows *and* their child rows together, in
|
|
268
|
+
* a single transaction (used by whole-unit pruning such as experiments →
|
|
269
|
+
* experiment_results). The aged parent IDs are selected first and both
|
|
270
|
+
* deletes target that exact ID set, so a bound or abort between batches never
|
|
271
|
+
* leaves a parent hollow (kept, but with its children gone) or children
|
|
272
|
+
* orphaned.
|
|
273
|
+
*/
|
|
274
|
+
pruneUnitsBatch({ parentTable, parentKey, parentColumn, childTable, childForeignKey, cutoff, limit, }: {
|
|
275
|
+
parentTable: TABLE_NAMES;
|
|
276
|
+
parentKey: string;
|
|
277
|
+
parentColumn: string;
|
|
278
|
+
childTable: TABLE_NAMES;
|
|
279
|
+
childForeignKey: string;
|
|
280
|
+
cutoff: Date | string | number;
|
|
281
|
+
limit: number;
|
|
282
|
+
}): Promise<{
|
|
283
|
+
parents: number;
|
|
284
|
+
children: number;
|
|
285
|
+
}>;
|
|
286
|
+
/**
|
|
287
|
+
* Creates a btree index on `column` for `tableName` if it does not already
|
|
288
|
+
* exist, so age-based prune deletes stay fast. Delegates to {@link createIndex}
|
|
289
|
+
* (which is a no-op when the index is present).
|
|
290
|
+
*
|
|
291
|
+
* The name is lowercased and truncated to Postgres' 63-byte identifier limit
|
|
292
|
+
* (schema-prefixed names can exceed it), mirroring {@link buildConstraintName}.
|
|
293
|
+
*/
|
|
294
|
+
ensureIndex({ indexName, tableName, column, }: {
|
|
295
|
+
indexName: string;
|
|
296
|
+
tableName: TABLE_NAMES;
|
|
297
|
+
column: string;
|
|
298
|
+
}): Promise<void>;
|
|
248
299
|
private executeUpdate;
|
|
249
300
|
}
|
|
250
301
|
//# 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,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAU/C,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,iBAAiB,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,KAAK,EAAE,QAAQ,EAAyB,MAAM,WAAW,CAAC;AAKjE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,MAAM,EAAE,QAAQ,CAAC;IACjB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,wDAAwD;IACxD,OAAO,CAAC,EAAE,kBAAkB,EAAE,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,UAAU,EACV,eAAe,EACf,MAAM,EACN,KAAK,GACN,EAAE;QACD,WAAW,EAAE,WAAW,CAAC;QACzB,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,WAAW,CAAC;QACxB,eAAe,EAAE,MAAM,CAAC;QACxB,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;QAC/B,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IA0BlD;;;;;;;OAOG;IACG,WAAW,CAAC,EAChB,SAAS,EACT,SAAS,EACT,MAAM,GACP,EAAE;QACD,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,WAAW,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,IAAI,CAAC;YAKH,aAAa;CA6C5B"}
|
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import type { BackgroundTask, TaskFilter, TaskListResult, UpdateBackgroundTask } from '@mastra/core/background-tasks';
|
|
2
|
-
import type { CreateIndexOptions } from '@mastra/core/storage';
|
|
2
|
+
import type { CreateIndexOptions, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
|
|
3
3
|
import { BackgroundTasksStorage } from '@mastra/core/storage';
|
|
4
4
|
import type { PgDomainConfig } from '../../db/index.js';
|
|
5
5
|
export declare class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
6
6
|
#private;
|
|
7
7
|
static readonly MANAGED_TABLES: readonly ["mastra_background_tasks"];
|
|
8
|
+
/**
|
|
9
|
+
* Completed background tasks accumulate as dead weight. Anchored on the
|
|
10
|
+
* timezone-aware `completedAtZ` mirror column: NULL (in-flight) rows are
|
|
11
|
+
* excluded automatically since `completedAtZ < cutoff` is false for NULL.
|
|
12
|
+
*/
|
|
13
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
8
14
|
constructor(config: PgDomainConfig);
|
|
9
15
|
init(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Lazily ensures a btree index exists on each configured policy's retention
|
|
18
|
+
* anchor column so age-based `prune()` deletes stay fast on large tables.
|
|
19
|
+
* Called from the prune path (not init) so only deployments that configure
|
|
20
|
+
* retention pay the index's write/disk overhead. Best-effort: failures are
|
|
21
|
+
* logged and pruning proceeds (correct, just slower).
|
|
22
|
+
* Created even with `skipDefaultIndexes` — retention is an explicit opt-in,
|
|
23
|
+
* so its supporting index is not part of the default index set.
|
|
24
|
+
*/
|
|
25
|
+
private ensureRetentionIndexes;
|
|
26
|
+
/** Delete completed tasks older than the `backgroundTasks` policy's `maxAge`, batched. */
|
|
27
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
10
28
|
static getDefaultIndexDefs(schemaPrefix: string): CreateIndexOptions[];
|
|
11
29
|
static getExportDDL(schemaName?: string): string[];
|
|
12
30
|
getDefaultIndexDefinitions(): CreateIndexOptions[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/background-tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/background-tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,kBAAkB,EAElB,YAAY,EACZ,WAAW,EACX,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAA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AAC,IAAI,CAAC;IAuC9C,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAQlC,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQ/D"}
|
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
import { ExperimentsStorage } from '@mastra/core/storage';
|
|
2
|
-
import type { Experiment, ExperimentResult, ExperimentReviewCounts, CreateExperimentInput, UpdateExperimentInput, AddExperimentResultInput, UpdateExperimentResultInput, ListExperimentsInput, ListExperimentsOutput, ListExperimentResultsInput, ListExperimentResultsOutput, CreateIndexOptions } from '@mastra/core/storage';
|
|
2
|
+
import type { Experiment, ExperimentResult, ExperimentReviewCounts, CreateExperimentInput, UpdateExperimentInput, AddExperimentResultInput, UpdateExperimentResultInput, ListExperimentsInput, ListExperimentsOutput, ListExperimentResultsInput, ListExperimentResultsOutput, CreateIndexOptions, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
|
|
3
3
|
import type { PgDomainConfig } from '../../db/index.js';
|
|
4
4
|
export declare class ExperimentsPG extends ExperimentsStorage {
|
|
5
5
|
#private;
|
|
6
6
|
static readonly MANAGED_TABLES: readonly ["mastra_experiments", "mastra_experiment_results"];
|
|
7
|
+
/**
|
|
8
|
+
* Experiments prune as whole units: an aged experiment and its result rows go
|
|
9
|
+
* together, mirroring `deleteExperiment`. Anchored on `completedAt` (not the
|
|
10
|
+
* `completedAtZ` mirror, which carries a `DEFAULT NOW()` this domain never
|
|
11
|
+
* overrides — it holds insert time even for running rows). `completedAt` is
|
|
12
|
+
* written as a UTC ISO string and stays NULL while running, so
|
|
13
|
+
* `completedAt < cutoff` is false for in-flight experiments.
|
|
14
|
+
*/
|
|
15
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
7
16
|
constructor(config: PgDomainConfig);
|
|
8
17
|
static getExportDDL(schemaName?: string): string[];
|
|
9
18
|
init(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Lazily ensures a btree index exists on each configured policy's retention
|
|
21
|
+
* anchor column so age-based `prune()` deletes stay fast on large tables.
|
|
22
|
+
* Called from the prune path (not init) so only deployments that configure
|
|
23
|
+
* retention pay the index's write/disk overhead. Best-effort: failures are
|
|
24
|
+
* logged and pruning proceeds (correct, just slower).
|
|
25
|
+
* Created even with `skipDefaultIndexes` — retention is an explicit opt-in,
|
|
26
|
+
* so its supporting index is not part of the default index set.
|
|
27
|
+
*/
|
|
28
|
+
private ensureRetentionIndexes;
|
|
29
|
+
/**
|
|
30
|
+
* Delete experiments whose `completedAt` is older than the policy's `maxAge`.
|
|
31
|
+
*
|
|
32
|
+
* Each batch selects up to `batchSize` aged experiments and deletes their
|
|
33
|
+
* `experiment_results` rows and the experiment rows in one transaction —
|
|
34
|
+
* mirroring `deleteExperiment` — so hitting `maxBatches`/`maxRows` or the
|
|
35
|
+
* abort signal between batches never leaves a run hollow (parent kept,
|
|
36
|
+
* results gone). NULL `completedAt` (still running) is excluded by the
|
|
37
|
+
* `< cutoff` predicate. Bounds count whole experiments, not rows.
|
|
38
|
+
*/
|
|
39
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
10
40
|
getDefaultIndexDefinitions(): CreateIndexOptions[];
|
|
11
41
|
createDefaultIndexes(): Promise<void>;
|
|
12
42
|
createCustomIndexes(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/experiments/index.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,kBAAkB,EAKnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,kBAAkB,
|
|
1
|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BAAqB,GAAG,OAAO,CAAC,UAAU,CAAC;IAiFnE,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAiBrE,eAAe,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAqF3E,gBAAgB,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBvD,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA8D/E,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAgErF,uBAAuB,CAAC,EAAE,EAAE,EAAE,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAiBjF,qBAAqB,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAuE7F,uBAAuB,CAAC,EAAE,YAAY,EAAE,EAAE;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBlF,gBAAgB,IAAI,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAmCrD,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;CAI3C"}
|
|
@@ -11,15 +11,33 @@ import { MemoryStorage } from '@mastra/core/storage';
|
|
|
11
11
|
* will fail otherwise.
|
|
12
12
|
*/
|
|
13
13
|
export declare const OM_MIGRATION_COLUMNS: string[];
|
|
14
|
-
import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesByResourceIdInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput, CreateIndexOptions, StorageCloneThreadInput, StorageCloneThreadOutput, ObservationalMemoryRecord, ObservationalMemoryHistoryOptions, CreateObservationalMemoryInput, UpdateActiveObservationsInput, UpdateBufferedObservationsInput, SwapBufferedToActiveInput, SwapBufferedToActiveResult, UpdateBufferedReflectionInput, SwapBufferedReflectionToActiveInput, CreateReflectionGenerationInput, UpdateObservationalMemoryConfigInput } from '@mastra/core/storage';
|
|
14
|
+
import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesByResourceIdInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput, CreateIndexOptions, StorageCloneThreadInput, StorageCloneThreadOutput, ObservationalMemoryRecord, ObservationalMemoryHistoryOptions, CreateObservationalMemoryInput, UpdateActiveObservationsInput, UpdateBufferedObservationsInput, SwapBufferedToActiveInput, SwapBufferedToActiveResult, UpdateBufferedReflectionInput, SwapBufferedReflectionToActiveInput, CreateReflectionGenerationInput, UpdateObservationalMemoryConfigInput, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
|
|
15
15
|
import type { PgDomainConfig } from '../../db/index.js';
|
|
16
16
|
export declare class MemoryPG extends MemoryStorage {
|
|
17
17
|
#private;
|
|
18
18
|
readonly supportsObservationalMemory = true;
|
|
19
|
+
/**
|
|
20
|
+
* Retention-eligible tables. `threads`, `messages`, and `resources` all anchor
|
|
21
|
+
* on the timezone-aware `createdAtZ` mirror column (kept in sync by triggers),
|
|
22
|
+
* and are indexed for fast batched deletes. Cascade order is enforced in
|
|
23
|
+
* `prune()` (children before threads), not here. Observational memory has no
|
|
24
|
+
* timestamp anchor and is deliberately excluded.
|
|
25
|
+
*/
|
|
26
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
19
27
|
/** Tables managed by this domain */
|
|
20
28
|
static readonly MANAGED_TABLES: readonly ["mastra_threads", "mastra_messages", "mastra_resources", "mastra_observational_memory"];
|
|
21
29
|
constructor(config: PgDomainConfig);
|
|
22
30
|
init(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Lazily ensures a btree index exists on each configured policy's retention
|
|
33
|
+
* anchor column so age-based `prune()` deletes stay fast on large tables.
|
|
34
|
+
* Called from the prune path (not init) so only deployments that configure
|
|
35
|
+
* retention pay the index's write/disk overhead. Best-effort: failures are
|
|
36
|
+
* logged and pruning proceeds (correct, just slower).
|
|
37
|
+
* Created even with `skipDefaultIndexes` — retention is an explicit opt-in,
|
|
38
|
+
* so its supporting index is not part of the default index set.
|
|
39
|
+
*/
|
|
40
|
+
private ensureRetentionIndexes;
|
|
23
41
|
/**
|
|
24
42
|
* Returns default index definitions for the memory domain tables.
|
|
25
43
|
* @param schemaPrefix - Prefix for index names (e.g. "my_schema_" or "")
|
|
@@ -43,6 +61,26 @@ export declare class MemoryPG extends MemoryStorage {
|
|
|
43
61
|
*/
|
|
44
62
|
createCustomIndexes(): Promise<void>;
|
|
45
63
|
dangerouslyClearAll(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Deletes rows older than the configured `maxAge` per table, in bounded,
|
|
66
|
+
* batched, cancellable chunks. Tables are pruned children-first (messages and
|
|
67
|
+
* resources before threads) since PostgreSQL has no FK cascade in this schema.
|
|
68
|
+
* Unset tables are kept forever.
|
|
69
|
+
*
|
|
70
|
+
* When a `messages` policy is set, semantic-recall embeddings for pruned
|
|
71
|
+
* messages are also swept from same-schema `memory_messages*` vector tables
|
|
72
|
+
* (best-effort, mirroring `deleteThread`). Embeddings held in an external
|
|
73
|
+
* vector store are out of reach and must be pruned by the operator.
|
|
74
|
+
*/
|
|
75
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Best-effort sweep of semantic-recall vector rows whose source message no
|
|
78
|
+
* longer exists (e.g. it was just pruned), so recall doesn't keep returning
|
|
79
|
+
* embeddings that resolve to nothing. Only same-schema default vector tables
|
|
80
|
+
* (`memory_messages*`) are covered — the same set `deleteThread` cleans up.
|
|
81
|
+
* Failures are logged, never thrown: vector cleanup must not fail the prune.
|
|
82
|
+
*/
|
|
83
|
+
private pruneOrphanedVectorRows;
|
|
46
84
|
/**
|
|
47
85
|
* Normalizes message row from database by applying createdAtZ fallback
|
|
48
86
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EACL,aAAa,EAQd,MAAM,sBAAsB,CAAC;AAa9B;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAgBxC,CAAC;AAeF,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,oCAAoC,EACpC,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EAExB,yBAAyB,EACzB,iCAAiC,EAEjC,8BAA8B,EAC9B,6BAA6B,EAC7B,+BAA+B,EAC/B,yBAAyB,EACzB,0BAA0B,EAC1B,6BAA6B,EAC7B,mCAAmC,EACnC,+BAA+B,EAC/B,oCAAoC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/memory/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EACL,aAAa,EAQd,MAAM,sBAAsB,CAAC;AAa9B;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,MAAM,EAgBxC,CAAC;AAeF,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,oCAAoC,EACpC,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,E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BAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAuN3F,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,GAAG,OAAO,CAAC,IAAI,CAAC;IA0D7E,8BAA8B,CAAC,KAAK,EAAE,mCAAmC,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAqFrH"}
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { NotificationsStorage } from '@mastra/core/storage';
|
|
2
|
-
import type { CreateIndexOptions, CreateNotificationInput, ListDueNotificationsInput, ListNotificationsInput, NotificationRecord, UpdateNotificationInput } from '@mastra/core/storage';
|
|
2
|
+
import type { CreateIndexOptions, CreateNotificationInput, ListDueNotificationsInput, ListNotificationsInput, NotificationRecord, UpdateNotificationInput, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
|
|
3
3
|
import type { PgDomainConfig } from '../../db/index.js';
|
|
4
4
|
export declare class NotificationsPG extends NotificationsStorage {
|
|
5
5
|
#private;
|
|
6
6
|
static readonly MANAGED_TABLES: readonly ["mastra_notifications"];
|
|
7
|
+
/**
|
|
8
|
+
* Notifications are an append-only event feed that grows unbounded. Single
|
|
9
|
+
* table, anchored on the timezone-aware `createdAtZ` mirror column.
|
|
10
|
+
*/
|
|
11
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
7
12
|
constructor(config: PgDomainConfig);
|
|
8
13
|
init(): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Lazily ensures a btree index exists on each configured policy's retention
|
|
16
|
+
* anchor column so age-based `prune()` deletes stay fast on large tables.
|
|
17
|
+
* Called from the prune path (not init) so only deployments that configure
|
|
18
|
+
* retention pay the index's write/disk overhead. Best-effort: failures are
|
|
19
|
+
* logged and pruning proceeds (correct, just slower).
|
|
20
|
+
* Created even with `skipDefaultIndexes` — retention is an explicit opt-in,
|
|
21
|
+
* so its supporting index is not part of the default index set.
|
|
22
|
+
*/
|
|
23
|
+
private ensureRetentionIndexes;
|
|
24
|
+
/** Delete notifications older than the `notifications` policy's `maxAge`, batched. */
|
|
25
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
9
26
|
static getDefaultIndexDefs(schemaPrefix: string): CreateIndexOptions[];
|
|
10
27
|
static getExportDDL(schemaName?: string): string[];
|
|
11
28
|
getDefaultIndexDefinitions(): CreateIndexOptions[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/notifications/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAsC,MAAM,sBAAsB,CAAC;AAChG,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EAEtB,kBAAkB,EAGlB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/notifications/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAsC,MAAM,sBAAsB,CAAC;AAChG,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,EAEtB,kBAAkB,EAGlB,uBAAuB,EAEvB,YAAY,EACZ,WAAW,EACX,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAI9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AA2F/C,qBAAa,eAAgB,SAAQ,oBAAoB;;IAMvD,MAAM,CAAC,QAAQ,CAAC,cAAc,oCAAkC;IAEhE;;;OAGG;IACH,gBAAyB,eAAe,EAAE,yBAAyB,CAEjE;gBAEU,MAAM,EAAE,cAAc;IAS5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAS3B;;;;;;;;OAQG;YACW,sBAAsB;IAgBpC,sFAAsF;IAChF,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAU3G,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,kBAAkB,EAAE;IAoBtE,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAqBlD,0BAA0B,IAAI,kBAAkB,EAAE;IAK5C,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAWrC,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAWpC,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;YAI5B,qBAAqB;IAmB7B,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAyD/E,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAsC/E,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA6BrF,eAAe,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAU5F,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,kBAAkB,CAAC;YA6BvE,eAAe;CAqB9B"}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import { ObservabilityStorage } from '@mastra/core/storage';
|
|
2
|
-
import type { TracingStorageStrategy, ListTracesArgs, ListTracesResponse, UpdateSpanArgs, BatchDeleteTracesArgs, BatchUpdateSpansArgs, BatchCreateSpansArgs, CreateSpanArgs, GetSpanArgs, GetSpanResponse, GetRootSpanArgs, GetRootSpanResponse, GetTraceArgs, GetTraceResponse, GetTraceLightResponse, CreateIndexOptions } from '@mastra/core/storage';
|
|
2
|
+
import type { TracingStorageStrategy, ListTracesArgs, ListTracesResponse, UpdateSpanArgs, BatchDeleteTracesArgs, BatchUpdateSpansArgs, BatchCreateSpansArgs, CreateSpanArgs, GetSpanArgs, GetSpanResponse, GetRootSpanArgs, GetRootSpanResponse, GetTraceArgs, GetTraceResponse, GetTraceLightResponse, CreateIndexOptions, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
|
|
3
3
|
import type { PgDomainConfig } from '../../db/index.js';
|
|
4
4
|
export declare class ObservabilityPG extends ObservabilityStorage {
|
|
5
5
|
#private;
|
|
6
|
+
/**
|
|
7
|
+
* Retention-eligible tables. The observability domain has a single physical
|
|
8
|
+
* table (`mastra_ai_spans`); spans anchor on the timezone-aware `startedAtZ`
|
|
9
|
+
* mirror column and are indexed for fast batched deletes.
|
|
10
|
+
*/
|
|
11
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
6
12
|
/** Tables managed by this domain */
|
|
7
13
|
static readonly MANAGED_TABLES: readonly ["mastra_ai_spans"];
|
|
8
14
|
constructor(config: PgDomainConfig);
|
|
9
15
|
init(): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Lazily ensures a btree index exists on each configured policy's retention
|
|
18
|
+
* anchor column so age-based `prune()` deletes stay fast on large span tables.
|
|
19
|
+
* Called from the prune path (not init) so only deployments that configure
|
|
20
|
+
* retention pay the index's write/disk overhead. Best-effort: failures are
|
|
21
|
+
* logged and pruning proceeds (correct, just slower).
|
|
22
|
+
* Created even with `skipDefaultIndexes` — retention is an explicit opt-in,
|
|
23
|
+
* so its supporting index is not part of the default index set.
|
|
24
|
+
*/
|
|
25
|
+
private ensureRetentionIndexes;
|
|
10
26
|
/**
|
|
11
27
|
* Returns default index definitions for the observability domain tables.
|
|
12
28
|
* @param schemaPrefix - Prefix for index names (e.g. "my_schema_" or "")
|
|
@@ -53,6 +69,11 @@ export declare class ObservabilityPG extends ObservabilityStorage {
|
|
|
53
69
|
tableName: string;
|
|
54
70
|
}>;
|
|
55
71
|
dangerouslyClearAll(): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Deletes spans older than the configured `maxAge`, in bounded, batched,
|
|
74
|
+
* cancellable chunks. Unset = keep forever.
|
|
75
|
+
*/
|
|
76
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
56
77
|
get tracingStrategy(): {
|
|
57
78
|
preferred: TracingStorageStrategy;
|
|
58
79
|
supported: TracingStorageStrategy[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/observability/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,oBAAoB,EAKrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAEV,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EAErB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/observability/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,oBAAoB,EAKrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAEV,sBAAsB,EACtB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,WAAW,EACX,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EAErB,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,yBAAyB,EACzB,oBAAoB,EAErB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI/C,qBAAa,eAAgB,SAA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S,EAAE,sBAAsB,EAAE,CAAC;KACrC,CAKA;IAEK,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAiC/C,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IA+C3D,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IA+CvE,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAqD9D,aAAa,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAiDxE,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC/C,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA0O7D,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+B3D,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC3D,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CAoBpE"}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* Use it through `MastraCompositeStore` with a dedicated Postgres connection.
|
|
23
23
|
*/
|
|
24
24
|
import { ObservabilityStorage } from '@mastra/core/storage';
|
|
25
|
-
import type { BatchCreateFeedbackArgs, BatchCreateLogsArgs, BatchCreateMetricsArgs, BatchCreateScoresArgs, BatchCreateSpansArgs, BatchDeleteTracesArgs, CreateFeedbackArgs, CreateScoreArgs, CreateSpanArgs, GetEntityNamesArgs, GetEntityNamesResponse, GetEntityTypesArgs, GetEntityTypesResponse, GetEnvironmentsArgs, GetEnvironmentsResponse, GetFeedbackAggregateArgs, GetFeedbackAggregateResponse, GetFeedbackBreakdownArgs, GetFeedbackBreakdownResponse, GetFeedbackPercentilesArgs, GetFeedbackPercentilesResponse, GetFeedbackTimeSeriesArgs, GetFeedbackTimeSeriesResponse, GetMetricAggregateArgs, GetMetricAggregateResponse, GetMetricBreakdownArgs, GetMetricBreakdownResponse, GetMetricLabelKeysArgs, GetMetricLabelKeysResponse, GetMetricLabelValuesArgs, GetMetricLabelValuesResponse, GetMetricNamesArgs, GetMetricNamesResponse, GetMetricPercentilesArgs, GetMetricPercentilesResponse, GetMetricTimeSeriesArgs, GetMetricTimeSeriesResponse, GetRootSpanArgs, GetRootSpanResponse, GetSpansArgs, GetSpansResponse, GetScoreAggregateArgs, GetScoreAggregateResponse, GetScoreBreakdownArgs, GetScoreBreakdownResponse, GetScorePercentilesArgs, GetScorePercentilesResponse, GetScoreTimeSeriesArgs, GetScoreTimeSeriesResponse, GetServiceNamesArgs, GetServiceNamesResponse, GetSpanArgs, GetSpanResponse, GetTagsArgs, GetTagsResponse, GetTraceArgs, GetTraceLightResponse, GetTraceResponse, ListBranchesArgs, ListBranchesResponse, ListFeedbackArgs, ListFeedbackResponse, ListLogsArgs, ListLogsResponse, ListMetricsArgs, ListMetricsResponse, ListScoresArgs, ListScoresResponse, ListTracesArgs, ListTracesResponse, ObservabilityStorageStrategy, ScoreRecord } from '@mastra/core/storage';
|
|
25
|
+
import type { BatchCreateFeedbackArgs, BatchCreateLogsArgs, BatchCreateMetricsArgs, BatchCreateScoresArgs, BatchCreateSpansArgs, BatchDeleteTracesArgs, CreateFeedbackArgs, CreateScoreArgs, CreateSpanArgs, GetEntityNamesArgs, GetEntityNamesResponse, GetEntityTypesArgs, GetEntityTypesResponse, GetEnvironmentsArgs, GetEnvironmentsResponse, GetFeedbackAggregateArgs, GetFeedbackAggregateResponse, GetFeedbackBreakdownArgs, GetFeedbackBreakdownResponse, GetFeedbackPercentilesArgs, GetFeedbackPercentilesResponse, GetFeedbackTimeSeriesArgs, GetFeedbackTimeSeriesResponse, GetMetricAggregateArgs, GetMetricAggregateResponse, GetMetricBreakdownArgs, GetMetricBreakdownResponse, GetMetricLabelKeysArgs, GetMetricLabelKeysResponse, GetMetricLabelValuesArgs, GetMetricLabelValuesResponse, GetMetricNamesArgs, GetMetricNamesResponse, GetMetricPercentilesArgs, GetMetricPercentilesResponse, GetMetricTimeSeriesArgs, GetMetricTimeSeriesResponse, GetRootSpanArgs, GetRootSpanResponse, GetSpansArgs, GetSpansResponse, GetScoreAggregateArgs, GetScoreAggregateResponse, GetScoreBreakdownArgs, GetScoreBreakdownResponse, GetScorePercentilesArgs, GetScorePercentilesResponse, GetScoreTimeSeriesArgs, GetScoreTimeSeriesResponse, GetServiceNamesArgs, GetServiceNamesResponse, GetSpanArgs, GetSpanResponse, GetTagsArgs, GetTagsResponse, GetTraceArgs, GetTraceLightResponse, GetTraceResponse, ListBranchesArgs, ListBranchesResponse, ListFeedbackArgs, ListFeedbackResponse, ListLogsArgs, ListLogsResponse, ListMetricsArgs, ListMetricsResponse, ListScoresArgs, ListScoresResponse, ListTracesArgs, ListTracesResponse, ObservabilityStorageStrategy, PruneOptions, PruneResult, RetentionTablesDescriptor, ScoreRecord, TableRetentionPolicy } from '@mastra/core/storage';
|
|
26
26
|
import type { PgDomainConfig } from '../../../db/index.js';
|
|
27
27
|
import type { DiscoveryConfig } from './discovery.js';
|
|
28
28
|
import type { PartitioningOptions, PartitionMode } from './partitioning.js';
|
|
@@ -53,6 +53,22 @@ export declare class ObservabilityStoragePostgresVNext extends ObservabilityStor
|
|
|
53
53
|
init(): Promise<void>;
|
|
54
54
|
/** Resolved partition mode after init(). Useful for tests and diagnostics. */
|
|
55
55
|
get partitionMode(): PartitionMode | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* All five signal tables are insert-only growth tables. The anchor column is
|
|
58
|
+
* each table's partition / chunk key, so age-based expiry drops whole day
|
|
59
|
+
* partitions instead of deleting rows (see `./retention.ts`). `indexed: true`
|
|
60
|
+
* reflects that expiry never scans — it acts on partition bounds.
|
|
61
|
+
*/
|
|
62
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
63
|
+
/**
|
|
64
|
+
* Expire signal events older than each table's `maxAge` by dropping whole
|
|
65
|
+
* day partitions (native / pg_partman) or chunks (Timescale). Only
|
|
66
|
+
* partitions wholly older than the cutoff are dropped, so the effective
|
|
67
|
+
* granularity is one day. Each partition drop counts as one batch for
|
|
68
|
+
* `maxBatches` / `maxRows` / abort-signal purposes; `deleted` reports the
|
|
69
|
+
* row count of the dropped partitions.
|
|
70
|
+
*/
|
|
71
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
56
72
|
get observabilityStrategy(): {
|
|
57
73
|
preferred: ObservabilityStorageStrategy;
|
|
58
74
|
supported: ObservabilityStorageStrategy[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/storage/domains/observability/v-next/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAwB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EACV,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,EAC5B,wBAAwB,EACxB,4BAA4B,EAC5B,0BAA0B,EAC1B,8BAA8B,EAC9B,yBAAyB,EACzB,6BAA6B,EAC7B,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,2BAA2B,EAC3B,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,EACvB,WAAW,EACX,eAAe,EACf,WAAW,EACX,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,4BAA4B,EAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/storage/domains/observability/v-next/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAAwB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EACV,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,4BAA4B,EAC5B,wBAAwB,EACxB,4BAA4B,EAC5B,0BAA0B,EAC1B,8BAA8B,EAC9B,yBAAyB,EACzB,6BAA6B,EAC7B,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,EAC5B,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,2BAA2B,E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AAC;IAM3F,oBAAoB,CAAC,IAAI,EAAE,wBAAwB,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAM3F,qBAAqB,CAAC,IAAI,EAAE,yBAAyB,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAM9F,sBAAsB,CAAC,IAAI,EAAE,0BAA0B,GAAG,OAAO,CAAC,8BAA8B,CAAC;IAUjG,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAMzE,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAMzE,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAM5E,eAAe,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAM5E,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC;IAIpD,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAMzE,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAMrF,oBAAoB,CAAC,IAAI,EAAE,wBAAwB,GAAG,OAAO,CAAC,4BAA4B,CAAC;IAU3F,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7D,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;CAoBpD"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Age-based retention for the v-next Postgres observability domain.
|
|
3
|
+
*
|
|
4
|
+
* The signal tables are insert-only and day-partitioned (native declarative
|
|
5
|
+
* partitions, pg_partman-managed partitions, or Timescale chunks), so
|
|
6
|
+
* retention here is NOT the row-level batched `DELETE` used by the other
|
|
7
|
+
* domains — it expires data the way the partition skeleton was designed for:
|
|
8
|
+
*
|
|
9
|
+
* - native / partman: `DETACH PARTITION` + `DROP TABLE` for every child
|
|
10
|
+
* partition whose upper bound is at or before the cutoff. Detach-then-drop
|
|
11
|
+
* keeps the parent lock window short, and dropping a whole day of events
|
|
12
|
+
* is O(1) — no dead tuples, no WAL churn, no vacuum debt.
|
|
13
|
+
* - timescale: `drop_chunks(older_than => cutoff)`, the Timescale-native
|
|
14
|
+
* equivalent (only chunks wholly older than the cutoff are dropped).
|
|
15
|
+
*
|
|
16
|
+
* Because only *whole* partitions/chunks are dropped, the effective
|
|
17
|
+
* granularity is one day: rows stay until the full day they belong to has
|
|
18
|
+
* aged past `maxAge`. Empty future partitions (pre-created for routing) have
|
|
19
|
+
* upper bounds in the future and are never touched.
|
|
20
|
+
*
|
|
21
|
+
* `PruneOptions` map onto partition drops: each dropped partition counts as
|
|
22
|
+
* one batch (`maxBatches` caps partitions dropped per table per call),
|
|
23
|
+
* `maxRows` stops before a drop that would exceed the row budget, and the
|
|
24
|
+
* abort signal is checked between drops. `deleted` reports the number of
|
|
25
|
+
* rows in the dropped partitions/chunks.
|
|
26
|
+
*/
|
|
27
|
+
import type { PruneOptions, TableRetentionPolicy } from '@mastra/core/storage';
|
|
28
|
+
import type { DbClient } from '../../../client.js';
|
|
29
|
+
export interface PartitionPruneOutcome {
|
|
30
|
+
deleted: number;
|
|
31
|
+
done: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Convert a policy's `maxAge` into a cutoff `Date`. */
|
|
34
|
+
export declare function retentionCutoff(policy: TableRetentionPolicy, now?: number): Date;
|
|
35
|
+
/**
|
|
36
|
+
* Drops every child partition of `table` whose upper bound is at or before
|
|
37
|
+
* `cutoff` (i.e. every row in it is provably older than the cutoff).
|
|
38
|
+
* Detaches first so the parent's ACCESS EXCLUSIVE window is a fast catalog
|
|
39
|
+
* change, then drops the detached table. Used for both native and
|
|
40
|
+
* pg_partman-managed partitions (partman children are ordinary declarative
|
|
41
|
+
* partitions; partman's own retention does the same detach+drop).
|
|
42
|
+
*/
|
|
43
|
+
export declare function prunePartitionedTable({ client, schema, table, cutoff, options, }: {
|
|
44
|
+
client: DbClient;
|
|
45
|
+
schema: string;
|
|
46
|
+
table: string;
|
|
47
|
+
cutoff: Date;
|
|
48
|
+
options?: PruneOptions;
|
|
49
|
+
}): Promise<PartitionPruneOutcome>;
|
|
50
|
+
/**
|
|
51
|
+
* Drops every Timescale chunk of `table` wholly older than `cutoff` via
|
|
52
|
+
* `drop_chunks()`. Row counts are taken from the eligible chunks (reported by
|
|
53
|
+
* `show_chunks()`) before the drop. The whole `drop_chunks()` call is a
|
|
54
|
+
* single batch: it either runs or is skipped when `maxBatches` is 0 or the
|
|
55
|
+
* signal is already aborted.
|
|
56
|
+
*/
|
|
57
|
+
export declare function pruneTimescaleTable({ client, schema, table, cutoff, options, }: {
|
|
58
|
+
client: DbClient;
|
|
59
|
+
schema: string;
|
|
60
|
+
table: string;
|
|
61
|
+
cutoff: Date;
|
|
62
|
+
options?: PruneOptions;
|
|
63
|
+
}): Promise<PartitionPruneOutcome>;
|
|
64
|
+
//# sourceMappingURL=retention.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retention.d.ts","sourceRoot":"","sources":["../../../../../src/storage/domains/observability/v-next/retention.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAQD,wDAAwD;AACxD,wBAAgB,eAAe,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,SAAa,GAAG,IAAI,CAEpF;AA+BD;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA2BjC;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,QAAQ,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAuBjC"}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
import type { Schedule, ScheduleFilter, ScheduleTrigger, ScheduleTriggerListOptions, ScheduleUpdate, CreateIndexOptions } from '@mastra/core/storage';
|
|
1
|
+
import type { Schedule, ScheduleFilter, ScheduleTrigger, ScheduleTriggerListOptions, ScheduleUpdate, CreateIndexOptions, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
|
|
2
2
|
import { SchedulesStorage } from '@mastra/core/storage';
|
|
3
3
|
import type { PgDomainConfig } from '../../db/index.js';
|
|
4
4
|
export declare class SchedulesPG extends SchedulesStorage {
|
|
5
5
|
#private;
|
|
6
6
|
/** Tables managed by this domain */
|
|
7
7
|
static readonly MANAGED_TABLES: readonly ["mastra_schedules", "mastra_schedule_triggers"];
|
|
8
|
+
/**
|
|
9
|
+
* The fire/run history (`schedule_triggers`, one row per fire) is the growth
|
|
10
|
+
* table; schedule definitions are config and excluded. Anchored on
|
|
11
|
+
* `actual_fire_at`, a bigint epoch-ms column (numeric comparison, not
|
|
12
|
+
* timestamptz).
|
|
13
|
+
*/
|
|
14
|
+
static readonly retentionTables: RetentionTablesDescriptor;
|
|
8
15
|
constructor(config: PgDomainConfig);
|
|
9
16
|
init(): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Lazily ensures a btree index exists on each configured policy's retention
|
|
19
|
+
* anchor column so age-based `prune()` deletes stay fast. The default
|
|
20
|
+
* composite index leads with `schedule_id`, so a bare `actual_fire_at` range
|
|
21
|
+
* scan can't use it. Called from the prune path (not init) so only
|
|
22
|
+
* deployments that configure retention pay the index's write/disk overhead.
|
|
23
|
+
* Created even with `skipDefaultIndexes` — retention is an explicit opt-in,
|
|
24
|
+
* so its supporting index is not part of the default index set.
|
|
25
|
+
*/
|
|
26
|
+
private ensureRetentionIndexes;
|
|
27
|
+
/**
|
|
28
|
+
* Delete trigger (fire history) rows whose `actual_fire_at` is older than the
|
|
29
|
+
* `triggers` policy's `maxAge`, batched. Schedule definitions are never pruned.
|
|
30
|
+
*/
|
|
31
|
+
prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
|
|
10
32
|
/**
|
|
11
33
|
* Returns default index definitions for the schedules domain.
|
|
12
34
|
* @param schemaPrefix - Prefix for index names (e.g. "my_schema_" or "")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/schedules/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAGd,eAAe,EACf,0BAA0B,EAC1B,cAAc,EACd,kBAAkB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/schedules/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAGd,eAAe,EACf,0BAA0B,EAC1B,cAAc,EACd,kBAAkB,EAElB,YAAY,EACZ,WAAW,EACX,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAA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