@yorkie-js/sdk 0.7.2 → 0.7.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.
@@ -5499,6 +5499,7 @@
5499
5499
  Code2["ErrUnauthenticated"] = "ErrUnauthenticated";
5500
5500
  Code2["ErrTooManySubscribers"] = "ErrTooManySubscribers";
5501
5501
  Code2["ErrTooManyAttachments"] = "ErrTooManyAttachments";
5502
+ Code2["ErrEpochMismatch"] = "ErrEpochMismatch";
5502
5503
  return Code2;
5503
5504
  })(Code || {});
5504
5505
  class YorkieError extends Error {
@@ -17221,22 +17222,49 @@
17221
17222
  }
17222
17223
  }
17223
17224
  /**
17224
- * `styleByPath` sets the attributes to the elements of the given path.
17225
+ * `styleByPath` sets the attributes to the elements of the given
17226
+ * path. When called with two paths, it styles the range between
17227
+ * them.
17225
17228
  */
17226
- styleByPath(path, attributes) {
17229
+ styleByPath(fromPathOrPath, toPathOrAttrs, maybeAttrs) {
17227
17230
  if (!this.context || !this.tree) {
17228
17231
  throw new YorkieError(
17229
17232
  Code.ErrNotInitialized,
17230
17233
  "Tree is not initialized yet"
17231
17234
  );
17232
17235
  }
17233
- if (!path.length) {
17234
- throw new YorkieError(
17235
- Code.ErrInvalidArgument,
17236
- "path should not be empty"
17237
- );
17236
+ let fromPos;
17237
+ let toPos;
17238
+ let attributes;
17239
+ if (Array.isArray(toPathOrAttrs)) {
17240
+ const fromPath = fromPathOrPath;
17241
+ const toPath = toPathOrAttrs;
17242
+ attributes = maybeAttrs;
17243
+ if (fromPath.length !== toPath.length) {
17244
+ throw new YorkieError(
17245
+ Code.ErrInvalidArgument,
17246
+ "path length should be equal"
17247
+ );
17248
+ }
17249
+ if (!fromPath.length || !toPath.length) {
17250
+ throw new YorkieError(
17251
+ Code.ErrInvalidArgument,
17252
+ "path should not be empty"
17253
+ );
17254
+ }
17255
+ fromPos = this.tree.pathToPos(fromPath);
17256
+ toPos = this.tree.pathToPos(toPath);
17257
+ } else {
17258
+ const path = fromPathOrPath;
17259
+ attributes = toPathOrAttrs;
17260
+ if (!path.length) {
17261
+ throw new YorkieError(
17262
+ Code.ErrInvalidArgument,
17263
+ "path should not be empty"
17264
+ );
17265
+ }
17266
+ [fromPos, toPos] = this.tree.pathToPosRange(path);
17238
17267
  }
17239
- const [fromPos, toPos] = this.tree.pathToPosRange(path);
17240
17268
  const ticket = this.context.issueTimeTicket();
17241
17269
  const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
17242
17270
  const [pairs, , diff] = this.tree.style([fromPos, toPos], attrs, ticket);
@@ -17327,6 +17355,51 @@
17327
17355
  )
17328
17356
  );
17329
17357
  }
