@yorkie-js/sdk 0.7.4 → 0.7.6

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.
@@ -104,7 +104,7 @@
104
104
  }
105
105
  bytes.push(hi >>> 31 & 1);
106
106
  }
107
- const TWO_PWR_32_DBL$1 = 4294967296;
107
+ const TWO_PWR_32_DBL = 4294967296;
108
108
  function int64FromString(dec) {
109
109
  const minus = dec[0] === "-";
110
110
  if (minus) {
@@ -117,9 +117,9 @@
117
117
  const digit1e6 = Number(dec.slice(begin, end));
118
118
  highBits *= base;
119
119
  lowBits = lowBits * base + digit1e6;
120
- if (lowBits >= TWO_PWR_32_DBL$1) {
121
- highBits = highBits + (lowBits / TWO_PWR_32_DBL$1 | 0);
122
- lowBits = lowBits % TWO_PWR_32_DBL$1;
120
+ if (lowBits >= TWO_PWR_32_DBL) {
121
+ highBits = highBits + (lowBits / TWO_PWR_32_DBL | 0);
122
+ lowBits = lowBits % TWO_PWR_32_DBL;
123
123
  }
124
124
  }
125
125
  add1e6digit(-24, -18);
@@ -140,7 +140,7 @@
140
140
  function uInt64ToString(lo, hi) {
141
141
  ({ lo, hi } = toUnsigned(lo, hi));
142
142
  if (hi <= 2097151) {
143
- return String(TWO_PWR_32_DBL$1 * hi + lo);
143
+ return String(TWO_PWR_32_DBL * hi + lo);
144
144
  }
145
145
  const low = lo & 16777215;
146
146
  const mid = (lo >>> 24 | hi << 8) & 16777215;
@@ -4387,6 +4387,19 @@
4387
4387
  }
4388
4388
  return name2[0].toLowerCase() + name2.substring(1).replace(/[A-Z]/g, (c) => "_" + c.toLowerCase());
4389
4389
  }
4390
+ let stringToCode;
4391
+ function codeFromString(value) {
4392
+ if (!stringToCode) {
4393
+ stringToCode = {};
4394
+ for (const value2 of Object.values(Code$1)) {
4395
+ if (typeof value2 == "string") {
4396
+ continue;
4397
+ }
4398
+ stringToCode[codeToString(value2)] = value2;
4399
+ }
4400
+ }
4401
+ return stringToCode[value];
4402
+ }
4390
4403
  class ConnectError extends Error {
4391
4404
  /**
4392
4405
  * Create a new ConnectError.
@@ -4475,6 +4488,15 @@
4475
4488
  throw ConnectError.from(e, Code$1.DataLoss);
4476
4489
  }
4477
4490
  }
4491
+ function appendHeaders(...headers) {
4492
+ const h = new Headers();
4493
+ for (const e of headers) {
4494
+ e.forEach((value, key) => {
4495
+ h.append(key, value);
4496
+ });
4497
+ }
4498
+ return h;
4499
+ }
4478
4500
  function makeAnyClient(service, createMethod) {
4479
4501
  const client = {};
4480
4502
  for (const desc of service.methods) {
@@ -4622,10 +4644,10 @@
4622
4644
  }, reject);
4623
4645
  }
4624
4646
  };
4625
- var __await$2 = function(v) {
4626
- return this instanceof __await$2 ? (this.v = v, this) : new __await$2(v);
4647
+ var __await$3 = function(v) {
4648
+ return this instanceof __await$3 ? (this.v = v, this) : new __await$3(v);
4627
4649
  };
4628
- var __asyncGenerator$2 = function(thisArg, _arguments, generator) {
4650
+ var __asyncGenerator$3 = function(thisArg, _arguments, generator) {
4629
4651
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4630
4652
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
4631
4653
  return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
@@ -4654,7 +4676,7 @@
4654
4676
  }
4655
4677
  }
4656
4678
  function step(r) {
4657
- r.value instanceof __await$2 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
4679
+ r.value instanceof __await$3 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
4658
4680
  }
4659
4681
  function fulfill(value) {
4660
4682
  resume("next", value);
@@ -4675,13 +4697,13 @@
4675
4697
  }, i;
4676
4698
  function verb(n, f) {
4677
4699
  i[n] = o[n] ? function(v) {
4678
- return (p = !p) ? { value: __await$2(o[n](v)), done: false } : f ? f(v) : v;
4700
+ return (p = !p) ? { value: __await$3(o[n](v)), done: false } : f ? f(v) : v;
4679
4701
  } : f;
4680
4702
  }
4681
4703
  };
4682
4704
  function createAsyncIterable(items) {
4683
- return __asyncGenerator$2(this, arguments, function* createAsyncIterable_1() {
4684
- yield __await$2(yield* __asyncDelegator$1(__asyncValues$1(items)));
4705
+ return __asyncGenerator$3(this, arguments, function* createAsyncIterable_1() {
4706
+ yield __await$3(yield* __asyncDelegator$1(__asyncValues$1(items)));
4685
4707
  });
4686
4708
  }
4687
4709
  var __asyncValues = function(o) {
@@ -4703,8 +4725,8 @@
4703
4725
  }, reject);
4704
4726
  }
4705
4727
  };
4706
- var __await$1 = function(v) {
4707
- return this instanceof __await$1 ? (this.v = v, this) : new __await$1(v);
4728
+ var __await$2 = function(v) {
4729
+ return this instanceof __await$2 ? (this.v = v, this) : new __await$2(v);
4708
4730
  };
4709
4731
  var __asyncDelegator = function(o) {
4710
4732
  var i, p;
@@ -4715,11 +4737,11 @@
4715
4737
  }, i;
4716
4738
  function verb(n, f) {
4717
4739
  i[n] = o[n] ? function(v) {
4718
- return (p = !p) ? { value: __await$1(o[n](v)), done: false } : f ? f(v) : v;
4740
+ return (p = !p) ? { value: __await$2(o[n](v)), done: false } : f ? f(v) : v;
4719
4741
  } : f;
4720
4742
  }
4721
4743
  };
4722
- var __asyncGenerator$1 = function(thisArg, _arguments, generator) {
4744
+ var __asyncGenerator$2 = function(thisArg, _arguments, generator) {
4723
4745
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4724
4746
  var g = generator.apply(thisArg, _arguments || []), i, q = [];
4725
4747
  return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
@@ -4748,7 +4770,7 @@
4748
4770
  }
4749
4771
  }
4750
4772
  function step(r) {
4751
- r.value instanceof __await$1 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
4773
+ r.value instanceof __await$2 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
4752
4774
  }
4753
4775
  function fulfill(value) {
4754
4776
  resume("next", value);
@@ -4828,11 +4850,11 @@
4828
4850
  }
4829
4851
  function handleStreamResponse(stream, options) {
4830
4852
  const it = (function() {
4831
- return __asyncGenerator$1(this, arguments, function* () {
4853
+ return __asyncGenerator$2(this, arguments, function* () {
4832
4854
  var _a, _b;
4833
- const response = yield __await$1(stream);
4855
+ const response = yield __await$2(stream);
4834
4856
  (_a = options === null || options === void 0 ? void 0 : options.onHeader) === null || _a === void 0 ? void 0 : _a.call(options, response.header);
4835
- yield __await$1(yield* __asyncDelegator(__asyncValues(response.message)));
4857
+ yield __await$2(yield* __asyncDelegator(__asyncValues(response.message)));
4836
4858
  (_b = options === null || options === void 0 ? void 0 : options.onTrailer) === null || _b === void 0 ? void 0 : _b.call(options, response.trailer);
4837
4859
  });
4838
4860
  })()[Symbol.asyncIterator]();
@@ -4922,12 +4944,12 @@
4922
4944
  }
4923
4945
  return headers;
4924
4946
  }
4925
- const headerContentType = "Content-Type";
4926
- const headerTimeout = "Grpc-Timeout";
4947
+ const headerContentType$1 = "Content-Type";
4948
+ const headerTimeout$1 = "Grpc-Timeout";
4927
4949
  const headerGrpcStatus = "Grpc-Status";
4928
4950
  const headerGrpcMessage = "Grpc-Message";
4929
4951
  const headerStatusDetailsBin = "Grpc-Status-Details-Bin";
4930
- const headerUserAgent = "User-Agent";
4952
+ const headerUserAgent$1 = "User-Agent";
4931
4953
  const headerXUserAgent = "X-User-Agent";
4932
4954
  const headerXGrpcWeb = "X-Grpc-Web";
4933
4955
  const contentTypeProto = "application/grpc-web+proto";
@@ -5065,6 +5087,204 @@
5065
5087
  }
5066
5088
  };
5067
5089
  }
5090
+ const contentTypeRegExp = /^application\/(connect\+)?(?:(json)(?:; ?charset=utf-?8)?|(proto))$/i;
5091
+ const contentTypeUnaryProto = "application/proto";
5092
+ const contentTypeUnaryJson = "application/json";
5093
+ const contentTypeStreamProto = "application/connect+proto";
5094
+ const contentTypeStreamJson = "application/connect+json";
5095
+ function parseContentType(contentType) {
5096
+ const match = contentType === null || contentType === void 0 ? void 0 : contentType.match(contentTypeRegExp);
5097
+ if (!match) {
5098
+ return void 0;
5099
+ }
5100
+ const stream = !!match[1];
5101
+ const binary = !!match[3];
5102
+ return { stream, binary };
5103
+ }
5104
+ (function(s, e) {
5105
+ var t = {};
5106
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5107
+ t[p] = s[p];
5108
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
5109
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
5110
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
5111
+ t[p[i]] = s[p[i]];
5112
+ }
5113
+ return t;
5114
+ });
5115
+ function errorFromJson(jsonValue, metadata, fallback) {
5116
+ var _a;
5117
+ if (metadata) {
5118
+ new Headers(metadata).forEach((value, key) => fallback.metadata.append(key, value));
5119
+ }
5120
+ if (typeof jsonValue !== "object" || jsonValue == null || Array.isArray(jsonValue)) {
5121
+ throw fallback;
5122
+ }
5123
+ let code = fallback.code;
5124
+ if ("code" in jsonValue && typeof jsonValue.code === "string") {
5125
+ code = (_a = codeFromString(jsonValue.code)) !== null && _a !== void 0 ? _a : code;
5126
+ }
5127
+ const message = jsonValue.message;
5128
+ if (message != null && typeof message !== "string") {
5129
+ throw fallback;
5130
+ }
5131
+ const error = new ConnectError(message !== null && message !== void 0 ? message : "", code, metadata);
5132
+ if ("details" in jsonValue && Array.isArray(jsonValue.details)) {
5133
+ for (const detail of jsonValue.details) {
5134
+ if (detail === null || typeof detail != "object" || Array.isArray(detail) || typeof detail.type != "string" || typeof detail.value != "string") {
5135
+ throw fallback;
5136
+ }
5137
+ try {
5138
+ error.details.push({
5139
+ type: detail.type,
5140
+ value: base64Decode(detail.value),
5141
+ debug: detail.debug
5142
+ });
5143
+ } catch (e) {
5144
+ throw fallback;
5145
+ }
5146
+ }
5147
+ }
5148
+ return error;
5149
+ }
5150
+ const endStreamFlag = 2;
5151
+ function endStreamFromJson(data) {
5152
+ const parseErr = new ConnectError("invalid end stream", Code$1.Unknown);
5153
+ let jsonValue;
5154
+ try {
5155
+ jsonValue = JSON.parse(typeof data == "string" ? data : new TextDecoder().decode(data));
5156
+ } catch (e) {
5157
+ throw parseErr;
5158
+ }
5159
+ if (typeof jsonValue != "object" || jsonValue == null || Array.isArray(jsonValue)) {
5160
+ throw parseErr;
5161
+ }
5162
+ const metadata = new Headers();
5163
+ if ("metadata" in jsonValue) {
5164
+ if (typeof jsonValue.metadata != "object" || jsonValue.metadata == null || Array.isArray(jsonValue.metadata)) {
5165
+ throw parseErr;
5166
+ }
5167
+ for (const [key, values] of Object.entries(jsonValue.metadata)) {
5168
+ if (!Array.isArray(values) || values.some((value) => typeof value != "string")) {
5169
+ throw parseErr;
5170
+ }
5171
+ for (const value of values) {
5172
+ metadata.append(key, value);
5173
+ }
5174
+ }
5175
+ }
5176
+ const error = "error" in jsonValue && jsonValue.error != null ? errorFromJson(jsonValue.error, metadata, parseErr) : void 0;
5177
+ return { metadata, error };
5178
+ }
5179
+ const headerContentType = "Content-Type";
5180
+ const headerUnaryContentLength = "Content-Length";
5181
+ const headerUnaryEncoding = "Content-Encoding";
5182
+ const headerUnaryAcceptEncoding = "Accept-Encoding";
5183
+ const headerTimeout = "Connect-Timeout-Ms";
5184
+ const headerProtocolVersion = "Connect-Protocol-Version";
5185
+ const headerUserAgent = "User-Agent";
5186
+ function codeFromHttpStatus$1(httpStatus) {
5187
+ switch (httpStatus) {
5188
+ case 400:
5189
+ return Code$1.Internal;
5190
+ case 401:
5191
+ return Code$1.Unauthenticated;
5192
+ case 403:
5193
+ return Code$1.PermissionDenied;
5194
+ case 404:
5195
+ return Code$1.Unimplemented;
5196
+ case 429:
5197
+ return Code$1.Unavailable;
5198
+ case 502:
5199
+ return Code$1.Unavailable;
5200
+ case 503:
5201
+ return Code$1.Unavailable;
5202
+ case 504:
5203
+ return Code$1.Unavailable;
5204
+ default:
5205
+ return Code$1.Unknown;
5206
+ }
5207
+ }
5208
+ function trailerDemux(header) {
5209
+ const h = new Headers(), t = new Headers();
5210
+ header.forEach((value, key) => {
5211
+ if (key.toLowerCase().startsWith("trailer-")) {
5212
+ t.append(key.substring(8), value);
5213
+ } else {
5214
+ h.append(key, value);
5215
+ }
5216
+ });
5217
+ return [h, t];
5218
+ }
5219
+ const protocolVersion = "1";
5220
+ function requestHeader$1(methodKind, useBinaryFormat, timeoutMs, userProvidedHeaders, setUserAgent) {
5221
+ const result = new Headers(userProvidedHeaders !== null && userProvidedHeaders !== void 0 ? userProvidedHeaders : {});
5222
+ if (timeoutMs !== void 0) {
5223
+ result.set(headerTimeout, `${timeoutMs}`);
5224
+ }
5225
+ result.set(headerContentType, methodKind == "unary" ? useBinaryFormat ? contentTypeUnaryProto : contentTypeUnaryJson : useBinaryFormat ? contentTypeStreamProto : contentTypeStreamJson);
5226
+ result.set(headerProtocolVersion, protocolVersion);
5227
+ if (!result.has(headerUserAgent) && setUserAgent) ;
5228
+ return result;
5229
+ }
5230
+ function validateResponse$1(methodKind, useBinaryFormat, status, headers) {
5231
+ const mimeType = headers.get(headerContentType);
5232
+ const parsedType = parseContentType(mimeType);
5233
+ if (status !== 200) {
5234
+ const errorFromStatus = new ConnectError(`HTTP ${status}`, codeFromHttpStatus$1(status), headers);
5235
+ if (methodKind == "unary" && parsedType && !parsedType.binary) {
5236
+ return { isUnaryError: true, unaryError: errorFromStatus };
5237
+ }
5238
+ throw errorFromStatus;
5239
+ }
5240
+ const allowedContentType = {
5241
+ binary: useBinaryFormat,
5242
+ stream: methodKind !== "unary"
5243
+ };
5244
+ if ((parsedType === null || parsedType === void 0 ? void 0 : parsedType.binary) !== allowedContentType.binary || parsedType.stream !== allowedContentType.stream) {
5245
+ throw new ConnectError(`unsupported content type ${mimeType}`, parsedType === void 0 ? Code$1.Unknown : Code$1.Internal, headers);
5246
+ }
5247
+ return { isUnaryError: false };
5248
+ }
5249
+ const contentTypePrefix = "application/";
5250
+ function encodeMessageForUrl(message, useBase64) {
5251
+ if (useBase64) {
5252
+ return base64Encode(message, "url");
5253
+ }
5254
+ return encodeURIComponent(new TextDecoder().decode(message));
5255
+ }
5256
+ function transformConnectPostToGetRequest(request, message, useBase64) {
5257
+ let query = `?connect=v${protocolVersion}`;
5258
+ const contentType = request.header.get(headerContentType);
5259
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(contentTypePrefix)) === 0) {
5260
+ query += "&encoding=" + encodeURIComponent(contentType.slice(contentTypePrefix.length));
5261
+ }
5262
+ const compression = request.header.get(headerUnaryEncoding);
5263
+ if (compression !== null && compression !== "identity") {
5264
+ query += "&compression=" + encodeURIComponent(compression);
5265
+ useBase64 = true;
5266
+ }
5267
+ if (useBase64) {
5268
+ query += "&base64=1";
5269
+ }
5270
+ query += "&message=" + encodeMessageForUrl(message, useBase64);
5271
+ const url = request.url + query;
5272
+ const header = new Headers(request.header);
5273
+ for (const h of [
5274
+ headerProtocolVersion,
5275
+ headerContentType,
5276
+ headerUnaryContentLength,
5277
+ headerUnaryEncoding,
5278
+ headerUnaryAcceptEncoding
5279
+ ]) {
5280
+ header.delete(h);
5281
+ }
5282
+ return Object.assign(Object.assign({}, request), {
5283
+ requestMethod: "GET",
5284
+ url,
5285
+ header
5286
+ });
5287
+ }
5068
5288
  function runUnaryCall(opt) {
5069
5289
  const next = applyInterceptors(opt.next, opt.interceptors);
5070
5290
  const [signal, abort, done] = setupSignal(opt);
@@ -5133,6 +5353,181 @@
5133
5353
  throw new Error("connect-web requires the fetch API. Are you running on an old version of Node.js? Node.js is not supported in Connect for Web - please stay tuned for Connect for Node.");
5134
5354
  }
5135
5355
  }
5356
+ var __await$1 = function(v) {
5357
+ return this instanceof __await$1 ? (this.v = v, this) : new __await$1(v);
5358
+ };
5359
+ var __asyncGenerator$1 = function(thisArg, _arguments, generator) {
5360
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5361
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
5362
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
5363
+ return this;
5364
+ }, i;
5365
+ function awaitReturn(f) {
5366
+ return function(v) {
5367
+ return Promise.resolve(v).then(f, reject);
5368
+ };
5369
+ }
5370
+ function verb(n, f) {
5371
+ if (g[n]) {
5372
+ i[n] = function(v) {
5373
+ return new Promise(function(a, b) {
5374
+ q.push([n, v, a, b]) > 1 || resume(n, v);
5375
+ });
5376
+ };
5377
+ if (f) i[n] = f(i[n]);
5378
+ }
5379
+ }
5380
+ function resume(n, v) {
5381
+ try {
5382
+ step(g[n](v));
5383
+ } catch (e) {
5384
+ settle(q[0][3], e);
5385
+ }
5386
+ }
5387
+ function step(r) {
5388
+ r.value instanceof __await$1 ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
5389
+ }
5390
+ function fulfill(value) {
5391
+ resume("next", value);
5392
+ }
5393
+ function reject(value) {
5394
+ resume("throw", value);
5395
+ }
5396
+ function settle(f, v) {
5397
+ if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
5398
+ }
5399
+ };
5400
+ const fetchOptions$1 = {
5401
+ redirect: "error"
5402
+ };
5403
+ function createConnectTransport(options) {
5404
+ var _a;
5405
+ assertFetchApi();
5406
+ const useBinaryFormat = (_a = options.useBinaryFormat) !== null && _a !== void 0 ? _a : false;
5407
+ return {
5408
+ async unary(method, signal, timeoutMs, header, message, contextValues) {
5409
+ const { serialize, parse: parse2 } = createClientMethodSerializers(method, useBinaryFormat, options.jsonOptions, options.binaryOptions);
5410
+ timeoutMs = timeoutMs === void 0 ? options.defaultTimeoutMs : timeoutMs <= 0 ? void 0 : timeoutMs;
5411
+ return await runUnaryCall({
5412
+ interceptors: options.interceptors,
5413
+ signal,
5414
+ timeoutMs,
5415
+ req: {
5416
+ stream: false,
5417
+ service: method.parent,
5418
+ method,
5419
+ requestMethod: "POST",
5420
+ url: createMethodUrl(options.baseUrl, method),
5421
+ header: requestHeader$1(method.methodKind, useBinaryFormat, timeoutMs, header, false),
5422
+ contextValues: contextValues !== null && contextValues !== void 0 ? contextValues : createContextValues(),
5423
+ message
5424
+ },
5425
+ next: async (req) => {
5426
+ var _a2;
5427
+ const useGet = options.useHttpGet === true && method.idempotency === MethodOptions_IdempotencyLevel.NO_SIDE_EFFECTS;
5428
+ let body = null;
5429
+ if (useGet) {
5430
+ req = transformConnectPostToGetRequest(req, serialize(req.message), useBinaryFormat);
5431
+ } else {
5432
+ body = serialize(req.message);
5433
+ }
5434
+ const fetch2 = (_a2 = options.fetch) !== null && _a2 !== void 0 ? _a2 : globalThis.fetch;
5435
+ const response = await fetch2(req.url, Object.assign(Object.assign({}, fetchOptions$1), { method: req.requestMethod, headers: req.header, signal: req.signal, body }));
5436
+ const { isUnaryError, unaryError } = validateResponse$1(method.methodKind, useBinaryFormat, response.status, response.headers);
5437
+ if (isUnaryError) {
5438
+ throw errorFromJson(await response.json(), appendHeaders(...trailerDemux(response.headers)), unaryError);
5439
+ }
5440
+ const [demuxedHeader, demuxedTrailer] = trailerDemux(response.headers);
5441
+ return {
5442
+ stream: false,
5443
+ service: method.parent,
5444
+ method,
5445
+ header: demuxedHeader,
5446
+ message: useBinaryFormat ? parse2(new Uint8Array(await response.arrayBuffer())) : fromJson(method.output, await response.json(), getJsonOptions(options.jsonOptions)),
5447
+ trailer: demuxedTrailer
5448
+ };
5449
+ }
5450
+ });
5451
+ },
5452
+ async stream(method, signal, timeoutMs, header, input, contextValues) {
5453
+ const { serialize, parse: parse2 } = createClientMethodSerializers(method, useBinaryFormat, options.jsonOptions, options.binaryOptions);
5454
+ function parseResponseBody(body, trailerTarget, header2, signal2) {
5455
+ return __asyncGenerator$1(this, arguments, function* parseResponseBody_1() {
5456
+ const reader = createEnvelopeReadableStream(body).getReader();
5457
+ let endStreamReceived = false;
5458
+ for (; ; ) {
5459
+ const result = yield __await$1(reader.read());
5460
+ if (result.done) {
5461
+ break;
5462
+ }
5463
+ const { flags, data } = result.value;
5464
+ if ((flags & compressedFlag) === compressedFlag) {
5465
+ throw new ConnectError(`protocol error: received unsupported compressed output`, Code$1.Internal);
5466
+ }
5467
+ if ((flags & endStreamFlag) === endStreamFlag) {
5468
+ endStreamReceived = true;
5469
+ const endStream = endStreamFromJson(data);
5470
+ if (endStream.error) {
5471
+ const error = endStream.error;
5472
+ header2.forEach((value, key) => {
5473
+ error.metadata.append(key, value);
5474
+ });
5475
+ throw error;
5476
+ }
5477
+ endStream.metadata.forEach((value, key) => trailerTarget.set(key, value));
5478
+ continue;
5479
+ }
5480
+ yield yield __await$1(parse2(data));
5481
+ }
5482
+ if ("throwIfAborted" in signal2) {
5483
+ signal2.throwIfAborted();
5484
+ }
5485
+ if (!endStreamReceived) {
5486
+ throw "missing EndStreamResponse";
5487
+ }
5488
+ });
5489
+ }
5490
+ async function createRequestBody(input2) {
5491
+ if (method.methodKind != "server_streaming") {
5492
+ throw "The fetch API does not support streaming request bodies";
5493
+ }
5494
+ const r = await input2[Symbol.asyncIterator]().next();
5495
+ if (r.done == true) {
5496
+ throw "missing request message";
5497
+ }
5498
+ return encodeEnvelope(0, serialize(r.value));
5499
+ }
5500
+ timeoutMs = timeoutMs === void 0 ? options.defaultTimeoutMs : timeoutMs <= 0 ? void 0 : timeoutMs;
5501
+ return await runStreamingCall({
5502
+ interceptors: options.interceptors,
5503
+ timeoutMs,
5504
+ signal,
5505
+ req: {
5506
+ stream: true,
5507
+ service: method.parent,
5508
+ method,
5509
+ requestMethod: "POST",
5510
+ url: createMethodUrl(options.baseUrl, method),
5511
+ header: requestHeader$1(method.methodKind, useBinaryFormat, timeoutMs, header, false),
5512
+ contextValues: contextValues !== null && contextValues !== void 0 ? contextValues : createContextValues(),
5513
+ message: input
5514
+ },
5515
+ next: async (req) => {
5516
+ var _a2;
5517
+ const fetch2 = (_a2 = options.fetch) !== null && _a2 !== void 0 ? _a2 : globalThis.fetch;
5518
+ const fRes = await fetch2(req.url, Object.assign(Object.assign({}, fetchOptions$1), { method: req.requestMethod, headers: req.header, signal: req.signal, body: await createRequestBody(req.message) }));
5519
+ validateResponse$1(method.methodKind, useBinaryFormat, fRes.status, fRes.headers);
5520
+ if (fRes.body === null) {
5521
+ throw "missing response body";
5522
+ }
5523
+ const trailer = new Headers();
5524
+ const res = Object.assign(Object.assign({}, req), { header: fRes.headers, trailer, message: parseResponseBody(fRes.body, trailer, fRes.headers, req.signal) });
5525
+ return res;
5526
+ }
5527
+ });
5528
+ }
5529
+ };
5530
+ }
5136
5531
  function validateTrailer(trailer, header) {
5137
5532
  const err = findTrailerError(trailer);
5138
5533
  if (err) {
@@ -5148,12 +5543,12 @@
5148
5543
  function requestHeader(useBinaryFormat, timeoutMs, userProvidedHeaders, setUserAgent) {
5149
5544
  var _a, _b;
5150
5545
  const result = new Headers(userProvidedHeaders !== null && userProvidedHeaders !== void 0 ? userProvidedHeaders : {});
5151
- result.set(headerContentType, useBinaryFormat ? contentTypeProto : contentTypeJson);
5546
+ result.set(headerContentType$1, useBinaryFormat ? contentTypeProto : contentTypeJson);
5152
5547
  result.set(headerXGrpcWeb, "1");
5153
- const userAgent = (_b = (_a = result.get(headerUserAgent)) !== null && _a !== void 0 ? _a : result.get(headerXUserAgent)) !== null && _b !== void 0 ? _b : "connect-es/2.1.1";
5548
+ const userAgent = (_b = (_a = result.get(headerUserAgent$1)) !== null && _a !== void 0 ? _a : result.get(headerXUserAgent)) !== null && _b !== void 0 ? _b : "connect-es/2.1.1";
5154
5549
  result.set(headerXUserAgent, userAgent);
5155
5550
  if (timeoutMs !== void 0) {
5156
- result.set(headerTimeout, `${timeoutMs}m`);
5551
+ result.set(headerTimeout$1, `${timeoutMs}m`);
5157
5552
  }
5158
5553
  return result;
5159
5554
  }
@@ -5397,7 +5792,7 @@
5397
5792
  }
5398
5793
  };
5399
5794
  }
5400
- const file_src_api_yorkie_v1_resources = /* @__PURE__ */ fileDesc("CiFzcmMvYXBpL3lvcmtpZS92MS9yZXNvdXJjZXMucHJvdG8SCXlvcmtpZS52MSKuAQoIU25hcHNob3QSJAoEcm9vdBgBIAEoCzIWLnlvcmtpZS52MS5KU09ORWxlbWVudBI1CglwcmVzZW5jZXMYAiADKAsyIi55b3JraWUudjEuU25hcHNob3QuUHJlc2VuY2VzRW50cnkaRQoOUHJlc2VuY2VzRW50cnkSCwoDa2V5GAEgASgJEiIKBXZhbHVlGAIgASgLMhMueW9ya2llLnYxLlByZXNlbmNlOgI4ASL7AQoKQ2hhbmdlUGFjaxIUCgxkb2N1bWVudF9rZXkYASABKAkSKQoKY2hlY2twb2ludBgCIAEoCzIVLnlvcmtpZS52MS5DaGVja3BvaW50EhAKCHNuYXBzaG90GAMgASgMEiIKB2NoYW5nZXMYBCADKAsyES55b3JraWUudjEuQ2hhbmdlEjAKEW1pbl9zeW5jZWRfdGlja2V0GAUgASgLMhUueW9ya2llLnYxLlRpbWVUaWNrZXQSEgoKaXNfcmVtb3ZlZBgGIAEoCBIwCg52ZXJzaW9uX3ZlY3RvchgHIAEoCzIYLnlvcmtpZS52MS5WZXJzaW9uVmVjdG9yIpgBCgZDaGFuZ2USHwoCaWQYASABKAsyEy55b3JraWUudjEuQ2hhbmdlSUQSDwoHbWVzc2FnZRgCIAEoCRIoCgpvcGVyYXRpb25zGAMgAygLMhQueW9ya2llLnYxLk9wZXJhdGlvbhIyCg9wcmVzZW5jZV9jaGFuZ2UYBCABKAsyGS55b3JraWUudjEuUHJlc2VuY2VDaGFuZ2UihwEKCENoYW5nZUlEEhIKCmNsaWVudF9zZXEYASABKA0SEgoKc2VydmVyX3NlcRgCIAEoAxIPCgdsYW1wb3J0GAMgASgDEhAKCGFjdG9yX2lkGAQgASgMEjAKDnZlcnNpb25fdmVjdG9yGAUgASgLMhgueW9ya2llLnYxLlZlcn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Q05UEAwSEwoPVkFMVUVfVFlQRV9UUkVFEA0qpgEKDERvY0V2ZW50VHlwZRIjCh9ET0NfRVZFTlRfVFlQRV9ET0NVTUVOVF9DSEFOR0VEEAASIwofRE9DX0VWRU5UX1RZUEVfRE9DVU1FTlRfV0FUQ0hFRBABEiUKIURPQ19FVkVOVF9UWVBFX0RPQ1VNRU5UX1VOV0FUQ0hFRBACEiUKIURPQ19FVkVOVF9UWVBFX0RPQ1VNRU5UX0JST0FEQ0FTVBADQkUKEWRldi55b3JraWUuYXBpLnYxUAFaLmdpdGh1Yi5jb20veW9ya2llLXRlYW0veW9ya2llL2FwaS95b3JraWUvdjE7djFiBnByb3RvMw", [file_google_protobuf_timestamp, file_google_protobuf_wrappers]);
5795
+ const file_src_api_yorkie_v1_resources = /* @__PURE__ */ fileDesc("CiFzcmMvYXBpL3lvcmtpZS92MS9yZXNvdXJjZXMucHJvdG8SCXlvcmtpZS52MSKuAQoIU25hcHNob3QSJAoEcm9vdBgBIAEoCzIWLnlvcmtpZS52MS5KU09ORWxlbWVudBI1CglwcmVzZW5jZXMYAiADKAsyIi55b3JraWUudjEuU25hcHNob3QuUHJlc2VuY2VzRW50cnkaRQoOUHJlc2VuY2VzRW50cnkSCwoDa2V5GAEgASgJEiIKBXZhbHVlGAIgASgLMhMueW9ya2llLnYxLlByZXNlbmNlOgI4ASL7AQoKQ2hhbmdlUGFjaxIUCgxkb2N1bWVudF9rZXkYASABKAkSKQoKY2hlY2twb2ludBgCIAEoCzIVLnlvcmtpZS52MS5DaGVja3BvaW50EhAKCHNuYXBzaG90GAMgASgMEiIKB2NoYW5nZXMYBCADKAsyES55b3JraWUudjEuQ2hhbmdlEjAKEW1pbl9zeW5jZWRfdGlja2V0GAUgASgLMhUueW9ya2llLnYxLlRpbWVUaWNrZXQSEgoKaXNfcmVtb3ZlZBgGIAEoCBIwCg52ZXJzaW9uX3ZlY3RvchgHIAEoCzIYLnlvcmtpZS52MS5WZXJzaW9uVmVjdG9yIpgB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dG8z", [file_google_protobuf_timestamp, file_google_protobuf_wrappers]);
5401
5796
  const SnapshotSchema = /* @__PURE__ */ messageDesc(file_src_api_yorkie_v1_resources, 0);
5402
5797
  const ChangePackSchema = /* @__PURE__ */ messageDesc(file_src_api_yorkie_v1_resources, 1);
5403
5798
  const ChangeSchema = /* @__PURE__ */ messageDesc(file_src_api_yorkie_v1_resources, 2);
@@ -5464,6 +5859,7 @@
5464
5859
  ValueType2[ValueType2["INTEGER_CNT"] = 11] = "INTEGER_CNT";
5465
5860
  ValueType2[ValueType2["LONG_CNT"] = 12] = "LONG_CNT";
5466
5861
  ValueType2[ValueType2["TREE"] = 13] = "TREE";
5862
+ ValueType2[ValueType2["INTEGER_DEDUP_CNT"] = 14] = "INTEGER_DEDUP_CNT";
5467
5863
  return ValueType2;
5468
5864
  })(ValueType || {});
