@mastra/mysql 0.10.0 → 0.10.1

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.10.0"
6
+ version: "0.10.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.10.0",
2
+ "version": "0.10.1",
3
3
  "package": "@mastra/mysql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -15,7 +15,7 @@ Storage adapters use the shared core retention contract for `prune()`, or a data
15
15
  | Adapter | Mechanism | Retention support |
16
16
  | -------------------- | ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
17
17
  | libSQL | `prune()` | All supported growth domains |
18
- | PostgreSQL | `prune()` | All supported growth domains. V-next observability drops expired partitions or chunks |
18
+ | PostgreSQL | `prune()` | All supported growth domains. vNext observability drops expired partitions or chunks |
19
19
  | MongoDB | `prune()` or native TTL | All supported growth domains. Native TTL indexes are also available |
20
20
  | DuckDB | `prune()` | Observability spans, metrics, logs, scores, and feedback |
21
21
  | MySQL | `prune()` | Observability spans |
@@ -102,10 +102,10 @@ Each domain specifies its age-prunable tables and the timestamp column that anch
102
102
  | `memory` | `resources` | `createdAt` | Resource age |
103
103
  | `threadState` | `threadState` | `updatedAt` | Inactivity: state for still-active threads survives |
104
104
  | `observability` | `spans` | `startedAt` | Span age |
105
- | `observability` | `metrics` | `timestamp` | Metric event age (v-next only) |
106
- | `observability` | `logs` | `timestamp` | Log event age (v-next only) |
107
- | `observability` | `scores` | `timestamp` | Score event age (v-next only) |
108
- | `observability` | `feedback` | `timestamp` | Feedback event age (v-next only) |
105
+ | `observability` | `metrics` | `timestamp` | Metric event age (vNext only) |
106
+ | `observability` | `logs` | `timestamp` | Log event age (vNext only) |
107
+ | `observability` | `scores` | `timestamp` | Score event age (vNext only) |
108
+ | `observability` | `feedback` | `timestamp` | Feedback event age (vNext only) |
109
109
  | `scores` | `scorers` | `createdAt` | Score record age |
110
110
  | `workflows` | `workflowSnapshot` | `updatedAt` | Inactivity, suspended or long-running workflows survive |
111
111
  | `backgroundTasks` | `backgroundTasks` | `completedAt` | Time since completion, in-flight tasks (`NULL`) are never pruned |
@@ -122,7 +122,7 @@ Each domain specifies its age-prunable tables and the timestamp column that anch
122
122
  > - On PostgreSQL, timestamp anchors use the timezone-aware mirror columns (for example `createdAtZ`, `completedAtZ`).
123
123
  > - DuckDB observability stores append-only events for all five signals. Its `spans` policy uses the event `timestamp` column rather than `startedAt`.
124
124
  > - LibSQL and PostgreSQL support all domains above except `harness`, which PostgreSQL doesn't implement. MongoDB supports all except `threadState` and `harness`. DuckDB, MySQL, Microsoft SQL Server, Oracle Database, Amazon Aurora DSQL, and Google Cloud Spanner currently support retention only in their `observability` domains, with the signal coverage shown in the support matrix.
125
- > - The v-next PostgreSQL observability domain stores signal events in day-partitioned tables (`spans`, `metrics`, `logs`, `scores`, `feedback`). For it, `prune()` drops whole day partitions (or TimescaleDB chunks) that are entirely older than the cutoff instead of deleting rows: effective level of detail is one day, and a partition is only dropped once its entire day is past `maxAge`. `PruneResult.deleted` reports the number of rows in the dropped partitions.
125
+ > - The vNext PostgreSQL observability domain stores signal events in day-partitioned tables (`spans`, `metrics`, `logs`, `scores`, `feedback`). For it, `prune()` drops whole day partitions (or TimescaleDB chunks) that are entirely older than the cutoff instead of deleting rows: effective level of detail is one day, and a partition is only dropped once its entire day is past `maxAge`. `PruneResult.deleted` reports the number of rows in the dropped partitions.
126
126
 
127
127
  ## Methods
128
128
 
