@lowgular/code-graph 0.0.1 → 0.1.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 (179) hide show
  1. package/bin/cli.js +10 -0
  2. package/code-graph-v2/code.graph.js +37 -0
  3. package/code-graph-v2/config-from-query.js +131 -0
  4. package/code-graph-v2/extractors/extractor.js +27 -0
  5. package/code-graph-v2/extractors/index.js +1 -0
  6. package/code-graph-v2/graph-builder/code-graph.builder.js +49 -0
  7. package/code-graph-v2/graph-builder/index.js +1 -0
  8. package/code-graph-v2/graph-builder/node.processor.js +22 -0
  9. package/{libs/cli/code-graph/src/lib/v2 → code-graph-v2}/graph-builder/relationship.processor.js +11 -35
  10. package/code-graph-v2/graph-builder/type.processor.js +21 -0
  11. package/code-graph-v2/index.js +4 -0
  12. package/code-graph-v2/tools/build-code-graph.tool.js +19 -0
  13. package/code-graph-v2/utils.js +34 -0
  14. package/codegular/index.js +5 -0
  15. package/codegular/node.js +71 -0
  16. package/codegular/program.js +100 -0
  17. package/{libs/core/codegular/src/lib → codegular}/string.js +6 -53
  18. package/{libs/core/codegular/src/lib → codegular}/type-checker.js +3 -40
  19. package/codegular/type.js +356 -0
  20. package/{libs/core/codegular/src/lib → codegular}/utils.js +50 -62
  21. package/cypher/index.js +1 -0
  22. package/{libs/cli/cypher/src → cypher}/lib/executor/condition-evaluator.js +2 -25
  23. package/cypher/lib/executor/executor.js +60 -0
  24. package/cypher/lib/executor/graph.js +0 -0
  25. package/{libs/cli/cypher/src → cypher}/lib/executor/match-engine.js +4 -27
  26. package/{libs/cli/cypher/src → cypher}/lib/executor/pattern-matcher.js +2 -25
  27. package/{libs/cli/cypher/src → cypher}/lib/executor/relationship-navigator.js +2 -25
  28. package/{libs/cli/cypher/src → cypher}/lib/executor/result-formatter.js +37 -31
  29. package/{libs/cli/cypher/src → cypher}/lib/executor/traverse-engine.js +4 -27
  30. package/cypher/lib/executor/utils.js +14 -0
  31. package/cypher/lib/graph.stub.js +38 -0
  32. package/cypher/lib/index.js +32 -0
  33. package/{libs/cli/cypher/src → cypher}/lib/lexer.js +4 -26
  34. package/{libs/cli/cypher/src → cypher}/lib/parser.js +119 -135
  35. package/{libs/cli/cypher/src → cypher}/lib/validator/query-validator.js +12 -32
  36. package/{libs/cli/cypher/src → cypher}/lib/validator/supported-features.config.js +2 -30
  37. package/{libs/cli/cypher/src → cypher}/lib/validator/unsupported-features.config.js +8 -34
  38. package/cypher-cli.js +41 -0
  39. package/infra/code-graph.js +147 -0
  40. package/main.js +0 -43
  41. package/package.json +25 -7
  42. package/resources-cli.js +75 -0
  43. package/run-cli.js +43 -0
  44. package/apps/code-graph/src/main.js +0 -50
  45. package/libs/cli/code-graph/src/index.js +0 -39
  46. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +0 -72
  47. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +0 -68
  48. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +0 -147
  49. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +0 -55
  50. package/libs/cli/code-graph/src/lib/class-declarations/index.js +0 -27
  51. package/libs/cli/code-graph/src/lib/code.graph.factory.js +0 -63
  52. package/libs/cli/code-graph/src/lib/code.graph.js +0 -62
  53. package/libs/cli/code-graph/src/lib/core/core.js +0 -58
  54. package/libs/cli/code-graph/src/lib/core.js +0 -85
  55. package/libs/cli/code-graph/src/lib/decorators/index.js +0 -36
  56. package/libs/cli/code-graph/src/lib/docs/index.js +0 -21
  57. package/libs/cli/code-graph/src/lib/docs/specs.js +0 -36
  58. package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +0 -28
  59. package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +0 -53
  60. package/libs/cli/code-graph/src/lib/method-declarations/index.js +0 -23
  61. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +0 -106
  62. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +0 -56
  63. package/libs/cli/code-graph/src/lib/parameters/index.js +0 -42
  64. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +0 -139
  65. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +0 -104
  66. package/libs/cli/code-graph/src/lib/property-declarations/index.js +0 -25
  67. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +0 -74
  68. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +0 -43
  69. package/libs/cli/code-graph/src/lib/tools/index.js +0 -34
  70. package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +0 -64
  71. package/libs/cli/code-graph/src/lib/types/index.js +0 -99
  72. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +0 -345
  73. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +0 -52
  74. package/libs/cli/code-graph/src/lib/v2/extractors/index.js +0 -23
  75. package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +0 -76
  76. package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +0 -21
  77. package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +0 -48
  78. package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +0 -45
  79. package/libs/cli/code-graph/src/lib/v2/index.js +0 -37
  80. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +0 -220
  81. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +0 -42
  82. package/libs/cli/cypher/src/index.js +0 -25
  83. package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +0 -277
  84. package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +0 -69
  85. package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +0 -105
  86. package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +0 -70
  87. package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +0 -99
  88. package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +0 -125
  89. package/libs/cli/cypher/src/lib/docs/features/index.js +0 -51
  90. package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +0 -50
  91. package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +0 -106
  92. package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +0 -105
  93. package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +0 -143
  94. package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +0 -152
  95. package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +0 -48
  96. package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +0 -65
  97. package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +0 -82
  98. package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +0 -136
  99. package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +0 -187
  100. package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +0 -302
  101. package/libs/cli/cypher/src/lib/docs/prompts.js +0 -36
  102. package/libs/cli/cypher/src/lib/docs/specs.js +0 -181
  103. package/libs/cli/cypher/src/lib/executor/executor.js +0 -83
  104. package/libs/cli/cypher/src/lib/executor/graph.js +0 -15
  105. package/libs/cli/cypher/src/lib/executor/utils.js +0 -37
  106. package/libs/cli/cypher/src/lib/graph.stub.js +0 -63
  107. package/libs/cli/cypher/src/lib/index.js +0 -74
  108. package/libs/cli/shared/src/index.js +0 -53
  109. package/libs/cli/shared/src/lib/admin-token.js +0 -121
  110. package/libs/cli/shared/src/lib/config.js +0 -49
  111. package/libs/cli/shared/src/lib/consts.js +0 -57
  112. package/libs/cli/shared/src/lib/core.js +0 -46
  113. package/libs/cli/shared/src/lib/infrastructure/cli.js +0 -47
  114. package/libs/cli/shared/src/lib/infrastructure/config.js +0 -47
  115. package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +0 -51
  116. package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +0 -96
  117. package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +0 -41
  118. package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +0 -64
  119. package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +0 -120
  120. package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +0 -15
  121. package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +0 -72
  122. package/libs/cli/shared/src/lib/infrastructure/git.js +0 -147
  123. package/libs/cli/shared/src/lib/infrastructure/http.js +0 -257
  124. package/libs/cli/shared/src/lib/infrastructure/markdown.js +0 -95
  125. package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +0 -88
  126. package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +0 -25
  127. package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +0 -154
  128. package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +0 -210
  129. package/libs/cli/shared/src/lib/infrastructure/workspace.js +0 -297
  130. package/libs/cli/shared/src/lib/infrastructure/yaml.js +0 -237
  131. package/libs/cli/shared/src/lib/lowgular.config.js +0 -120
  132. package/libs/cli/shared/src/lib/token.js +0 -135
  133. package/libs/cli/shared/src/lib/utils/solution.util.js +0 -35
  134. package/libs/cli/shared/src/lib/utils/utils.js +0 -89
  135. package/libs/cli/typescript/src/index.js +0 -21
  136. package/libs/cli/typescript/src/lib/base/index.js +0 -23
  137. package/libs/cli/typescript/src/lib/base/nameable.js +0 -34
  138. package/libs/cli/typescript/src/lib/base/nodeable.js +0 -36
  139. package/libs/cli/typescript/src/lib/class.implementation.js +0 -52
  140. package/libs/cli/typescript/src/lib/core/declaration.registry.js +0 -107
  141. package/libs/cli/typescript/src/lib/core/design-pattern.js +0 -55
  142. package/libs/cli/typescript/src/lib/core/index.js +0 -35
  143. package/libs/cli/typescript/src/lib/core/navigable-declaration.js +0 -69
  144. package/libs/cli/typescript/src/lib/core/program-context.js +0 -71
  145. package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +0 -40
  146. package/libs/cli/typescript/src/lib/core/type.js +0 -374
  147. package/libs/cli/typescript/src/lib/declaration.abstraction.js +0 -90
  148. package/libs/cli/typescript/src/lib/decorator.implementation.js +0 -35
  149. package/libs/cli/typescript/src/lib/enum.implementation.js +0 -35
  150. package/libs/cli/typescript/src/lib/function-declaration.implementation.js +0 -35
  151. package/libs/cli/typescript/src/lib/index.js +0 -57
  152. package/libs/cli/typescript/src/lib/interface.implementation.js +0 -51
  153. package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +0 -90
  154. package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +0 -44
  155. package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +0 -46
  156. package/libs/cli/typescript/src/lib/members/method.util.js +0 -32
  157. package/libs/cli/typescript/src/lib/members/parameter.implementation.js +0 -38
  158. package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +0 -64
  159. package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +0 -34
  160. package/libs/cli/typescript/src/lib/members/property.util.js +0 -61
  161. package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +0 -42
  162. package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +0 -114
  163. package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +0 -188
  164. package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +0 -35
  165. package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +0 -51
  166. package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +0 -49
  167. package/libs/cli/typescript/src/lib/members/statements/utils.js +0 -51
  168. package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +0 -258
  169. package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +0 -15
  170. package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +0 -228
  171. package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +0 -126
  172. package/libs/cli/typescript/src/lib/plugins/stubs.js +0 -66
  173. package/libs/cli/typescript/src/lib/type-alias.implementation.js +0 -72
  174. package/libs/cli/typescript/src/lib/utils.js +0 -39
  175. package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +0 -35
  176. package/libs/core/codegular/src/index.js +0 -21
  177. package/libs/core/codegular/src/lib/index.js +0 -29
  178. package/libs/core/codegular/src/lib/node.js +0 -112
  179. package/libs/core/codegular/src/lib/program.js +0 -92
