flowquery 1.0.63 → 1.0.65

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.
@@ -4,9 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const context_1 = __importDefault(require("./context"));
7
+ const expression_1 = __importDefault(require("./expressions/expression"));
8
+ /**
9
+ * Mutable parser state shared across operation parsers.
10
+ *
11
+ * Two scope concepts are tracked:
12
+ *
13
+ * - `variables` is the *current* scope. It is updated in place as the
14
+ * parser walks forward (MATCH binds nodes/relationships, UNWIND binds
15
+ * its alias, RETURN/WITH register projection aliases, etc.).
16
+ * - `inputScope` is an optional snapshot of `variables` taken at the
17
+ * start of a RETURN/WITH clause, *before* its projection aliases are
18
+ * registered. It is consulted by `resolve` so that trailing modifiers
19
+ * attached to that clause (ORDER BY / WHERE / LIMIT) can still see the
20
+ * pre-projection bindings — making references such as
21
+ * `ORDER BY peer.name` after `RETURN peer.name AS peer` resolve to the
22
+ * matched node rather than the projected scalar.
23
+ */
7
24
  class ParserState {
8
25
  constructor() {
9
26
  this._variables = new Map();
27
+ this._variableStack = [];
28
+ this._inputScope = null;
10
29
  this._context = new context_1.default();
11
30
  this._returns = 0;
12
31
  this._inVirtualDefinition = false;
@@ -14,6 +33,89 @@ class ParserState {
14
33
  get variables() {
15
34
  return this._variables;
16
35
  }
36
+ /**
37
+ * Save the current variable scope onto a stack and start a child
38
+ * scope that inherits the outer bindings. Mutations made in the
39
+ * child scope (typically registering a single block-local name) do
40
+ * not leak back to the outer scope when `popVariableScope` is
41
+ * called. Used for syntactic blocks that introduce their own
42
+ * binding — list comprehensions, predicate-function bodies, etc.
43
+ */
44
+ pushVariableScope() {
45
+ this._variableStack.push(this._variables);
46
+ this._variables = new Map(this._variables);
47
+ }
48
+ /**
49
+ * Restore the variable scope previously pushed by
50
+ * `pushVariableScope`.
51
+ */
52
+ popVariableScope() {
53
+ const previous = this._variableStack.pop();
54
+ if (previous === undefined) {
55
+ throw new Error("popVariableScope without matching pushVariableScope");
56
+ }
57
+ this._variables = previous;
58
+ }
59
+ /**
60
+ * Seed the current variable scope with the bindings of another
61
+ * parser state. Used when entering a subquery expression: the
62
+ * subquery gets its own fresh state (with independent returns
63
+ * counter, aggregate context, input-scope snapshot, etc.) but
64
+ * still needs to see the outer query's variable bindings.
65
+ */
66
+ inheritVariablesFrom(other) {
67
+ for (const [k, v] of other._variables) {
68
+ this._variables.set(k, v);
69
+ }
70
+ }
71
+ get inputScope() {
72
+ return this._inputScope;
73
+ }
74
+ /**
75
+ * Capture the current variable scope as the clause input scope.
76
+ *
77
+ * Called by RETURN/WITH parsers immediately before their projection
78
+ * expressions are registered, so that `inputScope` reflects what
79
+ * was visible *before* the projections introduced any aliases.
80
+ */
81
+ takeInputScopeSnapshot() {
82
+ this._inputScope = new Map(this._variables);
83
+ }
84
+ /**
85
+ * Drop the clause input snapshot. Called once a clause's trailing
86
+ * modifiers (ORDER BY / WHERE / LIMIT) have been parsed.
87
+ */
88
+ clearInputScope() {
89
+ this._inputScope = null;
90
+ }
91
+ /**
92
+ * Resolve an identifier reference during expression parsing.
93
+ *
94
+ * The current (output) scope wins by default — this is what makes
95
+ * post-aggregation references such as `WHERE i = 1` after
96
+ * `RETURN i, sum(j) AS sum` see the grouped value through the
97
+ * projection's override mechanism.
98
+ *
99
+ * When the reference is followed by a property or index access
100
+ * (`propertyAccess` is true) and an input-scope snapshot is active,
101
+ * the input binding is preferred whenever the current binding is a
102
+ * projection alias (Expression) while the input bound the same name
103
+ * to a graph entity (Node / Relationship / Pattern / Unwind / Load —
104
+ * anything that is not itself an Expression). This makes
105
+ * `ORDER BY peer.name` after `RETURN peer.name AS peer` reach the
106
+ * matched node rather than crashing on subscripting the projected
107
+ * string.
108
+ */
109
+ resolve(identifier, propertyAccess = false) {
110
+ const current = this._variables.get(identifier);
111
+ if (propertyAccess && this._inputScope !== null && current instanceof expression_1.default) {
112
+ const inherited = this._inputScope.get(identifier);
113
+ if (inherited !== undefined && !(inherited instanceof expression_1.default)) {
114
+ return inherited;
115
+ }
116
+ }
117
+ return current;
118
+ }
17
119
  get context() {
18
120
  return this._context;
19
121
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parser_state.js","sourceRoot":"","sources":["../../src/parsing/parser_state.ts"],"names":[],"mappings":";;;;;AACA,wDAAgC;AAEhC,MAAM,WAAW;IAAjB;QACY,eAAU,GAAyB,IAAI,GAAG,EAAE,CAAC;QAC7C,aAAQ,GAAY,IAAI,iBAAO,EAAE,CAAC;QAClC,aAAQ,GAAW,CAAC,CAAC;QACrB,yBAAoB,GAAY,KAAK,CAAC;IAsBlD,CAAC;IApBG,IAAW,SAAS;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IACM,gBAAgB;QACnB,IAAI,CAAC,QAAQ,EAAE,CAAC;IACpB,CAAC;IACD,IAAW,mBAAmB;QAC1B,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;IACD,IAAW,mBAAmB,CAAC,KAAc;QACzC,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACtC,CAAC;CACJ;AAED,kBAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"parser_state.js","sourceRoot":"","sources":["../../src/parsing/parser_state.ts"],"names":[],"mappings":";;;;;AACA,wDAAgC;AAChC,0EAAkD;AAElD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW;IAAjB;QACY,eAAU,GAAyB,IAAI,GAAG,EAAE,CAAC;QAC7C,mBAAc,GAA2B,EAAE,CAAC;QAC5C,gBAAW,GAAgC,IAAI,CAAC;QAChD,aAAQ,GAAY,IAAI,iBAAO,EAAE,CAAC;QAClC,aAAQ,G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QAChD,IAAI,cAAc,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,OAAO,YAAY,oBAAU,EAAE,CAAC;YAC/E,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACnD,IAAI,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC,SAAS,YAAY,oBAAU,CAAC,EAAE,CAAC;gBAChE,OAAO,SAAS,CAAC;YACrB,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IACM,gBAAgB;QACnB,IAAI,CAAC,QAAQ,EAAE,CAAC;IACpB,CAAC;IACD,IAAW,mBAAmB;QAC1B,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;IACD,IAAW,mBAAmB,CAAC,KAAc;QACzC,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;IACtC,CAAC;CACJ;AAED,kBAAe,WAAW,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flowquery",
3
- "version": "1.0.63",
3
+ "version": "1.0.65",
4
4
  "description": "A declarative query language for data processing pipelines.",
5
5
  "main": "dist/index.node.js",
6
6
  "types": "dist/index.node.d.ts",