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