@mastra/mysql 0.14.0 → 0.14.1-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.
@@ -1,4 +1,3 @@
1
- //#region src/memory/index.d.ts
2
1
  /**
3
2
  * Shared rules for observational memory lifecycle writes. Every storage adapter applies
4
3
  * these inside its own atomic section (lock, transaction, or conditional update), so the
@@ -9,18 +8,18 @@
9
8
  * into the table schema they get from `@mastra/core`, so the columns exist even when the
10
9
  * installed core predates them.
11
10
  */
12
- declare const OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS: {
11
+ export declare const OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS: {
13
12
  readonly supersededBy: {
14
13
  readonly type: 'text';
15
14
  readonly nullable: true;
16
15
  };
17
16
  };
18
17
  /** `schema` plus {@link OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS}; `undefined` when `schema` is. */
19
- declare function withObservationalMemoryLifecycleColumns<T extends object>(schema: T | undefined): (T & typeof OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS) | undefined;
18
+ export declare function withObservationalMemoryLifecycleColumns<T extends object>(schema: T | undefined): (T & typeof OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS) | undefined;
20
19
  /**
21
20
  * Result of `commitActiveObservations`.
22
21
  */
23
- interface UpdateActiveObservationsResult {
22
+ export interface UpdateActiveObservationsResult {
24
23
  /** Whether the observations were written. */
25
24
  applied: boolean;
26
25
  /**
@@ -38,14 +37,14 @@ interface UpdateActiveObservationsResult {
38
37
  * the head's cursor. Chunks carry `lastObservedAt = max message time + 1ms`, so a chunk is
39
38
  * wholly covered iff `head.lastObservedAt >= chunk.lastObservedAt - 1ms`.
40
39
  */
41
- interface UpdateBufferedObservationsResult {
40
+ export interface UpdateBufferedObservationsResult {
42
41
  /** Whether the chunk was stored. */
43
42
  persisted: boolean;
44
43
  /** The record the chunk was written to (or would have been written to). */
45
44
  recordId: string;
46
45
  }
47
46
  /** The fields of an observational memory record that decide head order. */
48
- interface ObservationalMemoryHeadOrderFields {
47
+ export interface ObservationalMemoryHeadOrderFields {
49
48
  generationCount: number;
50
49
  createdAt: Date | string;
51
50
  id: string;
@@ -54,16 +53,16 @@ interface ObservationalMemoryHeadOrderFields {
54
53
  * Canonical head order: `generationCount DESC, createdAt ASC, id ASC`.
55
54
  * Returns a negative number when `a` sorts before `b` (i.e. `a` is the better head candidate).
56
55
  */
57
- declare function compareObservationalMemoryHeadOrder(a: ObservationalMemoryHeadOrderFields, b: ObservationalMemoryHeadOrderFields): number;
56
+ export declare function compareObservationalMemoryHeadOrder(a: ObservationalMemoryHeadOrderFields, b: ObservationalMemoryHeadOrderFields): number;
58
57
  /**
59
58
  * A buffered chunk stores `lastObservedAt = max message time + 1ms`. It is wholly covered
60
59
  * (every message it observed is already at or before the cursor) iff
61
60
  * `cursor >= chunk.lastObservedAt - 1ms`.
62
61
  */
63
- declare function isBufferedChunkCoveredByCursor(chunkLastObservedAt: Date | string, cursor: Date | string | null | undefined): boolean;
62
+ export declare function isBufferedChunkCoveredByCursor(chunkLastObservedAt: Date | string, cursor: Date | string | null | undefined): boolean;
64
63
  /** The later of two cursors; `undefined` only when both are absent. */
65
- declare function maxObservationCursor(a: Date | string | null | undefined, b: Date | string | null | undefined): Date | undefined;
66
- interface ReflectionTextPlan {
64
+ export declare function maxObservationCursor(a: Date | string | null | undefined, b: Date | string | null | undefined): Date | undefined;
65
+ export interface ReflectionTextPlan {
67
66
  /** `equal`: stored text equals the snapshot. `append`: observations were appended after the snapshot. */
68
67
  mode: 'equal' | 'append';
69
68
  observations: string;
@@ -78,7 +77,7 @@ interface ReflectionTextPlan {
78
77
  * after the reflection, and its tokens are added.
79
78
  * - Anything else (a non-append rewrite): `null` — the reflection must not be applied.
80
79
  */
81
- declare function planReflectionGenerationText(input: {
80
+ export declare function planReflectionGenerationText(input: {
82
81
  storedObservations: string;
83
82
  storedObservationTokenCount: number;
84
83
  snapshotObservations: string;
@@ -91,12 +90,10 @@ declare function planReflectionGenerationText(input: {
91
90
  * Callers of `updateActiveObservations` (which resolves `void`) can't see a commit result, so a
92
91
  * write that was not applied throws instead of resolving as if it had committed.
93
92
  */
94
- declare function assertActiveObservationsApplied(result: UpdateActiveObservationsResult, id: string): void;
93
+ export declare function assertActiveObservationsApplied(result: UpdateActiveObservationsResult, id: string): void;
95
94
  /**
96
95
  * Whether the stored text can still accept a reflection built from `snapshot`
97
96
  * (equal, or only appended to since).
98
97
  */
99
- declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
100
- //#endregion
101
- export { OBSERVATIONAL_MEMORY_LIFECYCLE_COLUMNS, ObservationalMemoryHeadOrderFields, ReflectionTextPlan, UpdateActiveObservationsResult, UpdateBufferedObservationsResult, assertActiveObservationsApplied, compareObservationalMemoryHeadOrder, isAppendOnlySince, isBufferedChunkCoveredByCursor, maxObservationCursor, planReflectionGenerationText, withObservationalMemoryLifecycleColumns };
98
+ export declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
102
99
  //# sourceMappingURL=index.d.ts.map
@@ -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"
6
+ version: "0.14.1-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.14.0",
2
+ "version": "0.14.1-alpha.0",
3
3
  "package": "@mastra/mysql",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -294,7 +294,7 @@ const storage = new MongoDBStore({
294
294
 
295
295
  ## Reclaiming disk
296
296
 
297
- `prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist and are reused by future writes, so the file stops growing: for most users this alone solves the unbounded-growth problem.
297
+ `prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist for reuse by future writes. Reusing these pages prevents unbounded file growth for most users.
298
298
 
299
299
  Handing that free space back to the OS is a separate concern that Mastra doesn't manage. If you specifically need to shrink the file, run the underlying database's compaction (for example `VACUUM` on self-hosted libSQL) yourself in a maintenance window. A full `VACUUM` locks the file and needs roughly twice the file size in free disk. On PostgreSQL, autovacuum reclaims dead tuples for reuse automatically. A manual `VACUUM FULL` is only needed if you must return disk to the OS.
300
300
 
package/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ let _mastra_core_utils = require("@mastra/core/utils");
6
6
  let crypto$1 = require("crypto");
7
7
  let _mastra_core_agent = require("@mastra/core/agent");
8
8
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
9
- //#region src/storage/db/schema-snapshot.ts
9
+ // src/storage/db/schema-snapshot.ts
10
10
  /** Builds the `table.index` presence key the snapshot uses. */
11
11
  function indexKey(table, index) {
12
12
  return `${table.toLowerCase()}.${index.toLowerCase()}`;
@@ -45,8 +45,7 @@ async function loadSchemaSnapshot(pool, schemaName) {
45
45
  indexes
46
46
  };
47
47
  }
48
- //#endregion
49
- //#region src/storage/domains/utils.ts
48
+ // src/storage/domains/utils.ts
50
49
  function quoteIdentifier(value, context) {
51
50
  return `\`${(0, _mastra_core_utils.parseSqlIdentifier)(value, context)}\``;
52
51
  }
@@ -181,8 +180,7 @@ function parseDateTime(value) {
181
180
  const withZone = /[zZ]|[+-]\d\d:?\d\d$/.test(normalized) ? normalized : `${normalized}Z`;
182
181
  return new Date(withZone);
183
182
  }
184
- //#endregion
185
- //#region src/storage/domains/operations/index.ts
183
+ // src/storage/domains/operations/index.ts
186
184
  var StoreOperationsMySQL = class extends _mastra_core_storage.StoreOperations {
187
185
  pool;
188
186
  database;
@@ -776,8 +774,7 @@ function mapToMySqlType(type, isKey = false) {
776
774
  default: return "TEXT";
777
775
  }
778
776
  }
779
- //#endregion
780
- //#region src/storage/domains/agents/index.ts
777
+ // src/storage/domains/agents/index.ts
781
778
  var AgentsMySQL = class AgentsMySQL extends _mastra_core_storage.AgentsStorage {
782
779
  pool;
783
780
  operations;
@@ -1374,8 +1371,7 @@ var AgentsMySQL = class AgentsMySQL extends _mastra_core_storage.AgentsStorage {
1374
1371
  };
1375
1372
  }
1376
1373
  };
1377
- //#endregion
1378
- //#region src/storage/domains/background-tasks/index.ts
1374
+ // src/storage/domains/background-tasks/index.ts
1379
1375
  function serializeJson(v) {
1380
1376
  if (typeof v === "object" && v != null) return JSON.stringify(v);
1381
1377
  return v ?? null;
@@ -1693,8 +1689,7 @@ var BackgroundTasksMySQL = class BackgroundTasksMySQL extends _mastra_core_stora
1693
1689
  return Number(rows[0]?.count ?? 0);
1694
1690
  }
1695
1691
  };
1696
- //#endregion
1697
- //#region src/storage/domains/blobs/index.ts
1692
+ // src/storage/domains/blobs/index.ts
1698
1693
  const INSERT_IGNORE_SQL = `INSERT IGNORE INTO ${formatTableName(_mastra_core_storage.TABLE_SKILL_BLOBS)} (${[
1699
1694
  "hash",
1700
1695
  "content",
@@ -1775,8 +1770,7 @@ var BlobsMySQL = class extends _mastra_core_storage.BlobStore {
1775
1770
  };
1776
1771
  }
1777
1772
  };
1778
- //#endregion
1779
- //#region src/storage/domains/channels/index.ts
1773
+ // src/storage/domains/channels/index.ts
1780
1774
  var ChannelsMySQL = class ChannelsMySQL extends _mastra_core_storage.ChannelsStorage {
1781
1775
  pool;
1782
1776
  operations;
@@ -1910,8 +1904,7 @@ var ChannelsMySQL = class ChannelsMySQL extends _mastra_core_storage.ChannelsSto
1910
1904
  };
1911
1905
  }
1912
1906
  };
1913
- //#endregion
1914
- //#region src/storage/domains/datasets/index.ts
1907
+ // src/storage/domains/datasets/index.ts
1915
1908
  function parseJSON$3(value) {
1916
1909
  if (value === null || value === void 0) return void 0;
1917
1910
  if (typeof value === "string") try {
@@ -3062,8 +3055,7 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
3062
3055
  }
3063
3056
  }
3064
3057
  };
3065
- //#endregion
3066
- //#region src/storage/domains/experiments/index.ts
3058
+ // src/storage/domains/experiments/index.ts
3067
3059
  function parseJSON$2(value) {
3068
3060
  if (value === null || value === void 0) return void 0;
3069
3061
  if (typeof value === "string") {
@@ -3935,8 +3927,7 @@ var ExperimentsMySQL = class ExperimentsMySQL extends _mastra_core_storage.Exper
3935
3927
  }
3936
3928
  }
3937
3929
  };
3938
- //#endregion
3939
- //#region src/storage/domains/favorites/index.ts
3930
+ // src/storage/domains/favorites/index.ts
3940
3931
  /**
3941
3932
  * Maps a favorite entity type to its parent entity table.
3942
3933
  */
@@ -4172,8 +4163,7 @@ var FavoritesMySQL = class FavoritesMySQL extends _mastra_core_storage.Favorites
4172
4163
  }
4173
4164
  }
4174
4165
  };
4175
- //#endregion
4176
- //#region src/storage/domains/knowledge/index.ts
4166
+ // src/storage/domains/knowledge/index.ts
4177
4167
  let assertDescriptionWithinBound;
4178
4168
  async function assertKnowledgeDescriptionWithinBoundCompat(description) {
4179
4169
  let assertWithinBound = assertDescriptionWithinBound;
@@ -5068,8 +5058,7 @@ var KnowledgeMySQL = class extends _mastra_core_storage.KnowledgeStorage {
5068
5058
  });
5069
5059
  }
5070
5060
  };
5071
- //#endregion
5072
- //#region src/storage/domains/mcp-clients/index.ts
5061
+ // src/storage/domains/mcp-clients/index.ts
5073
5062
  var MCPClientsMySQL = class MCPClientsMySQL extends _mastra_core_storage.MCPClientsStorage {
5074
5063
  pool;
5075
5064
  operations;
@@ -5542,8 +5531,7 @@ var MCPClientsMySQL = class MCPClientsMySQL extends _mastra_core_storage.MCPClie
5542
5531
  }
5543
5532
  }
5544
5533
  };
5545
- //#endregion
5546
- //#region src/storage/domains/mcp-servers/index.ts
5534
+ // src/storage/domains/mcp-servers/index.ts
5547
5535
  var MCPServersMySQL = class MCPServersMySQL extends _mastra_core_storage.MCPServersStorage {
5548
5536
  pool;
5549
5537
  operations;
@@ -6032,8 +6020,7 @@ var MCPServersMySQL = class MCPServersMySQL extends _mastra_core_storage.MCPServ
6032
6020
  }
6033
6021
  }
6034
6022
  };
6035
- //#endregion
6036
- //#region ../../packages/_internal-core/dist/memory/index.js
6023
+ // ../../packages/_internal-core/dist/memory/index.js
6037
6024
  /**
6038
6025
  * Shared rules for observational memory lifecycle writes. Every storage adapter applies
6039
6026
  * these inside its own atomic section (lock, transaction, or conditional update), so the
@@ -6118,8 +6105,7 @@ function isAppendOnlySince(storedObservations, snapshotObservations) {
6118
6105
  const snapshot = snapshotObservations ?? "";
6119
6106
  return stored === snapshot || stored.startsWith(snapshot);
6120
6107
  }
6121
- //#endregion
6122
- //#region src/storage/db/run-fencing.ts
6108
+ // src/storage/db/run-fencing.ts
6123
6109
  /**
6124
6110
  * Epoch milliseconds on the database clock. `UTC_TIMESTAMP` is the time the
6125
6111
  * statement started and doesn't depend on the session time zone. Every lease
@@ -6187,8 +6173,7 @@ async function claimTransaction(pool, fn) {
6187
6173
  if (attempt >= MAX_CLAIM_ATTEMPTS || errno !== ER_DUP_ENTRY && errno !== ER_LOCK_DEADLOCK) throw error;
6188
6174
  }
6189
6175
  }
6190
- //#endregion
6191
- //#region src/storage/domains/memory/index.ts
6176
+ // src/storage/domains/memory/index.ts
6192
6177
  const OM_TABLE = "mastra_observational_memory";
6193
6178
  const OM_TABLE_QUOTED = quoteIdentifier(OM_TABLE, "table name");
6194
6179
  const RUN_FENCES_TABLE = formatTableName(_mastra_core_storage.TABLE_MEMORY_RUN_FENCES);
@@ -8379,8 +8364,7 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
8379
8364
  };
8380
8365
  }
8381
8366
  };
8382
- //#endregion
8383
- //#region src/storage/domains/observability/index.ts
8367
+ // src/storage/domains/observability/index.ts
8384
8368
  const JSON_SPAN_FIELDS = [
8385
8369
  "input",
8386
8370
  "output",
@@ -8914,8 +8898,7 @@ var ObservabilityMySQL = class ObservabilityMySQL extends _mastra_core_storage.O
8914
8898
  }
8915
8899
  }
8916
8900
  };
8917
- //#endregion
8918
- //#region src/storage/domains/prompt-blocks/index.ts
8901
+ // src/storage/domains/prompt-blocks/index.ts
8919
8902
  var PromptBlocksMySQL = class PromptBlocksMySQL extends _mastra_core_storage.PromptBlocksStorage {
8920
8903
  pool;
8921
8904
  operations;
@@ -9387,8 +9370,7 @@ var PromptBlocksMySQL = class PromptBlocksMySQL extends _mastra_core_storage.Pro
9387
9370
  }
9388
9371
  }
9389
9372
  };
9390
- //#endregion
9391
- //#region src/storage/domains/schedules/index.ts
9373
+ // src/storage/domains/schedules/index.ts
9392
9374
  function parseJson(val) {
9393
9375
  if (val == null) return void 0;
9394
9376
  if (typeof val === "string") try {
@@ -9657,8 +9639,7 @@ var SchedulesMySQL = class SchedulesMySQL extends _mastra_core_storage.Schedules
9657
9639
  return rows.map((r) => rowToTrigger(r));
9658
9640
  }
9659
9641
  };
9660
- //#endregion
9661
- //#region src/storage/domains/scorer-definitions/index.ts
9642
+ // src/storage/domains/scorer-definitions/index.ts
9662
9643
  var ScorerDefinitionsMySQL = class ScorerDefinitionsMySQL extends _mastra_core_storage.ScorerDefinitionsStorage {
9663
9644
  pool;
9664
9645
  operations;
@@ -10133,8 +10114,7 @@ var ScorerDefinitionsMySQL = class ScorerDefinitionsMySQL extends _mastra_core_s
10133
10114
  }
10134
10115
  }
10135
10116
  };
10136
- //#endregion
10137
- //#region src/storage/domains/scores/index.ts
10117
+ // src/storage/domains/scores/index.ts
10138
10118
  function parseJSON(value) {
10139
10119
  if (value === null || value === void 0) return void 0;
10140
10120
  if (typeof value === "string") {
@@ -10429,8 +10409,7 @@ var ScoresMySQL = class ScoresMySQL extends _mastra_core_storage.ScoresStorage {
10429
10409
  }), pagination);
10430
10410
  }
10431
10411
  };
10432
- //#endregion
10433
- //#region src/storage/domains/skills/index.ts
10412
+ // src/storage/domains/skills/index.ts
10434
10413
  const SNAPSHOT_FIELDS$1 = [
10435
10414
  "name",
10436
10415
  "description",
@@ -10990,8 +10969,7 @@ var SkillsMySQL = class SkillsMySQL extends _mastra_core_storage.SkillsStorage {
10990
10969
  }
10991
10970
  }
10992
10971
  };
10993
- //#endregion
10994
- //#region src/storage/domains/tool-provider-connections/index.ts
10972
+ // src/storage/domains/tool-provider-connections/index.ts
10995
10973
  function normaliseScope(raw) {
10996
10974
  const value = raw == null ? "per-author" : String(raw);
10997
10975
  if (value === "shared") return "shared";
@@ -11216,8 +11194,7 @@ var ToolProviderConnectionsMySQL = class ToolProviderConnectionsMySQL extends _m
11216
11194
  }
11217
11195
  }
11218
11196
  };
11219
- //#endregion
11220
- //#region src/storage/domains/workflow-definitions/index.ts
11197
+ // src/storage/domains/workflow-definitions/index.ts
11221
11198
  function rowToDefinition(row) {
11222
11199
  const transformed = transformFromSqlRow({
11223
11200
  tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
@@ -11358,8 +11335,7 @@ var WorkflowDefinitionsMySQL = class extends _mastra_core_storage.WorkflowDefini
11358
11335
  await this.pool.execute(`DELETE FROM ${formatTableName(_mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS, this.database)} WHERE ${quoteIdentifier("id", "column name")} = ?`, [id]);
11359
11336
  }
11360
11337
  };
11361
- //#endregion
11362
- //#region src/storage/domains/workflows/index.ts
11338
+ // src/storage/domains/workflows/index.ts
11363
11339
  function parseSnapshot(snapshot) {
11364
11340
  if (typeof snapshot === "string") try {
11365
11341
  return JSON.parse(snapshot);
@@ -11878,8 +11854,7 @@ var WorkflowsMySQL = class WorkflowsMySQL extends _mastra_core_storage.Workflows
11878
11854
  }
11879
11855
  }
11880
11856
  };
11881
- //#endregion
11882
- //#region src/storage/domains/workspaces/index.ts
11857
+ // src/storage/domains/workspaces/index.ts
11883
11858
  const SNAPSHOT_FIELDS = [
11884
11859
  "name",
11885
11860
  "description",
@@ -12397,8 +12372,7 @@ var WorkspacesMySQL = class WorkspacesMySQL extends _mastra_core_storage.Workspa
12397
12372
  }
12398
12373
  }
12399
12374
  };
12400
- //#endregion
12401
- //#region src/storage/index.ts
12375
+ // src/storage/index.ts
12402
12376
  function validateConfig(config) {
12403
12377
  if ("connectionString" in config) {
12404
12378
  if (!config.connectionString || typeof config.connectionString !== "string") throw new Error("MySQLStore: connectionString must be a non-empty string.");
@@ -12671,7 +12645,6 @@ var MySQLStore = class extends _mastra_core_storage.MastraCompositeStore {
12671
12645
  await this.pool.end();
12672
12646
  }
12673
12647
  };
12674
- //#endregion
12675
12648
  exports.AgentsMySQL = AgentsMySQL;
12676
12649
  exports.BlobsMySQL = BlobsMySQL;
12677
12650
  exports.DatasetsMySQL = DatasetsMySQL;