@mastra/cloudflare 0.10.0 → 0.10.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.
@@ -55,6 +55,20 @@ declare class CloudflareStore extends MastraStorage {
55
55
  private createNamespace;
56
56
  private getOrCreateNamespaceId;
57
57
  private getNamespaceId;
58
+ private LEGACY_NAMESPACE_MAP;
59
+ /**
60
+ * There were a few legacy mappings for tables such as
61
+ * - messages -> threads
62
+ * - workflow_snapshot -> mastra_workflows
63
+ * - traces -> evals
64
+ * This has been updated to use dedicated namespaces for each table.
65
+ * In the case of data for a table existing in the legacy namespace, warn the user to migrate to the new namespace.
66
+ *
67
+ * @param tableName The table name to check for legacy data
68
+ * @param prefix The namespace prefix
69
+ * @returns The legacy namespace ID if data exists; otherwise, null
70
+ */
71
+ private checkLegacyNamespace;
58
72
  /**
59
73
  * Helper to safely serialize data for KV storage
60
74
  */
@@ -55,6 +55,20 @@ declare class CloudflareStore extends MastraStorage {
55
55
  private createNamespace;
56
56
  private getOrCreateNamespaceId;
57
57
  private getNamespaceId;
58
+ private LEGACY_NAMESPACE_MAP;
59
+ /**
60
+ * There were a few legacy mappings for tables such as
61
+ * - messages -> threads
62
+ * - workflow_snapshot -> mastra_workflows
63
+ * - traces -> evals
64
+ * This has been updated to use dedicated namespaces for each table.
65
+ * In the case of data for a table existing in the legacy namespace, warn the user to migrate to the new namespace.
66
+ *
67
+ * @param tableName The table name to check for legacy data
68
+ * @param prefix The namespace prefix
69
+ * @returns The legacy namespace ID if data exists; otherwise, null
70
+ */
71
+ private checkLegacyNamespace;
58
72
  /**
59
73
  * Helper to safely serialize data for KV storage
60
74
  */
package/dist/index.cjs CHANGED
@@ -219,18 +219,57 @@ var CloudflareStore = class extends storage.MastraStorage {
219
219
  async getNamespaceId(tableName) {
220
220
  const prefix = this.namespacePrefix ? `${this.namespacePrefix}_` : "";
221
221
  try {
222
- if (tableName === storage.TABLE_MESSAGES || tableName === storage.TABLE_THREADS) {
223
- return await this.getOrCreateNamespaceId(`${prefix}mastra_threads`);
224
- } else if (tableName === storage.TABLE_WORKFLOW_SNAPSHOT) {
225
- return await this.getOrCreateNamespaceId(`${prefix}mastra_workflows`);
226
- } else {
227
- return await this.getOrCreateNamespaceId(`${prefix}mastra_evals`);
222
+ const legacyNamespaceId = await this.checkLegacyNamespace(tableName, prefix);
223
+ if (legacyNamespaceId) {
224
+ return legacyNamespaceId;
228
225
  }
226
+ return await this.getOrCreateNamespaceId(`${prefix}${tableName}`);
229
227
  } catch (error) {
230
228
  this.logger.error("Error fetching namespace ID:", error);
231
229
  throw new Error(`Failed to fetch namespace ID for table ${tableName}: ${error.message}`);
232
230
  }
233
231
  }
232
+ LEGACY_NAMESPACE_MAP = {
233
+ [storage.TABLE_MESSAGES]: storage.TABLE_THREADS,
234
+ [storage.TABLE_WORKFLOW_SNAPSHOT]: "mastra_workflows",
235
+ [storage.TABLE_TRACES]: storage.TABLE_EVALS
236
+ };
237
+ /**
238
+ * There were a few legacy mappings for tables such as
239
+ * - messages -> threads
240
+ * - workflow_snapshot -> mastra_workflows
241
+ * - traces -> evals
242
+ * This has been updated to use dedicated namespaces for each table.
243
+ * In the case of data for a table existing in the legacy namespace, warn the user to migrate to the new namespace.
244
+ *
245
+ * @param tableName The table name to check for legacy data
246
+ * @param prefix The namespace prefix
247
+ * @returns The legacy namespace ID if data exists; otherwise, null
248
+ */
249
+ async checkLegacyNamespace(tableName, prefix) {
250
+ const legacyNamespaceBase = this.LEGACY_NAMESPACE_MAP[tableName];
251
+ if (legacyNamespaceBase) {
252
+ const legacyNamespace = `${prefix}${legacyNamespaceBase}`;
253
+ const keyPrefix = this.namespacePrefix ? `${this.namespacePrefix}:` : "";
254
+ const prefixKey = `${keyPrefix}${tableName}:`;
255
+ const legacyId = await this.getNamespaceIdByName(legacyNamespace);
256
+ if (legacyId) {
257
+ const response = await this.client.kv.namespaces.keys.list(legacyId, {
258
+ account_id: this.accountId,
259
+ prefix: prefixKey
260
+ });
261
+ const keys = response.result;
262
+ const hasTableData = keys.length > 0;
263
+ if (hasTableData) {
264
+ this.logger.warn(
265
+ `Using legacy namespace "${legacyNamespace}" for ${tableName}. Consider migrating to a dedicated namespace "${prefix}${tableName}".`
266
+ );
267
+ return legacyId;
268
+ }
269
+ }
270
+ }
271
+ return null;
272
+ }
234
273
  /**
235
274
  * Helper to safely serialize data for KV storage
236
275
  */
package/dist/index.js CHANGED
@@ -213,18 +213,57 @@ var CloudflareStore = class extends MastraStorage {
213
213
  async getNamespaceId(tableName) {
214
214
  const prefix = this.namespacePrefix ? `${this.namespacePrefix}_` : "";
215
215
  try {
216
- if (tableName === TABLE_MESSAGES || tableName === TABLE_THREADS) {
217
- return await this.getOrCreateNamespaceId(`${prefix}mastra_threads`);
218
- } else if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
219
- return await this.getOrCreateNamespaceId(`${prefix}mastra_workflows`);
220
- } else {
221
- return await this.getOrCreateNamespaceId(`${prefix}mastra_evals`);
216
+ const legacyNamespaceId = await this.checkLegacyNamespace(tableName, prefix);
217
+ if (legacyNamespaceId) {
218
+ return legacyNamespaceId;
222
219
  }
220
+ return await this.getOrCreateNamespaceId(`${prefix}${tableName}`);
223
221
  } catch (error) {
224
222
  this.logger.error("Error fetching namespace ID:", error);
225
223
  throw new Error(`Failed to fetch namespace ID for table ${tableName}: ${error.message}`);
226
224
  }
227
225
  }
226
+ LEGACY_NAMESPACE_MAP = {
227
+ [TABLE_MESSAGES]: TABLE_THREADS,
228
+ [TABLE_WORKFLOW_SNAPSHOT]: "mastra_workflows",
229
+ [TABLE_TRACES]: TABLE_EVALS
230
+ };
231
+ /**
232
+ * There were a few legacy mappings for tables such as
233
+ * - messages -> threads
234
+ * - workflow_snapshot -> mastra_workflows
235
+ * - traces -> evals
236
+ * This has been updated to use dedicated namespaces for each table.
237
+ * In the case of data for a table existing in the legacy namespace, warn the user to migrate to the new namespace.
238
+ *
239
+ * @param tableName The table name to check for legacy data
240
+ * @param prefix The namespace prefix
241
+ * @returns The legacy namespace ID if data exists; otherwise, null
242
+ */
243
+ async checkLegacyNamespace(tableName, prefix) {
244
+ const legacyNamespaceBase = this.LEGACY_NAMESPACE_MAP[tableName];
245
+ if (legacyNamespaceBase) {
246
+ const legacyNamespace = `${prefix}${legacyNamespaceBase}`;
247
+ const keyPrefix = this.namespacePrefix ? `${this.namespacePrefix}:` : "";
248
+ const prefixKey = `${keyPrefix}${tableName}:`;
249
+ const legacyId = await this.getNamespaceIdByName(legacyNamespace);
250
+ if (legacyId) {
251
+ const response = await this.client.kv.namespaces.keys.list(legacyId, {
252
+ account_id: this.accountId,
253
+ prefix: prefixKey
254
+ });
255
+ const keys = response.result;
256
+ const hasTableData = keys.length > 0;
257
+ if (hasTableData) {
258
+ this.logger.warn(
259
+ `Using legacy namespace "${legacyNamespace}" for ${tableName}. Consider migrating to a dedicated namespace "${prefix}${tableName}".`
260
+ );
261
+ return legacyId;
262
+ }
263
+ }
264
+ }
265
+ return null;
266
+ }
228
267
  /**
229
268
  * Helper to safely serialize data for KV storage
230
269
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/cloudflare",
3
- "version": "0.10.0",
3
+ "version": "0.10.1-alpha.0",
4
4
  "description": "Cloudflare provider for Mastra - includes db storage capabilities",
5
5
  "type": "module",
6
6
  "files": [
@@ -36,7 +36,7 @@
36
36
  "typescript": "^5.8.2",
37
37
  "vitest": "^3.1.2",
38
38
  "@internal/lint": "0.0.6",
39
- "@mastra/core": "0.10.0"
39
+ "@mastra/core": "0.10.1-alpha.1"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@mastra/core": "^0.10.0"