@colyseus/schema 3.0.47 → 3.0.49

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.
@@ -2799,6 +2799,12 @@ class MapSchema {
2799
2799
  this.$indexes.delete(index);
2800
2800
  }
2801
2801
  [$onEncodeEnd]() {
2802
+ const changeTree = this[$changes];
2803
+ // cleanup changeTree.indexes of deleted keys
2804
+ for (const indexStr in this.deletedItems) {
2805
+ const key = this.$indexes.get(parseInt(indexStr));
2806
+ delete changeTree.indexes[key];
2807
+ }
2802
2808
  this.deletedItems = {};
2803
2809
  }
2804
2810
  toJSON() {
@@ -3172,20 +3178,29 @@ function defineTypes(target, fields, options) {
3172
3178
  }
3173
3179
  return target;
3174
3180
  }
3175
- function schema(fields, name, inherits = Schema) {
3181
+ function schema(fieldsAndMethods, name, inherits = Schema) {
3182
+ const fields = {};
3183
+ const methods = {};
3176
3184
  const defaultValues = {};
3177
3185
  const viewTagFields = {};
3178
- for (let fieldName in fields) {
3179
- const field = fields[fieldName];
3180
- if (typeof (field) === "object") {
3181
- if (field['default'] !== undefined) {
3182
- defaultValues[fieldName] = field['default'];
3186
+ for (let fieldName in fieldsAndMethods) {
3187
+ const value = fieldsAndMethods[fieldName];
3188
+ if (typeof (value) === "object") {
3189
+ if (value['default'] !== undefined) {
3190
+ defaultValues[fieldName] = value['default'];
3183
3191
  }
3184
- if (field['view'] !== undefined) {
3185
- viewTagFields[fieldName] = (typeof (field['view']) === "boolean")
3192
+ if (value['view'] !== undefined) {
3193
+ viewTagFields[fieldName] = (typeof (value['view']) === "boolean")
3186
3194
  ? DEFAULT_VIEW_TAG
3187
- : field['view'];
3195
+ : value['view'];
3188
3196
  }
3197
+ fields[fieldName] = value;
3198
+ }
3199
+ else if (typeof (value) === "function") {
3200
+ methods[fieldName] = value;
3201
+ }
3202
+ else {
3203
+ fields[fieldName] = value;
3189
3204
  }
3190
3205
  }
3191
3206
  const klass = Metadata.setFields(class extends inherits {
@@ -3197,6 +3212,9 @@ function schema(fields, name, inherits = Schema) {
3197
3212
  for (let fieldName in viewTagFields) {
3198
3213
  view(viewTagFields[fieldName])(klass.prototype, fieldName);
3199
3214
  }
3215
+ for (let methodName in methods) {
3216
+ klass.prototype[methodName] = methods[methodName];
3217
+ }
3200
3218
  if (name) {
3201
3219
  Object.defineProperty(klass, "name", { value: name });
3202
3220
  }