ahmed-rivet-convex 2.2.5 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-MLCRKRW5.js → chunk-5AEROL6U.js} +681 -153
- package/dist/{chunk-SIMXYEFB.js → chunk-FVFX5V7B.js} +143 -43
- package/dist/{lazy-inspector-V7RUTGPZ.js → lazy-inspector-HSAL7IXV.js} +1 -1
- package/dist/react.js +2 -2
- package/dist/replicache/src/bg-interval.d.ts +7 -1
- package/dist/replicache/src/btree/write.d.ts +14 -0
- package/dist/replicache/src/kv/idb-store.d.ts +8 -0
- package/dist/replicache/src/new-client-channel.d.ts +9 -1
- package/dist/replicache/src/persist/heartbeat.d.ts +7 -1
- package/dist/replicache/src/persist/persist.d.ts +17 -0
- package/dist/replicache/src/replicache-impl.d.ts +73 -5
- package/dist/replicache/src/replicache-options.d.ts +4 -1
- package/dist/zero-client/src/client/options.d.ts +5 -1
- package/dist/zero-client/src/client/zero-rep.d.ts +6 -0
- package/dist/zero-client/src/client/zero.d.ts +13 -1
- package/dist/zero.js +2 -2
- package/package.json +1 -1
|
@@ -852,6 +852,10 @@ var DataNodeImpl = class extends NodeImpl {
|
|
|
852
852
|
if (!binarySearchFound(i, this.entries, key)) {
|
|
853
853
|
deleteCount = 0;
|
|
854
854
|
} else {
|
|
855
|
+
if (deepEqual(this.entries[i][1], value)) {
|
|
856
|
+
tree.putWasNoop = true;
|
|
857
|
+
return Promise.resolve(this);
|
|
858
|
+
}
|
|
855
859
|
deleteCount = 1;
|
|
856
860
|
}
|
|
857
861
|
return Promise.resolve(
|
|
@@ -909,6 +913,9 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
|
|
|
909
913
|
const childHash = this.entries[i][1];
|
|
910
914
|
const oldChildNode = await tree.getNode(childHash);
|
|
911
915
|
const childNode = await oldChildNode.set(key, value, entrySize, tree);
|
|
916
|
+
if (tree.putWasNoop) {
|
|
917
|
+
return this;
|
|
918
|
+
}
|
|
912
919
|
const childNodeSize = childNode.getChildNodeSize(tree);
|
|
913
920
|
if (childNodeSize > tree.maxSize || childNodeSize < tree.minSize) {
|
|
914
921
|
return this.#mergeAndPartition(tree, i, childNode);
|
|
@@ -1005,9 +1012,6 @@ var InternalNodeImpl = class _InternalNodeImpl extends NodeImpl {
|
|
|
1005
1012
|
const entries = readonlySplice(this.entries, i, 1);
|
|
1006
1013
|
return tree.newInternalNodeImpl(entries, this.level);
|
|
1007
1014
|
}
|
|
1008
|
-
if (i === 0 && this.entries.length === 1) {
|
|
1009
|
-
return childNode;
|
|
1010
|
-
}
|
|
1011
1015
|
if (childNode.getChildNodeSize(tree) > tree.minSize) {
|
|
1012
1016
|
const entry = createNewInternalEntryForNode(childNode, tree.getEntrySize);
|
|
1013
1017
|
return this.#replaceChild(tree, i, entry);
|
|
@@ -2361,6 +2365,8 @@ function diff(oldMap, newMap) {
|
|
|
2361
2365
|
|
|
2362
2366
|
// ../replicache/src/btree/write.ts
|
|
2363
2367
|
import { Lock } from "@rocicorp/lock";
|
|
2368
|
+
import { compareUTF8 as compareUTF82 } from "compare-utf8";
|
|
2369
|
+
var REBUILD_MIN_CHANGE_RATIO = 4;
|
|
2364
2370
|
var BTreeWrite = class extends BTreeRead {
|
|
2365
2371
|
/**
|
|
2366
2372
|
* This rw lock is used to ensure we do not mutate the btree in parallel. It
|
|
@@ -2413,45 +2419,140 @@ var BTreeWrite = class extends BTreeRead {
|
|
|
2413
2419
|
this.#addToModified(n);
|
|
2414
2420
|
return n;
|
|
2415
2421
|
}
|
|
2422
|
+
/**
|
|
2423
|
+
* Set by the leaf when the put being applied stores a value equal to the
|
|
2424
|
+
* existing one; the nodes on the path then return themselves unchanged.
|
|
2425
|
+
*/
|
|
2426
|
+
putWasNoop = false;
|
|
2416
2427
|
put(key, value) {
|
|
2428
|
+
return this.#lock.withLock(() => this.#put(key, value));
|
|
2429
|
+
}
|
|
2430
|
+
async #put(key, value) {
|
|
2431
|
+
const oldRootNode = await this.getNode(this.rootHash);
|
|
2432
|
+
const entrySize = this.getEntrySize(key, value);
|
|
2433
|
+
this.putWasNoop = false;
|
|
2434
|
+
const rootNode = await oldRootNode.set(key, value, entrySize, this);
|
|
2435
|
+
if (this.putWasNoop) {
|
|
2436
|
+
return;
|
|
2437
|
+
}
|
|
2438
|
+
if (rootNode.getChildNodeSize(this) > this.maxSize) {
|
|
2439
|
+
const headerSize = this.chunkHeaderSize;
|
|
2440
|
+
const partitions = partition(
|
|
2441
|
+
rootNode.entries,
|
|
2442
|
+
(value2) => value2[2],
|
|
2443
|
+
this.minSize - headerSize,
|
|
2444
|
+
this.maxSize - headerSize
|
|
2445
|
+
);
|
|
2446
|
+
const { level } = rootNode;
|
|
2447
|
+
const entries = partitions.map((entries2) => {
|
|
2448
|
+
const node = this.newNodeImpl(entries2, level);
|
|
2449
|
+
return createNewInternalEntryForNode(node, this.getEntrySize);
|
|
2450
|
+
});
|
|
2451
|
+
const newRoot = this.newInternalNodeImpl(entries, level + 1);
|
|
2452
|
+
this.rootHash = newRoot.hash;
|
|
2453
|
+
return;
|
|
2454
|
+
}
|
|
2455
|
+
this.rootHash = rootNode.hash;
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Applies `changes` (strictly ascending by key; `undefined` deletes) by
|
|
2459
|
+
* merging them with the existing entries and building the tree bottom-up
|
|
2460
|
+
* in one pass — no per-entry lock, descent, path copy or fresh hash. For
|
|
2461
|
+
* large patches (a first hydrate, a bulk change) this replaces N
|
|
2462
|
+
* sequential puts. Returns false, having changed nothing, when the tree
|
|
2463
|
+
* holds more than `maxExisting` entries: then sequential puts touch less.
|
|
2464
|
+
*/
|
|
2465
|
+
putSorted(changes, maxExisting) {
|
|
2417
2466
|
return this.#lock.withLock(async () => {
|
|
2418
|
-
const
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2467
|
+
const existing = [];
|
|
2468
|
+
if (!await this.#collectEntries(this.rootHash, existing, maxExisting)) {
|
|
2469
|
+
return false;
|
|
2470
|
+
}
|
|
2471
|
+
const entries = [];
|
|
2472
|
+
const effective = [];
|
|
2473
|
+
let i = 0;
|
|
2474
|
+
for (const change of changes) {
|
|
2475
|
+
const [key, value] = change;
|
|
2476
|
+
while (i < existing.length && compareUTF82(existing[i][0], key) < 0) {
|
|
2477
|
+
entries.push(existing[i++]);
|
|
2478
|
+
}
|
|
2479
|
+
const old = i < existing.length && existing[i][0] === key ? existing[i++] : void 0;
|
|
2480
|
+
if (value === void 0) {
|
|
2481
|
+
if (old) effective.push(change);
|
|
2482
|
+
} else if (old && deepEqual(old[1], value)) {
|
|
2483
|
+
entries.push(old);
|
|
2484
|
+
} else {
|
|
2485
|
+
entries.push([key, value, this.getEntrySize(key, value)]);
|
|
2486
|
+
effective.push(change);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
while (i < existing.length) entries.push(existing[i++]);
|
|
2490
|
+
if (effective.length === 0) {
|
|
2491
|
+
return true;
|
|
2492
|
+
}
|
|
2493
|
+
if (effective.length * REBUILD_MIN_CHANGE_RATIO < existing.length) {
|
|
2494
|
+
for (const [key, value] of effective) {
|
|
2495
|
+
if (value === void 0) await this.#del(key);
|
|
2496
|
+
else await this.#put(key, value);
|
|
2497
|
+
}
|
|
2498
|
+
return true;
|
|
2499
|
+
}
|
|
2500
|
+
if (entries.length === 0) {
|
|
2501
|
+
this.rootHash = emptyHash;
|
|
2502
|
+
return true;
|
|
2503
|
+
}
|
|
2504
|
+
const min = this.minSize - this.chunkHeaderSize;
|
|
2505
|
+
const max = this.maxSize - this.chunkHeaderSize;
|
|
2506
|
+
let level = 0;
|
|
2507
|
+
let nodes = partition(
|
|
2508
|
+
entries,
|
|
2509
|
+
(e) => e[2],
|
|
2510
|
+
min,
|
|
2511
|
+
max
|
|
2512
|
+
).map((p) => this.newDataNodeImpl(p));
|
|
2513
|
+
while (nodes.length > 1) {
|
|
2514
|
+
const parents = nodes.map(
|
|
2515
|
+
(n) => createNewInternalEntryForNode(n, this.getEntrySize)
|
|
2428
2516
|
);
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
this.rootHash = newRoot.hash;
|
|
2436
|
-
return;
|
|
2517
|
+
let partitions = partition(parents, (e) => e[2], min, max);
|
|
2518
|
+
if (partitions.length >= nodes.length) {
|
|
2519
|
+
partitions = [parents];
|
|
2520
|
+
}
|
|
2521
|
+
level++;
|
|
2522
|
+
nodes = partitions.map((p) => this.newInternalNodeImpl(p, level));
|
|
2437
2523
|
}
|
|
2438
|
-
this.rootHash =
|
|
2524
|
+
this.rootHash = nodes[0].hash;
|
|
2525
|
+
return true;
|
|
2439
2526
|
});
|
|
2440
2527
|
}
|
|
2528
|
+
/** In-order leaf entries under `hash`; false once more than `max`. */
|
|
2529
|
+
async #collectEntries(hash2, out, max) {
|
|
2530
|
+
if (hash2 === emptyHash) return true;
|
|
2531
|
+
const node = await this.getNode(hash2);
|
|
2532
|
+
if (isDataNodeImpl(node)) {
|
|
2533
|
+
for (const e of node.entries) out.push(e);
|
|
2534
|
+
return out.length <= max;
|
|
2535
|
+
}
|
|
2536
|
+
for (const [, child] of node.entries) {
|
|
2537
|
+
if (!await this.#collectEntries(child, out, max)) return false;
|
|
2538
|
+
}
|
|
2539
|
+
return true;
|
|
2540
|
+
}
|
|
2441
2541
|
del(key) {
|
|
2442
|
-
return this.#lock.withLock(
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2542
|
+
return this.#lock.withLock(() => this.#del(key));
|
|
2543
|
+
}
|
|
2544
|
+
async #del(key) {
|
|
2545
|
+
const oldRootNode = await this.getNode(this.rootHash);
|
|
2546
|
+
const newRootNode = await oldRootNode.del(key, this);
|
|
2547
|
+
const found = this.rootHash !== newRootNode.hash;
|
|
2548
|
+
if (found) {
|
|
2549
|
+
let root = newRootNode;
|
|
2550
|
+
while (root.level > 0 && root.entries.length === 1) {
|
|
2551
|
+
root = await this.getNode(root.entries[0][1]);
|
|
2452
2552
|
}
|
|
2453
|
-
|
|
2454
|
-
}
|
|
2553
|
+
this.rootHash = root.hash;
|
|
2554
|
+
}
|
|
2555
|
+
return found;
|
|
2455
2556
|
}
|
|
2456
2557
|
clear() {
|
|
2457
2558
|
return this.#lock.withLock(() => {
|
|
@@ -3265,7 +3366,7 @@ var analyzeQueryResultSchema = valita_exports.object({
|
|
|
3265
3366
|
});
|
|
3266
3367
|
|
|
3267
3368
|
// ../zero-protocol/src/ast.ts
|
|
3268
|
-
import { compareUTF8 as
|
|
3369
|
+
import { compareUTF8 as compareUTF83 } from "compare-utf8";
|
|
3269
3370
|
|
|
3270
3371
|
// ../shared/src/arrays.ts
|
|
3271
3372
|
function defined(arr) {
|
|
@@ -3542,15 +3643,15 @@ function cmpCondition(a, b) {
|
|
|
3542
3643
|
}
|
|
3543
3644
|
function compareValuePosition(a, b) {
|
|
3544
3645
|
if (a.type !== b.type) {
|
|
3545
|
-
return
|
|
3646
|
+
return compareUTF83(a.type, b.type);
|
|
3546
3647
|
}
|
|
3547
3648
|
switch (a.type) {
|
|
3548
3649
|
case "literal":
|
|
3549
3650
|
assert2(b.type === "literal");
|
|
3550
|
-
return
|
|
3651
|
+
return compareUTF83(String(a.value), String(b.value));
|
|
3551
3652
|
case "column":
|
|
3552
3653
|
assert2(b.type === "column");
|
|
3553
|
-
return
|
|
3654
|
+
return compareUTF83(a.name, b.name);
|
|
3554
3655
|
case "static":
|
|
3555
3656
|
throw new Error(
|
|
3556
3657
|
"Static parameters should be resolved before normalization"
|
|
@@ -3558,7 +3659,7 @@ function compareValuePosition(a, b) {
|
|
|
3558
3659
|
}
|
|
3559
3660
|
}
|
|
3560
3661
|
function cmpRelated(a, b) {
|
|
3561
|
-
return
|
|
3662
|
+
return compareUTF83(must(a.subquery.alias), must(b.subquery.alias));
|
|
3562
3663
|
}
|
|
3563
3664
|
function flattened(cond) {
|
|
3564
3665
|
if (cond.type === "simple" || cond.type === "correlatedSubquery") {
|
|
@@ -3583,7 +3684,7 @@ function flattened(cond) {
|
|
|
3583
3684
|
}
|
|
3584
3685
|
function compareUTF8MaybeNull(a, b) {
|
|
3585
3686
|
if (a !== null && b !== null) {
|
|
3586
|
-
return
|
|
3687
|
+
return compareUTF83(a, b);
|
|
3587
3688
|
}
|
|
3588
3689
|
if (b !== null) {
|
|
3589
3690
|
return -1;
|
|
@@ -4197,7 +4298,7 @@ function isTwoHop(r) {
|
|
|
4197
4298
|
}
|
|
4198
4299
|
|
|
4199
4300
|
// ../zql/src/ivm/data.ts
|
|
4200
|
-
import { compareUTF8 as
|
|
4301
|
+
import { compareUTF8 as compareUTF84 } from "compare-utf8";
|
|
4201
4302
|
function compareValues(a, b) {
|
|
4202
4303
|
a = normalizeUndefined(a);
|
|
4203
4304
|
b = normalizeUndefined(b);
|
|
@@ -4220,7 +4321,7 @@ function compareValues(a, b) {
|
|
|
4220
4321
|
}
|
|
4221
4322
|
if (typeof a === "string") {
|
|
4222
4323
|
assertString(b);
|
|
4223
|
-
return
|
|
4324
|
+
return compareUTF84(a, b);
|
|
4224
4325
|
}
|
|
4225
4326
|
throw new Error(`Unsupported type: ${a}`);
|
|
4226
4327
|
}
|
|
@@ -8643,7 +8744,6 @@ export {
|
|
|
8643
8744
|
withRead,
|
|
8644
8745
|
withWriteNoImplicitCommit,
|
|
8645
8746
|
withWrite,
|
|
8646
|
-
using,
|
|
8647
8747
|
getClientGroups,
|
|
8648
8748
|
setClientGroups,
|
|
8649
8749
|
setClientGroup,
|
package/dist/react.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Zero
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5AEROL6U.js";
|
|
4
4
|
import {
|
|
5
5
|
DEFAULT_TTL_MS
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FVFX5V7B.js";
|
|
7
7
|
|
|
8
8
|
// ../zero-react/src/use-query.tsx
|
|
9
9
|
import React, { useSyncExternalStore } from "react";
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { LogContext } from '@rocicorp/logger';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Runs `process` every `delayMs()` until `signal` aborts. A failed run is
|
|
4
|
+
* logged as an error and the next one runs as usual — unless `stopOn(e)`
|
|
5
|
+
* says the failure is permanent for this process (e.g. its database is
|
|
6
|
+
* gone), in which case the process stops quietly (debug log).
|
|
7
|
+
*/
|
|
8
|
+
export declare function initBgIntervalProcess(processName: string, process: () => Promise<unknown>, delayMs: () => number, lc: LogContext, signal: AbortSignal, stopOn?: (e: unknown) => boolean): void;
|
|
3
9
|
//# sourceMappingURL=bg-interval.d.ts.map
|
|
@@ -18,7 +18,21 @@ export declare class BTreeWrite extends BTreeRead {
|
|
|
18
18
|
newNodeImpl(entries: Entry<FrozenJSONValue>[], level: number): DataNodeImpl;
|
|
19
19
|
newNodeImpl(entries: Entry<Hash>[], level: number): InternalNodeImpl;
|
|
20
20
|
newNodeImpl(entries: Entry<Hash>[] | Entry<FrozenJSONValue>[], level: number): InternalNodeImpl | DataNodeImpl;
|
|
21
|
+
/**
|
|
22
|
+
* Set by the leaf when the put being applied stores a value equal to the
|
|
23
|
+
* existing one; the nodes on the path then return themselves unchanged.
|
|
24
|
+
*/
|
|
25
|
+
putWasNoop: boolean;
|
|
21
26
|
put(key: string, value: FrozenJSONValue): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Applies `changes` (strictly ascending by key; `undefined` deletes) by
|
|
29
|
+
* merging them with the existing entries and building the tree bottom-up
|
|
30
|
+
* in one pass — no per-entry lock, descent, path copy or fresh hash. For
|
|
31
|
+
* large patches (a first hydrate, a bulk change) this replaces N
|
|
32
|
+
* sequential puts. Returns false, having changed nothing, when the tree
|
|
33
|
+
* holds more than `maxExisting` entries: then sequential puts touch less.
|
|
34
|
+
*/
|
|
35
|
+
putSorted(changes: readonly (readonly [string, FrozenJSONValue | undefined])[], maxExisting: number): Promise<boolean>;
|
|
22
36
|
del(key: string): Promise<boolean>;
|
|
23
37
|
clear(): Promise<void>;
|
|
24
38
|
flush(): Promise<Hash>;
|
|
@@ -7,6 +7,13 @@ export declare class IDBStore implements Store {
|
|
|
7
7
|
close(): Promise<void>;
|
|
8
8
|
get closed(): boolean;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Resolves at once unless the page is frozen (a `freeze` event this store
|
|
12
|
+
* saw, with no `resume` since); then when it resumes. Work IndexedDB
|
|
13
|
+
* aborted because of a freeze waits on this before trying again, so it
|
|
14
|
+
* does not run inside the frozen window.
|
|
15
|
+
*/
|
|
16
|
+
export declare function whenPageResumed(): Promise<void>;
|
|
10
17
|
/**
|
|
11
18
|
* This error is thrown when we detect that the IndexedDB has been removed. This
|
|
12
19
|
* does not normally happen but can happen during development if the user has
|
|
@@ -15,4 +22,5 @@ export declare class IDBStore implements Store {
|
|
|
15
22
|
export declare class IDBNotFoundError extends Error {
|
|
16
23
|
name: string;
|
|
17
24
|
}
|
|
25
|
+
export declare function isIDBNotFoundError(e: unknown): e is IDBNotFoundError;
|
|
18
26
|
//# sourceMappingURL=idb-store.d.ts.map
|
|
@@ -2,5 +2,13 @@ import type { Store } from './dag/store.ts';
|
|
|
2
2
|
declare function makeChannelNameV0(replicacheName: string): string;
|
|
3
3
|
declare function makeChannelNameV1(replicacheName: string): string;
|
|
4
4
|
export { makeChannelNameV0 as makeChannelNameV0ForTesting, makeChannelNameV1 as makeChannelNameV1ForTesting, };
|
|
5
|
-
export declare function initNewClientChannel(replicacheName: string, idbName: string, signal: AbortSignal, clientGroupID: string, isNewClientGroup: boolean, onUpdateNeeded: () => void, perdag: Store
|
|
5
|
+
export declare function initNewClientChannel(replicacheName: string, idbName: string, signal: AbortSignal, clientGroupID: string, isNewClientGroup: boolean, onUpdateNeeded: () => void, perdag: Store,
|
|
6
|
+
/**
|
|
7
|
+
* Called with anything a message handler throws (reading the perdag can
|
|
8
|
+
* fail, e.g. with IDBNotFoundError once the database is gone). The
|
|
9
|
+
* handler is an event listener: without this, the failure would be an
|
|
10
|
+
* unhandled rejection. Without an `onError` the failure is rethrown, as
|
|
11
|
+
* before.
|
|
12
|
+
*/
|
|
13
|
+
onError?: (e: unknown) => void): void;
|
|
6
14
|
//# sourceMappingURL=new-client-channel.d.ts.map
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { LogContext } from '@rocicorp/logger';
|
|
2
2
|
import type { Store } from '../dag/store.ts';
|
|
3
|
+
import { IDBNotFoundError } from '../kv/idb-store.ts';
|
|
3
4
|
import type { ClientID } from '../sync/ids.ts';
|
|
4
5
|
import { type ClientMap } from './clients.ts';
|
|
5
6
|
export declare const HEARTBEAT_INTERVAL: number;
|
|
6
7
|
export declare let latestHeartbeatUpdate: Promise<ClientMap> | undefined;
|
|
7
|
-
export declare function startHeartbeats(clientID: ClientID, dagStore: Store,
|
|
8
|
+
export declare function startHeartbeats(clientID: ClientID, dagStore: Store,
|
|
9
|
+
/**
|
|
10
|
+
* Called with no argument when this client's entry is gone, and with the
|
|
11
|
+
* error when the whole database is gone (this client's state with it).
|
|
12
|
+
*/
|
|
13
|
+
onClientStateNotFound: (cause?: IDBNotFoundError) => void, heartbeatIntervalMs: number, lc: LogContext, signal: AbortSignal): void;
|
|
8
14
|
export declare function writeHeartbeat(clientID: ClientID, dagStore: Store): Promise<ClientMap>;
|
|
9
15
|
//# sourceMappingURL=heartbeat.d.ts.map
|
|
@@ -3,10 +3,27 @@ import type { Enum } from '../../../shared/src/enum.ts';
|
|
|
3
3
|
import type { LazyStore } from '../dag/lazy-store.ts';
|
|
4
4
|
import type { Store } from '../dag/store.ts';
|
|
5
5
|
import * as FormatVersion from '../format-version-enum.ts';
|
|
6
|
+
import type { Hash } from '../hash.ts';
|
|
6
7
|
import type { ClientID } from '../sync/ids.ts';
|
|
7
8
|
import type { MutatorDefs } from '../types.ts';
|
|
8
9
|
import type { ZeroOption } from '../replicache-options.ts';
|
|
9
10
|
type FormatVersion = Enum<typeof FormatVersion>;
|
|
11
|
+
/**
|
|
12
|
+
* The perdag main client group's head moved between persist's first READ and
|
|
13
|
+
* its WRITE transaction (another tab persisted in between), so the IVM tx data
|
|
14
|
+
* computed for the head seen at read time does not describe the head the write
|
|
15
|
+
* would rebase onto. Nothing has been written when this is thrown; the caller
|
|
16
|
+
* reschedules persist, and the next attempt reads the new head.
|
|
17
|
+
*
|
|
18
|
+
* Why this exists instead of computing the data inside the write: see the
|
|
19
|
+
* comment on `zeroDataForPerdagHeadAtRead` in `persistDD31`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class PersistBaseMovedError extends Error {
|
|
22
|
+
readonly expected: Hash;
|
|
23
|
+
readonly actual: Hash;
|
|
24
|
+
readonly name = "PersistBaseMovedError";
|
|
25
|
+
constructor(expected: Hash, actual: Hash);
|
|
26
|
+
}
|
|
10
27
|
/**
|
|
11
28
|
* Persists the client's memdag state to the client's perdag client group.
|
|
12
29
|
*
|
|
@@ -3,6 +3,7 @@ import type { MaybePromise } from '../../shared/src/types.ts';
|
|
|
3
3
|
import { type Cookie } from './cookies.ts';
|
|
4
4
|
import { LazyStore } from './dag/lazy-store.ts';
|
|
5
5
|
import { type Store } from './dag/store.ts';
|
|
6
|
+
import { type FrozenJSONValue } from './frozen-json.ts';
|
|
6
7
|
import { type Hash } from './hash.ts';
|
|
7
8
|
import { type PendingMutation } from './pending-mutations.ts';
|
|
8
9
|
import { type OnClientsDeleted } from './persist/clients.ts';
|
|
@@ -131,9 +132,16 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
131
132
|
*
|
|
132
133
|
* The default behavior is to reload the page (using `location.reload()`). Set
|
|
133
134
|
* this to `null` or provide your own function to prevent the page from
|
|
134
|
-
* reloading automatically.
|
|
135
|
+
* reloading automatically. The default reloads at most once per 10 seconds
|
|
136
|
+
* for a given database (tracked in `sessionStorage`): a reload that lands
|
|
137
|
+
* straight back here warns once and the page keeps running in memory
|
|
138
|
+
* instead of looping.
|
|
139
|
+
*
|
|
140
|
+
* `reason` is `'idb-deleted'` when this instance's IndexedDB database was
|
|
141
|
+
* deleted under it (another tab's collector dropped it, or site data was
|
|
142
|
+
* cleared); it is `undefined` for the other causes.
|
|
135
143
|
*/
|
|
136
|
-
onClientStateNotFound: (() => void) | null;
|
|
144
|
+
onClientStateNotFound: ((reason?: string) => void) | null;
|
|
137
145
|
/**
|
|
138
146
|
* `onUpdateNeeded` is called when a code update is needed.
|
|
139
147
|
*
|
|
@@ -164,6 +172,12 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
164
172
|
onBeginPull: () => undefined;
|
|
165
173
|
onRecoverMutations: (r: Promise<boolean>) => Promise<boolean>;
|
|
166
174
|
constructor(options: ReplicacheOptions<MD>, implOptions?: ReplicacheImplOptions);
|
|
175
|
+
/**
|
|
176
|
+
* `#ready` itself: resolves when open has completed (after Zero's `init`,
|
|
177
|
+
* when there is one); never, if open failed. For tests that measure boot,
|
|
178
|
+
* which must not read anything themselves to find out.
|
|
179
|
+
*/
|
|
180
|
+
get readyForTesting(): Promise<void>;
|
|
167
181
|
/**
|
|
168
182
|
* The browser profile ID for this browser profile. Every instance of Replicache
|
|
169
183
|
* browser-profile-wide shares the same profile ID.
|
|
@@ -255,7 +269,22 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
255
269
|
*/
|
|
256
270
|
poke(poke: PokeInternal): Promise<void>;
|
|
257
271
|
beginPull(): Promise<BeginPullResult>;
|
|
272
|
+
/**
|
|
273
|
+
* Writes the in-memory state to IndexedDB.
|
|
274
|
+
*
|
|
275
|
+
* Behaviour change: if this instance's IndexedDB database was deleted under
|
|
276
|
+
* it (another tab's collector, or cleared site data), this no longer rejects
|
|
277
|
+
* with `IDBNotFoundError`. It reports the loss once through
|
|
278
|
+
* `onClientStateNotFound('idb-deleted')` and resolves; nothing was persisted.
|
|
279
|
+
* `refresh()` behaves the same way. Callers that need to know the write did
|
|
280
|
+
* not land must use `onClientStateNotFound`.
|
|
281
|
+
*/
|
|
258
282
|
persist(): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Pulls the latest persisted state from IndexedDB. Like `persist()`, a
|
|
285
|
+
* deleted database reports `onClientStateNotFound('idb-deleted')` and
|
|
286
|
+
* resolves instead of rejecting.
|
|
287
|
+
*/
|
|
259
288
|
refresh(): Promise<void>;
|
|
260
289
|
disableClientGroup(): Promise<void>;
|
|
261
290
|
/**
|
|
@@ -317,9 +346,9 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
317
346
|
*/
|
|
318
347
|
query<R>(body: (tx: ReadTransaction) => Promise<R> | R): Promise<R>;
|
|
319
348
|
/**
|
|
320
|
-
* The DURABLE last-mutation-IDs of this client's
|
|
321
|
-
* the PERDAG — the companion to `cookie`, and
|
|
322
|
-
* that supplies its own pokes.
|
|
349
|
+
* The DURABLE, server-acknowledged last-mutation-IDs of this client's
|
|
350
|
+
* client group, read from the PERDAG — the companion to `cookie`, and
|
|
351
|
+
* required by any embedder that supplies its own pokes.
|
|
323
352
|
*
|
|
324
353
|
* WHY THIS HAS TO EXIST. A poke's `lastMutationIDChanges` are merged
|
|
325
354
|
* over the base snapshot's, so naming a client with a value BELOW what
|
|
@@ -346,6 +375,17 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
346
375
|
* appears.
|
|
347
376
|
*/
|
|
348
377
|
get lastMutationIDs(): Promise<Record<ClientID, number>>;
|
|
378
|
+
/**
|
|
379
|
+
* The snapshot the next poke applies on — its cookie and every entry
|
|
380
|
+
* whose key starts with `prefix`, read together. For embedders that
|
|
381
|
+
* supply their own pokes and must diff against what that snapshot really
|
|
382
|
+
* holds (after a sibling tab's snapshot was refreshed in underneath them,
|
|
383
|
+
* or while pending mutations make the local view differ from it).
|
|
384
|
+
*/
|
|
385
|
+
baseSnapshotEntries(prefix: string): Promise<{
|
|
386
|
+
cookie: Cookie;
|
|
387
|
+
entries: [string, FrozenJSONValue][];
|
|
388
|
+
}>;
|
|
349
389
|
get cookie(): Promise<Cookie>;
|
|
350
390
|
recoverMutations(): Promise<boolean> | void;
|
|
351
391
|
/**
|
|
@@ -358,4 +398,32 @@ export declare class ReplicacheImpl<MD extends MutatorDefs = {}> {
|
|
|
358
398
|
*/
|
|
359
399
|
experimentalPendingMutations(): Promise<readonly PendingMutation[]>;
|
|
360
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* The `reason` `onClientStateNotFound` is called with when this instance's
|
|
403
|
+
* IndexedDB database was deleted under it.
|
|
404
|
+
*/
|
|
405
|
+
export declare const CLIENT_STATE_NOT_FOUND_REASON_IDB_DELETED = "idb-deleted";
|
|
406
|
+
/**
|
|
407
|
+
* The longest a retry waits for a `resume` after a freeze. `frozen` is
|
|
408
|
+
* module-global and set by any `freeze` event, so a `resume` that is missed
|
|
409
|
+
* (or a synthetic `freeze` from another tool) would otherwise park open
|
|
410
|
+
* forever. Past the cap the retry proceeds with its ordinary backoff.
|
|
411
|
+
*/
|
|
412
|
+
export declare const FREEZE_RESUME_WAIT_CAP_MS = 10000;
|
|
413
|
+
/**
|
|
414
|
+
* The DOMExceptions an IndexedDB call raises when the browser ended its
|
|
415
|
+
* transaction underneath it — a request in an aborted transaction
|
|
416
|
+
* (`AbortError`), `objectStore()` on a finished one (`InvalidStateError`), a
|
|
417
|
+
* request on an inactive one (`TransactionInactiveError`). Everything else —
|
|
418
|
+
* a missing store, bad data, quota on a fresh transaction — is not retried.
|
|
419
|
+
*/
|
|
420
|
+
export declare function isTransientIdbAbort(e: unknown): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Reload loop guard for the default `onClientStateNotFound`. Records the
|
|
423
|
+
* reload's timestamp under a per-database `sessionStorage` key (the value
|
|
424
|
+
* survives the reload, which is the point) and refuses a second reload inside
|
|
425
|
+
* RELOAD_LOOP_WINDOW_MS. `sessionStorage` unavailable or throwing (privacy
|
|
426
|
+
* modes, sandboxed frames) means no guard: allow the reload, as before.
|
|
427
|
+
*/
|
|
428
|
+
export declare function allowClientStateNotFoundReload(idbName: string, now?: number): boolean;
|
|
361
429
|
//# sourceMappingURL=replicache-impl.d.ts.map
|
|
@@ -237,8 +237,8 @@ export interface ZeroTxData {
|
|
|
237
237
|
token: string | undefined;
|
|
238
238
|
}
|
|
239
239
|
export type ZeroReadOptions = {
|
|
240
|
+
/** A MEMDAG read/write the caller already holds (no lock is taken). */
|
|
240
241
|
openLazyRead?: Read | undefined;
|
|
241
|
-
openLazySourceRead?: Read | undefined;
|
|
242
242
|
};
|
|
243
243
|
declare const idTag: unique symbol;
|
|
244
244
|
export type EphemeralID = number & {
|
|
@@ -256,6 +256,9 @@ export interface ZeroOption {
|
|
|
256
256
|
auth: string;
|
|
257
257
|
/**
|
|
258
258
|
* Allow Zero to initialize its IVM state from the given hash and dag.
|
|
259
|
+
*
|
|
260
|
+
* Called again if IndexedDB aborts the read underneath it (a tab frozen
|
|
261
|
+
* while it boots): apply side effects only once the read has succeeded.
|
|
259
262
|
*/
|
|
260
263
|
init(hash: Hash, store: Store): Promise<void>;
|
|
261
264
|
/**
|
|
@@ -143,10 +143,14 @@ export interface ZeroOptions<S extends Schema, MD extends CustomMutatorDefs | un
|
|
|
143
143
|
* - the zero-cache fails to find the server side synchronization state for
|
|
144
144
|
* this client.
|
|
145
145
|
*
|
|
146
|
+
* - the local IndexedDB database was deleted while this client was running
|
|
147
|
+
* (another tab's collector dropped it, or site data was cleared); then
|
|
148
|
+
* `reason` is `'idb-deleted'`.
|
|
149
|
+
*
|
|
146
150
|
* The default behavior is to reload the page (using `location.reload()`).
|
|
147
151
|
* Provide your own function to prevent the page from reloading automatically.
|
|
148
152
|
*/
|
|
149
|
-
onClientStateNotFound?: (() => void) | undefined;
|
|
153
|
+
onClientStateNotFound?: ((reason?: string) => void) | undefined;
|
|
150
154
|
/**
|
|
151
155
|
* The number of milliseconds to wait before disconnecting a Zero
|
|
152
156
|
* instance whose tab has become hidden.
|
|
@@ -13,6 +13,12 @@ export declare class ZeroRep implements ZeroOption {
|
|
|
13
13
|
#private;
|
|
14
14
|
constructor(context: ZeroContext, ivmMain: IVMSourceBranch, customMutatorsEnabled: boolean, mutationTracker: MutationTracker, onLocalHydrationComplete: () => void);
|
|
15
15
|
set auth(auth: string);
|
|
16
|
+
/**
|
|
17
|
+
* Safe to call again: Replicache retries it when IndexedDB aborts its read
|
|
18
|
+
* (a tab frozen while it boots). A call that fails applies nothing (the
|
|
19
|
+
* rows are applied only after the whole read); once one has applied its
|
|
20
|
+
* result, later calls do nothing.
|
|
21
|
+
*/
|
|
16
22
|
init(hash: Hash, store: LazyStore): Promise<void>;
|
|
17
23
|
getTxData: (desiredHead: Hash, readOptions?: ZeroReadOptions | undefined) => Promise<TxData> | undefined;
|
|
18
24
|
advance: (expectedHash: Hash, newHash: Hash, diffs: InternalDiff) => void;
|
|
@@ -201,7 +201,8 @@ export declare class Zero<const S extends Schema, MD extends CustomMutatorDefs |
|
|
|
201
201
|
*/
|
|
202
202
|
get currentCookie(): Promise<Cookie>;
|
|
203
203
|
/**
|
|
204
|
-
* The DURABLE last-mutation-IDs of this client's
|
|
204
|
+
* The DURABLE, server-acknowledged last-mutation-IDs of this client's
|
|
205
|
+
* client group (pending local mutations are not counted).
|
|
205
206
|
*
|
|
206
207
|
* An adapter that supplies its own pokes MUST floor every
|
|
207
208
|
* `lastMutationIDChanges` entry with this. A poke naming any client —
|
|
@@ -212,6 +213,17 @@ export declare class Zero<const S extends Schema, MD extends CustomMutatorDefs |
|
|
|
212
213
|
* sibling made durable.
|
|
213
214
|
*/
|
|
214
215
|
get currentLastMutationIDs(): Promise<Record<ClientID, number>>;
|
|
216
|
+
/**
|
|
217
|
+
* The snapshot the next `pokeDirect` applies on: its cookie and every
|
|
218
|
+
* entry under `prefix`, read together. Lets an adapter diff against what
|
|
219
|
+
* that snapshot really holds when it is not what the adapter last poked
|
|
220
|
+
* (a sibling tab's snapshot refreshed in, or pending mutations that make
|
|
221
|
+
* the local view differ from it on rows it cannot name).
|
|
222
|
+
*/
|
|
223
|
+
baseSnapshotEntries(prefix: string): Promise<{
|
|
224
|
+
cookie: Cookie;
|
|
225
|
+
entries: [string, ReadonlyJSONValue][];
|
|
226
|
+
}>;
|
|
215
227
|
/**
|
|
216
228
|
* A rough heuristic for whether the client is currently online and
|
|
217
229
|
* authenticated.
|
package/dist/zero.js
CHANGED
package/package.json
CHANGED