@yorkie-js/sdk 0.6.26 → 0.6.27

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.
@@ -115,16 +115,13 @@ declare interface AuthErrorEvent_2 extends BaseDocEvent_2 {
115
115
  };
116
116
  }
117
117
 
118
- /**
119
- * `BaseArray` is a base type of JSONArray.
120
- */
121
118
  declare type BaseArray<T> = JSONArray<T> | Array<T>;
122
119
 
123
120
  /* Excluded from this release type: BaseDocEvent */
124
121
 
125
122
  /* Excluded from this release type: BaseDocEvent_2 */
126
123
 
127
- declare type BaseObject<T> = JSONObject<T> | Record<string, T>;
124
+ declare type BaseObject<T> = JSONObject<T> | T;
128
125
 
129
126
  declare interface BroadcastEvent extends BaseDocEvent {
130
127
  type: DocEventType_2.Broadcast;
@@ -2902,6 +2899,17 @@ declare class History_2<P extends Indexable> {
2902
2899
  * `getRedoStackForTest` returns the redo stack for test.
2903
2900
  */
2904
2901
  getRedoStackForTest(): Array<Array<HistoryOperation<P>>>;
2902
+ /**
2903
+ * `reconcileCreatedAt` updates the createdAt and prevCreatedAt fields.
2904
+ *
2905
+ * When an element is replaced(e.g., UndoRemove as Add, or Set),
2906
+ * it receives a new createdAt(executedAt). However, existing history
2907
+ * operations may still reference the old createdAt or prevCreatedAt.
2908
+ *
2909
+ * This method scans both undo/redo stacks and replaces any matching
2910
+ * createdAt/prevCreatedAt with the new one, ensuring consistency.
2911
+ */
2912
+ reconcileCreatedAt(prevCreatedAt: TimeTicket, currCreatedAt: TimeTicket): void;
2905
2913
  }
2906
2914
 
2907
2915
  /**
@@ -3202,68 +3210,68 @@ export declare type JSONArray<T> = {
3202
3210
  /**
3203
3211
  * `getID` returns the ID, `TimeTicket` of this Object.
3204
3212
  */
3205
- getID?(): TimeTicket;
3213
+ getID(): TimeTicket;
3206
3214
  /**
3207
3215
  * `getElementByID` returns the element for the given ID.
3208
3216
  */
3209
- getElementByID?(createdAt: TimeTicket): WrappedElement<T>;
3217
+ getElementByID(createdAt: TimeTicket): WrappedElement<T>;
3210
3218
  /**
3211
3219
  * `getElementByIndex` returns the element for the given index.
3212
3220
  */
3213
- getElementByIndex?(index: number): WrappedElement<T>;
3221
+ getElementByIndex(index: number): WrappedElement<T>;
3214
3222
  /**
3215
3223
  * `getLast` returns the last element of this array.
3216
3224
  */
3217
- getLast?(): WrappedElement<T>;
3225
+ getLast(): WrappedElement<T>;
3218
3226
  /**
3219
3227
  * `setValue` sets the given value at the given index.
3220
3228
  */
3221
- setValue?(index: number, value: unknown): WrappedElement<T>;
3229
+ setValue(index: number, value: unknown): WrappedElement<T>;
3222
3230
  /**
3223
3231
  * `delete` deletes the element of the given index.
3224
3232
  */
3225
- delete?(index: number): WrappedElement<T>;
3233
+ delete(index: number): WrappedElement<T>;
3226
3234
  /**
3227
3235
  * `deleteByID` deletes the element of the given ID.
3228
3236
  */
3229
- deleteByID?(createdAt: TimeTicket): WrappedElement<T>;
3237
+ deleteByID(createdAt: TimeTicket): WrappedElement<T>;
3230
3238
  /**
3231
3239
  * `insertBefore` inserts a value before the given next element.
3232
3240
  */
3233
- insertBefore?(nextID: TimeTicket, value: any): WrappedElement<T>;
3241
+ insertBefore(nextID: TimeTicket, value: any): WrappedElement<T>;
3234
3242
  /**
3235
3243
  * `insertAfter` inserts a value after the given previous element.
3236
3244
  */
3237
- insertAfter?(prevID: TimeTicket, value: any): WrappedElement<T>;
3245
+ insertAfter(prevID: TimeTicket, value: any): WrappedElement<T>;
3238
3246
  /**
3239
3247
  * `insertIntegerAfter` inserts a value after the given index.
3240
3248
  */
3241
- insertIntegerAfter?(index: number, value: number): WrappedElement<T>;
3249
+ insertIntegerAfter(index: number, value: number): WrappedElement<T>;
3242
3250
  /**
3243
3251
  * `moveBefore` moves the element before the given next element.
3244
3252
  */
3245
- moveBefore?(nextID: TimeTicket, id: TimeTicket): void;
3253
+ moveBefore(nextID: TimeTicket, id: TimeTicket): void;
3246
3254
  /**
3247
3255
  * `moveAfter` moves the element after the given previous element.
3248
3256
  */
3249
- moveAfter?(prevID: TimeTicket, id: TimeTicket): void;
3257
+ moveAfter(prevID: TimeTicket, id: TimeTicket): void;
3250
3258
  /**
3251
3259
  * `moveAfterByIndex` moves the element after the given index.
3252
3260
  */
3253
- moveAfterByIndex?(prevIndex: number, targetIndex: number): void;
3261
+ moveAfterByIndex(prevIndex: number, targetIndex: number): void;
3254
3262
  /**
3255
3263
  * `moveFront` moves the element before the first element.
3256
3264
  */
3257
- moveFront?(id: TimeTicket): void;
3265
+ moveFront(id: TimeTicket): void;
3258
3266
  /**
3259
3267
  * `moveLast` moves the element after the last element.
3260
3268
  */
3261
- moveLast?(id: TimeTicket): void;
3269
+ moveLast(id: TimeTicket): void;
3262
3270
  /**
3263
3271
  * `toTestString` returns a String containing the meta data of the node
3264
3272
  * for debugging purpose.
3265
3273
  */
3266
- toTestString?(): string;
3274
+ toTestString(): string;
3267
3275
  /* Excluded from this release type: toJSForTest */
3268
3276
  } & Array<T>;
