flowquery 1.0.67 → 1.0.68

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.
@@ -1,22 +1,46 @@
1
1
  import ASTNode from "./ast_node";
2
2
  /**
3
3
  * Per-entity lineage for a node label: which properties the query
4
- * accesses on it, and which sources (URLs / file URIs / async-function
5
- * names) back the virtual definition for that label.
4
+ * accesses on it, the sources backing the virtual definition, and any
5
+ * literal values the query supplies for those properties.
6
6
  */
7
7
  export interface NodeInfo {
8
8
  properties: string[];
9
9
  sources: string[];
10
+ /**
11
+ * Literal values supplied for this label's properties at the call
12
+ * site. Collected from inline node-property assignments
13
+ * (`(u:User {id: 'rick.o'})`) and from equality / `IN` predicates
14
+ * (`WHERE u.id = 'rick.o'`, `WHERE u.id IN ['a', 'b']`).
15
+ *
16
+ * Only purely literal AST subtrees (no references, parameters,
17
+ * f-strings, or subqueries) are captured. Always present in objects
18
+ * produced by the crawler (defaults to `{}`); optional in the
19
+ * interface so externally-constructed `NodeInfo` literals remain
20
+ * valid.
21
+ */
22
+ literal_values?: Record<string, any[]>;
10
23
  }
11
24
  /**
12
25
  * Per-entity lineage for a relationship type: which properties the query
13
- * accesses on it, and which sources back the virtual definitions for
14
- * that type. A single type may have multiple sources when it spans
15
- * several `(:From)-[:Type]-(:To)` definitions.
26
+ * accesses on it, the sources backing the virtual definitions, and any
27
+ * literal values supplied for those properties. A single type may have
28
+ * multiple sources when it spans several `(:From)-[:Type]-(:To)` definitions.
16
29
  */
17
30
  export interface RelationshipInfo {
18
31
  properties: string[];
19
32
  sources: string[];
33
+ /** Literal values supplied for this type's properties at the call site. */
34
+ literal_values?: Record<string, any[]>;
35
+ }
36
+ /**
37
+ * Schema-level lineage: the full set of properties projected by a virtual
38
+ * definition (independent of whether the crawled statement consumes them)
39
+ * plus the sources that back the definition.
40
+ */
41
+ export interface DeclaredEntityInfo {
42
+ properties: string[];
43
+ sources: string[];
20
44
  }
21
45
  /**
22
46
  * Structural information extracted from a parsed FlowQuery statement.
@@ -24,12 +48,18 @@ export interface RelationshipInfo {
24
48
  * Captures the node labels, relationship types, data sources, and properties
25
49
  * the query references — independent of whether/when it has been executed.
26
50
  * The properties listed are those accessed by the *query itself* (e.g.
27
- * `n.name` in a MATCH/RETURN/WHERE), not the columns produced by the
28
- * underlying virtual node/relationship definitions.
51
+ * `n.name` in a MATCH/RETURN/WHERE/ORDER BY), not the columns produced by
52
+ * the underlying virtual node/relationship definitions.
29
53
  *
30
54
  * To trace the full lineage from a property to its source, use the
31
55
  * {@link nodes} / {@link relationships} maps. Each entry there links a
32
- * label/type to its accessed properties and the sources that back it.
56
+ * label/type to its accessed properties, the sources that back it, and
57
+ * any literal values supplied at the call site.
58
+ *
59
+ * To validate a query against the registered schema (e.g. "is
60
+ * `User.phoneNumber` a declared property?"), use {@link declared}, which
61
+ * lists the *full* set of properties projected by each virtual's RETURN
62
+ * clause regardless of whether the query consumes them.
33
63
  */
