@mastra/mysql 0.8.7-alpha.0 → 0.8.8-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-mysql
3
3
  description: Documentation for @mastra/mysql. Use when working with @mastra/mysql APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mysql"
6
- version: "0.8.7-alpha.0"
6
+ version: "0.8.8-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.8.7-alpha.0",
2
+ "version": "0.8.8-alpha.0",
3
3
  "package": "@mastra/mysql",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -2415,23 +2415,6 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2415
2415
  }
2416
2416
  async _doUpdateItem(args) {
2417
2417
  this.#rejectToolMocks(args.toolMocks);
2418
- const existing = await this.getItemById({ id: args.id });
2419
- if (!existing) throw new _mastra_core_error.MastraError({
2420
- id: "MYSQL_UPDATE_ITEM_NOT_FOUND",
2421
- domain: _mastra_core_error.ErrorDomain.STORAGE,
2422
- category: _mastra_core_error.ErrorCategory.USER,
2423
- details: { itemId: args.id }
2424
- });
2425
- if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
2426
- id: "MYSQL_UPDATE_ITEM_DATASET_MISMATCH",
2427
- domain: _mastra_core_error.ErrorDomain.STORAGE,
2428
- category: _mastra_core_error.ErrorCategory.USER,
2429
- details: {
2430
- itemId: args.id,
2431
- expectedDatasetId: args.datasetId,
2432
- actualDatasetId: existing.datasetId
2433
- }
2434
- });
2435
2418
  const connection = await this.pool.getConnection();
2436
2419
  try {
2437
2420
  await connection.beginTransaction();
@@ -2440,6 +2423,36 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2440
2423
  const tableDatasetsName = formatTableName(_mastra_core_storage.TABLE_DATASETS);
2441
2424
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2442
2425
  const tableVersionsName = formatTableName(_mastra_core_storage.TABLE_DATASET_VERSIONS);
2426
+ await connection.execute(`SELECT id FROM ${tableDatasetsName} WHERE id = ? FOR UPDATE`, [args.datasetId]);
2427
+ const [itemRows] = await connection.execute(`SELECT * FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [args.id]);
2428
+ const itemRow = itemRows[0];
2429
+ const existing = itemRow ? this.mapItem(itemRow) : null;
2430
+ if (!existing) throw new _mastra_core_error.MastraError({
2431
+ id: "MYSQL_UPDATE_ITEM_NOT_FOUND",
2432
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
2433
+ category: _mastra_core_error.ErrorCategory.USER,
2434
+ details: { itemId: args.id }
2435
+ });
2436
+ if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
2437
+ id: "MYSQL_UPDATE_ITEM_DATASET_MISMATCH",
2438
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
2439
+ category: _mastra_core_error.ErrorCategory.USER,
2440
+ details: {
2441
+ itemId: args.id,
2442
+ expectedDatasetId: args.datasetId,
2443
+ actualDatasetId: existing.datasetId
2444
+ }
2445
+ });
2446
+ if (existing.metadata?.__purged === true) throw new _mastra_core_error.MastraError({
2447
+ id: "DATASET_ITEM_PURGED",
2448
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
2449
+ category: _mastra_core_error.ErrorCategory.USER,
2450
+ details: {
2451
+ datasetId: args.datasetId,
2452
+ itemId: args.id
2453
+ },
2454
+ text: `Purged dataset item cannot be updated: ${args.id}`
2455
+ });
2443
2456
  const mergedInput = args.input ?? existing.input;
2444
2457
  const mergedGroundTruth = args.groundTruth ?? existing.groundTruth;
2445
2458
  const mergedExpectedTrajectory = args.expectedTrajectory ?? existing.expectedTrajectory;
@@ -2511,18 +2524,6 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2511
2524
  }
2512
2525
  }
2513
2526
  async _doDeleteItem({ id, datasetId }) {
2514
- const existing = await this.getItemById({ id });
2515
- if (!existing) return;
2516
- if (existing.datasetId !== datasetId) throw new _mastra_core_error.MastraError({
2517
- id: "MYSQL_DELETE_ITEM_DATASET_MISMATCH",
2518
- domain: _mastra_core_error.ErrorDomain.STORAGE,
2519
- category: _mastra_core_error.ErrorCategory.USER,
2520
- details: {
2521
- itemId: id,
2522
- expectedDatasetId: datasetId,
2523
- actualDatasetId: existing.datasetId
2524
- }
2525
- });
2526
2527
  const connection = await this.pool.getConnection();
2527
2528
  try {
2528
2529
  await connection.beginTransaction();
@@ -2531,6 +2532,24 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2531
2532
  const tableDatasetsName = formatTableName(_mastra_core_storage.TABLE_DATASETS);
2532
2533
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2533
2534
  const tableVersionsName = formatTableName(_mastra_core_storage.TABLE_DATASET_VERSIONS);
2535
+ await connection.execute(`SELECT id FROM ${tableDatasetsName} WHERE id = ? FOR UPDATE`, [datasetId]);
2536
+ const [itemRows] = await connection.execute(`SELECT * FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [id]);
2537
+ const itemRow = itemRows[0];
2538
+ const existing = itemRow ? this.mapItem(itemRow) : null;
2539
+ if (!existing) {
2540
+ await connection.commit();
2541
+ return;
2542
+ }
2543
+ if (existing.datasetId !== datasetId) throw new _mastra_core_error.MastraError({
2544
+ id: "MYSQL_DELETE_ITEM_DATASET_MISMATCH",
2545
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
2546
+ category: _mastra_core_error.ErrorCategory.USER,
2547
+ details: {
2548
+ itemId: id,
2549
+ expectedDatasetId: datasetId,
2550
+ actualDatasetId: existing.datasetId
2551
+ }
2552
+ });
2534
2553
  await connection.execute(`UPDATE ${tableDatasetsName} SET \`version\` = \`version\` + 1 WHERE id = ?`, [datasetId]);
2535
2554
  const [datasetRows] = await connection.execute(`SELECT \`version\`, \`organizationId\`, \`projectId\` FROM ${tableDatasetsName} WHERE id = ?`, [datasetId]);
2536
2555
  const parentRow = datasetRows[0];
@@ -2899,12 +2918,6 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2899
2918
  category: _mastra_core_error.ErrorCategory.USER,
2900
2919
  details: { datasetId: input.datasetId }
2901
2920
  });
