• Public
  • Public/Protected
  • All

Class Replicache


  • Replicache







getDataLayerAuth: (() => MaybePromise<string | null | undefined>) | null | undefined = null

This gets called when we get an HTTP unauthorized from the client view or the batch endpoint. Set this to a function that will ask your user to reauthenticate.


onSync: ((syncing: boolean) => void) | null = null


pushDelay: number

The delay between when a change is made to Replicache and when Replicache attempts to push that change.



  • get closed(): boolean
  • Returns boolean


  • get online(): boolean
  • Returns boolean


  • get syncInterval(): number | null
  • set syncInterval(duration: number | null): void
  • The duration between each sync. Set this to null to prevent syncing in the background.

    Returns number | null

  • The duration between each sync. Set this to null to prevent syncing in the background.


    • duration: number | null

    Returns void



  • close(): Promise<void>
  • Returns Promise<void>


  • createIndex(def: { jsonPointer: string; keyPrefix?: undefined | string; name: string }): Promise<void>
  • Creates a persistent secondary index in Replicache which can be used with scan.

    If the named index already exists with the same definition this returns success immediately. If the named index already exists, but with a different definition an error is returned.


    • def: { jsonPointer: string; keyPrefix?: undefined | string; name: string }
      • jsonPointer: string
      • Optional keyPrefix?: undefined | string
      • name: string

    Returns Promise<void>


  • dropIndex(name: string): Promise<void>
  • Drops an index previously created with createIndex.


    • name: string

    Returns Promise<void>


  • get(key: string): Promise<JSONValue | undefined>
  • Get a single value from the database.


    • key: string

    Returns Promise<JSONValue | undefined>


  • has(key: string): Promise<boolean>
  • Determines if a single key is present in the database.


    • key: string

    Returns Promise<boolean>


  • Query is used for read transactions. It is recommended to use transactions to ensure you get a consistent view across multiple calls to get, has and scan.

    Type parameters

    • R


    Returns Promise<R>


  • register<Return>(name: string, mutatorImpl: (tx: WriteTransaction) => MaybePromise<Return>): () => Promise<Return>
  • register<Return, Args>(name: string, mutatorImpl: (tx: WriteTransaction, args: Args) => MaybePromise<Return>): (args: Args) => Promise<Return>
  • Registers a mutator, which is used to make changes to the data.


    Mutators run once when they are initially invoked, but they might also be replayed multiple times during sync. As such mutators should not modify application state directly. Also, it is important that the set of registered mutator names only grows over time. If Replicache syncs and needed mutator is not registered, it will substitute a no-op mutator, but this might be a poor user experience.

    Server application

    During sync, a description of each mutation is sent to the server's batch endpoint where it is applied. Once the mutation has been applied successfully, as indicated by the client view's lastMutationId field, the local version of the mutation is removed. See the design doc for additional details on the sync protocol.


    Mutators are atomic: all their changes are applied together, or none are. Throwing an exception aborts the transaction. Otherwise, it is committed. As with [query] and [subscribe] all reads will see a consistent view of the cache while they run.

    Type parameters

    • Return: JSONValue | void


    Returns () => Promise<Return>

      • (): Promise<Return>
      • Returns Promise<Return>

  • Type parameters

    • Return: JSONValue | void

    • Args: JSONValue


    Returns (args: Args) => Promise<Return>

      • (args: Args): Promise<Return>
      • Parameters

        • args: Args

        Returns Promise<Return>


  • Gets many values from the database. This returns a ScanResult which implements AsyncIterable. It also has methods to iterate over the keys and entries.

    If options has an indexName, then this does a scan over an index with that name. A scan over an index uses a tuple for the key consisting of [secondary: string, primary: string].

    Type parameters


    • Optional options: O

    Returns ScanResult<K>


  • scanAll<O, K>(options?: O): Promise<[][]>


  • setVerboseWasmLogging(verbose: boolean): Promise<void>
  • When this is set to true the internal Replicache wasm module will log more things to the console (using console.debug). Setting this to false reduces the amount of logging done by the wasm module.

    If you want to see the verbose logging from Replicache in Devtools/Web Inspector you also need to change the console log level to Verbose.


    • verbose: boolean

    Returns Promise<void>


  • subscribe<R, E>(body: (tx: ReadTransaction) => Promise<R>, __namedParameters: { onData: (result: R) => void; onDone: undefined | (() => void); onError: undefined | ((error: E) => void) }): () => void
  • Subcribe to changes to the underlying data. Every time the underlying data changes onData is called. The function is also called once the first time the subscription is added. There is currently no guarantee that the result of this subscription changes and it might get called with the same value over and over.

    This returns a function that can be used to cancel the subscription.

    If an error occurs in the body the onError function is called if present. Otherwise, the error is thrown.

    Type parameters

    • R

    • E


    • body: (tx: ReadTransaction) => Promise<R>
    • __namedParameters: { onData: (result: R) => void; onDone: undefined | (() => void); onError: undefined | ((error: E) => void) }
      • onData: (result: R) => void
          • (result: R): void
          • Parameters

            • result: R

            Returns void

      • onDone: undefined | (() => void)
      • onError: undefined | ((error: E) => void)

    Returns () => void

      • (): void
      • Returns void


  • sync(): Promise<void>
  • Synchronizes this cache with the server. New local mutations are sent to the server, and the latest server state is applied to the cache. Any local mutations not included in the new server state are replayed. See the Replicache design document for more information on sync: https://github.com/rocicorp/replicache/blob/master/design.md

    Returns Promise<void>

Generated using TypeDoc