@colyseus/schema 5.0.1 → 5.0.3
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/Metadata.d.ts +7 -0
- package/build/Reflection.d.ts +18 -2
- package/build/index.cjs +53 -11
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +53 -11
- package/build/index.mjs +53 -11
- package/build/index.mjs.map +1 -1
- package/build/input/index.cjs +28 -11
- package/build/input/index.cjs.map +1 -1
- package/build/input/index.mjs +28 -11
- package/build/input/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Metadata.ts +44 -22
- package/src/Reflection.ts +46 -1
- package/src/index.ts +1 -1
package/build/input/index.mjs
CHANGED
|
@@ -5554,6 +5554,33 @@ const Metadata = {
|
|
|
5554
5554
|
getStreamPriority(metadata, index) {
|
|
5555
5555
|
return metadata?.[$streamPriorities]?.[index];
|
|
5556
5556
|
},
|
|
5557
|
+
/**
|
|
5558
|
+
* Install a single field with full encoder wiring: accessor descriptor
|
|
5559
|
+
* on the prototype + `metadata[$encoders]` slot for primitives. Shared
|
|
5560
|
+
* between `Metadata.setFields` (build path) and
|
|
5561
|
+
* `Reflection.makeEncodable` (Reflection upgrade path).
|
|
5562
|
+
*/
|
|
5563
|
+
defineField(target, metadata, fieldIndex, fieldName, type) {
|
|
5564
|
+
const normalized = getNormalizedType(type);
|
|
5565
|
+
const { complexTypeKlass, childType } = resolveFieldType(normalized);
|
|
5566
|
+
Metadata.addField(metadata, fieldIndex, fieldName, normalized, getPropertyDescriptor(fieldName, fieldIndex, childType, complexTypeKlass));
|
|
5567
|
+
// Install accessor descriptor on the prototype (once per class field).
|
|
5568
|
+
if (metadata[$descriptors][fieldName]) {
|
|
5569
|
+
Object.defineProperty(target.prototype, fieldName, metadata[$descriptors][fieldName]);
|
|
5570
|
+
}
|
|
5571
|
+
// Pre-compute encoder function for primitive types.
|
|
5572
|
+
if (typeof normalized === "string") {
|
|
5573
|
+
if (!metadata[$encoders]) {
|
|
5574
|
+
Object.defineProperty(metadata, $encoders, {
|
|
5575
|
+
value: [],
|
|
5576
|
+
enumerable: false,
|
|
5577
|
+
configurable: true,
|
|
5578
|
+
writable: true,
|
|
5579
|
+
});
|
|
5580
|
+
}
|
|
5581
|
+
metadata[$encoders][fieldIndex] = encode[normalized];
|
|
5582
|
+
}
|
|
5583
|
+
},
|
|
5557
5584
|
setFields(target, fields) {
|
|
5558
5585
|
// for inheritance support
|
|
5559
5586
|
const constructor = target.prototype.constructor;
|
|
@@ -5591,17 +5618,7 @@ const Metadata = {
|
|
|
5591
5618
|
});
|
|
5592
5619
|
}
|
|
5593
5620
|
for (const field in fields) {
|
|
5594
|
-
|
|
5595
|
-
const { complexTypeKlass, childType } = resolveFieldType(type);
|
|
5596
|
-
Metadata.addField(metadata, fieldIndex, field, type, getPropertyDescriptor(field, fieldIndex, childType, complexTypeKlass));
|
|
5597
|
-
// Install accessor descriptor on the prototype (once per class field).
|
|
5598
|
-
if (metadata[$descriptors][field]) {
|
|
5599
|
-
Object.defineProperty(target.prototype, field, metadata[$descriptors][field]);
|
|
5600
|
-
}
|
|
5601
|
-
// Pre-compute encoder function for primitive types.
|
|
5602
|
-
if (typeof type === "string") {
|
|
5603
|
-
metadata[$encoders][fieldIndex] = encode[type];
|
|
5604
|
-
}
|
|
5621
|
+
Metadata.defineField(constructor, metadata, fieldIndex, field, fields[field]);
|
|
5605
5622
|
fieldIndex++;
|
|
5606
5623
|
}
|
|
5607
5624
|
return target;
|