@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.
- package/build/cjs/index.js +15 -3
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +15 -3
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +15 -3
- package/lib/annotations.js +12 -4
- package/lib/annotations.js.map +1 -1
- package/package.json +1 -1
- package/src/annotations.ts +12 -4
package/build/esm/index.mjs
CHANGED
|
@@ -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
|
-
|
|
3535
|
-
|
|
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 {
|