@mastra/cloudflare-d1 0.12.6 → 0.12.7-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.
package/dist/index.js CHANGED
@@ -920,6 +920,47 @@ var MemoryStorageD1 = class extends MemoryStorage {
920
920
  throw mastraError;
921
921
  }
922
922
  }
923
+ async getMessagesById({
924
+ messageIds,
925
+ format
926
+ }) {
927
+ if (messageIds.length === 0) return [];
928
+ const fullTableName = this.operations.getTableName(TABLE_MESSAGES);
929
+ const messages = [];
930
+ try {
931
+ const query = createSqlBuilder().select(["id", "content", "role", "type", "createdAt", "thread_id AS threadId", "resourceId"]).from(fullTableName).where(`id in (${messageIds.map(() => "?").join(",")})`, ...messageIds);
932
+ query.orderBy("createdAt", "DESC");
933
+ const { sql, params } = query.build();
934
+ const result = await this.operations.executeQuery({ sql, params });
935
+ if (Array.isArray(result)) messages.push(...result);
936
+ const processedMessages = messages.map((message) => {
937
+ const processedMsg = {};
938
+ for (const [key, value] of Object.entries(message)) {
939
+ if (key === `type` && value === `v2`) continue;
940
+ processedMsg[key] = deserializeValue(value);
941
+ }
942
+ return processedMsg;
943
+ });
944
+ this.logger.debug(`Retrieved ${messages.length} messages`);
945
+ const list = new MessageList().add(processedMessages, "memory");
946
+ if (format === `v1`) return list.get.all.v1();
947
+ return list.get.all.v2();
948
+ } catch (error) {
949
+ const mastraError = new MastraError(
950
+ {
951
+ id: "CLOUDFLARE_D1_STORAGE_GET_MESSAGES_BY_ID_ERROR",
952
+ domain: ErrorDomain.STORAGE,
953
+ category: ErrorCategory.THIRD_PARTY,
954
+ text: `Failed to retrieve messages by ID: ${error instanceof Error ? error.message : String(error)}`,
955
+ details: { messageIds: JSON.stringify(messageIds) }
956
+ },
957
+ error
958
+ );
959
+ this.logger?.error(mastraError.toString());
960
+ this.logger?.trackException(mastraError);
961
+ throw mastraError;
962
+ }
963
+ }
923
964
  async getMessagesPaginated({
924
965
  threadId,
925
966
  selectBy,
@@ -2241,6 +2282,12 @@ var D1Store = class extends MastraStorage {
2241
2282
  }) {
2242
2283
  return this.stores.memory.getMessages({ threadId, selectBy, format });
2243
2284
  }
2285
+ async getMessagesById({
2286
+ messageIds,
2287
+ format
2288
+ }) {
2289
+ return this.stores.memory.getMessagesById({ messageIds, format });
2290
+ }
2244
2291
  async getMessagesPaginated({
2245
2292
  threadId,
2246
2293
  selectBy,