@yorkie-js/sdk 0.6.11-rc → 0.6.13
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.
- package/dist/yorkie-js-sdk.d.ts +70 -21
- package/dist/yorkie-js-sdk.es.js +512 -178
- package/dist/yorkie-js-sdk.es.js.map +1 -1
- package/dist/yorkie-js-sdk.js +512 -178
- package/dist/yorkie-js-sdk.js.map +1 -1
- package/package.json +1 -1
package/dist/yorkie-js-sdk.js
CHANGED
|
@@ -6061,15 +6061,39 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6061
6061
|
*/
|
|
6062
6062
|
__publicField(this, "authWebhookMethods", []);
|
|
6063
6063
|
/**
|
|
6064
|
-
* @generated from field: string
|
|
6064
|
+
* @generated from field: string event_webhook_url = 7;
|
|
6065
|
+
*/
|
|
6066
|
+
__publicField(this, "eventWebhookUrl", "");
|
|
6067
|
+
/**
|
|
6068
|
+
* @generated from field: repeated string event_webhook_events = 8;
|
|
6069
|
+
*/
|
|
6070
|
+
__publicField(this, "eventWebhookEvents", []);
|
|
6071
|
+
/**
|
|
6072
|
+
* @generated from field: string client_deactivate_threshold = 9;
|
|
6065
6073
|
*/
|
|
6066
6074
|
__publicField(this, "clientDeactivateThreshold", "");
|
|
6067
6075
|
/**
|
|
6068
|
-
* @generated from field:
|
|
6076
|
+
* @generated from field: int32 max_subscribers_per_document = 10;
|
|
6077
|
+
*/
|
|
6078
|
+
__publicField(this, "maxSubscribersPerDocument", 0);
|
|
6079
|
+
/**
|
|
6080
|
+
* @generated from field: int32 max_attachments_per_document = 11;
|
|
6081
|
+
*/
|
|
6082
|
+
__publicField(this, "maxAttachmentsPerDocument", 0);
|
|
6083
|
+
/**
|
|
6084
|
+
* @generated from field: int32 max_size_per_document = 15;
|
|
6085
|
+
*/
|
|
6086
|
+
__publicField(this, "maxSizePerDocument", 0);
|
|
6087
|
+
/**
|
|
6088
|
+
* @generated from field: repeated string allowed_origins = 14;
|
|
6089
|
+
*/
|
|
6090
|
+
__publicField(this, "allowedOrigins", []);
|
|
6091
|
+
/**
|
|
6092
|
+
* @generated from field: google.protobuf.Timestamp created_at = 12;
|
|
6069
6093
|
*/
|
|
6070
6094
|
__publicField(this, "createdAt");
|
|
6071
6095
|
/**
|
|
6072
|
-
* @generated from field: google.protobuf.Timestamp updated_at =
|
|
6096
|
+
* @generated from field: google.protobuf.Timestamp updated_at = 13;
|
|
6073
6097
|
*/
|
|
6074
6098
|
__publicField(this, "updatedAt");
|
|
6075
6099
|
proto3.util.initPartial(data, this);
|
|
@@ -6128,13 +6152,43 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6128
6152
|
{ no: 6, name: "auth_webhook_methods", kind: "scalar", T: 9, repeated: true },
|
|
6129
6153
|
{
|
|
6130
6154
|
no: 7,
|
|
6155
|
+
name: "event_webhook_url",
|
|
6156
|
+
kind: "scalar",
|
|
6157
|
+
T: 9
|
|
6158
|
+
/* ScalarType.STRING */
|
|
6159
|
+
},
|
|
6160
|
+
{ no: 8, name: "event_webhook_events", kind: "scalar", T: 9, repeated: true },
|
|
6161
|
+
{
|
|
6162
|
+
no: 9,
|
|
6131
6163
|
name: "client_deactivate_threshold",
|
|
6132
6164
|
kind: "scalar",
|
|
6133
6165
|
T: 9
|
|
6134
6166
|
/* ScalarType.STRING */
|
|
6135
6167
|
},
|
|
6136
|
-
{
|
|
6137
|
-
|
|
6168
|
+
{
|
|
6169
|
+
no: 10,
|
|
6170
|
+
name: "max_subscribers_per_document",
|
|
6171
|
+
kind: "scalar",
|
|
6172
|
+
T: 5
|
|
6173
|
+
/* ScalarType.INT32 */
|
|
6174
|
+
},
|
|
6175
|
+
{
|
|
6176
|
+
no: 11,
|
|
6177
|
+
name: "max_attachments_per_document",
|
|
6178
|
+
kind: "scalar",
|
|
6179
|
+
T: 5
|
|
6180
|
+
/* ScalarType.INT32 */
|
|
6181
|
+
},
|
|
6182
|
+
{
|
|
6183
|
+
no: 15,
|
|
6184
|
+
name: "max_size_per_document",
|
|
6185
|
+
kind: "scalar",
|
|
6186
|
+
T: 5
|
|
6187
|
+
/* ScalarType.INT32 */
|
|
6188
|
+
},
|
|
6189
|
+
{ no: 14, name: "allowed_origins", kind: "scalar", T: 9, repeated: true },
|
|
6190
|
+
{ no: 12, name: "created_at", kind: "message", T: Timestamp },
|
|
6191
|
+
{ no: 13, name: "updated_at", kind: "message", T: Timestamp }
|
|
6138
6192
|
]));
|
|
6139
6193
|
let Project = _Project;
|
|
6140
6194
|
const _UpdatableProjectFields = class _UpdatableProjectFields extends Message {
|
|
@@ -6153,9 +6207,33 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6153
6207
|
*/
|
|
6154
6208
|
__publicField(this, "authWebhookMethods");
|
|
6155
6209
|
/**
|
|
6156
|
-
* @generated from field: google.protobuf.StringValue
|
|
6210
|
+
* @generated from field: google.protobuf.StringValue event_webhook_url = 4;
|
|
6211
|
+
*/
|
|
6212
|
+
__publicField(this, "eventWebhookUrl");
|
|
6213
|
+
/**
|
|
6214
|
+
* @generated from field: yorkie.v1.UpdatableProjectFields.EventWebhookEvents event_webhook_events = 5;
|
|
6215
|
+
*/
|
|
6216
|
+
__publicField(this, "eventWebhookEvents");
|
|
6217
|
+
/**
|
|
6218
|
+
* @generated from field: google.protobuf.StringValue client_deactivate_threshold = 6;
|
|
6157
6219
|
*/
|
|
6158
6220
|
__publicField(this, "clientDeactivateThreshold");
|
|
6221
|
+
/**
|
|
6222
|
+
* @generated from field: google.protobuf.Int32Value max_subscribers_per_document = 7;
|
|
6223
|
+
*/
|
|
6224
|
+
__publicField(this, "maxSubscribersPerDocument");
|
|
6225
|
+
/**
|
|
6226
|
+
* @generated from field: google.protobuf.Int32Value max_attachments_per_document = 8;
|
|
6227
|
+
*/
|
|
6228
|
+
__publicField(this, "maxAttachmentsPerDocument");
|
|
6229
|
+
/**
|
|
6230
|
+
* @generated from field: google.protobuf.Int32Value max_size_per_document = 10;
|
|
6231
|
+
*/
|
|
6232
|
+
__publicField(this, "maxSizePerDocument");
|
|
6233
|
+
/**
|
|
6234
|
+
* @generated from field: yorkie.v1.UpdatableProjectFields.AllowedOrigins allowed_origins = 9;
|
|
6235
|
+
*/
|
|
6236
|
+
__publicField(this, "allowedOrigins");
|
|
6159
6237
|
proto3.util.initPartial(data, this);
|
|
6160
6238
|
}
|
|
6161
6239
|
static fromBinary(bytes, options) {
|
|
@@ -6177,7 +6255,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6177
6255
|
{ no: 1, name: "name", kind: "message", T: StringValue },
|
|
6178
6256
|
{ no: 2, name: "auth_webhook_url", kind: "message", T: StringValue },
|
|
6179
6257
|
{ no: 3, name: "auth_webhook_methods", kind: "message", T: UpdatableProjectFields_AuthWebhookMethods },
|
|
6180
|
-
{ no: 4, name: "
|
|
6258
|
+
{ no: 4, name: "event_webhook_url", kind: "message", T: StringValue },
|
|
6259
|
+
{ no: 5, name: "event_webhook_events", kind: "message", T: UpdatableProjectFields_EventWebhookEvents },
|
|
6260
|
+
{ no: 6, name: "client_deactivate_threshold", kind: "message", T: StringValue },
|
|
6261
|
+
{ no: 7, name: "max_subscribers_per_document", kind: "message", T: Int32Value },
|
|
6262
|
+
{ no: 8, name: "max_attachments_per_document", kind: "message", T: Int32Value },
|
|
6263
|
+
{ no: 10, name: "max_size_per_document", kind: "message", T: Int32Value },
|
|
6264
|
+
{ no: 9, name: "allowed_origins", kind: "message", T: UpdatableProjectFields_AllowedOrigins }
|
|
6181
6265
|
]));
|
|
6182
6266
|
let UpdatableProjectFields = _UpdatableProjectFields;
|
|
6183
6267
|
const _UpdatableProjectFields_AuthWebhookMethods = class _UpdatableProjectFields_AuthWebhookMethods extends Message {
|
|
@@ -6208,6 +6292,62 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6208
6292
|
{ no: 1, name: "methods", kind: "scalar", T: 9, repeated: true }
|
|
6209
6293
|
]));
|
|
6210
6294
|
let UpdatableProjectFields_AuthWebhookMethods = _UpdatableProjectFields_AuthWebhookMethods;
|
|
6295
|
+
const _UpdatableProjectFields_EventWebhookEvents = class _UpdatableProjectFields_EventWebhookEvents extends Message {
|
|
6296
|
+
constructor(data) {
|
|
6297
|
+
super();
|
|
6298
|
+
/**
|
|
6299
|
+
* @generated from field: repeated string events = 1;
|
|
6300
|
+
*/
|
|
6301
|
+
__publicField(this, "events", []);
|
|
6302
|
+
proto3.util.initPartial(data, this);
|
|
6303
|
+
}
|
|
6304
|
+
static fromBinary(bytes, options) {
|
|
6305
|
+
return new _UpdatableProjectFields_EventWebhookEvents().fromBinary(bytes, options);
|
|
6306
|
+
}
|
|
6307
|
+
static fromJson(jsonValue, options) {
|
|
6308
|
+
return new _UpdatableProjectFields_EventWebhookEvents().fromJson(jsonValue, options);
|
|
6309
|
+
}
|
|
6310
|
+
static fromJsonString(jsonString, options) {
|
|
6311
|
+
return new _UpdatableProjectFields_EventWebhookEvents().fromJsonString(jsonString, options);
|
|
6312
|
+
}
|
|
6313
|
+
static equals(a, b) {
|
|
6314
|
+
return proto3.util.equals(_UpdatableProjectFields_EventWebhookEvents, a, b);
|
|
6315
|
+
}
|
|
6316
|
+
};
|
|
6317
|
+
__publicField(_UpdatableProjectFields_EventWebhookEvents, "runtime", proto3);
|
|
6318
|
+
__publicField(_UpdatableProjectFields_EventWebhookEvents, "typeName", "yorkie.v1.UpdatableProjectFields.EventWebhookEvents");
|
|
6319
|
+
__publicField(_UpdatableProjectFields_EventWebhookEvents, "fields", proto3.util.newFieldList(() => [
|
|
6320
|
+
{ no: 1, name: "events", kind: "scalar", T: 9, repeated: true }
|
|
6321
|
+
]));
|
|
6322
|
+
let UpdatableProjectFields_EventWebhookEvents = _UpdatableProjectFields_EventWebhookEvents;
|
|
6323
|
+
const _UpdatableProjectFields_AllowedOrigins = class _UpdatableProjectFields_AllowedOrigins extends Message {
|
|
6324
|
+
constructor(data) {
|
|
6325
|
+
super();
|
|
6326
|
+
/**
|
|
6327
|
+
* @generated from field: repeated string origins = 1;
|
|
6328
|
+
*/
|
|
6329
|
+
__publicField(this, "origins", []);
|
|
6330
|
+
proto3.util.initPartial(data, this);
|
|
6331
|
+
}
|
|
6332
|
+
static fromBinary(bytes, options) {
|
|
6333
|
+
return new _UpdatableProjectFields_AllowedOrigins().fromBinary(bytes, options);
|
|
6334
|
+
}
|
|
6335
|
+
static fromJson(jsonValue, options) {
|
|
6336
|
+
return new _UpdatableProjectFields_AllowedOrigins().fromJson(jsonValue, options);
|
|
6337
|
+
}
|
|
6338
|
+
static fromJsonString(jsonString, options) {
|
|
6339
|
+
return new _UpdatableProjectFields_AllowedOrigins().fromJsonString(jsonString, options);
|
|
6340
|
+
}
|
|
6341
|
+
static equals(a, b) {
|
|
6342
|
+
return proto3.util.equals(_UpdatableProjectFields_AllowedOrigins, a, b);
|
|
6343
|
+
}
|
|
6344
|
+
};
|
|
6345
|
+
__publicField(_UpdatableProjectFields_AllowedOrigins, "runtime", proto3);
|
|
6346
|
+
__publicField(_UpdatableProjectFields_AllowedOrigins, "typeName", "yorkie.v1.UpdatableProjectFields.AllowedOrigins");
|
|
6347
|
+
__publicField(_UpdatableProjectFields_AllowedOrigins, "fields", proto3.util.newFieldList(() => [
|
|
6348
|
+
{ no: 1, name: "origins", kind: "scalar", T: 9, repeated: true }
|
|
6349
|
+
]));
|
|
6350
|
+
let UpdatableProjectFields_AllowedOrigins = _UpdatableProjectFields_AllowedOrigins;
|
|
6211
6351
|
const _DocumentSummary = class _DocumentSummary extends Message {
|
|
6212
6352
|
constructor(data) {
|
|
6213
6353
|
super();
|
|
@@ -6764,6 +6904,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6764
6904
|
* @generated from field: string document_id = 1;
|
|
6765
6905
|
*/
|
|
6766
6906
|
__publicField(this, "documentId", "");
|
|
6907
|
+
/**
|
|
6908
|
+
* @generated from field: int32 max_size_per_document = 3;
|
|
6909
|
+
*/
|
|
6910
|
+
__publicField(this, "maxSizePerDocument", 0);
|
|
6767
6911
|
/**
|
|
6768
6912
|
* @generated from field: yorkie.v1.ChangePack change_pack = 2;
|
|
6769
6913
|
*/
|
|
@@ -6793,6 +6937,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6793
6937
|
T: 9
|
|
6794
6938
|
/* ScalarType.STRING */
|
|
6795
6939
|
},
|
|
6940
|
+
{
|
|
6941
|
+
no: 3,
|
|
6942
|
+
name: "max_size_per_document",
|
|
6943
|
+
kind: "scalar",
|
|
6944
|
+
T: 5
|
|
6945
|
+
/* ScalarType.INT32 */
|
|
6946
|
+
},
|
|
6796
6947
|
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 }
|
|
6797
6948
|
]));
|
|
6798
6949
|
let AttachDocumentResponse = _AttachDocumentResponse;
|
|
@@ -7563,6 +7714,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7563
7714
|
Code2["ErrDocumentNotAttached"] = "ErrDocumentNotAttached";
|
|
7564
7715
|
Code2["ErrDocumentNotDetached"] = "ErrDocumentNotDetached";
|
|
7565
7716
|
Code2["ErrDocumentRemoved"] = "ErrDocumentRemoved";
|
|
7717
|
+
Code2["ErrDocumentSizeExceedsLimit"] = "ErrDocumentSizeExceedsLimit";
|
|
7566
7718
|
Code2["ErrInvalidObjectKey"] = "ErrInvalidObjectKey";
|
|
7567
7719
|
Code2["ErrInvalidArgument"] = "ErrInvalidArgument";
|
|
7568
7720
|
Code2["ErrNotInitialized"] = "ErrNotInitialized";
|
|
@@ -7585,76 +7737,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7585
7737
|
this.toString = () => `[code=${this.code}]: ${this.message}`;
|
|
7586
7738
|
}
|
|
7587
7739
|
}
|
|
7588
|
-
function deepcopy(object) {
|
|
7589
|
-
if (object instanceof Map) {
|
|
7590
|
-
const pairs = Array.from(object);
|
|
7591
|
-
return new Map(JSON.parse(JSON.stringify(pairs)));
|
|
7592
|
-
}
|
|
7593
|
-
return JSON.parse(JSON.stringify(object));
|
|
7594
|
-
}
|
|
7595
|
-
const isEmpty = (object) => {
|
|
7596
|
-
if (!object) {
|
|
7597
|
-
return true;
|
|
7598
|
-
}
|
|
7599
|
-
return Object.entries(object).length === 0;
|
|
7600
|
-
};
|
|
7601
|
-
const stringifyObjectValues = (attributes) => {
|
|
7602
|
-
const attrs = {};
|
|
7603
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
7604
|
-
attrs[key] = JSON.stringify(value);
|
|
7605
|
-
}
|
|
7606
|
-
return attrs;
|
|
7607
|
-
};
|
|
7608
|
-
const parseObjectValues = (attrs) => {
|
|
7609
|
-
const attributes = {};
|
|
7610
|
-
for (const [key, value] of Object.entries(attrs)) {
|
|
7611
|
-
attributes[key] = JSON.parse(value);
|
|
7612
|
-
}
|
|
7613
|
-
return attributes;
|
|
7614
|
-
};
|
|
7615
7740
|
var PresenceChangeType = /* @__PURE__ */ ((PresenceChangeType2) => {
|
|
7616
7741
|
PresenceChangeType2["Put"] = "put";
|
|
7617
7742
|
PresenceChangeType2["Clear"] = "clear";
|
|
7618
7743
|
return PresenceChangeType2;
|
|
7619
7744
|
})(PresenceChangeType || {});
|
|
7620
|
-
class Presence {
|
|
7621
|
-
constructor(changeContext, presence) {
|
|
7622
|
-
__publicField(this, "context");
|
|
7623
|
-
__publicField(this, "presence");
|
|
7624
|
-
this.context = changeContext;
|
|
7625
|
-
this.presence = presence;
|
|
7626
|
-
}
|
|
7627
|
-
/**
|
|
7628
|
-
* `set` updates the presence based on the partial presence.
|
|
7629
|
-
*/
|
|
7630
|
-
set(presence, option) {
|
|
7631
|
-
for (const key of Object.keys(presence)) {
|
|
7632
|
-
this.presence[key] = presence[key];
|
|
7633
|
-
}
|
|
7634
|
-
this.context.setPresenceChange({
|
|
7635
|
-
type: "put",
|
|
7636
|
-
presence: deepcopy(this.presence)
|
|
7637
|
-
});
|
|
7638
|
-
this.context.setReversePresence(presence, option);
|
|
7639
|
-
}
|
|
7640
|
-
/**
|
|
7641
|
-
* `get` returns the presence value of the given key.
|
|
7642
|
-
*/
|
|
7643
|
-
get(key) {
|
|
7644
|
-
return this.presence[key];
|
|
7645
|
-
}
|
|
7646
|
-
/**
|
|
7647
|
-
* `clear` clears the presence.
|
|
7648
|
-
* @internal
|
|
7649
|
-
*/
|
|
7650
|
-
clear() {
|
|
7651
|
-
this.presence = {};
|
|
7652
|
-
this.context.setPresenceChange({
|
|
7653
|
-
type: "clear"
|
|
7654
|
-
/* Clear */
|
|
7655
|
-
});
|
|
7656
|
-
}
|
|
7657
|
-
}
|
|
7658
7745
|
const InitialActorID = "000000000000000000000000";
|
|
7659
7746
|
const TimeTicketSize = 8 + 4 + 12;
|
|
7660
7747
|
class TimeTicket {
|
|
@@ -7770,10 +7857,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7770
7857
|
return 0;
|
|
7771
7858
|
}
|
|
7772
7859
|
}
|
|
7860
|
+
const InitialLamport = 0n;
|
|
7773
7861
|
const InitialDelimiter = 0;
|
|
7774
7862
|
const MaxLamport = 9223372036854775807n;
|
|
7775
7863
|
const InitialTimeTicket = new TimeTicket(
|
|
7776
|
-
|
|
7864
|
+
InitialLamport,
|
|
7777
7865
|
InitialDelimiter,
|
|
7778
7866
|
InitialActorID
|
|
7779
7867
|
);
|
|
@@ -10984,6 +11072,50 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
10984
11072
|
this.numberOfRemovedElement--;
|
|
10985
11073
|
}
|
|
10986
11074
|
}
|
|
11075
|
+
function deepcopy(object) {
|
|
11076
|
+
if (object instanceof Map) {
|
|
11077
|
+
const pairs = Array.from(object);
|
|
11078
|
+
return new Map(JSON.parse(JSON.stringify(pairs)));
|
|
11079
|
+
}
|
|
11080
|
+
return JSON.parse(JSON.stringify(object));
|
|
11081
|
+
}
|
|
11082
|
+
const isEmpty = (object) => {
|
|
11083
|
+
if (!object) {
|
|
11084
|
+
return true;
|
|
11085
|
+
}
|
|
11086
|
+
return Object.entries(object).length === 0;
|
|
11087
|
+
};
|
|
11088
|
+
const stringifyObjectValues = (attributes) => {
|
|
11089
|
+
const attrs = {};
|
|
11090
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
11091
|
+
attrs[key] = JSON.stringify(value);
|
|
11092
|
+
}
|
|
11093
|
+
return attrs;
|
|
11094
|
+
};
|
|
11095
|
+
const parseObjectValues = (attrs) => {
|
|
11096
|
+
const attributes = {};
|
|
11097
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
11098
|
+
attributes[key] = JSON.parse(value);
|
|
11099
|
+
}
|
|
11100
|
+
return attributes;
|
|
11101
|
+
};
|
|
11102
|
+
function totalDocSize(d) {
|
|
11103
|
+
if (!d) return 0;
|
|
11104
|
+
return totalDataSize(d.live) + totalDataSize(d.gc);
|
|
11105
|
+
}
|
|
11106
|
+
function totalDataSize(d) {
|
|
11107
|
+
return d.data + d.meta;
|
|
11108
|
+
}
|
|
11109
|
+
function addDataSizes(target, ...others) {
|
|
11110
|
+
for (const other of others) {
|
|
11111
|
+
target.data += other.data;
|
|
11112
|
+
target.meta += other.meta;
|
|
11113
|
+
}
|
|
11114
|
+
}
|
|
11115
|
+
function subDataSize(target, other) {
|
|
11116
|
+
target.data -= other.data;
|
|
11117
|
+
target.meta -= other.meta;
|
|
11118
|
+
}
|
|
10987
11119
|
class CRDTTextValue {
|
|
10988
11120
|
constructor(content) {
|
|
10989
11121
|
__publicField(this, "attributes");
|
|
@@ -11119,7 +11251,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11119
11251
|
crdtTextValue.setAttr(k, v, editedAt);
|
|
11120
11252
|
}
|
|
11121
11253
|
}
|
|
11122
|
-
const [caretPos, pairs, valueChanges] = this.rgaTreeSplit.edit(
|
|
11254
|
+
const [caretPos, pairs, diff, valueChanges] = this.rgaTreeSplit.edit(
|
|
11123
11255
|
range,
|
|
11124
11256
|
editedAt,
|
|
11125
11257
|
crdtTextValue,
|
|
@@ -11137,7 +11269,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11137
11269
|
type: "content"
|
|
11138
11270
|
/* Content */
|
|
11139
11271
|
}));
|
|
11140
|
-
return [changes, pairs, [caretPos, caretPos]];
|
|
11272
|
+
return [changes, pairs, diff, [caretPos, caretPos]];
|
|
11141
11273
|
}
|
|
11142
11274
|
/**
|
|
11143
11275
|
* `setStyle` applies the style of the given range.
|
|
@@ -11150,11 +11282,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11150
11282
|
* @internal
|
|
11151
11283
|
*/
|
|
11152
11284
|
setStyle(range, attributes, editedAt, versionVector) {
|
|
11153
|
-
const
|
|
11154
|
-
const [,
|
|
11285
|
+
const diff = { data: 0, meta: 0 };
|
|
11286
|
+
const [, diffTo, toRight] = this.rgaTreeSplit.findNodeWithSplit(
|
|
11287
|
+
range[1],
|
|
11288
|
+
editedAt
|
|
11289
|
+
);
|
|
11290
|
+
const [, diffFrom, fromRight] = this.rgaTreeSplit.findNodeWithSplit(
|
|
11155
11291
|
range[0],
|
|
11156
11292
|
editedAt
|
|
11157
11293
|
);
|
|
11294
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
11158
11295
|
const changes = [];
|
|
11159
11296
|
const nodes = this.rgaTreeSplit.findBetween(fromRight, toRight);
|
|
11160
11297
|
const toBeStyleds = [];
|
|
@@ -11190,9 +11327,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11190
11327
|
if (prev !== void 0) {
|
|
11191
11328
|
pairs.push({ parent: node.getValue(), child: prev });
|
|
11192
11329
|
}
|
|
11330
|
+
const curr = node.getValue().getAttrs().getNodeMapByKey().get(key);
|
|
11331
|
+
if (curr !== void 0) {
|
|
11332
|
+
addDataSizes(diff, curr.getDataSize());
|
|
11333
|
+
}
|
|
11193
11334
|
}
|
|
11194
11335
|
}
|
|
11195
|
-
return [pairs, changes];
|
|
11336
|
+
return [pairs, diff, changes];
|
|
11196
11337
|
}
|
|
11197
11338
|
/**
|
|
11198
11339
|
* `indexRangeToPosRange` returns the position range of the given index range.
|
|
@@ -11381,13 +11522,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11381
11522
|
);
|
|
11382
11523
|
}
|
|
11383
11524
|
const text = parentObject;
|
|
11384
|
-
const [changes, pairs] = text.edit(
|
|
11525
|
+
const [changes, pairs, diff] = text.edit(
|
|
11385
11526
|
[this.fromPos, this.toPos],
|
|
11386
11527
|
this.content,
|
|
11387
11528
|
this.getExecutedAt(),
|
|
11388
11529
|
Object.fromEntries(this.attributes),
|
|
11389
11530
|
versionVector
|
|
11390
11531
|
);
|
|
11532
|
+
root.acc(diff);
|
|
11391
11533
|
for (const pair of pairs) {
|
|
11392
11534
|
root.registerGCPair(pair);
|
|
11393
11535
|
}
|
|
@@ -11484,12 +11626,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11484
11626
|
);
|
|
11485
11627
|
}
|
|
11486
11628
|
const text = parentObject;
|
|
11487
|
-
const [pairs, changes] = text.setStyle(
|
|
11629
|
+
const [pairs, diff, changes] = text.setStyle(
|
|
11488
11630
|
[this.fromPos, this.toPos],
|
|
11489
11631
|
this.attributes ? Object.fromEntries(this.attributes) : {},
|
|
11490
11632
|
this.getExecutedAt(),
|
|
11491
11633
|
versionVector
|
|
11492
11634
|
);
|
|
11635
|
+
root.acc(diff);
|
|
11493
11636
|
for (const pair of pairs) {
|
|
11494
11637
|
root.registerGCPair(pair);
|
|
11495
11638
|
}
|
|
@@ -11643,19 +11786,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11643
11786
|
* `splitText` splits the given node at the given offset.
|
|
11644
11787
|
*/
|
|
11645
11788
|
splitText(offset, absOffset) {
|
|
11789
|
+
const diff = { data: 0, meta: 0 };
|
|
11646
11790
|
if (offset === 0 || offset === this.size) {
|
|
11647
|
-
return;
|
|
11791
|
+
return [void 0, diff];
|
|
11648
11792
|
}
|
|
11649
11793
|
const leftValue = this.value.slice(0, offset);
|
|
11650
11794
|
const rightValue = this.value.slice(offset);
|
|
11651
11795
|
if (!rightValue.length) {
|
|
11652
|
-
return;
|
|
11796
|
+
return [void 0, diff];
|
|
11653
11797
|
}
|
|
11798
|
+
const prvSize = this.getDataSize();
|
|
11654
11799
|
this.value = leftValue;
|
|
11655
11800
|
const rightNode = this.cloneText(offset + absOffset);
|
|
11656
11801
|
rightNode.value = rightValue;
|
|
11657
11802
|
this.parent.insertAfterInternal(rightNode, this);
|
|
11658
|
-
|
|
11803
|
+
addDataSizes(diff, this.getDataSize(), rightNode.getDataSize());
|
|
11804
|
+
subDataSize(diff, prvSize);
|
|
11805
|
+
return [rightNode, diff];
|
|
11659
11806
|
}
|
|
11660
11807
|
/**
|
|
11661
11808
|
* `children` returns the children of the node.
|
|
@@ -11770,6 +11917,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11770
11917
|
* `splitElement` splits the given element at the given offset.
|
|
11771
11918
|
*/
|
|
11772
11919
|
splitElement(offset, issueTimeTicket) {
|
|
11920
|
+
const diff = { data: 0, meta: 0 };
|
|
11921
|
+
const prvSize = this.getDataSize();
|
|
11773
11922
|
const clone = this.cloneElement(issueTimeTicket);
|
|
11774
11923
|
this.parent.insertAfterInternal(clone, this);
|
|
11775
11924
|
clone.updateAncestorsSize();
|
|
@@ -11788,7 +11937,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
11788
11937
|
for (const child of clone._children) {
|
|
11789
11938
|
child.parent = clone;
|
|
11790
11939
|
}
|
|
11791
|
-
|
|
11940
|
+
addDataSizes(diff, this.getDataSize(), clone.getDataSize());
|
|
11941
|
+
subDataSize(diff, prvSize);
|
|
11942
|
+
return [clone, diff];
|
|
11792
11943
|
}
|
|
11793
11944
|
/**
|
|
11794
11945
|
* `insertAfterInternal` inserts the given node after the given child.
|
|
@@ -12781,7 +12932,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12781
12932
|
* `split` splits the given offset of this node.
|
|
12782
12933
|
*/
|
|
12783
12934
|
split(tree, offset, issueTimeTicket) {
|
|
12784
|
-
const split = this.isText ? this.splitText(offset, this.id.getOffset()) : this.splitElement(offset, issueTimeTicket);
|
|
12935
|
+
const [split, diff] = this.isText ? this.splitText(offset, this.id.getOffset()) : this.splitElement(offset, issueTimeTicket);
|
|
12785
12936
|
if (split) {
|
|
12786
12937
|
split.insPrevID = this.id;
|
|
12787
12938
|
if (this.insNextID) {
|
|
@@ -12792,7 +12943,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12792
12943
|
this.insNextID = split.id;
|
|
12793
12944
|
tree.registerNode(split);
|
|
12794
12945
|
}
|
|
12795
|
-
return split;
|
|
12946
|
+
return [split, diff];
|
|
12796
12947
|
}
|
|
12797
12948
|
/**
|
|
12798
12949
|
* `getCreatedAt` returns the creation time of this element.
|
|
@@ -12983,15 +13134,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
12983
13134
|
* for concurrent insertion.
|
|
12984
13135
|
*/
|
|
12985
13136
|
findNodesAndSplitText(pos, editedAt) {
|
|
13137
|
+
let diff = { data: 0, meta: 0 };
|
|
12986
13138
|
const [parent, leftSibling] = pos.toTreeNodePair(this);
|
|
12987
13139
|
let leftNode = leftSibling;
|
|
12988
13140
|
const isLeftMost = parent === leftNode;
|
|
12989
13141
|
const realParent = leftNode.parent && !isLeftMost ? leftNode.parent : parent;
|
|
12990
13142
|
if (leftNode.isText) {
|
|
12991
|
-
leftNode.split(
|
|
13143
|
+
const [, splitedDiff] = leftNode.split(
|
|
12992
13144
|
this,
|
|
12993
13145
|
pos.getLeftSiblingID().getOffset() - leftNode.id.getOffset()
|
|
12994
13146
|
);
|
|
13147
|
+
diff = splitedDiff;
|
|
12995
13148
|
}
|
|
12996
13149
|
if (editedAt) {
|
|
12997
13150
|
const allChildren = realParent.allChildren;
|
|
@@ -13004,17 +13157,22 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13004
13157
|
leftNode = next;
|
|
13005
13158
|
}
|
|
13006
13159
|
}
|
|
13007
|
-
return [realParent, leftNode];
|
|
13160
|
+
return [[realParent, leftNode], diff];
|
|
13008
13161
|
}
|
|
13009
13162
|
/**
|
|
13010
13163
|
* `style` applies the given attributes of the given range.
|
|
13011
13164
|
*/
|
|
13012
13165
|
style(range, attributes, editedAt, versionVector) {
|
|
13013
|
-
const
|
|
13166
|
+
const diff = { data: 0, meta: 0 };
|
|
13167
|
+
const [[fromParent, fromLeft], diffFrom] = this.findNodesAndSplitText(
|
|
13014
13168
|
range[0],
|
|
13015
13169
|
editedAt
|
|
13016
13170
|
);
|
|
13017
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(
|
|
13171
|
+
const [[toParent, toLeft], diffTo] = this.findNodesAndSplitText(
|
|
13172
|
+
range[1],
|
|
13173
|
+
editedAt
|
|
13174
|
+
);
|
|
13175
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
13018
13176
|
const changes = [];
|
|
13019
13177
|
const attrs = attributes ? parseObjectValues(attributes) : {};
|
|
13020
13178
|
const pairs = [];
|
|
@@ -13023,7 +13181,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13023
13181
|
fromLeft,
|
|
13024
13182
|
toParent,
|
|
13025
13183
|
toLeft,
|
|
13026
|
-
([node]) => {
|
|
13184
|
+
([node, tokenType]) => {
|
|
13185
|
+
var _a2;
|
|
13027
13186
|
const actorID = node.getCreatedAt().getActorID();
|
|
13028
13187
|
let clientLamportAtChange = MaxLamport;
|
|
13029
13188
|
if (versionVector != void 0) {
|
|
@@ -13059,20 +13218,31 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13059
13218
|
pairs.push({ parent: node, child: prev });
|
|
13060
13219
|
}
|
|
13061
13220
|
}
|
|
13221
|
+
for (const [key] of Object.entries(attrs)) {
|
|
13222
|
+
const curr = (_a2 = node.attrs) == null ? void 0 : _a2.getNodeMapByKey().get(key);
|
|
13223
|
+
if (curr !== void 0 && tokenType !== TokenType.End) {
|
|
13224
|
+
addDataSizes(diff, curr.getDataSize());
|
|
13225
|
+
}
|
|
13226
|
+
}
|
|
13062
13227
|
}
|
|
13063
13228
|
}
|
|
13064
13229
|
);
|
|
13065
|
-
return [pairs, changes];
|
|
13230
|
+
return [pairs, changes, diff];
|
|
13066
13231
|
}
|
|
13067
13232
|
/**
|
|
13068
13233
|
* `removeStyle` removes the given attributes of the given range.
|
|
13069
13234
|
*/
|
|
13070
13235
|
removeStyle(range, attributesToRemove, editedAt, versionVector) {
|
|
13071
|
-
const
|
|
13236
|
+
const diff = { data: 0, meta: 0 };
|
|
13237
|
+
const [[fromParent, fromLeft], diffFrom] = this.findNodesAndSplitText(
|
|
13072
13238
|
range[0],
|
|
13073
13239
|
editedAt
|
|
13074
13240
|
);
|
|
13075
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(
|
|
13241
|
+
const [[toParent, toLeft], diffTo] = this.findNodesAndSplitText(
|
|
13242
|
+
range[1],
|
|
13243
|
+
editedAt
|
|
13244
|
+
);
|
|
13245
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
13076
13246
|
const changes = [];
|
|
13077
13247
|
const pairs = [];
|
|
13078
13248
|
this.traverseInPosRange(
|
|
@@ -13110,18 +13280,23 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13110
13280
|
}
|
|
13111
13281
|
}
|
|
13112
13282
|
);
|
|
13113
|
-
return [pairs, changes];
|
|
13283
|
+
return [pairs, changes, diff];
|
|
13114
13284
|
}
|
|
13115
13285
|
/**
|
|
13116
13286
|
* `edit` edits the tree with the given range and content.
|
|
13117
13287
|
* If the content is undefined, the range will be removed.
|
|
13118
13288
|
*/
|
|
13119
13289
|
edit(range, contents, splitLevel, editedAt, issueTimeTicket, versionVector) {
|
|
13120
|
-
const
|
|
13290
|
+
const diff = { data: 0, meta: 0 };
|
|
13291
|
+
const [[fromParent, fromLeft], diffFrom] = this.findNodesAndSplitText(
|
|
13121
13292
|
range[0],
|
|
13122
13293
|
editedAt
|
|
13123
13294
|
);
|
|
13124
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(
|
|
13295
|
+
const [[toParent, toLeft], diffTo] = this.findNodesAndSplitText(
|
|
13296
|
+
range[1],
|
|
13297
|
+
editedAt
|
|
13298
|
+
);
|
|
13299
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
13125
13300
|
const fromIdx = this.toIndex(fromParent, fromLeft);
|
|
13126
13301
|
const fromPath = this.toPath(fromParent, fromLeft);
|
|
13127
13302
|
const nodesToBeRemoved = [];
|
|
@@ -13200,6 +13375,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13200
13375
|
if (fromParent.isRemoved) {
|
|
13201
13376
|
node.remove(editedAt);
|
|
13202
13377
|
pairs.push({ parent: this, child: node });
|
|
13378
|
+
} else {
|
|
13379
|
+
addDataSizes(diff, node.getDataSize());
|
|
13203
13380
|
}
|
|
13204
13381
|
this.nodeMapByID.put(node.id, node);
|
|
13205
13382
|
});
|
|
@@ -13224,7 +13401,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13224
13401
|
}
|
|
13225
13402
|
}
|
|
13226
13403
|
}
|
|
13227
|
-
return [changes, pairs];
|
|
13404
|
+
return [changes, pairs, diff];
|
|
13228
13405
|
}
|
|
13229
13406
|
/**
|
|
13230
13407
|
* `editT` edits the given range with the given value.
|
|
@@ -13503,16 +13680,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13503
13680
|
* `posRangeToPathRange` converts the given position range to the path range.
|
|
13504
13681
|
*/
|
|
13505
13682
|
posRangeToPathRange(range) {
|
|
13506
|
-
const [fromParent, fromLeft] = this.findNodesAndSplitText(range[0]);
|
|
13507
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(range[1]);
|
|
13683
|
+
const [[fromParent, fromLeft]] = this.findNodesAndSplitText(range[0]);
|
|
13684
|
+
const [[toParent, toLeft]] = this.findNodesAndSplitText(range[1]);
|
|
13508
13685
|
return [this.toPath(fromParent, fromLeft), this.toPath(toParent, toLeft)];
|
|
13509
13686
|
}
|
|
13510
13687
|
/**
|
|
13511
13688
|
* `posRangeToIndexRange` converts the given position range to the path range.
|
|
13512
13689
|
*/
|
|
13513
13690
|
posRangeToIndexRange(range) {
|
|
13514
|
-
const [fromParent, fromLeft] = this.findNodesAndSplitText(range[0]);
|
|
13515
|
-
const [toParent, toLeft] = this.findNodesAndSplitText(range[1]);
|
|
13691
|
+
const [[fromParent, fromLeft]] = this.findNodesAndSplitText(range[0]);
|
|
13692
|
+
const [[toParent, toLeft]] = this.findNodesAndSplitText(range[1]);
|
|
13516
13693
|
return [this.toIndex(fromParent, fromLeft), this.toIndex(toParent, toLeft)];
|
|
13517
13694
|
}
|
|
13518
13695
|
/**
|
|
@@ -13707,7 +13884,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13707
13884
|
}
|
|
13708
13885
|
const editedAt = this.getExecutedAt();
|
|
13709
13886
|
const tree = parentObject;
|
|
13710
|
-
const [changes, pairs] = tree.edit(
|
|
13887
|
+
const [changes, pairs, diff] = tree.edit(
|
|
13711
13888
|
[this.fromPos, this.toPos],
|
|
13712
13889
|
(_a2 = this.contents) == null ? void 0 : _a2.map((content) => content.deepcopy()),
|
|
13713
13890
|
this.splitLevel,
|
|
@@ -13733,6 +13910,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13733
13910
|
})(),
|
|
13734
13911
|
versionVector
|
|
13735
13912
|
);
|
|
13913
|
+
root.acc(diff);
|
|
13736
13914
|
for (const pair of pairs) {
|
|
13737
13915
|
root.registerGCPair(pair);
|
|
13738
13916
|
}
|
|
@@ -13899,12 +14077,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13899
14077
|
__publicField(this, "clientSeq");
|
|
13900
14078
|
// `serverSeq` is optional and only present for changes stored on the server.
|
|
13901
14079
|
__publicField(this, "serverSeq");
|
|
13902
|
-
// `
|
|
13903
|
-
// This is used to determine the order of changes in logical time.
|
|
13904
|
-
__publicField(this, "lamport");
|
|
14080
|
+
// `actor` is the creator of this change.
|
|
13905
14081
|
__publicField(this, "actor");
|
|
14082
|
+
// `lamport` is the lamport clock of this change. This is used to determine
|
|
14083
|
+
// the order of changes in logical time. It is optional and only present
|
|
14084
|
+
// if the change has operations.
|
|
14085
|
+
__publicField(this, "lamport");
|
|
13906
14086
|
// `versionVector` is the vector clock of this change. This is used to
|
|
13907
|
-
// determine the relationship is causal or not between changes.
|
|
14087
|
+
// determine the relationship is causal or not between changes. It is optional
|
|
14088
|
+
// and only present if the change has operations.
|
|
13908
14089
|
__publicField(this, "versionVector");
|
|
13909
14090
|
this.clientSeq = clientSeq;
|
|
13910
14091
|
this.serverSeq = serverSeq;
|
|
@@ -13912,6 +14093,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13912
14093
|
this.versionVector = vector;
|
|
13913
14094
|
this.actor = actor;
|
|
13914
14095
|
}
|
|
14096
|
+
/**
|
|
14097
|
+
* `hasClocks` returns true if this ID has logical clocks.
|
|
14098
|
+
*/
|
|
14099
|
+
hasClocks() {
|
|
14100
|
+
return this.versionVector.size() > 0 && this.lamport != InitialLamport;
|
|
14101
|
+
}
|
|
13915
14102
|
/**
|
|
13916
14103
|
* `of` creates a new instance of ChangeID.
|
|
13917
14104
|
*/
|
|
@@ -13921,7 +14108,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13921
14108
|
/**
|
|
13922
14109
|
* `next` creates a next ID of this ID.
|
|
13923
14110
|
*/
|
|
13924
|
-
next() {
|
|
14111
|
+
next(excludeClocks = false) {
|
|
14112
|
+
if (excludeClocks) {
|
|
14113
|
+
return new ChangeID(
|
|
14114
|
+
this.clientSeq + 1,
|
|
14115
|
+
this.lamport,
|
|
14116
|
+
this.actor,
|
|
14117
|
+
InitialVersionVector,
|
|
14118
|
+
InitialLamport
|
|
14119
|
+
);
|
|
14120
|
+
}
|
|
13925
14121
|
const vector = this.versionVector.deepcopy();
|
|
13926
14122
|
vector.set(this.actor, this.lamport + 1n);
|
|
13927
14123
|
return new ChangeID(
|
|
@@ -13932,9 +14128,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13932
14128
|
);
|
|
13933
14129
|
}
|
|
13934
14130
|
/**
|
|
13935
|
-
* `syncClocks` syncs logical clocks with the given ID.
|
|
14131
|
+
* `syncClocks` syncs logical clocks with the given ID. If the given ID
|
|
14132
|
+
* doesn't have logical clocks, this ID is returned.
|
|
13936
14133
|
*/
|
|
13937
14134
|
syncClocks(other) {
|
|
14135
|
+
if (!other.hasClocks()) {
|
|
14136
|
+
return this;
|
|
14137
|
+
}
|
|
13938
14138
|
const lamport = other.lamport > this.lamport ? other.lamport + 1n : this.lamport + 1n;
|
|
13939
14139
|
const maxVersionVector = this.versionVector.max(other.versionVector);
|
|
13940
14140
|
const newID = new ChangeID(
|
|
@@ -13975,6 +14175,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
13975
14175
|
this.serverSeq
|
|
13976
14176
|
);
|
|
13977
14177
|
}
|
|
14178
|
+
/**
|
|
14179
|
+
* `setLamport` sets the given lamport clock.
|
|
14180
|
+
*/
|
|
14181
|
+
setLamport(lamport) {
|
|
14182
|
+
return new ChangeID(
|
|
14183
|
+
this.clientSeq,
|
|
14184
|
+
lamport,
|
|
14185
|
+
this.actor,
|
|
14186
|
+
this.versionVector,
|
|
14187
|
+
this.serverSeq
|
|
14188
|
+
);
|
|
14189
|
+
}
|
|
13978
14190
|
/**
|
|
13979
14191
|
* `setVersionVector` sets the given version vector.
|
|
13980
14192
|
*/
|
|
@@ -14753,8 +14965,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14753
14965
|
* @returns `[RGATreeSplitPos, Array<GCPair>, Array<Change>]`
|
|
14754
14966
|
*/
|
|
14755
14967
|
edit(range, editedAt, value, versionVector) {
|
|
14756
|
-
const
|
|
14757
|
-
const [
|
|
14968
|
+
const diff = { data: 0, meta: 0 };
|
|
14969
|
+
const [toLeft, diffTo, toRight] = this.findNodeWithSplit(
|
|
14970
|
+
range[1],
|
|
14971
|
+
editedAt
|
|
14972
|
+
);
|
|
14973
|
+
const [fromLeft, diffFrom, fromRight] = this.findNodeWithSplit(
|
|
14974
|
+
range[0],
|
|
14975
|
+
editedAt
|
|
14976
|
+
);
|
|
14977
|
+
addDataSizes(diff, diffTo, diffFrom);
|
|
14758
14978
|
const nodesToDelete = this.findBetween(fromRight, toRight);
|
|
14759
14979
|
const [changes, removedNodes] = this.deleteNodes(
|
|
14760
14980
|
nodesToDelete,
|
|
@@ -14769,6 +14989,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14769
14989
|
fromLeft,
|
|
14770
14990
|
RGATreeSplitNode.create(RGATreeSplitNodeID.of(editedAt, 0), value)
|
|
14771
14991
|
);
|
|
14992
|
+
addDataSizes(diff, inserted.getDataSize());
|
|
14772
14993
|
if (changes.length && changes[changes.length - 1].from === idx) {
|
|
14773
14994
|
changes[changes.length - 1].value = value;
|
|
14774
14995
|
} else {
|
|
@@ -14788,7 +15009,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14788
15009
|
for (const [, removedNode] of removedNodes) {
|
|
14789
15010
|
pairs.push({ parent: this, child: removedNode });
|
|
14790
15011
|
}
|
|
14791
|
-
return [caretPos, pairs, changes];
|
|
15012
|
+
return [caretPos, pairs, diff, changes];
|
|
14792
15013
|
}
|
|
14793
15014
|
/**
|
|
14794
15015
|
* `indexToPos` finds RGATreeSplitPos of given offset.
|
|
@@ -14927,11 +15148,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14927
15148
|
const absoluteID = pos.getAbsoluteID();
|
|
14928
15149
|
let node = this.findFloorNodePreferToLeft(absoluteID);
|
|
14929
15150
|
const relativeOffset = absoluteID.getOffset() - node.getID().getOffset();
|
|
14930
|
-
this.splitNode(node, relativeOffset);
|
|
15151
|
+
const [, diff] = this.splitNode(node, relativeOffset);
|
|
14931
15152
|
while (node.hasNext() && node.getNext().getCreatedAt().after(editedAt)) {
|
|
14932
15153
|
node = node.getNext();
|
|
14933
15154
|
}
|
|
14934
|
-
return [node, node.getNext()];
|
|
15155
|
+
return [node, diff, node.getNext()];
|
|
14935
15156
|
}
|
|
14936
15157
|
findFloorNodePreferToLeft(id) {
|
|
14937
15158
|
let node = this.findFloorNode(id);
|
|
@@ -14972,6 +15193,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14972
15193
|
return nodes;
|
|
14973
15194
|
}
|
|
14974
15195
|
splitNode(node, offset) {
|
|
15196
|
+
const diff = { data: 0, meta: 0 };
|
|
14975
15197
|
if (offset > node.getContentLength()) {
|
|
14976
15198
|
throw new YorkieError(
|
|
14977
15199
|
Code.ErrInvalidArgument,
|
|
@@ -14979,10 +15201,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14979
15201
|
);
|
|
14980
15202
|
}
|
|
14981
15203
|
if (offset === 0) {
|
|
14982
|
-
return node;
|
|
15204
|
+
return [node, diff];
|
|
14983
15205
|
} else if (offset === node.getContentLength()) {
|
|
14984
|
-
return node.getNext();
|
|
15206
|
+
return [node.getNext(), diff];
|
|
14985
15207
|
}
|
|
15208
|
+
const prvSize = node.getDataSize();
|
|
14986
15209
|
const splitNode = node.split(offset);
|
|
14987
15210
|
this.treeByIndex.updateWeight(splitNode);
|
|
14988
15211
|
this.insertAfter(node, splitNode);
|
|
@@ -14991,7 +15214,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
14991
15214
|
insNext.setInsPrev(splitNode);
|
|
14992
15215
|
}
|
|
14993
15216
|
splitNode.setInsPrev(node);
|
|
14994
|
-
|
|
15217
|
+
addDataSizes(diff, node.getDataSize(), splitNode.getDataSize());
|
|
15218
|
+
subDataSize(diff, prvSize);
|
|
15219
|
+
return [splitNode, diff];
|
|
14995
15220
|
}
|
|
14996
15221
|
deleteNodes(candidates, editedAt, versionVector) {
|
|
14997
15222
|
if (!candidates.length) {
|
|
@@ -15460,10 +15685,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
15460
15685
|
const tree = parentObject;
|
|
15461
15686
|
let changes;
|
|
15462
15687
|
let pairs;
|
|
15688
|
+
let diff = { data: 0, meta: 0 };
|
|
15463
15689
|
if (this.attributes.size) {
|
|
15464
15690
|
const attributes = {};
|
|
15465
15691
|
[...this.attributes].forEach(([key, value]) => attributes[key] = value);
|
|
15466
|
-
[pairs, changes] = tree.style(
|
|
15692
|
+
[pairs, changes, diff] = tree.style(
|
|
15467
15693
|
[this.fromPos, this.toPos],
|
|
15468
15694
|
attributes,
|
|
15469
15695
|
this.getExecutedAt(),
|
|
@@ -15471,13 +15697,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
15471
15697
|
);
|
|
15472
15698
|
} else {
|
|
15473
15699
|
const attributesToRemove = this.attributesToRemove;
|
|
15474
|
-
[pairs, changes] = tree.removeStyle(
|
|
15700
|
+
[pairs, changes, diff] = tree.removeStyle(
|
|
15475
15701
|
[this.fromPos, this.toPos],
|
|
15476
15702
|
attributesToRemove,
|
|
15477
15703
|
this.getExecutedAt(),
|
|
15478
15704
|
versionVector
|
|
15479
15705
|
);
|
|
15480
15706
|
}
|
|
15707
|
+
root.acc(diff);
|
|
15481
15708
|
for (const pair of pairs) {
|
|
15482
15709
|
root.registerGCPair(pair);
|
|
15483
15710
|
}
|
|
@@ -16930,8 +17157,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16930
17157
|
};
|
|
16931
17158
|
}
|
|
16932
17159
|
class ChangeContext {
|
|
16933
|
-
constructor(
|
|
16934
|
-
__publicField(this, "
|
|
17160
|
+
constructor(prevID, root, presence, message) {
|
|
17161
|
+
__publicField(this, "prevID");
|
|
17162
|
+
__publicField(this, "nextID");
|
|
16935
17163
|
__publicField(this, "delimiter");
|
|
16936
17164
|
__publicField(this, "message");
|
|
16937
17165
|
__publicField(this, "root");
|
|
@@ -16947,7 +17175,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16947
17175
|
* presence changes.
|
|
16948
17176
|
*/
|
|
16949
17177
|
__publicField(this, "reversePresenceKeys");
|
|
16950
|
-
this.
|
|
17178
|
+
this.prevID = prevID;
|
|
17179
|
+
this.nextID = prevID.next();
|
|
16951
17180
|
this.delimiter = InitialDelimiter;
|
|
16952
17181
|
this.root = root;
|
|
16953
17182
|
this.operations = [];
|
|
@@ -16959,8 +17188,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16959
17188
|
/**
|
|
16960
17189
|
* `create` creates a new instance of ChangeContext.
|
|
16961
17190
|
*/
|
|
16962
|
-
static create(
|
|
16963
|
-
return new ChangeContext(
|
|
17191
|
+
static create(prevID, root, presence, message) {
|
|
17192
|
+
return new ChangeContext(prevID, root, presence, message);
|
|
16964
17193
|
}
|
|
16965
17194
|
/**
|
|
16966
17195
|
* `push` pushes the given operation to this context.
|
|
@@ -16987,16 +17216,34 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16987
17216
|
this.root.registerGCPair(pair);
|
|
16988
17217
|
}
|
|
16989
17218
|
/**
|
|
16990
|
-
* `
|
|
17219
|
+
* `getNextID` returns the next ID of this context. It will be set to the
|
|
17220
|
+
* document for the next change.returns the next ID of this context.
|
|
16991
17221
|
*/
|
|
16992
|
-
|
|
17222
|
+
getNextID() {
|
|
17223
|
+
if (this.isPresenceOnlyChange()) {
|
|
17224
|
+
return this.prevID.next(true).setLamport(this.prevID.getLamport()).setVersionVector(this.prevID.getVersionVector());
|
|
17225
|
+
}
|
|
17226
|
+
return this.nextID;
|
|
17227
|
+
}
|
|
17228
|
+
/**
|
|
17229
|
+
* `toChange` creates a new instance of Change in this context.
|
|
17230
|
+
*/
|
|
17231
|
+
toChange() {
|
|
17232
|
+
const id = this.isPresenceOnlyChange() ? this.prevID.next(true) : this.nextID;
|
|
16993
17233
|
return Change.create({
|
|
16994
|
-
id
|
|
17234
|
+
id,
|
|
16995
17235
|
operations: this.operations,
|
|
16996
17236
|
presenceChange: this.presenceChange,
|
|
16997
17237
|
message: this.message
|
|
16998
17238
|
});
|
|
16999
17239
|
}
|
|
17240
|
+
/**
|
|
17241
|
+
* `isPresenceOnlyChange` returns whether this context is only for presence
|
|
17242
|
+
* change or not.
|
|
17243
|
+
*/
|
|
17244
|
+
isPresenceOnlyChange() {
|
|
17245
|
+
return this.operations.length === 0;
|
|
17246
|
+
}
|
|
17000
17247
|
/**
|
|
17001
17248
|
* `hasChange` returns whether this context has change or not.
|
|
17002
17249
|
*/
|
|
@@ -17037,13 +17284,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17037
17284
|
*/
|
|
17038
17285
|
issueTimeTicket() {
|
|
17039
17286
|
this.delimiter += 1;
|
|
17040
|
-
return this.
|
|
17287
|
+
return this.nextID.createTimeTicket(this.delimiter);
|
|
17041
17288
|
}
|
|
17042
17289
|
/**
|
|
17043
17290
|
* `getLastTimeTicket` returns the last time ticket issued in this context.
|
|
17044
17291
|
*/
|
|
17045
17292
|
getLastTimeTicket() {
|
|
17046
|
-
return this.
|
|
17293
|
+
return this.nextID.createTimeTicket(this.delimiter);
|
|
17294
|
+
}
|
|
17295
|
+
/**
|
|
17296
|
+
* `acc` accumulates the given DataSize to Live size of the root.
|
|
17297
|
+
*/
|
|
17298
|
+
acc(diff) {
|
|
17299
|
+
this.root.acc(diff);
|
|
17047
17300
|
}
|
|
17048
17301
|
}
|
|
17049
17302
|
class CRDTRoot {
|
|
@@ -17068,10 +17321,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17068
17321
|
* element itself and its parent.
|
|
17069
17322
|
*/
|
|
17070
17323
|
__publicField(this, "gcPairMap");
|
|
17324
|
+
/**
|
|
17325
|
+
* `docSize` is a structure that represents the size of the document.
|
|
17326
|
+
*/
|
|
17327
|
+
__publicField(this, "docSize");
|
|
17071
17328
|
this.rootObject = rootObject;
|
|
17072
17329
|
this.elementPairMapByCreatedAt = /* @__PURE__ */ new Map();
|
|
17073
17330
|
this.gcElementSetByCreatedAt = /* @__PURE__ */ new Set();
|
|
17074
17331
|
this.gcPairMap = /* @__PURE__ */ new Map();
|
|
17332
|
+
this.docSize = { live: { data: 0, meta: 0 }, gc: { data: 0, meta: 0 } };
|
|
17075
17333
|
this.registerElement(rootObject, void 0);
|
|
17076
17334
|
rootObject.getDescendants((elem) => {
|
|
17077
17335
|
if (elem.getRemovedAt()) {
|
|
@@ -17148,6 +17406,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17148
17406
|
parent,
|
|
17149
17407
|
element
|
|
17150
17408
|
});
|
|
17409
|
+
addDataSizes(this.docSize.live, element.getDataSize());
|
|
17151
17410
|
if (element instanceof CRDTContainer) {
|
|
17152
17411
|
element.getDescendants((elem, parent2) => {
|
|
17153
17412
|
this.registerElement(elem, parent2);
|
|
@@ -17162,6 +17421,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17162
17421
|
let count = 0;
|
|
17163
17422
|
const deregisterElementInternal = (elem) => {
|
|
17164
17423
|
const createdAt = elem.getCreatedAt().toIDString();
|
|
17424
|
+
subDataSize(this.docSize.gc, elem.getDataSize());
|
|
17165
17425
|
this.elementPairMapByCreatedAt.delete(createdAt);
|
|
17166
17426
|
this.gcElementSetByCreatedAt.delete(createdAt);
|
|
17167
17427
|
count++;
|
|
@@ -17179,6 +17439,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17179
17439
|
* `registerRemovedElement` registers the given element to the hash set.
|
|
17180
17440
|
*/
|
|
17181
17441
|
registerRemovedElement(element) {
|
|
17442
|
+
addDataSizes(this.docSize.gc, element.getDataSize());
|
|
17443
|
+
subDataSize(this.docSize.live, element.getDataSize());
|
|
17444
|
+
this.docSize.live.meta += TimeTicketSize;
|
|
17182
17445
|
this.gcElementSetByCreatedAt.add(element.getCreatedAt().toIDString());
|
|
17183
17446
|
}
|
|
17184
17447
|
/**
|
|
@@ -17191,6 +17454,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17191
17454
|
return;
|
|
17192
17455
|
}
|
|
17193
17456
|
this.gcPairMap.set(pair.child.toIDString(), pair);
|
|
17457
|
+
const size = this.gcPairMap.get(pair.child.toIDString()).child.getDataSize();
|
|
17458
|
+
addDataSizes(this.docSize.gc, size);
|
|
17459
|
+
subDataSize(this.docSize.live, size);
|
|
17460
|
+
if (!(pair.child instanceof RHTNode)) {
|
|
17461
|
+
this.docSize.live.meta += TimeTicketSize;
|
|
17462
|
+
}
|
|
17194
17463
|
}
|
|
17195
17464
|
/**
|
|
17196
17465
|
* `getElementMapSize` returns the size of element map.
|
|
@@ -17231,22 +17500,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17231
17500
|
* `getDocSize` returns the size of the document.
|
|
17232
17501
|
*/
|
|
17233
17502
|
getDocSize() {
|
|
17234
|
-
|
|
17235
|
-
for (const [createdAt, value] of this.elementPairMapByCreatedAt) {
|
|
17236
|
-
if (this.gcElementSetByCreatedAt.has(createdAt)) {
|
|
17237
|
-
docSize.gc.data += value.element.getDataSize().data;
|
|
17238
|
-
docSize.gc.meta += value.element.getDataSize().meta;
|
|
17239
|
-
} else {
|
|
17240
|
-
docSize.live.data += value.element.getDataSize().data;
|
|
17241
|
-
docSize.live.meta += value.element.getDataSize().meta;
|
|
17242
|
-
}
|
|
17243
|
-
}
|
|
17244
|
-
for (const pair of this.gcPairMap.values()) {
|
|
17245
|
-
const size = pair.child.getDataSize();
|
|
17246
|
-
docSize.gc.data += size.data;
|
|
17247
|
-
docSize.gc.meta += size.meta;
|
|
17248
|
-
}
|
|
17249
|
-
return docSize;
|
|
17503
|
+
return this.docSize;
|
|
17250
17504
|
}
|
|
17251
17505
|
/**
|
|
17252
17506
|
* `deepcopy` copies itself deeply.
|
|
@@ -17300,6 +17554,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17300
17554
|
gcElements: this.getGarbageElementSetSize()
|
|
17301
17555
|
};
|
|
17302
17556
|
}
|
|
17557
|
+
/**
|
|
17558
|
+
* `acc` accumulates the given DataSize to Live.
|
|
17559
|
+
*/
|
|
17560
|
+
acc(diff) {
|
|
17561
|
+
addDataSizes(this.docSize.live, diff);
|
|
17562
|
+
}
|
|
17303
17563
|
}
|
|
17304
17564
|
function createJSONObject(context, target) {
|
|
17305
17565
|
const objectProxy = new ObjectProxy(context);
|
|
@@ -17917,12 +18177,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17917
18177
|
}
|
|
17918
18178
|
const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
|
|
17919
18179
|
const ticket = this.context.issueTimeTicket();
|
|
17920
|
-
const [, pairs, rangeAfterEdit] = this.text.edit(
|
|
18180
|
+
const [, pairs, diff, rangeAfterEdit] = this.text.edit(
|
|
17921
18181
|
range,
|
|
17922
18182
|
content,
|
|
17923
18183
|
ticket,
|
|
17924
18184
|
attrs
|
|
17925
18185
|
);
|
|
18186
|
+
this.context.acc(diff);
|
|
17926
18187
|
for (const pair of pairs) {
|
|
17927
18188
|
this.context.registerGCPair(pair);
|
|
17928
18189
|
}
|
|
@@ -17976,7 +18237,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17976
18237
|
}
|
|
17977
18238
|
const attrs = stringifyObjectValues(attributes);
|
|
17978
18239
|
const ticket = this.context.issueTimeTicket();
|
|
17979
|
-
const [pairs] = this.text.setStyle(range, attrs, ticket);
|
|
18240
|
+
const [pairs, diff] = this.text.setStyle(range, attrs, ticket);
|
|
18241
|
+
this.context.acc(diff);
|
|
17980
18242
|
for (const pair of pairs) {
|
|
17981
18243
|
this.context.registerGCPair(pair);
|
|
17982
18244
|
}
|
|
@@ -18519,7 +18781,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
18519
18781
|
const [fromPos, toPos] = this.tree.pathToPosRange(path);
|
|
18520
18782
|
const ticket = this.context.issueTimeTicket();
|
|
18521
18783
|
const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
|
|
18522
|
-
const [pairs] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18784
|
+
const [pairs, , diff] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18785
|
+
this.context.acc(diff);
|
|
18523
18786
|
for (const pair of pairs) {
|
|
18524
18787
|
this.context.registerGCPair(pair);
|
|
18525
18788
|
}
|
|
@@ -18553,7 +18816,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
18553
18816
|
const toPos = this.tree.findPos(toIdx);
|
|
18554
18817
|
const ticket = this.context.issueTimeTicket();
|
|
18555
18818
|
const attrs = attributes ? stringifyObjectValues(attributes) : void 0;
|
|
18556
|
-
const [pairs] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18819
|
+
const [pairs, , diff] = this.tree.style([fromPos, toPos], attrs, ticket);
|
|
18820
|
+
this.context.acc(diff);
|
|
18557
18821
|
for (const pair of pairs) {
|
|
18558
18822
|
this.context.registerGCPair(pair);
|
|
18559
18823
|
}
|
|
@@ -18586,11 +18850,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
18586
18850
|
const fromPos = this.tree.findPos(fromIdx);
|
|
18587
18851
|
const toPos = this.tree.findPos(toIdx);
|
|
18588
18852
|
const ticket = this.context.issueTimeTicket();
|
|
18589
|
-
const [pairs] = this.tree.removeStyle(
|
|
18853
|
+
const [pairs, , diff] = this.tree.removeStyle(
|
|
18590
18854
|
[fromPos, toPos],
|
|
18591
18855
|
attributesToRemove,
|
|
18592
18856
|
ticket
|
|
18593
18857
|
);
|
|
18858
|
+
this.context.acc(diff);
|
|
18594
18859
|
for (const pair of pairs) {
|
|
18595
18860
|
this.context.registerGCPair(pair);
|
|
18596
18861
|
}
|
|
@@ -18633,13 +18898,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
18633
18898
|
} else {
|
|
18634
18899
|
crdtNodes = contents.map((content) => content && createCRDTTreeNode(this.context, content)).filter((a) => a);
|
|
18635
18900
|
}
|
|
18636
|
-
const [, pairs] = this.tree.edit(
|
|
18901
|
+
const [, pairs, diff] = this.tree.edit(
|
|
18637
18902
|
[fromPos, toPos],
|
|
18638
18903
|
crdtNodes.length ? crdtNodes.map((crdtNode) => crdtNode == null ? void 0 : crdtNode.deepcopy()) : void 0,
|
|
18639
18904
|
splitLevel,
|
|
18640
18905
|
ticket,
|
|
18641
18906
|
() => this.context.issueTimeTicket()
|
|
18642
18907
|
);
|
|
18908
|
+
this.context.acc(diff);
|
|
18643
18909
|
for (const pair of pairs) {
|
|
18644
18910
|
this.context.registerGCPair(pair);
|
|
18645
18911
|
}
|
|
@@ -18972,6 +19238,43 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
18972
19238
|
}
|
|
18973
19239
|
return element;
|
|
18974
19240
|
}
|
|
19241
|
+
class Presence {
|
|
19242
|
+
constructor(changeContext, presence) {
|
|
19243
|
+
__publicField(this, "context");
|
|
19244
|
+
__publicField(this, "presence");
|
|
19245
|
+
this.context = changeContext;
|
|
19246
|
+
this.presence = presence;
|
|
19247
|
+
}
|
|
19248
|
+
/**
|
|
19249
|
+
* `set` updates the presence based on the partial presence.
|
|
19250
|
+
*/
|
|
19251
|
+
set(presence, option) {
|
|
19252
|
+
for (const key of Object.keys(presence)) {
|
|
19253
|
+
this.presence[key] = presence[key];
|
|
19254
|
+
}
|
|
19255
|
+
this.context.setPresenceChange({
|
|
19256
|
+
type: PresenceChangeType.Put,
|
|
19257
|
+
presence: deepcopy(this.presence)
|
|
19258
|
+
});
|
|
19259
|
+
this.context.setReversePresence(presence, option);
|
|
19260
|
+
}
|
|
19261
|
+
/**
|
|
19262
|
+
* `get` returns the presence value of the given key.
|
|
19263
|
+
*/
|
|
19264
|
+
get(key) {
|
|
19265
|
+
return this.presence[key];
|
|
19266
|
+
}
|
|
19267
|
+
/**
|
|
19268
|
+
* `clear` clears the presence.
|
|
19269
|
+
* @internal
|
|
19270
|
+
*/
|
|
19271
|
+
clear() {
|
|
19272
|
+
this.presence = {};
|
|
19273
|
+
this.context.setPresenceChange({
|
|
19274
|
+
type: PresenceChangeType.Clear
|
|
19275
|
+
});
|
|
19276
|
+
}
|
|
19277
|
+
}
|
|
18975
19278
|
const MaxUndoRedoStackDepth = 50;
|
|
18976
19279
|
class History {
|
|
18977
19280
|
constructor() {
|
|
@@ -19182,6 +19485,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19182
19485
|
__publicField(this, "changeID");
|
|
19183
19486
|
__publicField(this, "checkpoint");
|
|
19184
19487
|
__publicField(this, "localChanges");
|
|
19488
|
+
__publicField(this, "maxSizeLimit");
|
|
19185
19489
|
__publicField(this, "root");
|
|
19186
19490
|
__publicField(this, "clone");
|
|
19187
19491
|
__publicField(this, "eventStream");
|
|
@@ -19214,6 +19518,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19214
19518
|
this.changeID = InitialChangeID;
|
|
19215
19519
|
this.checkpoint = InitialCheckpoint;
|
|
19216
19520
|
this.localChanges = [];
|
|
19521
|
+
this.maxSizeLimit = 0;
|
|
19217
19522
|
this.eventStream = createObservable((observer) => {
|
|
19218
19523
|
this.eventStreamObserver = observer;
|
|
19219
19524
|
});
|
|
@@ -19233,13 +19538,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19233
19538
|
* `update` executes the given updater to update this document.
|
|
19234
19539
|
*/
|
|
19235
19540
|
update(updater, message) {
|
|
19541
|
+
var _a2;
|
|
19236
19542
|
if (this.getStatus() === "removed") {
|
|
19237
19543
|
throw new YorkieError(Code.ErrDocumentRemoved, `${this.key} is removed`);
|
|
19238
19544
|
}
|
|
19239
19545
|
this.ensureClone();
|
|
19240
19546
|
const actorID = this.changeID.getActorID();
|
|
19241
19547
|
const context = ChangeContext.create(
|
|
19242
|
-
this.changeID
|
|
19548
|
+
this.changeID,
|
|
19243
19549
|
this.clone.root,
|
|
19244
19550
|
this.clone.presences.get(actorID) || {},
|
|
19245
19551
|
message
|
|
@@ -19263,11 +19569,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19263
19569
|
} finally {
|
|
19264
19570
|
this.isUpdating = false;
|
|
19265
19571
|
}
|
|
19572
|
+
const size = totalDocSize((_a2 = this.clone) == null ? void 0 : _a2.root.getDocSize());
|
|
19573
|
+
if (!context.isPresenceOnlyChange() && this.maxSizeLimit > 0 && this.maxSizeLimit < size) {
|
|
19574
|
+
this.clone = void 0;
|
|
19575
|
+
throw new YorkieError(
|
|
19576
|
+
Code.ErrDocumentSizeExceedsLimit,
|
|
19577
|
+
`document size exceeded: ${size} > ${this.maxSizeLimit}`
|
|
19578
|
+
);
|
|
19579
|
+
}
|
|
19266
19580
|
if (context.hasChange()) {
|
|
19267
19581
|
if (logger.isEnabled(LogLevel.Trivial)) {
|
|
19268
19582
|
logger.trivial(`trying to update a local change: ${this.toJSON()}`);
|
|
19269
19583
|
}
|
|
19270
|
-
const change = context.
|
|
19584
|
+
const change = context.toChange();
|
|
19271
19585
|
const { opInfos, reverseOps } = change.execute(
|
|
19272
19586
|
this.root,
|
|
19273
19587
|
this.presences,
|
|
@@ -19287,7 +19601,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19287
19601
|
if (opInfos.length > 0) {
|
|
19288
19602
|
this.internalHistory.clearRedo();
|
|
19289
19603
|
}
|
|
19290
|
-
this.changeID =
|
|
19604
|
+
this.changeID = context.getNextID();
|
|
19291
19605
|
const event = [];
|
|
19292
19606
|
if (opInfos.length > 0) {
|
|
19293
19607
|
event.push({
|
|
@@ -19657,7 +19971,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19657
19971
|
return this.status;
|
|
19658
19972
|
}
|
|
19659
19973
|
/**
|
|
19660
|
-
* `getClone`
|
|
19974
|
+
* `getClone` returns this clone.
|
|
19975
|
+
*/
|
|
19976
|
+
getClone() {
|
|
19977
|
+
return this.clone;
|
|
19978
|
+
}
|
|
19979
|
+
/**
|
|
19980
|
+
* `getCloneRoot` returns clone object.
|
|
19661
19981
|
*
|
|
19662
19982
|
* @internal
|
|
19663
19983
|
*/
|
|
@@ -19685,6 +20005,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19685
20005
|
getDocSize() {
|
|
19686
20006
|
return this.root.getDocSize();
|
|
19687
20007
|
}
|
|
20008
|
+
/**
|
|
20009
|
+
* `getMaxSizePerDocument` gets the maximum size of this document.
|
|
20010
|
+
*/
|
|
20011
|
+
getMaxSizePerDocument() {
|
|
20012
|
+
return this.maxSizeLimit;
|
|
20013
|
+
}
|
|
20014
|
+
/**
|
|
20015
|
+
* `setMaxSizePerDocument` sets the maximum size of this document.
|
|
20016
|
+
*/
|
|
20017
|
+
setMaxSizePerDocument(size) {
|
|
20018
|
+
this.maxSizeLimit = size;
|
|
20019
|
+
}
|
|
19688
20020
|
/**
|
|
19689
20021
|
* `garbageCollect` purges elements that were removed before the given time.
|
|
19690
20022
|
*
|
|
@@ -20156,14 +20488,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20156
20488
|
canUndo() {
|
|
20157
20489
|
return this.internalHistory.hasUndo() && !this.isUpdating;
|
|
20158
20490
|
}
|
|
20159
|
-
/**
|
|
20160
|
-
* 'filterVersionVector' filters detached client's lamport from version vector.
|
|
20161
|
-
*/
|
|
20162
|
-
filterVersionVector(minSyncedVersionVector) {
|
|
20163
|
-
const versionVector = this.changeID.getVersionVector();
|
|
20164
|
-
const filteredVersionVector = versionVector.filter(minSyncedVersionVector);
|
|
20165
|
-
this.changeID = this.changeID.setVersionVector(filteredVersionVector);
|
|
20166
|
-
}
|
|
20167
20491
|
/**
|
|
20168
20492
|
* `canRedo` returns whether there are any operations to redo.
|
|
20169
20493
|
*/
|
|
@@ -20190,7 +20514,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20190
20514
|
}
|
|
20191
20515
|
this.ensureClone();
|
|
20192
20516
|
const context = ChangeContext.create(
|
|
20193
|
-
this.changeID
|
|
20517
|
+
this.changeID,
|
|
20194
20518
|
this.clone.root,
|
|
20195
20519
|
this.clone.presences.get(this.changeID.getActorID()) || {}
|
|
20196
20520
|
);
|
|
@@ -20207,7 +20531,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20207
20531
|
undoOp.setExecutedAt(ticket);
|
|
20208
20532
|
context.push(undoOp);
|
|
20209
20533
|
}
|
|
20210
|
-
const change = context.
|
|
20534
|
+
const change = context.toChange();
|
|
20211
20535
|
change.execute(this.clone.root, this.clone.presences, OpSource.UndoRedo);
|
|
20212
20536
|
const { opInfos, reverseOps } = change.execute(
|
|
20213
20537
|
this.root,
|
|
@@ -20228,7 +20552,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20228
20552
|
return;
|
|
20229
20553
|
}
|
|
20230
20554
|
this.localChanges.push(change);
|
|
20231
|
-
this.changeID =
|
|
20555
|
+
this.changeID = context.getNextID();
|
|
20232
20556
|
const actorID = this.changeID.getActorID();
|
|
20233
20557
|
const event = [];
|
|
20234
20558
|
if (opInfos.length > 0) {
|
|
@@ -20277,7 +20601,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20277
20601
|
}
|
|
20278
20602
|
this.ensureClone();
|
|
20279
20603
|
const context = ChangeContext.create(
|
|
20280
|
-
this.changeID
|
|
20604
|
+
this.changeID,
|
|
20281
20605
|
this.clone.root,
|
|
20282
20606
|
this.clone.presences.get(this.changeID.getActorID()) || {}
|
|
20283
20607
|
);
|
|
@@ -20294,7 +20618,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20294
20618
|
redoOp.setExecutedAt(ticket);
|
|
20295
20619
|
context.push(redoOp);
|
|
20296
20620
|
}
|
|
20297
|
-
const change = context.
|
|
20621
|
+
const change = context.toChange();
|
|
20298
20622
|
change.execute(this.clone.root, this.clone.presences, OpSource.UndoRedo);
|
|
20299
20623
|
const { opInfos, reverseOps } = change.execute(
|
|
20300
20624
|
this.root,
|
|
@@ -20315,7 +20639,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20315
20639
|
return;
|
|
20316
20640
|
}
|
|
20317
20641
|
this.localChanges.push(change);
|
|
20318
|
-
this.changeID =
|
|
20642
|
+
this.changeID = context.getNextID();
|
|
20319
20643
|
const actorID = this.changeID.getActorID();
|
|
20320
20644
|
const event = [];
|
|
20321
20645
|
if (opInfos.length > 0) {
|
|
@@ -20394,7 +20718,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20394
20718
|
};
|
|
20395
20719
|
}
|
|
20396
20720
|
const name = "@yorkie-js/sdk";
|
|
20397
|
-
const version = "0.6.
|
|
20721
|
+
const version = "0.6.13";
|
|
20398
20722
|
const pkg = {
|
|
20399
20723
|
name,
|
|
20400
20724
|
version
|
|
@@ -20562,16 +20886,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20562
20886
|
if (this.status === "deactivated") {
|
|
20563
20887
|
return Promise.resolve();
|
|
20564
20888
|
}
|
|
20565
|
-
this.deactivateInternal();
|
|
20566
20889
|
const task = async () => {
|
|
20567
20890
|
try {
|
|
20568
20891
|
await this.rpcClient.deactivateClient(
|
|
20569
20892
|
{ clientId: this.id },
|
|
20570
20893
|
{ headers: { "x-shard-key": this.apiKey } }
|
|
20571
20894
|
);
|
|
20895
|
+
this.deactivateInternal();
|
|
20572
20896
|
logger.info(`[DC] c"${this.getKey()}" deactivated`);
|
|
20573
20897
|
} catch (err) {
|
|
20574
|
-
this.status = "activated";
|
|
20575
20898
|
logger.error(`[DC] c:"${this.getKey()}" err :`, err);
|
|
20576
20899
|
await this.handleConnectError(err);
|
|
20577
20900
|
throw err;
|
|
@@ -20635,6 +20958,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20635
20958
|
},
|
|
20636
20959
|
{ headers: { "x-shard-key": `${this.apiKey}/${doc.getKey()}` } }
|
|
20637
20960
|
);
|
|
20961
|
+
const maxSize = res.maxSizePerDocument ?? 0;
|
|
20962
|
+
if (maxSize > 0) {
|
|
20963
|
+
doc.setMaxSizePerDocument(res.maxSizePerDocument);
|
|
20964
|
+
}
|
|
20638
20965
|
const pack = converter.fromChangePack(res.changePack);
|
|
20639
20966
|
doc.applyChangePack(pack);
|
|
20640
20967
|
if (doc.getStatus() === DocStatus.Removed) {
|
|
@@ -20655,12 +20982,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20655
20982
|
await this.runWatchLoop(doc.getKey());
|
|
20656
20983
|
}
|
|
20657
20984
|
logger.info(`[AD] c:"${this.getKey()}" attaches d:"${doc.getKey()}"`);
|
|
20658
|
-
const
|
|
20985
|
+
const crdtObject = doc.getRootObject();
|
|
20659
20986
|
if (opts.initialRoot) {
|
|
20660
20987
|
const initialRoot = opts.initialRoot;
|
|
20661
20988
|
doc.update((root) => {
|
|
20662
20989
|
for (const [k, v] of Object.entries(initialRoot)) {
|
|
20663
|
-
if (!
|
|
20990
|
+
if (!crdtObject.has(k)) {
|
|
20664
20991
|
const key = k;
|
|
20665
20992
|
root[key] = v;
|
|
20666
20993
|
}
|
|
@@ -20683,7 +21010,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20683
21010
|
* the changes should be applied to other replicas before GC time. For this,
|
|
20684
21011
|
* if the document is no longer used by this client, it should be detached.
|
|
20685
21012
|
*/
|
|
20686
|
-
detach(doc, opts = {
|
|
21013
|
+
detach(doc, opts = { keepalive: false }) {
|
|
20687
21014
|
if (!this.isActive()) {
|
|
20688
21015
|
throw new YorkieError(
|
|
20689
21016
|
Code.ErrClientNotActivated,
|
|
@@ -20698,14 +21025,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20698
21025
|
);
|
|
20699
21026
|
}
|
|
20700
21027
|
doc.update((_, p) => p.clear());
|
|
20701
|
-
|
|
21028
|
+
const task = async () => {
|
|
20702
21029
|
try {
|
|
20703
21030
|
const res = await this.rpcClient.detachDocument(
|
|
20704
21031
|
{
|
|
20705
21032
|
clientId: this.id,
|
|
20706
21033
|
documentId: attachment.docID,
|
|
20707
21034
|
changePack: converter.toChangePack(doc.createChangePack()),
|
|
20708
|
-
removeIfNotAttached: opts.removeIfNotAttached
|
|
21035
|
+
removeIfNotAttached: opts.removeIfNotAttached ?? false
|
|
20709
21036
|
},
|
|
20710
21037
|
{ headers: { "x-shard-key": `${this.apiKey}/${doc.getKey()}` } }
|
|
20711
21038
|
);
|
|
@@ -20722,7 +21049,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20722
21049
|
await this.handleConnectError(err);
|
|
20723
21050
|
throw err;
|
|
20724
21051
|
}
|
|
20725
|
-
}
|
|
21052
|
+
};
|
|
21053
|
+
if (opts.keepalive) {
|
|
21054
|
+
this.keepalive = true;
|
|
21055
|
+
const resp = task();
|
|
21056
|
+
this.keepalive = false;
|
|
21057
|
+
return resp;
|
|
21058
|
+
}
|
|
21059
|
+
return this.enqueueTask(task);
|
|
20726
21060
|
}
|
|
20727
21061
|
/**
|
|
20728
21062
|
* `changeRealtimeSync` changes the synchronization mode of the given document.
|