@colyseus/schema 2.0.2 → 2.0.3
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/lib/codegen/types.js +8 -8
- package/lib/codegen/types.js.map +1 -1
- package/package.json +1 -1
package/lib/codegen/types.js
CHANGED
|
@@ -19,13 +19,6 @@ var Context = /** @class */ (function () {
|
|
|
19
19
|
return {
|
|
20
20
|
classes: this.classes.filter(function (klass) {
|
|
21
21
|
if (_this.isSchemaClass(klass)) {
|
|
22
|
-
//
|
|
23
|
-
// FIXME: see "this.isSchemaClass()" comments.
|
|
24
|
-
//
|
|
25
|
-
// When extending from `schema.Schema`, it is required to
|
|
26
|
-
// normalize as "Schema" for code generation.
|
|
27
|
-
//
|
|
28
|
-
klass.extends = "Schema";
|
|
29
22
|
return true;
|
|
30
23
|
}
|
|
31
24
|
else {
|
|
@@ -58,12 +51,19 @@ var Context = /** @class */ (function () {
|
|
|
58
51
|
var currentClass = klass;
|
|
59
52
|
while (!isSchema && currentClass) {
|
|
60
53
|
//
|
|
61
|
-
// TODO: ideally we should check for actual @
|
|
54
|
+
// TODO: ideally we should check for actual @colyseus/schema module
|
|
62
55
|
// reference rather than arbitrary strings.
|
|
63
56
|
//
|
|
64
57
|
isSchema = (currentClass.extends === "Schema" ||
|
|
65
58
|
currentClass.extends === "schema.Schema" ||
|
|
66
59
|
currentClass.extends === "Schema.Schema");
|
|
60
|
+
//
|
|
61
|
+
// When extending from `schema.Schema`, it is required to
|
|
62
|
+
// normalize as "Schema" for code generation.
|
|
63
|
+
//
|
|
64
|
+
if (currentClass === klass && isSchema) {
|
|
65
|
+
klass.extends = "Schema";
|
|
66
|
+
}
|
|
67
67
|
currentClass = this.getParentClass(currentClass);
|
|
68
68
|
}
|
|
69
69
|
return isSchema;
|
package/lib/codegen/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/codegen/types.ts"],"names":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CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,OAAO,EAA9B,CAA8B,CAAC,CAAC,EAChF;YACE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAA,IAAI;gBACxB,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC;YAChD,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IACL,YAAC;AAAD,CAAC,AA1BD,IA0BC;AA1BY,sBAAK;AA4BlB;IAAA;IAMA,CAAC;IAAD,eAAC;AAAD,CAAC,AAND,IAMC;AANY,4BAAQ;AAarB,SAAgB,kBAAkB,CAAC,KAAY,EAAE,UAAmB,EAAE,WAA2B;IAA3B,4BAAA,EAAA,kBAA2B;IAC7F,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,IAAI,eAAe,GAAY,EAAE,CAAC;IAElC,IAAI,WAAW,EAAE;QACb,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACtC;IAED,OAAO,YAAY,CAAC,OAAO,KAAK,QAAQ,EAAE;QACtC,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,IAAI,IAAI,YAAY,CAAC,OAAO,EAAlC,CAAkC,CAAC,CAAC;QAC5E,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KACtC;IAED,OAAO,eAAe,CAAC;AAC3B,CAAC;AAdD,gDAcC","sourcesContent":["import * as fs from \"fs\";\n\nconst VERSION = JSON.parse(fs.readFileSync(__dirname + \"/../../package.json\").toString()).version;\nconst COMMENT_HEADER = `\nTHIS FILE HAS BEEN GENERATED AUTOMATICALLY\nDO NOT CHANGE IT MANUALLY UNLESS YOU KNOW WHAT YOU'RE DOING\n\nGENERATED USING @colyseus/schema ${VERSION}\n`;\n\nexport function getCommentHeader(singleLineComment: string = \"//\") {\n return `${COMMENT_HEADER.split(\"\\n\").map(line => `${singleLineComment} ${line}`).join(\"\\n\")}`;\n}\n\nexport class Context {\n classes: Class[] = [];\n interfaces: Interface[] = [];\n\n getStructures() {\n return {\n classes: this.classes.filter(klass => {\n if (this.isSchemaClass(klass)) {\n return true;\n\n } else {\n let parentClass = klass;\n while (parentClass = this.getParentClass(parentClass)) {\n if (this.isSchemaClass(parentClass)) {\n return true;\n }\n }\n }\n return false;\n }),\n interfaces: this.interfaces,\n };\n }\n\n addStructure(structure: IStructure) {\n structure.context = this;\n\n if (structure instanceof Class) {\n this.classes.push(structure);\n\n } else if (structure instanceof Interface) {\n this.interfaces.push(structure);\n }\n }\n\n private getParentClass(klass: Class) {\n return this.classes.find(c => c.name === klass.extends);\n }\n\n private isSchemaClass(klass: Class) {\n let isSchema: boolean = false;\n\n let currentClass = klass;\n while (!isSchema && currentClass) {\n //\n // TODO: ideally we should check for actual @colyseus/schema module\n // reference rather than arbitrary strings.\n //\n isSchema = (\n currentClass.extends === \"Schema\" ||\n currentClass.extends === \"schema.Schema\" ||\n currentClass.extends === \"Schema.Schema\"\n );\n\n //\n // When extending from `schema.Schema`, it is required to\n // normalize as \"Schema\" for code generation.\n //\n if (currentClass === klass && isSchema) {\n klass.extends = \"Schema\";\n }\n\n currentClass = this.getParentClass(currentClass);\n }\n\n return isSchema;\n }\n}\n\nexport interface IStructure {\n context: Context;\n name: string;\n properties: Property[];\n addProperty(property: Property);\n}\n\nexport class Interface implements IStructure {\n context: Context;\n name: string;\n properties: Property[] = [];\n\n addProperty(property: Property) {\n if (property.type.indexOf(\"[]\") >= 0) {\n // is array!\n property.childType = property.type.match(/([^\\[]+)/i)[1];\n property.type = \"array\";\n this.properties.push(property);\n\n } else {\n this.properties.push(property);\n }\n }\n}\n\nexport class Class implements IStructure {\n context: Context;\n name: string;\n properties: Property[] = [];\n extends: string;\n\n addProperty(property: Property) {\n property.index = this.properties.length;\n this.properties.push(property);\n }\n\n postProcessing() {\n /**\n * Ensure the proprierties `index` are correct using inheritance\n */\n let parentKlass: Class = this;\n\n while (\n parentKlass &&\n (parentKlass = this.context.classes.find(k => k.name === parentKlass.extends))\n ) {\n this.properties.forEach(prop => {\n prop.index += parentKlass.properties.length;\n });\n }\n }\n}\n\nexport class Property {\n index: number;\n name: string;\n type: string;\n childType: string;\n deprecated?: boolean;\n}\n\nexport interface File {\n name: string\n content: string;\n}\n\nexport function getInheritanceTree(klass: Class, allClasses: Class[], includeSelf: boolean = true) {\n let currentClass = klass;\n let inheritanceTree: Class[] = [];\n\n if (includeSelf) {\n inheritanceTree.push(currentClass);\n }\n\n while (currentClass.extends !== \"Schema\") {\n currentClass = allClasses.find(klass => klass.name == currentClass.extends);\n inheritanceTree.push(currentClass);\n }\n\n return inheritanceTree;\n}\n"]}
|