Skip to content

Commit d2ab233

Browse files
refactor: cleaner API for storage in LocalHistoryOptions
1 parent af89d5f commit d2ab233

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/sds/src/message_channel/local_history.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ export const DEFAULT_MAX_LENGTH = 10_000;
2121
*/
2222

2323
export type LocalHistoryOptions = {
24-
storagePrefix?: string;
25-
storage?: Storage;
24+
storage?: {
25+
prefix?: string;
26+
customInstance?: Storage;
27+
};
2628
maxSize?: number;
2729
};
2830

@@ -42,14 +44,15 @@ export class LocalHistory {
4244
* - maxSize: The maximum number of messages to store. Optional, defaults to DEFAULT_MAX_LENGTH.
4345
*/
4446
public constructor(opts: LocalHistoryOptions = {}) {
45-
const { storagePrefix, storage, maxSize } = opts;
47+
const { storage, maxSize } = opts;
48+
const { prefix, customInstance } = storage ?? {};
4649
this.maxSize = maxSize ?? DEFAULT_MAX_LENGTH;
47-
if (storage) {
48-
this.storage = storage;
49-
log.info("Using explicit storage");
50-
} else if (storagePrefix) {
51-
this.storage = new Storage(storagePrefix);
52-
log.info("Creating storage for prefix", storagePrefix);
50+
if (customInstance) {
51+
this.storage = customInstance;
52+
log.info("Using custom storage instance", { customInstance });
53+
} else if (prefix) {
54+
this.storage = new Storage(prefix);
55+
log.info("Creating storage with prefix", { prefix });
5356
} else {
5457
this.storage = undefined;
5558
log.info("Using in-memory storage");

packages/sds/src/message_channel/storage/message_serializer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class MessageSerializer {
5959
}
6060
}
6161

62-
public static serializeCausalEntry(entry: HistoryEntry): StoredCausalEntry {
62+
private static serializeCausalEntry(entry: HistoryEntry): StoredCausalEntry {
6363
return {
6464
messageId: entry.messageId,
6565
retrievalHint: entry.retrievalHint
@@ -68,7 +68,9 @@ export class MessageSerializer {
6868
};
6969
}
7070

71-
public static deserializeCausalEntry(entry: StoredCausalEntry): HistoryEntry {
71+
private static deserializeCausalEntry(
72+
entry: StoredCausalEntry
73+
): HistoryEntry {
7274
return {
7375
messageId: entry.messageId,
7476
retrievalHint: entry.retrievalHint

0 commit comments

Comments
 (0)