@colyseus/schema 3.0.0-alpha.24 → 3.0.0-alpha.25
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 +8 -6
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +8 -6
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +8 -6
- package/lib/Metadata.js +1 -1
- package/lib/Metadata.js.map +1 -1
- package/lib/annotations.js +6 -0
- package/lib/annotations.js.map +1 -1
- package/lib/encoder/Encoder.js +1 -6
- package/lib/encoder/Encoder.js.map +1 -1
- package/package.json +1 -1
- package/src/Metadata.ts +1 -1
- package/src/annotations.ts +8 -0
- package/src/encoder/Encoder.ts +2 -8
package/build/esm/index.mjs
CHANGED
|
@@ -146,7 +146,7 @@ const Metadata = {
|
|
|
146
146
|
// TODO: remove/refactor this...
|
|
147
147
|
//
|
|
148
148
|
const metadata = {};
|
|
149
|
-
klass
|
|
149
|
+
klass[Symbol.metadata] = metadata;
|
|
150
150
|
Object.defineProperty(metadata, -1, {
|
|
151
151
|
value: 0,
|
|
152
152
|
enumerable: false,
|
|
@@ -2413,6 +2413,12 @@ class TypeContext {
|
|
|
2413
2413
|
return false;
|
|
2414
2414
|
}
|
|
2415
2415
|
this.types[typeid] = schema;
|
|
2416
|
+
//
|
|
2417
|
+
// Workaround to allow using an empty Schema (with no `@type()` fields)
|
|
2418
|
+
//
|
|
2419
|
+
if (schema[Symbol.metadata] === undefined) {
|
|
2420
|
+
Metadata.init(schema);
|
|
2421
|
+
}
|
|
2416
2422
|
this.schemas.set(schema, typeid);
|
|
2417
2423
|
return true;
|
|
2418
2424
|
}
|
|
@@ -3428,12 +3434,12 @@ class Encoder {
|
|
|
3428
3434
|
static { this.BUFFER_SIZE = 8 * 1024; } // 8KB
|
|
3429
3435
|
constructor(root) {
|
|
3430
3436
|
this.sharedBuffer = Buffer.allocUnsafeSlow(Encoder.BUFFER_SIZE);
|
|
3431
|
-
this.setRoot(root);
|
|
3432
3437
|
//
|
|
3433
3438
|
// TODO: cache and restore "Context" based on root schema
|
|
3434
3439
|
// (to avoid creating a new context for every new room)
|
|
3435
3440
|
//
|
|
3436
3441
|
this.context = new TypeContext(root.constructor);
|
|
3442
|
+
this.setRoot(root);
|
|
3437
3443
|
// console.log(">>>>>>>>>>>>>>>> Encoder types");
|
|
3438
3444
|
// this.context.schemas.forEach((id, schema) => {
|
|
3439
3445
|
// console.log("type:", id, schema.name, Object.keys(schema[Symbol.metadata]));
|
|
@@ -3442,10 +3448,6 @@ class Encoder {
|
|
|
3442
3448
|
setRoot(state) {
|
|
3443
3449
|
this.root = new Root();
|
|
3444
3450
|
this.state = state;
|
|
3445
|
-
// Workaround to allow using an empty Schema.
|
|
3446
|
-
if (state.constructor[Symbol.metadata] === undefined) {
|
|
3447
|
-
Metadata.init(state);
|
|
3448
|
-
}
|
|
3449
3451
|
state[$changes].setRoot(this.root);
|
|
3450
3452
|
}
|
|
3451
3453
|
encode(it = { offset: 0 }, view, buffer = this.sharedBuffer, changeTrees = this.root.changes, isEncodeAll = this.root.allChanges === changeTrees) {
|