@colyseus/schema 5.0.11 → 5.0.12
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/Metadata.d.ts +20 -12
- package/build/annotations.d.ts +23 -10
- package/build/codegen/cli.cjs +615 -204
- package/build/codegen/cli.cjs.map +1 -1
- package/build/codegen/languages/dart.d.ts +20 -0
- package/build/codegen/types.d.ts +20 -0
- package/build/decoder/Resync.d.ts +3 -3
- package/build/encoder/ChangeTree.d.ts +22 -9
- package/build/encoder/EncodeDescriptor.d.ts +11 -12
- package/build/encoder/StateView.d.ts +26 -2
- package/build/encoder/changeTree/inheritedFlags.d.ts +1 -1
- package/build/encoder/streaming.d.ts +7 -0
- package/build/index.cjs +374 -232
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +374 -232
- package/build/index.mjs +373 -231
- package/build/index.mjs.map +1 -1
- package/build/types/builder.d.ts +31 -22
- package/build/types/custom/StreamSchema.d.ts +1 -1
- package/build/types/symbols.d.ts +4 -10
- package/package.json +1 -1
- package/src/Metadata.ts +58 -31
- package/src/annotations.ts +56 -32
- package/src/codegen/api.ts +2 -1
- package/src/codegen/languages/c.ts +21 -3
- package/src/codegen/languages/csharp.ts +7 -1
- package/src/codegen/languages/dart.ts +274 -0
- package/src/codegen/languages/haxe.ts +7 -1
- package/src/codegen/languages/lua.ts +16 -4
- package/src/codegen/languages/ts.ts +5 -0
- package/src/codegen/parser.ts +97 -3
- package/src/codegen/types.ts +24 -0
- package/src/decoder/Resync.ts +8 -8
- package/src/encoder/ChangeRecorder.ts +1 -1
- package/src/encoder/ChangeTree.ts +41 -26
- package/src/encoder/EncodeDescriptor.ts +17 -38
- package/src/encoder/EncodeOperation.ts +3 -1
- package/src/encoder/Encoder.ts +97 -21
- package/src/encoder/Root.ts +18 -20
- package/src/encoder/StateView.ts +102 -12
- package/src/encoder/changeTree/inheritedFlags.ts +10 -10
- package/src/encoder/changeTree/liveIteration.ts +9 -9
- package/src/encoder/streaming.ts +8 -0
- package/src/encoding/spec.ts +1 -1
- package/src/index.ts +2 -2
- package/src/types/builder.ts +35 -31
- package/src/types/custom/StreamSchema.ts +1 -1
- package/src/types/symbols.ts +4 -11
- package/src/bench_bloat.ts +0 -173
- package/src/bench_churn.ts +0 -121
- package/src/bench_decode.ts +0 -221
- package/src/bench_decode_mem.ts +0 -165
- package/src/bench_encode.ts +0 -108
- package/src/bench_init.ts +0 -150
- package/src/bench_static.ts +0 -109
- package/src/bench_stream.ts +0 -295
- package/src/bench_view_cmp.ts +0 -142
package/build/Metadata.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { DefinitionType } from "./annotations.js";
|
|
2
2
|
import { TypeDefinition } from "./types/registry.js";
|
|
3
|
-
import { $descriptors, $encoders, $fieldIndexesByViewTag, $numFields, $refTypeFieldIndexes, $
|
|
3
|
+
import { $descriptors, $encoders, $fieldIndexesByViewTag, $numFields, $refTypeFieldIndexes, $fullStateOnlyFieldIndexes, $streamFieldIndexes, $streamPriorities, $patchOnlyFieldIndexes, $unreliableFieldIndexes, $viewFieldIndexes } from "./types/symbols.js";
|
|
4
|
+
/**
|
|
5
|
+
* Field indexes ride in the low 6 bits of the operation byte
|
|
6
|
+
* (`(index | operation) & 255`), which leaves room for 0..63. Index 63 is
|
|
7
|
+
* given up: `DELETE_AND_ADD | 63` is 255, the same byte the decoder claims
|
|
8
|
+
* as SWITCH_TO_STRUCTURE before any field decoder sees it. Every nullable
|
|
9
|
+
* field can produce that operation (delete-then-set in one tick merges to
|
|
10
|
+
* DELETE_AND_ADD), so the slot is unusable rather than partly usable.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MAX_FIELDS = 63;
|
|
4
13
|
export type MetadataField = {
|
|
5
14
|
type: DefinitionType;
|
|
6
15
|
name: string;
|
|
7
16
|
index: number;
|
|
8
17
|
tag?: number;
|
|
9
18
|
unreliable?: boolean;
|
|
10
|
-
|
|
19
|
+
patchOnly?: boolean;
|
|
11
20
|
deprecated?: boolean;
|
|
12
|
-
|
|
13
|
-
static?: boolean;
|
|
21
|
+
fullStateOnly?: boolean;
|
|
14
22
|
stream?: boolean;
|
|
15
23
|
optional?: boolean;
|
|
16
24
|
};
|
|
@@ -32,11 +40,11 @@ export type Metadata = {
|
|
|
32
40
|
[$unreliableFieldIndexes]: number[];
|
|
33
41
|
} & // all field indexes tagged with @unreliable
|
|
34
42
|
{
|
|
35
|
-
[$
|
|
36
|
-
} & // all field indexes tagged with @
|
|
43
|
+
[$patchOnlyFieldIndexes]: number[];
|
|
44
|
+
} & // all field indexes tagged with @patchOnly (not persisted to snapshots)
|
|
37
45
|
{
|
|
38
|
-
[$
|
|
39
|
-
} & // all field indexes tagged
|
|
46
|
+
[$fullStateOnlyFieldIndexes]: number[];
|
|
47
|
+
} & // all field indexes tagged @fullStateOnly / .fullStateOnly() (not tracked after assignment)
|
|
40
48
|
{
|
|
41
49
|
[$streamFieldIndexes]: number[];
|
|
42
50
|
} & // all field indexes holding a t.stream(...) collection
|
|
@@ -75,8 +83,8 @@ export declare const Metadata: {
|
|
|
75
83
|
addField(metadata: any, index: number, name: string, type: DefinitionType, descriptor?: PropertyDescriptor): void;
|
|
76
84
|
setTag(metadata: Metadata, fieldName: string, tag: number): void;
|
|
77
85
|
setUnreliable(metadata: Metadata, fieldName: string): void;
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
setPatchOnly(metadata: Metadata, fieldName: string): void;
|
|
87
|
+
setFullStateOnly(metadata: Metadata, fieldName: string): void;
|
|
80
88
|
setStream(metadata: Metadata, fieldName: string): void;
|
|
81
89
|
/**
|
|
82
90
|
* Attach a declaration-scope priority callback to a stream field.
|
|
@@ -104,7 +112,7 @@ export declare const Metadata: {
|
|
|
104
112
|
getFields(klass: any): any;
|
|
105
113
|
hasViewTagAtIndex(metadata: Metadata, index: number): boolean;
|
|
106
114
|
hasUnreliableAtIndex(metadata: Metadata, index: number): boolean;
|
|
107
|
-
|
|
108
|
-
|
|
115
|
+
hasPatchOnlyAtIndex(metadata: Metadata, index: number): boolean;
|
|
116
|
+
hasFullStateOnlyAtIndex(metadata: Metadata, index: number): boolean;
|
|
109
117
|
hasStreamAtIndex(metadata: Metadata, index: number): boolean;
|
|
110
118
|
};
|
package/build/annotations.d.ts
CHANGED
|
@@ -15,37 +15,31 @@ export type DefinitionType<T extends PrimitiveType = PrimitiveType> = T | T[] |
|
|
|
15
15
|
default?: InferValueType<T>;
|
|
16
16
|
view?: boolean | number;
|
|
17
17
|
sync?: boolean;
|
|
18
|
-
owned?: boolean;
|
|
19
18
|
} | {
|
|
20
19
|
array: T;
|
|
21
20
|
default?: ArraySchema<InferValueType<T>>;
|
|
22
21
|
view?: boolean | number;
|
|
23
22
|
sync?: boolean;
|
|
24
|
-
owned?: boolean;
|
|
25
23
|
} | {
|
|
26
24
|
map: T;
|
|
27
25
|
default?: MapSchema<InferValueType<T>>;
|
|
28
26
|
view?: boolean | number;
|
|
29
27
|
sync?: boolean;
|
|
30
|
-
owned?: boolean;
|
|
31
28
|
} | {
|
|
32
29
|
collection: T;
|
|
33
30
|
default?: CollectionSchema<InferValueType<T>>;
|
|
34
31
|
view?: boolean | number;
|
|
35
32
|
sync?: boolean;
|
|
36
|
-
owned?: boolean;
|
|
37
33
|
} | {
|
|
38
34
|
set: T;
|
|
39
35
|
default?: SetSchema<InferValueType<T>>;
|
|
40
36
|
view?: boolean | number;
|
|
41
37
|
sync?: boolean;
|
|
42
|
-
owned?: boolean;
|
|
43
38
|
} | {
|
|
44
39
|
stream: T;
|
|
45
40
|
default?: StreamSchema<InferValueType<T>>;
|
|
46
41
|
view?: boolean | number;
|
|
47
42
|
sync?: boolean;
|
|
48
|
-
owned?: boolean;
|
|
49
43
|
priority?: (view: any, element: InferValueType<T>) => number;
|
|
50
44
|
};
|
|
51
45
|
export type Definition = {
|
|
@@ -80,17 +74,36 @@ export declare function entity<T extends Function>(constructor: T): T;
|
|
|
80
74
|
* ```
|
|
81
75
|
*/
|
|
82
76
|
export declare function view<T>(tag?: number): (target: T, fieldName: string) => void;
|
|
83
|
-
|
|
77
|
+
/**
|
|
78
|
+
* `@unreliable` — route a field onto the unreliable transport channel, so a
|
|
79
|
+
* dropped update costs one stale value instead of stalling the ordered stream
|
|
80
|
+
* behind a retransmit. Primitive fields only (see `Metadata.setUnreliable`).
|
|
81
|
+
*
|
|
82
|
+
* The field's FIRST value still travels the reliable channel, as part of the
|
|
83
|
+
* owning instance's ADD; only later mutations become unreliable. A decoder
|
|
84
|
+
* cannot apply a write to a ref it has not been told about, so a value emitted
|
|
85
|
+
* ahead of that ADD would be dropped — and lost for good if the field is never
|
|
86
|
+
* written again.
|
|
87
|
+
*/
|
|
84
88
|
export declare function unreliable<T>(target: T, field: string): void;
|
|
85
89
|
/**
|
|
86
|
-
* @
|
|
87
|
-
* encodeAllView).
|
|
90
|
+
* @patchOnly — mark a field as not persisted to snapshots (encodeAll /
|
|
91
|
+
* encodeAllView). PatchOnly fields are still emitted on per-tick patches
|
|
88
92
|
* (reliable or unreliable), but late-joining clients won't see them until
|
|
89
93
|
* the next mutation.
|
|
90
94
|
*
|
|
91
95
|
* Orthogonal to @unreliable: a field can be either, both, or neither.
|
|
92
96
|
*/
|
|
93
|
-
export declare function
|
|
97
|
+
export declare function patchOnly<T>(target: T, field: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* @fullStateOnly — mark a field as delivered in the full state sync only
|
|
100
|
+
* (encodeAll / encodeAllView), never on per-tick patches. Writes after a
|
|
101
|
+
* client has joined are not propagated to it — populate these fields
|
|
102
|
+
* before clients connect (e.g. during onCreate).
|
|
103
|
+
*
|
|
104
|
+
* The exact mirror of @patchOnly — the two are mutually exclusive.
|
|
105
|
+
*/
|
|
106
|
+
export declare function fullStateOnly<T>(target: T, field: string): void;
|
|
94
107
|
export declare function type(type: DefinitionType, options?: TypeOptions): PropertyDecorator;
|
|
95
108
|
export declare function getPropertyDescriptor(fieldName: string, fieldIndex: number, type: DefinitionType, complexTypeKlass: TypeDefinition | false): {
|
|
96
109
|
get: (this: Schema) => any;
|