loro-crdt 1.4.1 → 1.4.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.
@@ -1,6 +1,11 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
+ * Get the version of Loro
5
+ * @returns {string}
6
+ */
7
+ export function LORO_VERSION(): string;
8
+ /**
4
9
  */
5
10
  export function run(): void;
6
11
  /**
@@ -109,7 +114,7 @@ interface LoroDoc {
109
114
  * text = doc.getContainerById(textId);
110
115
  * ```
111
116
  */
112
- getContainerById(id: ContainerID): Container;
117
+ getContainerById(id: ContainerID): Container | undefined;
113
118
 
114
119
  /**
115
120
  * Subscribe to updates from local edits.
@@ -1859,6 +1864,8 @@ export class LoroDoc {
1859
1864
  * The object returned is a new js object each time because it need to cross
1860
1865
  * the WASM boundary.
1861
1866
  *
1867
+ * If the container does not exist, an error will be thrown.
1868
+ *
1862
1869
  * @example
1863
1870
  * ```ts
1864
1871
  * import { LoroDoc } from "loro-crdt";
@@ -1872,16 +1879,67 @@ export class LoroDoc {
1872
1879
  getText(cid: ContainerID | string): LoroText;
1873
1880
  /**
1874
1881
  * Get a LoroCounter by container id
1882
+ *
1883
+ * If the container does not exist, an error will be thrown.
1875
1884
  * @param {ContainerID | string} cid
1876
1885
  * @returns {LoroCounter}
1877
1886
  */
1878
1887
  getCounter(cid: ContainerID | string): LoroCounter;
1879
1888
  /**
1889
+ * Check if the doc contains the target container.
1890
+ *
1891
+ * A root container always exists, while a normal container exists
1892
+ * if it has ever been created on the doc.
1893
+ *
1894
+ * @example
1895
+ * ```ts
1896
+ * import { LoroDoc, LoroMap, LoroText, LoroList } from "loro-crdt";
1897
+ *
1898
+ * const doc = new LoroDoc();
1899
+ * doc.setPeerId("1");
1900
+ * const text = doc.getMap("map").setContainer("text", new LoroText());
1901
+ * const list = doc.getMap("map").setContainer("list", new LoroList());
1902
+ * expect(doc.isContainerExists("cid:root-map:Map")).toBe(true);
1903
+ * expect(doc.isContainerExists("cid:0@1:Text")).toBe(true);
1904
+ * expect(doc.isContainerExists("cid:1@1:List")).toBe(true);
1905
+ *
1906
+ * const doc2 = new LoroDoc();
1907
+ * // Containers exist, as long as the history or the doc state include it
1908
+ * doc.detach();
1909
+ * doc2.import(doc.export({ mode: "update" }));
1910
+ * expect(doc2.isContainerExists("cid:root-map:Map")).toBe(true);
1911
+ * expect(doc2.isContainerExists("cid:0@1:Text")).toBe(true);
1912
+ * expect(doc2.isContainerExists("cid:1@1:List")).toBe(true);
1913
+ * ```
1914
+ * @param {ContainerID} container_id
1915
+ * @returns {boolean}
1916
+ */
1917
+ hasContainer(container_id: ContainerID): boolean;
1918
+ /**
1880
1919
  * Set the commit message of the next commit
1881
1920
  * @param {string} msg
1882
1921
  */
1883
1922
  setNextCommitMessage(msg: string): void;
1884
1923
  /**
1924
+ * Set the origin of the next commit
1925
+ * @param {string} origin
1926
+ */
1927
+ setNextCommitOrigin(origin: string): void;
1928
+ /**
1929
+ * Set the timestamp of the next commit
1930
+ * @param {number} timestamp
1931
+ */
1932
+ setNextCommitTimestamp(timestamp: number): void;
1933
+ /**
1934
+ * Set the options of the next commit
1935
+ * @param {{ origin?: string, timestamp?: number, message?: string }} options
1936
+ */
1937
+ setNextCommitOptions(options: { origin?: string, timestamp?: number, message?: string }): void;
1938
+ /**
1939
+ * Clear the options of the next commit
1940
+ */
1941
+ clearNextCommitOptions(): void;
1942
+ /**
1885
1943
  * Get deep value of the document with container id
1886
1944
  * @returns {any}
1887
1945
  */
