@mastra/pg 1.14.3 → 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.
Files changed (51) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/docs/SKILL.md +2 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  4. package/dist/docs/references/docs-memory-semantic-recall.md +8 -0
  5. package/dist/docs/references/docs-memory-storage.md +6 -0
  6. package/dist/docs/references/docs-memory-working-memory.md +2 -0
  7. package/dist/docs/references/docs-rag-overview.md +2 -0
  8. package/dist/docs/references/docs-rag-retrieval.md +2 -0
  9. package/dist/docs/references/docs-rag-vector-databases.md +2 -0
  10. package/dist/docs/references/reference-memory-memory-class.md +3 -0
  11. package/dist/docs/references/reference-processors-message-history-processor.md +3 -0
  12. package/dist/docs/references/reference-processors-semantic-recall-processor.md +3 -0
  13. package/dist/docs/references/reference-processors-working-memory-processor.md +3 -0
  14. package/dist/docs/references/reference-rag-metadata-filters.md +2 -0
  15. package/dist/docs/references/reference-storage-composite.md +2 -0
  16. package/dist/docs/references/reference-storage-dynamodb.md +2 -0
  17. package/dist/docs/references/reference-storage-postgresql.md +2 -0
  18. package/dist/docs/references/reference-storage-retention.md +180 -0
  19. package/dist/docs/references/reference-tools-vector-query-tool.md +2 -0
  20. package/dist/docs/references/reference-vectors-pg.md +2 -0
  21. package/dist/index.cjs +749 -2
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.js +750 -3
  24. package/dist/index.js.map +1 -1
  25. package/dist/shared/config.d.ts +8 -1
  26. package/dist/shared/config.d.ts.map +1 -1
  27. package/dist/storage/db/index.d.ts +51 -0
  28. package/dist/storage/db/index.d.ts.map +1 -1
  29. package/dist/storage/domains/background-tasks/index.d.ts +19 -1
  30. package/dist/storage/domains/background-tasks/index.d.ts.map +1 -1
  31. package/dist/storage/domains/experiments/index.d.ts +31 -1
  32. package/dist/storage/domains/experiments/index.d.ts.map +1 -1
  33. package/dist/storage/domains/memory/index.d.ts +39 -1
  34. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  35. package/dist/storage/domains/notifications/index.d.ts +18 -1
  36. package/dist/storage/domains/notifications/index.d.ts.map +1 -1
  37. package/dist/storage/domains/observability/index.d.ts +22 -1
  38. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  39. package/dist/storage/domains/observability/v-next/index.d.ts +17 -1
  40. package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
  41. package/dist/storage/domains/observability/v-next/retention.d.ts +64 -0
  42. package/dist/storage/domains/observability/v-next/retention.d.ts.map +1 -0
  43. package/dist/storage/domains/schedules/index.d.ts +23 -1
  44. package/dist/storage/domains/schedules/index.d.ts.map +1 -1
  45. package/dist/storage/domains/scores/index.d.ts +18 -1
  46. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  47. package/dist/storage/domains/workflows/index.d.ts +19 -1
  48. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  49. package/dist/storage/retention.d.ts +76 -0
  50. package/dist/storage/retention.d.ts.map +1 -0
  51. package/package.json +3 -3
@@ -1,13 +1,28 @@
1
1
  import type { ListScoresResponse, SaveScorePayload, ScoreRowData, ScoringSource } from '@mastra/core/evals';
