@yorkie-js/sdk 0.7.3 → 0.7.5

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/dist/counter.html CHANGED
@@ -58,7 +58,7 @@
58
58
  // 03. initialize document properties
59
59
  doc.update((root) => {
60
60
  if (!root.counter) {
61
- root.counter = new yorkie.Counter(yorkie.IntType, 0);
61
+ root.counter = new yorkie.Counter(0);
62
62
  }
63
63
  }, 'create counter if not exists');
64
64
 
package/dist/multi.html CHANGED
@@ -115,7 +115,7 @@
115
115
 
116
116
  doc.update((root) => {
117
117
  if (!root.counter) {
118
- root.counter = new yorkie.Counter(yorkie.IntType, 0);
118
+ root.counter = new yorkie.Counter(0);
119
119
  root.todos = [];
120
120
  root.content = new yorkie.Text();
121
121
  root.content.edit(0, 0, '\n');
@@ -1,5 +1,3 @@
1
- import { default as default_2 } from 'long';
2
- import { default as Long_2 } from 'long';
3
1
  import { Message } from '@bufbuild/protobuf';
4
2
  import { Rule } from '@yorkie-js/schema';
5
3
  import { Timestamp } from '@bufbuild/protobuf/wkt';
@@ -166,6 +164,38 @@ declare interface AuthErrorEvent_3 {
166
164
 
167
165
  declare type BaseArray<T> = JSONArray<T> | Array<T>;
168
166
 
167
+ /**
168
+ * `BaseCounter` is an internal base that holds the shared state and
169
+ * initialization logic for Counter and DedupCounter. Not exported.
170
+ */
171
+ declare class BaseCounter {
172
+ protected valueType: CounterType;
173
+ protected value: number | bigint;
174
+ protected context?: ChangeContext;
175
+ protected counter?: CRDTCounter;
176
+ constructor(valueType: CounterType, value: number | bigint);
177
+ /**
178
+ * `initialize` links this proxy to a ChangeContext and CRDTCounter.
179
+ */
180
+ initialize(context: ChangeContext, counter: CRDTCounter): void;
181
+ /**
182
+ * `getID` returns the ID of this counter.
183
+ */
184
+ getID(): TimeTicket;
185
+ /**
186
+ * `getValueType` returns the value type of this counter.
187
+ */
188
+ getValueType(): CounterType;
189
+ /**
190
+ * `toJSForTest` returns value with meta data for testing.
191
+ */
192
+ toJSForTest(): Devtools.JSONElement;
193
+ /**
194
+ * `ensureInitialized` throws if this counter has not been initialized.
195
+ */
196
+ protected ensureInitialized(): void;
197
+ }
198
+
169
199
  declare interface BaseDocEvent {
170
200
  type: DocEventType_2;
171
201
  }
@@ -1183,6 +1213,12 @@ export declare interface ClientOptions {
1183
1213
  * client.
1184
1214
  */
1185
1215
  userAgent?: string;
1216
+ /**
1217
+ * `useGrpcWebTransport` determines the transport protocol.
1218
+ * If true, uses gRPC-Web transport for backward compatibility.
1219
+ * If false (default), uses Connect Protocol transport.
1220
+ */
1221
+ useGrpcWebTransport?: boolean;
1186
1222
  }
1187
1223
 
1188
1224
  /**
@@ -1261,38 +1297,25 @@ export declare const converter: {
1261
1297
  };
1262
1298
 
1263
1299
  /**
1264
- * `Counter` is a custom data type that is used to counter.
1300
+ * `Counter` is a numeric counter that supports `increase()`.
1301
+ * For counting unique actors, use `DedupCounter` instead.
1302
+ *
1303
+ * ```typescript
1304
+ * // Type is inferred from value:
1305
+ * root.count = new Counter(0); // Int
1306
+ * root.count = new Counter(0n); // Long
1307
+ * ```
1265
1308
  */
1266
- export declare class Counter {
1267
- private valueType;
1268
- private value;
1269
- private context?;
1270
- private counter?;
1271
- constructor(valueType: CounterType, value: number | default_2);
1272
- /**
1273
- * `initialize` initialize this text with context and internal text.
1274
- */
1275
- initialize(context: ChangeContext, counter: CRDTCounter): void;
1276
- /**
1277
- * `getID` returns the ID of this text.
1278
- */
1279
- getID(): TimeTicket;
1309
+ export declare class Counter extends BaseCounter {
1310
+ constructor(value: number | bigint);
1280
1311
  /**
1281
- * `getValue` returns the value of this counter;
1312
+ * `getValue` returns the value of this counter.
1282
1313
  */
1283
- getValue(): number | default_2;
1284
- /**
1285
- * `getValueType` returns the value type of this counter.
1286
- */
1287
- getValueType(): CounterType;
1314
+ getValue(): number | bigint;
1288
1315
  /**
1289
1316
  * `increase` increases numeric data.
1290
1317
  */
1291
- increase(v: number | default_2): Counter;
1292
- /**
1293
- * `toJSForTest` returns value with meta data for testing.
1294
- */
1295
- toJSForTest(): Devtools.JSONElement;
1318
+ increase(v: number | bigint): Counter;
1296
1319
  }
1297
1320
 
1298
1321
  /**
@@ -1307,12 +1330,13 @@ declare type CounterOpInfo_2 = IncreaseOpInfo_2;
1307
1330
 
1308
1331
  export declare enum CounterType {
1309
1332
  Int = 0,
1310
- Long = 1
1333
+ Long = 1,
1334
+ IntDedup = 2
1311
1335
  }
1312
1336
 
1313
- export declare type CounterValue = number | default_2;
1337
+ export declare type CounterValue = number | bigint;
1314
1338
 
1315
- declare type CounterValue_2 = number | Long_2;
1339
+ declare type CounterValue_2 = number | bigint;
1316
1340
 
1317
1341
  /**
1318
1342
  *
@@ -1347,6 +1371,7 @@ declare abstract class CRDTContainer extends CRDTElement {
1347
1371
  declare class CRDTCounter extends CRDTElement {
1348
1372
  private valueType;
1349
1373
  private value;
1374
+ private hll?;
1350
1375
  constructor(valueType: CounterType, value: CounterValue, createdAt: TimeTicket);
1351
1376
  /**
1352
1377
  * `of` creates a new instance of Counter.
@@ -1408,8 +1433,30 @@ declare class CRDTCounter extends CRDTElement {
1408
1433
  * `toBytes` creates an array representing the value.
1409
1434
  */
1410
1435
  toBytes(): Uint8Array;
1436
+ /**
1437
+ * `isDedup` returns whether dedup mode is enabled (derived from ValueType).
1438
+ */
1439
+ isDedup(): boolean;
1440
+ /**
1441
+ * `increaseDedup` increases the counter using HLL-based dedup.
1442
+ * Only updates the value if the actor is new (not seen before).
1443
+ */
1444
+ increaseDedup(v: Primitive, actor: string): CRDTCounter;
1445
+ /**
1446
+ * `hllBytes` returns the HLL register bytes, or undefined if not in dedup mode.
1447
+ */
1448
+ hllBytes(): Uint8Array | undefined;
1449
+ /**
1450
+ * `restoreHLL` restores the HLL state from serialized bytes.
1451
+ */
1452
+ restoreHLL(data: Uint8Array): void;
1453
+ /**
1454
+ * `recomputeValue` updates the counter value from the HLL cardinality estimate.
1455
+ */
1456
+ private recomputeValue;
1411
1457
  /**
1412
1458
  * `increase` increases numeric data.
1459
+ * Dedup counters must use increaseDedup() instead.
1413
1460
  */
1414
1461
  increase(v: Primitive): CRDTCounter;
1415
1462
  }
@@ -1882,6 +1929,16 @@ declare class CRDTTree extends CRDTElement implements GCParent {
1882
1929
  private indexTree;
1883
1930
  private nodeMapByID;
1884
1931
  constructor(root: CRDTTreeNode, createdAt: TimeTicket);
1932
+ /**
1933
+ * `rebuildMergeState` reconstructs the `mergedInto` cache on source
1934
+ * parents from the persisted `mergedFrom` field on moved children.
1935
+ * For snapshots written before `mergedAt` was added to the proto,
1936
+ * it also falls back to the source's `removedAt` — an approximation
1937
+ * that may be wrong if the source was later overwritten by a
1938
+ * concurrent delete, but this is the best we can do without the
1939
+ * persisted merge ticket.
1940
+ */
1941
+ private rebuildMergeState;
1885
1942
  /**
1886
1943
  * `create` creates a new instance of `CRDTTree`.
1887
1944
  */
@@ -1890,6 +1947,19 @@ declare class CRDTTree extends CRDTElement implements GCParent {
1890
1947
  * `findFloorNode` finds node of given id.
1891
1948
  */
1892
1949
  findFloorNode(id: CRDTTreeNodeID): CRDTTreeNode | undefined;
1950
+ /**
1951
+ * `advancePastUnknownSplitSiblings` follows the insNextID chain of the
1952
+ * given node, advancing past element-type split siblings that the editing
1953
+ * client did not know about (not in versionVector).
1954
+ */
1955
+ private advancePastUnknownSplitSiblings;
1956
+ /**
1957
+ * `hasUnknownSplitSibling` checks whether the given element node has a
1958
+ * split sibling (via insNextID) whose creation the editor did not know
1959
+ * about. Used to prevent styling via End tokens when a concurrent split
1960
+ * extended the range into the split sibling.
1961
+ */
1962
+ private hasUnknownSplitSibling;
1893
1963
  /**
1894
1964
  * `registerNode` registers the given node to the tree.
1895
1965
  */
@@ -1911,11 +1981,17 @@ declare class CRDTTree extends CRDTElement implements GCParent {
1911
1981
  */
1912
1982
  style(range: [CRDTTreePos, CRDTTreePos], attributes: {
1913
1983
  [key: string]: string;
1914
- } | undefined, editedAt: TimeTicket, versionVector?: VersionVector): [Array<GCPair>, Array<TreeChange>, DataSize];
1984
+ } | undefined, editedAt: TimeTicket, versionVector?: VersionVector): [
1985
+ Array<GCPair>,
1986
+ Array<TreeChange>,
1987
+ DataSize,
1988
+ Map<string, string>,
1989
+ Array<string>
1990
+ ];
1915
1991
  /**
1916
1992
  * `removeStyle` removes the given attributes of the given range.
1917
1993
  */
1918
- removeStyle(range: [CRDTTreePos, CRDTTreePos], attributesToRemove: Array<string>, editedAt: TimeTicket, versionVector?: VersionVector): [Array<GCPair>, Array<TreeChange>, DataSize];
1994
+ removeStyle(range: [CRDTTreePos, CRDTTreePos], attributesToRemove: Array<string>, editedAt: TimeTicket, versionVector?: VersionVector): [Array<GCPair>, Array<TreeChange>, DataSize, Map<string, string>];
1919
1995
  /**
1920
1996
  * `edit` edits the tree with the given range and content.
1921
1997
  * If the content is undefined, the range will be removed.
@@ -2079,6 +2155,29 @@ declare class CRDTTreeNode extends IndexTreeNode<CRDTTreeNode> implements GCPare
2079
2155
  * `insNextID` is the previous node id of this node after the node is split.
2080
2156
  */
2081
2157
  insNextID?: CRDTTreeNodeID;
2158
+ /**
2159
+ * `mergedFrom` records the source parent's ID when this node was moved
2160
+ * by a concurrent merge. Persisted in the snapshot encoding as the
2161
+ * witness of the merge relationship.
2162
+ */
2163
+ mergedFrom?: CRDTTreeNodeID;
2164
+ /**
2165
+ * `mergedAt` records the immutable ticket of the merge operation.
2166
+ * Persisted alongside `mergedFrom` because the source parent's
2167
+ * `removedAt` may be overwritten by later LWW tombstones and thus
2168
+ * cannot serve as the merge-time causal boundary for splitElement's
2169
+ * Fix 8 version-vector check.
2170
+ */
2171
+ mergedAt?: TimeTicket;
2172
+ /**
2173
+ * `mergedInto` is a runtime cache set on the source parent pointing
2174
+ * at the merge target. Set locally during merge execution and rebuilt
2175
+ * from `mergedFrom` on snapshot load. Used for the fast
2176
+ * "is this tombstoned parent a merge source?" check in
2177
+ * `FindTreeNodesWithSplitText`; the alternative (scanning
2178
+ * `nodeMapByID` on every position resolution) would be too expensive.
2179
+ */
2180
+ mergedInto?: CRDTTreeNodeID;
2082
2181
  _value: string;
2083
2182
  constructor(id: CRDTTreeNodeID, type: string, opts?: string | Array<CRDTTreeNode>, attributes?: RHT, removedAt?: TimeTicket);
2084
2183
  /**
@@ -2124,7 +2223,7 @@ declare class CRDTTreeNode extends IndexTreeNode<CRDTTreeNode> implements GCPare
2124
2223
  /**
2125
2224
  * `split` splits the given offset of this node.
2126
2225
  */
2127
- split(tree: CRDTTree, offset: number, issueTimeTicket?: () => TimeTicket): [CRDTTreeNode | undefined, DataSize];
2226
+ split(tree: CRDTTree, offset: number, issueTimeTicket?: () => TimeTicket, versionVector?: VersionVector): [CRDTTreeNode | undefined, DataSize];
2128
2227
  /**
2129
2228
  * `getCreatedAt` returns the creation time of this element.
2130
2229
  */
@@ -2342,6 +2441,32 @@ declare interface DeactivateOptions {
2342
2441
  */
2343
2442
  declare type DecreasedDepthOf<Depth extends number> = Depth extends 10 ? 9 : Depth extends 9 ? 8 : Depth extends 8 ? 7 : Depth extends 7 ? 6 : Depth extends 6 ? 5 : Depth extends 5 ? 4 : Depth extends 4 ? 3 : Depth extends 3 ? 2 : Depth extends 2 ? 1 : Depth extends 1 ? 0 : -1;
2344
2443
 
2444
+ /**
2445
+ * `DedupCounter` is a Counter that uses HyperLogLog to count unique actors.
2446
+ * Use `add(actor)` to record a unique visitor. Provides approximate counts
2447
+ * with ~2% error rate.
2448
+ *
2449
+ * ```typescript
2450
+ * doc.update((root) => {
2451
+ * root.uv = new yorkie.DedupCounter();
2452
+ * root.uv.add(userId);
2453
+ * });
2454
+ * ```
2455
+ */
2456
+ export declare class DedupCounter extends BaseCounter {
2457
+ constructor();
2458
+ /**
2459
+ * `getValue` returns the value of this counter. Always a number since
2460
+ * DedupCounter only supports IntDedup.
2461
+ */
2462
+ getValue(): number;
2463
+ /**
2464
+ * `add` records a unique actor in the dedup counter. If the actor has
2465
+ * already been counted, the call is ignored.
2466
+ */
2467
+ add(actor: string): DedupCounter;
2468
+ }
2469
+
2345
2470
  /**
2346
2471
  * The top-level yorkie namespace with additional properties.
2347
2472
  *
@@ -2356,6 +2481,7 @@ declare const _default: {
2356
2481
  Primitive: typeof Primitive;
2357
2482
  Text: typeof Text_2;
2358
2483
  Counter: typeof Counter;
2484
+ DedupCounter: typeof DedupCounter;
2359
2485
  Tree: typeof Tree;
2360
2486
  Devtools: typeof Devtools;
2361
2487
  Channel: typeof Channel;
@@ -2363,8 +2489,6 @@ declare const _default: {
2363
2489
  YSON: typeof YSON;
2364
2490
  LogLevel: typeof LogLevel;
2365
2491
  setLogLevel: typeof setLogLevel;
2366
- IntType: CounterType;
2367
- LongType: CounterType;
2368
2492
  };
2369
2493
  export default _default;
2370
2494
 
@@ -3493,10 +3617,17 @@ declare abstract class IndexTreeNode<T extends IndexTreeNode<T>> {
3493
3617
  * In this method, the child is physically removed from the tree.
3494
3618
  */
3495
3619
  removeChild(child: T): void;
3620
+ /**
3621
+ * `detachChild` removes the given child from this node's children list
3622
+ * and updates both visibleSize and totalSize. Unlike `removeChild` which
3623
+ * is used for GC purge of tombstoned nodes, `detachChild` is used for
3624
+ * moving alive nodes between parents.
3625
+ */
3626
+ detachChild(child: T): void;
3496
3627
  /**
3497
3628
  * `splitElement` splits the given element at the given offset.
3498
3629
  */
3499
- splitElement(offset: number, issueTimeTicket: () => TimeTicket): [T | undefined, DataSize];
3630
+ splitElement(offset: number, issueTimeTicket: () => TimeTicket, versionVector?: VersionVector): [T | undefined, DataSize];
3500
3631
  /**
3501
3632
  * `insertAfterInternal` inserts the given node after the given child.
3502
3633
  * This method does not update the size of the ancestors.
@@ -3765,7 +3896,7 @@ declare type JsonArray_2 = Array<Json_2>;
3765
3896
  * `JSONElement` is a wrapper for `CRDTElement` that provides users with an
3766
3897
  * easy-to-use interface for manipulating `Document`s.
3767
3898
  */
3768
- export declare type JSONElement<T = unknown, A extends Indexable = Indexable> = PrimitiveValue | JSONObject<T> | JSONArray<T> | Text_2<A> | Counter | Tree;
3899
+ export declare type JSONElement<T = unknown, A extends Indexable = Indexable> = PrimitiveValue | JSONObject<T> | JSONArray<T> | Text_2<A> | Counter | DedupCounter | Tree;
3769
3900
 
3770
3901
  /**
3771
3902
  * `JSONElement` represents the result of `Element.toJSForTest()`.
@@ -4297,6 +4428,10 @@ declare type Operation_Increase = Message<"yorkie.v1.Operation.Increase"> & {
4297
4428
  * @generated from field: yorkie.v1.TimeTicket executed_at = 3;
4298
4429
  */
4299
4430
  executedAt?: TimeTicket_2;
4431
+ /**
4432
+ * @generated from field: string actor = 4;
4433
+ */
4434
+ actor: string;
4300
4435
  };
4301
4436
 
4302
4437
  /**
@@ -4840,7 +4975,7 @@ declare enum PrimitiveType {
4840
4975
  * `PrimitiveValue` represents a value of primitive type. Only values of type
4841
4976
  * included in `PrimitiveValue` can be set to the document.
4842
4977
  */
4843
- export declare type PrimitiveValue = null | boolean | number | default_2 | string | Uint8Array | Date;
4978
+ export declare type PrimitiveValue = null | boolean | number | bigint | string | Uint8Array | Date;
4844
4979
 
4845
4980
  /**
4846
4981
  * `PrimitiveValue` represents a value of primitive type. Only values of type
@@ -4848,7 +4983,7 @@ export declare type PrimitiveValue = null | boolean | number | default_2 | strin
4848
4983
  */
4849
4984
  declare type PrimitiveValue_2 =
4850
4985
  // eslint-disable-next-line @typescript-eslint/no-restricted-types
4851
- null | boolean | number | Long_2 | string | Uint8Array | Date;
4986
+ null | boolean | number | bigint | string | Uint8Array | Date;
4852
4987
 
4853
4988
  /**
4854
4989
  * `RemoteChangeEvent` is an event that occurs when the document is changed
@@ -6473,6 +6608,22 @@ declare type TreeNode_3 = Message<"yorkie.v1.TreeNode"> & {
6473
6608
  attributes: {
6474
6609
  [key: string]: NodeAttr;
6475
6610
  };
6611
+ /**
6612
+ * merged_from is set when this node was moved to a new parent by a
6613
+ * concurrent merge. It points to the source parent's ID.
6614
+ *
6615
+ * @generated from field: yorkie.v1.TreeNodeID merged_from = 9;
6616
+ */
6617
+ mergedFrom?: TreeNodeID;
6618
+ /**
6619
+ * merged_at records the immutable ticket of the merge operation.
6620
+ * Stored alongside merged_from because the source parent's removed_at
6621
+ * may be overwritten by later LWW tombstones and thus cannot serve as
6622
+ * the merge-time causal boundary for SplitElement.
6623
+ *
6624
+ * @generated from field: yorkie.v1.TimeTicket merged_at = 10;
6625
+ */
6626
+ mergedAt?: TimeTicket_2;
6476
6627
  };
6477
6628
 
6478
6629
  /**
@@ -6745,7 +6896,11 @@ declare enum ValueType {
6745
6896
  /**
6746
6897
  * @generated from enum value: VALUE_TYPE_TREE = 13;
6747
6898
  */
6748
- TREE = 13
6899
+ TREE = 13,
6900
+ /**
6901
+ * @generated from enum value: VALUE_TYPE_INTEGER_DEDUP_CNT = 14;
6902
+ */
6903
+ INTEGER_DEDUP_CNT = 14
6749
6904
  }
6750
6905
 
6751
6906
  /**
@@ -6835,7 +6990,7 @@ declare interface WatchedEvent_2<P extends Indexable_2> extends BaseDocEvent {
6835
6990
  /**
6836
6991
  * `WrappedElement` is a wrapper of JSONElement that provides `getID()`.
6837
6992
  */
6838
- export declare type WrappedElement<T = unknown, A extends Indexable = Indexable> = Primitive | JSONObject<T> | JSONArray<T> | Text_2<A> | Counter | Tree;
6993
+ export declare type WrappedElement<T = unknown, A extends Indexable = Indexable> = Primitive | JSONObject<T> | JSONArray<T> | Text_2<A> | Counter | DedupCounter | Tree;
6839
6994
 
6840
6995
  declare namespace YSON {
6841
6996
  export {