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