@colyseus/schema 3.0.0-alpha.17 → 3.0.0-alpha.19
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 +14 -2
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +14 -2
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +14 -2
- package/lib/Metadata.d.ts +1 -0
- package/lib/Metadata.js +8 -0
- package/lib/Metadata.js.map +1 -1
- package/lib/decoder/strategy/StateCallbacks.d.ts +1 -1
- package/lib/decoder/strategy/StateCallbacks.js +3 -3
- package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
- package/lib/encoder/Encoder.js +5 -0
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Metadata.ts +9 -0
- package/src/decoder/strategy/StateCallbacks.ts +1 -1
- package/src/encoder/Encoder.ts +7 -0
- package/src/index.ts +1 -1
package/build/cjs/index.js
CHANGED
|
@@ -144,6 +144,14 @@ const Metadata = {
|
|
|
144
144
|
isDeprecated(metadata, field) {
|
|
145
145
|
return metadata[field].deprecated === true;
|
|
146
146
|
},
|
|
147
|
+
init(klass) {
|
|
148
|
+
//
|
|
149
|
+
// Used only to initialize an empty Schema (Encoder#constructor)
|
|
150
|
+
//
|
|
151
|
+
const metadata = {};
|
|
152
|
+
klass.constructor[Symbol.metadata] = metadata;
|
|
153
|
+
Object.defineProperty(metadata, -1, { value: 0, enumerable: false, configurable: true });
|
|
154
|
+
},
|
|
147
155
|
isValidInstance(klass) {
|
|
148
156
|
return (klass.constructor[Symbol.metadata] &&
|
|
149
157
|
Object.prototype.hasOwnProperty.call(klass.constructor[Symbol.metadata], -1));
|
|
@@ -3412,6 +3420,10 @@ class Encoder {
|
|
|
3412
3420
|
setRoot(state) {
|
|
3413
3421
|
this.root = new Root();
|
|
3414
3422
|
this.state = state;
|
|
3423
|
+
// Workaround to allow using an empty Schema.
|
|
3424
|
+
if (state.constructor[Symbol.metadata] === undefined) {
|
|
3425
|
+
Metadata.init(state);
|
|
3426
|
+
}
|
|
3415
3427
|
state[$changes].setRoot(this.root);
|
|
3416
3428
|
}
|
|
3417
3429
|
encode(it = { offset: 0 }, view, buffer = this.sharedBuffer, changeTrees = this.root.changes, isEncodeAll = this.root.allChanges === changeTrees) {
|
|
@@ -3980,7 +3992,7 @@ __decorate([
|
|
|
3980
3992
|
type([ReflectionType])
|
|
3981
3993
|
], Reflection.prototype, "types", void 0);
|
|
3982
3994
|
|
|
3983
|
-
function
|
|
3995
|
+
function getDecoderStateCallbacks(decoder) {
|
|
3984
3996
|
const $root = decoder.root;
|
|
3985
3997
|
const callbacks = $root.callbacks;
|
|
3986
3998
|
let isTriggeringOnAdd = false;
|
|
@@ -4441,8 +4453,8 @@ exports.dumpChanges = dumpChanges;
|
|
|
4441
4453
|
exports.encode = encode;
|
|
4442
4454
|
exports.encodeKeyValueOperation = encodeArray;
|
|
4443
4455
|
exports.encodeSchemaOperation = encodeSchemaOperation;
|
|
4456
|
+
exports.getDecoderStateCallbacks = getDecoderStateCallbacks;
|
|
4444
4457
|
exports.getRawChangesCallback = getRawChangesCallback;
|
|
4445
|
-
exports.getStateCallbacks = getStateCallbacks;
|
|
4446
4458
|
exports.registerType = registerType;
|
|
4447
4459
|
exports.type = type;
|
|
4448
4460
|
exports.view = view;
|