@mastra/dynamodb 0.14.0-alpha.0 → 0.14.0-alpha.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.
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
@@ -1121,6 +1121,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1121
1121
  // transformed by the ElectroDB entity getters.
1122
1122
  };
1123
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
+ }
1124
1138
  async getThreadById({ threadId }) {
1125
1139
  this.logger.debug("Getting thread by ID", { threadId });
1126
1140
  try {
@@ -1149,21 +1163,20 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1149
1163
  );
1150
1164
  }
1151
1165
  }
1152
- async getThreadsByResourceId({ resourceId }) {
1153
- 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 });
1154
1174
  try {
1155
1175
  const result = await this.service.entities.thread.query.byResource({ entity: "thread", resourceId }).go();
1156
1176
  if (!result.data.length) {
1157
1177
  return [];
1158
1178
  }
1159
- return result.data.map((data) => ({
1160
- ...data,
1161
- // Convert date strings back to Date objects for consistency
1162
- createdAt: typeof data.createdAt === "string" ? new Date(data.createdAt) : data.createdAt,
1163
- updatedAt: typeof data.updatedAt === "string" ? new Date(data.updatedAt) : data.updatedAt
1164
- // metadata: data.metadata ? JSON.parse(data.metadata) : undefined, // REMOVED by AI
1165
- // metadata is already transformed by the entity's getter
1166
- }));
1179
+ return this.transformAndSortThreads(result.data, orderBy, sortDirection);
1167
1180
  } catch (error) {
1168
1181
  throw new MastraError(
1169
1182
  {
@@ -1420,11 +1433,19 @@ var MemoryStorageDynamoDB = class extends MemoryStorage {
1420
1433
  }
1421
1434
  async getThreadsByResourceIdPaginated(args) {
1422
1435
  const { resourceId, page = 0, perPage = 100 } = args;
1423
- this.logger.debug("Getting threads by resource ID with pagination", { resourceId, page, perPage });
1436
+ const orderBy = this.castThreadOrderBy(args.orderBy);
1437
+ const sortDirection = this.castThreadSortDirection(args.sortDirection);
1438
+ this.logger.debug("Getting threads by resource ID with pagination", {
1439
+ resourceId,
1440
+ page,
1441
+ perPage,
1442
+ orderBy,
1443
+ sortDirection
1444
+ });
1424
1445
  try {
1425
1446
  const query = this.service.entities.thread.query.byResource({ entity: "thread", resourceId });
1426
1447
  const results = await query.go();
1427
- const allThreads = results.data;
1448
+ const allThreads = this.transformAndSortThreads(results.data, orderBy, sortDirection);
1428
1449
  const startIndex = page * perPage;
1429
1450
  const endIndex = startIndex + perPage;
1430
1451
  const paginatedThreads = allThreads.slice(startIndex, endIndex);
@@ -2889,8 +2910,8 @@ var DynamoDBStore = class extends MastraStorage {
2889
2910
  async getThreadById({ threadId }) {
2890
2911
  return this.stores.memory.getThreadById({ threadId });
2891
2912
  }
2892
- async getThreadsByResourceId({ resourceId }) {
2893
- return this.stores.memory.getThreadsByResourceId({ resourceId });
2913
+ async getThreadsByResourceId(args) {
2914
+ return this.stores.memory.getThreadsByResourceId(args);
2894
2915
  }
2895
2916
  async saveThread({ thread }) {
2896
2917
  return this.stores.memory.saveThread({ thread });