2902
- const currentItems = [];
2903
- for (const itemId of input.itemIds) {
2904
- const item = await this.getItemById({ id: itemId });
2905
- if (item && item.datasetId === input.datasetId) currentItems.push(item);
2906
- }
2907
- if (currentItems.length === 0) return;
2908
2921
  const connection = await this.pool.getConnection();
2909
2922
  try {
2910
2923
  await connection.beginTransaction();
@@ -2913,6 +2926,18 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2913
2926
  const tableDatasetsName = formatTableName(_mastra_core_storage.TABLE_DATASETS);
2914
2927
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2915
2928
  const tableVersionsName = formatTableName(_mastra_core_storage.TABLE_DATASET_VERSIONS);
2929
+ await connection.execute(`SELECT id FROM ${tableDatasetsName} WHERE id = ? FOR UPDATE`, [input.datasetId]);
2930
+ const currentItems = [];
2931
+ for (const itemId of input.itemIds) {
2932
+ const [itemRows] = await connection.execute(`SELECT * FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [itemId]);
2933
+ const row = itemRows[0];
2934
+ const item = row ? this.mapItem(row) : null;
2935
+ if (item && item.datasetId === input.datasetId) currentItems.push(item);
2936
+ }
2937
+ if (currentItems.length === 0) {
2938
+ await connection.commit();
2939
+ return;
2940
+ }
2916
2941
  await connection.execute(`UPDATE ${tableDatasetsName} SET \`version\` = \`version\` + 1 WHERE id = ?`, [input.datasetId]);
2917
2942
  const [versionRows] = await connection.execute(`SELECT \`version\` FROM ${tableDatasetsName} WHERE id = ?`, [input.datasetId]);
2918
2943
  const newVersion = versionRows[0]?.version;