cojson 0.20.1 → 0.20.3
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +19 -7
- package/dist/GarbageCollector.d.ts +3 -3
- package/dist/GarbageCollector.d.ts.map +1 -1
- package/dist/GarbageCollector.js +4 -4
- package/dist/GarbageCollector.js.map +1 -1
- package/dist/coValueCore/coValueCore.d.ts +23 -3
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +116 -36
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/localNode.d.ts +12 -0
- package/dist/localNode.d.ts.map +1 -1
- package/dist/localNode.js +51 -3
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +5 -0
- package/dist/permissions.js.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +13 -10
- package/dist/sync.js.map +1 -1
- package/dist/tests/coValueCore.loadFromStorage.test.js +87 -0
- package/dist/tests/coValueCore.loadFromStorage.test.js.map +1 -1
- package/dist/tests/group.parentGroupCache.test.js +2 -2
- package/dist/tests/group.parentGroupCache.test.js.map +1 -1
- package/dist/tests/knownState.lazyLoading.test.js +44 -0
- package/dist/tests/knownState.lazyLoading.test.js.map +1 -1
- package/dist/tests/permissions.test.js +83 -2
- package/dist/tests/permissions.test.js.map +1 -1
- package/dist/tests/sync.garbageCollection.test.js +87 -3
- package/dist/tests/sync.garbageCollection.test.js.map +1 -1
- package/dist/tests/sync.multipleServers.test.js +0 -62
- package/dist/tests/sync.multipleServers.test.js.map +1 -1
- package/dist/tests/sync.peerReconciliation.test.js +156 -0
- package/dist/tests/sync.peerReconciliation.test.js.map +1 -1
- package/package.json +4 -4
- package/src/GarbageCollector.ts +4 -3
- package/src/coValueCore/coValueCore.ts +129 -39
- package/src/localNode.ts +65 -4
- package/src/permissions.ts +6 -0
- package/src/sync.ts +11 -9
- package/src/tests/coValueCore.loadFromStorage.test.ts +108 -0
- package/src/tests/group.parentGroupCache.test.ts +2 -2
- package/src/tests/knownState.lazyLoading.test.ts +52 -0
- package/src/tests/permissions.test.ts +118 -1
- package/src/tests/sync.garbageCollection.test.ts +115 -3
- package/src/tests/sync.multipleServers.test.ts +0 -65
- package/src/tests/sync.peerReconciliation.test.ts +199 -0
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# cojson
|
|
2
2
|
|
|
3
|
+
## 0.20.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- eca8b83: Added caching for groups when accessing a readKey.
|
|
8
|
+
Marked private transactions in groups as invalid.
|
|
9
|
+
- cojson-core-wasm@0.20.3
|
|
10
|
+
- cojson-core-rn@0.20.3
|
|
11
|
+
- cojson-core-napi@0.20.3
|
|
12
|
+
|
|
13
|
+
## 0.20.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 251a89e: Optimized peer reconciliation to prevent unnecessary data transfer on reconnect.
|
|
18
|
+
- cojson-core-wasm@0.20.2
|
|
19
|
+
- cojson-core-rn@0.20.2
|
|
20
|
+
- cojson-core-napi@0.20.2
|
|
21
|
+
|
|
3
22
|
## 0.20.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -7,7 +26,6 @@
|
|
|
7
26
|
- 03195eb: Added client-side load request throttling to improve the loading experience when loading a lot of data concurrently.
|
|
8
27
|
|
|
9
28
|
When a client requests more than 1k CoValues concurrently, load requests are now queued locally and sent as capacity becomes available.
|
|
10
|
-
|
|
11
29
|
- cojson-core-wasm@0.20.1
|
|
12
30
|
- cojson-core-rn@0.20.1
|
|
13
31
|
- cojson-core-napi@0.20.1
|
|
@@ -32,7 +50,6 @@
|
|
|
32
50
|
## 💥 Breaking changes
|
|
33
51
|
|
|
34
52
|
### Crypto providers / fallback behavior
|
|
35
|
-
|
|
36
53
|
- **Removed `PureJSCrypto`** from `cojson` (including the `cojson/crypto/PureJSCrypto` export).
|
|
37
54
|
- **Removed `RNQuickCrypto`** from `jazz-tools`.
|
|
38
55
|
- **No more fallback to JavaScript crypto**: if crypto fails to initialize, Jazz now throws an error instead of falling back silently.
|
|
@@ -43,7 +60,6 @@
|
|
|
43
60
|
### Patch Changes
|
|
44
61
|
|
|
45
62
|
- 6b9368a: Added `deleteCoValues` function to permanently delete CoValues and their nested references.
|
|
46
|
-
|
|
47
63
|
- CoValues are marked with a tombstone, making them inaccessible to all users
|
|
48
64
|
- Supports deleting nested CoValues via resolve queries
|
|
49
65
|
- Requires admin permissions on the CoValue's group
|
|
@@ -55,7 +71,6 @@
|
|
|
55
71
|
- 89332d5: Moved stable JSON serialization from JavaScript to Rust in SessionLog operations
|
|
56
72
|
|
|
57
73
|
### Changes
|
|
58
|
-
|
|
59
74
|
- **`tryAdd`**: Stable serialization now happens in Rust. The Rust layer parses each transaction and re-serializes it to ensure a stable JSON representation for signature verification. JavaScript side now uses `JSON.stringify` instead of `stableStringify`.
|
|
60
75
|
|
|
61
76
|
- **`addNewPrivateTransaction`** and **`addNewTrustingTransaction`**: Removed `stableStringify` usage since the data is either encrypted (private) or already in string format (trusting), making stable serialization unnecessary on the JS side.
|
|
@@ -431,7 +446,6 @@
|
|
|
431
446
|
### Patch Changes
|
|
432
447
|
|
|
433
448
|
- a584ab3: Add WasmCrypto support for Cloudflare Workers and edge runtimes by importing `jazz-tools/load-edge-wasm`.
|
|
434
|
-
|
|
435
449
|
- Enable WasmCrypto functionality by initializing the WebAssembly environment with the import: `import "jazz-tools/load-edge-wasm"` in edge runtimes.
|
|
436
450
|
- Guarantee compatibility across Cloudflare Workers and other edge runtime environments.
|
|
437
451
|
|
|
@@ -452,7 +466,6 @@
|
|
|
452
466
|
- 2ddf4d9: Introducing version control APIs, unstable_branch and unstable_merge
|
|
453
467
|
|
|
454
468
|
Flagged as unstable because branch & merge scope & propagation needs to be validated.
|
|
455
|
-
|
|
456
469
|
- cojson-core-wasm@0.18.13
|
|
457
470
|
|
|
458
471
|
## 0.18.12
|
|
@@ -668,7 +681,6 @@
|
|
|
668
681
|
- 3cd1586: Makes the key rotation not fail when child groups are unavailable or their readkey is not accessible.
|
|
669
682
|
|
|
670
683
|
Also changes the Group.removeMember method to not return a Promise, because:
|
|
671
|
-
|
|
672
684
|
- All the locally available child groups are rotated immediately
|
|
673
685
|
- All the remote child groups are rotated in background, but since they are not locally available the user won't need the new key immediately
|
|
674
686
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { CoValueCore } from "./coValueCore/coValueCore.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { LocalNode } from "./localNode.js";
|
|
3
3
|
/**
|
|
4
4
|
* TTL-based garbage collector for removing unused CoValues from memory.
|
|
5
5
|
*/
|
|
6
6
|
export declare class GarbageCollector {
|
|
7
|
-
private readonly
|
|
7
|
+
private readonly node;
|
|
8
8
|
private readonly interval;
|
|
9
|
-
constructor(
|
|
9
|
+
constructor(node: LocalNode);
|
|
10
10
|
getCurrentTime(): number;
|
|
11
11
|
trackCoValueAccess({ verified }: CoValueCore): void;
|
|
12
12
|
collect(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GarbageCollector.d.ts","sourceRoot":"","sources":["../src/GarbageCollector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"GarbageCollector.d.ts","sourceRoot":"","sources":["../src/GarbageCollector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAG3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,qBAAa,gBAAgB;IAGf,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiC;gBAE7B,IAAI,EAAE,SAAS;IAM5C,cAAc;IAId,kBAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,WAAW;IAM5C,OAAO;IAiBP,IAAI;CAGL"}
|
package/dist/GarbageCollector.js
CHANGED
|
@@ -3,8 +3,8 @@ import { GARBAGE_COLLECTOR_CONFIG } from "./config.js";
|
|
|
3
3
|
* TTL-based garbage collector for removing unused CoValues from memory.
|
|
4
4
|
*/
|
|
5
5
|
export class GarbageCollector {
|
|
6
|
-
constructor(
|
|
7
|
-
this.
|
|
6
|
+
constructor(node) {
|
|
7
|
+
this.node = node;
|
|
8
8
|
this.interval = setInterval(() => {
|
|
9
9
|
this.collect();
|
|
10
10
|
}, GARBAGE_COLLECTOR_CONFIG.INTERVAL);
|
|
@@ -19,14 +19,14 @@ export class GarbageCollector {
|
|
|
19
19
|
}
|
|
20
20
|
collect() {
|
|
21
21
|
const currentTime = this.getCurrentTime();
|
|
22
|
-
for (const coValue of this.
|
|
22
|
+
for (const coValue of this.node.allCoValues()) {
|
|
23
23
|
const { verified } = coValue;
|
|
24
24
|
if (!verified?.lastAccessed) {
|
|
25
25
|
continue;
|
|
26
26
|
}
|
|
27
27
|
const timeSinceLastAccessed = currentTime - verified.lastAccessed;
|
|
28
28
|
if (timeSinceLastAccessed > GARBAGE_COLLECTOR_CONFIG.MAX_AGE) {
|
|
29
|
-
coValue.
|
|
29
|
+
this.node.internalUnmountCoValue(coValue.id);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GarbageCollector.js","sourceRoot":"","sources":["../src/GarbageCollector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"GarbageCollector.js","sourceRoot":"","sources":["../src/GarbageCollector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAIvD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAG3B,YAA6B,IAAe;QAAf,SAAI,GAAJ,IAAI,CAAW;QAC1C,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE;YAC/B,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,cAAc;QACZ,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC;IAC3B,CAAC;IAED,kBAAkB,CAAC,EAAE,QAAQ,EAAe;QAC1C,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAC1C,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YAC9C,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;YAE7B,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE,CAAC;gBAC5B,SAAS;YACX,CAAC;YAED,MAAM,qBAAqB,GAAG,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAC;YAElE,IAAI,qBAAqB,GAAG,wBAAwB,CAAC,OAAO,EAAE,CAAC;gBAC7D,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI;QACF,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -78,7 +78,7 @@ export declare class CoValueCore {
|
|
|
78
78
|
readonly listeners: Set<(core: CoValueCore, unsub: () => void) => void>;
|
|
79
79
|
private counter;
|
|
80
80
|
constructor(id: RawCoID, node: LocalNode);
|
|
81
|
-
get loadingState(): "available" | "
|
|
81
|
+
get loadingState(): "available" | "loading" | "garbageCollected" | "onlyKnownState" | "unknown" | "unavailable";
|
|
82
82
|
hasMissingDependencies(): boolean;
|
|
83
83
|
isAvailable(): this is AvailableCoValueCore;
|
|
84
84
|
isCompletelyDownloaded(): boolean;
|
|
@@ -103,13 +103,30 @@ export declare class CoValueCore {
|
|
|
103
103
|
getLoadingStateForPeer(peerId: PeerID): "available" | "unknown" | "unavailable" | "pending" | "errored";
|
|
104
104
|
private updateCounter;
|
|
105
105
|
/**
|
|
106
|
-
* Removes the CoValue from memory.
|
|
106
|
+
* Removes the CoValue content from memory but keeps a shell with cached knownState.
|
|
107
|
+
* This enables accurate LOAD requests during peer reconciliation.
|
|
107
108
|
*
|
|
108
109
|
* @returns true if the coValue was successfully unmounted, false otherwise
|
|
109
110
|
*/
|
|
110
111
|
unmount(): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Decrements the counter for the current loading state.
|
|
114
|
+
* Used during unmount to properly track state transitions.
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
decrementLoadingStateCounter(): void;
|
|
111
118
|
markNotFoundInPeer(peerId: PeerID): void;
|
|
112
119
|
markFoundInPeer(peerId: PeerID, previousState: string): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clean up cached state when CoValue becomes available.
|
|
122
|
+
* Called after the CoValue transitions from garbageCollected/onlyKnownState to available.
|
|
123
|
+
*/
|
|
124
|
+
private cleanupLastKnownState;
|
|
125
|
+
/**
|
|
126
|
+
* Initialize this CoValueCore as a garbageCollected shell.
|
|
127
|
+
* Called when creating a replacement CoValueCore after unmounting.
|
|
128
|
+
*/
|
|
129
|
+
setGarbageCollectedState(knownState: CoValueKnownState): void;
|
|
113
130
|
missingDependencies: Set<`co_z${string}`>;
|
|
114
131
|
isCircularDependency(dependency: CoValueCore): boolean;
|
|
115
132
|
newContentQueue: {
|
|
@@ -137,6 +154,8 @@ export declare class CoValueCore {
|
|
|
137
154
|
* The return value identity is going to be stable as long as the CoValue is not modified.
|
|
138
155
|
*
|
|
139
156
|
* On change the knownState is invalidated and a new object is returned.
|
|
157
|
+
*
|
|
158
|
+
* For garbageCollected/onlyKnownState CoValues, returns the cached knownState.
|
|
140
159
|
*/
|
|
141
160
|
knownState(): CoValueKnownState;
|
|
142
161
|
/**
|
|
@@ -324,7 +343,8 @@ export declare class CoValueCore {
|
|
|
324
343
|
* Lazily load only the knownState from storage without loading full transaction data.
|
|
325
344
|
* This is useful for checking if a peer needs new content before committing to a full load.
|
|
326
345
|
*
|
|
327
|
-
*
|
|
346
|
+
* If found in storage, marks the CoValue as onlyKnownState and caches the knownState.
|
|
347
|
+
* This enables accurate LOAD requests during peer reconciliation.
|
|
328
348
|
*
|
|
329
349
|
* @param done - Callback with the storage knownState, or undefined if not found in storage
|
|
330
350
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coValueCore.d.ts","sourceRoot":"","sources":["../../src/coValueCore/coValueCore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGrD,OAAO,EACL,cAAc,EACd,IAAI,EACJ,KAAK,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,OAAO,EAEP,OAAO,EACP,SAAS,EACT,aAAa,EACd,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAGtE,OAAO,EA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e,EAAE,IAAI,CAAC;IACtB,oBAAoB,EAAE,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,kBAAkB,CAAC;IACzB,EAAE,EAAE,OAAO,CAAC;IACZ,YAAY,EAAE,SAAS,CAAC;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,EAAE,EAAE,OAAO,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;IAC/B,MAAM,EAAE,UAAU,GAAG,qBAAqB,GAAG,yBAAyB,CAAC;IACvE,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAC/B,+CAA+C,GAC/C,0CAA0C,GAC1C,wBAAwB,GACxB,gBAAgB,GAChB,qBAAqB,GACrB,8BAA8B,CAAC"}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CoValueCore_instances, _CoValueCore_isDeleteTransaction, _CoValueCore_markAsDeleted, _CoValueCore_getDeleteMarker, _CoValueCore_canAuthorDeleteCoValueAtTime, _CoValueCore_isNotificationScheduled, _CoValueCore_batchedUpdates, _CoValueCore_isNotifyUpdatePaused;
|
|
12
|
+
var _CoValueCore_instances, _CoValueCore_lastKnownStateSource, _CoValueCore_lastKnownState, _CoValueCore_isDeleteTransaction, _CoValueCore_markAsDeleted, _CoValueCore_getDeleteMarker, _CoValueCore_canAuthorDeleteCoValueAtTime, _CoValueCore_isNotificationScheduled, _CoValueCore_batchedUpdates, _CoValueCore_isNotifyUpdatePaused;
|
|
13
13
|
import { ValueType, metrics } from "@opentelemetry/api";
|
|
14
14
|
import { coreToCoValue } from "../coreToCoValue.js";
|
|
15
15
|
import { isDeleteSessionID, } from "../ids.js";
|
|
@@ -155,6 +155,13 @@ export class CoValueCore {
|
|
|
155
155
|
// Whether the coValue is deleted
|
|
156
156
|
this.isDeleted = false;
|
|
157
157
|
this.loadingStatuses = new Map();
|
|
158
|
+
// Tracks why we have lastKnownState (separate from loadingStatuses)
|
|
159
|
+
// - "garbageCollected": was in memory, got GC'd
|
|
160
|
+
// - "onlyKnownState": checked storage, found knownState, but didn't load full content
|
|
161
|
+
_CoValueCore_lastKnownStateSource.set(this, void 0);
|
|
162
|
+
// Cache the knownState when transitioning to garbageCollected/onlyKnownState
|
|
163
|
+
// Used during peer reconciliation to send accurate LOAD requests
|
|
164
|
+
_CoValueCore_lastKnownState.set(this, void 0);
|
|
158
165
|
this.listeners = new Set();
|
|
159
166
|
this.missingDependencies = new Set();
|
|
160
167
|
this.newContentQueue = [];
|
|
@@ -223,14 +230,21 @@ export class CoValueCore {
|
|
|
223
230
|
if (this.verified) {
|
|
224
231
|
return "available";
|
|
225
232
|
}
|
|
226
|
-
|
|
227
|
-
return "unknown";
|
|
228
|
-
}
|
|
233
|
+
// Check for pending peers FIRST - loading takes priority over other states
|
|
229
234
|
for (const peer of this.loadingStatuses.values()) {
|
|
230
235
|
if (peer.type === "pending") {
|
|
231
236
|
return "loading";
|
|
232
237
|
}
|
|
233
|
-
|
|
238
|
+
}
|
|
239
|
+
// Check for lastKnownStateSource (garbageCollected or onlyKnownState)
|
|
240
|
+
if (__classPrivateFieldGet(this, _CoValueCore_lastKnownStateSource, "f")) {
|
|
241
|
+
return __classPrivateFieldGet(this, _CoValueCore_lastKnownStateSource, "f");
|
|
242
|
+
}
|
|
243
|
+
if (this.loadingStatuses.size === 0) {
|
|
244
|
+
return "unknown";
|
|
245
|
+
}
|
|
246
|
+
for (const peer of this.loadingStatuses.values()) {
|
|
247
|
+
if (peer.type === "unknown") {
|
|
234
248
|
return "unknown";
|
|
235
249
|
}
|
|
236
250
|
}
|
|
@@ -314,27 +328,21 @@ export class CoValueCore {
|
|
|
314
328
|
}
|
|
315
329
|
}
|
|
316
330
|
/**
|
|
317
|
-
* Removes the CoValue from memory.
|
|
331
|
+
* Removes the CoValue content from memory but keeps a shell with cached knownState.
|
|
332
|
+
* This enables accurate LOAD requests during peer reconciliation.
|
|
318
333
|
*
|
|
319
334
|
* @returns true if the coValue was successfully unmounted, false otherwise
|
|
320
335
|
*/
|
|
321
336
|
unmount() {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (!this.node.syncManager.isSyncedToServerPeers(this.id)) {
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
337
|
+
return this.node.internalUnmountCoValue(this.id);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Decrements the counter for the current loading state.
|
|
341
|
+
* Used during unmount to properly track state transitions.
|
|
342
|
+
* @internal
|
|
343
|
+
*/
|
|
344
|
+
decrementLoadingStateCounter() {
|
|
335
345
|
this.counter.add(-1, { state: this.loadingState });
|
|
336
|
-
this.node.internalDeleteCoValue(this.id);
|
|
337
|
-
return true;
|
|
338
346
|
}
|
|
339
347
|
markNotFoundInPeer(peerId) {
|
|
340
348
|
const previousState = this.loadingState;
|
|
@@ -347,6 +355,32 @@ export class CoValueCore {
|
|
|
347
355
|
this.updateCounter(previousState);
|
|
348
356
|
this.scheduleNotifyUpdate();
|
|
349
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Clean up cached state when CoValue becomes available.
|
|
360
|
+
* Called after the CoValue transitions from garbageCollected/onlyKnownState to available.
|
|
361
|
+
*/
|
|
362
|
+
cleanupLastKnownState() {
|
|
363
|
+
// Clear both fields - in-memory verified state is now authoritative
|
|
364
|
+
__classPrivateFieldSet(this, _CoValueCore_lastKnownStateSource, undefined, "f");
|
|
365
|
+
__classPrivateFieldSet(this, _CoValueCore_lastKnownState, undefined, "f");
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Initialize this CoValueCore as a garbageCollected shell.
|
|
369
|
+
* Called when creating a replacement CoValueCore after unmounting.
|
|
370
|
+
*/
|
|
371
|
+
setGarbageCollectedState(knownState) {
|
|
372
|
+
// Only set garbageCollected state if storage is active
|
|
373
|
+
// Without storage, we can't reload the CoValue anyway
|
|
374
|
+
if (!this.node.storage) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
// Transition counter from 'unknown' (set by constructor) to 'garbageCollected'
|
|
378
|
+
// previousState will be 'unknown', newState will be 'garbageCollected'
|
|
379
|
+
const previousState = this.loadingState;
|
|
380
|
+
__classPrivateFieldSet(this, _CoValueCore_lastKnownStateSource, "garbageCollected", "f");
|
|
381
|
+
__classPrivateFieldSet(this, _CoValueCore_lastKnownState, knownState, "f");
|
|
382
|
+
this.updateCounter(previousState);
|
|
383
|
+
}
|
|
350
384
|
isCircularDependency(dependency) {
|
|
351
385
|
if (dependency.id === this.id) {
|
|
352
386
|
return true;
|
|
@@ -415,6 +449,10 @@ export class CoValueCore {
|
|
|
415
449
|
throw new Error("CoValueCore: provideHeader called on coValue with verified sessions present!");
|
|
416
450
|
}
|
|
417
451
|
this._verified = new VerifiedState(this.id, this.node.crypto, header, new SessionMap(this.id, this.node.crypto, streamingKnownState));
|
|
452
|
+
// Clean up if transitioning from garbageCollected/onlyKnownState
|
|
453
|
+
if (this.isAvailable()) {
|
|
454
|
+
this.cleanupLastKnownState();
|
|
455
|
+
}
|
|
418
456
|
return true;
|
|
419
457
|
}
|
|
420
458
|
markErrored(peerId, error) {
|
|
@@ -440,8 +478,10 @@ export class CoValueCore {
|
|
|
440
478
|
* Used to correctly manage the content & subscriptions during the content streaming process
|
|
441
479
|
*/
|
|
442
480
|
knownStateWithStreaming() {
|
|
443
|
-
|
|
444
|
-
|
|
481
|
+
if (this.verified) {
|
|
482
|
+
return this.verified.immutableKnownStateWithStreaming();
|
|
483
|
+
}
|
|
484
|
+
return this.knownState();
|
|
445
485
|
}
|
|
446
486
|
/**
|
|
447
487
|
* Returns the known state of the CoValue
|
|
@@ -449,9 +489,20 @@ export class CoValueCore {
|
|
|
449
489
|
* The return value identity is going to be stable as long as the CoValue is not modified.
|
|
450
490
|
*
|
|
451
491
|
* On change the knownState is invalidated and a new object is returned.
|
|
492
|
+
*
|
|
493
|
+
* For garbageCollected/onlyKnownState CoValues, returns the cached knownState.
|
|
452
494
|
*/
|
|
453
495
|
knownState() {
|
|
454
|
-
|
|
496
|
+
// 1. If we have verified content in memory, use that (authoritative)
|
|
497
|
+
if (this.verified) {
|
|
498
|
+
return this.verified.immutableKnownState();
|
|
499
|
+
}
|
|
500
|
+
// 2. If we have last known state (GC'd or onlyKnownState), use that
|
|
501
|
+
if (__classPrivateFieldGet(this, _CoValueCore_lastKnownState, "f")) {
|
|
502
|
+
return __classPrivateFieldGet(this, _CoValueCore_lastKnownState, "f");
|
|
503
|
+
}
|
|
504
|
+
// 3. Fallback to empty state (truly unknown CoValue)
|
|
505
|
+
return emptyKnownState(this.id);
|
|
455
506
|
}
|
|
456
507
|
/**
|
|
457
508
|
* Returns a known state message to signal to the peer that the coValue doesn't need to be synced anymore
|
|
@@ -1086,7 +1137,7 @@ export class CoValueCore {
|
|
|
1086
1137
|
if (!this.verified) {
|
|
1087
1138
|
throw new Error("CoValueCore: getCurrentReadKey called on coValue without verified state");
|
|
1088
1139
|
}
|
|
1089
|
-
if (this.
|
|
1140
|
+
if (this.isGroupOrAccount()) {
|
|
1090
1141
|
return expectGroup(this.getCurrentContent()).getCurrentReadKey();
|
|
1091
1142
|
}
|
|
1092
1143
|
else if (this.verified.header.ruleset.type === "ownedByGroup") {
|
|
@@ -1107,15 +1158,24 @@ export class CoValueCore {
|
|
|
1107
1158
|
if (!this.verified) {
|
|
1108
1159
|
throw new Error("CoValueCore: getUncachedReadKey called on coValue without verified state");
|
|
1109
1160
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1161
|
+
if (this.isGroup()) {
|
|
1162
|
+
// is group
|
|
1112
1163
|
const content = expectGroup(
|
|
1113
|
-
//
|
|
1114
|
-
// to
|
|
1164
|
+
// Private transactions are not considered valid in groups, so we don't need to pass
|
|
1165
|
+
// ignorePrivateTransactions: true to safely load the content
|
|
1166
|
+
this.getCurrentContent());
|
|
1167
|
+
return content.getReadKey(keyID);
|
|
1168
|
+
}
|
|
1169
|
+
else if (this.isGroupOrAccount()) {
|
|
1170
|
+
// is account
|
|
1171
|
+
const content = expectGroup(
|
|
1172
|
+
// Old accounts might have private transactions, because we were encrypting the root id in the past
|
|
1173
|
+
// So we need to load the account without private transactions, because we can't decrypt them without the read key
|
|
1115
1174
|
this.getCurrentContent({ ignorePrivateTransactions: true }));
|
|
1116
1175
|
return content.getReadKey(keyID);
|
|
1117
1176
|
}
|
|
1118
1177
|
else if (this.verified.header.ruleset.type === "ownedByGroup") {
|
|
1178
|
+
// is a CoValue owned by a group
|
|
1119
1179
|
return expectGroup(this.node
|
|
1120
1180
|
.expectCoValueLoaded(this.verified.header.ruleset.group)
|
|
1121
1181
|
.getCurrentContent()).getReadKey(keyID);
|
|
@@ -1186,7 +1246,14 @@ export class CoValueCore {
|
|
|
1186
1246
|
});
|
|
1187
1247
|
return;
|
|
1188
1248
|
}
|
|
1189
|
-
if
|
|
1249
|
+
// Check if we need to load from storage:
|
|
1250
|
+
// - If storage state is not unknown (already tried), AND
|
|
1251
|
+
// - Overall state is not garbageCollected/onlyKnownState (which need full content)
|
|
1252
|
+
// Then return early
|
|
1253
|
+
const overallState = this.loadingState;
|
|
1254
|
+
if (currentState !== "unknown" &&
|
|
1255
|
+
overallState !== "garbageCollected" &&
|
|
1256
|
+
overallState !== "onlyKnownState") {
|
|
1190
1257
|
done?.(currentState === "available");
|
|
1191
1258
|
return;
|
|
1192
1259
|
}
|
|
@@ -1204,7 +1271,8 @@ export class CoValueCore {
|
|
|
1204
1271
|
* Lazily load only the knownState from storage without loading full transaction data.
|
|
1205
1272
|
* This is useful for checking if a peer needs new content before committing to a full load.
|
|
1206
1273
|
*
|
|
1207
|
-
*
|
|
1274
|
+
* If found in storage, marks the CoValue as onlyKnownState and caches the knownState.
|
|
1275
|
+
* This enables accurate LOAD requests during peer reconciliation.
|
|
1208
1276
|
*
|
|
1209
1277
|
* @param done - Callback with the storage knownState, or undefined if not found in storage
|
|
1210
1278
|
*/
|
|
@@ -1213,13 +1281,25 @@ export class CoValueCore {
|
|
|
1213
1281
|
done(undefined);
|
|
1214
1282
|
return;
|
|
1215
1283
|
}
|
|
1216
|
-
// If already
|
|
1217
|
-
|
|
1218
|
-
|
|
1284
|
+
// If we already have knowledge about this CoValue (in memory or cached), return it
|
|
1285
|
+
// knownState() returns verified state, lastKnownState, or empty state
|
|
1286
|
+
const knownState = this.knownState();
|
|
1287
|
+
if (knownState.header) {
|
|
1288
|
+
done(knownState);
|
|
1219
1289
|
return;
|
|
1220
1290
|
}
|
|
1221
1291
|
// Delegate to storage - caching is handled at storage level
|
|
1222
|
-
this.node.storage.loadKnownState(this.id,
|
|
1292
|
+
this.node.storage.loadKnownState(this.id, (knownState) => {
|
|
1293
|
+
// The coValue could become available in the meantime.
|
|
1294
|
+
if (knownState && !this.isAvailable()) {
|
|
1295
|
+
// Cache the knownState and mark as onlyKnownState
|
|
1296
|
+
const previousState = this.loadingState;
|
|
1297
|
+
__classPrivateFieldSet(this, _CoValueCore_lastKnownStateSource, "onlyKnownState", "f");
|
|
1298
|
+
__classPrivateFieldSet(this, _CoValueCore_lastKnownState, knownState, "f");
|
|
1299
|
+
this.updateCounter(previousState);
|
|
1300
|
+
}
|
|
1301
|
+
done(knownState);
|
|
1302
|
+
});
|
|
1223
1303
|
}
|
|
1224
1304
|
loadFromPeers(peers, mode) {
|
|
1225
1305
|
if (peers.length === 0) {
|
|
@@ -1270,7 +1350,7 @@ export class CoValueCore {
|
|
|
1270
1350
|
}, true);
|
|
1271
1351
|
}
|
|
1272
1352
|
}
|
|
1273
|
-
_CoValueCore_isNotificationScheduled = new WeakMap(), _CoValueCore_batchedUpdates = new WeakMap(), _CoValueCore_isNotifyUpdatePaused = new WeakMap(), _CoValueCore_instances = new WeakSet(), _CoValueCore_isDeleteTransaction = function _CoValueCore_isDeleteTransaction(sessionID, newTransactions, skipVerify) {
|
|
1353
|
+
_CoValueCore_lastKnownStateSource = new WeakMap(), _CoValueCore_lastKnownState = new WeakMap(), _CoValueCore_isNotificationScheduled = new WeakMap(), _CoValueCore_batchedUpdates = new WeakMap(), _CoValueCore_isNotifyUpdatePaused = new WeakMap(), _CoValueCore_instances = new WeakSet(), _CoValueCore_isDeleteTransaction = function _CoValueCore_isDeleteTransaction(sessionID, newTransactions, skipVerify) {
|
|
1274
1354
|
if (!this.verified) {
|
|
1275
1355
|
return {
|
|
1276
1356
|
value: false,
|