package/bin/cli.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import yargs from "yargs";
3
+ import { hideBin } from "yargs/helpers";
4
+ import * as QueryModule from "../run-cli.js";
5
+ import * as ResourcesModule from "../resources-cli.js";
6
+ import * as CypherModule from "../cypher-cli.js";
7
+ const VERSION = process.env.npm_package_version ?? "0.1.0";
8
+ yargs(hideBin(process.argv)).scriptName("code-graph").demandCommand().recommendCommands().command(QueryModule.command, QueryModule.describe, QueryModule).command(ResourcesModule.command, ResourcesModule.describe, ResourcesModule).command(CypherModule.command, CypherModule.describe, CypherModule).wrap(120).strict().help().version(VERSION).epilog(
9
+ 'Exits 0 and prints JSON array of matches to stdout on success; exits 1 and prints error to stderr on failure.\n\nExamples:\n code-graph query "MATCH (n:ClassDeclaration) RETURN n"\n code-graph query --tsconfig ./lib/tsconfig.json "MATCH (n:ClassDeclaration) RETURN n"\n code-graph resources # schema and concepts\n code-graph cypher # full Cypher dialect reference'
10
+ ).parse();
@@ -0,0 +1,37 @@
1
+ const addNode = (graph, node) => {
2
+ graph.nodesById[node.id] = node;
3
+ return graph;
4
+ };
5
+ const getEdgeKey = (edge) => {
6
+ return `${edge.source}|${edge.target}|${edge.type}`;
7
+ };
8
+ const addEdge = (graph, edge) => {
9
+ const edgeKey = getEdgeKey(edge);
10
+ const sourceEdges = graph.edgesBySource[edge.source];
11
+ if (sourceEdges) {
12
+ const sourceEdgeKeys = new Set(sourceEdges.map(getEdgeKey));
13
+ if (sourceEdgeKeys.has(edgeKey)) {
14
+ return graph;
15
+ }
16
+ }
17
+ const targetEdges = graph.edgesByTarget[edge.target];
18
+ if (targetEdges) {
19
+ const targetEdgeKeys = new Set(targetEdges.map(getEdgeKey));
20
+ if (targetEdgeKeys.has(edgeKey)) {
21
+ return graph;
22
+ }
23
+ }
24
+ if (!graph.edgesBySource[edge.source]) {
25
+ graph.edgesBySource[edge.source] = [];
26
+ }
27
+ graph.edgesBySource[edge.source].push(edge);
28
+ if (!graph.edgesByTarget[edge.target]) {
29
+ graph.edgesByTarget[edge.target] = [];
30
+ }
31
+ graph.edgesByTarget[edge.target].push(edge);
32
+ return graph;
33
+ };
34
+ export {
35
+ addEdge,
36
+ addNode
37
+ };
@@ -0,0 +1,131 @@
1
+ const STANDARD_NODE_PROPERTIES = {
2
+ firstIdentifier: `helpers.getDescendantsBy(args.current, (node) => node.kind === args.ts.SyntaxKind.Identifier)[0]?.getText() ?? null`,
3
+ initializer: `args.current.initializer ? args.current.initializer?.getText() : null`,
4
+ name: `args.current.name?.getText() ?? null`,
5
+ filePath: `args.sourceFile.fileName`,
6
+ text: `args.current.getText()`,
7
+ type: `(() => { try { const t = args.typeChecker.getTypeAtLocation(args.current); return t ? args.typeChecker.typeToString(t) : null; } catch { return null; } })()`
8
+ };
9
+ const SUPPORTED_RELATIONSHIPS = {
10
+ // --- Traversal relationships ---
11
+ HAS_DESCENDANTS: (labels) => labels.length > 0 ? `helpers.getDescendantsBy(args.current, (node) => ${buildKindFilter(labels)})` : `helpers.getDescendantsBy(args.current, () => true)`,
12
+ HAS_ANCESTORS: (labels) => labels.length > 0 ? `helpers.getAncestorsBy(args.current, (node) => ${buildKindFilter(labels)})` : `helpers.getAncestorsBy(args.current, () => true)`,
13
+ HAS_TYPE: () => `helpers.getType(args.current)`,
14
+ HAS_NAME: () => `args.current.name ? [args.current.name] : []`,
15
+ // --- Direct AST property relationships ---
16
+ HAS_INITIALIZER: () => `args.current.initializer ? [args.current.initializer] : []`,
17
+ HAS_PARAMETERS: () => `args.current.parameters ? [...args.current.parameters] : []`,
18
+ HAS_EXPRESSION: () => `args.current.expression ? [args.current.expression] : []`,
19
+ HAS_TYPE_ANNOTATION: () => `args.current.type ? [args.current.type] : []`,
20
+ HAS_BODY: () => `args.current.body ? [args.current.body] : []`,
21
+ HAS_MEMBERS: () => `args.current.members ? [...args.current.members] : []`,
22
+ HAS_PROPERTIES: () => `args.current.properties ? [...args.current.properties] : []`,
23
+ HAS_ARGUMENTS: () => `args.current.arguments ? [...args.current.arguments] : []`,
24
+ HAS_DECORATORS: () => `args.ts.getDecorators(args.current) || []`,
25
+ // --- Heritage relationships ---
26
+ EXTENDS: () => `(() => { const c = (args.current.heritageClauses || []).find(c => c.token === args.ts.SyntaxKind.ExtendsKeyword); return c ? [...c.types] : []; })()`,
27
+ IMPLEMENTS: () => `(() => { const c = (args.current.heritageClauses || []).find(c => c.token === args.ts.SyntaxKind.ImplementsKeyword); return c ? [...c.types] : []; })()`
28
+ };
29
+ const buildConfigFromQuery = (query) => {
30
+ const nodeExtractors = {};
31
+ const matchStatements = query.statements.filter(
32
+ (s) => s.type === "MatchStatement"
33
+ );
34
+ const variableToLabels = {};
35
+ for (const match of matchStatements) {
36
+ for (const pattern of match.patterns) {
37
+ if (pattern.variable && pattern.labels.length > 0) {
38
+ variableToLabels[pattern.variable] = pattern.labels;
39
+ }
40
+ }
41
+ }
42
+ for (const match of matchStatements) {
43
+ buildExtractorsFromMatch(match, nodeExtractors, variableToLabels);
44
+ }
45
+ return { nodeExtractors };
46
+ };
47
+ const resolveLabels = (pattern, variableToLabels) => {
48
+ if (pattern.labels.length > 0)
49
+ return pattern.labels;
50
+ if (pattern.variable && variableToLabels[pattern.variable]) {
51
+ return variableToLabels[pattern.variable];
52
+ }
53
+ return [];
54
+ };
55
+ const buildExtractorsFromMatch = (match, rootNodeExtractors, variableToLabels) => {
56
+ const { patterns, relationships } = match;
57
+ if (patterns.length === 0)
58
+ return;
59
+ const rootPattern = patterns[0];
60
+ const rootLabels = resolveLabels(rootPattern, variableToLabels);
61
+ for (const label of rootLabels) {
62
+ rootNodeExtractors[label] ??= {
63
+ properties: { ...STANDARD_NODE_PROPERTIES }
64
+ };
65
+ }
66
+ if (!relationships || relationships.length === 0)
67
+ return;
68
+ let currentExtractors = rootNodeExtractors;
69
+ for (let i = 0; i < relationships.length; i++) {
70
+ const rel = relationships[i];
71
+ const sourcePattern = patterns[i];
72
+ const targetPattern = patterns[i + 1];
73
+ if (!targetPattern)
74
+ break;
75
+ const edgeType = resolveEdgeType(rel.edgeType);
76
+ const codeGenerator = getCodeGenerator(edgeType);
77
+ const sourceLabels = resolveLabels(sourcePattern, variableToLabels);
78
+ const targetLabels = resolveLabels(targetPattern, variableToLabels);
79
+ const targetNodeExtractors = {};
80
+ if (targetLabels.length === 0) {
81
+ targetNodeExtractors["*"] = {
82
+ properties: { ...STANDARD_NODE_PROPERTIES }
83
+ };
84
+ } else {
85
+ for (const label of targetLabels) {
86
+ targetNodeExtractors[label] = {
87
+ properties: { ...STANDARD_NODE_PROPERTIES }
88
+ };
89
+ }
90
+ }
91
+ for (const sourceLabel of sourceLabels) {
92
+ currentExtractors[sourceLabel] ??= {
93
+ properties: { ...STANDARD_NODE_PROPERTIES }
94
+ };
95
+ currentExtractors[sourceLabel].relationships ??= {};
96
+ currentExtractors[sourceLabel].relationships[edgeType] = {
97
+ extractorCode: codeGenerator(targetLabels),
98
+ nodeExtractors: targetNodeExtractors
99
+ };
100
+ }
101
+ currentExtractors = targetNodeExtractors;
102
+ }
103
+ };
104
+ const resolveEdgeType = (edgeType) => {
105
+ if (!edgeType) {
106
+ throw new Error(
107
+ `Relationship type is required in auto-config mode. Supported: ${Object.keys(SUPPORTED_RELATIONSHIPS).join(", ")}`
108
+ );
109
+ }
110
+ if (Array.isArray(edgeType)) {
111
+ throw new Error(
112
+ `Union relationship types are not supported in auto-config. Got: ${edgeType.join("|")}`
113
+ );
114
+ }
115
+ return edgeType;
116
+ };
117
+ const getCodeGenerator = (edgeType) => {
118
+ const generator = SUPPORTED_RELATIONSHIPS[edgeType];
119
+ if (!generator) {
120
+ throw new Error(
121
+ `Unsupported relationship type: "${edgeType}". Auto-config supports: ${Object.keys(SUPPORTED_RELATIONSHIPS).join(", ")}`
122
+ );
123
+ }
124
+ return generator;
125
+ };
126
+ const buildKindFilter = (labels) => {
127
+ return labels.map((l) => `node.kind === args.ts.SyntaxKind.${l}`).join(" || ");
128
+ };
129
+ export {
130
+ buildConfigFromQuery
131
+ };
@@ -0,0 +1,27 @@
1
+ function executeExtractor(code, context) {
2
+ try {
3
+ const fn = new Function(
4
+ ...Object.keys(context),
5
+ `
6
+ return ${code}
7
+ `
8
+ );
9
+ return fn(...Object.values(context));
10
+ } catch (error) {
11
+ throw new Error(`Extractor execution failed: ${error.message}`);
12
+ }
13
+ }
14
+ function extractNodeProperties(context, propertyExectorMap = {}) {
15
+ const properties = {};
16
+ for (const [propertyName, extractorCode] of Object.entries(
17
+ propertyExectorMap
18
+ )) {
19
+ const value = executeExtractor(extractorCode, context);
20
+ properties[propertyName] = value;
21
+ }
22
+ return properties;
23
+ }
24
+ export {
25
+ executeExtractor,
26
+ extractNodeProperties
27
+ };
@@ -0,0 +1 @@
1
+ export * from "./extractor.js";
@@ -0,0 +1,49 @@
1
+ import * as ts from "typescript";
2
+ import {
3
+ getAncestorsBy,
4
+ getDescendantsBy,
5
+ getDescendantsByKind,
6
+ getSolutionSourceFiles
7
+ } from "../../codegular/index.js";
8
+ import { processNode } from "./node.processor.js";
9
+ const buildCodeGraph = (program, config) => {
10
+ const codeGraph = {
11
+ nodesById: {},
12
+ edgesBySource: {},
13
+ edgesByTarget: {}
14
+ };
15
+ const sourceFiles = getSolutionSourceFiles(program);
16
+ sourceFiles.forEach((sourceFile) => {
17
+ Object.keys(config.nodeExtractors).forEach((kindName) => {
18
+ const nodes = getDescendantsByKind(sourceFile, ts.SyntaxKind[kindName]);
19
+ nodes.forEach((node) => {
20
+ const extractorContext = {
21
+ args: {
22
+ current: node,
23
+ sourceFile,
24
+ typeChecker: program.getTypeChecker(),
25
+ ts
26
+ },
27
+ helpers: {
28
+ getDescendantsBy,
29
+ getAncestorsBy,
30
+ getType: (node2) => []
31
+ // TODO: add type extraction
32
+ // getType(
33
+ // node,
34
+ // program.getTypeChecker(),
35
+ // new TypeResolutionTracker(),
36
+ // ),
37
+ // getDeclarations: (node: ts.Type | ts.Node) =>
38
+ // getDeclarations(node, context.typeChecker),
39
+ }
40
+ };
41
+ processNode(extractorContext, config.nodeExtractors, codeGraph);
42
+ });
43
+ });
44
+ });
45
+ return codeGraph;
46
+ };
47
+ export {
48
+ buildCodeGraph
49
+ };
@@ -0,0 +1 @@
1
+ export * from "./code-graph.builder.js";
@@ -0,0 +1,22 @@
1
+ import { addNode } from "../code.graph.js";
2
+ import {
3
+ extractNodeProperties
4
+ } from "../extractors/index.js";
5
+ import { generateNodeId, getSyntaxKindName } from "../utils.js";
6
+ import { processRelationships } from "./relationship.processor.js";
7
+ const processNode = (context, nodeExtractors, codeGraph) => {
8
+ const nodeId = generateNodeId(context.args.current);
9
+ const kindName = getSyntaxKindName(context.args.current.kind);
10
+ const nodeConfig = nodeExtractors[kindName] ?? nodeExtractors["*"];
11
+ const graphNode = {
12
+ ...nodeConfig && nodeConfig.properties ? extractNodeProperties(context, nodeConfig.properties) : {},
13
+ id: nodeId,
14
+ labels: [kindName]
15
+ };
16
+ addNode(codeGraph, graphNode);
17
+ processRelationships(nodeId, context, nodeConfig, codeGraph);
18
+ return graphNode;
19
+ };
20
+ export {
21
+ processNode
22
+ };
@@ -1,30 +1,7 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var relationship_processor_exports = {};
19
- __export(relationship_processor_exports, {
20
- processRelationships: () => processRelationships
21
- });
22
- module.exports = __toCommonJS(relationship_processor_exports);
23
- var import_typescript = require("@cli/typescript");
24
- var import_extractors = require("../extractors");
25
- var import_node = require("./node.processor");
26
- var import_type = require("./type.processor");
27
- const ts = require("typescript");
1
+ import { addEdge } from "../code.graph.js";
2
+ import { executeExtractor } from "../extractors/index.js";
3
+ import { processNode } from "./node.processor.js";
4
+ import { processType } from "./type.processor.js";
28
5
  function isTsNode(obj) {
29
6
  return obj && "kind" in obj && typeof obj.kind === "number";
30
7
  }
