@mastra/duckdb 1.7.0-alpha.0 → 1.7.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.
@@ -20,7 +20,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  enumerable: true
21
21
  }) : target, mod));
22
22
  //#endregion
23
- const require_db = require("./db-TBEcMD49.cjs");
23
+ const require_db = require("./db-CJBcanx4.cjs");
24
24
  let _mastra_core_error = require("@mastra/core/error");
25
25
  let _mastra_core_storage = require("@mastra/core/storage");
26
26
  _mastra_core_storage = __toESM(_mastra_core_storage, 1);
@@ -2093,6 +2093,43 @@ async function migrateSignalTables(db, logger) {
2093
2093
  }
2094
2094
  //#endregion
2095
2095
  //#region src/storage/domains/observability/scores.ts
2096
+ const SCORE_UPSERT_CLAUSE = `ON CONFLICT (scoreId) DO UPDATE SET ${[
2097
+ "timestamp",
2098
+ "traceId",
2099
+ "spanId",
2100
+ "experimentId",
2101
+ "scoreTraceId",
2102
+ "entityType",
2103
+ "entityId",
2104
+ "entityName",
2105
+ "entityVersionId",
2106
+ "parentEntityVersionId",
2107
+ "parentEntityType",
2108
+ "parentEntityId",
2109
+ "parentEntityName",
2110
+ "rootEntityVersionId",
2111
+ "rootEntityType",
2112
+ "rootEntityId",
2113
+ "rootEntityName",
2114
+ "userId",
2115
+ "organizationId",
2116
+ "resourceId",
2117
+ "runId",
2118
+ "sessionId",
2119
+ "threadId",
2120
+ "requestId",
2121
+ "environment",
2122
+ "executionSource",
2123
+ "serviceName",
2124
+ "scorerId",
2125
+ "scorerVersion",
2126
+ "scoreSource",
2127
+ "score",
2128
+ "reason",
2129
+ "tags",
2130
+ "metadata",
2131
+ "scope"
2132
+ ].map((column) => `${column} = excluded.${column}`).join(", ")}`;
2096
2133
  const SCORE_GROUP_BY_COLUMNS = /* @__PURE__ */ new Set([
2097
2134
  "timestamp",
2098
2135
  "traceId",
@@ -2256,7 +2293,7 @@ function getComparisonDateRange(comparePeriod, timestamp) {
2256
2293
  async function createScore(db, args) {
2257
2294
  const s = args.score;
2258
2295
  const scoreSource = s.scoreSource ?? s.source ?? null;
2259
- await db.execute(`INSERT OR REPLACE INTO score_events (
2296
+ await db.execute(`INSERT INTO score_events (
2260
2297
  scoreId, timestamp, cursorId, traceId, spanId, experimentId, scoreTraceId,
2261
2298
  entityType, entityId, entityName, entityVersionId, parentEntityVersionId, parentEntityType, parentEntityId, parentEntityName, rootEntityVersionId, rootEntityType, rootEntityId, rootEntityName,
2262
2299
  userId, organizationId, resourceId, runId, sessionId, threadId, requestId, environment, executionSource, serviceName,
@@ -2300,7 +2337,8 @@ async function createScore(db, args) {
2300
2337
  jsonV(s.tags ?? null),
2301
2338
  jsonV(s.metadata),
2302
2339
  jsonV(s.scope ?? null)
2303
- ].join(", ")})`);
2340
+ ].join(", ")})
2341
+ ${SCORE_UPSERT_CLAUSE}`);
2304
2342
  }
2305
2343
  /** Insert multiple score events in a single statement. */
2306
2344
  async function batchCreateScores(db, args) {
@@ -2348,13 +2386,14 @@ async function batchCreateScores(db, args) {
2348
2386
  jsonV(legacyScore.scope ?? null)
2349
2387
  ].join(", ")})`;
2350
2388
  });
2351
- await db.execute(`INSERT OR REPLACE INTO score_events (
2389
+ await db.execute(`INSERT INTO score_events (
2352
2390
  scoreId, timestamp, cursorId, traceId, spanId, experimentId, scoreTraceId,
2353
2391
  entityType, entityId, entityName, entityVersionId, parentEntityVersionId, parentEntityType, parentEntityId, parentEntityName, rootEntityVersionId, rootEntityType, rootEntityId, rootEntityName,
2354
2392
  userId, organizationId, resourceId, runId, sessionId, threadId, requestId, environment, executionSource, serviceName,
2355
2393
  scorerId, scorerVersion, scoreSource, score, reason, tags, metadata, scope
2356
2394
  )
2357
- VALUES ${tuples.join(",\n ")}`);
2395
+ VALUES ${tuples.join(",\n ")}
2396
+ ${SCORE_UPSERT_CLAUSE}`);
2358
2397
  }
2359
2398
  /** Query score events with filtering, ordering, and pagination. */
2360
2399
  async function listScores(db, args) {
@@ -3353,11 +3392,36 @@ async function batchCreateSpans(db, args) {
3353
3392
  return events;
3354
3393
  }));
3355
3394
  }
3356
- /** Delete all span events for the given trace IDs. */
3395
+ /**
3396
+ * Delete all span events for the given trace IDs, cascading to trace-linked
3397
+ * signal events (metrics, logs, scores, feedback). Signal rows with a NULL
3398
+ * traceId are never affected. When the optional tenant scope
3399
+ * (`organizationId` / `resourceId`) is set, every DELETE additionally
3400
+ * requires the row's tenant columns to match.
3401
+ */
3357
3402
  async function batchDeleteTraces(db, args) {
3358
3403
  if (args.traceIds.length === 0) return;
3359
3404
  const placeholders = args.traceIds.map(() => "?").join(", ");
3360
- await db.execute(`DELETE FROM span_events WHERE traceId IN (${placeholders})`, args.traceIds);
3405
+ const params = [...args.traceIds];
3406
+ let scopeCondition = "";
3407
+ if (args.organizationId !== void 0) {
3408
+ scopeCondition += ` AND organizationId = ?`;
3409
+ params.push(args.organizationId);
3410
+ }
3411
+ if (args.resourceId !== void 0) {
3412
+ scopeCondition += ` AND resourceId = ?`;
3413
+ params.push(args.resourceId);
3414
+ }
3415
+ await db.executeTransaction([
3416
+ "span_events",
3417
+ "metric_events",
3418
+ "log_events",
3419
+ "score_events",
3420
+ "feedback_events"
3421
+ ].map((table) => ({
3422
+ sql: `DELETE FROM ${table} WHERE traceId IN (${placeholders})${scopeCondition}`,
3423
+ params
3424
+ })));
3361
3425
  }
3362
3426
  /** Reconstruct a single span from its event history. */
3363
3427
  async function getSpan(db, args) {
@@ -4204,4 +4268,4 @@ var ObservabilityStorageDuckDB = class extends _mastra_core_storage.Observabilit
4204
4268
  //#endregion
4205
4269
  exports.ObservabilityStorageDuckDB = ObservabilityStorageDuckDB;
4206
4270
 
4207
- //# sourceMappingURL=observability-BAQ2aKaO.cjs.map
4271
+ //# sourceMappingURL=observability-yLoG0tl3.cjs.map