@colyseus/schema 3.0.0-alpha.8 → 3.0.0

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.
Files changed (150) hide show
  1. package/README.md +148 -62
  2. package/bin/schema-debug +94 -0
  3. package/build/cjs/index.js +2227 -1519
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.mjs +2228 -1522
  6. package/build/esm/index.mjs.map +1 -1
  7. package/build/umd/index.js +2230 -1522
  8. package/lib/Metadata.d.ts +21 -9
  9. package/lib/Metadata.js +169 -32
  10. package/lib/Metadata.js.map +1 -1
  11. package/lib/Reflection.d.ts +19 -4
  12. package/lib/Reflection.js +66 -31
  13. package/lib/Reflection.js.map +1 -1
  14. package/lib/Schema.d.ts +12 -5
  15. package/lib/Schema.js +57 -56
  16. package/lib/Schema.js.map +1 -1
  17. package/lib/annotations.d.ts +31 -34
  18. package/lib/annotations.js +110 -160
  19. package/lib/annotations.js.map +1 -1
  20. package/lib/bench_encode.d.ts +1 -0
  21. package/lib/bench_encode.js +130 -0
  22. package/lib/bench_encode.js.map +1 -0
  23. package/lib/codegen/api.js +1 -2
  24. package/lib/codegen/api.js.map +1 -1
  25. package/lib/codegen/languages/cpp.js +1 -2
  26. package/lib/codegen/languages/cpp.js.map +1 -1
  27. package/lib/codegen/languages/csharp.js +9 -46
  28. package/lib/codegen/languages/csharp.js.map +1 -1
  29. package/lib/codegen/languages/haxe.js +4 -2
  30. package/lib/codegen/languages/haxe.js.map +1 -1
  31. package/lib/codegen/languages/java.js +1 -2
  32. package/lib/codegen/languages/java.js.map +1 -1
  33. package/lib/codegen/languages/js.js +1 -2
  34. package/lib/codegen/languages/js.js.map +1 -1
  35. package/lib/codegen/languages/lua.js +23 -25
  36. package/lib/codegen/languages/lua.js.map +1 -1
  37. package/lib/codegen/languages/ts.js +1 -2
  38. package/lib/codegen/languages/ts.js.map +1 -1
  39. package/lib/codegen/parser.js +85 -3
  40. package/lib/codegen/parser.js.map +1 -1
  41. package/lib/codegen/types.js +6 -3
  42. package/lib/codegen/types.js.map +1 -1
  43. package/lib/debug.d.ts +1 -0
  44. package/lib/debug.js +51 -0
  45. package/lib/debug.js.map +1 -0
  46. package/lib/decoder/DecodeOperation.d.ts +3 -4
  47. package/lib/decoder/DecodeOperation.js +35 -17
  48. package/lib/decoder/DecodeOperation.js.map +1 -1
  49. package/lib/decoder/Decoder.d.ts +5 -6
  50. package/lib/decoder/Decoder.js +10 -10
  51. package/lib/decoder/Decoder.js.map +1 -1
  52. package/lib/decoder/ReferenceTracker.js +4 -2
  53. package/lib/decoder/ReferenceTracker.js.map +1 -1
  54. package/lib/decoder/strategy/RawChanges.js +1 -2
  55. package/lib/decoder/strategy/RawChanges.js.map +1 -1
  56. package/lib/decoder/strategy/StateCallbacks.d.ts +44 -11
  57. package/lib/decoder/strategy/StateCallbacks.js +74 -64
  58. package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
  59. package/lib/encoder/ChangeTree.d.ts +28 -20
  60. package/lib/encoder/ChangeTree.js +242 -188
  61. package/lib/encoder/ChangeTree.js.map +1 -1
  62. package/lib/encoder/EncodeOperation.d.ts +3 -6
  63. package/lib/encoder/EncodeOperation.js +51 -65
  64. package/lib/encoder/EncodeOperation.js.map +1 -1
  65. package/lib/encoder/Encoder.d.ts +8 -7
  66. package/lib/encoder/Encoder.js +133 -85
  67. package/lib/encoder/Encoder.js.map +1 -1
  68. package/lib/encoder/Root.d.ts +22 -0
  69. package/lib/encoder/Root.js +81 -0
  70. package/lib/encoder/Root.js.map +1 -0
  71. package/lib/encoder/StateView.d.ts +7 -7
  72. package/lib/encoder/StateView.js +72 -74
  73. package/lib/encoder/StateView.js.map +1 -1
  74. package/lib/encoding/assert.d.ts +7 -6
  75. package/lib/encoding/assert.js +13 -5
  76. package/lib/encoding/assert.js.map +1 -1
  77. package/lib/encoding/decode.d.ts +36 -19
  78. package/lib/encoding/decode.js +54 -84
  79. package/lib/encoding/decode.js.map +1 -1
  80. package/lib/encoding/encode.d.ts +36 -18
  81. package/lib/encoding/encode.js +61 -48
  82. package/lib/encoding/encode.js.map +1 -1
  83. package/lib/encoding/spec.d.ts +4 -5
  84. package/lib/encoding/spec.js +1 -2
  85. package/lib/encoding/spec.js.map +1 -1
  86. package/lib/index.d.ts +10 -9
  87. package/lib/index.js +24 -17
  88. package/lib/index.js.map +1 -1
  89. package/lib/types/HelperTypes.d.ts +34 -2
  90. package/lib/types/HelperTypes.js.map +1 -1
  91. package/lib/types/TypeContext.d.ts +29 -0
  92. package/lib/types/TypeContext.js +151 -0
  93. package/lib/types/TypeContext.js.map +1 -0
  94. package/lib/types/custom/ArraySchema.d.ts +2 -2
  95. package/lib/types/custom/ArraySchema.js +33 -22
  96. package/lib/types/custom/ArraySchema.js.map +1 -1
  97. package/lib/types/custom/CollectionSchema.d.ts +2 -2
  98. package/lib/types/custom/CollectionSchema.js +1 -0
  99. package/lib/types/custom/CollectionSchema.js.map +1 -1
  100. package/lib/types/custom/MapSchema.d.ts +18 -16
  101. package/lib/types/custom/MapSchema.js +12 -4
  102. package/lib/types/custom/MapSchema.js.map +1 -1
  103. package/lib/types/custom/SetSchema.d.ts +2 -2
  104. package/lib/types/custom/SetSchema.js +1 -0
  105. package/lib/types/custom/SetSchema.js.map +1 -1
  106. package/lib/types/registry.d.ts +8 -1
  107. package/lib/types/registry.js +23 -6
  108. package/lib/types/registry.js.map +1 -1
  109. package/lib/types/symbols.d.ts +8 -5
  110. package/lib/types/symbols.js +9 -6
  111. package/lib/types/symbols.js.map +1 -1
  112. package/lib/types/utils.js +1 -2
  113. package/lib/types/utils.js.map +1 -1
  114. package/lib/utils.js +9 -7
  115. package/lib/utils.js.map +1 -1
  116. package/package.json +19 -18
  117. package/src/Metadata.ts +190 -42
  118. package/src/Reflection.ts +76 -38
  119. package/src/Schema.ts +72 -70
  120. package/src/annotations.ts +156 -202
  121. package/src/bench_encode.ts +108 -0
  122. package/src/codegen/languages/csharp.ts +8 -47
  123. package/src/codegen/languages/haxe.ts +4 -0
  124. package/src/codegen/languages/lua.ts +19 -27
  125. package/src/codegen/parser.ts +107 -0
  126. package/src/codegen/types.ts +1 -0
  127. package/src/debug.ts +55 -0
  128. package/src/decoder/DecodeOperation.ts +43 -15
  129. package/src/decoder/Decoder.ts +12 -10
  130. package/src/decoder/ReferenceTracker.ts +5 -3
  131. package/src/decoder/strategy/StateCallbacks.ts +152 -81
  132. package/src/encoder/ChangeTree.ts +282 -209
  133. package/src/encoder/EncodeOperation.ts +78 -78
  134. package/src/encoder/Encoder.ts +157 -93
  135. package/src/encoder/Root.ts +93 -0
  136. package/src/encoder/StateView.ts +80 -88
  137. package/src/encoding/assert.ts +17 -8
  138. package/src/encoding/decode.ts +73 -93
  139. package/src/encoding/encode.ts +76 -45
  140. package/src/encoding/spec.ts +3 -5
  141. package/src/index.ts +12 -20
  142. package/src/types/HelperTypes.ts +54 -2
  143. package/src/types/TypeContext.ts +175 -0
  144. package/src/types/custom/ArraySchema.ts +49 -19
  145. package/src/types/custom/CollectionSchema.ts +1 -0
  146. package/src/types/custom/MapSchema.ts +30 -17
  147. package/src/types/custom/SetSchema.ts +1 -0
  148. package/src/types/registry.ts +22 -3
  149. package/src/types/symbols.ts +10 -7
  150. package/src/utils.ts +7 -3
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = void 0;
3
+ exports.generate = generate;
4
4
  const types_1 = require("../types");
