@yorkie-js/react 0.6.15 → 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.
@@ -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.15";
8
+ const version$1 = "0.6.18";
9
9
  const pkg$1 = {
10
10
  name: name$1,
11
11
  version: version$1
@@ -6020,11 +6020,15 @@ const _User = class _User extends Message {
6020
6020
  */
6021
6021
  __publicField(this, "id", "");
6022
6022
  /**
6023
- * @generated from field: string username = 2;
6023
+ * @generated from field: string auth_provider = 2;
6024
+ */
6025
+ __publicField(this, "authProvider", "");
6026
+ /**
6027
+ * @generated from field: string username = 3;
6024
6028
  */
6025
6029
  __publicField(this, "username", "");
6026
6030
  /**
6027
- * @generated from field: google.protobuf.Timestamp created_at = 3;
6031
+ * @generated from field: google.protobuf.Timestamp created_at = 4;
6028
6032
  */
6029
6033
  __publicField(this, "createdAt");
6030
6034
  proto3.util.initPartial(data, this);
@@ -6054,12 +6058,19 @@ __publicField(_User, "fields", proto3.util.newFieldList(() => [
6054
6058
  },
6055
6059
  {
6056
6060
  no: 2,
6061
+ name: "auth_provider",
6062
+ kind: "scalar",
6063
+ T: 9
6064
+ /* ScalarType.STRING */
6065
+ },
6066
+ {
6067
+ no: 3,
6057
6068
  name: "username",
6058
6069
  kind: "scalar",
6059
6070
  T: 9
6060
6071
  /* ScalarType.STRING */
6061
6072
  },
6062
- { no: 3, name: "created_at", kind: "message", T: Timestamp }
6073
+ { no: 4, name: "created_at", kind: "message", T: Timestamp }
6063
6074
  ]));
6064
6075
  let User = _User;
6065
6076
  const _Project = class _Project extends Message {
@@ -6220,6 +6231,51 @@ __publicField(_Project, "fields", proto3.util.newFieldList(() => [
6220
6231
  { no: 13, name: "updated_at", kind: "message", T: Timestamp }
6221
6232
  ]));
6222
6233
  let Project = _Project;
6234
+ const _MetricPoint = class _MetricPoint extends Message {
6235
+ constructor(data) {
6236
+ super();
6237
+ /**
6238
+ * @generated from field: int64 timestamp = 1;
6239
+ */
6240
+ __publicField(this, "timestamp", protoInt64.zero);
6241
+ /**
6242
+ * @generated from field: int32 value = 2;
6243
+ */
6244
+ __publicField(this, "value", 0);
6245
+ proto3.util.initPartial(data, this);
6246
+ }
6247
+ static fromBinary(bytes, options) {
6248
+ return new _MetricPoint().fromBinary(bytes, options);
6249
+ }
6250
+ static fromJson(jsonValue, options) {
6251
+ return new _MetricPoint().fromJson(jsonValue, options);
6252
+ }
6253
+ static fromJsonString(jsonString, options) {
6254
+ return new _MetricPoint().fromJsonString(jsonString, options);
6255
+ }
6256
+ static equals(a, b) {
6257
+ return proto3.util.equals(_MetricPoint, a, b);
6258
+ }
6259
+ };
6260
+ __publicField(_MetricPoint, "runtime", proto3);
6261
+ __publicField(_MetricPoint, "typeName", "yorkie.v1.MetricPoint");
6262
+ __publicField(_MetricPoint, "fields", proto3.util.newFieldList(() => [
6263
+ {
6264
+ no: 1,
6265
+ name: "timestamp",
6266
+ kind: "scalar",
6267
+ T: 3
6268
+ /* ScalarType.INT64 */
6269
+ },
6270
+ {
6271
+ no: 2,
6272
+ name: "value",
6273
+ kind: "scalar",
6274
+ T: 5
6275
+ /* ScalarType.INT32 */
6276
+ }
6277
+ ]));
6278
+ let MetricPoint = _MetricPoint;
6223
6279
  const _UpdatableProjectFields = class _UpdatableProjectFields extends Message {
6224
6280
  constructor(data) {
6225
6281
  super();
@@ -6392,6 +6448,18 @@ const _DocumentSummary = class _DocumentSummary extends Message {
6392
6448
  * @generated from field: string snapshot = 3;
6393
6449
  */
6394
6450
  __publicField(this, "snapshot", "");
6451
+ /**
6452
+ * @generated from field: int32 attached_clients = 7;
6453
+ */
6454
+ __publicField(this, "attachedClients", 0);
6455
+ /**
6456
+ * @generated from field: yorkie.v1.DocSize document_size = 8;
6457
+ */
6458
+ __publicField(this, "documentSize");
6459
+ /**
6460
+ * @generated from field: string schema_key = 9;
6461
+ */
6462
+ __publicField(this, "schemaKey", "");
6395
6463
  /**
6396
6464
  * @generated from field: google.protobuf.Timestamp created_at = 4;
6397
6465
  */
@@ -6443,6 +6511,21 @@ __publicField(_DocumentSummary, "fields", proto3.util.newFieldList(() => [
6443
6511
  T: 9
6444
6512
  /* ScalarType.STRING */
6445
6513
  },
6514
+ {
6515
+ no: 7,
6516
+ name: "attached_clients",
6517
+ kind: "scalar",
6518
+ T: 5
6519
+ /* ScalarType.INT32 */
6520
+ },
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
+ },
6446
6529
  { no: 4, name: "created_at", kind: "message", T: Timestamp },
6447
6530
  { no: 5, name: "accessed_at", kind: "message", T: Timestamp },
6448
6531
  { no: 6, name: "updated_at", kind: "message", T: Timestamp }
@@ -6754,6 +6837,206 @@ __publicField(_DocEvent, "fields", proto3.util.newFieldList(() => [
6754
6837
  { no: 3, name: "body", kind: "message", T: DocEventBody }
6755
6838
  ]));
6756
6839
  let DocEvent = _DocEvent;
6840
+ const _DataSize = class _DataSize extends Message {
6841
+ constructor(data) {
6842
+ super();
6843
+ /**
6844
+ * @generated from field: int32 data = 1;
6845
+ */
6846
+ __publicField(this, "data", 0);
6847
+ /**
6848
+ * @generated from field: int32 meta = 2;
6849
+ */
6850
+ __publicField(this, "meta", 0);
6851
+ proto3.util.initPartial(data, this);
6852
+ }
6853
+ static fromBinary(bytes, options) {
6854
+ return new _DataSize().fromBinary(bytes, options);
6855
+ }
6856
+ static fromJson(jsonValue, options) {
6857
+ return new _DataSize().fromJson(jsonValue, options);
6858
+ }
6859
+ static fromJsonString(jsonString, options) {
6860
+ return new _DataSize().fromJsonString(jsonString, options);
6861
+ }
6862
+ static equals(a, b) {
6863
+ return proto3.util.equals(_DataSize, a, b);
6864
+ }
6865
+ };
6866
+ __publicField(_DataSize, "runtime", proto3);
6867
+ __publicField(_DataSize, "typeName", "yorkie.v1.DataSize");
6868
+ __publicField(_DataSize, "fields", proto3.util.newFieldList(() => [
6869
+ {
6870
+ no: 1,
6871
+ name: "data",
6872
+ kind: "scalar",
6873
+ T: 5
6874
+ /* ScalarType.INT32 */
6875
+ },
6876
+ {
6877
+ no: 2,
6878
+ name: "meta",
6879
+ kind: "scalar",
6880
+ T: 5
6881
+ /* ScalarType.INT32 */
6882
+ }
6883
+ ]));
6884
+ let DataSize = _DataSize;
6885
+ const _DocSize = class _DocSize extends Message {
6886
+ constructor(data) {
6887
+ super();
6888
+ /**
6889
+ * @generated from field: yorkie.v1.DataSize live = 1;
6890
+ */
6891
+ __publicField(this, "live");
6892
+ /**
6893
+ * @generated from field: yorkie.v1.DataSize gc = 2;
6894
+ */
6895
+ __publicField(this, "gc");
6896
+ proto3.util.initPartial(data, this);
6897
+ }
6898
+ static fromBinary(bytes, options) {
6899
+ return new _DocSize().fromBinary(bytes, options);
6900
+ }
6901
+ static fromJson(jsonValue, options) {
6902
+ return new _DocSize().fromJson(jsonValue, options);
6903
+ }
6904
+ static fromJsonString(jsonString, options) {
6905
+ return new _DocSize().fromJsonString(jsonString, options);
6906
+ }
6907
+ static equals(a, b) {
6908
+ return proto3.util.equals(_DocSize, a, b);
6909
+ }
6910
+ };
6911
+ __publicField(_DocSize, "runtime", proto3);
6912
+ __publicField(_DocSize, "typeName", "yorkie.v1.DocSize");
6913
+ __publicField(_DocSize, "fields", proto3.util.newFieldList(() => [
6914
+ { no: 1, name: "live", kind: "message", T: DataSize },
6915
+ { no: 2, name: "gc", kind: "message", T: DataSize }
6916
+ ]));
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;
6757
7040
  const _ActivateClientRequest = class _ActivateClientRequest extends Message {
6758
7041
  constructor(data) {
6759
7042
  super();
@@ -6898,6 +7181,10 @@ const _AttachDocumentRequest = class _AttachDocumentRequest extends Message {
6898
7181
  * @generated from field: yorkie.v1.ChangePack change_pack = 2;
6899
7182
  */
6900
7183
  __publicField(this, "changePack");
7184
+ /**
7185
+ * @generated from field: string schema_key = 3;
7186
+ */
7187
+ __publicField(this, "schemaKey", "");
6901
7188
  proto3.util.initPartial(data, this);
6902
7189
  }
6903
7190
  static fromBinary(bytes, options) {
@@ -6923,7 +7210,14 @@ __publicField(_AttachDocumentRequest, "fields", proto3.util.newFieldList(() => [
6923
7210
  T: 9
6924
7211
  /* ScalarType.STRING */
6925
7212
  },
6926
- { 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
+ }
6927
7221
  ]));
6928
7222
  let AttachDocumentRequest = _AttachDocumentRequest;
6929
7223
  const _AttachDocumentResponse = class _AttachDocumentResponse extends Message {
@@ -6933,14 +7227,18 @@ const _AttachDocumentResponse = class _AttachDocumentResponse extends Message {
6933
7227
  * @generated from field: string document_id = 1;
6934
7228
  */
6935
7229
  __publicField(this, "documentId", "");
7230
+ /**
7231
+ * @generated from field: yorkie.v1.ChangePack change_pack = 2;
7232
+ */
7233
+ __publicField(this, "changePack");
6936
7234
  /**
6937
7235
  * @generated from field: int32 max_size_per_document = 3;
6938
7236
  */
6939
7237
  __publicField(this, "maxSizePerDocument", 0);
6940
7238
  /**
6941
- * @generated from field: yorkie.v1.ChangePack change_pack = 2;
7239
+ * @generated from field: repeated yorkie.v1.Rule schema_rules = 4;
6942
7240
  */
6943
- __publicField(this, "changePack");
7241
+ __publicField(this, "schemaRules", []);
6944
7242
  proto3.util.initPartial(data, this);
6945
7243
  }
6946
7244
  static fromBinary(bytes, options) {
@@ -6966,6 +7264,7 @@ __publicField(_AttachDocumentResponse, "fields", proto3.util.newFieldList(() =>
6966
7264
  T: 9
6967
7265
  /* ScalarType.STRING */
6968
7266
  },
7267
+ { no: 2, name: "change_pack", kind: "message", T: ChangePack$1 },
6969
7268
  {
6970
7269
  no: 3,
6971
7270
  name: "max_size_per_document",
@@ -6973,7 +7272,7 @@ __publicField(_AttachDocumentResponse, "fields", proto3.util.newFieldList(() =>
6973
7272
  T: 5
6974
7273
  /* ScalarType.INT32 */
6975
7274
  },
6976
- { no: 2, name: "change_pack", kind: "message", T: ChangePack$1 }
7275
+ { no: 4, name: "schema_rules", kind: "message", T: Rule, repeated: true }
6977
7276
  ]));
6978
7277
  let AttachDocumentResponse = _AttachDocumentResponse;
6979
7278
  const _DetachDocumentRequest = class _DetachDocumentRequest extends Message {
@@ -7744,6 +8043,7 @@ var Code = /* @__PURE__ */ ((Code2) => {
7744
8043
  Code2["ErrDocumentNotDetached"] = "ErrDocumentNotDetached";
7745
8044
  Code2["ErrDocumentRemoved"] = "ErrDocumentRemoved";
7746
8045
  Code2["ErrDocumentSizeExceedsLimit"] = "ErrDocumentSizeExceedsLimit";
8046
+ Code2["ErrDocumentSchemaValidationFailed"] = "ErrDocumentSchemaValidationFailed";
7747
8047
  Code2["ErrInvalidObjectKey"] = "ErrInvalidObjectKey";
7748
8048
  Code2["ErrInvalidArgument"] = "ErrInvalidArgument";
7749
8049
  Code2["ErrNotInitialized"] = "ErrNotInitialized";
@@ -16797,6 +17097,14 @@ function fromElement(pbElement) {
16797
17097
  throw new YorkieError(Code.ErrUnimplemented, `unimplemented element`);
16798
17098
  }
16799
17099
  }
17100
+ function fromSchemaRules(pbRules) {
17101
+ return pbRules.map((pbRule) => {
17102
+ return {
17103
+ path: pbRule.path,
17104
+ type: pbRule.type
17105
+ };
17106
+ });
17107
+ }
16800
17108
  function bytesToSnapshot(bytes) {
16801
17109
  if (!bytes) {
16802
17110
  return {
@@ -16894,7 +17202,8 @@ const converter = {
16894
17202
  bytesToChangeID,
16895
17203
  bytesToOperation,
16896
17204
  versionVectorToHex,
16897
- hexToVersionVector
17205
+ hexToVersionVector,
17206
+ fromSchemaRules
16898
17207
  };
16899
17208
  var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
16900
17209
  LogLevel2[LogLevel2["Trivial"] = 0] = "Trivial";
@@ -17054,6 +17363,156 @@ class Attachment {
17054
17363
  this.watchLoopTimerID = void 0;
17055
17364
  }
17056
17365
  }
17366
+ function validateYorkieRuleset(data, ruleset) {
17367
+ const errors = [];
17368
+ for (const rule of ruleset) {
17369
+ const value = getValueByPath(data, rule.path);
17370
+ const result = validateValue(value, rule);
17371
+ if (!result.valid) {
17372
+ for (const error of result.errors || []) {
17373
+ errors.push(error);
17374
+ }
17375
+ }
17376
+ }
17377
+ return {
17378
+ valid: errors.length === 0,
17379
+ errors
17380
+ };
17381
+ }
17382
+ function getValueByPath(obj, path) {
17383
+ if (!path.startsWith("$")) {
17384
+ throw new Error(`Path must start with $, got ${path}`);
17385
+ }
17386
+ const keys = path.split(".");
17387
+ let current = obj;
17388
+ for (let i = 1; i < keys.length; i++) {
17389
+ const key = keys[i];
17390
+ if (!(current instanceof CRDTObject)) {
17391
+ return void 0;
17392
+ }
17393
+ current = current.get(key);
17394
+ }
17395
+ return current;
17396
+ }
17397
+ function validateValue(value, rule) {
17398
+ switch (rule.type) {
17399
+ case "string":
17400
+ case "boolean":
17401
+ case "integer":
17402
+ case "double":
17403
+ case "long":
17404
+ case "date":
17405
+ case "bytes":
17406
+ case "null":
17407
+ return validatePrimitiveValue(value, rule);
17408
+ case "object":
17409
+ if (!(value instanceof CRDTObject)) {
17410
+ return {
17411
+ valid: false,
17412
+ errors: [
17413
+ {
17414
+ path: rule.path,
17415
+ message: `Expected object at path ${rule.path}`
17416
+ }
17417
+ ]
17418
+ };
17419
+ }
17420
+ break;
17421
+ case "array":
17422
+ if (!(value instanceof CRDTArray)) {
17423
+ return {
17424
+ valid: false,
17425
+ errors: [
17426
+ {
17427
+ path: rule.path,
17428
+ message: `Expected array at path ${rule.path}`
17429
+ }
17430
+ ]
17431
+ };
17432
+ }
17433
+ break;
17434
+ case "yorkie.Text":
17435
+ if (!(value instanceof CRDTText)) {
17436
+ return {
17437
+ valid: false,
17438
+ errors: [
17439
+ {
17440
+ path: rule.path,
17441
+ message: `Expected yorkie.Text at path ${rule.path}`
17442
+ }
17443
+ ]
17444
+ };
17445
+ }
17446
+ break;
17447
+ case "yorkie.Tree":
17448
+ if (!(value instanceof CRDTTree)) {
17449
+ return {
17450
+ valid: false,
17451
+ errors: [
17452
+ {
17453
+ path: rule.path,
17454
+ message: `Expected yorkie.Tree at path ${rule.path}`
17455
+ }
17456
+ ]
17457
+ };
17458
+ }
17459
+ break;
17460
+ case "yorkie.Counter":
17461
+ if (!(value instanceof CRDTCounter)) {
17462
+ return {
17463
+ valid: false,
17464
+ errors: [
17465
+ {
17466
+ path: rule.path,
17467
+ message: `Expected yorkie.Counter at path ${rule.path}`
17468
+ }
17469
+ ]
17470
+ };
17471
+ }
17472
+ break;
17473
+ default:
17474
+ throw new Error(`Unknown rule type: ${rule.type}`);
17475
+ }
17476
+ return {
17477
+ valid: true
17478
+ };
17479
+ }
17480
+ function getPrimitiveType(type) {
17481
+ switch (type) {
17482
+ case "null":
17483
+ return PrimitiveType.Null;
17484
+ case "boolean":
17485
+ return PrimitiveType.Boolean;
17486
+ case "integer":
17487
+ return PrimitiveType.Integer;
17488
+ case "long":
17489
+ return PrimitiveType.Long;
17490
+ case "double":
17491
+ return PrimitiveType.Double;
17492
+ case "string":
17493
+ return PrimitiveType.String;
17494
+ case "bytes":
17495
+ return PrimitiveType.Bytes;
17496
+ case "date":
17497
+ return PrimitiveType.Date;
17498
+ default:
17499
+ throw new Error(`Unknown primitive type: ${type}`);
17500
+ }
17501
+ }
17502
+ function validatePrimitiveValue(value, rule) {
17503
+ if (value instanceof Primitive && value.getType() === getPrimitiveType(rule.type)) {
17504
+ return { valid: true };
17505
+ }
17506
+ return {
17507
+ valid: false,
17508
+ errors: [
17509
+ {
17510
+ path: rule.path,
17511
+ message: `Expected ${rule.type} at path ${rule.path}`
17512
+ }
17513
+ ]
17514
+ };
17515
+ }
17057
17516
  const Noop = () => {
17058
17517
  };
17059
17518
  class ObserverProxy {
@@ -19514,6 +19973,7 @@ class Document {
19514
19973
  __publicField(this, "checkpoint");
19515
19974
  __publicField(this, "localChanges");
19516
19975
  __publicField(this, "maxSizeLimit");
19976
+ __publicField(this, "schemaRules");
19517
19977
  __publicField(this, "root");
19518
19978
  __publicField(this, "clone");
19519
19979
  __publicField(this, "eventStream");
@@ -19547,6 +20007,7 @@ class Document {
19547
20007
  this.checkpoint = InitialCheckpoint;
19548
20008
  this.localChanges = [];
19549
20009
  this.maxSizeLimit = 0;
20010
+ this.schemaRules = [];
19550
20011
  this.eventStream = createObservable((observer) => {
19551
20012
  this.eventStreamObserver = observer;
19552
20013
  });
@@ -19566,7 +20027,7 @@ class Document {
19566
20027
  * `update` executes the given updater to update this document.
19567
20028
  */
19568
20029
  update(updater, message) {
19569
- var _a2;
20030
+ var _a2, _b2, _c2;
19570
20031
  if (this.getStatus() === "removed") {
19571
20032
  throw new YorkieError(Code.ErrDocumentRemoved, `${this.key} is removed`);
19572
20033
  }
@@ -19597,7 +20058,21 @@ class Document {
19597
20058
  } finally {
19598
20059
  this.isUpdating = false;
19599
20060
  }
19600
- const size = totalDocSize((_a2 = this.clone) == null ? void 0 : _a2.root.getDocSize());
20061
+ const schemaRules = this.getSchemaRules();
20062
+ if (!context.isPresenceOnlyChange() && schemaRules.length > 0) {
20063
+ const result = validateYorkieRuleset(
20064
+ (_a2 = this.clone) == null ? void 0 : _a2.root.getObject(),
20065
+ schemaRules
20066
+ );
20067
+ if (!result.valid) {
20068
+ this.clone = void 0;
20069
+ throw new YorkieError(
20070
+ Code.ErrDocumentSchemaValidationFailed,
20071
+ `schema validation failed: ${(_b2 = result.errors) == null ? void 0 : _b2.map((error) => error.message).join(", ")}`
20072
+ );
20073
+ }
20074
+ }
20075
+ const size = totalDocSize((_c2 = this.clone) == null ? void 0 : _c2.root.getDocSize());
19601
20076
  if (!context.isPresenceOnlyChange() && this.maxSizeLimit > 0 && this.maxSizeLimit < size) {
19602
20077
  this.clone = void 0;
19603
20078
  throw new YorkieError(
@@ -20045,6 +20520,18 @@ class Document {
20045
20520
  setMaxSizePerDocument(size) {
20046
20521
  this.maxSizeLimit = size;
20047
20522
  }
20523
+ /**
20524
+ * `getSchemaRules` gets the schema rules of this document.
20525
+ */
20526
+ getSchemaRules() {
20527
+ return this.schemaRules;
20528
+ }
20529
+ /**
20530
+ * `setSchemaRules` sets the schema rules of this document.
20531
+ */
20532
+ setSchemaRules(rules) {
20533
+ this.schemaRules = rules;
20534
+ }
20048
20535
  /**
20049
20536
  * `garbageCollect` purges elements that were removed before the given time.
20050
20537
  *
@@ -20746,7 +21233,7 @@ function createAuthInterceptor(apiKey, token) {
20746
21233
  };
20747
21234
  }
20748
21235
  const name = "@yorkie-js/sdk";
20749
- const version = "0.6.15";
21236
+ const version = "0.6.18";
20750
21237
  const pkg = {
20751
21238
  name,
20752
21239
  version
@@ -20972,7 +21459,8 @@ class Client {
20972
21459
  const res = await this.rpcClient.attachDocument(
20973
21460
  {
20974
21461
  clientId: this.id,
20975
- changePack: converter.toChangePack(doc.createChangePack())
21462
+ changePack: converter.toChangePack(doc.createChangePack()),
21463
+ schemaKey: opts.schema
20976
21464
  },
20977
21465
  { headers: { "x-shard-key": `${this.apiKey}/${doc.getKey()}` } }
20978
21466
  );
@@ -20980,6 +21468,9 @@ class Client {
20980
21468
  if (maxSize > 0) {
20981
21469
  doc.setMaxSizePerDocument(res.maxSizePerDocument);
20982
21470
  }
21471
+ if (res.schemaRules.length > 0) {
21472
+ doc.setSchemaRules(converter.fromSchemaRules(res.schemaRules));
21473
+ }
20983
21474
  const pack = converter.fromChangePack(res.changePack);
20984
21475
  doc.applyChangePack(pack);
20985
21476
  if (doc.getStatus() === DocStatus.Removed) {