@@ -208,7 +208,9 @@ You can also cancel a long-running prune with an `AbortSignal`: the loop stops b
208
208
 
209
209
  ClickHouse observability storage uses native table TTLs instead of `prune()`. Configure retention as days per signal. `init()` applies the TTLs to new and existing tables and skips `ALTER TABLE` statements when the configured TTL is already present.
210
210
 
211
- For deployments that need to update TTL configuration without running the full initialization path, call `applyRetention()` on the v-next observability store:
211
+ Omitted signals, and signals set to zero or less, get no TTL. When you remove a signal from `retention`, the next `init()` or `applyRetention()` removes that table's TTL. If Mastra can't read the current TTLs from `system.tables`, it applies the configured TTLs and leaves the others unchanged.
212
+
213
+ For deployments that need to update TTL configuration without running the full initialization path, call `applyRetention()` on the vNext observability store:
212
214
 
213
215
  ```typescript
214
216
  import { ObservabilityStorageClickhouseVNext } from '@mastra/clickhouse'
package/dist/index.cjs CHANGED
@@ -1884,6 +1884,17 @@ function parseOptionalJSON(value, emptyValue) {
1884
1884
  function jsonArg(value) {
1885
1885
  return value === void 0 || value === null ? null : JSON.stringify(value);
1886
1886
  }
1887
+ function jsonDataArg(value) {
1888
+ return value === void 0 ? null : JSON.stringify(value);
1889
+ }
1890
+ const ITEM_SELECT_COLUMNS = Object.keys(_mastra_core_storage.DATASET_ITEMS_SCHEMA).map((column) => {
1891
+ const name = quoteIdentifier(column, "column name");
1892
+ return [
1893
+ "input",
1894
+ "groundTruth",
1895
+ "expectedTrajectory"
1896
+ ].includes(column) ? `CAST(${name} AS CHAR CHARACTER SET utf8mb4) AS ${name}` : name;
1897
+ }).join(", ");
1887
1898
  var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsStorage {
1888
1899
  pool;
1889
1900
  operations;
@@ -2032,15 +2043,15 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2032
2043
  return {
2033
2044
  id: row.id,
2034
2045
  name: row.name,
2035
- description: row.description,
2046
+ description: row.description ?? void 0,
2036
2047
  metadata: parseJSON$3(row.metadata),
2037
2048
  inputSchema: parseJSON$3(row.inputSchema),
2038
2049
  groundTruthSchema: parseJSON$3(row.groundTruthSchema),
2039
2050
  requestContextSchema: parseJSON$3(row.requestContextSchema),
2040
- tags: parseJSON$3(row.tags) ?? null,
2041
- targetType: row.targetType ?? null,
2042
- targetIds: parseJSON$3(row.targetIds) ?? null,
2043
- scorerIds: parseJSON$3(row.scorerIds) ?? null,
2051
+ tags: parseJSON$3(row.tags),
2052
+ targetType: row.targetType ?? void 0,
2053
+ targetIds: parseJSON$3(row.targetIds),
2054
+ scorerIds: parseJSON$3(row.scorerIds),
2044
2055
  version: row.version,
2045
2056
  organizationId: row.organizationId ?? null,
2046
2057
  projectId: row.projectId ?? null,
@@ -2141,9 +2152,9 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2141
2152
  inputSchema: input.inputSchema ?? void 0,
2142
2153
  groundTruthSchema: input.groundTruthSchema ?? void 0,
2143
2154
  requestContextSchema: input.requestContextSchema ?? void 0,
2144
- targetType: input.targetType ?? null,
2145
- targetIds: input.targetIds ?? null,
2146
- scorerIds: input.scorerIds ?? null,
2155
+ targetType: input.targetType ?? void 0,
2156
+ targetIds: input.targetIds ?? void 0,
2157
+ scorerIds: input.scorerIds ?? void 0,
2147
2158
  version: 0,
2148
2159
  organizationId: input.organizationId ?? null,
2149
2160
  projectId: input.projectId ?? null,
@@ -2223,10 +2234,10 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2223
2234
  inputSchema: (args.inputSchema !== void 0 ? args.inputSchema : existing.inputSchema) ?? void 0,
2224
2235
  groundTruthSchema: (args.groundTruthSchema !== void 0 ? args.groundTruthSchema : existing.groundTruthSchema) ?? void 0,
2225
2236
  requestContextSchema: (args.requestContextSchema !== void 0 ? args.requestContextSchema : existing.requestContextSchema) ?? void 0,
2226
- tags: (args.tags !== void 0 ? args.tags : existing.tags) ?? null,
2227
- targetType: (args.targetType !== void 0 ? args.targetType : existing.targetType) ?? null,
2228
- targetIds: (args.targetIds !== void 0 ? args.targetIds : existing.targetIds) ?? null,
2229
- scorerIds: (args.scorerIds !== void 0 ? args.scorerIds : existing.scorerIds) ?? null,
2237
+ tags: (args.tags !== void 0 ? args.tags : existing.tags) ?? void 0,
2238
+ targetType: (args.targetType !== void 0 ? args.targetType : existing.targetType) ?? void 0,
2239
+ targetIds: (args.targetIds !== void 0 ? args.targetIds : existing.targetIds) ?? void 0,
2240
+ scorerIds: (args.scorerIds !== void 0 ? args.scorerIds : existing.scorerIds) ?? void 0,
2230
2241
  updatedAt: data.updatedAt
2231
2242
  };
2232
2243
  } catch (error) {
@@ -2386,8 +2397,8 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2386
2397
  newVersion,
2387
2398
  parentOrganizationId,
2388
2399
  parentProjectId,
2389
- jsonArg(args.input),
2390
- jsonArg(args.groundTruth),
2400
+ jsonDataArg(args.input),
2401
+ jsonDataArg(args.groundTruth),
2391
2402
  args.unmockedToolPolicy ?? null,
2392
2403
  jsonArg(args.scorerIds),
2393
2404
  jsonArg(args.metadata),
@@ -2438,7 +2449,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2438
2449
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2439
2450
  const tableVersionsName = formatTableName(_mastra_core_storage.TABLE_DATASET_VERSIONS);
2440
2451
  await connection.execute(`SELECT id FROM ${tableDatasetsName} WHERE id = ? FOR UPDATE`, [args.datasetId]);
2441
- const [itemRows] = await connection.execute(`SELECT * FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [args.id]);
2452
+ const [itemRows] = await connection.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [args.id]);
2442
2453
  const itemRow = itemRows[0];
