@colyseus/schema 2.0.4 → 2.0.6
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/README.md +0 -4
- package/build/cjs/index.js +48 -48
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +130 -104
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +50 -50
- package/lib/Reflection.js +87 -119
- package/lib/Reflection.js.map +1 -1
- package/lib/Schema.js +195 -257
- package/lib/Schema.js.map +1 -1
- package/lib/annotations.d.ts +6 -6
- package/lib/annotations.js +64 -92
- package/lib/annotations.js.map +1 -1
- package/lib/changes/ChangeTree.d.ts +1 -1
- package/lib/changes/ChangeTree.js +63 -70
- package/lib/changes/ChangeTree.js.map +1 -1
- package/lib/changes/ReferenceTracker.js +24 -27
- package/lib/changes/ReferenceTracker.js.map +1 -1
- package/lib/codegen/api.js +9 -9
- package/lib/codegen/api.js.map +1 -1
- package/lib/codegen/argv.d.ts +1 -1
- package/lib/codegen/argv.js +11 -11
- package/lib/codegen/argv.js.map +1 -1
- package/lib/codegen/cli.js +21 -10
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/languages/cpp.js +126 -77
- package/lib/codegen/languages/cpp.js.map +1 -1
- package/lib/codegen/languages/csharp.js +121 -62
- package/lib/codegen/languages/csharp.js.map +1 -1
- package/lib/codegen/languages/haxe.js +34 -26
- package/lib/codegen/languages/haxe.js.map +1 -1
- package/lib/codegen/languages/java.js +39 -27
- package/lib/codegen/languages/java.js.map +1 -1
- package/lib/codegen/languages/js.js +48 -32
- package/lib/codegen/languages/js.js.map +1 -1
- package/lib/codegen/languages/lua.js +35 -24
- package/lib/codegen/languages/lua.js.map +1 -1
- package/lib/codegen/languages/ts.js +63 -68
- package/lib/codegen/languages/ts.js.map +1 -1
- package/lib/codegen/parser.d.ts +9 -1
- package/lib/codegen/parser.js +88 -46
- package/lib/codegen/parser.js.map +1 -1
- package/lib/codegen/types.d.ts +8 -0
- package/lib/codegen/types.js +64 -54
- package/lib/codegen/types.js.map +1 -1
- package/lib/encoding/decode.js +15 -15
- package/lib/encoding/decode.js.map +1 -1
- package/lib/encoding/encode.js +14 -14
- package/lib/encoding/encode.js.map +1 -1
- package/lib/events/EventEmitter.d.ts +1 -1
- package/lib/events/EventEmitter.js +16 -47
- package/lib/events/EventEmitter.js.map +1 -1
- package/lib/filters/index.js +7 -8
- package/lib/filters/index.js.map +1 -1
- package/lib/index.js +11 -11
- package/lib/index.js.map +1 -1
- package/lib/types/ArraySchema.d.ts +1 -1
- package/lib/types/ArraySchema.js +161 -219
- package/lib/types/ArraySchema.js.map +1 -1
- package/lib/types/CollectionSchema.d.ts +1 -1
- package/lib/types/CollectionSchema.js +63 -71
- package/lib/types/CollectionSchema.js.map +1 -1
- package/lib/types/HelperTypes.d.ts +9 -9
- package/lib/types/MapSchema.d.ts +16 -16
- package/lib/types/MapSchema.js +68 -78
- package/lib/types/MapSchema.js.map +1 -1
- package/lib/types/SetSchema.js +62 -71
- package/lib/types/SetSchema.js.map +1 -1
- package/lib/types/index.js +1 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/typeRegistry.js +1 -1
- package/lib/types/typeRegistry.js.map +1 -1
- package/lib/types/utils.js +9 -10
- package/lib/types/utils.js.map +1 -1
- package/lib/utils.js +10 -13
- package/lib/utils.js.map +1 -1
- package/package.json +18 -15
- package/src/Reflection.ts +159 -0
- package/src/Schema.ts +1024 -0
- package/src/annotations.ts +400 -0
- package/src/changes/ChangeTree.ts +295 -0
- package/src/changes/ReferenceTracker.ts +81 -0
- package/src/codegen/api.ts +46 -0
- package/src/codegen/argv.ts +40 -0
- package/src/codegen/cli.ts +65 -0
- package/src/codegen/languages/cpp.ts +297 -0
- package/src/codegen/languages/csharp.ts +208 -0
- package/src/codegen/languages/haxe.ts +110 -0
- package/src/codegen/languages/java.ts +115 -0
- package/src/codegen/languages/js.ts +115 -0
- package/src/codegen/languages/lua.ts +125 -0
- package/src/codegen/languages/ts.ts +129 -0
- package/src/codegen/parser.ts +299 -0
- package/src/codegen/types.ts +177 -0
- package/src/encoding/decode.ts +278 -0
- package/src/encoding/encode.ts +283 -0
- package/src/filters/index.ts +23 -0
- package/src/index.ts +59 -0
- package/src/spec.ts +49 -0
- package/src/types/ArraySchema.ts +612 -0
- package/src/types/CollectionSchema.ts +199 -0
- package/src/types/HelperTypes.ts +34 -0
- package/src/types/MapSchema.ts +268 -0
- package/src/types/SetSchema.ts +208 -0
- package/src/types/typeRegistry.ts +19 -0
- package/src/types/utils.ts +62 -0
- package/src/utils.ts +28 -0
package/README.md
CHANGED
|
@@ -7,10 +7,6 @@
|
|
|
7
7
|
An incremental binary state serializer with delta encoding for games.<br>
|
|
8
8
|
Although it was born to be used on <a href="https://github.com/colyseus/colyseus">Colyseus</a>, this library can be used as standalone.
|
|
9
9
|
</p>
|
|
10
|
-
|
|
11
|
-
<a href="https://travis-ci.org/colyseus/schema">
|
|
12
|
-
<img src="https://img.shields.io/travis/colyseus/schema.svg?style=for-the-badge" alt="Build status" />
|
|
13
|
-
</a>
|
|
14
10
|
</div>
|
|
15
11
|
|
|
16
12
|
## Defining Schema
|
package/build/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/******************************************************************************
|
|
6
6
|
Copyright (c) Microsoft Corporation.
|
|
7
7
|
|
|
8
8
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -40,10 +40,14 @@ function __decorate(decorators, target, key, desc) {
|
|
|
40
40
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function __spreadArray(to, from) {
|
|
44
|
-
for (var i = 0,
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
function __spreadArray(to, from, pack) {
|
|
44
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
45
|
+
if (ar || !(i in from)) {
|
|
46
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
47
|
+
ar[i] = from[i];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
// export const SWITCH_TO_STRUCTURE = 193; (easily collides with DELETE_AND_ADD + fieldIndex = 2)
|
|
@@ -210,7 +214,7 @@ var ChangeTree = /** @class */ (function () {
|
|
|
210
214
|
? fieldName
|
|
211
215
|
: this.indexes[fieldName];
|
|
212
216
|
if (index === undefined) {
|
|
213
|
-
console.warn("@colyseus/schema "
|
|
217
|
+
console.warn("@colyseus/schema ".concat(this.ref.constructor.name, ": trying to delete non-existing index: ").concat(fieldName, " (").concat(index, ")"));
|
|
214
218
|
return;
|
|
215
219
|
}
|
|
216
220
|
var previousValue = this.getValue(index);
|
|
@@ -282,7 +286,7 @@ var ChangeTree = /** @class */ (function () {
|
|
|
282
286
|
};
|
|
283
287
|
ChangeTree.prototype.assertValidIndex = function (index, fieldName) {
|
|
284
288
|
if (index === undefined) {
|
|
285
|
-
throw new Error("ChangeTree: missing index for field \""
|
|
289
|
+
throw new Error("ChangeTree: missing index for field \"".concat(fieldName, "\""));
|
|
286
290
|
}
|
|
287
291
|
};
|
|
288
292
|
return ChangeTree;
|
|
@@ -520,7 +524,7 @@ var ArraySchema = /** @class */ (function () {
|
|
|
520
524
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
521
525
|
items[_i] = arguments[_i];
|
|
522
526
|
}
|
|
523
|
-
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], (_a = Array.from(this.$items.values())).concat.apply(_a, items))))();
|
|
527
|
+
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], (_a = Array.from(this.$items.values())).concat.apply(_a, items), false)))();
|
|
524
528
|
};
|
|
525
529
|
/**
|
|
526
530
|
* Adds all the elements of an array separated by the specified separator string.
|
|
@@ -560,7 +564,7 @@ var ArraySchema = /** @class */ (function () {
|
|
|
560
564
|
* @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
|
|
561
565
|
*/
|
|
562
566
|
ArraySchema.prototype.slice = function (start, end) {
|
|
563
|
-
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()).slice(start, end))))();
|
|
567
|
+
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()).slice(start, end), false)))();
|
|
564
568
|
};
|
|
565
569
|
/**
|
|
566
570
|
* Sorts an array.
|
|
@@ -589,10 +593,6 @@ var ArraySchema = /** @class */ (function () {
|
|
|
589
593
|
*/
|
|
590
594
|
ArraySchema.prototype.splice = function (start, deleteCount) {
|
|
591
595
|
if (deleteCount === void 0) { deleteCount = this.length - start; }
|
|
592
|
-
var items = [];
|
|
593
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
594
|
-
items[_i - 2] = arguments[_i];
|
|
595
|
-
}
|
|
596
596
|
var indexes = Array.from(this.$items.keys());
|
|
597
597
|
var removedItems = [];
|
|
598
598
|
for (var i = start; i < start + deleteCount; i++) {
|
|
@@ -687,7 +687,7 @@ var ArraySchema = /** @class */ (function () {
|
|
|
687
687
|
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
|
|
688
688
|
*/
|
|
689
689
|
ArraySchema.prototype.reduce = function (callbackfn, initialValue) {
|
|
690
|
-
return Array.from(this.$items.values())
|
|
690
|
+
return Array.prototype.reduce.apply(Array.from(this.$items.values()), arguments);
|
|
691
691
|
};
|
|
692
692
|
/**
|
|
693
693
|
* Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
|
|
@@ -695,7 +695,7 @@ var ArraySchema = /** @class */ (function () {
|
|
|
695
695
|
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
|
|
696
696
|
*/
|
|
697
697
|
ArraySchema.prototype.reduceRight = function (callbackfn, initialValue) {
|
|
698
|
-
return Array.from(this.$items.values())
|
|
698
|
+
return Array.prototype.reduceRight.apply(Array.from(this.$items.values()), arguments);
|
|
699
699
|
};
|
|
700
700
|
/**
|
|
701
701
|
* Returns the value of the first element in the array where predicate is true, and undefined
|
|
@@ -762,9 +762,6 @@ var ArraySchema = /** @class */ (function () {
|
|
|
762
762
|
ArraySchema.prototype[Symbol.iterator] = function () {
|
|
763
763
|
return Array.from(this.$items.values())[Symbol.iterator]();
|
|
764
764
|
};
|
|
765
|
-
ArraySchema.prototype[Symbol.unscopables] = function () {
|
|
766
|
-
return this.$items[Symbol.unscopables]();
|
|
767
|
-
};
|
|
768
765
|
/**
|
|
769
766
|
* Returns an iterable of key, value pairs for every entry in the array
|
|
770
767
|
*/
|
|
@@ -844,12 +841,12 @@ var ArraySchema = /** @class */ (function () {
|
|
|
844
841
|
ArraySchema.prototype.clone = function (isDecoding) {
|
|
845
842
|
var cloned;
|
|
846
843
|
if (isDecoding) {
|
|
847
|
-
cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()))))();
|
|
844
|
+
cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()), false)))();
|
|
848
845
|
}
|
|
849
846
|
else {
|
|
850
847
|
cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], this.map(function (item) { return ((item['$changes'])
|
|
851
848
|
? item.clone()
|
|
852
|
-
: item); }))))();
|
|
849
|
+
: item); }), false)))();
|
|
853
850
|
}
|
|
854
851
|
return cloned;
|
|
855
852
|
};
|
|
@@ -896,7 +893,8 @@ var MapSchema = /** @class */ (function () {
|
|
|
896
893
|
this.$indexes = new Map();
|
|
897
894
|
this.$refId = 0;
|
|
898
895
|
if (initialValues) {
|
|
899
|
-
if (initialValues instanceof Map
|
|
896
|
+
if (initialValues instanceof Map ||
|
|
897
|
+
initialValues instanceof MapSchema) {
|
|
900
898
|
initialValues.forEach(function (v, k) { return _this.set(k, v); });
|
|
901
899
|
}
|
|
902
900
|
else {
|
|
@@ -926,7 +924,7 @@ var MapSchema = /** @class */ (function () {
|
|
|
926
924
|
});
|
|
927
925
|
MapSchema.prototype.set = function (key, value) {
|
|
928
926
|
if (value === undefined || value === null) {
|
|
929
|
-
throw new Error("MapSchema#set('"
|
|
927
|
+
throw new Error("MapSchema#set('".concat(key, "', ").concat(value, "): trying to set ").concat(value, " value on '").concat(key, "'."));
|
|
930
928
|
}
|
|
931
929
|
// get "index" for this value.
|
|
932
930
|
var hasIndex = typeof (this.$changes.indexes[key]) !== "undefined";
|
|
@@ -1121,7 +1119,7 @@ var SchemaDefinition = /** @class */ (function () {
|
|
|
1121
1119
|
return true;
|
|
1122
1120
|
}
|
|
1123
1121
|
else {
|
|
1124
|
-
console.warn("@filterChildren: field '"
|
|
1122
|
+
console.warn("@filterChildren: field '".concat(field, "' can't have children. Ignoring filter."));
|
|
1125
1123
|
}
|
|
1126
1124
|
};
|
|
1127
1125
|
SchemaDefinition.prototype.getChildrenFilter = function (field) {
|
|
@@ -1191,7 +1189,7 @@ function type(type, options) {
|
|
|
1191
1189
|
var constructor = target.constructor;
|
|
1192
1190
|
constructor._context = context;
|
|
1193
1191
|
if (!type) {
|
|
1194
|
-
throw new Error(constructor.name
|
|
1192
|
+
throw new Error("".concat(constructor.name, ": @type() reference provided for \"").concat(field, "\" is undefined. Make sure you don't have any circular dependencies."));
|
|
1195
1193
|
}
|
|
1196
1194
|
/*
|
|
1197
1195
|
* static schema
|
|
@@ -1213,11 +1211,11 @@ function type(type, options) {
|
|
|
1213
1211
|
// trying to define same property multiple times across inheritance.
|
|
1214
1212
|
// https://github.com/colyseus/colyseus-unity3d/issues/131#issuecomment-814308572
|
|
1215
1213
|
try {
|
|
1216
|
-
throw new Error("@colyseus/schema: Duplicate '"
|
|
1214
|
+
throw new Error("@colyseus/schema: Duplicate '".concat(field, "' definition on '").concat(constructor.name, "'.\nCheck @type() annotation"));
|
|
1217
1215
|
}
|
|
1218
1216
|
catch (e) {
|
|
1219
1217
|
var definitionAtLine = e.stack.split("\n")[4].trim();
|
|
1220
|
-
throw new Error(e.message
|
|
1218
|
+
throw new Error("".concat(e.message, " ").concat(definitionAtLine));
|
|
1221
1219
|
}
|
|
1222
1220
|
}
|
|
1223
1221
|
}
|
|
@@ -1241,7 +1239,7 @@ function type(type, options) {
|
|
|
1241
1239
|
};
|
|
1242
1240
|
return;
|
|
1243
1241
|
}
|
|
1244
|
-
var fieldCached = "_"
|
|
1242
|
+
var fieldCached = "_".concat(field);
|
|
1245
1243
|
definition.descriptors[fieldCached] = {
|
|
1246
1244
|
enumerable: false,
|
|
1247
1245
|
configurable: false,
|
|
@@ -1263,7 +1261,7 @@ function type(type, options) {
|
|
|
1263
1261
|
value !== null) {
|
|
1264
1262
|
// automaticallty transform Array into ArraySchema
|
|
1265
1263
|
if (isArray && !(value instanceof ArraySchema)) {
|
|
1266
|
-
value = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], value)))();
|
|
1264
|
+
value = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], value, false)))();
|
|
1267
1265
|
}
|
|
1268
1266
|
// automaticallty transform Map into MapSchema
|
|
1269
1267
|
if (isMap && !(value instanceof MapSchema)) {
|
|
@@ -1288,7 +1286,7 @@ function type(type, options) {
|
|
|
1288
1286
|
value['$changes'].setParent(this, this.$changes.root, this._definition.indexes[field]);
|
|
1289
1287
|
}
|
|
1290
1288
|
}
|
|
1291
|
-
else {
|
|
1289
|
+
else if (this[fieldCached]) {
|
|
1292
1290
|
//
|
|
1293
1291
|
// Setting a field to `null` or `undefined` will delete it.
|
|
1294
1292
|
//
|
|
@@ -1334,7 +1332,7 @@ function deprecated(throws) {
|
|
|
1334
1332
|
definition.deprecated[field] = true;
|
|
1335
1333
|
if (throws) {
|
|
1336
1334
|
definition.descriptors[field] = {
|
|
1337
|
-
get: function () { throw new Error(field
|
|
1335
|
+
get: function () { throw new Error("".concat(field, " is deprecated.")); },
|
|
1338
1336
|
set: function (value) { },
|
|
1339
1337
|
enumerable: false,
|
|
1340
1338
|
configurable: true
|
|
@@ -2307,7 +2305,7 @@ function assertType(value, type, klass, field) {
|
|
|
2307
2305
|
case "float64":
|
|
2308
2306
|
typeofTarget = "number";
|
|
2309
2307
|
if (isNaN(value)) {
|
|
2310
|
-
console.log("trying to encode \"NaN\" in "
|
|
2308
|
+
console.log("trying to encode \"NaN\" in ".concat(klass.constructor.name, "#").concat(field));
|
|
2311
2309
|
}
|
|
2312
2310
|
break;
|
|
2313
2311
|
case "string":
|
|
@@ -2319,13 +2317,13 @@ function assertType(value, type, klass, field) {
|
|
|
2319
2317
|
return;
|
|
2320
2318
|
}
|
|
2321
2319
|
if (typeof (value) !== typeofTarget && (!allowNull || (allowNull && value !== null))) {
|
|
2322
|
-
var foundValue = "'"
|
|
2323
|
-
throw new EncodeSchemaError("a '"
|
|
2320
|
+
var foundValue = "'".concat(JSON.stringify(value), "'").concat((value && value.constructor && " (".concat(value.constructor.name, ")")) || '');
|
|
2321
|
+
throw new EncodeSchemaError("a '".concat(typeofTarget, "' was expected, but ").concat(foundValue, " was provided in ").concat(klass.constructor.name, "#").concat(field));
|
|
2324
2322
|
}
|
|
2325
2323
|
}
|
|
2326
2324
|
function assertInstanceType(value, type, klass, field) {
|
|
2327
2325
|
if (!(value instanceof type)) {
|
|
2328
|
-
throw new EncodeSchemaError("a '"
|
|
2326
|
+
throw new EncodeSchemaError("a '".concat(type.name, "' was expected, but '").concat(value.constructor.name, "' was provided in ").concat(klass.constructor.name, "#").concat(field));
|
|
2329
2327
|
}
|
|
2330
2328
|
}
|
|
2331
2329
|
function encodePrimitiveType(type, bytes, value, klass, field) {
|
|
@@ -2335,7 +2333,7 @@ function encodePrimitiveType(type, bytes, value, klass, field) {
|
|
|
2335
2333
|
encodeFunc(bytes, value);
|
|
2336
2334
|
}
|
|
2337
2335
|
else {
|
|
2338
|
-
throw new EncodeSchemaError("a '"
|
|
2336
|
+
throw new EncodeSchemaError("a '".concat(type, "' was expected, but ").concat(value, " was provided in ").concat(klass.constructor.name, "#").concat(field));
|
|
2339
2337
|
}
|
|
2340
2338
|
}
|
|
2341
2339
|
function decodePrimitiveType(type, bytes, it) {
|
|
@@ -2440,7 +2438,7 @@ var Schema = /** @class */ (function () {
|
|
|
2440
2438
|
// Trying to access a reference that haven't been decoded yet.
|
|
2441
2439
|
//
|
|
2442
2440
|
if (!nextRef) {
|
|
2443
|
-
throw new Error("\"refId\" not found: "
|
|
2441
|
+
throw new Error("\"refId\" not found: ".concat(refId));
|
|
2444
2442
|
}
|
|
2445
2443
|
ref = nextRef;
|
|
2446
2444
|
continue;
|
|
@@ -2483,7 +2481,7 @@ var Schema = /** @class */ (function () {
|
|
|
2483
2481
|
}
|
|
2484
2482
|
}
|
|
2485
2483
|
else {
|
|
2486
|
-
previousValue = ref["_"
|
|
2484
|
+
previousValue = ref["_".concat(fieldName)];
|
|
2487
2485
|
}
|
|
2488
2486
|
//
|
|
2489
2487
|
// Delete operations
|
|
@@ -2590,6 +2588,7 @@ var Schema = /** @class */ (function () {
|
|
|
2590
2588
|
var key = dynamicIndex;
|
|
2591
2589
|
// ref.set(key, value);
|
|
2592
2590
|
ref['$items'].set(key, value);
|
|
2591
|
+
ref['$changes'].allChanges.add(fieldIndex);
|
|
2593
2592
|
}
|
|
2594
2593
|
else if (ref instanceof ArraySchema) {
|
|
2595
2594
|
// const key = ref['$indexes'][field];
|
|
@@ -2742,7 +2741,7 @@ var Schema = /** @class */ (function () {
|
|
|
2742
2741
|
//
|
|
2743
2742
|
// ensure a ArraySchema has been provided
|
|
2744
2743
|
//
|
|
2745
|
-
assertInstanceType(ref["_"
|
|
2744
|
+
assertInstanceType(ref["_".concat(field)], definition.constructor, ref, field);
|
|
2746
2745
|
//
|
|
2747
2746
|
// Encode refId for this instance.
|
|
2748
2747
|
// The actual instance is going to be encoded on next `changeTree` iteration.
|
|
@@ -2944,11 +2943,12 @@ var Schema = /** @class */ (function () {
|
|
|
2944
2943
|
return filteredBytes;
|
|
2945
2944
|
};
|
|
2946
2945
|
Schema.prototype.clone = function () {
|
|
2946
|
+
var _a;
|
|
2947
2947
|
var cloned = new (this.constructor);
|
|
2948
2948
|
var schema = this._definition.schema;
|
|
2949
2949
|
for (var field in schema) {
|
|
2950
2950
|
if (typeof (this[field]) === "object" &&
|
|
2951
|
-
typeof (this[field].clone) === "function") {
|
|
2951
|
+
typeof ((_a = this[field]) === null || _a === void 0 ? void 0 : _a.clone) === "function") {
|
|
2952
2952
|
// deep clone
|
|
2953
2953
|
cloned[field] = this[field].clone();
|
|
2954
2954
|
}
|
|
@@ -2967,7 +2967,7 @@ var Schema = /** @class */ (function () {
|
|
|
2967
2967
|
if (!deprecated[field] && this[field] !== null && typeof (this[field]) !== "undefined") {
|
|
2968
2968
|
obj[field] = (typeof (this[field]['toJSON']) === "function")
|
|
2969
2969
|
? this[field]['toJSON']()
|
|
2970
|
-
: this["_"
|
|
2970
|
+
: this["_".concat(field)];
|
|
2971
2971
|
}
|
|
2972
2972
|
}
|
|
2973
2973
|
return obj;
|
|
@@ -3002,7 +3002,7 @@ var Schema = /** @class */ (function () {
|
|
|
3002
3002
|
return instance;
|
|
3003
3003
|
};
|
|
3004
3004
|
Schema.prototype._triggerChanges = function (changes) {
|
|
3005
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
3005
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
3006
3006
|
var uniqueRefIds = new Set();
|
|
3007
3007
|
var $refs = this.$changes.root.refs;
|
|
3008
3008
|
var _loop_2 = function (i) {
|
|
@@ -3025,7 +3025,7 @@ var Schema = /** @class */ (function () {
|
|
|
3025
3025
|
if (!uniqueRefIds.has(refId)) {
|
|
3026
3026
|
try {
|
|
3027
3027
|
// trigger onChange
|
|
3028
|
-
(
|
|
3028
|
+
(_c = $callbacks === null || $callbacks === void 0 ? void 0 : $callbacks[exports.OPERATION.REPLACE]) === null || _c === void 0 ? void 0 : _c.forEach(function (callback) {
|
|
3029
3029
|
return callback(changes);
|
|
3030
3030
|
});
|
|
3031
3031
|
}
|
|
@@ -3035,7 +3035,7 @@ var Schema = /** @class */ (function () {
|
|
|
3035
3035
|
}
|
|
3036
3036
|
try {
|
|
3037
3037
|
if ($callbacks.hasOwnProperty(change.field)) {
|
|
3038
|
-
(
|
|
3038
|
+
(_d = $callbacks[change.field]) === null || _d === void 0 ? void 0 : _d.forEach(function (callback) {
|
|
3039
3039
|
return callback(change.value, change.previousValue);
|
|
3040
3040
|
});
|
|
3041
3041
|
}
|
|
@@ -3048,7 +3048,7 @@ var Schema = /** @class */ (function () {
|
|
|
3048
3048
|
// is a collection of items
|
|
3049
3049
|
if (change.op === exports.OPERATION.ADD && change.previousValue === undefined) {
|
|
3050
3050
|
// triger onAdd
|
|
3051
|
-
(
|
|
3051
|
+
(_e = $callbacks[exports.OPERATION.ADD]) === null || _e === void 0 ? void 0 : _e.forEach(function (callback) { var _a; return callback(change.value, (_a = change.dynamicIndex) !== null && _a !== void 0 ? _a : change.field); });
|
|
3052
3052
|
}
|
|
3053
3053
|
else if (change.op === exports.OPERATION.DELETE) {
|
|
3054
3054
|
//
|
|
@@ -3057,20 +3057,20 @@ var Schema = /** @class */ (function () {
|
|
|
3057
3057
|
//
|
|
3058
3058
|
if (change.previousValue !== undefined) {
|
|
3059
3059
|
// triger onRemove
|
|
3060
|
-
(
|
|
3060
|
+
(_f = $callbacks[exports.OPERATION.DELETE]) === null || _f === void 0 ? void 0 : _f.forEach(function (callback) { var _a; return callback(change.previousValue, (_a = change.dynamicIndex) !== null && _a !== void 0 ? _a : change.field); });
|
|
3061
3061
|
}
|
|
3062
3062
|
}
|
|
3063
3063
|
else if (change.op === exports.OPERATION.DELETE_AND_ADD) {
|
|
3064
3064
|
// triger onRemove
|
|
3065
3065
|
if (change.previousValue !== undefined) {
|
|
3066
|
-
(
|
|
3066
|
+
(_g = $callbacks[exports.OPERATION.DELETE]) === null || _g === void 0 ? void 0 : _g.forEach(function (callback) { var _a; return callback(change.previousValue, (_a = change.dynamicIndex) !== null && _a !== void 0 ? _a : change.field); });
|
|
3067
3067
|
}
|
|
3068
3068
|
// triger onAdd
|
|
3069
|
-
(
|
|
3069
|
+
(_h = $callbacks[exports.OPERATION.ADD]) === null || _h === void 0 ? void 0 : _h.forEach(function (callback) { var _a; return callback(change.value, (_a = change.dynamicIndex) !== null && _a !== void 0 ? _a : change.field); });
|
|
3070
3070
|
}
|
|
3071
3071
|
// trigger onChange
|
|
3072
3072
|
if (change.value !== change.previousValue) {
|
|
3073
|
-
(
|
|
3073
|
+
(_j = $callbacks[exports.OPERATION.REPLACE]) === null || _j === void 0 ? void 0 : _j.forEach(function (callback) { var _a; return callback(change.value, (_a = change.dynamicIndex) !== null && _a !== void 0 ? _a : change.field); });
|
|
3074
3074
|
}
|
|
3075
3075
|
}
|
|
3076
3076
|
uniqueRefIds.add(refId);
|