@colyseus/schema 2.0.15 → 2.0.17
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/cjs/index.js +8 -4
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +6 -1
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +8 -4
- package/lib/Reflection.js +3 -3
- package/lib/Reflection.js.map +1 -1
- package/lib/Schema.d.ts +1 -3
- package/lib/Schema.js.map +1 -1
- package/lib/codegen/languages/csharp.js +2 -1
- package/lib/codegen/languages/csharp.js.map +1 -1
- package/lib/encoding/encode.d.ts +1 -1
- package/lib/events/EventEmitter.d.ts +13 -0
- package/lib/events/EventEmitter.js +31 -0
- package/lib/events/EventEmitter.js.map +1 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/spec.js +1 -1
- package/lib/spec.js.map +1 -1
- package/lib/types/HelperTypes.d.ts +2 -2
- package/lib/types/HelperTypes.js.map +1 -1
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.js +13 -0
- package/lib/types/index.js.map +1 -0
- package/package.json +3 -3
- package/src/Schema.ts +2 -2
- package/src/codegen/languages/csharp.ts +3 -2
- package/src/index.ts +8 -5
- package/src/types/HelperTypes.ts +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Schema
|
|
1
|
+
export { Schema } from "./Schema";
|
|
2
|
+
export type { DataChange } from "./Schema";
|
|
2
3
|
import { MapSchema } from "./types/MapSchema";
|
|
3
4
|
export { MapSchema };
|
|
4
5
|
import { ArraySchema } from "./types/ArraySchema";
|
|
@@ -10,10 +11,11 @@ export { SetSchema };
|
|
|
10
11
|
import { registerType } from "./types/typeRegistry";
|
|
11
12
|
export { registerType };
|
|
12
13
|
export { dumpChanges } from "./utils";
|
|
13
|
-
export { Iterator } from "./encoding/decode";
|
|
14
|
+
export type { Iterator } from "./encoding/decode";
|
|
14
15
|
import * as encode from "./encoding/encode";
|
|
15
16
|
import * as decode from "./encoding/decode";
|
|
16
17
|
export { encode, decode };
|
|
17
18
|
export { Reflection, ReflectionType, ReflectionField, } from "./Reflection";
|
|
18
|
-
export { type, deprecated, filter, filterChildren, defineTypes, hasFilter, SchemaDefinition, Context,
|
|
19
|
+
export { type, deprecated, filter, filterChildren, defineTypes, hasFilter, SchemaDefinition, Context, } from "./annotations";
|
|
20
|
+
export type { DefinitionType, PrimitiveType, Definition, FilterCallback, } from "./annotations";
|
|
19
21
|
export { OPERATION } from "./spec";
|
package/lib/index.js
CHANGED
|
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "defineTypes", { enumerable: true, get: function
|
|
|
39
39
|
Object.defineProperty(exports, "hasFilter", { enumerable: true, get: function () { return annotations_1.hasFilter; } });
|
|
40
40
|
// Internals
|
|
41
41
|
Object.defineProperty(exports, "SchemaDefinition", { enumerable: true, get: function () { return annotations_1.SchemaDefinition; } });
|
|
42
|
-
// Types
|
|
43
42
|
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return annotations_1.Context; } });
|
|
44
43
|
var spec_1 = require("./spec");
|
|
45
44
|
Object.defineProperty(exports, "OPERATION", { enumerable: true, get: function () { return spec_1.OPERATION; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAGf,iDAA6C;AACpC,0FADA,qBAAS,OACA;AAElB,qDAAkD;AACzC,4FADA,yBAAW,OACA;AAEpB,+DAA4D;AACnD,iGADA,mCAAgB,OACA;AAEzB,iDAA8C;AACrC,0FADA,qBAAS,OACA;AAElB,uDAAoD;AAC3C,6FADA,2BAAY,OACA;AAErB,IAAA,2BAAY,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,qBAAS,EAAE,CAAC,CAAC;AAChD,IAAA,2BAAY,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,yBAAW,EAAE,CAAC,CAAC;AACpD,IAAA,2BAAY,EAAC,KAAK,EAAE,EAAE,WAAW,EAAE,qBAAS,EAAE,CAAC,CAAC;AAChD,IAAA,2BAAY,EAAC,YAAY,EAAE,EAAE,WAAW,EAAE,mCAAgB,GAAG,CAAC,CAAC;AAE/D,QAAQ;AACR,iCAAsC;AAA7B,oGAAA,WAAW,OAAA;AAIpB,4CAA4C;AAEnC,wBAAM;AADf,4CAA4C;AAC3B,wBAAM;AAEvB,aAAa;AACb,2CAIsB;AAHlB,wGAAA,UAAU,OAAA;AACV,4GAAA,cAAc,OAAA;AACd,6GAAA,eAAe,OAAA;AAGnB,6CAYuB;AAXnB,cAAc;AACd,mGAAA,IAAI,OAAA;AACJ,yGAAA,UAAU,OAAA;AACV,qGAAA,MAAM,OAAA;AACN,6GAAA,cAAc,OAAA;AACd,0GAAA,WAAW,OAAA;AACX,wGAAA,SAAS,OAAA;AAET,YAAY;AACZ,+GAAA,gBAAgB,OAAA;AAChB,sGAAA,OAAO,OAAA;AAWX,+BAAmC;AAA1B,iGAAA,SAAS,OAAA","sourcesContent":["export { Schema } from \"./Schema\";\nexport type { DataChange } from \"./Schema\";\n\nimport { MapSchema } from \"./types/MapSchema\"\nexport { MapSchema };\n\nimport { ArraySchema } from \"./types/ArraySchema\";\nexport { ArraySchema };\n\nimport { CollectionSchema } from \"./types/CollectionSchema\";\nexport { CollectionSchema };\n\nimport { SetSchema } from \"./types/SetSchema\";\nexport { SetSchema };\n\nimport { registerType } from \"./types/typeRegistry\";\nexport { registerType };\n\nregisterType(\"map\", { constructor: MapSchema });\nregisterType(\"array\", { constructor: ArraySchema });\nregisterType(\"set\", { constructor: SetSchema });\nregisterType(\"collection\", { constructor: CollectionSchema, });\n\n// Utils\nexport { dumpChanges } from \"./utils\";\n\n// Encoder / Decoder\nexport type { Iterator } from \"./encoding/decode\";\nimport * as encode from \"./encoding/encode\";\nimport * as decode from \"./encoding/decode\";\nexport { encode, decode };\n\n// Reflection\nexport {\n Reflection,\n ReflectionType,\n ReflectionField,\n} from \"./Reflection\";\n\nexport {\n // Annotations\n type,\n deprecated,\n filter,\n filterChildren,\n defineTypes,\n hasFilter,\n\n // Internals\n SchemaDefinition,\n Context,\n} from \"./annotations\";\n\n// Annotation types\nexport type {\n DefinitionType,\n PrimitiveType,\n Definition,\n FilterCallback,\n} from \"./annotations\";\n\nexport { OPERATION } from \"./spec\";"]}
|
package/lib/spec.js
CHANGED
|
@@ -22,7 +22,7 @@ var OPERATION;
|
|
|
22
22
|
OPERATION[OPERATION["TOUCH"] = 1] = "TOUCH";
|
|
23
23
|
// MapSchema Operations
|
|
24
24
|
OPERATION[OPERATION["CLEAR"] = 10] = "CLEAR";
|
|
25
|
-
})(OPERATION
|
|
25
|
+
})(OPERATION || (exports.OPERATION = OPERATION = {}));
|
|
26
26
|
// export enum OPERATION {
|
|
27
27
|
// // add new structure/primitive
|
|
28
28
|
// // (128)
|
package/lib/spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../src/spec.ts"],"names":[],"mappings":";;;AAAA,iGAAiG;AACpF,QAAA,mBAAmB,GAAG,GAAG,CAAC,CAAC,4DAA4D;AACvF,QAAA,OAAO,GAAG,GAAG,CAAC;AAE3B;;GAEG;AACH,IAAY,SAmBX;AAnBD,WAAY,SAAS;IACjB,8BAA8B;IAC9B,yCAAS,CAAA;IAET,8BAA8B;IAC9B,+CAAW,CAAA;IAEX,eAAe;IACf,8CAAW,CAAA;IAEX,mCAAmC;IACnC,+DAAoB,CAAA;IAEpB,yFAAyF;IACzF,2BAA2B;IAC3B,2CAAS,CAAA;IAET,uBAAuB;IACvB,4CAAU,CAAA;AACd,CAAC,EAnBW,SAAS,
|
|
1
|
+
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../src/spec.ts"],"names":[],"mappings":";;;AAAA,iGAAiG;AACpF,QAAA,mBAAmB,GAAG,GAAG,CAAC,CAAC,4DAA4D;AACvF,QAAA,OAAO,GAAG,GAAG,CAAC;AAE3B;;GAEG;AACH,IAAY,SAmBX;AAnBD,WAAY,SAAS;IACjB,8BAA8B;IAC9B,yCAAS,CAAA;IAET,8BAA8B;IAC9B,+CAAW,CAAA;IAEX,eAAe;IACf,8CAAW,CAAA;IAEX,mCAAmC;IACnC,+DAAoB,CAAA;IAEpB,yFAAyF;IACzF,2BAA2B;IAC3B,2CAAS,CAAA;IAET,uBAAuB;IACvB,4CAAU,CAAA;AACd,CAAC,EAnBW,SAAS,yBAAT,SAAS,QAmBpB;AAED,0BAA0B;AAC1B,qCAAqC;AACrC,eAAe;AACf,8BAA8B;AAE9B,qCAAqC;AACrC,8BAA8B;AAE9B,sBAAsB;AACtB,gCAAgC;AAEhC,0CAA0C;AAC1C,wCAAwC;AAExC,gGAAgG;AAChG,kCAAkC;AAClC,6BAA6B;AAE7B,8BAA8B;AAC9B,kBAAkB;AAClB,IAAI","sourcesContent":["// export const SWITCH_TO_STRUCTURE = 193; (easily collides with DELETE_AND_ADD + fieldIndex = 2)\nexport const SWITCH_TO_STRUCTURE = 255; // (decoding collides with DELETE_AND_ADD + fieldIndex = 63)\nexport const TYPE_ID = 213;\n\n/**\n * Encoding Schema field operations.\n */\nexport enum OPERATION {\n // add new structure/primitive\n ADD = 128,\n\n // replace structure/primitive\n REPLACE = 0,\n\n // delete field\n DELETE = 64,\n\n // DELETE field, followed by an ADD\n DELETE_AND_ADD = 192, // 11100000\n\n // TOUCH is used to determine hierarchy of nested Schema structures during serialization.\n // touches are NOT encoded.\n TOUCH = 1, // 00000000\n\n // MapSchema Operations\n CLEAR = 10,\n}\n\n// export enum OPERATION {\n// // add new structure/primitive\n// // (128)\n// ADD = 128, // 10000000,\n\n// // replace structure/primitive\n// REPLACE = 1,// 00000001\n\n// // delete field\n// DELETE = 192, // 11000000\n\n// // DELETE field, followed by an ADD\n// DELETE_AND_ADD = 224, // 11100000\n\n// // TOUCH is used to determine hierarchy of nested Schema structures during serialization.\n// // touches are NOT encoded.\n// TOUCH = 0, // 00000000\n\n// // MapSchema Operations\n// CLEAR = 10,\n// }"]}
|
|
@@ -6,6 +6,6 @@ export type NonFunctionProps<T> = Omit<T, {
|
|
|
6
6
|
export type NonFunctionPropNames<T> = {
|
|
7
7
|
[K in keyof T]: T[K] extends Function ? never : K;
|
|
8
8
|
}[keyof T];
|
|
9
|
-
export type ToJSON<T> =
|
|
9
|
+
export type ToJSON<T> = NonFunctionProps<{
|
|
10
10
|
[K in keyof T]: T[K] extends MapSchema<infer U> ? Record<string, U> : T[K] extends ArraySchema<infer U> ? U[] : T[K];
|
|
11
|
-
}
|
|
11
|
+
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HelperTypes.js","sourceRoot":"","sources":["../../src/types/HelperTypes.ts"],"names":[],"mappings":"","sourcesContent":["import { ArraySchema } from \"./ArraySchema\";\nimport { MapSchema } from \"./MapSchema\";\n\nexport type NonFunctionProps<T> = Omit<T, {\n [K in keyof T]: T[K] extends Function ? K : never;\n}[keyof T]>;\n\nexport type NonFunctionPropNames<T> = {\n [K in keyof T]: T[K] extends Function ? never : K\n}[keyof T];\n\nexport type ToJSON<T> =
|
|
1
|
+
{"version":3,"file":"HelperTypes.js","sourceRoot":"","sources":["../../src/types/HelperTypes.ts"],"names":[],"mappings":"","sourcesContent":["import { ArraySchema } from \"./ArraySchema\";\nimport { MapSchema } from \"./MapSchema\";\n\nexport type NonFunctionProps<T> = Omit<T, {\n [K in keyof T]: T[K] extends Function ? K : never;\n}[keyof T]>;\n\nexport type NonFunctionPropNames<T> = {\n [K in keyof T]: T[K] extends Function ? never : K\n}[keyof T];\n\nexport type ToJSON<T> = NonFunctionProps<{\n [K in keyof T]: T[K] extends MapSchema<infer U>\n ? Record<string, U>\n : T[K] extends ArraySchema<infer U>\n ? U[]\n : T[K]\n}>;"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getType = exports.registerType = void 0;
|
|
4
|
+
const registeredTypes = {};
|
|
5
|
+
function registerType(identifier, definition) {
|
|
6
|
+
registeredTypes[identifier] = definition;
|
|
7
|
+
}
|
|
8
|
+
exports.registerType = registerType;
|
|
9
|
+
function getType(identifier) {
|
|
10
|
+
return registeredTypes[identifier];
|
|
11
|
+
}
|
|
12
|
+
exports.getType = getType;
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;AAUA,MAAM,eAAe,GAA4C,EAAE,CAAC;AAEpE,SAAgB,YAAY,CAAC,UAAkB,EAAE,UAA0B;IACvE,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AAC7C,CAAC;AAFD,oCAEC;AAED,SAAgB,OAAO,CAAC,UAAkB;IACtC,OAAO,eAAe,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC;AAFD,0BAEC","sourcesContent":["export interface TypeDefinition {\n constructor: any,\n\n //\n // TODO: deprecate proxy on next version\n // the proxy is used for compatibility with versions <1.0.0 of @colyseus/schema\n //\n getProxy?: any,\n}\n\nconst registeredTypes: {[identifier: string] : TypeDefinition} = {};\n\nexport function registerType(identifier: string, definition: TypeDefinition) {\n registeredTypes[identifier] = definition;\n}\n\nexport function getType(identifier: string): TypeDefinition {\n return registeredTypes[identifier];\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colyseus/schema",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.17",
|
|
4
4
|
"description": "Binary state serializer with delta encoding for games",
|
|
5
5
|
"bin": {
|
|
6
6
|
"schema-codegen": "./bin/schema-codegen"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc && rollup -c rollup.config.js",
|
|
10
10
|
"watch": "tsc -w",
|
|
11
|
-
"test": "mocha --require ts-node/register test
|
|
11
|
+
"test": "mocha --require ts-node/register test/*.test.ts test/**/*.test.ts",
|
|
12
12
|
"coverage": "nyc mocha --require ts-node/register --require source-map-support/register --recursive test/**Test.ts",
|
|
13
13
|
"generate-test-1": "bin/schema-codegen test-external/PrimitiveTypes.ts --namespace SchemaTest.PrimitiveTypes --output ../colyseus-unity-sdk/Assets/Editor/ColyseusTests/Schema/PrimitiveTypes",
|
|
14
14
|
"generate-test-2": "bin/schema-codegen test-external/ChildSchemaTypes.ts --namespace SchemaTest.ChildSchemaTypes --output ../colyseus-unity-sdk/Assets/Editor/ColyseusTests/Schema/ChildSchemaTypes",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"source-map-support": "^0.5.13",
|
|
79
79
|
"ts-node": "^7.0.1",
|
|
80
80
|
"tslib": "^2.1.0",
|
|
81
|
-
"tsx": "^3.
|
|
81
|
+
"tsx": "^3.13.0",
|
|
82
82
|
"typescript": "^5.0.4"
|
|
83
83
|
},
|
|
84
84
|
"nyc": {
|
package/src/Schema.ts
CHANGED
|
@@ -898,7 +898,7 @@ export abstract class Schema {
|
|
|
898
898
|
const schema = this._definition.schema;
|
|
899
899
|
const deprecated = this._definition.deprecated;
|
|
900
900
|
|
|
901
|
-
const obj:
|
|
901
|
+
const obj: unknown = {};
|
|
902
902
|
for (let field in schema) {
|
|
903
903
|
if (!deprecated[field] && this[field] !== null && typeof (this[field]) !== "undefined") {
|
|
904
904
|
obj[field] = (typeof (this[field]['toJSON']) === "function")
|
|
@@ -906,7 +906,7 @@ export abstract class Schema {
|
|
|
906
906
|
: this[`_${field}`];
|
|
907
907
|
}
|
|
908
908
|
}
|
|
909
|
-
return obj
|
|
909
|
+
return obj as ToJSON<typeof this>;
|
|
910
910
|
}
|
|
911
911
|
|
|
912
912
|
discardAllChanges() {
|
|
@@ -99,7 +99,8 @@ ${_enum.properties
|
|
|
99
99
|
return `${indent}\tpublic const ${dataType} ${prop.name} = ${value};`;
|
|
100
100
|
})
|
|
101
101
|
.join("\n")}
|
|
102
|
-
${indent}}
|
|
102
|
+
${indent}}
|
|
103
|
+
${namespace ? "}" : ""}`
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
function generateProperty(prop: Property, indent: string = "") {
|
|
@@ -211,4 +212,4 @@ function getType(prop: Property) {
|
|
|
211
212
|
? `${typeMaps[prop.childType] || prop.childType}[]`
|
|
212
213
|
: typeMaps[prop.type];
|
|
213
214
|
}
|
|
214
|
-
}
|
|
215
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Schema
|
|
1
|
+
export { Schema } from "./Schema";
|
|
2
|
+
export type { DataChange } from "./Schema";
|
|
2
3
|
|
|
3
4
|
import { MapSchema } from "./types/MapSchema"
|
|
4
5
|
export { MapSchema };
|
|
@@ -24,7 +25,7 @@ registerType("collection", { constructor: CollectionSchema, });
|
|
|
24
25
|
export { dumpChanges } from "./utils";
|
|
25
26
|
|
|
26
27
|
// Encoder / Decoder
|
|
27
|
-
export { Iterator } from "./encoding/decode";
|
|
28
|
+
export type { Iterator } from "./encoding/decode";
|
|
28
29
|
import * as encode from "./encoding/encode";
|
|
29
30
|
import * as decode from "./encoding/decode";
|
|
30
31
|
export { encode, decode };
|
|
@@ -47,12 +48,14 @@ export {
|
|
|
47
48
|
|
|
48
49
|
// Internals
|
|
49
50
|
SchemaDefinition,
|
|
50
|
-
|
|
51
|
-
// Types
|
|
52
51
|
Context,
|
|
52
|
+
} from "./annotations";
|
|
53
|
+
|
|
54
|
+
// Annotation types
|
|
55
|
+
export type {
|
|
56
|
+
DefinitionType,
|
|
53
57
|
PrimitiveType,
|
|
54
58
|
Definition,
|
|
55
|
-
DefinitionType,
|
|
56
59
|
FilterCallback,
|
|
57
60
|
} from "./annotations";
|
|
58
61
|
|
package/src/types/HelperTypes.ts
CHANGED
|
@@ -9,10 +9,10 @@ export type NonFunctionPropNames<T> = {
|
|
|
9
9
|
[K in keyof T]: T[K] extends Function ? never : K
|
|
10
10
|
}[keyof T];
|
|
11
11
|
|
|
12
|
-
export type ToJSON<T> =
|
|
12
|
+
export type ToJSON<T> = NonFunctionProps<{
|
|
13
13
|
[K in keyof T]: T[K] extends MapSchema<infer U>
|
|
14
14
|
? Record<string, U>
|
|
15
15
|
: T[K] extends ArraySchema<infer U>
|
|
16
16
|
? U[]
|
|
17
17
|
: T[K]
|
|
18
|
-
}
|
|
18
|
+
}>;
|