2
- import type { StoragePagination, CreateIndexOptions } from '@mastra/core/storage';
2
+ import type { StoragePagination, CreateIndexOptions, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
3
3
  import { ScoresStorage } from '@mastra/core/storage';
4
4
  import type { PgDomainConfig } from '../../db/index.js';
5
5
  export declare class ScoresPG extends ScoresStorage {
6
6
  #private;
7
7
  /** Tables managed by this domain */
8
8
  static readonly MANAGED_TABLES: readonly ["mastra_scorers"];
9
+ /**
10
+ * Scorer results accumulate as evals run. Single table, anchored on the
11
+ * timezone-aware `createdAtZ` mirror column (kept in sync by triggers).
12
+ */
13
+ static readonly retentionTables: RetentionTablesDescriptor;
9
14
  constructor(config: PgDomainConfig);
10
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;
11
26
  /**
12
27
  * Returns default index definitions for the scores domain tables.
13
28
  * @param schemaPrefix - Prefix for index names (e.g. "my_schema_" or "")
@@ -31,6 +46,8 @@ export declare class ScoresPG extends ScoresStorage {
31
46
  */
32
47
  createCustomIndexes(): Promise<void>;
33
48
  dangerouslyClearAll(): Promise<void>;
49
+ /** Delete scorer results older than the `scorers` policy's `maxAge`, batched. */
50
+ prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
34
51
  getScoreById({ id }: {
35
52
  id: string;
36
53
  }): Promise<ScoreRowData | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/scores/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE5G,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAIL,aAAa,EAId,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAwB/C,qBAAa,QAAS,SAAQ,aAAa;;IAMzC,oCAAoC;IACpC,MAAM,CAAC,QAAQ,CAAC,cAAc,8BAA4B;gBAE9C,MAAM,EAAE,cAAc;IAU5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CAAC,YAAY,E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C;CA0ChC"}
@@ -1,5 +1,5 @@
1
1
  import { WorkflowsStorage } from '@mastra/core/storage';
2
- import type { UpdateWorkflowStateOptions, StorageListWorkflowRunsInput, WorkflowRun, WorkflowRuns, CreateIndexOptions } from '@mastra/core/storage';
2
+ import type { UpdateWorkflowStateOptions, StorageListWorkflowRunsInput, WorkflowRun, WorkflowRuns, CreateIndexOptions, PruneOptions, PruneResult, RetentionTablesDescriptor, TableRetentionPolicy } from '@mastra/core/storage';
3
3
  import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
4
4
  import type { PgDomainConfig } from '../../db/index.js';
5
5
  /**
@@ -16,6 +16,12 @@ export declare class WorkflowsPG extends WorkflowsStorage {
16
16
  #private;
17
17
  /** Tables managed by this domain */
18
18
  static readonly MANAGED_TABLES: readonly ["mastra_workflow_snapshot"];
19
+ /**
20
+ * Workflow run snapshots accumulate as runs execute. Anchored on the
21
+ * timezone-aware `updatedAtZ` mirror column (last activity) so suspended or
22
+ * long-running runs are not pruned by start age.
23
+ */
24
+ static readonly retentionTables: RetentionTablesDescriptor;
19
25
  constructor(config: PgDomainConfig);
20
26
  supportsConcurrentUpdates(): boolean;
21
27
  private parseWorkflowRun;
@@ -35,6 +41,18 @@ export declare class WorkflowsPG extends WorkflowsStorage {
35
41
  */
36
42
  createDefaultIndexes(): Promise<void>;
37
43
  init(): Promise<void>;
44
+ /**
45
+ * Lazily ensures a btree index exists on each configured policy's retention
46
+ * anchor column so age-based `prune()` deletes stay fast on large tables.
47
+ * Called from the prune path (not init) so only deployments that configure
48
+ * retention pay the index's write/disk overhead. Best-effort: failures are
49
+ * logged and pruning proceeds (correct, just slower).
50
+ * Created even with `skipDefaultIndexes` — retention is an explicit opt-in,
51
+ * so its supporting index is not part of the default index set.
52
+ */
53
+ private ensureRetentionIndexes;
54
+ /** Delete workflow run snapshots older than the `workflowSnapshot` policy's `maxAge`, batched. */
55
+ prune(policies: Record<string, TableRetentionPolicy>, options?: PruneOptions): Promise<PruneResult[]>;
38
56
  /**
39
57
  * Creates custom user-defined indexes for this domain's tables.
40
58
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/workflows/index.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,gBAAgB,EAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,WAAW,EACX,YAAY,EACZ,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAW/C;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAa5D;AAED,qBAAa,WAAY,SAAQ,gBAAgB;;IAM/C,oCAAoC;IACpC,MAAM,CAAC,QAAQ,CAAC,cAAc,wCAAsC;gBAExD,MAAM,EAAE,cAAc;IAUlC,yBAAyB,IAAI,OAAO;IAIpC,OAAO,CAAC,gBAAgB;IAmBxB;;;OAGG;IACH,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAgBlD;;;OAGG;IACH,0BAA0B,IAAI,kBAAkB,EAAE;IAIlD;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAepC,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,qBAAqB,CAAC,EAC1B,YAAY,EACZ,KAAK,EACL,MAAM,EACN,MAAM,EACN,cAAc,GACf,EAAE;QACD,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,MAA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AAG,OAAO,CAAC,IAAI,CAAC;IAoCX,oBAAoB,CAAC,EACzB,YAAY,EACZ,KAAK,GACN,EAAE;QACD,YAAY,EAAE,MAAM,CAAC;QACrB,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAoB9B,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;IAmDzB,qBAAqB,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBtG,gBAAgB,CAAC,EACrB,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,IAAI,EACJ,UAAU,EACV,MAAM,GACP,GAAE,4BAAiC,GAAG,OAAO,CAAC,YAAY,CAAC;CA6F7D"}
@@ -0,0 +1,76 @@
1
+ import type { TABLE_NAMES, PruneOptions, PruneResult, TableRetentionPolicy } from '@mastra/core/storage';
2
+ import type { PgDB } from './db/index.js';
3
+ /** One table to prune, resolved from a policy + the domain's descriptor. */
4
+ export interface PruneTarget {
5
+ /** Physical table name. */
6
+ table: TABLE_NAMES;
7
+ /** Anchor column for the age comparison. */
8
+ column: string;
9
+ /**
10
+ * How the anchor column stores time, which decides how the cutoff is bound:
11
+ * - `timestamp` (default): a `Date` compared against a `timestamptz` column.
12
+ * - `epoch-ms`: a raw millisecond number compared against a `bigint` column
13
+ * (e.g. `schedules.triggers.actual_fire_at`).
14
+ */
15
+ anchorType: 'timestamp' | 'epoch-ms';
16
+ /** Retention policy (maxAge + optional batchSize). */
17
+ policy: TableRetentionPolicy;
18
+ }
19
+ /**
20
+ * Convert a policy's `maxAge` into a cutoff bound matching the anchor's storage
21
+ * type: a `Date` for `timestamptz` columns (pg compares timezone-aware), or a
22
+ * raw millisecond number for `bigint` epoch-ms columns.
23
+ */
24
+ export declare function cutoffFor(policy: TableRetentionPolicy, anchorType: 'timestamp' | 'epoch-ms', now?: number): number | Date;
25
+ /**
26
+ * Run the bounded/cancellable batched-delete loop for a single logical target,
27
+ * delegating the actual delete of up to `limit` rows to `deleteBatch`. Returns
28
+ * `{ deleted, done }`; `done: false` means the loop stopped on a bound or the
29
+ * abort signal and eligible rows may remain.
30
+ */
31
+ export declare function runBatchedDelete({ deleteBatch, batchSize, options, }: {
32
+ deleteBatch: (limit: number) => Promise<number>;
33
+ batchSize: number;
34
+ options?: PruneOptions;
35
+ }): Promise<{
36
+ deleted: number;
37
+ done: boolean;
38
+ }>;
39
+ /**
40
+ * Runs the bounded, batched, cancellable delete loop for a set of tables in the
41
+ * given order (callers pass children before parents for cascade-safe pruning),
42
+ * and returns one {@link PruneResult} per table.
43
+ *
44
+ * The loop:
45
+ * - deletes in chunks of `batchSize` (default 1000), each its own statement;
46
+ * - stops a table's loop when a batch deletes fewer rows than requested (drained),
47
+ * or when `maxBatches`/`maxRows` is hit, or the `signal` aborts — the latter
48
+ * three leave `done: false` so the caller can resume;
49
+ * - pauses `pauseMs` between batches when set, to avoid starving live traffic.
50
+ *
51
+ * `prune()` only deletes rows; it never reclaims disk. PostgreSQL reuses freed
52
+ * space (dead tuples) via autovacuum on subsequent writes, so tables stop
53
+ * growing. Returning disk to the OS (e.g. `VACUUM FULL`) is left to the operator.
54
+ */
55
+ export declare function runPrune({ db, domain, targets, options, }: {
56
+ db: PgDB;
57
+ domain: string;
58
+ targets: PruneTarget[];
59
+ options?: PruneOptions;
60
+ }): Promise<PruneResult[]>;
61
+ /**
62
+ * Resolve a domain's `{ tableKey: policy }` map plus its descriptor into an
63
+ * ordered list of {@link PruneTarget}s. `order` lists table keys children-first
64
+ * so cascade-dependent rows are removed before their parents. Table keys not in
65
+ * `policies` are skipped (unset = keep forever).
66
+ */
67
+ export declare function resolveTargets({ policies, descriptor, order, }: {
68
+ policies: Record<string, TableRetentionPolicy>;
69
+ descriptor: Record<string, {
70
+ table: string;
71
+ column: string;
72
+ anchorType?: 'timestamp' | 'epoch-ms';
73
+ }>;
74
+ order: string[];
75
+ }): PruneTarget[];
76
+ //# sourceMappingURL=retention.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retention.d.ts","sourceRoot":"","sources":["../../src/storage/retention.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACzG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAIjC,4EAA4E;AAC5E,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,KAAK,EAAE,WAAW,CAAC;IACnB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,UAAU,EAAE,WAAW,GAAG,UAAU,CAAC;IACrC,sDAAsD;IACtD,MAAM,EAAE,oBAAoB,CAAC;CAC9B;AAiBD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,GAAG,UAAU,EAAE,GAAG,SAAa,iBAG7G;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,EACrC,WAAW,EACX,SAAS,EACT,OAAO,GACR,EAAE;IACD,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAkC9C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,QAAQ,CAAC,EAC7B,EAAE,EACF,MAAM,EACN,OAAO,EACP,OAAO,GACR,EAAE;IACD,EAAE,EAAE,IAAI,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,YAAY,CAAC;CACxB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAuBzB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,UAAU,EACV,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC/C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,WAAW,GAAG,UAAU,CAAA;KAAE,CAAC,CAAC;IACrG,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,GAAG,WAAW,EAAE,CAchB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "1.14.3",
3
+ "version": "1.15.0-alpha.0",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -37,8 +37,8 @@
37
37
  "vitest": "4.1.8",
38
38
  "@internal/lint": "0.0.110",
39
39
  "@internal/storage-test-utils": "0.0.106",
40
- "@mastra/core": "1.48.0",
41
- "@internal/types-builder": "0.0.85"
40
+ "@internal/types-builder": "0.0.85",
41
+ "@mastra/core": "1.49.0-alpha.3"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@mastra/core": ">=1.42.1-0 <2.0.0-0"