@lowgular/code-graph 0.0.1 → 0.1.2

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 (155) hide show
  1. package/bin/cli.js +2463 -0
  2. package/lib.js +2430 -0
  3. package/package.json +26 -7
  4. package/apps/code-graph/src/main.js +0 -50
  5. package/libs/cli/code-graph/src/index.js +0 -39
  6. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +0 -72
  7. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +0 -68
  8. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +0 -147
  9. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +0 -55
  10. package/libs/cli/code-graph/src/lib/class-declarations/index.js +0 -27
  11. package/libs/cli/code-graph/src/lib/code.graph.factory.js +0 -63
  12. package/libs/cli/code-graph/src/lib/code.graph.js +0 -62
  13. package/libs/cli/code-graph/src/lib/core/core.js +0 -58
  14. package/libs/cli/code-graph/src/lib/core.js +0 -85
  15. package/libs/cli/code-graph/src/lib/decorators/index.js +0 -36
  16. package/libs/cli/code-graph/src/lib/docs/index.js +0 -21
  17. package/libs/cli/code-graph/src/lib/docs/specs.js +0 -36
  18. package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +0 -28
  19. package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +0 -53
  20. package/libs/cli/code-graph/src/lib/method-declarations/index.js +0 -23
  21. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +0 -106
  22. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +0 -56
  23. package/libs/cli/code-graph/src/lib/parameters/index.js +0 -42
  24. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +0 -139
  25. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +0 -104
  26. package/libs/cli/code-graph/src/lib/property-declarations/index.js +0 -25
  27. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +0 -74
  28. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +0 -43
  29. package/libs/cli/code-graph/src/lib/tools/index.js +0 -34
  30. package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +0 -64
  31. package/libs/cli/code-graph/src/lib/types/index.js +0 -99
  32. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +0 -345
  33. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +0 -52
  34. package/libs/cli/code-graph/src/lib/v2/extractors/index.js +0 -23
  35. package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +0 -76
  36. package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +0 -21
  37. package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +0 -48
  38. package/libs/cli/code-graph/src/lib/v2/graph-builder/relationship.processor.js +0 -79
  39. package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +0 -45
  40. package/libs/cli/code-graph/src/lib/v2/index.js +0 -37
  41. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +0 -220
  42. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +0 -42
  43. package/libs/cli/cypher/src/index.js +0 -25
  44. package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +0 -277
  45. package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +0 -69
  46. package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +0 -105
  47. package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +0 -70
  48. package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +0 -99
  49. package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +0 -125
  50. package/libs/cli/cypher/src/lib/docs/features/index.js +0 -51
  51. package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +0 -50
  52. package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +0 -106
  53. package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +0 -105
  54. package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +0 -143
  55. package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +0 -152
  56. package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +0 -48
  57. package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +0 -65
  58. package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +0 -82
  59. package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +0 -136
  60. package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +0 -187
  61. package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +0 -302
  62. package/libs/cli/cypher/src/lib/docs/prompts.js +0 -36
  63. package/libs/cli/cypher/src/lib/docs/specs.js +0 -181
  64. package/libs/cli/cypher/src/lib/executor/condition-evaluator.js +0 -158
  65. package/libs/cli/cypher/src/lib/executor/executor.js +0 -83
  66. package/libs/cli/cypher/src/lib/executor/graph.js +0 -15
  67. package/libs/cli/cypher/src/lib/executor/match-engine.js +0 -153
  68. package/libs/cli/cypher/src/lib/executor/pattern-matcher.js +0 -109
  69. package/libs/cli/cypher/src/lib/executor/relationship-navigator.js +0 -64
  70. package/libs/cli/cypher/src/lib/executor/result-formatter.js +0 -143
  71. package/libs/cli/cypher/src/lib/executor/traverse-engine.js +0 -164
  72. package/libs/cli/cypher/src/lib/executor/utils.js +0 -37
  73. package/libs/cli/cypher/src/lib/graph.stub.js +0 -63
  74. package/libs/cli/cypher/src/lib/index.js +0 -74
  75. package/libs/cli/cypher/src/lib/lexer.js +0 -398
  76. package/libs/cli/cypher/src/lib/parser.js +0 -602
  77. package/libs/cli/cypher/src/lib/validator/query-validator.js +0 -95
  78. package/libs/cli/cypher/src/lib/validator/supported-features.config.js +0 -111
  79. package/libs/cli/cypher/src/lib/validator/unsupported-features.config.js +0 -150
  80. package/libs/cli/shared/src/index.js +0 -53
  81. package/libs/cli/shared/src/lib/admin-token.js +0 -121
  82. package/libs/cli/shared/src/lib/config.js +0 -49
  83. package/libs/cli/shared/src/lib/consts.js +0 -57
  84. package/libs/cli/shared/src/lib/core.js +0 -46
  85. package/libs/cli/shared/src/lib/infrastructure/cli.js +0 -47
  86. package/libs/cli/shared/src/lib/infrastructure/config.js +0 -47
  87. package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +0 -51
  88. package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +0 -96
  89. package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +0 -41
  90. package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +0 -64
  91. package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +0 -120
  92. package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +0 -15
  93. package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +0 -72
  94. package/libs/cli/shared/src/lib/infrastructure/git.js +0 -147
  95. package/libs/cli/shared/src/lib/infrastructure/http.js +0 -257
  96. package/libs/cli/shared/src/lib/infrastructure/markdown.js +0 -95
  97. package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +0 -88
  98. package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +0 -25
  99. package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +0 -154
  100. package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +0 -210
  101. package/libs/cli/shared/src/lib/infrastructure/workspace.js +0 -297
  102. package/libs/cli/shared/src/lib/infrastructure/yaml.js +0 -237
  103. package/libs/cli/shared/src/lib/lowgular.config.js +0 -120
  104. package/libs/cli/shared/src/lib/token.js +0 -135
  105. package/libs/cli/shared/src/lib/utils/solution.util.js +0 -35
  106. package/libs/cli/shared/src/lib/utils/utils.js +0 -89
  107. package/libs/cli/typescript/src/index.js +0 -21
  108. package/libs/cli/typescript/src/lib/base/index.js +0 -23
  109. package/libs/cli/typescript/src/lib/base/nameable.js +0 -34
  110. package/libs/cli/typescript/src/lib/base/nodeable.js +0 -36
  111. package/libs/cli/typescript/src/lib/class.implementation.js +0 -52
  112. package/libs/cli/typescript/src/lib/core/declaration.registry.js +0 -107
  113. package/libs/cli/typescript/src/lib/core/design-pattern.js +0 -55
  114. package/libs/cli/typescript/src/lib/core/index.js +0 -35
  115. package/libs/cli/typescript/src/lib/core/navigable-declaration.js +0 -69
  116. package/libs/cli/typescript/src/lib/core/program-context.js +0 -71
  117. package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +0 -40
  118. package/libs/cli/typescript/src/lib/core/type.js +0 -374
  119. package/libs/cli/typescript/src/lib/declaration.abstraction.js +0 -90
  120. package/libs/cli/typescript/src/lib/decorator.implementation.js +0 -35
  121. package/libs/cli/typescript/src/lib/enum.implementation.js +0 -35
  122. package/libs/cli/typescript/src/lib/function-declaration.implementation.js +0 -35
  123. package/libs/cli/typescript/src/lib/index.js +0 -57
  124. package/libs/cli/typescript/src/lib/interface.implementation.js +0 -51
  125. package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +0 -90
  126. package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +0 -44
  127. package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +0 -46
  128. package/libs/cli/typescript/src/lib/members/method.util.js +0 -32
  129. package/libs/cli/typescript/src/lib/members/parameter.implementation.js +0 -38
  130. package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +0 -64
  131. package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +0 -34
  132. package/libs/cli/typescript/src/lib/members/property.util.js +0 -61
  133. package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +0 -42
  134. package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +0 -114
  135. package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +0 -188
  136. package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +0 -35
  137. package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +0 -51
  138. package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +0 -49
  139. package/libs/cli/typescript/src/lib/members/statements/utils.js +0 -51
  140. package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +0 -258
  141. package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +0 -15
  142. package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +0 -228
  143. package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +0 -126
  144. package/libs/cli/typescript/src/lib/plugins/stubs.js +0 -66
  145. package/libs/cli/typescript/src/lib/type-alias.implementation.js +0 -72
  146. package/libs/cli/typescript/src/lib/utils.js +0 -39
  147. package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +0 -35
  148. package/libs/core/codegular/src/index.js +0 -21
  149. package/libs/core/codegular/src/lib/index.js +0 -29
  150. package/libs/core/codegular/src/lib/node.js +0 -112
  151. package/libs/core/codegular/src/lib/program.js +0 -92
  152. package/libs/core/codegular/src/lib/string.js +0 -168
  153. package/libs/core/codegular/src/lib/type-checker.js +0 -170
  154. package/libs/core/codegular/src/lib/utils.js +0 -347
  155. package/main.js +0 -43
