xml-model 1.2.0 → 1.3.1

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 (131) hide show
  1. package/README.md +0 -1
  2. package/dist/_virtual/Reflect.js +8 -0
  3. package/dist/_virtual/Reflect2.js +5 -0
  4. package/{vite/dist → dist}/_virtual/_commonjsHelpers.js +10 -4
  5. package/dist/defaults.d.ts +1 -0
  6. package/dist/errors.d.ts +1 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/middleware.d.ts +1 -0
  9. package/dist/model/built-ins.d.ts +1 -0
  10. package/dist/model/index.d.ts +1 -0
  11. package/dist/model/index.js +1 -0
  12. package/dist/model/property.d.ts +1 -0
  13. package/dist/model/registry.d.ts +1 -0
  14. package/dist/model/types.d.ts +1 -0
  15. package/dist/node_modules/reflect-metadata/Reflect.js +867 -0
  16. package/dist/types.d.ts +1 -0
  17. package/dist/util/is-regexp.d.ts +1 -0
  18. package/dist/util/kebab-case.d.ts +1 -0
  19. package/dist/util/merge-maps.d.ts +1 -0
  20. package/dist/xml/index.d.ts +1 -0
  21. package/dist/xml/xml-js.d.ts +1 -0
  22. package/package.json +4 -4
  23. package/vite/dist/index.js +2 -3
  24. package/vite/dist/node_modules/typescript-rtti/dist.esm/common/format.js +105 -0
  25. package/vite/dist/node_modules/typescript-rtti/dist.esm/common/index.js +55 -0
  26. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/api-call-transformer.js +152 -0
  27. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/class-analyzer.js +83 -0
  28. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/compile-error.js +8 -0
  29. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/import-analyzer.js +89 -0
  30. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/interface-analyzer.js +58 -0
  31. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/common/visitor-base.js +93 -0
  32. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/declarations-emitter.js +31 -0
  33. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/encode-parameter.js +64 -0
  34. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/find-relative-path.js +41 -0
  35. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/flags.js +43 -0
  36. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/forward-ref.js +20 -0
  37. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/get-exports-for-symbol.js +64 -0
  38. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/index.js +130 -0
  39. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/legacy-decorator.js +10 -0
  40. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/legacy-type-encoder.js +82 -0
  41. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/literal-node.js +9 -0
  42. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-collector.js +56 -0
  43. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-decorator.js +80 -0
  44. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-emitter.js +425 -0
  45. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/metadata-encoder.js +212 -0
  46. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/rt-helper.js +96 -0
  47. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/rtti-visitor-base.js +28 -0
  48. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/serialize.js +31 -0
  49. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/type-encoder.js +76 -0
  50. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/type-literal.js +499 -0
  51. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/utils.js +906 -0
  52. package/vite/dist/node_modules/typescript-rtti/dist.esm/transformer/workarounds.js +7 -0
  53. package/vite/dist/src/class-names.test.d.ts +9 -0
  54. package/vite/dist/src/defaults.d.ts +15 -0
  55. package/vite/dist/src/errors.d.ts +24 -0
  56. package/vite/dist/src/index.d.ts +8 -0
  57. package/vite/dist/src/middleware.d.ts +10 -0
  58. package/vite/dist/src/model/built-ins.d.ts +3 -0
  59. package/vite/dist/src/model/index.d.ts +21 -0
  60. package/vite/dist/src/model/property.d.ts +6 -0
  61. package/vite/dist/src/model/registry.d.ts +9 -0
  62. package/vite/dist/src/model/types.d.ts +74 -0
  63. package/vite/dist/src/model.test.d.ts +2 -0
  64. package/vite/dist/src/types.d.ts +17 -0
  65. package/vite/dist/src/util/is-regexp.d.ts +12 -0
  66. package/vite/dist/src/util/kebab-case.d.ts +16 -0
  67. package/vite/dist/src/util/merge-maps.d.ts +2 -0
  68. package/vite/dist/src/xml/index.d.ts +33 -0
  69. package/vite/dist/src/xml/xml-js.d.ts +7 -0
  70. package/vite/dist/_virtual/_commonjs-dynamic-modules.js +0 -7
  71. package/vite/dist/_virtual/_typescript.js +0 -5
  72. package/vite/dist/_virtual/api-call-transformer.js +0 -5
  73. package/vite/dist/_virtual/class-analyzer.js +0 -5
  74. package/vite/dist/_virtual/compile-error.js +0 -5
  75. package/vite/dist/_virtual/declarations-emitter.js +0 -5
  76. package/vite/dist/_virtual/encode-parameter.js +0 -5
  77. package/vite/dist/_virtual/find-relative-path.js +0 -5
  78. package/vite/dist/_virtual/flags.js +0 -5
  79. package/vite/dist/_virtual/format.js +0 -5
  80. package/vite/dist/_virtual/forward-ref.js +0 -5
  81. package/vite/dist/_virtual/get-exports-for-symbol.js +0 -5
  82. package/vite/dist/_virtual/import-analyzer.js +0 -5
  83. package/vite/dist/_virtual/index.js +0 -8
  84. package/vite/dist/_virtual/index2.js +0 -5
  85. package/vite/dist/_virtual/index3.js +0 -5
  86. package/vite/dist/_virtual/interface-analyzer.js +0 -5
  87. package/vite/dist/_virtual/legacy-decorator.js +0 -5
  88. package/vite/dist/_virtual/legacy-type-encoder.js +0 -5
  89. package/vite/dist/_virtual/literal-node.js +0 -5
  90. package/vite/dist/_virtual/metadata-collector.js +0 -5
  91. package/vite/dist/_virtual/metadata-decorator.js +0 -5
  92. package/vite/dist/_virtual/metadata-emitter.js +0 -5
  93. package/vite/dist/_virtual/metadata-encoder.js +0 -5
  94. package/vite/dist/_virtual/rt-helper.js +0 -5
  95. package/vite/dist/_virtual/rtti-visitor-base.js +0 -5
  96. package/vite/dist/_virtual/serialize.js +0 -5
  97. package/vite/dist/_virtual/type-encoder.js +0 -5
  98. package/vite/dist/_virtual/type-literal.js +0 -5
  99. package/vite/dist/_virtual/utils.js +0 -5
  100. package/vite/dist/_virtual/visitor-base.js +0 -5
  101. package/vite/dist/_virtual/workarounds.js +0 -5
  102. package/vite/dist/index.d.ts +0 -28
  103. package/vite/dist/node_modules/typescript-rtti/dist/common/format.js +0 -69
  104. package/vite/dist/node_modules/typescript-rtti/dist/common/index.js +0 -34
  105. package/vite/dist/node_modules/typescript-rtti/dist/transformer/api-call-transformer.js +0 -197
  106. package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/class-analyzer.js +0 -124
  107. package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/compile-error.js +0 -18
  108. package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/import-analyzer.js +0 -130
  109. package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/interface-analyzer.js +0 -98
  110. package/vite/dist/node_modules/typescript-rtti/dist/transformer/common/visitor-base.js +0 -132
  111. package/vite/dist/node_modules/typescript-rtti/dist/transformer/declarations-emitter.js +0 -72
  112. package/vite/dist/node_modules/typescript-rtti/dist/transformer/encode-parameter.js +0 -110
  113. package/vite/dist/node_modules/typescript-rtti/dist/transformer/find-relative-path.js +0 -51
  114. package/vite/dist/node_modules/typescript-rtti/dist/transformer/flags.js +0 -59
  115. package/vite/dist/node_modules/typescript-rtti/dist/transformer/forward-ref.js +0 -35
  116. package/vite/dist/node_modules/typescript-rtti/dist/transformer/get-exports-for-symbol.js +0 -75
  117. package/vite/dist/node_modules/typescript-rtti/dist/transformer/index.js +0 -174
  118. package/vite/dist/node_modules/typescript-rtti/dist/transformer/legacy-decorator.js +0 -20
  119. package/vite/dist/node_modules/typescript-rtti/dist/transformer/legacy-type-encoder.js +0 -123
  120. package/vite/dist/node_modules/typescript-rtti/dist/transformer/literal-node.js +0 -19
  121. package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-collector.js +0 -96
  122. package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-decorator.js +0 -99
  123. package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-emitter.js +0 -475
  124. package/vite/dist/node_modules/typescript-rtti/dist/transformer/metadata-encoder.js +0 -261
  125. package/vite/dist/node_modules/typescript-rtti/dist/transformer/rt-helper.js +0 -113
  126. package/vite/dist/node_modules/typescript-rtti/dist/transformer/rtti-visitor-base.js +0 -39
  127. package/vite/dist/node_modules/typescript-rtti/dist/transformer/serialize.js +0 -46
  128. package/vite/dist/node_modules/typescript-rtti/dist/transformer/type-encoder.js +0 -96
  129. package/vite/dist/node_modules/typescript-rtti/dist/transformer/type-literal.js +0 -546
  130. package/vite/dist/node_modules/typescript-rtti/dist/transformer/utils.js +0 -922
  131. package/vite/dist/node_modules/typescript-rtti/dist/transformer/workarounds.js +0 -16
