@mastra/spanner 1.10.0-alpha.1 → 1.10.1-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.
@@ -3,7 +3,7 @@ name: mastra-spanner
3
3
  description: Documentation for @mastra/spanner. Use when working with @mastra/spanner APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/spanner"
6
- version: "1.10.0-alpha.1"
6
+ version: "1.10.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.0-alpha.1",
2
+ "version": "1.10.1-alpha.0",
3
3
  "package": "@mastra/spanner",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -839,24 +839,27 @@ var SpannerDB = class extends _mastra_core_base.MastraBase {
839
839
  result[key] = value;
840
840
  continue;
841
841
  }
842
- if (colDef?.type === "jsonb") if (typeof value === "string") try {
843
- result[key] = JSON.parse(value);
844
- } catch {
845
- result[key] = value;
846
- }
847
- else result[key] = value;
848
- else if (colDef?.type === "timestamp") if (value instanceof Date) result[key] = new Date(value.getTime());
849
- else if (typeof value === "string") result[key] = new Date(value);
850
- else if (typeof value === "object" && typeof value.value === "string") result[key] = new Date(value.value);
851
- else result[key] = value;
852
- else if (colDef?.type === "integer" || colDef?.type === "bigint") if (typeof value === "string") {
853
- const n = Number(value);
854
- result[key] = Number.isSafeInteger(n) ? n : value;
855
- } else if (typeof value === "bigint") {
856
- const n = Number(value);
857
- result[key] = Number.isSafeInteger(n) ? n : value.toString();
858
- } else result[key] = value;
859
- else if (colDef?.type === "boolean") result[key] = Boolean(value);
842
+ if (colDef?.type === "jsonb") {
843
+ if (typeof value === "string") try {
844
+ result[key] = JSON.parse(value);
845
+ } catch {
846
+ result[key] = value;
847
+ }
848
+ else result[key] = value;
849
+ } else if (colDef?.type === "timestamp") {
850
+ if (value instanceof Date) result[key] = new Date(value.getTime());
851
+ else if (typeof value === "string") result[key] = new Date(value);
852
+ else if (typeof value === "object" && typeof value.value === "string") result[key] = new Date(value.value);
853
+ else result[key] = value;
854
+ } else if (colDef?.type === "integer" || colDef?.type === "bigint") {
855
+ if (typeof value === "string") {
856
+ const n = Number(value);
857
+ result[key] = Number.isSafeInteger(n) ? n : value;
858
+ } else if (typeof value === "bigint") {
859
+ const n = Number(value);
860
+ result[key] = Number.isSafeInteger(n) ? n : value.toString();
861
+ } else result[key] = value;
862
+ } else if (colDef?.type === "boolean") result[key] = Boolean(value);
860
863
  else result[key] = value;
861
864
  }
862
865
  return result;
@@ -905,16 +908,17 @@ var SpannerDB = class extends _mastra_core_base.MastraBase {
905
908
  for (const item of inValues) paramNames.push(`@${bind(key, item)}`);
906
909
  conditions.push(`${quoteIdent(key, "field name")} IN (${paramNames.join(", ")})`);
907
910
  }
908
- } else if (Array.isArray(value)) if (value.length === 0) conditions.push("1 = 0");
909
- else if (value.length === 1) {
910
- const param = bind(key, value[0]);
911
- conditions.push(`${quoteIdent(key, "field name")} = @${param}`);
911
+ } else if (Array.isArray(value)) {
912
+ if (value.length === 0) conditions.push("1 = 0");
913
+ else if (value.length === 1) {
914
+ const param = bind(key, value[0]);
915
+ conditions.push(`${quoteIdent(key, "field name")} = @${param}`);
916
+ } else {
917
+ const paramNames = [];
918
+ for (const item of value) paramNames.push(`@${bind(key, item)}`);
919
+ conditions.push(`${quoteIdent(key, "field name")} IN (${paramNames.join(", ")})`);
920
+ }
912
921
  } else {
913
- const paramNames = [];
914
- for (const item of value) paramNames.push(`@${bind(key, item)}`);
915
- conditions.push(`${quoteIdent(key, "field name")} IN (${paramNames.join(", ")})`);
916
- }
917
- else {
918
922
  const param = bind(key, value);
919
923
  conditions.push(`${quoteIdent(key, "field name")} = @${param}`);
920
924
  }
@@ -1174,18 +1178,20 @@ function transformFromSpannerRow({ tableName, row }) {
1174
1178
  } catch {
1175
1179
  result[key] = value;
1176
1180
  }
