@colyseus/schema 3.0.0-alpha.33 → 3.0.0-alpha.35
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/bin/schema-debug +94 -0
- package/build/cjs/index.js +465 -303
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +465 -303
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +465 -303
- package/lib/Metadata.d.ts +5 -5
- package/lib/Metadata.js +17 -17
- package/lib/Metadata.js.map +1 -1
- package/lib/Schema.js +24 -17
- package/lib/Schema.js.map +1 -1
- package/lib/annotations.js +11 -11
- package/lib/annotations.js.map +1 -1
- package/lib/bench_encode.js +12 -5
- package/lib/bench_encode.js.map +1 -1
- package/lib/decoder/Decoder.js +1 -1
- package/lib/decoder/Decoder.js.map +1 -1
- package/lib/encoder/ChangeTree.d.ts +23 -7
- package/lib/encoder/ChangeTree.js +183 -106
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/EncodeOperation.d.ts +2 -1
- package/lib/encoder/EncodeOperation.js +2 -2
- package/lib/encoder/EncodeOperation.js.map +1 -1
- package/lib/encoder/Encoder.d.ts +3 -5
- package/lib/encoder/Encoder.js +93 -61
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/encoder/Root.d.ts +12 -7
- package/lib/encoder/Root.js +41 -20
- package/lib/encoder/Root.js.map +1 -1
- package/lib/encoder/StateView.d.ts +5 -5
- package/lib/encoder/StateView.js +29 -23
- package/lib/encoder/StateView.js.map +1 -1
- package/lib/encoding/encode.js +12 -9
- package/lib/encoding/encode.js.map +1 -1
- package/lib/types/TypeContext.js +2 -1
- package/lib/types/TypeContext.js.map +1 -1
- package/lib/types/custom/ArraySchema.js +27 -13
- package/lib/types/custom/ArraySchema.js.map +1 -1
- package/lib/types/custom/MapSchema.d.ts +3 -1
- package/lib/types/custom/MapSchema.js +7 -4
- package/lib/types/custom/MapSchema.js.map +1 -1
- package/lib/types/symbols.d.ts +8 -6
- package/lib/types/symbols.js +9 -7
- package/lib/types/symbols.js.map +1 -1
- package/lib/utils.js +6 -3
- package/lib/utils.js.map +1 -1
- package/package.json +3 -2
- package/src/Metadata.ts +22 -22
- package/src/Schema.ts +33 -25
- package/src/annotations.ts +12 -12
- package/src/bench_encode.ts +15 -6
- package/src/decoder/Decoder.ts +1 -1
- package/src/encoder/ChangeTree.ts +220 -115
- package/src/encoder/EncodeOperation.ts +5 -1
- package/src/encoder/Encoder.ts +110 -68
- package/src/encoder/Root.ts +41 -21
- package/src/encoder/StateView.ts +32 -28
- package/src/encoding/encode.ts +12 -9
- package/src/types/TypeContext.ts +2 -1
- package/src/types/custom/ArraySchema.ts +39 -17
- package/src/types/custom/MapSchema.ts +12 -5
- package/src/types/symbols.ts +10 -9
- package/src/utils.ts +7 -3
package/bin/schema-debug
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const schema = require('@colyseus/schema');
|
|
5
|
+
|
|
6
|
+
const Reflection = schema.Reflection;
|
|
7
|
+
const Decoder = schema.Decoder;
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(process.argv[2])) {
|
|
10
|
+
console.error("Error: File not found:", process.argv[2]);
|
|
11
|
+
console.log("");
|
|
12
|
+
console.log("Usage: schema-debug <schema-debug.txt>");
|
|
13
|
+
console.log("");
|
|
14
|
+
console.log(" From your server-side, you must use the SchemaSerializerDebug as serializer, in order to generate the schema-debug.txt file.");
|
|
15
|
+
console.log("");
|
|
16
|
+
console.log(" Example:");
|
|
17
|
+
console.log("");
|
|
18
|
+
console.log(" import { SchemaSerializerDebug } from '@colyseus/core';");
|
|
19
|
+
console.log(" // ...");
|
|
20
|
+
console.log(" onCreate() {");
|
|
21
|
+
console.log(" const state = new MyRoomState();");
|
|
22
|
+
console.log(" this.setState(state);");
|
|
23
|
+
console.log(" // Override serializer");
|
|
24
|
+
console.log(" this.setSerializer(new SchemaSerializerDebug());");
|
|
25
|
+
console.log(" this['_serializer'].reset(state)");
|
|
26
|
+
console.log(" // ...");
|
|
27
|
+
console.log("");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const contents = fs.readFileSync(process.argv[2], { encoding: "utf8" }).toString();
|
|
32
|
+
|
|
33
|
+
let isCommentBlock = false;
|
|
34
|
+
let lastComment = "";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @type {Decoder}
|
|
38
|
+
*/
|
|
39
|
+
let decoder;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param line string
|
|
44
|
+
* @returns {Buffer}
|
|
45
|
+
*/
|
|
46
|
+
function getBuffer(line) {
|
|
47
|
+
const start = line.lastIndexOf(":");
|
|
48
|
+
const buffer = Buffer.from(new Uint8Array(line.substring(start + 1).split(",").map(n => Number(n))));
|
|
49
|
+
console.log(`(${buffer.byteLength}) ${Array.from(buffer).join(",")}`)
|
|
50
|
+
// console.log("");
|
|
51
|
+
// console.log("");
|
|
52
|
+
// console.log("> ", line);
|
|
53
|
+
// console.log("> substring:", line.substring(start + 1))
|
|
54
|
+
return buffer;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param buffer {Buffer}
|
|
59
|
+
*/
|
|
60
|
+
function decode(buffer) {
|
|
61
|
+
try {
|
|
62
|
+
decoder.decode(buffer);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
console.error(e);
|
|
65
|
+
console.log("NOT OK. Last log:\n\n")
|
|
66
|
+
console.log(lastComment);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
contents.split("\n").forEach((line) => {
|
|
71
|
+
if (line.startsWith("#")) {
|
|
72
|
+
// reset last comment.
|
|
73
|
+
if (isCommentBlock === false) { lastComment = ""; }
|
|
74
|
+
|
|
75
|
+
isCommentBlock = true;
|
|
76
|
+
lastComment += line.substring(line.indexOf(":") + 1) + "\n";
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
isCommentBlock = false;
|
|
81
|
+
|
|
82
|
+
if (line.startsWith("handshake:") && !decoder) {
|
|
83
|
+
const state = Reflection.decode(getBuffer(line));
|
|
84
|
+
decoder = new Decoder(state);
|
|
85
|
+
|
|
86
|
+
} else if (line.startsWith("state:")) {
|
|
87
|
+
decode(getBuffer(line));
|
|
88
|
+
|
|
89
|
+
} else if (line.startsWith("patch:")) {
|
|
90
|
+
decode(getBuffer(line));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log("OK:", decoder.state.toJSON());
|