@lowgular/code-graph 0.0.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.
- package/apps/code-graph/src/main.js +50 -0
- package/libs/cli/code-graph/src/index.js +39 -0
- package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +72 -0
- package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +68 -0
- package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +147 -0
- package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +55 -0
- package/libs/cli/code-graph/src/lib/class-declarations/index.js +27 -0
- package/libs/cli/code-graph/src/lib/code.graph.factory.js +63 -0
- package/libs/cli/code-graph/src/lib/code.graph.js +62 -0
- package/libs/cli/code-graph/src/lib/core/core.js +58 -0
- package/libs/cli/code-graph/src/lib/core.js +85 -0
- package/libs/cli/code-graph/src/lib/decorators/index.js +36 -0
- package/libs/cli/code-graph/src/lib/docs/index.js +21 -0
- package/libs/cli/code-graph/src/lib/docs/specs.js +36 -0
- package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +28 -0
- package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +53 -0
- package/libs/cli/code-graph/src/lib/method-declarations/index.js +23 -0
- package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +106 -0
- package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +56 -0
- package/libs/cli/code-graph/src/lib/parameters/index.js +42 -0
- package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +139 -0
- package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +104 -0
- package/libs/cli/code-graph/src/lib/property-declarations/index.js +25 -0
- package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +74 -0
- package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +43 -0
- package/libs/cli/code-graph/src/lib/tools/index.js +34 -0
- package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +64 -0
- package/libs/cli/code-graph/src/lib/types/index.js +99 -0
- package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +345 -0
- package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +52 -0
- package/libs/cli/code-graph/src/lib/v2/extractors/index.js +23 -0
- package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +76 -0
- package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +21 -0
- package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +48 -0
- package/libs/cli/code-graph/src/lib/v2/graph-builder/relationship.processor.js +79 -0
- package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +45 -0
- package/libs/cli/code-graph/src/lib/v2/index.js +37 -0
- package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +220 -0
- package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +42 -0
- package/libs/cli/cypher/src/index.js +25 -0
- package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +277 -0
- package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +69 -0
- package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +105 -0
- package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +70 -0
- package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +99 -0
- package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +125 -0
- package/libs/cli/cypher/src/lib/docs/features/index.js +51 -0
- package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +50 -0
- package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +106 -0
- package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +105 -0
- package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +143 -0
- package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +152 -0
- package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +48 -0
- package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +65 -0
- package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +82 -0
- package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +136 -0
- package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +187 -0
- package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +302 -0
- package/libs/cli/cypher/src/lib/docs/prompts.js +36 -0
- package/libs/cli/cypher/src/lib/docs/specs.js +181 -0
- package/libs/cli/cypher/src/lib/executor/condition-evaluator.js +158 -0
- package/libs/cli/cypher/src/lib/executor/executor.js +83 -0
- package/libs/cli/cypher/src/lib/executor/graph.js +15 -0
- package/libs/cli/cypher/src/lib/executor/match-engine.js +153 -0
- package/libs/cli/cypher/src/lib/executor/pattern-matcher.js +109 -0
- package/libs/cli/cypher/src/lib/executor/relationship-navigator.js +64 -0
- package/libs/cli/cypher/src/lib/executor/result-formatter.js +143 -0
- package/libs/cli/cypher/src/lib/executor/traverse-engine.js +164 -0
- package/libs/cli/cypher/src/lib/executor/utils.js +37 -0
- package/libs/cli/cypher/src/lib/graph.stub.js +63 -0
- package/libs/cli/cypher/src/lib/index.js +74 -0
- package/libs/cli/cypher/src/lib/lexer.js +398 -0
- package/libs/cli/cypher/src/lib/parser.js +602 -0
- package/libs/cli/cypher/src/lib/validator/query-validator.js +95 -0
- package/libs/cli/cypher/src/lib/validator/supported-features.config.js +111 -0
- package/libs/cli/cypher/src/lib/validator/unsupported-features.config.js +150 -0
- package/libs/cli/shared/src/index.js +53 -0
- package/libs/cli/shared/src/lib/admin-token.js +121 -0
- package/libs/cli/shared/src/lib/config.js +49 -0
- package/libs/cli/shared/src/lib/consts.js +57 -0
- package/libs/cli/shared/src/lib/core.js +46 -0
- package/libs/cli/shared/src/lib/infrastructure/cli.js +47 -0
- package/libs/cli/shared/src/lib/infrastructure/config.js +47 -0
- package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +51 -0
- package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +96 -0
- package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +41 -0
- package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +64 -0
- package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +120 -0
- package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +15 -0
- package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +72 -0
- package/libs/cli/shared/src/lib/infrastructure/git.js +147 -0
- package/libs/cli/shared/src/lib/infrastructure/http.js +257 -0
- package/libs/cli/shared/src/lib/infrastructure/markdown.js +95 -0
- package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +88 -0
- package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +25 -0
- package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +154 -0
- package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +210 -0
- package/libs/cli/shared/src/lib/infrastructure/workspace.js +297 -0
- package/libs/cli/shared/src/lib/infrastructure/yaml.js +237 -0
- package/libs/cli/shared/src/lib/lowgular.config.js +120 -0
- package/libs/cli/shared/src/lib/token.js +135 -0
- package/libs/cli/shared/src/lib/utils/solution.util.js +35 -0
- package/libs/cli/shared/src/lib/utils/utils.js +89 -0
- package/libs/cli/typescript/src/index.js +21 -0
- package/libs/cli/typescript/src/lib/base/index.js +23 -0
- package/libs/cli/typescript/src/lib/base/nameable.js +34 -0
- package/libs/cli/typescript/src/lib/base/nodeable.js +36 -0
- package/libs/cli/typescript/src/lib/class.implementation.js +52 -0
- package/libs/cli/typescript/src/lib/core/declaration.registry.js +107 -0
- package/libs/cli/typescript/src/lib/core/design-pattern.js +55 -0
- package/libs/cli/typescript/src/lib/core/index.js +35 -0
- package/libs/cli/typescript/src/lib/core/navigable-declaration.js +69 -0
- package/libs/cli/typescript/src/lib/core/program-context.js +71 -0
- package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +40 -0
- package/libs/cli/typescript/src/lib/core/type.js +374 -0
- package/libs/cli/typescript/src/lib/declaration.abstraction.js +90 -0
- package/libs/cli/typescript/src/lib/decorator.implementation.js +35 -0
- package/libs/cli/typescript/src/lib/enum.implementation.js +35 -0
- package/libs/cli/typescript/src/lib/function-declaration.implementation.js +35 -0
- package/libs/cli/typescript/src/lib/index.js +57 -0
- package/libs/cli/typescript/src/lib/interface.implementation.js +51 -0
- package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +90 -0
- package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +44 -0
- package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +46 -0
- package/libs/cli/typescript/src/lib/members/method.util.js +32 -0
- package/libs/cli/typescript/src/lib/members/parameter.implementation.js +38 -0
- package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +64 -0
- package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +34 -0
- package/libs/cli/typescript/src/lib/members/property.util.js +61 -0
- package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +42 -0
- package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +114 -0
- package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +188 -0
- package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +35 -0
- package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +51 -0
- package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +49 -0
- package/libs/cli/typescript/src/lib/members/statements/utils.js +51 -0
- package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +258 -0
- package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +15 -0
- package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +228 -0
- package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +126 -0
- package/libs/cli/typescript/src/lib/plugins/stubs.js +66 -0
- package/libs/cli/typescript/src/lib/type-alias.implementation.js +72 -0
- package/libs/cli/typescript/src/lib/utils.js +39 -0
- package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +35 -0
- package/libs/core/codegular/src/index.js +21 -0
- package/libs/core/codegular/src/lib/index.js +29 -0
- package/libs/core/codegular/src/lib/node.js +112 -0
- package/libs/core/codegular/src/lib/program.js +92 -0
- package/libs/core/codegular/src/lib/string.js +168 -0
- package/libs/core/codegular/src/lib/type-checker.js +170 -0
- package/libs/core/codegular/src/lib/utils.js +347 -0
- package/main.js +43 -0
- package/package.json +12 -0
|
@@ -0,0 +1,345 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
});
|