@colyseus/schema 3.0.0-alpha.28 → 3.0.0-alpha.29
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 +109 -84
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +109 -84
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +109 -84
- package/lib/Metadata.d.ts +3 -0
- package/lib/Metadata.js.map +1 -1
- package/lib/Reflection.d.ts +1 -1
- package/lib/Reflection.js +4 -3
- package/lib/Reflection.js.map +1 -1
- package/lib/annotations.d.ts +0 -19
- package/lib/annotations.js +4 -106
- package/lib/annotations.js.map +1 -1
- package/lib/bench_encode.js +54 -27
- package/lib/bench_encode.js.map +1 -1
- package/lib/decoder/Decoder.d.ts +1 -1
- package/lib/decoder/Decoder.js +2 -2
- package/lib/decoder/Decoder.js.map +1 -1
- package/lib/encoder/ChangeTree.d.ts +1 -12
- package/lib/encoder/ChangeTree.js +24 -51
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/Encoder.d.ts +6 -5
- package/lib/encoder/Encoder.js +28 -19
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/encoder/Root.d.ts +17 -0
- package/lib/encoder/Root.js +44 -0
- package/lib/encoder/Root.js.map +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/types/TypeContext.d.ts +23 -0
- package/lib/types/TypeContext.js +109 -0
- package/lib/types/TypeContext.js.map +1 -0
- package/lib/types/custom/ArraySchema.js +0 -1
- package/lib/types/custom/ArraySchema.js.map +1 -1
- package/package.json +1 -1
- package/src/Metadata.ts +1 -0
- package/src/Reflection.ts +2 -1
- package/src/annotations.ts +1 -126
- package/src/bench_encode.ts +47 -16
- package/src/decoder/Decoder.ts +1 -1
- package/src/encoder/ChangeTree.ts +30 -59
- package/src/encoder/Encoder.ts +36 -23
- package/src/encoder/Root.ts +51 -0
- package/src/index.ts +3 -11
- package/src/types/TypeContext.ts +127 -0
- package/src/types/custom/ArraySchema.ts +0 -1
|
@@ -7,6 +7,7 @@ import type { ArraySchema } from "../types/custom/ArraySchema";
|
|
|
7
7
|
import type { CollectionSchema } from "../types/custom/CollectionSchema";
|
|
8
8
|
import type { SetSchema } from "../types/custom/SetSchema";
|
|
9
9
|
|
|
10
|
+
import { Root } from "./Root";
|
|
10
11
|
import { Metadata } from "../Metadata";
|
|
11
12
|
import type { EncodeOperation } from "./EncodeOperation";
|
|
12
13
|
import type { DecodeOperation } from "../decoder/DecodeOperation";
|
|
@@ -26,53 +27,6 @@ export type Ref = Schema
|
|
|
26
27
|
| CollectionSchema
|
|
27
28
|
| SetSchema;
|
|
28
29
|
|
|
29
|
-
export class Root {
|
|
30
|
-
protected nextUniqueId: number = 0;
|
|
31
|
-
refCount = new WeakMap<ChangeTree, number>();
|
|
32
|
-
|
|
33
|
-
// all changes
|
|
34
|
-
allChanges = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
35
|
-
allFilteredChanges = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
36
|
-
|
|
37
|
-
// pending changes to be encoded
|
|
38
|
-
changes = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
39
|
-
filteredChanges = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
40
|
-
|
|
41
|
-
getNextUniqueId() {
|
|
42
|
-
return this.nextUniqueId++;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
add (changeTree: ChangeTree) {
|
|
46
|
-
const refCount = this.refCount.get(changeTree) || 0;
|
|
47
|
-
this.refCount.set(changeTree, refCount + 1);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
remove(changeTree: ChangeTree) {
|
|
51
|
-
const refCount = this.refCount.get(changeTree);
|
|
52
|
-
if (refCount <= 1) {
|
|
53
|
-
this.allChanges.delete(changeTree);
|
|
54
|
-
this.changes.delete(changeTree);
|
|
55
|
-
|
|
56
|
-
if (changeTree.isFiltered || changeTree.isPartiallyFiltered) {
|
|
57
|
-
this.allFilteredChanges.delete(changeTree);
|
|
58
|
-
this.filteredChanges.delete(changeTree);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.refCount.delete(changeTree);
|
|
62
|
-
|
|
63
|
-
} else {
|
|
64
|
-
this.refCount.set(changeTree, refCount - 1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
changeTree.forEachChild((child, _) =>
|
|
68
|
-
this.remove(child));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
clear() {
|
|
72
|
-
this.changes.clear();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
30
|
export class ChangeTree<T extends Ref=any> {
|
|
77
31
|
ref: T;
|
|
78
32
|
refId: number;
|
|
@@ -122,9 +76,6 @@ export class ChangeTree<T extends Ref=any> {
|
|
|
122
76
|
if (this.isFiltered || this.isPartiallyFiltered) {
|
|
123
77
|
this.root.allFilteredChanges.set(this, this.allFilteredChanges);
|
|
124
78
|
this.root.filteredChanges.set(this, this.filteredChanges);
|
|
125
|
-
|
|
126
|
-
// } else {
|
|
127
|
-
// this.root.allChanges.set(this, this.allChanges);
|
|
128
79
|
}
|
|
129
80
|
|
|
130
81
|
if (!this.isFiltered) {
|
|
@@ -453,19 +404,39 @@ export class ChangeTree<T extends Ref=any> {
|
|
|
453
404
|
// Detect if current structure has "filters" declared
|
|
454
405
|
this.isPartiallyFiltered = (this.ref['constructor']?.[Symbol.metadata]?.[-2] !== undefined);
|
|
455
406
|
|
|
456
|
-
|
|
407
|
+
if (parent && !Metadata.isValidInstance(parent)) {
|
|
408
|
+
const parentChangeTree = parent[$changes];
|
|
409
|
+
parent = parentChangeTree.parent;
|
|
410
|
+
parentIndex = parentChangeTree.parentIndex;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const parentMetadata = parent?.['constructor']?.[Symbol.metadata];
|
|
457
414
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
415
|
+
this.isFiltered = (
|
|
416
|
+
parent &&
|
|
417
|
+
parentMetadata?.[-2]?.includes(parentIndex)
|
|
418
|
+
);
|
|
461
419
|
|
|
462
|
-
|
|
463
|
-
const isParentOwned = metadata?.[fieldName]?.tag !== undefined;
|
|
420
|
+
// this.isFiltered = this.ref['constructor']?.[Symbol.metadata]?.[-4];
|
|
464
421
|
|
|
465
|
-
|
|
422
|
+
// // Detect if parent has "filters" declared
|
|
423
|
+
// while (parent && !this.isFiltered) {
|
|
424
|
+
// const metadata: Metadata = parent['constructor'][Symbol.metadata];
|
|
425
|
+
// // this.isFiltered = metadata?.[-4];
|
|
466
426
|
|
|
467
|
-
|
|
468
|
-
|
|
427
|
+
// const fieldName = metadata?.[parentIndex];
|
|
428
|
+
// const isParentOwned = metadata?.[fieldName]?.tag !== undefined;
|
|
429
|
+
// this.isFiltered = isParentOwned || parent[$changes].isFiltered; // metadata?.[-2]
|
|
430
|
+
|
|
431
|
+
// parent = parent[$changes].parent;
|
|
432
|
+
// };
|
|
433
|
+
|
|
434
|
+
// console.log("ChangeTree.checkIsFiltered", {
|
|
435
|
+
// parent: parent?.constructor.name,
|
|
436
|
+
// ref: this.ref.constructor.name,
|
|
437
|
+
// isFiltered: this.isFiltered,
|
|
438
|
+
// isPartiallyFiltered: this.isPartiallyFiltered,
|
|
439
|
+
// });
|
|
469
440
|
|
|
470
441
|
//
|
|
471
442
|
// TODO: refactor this!
|
package/src/encoder/Encoder.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import type { Schema } from "../Schema";
|
|
2
|
-
import { TypeContext } from "../
|
|
2
|
+
import { TypeContext } from "../types/TypeContext";
|
|
3
3
|
import { $changes, $encoder, $filter } from "../types/symbols";
|
|
4
4
|
|
|
5
5
|
import * as encode from "../encoding/encode";
|
|
6
6
|
import type { Iterator } from "../encoding/decode";
|
|
7
7
|
|
|
8
8
|
import { OPERATION, SWITCH_TO_STRUCTURE, TYPE_ID } from '../encoding/spec';
|
|
9
|
-
import { Root } from "./
|
|
9
|
+
import { Root } from "./Root";
|
|
10
10
|
import { getNextPowerOf2 } from "../utils";
|
|
11
|
+
|
|
11
12
|
import type { StateView } from "./StateView";
|
|
12
|
-
import { Metadata } from "../Metadata";
|
|
13
|
+
import type { Metadata } from "../Metadata";
|
|
14
|
+
import type { ChangeTree } from "./ChangeTree";
|
|
13
15
|
|
|
14
16
|
export class Encoder<T extends Schema = any> {
|
|
15
17
|
static BUFFER_SIZE = 8 * 1024;// 8KB
|
|
@@ -21,13 +23,13 @@ export class Encoder<T extends Schema = any> {
|
|
|
21
23
|
root: Root;
|
|
22
24
|
|
|
23
25
|
constructor(state: T) {
|
|
24
|
-
this.root = new Root();
|
|
25
26
|
|
|
26
27
|
//
|
|
27
28
|
// TODO: cache and restore "Context" based on root schema
|
|
28
29
|
// (to avoid creating a new context for every new room)
|
|
29
30
|
//
|
|
30
31
|
this.context = new TypeContext(state.constructor as typeof Schema);
|
|
32
|
+
this.root = new Root(this.context);
|
|
31
33
|
|
|
32
34
|
this.setState(state);
|
|
33
35
|
|
|
@@ -80,7 +82,8 @@ export class Encoder<T extends Schema = any> {
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
// skip root `refId` if it's the first change tree
|
|
83
|
-
|
|
85
|
+
// (unless it "hasView", which will need to revisit the root)
|
|
86
|
+
if (hasView || changeTree !== rootChangeTree) {
|
|
84
87
|
buffer[it.offset++] = SWITCH_TO_STRUCTURE & 255;
|
|
85
88
|
encode.number(buffer, changeTree.refId, it);
|
|
86
89
|
}
|
|
@@ -124,7 +127,6 @@ export class Encoder<T extends Schema = any> {
|
|
|
124
127
|
Encoder.BUFFER_SIZE = ${Math.round(newSize / 1024)} * 1024; // ${Math.round(newSize / 1024)} KB
|
|
125
128
|
`);
|
|
126
129
|
|
|
127
|
-
|
|
128
130
|
//
|
|
129
131
|
// resize buffer and re-encode (TODO: can we avoid re-encoding here?)
|
|
130
132
|
//
|
|
@@ -153,11 +155,8 @@ export class Encoder<T extends Schema = any> {
|
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
encodeAll(it: Iterator = { offset: 0 }, buffer: Buffer = this.sharedBuffer) {
|
|
156
|
-
// console.log(
|
|
157
|
-
|
|
158
|
-
// Array.from(this.root.allChanges.entries()).map((item) => {
|
|
159
|
-
// console.log("->", { ref: item[0].ref.constructor.name, refId: item[0].refId, changes: item[1].size });
|
|
160
|
-
// });
|
|
158
|
+
// console.log(`\nencodeAll(), this.root.allChanges (${this.root.allChanges.size})`);
|
|
159
|
+
// this.debugChanges("allChanges");
|
|
161
160
|
|
|
162
161
|
return this.encode(it, undefined, buffer, this.root.allChanges, true);
|
|
163
162
|
}
|
|
@@ -165,11 +164,11 @@ export class Encoder<T extends Schema = any> {
|
|
|
165
164
|
encodeAllView(view: StateView, sharedOffset: number, it: Iterator, bytes = this.sharedBuffer) {
|
|
166
165
|
const viewOffset = it.offset;
|
|
167
166
|
|
|
168
|
-
// console.log(
|
|
169
|
-
// this.
|
|
167
|
+
// console.log(`\nencodeAllView(), this.root.allFilteredChanges (${this.root.allFilteredChanges.size})`);
|
|
168
|
+
// this.debugChanges("allFilteredChanges");
|
|
170
169
|
|
|
171
170
|
// try to encode "filtered" changes
|
|
172
|
-
this.encode(it, view, bytes, this.root.allFilteredChanges, true);
|
|
171
|
+
this.encode(it, view, bytes, this.root.allFilteredChanges, true, viewOffset);
|
|
173
172
|
|
|
174
173
|
return Buffer.concat([
|
|
175
174
|
bytes.subarray(0, sharedOffset),
|
|
@@ -177,21 +176,35 @@ export class Encoder<T extends Schema = any> {
|
|
|
177
176
|
]);
|
|
178
177
|
}
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
179
|
+
debugChanges(
|
|
180
|
+
field: "changes" | "allFilteredChanges" | "allChanges" | "filteredChanges" | Map<ChangeTree, Map<number, OPERATION>>
|
|
181
|
+
) {
|
|
182
|
+
const changeSet = (typeof (field) === "string")
|
|
183
|
+
? this.root[field]
|
|
184
|
+
: field;
|
|
185
|
+
|
|
186
|
+
Array.from(changeSet.entries()).map((item) => {
|
|
187
|
+
const metadata: Metadata = item[0].ref.constructor[Symbol.metadata];
|
|
188
|
+
console.log("->", { ref: item[0].ref.constructor.name, refId: item[0].refId, changes: item[1].size });
|
|
189
|
+
item[1].forEach((op, index) => {
|
|
190
|
+
console.log(" ->", {
|
|
191
|
+
index,
|
|
192
|
+
field: metadata?.[index],
|
|
193
|
+
op: OPERATION[op],
|
|
194
|
+
});
|
|
195
|
+
});
|
|
189
196
|
});
|
|
190
197
|
}
|
|
191
198
|
|
|
192
199
|
encodeView(view: StateView, sharedOffset: number, it: Iterator, bytes = this.sharedBuffer) {
|
|
193
200
|
const viewOffset = it.offset;
|
|
194
201
|
|
|
202
|
+
// console.log(`\nencodeView(), view.changes (${view.changes.size})`);
|
|
203
|
+
// this.debugChanges(view.changes);
|
|
204
|
+
|
|
205
|
+
// console.log(`\nencodeView(), this.root.filteredChanges (${this.root.filteredChanges.size})`);
|
|
206
|
+
// this.debugChanges("filteredChanges");
|
|
207
|
+
|
|
195
208
|
// encode visibility changes (add/remove for this view)
|
|
196
209
|
const viewChangesIterator = view.changes.entries();
|
|
197
210
|
for (const [changeTree, changes] of viewChangesIterator) {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { OPERATION } from "../encoding/spec";
|
|
2
|
+
import { TypeContext } from "../types/TypeContext";
|
|
3
|
+
import { ChangeTree } from "./ChangeTree";
|
|
4
|
+
|
|
5
|
+
export class Root {
|
|
6
|
+
protected nextUniqueId: number = 0;
|
|
7
|
+
refCount = new WeakMap<ChangeTree, number>();
|
|
8
|
+
|
|
9
|
+
// all changes
|
|
10
|
+
allChanges = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
11
|
+
allFilteredChanges = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
12
|
+
|
|
13
|
+
// pending changes to be encoded
|
|
14
|
+
changes = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
15
|
+
filteredChanges = new Map<ChangeTree, Map<number, OPERATION>>();
|
|
16
|
+
|
|
17
|
+
constructor(public types: TypeContext) { }
|
|
18
|
+
|
|
19
|
+
getNextUniqueId() {
|
|
20
|
+
return this.nextUniqueId++;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
add(changeTree: ChangeTree) {
|
|
24
|
+
const refCount = this.refCount.get(changeTree) || 0;
|
|
25
|
+
this.refCount.set(changeTree, refCount + 1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
remove(changeTree: ChangeTree) {
|
|
29
|
+
const refCount = this.refCount.get(changeTree);
|
|
30
|
+
if (refCount <= 1) {
|
|
31
|
+
this.allChanges.delete(changeTree);
|
|
32
|
+
this.changes.delete(changeTree);
|
|
33
|
+
|
|
34
|
+
if (changeTree.isFiltered || changeTree.isPartiallyFiltered) {
|
|
35
|
+
this.allFilteredChanges.delete(changeTree);
|
|
36
|
+
this.filteredChanges.delete(changeTree);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.refCount.delete(changeTree);
|
|
40
|
+
|
|
41
|
+
} else {
|
|
42
|
+
this.refCount.set(changeTree, refCount - 1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
changeTree.forEachChild((child, _) => this.remove(child));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
clear() {
|
|
49
|
+
this.changes.clear();
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -42,18 +42,10 @@ export {
|
|
|
42
42
|
ReflectionField,
|
|
43
43
|
} from "./Reflection";
|
|
44
44
|
|
|
45
|
+
// Annotations, Metadata and TypeContext
|
|
45
46
|
export { Metadata } from "./Metadata";
|
|
46
|
-
|
|
47
|
-
export {
|
|
48
|
-
// Annotations
|
|
49
|
-
type,
|
|
50
|
-
deprecated,
|
|
51
|
-
defineTypes,
|
|
52
|
-
view,
|
|
53
|
-
|
|
54
|
-
// Internals
|
|
55
|
-
TypeContext,
|
|
56
|
-
} from "./annotations";
|
|
47
|
+
export { type, deprecated, defineTypes, view, } from "./annotations";
|
|
48
|
+
export { TypeContext } from "./types/TypeContext";
|
|
57
49
|
|
|
58
50
|
// Annotation types
|
|
59
51
|
export type { DefinitionType, PrimitiveType, Definition, } from "./annotations";
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Metadata } from "../Metadata";
|
|
2
|
+
import { Schema } from "../Schema";
|
|
3
|
+
|
|
4
|
+
export class TypeContext {
|
|
5
|
+
types: { [id: number]: typeof Schema; } = {};
|
|
6
|
+
schemas = new Map<typeof Schema, number>();
|
|
7
|
+
|
|
8
|
+
hasFilters: boolean = false;
|
|
9
|
+
parentFiltered: {[typeIdAndParentIndex: string]: boolean} = {};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* For inheritance support
|
|
13
|
+
* Keeps track of which classes extends which. (parent -> children)
|
|
14
|
+
*/
|
|
15
|
+
static inheritedTypes = new Map<typeof Schema, Set<typeof Schema>>();
|
|
16
|
+
|
|
17
|
+
static register(target: typeof Schema) {
|
|
18
|
+
const parent = Object.getPrototypeOf(target);
|
|
19
|
+
if (parent !== Schema) {
|
|
20
|
+
let inherits = TypeContext.inheritedTypes.get(parent);
|
|
21
|
+
if (!inherits) {
|
|
22
|
+
inherits = new Set<typeof Schema>();
|
|
23
|
+
TypeContext.inheritedTypes.set(parent, inherits);
|
|
24
|
+
}
|
|
25
|
+
inherits.add(target);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(rootClass?: typeof Schema) {
|
|
30
|
+
if (rootClass) {
|
|
31
|
+
this.discoverTypes(rootClass);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
has(schema: typeof Schema) {
|
|
36
|
+
return this.schemas.has(schema);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get(typeid: number) {
|
|
40
|
+
return this.types[typeid];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
add(schema: typeof Schema, typeid: number = this.schemas.size) {
|
|
44
|
+
// skip if already registered
|
|
45
|
+
if (this.schemas.has(schema)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.types[typeid] = schema;
|
|
50
|
+
|
|
51
|
+
//
|
|
52
|
+
// Workaround to allow using an empty Schema (with no `@type()` fields)
|
|
53
|
+
//
|
|
54
|
+
if (schema[Symbol.metadata] === undefined) {
|
|
55
|
+
Metadata.init(schema);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.schemas.set(schema, typeid);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getTypeId(klass: typeof Schema) {
|
|
63
|
+
return this.schemas.get(klass);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private discoverTypes(klass: typeof Schema, parentIndex?: number, parentFieldViewTag?: number) {
|
|
67
|
+
if (!this.add(klass)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// add classes inherited from this base class
|
|
72
|
+
TypeContext.inheritedTypes.get(klass)?.forEach((child) => {
|
|
73
|
+
this.discoverTypes(child, parentIndex, parentFieldViewTag);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const metadata: Metadata = (klass[Symbol.metadata] ??= {});
|
|
77
|
+
|
|
78
|
+
// if any schema/field has filters, mark "context" as having filters.
|
|
79
|
+
if (metadata[-2]) {
|
|
80
|
+
this.hasFilters = true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (parentFieldViewTag !== undefined) {
|
|
84
|
+
this.parentFiltered[`${this.schemas.get(klass)}-${parentIndex}`] = true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for (const field in metadata) {
|
|
88
|
+
// //
|
|
89
|
+
// // Modify the field's metadata to include the parent field's view tag
|
|
90
|
+
// //
|
|
91
|
+
// if (
|
|
92
|
+
// parentFieldViewTag !== undefined &&
|
|
93
|
+
// metadata[field].tag === undefined
|
|
94
|
+
// ) {
|
|
95
|
+
// metadata[field].tag = parentFieldViewTag;
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
const fieldType = metadata[field].type;
|
|
99
|
+
const viewTag = metadata[field].tag;
|
|
100
|
+
|
|
101
|
+
if (typeof (fieldType) === "string") {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (Array.isArray(fieldType)) {
|
|
106
|
+
const type = fieldType[0];
|
|
107
|
+
if (type === "string") {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
this.discoverTypes(type as typeof Schema, metadata[field].index, viewTag);
|
|
111
|
+
|
|
112
|
+
} else if (typeof (fieldType) === "function") {
|
|
113
|
+
this.discoverTypes(fieldType as typeof Schema, viewTag);
|
|
114
|
+
|
|
115
|
+
} else {
|
|
116
|
+
const type = Object.values(fieldType)[0];
|
|
117
|
+
|
|
118
|
+
// skip primitive types
|
|
119
|
+
if (typeof (type) === "string") {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.discoverTypes(type as typeof Schema, metadata[field].index, viewTag);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -163,7 +163,6 @@ export class ArraySchema<V = any> implements Array<V>, Collection<number, V> {
|
|
|
163
163
|
|
|
164
164
|
const changeTree = this[$changes];
|
|
165
165
|
changeTree.indexedOperation(length, OPERATION.ADD, this.items.length);
|
|
166
|
-
// changeTree.indexes[length] = length;
|
|
167
166
|
|
|
168
167
|
this.items.push(value);
|
|
169
168
|
this.tmpItems.push(value);
|