• Public
  • Public/Protected
  • All

Class default


  • default







getDataLayerAuth: undefined | null | (() => MaybePromise<undefined | null | string>) = 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: null | ((syncing: boolean) => void) = null

onSync is called when a sync begins, and again when the sync ends. The parameter syncing is set to true when onSync is called at the beginning of a sync, and false when it is called at the end of a sync.

This can be used in a React like app by doing something like the following:

const [syncing, setSyncing] = useState(false);
useEffect(() => {
  rep.onSync = setSyncing;
}, [rep]);


pushDelay: number

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



  • get closed(): boolean
  • Whether the Replicache database has been closed. Once Replicache has been closed it no longer syncs and you can no longer read or write data out of it. After it has been closed it is pretty much useless and should not be used any more.

    Returns boolean


  • get online(): boolean
  • A rough heuristic for whether the client is currently online. Note that there is no way to know for certain whether a client is online - the next request can always fail. This is true if the last sync attempt succeeded, and false otherwise.

    Returns boolean


  • get syncInterval(): null | number
  • set syncInterval(duration: null | number): void
  • The duration between each periodic sync. Setting this to null disables periodic sync completely. Sync will still happen if you call sync manually, and after writes (see pushDelay).

    Returns null | number

  • The duration between each periodic sync. Setting this to null disables periodic sync completely. Sync will still happen if you call sync manually, and after writes (see pushDelay).


    • duration: null | number

    Returns void



  • close(): Promise<void>
  • Closes this Replicache instance.

    When closed all subscriptions end and no more read or writes are allowed.

    Returns 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.


    Returns Promise<void>


  • dropIndex(name: string): Promise<void>


  • get(key: string): Promise<undefined | null | string | number | boolean | JSONValue[] | Partial<{}>>


  • has(key: string): Promise<boolean>


  • isEmpty(): 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>


  • 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.


    register returns the function to use to mutate Replicache.

    const createTodo = rep.register('createTodo',
      async (tx: WriteTransaction, args: JSONValue) => {
        const key = `/todo/${args.id}`;
        if (await tx.has(key)) {
          throw new Error('Todo already exists');
        await tx.put(key, args);

    This will create the function to later use:

    await createTodo({id: 1234, title: 'Make things work offline', complete: true});

    Type parameters

    • Return: null | string | number | boolean | void | JSONValue[] | Partial<{}>


    Returns () => Promise<Return>

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

  • Type parameters

    • Return: null | string | number | boolean | void | JSONValue[] | Partial<{}>

    • 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<[K, JSONValue][]>


  • 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 body is called and if the result of body changes compared to last time onData is called. The function is also called once the first time the subscription is added.

    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: undefined | null | string | number | boolean | JSONValue[] | Partial<{}>

    • 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

      • Optional onDone?: undefined | (() => void)
      • Optional 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