@lowgular/code-graph 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/bin/cli.js +10 -0
  2. package/code-graph-v2/code.graph.js +37 -0
  3. package/code-graph-v2/config-from-query.js +131 -0
  4. package/code-graph-v2/extractors/extractor.js +27 -0
  5. package/code-graph-v2/extractors/index.js +1 -0
  6. package/code-graph-v2/graph-builder/code-graph.builder.js +49 -0
  7. package/code-graph-v2/graph-builder/index.js +1 -0
  8. package/code-graph-v2/graph-builder/node.processor.js +22 -0
  9. package/{libs/cli/code-graph/src/lib/v2 → code-graph-v2}/graph-builder/relationship.processor.js +11 -35
  10. package/code-graph-v2/graph-builder/type.processor.js +21 -0
  11. package/code-graph-v2/index.js +4 -0
  12. package/code-graph-v2/tools/build-code-graph.tool.js +19 -0
  13. package/code-graph-v2/utils.js +34 -0
  14. package/codegular/index.js +5 -0
  15. package/codegular/node.js +71 -0
  16. package/codegular/program.js +100 -0
  17. package/{libs/core/codegular/src/lib → codegular}/string.js +6 -53
  18. package/{libs/core/codegular/src/lib → codegular}/type-checker.js +3 -40
  19. package/codegular/type.js +356 -0
  20. package/{libs/core/codegular/src/lib → codegular}/utils.js +50 -62
  21. package/cypher/index.js +1 -0
  22. package/{libs/cli/cypher/src → cypher}/lib/executor/condition-evaluator.js +2 -25
  23. package/cypher/lib/executor/executor.js +60 -0
  24. package/cypher/lib/executor/graph.js +0 -0
  25. package/{libs/cli/cypher/src → cypher}/lib/executor/match-engine.js +4 -27
  26. package/{libs/cli/cypher/src → cypher}/lib/executor/pattern-matcher.js +2 -25
  27. package/{libs/cli/cypher/src → cypher}/lib/executor/relationship-navigator.js +2 -25
  28. package/{libs/cli/cypher/src → cypher}/lib/executor/result-formatter.js +37 -31
  29. package/{libs/cli/cypher/src → cypher}/lib/executor/traverse-engine.js +4 -27
  30. package/cypher/lib/executor/utils.js +14 -0
  31. package/cypher/lib/graph.stub.js +38 -0
  32. package/cypher/lib/index.js +32 -0
  33. package/{libs/cli/cypher/src → cypher}/lib/lexer.js +4 -26
  34. package/{libs/cli/cypher/src → cypher}/lib/parser.js +119 -135
  35. package/{libs/cli/cypher/src → cypher}/lib/validator/query-validator.js +12 -32
  36. package/{libs/cli/cypher/src → cypher}/lib/validator/supported-features.config.js +2 -30
  37. package/{libs/cli/cypher/src → cypher}/lib/validator/unsupported-features.config.js +8 -34
  38. package/cypher-cli.js +41 -0
  39. package/infra/code-graph.js +147 -0
  40. package/main.js +0 -43
  41. package/package.json +25 -7
  42. package/resources-cli.js +75 -0
  43. package/run-cli.js +43 -0
  44. package/apps/code-graph/src/main.js +0 -50
  45. package/libs/cli/code-graph/src/index.js +0 -39
  46. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +0 -72
  47. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +0 -68
  48. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +0 -147
  49. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +0 -55
  50. package/libs/cli/code-graph/src/lib/class-declarations/index.js +0 -27
  51. package/libs/cli/code-graph/src/lib/code.graph.factory.js +0 -63
  52. package/libs/cli/code-graph/src/lib/code.graph.js +0 -62
  53. package/libs/cli/code-graph/src/lib/core/core.js +0 -58
  54. package/libs/cli/code-graph/src/lib/core.js +0 -85
  55. package/libs/cli/code-graph/src/lib/decorators/index.js +0 -36
  56. package/libs/cli/code-graph/src/lib/docs/index.js +0 -21
  57. package/libs/cli/code-graph/src/lib/docs/specs.js +0 -36
  58. package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +0 -28
  59. package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +0 -53
  60. package/libs/cli/code-graph/src/lib/method-declarations/index.js +0 -23
  61. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +0 -106
  62. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +0 -56
  63. package/libs/cli/code-graph/src/lib/parameters/index.js +0 -42
  64. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +0 -139
  65. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +0 -104
  66. package/libs/cli/code-graph/src/lib/property-declarations/index.js +0 -25
  67. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +0 -74
  68. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +0 -43
  69. package/libs/cli/code-graph/src/lib/tools/index.js +0 -34
  70. package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +0 -64
  71. package/libs/cli/code-graph/src/lib/types/index.js +0 -99
  72. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +0 -345
  73. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +0 -52
  74. package/libs/cli/code-graph/src/lib/v2/extractors/index.js +0 -23
  75. package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +0 -76
  76. package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +0 -21
  77. package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +0 -48
  78. package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +0 -45
  79. package/libs/cli/code-graph/src/lib/v2/index.js +0 -37
  80. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +0 -220
  81. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +0 -42
  82. package/libs/cli/cypher/src/index.js +0 -25
  83. package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +0 -277
  84. package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +0 -69
  85. package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +0 -105
  86. package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +0 -70
  87. package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +0 -99
  88. package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +0 -125
  89. package/libs/cli/cypher/src/lib/docs/features/index.js +0 -51
  90. package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +0 -50
  91. package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +0 -106
  92. package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +0 -105
  93. package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +0 -143
  94. package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +0 -152
  95. package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +0 -48
  96. package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +0 -65
  97. package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +0 -82
  98. package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +0 -136
  99. package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +0 -187
  100. package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +0 -302
  101. package/libs/cli/cypher/src/lib/docs/prompts.js +0 -36
  102. package/libs/cli/cypher/src/lib/docs/specs.js +0 -181
  103. package/libs/cli/cypher/src/lib/executor/executor.js +0 -83
  104. package/libs/cli/cypher/src/lib/executor/graph.js +0 -15
  105. package/libs/cli/cypher/src/lib/executor/utils.js +0 -37
  106. package/libs/cli/cypher/src/lib/graph.stub.js +0 -63
  107. package/libs/cli/cypher/src/lib/index.js +0 -74
  108. package/libs/cli/shared/src/index.js +0 -53
  109. package/libs/cli/shared/src/lib/admin-token.js +0 -121
  110. package/libs/cli/shared/src/lib/config.js +0 -49
  111. package/libs/cli/shared/src/lib/consts.js +0 -57
  112. package/libs/cli/shared/src/lib/core.js +0 -46
  113. package/libs/cli/shared/src/lib/infrastructure/cli.js +0 -47
  114. package/libs/cli/shared/src/lib/infrastructure/config.js +0 -47
  115. package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +0 -51
  116. package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +0 -96
  117. package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +0 -41
  118. package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +0 -64
  119. package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +0 -120
  120. package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +0 -15
  121. package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +0 -72
  122. package/libs/cli/shared/src/lib/infrastructure/git.js +0 -147
  123. package/libs/cli/shared/src/lib/infrastructure/http.js +0 -257
  124. package/libs/cli/shared/src/lib/infrastructure/markdown.js +0 -95
  125. package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +0 -88
  126. package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +0 -25
  127. package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +0 -154
  128. package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +0 -210
  129. package/libs/cli/shared/src/lib/infrastructure/workspace.js +0 -297
  130. package/libs/cli/shared/src/lib/infrastructure/yaml.js +0 -237
  131. package/libs/cli/shared/src/lib/lowgular.config.js +0 -120
  132. package/libs/cli/shared/src/lib/token.js +0 -135
  133. package/libs/cli/shared/src/lib/utils/solution.util.js +0 -35
  134. package/libs/cli/shared/src/lib/utils/utils.js +0 -89
  135. package/libs/cli/typescript/src/index.js +0 -21
  136. package/libs/cli/typescript/src/lib/base/index.js +0 -23
  137. package/libs/cli/typescript/src/lib/base/nameable.js +0 -34
  138. package/libs/cli/typescript/src/lib/base/nodeable.js +0 -36
  139. package/libs/cli/typescript/src/lib/class.implementation.js +0 -52
  140. package/libs/cli/typescript/src/lib/core/declaration.registry.js +0 -107
  141. package/libs/cli/typescript/src/lib/core/design-pattern.js +0 -55
  142. package/libs/cli/typescript/src/lib/core/index.js +0 -35
  143. package/libs/cli/typescript/src/lib/core/navigable-declaration.js +0 -69
  144. package/libs/cli/typescript/src/lib/core/program-context.js +0 -71
  145. package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +0 -40
  146. package/libs/cli/typescript/src/lib/core/type.js +0 -374
  147. package/libs/cli/typescript/src/lib/declaration.abstraction.js +0 -90
  148. package/libs/cli/typescript/src/lib/decorator.implementation.js +0 -35
  149. package/libs/cli/typescript/src/lib/enum.implementation.js +0 -35
  150. package/libs/cli/typescript/src/lib/function-declaration.implementation.js +0 -35
  151. package/libs/cli/typescript/src/lib/index.js +0 -57
  152. package/libs/cli/typescript/src/lib/interface.implementation.js +0 -51
  153. package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +0 -90
  154. package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +0 -44
  155. package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +0 -46
  156. package/libs/cli/typescript/src/lib/members/method.util.js +0 -32
  157. package/libs/cli/typescript/src/lib/members/parameter.implementation.js +0 -38
  158. package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +0 -64
  159. package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +0 -34
  160. package/libs/cli/typescript/src/lib/members/property.util.js +0 -61
  161. package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +0 -42
  162. package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +0 -114
  163. package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +0 -188
  164. package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +0 -35
  165. package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +0 -51
  166. package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +0 -49
  167. package/libs/cli/typescript/src/lib/members/statements/utils.js +0 -51
  168. package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +0 -258
  169. package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +0 -15
  170. package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +0 -228
  171. package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +0 -126
  172. package/libs/cli/typescript/src/lib/plugins/stubs.js +0 -66
  173. package/libs/cli/typescript/src/lib/type-alias.implementation.js +0 -72
  174. package/libs/cli/typescript/src/lib/utils.js +0 -39
  175. package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +0 -35
  176. package/libs/core/codegular/src/index.js +0 -21
  177. package/libs/core/codegular/src/lib/index.js +0 -29
  178. package/libs/core/codegular/src/lib/node.js +0 -112
  179. package/libs/core/codegular/src/lib/program.js +0 -92