5469
5865
  var DocEventType$1 = /* @__PURE__ */ ((DocEventType2) => {
@@ -6615,923 +7011,32 @@
6615
7011
  return false;
6616
7012
  }
6617
7013
  }
6618
- var wasm = null;
6619
- try {
6620
- wasm = new WebAssembly.Instance(
6621
- new WebAssembly.Module(
6622
- new Uint8Array([
6623
- // \0asm
6624
- 0,
6625
- 97,
6626
- 115,
6627
- 109,
6628
- // version 1
6629
- 1,
6630
- 0,
6631
- 0,
6632
- 0,
6633
- // section "type"
6634
- 1,
6635
- 13,
6636
- 2,
6637
- // 0, () => i32
6638
- 96,
6639
- 0,
6640
- 1,
6641
- 127,
6642
- // 1, (i32, i32, i32, i32) => i32
6643
- 96,
6644
- 4,
6645
- 127,
6646
- 127,
6647
- 127,
6648
- 127,
6649
- 1,
6650
- 127,
6651
- // section "function"
6652
- 3,
6653
- 7,
6654
- 6,
6655
- // 0, type 0
6656
- 0,
6657
- // 1, type 1
6658
- 1,
6659
- // 2, type 1
6660
- 1,
6661
- // 3, type 1
6662
- 1,
6663
- // 4, type 1
6664
- 1,
6665
- // 5, type 1
6666
- 1,
6667
- // section "global"
6668
- 6,
6669
- 6,
6670
- 1,
6671
- // 0, "high", mutable i32
6672
- 127,
6673
- 1,
6674
- 65,
6675
- 0,
6676
- 11,
6677
- // section "export"
6678
- 7,
6679
- 50,
6680
- 6,
6681
- // 0, "mul"
6682
- 3,
6683
- 109,
6684
- 117,
6685
- 108,
6686
- 0,
6687
- 1,
6688
- // 1, "div_s"
6689
- 5,
6690
- 100,
6691
- 105,
6692
- 118,
6693
- 95,
6694
- 115,
6695
- 0,
6696
- 2,
6697
- // 2, "div_u"
6698
- 5,
6699
- 100,
6700
- 105,
6701
- 118,
6702
- 95,
6703
- 117,
6704
- 0,
6705
- 3,
6706
- // 3, "rem_s"
6707
- 5,
6708
- 114,
6709
- 101,
6710
- 109,
6711
- 95,
6712
- 115,
6713
- 0,
6714
- 4,
6715
- // 4, "rem_u"
6716
- 5,
6717
- 114,
6718
- 101,
6719
- 109,
6720
- 95,
6721
- 117,
6722
- 0,
6723
- 5,
6724
- // 5, "get_high"
6725
- 8,
6726
- 103,
6727
- 101,
6728
- 116,
6729
- 95,
6730
- 104,
6731
- 105,
6732
- 103,
6733
- 104,
6734
- 0,
6735
- 0,
6736
- // section "code"
6737
- 10,
6738
- 191,
6739
- 1,
6740
- 6,
6741
- // 0, "get_high"
6742
- 4,
6743
- 0,
6744
- 35,
6745
- 0,
6746
- 11,
6747
- // 1, "mul"
6748
- 36,
6749
- 1,
6750
- 1,
6751
- 126,
6752
- 32,
6753
- 0,
6754
- 173,
6755
- 32,
6756
- 1,
6757
- 173,
6758
- 66,
6759
- 32,
6760
- 134,
6761
- 132,
6762
- 32,
6763
- 2,
6764
- 173,
6765
- 32,
6766
- 3,
6767
- 173,
6768
- 66,
6769
- 32,
6770
- 134,
6771
- 132,
6772
- 126,
6773
- 34,
6774
- 4,
6775
- 66,
6776
- 32,
6777
- 135,
6778
- 167,
6779
- 36,
6780
- 0,
6781
- 32,
6782
- 4,
6783
- 167,
6784
- 11,
6785
- // 2, "div_s"
6786
- 36,
6787
- 1,
6788
- 1,
6789
- 126,
6790
- 32,
6791
- 0,
6792
- 173,
6793
- 32,
6794
- 1,
6795
- 173,
6796
- 66,
6797
- 32,
6798
- 134,
6799
- 132,
6800
- 32,
6801
- 2,
6802
- 173,
6803
- 32,
6804
- 3,
6805
- 173,
6806
- 66,
6807
- 32,
6808
- 134,
6809
- 132,
6810
- 127,
6811
- 34,
6812
- 4,
6813
- 66,
6814
- 32,
6815
- 135,
6816
- 167,
6817
- 36,
6818
- 0,
6819
- 32,
6820
- 4,
6821
- 167,
6822
- 11,
6823
- // 3, "div_u"
6824
- 36,
6825
- 1,
6826
- 1,
6827
- 126,
6828
- 32,
6829
- 0,
6830
- 173,
6831
- 32,
6832
- 1,
6833
- 173,
6834
- 66,
6835
- 32,
6836
- 134,
6837
- 132,
6838
- 32,
6839
- 2,
6840
- 173,
6841
- 32,
6842
- 3,
6843
- 173,
6844
- 66,
6845
- 32,
6846
- 134,
6847
- 132,
6848
- 128,
6849
- 34,
6850
- 4,
6851
- 66,
6852
- 32,
6853
- 135,
6854
- 167,
6855
- 36,
6856
- 0,
6857
- 32,
6858
- 4,
6859
- 167,
6860
- 11,
6861
- // 4, "rem_s"
6862
- 36,
6863
- 1,
6864
- 1,
6865
- 126,
6866
- 32,
6867
- 0,
6868
- 173,
6869
- 32,
6870
- 1,
6871
- 173,
6872
- 66,
6873
- 32,
6874
- 134,
6875
- 132,
6876
- 32,
6877
- 2,
6878
- 173,
6879
- 32,
6880
- 3,
6881
- 173,
6882
- 66,
6883
- 32,
6884
- 134,
6885
- 132,
6886
- 129,
6887
- 34,
6888
- 4,
6889
- 66,
6890
- 32,
6891
- 135,
6892
- 167,
6893
- 36,
6894
- 0,
6895
- 32,
6896
- 4,
6897
- 167,
6898
- 11,
6899
- // 5, "rem_u"
6900
- 36,
6901
- 1,
6902
- 1,
6903
- 126,
6904
- 32,
6905
- 0,
6906
- 173,
6907
- 32,
6908
- 1,
6909
- 173,
6910
- 66,
6911
- 32,
6912
- 134,
6913
- 132,
6914
- 32,
6915
- 2,
6916
- 173,
6917
- 32,
6918
- 3,
6919
- 173,
6920
- 66,
6921
- 32,
6922
- 134,
6923
- 132,
6924
- 130,
6925
- 34,
6926
- 4,
6927
- 66,
6928
- 32,
6929
- 135,
6930
- 167,
6931
- 36,
6932
- 0,
6933
- 32,
6934
- 4,
6935
- 167,
6936
- 11
6937
- ])
6938
- ),
6939
- {}
6940
- ).exports;
6941
- } catch {
6942
- }
6943
- function Long(low, high, unsigned) {
6944
- this.low = low | 0;
6945
- this.high = high | 0;
6946
- this.unsigned = !!unsigned;
6947
- }
6948
- Long.prototype.__isLong__;
6949
- Object.defineProperty(Long.prototype, "__isLong__", { value: true });
6950
- function isLong$1(obj) {
6951
- return (obj && obj["__isLong__"]) === true;
6952
- }
6953
- function ctz32(value) {
6954
- var c = Math.clz32(value & -value);
6955
- return value ? 31 - c : c;
6956
- }
6957
- Long.isLong = isLong$1;
6958
- var INT_CACHE = {};
6959
- var UINT_CACHE = {};
6960
- function fromInt(value, unsigned) {
6961
- var obj, cachedObj, cache;
6962
- if (unsigned) {
6963
- value >>>= 0;
6964
- if (cache = 0 <= value && value < 256) {
6965
- cachedObj = UINT_CACHE[value];
6966
- if (cachedObj) return cachedObj;
6967
- }
6968
- obj = fromBits(value, 0, true);
6969
- if (cache) UINT_CACHE[value] = obj;
6970
- return obj;
6971
- } else {
6972
- value |= 0;
6973
- if (cache = -128 <= value && value < 128) {
6974
- cachedObj = INT_CACHE[value];
6975
- if (cachedObj) return cachedObj;
6976
- }
6977
- obj = fromBits(value, value < 0 ? -1 : 0, false);
6978
- if (cache) INT_CACHE[value] = obj;
6979
- return obj;
7014
+ const removeDecimal = (number) => number < 0 ? Math.ceil(number) : Math.floor(number);
7015
+ function bigintToBytesLE(value) {
7016
+ const buf = new Uint8Array(8);
7017
+ let v = BigInt.asUintN(64, value);
7018
+ for (let i = 0; i < 8; i++) {
7019
+ buf[i] = Number(v & 0xffn);
7020
+ v >>= 8n;
6980
7021
  }
7022
+ return buf;
6981
7023
  }
6982
- Long.fromInt = fromInt;
6983
- function fromNumber(value, unsigned) {
6984
- if (isNaN(value)) return unsigned ? UZERO : ZERO;
6985
- if (unsigned) {
6986
- if (value < 0) return UZERO;
6987
- if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
6988
- } else {
6989
- if (value <= -TWO_PWR_63_DBL) return MIN_VALUE;
6990
- if (value + 1 >= TWO_PWR_63_DBL) return MAX_VALUE;
6991
- }
6992
- if (value < 0) return fromNumber(-value, unsigned).neg();
6993
- return fromBits(
6994
- value % TWO_PWR_32_DBL | 0,
6995
- value / TWO_PWR_32_DBL | 0,
6996
- unsigned
6997
- );
6998
- }
6999
- Long.fromNumber = fromNumber;
7000
- function fromBits(lowBits, highBits, unsigned) {
7001
- return new Long(lowBits, highBits, unsigned);
7002
- }
7003
- Long.fromBits = fromBits;
7004
- var pow_dbl = Math.pow;
7005
- function fromString(str, unsigned, radix) {
7006
- if (str.length === 0) throw Error("empty string");
7007
- if (typeof unsigned === "number") {
7008
- radix = unsigned;
7009
- unsigned = false;
7010
- } else {
7011
- unsigned = !!unsigned;
7012
- }
7013
- if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
7014
- return unsigned ? UZERO : ZERO;
7015
- radix = radix || 10;
7016
- if (radix < 2 || 36 < radix) throw RangeError("radix");
7017
- var p;
7018
- if ((p = str.indexOf("-")) > 0) throw Error("interior hyphen");
7019
- else if (p === 0) {
7020
- return fromString(str.substring(1), unsigned, radix).neg();
7021
- }
7022
- var radixToPower = fromNumber(pow_dbl(radix, 8));
7023
- var result = ZERO;
7024
- for (var i = 0; i < str.length; i += 8) {
7025
- var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
7026
- if (size < 8) {
7027
- var power = fromNumber(pow_dbl(radix, size));
7028
- result = result.mul(power).add(fromNumber(value));
7029
- } else {
7030
- result = result.mul(radixToPower);
7031
- result = result.add(fromNumber(value));
7032
- }
7024
+ function bigintFromBytesLE(bytes) {
7025
+ let v = 0n;
7026
+ for (let i = 7; i >= 0; i--) {
7027
+ v = v << 8n | BigInt(bytes[i]);
7033
7028
  }
7034
- result.unsigned = unsigned;
7035
- return result;
7036
- }
7037
- Long.fromString = fromString;
7038
- function fromValue(val, unsigned) {
7039
- if (typeof val === "number") return fromNumber(val, unsigned);
7040
- if (typeof val === "string") return fromString(val, unsigned);
7041
- return fromBits(
7042
- val.low,
7043
- val.high,
7044
- typeof unsigned === "boolean" ? unsigned : val.unsigned
7045
- );
7029
+ return BigInt.asIntN(64, v);
7046
7030
  }
7047
- Long.fromValue = fromValue;
7048
- var TWO_PWR_16_DBL = 1 << 16;
7049
- var TWO_PWR_24_DBL = 1 << 24;
7050
- var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
7051
- var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
7052
- var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
7053
- var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
7054
- var ZERO = fromInt(0);
7055
- Long.ZERO = ZERO;
7056
- var UZERO = fromInt(0, true);
7057
- Long.UZERO = UZERO;
7058
- var ONE = fromInt(1);
7059
- Long.ONE = ONE;
7060
- var UONE = fromInt(1, true);
7061
- Long.UONE = UONE;
7062
- var NEG_ONE = fromInt(-1);
7063
- Long.NEG_ONE = NEG_ONE;
7064
- var MAX_VALUE = fromBits(4294967295 | 0, 2147483647 | 0, false);
7065
- Long.MAX_VALUE = MAX_VALUE;
7066
- var MAX_UNSIGNED_VALUE = fromBits(4294967295 | 0, 4294967295 | 0, true);
7067
- Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
7068
- var MIN_VALUE = fromBits(0, 2147483648 | 0, false);
7069
- Long.MIN_VALUE = MIN_VALUE;
7070
- var LongPrototype = Long.prototype;
7071
- LongPrototype.toInt = function toInt() {
7072
- return this.unsigned ? this.low >>> 0 : this.low;
7073
- };
7074
- LongPrototype.toNumber = function toNumber() {
7075
- if (this.unsigned)
7076
- return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
7077
- return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
7078
- };
7079
- LongPrototype.toString = function toString(radix) {
7080
- radix = radix || 10;
7081
- if (radix < 2 || 36 < radix) throw RangeError("radix");
7082
- if (this.isZero()) return "0";
7083
- if (this.isNegative()) {
7084
- if (this.eq(MIN_VALUE)) {
7085
- var radixLong = fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
7086
- return div.toString(radix) + rem1.toInt().toString(radix);
7087
- } else return "-" + this.neg().toString(radix);
7088
- }
7089
- var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned), rem = this;
7090
- var result = "";
7091
- while (true) {
7092
- var remDiv = rem.div(radixToPower), intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0, digits = intval.toString(radix);
7093
- rem = remDiv;
7094
- if (rem.isZero()) return digits + result;
7095
- else {
7096
- while (digits.length < 6) digits = "0" + digits;
7097
- result = "" + digits + result;
7098
- }
7031
+ function bigintFromBytesLEUnsigned(bytes) {
7032
+ let v = 0n;
7033
+ for (let i = 7; i >= 0; i--) {
7034
+ v = v << 8n | BigInt(bytes[i]);
7099
7035
  }
7100
- };
7101
- LongPrototype.getHighBits = function getHighBits() {
7102
- return this.high;
7103
- };
7104
- LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
7105
- return this.high >>> 0;
7106
- };
7107
- LongPrototype.getLowBits = function getLowBits() {
7108
- return this.low;
7109
- };
7110
- LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
7111
- return this.low >>> 0;
7112
- };
7113
- LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
7114
- if (this.isNegative())
7115
- return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
7116
- var val = this.high != 0 ? this.high : this.low;
7117
- for (var bit = 31; bit > 0; bit--) if ((val & 1 << bit) != 0) break;
7118
- return this.high != 0 ? bit + 33 : bit + 1;
7119
- };
7120
- LongPrototype.isSafeInteger = function isSafeInteger() {
7121
- var top11Bits = this.high >> 21;
7122
- if (!top11Bits) return true;
7123
- if (this.unsigned) return false;
7124
- return top11Bits === -1 && !(this.low === 0 && this.high === -2097152);
7125
- };
7126
- LongPrototype.isZero = function isZero() {
7127
- return this.high === 0 && this.low === 0;
7128
- };
7129
- LongPrototype.eqz = LongPrototype.isZero;
7130
- LongPrototype.isNegative = function isNegative() {
7131
- return !this.unsigned && this.high < 0;
7132
- };
7133
- LongPrototype.isPositive = function isPositive() {
7134
- return this.unsigned || this.high >= 0;
7135
- };
7136
- LongPrototype.isOdd = function isOdd() {
7137
- return (this.low & 1) === 1;
7138
- };
7139
- LongPrototype.isEven = function isEven() {
7140
- return (this.low & 1) === 0;
7141
- };
7142
- LongPrototype.equals = function equals(other) {
7143
- if (!isLong$1(other)) other = fromValue(other);
7144
- if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
7145
- return false;
7146
- return this.high === other.high && this.low === other.low;
7147
- };
7148
- LongPrototype.eq = LongPrototype.equals;
7149
- LongPrototype.notEquals = function notEquals(other) {
7150
- return !this.eq(
7151
- /* validates */
7152
- other
7153
- );
7154
- };
7155
- LongPrototype.neq = LongPrototype.notEquals;
7156
- LongPrototype.ne = LongPrototype.notEquals;
7157
- LongPrototype.lessThan = function lessThan(other) {
7158
- return this.comp(
7159
- /* validates */
7160
- other
7161
- ) < 0;
7162
- };
7163
- LongPrototype.lt = LongPrototype.lessThan;
7164
- LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
7165
- return this.comp(
7166
- /* validates */
7167
- other
7168
- ) <= 0;
7169
- };
7170
- LongPrototype.lte = LongPrototype.lessThanOrEqual;
7171
- LongPrototype.le = LongPrototype.lessThanOrEqual;
7172
- LongPrototype.greaterThan = function greaterThan(other) {
7173
- return this.comp(
7174
- /* validates */
7175
- other
7176
- ) > 0;
7177
- };
7178
- LongPrototype.gt = LongPrototype.greaterThan;
7179
- LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
7180
- return this.comp(
7181
- /* validates */
7182
- other
7183
- ) >= 0;
7184
- };
7185
- LongPrototype.gte = LongPrototype.greaterThanOrEqual;
7186
- LongPrototype.ge = LongPrototype.greaterThanOrEqual;
7187
- LongPrototype.compare = function compare(other) {
7188
- if (!isLong$1(other)) other = fromValue(other);
7189
- if (this.eq(other)) return 0;
7190
- var thisNeg = this.isNegative(), otherNeg = other.isNegative();
7191
- if (thisNeg && !otherNeg) return -1;
7192
- if (!thisNeg && otherNeg) return 1;
7193
- if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1;
7194
- return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
7195
- };
7196
- LongPrototype.comp = LongPrototype.compare;
7197
- LongPrototype.negate = function negate2() {
7198
- if (!this.unsigned && this.eq(MIN_VALUE)) return MIN_VALUE;
7199
- return this.not().add(ONE);
7200
- };
7201
- LongPrototype.neg = LongPrototype.negate;
7202
- LongPrototype.add = function add(addend) {
7203
- if (!isLong$1(addend)) addend = fromValue(addend);
7204
- var a48 = this.high >>> 16;
7205
- var a32 = this.high & 65535;
7206
- var a16 = this.low >>> 16;
7207
- var a00 = this.low & 65535;
7208
- var b48 = addend.high >>> 16;
7209
- var b32 = addend.high & 65535;
7210
- var b16 = addend.low >>> 16;
7211
- var b00 = addend.low & 65535;
7212
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
7213
- c00 += a00 + b00;
7214
- c16 += c00 >>> 16;
7215
- c00 &= 65535;
7216
- c16 += a16 + b16;
7217
- c32 += c16 >>> 16;
7218
- c16 &= 65535;
7219
- c32 += a32 + b32;
7220
- c48 += c32 >>> 16;
7221
- c32 &= 65535;
7222
- c48 += a48 + b48;
7223
- c48 &= 65535;
7224
- return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
7225
- };
7226
- LongPrototype.subtract = function subtract(subtrahend) {
7227
- if (!isLong$1(subtrahend)) subtrahend = fromValue(subtrahend);
7228
- return this.add(subtrahend.neg());
7229
- };
7230
- LongPrototype.sub = LongPrototype.subtract;
7231
- LongPrototype.multiply = function multiply(multiplier) {
7232
- if (this.isZero()) return this;
7233
- if (!isLong$1(multiplier)) multiplier = fromValue(multiplier);
7234
- if (wasm) {
7235
- var low = wasm["mul"](this.low, this.high, multiplier.low, multiplier.high);
7236
- return fromBits(low, wasm["get_high"](), this.unsigned);
7237
- }
7238
- if (multiplier.isZero()) return this.unsigned ? UZERO : ZERO;
7239
- if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO;
7240
- if (multiplier.eq(MIN_VALUE)) return this.isOdd() ? MIN_VALUE : ZERO;
7241
- if (this.isNegative()) {
7242
- if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());
7243
- else return this.neg().mul(multiplier).neg();
7244
- } else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg();
7245
- if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
7246
- return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
7247
- var a48 = this.high >>> 16;
7248
- var a32 = this.high & 65535;
7249
- var a16 = this.low >>> 16;
7250
- var a00 = this.low & 65535;
7251
- var b48 = multiplier.high >>> 16;
7252
- var b32 = multiplier.high & 65535;
7253
- var b16 = multiplier.low >>> 16;
7254
- var b00 = multiplier.low & 65535;
7255
- var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
7256
- c00 += a00 * b00;
7257
- c16 += c00 >>> 16;
7258
- c00 &= 65535;
7259
- c16 += a16 * b00;
7260
- c32 += c16 >>> 16;
7261
- c16 &= 65535;
7262
- c16 += a00 * b16;
7263
- c32 += c16 >>> 16;
7264
- c16 &= 65535;
7265
- c32 += a32 * b00;
7266
- c48 += c32 >>> 16;
7267
- c32 &= 65535;
7268
- c32 += a16 * b16;
7269
- c48 += c32 >>> 16;
7270
- c32 &= 65535;
7271
- c32 += a00 * b32;
7272
- c48 += c32 >>> 16;
7273
- c32 &= 65535;
7274
- c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
7275
- c48 &= 65535;
7276
- return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
7277
- };
7278
- LongPrototype.mul = LongPrototype.multiply;
7279
- LongPrototype.divide = function divide(divisor) {
7280
- if (!isLong$1(divisor)) divisor = fromValue(divisor);
7281
- if (divisor.isZero()) throw Error("division by zero");
7282
- if (wasm) {
7283
- if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
7284
- return this;
7285
- }
7286
- var low = (this.unsigned ? wasm["div_u"] : wasm["div_s"])(
7287
- this.low,
7288
- this.high,
7289
- divisor.low,
7290
- divisor.high
7291
- );
7292
- return fromBits(low, wasm["get_high"](), this.unsigned);
7293
- }
7294
- if (this.isZero()) return this.unsigned ? UZERO : ZERO;
7295
- var approx, rem, res;
7296
- if (!this.unsigned) {
7297
- if (this.eq(MIN_VALUE)) {
7298
- if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
7299
- return MIN_VALUE;
7300
- else if (divisor.eq(MIN_VALUE)) return ONE;
7301
- else {
7302
- var halfThis = this.shr(1);
7303
- approx = halfThis.div(divisor).shl(1);
7304
- if (approx.eq(ZERO)) {
7305
- return divisor.isNegative() ? ONE : NEG_ONE;
7306
- } else {
7307
- rem = this.sub(divisor.mul(approx));
7308
- res = approx.add(rem.div(divisor));
7309
- return res;
7310
- }
7311
- }
7312
- } else if (divisor.eq(MIN_VALUE)) return this.unsigned ? UZERO : ZERO;
7313
- if (this.isNegative()) {
7314
- if (divisor.isNegative()) return this.neg().div(divisor.neg());
7315
- return this.neg().div(divisor).neg();
7316
- } else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
7317
- res = ZERO;
7318
- } else {
7319
- if (!divisor.unsigned) divisor = divisor.toUnsigned();
7320
- if (divisor.gt(this)) return UZERO;
7321
- if (divisor.gt(this.shru(1)))
7322
- return UONE;
7323
- res = UZERO;
7324
- }
7325
- rem = this;
7326
- while (rem.gte(divisor)) {
7327
- approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
7328
- var log2 = Math.ceil(Math.log(approx) / Math.LN2), delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48), approxRes = fromNumber(approx), approxRem = approxRes.mul(divisor);
7329
- while (approxRem.isNegative() || approxRem.gt(rem)) {
7330
- approx -= delta;
7331
- approxRes = fromNumber(approx, this.unsigned);
7332
- approxRem = approxRes.mul(divisor);
7333
- }
7334
- if (approxRes.isZero()) approxRes = ONE;
7335
- res = res.add(approxRes);
7336
- rem = rem.sub(approxRem);
7337
- }
7338
- return res;
7339
- };
7340
- LongPrototype.div = LongPrototype.divide;
7341
- LongPrototype.modulo = function modulo(divisor) {
7342
- if (!isLong$1(divisor)) divisor = fromValue(divisor);
7343
- if (wasm) {
7344
- var low = (this.unsigned ? wasm["rem_u"] : wasm["rem_s"])(
7345
- this.low,
7346
- this.high,
7347
- divisor.low,
7348
- divisor.high
7349
- );
7350
- return fromBits(low, wasm["get_high"](), this.unsigned);
7351
- }
7352
- return this.sub(this.div(divisor).mul(divisor));
7353
- };
7354
- LongPrototype.mod = LongPrototype.modulo;
7355
- LongPrototype.rem = LongPrototype.modulo;
7356
- LongPrototype.not = function not() {
7357
- return fromBits(~this.low, ~this.high, this.unsigned);
7358
- };
7359
- LongPrototype.countLeadingZeros = function countLeadingZeros() {
7360
- return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32;
7361
- };
7362
- LongPrototype.clz = LongPrototype.countLeadingZeros;
7363
- LongPrototype.countTrailingZeros = function countTrailingZeros() {
7364
- return this.low ? ctz32(this.low) : ctz32(this.high) + 32;
7365
- };
7366
- LongPrototype.ctz = LongPrototype.countTrailingZeros;
7367
- LongPrototype.and = function and(other) {
7368
- if (!isLong$1(other)) other = fromValue(other);
7369
- return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
7370
- };
7371
- LongPrototype.or = function or(other) {
7372
- if (!isLong$1(other)) other = fromValue(other);
7373
- return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
7374
- };
7375
- LongPrototype.xor = function xor(other) {
7376
- if (!isLong$1(other)) other = fromValue(other);
7377
- return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
7378
- };
7379
- LongPrototype.shiftLeft = function shiftLeft(numBits) {
7380
- if (isLong$1(numBits)) numBits = numBits.toInt();
7381
- if ((numBits &= 63) === 0) return this;
7382
- else if (numBits < 32)
7383
- return fromBits(
7384
- this.low << numBits,
7385
- this.high << numBits | this.low >>> 32 - numBits,
7386
- this.unsigned
7387
- );
7388
- else return fromBits(0, this.low << numBits - 32, this.unsigned);
7389
- };
7390
- LongPrototype.shl = LongPrototype.shiftLeft;
7391
- LongPrototype.shiftRight = function shiftRight(numBits) {
7392
- if (isLong$1(numBits)) numBits = numBits.toInt();
7393
- if ((numBits &= 63) === 0) return this;
7394
- else if (numBits < 32)
7395
- return fromBits(
7396
- this.low >>> numBits | this.high << 32 - numBits,
7397
- this.high >> numBits,
7398
- this.unsigned
7399
- );
7400
- else
7401
- return fromBits(
7402
- this.high >> numBits - 32,
7403
- this.high >= 0 ? 0 : -1,
7404
- this.unsigned
7405
- );
7406
- };
7407
- LongPrototype.shr = LongPrototype.shiftRight;
7408
- LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
7409
- if (isLong$1(numBits)) numBits = numBits.toInt();
7410
- if ((numBits &= 63) === 0) return this;
7411
- if (numBits < 32)
7412
- return fromBits(
7413
- this.low >>> numBits | this.high << 32 - numBits,
7414
- this.high >>> numBits,
7415
- this.unsigned
7416
- );
7417
- if (numBits === 32) return fromBits(this.high, 0, this.unsigned);
7418
- return fromBits(this.high >>> numBits - 32, 0, this.unsigned);
7419
- };
7420
- LongPrototype.shru = LongPrototype.shiftRightUnsigned;
7421
- LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
7422
- LongPrototype.rotateLeft = function rotateLeft(numBits) {
7423
- var b;
7424
- if (isLong$1(numBits)) numBits = numBits.toInt();
7425
- if ((numBits &= 63) === 0) return this;
7426
- if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
7427
- if (numBits < 32) {
7428
- b = 32 - numBits;
7429
- return fromBits(
7430
- this.low << numBits | this.high >>> b,
7431
- this.high << numBits | this.low >>> b,
7432
- this.unsigned
7433
- );
7434
- }
7435
- numBits -= 32;
7436
- b = 32 - numBits;
7437
- return fromBits(
7438
- this.high << numBits | this.low >>> b,
7439
- this.low << numBits | this.high >>> b,
7440
- this.unsigned
7441
- );
7442
- };
7443
- LongPrototype.rotl = LongPrototype.rotateLeft;
7444
- LongPrototype.rotateRight = function rotateRight(numBits) {
7445
- var b;
7446
- if (isLong$1(numBits)) numBits = numBits.toInt();
7447
- if ((numBits &= 63) === 0) return this;
7448
- if (numBits === 32) return fromBits(this.high, this.low, this.unsigned);
7449
- if (numBits < 32) {
7450
- b = 32 - numBits;
7451
- return fromBits(
7452
- this.high << b | this.low >>> numBits,
7453
- this.low << b | this.high >>> numBits,
7454
- this.unsigned
7455
- );
7456
- }
7457
- numBits -= 32;
7458
- b = 32 - numBits;
7459
- return fromBits(
7460
- this.low << b | this.high >>> numBits,
7461
- this.high << b | this.low >>> numBits,
7462
- this.unsigned
7463
- );
7464
- };
7465
- LongPrototype.rotr = LongPrototype.rotateRight;
7466
- LongPrototype.toSigned = function toSigned() {
7467
- if (!this.unsigned) return this;
7468
- return fromBits(this.low, this.high, false);
7469
- };
7470
- LongPrototype.toUnsigned = function toUnsigned2() {
7471
- if (this.unsigned) return this;
7472
- return fromBits(this.low, this.high, true);
7473
- };
7474
- LongPrototype.toBytes = function toBytes(le) {
7475
- return le ? this.toBytesLE() : this.toBytesBE();
7476
- };
7477
- LongPrototype.toBytesLE = function toBytesLE() {
7478
- var hi = this.high, lo = this.low;
7479
- return [
7480
- lo & 255,
7481
- lo >>> 8 & 255,
7482
- lo >>> 16 & 255,
7483
- lo >>> 24,
7484
- hi & 255,
7485
- hi >>> 8 & 255,
7486
- hi >>> 16 & 255,
7487
- hi >>> 24
7488
- ];
7489
- };
7490
- LongPrototype.toBytesBE = function toBytesBE() {
7491
- var hi = this.high, lo = this.low;
7492
- return [
7493
- hi >>> 24,
7494
- hi >>> 16 & 255,
7495
- hi >>> 8 & 255,
7496
- hi & 255,
7497
- lo >>> 24,
7498
- lo >>> 16 & 255,
7499
- lo >>> 8 & 255,
7500
- lo & 255
7501
- ];
7502
- };
7503
- Long.fromBytes = function fromBytes(bytes, unsigned, le) {
7504
- return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
7505
- };
7506
- Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
7507
- return new Long(
7508
- bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24,
7509
- bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24,
7510
- unsigned
7511
- );
7512
- };
7513
- Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
7514
- return new Long(
7515
- bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7],
7516
- bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3],
7517
- unsigned
7518
- );
7519
- };
7520
- if (typeof BigInt === "function") {
7521
- Long.fromBigInt = function fromBigInt(value, unsigned) {
7522
- var lowBits = Number(BigInt.asIntN(32, value));
7523
- var highBits = Number(BigInt.asIntN(32, value >> BigInt(32)));
7524
- return fromBits(lowBits, highBits, unsigned);
7525
- };
7526
- Long.fromValue = function fromValueWithBigInt(value, unsigned) {
7527
- if (typeof value === "bigint") return Long.fromBigInt(value, unsigned);
7528
- return fromValue(value, unsigned);
7529
- };
7530
- LongPrototype.toBigInt = function toBigInt() {
7531
- var lowBigInt = BigInt(this.low >>> 0);
7532
- var highBigInt = BigInt(this.unsigned ? this.high >>> 0 : this.high);
7533
- return highBigInt << BigInt(32) | lowBigInt;
7534
- };
7036
+ return v;
7037
+ }
7038
+ function bigintToInt32(value) {
7039
+ return Number(BigInt.asIntN(32, value));
7535
7040
  }
