@colyseus/schema 3.0.71 → 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 +29 -4
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +29 -4
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +29 -4
- package/lib/annotations.js +26 -5
- package/lib/annotations.js.map +1 -1
- package/package.json +1 -1
- package/src/annotations.ts +27 -6
package/build/cjs/index.js
CHANGED
|
@@ -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
|
-
|
|
3537
|
-
|
|
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 {
|
|
@@ -3561,14 +3573,27 @@ function schema(fieldsAndMethods, name, inherits = Schema) {
|
|
|
3561
3573
|
}
|
|
3562
3574
|
return defaults;
|
|
3563
3575
|
};
|
|
3576
|
+
const getParentProps = (props) => {
|
|
3577
|
+
const fieldNames = Object.keys(fields);
|
|
3578
|
+
const parentProps = {};
|
|
3579
|
+
for (const key in props) {
|
|
3580
|
+
if (!fieldNames.includes(key)) {
|
|
3581
|
+
parentProps[key] = props[key];
|
|
3582
|
+
}
|
|
3583
|
+
}
|
|
3584
|
+
return parentProps;
|
|
3585
|
+
};
|
|
3564
3586
|
/** @codegen-ignore */
|
|
3565
3587
|
const klass = Metadata.setFields(class extends inherits {
|
|
3566
3588
|
constructor(...args) {
|
|
3567
|
-
super(Object.assign({}, getDefaultValues(), args[0] || {}));
|
|
3568
3589
|
// call initialize method
|
|
3569
3590
|
if (methods.initialize && typeof methods.initialize === 'function') {
|
|
3591
|
+
super(Object.assign({}, getDefaultValues(), getParentProps(args[0] || {})));
|
|
3570
3592
|
methods.initialize.apply(this, args);
|
|
3571
3593
|
}
|
|
3594
|
+
else {
|
|
3595
|
+
super(Object.assign({}, getDefaultValues(), args[0] || {}));
|
|
3596
|
+
}
|
|
3572
3597
|
}
|
|
3573
3598
|
}, fields);
|
|
3574
3599
|
// Store the getDefaultValues function on the class for inheritance
|