2443
2454
  const existing = itemRow ? this.mapItem(itemRow) : null;
2444
2455
  if (!existing) throw new _mastra_core_error.MastraError({
@@ -2467,9 +2478,9 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2467
2478
  },
2468
2479
  text: `Purged dataset item cannot be updated: ${args.id}`
2469
2480
  });
2470
- const mergedInput = args.input ?? existing.input;
2471
- const mergedGroundTruth = args.groundTruth ?? existing.groundTruth;
2472
- const mergedExpectedTrajectory = args.expectedTrajectory ?? existing.expectedTrajectory;
2481
+ const mergedInput = args.input !== void 0 ? args.input : existing.input;
2482
+ const mergedGroundTruth = args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth;
2483
+ const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
2473
2484
  const mergedToolMocks = args.toolMocks ?? existing.toolMocks;
2474
2485
  const mergedUnmockedToolPolicy = args.unmockedToolPolicy ?? existing.unmockedToolPolicy;
2475
2486
  const mergedScorerIds = args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds;
@@ -2490,9 +2501,9 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2490
2501
  existing.externalId ?? null,
2491
2502
  parentOrganizationId,
2492
2503
  parentProjectId,
2493
- jsonArg(mergedInput),
2494
- jsonArg(mergedGroundTruth),
2495
- jsonArg(mergedExpectedTrajectory),
2504
+ jsonDataArg(mergedInput),
2505
+ jsonDataArg(mergedGroundTruth),
2506
+ jsonDataArg(mergedExpectedTrajectory),
2496
2507
  jsonArg(mergedToolMocks),
2497
2508
  mergedUnmockedToolPolicy ?? null,