5
5
  /**
6
6
  TODO:
@@ -29,7 +29,6 @@ function generate(context, options) {
29
29
  content: generateClass(klass, options.namespace, context.classes)
30
30
  }));
31
31
  }
32
- exports.generate = generate;
33
32
  function generateClass(klass, namespace, allClasses) {
34
33
  const allRefs = [];
35
34
  klass.properties.forEach(property => {
@@ -39,10 +38,13 @@ function generateClass(klass, namespace, allClasses) {
39
38
  allRefs.push(property);
40
39
  }
41
40
  });
42
- // TOOD: inheritance
41
+ // Inheritance support
42
+ const inherits = (klass.extends !== "Schema")
43
+ ? `, ${klass.extends}`
44
+ : "";
43
45
  return `${(0, types_1.getCommentHeader)().replace(/\/\//mg, "--")}
44
46
 
45
- local schema = require 'colyseus.serialization.schema.schema'
47
+ local schema = require 'colyseus.serializer.schema.schema'
46
48
  ${allRefs.
47
49
  filter(ref => ref.childType && typeMaps[ref.childType] === undefined).
48
50
  map(ref => ref.childType).
@@ -51,22 +53,15 @@ ${allRefs.
51
53
  map(childType => `local ${childType} = require '${(namespace ? `${namespace}.` : '')}${childType}'`).
52
54
  join("\n")}
53
55
 
56
+ ---@class ${klass.name}: ${klass.extends}
57
+ ${klass.properties.map(prop => `---@field ${prop.name} ${getLUATypeAnnotation(prop)}`).join("\n")}
54
58
  local ${klass.name} = schema.define({
55
59
  ${klass.properties.map(prop => generatePropertyDeclaration(prop)).join(",\n")},
56
60
  ["_fields_by_index"] = { ${klass.properties.map(prop => `"${prop.name}"`).join(", ")} },
57
- })
61
+ }${inherits})
58
62
 
59
63
  return ${klass.name}
60
64
  `;
61
- // ["on_change"] = function(changes)
62
- // -- on change logic here
63
- // end,
64
- // ["on_add"] = function()
65
- // -- on add logic here
66
- // end,
67
- // ["on_remove"] = function()
68
- // -- on remove logic here
69
- // end,
70
65
  }
71
66
  function generatePropertyDeclaration(prop) {
72
67
  let typeArgs;
@@ -94,15 +89,18 @@ function generatePropertyDeclaration(prop) {
94
89
  }
95
90
  return ` ["${prop.name}"] = ${typeArgs}`;
96
91
  }
97
- // function generatePropertyInitializer(prop: Property) {
98
- // let initializer = "";
99
- // if(prop.type === "ref") {
100
- // initializer = `new ${prop.childType}()`;
101
- // } else if(prop.type === "array") {
102
- // initializer = `new schema.ArraySchema()`;
103
- // } else if(prop.type === "map") {
104
- // initializer = `new schema.MapSchema()`;
105
- // }
106
- // return `this.${prop.name} = ${initializer}`;
107
- // }
92
+ function getLUATypeAnnotation(prop) {
93
+ if (prop.type === "ref") {
94
+ return prop.childType;
95
+ }
96
+ else if (prop.type === "array") {
97
+ return "ArraySchema";
98
+ }
99
+ else if (prop.type === "map") {
100
+ return "MapSchema";
101
+ }
102
+ else {
103
+ return typeMaps[prop.type];
104
+ }
105
+ }
108
106
  //# sourceMappingURL=lua.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lua.js","sourceRoot":"","sources":["../../../src/codegen/languages/lua.ts"],"names":[],"mappings":";;;AAAA,oCAAgG;AAGhG;;;;EAIE;AAEF,MAAM,QAAQ,GAAG;IACb,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;CACtB,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AAEvE,SAAgB,QAAQ,CAAE,OAAgB,EAAE,OAAwB;IAChE,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,MAAM;QACzB,OAAO,EAAE,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC;KACpE,CAAC,CAAC,CAAC;AACR,CAAC;AALD,4BAKC;AAED,SAAS,aAAa,CAAC,KAAY,EAAE,SAAiB,EAAE,UAAmB;IACvE,MAAM,OAAO,GAAe,EAAE,CAAC;IAC/B,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAChC,IAAI,IAAI,GA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D,IAAI","sourcesContent":["import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from \"../types\";\nimport { GenerateOptions } from \"../api\";\n\n/**\n TODO:\n - Support inheritance\n - Support importing Schema dependencies\n*/\n\nconst typeMaps = {\n \"string\": \"string\",\n \"number\": \"number\",\n \"boolean\": \"boolean\",\n \"int8\": \"number\",\n \"uint8\": \"number\",\n \"int16\": \"number\",\n \"uint16\": \"number\",\n \"int32\": \"number\",\n \"uint32\": \"number\",\n \"int64\": \"number\",\n \"uint64\": \"number\",\n \"float32\": \"number\",\n \"float64\": \"number\",\n}\n\nconst distinct = (value, index, self) => self.indexOf(value) === index;\n\nexport function generate (context: Context, options: GenerateOptions): File[] {\n return context.classes.map(klass => ({\n name: klass.name + \".lua\",\n content: generateClass(klass, options.namespace, context.classes)\n }));\n}\n\nfunction generateClass(klass: Class, namespace: string, allClasses: Class[]) {\n const allRefs: Property[] = [];\n klass.properties.forEach(property => {\n let type = property.type;\n\n // keep all refs list\n if ((type === \"ref\" || type === \"array\" || type === \"map\")) {\n allRefs.push(property);\n }\n });\n\n// TOOD: inheritance\n\n return `${getCommentHeader().replace(/\\/\\//mg, \"--\")}\n\nlocal schema = require 'colyseus.serialization.schema.schema'\n${allRefs.\n filter(ref => ref.childType && typeMaps[ref.childType] === undefined).\n map(ref => ref.childType).\n concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).\n filter(distinct).\n map(childType => `local ${childType} = require '${(namespace ? `${namespace}.` : '')}${childType}'`).\n join(\"\\n\")}\n\nlocal ${klass.name} = schema.define({\n${klass.properties.map(prop => generatePropertyDeclaration(prop)).join(\",\\n\")},\n [\"_fields_by_index\"] = { ${klass.properties.map(prop => `\"${prop.name}\"`).join(\", \")} },\n})\n\nreturn ${klass.name}\n`;\n\n // [\"on_change\"] = function(changes)\n // -- on change logic here\n // end,\n\n // [\"on_add\"] = function()\n // -- on add logic here\n // end,\n\n // [\"on_remove\"] = function()\n // -- on remove logic here\n // end,\n}\n\nfunction generatePropertyDeclaration(prop: Property) {\n let typeArgs: string;\n\n if (prop.childType) {\n const isUpcaseFirst = prop.childType.match(/^[A-Z]/);\n\n if (isUpcaseFirst) {\n typeArgs += `${prop.childType}`;\n\n } else {\n typeArgs += `\"${prop.childType}\"`;\n }\n\n if(prop.type === \"ref\") {\n typeArgs = (isUpcaseFirst)\n ? `${prop.childType}`\n : `\"${prop.childType}\"`;\n\n } else {\n typeArgs = (isUpcaseFirst)\n ? `{ ${prop.type} = ${prop.childType} }`\n : `{ ${prop.type} = \"${prop.childType}\" }`;\n }\n\n } else {\n typeArgs = `\"${prop.type}\"`;\n }\n\n return ` [\"${prop.name}\"] = ${typeArgs}`;\n}\n\n// function generatePropertyInitializer(prop: Property) {\n// let initializer = \"\";\n\n// if(prop.type === \"ref\") {\n// initializer = `new ${prop.childType}()`;\n\n// } else if(prop.type === \"array\") {\n// initializer = `new schema.ArraySchema()`;\n\n// } else if(prop.type === \"map\") {\n// initializer = `new schema.MapSchema()`;\n// }\n\n// return `this.${prop.name} = ${initializer}`;\n// }\n"]}
