@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.
@@ -140,6 +140,14 @@ const Metadata = {
140
140
  isDeprecated(metadata, field) {
141
141
  return metadata[field].deprecated === true;
142
142
  },
143
+ init(klass) {
144
+ //
145
+ // Used only to initialize an empty Schema (Encoder#constructor)
146
+ //
147
+ const metadata = {};
148
+ klass.constructor[Symbol.metadata] = metadata;
149
+ Object.defineProperty(metadata, -1, { value: 0, enumerable: false, configurable: true });
150
+ },
143
151
  isValidInstance(klass) {
144
152
  return (klass.constructor[Symbol.metadata] &&
145
153
  Object.prototype.hasOwnProperty.call(klass.constructor[Symbol.metadata], -1));
@@ -3408,6 +3416,10 @@ class Encoder {
3408
3416
  setRoot(state) {
3409
3417
  this.root = new Root();
3410
3418
  this.state = state;
3419
+ // Workaround to allow using an empty Schema.
3420
+ if (state.constructor[Symbol.metadata] === undefined) {
3421
+ Metadata.init(state);
3422
+ }
3411
3423
  state[$changes].setRoot(this.root);
3412
3424
  }
3413
3425
  encode(it = { offset: 0 }, view, buffer = this.sharedBuffer, changeTrees = this.root.changes, isEncodeAll = this.root.allChanges === changeTrees) {
@@ -3976,7 +3988,7 @@ __decorate([
3976
3988
  type([ReflectionType])
3977
3989
  ], Reflection.prototype, "types", void 0);
3978
3990
 
3979
- function getStateCallbacks(decoder) {
3991
+ function getDecoderStateCallbacks(decoder) {
3980
3992
  const $root = decoder.root;
3981
3993
  const callbacks = $root.callbacks;
3982
3994
  let isTriggeringOnAdd = false;
@@ -4406,5 +4418,5 @@ registerType("array", { constructor: ArraySchema });
4406
4418
  registerType("set", { constructor: SetSchema });
4407
4419
  registerType("collection", { constructor: CollectionSchema, });
4408
4420
 
4409
- export { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $track, ArraySchema, ChangeTree, CollectionSchema, Decoder, Encoder, MapSchema, Metadata, OPERATION, Reflection, ReflectionField, ReflectionType, Schema, SetSchema, StateView, TypeContext, decode, decodeKeyValueOperation, decodeSchemaOperation, defineTypes, deprecated, dumpChanges, encode, encodeArray as encodeKeyValueOperation, encodeSchemaOperation, getRawChangesCallback, getStateCallbacks, registerType, type, view };
4421
+ export { $changes, $childType, $decoder, $deleteByIndex, $encoder, $filter, $getByIndex, $track, ArraySchema, ChangeTree, CollectionSchema, Decoder, Encoder, MapSchema, Metadata, OPERATION, Reflection, ReflectionField, ReflectionType, Schema, SetSchema, StateView, TypeContext, decode, decodeKeyValueOperation, decodeSchemaOperation, defineTypes, deprecated, dumpChanges, encode, encodeArray as encodeKeyValueOperation, encodeSchemaOperation, getDecoderStateCallbacks, getRawChangesCallback, registerType, type, view };
4410
4422
  //# sourceMappingURL=index.mjs.map