@yorkie-js/react 0.6.17 → 0.6.18
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 +362 -20
- package/dist/yorkie-js-react.es.js.map +1 -1
- package/dist/yorkie-js-react.js +362 -20
- package/dist/yorkie-js-react.js.map +1 -1
- package/package.json +2 -2
package/dist/yorkie-js-react.js
CHANGED
|
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7
7
|
|
|
8
8
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
9
9
|
const name$1 = "@yorkie-js/react";
|
|
10
|
-
const version$1 = "0.6.
|
|
10
|
+
const version$1 = "0.6.18";
|
|
11
11
|
const pkg$1 = {
|
|
12
12
|
name: name$1,
|
|
13
13
|
version: version$1
|
|
@@ -6458,6 +6458,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6458
6458
|
* @generated from field: yorkie.v1.DocSize document_size = 8;
|
|
6459
6459
|
*/
|
|
6460
6460
|
__publicField(this, "documentSize");
|
|
6461
|
+
/**
|
|
6462
|
+
* @generated from field: string schema_key = 9;
|
|
6463
|
+
*/
|
|
6464
|
+
__publicField(this, "schemaKey", "");
|
|
6461
6465
|
/**
|
|
6462
6466
|
* @generated from field: google.protobuf.Timestamp created_at = 4;
|
|
6463
6467
|
*/
|
|
@@ -6517,6 +6521,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6517
6521
|
/* ScalarType.INT32 */
|
|
6518
6522
|
},
|
|
6519
6523
|
{ no: 8, name: "document_size", kind: "message", T: DocSize },
|
|
6524
|
+
{
|
|
6525
|
+
no: 9,
|
|
6526
|
+
name: "schema_key",
|
|
6527
|
+
kind: "scalar",
|
|
6528
|
+
T: 9
|
|
6529
|
+
/* ScalarType.STRING */
|
|
6530
|
+
},
|
|
6520
6531
|
{ no: 4, name: "created_at", kind: "message", T: Timestamp },
|
|
6521
6532
|
{ no: 5, name: "accessed_at", kind: "message", T: Timestamp },
|
|
6522
6533
|
{ no: 6, name: "updated_at", kind: "message", T: Timestamp }
|
|
@@ -6572,9 +6583,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6572
6583
|
constructor(data) {
|
|
6573
6584
|
super();
|
|
6574
6585
|
/**
|
|
6575
|
-
* @generated from field:
|
|
6586
|
+
* @generated from field: map<string, string> data = 1;
|
|
6576
6587
|
*/
|
|
6577
|
-
__publicField(this, "data",
|
|
6588
|
+
__publicField(this, "data", {});
|
|
6578
6589
|
proto3.util.initPartial(data, this);
|
|
6579
6590
|
}
|
|
6580
6591
|
static fromBinary(bytes, options) {
|
|
@@ -6590,7 +6601,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6590
6601
|
return proto3.util.equals(_g, a, b);
|
|
6591
6602
|
}
|
|
6592
6603
|
}, __publicField(_g, "runtime", proto3), __publicField(_g, "typeName", "yorkie.v1.Presence"), __publicField(_g, "fields", proto3.util.newFieldList(() => [
|
|
6593
|
-
{ no: 1, name: "data", kind: "
|
|
6604
|
+
{ no: 1, name: "data", kind: "map", K: 9, V: {
|
|
6605
|
+
kind: "scalar",
|
|
6606
|
+
T: 9
|
|
6607
|
+
/* ScalarType.STRING */
|
|
6608
|
+
} }
|
|
6594
6609
|
])), _g);
|
|
6595
6610
|
let Checkpoint$1 = (_h = class extends Message {
|
|
6596
6611
|
constructor(data) {
|
|
@@ -6902,6 +6917,128 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6902
6917
|
{ no: 2, name: "gc", kind: "message", T: DataSize }
|
|
6903
6918
|
]));
|
|
6904
6919
|
let DocSize = _DocSize;
|
|
6920
|
+
const _Schema = class _Schema extends Message {
|
|
6921
|
+
constructor(data) {
|
|
6922
|
+
super();
|
|
6923
|
+
/**
|
|
6924
|
+
* @generated from field: string id = 1;
|
|
6925
|
+
*/
|
|
6926
|
+
__publicField(this, "id", "");
|
|
6927
|
+
/**
|
|
6928
|
+
* @generated from field: string name = 2;
|
|
6929
|
+
*/
|
|
6930
|
+
__publicField(this, "name", "");
|
|
6931
|
+
/**
|
|
6932
|
+
* @generated from field: int32 version = 3;
|
|
6933
|
+
*/
|
|
6934
|
+
__publicField(this, "version", 0);
|
|
6935
|
+
/**
|
|
6936
|
+
* @generated from field: string body = 4;
|
|
6937
|
+
*/
|
|
6938
|
+
__publicField(this, "body", "");
|
|
6939
|
+
/**
|
|
6940
|
+
* @generated from field: repeated yorkie.v1.Rule rules = 5;
|
|
6941
|
+
*/
|
|
6942
|
+
__publicField(this, "rules", []);
|
|
6943
|
+
/**
|
|
6944
|
+
* @generated from field: google.protobuf.Timestamp created_at = 6;
|
|
6945
|
+
*/
|
|
6946
|
+
__publicField(this, "createdAt");
|
|
6947
|
+
proto3.util.initPartial(data, this);
|
|
6948
|
+
}
|
|
6949
|
+
static fromBinary(bytes, options) {
|
|
6950
|
+
return new _Schema().fromBinary(bytes, options);
|
|
6951
|
+
}
|
|
6952
|
+
static fromJson(jsonValue, options) {
|
|
6953
|
+
return new _Schema().fromJson(jsonValue, options);
|
|
6954
|
+
}
|
|
6955
|
+
static fromJsonString(jsonString, options) {
|
|
6956
|
+
return new _Schema().fromJsonString(jsonString, options);
|
|
6957
|
+
}
|
|
6958
|
+
static equals(a, b) {
|
|
6959
|
+
return proto3.util.equals(_Schema, a, b);
|
|
6960
|
+
}
|
|
6961
|
+
};
|
|
6962
|
+
__publicField(_Schema, "runtime", proto3);
|
|
6963
|
+
__publicField(_Schema, "typeName", "yorkie.v1.Schema");
|
|
6964
|
+
__publicField(_Schema, "fields", proto3.util.newFieldList(() => [
|
|
6965
|
+
{
|
|
6966
|
+
no: 1,
|
|
6967
|
+
name: "id",
|
|
6968
|
+
kind: "scalar",
|
|
6969
|
+
T: 9
|
|
6970
|
+
/* ScalarType.STRING */
|
|
6971
|
+
},
|
|
6972
|
+
{
|
|
6973
|
+
no: 2,
|
|
6974
|
+
name: "name",
|
|
6975
|
+
kind: "scalar",
|
|
6976
|
+
T: 9
|
|
6977
|
+
/* ScalarType.STRING */
|
|
6978
|
+
},
|
|
6979
|
+
{
|
|
6980
|
+
no: 3,
|
|
6981
|
+
name: "version",
|
|
6982
|
+
kind: "scalar",
|
|
6983
|
+
T: 5
|
|
6984
|
+
/* ScalarType.INT32 */
|
|
6985
|
+
},
|
|
6986
|
+
{
|
|
6987
|
+
no: 4,
|
|
6988
|
+
name: "body",
|
|
6989
|
+
kind: "scalar",
|
|
6990
|
+
T: 9
|
|
6991
|
+
/* ScalarType.STRING */
|
|
6992
|
+
},
|
|
6993
|
+
{ no: 5, name: "rules", kind: "message", T: Rule, repeated: true },
|
|
6994
|
+
{ no: 6, name: "created_at", kind: "message", T: Timestamp }
|
|
6995
|
+
]));
|
|
6996
|
+
let Schema = _Schema;
|
|
6997
|
+
const _Rule = class _Rule extends Message {
|
|
6998
|
+
constructor(data) {
|
|
6999
|
+
super();
|
|
7000
|
+
/**
|
|
7001
|
+
* @generated from field: string path = 1;
|
|
7002
|
+
*/
|
|
7003
|
+
__publicField(this, "path", "");
|
|
7004
|
+
/**
|
|
7005
|
+
* @generated from field: string type = 2;
|
|
7006
|
+
*/
|
|
7007
|
+
__publicField(this, "type", "");
|
|
7008
|
+
proto3.util.initPartial(data, this);
|
|
7009
|
+
}
|
|
7010
|
+
static fromBinary(bytes, options) {
|
|
7011
|
+
return new _Rule().fromBinary(bytes, options);
|
|
7012
|
+
}
|
|
7013
|
+
static fromJson(jsonValue, options) {
|
|
7014
|
+
return new _Rule().fromJson(jsonValue, options);
|
|
7015
|
+
}
|
|
7016
|
+
static fromJsonString(jsonString, options) {
|
|
7017
|
+
return new _Rule().fromJsonString(jsonString, options);
|
|
7018
|
+
}
|
|
7019
|
+
static equals(a, b) {
|
|
7020
|
+
return proto3.util.equals(_Rule, a, b);
|
|
7021
|
+
}
|
|
7022
|
+
};
|
|
7023
|
+
__publicField(_Rule, "runtime", proto3);
|
|
7024
|
+
__publicField(_Rule, "typeName", "yorkie.v1.Rule");
|
|
7025
|
+
__publicField(_Rule, "fields", proto3.util.newFieldList(() => [
|
|
7026
|
+
{
|
|
7027
|
+
no: 1,
|
|
7028
|
+
name: "path",
|
|
7029
|
+
kind: "scalar",
|
|
7030
|
+
T: 9
|
|
7031
|
+
/* ScalarType.STRING */
|
|
7032
|
+
},
|
|
7033
|
+
{
|
|
7034
|
+
no: 2,
|
|
7035
|
+
name: "type",
|
|
7036
|
+
kind: "scalar",
|
|
7037
|
+
T: 9
|
|
7038
|
+
/* ScalarType.STRING */
|
|
7039
|
+
}
|
|
7040
|
+
]));
|
|
7041
|
+
let Rule = _Rule;
|
|
6905
7042
|
const _ActivateClientRequest = class _ActivateClientRequest extends Message {
|
|
6906
7043
|
constructor(data) {
|
|
6907
7044
|
super();
|
|
@@ -7046,6 +7183,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7046
7183
|
* @generated from field: yorkie.v1.ChangePack change_pack = 2;
|
|
7047
7184
|
*/
|
|
7048
7185
|
__publicField(this, "changePack");
|
|
7186
|
+
/**
|
|
7187
|
+
* @generated from field: string schema_key = 3;
|
|
7188
|
+
*/
|
|
7189
|
+
__publicField(this, "schemaKey", "");
|
|
7049
7190
|
proto3.util.initPartial(data, this);
|
|
7050
7191
|
}
|
|
7051
7192
|
static fromBinary(bytes, options) {
|
|
@@ -7071,7 +7212,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7071
7212
|
T: 9
|
|
7072
7213
|
/* ScalarType.STRING */
|
|
7073
7214
|
},
|
|
7074
|
-
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 }
|
|
7215
|
+
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 },
|
|
7216
|
+
{
|
|
7217
|
+
no: 3,
|
|
7218
|
+
name: "schema_key",
|
|
7219
|
+
kind: "scalar",
|
|
7220
|
+
T: 9
|
|
7221
|
+
/* ScalarType.STRING */
|
|
7222
|
+
}
|
|
7075
7223
|
]));
|
|
7076
7224
|
let AttachDocumentRequest = _AttachDocumentRequest;
|
|
7077
7225
|
const _AttachDocumentResponse = class _AttachDocumentResponse extends Message {
|
|
@@ -7081,14 +7229,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7081
7229
|
* @generated from field: string document_id = 1;
|
|
7082
7230
|
*/
|
|
7083
7231
|
__publicField(this, "documentId", "");
|
|
7232
|
+
/**
|
|
7233
|
+
* @generated from field: yorkie.v1.ChangePack change_pack = 2;
|
|
7234
|
+
*/
|
|
7235
|
+
__publicField(this, "changePack");
|
|
7084
7236
|
/**
|
|
7085
7237
|
* @generated from field: int32 max_size_per_document = 3;
|
|
7086
7238
|
*/
|
|
7087
7239
|
__publicField(this, "maxSizePerDocument", 0);
|
|
7088
7240
|
/**
|
|
7089
|
-
* @generated from field: yorkie.v1.
|
|
7241
|
+
* @generated from field: repeated yorkie.v1.Rule schema_rules = 4;
|
|
7090
7242
|
*/
|
|
7091
|
-
__publicField(this, "
|
|
7243
|
+
__publicField(this, "schemaRules", []);
|
|
7092
7244
|
proto3.util.initPartial(data, this);
|
|
7093
7245
|
}
|
|
7094
7246
|
static fromBinary(bytes, options) {
|
|
@@ -7114,6 +7266,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7114
7266
|
T: 9
|
|
7115
7267
|
/* ScalarType.STRING */
|
|
7116
7268
|
},
|
|
7269
|
+
{ no: 2, name: "change_pack", kind: "message", T: ChangePack$1 },
|
|
7117
7270
|
{
|
|
7118
7271
|
no: 3,
|
|
7119
7272
|
name: "max_size_per_document",
|
|
@@ -7121,7 +7274,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7121
7274
|
T: 5
|
|
7122
7275
|
/* ScalarType.INT32 */
|
|
7123
7276
|
},
|
|
7124
|
-
{ no:
|
|
7277
|
+
{ no: 4, name: "schema_rules", kind: "message", T: Rule, repeated: true }
|
|
7125
7278
|
]));
|
|
7126
7279
|
let AttachDocumentResponse = _AttachDocumentResponse;
|
|
7127
7280
|
const _DetachDocumentRequest = class _DetachDocumentRequest extends Message {
|
|
@@ -7892,6 +8045,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
7892
8045
|
Code2["ErrDocumentNotDetached"] = "ErrDocumentNotDetached";
|
|
7893
8046
|
Code2["ErrDocumentRemoved"] = "ErrDocumentRemoved";
|
|
7894
8047
|
Code2["ErrDocumentSizeExceedsLimit"] = "ErrDocumentSizeExceedsLimit";
|
|
8048
|
+
Code2["ErrDocumentSchemaValidationFailed"] = "ErrDocumentSchemaValidationFailed";
|
|
7895
8049
|
Code2["ErrInvalidObjectKey"] = "ErrInvalidObjectKey";
|
|
7896
8050
|
Code2["ErrInvalidArgument"] = "ErrInvalidArgument";
|
|
7897
8051
|
Code2["ErrNotInitialized"] = "ErrNotInitialized";
|
|
@@ -15943,10 +16097,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
15943
16097
|
}
|
|
15944
16098
|
function toPresence(presence) {
|
|
15945
16099
|
const pbPresence = new Presence$1();
|
|
15946
|
-
const
|
|
16100
|
+
const pbDataMap = pbPresence.data;
|
|
15947
16101
|
for (const [key, value] of Object.entries(presence)) {
|
|
15948
|
-
|
|
15949
|
-
pbDataArray.push(JSON.stringify(value));
|
|
16102
|
+
pbDataMap[key] = JSON.stringify(value);
|
|
15950
16103
|
}
|
|
15951
16104
|
return pbPresence;
|
|
15952
16105
|
}
|
|
@@ -16508,11 +16661,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16508
16661
|
}
|
|
16509
16662
|
function fromPresence(pbPresence) {
|
|
16510
16663
|
const data = {};
|
|
16511
|
-
|
|
16512
|
-
const key = pbPresence.data[i];
|
|
16513
|
-
const value = pbPresence.data[i + 1];
|
|
16664
|
+
Object.entries(pbPresence.data).forEach(([key, value]) => {
|
|
16514
16665
|
data[key] = JSON.parse(value);
|
|
16515
|
-
}
|
|
16666
|
+
});
|
|
16516
16667
|
return data;
|
|
16517
16668
|
}
|
|
16518
16669
|
function fromPresenceChange(pbPresenceChange) {
|
|
@@ -16948,6 +17099,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
16948
17099
|
throw new YorkieError(Code.ErrUnimplemented, `unimplemented element`);
|
|
16949
17100
|
}
|
|
16950
17101
|
}
|
|
17102
|
+
function fromSchemaRules(pbRules) {
|
|
17103
|
+
return pbRules.map((pbRule) => {
|
|
17104
|
+
return {
|
|
17105
|
+
path: pbRule.path,
|
|
17106
|
+
type: pbRule.type
|
|
17107
|
+
};
|
|
17108
|
+
});
|
|
17109
|
+
}
|
|
16951
17110
|
function bytesToSnapshot(bytes) {
|
|
16952
17111
|
if (!bytes) {
|
|
16953
17112
|
return {
|
|
@@ -17045,7 +17204,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17045
17204
|
bytesToChangeID,
|
|
17046
17205
|
bytesToOperation,
|
|
17047
17206
|
versionVectorToHex,
|
|
17048
|
-
hexToVersionVector
|
|
17207
|
+
hexToVersionVector,
|
|
17208
|
+
fromSchemaRules
|
|
17049
17209
|
};
|
|
17050
17210
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
17051
17211
|
LogLevel2[LogLevel2["Trivial"] = 0] = "Trivial";
|
|
@@ -17205,6 +17365,156 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
17205
17365
|
this.watchLoopTimerID = void 0;
|
|
17206
17366
|
}
|
|
17207
17367
|
}
|
|
17368
|
+
function validateYorkieRuleset(data, ruleset) {
|
|
17369
|
+
const errors = [];
|
|
17370
|
+
for (const rule of ruleset) {
|
|
17371
|
+
const value = getValueByPath(data, rule.path);
|
|
17372
|
+
const result = validateValue(value, rule);
|
|
17373
|
+
if (!result.valid) {
|
|
17374
|
+
for (const error of result.errors || []) {
|
|
17375
|
+
errors.push(error);
|
|
17376
|
+
}
|
|
17377
|
+
}
|
|
17378
|
+
}
|
|
17379
|
+
return {
|
|
17380
|
+
valid: errors.length === 0,
|
|
17381
|
+
errors
|
|
17382
|
+
};
|
|
17383
|
+
}
|
|
17384
|
+
function getValueByPath(obj, path) {
|
|
17385
|
+
if (!path.startsWith("$")) {
|
|
17386
|
+
throw new Error(`Path must start with $, got ${path}`);
|
|
17387
|
+
}
|
|
17388
|
+
const keys = path.split(".");
|
|
17389
|
+
let current = obj;
|
|
17390
|
+
for (let i = 1; i < keys.length; i++) {
|
|
17391
|
+
const key = keys[i];
|
|
17392
|
+
if (!(current instanceof CRDTObject)) {
|
|
17393
|
+
return void 0;
|
|
17394
|
+
}
|
|
17395
|
+
current = current.get(key);
|
|
17396
|
+
}
|
|
17397
|
+
return current;
|
|
17398
|
+
}
|
|
17399
|
+
function validateValue(value, rule) {
|
|
17400
|
+
switch (rule.type) {
|
|
17401
|
+
case "string":
|
|
17402
|
+
case "boolean":
|
|
17403
|
+
case "integer":
|
|
17404
|
+
case "double":
|
|
17405
|
+
case "long":
|
|
17406
|
+
case "date":
|
|
17407
|
+
case "bytes":
|
|
17408
|
+
case "null":
|
|
17409
|
+
return validatePrimitiveValue(value, rule);
|
|
17410
|
+
case "object":
|
|
17411
|
+
if (!(value instanceof CRDTObject)) {
|
|
17412
|
+
return {
|
|
17413
|
+
valid: false,
|
|
17414
|
+
errors: [
|
|
17415
|
+
{
|
|
17416
|
+
path: rule.path,
|
|
17417
|
+
message: `Expected object at path ${rule.path}`
|
|
17418
|
+
}
|
|
17419
|
+
]
|
|
17420
|
+
};
|
|
17421
|
+
}
|
|
17422
|
+
break;
|
|
17423
|
+
case "array":
|
|
17424
|
+
if (!(value instanceof CRDTArray)) {
|
|
17425
|
+
return {
|
|
17426
|
+
valid: false,
|
|
17427
|
+
errors: [
|
|
17428
|
+
{
|
|
17429
|
+
path: rule.path,
|
|
17430
|
+
message: `Expected array at path ${rule.path}`
|
|
17431
|
+
}
|
|
17432
|
+
]
|
|
17433
|
+
};
|
|
17434
|
+
}
|
|
17435
|
+
break;
|
|
17436
|
+
case "yorkie.Text":
|
|
17437
|
+
if (!(value instanceof CRDTText)) {
|
|
17438
|
+
return {
|
|
17439
|
+
valid: false,
|
|
17440
|
+
errors: [
|
|
17441
|
+
{
|
|
17442
|
+
path: rule.path,
|
|
17443
|
+
message: `Expected yorkie.Text at path ${rule.path}`
|
|
17444
|
+
}
|
|
17445
|
+
]
|
|
17446
|
+
};
|
|
17447
|
+
}
|
|
17448
|
+
break;
|
|
17449
|
+
case "yorkie.Tree":
|
|
17450
|
+
if (!(value instanceof CRDTTree)) {
|
|
17451
|
+
return {
|
|
17452
|
+
valid: false,
|
|
17453
|
+
errors: [
|
|
17454
|
+
{
|
|
17455
|
+
path: rule.path,
|
|
17456
|
+
message: `Expected yorkie.Tree at path ${rule.path}`
|
|
17457
|
+
}
|
|
17458
|
+
]
|
|
17459
|
+
};
|
|
17460
|
+
}
|
|
17461
|
+
break;
|
|
17462
|
+
case "yorkie.Counter":
|
|
17463
|
+
if (!(value instanceof CRDTCounter)) {
|
|
17464
|
+
return {
|
|
17465
|
+
valid: false,
|
|
17466
|
+
errors: [
|
|
17467
|
+
{
|
|
17468
|
+
path: rule.path,
|
|
17469
|
+
message: `Expected yorkie.Counter at path ${rule.path}`
|
|
17470
|
+
}
|
|
17471
|
+
]
|
|
17472
|
+
};
|
|
17473
|
+
}
|
|
17474
|
+
break;
|
|
17475
|
+
default:
|
|
17476
|
+
throw new Error(`Unknown rule type: ${rule.type}`);
|
|
17477
|
+
}
|
|
17478
|
+
return {
|
|
17479
|
+
valid: true
|
|
17480
|
+
};
|
|
17481
|
+
}
|
|
17482
|
+
function getPrimitiveType(type) {
|
|
17483
|
+
switch (type) {
|
|
17484
|
+
case "null":
|
|
17485
|
+
return PrimitiveType.Null;
|
|
17486
|
+
case "boolean":
|
|
17487
|
+
return PrimitiveType.Boolean;
|
|
17488
|
+
case "integer":
|
|
17489
|
+
return PrimitiveType.Integer;
|
|
17490
|
+
case "long":
|
|
17491
|
+
return PrimitiveType.Long;
|
|
17492
|
+
case "double":
|
|
17493
|
+
return PrimitiveType.Double;
|
|
17494
|
+
case "string":
|
|
17495
|
+
return PrimitiveType.String;
|
|
17496
|
+
case "bytes":
|
|
17497
|
+
return PrimitiveType.Bytes;
|
|
17498
|
+
case "date":
|
|
17499
|
+
return PrimitiveType.Date;
|
|
17500
|
+
default:
|
|
17501
|
+
throw new Error(`Unknown primitive type: ${type}`);
|
|
17502
|
+
}
|
|
17503
|
+
}
|
|
17504
|
+
function validatePrimitiveValue(value, rule) {
|
|
17505
|
+
if (value instanceof Primitive && value.getType() === getPrimitiveType(rule.type)) {
|
|
17506
|
+
return { valid: true };
|
|
17507
|
+
}
|
|
17508
|
+
return {
|
|
17509
|
+
valid: false,
|
|
17510
|
+
errors: [
|
|
17511
|
+
{
|
|
17512
|
+
path: rule.path,
|
|
17513
|
+
message: `Expected ${rule.type} at path ${rule.path}`
|
|
17514
|
+
}
|
|
17515
|
+
]
|
|
17516
|
+
};
|
|
17517
|
+
}
|
|
17208
17518
|
const Noop = () => {
|
|
17209
17519
|
};
|
|
17210
17520
|
class ObserverProxy {
|
|
@@ -19665,6 +19975,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19665
19975
|
__publicField(this, "checkpoint");
|
|
19666
19976
|
__publicField(this, "localChanges");
|
|
19667
19977
|
__publicField(this, "maxSizeLimit");
|
|
19978
|
+
__publicField(this, "schemaRules");
|
|
19668
19979
|
__publicField(this, "root");
|
|
19669
19980
|
__publicField(this, "clone");
|
|
19670
19981
|
__publicField(this, "eventStream");
|
|
@@ -19698,6 +20009,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19698
20009
|
this.checkpoint = InitialCheckpoint;
|
|
19699
20010
|
this.localChanges = [];
|
|
19700
20011
|
this.maxSizeLimit = 0;
|
|
20012
|
+
this.schemaRules = [];
|
|
19701
20013
|
this.eventStream = createObservable((observer) => {
|
|
19702
20014
|
this.eventStreamObserver = observer;
|
|
19703
20015
|
});
|
|
@@ -19717,7 +20029,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19717
20029
|
* `update` executes the given updater to update this document.
|
|
19718
20030
|
*/
|
|
19719
20031
|
update(updater, message) {
|
|
19720
|
-
var _a2;
|
|
20032
|
+
var _a2, _b2, _c2;
|
|
19721
20033
|
if (this.getStatus() === "removed") {
|
|
19722
20034
|
throw new YorkieError(Code.ErrDocumentRemoved, `${this.key} is removed`);
|
|
19723
20035
|
}
|
|
@@ -19748,7 +20060,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19748
20060
|
} finally {
|
|
19749
20061
|
this.isUpdating = false;
|
|
19750
20062
|
}
|
|
19751
|
-
const
|
|
20063
|
+
const schemaRules = this.getSchemaRules();
|
|
20064
|
+
if (!context.isPresenceOnlyChange() && schemaRules.length > 0) {
|
|
20065
|
+
const result = validateYorkieRuleset(
|
|
20066
|
+
(_a2 = this.clone) == null ? void 0 : _a2.root.getObject(),
|
|
20067
|
+
schemaRules
|
|
20068
|
+
);
|
|
20069
|
+
if (!result.valid) {
|
|
20070
|
+
this.clone = void 0;
|
|
20071
|
+
throw new YorkieError(
|
|
20072
|
+
Code.ErrDocumentSchemaValidationFailed,
|
|
20073
|
+
`schema validation failed: ${(_b2 = result.errors) == null ? void 0 : _b2.map((error) => error.message).join(", ")}`
|
|
20074
|
+
);
|
|
20075
|
+
}
|
|
20076
|
+
}
|
|
20077
|
+
const size = totalDocSize((_c2 = this.clone) == null ? void 0 : _c2.root.getDocSize());
|
|
19752
20078
|
if (!context.isPresenceOnlyChange() && this.maxSizeLimit > 0 && this.maxSizeLimit < size) {
|
|
19753
20079
|
this.clone = void 0;
|
|
19754
20080
|
throw new YorkieError(
|
|
@@ -20196,6 +20522,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20196
20522
|
setMaxSizePerDocument(size) {
|
|
20197
20523
|
this.maxSizeLimit = size;
|
|
20198
20524
|
}
|
|
20525
|
+
/**
|
|
20526
|
+
* `getSchemaRules` gets the schema rules of this document.
|
|
20527
|
+
*/
|
|
20528
|
+
getSchemaRules() {
|
|
20529
|
+
return this.schemaRules;
|
|
20530
|
+
}
|
|
20531
|
+
/**
|
|
20532
|
+
* `setSchemaRules` sets the schema rules of this document.
|
|
20533
|
+
*/
|
|
20534
|
+
setSchemaRules(rules) {
|
|
20535
|
+
this.schemaRules = rules;
|
|
20536
|
+
}
|
|
20199
20537
|
/**
|
|
20200
20538
|
* `garbageCollect` purges elements that were removed before the given time.
|
|
20201
20539
|
*
|
|
@@ -20897,7 +21235,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
20897
21235
|
};
|
|
20898
21236
|
}
|
|
20899
21237
|
const name = "@yorkie-js/sdk";
|
|
20900
|
-
const version = "0.6.
|
|
21238
|
+
const version = "0.6.18";
|
|
20901
21239
|
const pkg = {
|
|
20902
21240
|
name,
|
|
20903
21241
|
version
|
|
@@ -21123,7 +21461,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
21123
21461
|
const res = await this.rpcClient.attachDocument(
|
|
21124
21462
|
{
|
|
21125
21463
|
clientId: this.id,
|
|
21126
|
-
changePack: converter.toChangePack(doc.createChangePack())
|
|
21464
|
+
changePack: converter.toChangePack(doc.createChangePack()),
|
|
21465
|
+
schemaKey: opts.schema
|
|
21127
21466
|
},
|
|
21128
21467
|
{ headers: { "x-shard-key": `${this.apiKey}/${doc.getKey()}` } }
|
|
21129
21468
|
);
|
|
@@ -21131,6 +21470,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
21131
21470
|
if (maxSize > 0) {
|
|
21132
21471
|
doc.setMaxSizePerDocument(res.maxSizePerDocument);
|
|
21133
21472
|
}
|
|
21473
|
+
if (res.schemaRules.length > 0) {
|
|
21474
|
+
doc.setSchemaRules(converter.fromSchemaRules(res.schemaRules));
|
|
21475
|
+
}
|
|
21134
21476
|
const pack = converter.fromChangePack(res.changePack);
|
|
21135
21477
|
doc.applyChangePack(pack);
|
|
21136
21478
|
if (doc.getStatus() === DocStatus.Removed) {
|