loro-crdt 1.2.1 → 1.2.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/web/loro_wasm.js CHANGED
@@ -853,6 +853,14 @@ export class LoroCounter {
853
853
  const ret = wasm.lorocounter_getAttached(this.__wbg_ptr);
854
854
  return takeObject(ret);
855
855
  }
856
+ /**
857
+ * Get the value of the counter.
858
+ * @returns {number}
859
+ */
860
+ getShallowValue() {
861
+ const ret = wasm.lorocounter_getShallowValue(this.__wbg_ptr);
862
+ return ret;
863
+ }
856
864
  }
857
865
 
858
866
  const LoroDocFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -1979,10 +1987,12 @@ export class LoroDoc {
1979
1987
  }
1980
1988
  }
1981
1989
  /**
1982
- * Import a batch of updates.
1990
+ * Import a batch of updates and snapshots.
1983
1991
  *
1984
1992
  * It's more efficient than importing updates one by one.
1985
1993
  *
1994
+ * @deprecated Use `importBatch` instead.
1995
+ *
1986
1996
  * @example
1987
1997
  * ```ts
1988
1998
  * import { LoroDoc } from "loro-crdt";
@@ -1993,9 +2003,9 @@ export class LoroDoc {
1993
2003
  * const updates = doc.export({ mode: "update" });
1994
2004
  * const snapshot = doc.export({ mode: "snapshot" });
1995
2005
  * const doc2 = new LoroDoc();
1996
- * doc2.importUpdateBatch([snapshot, updates]);
2006
+ * doc2.importBatch([snapshot, updates]);
1997
2007
  * ```
1998
- * @param {Array<any>} data
2008
+ * @param {Uint8Array[]} data
1999
2009
  * @returns {ImportStatus}
2000
2010
  */
2001
2011
  importUpdateBatch(data) {
@@ -2014,8 +2024,46 @@ export class LoroDoc {
2014
2024
  }
2015
2025
  }
2016
2026
  /**
2027
+ * Import a batch of updates or snapshots.
2028
+ *
2029
+ * It's more efficient than importing updates one by one.
2030
+ *
2031
+ * @example
2032
+ * ```ts
2033
+ * import { LoroDoc } from "loro-crdt";
2034
+ *
2035
+ * const doc = new LoroDoc();
2036
+ * const text = doc.getText("text");
2037
+ * text.insert(0, "Hello");
2038
+ * const updates = doc.export({ mode: "update" });
2039
+ * const snapshot = doc.export({ mode: "snapshot" });
2040
+ * const doc2 = new LoroDoc();
2041
+ * doc2.importBatch([snapshot, updates]);
2042
+ * ```
2043
+ * @param {Uint8Array[]} data
2044
+ * @returns {ImportStatus}
2045
+ */
2046
+ importBatch(data) {
2047
+ try {
2048
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2049
+ wasm.lorodoc_importBatch(retptr, this.__wbg_ptr, addHeapObject(data));
2050
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
2051
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
2052
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
2053
+ if (r2) {
2054
+ throw takeObject(r1);
2055
+ }
2056
+ return takeObject(r0);
2057
+ } finally {
2058
+ wasm.__wbindgen_add_to_stack_pointer(16);
2059
+ }
2060
+ }
2061
+ /**
2017
2062
  * Get the shallow json format of the document state.
2018
2063
  *
2064
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2065
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2066
+ *
2019
2067
  * @example
2020
2068
  * ```ts
2021
2069
  * import { LoroDoc } from "loro-crdt";
@@ -2025,12 +2073,17 @@ export class LoroDoc {
2025
2073
  * const tree = doc.getTree("tree");
2026
2074
  * const map = doc.getMap("map");
2027
2075
  * const shallowValue = doc.getShallowValue();
2028
- * /*
2029
- * {"list": ..., "tree": ..., "map": ...}
2030
- * *\/
2031
2076
  * console.log(shallowValue);
2077
+ * // {
2078
+ * // list: 'cid:root-list:List',
2079
+ * // tree: 'cid:root-tree:Tree',
2080
+ * // map: 'cid:root-map:Map'
2081
+ * // }
2082
+ *
2083
+ * // It points to the same container as `list`
2084
+ * const listB = doc.getContainerById(shallowValue.list);
2032
2085
  * ```
2033
- * @returns {any}
2086
+ * @returns {Record<string, ContainerID>}
2034
2087
  */