3269
3277
 
@@ -3349,15 +3357,15 @@ export declare type JSONObject<T> = {
3349
3357
  /**
3350
3358
  * `getID` returns the ID(time ticket) of this Object.
3351
3359
  */
3352
- getID?(): TimeTicket;
3360
+ getID(): TimeTicket;
3353
3361
  /**
3354
3362
  * `toJSON` returns the JSON encoding of this object.
3355
3363
  */
3356
- toJSON?(): string;
3364
+ toJSON(): string;
3357
3365
  /**
3358
3366
  * `toJS` returns the JSON object of this object.
3359
3367
  */
3360
- toJS?(): T;
3368
+ toJS(): T;
3361
3369
  /* Excluded from this release type: toJSForTest */
3362
3370
  } & T;
3363
3371
 
@@ -3371,9 +3379,6 @@ declare type JsonPrimitive = string | number | boolean | null;
3371
3379
 
3372
3380
  declare type JsonPrimitive_2 = string | number | boolean | null;
3373
3381
 
3374
- /**
3375
- * `LeafElement` is a leaf element of JSONElement.
3376
- */
3377
3382
  declare type LeafElement = PrimitiveValue | Primitive | Text_2 | Counter | Tree;
3378
3383
 
3379
3384
  /**
@@ -8232,6 +8232,12 @@ class CRDTElement {
8232
8232
  }
8233
8233
  return this.movedAt;
8234
8234
  }
8235
+ /**
8236
+ * `setCreatedAt` sets the creation time of this element manually.
8237
+ */
8238
+ setCreatedAt(createdAt) {
8239
+ this.createdAt = createdAt;
8240
+ }
8235
8241
  /**
8236
8242
  * `setMovedAt` sets the move time of this element.
8237
8243
  */
@@ -10930,6 +10936,12 @@ class AddOperation extends Operation {
10930
10936
  getValue() {
10931
10937
  return this.value;
10932
10938
  }
10939
+ /**
10940
+ * `setPrevCreatedAt` sets the creation time of the previous element.
10941
+ */
10942
+ setPrevCreatedAt(createdAt) {
10943
+ this.prevCreatedAt = createdAt;
10944
+ }
10933
10945
  }