package/dist/types.d.ts CHANGED
@@ -14,3 +14,4 @@ export interface XMLElement {
14
14
  export type XMLRoot = {
15
15
  elements: XMLElement[];
16
16
  };
17
+ //# sourceMappingURL=types.d.ts.map
@@ -9,3 +9,4 @@
9
9
  */
10
10
  export declare function isRegExp(value: unknown): value is RegExp;
11
11
  export default isRegExp;
12
+ //# sourceMappingURL=is-regexp.d.ts.map
@@ -13,3 +13,4 @@
13
13
  * @returns The kebab-cased string
14
14
  */
15
15
  export declare function kebabCase(str: string, keepLeadingDash?: boolean): string;
16
+ //# sourceMappingURL=kebab-case.d.ts.map
@@ -1 +1,2 @@
1
1
  export default function mergeMaps<K, V>(...sources: Map<K, V>[]): Map<K, V>;
2
+ //# sourceMappingURL=merge-maps.d.ts.map
@@ -30,3 +30,4 @@ declare const XML: {
30
30
  deleteAttribute: typeof deleteAttribute;
31
31
  };
32
32
  export default XML;
33
+ //# sourceMappingURL=index.d.ts.map
@@ -4,3 +4,4 @@ declare const _default: {
4
4
  stringify: typeof stringify;
5
5
  };
6
6
  export default _default;
7
+ //# sourceMappingURL=xml-js.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xml-model",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "allows transparent XML <-> Object conversion in typescript",
5
5
  "license": "MIT",
6
6
  "author": "MathisTLD",
@@ -34,6 +34,7 @@
34
34
  "prepare": "husky"
35
35
  },
