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