1
+ {"version":3,"file":"lua.js","sourceRoot":"","sources":["../../../src/codegen/languages/lua.ts"],"names":[],"mappings":";;AA2BA,4BAKC;AAhCD,oCAAgG;AAGhG;;;;EAIE;AAEF,MAAM,QAAQ,GAAG;IACb,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;CACtB,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAA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AAS,GAAG,CAAC;QACtC,CAAC;QAED,IAAG,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACrB,QAAQ,GAAG,CAAC,aAAa,CAAC;gBACtB,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,EAAE;gBACrB,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC;QAEhC,CAAC;aAAM,CAAC;YACJ,QAAQ,GAAG,CAAC,aAAa,CAAC;gBACtB,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,SAAS,IAAI;gBACxC,CAAC,CAAC,KAAK,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,SAAS,KAAK,CAAC;QACnD,CAAC;IAEL,CAAC;SAAM,CAAC;QACJ,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,IAAI,CAAC,IAAI,QAAQ,QAAQ,EAAE,CAAC;AAChD,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAc;IACxC,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC,SAAS,CAAC;IAE1B,CAAC;SAAM,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC/B,OAAO,aAAa,CAAC;IAEzB,CAAC;SAAM,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;QAC7B,OAAO,WAAW,CAAC;IAEvB,CAAC;SAAM,CAAC;QACJ,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;AACL,CAAC","sourcesContent":["import { Class, Property, File, getCommentHeader, getInheritanceTree, Context } from \"../types\";\nimport { GenerateOptions } from \"../api\";\n\n/**\n TODO:\n - Support inheritance\n - Support importing Schema dependencies\n*/\n\nconst typeMaps = {\n \"string\": \"string\",\n \"number\": \"number\",\n \"boolean\": \"boolean\",\n \"int8\": \"number\",\n \"uint8\": \"number\",\n \"int16\": \"number\",\n \"uint16\": \"number\",\n \"int32\": \"number\",\n \"uint32\": \"number\",\n \"int64\": \"number\",\n \"uint64\": \"number\",\n \"float32\": \"number\",\n \"float64\": \"number\",\n}\n\nconst distinct = (value, index, self) => self.indexOf(value) === index;\n\nexport function generate (context: Context, options: GenerateOptions): File[] {\n return context.classes.map(klass => ({\n name: klass.name + \".lua\",\n content: generateClass(klass, options.namespace, context.classes)\n }));\n}\n\nfunction generateClass(klass: Class, namespace: string, allClasses: Class[]) {\n const allRefs: Property[] = [];\n klass.properties.forEach(property => {\n let type = property.type;\n\n // keep all refs list\n if ((type === \"ref\" || type === \"array\" || type === \"map\")) {\n allRefs.push(property);\n }\n });\n\n // Inheritance support\n const inherits = (klass.extends !== \"Schema\")\n ? `, ${klass.extends}`\n : \"\";\n\n return `${getCommentHeader().replace(/\\/\\//mg, \"--\")}\n\nlocal schema = require 'colyseus.serializer.schema.schema'\n${allRefs.\n filter(ref => ref.childType && typeMaps[ref.childType] === undefined).\n map(ref => ref.childType).\n concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).\n filter(distinct).\n map(childType => `local ${childType} = require '${(namespace ? `${namespace}.` : '')}${childType}'`).\n join(\"\\n\")}\n\n---@class ${klass.name}: ${klass.extends}\n${klass.properties.map(prop => `---@field ${prop.name} ${getLUATypeAnnotation(prop)}`).join(\"\\n\")}\nlocal ${klass.name} = schema.define({\n${klass.properties.map(prop => generatePropertyDeclaration(prop)).join(\",\\n\")},\n [\"_fields_by_index\"] = { ${klass.properties.map(prop => `\"${prop.name}\"`).join(\", \")} },\n}${inherits})\n\nreturn ${klass.name}\n`;\n}\n\nfunction generatePropertyDeclaration(prop: Property) {\n let typeArgs: string;\n\n if (prop.childType) {\n const isUpcaseFirst = prop.childType.match(/^[A-Z]/);\n\n if (isUpcaseFirst) {\n typeArgs += `${prop.childType}`;\n\n } else {\n typeArgs += `\"${prop.childType}\"`;\n }\n\n if(prop.type === \"ref\") {\n typeArgs = (isUpcaseFirst)\n ? `${prop.childType}`\n : `\"${prop.childType}\"`;\n\n } else {\n typeArgs = (isUpcaseFirst)\n ? `{ ${prop.type} = ${prop.childType} }`\n : `{ ${prop.type} = \"${prop.childType}\" }`;\n }\n\n } else {\n typeArgs = `\"${prop.type}\"`;\n }\n\n return ` [\"${prop.name}\"] = ${typeArgs}`;\n}\n\nfunction getLUATypeAnnotation(prop: Property) {\n if (prop.type === \"ref\") {\n return prop.childType;\n\n } else if (prop.type === \"array\") {\n return \"ArraySchema\";\n\n } else if (prop.type === \"map\") {\n return \"MapSchema\";\n\n } else {\n return typeMaps[prop.type];\n }\n}"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = void 0;
3
+ exports.generate = generate;
4
4
  const types_1 = require("../types");
5
5
  const typeMaps = {
6
6
  "string": "string",
@@ -30,7 +30,6 @@ function generate(context, options) {
30
30
  }))
31
31
  ];
32
32
  }
