Skip to content

Releases: colyseus/schema

5.0.3

27 Apr 20:04

Choose a tag to compare

5.0.3 Pre-release
Pre-release

Added

  • Reflection.makeEncodable(ctor) — opt-in upgrade for classes
    reconstructed via Reflection.decode. Installs the same prototype
    accessor descriptors and metadata[$encoders] lookup table that the
    schema(...) / @type builders install at class-definition time, so
    the reconstructed class becomes usable as an encode source for
    InputEncoder and Encoder. Idempotent. Reflection.decode itself
    is unchanged — decoder-only callers (the dominant case) pay nothing
    extra; only code that explicitly opts in pays the descriptor + encoder
    install cost. This unblocks Colyseus 0.18's reflection-based input
    schema discovery, where the SDK reconstructs the input class from the
    server's JOIN_ROOM handshake bytes and then needs to encode against
    it.
  • Metadata.defineField(target, metadata, fieldIndex, fieldName, type)
    — internal helper that folds the per-field install logic (descriptor
    build, prototype install, $encoders slot) into a single shared path.
    Called by both Metadata.setFields (build path) and
    Reflection.makeEncodable (Reflection upgrade path) to keep the
    field-installation logic in one place.

5.0.2

26 Apr 01:49

Choose a tag to compare

5.0.2 Pre-release
Pre-release

Fixed

  • Re-export BuilderInitProps from the package entry. Without it,
    consumers using schema() could hit ts(2883) — The inferred type of 'X' cannot be named without a reference to 'BuilderInitProps' from '../node_modules/@colyseus/schema/build/types/HelperTypes.js' — when
    TypeScript emitted declarations for inferred schema types.

5.0.1

24 Apr 22:22

Choose a tag to compare

5.0.1 Pre-release
Pre-release

Added

  • FieldBuilder#optional() — chainable modifier that marks a field as
    optional. Widens the inferred instance type to T | undefined and skips
    auto-instantiation of collection / Schema-ref defaults at construction.
  • BuilderInitProps<T> — new helper type that derives a strict
    constructor-props shape from a schema() fields map. Required fields
    (primitives without .default() / .optional(), and Schema refs with a
    non-zero-arg initialize()) must now be provided at construction;
    optional fields remain omittable.

Fixed

  • Internal symbols ($refId, $changes, $childType, $proxyTarget,
    $values) now use Symbol.for(...) so duplicate copies of
    @colyseus/schema loaded into the same JS realm — for example, the
    ./input subpath bundle alongside the main bundle — share identity and
    can read each other's tagged instances. Previously, each copy created
    its own Symbol(...), breaking cross-bundle property access. A small
    polyfill installs at module load for runtimes lacking Symbol.for,
    using a globalThis-anchored registry so cross-copy sharing still
    works there.

Changed

  • InferSchemaInstanceType<T> now marks .optional() fields as ?:,
    preserving the mandatory-by-default typing for every other field.
  • Schema#toJSON()'s return type respects .optional() (fields whose
    generic admits undefined are emitted as ?:), matching the runtime
    behavior that omits null/undefined fields.
  • schema().extend() merges parent+child fields into init-props so child
    constructors accept parent-declared fields when no initialize() is
    declared.
  • Constructor signatures: schemas with an explicit initialize(arg) keep
    strict required args; otherwise [] | [InitProps] is accepted —
    preserving the new X(); x.field = ... deferred-assignment pattern
    while catching incomplete partial objects like new X({ hp: 1 }).
  • FieldBuilder now carries two phantom generics
    (<T, HasDefault extends boolean, IsOptional extends boolean>) so the
    init-props derivation can distinguish required vs. omittable fields
    without runtime cost.

5.0.0

23 Apr 23:54

Choose a tag to compare

5.0.0 Pre-release
Pre-release

Experimenting with new features for colyseus 0.18 (beta/preview)

4.0.20

15 Apr 15:29

Choose a tag to compare

C# codegen: emit native enum for positive-int enums

The Unity/C# code generator now emits a native public enum Name : int { ... }
when every member of a TypeScript enum resolves to a non-negative integer
(implicit index-based or explicit positive int values). String and float enums
continue to emit public struct with public const fields, since C# native
enums only support integral underlying types.

Benefits: improved type-safety and proper dropdown display for serialized
enum fields in the Unity Inspector.

Potential source-level break: native C# enum values are strongly typed,
so comparisons against raw ints now require a cast — e.g.
if ((int)myEnum == 0) or, preferably, if (myEnum == MyEnum.Foo).
Wire format is unchanged.

4.0.19

13 Mar 19:22

Choose a tag to compare

fix toJSON(): should not make fields 'optional'. closes #222

4.0.18

11 Mar 03:28

Choose a tag to compare

callbacks: allow to call .listen() even with multiple @colyseus/schem…

4.0.17

06 Mar 13:47

Choose a tag to compare

TypeScript: fix .toJSON() and .restore() to support complex generic i…

4.0.16

04 Mar 23:21

Choose a tag to compare

StateView.remove() fixes to prevent refId not found issues.

4.0.15

25 Feb 02:19

Choose a tag to compare

schema-codegen: fixes bad parsing of interfaces