@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.
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.23.0-alpha.0"
6
+ version: "1.23.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.23.0-alpha.0",
2
+ "version": "1.23.0-alpha.1",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -13513,6 +13513,7 @@ var ObservabilityPG = class ObservabilityPG extends _mastra_core_storage.Observa
13513
13513
  }
13514
13514
  }
13515
13515
  async batchDeleteTraces(args) {
13516
+ this.assertUnscopedBatchDeleteTraces(args);
13516
13517
  try {
13517
13518
  const tableName = getTableName$5({
13518
13519
  indexName: _mastra_core_storage.TABLE_SPANS,
@@ -17695,11 +17696,39 @@ async function getTraceLight(client, schema, args) {
17695
17696
  spans: rows.map(rowToLightSpanRecord)
17696
17697
  };
17697
17698
  }
17699
+ /**
17700
+ * Delete traces by traceId, cascading to trace-linked signal events
17701
+ * (metrics, logs, scores, feedback). Signal rows with a NULL traceId are
17702
+ * never affected. When the optional tenant scope (`organizationId` /
17703
+ * `resourceId`) is set, every DELETE additionally requires the row's tenant
17704
+ * columns to match.
17705
+ */
17698
17706
  async function batchDeleteTraces(client, schema, args) {
17699
17707
  if (args.traceIds.length === 0) return;
17700
- const span = qualifiedTable(schema, TABLE_SPAN_EVENTS);
17708
+ const params = [...args.traceIds];
17701
17709
  const placeholders = args.traceIds.map((_, i) => `$${i + 1}`).join(", ");
17702
- await client.query(`DELETE FROM ${span} WHERE "traceId" IN (${placeholders})`, args.traceIds);
17710
+ let scopeCondition = "";
17711
+ if (args.organizationId !== void 0) {
17712
+ params.push(args.organizationId);
17713
+ scopeCondition += ` AND "organizationId" = $${params.length}`;
17714
+ }
17715
+ if (args.resourceId !== void 0) {
17716
+ params.push(args.resourceId);
17717
+ scopeCondition += ` AND "resourceId" = $${params.length}`;
17718
+ }
17719
+ const tables = [
17720
+ TABLE_SPAN_EVENTS,
17721
+ TABLE_METRIC_EVENTS,
17722
+ TABLE_LOG_EVENTS,
17723
+ TABLE_SCORE_EVENTS,
17724
+ TABLE_FEEDBACK_EVENTS
17725
+ ];
17726
+ await client.tx(async (t) => {
17727
+ for (const tableName of tables) {
17728
+ const table = qualifiedTable(schema, tableName);
17729
+ await t.query(`DELETE FROM ${table} WHERE "traceId" IN (${placeholders})${scopeCondition}`, params);
17730
+ }
17731
+ });
17703
17732
  }
17704
17733
  /** Truncate the span_events table. */
17705
17734
  async function dangerouslyClearTracing(client, schema) {