1177
- else if (colDef?.type === "timestamp") if (value instanceof Date) result[key] = new Date(value.getTime());
1178
- else if (typeof value === "string") result[key] = new Date(value);
1179
- else if (typeof value === "object" && typeof value.value === "string") result[key] = new Date(value.value);
1180
- else result[key] = value;
1181
- else if (colDef?.type === "integer" || colDef?.type === "bigint") if (typeof value === "string") {
1182
- const n = Number(value);
1183
- result[key] = Number.isSafeInteger(n) ? n : value;
1184
- } else if (typeof value === "bigint") {
1185
- const n = Number(value);
1186
- result[key] = Number.isSafeInteger(n) ? n : value.toString();
1187
- } else result[key] = value;
1188
- else if (colDef?.type === "boolean") result[key] = Boolean(value);
1181
+ else if (colDef?.type === "timestamp") {
1182
+ if (value instanceof Date) result[key] = new Date(value.getTime());
1183
+ else if (typeof value === "string") result[key] = new Date(value);
1184
+ else if (typeof value === "object" && typeof value.value === "string") result[key] = new Date(value.value);
1185
+ else result[key] = value;
1186
+ } else if (colDef?.type === "integer" || colDef?.type === "bigint") {
1187
+ if (typeof value === "string") {
1188
+ const n = Number(value);
1189
+ result[key] = Number.isSafeInteger(n) ? n : value;
1190
+ } else if (typeof value === "bigint") {
1191
+ const n = Number(value);
1192
+ result[key] = Number.isSafeInteger(n) ? n : value.toString();
1193
+ } else result[key] = value;
1194
+ } else if (colDef?.type === "boolean") result[key] = Boolean(value);
1189
1195
  else result[key] = value;
1190
1196
  }
1191
1197
  return result;
@@ -2049,15 +2055,19 @@ var BackgroundTasksSpanner = class BackgroundTasksSpanner extends _mastra_core_s
2049
2055
  predicates.push("status = @expectedStatus");
2050
2056
  params.expectedStatus = options.expectedStatus;
2051
2057
  }
