@colyseus/schema 4.0.2 → 4.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 → build}/Metadata.d.ts +2 -2
- package/{lib → build}/Reflection.d.ts +13 -13
- package/{lib → build}/Schema.d.ts +10 -10
- package/{lib/src → build}/annotations.d.ts +10 -10
- package/build/codegen/languages/cpp.d.ts +3 -0
- package/build/codegen/languages/csharp.d.ts +4 -0
- package/build/codegen/languages/haxe.d.ts +3 -0
- package/{lib → build}/codegen/languages/java.d.ts +2 -2
- package/build/codegen/languages/js.d.ts +3 -0
- package/build/codegen/languages/lua.d.ts +3 -0
- package/build/codegen/languages/ts.d.ts +3 -0
- package/{lib → build}/codegen/parser.d.ts +1 -1
- package/{lib → build}/decoder/DecodeOperation.d.ts +5 -5
- package/{lib/src → build}/decoder/Decoder.d.ts +7 -7
- package/{lib → build}/decoder/ReferenceTracker.d.ts +1 -1
- package/{lib → build}/decoder/strategy/Callbacks.d.ts +11 -11
- package/{lib → build}/decoder/strategy/RawChanges.d.ts +2 -2
- package/{lib → build}/decoder/strategy/getDecoderStateCallbacks.d.ts +3 -3
- package/{lib → build}/encoder/ChangeTree.d.ts +11 -11
- package/{lib → build}/encoder/EncodeOperation.d.ts +5 -5
- package/{lib → build}/encoder/Encoder.d.ts +6 -6
- package/{lib/src → build}/encoder/Root.d.ts +2 -2
- package/{lib/src → build}/encoder/StateView.d.ts +1 -1
- package/{lib/src → build}/encoding/assert.d.ts +6 -6
- package/{lib/src → build}/encoding/decode.d.ts +1 -1
- package/{lib/src → build}/encoding/encode.d.ts +1 -1
- package/build/index.cjs.map +1 -0
- package/build/index.d.ts +32 -0
- package/build/index.mjs.map +1 -0
- package/{lib → build}/types/HelperTypes.d.ts +6 -6
- package/{lib → build}/types/TypeContext.d.ts +1 -1
- package/{lib/src → build}/types/custom/ArraySchema.d.ts +8 -8
- package/{lib/src → build}/types/custom/CollectionSchema.d.ts +7 -7
- package/{lib → build}/types/custom/MapSchema.d.ts +7 -7
- package/{lib/src → build}/types/custom/SetSchema.d.ts +7 -7
- package/{lib/src → build}/types/registry.d.ts +2 -2
- package/{lib → build}/utils.d.ts +1 -1
- package/package.json +9 -10
- package/src/Metadata.ts +5 -5
- package/src/Reflection.ts +7 -7
- package/src/Schema.ts +11 -11
- package/src/annotations.ts +13 -13
- package/src/codegen/api.ts +3 -3
- package/src/codegen/cli.ts +2 -2
- package/src/codegen/languages/cpp.ts +2 -2
- package/src/codegen/languages/csharp.ts +3 -3
- package/src/codegen/languages/haxe.ts +2 -2
- package/src/codegen/languages/java.ts +2 -2
- package/src/codegen/languages/js.ts +2 -2
- package/src/codegen/languages/lua.ts +2 -2
- package/src/codegen/languages/ts.ts +2 -2
- package/src/codegen/parser.ts +6 -1
- package/src/decoder/DecodeOperation.ts +14 -14
- package/src/decoder/Decoder.ts +11 -11
- package/src/decoder/ReferenceTracker.ts +8 -8
- package/src/decoder/strategy/Callbacks.ts +12 -12
- package/src/decoder/strategy/RawChanges.ts +2 -2
- package/src/decoder/strategy/getDecoderStateCallbacks.ts +10 -10
- package/src/encoder/ChangeTree.ts +13 -13
- package/src/encoder/EncodeOperation.ts +9 -9
- package/src/encoder/Encoder.ts +10 -10
- package/src/encoder/Root.ts +4 -4
- package/src/encoder/StateView.ts +7 -7
- package/src/encoding/assert.ts +6 -6
- package/src/encoding/decode.ts +1 -1
- package/src/encoding/encode.ts +1 -1
- package/src/index.ts +27 -27
- package/src/types/HelperTypes.ts +6 -6
- package/src/types/TypeContext.ts +3 -3
- package/src/types/custom/ArraySchema.ts +11 -11
- package/src/types/custom/CollectionSchema.ts +9 -9
- package/src/types/custom/MapSchema.ts +10 -10
- package/src/types/custom/SetSchema.ts +9 -9
- package/src/types/registry.ts +3 -3
- package/src/utils.ts +3 -3
- package/src/v3_bench.ts +1 -1
- package/build/cjs/index.cjs.map +0 -1
- package/build/esm/index.mjs.map +0 -1
- package/lib/Metadata.js +0 -256
- package/lib/Metadata.js.map +0 -1
- package/lib/Reflection.js +0 -179
- package/lib/Reflection.js.map +0 -1
- package/lib/Schema.js +0 -352
- package/lib/Schema.js.map +0 -1
- package/lib/annotations.d.ts +0 -109
- package/lib/annotations.js +0 -473
- package/lib/annotations.js.map +0 -1
- package/lib/bench_encode.d.ts +0 -1
- package/lib/bench_encode.js +0 -91
- package/lib/bench_encode.js.map +0 -1
- package/lib/benchmark.d.ts +0 -1
- package/lib/benchmark.js +0 -218
- package/lib/benchmark.js.map +0 -1
- package/lib/codegen/api.js +0 -56
- package/lib/codegen/api.js.map +0 -1
- package/lib/codegen/argv.js +0 -39
- package/lib/codegen/argv.js.map +0 -1
- package/lib/codegen/cli.js +0 -58
- package/lib/codegen/cli.js.map +0 -1
- package/lib/codegen/languages/cpp.d.ts +0 -3
- package/lib/codegen/languages/cpp.js +0 -258
- package/lib/codegen/languages/cpp.js.map +0 -1
- package/lib/codegen/languages/csharp.d.ts +0 -4
- package/lib/codegen/languages/csharp.js +0 -154
- package/lib/codegen/languages/csharp.js.map +0 -1
- package/lib/codegen/languages/haxe.d.ts +0 -3
- package/lib/codegen/languages/haxe.js +0 -100
- package/lib/codegen/languages/haxe.js.map +0 -1
- package/lib/codegen/languages/java.js +0 -100
- package/lib/codegen/languages/java.js.map +0 -1
- package/lib/codegen/languages/js.d.ts +0 -3
- package/lib/codegen/languages/js.js +0 -101
- package/lib/codegen/languages/js.js.map +0 -1
- package/lib/codegen/languages/lua.d.ts +0 -3
- package/lib/codegen/languages/lua.js +0 -103
- package/lib/codegen/languages/lua.js.map +0 -1
- package/lib/codegen/languages/ts.d.ts +0 -3
- package/lib/codegen/languages/ts.js +0 -116
- package/lib/codegen/languages/ts.js.map +0 -1
- package/lib/codegen/parser.js +0 -327
- package/lib/codegen/parser.js.map +0 -1
- package/lib/codegen/types.js +0 -142
- package/lib/codegen/types.js.map +0 -1
- package/lib/decoder/DecodeOperation.js +0 -248
- package/lib/decoder/DecodeOperation.js.map +0 -1
- package/lib/decoder/Decoder.d.ts +0 -21
- package/lib/decoder/Decoder.js +0 -114
- package/lib/decoder/Decoder.js.map +0 -1
- package/lib/decoder/ReferenceTracker.js +0 -135
- package/lib/decoder/ReferenceTracker.js.map +0 -1
- package/lib/decoder/strategy/Callbacks.js +0 -336
- package/lib/decoder/strategy/Callbacks.js.map +0 -1
- package/lib/decoder/strategy/RawChanges.js +0 -4
- package/lib/decoder/strategy/RawChanges.js.map +0 -1
- package/lib/decoder/strategy/getDecoderStateCallbacks.js +0 -274
- package/lib/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
- package/lib/encoder/ChangeTree.js +0 -534
- package/lib/encoder/ChangeTree.js.map +0 -1
- package/lib/encoder/EncodeOperation.js +0 -132
- package/lib/encoder/EncodeOperation.js.map +0 -1
- package/lib/encoder/Encoder.js +0 -204
- package/lib/encoder/Encoder.js.map +0 -1
- package/lib/encoder/Root.d.ts +0 -28
- package/lib/encoder/Root.js +0 -229
- package/lib/encoder/Root.js.map +0 -1
- package/lib/encoder/StateView.d.ts +0 -34
- package/lib/encoder/StateView.js +0 -279
- package/lib/encoder/StateView.js.map +0 -1
- package/lib/encoding/assert.d.ts +0 -10
- package/lib/encoding/assert.js +0 -49
- package/lib/encoding/assert.js.map +0 -1
- package/lib/encoding/decode.d.ts +0 -67
- package/lib/encoding/decode.js +0 -217
- package/lib/encoding/decode.js.map +0 -1
- package/lib/encoding/encode.d.ts +0 -40
- package/lib/encoding/encode.js +0 -279
- package/lib/encoding/encode.js.map +0 -1
- package/lib/encoding/spec.js +0 -26
- package/lib/encoding/spec.js.map +0 -1
- package/lib/index.d.ts +0 -32
- package/lib/index.js +0 -39
- package/lib/index.js.map +0 -1
- package/lib/src/Metadata.d.ts +0 -49
- package/lib/src/Metadata.js +0 -256
- package/lib/src/Metadata.js.map +0 -1
- package/lib/src/Reflection.d.ts +0 -71
- package/lib/src/Reflection.js +0 -179
- package/lib/src/Reflection.js.map +0 -1
- package/lib/src/Schema.d.ts +0 -86
- package/lib/src/Schema.js +0 -352
- package/lib/src/Schema.js.map +0 -1
- package/lib/src/annotations.js +0 -473
- package/lib/src/annotations.js.map +0 -1
- package/lib/src/bench_encode.d.ts +0 -1
- package/lib/src/bench_encode.js +0 -91
- package/lib/src/bench_encode.js.map +0 -1
- package/lib/src/codegen/api.d.ts +0 -7
- package/lib/src/codegen/api.js +0 -56
- package/lib/src/codegen/api.js.map +0 -1
- package/lib/src/codegen/argv.d.ts +0 -6
- package/lib/src/codegen/argv.js +0 -39
- package/lib/src/codegen/argv.js.map +0 -1
- package/lib/src/codegen/cli.d.ts +0 -1
- package/lib/src/codegen/cli.js +0 -58
- package/lib/src/codegen/cli.js.map +0 -1
- package/lib/src/codegen/languages/cpp.d.ts +0 -3
- package/lib/src/codegen/languages/cpp.js +0 -258
- package/lib/src/codegen/languages/cpp.js.map +0 -1
- package/lib/src/codegen/languages/csharp.d.ts +0 -4
- package/lib/src/codegen/languages/csharp.js +0 -154
- package/lib/src/codegen/languages/csharp.js.map +0 -1
- package/lib/src/codegen/languages/haxe.d.ts +0 -3
- package/lib/src/codegen/languages/haxe.js +0 -100
- package/lib/src/codegen/languages/haxe.js.map +0 -1
- package/lib/src/codegen/languages/java.d.ts +0 -6
- package/lib/src/codegen/languages/java.js +0 -100
- package/lib/src/codegen/languages/java.js.map +0 -1
- package/lib/src/codegen/languages/js.d.ts +0 -3
- package/lib/src/codegen/languages/js.js +0 -101
- package/lib/src/codegen/languages/js.js.map +0 -1
- package/lib/src/codegen/languages/lua.d.ts +0 -3
- package/lib/src/codegen/languages/lua.js +0 -103
- package/lib/src/codegen/languages/lua.js.map +0 -1
- package/lib/src/codegen/languages/ts.d.ts +0 -3
- package/lib/src/codegen/languages/ts.js +0 -116
- package/lib/src/codegen/languages/ts.js.map +0 -1
- package/lib/src/codegen/parser.d.ts +0 -13
- package/lib/src/codegen/parser.js +0 -327
- package/lib/src/codegen/parser.js.map +0 -1
- package/lib/src/codegen/types.d.ts +0 -52
- package/lib/src/codegen/types.js +0 -142
- package/lib/src/codegen/types.js.map +0 -1
- package/lib/src/decoder/DecodeOperation.d.ts +0 -23
- package/lib/src/decoder/DecodeOperation.js +0 -248
- package/lib/src/decoder/DecodeOperation.js.map +0 -1
- package/lib/src/decoder/Decoder.js +0 -114
- package/lib/src/decoder/Decoder.js.map +0 -1
- package/lib/src/decoder/ReferenceTracker.d.ts +0 -25
- package/lib/src/decoder/ReferenceTracker.js +0 -135
- package/lib/src/decoder/ReferenceTracker.js.map +0 -1
- package/lib/src/decoder/strategy/Callbacks.d.ts +0 -154
- package/lib/src/decoder/strategy/Callbacks.js +0 -336
- package/lib/src/decoder/strategy/Callbacks.js.map +0 -1
- package/lib/src/decoder/strategy/RawChanges.d.ts +0 -3
- package/lib/src/decoder/strategy/RawChanges.js +0 -4
- package/lib/src/decoder/strategy/RawChanges.js.map +0 -1
- package/lib/src/decoder/strategy/getDecoderStateCallbacks.d.ts +0 -76
- package/lib/src/decoder/strategy/getDecoderStateCallbacks.js +0 -274
- package/lib/src/decoder/strategy/getDecoderStateCallbacks.js.map +0 -1
- package/lib/src/encoder/ChangeTree.d.ts +0 -135
- package/lib/src/encoder/ChangeTree.js +0 -534
- package/lib/src/encoder/ChangeTree.js.map +0 -1
- package/lib/src/encoder/EncodeOperation.d.ts +0 -22
- package/lib/src/encoder/EncodeOperation.js +0 -132
- package/lib/src/encoder/EncodeOperation.js.map +0 -1
- package/lib/src/encoder/Encoder.d.ts +0 -22
- package/lib/src/encoder/Encoder.js +0 -204
- package/lib/src/encoder/Encoder.js.map +0 -1
- package/lib/src/encoder/Root.js +0 -229
- package/lib/src/encoder/Root.js.map +0 -1
- package/lib/src/encoder/StateView.js +0 -279
- package/lib/src/encoder/StateView.js.map +0 -1
- package/lib/src/encoding/assert.js +0 -49
- package/lib/src/encoding/assert.js.map +0 -1
- package/lib/src/encoding/decode.js +0 -217
- package/lib/src/encoding/decode.js.map +0 -1
- package/lib/src/encoding/encode.js +0 -279
- package/lib/src/encoding/encode.js.map +0 -1
- package/lib/src/encoding/spec.d.ts +0 -24
- package/lib/src/encoding/spec.js +0 -26
- package/lib/src/encoding/spec.js.map +0 -1
- package/lib/src/index.d.ts +0 -32
- package/lib/src/index.js +0 -39
- package/lib/src/index.js.map +0 -1
- package/lib/src/symbol.shim.js +0 -3
- package/lib/src/symbol.shim.js.map +0 -1
- package/lib/src/types/HelperTypes.d.ts +0 -77
- package/lib/src/types/HelperTypes.js +0 -2
- package/lib/src/types/HelperTypes.js.map +0 -1
- package/lib/src/types/TypeContext.d.ts +0 -31
- package/lib/src/types/TypeContext.js +0 -143
- package/lib/src/types/TypeContext.js.map +0 -1
- package/lib/src/types/custom/ArraySchema.js +0 -733
- package/lib/src/types/custom/ArraySchema.js.map +0 -1
- package/lib/src/types/custom/CollectionSchema.js +0 -170
- package/lib/src/types/custom/CollectionSchema.js.map +0 -1
- package/lib/src/types/custom/MapSchema.d.ts +0 -51
- package/lib/src/types/custom/MapSchema.js +0 -222
- package/lib/src/types/custom/MapSchema.js.map +0 -1
- package/lib/src/types/custom/SetSchema.js +0 -178
- package/lib/src/types/custom/SetSchema.js.map +0 -1
- package/lib/src/types/registry.js +0 -30
- package/lib/src/types/registry.js.map +0 -1
- package/lib/src/types/symbols.js +0 -34
- package/lib/src/types/symbols.js.map +0 -1
- package/lib/src/types/utils.js +0 -13
- package/lib/src/types/utils.js.map +0 -1
- package/lib/src/utils.d.ts +0 -13
- package/lib/src/utils.js +0 -49
- package/lib/src/utils.js.map +0 -1
- package/lib/src/v3_bench.js +0 -128
- package/lib/src/v3_bench.js.map +0 -1
- package/lib/symbol.shim.d.ts +0 -6
- package/lib/symbol.shim.js +0 -3
- package/lib/symbol.shim.js.map +0 -1
- package/lib/types/HelperTypes.js +0 -2
- package/lib/types/HelperTypes.js.map +0 -1
- package/lib/types/TypeContext.js +0 -143
- package/lib/types/TypeContext.js.map +0 -1
- package/lib/types/custom/ArraySchema.d.ts +0 -270
- package/lib/types/custom/ArraySchema.js +0 -733
- package/lib/types/custom/ArraySchema.js.map +0 -1
- package/lib/types/custom/CollectionSchema.d.ts +0 -51
- package/lib/types/custom/CollectionSchema.js +0 -170
- package/lib/types/custom/CollectionSchema.js.map +0 -1
- package/lib/types/custom/MapSchema.js +0 -222
- package/lib/types/custom/MapSchema.js.map +0 -1
- package/lib/types/custom/SetSchema.d.ts +0 -48
- package/lib/types/custom/SetSchema.js +0 -178
- package/lib/types/custom/SetSchema.js.map +0 -1
- package/lib/types/registry.d.ts +0 -16
- package/lib/types/registry.js +0 -30
- package/lib/types/registry.js.map +0 -1
- package/lib/types/symbols.d.ts +0 -33
- package/lib/types/symbols.js +0 -34
- package/lib/types/symbols.js.map +0 -1
- package/lib/types/utils.d.ts +0 -1
- package/lib/types/utils.js +0 -13
- package/lib/types/utils.js.map +0 -1
- package/lib/utils.js +0 -49
- package/lib/utils.js.map +0 -1
- package/lib/v3_bench.d.ts +0 -1
- package/lib/v3_bench.js +0 -128
- package/lib/v3_bench.js.map +0 -1
- /package/{lib → build}/codegen/api.d.ts +0 -0
- /package/{lib → build}/codegen/argv.d.ts +0 -0
- /package/{lib → build}/codegen/cli.d.ts +0 -0
- /package/{lib → build}/codegen/types.d.ts +0 -0
- /package/{lib → build}/encoding/spec.d.ts +0 -0
- /package/build/{cjs/index.cjs → index.cjs} +0 -0
- /package/build/{umd/index.js → index.js} +0 -0
- /package/build/{esm/index.mjs → index.mjs} +0 -0
- /package/{lib/src → build}/symbol.shim.d.ts +0 -0
- /package/{lib/src → build}/types/symbols.d.ts +0 -0
- /package/{lib/src → build}/types/utils.d.ts +0 -0
- /package/{lib/src → build}/v3_bench.d.ts +0 -0
package/lib/codegen/parser.js
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
import { readFileSync } from "fs";
|
|
4
|
-
import { Class, Interface, Property, Context, Enum } from "./types";
|
|
5
|
-
let currentStructure;
|
|
6
|
-
let currentProperty;
|
|
7
|
-
let globalContext;
|
|
8
|
-
function defineProperty(property, initializer) {
|
|
9
|
-
if (ts.isIdentifier(initializer)) {
|
|
10
|
-
property.type = "ref";
|
|
11
|
-
property.childType = initializer.text;
|
|
12
|
-
}
|
|
13
|
-
else if (initializer.kind == ts.SyntaxKind.ObjectLiteralExpression) {
|
|
14
|
-
property.type = initializer.properties[0].name.text;
|
|
15
|
-
property.childType = initializer.properties[0].initializer.text;
|
|
16
|
-
}
|
|
17
|
-
else if (initializer.kind == ts.SyntaxKind.ArrayLiteralExpression) {
|
|
18
|
-
property.type = "array";
|
|
19
|
-
property.childType = initializer.elements[0].text;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
property.type = initializer.text;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function inspectNode(node, context, decoratorName) {
|
|
26
|
-
switch (node.kind) {
|
|
27
|
-
case ts.SyntaxKind.ImportClause:
|
|
28
|
-
const specifier = node.parent.moduleSpecifier;
|
|
29
|
-
if (specifier && specifier.text.startsWith('.')) {
|
|
30
|
-
const currentDir = path.dirname(node.getSourceFile().fileName);
|
|
31
|
-
const pathToImport = path.resolve(currentDir, specifier.text);
|
|
32
|
-
parseFiles([pathToImport], decoratorName, globalContext);
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case ts.SyntaxKind.ClassDeclaration:
|
|
36
|
-
currentStructure = new Class();
|
|
37
|
-
const heritageClauses = node.heritageClauses;
|
|
38
|
-
if (heritageClauses && heritageClauses.length > 0) {
|
|
39
|
-
currentStructure.extends = heritageClauses[0].types[0].expression.getText();
|
|
40
|
-
}
|
|
41
|
-
context.addStructure(currentStructure);
|
|
42
|
-
break;
|
|
43
|
-
case ts.SyntaxKind.InterfaceDeclaration:
|
|
44
|
-
//
|
|
45
|
-
// Only generate Interfaces if it has "Message" on its name.
|
|
46
|
-
// Example: MyMessage
|
|
47
|
-
//
|
|
48
|
-
const interfaceName = node.name.escapedText.toString();
|
|
49
|
-
if (interfaceName.indexOf("Message") !== -1) {
|
|
50
|
-
currentStructure = new Interface();
|
|
51
|
-
currentStructure.name = interfaceName;
|
|
52
|
-
context.addStructure(currentStructure);
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
case ts.SyntaxKind.EnumDeclaration:
|
|
56
|
-
const enumName = node.name.escapedText.toString();
|
|
57
|
-
currentStructure = new Enum();
|
|
58
|
-
currentStructure.name = enumName;
|
|
59
|
-
context.addStructure(currentStructure);
|
|
60
|
-
break;
|
|
61
|
-
case ts.SyntaxKind.ExtendsKeyword:
|
|
62
|
-
// console.log(node.getText());
|
|
63
|
-
break;
|
|
64
|
-
case ts.SyntaxKind.PropertySignature:
|
|
65
|
-
if (currentStructure instanceof Interface) {
|
|
66
|
-
const interfaceDeclaration = node.parent;
|
|
67
|
-
if (currentStructure.name !== interfaceDeclaration.name.escapedText.toString()) {
|
|
68
|
-
// skip if property if for a another interface than the one we're interested in.
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
// define a property of an interface
|
|
72
|
-
const property = new Property();
|
|
73
|
-
property.name = node.name.escapedText.toString();
|
|
74
|
-
property.type = node.type.getText();
|
|
75
|
-
currentStructure.addProperty(property);
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
case ts.SyntaxKind.Identifier:
|
|
79
|
-
if (node.getText() === "deprecated" &&
|
|
80
|
-
node.parent.kind !== ts.SyntaxKind.ImportSpecifier) {
|
|
81
|
-
currentProperty = new Property();
|
|
82
|
-
currentProperty.deprecated = true;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
if (node.getText() === decoratorName) {
|
|
86
|
-
const prop = node.parent?.parent?.parent;
|
|
87
|
-
const propDecorator = getDecorators(prop);
|
|
88
|
-
const hasExpression = prop?.expression?.arguments;
|
|
89
|
-
const hasDecorator = (propDecorator?.length > 0);
|
|
90
|
-
/**
|
|
91
|
-
* neither a `@type()` decorator or `type()` call. skip.
|
|
92
|
-
*/
|
|
93
|
-
if (!hasDecorator && !hasExpression) {
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
// using as decorator
|
|
97
|
-
if (propDecorator) {
|
|
98
|
-
/**
|
|
99
|
-
* Calling `@type()` as decorator
|
|
100
|
-
*/
|
|
101
|
-
const typeDecorator = propDecorator.find((decorator => {
|
|
102
|
-
return decorator.expression.expression.escapedText === decoratorName;
|
|
103
|
-
})).expression;
|
|
104
|
-
const property = currentProperty || new Property();
|
|
105
|
-
property.name = prop.name.escapedText;
|
|
106
|
-
currentStructure.addProperty(property);
|
|
107
|
-
const typeArgument = typeDecorator.arguments[0];
|
|
108
|
-
defineProperty(property, typeArgument);
|
|
109
|
-
}
|
|
110
|
-
else if (prop.expression.arguments?.[1] &&
|
|
111
|
-
prop.expression.expression.arguments?.[0]) {
|
|
112
|
-
/**
|
|
113
|
-
* Calling `type()` as a regular method
|
|
114
|
-
*/
|
|
115
|
-
const property = currentProperty || new Property();
|
|
116
|
-
property.name = prop.expression.arguments[1].text;
|
|
117
|
-
currentStructure.addProperty(property);
|
|
118
|
-
const typeArgument = prop.expression.expression.arguments[0];
|
|
119
|
-
defineProperty(property, typeArgument);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else if (node.getText() === "setFields" &&
|
|
123
|
-
(node.parent.kind === ts.SyntaxKind.CallExpression ||
|
|
124
|
-
node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)) {
|
|
125
|
-
/**
|
|
126
|
-
* Metadata.setFields(klassName, { ... })
|
|
127
|
-
*/
|
|
128
|
-
const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)
|
|
129
|
-
? node.parent.parent
|
|
130
|
-
: node.parent;
|
|
131
|
-
/**
|
|
132
|
-
* Skip if @codegen-ignore comment is found before the call expression
|
|
133
|
-
* TODO: currently, if @codegen-ignore is on the file, it will skip all the setFields calls.
|
|
134
|
-
*/
|
|
135
|
-
const sourceFile = node.getSourceFile();
|
|
136
|
-
const fullText = sourceFile.getFullText();
|
|
137
|
-
const nodeStart = callExpression.getFullStart();
|
|
138
|
-
const textBeforeNode = fullText.substring(0, nodeStart);
|
|
139
|
-
if (textBeforeNode.includes('@codegen-ignore')) {
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
if (callExpression.kind !== ts.SyntaxKind.CallExpression) {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
const classNameNode = callExpression.arguments[0];
|
|
146
|
-
const className = ts.isClassExpression(classNameNode)
|
|
147
|
-
? classNameNode.name?.escapedText.toString()
|
|
148
|
-
: classNameNode.getText();
|
|
149
|
-
// skip if no className is provided
|
|
150
|
-
if (!className) {
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
if (currentStructure?.name !== className) {
|
|
154
|
-
currentStructure = new Class();
|
|
155
|
-
}
|
|
156
|
-
context.addStructure(currentStructure);
|
|
157
|
-
currentStructure.extends = "Schema"; // force extends to Schema
|
|
158
|
-
currentStructure.name = className;
|
|
159
|
-
const types = callExpression.arguments[1];
|
|
160
|
-
for (let i = 0; i < types.properties.length; i++) {
|
|
161
|
-
const prop = types.properties[i];
|
|
162
|
-
const property = currentProperty || new Property();
|
|
163
|
-
property.name = prop.name.escapedText;
|
|
164
|
-
currentStructure.addProperty(property);
|
|
165
|
-
defineProperty(property, prop.initializer);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
else if (node.getText() === "defineTypes" &&
|
|
169
|
-
(node.parent.kind === ts.SyntaxKind.CallExpression ||
|
|
170
|
-
node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)) {
|
|
171
|
-
/**
|
|
172
|
-
* JavaScript source file (`.js`)
|
|
173
|
-
* Using `defineTypes()`
|
|
174
|
-
*/
|
|
175
|
-
const callExpression = (node.parent.kind === ts.SyntaxKind.PropertyAccessExpression)
|
|
176
|
-
? node.parent.parent
|
|
177
|
-
: node.parent;
|
|
178
|
-
if (callExpression.kind !== ts.SyntaxKind.CallExpression) {
|
|
179
|
-
break;
|
|
180
|
-
}
|
|
181
|
-
const className = callExpression.arguments[0].getText();
|
|
182
|
-
currentStructure.name = className;
|
|
183
|
-
const types = callExpression.arguments[1];
|
|
184
|
-
for (let i = 0; i < types.properties.length; i++) {
|
|
185
|
-
const prop = types.properties[i];
|
|
186
|
-
const property = currentProperty || new Property();
|
|
187
|
-
property.name = prop.name.escapedText;
|
|
188
|
-
currentStructure.addProperty(property);
|
|
189
|
-
defineProperty(property, prop.initializer);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
if (node.parent.kind === ts.SyntaxKind.ClassDeclaration) {
|
|
193
|
-
currentStructure.name = node.getText();
|
|
194
|
-
}
|
|
195
|
-
currentProperty = undefined;
|
|
196
|
-
break;
|
|
197
|
-
case ts.SyntaxKind.CallExpression:
|
|
198
|
-
/**
|
|
199
|
-
* Defining schema via `schema.schema({ ... })`
|
|
200
|
-
* - schema.schema({})
|
|
201
|
-
* - schema({})
|
|
202
|
-
* - ClassName.extends({})
|
|
203
|
-
*/
|
|
204
|
-
if (((node.expression?.getText() === "schema.schema" ||
|
|
205
|
-
node.expression?.getText() === "schema") ||
|
|
206
|
-
(node.expression?.getText().indexOf(".extends") !== -1)) &&
|
|
207
|
-
node.arguments[0].kind === ts.SyntaxKind.ObjectLiteralExpression) {
|
|
208
|
-
const callExpression = node;
|
|
209
|
-
let className = callExpression.arguments[1]?.getText();
|
|
210
|
-
if (!className && callExpression.parent.kind === ts.SyntaxKind.VariableDeclaration) {
|
|
211
|
-
className = callExpression.parent.name?.getText();
|
|
212
|
-
}
|
|
213
|
-
// skip if no className is provided
|
|
214
|
-
if (!className) {
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
if (currentStructure?.name !== className) {
|
|
218
|
-
currentStructure = new Class();
|
|
219
|
-
context.addStructure(currentStructure);
|
|
220
|
-
}
|
|
221
|
-
if (node.expression?.getText().indexOf(".extends") !== -1) {
|
|
222
|
-
// if it's using `.extends({})`
|
|
223
|
-
const extendsClass = node.expression?.expression?.escapedText;
|
|
224
|
-
// skip if no extendsClass is provided
|
|
225
|
-
if (!extendsClass) {
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
currentStructure.extends = extendsClass;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
// if it's using `schema({})`
|
|
232
|
-
currentStructure.extends = "Schema"; // force extends to Schema
|
|
233
|
-
}
|
|
234
|
-
currentStructure.name = className;
|
|
235
|
-
const types = callExpression.arguments[0];
|
|
236
|
-
for (let i = 0; i < types.properties.length; i++) {
|
|
237
|
-
const prop = types.properties[i];
|
|
238
|
-
const property = currentProperty || new Property();
|
|
239
|
-
property.name = prop.name.escapedText;
|
|
240
|
-
currentStructure.addProperty(property);
|
|
241
|
-
defineProperty(property, prop.initializer);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
break;
|
|
245
|
-
case ts.SyntaxKind.EnumMember:
|
|
246
|
-
if (currentStructure instanceof Enum) {
|
|
247
|
-
const initializer = node.initializer?.text;
|
|
248
|
-
const name = node.getFirstToken().getText();
|
|
249
|
-
const property = currentProperty || new Property();
|
|
250
|
-
property.name = name;
|
|
251
|
-
if (initializer !== undefined) {
|
|
252
|
-
property.type = initializer;
|
|
253
|
-
}
|
|
254
|
-
currentStructure.addProperty(property);
|
|
255
|
-
currentProperty = undefined;
|
|
256
|
-
}
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
ts.forEachChild(node, (n) => inspectNode(n, context, decoratorName));
|
|
260
|
-
}
|
|
261
|
-
let parsedFiles;
|
|
262
|
-
export function parseFiles(fileNames, decoratorName = "type", context = new Context()) {
|
|
263
|
-
/**
|
|
264
|
-
* Re-set globalContext for each test case
|
|
265
|
-
*/
|
|
266
|
-
if (globalContext !== context) {
|
|
267
|
-
parsedFiles = {};
|
|
268
|
-
globalContext = context;
|
|
269
|
-
}
|
|
270
|
-
fileNames.forEach((fileName) => {
|
|
271
|
-
let sourceFile;
|
|
272
|
-
let sourceFileName;
|
|
273
|
-
const fileNameAlternatives = [];
|
|
274
|
-
if (!fileName.endsWith(".ts") &&
|
|
275
|
-
!fileName.endsWith(".js") &&
|
|
276
|
-
!fileName.endsWith(".mjs")) {
|
|
277
|
-
fileNameAlternatives.push(`${fileName}.ts`);
|
|
278
|
-
fileNameAlternatives.push(`${fileName}/index.ts`);
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
fileNameAlternatives.push(fileName);
|
|
282
|
-
}
|
|
283
|
-
for (let i = 0; i < fileNameAlternatives.length; i++) {
|
|
284
|
-
try {
|
|
285
|
-
sourceFileName = path.resolve(fileNameAlternatives[i]);
|
|
286
|
-
if (parsedFiles[sourceFileName]) {
|
|
287
|
-
break;
|
|
288
|
-
}
|
|
289
|
-
sourceFile = ts.createSourceFile(sourceFileName, readFileSync(sourceFileName).toString(), ts.ScriptTarget.Latest, true);
|
|
290
|
-
parsedFiles[sourceFileName] = true;
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
catch (e) {
|
|
294
|
-
// console.log(`${fileNameAlternatives[i]} => ${e.message}`);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (sourceFile) {
|
|
298
|
-
inspectNode(sourceFile, context, decoratorName);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
return context.getStructures();
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* TypeScript 4.8+ has introduced a change on how to access decorators.
|
|
305
|
-
* - https://github.com/microsoft/TypeScript/pull/49089
|
|
306
|
-
* - https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees
|
|
307
|
-
*/
|
|
308
|
-
export function getDecorators(node) {
|
|
309
|
-
if (node == undefined) {
|
|
310
|
-
return undefined;
|
|
311
|
-
}
|
|
312
|
-
// TypeScript 4.7 and below
|
|
313
|
-
// @ts-ignore
|
|
314
|
-
if (node.decorators) {
|
|
315
|
-
return node.decorators;
|
|
316
|
-
}
|
|
317
|
-
// TypeScript 4.8 and above
|
|
318
|
-
// @ts-ignore
|
|
319
|
-
if (ts.canHaveDecorators && ts.canHaveDecorators(node)) {
|
|
320
|
-
// @ts-ignore
|
|
321
|
-
const decorators = ts.getDecorators(node);
|
|
322
|
-
return decorators ? Array.from(decorators) : undefined;
|
|
323
|
-
}
|
|
324
|
-
// @ts-ignore
|
|
325
|
-
return node.modifiers?.filter(ts.isDecorator);
|
|
326
|
-
}
|
|
327
|
-
//# sourceMappingURL=parser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/codegen/parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAc,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEhF,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,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;IAEpE,CAAC;S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C,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 /**\n * Skip if @codegen-ignore comment is found before the call expression\n * TODO: currently, if @codegen-ignore is on the file, it will skip all the setFields calls.\n */\n const sourceFile = node.getSourceFile();\n const fullText = sourceFile.getFullText();\n const nodeStart = callExpression.getFullStart();\n const textBeforeNode = fullText.substring(0, nodeStart);\n if (textBeforeNode.includes('@codegen-ignore')) {\n break;\n }\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: ts.Node) => 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"]}
|
package/lib/codegen/types.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
if (typeof (__dirname) === "undefined") {
|
|
4
|
-
global.__dirname = path.dirname(new URL(import.meta.url).pathname);
|
|
5
|
-
}
|
|
6
|
-
const VERSION = JSON.parse(fs.readFileSync(__dirname + "/../../package.json").toString()).version;
|
|
7
|
-
const COMMENT_HEADER = `
|
|
8
|
-
THIS FILE HAS BEEN GENERATED AUTOMATICALLY
|
|
9
|
-
DO NOT CHANGE IT MANUALLY UNLESS YOU KNOW WHAT YOU'RE DOING
|
|
10
|
-
|
|
11
|
-
GENERATED USING @colyseus/schema ${VERSION}
|
|
12
|
-
`;
|
|
13
|
-
export function getCommentHeader(singleLineComment = "//") {
|
|
14
|
-
return `${COMMENT_HEADER.split("\n").map(line => `${singleLineComment} ${line}`).join("\n")}`;
|
|
15
|
-
}
|
|
16
|
-
export class Context {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.classes = [];
|
|
19
|
-
this.interfaces = [];
|
|
20
|
-
this.enums = [];
|
|
21
|
-
}
|
|
22
|
-
getStructures() {
|
|
23
|
-
return {
|
|
24
|
-
classes: this.classes.filter(klass => {
|
|
25
|
-
if (this.isSchemaClass(klass)) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
let parentClass = klass;
|
|
30
|
-
while (parentClass = this.getParentClass(parentClass)) {
|
|
31
|
-
if (this.isSchemaClass(parentClass)) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}),
|
|
38
|
-
interfaces: this.interfaces,
|
|
39
|
-
enums: this.enums,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
addStructure(structure) {
|
|
43
|
-
if (structure.context === this) {
|
|
44
|
-
return;
|
|
45
|
-
} // skip if already added.
|
|
46
|
-
structure.context = this;
|
|
47
|
-
if (structure instanceof Class) {
|
|
48
|
-
this.classes.push(structure);
|
|
49
|
-
}
|
|
50
|
-
else if (structure instanceof Interface) {
|
|
51
|
-
this.interfaces.push(structure);
|
|
52
|
-
}
|
|
53
|
-
else if (structure instanceof Enum) {
|
|
54
|
-
this.enums.push(structure);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
getParentClass(klass) {
|
|
58
|
-
return this.classes.find(c => c.name === klass.extends);
|
|
59
|
-
}
|
|
60
|
-
isSchemaClass(klass) {
|
|
61
|
-
let isSchema = false;
|
|
62
|
-
let currentClass = klass;
|
|
63
|
-
while (!isSchema && currentClass) {
|
|
64
|
-
//
|
|
65
|
-
// TODO: ideally we should check for actual @colyseus/schema module
|
|
66
|
-
// reference rather than arbitrary strings.
|
|
67
|
-
//
|
|
68
|
-
isSchema = (currentClass.extends === "Schema" ||
|
|
69
|
-
currentClass.extends === "schema.Schema" ||
|
|
70
|
-
currentClass.extends === "Schema.Schema");
|
|
71
|
-
//
|
|
72
|
-
// When extending from `schema.Schema`, it is required to
|
|
73
|
-
// normalize as "Schema" for code generation.
|
|
74
|
-
//
|
|
75
|
-
if (currentClass === klass && isSchema) {
|
|
76
|
-
klass.extends = "Schema";
|
|
77
|
-
}
|
|
78
|
-
currentClass = this.getParentClass(currentClass);
|
|
79
|
-
}
|
|
80
|
-
return isSchema;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export class Interface {
|
|
84
|
-
constructor() {
|
|
85
|
-
this.properties = [];
|
|
86
|
-
}
|
|
87
|
-
addProperty(property) {
|
|
88
|
-
if (property.type.indexOf("[]") >= 0) {
|
|
89
|
-
// is array!
|
|
90
|
-
property.childType = property.type.match(/([^\[]+)/i)[1];
|
|
91
|
-
property.type = "array";
|
|
92
|
-
this.properties.push(property);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this.properties.push(property);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
export class Class {
|
|
100
|
-
constructor() {
|
|
101
|
-
this.properties = [];
|
|
102
|
-
}
|
|
103
|
-
addProperty(property) {
|
|
104
|
-
property.index = this.properties.length;
|
|
105
|
-
this.properties.push(property);
|
|
106
|
-
}
|
|
107
|
-
postProcessing() {
|
|
108
|
-
/**
|
|
109
|
-
* Ensure the proprierties `index` are correct using inheritance
|
|
110
|
-
*/
|
|
111
|
-
let parentKlass = this;
|
|
112
|
-
while (parentKlass &&
|
|
113
|
-
(parentKlass = this.context.classes.find(k => k.name === parentKlass.extends))) {
|
|
114
|
-
this.properties.forEach(prop => {
|
|
115
|
-
prop.index += parentKlass.properties.length;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
export class Enum {
|
|
121
|
-
constructor() {
|
|
122
|
-
this.properties = [];
|
|
123
|
-
}
|
|
124
|
-
addProperty(property) {
|
|
125
|
-
this.properties.push(property);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
export class Property {
|
|
129
|
-
}
|
|
130
|
-
export function getInheritanceTree(klass, allClasses, includeSelf = true) {
|
|
131
|
-
let currentClass = klass;
|
|
132
|
-
let inheritanceTree = [];
|
|
133
|
-
if (includeSelf) {
|
|
134
|
-
inheritanceTree.push(currentClass);
|
|
135
|
-
}
|
|
136
|
-
while (currentClass.extends !== "Schema") {
|
|
137
|
-
currentClass = allClasses.find(klass => klass.name == currentClass.extends);
|
|
138
|
-
inheritanceTree.push(currentClass);
|
|
139
|
-
}
|
|
140
|
-
return inheritanceTree;
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=types.js.map
|
package/lib/codegen/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/codegen/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,IAAI,OAAM,CAAC,SAAS,CAAC,KAAK,WAAW,EAAE,CAAC;IACpC,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;AACvE,CAAC;AAED,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,MAAM,UAAU,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,MAAM,OAAO,OA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G,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","sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\n\nif (typeof(__dirname) === \"undefined\") {\n global.__dirname = path.dirname(new URL(import.meta.url).pathname);\n}\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): void;\n}\n\nexport class Interface implements IStructure {\n context: Context;\n name: string;\n properties: Property[] = [];\n\n addProperty(property: Property): void {\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"]}
|