@colyseus/schema 1.0.33 → 1.0.36
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 +36 -35
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +114 -85
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +38 -37
- package/lib/Reflection.js +11 -11
- package/lib/Reflection.js.map +1 -1
- package/lib/Schema.js +14 -13
- package/lib/Schema.js.map +1 -1
- package/lib/annotations.js +17 -13
- package/lib/annotations.js.map +1 -1
- package/lib/changes/ChangeTree.js +2 -2
- package/lib/changes/ChangeTree.js.map +1 -1
- package/lib/codegen/api.js +1 -1
- package/lib/codegen/api.js.map +1 -1
- package/lib/codegen/argv.d.ts +1 -1
- package/lib/codegen/cli.js +5 -5
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/languages/cpp.js +38 -38
- package/lib/codegen/languages/cpp.js.map +1 -1
- package/lib/codegen/languages/csharp.js +25 -21
- package/lib/codegen/languages/csharp.js.map +1 -1
- package/lib/codegen/languages/haxe.js +13 -13
- package/lib/codegen/languages/haxe.js.map +1 -1
- package/lib/codegen/languages/java.js +11 -11
- package/lib/codegen/languages/java.js.map +1 -1
- package/lib/codegen/languages/js.js +16 -16
- package/lib/codegen/languages/js.js.map +1 -1
- package/lib/codegen/languages/lua.js +12 -12
- package/lib/codegen/languages/lua.js.map +1 -1
- package/lib/codegen/languages/ts.js +37 -33
- package/lib/codegen/languages/ts.js.map +1 -1
- package/lib/codegen/parser.js +3 -3
- package/lib/codegen/parser.js.map +1 -1
- package/lib/codegen/types.js +2 -2
- package/lib/codegen/types.js.map +1 -1
- package/lib/events/EventEmitter.js +10 -6
- package/lib/events/EventEmitter.js.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/types/ArraySchema.js +14 -10
- package/lib/types/ArraySchema.js.map +1 -1
- package/lib/types/MapSchema.d.ts +19 -19
- package/lib/types/MapSchema.js +2 -2
- package/lib/types/MapSchema.js.map +1 -1
- package/package.json +2 -1
- package/src/Reflection.ts +159 -0
- package/src/Schema.ts +1084 -0
- package/src/annotations.ts +357 -0
- package/src/changes/ChangeTree.ts +373 -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 +119 -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 +251 -0
- package/src/codegen/types.ts +164 -0
- package/src/encoding/decode.ts +278 -0
- package/src/encoding/encode.ts +283 -0
- package/src/events/EventEmitter.ts +32 -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 +608 -0
- package/src/types/CollectionSchema.ts +188 -0
- package/src/types/HelperTypes.ts +34 -0
- package/src/types/MapSchema.ts +255 -0
- package/src/types/SetSchema.ts +197 -0
- package/src/types/index.ts +19 -0
- package/src/utils.ts +28 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracted from https://www.npmjs.com/package/strong-events
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
type ExtractFunctionParameters<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
|
|
6
|
+
|
|
7
|
+
export class EventEmitter_<CallbackSignature extends (...args: any[]) => any> {
|
|
8
|
+
handlers: Array<CallbackSignature> = [];
|
|
9
|
+
|
|
10
|
+
register(cb: CallbackSignature, once: boolean = false) {
|
|
11
|
+
this.handlers.push(cb);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
invoke(...args: ExtractFunctionParameters<CallbackSignature>) {
|
|
16
|
+
this.handlers.forEach((handler) => handler(...args));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
invokeAsync(...args: ExtractFunctionParameters<CallbackSignature>) {
|
|
20
|
+
return Promise.all(this.handlers.map((handler) => handler(...args)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
remove (cb: CallbackSignature) {
|
|
24
|
+
const index = this.handlers.indexOf(cb);
|
|
25
|
+
this.handlers[index] = this.handlers[this.handlers.length - 1];
|
|
26
|
+
this.handlers.pop();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
clear() {
|
|
30
|
+
this.handlers = [];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ChangeTree } from "../changes/ChangeTree";
|
|
2
|
+
import { ClientWithSessionId } from "../annotations";
|
|
3
|
+
|
|
4
|
+
export class ClientState {
|
|
5
|
+
refIds = new WeakSet<ChangeTree>();
|
|
6
|
+
containerIndexes = new WeakMap<ChangeTree, Set<number>>();
|
|
7
|
+
// containerIndexes = new Map<ChangeTree, Set<number>>();
|
|
8
|
+
|
|
9
|
+
addRefId(changeTree: ChangeTree) {
|
|
10
|
+
if (!this.refIds.has(changeTree)) {
|
|
11
|
+
this.refIds.add(changeTree);
|
|
12
|
+
this.containerIndexes.set(changeTree, new Set());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static get(client: ClientWithSessionId) {
|
|
17
|
+
if (client.$filterState === undefined) {
|
|
18
|
+
client.$filterState = new ClientState();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return client.$filterState as ClientState;
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export { Schema, DataChange } from "./Schema";
|
|
2
|
+
|
|
3
|
+
import { MapSchema, getMapProxy } from "./types/MapSchema"
|
|
4
|
+
export { MapSchema };
|
|
5
|
+
|
|
6
|
+
import { ArraySchema, getArrayProxy } from "./types/ArraySchema";
|
|
7
|
+
export { ArraySchema };
|
|
8
|
+
|
|
9
|
+
import { CollectionSchema } from "./types/CollectionSchema";
|
|
10
|
+
export { CollectionSchema };
|
|
11
|
+
|
|
12
|
+
import { SetSchema } from "./types/SetSchema";
|
|
13
|
+
export { SetSchema };
|
|
14
|
+
|
|
15
|
+
import { registerType } from "./types";
|
|
16
|
+
export { registerType };
|
|
17
|
+
|
|
18
|
+
registerType("map", { constructor: MapSchema, getProxy: getMapProxy });
|
|
19
|
+
registerType("array", { constructor: ArraySchema, getProxy: getArrayProxy });
|
|
20
|
+
registerType("set", { constructor: SetSchema });
|
|
21
|
+
registerType("collection", { constructor: CollectionSchema, });
|
|
22
|
+
|
|
23
|
+
// Utils
|
|
24
|
+
export { dumpChanges } from "./utils";
|
|
25
|
+
|
|
26
|
+
// Encoder / Decoder
|
|
27
|
+
export { Iterator } from "./encoding/decode";
|
|
28
|
+
import * as encode from "./encoding/encode";
|
|
29
|
+
import * as decode from "./encoding/decode";
|
|
30
|
+
export { encode, decode };
|
|
31
|
+
|
|
32
|
+
// Reflection
|
|
33
|
+
export {
|
|
34
|
+
Reflection,
|
|
35
|
+
ReflectionType,
|
|
36
|
+
ReflectionField,
|
|
37
|
+
} from "./Reflection";
|
|
38
|
+
|
|
39
|
+
export {
|
|
40
|
+
// Annotations
|
|
41
|
+
type,
|
|
42
|
+
deprecated,
|
|
43
|
+
filter,
|
|
44
|
+
filterChildren,
|
|
45
|
+
defineTypes,
|
|
46
|
+
hasFilter,
|
|
47
|
+
|
|
48
|
+
// Internals
|
|
49
|
+
SchemaDefinition,
|
|
50
|
+
|
|
51
|
+
// Types
|
|
52
|
+
Context,
|
|
53
|
+
PrimitiveType,
|
|
54
|
+
Definition,
|
|
55
|
+
DefinitionType,
|
|
56
|
+
FilterCallback,
|
|
57
|
+
} from "./annotations";
|
|
58
|
+
|
|
59
|
+
export { OPERATION } from "./spec";
|
package/src/spec.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// export const SWITCH_TO_STRUCTURE = 193; (easily collides with DELETE_AND_ADD + fieldIndex = 2)
|
|
2
|
+
export const SWITCH_TO_STRUCTURE = 255; // (decoding collides with DELETE_AND_ADD + fieldIndex = 63)
|
|
3
|
+
export const TYPE_ID = 213;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Encoding Schema field operations.
|
|
7
|
+
*/
|
|
8
|
+
export enum OPERATION {
|
|
9
|
+
// add new structure/primitive
|
|
10
|
+
ADD = 128,
|
|
11
|
+
|
|
12
|
+
// replace structure/primitive
|
|
13
|
+
REPLACE = 0,
|
|
14
|
+
|
|
15
|
+
// delete field
|
|
16
|
+
DELETE = 64,
|
|
17
|
+
|
|
18
|
+
// DELETE field, followed by an ADD
|
|
19
|
+
DELETE_AND_ADD = 192, // 11100000
|
|
20
|
+
|
|
21
|
+
// TOUCH is used to determine hierarchy of nested Schema structures during serialization.
|
|
22
|
+
// touches are NOT encoded.
|
|
23
|
+
TOUCH = 1, // 00000000
|
|
24
|
+
|
|
25
|
+
// MapSchema Operations
|
|
26
|
+
CLEAR = 10,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// export enum OPERATION {
|
|
30
|
+
// // add new structure/primitive
|
|
31
|
+
// // (128)
|
|
32
|
+
// ADD = 128, // 10000000,
|
|
33
|
+
|
|
34
|
+
// // replace structure/primitive
|
|
35
|
+
// REPLACE = 1,// 00000001
|
|
36
|
+
|
|
37
|
+
// // delete field
|
|
38
|
+
// DELETE = 192, // 11000000
|
|
39
|
+
|
|
40
|
+
// // DELETE field, followed by an ADD
|
|
41
|
+
// DELETE_AND_ADD = 224, // 11100000
|
|
42
|
+
|
|
43
|
+
// // TOUCH is used to determine hierarchy of nested Schema structures during serialization.
|
|
44
|
+
// // touches are NOT encoded.
|
|
45
|
+
// TOUCH = 0, // 00000000
|
|
46
|
+
|
|
47
|
+
// // MapSchema Operations
|
|
48
|
+
// CLEAR = 10,
|
|
49
|
+
// }
|