@mastra/pg 1.23.0-alpha.0 → 1.23.0-alpha.1

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
@@ -13489,6 +13489,7 @@ var ObservabilityPG = class ObservabilityPG extends ObservabilityStorage {
13489
13489
  }
13490
13490
  }
13491
13491
  async batchDeleteTraces(args) {
13492
+ this.assertUnscopedBatchDeleteTraces(args);
13492
13493
  try {
13493
13494
  const tableName = getTableName$5({
13494
13495
  indexName: TABLE_SPANS,
@@ -17671,11 +17672,39 @@ async function getTraceLight(client, schema, args) {
17671
17672
  spans: rows.map(rowToLightSpanRecord)
17672
17673
  };
17673
17674
  }
17675
+ /**
17676
+ * Delete traces by traceId, cascading to trace-linked signal events
17677
+ * (metrics, logs, scores, feedback). Signal rows with a NULL traceId are
17678
+ * never affected. When the optional tenant scope (`organizationId` /
17679
+ * `resourceId`) is set, every DELETE additionally requires the row's tenant
17680
+ * columns to match.
17681
+ */
17674
17682
  async function batchDeleteTraces(client, schema, args) {
17675
17683
  if (args.traceIds.length === 0) return;
17676
- const span = qualifiedTable(schema, TABLE_SPAN_EVENTS);
17684
+ const params = [...args.traceIds];
17677
17685
  const placeholders = args.traceIds.map((_, i) => `$${i + 1}`).join(", ");
17678
- await client.query(`DELETE FROM ${span} WHERE "traceId" IN (${placeholders})`, args.traceIds);
17686
+ let scopeCondition = "";
17687
+ if (args.organizationId !== void 0) {
17688
+ params.push(args.organizationId);
17689
+ scopeCondition += ` AND "organizationId" = $${params.length}`;
17690
+ }
17691
+ if (args.resourceId !== void 0) {
17692
+ params.push(args.resourceId);
17693
+ scopeCondition += ` AND "resourceId" = $${params.length}`;
17694
+ }
17695
+ const tables = [
17696
+ TABLE_SPAN_EVENTS,
17697
+ TABLE_METRIC_EVENTS,
17698
+ TABLE_LOG_EVENTS,
17699
+ TABLE_SCORE_EVENTS,
17700
+ TABLE_FEEDBACK_EVENTS
17701
+ ];
17702
+ await client.tx(async (t) => {
17703
+ for (const tableName of tables) {
17704
+ const table = qualifiedTable(schema, tableName);
17705
+ await t.query(`DELETE FROM ${table} WHERE "traceId" IN (${placeholders})${scopeCondition}`, params);
17706
+ }
17707
+ });
17679
17708
  }
17680
17709
  /** Truncate the span_events table. */
17681
17710
  async function dangerouslyClearTracing(client, schema) {