2035
2088
  getShallowValue() {
2036
2089
  try {
@@ -2050,9 +2103,12 @@ export class LoroDoc {
2050
2103
  /**
2051
2104
  * Get the json format of the entire document state.
2052
2105
  *
2106
+ * Unlike `getShallowValue()` which returns container IDs as strings,
2107
+ * `toJSON()` recursively resolves all containers to their actual values.
2108
+ *
2053
2109
  * @example
2054
2110
  * ```ts
2055
- * import { LoroDoc, LoroText, LoroMap } from "loro-crdt";
2111
+ * import { LoroDoc, LoroText } from "loro-crdt";
2056
2112
  *
2057
2113
  * const doc = new LoroDoc();
2058
2114
  * const list = doc.getList("list");
@@ -2061,10 +2117,8 @@ export class LoroDoc {
2061
2117
  * text.insert(0, "Hello");
2062
2118
  * const map = list.insertContainer(1, new LoroMap());
2063
2119
  * map.set("foo", "bar");
2064
- * /*
2065
- * {"list": ["Hello", {"foo": "bar"}]}
2066
- * *\/
2067
2120
  * console.log(doc.toJSON());
2121
+ * // {"list": ["Hello", {"foo": "bar"}]}
2068
2122
  * ```
2069
2123
  * @returns {any}
2070
2124
  */
@@ -2819,6 +2873,29 @@ export class LoroList {
2819
2873
  const ret = wasm.lorolist_isDeleted(this.__wbg_ptr);
2820
2874
  return ret !== 0;
2821
2875
  }
2876
+ /**
2877
+ * Get the shallow value of the list.
2878
+ *
2879
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
2880
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
2881
+ *
2882
+ * ```js
2883
+ * const doc = new LoroDoc();
2884
+ * doc.setPeerId("1");
2885
+ * const list = doc.getList("list");
2886
+ * list.insert(0, 1);
2887
+ * list.insert(1, "two");
2888
+ * const subList = list.insertContainer(2, new LoroList());
2889
+ * subList.insert(0, "sub");
2890
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
2891
+ * list.toJSON(); // [1, "two", ["sub"]]
2892
+ * ```
2893
+ * @returns {Value[]}
2894
+ */
2895
+ getShallowValue() {
2896
+ const ret = wasm.lorolist_getShallowValue(this.__wbg_ptr);
2897
+ return takeObject(ret);
2898
+ }
2822
2899
  }
2823
2900
 
2824
2901
  const LoroMapFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -3269,6 +3346,37 @@ export class LoroMap {
3269
3346
  const ret = wasm.loromap_isDeleted(this.__wbg_ptr);
3270
3347
  return ret !== 0;
3271
3348
  }
3349
+ /**
3350
+ * Get the shallow value of the map.
3351
+ *
3352
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
3353
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
3354
+ *
3355
+ * @example
3356
+ * ```ts
3357
+ * import { LoroDoc } from "loro-crdt";
3358
+ *
3359
+ * const doc = new LoroDoc();
3360
+ * doc.setPeerId("1");
3361
+ * const map = doc.getMap("map");
3362
+ * map.set("key", "value");
3363
+ * const subText = map.setContainer("text", new LoroText());
3364
+ * subText.insert(0, "Hello");
3365
+ *
3366
+ * // Get shallow value - nested containers are represented by their IDs
3367
+ * console.log(map.getShallowValue());
3368
+ * // Output: { key: "value", text: "cid:1@1:Text" }
3369
+ *
3370
+ * // Get full value with nested containers resolved by `toJSON()`
3371
+ * console.log(map.toJSON());
3372
+ * // Output: { key: "value", text: "Hello" }
3373
+ * ```
3374
+ * @returns {Record<string, Value>}
3375
+ */
3376
+ getShallowValue() {
3377
+ const ret = wasm.loromap_getShallowValue(this.__wbg_ptr);
3378
+ return takeObject(ret);
3379
+ }
3272
3380
  }
3273
3381
 
3274
3382
  const LoroMovableListFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -3776,6 +3884,29 @@ export class LoroMovableList {
3776
3884
  const ret = wasm.loromovablelist_isDeleted(this.__wbg_ptr);
3777
3885
  return ret !== 0;
3778
3886
  }
3887
+ /**
3888
+ * Get the shallow value of the movable list.
3889
+ *
3890
+ * Unlike `toJSON()` which recursively resolves all containers to their values,
3891
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
3892
+ *
3893
+ * ```js
3894
+ * const doc = new LoroDoc();
3895
+ * doc.setPeerId("1");
3896
+ * const list = doc.getMovableList("list");
3897
+ * list.insert(0, 1);
3898
+ * list.insert(1, "two");
3899
+ * const subList = list.insertContainer(2, new LoroList());
3900
+ * subList.insert(0, "sub");
3901
+ * list.getShallowValue(); // [1, "two", "cid:2@1:List"]
3902
+ * list.toJSON(); // [1, "two", ["sub"]]
3903
+ * ```
3904
+ * @returns {Value[]}
3905
+ */
3906
+ getShallowValue() {
3907
+ const ret = wasm.loromovablelist_getShallowValue(this.__wbg_ptr);
3908
+ return takeObject(ret);
3909
+ }
3779
3910
  }
3780
3911
 
3781
3912
  const LoroTextFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -4431,6 +4562,26 @@ export class LoroText {
4431
4562
  const ret = wasm.lorotext_isDeleted(this.__wbg_ptr);
4432
4563
  return ret !== 0;
4433
4564
  }
4565
+ /**
4566
+ * Get the shallow value of the text. This equals to `text.toString()`.
4567
+ * @returns {string}
4568
+ */
4569
+ getShallowValue() {
4570
+ let deferred1_0;
4571
+ let deferred1_1;
4572
+ try {
4573
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
4574
+ wasm.lorotext_getShallowValue(retptr, this.__wbg_ptr);
4575
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
4576
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
4577
+ deferred1_0 = r0;
4578
+ deferred1_1 = r1;
4579
+ return getStringFromWasm0(r0, r1);
4580
+ } finally {
4581
+ wasm.__wbindgen_add_to_stack_pointer(16);
4582
+ wasm.__wbindgen_export_5(deferred1_0, deferred1_1, 1);
4583
+ }
4584
+ }
4434
4585
  }
4435
4586
 
4436
4587
  const LoroTreeFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -4878,6 +5029,51 @@ export class LoroTree {
4878
5029
  const ret = wasm.lorotree_isDeleted(this.__wbg_ptr);
4879
5030
  return ret !== 0;
4880
5031
  }
5032
+ /**
5033
+ * Get the shallow value of the tree.
5034
+ *
5035
+ * Unlike `toJSON()` which recursively resolves nested containers to their values,
5036
+ * `getShallowValue()` returns container IDs as strings for any nested containers.
5037
+ *
5038
+ * @example
5039
+ * ```ts
5040
+ * const doc = new LoroDoc();
5041
+ * doc.setPeerId("1");
5042
+ * const tree = doc.getTree("tree");
5043
+ * const root = tree.createNode();
5044
+ * root.data.set("name", "root");
5045
+ * const text = root.data.setContainer("content", new LoroText());
5046
+ * text.insert(0, "Hello");
5047
+ *
5048
+ * console.log(tree.getShallowValue());
5049
+ * // [{
5050
+ * // id: "0@1",
5051
+ * // parent: null,
5052
+ * // index: 0,
5053
+ * // fractional_index: "80",
5054
+ * // meta: "cid:0@1:Map",
5055
+ * // children: []
5056
+ * // }]
5057
+ *
5058
+ * console.log(tree.toJSON());
5059
+ * // [{
5060
+ * // id: "0@1",
5061
+ * // parent: null,
5062
+ * // index: 0,
5063
+ * // fractional_index: "80",
5064
+ * // meta: {
5065
+ * // name: "root",
5066
+ * // content: "Hello"
5067
+ * // },
5068
+ * // children: []
5069
+ * // }]
5070
+ * ```
5071
+ * @returns {TreeNodeShallowValue[]}
5072
+ */
5073
+ getShallowValue() {
5074
+ const ret = wasm.lorotree_getShallowValue(this.__wbg_ptr);
5075
+ return takeObject(ret);
5076
+ }
4881
5077
  }