@@ -37,27 +14,27 @@ const processRelationships = (parentId, context, nodeConfig, codeGraph) => {
37
14
  const relationshipExtractorFnCode = nodeConfig.relationships[relationshipName].extractorCode;
38
15
  const relationshipNodeExtractors = nodeConfig.relationships[relationshipName].nodeExtractors;
39
16
  Object.keys(relationshipNodeExtractors).forEach((label) => {
40
- const children = (0, import_extractors.executeExtractor)(relationshipExtractorFnCode, context);
17
+ const children = executeExtractor(relationshipExtractorFnCode, context);
41
18
  children.forEach(
42
19
  (child) => {
43
20
  if (isTsType(child)) {
44
- const childNode = (0, import_type.processType)(
21
+ const childNode = processType(
45
22
  { ...context, args: { ...context.args, current: child } },
46
23
  relationshipNodeExtractors,
47
24
  codeGraph
48
25
  );
49
- (0, import_typescript.addEdge)(codeGraph, {
26
+ addEdge(codeGraph, {
50
27
  source: parentId,
51
28
  target: childNode.id,
52
29
  type: relationshipName
53
30
  });
54
31
  } else if (isTsNode(child)) {
55
- const childNode = (0, import_node.processNode)(
32
+ const childNode = processNode(
56
33
  { ...context, args: { ...context.args, current: child } },
57
34
  relationshipNodeExtractors,
58
35
  codeGraph
59
36
  );
60
- (0, import_typescript.addEdge)(codeGraph, {
37
+ addEdge(codeGraph, {
61
38
  source: parentId,
62
39
  target: childNode.id,
63
40
  type: relationshipName
@@ -73,7 +50,6 @@ const processRelationships = (parentId, context, nodeConfig, codeGraph) => {
73
50
  }
74
51
  }
75
52
  };
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
53
+ export {
78
54
  processRelationships
79
- });
55
+ };
@@ -0,0 +1,21 @@
1
+ import { addNode } from "../code.graph.js";
2
+ import { extractNodeProperties } from "../extractors/index.js";
3
+ import { processRelationships } from "./relationship.processor.js";
4
+ const processType = (context, nodeExtractors, codeGraph) => {
5
+ const nodeId = context.args.typeChecker.typeToString(
6
+ context.args.current
7
+ );
8
+ const kindName = "Type";
9
+ const nodeConfig = nodeExtractors[kindName];
10
+ const graphNode = {
11
+ ...nodeConfig && nodeConfig.properties ? extractNodeProperties(context, nodeConfig.properties) : {},
12
+ id: nodeId,
13
+ labels: [kindName]
14
+ };
15
+ addNode(codeGraph, graphNode);
16
+ processRelationships(nodeId, context, nodeConfig, codeGraph);
17
+ return graphNode;
18
+ };
19
+ export {
20
+ processType
21
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./config-from-query.js";
2
+ export * from "./extractors/index.js";
3
+ export * from "./graph-builder/index.js";
4
+ export * from "./tools/build-code-graph.tool.js";
@@ -0,0 +1,19 @@
1
+ import { writeFileSync } from "fs";
2
+ import { createProgramFromTsConfig } from "../../codegular/index.js";
3
+ import { buildCodeGraph } from "../graph-builder/index.js";
4
+ async function buildCodeGraphTool(tsConfigPath, config) {
5
+ const program = createProgramFromTsConfig(tsConfigPath);
6
+ const graph = buildCodeGraph(program, config);
7
+ const nodeCount = Object.keys(graph.nodesById).length;
8
+ const edgeCount = Object.values(graph.edgesBySource).flat().length;
9
+ const graphPath = tsConfigPath.replace("tsconfig.json", "code-graph.json");
10
+ writeFileSync(graphPath, JSON.stringify(graph, null, 2));
11
+ return {
12
+ graphPath,
13
+ nodeCount,
14
+ edgeCount
15
+ };
16
+ }
17
+ export {
18
+ buildCodeGraphTool
19
+ };
@@ -0,0 +1,34 @@
1
+ import ts from "typescript";
2
+ const getSyntaxKindName = (kind) => {
3
+ return ts.SyntaxKind[kind];
4
+ };
5
+ const generateNodeId = (n) => {
6
+ const s = n.getSourceFile();
7
+ const start = s.getLineAndCharacterOfPosition(n.getStart(s));
8
+ const end = s.getLineAndCharacterOfPosition(n.getEnd());
9
+ return `${s.fileName}.${start.line}.${start.character}.${end.line}.${end.character}`;
10
+ };
11
+ const extractFromNodeId = (nodeId) => {
12
+ const parts = nodeId.split(".");
13
+ const endCharacter = parts.pop();
14
+ const endLine = parts.pop();
15
+ const startCharacter = parts.pop();
16
+ const startLine = parts.pop();
17
+ const filePath = parts.join(".");
18
+ return {
19
+ filePath,
20
+ start: {
21
+ line: parseInt(startLine),
22
+ character: parseInt(startCharacter)
23
+ },
24
+ end: {
25
+ line: parseInt(endLine),
26
+ character: parseInt(endCharacter)
27
+ }
28
+ };
29
+ };
30
+ export {
31
+ extractFromNodeId,
32
+ generateNodeId,
33
+ getSyntaxKindName
34
+ };
@@ -0,0 +1,5 @@
1
+ export * from "./node.js";
2
+ export * from "./program.js";
3
+ export * from "./string.js";
4
+ export * from "./type-checker.js";
5
+ export * from "./utils.js";
@@ -0,0 +1,71 @@
1
+ import * as ts from "typescript";
2
+ import { getNameByIdentifier } from "./string.js";
3
+ const { forEachChild, SyntaxKind } = ts;
4
+ const hasKind = (kinds) => (child) => kinds.includes(child.kind);
5
+ const hasName = (names) => (child) => names.includes(getNameByIdentifier(child));
6
+ const hasDecorator = (decoratorName) => (child) => findByDecorator(child, decoratorName) !== void 0;
7
+ const hasAnyDecoratorName = (node, decoratorNames) => {
8
+ const decorators = getChildrenBy(node, hasKind([SyntaxKind.Decorator]));
9
+ return decorators.find((d) => {
10
+ return getChildrenBy(d, hasKind([SyntaxKind.CallExpression])).find(
11
+ (callExpr) => {
12
+ return decoratorNames.includes(getNameByIdentifier(callExpr));
13
+ }
14
+ ) !== void 0;
15
+ }) !== void 0;
16
+ };
17
+ const every = () => true;
18
+ function getChildrenBy(node, findFunc = every) {
19
+ const elements = [];
20
+ forEachChild(node, (child) => {
21
+ if (!findFunc(child)) {
22
+ return;
23
+ }
24
+ elements.push(child);
25
+ });
26
+ return elements;
27
+ }
28
+ function findChildOrThrow(node, findFunc) {
29
+ let element;
30
+ forEachChild(node, (child) => {
31
+ if (element)
32
+ return;
33
+ if (findFunc(child)) {
34
+ element = child;
35
+ return;
36
+ }
37
+ });
38
+ if (element === void 0) {
39
+ throw new Error("Could not find child");
40
+ }
41
+ return element;
42
+ }
43
+ const getDecoratorName = (d) => {
44
+ return getNameByIdentifier(
45
+ getChildrenBy(d, hasKind([SyntaxKind.CallExpression]))[0]
46
+ );
47
+ };
48
+ const findByDecorator = (node, decoratorName) => {
49
+ const decorators = getChildrenBy(node, hasKind([SyntaxKind.Decorator]));
50
+ if (decorators.length === 0) {
51
+ return void 0;
52
+ }
53
+ return decorators.find((d) => {
54
+ return getChildrenBy(d, hasKind([SyntaxKind.CallExpression])).find(
55
+ (callExpr) => {
56
+ return getNameByIdentifier(callExpr) === decoratorName;
57
+ }
58
+ ) !== void 0;
59
+ });
60
+ };
61
+ export {
62
+ every,
63
+ findByDecorator,
64
+ findChildOrThrow,
65
+ getChildrenBy,
66
+ getDecoratorName,
67
+ hasAnyDecoratorName,
68
+ hasDecorator,
69
+ hasKind,
70
+ hasName
71
+ };
@@ -0,0 +1,100 @@
1
+ import * as path from "path";
2
+ import * as ts from "typescript";
3
+ const createSourceFileFromContent = (fileName, content) => {
4
+ return ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, true);
5
+ };
6
+ const createProgramFromFileSystem = (fileSystem) => {
7
+ const compilerOptions = {
8
+ target: ts.ScriptTarget.ES2020,
9
+ module: ts.ModuleKind.CommonJS,
10
+ moduleResolution: ts.ModuleResolutionKind.NodeJs,
11
+ allowSyntheticDefaultImports: true,
12
+ esModuleInterop: true,
13
+ skipLibCheck: true,
14
+ lib: ["ES2020", "DOM"]
15
+ };
16
+ const compilerHost = ts.createCompilerHost(compilerOptions);
17
+ const originalGetSourceFile = compilerHost.getSourceFile;
18
+ compilerHost.getSourceFile = (fileName, languageVersion) => {
19
+ if (fileSystem[fileName]) {
20
+ return ts.createSourceFile(
21
+ fileName,
22
+ fileSystem[fileName],
23
+ languageVersion,
24
+ true
25
+ );
26
+ }
27
+ return originalGetSourceFile(fileName, languageVersion);
28
+ };
29
+ const fileNames = Object.keys(fileSystem);
30
+ return ts.createProgram(fileNames, compilerOptions, compilerHost);
31
+ };
32
+ const createHybridProgram = (generatedFiles, options) => {
33
+ const rootPath = path.resolve(options?.workspaceRoot ?? process.cwd());
34
+ const fileSystem = {};
35
+ for (const { filePath, code } of generatedFiles) {
36
+ const absolutePath = path.isAbsolute(filePath) ? filePath : path.join(rootPath, filePath);
37
+ fileSystem[absolutePath] = code;
38
+ }
39
+ const rootNames = Object.keys(fileSystem).filter(
40
+ (p) => p.endsWith(".ts")
41
+ );
42
+ const compilerOptions = {
43
+ target: ts.ScriptTarget.ES2020,
44
+ module: ts.ModuleKind.ESNext,
45
+ moduleResolution: ts.ModuleResolutionKind.Node10,
46
+ allowSyntheticDefaultImports: true,
47
+ esModuleInterop: true,
48
+ skipLibCheck: true,
49
+ lib: ["ES2020", "DOM"],
50
+ strict: true
51
+ };
52
+ const compilerHost = ts.createCompilerHost(compilerOptions);
53
+ const originalGetSourceFile = compilerHost.getSourceFile;
54
+ compilerHost.getCurrentDirectory = () => rootPath;
55
+ compilerHost.getSourceFile = (fileName, languageVersion) => {
56
+ const normalized = path.normalize(fileName);
57
+ const content = fileSystem[normalized] ?? fileSystem[fileName] ?? fileSystem[path.resolve(rootPath, fileName)];
58
+ if (content !== void 0) {
59
+ return ts.createSourceFile(
60
+ fileName,
61
+ content,
62
+ languageVersion,
63
+ true
64
+ );
65
+ }
66
+ return originalGetSourceFile.call(
67
+ compilerHost,
68
+ fileName,
69
+ languageVersion
70
+ );
71
+ };
72
+ return ts.createProgram(rootNames, compilerOptions, compilerHost);
73
+ };
74
+ const createProgramFromTsConfig = (configPath) => {
75
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
76
+ if (configFile.error) {
77
+ const errorMessage = ts.formatDiagnostic(configFile.error, {
78
+ getCurrentDirectory: () => process.cwd(),
79
+ getNewLine: () => "\n",
80
+ getCanonicalFileName: (fileName) => fileName
81
+ });
82
+ throw new Error(`Error reading tsconfig at ${configPath}: ${errorMessage}`);
83
+ }
84
+ const parsedConfig = ts.parseJsonConfigFileContent(
85
+ configFile.config,
86
+ ts.sys,
87
+ path.dirname(configPath)
88
+ );
89
+ return ts.createProgram(
90
+ parsedConfig.fileNames,
91
+ parsedConfig.options,
92
+ ts.createCompilerHost(parsedConfig.options)
93
+ );
94
+ };
95
+ export {
96
+ createHybridProgram,
97
+ createProgramFromFileSystem,
98
+ createProgramFromTsConfig,
99
+ createSourceFileFromContent
100
+ };