17358
+ /**
17359
+ * `removeStyleByPath` removes the attributes of the elements in
17360
+ * the given path range.
17361
+ */
17362
+ removeStyleByPath(fromPath, toPath, attributesToRemove) {
17363
+ if (!this.context || !this.tree) {
17364
+ throw new YorkieError(
17365
+ Code.ErrNotInitialized,
17366
+ "Tree is not initialized yet"
17367
+ );
17368
+ }
17369
+ if (fromPath.length !== toPath.length) {
17370
+ throw new YorkieError(
17371
+ Code.ErrInvalidArgument,
17372
+ "path length should be equal"
17373
+ );
17374
+ }
17375
+ if (!fromPath.length || !toPath.length) {
17376
+ throw new YorkieError(
17377
+ Code.ErrInvalidArgument,
17378
+ "path should not be empty"
17379
+ );
17380
+ }
17381
+ const fromPos = this.tree.pathToPos(fromPath);
17382
+ const toPos = this.tree.pathToPos(toPath);
17383
+ const ticket = this.context.issueTimeTicket();
17384
+ const [pairs, , diff] = this.tree.removeStyle(
17385
+ [fromPos, toPos],
17386
+ attributesToRemove,
17387
+ ticket
17388
+ );
17389
+ this.context.acc(diff);
17390
+ for (const pair of pairs) {
17391
+ this.context.registerGCPair(pair);
17392
+ }
17393
+ this.context.push(
17394
+ TreeStyleOperation.createTreeRemoveStyleOperation(
17395
+ this.tree.getCreatedAt(),
17396
+ fromPos,
17397
+ toPos,
17398
+ attributesToRemove,
17399
+ ticket
17400
+ )
17401
+ );
17402
+ }
17330
17403
  editInternal(fromPos, toPos, contents, splitLevel = 0) {
17331
17404
  if (contents.length !== 0 && contents[0]) {
17332
17405
  validateTreeNodes(contents);
@@ -18711,6 +18784,7 @@
18711
18784
  DocEventType2["Unwatched"] = "unwatched";
18712
18785
  DocEventType2["PresenceChanged"] = "presence-changed";
18713
18786
  DocEventType2["AuthError"] = "auth-error";
18787
+ DocEventType2["EpochMismatch"] = "epoch-mismatch";
18714
18788
  return DocEventType2;
18715
18789
  })(DocEventType || {});
18716
18790
  var StreamConnectionStatus = /* @__PURE__ */ ((StreamConnectionStatus2) => {
@@ -19000,6 +19074,17 @@
19000
19074
  }
19001
19075
  }, arg3);
19002
19076
  }
19077
+ if (arg1 === "epoch-mismatch") {
19078
+ const callback2 = arg2;
19079
+ return this.eventStream.subscribe((event) => {
19080
+ for (const docEvent of event) {
19081
+ if (docEvent.type !== "epoch-mismatch") {
19082
+ continue;
19083
+ }
19084
+ callback2(docEvent);
19085
+ }
19086
+ }, arg3);
19087
+ }
19003
19088
  if (arg1 === "all") {
19004
19089
  const callback2 = arg2;
19005
19090
  return this.eventStream.subscribe(callback2, arg3, arg4);
@@ -19947,7 +20032,7 @@
19947
20032
  };
19948
20033
  }
19949
20034
  const name = "@yorkie-js/sdk";
19950
- const version = "0.7.2";
20035
+ const version = "0.7.3";
19951
20036
  const pkg = {
19952
20037
  name,
19953
20038
  version
@@ -20748,6 +20833,16 @@
20748
20833
  ).catch(
20749
20834
  async (err) => {
20750
20835
  logger.error(`[SY] c:"${this.getKey()}" err :`, err);
20836
+ if (isErrorCode(err, Code.ErrEpochMismatch)) {
20837
+ attachment.resource.publish([
20838
+ {
20839
+ type: DocEventType.EpochMismatch,
20840
+ value: {
20841
+ method: "PushPull"
20842
+ }
20843
+ }
20844
+ ]);
20845
+ }
20751
20846
  await this.handleConnectError(err);
20752
20847
  throw err;
20753
20848
  }
@@ -21131,6 +21226,16 @@
21131
21226
  }
21132
21227
  ]);
21133
21228
  }
21229
+ if (isErrorCode(e, Code.ErrEpochMismatch)) {
21230
+ attachment.resource.publish([
21231
+ {
21232
+ type: DocEventType.EpochMismatch,
21233
+ value: {
21234
+ method: "PushPull"
21235
+ }
21236
+ }
21237
+ ]);
21238
+ }
21134
21239
  throw e;
21135
21240
  })
21136
21241
  );
@@ -21560,6 +21665,9 @@
21560
21665
  if (errorCodeOf(err) === Code.ErrTooManyAttachments) {
21561
21666
  return false;
21562
21667
  }
21668
+ if (errorCodeOf(err) === Code.ErrEpochMismatch) {
21669
+ return false;
21670
+ }
21563
21671
  if (errorCodeOf(err) === Code.ErrClientNotActivated || errorCodeOf(err) === Code.ErrClientNotFound) {
21564
21672
  this.deactivateInternal();
21565
21673
  }