New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

replicache

Package Overview
Dependencies
Maintainers
6
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replicache - npm Package Compare versions

Comparing version 12.2.1 to 13.0.0-beta.0

1312

out/replicache.d.ts

@@ -0,61 +1,123 @@

/**
* 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.
*/
declare type LogLevel = 'error' | 'info' | 'debug';
interface LogSink {
log(level: LogLevel, ...args: unknown[]): void;
flush?(): Promise<void>;
}
/**
* An implementation of [[LogSink]] that logs using `console.log` etc
*/
declare const consoleLogSink: LogSink;
// TODO when our license is finalized add a link to it.
declare const TEST_LICENSE_KEY = 'This key only good for automated testing';
/** The values that can be represented in JSON */
declare type JSONValue = null | string | boolean | number | Array<JSONValue> | JSONObject;
type JSONValue =
| null
| string
| boolean
| number
| Array<JSONValue>
| JSONObject;
/**
* A JSON object. This is a map from strings to JSON values.
*/
declare type JSONObject = {
[key: string]: JSONValue;
};
type JSONObject = {[key: string]: JSONValue};
/** Like {@link JSONValue} but deeply readonly */
declare type ReadonlyJSONValue = null | string | boolean | number | ReadonlyArray<ReadonlyJSONValue> | ReadonlyJSONObject;
type ReadonlyJSONValue =
| null
| string
| boolean
| number
| ReadonlyArray<ReadonlyJSONValue>
| ReadonlyJSONObject;
/** Like {@link JSONObject} but deeply readonly */
declare type ReadonlyJSONObject = {
readonly [key: string]: ReadonlyJSONValue;
type ReadonlyJSONObject = {
readonly [key: string]: ReadonlyJSONValue;
};
declare type HTTPRequestInfo = {
httpStatusCode: number;
errorMessage: string;
};
/**
* 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 {@link PushRequest}.
* A cookie is a value that is used to determine the order of snapshots. It
* needs to be comparable. This can be a `string`, `number` or if you want to
* use a more complex value, you can use an object with an `order` property. The
* value `null` is considered to be less than any other cookie and it is used
* for the first pull when no cookie has been set.
*
* The order is the natural order of numbers and strings. If one of the cookies
* is an object then the value of the `order` property is treated as the cookie
* when doing comparison.
*
* If one of the cookies is a string and the other is a number, the number is
* fist converted to a string (using `toString()`).
*/
declare type Pusher = (request: Request) => Promise<HTTPRequestInfo>;
type Cookie = null | string | number | (ReadonlyJSONValue & {
readonly order: number | string;
});
declare const hashTag: unique symbol;
/**
* This error is thrown when the pusher fails for any reason.
* Opaque type representing a hash. The only way to create one is using `parse`
* or `hashOf` (except for static unsafe cast of course).
*/
declare class PushError extends Error {
name: string;
causedBy?: Error | undefined;
constructor(causedBy?: Error);
}
type Hash = string & {
[hashTag]: true;
};
/**
* The ID describing a group of clients. All clients in the same group share a
* perdag.
* persistent storage (IDB).
*/
declare type ClientGroupID = string;
type ClientGroupID = string;
/**
* The ID describing a client.
*/
declare type ClientID = string;
type ClientID = string;
declare type PullerResult = {
response?: PullResponse | undefined;
httpRequestInfo: HTTPRequestInfo;
/**
* The definition of a single index.
*/
type IndexDefinition = {
/**
* The prefix, if any, to limit the index over. If not provided the values of
* all keys are indexed.
*/
readonly prefix?: string;
/**
* A [JSON Pointer](https://tools.ietf.org/html/rfc6901) pointing at the sub
* value inside each value to index over.
*
* For example, one might index over users' ages like so:
* `{prefix: '/user/', jsonPointer: '/age'}`
*/
readonly jsonPointer: string;
/**
* If `true`, indexing empty values will not emit a warning. Defaults to `false`.
*/
readonly allowEmpty?: boolean;
};
/**
* 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 {@link PullRequest}.
* An object as a map defining the indexes. The keys are the index names and the
* values are the index definitions.
*/
declare type Puller = (request: Request) => Promise<PullerResult>;
type IndexDefinitions = {
readonly [name: string]: IndexDefinition;
};
/**
* The shape of a pull response under normal circumstances.
* When using indexes the key is a tuple of the secondary key and the primary
* key.
*/
declare type PullResponseOK = {
cookie?: ReadonlyJSONValue | undefined;
lastMutationID: number;
patch: PatchOperation[];
type IndexKey = readonly [secondary: string, primary: string];
type HTTPRequestInfo = {
httpStatusCode: number;
errorMessage: string;
};

@@ -65,12 +127,17 @@

* In certain scenarios the server can signal that it does not know about the
* client. For example, the server might have deleted the client.
* client. For example, the server might have lost all of its state (this might
* happen during the development of the server).
*/
declare type ClientStateNotFoundResponse = {
type ClientStateNotFoundResponse = {
error: 'ClientStateNotFound';
};
/**
* PullResponse defines the shape and type of the response of a pull. This is
* the JSON you should return from your pull server endpoint.
* The server endpoint may respond with a `VersionNotSupported` error if it does
* not know how to handle the {@link pullVersion}, {@link pushVersion} or the
* {@link schemaVersion}.
*/
declare type PullResponse = PullResponseOK | ClientStateNotFoundResponse;
type VersionNotSupportedResponse = {
error: 'VersionNotSupported';
versionType?: 'pull' | 'push' | 'schema' | undefined;
};

@@ -81,3 +148,3 @@ /**

*/
declare type PatchOperation = {
type PatchOperation = {
readonly op: 'put';

@@ -92,6 +159,105 @@ readonly key: string;

};
type PullerResultV0 = {
response?: PullResponseV0 | undefined;
httpRequestInfo: HTTPRequestInfo;
};
type PullerResultV1 = {
response?: PullResponseV1 | undefined;
httpRequestInfo: HTTPRequestInfo;
};
type PullerResult = PullerResultV1 | PullerResultV0;
/**
* This error is thrown when the puller fails for any reason.
* Puller is the function type used to do the fetch part of a pull.
*
* Puller needs to support dealing with pull request of version 0 and 1. Version
* 0 is used when doing mutation recovery of old clients. If a
* {@link PullRequestV1} is passed in the n a {@link PullerResultV1} should
* be returned. We do a runtime assert to make this is the case.
*
* If you do not support old clients you can just throw if `pullVersion` is `0`,
*/
declare class PullError extends Error {
type Puller = (requestBody: PullRequest, requestID: string) => Promise<PullerResult>;
/**
* The shape of a pull response under normal circumstances.
*/
type PullResponseOKV0 = {
cookie?: ReadonlyJSONValue | undefined;
lastMutationID: number;
patch: PatchOperation[];
};
/**
* The shape of a pull response under normal circumstances.
*/
type PullResponseOKV1 = {
cookie: Cookie;
lastMutationIDChanges: Record<ClientID, number>;
patch: PatchOperation[];
};
/**
* 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 PullResponseV0 = PullResponseOKV0 | ClientStateNotFoundResponse | VersionNotSupportedResponse;
/**
* 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 PullResponseV1 = PullResponseOKV1 | ClientStateNotFoundResponse | VersionNotSupportedResponse;
type PullResponse = PullResponseV1 | PullResponseV0;
/**
* The JSON value used as the body when doing a POST to the [pull
* endpoint](/reference/server-pull).
*/
type PullRequest = PullRequestV1 | PullRequestV0;
/**
* The JSON value used as the body when doing a POST to the [pull
* endpoint](/reference/server-pull). This is the legacy version (V0) and it is
* still used when recovering mutations from old clients.
*/
type PullRequestV0 = {
pullVersion: 0;
schemaVersion: string;
profileID: string;
cookie: ReadonlyJSONValue;
clientID: ClientID;
lastMutationID: number;
};
/**
* The JSON value used as the body when doing a POST to the [pull
* endpoint](/reference/server-pull).
*/
type PullRequestV1 = {
pullVersion: 1;
schemaVersion: string;
profileID: string;
cookie: Cookie;
clientGroupID: ClientGroupID;
};
type PusherResult = {
response?: PushResponse | undefined;
httpRequestInfo: HTTPRequestInfo;
};
/**
* The response from a push can contain information about error conditions.
*/
type PushResponse = ClientStateNotFoundResponse | VersionNotSupportedResponse;
/**
* 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 {@link PushRequest}.
*
* The return value should either be a {@link HTTPRequestInfo} or a
* {@link PusherResult}. The reason for the two different return types is that
* we didn't use to care about the response body of the push request. The
* default pusher implementation checks if the response body is JSON and if it
* matches the type {@link PusherResponse}. If it does, it is included in the
* return value.
*/
type Pusher = (requestBody: PushRequest, requestID: string) => Promise<PusherResult>;
/**
* This error is thrown when the pusher fails for any reason.
*/
declare class PushError extends Error {
name: string;

@@ -103,25 +269,142 @@ causedBy?: Error | undefined;

/**
* 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.
* The JSON value used as the body when doing a POST to the [push
* endpoint](/reference/server-push). This is the legacy version (V0) and it is
* still used when recovering mutations from old clients.
*/
declare type LogLevel = 'error' | 'info' | 'debug';
interface LogSink {
log(level: LogLevel, ...args: unknown[]): void;
flush?(): Promise<void>;
}
type PushRequestV0 = {
pushVersion: 0;
/**
* `schemaVersion` can optionally be used to specify to the push endpoint
* version information about the mutators the app is using (e.g., format of
* mutator args).
*/
schemaVersion: string;
profileID: string;
clientID: ClientID;
mutations: MutationV0[];
};
/**
* An implementation of [[Logger]] that logs using `console.log` etc
* The JSON value used as the body when doing a POST to the [push
* endpoint](/reference/server-push).
*/
declare const consoleLogSink: LogSink;
declare const hashTag: unique symbol;
type PushRequestV1 = {
pushVersion: 1;
/**
* `schemaVersion` can optionally be used to specify to the push endpoint
* version information about the mutators the app is using (e.g., format of
* mutator args).
*/
schemaVersion: string;
profileID: string;
clientGroupID: ClientGroupID;
mutations: MutationV1[];
};
type PushRequest = PushRequestV0 | PushRequestV1;
/**
* Opaque type representing a hash. The only way to create one is using `parse`
* or `hashOf` (except for static unsafe cast of course).
* Mutation describes a single mutation done on the client. This is the legacy
* version (V0) and it is used when recovering mutations from old clients.
*/
declare type Hash = {
[hashTag]: true;
type MutationV0 = {
readonly id: number;
readonly name: string;
readonly args: ReadonlyJSONValue;
readonly timestamp: number;
};
/**
* Mutation describes a single mutation done on the client.
*/
type MutationV1 = {
readonly id: number;
readonly name: string;
readonly args: ReadonlyJSONValue;
readonly timestamp: number;
readonly clientID: ClientID;
};
type ClientMap = ReadonlyMap<ClientID, ClientV4 | ClientV5 | ClientV6>;
type ClientV4 = {
/**
* A UNIX timestamp in milliseconds updated by the client once a minute
* while it is active and every time the client persists its state to
* the perdag.
* Should only be updated by the client represented by this structure.
*/
readonly heartbeatTimestampMs: number;
/**
* The hash of the commit in the perdag this client last persisted.
* Should only be updated by the client represented by this structure.
*/
readonly headHash: Hash;
/**
* The mutationID of the commit at headHash (mutationID if it is a
* local commit, lastMutationID if it is an index change or snapshot commit).
* Should only be updated by the client represented by this structure.
* Read by other clients to determine if there are unacknowledged pending
* mutations for them to push on behalf of the client represented by this
* structure.
* This is redundant with information in the commit graph at headHash,
* but allows other clients to determine if there are unacknowledged pending
* mutations without having to load the commit graph at headHash.
*/
readonly mutationID: number;
/**
* The highest lastMutationID received from the server for this client.
*
* Should be updated by the client represented by this structure whenever
* it persists its state to the perdag.
* Read by other clients to determine if there are unacknowledged pending
* mutations for them to push on behalf of the client represented by this
* structure, and *updated* by other clients upon successfully pushing
* pending mutations to avoid redundant pushes of those mutations.
*
* Note: This will be the same as the lastMutationID of the base snapshot of
* the commit graph at headHash when written by the client represented by this
* structure. However, when written by another client pushing pending
* mutations on this client's behalf it will be different. This is because
* the other client does not update the commit graph (it is unsafe to update
* another client's commit graph).
*/
readonly lastServerAckdMutationID: number;
};
type ClientV5 = {
readonly heartbeatTimestampMs: number;
readonly headHash: Hash;
/**
* The hash of a commit we are in the middle of refreshing into this client's
* memdag.
*/
readonly tempRefreshHash: Hash | null;
/**
* ID of this client's perdag client group. This needs to be sent in pull
* request (to enable syncing all last mutation ids in the client group).
*/
readonly clientGroupID: ClientGroupID;
};
type ClientV6 = {
readonly heartbeatTimestampMs: number;
/**
* A set of hashes, which contains:
* 1. The hash of the last commit this client refreshed from its client group
* (this is the commit it bootstrapped from until it completes its first
* refresh).
* 2. One or more hashes that were added to retain chunks of a commit while it
* was being refreshed into this client's memdag. (This can be one or more
* because refresh's cleanup step is a separate transaction and can fail).
* Upon refresh completing and successfully running its clean up step, this
* set will contain a single hash: the hash of the last commit this client
* refreshed.
*/
readonly refreshHashes: readonly Hash[];
/**
* The hash of the last snapshot commit persisted by this client to this
* client's client group, or null if has never persisted a snapshot.
*/
readonly persistHash: Hash | null;
/**
* ID of this client's perdag client group. This needs to be sent in pull
* request (to enable syncing all last mutation ids in the client group).
*/
readonly clientGroupID: ClientGroupID;
};
/**

@@ -159,3 +442,3 @@ * Store defines a transactional key/value store that Replicache stores all data

*/
declare type CreateStore = (name: string) => Store;
type CreateStore = (name: string) => Store;
/**

@@ -191,2 +474,11 @@ * This interface is used so that we can release the lock when the transaction

/**
* This {@link Error} is thrown when we detect that the IndexedDB has been
* removed. This does not normally happen but can happen during development if
* the user has DevTools open and deletes the IndexedDB from there.
*/
declare class IDBNotFoundError extends Error {
name: string;
}
/**
* A named in-memory Store implementation.

@@ -213,123 +505,234 @@ *

/**
* The definition of a single index.
* Deletes a single Replicache database.
* @param dbName
* @param createKVStore
*/
declare type IndexDefinition = {
/**
* The prefix, if any, to limit the index over. If not provided the values of
* all keys are indexed.
*/
readonly prefix?: string;
/**
* A [JSON Pointer](https://tools.ietf.org/html/rfc6901) pointing at the sub
* value inside each value to index over.
*
* For example, one might index over users' ages like so:
* `{prefix: '/user/', jsonPointer: '/age'}`
*/
readonly jsonPointer: string;
/**
* If `true`, indexing empty values will not emit a warning. Defaults to `false`.
*/
readonly allowEmpty?: boolean;
};
declare function dropDatabase(dbName: string, createKVStore?: CreateStore): Promise<void>;
/**
* An object as a map defining the indexes. The keys are the index names and the
* values are the index definitions.
*/
declare type IndexDefinitions = {
readonly [name: string]: IndexDefinition;
};
declare type Entry<V> = readonly [key: string, value: V];
/**
* Describes the changes that happened to Replicache after a
* {@link WriteTransaction} was committed.
* Deletes all IndexedDB data associated with Replicache.
*
* @experimental This type is experimental and may change in the future.
* Returns an object with the names of the successfully dropped databases
* and any errors encountered while dropping.
*/
declare type Diff = IndexDiff | NoIndexDiff;
declare function dropAllDatabases(createKVStore?: CreateStore): Promise<{
dropped: string[];
errors: unknown[];
}>;
/**
* @experimental This type is experimental and may change in the future.
*/
declare type IndexDiff = readonly DiffOperation<IndexKey>[];
/**
* @experimental This type is experimental and may change in the future.
*/
declare type NoIndexDiff = readonly DiffOperation<string>[];
declare type DiffOperationAdd<Key, Value = ReadonlyJSONValue> = {
readonly op: 'add';
readonly key: Key;
readonly newValue: Value;
};
declare type DiffOperationDel<Key, Value = ReadonlyJSONValue> = {
readonly op: 'del';
readonly key: Key;
readonly oldValue: Value;
};
declare type DiffOperationChange<Key, Value = ReadonlyJSONValue> = {
readonly op: 'change';
readonly key: Key;
readonly oldValue: Value;
readonly newValue: Value;
};
/**
* 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.
* Deletes all IndexedDB data associated with Replicache.
*
* @experimental This type is experimental and may change in the future.
* Returns an object with the names of the successfully dropped databases
* and any errors encountered while dropping.
*
* @deprecated Use `dropAllDatabases` instead.
*/
declare type DiffOperation<Key> = DiffOperationAdd<Key> | DiffOperationDel<Key> | DiffOperationChange<Key>;
declare function deleteAllReplicacheData(createKVStore?: CreateStore): Promise<{
dropped: string[];
errors: unknown[];
}>;
/**
* The JSON value used as the body when doing a POST to the [pull
* endpoint](/reference/server-pull).
* The options passed to {@link Replicache}.
*/
declare type PullRequest = {
profileID: string;
clientID: ClientID;
cookie: ReadonlyJSONValue;
lastMutationID: number;
pullVersion: number;
schemaVersion: string;
};
/**
* The JSON value used as the body when doing a POST to the [push
* endpoint](/reference/server-push).
*/
declare type PushRequest = {
profileID: string;
clientID: ClientID;
mutations: Mutation[];
pushVersion: number;
interface ReplicacheOptions<MD extends MutatorDefs> {
/**
* `schemaVersion` can optionally be used to specify to the push endpoint
* version information about the mutators the app is using (e.g., format of
* mutator args).
* This is the URL to the server endpoint dealing with the push updates. See
* [Push Endpoint Reference](https://doc.replicache.dev/reference/server-push) for more
* details.
*
* If not provided, push requests will not be made unless a custom
* {@link ReplicacheOptions.pusher} is provided.
*/
schemaVersion: string;
};
/**
* Mutation describes a single mutation done on the client.
*/
declare type Mutation = {
readonly id: number;
readonly name: string;
readonly args: ReadonlyJSONValue;
readonly timestamp: number;
};
pushURL?: string | undefined;
/**
* This is the authorization token used when doing a
* [pull](https://doc.replicache.dev/reference/server-pull#authorization) and
* [push](https://doc.replicache.dev/reference/server-push#authorization).
*/
auth?: string | undefined;
/**
* This is the URL to the server endpoint dealing with pull. See [Pull
* Endpoint Reference](https://doc.replicache.dev/reference/server-pull) for more
* details.
*
* If not provided, pull requests will not be made unless a custom
* {@link ReplicacheOptions.puller} is provided.
*/
pullURL?: string | undefined;
/**
* The name of the Replicache database.
*
* It is important to use user specific names so that if there are multiple
* tabs open for different distinct users their data is kept separate.
*
* For efficiency and performance, a new {@link Replicache} instance will
* initialize its state from the persisted state of an existing {@link Replicache}
* instance with the same `name`, domain and browser profile.
*
* Mutations from one {@link Replicache} instance may be pushed using the
* {@link ReplicacheOptions.auth}, {@link ReplicacheOptions.pushURL},
* {@link ReplicacheOptions.pullURL}, {@link ReplicacheOptions.pusher}, and
* {@link ReplicacheOptions.puller} of another Replicache instance with the same
* `name`, domain and browser profile.
*
* You can use multiple Replicache instances for the same user as long as the
* names are unique. e.g. `name: `$userID:$roomID`
*/
name: string;
/**
* The schema version of the data understood by this application. This enables
* versioning of mutators (in the push direction) and the client view (in the
* pull direction).
*/
schemaVersion?: string | undefined;
/**
* The duration between each {@link pull} in milliseconds. Set this to `null` to
* prevent pulling in the background. Defaults to 60 seconds.
*/
pullInterval?: number | null | undefined;
/**
* The delay between when a change is made to Replicache and when Replicache
* attempts to push that change.
*/
pushDelay?: number | undefined;
/**
* Determines how much logging to do. When this is set to `'debug'`,
* Replicache will also log `'info'` and `'error'` messages. When set to
* `'info'` we log `'info'` and `'error'` but not `'debug'`. When set to
* `'error'` we only log `'error'` messages.
* Default is `'info'`.
*/
logLevel?: LogLevel | undefined;
/**
* Enables custom handling of logs.
*
* By default logs are logged to the console. If you would like logs to be
* sent elsewhere (e.g. to a cloud logging service like DataDog) you can
* provide an array of {@link LogSink}s. Logs at or above
* {@link ReplicacheOptions.logLevel} are sent to each of these {@link LogSink}s.
* If you would still like logs to go to the console, include
* `consoleLogSink` in the array.
*
* ```ts
* logSinks: [consoleLogSink, myCloudLogSink],
* ```
*/
logSinks?: LogSink[] | undefined;
/**
* An object used as a map to define the *mutators*. These gets registered at
* startup of {@link Replicache}.
*
* *Mutators* are used to make changes to the data.
*
* #### Example
*
* The registered *mutations* are reflected on the
* {@link Replicache.mutate | mutate} property of the {@link Replicache} instance.
*
* ```ts
* const rep = new Replicache({
* name: 'user-id',
* mutators: {
* async createTodo(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);
* },
* async deleteTodo(tx: WriteTransaction, id: number) {
* ...
* },
* },
* });
* ```
*
* This will create the function to later use:
*
* ```ts
* await rep.mutate.createTodo({
* id: 1234,
* title: 'Make things work offline',
* complete: true,
* });
* ```
*
* #### Replays
*
* *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 push, a description of each mutation is sent to the server's [push
* endpoint](https://doc.replicache.dev/reference/server-push) where it is applied. Once
* the *mutation* has been applied successfully, as indicated by the client
* view's
* [`lastMutationId`](https://doc.replicache.dev/reference/server-pull#lastmutationid)
* field, the local version of the *mutation* is removed. See the [design
* doc](https://doc.replicache.dev/design#commits) for additional details on
* the sync protocol.
*
* #### Transactionality
*
* *Mutators* are atomic: all their changes are applied together, or none are.
* Throwing an exception aborts the transaction. Otherwise, it is committed.
* As with {@link query} and {@link subscribe} all reads will see a consistent view of
* the cache while they run.
*/
mutators?: MD | undefined;
/**
* Options to use when doing pull and push requests.
*/
requestOptions?: RequestOptions | undefined;
/**
* Allows passing in a custom implementation of a {@link Puller} function. This
* function is called when doing a pull and it is responsible for
* communicating with the server.
*
* Normally, this is just a POST to a URL with a JSON body but you can provide
* your own function if you need to do things differently.
*/
puller?: Puller | undefined;
/**
* Allows passing in a custom implementation of a {@link Pusher} function. This
* function is called when doing a push and it is responsible for
* communicating with the server.
*
* Normally, this is just a POST to a URL with a JSON body but you can provide
* your own function if you need to do things differently.
*/
pusher?: Pusher | undefined;
/**
* The license key for Replicache. This parameter is required for Replicache to
* function. See https://replicache.dev for how to acquire a license key.
*
* YOU SHOULD PASS TEST_LICENSE_KEY IN AUTOMATED TESTS. It disables license
* checks for several minutes. If you pass a normal license key in tests, each test
* that instantiates Replicache will attempt to perform a license check against
* Replicache's licensing server, potentially increasing your monthly active browser
* profile count, slowing the test down, and spamming Replicache's servers.
*/
licenseKey: string;
/**
* Allows providing a custom implementation of the underlying storage layer.
*
* @experimental This option is experimental and might be removed or changed
* in the future without following semver versioning. Please be cautious.
*/
experimentalCreateKVStore?: CreateStore | undefined;
/**
* Defines the indexes, if any, to use on the data.
*/
readonly indexes?: IndexDefinitions | undefined;
}
/**
* When using indexes the key is a tuple of the secondary key and the primary
* key.
*/
declare type IndexKey = readonly [secondary: string, primary: string];
/**
* Options for {@link ReadTransaction.scan | scan}
*/
declare type ScanOptions = ScanIndexOptions | ScanNoIndexOptions;
type ScanOptions = ScanIndexOptions | ScanNoIndexOptions;
/**

@@ -339,3 +742,3 @@ * Options for {@link ReadTransaction.scan | scan} when scanning over the entire key

*/
declare type ScanNoIndexOptions = {
type ScanNoIndexOptions = {
/** Only include keys starting with `prefix`. */

@@ -357,3 +760,3 @@ prefix?: string | undefined;

*/
declare type ScanIndexOptions = {
type ScanIndexOptions = {
/** Only include results starting with the *secondary* keys starting with `prefix`. */

@@ -382,3 +785,3 @@ prefix?: string | undefined;

*/
declare type KeyTypeForScanOptions<O extends ScanOptions> = O extends ScanIndexOptions ? IndexKey : string;
type KeyTypeForScanOptions<O extends ScanOptions> = O extends ScanIndexOptions ? IndexKey : string;
/**

@@ -395,3 +798,3 @@ * The key to start scanning at.

*/
declare type ScanOptionIndexedStartKey = readonly [secondary: string, primary?: string | undefined] | string;
type ScanOptionIndexedStartKey = readonly [secondary: string, primary?: string | undefined] | string;

@@ -405,5 +808,5 @@ /**

declare type IterableUnion<T> = AsyncIterable<T> | Iterable<T>;
type IterableUnion<T> = AsyncIterable<T> | Iterable<T>;
declare type ScanKey = string | IndexKey;
type ScanKey = string | IndexKey;
interface ScanResult<K extends ScanKey> extends AsyncIterable<ReadonlyJSONValue> {

@@ -450,3 +853,3 @@ /** The default AsyncIterable. This is the same as {@link values}. */

*/
declare type GetScanIterator = (fromKey: string) => IterableUnion<Entry<ReadonlyJSONValue>>;
type GetScanIterator = (fromKey: string) => IterableUnion<Entry<ReadonlyJSONValue>>;
/**

@@ -464,3 +867,3 @@ * When using {@link makeScanResult} this is the type used for the function called when doing a {@link ReadTransaction.scan | scan} with an

*/
declare type GetIndexScanIterator = (indexName: string, fromSecondaryKey: string, fromPrimaryKey: string | undefined) => IterableUnion<readonly [key: IndexKey, value: ReadonlyJSONValue]>;
type GetIndexScanIterator = (indexName: string, fromSecondaryKey: string, fromPrimaryKey: string | undefined) => IterableUnion<readonly [key: IndexKey, value: ReadonlyJSONValue]>;
/**

@@ -498,71 +901,5 @@ * A helper function that makes it easier to implement {@link ReadTransaction.scan}

type TransactionEnvironment = 'client' | 'server';
type TransactionReason = 'initial' | 'rebase' | 'authoritative';
/**
* Function that gets passed into {@link Replicache.experimentalWatch} and gets
* called when the data in Replicache changes.
*
* @experimental This type is experimental and may change in the future.
*/
declare type WatchNoIndexCallback = (diff: NoIndexDiff) => void;
declare type WatchCallbackForOptions<Options extends WatchOptions> = Options extends WatchIndexOptions ? WatchIndexCallback : WatchNoIndexCallback;
/**
* Function that gets passed into {@link Replicache.experimentalWatch} when doing a
* watch on a secondary index map and gets called when the data in Replicache
* changes.
*
* @experimental This type is experimental and may change in the future.
*/
declare type WatchIndexCallback = (diff: IndexDiff) => void;
/**
* Options for {@link Replicache.experimentalWatch}.
*
* @experimental This interface is experimental and may change in the future.
*/
declare type WatchOptions = WatchIndexOptions | WatchNoIndexOptions;
/**
* Options object passed to {@link Replicache.experimentalWatch}. This is for an
* index watch.
*/
declare type WatchIndexOptions = WatchNoIndexOptions & {
/**
* When provided, the `watch` is limited to the changes that apply to the index map.
*/
indexName: string;
};
/**
* Options object passed to {@link Replicache.experimentalWatch}. This is for a non
* index watch.
*/
declare type WatchNoIndexOptions = {
/**
* When provided, the `watch` is limited to changes where the `key` starts
* with `prefix`.
*/
prefix?: string;
/**
* When this is set to `true` (default is `false`), the `watch` callback will
* be called once asynchronously when watch is called. The arguments in that
* case is a diff where we consider all the existing values in Replicache as
* being added.
*/
initialValuesInFirstDiff?: boolean;
};
/**
* The options passed to {@link Replicache.subscribe}.
*/
interface SubscribeOptions<R extends ReadonlyJSONValue | undefined> {
/**
* Called when the return value of the body function changes.
*/
onData: (result: R) => void;
/**
* If present, called when an error occurs.
*/
onError?: ((error: unknown) => void) | undefined;
/**
* If present, called when the subscription is removed/done.
*/
onDone?: (() => void) | undefined;
}
/**
* ReadTransactions are used with {@link Replicache.query} and

@@ -574,2 +911,3 @@ * {@link Replicache.subscribe} and allows read operations on the

readonly clientID: ClientID;
readonly environment: TransactionEnvironment;
/**

@@ -633,2 +971,10 @@ * Get a single value from the database. If the `key` is not present this

/**
* The ID of the mutation that is being applied.
*/
readonly mutationID: number;
/**
* The reason for the transaction. This can be `initial`, `rebase` or `authoriative`.
*/
readonly reason: TransactionReason;
/**
* Sets a single `value` in the database. The value will be frozen (using

@@ -644,3 +990,3 @@ * `Object.freeze`) in debug mode.

}
declare type CreateIndexDefinition = IndexDefinition & {
type CreateIndexDefinition = IndexDefinition & {
name: string;

@@ -650,273 +996,70 @@ };

/**
* The options passed to {@link Replicache}.
* Function that gets passed into {@link Replicache.experimentalWatch} and gets
* called when the data in Replicache changes.
*
* @experimental This type is experimental and may change in the future.
*/
interface ReplicacheOptions<MD extends MutatorDefs> {
type WatchNoIndexCallback = (diff: NoIndexDiff) => void;
type WatchCallbackForOptions<Options extends WatchOptions> = Options extends WatchIndexOptions ? WatchIndexCallback : WatchNoIndexCallback;
/**
* Function that gets passed into {@link Replicache.experimentalWatch} when doing a
* watch on a secondary index map and gets called when the data in Replicache
* changes.
*
* @experimental This type is experimental and may change in the future.
*/
type WatchIndexCallback = (diff: IndexDiff) => void;
/**
* Options for {@link Replicache.experimentalWatch}.
*
* @experimental This interface is experimental and may change in the future.
*/
type WatchOptions = WatchIndexOptions | WatchNoIndexOptions;
/**
* Options object passed to {@link Replicache.experimentalWatch}. This is for an
* index watch.
*/
type WatchIndexOptions = WatchNoIndexOptions & {
/**
* This is the URL to the server endpoint dealing with the push updates. See
* [Push Endpoint Reference](https://doc.replicache.dev/reference/server-push) for more
* details.
*
* If not provided, push requests will not be made unless a custom
* {@link ReplicacheOptions.pusher} is provided.
* When provided, the `watch` is limited to the changes that apply to the index map.
*/
pushURL?: string | undefined;
indexName: string;
};
/**
* Options object passed to {@link Replicache.experimentalWatch}. This is for a non
* index watch.
*/
type WatchNoIndexOptions = {
/**
* This is the authorization token used when doing a
* [pull](https://doc.replicache.dev/reference/server-pull#authorization) and
* [push](https://doc.replicache.dev/reference/server-push#authorization).
* When provided, the `watch` is limited to changes where the `key` starts
* with `prefix`.
*/
auth?: string | undefined;
prefix?: string;
/**
* This is the URL to the server endpoint dealing with pull. See [Pull
* Endpoint Reference](https://doc.replicache.dev/reference/server-pull) for more
* details.
*
* If not provided, pull requests will not be made unless a custom
* {@link ReplicacheOptions.puller} is provided.
* When this is set to `true` (default is `false`), the `watch` callback will
* be called once asynchronously when watch is called. The arguments in that
* case is a diff where we consider all the existing values in Replicache as
* being added.
*/
pullURL?: string | undefined;
initialValuesInFirstDiff?: boolean;
};
/**
* The options passed to {@link Replicache.subscribe}.
*/
interface SubscribeOptions<R extends ReadonlyJSONValue | undefined> {
/**
* The name of the Replicache database.
*
* It is important to use user specific names so that if there are multiple
* tabs open for different distinct users their data is kept separate.
*
* For efficiency and performance, a new {@link Replicache} instance will
* initialize its state from the persisted state of an existing {@link Replicache}
* instance with the same `name`, domain and browser profile.
*
* Mutations from one {@link Replicache} instance may be pushed using the
* {@link ReplicacheOptions.auth}, {@link ReplicacheOptions.pushURL},
* {@link ReplicacheOptions.pullURL}, {@link ReplicacheOptions.pusher}, and
* {@link ReplicacheOptions.puller} of another Replicache instance with the same
* `name`, domain and browser profile.
*
* You can use multiple Replicache instances for the same user as long as the
* names are unique. e.g. `name: `$userID:$roomID`
* Called when the return value of the body function changes.
*/
name: string;
onData: (result: R) => void;
/**
* The schema version of the data understood by this application. This enables
* versioning of mutators (in the push direction) and the client view (in the
* pull direction).
* If present, called when an error occurs.
*/
schemaVersion?: string | undefined;
onError?: ((error: unknown) => void) | undefined;
/**
* The duration between each {@link pull} in milliseconds. Set this to `null` to
* prevent pulling in the background. Defaults to 60 seconds.
* If present, called when the subscription is removed/done.
*/
pullInterval?: number | null | undefined;
/**
* The delay between when a change is made to Replicache and when Replicache
* attempts to push that change.
*/
pushDelay?: number | undefined;
/**
* Determines how much logging to do. When this is set to `'debug'`,
* Replicache will also log `'info'` and `'error'` messages. When set to
* `'info'` we log `'info'` and `'error'` but not `'debug'`. When set to
* `'error'` we only log `'error'` messages.
* Default is `'info'`.
*/
logLevel?: LogLevel | undefined;
/**
* Enables custom handling of logs.
*
* By default logs are logged to the console. If you would like logs to be
* sent elsewhere (e.g. to a cloud logging service like DataDog) you can
* provide an array of {@link LogSink}s. Logs at or above
* {@link ReplicacheOptions.logLevel} are sent to each of these {@link LogSink}s.
* If you would still like logs to go to the console, include
* `consoleLogSink` in the array.
*
* ```ts
* logSinks: [consoleLogSink, myCloudLogSink],
* ```
*/
logSinks?: LogSink[] | undefined;
/**
* An object used as a map to define the *mutators*. These gets registered at
* startup of {@link Replicache}.
*
* *Mutators* are used to make changes to the data.
*
* #### Example
*
* The registered *mutations* are reflected on the
* {@link Replicache.mutate | mutate} property of the {@link Replicache} instance.
*
* ```ts
* const rep = new Replicache({
* name: 'user-id',
* mutators: {
* async createTodo(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);
* },
* async deleteTodo(tx: WriteTransaction, id: number) {
* ...
* },
* },
* });
* ```
*
* This will create the function to later use:
*
* ```ts
* await rep.mutate.createTodo({
* id: 1234,
* title: 'Make things work offline',
* complete: true,
* });
* ```
*
* #### Replays
*
* *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 push, a description of each mutation is sent to the server's [push
* endpoint](https://doc.replicache.dev/reference/server-push) where it is applied. Once
* the *mutation* has been applied successfully, as indicated by the client
* view's
* [`lastMutationId`](https://doc.replicache.dev/reference/server-pull#lastmutationid)
* field, the local version of the *mutation* is removed. See the [design
* doc](https://doc.replicache.dev/design#commits) for additional details on
* the sync protocol.
*
* #### Transactionality
*
* *Mutators* are atomic: all their changes are applied together, or none are.
* Throwing an exception aborts the transaction. Otherwise, it is committed.
* As with {@link query} and {@link subscribe} all reads will see a consistent view of
* the cache while they run.
*/
mutators?: MD | undefined;
/**
* Options to use when doing pull and push requests.
*/
requestOptions?: RequestOptions | undefined;
/**
* Allows passing in a custom implementation of a {@link Puller} function. This
* function is called when doing a pull and it is responsible for
* communicating with the server.
*
* Normally, this is just a POST to a URL with a JSON body but you can provide
* your own function if you need to do things differently.
*/
puller?: Puller | undefined;
/**
* Allows passing in a custom implementation of a {@link Pusher} function. This
* function is called when doing a push and it is responsible for
* communicating with the server.
*
* Normally, this is just a POST to a URL with a JSON body but you can provide
* your own function if you need to do things differently.
*/
pusher?: Pusher | undefined;
/**
* The license key for Replicache. This parameter is required for Replicache to
* function. See https://replicache.dev for how to acquire a license key.
*
* YOU SHOULD PASS TEST_LICENSE_KEY IN AUTOMATED TESTS. It disables license
* checks for several minutes. If you pass a normal license key in tests, each test
* that instantiates Replicache will attempt to perform a license check against
* Replicache's licensing server, potentially increasing your monthly active browser
* profile count, slowing the test down, and spamming Replicache's servers.
*/
licenseKey: string;
/**
* Allows providing a custom implementation of the underlying storage layer.
*
* @experimental This option is experimental and might be removed or changed
* in the future without following semver versioning. Please be cautious.
*/
experimentalCreateKVStore?: CreateStore | undefined;
/**
* Defines the indexes, if any, to use on the data.
*/
readonly indexes?: IndexDefinitions | undefined;
onDone?: (() => void) | undefined;
}
declare type ClientMap = ReadonlyMap<ClientID, ClientSDD | ClientDD31>;
declare type ClientSDD = {
/**
* A UNIX timestamp in milliseconds updated by the client once a minute
* while it is active and every time the client persists its state to
* the perdag.
* Should only be updated by the client represented by this structure.
*/
readonly heartbeatTimestampMs: number;
/**
* The hash of the commit in the perdag this client last persisted.
* Should only be updated by the client represented by this structure.
*/
readonly headHash: Hash;
/**
* The mutationID of the commit at headHash (mutationID if it is a
* local commit, lastMutationID if it is an index change or snapshot commit).
* Should only be updated by the client represented by this structure.
* Read by other clients to determine if there are unacknowledged pending
* mutations for them to push on behalf of the client represented by this
* structure.
* This is redundant with information in the commit graph at headHash,
* but allows other clients to determine if there are unacknowledged pending
* mutations without having to load the commit graph at headHash.
*/
readonly mutationID: number;
/**
* The highest lastMutationID received from the server for this client.
*
* Should be updated by the client represented by this structure whenever
* it persists its state to the perdag.
* Read by other clients to determine if there are unacknowledged pending
* mutations for them to push on behalf of the client represented by this
* structure, and *updated* by other clients upon successfully pushing
* pending mutations to avoid redundant pushes of those mutations.
*
* Note: This will be the same as the lastMutationID of the base snapshot of
* the commit graph at headHash when written by the client represented by this
* structure. However, when written by another client pushing pending
* mutations on this client's behalf it will be different. This is because
* the other client does not update the commit graph (it is unsafe to update
* another client's commit graph).
*/
readonly lastServerAckdMutationID: number;
};
declare type ClientDD31 = {
readonly heartbeatTimestampMs: number;
readonly headHash: Hash;
/**
* The hash of a commit we are in the middle of refreshing into this client's
* memdag.
*/
readonly tempRefreshHash: Hash | null;
/**
* ID of this client's perdag client group. This needs to be sent in pull
* request (to enable syncing all last mutation ids in the client group).
*/
readonly clientGroupID: ClientGroupID;
};
/**
* Deletes all IndexedDB data associated with Replicache.
*
* Returns an object with the names of the successfully dropped databases
* and any errors encountered while dropping.
*/
declare function deleteAllReplicacheData(createKVStore?: CreateStore): Promise<{
dropped: string[];
errors: unknown[];
}>;
declare type BeginPullResult = {
type BeginPullResult = {
requestID: string;

@@ -926,8 +1069,8 @@ syncHead: Hash;

};
declare type Poke = {
type Poke = {
baseCookie: ReadonlyJSONValue;
pullResponse: PullResponse;
pullResponse: PullResponseV1;
};
declare type MaybePromise<T> = T | Promise<T>;
declare type ToPromise<P> = P extends Promise<unknown> ? P : Promise<P>;
type MaybePromise<T> = T | Promise<T>;
type ToPromise<P> = P extends Promise<unknown> ? P : Promise<P>;
/**

@@ -940,3 +1083,3 @@ * Returns the name of the IDB database that will be used for a particular Replicache instance.

declare function makeIDBName(name: string, schemaVersion?: string): string;
declare type MutatorReturn<T extends ReadonlyJSONValue = ReadonlyJSONValue> = MaybePromise<T | void>;
type MutatorReturn<T extends ReadonlyJSONValue = ReadonlyJSONValue> = MaybePromise<T | void>;
/**

@@ -949,7 +1092,7 @@ * The type used to describe the mutator definitions passed into [Replicache](classes/Replicache)

*/
declare type MutatorDefs = {
type MutatorDefs = {
[key: string]: (tx: WriteTransaction, args?: any) => MutatorReturn;
};
declare type MakeMutator<F extends (tx: WriteTransaction, ...args: [] | [ReadonlyJSONValue]) => MutatorReturn> = F extends (tx: WriteTransaction, ...args: infer Args) => infer Ret ? (...args: Args) => ToPromise<Ret> : never;
declare type MakeMutators<T extends MutatorDefs> = {
type MakeMutator<F extends (tx: WriteTransaction, ...args: [] | [ReadonlyJSONValue]) => MutatorReturn> = F extends (tx: WriteTransaction, ...args: infer Args) => infer Ret ? (...args: Args) => ToPromise<Ret> : never;
type MakeMutators<T extends MutatorDefs> = {
readonly [P in keyof T]: MakeMutator<T[P]>;

@@ -973,13 +1116,15 @@ };

/**
* The reason {@link onClientStateNotFound} was called.
* The reason {@link onUpdateNeeded} was called.
*/
declare type ClientStateNotFoundReason = {
type: 'NotFoundOnServer';
type UpdateNeededReason = {
type: 'NewClientGroup';
} | {
type: 'NotFoundOnClient';
type: 'VersionNotSupported';
versionType?: 'push' | 'pull' | 'schema' | undefined;
};
declare type PendingMutation = {
type PendingMutation = {
readonly name: string;
readonly id: number;
readonly args: ReadonlyJSONValue;
readonly clientID: ClientID;
};

@@ -998,2 +1143,7 @@ declare class Replicache<MD extends MutatorDefs = {}> {

/**
* Client groups gets disabled when the server does not know about it.
* A disabled client group prevents the client from pushing and pulling.
*/
private _isClientGroupDisabled;
/**
* Factory function to create the persisted stores. Defaults to use `new

@@ -1004,4 +1154,2 @@ * IDBStore(name)`.

/**
/**
* This is the name Replicache uses for the IndexedDB database where data is

@@ -1061,3 +1209,4 @@ * stored.

private readonly _enableScheduledPersist;
private readonly _enableRefresh;
private readonly _enableScheduledRefresh;
private readonly _enablePullAndPushInOpen;
private _persistScheduler;

@@ -1073,5 +1222,4 @@ private readonly _onPersist;

/**
* `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.
* `onSync` is called when a sync begins (the `syncing` parameter is then set
* to `true`), and again when the sync ends (`syncing` is set to `false`).
*

@@ -1090,7 +1238,5 @@ * This can be used in a React like app by doing something like the following:

* `onClientStateNotFound` is called when the persistent client has been
* garbage collected. This can happen if the client has not been used for over
* a week.
* garbage collected. This can happen if the client has no pending mutations
* and has not been used for a while.
*
* It can also happen if the server no longer knows about this client.
*
* The default behavior is to reload the page (using `location.reload()`). Set

@@ -1100,4 +1246,24 @@ * this to `null` or provide your own function to prevent the page from

*/
onClientStateNotFound: ((reason: ClientStateNotFoundReason) => void) | null;
onClientStateNotFound: (() => void) | null;
/**
* `onUpdateNeeded` is called when a code update is needed.
*
* A code update can be needed because:
* - the server no longer supports the {@link pushVersion},
* {@link pullVersion} or {@link schemaVersion} of the current code.
* - a new Replicache client has created a new client group, because its code
* has different mutators, indexes, schema version and/or format version
* from this Replicache client. This is likely due to the new client having
* newer code. A code update is needed to be able to locally sync with this
* new Replicache client (i.e. to sync while offline, the clients can can
* still sync with each other via the server).
*
* The default behavior is to reload the page (using `location.reload()`). Set
* this to `null` or provide your own function to prevent the page from
* reloading automatically. You may want to provide your own function to
* display a toast to inform the end user there is a new version of your app
* available and prompting them to refresh.
*/
onUpdateNeeded: ((reason: UpdateNeededReason) => void) | null;
/**
* This gets called when we get an HTTP unauthorized (401) response from the

@@ -1110,3 +1276,2 @@ * push or pull endpoint. Set this to a function that will ask your user to

private _open;
private _syncIndexes;
private _onVisibilityChange;

@@ -1128,2 +1293,9 @@ private _checkForClientStateNotFoundAndCallHandler;

/**
* The client group ID for this instance of Replicache. Instances of
* Replicache will have the same client group ID if and only if they have
* the same name, mutators, indexes, schema version, format version, and
* browser profile.
*/
get clientGroupID(): Promise<string>;
/**
* `onOnlineChange` is called when the {@link online} property changes. See

@@ -1155,17 +1327,2 @@ * {@link online} for more details.

private _checkChange;
/**
* 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 thrown.
* @deprecated Use {@link ReplicacheOptions.indexes} instead.
*/
createIndex(def: CreateIndexDefinition): Promise<void>;
/**
* Drops an index previously created with {@link createIndex}.
* @deprecated Use {@link ReplicacheOptions.indexes} instead.
*/
dropIndex(name: string): Promise<void>;
private _indexOp;
protected _maybeEndPull(syncHead: Hash, requestID: string): Promise<void>;

@@ -1178,2 +1335,3 @@ private _invokePull;

protected _invokePush(): Promise<boolean>;
private _handleVersionNotSupportedResponse;
/**

@@ -1206,2 +1364,5 @@ * Push pushes pending changes to the {@link pushURL}.

private _fireOnClientStateNotFound;
private _clientStateNotFoundOnClient;
private _clientStateNotFoundOnServer;
private _fireOnUpdateNeeded;
private _schedulePersist;

@@ -1286,6 +1447,63 @@ private _handlePersist;

// TODO when our license is finalized add a link to it.
declare const TEST_LICENSE_KEY = 'This key only good for automated testing';
type Entry<V> = readonly [key: string, value: V];
/**
* Describes the changes that happened to Replicache after a
* {@link WriteTransaction} was committed.
*
* @experimental This type is experimental and may change in the future.
*/
type Diff = IndexDiff | NoIndexDiff;
/**
* @experimental This type is experimental and may change in the future.
*/
type IndexDiff = readonly DiffOperation<IndexKey>[];
/**
* @experimental This type is experimental and may change in the future.
*/
type NoIndexDiff = readonly DiffOperation<string>[];
type DiffOperationAdd<Key, Value = ReadonlyJSONValue> = {
readonly op: 'add';
readonly key: Key;
readonly newValue: Value;
};
type DiffOperationDel<Key, Value = ReadonlyJSONValue> = {
readonly op: 'del';
readonly key: Key;
readonly oldValue: Value;
};
type DiffOperationChange<Key, Value = ReadonlyJSONValue> = {
readonly op: 'change';
readonly key: Key;
readonly oldValue: Value;
readonly newValue: Value;
};
/**
* 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.
*/
type DiffOperation<Key> = DiffOperationAdd<Key> | DiffOperationDel<Key> | DiffOperationChange<Key>;
/**
* Filters an async iterable.
*
* This utility function is provided because it is useful when using
* {@link makeScanResult}. It can be used to filter out tombstones (delete entries)
* for example.
*/
declare function filterAsyncIterable<V>(iter: IterableUnion<V>, predicate: (v: V) => boolean): AsyncIterable<V>;
/**
* This creates a default puller which uses HTTP POST to send the pull request.
*/
declare function getDefaultPuller(rep: {
pullURL: string;
auth: string;
}): Puller;
/**
* Merges an iterable on to another iterable.

@@ -1306,9 +1524,9 @@ *

/**
* Filters an async iterable.
*
* This utility function is provided because it is useful when using
* {@link makeScanResult}. It can be used to filter out tombstones (delete entries)
* for example.
* This error is thrown when the puller fails for any reason.
*/
declare function filterAsyncIterable<V>(iter: IterableUnion<V>, predicate: (v: V) => boolean): AsyncIterable<V>;
declare class PullError extends Error {
name: string;
causedBy?: Error | undefined;
constructor(causedBy?: Error);
}

@@ -1320,2 +1538,2 @@ /**

export { AsyncIterableIteratorToArray, ClientID, ClientStateNotFoundReason, ClientStateNotFoundResponse, CreateIndexDefinition, CreateStore as ExperimentalCreateKVStore, Diff as ExperimentalDiff, DiffOperation as ExperimentalDiffOperation, DiffOperationAdd as ExperimentalDiffOperationAdd, DiffOperationChange as ExperimentalDiffOperationChange, DiffOperationDel as ExperimentalDiffOperationDel, IndexDiff as ExperimentalIndexDiff, Read as ExperimentalKVRead, Store as ExperimentalKVStore, Write as ExperimentalKVWrite, MemStore as ExperimentalMemKVStore, NoIndexDiff as ExperimentalNoIndexDiff, WatchCallbackForOptions as ExperimentalWatchCallbackForOptions, WatchIndexCallback as ExperimentalWatchIndexCallback, WatchIndexOptions as ExperimentalWatchIndexOptions, WatchNoIndexCallback as ExperimentalWatchNoIndexCallback, WatchNoIndexOptions as ExperimentalWatchNoIndexOptions, WatchOptions as ExperimentalWatchOptions, GetIndexScanIterator, GetScanIterator, HTTPRequestInfo, IndexDefinition, IndexDefinitions, IndexKey, IterableUnion, JSONObject, JSONValue, KeyTypeForScanOptions, LogLevel, LogSink, MaybePromise, Mutation, MutatorDefs, PatchOperation, PendingMutation, Poke, PullError, PullRequest, PullResponse, PullResponseOK, Puller, PullerResult, PushError, PushRequest, Pusher, ReadTransaction, ReadonlyJSONObject, ReadonlyJSONValue, Replicache, ReplicacheOptions, RequestOptions, ScanIndexOptions, ScanNoIndexOptions, ScanOptionIndexedStartKey, ScanOptions, ScanResult, SubscribeOptions, TEST_LICENSE_KEY, TransactionClosedError, WriteTransaction, consoleLogSink, deleteAllReplicacheData, filterAsyncIterable, isScanIndexOptions, makeIDBName, makeScanResult, mergeAsyncIterables, version };
export { AsyncIterableIteratorToArray, ClientGroupID, ClientID, ClientStateNotFoundResponse, Cookie, CreateIndexDefinition, CreateStore as ExperimentalCreateKVStore, Diff as ExperimentalDiff, DiffOperation as ExperimentalDiffOperation, DiffOperationAdd as ExperimentalDiffOperationAdd, DiffOperationChange as ExperimentalDiffOperationChange, DiffOperationDel as ExperimentalDiffOperationDel, IndexDiff as ExperimentalIndexDiff, Read as ExperimentalKVRead, Store as ExperimentalKVStore, Write as ExperimentalKVWrite, MemStore as ExperimentalMemKVStore, NoIndexDiff as ExperimentalNoIndexDiff, WatchCallbackForOptions as ExperimentalWatchCallbackForOptions, WatchIndexCallback as ExperimentalWatchIndexCallback, WatchIndexOptions as ExperimentalWatchIndexOptions, WatchNoIndexCallback as ExperimentalWatchNoIndexCallback, WatchNoIndexOptions as ExperimentalWatchNoIndexOptions, WatchOptions as ExperimentalWatchOptions, GetIndexScanIterator, GetScanIterator, HTTPRequestInfo, IDBNotFoundError, IndexDefinition, IndexDefinitions, IndexKey, IterableUnion, JSONObject, JSONValue, KeyTypeForScanOptions, LogLevel, LogSink, MaybePromise, MutationV0, MutationV1, MutatorDefs, MutatorReturn, PatchOperation, PendingMutation, Poke, PullError, PullRequest, PullRequestV0, PullRequestV1, PullResponse, PullResponseOKV0, PullResponseOKV1, PullResponseV0, PullResponseV1, Puller, PullerResult, PullerResultV0, PullerResultV1, PushError, PushRequest, PushRequestV0, PushRequestV1, PushResponse, Pusher, PusherResult, ReadTransaction, ReadonlyJSONObject, ReadonlyJSONValue, Replicache, ReplicacheOptions, RequestOptions, ScanIndexOptions, ScanNoIndexOptions, ScanOptionIndexedStartKey, ScanOptions, ScanResult, SubscribeOptions, TEST_LICENSE_KEY, TransactionClosedError, TransactionEnvironment, TransactionReason, UpdateNeededReason, VersionNotSupportedResponse, WriteTransaction, consoleLogSink, deleteAllReplicacheData, dropAllDatabases, dropDatabase, filterAsyncIterable, getDefaultPuller, isScanIndexOptions, makeIDBName, makeScanResult, mergeAsyncIterables, version };
{
"name": "replicache",
"description": "Realtime sync for any backend stack",
"version": "12.2.1",
"version": "13.0.0-beta.0",
"repository": "github:rocicorp/replicache",

@@ -10,5 +10,5 @@ "license": "https://roci.dev/terms.html",

"test:watch": "web-test-runner --watch",
"format": "prettier --write '{doc,src,sample,perf}/**/*.{js,jsx,json,ts,tsx,html,css,md}' '*.{cjs,js,jsx,json,ts,tsx,html,css,md}'",
"check-format": "prettier --check '{doc,src,sample,perf}/**/*.{js,jsx,json,ts,tsx,html,css,md}' '*.{cjs,js,jsx,json,ts,tsx,html,css,md}'",
"check-types": "tsc --noEmit && npm run build && tsc --noEmit --project perf/tsconfig.json && tsc --noEmit tool/cli.ts",
"format": "prettier --write *",
"check-format": "prettier --check *",
"check-types": "tsc --noEmit && npm run build && tsc --noEmit --project perf/tsconfig.json && tsc --noEmit --project tool/tsconfig.json",
"lint": "eslint --ext .ts,.tsx,.js,.jsx src/ perf/",

@@ -24,24 +24,25 @@ "build-dts": "rm -rf out/.dts/ && tsc --emitDeclarationOnly --outDir out/.dts/ && rollup --config rollup.config.js && rm -rf out/.dts",

},
"dependencies": {
"@rocicorp/lock": "^1.0.1",
"@rocicorp/logger": "^4.1.0",
"@rocicorp/resolver": "^1.0.0"
},
"devDependencies": {
"@esm-bundle/chai": "^4.3.4",
"@rocicorp/eslint-config": "^0.2.0",
"@rocicorp/licensing": "^4.1.0",
"@rocicorp/lock": "^1.0.1",
"@rocicorp/logger": "^2.2.0",
"@esm-bundle/chai": "^4.3.4-fix.0",
"@rocicorp/eslint-config": "^0.3.0",
"@rocicorp/licensing": "^5.0.0",
"@rocicorp/prettier-config": "^0.1.1",
"@rocicorp/resolver": "^1.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@types/command-line-usage": "^5.0.2",
"@types/lodash-es": "^4.17.6",
"@types/mocha": "^9.1.0",
"@types/node": "^18.11.9",
"@types/sinon": "^10.0.11",
"@web/dev-server": "0.1.29",
"@web/dev-server-esbuild": "^0.2.16",
"@web/test-runner": "^0.13.25",
"@web/test-runner-playwright": "^0.8.8",
"@web/dev-server": "^0.1.36",
"@web/dev-server-esbuild": "^0.3.4",
"@web/test-runner": "^0.15.1",
"@web/test-runner-playwright": "^0.9.0",
"benchmark": "^2.1.4",
"command-line-args": "^5.2.1",
"command-line-usage": "^6.1.2",
"compare-utf8": "^0.1.0",
"esbuild": "^0.14.34",
"compare-utf8": "^0.1.1",
"esbuild": "^0.17.11",
"fetch-mock": "^9.11.0",

@@ -52,7 +53,8 @@ "get-port": "^6.1.2",

"navigator.locks": "^0.8.5",
"playwright": "^1.20.2",
"rollup": "^2.70.1",
"rollup-plugin-dts": "^4.2.0",
"playwright": "^1.28.1",
"rollup": "^3.19.1",
"rollup-plugin-dts": "^5.2.0",
"shared": "*",
"sinon": "^13.0.1",
"typescript": "^4.8.3",
"typescript": "^4.9.5",
"xbytes": "^1.7.0"

@@ -59,0 +61,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc