loro-crdt 1.3.1 → 1.3.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.
@@ -48,7 +48,7 @@ export function decodeImportBlobMeta(blob: Uint8Array, check_checksum: boolean):
48
48
  * const text = list.insertContainer(1, new LoroText());
49
49
  * ```
50
50
  */
51
- export type ContainerType = "Text" | "Map" | "List"| "Tree" | "MovableList";
51
+ export type ContainerType = "Text" | "Map" | "List"| "Tree" | "MovableList" | "Counter";
52
52
 
53
53
  export type PeerID = `${number}`;
54
54
  /**
@@ -292,7 +292,7 @@ export type UndoConfig = {
292
292
  onPush?: (isUndo: boolean, counterRange: { start: number, end: number }, event?: LoroEventBatch) => { value: Value, cursors: Cursor[] },
293
293
  onPop?: (isUndo: boolean, value: { value: Value, cursors: Cursor[] }, counterRange: { start: number, end: number }) => void
294
294
  };
295
- export type Container = LoroList | LoroMap | LoroText | LoroTree | LoroMovableList;
295
+ export type Container = LoroList | LoroMap | LoroText | LoroTree | LoroMovableList | LoroCounter;
296
296
 
297
297
  export interface ImportBlobMetadata {
298
298
  /**
@@ -1023,6 +1023,7 @@ interface LoroMovableList<T = unknown> {
1023
1023
  */
1024
1024
  setContainer<C extends Container>(pos: number, child: C): T extends C ? T : C;
1025
1025
  }
1026
+
1026
1027
  interface LoroMap<T extends Record<string, unknown> = Record<string, unknown>> {
1027
1028
  new(): LoroMap<T>;
1028
1029
  /**
@@ -1076,9 +1077,13 @@ interface LoroMap<T extends Record<string, unknown> = Record<string, unknown>> {
1076
1077
  */
1077
1078
  get<Key extends keyof T>(key: Key): T[Key];
1078
1079
  /**
1079
- * Set the key with the value.
1080
+ * Set the key with the value.
1081
+ *
1082
+ * If the key already exists, its value will be updated. If the key doesn't exist,
1083
+ * a new key-value pair will be created.
1080
1084
  *
1081
- * If the value of the key is exist, the old value will be updated.
1085
+ * > **Note**: When calling `map.set(key, value)` on a LoroMap, if `map.get(key)` already returns `value`,
1086
+ * > the operation will be a no-op (no operation recorded) to avoid unnecessary updates.
1082
1087
  *
1083
1088
  * @example
1084
1089
  * ```ts
@@ -1155,7 +1160,7 @@ interface LoroTree<T extends Record<string, unknown> = Record<string, unknown>>
1155
1160
  /**
1156
1161
  * Get LoroTreeNode by the TreeID.
1157
1162
  */
1158
- getNodeByID(target: TreeID): LoroTreeNode<T>;
1163
+ getNodeByID(target: TreeID): LoroTreeNode<T> | undefined;
1159
1164
  subscribe(listener: Listener): Subscription;
1160
1165
  toArray(): TreeNodeValue[];
1161
1166
  getNodes(options?: { withDeleted?: boolean } ): LoroTreeNode<T>[];
@@ -1378,7 +1383,7 @@ export class Cursor {
1378
1383
  kind(): any;
1379
1384
  }
1380
1385
  /**
1381
- * The handler of a tree(forest) container.
1386
+ * The handler of a counter container.
1382
1387
  */
1383
1388
  export class LoroCounter {
1384
1389
  free(): void;
@@ -1387,6 +1392,11 @@ export class LoroCounter {
1387
1392
  */
1388
1393
  constructor();
1389
1394
  /**
1395
+ * "Counter"
1396
+ * @returns {'Counter'}
1397
+ */
1398
+ kind(): 'Counter';
1399
+ /**
1390
1400
  * Increment the counter by the given value.
1391
1401
  * @param {number} value
1392
1402
  */
@@ -1431,6 +1441,10 @@ export class LoroCounter {
1431
1441
  */
1432
1442
  getShallowValue(): number;
1433
1443
  /**
1444
+ * The container id of this handler.
1445
+ */
1446
+ readonly id: ContainerID;
1447
+ /**
1434
1448
  * Get the value of the counter.
1435
1449
  */
1436
1450
  readonly value: number;
@@ -1440,6 +1454,10 @@ export class LoroCounter {
1440
1454
  * [**RichText**](LoroText), [**Map**](LoroMap) and [**Movable Tree**](LoroTree),
1441
1455
  * you could build all kind of applications by these.
1442
1456
  *
1457
+ * **Important:** Loro is a pure library and does not handle network protocols.
1458
+ * It is the responsibility of the user to manage the storage, loading, and synchronization
1459
+ * of the bytes exported by Loro in a manner suitable for their specific environment.
1460
+ *
1443
1461
  * @example
1444
1462
  * ```ts
1445
1463
  * import { LoroDoc } from "loro-crdt"
@@ -3498,12 +3516,6 @@ export class UndoManager {
3498
3516
  */
3499
3517
  addExcludeOriginPrefix(prefix: string): void;
3500
3518
  /**
3501
- * Check if the undo manager is bound to the given document.
3502
- * @param {LoroDoc} doc
3503
- * @returns {boolean}
3504
- */
3505
- checkBinding(doc: LoroDoc): boolean;
3506
- /**
3507
3519
  */
3508
3520
  clear(): void;
3509
3521
  }
@@ -3583,6 +3595,8 @@ export interface InitOutput {
3583
3595
  readonly memory: WebAssembly.Memory;
3584
3596
  readonly __wbg_lorocounter_free: (a: number) => void;
3585
3597
  readonly lorocounter_new: () => number;
3598
+ readonly lorocounter_kind: (a: number) => number;
3599
+ readonly lorocounter_id: (a: number) => number;
3586
3600
  readonly lorocounter_increment: (a: number, b: number, c: number) => void;
3587
3601
  readonly lorocounter_decrement: (a: number, b: number, c: number) => void;
3588
3602
  readonly lorocounter_value: (a: number) => number;
@@ -3658,7 +3672,6 @@ export interface InitOutput {
3658
3672
  readonly lorodoc_exportJsonInIdSpan: (a: number, b: number, c: number) => void;
3659
3673
  readonly lorodoc_importJsonUpdates: (a: number, b: number, c: number) => void;
3660
3674
  readonly lorodoc_import: (a: number, b: number, c: number, d: number) => void;
3661
- readonly lorodoc_importUpdateBatch: (a: number, b: number, c: number) => void;
3662
3675
  readonly lorodoc_importBatch: (a: number, b: number, c: number) => void;
3663
3676
  readonly lorodoc_getShallowValue: (a: number, b: number) => void;
3664
3677
  readonly lorodoc_toJSON: (a: number, b: number) => void;
@@ -3833,7 +3846,6 @@ export interface InitOutput {
3833
3846
  readonly undomanager_setMaxUndoSteps: (a: number, b: number) => void;
3834
3847
  readonly undomanager_setMergeInterval: (a: number, b: number) => void;
3835
3848
  readonly undomanager_addExcludeOriginPrefix: (a: number, b: number, c: number) => void;
3836
- readonly undomanager_checkBinding: (a: number, b: number) => number;
3837
3849
  readonly undomanager_setOnPush: (a: number, b: number) => void;
3838
3850
  readonly undomanager_setOnPop: (a: number, b: number) => void;
3839
3851
  readonly undomanager_clear: (a: number) => void;
@@ -3851,6 +3863,7 @@ export interface InitOutput {
3851
3863
  readonly versionvector_length: (a: number) => number;
3852
3864
  readonly decodeImportBlobMeta: (a: number, b: number, c: number, d: number) => void;
3853
3865
  readonly __wbg_loromovablelist_free: (a: number) => void;
3866
+ readonly lorodoc_importUpdateBatch: (a: number, b: number, c: number) => void;
3854
3867
  readonly loromovablelist_parent: (a: number) => number;
3855
3868
  readonly lorotext_isAttached: (a: number) => number;
3856
3869
  readonly loromap_isAttached: (a: number) => number;
package/web/loro_wasm.js CHANGED
@@ -728,7 +728,7 @@ const LoroCounterFinalization = (typeof FinalizationRegistry === 'undefined')
728
728
  ? { register: () => {}, unregister: () => {} }
729
729
  : new FinalizationRegistry(ptr => wasm.__wbg_lorocounter_free(ptr >>> 0));
730
730
  /**
731
- * The handler of a tree(forest) container.
731
+ * The handler of a counter container.
732
732
  */
733
733
  export class LoroCounter {
734
734
 
@@ -760,6 +760,22 @@ export class LoroCounter {
760
760
  return this;
761
761
  }
762
762
  /**
763
+ * "Counter"
764
+ * @returns {'Counter'}
765
+ */
766
+ kind() {
767
+ const ret = wasm.lorocounter_kind(this.__wbg_ptr);
768
+ return takeObject(ret);
769
+ }
770
+ /**
771
+ * The container id of this handler.
772
+ * @returns {ContainerID}
773
+ */
774
+ get id() {
775
+ const ret = wasm.lorocounter_id(this.__wbg_ptr);
776
+ return takeObject(ret);
777
+ }
778
+ /**
763
779
  * Increment the counter by the given value.
764
780
  * @param {number} value
765
781
  */
@@ -871,6 +887,10 @@ const LoroDocFinalization = (typeof FinalizationRegistry === 'undefined')
871
887
  * [**RichText**](LoroText), [**Map**](LoroMap) and [**Movable Tree**](LoroTree),
872
888
  * you could build all kind of applications by these.
873
889
  *
890
+ * **Important:** Loro is a pure library and does not handle network protocols.
891
+ * It is the responsibility of the user to manage the storage, loading, and synchronization
892
+ * of the bytes exported by Loro in a manner suitable for their specific environment.
893
+ *
874
894
  * @example
875
895
  * ```ts
876
896
  * import { LoroDoc } from "loro-crdt"
@@ -2087,7 +2107,7 @@ export class LoroDoc {
2087
2107
  importUpdateBatch(data) {
2088
2108
  try {
2089
2109
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2090
- wasm.lorodoc_importUpdateBatch(retptr, this.__wbg_ptr, addHeapObject(data));
2110
+ wasm.lorodoc_importBatch(retptr, this.__wbg_ptr, addHeapObject(data));
2091
2111
  var r0 = getInt32Memory0()[retptr / 4 + 0];
2092
2112
  var r1 = getInt32Memory0()[retptr / 4 + 1];
2093
2113
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -5715,16 +5735,6 @@ export class UndoManager {
5715
5735
  wasm.undomanager_addExcludeOriginPrefix(this.__wbg_ptr, ptr0, len0);
5716
5736
  }
5717
5737
  /**
5718
- * Check if the undo manager is bound to the given document.
5719
- * @param {LoroDoc} doc
5720
- * @returns {boolean}
5721
- */
5722
- checkBinding(doc) {
5723
- _assertClass(doc, LoroDoc);
5724
- const ret = wasm.undomanager_checkBinding(this.__wbg_ptr, doc.__wbg_ptr);
5725
- return ret !== 0;
5726
- }
5727
- /**
5728
5738
  * Set the on push event listener.
5729
5739
  *
5730
5740
  * Every time an undo step or redo step is pushed, the on push event listener will be called.
@@ -6003,36 +6013,36 @@ function __wbg_get_imports() {
6003
6013
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
6004
6014
  takeObject(arg0);
6005
6015
  };
6006
- imports.wbg.__wbg_lorolist_new = function(arg0) {
6007
- const ret = LoroList.__wrap(arg0);
6016
+ imports.wbg.__wbg_lorotreenode_new = function(arg0) {
6017
+ const ret = LoroTreeNode.__wrap(arg0);
6008
6018
  return addHeapObject(ret);
6009
6019
  };
6010
6020
  imports.wbg.__wbg_lorocounter_new = function(arg0) {
6011
6021
  const ret = LoroCounter.__wrap(arg0);
6012
6022
  return addHeapObject(ret);
6013
6023
  };
6014
- imports.wbg.__wbg_loromap_new = function(arg0) {
6015
- const ret = LoroMap.__wrap(arg0);
6016
- return addHeapObject(ret);
6017
- };
6018
- imports.wbg.__wbg_lorotreenode_new = function(arg0) {
6019
- const ret = LoroTreeNode.__wrap(arg0);
6024
+ imports.wbg.__wbg_lorotext_new = function(arg0) {
6025
+ const ret = LoroText.__wrap(arg0);
6020
6026
  return addHeapObject(ret);
6021
6027
  };
6022
- imports.wbg.__wbg_lorotree_new = function(arg0) {
6023
- const ret = LoroTree.__wrap(arg0);
6028
+ imports.wbg.__wbg_lorolist_new = function(arg0) {
6029
+ const ret = LoroList.__wrap(arg0);
6024
6030
  return addHeapObject(ret);
6025
6031
  };
6026
- imports.wbg.__wbg_loromovablelist_new = function(arg0) {
6027
- const ret = LoroMovableList.__wrap(arg0);
6032
+ imports.wbg.__wbg_loromap_new = function(arg0) {
6033
+ const ret = LoroMap.__wrap(arg0);
6028
6034
  return addHeapObject(ret);
6029
6035
  };
6030
6036
  imports.wbg.__wbg_cursor_new = function(arg0) {
6031
6037
  const ret = Cursor.__wrap(arg0);
6032
6038
  return addHeapObject(ret);
6033
6039
  };
6034
- imports.wbg.__wbg_lorotext_new = function(arg0) {
6035
- const ret = LoroText.__wrap(arg0);
6040
+ imports.wbg.__wbg_loromovablelist_new = function(arg0) {
6041
+ const ret = LoroMovableList.__wrap(arg0);
6042
+ return addHeapObject(ret);
6043
+ };
6044
+ imports.wbg.__wbg_lorotree_new = function(arg0) {
6045
+ const ret = LoroTree.__wrap(arg0);
6036
6046
  return addHeapObject(ret);
6037
6047
  };
6038
6048
  imports.wbg.__wbg_versionvector_new = function(arg0) {
@@ -6136,10 +6146,10 @@ function __wbg_get_imports() {
6136
6146
  const ret = typeof getObject(arg0);
6137
6147
  return addHeapObject(ret);
6138
6148
  };
6139
- imports.wbg.__wbg_error_c8c2cca30a630316 = function(arg0, arg1) {
6149
+ imports.wbg.__wbg_error_9384d761bf46409d = function(arg0, arg1) {
6140
6150
  console.error(getStringFromWasm0(arg0, arg1));
6141
6151
  };
6142
- imports.wbg.__wbg_log_d8fdbde28117925d = function(arg0, arg1) {
6152
+ imports.wbg.__wbg_log_c86c3e1bf097ba35 = function(arg0, arg1) {
6143
6153
  console.log(getStringFromWasm0(arg0, arg1));
6144
6154
  };
6145
6155
  imports.wbg.__wbindgen_is_falsy = function(arg0) {
@@ -6227,7 +6237,7 @@ function __wbg_get_imports() {
6227
6237
  wasm.__wbindgen_export_5(deferred0_0, deferred0_1, 1);
6228
6238
  }
6229
6239
  };
6230
- imports.wbg.__wbg_now_15d99db1ebc1f0b2 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6240
+ imports.wbg.__wbg_now_6dd635953150ee31 = typeof Date.now == 'function' ? Date.now : notDefined('Date.now');
6231
6241
  imports.wbg.__wbg_crypto_1d1f22824a6a080c = function(arg0) {
6232
6242
  const ret = getObject(arg0).crypto;
6233
6243
  return addHeapObject(ret);
@@ -6490,12 +6500,12 @@ function __wbg_get_imports() {
6490
6500
  const ret = wasm.memory;
6491
6501
  return addHeapObject(ret);
6492
6502
  };
6493
- imports.wbg.__wbindgen_closure_wrapper491 = function(arg0, arg1, arg2) {
6494
- const ret = makeMutClosure(arg0, arg1, 9, __wbg_adapter_60);
6503
+ imports.wbg.__wbindgen_closure_wrapper482 = function(arg0, arg1, arg2) {
6504
+ const ret = makeMutClosure(arg0, arg1, 8, __wbg_adapter_60);
6495
6505
  return addHeapObject(ret);
6496
6506
  };
6497
- imports.wbg.__wbindgen_closure_wrapper494 = function(arg0, arg1, arg2) {
6498
- const ret = makeMutClosure(arg0, arg1, 11, __wbg_adapter_63);
6507
+ imports.wbg.__wbindgen_closure_wrapper484 = function(arg0, arg1, arg2) {
6508
+ const ret = makeMutClosure(arg0, arg1, 10, __wbg_adapter_63);
6499
6509
  return addHeapObject(ret);
6500
6510
  };
6501
6511
 
Binary file
@@ -3,6 +3,8 @@
3
3
  export const memory: WebAssembly.Memory;
4
4
  export function __wbg_lorocounter_free(a: number): void;
5
5
  export function lorocounter_new(): number;
6
+ export function lorocounter_kind(a: number): number;
7
+ export function lorocounter_id(a: number): number;
6
8
  export function lorocounter_increment(a: number, b: number, c: number): void;
7
9
  export function lorocounter_decrement(a: number, b: number, c: number): void;
8
10
  export function lorocounter_value(a: number): number;
@@ -78,7 +80,6 @@ export function lorodoc_exportJsonUpdates(a: number, b: number, c: number, d: nu
78
80
  export function lorodoc_exportJsonInIdSpan(a: number, b: number, c: number): void;
79
81
  export function lorodoc_importJsonUpdates(a: number, b: number, c: number): void;
80
82
  export function lorodoc_import(a: number, b: number, c: number, d: number): void;
81
- export function lorodoc_importUpdateBatch(a: number, b: number, c: number): void;
82
83
  export function lorodoc_importBatch(a: number, b: number, c: number): void;
83
84
  export function lorodoc_getShallowValue(a: number, b: number): void;
84
85
  export function lorodoc_toJSON(a: number, b: number): void;
@@ -253,7 +254,6 @@ export function undomanager_canRedo(a: number): number;
253
254
  export function undomanager_setMaxUndoSteps(a: number, b: number): void;
254
255
  export function undomanager_setMergeInterval(a: number, b: number): void;
255
256
  export function undomanager_addExcludeOriginPrefix(a: number, b: number, c: number): void;
256
- export function undomanager_checkBinding(a: number, b: number): number;
257
257
  export function undomanager_setOnPush(a: number, b: number): void;
258
258
  export function undomanager_setOnPop(a: number, b: number): void;
259
259
  export function undomanager_clear(a: number): void;
@@ -271,6 +271,7 @@ export function versionvector_remove(a: number, b: number, c: number): void;
271
271
  export function versionvector_length(a: number): number;
272
272
  export function decodeImportBlobMeta(a: number, b: number, c: number, d: number): void;
273
273
  export function __wbg_loromovablelist_free(a: number): void;
274
+ export function lorodoc_importUpdateBatch(a: number, b: number, c: number): void;
274
275
  export function loromovablelist_parent(a: number): number;
275
276
  export function lorotext_isAttached(a: number): number;
276
277
  export function loromap_isAttached(a: number): number;