@colyseus/schema 3.0.72 → 3.0.73

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.
@@ -3522,7 +3522,15 @@ 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'])) ;
3525
+ else if (value['type'] !== undefined && Schema.is(value['type'])) {
3526
+ // Direct Schema type: Type → new Type()
3527
+ if (!value['type'].prototype.initialize || value['type'].prototype.initialize.length === 0) {
3528
+ // only auto-initialize Schema instances if:
3529
+ // - they don't have an initialize method
3530
+ // - or initialize method doesn't accept any parameters
3531
+ defaultValues[fieldName] = new value['type']();
3532
+ }
3533
+ }
3526
3534
  }
3527
3535
  else {
3528
3536
  defaultValues[fieldName] = value['default'];
@@ -3531,8 +3539,12 @@ function schema(fieldsAndMethods, name, inherits = Schema) {
3531
3539
  else if (typeof (value) === "function") {
3532
3540
  if (Schema.is(value)) {
3533
3541
  // Direct Schema type: Type → new Type()
3534
- // TODO: should we auto-initialize Schema instances, in case their initialize() method is not defined?
3535
- // defaultValues[fieldName] = new value();
3542
+ if (!value.prototype.initialize || value.prototype.initialize.length === 0) {
3543
+ // only auto-initialize Schema instances if:
3544
+ // - they don't have an initialize method
3545
+ // - or initialize method doesn't accept any parameters
3546
+ defaultValues[fieldName] = new value();
3547
+ }
3536
3548
  fields[fieldName] = getNormalizedType(value);
3537
3549
  }
3538
3550
  else {