loro-crdt 1.2.6 → 1.3.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.
@@ -237,11 +237,11 @@ function makeMutClosure(arg0, arg1, dtor, f) {
237
237
  CLOSURE_DTORS.register(real, state, state);
238
238
  return real;
239
239
  }
240
- function __wbg_adapter_58(arg0, arg1, arg2) {
240
+ function __wbg_adapter_60(arg0, arg1, arg2) {
241
241
  wasm.__wbindgen_export_3(arg0, arg1, addHeapObject(arg2));
242
242
  }
243
243
 
244
- function __wbg_adapter_61(arg0, arg1) {
244
+ function __wbg_adapter_63(arg0, arg1) {
245
245
  wasm.__wbindgen_export_4(arg0, arg1);
246
246
  }
247
247
 
@@ -971,9 +971,12 @@ export class LoroDoc {
971
971
  wasm.lorodoc_setRecordTimestamp(this.__wbg_ptr, auto_record);
972
972
  }
973
973
  /**
974
- * If two continuous local changes are within the interval, they will be merged into one change.
974
+ * If two continuous local changes are within (<=) the interval(**in seconds**), they will be merged into one change.
975
975
  *
976
- * The default value is 1_000_000, the default unit is seconds.
976
+ * The default value is 1_000 seconds.
977
+ *
978
+ * By default, we record timestamps in seconds for each change. So if the merge interval is 1, and changes A and B
979
+ * have timestamps of 3 and 4 respectively, then they will be merged into one change
977
980
  * @param {number} interval
978
981
  */
979
982
  setChangeMergeInterval(interval) {
@@ -1237,6 +1240,72 @@ export class LoroDoc {
1237
1240
  }
1238
1241
  }
1239
1242
  /**
1243
+ * Find the op id spans that between the `from` version and the `to` version.
1244
+ *
1245
+ * You can combine it with `exportJsonInIdSpan` to get the changes between two versions.
1246
+ *
1247
+ * You can use it to travel all the changes from `from` to `to`. `from` and `to` are frontiers,
1248
+ * and they can be concurrent to each other. You can use it to find all the changes related to an event:
1249
+ *
1250
+ * @example
1251
+ * ```ts
1252
+ * import { LoroDoc } from "loro-crdt";
1253
+ *
1254
+ * const docA = new LoroDoc();
1255
+ * docA.setPeerId("1");
1256
+ * const docB = new LoroDoc();
1257
+ *
1258
+ * docA.getText("text").update("Hello");
1259
+ * docA.commit();
1260
+ * const snapshot = docA.export({ mode: "snapshot" });
1261
+ * let done = false;
1262
+ * docB.subscribe(e => {
1263
+ * const spans = docB.findIdSpansBetween(e.from, e.to);
1264
+ * const changes = docB.exportJsonInIdSpan(spans.forward[0]);
1265
+ * console.log(changes);
1266
+ * // [{
1267
+ * // id: "0@1",
1268
+ * // timestamp: expect.any(Number),
1269
+ * // deps: [],
1270
+ * // lamport: 0,
1271
+ * // msg: undefined,
1272
+ * // ops: [{
1273
+ * // container: "cid:root-text:Text",
1274
+ * // counter: 0,
1275
+ * // content: {
1276
+ * // type: "insert",
1277
+ * // pos: 0,
1278
+ * // text: "Hello"
1279
+ * // }
1280
+ * // }]
1281
+ * // }]
1282
+ * });
1283
+ * docB.import(snapshot);
1284
+ * ```
1285
+ * @param {({ peer: PeerID, counter: number })[]} from
1286
+ * @param {({ peer: PeerID, counter: number })[]} to
1287
+ * @returns {VersionVectorDiff}
1288
+ */
1289
+ findIdSpansBetween(from, to) {
1290
+ try {
1291
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1292
+ const ptr0 = passArrayJsValueToWasm0(from, wasm.__wbindgen_export_0);
1293
+ const len0 = WASM_VECTOR_LEN;
1294
+ const ptr1 = passArrayJsValueToWasm0(to, wasm.__wbindgen_export_0);
1295
+ const len1 = WASM_VECTOR_LEN;
1296
+ wasm.lorodoc_findIdSpansBetween(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
1297
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1298
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1299
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1300
+ if (r2) {
1301
+ throw takeObject(r1);
1302
+ }
1303
+ return takeObject(r0);
1304
+ } finally {
1305
+ wasm.__wbindgen_add_to_stack_pointer(16);
1306
+ }
1307
+ }
1308
+ /**
1240
1309
  * Checkout the `DocState` to a specific version.
1241
1310
  *
1242
1311
  * > The document becomes detached during a `checkout` operation.
@@ -1315,12 +1384,14 @@ export class LoroDoc {
1315
1384
  }
1316
1385
  }
1317
1386
  /**
1318
- * Commit the cumulative auto committed transaction.
1387
+ * Commit the cumulative auto-committed transaction.
1319
1388
  *
1320
1389
  * You can specify the `origin`, `timestamp`, and `message` of the commit.
1321
1390
  *
1322
1391
  * - The `origin` is used to mark the event
1323
1392
  * - The `message` works like a git commit message, which will be recorded and synced to peers
1393
+ * - The `timestamp` is the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970.
1394
+ * It defaults to `Date.now() / 1000` when timestamp recording is enabled
1324
1395
  *
1325
1396
  * The events will be emitted after a transaction is committed. A transaction is committed when:
1326
1397
  *
@@ -1897,12 +1968,32 @@ export class LoroDoc {
1897
1968
  * Export updates in the given range in JSON format.
1898
1969
  * @param {any} start_vv
1899
1970
  * @param {any} end_vv
1971
+ * @param {boolean | undefined} [with_peer_compression]
1900
1972
  * @returns {JsonSchema}
1901
1973
  */
1902
- exportJsonUpdates(start_vv, end_vv) {
1974
+ exportJsonUpdates(start_vv, end_vv, with_peer_compression) {
1903
1975
  try {
1904
1976
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1905
- wasm.lorodoc_exportJsonUpdates(retptr, this.__wbg_ptr, addHeapObject(start_vv), addHeapObject(end_vv));
1977
+ wasm.lorodoc_exportJsonUpdates(retptr, this.__wbg_ptr, addHeapObject(start_vv), addHeapObject(end_vv), isLikeNone(with_peer_compression) ? 0xFFFFFF : with_peer_compression ? 1 : 0);
1978
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1979
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1980
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1981
+ if (r2) {
1982
+ throw takeObject(r1);
1983
+ }
1984
+ return takeObject(r0);
1985
+ } finally {
1986
+ wasm.__wbindgen_add_to_stack_pointer(16);
1987
+ }
1988
+ }
1989
+ /**
1990
+ * @param {{ peer: PeerID, counter: number, length: number }} idSpan
1991
+ * @returns {any}
1992
+ */
1993
+ exportJsonInIdSpan(idSpan) {
1994
+ try {
1995
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1996
+ wasm.lorodoc_exportJsonInIdSpan(retptr, this.__wbg_ptr, addHeapObject(idSpan));
1906
1997
  var r0 = getInt32Memory0()[retptr / 4 + 0];
1907
1998
  var r1 = getInt32Memory0()[retptr / 4 + 1];
1908
1999
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -2101,7 +2192,7 @@ export class LoroDoc {
2101
2192
  *
2102
2193
  * @example
2103
2194
  * ```ts
2104
- * import { LoroDoc, LoroText } from "loro-crdt";
2195
+ * import { LoroDoc, LoroText, LoroMap } from "loro-crdt";
2105
2196
  *
2106
2197
  * const doc = new LoroDoc();
2107
2198
  * const list = doc.getList("list");
@@ -2465,6 +2556,84 @@ export class LoroDoc {
2465
2556
  wasm.__wbindgen_add_to_stack_pointer(16);
2466
2557
  }
2467
2558
  }
2559
+ /**
2560
+ * Revert the document to the given frontiers.
2561
+ *
2562
+ * The doc will not become detached when using this method. Instead, it will generate a series
2563
+ * of operations to revert the document to the given version.
2564
+ *
2565
+ * @example
2566
+ * ```ts
2567
+ * const doc = new LoroDoc();
2568
+ * doc.setPeerId("1");
2569
+ * const text = doc.getText("text");
2570
+ * text.insert(0, "Hello");
2571
+ * doc.commit();
2572
+ * doc.revertTo([{ peer: "1", counter: 1 }]);
2573
+ * expect(doc.getText("text").toString()).toBe("He");
2574
+ * ```
2575
+ * @param {({ peer: PeerID, counter: number })[]} frontiers
2576
+ */
2577
+ revertTo(frontiers) {
2578
+ try {
2579
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2580
+ const ptr0 = passArrayJsValueToWasm0(frontiers, wasm.__wbindgen_export_0);
2581
+ const len0 = WASM_VECTOR_LEN;
2582
+ wasm.lorodoc_revertTo(retptr, this.__wbg_ptr, ptr0, len0);
2583
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2584
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2585
+ if (r1) {
2586
+ throw takeObject(r0);
2587
+ }
2588
+ } finally {
2589
+ wasm.__wbindgen_add_to_stack_pointer(16);
2590
+ }
2591
+ }
2592
+ /**
2593
+ * Apply a diff batch to the document
2594
+ * @param {Record<ContainerID, Diff>} diff
2595
+ */
2596
+ applyDiff(diff) {
2597
+ try {
2598
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2599
+ wasm.lorodoc_applyDiff(retptr, this.__wbg_ptr, addHeapObject(diff));
2600
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2601
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2602
+ if (r1) {
2603
+ throw takeObject(r0);
2604
+ }
2605
+ } finally {
2606
+ wasm.__wbindgen_add_to_stack_pointer(16);
2607
+ }
2608
+ }
2609
+ /**
2610
+ * Calculate the differences between two frontiers
2611
+ *
2612
+ * The entries in the returned object are sorted by causal order: the creation of a child container will be
2613
+ * presented before its use.
2614
+ * @param {({ peer: PeerID, counter: number })[]} from
2615
+ * @param {({ peer: PeerID, counter: number })[]} to
2616
+ * @returns {Record<ContainerID, Diff>}
2617
+ */
2618
+ diff(from, to) {
2619
+ try {
2620
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2621
+ const ptr0 = passArrayJsValueToWasm0(from, wasm.__wbindgen_export_0);
2622
+ const len0 = WASM_VECTOR_LEN;
2623
+ const ptr1 = passArrayJsValueToWasm0(to, wasm.__wbindgen_export_0);
2624
+ const len1 = WASM_VECTOR_LEN;
2625
+ wasm.lorodoc_diff(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1);
2626
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2627
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2628
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2629
+ if (r2) {
2630
+ throw takeObject(r1);
2631
+ }
2632
+ return takeObject(r0);
2633
+ } finally {
2634
+ wasm.__wbindgen_add_to_stack_pointer(16);
2635
+ }
2636
+ }
2468
2637
  }
2469
2638
 
2470
2639
  const LoroListFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -3362,7 +3531,7 @@ export class LoroMap {
3362
3531
  *
3363
3532
  * @example
3364
3533
  * ```ts
3365
- * import { LoroDoc } from "loro-crdt";
3534
+ * import { LoroDoc, LoroText } from "loro-crdt";
3366
3535
  *
3367
3536
  * const doc = new LoroDoc();
3368
3537
  * doc.setPeerId("1");
@@ -5176,26 +5345,6 @@ export class LoroTreeNode {
5176
5345
  }
5177
5346
  }
5178
5347
  /**
5179
- * Move this tree node to be a child of the parent.
5180
- * If the parent is undefined, this node will be a root node.
5181
- *
5182
- * If the index is not provided, the node will be appended to the end.
5183
- *
5184
- * It's not allowed that the target is an ancestor of the parent.
5185
- *
5186
- * @example
5187
- * ```ts
5188
- * const doc = new LoroDoc();
5189
- * const tree = doc.getTree("tree");
5190
- * const root = tree.createNode();
5191
- * const node = root.createNode();
5192
- * const node2 = node.createNode();
5193
- * node2.move(undefined, 0);
5194
- * // node2 root
5195
- * // |
5196
- * // node
5197
- *
5198
- * ```
5199
5348
  * @param {LoroTreeNode | undefined} parent
5200
5349
  * @param {number | undefined} [index]
5201
5350
  */
@@ -5358,11 +5507,6 @@ export class LoroTreeNode {
5358
5507
  }
5359
5508
  }
5360
5509
  /**
5361
- * Get the parent node of this node.
5362
- *
5363
- * - The parent of the root node is `undefined`.
5364
- * - The object returned is a new js object each time because it need to cross
5365
- * the WASM boundary.
5366
5510
  * @returns {LoroTreeNode | undefined}
5367
5511
  */
5368
5512
  parent() {
@@ -5560,6 +5704,7 @@ export class UndoManager {
5560
5704
  }
5561
5705
  /**
5562
5706
  * Set the merge interval (in ms).
5707
+ *
5563
5708
  * If the interval is set to 0, the undo steps will not be merged.
5564
5709
  * Otherwise, the undo steps will be merged if the interval between the two steps is less than the given interval.
5565
5710
  * @param {number} interval
@@ -5833,28 +5978,28 @@ export function __wbindgen_object_drop_ref(arg0) {
5833
5978
  takeObject(arg0);
5834
5979
  };
5835
5980
 
5836
- export function __wbg_loromap_new(arg0) {
5837
- const ret = LoroMap.__wrap(arg0);
5981
+ export function __wbg_lorolist_new(arg0) {
5982
+ const ret = LoroList.__wrap(arg0);
5838
5983
  return addHeapObject(ret);
5839
5984
  };
5840
5985
 
5841
- export function __wbg_lorotext_new(arg0) {
5842
- const ret = LoroText.__wrap(arg0);
5986
+ export function __wbg_lorocounter_new(arg0) {
5987
+ const ret = LoroCounter.__wrap(arg0);
5843
5988
  return addHeapObject(ret);
5844
5989
  };
5845
5990
 
5846
- export function __wbg_lorolist_new(arg0) {
5847
- const ret = LoroList.__wrap(arg0);
5991
+ export function __wbg_loromap_new(arg0) {
5992
+ const ret = LoroMap.__wrap(arg0);
5848
5993
  return addHeapObject(ret);
5849
5994
  };
5850
5995
 
5851
- export function __wbg_lorotree_new(arg0) {
5852
- const ret = LoroTree.__wrap(arg0);
5996
+ export function __wbg_lorotreenode_new(arg0) {
5997
+ const ret = LoroTreeNode.__wrap(arg0);
5853
5998
  return addHeapObject(ret);
5854
5999
  };
5855
6000
 
5856
- export function __wbg_cursor_new(arg0) {
5857
- const ret = Cursor.__wrap(arg0);
6001
+ export function __wbg_lorotree_new(arg0) {
6002
+ const ret = LoroTree.__wrap(arg0);
5858
6003
  return addHeapObject(ret);
5859
6004
  };
5860
6005
 
@@ -5863,13 +6008,13 @@ export function __wbg_loromovablelist_new(arg0) {
5863
6008
  return addHeapObject(ret);
5864
6009
  };
5865
6010
 
5866
- export function __wbg_lorocounter_new(arg0) {
5867
- const ret = LoroCounter.__wrap(arg0);
6011
+ export function __wbg_cursor_new(arg0) {
6012
+ const ret = Cursor.__wrap(arg0);
5868
6013
  return addHeapObject(ret);
5869
6014
  };
5870
6015
 
5871
- export function __wbg_lorotreenode_new(arg0) {
5872
- const ret = LoroTreeNode.__wrap(arg0);
6016
+ export function __wbg_lorotext_new(arg0) {
6017
+ const ret = LoroText.__wrap(arg0);
5873
6018
  return addHeapObject(ret);
5874
6019
  };
5875
6020
 
@@ -5986,6 +6131,11 @@ export function __wbindgen_number_new(arg0) {
5986
6131
  return addHeapObject(ret);
5987
6132
  };
5988
6133
 
6134
+ export function __wbindgen_is_array(arg0) {
6135
+ const ret = Array.isArray(getObject(arg0));
6136
+ return ret;
6137
+ };
6138
+
5989
6139
  export function __wbindgen_typeof(arg0) {
5990
6140
  const ret = typeof getObject(arg0);
5991
6141
  return addHeapObject(ret);
@@ -6096,7 +6246,7 @@ export function __wbg_error_f851667af71bcfc6(arg0, arg1) {
6096
6246
  }
6097
6247
  };
6098
6248
 
6099
- export const __wbg_now_11683c634f92ae89 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6249
+ export const __wbg_now_15d99db1ebc1f0b2 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6100
6250
 
6101
6251
  export function __wbg_crypto_1d1f22824a6a080c(arg0) {
6102
6252
  const ret = getObject(arg0).crypto;
@@ -6230,6 +6380,11 @@ export function __wbg_set_d4638f722068f043(arg0, arg1, arg2) {
6230
6380
  getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
6231
6381
  };
6232
6382
 
6383
+ export function __wbg_from_89e3fc3ba5e6fb48(arg0) {
6384
+ const ret = Array.from(getObject(arg0));
6385
+ return addHeapObject(ret);
6386
+ };
6387
+
6233
6388
  export function __wbg_isArray_2ab64d95e09ea0ae(arg0) {
6234
6389
  const ret = Array.isArray(getObject(arg0));
6235
6390
  return ret;
@@ -6415,13 +6570,13 @@ export function __wbindgen_memory() {
6415
6570
  return addHeapObject(ret);
6416
6571
  };
6417
6572
 
6418
- export function __wbindgen_closure_wrapper487(arg0, arg1, arg2) {
6419
- const ret = makeMutClosure(arg0, arg1, 9, __wbg_adapter_58);
6573
+ export function __wbindgen_closure_wrapper491(arg0, arg1, arg2) {
6574
+ const ret = makeMutClosure(arg0, arg1, 9, __wbg_adapter_60);
6420
6575
  return addHeapObject(ret);
6421
6576
  };
6422
6577
 
6423
- export function __wbindgen_closure_wrapper489(arg0, arg1, arg2) {
6424
- const ret = makeMutClosure(arg0, arg1, 11, __wbg_adapter_61);
6578
+ export function __wbindgen_closure_wrapper494(arg0, arg1, arg2) {
6579
+ const ret = makeMutClosure(arg0, arg1, 11, __wbg_adapter_63);
6425
6580
  return addHeapObject(ret);
6426
6581
  };
6427
6582
 
Binary file
@@ -44,6 +44,7 @@ export function lorodoc_fork(a: number): number;
44
44
  export function lorodoc_forkAt(a: number, b: number, c: number, d: number): void;
45
45
  export function lorodoc_checkoutToLatest(a: number, b: number): void;
46
46
  export function lorodoc_travelChangeAncestors(a: number, b: number, c: number, d: number, e: number): void;
47
+ export function lorodoc_findIdSpansBetween(a: number, b: number, c: number, d: number, e: number, f: number): void;
47
48
  export function lorodoc_checkout(a: number, b: number, c: number, d: number): void;
48
49
  export function lorodoc_peerId(a: number): number;
49
50
  export function lorodoc_peerIdStr(a: number): number;
@@ -73,7 +74,8 @@ export function lorodoc_cmpFrontiers(a: number, b: number, c: number, d: number,
73
74
  export function lorodoc_exportSnapshot(a: number, b: number): void;
74
75
  export function lorodoc_exportFrom(a: number, b: number, c: number): void;
75
76
  export function lorodoc_export(a: number, b: number, c: number): void;
76
- export function lorodoc_exportJsonUpdates(a: number, b: number, c: number, d: number): void;
77
+ export function lorodoc_exportJsonUpdates(a: number, b: number, c: number, d: number, e: number): void;
78
+ export function lorodoc_exportJsonInIdSpan(a: number, b: number, c: number): void;
77
79
  export function lorodoc_importJsonUpdates(a: number, b: number, c: number): void;
78
80
  export function lorodoc_import(a: number, b: number, c: number, d: number): void;
79
81
  export function lorodoc_importUpdateBatch(a: number, b: number, c: number): void;
@@ -94,6 +96,9 @@ export function lorodoc_vvToFrontiers(a: number, b: number, c: number): void;
94
96
  export function lorodoc_getByPath(a: number, b: number, c: number): number;
95
97
  export function lorodoc_getCursorPos(a: number, b: number, c: number): void;
96
98
  export function lorodoc_getChangedContainersIn(a: number, b: number, c: number, d: number): void;
99
+ export function lorodoc_revertTo(a: number, b: number, c: number, d: number): void;
100
+ export function lorodoc_applyDiff(a: number, b: number, c: number): void;
101
+ export function lorodoc_diff(a: number, b: number, c: number, d: number, e: number, f: number): void;
97
102
  export function __wbg_lorotext_free(a: number): void;
98
103
  export function lorotext_new(): number;
99
104
  export function lorotext_kind(a: number): number;