@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.
- package/bin/cli.js +10 -0
- package/code-graph-v2/code.graph.js +37 -0
- package/code-graph-v2/config-from-query.js +131 -0
- package/code-graph-v2/extractors/extractor.js +27 -0
- package/code-graph-v2/extractors/index.js +1 -0
- package/code-graph-v2/graph-builder/code-graph.builder.js +49 -0
- package/code-graph-v2/graph-builder/index.js +1 -0
- package/code-graph-v2/graph-builder/node.processor.js +22 -0
- package/{libs/cli/code-graph/src/lib/v2 → code-graph-v2}/graph-builder/relationship.processor.js +11 -35
- package/code-graph-v2/graph-builder/type.processor.js +21 -0
- package/code-graph-v2/index.js +4 -0
- package/code-graph-v2/tools/build-code-graph.tool.js +19 -0
- package/code-graph-v2/utils.js +34 -0
- package/codegular/index.js +5 -0
- package/codegular/node.js +71 -0
- package/codegular/program.js +100 -0
- package/{libs/core/codegular/src/lib → codegular}/string.js +6 -53
- package/{libs/core/codegular/src/lib → codegular}/type-checker.js +3 -40
- package/codegular/type.js +356 -0
- package/{libs/core/codegular/src/lib → codegular}/utils.js +50 -62
- package/cypher/index.js +1 -0
- package/{libs/cli/cypher/src → cypher}/lib/executor/condition-evaluator.js +2 -25
- package/cypher/lib/executor/executor.js +60 -0
- package/cypher/lib/executor/graph.js +0 -0
- package/{libs/cli/cypher/src → cypher}/lib/executor/match-engine.js +4 -27
- package/{libs/cli/cypher/src → cypher}/lib/executor/pattern-matcher.js +2 -25
- package/{libs/cli/cypher/src → cypher}/lib/executor/relationship-navigator.js +2 -25
- package/{libs/cli/cypher/src → cypher}/lib/executor/result-formatter.js +37 -31
- package/{libs/cli/cypher/src → cypher}/lib/executor/traverse-engine.js +4 -27
- package/cypher/lib/executor/utils.js +14 -0
- package/cypher/lib/graph.stub.js +38 -0
- package/cypher/lib/index.js +32 -0
- package/{libs/cli/cypher/src → cypher}/lib/lexer.js +4 -26
- package/{libs/cli/cypher/src → cypher}/lib/parser.js +119 -135
- package/{libs/cli/cypher/src → cypher}/lib/validator/query-validator.js +12 -32
- package/{libs/cli/cypher/src → cypher}/lib/validator/supported-features.config.js +2 -30
- package/{libs/cli/cypher/src → cypher}/lib/validator/unsupported-features.config.js +8 -34
- package/cypher-cli.js +41 -0
- package/infra/code-graph.js +147 -0
- package/main.js +0 -43
- package/package.json +25 -7
- package/resources-cli.js +75 -0
- package/run-cli.js +43 -0
- package/apps/code-graph/src/main.js +0 -50
- package/libs/cli/code-graph/src/index.js +0 -39
- package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +0 -72
- package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +0 -68
- package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +0 -147
- package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +0 -55
- package/libs/cli/code-graph/src/lib/class-declarations/index.js +0 -27
- package/libs/cli/code-graph/src/lib/code.graph.factory.js +0 -63
- package/libs/cli/code-graph/src/lib/code.graph.js +0 -62
- package/libs/cli/code-graph/src/lib/core/core.js +0 -58
- package/libs/cli/code-graph/src/lib/core.js +0 -85
- package/libs/cli/code-graph/src/lib/decorators/index.js +0 -36
- package/libs/cli/code-graph/src/lib/docs/index.js +0 -21
- package/libs/cli/code-graph/src/lib/docs/specs.js +0 -36
- package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +0 -28
- package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +0 -53
- package/libs/cli/code-graph/src/lib/method-declarations/index.js +0 -23
- package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +0 -106
- package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +0 -56
- package/libs/cli/code-graph/src/lib/parameters/index.js +0 -42
- package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +0 -139
- package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +0 -104
- package/libs/cli/code-graph/src/lib/property-declarations/index.js +0 -25
- package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +0 -74
- package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +0 -43
- package/libs/cli/code-graph/src/lib/tools/index.js +0 -34
- package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +0 -64
- package/libs/cli/code-graph/src/lib/types/index.js +0 -99
- package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +0 -345
- package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +0 -52
- package/libs/cli/code-graph/src/lib/v2/extractors/index.js +0 -23
- package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +0 -76
- package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +0 -21
- package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +0 -48
- package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +0 -45
- package/libs/cli/code-graph/src/lib/v2/index.js +0 -37
- package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +0 -220
- package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +0 -42
- package/libs/cli/cypher/src/index.js +0 -25
- package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +0 -277
- package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +0 -69
- package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +0 -105
- package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +0 -70
- package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +0 -99
- package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +0 -125
- package/libs/cli/cypher/src/lib/docs/features/index.js +0 -51
- package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +0 -50
- package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +0 -106
- package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +0 -105
- package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +0 -143
- package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +0 -152
- package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +0 -48
- package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +0 -65
- package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +0 -82
- package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +0 -136
- package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +0 -187
- package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +0 -302
- package/libs/cli/cypher/src/lib/docs/prompts.js +0 -36
- package/libs/cli/cypher/src/lib/docs/specs.js +0 -181
- package/libs/cli/cypher/src/lib/executor/executor.js +0 -83
- package/libs/cli/cypher/src/lib/executor/graph.js +0 -15
- package/libs/cli/cypher/src/lib/executor/utils.js +0 -37
- package/libs/cli/cypher/src/lib/graph.stub.js +0 -63
- package/libs/cli/cypher/src/lib/index.js +0 -74
- package/libs/cli/shared/src/index.js +0 -53
- package/libs/cli/shared/src/lib/admin-token.js +0 -121
- package/libs/cli/shared/src/lib/config.js +0 -49
- package/libs/cli/shared/src/lib/consts.js +0 -57
- package/libs/cli/shared/src/lib/core.js +0 -46
- package/libs/cli/shared/src/lib/infrastructure/cli.js +0 -47
- package/libs/cli/shared/src/lib/infrastructure/config.js +0 -47
- package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +0 -51
- package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +0 -96
- package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +0 -41
- package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +0 -64
- package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +0 -120
- package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +0 -15
- package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +0 -72
- package/libs/cli/shared/src/lib/infrastructure/git.js +0 -147
- package/libs/cli/shared/src/lib/infrastructure/http.js +0 -257
- package/libs/cli/shared/src/lib/infrastructure/markdown.js +0 -95
- package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +0 -88
- package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +0 -25
- package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +0 -154
- package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +0 -210
- package/libs/cli/shared/src/lib/infrastructure/workspace.js +0 -297
- package/libs/cli/shared/src/lib/infrastructure/yaml.js +0 -237
- package/libs/cli/shared/src/lib/lowgular.config.js +0 -120
- package/libs/cli/shared/src/lib/token.js +0 -135
- package/libs/cli/shared/src/lib/utils/solution.util.js +0 -35
- package/libs/cli/shared/src/lib/utils/utils.js +0 -89
- package/libs/cli/typescript/src/index.js +0 -21
- package/libs/cli/typescript/src/lib/base/index.js +0 -23
- package/libs/cli/typescript/src/lib/base/nameable.js +0 -34
- package/libs/cli/typescript/src/lib/base/nodeable.js +0 -36
- package/libs/cli/typescript/src/lib/class.implementation.js +0 -52
- package/libs/cli/typescript/src/lib/core/declaration.registry.js +0 -107
- package/libs/cli/typescript/src/lib/core/design-pattern.js +0 -55
- package/libs/cli/typescript/src/lib/core/index.js +0 -35
- package/libs/cli/typescript/src/lib/core/navigable-declaration.js +0 -69
- package/libs/cli/typescript/src/lib/core/program-context.js +0 -71
- package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +0 -40
- package/libs/cli/typescript/src/lib/core/type.js +0 -374
- package/libs/cli/typescript/src/lib/declaration.abstraction.js +0 -90
- package/libs/cli/typescript/src/lib/decorator.implementation.js +0 -35
- package/libs/cli/typescript/src/lib/enum.implementation.js +0 -35
- package/libs/cli/typescript/src/lib/function-declaration.implementation.js +0 -35
- package/libs/cli/typescript/src/lib/index.js +0 -57
- package/libs/cli/typescript/src/lib/interface.implementation.js +0 -51
- package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +0 -90
- package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +0 -44
- package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +0 -46
- package/libs/cli/typescript/src/lib/members/method.util.js +0 -32
- package/libs/cli/typescript/src/lib/members/parameter.implementation.js +0 -38
- package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +0 -64
- package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +0 -34
- package/libs/cli/typescript/src/lib/members/property.util.js +0 -61
- package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +0 -42
- package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +0 -114
- package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +0 -188
- package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +0 -35
- package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +0 -51
- package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +0 -49
- package/libs/cli/typescript/src/lib/members/statements/utils.js +0 -51
- package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +0 -258
- package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +0 -15
- package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +0 -228
- package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +0 -126
- package/libs/cli/typescript/src/lib/plugins/stubs.js +0 -66
- package/libs/cli/typescript/src/lib/type-alias.implementation.js +0 -72
- package/libs/cli/typescript/src/lib/utils.js +0 -39
- package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +0 -35
- package/libs/core/codegular/src/index.js +0 -21
- package/libs/core/codegular/src/lib/index.js +0 -29
- package/libs/core/codegular/src/lib/node.js +0 -112
- package/libs/core/codegular/src/lib/program.js +0 -92
|
@@ -1,30 +1,3 @@
|
|
|
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 supported_features_config_exports = {};
|
|
19
|
-
__export(supported_features_config_exports, {
|
|
20
|
-
ERROR_HANDLING_ITEMS: () => ERROR_HANDLING_ITEMS,
|
|
21
|
-
NODE_CONSTRAINTS: () => NODE_CONSTRAINTS,
|
|
22
|
-
PATTERN_CONSTRAINTS: () => PATTERN_CONSTRAINTS,
|
|
23
|
-
QUERY_CONSTRAINTS: () => QUERY_CONSTRAINTS,
|
|
24
|
-
RELATIONSHIP_CONSTRAINTS: () => RELATIONSHIP_CONSTRAINTS,
|
|
25
|
-
RESULT_FORMAT_ITEMS: () => RESULT_FORMAT_ITEMS
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(supported_features_config_exports);
|
|
28
1
|
const NODE_CONSTRAINTS = [
|
|
29
2
|
{
|
|
30
3
|
description: "Nodes can have multiple labels (:A:B means must have A AND B and :A|B means must have A OR B)"
|
|
@@ -100,12 +73,11 @@ const ERROR_HANDLING_ITEMS = [
|
|
|
100
73
|
description: "Using FORBIDDEN features will cause errors"
|
|
101
74
|
}
|
|
102
75
|
];
|
|
103
|
-
|
|
104
|
-
0 && (module.exports = {
|
|
76
|
+
export {
|
|
105
77
|
ERROR_HANDLING_ITEMS,
|
|
106
78
|
NODE_CONSTRAINTS,
|
|
107
79
|
PATTERN_CONSTRAINTS,
|
|
108
80
|
QUERY_CONSTRAINTS,
|
|
109
81
|
RELATIONSHIP_CONSTRAINTS,
|
|
110
82
|
RESULT_FORMAT_ITEMS
|
|
111
|
-
}
|
|
83
|
+
};
|
|
@@ -1,29 +1,3 @@
|
|
|
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 unsupported_features_config_exports = {};
|
|
19
|
-
__export(unsupported_features_config_exports, {
|
|
20
|
-
FORBIDDEN_AGGREGATIONS: () => FORBIDDEN_AGGREGATIONS,
|
|
21
|
-
FORBIDDEN_FEATURES: () => FORBIDDEN_FEATURES,
|
|
22
|
-
FORBIDDEN_KEYWORDS: () => FORBIDDEN_KEYWORDS,
|
|
23
|
-
FORBIDDEN_MODIFIERS: () => FORBIDDEN_MODIFIERS,
|
|
24
|
-
FORBIDDEN_PATTERNS: () => FORBIDDEN_PATTERNS
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(unsupported_features_config_exports);
|
|
27
1
|
const FORBIDDEN_KEYWORDS = [
|
|
28
2
|
{
|
|
29
3
|
pattern: /\bWITH\b/i,
|
|
@@ -55,12 +29,13 @@ const FORBIDDEN_KEYWORDS = [
|
|
|
55
29
|
pattern: /\bDELETE\b/i,
|
|
56
30
|
name: "DELETE clause",
|
|
57
31
|
errorMessage: "DELETE clause is not supported. This is a read-only query engine (no mutations)."
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
pattern: /\bSET\b/i,
|
|
61
|
-
name: "SET clause",
|
|
62
|
-
errorMessage: "SET clause is not supported. This is a read-only query engine (no mutations)."
|
|
63
32
|
}
|
|
33
|
+
// {
|
|
34
|
+
// pattern: /\bSET\b/i,
|
|
35
|
+
// name: 'SET clause',
|
|
36
|
+
// errorMessage:
|
|
37
|
+
// 'SET clause is not supported. This is a read-only query engine (no mutations).',
|
|
38
|
+
// },
|
|
64
39
|
];
|
|
65
40
|
const FORBIDDEN_AGGREGATIONS = [
|
|
66
41
|
{
|
|
@@ -140,11 +115,10 @@ const FORBIDDEN_FEATURES = [
|
|
|
140
115
|
description: "Nested queries not supported"
|
|
141
116
|
}
|
|
142
117
|
];
|
|
143
|
-
|
|
144
|
-
0 && (module.exports = {
|
|
118
|
+
export {
|
|
145
119
|
FORBIDDEN_AGGREGATIONS,
|
|
146
120
|
FORBIDDEN_FEATURES,
|
|
147
121
|
FORBIDDEN_KEYWORDS,
|
|
148
122
|
FORBIDDEN_MODIFIERS,
|
|
149
123
|
FORBIDDEN_PATTERNS
|
|
150
|
-
}
|
|
124
|
+
};
|
package/cypher-cli.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const command = "cypher";
|
|
2
|
+
const describe = "Print supported Cypher syntax and constraints (MATCH, WHERE, RETURN, etc.).";
|
|
3
|
+
const builder = (yargs) => yargs;
|
|
4
|
+
function handler() {
|
|
5
|
+
console.log(CYPHER_REFERENCE);
|
|
6
|
+
}
|
|
7
|
+
const CYPHER_REFERENCE = `# Cypher reference (code-graph dialect)
|
|
8
|
+
|
|
9
|
+
Unsupported features (e.g. CREATE, MERGE, path ranges like *1..3) will error \u2014 see validator if needed.
|
|
10
|
+
|
|
11
|
+
MATCH, WHERE, RETURN, ORDER BY, LIMIT, OPTIONAL MATCH, and variable-length paths are supported.
|
|
12
|
+
|
|
13
|
+
## MATCH
|
|
14
|
+
(n:Label), (n:Label { prop: 'value' }), (a)-[:REL]->(b), (a)<-[:REL]-(b)
|
|
15
|
+
Variable-length: (a)-[*]->(b)
|
|
16
|
+
Multiple labels: (n:A:B) AND, (n:A|B) OR. Multiple rel types: [:R1|R2]
|
|
17
|
+
OPTIONAL MATCH for left outer joins.
|
|
18
|
+
|
|
19
|
+
## WHERE
|
|
20
|
+
=, !=, >, <, >=, <=
|
|
21
|
+
IN [...], NOT IN [...]
|
|
22
|
+
IS NULL, IS NOT NULL
|
|
23
|
+
STARTS WITH, ENDS WITH, CONTAINS, =~ 'regex'
|
|
24
|
+
Same logic for whole clause: all AND or all OR (no mixing).
|
|
25
|
+
|
|
26
|
+
## RETURN
|
|
27
|
+
RETURN n, m | RETURN * | RETURN n AS alias
|
|
28
|
+
RETURN DISTINCT n | RETURN n LIMIT 10
|
|
29
|
+
|
|
30
|
+
## ORDER BY
|
|
31
|
+
ORDER BY n.name ASC | DESC, multiple fields supported.
|
|
32
|
+
|
|
33
|
+
## Constraints
|
|
34
|
+
RETURN required. Node properties flat, primitives only. Edges: source, target, type (no edge properties). Variable-length only * (no *1..3 etc).
|
|
35
|
+
`;
|
|
36
|
+
export {
|
|
37
|
+
builder,
|
|
38
|
+
command,
|
|
39
|
+
describe,
|
|
40
|
+
handler
|
|
41
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildCodeGraph,
|
|
3
|
+
buildConfigFromQuery
|
|
4
|
+
} from "../code-graph-v2/index.js";
|
|
5
|
+
import {
|
|
6
|
+
createProgramFromFileSystem,
|
|
7
|
+
createProgramFromTsConfig
|
|
8
|
+
} from "../codegular/index.js";
|
|
9
|
+
import { buildQueryObject, query } from "../cypher/index.js";
|
|
10
|
+
const matchFromGeneratedFiles = (cypherQuery, config, generatedFiles) => {
|
|
11
|
+
const fileSystem = generatedFiles.reduce((acc, file) => {
|
|
12
|
+
if (file.filePath.endsWith(".ts")) {
|
|
13
|
+
acc[file.filePath] = file.code;
|
|
14
|
+
}
|
|
15
|
+
return acc;
|
|
16
|
+
}, {});
|
|
17
|
+
return matchFromFileSystem(cypherQuery, config, fileSystem);
|
|
18
|
+
};
|
|
19
|
+
const matchFromFileSystem = (cypherQuery, config, fileSystem) => {
|
|
20
|
+
const program = createProgramFromFileSystem(fileSystem);
|
|
21
|
+
const codeGraph = buildCodeGraph(program, config);
|
|
22
|
+
const results = query(cypherQuery, codeGraph);
|
|
23
|
+
return results;
|
|
24
|
+
};
|
|
25
|
+
const mapGeneratedFilesToFileSystem = (generatedFiles) => {
|
|
26
|
+
return generatedFiles.reduce(
|
|
27
|
+
(acc, file) => {
|
|
28
|
+
acc[file.filePath] = file.code;
|
|
29
|
+
return acc;
|
|
30
|
+
},
|
|
31
|
+
{}
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
const resolveProgramFromConfig = (env) => {
|
|
35
|
+
return env.tsConfig ? createProgramFromTsConfig(env.tsConfig) : createProgramFromFileSystem(
|
|
36
|
+
mapGeneratedFilesToFileSystem(env.generatedFiles)
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
const autoMatch = (cypherQuery, program, options) => {
|
|
40
|
+
const queryObject = buildQueryObject(cypherQuery);
|
|
41
|
+
const config = buildConfigFromQuery(queryObject);
|
|
42
|
+
const codeGraph = buildCodeGraph(program, config);
|
|
43
|
+
const results = query(cypherQuery, codeGraph);
|
|
44
|
+
return options?.skipRewrite ? results : rewriteOccurenceOf(results);
|
|
45
|
+
};
|
|
46
|
+
const PATH_ANCHOR_SRC_APP = "src/app";
|
|
47
|
+
const rewriteUntilPath = (pathOrNodeId, pathAnchor) => {
|
|
48
|
+
const searchSegment = pathAnchor.startsWith("/") && pathAnchor.endsWith("/") ? pathAnchor : `/${pathAnchor.replace(/^\/|\/$/g, "")}/`;
|
|
49
|
+
const idx = pathOrNodeId.lastIndexOf(searchSegment);
|
|
50
|
+
if (idx < 0)
|
|
51
|
+
return pathOrNodeId;
|
|
52
|
+
const sliced = pathOrNodeId.slice(idx);
|
|
53
|
+
return sliced.startsWith("/") ? sliced.slice(1) : sliced;
|
|
54
|
+
};
|
|
55
|
+
const rewriteOccurenceOf = (result) => {
|
|
56
|
+
return result.map((result2) => {
|
|
57
|
+
return Object.keys(result2).reduce((acc, key) => {
|
|
58
|
+
if (!result2[key]) {
|
|
59
|
+
return acc;
|
|
60
|
+
}
|
|
61
|
+
const id = result2[key]["id"];
|
|
62
|
+
if (!id) {
|
|
63
|
+
return acc;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...acc,
|
|
67
|
+
[key]: {
|
|
68
|
+
...result2[key],
|
|
69
|
+
id: rewriteUntilPath(id, PATH_ANCHOR_SRC_APP)
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}, {});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
const filterResultsByGeneratedFiles = (results, generatedFiles) => {
|
|
76
|
+
const filePaths = generatedFiles.map((file) => file.filePath);
|
|
77
|
+
return results.filter(
|
|
78
|
+
(result) => Object.values(result).find(
|
|
79
|
+
(n) => filePaths.includes(n["id"].split(".")[0] + ".ts")
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
const autoMatchFromGeneratedFiles = (cypherQuery, generatedFiles) => {
|
|
84
|
+
const queryObject = buildQueryObject(cypherQuery);
|
|
85
|
+
const config = buildConfigFromQuery(queryObject);
|
|
86
|
+
return matchFromGeneratedFiles(cypherQuery, config, generatedFiles);
|
|
87
|
+
};
|
|
88
|
+
const NODE_PROPERTIES_PRESET = {
|
|
89
|
+
NAMEABLE: {
|
|
90
|
+
name: `helpers.getDescendantsBy(args.current, (node) => node.kind === args.ts.SyntaxKind.Identifier)[0]?.getText();`,
|
|
91
|
+
filePath: "args.sourceFile.fileName;"
|
|
92
|
+
},
|
|
93
|
+
/**
|
|
94
|
+
* Creates a preset that extracts a property value from an ObjectLiteralExpression
|
|
95
|
+
* @param key - The property name to look for in the object literal
|
|
96
|
+
* @returns An extractor code string that finds the property and returns its initializer text
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* properties: {
|
|
101
|
+
* selector: NODE_PROPERTIES_PRESET.OBJECT_PROPERTY('selector'),
|
|
102
|
+
* template: NODE_PROPERTIES_PRESET.OBJECT_PROPERTY('template'),
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
OBJECT_LITERAL_PROPERTY: (key, valueFns = []) => {
|
|
107
|
+
return `(function() {
|
|
108
|
+
const objectLiterals = helpers.getDescendantsBy(
|
|
109
|
+
args.current,
|
|
110
|
+
(node) => node.kind === args.ts.SyntaxKind.ObjectLiteralExpression
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
for (const objLiteral of objectLiterals) {
|
|
114
|
+
if (args.ts.isObjectLiteralExpression(objLiteral)) {
|
|
115
|
+
for (const property of objLiteral.properties) {
|
|
116
|
+
if (args.ts.isPropertyAssignment(property)) {
|
|
117
|
+
const propName = property.name;
|
|
118
|
+
let propNameText = '';
|
|
119
|
+
|
|
120
|
+
if (args.ts.isIdentifier(propName)) {
|
|
121
|
+
propNameText = propName.text;
|
|
122
|
+
} else if (args.ts.isStringLiteral(propName)) {
|
|
123
|
+
propNameText = propName.text;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (propNameText === '${key}') {
|
|
127
|
+
const value = property.initializer?.getText() || null;
|
|
128
|
+
return [${valueFns.join(", ")}].reduce((acc, valueFn) => valueFn(acc), value);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
})();`;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
export {
|
|
139
|
+
NODE_PROPERTIES_PRESET,
|
|
140
|
+
autoMatch,
|
|
141
|
+
autoMatchFromGeneratedFiles,
|
|
142
|
+
filterResultsByGeneratedFiles,
|
|
143
|
+
matchFromFileSystem,
|
|
144
|
+
matchFromGeneratedFiles,
|
|
145
|
+
resolveProgramFromConfig,
|
|
146
|
+
rewriteUntilPath
|
|
147
|
+
};
|
package/main.js
CHANGED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
const Module = require("module");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const originalResolveFilename = Module._resolveFilename;
|
|
5
|
-
const distPath = __dirname;
|
|
6
|
-
const manifest = [{ "module": "@features/practice-solutions/api", "exactMatch": "libs/features/practice-solutions/api/src/index.js", "pattern": "libs/features/practice-solutions/api/src/index.ts" }, { "module": "@core/code-snapshot/api", "exactMatch": "libs/core/code-snapshot/api/src/index.js", "pattern": "libs/core/code-snapshot/api/src/index.ts" }, { "module": "@platform/challenge/solution", "exactMatch": "libs/platform/challenge/solution/src/index.js", "pattern": "libs/platform/challenge/solution/src/index.ts" }, { "module": "@core/story-points/api", "exactMatch": "libs/core/story-points/api/src/index.js", "pattern": "libs/core/story-points/api/src/index.ts" }, { "module": "@core/story-points/platform", "exactMatch": "libs/core/story-points/platform/src/index.js", "pattern": "libs/core/story-points/platform/src/index.ts" }, { "module": "@shared/http-utils/api", "exactMatch": "libs/shared/http-utils/api/src/index.js", "pattern": "libs/shared/http-utils/api/src/index.ts" }, { "module": "@academy/features/articles", "exactMatch": "libs/features/articles/academy/src/index.js", "pattern": "libs/features/articles/academy/src/index.ts" }, { "module": "@academy/features/code-snapshot-review", "exactMatch": "libs/features/code-snapshot-review/academy/src/index.js", "pattern": "libs/features/code-snapshot-review/academy/src/index.ts" }, { "module": "@academy/features/code-solutions", "exactMatch": "libs/features/code-solutions/academy/src/index.js", "pattern": "libs/features/code-solutions/academy/src/index.ts" }, { "module": "@academy/features/content", "exactMatch": "libs/features/content/academy/src/index.js", "pattern": "libs/features/content/academy/src/index.ts" }, { "module": "@academy/features/ide", "exactMatch": "libs/features/ide/academy/src/index.js", "pattern": "libs/features/ide/academy/src/index.ts" }, { "module": "@academy/features/modules", "exactMatch": "libs/features/modules/academy/src/index.js", "pattern": "libs/features/modules/academy/src/index.ts" }, { "module": "@academy/features/patterns", "exactMatch": "libs/features/patterns/academy/src/index.js", "pattern": "libs/features/patterns/academy/src/index.ts" }, { "module": "@academy/features/practices", "exactMatch": "libs/features/practices/academy/src/index.js", "pattern": "libs/features/practices/academy/src/index.ts" }, { "module": "@academy/features/projects", "exactMatch": "libs/features/projects/academy/src/index.js", "pattern": "libs/features/projects/academy/src/index.ts" }, { "module": "@academy/features/sequences", "exactMatch": "libs/features/sequences/academy/src/index.js", "pattern": "libs/features/sequences/academy/src/index.ts" }, { "module": "@core/app-events/api", "exactMatch": "libs/core/app-events/api/src/index.js", "pattern": "libs/core/app-events/api/src/index.ts" }, { "module": "@platform/report/build", "exactMatch": "libs/platform/report/build/src/index.js", "pattern": "libs/platform/report/build/src/index.ts" }, { "module": "@platform/report/code", "exactMatch": "libs/platform/report/code/src/index.js", "pattern": "libs/platform/report/code/src/index.ts" }, { "module": "@platform/report/feature", "exactMatch": "libs/platform/report/feature/src/index.js", "pattern": "libs/platform/report/feature/src/index.ts" }, { "module": "@platform/report/lint", "exactMatch": "libs/platform/report/lint/src/index.js", "pattern": "libs/platform/report/lint/src/index.ts" }, { "module": "@platform/report/ui", "exactMatch": "libs/platform/report/ui/src/index.js", "pattern": "libs/platform/report/ui/src/index.ts" }, { "module": "@platform/review/ui", "exactMatch": "libs/platform/review/ui/src/index.js", "pattern": "libs/platform/review/ui/src/index.ts" }, { "module": "@platform/shared/layouts", "exactMatch": "libs/platform/shared/layouts/src/index.js", "pattern": "libs/platform/shared/layouts/src/index.ts" }, { "module": "@platform/shared/modals", "exactMatch": "libs/platform/shared/modals/src/index.js", "pattern": "libs/platform/shared/modals/src/index.ts" }, { "module": "@platform/shared/polling", "exactMatch": "libs/platform/shared/polling/src/index.js", "pattern": "libs/platform/shared/polling/src/index.ts" }, { "module": "@platform/shared/progress", "exactMatch": "libs/platform/shared/progress/src/index.js", "pattern": "libs/platform/shared/progress/src/index.ts" }, { "module": "@platform/shared/tables", "exactMatch": "libs/platform/shared/tables/src/index.js", "pattern": "libs/platform/shared/tables/src/index.ts" }, { "module": "@platform/shared/text", "exactMatch": "libs/platform/shared/text/src/index.js", "pattern": "libs/platform/shared/text/src/index.ts" }, { "module": "@platform/shared/utils", "exactMatch": "libs/platform/shared/utils/index.js", "pattern": "libs/platform/shared/utils/index.ts" }, { "module": "@shared/features/benchmark", "exactMatch": "libs/features/benchmark/shared/src/index.js", "pattern": "libs/features/benchmark/shared/src/index.ts" }, { "module": "@shared/features/code-snapshot-review", "exactMatch": "libs/features/code-snapshot-review/shared/src/index.js", "pattern": "libs/features/code-snapshot-review/shared/src/index.ts" }, { "module": "@shared/features/code-solutions", "exactMatch": "libs/features/code-solutions/shared/src/index.js", "pattern": "libs/features/code-solutions/shared/src/index.ts" }, { "module": "@shared/features/content", "exactMatch": "libs/features/content/shared/src/index.js", "pattern": "libs/features/content/shared/src/index.ts" }, { "module": "@shared/features/llm", "exactMatch": "libs/features/llm/shared/src/index.js", "pattern": "libs/features/llm/shared/src/index.ts" }, { "module": "@shared/features/modules", "exactMatch": "libs/features/modules/shared/src/index.js", "pattern": "libs/features/modules/shared/src/index.ts" }, { "module": "@shared/features/patterns", "exactMatch": "libs/features/patterns/shared/src/index.js", "pattern": "libs/features/patterns/shared/src/index.ts" }, { "module": "@shared/features/projects", "exactMatch": "libs/features/projects/shared/src/index.js", "pattern": "libs/features/projects/shared/src/index.ts" }, { "module": "@shared/features/sequences", "exactMatch": "libs/features/sequences/shared/src/index.js", "pattern": "libs/features/sequences/shared/src/index.ts" }, { "module": "@shared/firebase/api", "exactMatch": "libs/shared/firebase/api/src/index.js", "pattern": "libs/shared/firebase/api/src/index.ts" }, { "module": "@feature-shared/challenges", "exactMatch": "libs/features/challenges/shared/src/index.js", "pattern": "libs/features/challenges/shared/src/index.ts" }, { "module": "@platform/core/code-snapshot", "exactMatch": "libs/core/code-snapshot/platform/src/index.js", "pattern": "libs/core/code-snapshot/platform/src/index.ts" }, { "module": "@platform/core/feature-flags", "exactMatch": "libs/platform/core/feature-flags/src/index.js", "pattern": "libs/platform/core/feature-flags/src/index.ts" }, { "module": "@academy/core/feature-flags", "exactMatch": "libs/academy/core/feature-flags/src/index.js", "pattern": "libs/academy/core/feature-flags/src/index.ts" }, { "module": "@api/features/articles", "exactMatch": "libs/features/articles/api/src/index.js", "pattern": "libs/features/articles/api/src/index.ts" }, { "module": "@api/features/challenge-solutions", "exactMatch": "libs/features/challenge-solutions/api/src/index.js", "pattern": "libs/features/challenge-solutions/api/src/index.ts" }, { "module": "@api/features/challenges", "exactMatch": "libs/features/challenges/api/src/index.js", "pattern": "libs/features/challenges/api/src/index.ts" }, { "module": "@api/features/code-snapshot-review", "exactMatch": "libs/features/code-snapshot-review/api/src/index.js", "pattern": "libs/features/code-snapshot-review/api/src/index.ts" }, { "module": "@api/features/code-solutions", "exactMatch": "libs/features/code-solutions/api/src/index.js", "pattern": "libs/features/code-solutions/api/src/index.ts" }, { "module": "@api/features/content", "exactMatch": "libs/features/content/api/src/index.js", "pattern": "libs/features/content/api/src/index.ts" }, { "module": "@api/features/lessons", "exactMatch": "libs/features/lessons/api/src/index.js", "pattern": "libs/features/lessons/api/src/index.ts" }, { "module": "@api/features/llm", "exactMatch": "libs/features/llm/api/src/index.js", "pattern": "libs/features/llm/api/src/index.ts" }, { "module": "@api/features/modules", "exactMatch": "libs/features/modules/api/src/index.js", "pattern": "libs/features/modules/api/src/index.ts" }, { "module": "@api/features/patterns", "exactMatch": "libs/features/patterns/api/src/index.js", "pattern": "libs/features/patterns/api/src/index.ts" }, { "module": "@api/features/pipelines", "exactMatch": "libs/features/pipelines/api/src/index.js", "pattern": "libs/features/pipelines/api/src/index.ts" }, { "module": "@api/features/practices", "exactMatch": "libs/features/practices/api/src/index.js", "pattern": "libs/features/practices/api/src/index.ts" }, { "module": "@api/features/projects", "exactMatch": "libs/features/projects/api/src/index.js", "pattern": "libs/features/projects/api/src/index.ts" }, { "module": "@api/features/sequences", "exactMatch": "libs/features/sequences/api/src/index.js", "pattern": "libs/features/sequences/api/src/index.ts" }, { "module": "@api/features/sprints", "exactMatch": "libs/features/sprints/api/src/index.js", "pattern": "libs/features/sprints/api/src/index.ts" }, { "module": "@api/features/users", "exactMatch": "libs/features/users/api/src/index.js", "pattern": "libs/features/users/api/src/index.ts" }, { "module": "@cli/features/articles", "exactMatch": "libs/features/articles/cli/src/index.js", "pattern": "libs/features/articles/cli/src/index.ts" }, { "module": "@cli/features/challenges", "exactMatch": "libs/features/challenges/cli/src/index.js", "pattern": "libs/features/challenges/cli/src/index.ts" }, { "module": "@cli/features/code-snapshot-review", "exactMatch": "libs/features/code-snapshot-review/cli/src/index.js", "pattern": "libs/features/code-snapshot-review/cli/src/index.ts" }, { "module": "@cli/features/content", "exactMatch": "libs/features/content/cli/src/index.js", "pattern": "libs/features/content/cli/src/index.ts" }, { "module": "@cli/features/patterns", "exactMatch": "libs/features/patterns/cli/src/index.js", "pattern": "libs/features/patterns/cli/src/index.ts" }, { "module": "@cli/features/practices", "exactMatch": "libs/features/practices/cli/src/index.js", "pattern": "libs/features/practices/cli/src/index.ts" }, { "module": "@cli/features/projects", "exactMatch": "libs/features/projects/cli/src/index.js", "pattern": "libs/features/projects/cli/src/index.ts" }, { "module": "@cli/features/sequences", "exactMatch": "libs/features/sequences/cli/src/index.js", "pattern": "libs/features/sequences/cli/src/index.ts" }, { "module": "@api/core/circle-ci", "exactMatch": "libs/api/core/circle-ci/src/index.js", "pattern": "libs/api/core/circle-ci/src/index.ts" }, { "module": "@api/core/http", "exactMatch": "libs/api/core/http/src/index.js", "pattern": "libs/api/core/http/src/index.ts" }, { "module": "@api/core/payments", "exactMatch": "libs/core/payments/api/src/index.js", "pattern": "libs/core/payments/api/src/index.ts" }, { "module": "@api/core/rating", "exactMatch": "libs/core/rating/api/src/index.js", "pattern": "libs/core/rating/api/src/index.ts" }, { "module": "@api/core/subscriptions", "exactMatch": "libs/core/subscriptions/api/src/index.js", "pattern": "libs/core/subscriptions/api/src/index.ts" }, { "module": "@api/core/utils", "exactMatch": "libs/api/core/utils/src/index.js", "pattern": "libs/api/core/utils/src/index.ts" }, { "module": "@lowgular/code-locator", "exactMatch": "libs/lowgular/code-locator/src/index.js", "pattern": "libs/lowgular/code-locator/src/index.ts" }, { "module": "@lowgular/codegular", "exactMatch": "libs/lowgular/codegular/src/index.js", "pattern": "libs/lowgular/codegular/src/index.ts" }, { "module": "@lowgular/marked-bootstrap", "exactMatch": "libs/lowgular/marked-bootstrap/src/index.js", "pattern": "libs/lowgular/marked-bootstrap/src/index.ts" }, { "module": "@platform/challenges", "exactMatch": "libs/platform/challenges/src/index.js", "pattern": "libs/platform/challenges/src/index.ts" }, { "module": "@platform/code-editor", "exactMatch": "libs/code-editor/src/index.js", "pattern": "libs/code-editor/src/index.ts" }, { "module": "@platform/featured-reports", "exactMatch": "libs/platform/featured-reports/src/index.js", "pattern": "libs/platform/featured-reports/src/index.ts" }, { "module": "@platform/featured-solutions", "exactMatch": "libs/platform/featured-solutions/src/index.js", "pattern": "libs/platform/featured-solutions/src/index.ts" }, { "module": "@platform/legacy-review", "exactMatch": "libs/platform/legacy-review/src/index.js", "pattern": "libs/platform/legacy-review/src/index.ts" }, { "module": "@platform/lessons", "exactMatch": "libs/platform/lessons/src/index.js", "pattern": "libs/platform/lessons/src/index.ts" }, { "module": "@platform/module", "exactMatch": "libs/platform/module/src/index.js", "pattern": "libs/platform/module/src/index.ts" }, { "module": "@platform/page-title", "exactMatch": "libs/platform/page-title/src/index.js", "pattern": "libs/platform/page-title/src/index.ts" }, { "module": "@platform/payment", "exactMatch": "libs/platform/payment/src/index.js", "pattern": "libs/platform/payment/src/index.ts" }, { "module": "@platform/pipelines", "exactMatch": "libs/platform/pipelines/src/index.js", "pattern": "libs/platform/pipelines/src/index.ts" }, { "module": "@platform/practice", "exactMatch": "libs/platform/practice/src/index.js", "pattern": "libs/platform/practice/src/index.ts" }, { "module": "@platform/practice-solutions", "exactMatch": "libs/platform/practice-solutions/src/index.js", "pattern": "libs/platform/practice-solutions/src/index.ts" }, { "module": "@platform/rating", "exactMatch": "libs/platform/rating/src/index.js", "pattern": "libs/platform/rating/src/index.ts" }, { "module": "@platform/sprints", "exactMatch": "libs/platform/sprints/src/index.js", "pattern": "libs/platform/sprints/src/index.ts" }, { "module": "@platform/subscriptions", "exactMatch": "libs/platform/subscriptions/src/index.js", "pattern": "libs/platform/subscriptions/src/index.ts" }, { "module": "@platform/users", "exactMatch": "libs/platform/users/src/index.js", "pattern": "libs/platform/users/src/index.ts" }, { "module": "@shared/alerts", "exactMatch": "libs/shared/alerts/src/index.js", "pattern": "libs/shared/alerts/src/index.ts" }, { "module": "@shared/annotation", "exactMatch": "libs/shared/annotation/src/index.js", "pattern": "libs/shared/annotation/src/index.ts" }, { "module": "@shared/articles", "exactMatch": "libs/features/articles/shared/src/index.js", "pattern": "libs/features/articles/shared/src/index.ts" }, { "module": "@shared/canvas", "exactMatch": "libs/shared/canvas/src/index.js", "pattern": "libs/shared/canvas/src/index.ts" }, { "module": "@shared/code-editor", "exactMatch": "libs/platform/shared/code-editor/src/index.js", "pattern": "libs/platform/shared/code-editor/src/index.ts" }, { "module": "@shared/components", "exactMatch": "libs/shared/components/src/index.js", "pattern": "libs/shared/components/src/index.ts" }, { "module": "@shared/design-system", "exactMatch": "libs/shared/design-system/src/index.js", "pattern": "libs/shared/design-system/src/index.ts" }, { "module": "@shared/directives", "exactMatch": "libs/shared/directives/src/index.js", "pattern": "libs/shared/directives/src/index.ts" }, { "module": "@shared/errors", "exactMatch": "libs/shared/errors/src/index.js", "pattern": "libs/shared/errors/src/index.ts" }, { "module": "@shared/forms", "exactMatch": "libs/shared/forms/src/index.js", "pattern": "libs/shared/forms/src/index.ts" }, { "module": "@shared/full-screen", "exactMatch": "libs/shared/full-screen/src/index.js", "pattern": "libs/shared/full-screen/src/index.ts" }, { "module": "@shared/ghosts", "exactMatch": "libs/shared/ghosts/src/index.js", "pattern": "libs/shared/ghosts/src/index.ts" }, { "module": "@shared/http", "exactMatch": "libs/shared/http/src/index.js", "pattern": "libs/shared/http/src/index.ts" }, { "module": "@shared/modals", "exactMatch": "libs/shared/modals/src/index.js", "pattern": "libs/shared/modals/src/index.ts" }, { "module": "@shared/pagination", "exactMatch": "libs/shared/pagination/src/index.js", "pattern": "libs/shared/pagination/src/index.ts" }, { "module": "@shared/pipes", "exactMatch": "libs/shared/pipes/src/index.js", "pattern": "libs/shared/pipes/src/index.ts" }, { "module": "@shared/states", "exactMatch": "libs/shared/states/src/index.js", "pattern": "libs/shared/states/src/index.ts" }, { "module": "@shared/text-area", "exactMatch": "libs/shared/text-area/src/index.js", "pattern": "libs/shared/text-area/src/index.ts" }, { "module": "@shared/theme", "exactMatch": "libs/shared/theme/src/index.js", "pattern": "libs/shared/theme/src/index.ts" }, { "module": "@shared/utils", "exactMatch": "libs/shared/utils/src/index.js", "pattern": "libs/shared/utils/src/index.ts" }, { "module": "@core/environment", "exactMatch": "libs/core/environment/src/index.js", "pattern": "libs/core/environment/src/index.ts" }, { "module": "@core/users", "exactMatch": "libs/core/users/src/index.js", "pattern": "libs/core/users/src/index.ts" }, { "module": "@core/codegular", "exactMatch": "libs/core/codegular/src/index.js", "pattern": "libs/core/codegular/src/index.ts" }, { "module": "@cli/code-graph", "exactMatch": "libs/cli/code-graph/src/index.js", "pattern": "libs/cli/code-graph/src/index.ts" }, { "module": "@cli/core", "exactMatch": "libs/cli/core/src/index.js", "pattern": "libs/cli/core/src/index.ts" }, { "module": "@cli/cypher", "exactMatch": "libs/cli/cypher/src/index.js", "pattern": "libs/cli/cypher/src/index.ts" }, { "module": "@cli/shared", "exactMatch": "libs/cli/shared/src/index.js", "pattern": "libs/cli/shared/src/index.ts" }, { "module": "@cli/typescript", "exactMatch": "libs/cli/typescript/src/index.js", "pattern": "libs/cli/typescript/src/index.ts" }, { "module": "@achievements", "exactMatch": "libs/achievements/src/index.js", "pattern": "libs/achievements/src/index.ts" }, { "module": "@auth", "exactMatch": "libs/auth/src/index.js", "pattern": "libs/auth/src/index.ts" }, { "module": "@breadcrumbs", "exactMatch": "libs/breadcrumbs/src/index.js", "pattern": "libs/breadcrumbs/src/index.ts" }, { "module": "@common", "exactMatch": "libs/common/src/index.js", "pattern": "libs/common/src/index.ts" }, { "module": "theme", "exactMatch": "libs/shared/theme/src/index.js", "pattern": "libs/shared/theme/src/index.ts" }];
|
|
7
|
-
Module._resolveFilename = function(request, parent) {
|
|
8
|
-
let found;
|
|
9
|
-
for (const entry of manifest) {
|
|
10
|
-
if (request === entry.module && entry.exactMatch) {
|
|
11
|
-
const entry2 = manifest.find((x) => request === x.module || request.startsWith(x.module + "/"));
|
|
12
|
-
const candidate = path.join(distPath, entry2.exactMatch);
|
|
13
|
-
if (isFile(candidate)) {
|
|
14
|
-
found = candidate;
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
} else {
|
|
18
|
-
const re = new RegExp(entry.module.replace(/\*$/, "(?<rest>.*)"));
|
|
19
|
-
const match = request.match(re);
|
|
20
|
-
if (match?.groups) {
|
|
21
|
-
const candidate = path.join(distPath, entry.pattern.replace("*", ""), match.groups.rest);
|
|
22
|
-
if (isFile(candidate)) {
|
|
23
|
-
found = candidate;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (found) {
|
|
29
|
-
const modifiedArguments = [found, ...[].slice.call(arguments, 1)];
|
|
30
|
-
return originalResolveFilename.apply(this, modifiedArguments);
|
|
31
|
-
} else {
|
|
32
|
-
return originalResolveFilename.apply(this, arguments);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
function isFile(s) {
|
|
36
|
-
try {
|
|
37
|
-
require.resolve(s);
|
|
38
|
-
return true;
|
|
39
|
-
} catch (_e) {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
module.exports = require("./apps/code-graph/src/main.js");
|
package/package.json
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowgular/code-graph",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Run Cypher queries against a TypeScript code graph built from tsconfig",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./bin/cli.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./bin/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"code-graph": "./bin/cli.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"**/*.js",
|
|
16
|
+
"!**/*.spec.js",
|
|
17
|
+
"!**/*.test.js"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "nx build code-graph",
|
|
21
|
+
"cli": "nx run code-graph:cli"
|
|
8
22
|
},
|
|
9
23
|
"dependencies": {
|
|
10
|
-
"
|
|
24
|
+
"typescript": "^5.0.0",
|
|
25
|
+
"yargs": "^18.0.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
11
29
|
}
|
|
12
|
-
}
|
|
30
|
+
}
|
package/resources-cli.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const command = "resources";
|
|
2
|
+
const describe = "Print code graph schema and Cypher reference (for agents and tooling).";
|
|
3
|
+
const builder = (yargs) => yargs;
|
|
4
|
+
function handler() {
|
|
5
|
+
console.log(RESOURCES_TEXT);
|
|
6
|
+
}
|
|
7
|
+
const RESOURCES_TEXT = `# Code Graph \u2014 Cypher over TypeScript
|
|
8
|
+
|
|
9
|
+
The graph database is your **TypeScript code**. Nodes are AST nodes; relationships follow the structure of the program. You run Cypher queries against a project built from a tsconfig; the engine builds the graph on the fly from the query (no separate schema).
|
|
10
|
+
|
|
11
|
+
## Node labels = TypeScript SyntaxKind
|
|
12
|
+
|
|
13
|
+
Labels are **TypeScript AST node kinds** (SyntaxKind names). Examples:
|
|
14
|
+
|
|
15
|
+
ClassDeclaration, MethodDeclaration, PropertyDeclaration, Constructor,
|
|
16
|
+
FunctionDeclaration, VariableStatement, CallExpression, Identifier,
|
|
17
|
+
ObjectLiteralExpression, Decorator, SourceFile, ImportDeclaration, ...
|
|
18
|
+
|
|
19
|
+
Use them in patterns: \`(n:ClassDeclaration)\`, \`(d:Decorator)\`, \`(p:PropertyDeclaration)\`.
|
|
20
|
+
|
|
21
|
+
## Node shape (every node)
|
|
22
|
+
|
|
23
|
+
Each node in the result has:
|
|
24
|
+
|
|
25
|
+
- **id** \u2014 unique node id (file path + position)
|
|
26
|
+
- **labels** \u2014 array of one label (the SyntaxKind name)
|
|
27
|
+
- **name** \u2014 \`node.name?.getText()\` (e.g. class/method/prop name)
|
|
28
|
+
- **filePath** \u2014 source file path
|
|
29
|
+
- **text** \u2014 full text of the AST node
|
|
30
|
+
- **type** \u2014 resolved type from TypeChecker when available
|
|
31
|
+
- **firstIdentifier** \u2014 first descendant Identifier text
|
|
32
|
+
- **initializer** \u2014 initializer text when present (e.g. variable, property)
|
|
33
|
+
|
|
34
|
+
So you can filter or return \`n.name\`, \`n.filePath\`, \`n.text\`, \`n.type\`, etc.
|
|
35
|
+
|
|
36
|
+
## Relationships (most common)
|
|
37
|
+
|
|
38
|
+
**Traversal (AST structure)**
|
|
39
|
+
- **HAS_DESCENDANTS** \u2014 recursive descent into child nodes (optionally by kind)
|
|
40
|
+
- **HAS_ANCESTORS** \u2014 recursive ascent to parent nodes
|
|
41
|
+
|
|
42
|
+
**Direct AST properties**
|
|
43
|
+
- **HAS_INITIALIZER** \u2014 \`node.initializer\` (VariableDeclaration, PropertyDeclaration, \u2026)
|
|
44
|
+
- **HAS_PARAMETERS** \u2014 \`node.parameters\` (functions, constructors, \u2026)
|
|
45
|
+
- **HAS_EXPRESSION** \u2014 \`node.expression\` (CallExpression, Decorator, \u2026)
|
|
46
|
+
- **HAS_TYPE_ANNOTATION** \u2014 \`node.type\` (explicit type on params, properties, return)
|
|
47
|
+
- **HAS_BODY** \u2014 \`node.body\` (functions, methods, arrow functions, \u2026)
|
|
48
|
+
- **HAS_MEMBERS** \u2014 \`node.members\` (class/interface/enum members)
|
|
49
|
+
- **HAS_PROPERTIES** \u2014 \`node.properties\` (ObjectLiteralExpression)
|
|
50
|
+
- **HAS_ARGUMENTS** \u2014 \`node.arguments\` (CallExpression, NewExpression)
|
|
51
|
+
- **HAS_DECORATORS** \u2014 decorators on the node
|
|
52
|
+
- **HAS_TYPE** \u2014 resolved type (TypeChecker)
|
|
53
|
+
- **HAS_NAME** \u2014 \`node.name\` (Identifier)
|
|
54
|
+
|
|
55
|
+
**Heritage**
|
|
56
|
+
- **EXTENDS** \u2014 \`extends\` clause (classes, interfaces)
|
|
57
|
+
- **IMPLEMENTS** \u2014 \`implements\` clause (classes)
|
|
58
|
+
|
|
59
|
+
Example: find classes with a \`Component\` decorator:
|
|
60
|
+
|
|
61
|
+
MATCH (c:ClassDeclaration)-[:HAS_DECORATORS]->(d:Decorator)
|
|
62
|
+
WHERE d.name = 'Component'
|
|
63
|
+
RETURN c
|
|
64
|
+
|
|
65
|
+
Example: find method and its parameters:
|
|
66
|
+
|
|
67
|
+
MATCH (m:MethodDeclaration)-[:HAS_PARAMETERS]->(p:ParameterDeclaration)
|
|
68
|
+
RETURN m, p
|
|
69
|
+
`;
|
|
70
|
+
export {
|
|
71
|
+
builder,
|
|
72
|
+
command,
|
|
73
|
+
describe,
|
|
74
|
+
handler
|
|
75
|
+
};
|
package/run-cli.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { createProgramFromTsConfig } from "./codegular/index.js";
|
|
4
|
+
import { autoMatch } from "./infra/code-graph.js";
|
|
5
|
+
const command = "query <cypher>";
|
|
6
|
+
const describe = "Run Cypher and print match results as JSON. Builds the code graph from the project tsconfig; node/relationship config is inferred from the query.";
|
|
7
|
+
const builder = (yargs) => yargs.option("tsconfig", {
|
|
8
|
+
type: "string",
|
|
9
|
+
default: "tsconfig.json",
|
|
10
|
+
description: "Path to tsconfig.json (default: tsconfig.json in cwd)"
|
|
11
|
+
}).positional("cypher", {
|
|
12
|
+
type: "string",
|
|
13
|
+
demandOption: true,
|
|
14
|
+
description: 'Cypher query (quote in shell: "MATCH (n:ClassDeclaration) RETURN n")'
|
|
15
|
+
});
|
|
16
|
+
async function handler(argv) {
|
|
17
|
+
const cypherQuery = argv.cypher.trim();
|
|
18
|
+
const cwd = process.cwd();
|
|
19
|
+
const tsconfigPath = path.isAbsolute(argv.tsconfig) ? argv.tsconfig : path.join(cwd, argv.tsconfig);
|
|
20
|
+
if (!fs.existsSync(tsconfigPath)) {
|
|
21
|
+
console.error(`Error: tsconfig not found at ${tsconfigPath}`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const program = createProgramFromTsConfig(tsconfigPath);
|
|
26
|
+
const results = autoMatch(cypherQuery, program);
|
|
27
|
+
console.log(JSON.stringify(results, null, 2));
|
|
28
|
+
} catch (err) {
|
|
29
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
30
|
+
const stack = err instanceof Error ? err.stack : void 0;
|
|
31
|
+
console.error(`Error: ${message}`);
|
|
32
|
+
if (stack && process.env.DEBUG) {
|
|
33
|
+
console.error(stack);
|
|
34
|
+
}
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
builder,
|
|
40
|
+
command,
|
|
41
|
+
describe,
|
|
42
|
+
handler
|
|
43
|
+
};
|
|
@@ -1,50 +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 main_exports = {};
|
|
19
|
-
__export(main_exports, {
|
|
20
|
-
NODE_PRESETS: () => NODE_PRESETS,
|
|
21
|
-
matchFromFileSystem: () => matchFromFileSystem,
|
|
22
|
-
matchFromTsConfig: () => matchFromTsConfig
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(main_exports);
|
|
25
|
-
var import_code_graph = require("@cli/code-graph");
|
|
26
|
-
var import_codegular = require("@core/codegular");
|
|
27
|
-
const matchFromTsConfig = async (cypherQuery, tsConfigPath = "./tsconfig.json") => {
|
|
28
|
-
const program = (0, import_codegular.createProgramFromTsConfig)(tsConfigPath);
|
|
29
|
-
return [];
|
|
30
|
-
};
|
|
31
|
-
const matchFromFileSystem = async (cypherQuery, config, fileSystem) => {
|
|
32
|
-
const program = (0, import_codegular.createProgramFromFileSystem)(fileSystem);
|
|
33
|
-
const codeGraph = (0, import_code_graph.buildCodeGraph)(program, config);
|
|
34
|
-
const results = await import_code_graph.TOOLS.queryFromGraph(cypherQuery, codeGraph);
|
|
35
|
-
return results;
|
|
36
|
-
};
|
|
37
|
-
const NODE_PRESETS = {
|
|
38
|
-
NAMEABLE: {
|
|
39
|
-
properties: {
|
|
40
|
-
name: `helpers.getDescendantsBy(args.current, (node) => node.kind === args.ts.SyntaxKind.Identifier)[0]?.getText();`,
|
|
41
|
-
filePath: "args.sourceFile.fileName;"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
-
0 && (module.exports = {
|
|
47
|
-
NODE_PRESETS,
|
|
48
|
-
matchFromFileSystem,
|
|
49
|
-
matchFromTsConfig
|
|
50
|
-
});
|
|
@@ -1,39 +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 src_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(src_exports);
|
|
17
|
-
__reExport(src_exports, require("./lib/class-declarations"), module.exports);
|
|
18
|
-
__reExport(src_exports, require("./lib/code.graph.factory"), module.exports);
|
|
19
|
-
__reExport(src_exports, require("./lib/core/core"), module.exports);
|
|
20
|
-
__reExport(src_exports, require("./lib/decorators"), module.exports);
|
|
21
|
-
__reExport(src_exports, require("./lib/docs"), module.exports);
|
|
22
|
-
__reExport(src_exports, require("./lib/method-declarations"), module.exports);
|
|
23
|
-
__reExport(src_exports, require("./lib/parameters"), module.exports);
|
|
24
|
-
__reExport(src_exports, require("./lib/property-declarations"), module.exports);
|
|
25
|
-
__reExport(src_exports, require("./lib/tools"), module.exports);
|
|
26
|
-
__reExport(src_exports, require("./lib/v2"), module.exports);
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
...require("./lib/class-declarations"),
|
|
30
|
-
...require("./lib/code.graph.factory"),
|
|
31
|
-
...require("./lib/core/core"),
|
|
32
|
-
...require("./lib/decorators"),
|
|
33
|
-
...require("./lib/docs"),
|
|
34
|
-
...require("./lib/method-declarations"),
|
|
35
|
-
...require("./lib/parameters"),
|
|
36
|
-
...require("./lib/property-declarations"),
|
|
37
|
-
...require("./lib/tools"),
|
|
38
|
-
...require("./lib/v2")
|
|
39
|
-
});
|