@lowgular/code-graph 0.0.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/bin/cli.js +2463 -0
  2. package/lib.js +2430 -0
  3. package/package.json +26 -7
  4. package/apps/code-graph/src/main.js +0 -50
  5. package/libs/cli/code-graph/src/index.js +0 -39
  6. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.js +0 -72
  7. package/libs/cli/code-graph/src/lib/class-declarations/abstractions/service.stateful.js +0 -68
  8. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.doc.js +0 -147
  9. package/libs/cli/code-graph/src/lib/class-declarations/class-declarations.graph.js +0 -55
  10. package/libs/cli/code-graph/src/lib/class-declarations/index.js +0 -27
  11. package/libs/cli/code-graph/src/lib/code.graph.factory.js +0 -63
  12. package/libs/cli/code-graph/src/lib/code.graph.js +0 -62
  13. package/libs/cli/code-graph/src/lib/core/core.js +0 -58
  14. package/libs/cli/code-graph/src/lib/core.js +0 -85
  15. package/libs/cli/code-graph/src/lib/decorators/index.js +0 -36
  16. package/libs/cli/code-graph/src/lib/docs/index.js +0 -21
  17. package/libs/cli/code-graph/src/lib/docs/specs.js +0 -36
  18. package/libs/cli/code-graph/src/lib/expressions/call-expressions.graph.js +0 -28
  19. package/libs/cli/code-graph/src/lib/fixtures/reactive-event-bus/src/app/examples.event-bus.js +0 -53
  20. package/libs/cli/code-graph/src/lib/method-declarations/index.js +0 -23
  21. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.doc.js +0 -106
  22. package/libs/cli/code-graph/src/lib/method-declarations/method-declarations.graph.js +0 -56
  23. package/libs/cli/code-graph/src/lib/parameters/index.js +0 -42
  24. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.evals.js +0 -139
  25. package/libs/cli/code-graph/src/lib/property-declarations/abstractions/reactive-state.js +0 -104
  26. package/libs/cli/code-graph/src/lib/property-declarations/index.js +0 -25
  27. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.doc.js +0 -74
  28. package/libs/cli/code-graph/src/lib/property-declarations/property-declarations.graph.js +0 -43
  29. package/libs/cli/code-graph/src/lib/tools/index.js +0 -34
  30. package/libs/cli/code-graph/src/lib/tools/match-code-graph.tool.js +0 -64
  31. package/libs/cli/code-graph/src/lib/types/index.js +0 -99
  32. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.doc.js +0 -345
  33. package/libs/cli/code-graph/src/lib/v2/extractors/extractor.js +0 -52
  34. package/libs/cli/code-graph/src/lib/v2/extractors/index.js +0 -23
  35. package/libs/cli/code-graph/src/lib/v2/graph-builder/code-graph.builder.js +0 -76
  36. package/libs/cli/code-graph/src/lib/v2/graph-builder/index.js +0 -21
  37. package/libs/cli/code-graph/src/lib/v2/graph-builder/node.processor.js +0 -48
  38. package/libs/cli/code-graph/src/lib/v2/graph-builder/relationship.processor.js +0 -79
  39. package/libs/cli/code-graph/src/lib/v2/graph-builder/type.processor.js +0 -45
  40. package/libs/cli/code-graph/src/lib/v2/index.js +0 -37
  41. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.doc.js +0 -220
  42. package/libs/cli/code-graph/src/lib/v2/tools/build-code-graph.tool.js +0 -42
  43. package/libs/cli/cypher/src/index.js +0 -25
  44. package/libs/cli/cypher/src/lib/docs/features/advanced-optional-match.feature.js +0 -277
  45. package/libs/cli/cypher/src/lib/docs/features/anonymous-relationship.feature.js +0 -69
  46. package/libs/cli/cypher/src/lib/docs/features/anonymous-variable-length.feature.js +0 -105
  47. package/libs/cli/cypher/src/lib/docs/features/basic-filtering.feature.js +0 -70
  48. package/libs/cli/cypher/src/lib/docs/features/basic-optional-match.feature.js +0 -99
  49. package/libs/cli/cypher/src/lib/docs/features/basic-relationship.feature.js +0 -125
  50. package/libs/cli/cypher/src/lib/docs/features/index.js +0 -51
  51. package/libs/cli/cypher/src/lib/docs/features/limit.feature.js +0 -50
  52. package/libs/cli/cypher/src/lib/docs/features/match-nodes.feature.js +0 -106
  53. package/libs/cli/cypher/src/lib/docs/features/multiple-relationship-types.feature.js +0 -105
  54. package/libs/cli/cypher/src/lib/docs/features/order-by.feature.js +0 -143
  55. package/libs/cli/cypher/src/lib/docs/features/property-matching.feature.js +0 -152
  56. package/libs/cli/cypher/src/lib/docs/features/relationship-without-variable.feature.js +0 -48
  57. package/libs/cli/cypher/src/lib/docs/features/return-statement.feature.js +0 -65
  58. package/libs/cli/cypher/src/lib/docs/features/unidirected-relationship.feature.js +0 -82
  59. package/libs/cli/cypher/src/lib/docs/features/variable-length-path.feature.js +0 -136
  60. package/libs/cli/cypher/src/lib/docs/features/where-conditional.feature.js +0 -187
  61. package/libs/cli/cypher/src/lib/docs/features/where-operators.feature.js +0 -302
  62. package/libs/cli/cypher/src/lib/docs/prompts.js +0 -36
  63. package/libs/cli/cypher/src/lib/docs/specs.js +0 -181
  64. package/libs/cli/cypher/src/lib/executor/condition-evaluator.js +0 -158
  65. package/libs/cli/cypher/src/lib/executor/executor.js +0 -83
  66. package/libs/cli/cypher/src/lib/executor/graph.js +0 -15
  67. package/libs/cli/cypher/src/lib/executor/match-engine.js +0 -153
  68. package/libs/cli/cypher/src/lib/executor/pattern-matcher.js +0 -109
  69. package/libs/cli/cypher/src/lib/executor/relationship-navigator.js +0 -64
  70. package/libs/cli/cypher/src/lib/executor/result-formatter.js +0 -143
  71. package/libs/cli/cypher/src/lib/executor/traverse-engine.js +0 -164
  72. package/libs/cli/cypher/src/lib/executor/utils.js +0 -37
  73. package/libs/cli/cypher/src/lib/graph.stub.js +0 -63
  74. package/libs/cli/cypher/src/lib/index.js +0 -74
  75. package/libs/cli/cypher/src/lib/lexer.js +0 -398
  76. package/libs/cli/cypher/src/lib/parser.js +0 -602
  77. package/libs/cli/cypher/src/lib/validator/query-validator.js +0 -95
  78. package/libs/cli/cypher/src/lib/validator/supported-features.config.js +0 -111
  79. package/libs/cli/cypher/src/lib/validator/unsupported-features.config.js +0 -150
  80. package/libs/cli/shared/src/index.js +0 -53
  81. package/libs/cli/shared/src/lib/admin-token.js +0 -121
  82. package/libs/cli/shared/src/lib/config.js +0 -49
  83. package/libs/cli/shared/src/lib/consts.js +0 -57
  84. package/libs/cli/shared/src/lib/core.js +0 -46
  85. package/libs/cli/shared/src/lib/infrastructure/cli.js +0 -47
  86. package/libs/cli/shared/src/lib/infrastructure/config.js +0 -47
  87. package/libs/cli/shared/src/lib/infrastructure/config.reporitory.js +0 -51
  88. package/libs/cli/shared/src/lib/infrastructure/formatters/console-formatter.js +0 -96
  89. package/libs/cli/shared/src/lib/infrastructure/formatters/index.js +0 -41
  90. package/libs/cli/shared/src/lib/infrastructure/formatters/json-formatter.js +0 -64
  91. package/libs/cli/shared/src/lib/infrastructure/formatters/markdown-formatter.js +0 -120
  92. package/libs/cli/shared/src/lib/infrastructure/formatters/types.js +0 -15
  93. package/libs/cli/shared/src/lib/infrastructure/formatters/utils.js +0 -72
  94. package/libs/cli/shared/src/lib/infrastructure/git.js +0 -147
  95. package/libs/cli/shared/src/lib/infrastructure/http.js +0 -257
  96. package/libs/cli/shared/src/lib/infrastructure/markdown.js +0 -95
  97. package/libs/cli/shared/src/lib/infrastructure/transformers/embeddings.js +0 -88
  98. package/libs/cli/shared/src/lib/infrastructure/transformers/index.js +0 -25
  99. package/libs/cli/shared/src/lib/infrastructure/transformers/rag-eval.js +0 -154
  100. package/libs/cli/shared/src/lib/infrastructure/transformers/similarity.js +0 -210
  101. package/libs/cli/shared/src/lib/infrastructure/workspace.js +0 -297
  102. package/libs/cli/shared/src/lib/infrastructure/yaml.js +0 -237
  103. package/libs/cli/shared/src/lib/lowgular.config.js +0 -120
  104. package/libs/cli/shared/src/lib/token.js +0 -135
  105. package/libs/cli/shared/src/lib/utils/solution.util.js +0 -35
  106. package/libs/cli/shared/src/lib/utils/utils.js +0 -89
  107. package/libs/cli/typescript/src/index.js +0 -21
  108. package/libs/cli/typescript/src/lib/base/index.js +0 -23
  109. package/libs/cli/typescript/src/lib/base/nameable.js +0 -34
  110. package/libs/cli/typescript/src/lib/base/nodeable.js +0 -36
  111. package/libs/cli/typescript/src/lib/class.implementation.js +0 -52
  112. package/libs/cli/typescript/src/lib/core/declaration.registry.js +0 -107
  113. package/libs/cli/typescript/src/lib/core/design-pattern.js +0 -55
  114. package/libs/cli/typescript/src/lib/core/index.js +0 -35
  115. package/libs/cli/typescript/src/lib/core/navigable-declaration.js +0 -69
  116. package/libs/cli/typescript/src/lib/core/program-context.js +0 -71
  117. package/libs/cli/typescript/src/lib/core/syntax-kind.utils.js +0 -40
  118. package/libs/cli/typescript/src/lib/core/type.js +0 -374
  119. package/libs/cli/typescript/src/lib/declaration.abstraction.js +0 -90
  120. package/libs/cli/typescript/src/lib/decorator.implementation.js +0 -35
  121. package/libs/cli/typescript/src/lib/enum.implementation.js +0 -35
  122. package/libs/cli/typescript/src/lib/function-declaration.implementation.js +0 -35
  123. package/libs/cli/typescript/src/lib/index.js +0 -57
  124. package/libs/cli/typescript/src/lib/interface.implementation.js +0 -51
  125. package/libs/cli/typescript/src/lib/members/method-abstraction.resolver.js +0 -90
  126. package/libs/cli/typescript/src/lib/members/method-declaration.implementation.js +0 -44
  127. package/libs/cli/typescript/src/lib/members/method-signature.implementation.js +0 -46
  128. package/libs/cli/typescript/src/lib/members/method.util.js +0 -32
  129. package/libs/cli/typescript/src/lib/members/parameter.implementation.js +0 -38
  130. package/libs/cli/typescript/src/lib/members/property-declaration.implementation.js +0 -64
  131. package/libs/cli/typescript/src/lib/members/property-signature.implementation.js +0 -34
  132. package/libs/cli/typescript/src/lib/members/property.util.js +0 -61
  133. package/libs/cli/typescript/src/lib/members/statements/expressions/binary-expression.implementation.js +0 -42
  134. package/libs/cli/typescript/src/lib/members/statements/expressions/call-expression.implementation.js +0 -114
  135. package/libs/cli/typescript/src/lib/members/statements/expressions/expression.abstraction.js +0 -188
  136. package/libs/cli/typescript/src/lib/members/statements/expressions/property-access-expression.implementation.js +0 -35
  137. package/libs/cli/typescript/src/lib/members/statements/expressions/unary-expression.implementation.js +0 -51
  138. package/libs/cli/typescript/src/lib/members/statements/statement.implementation.js +0 -49
  139. package/libs/cli/typescript/src/lib/members/statements/utils.js +0 -51
  140. package/libs/cli/typescript/src/lib/plugins/built-in.plugin.js +0 -258
  141. package/libs/cli/typescript/src/lib/plugins/plugin.interface.js +0 -15
  142. package/libs/cli/typescript/src/lib/plugins/rxjs.plugin.js +0 -228
  143. package/libs/cli/typescript/src/lib/plugins/signal.plugin.js +0 -126
  144. package/libs/cli/typescript/src/lib/plugins/stubs.js +0 -66
  145. package/libs/cli/typescript/src/lib/type-alias.implementation.js +0 -72
  146. package/libs/cli/typescript/src/lib/utils.js +0 -39
  147. package/libs/cli/typescript/src/lib/variable-declaration.implementation.js +0 -35
  148. package/libs/core/codegular/src/index.js +0 -21
  149. package/libs/core/codegular/src/lib/index.js +0 -29
  150. package/libs/core/codegular/src/lib/node.js +0 -112
  151. package/libs/core/codegular/src/lib/program.js +0 -92
  152. package/libs/core/codegular/src/lib/string.js +0 -168
  153. package/libs/core/codegular/src/lib/type-checker.js +0 -170
  154. package/libs/core/codegular/src/lib/utils.js +0 -347
  155. package/main.js +0 -43
