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