@@ -1,345 +0,0 @@
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 extractor_doc_exports = {};
19
- __export(extractor_doc_exports, {
20
- EXTRACTOR_ARGUMENT_CONTEXT_DOC: () => EXTRACTOR_ARGUMENT_CONTEXT_DOC,
21
- EXTRACTOR_DOC: () => EXTRACTOR_DOC,
22
- EXTRACTOR_HELPERS_DOC: () => EXTRACTOR_HELPERS_DOC
23
- });
24
- module.exports = __toCommonJS(extractor_doc_exports);
25
- var import_cypher = require("@cli/cypher");
26
- const EXTRACTOR_ARGUMENT_CONTEXT_DOC = {
27
- current: `\`ts.Node | ts.Type\`: The current node that is being processed.
28
- - For properties: The node whose property you're extracting
29
- - For relationships: The source node from which you're finding related nodes
30
- - Can be a \`ts.Node\` or \`ts.Type\``,
31
- sourceFile: `\`ts.SourceFile\`: Current source file that is being processed
32
- - Always the final parent of the current node
33
- - Use \`args.sourceFile.fileName\` to get the file path`,
34
- typeChecker: `\`ts.TypeChecker\`: The type checker to use to extract information from
35
- - Use for type resolution and semantic analysis
36
- - Access via \`args.typeChecker\``,
37
- ts: `\`typeof ts\`: The TypeScript API to use to extract information from
38
- - Access to all TypeScript types, enums, and utilities
39
- - Use \`args.ts.SyntaxKind\` for node kinds
40
- - Use \`args.ts.isIdentifier()\` for type guards, etc.`
41
- };
42
- const EXTRACTOR_HELPERS_DOC = {
43
- getDescendantsBy: `Performs a breadth-first traversal of a TypeScript AST node tree, collecting all descendant nodes that match a custom predicate.
44
- It uses a queue-based algorithm starting from the given node, iteratively processing each node by extracting its children via getChildren(), filtering those that match the predicate into the results array, and adding all children (both matching and non-matching) back to the queue for further traversal.
45
- This ensures all descendants at every depth level are examined, making it useful for finding nodes based on flexible criteria (node kind, name, custom properties, etc.) rather than just syntax kind matching, and it returns a type-safe array of matching nodes cast to the specified generic type T.
46
-
47
- Signature:
48
- function getDescendantsBy<T extends Node>(
49
- node: Node,
50
- predicate: (node: Node) => boolean,
51
- ): T[]
52
-
53
- **Use Case**: Finding nodes based on flexible criteria (node kind, name, custom properties, etc.)
54
-
55
- **Examples:**
56
- ${(0, import_cypher.mb)(
57
- `// Find all MethodDeclaration descendants
58
- helpers.getDescendantsBy(args.current, (node) =>
59
- node.kind === args.ts.SyntaxKind.MethodDeclaration
60
- );`,
61
- "typescript"
62
- )}
63
-
64
- ${(0, import_cypher.mb)(
65
- `// Find all methods with specific name
66
- helpers.getDescendantsBy(args.current, (node) =>
67
- node.kind === args.ts.SyntaxKind.MethodDeclaration &&
68
- node.name?.getText() === 'getAll'
69
- );`,
70
- "typescript"
71
- )}
72
-
73
- ${(0, import_cypher.mb)(
74
- `// Find all nodes with decorators
75
- helpers.getDescendantsBy(args.current, (node) =>
76
- args.ts.canHaveDecorators(node) &&
77
- args.ts.getDecorators(node)?.length > 0
78
- );`,
79
- "typescript"
80
- )}
81
- `,
82
- getAncestorsBy: `Traverses up the TypeScript AST from a given node, collecting all ancestor nodes that match a custom predicate.
83
- It follows parent links from the starting node to the root, checking each ancestor against the predicate and adding matches to the results array.
84
- The traversal stops when it reaches a node without a parent (typically the SourceFile root), ensuring it doesn't attempt to access undefined parents.
85
- This provides a flexible way to find ancestor nodes based on any criteria (node kind, name, custom properties, etc.) rather than just syntax kind matching, and returns a type-safe array of matching ancestors cast to the specified generic type T, making it useful for finding containing scopes, parent declarations, or any higher-level context nodes in the AST hierarchy.
86
-
87
- Signature:
88
- function getAncestorsBy<T extends Node>(
89
- node: Node,
90
- predicate: (node: Node) => boolean,
91
- ): T[]
92
-
93
- **Use Case**: Finding containing scopes, parent declarations, or higher-level context nodes
94
-
95
- **Examples:**
96
- ${(0, import_cypher.mb)(
97
- `// Find containing class
98
- helpers.getAncestorsBy(args.current, (node) =>
99
- node.kind === args.ts.SyntaxKind.ClassDeclaration
100
- );`,
101
- "typescript"
102
- )}
103
-
104
- ${(0, import_cypher.mb)(
105
- `// Find containing function or method
106
- return helpers.getAncestorsBy(args.current, (node) =>
107
- node.kind === args.ts.SyntaxKind.FunctionDeclaration ||
108
- node.kind === args.ts.SyntaxKind.MethodDeclaration
109
- );`,
110
- "typescript"
111
- )}
112
- `,
113
- getType: `Resolves type information from any TypeScript AST node.
114
- It checks a node-based cache first, then routes by node type: for MethodDeclaration it extracts return types (explicit or inferred from call signatures), for PropertyDeclaration it prefers explicit type annotations and falls back to inferring from initializers, for TypeNode it processes explicit type annotations, and for Expression nodes it infers types from property initializers.
115
- For other nodes, it uses TypeScript's type checker to infer the type at the node's location.
116
- All resolved types are cached in the context's type resolution tracker before being returned, and the function gracefully handles errors by returning undefined.
117
- This provides a unified API for extracting type information regardless of whether types are explicitly annotated or inferred, making it ideal for code analysis tools that need consistent type resolution across different TypeScript code patterns.
118
-
119
- Signature:
120
- const getType = (
121
- node: ts.Node,
122
- typeChecker: ts.TypeChecker,
123
- typeResolutionTracker: TypeResolutionTracker,
124
- ): ts.Type[]
125
-
126
- **IMPORTANT**: To be consistent with other helpers the function will return array with single element if type is found and empty array if type is not found.
127
-
128
- **Use Case**: Extracting type information regardless of whether types are explicitly annotated or inferred
129
-
130
- **Examples:**
131
- ${(0, import_cypher.mb)(
132
- `// Get type of current node
133
- helpers.getType(args.current);`,
134
- "typescript"
135
- )}
136
- `,
137
- getDeclarations: `Extracts all TypeScript declaration nodes from either a ts.Type or ts.Node input, using multiple strategies.
138
- For nodes, it first checks if it's a TypeReferenceNode and extracts the symbol from the type name; if not, it tries getSymbolAtLocation for value nodes, then falls back to getTypeAtLocation for type nodes (recursively calling itself with the resolved type).
139
- For type inputs, it prioritizes type aliases by checking aliasSymbol first, then handles generic types by accessing the base type via the target property, and finally extracts declarations from the type's symbol.
140
- The function resolves symbol aliases internally and aggregates all found declarations (including multiple declarations from the same symbol) into a single array, making it a unified entry point for declaration extraction regardless of whether you're working with types or AST nodes, with graceful error handling that returns an empty array when no declarations can be found.
141
-
142
- Signature:
143
- const getDeclarations = (
144
- node: ts.Type | ts.Node,
145
- typeChecker: ts.TypeChecker,
146
- ): ts.Declaration[]
147
-
148
- **Use Case**: Unified entry point for declaration extraction regardless of whether you're working with types or AST nodes
149
-
150
- **Examples:**
151
- ${(0, import_cypher.mb)(
152
- `// Get declarations from current node
153
- helpers.getDeclarations(args.current);`,
154
- "typescript"
155
- )}
156
-
157
- ${(0, import_cypher.mb)(
158
- `// Get declarations from current node that are class declarations
159
- helpers.getDeclarations(args.current).filter(d =>
160
- d.kind === args.ts.SyntaxKind.ClassDeclaration
161
- );`,
162
- "typescript"
163
- )}
164
- `
165
- };
166
- const EXTRACTOR_DOC = `# Extractors
167
-
168
- You are given a great responsibility of running typescript code that you can use to extract information from the code.
169
-
170
- It can be used when extracting:
171
- - **properties** on GraphNodes
172
- - **relationships** between GraphNodes
173
-
174
- Your task is to provide missing code that will be injected in following extractor function:
175
-
176
- ${(0, import_cypher.mb)(
177
- `export function executeExtractor(code: string, context: ExtractorContext): any {
178
- // console.log('context: ', Object.keys(context));
179
- try {
180
- // Create a function with the context as parameters
181
- const fn = new Function(
182
- ...Object.keys(context),
183
- \`
184
- return \${code}
185
- \`,
186
- );
187
-
188
- return fn(...Object.values(context));
189
- } catch (error) {
190
- throw new Error('Extractor execution failed: ' + error.message);
191
- }
192
- }`,
193
- "typescript"
194
- )}
195
-
196
- ## Return Types
197
-
198
- The function can return anything, however CodeGraph supports the following return types:
199
-
200
- ### For Properties
201
- - **Primitive types**: \`string\`, \`number\`, \`boolean\`
202
- - **Arrays of primitives**: \`string[]\`, \`number[]\`, \`boolean[]\`
203
- - **null and undefined**: Allowed but will be ignored when returning the value (property won't be set on the node)
204
-
205
- ### For Relationships
206
- - **Arrays of nodes**: \`ts.Node[]\` or \`ts.Type[]\`
207
- - The returned nodes will be processed according to the nested \`nodeExtractors\` configuration
208
- - Each node in the array will create an edge from the source node to that target node
209
-
210
-
211
- **Example for Properties:**
212
- ${(0, import_cypher.mb)(
213
- `
214
- // Returns a string
215
- "name": "args.current.name?.getText();"
216
-
217
- // Returns a boolean
218
- "hasDecorators": "args.ts.getDecorators(args.current)?.length > 0 || false;"
219
-
220
- // Returns an array of strings
221
- "decoratorNames": "args.ts.getDecorators(args.current)?.map(d => d.expression.getText()) || [];"
222
- `,
223
- "typescript"
224
- )}
225
-
226
- **Example for Relationships:**
227
- ${(0, import_cypher.mb)(
228
- `
229
- // Returns array of MethodDeclaration nodes
230
- "extractorCode": "return helpers.getDescendantsBy(args.current, (node) => node.kind === args.ts.SyntaxKind.MethodDeclaration);"
231
-
232
- // Returns array of Type nodes
233
- "extractorCode": "const type = helpers.getType(args.current); return type ? [type] : [];"
234
-
235
- // Returns array of Declaration nodes
236
- "extractorCode": "return helpers.getDeclarations(args.current);"
237
- `,
238
- "typescript"
239
- )}
240
-
241
- ## ExtractorContext
242
-
243
- When your extractor code executes, it has access to the following context:
244
-
245
- ${(0, import_cypher.mb)(
246
- `
247
- export type ExtractorContext = {
248
- args: ExtractorArgumentContext; // data structures available in your context
249
- helpers: ExtractorHelpersContext; // helper functions available in your context
250
- };`,
251
- "typescript"
252
- )}
253
-
254
- ### ExtractorArgumentContext (args)
255
- ${Object.entries(EXTRACTOR_ARGUMENT_CONTEXT_DOC).map(([name, content]) => `- **\`${name}\`** - ${content}`).join("\n")}
256
-
257
- **Usage Examples:**
258
-
259
- ${(0, import_cypher.mb)(
260
- `// Access node name
261
- args.current.name?.getText();
262
-
263
- // Get file path
264
- args.sourceFile.fileName;
265
-
266
- // Check node kind
267
- args.current.kind === args.ts.SyntaxKind.ClassDeclaration;
268
-
269
- // Use type guards
270
- args.ts.isIdentifier(args.current);
271
- args.ts.isStringLiteral(args.current);`,
272
- "typescript"
273
- )}
274
-
275
- ### ExtractorHelpersContext (helpers)
276
-
277
- The \`helpers\` object provides utility functions for common operations:
278
-
279
- ${Object.entries(EXTRACTOR_HELPERS_DOC).map(([name, content]) => `#### ${name}
280
- ${content}`).join("\n")}
281
-
282
- ## Complete Examples
283
-
284
- ### Property Extractor Example
285
-
286
- ${(0, import_cypher.mb)(
287
- `
288
- {
289
- "properties": {
290
- "name": "args.current.name?.getText();",
291
- "filePath": "args.sourceFile.fileName;",
292
- "hasDecorators": "args.ts.getDecorators(args.current)?.length > 0 || false;",
293
- "decoratorNames": "args.ts.getDecorators(args.current)?.map(d => d.expression.getText()) || [];"
294
- }
295
- }
296
- `,
297
- "typescript"
298
- )}
299
-
300
- ### Relationship Extractor Example
301
- ${(0, import_cypher.mb)(
302
- `
303
- {
304
- "relationships": {
305
- "HAS_METHOD": {
306
- "extractorCode": "return helpers.getDescendantsBy(args.current, (node) => node.kind === args.ts.SyntaxKind.MethodDeclaration);",
307
- "nodeExtractors": {
308
- "MethodDeclaration": {
309
- "properties": {
310
- "name": "args.current.name?.getText();"
311
- }
312
- }
313
- }
314
- },
315
- "HAS_TYPE": {
316
- "extractorCode": "const type = helpers.getType(args.current); return type ? [type] : [];",
317
- "nodeExtractors": {
318
- "Type": {
319
- "relationships": {
320
- "HAS_DECLARATION": {
321
- "extractorCode": "return helpers.getDeclarations(args.current);",
322
- "nodeExtractors": {
323
- "ClassDeclaration": {
324
- "properties": {
325
- "name": "args.current.name?.getText();"
326
- }
327
- }
328
- }
329
- }
330
- }
331
- }
332
- }
333
- }
334
- }
335
- }
336
- `,
337
- "typescript"
338
- )}
339
- `;
340
- // Annotate the CommonJS export names for ESM import in node:
341
- 0 && (module.exports = {
342
- EXTRACTOR_ARGUMENT_CONTEXT_DOC,
343
- EXTRACTOR_DOC,
344
- EXTRACTOR_HELPERS_DOC
345
- });
@@ -1,52 +0,0 @@
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 extractor_exports = {};
19
- __export(extractor_exports, {
20
- executeExtractor: () => executeExtractor,
21
- extractNodeProperties: () => extractNodeProperties
22
- });
23
- module.exports = __toCommonJS(extractor_exports);
24
- const ts = require("typescript");
25
- function executeExtractor(code, context) {
26
- try {
27
- const fn = new Function(
28
- ...Object.keys(context),
29
- `
30
- return ${code}
31
- `
32
- );
33
- return fn(...Object.values(context));
34
- } catch (error) {
35
- throw new Error(`Extractor execution failed: ${error.message}`);
36
- }
37
- }
38
- function extractNodeProperties(context, propertyExectorMap = {}) {
39
- const properties = {};
40
- for (const [propertyName, extractorCode] of Object.entries(
41
- propertyExectorMap
42
- )) {
43
- const value = executeExtractor(extractorCode, context);
44
- properties[propertyName] = value;
45
- }
46
- return properties;
47
- }
48
- // Annotate the CommonJS export names for ESM import in node:
49
- 0 && (module.exports = {
50
- executeExtractor,
51
- extractNodeProperties
52
- });
@@ -1,23 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var extractors_exports = {};
16
- module.exports = __toCommonJS(extractors_exports);
17
- __reExport(extractors_exports, require("./extractor"), module.exports);
18
- __reExport(extractors_exports, require("./extractor.doc"), module.exports);
19
- // Annotate the CommonJS export names for ESM import in node:
20
- 0 && (module.exports = {
21
- ...require("./extractor"),
22
- ...require("./extractor.doc")
23
- });
@@ -1,76 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var code_graph_builder_exports = {};
29
- __export(code_graph_builder_exports, {
30
- buildCodeGraph: () => buildCodeGraph
31
- });
32
- module.exports = __toCommonJS(code_graph_builder_exports);
33
- var import_typescript = require("@cli/typescript");
34
- var import_codegular = require("@core/codegular");
35
- var ts = __toESM(require("typescript"));
36
- var import_node = require("./node.processor");
37
- const buildCodeGraph = (program, config) => {
38
- const codeGraph = {
39
- nodesById: {},
40
- edgesBySource: {},
41
- edgesByTarget: {}
42
- };
43
- const sourceFiles = (0, import_codegular.getSolutionSourceFiles)(program);
44
- const context = {
45
- typeChecker: program.getTypeChecker(),
46
- typeResolutionTracker: new import_typescript.TypeResolutionTracker(),
47
- declarationRegistry: new import_typescript.DeclarationRegistry()
48
- };
49
- sourceFiles.forEach((sourceFile) => {
50
- Object.keys(config.nodeExtractors).forEach((kindName) => {
51
- const nodes = (0, import_codegular.getDescendantsByKind)(sourceFile, ts.SyntaxKind[kindName]);
52
- nodes.forEach((node) => {
53
- const extractorContext = {
54
- args: {
55
- current: node,
56
- sourceFile,
57
- typeChecker: program.getTypeChecker(),
58
- ts
59
- },
60
- helpers: {
61
- getDescendantsBy: import_codegular.getDescendantsBy,
62
- getAncestorsBy: import_codegular.getAncestorsBy,
63
- getType: (node2) => (0, import_typescript.getType)(node2, context.typeChecker, context.typeResolutionTracker),
64
- getDeclarations: (node2) => (0, import_codegular.getDeclarations)(node2, context.typeChecker)
65
- }
66
- };
67
- (0, import_node.processNode)(extractorContext, config.nodeExtractors, codeGraph);
68
- });
69
- });
70
- });
71
- return codeGraph;
72
- };
73
- // Annotate the CommonJS export names for ESM import in node:
74
- 0 && (module.exports = {
75
- buildCodeGraph
76
- });
@@ -1,21 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var graph_builder_exports = {};
16
- module.exports = __toCommonJS(graph_builder_exports);
17
- __reExport(graph_builder_exports, require("./code-graph.builder"), module.exports);
18
- // Annotate the CommonJS export names for ESM import in node:
19
- 0 && (module.exports = {
20
- ...require("./code-graph.builder")
21
- });
@@ -1,48 +0,0 @@
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 node_processor_exports = {};
19
- __export(node_processor_exports, {
20
- processNode: () => processNode
21
- });
22
- module.exports = __toCommonJS(node_processor_exports);
23
- var import_typescript = require("@cli/typescript");
24
- var import_codegular = require("@core/codegular");
25
- var import_core = require("../../core/core");
26
- var import_extractors = require("../extractors");
27
- var import_relationship = require("./relationship.processor");
28
- const ts = require("typescript");
29
- const processNode = (context, nodeExtractors, codeGraph) => {
30
- const nodeId = (0, import_core.generateNodeId)({
31
- filePath: (0, import_codegular.getFilePath)(context.args.current),
32
- range: (0, import_codegular.getRange)(context.args.current)
33
- });
34
- const kindName = (0, import_typescript.getSyntaxKindName)(context.args.current.kind);
35
- const nodeConfig = nodeExtractors[kindName];
36
- const graphNode = {
37
- ...nodeConfig && nodeConfig.properties ? (0, import_extractors.extractNodeProperties)(context, nodeConfig.properties) : {},
38
- id: nodeId,
39
- labels: [kindName]
40
- };
41
- (0, import_typescript.addNode)(codeGraph, graphNode);
42
- (0, import_relationship.processRelationships)(nodeId, context, nodeConfig, codeGraph);
43
- return graphNode;
44
- };
45
- // Annotate the CommonJS export names for ESM import in node:
46
- 0 && (module.exports = {
47
- processNode
48
- });
@@ -1,79 +0,0 @@
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");
28
- function isTsNode(obj) {
29
- return obj && "kind" in obj && typeof obj.kind === "number";
30
- }
31
- function isTsType(obj) {
32
- return obj && "flags" in obj && typeof obj.flags === "number" && !("kind" in obj);
33
- }
34
- const processRelationships = (parentId, context, nodeConfig, codeGraph) => {
35
- if (nodeConfig?.relationships) {
36
- for (const relationshipName of Object.keys(nodeConfig.relationships)) {
37
- const relationshipExtractorFnCode = nodeConfig.relationships[relationshipName].extractorCode;
38
- const relationshipNodeExtractors = nodeConfig.relationships[relationshipName].nodeExtractors;
39
- Object.keys(relationshipNodeExtractors).forEach((label) => {
40
- const children = (0, import_extractors.executeExtractor)(relationshipExtractorFnCode, context);
41
- children.forEach(
42
- (child) => {
43
- if (isTsType(child)) {
44
- const childNode = (0, import_type.processType)(
45
- { ...context, args: { ...context.args, current: child } },
46
- relationshipNodeExtractors,
47
- codeGraph
48
- );
49
- (0, import_typescript.addEdge)(codeGraph, {
50
- source: parentId,
51
- target: childNode.id,
52
- type: relationshipName
53
- });
54
- } else if (isTsNode(child)) {
55
- const childNode = (0, import_node.processNode)(
56
- { ...context, args: { ...context.args, current: child } },
57
- relationshipNodeExtractors,
58
- codeGraph
59
- );
60
- (0, import_typescript.addEdge)(codeGraph, {
61
- source: parentId,
62
- target: childNode.id,
63
- type: relationshipName
64
- });
65
- } else {
66
- throw new Error(
67
- `The code provided: ${relationshipExtractorFnCode} returned an invalid child: ${child}. We support only ts.Node and ts.Type array returns from executed code`
68
- );
69
- }
70
- }
71
- );
72
- });
73
- }
74
- }
75
- };
76
- // Annotate the CommonJS export names for ESM import in node:
77
- 0 && (module.exports = {
78
- processRelationships
79
- });