@@ -276,6 +276,27 @@ function getArrayJsValueFromWasm0(ptr, len) {
276
276
  }
277
277
  return result;
278
278
  }
279
+ /**
280
+ * Get the version of Loro
281
+ * @returns {string}
282
+ */
283
+ export function LORO_VERSION() {
284
+ let deferred1_0;
285
+ let deferred1_1;
286
+ try {
287
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
288
+ wasm.LORO_VERSION(retptr);
289
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
290
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
291
+ deferred1_0 = r0;
292
+ deferred1_1 = r1;
293
+ return getStringFromWasm0(r0, r1);
294
+ } finally {
295
+ wasm.__wbindgen_add_to_stack_pointer(16);
296
+ wasm.__wbindgen_export_5(deferred1_0, deferred1_1, 1);
297
+ }
298
+ }
299
+
279
300
  /**
280
301
  */
281
302
  export function run() {
@@ -1457,6 +1478,8 @@ export class LoroDoc {
1457
1478
  * The object returned is a new js object each time because it need to cross
1458
1479
  * the WASM boundary.
1459
1480
  *
1481
+ * If the container does not exist, an error will be thrown.
1482
+ *
1460
1483
  * @example
1461
1484
  * ```ts
1462
1485
  * import { LoroDoc } from "loro-crdt";
@@ -1489,6 +1512,8 @@ export class LoroDoc {
1489
1512
  * The object returned is a new js object each time because it need to cross
1490
1513
  * the WASM boundary.
1491
1514
  *
1515
+ * If the container does not exist, an error will be thrown.
1516
+ *
1492
1517
  * @example
1493
1518
  * ```ts
1494
1519
  * import { LoroDoc } from "loro-crdt";
@@ -1521,6 +1546,8 @@ export class LoroDoc {
1521
1546
  * The object returned is a new js object each time because it need to cross
1522
1547
  * the WASM boundary.
1523
1548
  *
1549
+ * If the container does not exist, an error will be thrown.
1550
+ *
1524
1551
  * @example
1525
1552
  * ```ts
1526
1553
  * import { LoroDoc } from "loro-crdt";
@@ -1553,6 +1580,8 @@ export class LoroDoc {
1553
1580
  * The object returned is a new js object each time because it need to cross
1554
1581
  * the WASM boundary.
1555
1582
  *
1583
+ * If the container does not exist, an error will be thrown.
1584
+ *
1556
1585
  * @example
1557
1586
  * ```ts
1558
1587
  * import { LoroDoc } from "loro-crdt";
@@ -1581,6 +1610,8 @@ export class LoroDoc {
1581
1610
  }
1582
1611
  /**
1583
1612
  * Get a LoroCounter by container id
1613
+ *
1614
+ * If the container does not exist, an error will be thrown.
1584
1615
  * @param {ContainerID | string} cid
1585
1616
  * @returns {LoroCounter}
1586
1617
  */
@@ -1606,6 +1637,8 @@ export class LoroDoc {
1606
1637
  * The object returned is a new js object each time because it need to cross
1607
1638
  * the WASM boundary.
1608
1639
  *
1640
+ * If the container does not exist, an error will be thrown.
1641
+ *
1609
1642
  * @example
1610
1643
  * ```ts
1611
1644
  * import { LoroDoc } from "loro-crdt";
@@ -1633,8 +1666,42 @@ export class LoroDoc {
1633
1666
  }
1634
1667
  }
1635
1668
  /**
1636
- * Get the container corresponding to the container id
1669
+ * Check if the doc contains the target container.
1637
1670
  *
1671
+ * A root container always exists, while a normal container exists
1672
+ * if it has ever been created on the doc.
1673
+ *
1674
+ * @example
1675
+ * ```ts
1676
+ * import { LoroDoc, LoroMap, LoroText, LoroList } from "loro-crdt";
1677
+ *
1678
+ * const doc = new LoroDoc();
1679
+ * doc.setPeerId("1");
1680
+ * const text = doc.getMap("map").setContainer("text", new LoroText());
1681
+ * const list = doc.getMap("map").setContainer("list", new LoroList());
1682
+ * expect(doc.isContainerExists("cid:root-map:Map")).toBe(true);
1683
+ * expect(doc.isContainerExists("cid:0@1:Text")).toBe(true);
1684
+ * expect(doc.isContainerExists("cid:1@1:List")).toBe(true);
1685
+ *
1686
+ * const doc2 = new LoroDoc();
1687
+ * // Containers exist, as long as the history or the doc state include it
1688
+ * doc.detach();
1689
+ * doc2.import(doc.export({ mode: "update" }));
1690
+ * expect(doc2.isContainerExists("cid:root-map:Map")).toBe(true);
1691
+ * expect(doc2.isContainerExists("cid:0@1:Text")).toBe(true);
1692
+ * expect(doc2.isContainerExists("cid:1@1:List")).toBe(true);
1693
+ * ```
1694
+ * @param {ContainerID} container_id
1695
+ * @returns {boolean}
1696
+ */
1697
+ hasContainer(container_id) {
1698
+ const ret = wasm.lorodoc_hasContainer(this.__wbg_ptr, addHeapObject(container_id));
1699
+ return ret !== 0;
1700
+ }
1701
+ /**
1702
+ * Get the container corresponding to the container id.
1703
+ *
1704
+ * If the container does not exist, it returns `undefined`.
1638
1705
  *
1639
1706
  * @example
1640
1707
  * ```ts
@@ -1673,6 +1740,45 @@ export class LoroDoc {
1673
1740
  wasm.lorodoc_setNextCommitMessage(this.__wbg_ptr, ptr0, len0);
1674
1741
  }
1675
1742
  /**
1743
+ * Set the origin of the next commit
1744
+ * @param {string} origin
1745
+ */
1746
+ setNextCommitOrigin(origin) {
1747
+ const ptr0 = passStringToWasm0(origin, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
1748
+ const len0 = WASM_VECTOR_LEN;
1749
+ wasm.lorodoc_setNextCommitOrigin(this.__wbg_ptr, ptr0, len0);
1750
+ }
1751
+ /**
1752
+ * Set the timestamp of the next commit
1753
+ * @param {number} timestamp
1754
+ */
1755
+ setNextCommitTimestamp(timestamp) {
1756
+ wasm.lorodoc_setNextCommitTimestamp(this.__wbg_ptr, timestamp);
1757
+ }
1758
+ /**
1759
+ * Set the options of the next commit
1760
+ * @param {{ origin?: string, timestamp?: number, message?: string }} options
1761
+ */
1762
+ setNextCommitOptions(options) {
1763
+ try {
1764
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1765
+ wasm.lorodoc_setNextCommitOptions(retptr, this.__wbg_ptr, addHeapObject(options));
1766
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1767
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1768
+ if (r1) {
1769
+ throw takeObject(r0);
1770
+ }
1771
+ } finally {
1772
+ wasm.__wbindgen_add_to_stack_pointer(16);
1773
+ }
1774
+ }
1775
+ /**
1776
+ * Clear the options of the next commit
1777
+ */
1778
+ clearNextCommitOptions() {
1779
+ wasm.lorodoc_clearNextCommitOptions(this.__wbg_ptr);
1780
+ }
1781
+ /**
1676
1782
  * Get deep value of the document with container id
1677
1783
  * @returns {any}
1678
1784
  */
@@ -6013,28 +6119,33 @@ export function __wbindgen_object_drop_ref(arg0) {
6013
6119
  takeObject(arg0);
6014
6120
  };
6015
6121
 
6122
+ export function __wbg_lorocounter_new(arg0) {
6123
+ const ret = LoroCounter.__wrap(arg0);
6124
+ return addHeapObject(ret);
6125
+ };
6126
+
6016
6127
  export function __wbg_lorotreenode_new(arg0) {
6017
6128
  const ret = LoroTreeNode.__wrap(arg0);
6018
6129
  return addHeapObject(ret);
6019
6130
  };
6020
6131
 
6021
- export function __wbg_lorotree_new(arg0) {
6022
- const ret = LoroTree.__wrap(arg0);
6132
+ export function __wbg_cursor_new(arg0) {
6133
+ const ret = Cursor.__wrap(arg0);
6023
6134
  return addHeapObject(ret);
6024
6135
  };
6025
6136
 
6026
- export function __wbg_lorolist_new(arg0) {
6027
- const ret = LoroList.__wrap(arg0);
6137
+ export function __wbg_loromap_new(arg0) {
6138
+ const ret = LoroMap.__wrap(arg0);
6028
6139
  return addHeapObject(ret);
6029
6140
  };
6030
6141
 
6031
- export function __wbg_lorocounter_new(arg0) {
6032
- const ret = LoroCounter.__wrap(arg0);
6142
+ export function __wbg_lorotext_new(arg0) {
6143
+ const ret = LoroText.__wrap(arg0);
6033
6144
  return addHeapObject(ret);
6034
6145
  };
6035
6146
 
6036
- export function __wbg_loromap_new(arg0) {
6037
- const ret = LoroMap.__wrap(arg0);
6147
+ export function __wbg_lorotree_new(arg0) {
6148
+ const ret = LoroTree.__wrap(arg0);
6038
6149
  return addHeapObject(ret);
6039
6150
  };
6040
6151
 
@@ -6043,13 +6154,8 @@ export function __wbg_loromovablelist_new(arg0) {
6043
6154
  return addHeapObject(ret);
6044
6155
  };
6045
6156
 
6046
- export function __wbg_lorotext_new(arg0) {
6047
- const ret = LoroText.__wrap(arg0);
6048
- return addHeapObject(ret);
6049
- };
6050
-
6051
- export function __wbg_cursor_new(arg0) {
6052
- const ret = Cursor.__wrap(arg0);
6157
+ export function __wbg_lorolist_new(arg0) {
6158
+ const ret = LoroList.__wrap(arg0);
6053
6159
  return addHeapObject(ret);
6054
6160
  };
6055
6161
 
@@ -6281,7 +6387,7 @@ export function __wbg_error_f851667af71bcfc6(arg0, arg1) {
6281
6387
  }
6282
6388
  };
6283
6389
 
6284
- export const __wbg_now_bc6f749123583eb9 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6390
+ export const __wbg_now_cd30a09c9b727b65 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6285
6391
 
6286
6392
  export function __wbg_crypto_1d1f22824a6a080c(arg0) {
6287
6393
  const ret = getObject(arg0).crypto;
@@ -6606,12 +6712,12 @@ export function __wbindgen_memory() {
6606
6712
  };
6607
6713
 
6608
6714
  export function __wbindgen_closure_wrapper482(arg0, arg1, arg2) {
6609
- const ret = makeMutClosure(arg0, arg1, 10, __wbg_adapter_60);
6715
+ const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_60);
6610
6716
  return addHeapObject(ret);
6611
6717
  };
6612
6718
 
6613
6719
  export function __wbindgen_closure_wrapper485(arg0, arg1, arg2) {
6614
- const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_63);
6720
+ const ret = makeMutClosure(arg0, arg1, 10, __wbg_adapter_63);
6615
6721
  return addHeapObject(ret);
6616
6722
  };
6617
6723
 
Binary file
@@ -27,6 +27,7 @@ export function awarenesswasm_removeOutdated(a: number, b: number): void;
27
27
  export function awarenesswasm_length(a: number): number;
28
28
  export function awarenesswasm_isEmpty(a: number): number;
29
29
  export function awarenesswasm_peers(a: number, b: number): void;
30
+ export function LORO_VERSION(a: number): void;
30
31
  export function run(): void;
31
32
  export function encodeFrontiers(a: number, b: number, c: number): void;
32
33
  export function decodeFrontiers(a: number, b: number, c: number): void;
@@ -59,8 +60,13 @@ export function lorodoc_getList(a: number, b: number, c: number): void;
59
60
  export function lorodoc_getMovableList(a: number, b: number, c: number): void;
60
61
  export function lorodoc_getCounter(a: number, b: number, c: number): void;
61
62
  export function lorodoc_getTree(a: number, b: number, c: number): void;
63
+ export function lorodoc_hasContainer(a: number, b: number): number;
62
64
  export function lorodoc_getContainerById(a: number, b: number, c: number): void;
63
65
  export function lorodoc_setNextCommitMessage(a: number, b: number, c: number): void;
66
+ export function lorodoc_setNextCommitOrigin(a: number, b: number, c: number): void;
67
+ export function lorodoc_setNextCommitTimestamp(a: number, b: number): void;
68
+ export function lorodoc_setNextCommitOptions(a: number, b: number, c: number): void;
69
+ export function lorodoc_clearNextCommitOptions(a: number): void;
64
70
  export function lorodoc_getDeepValueWithID(a: number): number;
65
71
  export function lorodoc_getPathToContainer(a: number, b: number, c: number): void;
66
72
  export function lorodoc_JSONPath(a: number, b: number, c: number, d: number): void;
@@ -1,6 +1,11 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
+ * Get the version of Loro
5
+ * @returns {string}
6
+ */
7
+ export function LORO_VERSION(): string;
8
+ /**
4
9
  */
5
10
  export function run(): void;
6
11
  /**
@@ -109,7 +114,7 @@ interface LoroDoc {
109
114
  * text = doc.getContainerById(textId);
110
115
  * ```
111
116
  */
112
- getContainerById(id: ContainerID): Container;
117
+ getContainerById(id: ContainerID): Container | undefined;
113
118
 
114
119
  /**
115
120
  * Subscribe to updates from local edits.
@@ -1859,6 +1864,8 @@ export class LoroDoc {
1859
1864
  * The object returned is a new js object each time because it need to cross
1860
1865
  * the WASM boundary.
1861
1866
  *
1867
+ * If the container does not exist, an error will be thrown.
1868
+ *
1862
1869
  * @example
1863
1870
  * ```ts
1864
1871
  * import { LoroDoc } from "loro-crdt";
@@ -1872,16 +1879,67 @@ export class LoroDoc {
1872
1879
  getText(cid: ContainerID | string): LoroText;
1873
1880
  /**
1874
1881
  * Get a LoroCounter by container id
1882
+ *
1883
+ * If the container does not exist, an error will be thrown.
1875
1884
  * @param {ContainerID | string} cid
1876
1885
  * @returns {LoroCounter}
1877
1886
  */
1878
1887
  getCounter(cid: ContainerID | string): LoroCounter;
1879
1888
  /**
1889
+ * Check if the doc contains the target container.
1890
+ *
1891
+ * A root container always exists, while a normal container exists
1892
+ * if it has ever been created on the doc.
1893
+ *
1894
+ * @example
1895
+ * ```ts
1896
+ * import { LoroDoc, LoroMap, LoroText, LoroList } from "loro-crdt";
1897
+ *
1898
+ * const doc = new LoroDoc();
1899
+ * doc.setPeerId("1");
1900
+ * const text = doc.getMap("map").setContainer("text", new LoroText());
1901
+ * const list = doc.getMap("map").setContainer("list", new LoroList());
1902
+ * expect(doc.isContainerExists("cid:root-map:Map")).toBe(true);
1903
+ * expect(doc.isContainerExists("cid:0@1:Text")).toBe(true);
1904
+ * expect(doc.isContainerExists("cid:1@1:List")).toBe(true);
1905
+ *
1906
+ * const doc2 = new LoroDoc();
1907
+ * // Containers exist, as long as the history or the doc state include it
1908
+ * doc.detach();
1909
+ * doc2.import(doc.export({ mode: "update" }));
1910
+ * expect(doc2.isContainerExists("cid:root-map:Map")).toBe(true);
1911
+ * expect(doc2.isContainerExists("cid:0@1:Text")).toBe(true);
1912
+ * expect(doc2.isContainerExists("cid:1@1:List")).toBe(true);
1913
+ * ```
1914
+ * @param {ContainerID} container_id
1915
+ * @returns {boolean}
1916
+ */
1917
+ hasContainer(container_id: ContainerID): boolean;
1918
+ /**
1880
1919
  * Set the commit message of the next commit
1881
1920
  * @param {string} msg
1882
1921
  */
1883
1922
  setNextCommitMessage(msg: string): void;
1884
1923
  /**
1924
+ * Set the origin of the next commit
1925
+ * @param {string} origin
1926
+ */
1927
+ setNextCommitOrigin(origin: string): void;
1928
+ /**
1929
+ * Set the timestamp of the next commit
1930
+ * @param {number} timestamp
1931
+ */
1932
+ setNextCommitTimestamp(timestamp: number): void;
1933
+ /**
1934
+ * Set the options of the next commit
1935
+ * @param {{ origin?: string, timestamp?: number, message?: string }} options
1936
+ */
1937
+ setNextCommitOptions(options: { origin?: string, timestamp?: number, message?: string }): void;
1938
+ /**
1939
+ * Clear the options of the next commit
1940
+ */
1941
+ clearNextCommitOptions(): void;
1942
+ /**
1885
1943
  * Get deep value of the document with container id
1886
1944
  * @returns {any}
1887
1945
  */