@yorkie-js/react 0.6.17 → 0.6.20
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-react.es.js +466 -93
- package/dist/yorkie-js-react.es.js.map +1 -1
- package/dist/yorkie-js-react.js +466 -93
- package/dist/yorkie-js-react.js.map +1 -1
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
import { createContext, useMemo, useState, useEffect, useContext, useCallback } from "react";
|
|
7
7
|
const name$1 = "@yorkie-js/react";
|
|
8
|
-
const version$1 = "0.6.
|
|
8
|
+
const version$1 = "0.6.20";
|
|
9
9
|
const pkg$1 = {
|
|
10
10
|
name: name$1,
|
|
11
11
|
version: version$1
|
|
@@ -6456,6 +6456,10 @@ const _DocumentSummary = class _DocumentSummary extends Message {
|
|
|
6456
6456
|
* @generated from field: yorkie.v1.DocSize document_size = 8;
|
|
6457
6457
|
*/
|
|
6458
6458
|
__publicField(this, "documentSize");
|
|
6459
|
+
/**
|
|
6460
|
+
* @generated from field: string schema_key = 9;
|
|
6461
|
+
*/
|
|
6462
|
+
__publicField(this, "schemaKey", "");
|
|
6459
6463
|
/**
|
|
6460
6464
|
* @generated from field: google.protobuf.Timestamp created_at = 4;
|
|
6461
6465
|
*/
|
|
@@ -6515,6 +6519,13 @@ __publicField(_DocumentSummary, "fields", proto3.util.newFieldList(() => [
|
|
|
6515
6519
|
/* ScalarType.INT32 */
|
|
6516
6520
|
},
|
|
6517
6521
|
{ no: 8, name: "document_size", kind: "message", T: DocSize },
|
|
6522
|
+
{
|
|
6523
|
+
no: 9,
|
|
6524
|
+
name: "schema_key",
|
|
6525
|
+
kind: "scalar",
|
|
6526
|
+
T: 9
|
|
6527
|
+
/* ScalarType.STRING */
|
|
6528
|
+
},
|
|
6518
6529
|
{ no: 4, name: "created_at", kind: "message", T: Timestamp },
|
|
6519
6530
|
{ no: 5, name: "accessed_at", kind: "message", T: Timestamp },
|
|
6520
6531
|
{ no: 6, name: "updated_at", kind: "message", T: Timestamp }
|
|
@@ -6570,9 +6581,9 @@ let Presence$1 = (_g = class extends Message {
|
|
|
6570
6581
|
constructor(data) {
|
|
6571
6582
|
super();
|
|
6572
6583
|
/**
|
|
6573
|
-
* @generated from field:
|
|
6584
|
+
* @generated from field: map<string, string> data = 1;
|
|
6574
6585
|
*/
|
|
6575
|
-
__publicField(this, "data",
|
|
6586
|
+
__publicField(this, "data", {});
|
|
6576
6587
|
proto3.util.initPartial(data, this);
|
|
6577
6588
|
}
|
|
6578
6589
|
static fromBinary(bytes, options) {
|
|
@@ -6588,7 +6599,11 @@ let Presence$1 = (_g = class extends Message {
|
|
|
6588
6599
|
return proto3.util.equals(_g, a, b);
|
|
6589
6600
|
}
|
|
6590
6601
|
}, __publicField(_g, "runtime", proto3), __publicField(_g, "typeName", "yorkie.v1.Presence"), __publicField(_g, "fields", proto3.util.newFieldList(() => [
|
|
6591
|
-
{ no: 1, name: "data", kind: "
|
|
6602
|
+
{ no: 1, name: "data", kind: "map", K: 9, V: {
|
|
6603
|
+
kind: "scalar",
|
|
6604
|
+
T: 9
|
|
6605
|
+
/* ScalarType.STRING */
|
|
6606
|
+
} }
|
|
6592
6607
|
])), _g);
|
|
6593
6608
|
let Checkpoint$1 = (_h = class extends Message {
|
|
6594
6609
|
constructor(data) {
|
|
@@ -6900,6 +6915,128 @@ __publicField(_DocSize, "fields", proto3.util.newFieldList(() => [
|
|
|
6900
6915
|
{ no: 2, name: "gc", kind: "message", T: DataSize }
|
|
6901
6916
|
]));
|
|
6902
6917
|
let DocSize = _DocSize;
|
|
6918
|
+
const _Schema = class _Schema extends Message {
|
|
6919
|
+
constructor(data) {
|
|
6920
|
+
super();
|
|
6921
|
+
/**
|
|
6922
|
+
* @generated from field: string id = 1;
|
|
6923
|
+
*/
|
|
6924
|
+
__publicField(this, "id", "");
|
|
6925
|
+
/**
|
|
6926
|
+
* @generated from field: string name = 2;
|
|
6927
|
+
*/
|
|
6928
|
+
__publicField(this, "name", "");
|
|
6929
|
+
/**
|
|
6930
|
+
* @generated from field: int32 version = 3;
|
|
6931
|
+
*/
|
|
6932
|
+
__publicField(this, "version", 0);
|
|
6933
|
+
/**
|
|
6934
|
+
* @generated from field: string body = 4;
|
|
6935
|
+
*/
|
|
6936
|
+
__publicField(this, "body", "");
|
|
6937
|
+
/**
|
|
6938
|
+
* @generated from field: repeated yorkie.v1.Rule rules = 5;
|
|
6939
|
+
*/
|
|
6940
|
+
__publicField(this, "rules", []);
|
|
6941
|
+
/**
|
|
6942
|
+
* @generated from field: google.protobuf.Timestamp created_at = 6;
|
|
6943
|
+
*/
|
|
6944
|
+
__publicField(this, "createdAt");
|
|
6945
|
+
proto3.util.initPartial(data, this);
|
|
6946
|
+
}
|
|
6947
|
+
static fromBinary(bytes, options) {
|
|
6948
|
+
return new _Schema().fromBinary(bytes, options);
|
|
6949
|
+
}
|
|
6950
|
+
static fromJson(jsonValue, options) {
|
|
6951
|
+
return new _Schema().fromJson(jsonValue, options);
|
|
6952
|
+
}
|
|
6953
|
+
static fromJsonString(jsonString, options) {
|
|
6954
|
+
return new _Schema().fromJsonString(jsonString, options);
|
|
6955
|
+
}
|
|
6956
|
+
static equals(a, b) {
|
|
6957
|
+
return proto3.util.equals(_Schema, a, b);
|
|
6958
|
+
}
|
|
6959
|
+
};
|
|
6960
|
+
__publicField(_Schema, "runtime", proto3);
|
|
6961
|
+
__publicField(_Schema, "typeName", "yorkie.v1.Schema");
|
|
6962
|
+
__publicField(_Schema, "fields", proto3.util.newFieldList(() => [
|
|
6963
|
+
{
|
|
6964
|
+
no: 1,
|
|
6965
|
+
name: "id",
|
|
6966
|
+
kind: "scalar",
|
|
6967
|
+
T: 9
|
|
6968
|
+
/* ScalarType.STRING */
|
|
6969
|
+
},
|
|
6970
|
+
{
|
|
6971
|
+
no: 2,
|
|
6972
|
+
name: "name",
|
|
6973
|
+
kind: "scalar",
|
|
6974
|
+
T: 9
|
|
6975
|
+
/* ScalarType.STRING */
|
|
6976
|
+
},
|
|
6977
|
+
{
|
|
6978
|
+
no: 3,
|
|
6979
|
+
name: "version",
|
|
6980
|
+
kind: "scalar",
|
|
6981
|
+
T: 5
|
|
6982
|
+
/* ScalarType.INT32 */
|
|
6983
|
+
},
|
|
6984
|
+
{
|
|
6985
|
+
no: 4,
|
|
6986
|
+
name: "body",
|
|
6987
|
+
kind: "scalar",
|
|
6988
|
+
T: 9
|
|
6989
|
+
/* ScalarType.STRING */
|
|
6990
|
+
},
|
|
6991
|
+
{ no: 5, name: "rules", kind: "message", T: Rule, repeated: true },
|
|
6992
|
+
{ no: 6, name: "created_at", kind: "message", T: Timestamp }
|
|
6993
|
+
]));
|
|
6994
|
+
let Schema = _Schema;
|
|
6995
|
+
const _Rule = class _Rule extends Message {
|
|
6996
|
+
constructor(data) {
|
|
6997
|
+
super();
|
|
6998
|
+
/**
|
|
6999
|
+
* @generated from field: string path = 1;
|
|
7000
|
+
*/
|
|
7001
|
+
__publicField(this, "path", "");
|
|
7002
|
+
/**
|
|
7003
|
+
* @generated from field: string type = 2;
|
|
7004
|
+
*/
|
|
7005
|
+
__publicField(this, "type", "");
|
|
7006
|
+
proto3.util.initPartial(data, this);
|
|
7007
|
+
}
|
|
7008
|
+
static fromBinary(bytes, options) {
|
|
7009
|
+
return new _Rule().fromBinary(bytes, options);
|
|
7010
|
+
}
|
|
7011
|
+
static fromJson(jsonValue, options) {
|
|
7012
|
+
return new _Rule().fromJson(jsonValue, options);
|
|
7013
|
+
}
|
|
7014
|
+
static fromJsonString(jsonString, options) {
|
|
7015
|
+
return new _Rule().fromJsonString(jsonString, options);
|
|
7016
|
+
}
|
|
7017
|
+
static equals(a, b) {
|
|
7018
|
+
return proto3.util.equals(_Rule, a, b);
|
|
7019
|
+
}
|
|
7020
|
+
};
|
|
7021
|
+
__publicField(_Rule, "runtime", proto3);
|
|
7022
|
+
__publicField(_Rule, "typeName", "yorkie.v1.Rule");
|
|
7023
|
+
__publicField(_Rule, "fields", proto3.util.newFieldList(() => [
|
|
7024
|
+
{
|
|
7025
|
+
no: 1,
|
|
7026
|
+
name: "path",
|
|
7027
|
+
kind: "scalar",
|
|
7028
|
+
T: 9
|
|
7029
|
+
/* ScalarType.STRING */
|
|
7030
|
+
},
|
|
7031
|
+
{
|
|
7032
|
+
no: 2,
|
|
7033
|
+
name: "type",
|
|
7034
|
+
kind: "scalar",
|
|
7035
|
+
T: 9
|
|
7036
|
+
/* ScalarType.STRING */
|
|
7037
|
+
}
|
|
7038
|
+
]));
|
|
7039
|
+
let Rule = _Rule;
|
|
6903
7040
|
const _ActivateClientRequest = class _ActivateClientRequest extends Message {
|
|
6904
7041
|
constructor(data) {
|
|
6905
7042
|
super();
|
|
@@ -7044,6 +7181,10 @@ const _AttachDocumentRequest = class _AttachDocumentRequest extends Message {
|
|
|
7044
7181
|
* @generated from field: yorkie.v1.ChangePack change_pack = 2;
|
|
7045
7182
|
*/
|
|
7046
7183
|
__publicField(this, "changePack");
|
|
7184
|
+
/**
|
|
7185
|
+
* @generated from field: string schema_key = 3;
|
|
7186
|
+
*/
|
|
7187
|
+
__publicField(this, "schemaKey", "");
|
|
7047
7188
|
proto3.util.initPartial(data, this);
|
|
7048
7189
|
}
|
|
7049
7190
|
static fromBinary(bytes, options) {
|
|
@@ -7069,7 +7210,14 @@ __publicField(_AttachDocumentRequest, "fields", proto3.util.newFieldList(() => [
|
|
|
7069
7210
|
T: 9
|
|
7070
7211
|
/* ScalarType.STRING */
|
|
7071
7212
|
},
|
|
7072
|
-
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 }
|
|
7213
|
+
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 },
|
|
7214
|
+
{
|
|
7215
|
+
no: 3,
|
|
7216
|
+
name: "schema_key",
|
|
7217
|
+
kind: "scalar",
|
|
7218
|
+
T: 9
|
|
7219
|
+
/* ScalarType.STRING */
|
|
7220
|
+
}
|
|
7073
7221
|
]));
|
|
7074
7222
|
let AttachDocumentRequest = _AttachDocumentRequest;
|
|
7075
7223
|
const _AttachDocumentResponse = class _AttachDocumentResponse extends Message {
|
|
@@ -7079,14 +7227,18 @@ const _AttachDocumentResponse = class _AttachDocumentResponse extends Message {
|
|
|
7079
7227
|
* @generated from field: string document_id = 1;
|
|
7080
7228
|
*/
|
|
7081
7229
|
__publicField(this, "documentId", "");
|
|
7230
|
+
/**
|
|
7231
|
+
* @generated from field: yorkie.v1.ChangePack change_pack = 2;
|
|
7232
|
+
*/
|
|
7233
|
+
__publicField(this, "changePack");
|
|
7082
7234
|
/**
|
|
7083
7235
|
* @generated from field: int32 max_size_per_document = 3;
|
|
7084
7236
|
*/
|
|
7085
7237
|
__publicField(this, "maxSizePerDocument", 0);
|
|
7086
7238
|
/**
|
|
7087
|
-
* @generated from field: yorkie.v1.
|
|
7239
|
+
* @generated from field: repeated yorkie.v1.Rule schema_rules = 4;
|
|
7088
7240
|
*/
|
|
7089
|
-
__publicField(this, "
|
|
7241
|
+
__publicField(this, "schemaRules", []);
|
|
7090
7242
|
proto3.util.initPartial(data, this);
|
|
7091
7243
|
}
|
|
7092
7244
|
static fromBinary(bytes, options) {
|
|
@@ -7112,6 +7264,7 @@ __publicField(_AttachDocumentResponse, "fields", proto3.util.newFieldList(() =>
|
|
|
7112
7264
|
T: 9
|
|
7113
7265
|
/* ScalarType.STRING */
|
|
7114
7266
|
},
|
|
7267
|
+
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 },
|
|
7115
7268
|
{
|
|
7116
7269
|
no: 3,
|
|
7117
7270
|
name: "max_size_per_document",
|
|
@@ -7119,7 +7272,7 @@ __publicField(_AttachDocumentResponse, "fields", proto3.util.newFieldList(() =>
|
|
|
7119
7272
|
T: 5
|
|
7120
7273
|
/* ScalarType.INT32 */
|
|
7121
7274
|
},
|
|
7122
|
-
{ no:
|
|
7275
|
+
{ no: 4, name: "schema_rules", kind: "message", T: Rule, repeated: true }
|
|
7123
7276
|
]));
|
|
7124
7277
|
let AttachDocumentResponse = _AttachDocumentResponse;
|
|
7125
7278
|
const _DetachDocumentRequest = class _DetachDocumentRequest extends Message {
|
|
@@ -7890,6 +8043,7 @@ var Code = /* @__PURE__ */ ((Code2) => {
|
|
|
7890
8043
|
Code2["ErrDocumentNotDetached"] = "ErrDocumentNotDetached";
|
|
7891
8044
|
Code2["ErrDocumentRemoved"] = "ErrDocumentRemoved";
|
|
7892
8045
|
Code2["ErrDocumentSizeExceedsLimit"] = "ErrDocumentSizeExceedsLimit";
|
|
8046
|
+
Code2["ErrDocumentSchemaValidationFailed"] = "ErrDocumentSchemaValidationFailed";
|
|
7893
8047
|
Code2["ErrInvalidObjectKey"] = "ErrInvalidObjectKey";
|
|
7894
8048
|
Code2["ErrInvalidArgument"] = "ErrInvalidArgument";
|
|
7895
8049
|
Code2["ErrNotInitialized"] = "ErrNotInitialized";
|
|
@@ -10501,8 +10655,8 @@ class CRDTArray extends CRDTContainer {
|
|
|
10501
10655
|
/**
|
|
10502
10656
|
* `insertAfter` adds a new node after the the given node.
|
|
10503
10657
|
*/
|
|
10504
|
-
insertAfter(prevCreatedAt, value) {
|
|
10505
|
-
this.elements.insertAfter(prevCreatedAt, value);
|
|
10658
|
+
insertAfter(prevCreatedAt, value, executedAt) {
|
|
10659
|
+
this.elements.insertAfter(prevCreatedAt, value, executedAt);
|
|
10506
10660
|
}
|
|
10507
10661
|
/**
|
|
10508
10662
|
* `moveAfter` moves the given `createdAt` element after the `prevCreatedAt`.
|
|
@@ -10670,6 +10824,84 @@ class CRDTArray extends CRDTContainer {
|
|
|
10670
10824
|
return clone;
|
|
10671
10825
|
}
|
|
10672
10826
|
}
|
|
10827
|
+
class AddOperation extends Operation {
|
|
10828
|
+
constructor(parentCreatedAt, prevCreatedAt, value, executedAt) {
|
|
10829
|
+
super(parentCreatedAt, executedAt);
|
|
10830
|
+
__publicField(this, "prevCreatedAt");
|
|
10831
|
+
__publicField(this, "value");
|
|
10832
|
+
this.prevCreatedAt = prevCreatedAt;
|
|
10833
|
+
this.value = value;
|
|
10834
|
+
}
|
|
10835
|
+
/**
|
|
10836
|
+
* `create` creates a new instance of AddOperation.
|
|
10837
|
+
*/
|
|
10838
|
+
static create(parentCreatedAt, prevCreatedAt, value, executedAt) {
|
|
10839
|
+
return new AddOperation(parentCreatedAt, prevCreatedAt, value, executedAt);
|
|
10840
|
+
}
|
|
10841
|
+
/**
|
|
10842
|
+
* `execute` executes this operation on the given `CRDTRoot`.
|
|
10843
|
+
*/
|
|
10844
|
+
execute(root) {
|
|
10845
|
+
const parentObject = root.findByCreatedAt(this.getParentCreatedAt());
|
|
10846
|
+
if (!parentObject) {
|
|
10847
|
+
throw new YorkieError(
|
|
10848
|
+
Code.ErrInvalidArgument,
|
|
10849
|
+
`fail to find ${this.getParentCreatedAt()}`
|
|
10850
|
+
);
|
|
10851
|
+
}
|
|
10852
|
+
if (!(parentObject instanceof CRDTArray)) {
|
|
10853
|
+
throw new YorkieError(
|
|
10854
|
+
Code.ErrInvalidArgument,
|
|
10855
|
+
`fail to execute, only array can execute add`
|
|
10856
|
+
);
|
|
10857
|
+
}
|
|
10858
|
+
const array = parentObject;
|
|
10859
|
+
const value = this.value.deepcopy();
|
|
10860
|
+
array.insertAfter(this.prevCreatedAt, value, this.getExecutedAt());
|
|
10861
|
+
root.registerElement(value, array);
|
|
10862
|
+
return {
|
|
10863
|
+
opInfos: [
|
|
10864
|
+
{
|
|
10865
|
+
type: "add",
|
|
10866
|
+
path: root.createPath(this.getParentCreatedAt()),
|
|
10867
|
+
index: Number(array.subPathOf(this.getEffectedCreatedAt()))
|
|
10868
|
+
}
|
|
10869
|
+
],
|
|
10870
|
+
reverseOp: this.toReverseOperation()
|
|
10871
|
+
};
|
|
10872
|
+
}
|
|
10873
|
+
toReverseOperation() {
|
|
10874
|
+
const reverseOp = RemoveOperation.create(
|
|
10875
|
+
this.getParentCreatedAt(),
|
|
10876
|
+
this.value.getCreatedAt()
|
|
10877
|
+
);
|
|
10878
|
+
return reverseOp;
|
|
10879
|
+
}
|
|
10880
|
+
/**
|
|
10881
|
+
* `getEffectedCreatedAt` returns the creation time of the effected element.
|
|
10882
|
+
*/
|
|
10883
|
+
getEffectedCreatedAt() {
|
|
10884
|
+
return this.value.getCreatedAt();
|
|
10885
|
+
}
|
|
10886
|
+
/**
|
|
10887
|
+
* `toTestString` returns a string containing the meta data.
|
|
10888
|
+
*/
|
|
10889
|
+
toTestString() {
|
|
10890
|
+
return `${this.getParentCreatedAt().toTestString()}.ADD.${this.value.toJSON()}`;
|
|
10891
|
+
}
|
|
10892
|
+
/**
|
|
10893
|
+
* `getPrevCreatedAt` returns the creation time of previous element.
|
|
10894
|
+
*/
|
|
10895
|
+
getPrevCreatedAt() {
|
|
10896
|
+
return this.prevCreatedAt;
|
|
10897
|
+
}
|
|
10898
|
+
/**
|
|
10899
|
+
* `getValue` returns the value of this operation.
|
|
10900
|
+
*/
|
|
10901
|
+
getValue() {
|
|
10902
|
+
return this.value;
|
|
10903
|
+
}
|
|
10904
|
+
}
|
|
10673
10905
|
class RemoveOperation extends Operation {
|
|
10674
10906
|
constructor(parentCreatedAt, createdAt, executedAt) {
|
|
10675
10907
|
super(parentCreatedAt, executedAt);
|
|
@@ -10734,6 +10966,19 @@ class RemoveOperation extends Operation {
|
|
|
10734
10966
|
* `toReverseOperation` returns the reverse operation of this operation.
|
|
10735
10967
|
*/
|
|
10736
10968
|
toReverseOperation(parentObject) {
|
|
10969
|
+
if (parentObject instanceof CRDTArray) {
|
|
10970
|
+
const value = parentObject.getByID(this.createdAt);
|
|
10971
|
+
if (value !== void 0) {
|
|
10972
|
+
const prevCreatedAt = parentObject.getPrevCreatedAt(
|
|
10973
|
+
this.createdAt
|
|
10974
|
+
);
|
|
10975
|
+
return AddOperation.create(
|
|
10976
|
+
this.getParentCreatedAt(),
|
|
10977
|
+
prevCreatedAt,
|
|
10978
|
+
value.deepcopy()
|
|
10979
|
+
);
|
|
10980
|
+
}
|
|
10981
|
+
}
|
|
10737
10982
|
if (parentObject instanceof CRDTObject) {
|
|
10738
10983
|
const key = parentObject.subPathOf(this.createdAt);
|
|
10739
10984
|
if (key !== void 0) {
|
|
@@ -10872,76 +11117,6 @@ class SetOperation extends Operation {
|
|
|
10872
11117
|
return this.value;
|
|
10873
11118
|
}
|
|
10874
11119
|
}
|
|
10875
|
-
class AddOperation extends Operation {
|
|
10876
|
-
constructor(parentCreatedAt, prevCreatedAt, value, executedAt) {
|
|
10877
|
-
super(parentCreatedAt, executedAt);
|
|
10878
|
-
__publicField(this, "prevCreatedAt");
|
|
10879
|
-
__publicField(this, "value");
|
|
10880
|
-
this.prevCreatedAt = prevCreatedAt;
|
|
10881
|
-
this.value = value;
|
|
10882
|
-
}
|
|
10883
|
-
/**
|
|
10884
|
-
* `create` creates a new instance of AddOperation.
|
|
10885
|
-
*/
|
|
10886
|
-
static create(parentCreatedAt, prevCreatedAt, value, executedAt) {
|
|
10887
|
-
return new AddOperation(parentCreatedAt, prevCreatedAt, value, executedAt);
|
|
10888
|
-
}
|
|
10889
|
-
/**
|
|
10890
|
-
* `execute` executes this operation on the given `CRDTRoot`.
|
|
10891
|
-
*/
|
|
10892
|
-
execute(root) {
|
|
10893
|
-
const parentObject = root.findByCreatedAt(this.getParentCreatedAt());
|
|
10894
|
-
if (!parentObject) {
|
|
10895
|
-
throw new YorkieError(
|
|
10896
|
-
Code.ErrInvalidArgument,
|
|
10897
|
-
`fail to find ${this.getParentCreatedAt()}`
|
|
10898
|
-
);
|
|
10899
|
-
}
|
|
10900
|
-
if (!(parentObject instanceof CRDTArray)) {
|
|
10901
|
-
throw new YorkieError(
|
|
10902
|
-
Code.ErrInvalidArgument,
|
|
10903
|
-
`fail to execute, only array can execute add`
|
|
10904
|
-
);
|
|
10905
|
-
}
|
|
10906
|
-
const array = parentObject;
|
|
10907
|
-
const value = this.value.deepcopy();
|
|
10908
|
-
array.insertAfter(this.prevCreatedAt, value);
|
|
10909
|
-
root.registerElement(value, array);
|
|
10910
|
-
return {
|
|
10911
|
-
opInfos: [
|
|
10912
|
-
{
|
|
10913
|
-
type: "add",
|
|
10914
|
-
path: root.createPath(this.getParentCreatedAt()),
|
|
10915
|
-
index: Number(array.subPathOf(this.getEffectedCreatedAt()))
|
|
10916
|
-
}
|
|
10917
|
-
]
|
|
10918
|
-
};
|
|
10919
|
-
}
|
|
10920
|
-
/**
|
|
10921
|
-
* `getEffectedCreatedAt` returns the creation time of the effected element.
|
|
10922
|
-
*/
|
|
10923
|
-
getEffectedCreatedAt() {
|
|
10924
|
-
return this.value.getCreatedAt();
|
|
10925
|
-
}
|
|
10926
|
-
/**
|
|
10927
|
-
* `toTestString` returns a string containing the meta data.
|
|
10928
|
-
*/
|
|
10929
|
-
toTestString() {
|
|
10930
|
-
return `${this.getParentCreatedAt().toTestString()}.ADD.${this.value.toJSON()}`;
|
|
10931
|
-
}
|
|
10932
|
-
/**
|
|
10933
|
-
* `getPrevCreatedAt` returns the creation time of previous element.
|
|
10934
|
-
*/
|
|
10935
|
-
getPrevCreatedAt() {
|
|
10936
|
-
return this.prevCreatedAt;
|
|
10937
|
-
}
|
|
10938
|
-
/**
|
|
10939
|
-
* `getValue` returns the value of this operation.
|
|
10940
|
-
*/
|
|
10941
|
-
getValue() {
|
|
10942
|
-
return this.value;
|
|
10943
|
-
}
|
|
10944
|
-
}
|
|
10945
11120
|
class MoveOperation extends Operation {
|
|
10946
11121
|
constructor(parentCreatedAt, prevCreatedAt, createdAt, executedAt) {
|
|
10947
11122
|
super(parentCreatedAt, executedAt);
|
|
@@ -10979,6 +11154,7 @@ class MoveOperation extends Operation {
|
|
|
10979
11154
|
);
|
|
10980
11155
|
}
|
|
10981
11156
|
const array = parentObject;
|
|
11157
|
+
const reverseOp = this.toReverseOperation(array);
|
|
10982
11158
|
const previousIndex = Number(array.subPathOf(this.createdAt));
|
|
10983
11159
|
array.moveAfter(this.prevCreatedAt, this.createdAt, this.getExecutedAt());
|
|
10984
11160
|
const index = Number(array.subPathOf(this.createdAt));
|
|
@@ -10990,9 +11166,18 @@ class MoveOperation extends Operation {
|
|
|
10990
11166
|
index,
|
|
10991
11167
|
previousIndex
|
|
10992
11168
|
}
|
|
10993
|
-
]
|
|
11169
|
+
],
|
|
11170
|
+
reverseOp
|
|
10994
11171
|
};
|
|
10995
11172
|
}
|
|
11173
|
+
toReverseOperation(array) {
|
|
11174
|
+
const preservePrevCreatedAt = array.getPrevCreatedAt(this.createdAt);
|
|
11175
|
+
return MoveOperation.create(
|
|
11176
|
+
this.getParentCreatedAt(),
|
|
11177
|
+
preservePrevCreatedAt,
|
|
11178
|
+
this.createdAt
|
|
11179
|
+
);
|
|
11180
|
+
}
|
|
10996
11181
|
/**
|
|
10997
11182
|
* `getEffectedCreatedAt` returns the creation time of the effected element.
|
|
10998
11183
|
*/
|
|
@@ -15941,10 +16126,9 @@ class TreeStyleOperation extends Operation {
|
|
|
15941
16126
|
}
|
|
15942
16127
|
function toPresence(presence) {
|
|
15943
16128
|
const pbPresence = new Presence$1();
|
|
15944
|
-
const
|
|
16129
|
+
const pbDataMap = pbPresence.data;
|
|
15945
16130
|
for (const [key, value] of Object.entries(presence)) {
|
|
15946
|
-
|
|
15947
|
-
pbDataArray.push(JSON.stringify(value));
|
|
16131
|
+
pbDataMap[key] = JSON.stringify(value);
|
|
15948
16132
|
}
|
|
15949
16133
|
return pbPresence;
|
|
15950
16134
|
}
|
|
@@ -16506,11 +16690,9 @@ function fromTimeTicket(pbTimeTicket) {
|
|
|
16506
16690
|
}
|
|
16507
16691
|
function fromPresence(pbPresence) {
|
|
16508
16692
|
const data = {};
|
|
16509
|
-
|
|
16510
|
-
const key = pbPresence.data[i];
|
|
16511
|
-
const value = pbPresence.data[i + 1];
|
|
16693
|
+
Object.entries(pbPresence.data).forEach(([key, value]) => {
|
|
16512
16694
|
data[key] = JSON.parse(value);
|
|
16513
|
-
}
|
|
16695
|
+
});
|
|
16514
16696
|
return data;
|
|
16515
16697
|
}
|
|
16516
16698
|
function fromPresenceChange(pbPresenceChange) {
|
|
@@ -16946,6 +17128,14 @@ function fromElement(pbElement) {
|
|
|
16946
17128
|
throw new YorkieError(Code.ErrUnimplemented, `unimplemented element`);
|
|
16947
17129
|
}
|
|
16948
17130
|
}
|
|
17131
|
+
function fromSchemaRules(pbRules) {
|
|
17132
|
+
return pbRules.map((pbRule) => {
|
|
17133
|
+
return {
|
|
17134
|
+
path: pbRule.path,
|
|
17135
|
+
type: pbRule.type
|
|
17136
|
+
};
|
|
17137
|
+
});
|
|
17138
|
+
}
|
|
16949
17139
|
function bytesToSnapshot(bytes) {
|
|
16950
17140
|
if (!bytes) {
|
|
16951
17141
|
return {
|
|
@@ -17043,7 +17233,8 @@ const converter = {
|
|
|
17043
17233
|
bytesToChangeID,
|
|
17044
17234
|
bytesToOperation,
|
|
17045
17235
|
versionVectorToHex,
|
|
17046
|
-
hexToVersionVector
|
|
17236
|
+
hexToVersionVector,
|
|
17237
|
+
fromSchemaRules
|
|
17047
17238
|
};
|
|
17048
17239
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
17049
17240
|
LogLevel2[LogLevel2["Trivial"] = 0] = "Trivial";
|
|
@@ -17203,6 +17394,156 @@ class Attachment {
|
|
|
17203
17394
|
this.watchLoopTimerID = void 0;
|
|
17204
17395
|
}
|
|
17205
17396
|
}
|
|
17397
|
+
function validateYorkieRuleset(data, ruleset) {
|
|
17398
|
+
const errors = [];
|
|
17399
|
+
for (const rule of ruleset) {
|
|
17400
|
+
const value = getValueByPath(data, rule.path);
|
|
17401
|
+
const result = validateValue(value, rule);
|
|
17402
|
+
if (!result.valid) {
|
|
17403
|
+
for (const error of result.errors || []) {
|
|
17404
|
+
errors.push(error);
|
|
17405
|
+
}
|
|
17406
|
+
}
|
|
17407
|
+
}
|
|
17408
|
+
return {
|
|
17409
|
+
valid: errors.length === 0,
|
|
17410
|
+
errors
|
|
17411
|
+
};
|
|
17412
|
+
}
|
|
17413
|
+
function getValueByPath(obj, path) {
|
|
17414
|
+
if (!path.startsWith("$")) {
|
|
17415
|
+
throw new Error(`Path must start with $, got ${path}`);
|
|
17416
|
+
}
|
|
17417
|
+
const keys = path.split(".");
|
|
17418
|
+
let current = obj;
|
|
17419
|
+
for (let i = 1; i < keys.length; i++) {
|
|
17420
|
+
const key = keys[i];
|
|
17421
|
+
if (!(current instanceof CRDTObject)) {
|
|
17422
|
+
return void 0;
|
|
17423
|
+
}
|
|
17424
|
+
current = current.get(key);
|
|
17425
|
+
}
|
|
17426
|
+
return current;
|
|
17427
|
+
}
|
|
17428
|
+
function validateValue(value, rule) {
|
|
17429
|
+
switch (rule.type) {
|
|
17430
|
+
case "string":
|
|
17431
|
+
case "boolean":
|
|
17432
|
+
case "integer":
|
|
17433
|
+
case "double":
|
|
17434
|
+
case "long":
|
|
17435
|
+
case "date":
|
|
17436
|
+
case "bytes":
|
|
17437
|
+
case "null":
|
|
17438
|
+
return validatePrimitiveValue(value, rule);
|
|
17439
|
+
case "object":
|
|
17440
|
+
if (!(value instanceof CRDTObject)) {
|
|
17441
|
+
return {
|
|
17442
|
+
valid: false,
|
|
17443
|
+
errors: [
|
|
17444
|
+
{
|
|
17445
|
+
path: rule.path,
|
|
17446
|
+
message: `Expected object at path ${rule.path}`
|
|
17447
|
+
}
|
|
17448
|
+
]
|
|
17449
|
+
};
|
|
17450
|
+
}
|
|
17451
|
+
break;
|
|
17452
|
+
case "array":
|
|
17453
|
+
if (!(value instanceof CRDTArray)) {
|
|
17454
|
+
return {
|
|
17455
|
+
valid: false,
|
|
17456
|
+
errors: [
|
|
17457
|
+
{
|
|
17458
|
+
path: rule.path,
|
|
17459
|
+
message: `Expected array at path ${rule.path}`
|
|
17460
|
+
}
|
|
17461
|
+
]
|
|
17462
|
+
};
|
|
17463
|
+
}
|
|
17464
|
+
break;
|
|
17465
|
+
case "yorkie.Text":
|
|
17466
|
+
if (!(value instanceof CRDTText)) {
|
|
17467
|
+
return {
|
|
17468
|
+
valid: false,
|
|
17469
|
+
errors: [
|
|
17470
|
+
{
|
|
17471
|
+
path: rule.path,
|
|
17472
|
+
message: `Expected yorkie.Text at path ${rule.path}`
|
|
17473
|
+
}
|
|
17474
|
+
]
|
|
17475
|
+
};
|
|
17476
|
+
}
|
|
17477
|
+
break;
|
|
17478
|
+
case "yorkie.Tree":
|
|
17479
|
+
if (!(value instanceof CRDTTree)) {
|
|
17480
|
+
return {
|
|
17481
|
+
valid: false,
|
|
17482
|
+
errors: [
|
|
17483
|
+
{
|
|
17484
|
+
path: rule.path,
|
|
17485
|
+
message: `Expected yorkie.Tree at path ${rule.path}`
|
|
17486
|
+
}
|
|
17487
|
+
]
|
|
17488
|
+
};
|
|
17489
|
+
}
|
|
17490
|
+
break;
|
|
17491
|
+
case "yorkie.Counter":
|
|
17492
|
+
if (!(value instanceof CRDTCounter)) {
|
|
17493
|
+
return {
|
|
17494
|
+
valid: false,
|
|
17495
|
+
errors: [
|
|
17496
|
+
{
|
|
17497
|
+
path: rule.path,
|
|
17498
|
+
message: `Expected yorkie.Counter at path ${rule.path}`
|
|
17499
|
+
}
|
|
17500
|
+
]
|
|
17501
|
+
};
|
|
17502
|
+
}
|
|
17503
|
+
break;
|
|
17504
|
+
default:
|
|
17505
|
+
throw new Error(`Unknown rule type: ${rule.type}`);
|
|
17506
|
+
}
|
|
17507
|
+
return {
|
|
17508
|
+
valid: true
|
|
17509
|
+
};
|
|
17510
|
+
}
|
|
17511
|
+
function getPrimitiveType(type) {
|
|
17512
|
+
switch (type) {
|
|
17513
|
+
case "null":
|
|
17514
|
+
return PrimitiveType.Null;
|
|
17515
|
+
case "boolean":
|
|
17516
|
+
return PrimitiveType.Boolean;
|
|
17517
|
+
case "integer":
|
|
17518
|
+
return PrimitiveType.Integer;
|
|
17519
|
+
case "long":
|
|
17520
|
+
return PrimitiveType.Long;
|
|
17521
|
+
case "double":
|
|
17522
|
+
return PrimitiveType.Double;
|
|
17523
|
+
case "string":
|
|
17524
|
+
return PrimitiveType.String;
|
|
17525
|
+
case "bytes":
|
|
17526
|
+
return PrimitiveType.Bytes;
|
|
17527
|
+
case "date":
|
|
17528
|
+
return PrimitiveType.Date;
|
|
17529
|
+
default:
|
|
17530
|
+
throw new Error(`Unknown primitive type: ${type}`);
|
|
17531
|
+
}
|
|
17532
|
+
}
|
|
17533
|
+
function validatePrimitiveValue(value, rule) {
|
|
17534
|
+
if (value instanceof Primitive && value.getType() === getPrimitiveType(rule.type)) {
|
|
17535
|
+
return { valid: true };
|
|
17536
|
+
}
|
|
17537
|
+
return {
|
|
17538
|
+
valid: false,
|
|
17539
|
+
errors: [
|
|
17540
|
+
{
|
|
17541
|
+
path: rule.path,
|
|
17542
|
+
message: `Expected ${rule.type} at path ${rule.path}`
|
|
17543
|
+
}
|
|
17544
|
+
]
|
|
17545
|
+
};
|
|
17546
|
+
}
|
|
17206
17547
|
const Noop = () => {
|
|
17207
17548
|
};
|
|
17208
17549
|
class ObserverProxy {
|
|
@@ -19663,6 +20004,7 @@ class Document {
|
|
|
19663
20004
|
__publicField(this, "checkpoint");
|
|
19664
20005
|
__publicField(this, "localChanges");
|
|
19665
20006
|
__publicField(this, "maxSizeLimit");
|
|
20007
|
+
__publicField(this, "schemaRules");
|
|
19666
20008
|
__publicField(this, "root");
|
|
19667
20009
|
__publicField(this, "clone");
|
|
19668
20010
|
__publicField(this, "eventStream");
|
|
@@ -19696,6 +20038,7 @@ class Document {
|
|
|
19696
20038
|
this.checkpoint = InitialCheckpoint;
|
|
19697
20039
|
this.localChanges = [];
|
|
19698
20040
|
this.maxSizeLimit = 0;
|
|
20041
|
+
this.schemaRules = [];
|
|
19699
20042
|
this.eventStream = createObservable((observer) => {
|
|
19700
20043
|
this.eventStreamObserver = observer;
|
|
19701
20044
|
});
|
|
@@ -19715,7 +20058,7 @@ class Document {
|
|
|
19715
20058
|
* `update` executes the given updater to update this document.
|
|
19716
20059
|
*/
|
|
19717
20060
|
update(updater, message) {
|
|
19718
|
-
var _a2;
|
|
20061
|
+
var _a2, _b2, _c2;
|
|
19719
20062
|
if (this.getStatus() === "removed") {
|
|
19720
20063
|
throw new YorkieError(Code.ErrDocumentRemoved, `${this.key} is removed`);
|
|
19721
20064
|
}
|
|
@@ -19746,7 +20089,21 @@ class Document {
|
|
|
19746
20089
|
} finally {
|
|
19747
20090
|
this.isUpdating = false;
|
|
19748
20091
|
}
|
|
19749
|
-
const
|
|
20092
|
+
const schemaRules = this.getSchemaRules();
|
|
20093
|
+
if (!context.isPresenceOnlyChange() && schemaRules.length > 0) {
|
|
20094
|
+
const result = validateYorkieRuleset(
|
|
20095
|
+
(_a2 = this.clone) == null ? void 0 : _a2.root.getObject(),
|
|
20096
|
+
schemaRules
|
|
20097
|
+
);
|
|
20098
|
+
if (!result.valid) {
|
|
20099
|
+
this.clone = void 0;
|
|
20100
|
+
throw new YorkieError(
|
|
20101
|
+
Code.ErrDocumentSchemaValidationFailed,
|
|
20102
|
+
`schema validation failed: ${(_b2 = result.errors) == null ? void 0 : _b2.map((error) => error.message).join(", ")}`
|
|
20103
|
+
);
|
|
20104
|
+
}
|
|
20105
|
+
}
|
|
20106
|
+
const size = totalDocSize((_c2 = this.clone) == null ? void 0 : _c2.root.getDocSize());
|
|
19750
20107
|
if (!context.isPresenceOnlyChange() && this.maxSizeLimit > 0 && this.maxSizeLimit < size) {
|
|
19751
20108
|
this.clone = void 0;
|
|
19752
20109
|
throw new YorkieError(
|
|
@@ -20194,6 +20551,18 @@ class Document {
|
|
|
20194
20551
|
setMaxSizePerDocument(size) {
|
|
20195
20552
|
this.maxSizeLimit = size;
|
|
20196
20553
|
}
|
|
20554
|
+
/**
|
|
20555
|
+
* `getSchemaRules` gets the schema rules of this document.
|
|
20556
|
+
*/
|
|
20557
|
+
getSchemaRules() {
|
|
20558
|
+
return this.schemaRules;
|
|
20559
|
+
}
|
|
20560
|
+
/**
|
|
20561
|
+
* `setSchemaRules` sets the schema rules of this document.
|
|
20562
|
+
*/
|
|
20563
|
+
setSchemaRules(rules) {
|
|
20564
|
+
this.schemaRules = rules;
|
|
20565
|
+
}
|
|
20197
20566
|
/**
|
|
20198
20567
|
* `garbageCollect` purges elements that were removed before the given time.
|
|
20199
20568
|
*
|
|
@@ -20895,7 +21264,7 @@ function createAuthInterceptor(apiKey, token) {
|
|
|
20895
21264
|
};
|
|
20896
21265
|
}
|
|
20897
21266
|
const name = "@yorkie-js/sdk";
|
|
20898
|
-
const version = "0.6.
|
|
21267
|
+
const version = "0.6.20";
|
|
20899
21268
|
const pkg = {
|
|
20900
21269
|
name,
|
|
20901
21270
|
version
|
|
@@ -21121,7 +21490,8 @@ class Client {
|
|
|
21121
21490
|
const res = await this.rpcClient.attachDocument(
|
|
21122
21491
|
{
|
|
21123
21492
|
clientId: this.id,
|
|
21124
|
-
changePack: converter.toChangePack(doc.createChangePack())
|
|
21493
|
+
changePack: converter.toChangePack(doc.createChangePack()),
|
|
21494
|
+
schemaKey: opts.schema
|
|
21125
21495
|
},
|
|
21126
21496
|
{ headers: { "x-shard-key": `${this.apiKey}/${doc.getKey()}` } }
|
|
21127
21497
|
);
|
|
@@ -21129,6 +21499,9 @@ class Client {
|
|
|
21129
21499
|
if (maxSize > 0) {
|
|
21130
21500
|
doc.setMaxSizePerDocument(res.maxSizePerDocument);
|
|
21131
21501
|
}
|
|
21502
|
+
if (res.schemaRules.length > 0) {
|
|
21503
|
+
doc.setSchemaRules(converter.fromSchemaRules(res.schemaRules));
|
|
21504
|
+
}
|
|
21132
21505
|
const pack = converter.fromChangePack(res.changePack);
|
|
21133
21506
|
doc.applyChangePack(pack);
|
|
21134
21507
|
if (doc.getStatus() === DocStatus.Removed) {
|