Replicache
Classes
Interfaces
- AsyncIterableIteratorToArray
- CreateIndexDefinition
- ExperimentalKVRead
- ExperimentalKVStore
- ExperimentalKVWrite
- ExperimentalWatchOptions
- LogSink
- ReadTransaction
- ReplicacheOptions
- RequestOptions
- ScanResult
- SubscribeOptions
- WriteTransaction
Type aliases
ClientStateNotFoundReason
Ƭ ClientStateNotFoundReason: { type
: "NotFoundOnServer"
} | { type
: "NotFoundOnClient"
}
The reason onClientStateNotFound was called.
ClientStateNotFoundResponse
Ƭ ClientStateNotFoundResponse: Object
In certain scenarios the server can signal that it does not know about the client. For example, the server might have deleted the client.
Type declaration
Name | Type |
---|---|
error | "ClientStateNotFound" |
ExperimentalDiff
Ƭ ExperimentalDiff: readonly ExperimentalDiffOperation
[]
Describes the changes that happened to Replicache after a WriteTransaction was committed.
experimental
This type is experimental and may change in the future.
ExperimentalDiffOperation
Ƭ ExperimentalDiffOperation: { key
: string
; newValue
: ReadonlyJSONValue
; op
: "add"
} | { key
: string
; oldValue
: ReadonlyJSONValue
; op
: "del"
} | { key
: string
; newValue
: ReadonlyJSONValue
; oldValue
: ReadonlyJSONValue
; op
: "change"
}
The individual parts describing the changes that happened to the Replicache data. There are three different kinds of operations:
add
: A new entry was added.del
: An entry was deleted.change
: An entry was changed.
experimental
This type is experimental and may change in the future.
ExperimentalWatchCallback
Ƭ ExperimentalWatchCallback: (diff
: ExperimentalDiff
) => void
Type declaration
▸ (diff
): void
Function that gets passed into Replicache.experimentalWatch and gets called when the data in Replicache changes.
experimental
This type is experimental and may change in the future.
Parameters
Name | Type |
---|---|
diff | ExperimentalDiff |
Returns
void
GetIndexScanIterator
Ƭ GetIndexScanIterator<V
>: (indexName
: string
, fromSecondaryKey
: string
, fromPrimaryKey
: string
| undefined
) => IterableUnion
<readonly [key: IndexKey, value: V]>
Type parameters
Name |
---|
V |
Type declaration
▸ (indexName
, fromSecondaryKey
, fromPrimaryKey
): IterableUnion
<readonly [key: IndexKey, value: V]>
When using makeScanResult this is the type used for the function called when doing a scan with an
indexName
.
Parameters
Name | Type | Description |
---|---|---|
indexName | string | The name of the index we are scanning over. |
fromSecondaryKey | string | The fromSecondaryKey is computed by scan and is the secondary key of the first entry to return in the iterator. It is based on prefix and start.key of the ScanIndexOptions. |
fromPrimaryKey | string | undefined | The fromPrimaryKey is computed by scan and is the primary key of the first entry to return in the iterator. It is based on prefix and start.key of the ScanIndexOptions. |
Returns
IterableUnion
<readonly [key: IndexKey, value: V]>
GetScanIterator
Ƭ GetScanIterator<V
>: (fromKey
: string
) => IterableUnion
<ReadonlyEntry
<V
>>
Type parameters
Name |
---|
V |
Type declaration
▸ (fromKey
): IterableUnion
<ReadonlyEntry
<V
>>
This is called when doing a scan without an
indexName
.
Parameters
Name | Type | Description |
---|---|---|
fromKey | string | The fromKey is computed by scan and is the key of the first entry to return in the iterator. It is based on prefix and start.key of the ScanNoIndexOptions. |
Returns
IterableUnion
<ReadonlyEntry
<V
>>
HTTPRequestInfo
Ƭ HTTPRequestInfo: Object
Type declaration
Name | Type |
---|---|
errorMessage | string |
httpStatusCode | number |
IndexKey
Ƭ IndexKey: readonly [secondary: string, primary: string]
When using indexes the key is a tuple of the secondary key and the primary key.
IterableUnion
Ƭ IterableUnion<T
>: AsyncIterable
<T
> | Iterable
<T
>
Type parameters
Name |
---|
T |
JSONObject
Ƭ JSONObject: Partial
<{ [key: string]
: JSONValue
; }>
A JSON object. We allow undefined values because in TypeScript there is no
way to express optional missing properties vs properties with the value
undefined
.
JSONValue
Ƭ JSONValue: null
| string
| boolean
| number
| JSONValue
[] | JSONObject
The values that can be represented in JSON
KeyTypeForScanOptions
Ƭ KeyTypeForScanOptions<O
>: O
extends ScanIndexOptions
? IndexKey
: string
If the options contains an indexName
then the key type is a tuple of
secondary and primary.
Type parameters
Name | Type |
---|---|
O | extends ScanOptions |
LogLevel
Ƭ LogLevel: "error"
| "info"
| "debug"
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.
MaybePromise
Ƭ MaybePromise<T
>: T
| Promise
<T
>
Type parameters
Name |
---|
T |
MutatorDefs
Ƭ MutatorDefs: Object
The type used to describe the mutator definitions passed into Replicache constructor as part of the ReplicacheOptions.
See ReplicacheOptions mutators for more info.
Index signature
▪ [key: string
]: (tx
: WriteTransaction
, args?
: any
) => MaybePromise
<JSONValue
| void
>
PatchOperation
Ƭ PatchOperation: { key
: string
; op
: "put"
; value
: JSONValue
} | { key
: string
; op
: "del"
} | { op
: "clear"
}
This type describes the patch field in a PullResponse and it is used to describe how to update the Replicache key-value store.
Poke
Ƭ Poke: Object
Type declaration
Name | Type |
---|---|
baseCookie | ReadonlyJSONValue |
pullResponse | PullResponse |
PullRequest
Ƭ PullRequest: Object
The JSON value used as the body when doing a POST to the pull endpoint.
Type declaration
Name | Type |
---|---|
clientID | string |
cookie | ReadonlyJSONValue |
lastMutationID | number |
profileID | string |
pullVersion | number |
schemaVersion | string |
PullResponse
Ƭ PullResponse: PullResponseOK
| ClientStateNotFoundResponse
PullResponse defines the shape and type of the response of a pull. This is the JSON you should return from your pull server endpoint.
PullResponseOK
Ƭ PullResponseOK: Object
The shape of a pull response under normal circumstances.
Type declaration
Name | Type |
---|---|
cookie? | ReadonlyJSONValue |
lastMutationID | number |
patch | PatchOperation [] |
Puller
Ƭ Puller: (request
: Request
) => Promise
<PullerResult
>
Type declaration
▸ (request
): Promise
<PullerResult
>
Puller is the function type used to do the fetch part of a pull. The request is a POST request where the body is JSON with the type PullRequest.
Parameters
Name | Type |
---|---|
request | Request |
Returns
Promise
<PullerResult
>
PullerResult
Ƭ PullerResult: Object
Type declaration
Name | Type |
---|---|
httpRequestInfo | HTTPRequestInfo |
response? | PullResponse |
PushRequest
Ƭ PushRequest: Object
The JSON value used as the body when doing a POST to the push endpoint.
Type declaration
Name | Type |
---|---|
clientID | string |
mutations | Mutation [] |
profileID | string |
pushVersion | number |
schemaVersion | string |
Pusher
Ƭ Pusher: (request
: Request
) => Promise
<HTTPRequestInfo
>
Type declaration
▸ (request
): Promise
<HTTPRequestInfo
>
Pusher is the function type used to do the fetch part of a push. The request is a POST request where the body is JSON with the type PushRequest.
Parameters
Name | Type |
---|---|
request | Request |
Returns
Promise
<HTTPRequestInfo
>
ReadonlyJSONObject
Ƭ ReadonlyJSONObject: Partial
<{ [key: string]
: ReadonlyJSONValue
; }>
Like JSONObject but deeply readonly
ReadonlyJSONValue
Ƭ ReadonlyJSONValue: null
| string
| boolean
| number
| ReadonlyArray
<ReadonlyJSONValue
> | ReadonlyJSONObject
Like JSONValue but deeply readonly
ScanIndexOptions
Ƭ ScanIndexOptions: Object
Options for scan when scanning over an index. When
scanning over and index you need to provide the indexName
and the start
key
is now a tuple consisting of secondar and primary key
Type declaration
Name | Type | Description |
---|---|---|
indexName | string | Do a scan over a named index. The indexName is the name of an index previously created with createIndex. |
limit? | number | Only include up to limit results. |
prefix? | string | Only include results starting with the secondary keys starting with prefix . |
start? | { exclusive? : boolean ; key : ScanOptionIndexedStartKey } | When provided the scan starts at this key. |
start.exclusive? | boolean | Whether the key is exclusive or inclusive. |
start.key | ScanOptionIndexedStartKey | - |
ScanNoIndexOptions
Ƭ ScanNoIndexOptions: Object
Options for scan when scanning over the entire key space.
Type declaration
Name | Type | Description |
---|---|---|
limit? | number | Only include up to limit results. |
prefix? | string | Only include keys starting with prefix . |
start? | { exclusive? : boolean ; key : string } | When provided the scan starts at this key. |
start.exclusive? | boolean | Whether the key is exclusive or inclusive. |
start.key | string | - |
ScanOptionIndexedStartKey
Ƭ ScanOptionIndexedStartKey: readonly [secondary: string, primary?: string] | string
The key to start scanning at.
If you are scanning the primary index (i.e., you did not specify
indexName
), then pass a single string for this field, which is the key in
the primary index to scan at.
If you are scanning a secondary index (i.e., you specified indexName
), then
use the tuple form. In that case, secondary
is the secondary key to start
scanning at, and primary
(if any) is the primary key to start scanning at.
ScanOptions
Ƭ ScanOptions: ScanIndexOptions
| ScanNoIndexOptions
Options for scan
Variables
TEST_LICENSE_KEY
• Const
TEST_LICENSE_KEY: "This key only good for automated testing"
consoleLogSink
• Const
consoleLogSink: LogSink
An implementation of [[Logger]] that logs using console.log
etc
version
• Const
version: string
= REPLICACHE_VERSION
The current version of Replicache.
Functions
filterAsyncIterable
▸ filterAsyncIterable<V
>(iter
, predicate
): AsyncIterable
<V
>
Filters an async iterable.
This utility function is provided because it is useful when using makeScanResult. It can be used to filter out tombstones (delete entries) for example.
Type parameters
Name |
---|
V |
Parameters
Name | Type |
---|---|
iter | IterableUnion <V > |
predicate | (v : V ) => boolean |
Returns
AsyncIterable
<V
>
isScanIndexOptions
▸ isScanIndexOptions(options
): options is ScanIndexOptions
Type narrowing of ScanOptions.
Parameters
Name | Type |
---|---|
options | ScanOptions |
Returns
options is ScanIndexOptions
makeIDBName
▸ makeIDBName(name
, schemaVersion?
): string
Returns the name of the IDB database that will be used for a particular Replicache instance.
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the Replicache instance (i.e., the name field of ReplicacheOptions ). |
schemaVersion? | string | The schema version of the database (i.e., the schemaVersion field of ReplicacheOptions ). |
Returns
string
makeScanResult
▸ makeScanResult<Options
, Value
>(options
, getScanIterator
): ScanResult
<KeyTypeForScanOptions
<Options
>, Value
>
A helper function that makes it easier to implement ReadTransaction.scan with a custom backend.
If you are implementing a custom backend and have an in memory pending async iterable we provide two helper functions to make it easier to merge these together. mergeAsyncIterables and filterAsyncIterable.
For example:
const scanResult = makeScanResult(
options,
options.indexName
? () => {
throw Error('not implemented');
}
: fromKey => {
const persisted: AsyncIterable<Entry<ReadonlyJSONValue>> = ...;
const pending: AsyncIterable<Entry<ReadonlyJSONValue | undefined>> = ...;
const iter = await mergeAsyncIterables(persisted, pending);
const filteredIter = await filterAsyncIterable(
iter,
entry => entry[1] !== undefined,
);
return filteredIter;
},
);
Type parameters
Name | Type |
---|---|
Options | extends ScanOptions |
Value | Value |
Parameters
Name | Type |
---|---|
options | Options |
getScanIterator | Options extends ScanIndexOptions ? GetIndexScanIterator <Value > : GetScanIterator <Value > |
Returns
ScanResult
<KeyTypeForScanOptions
<Options
>, Value
>
mergeAsyncIterables
▸ mergeAsyncIterables<A
, B
>(iterableBase
, iterableOverlay
, compare
): AsyncIterable
<A
| B
>
Merges an iterable on to another iterable.
The two iterables need to be ordered and the compare
function is used to
compare two different elements.
If two elements are equal (compare
returns 0
) then the element from the
second iterable is picked.
This utility function is provided because it is useful when using makeScanResult. It can be used to merge an in memory pending async iterable on to a persistent async iterable for example.
Type parameters
Name |
---|
A |
B |
Parameters
Name | Type |
---|---|
iterableBase | IterableUnion <A > |
iterableOverlay | IterableUnion <B > |
compare | (a : A , b : B ) => number |
Returns
AsyncIterable
<A
| B
>