@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.
Files changed (107) hide show
  1. package/README.md +0 -4
  2. package/build/cjs/index.js +48 -48
  3. package/build/cjs/index.js.map +1 -1
  4. package/build/esm/index.mjs +130 -104
  5. package/build/esm/index.mjs.map +1 -1
  6. package/build/umd/index.js +50 -50
  7. package/lib/Reflection.js +87 -119
  8. package/lib/Reflection.js.map +1 -1
  9. package/lib/Schema.js +195 -257
  10. package/lib/Schema.js.map +1 -1
  11. package/lib/annotations.d.ts +6 -6
  12. package/lib/annotations.js +64 -92
  13. package/lib/annotations.js.map +1 -1
  14. package/lib/changes/ChangeTree.d.ts +1 -1
  15. package/lib/changes/ChangeTree.js +63 -70
  16. package/lib/changes/ChangeTree.js.map +1 -1
  17. package/lib/changes/ReferenceTracker.js +24 -27
  18. package/lib/changes/ReferenceTracker.js.map +1 -1
  19. package/lib/codegen/api.js +9 -9
  20. package/lib/codegen/api.js.map +1 -1
  21. package/lib/codegen/argv.d.ts +1 -1
  22. package/lib/codegen/argv.js +11 -11
  23. package/lib/codegen/argv.js.map +1 -1
  24. package/lib/codegen/cli.js +21 -10
  25. package/lib/codegen/cli.js.map +1 -1
  26. package/lib/codegen/languages/cpp.js +126 -77
  27. package/lib/codegen/languages/cpp.js.map +1 -1
  28. package/lib/codegen/languages/csharp.js +121 -62
  29. package/lib/codegen/languages/csharp.js.map +1 -1
  30. package/lib/codegen/languages/haxe.js +34 -26
  31. package/lib/codegen/languages/haxe.js.map +1 -1
  32. package/lib/codegen/languages/java.js +39 -27
  33. package/lib/codegen/languages/java.js.map +1 -1
  34. package/lib/codegen/languages/js.js +48 -32
  35. package/lib/codegen/languages/js.js.map +1 -1
  36. package/lib/codegen/languages/lua.js +35 -24
  37. package/lib/codegen/languages/lua.js.map +1 -1
  38. package/lib/codegen/languages/ts.js +63 -68
  39. package/lib/codegen/languages/ts.js.map +1 -1
  40. package/lib/codegen/parser.d.ts +9 -1
  41. package/lib/codegen/parser.js +88 -46
  42. package/lib/codegen/parser.js.map +1 -1
  43. package/lib/codegen/types.d.ts +8 -0
  44. package/lib/codegen/types.js +64 -54
  45. package/lib/codegen/types.js.map +1 -1
  46. package/lib/encoding/decode.js +15 -15
  47. package/lib/encoding/decode.js.map +1 -1
  48. package/lib/encoding/encode.js +14 -14
  49. package/lib/encoding/encode.js.map +1 -1
  50. package/lib/events/EventEmitter.d.ts +1 -1
  51. package/lib/events/EventEmitter.js +16 -47
  52. package/lib/events/EventEmitter.js.map +1 -1
  53. package/lib/filters/index.js +7 -8
  54. package/lib/filters/index.js.map +1 -1
  55. package/lib/index.js +11 -11
  56. package/lib/index.js.map +1 -1
  57. package/lib/types/ArraySchema.d.ts +1 -1
  58. package/lib/types/ArraySchema.js +161 -219
  59. package/lib/types/ArraySchema.js.map +1 -1
  60. package/lib/types/CollectionSchema.d.ts +1 -1
  61. package/lib/types/CollectionSchema.js +63 -71
  62. package/lib/types/CollectionSchema.js.map +1 -1
  63. package/lib/types/HelperTypes.d.ts +9 -9
  64. package/lib/types/MapSchema.d.ts +16 -16
  65. package/lib/types/MapSchema.js +68 -78
  66. package/lib/types/MapSchema.js.map +1 -1
  67. package/lib/types/SetSchema.js +62 -71
  68. package/lib/types/SetSchema.js.map +1 -1
  69. package/lib/types/index.js +1 -1
  70. package/lib/types/index.js.map +1 -1
  71. package/lib/types/typeRegistry.js +1 -1
  72. package/lib/types/typeRegistry.js.map +1 -1
  73. package/lib/types/utils.js +9 -10
  74. package/lib/types/utils.js.map +1 -1
  75. package/lib/utils.js +10 -13
  76. package/lib/utils.js.map +1 -1
  77. package/package.json +18 -15
  78. package/src/Reflection.ts +159 -0
  79. package/src/Schema.ts +1024 -0
  80. package/src/annotations.ts +400 -0
  81. package/src/changes/ChangeTree.ts +295 -0
  82. package/src/changes/ReferenceTracker.ts +81 -0
  83. package/src/codegen/api.ts +46 -0
  84. package/src/codegen/argv.ts +40 -0
  85. package/src/codegen/cli.ts +65 -0
  86. package/src/codegen/languages/cpp.ts +297 -0
  87. package/src/codegen/languages/csharp.ts +208 -0
  88. package/src/codegen/languages/haxe.ts +110 -0
  89. package/src/codegen/languages/java.ts +115 -0
  90. package/src/codegen/languages/js.ts +115 -0
  91. package/src/codegen/languages/lua.ts +125 -0
  92. package/src/codegen/languages/ts.ts +129 -0
  93. package/src/codegen/parser.ts +299 -0
  94. package/src/codegen/types.ts +177 -0
  95. package/src/encoding/decode.ts +278 -0
  96. package/src/encoding/encode.ts +283 -0
  97. package/src/filters/index.ts +23 -0
  98. package/src/index.ts +59 -0
  99. package/src/spec.ts +49 -0
  100. package/src/types/ArraySchema.ts +612 -0
  101. package/src/types/CollectionSchema.ts +199 -0
  102. package/src/types/HelperTypes.ts +34 -0
  103. package/src/types/MapSchema.ts +268 -0
  104. package/src/types/SetSchema.ts +208 -0
  105. package/src/types/typeRegistry.ts +19 -0
  106. package/src/types/utils.ts +62 -0
  107. package/src/utils.ts +28 -0
