@colyseus/schema 3.0.70 → 3.0.72

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.
Files changed (73) hide show
  1. package/build/cjs/index.js +17 -6
  2. package/build/cjs/index.js.map +1 -1
  3. package/build/esm/index.mjs +17 -6
  4. package/build/esm/index.mjs.map +1 -1
  5. package/build/umd/index.js +17 -6
  6. package/lib/Decoder.d.ts +16 -0
  7. package/lib/Decoder.js +182 -0
  8. package/lib/Decoder.js.map +1 -0
  9. package/lib/Encoder.d.ts +13 -0
  10. package/lib/Encoder.js +79 -0
  11. package/lib/Encoder.js.map +1 -0
  12. package/lib/annotations.js +18 -3
  13. package/lib/annotations.js.map +1 -1
  14. package/lib/bench_encode.d.ts +1 -0
  15. package/lib/bench_encode.js +93 -0
  16. package/lib/bench_encode.js.map +1 -0
  17. package/lib/changes/ChangeSet.d.ts +12 -0
  18. package/lib/changes/ChangeSet.js +35 -0
  19. package/lib/changes/ChangeSet.js.map +1 -0
  20. package/lib/changes/ChangeTree.d.ts +53 -0
  21. package/lib/changes/ChangeTree.js +202 -0
  22. package/lib/changes/ChangeTree.js.map +1 -0
  23. package/lib/changes/DecodeOperation.d.ts +15 -0
  24. package/lib/changes/DecodeOperation.js +186 -0
  25. package/lib/changes/DecodeOperation.js.map +1 -0
  26. package/lib/changes/EncodeOperation.d.ts +18 -0
  27. package/lib/changes/EncodeOperation.js +130 -0
  28. package/lib/changes/EncodeOperation.js.map +1 -0
  29. package/lib/changes/ReferenceTracker.d.ts +14 -0
  30. package/lib/changes/ReferenceTracker.js +83 -0
  31. package/lib/changes/ReferenceTracker.js.map +1 -0
  32. package/lib/changes/consts.d.ts +14 -0
  33. package/lib/changes/consts.js +18 -0
  34. package/lib/changes/consts.js.map +1 -0
  35. package/lib/decoding/decode.d.ts +48 -0
  36. package/lib/decoding/decode.js +267 -0
  37. package/lib/decoding/decode.js.map +1 -0
  38. package/lib/ecs.d.ts +11 -0
  39. package/lib/ecs.js +160 -0
  40. package/lib/ecs.js.map +1 -0
  41. package/lib/filters/index.d.ts +8 -0
  42. package/lib/filters/index.js +24 -0
  43. package/lib/filters/index.js.map +1 -0
  44. package/lib/spec.d.ts +13 -0
  45. package/lib/spec.js +42 -0
  46. package/lib/spec.js.map +1 -0
  47. package/lib/types/ArraySchema.d.ts +238 -0
  48. package/lib/types/ArraySchema.js +555 -0
  49. package/lib/types/ArraySchema.js.map +1 -0
  50. package/lib/types/CollectionSchema.d.ts +35 -0
  51. package/lib/types/CollectionSchema.js +150 -0
  52. package/lib/types/CollectionSchema.js.map +1 -0
  53. package/lib/types/MapSchema.d.ts +38 -0
  54. package/lib/types/MapSchema.js +215 -0
  55. package/lib/types/MapSchema.js.map +1 -0
  56. package/lib/types/SetSchema.d.ts +32 -0
  57. package/lib/types/SetSchema.js +162 -0
  58. package/lib/types/SetSchema.js.map +1 -0
  59. package/lib/types/typeRegistry.d.ts +5 -0
  60. package/lib/types/typeRegistry.js +13 -0
  61. package/lib/types/typeRegistry.js.map +1 -0
  62. package/lib/usage.d.ts +1 -0
  63. package/lib/usage.js +22 -0
  64. package/lib/usage.js.map +1 -0
  65. package/lib/v3.d.ts +1 -0
  66. package/lib/v3.js +427 -0
  67. package/lib/v3.js.map +1 -0
  68. package/lib/v3_experiment.d.ts +1 -0
  69. package/lib/v3_experiment.js +407 -0
  70. package/lib/v3_experiment.js.map +1 -0
  71. package/package.json +1 -1
  72. package/src/annotations.ts +19 -4
  73. package/src/bench_encode.ts +64 -0
@@ -3522,10 +3522,7 @@ function schema(fieldsAndMethods, name, inherits = Schema) {
3522
3522
  // Collection: Set → new SetSchema()
3523
3523
  defaultValues[fieldName] = new SetSchema();
3524
3524
  }
3525
- else if (value['type'] !== undefined && Schema.is(value['type'])) {
3526
- // Direct Schema type: Type → new Type()
3527
- defaultValues[fieldName] = new value['type']();
3528
- }
3525
+ else if (value['type'] !== undefined && Schema.is(value['type'])) ;
3529
3526
  }
3530
3527
  else {
3531
3528
  defaultValues[fieldName] = value['default'];
@@ -3534,7 +3531,8 @@ function schema(fieldsAndMethods, name, inherits = Schema) {
3534
3531
  else if (typeof (value) === "function") {
3535
3532
  if (Schema.is(value)) {
3536
3533
  // Direct Schema type: Type → new Type()
3537
- defaultValues[fieldName] = new value();
3534
+ // TODO: should we auto-initialize Schema instances, in case their initialize() method is not defined?
3535
+ // defaultValues[fieldName] = new value();
3538
3536
  fields[fieldName] = getNormalizedType(value);
3539
3537
  }
3540
3538
  else {
@@ -3561,14 +3559,27 @@ function schema(fieldsAndMethods, name, inherits = Schema) {
3561
3559
  }
3562
3560
  return defaults;
3563
3561
  };
3562
+ const getParentProps = (props) => {
3563
+ const fieldNames = Object.keys(fields);
3564
+ const parentProps = {};
3565
+ for (const key in props) {
3566
+ if (!fieldNames.includes(key)) {
3567
+ parentProps[key] = props[key];
3568
+ }
3569
+ }
3570
+ return parentProps;
3571
+ };
3564
3572
  /** @codegen-ignore */
3565
3573
  const klass = Metadata.setFields(class extends inherits {
3566
3574
  constructor(...args) {
3567
- super(Object.assign({}, getDefaultValues(), args[0] || {}));
3568
3575
  // call initialize method
3569
3576
  if (methods.initialize && typeof methods.initialize === 'function') {
3577
+ super(Object.assign({}, getDefaultValues(), getParentProps(args[0] || {})));
3570
3578
  methods.initialize.apply(this, args);
3571
3579
  }
3580
+ else {
3581
+ super(Object.assign({}, getDefaultValues(), args[0] || {}));
3582
+ }
3572
3583
  }
3573
3584
  }, fields);
3574
3585
  // Store the getDefaultValues function on the class for inheritance