@mastra/mysql 0.14.0-alpha.1 → 0.14.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.
@@ -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.14.0-alpha.1"
6
+ version: "0.14.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.14.0-alpha.1",
2
+ "version": "0.14.0",
3
3
  "package": "@mastra/mysql",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -86,13 +86,14 @@ function prepareWhereClause(filters) {
86
86
  if (value === true) conditions.push(`${quoteIdentifier(fieldName, "column name")} IS NULL`);
87
87
  else if (value === false) conditions.push(`${quoteIdentifier(fieldName, "column name")} IS NOT NULL`);
88
88
  } else if (value === null) conditions.push(`${quoteIdentifier(key, "column name")} IS NULL`);
89
- else if (Array.isArray(value)) if (value.length === 0) conditions.push("FALSE");
90
- else {
91
- const placeholders = value.map(() => "?").join(", ");
92
- conditions.push(`${quoteIdentifier(key, "column name")} IN (${placeholders})`);
93
- args.push(...value.map(transformToSqlValue));
94
- }
95
- else {
89
+ else if (Array.isArray(value)) {
90
+ if (value.length === 0) conditions.push("FALSE");
91
+ else {
92
+ const placeholders = value.map(() => "?").join(", ");
93
+ conditions.push(`${quoteIdentifier(key, "column name")} IN (${placeholders})`);
94
+ args.push(...value.map(transformToSqlValue));
95
+ }
96
+ } else {
96
97
  conditions.push(`${quoteIdentifier(key, "column name")} = ?`);
97
98
  args.push(transformToSqlValue(value));
98
99
  }
@@ -157,13 +158,14 @@ function transformFromSqlRow({ tableName, sqlRow }) {
157
158
  const result = {};
158
159
  Object.entries(sqlRow).forEach(([key, value]) => {
159
160
  const columnSchema = schema?.[key];
160
- if (columnSchema?.type === "jsonb") if (typeof value === "string") try {
161
- result[key] = JSON.parse(value);
162
- } catch {
163
- result[key] = value;
164
- }
165
- else result[key] = value;
166
- else if (columnSchema?.type === "timestamp") result[key] = value === null ? null : parseDateTime(value);
161
+ if (columnSchema?.type === "jsonb") {
162
+ if (typeof value === "string") try {
163
+ result[key] = JSON.parse(value);
164
+ } catch {
165
+ result[key] = value;
166
+ }
167
+ else result[key] = value;
168
+ } else if (columnSchema?.type === "timestamp") result[key] = value === null ? null : parseDateTime(value);
167
169
  else if (columnSchema?.type === "boolean") result[key] = value === true || value === 1 || value === "1";
168
170
  else result[key] = value;
169
171
  });
@@ -1565,15 +1567,19 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends _mastra_core_stora
1565
1567
  predicates.push(`${quoteIdentifier("status", "column name")} = ?`);
1566
1568
  params.push(options.expectedStatus);
1567
1569
  }
1568
- if (options?.expectedOwnerId !== void 0) if (options.expectedOwnerId === null) predicates.push(`${quoteIdentifier("ownerId", "column name")} IS NULL`);
1569
- else {
1570
- predicates.push(`${quoteIdentifier("ownerId", "column name")} = ?`);
1571
- params.push(options.expectedOwnerId);
1570
+ if (options?.expectedOwnerId !== void 0) {
1571
+ if (options.expectedOwnerId === null) predicates.push(`${quoteIdentifier("ownerId", "column name")} IS NULL`);
1572
+ else {
1573
+ predicates.push(`${quoteIdentifier("ownerId", "column name")} = ?`);
1574
+ params.push(options.expectedOwnerId);
1575
+ }
1572
1576
  }
1573
- if (options?.expectedLeaseExpiresAt !== void 0) if (options.expectedLeaseExpiresAt === null) predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} IS NULL`);
1574
- else {
1575
- predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} = ?`);
1576
- params.push(transformToSqlValue(options.expectedLeaseExpiresAt));
1577
+ if (options?.expectedLeaseExpiresAt !== void 0) {
1578
+ if (options.expectedLeaseExpiresAt === null) predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} IS NULL`);
1579
+ else {
1580
+ predicates.push(`${quoteIdentifier("leaseExpiresAt", "column name")} = ?`);
1581
+ params.push(transformToSqlValue(options.expectedLeaseExpiresAt));
1582
+ }
1577
1583
  }
1578
1584
  const predicateSql = predicates.length > 0 ? ` AND ${predicates.join(" AND ")}` : "";
1579
1585
  const [result] = await this.pool.execute(`UPDATE ${formatTableName(_mastra_core_storage.TABLE_BACKGROUND_TASKS)} SET ${setClauses.join(", ")} WHERE ${quoteIdentifier("id", "column name")} = ?${predicateSql}`, params);
@@ -6134,10 +6140,11 @@ async function assertRunFence(q, claimsTable, fence, operation) {
6134
6140
  const [rows] = await q.execute(`SELECT generation, ${quoteIdentifier("ownerId", "column name")} AS ownerId FROM ${claimsTable}
