@mastra/spanner 1.6.6-alpha.0 → 1.6.7-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.6.6-alpha.0"
6
+ version: "1.6.7-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.6-alpha.0",
2
+ "version": "1.6.7-alpha.0",
3
3
  "package": "@mastra/spanner",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -3326,8 +3326,8 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3326
3326
  });
3327
3327
  }
3328
3328
  /** Reads the current live row for an item (validTo IS NULL, not deleted). */
3329
- async loadCurrentItemRow(itemId) {
3330
- const [rows] = await this.database.run({
3329
+ async loadCurrentItemRow(tx, itemId) {
3330
+ const [rows] = await tx.run({
3331
3331
  sql: `SELECT * FROM ${quoteIdent(_mastra_core_storage.TABLE_DATASET_ITEMS, "table name")}
3332
3332
  WHERE ${quoteIdent("id", "column name")} = @id
3333
3333
  AND ${quoteIdent("validTo", "column name")} IS NULL
@@ -3410,39 +3410,49 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3410
3410
  }
3411
3411
  async _doUpdateItem(args) {
3412
3412
  try {
3413
- const existing = await this.loadCurrentItemRow(args.id);
3414
- if (!existing) throw new _mastra_core_error.MastraError({
3415
- id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "UPDATE_DATASET_ITEM", "NOT_FOUND"),
3416
- domain: _mastra_core_error.ErrorDomain.STORAGE,
3417
- category: _mastra_core_error.ErrorCategory.USER,
3418
- text: `Dataset item not found: ${args.id}`,
3419
- details: { id: args.id }
3420
- });
3421
- if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
3422
- id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "UPDATE_DATASET_ITEM", "DATASET_MISMATCH"),
3423
- domain: _mastra_core_error.ErrorDomain.STORAGE,
3424
- category: _mastra_core_error.ErrorCategory.USER,
3425
- text: `Dataset item ${args.id} does not belong to dataset ${args.datasetId}`,
3426
- details: {
3427
- id: args.id,
3428
- datasetId: args.datasetId
3429
- }
3430
- });
3431
- const merged = {
3432
- input: args.input !== void 0 ? args.input : existing.input,
3433
- groundTruth: args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth,
3434
- expectedTrajectory: args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory,
3435
- toolMocks: args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks,
3436
- unmockedToolPolicy: args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy,
3437
- scorerIds: args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds,
3438
- requestContext: args.requestContext !== void 0 ? args.requestContext : existing.requestContext,
3439
- metadata: args.metadata !== void 0 ? args.metadata : existing.metadata,
3440
- source: args.source !== void 0 ? args.source : existing.source
3441
- };
3442
3413
  const now = /* @__PURE__ */ new Date();
3443
3414
  let updated = null;
3444
3415
  await this.db.runWithAbortRetry(() => this.database.runTransactionAsync(async (tx) => {
3445
3416
  try {
3417
+ const existing = await this.loadCurrentItemRow(tx, args.id);
3418
+ if (!existing) throw new _mastra_core_error.MastraError({
3419
+ id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "UPDATE_DATASET_ITEM", "NOT_FOUND"),
3420
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
3421
+ category: _mastra_core_error.ErrorCategory.USER,
3422
+ text: `Dataset item not found: ${args.id}`,
3423
+ details: { id: args.id }
3424
+ });
3425
+ if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
3426
+ id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "UPDATE_DATASET_ITEM", "DATASET_MISMATCH"),
3427
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
3428
+ category: _mastra_core_error.ErrorCategory.USER,
3429
+ text: `Dataset item ${args.id} does not belong to dataset ${args.datasetId}`,
3430
+ details: {
3431
+ id: args.id,
3432
+ datasetId: args.datasetId
3433
+ }
3434
+ });
3435
+ if (existing.metadata?.__purged === true) throw new _mastra_core_error.MastraError({
3436
+ id: "DATASET_ITEM_PURGED",
3437
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
3438
+ category: _mastra_core_error.ErrorCategory.USER,
3439
+ details: {
3440
+ datasetId: args.datasetId,
3441
+ itemId: args.id
3442
+ },
3443
+ text: `Purged dataset item cannot be updated: ${args.id}`
3444
+ });
3445
+ const merged = {
3446
+ input: args.input !== void 0 ? args.input : existing.input,
3447
+ groundTruth: args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth,
3448
+ expectedTrajectory: args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory,
3449
+ toolMocks: args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks,
3450
+ unmockedToolPolicy: args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy,
3451
+ scorerIds: args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds,
3452
+ requestContext: args.requestContext !== void 0 ? args.requestContext : existing.requestContext,
3453
+ metadata: args.metadata !== void 0 ? args.metadata : existing.metadata,
3454
+ source: args.source !== void 0 ? args.source : existing.source
3455
+ };
3446
3456
  const { version: newVersion, organizationId, projectId } = await this.bumpVersion(tx, args.datasetId, now);
3447
3457
  await this.closeCurrentRow(tx, args.id, newVersion);
3448
3458
  await this.db.insert({
@@ -3511,21 +3521,24 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3511
3521
  }
3512
3522
  async _doDeleteItem(args) {
3513
3523
  try {
3514
- const existing = await this.loadCurrentItemRow(args.id);
3515
- if (!existing) return;
3516
- if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
3517
- id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "DELETE_DATASET_ITEM", "DATASET_MISMATCH"),
3518
- domain: _mastra_core_error.ErrorDomain.STORAGE,
3519
- category: _mastra_core_error.ErrorCategory.USER,
3520
- text: `Dataset item ${args.id} does not belong to dataset ${args.datasetId}`,
3521
- details: {
3522
- id: args.id,
3523
- datasetId: args.datasetId
3524
- }
3525
- });
3526
3524
  const now = /* @__PURE__ */ new Date();
3527
3525
  await this.db.runWithAbortRetry(() => this.database.runTransactionAsync(async (tx) => {
3528
3526
  try {
3527
+ const existing = await this.loadCurrentItemRow(tx, args.id);
3528
+ if (!existing) {
3529
+ await tx.commit();
3530
+ return;
3531
+ }
3532
+ if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
3533
+ id: (0, _mastra_core_storage.createStorageErrorId)("SPANNER", "DELETE_DATASET_ITEM", "DATASET_MISMATCH"),
3534
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
3535
+ category: _mastra_core_error.ErrorCategory.USER,
3536
+ text: `Dataset item ${args.id} does not belong to dataset ${args.datasetId}`,
3537
+ details: {
3538
+ id: args.id,
3539
+ datasetId: args.datasetId
3540
+ }
3541
+ });
3529
3542
  const { version: newVersion, organizationId, projectId } = await this.bumpVersion(tx, args.datasetId, now);
3530
3543
  await this.closeCurrentRow(tx, args.id, newVersion);
3531
3544
  await this.db.insert({
@@ -3992,15 +4005,18 @@ var DatasetsSpanner = class DatasetsSpanner extends _mastra_core_storage.Dataset
3992
4005
  }
3993
4006
  async _doBatchDeleteItems(input) {
3994
4007
  try {
3995
- const current = [];
3996
- for (const itemId of input.itemIds) {
3997
- const row = await this.loadCurrentItemRow(itemId);
3998
- if (row && row.datasetId === input.datasetId) current.push(row);
3999
- }
4000
- if (current.length === 0) return;
4001
4008
  const now = /* @__PURE__ */ new Date();
4002
4009
  await this.db.runWithAbortRetry(() => this.database.runTransactionAsync(async (tx) => {
4003
4010
  try {
4011
+ const current = [];
4012
+ for (const itemId of input.itemIds) {
4013
+ const row = await this.loadCurrentItemRow(tx, itemId);
4014
+ if (row && row.datasetId === input.datasetId) current.push(row);
4015
+ }
4016
+ if (current.length === 0) {
4017
+ await tx.commit();
4018
+ return;
4019
+ }
4004
4020
  const { version: newVersion, organizationId, projectId } = await this.bumpVersion(tx, input.datasetId, now);
4005
4021
  for (const existing of current) {
4006
4022
  await this.closeCurrentRow(tx, existing.id, newVersion);