Releases: colyseus/schema
5.0.3
Added
Reflection.makeEncodable(ctor)— opt-in upgrade for classes
reconstructed viaReflection.decode. Installs the same prototype
accessor descriptors andmetadata[$encoders]lookup table that the
schema(...)/@typebuilders install at class-definition time, so
the reconstructed class becomes usable as an encode source for
InputEncoderandEncoder. Idempotent.Reflection.decodeitself
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,$encodersslot) into a single shared path.
Called by bothMetadata.setFields(build path) and
Reflection.makeEncodable(Reflection upgrade path) to keep the
field-installation logic in one place.
5.0.2
Fixed
- Re-export
BuilderInitPropsfrom the package entry. Without it,
consumers usingschema()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
Added
FieldBuilder#optional()— chainable modifier that marks a field as
optional. Widens the inferred instance type toT | undefinedand skips
auto-instantiation of collection / Schema-ref defaults at construction.BuilderInitProps<T>— new helper type that derives a strict
constructor-props shape from aschema()fields map. Required fields
(primitives without.default()/.optional(), and Schema refs with a
non-zero-arginitialize()) must now be provided at construction;
optional fields remain omittable.
Fixed
- Internal symbols (
$refId,$changes,$childType,$proxyTarget,
$values) now useSymbol.for(...)so duplicate copies of
@colyseus/schemaloaded into the same JS realm — for example, the
./inputsubpath bundle alongside the main bundle — share identity and
can read each other's tagged instances. Previously, each copy created
its ownSymbol(...), breaking cross-bundle property access. A small
polyfill installs at module load for runtimes lackingSymbol.for,
using aglobalThis-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 admitsundefinedare emitted as?:), matching the runtime
behavior that omitsnull/undefinedfields.schema().extend()merges parent+child fields into init-props so child
constructors accept parent-declared fields when noinitialize()is
declared.- Constructor signatures: schemas with an explicit
initialize(arg)keep
strict required args; otherwise[] | [InitProps]is accepted —
preserving thenew X(); x.field = ...deferred-assignment pattern
while catching incomplete partial objects likenew X({ hp: 1 }). FieldBuildernow 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
Experimenting with new features for colyseus 0.18 (beta/preview)
4.0.20
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
fix toJSON(): should not make fields 'optional'. closes #222
4.0.18
callbacks: allow to call .listen() even with multiple @colyseus/schem…
4.0.17
TypeScript: fix .toJSON() and .restore() to support complex generic i…
4.0.16
StateView.remove() fixes to prevent refId not found issues.
4.0.15
schema-codegen: fixes bad parsing of interfaces