@yorkie-js/react 0.6.7 → 0.6.8

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,5 +1,6 @@
1
1
  import { ClientOptions } from '@yorkie-js/sdk';
2
2
  import { default as default_2 } from 'react';
3
+ import { Document as Document_2 } from '@yorkie-js/sdk';
3
4
  import { Indexable } from '@yorkie-js/sdk';
4
5
  import { JSONArray } from '@yorkie-js/sdk';
5
6
  import { JSONObject } from '@yorkie-js/sdk';
@@ -8,6 +9,8 @@ import { Presence } from '@yorkie-js/sdk';
8
9
  import { PropsWithChildren } from 'react';
9
10
  import { StreamConnectionStatus } from '@yorkie-js/sdk';
10
11
 
12
+ export { Document_2 as Document }
13
+
11
14
  /**
12
15
  * `DocumentProvider` is a component that provides a document to its children.
13
16
  * This component must be under a `YorkieProvider` component to initialize the
@@ -34,6 +37,7 @@ export declare const useConnection: () => StreamConnectionStatus;
34
37
  * This hook must be used within a `DocumentProvider`.
35
38
  */
36
39
  export declare const useDocument: <R, P extends Indexable = Indexable>() => {
40
+ doc: Document_2<R, P>;
37
41
  root: R;
38
42
  presences: {
39
43
  clientID: string;
@@ -50,7 +54,7 @@ export declare const useDocument: <R, P extends Indexable = Indexable>() => {
50
54
  */
51
55
  export declare const usePresences: () => {
52
56
  clientID: string;
53
- presence: Indexable;
57
+ presence: any;
54
58
  }[];
55
59
 
56
60
  /**
@@ -5,7 +5,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
5
5
  import { jsx } from "react/jsx-runtime";
6
6
  import { createContext, useMemo, useState, useEffect, useContext, useCallback } from "react";
7
7
  const name$1 = "@yorkie-js/react";
8
- const version$1 = "0.6.7";
8
+ const version$1 = "0.6.8";
9
9
  const pkg$1 = {
10
10
  name: name$1,
11
11
  version: version$1
@@ -7675,6 +7675,7 @@ class Presence {
7675
7675
  }
7676
7676
  }
7677
7677
  const InitialActorID = "000000000000000000000000";
7678
+ const TimeTicketSize = 8 + 4 + 12;
7678
7679
  class TimeTicket {
7679
7680
  constructor(lamport, delimiter, actorID) {
7680
7681
  __publicField(this, "lamport");
@@ -7893,6 +7894,22 @@ class CRDTElement {
7893
7894
  isRemoved() {
7894
7895
  return !!this.removedAt;
7895
7896
  }
7897
+ /**
7898
+ * `getMetaUsage` returns the meta usage of this element.
7899
+ */
7900
+ getMetaUsage() {
7901
+ let meta = 0;
7902
+ if (this.getCreatedAt()) {
7903
+ meta += TimeTicketSize;
7904
+ }
7905
+ if (this.getMovedAt()) {
7906
+ meta += TimeTicketSize;
7907
+ }
7908
+ if (this.getRemovedAt()) {
7909
+ meta += TimeTicketSize;
7910
+ }
7911
+ return meta;
7912
+ }
7896
7913
  }
7897
7914
  class CRDTContainer extends CRDTElement {
7898
7915
  constructor(createdAt) {
@@ -8125,6 +8142,15 @@ class CRDTObject extends CRDTContainer {
8125
8142
  has(key) {
8126
8143
  return this.memberNodes.has(key);
8127
8144
  }
8145
+ /**
8146
+ * `getDataSize` returns the data usage of this element.
8147
+ */
8148
+ getDataSize() {
8149
+ return {
8150
+ data: 0,
8151
+ meta: this.getMetaUsage()
8152
+ };
8153
+ }
8128
8154
  /**
8129
8155
  * `toJSON` returns the JSON encoding of this object.
8130
8156
  */
@@ -9692,6 +9718,44 @@ class Primitive extends CRDTElement {
9692
9718
  );
9693
9719
  }
9694
9720
  }
9721
+ /**
9722
+ * `getValueSize` returns the size of the value. The size is similar to
9723
+ * the size of primitives in JavaScript.
9724
+ */
9725
+ getValueSize() {
9726
+ switch (this.valueType) {
9727
+ case 0:
9728
+ return 8;
9729
+ case 1:
9730
+ return 4;
9731
+ case 2:
9732
+ return 4;
9733
+ case 3:
9734
+ return 8;
9735
+ case 4:
9736
+ return 8;
9737
+ case 5:
9738
+ return this.value.length * 2;
9739
+ case 6:
9740
+ return this.value.length;
9741
+ case 7:
9742
+ return 8;
9743
+ default:
9744
+ throw new YorkieError(
9745
+ Code.ErrUnimplemented,
9746
+ `unimplemented type: ${this.valueType}`
9747
+ );
9748
+ }
9749
+ }
9750
+ /**
9751
+ * `getDataSize` returns the data usage of this element.
9752
+ */
9753
+ getDataSize() {
9754
+ return {
9755
+ data: this.getValueSize(),
9756
+ meta: this.getMetaUsage()
9757
+ };
9758
+ }
9695
9759
  /**
9696
9760
  * `toJSON` returns the JSON encoding of the value.
9697
9761
  */
@@ -10290,6 +10354,15 @@ class CRDTArray extends CRDTContainer {
10290
10354
  }
10291
10355
  }
10292
10356
  }
10357
+ /**
10358
+ * `getDataSize` returns the data usage of this element.
10359
+ */
10360
+ getDataSize() {
10361
+ return {
10362
+ data: 0,
10363
+ meta: this.getMetaUsage()
10364
+ };
10365
+ }
10293
10366
  /**
10294
10367
  * `toJSON` returns the JSON encoding of this array.
10295
10368
  */
@@ -10757,6 +10830,15 @@ class RHTNode {
10757
10830
  }
10758
10831
  return void 0;
10759
10832
  }
