@yorkie-js/sdk 0.6.18 → 0.6.20

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.
@@ -10622,8 +10622,8 @@ class CRDTArray extends CRDTContainer {
10622
10622
  /**
10623
10623
  * `insertAfter` adds a new node after the the given node.
10624
10624
  */
10625
- insertAfter(prevCreatedAt, value) {
10626
- this.elements.insertAfter(prevCreatedAt, value);
10625
+ insertAfter(prevCreatedAt, value, executedAt) {
10626
+ this.elements.insertAfter(prevCreatedAt, value, executedAt);
10627
10627
  }
10628
10628
  /**
10629
10629
  * `moveAfter` moves the given `createdAt` element after the `prevCreatedAt`.
@@ -10791,6 +10791,84 @@ class CRDTArray extends CRDTContainer {
10791
10791
  return clone;
10792
10792
  }
10793
10793
  }
10794
+ class AddOperation extends Operation {
10795
+ constructor(parentCreatedAt, prevCreatedAt, value, executedAt) {
10796
+ super(parentCreatedAt, executedAt);
10797
+ __publicField(this, "prevCreatedAt");
10798
+ __publicField(this, "value");
10799
+ this.prevCreatedAt = prevCreatedAt;
10800
+ this.value = value;
10801
+ }
10802
+ /**
10803
+ * `create` creates a new instance of AddOperation.
10804
+ */
10805
+ static create(parentCreatedAt, prevCreatedAt, value, executedAt) {
10806
+ return new AddOperation(parentCreatedAt, prevCreatedAt, value, executedAt);
10807
+ }
10808
+ /**
10809
+ * `execute` executes this operation on the given `CRDTRoot`.
10810
+ */
10811
+ execute(root) {
10812
+ const parentObject = root.findByCreatedAt(this.getParentCreatedAt());
10813
+ if (!parentObject) {
10814
+ throw new YorkieError(
10815
+ Code.ErrInvalidArgument,
10816
+ `fail to find ${this.getParentCreatedAt()}`
10817
+ );
10818
+ }
10819
+ if (!(parentObject instanceof CRDTArray)) {
10820
+ throw new YorkieError(
10821
+ Code.ErrInvalidArgument,
10822
+ `fail to execute, only array can execute add`
10823
+ );
10824
+ }
10825
+ const array = parentObject;
10826
+ const value = this.value.deepcopy();
10827
+ array.insertAfter(this.prevCreatedAt, value, this.getExecutedAt());
10828
+ root.registerElement(value, array);
10829
+ return {
10830
+ opInfos: [
10831
+ {
10832
+ type: "add",
10833
+ path: root.createPath(this.getParentCreatedAt()),
10834
+ index: Number(array.subPathOf(this.getEffectedCreatedAt()))
10835
+ }
10836
+ ],
10837
+ reverseOp: this.toReverseOperation()
10838
+ };
10839
+ }
10840
+ toReverseOperation() {
10841
+ const reverseOp = RemoveOperation.create(
10842
+ this.getParentCreatedAt(),
10843
+ this.value.getCreatedAt()
10844
+ );
10845
+ return reverseOp;
10846
+ }
10847
+ /**
10848
+ * `getEffectedCreatedAt` returns the creation time of the effected element.
10849
+ */
10850
+ getEffectedCreatedAt() {
10851
+ return this.value.getCreatedAt();
10852
+ }
10853
+ /**
10854
+ * `toTestString` returns a string containing the meta data.
10855
+ */
10856
+ toTestString() {
10857
+ return `${this.getParentCreatedAt().toTestString()}.ADD.${this.value.toJSON()}`;
10858
+ }
10859
+ /**
10860
+ * `getPrevCreatedAt` returns the creation time of previous element.
10861
+ */
10862
+ getPrevCreatedAt() {
10863
+ return this.prevCreatedAt;
10864
+ }
10865
+ /**
10866
+ * `getValue` returns the value of this operation.
10867
+ */
10868
+ getValue() {
10869
+ return this.value;
10870
+ }
10871
+ }
10794
10872
  class RemoveOperation extends Operation {
10795
10873
  constructor(parentCreatedAt, createdAt, executedAt) {
10796
10874
  super(parentCreatedAt, executedAt);
@@ -10855,6 +10933,19 @@ class RemoveOperation extends Operation {
10855
10933
  * `toReverseOperation` returns the reverse operation of this operation.
10856
10934
  */
10857
10935
  toReverseOperation(parentObject) {
10936
+ if (parentObject instanceof CRDTArray) {
10937
+ const value = parentObject.getByID(this.createdAt);
10938
+ if (value !== void 0) {
10939
+ const prevCreatedAt = parentObject.getPrevCreatedAt(
10940
+ this.createdAt
10941
+ );
10942
+ return AddOperation.create(
10943
+ this.getParentCreatedAt(),
10944
+ prevCreatedAt,
10945
+ value.deepcopy()
10946
+ );
10947
+ }
10948
+ }
10858
10949
  if (parentObject instanceof CRDTObject) {
10859
10950
  const key = parentObject.subPathOf(this.createdAt);
10860
10951
  if (key !== void 0) {
@@ -10993,76 +11084,6 @@ class SetOperation extends Operation {
10993
11084
  return this.value;
10994
11085
  }
10995
11086
  }
10996
- class AddOperation extends Operation {
10997
- constructor(parentCreatedAt, prevCreatedAt, value, executedAt) {
10998
- super(parentCreatedAt, executedAt);
10999
- __publicField(this, "prevCreatedAt");
11000
- __publicField(this, "value");
11001
- this.prevCreatedAt = prevCreatedAt;
11002
- this.value = value;
11003
- }
11004
- /**
11005
- * `create` creates a new instance of AddOperation.
11006
- */
11007
- static create(parentCreatedAt, prevCreatedAt, value, executedAt) {
11008
- return new AddOperation(parentCreatedAt, prevCreatedAt, value, executedAt);
11009
- }
11010
- /**
11011
- * `execute` executes this operation on the given `CRDTRoot`.
11012
- */
11013
- execute(root) {
11014
- const parentObject = root.findByCreatedAt(this.getParentCreatedAt());
11015
- if (!parentObject) {
11016
- throw new YorkieError(
11017
- Code.ErrInvalidArgument,
11018
- `fail to find ${this.getParentCreatedAt()}`
11019
- );
11020
- }
11021
- if (!(parentObject instanceof CRDTArray)) {
11022
- throw new YorkieError(
11023
- Code.ErrInvalidArgument,
11024
- `fail to execute, only array can execute add`
11025
- );
11026
- }
11027
- const array = parentObject;
11028
- const value = this.value.deepcopy();
11029
- array.insertAfter(this.prevCreatedAt, value);
11030
- root.registerElement(value, array);
11031
- return {
11032
- opInfos: [
11033
- {
11034
- type: "add",
11035
- path: root.createPath(this.getParentCreatedAt()),
11036
- index: Number(array.subPathOf(this.getEffectedCreatedAt()))
11037
- }
11038
- ]
11039
- };
11040
- }
11041
- /**
11042
- * `getEffectedCreatedAt` returns the creation time of the effected element.
11043
- */
11044
- getEffectedCreatedAt() {
11045
- return this.value.getCreatedAt();
11046
- }
11047
- /**
11048
- * `toTestString` returns a string containing the meta data.
11049
- */
11050
- toTestString() {
11051
- return `${this.getParentCreatedAt().toTestString()}.ADD.${this.value.toJSON()}`;
11052
- }
11053
- /**
11054
- * `getPrevCreatedAt` returns the creation time of previous element.
11055
- */
11056
- getPrevCreatedAt() {
11057
- return this.prevCreatedAt;
11058
- }
11059
- /**
11060
- * `getValue` returns the value of this operation.
11061
- */
11062
- getValue() {
11063
- return this.value;
11064
- }
11065
- }
11066
11087
  class MoveOperation extends Operation {
11067
11088
  constructor(parentCreatedAt, prevCreatedAt, createdAt, executedAt) {
11068
11089
  super(parentCreatedAt, executedAt);
@@ -11100,6 +11121,7 @@ class MoveOperation extends Operation {
11100
11121
  );
11101
11122
  }
11102
11123
  const array = parentObject;
11124
+ const reverseOp = this.toReverseOperation(array);
11103
11125
  const previousIndex = Number(array.subPathOf(this.createdAt));
11104
11126
  array.moveAfter(this.prevCreatedAt, this.createdAt, this.getExecutedAt());
11105
11127
  const index = Number(array.subPathOf(this.createdAt));
@@ -11111,9 +11133,18 @@ class MoveOperation extends Operation {
11111
11133
  index,
11112
11134
  previousIndex
11113
11135
  }
11114
- ]
11136
+ ],
11137
+ reverseOp
11115
11138
  };
11116
11139
  }
11140
+ toReverseOperation(array) {
11141
+ const preservePrevCreatedAt = array.getPrevCreatedAt(this.createdAt);
11142
+ return MoveOperation.create(
11143
+ this.getParentCreatedAt(),
11144
+ preservePrevCreatedAt,
11145
+ this.createdAt
11146
+ );
11147
+ }
11117
11148
  /**
11118
11149
  * `getEffectedCreatedAt` returns the creation time of the effected element.
11119
11150
  */
@@ -21205,7 +21236,7 @@ function createAuthInterceptor(apiKey, token) {
21205
21236
  };
21206
21237
  }
21207
21238
  const name = "@yorkie-js/sdk";
21208
- const version = "0.6.18";
21239
+ const version = "0.6.20";
21209
21240
  const pkg = {
21210
21241
  name,
21211
21242
  version