@colyseus/schema 5.0.5 → 5.0.6

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.
@@ -97,6 +97,28 @@ export type ToJSON<T> = NonFunctionProps<{
97
97
  } & {
98
98
  [K in ToJSONOptionalKeys<T>]?: ToJSONField<Exclude<T[K], undefined>>;
99
99
  }>;
100
+ /**
101
+ * The plain DATA shape of a Schema instance type `T`: its synchronized fields
102
+ * with all `Schema` machinery stripped (`assign`, `clone`, `toJSON`, the
103
+ * change-tracking state, the internal symbol keys, …), so a plain object literal
104
+ * satisfies it. Field types — including narrowed primitives like
105
+ * `t.int8<-1 | 0 | 1>()` — are preserved exactly.
106
+ *
107
+ * Use it to type code that operates on schema-shaped *plain objects* rather than
108
+ * decoded instances: deterministic simulation / physics steps, synthesized or
109
+ * buffered input commands, plain DTOs, etc.
110
+ *
111
+ * ```ts
112
+ * function applyInput(state: Player, cmd: Data<MoveInput>) { … }
113
+ * applyInput(player, { moveX: 1, jump: false, dt }); // plain literal — OK
114
+ * ```
115
+ *
116
+ * Unlike {@link ToJSON} (a recursive *serialization* shape), this is a flat
117
+ * structural projection: nested Schema / collection fields keep their instance
118
+ * types, and it does not retain the non-method `Schema` members that `ToJSON`'s
119
+ * `NonFunctionProps` pass leaves behind.
120
+ */
121
+ export type Data<T> = Omit<T, keyof Schema>;
100
122
  export type IsNever<T> = [T] extends [never] ? true : false;
101
123
  /**
102
124
  * Type helper for .assign() method - allows assigning values in a flexible way
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/schema",
3
- "version": "5.0.5",
3
+ "version": "5.0.6",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "type": "module",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -71,7 +71,7 @@ export { t, FieldBuilder, isBuilder, type BuilderDefinition, type ChildType } fr
71
71
  export { TypeContext } from "./types/TypeContext.js";
72
72
 
73
73
  // Helper types for type inference
74
- export type { InferValueType, InferSchemaInstanceType, AssignableProps, BuilderInitProps } from "./types/HelperTypes.js";
74
+ export type { InferValueType, InferSchemaInstanceType, AssignableProps, BuilderInitProps, Data } from "./types/HelperTypes.js";
75
75
 
76
76
  export { getDecoderStateCallbacks, type CallbackProxy, type SchemaCallback, type CollectionCallback, type SchemaCallbackProxy } from "./decoder/strategy/getDecoderStateCallbacks.js";
77
77
  export { Callbacks, StateCallbackStrategy } from "./decoder/strategy/Callbacks.js";
@@ -143,6 +143,29 @@ export type ToJSON<T> = NonFunctionProps<
143
143
  & { [K in ToJSONOptionalKeys<T>]?: ToJSONField<Exclude<T[K], undefined>> }
144
144
  >;
145
145
 
146
+ /**
147
+ * The plain DATA shape of a Schema instance type `T`: its synchronized fields
148
+ * with all `Schema` machinery stripped (`assign`, `clone`, `toJSON`, the
149
+ * change-tracking state, the internal symbol keys, …), so a plain object literal
150
+ * satisfies it. Field types — including narrowed primitives like
151
+ * `t.int8<-1 | 0 | 1>()` — are preserved exactly.
152
+ *
153
+ * Use it to type code that operates on schema-shaped *plain objects* rather than
154
+ * decoded instances: deterministic simulation / physics steps, synthesized or
155
+ * buffered input commands, plain DTOs, etc.
156
+ *
157
+ * ```ts
158
+ * function applyInput(state: Player, cmd: Data<MoveInput>) { … }
159
+ * applyInput(player, { moveX: 1, jump: false, dt }); // plain literal — OK
160
+ * ```
161
+ *
162
+ * Unlike {@link ToJSON} (a recursive *serialization* shape), this is a flat
163
+ * structural projection: nested Schema / collection fields keep their instance
164
+ * types, and it does not retain the non-method `Schema` members that `ToJSON`'s
165
+ * `NonFunctionProps` pass leaves behind.
166
+ */
167
+ export type Data<T> = Omit<T, keyof Schema>;
168
+
146
169
  // Helper type to check if T is exactly 'never' (meaning no InitProps was provided)
147
170
  export type IsNever<T> = [T] extends [never] ? true : false;
148
171