@loro-dev/flock 4.0.0 → 4.2.0
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/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/_moon_flock.d.ts +4 -0
- package/src/_moon_flock.ts +2154 -1684
- package/src/index.ts +24 -3
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import_json_ffi,
|
|
12
12
|
import_json_str_ffi,
|
|
13
13
|
version_ffi,
|
|
14
|
+
inclusiveVersion_ffi,
|
|
14
15
|
get_max_physical_time_ffi,
|
|
15
16
|
peer_id_ffi,
|
|
16
17
|
kv_to_json_ffi,
|
|
@@ -372,16 +373,19 @@ function decodeUnsignedLeb128(
|
|
|
372
373
|
offset: number,
|
|
373
374
|
): [number, number] {
|
|
374
375
|
let result = 0;
|
|
375
|
-
let
|
|
376
|
+
let multiplier = 1;
|
|
376
377
|
let consumed = 0;
|
|
377
378
|
while (offset + consumed < bytes.length) {
|
|
378
379
|
const byte = bytes[offset + consumed];
|
|
379
380
|
consumed += 1;
|
|
380
|
-
|
|
381
|
+
// Use arithmetic instead of bitwise operations to avoid 32-bit overflow.
|
|
382
|
+
// JavaScript bitwise operators convert to 32-bit signed integers,
|
|
383
|
+
// which breaks for values >= 2^31.
|
|
384
|
+
result += (byte & 0x7f) * multiplier;
|
|
381
385
|
if ((byte & 0x80) === 0) {
|
|
382
386
|
break;
|
|
383
387
|
}
|
|
384
|
-
|
|
388
|
+
multiplier *= 128;
|
|
385
389
|
}
|
|
386
390
|
return [result, consumed];
|
|
387
391
|
}
|
|
@@ -967,10 +971,27 @@ export class Flock {
|
|
|
967
971
|
merge(this.inner, other.inner);
|
|
968
972
|
}
|
|
969
973
|
|
|
974
|
+
/**
|
|
975
|
+
* Returns the exclusive version vector, which only includes peers that have
|
|
976
|
+
* at least one entry in the current state. This is consistent with the state
|
|
977
|
+
* after export and re-import.
|
|
978
|
+
*
|
|
979
|
+
* Use this version when sending to other peers for incremental sync.
|
|
980
|
+
*/
|
|
970
981
|
version(): VersionVector {
|
|
971
982
|
return decodeVersionVectorFromRaw(version_ffi(this.inner));
|
|
972
983
|
}
|
|
973
984
|
|
|
985
|
+
/**
|
|
986
|
+
* Returns the inclusive version vector, which includes all peers ever seen,
|
|
987
|
+
* even if their entries have been overridden by other peers.
|
|
988
|
+
*
|
|
989
|
+
* Use this version when checking if you have received all data from another peer.
|
|
990
|
+
*/
|
|
991
|
+
inclusiveVersion(): VersionVector {
|
|
992
|
+
return decodeVersionVectorFromRaw(inclusiveVersion_ffi(this.inner));
|
|
993
|
+
}
|
|
994
|
+
|
|
974
995
|
private exportJsonInternal(
|
|
975
996
|
from?: VersionVector,
|
|
976
997
|
pruneTombstonesBefore?: number,
|