@colyseus/schema 2.0.4 → 2.0.5
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 +50 -49
- 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 +52 -51
- 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 +6 -4
- 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/build/umd/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.schema = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/******************************************************************************
|
|
8
8
|
Copyright (c) Microsoft Corporation.
|
|
9
9
|
|
|
10
10
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -42,10 +42,14 @@
|
|
|
42
42
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function __spreadArray(to, from) {
|
|
46
|
-
for (var i = 0,
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
function __spreadArray(to, from, pack) {
|
|
46
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
47
|
+
if (ar || !(i in from)) {
|
|
48
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
49
|
+
ar[i] = from[i];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
// export const SWITCH_TO_STRUCTURE = 193; (easily collides with DELETE_AND_ADD + fieldIndex = 2)
|
|
@@ -212,7 +216,7 @@
|
|
|
212
216
|
? fieldName
|
|
213
217
|
: this.indexes[fieldName];
|
|
214
218
|
if (index === undefined) {
|
|
215
|
-
console.warn("@colyseus/schema "
|
|
219
|
+
console.warn("@colyseus/schema ".concat(this.ref.constructor.name, ": trying to delete non-existing index: ").concat(fieldName, " (").concat(index, ")"));
|
|
216
220
|
return;
|
|
217
221
|
}
|
|
218
222
|
var previousValue = this.getValue(index);
|
|
@@ -284,7 +288,7 @@
|
|
|
284
288
|
};
|
|
285
289
|
ChangeTree.prototype.assertValidIndex = function (index, fieldName) {
|
|
286
290
|
if (index === undefined) {
|
|
287
|
-
throw new Error("ChangeTree: missing index for field \""
|
|
291
|
+
throw new Error("ChangeTree: missing index for field \"".concat(fieldName, "\""));
|
|
288
292
|
}
|
|
289
293
|
};
|
|
290
294
|
return ChangeTree;
|
|
@@ -522,7 +526,7 @@
|
|
|
522
526
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
523
527
|
items[_i] = arguments[_i];
|
|
524
528
|
}
|
|
525
|
-
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], (_a = Array.from(this.$items.values())).concat.apply(_a, items))))();
|
|
529
|
+
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], (_a = Array.from(this.$items.values())).concat.apply(_a, items), false)))();
|
|
526
530
|
};
|
|
527
531
|
/**
|
|
528
532
|
* Adds all the elements of an array separated by the specified separator string.
|
|
@@ -562,7 +566,7 @@
|
|
|
562
566
|
* @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
|
|
563
567
|
*/
|
|
564
568
|
ArraySchema.prototype.slice = function (start, end) {
|
|
565
|
-
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()).slice(start, end))))();
|
|
569
|
+
return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()).slice(start, end), false)))();
|
|
566
570
|
};
|
|
567
571
|
/**
|
|
568
572
|
* Sorts an array.
|
|
@@ -591,10 +595,6 @@
|
|
|
591
595
|
*/
|
|
592
596
|
ArraySchema.prototype.splice = function (start, deleteCount) {
|
|
593
597
|
if (deleteCount === void 0) { deleteCount = this.length - start; }
|
|
594
|
-
var items = [];
|
|
595
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
596
|
-
items[_i - 2] = arguments[_i];
|
|
597
|
-
}
|
|
598
598
|
var indexes = Array.from(this.$items.keys());
|
|
599
599
|
var removedItems = [];
|
|
600
600
|
for (var i = start; i < start + deleteCount; i++) {
|
|
@@ -689,7 +689,7 @@
|
|
|
689
689
|
* @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.
|
|
690
690
|
*/
|
|
691
691
|
ArraySchema.prototype.reduce = function (callbackfn, initialValue) {
|
|
692
|
-
return Array.from(this.$items.values())
|
|
692
|
+
return Array.prototype.reduce.apply(Array.from(this.$items.values()), arguments);
|
|
693
693
|
};
|
|
694
694
|
/**
|
|
695
695
|
* 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.
|
|
@@ -697,7 +697,7 @@
|
|
|
697
697
|
* @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.
|
|
698
698
|
*/
|
|
699
699
|
ArraySchema.prototype.reduceRight = function (callbackfn, initialValue) {
|
|
700
|
-
return Array.from(this.$items.values())
|
|
700
|
+
return Array.prototype.reduceRight.apply(Array.from(this.$items.values()), arguments);
|
|
701
701
|
};
|
|
702
702
|
/**
|
|
703
703
|
* Returns the value of the first element in the array where predicate is true, and undefined
|
|
@@ -764,9 +764,6 @@
|
|
|
764
764
|
ArraySchema.prototype[Symbol.iterator] = function () {
|
|
765
765
|
return Array.from(this.$items.values())[Symbol.iterator]();
|
|
766
766
|
};
|
|
767
|
-
ArraySchema.prototype[Symbol.unscopables] = function () {
|
|
768
|
-
return this.$items[Symbol.unscopables]();
|
|
769
|
-
};
|
|
770
767
|
/**
|
|
771
768
|
* Returns an iterable of key, value pairs for every entry in the array
|
|
772
769
|
*/
|
|
@@ -846,12 +843,12 @@
|
|
|
846
843
|
ArraySchema.prototype.clone = function (isDecoding) {
|
|
847
844
|
var cloned;
|
|
848
845
|
if (isDecoding) {
|
|
849
|
-
cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()))))();
|
|
846
|
+
cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], Array.from(this.$items.values()), false)))();
|
|
850
847
|
}
|
|
851
848
|
else {
|
|
852
849
|
cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], this.map(function (item) { return ((item['$changes'])
|
|
853
850
|
? item.clone()
|
|
854
|
-
: item); }))))();
|
|
851
|
+
: item); }), false)))();
|
|
855
852
|
}
|
|
856
853
|
return cloned;
|
|
857
854
|
};
|
|
@@ -898,7 +895,8 @@
|
|
|
898
895
|
this.$indexes = new Map();
|
|
899
896
|
this.$refId = 0;
|
|
900
897
|
if (initialValues) {
|
|
901
|
-
if (initialValues instanceof Map
|
|
898
|
+
if (initialValues instanceof Map ||
|
|
899
|
+
initialValues instanceof MapSchema) {
|
|
902
900
|
initialValues.forEach(function (v, k) { return _this.set(k, v); });
|
|
903
901
|
}
|
|
904
902
|
else {
|
|
@@ -928,7 +926,7 @@
|
|
|
928
926
|
});
|
|
929
927
|
MapSchema.prototype.set = function (key, value) {
|
|
930
928
|
if (value === undefined || value === null) {
|
|
931
|
-
throw new Error("MapSchema#set('"
|
|
929
|
+
throw new Error("MapSchema#set('".concat(key, "', ").concat(value, "): trying to set ").concat(value, " value on '").concat(key, "'."));
|
|
932
930
|
}
|
|
933
931
|
// get "index" for this value.
|
|
934
932
|
var hasIndex = typeof (this.$changes.indexes[key]) !== "undefined";
|
|
@@ -1123,7 +1121,7 @@
|
|
|
1123
1121
|
return true;
|
|
1124
1122
|
}
|
|
1125
1123
|
else {
|
|
1126
|
-
console.warn("@filterChildren: field '"
|
|
1124
|
+
console.warn("@filterChildren: field '".concat(field, "' can't have children. Ignoring filter."));
|
|
1127
1125
|
}
|
|
1128
1126
|
};
|
|
1129
1127
|
SchemaDefinition.prototype.getChildrenFilter = function (field) {
|
|
@@ -1193,7 +1191,7 @@
|
|
|
1193
1191
|
var constructor = target.constructor;
|
|
1194
1192
|
constructor._context = context;
|
|
1195
1193
|
if (!type) {
|
|
1196
|
-
throw new Error(constructor.name
|
|
1194
|
+
throw new Error("".concat(constructor.name, ": @type() reference provided for \"").concat(field, "\" is undefined. Make sure you don't have any circular dependencies."));
|
|
1197
1195
|
}
|
|
1198
1196
|
/*
|
|
1199
1197
|
* static schema
|
|
@@ -1215,11 +1213,11 @@
|
|
|
1215
1213
|
// trying to define same property multiple times across inheritance.
|
|
1216
1214
|
// https://github.com/colyseus/colyseus-unity3d/issues/131#issuecomment-814308572
|
|
1217
1215
|
try {
|
|
1218
|
-
throw new Error("@colyseus/schema: Duplicate '"
|
|
1216
|
+
throw new Error("@colyseus/schema: Duplicate '".concat(field, "' definition on '").concat(constructor.name, "'.\nCheck @type() annotation"));
|
|
1219
1217
|
}
|
|
1220
1218
|
catch (e) {
|
|
1221
1219
|
var definitionAtLine = e.stack.split("\n")[4].trim();
|
|
1222
|
-
throw new Error(e.message
|
|
1220
|
+
throw new Error("".concat(e.message, " ").concat(definitionAtLine));
|
|
1223
1221
|
}
|
|
1224
1222
|
}
|
|
1225
1223
|
}
|
|
@@ -1243,7 +1241,7 @@
|
|
|
1243
1241
|
};
|
|
1244
1242
|
return;
|
|
1245
1243
|
}
|
|
1246
|
-
var fieldCached = "_"
|
|
1244
|
+
var fieldCached = "_".concat(field);
|
|
1247
1245
|
definition.descriptors[fieldCached] = {
|
|
1248
1246
|
enumerable: false,
|
|
1249
1247
|
configurable: false,
|
|
@@ -1265,7 +1263,7 @@
|
|
|
1265
1263
|
value !== null) {
|
|
1266
1264
|
// automaticallty transform Array into ArraySchema
|
|
1267
1265
|
if (isArray && !(value instanceof ArraySchema)) {
|
|
1268
|
-
value = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], value)))();
|
|
1266
|
+
value = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], value, false)))();
|
|
1269
1267
|
}
|
|
1270
1268
|
// automaticallty transform Map into MapSchema
|
|
1271
1269
|
if (isMap && !(value instanceof MapSchema)) {
|
|
@@ -1290,7 +1288,7 @@
|
|
|
1290
1288
|
value['$changes'].setParent(this, this.$changes.root, this._definition.indexes[field]);
|
|
1291
1289
|
}
|
|
1292
1290
|
}
|
|
1293
|
-
else {
|
|
1291
|
+
else if (this[fieldCached]) {
|
|
1294
1292
|
//
|
|
1295
1293
|
// Setting a field to `null` or `undefined` will delete it.
|
|
1296
1294
|
//
|
|
@@ -1336,7 +1334,7 @@
|
|
|
1336
1334
|
definition.deprecated[field] = true;
|
|
1337
1335
|
if (throws) {
|
|
1338
1336
|
definition.descriptors[field] = {
|
|
1339
|
-
get: function () { throw new Error(field
|
|
1337
|
+
get: function () { throw new Error("".concat(field, " is deprecated.")); },
|
|
1340
1338
|
set: function (value) { },
|
|
1341
1339
|
enumerable: false,
|
|
1342
1340
|
configurable: true
|
|
@@ -2309,7 +2307,7 @@
|
|
|
2309
2307
|
case "float64":
|
|
2310
2308
|
typeofTarget = "number";
|
|
2311
2309
|
if (isNaN(value)) {
|
|
2312
|
-
console.log("trying to encode \"NaN\" in "
|
|
2310
|
+
console.log("trying to encode \"NaN\" in ".concat(klass.constructor.name, "#").concat(field));
|
|
2313
2311
|
}
|
|
2314
2312
|
break;
|
|
2315
2313
|
case "string":
|
|
@@ -2321,13 +2319,13 @@
|
|
|
2321
2319
|
return;
|
|
2322
2320
|
}
|
|
2323
2321
|
if (typeof (value) !== typeofTarget && (!allowNull || (allowNull && value !== null))) {
|
|
2324
|
-
var foundValue = "'"
|
|
2325
|
-
throw new EncodeSchemaError("a '"
|
|
2322
|
+
var foundValue = "'".concat(JSON.stringify(value), "'").concat((value && value.constructor && " (".concat(value.constructor.name, ")")) || '');
|
|
2323
|
+
throw new EncodeSchemaError("a '".concat(typeofTarget, "' was expected, but ").concat(foundValue, " was provided in ").concat(klass.constructor.name, "#").concat(field));
|
|
2326
2324
|
}
|
|
2327
2325
|
}
|
|
2328
2326
|
function assertInstanceType(value, type, klass, field) {
|
|
2329
2327
|
if (!(value instanceof type)) {
|
|
2330
|
-
throw new EncodeSchemaError("a '"
|
|
2328
|
+
throw new EncodeSchemaError("a '".concat(type.name, "' was expected, but '").concat(value.constructor.name, "' was provided in ").concat(klass.constructor.name, "#").concat(field));
|
|
2331
2329
|
}
|
|
2332
2330
|
}
|
|
2333
2331
|
function encodePrimitiveType(type, bytes, value, klass, field) {
|
|
@@ -2337,7 +2335,7 @@
|
|
|
2337
2335
|
encodeFunc(bytes, value);
|
|
2338
2336
|
}
|
|
2339
2337
|
else {
|
|
2340
|
-
throw new EncodeSchemaError("a '"
|
|
2338
|
+
throw new EncodeSchemaError("a '".concat(type, "' was expected, but ").concat(value, " was provided in ").concat(klass.constructor.name, "#").concat(field));
|
|
2341
2339
|
}
|
|
2342
2340
|
}
|
|
2343
2341
|
function decodePrimitiveType(type, bytes, it) {
|
|
@@ -2426,6 +2424,7 @@
|
|
|
2426
2424
|
return function () { return spliceOne(_this.$callbacks[attr], _this.$callbacks[attr].indexOf(callback)); };
|
|
2427
2425
|
};
|
|
2428
2426
|
Schema.prototype.decode = function (bytes, it, ref) {
|
|
2427
|
+
var _a;
|
|
2429
2428
|
if (it === void 0) { it = { offset: 0 }; }
|
|
2430
2429
|
if (ref === void 0) { ref = this; }
|
|
2431
2430
|
var allChanges = [];
|
|
@@ -2442,7 +2441,7 @@
|
|
|
2442
2441
|
// Trying to access a reference that haven't been decoded yet.
|
|
2443
2442
|
//
|
|
2444
2443
|
if (!nextRef) {
|
|
2445
|
-
throw new Error("\"refId\" not found: "
|
|
2444
|
+
throw new Error("\"refId\" not found: ".concat(refId));
|
|
2446
2445
|
}
|
|
2447
2446
|
ref = nextRef;
|
|
2448
2447
|
continue;
|
|
@@ -2485,7 +2484,7 @@
|
|
|
2485
2484
|
}
|
|
2486
2485
|
}
|
|
2487
2486
|
else {
|
|
2488
|
-
previousValue = ref["_"
|
|
2487
|
+
previousValue = ref["_".concat(fieldName)];
|
|
2489
2488
|
}
|
|
2490
2489
|
//
|
|
2491
2490
|
// Delete operations
|
|
@@ -2565,7 +2564,7 @@
|
|
|
2565
2564
|
var entries = previousValue.entries();
|
|
2566
2565
|
var iter = void 0;
|
|
2567
2566
|
while ((iter = entries.next()) && !iter.done) {
|
|
2568
|
-
var _a = iter.value,
|
|
2567
|
+
var key = (_a = iter.value, _a[0]), value_1 = _a[1];
|
|
2569
2568
|
allChanges.push({
|
|
2570
2569
|
refId: refId_2,
|
|
2571
2570
|
op: exports.OPERATION.DELETE,
|
|
@@ -2592,6 +2591,7 @@
|
|
|
2592
2591
|
var key = dynamicIndex;
|
|
2593
2592
|
// ref.set(key, value);
|
|
2594
2593
|
ref['$items'].set(key, value);
|
|
2594
|
+
ref['$changes'].allChanges.add(fieldIndex);
|
|
2595
2595
|
}
|
|
2596
2596
|
else if (ref instanceof ArraySchema) {
|
|
2597
2597
|
// const key = ref['$indexes'][field];
|
|
@@ -2744,7 +2744,7 @@
|
|
|
2744
2744
|
//
|
|
2745
2745
|
// ensure a ArraySchema has been provided
|
|
2746
2746
|
//
|
|
2747
|
-
assertInstanceType(ref["_"
|
|
2747
|
+
assertInstanceType(ref["_".concat(field)], definition.constructor, ref, field);
|
|
2748
2748
|
//
|
|
2749
2749
|
// Encode refId for this instance.
|
|
2750
2750
|
// The actual instance is going to be encoded on next `changeTree` iteration.
|
|
@@ -2946,11 +2946,12 @@
|
|
|
2946
2946
|
return filteredBytes;
|
|
2947
2947
|
};
|
|
2948
2948
|
Schema.prototype.clone = function () {
|
|
2949
|
+
var _a;
|
|
2949
2950
|
var cloned = new (this.constructor);
|
|
2950
2951
|
var schema = this._definition.schema;
|
|
2951
2952
|
for (var field in schema) {
|
|
2952
2953
|
if (typeof (this[field]) === "object" &&
|
|
2953
|
-
typeof (this[field].clone) === "function") {
|
|
2954
|
+
typeof ((_a = this[field]) === null || _a === void 0 ? void 0 : _a.clone) === "function") {
|
|
2954
2955
|
// deep clone
|
|
2955
2956
|
cloned[field] = this[field].clone();
|
|
2956
2957
|
}
|
|
@@ -2969,7 +2970,7 @@
|
|
|
2969
2970
|
if (!deprecated[field] && this[field] !== null && typeof (this[field]) !== "undefined") {
|
|
2970
2971
|
obj[field] = (typeof (this[field]['toJSON']) === "function")
|
|
2971
2972
|
? this[field]['toJSON']()
|
|
2972
|
-
: this["_"
|
|
2973
|
+
: this["_".concat(field)];
|
|
2973
2974
|
}
|
|
2974
2975
|
}
|
|
2975
2976
|
return obj;
|
|
@@ -3004,7 +3005,7 @@
|
|
|
3004
3005
|
return instance;
|
|
3005
3006
|
};
|
|
3006
3007
|
Schema.prototype._triggerChanges = function (changes) {
|
|
3007
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j
|
|
3008
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
3008
3009
|
var uniqueRefIds = new Set();
|
|
3009
3010
|
var $refs = this.$changes.root.refs;
|
|
3010
3011
|
var _loop_2 = function (i) {
|
|
@@ -3027,7 +3028,7 @@
|
|
|
3027
3028
|
if (!uniqueRefIds.has(refId)) {
|
|
3028
3029
|
try {
|
|
3029
3030
|
// trigger onChange
|
|
3030
|
-
(
|
|
3031
|
+
(_c = $callbacks === null || $callbacks === void 0 ? void 0 : $callbacks[exports.OPERATION.REPLACE]) === null || _c === void 0 ? void 0 : _c.forEach(function (callback) {
|
|
3031
3032
|
return callback(changes);
|
|
3032
3033
|
});
|
|
3033
3034
|
}
|
|
@@ -3037,7 +3038,7 @@
|
|
|
3037
3038
|
}
|
|
3038
3039
|
try {
|
|
3039
3040
|
if ($callbacks.hasOwnProperty(change.field)) {
|
|
3040
|
-
(
|
|
3041
|
+
(_d = $callbacks[change.field]) === null || _d === void 0 ? void 0 : _d.forEach(function (callback) {
|
|
3041
3042
|
return callback(change.value, change.previousValue);
|
|
3042
3043
|
});
|
|
3043
3044
|
}
|
|
@@ -3050,7 +3051,7 @@
|
|
|
3050
3051
|
// is a collection of items
|
|
3051
3052
|
if (change.op === exports.OPERATION.ADD && change.previousValue === undefined) {
|
|
3052
3053
|
// triger onAdd
|
|
3053
|
-
(
|
|
3054
|
+
(_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); });
|
|
3054
3055
|
}
|
|
3055
3056
|
else if (change.op === exports.OPERATION.DELETE) {
|
|
3056
3057
|
//
|
|
@@ -3059,20 +3060,20 @@
|
|
|
3059
3060
|
//
|
|
3060
3061
|
if (change.previousValue !== undefined) {
|
|
3061
3062
|
// triger onRemove
|
|
3062
|
-
(
|
|
3063
|
+
(_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); });
|
|
3063
3064
|
}
|
|
3064
3065
|
}
|
|
3065
3066
|
else if (change.op === exports.OPERATION.DELETE_AND_ADD) {
|
|
3066
3067
|
// triger onRemove
|
|
3067
3068
|
if (change.previousValue !== undefined) {
|
|
3068
|
-
(
|
|
3069
|
+
(_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); });
|
|
3069
3070
|
}
|
|
3070
3071
|
// triger onAdd
|
|
3071
|
-
(
|
|
3072
|
+
(_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); });
|
|
3072
3073
|
}
|
|
3073
3074
|
// trigger onChange
|
|
3074
3075
|
if (change.value !== change.previousValue) {
|
|
3075
|
-
(
|
|
3076
|
+
(_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); });
|
|
3076
3077
|
}
|
|
3077
3078
|
}
|
|
3078
3079
|
uniqueRefIds.add(refId);
|
|
@@ -3292,4 +3293,4 @@
|
|
|
3292
3293
|
|
|
3293
3294
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3294
3295
|
|
|
3295
|
-
}))
|
|
3296
|
+
}));
|