34
64
  export interface StatementInfo {
35
65
  /** Unique node labels referenced by MATCH/CREATE/DELETE in the statement(s). */
@@ -50,14 +80,31 @@ export interface StatementInfo {
50
80
  relationship_properties: Record<string, string[]>;
51
81
  /**
52
82
  * Per-label lineage: each accessed node label mapped to the
53
- * properties accessed on it and the sources that back it.
83
+ * properties accessed on it, the sources that back it, and any
84
+ * literal values supplied for those properties at the call site.
54
85
  */
55
86
  nodes: Record<string, NodeInfo>;
56
87
  /**
57
88
  * Per-type lineage: each accessed relationship type mapped to the
58
- * properties accessed on it and the sources that back it.
89
+ * properties accessed on it, the sources that back it, and any
90
+ * literal values supplied for those properties at the call site.
59
91
  */
60
92
  relationships: Record<string, RelationshipInfo>;
93
+ /**
94
+ * Schema-declared lineage. Lists, per label / relationship type, the
95
+ * full set of properties projected by the virtual's RETURN clause
96
+ * (or final WITH if no RETURN is present) — independent of whether
97
+ * the crawled statement actually consumes them. Useful for validating
98
+ * that a query references only declared properties.
99
+ *
100
+ * Includes both inline `CREATE VIRTUAL` declarations in the crawled
101
+ * statements and any already-registered virtuals the statement
102
+ * touches.
103
+ */
104
+ declared: {
105
+ nodes: Record<string, DeclaredEntityInfo>;
106
+ relationships: Record<string, DeclaredEntityInfo>;
107
+ };
61
108
  }
62
109
  /**
63
110
  * Walks one or more parsed FlowQuery statement ASTs and extracts a
@@ -82,12 +129,18 @@ declare class StatementInfoCrawler {
82
129
  private _relProps;
83
130
  private _nodeSources;
84
131
  private _relSources;
132
+ private _nodeLiterals;
133
+ private _relLiterals;
134
+ private _nodeDeclaredProps;
135
+ private _relDeclaredProps;
136
+ private _nodeDeclaredSources;
137
+ private _relDeclaredSources;
85
138
  private _ownCreatedNodeLabels;
86
139
  private _ownCreatedRelTypes;
87
140
  /**
88
141
  * For each inline CREATE VIRTUAL clause, the (label or type) it
89
142
  * declares and its inner statement AST. The label key receives the
90
- * sources collected from the statement during {@link resolveRegisteredSources}.
143
+ * sources collected from the statement during {@link resolveRegisteredDefinitions}.
91
144
  */
92
145
  private _ownNodeCreates;
93
146
  private _ownRelCreates;
@@ -102,12 +155,57 @@ declare class StatementInfoCrawler {
102
155
  private reset;
103
156
  private crawlStatement;
104
157
  private visitOperation;
105
- private resolveRegisteredSources;
158
+ private resolveRegisteredDefinitions;
106
159
  private getOrCreate;
160
+ /**
161
+ * Walks the AST rooted at `root` and records every property access
162
+ * (via `Lookup`) on a known node/relationship binding, every literal
163
+ * value supplied via equality / `IN` predicates, and descends into
164
+ * subqueries plus the privately-held WHERE / ORDER BY ASTs of
165
+ * RETURN-style operations.
166
+ */
107
167
  private collectPropertyAccesses;
168
+ private handleLookupAccess;
169
+ /**
170
+ * Resolves a `Lookup` of the shape `alias.prop` to the labels/types
171
+ * of the bound entity and the property name. Returns `null` if the
172
+ * lookup isn't of that shape or its variable doesn't resolve to a
173
+ * Node/Relationship.
174
+ */
175
+ private resolveLookupTarget;
176
+ private handleEqualityLiteral;
177
+ private tryRecordPropEquality;
178
+ private handleInLiteral;
179
+ /**
180
+ * Returns true iff the AST subtree contains only literal nodes (no
181
+ * References, ParameterReferences, Lookups, FStrings, or
182
+ * SubqueryExpressions). Used to guard literal-value extraction
183
+ * against runtime-dependent expressions.
184
+ */
185
+ private isLiteralAst;
186
+ private safeEvaluate;
187
+ private tryAddNodeLiteral;
188
+ private tryAddRelLiteral;
189
+ /**
190
+ * Walks a virtual definition's inner statement to find the final
191
+ * RETURN-style projection and records its aliases as the declared
192
+ * property set. Falls back to the last WITH if no RETURN exists.
193
+ */
194
+ private collectDeclaredProps;
195
+ /**
196
+ * Yields the alias of every projected expression in a Projection.
197
+ * Mirrors the alias-resolution logic of `Projection.expressions()`
198
+ * (which is protected).
199
+ */
200
+ private projectionAliases;
108
201
  private collectSources;
109
202
  private addNodeProp;
110
203
  private addRelProp;
204
+ private addNodeLiteralValue;
205
+ private addRelLiteralValue;
206
+ private appendUniqueLiteral;
207
+ private literalsEqual;
208
+ private literalsSnapshot;
111
209
  private snapshot;
112
210
  /**
113
211
  * Returns a deep copy of a StatementInfo so callers can mutate it freely.
@@ -1 +1 @@
1
- {"version":3,"file":"statement_info_crawler.d.ts","sourceRoot":"","sources":["../../src/parsing/statement_info_crawler.ts"],"names":[],"mappings":"AAGA,OAAO,OAAO,MAAM,YAAY,CAAC;AAajC;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC7B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,aAAa;IAC1B,gFAAgF;IAChF,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,uFAAuF;IACvF,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,mEAAmE;IACnE,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