10934
10946
  class RemoveOperation extends Operation {
10935
10947
  constructor(parentCreatedAt, createdAt, executedAt) {
@@ -11040,6 +11052,12 @@ class RemoveOperation extends Operation {
11040
11052
  getCreatedAt() {
11041
11053
  return this.createdAt;
11042
11054
  }
11055
+ /**
11056
+ * `setCreatedAt` sets the creation time of the target element.
11057
+ */
11058
+ setCreatedAt(createdAt) {
11059
+ this.createdAt = createdAt;
11060
+ }
11043
11061
  }
11044
11062
  class SetOperation extends Operation {
11045
11063
  constructor(key, value, parentCreatedAt, executedAt) {
@@ -11231,6 +11249,18 @@ class MoveOperation extends Operation {
11231
11249
  getCreatedAt() {
11232
11250
  return this.createdAt;
11233
11251
  }
11252
+ /**
11253
+ * `setPrevCreatedAt` sets the creation time of the previous element.
11254
+ */
11255
+ setPrevCreatedAt(createdAt) {
11256
+ this.prevCreatedAt = createdAt;
11257
+ }
11258
+ /**
11259
+ * `setCreatedAt` sets the creation time of the target element.
11260
+ */
11261
+ setCreatedAt(createdAt) {
11262
+ this.createdAt = createdAt;
11263
+ }
11234
11264
  }
11235
11265
  class RHTNode {
11236
11266
  constructor(key, value, updatedAt, isRemoved) {
@@ -16195,11 +16225,12 @@ class ArraySetOperation extends Operation {
16195
16225
  `fail to execute, only array can execute set`
16196
16226
  );
16197
16227
  }
16228
+ const previousValue = parentObject.getByID(this.createdAt).deepcopy();
16229
+ const reverseOp = this.toReverseOperation(this.value, previousValue);
16198
16230
  const value = this.value.deepcopy();
16199
16231
  parentObject.insertAfter(this.createdAt, value, this.getExecutedAt());
16200
16232
  parentObject.delete(this.createdAt, this.getExecutedAt());
16201
16233
  root.registerElement(value);
16202
- const reverseOp = void 0;
16203
16234
  return {
16204
16235
  opInfos: [
16205
16236
  {
@@ -16210,6 +16241,17 @@ class ArraySetOperation extends Operation {
16210
16241
  reverseOp
16211
16242
  };
16212
16243
  }
16244
+ /**
16245
+ * `toReverseOperation` returns the reverse operation of this operation.
16246
+ */
16247
+ toReverseOperation(newValue, prevValue) {
16248
+ const reverseOp = ArraySetOperation.create(
16249
+ this.getParentCreatedAt(),
16250
+ newValue.getCreatedAt(),
16251
+ prevValue
16252
+ );
16253
+ return reverseOp;
16254
+ }
16213
16255
  /**
16214
16256
  * `getEffectedCreatedAt` returns the creation time of the effected element.
16215
16257
  */
@@ -16234,6 +16276,12 @@ class ArraySetOperation extends Operation {
16234
16276
  getValue() {
16235
16277
  return this.value;
16236
16278
  }
16279
+ /**
16280
+ * `setCreatedAt` sets the creation time of the target element.
16281
+ */
16282
+ setCreatedAt(createdAt) {
16283
+ this.createdAt = createdAt;
16284
+ }
16237
16285
  }
16238
16286
  function toPresence(presence) {
16239
16287
  const pbPresence = new Presence$1();
@@ -17483,7 +17531,7 @@ function uuid() {
17483
17531
  });
17484
17532
  }
17485
17533
  class Attachment {
17486
- constructor(reconnectStreamDelay, doc, docID, syncMode, unsubscribeBroacastEvent) {
17534
+ constructor(reconnectStreamDelay, doc, docID, syncMode, unsubscribeBroadcastEvent) {
17487
17535
  // TODO(hackerwins): Consider to changing the modifiers of the following properties to private.
17488
17536
  __publicField(this, "reconnectStreamDelay");
17489
17537
  __publicField(this, "doc");
@@ -17501,7 +17549,7 @@ class Attachment {
17501
17549
  this.syncMode = syncMode;
17502
17550
  this.remoteChangeEventReceived = false;
17503
17551
  this.cancelled = false;
17504
- this.unsubscribeBroadcastEvent = unsubscribeBroacastEvent;
17552
+ this.unsubscribeBroadcastEvent = unsubscribeBroadcastEvent;
17505
17553
  }
17506
17554
  /**
17507
17555
  * `changeSyncMode` changes the sync mode of the document.
@@ -20157,6 +20205,32 @@ class History {
20157
20205
  getRedoStackForTest() {
20158
20206
  return this.redoStack;
20159
20207
  }
20208
+ /**
20209
+ * `reconcileCreatedAt` updates the createdAt and prevCreatedAt fields.
20210
+ *
20211
+ * When an element is replaced(e.g., UndoRemove as Add, or Set),
20212
+ * it receives a new createdAt(executedAt). However, existing history
20213
+ * operations may still reference the old createdAt or prevCreatedAt.
20214
+ *
20215
+ * This method scans both undo/redo stacks and replaces any matching
20216
+ * createdAt/prevCreatedAt with the new one, ensuring consistency.
20217
+ */
20218
+ reconcileCreatedAt(prevCreatedAt, currCreatedAt) {
20219
+ const replace = (stack) => {
20220
+ for (const ops of stack) {
20221
+ for (const op of ops) {
20222
+ if ((op instanceof ArraySetOperation || op instanceof RemoveOperation || op instanceof MoveOperation) && op.getCreatedAt() === prevCreatedAt) {
20223
+ op.setCreatedAt(currCreatedAt);
20224
+ }
20225
+ if ((op instanceof AddOperation || op instanceof MoveOperation) && op.getPrevCreatedAt() === prevCreatedAt) {
20226
+ op.setPrevCreatedAt(currCreatedAt);
20227
+ }
20228
+ }
20229
+ }
20230
+ };
20231
+ replace(this.undoStack);
20232
+ replace(this.redoStack);
20233
+ }
20160
20234
  }
20161
20235
  const EventSourceDevPanel = "yorkie-devtools-panel";
20162
20236
  const EventSourceSDK = "yorkie-devtools-sdk";
@@ -20419,6 +20493,14 @@ class Document {
20419
20493
  this.presences,
20420
20494
  OpSource.Local
20421
20495
  );
20496
+ for (const op of change.getOperations()) {
20497
+ if (op instanceof ArraySetOperation) {
20498
+ this.internalHistory.reconcileCreatedAt(
20499
+ op.getCreatedAt(),
20500
+ op.getValue().getCreatedAt()
20501
+ );
20502
+ }
20503
+ }
20422
20504
  const reversePresence = context.getReversePresence();
20423
20505
  if (reversePresence) {
20424
20506
  reverseOps.push({
@@ -21375,6 +21457,15 @@ class Document {
21375
21457
  }
21376
21458
  const ticket = context.issueTimeTicket();
21377
21459
  undoOp.setExecutedAt(ticket);
21460
+ if (undoOp instanceof ArraySetOperation) {
21461
+ const prev = undoOp.getCreatedAt();
21462
+ undoOp.getValue().setCreatedAt(ticket);
21463
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21464
+ } else if (undoOp instanceof AddOperation) {
21465
+ const prev = undoOp.getValue().getCreatedAt();
21466
+ undoOp.getValue().setCreatedAt(ticket);
21467
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21468
+ }
21378
21469
  context.push(undoOp);
21379
21470
  }
21380
21471
  const change = context.toChange();
@@ -21462,6 +21553,15 @@ class Document {
21462
21553
  }
21463
21554
  const ticket = context.issueTimeTicket();
21464
21555
  redoOp.setExecutedAt(ticket);
21556
+ if (redoOp instanceof ArraySetOperation) {
21557
+ const prev = redoOp.getCreatedAt();
21558
+ redoOp.getValue().setCreatedAt(ticket);
21559
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21560
+ } else if (redoOp instanceof AddOperation) {
21561
+ const prev = redoOp.getValue().getCreatedAt();
21562
+ redoOp.getValue().setCreatedAt(ticket);
21563
+ this.internalHistory.reconcileCreatedAt(prev, ticket);
21564
+ }
21465
21565
  context.push(redoOp);
21466
21566
  }
21467
21567
  const change = context.toChange();
@@ -21564,7 +21664,7 @@ function createAuthInterceptor(apiKey, token) {
21564
21664
  };
21565
21665
  }
21566
21666
  const name = "@yorkie-js/sdk";
21567
- const version = "0.6.26";
21667
+ const version = "0.6.27";
21568
21668
  const pkg = {
21569
21669
  name,
21570
21670
  version