From e396c3b755669579c51adea6eda1c306f9d6b502 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Wed, 10 Dec 2025 15:17:18 -0500 Subject: [PATCH] refactor: cleaner API for storage in LocalHistoryOptions --- .../sds/src/message_channel/local_history.ts | 21 +++++++++++-------- .../storage/message_serializer.ts | 6 ++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/sds/src/message_channel/local_history.ts b/packages/sds/src/message_channel/local_history.ts index 6a099ee8e9..a8d332a7ff 100644 --- a/packages/sds/src/message_channel/local_history.ts +++ b/packages/sds/src/message_channel/local_history.ts @@ -21,8 +21,10 @@ export const DEFAULT_MAX_LENGTH = 10_000; */ export type LocalHistoryOptions = { - storagePrefix?: string; - storage?: Storage; + storage?: { + prefix?: string; + customInstance?: Storage; + }; maxSize?: number; }; @@ -42,14 +44,15 @@ export class LocalHistory { * - maxSize: The maximum number of messages to store. Optional, defaults to DEFAULT_MAX_LENGTH. */ public constructor(opts: LocalHistoryOptions = {}) { - const { storagePrefix, storage, maxSize } = opts; + const { storage, maxSize } = opts; + const { prefix, customInstance } = storage ?? {}; this.maxSize = maxSize ?? DEFAULT_MAX_LENGTH; - if (storage) { - this.storage = storage; - log.info("Using explicit storage"); - } else if (storagePrefix) { - this.storage = new Storage(storagePrefix); - log.info("Creating storage for prefix", storagePrefix); + if (customInstance) { + this.storage = customInstance; + log.info("Using custom storage instance", { customInstance }); + } else if (prefix) { + this.storage = new Storage(prefix); + log.info("Creating storage with prefix", { prefix }); } else { this.storage = undefined; log.info("Using in-memory storage"); diff --git a/packages/sds/src/message_channel/storage/message_serializer.ts b/packages/sds/src/message_channel/storage/message_serializer.ts index 034d688d36..49bf4c8f90 100644 --- a/packages/sds/src/message_channel/storage/message_serializer.ts +++ b/packages/sds/src/message_channel/storage/message_serializer.ts @@ -59,7 +59,7 @@ export class MessageSerializer { } } - public static serializeCausalEntry(entry: HistoryEntry): StoredCausalEntry { + private static serializeCausalEntry(entry: HistoryEntry): StoredCausalEntry { return { messageId: entry.messageId, retrievalHint: entry.retrievalHint @@ -68,7 +68,9 @@ export class MessageSerializer { }; } - public static deserializeCausalEntry(entry: StoredCausalEntry): HistoryEntry { + private static deserializeCausalEntry( + entry: StoredCausalEntry + ): HistoryEntry { return { messageId: entry.messageId, retrievalHint: entry.retrievalHint