@@ -1,33 +1,12 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
19
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
20
- to[j] = from[i];
21
- return to;
22
- };
23
2
  Object.defineProperty(exports, "__esModule", { value: true });
24
3
  exports.ArraySchema = exports.getArrayProxy = void 0;
25
- var ChangeTree_1 = require("../changes/ChangeTree");
26
- var spec_1 = require("../spec");
27
- var utils_1 = require("./utils");
28
- var DEFAULT_SORT = function (a, b) {
29
- var A = a.toString();
30
- var B = b.toString();
4
+ const ChangeTree_1 = require("../changes/ChangeTree");
5
+ const spec_1 = require("../spec");
6
+ const utils_1 = require("./utils");
7
+ const DEFAULT_SORT = (a, b) => {
8
+ const A = a.toString();
9
+ const B = b.toString();
31
10
  if (A < B)
32
11
  return -1;
33
12
  else if (A > B)
@@ -44,7 +23,7 @@ function getArrayProxy(value) {
44
23
  // - allow `delete map["key"]`
45
24
  //
46
25
  value = new Proxy(value, {
47
- get: function (obj, prop) {
26
+ get: (obj, prop) => {
48
27
  if (typeof (prop) !== "symbol" &&
49
28
  !isNaN(prop) // https://stackoverflow.com/a/175787/892698
50
29
  ) {
@@ -54,11 +33,11 @@ function getArrayProxy(value) {
54
33
  return obj[prop];
55
34
  }
56
35
  },
57
- set: function (obj, prop, setValue) {
36
+ set: (obj, prop, setValue) => {
58
37
  if (typeof (prop) !== "symbol" &&
59
38
  !isNaN(prop)) {
60
- var indexes = Array.from(obj['$items'].keys());
61
- var key = parseInt(indexes[prop] || prop);
39
+ const indexes = Array.from(obj['$items'].keys());
40
+ const key = parseInt(indexes[prop] || prop);
62
41
  if (setValue === undefined || setValue === null) {
63
42
  obj.deleteAt(key);
64
43
  }
@@ -71,7 +50,7 @@ function getArrayProxy(value) {
71
50
  }
72
51
  return true;
73
52
  },
74
- deleteProperty: function (obj, prop) {
53
+ deleteProperty: (obj, prop) => {
75
54
  if (typeof (prop) === "number") {
76
55
  obj.deleteAt(prop);
77
56
  }
@@ -84,108 +63,94 @@ function getArrayProxy(value) {
84
63
  return value;
85
64
  }
86
65
  exports.getArrayProxy = getArrayProxy;
87
- var ArraySchema = /** @class */ (function () {
88
- function ArraySchema() {
89
- var items = [];
90
- for (var _i = 0; _i < arguments.length; _i++) {
91
- items[_i] = arguments[_i];
92
- }
93
- this.$changes = new ChangeTree_1.ChangeTree(this);
94
- this.$items = new Map();
95
- this.$indexes = new Map();
96
- this.$refId = 0;
97
- this.push.apply(this, items);
98
- }
99
- ArraySchema.prototype.onAdd = function (callback, triggerAll) {
100
- if (triggerAll === void 0) { triggerAll = true; }
101
- return utils_1.addCallback((this.$callbacks || (this.$callbacks = [])), spec_1.OPERATION.ADD, callback, (triggerAll)
66
+ class ArraySchema {
67
+ static { Symbol.unscopables; }
68
+ onAdd(callback, triggerAll = true) {
69
+ return (0, utils_1.addCallback)((this.$callbacks || (this.$callbacks = [])), spec_1.OPERATION.ADD, callback, (triggerAll)
102
70
  ? this.$items
103
71
  : undefined);
104
- };
105
- ArraySchema.prototype.onRemove = function (callback) { return utils_1.addCallback(this.$callbacks || (this.$callbacks = []), spec_1.OPERATION.DELETE, callback); };
106
- ArraySchema.prototype.onChange = function (callback) { return utils_1.addCallback(this.$callbacks || (this.$callbacks = []), spec_1.OPERATION.REPLACE, callback); };
107
- ArraySchema.is = function (type) {
72
+ }
73
+ onRemove(callback) { return (0, utils_1.addCallback)(this.$callbacks || (this.$callbacks = []), spec_1.OPERATION.DELETE, callback); }
74
+ onChange(callback) { return (0, utils_1.addCallback)(this.$callbacks || (this.$callbacks = []), spec_1.OPERATION.REPLACE, callback); }
75
+ static is(type) {
108
76
  return (
109
77
  // type format: ["string"]
110
78
  Array.isArray(type) ||
111
79
  // type format: { array: "string" }
112
80
  (type['array'] !== undefined));
113
- };
114
- Object.defineProperty(ArraySchema.prototype, "length", {
115
- get: function () {
116
- return this.$items.size;
117
- },
118
- set: function (value) {
119
- if (value === 0) {
120
- this.clear();
121
- }
122
- else {
123
- this.splice(value, this.length - value);
124
- }
125
- },
126
- enumerable: false,
127
- configurable: true
128
- });
129
- ArraySchema.prototype.push = function () {
130
- var _this = this;
131
- var values = [];
132
- for (var _i = 0; _i < arguments.length; _i++) {
133
- values[_i] = arguments[_i];
81
+ }
82
+ constructor(...items) {
83
+ this.$changes = new ChangeTree_1.ChangeTree(this);
84
+ this.$items = new Map();
85
+ this.$indexes = new Map();
86
+ this.$refId = 0;
87
+ this.push.apply(this, items);
88
+ }
89
+ set length(value) {
90
+ if (value === 0) {
91
+ this.clear();
92
+ }
93
+ else {
94
+ this.splice(value, this.length - value);
134
95
  }
135
- var lastIndex;
136
- values.forEach(function (value) {
96
+ }
97
+ get length() {
98
+ return this.$items.size;
99
+ }
100
+ push(...values) {
101
+ let lastIndex;
102
+ values.forEach(value => {
137
103
  // set "index" for reference.
138
- lastIndex = _this.$refId++;
139
- _this.setAt(lastIndex, value);
104
+ lastIndex = this.$refId++;
105
+ this.setAt(lastIndex, value);
140
106
  });
141
107
  return lastIndex;
142
- };
108
+ }
143
109
  /**
144
110
  * Removes the last element from an array and returns it.
145
111
  */
146
- ArraySchema.prototype.pop = function () {
147
- var key = Array.from(this.$indexes.values()).pop();
112
+ pop() {
113
+ const key = Array.from(this.$indexes.values()).pop();
148
114
  if (key === undefined) {
149
115
  return undefined;
150
116
  }
151
117
  this.$changes.delete(key);
152
118
  this.$indexes.delete(key);
153
- var value = this.$items.get(key);
119
+ const value = this.$items.get(key);
154
120
  this.$items.delete(key);
155
121
  return value;
156
- };
157
- ArraySchema.prototype.at = function (index) {
122
+ }
123
+ at(index) {
158
124
  //
159
125
  // FIXME: this should be O(1)
160
126
  //
161
- var key = Array.from(this.$items.keys())[index];
127
+ const key = Array.from(this.$items.keys())[index];
162
128
  return this.$items.get(key);
163
- };
164
- ArraySchema.prototype.setAt = function (index, value) {
165
- var _a, _b;
129
+ }
130
+ setAt(index, value) {
166
131
  if (value['$changes'] !== undefined) {
167
132
  value['$changes'].setParent(this, this.$changes.root, index);
168
133
  }
169
- var operation = (_b = (_a = this.$changes.indexes[index]) === null || _a === void 0 ? void 0 : _a.op) !== null && _b !== void 0 ? _b : spec_1.OPERATION.ADD;
134
+ const operation = this.$changes.indexes[index]?.op ?? spec_1.OPERATION.ADD;
170
135
  this.$changes.indexes[index] = index;
171
136
  this.$indexes.set(index, index);
172
137
  this.$items.set(index, value);
173
138
  this.$changes.change(index, operation);
174
- };
175
- ArraySchema.prototype.deleteAt = function (index) {
176
- var key = Array.from(this.$items.keys())[index];
139
+ }
140
+ deleteAt(index) {
141
+ const key = Array.from(this.$items.keys())[index];
177
142
  if (key === undefined) {
178
143
  return false;
179
144
  }
180
145
  return this.$deleteAt(key);
181
- };
182
- ArraySchema.prototype.$deleteAt = function (index) {
146
+ }
147
+ $deleteAt(index) {
183
148
  // delete at internal index
184
149
  this.$changes.delete(index);
185
150
  this.$indexes.delete(index);
186
151
  return this.$items.delete(index);
187
- };
188
- ArraySchema.prototype.clear = function (changes) {
152
+ }
153
+ clear(changes) {
189
154
  // discard previous operations.
190
155
  this.$changes.discard(true, true);
191
156
  this.$changes.indexes = {};
@@ -204,59 +169,53 @@ var ArraySchema = /** @class */ (function () {
204
169
  this.$changes.operation({ index: 0, op: spec_1.OPERATION.CLEAR });
205
170
  // touch all structures until reach root
206
171
  this.$changes.touchParents();
207
- };
172
+ }
208
173
  /**
209
174
  * Combines two or more arrays.
210
175
  * @param items Additional items to add to the end of array1.
211
176
  */
212
- ArraySchema.prototype.concat = function () {
213
- var _a;
214
- var items = [];
215
- for (var _i = 0; _i < arguments.length; _i++) {
216
- items[_i] = arguments[_i];
217
- }
218
- return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], __read((_a = Array.from(this.$items.values())).concat.apply(_a, __spreadArray([], __read(items)))))))();
219
- };
177
+ concat(...items) {
178
+ return new ArraySchema(...Array.from(this.$items.values()).concat(...items));
179
+ }
220
180
  /**
221
181
  * Adds all the elements of an array separated by the specified separator string.
222
182
  * @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
223
183
  */
224
- ArraySchema.prototype.join = function (separator) {
184
+ join(separator) {
225
185
  return Array.from(this.$items.values()).join(separator);
226
- };
186
+ }
227
187
  /**
228
188
  * Reverses the elements in an Array.
229
189
  */
230
- ArraySchema.prototype.reverse = function () {
231
- var _this = this;
232
- var indexes = Array.from(this.$items.keys());
233
- var reversedItems = Array.from(this.$items.values()).reverse();
234
- reversedItems.forEach(function (item, i) {
235
- _this.setAt(indexes[i], item);
190
+ reverse() {
191
+ const indexes = Array.from(this.$items.keys());
192
+ const reversedItems = Array.from(this.$items.values()).reverse();
193
+ reversedItems.forEach((item, i) => {
194
+ this.setAt(indexes[i], item);
236
195
  });
237
196
  return this;
238
- };
197
+ }
239
198
  /**
240
199
  * Removes the first element from an array and returns it.
241
200
  */
242
- ArraySchema.prototype.shift = function () {
243
- var indexes = Array.from(this.$items.keys());
244
- var shiftAt = indexes.shift();
201
+ shift() {
202
+ const indexes = Array.from(this.$items.keys());
203
+ const shiftAt = indexes.shift();
245
204
  if (shiftAt === undefined) {
246
205
  return undefined;
247
206
  }
248
- var value = this.$items.get(shiftAt);
207
+ const value = this.$items.get(shiftAt);
249
208
  this.$deleteAt(shiftAt);
250
209
  return value;
251
- };
210
+ }
252
211
  /**
253
212
  * Returns a section of an array.
254
213
  * @param start The beginning of the specified portion of the array.
255
214
  * @param end The end of the specified portion of the array. This is exclusive of the element at the index 'end'.
256
215
  */
257
- ArraySchema.prototype.slice = function (start, end) {
258
- return new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], __read(Array.from(this.$items.values()).slice(start, end)))))();
259
- };
216
+ slice(start, end) {
217
+ return new ArraySchema(...Array.from(this.$items.values()).slice(start, end));
218
+ }
260
219
  /**
261
220
  * Sorts an array.
262
221
  * @param compareFn Function used to determine the order of the elements. It is expected to return
@@ -266,75 +225,62 @@ var ArraySchema = /** @class */ (function () {
266
225
  * [11,2,22,1].sort((a, b) => a - b)
267
226
  * ```
268
227
  */
269
- ArraySchema.prototype.sort = function (compareFn) {
270
- var _this = this;
271
- if (compareFn === void 0) { compareFn = DEFAULT_SORT; }
272
- var indexes = Array.from(this.$items.keys());
273
- var sortedItems = Array.from(this.$items.values()).sort(compareFn);
274
- sortedItems.forEach(function (item, i) {
275
- _this.setAt(indexes[i], item);
228
+ sort(compareFn = DEFAULT_SORT) {
229
+ const indexes = Array.from(this.$items.keys());
230
+ const sortedItems = Array.from(this.$items.values()).sort(compareFn);
231
+ sortedItems.forEach((item, i) => {
232
+ this.setAt(indexes[i], item);
276
233
  });
277
234
  return this;
278
- };
235
+ }
279
236
  /**
280
237
  * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
281
238
  * @param start The zero-based location in the array from which to start removing elements.
282
239
  * @param deleteCount The number of elements to remove.
283
240
  * @param items Elements to insert into the array in place of the deleted elements.
284
241
  */
285
- ArraySchema.prototype.splice = function (start, deleteCount) {
286
- if (deleteCount === void 0) { deleteCount = this.length - start; }
287
- var items = [];
288
- for (var _i = 2; _i < arguments.length; _i++) {
289
- items[_i - 2] = arguments[_i];
290
- }
291
- var indexes = Array.from(this.$items.keys());
292
- var removedItems = [];
293
- for (var i = start; i < start + deleteCount; i++) {
242
+ splice(start, deleteCount = this.length - start, ...items) {
243
+ const indexes = Array.from(this.$items.keys());
244
+ const removedItems = [];
245
+ for (let i = start; i < start + deleteCount; i++) {
294
246
  removedItems.push(this.$items.get(indexes[i]));
295
247
  this.$deleteAt(indexes[i]);
296
248
  }
297
249
  return removedItems;
298
- };
250
+ }
299
251
  /**
300
252
  * Inserts new elements at the start of an array.
301
253
  * @param items Elements to insert at the start of the Array.
302
254
  */
303
- ArraySchema.prototype.unshift = function () {
304
- var _this = this;
305
- var items = [];
306
- for (var _i = 0; _i < arguments.length; _i++) {
307
- items[_i] = arguments[_i];
308
- }
309
- var length = this.length;
310
- var addedLength = items.length;
255
+ unshift(...items) {
256
+ const length = this.length;
257
+ const addedLength = items.length;
311
258
  // const indexes = Array.from(this.$items.keys());
312
- var previousValues = Array.from(this.$items.values());
313
- items.forEach(function (item, i) {
314
- _this.setAt(i, item);
259
+ const previousValues = Array.from(this.$items.values());
260
+ items.forEach((item, i) => {
261
+ this.setAt(i, item);
315
262
  });
316
- previousValues.forEach(function (previousValue, i) {
317
- _this.setAt(addedLength + i, previousValue);
263
+ previousValues.forEach((previousValue, i) => {
264
+ this.setAt(addedLength + i, previousValue);
318
265
  });
319
266
  return length + addedLength;
320
- };
267
+ }
321
268
  /**
322
269
  * Returns the index of the first occurrence of a value in an array.
323
270
  * @param searchElement The value to locate in the array.
324
271
  * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
325
272
  */
326
- ArraySchema.prototype.indexOf = function (searchElement, fromIndex) {
273
+ indexOf(searchElement, fromIndex) {
327
274
  return Array.from(this.$items.values()).indexOf(searchElement, fromIndex);
328
- };
275
+ }
329
276
  /**
330
277
  * Returns the index of the last occurrence of a specified value in an array.
331
278
  * @param searchElement The value to locate in the array.
332
279
  * @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
333
280
  */
334
- ArraySchema.prototype.lastIndexOf = function (searchElement, fromIndex) {
335
- if (fromIndex === void 0) { fromIndex = this.length - 1; }
281
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
336
282
  return Array.from(this.$items.values()).lastIndexOf(searchElement, fromIndex);
337
- };
283
+ }
338
284
  /**
339
285
  * Determines whether all the members of an array satisfy the specified test.
340
286
  * @param callbackfn A function that accepts up to three arguments. The every method calls
@@ -343,9 +289,9 @@ var ArraySchema = /** @class */ (function () {
343
289
  * @param thisArg An object to which the this keyword can refer in the callbackfn function.
344
290
  * If thisArg is omitted, undefined is used as the this value.
345
291
  */
346
- ArraySchema.prototype.every = function (callbackfn, thisArg) {
292
+ every(callbackfn, thisArg) {
347
293
  return Array.from(this.$items.values()).every(callbackfn, thisArg);
348
- };
294
+ }
349
295
  /**
350
296
  * Determines whether the specified callback function returns true for any element of an array.
351
297
  * @param callbackfn A function that accepts up to three arguments. The some method calls
@@ -354,44 +300,44 @@ var ArraySchema = /** @class */ (function () {
354
300
  * @param thisArg An object to which the this keyword can refer in the callbackfn function.
355
301
  * If thisArg is omitted, undefined is used as the this value.
356
302
  */
357
- ArraySchema.prototype.some = function (callbackfn, thisArg) {
303
+ some(callbackfn, thisArg) {
358
304
  return Array.from(this.$items.values()).some(callbackfn, thisArg);
359
- };
305
+ }
360
306
  /**
361
307
  * Performs the specified action for each element in an array.
362
308
  * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
363
309
  * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
364
310
  */
365
- ArraySchema.prototype.forEach = function (callbackfn, thisArg) {
311
+ forEach(callbackfn, thisArg) {
366
312
  Array.from(this.$items.values()).forEach(callbackfn, thisArg);
367
- };
313
+ }
368
314
  /**
369
315
  * Calls a defined callback function on each element of an array, and returns an array that contains the results.
370
316
  * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
371
317
  * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
372
318
  */
373
- ArraySchema.prototype.map = function (callbackfn, thisArg) {
319
+ map(callbackfn, thisArg) {
374
320
  return Array.from(this.$items.values()).map(callbackfn, thisArg);
375
- };
376
- ArraySchema.prototype.filter = function (callbackfn, thisArg) {
321
+ }
322
+ filter(callbackfn, thisArg) {
377
323
  return Array.from(this.$items.values()).filter(callbackfn, thisArg);
378
- };
324
+ }
379
325
  /**
380
326
  * Calls the specified callback function for all the elements in an array. 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.
381
327
  * @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
382
328
  * @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.
383
329
  */
384
- ArraySchema.prototype.reduce = function (callbackfn, initialValue) {
385
- return Array.from(this.$items.values()).reduce(callbackfn, initialValue);
386
- };
330
+ reduce(callbackfn, initialValue) {
331
+ return Array.prototype.reduce.apply(Array.from(this.$items.values()), arguments);
332
+ }
387
333
  /**
388
334
  * 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.
389
335
  * @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
390
336
  * @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.
391
337
  */
392
- ArraySchema.prototype.reduceRight = function (callbackfn, initialValue) {
393
- return Array.from(this.$items.values()).reduceRight(callbackfn, initialValue);
394
- };
338
+ reduceRight(callbackfn, initialValue) {
339
+ return Array.prototype.reduceRight.apply(Array.from(this.$items.values()), arguments);
340
+ }
395
341
  /**
396
342
  * Returns the value of the first element in the array where predicate is true, and undefined
397
343
  * otherwise.
@@ -401,9 +347,9 @@ var ArraySchema = /** @class */ (function () {
401
347
  * @param thisArg If provided, it will be used as the this value for each invocation of
402
348
  * predicate. If it is not provided, undefined is used instead.
403
349
  */
404
- ArraySchema.prototype.find = function (predicate, thisArg) {
350
+ find(predicate, thisArg) {
405
351
  return Array.from(this.$items.values()).find(predicate, thisArg);
406
- };
352
+ }
407
353
  /**
408
354
  * Returns the index of the first element in the array where predicate is true, and -1
409
355
  * otherwise.
@@ -413,9 +359,9 @@ var ArraySchema = /** @class */ (function () {
413
359
  * @param thisArg If provided, it will be used as the this value for each invocation of
414
360
  * predicate. If it is not provided, undefined is used instead.
415
361
  */
416
- ArraySchema.prototype.findIndex = function (predicate, thisArg) {
362
+ findIndex(predicate, thisArg) {
417
363
  return Array.from(this.$items.values()).findIndex(predicate, thisArg);
418
- };
364
+ }
419
365
  /**
420
366
  * Returns the this object after filling the section identified by start and end with value
421
367
  * @param value value to fill array section with
@@ -424,14 +370,14 @@ var ArraySchema = /** @class */ (function () {
424
370
  * @param end index to stop filling the array at. If end is negative, it is treated as
425
371
  * length+end.
426
372
  */
427
- ArraySchema.prototype.fill = function (value, start, end) {
373
+ fill(value, start, end) {
428
374
  //
429
375
  // TODO
430
376
  //
431
377
  throw new Error("ArraySchema#fill() not implemented");
432
378
  // this.$items.fill(value, start, end);
433
379
  return this;
434
- };
380
+ }
435
381
  /**
436
382
  * Returns the this object after copying a section of the array identified by start and end
437
383
  * to the same array starting at position target
@@ -441,49 +387,46 @@ var ArraySchema = /** @class */ (function () {
441
387
  * is treated as length+end.
442
388
  * @param end If not specified, length of the this object is used as its default value.
443
389
  */
444
- ArraySchema.prototype.copyWithin = function (target, start, end) {
390
+ copyWithin(target, start, end) {
445
391
  //
446
392
  // TODO
447
393
  //
448
394
  throw new Error("ArraySchema#copyWithin() not implemented");
449
395
  return this;
450
- };
396
+ }
451
397
  /**
452
398
  * Returns a string representation of an array.
453
399
  */
454
- ArraySchema.prototype.toString = function () { return this.$items.toString(); };
400
+ toString() { return this.$items.toString(); }
455
401
  /**
456
402
  * Returns a string representation of an array. The elements are converted to string using their toLocalString methods.
457
403
  */
458
- ArraySchema.prototype.toLocaleString = function () { return this.$items.toLocaleString(); };
404
+ toLocaleString() { return this.$items.toLocaleString(); }
459
405
  ;
460
406
  /** Iterator */
461
- ArraySchema.prototype[Symbol.iterator] = function () {
407
+ [Symbol.iterator]() {
462
408
  return Array.from(this.$items.values())[Symbol.iterator]();
463
- };
464
- ArraySchema.prototype[Symbol.unscopables] = function () {
465
- return this.$items[Symbol.unscopables]();
466
- };
409
+ }
467
410
  /**
468
411
  * Returns an iterable of key, value pairs for every entry in the array
469
412
  */
470
- ArraySchema.prototype.entries = function () { return this.$items.entries(); };
413
+ entries() { return this.$items.entries(); }
471
414
  /**
472
415
  * Returns an iterable of keys in the array
473
416
  */
474
- ArraySchema.prototype.keys = function () { return this.$items.keys(); };
417
+ keys() { return this.$items.keys(); }
475
418
  /**
476
419
  * Returns an iterable of values in the array
477
420
  */
478
- ArraySchema.prototype.values = function () { return this.$items.values(); };
421
+ values() { return this.$items.values(); }
479
422
  /**
480
423
  * Determines whether an array includes a certain element, returning true or false as appropriate.
481
424
  * @param searchElement The element to search for.
482
425
  * @param fromIndex The position in this array at which to begin searching for searchElement.
483
426
  */
484
- ArraySchema.prototype.includes = function (searchElement, fromIndex) {
427
+ includes(searchElement, fromIndex) {
485
428
  return Array.from(this.$items.values()).includes(searchElement, fromIndex);
486
- };
429
+ }
487
430
  /**
488
431
  * Calls a defined callback function on each element of an array. Then, flattens the result into
489
432
  * a new array.
@@ -495,10 +438,10 @@ var ArraySchema = /** @class */ (function () {
495
438
  * thisArg is omitted, undefined is used as the this value.
496
439
  */
497
440
  // @ts-ignore
498
- ArraySchema.prototype.flatMap = function (callback, thisArg) {
441
+ flatMap(callback, thisArg) {
499
442
  // @ts-ignore
500
443
  throw new Error("ArraySchema#flatMap() is not supported.");
501
- };
444
+ }
502
445
  /**
503
446
  * Returns a new array with all sub-array elements concatenated into it recursively up to the
504
447
  * specified depth.
@@ -506,54 +449,53 @@ var ArraySchema = /** @class */ (function () {
506
449
  * @param depth The maximum recursion depth
507
450
  */
508
451
  // @ts-ignore
509
- ArraySchema.prototype.flat = function (depth) {
452
+ flat(depth) {
510
453
  // @ts-ignore
511
454
  throw new Error("ArraySchema#flat() is not supported.");
512
- };
455
+ }
513
456
  // get size () {
514
457
  // return this.$items.size;
515
458
  // }
516
- ArraySchema.prototype.setIndex = function (index, key) {
459
+ setIndex(index, key) {
517
460
  this.$indexes.set(index, key);
518
- };
519
- ArraySchema.prototype.getIndex = function (index) {
461
+ }
462
+ getIndex(index) {
520
463
  return this.$indexes.get(index);
521
- };
522
- ArraySchema.prototype.getByIndex = function (index) {
464
+ }
465
+ getByIndex(index) {
523
466
  return this.$items.get(this.$indexes.get(index));
524
- };
525
- ArraySchema.prototype.deleteByIndex = function (index) {
526
- var key = this.$indexes.get(index);
467
+ }
468
+ deleteByIndex(index) {
469
+ const key = this.$indexes.get(index);
527
470
  this.$items.delete(key);
528
471
  this.$indexes.delete(index);
529
- };
530
- ArraySchema.prototype.toArray = function () {
472
+ }
473
+ toArray() {
531
474
  return Array.from(this.$items.values());
532
- };
533
- ArraySchema.prototype.toJSON = function () {
534
- return this.toArray().map(function (value) {
475
+ }
476
+ toJSON() {
477
+ return this.toArray().map((value) => {
535
478
  return (typeof (value['toJSON']) === "function")
536
479
  ? value['toJSON']()
537
480
  : value;
538
481
  });
539
- };
482
+ }
540
483
  //
541
484
  // Decoding utilities
542
485
  //
543
- ArraySchema.prototype.clone = function (isDecoding) {
544
- var cloned;
486
+ clone(isDecoding) {
487
+ let cloned;
545
488
  if (isDecoding) {
546
- cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], __read(Array.from(this.$items.values())))))();
489
+ cloned = new ArraySchema(...Array.from(this.$items.values()));
547
490
  }
548
491
  else {
549
- cloned = new (ArraySchema.bind.apply(ArraySchema, __spreadArray([void 0], __read(this.map(function (item) { return ((item['$changes'])
492
+ cloned = new ArraySchema(...this.map(item => ((item['$changes'])
550
493
  ? item.clone()
551
- : item); })))))();
494
+ : item)));
552
495
  }
553
496
  return cloned;
554
- };
497
+ }
555
498
  ;
556
- return ArraySchema;
557
- }());
499
+ }
558
500
  exports.ArraySchema = ArraySchema;
559
501
  //# sourceMappingURL=ArraySchema.js.map