36
36
  "dependencies": {
37
+ "typescript-rtti": "0.9.6",
37
38
  "xml-js": "^1.6.11"
38
39
  },
39
40
  "devDependencies": {
@@ -44,15 +45,14 @@
44
45
  "marmotte": "^0.1.4",
45
46
  "oxfmt": "^0.28.0",
46
47
  "oxlint": "^1.43.0",
48
+ "reflect-metadata": "^0.1.14",
47
49
  "typescript": "*",
48
50
  "vite": "*",
49
51
  "vitest": "^4.0.18"
50
52
  },
51
53
  "peerDependencies": {
52
54
  "@rollup/plugin-typescript": "^12.3.0",
53
- "reflect-metadata": "^0.1.14",
54
- "typescript": "^5.1.0",
55
- "typescript-rtti": "^0.9.6",
55
+ "typescript": "~5.1.6",
56
56
  "vite": "^7.3.1"
57
57
  },
58
58
  "peerDependenciesMeta": {
@@ -1,6 +1,5 @@
1
1
  import typescript from "@rollup/plugin-typescript";
2
- import _rtti from "./_virtual/index.js";
3
- const rtti = "default" in _rtti ? _rtti.default : _rtti;
2
+ import transformer from "./node_modules/typescript-rtti/dist.esm/transformer/index.js";
4
3
  function FixClassNames() {
5
4
  return {
6
5
  name: "fix-class-names",
@@ -33,7 +32,7 @@ function TypescriptRTTI(options = {}) {
33
32
  type: "program",
34
33
  factory: (program) => {
35
34
  if (debug) console.debug("[RTTI] Transformer is running!");
36
- const transformerFactory = rtti(program);
35
+ const transformerFactory = transformer(program);
37
36
  return (context) => {
38
37
  const transform = transformerFactory(context);
39
38
  return (source) => {
@@ -0,0 +1,105 @@
1
+ import { createRequire } from "node:module";
2
+ const require$1 = createRequire(import.meta.url);
3
+ const F_READONLY = "R";
4
+ const F_ABSTRACT = "A";
5
+ const F_PUBLIC = "$";
6
+ const F_PRIVATE = "#";
7
+ const F_PROTECTED = "@";
8
+ const F_PROPERTY = "P";
9
+ const F_METHOD = "M";
10
+ const F_STATIC = "S";
11
+ const F_CLASS = "C";
12
+ const F_INTERFACE = "I";
13
+ const F_FUNCTION = "F";
14
+ const F_ARROW_FUNCTION = ">";
15
+ const F_OPTIONAL = "?";
16
+ const F_REST = "3";
17
+ const F_ASYNC = "a";
18
+ const F_EXPORTED = "e";
19
+ const F_INFERRED = ".";
20
+ const F_OMITTED = ",";
21
+ const F_ARRAY_BINDING = "[";
22
+ const F_OBJECT_BINDING = "O";
23
+ const T_UNION = "|";
24
+ const T_INTERSECTION = "&";
25
+ const T_ANY = "~";
26
+ const T_UNKNOWN = "U";
27
+ const T_VOID = "V";
28
+ const T_UNDEFINED = "u";
29
+ const T_NULL = "n";
30
+ const T_TUPLE = "T";
31
+ const T_ARRAY = "[";
32
+ const T_THIS = "t";
33
+ const T_GENERIC = "g";
34
+ const T_MAPPED = "m";
35
+ const T_TRUE = "1";
36
+ const T_FALSE = "0";
37
+ const T_CALLSITE = "c";
38
+ const T_STAND_IN = "5";
39
+ const T_OBJECT = "O";
40
+ const T_ENUM = "e";
41
+ const T_FUNCTION = "F";
42
+ const T_INTRINSICS = [T_VOID, T_ANY, T_UNKNOWN, T_UNDEFINED, T_TRUE, T_FALSE, T_THIS, T_NULL];
43
+ const TI_VOID = { TΦ: T_VOID };
44
+ const TI_ANY = { TΦ: T_ANY };
45
+ const TI_UNKNOWN = { TΦ: T_UNKNOWN };
46
+ const TI_UNDEFINED = { TΦ: T_UNDEFINED };
47
+ const TI_TRUE = { TΦ: T_TRUE };
48
+ const TI_FALSE = { TΦ: T_FALSE };
49
+ const TI_THIS = { TΦ: T_THIS };
50
+ const TI_NULL = { TΦ: T_NULL };
51
+ function isLiteralNode(node) {
52
+ return !!node["$__isTSNode"];
53
+ }
54
+ export {
55
+ F_ABSTRACT,
56
+ F_ARRAY_BINDING,
57
+ F_ARROW_FUNCTION,
58
+ F_ASYNC,
59
+ F_CLASS,
60
+ F_EXPORTED,
61
+ F_FUNCTION,
62
+ F_INFERRED,
63
+ F_INTERFACE,
64
+ F_METHOD,
65
+ F_OBJECT_BINDING,
66
+ F_OMITTED,
67
+ F_OPTIONAL,
68
+ F_PRIVATE,
69
+ F_PROPERTY,
70
+ F_PROTECTED,
71
+ F_PUBLIC,
72
+ F_READONLY,
73
+ F_REST,
74
+ F_STATIC,
75
+ TI_ANY,
76
+ TI_FALSE,
77
+ TI_NULL,
78
+ TI_THIS,
79
+ TI_TRUE,
80
+ TI_UNDEFINED,
81
+ TI_UNKNOWN,
82
+ TI_VOID,
83
+ T_ANY,
84
+ T_ARRAY,
85
+ T_CALLSITE,
86
+ T_ENUM,
87
+ T_FALSE,
88
+ T_FUNCTION,
89
+ T_GENERIC,
90
+ T_INTERSECTION,
91
+ T_INTRINSICS,
92
+ T_MAPPED,
93
+ T_NULL,
94
+ T_OBJECT,
95
+ T_STAND_IN,
96
+ T_THIS,
97
+ T_TRUE,
98
+ T_TUPLE,
99
+ T_UNDEFINED,
100
+ T_UNION,
101
+ T_UNKNOWN,
102
+ T_VOID,
103
+ isLiteralNode
104
+ };
105
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1,55 @@
1
+ import { createRequire } from "node:module";
2
+ import { F_ABSTRACT, F_ARRAY_BINDING, F_ARROW_FUNCTION, F_ASYNC, F_CLASS, F_EXPORTED, F_FUNCTION, F_INFERRED, F_INTERFACE, F_METHOD, F_OBJECT_BINDING, F_OMITTED, F_OPTIONAL, F_PRIVATE, F_PROPERTY, F_PROTECTED, F_PUBLIC, F_READONLY, F_REST, F_STATIC, TI_ANY, TI_FALSE, TI_NULL, TI_THIS, TI_TRUE, TI_UNDEFINED, TI_UNKNOWN, TI_VOID, T_ANY, T_ARRAY, T_CALLSITE, T_ENUM, T_FALSE, T_FUNCTION, T_GENERIC, T_INTERSECTION, T_INTRINSICS, T_MAPPED, T_NULL, T_OBJECT, T_STAND_IN, T_THIS, T_TRUE, T_TUPLE, T_UNDEFINED, T_UNION, T_UNKNOWN, T_VOID, isLiteralNode } from "./format.js";
3
+ const require$1 = createRequire(import.meta.url);
4
+ export {
5
+ F_ABSTRACT,
6
+ F_ARRAY_BINDING,
7
+ F_ARROW_FUNCTION,
8
+ F_ASYNC,
9
+ F_CLASS,
10
+ F_EXPORTED,
11
+ F_FUNCTION,
12
+ F_INFERRED,
13
+ F_INTERFACE,
14
+ F_METHOD,
15
+ F_OBJECT_BINDING,
16
+ F_OMITTED,
17
+ F_OPTIONAL,
18
+ F_PRIVATE,
19
+ F_PROPERTY,
20
+ F_PROTECTED,
21
+ F_PUBLIC,
22
+ F_READONLY,
23
+ F_REST,
24
+ F_STATIC,
25
+ TI_ANY,
26
+ TI_FALSE,
27
+ TI_NULL,
28
+ TI_THIS,
29
+ TI_TRUE,
30
+ TI_UNDEFINED,
31
+ TI_UNKNOWN,
32
+ TI_VOID,
33
+ T_ANY,
34
+ T_ARRAY,
35
+ T_CALLSITE,
36
+ T_ENUM,
37
+ T_FALSE,
38
+ T_FUNCTION,
39
+ T_GENERIC,
40
+ T_INTERSECTION,
41
+ T_INTRINSICS,
42
+ T_MAPPED,
43
+ T_NULL,
44
+ T_OBJECT,
45
+ T_STAND_IN,
46
+ T_THIS,
47
+ T_TRUE,
48
+ T_TUPLE,
49
+ T_UNDEFINED,
50
+ T_UNION,
51
+ T_UNKNOWN,
52
+ T_VOID,
53
+ isLiteralNode
54
+ };
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,152 @@
1
+ import { Visit } from "./common/visitor-base.js";
2
+ import ts from "typescript";
3
+ import { isStatement, getRttiDocTagFromSignature, hasFlag } from "./utils.js";
4
+ import { RttiVisitor } from "./rtti-visitor-base.js";
5
+ import { serialize } from "./serialize.js";
6
+ import { TypeEncoder } from "./type-encoder.js";
7
+ import { literalNode } from "./literal-node.js";
8
+ import { createRequire } from "node:module";
9
+ var __decorate = function(decorators, target, key, desc) {
10
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
11
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
12
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
13
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
14
+ };
15
+ var __metadata = function(k, v) {
16
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
17
+ };
18
+ const require$1 = createRequire(import.meta.url);
19
+ class ApiCallTransformer extends RttiVisitor {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.typeEncoder = new TypeEncoder(this.ctx);
23
+ }
24
+ static transform(node, ctx) {
25
+ let transformer = new ApiCallTransformer(ctx);
26
+ return transformer.visitNode(node);
27
+ }
28
+ everyNode(node) {
29
+ if (isStatement(node) && node.parent && ts.isSourceFile(node.parent)) {
30
+ this.ctx.currentTopStatement = node;
31
+ }
32
+ }
33
+ isRttiCall(expr, name) {
34
+ if (!ts.isIdentifier(expr.expression))
35
+ return false;
36
+ return ts.isIdentifier(expr.expression) && this.isAnyImportedSymbol(this.checker.getSymbolAtLocation(expr.expression), ["typescript-rtti", "./FΦtypescript-rtti", "./FΦtypescript-rtti.js"], name ? [name] : ["reify", "reflect"]);
37
+ }
38
+ isAnyImportedSymbol(symbol, packageName, names) {
39
+ if (!symbol || !names.includes(symbol.name))
40
+ return false;
41
+ return this.isSymbolFromPackage(symbol, packageName);
42
+ }
43
+ isImportedSymbol(symbol, packageName, name) {
44
+ return this.isAnyImportedSymbol(symbol, [packageName], [name]);
45
+ }
46
+ isSymbolFromPackage(symbol, packageNames) {
47
+ let decls = Array.from(symbol.getDeclarations());
48
+ let importSpecifier = decls.find((x) => x.kind === ts.SyntaxKind.ImportSpecifier);
49
+ if (!importSpecifier)
50
+ return false;
51
+ let modSpecifier = importSpecifier.parent.parent.parent.moduleSpecifier;
52
+ if (!ts.isStringLiteral(modSpecifier))
53
+ return false;
54
+ for (let packageName of packageNames) {
55
+ let matches = modSpecifier.text === packageName || modSpecifier.text.match(new RegExp(`^https?:.*/${packageName}/index.js$`)) || modSpecifier.text.match(new RegExp(`^https?:.*/${packageName}/index.ts$`)) || modSpecifier.text.match(new RegExp(`^https?:.*/${packageName}/?$`));
56
+ if (matches)
57
+ return true;
58
+ }
59
+ return false;
60
+ }
61
+ isCallSiteTypeRef(typeNode) {
62
+ if (!typeNode)
63
+ return false;
64
+ if (typeNode.kind === ts.SyntaxKind.TypeReference) {
65
+ let typeRef = typeNode;
66
+ if (!typeRef.typeName)
67
+ return false;
68
+ if (typeRef.typeName.kind === ts.SyntaxKind.Identifier && typeRef.typeName.text === "CallSite") {
69
+ let symbol = this.checker.getSymbolAtLocation(typeRef.typeName);
70
+ return this.isImportedSymbol(symbol, "typescript-rtti", "CallSite");
71
+ }
72
+ }
73
+ return false;
74
+ }
75
+ isCallSiteParameter(param) {
76
+ return !!(param === null || param === void 0 ? void 0 : param.questionToken) && this.isCallSiteTypeRef(param === null || param === void 0 ? void 0 : param.type);
77
+ }
78
+ typeOfParamSymbol(symbol) {
79
+ return this.checker.getTypeOfSymbolAtLocation(symbol, symbol.getDeclarations()[0]);
80
+ }
81
+ callExpr(expr) {
82
+ var _a;
83
+ let signature = this.checker.getResolvedSignature(expr);
84
+ if (!signature) {
85
+ debugger;
86
+ if (globalThis.RTTI_TRACE)
87
+ console.warn(`RTTI: Could not find signature for call expression '${expr.getText()}'`);
88
+ return expr;
89
+ }
90
+ let params = signature.parameters;
91
+ let callSiteArgIndex = params.findIndex((x) => this.isCallSiteParameter(x.valueDeclaration));
92
+ if (callSiteArgIndex < 0) {
93
+ let callSiteArgFromJsDoc = getRttiDocTagFromSignature(signature, "callsite");
94
+ if (callSiteArgFromJsDoc)
95
+ callSiteArgIndex = Number(callSiteArgFromJsDoc);
96
+ }
97
+ if (this.isRttiCall(expr, "reflect") && callSiteArgIndex < 0) {
98
+ callSiteArgIndex = 1;
99
+ } else if (this.isRttiCall(expr, "reify") && callSiteArgIndex < 0) {
100
+ callSiteArgIndex = 0;
101
+ }
102
+ if (callSiteArgIndex >= 0 && callSiteArgIndex >= expr.arguments.length) {
103
+ let args = Array.from(expr.arguments);
104
+ while (callSiteArgIndex > args.length) {
105
+ args.push(ts.factory.createVoidZero());
106
+ }
107
+ args.push(serialize({
108
+ TΦ: "c",
109
+ t: void 0,
110
+ p: expr.arguments.map((x) => literalNode(this.referToType(this.checker.getTypeAtLocation(x)))),
111
+ r: void 0,
112
+ tp: ((_a = expr.typeArguments) !== null && _a !== void 0 ? _a : []).map((x) => literalNode(this.referToType(this.checker.getTypeAtLocation(x))))
113
+ }));
114
+ return ts.factory.updateCallExpression(this.visitEachChild(expr), expr.expression, expr.typeArguments, args);
115
+ } else {
116
+ return this.visitEachChild(expr);
117
+ }
118
+ }
119
+ referToType(type) {
120
+ if (hasFlag(type.flags, ts.TypeFlags.TypeVariable)) {
121
+ let symbol = type.symbol;
122
+ let decl = symbol.declarations[0];
123
+ if (ts.isTypeParameterDeclaration(decl)) {
124
+ let parentDecl = decl.parent;
125
+ if (ts.isFunctionDeclaration(parentDecl) || ts.isArrowFunction(parentDecl) || ts.isMethodDeclaration(parentDecl) || ts.isFunctionExpression(parentDecl)) {
126
+ let typeIndex = parentDecl.typeParameters.findIndex((tp) => this.checker.getTypeAtLocation(tp) === type);
127
+ if (typeIndex >= 0) {
128
+ let callSiteArgIndex = parentDecl.parameters.findIndex((p) => this.isCallSiteParameter(p));
129
+ if (callSiteArgIndex >= 0) {
130
+ let callSiteArg = parentDecl.parameters[callSiteArgIndex];
131
+ if (ts.isIdentifier(callSiteArg.name)) {
132
+ let callSiteName = callSiteArg.name.text;
133
+ return ts.factory.createElementAccessExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(callSiteName), "tp"), typeIndex);
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+ }
140
+ return this.typeEncoder.referToType(type);
141
+ }
142
+ }
143
+ __decorate([
144
+ Visit(ts.SyntaxKind.CallExpression),
145
+ __metadata("design:type", Function),
146
+ __metadata("design:paramtypes", [Object]),
147
+ __metadata("design:returntype", void 0)
148
+ ], ApiCallTransformer.prototype, "callExpr", null);
149
+ export {
150
+ ApiCallTransformer
151
+ };
152
+ //# sourceMappingURL=api-call-transformer.js.map
@@ -0,0 +1,83 @@
1
+ import { VisitorBase, Visit } from "./visitor-base.js";
2
+ import ts from "typescript";
3
+ import { getModifiers } from "../utils.js";
4
+ import { createRequire } from "node:module";
5
+ var __decorate = function(decorators, target, key, desc) {
6
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
8
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
9
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10
+ };
11
+ var __metadata = function(k, v) {
12
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
13
+ };
14
+ const require$1 = createRequire(import.meta.url);
15
+ class ClassAnalyzer extends VisitorBase {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.details = {
19
+ methodNames: [],
20
+ propertyNames: [],
21
+ staticMethodNames: [],
22
+ staticPropertyNames: []
23
+ };
24
+ }
25
+ isStatic(decl) {
26
+ return getModifiers(decl).some((x) => x.kind === ts.SyntaxKind.StaticKeyword);
27
+ }
28
+ static analyze(decl, context) {
29
+ try {
30
+ let analyzer = new ClassAnalyzer(context);
31
+ analyzer.visitEachChild(decl);
32
+ return analyzer.details;
33
+ } catch (e) {
34
+ console.error(`RTTI: During analyzer for class ${decl.name.getText()}: ${e.message}`);
35
+ throw e;
36
+ }
37
+ }
38
+ addItem(list, prop) {
39
+ if (!list.includes(prop))
40
+ list.push(prop);
41
+ }
42
+ property(decl) {
43
+ this.addItem(this.isStatic(decl) ? this.details.staticPropertyNames : this.details.propertyNames, decl.name);
44
+ }
45
+ method(decl) {
46
+ this.addItem(this.isStatic(decl) ? this.details.staticMethodNames : this.details.methodNames, decl.name);
47
+ }
48
+ ctor(decl) {
49
+ for (let param of decl.parameters) {
50
+ let paramModifiers = getModifiers(param);
51
+ let isProperty = paramModifiers && (paramModifiers.some((x) => x.kind === ts.SyntaxKind.PublicKeyword) || paramModifiers.some((x) => x.kind === ts.SyntaxKind.ProtectedKeyword) || paramModifiers.some((x) => x.kind === ts.SyntaxKind.PrivateKeyword) || paramModifiers.some((x) => x.kind === ts.SyntaxKind.ReadonlyKeyword));
52
+ if (isProperty) {
53
+ if (ts.isIdentifier(param.name)) {
54
+ this.addItem(this.details.propertyNames, param.name);
55
+ } else {
56
+ throw new Error(`Unexpected binding name as property in constructor for class ${decl.name.getText()}! Please file a bug!`);
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ __decorate([
63
+ Visit([ts.SyntaxKind.PropertyDeclaration, ts.SyntaxKind.GetAccessor, ts.SyntaxKind.SetAccessor]),
64
+ __metadata("design:type", Function),
65
+ __metadata("design:paramtypes", [Object]),
66
+ __metadata("design:returntype", void 0)
67
+ ], ClassAnalyzer.prototype, "property", null);
68
+ __decorate([
69
+ Visit(ts.SyntaxKind.MethodDeclaration),
70
+ __metadata("design:type", Function),
71
+ __metadata("design:paramtypes", [Object]),
72
+ __metadata("design:returntype", void 0)
73
+ ], ClassAnalyzer.prototype, "method", null);
74
+ __decorate([
75
+ Visit(ts.SyntaxKind.Constructor),
76
+ __metadata("design:type", Function),
77
+ __metadata("design:paramtypes", [Object]),
78
+ __metadata("design:returntype", void 0)
79
+ ], ClassAnalyzer.prototype, "ctor", null);
80
+ export {
81
+ ClassAnalyzer
82
+ };
83
+ //# sourceMappingURL=class-analyzer.js.map
@@ -0,0 +1,8 @@
1
+ import { createRequire } from "node:module";
2
+ const require$1 = createRequire(import.meta.url);
3
+ class CompileError extends Error {
4
+ }
5
+ export {
6
+ CompileError
7
+ };
8
+ //# sourceMappingURL=compile-error.js.map
@@ -0,0 +1,89 @@
1
+ import { Visit } from "./visitor-base.js";
2
+ import ts from "typescript";
3
+ import { RttiVisitor } from "../rtti-visitor-base.js";
4
+ import { createRequire } from "node:module";
5
+ var __decorate = function(decorators, target, key, desc) {
6
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
8
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
9
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
10
+ };
11
+ var __metadata = function(k, v) {
12
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
13
+ };
14
+ const require$1 = createRequire(import.meta.url);
15
+ class ImportAnalyzer extends RttiVisitor {
16
+ static analyze(file, ctx) {
17
+ let analyzer = new ImportAnalyzer(ctx);
18
+ try {
19
+ analyzer.visitEachChild(file);
20
+ } catch (e) {
21
+ console.error(`RTTI: While analyzing imports for file '${file.fileName}': ${e.message}`);
22
+ throw e;
23
+ }
24
+ }
25
+ import(decl) {
26
+ var _a, _b;
27
+ if (decl.importClause) {
28
+ let bindings = decl.importClause.namedBindings;
29
+ if (!bindings) {
30
+ let name = decl.importClause.name.text;
31
+ this.ctx.importMap.set(name, {
32
+ name,
33
+ localName: name,
34
+ refName: name,
35
+ modulePath: decl.moduleSpecifier.text,
36
+ isNamespace: false,
37
+ isDefault: true,
38
+ importDeclaration: decl
39
+ });
40
+ } else if (bindings) {
41
+ if (ts.isNamedImports(bindings)) {
42
+ for (let binding of bindings.elements) {
43
+ this.ctx.importMap.set(binding.name.text, {
44
+ name: binding.name.text,
45
+ symbol: this.checker.getSymbolAtLocation(binding.name),
46
+ localName: `${(_b = (_a = binding.propertyName) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : binding.name.text}Φ`,
47
+ refName: binding.name.text,
48
+ modulePath: decl.moduleSpecifier.text,
49
+ isNamespace: false,
50
+ isDefault: false,
51
+ importDeclaration: decl
52
+ });
53
+ let nameAsInterface = `IΦ${binding.name.text}`;
54
+ this.ctx.importMap.set(nameAsInterface, {
55
+ name: nameAsInterface,
56
+ localName: nameAsInterface,
57
+ refName: nameAsInterface,
58
+ modulePath: decl.moduleSpecifier.text,
59
+ isNamespace: false,
60
+ isDefault: false,
61
+ importDeclaration: decl
62
+ });
63
+ }
64
+ } else if (ts.isNamespaceImport(bindings)) {
65
+ this.ctx.importMap.set(bindings.name.text, {
66
+ name: bindings.name.text,
67
+ localName: `${bindings.name.text}Φ`,
68
+ modulePath: decl.moduleSpecifier.text,
69
+ refName: bindings.name.text,
70
+ isNamespace: true,
71
+ isDefault: false,
72
+ importDeclaration: decl
73
+ });
74
+ bindings.name;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ __decorate([
81
+ Visit(ts.SyntaxKind.ImportDeclaration),
82
+ __metadata("design:type", Function),
83
+ __metadata("design:paramtypes", [Object]),
84
+ __metadata("design:returntype", void 0)
85
+ ], ImportAnalyzer.prototype, "import", null);
86
+ export {
87
+ ImportAnalyzer
88
+ };
89
+ //# sourceMappingURL=import-analyzer.js.map
@@ -0,0 +1,58 @@
1
+ import { VisitorBase, Visit } from "./visitor-base.js";
2
+ import ts from "typescript";
3
+ import { createRequire } from "node:module";
4
+ var __decorate = function(decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ };
10
+ var __metadata = function(k, v) {
11
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
12
+ };
13
+ const require$1 = createRequire(import.meta.url);
14
+ class InterfaceAnalyzer extends VisitorBase {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.details = {
18
+ methodNames: [],
19
+ propertyNames: []
20
+ };
21
+ }
22
+ static analyze(decl, context) {
23
+ try {
24
+ let analyzer = new InterfaceAnalyzer(context);
25
+ analyzer.visitEachChild(decl);
26
+ return analyzer.details;
27
+ } catch (e) {
28
+ console.error(`RTTI: During analyzer for interface ${decl.name.getText()}: ${e.message}`);
29
+ throw e;
30
+ }
31
+ }
32
+ addItem(array, item) {
33
+ if (!array.includes(item))
34
+ array.push(item);
35
+ }
36
+ property(signature) {
37
+ this.addItem(this.details.propertyNames, signature.name);
38
+ }
39
+ method(signature) {
40
+ this.addItem(this.details.methodNames, signature.name);
41
+ }
42
+ }
43
+ __decorate([
44
+ Visit(ts.SyntaxKind.PropertySignature),
45
+ __metadata("design:type", Function),
46
+ __metadata("design:paramtypes", [Object]),
47
+ __metadata("design:returntype", void 0)
48
+ ], InterfaceAnalyzer.prototype, "property", null);
49
+ __decorate([
50
+ Visit(ts.SyntaxKind.MethodSignature),
51
+ __metadata("design:type", Function),
52
+ __metadata("design:paramtypes", [Object]),
53
+ __metadata("design:returntype", void 0)
54
+ ], InterfaceAnalyzer.prototype, "method", null);
55
+ export {
56
+ InterfaceAnalyzer
57
+ };
58
+ //# sourceMappingURL=interface-analyzer.js.map