33
- exports.generate = generate;
34
33
  function generateClass(klass, namespace, allClasses) {
35
34
  const allRefs = [];
36
35
  klass.properties.forEach(property => {
@@ -1 +1 @@
1
- {"version":3,"file":"ts.js","sourceRoot":"","sources":["../../../src/codegen/languages/ts.ts"],"names":[],"mappings":";;;AAAA,oCAA2G;AAG3G,MAAM,QAAQ,GAAG;IACb,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;CACtB,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,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AAS,KAAK,CAAC;QACzC,CAAC;IAEL,CAAC;SAAM,CAAC;QACJ,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,QAAQ,GAAG,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC;IAChC,CAAC;IAED,2FAA2F;IAC3F,MAAM,iBAAiB,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAEjD,OAAO,SAAS,QAAQ,YAAY,IAAI,CAAC,IAAI,GAAG,iBAAiB,KAAK,QAAQ,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAA;AAChI,CAAC;AAGD,SAAS,iBAAiB,CAAC,SAAoB,EAAE,SAAiB,EAAE,UAAmB;IACnF,OAAO,GAAG,IAAA,wBAAgB,GAAE;;mBAEb,SAAS,CAAC,IAAI;EAC/B,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;CAE/E,CAAC;AACF,CAAC","sourcesContent":["import { Class, Property, File, getCommentHeader, getInheritanceTree, Context, Interface } from \"../types\";\nimport { GenerateOptions } from \"../api\";\n\nconst typeMaps = {\n \"string\": \"string\",\n \"number\": \"number\",\n \"boolean\": \"boolean\",\n \"int8\": \"number\",\n \"uint8\": \"number\",\n \"int16\": \"number\",\n \"uint16\": \"number\",\n \"int32\": \"number\",\n \"uint32\": \"number\",\n \"int64\": \"number\",\n \"uint64\": \"number\",\n \"float32\": \"number\",\n \"float64\": \"number\",\n}\n\nconst distinct = (value, index, self) => self.indexOf(value) === index;\n\nexport function generate (context: Context, options: GenerateOptions): File[] {\n return [\n ...context.classes.map(structure => ({\n name: structure.name + \".ts\",\n content: generateClass(structure, options.namespace, context.classes)\n })),\n ...context.interfaces.map(structure => ({\n name: structure.name + \".ts\",\n content: generateInterface(structure, options.namespace, context.classes),\n }))\n ];\n}\n\nfunction generateClass(klass: Class, namespace: string, allClasses: Class[]) {\n const allRefs: Property[] = [];\n klass.properties.forEach(property => {\n let type = property.type;\n\n // keep all refs list\n if ((type === \"ref\" || type === \"array\" || type === \"map\" || type === \"set\")) {\n allRefs.push(property);\n }\n });\n\n return `${getCommentHeader()}\n\nimport { Schema, type, ArraySchema, MapSchema, SetSchema, DataChange } from '@colyseus/schema';\n${allRefs.\n filter(ref => ref.childType && typeMaps[ref.childType] === undefined).\n map(ref => ref.childType).\n concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).\n filter(distinct).\n map(childType => `import { ${childType} } from './${childType}'`).\n join(\"\\n\")}\n\nexport class ${klass.name} extends ${klass.extends} {\n${klass.properties.map(prop => ` ${generateProperty(prop)}`).join(\"\\n\")}\n}\n`;\n}\n\nfunction generateProperty(prop: Property) {\n let langType: string;\n let initializer = \"\";\n let typeArgs: string;\n\n if (prop.childType) {\n const isUpcaseFirst = prop.childType.match(/^[A-Z]/);\n\n if (isUpcaseFirst) {\n typeArgs += `, ${prop.childType}`;\n\n } else {\n typeArgs += `, \"${prop.childType}\"`;\n }\n\n if(prop.type === \"ref\") {\n langType = `${prop.childType}`;\n initializer = `new ${prop.childType}()`;\n typeArgs = `${prop.childType}`;\n\n } else if(prop.type === \"array\") {\n langType = (isUpcaseFirst)\n ? `ArraySchema<${prop.childType}>`\n : `ArraySchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `[ ${prop.childType} ]`\n : `[ \"${prop.childType}\" ]`;\n\n } else if(prop.type === \"map\") {\n langType = (isUpcaseFirst)\n ? `MapSchema<${prop.childType}>`\n : `MapSchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `{ map: ${prop.childType} }`\n : `{ map: \"${prop.childType}\" }`;\n } else if (prop.type === \"set\") {\n langType = (isUpcaseFirst)\n ? `SetSchema<${prop.childType}>`\n : `SetSchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `{ set: ${prop.childType} }`\n : `{ set: \"${prop.childType}\" }`;\n }\n\n } else {\n langType = typeMaps[prop.type];\n typeArgs = `\"${prop.type}\"`;\n }\n\n // TS1263: \"Declarations with initializers cannot also have definite assignment assertions\"\n const definiteAssertion = initializer ? \"\" : \"!\";\n\n return `@type(${typeArgs}) public ${prop.name}${definiteAssertion}: ${langType}${(initializer) ? ` = ${initializer}` : \"\"};`\n}\n\n\nfunction generateInterface(structure: Interface, namespace: string, allClasses: Class[]) {\n return `${getCommentHeader()}\n\nexport interface ${structure.name} {\n${structure.properties.map(prop => ` ${prop.name}: ${prop.type};`).join(\"\\n\")}\n}\n`;\n}\n"]}
1
+ {"version":3,"file":"ts.js","sourceRoot":"","sources":["../../../src/codegen/languages/ts.ts"],"names":[],"mappings":";;AAqBA,4BAWC;AAhCD,oCAA2G;AAG3G,MAAM,QAAQ,GAAG;IACb,QAAQ,EAAE,QAAQ;IAClB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,SAAS;IACpB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,QAAQ;IACjB,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,QAAQ;CACtB,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;AAEvE,SAAgB,QAAQ,CAAE,OAAgB,EAAE,OAAwB;IAChE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AC,IAAI,GAAG,CAAC;IAChC,CAAC;IAED,2FAA2F;IAC3F,MAAM,iBAAiB,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAEjD,OAAO,SAAS,QAAQ,YAAY,IAAI,CAAC,IAAI,GAAG,iBAAiB,KAAK,QAAQ,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAA;AAChI,CAAC;AAGD,SAAS,iBAAiB,CAAC,SAAoB,EAAE,SAAiB,EAAE,UAAmB;IACnF,OAAO,GAAG,IAAA,wBAAgB,GAAE;;mBAEb,SAAS,CAAC,IAAI;EAC/B,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;CAE/E,CAAC;AACF,CAAC","sourcesContent":["import { Class, Property, File, getCommentHeader, getInheritanceTree, Context, Interface } from \"../types\";\nimport { GenerateOptions } from \"../api\";\n\nconst typeMaps = {\n \"string\": \"string\",\n \"number\": \"number\",\n \"boolean\": \"boolean\",\n \"int8\": \"number\",\n \"uint8\": \"number\",\n \"int16\": \"number\",\n \"uint16\": \"number\",\n \"int32\": \"number\",\n \"uint32\": \"number\",\n \"int64\": \"number\",\n \"uint64\": \"number\",\n \"float32\": \"number\",\n \"float64\": \"number\",\n}\n\nconst distinct = (value, index, self) => self.indexOf(value) === index;\n\nexport function generate (context: Context, options: GenerateOptions): File[] {\n return [\n ...context.classes.map(structure => ({\n name: structure.name + \".ts\",\n content: generateClass(structure, options.namespace, context.classes)\n })),\n ...context.interfaces.map(structure => ({\n name: structure.name + \".ts\",\n content: generateInterface(structure, options.namespace, context.classes),\n }))\n ];\n}\n\nfunction generateClass(klass: Class, namespace: string, allClasses: Class[]) {\n const allRefs: Property[] = [];\n klass.properties.forEach(property => {\n let type = property.type;\n\n // keep all refs list\n if ((type === \"ref\" || type === \"array\" || type === \"map\" || type === \"set\")) {\n allRefs.push(property);\n }\n });\n\n return `${getCommentHeader()}\n\nimport { Schema, type, ArraySchema, MapSchema, SetSchema, DataChange } from '@colyseus/schema';\n${allRefs.\n filter(ref => ref.childType && typeMaps[ref.childType] === undefined).\n map(ref => ref.childType).\n concat(getInheritanceTree(klass, allClasses, false).map(klass => klass.name)).\n filter(distinct).\n map(childType => `import { ${childType} } from './${childType}'`).\n join(\"\\n\")}\n\nexport class ${klass.name} extends ${klass.extends} {\n${klass.properties.map(prop => ` ${generateProperty(prop)}`).join(\"\\n\")}\n}\n`;\n}\n\nfunction generateProperty(prop: Property) {\n let langType: string;\n let initializer = \"\";\n let typeArgs: string;\n\n if (prop.childType) {\n const isUpcaseFirst = prop.childType.match(/^[A-Z]/);\n\n if (isUpcaseFirst) {\n typeArgs += `, ${prop.childType}`;\n\n } else {\n typeArgs += `, \"${prop.childType}\"`;\n }\n\n if(prop.type === \"ref\") {\n langType = `${prop.childType}`;\n initializer = `new ${prop.childType}()`;\n typeArgs = `${prop.childType}`;\n\n } else if(prop.type === \"array\") {\n langType = (isUpcaseFirst)\n ? `ArraySchema<${prop.childType}>`\n : `ArraySchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `[ ${prop.childType} ]`\n : `[ \"${prop.childType}\" ]`;\n\n } else if(prop.type === \"map\") {\n langType = (isUpcaseFirst)\n ? `MapSchema<${prop.childType}>`\n : `MapSchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `{ map: ${prop.childType} }`\n : `{ map: \"${prop.childType}\" }`;\n } else if (prop.type === \"set\") {\n langType = (isUpcaseFirst)\n ? `SetSchema<${prop.childType}>`\n : `SetSchema<${typeMaps[prop.childType]}>`;\n initializer = `new ${langType}()`;\n typeArgs = (isUpcaseFirst)\n ? `{ set: ${prop.childType} }`\n : `{ set: \"${prop.childType}\" }`;\n }\n\n } else {\n langType = typeMaps[prop.type];\n typeArgs = `\"${prop.type}\"`;\n }\n\n // TS1263: \"Declarations with initializers cannot also have definite assignment assertions\"\n const definiteAssertion = initializer ? \"\" : \"!\";\n\n return `@type(${typeArgs}) public ${prop.name}${definiteAssertion}: ${langType}${(initializer) ? ` = ${initializer}` : \"\"};`\n}\n\n\nfunction generateInterface(structure: Interface, namespace: string, allClasses: Class[]) {\n return `${getCommentHeader()}\n\nexport interface ${structure.name} {\n${structure.properties.map(prop => ` ${prop.name}: ${prop.type};`).join(\"\\n\")}\n}\n`;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getDecorators = exports.parseFiles = void 0;
3
+ exports.parseFiles = parseFiles;
4
+ exports.getDecorators = getDecorators;
4
5
  const ts = require("typescript");
5
6
  const path = require("path");
6
7
  const fs_1 = require("fs");
@@ -122,6 +123,41 @@ function inspectNode(node, context, decoratorName) {
122
123
  defineProperty(property, typeArgument);
123
124
  }
124
125
  }
126
+ else if (node.getText() === "setFields" &&
127
+ (node.parent.kind === ts.SyntaxKind.CallExpression ||
128
+ node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)) {
129
+ /**
130
+ * Metadata.setFields(klassName, { ... })
131
+ */
132
+ const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)
133
+ ? node.parent.parent
134
+ : node.parent;
135
+ if (callExpression.kind !== ts.SyntaxKind.CallExpression) {
136
+ break;
137
+ }
138
+ const classNameNode = callExpression.arguments[0];
139
+ const className = ts.isClassExpression(classNameNode)
140
+ ? classNameNode.name?.escapedText.toString()
141
+ : classNameNode.getText();
142
+ // skip if no className is provided
143
+ if (!className) {
144
+ break;
145
+ }
146
+ if (currentStructure.name !== className) {
147
+ currentStructure = new types_1.Class();
148
+ }
149
+ context.addStructure(currentStructure);
150
+ currentStructure.extends = "Schema"; // force extends to Schema
151
+ currentStructure.name = className;
152
+ const types = callExpression.arguments[1];
153
+ for (let i = 0; i < types.properties.length; i++) {
154
+ const prop = types.properties[i];
155
+ const property = currentProperty || new types_1.Property();
156
+ property.name = prop.name.escapedText;
157
+ currentStructure.addProperty(property);
158
+ defineProperty(property, prop.initializer);
159
+ }
160
+ }
125
161
  else if (node.getText() === "defineTypes" &&
126
162
  (node.parent.kind === ts.SyntaxKind.CallExpression ||
127
163
  node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)) {
@@ -151,6 +187,54 @@ function inspectNode(node, context, decoratorName) {
151
187
  }
152
188
  currentProperty = undefined;
153
189
  break;
190
+ case ts.SyntaxKind.CallExpression:
191
+ /**
192
+ * Defining schema via `schema.schema({ ... })`
193
+ * - schema.schema({})
194
+ * - schema({})
195
+ * - ClassName.extends({})
196
+ */
197
+ if (((node.expression?.getText() === "schema.schema" ||
198
+ node.expression?.getText() === "schema") ||
199
+ (node.expression?.getText().indexOf(".extends") !== -1)) &&
200
+ node.arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression) {
201
+ const callExpression = node;
202
+ let className = callExpression.arguments[1]?.getText();
203
+ if (!className && callExpression.parent.kind === ts.SyntaxKind.VariableDeclaration) {
204
+ className = callExpression.parent.name?.getText();
205
+ }
206
+ // skip if no className is provided
207
+ if (!className) {
208
+ break;
209
+ }
210
+ if (currentStructure.name !== className) {
211
+ currentStructure = new types_1.Class();
212
+ context.addStructure(currentStructure);
213
+ }
214
+ if (node.expression?.getText().indexOf(".extends") !== -1) {
215
+ // if it's using `.extends({})`
216
+ const extendsClass = node.expression?.expression?.escapedText;
217
+ // skip if no extendsClass is provided
218
+ if (!extendsClass) {
219
+ break;
220
+ }
221
+ currentStructure.extends = extendsClass;
222
+ }
223
+ else {
224
+ // if it's using `schema({})`
225
+ currentStructure.extends = "Schema"; // force extends to Schema
226
+ }
227
+ currentStructure.name = className;
228
+ const types = callExpression.arguments[0];
229
+ for (let i = 0; i < types.properties.length; i++) {
230
+ const prop = types.properties[i];
231
+ const property = currentProperty || new types_1.Property();
232
+ property.name = prop.name.escapedText;
233
+ currentStructure.addProperty(property);
234
+ defineProperty(property, prop.initializer);
235
+ }
236
+ }
237
+ break;
154
238
  case ts.SyntaxKind.EnumMember:
155
239
  if (currentStructure instanceof types_1.Enum) {
156
240
  const initializer = node.initializer?.text;
@@ -209,7 +293,6 @@ function parseFiles(fileNames, decoratorName = "type", context = new types_1.Con
209
293
  });
210
294
  return context.getStructures();
211
295
  }
212
- exports.parseFiles = parseFiles;
213
296
  /**
214
297
  * TypeScript 4.8+ has introduced a change on how to access decorators.
215
298
  * - https://github.com/microsoft/TypeScript/pull/49089
@@ -234,5 +317,4 @@ function getDecorators(node) {
234
317
  // @ts-ignore
235
318
  return node.modifiers?.filter(ts.isDecorator);
236
319
  }
237
- exports.getDecorators = getDecorators;
238
320
  //# sourceMappingURL=parser.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/codegen/parser.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,6BAA6B;AAC7B,2BAAgC;AAChC,mCAA8E;AAE9E,IAAI,gBAA4B,CAAC;AACjC,IAAI,eAAyB,CAAC;AAE9B,IAAI,aAAsB,CAAC;AAE3B,SAAS,cAAc,CAAC,QAAkB,EAAE,WAAgB;IACxD,IAAI,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/B,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAC;QACtB,QAAQ,CAAC,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC;IAE1C,CAAC;SAAM,IAAI,WAAW,CAAC,IAAI,IAAI,EAAE,CAAC,UAAU,CAAC,uBAAuB,EAAE,CAAC;QACnE,QAAQ,CAAC,IAAI,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QACpD,QAAQ,CAAC,SAAS,GAAG,WAAW,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AAU,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAED,aAAa;IACb,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC;AAjBD,sCAiBC","sourcesContent":["import * as ts from \"typescript\";\nimport * as path from \"path\";\nimport {readFileSync} from \"fs\";\nimport {IStructure, Class, Interface, Property, Context, Enum} from \"./types\";\n\nlet currentStructure: IStructure;\nlet currentProperty: Property;\n\nlet globalContext: Context;\n\nfunction defineProperty(property: Property, initializer: any) {\n if (ts.isIdentifier(initializer)) {\n property.type = \"ref\";\n property.childType = initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n property.type = initializer.properties[0].name.text;\n property.childType = initializer.properties[0].initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ArrayLiteralExpression) {\n property.type = \"array\";\n property.childType = initializer.elements[0].text;\n\n } else {\n property.type = initializer.text;\n }\n}\n\nfunction inspectNode(node: ts.Node, context: Context, decoratorName: string) {\n switch (node.kind) {\n case ts.SyntaxKind.ImportClause:\n const specifier = (node.parent as any).moduleSpecifier;\n if (specifier && (specifier.text as string).startsWith('.')) {\n const currentDir = path.dirname(node.getSourceFile().fileName);\n const pathToImport = path.resolve(currentDir, specifier.text);\n parseFiles([pathToImport], decoratorName, globalContext);\n }\n break;\n\n case ts.SyntaxKind.ClassDeclaration:\n currentStructure = new Class();\n\n const heritageClauses = (node as ts.ClassLikeDeclarationBase).heritageClauses;\n if (heritageClauses && heritageClauses.length > 0) {\n (currentStructure as Class).extends = heritageClauses[0].types[0].expression.getText();\n }\n\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.InterfaceDeclaration:\n //\n // Only generate Interfaces if it has \"Message\" on its name.\n // Example: MyMessage\n //\n const interfaceName = (node as ts.TypeParameterDeclaration).name.escapedText.toString();\n if (interfaceName.indexOf(\"Message\") !== -1) {\n currentStructure = new Interface();\n currentStructure.name = interfaceName;\n\n context.addStructure(currentStructure);\n }\n break;\n\n case ts.SyntaxKind.EnumDeclaration:\n const enumName = (\n node as ts.EnumDeclaration\n ).name.escapedText.toString();\n currentStructure = new Enum();\n currentStructure.name = enumName;\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.ExtendsKeyword:\n // console.log(node.getText());\n break;\n\n case ts.SyntaxKind.PropertySignature:\n if (currentStructure instanceof Interface) {\n const interfaceDeclaration = node.parent;\n\n if (\n currentStructure.name !== (interfaceDeclaration as ts.TypeParameterDeclaration).name.escapedText.toString()\n ) {\n // skip if property if for a another interface than the one we're interested in.\n break;\n }\n\n // define a property of an interface\n const property = new Property();\n property.name = (node as any).name.escapedText.toString();\n property.type = (node as any).type.getText();\n currentStructure.addProperty(property);\n }\n break;\n\n case ts.SyntaxKind.Identifier:\n if (\n node.getText() === \"deprecated\" &&\n node.parent.kind !== ts.SyntaxKind.ImportSpecifier\n ) {\n currentProperty = new Property();\n currentProperty.deprecated = true;\n break;\n }\n\n if (node.getText() === decoratorName) {\n const prop: any = node.parent?.parent?.parent;\n const propDecorator = getDecorators(prop);\n const hasExpression = prop?.expression?.arguments;\n const hasDecorator = (propDecorator?.length > 0);\n\n /**\n * neither a `@type()` decorator or `type()` call. skip.\n */\n if (!hasDecorator && !hasExpression) {\n break;\n }\n\n // using as decorator\n if (propDecorator) {\n /**\n * Calling `@type()` as decorator\n */\n const typeDecorator: any = propDecorator.find((decorator => {\n return (decorator.expression as any).expression.escapedText === decoratorName;\n })).expression;\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n const typeArgument = typeDecorator.arguments[0];\n defineProperty(property, typeArgument);\n\n } else if (\n prop.expression.arguments?.[1] &&\n prop.expression.expression.arguments?.[0]\n ) {\n /**\n * Calling `type()` as a regular method\n */\n const property = currentProperty || new Property();\n property.name = prop.expression.arguments[1].text;\n currentStructure.addProperty(property);\n\n const typeArgument = prop.expression.expression.arguments[0];\n defineProperty(property, typeArgument);\n }\n\n\n } else if (\n node.getText() === \"defineTypes\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * JavaScript source file (`.js`)\n * Using `defineTypes()`\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const className = callExpression.arguments[0].getText()\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n defineProperty(property, prop.initializer);\n }\n\n }\n\n if (node.parent.kind === ts.SyntaxKind.ClassDeclaration) {\n currentStructure.name = node.getText();\n }\n\n currentProperty = undefined;\n\n break;\n\n case ts.SyntaxKind.EnumMember:\n if (currentStructure instanceof Enum) {\n const initializer = (node as any).initializer?.text;\n const name = node.getFirstToken().getText();\n const property = currentProperty || new Property();\n property.name = name;\n if (initializer !== undefined) {\n property.type = initializer;\n }\n currentStructure.addProperty(property);\n currentProperty = undefined;\n }\n break;\n }\n\n ts.forEachChild(node, (n) => inspectNode(n, context, decoratorName));\n}\n\nlet parsedFiles: { [filename: string]: boolean };\n\nexport function parseFiles(\n fileNames: string[],\n decoratorName: string = \"type\",\n context: Context = new Context()\n) {\n /**\n * Re-set globalContext for each test case\n */\n if (globalContext !== context) {\n parsedFiles = {};\n globalContext = context;\n }\n\n fileNames.forEach((fileName) => {\n let sourceFile: ts.Node;\n let sourceFileName: string;\n\n const fileNameAlternatives = [];\n\n if (\n !fileName.endsWith(\".ts\") &&\n !fileName.endsWith(\".js\") &&\n !fileName.endsWith(\".mjs\")\n ) {\n fileNameAlternatives.push(`${fileName}.ts`);\n fileNameAlternatives.push(`${fileName}/index.ts`);\n\n } else {\n fileNameAlternatives.push(fileName);\n }\n\n for (let i = 0; i < fileNameAlternatives.length; i++) {\n try {\n sourceFileName = path.resolve(fileNameAlternatives[i]);\n\n if (parsedFiles[sourceFileName]) {\n break;\n }\n\n sourceFile = ts.createSourceFile(\n sourceFileName,\n readFileSync(sourceFileName).toString(),\n ts.ScriptTarget.Latest,\n true\n );\n\n parsedFiles[sourceFileName] = true;\n\n break;\n } catch (e) {\n // console.log(`${fileNameAlternatives[i]} => ${e.message}`);\n }\n }\n\n if (sourceFile) {\n inspectNode(sourceFile, context, decoratorName);\n }\n });\n\n return context.getStructures();\n}\n\n/**\n * TypeScript 4.8+ has introduced a change on how to access decorators.\n * - https://github.com/microsoft/TypeScript/pull/49089\n * - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees\n */\nexport function getDecorators(node: ts.Node | null | undefined,): undefined | ts.Decorator[] {\n if (node == undefined) { return undefined; }\n\n // TypeScript 4.7 and below\n // @ts-ignore\n if (node.decorators) { return node.decorators; }\n\n // TypeScript 4.8 and above\n // @ts-ignore\n if (ts.canHaveDecorators && ts.canHaveDecorators(node)) {\n // @ts-ignore\n const decorators = ts.getDecorators(node);\n return decorators ? Array.from(decorators) : undefined;\n }\n\n // @ts-ignore\n return node.modifiers?.filter(ts.isDecorator);\n}\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/codegen/parser.ts"],"names":[],"mappings":";;AAiUA,gCA4DC;AAOD,sCAiBC;AArZD,iCAAiC;AACjC,6BAA6B;AAC7B,2BAAgC;AAChC,mCAA8E;AAE9E,IAAI,gBAA4B,CAAC;AACjC,IAAI,eAAyB,CAAC;AAE9B,IAAI,aAAsB,CAAC;AAE3B,SAAS,cAAc,CAAC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nC,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,IAAgC;IAC1D,IAAI,IAAI,IAAI,SAAS,EAAE,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;IAE5C,2BAA2B;IAC3B,aAAa;IACb,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;QAAC,OAAO,IAAI,CAAC,UAAU,CAAC;IAAC,CAAC;IAEhD,2BAA2B;IAC3B,aAAa;IACb,IAAI,EAAE,CAAC,iBAAiB,IAAI,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD,aAAa;QACb,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAED,aAAa;IACb,OAAO,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import * as ts from \"typescript\";\nimport * as path from \"path\";\nimport {readFileSync} from \"fs\";\nimport {IStructure, Class, Interface, Property, Context, Enum} from \"./types\";\n\nlet currentStructure: IStructure;\nlet currentProperty: Property;\n\nlet globalContext: Context;\n\nfunction defineProperty(property: Property, initializer: any) {\n if (ts.isIdentifier(initializer)) {\n property.type = \"ref\";\n property.childType = initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ObjectLiteralExpression) {\n property.type = initializer.properties[0].name.text;\n property.childType = initializer.properties[0].initializer.text;\n\n } else if (initializer.kind == ts.SyntaxKind.ArrayLiteralExpression) {\n property.type = \"array\";\n property.childType = initializer.elements[0].text;\n\n } else {\n property.type = initializer.text;\n }\n}\n\nfunction inspectNode(node: ts.Node, context: Context, decoratorName: string) {\n switch (node.kind) {\n case ts.SyntaxKind.ImportClause:\n const specifier = (node.parent as any).moduleSpecifier;\n if (specifier && (specifier.text as string).startsWith('.')) {\n const currentDir = path.dirname(node.getSourceFile().fileName);\n const pathToImport = path.resolve(currentDir, specifier.text);\n parseFiles([pathToImport], decoratorName, globalContext);\n }\n break;\n\n case ts.SyntaxKind.ClassDeclaration:\n currentStructure = new Class();\n\n const heritageClauses = (node as ts.ClassLikeDeclarationBase).heritageClauses;\n if (heritageClauses && heritageClauses.length > 0) {\n (currentStructure as Class).extends = heritageClauses[0].types[0].expression.getText();\n }\n\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.InterfaceDeclaration:\n //\n // Only generate Interfaces if it has \"Message\" on its name.\n // Example: MyMessage\n //\n const interfaceName = (node as ts.TypeParameterDeclaration).name.escapedText.toString();\n if (interfaceName.indexOf(\"Message\") !== -1) {\n currentStructure = new Interface();\n currentStructure.name = interfaceName;\n\n context.addStructure(currentStructure);\n }\n break;\n\n case ts.SyntaxKind.EnumDeclaration:\n const enumName = (\n node as ts.EnumDeclaration\n ).name.escapedText.toString();\n currentStructure = new Enum();\n currentStructure.name = enumName;\n context.addStructure(currentStructure);\n break;\n\n case ts.SyntaxKind.ExtendsKeyword:\n // console.log(node.getText());\n break;\n\n case ts.SyntaxKind.PropertySignature:\n if (currentStructure instanceof Interface) {\n const interfaceDeclaration = node.parent;\n\n if (\n currentStructure.name !== (interfaceDeclaration as ts.TypeParameterDeclaration).name.escapedText.toString()\n ) {\n // skip if property if for a another interface than the one we're interested in.\n break;\n }\n\n // define a property of an interface\n const property = new Property();\n property.name = (node as any).name.escapedText.toString();\n property.type = (node as any).type.getText();\n currentStructure.addProperty(property);\n }\n break;\n\n case ts.SyntaxKind.Identifier:\n if (\n node.getText() === \"deprecated\" &&\n node.parent.kind !== ts.SyntaxKind.ImportSpecifier\n ) {\n currentProperty = new Property();\n currentProperty.deprecated = true;\n break;\n }\n\n if (node.getText() === decoratorName) {\n const prop: any = node.parent?.parent?.parent;\n const propDecorator = getDecorators(prop);\n const hasExpression = prop?.expression?.arguments;\n const hasDecorator = (propDecorator?.length > 0);\n\n /**\n * neither a `@type()` decorator or `type()` call. skip.\n */\n if (!hasDecorator && !hasExpression) {\n break;\n }\n\n // using as decorator\n if (propDecorator) {\n /**\n * Calling `@type()` as decorator\n */\n const typeDecorator: any = propDecorator.find((decorator => {\n return (decorator.expression as any).expression.escapedText === decoratorName;\n })).expression;\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n const typeArgument = typeDecorator.arguments[0];\n defineProperty(property, typeArgument);\n\n } else if (\n prop.expression.arguments?.[1] &&\n prop.expression.expression.arguments?.[0]\n ) {\n /**\n * Calling `type()` as a regular method\n */\n const property = currentProperty || new Property();\n property.name = prop.expression.arguments[1].text;\n currentStructure.addProperty(property);\n\n const typeArgument = prop.expression.expression.arguments[0];\n defineProperty(property, typeArgument);\n }\n\n } else if (\n node.getText() === \"setFields\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * Metadata.setFields(klassName, { ... })\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const classNameNode = callExpression.arguments[0];\n const className = ts.isClassExpression(classNameNode)\n ? classNameNode.name?.escapedText.toString()\n : classNameNode.getText();\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure.name !== className) {\n currentStructure = new Class();\n }\n context.addStructure(currentStructure);\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n\n } else if (\n node.getText() === \"defineTypes\" &&\n (\n node.parent.kind === ts.SyntaxKind.CallExpression ||\n node.parent.kind === ts.SyntaxKind.PropertyAccessExpression\n )\n ) {\n /**\n * JavaScript source file (`.js`)\n * Using `defineTypes()`\n */\n const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)\n ? node.parent.parent as ts.CallExpression\n : node.parent as ts.CallExpression;\n\n if (callExpression.kind !== ts.SyntaxKind.CallExpression) {\n break;\n }\n\n const className = callExpression.arguments[0].getText()\n currentStructure.name = className;\n\n const types = callExpression.arguments[1] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n currentStructure.addProperty(property);\n\n defineProperty(property, prop.initializer);\n }\n\n }\n\n if (node.parent.kind === ts.SyntaxKind.ClassDeclaration) {\n currentStructure.name = node.getText();\n }\n\n currentProperty = undefined;\n\n break;\n\n case ts.SyntaxKind.CallExpression:\n /**\n * Defining schema via `schema.schema({ ... })`\n * - schema.schema({})\n * - schema({})\n * - ClassName.extends({})\n */\n if (\n (\n (\n (node as ts.CallExpression).expression?.getText() === \"schema.schema\" ||\n (node as ts.CallExpression).expression?.getText() === \"schema\"\n ) ||\n (\n (node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1\n )\n ) &&\n (node as ts.CallExpression).arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression\n ) {\n const callExpression = node as ts.CallExpression;\n\n let className = callExpression.arguments[1]?.getText();\n\n if (!className && callExpression.parent.kind === ts.SyntaxKind.VariableDeclaration) {\n className = (callExpression.parent as ts.VariableDeclaration).name?.getText();\n }\n\n // skip if no className is provided\n if (!className) { break; }\n\n if (currentStructure.name !== className) {\n currentStructure = new Class();\n context.addStructure(currentStructure);\n }\n\n if ((node as ts.CallExpression).expression?.getText().indexOf(\".extends\") !== -1) {\n // if it's using `.extends({})`\n const extendsClass = (node as any).expression?.expression?.escapedText;\n\n // skip if no extendsClass is provided\n if (!extendsClass) { break; }\n (currentStructure as Class).extends = extendsClass;\n\n } else {\n // if it's using `schema({})`\n (currentStructure as Class).extends = \"Schema\"; // force extends to Schema\n }\n\n currentStructure.name = className;\n\n const types = callExpression.arguments[0] as any;\n for (let i = 0; i < types.properties.length; i++) {\n const prop = types.properties[i];\n\n const property = currentProperty || new Property();\n property.name = prop.name.escapedText;\n\n currentStructure.addProperty(property);\n defineProperty(property, prop.initializer);\n }\n }\n\n break;\n\n case ts.SyntaxKind.EnumMember:\n if (currentStructure instanceof Enum) {\n const initializer = (node as any).initializer?.text;\n const name = node.getFirstToken().getText();\n const property = currentProperty || new Property();\n property.name = name;\n if (initializer !== undefined) {\n property.type = initializer;\n }\n currentStructure.addProperty(property);\n currentProperty = undefined;\n }\n break;\n }\n\n ts.forEachChild(node, (n) => inspectNode(n, context, decoratorName));\n}\n\nlet parsedFiles: { [filename: string]: boolean };\n\nexport function parseFiles(\n fileNames: string[],\n decoratorName: string = \"type\",\n context: Context = new Context()\n) {\n /**\n * Re-set globalContext for each test case\n */\n if (globalContext !== context) {\n parsedFiles = {};\n globalContext = context;\n }\n\n fileNames.forEach((fileName) => {\n let sourceFile: ts.Node;\n let sourceFileName: string;\n\n const fileNameAlternatives = [];\n\n if (\n !fileName.endsWith(\".ts\") &&\n !fileName.endsWith(\".js\") &&\n !fileName.endsWith(\".mjs\")\n ) {\n fileNameAlternatives.push(`${fileName}.ts`);\n fileNameAlternatives.push(`${fileName}/index.ts`);\n\n } else {\n fileNameAlternatives.push(fileName);\n }\n\n for (let i = 0; i < fileNameAlternatives.length; i++) {\n try {\n sourceFileName = path.resolve(fileNameAlternatives[i]);\n\n if (parsedFiles[sourceFileName]) {\n break;\n }\n\n sourceFile = ts.createSourceFile(\n sourceFileName,\n readFileSync(sourceFileName).toString(),\n ts.ScriptTarget.Latest,\n true\n );\n\n parsedFiles[sourceFileName] = true;\n\n break;\n } catch (e) {\n // console.log(`${fileNameAlternatives[i]} => ${e.message}`);\n }\n }\n\n if (sourceFile) {\n inspectNode(sourceFile, context, decoratorName);\n }\n });\n\n return context.getStructures();\n}\n\n/**\n * TypeScript 4.8+ has introduced a change on how to access decorators.\n * - https://github.com/microsoft/TypeScript/pull/49089\n * - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees\n */\nexport function getDecorators(node: ts.Node | null | undefined,): undefined | ts.Decorator[] {\n if (node == undefined) { return undefined; }\n\n // TypeScript 4.7 and below\n // @ts-ignore\n if (node.decorators) { return node.decorators; }\n\n // TypeScript 4.8 and above\n // @ts-ignore\n if (ts.canHaveDecorators && ts.canHaveDecorators(node)) {\n // @ts-ignore\n const decorators = ts.getDecorators(node);\n return decorators ? Array.from(decorators) : undefined;\n }\n\n // @ts-ignore\n return node.modifiers?.filter(ts.isDecorator);\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInheritanceTree = exports.Property = exports.Enum = exports.Class = exports.Interface = exports.Context = exports.getCommentHeader = void 0;
3
+ exports.Property = exports.Enum = exports.Class = exports.Interface = exports.Context = void 0;
4
+ exports.getCommentHeader = getCommentHeader;
5
+ exports.getInheritanceTree = getInheritanceTree;
4
6
  const fs = require("fs");
5
7
  const VERSION = JSON.parse(fs.readFileSync(__dirname + "/../../package.json").toString()).version;
6
8
  const COMMENT_HEADER = `
@@ -12,7 +14,6 @@ GENERATED USING @colyseus/schema ${VERSION}
12
14
  function getCommentHeader(singleLineComment = "//") {
13
15
  return `${COMMENT_HEADER.split("\n").map(line => `${singleLineComment} ${line}`).join("\n")}`;
14
16
  }
15
- exports.getCommentHeader = getCommentHeader;
16
17
  class Context {
17
18
  constructor() {
18
19
  this.classes = [];
@@ -40,6 +41,9 @@ class Context {
40
41
  };
41
42
  }
42
43
  addStructure(structure) {
44
+ if (structure.context === this) {
45
+ return;
46
+ } // skip if already added.
43
47
  structure.context = this;
44
48
  if (structure instanceof Class) {
45
49
  this.classes.push(structure);
@@ -141,5 +145,4 @@ function getInheritanceTree(klass, allClasses, includeSelf = true) {
141
145
  }
142
146
  return inheritanceTree;
143
147
  }
144
- exports.getInheritanceTree = getInheritanceTree;
145
148
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/codegen/types.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AAEzB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,SAAS,GAAG,qBAAqB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;AAClG,MAAM,cAAc,GAAG;;;;mCAIY,OAAO;CACzC,CAAC;AAEF,SAAgB,gBAAgB,CAAC,oBAA4B,IAAI;IAC7D,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,iBAAiB,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClG,CAAC;AAFD,4CAEC;AAED,MAAa,OAAO;IAApB;QACI,YAAO,GAAY,EAAE,CAAC;QACtB,eAAU,GAAgB,EAAE,CAAC;QAC7B,UAAK,GAAW,EAAE,CAAC;IAmEvB,CAAC;IAjEG,aAAa;QACT,OAAO;YACH,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;gBACjC,IAAI,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC5B,OAAO,IAAI,CAAC;gBAEhB,CAAC;qBAAM,CAAC;oBACJ,IAAI,WAAW,GAAG,KAAK,CAAC;oBACxB,OAAO,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,CAAC;wBACpD,IAAI,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,EAAE,CAAC;4BAClC,OAAO,IAAI,CAAC;wBAChB,CAAC;oBACL,CAA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AK,IAAI,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC;YAChD,CAAC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ;AA1BD,sBA0BC;AAED,MAAa,IAAI;IAAjB;QAGI,eAAU,GAAe,EAAE,CAAC;IAKhC,CAAC;IAHG,WAAW,CAAC,QAAkB;QAC1B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;CACJ;AARD,oBAQC;AAED,MAAa,QAAQ;CAMpB;AAND,4BAMC;AAOD,SAAgB,kBAAkB,CAAC,KAAY,EAAE,UAAmB,EAAE,cAAuB,IAAI;IAC7F,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,IAAI,eAAe,GAAY,EAAE,CAAC;IAElC,IAAI,WAAW,EAAE,CAAC;QACd,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,YAAY,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;QACvC,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC5E,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;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 enums: Enum[] = [];\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 enums: this.enums,\n };\n }\n\n addStructure(structure: IStructure) {\n structure.context = this;\n\n if (structure instanceof Class) {\n this.classes.push(structure);\n } else if (structure instanceof Interface) {\n this.interfaces.push(structure);\n } else if (structure instanceof Enum) {\n this.enums.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 Enum implements IStructure {\n context: Context;\n name: string;\n properties: Property[] = [];\n\n addProperty(property: Property) {\n this.properties.push(property);\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"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/codegen/types.ts"],"names":[],"mappings":";;;AAUA,4CAEC;AAuJD,gDAcC;AAjLD,yBAAyB;AAEzB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,SAAS,GAAG,qBAAqB,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC;AAClG,MAAM,cAAc,GAAG;;;;mCAIY,OAAO;CACzC,CAAC;AAEF,SAAgB,gBAAgB,CAAC,oBAA4B,IAAI;IAC7D,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,iBAAiB,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClG,CAAC;AAED,MAAa,OAAO;IAApB;QACI,YAAO,GAAY,EAAE,CAAC;QACtB,eAAU,GAAgB,EAAE,CAAC;QAC7B,UAAK,GAAW,EAAE,CAAC;IAoEvB,CAAC;IAlEG,aAAa;QACT,OAAO;YACH,OAAO,EA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eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,eAAe,CAAC;AAC3B,CAAC","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 enums: Enum[] = [];\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 enums: this.enums,\n };\n }\n\n addStructure(structure: IStructure) {\n if (structure.context === this) { return; } // skip if already added.\n structure.context = this;\n\n if (structure instanceof Class) {\n this.classes.push(structure);\n } else if (structure instanceof Interface) {\n this.interfaces.push(structure);\n } else if (structure instanceof Enum) {\n this.enums.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 Enum implements IStructure {\n context: Context;\n name: string;\n properties: Property[] = [];\n\n addProperty(property: Property) {\n this.properties.push(property);\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"]}
package/lib/debug.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/debug.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const index_1 = require("./index");
5
+ const contents = fs.readFileSync("/Users/endel/Projects/colyseus/clients/bubbits/project/@bubbits/backend/schema-debug.txt", { encoding: "utf8" }).toString();
6
+ let isCommentBlock = false;
7
+ let lastComment = "";
8
+ let decoder;
9
+ function getBuffer(line) {
10
+ const start = line.lastIndexOf(":");
11
+ const buffer = Buffer.from(new Uint8Array(line.substring(start + 1).split(",").map(n => Number(n))));
12
+ console.log(`(${buffer.byteLength}) ${Array.from(buffer).join(",")}`);
13
+ // console.log("");
14
+ // console.log("");
15
+ // console.log("> ", line);
16
+ // console.log("> substring:", line.substring(start + 1))
17
+ return buffer;
18
+ }
19
+ function decode(buffer) {
20
+ try {
21
+ decoder.decode(buffer);
22
+ }
23
+ catch (e) {
24
+ console.error(e);
25
+ console.log("Last log:\n\n");
26
+ console.log(lastComment);
27
+ }
28
+ }
29
+ contents.split("\n").forEach((line) => {
30
+ if (line.startsWith("#")) {
31
+ // reset last comment.
32
+ if (isCommentBlock === false) {
33
+ lastComment = "";
34
+ }
35
+ isCommentBlock = true;
36
+ lastComment += line.substring(line.indexOf(":") + 1) + "\n";
37
+ return;
38
+ }
39
+ isCommentBlock = false;
40
+ if (line.startsWith("handshake:") && !decoder) {
41
+ decoder = index_1.Reflection.decode(getBuffer(line));
42
+ }
43
+ else if (line.startsWith("state:")) {
44
+ decode(getBuffer(line));
45
+ }
46
+ else if (line.startsWith("patch:")) {
47
+ decode(getBuffer(line));
48
+ }
49
+ });
50
+ console.log(decoder.state.toJSON());
51
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":";;AAAA,yBAAyB;AACzB,mCAA8C;AAE9C,MAAM,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,0FAA0F,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;AAE9J,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,WAAW,GAAG,EAAE,CAAC;AAErB,IAAI,OAAgB,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AAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;QAC5D,OAAO;IACX,CAAC;IAED,cAAc,GAAG,KAAK,CAAC;IAEvB,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5C,OAAO,GAAG,kBAAU,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjD,CAAC;SAAM,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAE5B,CAAC;SAAM,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5B,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC","sourcesContent":["import * as fs from \"fs\";\nimport { Reflection, Decoder } from \"./index\";\n\nconst contents = fs.readFileSync(\"/Users/endel/Projects/colyseus/clients/bubbits/project/@bubbits/backend/schema-debug.txt\", { encoding: \"utf8\" }).toString();\n\nlet isCommentBlock = false;\nlet lastComment = \"\";\n\nlet decoder: Decoder;\n\nfunction getBuffer(line: string) {\n const start = line.lastIndexOf(\":\");\n const buffer = Buffer.from(new Uint8Array(line.substring(start + 1).split(\",\").map(n => Number(n))));\n console.log(`(${buffer.byteLength}) ${Array.from(buffer).join(\",\")}`)\n // console.log(\"\");\n // console.log(\"\");\n // console.log(\"> \", line);\n // console.log(\"> substring:\", line.substring(start + 1))\n return buffer;\n}\n\nfunction decode(buffer: Buffer) {\n try {\n decoder.decode(buffer);\n } catch (e) {\n console.error(e);\n console.log(\"Last log:\\n\\n\")\n console.log(lastComment);\n }\n}\n\ncontents.split(\"\\n\").forEach((line) => {\n if (line.startsWith(\"#\")) {\n // reset last comment.\n if (isCommentBlock === false) { lastComment = \"\"; }\n\n isCommentBlock = true;\n lastComment += line.substring(line.indexOf(\":\") + 1) + \"\\n\";\n return;\n }\n\n isCommentBlock = false;\n\n if (line.startsWith(\"handshake:\") && !decoder) {\n decoder = Reflection.decode(getBuffer(line));\n\n } else if (line.startsWith(\"state:\")) {\n decode(getBuffer(line));\n\n } else if (line.startsWith(\"patch:\")) {\n decode(getBuffer(line));\n }\n});\n\nconsole.log(decoder.state.toJSON());"]}
@@ -1,9 +1,8 @@
1
- /// <reference types="node" />
2
1
  import { OPERATION } from "../encoding/spec";
3
2
  import { Schema } from "../Schema";
4
3
  import type { Ref } from "../encoder/ChangeTree";
5
4
  import type { Decoder } from "./Decoder";
6
- import * as decode from "../encoding/decode";
5
+ import { Iterator } from "../encoding/decode";
7
6
  export interface DataChange<T = any, F = string> {
8
7
  ref: Ref;
9
8
  refId: number;
@@ -14,8 +13,8 @@ export interface DataChange<T = any, F = string> {
14
13
  previousValue: T;
15
14
  }
16
15
  export declare const DEFINITION_MISMATCH = -1;
17
- export type DecodeOperation<T extends Schema = any> = (decoder: Decoder<T>, bytes: Buffer, it: decode.Iterator, ref: Ref, allChanges: DataChange[]) => number | void;
18
- export declare function decodeValue(decoder: Decoder, operation: OPERATION, ref: Ref, index: number, type: any, bytes: Buffer, it: decode.Iterator, allChanges: DataChange[]): {
16
+ export type DecodeOperation<T extends Schema = any> = (decoder: Decoder<T>, bytes: Buffer, it: Iterator, ref: Ref, allChanges: DataChange[]) => number | void;
17
+ export declare function decodeValue(decoder: Decoder, operation: OPERATION, ref: Ref, index: number, type: any, bytes: Buffer, it: Iterator, allChanges: DataChange[]): {
19
18
  value: any;
20
19
  previousValue: any;
21
20
  };