@yorkie-js/sdk 0.7.4 → 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);
1309
+ export declare class Counter extends BaseCounter {
1310
+ constructor(value: number | bigint);
1272
1311
  /**
1273
- * `initialize` initialize this text with context and internal text.
1312
+ * `getValue` returns the value of this counter.
1274
1313
  */
1275
- initialize(context: ChangeContext, counter: CRDTCounter): void;
1276
- /**
1277
- * `getID` returns the ID of this text.
1278
- */
1279
- getID(): TimeTicket;
1280
- /**
1281
- * `getValue` returns the value of this counter;
1282
- */
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
  }
@@ -1934,11 +1981,17 @@ declare class CRDTTree extends CRDTElement implements GCParent {
1934
1981
  */
1935
1982
  style(range: [CRDTTreePos, CRDTTreePos], attributes: {
1936
1983
  [key: string]: string;
1937
- } | 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
+ ];
1938
1991
  /**
1939
1992
  * `removeStyle` removes the given attributes of the given range.
1940
1993
  */
1941
- 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>];
1942
1995
  /**
1943
1996
  * `edit` edits the tree with the given range and content.
1944
1997
  * If the content is undefined, the range will be removed.
@@ -2388,6 +2441,32 @@ declare interface DeactivateOptions {
2388
2441
  */
2389
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;
2390
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
+
2391
2470
  /**
2392
2471
  * The top-level yorkie namespace with additional properties.
2393
2472
  *
@@ -2402,6 +2481,7 @@ declare const _default: {
2402
2481
  Primitive: typeof Primitive;
2403
2482
  Text: typeof Text_2;
2404
2483
  Counter: typeof Counter;
2484
+ DedupCounter: typeof DedupCounter;
2405
2485
  Tree: typeof Tree;
2406
2486
  Devtools: typeof Devtools;
2407
2487
  Channel: typeof Channel;
@@ -2409,8 +2489,6 @@ declare const _default: {
2409
2489
  YSON: typeof YSON;
2410
2490
  LogLevel: typeof LogLevel;
2411
2491
  setLogLevel: typeof setLogLevel;
2412
- IntType: CounterType;
2413
- LongType: CounterType;
2414
2492
  };
2415
2493
  export default _default;
2416
2494
 
@@ -3818,7 +3896,7 @@ declare type JsonArray_2 = Array<Json_2>;
3818
3896
  * `JSONElement` is a wrapper for `CRDTElement` that provides users with an
3819
3897
  * easy-to-use interface for manipulating `Document`s.
3820
3898
  */
3821
- 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;
3822
3900
 
3823
3901
  /**
3824
3902
  * `JSONElement` represents the result of `Element.toJSForTest()`.
@@ -4350,6 +4428,10 @@ declare type Operation_Increase = Message<"yorkie.v1.Operation.Increase"> & {
4350
4428
  * @generated from field: yorkie.v1.TimeTicket executed_at = 3;
4351
4429
  */
4352
4430
  executedAt?: TimeTicket_2;
4431
+ /**
4432
+ * @generated from field: string actor = 4;
4433
+ */
4434
+ actor: string;
4353
4435
  };
4354
4436
 
4355
4437
  /**
@@ -4893,7 +4975,7 @@ declare enum PrimitiveType {
4893
4975
  * `PrimitiveValue` represents a value of primitive type. Only values of type
4894
4976
  * included in `PrimitiveValue` can be set to the document.
4895
4977
  */
4896
- export declare type PrimitiveValue = null | boolean | number | default_2 | string | Uint8Array | Date;
4978
+ export declare type PrimitiveValue = null | boolean | number | bigint | string | Uint8Array | Date;
4897
4979
 
4898
4980
  /**
4899
4981
  * `PrimitiveValue` represents a value of primitive type. Only values of type
@@ -4901,7 +4983,7 @@ export declare type PrimitiveValue = null | boolean | number | default_2 | strin
4901
4983
  */
4902
4984
  declare type PrimitiveValue_2 =
4903
4985
  // eslint-disable-next-line @typescript-eslint/no-restricted-types
4904
- null | boolean | number | Long_2 | string | Uint8Array | Date;
4986
+ null | boolean | number | bigint | string | Uint8Array | Date;
4905
4987
 
4906
4988
  /**
4907
4989
  * `RemoteChangeEvent` is an event that occurs when the document is changed
@@ -6814,7 +6896,11 @@ declare enum ValueType {
6814
6896
  /**
6815
6897
  * @generated from enum value: VALUE_TYPE_TREE = 13;
6816
6898
  */
6817
- TREE = 13
6899
+ TREE = 13,
6900
+ /**
6901
+ * @generated from enum value: VALUE_TYPE_INTEGER_DEDUP_CNT = 14;
6902
+ */
6903
+ INTEGER_DEDUP_CNT = 14
6818
6904
  }
6819
6905
 
6820
6906
  /**
@@ -6904,7 +6990,7 @@ declare interface WatchedEvent_2<P extends Indexable_2> extends BaseDocEvent {
6904
6990
  /**
6905
6991
  * `WrappedElement` is a wrapper of JSONElement that provides `getID()`.
6906
6992
  */
6907
- 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;
6908
6994
 
6909
6995
  declare namespace YSON {
6910
6996
  export {