6135
6141
  WHERE ${quoteIdentifier("runId", "column name")} = ? LOCK IN SHARE MODE`, [fence.runId]);
6136
6142
  const row = rows[0];
6137
- if (!(0, _mastra_core_storage.matchesRunFence)(row ? {
6143
+ const current = row ? {
6138
6144
  generation: Number(row.generation),
6139
6145
  ownerId: String(row.ownerId)
6140
- } : null, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
6146
+ } : null;
6147
+ if (!(0, _mastra_core_storage.matchesRunFence)(current, fence)) throw new _mastra_core_storage.RunFenceConflictError(fence, operation);
6141
6148
  }
6142
6149
  /** Runs `fn` in a transaction on its own pooled connection. */
6143
6150
  async function inTransaction(pool, fn) {
@@ -6471,13 +6478,14 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
6471
6478
  for (const indexDef of this.#indexes) await this.operations.createIndex(indexDef);
6472
6479
  }
6473
6480
  async prune(policies, options) {
6481
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
6482
+ policies,
6483
+ descriptor: MemoryMySQL.retentionTables,
6484
+ order: ["runFences"]
6485
+ });
6474
6486
  return (0, _mastra_core_storage.executeRetentionPrune)({
6475
6487
  domain: "memory",
6476
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
6477
- policies,
6478
- descriptor: MemoryMySQL.retentionTables,
6479
- order: ["runFences"]
6480
- }),
6488
+ targets,
6481
6489
  options,
6482
6490
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
6483
6491
  deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({
@@ -8405,13 +8413,14 @@ var ObservabilityMySQL = class ObservabilityMySQL extends _mastra_core_storage.O
8405
8413
  this.#indexes = indexes?.filter((idx) => ObservabilityMySQL.MANAGED_TABLES.includes(idx.table));
8406
8414
  }
8407
8415
  async prune(policies, options) {
8416
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
8417
+ policies,
8418
+ descriptor: ObservabilityMySQL.retentionTables,
8419
+ order: ["spans"]
8420
+ });
8408
8421
  return (0, _mastra_core_storage.executeRetentionPrune)({
8409
8422
  domain: "observability",
8410
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
8411
- policies,
8412
- descriptor: ObservabilityMySQL.retentionTables,
8413
- order: ["spans"]
8414
- }),
8423
+ targets,
8415
8424
  options,
8416
8425
  cutoffFor: (target, now) => new Date((0, _mastra_core_storage.retentionCutoffMs)(target.policy, now)),
8417
8426
  deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({
@@ -8778,22 +8787,22 @@ var ObservabilityMySQL = class ObservabilityMySQL extends _mastra_core_storage.O
8778
8787
  case _mastra_core_storage.TraceStatus.RUNNING:
8779
8788
  conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
8780
8789
  break;
8781
- case _mastra_core_storage.TraceStatus.SUCCESS:
8782
- conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NOT NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
8783
- break;
8790
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NOT NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
8784
8791
  }
8785
- if (filters.hasChildError !== void 0) if (filters.hasChildError) conditions.push(`EXISTS (
8792
+ if (filters.hasChildError !== void 0) {
8793
+ if (filters.hasChildError) conditions.push(`EXISTS (
8786
8794
  SELECT 1 FROM ${tbl} c
8787
8795
  WHERE c.${quoteIdentifier("traceId", "column name")} = ${tbl}.${quoteIdentifier("traceId", "column name")}
8788
8796
  AND c.${quoteIdentifier("parentSpanId", "column name")} IS NOT NULL
8789
8797
  AND c.${quoteIdentifier("error", "column name")} IS NOT NULL
8790
8798
  )`);
8791
- else conditions.push(`NOT EXISTS (
8799
+ else conditions.push(`NOT EXISTS (
8792
8800
  SELECT 1 FROM ${tbl} c
8793
8801
  WHERE c.${quoteIdentifier("traceId", "column name")} = ${tbl}.${quoteIdentifier("traceId", "column name")}
8794
8802
  AND c.${quoteIdentifier("parentSpanId", "column name")} IS NOT NULL
8795
8803
  AND c.${quoteIdentifier("error", "column name")} IS NOT NULL
8796
8804
  )`);
8805
+ }
8797
8806
  }
8798
8807
  const whereClause = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
8799
8808
  const sortField = quoteIdentifier(orderBy.field, "column name");
@@ -9529,15 +9538,19 @@ var SchedulesMySQL = class SchedulesMySQL extends _mastra_core_storage.Schedules
9529
9538
  conditions.push(`JSON_EXTRACT(${quoteIdentifier("target", "column name")}, '$.workflowId') = ?`);
9530
9539
  params.push(filter.workflowId);
9531
9540
  }
9532
- if (filter?.ownerType !== void 0) if (filter.ownerType === null) conditions.push(`${quoteIdentifier("owner_type", "column name")} IS NULL`);
9533
- else {
9534
- conditions.push(`${quoteIdentifier("owner_type", "column name")} = ?`);
9535
- params.push(filter.ownerType);
9541
+ if (filter?.ownerType !== void 0) {
9542
+ if (filter.ownerType === null) conditions.push(`${quoteIdentifier("owner_type", "column name")} IS NULL`);
9543
+ else {
9544
+ conditions.push(`${quoteIdentifier("owner_type", "column name")} = ?`);
9545
+ params.push(filter.ownerType);
9546
+ }
9536
9547
  }
9537
- if (filter?.ownerId !== void 0) if (filter.ownerId === null) conditions.push(`${quoteIdentifier("owner_id", "column name")} IS NULL`);
9538
- else {
9539
- conditions.push(`${quoteIdentifier("owner_id", "column name")} = ?`);
9540
- params.push(filter.ownerId);
9548
+ if (filter?.ownerId !== void 0) {
9549
+ if (filter.ownerId === null) conditions.push(`${quoteIdentifier("owner_id", "column name")} IS NULL`);
9550
+ else {
9551
+ conditions.push(`${quoteIdentifier("owner_id", "column name")} = ?`);
9552
+ params.push(filter.ownerId);
9553
+ }
9541
9554
  }
9542
9555
  const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
9543
9556
  const [rows] = await this.pool.execute(`SELECT * FROM ${formatTableName(_mastra_core_storage.TABLE_SCHEDULES)} ${where} ORDER BY ${quoteIdentifier("created_at", "column name")} ASC`, params);
@@ -11472,13 +11485,14 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
11472
11485
  await this.createCustomIndexes();
11473
11486
  }
11474
11487
  async prune(policies, options) {
11488
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
11489
+ policies,
11490
+ descriptor: WorkflowsMySQL.retentionTables,
11491
+ order: ["runOwnership"]
11492
+ });
11475
11493
  return (0, _mastra_core_storage.executeRetentionPrune)({
11476
11494
  domain: "workflows",
11477
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
11478
- policies,
11479
- descriptor: WorkflowsMySQL.retentionTables,
11480
- order: ["runOwnership"]
11481
- }),
11495
+ targets,
11482
11496
  options,
11483
11497
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
11484
11498
  deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({