2052
- if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) predicates.push("ownerId IS NULL");
2053
- else {
2054
- predicates.push("ownerId = @expectedOwnerId");
2055
- params.expectedOwnerId = options.expectedOwnerId;
2058
+ if (options?.expectedOwnerId !== void 0) {
2059
+ if (options.expectedOwnerId === null) predicates.push("ownerId IS NULL");
2060
+ else {
2061
+ predicates.push("ownerId = @expectedOwnerId");
2062
+ params.expectedOwnerId = options.expectedOwnerId;
2063
+ }
2056
2064
  }
2057
- if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) predicates.push("leaseExpiresAt IS NULL");
2058
- else {
2059
- predicates.push("leaseExpiresAt = @expectedLeaseExpiresAt");
2060
- params.expectedLeaseExpiresAt = options.expectedLeaseExpiresAt;
2065
+ if (options?.expectedLeaseExpiresAt !== void 0) {
2066
+ if (options.expectedLeaseExpiresAt === null) predicates.push("leaseExpiresAt IS NULL");
2067
+ else {
2068
+ predicates.push("leaseExpiresAt = @expectedLeaseExpiresAt");
2069
+ params.expectedLeaseExpiresAt = options.expectedLeaseExpiresAt;
2070
+ }
2061
2071
  }
2062
2072
  const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
2063
2073
  const [rowCount] = await this.database.runUpdate({
@@ -6729,10 +6739,11 @@ async function assertRunFence(tx, claimsTable, fence, operation) {
6729
6739
  json: true
6730
6740
  });
6731
6741
  const row = rows[0];
6732
- if (!(0, _mastra_core_storage.matchesRunFence)(row ? {
6742
+ const current = row ? {
6733
6743
  generation: Number(row.generation),
6734
6744
  ownerId: String(row.ownerId)
6735
- } : null, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
6745
+ } : null;
6746
+ if (!(0, _mastra_core_storage.matchesRunFence)(current, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
6736
6747
  }
6737
6748
  /**
6738
6749
  * Runs `fn` in a read-write transaction and commits it, retrying the whole
@@ -6883,13 +6894,14 @@ var MemorySpanner = class MemorySpanner extends _mastra_core_storage.MemoryStora
6883
6894
  }
6884
6895
  /** Removes every row from threads/messages/resources and run fence tables. Intended for tests. */
6885
6896
  async prune(policies, options) {
6897
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
6898
+ policies,
6899
+ descriptor: MemorySpanner.retentionTables,
6900
+ order: ["runFences"]
6901
+ });
6886
6902
  return (0, _mastra_core_storage.executeRetentionPrune)({
6887
6903
  domain: "memory",
6888
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
6889
- policies,
6890
- descriptor: MemorySpanner.retentionTables,
6891
- order: ["runFences"]
6892
- }),
6904
+ targets,
6893
6905
  options,
6894
6906
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
6895
6907
  deleteBatch: (target, cutoff, limit) => this.db.pruneRunRows({
@@ -8561,18 +8573,19 @@ function combineWhere(nameValue, filterClause, filterParams, filterTypes, nextIn
8561
8573
  const params = { ...filterParams };
8562
8574
  const types = { ...filterTypes };
8563
8575
  const conditions = [];
8564
- if (Array.isArray(nameValue)) if (nameValue.length === 0) conditions.push("1 = 0");
8565
- else {
8566
- const placeholders = [];
8567
- let i = nextIndex;
8568
- for (const n of nameValue) {
8569
- const param = `n${i++}`;
8570
- placeholders.push(`@${param}`);
8571
- params[param] = n;
8576
+ if (Array.isArray(nameValue)) {
8577
+ if (nameValue.length === 0) conditions.push("1 = 0");
8578
+ else {
8579
+ const placeholders = [];
8580
+ let i = nextIndex;
8581
+ for (const n of nameValue) {
8582
+ const param = `n${i++}`;
8583
+ placeholders.push(`@${param}`);
8584
+ params[param] = n;
8585
+ }
8586
+ conditions.push(`${quoteIdent("name", "column name")} IN (${placeholders.join(", ")})`);
8572
8587
  }
8573
- conditions.push(`${quoteIdent("name", "column name")} IN (${placeholders.join(", ")})`);
8574
- }
8575
- else {
8588
+ } else {
8576
8589
  const param = `n${nextIndex}`;
8577
8590
  params[param] = nameValue;
8578
8591
  conditions.push(`${quoteIdent("name", "column name")} = @${param}`);
@@ -8791,7 +8804,6 @@ async function getMetricAggregate(database, args, options) {
8791
8804
  default:
8792
8805
  prevStart = new Date(ts.start.getTime() - duration);
8793
8806
  prevEnd = new Date(ts.end.getTime() - duration);
8794
- break;
8795
8807
  }
8796
8808
  const prevFilterResult = buildWhereClause({
8797
8809
  ...args.filters,
@@ -9209,17 +9221,19 @@ var ObservabilitySpanner = class ObservabilitySpanner extends _mastra_core_stora
9209
9221
  return this.disableMetrics ? [] : ["metrics", "metric-discovery"];
9210
9222
  }
9211
9223
  async prune(policies, options) {
9224
+ const descriptor = this.disableMetrics ? { spans: {
9225
+ table: _mastra_core_storage.TABLE_SPANS,
9226
+ column: "startedAt",
9227
+ indexed: false
9228
+ } } : ObservabilitySpanner.retentionTables;
9229
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
9230
+ policies,
9231
+ descriptor,
9232
+ order: ["spans", "metrics"]
9233
+ });
9212
9234
  return (0, _mastra_core_storage.executeRetentionPrune)({
9213
9235
  domain: "observability",
9214
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
9215
- policies,
9216
- descriptor: this.disableMetrics ? { spans: {
9217
- table: _mastra_core_storage.TABLE_SPANS,
9218
- column: "startedAt",
9219
- indexed: false
9220
- } } : ObservabilitySpanner.retentionTables,
9221
- order: ["spans", "metrics"]
9222
- }),
9236
+ targets,
9223
9237
  options,
9224
9238
  cutoffFor: (target, now) => new Date((0, _mastra_core_storage.retentionCutoffMs)(target.policy, now)).toISOString(),
9225
9239
  deleteBatch: async (target, cutoff, limit) => {
@@ -9619,9 +9633,7 @@ var ObservabilitySpanner = class ObservabilitySpanner extends _mastra_core_stora
9619
9633
  case _mastra_core_storage.TraceStatus.RUNNING:
9620
9634
  conditions.push(`${rAlias}.${quoteIdent("endedAt", "column name")} IS NULL AND ${rAlias}.${quoteIdent("error", "column name")} IS NULL`);
9621
9635
  break;
9622
- case _mastra_core_storage.TraceStatus.SUCCESS:
9623
- conditions.push(`${rAlias}.${quoteIdent("endedAt", "column name")} IS NOT NULL AND ${rAlias}.${quoteIdent("error", "column name")} IS NULL`);
9624
- break;
9636
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`${rAlias}.${quoteIdent("endedAt", "column name")} IS NOT NULL AND ${rAlias}.${quoteIdent("error", "column name")} IS NULL`);
9625
9637
  }
9626
9638
  if (filters.hasChildError !== void 0) {
9627
9639
  const existsClause = `EXISTS (SELECT 1 FROM ${tableName} c WHERE c.${quoteIdent("traceId", "column name")} = ${rAlias}.${quoteIdent("traceId", "column name")} AND c.${quoteIdent("error", "column name")} IS NOT NULL)`;
@@ -10592,15 +10604,19 @@ var SchedulesSpanner = class SchedulesSpanner extends _mastra_core_storage.Sched
10592
10604
  else conditions.push(`JSON_VALUE(${quoteIdent("target", "column name")}, '$.workflowId') = @workflowId`);
10593
10605
  params.workflowId = filter.workflowId;
10594
10606
  }
10595
- if (filter?.ownerType !== void 0) if (filter.ownerType === null) conditions.push(`${quoteIdent("owner_type", "column name")} IS NULL`);
10596
- else {
10597
- conditions.push(`${quoteIdent("owner_type", "column name")} = @ownerType`);
10598
- params.ownerType = filter.ownerType;
10607
+ if (filter?.ownerType !== void 0) {
10608
+ if (filter.ownerType === null) conditions.push(`${quoteIdent("owner_type", "column name")} IS NULL`);
10609
+ else {
10610
+ conditions.push(`${quoteIdent("owner_type", "column name")} = @ownerType`);
10611
+ params.ownerType = filter.ownerType;
10612
+ }
10599
10613
  }
10600
- if (filter?.ownerId !== void 0) if (filter.ownerId === null) conditions.push(`${quoteIdent("owner_id", "column name")} IS NULL`);
10601
- else {
10602
- conditions.push(`${quoteIdent("owner_id", "column name")} = @ownerId`);
10603
- params.ownerId = filter.ownerId;
10614
+ if (filter?.ownerId !== void 0) {
10615
+ if (filter.ownerId === null) conditions.push(`${quoteIdent("owner_id", "column name")} IS NULL`);
10616
+ else {
10617
+ conditions.push(`${quoteIdent("owner_id", "column name")} = @ownerId`);
10618
+ params.ownerId = filter.ownerId;
10619
+ }
10604
10620
  }
10605
10621
  const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
10606
10622
  const sql = `SELECT * FROM ${quoteIdent(_mastra_core_storage.TABLE_SCHEDULES, "table name")}
@@ -11448,10 +11464,11 @@ var ScorerDefinitionsSpanner = class ScorerDefinitionsSpanner extends _mastra_co
11448
11464
  //#endregion
11449
11465
  //#region src/storage/domains/scores/index.ts
11450
11466
  function transformScoreRow(row) {
11451
- return (0, _mastra_core_storage.transformScoreRow)(transformFromSpannerRow({
11467
+ const normalized = transformFromSpannerRow({
11452
11468
  tableName: _mastra_core_storage.TABLE_SCORERS,
11453
11469
  row
11454
- }), { convertTimestamps: true });
11470
+ });
11471
+ return (0, _mastra_core_storage.transformScoreRow)(normalized, { convertTimestamps: true });
11455
11472
  }
11456
11473
  /** Appends multi-tenant scope conditions and their named params. */
11457
11474
  function applyTenancyFilters(conditions, params, filters) {
@@ -12703,13 +12720,14 @@ var WorkflowsSpanner = class WorkflowsSpanner extends _mastra_core_storage.Workf
12703
12720
  }
12704
12721
  /** Removes every workflow snapshot and run ownership row. Intended for tests. */
12705
12722
  async prune(policies, options) {
12723
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
12724
+ policies,
12725
+ descriptor: WorkflowsSpanner.retentionTables,
12726
+ order: ["runOwnership"]
12727
+ });
12706
12728
  return (0, _mastra_core_storage.executeRetentionPrune)({
12707
12729
  domain: "workflows",
12708
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
12709
- policies,
12710
- descriptor: WorkflowsSpanner.retentionTables,
12711
- order: ["runOwnership"]
12712
- }),
12730
+ targets,
12713
12731
  options,
12714
12732
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
12715
12733
  deleteBatch: (target, cutoff, limit) => this.db.pruneRunRows({