@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/lib/types/ArraySchema.js
CHANGED
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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:
|
|
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:
|
|
36
|
+
set: (obj, prop, setValue) => {
|
|
58
37
|
if (typeof (prop) !== "symbol" &&
|
|
59
38
|
!isNaN(prop)) {
|
|
60
|
-
|
|
61
|
-
|
|
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:
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
136
|
-
|
|
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 =
|
|
139
|
-
|
|
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
|
-
|
|
147
|
-
|
|
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
|
-
|
|
119
|
+
const value = this.$items.get(key);
|
|
154
120
|
this.$items.delete(key);
|
|
155
121
|
return value;
|
|
156
|
-
}
|
|
157
|
-
|
|
122
|
+
}
|
|
123
|
+
at(index) {
|
|
158
124
|
//
|
|
159
125
|
// FIXME: this should be O(1)
|
|
160
126
|
//
|
|
161
|
-
|
|
127
|
+
const key = Array.from(this.$items.keys())[index];
|
|
162
128
|
return this.$items.get(key);
|
|
163
|
-
}
|
|
164
|
-
|
|
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
|
-
|
|
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
|
-
|
|
176
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
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
|
-
|
|
258
|
-
return new
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
for (
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
313
|
-
items.forEach(
|
|
314
|
-
|
|
259
|
+
const previousValues = Array.from(this.$items.values());
|
|
260
|
+
items.forEach((item, i) => {
|
|
261
|
+
this.setAt(i, item);
|
|
315
262
|
});
|
|
316
|
-
previousValues.forEach(
|
|
317
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
319
|
+
map(callbackfn, thisArg) {
|
|
374
320
|
return Array.from(this.$items.values()).map(callbackfn, thisArg);
|
|
375
|
-
}
|
|
376
|
-
|
|
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
|
-
|
|
385
|
-
return Array.from(this.$items.values())
|
|
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
|
-
|
|
393
|
-
return Array.from(this.$items.values())
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
404
|
+
toLocaleString() { return this.$items.toLocaleString(); }
|
|
459
405
|
;
|
|
460
406
|
/** Iterator */
|
|
461
|
-
|
|
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
|
-
|
|
413
|
+
entries() { return this.$items.entries(); }
|
|
471
414
|
/**
|
|
472
415
|
* Returns an iterable of keys in the array
|
|
473
416
|
*/
|
|
474
|
-
|
|
417
|
+
keys() { return this.$items.keys(); }
|
|
475
418
|
/**
|
|
476
419
|
* Returns an iterable of values in the array
|
|
477
420
|
*/
|
|
478
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
459
|
+
setIndex(index, key) {
|
|
517
460
|
this.$indexes.set(index, key);
|
|
518
|
-
}
|
|
519
|
-
|
|
461
|
+
}
|
|
462
|
+
getIndex(index) {
|
|
520
463
|
return this.$indexes.get(index);
|
|
521
|
-
}
|
|
522
|
-
|
|
464
|
+
}
|
|
465
|
+
getByIndex(index) {
|
|
523
466
|
return this.$items.get(this.$indexes.get(index));
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
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
|
-
|
|
472
|
+
}
|
|
473
|
+
toArray() {
|
|
531
474
|
return Array.from(this.$items.values());
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
return this.toArray().map(
|
|
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
|
-
|
|
544
|
-
|
|
486
|
+
clone(isDecoding) {
|
|
487
|
+
let cloned;
|
|
545
488
|
if (isDecoding) {
|
|
546
|
-
cloned = new
|
|
489
|
+
cloned = new ArraySchema(...Array.from(this.$items.values()));
|
|
547
490
|
}
|
|
548
491
|
else {
|
|
549
|
-
cloned = new
|
|
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
|
-
|
|
557
|
-
}());
|
|
499
|
+
}
|
|
558
500
|
exports.ArraySchema = ArraySchema;
|
|
559
501
|
//# sourceMappingURL=ArraySchema.js.map
|