@mastra/mysql 0.14.1 → 0.15.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,10 +1406,13 @@ function rowToTask(row) {
1406
1406
  suspendedAt: parseDateTime(row.suspendedAt),
1407
1407
  completedAt: parseDateTime(row.completedAt),
1408
1408
  ownerId: row.ownerId != null ? String(row.ownerId) : void 0,
1409
- leaseExpiresAt: parseDateTime(row.leaseExpiresAt)
1409
+ leaseExpiresAt: parseDateTime(row.leaseExpiresAt),
1410
+ expiresAt: parseDateTime(row.expiresAt),
1411
+ metadata: parseJson$2(row.metadata)
1410
1412
  };
1411
1413
  }
1412
1414
  var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksStorage {
1415
+ supportsTaskExpiry = true;
1413
1416
  pool;
1414
1417
  operations;
1415
1418
  #skipDefaultIndexes;
@@ -1434,7 +1437,9 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1434
1437
  "suspend_payload",
1435
1438
  "suspendedAt",
1436
1439
  "ownerId",
1437
- "leaseExpiresAt"
1440
+ "leaseExpiresAt",
1441
+ "expiresAt",
1442
+ "metadata"
1438
1443
  ]
1439
1444
  });
1440
1445
  await this.createDefaultIndexes();
@@ -1488,7 +1493,7 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1488
1493
  await this.operations.clearTable({ tableName: TABLE_BACKGROUND_TASKS });
1489
1494
  }
1490
1495
  async createTask(task) {
1491
- 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
1496
+ 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")}, ${quoteIdentifier("expiresAt", "column name")}, ${quoteIdentifier("metadata", "column name")}) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
1492
1497
  task.id,
1493
1498
  task.toolCallId,
1494
1499
  task.toolName,
@@ -1509,7 +1514,9 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1509
1514
  transformToSqlValue(task.suspendedAt),
1510
1515
  transformToSqlValue(task.completedAt),
1511
1516
  task.ownerId ?? null,
1512
- transformToSqlValue(task.leaseExpiresAt)
1517
+ transformToSqlValue(task.leaseExpiresAt),
1518
+ transformToSqlValue(task.expiresAt),
1519
+ task.metadata ? JSON.stringify(task.metadata) : null
1513
1520
  ]);
1514
1521
  }
1515
1522
  async updateTask(taskId, update, options) {
@@ -1555,6 +1562,14 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1555
1562
  setClauses.push(`${quoteIdentifier("leaseExpiresAt", "column name")} = ?`);
1556
1563
  params.push(transformToSqlValue(update.leaseExpiresAt));
1557
1564
  }
1565
+ if ("expiresAt" in update) {
1566
+ setClauses.push(`${quoteIdentifier("expiresAt", "column name")} = ?`);
1567
+ params.push(transformToSqlValue(update.expiresAt));
1568
+ }
1569
+ if ("metadata" in update) {
1570
+ setClauses.push(`${quoteIdentifier("metadata", "column name")} = ?`);
1571
+ params.push(serializeJson(update.metadata));
1572
+ }
1558
1573
  if (setClauses.length === 0) return false;
1559
1574
  params.push(taskId);
1560
1575
  const predicates = [];
@@ -1576,6 +1591,13 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1576
1591
  params.push(transformToSqlValue(options.expectedLeaseExpiresAt));
1577
1592
  }
1578
1593
  }
1594
+ if (options?.expectedSuspendedAt !== void 0) {
1595
+ if (options.expectedSuspendedAt === null) predicates.push(`${quoteIdentifier("suspendedAt", "column name")} IS NULL`);
1596
+ else {
1597
+ predicates.push(`${quoteIdentifier("suspendedAt", "column name")} = ?`);
1598
+ params.push(transformToSqlValue(options.expectedSuspendedAt));
1599
+ }
1600
+ }
1579
1601
  const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
1580
1602
  const [result] = await this.pool.execute(`UPDATE ${formatTableName(TABLE_BACKGROUND_TASKS)} SET ${setClauses.join(", ")} WHERE ${quoteIdentifier("id", "column name")} = ?${predicateSql}`, params);
1581
1603
  return result.affectedRows > 0;
@@ -1618,7 +1640,8 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1618
1640
  conditions.push(`${quoteIdentifier("tool_call_id", "column name")} = ?`);
1619
1641
  params.push(filter.toolCallId);
1620
1642
  }
1621
- const dateCol = filter.dateFilterBy === "startedAt" ? quoteIdentifier("startedAt", "column name") : filter.dateFilterBy === "suspendedAt" ? quoteIdentifier("suspendedAt", "column name") : filter.dateFilterBy === "completedAt" ? quoteIdentifier("completedAt", "column name") : quoteIdentifier("createdAt", "column name");
1643
+ const dateCol = filter.dateFilterBy === "startedAt" ? quoteIdentifier("startedAt", "column name") : filter.dateFilterBy === "suspendedAt" ? quoteIdentifier("suspendedAt", "column name") : filter.dateFilterBy === "completedAt" ? quoteIdentifier("completedAt", "column name") : filter.dateFilterBy === "expiresAt" ? quoteIdentifier("expiresAt", "column name") : quoteIdentifier("createdAt", "column name");
1644
+ if (filter.hasExpiresAt !== void 0) conditions.push(`${quoteIdentifier("expiresAt", "column name")} IS ${filter.hasExpiresAt ? "NOT NULL" : "NULL"}`);
1622
1645
  if (filter.fromDate) {
1623
1646
  conditions.push(`${dateCol} >= ?`);
1624
1647
  params.push(transformToSqlValue(filter.fromDate));
@@ -1659,7 +1682,8 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends BackgroundTasksSto
1659
1682
  conditions.push(`${quoteIdentifier("status", "column name")} IN (${placeholders})`);
1660
1683
  params.push(...statuses);
1661
1684
  }
1662
- const dateCol = filter.dateFilterBy === "startedAt" ? quoteIdentifier("startedAt", "column name") : filter.dateFilterBy === "suspendedAt" ? quoteIdentifier("suspendedAt", "column name") : filter.dateFilterBy === "completedAt" ? quoteIdentifier("completedAt", "column name") : quoteIdentifier("createdAt", "column name");
1685
+ const dateCol = filter.dateFilterBy === "startedAt" ? quoteIdentifier("startedAt", "column name") : filter.dateFilterBy === "suspendedAt" ? quoteIdentifier("suspendedAt", "column name") : filter.dateFilterBy === "completedAt" ? quoteIdentifier("completedAt", "column name") : filter.dateFilterBy === "expiresAt" ? quoteIdentifier("expiresAt", "column name") : quoteIdentifier("createdAt", "column name");
1686
+ if (filter.hasExpiresAt !== void 0) conditions.push(`${quoteIdentifier("expiresAt", "column name")} IS ${filter.hasExpiresAt ? "NOT NULL" : "NULL"}`);
1663
1687
  if (filter.fromDate) {
1664
1688
  conditions.push(`${dateCol} >= ?`);
1665
1689
  params.push(transformToSqlValue(filter.fromDate));