7536
7041
  var PrimitiveType = /* @__PURE__ */ ((PrimitiveType2) => {
7537
7042
  PrimitiveType2[PrimitiveType2["Null"] = 0] = "Null";
@@ -7579,11 +7084,11 @@
7579
7084
  case 5:
7580
7085
  return new TextDecoder("utf-8").decode(bytes);
7581
7086
  case 3:
7582
- return Long.fromBytesLE(Array.from(bytes));
7087
+ return bigintFromBytesLE(bytes);
7583
7088
  case 6:
7584
7089
  return bytes;
7585
7090
  case 7:
7586
- return new Date(Long.fromBytesLE(Array.from(bytes), true).toNumber());
7091
+ return new Date(Number(bigintFromBytesLEUnsigned(bytes)));
7587
7092
  default:
7588
7093
  throw new YorkieError(
7589
7094
  Code.ErrUnimplemented,
@@ -7636,6 +7141,13 @@
7636
7141
  if (this.valueType === 5) {
7637
7142
  return `"${escapeString(this.value)}"`;
7638
7143
  }
7144
+ if (this.valueType === 6) {
7145
+ const bytes = this.value;
7146
+ return `"${btoa(String.fromCharCode(...bytes))}"`;
7147
+ }
7148
+ if (this.valueType === 7) {
7149
+ return `"${this.value.toISOString()}"`;
7150
+ }
7639
7151
  return `${this.value}`;
7640
7152
  }
7641
7153
  /**
@@ -7684,13 +7196,13 @@
7684
7196
  } else {
7685
7197
  return 4;
7686
7198
  }
7199
+ case "bigint":
7200
+ return 3;
7687
7201
  case "string":
7688
7202
  return 5;
7689
7203
  case "object":
7690
7204
  if (value === null) {
7691
7205
  return 0;
7692
- } else if (value instanceof Long) {
7693
- return 3;
7694
7206
  } else if (value instanceof Uint8Array) {
7695
7207
  return 6;
7696
7208
  } else if (value instanceof Date) {
@@ -7760,9 +7272,7 @@
7760
7272
  return new TextEncoder().encode(this.value);
7761
7273
  }
7762
7274
  case 3: {
7763
- const longVal = this.value;
7764
- const longToBytes = longVal.toBytesLE();
7765
- return Uint8Array.from(longToBytes);
7275
+ return bigintToBytesLE(this.value);
7766
7276
  }
7767
7277
  case 6: {
7768
7278
  const bytesVal = this.value;
@@ -7770,11 +7280,7 @@
7770
7280
  }
7771
7281
  case 7: {
7772
7282
  const dateVal = this.value;
7773
- const dateToBytes = Long.fromNumber(
7774
- dateVal.getTime(),
7775
- true
7776
- ).toBytesLE();
7777
- return Uint8Array.from(dateToBytes);
7283
+ return bigintToBytesLE(BigInt(dateVal.getTime()));
7778
7284
  }
7779
7285
  default:
7780
7286
  throw new YorkieError(
@@ -7784,19 +7290,54 @@
7784
7290
  }
7785
7291
  }
7786
7292
  }
7293
+ class ElementEntry {
7294
+ elem;
7295
+ positionNode;
7296
+ posMovedAt;
7297
+ constructor(elem) {
7298
+ this.elem = elem;
7299
+ }
7300
+ }
7787
7301
  class RGATreeListNode extends SplayNode {
7302
+ _elementEntry;
7303
+ _createdAt;
7304
+ _removedAt;
7788
7305
  prev;
7789
7306
  next;
7790
- movedFrom;
7791
- constructor(value) {
7792
- super(value);
7793
- this.value = value;
7307
+ constructor(elem, createdAt) {
7308
+ super(elem);
7309
+ this._createdAt = createdAt;
7310
+ }
7311
+ /**
7312
+ * `createWithElement` creates a new node that owns an element.
7313
+ */
7314
+ static createWithElement(elem) {
7315
+ const entry = new ElementEntry(elem);
7316
+ const node = new RGATreeListNode(elem, elem.getCreatedAt());
7317
+ entry.positionNode = node;
7318
+ node._elementEntry = entry;
7319
+ return node;
7794
7320
  }
7795
7321
  /**
7796
- * `createAfter` creates a new node after the given node.
7322
+ * `createBarePosition` creates a position node without an element
7323
+ * (used for move).
7797
7324
  */
7798
- static createAfter(prev, value) {
7799
- const newNode = new RGATreeListNode(value);
7325
+ static createBarePosition(createdAt) {
7326
+ return new RGATreeListNode(void 0, createdAt);
7327
+ }
7328
+ /**
7329
+ * `createAfter` creates a new node with the given element after
7330
+ * the given prev node.
7331
+ */
7332
+ static createAfter(prev, elem) {
7333
+ const newNode = RGATreeListNode.createWithElement(elem);
7334
+ RGATreeListNode.insertNodeAfter(prev, newNode);
7335
+ return newNode;
7336
+ }
7337
+ /**
7338
+ * `insertNodeAfter` inserts a node after the given prev node.
7339
+ */
7340
+ static insertNodeAfter(prev, newNode) {
7800
7341
  const prevNext = prev.next;
7801
7342
  prev.next = newNode;
7802
7343
  newNode.prev = prev;
@@ -7804,26 +7345,41 @@
7804
7345
  if (prevNext) {
7805
7346
  prevNext.prev = newNode;
7806
7347
  }
7807
- return newNode;
7808
7348
  }
7809
7349
  /**
7810
- * `remove` removes value based on removing time.
7350
+ * `remove` removes the element based on removing time.
7811
7351
  */
7812
7352
  remove(removedAt) {
7813
- return this.value.remove(removedAt);
7353
+ if (!this._elementEntry) {
7354
+ return false;
7355
+ }
7356
+ return this._elementEntry.elem.remove(removedAt);
7814
7357
  }
7815
7358
  /**
7816
- * `getCreatedAt` returns creation time of this value
7359
+ * `getCreatedAt` returns the creation time. For live nodes with
7360
+ * elements, returns the element's createdAt for backward
7361
+ * compatibility.
7817
7362
  */
7818
7363
  getCreatedAt() {
7819
- return this.value.getCreatedAt();
7364
+ if (this._elementEntry) {
7365
+ return this._elementEntry.elem.getCreatedAt();
7366
+ }
7367
+ return this._createdAt;
7820
7368
  }
7821
7369
  /**
7822
- * `getPositionedAt` returns the time of this element when it was positioned
7823
- * in the array.
7370
+ * `getPositionedAt` returns the time this element was positioned.
7371
+ * For live nodes, the position register (posMovedAt) is the source
7372
+ * of truth. For dead nodes (no element), the position node's own
7373
+ * createdAt is used.
7824
7374
  */
7825
7375
  getPositionedAt() {
7826
- return this.value.getPositionedAt();
7376
+ if (this._elementEntry) {
7377
+ if (this._elementEntry.posMovedAt) {
7378
+ return this._elementEntry.posMovedAt;
7379
+ }
7380
+ return this._elementEntry.elem.getCreatedAt();
7381
+ }
7382
+ return this._createdAt;
7827
7383
  }
7828
7384
  /**
7829
7385
  * `release` releases prev and next node.
@@ -7840,9 +7396,13 @@
7840
7396
  }
7841
7397
  /**
7842
7398
  * `getLength` returns the length of this node.
7399
+ * Dead nodes (no element) return 0, removed elements return 0.
7843
7400
  */
7844
7401
  getLength() {
7845
- return this.value.isRemoved() ? 0 : 1;
7402
+ if (!this._elementEntry || this.isRemoved()) {
7403
+ return 0;
7404
+ }
7405
+ return 1;
7846
7406
  }
7847
7407
  /**
7848
7408
  * `getPrev` returns a previous node.
@@ -7857,28 +7417,87 @@
7857
7417
  return this.next;
7858
7418
  }
7859
7419
  /**
7860
- * `getMovedFrom` returns the previous element before the element moved.
7420
+ * `getValue` returns the element value.
7861
7421
  */
7862
- getMovedFrom() {
7863
- return this.movedFrom;
7422
+ getValue() {
7423
+ if (!this._elementEntry) {
7424
+ return this.value;
7425
+ }
7426
+ return this._elementEntry.elem;
7864
7427
  }
7865
7428
  /**
7866
- * `setMovedFrom` sets the previous element before the element moved.
7429
+ * `getElement` returns the element or undefined if dead position.
7867
7430
  */
7868
- setMovedFrom(movedFrom) {
7869
- this.movedFrom = movedFrom;
7431
+ getElement() {
7432
+ return this._elementEntry?.elem;
7870
7433
  }
7871
7434
  /**
7872
- * `getValue` returns a element value.
7435
+ * `isRemoved` checks if the value was removed.
7873
7436
  */
7874
- getValue() {
7875
- return this.value;
7437
+ isRemoved() {
7438
+ if (!this._elementEntry) {
7439
+ return true;
7440
+ }
7441
+ return this._elementEntry.elem.isRemoved();
7876
7442
  }
7877
7443
  /**
7878
- * `isRemoved` checks if the value was removed.
7444
+ * `getElementEntry` returns the element entry.
7879
7445
  */
7880
- isRemoved() {
7881
- return this.value.isRemoved();
7446
+ getElementEntry() {
7447
+ return this._elementEntry;
7448
+ }
7449
+ /**
7450
+ * `setElementEntry` sets the element entry.
7451
+ */
7452
+ setElementEntry(entry) {
7453
+ this._elementEntry = entry;
7454
+ }
7455
+ /**
7456
+ * `getPositionCreatedAt` returns the position node's own createdAt.
7457
+ */
7458
+ getPositionCreatedAt() {
7459
+ return this._createdAt;
7460
+ }
7461
+ /**
7462
+ * `getPositionMovedAt` returns the LWW timestamp of the element's
7463
+ * move into this position. Undefined for insert-created positions.
7464
+ */
7465
+ getPositionMovedAt() {
7466
+ if (!this._elementEntry) {
7467
+ return void 0;
7468
+ }
7469
+ return this._elementEntry.posMovedAt;
7470
+ }
7471
+ /**
7472
+ * `getRemovedAt` returns the time this dead position node was
7473
+ * removed (for GC).
7474
+ */
7475
+ getRemovedAt() {
7476
+ return this._removedAt;
7477
+ }
7478
+ /**
7479
+ * `setRemovedAt` sets the removal time of this position node.
7480
+ */
7481
+ setRemovedAt(removedAt) {
7482
+ this._removedAt = removedAt;
7483
+ }
7484
+ /**
7485
+ * `toIDString` returns a unique identifier for this position node
7486
+ * (for GC).
7487
+ */
7488
+ toIDString() {
7489
+ return this._createdAt.toIDString();
7490
+ }
7491
+ /**
7492
+ * `getDataSize` returns the data size of this position node
7493
+ * (for GC).
7494
+ */
7495
+ getDataSize() {
7496
+ let meta = TimeTicketSize;
7497
+ if (this._removedAt) {
7498
+ meta += TimeTicketSize;
7499
+ }
7500
+ return { data: 0, meta };
7882
7501
  }
7883
7502
  }
7884
7503
  class RGATreeList {
@@ -7886,13 +7505,15 @@
7886
7505
  last;
7887
7506
  nodeMapByIndex;
7888
7507
  nodeMapByCreatedAt;
7508
+ elementMapByCreatedAt;
7889
7509
  constructor() {
7890
7510
  const dummyValue = Primitive.of(0, InitialTimeTicket);
7891
7511
  dummyValue.setRemovedAt(InitialTimeTicket);
7892
- this.dummyHead = new RGATreeListNode(dummyValue);
7512
+ this.dummyHead = RGATreeListNode.createWithElement(dummyValue);
7893
7513
  this.last = this.dummyHead;
7894
7514
  this.nodeMapByIndex = new SplayTree();
7895
7515
  this.nodeMapByCreatedAt = /* @__PURE__ */ new Map();
7516
+ this.elementMapByCreatedAt = /* @__PURE__ */ new Map();
7896
7517
  this.nodeMapByIndex.insert(this.dummyHead);
7897
7518
  this.nodeMapByCreatedAt.set(
7898
7519
  this.dummyHead.getCreatedAt().toIDString(),
@@ -7912,22 +7533,10 @@
7912
7533
  return this.nodeMapByIndex.length;
7913
7534
  }
7914
7535
  /**
7915
- * `findNextBeforeExecutedAt` returns the node by the given createdAt and
7916
- * executedAt. It passes through nodes created after executedAt from the
7917
- * given node and returns the next node.
7918
- * @returns the next node of the given createdAt and executedAt
7536
+ * `findNextBeforeExecutedAt` walks forward from the given node,
7537
+ * skipping nodes positioned after executedAt (RGA insertion rule).
7919
7538
  */
7920
- findNextBeforeExecutedAt(createdAt, executedAt) {
7921
- let node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
7922
- if (!node) {
7923
- throw new YorkieError(
7924
- Code.ErrInvalidArgument,
7925
- `cant find the given node: ${createdAt.toIDString()}`
7926
- );
7927
- }
7928
- while (node.getValue().getMovedAt() && node.getValue().getMovedAt().after(executedAt) && node.getMovedFrom()) {
7929
- node = node.getMovedFrom();
7930
- }
7539
+ findNextBeforeExecutedAt(node, executedAt) {
7931
7540
  while (node.getNext() && node.getNext().getPositionedAt().after(executedAt)) {
7932
7541
  node = node.getNext();
7933
7542
  }
@@ -7939,65 +7548,103 @@
7939
7548
  }
7940
7549
  node.release();
7941
7550
  this.nodeMapByIndex.delete(node);
7942
- this.nodeMapByCreatedAt.delete(node.getValue().getCreatedAt().toIDString());
7551
+ this.nodeMapByCreatedAt.delete(node.getPositionCreatedAt().toIDString());
7943
7552
  }
7944
7553
  /**
7945
- * `insertAfter` adds a new node with the value after the given node.
7554
+ * `insertAfter` adds a new node with the value after the given
7555
+ * position. prevCreatedAt is a position node identity. Looks up
7556
+ * nodeMapByCreatedAt first, then elementMapByCreatedAt for backward
7557
+ * compatibility.
7946
7558
  */
7947
7559
  insertAfter(prevCreatedAt, value, executedAt = value.getCreatedAt()) {
7948
- const prevNode = this.findNextBeforeExecutedAt(prevCreatedAt, executedAt);
7560
+ let startNode = this.nodeMapByCreatedAt.get(prevCreatedAt.toIDString());
7561
+ if (!startNode) {
7562
+ const entry = this.elementMapByCreatedAt.get(prevCreatedAt.toIDString());
7563
+ if (entry) {
7564
+ startNode = entry.positionNode;
7565
+ }
7566
+ }
7567
+ if (!startNode) {
7568
+ throw new YorkieError(
7569
+ Code.ErrInvalidArgument,
7570
+ `cant find the given node: ${prevCreatedAt.toIDString()}`
7571
+ );
7572
+ }
7573
+ const prevNode = this.findNextBeforeExecutedAt(startNode, executedAt);
7949
7574
  const newNode = RGATreeListNode.createAfter(prevNode, value);
7950
7575
  if (prevNode === this.last) {
7951
7576
  this.last = newNode;
7952
7577
  }
7953
7578
  this.nodeMapByIndex.insertAfter(prevNode, newNode);
7954
- this.nodeMapByCreatedAt.set(newNode.getCreatedAt().toIDString(), newNode);
7579
+ this.nodeMapByCreatedAt.set(value.getCreatedAt().toIDString(), newNode);
7580
+ this.elementMapByCreatedAt.set(
7581
+ value.getCreatedAt().toIDString(),
7582
+ newNode.getElementEntry()
7583
+ );
7955
7584
  return newNode;
7956
7585
  }
7957
7586
  /**
7958
- * `moveAfter` moves the given `createdAt` element
7959
- * after the `prevCreatedAt` element.
7587
+ * `insertPositionAfter` creates a bare position node after
7588
+ * resolving position via forward skip (RGA insertion rule).
7589
+ * Used by moveAfter. prevCreatedAt is a POSITION node identity.
7960
7590
  */
7961
- moveAfter(prevCreatedAt, createdAt, executedAt) {
7962
- let prevNode = this.nodeMapByCreatedAt.get(prevCreatedAt.toIDString());
7963
- if (!prevNode) {
7591
+ insertPositionAfter(prevCreatedAt, executedAt) {
7592
+ const startNode = this.nodeMapByCreatedAt.get(prevCreatedAt.toIDString());
7593
+ if (!startNode) {
7964
7594
  throw new YorkieError(
7965
7595
  Code.ErrInvalidArgument,
7966
7596
  `cant find the given node: ${prevCreatedAt.toIDString()}`
7967
7597
  );
7968
7598
  }
7969
- let node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
7970
- if (!node) {
7599
+ const prevNode = this.findNextBeforeExecutedAt(startNode, executedAt);
7600
+ const newNode = RGATreeListNode.createBarePosition(executedAt);
7601
+ RGATreeListNode.insertNodeAfter(prevNode, newNode);
7602
+ if (prevNode === this.last) {
7603
+ this.last = newNode;
7604
+ }
7605
+ this.nodeMapByIndex.insertAfter(prevNode, newNode);
7606
+ this.nodeMapByCreatedAt.set(executedAt.toIDString(), newNode);
7607
+ return newNode;
7608
+ }
7609
+ /**
7610
+ * `moveAfter` moves the given `createdAt` element after the
7611
+ * `prevCreatedAt` element using LWW position register semantics.
7612
+ * Returns the dead position node (if any) for GC registration.
7613
+ */
7614
+ moveAfter(prevCreatedAt, createdAt, executedAt) {
7615
+ if (!this.nodeMapByCreatedAt.has(prevCreatedAt.toIDString())) {
7971
7616
  throw new YorkieError(
7972
7617
  Code.ErrInvalidArgument,
7973
- `cant find the given node: ${createdAt.toIDString()}`
7618
+ `cant find the given node: ${prevCreatedAt.toIDString()}`
7974
7619
  );
7975
7620
  }
7976
- if (prevNode !== node && executedAt.after(node.getPositionedAt())) {
7977
- const movedFrom = node.getPrev();
7978
- let nextNode = node.getNext();
7979
- this.release(node);
7980
- node = this.insertAfter(
7981
- prevNode.getCreatedAt(),
7982
- node.getValue(),
7983
- executedAt
7621
+ const entry = this.elementMapByCreatedAt.get(createdAt.toIDString());
7622
+ if (!entry) {
7623
+ throw new YorkieError(
7624
+ Code.ErrInvalidArgument,
7625
+ `cant find the given node: ${createdAt.toIDString()}`
7984
7626
  );
7985
- node.getValue().setMovedAt(executedAt);
7986
- node.setMovedFrom(movedFrom);
7987
- while (nextNode && nextNode.getPositionedAt().after(executedAt)) {
7988
- prevNode = node;
7989
- node = nextNode;
7990
- nextNode = node.getNext();
7991
- this.release(node);
7992
- node = this.insertAfter(
7993
- prevNode.getCreatedAt(),
7994
- node.getValue(),
7995
- executedAt
7996
- );
7997
- node.getValue().setMovedAt(executedAt);
7998
- node.setMovedFrom(movedFrom);
7627
+ }
7628
+ if (entry.posMovedAt && !executedAt.after(entry.posMovedAt)) {
7629
+ if (this.nodeMapByCreatedAt.has(executedAt.toIDString())) {
7630
+ return void 0;
7999
7631
  }
7632
+ const deadPosNode = this.insertPositionAfter(prevCreatedAt, executedAt);
7633
+ deadPosNode.setRemovedAt(executedAt);
7634
+ this.nodeMapByIndex.splayNode(deadPosNode);
7635
+ return deadPosNode;
8000
7636
  }
7637
+ const newPosNode = this.insertPositionAfter(prevCreatedAt, executedAt);
7638
+ const oldPosNode = entry.positionNode;
7639
+ oldPosNode.setElementEntry(void 0);
7640
+ oldPosNode.setRemovedAt(executedAt);
7641
+ this.nodeMapByIndex.splayNode(oldPosNode);
7642
+ newPosNode.setElementEntry(entry);
7643
+ entry.positionNode = newPosNode;
7644
+ entry.posMovedAt = executedAt;
7645
+ entry.elem.setMovedAt(executedAt);
7646
+ this.nodeMapByIndex.splayNode(newPosNode);
7647
+ return oldPosNode;
8001
7648
  }
8002
7649
  /**
8003
7650
  * `insert` adds the given element after the last node.
@@ -8006,34 +7653,53 @@
8006
7653
  this.insertAfter(this.last.getCreatedAt(), value);
8007
7654
  }
8008
7655
  /**
8009
- * `getByID` returns the element of the given creation time.
7656
+ * `getByID` returns the node of the given creation time.
7657
+ * Checks elementMapByCreatedAt first (for moved elements whose
7658
+ * position node createdAt differs), then nodeMapByCreatedAt.
8010
7659
  */
8011
7660
  getByID(createdAt) {
7661
+ const entry = this.elementMapByCreatedAt.get(createdAt.toIDString());
7662
+ if (entry) {
7663
+ return entry.positionNode;
7664
+ }
8012
7665
  return this.nodeMapByCreatedAt.get(createdAt.toIDString());
8013
7666
  }
8014
7667
  /**
8015
7668
  * `subPathOf` returns the sub path of the given element.
8016
7669
  */
8017
7670
  subPathOf(createdAt) {
8018
- const node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
8019
- if (!node) {
8020
- return;
7671
+ const entry = this.elementMapByCreatedAt.get(createdAt.toIDString());
7672
+ if (!entry) {
7673
+ const node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
7674
+ if (!node) {
7675
+ return;
7676
+ }
7677
+ return String(this.nodeMapByIndex.indexOf(node));
8021
7678
  }
8022
- return String(this.nodeMapByIndex.indexOf(node));
7679
+ return String(this.nodeMapByIndex.indexOf(entry.positionNode));
8023
7680
  }
8024
7681
  /**
8025
- * `purge` physically purges element.
7682
+ * `purge` physically purges the given child. Handles both dead
7683
+ * position nodes (GCChild from GCParent path) and CRDTElements
7684
+ * (from CRDTContainer path).
8026
7685
  */
8027
- purge(element) {
8028
- const node = this.nodeMapByCreatedAt.get(
7686
+ purge(child) {
7687
+ if (child instanceof RGATreeListNode) {
7688
+ this.release(child);
7689
+ return;
7690
+ }
7691
+ const element = child;
7692
+ const entry = this.elementMapByCreatedAt.get(
8029
7693
  element.getCreatedAt().toIDString()
8030
7694
  );
8031
- if (!node) {
7695
+ if (!entry) {
8032
7696
  throw new YorkieError(
8033
7697
  Code.ErrInvalidArgument,
8034
7698
  `fail to find the given createdAt: ${element.getCreatedAt().toIDString()}`
8035
7699
  );
8036
7700
  }
7701
+ const node = entry.positionNode;
7702
+ this.elementMapByCreatedAt.delete(element.getCreatedAt().toIDString());
8037
7703
  this.release(node);
8038
7704
  }
8039
7705
  /**
@@ -8044,42 +7710,69 @@
8044
7710
  return;
8045
7711
  }
8046
7712
  const node = this.nodeMapByIndex.findForArray(idx);
8047
- const rgaNode = node;
8048
- return rgaNode;
7713
+ return node;
8049
7714
  }
8050
7715
  /**
8051
- * `getPrevCreatedAt` returns a creation time of the previous node.
7716
+ * `findPrevCreatedAt` returns the position node's createdAt of the
7717
+ * previous element. This returns a position identity suitable for
7718
+ * use as prevCreatedAt in moveAfter.
8052
7719
  */
8053
- getPrevCreatedAt(createdAt) {
8054
- let node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
7720
+ findPrevCreatedAt(createdAt) {
7721
+ const entry = this.elementMapByCreatedAt.get(createdAt.toIDString());
7722
+ if (!entry) {
7723
+ throw new YorkieError(
7724
+ Code.ErrInvalidArgument,
7725
+ `cant find the given node: ${createdAt.toIDString()}`
7726
+ );
7727
+ }
7728
+ let node = entry.positionNode;
8055
7729
  do {
8056
7730
  node = node.getPrev();
8057
- } while (this.dummyHead !== node && node.isRemoved());
8058
- return node.getValue().getCreatedAt();
7731
+ if (!node.getElementEntry()) {
7732
+ continue;
7733
+ }
7734
+ if (this.dummyHead === node || !node.isRemoved()) {
7735
+ break;
7736
+ }
7737
+ } while (node);
7738
+ return node.getPositionCreatedAt();
7739
+ }
7740
+ /**
7741
+ * `getPrevCreatedAt` returns the position node's createdAt of the
7742
+ * previous element. Delegates to findPrevCreatedAt.
7743
+ */
7744
+ getPrevCreatedAt(createdAt) {
7745
+ return this.findPrevCreatedAt(createdAt);
8059
7746
  }
8060
7747
  /**
8061
7748
  * `delete` deletes the node of the given creation time.
8062
7749
  */
8063
7750
  delete(createdAt, editedAt) {
8064
- const node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
7751
+ const entry = this.elementMapByCreatedAt.get(createdAt.toIDString());
7752
+ if (!entry) {
7753
+ throw new YorkieError(
7754
+ Code.ErrInvalidArgument,
7755
+ `cant find the given node: ${createdAt.toIDString()}`
7756
+ );
7757
+ }
7758
+ const node = entry.positionNode;
8065
7759
  const alreadyRemoved = node.isRemoved();
8066
- if (node.remove(editedAt) && !alreadyRemoved) {
7760
+ if (entry.elem.remove(editedAt) && !alreadyRemoved) {
8067
7761
  this.nodeMapByIndex.splayNode(node);
8068
7762
  }
8069
- return node.getValue();
7763
+ return entry.elem;
8070
7764
  }
8071
7765
  /**
8072
7766
  * `set` sets the given element at the given creation time.
8073
7767
  */
8074
7768
  set(createdAt, element, executedAt) {
8075
- const node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
8076
- if (!node) {
7769
+ if (!this.elementMapByCreatedAt.has(createdAt.toIDString())) {
8077
7770
  throw new YorkieError(
8078
7771
  Code.ErrInvalidArgument,
8079
7772
  `cant find the given node: ${createdAt.toIDString()}`
8080
7773
  );
8081
7774
  }
8082
- this.insertAfter(node.getCreatedAt(), element, executedAt);
7775
+ this.insertAfter(createdAt, element, executedAt);
8083
7776
  return this.delete(createdAt, executedAt);
8084
7777
  }
8085
7778
  /**
@@ -8108,18 +7801,80 @@
8108
7801
  return this.last.getValue();
8109
7802
  }
8110
7803
  /**
8111
- * `getLastCreatedAt` returns the creation time of last element.
7804
+ * `getLastCreatedAt` returns the position node's createdAt of the
7805
+ * last node in the linked list. This is a position identity
7806
+ * suitable for use as prevCreatedAt.
8112
7807
  */
8113
7808
  getLastCreatedAt() {
8114
- return this.last.getCreatedAt();
7809
+ return this.last.getPositionCreatedAt();
8115
7810
  }
8116
7811
  /**
8117
- * `toTestString` returns a String containing the meta data of the node id
8118
- * for debugging purpose.
7812
+ * `posCreatedAt` returns the createdAt of the position node
7813
+ * currently holding the element. Used to convert element identity
7814
+ * to position identity.
7815
+ */
7816
+ posCreatedAt(elemCreatedAt) {
7817
+ const entry = this.elementMapByCreatedAt.get(elemCreatedAt.toIDString());
7818
+ if (!entry) {
7819
+ throw new YorkieError(
7820
+ Code.ErrInvalidArgument,
7821
+ `cant find the given node: ${elemCreatedAt.toIDString()}`
7822
+ );
7823
+ }
7824
+ return entry.positionNode.getPositionCreatedAt();
7825
+ }
7826
+ /**
7827
+ * `addDeadPosition` appends a dead position node during snapshot
7828
+ * restoration.
7829
+ */
7830
+ addDeadPosition(posCreatedAt, removedAt) {
7831
+ const node = RGATreeListNode.createBarePosition(posCreatedAt);
7832
+ node.setRemovedAt(removedAt);
7833
+ const prevNode = this.last;
7834
+ RGATreeListNode.insertNodeAfter(prevNode, node);
7835
+ this.last = node;
7836
+ this.nodeMapByIndex.insertAfter(prevNode, node);
7837
+ this.nodeMapByCreatedAt.set(posCreatedAt.toIDString(), node);
7838
+ }
7839
+ /**
7840
+ * `addMovedElement` appends an element with explicit position
7841
+ * identity during snapshot restoration.
7842
+ */
7843
+ addMovedElement(elem, posCreatedAt, posMovedAt) {
7844
+ const entry = new ElementEntry(elem);
7845
+ entry.posMovedAt = posMovedAt;
7846
+ const node = RGATreeListNode.createBarePosition(posCreatedAt);
7847
+ node.setElementEntry(entry);
7848
+ entry.positionNode = node;
7849
+ const prevNode = this.last;
7850
+ RGATreeListNode.insertNodeAfter(prevNode, node);
7851
+ this.last = node;
7852
+ this.nodeMapByIndex.insertAfter(prevNode, node);
7853
+ this.nodeMapByCreatedAt.set(posCreatedAt.toIDString(), node);
7854
+ this.elementMapByCreatedAt.set(elem.getCreatedAt().toIDString(), entry);
7855
+ }
7856
+ /**
7857
+ * `allNodes` returns all nodes including dead position nodes.
7858
+ */
7859
+ allNodes() {
7860
+ const nodes = [];
7861
+ let current = this.dummyHead.getNext();
7862
+ while (current) {
7863
+ nodes.push(current);
7864
+ current = current.getNext();
7865
+ }
7866
+ return nodes;
7867
+ }
7868
+ /**
7869
+ * `toTestString` returns a String containing the meta data of the
7870
+ * node id for debugging purpose.
8119
7871
  */
8120
7872
  toTestString() {
8121
7873
  const json = [];
8122
7874
  for (const node of this) {
7875
+ if (!node.getElementEntry()) {
7876
+ continue;
7877
+ }
8123
7878
  const elem = `${node.getCreatedAt().toIDString()}:${node.getValue().toJSON()}`;
8124
7879
  if (node.isRemoved()) {
8125
7880
  json.push(`{${elem}}`);
@@ -8176,10 +7931,11 @@
8176
7931
  this.elements.insertAfter(prevCreatedAt, value, executedAt);
8177
7932
  }
8178
7933
  /**
8179
- * `moveAfter` moves the given `createdAt` element after the `prevCreatedAt`.
7934
+ * `moveAfter` moves the given `createdAt` element after the
7935
+ * `prevCreatedAt`. Returns the dead position node for GC.
8180
7936
  */
8181
7937
  moveAfter(prevCreatedAt, createdAt, executedAt) {
8182
- this.elements.moveAfter(prevCreatedAt, createdAt, executedAt);
7938
+ return this.elements.moveAfter(prevCreatedAt, createdAt, executedAt);
8183
7939
  }
8184
7940
  /**
8185
7941
  * `get` returns the element of the given index.
@@ -8208,11 +7964,20 @@
8208
7964
  return this.elements.getLast();
8209
7965
  }
8210
7966
  /**
8211
- * `getPrevCreatedAt` returns the creation time of the previous node.
7967
+ * `getPrevCreatedAt` returns the creation time of the previous
7968
+ * node.
8212
7969
  */
8213
7970
  getPrevCreatedAt(createdAt) {
8214
7971
  return this.elements.getPrevCreatedAt(createdAt);
8215
7972
  }
7973
+ /**
7974
+ * `posCreatedAt` returns the createdAt of the position node
7975
+ * currently holding the element. Used to convert element identity
7976
+ * to position identity for moves.
7977
+ */
7978
+ posCreatedAt(elemCreatedAt) {
7979
+ return this.elements.posCreatedAt(elemCreatedAt);
7980
+ }
8216
7981
  /**
8217
7982
  * `delete` deletes the element of the given creation time.
8218
7983
  */
@@ -8226,7 +7991,8 @@
8226
7991
  return this.elements.deleteByIndex(index, editedAt);
8227
7992
  }
8228
7993
  /**
8229
- * `set` sets the given element at the given position of the creation time.
7994
+ * `set` sets the given element at the given position of the
7995
+ * creation time.
8230
7996
  */
8231
7997
  set(createdAt, value, executedAt) {
8232
7998
  return this.elements.set(createdAt, value, executedAt);
@@ -8244,18 +8010,19 @@
8244
8010
  return this.elements.length;
8245
8011
  }
8246
8012
  /**
8247
- * `[Symbol.iterator]` returns an iterator for the elements in this array.
8013
+ * `[Symbol.iterator]` returns an iterator for the elements in
8014
+ * this array.
8248
8015
  */
8249
8016
  *[Symbol.iterator]() {
8250
8017
  for (const node of this.elements) {
8251
- if (!node.isRemoved()) {
8018
+ if (node.getElementEntry() && !node.isRemoved()) {
8252
8019
  yield node.getValue();
8253
8020
  }
8254
8021
  }
8255
8022
  }
8256
8023
  /**
8257
- * `toTestString` returns a String containing the meta data of this value
8258
- * for debugging purpose.
8024
+ * `toTestString` returns a String containing the meta data of
8025
+ * this value for debugging purpose.
8259
8026
  */
8260
8027
  toTestString() {
8261
8028
  return this.elements.toTestString();
@@ -8265,6 +8032,9 @@
8265
8032
  */
8266
8033
  getDescendants(callback) {
8267
8034
  for (const node of this.elements) {
8035
+ if (!node.getElementEntry()) {
8036
+ continue;
8037
+ }
8268
8038
  const element = node.getValue();
8269
8039
  if (callback(element, this)) {
8270
8040
  return;
@@ -8326,21 +8096,52 @@
8326
8096
  return this.toJSON();
8327
8097
  }
8328
8098
  /**
8329
- * `getElements` returns an array of elements contained in this RGATreeList.
8099
+ * `getElements` returns the underlying RGATreeList.
8330
8100
  */
8331
8101
  getElements() {
8332
8102
  return this.elements;
8333
8103
  }
8104
+ /**
8105
+ * `getRGATreeList` returns the underlying RGATreeList (GCParent
8106
+ * for dead positions).
8107
+ */
8108
+ getRGATreeList() {
8109
+ return this.elements;
8110
+ }
8111
+ /**
8112
+ * `getAllRGANodes` returns all RGA nodes including dead position
8113
+ * nodes.
8114
+ */
8115
+ getAllRGANodes() {
8116
+ return this.elements.allNodes();
8117
+ }
8334
8118
  /**
8335
8119
  * `deepcopy` copies itself deeply.
8336
8120
  */
8337
8121
  deepcopy() {
8338
8122
  const clone = CRDTArray.create(this.getCreatedAt());
8339
8123
  for (const node of this.elements) {
8340
- clone.elements.insertAfter(
8341
- clone.getLastCreatedAt(),
8342
- node.getValue().deepcopy()
8343
- );
8124
+ if (!node.getElementEntry()) {
8125
+ const removedAt = node.getRemovedAt();
8126
+ if (removedAt) {
8127
+ clone.elements.addDeadPosition(
8128
+ node.getPositionCreatedAt(),
8129
+ removedAt
8130
+ );
8131
+ }
8132
+ continue;
8133
+ }
8134
+ const value = node.getValue().deepcopy();
8135
+ const posMovedAt = node.getPositionMovedAt();
8136
+ if (posMovedAt) {
8137
+ clone.elements.addMovedElement(
8138
+ value,
8139
+ node.getPositionCreatedAt(),
8140
+ posMovedAt
8141
+ );
8142
+ } else {
8143
+ clone.elements.insertAfter(clone.getLastCreatedAt(), value);
8144
+ }
8344
8145
  }
8345
8146
  clone.setRemovedAt(this.getRemovedAt());
8346
8147
  clone.setMovedAt(this.getMovedAt());
@@ -8597,6 +8398,9 @@
8597
8398
  if (removed) {
8598
8399
  root.registerRemovedElement(removed);
8599
8400
  }
8401
+ if (value.getRemovedAt()) {
8402
+ root.registerRemovedElement(value);
8403
+ }
8600
8404
  return {
8601
8405
  opInfos: [
8602
8406
  {
@@ -8689,7 +8493,17 @@
8689
8493
  const array = parentObject;
8690
8494
  const reverseOp = this.toReverseOperation(array);
8691
8495
  const previousIndex = Number(array.subPathOf(this.createdAt));
8692
- array.moveAfter(this.prevCreatedAt, this.createdAt, this.getExecutedAt());
8496
+ const deadNode = array.moveAfter(
8497
+ this.prevCreatedAt,
8498
+ this.createdAt,
8499
+ this.getExecutedAt()
8500
+ );
8501
+ if (deadNode) {
8502
+ root.registerGCPair({
8503
+ parent: array.getRGATreeList(),
8504
+ child: deadNode
8505
+ });
8506
+ }
8693
8507
  const index = Number(array.subPathOf(this.createdAt));
8694
8508
  return {
8695
8509
  opInfos: [
@@ -8712,7 +8526,8 @@
8712
8526
  );
8713
8527
  }
8714
8528
  /**
8715
- * `getEffectedCreatedAt` returns the creation time of the effected element.
8529
+ * `getEffectedCreatedAt` returns the creation time of the
8530
+ * effected element.
8716
8531
  */
8717
8532
  getEffectedCreatedAt() {
8718
8533
  return this.createdAt;
@@ -8724,7 +8539,8 @@
8724
8539
  return `${this.getParentCreatedAt().toTestString()}.MOVE`;
8725
8540
  }
8726
8541
  /**
8727
- * `getPrevCreatedAt` returns the creation time of previous element.
8542
+ * `getPrevCreatedAt` returns the creation time of previous
8543
+ * element.
8728
8544
  */
8729
8545
  getPrevCreatedAt() {
8730
8546
  return this.prevCreatedAt;
@@ -8736,7 +8552,8 @@
8736
8552
  return this.createdAt;
8737
8553
  }
8738
8554
  /**
8739
- * `setPrevCreatedAt` sets the creation time of the previous element.
8555
+ * `setPrevCreatedAt` sets the creation time of the previous
8556
+ * element.
8740
8557
  */
8741
8558
  setPrevCreatedAt(createdAt) {
8742
8559
  this.prevCreatedAt = createdAt;
@@ -11320,7 +11137,7 @@
11320
11137
  this._children = left;
11321
11138
  clone._children = actualRight;
11322
11139
  this.visibleSize = this._children.reduce(
11323
- (acc, child) => acc + child.paddedSize(),
11140
+ (acc, child) => acc + (child.isRemoved ? 0 : child.paddedSize()),
11324
11141
  0
11325
11142
  );
11326
11143
  this.totalSize = this._children.reduce(
@@ -11328,7 +11145,7 @@
11328
11145
  0
11329
11146
  );
11330
11147
  clone.visibleSize = clone._children.reduce(
11331
- (acc, child) => acc + child.paddedSize(),
11148
+ (acc, child) => acc + (child.isRemoved ? 0 : child.paddedSize()),
11332
11149
  0
11333
11150
  );
11334
11151
  clone.totalSize = clone._children.reduce(
@@ -12080,7 +11897,7 @@
12080
11897
  CRDTTreeNodeID.of(issueTimeTicket(), 0),
12081
11898
  this.type,
12082
11899
  void 0,
12083
- void 0,
11900
+ this.attrs?.deepcopy(),
12084
11901
  this.removedAt
12085
11902
  );
12086
11903
  }
@@ -12437,6 +12254,9 @@
12437
12254
  const changes = [];
12438
12255
  const attrs = attributes ? parseObjectValues(attributes) : {};
12439
12256
  const pairs = [];
12257
+ const prevAttributes = /* @__PURE__ */ new Map();
12258
+ const newAttrKeys = [];
12259
+ let capturedPrev = false;
12440
12260
  this.traverseInPosRange(
12441
12261
  fromParent,
12442
12262
  fromLeft,
@@ -12452,6 +12272,16 @@
12452
12272
  if (tokenType === TokenType.End && versionVector !== void 0 && this.hasUnknownSplitSibling(node, versionVector)) {
12453
12273
  return;
12454
12274
  }
12275
+ if (!capturedPrev) {
12276
+ for (const key of Object.keys(attributes)) {
12277
+ if (node.attrs?.has(key)) {
12278
+ prevAttributes.set(key, node.attrs.get(key));
12279
+ } else {
12280
+ newAttrKeys.push(key);
12281
+ }
12282
+ }
12283
+ capturedPrev = true;
12284
+ }
12455
12285
  const updatedAttrPairs = node.setAttrs(attributes, editedAt);
12456
12286
  const affectedAttrs = updatedAttrPairs.reduce(
12457
12287
  (acc, [, curr]) => {
@@ -12487,10 +12317,57 @@
12487
12317
  addDataSizes(diff, curr.getDataSize());
12488
12318
  }
12489
12319
  }
12320
+ if (tokenType === TokenType.Start && versionVector !== void 0) {
12321
+ let current = node;
12322
+ while (current.insNextID) {
12323
+ const next = this.findFloorNode(current.insNextID);
12324
+ if (!next || next.isText) {
12325
+ break;
12326
+ }
12327
+ if (ticketKnown(versionVector, next.id.getCreatedAt())) {
12328
+ break;
12329
+ }
12330
+ const siblingPairs = next.setAttrs(attributes, editedAt);
12331
+ const siblingAffectedAttrs = siblingPairs.reduce(
12332
+ (acc, [, curr]) => {
12333
+ if (curr) {
12334
+ acc[curr.getKey()] = attrs[curr.getKey()];
12335
+ }
12336
+ return acc;
12337
+ },
12338
+ {}
12339
+ );
12340
+ if (Object.keys(siblingAffectedAttrs).length > 0) {
12341
+ const parentOfNext = next.parent;
12342
+ const previousNext = next.prevSibling || parentOfNext;
12343
+ changes.push({
12344
+ type: "style",
12345
+ from: this.toIndex(parentOfNext, previousNext),
12346
+ to: this.toIndex(next, next),
12347
+ fromPath: this.toPath(parentOfNext, previousNext),
12348
+ toPath: this.toPath(next, next),
12349
+ actor: editedAt.getActorID(),
12350
+ value: siblingAffectedAttrs
12351
+ });
12352
+ }
12353
+ for (const [prev] of siblingPairs) {
12354
+ if (prev) {
12355
+ pairs.push({ parent: next, child: prev });
12356
+ }
12357
+ }
12358
+ for (const [key] of Object.entries(attrs)) {
12359
+ const curr = next.attrs?.getNodeMapByKey().get(key);
12360
+ if (curr !== void 0) {
12361
+ addDataSizes(diff, curr.getDataSize());
12362
+ }
12363
+ }
12364
+ current = next;
12365
+ }
12366
+ }
12490
12367
  }
12491
12368
  }
12492
12369
  );
12493
- return [pairs, changes, diff];
12370
+ return [pairs, changes, diff, prevAttributes, newAttrKeys];
12494
12371
  }
12495
12372
  /**
12496
12373
  * `removeStyle` removes the given attributes of the given range.
@@ -12508,6 +12385,8 @@
12508
12385
  addDataSizes(diff, diffTo, diffFrom);
12509
12386
  const changes = [];
12510
12387
  const pairs = [];
12388
+ const prevAttributes = /* @__PURE__ */ new Map();
12389
+ let capturedPrev = false;
12511
12390
  this.traverseInPosRange(
12512
12391
  fromParent,
12513
12392
  fromLeft,
@@ -12526,6 +12405,14 @@
12526
12405
  if (!node.attrs) {
12527
12406
  node.attrs = new RHT();
12528
12407
  }
12408
+ if (!capturedPrev) {
12409
+ for (const key of attributesToRemove) {
12410
+ if (node.attrs.has(key)) {
12411
+ prevAttributes.set(key, node.attrs.get(key));
12412
+ }
12413
+ }
12414
+ capturedPrev = true;
12415
+ }
12529
12416
  for (const value of attributesToRemove) {
12530
12417
  const nodesTobeRemoved = node.attrs.remove(value, editedAt);
12531
12418
  for (const rhtNode of nodesTobeRemoved) {
@@ -12543,10 +12430,47 @@
12543
12430
  toPath: this.toPath(node, node),
12544
12431
  value: attributesToRemove
12545
12432
  });
12433
+ if (tokenType === TokenType.Start && versionVector !== void 0) {
12434
+ let current = node;
12435
+ while (current.insNextID) {
12436
+ const next = this.findFloorNode(current.insNextID);
12437
+ if (!next || next.isText) {
12438
+ break;
12439
+ }
12440
+ if (ticketKnown(versionVector, next.id.getCreatedAt())) {
12441
+ break;
12442
+ }
12443
+ if (!next.attrs) {
12444
+ next.attrs = new RHT();
12445
+ }
12446
+ let removedAny = false;
12447
+ for (const value of attributesToRemove) {
12448
+ const nodesTobeRemoved = next.attrs.remove(value, editedAt);
12449
+ removedAny = removedAny || nodesTobeRemoved.length > 0;
12450
+ for (const rhtNode of nodesTobeRemoved) {
12451
+ pairs.push({ parent: next, child: rhtNode });
12452
+ }
12453
+ }
12454
+ if (removedAny) {
12455
+ const parentOfNext = next.parent;
12456
+ const previousNext = next.prevSibling || parentOfNext;
12457
+ changes.push({
12458
+ actor: editedAt.getActorID(),
12459
+ type: "removeStyle",
12460
+ from: this.toIndex(parentOfNext, previousNext),
12461
+ to: this.toIndex(next, next),
12462
+ fromPath: this.toPath(parentOfNext, previousNext),
12463
+ toPath: this.toPath(next, next),
12464
+ value: attributesToRemove
12465
+ });
12466
+ }
12467
+ current = next;
12468
+ }
12469
+ }
12546
12470
  }
12547
12471
  }
12548
12472
  );
12549
- return [pairs, changes, diff];
12473
+ return [pairs, changes, diff, prevAttributes];
12550
12474
  }
12551
12475
  /**
12552
12476
  * `edit` edits the tree with the given range and content.
@@ -12680,7 +12604,7 @@
12680
12604
  while (splitCount < splitLevel) {
12681
12605
  parent.split(
12682
12606
  this,
12683
- parent.findOffset(left) + 1,
12607
+ parent.findOffset(left, true) + 1,
12684
12608
  issueTimeTicket,
12685
12609
  versionVector
12686
12610
  );
@@ -13194,6 +13118,13 @@
13194
13118
  toIdx;
13195
13119
  lastFromIdx;
13196
13120
  lastToIdx;
13121
+ /**
13122
+ * `redoSplitLevel` is set on boundary-deletion undo ops that were generated
13123
+ * to reverse a split. When this op executes (as undo), `toReverseOperation`
13124
+ * uses this value to generate a proper split op for redo, rather than
13125
+ * re-inserting the raw tombstoned boundary nodes as content.
13126
+ */
13127
+ redoSplitLevel;
13197
13128
  constructor(parentCreatedAt, fromPos, toPos, contents, splitLevel, executedAt, isUndoOp, fromIdx, toIdx) {
13198
13129
  super(parentCreatedAt, executedAt);
13199
13130
  this.fromPos = fromPos;
@@ -13279,7 +13210,13 @@
13279
13210
  0
13280
13211
  );
13281
13212
  this.lastToIdx = preEditFromIdx + removedSize;
13282
- const reverseOp = this.splitLevel === 0 ? this.toReverseOperation(tree, removedNodes, preEditFromIdx) : void 0;
13213
+ let reverseOp;
13214
+ const isPureL1Split = this.splitLevel === 1 && !this.contents?.length && removedNodes.length === 0;
13215
+ if (this.splitLevel === 0) {
13216
+ reverseOp = this.toReverseOperation(tree, removedNodes, preEditFromIdx);
13217
+ } else if (isPureL1Split) {
13218
+ reverseOp = this.toSplitReverseOperation(tree, preEditFromIdx);
13219
+ }
13283
13220
  root.acc(diff);
13284
13221
  for (const pair of pairs) {
13285
13222
  root.registerGCPair(pair);
@@ -13315,6 +13252,24 @@
13315
13252
  * @param preEditFromIdx - The from index captured BEFORE the edit
13316
13253
  */
13317
13254
  toReverseOperation(tree, removedNodes, preEditFromIdx) {
13255
+ if (this.redoSplitLevel !== void 0 && this.redoSplitLevel > 0) {
13256
+ const splitRedoFromPos = tree.findPos(preEditFromIdx);
13257
+ const splitRedoOp = TreeEditOperation.create(
13258
+ this.getParentCreatedAt(),
13259
+ splitRedoFromPos,
13260
+ splitRedoFromPos,
13261
+ void 0,
13262
+ // no inserted content
13263
+ this.redoSplitLevel,
13264
+ void 0,
13265
+ // executedAt assigned at redo time
13266
+ true,
13267
+ // isUndoOp (treated as undo/redo op)
13268
+ preEditFromIdx,
13269
+ preEditFromIdx
13270
+ );
13271
+ return splitRedoOp;
13272
+ }
13318
13273
  const insertedContentSize = this.contents ? this.contents.reduce((sum, node) => sum + node.paddedSize(), 0) : 0;
13319
13274
  const maxNeededIdx = preEditFromIdx + insertedContentSize;
13320
13275
  if (maxNeededIdx > tree.getSize()) {
@@ -13352,6 +13307,45 @@
13352
13307
  reverseToIdx
13353
13308
  );
13354
13309
  }
13310
+ /**
13311
+ * `toSplitReverseOperation` creates the reverse operation for a split edit.
13312
+ *
13313
+ * A split creates element boundaries (close + open tags). The reverse
13314
+ * is a boundary deletion: a splitLevel=0 edit that removes those tokens,
13315
+ * merging the split elements back together.
13316
+ *
13317
+ * boundarySize = 2 * splitLevel (each level creates 1 close + 1 open tag)
13318
+ *
13319
+ * @param tree - The CRDTTree after the split has been applied
13320
+ * @param preEditFromIdx - The from index captured BEFORE the split
13321
+ */
13322
+ toSplitReverseOperation(tree, preEditFromIdx) {
13323
+ const boundarySize = 2 * this.splitLevel;
13324
+ const reverseFromIdx = preEditFromIdx;
13325
+ const reverseToIdx = preEditFromIdx + boundarySize;
13326
+ if (reverseToIdx > tree.getSize()) {
13327
+ return void 0;
13328
+ }
13329
+ const reverseFromPos = tree.findPos(reverseFromIdx);
13330
+ const reverseToPos = tree.findPos(reverseToIdx);
13331
+ const boundaryDeletionOp = TreeEditOperation.create(
13332
+ this.getParentCreatedAt(),
13333
+ reverseFromPos,
13334
+ reverseToPos,
13335
+ void 0,
13336
+ // no content — this is a deletion
13337
+ 0,
13338
+ // splitLevel=0: boundary deletion
13339
+ void 0,
13340
+ // executedAt assigned at undo time
13341
+ true,
13342
+ // isUndoOp
13343
+ reverseFromIdx,
13344
+ reverseToIdx
13345
+ );
13346
+ boundaryDeletionOp.redoSplitLevel = this.splitLevel;
13347
+ return boundaryDeletionOp;
13348
+ }
13355
13349
  /**
13356
13350
  * `normalizePos` returns the visible-index range of this operation.
13357
13351
  * For undo ops, returns the stored (possibly reconciled) indices.
@@ -14057,35 +14051,196 @@
14057
14051
  }
14058
14052
  }
14059
14053
  const InitialCheckpoint = new Checkpoint(0n, 0);
14060
- const removeDecimal = (number) => number < 0 ? Math.ceil(number) : Math.floor(number);
14054
+ const hllPrecision = 14;
14055
+ const hllRegisterCount = 1 << hllPrecision;
14056
+ const prime64x1 = 0x9e3779b185ebca87n;
14057
+ const prime64x2 = 0xc2b2ae3d27d4eb4fn;
14058
+ const prime64x3 = 0x165667b19e3779f9n;
14059
+ const prime64x4 = 0x85ebca77c2b2ae63n;
14060
+ const prime64x5 = 0x27d4eb2f165667c5n;
14061
+ const mask64 = 0xffffffffffffffffn;
14062
+ class HLL {
14063
+ registers;
14064
+ constructor() {
14065
+ this.registers = new Uint8Array(hllRegisterCount);
14066
+ }
14067
+ /**
14068
+ * `add` adds a value to the HLL and returns true if the register was updated.
14069
+ */
14070
+ add(value) {
14071
+ const hash = xxhash64(value);
14072
+ const idx = Number(hash >> BigInt(64 - hllPrecision));
14073
+ const remaining = hash << BigInt(hllPrecision) & mask64 | 1n << BigInt(hllPrecision - 1);
14074
+ const rho = countLeadingZeros64(remaining) + 1;
14075
+ if (rho > this.registers[idx]) {
14076
+ this.registers[idx] = rho;
14077
+ return true;
14078
+ }
14079
+ return false;
14080
+ }
14081
+ /**
14082
+ * `count` returns the approximate cardinality estimate.
14083
+ */
14084
+ count() {
14085
+ const m = hllRegisterCount;
14086
+ const alpha = 0.7213 / (1 + 1.079 / m);
14087
+ let sum = 0;
14088
+ let zeros = 0;
14089
+ for (let i = 0; i < m; i++) {
14090
+ sum += Math.pow(2, -this.registers[i]);
14091
+ if (this.registers[i] === 0) zeros++;
14092
+ }
14093
+ let estimate = alpha * m * m / sum;
14094
+ if (estimate <= 2.5 * m && zeros > 0) {
14095
+ estimate = m * Math.log(m / zeros);
14096
+ }
14097
+ return Math.round(estimate);
14098
+ }
14099
+ /**
14100
+ * `merge` merges another HLL into this one by taking the max of each register.
14101
+ * This operation is commutative, associative, and idempotent.
14102
+ */
14103
+ merge(other) {
14104
+ for (let i = 0; i < hllRegisterCount; i++) {
14105
+ if (other.registers[i] > this.registers[i]) {
14106
+ this.registers[i] = other.registers[i];
14107
+ }
14108
+ }
14109
+ }
14110
+ /**
14111
+ * `toBytes` serializes the HLL registers to a byte array.
14112
+ */
14113
+ toBytes() {
14114
+ return new Uint8Array(this.registers);
14115
+ }
14116
+ /**
14117
+ * `restore` restores the HLL registers from a byte array.
14118
+ * Throws if the data length does not match the register count.
14119
+ */
14120
+ restore(data) {
14121
+ if (data.length !== hllRegisterCount) {
14122
+ throw new Error(
14123
+ `invalid HLL register payload: got ${data.length} bytes, want ${hllRegisterCount}`
14124
+ );
14125
+ }
14126
+ this.registers.set(data);
14127
+ }
14128
+ }
14129
+ function xxhash64(input) {
14130
+ const buf = new TextEncoder().encode(input);
14131
+ const len = buf.length;
14132
+ let h64;
14133
+ let offset = 0;
14134
+ const seed = 0n;
14135
+ if (len >= 32) {
14136
+ let v1 = seed + prime64x1 + prime64x2 & mask64;
14137
+ let v2 = seed + prime64x2 & mask64;
14138
+ let v3 = seed;
14139
+ let v4 = seed - prime64x1 & mask64;
14140
+ while (offset <= len - 32) {
14141
+ v1 = xxRound(v1, readU64LE(buf, offset));
14142
+ offset += 8;
14143
+ v2 = xxRound(v2, readU64LE(buf, offset));
14144
+ offset += 8;
14145
+ v3 = xxRound(v3, readU64LE(buf, offset));
14146
+ offset += 8;
14147
+ v4 = xxRound(v4, readU64LE(buf, offset));
14148
+ offset += 8;
14149
+ }
14150
+ h64 = rotl64(v1, 1n) + rotl64(v2, 7n) + rotl64(v3, 12n) + rotl64(v4, 18n) & mask64;
14151
+ h64 = xxMergeRound(h64, v1);
14152
+ h64 = xxMergeRound(h64, v2);
14153
+ h64 = xxMergeRound(h64, v3);
14154
+ h64 = xxMergeRound(h64, v4);
14155
+ } else {
14156
+ h64 = seed + prime64x5 & mask64;
14157
+ }
14158
+ h64 = h64 + BigInt(len) & mask64;
14159
+ while (offset + 8 <= len) {
14160
+ const k1 = xxRound(0n, readU64LE(buf, offset));
14161
+ h64 = rotl64(h64 ^ k1, 27n) * prime64x1 + prime64x4 & mask64;
14162
+ offset += 8;
14163
+ }
14164
+ if (offset + 4 <= len) {
14165
+ h64 = h64 ^ readU32LE(buf, offset) * prime64x1 & mask64;
14166
+ h64 = rotl64(h64, 23n) * prime64x2 + prime64x3 & mask64;
14167
+ offset += 4;
14168
+ }
14169
+ while (offset < len) {
14170
+ h64 = h64 ^ BigInt(buf[offset]) * prime64x5 & mask64;
14171
+ h64 = rotl64(h64, 11n) * prime64x1 & mask64;
14172
+ offset++;
14173
+ }
14174
+ h64 = (h64 ^ h64 >> 33n) * prime64x2 & mask64;
14175
+ h64 = (h64 ^ h64 >> 29n) * prime64x3 & mask64;
14176
+ h64 = (h64 ^ h64 >> 32n) & mask64;
14177
+ return h64;
14178
+ }
14179
+ function rotl64(x, r) {
14180
+ return (x << r | x >> 64n - r) & mask64;
14181
+ }
14182
+ function xxRound(acc, input) {
14183
+ acc = acc + input * prime64x2 & mask64;
14184
+ acc = rotl64(acc, 31n);
14185
+ return acc * prime64x1 & mask64;
14186
+ }
14187
+ function xxMergeRound(acc, val) {
14188
+ val = xxRound(0n, val);
14189
+ acc = (acc ^ val) & mask64;
14190
+ return acc * prime64x1 + prime64x4 & mask64;
14191
+ }
14192
+ function readU64LE(buf, offset) {
14193
+ let val = 0n;
14194
+ for (let i = 7; i >= 0; i--) {
14195
+ val = val << 8n | BigInt(buf[offset + i]);
14196
+ }
14197
+ return val;
14198
+ }
14199
+ function readU32LE(buf, offset) {
14200
+ return BigInt(buf[offset]) | BigInt(buf[offset + 1]) << 8n | BigInt(buf[offset + 2]) << 16n | BigInt(buf[offset + 3]) << 24n;
14201
+ }
14202
+ function countLeadingZeros64(x) {
14203
+ if (x === 0n) return 64;
14204
+ let n = 0;
14205
+ while ((x & 1n << 63n) === 0n) {
14206
+ n++;
14207
+ x <<= 1n;
14208
+ }
14209
+ return n;
14210
+ }
14061
14211
  var CounterType = /* @__PURE__ */ ((CounterType2) => {
14062
14212
  CounterType2[CounterType2["Int"] = 0] = "Int";
14063
14213
  CounterType2[CounterType2["Long"] = 1] = "Long";
14214
+ CounterType2[CounterType2["IntDedup"] = 2] = "IntDedup";
14064
14215
  return CounterType2;
14065
14216
  })(CounterType || {});
14066
14217
  class CRDTCounter extends CRDTElement {
14067
14218
  valueType;
14068
14219
  value;
14220
+ hll;
14069
14221
  constructor(valueType, value, createdAt) {
14070
14222
  super(createdAt);
14071
14223
  this.valueType = valueType;
14072
14224
  switch (valueType) {
14225
+ case 2:
14226
+ this.value = 0;
14227
+ break;
14073
14228
  case 0:
14074
14229
  if (typeof value === "number") {
14075
14230
  if (value > Math.pow(2, 31) - 1 || value < -Math.pow(2, 31)) {
14076
- this.value = Long.fromNumber(value).toInt();
14231
+ this.value = bigintToInt32(BigInt(value));
14077
14232
  } else {
14078
14233
  this.value = removeDecimal(value);
14079
14234
  }
14080
14235
  } else {
14081
- this.value = value.toInt();
14236
+ this.value = bigintToInt32(value);
14082
14237
  }
14083
14238
  break;
14084
14239
  case 1:
14085
14240
  if (typeof value === "number") {
14086
- this.value = Long.fromNumber(value);
14241
+ this.value = BigInt.asIntN(64, BigInt(Math.trunc(value)));
14087
14242
  } else {
14088
- this.value = value;
14243
+ this.value = BigInt.asIntN(64, value);
14089
14244
  }
14090
14245
  break;
14091
14246
  default:
@@ -14094,6 +14249,9 @@
14094
14249
  `unimplemented type: ${valueType}`
14095
14250
  );
14096
14251
  }
14252
+ if (this.isDedup()) {
14253
+ this.hll ??= new HLL();
14254
+ }
14097
14255
  }
14098
14256
  /**
14099
14257
  * `of` creates a new instance of Counter.
@@ -14107,9 +14265,10 @@
14107
14265
  static valueFromBytes(counterType, bytes) {
14108
14266
  switch (counterType) {
14109
14267
  case 0:
14268
+ case 2:
14110
14269
  return bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24;
14111
14270
  case 1:
14112
- return Long.fromBytesLE(Array.from(bytes));
14271
+ return bigintFromBytesLE(bytes);
14113
14272
  default:
14114
14273
  throw new YorkieError(
14115
14274
  Code.ErrUnimplemented,
@@ -14121,7 +14280,10 @@
14121
14280
  * `getDataSize` returns the data usage of this element.
14122
14281
  */
14123
14282
  getDataSize() {
14124
- const data = this.valueType === 0 ? 4 : 8;
14283
+ let data = this.valueType === 0 || this.valueType === 2 ? 4 : 8;
14284
+ if (this.isDedup() && this.hll) {
14285
+ data += this.hll.toBytes().length;
14286
+ }
14125
14287
  return {
14126
14288
  data,
14127
14289
  meta: this.getMetaUsage()
@@ -14160,6 +14322,9 @@
14160
14322
  );
14161
14323
  clone.setRemovedAt(this.getRemovedAt());
14162
14324
  clone.setMovedAt(this.getMovedAt());
14325
+ if (this.isDedup() && this.hll) {
14326
+ clone.restoreHLL(this.hll.toBytes());
14327
+ }
14163
14328
  return clone;
14164
14329
  }
14165
14330
  /**
@@ -14173,12 +14338,8 @@
14173
14338
  */
14174
14339
  static getCounterType(value) {
14175
14340
  switch (typeof value) {
14176
- case "object":
14177
- if (value instanceof Long) {
14178
- return 1;
14179
- } else {
14180
- return;
14181
- }
14341
+ case "bigint":
14342
+ return 1;
14182
14343
  case "number":
14183
14344
  if (value > Math.pow(2, 31) - 1 || value < -Math.pow(2, 31)) {
14184
14345
  return 1;
@@ -14206,7 +14367,7 @@
14206
14367
  */
14207
14368
  isNumericType() {
14208
14369
  const t = this.valueType;
14209
- return t === 0 || t === 1;
14370
+ return t === 0 || t === 1 || t === 2;
14210
14371
  }
14211
14372
  /**
14212
14373
  * `getValueType` get counter value type.
@@ -14225,7 +14386,8 @@
14225
14386
  */
14226
14387
  toBytes() {
14227
14388
  switch (this.valueType) {
14228
- case 0: {
14389
+ case 0:
14390
+ case 2: {
14229
14391
  const intVal = this.value;
14230
14392
  return new Uint8Array([
14231
14393
  intVal & 255,
@@ -14235,9 +14397,7 @@
14235
14397
  ]);
14236
14398
  }
14237
14399
  case 1: {
14238
- const longVal = this.value;
14239
- const longToBytes = longVal.toBytesLE();
14240
- return Uint8Array.from(longToBytes);
14400
+ return bigintToBytesLE(this.value);
14241
14401
  }
14242
14402
  default:
14243
14403
  throw new YorkieError(
@@ -14246,10 +14406,76 @@
14246
14406
  );
14247
14407
  }
14248
14408
  }
14409
+ /**
14410
+ * `isDedup` returns whether dedup mode is enabled (derived from ValueType).
14411
+ */
14412
+ isDedup() {
14413
+ return this.valueType === 2;
14414
+ }
14415
+ /**
14416
+ * `increaseDedup` increases the counter using HLL-based dedup.
14417
+ * Only updates the value if the actor is new (not seen before).
14418
+ */
14419
+ increaseDedup(v, actor) {
14420
+ if (!this.isDedup() || !this.hll) {
14421
+ return this.increase(v);
14422
+ }
14423
+ if (!this.isNumericType() || !v.isNumericType()) {
14424
+ throw new TypeError(`Unsupported type of value: ${typeof v.getValue()}`);
14425
+ }
14426
+ if (!actor) {
14427
+ throw new YorkieError(
14428
+ Code.ErrInvalidArgument,
14429
+ "dedup counter requires actor"
14430
+ );
14431
+ }
14432
+ const val = v.getValue();
14433
+ const isUnit = v.getType() === PrimitiveType.Long ? val === 1n : val === 1;
14434
+ if (!isUnit) {
14435
+ throw new YorkieError(
14436
+ Code.ErrInvalidArgument,
14437
+ "dedup counter only supports increment by 1"
14438
+ );
14439
+ }
14440
+ if (this.hll.add(actor)) {
14441
+ this.recomputeValue();
14442
+ }
14443
+ return this;
14444
+ }
14445
+ /**
14446
+ * `hllBytes` returns the HLL register bytes, or undefined if not in dedup mode.
14447
+ */
14448
+ hllBytes() {
14449
+ return this.hll?.toBytes();
14450
+ }
14451
+ /**
14452
+ * `restoreHLL` restores the HLL state from serialized bytes.
14453
+ */
14454
+ restoreHLL(data) {
14455
+ if (!this.hll) {
14456
+ this.hll = new HLL();
14457
+ }
14458
+ this.hll.restore(data);
14459
+ this.recomputeValue();
14460
+ }
14461
+ /**
14462
+ * `recomputeValue` updates the counter value from the HLL cardinality estimate.
14463
+ */
14464
+ recomputeValue() {
14465
+ if (!this.hll) return;
14466
+ this.value = this.hll.count();
14467
+ }
14249
14468
  /**
14250
14469
  * `increase` increases numeric data.
14470
+ * Dedup counters must use increaseDedup() instead.
14251
14471
  */
14252
14472
  increase(v) {
14473
+ if (this.isDedup()) {
14474
+ throw new YorkieError(
14475
+ Code.ErrInvalidArgument,
14476
+ "dedup counter requires actor, use increaseDedup()"
14477
+ );
14478
+ }
14253
14479
  function checkNumericType(target) {
14254
14480
  if (!target.isNumericType()) {
14255
14481
  throw new TypeError(
@@ -14260,14 +14486,17 @@
14260
14486
  checkNumericType(this);
14261
14487
  checkNumericType(v);
14262
14488
  if (this.valueType === 1) {
14263
- this.value = this.value.add(v.getValue());
14489
+ const delta = typeof v.getValue() === "bigint" ? v.getValue() : BigInt(Math.trunc(v.getValue()));
14490
+ this.value = BigInt.asIntN(64, this.value + delta);
14264
14491
  } else {
14265
14492
  if (v.getType() === PrimitiveType.Long) {
14266
- this.value = this.value + v.getValue().toInt();
14493
+ this.value = this.value + bigintToInt32(v.getValue());
14267
14494
  } else {
14268
- this.value = Long.fromNumber(
14269
- this.value + removeDecimal(v.getValue())
14270
- ).toInt();
14495
+ this.value = bigintToInt32(
14496
+ BigInt(
14497
+ this.value + removeDecimal(v.getValue())
14498
+ )
14499
+ );
14271
14500
  }
14272
14501
  }
14273
14502
  return this;
@@ -14275,15 +14504,23 @@
14275
14504
  }
14276
14505
  class IncreaseOperation extends Operation {
14277
14506
  value;
14278
- constructor(parentCreatedAt, value, executedAt) {
14507
+ actor;
14508
+ constructor(parentCreatedAt, value, executedAt, actor) {
14279
14509
  super(parentCreatedAt, executedAt);
14280
14510
  this.value = value;
14511
+ this.actor = actor || "";
14281
14512
  }
14282
14513
  /**
14283
14514
  * `create` creates a new instance of IncreaseOperation.
14284
14515
  */
14285
- static create(parentCreatedAt, value, executedAt) {
14286
- return new IncreaseOperation(parentCreatedAt, value, executedAt);
14516
+ static create(parentCreatedAt, value, executedAt, actor) {
14517
+ return new IncreaseOperation(parentCreatedAt, value, executedAt, actor);
14518
+ }
14519
+ /**
14520
+ * `getActor` returns the actor ID associated with this operation.
14521
+ */
14522
+ getActor() {
14523
+ return this.actor;
14287
14524
  }
14288
14525
  /**
14289
14526
  * `execute` executes this operation on the given `CRDTRoot`.
@@ -14304,7 +14541,17 @@
14304
14541
  }
14305
14542
  const counter = parentObject;
14306
14543
  const value = this.value.deepcopy();
14307
- counter.increase(value);
14544
+ if (counter.isDedup()) {
14545
+ if (!this.actor) {
14546
+ throw new YorkieError(
14547
+ Code.ErrInvalidArgument,
14548
+ "dedup counter requires actor"
14549
+ );
14550
+ }
14551
+ counter.increaseDedup(value, this.actor);
14552
+ } else {
14553
+ counter.increase(value);
14554
+ }
14308
14555
  return {
14309
14556
  opInfos: [
14310
14557
  {
@@ -14313,7 +14560,9 @@
14313
14560
  value: value.getValue()
14314
14561
  }
14315
14562
  ],
14316
- reverseOp: this.toReverseOperation()
14563
+ // Dedup counters do not support undo/redo because HLL cannot
14564
+ // remove an actor once added.
14565
+ reverseOp: this.actor ? void 0 : this.toReverseOperation()
14317
14566
  };
14318
14567
  }
14319
14568
  /**
@@ -14322,7 +14571,7 @@
14322
14571
  toReverseOperation() {
14323
14572
  const primitiveValue = this.value.deepcopy();
14324
14573
  const valueType = primitiveValue.getType();
14325
- const value = valueType === PrimitiveType.Long ? primitiveValue.getValue().multiply(-1) : primitiveValue.getValue() * -1;
14574
+ const value = valueType === PrimitiveType.Long ? -primitiveValue.getValue() : primitiveValue.getValue() * -1;
14326
14575
  const reverseOp = IncreaseOperation.create(
14327
14576
  this.getParentCreatedAt(),
14328
14577
  Primitive.of(value, primitiveValue.getCreatedAt())
@@ -14407,28 +14656,67 @@
14407
14656
  let changes;
14408
14657
  let pairs;
14409
14658
  let diff = { data: 0, meta: 0 };
14659
+ const reversePrevAttributes = /* @__PURE__ */ new Map();
14660
+ const reverseAttrsToRemove = [];
14410
14661
  if (this.attributes.size) {
14411
14662
  const attributes = {};
14412
14663
  [...this.attributes].forEach(([key, value]) => attributes[key] = value);
14413
- [pairs, changes, diff] = tree.style(
14664
+ let prevAttributes;
14665
+ let newAttrKeys;
14666
+ [pairs, changes, diff, prevAttributes, newAttrKeys] = tree.style(
14414
14667
  [this.fromPos, this.toPos],
14415
14668
  attributes,
14416
14669
  this.getExecutedAt(),
14417
14670
  versionVector
14418
14671
  );
14672
+ for (const [key, value] of prevAttributes) {
14673
+ reversePrevAttributes.set(key, value);
14674
+ }
14675
+ reverseAttrsToRemove.push(...newAttrKeys);
14419
14676
  } else {
14420
14677
  const attributesToRemove = this.attributesToRemove;
14421
- [pairs, changes, diff] = tree.removeStyle(
14678
+ let prevAttributes;
14679
+ [pairs, changes, diff, prevAttributes] = tree.removeStyle(
14422
14680
  [this.fromPos, this.toPos],
14423
14681
  attributesToRemove,
14424
14682
  this.getExecutedAt(),
14425
14683
  versionVector
14426
14684
  );
14685
+ for (const [key, value] of prevAttributes) {
14686
+ reversePrevAttributes.set(key, value);
14687
+ }
14427
14688
  }
14428
14689
  root.acc(diff);
14429
14690
  for (const pair of pairs) {
14430
14691
  root.registerGCPair(pair);
14431
14692
  }
14693
+ let reverseOp;
14694
+ if (reversePrevAttributes.size > 0 && reverseAttrsToRemove.length > 0) {
14695
+ reverseOp = new TreeStyleOperation(
14696
+ this.getParentCreatedAt(),
14697
+ this.fromPos,
14698
+ this.toPos,
14699
+ reversePrevAttributes,
14700
+ reverseAttrsToRemove,
14701
+ void 0
14702
+ );
14703
+ } else if (reverseAttrsToRemove.length > 0) {
14704
+ reverseOp = TreeStyleOperation.createTreeRemoveStyleOperation(
14705
+ this.getParentCreatedAt(),
14706
+ this.fromPos,
14707
+ this.toPos,
14708
+ reverseAttrsToRemove,
14709
+ void 0
14710
+ );
14711
+ } else if (reversePrevAttributes.size > 0) {
14712
+ reverseOp = TreeStyleOperation.create(
14713
+ this.getParentCreatedAt(),
14714
+ this.fromPos,
14715
+ this.toPos,
14716
+ reversePrevAttributes,
14717
+ void 0
14718
+ );
14719
+ }
14432
14720
  return {
14433
14721
  opInfos: changes.map(({ from, to, value, fromPath, toPath }) => {
14434
14722
  return {
@@ -14440,7 +14728,8 @@
14440
14728
  toPath,
14441
14729
  path: root.createPath(this.getParentCreatedAt())
14442
14730
  };
14443
- })
14731
+ }),
14732
+ reverseOp
14444
14733
  };
14445
14734
  }
14446
14735
  /**
@@ -14661,6 +14950,8 @@
14661
14950
  return ValueType.INTEGER_CNT;
14662
14951
  case CounterType.Long:
14663
14952
  return ValueType.LONG_CNT;
14953
+ case CounterType.IntDedup:
14954
+ return ValueType.INTEGER_DEDUP_CNT;
14664
14955
  default:
14665
14956
  throw new YorkieError(
14666
14957
  Code.ErrInvalidType,
@@ -14833,6 +15124,7 @@
14833
15124
  pbIncreaseOperation.executedAt = toTimeTicket(
14834
15125
  increaseOperation.getExecutedAt()
14835
15126
  );
15127
+ pbIncreaseOperation.actor = increaseOperation.getActor();
14836
15128
  pbOperation.body.case = "increase";
14837
15129
  pbOperation.body.value = pbIncreaseOperation;
14838
15130
  } else if (operation instanceof TreeEditOperation) {
@@ -14933,14 +15225,26 @@
14933
15225
  }
14934
15226
  return pbRHTNodes;
14935
15227
  }
14936
- function toRGANodes(rgaTreeList) {
15228
+ function toRGANodes(arr) {
14937
15229
  const pbRGANodes = [];
14938
- for (const rgaTreeListNode of rgaTreeList) {
14939
- pbRGANodes.push(
14940
- create(RGANodeSchema, {
14941
- element: toElement(rgaTreeListNode.getValue())
14942
- })
14943
- );
15230
+ for (const rgaNode of arr.getAllRGANodes()) {
15231
+ if (!rgaNode.getElementEntry()) {
15232
+ pbRGANodes.push(
15233
+ create(RGANodeSchema, {
15234
+ positionCreatedAt: toTimeTicket(rgaNode.getPositionCreatedAt()),
15235
+ positionRemovedAt: toTimeTicket(rgaNode.getRemovedAt())
15236
+ })
15237
+ );
15238
+ continue;
15239
+ }
15240
+ const pbNode = create(RGANodeSchema, {
15241
+ element: toElement(rgaNode.getValue())
15242
+ });
15243
+ if (rgaNode.getPositionMovedAt()) {
15244
+ pbNode.positionMovedAt = toTimeTicket(rgaNode.getPositionMovedAt());
15245
+ pbNode.positionCreatedAt = toTimeTicket(rgaNode.getPositionCreatedAt());
15246
+ }
15247
+ pbRGANodes.push(pbNode);
14944
15248
  }
14945
15249
  return pbRGANodes;
14946
15250
  }
@@ -15040,7 +15344,7 @@
15040
15344
  body: {
15041
15345
  case: "jsonArray",
15042
15346
  value: create(JSONElement_JSONArraySchema, {
15043
- nodes: toRGANodes(arr.getElements()),
15347
+ nodes: toRGANodes(arr),
15044
15348
  createdAt: toTimeTicket(arr.getCreatedAt()),
15045
15349
  movedAt: toTimeTicket(arr.getMovedAt()),
15046
15350
  removedAt: toTimeTicket(arr.getRemovedAt())
@@ -15084,7 +15388,8 @@
15084
15388
  value: counter.toBytes(),
15085
15389
  createdAt: toTimeTicket(counter.getCreatedAt()),
15086
15390
  movedAt: toTimeTicket(counter.getMovedAt()),
15087
- removedAt: toTimeTicket(counter.getRemovedAt())
15391
+ removedAt: toTimeTicket(counter.getRemovedAt()),
15392
+ hllRegisters: counter.hllBytes() || new Uint8Array()
15088
15393
  })
15089
15394
  }
15090
15395
  });
@@ -15248,6 +15553,8 @@
15248
15553
  return CounterType.Int;
15249
15554
  case ValueType.LONG_CNT:
15250
15555
  return CounterType.Long;
15556
+ case ValueType.INTEGER_DEDUP_CNT:
15557
+ return CounterType.IntDedup;
15251
15558
  }
15252
15559
  throw new YorkieError(
15253
15560
  Code.ErrUnimplemented,
@@ -15290,6 +15597,7 @@
15290
15597
  );
15291
15598
  case ValueType.INTEGER_CNT:
15292
15599
  case ValueType.LONG_CNT:
15600
+ case ValueType.INTEGER_DEDUP_CNT:
15293
15601
  return CRDTCounter.create(
15294
15602
  fromCounterType(pbElementSimple.type),
15295
15603
  CRDTCounter.valueFromBytes(
@@ -15472,7 +15780,8 @@
15472
15780
  return IncreaseOperation.create(
15473
15781
  fromTimeTicket(pbIncreaseOperation.parentCreatedAt),
15474
15782
  fromElementSimple(pbIncreaseOperation.value),
15475
- fromTimeTicket(pbIncreaseOperation.executedAt)
15783
+ fromTimeTicket(pbIncreaseOperation.executedAt),
15784
+ pbIncreaseOperation.actor || void 0
15476
15785
  );
15477
15786
  } else if (pbOperation.body.case === "treeEdit") {
15478
15787
  const pbTreeEditOperation = pbOperation.body.value;
@@ -15573,7 +15882,32 @@
15573
15882
  function fromArray(pbArray) {
15574
15883
  const rgaTreeList = new RGATreeList();
15575
15884
  for (const pbRGANode of pbArray.nodes) {
15576
- rgaTreeList.insert(fromElement(pbRGANode.element));
15885
+ if (!pbRGANode.element) {
15886
+ if (!pbRGANode.positionCreatedAt || !pbRGANode.positionRemovedAt) {
15887
+ throw new YorkieError(
15888
+ Code.ErrInvalidArgument,
15889
+ "dead RGA position node missing position timestamps"
15890
+ );
15891
+ }
15892
+ const posCreatedAt = fromTimeTicket(pbRGANode.positionCreatedAt);
15893
+ const posRemovedAt = fromTimeTicket(pbRGANode.positionRemovedAt);
15894
+ rgaTreeList.addDeadPosition(posCreatedAt, posRemovedAt);
15895
+ continue;
15896
+ }
15897
+ const elem = fromElement(pbRGANode.element);
15898
+ const posMovedAt = fromTimeTicket(pbRGANode.positionMovedAt);
15899
+ if (posMovedAt) {
15900
+ if (!pbRGANode.positionCreatedAt) {
15901
+ throw new YorkieError(
15902
+ Code.ErrInvalidArgument,
15903
+ "moved RGA node missing position_created_at"
15904
+ );
15905
+ }
15906
+ const posCreatedAt = fromTimeTicket(pbRGANode.positionCreatedAt);
15907
+ rgaTreeList.addMovedElement(elem, posCreatedAt, posMovedAt);
15908
+ } else {
15909
+ rgaTreeList.insert(elem);
15910
+ }
15577
15911
  }
15578
15912
  const arr = new CRDTArray(fromTimeTicket(pbArray.createdAt), rgaTreeList);
15579
15913
  arr.setMovedAt(fromTimeTicket(pbArray.movedAt));
@@ -15620,6 +15954,9 @@
15620
15954
  );
15621
15955
  counter.setMovedAt(fromTimeTicket(pbCounter.movedAt));
15622
15956
  counter.setRemovedAt(fromTimeTicket(pbCounter.removedAt));
15957
+ if (counter.isDedup() && pbCounter.hllRegisters.length > 0) {
15958
+ counter.restoreHLL(pbCounter.hllRegisters);
15959
+ }
15623
15960
  return counter;
15624
15961
  }
15625
15962
  function fromTree(pbTree) {
@@ -16358,10 +16695,16 @@
16358
16695
  };
16359
16696
  } else if (method === "insertAfter") {
16360
16697
  return (prevID, value) => {
16698
+ let posCreatedAt;
16699
+ try {
16700
+ posCreatedAt = target.posCreatedAt(prevID);
16701
+ } catch {
16702
+ posCreatedAt = prevID;
16703
+ }
16361
16704
  const inserted = ArrayProxy.insertAfterInternal(
16362
16705
  context,
16363
16706
  target,
16364
- prevID,
16707
+ posCreatedAt,
16365
16708
  value
16366
16709
  );
16367
16710
  return toWrappedElement(context, inserted);
@@ -16546,7 +16889,7 @@
16546
16889
  static moveBeforeInternal(context, target, nextCreatedAt, createdAt) {
16547
16890
  const ticket = context.issueTimeTicket();
16548
16891
  const prevCreatedAt = target.getPrevCreatedAt(nextCreatedAt);
16549
- target.moveAfter(prevCreatedAt, createdAt, ticket);
16892
+ const deadNode = target.moveAfter(prevCreatedAt, createdAt, ticket);
16550
16893
  context.push(
16551
16894
  MoveOperation.create(
16552
16895
  target.getCreatedAt(),
@@ -16555,26 +16898,45 @@
16555
16898
  ticket
16556
16899
  )
16557
16900
  );
16901
+ if (deadNode) {
16902
+ context.registerGCPair({
16903
+ parent: target.getRGATreeList(),
16904
+ child: deadNode
16905
+ });
16906
+ }
16558
16907
  }
16559
16908
  /**
16560
16909
  * `moveAfterInternal` moves the given `createdAt` element
16561
- * after the specific element.
16910
+ * after the specific element. Converts element identity to
16911
+ * position identity for the prevCreatedAt.
16562
16912
  */
16563
16913
  static moveAfterInternal(context, target, prevCreatedAt, createdAt) {
16564
16914
  const ticket = context.issueTimeTicket();
16915
+ let posCreatedAt;
16916
+ try {
16917
+ posCreatedAt = target.posCreatedAt(prevCreatedAt);
16918
+ } catch {
16919
+ posCreatedAt = prevCreatedAt;
16920
+ }
16921
+ const deadNode = target.moveAfter(posCreatedAt, createdAt, ticket);
16565
16922
  context.push(
16566
16923
  MoveOperation.create(
16567
16924
  target.getCreatedAt(),
16568
- prevCreatedAt,
16925
+ posCreatedAt,
16569
16926
  createdAt,
16570
16927
  ticket
16571
16928
  )
16572
16929
  );
16573
- target.moveAfter(prevCreatedAt, createdAt, ticket);
16930
+ if (deadNode) {
16931
+ context.registerGCPair({
16932
+ parent: target.getRGATreeList(),
16933
+ child: deadNode
16934
+ });
16935
+ }
16574
16936
  }
16575
16937
  /**
16576
- * `moveAfterByIndexInternal` moves the given element to its new position
16577
- * after the given previous element.
16938
+ * `moveAfterByIndexInternal` moves the given element to its new
16939
+ * position after the given previous element.
16578
16940
  */
16579
16941
  static moveAfterByIndexInternal(context, target, prevIndex, targetIndex) {
16580
16942
  const prevElem = target.get(prevIndex);
@@ -16605,7 +16967,7 @@
16605
16967
  static moveFrontInternal(context, target, createdAt) {
16606
16968
  const ticket = context.issueTimeTicket();
16607
16969
  const head = target.getHead();
16608
- target.moveAfter(head.getCreatedAt(), createdAt, ticket);
16970
+ const deadNode = target.moveAfter(head.getCreatedAt(), createdAt, ticket);
16609
16971
  context.push(
16610
16972
  MoveOperation.create(
16611
16973
  target.getCreatedAt(),
@@ -16614,6 +16976,12 @@
16614
16976
  ticket
16615
16977
  )
16616
16978
  );
16979
+ if (deadNode) {
16980
+ context.registerGCPair({
16981
+ parent: target.getRGATreeList(),
16982
+ child: deadNode
16983
+ });
16984
+ }
16617
16985
  }
16618
16986
  /**
16619
16987
  * `moveLastInternal` moves the given `createdAt` element
@@ -16622,13 +16990,20 @@
16622
16990
  static moveLastInternal(context, target, createdAt) {
16623
16991
  const ticket = context.issueTimeTicket();
16624
16992
  const last = target.getLastCreatedAt();
16625
- target.moveAfter(last, createdAt, ticket);
16993
+ const deadNode = target.moveAfter(last, createdAt, ticket);
16626
16994
  context.push(
16627
16995
  MoveOperation.create(target.getCreatedAt(), last, createdAt, ticket)
16628
16996
  );
16997
+ if (deadNode) {
16998
+ context.registerGCPair({
16999
+ parent: target.getRGATreeList(),
17000
+ child: deadNode
17001
+ });
17002
+ }
16629
17003
  }
16630
17004
  /**
16631
- * `insertAfterInternal` inserts the value after the previously created element.
17005
+ * `insertAfterInternal` inserts the value after the previously
17006
+ * created element.
16632
17007
  */
16633
17008
  static insertAfterInternal(context, target, prevCreatedAt, value) {
16634
17009
  const createdAt = context.issueTimeTicket();
@@ -16656,12 +17031,13 @@
16656
17031
  `index out of bounds: ${index}`
16657
17032
  );
16658
17033
  }
16659
- ArrayProxy.insertAfterInternal(
16660
- context,
16661
- target,
16662
- prevElem.getCreatedAt(),
16663
- value
16664
- );
17034
+ let posCreatedAt;
17035
+ try {
17036
+ posCreatedAt = target.posCreatedAt(prevElem.getCreatedAt());
17037
+ } catch {
17038
+ posCreatedAt = prevElem.getCreatedAt();
17039
+ }
17040
+ ArrayProxy.insertAfterInternal(context, target, posCreatedAt, value);
16665
17041
  return target;
16666
17042
  }
16667
17043
  /**
@@ -16760,7 +17136,17 @@
16760
17136
  }
16761
17137
  }
16762
17138
  if (items) {
16763
- let previousID = from === 0 ? target.getHead().getID() : target.get(from - 1).getID();
17139
+ let previousID;
17140
+ if (from === 0) {
17141
+ previousID = target.getHead().getID();
17142
+ } else {
17143
+ const elemID = target.get(from - 1).getID();
17144
+ try {
17145
+ previousID = target.posCreatedAt(elemID);
17146
+ } catch {
17147
+ previousID = elemID;
17148
+ }
17149
+ }
16764
17150
  for (const item of items) {
16765
17151
  const newElem = ArrayProxy.insertAfterInternal(
16766
17152
  context,
@@ -17089,7 +17475,7 @@
17089
17475
  return this.text.indexRangeToPosRange(fromIdx, toIdx);
17090
17476
  }
17091
17477
  }
17092
- class Counter {
17478
+ class BaseCounter {
17093
17479
  valueType;
17094
17480
  value;
17095
17481
  context;
@@ -17099,7 +17485,7 @@
17099
17485
  this.value = value;
17100
17486
  }
17101
17487
  /**
17102
- * `initialize` initialize this text with context and internal text.
17488
+ * `initialize` links this proxy to a ChangeContext and CRDTCounter.
17103
17489
  */
17104
17490
  initialize(context, counter) {
17105
17491
  this.valueType = counter.getValueType();
@@ -17108,17 +17494,11 @@
17108
17494
  this.value = counter.getValue();
17109
17495
  }
17110
17496
  /**
17111
- * `getID` returns the ID of this text.
17497
+ * `getID` returns the ID of this counter.
17112
17498
  */
17113
17499
  getID() {
17114
17500
  return this.counter.getID();
17115
17501
  }
17116
- /**
17117
- * `getValue` returns the value of this counter;
17118
- */
17119
- getValue() {
17120
- return this.value;
17121
- }
17122
17502
  /**
17123
17503
  * `getValueType` returns the value type of this counter.
17124
17504
  */
@@ -17126,15 +17506,45 @@
17126
17506
  return this.valueType;
17127
17507
  }
17128
17508
  /**
17129
- * `increase` increases numeric data.
17509
+ * `toJSForTest` returns value with meta data for testing.
17130
17510
  */
17131
- increase(v) {
17511
+ toJSForTest() {
17512
+ if (!this.context || !this.counter) {
17513
+ throw new YorkieError(
17514
+ Code.ErrNotInitialized,
17515
+ "Counter is not initialized yet"
17516
+ );
17517
+ }
17518
+ return this.counter.toJSForTest();
17519
+ }
17520
+ /**
17521
+ * `ensureInitialized` throws if this counter has not been initialized.
17522
+ */
17523
+ ensureInitialized() {
17132
17524
  if (!this.context || !this.counter) {
17133
17525
  throw new YorkieError(
17134
17526
  Code.ErrNotInitialized,
17135
17527
  "Counter is not initialized yet"
17136
17528
  );
17137
17529
  }
17530
+ }
17531
+ }
17532
+ class Counter extends BaseCounter {
17533
+ constructor(value) {
17534
+ const type = typeof value === "bigint" ? CounterType.Long : CounterType.Int;
17535
+ super(type, value);
17536
+ }
17537
+ /**
17538
+ * `getValue` returns the value of this counter.
17539
+ */
17540
+ getValue() {
17541
+ return this.value;
17542
+ }
17543
+ /**
17544
+ * `increase` increases numeric data.
17545
+ */
17546
+ increase(v) {
17547
+ this.ensureInitialized();
17138
17548
  const ticket = this.context.issueTimeTicket();
17139
17549
  const value = Primitive.of(v, ticket);
17140
17550
  if (!value.isNumericType()) {
@@ -17148,19 +17558,44 @@
17148
17558
  );
17149
17559
  return this;
17150
17560
  }
17561
+ }
17562
+ class DedupCounter extends BaseCounter {
17563
+ constructor() {
17564
+ super(CounterType.IntDedup, 0);
17565
+ }
17151
17566
  /**
17152
- * `toJSForTest` returns value with meta data for testing.
17567
+ * `getValue` returns the value of this counter. Always a number since
17568
+ * DedupCounter only supports IntDedup.
17153
17569
  */
17154
- toJSForTest() {
17155
- if (!this.context || !this.counter) {
17156
- throw new YorkieError(
17157
- Code.ErrNotInitialized,
17158
- "Counter is not initialized yet"
17159
- );
17570
+ getValue() {
17571
+ return this.value;
17572
+ }
17573
+ /**
17574
+ * `add` records a unique actor in the dedup counter. If the actor has
17575
+ * already been counted, the call is ignored.
17576
+ */
17577
+ add(actor) {
17578
+ this.ensureInitialized();
17579
+ if (!actor) {
17580
+ throw new YorkieError(Code.ErrInvalidArgument, "actor is required");
17160
17581
  }
17161
- return this.counter.toJSForTest();
17582
+ const ticket = this.context.issueTimeTicket();
17583
+ const value = Primitive.of(1, ticket);
17584
+ this.counter.increaseDedup(value, actor);
17585
+ this.context.push(
17586
+ IncreaseOperation.create(
17587
+ this.counter.getCreatedAt(),
17588
+ value,
17589
+ ticket,
17590
+ actor
17591
+ )
17592
+ );
17593
+ return this;
17162
17594
  }
17163
17595
  }
17596
+ function isCounter$1(value) {
17597
+ return value instanceof Counter || value instanceof DedupCounter;
17598
+ }
17164
17599
  function toTreeNode(node) {
17165
17600
  if (node.isText) {
17166
17601
  return {
@@ -17964,7 +18399,12 @@
17964
18399
  } else if (elem instanceof CRDTText) {
17965
18400
  return new Text(context, elem);
17966
18401
  } else if (elem instanceof CRDTCounter) {
17967
- const counter = new Counter(CounterType.Int, 0);
18402
+ if (elem.isDedup()) {
18403
+ const counter2 = new DedupCounter();
18404
+ counter2.initialize(context, elem);
18405
+ return counter2;
18406
+ }
18407
+ const counter = new Counter(0);
17968
18408
  counter.initialize(context, elem);
17969
18409
  return counter;
17970
18410
  } else if (elem instanceof CRDTTree) {
@@ -17994,7 +18434,7 @@
17994
18434
  if (value instanceof Text) {
17995
18435
  element = CRDTText.create(RGATreeSplit.create(), createdAt);
17996
18436
  value.initialize(context, element);
17997
- } else if (value instanceof Counter) {
18437
+ } else if (isCounter$1(value)) {
17998
18438
  element = CRDTCounter.create(
17999
18439
  value.getValueType(),
18000
18440
  value.getValue(),
@@ -18056,6 +18496,16 @@
18056
18496
  this.registerGCPair(pair);
18057
18497
  }
18058
18498
  }
18499
+ if (elem instanceof CRDTArray) {
18500
+ for (const node of elem.getAllRGANodes()) {
18501
+ if (!node.getElementEntry() && node.getRemovedAt()) {
18502
+ this.registerGCPair({
18503
+ parent: elem.getRGATreeList(),
18504
+ child: node
18505
+ });
18506
+ }
18507
+ }
18508
+ }
18059
18509
  return false;
18060
18510
  });
18061
18511
  }
@@ -19147,6 +19597,11 @@
19147
19597
  if (logger.isEnabled(LogLevel.Trivial)) {
19148
19598
  logger.trivial(`trying to update a local change: ${this.toJSON()}`);
19149
19599
  }
19600
+ const prev = {
19601
+ hadPresence: this.presences.has(actorID),
19602
+ wasOnline: this.status === "attached",
19603
+ presence: this.presences.has(actorID) ? deepcopy(this.presences.get(actorID)) : void 0
19604
+ };
19150
19605
  const change = ctx.toChange();
19151
19606
  const { opInfos, reverseOps } = change.execute(
19152
19607
  this.root,
@@ -19192,14 +19647,14 @@
19192
19647
  });
19193
19648
  }
19194
19649
  if (change.hasPresenceChange()) {
19195
- event.push({
19196
- type: "presence-changed",
19197
- source: OpSource.Local,
19198
- value: {
19199
- clientID: actorID,
19200
- presence: this.getPresence(actorID)
19201
- }
19202
- });
19650
+ const presenceEvent = this.reconcilePresence(
19651
+ actorID,
19652
+ prev,
19653
+ OpSource.Local
19654
+ );
19655
+ if (presenceEvent) {
19656
+ event.push(presenceEvent);
19657
+ }
19203
19658
  }
19204
19659
  this.publish(event);
19205
19660
  if (logger.isEnabled(LogLevel.Trivial)) {
@@ -19683,41 +20138,11 @@
19683
20138
  change.execute(this.clone.root, this.clone.presences, source);
19684
20139
  const events = [];
19685
20140
  const actorID = change.getID().getActorID();
19686
- if (change.hasPresenceChange() && this.onlineClients.has(actorID)) {
19687
- const presenceChange = change.getPresenceChange();
19688
- switch (presenceChange.type) {
19689
- case PresenceChangeType.Put:
19690
- events.push(
19691
- this.presences.has(actorID) ? {
19692
- type: "presence-changed",
19693
- source,
19694
- value: {
19695
- clientID: actorID,
19696
- presence: presenceChange.presence
19697
- }
19698
- } : {
19699
- type: "watched",
19700
- source: OpSource.Remote,
19701
- value: {
19702
- clientID: actorID,
19703
- presence: presenceChange.presence
19704
- }
19705
- }
19706
- );
19707
- break;
19708
- case PresenceChangeType.Clear:
19709
- events.push({
19710
- type: "unwatched",
19711
- source: OpSource.Remote,
19712
- value: {
19713
- clientID: actorID,
19714
- presence: this.getPresence(actorID)
19715
- }
19716
- });
19717
- this.removeOnlineClient(actorID);
19718
- break;
19719
- }
19720
- }
20141
+ const prev = change.hasPresenceChange() ? {
20142
+ hadPresence: this.presences.has(actorID),
20143
+ wasOnline: this.onlineClients.has(actorID),
20144
+ presence: this.presences.has(actorID) ? deepcopy(this.presences.get(actorID)) : void 0
20145
+ } : void 0;
19721
20146
  const { opInfos, operations } = change.execute(
19722
20147
  this.root,
19723
20148
  this.presences,
@@ -19772,6 +20197,16 @@
19772
20197
  }
19773
20198
  );
19774
20199
  }
20200
+ if (prev && change.hasPresenceChange()) {
20201
+ const presenceChange = change.getPresenceChange();
20202
+ if (presenceChange.type === PresenceChangeType.Clear) {
20203
+ this.removeOnlineClient(actorID);
20204
+ }
20205
+ const presenceEvent = this.reconcilePresence(actorID, prev, source);
20206
+ if (presenceEvent) {
20207
+ events.push(presenceEvent);
20208
+ }
20209
+ }
19775
20210
  if (events.length) {
19776
20211
  this.publish(events);
19777
20212
  }
@@ -19800,46 +20235,43 @@
19800
20235
  * `applyDocEvent` applies the given doc event into this document.
19801
20236
  */
19802
20237
  applyDocEvent(type, publisher) {
19803
- const events = [];
20238
+ const prev = {
20239
+ hadPresence: this.presences.has(publisher),
20240
+ wasOnline: this.onlineClients.has(publisher),
20241
+ presence: this.presences.has(publisher) ? deepcopy(this.presences.get(publisher)) : void 0
20242
+ };
19804
20243
  if (type === DocEventType$1.DOCUMENT_WATCHED) {
19805
20244
  if (this.onlineClients.has(publisher) && this.hasPresence(publisher)) {
19806
20245
  return;
19807
20246
  }
19808
20247
  this.addOnlineClient(publisher);
19809
- if (this.hasPresence(publisher)) {
19810
- events.push({
19811
- type: "watched",
19812
- source: OpSource.Remote,
19813
- value: {
19814
- clientID: publisher,
19815
- presence: this.getPresence(publisher)
19816
- }
19817
- });
19818
- }
19819
20248
  } else if (type === DocEventType$1.DOCUMENT_UNWATCHED) {
19820
- const presence = this.getPresence(publisher);
19821
20249
  this.removeOnlineClient(publisher);
19822
20250
  this.presences.delete(publisher);
19823
- if (presence) {
19824
- events.push({
19825
- type: "unwatched",
19826
- source: OpSource.Remote,
19827
- value: { clientID: publisher, presence }
19828
- });
19829
- }
19830
20251
  }
19831
- if (events.length) {
19832
- this.publish(events);
20252
+ const event = this.reconcilePresence(publisher, prev, OpSource.Remote);
20253
+ if (event) {
20254
+ this.publish([event]);
19833
20255
  }
19834
20256
  }
19835
20257
  /**
19836
20258
  * `applyStatus` applies the document status into this document.
19837
20259
  */
19838
20260
  applyStatus(status) {
20261
+ const actorID = this.changeID.getActorID();
20262
+ const prev = {
20263
+ hadPresence: this.presences.has(actorID),
20264
+ wasOnline: this.status === "attached",
20265
+ presence: this.presences.has(actorID) ? deepcopy(this.presences.get(actorID)) : void 0
20266
+ };
19839
20267
  this.status = status;
19840
20268
  if (status === "detached") {
19841
20269
  this.setActor(InitialActorID);
19842
20270
  }
20271
+ const event = this.reconcilePresence(actorID, prev, OpSource.Local);
20272
+ if (event) {
20273
+ this.publish([event]);
20274
+ }
19843
20275
  this.publish([
19844
20276
  {
19845
20277
  source: status === "removed" ? OpSource.Remote : OpSource.Local,
@@ -19939,6 +20371,57 @@
19939
20371
  removeOnlineClient(clientID) {
19940
20372
  this.onlineClients.delete(clientID);
19941
20373
  }
20374
+ /**
20375
+ * `reconcilePresence` compares the previous and current state of a client's
20376
+ * presence/online status and returns the appropriate event to emit.
20377
+ *
20378
+ * For remote clients, "online" means the client is in onlineClients.
20379
+ * For self, "online" means the document status is Attached.
20380
+ *
20381
+ * State transition table:
20382
+ * (!hadP || !wasOn) → (hasP && isOn) : watched (remote) or presence-changed (self)
20383
+ * (hadP && wasOn) → (hasP && isOn) : presence-changed
20384
+ * (hadP && wasOn) → (!hasP || !isOn): unwatched (remote only)
20385
+ * otherwise : no event (waiting)
20386
+ */
20387
+ reconcilePresence(actorID, prev, source) {
20388
+ const isSelf = actorID === this.changeID.getActorID();
20389
+ const hasPresence = this.presences.has(actorID);
20390
+ const isOnline = isSelf ? this.status === "attached" : this.onlineClients.has(actorID);
20391
+ if (!hasPresence || !isOnline) {
20392
+ if (prev.hadPresence && prev.wasOnline && !isSelf) {
20393
+ return {
20394
+ type: "unwatched",
20395
+ source: OpSource.Remote,
20396
+ value: {
20397
+ clientID: actorID,
20398
+ presence: prev.presence
20399
+ }
20400
+ };
20401
+ }
20402
+ return void 0;
20403
+ }
20404
+ const presence = deepcopy(this.presences.get(actorID));
20405
+ if (!prev.hadPresence || !prev.wasOnline) {
20406
+ if (isSelf) {
20407
+ return {
20408
+ type: "presence-changed",
20409
+ source,
20410
+ value: { clientID: actorID, presence }
20411
+ };
20412
+ }
20413
+ return {
20414
+ type: "watched",
20415
+ source: OpSource.Remote,
20416
+ value: { clientID: actorID, presence }
20417
+ };
20418
+ }
20419
+ return {
20420
+ type: "presence-changed",
20421
+ source,
20422
+ value: { clientID: actorID, presence }
20423
+ };
20424
+ }
19942
20425
  /**
19943
20426
  * `hasPresence` returns whether the given clientID has a presence or not.
19944
20427
  */
@@ -20100,18 +20583,24 @@
20100
20583
  const ticket = ctx.issueTimeTicket();
20101
20584
  op.setExecutedAt(ticket);
20102
20585
  if (op instanceof ArraySetOperation) {
20103
- const prev = op.getCreatedAt();
20586
+ const prev2 = op.getCreatedAt();
20104
20587
  op.getValue().setCreatedAt(ticket);
20105
- this.internalHistory.reconcileCreatedAt(prev, ticket);
20588
+ this.internalHistory.reconcileCreatedAt(prev2, ticket);
20106
20589
  } else if (op instanceof AddOperation) {
20107
- const prev = op.getValue().getCreatedAt();
20590
+ const prev2 = op.getValue().getCreatedAt();
20108
20591
  op.getValue().setCreatedAt(ticket);
20109
- this.internalHistory.reconcileCreatedAt(prev, ticket);
20592
+ this.internalHistory.reconcileCreatedAt(prev2, ticket);
20110
20593
  }
20111
20594
  ctx.push(op);
20112
20595
  }
20113
20596
  const change = ctx.toChange();
20114
20597
  change.execute(this.clone.root, this.clone.presences, OpSource.UndoRedo);
20598
+ const actorID = this.changeID.getActorID();
20599
+ const prev = {
20600
+ hadPresence: this.presences.has(actorID),
20601
+ wasOnline: this.status === "attached",
20602
+ presence: this.presences.has(actorID) ? deepcopy(this.presences.get(actorID)) : void 0
20603
+ };
20115
20604
  const { opInfos, reverseOps } = change.execute(
20116
20605
  this.root,
20117
20606
  this.presences,
@@ -20133,7 +20622,6 @@
20133
20622
  }
20134
20623
  this.localChanges.push(change);
20135
20624
  this.changeID = ctx.getNextID();
20136
- const actorID = this.changeID.getActorID();
20137
20625
  const events = [];
20138
20626
  if (opInfos.length) {
20139
20627
  events.push({
@@ -20150,14 +20638,14 @@
20150
20638
  });
20151
20639
  }
20152
20640
  if (change.hasPresenceChange()) {
20153
- events.push({
20154
- type: "presence-changed",
20155
- source: OpSource.UndoRedo,
20156
- value: {
20157
- clientID: actorID,
20158
- presence: this.getPresence(actorID)
20159
- }
20160
- });
20641
+ const presenceEvent = this.reconcilePresence(
20642
+ actorID,
20643
+ prev,
20644
+ OpSource.UndoRedo
20645
+ );
20646
+ if (presenceEvent) {
20647
+ events.push(presenceEvent);
20648
+ }
20161
20649
  }
20162
20650
  this.publish(events);
20163
20651
  }
@@ -20173,6 +20661,8 @@
20173
20661
  watchStream;
20174
20662
  watchLoopTimerID;
20175
20663
  watchAbortController;
20664
+ syncPromise;
20665
+ _detaching = false;
20176
20666
  constructor(reconnectStreamDelay, resource, resourceID, syncMode) {
20177
20667
  this.reconnectStreamDelay = reconnectStreamDelay;
20178
20668
  this.resource = resource;
@@ -20248,6 +20738,49 @@
20248
20738
  };
20249
20739
  await doLoop();
20250
20740
  }
20741
+ /**
20742
+ * `markDetaching` marks this attachment as being in the process of detaching.
20743
+ * Once marked, the sync loop will skip this attachment.
20744
+ */
20745
+ markDetaching() {
20746
+ this._detaching = true;
20747
+ }
20748
+ /**
20749
+ * `isDetaching` returns whether this attachment is being detached.
20750
+ */
20751
+ isDetaching() {
20752
+ return this._detaching;
20753
+ }
20754
+ /**
20755
+ * `resetDetaching` resets the detaching flag so the attachment can resume
20756
+ * syncing. Used when a detach RPC fails and the document remains attached.
20757
+ */
20758
+ resetDetaching() {
20759
+ this._detaching = false;
20760
+ }
20761
+ /**
20762
+ * `setSyncPromise` sets the in-progress sync promise for this attachment.
20763
+ */
20764
+ setSyncPromise(promise) {
20765
+ this.syncPromise = promise;
20766
+ }
20767
+ /**
20768
+ * `clearSyncPromise` clears the in-progress sync promise.
20769
+ */
20770
+ clearSyncPromise() {
20771
+ this.syncPromise = void 0;
20772
+ }
20773
+ /**
20774
+ * `waitForSyncComplete` waits for any in-progress sync to complete.
20775
+ */
20776
+ async waitForSyncComplete() {
20777
+ if (this.syncPromise) {
20778
+ try {
20779
+ await this.syncPromise;
20780
+ } catch {
20781
+ }
20782
+ }
20783
+ }
20251
20784
  /**
20252
20785
  * `cancelWatchStream` cancels the watch stream.
20253
20786
  */
@@ -20282,7 +20815,7 @@
20282
20815
  };
20283
20816
  }
20284
20817
  const name = "@yorkie-js/sdk";
20285
- const version = "0.7.4";
20818
+ const version = "0.7.6";
20286
20819
  const pkg = {
20287
20820
  name,
20288
20821
  version
@@ -20607,6 +21140,7 @@
20607
21140
  taskQueue;
20608
21141
  processing = false;
20609
21142
  keepalive = false;
21143
+ deactivating = false;
20610
21144
  /**
20611
21145
  * @param rpcAddr - the address of the RPC server.
20612
21146
  * @param opts - the options of the client.
@@ -20636,21 +21170,19 @@
20636
21170
  this.channelHeartbeatInterval = opts.channelHeartbeatInterval ?? DefaultClientOptions.channelHeartbeatInterval;
20637
21171
  const { authInterceptor, setToken } = createAuthInterceptor(this.apiKey);
20638
21172
  this.setAuthToken = setToken;
21173
+ const transportOptions = {
21174
+ baseUrl: rpcAddr,
21175
+ interceptors: [authInterceptor, createMetricInterceptor(opts?.userAgent)],
21176
+ fetch: (input, init) => {
21177
+ return fetch(input, {
21178
+ ...init,
21179
+ keepalive: this.keepalive
21180
+ });
21181
+ }
21182
+ };
20639
21183
  this.rpcClient = createClient(
20640
21184
  YorkieService,
20641
- createGrpcWebTransport({
20642
- baseUrl: rpcAddr,
20643
- interceptors: [
20644
- authInterceptor,
20645
- createMetricInterceptor(opts?.userAgent)
20646
- ],
20647
- fetch: (input, init) => {
20648
- return fetch(input, {
20649
- ...init,
20650
- keepalive: this.keepalive
20651
- });
20652
- }
20653
- })
21185
+ opts.useGrpcWebTransport ? createGrpcWebTransport(transportOptions) : createConnectTransport(transportOptions)
20654
21186
  );
20655
21187
  this.taskQueue = [];
20656
21188
  }
@@ -20678,6 +21210,7 @@
20678
21210
  );
20679
21211
  this.id = res.clientId;
20680
21212
  this.status = "activated";
21213
+ this.deactivating = false;
20681
21214
  this.runSyncLoop();
20682
21215
  logger.info(`[AC] c:"${this.getKey()}" activated, id:"${this.id}"`);
20683
21216
  if (typeof window !== "undefined") {
@@ -20706,6 +21239,7 @@
20706
21239
  if (this.status === "deactivated") {
20707
21240
  return Promise.resolve();
20708
21241
  }
21242
+ this.deactivating = true;
20709
21243
  const task = async () => {
20710
21244
  try {
20711
21245
  await this.rpcClient.deactivateClient(
@@ -20719,6 +21253,7 @@
20719
21253
  logger.info(`[DC] c"${this.getKey()}" deactivated`);
20720
21254
  } catch (err) {
20721
21255
  logger.error(`[DC] c:"${this.getKey()}" err :`, err);
21256
+ this.deactivating = false;
20722
21257
  await this.handleConnectError(err);
20723
21258
  throw err;
20724
21259
  }
@@ -20859,8 +21394,10 @@
20859
21394
  );
20860
21395
  }
20861
21396
  doc.update((_, p) => p.clear());
21397
+ attachment.markDetaching();
20862
21398
  const task = async () => {
20863
21399
  try {
21400
+ await attachment.waitForSyncComplete();
20864
21401
  const res = await this.rpcClient.detachDocument(
20865
21402
  {
20866
21403
  clientId: this.id,
@@ -20879,6 +21416,7 @@
20879
21416
  return doc;
20880
21417
  } catch (err) {
20881
21418
  logger.error(`[DD] c:"${this.getKey()}" err :`, err);
21419
+ attachment.resetDetaching();
20882
21420
  await this.handleConnectError(err);
20883
21421
  throw err;
20884
21422
  }
@@ -21445,7 +21983,7 @@
21445
21983
  */
21446
21984
  runSyncLoop() {
21447
21985
  const doLoop = async () => {
21448
- if (!this.isActive()) {
21986
+ if (!this.isActive() || this.deactivating) {
21449
21987
  logger.debug(`[SL] c:"${this.getKey()}" exit sync loop`);
21450
21988
  this.conditions[
21451
21989
  "SyncLoop"
@@ -21457,43 +21995,62 @@
21457
21995
  await this.enqueueTask(async () => {
21458
21996
  const syncs = [];
21459
21997
  for (const [, attachment] of this.attachmentMap) {
21998
+ if (this.deactivating) {
21999
+ break;
22000
+ }
21460
22001
  if (!attachment.needSync(this.channelHeartbeatInterval)) {
21461
22002
  continue;
21462
22003
  }
22004
+ if (attachment.isDetaching()) {
22005
+ continue;
22006
+ }
21463
22007
  if (attachment.changeEventReceived !== void 0) {
21464
22008
  attachment.changeEventReceived = false;
21465
22009
  }
21466
- syncs.push(
21467
- this.syncInternal(attachment, attachment.syncMode).catch((e) => {
21468
- if (isErrorCode(e, Code.ErrUnauthenticated)) {
21469
- attachment.resource.publish([
21470
- {
21471
- type: DocEventType.AuthError,
21472
- value: {
21473
- reason: errorMetadataOf(e).reason,
21474
- method: "PushPull"
21475
- }
22010
+ const syncPromise = this.syncInternal(
22011
+ attachment,
22012
+ attachment.syncMode
22013
+ ).then(() => {
22014
+ }).catch((e) => {
22015
+ if (isErrorCode(e, Code.ErrUnauthenticated)) {
22016
+ attachment.resource.publish([
22017
+ {
22018
+ type: DocEventType.AuthError,
22019
+ value: {
22020
+ reason: errorMetadataOf(e).reason,
22021
+ method: "PushPull"
21476
22022
  }
21477
- ]);
21478
- }
21479
- if (isErrorCode(e, Code.ErrEpochMismatch)) {
21480
- attachment.resource.publish([
21481
- {
21482
- type: DocEventType.EpochMismatch,
21483
- value: {
21484
- method: "PushPull"
21485
- }
22023
+ }
22024
+ ]);
22025
+ }
22026
+ if (isErrorCode(e, Code.ErrEpochMismatch)) {
22027
+ attachment.resource.publish([
22028
+ {
22029
+ type: DocEventType.EpochMismatch,
22030
+ value: {
22031
+ method: "PushPull"
21486
22032
  }
21487
- ]);
21488
- }
21489
- throw e;
21490
- })
21491
- );
22033
+ }
22034
+ ]);
22035
+ }
22036
+ throw e;
22037
+ }).finally(() => {
22038
+ attachment.clearSyncPromise();
22039
+ });
22040
+ attachment.setSyncPromise(syncPromise);
22041
+ syncs.push(syncPromise);
21492
22042
  }
21493
22043
  await Promise.all(syncs);
21494
22044
  setTimeout(doLoop, this.syncLoopDuration);
21495
22045
  });
21496
22046
  } catch (err) {
22047
+ if (this.deactivating) {
22048
+ this.conditions[
22049
+ "SyncLoop"
22050
+ /* SyncLoop */
22051
+ ] = false;
22052
+ return;
22053
+ }
21497
22054
  logger.error(`[SL] c:"${this.getKey()}" sync failed:`, err);
21498
22055
  if (await this.handleConnectError(err)) {
21499
22056
  setTimeout(doLoop, this.retrySyncLoopDelay);
@@ -22154,15 +22711,14 @@
22154
22711
  Primitive,
22155
22712
  Text,
22156
22713
  Counter,
22714
+ DedupCounter,
22157
22715
  Tree,
22158
22716
  Devtools,
22159
22717
  Channel,
22160
22718
  ChannelEventType,
22161
22719
  YSON,
22162
22720
  LogLevel,
22163
- setLogLevel,
22164
- IntType: CounterType.Int,
22165
- LongType: CounterType.Long
22721
+ setLogLevel
22166
22722
  };
22167
22723
  if (typeof globalThis !== "undefined") {
22168
22724
  globalThis.yorkie = {
@@ -22171,14 +22727,13 @@
22171
22727
  Primitive,
22172
22728
  Text,
22173
22729
  Counter,
22730
+ DedupCounter,
22174
22731
  Tree,
22175
22732
  Channel,
22176
22733
  ChannelEventType,
22177
22734
  YSON,
22178
22735
  LogLevel,
22179
- setLogLevel,
22180
- IntType: CounterType.Int,
22181
- LongType: CounterType.Long
22736
+ setLogLevel
22182
22737
  };
22183
22738
  }
22184
22739
  exports2.Change = Change;
@@ -22190,6 +22745,7 @@
22190
22745
  exports2.ClientStatus = ClientStatus;
22191
22746
  exports2.Counter = Counter;
22192
22747
  exports2.CounterType = CounterType;
22748
+ exports2.DedupCounter = DedupCounter;
22193
22749
  exports2.Devtools = Devtools;
22194
22750
  exports2.DocEventType = DocEventType;
22195
22751
  exports2.DocStatus = DocStatus;