@colyseus/schema 4.0.4 → 4.0.5
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.
- package/build/Schema.d.ts +7 -0
- package/build/index.cjs +13 -4
- package/build/index.cjs.map +1 -1
- package/build/index.js +13 -4
- package/build/index.mjs +13 -4
- package/build/index.mjs.map +1 -1
- package/package.json +20 -21
- package/src/Schema.ts +10 -0
- package/src/decoder/strategy/Callbacks.ts +2 -2
- package/src/decoder/strategy/getDecoderStateCallbacks.ts +2 -2
package/package.json
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/schema",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"description": "Binary state serializer with delta encoding for games",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"schema-codegen": "bin/schema-codegen",
|
|
8
8
|
"schema-debug": "bin/schema-debug"
|
|
9
9
|
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc -p tsconfig.build.json && rollup -c rollup.config.mjs",
|
|
12
|
-
"watch": "tsc -p tsconfig.build.json -w",
|
|
13
|
-
"test": "tsx --tsconfig tsconfig.test.json ./node_modules/.bin/mocha test/*.test.ts test/**/*.test.ts",
|
|
14
|
-
"coverage": "c8 npm run test",
|
|
15
|
-
"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
|
-
"generate-test-2": "bin/schema-codegen test-external/ChildSchemaTypes.ts --namespace SchemaTest.ChildSchemaTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ChildSchemaTypes",
|
|
17
|
-
"generate-test-3": "bin/schema-codegen test-external/ArraySchemaTypes.ts --namespace SchemaTest.ArraySchemaTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ArraySchemaTypes",
|
|
18
|
-
"generate-test-4": "bin/schema-codegen test-external/MapSchemaTypes.ts --namespace SchemaTest.MapSchemaTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/MapSchemaTypes",
|
|
19
|
-
"generate-test-5": "bin/schema-codegen test-external/InheritedTypes.ts --namespace SchemaTest.InheritedTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/InheritedTypes",
|
|
20
|
-
"generate-test-6": "bin/schema-codegen test-external/MapSchemaInt8.ts --namespace SchemaTest.MapSchemaInt8 --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/MapSchemaInt8",
|
|
21
|
-
"generate-test-7": "bin/schema-codegen test-external/BackwardsForwards.ts --namespace SchemaTest.BackwardsForwards --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/BackwardsForwards",
|
|
22
|
-
"generate-test-8": "bin/schema-codegen test-external/FilteredTypes.ts --namespace SchemaTest.FilteredTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/FilteredTypes",
|
|
23
|
-
"generate-test-9": "bin/schema-codegen test-external/InstanceSharingTypes.ts --namespace SchemaTest.InstanceSharingTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/InstanceSharingTypes",
|
|
24
|
-
"generate-test-10": "bin/schema-codegen test-external/Callbacks.ts --namespace SchemaTest.Callbacks --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/Callbacks",
|
|
25
|
-
"generate-test-11": "bin/schema-codegen test-external/MapSchemaMoveNullifyType.ts --namespace SchemaTest.MapSchemaMoveNullifyType --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/MapSchemaMoveNullifyType",
|
|
26
|
-
"generate-test-12": "bin/schema-codegen test-external/ArraySchemaClear --namespace SchemaTest.ArraySchemaClear --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ArraySchemaClear",
|
|
27
|
-
"prepublishOnly": "npm run build"
|
|
28
|
-
},
|
|
29
10
|
"files": [
|
|
30
11
|
"src",
|
|
31
12
|
"build",
|
|
@@ -93,5 +74,23 @@
|
|
|
93
74
|
"text"
|
|
94
75
|
],
|
|
95
76
|
"all": true
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "tsc -p tsconfig.build.json && rollup -c rollup.config.mjs",
|
|
80
|
+
"watch": "tsc -p tsconfig.build.json -w",
|
|
81
|
+
"test": "tsx --tsconfig tsconfig.test.json ./node_modules/.bin/mocha test/*.test.ts test/**/*.test.ts",
|
|
82
|
+
"coverage": "c8 npm run test",
|
|
83
|
+
"generate-test-1": "bin/schema-codegen test-external/PrimitiveTypes.ts --namespace SchemaTest.PrimitiveTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/PrimitiveTypes",
|
|
84
|
+
"generate-test-2": "bin/schema-codegen test-external/ChildSchemaTypes.ts --namespace SchemaTest.ChildSchemaTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ChildSchemaTypes",
|
|
85
|
+
"generate-test-3": "bin/schema-codegen test-external/ArraySchemaTypes.ts --namespace SchemaTest.ArraySchemaTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ArraySchemaTypes",
|
|
86
|
+
"generate-test-4": "bin/schema-codegen test-external/MapSchemaTypes.ts --namespace SchemaTest.MapSchemaTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/MapSchemaTypes",
|
|
87
|
+
"generate-test-5": "bin/schema-codegen test-external/InheritedTypes.ts --namespace SchemaTest.InheritedTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/InheritedTypes",
|
|
88
|
+
"generate-test-6": "bin/schema-codegen test-external/MapSchemaInt8.ts --namespace SchemaTest.MapSchemaInt8 --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/MapSchemaInt8",
|
|
89
|
+
"generate-test-7": "bin/schema-codegen test-external/BackwardsForwards.ts --namespace SchemaTest.BackwardsForwards --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/BackwardsForwards",
|
|
90
|
+
"generate-test-8": "bin/schema-codegen test-external/FilteredTypes.ts --namespace SchemaTest.FilteredTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/FilteredTypes",
|
|
91
|
+
"generate-test-9": "bin/schema-codegen test-external/InstanceSharingTypes.ts --namespace SchemaTest.InstanceSharingTypes --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/InstanceSharingTypes",
|
|
92
|
+
"generate-test-10": "bin/schema-codegen test-external/Callbacks.ts --namespace SchemaTest.Callbacks --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/Callbacks",
|
|
93
|
+
"generate-test-11": "bin/schema-codegen test-external/MapSchemaMoveNullifyType.ts --namespace SchemaTest.MapSchemaMoveNullifyType --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/MapSchemaMoveNullifyType",
|
|
94
|
+
"generate-test-12": "bin/schema-codegen test-external/ArraySchemaClear --namespace SchemaTest.ArraySchemaClear --output ../colyseus-unity-sdk/Assets/Colyseus/Tests/Editor/ColyseusTests/Schema/ArraySchemaClear"
|
|
96
95
|
}
|
|
97
|
-
}
|
|
96
|
+
}
|
package/src/Schema.ts
CHANGED
|
@@ -42,6 +42,16 @@ export class Schema<C = any> implements IRef {
|
|
|
42
42
|
return typeof((type as typeof Schema)[Symbol.metadata]) === "object";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Check if a value is an instance of Schema.
|
|
47
|
+
* This method uses duck-typing to avoid issues with multiple @colyseus/schema versions.
|
|
48
|
+
* @param obj Value to check
|
|
49
|
+
* @returns true if the value is a Schema instance
|
|
50
|
+
*/
|
|
51
|
+
static isSchema(obj: any): obj is Schema {
|
|
52
|
+
return typeof obj?.assign === "function";
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
/**
|
|
46
56
|
* Track property changes
|
|
47
57
|
*/
|
|
@@ -344,7 +344,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
344
344
|
//
|
|
345
345
|
if (
|
|
346
346
|
(change.op & OPERATION.DELETE) === OPERATION.DELETE &&
|
|
347
|
-
change.previousValue
|
|
347
|
+
Schema.isSchema(change.previousValue)
|
|
348
348
|
) {
|
|
349
349
|
const childRefId = (change.previousValue as Ref)[$refId];
|
|
350
350
|
const deleteCallbacks = this.callbacks[childRefId]?.[OPERATION.DELETE];
|
|
@@ -355,7 +355,7 @@ export class StateCallbackStrategy<TState extends Schema> {
|
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
if (ref
|
|
358
|
+
if (Schema.isSchema(ref)) {
|
|
359
359
|
//
|
|
360
360
|
// Handle Schema instance
|
|
361
361
|
//
|
|
@@ -137,7 +137,7 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
|
|
|
137
137
|
//
|
|
138
138
|
if (
|
|
139
139
|
(change.op & OPERATION.DELETE) === OPERATION.DELETE &&
|
|
140
|
-
change.previousValue
|
|
140
|
+
Schema.isSchema(change.previousValue)
|
|
141
141
|
) {
|
|
142
142
|
const deleteCallbacks = callbacks[(change.previousValue as Ref)[$refId]]?.[OPERATION.DELETE];
|
|
143
143
|
for (let i = deleteCallbacks?.length - 1; i >= 0; i--) {
|
|
@@ -145,7 +145,7 @@ export function getDecoderStateCallbacks<T extends Schema>(decoder: Decoder<T>):
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
if (ref
|
|
148
|
+
if (Schema.isSchema(ref)) {
|
|
149
149
|
//
|
|
150
150
|
// Handle schema instance
|
|
151
151
|
//
|