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