@@ -0,0 +1,60 @@
1
+ import { ConditionEvaluator } from "./condition-evaluator.js";
2
+ import { MatchEngine } from "./match-engine.js";
3
+ import { PatternMatcher } from "./pattern-matcher.js";
4
+ import { RelationshipNavigator } from "./relationship-navigator.js";
5
+ import { ResultFormatter } from "./result-formatter.js";
6
+ import { TraverseEngine } from "./traverse-engine.js";
7
+ class CypherExecutor {
8
+ constructor(graph) {
9
+ this.graph = graph;
10
+ this.conditionEvaluator = new ConditionEvaluator();
11
+ const patternMatcher = new PatternMatcher();
12
+ const relationshipNavigator = new RelationshipNavigator(patternMatcher);
13
+ const traverseEngine = new TraverseEngine(
14
+ patternMatcher,
15
+ relationshipNavigator
16
+ );
17
+ this.matchEngine = new MatchEngine(patternMatcher, traverseEngine);
18
+ this.resultFormatter = new ResultFormatter();
19
+ }
20
+ /**
21
+ * Execute a parsed Cypher query
22
+ * @param extractData - If true (default), returns node.data. If false, returns full GraphNode objects.
23
+ * For edges, always returns the full GraphEdge object (edges have no data property).
24
+ * Returns results where keys are variable names and values are either node data or edge objects
25
+ */
26
+ execute(query) {
27
+ if (query.statements.length === 0) {
28
+ throw new Error("Query must have at least one statement");
29
+ }
30
+ if (query.statements[query.statements.length - 1].type !== "ReturnStatement") {
31
+ throw new Error("MATCH Query must have a RETURN statement");
32
+ }
33
+ let results = [];
34
+ for (const statement of query.statements) {
35
+ if (statement.type === "MatchStatement") {
36
+ results = this.matchEngine.processMatchStatement(
37
+ this.graph,
38
+ statement,
39
+ results
40
+ );
41
+ } else if (statement.type === "WhereStatement") {
42
+ results = this.conditionEvaluator.applyWhereClauseIfNeeded(
43
+ results,
44
+ statement
45
+ );
46
+ } else if (statement.type === "OrderByStatement") {
47
+ results = this.resultFormatter.sortResults(results, statement);
48
+ }
49
+ }
50
+ const returnStatement = query.statements[query.statements.length - 1];
51
+ let formattedResults = this.resultFormatter.formatResults(
52
+ results,
53
+ returnStatement
54
+ );
55
+ return formattedResults;
56
+ }
57
+ }
58
+ export {
59
+ CypherExecutor
60
+ };
File without changes
@@ -1,31 +1,9 @@
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 match_engine_exports = {};
19
- __export(match_engine_exports, {
20
- MatchEngine: () => MatchEngine
21
- });
22
- module.exports = __toCommonJS(match_engine_exports);
23
- var import_utils = require("./utils");
1
+ import { Annonymizer } from "./utils.js";
24
2
  class MatchEngine {
25
3
  constructor(patternMatcher, traverseEngine) {
26
4
  this.patternMatcher = patternMatcher;
27
5
  this.traverseEngine = traverseEngine;
28
- this.annonymizer = new import_utils.Annonymizer();
6
+ this.annonymizer = new Annonymizer();
29
7
  }
30
8
  processMatchStatement(graph, match, existingResults = []) {
31
9
  if (match.patterns.length === 0)
@@ -147,7 +125,6 @@ class MatchEngine {
147
125
  return true;
148
126
  }
149
127
  }
150
- // Annotate the CommonJS export names for ESM import in node:
151
- 0 && (module.exports = {
128
+ export {
152
129
  MatchEngine
153
- });
130
+ };
@@ -1,25 +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 pattern_matcher_exports = {};
19
- __export(pattern_matcher_exports, {
20
- PatternMatcher: () => PatternMatcher
21
- });
22
- module.exports = __toCommonJS(pattern_matcher_exports);
23
1
  class PatternMatcher {
24
2
  /**
25
3
  * Check if an edge type matches the relationship pattern's edge type(s)
@@ -103,7 +81,6 @@ class PatternMatcher {
103
81
  );
104
82
  }
105
83
  }
106
- // Annotate the CommonJS export names for ESM import in node:
107
- 0 && (module.exports = {
84
+ export {
108
85
  PatternMatcher
109
- });
86
+ };
@@ -1,25 +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 relationship_navigator_exports = {};
19
- __export(relationship_navigator_exports, {
20
- RelationshipNavigator: () => RelationshipNavigator
21
- });
22
- module.exports = __toCommonJS(relationship_navigator_exports);
23
1
  class RelationshipNavigator {
24
2
  constructor(patternMatcher) {
25
3
  this.patternMatcher = patternMatcher;
@@ -58,7 +36,6 @@ class RelationshipNavigator {
58
36
  return connections;
59
37
  }
60
38
  }
61
- // Annotate the CommonJS export names for ESM import in node:
62
- 0 && (module.exports = {
39
+ export {
63
40
  RelationshipNavigator
64
- });
41
+ };
@@ -1,27 +1,4 @@
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 result_formatter_exports = {};
19
- __export(result_formatter_exports, {
20
- ResultFormatter: () => ResultFormatter,
21
- extractGraphNodesFromResult: () => extractGraphNodesFromResult
22
- });
23
- module.exports = __toCommonJS(result_formatter_exports);
24
- var import_utils = require("./utils");
1
+ import { Annonymizer } from "./utils.js";
25
2
  const extractGraphNodesFromResult = (results) => {
26
3
  return Object.values(results).filter(
27
4
  (value) => value !== null && typeof value === "object" && "id" in value && "labels" in value
@@ -29,7 +6,7 @@ const extractGraphNodesFromResult = (results) => {
29
6
  };
30
7
  class ResultFormatter {
31
8
  constructor() {
32
- this.annonymizer = new import_utils.Annonymizer();
9
+ this.annonymizer = new Annonymizer();
33
10
  }
34
11
  /**
35
12
  * Format a single match value (node or edge) based on extractData flag
@@ -95,13 +72,17 @@ class ResultFormatter {
95
72
  * Format results with RETURN clause
96
73
  * Only includes variables specified in RETURN clause, with optional aliases
97
74
  * If returnAll is true (RETURN *), returns all variables
75
+ * If distinct is true, deduplicate results based on returned variables' ids
98
76
  */
99
77
  formatResults(results, returnClause) {
100
- const limitedResults = returnClause.limit ? results.slice(0, returnClause.limit) : results;
78
+ let processedResults = returnClause.limit ? results.slice(0, returnClause.limit) : results;
79
+ if (returnClause.distinct) {
80
+ processedResults = this.deduplicateResults(processedResults, returnClause);
81
+ }
101
82
  if (returnClause.returnAll) {
102
- return this.formatDefault(limitedResults);
83
+ return this.formatDefault(processedResults);
103
84
  }
104
- return limitedResults.map((match) => {
85
+ return processedResults.map((match) => {
105
86
  const result = {};
106
87
  for (const item of returnClause.items) {
107
88
  const variable = item.expression;
@@ -119,6 +100,32 @@ class ResultFormatter {
119
100
  return result;
120
101
  });
121
102
  }
103
+ /**
104
+ * Deduplicate results based on returned variables' ids
105
+ */
106
+ deduplicateResults(results, returnClause) {
107
+ const seen = /* @__PURE__ */ new Map();
108
+ for (const match of results) {
109
+ const key = returnClause.items.map((item) => this.getValueId(match[item.expression])).join("|");
110
+ if (!seen.has(key)) {
111
+ seen.set(key, match);
112
+ }
113
+ }
114
+ return Array.from(seen.values());
115
+ }
116
+ /**
117
+ * Get a unique identifier for a match result value
118
+ */
119
+ getValueId(value) {
120
+ if (value === null || value === void 0) {
121
+ return "null";
122
+ }
123
+ if ("id" in value && "labels" in value) {
124
+ return value.id;
125
+ }
126
+ const edge = value;
127
+ return `edge:${edge.source}|${edge.target}|${edge.type}`;
128
+ }
122
129
  /**
123
130
  * Format results without RETURN clause (default)
124
131
  * Returns all matched variables keyed by their variable names
@@ -136,8 +143,7 @@ class ResultFormatter {
136
143
  });
137
144
  }
138
145
  }
139
- // Annotate the CommonJS export names for ESM import in node:
140
- 0 && (module.exports = {
146
+ export {
141
147
  ResultFormatter,
142
148
  extractGraphNodesFromResult
143
- });
149
+ };
@@ -1,31 +1,9 @@
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 traverse_engine_exports = {};
19
- __export(traverse_engine_exports, {
20
- TraverseEngine: () => TraverseEngine
21
- });
22
- module.exports = __toCommonJS(traverse_engine_exports);
23
- var import_utils = require("./utils");
1
+ import { Annonymizer } from "./utils.js";
24
2
  class TraverseEngine {
25
3
  constructor(patternMatcher, relationshipNavigator) {
26
4
  this.patternMatcher = patternMatcher;
27
5
  this.relationshipNavigator = relationshipNavigator;
28
- this.annonymizer = new import_utils.Annonymizer();
6
+ this.annonymizer = new Annonymizer();
29
7
  }
30
8
  /**
31
9
  * Recursively traverse relationships to match subsequent patterns
@@ -158,7 +136,6 @@ class TraverseEngine {
158
136
  return results;
159
137
  }
160
138
  }
161
- // Annotate the CommonJS export names for ESM import in node:
162
- 0 && (module.exports = {
139
+ export {
163
140
  TraverseEngine
164
- });
141
+ };
@@ -0,0 +1,14 @@
1
+ class Annonymizer {
2
+ constructor() {
3
+ this.anonymousVariablePrefix = "annonymous_";
4
+ }
5
+ generate(node) {
6
+ return this.anonymousVariablePrefix + node.id;
7
+ }
8
+ isAnonymous(variable) {
9
+ return variable.startsWith(this.anonymousVariablePrefix);
10
+ }
11
+ }
12
+ export {
13
+ Annonymizer
14
+ };
@@ -0,0 +1,38 @@
1
+ class GraphBuilder {
2
+ constructor() {
3
+ this.graph = {
4
+ nodesById: {},
5
+ edgesBySource: {},
6
+ edgesByTarget: {}
7
+ };
8
+ }
9
+ addNode(node) {
10
+ this.graph.nodesById[node.id] = node;
11
+ return this;
12
+ }
13
+ addEdge(edge) {
14
+ if (!this.graph.edgesBySource[edge.source]) {
15
+ this.graph.edgesBySource[edge.source] = [];
16
+ }
17
+ if (!this.graph.edgesByTarget[edge.target]) {
18
+ this.graph.edgesByTarget[edge.target] = [];
19
+ }
20
+ this.graph.edgesBySource[edge.source].push(edge);
21
+ this.graph.edgesByTarget[edge.target].push(edge);
22
+ return this;
23
+ }
24
+ build() {
25
+ return this.graph;
26
+ }
27
+ }
28
+ const stubNode = (id, label = "A", extras = {}) => ({ id, labels: Array.isArray(label) ? label : [label], ...extras });
29
+ const stubEdge = (source, target, type = "A") => ({
30
+ source,
31
+ target,
32
+ type
33
+ });
34
+ export {
35
+ GraphBuilder,
36
+ stubEdge,
37
+ stubNode
38
+ };
@@ -0,0 +1,32 @@
1
+ import { CypherExecutor } from "./executor/executor.js";
2
+ import { Lexer } from "./lexer.js";
3
+ import { Parser } from "./parser.js";
4
+ import { validateQuery } from "./validator/query-validator.js";
5
+ const buildQueryObject = (query2) => {
6
+ const joinedQuery = Array.isArray(query2) ? query2.join(" ") : query2;
7
+ validateQuery(joinedQuery);
8
+ const lexer = new Lexer(joinedQuery);
9
+ const tokens = lexer.tokenize();
10
+ const parser = new Parser(tokens);
11
+ return parser.parse();
12
+ };
13
+ const query = (queryStatements, graph) => {
14
+ const queryObject = buildQueryObject(queryStatements);
15
+ const executor = new CypherExecutor(graph);
16
+ return executor.execute(queryObject);
17
+ };
18
+ const matchAll = (query2, graph) => {
19
+ const queryObject = buildQueryObject(query2);
20
+ queryObject.statements.push({
21
+ type: "ReturnStatement",
22
+ returnAll: true,
23
+ items: []
24
+ });
25
+ const executor = new CypherExecutor(graph);
26
+ return executor.execute(queryObject);
27
+ };
28
+ export {
29
+ buildQueryObject,
30
+ matchAll,
31
+ query
32
+ };
@@ -1,30 +1,8 @@
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 lexer_exports = {};
19
- __export(lexer_exports, {
20
- Lexer: () => Lexer,
21
- TokenType: () => TokenType
22
- });
23
- module.exports = __toCommonJS(lexer_exports);
24
1
  var TokenType = /* @__PURE__ */ ((TokenType2) => {
25
2
  TokenType2["MATCH"] = "MATCH";
26
3
  TokenType2["OPTIONAL"] = "OPTIONAL";
27
4
  TokenType2["RETURN"] = "RETURN";
5
+ TokenType2["DISTINCT"] = "DISTINCT";
28
6
  TokenType2["WHERE"] = "WHERE";
29
7
  TokenType2["AND"] = "AND";
30
8
  TokenType2["OR"] = "OR";
@@ -148,6 +126,7 @@ class Lexer {
148
126
  MATCH: "MATCH" /* MATCH */,
149
127
  OPTIONAL: "OPTIONAL" /* OPTIONAL */,
150
128
  RETURN: "RETURN" /* RETURN */,
129
+ DISTINCT: "DISTINCT" /* DISTINCT */,
151
130
  WHERE: "WHERE" /* WHERE */,
152
131
  AND: "AND" /* AND */,
153
132
  OR: "OR" /* OR */,
@@ -391,8 +370,7 @@ class Lexer {
391
370
  return tokens;
392
371
  }
393
372
  }
394
- // Annotate the CommonJS export names for ESM import in node:
395
- 0 && (module.exports = {
373
+ export {
396
374
  Lexer,
397
375
  TokenType
398
- });
376
+ };