replicache
Advanced tools
Comparing version 15.0.0 to 15.0.1
@@ -7,2 +7,4 @@ import { LogLevel, LogSink } from '@rocicorp/logger'; | ||
type MaybePromise<T> = T | Promise<T>; | ||
/** The values that can be represented in JSON */ | ||
@@ -699,2 +701,76 @@ type JSONValue = | ||
/** | ||
* 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. | ||
*/ | ||
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 & { | ||
/** | ||
* 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. | ||
*/ | ||
type WatchNoIndexOptions = { | ||
/** | ||
* When provided, the `watch` is limited to changes where the `key` starts | ||
* with `prefix`. | ||
*/ | ||
prefix?: string | undefined; | ||
/** | ||
* 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 | undefined; | ||
}; | ||
/** | ||
* The options passed to {@link Replicache.subscribe}. | ||
*/ | ||
interface SubscribeOptions<R> { | ||
/** | ||
* 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; | ||
/** | ||
* If present this function is used to determine if the value returned by the | ||
* body function has changed. If not provided a JSON deep equality check is | ||
* used. | ||
*/ | ||
isEqual?: ((a: R, b: R) => boolean) | undefined; | ||
} | ||
type TransactionEnvironment = 'client' | 'server'; | ||
@@ -792,76 +868,2 @@ type TransactionLocation = TransactionEnvironment; | ||
/** | ||
* 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. | ||
*/ | ||
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 & { | ||
/** | ||
* 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. | ||
*/ | ||
type WatchNoIndexOptions = { | ||
/** | ||
* When provided, the `watch` is limited to changes where the `key` starts | ||
* with `prefix`. | ||
*/ | ||
prefix?: string | undefined; | ||
/** | ||
* 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 | undefined; | ||
}; | ||
/** | ||
* The options passed to {@link Replicache.subscribe}. | ||
*/ | ||
interface SubscribeOptions<R> { | ||
/** | ||
* 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; | ||
/** | ||
* If present this function is used to determine if the value returned by the | ||
* body function has changed. If not provided a JSON deep equality check is | ||
* used. | ||
*/ | ||
isEqual?: ((a: R, b: R) => boolean) | undefined; | ||
} | ||
type Poke = { | ||
@@ -871,29 +873,15 @@ baseCookie: ReadonlyJSONValue; | ||
}; | ||
type MaybePromise<T> = T | Promise<T>; | ||
type ToPromise<P> = P extends Promise<unknown> ? P : Promise<P>; | ||
/** | ||
* Returns the name of the IDB database that will be used for a particular Replicache instance. | ||
* @param name The name of the Replicache instance (i.e., the `name` field of `ReplicacheOptions`). | ||
* @param schemaVersion The schema version of the database (i.e., the `schemaVersion` field of `ReplicacheOptions`). | ||
* @returns | ||
*/ | ||
declare function makeIDBName(name: string, schemaVersion?: string): string; | ||
type MutatorReturn<T extends ReadonlyJSONValue = ReadonlyJSONValue> = MaybePromise<T | void>; | ||
/** | ||
* The type used to describe the mutator definitions passed into [Replicache](classes/Replicache) | ||
* constructor as part of the {@link ReplicacheOptions}. | ||
* | ||
* See {@link ReplicacheOptions} {@link ReplicacheOptions.mutators | mutators} for more | ||
* info. | ||
*/ | ||
type MutatorReturn<T extends ReadonlyJSONValue = ReadonlyJSONValue> = MaybePromise<T | void>; /** | ||
* The type used to describe the mutator definitions passed into [Replicache](classes/Replicache) | ||
* constructor as part of the {@link ReplicacheOptions}. | ||
* | ||
* See {@link ReplicacheOptions} {@link ReplicacheOptions.mutators | mutators} for more | ||
* info. | ||
*/ | ||
type MutatorDefs = { | ||
[key: string]: (tx: WriteTransaction, args?: any) => MutatorReturn; | ||
}; | ||
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]>; | ||
}; | ||
/** | ||
* Base options for {@link PullOptions} and {@link PushOptions} | ||
*/ | ||
type MakeMutator<F extends (tx: WriteTransaction, ...args: [] | [ReadonlyJSONValue]) => MutatorReturn> = F extends (tx: WriteTransaction, ...args: infer Args) => infer Ret ? (...args: Args) => ToPromise<Ret> : never; /** | ||
* Base options for {@link PullOptions} and {@link PushOptions} | ||
*/ | ||
interface RequestOptions { | ||
@@ -911,3 +899,6 @@ /** | ||
} | ||
/** | ||
type MakeMutators<T extends MutatorDefs> = { | ||
readonly [P in keyof T]: MakeMutator<T[P]>; | ||
}; | ||
type ToPromise<P> = P extends Promise<unknown> ? P : Promise<P>; /** | ||
* The reason {@link onUpdateNeeded} was called. | ||
@@ -921,12 +912,221 @@ */ | ||
}; | ||
/** | ||
* The options passed to {@link Replicache}. | ||
*/ | ||
interface ReplicacheOptions<MD extends MutatorDefs> { | ||
/** | ||
* 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. | ||
*/ | ||
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.set(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. | ||
*/ | ||
kvStore?: 'mem' | 'idb' | StoreProvider | undefined; | ||
/** | ||
* Defines the indexes, if any, to use on the data. | ||
*/ | ||
readonly indexes?: IndexDefinitions | undefined; | ||
} | ||
/** | ||
* Returns the name of the IDB database that will be used for a particular Replicache instance. | ||
* @param name The name of the Replicache instance (i.e., the `name` field of `ReplicacheOptions`). | ||
* @param schemaVersion The schema version of the database (i.e., the `schemaVersion` field of `ReplicacheOptions`). | ||
* @returns | ||
*/ | ||
declare function makeIDBName(name: string, schemaVersion?: string): string; | ||
declare class Replicache<MD extends MutatorDefs = {}> { | ||
#private; | ||
constructor(options: ReplicacheOptions<MD>); | ||
/** The URL to use when doing a pull request. */ | ||
pullURL: string; | ||
get pullURL(): string; | ||
set pullURL(value: string); | ||
/** The URL to use when doing a push request. */ | ||
pushURL: string; | ||
get pushURL(): string; | ||
set pushURL(value: string); | ||
/** The authorization token used when doing a push request. */ | ||
auth: string; | ||
get auth(): string; | ||
set auth(value: string); | ||
/** The name of the Replicache database. Populated by {@link ReplicacheOptions#name}. */ | ||
readonly name: string; | ||
get name(): string; | ||
/** | ||
@@ -938,7 +1138,7 @@ * This is the name Replicache uses for the IndexedDB database where data is | ||
/** The schema version of the data understood by this application. */ | ||
readonly schemaVersion: string; | ||
get schemaVersion(): string; | ||
/** | ||
* The mutators that was registered in the constructor. | ||
*/ | ||
readonly mutate: MakeMutators<MD>; | ||
get mutate(): MakeMutators<MD>; | ||
/** | ||
@@ -949,3 +1149,4 @@ * The duration between each periodic {@link pull}. Setting this to `null` | ||
*/ | ||
pullInterval: number | null; | ||
get pullInterval(): number | null; | ||
set pullInterval(value: number | null); | ||
/** | ||
@@ -955,11 +1156,14 @@ * The delay between when a change is made to Replicache and when Replicache | ||
*/ | ||
pushDelay: number; | ||
get pushDelay(): number; | ||
set pushDelay(value: number); | ||
/** | ||
* The function to use to pull data from the server. | ||
*/ | ||
puller: Puller; | ||
get puller(): Puller; | ||
set puller(value: Puller); | ||
/** | ||
* The function to use to push data to the server. | ||
*/ | ||
pusher: Pusher; | ||
get pusher(): Pusher; | ||
set pusher(value: Pusher); | ||
/** | ||
@@ -985,3 +1189,4 @@ * The options used to control the {@link pull} and push request behavior. This | ||
*/ | ||
onSync: ((syncing: boolean) => void) | null; | ||
get onSync(): ((syncing: boolean) => void) | null; | ||
set onSync(value: ((syncing: boolean) => void) | null); | ||
/** | ||
@@ -996,3 +1201,4 @@ * `onClientStateNotFound` is called when the persistent client has been | ||
*/ | ||
onClientStateNotFound: (() => void) | null; | ||
get onClientStateNotFound(): (() => void) | null; | ||
set onClientStateNotFound(value: (() => void) | null); | ||
/** | ||
@@ -1017,3 +1223,4 @@ * `onUpdateNeeded` is called when a code update is needed. | ||
*/ | ||
onUpdateNeeded: ((reason: UpdateNeededReason) => void) | null; | ||
get onUpdateNeeded(): ((reason: UpdateNeededReason) => void) | null; | ||
set onUpdateNeeded(value: ((reason: UpdateNeededReason) => void) | null); | ||
/** | ||
@@ -1024,4 +1231,4 @@ * This gets called when we get an HTTP unauthorized (401) response from the | ||
*/ | ||
getAuth: (() => MaybePromise<string | null | undefined>) | null | undefined; | ||
constructor(options: ReplicacheOptions<MD>); | ||
get getAuth(): (() => MaybePromise<string | null | undefined>) | null | undefined; | ||
set getAuth(value: (() => MaybePromise<string | null | undefined>) | null | undefined); | ||
/** | ||
@@ -1048,3 +1255,4 @@ * The browser profile ID for this browser profile. Every instance of Replicache | ||
*/ | ||
onOnlineChange: ((online: boolean) => void) | null; | ||
get onOnlineChange(): ((online: boolean) => void) | null; | ||
set onOnlineChange(value: ((online: boolean) => void) | null); | ||
/** | ||
@@ -1071,3 +1279,3 @@ * A rough heuristic for whether the client is currently online. Note that | ||
/** | ||
* Push pushes pending changes to the {@link pushURL}. | ||
* Push pushes pending changes to the {@link pushURLXXX}. | ||
* | ||
@@ -1188,199 +1396,2 @@ * You do not usually need to manually call push. If {@link pushDelay} is | ||
/** | ||
* The options passed to {@link Replicache}. | ||
*/ | ||
interface ReplicacheOptions<MD extends MutatorDefs> { | ||
/** | ||
* 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. | ||
*/ | ||
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.set(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. | ||
*/ | ||
kvStore?: 'mem' | 'idb' | StoreProvider | undefined; | ||
/** | ||
* Defines the indexes, if any, to use on the data. | ||
*/ | ||
readonly indexes?: IndexDefinitions | undefined; | ||
} | ||
/** | ||
* This error is thrown when the puller fails for any reason. | ||
@@ -1387,0 +1398,0 @@ */ |
{ | ||
"name": "replicache", | ||
"description": "Realtime sync for any backend stack", | ||
"version": "15.0.0", | ||
"version": "15.0.1", | ||
"repository": "github:rocicorp/replicache", | ||
@@ -12,18 +12,16 @@ "license": "https://roci.dev/terms.html", | ||
"check-format": "prettier --check *", | ||
"check-types": "tsc --noEmit && tsc --noEmit --project perf/tsconfig.json && tsc --noEmit --project tool/tsconfig.json", | ||
"lint": "eslint --ext .ts,.tsx,.js,.jsx src/ perf/", | ||
"check-types": "tsc --noEmit && tsc --noEmit --project tool/tsconfig.json", | ||
"lint": "eslint --ext .ts,.tsx,.js,.jsx src/", | ||
"build-dts": "rm -rf out/.dts/ && tsc --emitDeclarationOnly --outDir out/.dts/ && rollup --config rollup.config.js && rm -rf out/.dts", | ||
"build": "rm -rf out && npm run build-dts && node tool/build.js", | ||
"build-perf": "node tool/build.js --perf", | ||
"build-bundle-sizes": "rm -rf out && npm run build-dts && node tool/build.js --bundle-sizes", | ||
"prepack": "npm run lint && npm run test && npm run build && mv README.md README-org.md && mv README-external.md README.md", | ||
"postpack": "mv README.md README-external.md && mv README-org.md README.md", | ||
"prepare": "rm -f node_modules/fetch-mock/esm/client.d.ts", | ||
"perf": "npm run build-perf && node perf/runner.js" | ||
"prepare": "rm -f node_modules/fetch-mock/esm/client.d.ts" | ||
}, | ||
"dependencies": { | ||
"@badrap/valita": "^0.3.0", | ||
"@rocicorp/lock": "^1.0.3", | ||
"@rocicorp/logger": "^5.2.1", | ||
"@rocicorp/resolver": "^1.0.1" | ||
"@rocicorp/lock": "^1.0.4", | ||
"@rocicorp/logger": "^5.2.2", | ||
"@rocicorp/resolver": "^1.0.2" | ||
}, | ||
@@ -38,7 +36,6 @@ "devDependencies": { | ||
"@types/sinon": "^10.0.11", | ||
"@web/dev-server": "^0.4.0", | ||
"@web/dev-server-esbuild": "^1.0.0", | ||
"@web/test-runner": "^0.18.0", | ||
"@web/dev-server": "^0.4.4", | ||
"@web/dev-server-esbuild": "^1.0.2", | ||
"@web/test-runner": "^0.18.1", | ||
"@web/test-runner-playwright": "^0.11.0", | ||
"benchmark": "^2.1.4", | ||
"chai": "^5.0.0-alpha.2", | ||
@@ -48,14 +45,9 @@ "command-line-args": "^5.2.1", | ||
"compare-utf8": "^0.1.1", | ||
"esbuild": "^0.19.4", | ||
"esbuild": "^0.20.2", | ||
"fetch-mock": "^9.11.0", | ||
"get-port": "^7.0.0", | ||
"hash-wasm": "^4.9.0", | ||
"idb": "^7.0.1", | ||
"navigator.locks": "^0.8.5", | ||
"playwright": "^1.39.0", | ||
"playwright": "^1.43.1", | ||
"rollup": "^3.24.0", | ||
"shared": "0.0.0", | ||
"sinon": "^13.0.1", | ||
"typescript": "^5.4.2", | ||
"xbytes": "^1.7.0" | ||
"typescript": "^5.4.2" | ||
}, | ||
@@ -62,0 +54,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
324824
22
2475
3
Updated@rocicorp/lock@^1.0.4
Updated@rocicorp/logger@^5.2.2
Updated@rocicorp/resolver@^1.0.2