mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 00:33: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 {
|
export interface PersistentHistoryOptions {
|
||||||
channelId: ChannelId;
|
channelId: ChannelId;
|
||||||
storage?: HistoryStorage;
|
storage?: HistoryStorage;
|
||||||
storageKeyPrefix?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type StoredHistoryEntry = {
|
type StoredHistoryEntry = {
|
||||||
@ -45,8 +44,8 @@ export class PersistentHistory implements ILocalHistory {
|
|||||||
|
|
||||||
public constructor(options: PersistentHistoryOptions) {
|
public constructor(options: PersistentHistoryOptions) {
|
||||||
this.memory = new MemLocalHistory();
|
this.memory = new MemLocalHistory();
|
||||||
this.storage = options.storage ?? getDefaultHistoryStorage();
|
this.storage = options.storage || localStorage;
|
||||||
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.storageKeyPrefix}:${options.channelId}`;
|
this.storageKey = `${HISTORY_STORAGE_PREFIX}${options.channelId}`;
|
||||||
this.load();
|
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 => ({
|
const serializeHistoryEntry = (entry: HistoryEntry): StoredHistoryEntry => ({
|
||||||
messageId: entry.messageId,
|
messageId: entry.messageId,
|
||||||
retrievalHint: entry.retrievalHint
|
retrievalHint: entry.retrievalHint
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user