GitHub image
replicache
āŒ˜K
Exports
Readme
Classes
3
AsyncIterableIteratorToArrayWrapper
Docs
Import
Tests
3
References
2

A class that wraps an async iterable iterator to add a toArray method.

Usage:

const keys: string[] = await rep.scan().keys().toArray();
class AsyncIterableIteratorToArrayWrapper<V'> implements any {
next: (v?: any) => Promise<any>
return?: (value?: any) => Promise<any>
throw?: (e?: any) => Promise<any>
toArray: () => Promise<V'[]>
[Symbol.asyncIterator]: () => any
}
PullError
Docs
Import
Tests
3
References
2

This error is thrown when the puller fails for any reason.

class PullError {
constructor(cause?: Error): PullError
name: string
cause?: Error
}
PushError
Docs
Import
Tests
3
References
2

This error is thrown when the pusher fails for any reason.

class PushError {
constructor(cause?: Error): PushError
name: string
cause?: Error
}
Interfaces
5
CreateIndexDefinition
Docs
Import
Tests
3
References
2

The definition of an index. This is used with createIndex when creating indexes.

interface CreateIndexDefinition {

The name of the index. This is used when you scan over an index.

name: string

The prefix, if any, to limit the index over. If not provided the values of all keys are indexed.

keyPrefix?: string

The prefix, if any, to limit the index over. If not provided the values of all keys are indexed.

prefix?: string

A JSON Pointer pointing at the sub value inside each value to index over.

For example, one might index over users' ages like so: createIndex({name: 'usersByAge', keyPrefix: '/user/', jsonPointer: '/age'})

jsonPointer: string
}
ExperimentalKVRead
Docs
Import
Tests
3
References
2

This interface is experimental and might be removed or changed in the future without following semver versioning. Please be cautious.

interface Read {
has: (key: string) => Promise<boolean>
get: (key: string) => Promise<ReadonlyJSONValue>
release: () => void
}
ExperimentalKVStore
Docs
Import
Tests
3
References
2

Store defines a transactional key/value store that Replicache stores all data within.

For correct operation of Replicache, implementations of this interface must provide strict serializable transactions.

Informally, read and write transactions must behave like a ReadWrite Lock - multiple read transactions are allowed in parallel, or one write. Additionally writes from a transaction must appear all at one, atomically.

This interface is experimental and might be removed or changed in the future without following semver versioning. Please be cautious.

interface Store {
read: () => Promise<Read>
withRead: <R'>(f: (read: Read) => (R' | Promise<R'>)) => Promise<R'>
write: () => Promise<Write>
withWrite: <R'>(f: (write: Write) => (R' | Promise<R'>)) => Promise<R'>
close: () => Promise<void>
}
ExperimentalKVWrite
Docs
Import
Tests
3
References
2
interface Write {
put: (key: string, value: ReadonlyJSONValue) => Promise<void>
del: (key: string) => Promise<void>
commit: () => Promise<void>
has: (key: string) => Promise<boolean>
get: (key: string) => Promise<ReadonlyJSONValue>
release: () => void
}
ReadTransaction
Docs
Import
Tests
3
References
2

ReadTransactions are used with Replicache.query and Replicache.subscribe and allows read operations on the database.

interface ReadTransaction {

Get a single value from the database. If the key is not present this returns undefined.

get: (key: string) => Promise<ReadonlyJSONValue>

Determines if a single key is present in the database.

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

Whether the database is empty.

isEmpty: () => Promise<boolean>

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

If the ScanResult is used after the ReadTransaction has been closed it will throw a TransactionClosedError.

scan: () => ScanResult<string, ReadonlyJSONValue>+1
}
Type Aliases
12
HTTPRequestInfo
Docs
Import
Tests
3
References
2
type HTTPRequestInfo = { httpStatusCode: number, errorMessage: string }
JSONObject
Docs
Import
Tests
3
References
2
type Partial<T'> = Partial
JSONValue
Docs
Import
Tests
3
References
2

The values that can be represented in JSON

type JSONValue = string | number | false | true | Partial<{ }> | JSONValue[]
KeyTypeForScanOptions
Docs
Import
Tests
3
References
2

If the options contains an indexName then the key type is a tuple of secondary and primary.

type KeyTypeForScanOptions<O'> = KeyTypeForScanOptions<O>
LogLevel
Docs
Import
Tests
3
References
2

The different log levels. This is used to determine how much logging to do. 'error' > 'info' > 'debug'... meaning 'error' has highest priority and 'debug' lowest.

type LogLevel = "error" | "info" | "debug"
MaybePromise
Docs
Import
Tests
3
References
2
type MaybePromise<T'> = T' | Promise<T'>
MutatorDefs
Docs
Import
Tests
3
References
2

The type used to describe the mutator definitions passed into Replicache constructor as part of the ReplicacheOptions.

See ReplicacheOptions mutators for more info.

type MutatorDefs = { }
PatchOperation
Docs
Import
Tests
3
References
2

This type describes the patch field in a PullResponse and it is used to describe how to update the Replicache key-value store.

type PatchOperation =
|
{ op: "put", key: string, value: JSONValue }
|
{ op: "del", key: string }
|
{ op: "clear" }
PullResponse
Docs
Import
Tests
3
References
2

PullResponse defines the shape and type of the response of a pull. This is the JSON you should return from your pull server endpoint.

type PullResponse = {
lastMutationID: number
}
Puller
Docs
Import
Tests
3
References
2

Puller is the function type used to do the fetch part of a pull.

type Puller = (request: Request) => Promise<PullerResult>
PullerResult
Docs
Import
Tests
3
References
2
type PullerResult = { response?: PullResponse, httpRequestInfo: HTTPRequestInfo }
Pusher
Docs
Import
Tests
3
References
2

Pusher is the function type used to do the fetch part of a push.

type Pusher = (request: Request) => Promise<HTTPRequestInfo>
Description
Realtime sync for any backend stack
Install
yarn add replicache
Copy
Details
BSL-1.1 License
4 Dependencies
Bundles TypeScript Types
Metrics
Weekly Downloads
Keywords