@mastra/mysql 0.8.8-alpha.0 → 0.9.0-alpha.1

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.8-alpha.0"
6
+ version: "0.9.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.8.8-alpha.0",
2
+ "version": "0.9.0-alpha.1",
3
3
  "package": "@mastra/mysql",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -6375,6 +6375,62 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
6375
6375
  }, error);
6376
6376
  }
6377
6377
  }
6378
+ /**
6379
+ * Atomically reassign a thread and all of its messages to a different resource.
6380
+ *
6381
+ * Runs inside a single transaction and takes a `SELECT ... FOR UPDATE` row lock on the
6382
+ * thread, so overlapping transfers of the same thread serialize and can never interleave
6383
+ * the thread update with the message update. Either both the thread and every message move
6384
+ * to the new resource, or neither does — there is no split-ownership window. The thread's
6385
+ * `createdAt` is preserved. Callers are responsible for authorizing the reassignment.
6386
+ */
6387
+ async updateThreadResourceId({ threadId, resourceId }) {
6388
+ const connection = await this.pool.getConnection();
6389
+ try {
6390
+ await connection.beginTransaction();
6391
+ const [rows] = await connection.execute(`SELECT * FROM ${formatTableName(_mastra_core_storage.TABLE_THREADS)} WHERE ${quoteIdentifier("id", "column name")} = ? FOR UPDATE`, [threadId]);
6392
+ const row = rows[0];
6393
+ if (!row) throw new _mastra_core_error.MastraError({
6394
+ id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "UPDATE_THREAD_RESOURCE_ID", "NOT_FOUND"),
6395
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
6396
+ category: _mastra_core_error.ErrorCategory.USER,
6397
+ text: `Thread "${threadId}" not found`,
6398
+ details: { threadId }
6399
+ });
6400
+ const thread = this.mapThread(row);
6401
+ if (thread.resourceId === resourceId) {
6402
+ await connection.commit();
6403
+ return thread;
6404
+ }
6405
+ const updatedAt = /* @__PURE__ */ new Date();
6406
+ await connection.execute(`UPDATE ${formatTableName(_mastra_core_storage.TABLE_THREADS)} SET ${quoteIdentifier("resourceId", "column name")} = ?, ${quoteIdentifier("updatedAt", "column name")} = ? WHERE ${quoteIdentifier("id", "column name")} = ?`, [
6407
+ resourceId,
6408
+ transformToSqlValue(updatedAt),
6409
+ threadId
6410
+ ]);
6411
+ await connection.execute(`UPDATE ${formatTableName(_mastra_core_storage.TABLE_MESSAGES)} SET ${quoteIdentifier("resourceId", "column name")} = ? WHERE ${quoteIdentifier("thread_id", "column name")} = ?`, [resourceId, threadId]);
6412
+ await connection.commit();
6413
+ return {
6414
+ ...thread,
6415
+ resourceId,
6416
+ updatedAt
6417
+ };
6418
+ } catch (error) {
6419
+ await connection.rollback();
6420
+ if (error instanceof _mastra_core_error.MastraError) throw error;
6421
+ throw new _mastra_core_error.MastraError({
6422
+ id: (0, _mastra_core_storage.createStorageErrorId)("MYSQL", "UPDATE_THREAD_RESOURCE_ID", "FAILED"),
6423
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
6424
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
6425
+ details: {
6426
+ threadId,
6427
+ resourceId
6428
+ }
6429
+ }, error);
6430
+ } finally {
6431
+ connection.release();
6432
+ }
6433
+ }
6378
6434
  async listThreads(args) {
6379
6435
  const { page = 0, perPage: perPageInput, orderBy, filter } = args;
6380
6436
  const { field, direction } = this.parseOrderBy(orderBy, "DESC");