@mastra/mysql 0.13.3-alpha.0 → 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.13.3-alpha.0"
6
+ version: "0.14.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.13.3-alpha.0",
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);
@@ -2340,6 +2346,10 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2340
2346
  const { page, perPage: perPageInput } = args.pagination;
2341
2347
  const filterParts = [];
2342
2348
  const filterArgs = [];
2349
+ if (args.filters?.datasetIds !== void 0) {
2350
+ filterParts.push(args.filters.datasetIds.length > 0 ? `\`id\` IN (${args.filters.datasetIds.map(() => "?").join(",")})` : "1 = 0");
2351
+ filterArgs.push(...args.filters.datasetIds);
2352
+ }
2343
2353
  if (args.filters?.organizationId !== void 0) {
2344
2354
  filterParts.push(`${quoteIdentifier("organizationId", "column name")} = ?`);
2345
2355
  filterArgs.push(args.filters.organizationId);
@@ -6130,10 +6140,11 @@ async function assertRunFence(q, claimsTable, fence, operation) {
6130
6140
  const [rows] = await q.execute(`SELECT generation, ${quoteIdentifier("ownerId", "column name")} AS ownerId FROM ${claimsTable}
6131
6141
  WHERE ${quoteIdentifier("runId", "column name")} = ? LOCK IN SHARE MODE`, [fence.runId]);
6132
6142
  const row = rows[0];
6133
- if (!(0, _mastra_core_storage.matchesRunFence)(row ? {
6143
+ const current = row ? {
6134
6144
  generation: Number(row.generation),
6135
6145
  ownerId: String(row.ownerId)
6136
- } : 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);
6137
6148
  }
6138
6149
  /** Runs `fn` in a transaction on its own pooled connection. */
6139
6150
  async function inTransaction(pool, fn) {
@@ -6467,13 +6478,14 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
6467
6478
  for (const indexDef of this.#indexes) await this.operations.createIndex(indexDef);
6468
6479
  }
6469
6480
  async prune(policies, options) {
6481
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
6482
+ policies,
6483
+ descriptor: MemoryMySQL.retentionTables,
6484
+ order: ["runFences"]
6485
+ });
6470
6486
  return (0, _mastra_core_storage.executeRetentionPrune)({
6471
6487
  domain: "memory",
6472
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
6473
- policies,
6474
- descriptor: MemoryMySQL.retentionTables,
6475
- order: ["runFences"]
6476
- }),
6488
+ targets,
6477
6489
  options,
6478
6490
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
6479
6491
  deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({
@@ -8401,13 +8413,14 @@ var ObservabilityMySQL = class ObservabilityMySQL extends _mastra_core_storage.O
8401
8413
  this.#indexes = indexes?.filter((idx) => ObservabilityMySQL.MANAGED_TABLES.includes(idx.table));
8402
8414
  }
8403
8415
  async prune(policies, options) {
8416
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
8417
+ policies,
8418
+ descriptor: ObservabilityMySQL.retentionTables,
8419
+ order: ["spans"]
8420
+ });
8404
8421
  return (0, _mastra_core_storage.executeRetentionPrune)({
8405
8422
  domain: "observability",
8406
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
8407
- policies,
8408
- descriptor: ObservabilityMySQL.retentionTables,
8409
- order: ["spans"]
8410
- }),
8423
+ targets,
8411
8424
  options,
8412
8425
  cutoffFor: (target, now) => new Date((0, _mastra_core_storage.retentionCutoffMs)(target.policy, now)),
8413
8426
  deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({
@@ -8774,22 +8787,22 @@ var ObservabilityMySQL = class ObservabilityMySQL extends _mastra_core_storage.O
8774
8787
  case _mastra_core_storage.TraceStatus.RUNNING:
8775
8788
  conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
8776
8789
  break;
8777
- case _mastra_core_storage.TraceStatus.SUCCESS:
8778
- conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NOT NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
8779
- break;
8790
+ case _mastra_core_storage.TraceStatus.SUCCESS: conditions.push(`${quoteIdentifier("endedAt", "column name")} IS NOT NULL AND ${quoteIdentifier("error", "column name")} IS NULL`);
8780
8791
  }
8781
- if (filters.hasChildError !== void 0) if (filters.hasChildError) conditions.push(`EXISTS (
8792
+ if (filters.hasChildError !== void 0) {
8793
+ if (filters.hasChildError) conditions.push(`EXISTS (
8782
8794
  SELECT 1 FROM ${tbl} c
8783
8795
  WHERE c.${quoteIdentifier("traceId", "column name")} = ${tbl}.${quoteIdentifier("traceId", "column name")}
8784
8796
  AND c.${quoteIdentifier("parentSpanId", "column name")} IS NOT NULL
8785
8797
  AND c.${quoteIdentifier("error", "column name")} IS NOT NULL
8786
8798
  )`);
8787
- else conditions.push(`NOT EXISTS (
8799
+ else conditions.push(`NOT EXISTS (
8788
8800
  SELECT 1 FROM ${tbl} c
8789
8801
  WHERE c.${quoteIdentifier("traceId", "column name")} = ${tbl}.${quoteIdentifier("traceId", "column name")}
8790
8802
  AND c.${quoteIdentifier("parentSpanId", "column name")} IS NOT NULL
8791
8803
  AND c.${quoteIdentifier("error", "column name")} IS NOT NULL
8792
8804
  )`);
8805
+ }
8793
8806
  }
8794
8807
  const whereClause = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")}` : "";
8795
8808
  const sortField = quoteIdentifier(orderBy.field, "column name");
@@ -9525,15 +9538,19 @@ var SchedulesMySQL = class SchedulesMySQL extends _mastra_core_storage.Schedules
9525
9538
  conditions.push(`JSON_EXTRACT(${quoteIdentifier("target", "column name")}, '$.workflowId') = ?`);
9526
9539
  params.push(filter.workflowId);
9527
9540
  }
9528
- if (filter?.ownerType !== void 0) if (filter.ownerType === null) conditions.push(`${quoteIdentifier("owner_type", "column name")} IS NULL`);
9529
- else {
9530
- conditions.push(`${quoteIdentifier("owner_type", "column name")} = ?`);
9531
- 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
+ }
9532
9547
  }
9533
- if (filter?.ownerId !== void 0) if (filter.ownerId === null) conditions.push(`${quoteIdentifier("owner_id", "column name")} IS NULL`);
9534
- else {
9535
- conditions.push(`${quoteIdentifier("owner_id", "column name")} = ?`);
9536
- 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
+ }
9537
9554
  }
9538
9555
  const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
9539
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);
@@ -11468,13 +11485,14 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
11468
11485
  await this.createCustomIndexes();
11469
11486
  }
11470
11487
  async prune(policies, options) {
11488
+ const targets = (0, _mastra_core_storage.resolveRetentionTargets)({
11489
+ policies,
11490
+ descriptor: WorkflowsMySQL.retentionTables,
11491
+ order: ["runOwnership"]
11492
+ });
11471
11493
  return (0, _mastra_core_storage.executeRetentionPrune)({
11472
11494
  domain: "workflows",
11473
- targets: (0, _mastra_core_storage.resolveRetentionTargets)({
11474
- policies,
11475
- descriptor: WorkflowsMySQL.retentionTables,
11476
- order: ["runOwnership"]
11477
- }),
11495
+ targets,
11478
11496
  options,
11479
11497
  cutoffFor: (target, now) => (0, _mastra_core_storage.retentionCutoffMs)(target.policy, now),
11480
11498
  deleteBatch: (target, cutoff, limit) => this.operations.pruneBatch({