4882
5078
 
4883
5079
  const LoroTreeNodeFinalization = (typeof FinalizationRegistry === 'undefined')
Binary file
@@ -10,6 +10,7 @@ export function lorocounter_subscribe(a: number, b: number, c: number): void;
10
10
  export function lorocounter_parent(a: number): number;
11
11
  export function lorocounter_isAttached(a: number): number;
12
12
  export function lorocounter_getAttached(a: number): number;
13
+ export function lorocounter_getShallowValue(a: number): number;
13
14
  export function __wbg_awarenesswasm_free(a: number): void;
14
15
  export function awarenesswasm_new(a: number, b: number): number;
15
16
  export function awarenesswasm_encode(a: number, b: number, c: number): void;
@@ -76,6 +77,7 @@ export function lorodoc_exportJsonUpdates(a: number, b: number, c: number, d: nu
76
77
  export function lorodoc_importJsonUpdates(a: number, b: number, c: number): void;
77
78
  export function lorodoc_import(a: number, b: number, c: number, d: number): void;
78
79
  export function lorodoc_importUpdateBatch(a: number, b: number, c: number): void;
80
+ export function lorodoc_importBatch(a: number, b: number, c: number): void;
79
81
  export function lorodoc_getShallowValue(a: number, b: number): void;
80
82
  export function lorodoc_toJSON(a: number, b: number): void;
81
83
  export function lorodoc_subscribe(a: number, b: number): number;
@@ -119,6 +121,7 @@ export function lorotext_getCursor(a: number, b: number, c: number): number;
119
121
  export function lorotext_push(a: number, b: number, c: number, d: number): void;
120
122
  export function lorotext_getEditorOf(a: number, b: number): number;
121
123
  export function lorotext_isDeleted(a: number): number;
124
+ export function lorotext_getShallowValue(a: number, b: number): void;
122
125
  export function __wbg_loromap_free(a: number): void;
123
126
  export function loromap_new(): number;
124
127
  export function loromap_kind(a: number): number;
@@ -139,6 +142,7 @@ export function loromap_getAttached(a: number): number;
139
142
  export function loromap_clear(a: number, b: number): void;
140
143
  export function loromap_getLastEditor(a: number, b: number, c: number): number;
141
144
  export function loromap_isDeleted(a: number): number;
145
+ export function loromap_getShallowValue(a: number): number;
142
146
  export function __wbg_lorolist_free(a: number): void;
143
147
  export function lorolist_new(): number;
144
148
  export function lorolist_kind(a: number): number;
@@ -161,6 +165,7 @@ export function lorolist_pop(a: number, b: number): void;
161
165
  export function lorolist_clear(a: number, b: number): void;
162
166
  export function lorolist_getIdAt(a: number, b: number): number;
163
167
  export function lorolist_isDeleted(a: number): number;
168
+ export function lorolist_getShallowValue(a: number): number;
164
169
  export function loromovablelist_new(): number;
165
170
  export function loromovablelist_kind(a: number): number;
166
171
  export function loromovablelist_insert(a: number, b: number, c: number, d: number): void;
@@ -185,6 +190,7 @@ export function loromovablelist_getCreatorAt(a: number, b: number): number;
185
190
  export function loromovablelist_getLastMoverAt(a: number, b: number): number;
186
191
  export function loromovablelist_getLastEditorAt(a: number, b: number): number;
187
192
  export function loromovablelist_isDeleted(a: number): number;
193
+ export function loromovablelist_getShallowValue(a: number): number;
188
194
  export function __wbg_lorotree_free(a: number): void;
189
195
  export function lorotreenode___getClassname(a: number, b: number): void;
190
196
  export function __wbg_lorotreenode_free(a: number): void;
@@ -225,6 +231,7 @@ export function lorotree_enableFractionalIndex(a: number, b: number): void;
225
231
  export function lorotree_disableFractionalIndex(a: number): void;
226
232
  export function lorotree_isFractionalIndexEnabled(a: number): number;
227
233
  export function lorotree_isDeleted(a: number): number;
234
+ export function lorotree_getShallowValue(a: number): number;
228
235
  export function __wbg_cursor_free(a: number): void;
229
236
  export function cursor_containerId(a: number): number;
230
237
  export function cursor_pos(a: number): number;