Class IndexedDBStore

A store for most of the data js-sdk needs to store, apart from crypto data

Hierarchy

Constructors

  • Construct a new Indexed Database store, which extends MemoryStore.

    This store functions like a MemoryStore except it periodically persists the contents of the store to an IndexedDB backend.

    All data is still kept in-memory but can be loaded from disk by calling startup(). This can make startup times quicker as a complete sync from the server is not required. This does not reduce memory usage as all the data is eagerly fetched when startup() is called.

    let opts = { indexedDB: window.indexedDB, localStorage: window.localStorage };
    let store = new IndexedDBStore(opts);
    await store.startup(); // load from indexed db
    let client = sdk.createClient({
    store: store,
    });
    client.startClient();
    client.on("sync", function(state, prevState, data) {
    if (state === "PREPARED") {
    console.log("Started up, now with go faster stripes!");
    }
    });

    Parameters

    • opts: IOpts

      Options object.

    Returns IndexedDBStore

Properties

accountData: Map<string, MatrixEvent> = ...

The backend instance. Call through to this API if you need to perform specific indexeddb actions like deleting the database.

clearOutOfBandMembers: DegradableFn<[roomId: string], void> = ...
deleteAllData: DegradableFn<[], void> = ...

Delete all data from this store.

Returns

Promise which resolves if the data was deleted from the database.

getClientOptions: DegradableFn<[], undefined | IStoredClientOpts> = ...
getOutOfBandMembers: DegradableFn<[roomId: string], null | IStateEventWithRoomId[]> = ...

Returns the out-of-band membership events for this room that were previously loaded.

Returns

the events, potentially an empty array if OOB loading didn't yield any new members

Returns

in case the members for this room haven't been stored yet

getSavedSync: DegradableFn<[], null | ISavedSync> = ...

Returns

Promise which resolves with a sync response to restore the client state to where it was at the last save, or null if there is no saved sync data.

getSavedSyncToken: DegradableFn<[], null | string> = ...

Returns

If there is a saved sync, the nextBatch token for this sync, otherwise null.

isNewlyCreated: DegradableFn<[], boolean> = ...

Returns

whether or not the database was newly created in this session.

localStorage?: Storage

Type declaration

reallySave: DegradableFn<[], void> = ...
setOutOfBandMembers: DegradableFn<[roomId: string, membershipEvents: IStateEventWithRoomId[]], void> = ...

Stores the out-of-band membership events for this room. Note that it still makes sense to store an empty array as the OOB status for the room is marked as fetched, and getOutOfBandMembers will return an empty array instead of null

Param

the membership events to store

Returns

when all members have been stored

setSyncData: DegradableFn<[syncData: ISyncResponse], void> = ...
startedUp: boolean = false
storeClientOptions: DegradableFn<[options: IStoredClientOpts], void> = ...
syncTs: number = 0
userModifiedMap: Record<string, number> = {}

Methods

  • All member functions of IndexedDBStore that access the backend use this wrapper to watch for failures after initial store startup, including QuotaExceededError as free disk space changes, etc.

    When IndexedDB fails via any of these paths, we degrade this back to a MemoryStore in place so that the current operation and all future ones are in-memory only.

    Returns

    A wrapped member function.

    Type Parameters

    • A extends any[]

    • R = void

    Parameters

    • func: DegradableFn<A, R>

      The degradable work to do.

    • Optional fallback: keyof MemoryStore

      The method name for fallback.

    Returns DegradableFn<A, R>

  • Retrieve a filter ID with the given name.

    Returns

    The filter ID or null.

    Parameters

    • filterName: string

      The filter name.

    Returns null | string

  • Possibly write data to the database.

    Returns

    Promise resolves after the write completes (or immediately if no write is performed)

    Parameters

    • force: boolean = false

      True to force a save to happen

    Returns Promise<void>

  • Retrieve scrollback for this room.

    Returns

    An array of objects which will be at most 'limit' length and at least 0. The objects are the raw event JSON.

    Parameters

    • room: Room

      The matrix room

    • limit: number

      The max number of old events to retrieve.

    Returns MatrixEvent[]

  • Store events for a room. The events have already been added to the timeline

    Parameters

    • room: Room

      The room to store events for.

    • events: MatrixEvent[]

      The events to store.

    • token: null | string

      The token associated with these events.

    • toStart: boolean

      True if these are paginated results.

    Returns void

  • Whether this store would like to save its data Note that obviously whether the store wants to save or not could change between calling this function and calling save().

    Returns

    True if calling save() will actually save (at the time this function is called).

    Returns boolean

Generated using TypeDoc