@mastra/dynamodb 0.0.0-zod-v4-compat-part-2-20250822105954 → 0.0.0-zod-v4-stuff-20250825154219

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.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './storage';
1
+ export * from './storage/index.js';
2
2
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -418,6 +418,28 @@ var scoreEntity = new Entity({
418
418
  return value;
419
419
  }
420
420
  },
421
+ preprocessStepResult: {
422
+ type: "string",
423
+ required: false,
424
+ set: (value) => {
425
+ if (value && typeof value !== "string") {
426
+ return JSON.stringify(value);
427
+ }
428
+ return value;
429
+ },
430
+ get: (value) => {
431
+ if (value && typeof value === "string") {
432
+ try {
433
+ if (value.startsWith("{") || value.startsWith("[")) {
434
+ return JSON.parse(value);
435
+ }
436
+ } catch {
437
+ return value;
438
+ }
439
+ }
440
+ return value;
441
+ }
442
+ },
421
443
  analyzeStepResult: {
422
444
  type: "string",
423
445
  required: false,
@@ -456,10 +478,19 @@ var scoreEntity = new Entity({
456
478
  type: "string",
457
479
  required: false
458
480
  },
481
+ // Deprecated in favor of generateReasonPrompt
459
482
  reasonPrompt: {
460
483
  type: "string",
461
484
  required: false
462
485
  },
486
+ generateScorePrompt: {
487
+ type: "string",
488
+ required: false
489
+ },
490
+ generateReasonPrompt: {
491
+ type: "string",
492
+ required: false
493
+ },
463
494
  input: {
464
495
  type: "string",
465
496
  required: true,
@@ -1090,6 +1121,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1090
1121
  // transformed by the ElectroDB entity getters.
1091
1122
  };
1092
1123
  }
1124
+ // Helper function to transform and sort threads
1125
+ transformAndSortThreads(rawThreads, orderBy, sortDirection) {
1126
+ return rawThreads.map((data) => ({
1127
+ ...data,
1128
+ // Convert date strings back to Date objects for consistency
1129
+ createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1130
+ updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1131
+ })).sort((a, b) => {
1132
+ const fieldA = orderBy === "createdAt" ? a.createdAt : a.updatedAt;
1133
+ const fieldB = orderBy === "createdAt" ? b.createdAt : b.updatedAt;
1134
+ const comparison = fieldA.getTime() - fieldB.getTime();
1135
+ return sortDirection === "DESC" ? -comparison : comparison;
1136
+ });
1137
+ }
1093
1138
  async getThreadById({ threadId }) {
1094
1139
  this.logger.debug("Getting thread by ID", { threadId });
1095
1140
  try {
@@ -1118,21 +1163,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1118
1163
  );
1119
1164
  }
1120
1165
  }
