replicache
Advanced tools
Comparing version 9.0.0 to 10.0.0-alpha.0
@@ -0,1 +1,5 @@ | ||
import { RWLock } from '@rocicorp/lock'; | ||
import { LogLevel, LogSink } from '@rocicorp/logger'; | ||
export { LogLevel, LogSink, consoleLogSink } from '@rocicorp/logger'; | ||
/** The values that can be represented in JSON */ | ||
@@ -18,2 +22,73 @@ declare type JSONValue = null | string | boolean | number | Array<JSONValue> | JSONObject; | ||
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 [[PushRequest]]. | ||
*/ | ||
declare type Pusher = (request: Request) => Promise<HTTPRequestInfo>; | ||
/** | ||
* This error is thrown when the pusher fails for any reason. | ||
*/ | ||
declare class PushError extends Error { | ||
name: string; | ||
causedBy?: Error; | ||
constructor(causedBy?: Error); | ||
} | ||
declare type PullerResult = { | ||
response?: PullResponse; | ||
httpRequestInfo: HTTPRequestInfo; | ||
}; | ||
/** | ||
* Puller is the function type used to do the fetch part of a pull. The request | ||
* is a POST request where the body is JSON with the type [[PullRequest]]. | ||
*/ | ||
declare type Puller = (request: Request) => Promise<PullerResult>; | ||
/** | ||
* The shape of a pull response under normal circumstances. | ||
*/ | ||
declare type PullResponseOK = { | ||
cookie?: ReadonlyJSONValue; | ||
lastMutationID: number; | ||
patch: PatchOperation[]; | ||
}; | ||
/** | ||
* In certain scenarios the server can signal that it does not know about the | ||
* client. For example, the server might have deleted the client. | ||
*/ | ||
declare 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. | ||
*/ | ||
declare type PullResponse = PullResponseOK | ClientStateNotFoundResponse; | ||
/** | ||
* This type describes the patch field in a [[PullResponse]] and it is used | ||
* to describe how to update the Replicache key-value store. | ||
*/ | ||
declare type PatchOperation = { | ||
op: 'put'; | ||
key: string; | ||
value: JSONValue; | ||
} | { | ||
op: 'del'; | ||
key: string; | ||
} | { | ||
op: 'clear'; | ||
}; | ||
/** | ||
* This error is thrown when the puller fails for any reason. | ||
*/ | ||
declare class PullError extends Error { | ||
name: string; | ||
causedBy?: Error; | ||
constructor(causedBy?: Error); | ||
} | ||
declare const hashTag: unique symbol; | ||
@@ -92,5 +167,8 @@ /** | ||
interface Read$1 { | ||
interface GetChunk { | ||
getChunk(hash: Hash): Promise<Chunk | undefined>; | ||
} | ||
interface Read$1 extends GetChunk { | ||
hasChunk(hash: Hash): Promise<boolean>; | ||
getChunk(hash: Hash): Promise<Chunk | undefined>; | ||
mustGetChunk(hash: Hash): Promise<Chunk>; | ||
getHead(name: string): Promise<Hash | undefined>; | ||
@@ -119,12 +197,2 @@ close(): void; | ||
declare class RWLock { | ||
private _lock; | ||
private _writeP; | ||
private _readP; | ||
read(): Promise<() => void>; | ||
withRead<R>(f: () => R | Promise<R>): Promise<R>; | ||
write(): Promise<() => void>; | ||
withWrite<R>(f: () => R | Promise<R>): Promise<R>; | ||
} | ||
declare type ScanOptions$1 = { | ||
@@ -276,9 +344,2 @@ prefix?: string; | ||
/** | ||
* 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'; | ||
declare abstract class Index<DagReadWrite, BTree> { | ||
@@ -370,70 +431,3 @@ readonly meta: IndexRecord; | ||
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 [[PushRequest]]. | ||
*/ | ||
declare type Pusher = (request: Request) => Promise<HTTPRequestInfo>; | ||
/** | ||
* This error is thrown when the pusher fails for any reason. | ||
*/ | ||
declare class PushError extends Error { | ||
name: string; | ||
causedBy?: Error; | ||
constructor(causedBy?: Error); | ||
} | ||
declare type PullerResult = { | ||
response?: PullResponse; | ||
httpRequestInfo: HTTPRequestInfo; | ||
}; | ||
/** | ||
* Puller is the function type used to do the fetch part of a pull. The request | ||
* is a POST request where the body is JSON with the type [[PullRequest]]. | ||
*/ | ||
declare type Puller = (request: Request) => Promise<PullerResult>; | ||
/** | ||
* PullResponse defines the shape and type of the response of a pull. This is | ||
* the JSON you should return from your pull server endpoint. | ||
*/ | ||
declare type PullResponse = { | ||
cookie?: ReadonlyJSONValue; | ||
lastMutationID: number; | ||
patch: PatchOperation[]; | ||
}; | ||
/** | ||
* This type describes the patch field in a [[PullResponse]] and it is used | ||
* to describe how to update the Replicache key-value store. | ||
*/ | ||
declare type PatchOperation = { | ||
op: 'put'; | ||
key: string; | ||
value: JSONValue; | ||
} | { | ||
op: 'del'; | ||
key: string; | ||
} | { | ||
op: 'clear'; | ||
}; | ||
/** | ||
* This error is thrown when the puller fails for any reason. | ||
*/ | ||
declare class PullError extends Error { | ||
name: string; | ||
causedBy?: Error; | ||
constructor(causedBy?: Error); | ||
} | ||
declare type Args = [ | ||
options: ScanOptions | undefined, | ||
getTransaction: () => Promise<Read> | Read, | ||
shouldCloseTransaction: boolean, | ||
shouldClone: boolean, | ||
onLimitKey?: (inclusiveLimitKey: string) => void | ||
]; | ||
/** | ||
* This class is used for the results of [[ReadTransaction.scan|scan]]. It | ||
@@ -445,8 +439,10 @@ * implements `AsyncIterable<JSONValue>` which allows you to use it in a `for | ||
declare class ScanResult<K, V extends ReadonlyJSONValue = JSONValue> implements AsyncIterable<V> { | ||
private readonly _args; | ||
private readonly _options; | ||
private readonly _dbRead; | ||
private readonly _onLimitKey?; | ||
/** @internal */ | ||
constructor(...args: Args); | ||
constructor(options: ScanOptions | undefined, dbRead: Read, onLimitKey?: (inclusiveLimitKey: string) => void); | ||
/** The default AsyncIterable. This is the same as [[values]]. */ | ||
[Symbol.asyncIterator](): AsyncIterableIteratorToArrayWrapper<V>; | ||
/** Async iterator over the valus of the [[ReadTransaction.scan|scan]] call. */ | ||
/** Async iterator over the values of the [[ReadTransaction.scan|scan]] call. */ | ||
values(): AsyncIterableIteratorToArrayWrapper<V>; | ||
@@ -496,2 +492,3 @@ /** | ||
declare type PullRequest = { | ||
profileID: string; | ||
clientID: string; | ||
@@ -509,2 +506,3 @@ cookie: ReadonlyJSONValue; | ||
declare type PushRequest = { | ||
profileID: string; | ||
clientID: string; | ||
@@ -685,5 +683,21 @@ mutations: Mutation[]; | ||
* `'error'` we only log `'error'` messages. | ||
* Default is `'info'`. | ||
*/ | ||
logLevel?: LogLevel; | ||
/** | ||
* 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 [[LogSink]]s. Logs at or above | ||
* [[ReplicacheOptions.logLevel]] are sent to each of these [[LogSink]]s. | ||
* If you would still like logs to go to the console, include | ||
* [[consoleLogSink]] in the array. | ||
* | ||
* ```ts | ||
* logSinks: [consoleLogSink, myCloudLogSink], | ||
* ``` | ||
*/ | ||
logSinks?: LogSink[]; | ||
/** | ||
* An object used as a map to define the *mutators*. These gets registered at | ||
@@ -778,11 +792,14 @@ * startup of [[Replicache]]. | ||
/** | ||
* Allows implementing the underlying storage layer completely in JavaScript. | ||
* The license key for Replicache. This parameter is required for Replicache to | ||
* function. See https://replicache.dev for how to acquire a license key. | ||
* | ||
* @experimental This option is experimental and might be removed or changed | ||
* in the future without following semver versioning. Please be cautious. | ||
* 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. | ||
*/ | ||
experimentalKVStore?: Store; | ||
licenseKey: string; | ||
/** | ||
* When defined, activates Replicache's experimental license key support. You | ||
* don't want to use this option unless you are a Replicache developer. | ||
* Allows implementing the underlying storage layer completely in JavaScript. | ||
* | ||
@@ -792,3 +809,3 @@ * @experimental This option is experimental and might be removed or changed | ||
*/ | ||
experimentalLicenseKey?: string; | ||
experimentalKVStore?: Store; | ||
} | ||
@@ -854,2 +871,9 @@ | ||
/** | ||
* 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; | ||
/** | ||
* The type used to describe the mutator definitions passed into [Replicache](classes/Replicache) | ||
@@ -874,3 +898,3 @@ * constructor as part of the [[ReplicacheOptions]]. | ||
/** | ||
* When there are pending pull or push requests this is the _minimum_ ammount | ||
* When there are pending pull or push requests this is the _minimum_ amount | ||
* of time to wait until we try another pull/push. | ||
@@ -880,3 +904,3 @@ */ | ||
/** | ||
* When there are pending pull or push requests this is the _maximum_ ammount | ||
* When there are pending pull or push requests this is the _maximum_ amount | ||
* of time to wait until we try another pull/push. | ||
@@ -886,2 +910,10 @@ */ | ||
} | ||
/** | ||
* The reason [[onClientStateNotFound]] was called. | ||
*/ | ||
declare type ClientStateNotFoundReason = { | ||
type: 'NotFoundOnServer'; | ||
} | { | ||
type: 'NotFoundOnClient'; | ||
}; | ||
declare class Replicache<MD extends MutatorDefs = {}> { | ||
@@ -906,5 +938,8 @@ /** The URL to use when doing a pull request. */ | ||
private _online; | ||
private readonly _logger; | ||
private readonly _ready; | ||
private readonly _profileIDPromise; | ||
private readonly _clientIDPromise; | ||
protected readonly _licenseCheckPromise: Promise<boolean>; | ||
protected _licenseActivePromise: Promise<boolean>; | ||
private _stopLicenseActive; | ||
private _root; | ||
@@ -954,2 +989,4 @@ private readonly _mutatorRegistry; | ||
private _recoveringMutations; | ||
private readonly _disableLicensing; | ||
private readonly _disableMutationRecovery; | ||
/** | ||
@@ -976,2 +1013,14 @@ * The options used to control the [[pull]] and push request behavior. This | ||
/** | ||
* `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. | ||
* | ||
* 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 | ||
* this to `null` or provide your own function to prevent the page from | ||
* reloading automatically. | ||
*/ | ||
onClientStateNotFound: ((reason: ClientStateNotFoundReason) => void) | null; | ||
/** | ||
* This gets called when we get an HTTP unauthorized (401) response from the | ||
@@ -985,3 +1034,13 @@ * push or pull endpoint. Set this to a function that will ask your user to | ||
private _open; | ||
private _onVisibilityChange; | ||
private _checkForClientStateNotFoundAndCallHandler; | ||
private _licenseCheck; | ||
private _licenseInvalid; | ||
private _startLicenseActive; | ||
/** | ||
* The browser profile ID for this browser profile. Every instance of Replicache | ||
* browser-profile-wide shares the same profile ID. | ||
*/ | ||
get profileID(): Promise<string>; | ||
/** | ||
* The client ID for this instance of Replicache. Each instance of Replicache | ||
@@ -1019,28 +1078,2 @@ * gets a unique client ID. | ||
/** | ||
* Get a single value from the database. | ||
* @deprecated Use [[query]] instead. | ||
*/ | ||
get(key: string): Promise<ReadonlyJSONValue | undefined>; | ||
/** | ||
* Determines if a single `key` is present in the database. | ||
* @deprecated Use [[query]] instead. | ||
*/ | ||
has(key: string): Promise<boolean>; | ||
/** | ||
* Whether the database is empty. | ||
* @deprecated Use [[query]] instead. | ||
*/ | ||
isEmpty(): Promise<boolean>; | ||
/** | ||
* Gets many values from the database. This returns a `ScanResult` which | ||
* implements `AsyncIterable`. It also has methods to iterate over the `keys` | ||
* and `entries`. | ||
* | ||
* If `options` has an `indexName`, then this does a scan over an index with | ||
* that name. A scan over an index uses a tuple for the key consisting of | ||
* `[secondary: string, primary: string]`. | ||
* @deprecated Use [[query]] instead. | ||
*/ | ||
scan<Options extends ScanOptions, Key extends KeyTypeForScanOptions<Options>>(options?: Options): ScanResult<Key, ReadonlyJSONValue>; | ||
/** | ||
* Creates a persistent secondary index in Replicache which can be used with scan. | ||
@@ -1061,4 +1094,6 @@ * | ||
private _invokePull; | ||
private _isPullDisabled; | ||
private _wrapInOnlineCheck; | ||
private _wrapInReauthRetries; | ||
private _isPushDisabled; | ||
protected _invokePush(): Promise<boolean>; | ||
@@ -1090,2 +1125,3 @@ /** | ||
protected _persist(): Promise<void>; | ||
private _fireOnClientStateNotFound; | ||
private _schedulePersist; | ||
@@ -1123,2 +1159,7 @@ private _changeSyncCounters; | ||
private _mutate; | ||
/** | ||
* In the case we get a ChunkNotFoundError we check if the client got garbage | ||
* collected and if so change the error to a ClientNotFoundError instead | ||
*/ | ||
private _convertToClientStateNotFoundError; | ||
protected _recoverMutations(preReadClientMap?: ClientMap): Promise<boolean>; | ||
@@ -1143,2 +1184,2 @@ private _recoverMutationsFromPerdag; | ||
export { AsyncIterableIteratorToArrayWrapper, CreateIndexDefinition, Read$2 as ExperimentalKVRead, Store as ExperimentalKVStore, Write$1 as ExperimentalKVWrite, HTTPRequestInfo, JSONObject, JSONValue, KeyTypeForScanOptions, LogLevel, MaybePromise, MutatorDefs, PatchOperation, Poke, PullError, PullRequest, PullResponse, Puller, PullerResult, PushError, PushRequest, Pusher, ReadTransaction, ReadonlyJSONObject, ReadonlyJSONValue, Replicache, ReplicacheOptions, RequestOptions, ScanIndexOptions, ScanNoIndexOptions, ScanOptionIndexedStartKey, ScanOptions, ScanResult, TransactionClosedError, WriteTransaction }; | ||
export { AsyncIterableIteratorToArrayWrapper, ClientStateNotFoundReason, ClientStateNotFoundResponse, CreateIndexDefinition, Read$2 as ExperimentalKVRead, Store as ExperimentalKVStore, Write$1 as ExperimentalKVWrite, HTTPRequestInfo, JSONObject, JSONValue, KeyTypeForScanOptions, MaybePromise, MutatorDefs, PatchOperation, Poke, PullError, PullRequest, PullResponse, PullResponseOK, Puller, PullerResult, PushError, PushRequest, Pusher, ReadTransaction, ReadonlyJSONObject, ReadonlyJSONValue, Replicache, ReplicacheOptions, RequestOptions, ScanIndexOptions, ScanNoIndexOptions, ScanOptionIndexedStartKey, ScanOptions, ScanResult, TransactionClosedError, WriteTransaction, makeIDBName }; |
{ | ||
"name": "replicache", | ||
"description": "Realtime sync for any backend stack", | ||
"version": "9.0.0", | ||
"version": "10.0.0-alpha.0", | ||
"repository": "github:rocicorp/replicache", | ||
@@ -13,3 +13,3 @@ "license": "BSL-1.1", | ||
"lint": "eslint --ext .ts,.tsx,.js,.jsx src/ perf/", | ||
"build-get-license": "esbuild --bundle --target=es2018 --external:'node:*' --outfile=out/get-license.mjs --format=esm tool/get-license.ts", | ||
"build-cli": "esbuild --bundle --platform=node --target=es2018 --external:'node:*' --outfile=out/cli.cjs --format=cjs tool/cli.ts", | ||
"build-dts": "rm -rf out/.dts/ && tsc --emitDeclarationOnly --outDir out/.dts/ && rollup --config rollup.config.js && rm -rf out/.dts", | ||
@@ -19,3 +19,3 @@ "build-mjs": "esbuild --bundle --target=es2018 --outfile=out/replicache.mjs --format=esm src/mod.ts", | ||
"build-min-mjs": "esbuild --bundle --target=es2018 --outfile=out/replicache.min.mjs --format=esm src/mod.ts --minify --mangle-props=^_", | ||
"build": "rm -rf out && npm run build-dts && npm run build-mjs && npm run build-cjs && npm run build-min-mjs && npm run build-get-license", | ||
"build": "rm -rf out && npm run build-dts && npm run build-mjs && npm run build-cjs && npm run build-min-mjs && npm run build-cli", | ||
"prepack": "npm run lint && npm run test && npm run build", | ||
@@ -27,3 +27,6 @@ "prepare": "rm -f node_modules/fetch-mock/esm/client.d.ts", | ||
"@esm-bundle/chai": "^4.3.4", | ||
"@rocicorp/licensing": "^1.0.0", | ||
"@rocicorp/licensing": "^4.0.0-beta.3", | ||
"@rocicorp/lock": "^1.0.1", | ||
"@rocicorp/logger": "^2.2.0", | ||
"@rocicorp/resolver": "^1.0.0", | ||
"@types/lodash-es": "^4.17.5", | ||
@@ -61,3 +64,3 @@ "@types/mocha": "^9.0.0", | ||
"bin": { | ||
"get-license": "./out/get-license.mjs" | ||
"replicache": "./out/cli.cjs" | ||
}, | ||
@@ -70,3 +73,3 @@ "exports": { | ||
"files": [ | ||
"out/get-license.mjs", | ||
"out/cli.mjs", | ||
"out/replicache.d.ts", | ||
@@ -77,6 +80,3 @@ "out/replicache.js", | ||
"out/replicache.dev.wasm" | ||
], | ||
"dependencies": { | ||
"node-fetch": "^3.0.0" | ||
} | ||
] | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
769121
0
22545
2
32
2
7
- Removednode-fetch@^3.0.0
- Removeddata-uri-to-buffer@4.0.1(transitive)
- Removedfetch-blob@3.2.0(transitive)
- Removedformdata-polyfill@4.0.10(transitive)
- Removednode-domexception@1.0.0(transitive)
- Removednode-fetch@3.3.2(transitive)
- Removedweb-streams-polyfill@3.3.3(transitive)