loro-crdt 1.4.0 → 1.4.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - e0948d8: feat: add container existence check methods & avoid panic in wasm/js #651
8
+ - 9955500: fix: an internal iter_change err that may cause fork_at panic #649
9
+
10
+ ## 1.4.1
11
+
12
+ ### Patch Changes
13
+
14
+ - 9090c4d: fix: memory leak issue
15
+
3
16
  ## 1.4.0
4
17
 
5
18
  ### Minor Changes
package/base64/index.js CHANGED
@@ -1457,6 +1457,8 @@ class LoroDoc {
1457
1457
  * The object returned is a new js object each time because it need to cross
1458
1458
  * the WASM boundary.
1459
1459
  *
1460
+ * If the container does not exist, an error will be thrown.
1461
+ *
1460
1462
  * @example
1461
1463
  * ```ts
1462
1464
  * import { LoroDoc } from "loro-crdt";
@@ -1489,6 +1491,8 @@ class LoroDoc {
1489
1491
  * The object returned is a new js object each time because it need to cross
1490
1492
  * the WASM boundary.
1491
1493
  *
1494
+ * If the container does not exist, an error will be thrown.
1495
+ *
1492
1496
  * @example
1493
1497
  * ```ts
1494
1498
  * import { LoroDoc } from "loro-crdt";
@@ -1521,6 +1525,8 @@ class LoroDoc {
1521
1525
  * The object returned is a new js object each time because it need to cross
1522
1526
  * the WASM boundary.
1523
1527
  *
1528
+ * If the container does not exist, an error will be thrown.
1529
+ *
1524
1530
  * @example
1525
1531
  * ```ts
1526
1532
  * import { LoroDoc } from "loro-crdt";
@@ -1553,6 +1559,8 @@ class LoroDoc {
1553
1559
  * The object returned is a new js object each time because it need to cross
1554
1560
  * the WASM boundary.
1555
1561
  *
1562
+ * If the container does not exist, an error will be thrown.
1563
+ *
1556
1564
  * @example
1557
1565
  * ```ts
1558
1566
  * import { LoroDoc } from "loro-crdt";
@@ -1581,6 +1589,8 @@ class LoroDoc {
1581
1589
  }
1582
1590
  /**
1583
1591
  * Get a LoroCounter by container id
1592
+ *
1593
+ * If the container does not exist, an error will be thrown.
1584
1594
  * @param {ContainerID | string} cid
1585
1595
  * @returns {LoroCounter}
1586
1596
  */
@@ -1606,6 +1616,8 @@ class LoroDoc {
1606
1616
  * The object returned is a new js object each time because it need to cross
1607
1617
  * the WASM boundary.
1608
1618
  *
1619
+ * If the container does not exist, an error will be thrown.
1620
+ *
1609
1621
  * @example
1610
1622
  * ```ts
1611
1623
  * import { LoroDoc } from "loro-crdt";
@@ -1633,8 +1645,42 @@ class LoroDoc {
1633
1645
  }
1634
1646
  }
1635
1647
  /**
1636
- * Get the container corresponding to the container id
1648
+ * Check if the doc contains the target container.
1649
+ *
1650
+ * A root container always exists, while a normal container exists
1651
+ * if it has ever been created on the doc.
1652
+ *
1653
+ * @example
1654
+ * ```ts
1655
+ * import { LoroDoc, LoroMap, LoroText, LoroList } from "loro-crdt";
1656
+ *
1657
+ * const doc = new LoroDoc();
1658
+ * doc.setPeerId("1");
1659
+ * const text = doc.getMap("map").setContainer("text", new LoroText());
1660
+ * const list = doc.getMap("map").setContainer("list", new LoroList());
1661
+ * expect(doc.isContainerExists("cid:root-map:Map")).toBe(true);
1662
+ * expect(doc.isContainerExists("cid:0@1:Text")).toBe(true);
1663
+ * expect(doc.isContainerExists("cid:1@1:List")).toBe(true);
1664
+ *
1665
+ * const doc2 = new LoroDoc();
1666
+ * // Containers exist, as long as the history or the doc state include it
1667
+ * doc.detach();
1668
+ * doc2.import(doc.export({ mode: "update" }));
1669
+ * expect(doc2.isContainerExists("cid:root-map:Map")).toBe(true);
1670
+ * expect(doc2.isContainerExists("cid:0@1:Text")).toBe(true);
1671
+ * expect(doc2.isContainerExists("cid:1@1:List")).toBe(true);
1672
+ * ```
1673
+ * @param {ContainerID} container_id
1674
+ * @returns {boolean}
1675
+ */
1676
+ hasContainer(container_id) {
1677
+ const ret = wasm.lorodoc_hasContainer(this.__wbg_ptr, addHeapObject(container_id));
1678
+ return ret !== 0;
1679
+ }
1680
+ /**
1681
+ * Get the container corresponding to the container id.
1637
1682
  *
1683
+ * If the container does not exist, it returns `undefined`.
1638
1684
  *
1639
1685
  * @example
1640
1686
  * ```ts
@@ -6012,36 +6058,36 @@ class VersionVector {
6012
6058
  function __wbindgen_object_drop_ref(arg0) {
6013
6059
  takeObject(arg0);
6014
6060
  }
6061
+ function __wbg_lorocounter_new(arg0) {
6062
+ const ret = LoroCounter.__wrap(arg0);
6063
+ return addHeapObject(ret);
6064
+ }
6015
6065
  function __wbg_lorotreenode_new(arg0) {
6016
6066
  const ret = LoroTreeNode.__wrap(arg0);
6017
6067
  return addHeapObject(ret);
6018
6068
  }
6019
- function __wbg_lorotree_new(arg0) {
6020
- const ret = LoroTree.__wrap(arg0);
6069
+ function __wbg_cursor_new(arg0) {
6070
+ const ret = Cursor.__wrap(arg0);
6021
6071
  return addHeapObject(ret);
6022
6072
  }
6023
- function __wbg_lorolist_new(arg0) {
6024
- const ret = LoroList.__wrap(arg0);
6073
+ function __wbg_loromap_new(arg0) {
6074
+ const ret = LoroMap.__wrap(arg0);
6025
6075
  return addHeapObject(ret);
6026
6076
  }
6027
- function __wbg_lorocounter_new(arg0) {
6028
- const ret = LoroCounter.__wrap(arg0);
6077
+ function __wbg_lorotext_new(arg0) {
6078
+ const ret = LoroText.__wrap(arg0);
6029
6079
  return addHeapObject(ret);
6030
6080
  }
6031
- function __wbg_loromap_new(arg0) {
6032
- const ret = LoroMap.__wrap(arg0);
6081
+ function __wbg_lorotree_new(arg0) {
6082
+ const ret = LoroTree.__wrap(arg0);
6033
6083
  return addHeapObject(ret);
6034
6084
  }
6035
6085
  function __wbg_loromovablelist_new(arg0) {
6036
6086
  const ret = LoroMovableList.__wrap(arg0);
6037
6087
  return addHeapObject(ret);
6038
6088
  }
6039
- function __wbg_lorotext_new(arg0) {
6040
- const ret = LoroText.__wrap(arg0);
6041
- return addHeapObject(ret);
6042
- }
6043
- function __wbg_cursor_new(arg0) {
6044
- const ret = Cursor.__wrap(arg0);
6089
+ function __wbg_lorolist_new(arg0) {
6090
+ const ret = LoroList.__wrap(arg0);
6045
6091
  return addHeapObject(ret);
6046
6092
  }
6047
6093
  function __wbg_versionvector_new(arg0) {
@@ -6236,7 +6282,7 @@ function __wbg_error_f851667af71bcfc6(arg0, arg1) {
6236
6282
  wasm.__wbindgen_export_5(deferred0_0, deferred0_1, 1);
6237
6283
  }
6238
6284
  }
6239
- const __wbg_now_bc6f749123583eb9 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6285
+ const __wbg_now_cd30a09c9b727b65 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6240
6286
 
6241
6287
  function __wbg_crypto_1d1f22824a6a080c(arg0) {
6242
6288
  const ret = getObject(arg0).crypto;
@@ -6501,11 +6547,11 @@ function __wbindgen_memory() {
6501
6547
  return addHeapObject(ret);
6502
6548
  }
6503
6549
  function __wbindgen_closure_wrapper482(arg0, arg1, arg2) {
6504
- const ret = makeMutClosure(arg0, arg1, 10, __wbg_adapter_60);
6550
+ const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_60);
6505
6551
  return addHeapObject(ret);
6506
6552
  }
6507
6553
  function __wbindgen_closure_wrapper485(arg0, arg1, arg2) {
6508
- const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_63);
6554
+ const ret = makeMutClosure(arg0, arg1, 10, __wbg_adapter_63);
6509
6555
  return addHeapObject(ret);
6510
6556
  }
6511
6557
 
@@ -6579,7 +6625,7 @@ var imports = /*#__PURE__*/Object.freeze({
6579
6625
  __wbg_next_196c84450b364254: __wbg_next_196c84450b364254,
6580
6626
  __wbg_next_40fc327bfc8770e6: __wbg_next_40fc327bfc8770e6,
6581
6627
  __wbg_node_104a2ff8d6ea03a2: __wbg_node_104a2ff8d6ea03a2,
6582
- __wbg_now_bc6f749123583eb9: __wbg_now_bc6f749123583eb9,
6628
+ __wbg_now_cd30a09c9b727b65: __wbg_now_cd30a09c9b727b65,
6583
6629
  __wbg_ownKeys_658942b7f28d1fe9: __wbg_ownKeys_658942b7f28d1fe9,
6584
6630
  __wbg_process_4a72847cc503995b: __wbg_process_4a72847cc503995b,
6585
6631
  __wbg_push_a5b05aedc7234f9f: __wbg_push_a5b05aedc7234f9f,
@@ -6643,7 +6689,7 @@ var imports = /*#__PURE__*/Object.freeze({
6643
6689
  // Without this patch, Cloudflare Worker would raise issue like: "Uncaught TypeError: wasm2.__wbindgen_start is not a function"
6644
6690
 
6645
6691
 
6646
- import loro_wasm_bg_js from './loro_wasm_bg-9c66a53e.js';
6692
+ import loro_wasm_bg_js from './loro_wasm_bg-b04f3476.js';
6647
6693
  const instance = new WebAssembly.Instance(loro_wasm_bg_js(), {
6648
6694
  "./loro_wasm_bg.js": imports,
6649
6695
  });
@@ -6848,4 +6894,4 @@ LoroDoc.prototype.toJsonWithReplacer = function (replacer) {
6848
6894
  return run(layer);
6849
6895
  };
6850
6896
 
6851
- export { Awareness, AwarenessWasm, Cursor, Loro, LoroCounter, LoroDoc, LoroList, LoroMap, LoroMovableList, LoroText, LoroTree, LoroTreeNode, UndoManager, VersionVector, __wbg_String_b9412f8799faab3e, __wbg_apply_0a5aa603881e6d79, __wbg_buffer_12d079cc21e14bdb, __wbg_call_27c0f87801dedf93, __wbg_call_8e7cb608789c2528, __wbg_call_938992c832f74314, __wbg_call_b3ca7c6051f9bec1, __wbg_crypto_1d1f22824a6a080c, __wbg_cursor_new, __wbg_done_298b57d23c0fc80c, __wbg_entries_95cc2c823b285a09, __wbg_entries_ce844941d0c51880, __wbg_error_9384d761bf46409d, __wbg_error_f851667af71bcfc6, __wbg_from_89e3fc3ba5e6fb48, __wbg_getRandomValues_3aa56aa6edec874c, __wbg_get_bd8e338fbd5f5cc8, __wbg_get_e3c254076557e348, __wbg_getindex_03d06b4e7ea3475e, __wbg_getwithrefkey_edc2c8960f0f1191, __wbg_globalThis_d1e6af4856ba331b, __wbg_global_207b558942527489, __wbg_instanceof_ArrayBuffer_836825be07d4c9d2, __wbg_instanceof_Map_87917e0a7aaf4012, __wbg_instanceof_Object_71ca3c0a59266746, __wbg_instanceof_Uint8Array_2b3bbecd033d19f6, __wbg_isArray_2ab64d95e09ea0ae, __wbg_isSafeInteger_f7b04ef02296c4d2, __wbg_iterator_2cee6dadfd956dfa, __wbg_length_c20a40f15020d68a, __wbg_length_cd7af8117672b8b8, __wbg_log_aba5996d9bde071f, __wbg_log_c86c3e1bf097ba35, __wbg_log_c9486ca5d8e2cbe8, __wbg_lorocounter_new, __wbg_lorolist_new, __wbg_loromap_new, __wbg_loromovablelist_new, __wbg_lorotext_new, __wbg_lorotree_new, __wbg_lorotreenode_new, __wbg_mark_40e050a77cc39fea, __wbg_measure_aa7a73f17813f708, __wbg_msCrypto_eb05e62b530a1508, __wbg_new_16b304a2cfa7ff4a, __wbg_new_63b92bc8671ed464, __wbg_new_72fb9a18b5ae2624, __wbg_new_abda76e883ba8a5f, __wbg_new_d9bc3a0147634640, __wbg_newnoargs_e258087cd0daa0ea, __wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb, __wbg_newwithlength_66ae46612e7f0234, __wbg_newwithlength_e9b4878cebadb3d3, __wbg_next_196c84450b364254, __wbg_next_40fc327bfc8770e6, __wbg_node_104a2ff8d6ea03a2, __wbg_now_bc6f749123583eb9, __wbg_ownKeys_658942b7f28d1fe9, __wbg_process_4a72847cc503995b, __wbg_push_a5b05aedc7234f9f, __wbg_randomFillSync_5c9c955aa56b6049, __wbg_require_cca90b1a94a0255b, __wbg_resolve_b0083a7967828ec8, __wbg_self_ce0dbfc45cf2f5be, __wbg_set_1f9b04f170055d33, __wbg_set_8417257aaedc936b, __wbg_set_a47bac70306a19a7, __wbg_set_d4638f722068f043, __wbg_set_f975102236d3c502, __wbg_set_wasm, __wbg_setindex_0b7ede192dc5eca8, __wbg_stack_658279fe44541cf6, __wbg_subarray_a1f73cd4b5b42fe1, __wbg_then_0c86a60e8fcfe9f6, __wbg_value_d93c65011f51a456, __wbg_versions_f686565e586dd935, __wbg_versionvector_new, __wbg_window_c6fb939a7f436783, __wbindgen_as_number, __wbindgen_bigint_from_i64, __wbindgen_bigint_from_u64, __wbindgen_bigint_get_as_i64, __wbindgen_boolean_get, __wbindgen_cb_drop, __wbindgen_closure_wrapper482, __wbindgen_closure_wrapper485, __wbindgen_debug_string, __wbindgen_error_new, __wbindgen_in, __wbindgen_is_array, __wbindgen_is_bigint, __wbindgen_is_falsy, __wbindgen_is_function, __wbindgen_is_null, __wbindgen_is_object, __wbindgen_is_string, __wbindgen_is_undefined, __wbindgen_jsval_eq, __wbindgen_jsval_loose_eq, __wbindgen_memory, __wbindgen_number_get, __wbindgen_number_new, __wbindgen_object_clone_ref, __wbindgen_object_drop_ref, __wbindgen_rethrow, __wbindgen_string_get, __wbindgen_string_new, __wbindgen_throw, __wbindgen_typeof, decodeFrontiers, decodeImportBlobMeta, encodeFrontiers, getType, isContainer, isContainerId, newContainerID, newRootContainerID, run, setDebug };
6897
+ export { Awareness, AwarenessWasm, Cursor, Loro, LoroCounter, LoroDoc, LoroList, LoroMap, LoroMovableList, LoroText, LoroTree, LoroTreeNode, UndoManager, VersionVector, __wbg_String_b9412f8799faab3e, __wbg_apply_0a5aa603881e6d79, __wbg_buffer_12d079cc21e14bdb, __wbg_call_27c0f87801dedf93, __wbg_call_8e7cb608789c2528, __wbg_call_938992c832f74314, __wbg_call_b3ca7c6051f9bec1, __wbg_crypto_1d1f22824a6a080c, __wbg_cursor_new, __wbg_done_298b57d23c0fc80c, __wbg_entries_95cc2c823b285a09, __wbg_entries_ce844941d0c51880, __wbg_error_9384d761bf46409d, __wbg_error_f851667af71bcfc6, __wbg_from_89e3fc3ba5e6fb48, __wbg_getRandomValues_3aa56aa6edec874c, __wbg_get_bd8e338fbd5f5cc8, __wbg_get_e3c254076557e348, __wbg_getindex_03d06b4e7ea3475e, __wbg_getwithrefkey_edc2c8960f0f1191, __wbg_globalThis_d1e6af4856ba331b, __wbg_global_207b558942527489, __wbg_instanceof_ArrayBuffer_836825be07d4c9d2, __wbg_instanceof_Map_87917e0a7aaf4012, __wbg_instanceof_Object_71ca3c0a59266746, __wbg_instanceof_Uint8Array_2b3bbecd033d19f6, __wbg_isArray_2ab64d95e09ea0ae, __wbg_isSafeInteger_f7b04ef02296c4d2, __wbg_iterator_2cee6dadfd956dfa, __wbg_length_c20a40f15020d68a, __wbg_length_cd7af8117672b8b8, __wbg_log_aba5996d9bde071f, __wbg_log_c86c3e1bf097ba35, __wbg_log_c9486ca5d8e2cbe8, __wbg_lorocounter_new, __wbg_lorolist_new, __wbg_loromap_new, __wbg_loromovablelist_new, __wbg_lorotext_new, __wbg_lorotree_new, __wbg_lorotreenode_new, __wbg_mark_40e050a77cc39fea, __wbg_measure_aa7a73f17813f708, __wbg_msCrypto_eb05e62b530a1508, __wbg_new_16b304a2cfa7ff4a, __wbg_new_63b92bc8671ed464, __wbg_new_72fb9a18b5ae2624, __wbg_new_abda76e883ba8a5f, __wbg_new_d9bc3a0147634640, __wbg_newnoargs_e258087cd0daa0ea, __wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb, __wbg_newwithlength_66ae46612e7f0234, __wbg_newwithlength_e9b4878cebadb3d3, __wbg_next_196c84450b364254, __wbg_next_40fc327bfc8770e6, __wbg_node_104a2ff8d6ea03a2, __wbg_now_cd30a09c9b727b65, __wbg_ownKeys_658942b7f28d1fe9, __wbg_process_4a72847cc503995b, __wbg_push_a5b05aedc7234f9f, __wbg_randomFillSync_5c9c955aa56b6049, __wbg_require_cca90b1a94a0255b, __wbg_resolve_b0083a7967828ec8, __wbg_self_ce0dbfc45cf2f5be, __wbg_set_1f9b04f170055d33, __wbg_set_8417257aaedc936b, __wbg_set_a47bac70306a19a7, __wbg_set_d4638f722068f043, __wbg_set_f975102236d3c502, __wbg_set_wasm, __wbg_setindex_0b7ede192dc5eca8, __wbg_stack_658279fe44541cf6, __wbg_subarray_a1f73cd4b5b42fe1, __wbg_then_0c86a60e8fcfe9f6, __wbg_value_d93c65011f51a456, __wbg_versions_f686565e586dd935, __wbg_versionvector_new, __wbg_window_c6fb939a7f436783, __wbindgen_as_number, __wbindgen_bigint_from_i64, __wbindgen_bigint_from_u64, __wbindgen_bigint_get_as_i64, __wbindgen_boolean_get, __wbindgen_cb_drop, __wbindgen_closure_wrapper482, __wbindgen_closure_wrapper485, __wbindgen_debug_string, __wbindgen_error_new, __wbindgen_in, __wbindgen_is_array, __wbindgen_is_bigint, __wbindgen_is_falsy, __wbindgen_is_function, __wbindgen_is_null, __wbindgen_is_object, __wbindgen_is_string, __wbindgen_is_undefined, __wbindgen_jsval_eq, __wbindgen_jsval_loose_eq, __wbindgen_memory, __wbindgen_number_get, __wbindgen_number_new, __wbindgen_object_clone_ref, __wbindgen_object_drop_ref, __wbindgen_rethrow, __wbindgen_string_get, __wbindgen_string_new, __wbindgen_throw, __wbindgen_typeof, decodeFrontiers, decodeImportBlobMeta, encodeFrontiers, getType, isContainer, isContainerId, newContainerID, newRootContainerID, run, setDebug };
@@ -109,7 +109,7 @@ interface LoroDoc {
109
109
  * text = doc.getContainerById(textId);
110
110
  * ```
111
111
  */
112
- getContainerById(id: ContainerID): Container;
112
+ getContainerById(id: ContainerID): Container | undefined;
113
113
 
114
114
  /**
115
115
  * Subscribe to updates from local edits.
@@ -1859,6 +1859,8 @@ export class LoroDoc {
1859
1859
  * The object returned is a new js object each time because it need to cross
1860
1860
  * the WASM boundary.
1861
1861
  *
1862
+ * If the container does not exist, an error will be thrown.
1863
+ *
1862
1864
  * @example
1863
1865
  * ```ts
1864
1866
  * import { LoroDoc } from "loro-crdt";
@@ -1872,11 +1874,43 @@ export class LoroDoc {
1872
1874
  getText(cid: ContainerID | string): LoroText;
1873
1875
  /**
1874
1876
  * Get a LoroCounter by container id
1877
+ *
1878
+ * If the container does not exist, an error will be thrown.
1875
1879
  * @param {ContainerID | string} cid
1876
1880
  * @returns {LoroCounter}
1877
1881
  */
1878
1882
  getCounter(cid: ContainerID | string): LoroCounter;
1879
1883
  /**
1884
+ * Check if the doc contains the target container.
1885
+ *
1886
+ * A root container always exists, while a normal container exists
1887
+ * if it has ever been created on the doc.
1888
+ *
1889
+ * @example
1890
+ * ```ts
1891
+ * import { LoroDoc, LoroMap, LoroText, LoroList } from "loro-crdt";
1892
+ *
1893
+ * const doc = new LoroDoc();
1894
+ * doc.setPeerId("1");
1895
+ * const text = doc.getMap("map").setContainer("text", new LoroText());
1896
+ * const list = doc.getMap("map").setContainer("list", new LoroList());
1897
+ * expect(doc.isContainerExists("cid:root-map:Map")).toBe(true);
1898
+ * expect(doc.isContainerExists("cid:0@1:Text")).toBe(true);
1899
+ * expect(doc.isContainerExists("cid:1@1:List")).toBe(true);
1900
+ *
1901
+ * const doc2 = new LoroDoc();
1902
+ * // Containers exist, as long as the history or the doc state include it
1903
+ * doc.detach();
1904
+ * doc2.import(doc.export({ mode: "update" }));
1905
+ * expect(doc2.isContainerExists("cid:root-map:Map")).toBe(true);
1906
+ * expect(doc2.isContainerExists("cid:0@1:Text")).toBe(true);
1907
+ * expect(doc2.isContainerExists("cid:1@1:List")).toBe(true);
1908
+ * ```
1909
+ * @param {ContainerID} container_id
1910
+ * @returns {boolean}
1911
+ */
1912
+ hasContainer(container_id: ContainerID): boolean;
1913
+ /**
1880
1914
  * Set the commit message of the next commit
1881
1915
  * @param {string} msg
1882
1916
  */