@yorkie-js/sdk 0.6.36 → 0.6.38

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.
@@ -13504,7 +13504,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
13504
13504
  constructor(key, value, isRed) {
13505
13505
  __publicField(this, "key");
13506
13506
  __publicField(this, "value");
13507
- __publicField(this, "parent");
13508
13507
  __publicField(this, "left");
13509
13508
  __publicField(this, "right");
13510
13509
  __publicField(this, "isRed");
@@ -13589,33 +13588,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
13589
13588
  */
13590
13589
  floorEntry(key) {
13591
13590
  let node = this.root;
13591
+ let result = void 0;
13592
13592
  while (node) {
13593
13593
  const compare = this.comparator(key, node.key);
13594
- if (compare > 0) {
13595
- if (node.right) {
13596
- node.right.parent = node;
13597
- node = node.right;
13598
- } else {
13599
- return node;
13600
- }
13594
+ if (compare === 0) {
13595
+ return node;
13601
13596
  } else if (compare < 0) {
13602
- if (node.left) {
13603
- node.left.parent = node;
13604
- node = node.left;
13605
- } else {
13606
- let parent = node.parent;
13607
- let childNode = node;
13608
- while (parent && childNode === parent.left) {
13609
- childNode = parent;
13610
- parent = parent.parent;
13611
- }
13612
- return parent;
13613
- }
13597
+ node = node.left;
13614
13598
  } else {
13615
- return node;
13599
+ result = node;
13600
+ node = node.right;
13616
13601
  }
13617
13602
  }
13618
- return;
13603
+ return result;
13619
13604
  }
13620
13605
  /**
13621
13606
  * `lastEntry` returns last entry of LLRBTree.
@@ -22291,7 +22276,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22291
22276
  };
22292
22277
  }
22293
22278
  const name = "@yorkie-js/sdk";
22294
- const version = "0.6.36";
22279
+ const version = "0.6.38";
22295
22280
  const pkg = {
22296
22281
  name,
22297
22282
  version
@@ -22331,6 +22316,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22331
22316
  ChannelEventType2["AuthError"] = "auth-error";
22332
22317
  return ChannelEventType2;
22333
22318
  })(ChannelEventType || {});
22319
+ const KeyPathSeparator = ".";
22334
22320
  class Channel {
22335
22321
  /**
22336
22322
  * @param key - the key of the channel.
@@ -22344,6 +22330,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22344
22330
  __publicField(this, "seq");
22345
22331
  __publicField(this, "eventStream");
22346
22332
  __publicField(this, "eventStreamObserver");
22333
+ this.validateChannelKey(key);
22347
22334
  this.key = key;
22348
22335
  this.status = "detached";
22349
22336
  this.count = 0;
@@ -22358,6 +22345,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22358
22345
  getKey() {
22359
22346
  return this.key;
22360
22347
  }
22348
+ /**
22349
+ * `getFirstKeyPath` returns the first key path to the presence count.
22350
+ */
22351
+ getFirstKeyPath() {
22352
+ return this.key.split(KeyPathSeparator)[0];
22353
+ }
22361
22354
  /**
22362
22355
  * `getStatus` returns the status of this channel.
22363
22356
  */
@@ -22503,6 +22496,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22503
22496
  options
22504
22497
  });
22505
22498
  }
22499
+ validateChannelKey(key) {
22500
+ if (key === "") {
22501
+ throw new Error("channel key must not be empty");
22502
+ }
22503
+ if (key.includes(" ")) {
22504
+ throw new Error("channel key must not contain a whitespace");
22505
+ }
22506
+ if (key.startsWith(KeyPathSeparator)) {
22507
+ throw new Error("channel key must not start with a period");
22508
+ }
22509
+ if (key.endsWith(KeyPathSeparator)) {
22510
+ throw new Error("channel key must not end with a period");
22511
+ }
22512
+ if (key.includes(`${KeyPathSeparator}${KeyPathSeparator}`)) {
22513
+ throw new Error("channel key path must not empty");
22514
+ }
22515
+ }
22506
22516
  }
22507
22517
  var SyncMode = /* @__PURE__ */ ((SyncMode2) => {
22508
22518
  SyncMode2["Manual"] = "manual";
@@ -22861,7 +22871,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22861
22871
  clientId: this.id,
22862
22872
  channelKey: channel.getKey()
22863
22873
  },
22864
- { headers: { "x-shard-key": `${this.apiKey}/${channel.getKey()}` } }
22874
+ {
22875
+ headers: {
22876
+ "x-shard-key": `${this.apiKey}/${channel.getFirstKeyPath()}`
22877
+ }
22878
+ }
22865
22879
  );
22866
22880
  channel.setSessionID(res.sessionId);
22867
22881
  channel.updateCount(Number(res.count), 0);
@@ -22925,7 +22939,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
22925
22939
  channelKey: channel.getKey(),
22926
22940
  sessionId: channel.getSessionID()
22927
22941
  },
22928
- { headers: { "x-shard-key": `${this.apiKey}/${channel.getKey()}` } }
22942
+ {
22943
+ headers: {
22944
+ "x-shard-key": `${this.apiKey}/${channel.getFirstKeyPath()}`
22945
+ }
22946
+ }
22929
22947
  );
22930
22948
  channel.updateCount(Number(res.count), 0);
22931
22949
  channel.applyStatus(ChannelStatus.Detached);
@@ -23136,6 +23154,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
23136
23154
  "payload is not serializable"
23137
23155
  );
23138
23156
  }
23157
+ const ch = attachment.resource;
23139
23158
  const maxRetries = (options == null ? void 0 : options.maxRetries) ?? DefaultBroadcastOptions.maxRetries;
23140
23159
  const maxBackoff = DefaultBroadcastOptions.maxBackoff;
23141
23160
  let retryCount = 0;
@@ -23156,7 +23175,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
23156
23175
  topic,
23157
23176
  payload: new TextEncoder().encode(JSON.stringify(payload))
23158
23177
  },
23159
- { headers: { "x-shard-key": `${this.apiKey}/${key}` } }
23178
+ {
23179
+ headers: {
23180
+ "x-shard-key": `${this.apiKey}/${ch.getFirstKeyPath()}`
23181
+ }
23182
+ }
23160
23183
  );
23161
23184
  logger.info(
23162
23185
  `[BC] c:"${this.getKey()}" broadcasts p:"${key}" t:"${topic}"`
@@ -23417,7 +23440,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
23417
23440
  channelKey: key
23418
23441
  },
23419
23442
  {
23420
- headers: { "x-shard-key": `${this.apiKey}/${key}` },
23443
+ headers: {
23444
+ "x-shard-key": `${this.apiKey}/${attachment.resource.getFirstKeyPath()}`
23445
+ },
23421
23446
  signal: ac.signal
23422
23447
  }
23423
23448
  );
@@ -23541,7 +23566,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
23541
23566
  },
23542
23567
  {
23543
23568
  headers: {
23544
- "x-shard-key": `${this.apiKey}/${resource.getKey()}`
23569
+ "x-shard-key": `${this.apiKey}/${resource.getFirstKeyPath()}`
23545
23570
  }
23546
23571
  }
23547
23572
  );