idb-ts
    Preparing search index...

    Interface SyncAdapter

    Transport-agnostic adapter bridging the local IndexedDB with any backend.

    Implement these two methods over your transport of choice (REST, WebSocket, in-memory, ...) and pass the adapter to Database.pushTo / Database.pullFrom. The library never assumes anything about the transport; conflict resolution is left to the adapter/backend (locally, pulled records win by primary key).

    class RestAdapter implements SyncAdapter {
    async push(entityName: string, records: unknown[]): Promise<void> {
    await fetch(`/api/sync/${entityName}`, {
    method: 'PUT',
    body: JSON.stringify(records),
    });
    }

    async pull(entityName: string): Promise<unknown[] | undefined> {
    const response = await fetch(`/api/sync/${entityName}`);
    return response.ok ? response.json() : undefined;
    }
    }
    interface SyncAdapter {
        pull(entityName: string): Promise<unknown[] | undefined>;
        push(entityName: string, records: unknown[]): Promise<void>;
    }
    Index

    Methods

    Methods

    • Supplies records for one entity store during Database.pullFrom.

      Parameters

      • entityName: string

        The entity class name, e.g. "User".

      Returns Promise<unknown[] | undefined>

      The records to upsert locally, or undefined to leave the local store untouched.

    • Receives the full record list of one entity store during Database.pushTo.

      Parameters

      • entityName: string

        The entity class name, e.g. "User".

      • records: unknown[]

        All records currently in that entity's store.

      Returns Promise<void>