mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
feat: remove storageKeyPrefix and getDefaultHistoryStorage, simplifying history storage initialization to default to localStorage
This commit is contained in:
parent
322240b2d0
commit
15f1a22f2e
@ -12,7 +12,6 @@ export interface HistoryStorage {
|
||||
export interface PersistentHistoryOptions {
|
||||
channelId: ChannelId;
|
||||
storage?: HistoryStorage;
|
||||
storageKeyPrefix?: string;
|
||||
}
|
||||
|
||||
type StoredHistoryEntry = {
|
||||
@ -45,8 +44,8 @@ export class PersistentHistory implements ILocalHistory {
|
||||
|
||||
public constructor(options: PersistentHistoryOptions) {
|
||||
this.memory = new MemLocalHistory();
|
||||
this.storage = options.storage ?? getDefaultHistoryStorage();
|
||||
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.storageKeyPrefix}:${options.channelId}`;
|
||||
this.storage = options.storage || localStorage;
|
||||
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`;
|
||||
this.load();
|
||||
}
|
||||
|
||||
@ -132,21 +131,6 @@ export class PersistentHistory implements ILocalHistory {
|
||||
}
|
||||
}
|
||||
|
||||
export const getDefaultHistoryStorage = (): HistoryStorage | undefined => {
|
||||
try {
|
||||
if (typeof localStorage === "undefined") {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const probeKey = `${HISTORY_STORAGE_PREFIX}__probe__`;
|
||||
localStorage.setItem(probeKey, probeKey);
|
||||
localStorage.removeItem(probeKey);
|
||||
return localStorage;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const serializeHistoryEntry = (entry: HistoryEntry): StoredHistoryEntry => ({
|
||||
messageId: entry.messageId,
|
||||
retrievalHint: entry.retrievalHint
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user