@@ -1,602 +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 parser_exports = {};
19
- __export(parser_exports, {
20
- Parser: () => Parser
21
- });
22
- module.exports = __toCommonJS(parser_exports);
23
- var import_lexer = require("./lexer");
24
- class Parser {
25
- constructor(tokens) {
26
- this.tokens = [];
27
- this.position = 0;
28
- this.tokens = tokens;
29
- }
30
- current() {
31
- return this.tokens[this.position];
32
- }
33
- advance() {
34
- const token = this.current();
35
- if (this.position < this.tokens.length - 1) {
36
- this.position++;
37
- }
38
- return token;
39
- }
40
- peek() {
41
- return this.tokens[this.position + 1] || this.tokens[this.tokens.length - 1];
42
- }
43
- expect(type) {
44
- const token = this.current();
45
- if (token.type !== type) {
46
- throw new Error(
47
- `Expected ${type}, got ${token.type} at position ${token.position}`
48
- );
49
- }
50
- return this.advance();
51
- }
52
- isKeyword(keyword) {
53
- return this.current().type === keyword;
54
- }
55
- /**
56
- * Parse a property object: { key: value, ... }
57
- * Note: Cypher uses colon (:) for properties in node patterns, not equals (=)
58
- */
59
- parseProperties() {
60
- this.expect(import_lexer.TokenType.LBRACE);
61
- const properties = {};
62
- if (this.current().type === import_lexer.TokenType.RBRACE) {
63
- this.advance();
64
- return properties;
65
- }
66
- while (true) {
67
- const key = this.expect(import_lexer.TokenType.IDENTIFIER).value;
68
- this.expect(import_lexer.TokenType.LABEL);
69
- let value;
70
- if (this.current().type === import_lexer.TokenType.LBRACKET) {
71
- value = this.parseArrayLiteral();
72
- } else if (this.current().type === import_lexer.TokenType.STRING) {
73
- value = this.advance().value;
74
- } else if (this.current().type === import_lexer.TokenType.NUMBER) {
75
- value = parseFloat(this.advance().value);
76
- } else if (this.current().type === import_lexer.TokenType.TRUE) {
77
- value = true;
78
- this.advance();
79
- } else if (this.current().type === import_lexer.TokenType.FALSE) {
80
- value = false;
81
- this.advance();
82
- } else if (this.current().type === import_lexer.TokenType.IDENTIFIER) {
83
- value = this.advance().value;
84
- } else {
85
- throw new Error(
86
- `Unexpected token type for property value: ${this.current().type}`
87
- );
88
- }
89
- properties[key] = value;
90
- if (this.current().type === import_lexer.TokenType.RBRACE) {
91
- this.advance();
92
- break;
93
- }
94
- this.expect(import_lexer.TokenType.COMMA);
95
- }
96
- return properties;
97
- }
98
- /**
99
- * Parse a node pattern: (var:Label {prop: value}) or (:Label {prop: value})
100
- */
101
- parseNodePattern() {
102
- this.expect(import_lexer.TokenType.LPAREN);
103
- const pattern = {
104
- type: "NodePattern",
105
- labels: []
106
- };
107
- if (this.current().type === import_lexer.TokenType.IDENTIFIER) {
108
- const nextToken = this.peek();
109
- if (nextToken.type === import_lexer.TokenType.LABEL || nextToken.type === import_lexer.TokenType.LBRACE || nextToken.type === import_lexer.TokenType.RPAREN) {
110
- pattern.variable = this.advance().value;
111
- }
112
- }
113
- if (this.current().type === import_lexer.TokenType.LABEL) {
114
- this.advance();
115
- if (this.current().type !== import_lexer.TokenType.IDENTIFIER) {
116
- throw new Error(
117
- `Expected identifier after :, got ${this.current().type}`
118
- );
119
- }
120
- pattern.labels.push(this.advance().value);
121
- if (this.current().type === import_lexer.TokenType.LABEL) {
122
- pattern.labelOperator = "AND";
123
- while (this.current().type === import_lexer.TokenType.LABEL) {
124
- this.advance();
125
- if (this.current().type === import_lexer.TokenType.IDENTIFIER) {
126
- pattern.labels.push(this.advance().value);
127
- } else {
128
- throw new Error(
129
- `Expected identifier after :, got ${this.current().type}`
130
- );
131
- }
132
- }
133
- } else if (this.current().type === import_lexer.TokenType.PIPE) {
134
- pattern.labelOperator = "OR";
135
- while (this.current().type === import_lexer.TokenType.PIPE) {
136
- this.advance();
137
- if (this.current().type === import_lexer.TokenType.IDENTIFIER) {
138
- pattern.labels.push(this.advance().value);
139
- } else {
140
- throw new Error(
141
- `Expected identifier after |, got ${this.current().type}`
142
- );
143
- }
144
- }
145
- } else {
146
- pattern.labelOperator = "AND";
147
- }
148
- }
149
- if (this.current().type === import_lexer.TokenType.LBRACE) {
150
- pattern.properties = this.parseProperties();
151
- }
152
- this.expect(import_lexer.TokenType.RPAREN);
153
- return pattern;
154
- }
155
- /**
156
- * Parse relationship pattern: -[:RELATIONSHIP_TYPE]-> or <-[:RELATIONSHIP_TYPE]- or -[r:RELATIONSHIP_TYPE]->
157
- */
158
- parseRelationship() {
159
- const relationship = {
160
- type: "RelationshipPattern",
161
- direction: "outgoing"
162
- };
163
- if (this.current().type === import_lexer.TokenType.ARROW && this.current().value === "<-") {
164
- relationship.direction = "incoming";
165
- this.advance();
166
- } else {
167
- this.expect(import_lexer.TokenType.DASH);
168
- }
169
- if (this.current().type === import_lexer.TokenType.LBRACKET) {
170
- this.advance();
171
- if (this.current().type === import_lexer.TokenType.IDENTIFIER) {
172
- const nextToken = this.peek();
173
- if (nextToken.type === import_lexer.TokenType.LABEL || nextToken.type === import_lexer.TokenType.ASTERISK) {
174
- relationship.variable = this.advance().value;
175
- }
176
- }
177
- if (this.current().type === import_lexer.TokenType.ASTERISK) {
178
- this.advance();
179
- relationship.variableLength = true;
180
- relationship.minLength = 0;
181
- relationship.maxLength = void 0;
182
- } else if (this.current().type === import_lexer.TokenType.LABEL) {
183
- this.advance();
184
- const edgeTypes = [];
185
- edgeTypes.push(this.expect(import_lexer.TokenType.IDENTIFIER).value);
186
- while (this.current().type === import_lexer.TokenType.PIPE) {
187
- this.advance();
188
- edgeTypes.push(this.expect(import_lexer.TokenType.IDENTIFIER).value);
189
- }
190
- relationship.edgeType = edgeTypes.length === 1 ? edgeTypes[0] : edgeTypes;
191
- if (this.current().type === import_lexer.TokenType.ASTERISK) {
192
- this.advance();
193
- relationship.variableLength = true;
194
- relationship.minLength = 0;
195
- relationship.maxLength = void 0;
196
- }
197
- }
198
- this.expect(import_lexer.TokenType.RBRACKET);
199
- }
200
- if (relationship.direction === "incoming") {
201
- this.expect(import_lexer.TokenType.DASH);
202
- } else {
203
- if (this.current().type === import_lexer.TokenType.ARROW && this.current().value === "->") {
204
- this.advance();
205
- } else if (this.current().type === import_lexer.TokenType.DASH) {
206
- relationship.direction = "both";
207
- this.advance();
208
- }
209
- }
210
- return relationship;
211
- }
212
- /**
213
- * Parse MATCH clause (supports OPTIONAL MATCH)
214
- */
215
- parseMatch() {
216
- const isOptional = this.isKeyword(import_lexer.TokenType.OPTIONAL);
217
- if (isOptional) {
218
- this.advance();
219
- }
220
- this.expect(import_lexer.TokenType.MATCH);
221
- const firstPattern = this.parsePatternChain();
222
- const matchClause = {
223
- type: "MatchClause",
224
- patterns: firstPattern.patterns,
225
- relationships: firstPattern.relationships,
226
- additionalMatches: []
227
- };
228
- while (this.current().type === import_lexer.TokenType.COMMA) {
229
- this.advance();
230
- const additionalPattern = this.parsePatternChain();
231
- matchClause.additionalMatches.push(additionalPattern);
232
- }
233
- if (isOptional) {
234
- matchClause.optionalMatches = [
235
- {
236
- type: "MatchStatement",
237
- patterns: firstPattern.patterns,
238
- relationships: firstPattern.relationships
239
- },
240
- ...matchClause.additionalMatches || []
241
- ];
242
- matchClause.patterns = [];
243
- matchClause.relationships = void 0;
244
- matchClause.additionalMatches = void 0;
245
- }
246
- return matchClause;
247
- }
248
- /**
249
- * Parse a pattern chain: (node)-[:rel]->(node)-[:rel]->(node)...
250
- * Returns patterns and relationships for a single connected pattern
251
- */
252
- parsePatternChain() {
253
- const patterns = [];
254
- const relationships = [];
255
- patterns.push(this.parseNodePattern());
256
- while (this.current().type === import_lexer.TokenType.DASH || this.current().type === import_lexer.TokenType.ARROW) {
257
- relationships.push(this.parseRelationship());
258
- patterns.push(this.parseNodePattern());
259
- }
260
- return {
261
- type: "MatchStatement",
262
- patterns,
263
- relationships: relationships.length > 0 ? relationships : void 0
264
- };
265
- }
266
- /**
267
- * Parse WHERE clause
268
- * Example: WHERE m.type = "Command" AND "param" IN m.parameters
269
- * Note: Flat properties only (no nesting, like Neo4j Cypher)
270
- */
271
- parseWhere() {
272
- this.expect(import_lexer.TokenType.WHERE);
273
- const conditions = [];
274
- let logic;
275
- while (true) {
276
- const variable = this.expect(import_lexer.TokenType.IDENTIFIER).value;
277
- let property;
278
- if (this.current().type === import_lexer.TokenType.DOT) {
279
- this.advance();
280
- property = this.expect(import_lexer.TokenType.IDENTIFIER).value;
281
- }
282
- let operator = "=";
283
- if (this.current().type === import_lexer.TokenType.EQUALS) {
284
- operator = "=";
285
- this.advance();
286
- } else if (this.current().type === import_lexer.TokenType.NOT_EQUALS) {
287
- operator = "!=";
288
- this.advance();
289
- } else if (this.current().type === import_lexer.TokenType.GT) {
290
- operator = ">";
291
- this.advance();
292
- } else if (this.current().type === import_lexer.TokenType.LT) {
293
- operator = "<";
294
- this.advance();
295
- } else if (this.current().type === import_lexer.TokenType.GTE) {
296
- operator = ">=";
297
- this.advance();
298
- } else if (this.current().type === import_lexer.TokenType.LTE) {
299
- operator = "<=";
300
- this.advance();
301
- } else if (this.current().type === import_lexer.TokenType.NOT) {
302
- this.advance();
303
- this.expect(import_lexer.TokenType.IN);
304
- operator = "NOT IN";
305
- } else if (this.current().type === import_lexer.TokenType.IN) {
306
- this.advance();
307
- operator = "IN";
308
- } else if (this.current().type === import_lexer.TokenType.IS) {
309
- this.advance();
310
- if (this.isKeyword(import_lexer.TokenType.NULL)) {
311
- this.advance();
312
- operator = "IS NULL";
313
- } else if (this.isKeyword(import_lexer.TokenType.NOT)) {
314
- this.advance();
315
- this.expect(import_lexer.TokenType.NULL);
316
- operator = "IS NOT NULL";
317
- } else {
318
- throw new Error(
319
- `Expected NULL or NOT NULL after IS at position ${this.current().position}`
320
- );
321
- }
322
- } else if (this.current().type === import_lexer.TokenType.STARTS) {
323
- this.advance();
324
- this.expect(import_lexer.TokenType.WITH);
325
- operator = "STARTS WITH";
326
- } else if (this.current().type === import_lexer.TokenType.ENDS) {
327
- this.advance();
328
- this.expect(import_lexer.TokenType.WITH);
329
- operator = "ENDS WITH";
330
- } else if (this.current().type === import_lexer.TokenType.CONTAINS) {
331
- operator = "CONTAINS";
332
- this.advance();
333
- } else if (this.current().type === import_lexer.TokenType.REGEX_MATCH) {
334
- operator = "=~";
335
- this.advance();
336
- } else {
337
- throw new Error(
338
- `Unsupported operator at position ${this.current().position}.`
339
- );
340
- }
341
- let value = null;
342
- if (operator === "IS NULL" || operator === "IS NOT NULL") {
343
- } else if (operator === "STARTS WITH" || operator === "ENDS WITH" || operator === "CONTAINS" || operator === "=~") {
344
- if (this.current().type === import_lexer.TokenType.STRING) {
345
- value = this.advance().value;
346
- } else {
347
- throw new Error(
348
- `String matching operators (${operator}) require a string value at position ${this.current().position}`
349
- );
350
- }
351
- } else if (this.current().type === import_lexer.TokenType.LBRACKET) {
352
- value = this.parseArrayLiteral();
353
- } else if (this.current().type === import_lexer.TokenType.STRING) {
354
- value = this.advance().value;
355
- } else if (this.current().type === import_lexer.TokenType.NUMBER) {
356
- value = parseFloat(this.advance().value);
357
- } else if (this.current().type === import_lexer.TokenType.TRUE) {
358
- value = true;
359
- this.advance();
360
- } else if (this.current().type === import_lexer.TokenType.FALSE) {
361
- value = false;
362
- this.advance();
363
- } else if (this.current().type === import_lexer.TokenType.IDENTIFIER) {
364
- value = this.advance().value;
365
- } else {
366
- throw new Error(
367
- `Unexpected token type for WHERE value: ${this.current().type}`
368
- );
369
- }
370
- conditions.push({ variable, property, operator, value });
371
- if (this.isKeyword(import_lexer.TokenType.AND)) {
372
- if (logic === void 0) {
373
- logic = "AND";
374
- } else if (logic !== "AND") {
375
- throw new Error("Cannot mix AND and OR in WHERE clause");
376
- }
377
- this.advance();
378
- continue;
379
- } else if (this.isKeyword(import_lexer.TokenType.OR)) {
380
- if (logic === void 0) {
381
- logic = "OR";
382
- } else if (logic !== "OR") {
383
- throw new Error("Cannot mix AND and OR in WHERE clause");
384
- }
385
- this.advance();
386
- continue;
387
- }
388
- break;
389
- }
390
- return {
391
- type: "WhereClause",
392
- conditions,
393
- logic
394
- };
395
- }
396
- /**
397
- * Parse array literal: [value1, value2, ...]
398
- */
399
- parseArrayLiteral() {
400
- this.expect(import_lexer.TokenType.LBRACKET);
401
- const array = [];
402
- if (this.current().type === import_lexer.TokenType.RBRACKET) {
403
- this.advance();
404
- return array;
405
- }
406
- while (true) {
407
- if (this.current().type === import_lexer.TokenType.STRING) {
408
- array.push(this.advance().value);
409
- } else if (this.current().type === import_lexer.TokenType.NUMBER) {
410
- array.push(parseFloat(this.advance().value));
411
- } else if (this.current().type === import_lexer.TokenType.TRUE) {
412
- array.push(true);
413
- this.advance();
414
- } else if (this.current().type === import_lexer.TokenType.FALSE) {
415
- array.push(false);
416
- this.advance();
417
- } else if (this.current().type === import_lexer.TokenType.IDENTIFIER) {
418
- array.push(this.advance().value);
419
- } else {
420
- throw new Error(
421
- `Unexpected token type in array literal: ${this.current().type}`
422
- );
423
- }
424
- if (this.current().type === import_lexer.TokenType.COMMA) {
425
- this.advance();
426
- } else if (this.current().type === import_lexer.TokenType.RBRACKET) {
427
- this.advance();
428
- break;
429
- } else {
430
- throw new Error(
431
- `Expected comma or closing bracket in array literal at position ${this.current().position}`
432
- );
433
- }
434
- }
435
- return array;
436
- }
437
- /**
438
- * Parse RETURN clause
439
- * Supports: RETURN *, RETURN var1, var2, RETURN var AS alias, LIMIT n
440
- */
441
- parseReturn() {
442
- this.expect(import_lexer.TokenType.RETURN);
443
- if (this.current().type === import_lexer.TokenType.ASTERISK) {
444
- this.advance();
445
- const limit2 = this.parseOptionalLimit();
446
- return {
447
- type: "ReturnClause",
448
- returnAll: true,
449
- items: [],
450
- limit: limit2
451
- };
452
- }
453
- const items = [];
454
- while (true) {
455
- const expression = this.expect(import_lexer.TokenType.IDENTIFIER).value;
456
- let alias;
457
- if (this.isKeyword(import_lexer.TokenType.AS)) {
458
- this.advance();
459
- alias = this.expect(import_lexer.TokenType.IDENTIFIER).value;
460
- }
461
- items.push({ expression, alias });
462
- if (this.current().type === import_lexer.TokenType.COMMA) {
463
- this.advance();
464
- continue;
465
- }
466
- break;
467
- }
468
- const limit = this.parseOptionalLimit();
469
- return {
470
- type: "ReturnClause",
471
- returnAll: false,
472
- items,
473
- limit
474
- };
475
- }
476
- /**
477
- * Parse optional LIMIT clause
478
- * Returns the limit number or undefined if not present
479
- */
480
- parseOptionalLimit() {
481
- if (this.isKeyword(import_lexer.TokenType.LIMIT)) {
482
- this.advance();
483
- const limitToken = this.expect(import_lexer.TokenType.NUMBER);
484
- return parseInt(limitToken.value, 10);
485
- }
486
- return void 0;
487
- }
488
- /**
489
- * Parse ORDER BY clause
490
- * Supports: ORDER BY n.name, ORDER BY n.name ASC, ORDER BY n.name DESC
491
- * Also supports multiple fields: ORDER BY n.type DESC, n.name ASC
492
- */
493
- parseOrderBy() {
494
- this.expect(import_lexer.TokenType.ORDER);
495
- this.expect(import_lexer.TokenType.BY);
496
- const items = [];
497
- while (true) {
498
- const variable = this.expect(import_lexer.TokenType.IDENTIFIER).value;
499
- let property;
500
- if (this.current().type === import_lexer.TokenType.DOT) {
501
- this.advance();
502
- property = this.expect(import_lexer.TokenType.IDENTIFIER).value;
503
- }
504
- let direction = "ASC";
505
- if (this.isKeyword(import_lexer.TokenType.ASC)) {
506
- this.advance();
507
- direction = "ASC";
508
- } else if (this.isKeyword(import_lexer.TokenType.DESC)) {
509
- this.advance();
510
- direction = "DESC";
511
- }
512
- items.push({ variable, property, direction });
513
- if (this.current().type === import_lexer.TokenType.COMMA) {
514
- this.advance();
515
- continue;
516
- }
517
- break;
518
- }
519
- return { type: "OrderByStatement", items };
520
- }
521
- /**
522
- * Parse entire Cypher query
523
- * Returns statements in execution order
524
- */
525
- parse() {
526
- const statements = [];
527
- while (this.current().type !== import_lexer.TokenType.EOF) {
528
- if (this.isKeyword(import_lexer.TokenType.MATCH) || this.isKeyword(import_lexer.TokenType.OPTIONAL)) {
529
- const isOptional = this.isKeyword(import_lexer.TokenType.OPTIONAL);
530
- const matchClause = this.parseMatch();
531
- if (matchClause.optionalMatches) {
532
- for (const optionalMatch of matchClause.optionalMatches) {
533
- statements.push({
534
- type: "MatchStatement",
535
- patterns: optionalMatch.patterns,
536
- relationships: optionalMatch.relationships,
537
- optional: true
538
- });
539
- }
540
- } else {
541
- if (matchClause.patterns.length > 0) {
542
- statements.push({
543
- type: "MatchStatement",
544
- patterns: matchClause.patterns,
545
- relationships: matchClause.relationships,
546
- optional: false
547
- });
548
- }
549
- if (matchClause.additionalMatches) {
550
- for (const additionalMatch of matchClause.additionalMatches) {
551
- statements.push({
552
- type: "MatchStatement",
553
- patterns: additionalMatch.patterns,
554
- relationships: additionalMatch.relationships,
555
- optional: false
556
- });
557
- }
558
- }
559
- }
560
- continue;
561
- }
562
- if (this.isKeyword(import_lexer.TokenType.WHERE)) {
563
- const whereClause = this.parseWhere();
564
- statements.push({
565
- type: "WhereStatement",
566
- conditions: whereClause.conditions,
567
- logic: whereClause.logic
568
- });
569
- continue;
570
- }
571
- if (this.isKeyword(import_lexer.TokenType.ORDER)) {
572
- const orderByStatement = this.parseOrderBy();
573
- statements.push(orderByStatement);
574
- continue;
575
- }
576
- if (this.isKeyword(import_lexer.TokenType.RETURN)) {
577
- const returnClause = this.parseReturn();
578
- statements.push({
579
- type: "ReturnStatement",
580
- returnAll: returnClause.returnAll,
581
- items: returnClause.items,
582
- limit: returnClause.limit
583
- });
584
- continue;
585
- }
586
- break;
587
- }
588
- if (this.current().type !== import_lexer.TokenType.EOF) {
589
- throw new Error(
590
- `Unexpected token: ${this.current().type} at position ${this.current().position}`
591
- );
592
- }
593
- return {
594
- type: "CypherQuery",
595
- statements
596
- };
597
- }
598
- }
599
- // Annotate the CommonJS export names for ESM import in node:
600
- 0 && (module.exports = {
601
- Parser
602
- });
@@ -1,95 +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 query_validator_exports = {};
19
- __export(query_validator_exports, {
20
- UnsupportedFeatureError: () => UnsupportedFeatureError,
21
- validateQuery: () => validateQuery,
22
- validateQuerySafe: () => validateQuerySafe
23
- });
24
- module.exports = __toCommonJS(query_validator_exports);
25
- var import_unsupported_features = require("./unsupported-features.config");
26
- const UNSUPPORTED_FEATURES = [
27
- ...import_unsupported_features.FORBIDDEN_KEYWORDS,
28
- ...import_unsupported_features.FORBIDDEN_AGGREGATIONS,
29
- ...import_unsupported_features.FORBIDDEN_MODIFIERS,
30
- ...import_unsupported_features.FORBIDDEN_PATTERNS
31
- ];
32
- class UnsupportedFeatureError extends Error {
33
- constructor(feature, query) {
34
- const message = `Unsupported Cypher feature detected: ${feature.name}
35
-
36
- ${feature.errorMessage}${feature.alternative ? `
37
-
38
- Alternative: ${feature.alternative}` : ""}
39
-
40
- Query: ${query}`;
41
- super(message);
42
- this.feature = feature;
43
- this.query = query;
44
- this.name = "UnsupportedFeatureError";
45
- }
46
- }
47
- function validateQuery(query) {
48
- if (!query || typeof query !== "string") {
49
- throw new Error("Query must be a non-empty string");
50
- }
51
- const normalizedQuery = query.trim();
52
- if (normalizedQuery.length === 0) {
53
- throw new Error("Query cannot be empty");
54
- }
55
- for (const feature of UNSUPPORTED_FEATURES) {
56
- const pattern = typeof feature.pattern === "string" ? new RegExp(feature.pattern, "i") : feature.pattern;
57
- if (pattern.test(normalizedQuery)) {
58
- if (feature.name === "WITH clause") {
59
- const withMatches = normalizedQuery.matchAll(/\bWITH\b/gi);
60
- let isAllowed = false;
61
- for (const match of withMatches) {
62
- const beforeMatch = normalizedQuery.substring(
63
- Math.max(0, match.index - 10),
64
- match.index
65
- );
66
- if (/\bSTARTS\s+$/i.test(beforeMatch) || /\bENDS\s+$/i.test(beforeMatch)) {
67
- isAllowed = true;
68
- break;
69
- }
70
- }
71
- if (isAllowed) {
72
- continue;
73
- }
74
- }
75
- throw new UnsupportedFeatureError(feature, normalizedQuery);
76
- }
77
- }
78
- }
79
- function validateQuerySafe(query) {
80
- try {
81
- validateQuery(query);
82
- return { valid: true };
83
- } catch (error) {
84
- if (error instanceof UnsupportedFeatureError) {
85
- return { valid: false, error };
86
- }
87
- throw error;
88
- }
89
- }
90
- // Annotate the CommonJS export names for ESM import in node:
91
- 0 && (module.exports = {
92
- UnsupportedFeatureError,
93
- validateQuery,
94
- validateQuerySafe
95
- });