1121
- async getThreadsByResourceId({ resourceId }) {
1122
- this.logger.debug("Getting threads by resource ID", { resourceId });
1166
+ /**
1167
+ * @deprecated use getThreadsByResourceIdPaginated instead for paginated results.
1168
+ */
1169
+ async getThreadsByResourceId(args) {
1170
+ const resourceId = args.resourceId;
1171
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1172
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1173
+ this.logger.debug("Getting threads by resource ID", { resourceId, orderBy, sortDirection });
1123
1174
  try {
1124
1175
  const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
1125
1176
  if (!result.data.length) {
1126
1177
  return [];
1127
1178
  }
1128
- return result.data.map((data) => ({
1129
- ...data,
1130
- // Convert date strings back to Date objects for consistency
1131
- createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1132
- updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1133
- // metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
1134
- // metadata is already transformed by the entity's getter
1135
- }));
1179
+ return this.transformAndSortThreads(result.data, orderBy, sortDirection);
1136
1180
  } catch (error) {
1137
1181
  throw new MastraError(
1138
1182
  {
@@ -1154,7 +1198,7 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1154
1198
  resourceId: thread.resourceId,
1155
1199
  title: thread.title || `Thread ${thread.id}`,
1156
1200
  createdAt: thread.createdAt?.toISOString() || now.toISOString(),
1157
- updatedAt: now.toISOString(),
1201
+ updatedAt: thread.updatedAt?.toISOString() || now.toISOString(),
1158
1202
  metadata: thread.metadata ? JSON.stringify(thread.metadata) : void 0
1159
1203
  };
1160
1204
  try {
@@ -1315,6 +1359,36 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1315
1359
  );
1316
1360
  }
1317
1361
  }
1362
+ async getMessagesById({
1363
+ messageIds,
1364
+ format
1365
+ }) {
1366
+ this.logger.debug("Getting messages by ID", { messageIds });
1367
+ if (messageIds.length === 0) return [];
1368
+ try {
1369
+ const results = await Promise.all(
1370
+ messageIds.map((id) => this.service.entities.message.query.primary({ entity: "message", id }).go())
1371
+ );
1372
+ const data = results.map((result) => result.data).flat(1);
1373
+ let parsedMessages = data.map((data2) => this.parseMessageData(data2)).filter((msg) => "content" in msg);
1374
+ const uniqueMessages = parsedMessages.filter(
1375
+ (message, index, self) => index === self.findIndex((m) => m.id === message.id)
1376
+ );
1377
+ const list = new MessageList().add(uniqueMessages, "memory");
1378
+ if (format === `v1`) return list.get.all.v1();
1379
+ return list.get.all.v2();
1380
+ } catch (error) {
1381
+ throw new MastraError(
1382
+ {
1383
+ id: "STORAGE_DYNAMODB_STORE_GET_MESSAGES_BY_ID_FAILED",
1384
+ domain: ErrorDomain.STORAGE,
1385
+ category: ErrorCategory.THIRD_PARTY,
1386
+ details: { messageIds: JSON.stringify(messageIds) }
1387
+ },
1388
+ error
1389
+ );
1390
+ }
1391
+ }
1318
1392
  async saveMessages(args) {
1319
1393
  const { messages, format = "v1" } = args;
1320
1394
  this.logger.debug("Saving messages", { count: messages.length });
@@ -1389,11 +1463,19 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1389
1463
  }
1390
1464
  async getThreadsByResourceIdPaginated(args) {
1391
1465
  const { resourceId, page = 0, perPage = 100 } = args;
1392
- this.logger.debug("Getting threads by resource ID with pagination", { resourceId, page, perPage });
1466
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1467
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1468
+ this.logger.debug("Getting threads by resource ID with pagination", {
1469
+ resourceId,
1470
+ page,
1471
+ perPage,
1472
+ orderBy,
1473
+ sortDirection
1474
+ });
1393
1475
  try {
1394
1476
  const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
1395
1477
  const results = await query.go();
1396
- const allThreads = results.data;
1478
+ const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
1397
1479
  const startIndex = page * perPage;
1398
1480
  const endIndex = startIndex + perPage;
1399
1481
  const paginatedThreads = allThreads.slice(startIndex, endIndex);
@@ -2097,11 +2179,12 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2097
2179
  traceId: score.traceId || "",
2098
2180
  runId: score.runId,
2099
2181
  scorer: typeof score.scorer === "string" ? score.scorer : JSON.stringify(score.scorer),
2100
- extractStepResult: typeof score.extractStepResult === "string" ? score.extractStepResult : JSON.stringify(score.extractStepResult),
2182
+ preprocessStepResult: typeof score.preprocessStepResult === "string" ? score.preprocessStepResult : JSON.stringify(score.preprocessStepResult),
2101
2183
  analyzeStepResult: typeof score.analyzeStepResult === "string" ? score.analyzeStepResult : JSON.stringify(score.analyzeStepResult),
2102
2184
  score: score.score,
2103
2185
  reason: score.reason,
2104
- extractPrompt: score.extractPrompt,
2186
+ preprocessPrompt: score.preprocessPrompt,
2187
+ generateScorePrompt: score.generateScorePrompt,
2105
2188
  analyzePrompt: score.analyzePrompt,
2106
2189
  reasonPrompt: score.reasonPrompt,
2107
2190
  input: typeof score.input === "string" ? score.input : JSON.stringify(score.input),
@@ -2142,9 +2225,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2142
2225
  scorerId,
2143
2226
  pagination,
2144
2227
  entityId,
2145
- entityType
2228
+ entityType,
2229
+ source
2146
2230
  }) {
2147
- this.logger.debug("Getting scores by scorer ID", { scorerId, pagination, entityId, entityType });
2148
2231
  try {
2149
2232
  const query = this.service.entities.score.query.byScorer({ entity: "score", scorerId });
2150
2233
  const results = await query.go();
@@ -2155,6 +2238,9 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2155
2238
  if (entityType) {
2156
2239
  allScores = allScores.filter((score) => score.entityType === entityType);
2157
2240
  }
2241
+ if (source) {
2242
+ allScores = allScores.filter((score) => score.source === source);
2243
+ }
2158
2244
  allScores.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2159
2245
  const startIndex = pagination.page * pagination.perPage;
2160
2246
  const endIndex = startIndex + pagination.perPage;
@@ -2180,6 +2266,7 @@ var ScoresStorageDynamoDB = class extends ScoresStorage {
2180
2266
  scorerId: scorerId || "",
2181
2267
  entityId: entityId || "",
2182
2268
  entityType: entityType || "",
2269
+ source: source || "",
2183
2270
  page: pagination.page,
2184
2271
  perPage: pagination.perPage
2185
2272
  }
@@ -2857,8 +2944,8 @@ var DynamoDBStore = class extends MastraStorage {
2857
2944
  async getThreadById({ threadId }) {
2858
2945
  return this.stores.memory.getThreadById({ threadId });
2859
2946
  }
2860
- async getThreadsByResourceId({ resourceId }) {
2861
- return this.stores.memory.getThreadsByResourceId({ resourceId });
2947
+ async getThreadsByResourceId(args) {
2948
+ return this.stores.memory.getThreadsByResourceId(args);
2862
2949
  }
2863
2950
  async saveThread({ thread }) {
2864
2951
  return this.stores.memory.saveThread({ thread });
@@ -2881,6 +2968,12 @@ var DynamoDBStore = class extends MastraStorage {
2881
2968
  }) {
2882
2969
  return this.stores.memory.getMessages({ threadId, resourceId, selectBy, format });
2883
2970
  }
2971
+ async getMessagesById({
2972
+ messageIds,
2973
+ format
2974
+ }) {
2975
+ return this.stores.memory.getMessagesById({ messageIds, format });
2976
+ }
2884
2977
  async saveMessages(args) {
2885
2978
  return this.stores.memory.saveMessages(args);
2886
2979
  }
@@ -2990,10 +3083,13 @@ var DynamoDBStore = class extends MastraStorage {
2990
3083
  });
2991
3084
  }
2992
3085
  async getScoresByScorerId({
2993
- scorerId: _scorerId,
2994
- pagination: _pagination
3086
+ scorerId,
3087
+ source,
3088
+ entityId,
3089
+ entityType,
3090
+ pagination
2995
3091
  }) {
2996
- return this.stores.scores.getScoresByScorerId({ scorerId: _scorerId, pagination: _pagination });
3092
+ return this.stores.scores.getScoresByScorerId({ scorerId, source, entityId, entityType, pagination });
2997
3093
  }
2998
3094
  };
2999
3095