@mastra/mysql 0.17.2-alpha.0 → 0.17.2-alpha.2

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.
@@ -96,4 +96,29 @@ export declare function assertActiveObservationsApplied(result: UpdateActiveObse
96
96
  * (equal, or only appended to since).
97
97
  */
98
98
  export declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
99
+ /** The buffered-reflection fields a `swapBufferedReflectionToActive` caller read, and the stored ones. */
100
+ export interface BufferedReflectionState {
101
+ bufferedReflection?: string | null;
102
+ reflectedObservationLineCount?: number | null;
103
+ }
104
+ /**
105
+ * Whether the stored buffered reflection and reflected line count are still the ones in
106
+ * `snapshot`, so a buffered-reflection swap activates exactly the buffer the caller read.
107
+ *
108
+ * Another writer can extend the buffer (`updateBufferedReflection` appends and moves the line
109
+ * count) after the caller's read. The activated text alone cannot tell the two apart: an
110
+ * extension that repeats the unreflected tail and moves the cut past it produces the same text.
111
+ * A snapshot without a buffered reflection (callers that never read one) is not checked.
112
+ */
113
+ export declare function isBufferedReflectionUnchangedSince(stored: BufferedReflectionState, snapshot: BufferedReflectionState): boolean;
114
+ /**
115
+ * The generation a buffered-reflection swap just created, marked with
116
+ * `bufferedReflectionVerified: true` when the swap checked the caller's buffered reflection with
117
+ * `isBufferedReflectionUnchangedSince` in the same atomic step. A snapshot without a buffered
118
+ * reflection was not checked, so its successor is returned unmarked. Always returns a new object,
119
+ * so a store's own record is never handed out or mutated.
120
+ */
121
+ export declare function withBufferedReflectionVerified<T extends object>(successor: T, snapshot: BufferedReflectionState): T & {
122
+ bufferedReflectionVerified?: true;
123
+ };
99
124
  //# 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.17.2-alpha.0"
6
+ version: "0.17.2-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.17.2-alpha.0",
2
+ "version": "0.17.2-alpha.2",
3
3
  "package": "@mastra/mysql",
4
4
  "exports": {
5
5
  "AgentsMySQL": {
@@ -20,52 +20,52 @@
20
20
  "ExperimentsMySQL": {
21
21
  "types": "dist/storage/domains/experiments/index.d.ts",
22
22
  "implementation": "dist/index.js",
23
- "line": 3098
23
+ "line": 3107
24
24
  },
25
25
  "MCPClientsMySQL": {
26
26
  "types": "dist/storage/domains/mcp-clients/index.d.ts",
27
27
  "implementation": "dist/index.js",
28
- "line": 6064
28
+ "line": 6073
29
29
  },
30
30
  "MCPServersMySQL": {
31
31
  "types": "dist/storage/domains/mcp-servers/index.d.ts",
32
32
  "implementation": "dist/index.js",
33
- "line": 6537
33
+ "line": 6546
34
34
  },
35
35
  "MemoryMySQL": {
36
36
  "types": "dist/storage/domains/memory/index.d.ts",
37
37
  "implementation": "dist/index.js",
38
- "line": 7271
38
+ "line": 7309
39
39
  },
40
40
  "MySQLStore": {
41
41
  "types": "dist/storage/index.d.ts",
42
42
  "implementation": "dist/index.js",
43
- "line": 13573
43
+ "line": 13612
44
44
  },
45
45
  "ObservabilityMySQL": {
46
46
  "types": "dist/storage/domains/observability/index.d.ts",
47
47
  "implementation": "dist/index.js",
48
- "line": 9385
48
+ "line": 9424
49
49
  },
50
50
  "PromptBlocksMySQL": {
51
51
  "types": "dist/storage/domains/prompt-blocks/index.d.ts",
52
52
  "implementation": "dist/index.js",
53
- "line": 9904
53
+ "line": 9943
54
54
  },
55
55
  "ScorerDefinitionsMySQL": {
56
56
  "types": "dist/storage/domains/scorer-definitions/index.d.ts",
57
57
  "implementation": "dist/index.js",
58
- "line": 10662
58
+ "line": 10701
59
59
  },
60
60
  "ScoresMySQL": {
61
61
  "types": "dist/storage/domains/scores/index.d.ts",
62
62
  "implementation": "dist/index.js",
63
- "line": 11149
63
+ "line": 11188
64
64
  },
65
65
  "SkillsMySQL": {
66
66
  "types": "dist/storage/domains/skills/index.d.ts",
67
67
  "implementation": "dist/index.js",
68
- "line": 11446
68
+ "line": 11485
69
69
  },
70
70
  "StoreOperationsMySQL": {
71
71
  "types": "dist/storage/domains/operations/index.d.ts",
@@ -75,12 +75,12 @@
75
75
  "WorkflowsMySQL": {
76
76
  "types": "dist/storage/domains/workflows/index.d.ts",
77
77
  "implementation": "dist/index.js",
78
- "line": 12414
78
+ "line": 12453
79
79
  },
80
80
  "WorkspacesMySQL": {
81
81
  "types": "dist/storage/domains/workspaces/index.d.ts",
82
82
  "implementation": "dist/index.js",
83
- "line": 12977
83
+ "line": 13016
84
84
  }
85
85
  },
86
86
  "modules": {}
package/dist/index.cjs CHANGED
@@ -2831,6 +2831,15 @@ var DatasetsMySQL = class DatasetsMySQL extends _mastra_core_storage.DatasetsSto
2831
2831
  };
2832
2832
  const perPage = (0, _mastra_core_storage.normalizePerPage)(perPageInput, 100);
2833
2833
  const { offset, perPage: perPageForResponse } = (0, _mastra_core_storage.calculatePagination)(page, perPageInput, perPage);
2834
+ if (perPage === 0) return {
2835
+ items: [],
2836
+ pagination: {
2837
+ total,
2838
+ page,
2839
+ perPage: perPageForResponse,
2840
+ hasMore: true
2841
+ }
2842
+ };
2834
2843
  const limitValue = perPageInput === false ? total : perPage;
2835
2844
  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);
2836
2845
  return {
@@ -7108,6 +7117,35 @@ function isAppendOnlySince(storedObservations, snapshotObservations) {
7108
7117
  const snapshot = snapshotObservations ?? "";
7109
7118
  return stored === snapshot || stored.startsWith(snapshot);
7110
7119
  }
7120
+ /**
7121
+ * Whether the stored buffered reflection and reflected line count are still the ones in
7122
+ * `snapshot`, so a buffered-reflection swap activates exactly the buffer the caller read.
7123
+ *
7124
+ * Another writer can extend the buffer (`updateBufferedReflection` appends and moves the line
7125
+ * count) after the caller's read. The activated text alone cannot tell the two apart: an
7126
+ * extension that repeats the unreflected tail and moves the cut past it produces the same text.
7127
+ * A snapshot without a buffered reflection (callers that never read one) is not checked.
7128
+ */
7129
+ function isBufferedReflectionUnchangedSince(stored, snapshot) {
7130
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return true;
7131
+ if ((stored.bufferedReflection ?? "") !== snapshot.bufferedReflection) return false;
7132
+ if (snapshot.reflectedObservationLineCount === void 0 || snapshot.reflectedObservationLineCount === null) return true;
7133
+ return (stored.reflectedObservationLineCount ?? 0) === snapshot.reflectedObservationLineCount;
7134
+ }
7135
+ /**
7136
+ * The generation a buffered-reflection swap just created, marked with
7137
+ * `bufferedReflectionVerified: true` when the swap checked the caller's buffered reflection with
7138
+ * `isBufferedReflectionUnchangedSince` in the same atomic step. A snapshot without a buffered
7139
+ * reflection was not checked, so its successor is returned unmarked. Always returns a new object,
7140
+ * so a store's own record is never handed out or mutated.
7141
+ */
7142
+ function withBufferedReflectionVerified(successor, snapshot) {
7143
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return { ...successor };
7144
+ return {
7145
+ ...successor,
7146
+ bufferedReflectionVerified: true
7147
+ };
7148
+ }
7111
7149
  // src/storage/db/run-fencing.ts
7112
7150
  /**
7113
7151
  * Epoch milliseconds on the database clock. `UTC_TIMESTAMP` is the time the
@@ -9153,11 +9191,12 @@ var MemoryMySQL = class MemoryMySQL extends _mastra_core_storage.MemoryStorage {
9153
9191
  details: { id: currentRecord.id }
9154
9192
  });
9155
9193
  if (!isAppendOnlySince(stored.activeObservations, currentRecord.activeObservations)) return stored;
9194
+ if (!isBufferedReflectionUnchangedSince(stored, currentRecord)) return stored;
9156
9195
  const reflectedLineCount = stored.reflectedObservationLineCount ?? 0;
9157
9196
  const unreflectedContent = (stored.activeObservations || "").split("\n").slice(reflectedLineCount).join("\n").trim();
9158
9197
  const newObservations = unreflectedContent ? `${bufferedReflection}\n\n${unreflectedContent}` : bufferedReflection;
9159
9198
  const tokenCount = input.tokenCount + Math.max(0, (stored.observationTokenCount ?? 0) - (currentRecord.observationTokenCount ?? 0));
9160
- return this.rollOverOMRow(connection, stored.id, newObservations, tokenCount, input.newRecordId, true);
9199
+ return withBufferedReflectionVerified(await this.rollOverOMRow(connection, stored.id, newObservations, tokenCount, input.newRecordId, true), currentRecord);
9161
9200
  }, "swapBufferedReflectionToActive");
9162
9201
  } catch (error) {
9163
9202
  rethrowOrWrapOM(error, input.currentRecord.id, "SWAP_BUFFERED_REFLECTION_TO_ACTIVE");
package/dist/index.js CHANGED
@@ -2830,6 +2830,15 @@ var DatasetsMySQL = class DatasetsMySQL extends DatasetsStorage {
2830
2830
  };
2831
2831
  const perPage = normalizePerPage(perPageInput, 100);
2832
2832
  const { offset, perPage: perPageForResponse } = calculatePagination(page, perPageInput, perPage);
2833
+ if (perPage === 0) return {
2834
+ items: [],
2835
+ pagination: {
2836
+ total,
2837
+ page,
2838
+ perPage: perPageForResponse,
2839
+ hasMore: true
2840
+ }
2841
+ };
2833
2842
  const limitValue = perPageInput === false ? total : perPage;
2834
2843
  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);
2835
2844
  return {
@@ -7107,6 +7116,35 @@ function isAppendOnlySince(storedObservations, snapshotObservations) {
7107
7116
  const snapshot = snapshotObservations ?? "";
7108
7117
  return stored === snapshot || stored.startsWith(snapshot);
7109
7118
  }
7119
+ /**
7120
+ * Whether the stored buffered reflection and reflected line count are still the ones in
7121
+ * `snapshot`, so a buffered-reflection swap activates exactly the buffer the caller read.
7122
+ *
7123
+ * Another writer can extend the buffer (`updateBufferedReflection` appends and moves the line
7124
+ * count) after the caller's read. The activated text alone cannot tell the two apart: an
7125
+ * extension that repeats the unreflected tail and moves the cut past it produces the same text.
7126
+ * A snapshot without a buffered reflection (callers that never read one) is not checked.
7127
+ */
7128
+ function isBufferedReflectionUnchangedSince(stored, snapshot) {
7129
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return true;
7130
+ if ((stored.bufferedReflection ?? "") !== snapshot.bufferedReflection) return false;
7131
+ if (snapshot.reflectedObservationLineCount === void 0 || snapshot.reflectedObservationLineCount === null) return true;
7132
+ return (stored.reflectedObservationLineCount ?? 0) === snapshot.reflectedObservationLineCount;
7133
+ }
7134
+ /**
7135
+ * The generation a buffered-reflection swap just created, marked with
7136
+ * `bufferedReflectionVerified: true` when the swap checked the caller's buffered reflection with
7137
+ * `isBufferedReflectionUnchangedSince` in the same atomic step. A snapshot without a buffered
7138
+ * reflection was not checked, so its successor is returned unmarked. Always returns a new object,
7139
+ * so a store's own record is never handed out or mutated.
7140
+ */
7141
+ function withBufferedReflectionVerified(successor, snapshot) {
7142
+ if (snapshot.bufferedReflection === void 0 || snapshot.bufferedReflection === null) return { ...successor };
7143
+ return {
7144
+ ...successor,
7145
+ bufferedReflectionVerified: true
7146
+ };
7147
+ }
7110
7148
  // src/storage/db/run-fencing.ts
7111
7149
  /**
7112
7150
  * Epoch milliseconds on the database clock. `UTC_TIMESTAMP` is the time the
@@ -9152,11 +9190,12 @@ var MemoryMySQL = class MemoryMySQL extends MemoryStorage {
9152
9190
  details: { id: currentRecord.id }
9153
9191
  });
9154
9192
  if (!isAppendOnlySince(stored.activeObservations, currentRecord.activeObservations)) return stored;
9193
+ if (!isBufferedReflectionUnchangedSince(stored, currentRecord)) return stored;
9155
9194
  const reflectedLineCount = stored.reflectedObservationLineCount ?? 0;
9156
9195
  const unreflectedContent = (stored.activeObservations || "").split("\n").slice(reflectedLineCount).join("\n").trim();
9157
9196
  const newObservations = unreflectedContent ? `${bufferedReflection}\n\n${unreflectedContent}` : bufferedReflection;
9158
9197
  const tokenCount = input.tokenCount + Math.max(0, (stored.observationTokenCount ?? 0) - (currentRecord.observationTokenCount ?? 0));
9159
- return this.rollOverOMRow(connection, stored.id, newObservations, tokenCount, input.newRecordId, true);
9198
+ return withBufferedReflectionVerified(await this.rollOverOMRow(connection, stored.id, newObservations, tokenCount, input.newRecordId, true), currentRecord);
9160
9199
  }, "swapBufferedReflectionToActive");
9161
9200
  } catch (error) {
9162
9201
  rethrowOrWrapOM(error, input.currentRecord.id, "SWAP_BUFFERED_REFLECTION_TO_ACTIVE");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mysql",
3
- "version": "0.17.2-alpha.0",
3
+ "version": "0.17.2-alpha.2",
4
4
  "description": "MySQL provider for Mastra - db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -34,7 +34,7 @@
34
34
  "@internal/lint": "0.0.151",
35
35
  "@internal/storage-test-utils": "0.0.147",
36
36
  "@internal/types-builder": "0.0.126",
37
- "@mastra/core": "1.86.0-alpha.6"
37
+ "@mastra/core": "1.86.0-alpha.8"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@mastra/core": ">=1.76.0-0 <2.0.0-0"