2498
2509
  jsonArg(mergedScorerIds),
@@ -2547,7 +2558,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2547
2558
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2548
2559
  const tableVersionsName = formatTableName(_mastra_core_storage.TABLE_DATASET_VERSIONS);
2549
2560
  await connection.execute(`SELECT id FROM ${tableDatasetsName} WHERE id = ? FOR UPDATE`, [datasetId]);
2550
- const [itemRows] = await connection.execute(`SELECT * FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [id]);
2561
+ const [itemRows] = await connection.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [id]);
2551
2562
  const itemRow = itemRows[0];
2552
2563
  const existing = itemRow ? this.mapItem(itemRow) : null;
2553
2564
  if (!existing) {
@@ -2578,9 +2589,9 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2578
2589
  existing.externalId ?? null,
2579
2590
  parentOrganizationId,
2580
2591
  parentProjectId,
2581
- jsonArg(existing.input),
2582
- jsonArg(existing.groundTruth),
2583
- jsonArg(existing.expectedTrajectory),
2592
+ jsonDataArg(existing.input),
2593
+ jsonDataArg(existing.groundTruth),
2594
+ jsonDataArg(existing.expectedTrajectory),
2584
2595
  jsonArg(existing.toolMocks),
2585
2596
  existing.unmockedToolPolicy ?? null,
2586
2597
  jsonArg(existing.scorerIds),
@@ -2660,12 +2671,12 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2660
2671
  try {
2661
2672
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2662
2673
  let rows;
2663
- if (args.datasetVersion !== void 0) [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName} WHERE \`id\` = ? AND \`datasetVersion\` <= ? AND (\`validTo\` IS NULL OR \`validTo\` > ?) AND \`isDeleted\` = 0 ORDER BY \`datasetVersion\` DESC LIMIT 1`, [
2674
+ if (args.datasetVersion !== void 0) [rows] = await this.pool.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE \`id\` = ? AND \`datasetVersion\` <= ? AND (\`validTo\` IS NULL OR \`validTo\` > ?) AND \`isDeleted\` = 0 ORDER BY \`datasetVersion\` DESC LIMIT 1`, [
2664
2675
  args.id,
2665
2676
  args.datasetVersion,
2666
2677
  args.datasetVersion
2667
2678
  ]);
2668
- else [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName} WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [args.id]);
2679
+ else [rows] = await this.pool.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE \`id\` = ? AND \`validTo\` IS NULL AND \`isDeleted\` = 0`, [args.id]);
2669
2680
  return rows.length > 0 ? this.mapItem(rows[0]) : null;