10833
+ /**
10834
+ * `getDataSize` returns the size of this node.
10835
+ */
10836
+ getDataSize() {
10837
+ return {
10838
+ data: (this.key.length + this.value.length) * 2,
10839
+ meta: TimeTicketSize
10840
+ };
10841
+ }
10760
10842
  }
10761
10843
  class RHT {
10762
10844
  constructor() {
@@ -10968,6 +11050,19 @@ class CRDTTextValue {
10968
11050
  toString() {
10969
11051
  return this.content;
10970
11052
  }
11053
+ /**
11054
+ * `getDataSize` returns the data usage of this value.
11055
+ */
11056
+ getDataSize() {
11057
+ const dataSize = { data: 0, meta: 0 };
11058
+ dataSize.data += this.content.length * 2;
11059
+ for (const node of this.attributes) {
11060
+ const size = node.getDataSize();
11061
+ dataSize.meta += size.meta;
11062
+ dataSize.data += size.data;
11063
+ }
11064
+ return dataSize;
11065
+ }
10971
11066
  /**
10972
11067
  * `toJSON` returns the JSON encoding of this value.
10973
11068
  */
@@ -11159,6 +11254,24 @@ class CRDTText extends CRDTElement {
11159
11254
  getTreeByID() {
11160
11255
  return this.rgaTreeSplit.getTreeByID();
11161
11256
  }
11257
+ /**
11258
+ * `getDataSize` returns the data usage of this element.
11259
+ */
11260
+ getDataSize() {
11261
+ const dataSize = { data: 0, meta: 0 };
11262
+ for (const node of this.rgaTreeSplit) {
11263
+ if (node.isRemoved()) {
11264
+ continue;
11265
+ }
11266
+ const size = node.getDataSize();
11267
+ dataSize.data += size.data;
11268
+ dataSize.meta += size.meta;
11269
+ }
11270
+ return {
11271
+ data: dataSize.data,
11272
+ meta: dataSize.meta + this.getMetaUsage()
11273
+ };
11274
+ }
11162
11275
  /**
11163
11276
  * `toJSON` returns the JSON encoding of this text.
11164
11277
  */
@@ -12773,6 +12886,32 @@ class CRDTTreeNode extends IndexTreeNode {
12773
12886
  this.attrs.purge(node);
12774
12887
  }
12775
12888
  }
12889
+ /**
12890
+ * `getDataSize` returns the data size of the node.
12891
+ */
12892
+ getDataSize() {
12893
+ const dataSize = { data: 0, meta: 0 };
12894
+ if (this.isText) {
12895
+ dataSize.data += this.size * 2;
12896
+ }
12897
+ if (this.id) {
12898
+ dataSize.meta += TimeTicketSize;
12899
+ }
12900
+ if (this.removedAt) {
12901
+ dataSize.meta += TimeTicketSize;
12902
+ }
12903
+ if (this.attrs) {
12904
+ for (const node of this.attrs) {
12905
+ if (node.getRemovedAt()) {
12906
+ continue;
12907
+ }
12908
+ const size = node.getDataSize();
12909
+ dataSize.meta += size.meta;
12910
+ dataSize.data += size.data;
12911
+ }
12912
+ }
12913
+ return dataSize;
12914
+ }
12776
12915
  /**
12777
12916
  * `getGCPairs` returns the pairs of GC.
12778
12917
  */
@@ -13272,6 +13411,24 @@ class CRDTTree extends CRDTElement {
13272
13411
  toXML() {
13273
13412
  return toXML(this.indexTree.getRoot());
13274
13413
  }
13414
+ /**
13415
+ * `getDataSize` returns the data usage of this element.
13416
+ */
13417
+ getDataSize() {
13418
+ const dataSize = { data: 0, meta: 0 };
13419
+ this.indexTree.traverse((node) => {
13420
+ if (node.getRemovedAt()) {
13421
+ return;
13422
+ }
13423
+ const size = node.getDataSize();
13424
+ dataSize.data += size.data;
13425
+ dataSize.meta += size.meta;
13426
+ });
13427
+ return {
13428
+ data: dataSize.data,
13429
+ meta: dataSize.meta + this.getMetaUsage()
13430
+ };
13431
+ }
13275
13432
  /**
13276
13433
  * `toJSON` returns the JSON encoding of this tree.
13277
13434
  */
@@ -14628,6 +14785,19 @@ class RGATreeSplitNode extends SplayNode {
14628
14785
  RGATreeSplitPos.of(this.id, this.getLength())
14629
14786
  ];
14630
14787
  }
14788
+ /**
14789
+ * `getData` returns the data of this node.
14790
+ */
14791
+ getDataSize() {
14792
+ const dataSize = this.value.getDataSize();
14793
+ if (this.id) {
14794
+ dataSize.meta += TimeTicketSize;
14795
+ }
14796
+ if (this.removedAt) {
14797
+ dataSize.meta += TimeTicketSize;
14798
+ }
14799
+ return dataSize;
14800
+ }
14631
14801
  /**
14632
14802
  * `deepcopy` returns a new instance of this RGATreeSplitNode without structural info.
14633
14803
  */
@@ -15056,8 +15226,8 @@ class RGATreeSplit {
15056
15226
  }
15057
15227
  const removeDecimal = (number) => number < 0 ? Math.ceil(number) : Math.floor(number);
15058
15228
  var CounterType = /* @__PURE__ */ ((CounterType2) => {
15059
- CounterType2[CounterType2["IntegerCnt"] = 0] = "IntegerCnt";
15060
- CounterType2[CounterType2["LongCnt"] = 1] = "LongCnt";
15229
+ CounterType2[CounterType2["Int"] = 0] = "Int";
15230
+ CounterType2[CounterType2["Long"] = 1] = "Long";
15061
15231
  return CounterType2;
15062
15232
  })(CounterType || {});
15063
15233
  class CRDTCounter extends CRDTElement {
@@ -15114,6 +15284,16 @@ class CRDTCounter extends CRDTElement {
15114
15284
  );
15115
15285
  }
15116
15286
  }
15287
+ /**
15288
+ * `getDataSize` returns the data usage of this element.
15289
+ */
15290
+ getDataSize() {
15291
+ const data = this.valueType === 0 ? 4 : 8;
15292
+ return {
15293
+ data,
15294
+ meta: this.getMetaUsage()
15295
+ };
15296
+ }
15117
15297
  /**
15118
15298
  * `toJSON` returns the JSON encoding of the value.
15119
15299
  */
@@ -15565,9 +15745,9 @@ function toValueType(valueType) {
15565
15745
  }
15566
15746
  function toCounterType(valueType) {
15567
15747
  switch (valueType) {
15568
- case CounterType.IntegerCnt:
15748
+ case CounterType.Int:
15569
15749
  return ValueType.INTEGER_CNT;
15570
- case CounterType.LongCnt:
15750
+ case CounterType.Long:
15571
15751
  return ValueType.LONG_CNT;
15572
15752
  default:
15573
15753
  throw new YorkieError(
@@ -16120,9 +16300,9 @@ function fromValueType(pbValueType) {
16120
16300
  function fromCounterType(pbValueType) {
16121
16301
  switch (pbValueType) {
16122
16302
  case ValueType.INTEGER_CNT:
16123
- return CounterType.IntegerCnt;
16303
+ return CounterType.Int;
16124
16304
  case ValueType.LONG_CNT:
16125
- return CounterType.LongCnt;
16305
+ return CounterType.Long;
16126
16306
  }
16127
16307
  throw new YorkieError(
16128
16308
  Code.ErrUnimplemented,
@@ -17221,6 +17401,27 @@ class CRDTRoot {
17221
17401
  getGarbageLen() {
17222
17402
  return this.getGarbageElementSetSize() + this.gcPairMap.size;
17223
17403
  }
17404
+ /**
17405
+ * `getDocSize` returns the size of the document.
17406
+ */
17407
+ getDocSize() {
17408
+ const docSize = { live: { data: 0, meta: 0 }, gc: { data: 0, meta: 0 } };
17409
+ for (const [createdAt, value] of this.elementPairMapByCreatedAt) {
17410
+ if (this.gcElementSetByCreatedAt.has(createdAt)) {
17411
+ docSize.gc.data += value.element.getDataSize().data;
17412
+ docSize.gc.meta += value.element.getDataSize().meta;
17413
+ } else {
17414
+ docSize.live.data += value.element.getDataSize().data;
17415
+ docSize.live.meta += value.element.getDataSize().meta;
17416
+ }
17417
+ }
17418
+ for (const pair of this.gcPairMap.values()) {
17419
+ const size = pair.child.getDataSize();
17420
+ docSize.gc.data += size.data;
17421
+ docSize.gc.meta += size.meta;
17422
+ }
17423
+ return docSize;
17424
+ }
17224
17425
  /**
17225
17426
  * `deepcopy` copies itself deeply.
17226
17427
  */
@@ -18778,7 +18979,7 @@ function toWrappedElement(context, elem) {
18778
18979
  } else if (elem instanceof CRDTText) {
18779
18980
  return new Text(context, elem);
18780
18981
  } else if (elem instanceof CRDTCounter) {
18781
- const counter = new Counter(CounterType.IntegerCnt, 0);
18982
+ const counter = new Counter(CounterType.Int, 0);
18782
18983
  counter.initialize(context, elem);
18783
18984
  return counter;
18784
18985
  } else if (elem instanceof CRDTTree) {
@@ -19531,6 +19732,12 @@ class Document {
19531
19732
  );
19532
19733
  return createJSON(context, this.clone.root.getObject());
19533
19734
  }
19735
+ /**
19736
+ * `getDocSize` returns the size of this document.
19737
+ */
19738
+ getDocSize() {
19739
+ return this.root.getDocSize();
19740
+ }
19534
19741
  /**
19535
19742
  * `garbageCollect` purges elements that were removed before the given time.
19536
19743
  *
@@ -20240,7 +20447,7 @@ function createAuthInterceptor(apiKey, token) {
20240
20447
  };
20241
20448
  }
20242
20449
  const name = "@yorkie-js/sdk";
20243
- const version = "0.6.7";
20450
+ const version = "0.6.8";
20244
20451
  const pkg = {
20245
20452
  name,
20246
20453
  version
@@ -21085,8 +21292,8 @@ class Client {
21085
21292
  }
21086
21293
  }
21087
21294
  ({
21088
- IntType: CounterType.IntegerCnt,
21089
- LongType: CounterType.LongCnt
21295
+ IntType: CounterType.Int,
21296
+ LongType: CounterType.Long
21090
21297
  });
21091
21298
  if (typeof globalThis !== "undefined") {
21092
21299
  globalThis.yorkie = {
@@ -21098,8 +21305,8 @@ if (typeof globalThis !== "undefined") {
21098
21305
  Tree,
21099
21306
  LogLevel,
21100
21307
  setLogLevel,
21101
- IntType: CounterType.IntegerCnt,
21102
- LongType: CounterType.LongCnt
21308
+ IntType: CounterType.Int,
21309
+ LongType: CounterType.Long
21103
21310
  };
21104
21311
  }
21105
21312
  const YorkieContext = createContext({
@@ -21257,7 +21464,9 @@ function useYorkieDocument(client, clientLoading, clientError, docKey, initialRo
21257
21464
  error
21258
21465
  };
21259
21466
  }
21260
- const DocumentContext = createContext(null);
21467
+ const DocumentContext = createContext(
21468
+ null
21469
+ );
21261
21470
  const DocumentProvider = ({
21262
21471
  docKey,
21263
21472
  initialRoot = {},
@@ -21265,7 +21474,7 @@ const DocumentProvider = ({
21265
21474
  children
21266
21475
  }) => {
21267
21476
  const { client, loading: clientLoading, error: clientError } = useYorkie();
21268
- const { root, presences, connection, update, loading, error } = useYorkieDocument(
21477
+ const { doc, root, presences, connection, update, loading, error } = useYorkieDocument(
21269
21478
  client,
21270
21479
  clientLoading,
21271
21480
  clientError,
@@ -21276,7 +21485,15 @@ const DocumentProvider = ({
21276
21485
  return /* @__PURE__ */ jsx(
21277
21486
  DocumentContext.Provider,
21278
21487
  {
21279
- value: { root, presences, connection, update, loading, error },
21488
+ value: {
21489
+ doc,
21490
+ root,
21491
+ presences,
21492
+ connection,
21493
+ update,
21494
+ loading,
21495
+ error
21496
+ },
21280
21497
  children
21281
21498
  }
21282
21499
  );
@@ -21287,6 +21504,7 @@ const useDocument = () => {
21287
21504
  throw new Error("useDocument must be used within a DocumentProvider");
21288
21505
  }
21289
21506
  return {
21507
+ doc: context.doc,
21290
21508
  root: context.root,
21291
21509
  presences: context.presences,
21292
21510
  connection: context.connection,