@mastra/oracledb 0.3.0 → 0.4.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.js CHANGED
@@ -2,7 +2,7 @@ import { MastraVector, validateTopK, validateUpsertInput } from "@mastra/core/ve
2
2
  import oracledb from "oracledb";
3
3
  import { ErrorCategory, ErrorDomain, MastraError } from "@mastra/core/error";
4
4
  import { createHash, randomUUID } from "crypto";
5
- import { AgentsStorage, MCPClientsStorage, MastraCompositeStore, MemoryStorage, ObservabilityStorage, ScorerDefinitionsStorage, ScoresStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, TraceStatus, WorkflowsStorage, calculatePagination, createStorageErrorId, createVectorErrorId, listLogsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
5
+ import { AgentsStorage, MCPClientsStorage, MastraCompositeStore, MemoryStorage, ObservabilityStorage, ScorerDefinitionsStorage, ScoresStorage, TABLE_AGENTS, TABLE_AGENT_VERSIONS, TABLE_MCP_CLIENTS, TABLE_MCP_CLIENT_VERSIONS, TABLE_MESSAGES, TABLE_OBSERVATIONAL_MEMORY, TABLE_RESOURCES, TABLE_SCHEMAS, TABLE_SCORERS, TABLE_SCORER_DEFINITIONS, TABLE_SCORER_DEFINITION_VERSIONS, TABLE_SPANS, TABLE_THREADS, TABLE_WORKFLOW_SNAPSHOT, TraceStatus, WorkflowsStorage, calculatePagination, createStorageErrorId, createVectorErrorId, executeRetentionPrune, listLogsArgsSchema, listScoresArgsSchema, listTracesArgsSchema, matchesExpectedWorkflowStatus, normalizePerPage, resolveRetentionTargets, retentionCutoffMs, storageMessageMatchesMetadataFilter, toTraceSpans, transformScoreRow, validateStorageMetadataFilter } from "@mastra/core/storage";
6
6
  import { MessageList } from "@mastra/core/agent";
7
7
  import { saveScorePayloadSchema } from "@mastra/core/evals";
8
8
  //#region src/shared/connection.ts
@@ -1668,6 +1668,25 @@ var OracleDB = class {
1668
1668
  async withConnection(callback) {
1669
1669
  return this.config.poolManager.withConnection(callback);
1670
1670
  }
1671
+ async pruneBatch({ tableName, column, cutoff, limit }) {
1672
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(column)) throw new Error(`Invalid retention identifier: ${tableName}.${column}`);
1673
+ return this.config.poolManager.withConnection(async (connection) => {
1674
+ try {
1675
+ const table = this.table(tableName);
1676
+ const result = await connection.execute(`DELETE FROM ${table} WHERE ROWID IN (
1677
+ SELECT ROWID FROM ${table} WHERE "${column}" < :cutoff ORDER BY "${column}" FETCH FIRST :limit ROWS ONLY
1678
+ )`, asBindParameters({
1679
+ cutoff,
1680
+ limit
1681
+ }));
1682
+ await connection.commit();
1683
+ return result.rowsAffected ?? 0;
1684
+ } catch (error) {
1685
+ await rollbackQuietly(connection);
1686
+ throw error;
1687
+ }
1688
+ });
1689
+ }
1671
1690
  async none(sql, binds = {}) {
1672
1691
  await this.config.poolManager.withConnection(async (connection) => {
1673
1692
  await connection.execute(sql, asBindParameters(binds));
@@ -6734,6 +6753,18 @@ function traceOrderClause(field, direction) {
6734
6753
  //#endregion
6735
6754
  //#region src/storage/domains/observability/index.ts
6736
6755
  var ObservabilityOracle = class ObservabilityOracle extends ObservabilityStorage {
6756
+ static retentionTables = {
6757
+ spans: {
6758
+ table: TABLE_SPANS,
6759
+ column: "startedAt",
6760
+ indexed: true
6761
+ },
6762
+ logs: {
6763
+ table: LOG_EVENTS_TABLE,
6764
+ column: "timestamp",
6765
+ indexed: true
6766
+ }
6767
+ };
6737
6768
  static MANAGED_TABLES = [TABLE_SPANS, LOG_EVENTS_TABLE];
6738
6769
  db;
6739
6770
  schemaName;
@@ -6746,6 +6777,24 @@ var ObservabilityOracle = class ObservabilityOracle extends ObservabilityStorage
6746
6777
  this.skipDefaultIndexes = config.skipDefaultIndexes;
6747
6778
  this.indexes = filterIndexesForTables(config.indexes, ObservabilityOracle.MANAGED_TABLES);
6748
6779
  }
6780
+ async prune(policies, options) {
6781
+ return executeRetentionPrune({
6782
+ domain: "observability",
6783
+ targets: resolveRetentionTargets({
6784
+ policies,
6785
+ descriptor: ObservabilityOracle.retentionTables,
6786
+ order: ["spans", "logs"]
6787
+ }),
6788
+ options,
6789
+ cutoffFor: (target, now) => new Date(retentionCutoffMs(target.policy, now)),
6790
+ deleteBatch: (target, cutoff, limit) => this.db.pruneBatch({
6791
+ tableName: target.table,
6792
+ column: target.column,
6793
+ cutoff,
6794
+ limit
6795
+ })
6796
+ });
6797
+ }
6749
6798
  async init() {
6750
6799
  await this.db.createTable({
6751
6800
  tableName: TABLE_SPANS,
@@ -8420,7 +8469,8 @@ var OracleStore = class extends MastraCompositeStore {
8420
8469
  super({
8421
8470
  id: config.id,
8422
8471
  name: "OracleStore",
8423
- disableInit: config.disableInit
8472
+ disableInit: config.disableInit,
8473
+ retention: config.retention
8424
8474
  });
8425
8475
  this.schemaName = config.schemaName ? normalizeIdentifier(config.schemaName, "schema name") : void 0;
8426
8476
  this.skipDefaultIndexes = config.skipDefaultIndexes;