2670
2681
  } catch (error) {
2671
2682
  throw new _mastra_core_error.MastraError({
@@ -2678,7 +2689,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2678
2689
  async getItemsByVersion({ datasetId, version }) {
2679
2690
  try {
2680
2691
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2681
- const [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName} WHERE \`datasetId\` = ? AND \`datasetVersion\` <= ? AND (\`validTo\` IS NULL OR \`validTo\` > ?) AND \`isDeleted\` = 0 ORDER BY \`createdAt\` DESC, \`id\` ASC`, [
2692
+ const [rows] = await this.pool.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE \`datasetId\` = ? AND \`datasetVersion\` <= ? AND (\`validTo\` IS NULL OR \`validTo\` > ?) AND \`isDeleted\` = 0 ORDER BY \`createdAt\` DESC, \`id\` ASC`, [
2682
2693
  datasetId,
2683
2694
  version,
2684
2695
  version
@@ -2695,7 +2706,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2695
2706
  async getItemHistory(itemId) {
2696
2707
  try {
2697
2708
  const tableItemsName = formatTableName(_mastra_core_storage.TABLE_DATASET_ITEMS);
2698
- const [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName} WHERE \`id\` = ? ORDER BY \`datasetVersion\` DESC`, [itemId]);
2709
+ const [rows] = await this.pool.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE \`id\` = ? ORDER BY \`datasetVersion\` DESC`, [itemId]);
2699
2710
  return rows.map((row) => this.mapItemFull(row));
2700
2711
  } catch (error) {
2701
2712
  throw new _mastra_core_error.MastraError({
@@ -2752,7 +2763,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2752
2763
  const perPage = (0, _mastra_core_storage.normalizePerPage)(perPageInput, 100);
2753
2764
  const { offset, perPage: perPageForResponse } = (0, _mastra_core_storage.calculatePagination)(page, perPageInput, perPage);
2754
2765
  const limitValue = perPageInput === false ? total : perPage;
2755
- const [rows] = await this.pool.execute(`SELECT * FROM ${tableItemsName}${whereSql} ORDER BY ${quoteIdentifier(orderBy.field, "column name")} ${orderBy.direction}, \`id\` ASC LIMIT ${limitValue} OFFSET ${offset}`, params);
2766
+ const [rows] = await this.pool.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName}${whereSql} ORDER BY ${quoteIdentifier(orderBy.field, "column name")} ${orderBy.direction}, \`id\` ASC LIMIT ${limitValue} OFFSET ${offset}`, params);
2756
2767
  return {
2757
2768
  items: rows.map((row) => this.mapItem(row)),
2758
2769
  pagination: {
@@ -2863,7 +2874,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2863
2874
  let historyRows = [];
2864
2875
  if (externalIds.length > 0) {
2865
2876
  const placeholders = externalIds.map(() => "?").join(", ");
2866
- const [rows] = await connection.execute(`SELECT * FROM ${tableItemsName} WHERE \`datasetId\` = ? AND \`externalId\` IN (${placeholders}) ORDER BY \`datasetVersion\` ASC`, [input.datasetId, ...externalIds]);
2877
+ const [rows] = await connection.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE \`datasetId\` = ? AND \`externalId\` IN (${placeholders}) ORDER BY \`datasetVersion\` ASC`, [input.datasetId, ...externalIds]);
2867
2878
  historyRows = rows.map((row) => this.mapItemFull(row));
2868
2879
  }
2869
2880
  const plan = this.planDatasetItemBatch(input.items, historyRows, crypto$1.randomUUID);
@@ -2884,9 +2895,9 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2884
2895
  item.externalId ?? null,
2885
2896
  dataset.organizationId ?? null,
2886
2897
  dataset.projectId ?? null,
2887
- jsonArg(item.input),
2888
- jsonArg(item.groundTruth),
2889
- jsonArg(item.expectedTrajectory),
2898
+ jsonDataArg(item.input),
2899
+ jsonDataArg(item.groundTruth),
2900
+ jsonDataArg(item.expectedTrajectory),
2890
2901
  jsonArg(item.toolMocks),
2891
2902
  item.unmockedToolPolicy ?? null,
2892
2903
  jsonArg(item.scorerIds),
@@ -2947,7 +2958,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2947
2958
  await connection.execute(`SELECT id FROM ${tableDatasetsName} WHERE id = ? FOR UPDATE`, [input.datasetId]);
2948
2959
  const currentItems = [];
2949
2960
  for (const itemId of input.itemIds) {
2950
- const [itemRows] = await connection.execute(`SELECT * FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [itemId]);
2961
+ const [itemRows] = await connection.execute(`SELECT ${ITEM_SELECT_COLUMNS} FROM ${tableItemsName} WHERE id = ? AND validTo IS NULL AND isDeleted = 0`, [itemId]);
2951
2962
  const row = itemRows[0];
2952
2963
  const item = row ? this.mapItem(row) : null;
2953
2964
  if (item && item.datasetId === input.datasetId) currentItems.push(item);
@@ -2970,9 +2981,9 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2970
2981
  item.externalId ?? null,
2971
2982
  parentOrganizationId,
2972
2983
  parentProjectId,
2973
- jsonArg(item.input),
2974
- jsonArg(item.groundTruth),
2975
- jsonArg(item.expectedTrajectory),
2984
+ jsonDataArg(item.input),
2985
+ jsonDataArg(item.groundTruth),
2986
+ jsonDataArg(item.expectedTrajectory),
2976
2987
  jsonArg(item.toolMocks),
2977
2988
  item.unmockedToolPolicy ?? null,
2978
2989
  jsonArg(item.scorerIds),