@mastra/mysql 0.10.2 → 0.11.0-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/index.js CHANGED
@@ -1406,7 +1406,9 @@ function rowToTask(row) {
1406
1406
  createdAt: parseDateTime(row.createdAt),
1407
1407
  startedAt: parseDateTime(row.startedAt),
1408
1408
  suspendedAt: parseDateTime(row.suspendedAt),
1409
- completedAt: parseDateTime(row.completedAt)
1409
+ completedAt: parseDateTime(row.completedAt),
1410
+ ownerId: row.ownerId != null ? String(row.ownerId) : void 0,
1411
+ leaseExpiresAt: parseDateTime(row.leaseExpiresAt)
1410
1412
  };
1411
1413
  }
1412
1414
  var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksStorage {
@@ -1427,6 +1429,16 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1427
1429
  tableName: TABLE_BACKGROUND_TASKS,
1428
1430
  schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS]
1429
1431
  });
1432
+ await this.operations.alterTable({
1433
+ tableName: TABLE_BACKGROUND_TASKS,
1434
+ schema: TABLE_SCHEMAS[TABLE_BACKGROUND_TASKS],
1435
+ ifNotExists: [
1436
+ "suspend_payload",
1437
+ "suspendedAt",
1438
+ "ownerId",
1439
+ "leaseExpiresAt"
1440
+ ]
1441
+ });
1430
1442
  await this.createDefaultIndexes();
1431
1443
  await this.createCustomIndexes();
1432
1444
  }
@@ -1478,7 +1490,7 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1478
1490
  await this.operations.clearTable({ tableName: TABLE_BACKGROUND_TASKS });
1479
1491
  }
1480
1492
  async createTask(task) {
1481
- await this.pool.execute(`INSERT INTO ${formatTableName(TABLE_BACKGROUND_TASKS)} (${quoteIdentifier("id", "column name")}, ${quoteIdentifier("tool_call_id", "column name")}, ${quoteIdentifier("tool_name", "column name")}, ${quoteIdentifier("agent_id", "column name")}, ${quoteIdentifier("thread_id", "column name")}, ${quoteIdentifier("resource_id", "column name")}, ${quoteIdentifier("run_id", "column name")}, ${quoteIdentifier("status", "column name")}, ${quoteIdentifier("args", "column name")}, ${quoteIdentifier("result", "column name")}, ${quoteIdentifier("error", "column name")}, ${quoteIdentifier("suspend_payload", "column name")}, ${quoteIdentifier("retry_count", "column name")}, ${quoteIdentifier("max_retries", "column name")}, ${quoteIdentifier("timeout_ms", "column name")}, ${quoteIdentifier("createdAt", "column name")}, ${quoteIdentifier("startedAt", "column name")}, ${quoteIdentifier("suspendedAt", "column name")}, ${quoteIdentifier("completedAt", "column name")}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
1493
+ await this.pool.execute(`INSERT INTO ${formatTableName(TABLE_BACKGROUND_TASKS)} (${quoteIdentifier("id", "column name")}, ${quoteIdentifier("tool_call_id", "column name")}, ${quoteIdentifier("tool_name", "column name")}, ${quoteIdentifier("agent_id", "column name")}, ${quoteIdentifier("thread_id", "column name")}, ${quoteIdentifier("resource_id", "column name")}, ${quoteIdentifier("run_id", "column name")}, ${quoteIdentifier("status", "column name")}, ${quoteIdentifier("args", "column name")}, ${quoteIdentifier("result", "column name")}, ${quoteIdentifier("error", "column name")}, ${quoteIdentifier("suspend_payload", "column name")}, ${quoteIdentifier("retry_count", "column name")}, ${quoteIdentifier("max_retries", "column name")}, ${quoteIdentifier("timeout_ms", "column name")}, ${quoteIdentifier("createdAt", "column name")}, ${quoteIdentifier("startedAt", "column name")}, ${quoteIdentifier("suspendedAt", "column name")}, ${quoteIdentifier("completedAt", "column name")}, ${quoteIdentifier("ownerId", "column name")}, ${quoteIdentifier("leaseExpiresAt", "column name")}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
1482
1494
  task.id,
1483
1495
  task.toolCallId,
1484
1496
  task.toolName,
@@ -1497,7 +1509,9 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1497
1509
  transformToSqlValue(task.createdAt),
1498
1510
  transformToSqlValue(task.startedAt),
1499
1511
  transformToSqlValue(task.suspendedAt),
1500
- transformToSqlValue(task.completedAt)
1512
+ transformToSqlValue(task.completedAt),
1513
+ task.ownerId ?? null,
1514
+ transformToSqlValue(task.leaseExpiresAt)
1501
1515
  ]);
1502
1516
  }
1503
1517
  async updateTask(taskId, update, options) {
@@ -1535,11 +1549,33 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1535
1549
  setClauses.push(`${quoteIdentifier("completedAt", "column name")} = ?`);
1536
1550
  params.push(transformToSqlValue(update.completedAt));
1537
1551
  }
1552
+ if ("ownerId" in update) {
1553
+ setClauses.push(`${quoteIdentifier("ownerId", "column name")} = ?`);
1554
+ params.push(update.ownerId ?? null);
1555
+ }
1556
+ if ("leaseExpiresAt" in update) {
1557
+ setClauses.push(`${quoteIdentifier("leaseExpiresAt", "column name")} = ?`);
1558
+ params.push(transformToSqlValue(update.leaseExpiresAt));
1559
+ }
1538
1560
  if (setClauses.length === 0) return false;
1539
1561
  params.push(taskId);
1540
- const statusPredicate = options?.expectedStatus ? ` AND ${quoteIdentifier("status", "column name")} = ?` : "";
1541
- if (options?.expectedStatus) params.push(options.expectedStatus);
1542
- const [result] = await this.pool.execute(`UPDATE ${formatTableName(TABLE_BACKGROUND_TASKS)} SET ${setClauses.join(", ")} WHERE ${quoteIdentifier("id", "column name")} = ?${statusPredicate}`, params);
1562
+ const predicates = [];
1563
+ if (options?.expectedStatus) {
1564
+ predicates.push(`${quoteIdentifier("status", "column name")} = ?`);
1565
+ params.push(options.expectedStatus);
1566
+ }
1567
+ if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) predicates.push(`${quoteIdentifier("ownerId", "column name")} IS NULL`);
1568
+ else {
1569
+ predicates.push(`${quoteIdentifier("ownerId", "column name")} = ?`);
1570
+ params.push(options.expectedOwnerId);
1571
+ }
1572
+ if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} IS NULL`);
1573
+ else {
1574
+ predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} = ?`);
1575
+ params.push(transformToSqlValue(options.expectedLeaseExpiresAt));
1576
+ }
1577
+ const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
1578
+ const [result] = await this.pool.execute(`UPDATE ${formatTableName(TABLE_BACKGROUND_TASKS)} SET ${setClauses.join(", ")} WHERE ${quoteIdentifier("id", "column name")} = ?${predicateSql}`, params);
1543
1579
  return result.affectedRows > 0;
1544
1580
  }
1545
1581
  async getTask(taskId) {