@colyseus/schema 4.0.17 → 4.0.19

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.
@@ -65,9 +65,9 @@ export type NonFunctionNonPrimitivePropNames<T> = {
65
65
  [K in keyof T]: T[K] extends Function ? never : T[K] extends number | string | boolean ? never : K;
66
66
  }[keyof T];
67
67
  type ToJSONValue<U> = U extends Schema ? ToJSON<U> : PrimitiveStringToType<U>;
68
- export type ToJSON<T> = NonFunctionProps<{
69
- [K in keyof T]: T[K] extends MapSchema<infer U> ? Record<string, ToJSONValue<U>> : T[K] extends Map<string, infer U> ? Record<string, ToJSONValue<U>> : T[K] extends ArraySchema<infer U> ? ToJSONValue<U>[] : T[K] extends SetSchema<infer U> ? ToJSONValue<U>[] : T[K] extends CollectionSchema<infer U> ? ToJSONValue<U>[] : T[K] extends Schema ? ToJSON<T[K]> : T[K];
70
- }>;
68
+ export type ToJSON<T> = {
69
+ [K in keyof T as T[K] extends Function ? never : K]: T[K] extends MapSchema<infer U> ? Record<string, ToJSONValue<U>> : T[K] extends Map<string, infer U> ? Record<string, ToJSONValue<U>> : T[K] extends ArraySchema<infer U> ? ToJSONValue<U>[] : T[K] extends SetSchema<infer U> ? ToJSONValue<U>[] : T[K] extends CollectionSchema<infer U> ? ToJSONValue<U>[] : T[K] extends Schema ? ToJSON<T[K]> : T[K];
70
+ };
71
71
  export type IsNever<T> = [T] extends [never] ? true : false;
72
72
  /**
73
73
  * 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": "4.0.17",
3
+ "version": "4.0.19",
4
4
  "description": "Binary state serializer with delta encoding for games",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,6 +11,7 @@
11
11
  "build": "tsc -p tsconfig.build.json && rollup -c rollup.config.mjs",
12
12
  "watch": "tsc -p tsconfig.build.json -w",
13
13
  "test": "tsx --tsconfig tsconfig.test.json ./node_modules/.bin/mocha test/*.test.ts test/**/*.test.ts",
14
+ "typecheck": "tsc -p tsconfig.test.json",
14
15
  "coverage": "c8 npm run test",
15
16
  "generate-test-1": "bin/schema-codegen test-external/PrimitiveTypes.ts --namespace SchemaTest.PrimitiveTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/PrimitiveTypes",
16
17
  "generate-test-2": "bin/schema-codegen test-external/ChildSchemaTypes.ts --namespace SchemaTest.ChildSchemaTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ChildSchemaTypes",
package/src/Schema.ts CHANGED
@@ -122,7 +122,7 @@ export class Schema<C = any> implements IRef {
122
122
  * @param jsonData JSON data to restore the instance from
123
123
  * @returns
124
124
  */
125
- public restore<T extends Partial<this>>(jsonData: ToJSON<T>): this {
125
+ public restore(jsonData: ToJSON<this>): this {
126
126
  const metadata: Metadata = (this.constructor as typeof Schema)[Symbol.metadata];
127
127
 
128
128
  for (const fieldIndex in metadata) {
@@ -224,7 +224,7 @@ export class Schema<C = any> implements IRef {
224
224
  return cloned;
225
225
  }
226
226
 
227
- toJSON (this: any): ToJSON<Partial<this>> {
227
+ toJSON (this: any): ToJSON<this> {
228
228
  const obj: any = {};
229
229
  const metadata = this.constructor[Symbol.metadata];
230
230
  for (const index in metadata) {
@@ -129,7 +129,7 @@ export class StateCallbackStrategy<TState extends IRef> {
129
129
  /**
130
130
  * Listen to property changes on a nested instance.
131
131
  */
132
- listen<TInstance extends Schema, K extends PublicPropNames<TInstance>>(
132
+ listen<TInstance, K extends PublicPropNames<TInstance>>(
133
133
  instance: TInstance,
134
134
  property: K,
135
135
  handler: PropertyChangeCallback<TInstance[K]>,
@@ -95,8 +95,8 @@ export type NonFunctionNonPrimitivePropNames<T> = {
95
95
  // Helper to recursively convert Schema instances to their JSON representation
96
96
  type ToJSONValue<U> = U extends Schema ? ToJSON<U> : PrimitiveStringToType<U>;
97
97
 
98
- export type ToJSON<T> = NonFunctionProps<{
99
- [K in keyof T]:
98
+ export type ToJSON<T> = {
99
+ [K in keyof T as T[K] extends Function ? never : K]:
100
100
  T[K] extends MapSchema<infer U> ? Record<string, ToJSONValue<U>>
101
101
  : T[K] extends Map<string, infer U> ? Record<string, ToJSONValue<U>>
102
102
  : T[K] extends ArraySchema<infer U> ? ToJSONValue<U>[]
@@ -104,7 +104,7 @@ export type ToJSON<T> = NonFunctionProps<{
104
104
  : T[K] extends CollectionSchema<infer U> ? ToJSONValue<U>[]
105
105
  : T[K] extends Schema ? ToJSON<T[K]>
106
106
  : T[K]
107
- }>;
107
+ };
108
108
 
109
109
  // Helper type to check if T is exactly 'never' (meaning no InitProps was provided)
110
110
  export type IsNever<T> = [T] extends [never] ? true : false;