patram 0.11.0 → 0.12.0
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/patram.js +4 -4
- package/lib/cli/commands/fields.js +0 -4
- package/lib/cli/commands/queries.js +10 -20
- package/lib/cli/commands/query.js +1 -8
- package/lib/cli/commands/refs.js +3 -10
- package/lib/cli/commands/show.js +1 -8
- package/lib/cli/help-metadata.js +71 -106
- package/lib/cli/main.js +10 -10
- package/lib/cli/parse-arguments-helpers.js +165 -59
- package/lib/cli/parse-arguments.js +4 -4
- package/lib/cli/render-help.js +2 -2
- package/lib/config/defaults.js +33 -25
- package/lib/config/load-patram-config.d.ts +8 -33
- package/lib/config/load-patram-config.js +9 -33
- package/lib/config/load-patram-config.types.d.ts +3 -40
- package/lib/config/manage-stored-queries-helpers.d.ts +4 -4
- package/lib/config/manage-stored-queries-helpers.js +91 -33
- package/lib/config/manage-stored-queries.d.ts +4 -4
- package/lib/config/manage-stored-queries.js +11 -5
- package/lib/config/patram-config.d.ts +34 -34
- package/lib/config/patram-config.js +3 -3
- package/lib/config/patram-config.types.d.ts +5 -11
- package/lib/config/resolve-patram-graph-config.d.ts +5 -1
- package/lib/config/resolve-patram-graph-config.js +3 -119
- package/lib/config/schema.d.ts +158 -269
- package/lib/config/schema.js +72 -210
- package/lib/config/validate-patram-config-value.js +6 -31
- package/lib/config/validation.d.ts +2 -12
- package/lib/config/validation.js +125 -483
- package/lib/find-close-match.d.ts +4 -1
- package/lib/graph/build-graph-identity.d.ts +1 -32
- package/lib/graph/build-graph-identity.js +5 -269
- package/lib/graph/build-graph.d.ts +13 -4
- package/lib/graph/build-graph.js +347 -488
- package/lib/graph/build-graph.types.d.ts +8 -9
- package/lib/graph/check-directive-metadata-helpers.d.ts +30 -0
- package/lib/graph/check-directive-metadata-helpers.js +126 -0
- package/lib/graph/check-directive-metadata.d.ts +8 -9
- package/lib/graph/check-directive-metadata.js +70 -561
- package/lib/graph/check-directive-path-target.d.ts +6 -13
- package/lib/graph/check-directive-path-target.js +26 -57
- package/lib/graph/check-directive-value.d.ts +1 -5
- package/lib/graph/check-directive-value.js +40 -180
- package/lib/graph/check-graph.d.ts +5 -5
- package/lib/graph/check-graph.js +8 -6
- package/lib/graph/document-node-identity.d.ts +23 -7
- package/lib/graph/document-node-identity.js +417 -160
- package/lib/graph/graph-node.d.ts +42 -0
- package/lib/graph/graph-node.js +83 -0
- package/lib/graph/inspect-reverse-references.js +16 -11
- package/lib/graph/load-project-graph.d.ts +7 -7
- package/lib/graph/load-project-graph.js +7 -7
- package/lib/graph/parse-where-clause.types.d.ts +3 -2
- package/lib/graph/query/cypher-reader.d.ts +59 -0
- package/lib/graph/query/cypher-reader.js +151 -0
- package/lib/graph/query/cypher-support.d.ts +79 -0
- package/lib/graph/query/cypher-support.js +213 -0
- package/lib/graph/query/cypher-tokenize.d.ts +13 -0
- package/lib/graph/query/cypher-tokenize.js +225 -0
- package/lib/graph/query/cypher.types.d.ts +43 -0
- package/lib/graph/query/execute.d.ts +7 -7
- package/lib/graph/query/execute.js +71 -33
- package/lib/graph/query/inspect.js +58 -24
- package/lib/graph/query/parse-cypher-patterns.d.ts +27 -0
- package/lib/graph/query/parse-cypher-patterns.js +382 -0
- package/lib/graph/query/parse-cypher.d.ts +7 -0
- package/lib/graph/query/parse-cypher.js +580 -0
- package/lib/graph/query/parse-query.d.ts +13 -0
- package/lib/graph/query/parse-query.js +97 -0
- package/lib/graph/query/resolve.js +77 -23
- package/lib/output/command-output.js +12 -5
- package/lib/output/compact-layout.js +221 -0
- package/lib/output/format-output-item-block.js +31 -1
- package/lib/output/format-output-metadata.js +16 -29
- package/lib/output/format-stored-query-block.js +95 -0
- package/lib/output/layout-incoming-references.js +101 -19
- package/lib/output/layout-stored-queries.js +23 -330
- package/lib/output/list-queries.js +1 -1
- package/lib/output/render-field-discovery.js +11 -2
- package/lib/output/render-output-view.js +9 -5
- package/lib/output/renderers/json.js +5 -26
- package/lib/output/renderers/plain.js +155 -35
- package/lib/output/renderers/rich.js +250 -36
- package/lib/output/resolved-link-layout.js +43 -0
- package/lib/output/rich-source/render.js +193 -35
- package/lib/output/show-document.js +25 -18
- package/lib/output/view-model/index.js +124 -103
- package/lib/parse/jsdoc/parse-jsdoc-blocks.js +1 -1
- package/lib/parse/jsdoc/parse-jsdoc-claims.js +12 -6
- package/lib/parse/markdown/parse-markdown-claims.js +99 -62
- package/lib/parse/markdown/parse-markdown-directives.d.ts +10 -6
- package/lib/parse/markdown/parse-markdown-directives.js +104 -18
- package/lib/parse/markdown/parse-markdown-prose.d.ts +27 -0
- package/lib/parse/markdown/parse-markdown-prose.js +243 -0
- package/lib/parse/parse-claims.d.ts +2 -6
- package/lib/parse/parse-claims.js +11 -53
- package/lib/parse/tagged-fenced/tagged-fenced-blocks.d.ts +4 -4
- package/lib/parse/tagged-fenced/tagged-fenced-blocks.js +4 -4
- package/lib/parse/yaml/parse-yaml-claims.js +4 -4
- package/lib/patram.d.ts +3 -5
- package/lib/patram.js +1 -1
- package/lib/scan/discover-fields.js +194 -55
- package/lib/scan/list-source-files.d.ts +4 -4
- package/lib/scan/list-source-files.js +4 -4
- package/package.json +1 -1
- package/lib/directive-validation-test-helpers.js +0 -87
- package/lib/graph/query/parse.d.ts +0 -75
- package/lib/graph/query/parse.js +0 -1064
- package/lib/output/derived-summary.js +0 -280
- package/lib/output/format-derived-summary-row.js +0 -9
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { GraphNode } from './build-graph.types.d.ts';
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {GraphNode &
|
|
6
|
+
* Record<string, unknown> & {
|
|
7
|
+
* $class?: string,
|
|
8
|
+
* $path?: string,
|
|
9
|
+
* id?: string,
|
|
10
|
+
* kind?: string,
|
|
11
|
+
* path?: string,
|
|
12
|
+
* }} GraphNodeLike
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @param {GraphNode | undefined} graph_node
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
export function getGraphNodeId(graph_node: GraphNode | undefined): string;
|
|
19
|
+
/**
|
|
20
|
+
* @param {GraphNode | undefined} graph_node
|
|
21
|
+
* @returns {string | undefined}
|
|
22
|
+
*/
|
|
23
|
+
export function getGraphNodeClassName(graph_node: GraphNode | undefined): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* @param {GraphNode | undefined} graph_node
|
|
26
|
+
* @returns {string | undefined}
|
|
27
|
+
*/
|
|
28
|
+
export function getGraphNodePath(graph_node: GraphNode | undefined): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* @param {GraphNode | undefined} graph_node
|
|
31
|
+
* @param {string} field_name
|
|
32
|
+
* @returns {GraphNode['metadata'][string] | undefined}
|
|
33
|
+
*/
|
|
34
|
+
export function getGraphNodeMetadataValue(graph_node: GraphNode | undefined, field_name: string): GraphNode["metadata"][string] | undefined;
|
|
35
|
+
export type GraphNodeLike = GraphNode & Record<string, unknown> & {
|
|
36
|
+
$class?: string;
|
|
37
|
+
$path?: string;
|
|
38
|
+
id?: string;
|
|
39
|
+
kind?: string;
|
|
40
|
+
path?: string;
|
|
41
|
+
};
|
|
42
|
+
import type { GraphNode } from './build-graph.types.d.ts';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { GraphNode } from './build-graph.types.ts';
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {GraphNode &
|
|
7
|
+
* Record<string, unknown> & {
|
|
8
|
+
* $class?: string,
|
|
9
|
+
* $path?: string,
|
|
10
|
+
* id?: string,
|
|
11
|
+
* kind?: string,
|
|
12
|
+
* path?: string,
|
|
13
|
+
* }} GraphNodeLike
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {GraphNode | undefined} graph_node
|
|
18
|
+
* @returns {string}
|
|
19
|
+
*/
|
|
20
|
+
export function getGraphNodeId(graph_node) {
|
|
21
|
+
if (!graph_node) {
|
|
22
|
+
throw new Error('Expected a graph node.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const legacy_graph_node = /** @type {GraphNodeLike} */ (graph_node);
|
|
26
|
+
|
|
27
|
+
return graph_node.identity?.id ?? legacy_graph_node.id ?? '';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {GraphNode | undefined} graph_node
|
|
32
|
+
* @returns {string | undefined}
|
|
33
|
+
*/
|
|
34
|
+
export function getGraphNodeClassName(graph_node) {
|
|
35
|
+
if (!graph_node) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const legacy_graph_node = /** @type {GraphNodeLike} */ (graph_node);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
graph_node.identity?.class_name ??
|
|
43
|
+
legacy_graph_node.$class ??
|
|
44
|
+
legacy_graph_node.kind
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {GraphNode | undefined} graph_node
|
|
50
|
+
* @returns {string | undefined}
|
|
51
|
+
*/
|
|
52
|
+
export function getGraphNodePath(graph_node) {
|
|
53
|
+
if (!graph_node) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const legacy_graph_node = /** @type {GraphNodeLike} */ (graph_node);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
graph_node.identity?.path ??
|
|
61
|
+
legacy_graph_node.$path ??
|
|
62
|
+
legacy_graph_node.path
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {GraphNode | undefined} graph_node
|
|
68
|
+
* @param {string} field_name
|
|
69
|
+
* @returns {GraphNode['metadata'][string] | undefined}
|
|
70
|
+
*/
|
|
71
|
+
export function getGraphNodeMetadataValue(graph_node, field_name) {
|
|
72
|
+
if (!graph_node) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (graph_node.metadata) {
|
|
77
|
+
return graph_node.metadata[field_name];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return /** @type {GraphNode['metadata'][string] | undefined} */ (
|
|
81
|
+
/** @type {GraphNodeLike} */ (graph_node)[field_name]
|
|
82
|
+
);
|
|
83
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
normalizeRepoRelativePath,
|
|
8
8
|
resolveDocumentNodeId,
|
|
9
9
|
} from './document-node-identity.js';
|
|
10
|
+
import { getGraphNodeId } from './graph-node.js';
|
|
10
11
|
import { queryGraph } from './query/execute.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -30,7 +31,7 @@ export function inspectReverseReferences(
|
|
|
30
31
|
) {
|
|
31
32
|
const normalized_target_path = normalizeRepoRelativePath(target_file_path);
|
|
32
33
|
const target_node_id = resolveDocumentNodeId(
|
|
33
|
-
graph.
|
|
34
|
+
graph.document_path_ids,
|
|
34
35
|
normalized_target_path,
|
|
35
36
|
);
|
|
36
37
|
const target_node =
|
|
@@ -52,7 +53,7 @@ export function inspectReverseReferences(
|
|
|
52
53
|
diagnostics: [],
|
|
53
54
|
incoming: collectIncomingGroups(
|
|
54
55
|
graph,
|
|
55
|
-
target_node
|
|
56
|
+
getGraphNodeId(target_node),
|
|
56
57
|
allowed_source_node_ids,
|
|
57
58
|
),
|
|
58
59
|
node: target_node,
|
|
@@ -94,7 +95,7 @@ function collectIncomingGroups(graph, target_node_id, allowed_source_node_ids) {
|
|
|
94
95
|
grouped_incoming.set(graph_edge.relation, relation_sources);
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
relation_sources.set(source_node
|
|
98
|
+
relation_sources.set(getGraphNodeId(source_node), source_node);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
return formatIncomingGroups(grouped_incoming);
|
|
@@ -123,7 +124,9 @@ function resolveAllowedSourceNodeIds(graph, where_clause, repo_config) {
|
|
|
123
124
|
};
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
return new Set(
|
|
127
|
+
return new Set(
|
|
128
|
+
query_result.nodes.map((graph_node) => getGraphNodeId(graph_node)),
|
|
129
|
+
);
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
/**
|
|
@@ -156,12 +159,14 @@ function formatIncomingGroups(grouped_incoming) {
|
|
|
156
159
|
*/
|
|
157
160
|
function createFallbackTargetNode(node_id, target_path) {
|
|
158
161
|
return {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
identity: {
|
|
163
|
+
class_name: 'document',
|
|
164
|
+
id: node_id,
|
|
165
|
+
path: target_path,
|
|
166
|
+
},
|
|
167
|
+
metadata: {
|
|
168
|
+
title: target_path,
|
|
169
|
+
},
|
|
165
170
|
};
|
|
166
171
|
}
|
|
167
172
|
|
|
@@ -171,7 +176,7 @@ function createFallbackTargetNode(node_id, target_path) {
|
|
|
171
176
|
* @returns {number}
|
|
172
177
|
*/
|
|
173
178
|
function compareGraphNodes(left_node, right_node) {
|
|
174
|
-
return compareStrings(left_node
|
|
179
|
+
return compareStrings(getGraphNodeId(left_node), getGraphNodeId(right_node));
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
/**
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* Loads config, scans source files, parses claims, and materializes the graph
|
|
5
5
|
* used by CLI commands.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
7
|
+
* kind: graph
|
|
8
|
+
* status: active
|
|
9
|
+
* uses_term: ../../docs/reference/terms/claim.md
|
|
10
|
+
* uses_term: ../../docs/reference/terms/graph.md
|
|
11
|
+
* uses_term: ../../docs/reference/terms/mapping.md
|
|
12
|
+
* tracked_in: ../../docs/plans/v0/source-anchor-dogfooding.md
|
|
13
|
+
* decided_by: ../../docs/decisions/dogfood-query-graph-v0.md
|
|
14
14
|
* @patram
|
|
15
15
|
* @see {@link ../parse/parse-claims.js}
|
|
16
16
|
* @see {@link ./build-graph.js}
|
|
@@ -19,13 +19,13 @@ import { resolvePatramGraphConfig } from '../config/resolve-patram-graph-config.
|
|
|
19
19
|
* Loads config, scans source files, parses claims, and materializes the graph
|
|
20
20
|
* used by CLI commands.
|
|
21
21
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
22
|
+
* kind: graph
|
|
23
|
+
* status: active
|
|
24
|
+
* uses_term: ../../docs/reference/terms/claim.md
|
|
25
|
+
* uses_term: ../../docs/reference/terms/graph.md
|
|
26
|
+
* uses_term: ../../docs/reference/terms/mapping.md
|
|
27
|
+
* tracked_in: ../../docs/plans/v0/source-anchor-dogfooding.md
|
|
28
|
+
* decided_by: ../../docs/decisions/dogfood-query-graph-v0.md
|
|
29
29
|
* @patram
|
|
30
30
|
* @see {@link ../parse/parse-claims.js}
|
|
31
31
|
* @see {@link ./build-graph.js}
|
|
@@ -4,7 +4,7 @@ export interface ParsedFieldTerm {
|
|
|
4
4
|
column: number;
|
|
5
5
|
field_name: ParsedFieldName;
|
|
6
6
|
kind: 'field';
|
|
7
|
-
operator: '
|
|
7
|
+
operator: '$=' | '*=' | '<' | '<=' | '<>' | '=' | '>' | '>=' | '^=' | '~';
|
|
8
8
|
value: string;
|
|
9
9
|
}
|
|
10
10
|
export interface ParsedFieldSetTerm {
|
|
@@ -30,7 +30,7 @@ export interface ParsedRelationTargetTerm {
|
|
|
30
30
|
relation_name: string;
|
|
31
31
|
target_id: string;
|
|
32
32
|
}
|
|
33
|
-
export type ParsedAggregateComparison = '
|
|
33
|
+
export type ParsedAggregateComparison = '<' | '<=' | '<>' | '=' | '>' | '>=';
|
|
34
34
|
export type ParsedAggregateName = 'any' | 'count' | 'none';
|
|
35
35
|
export interface ParsedAggregateTerm {
|
|
36
36
|
aggregate_name: ParsedAggregateName;
|
|
@@ -61,3 +61,4 @@ export type ParseWhereClauseResult = {
|
|
|
61
61
|
diagnostic: PatramDiagnostic;
|
|
62
62
|
success: false;
|
|
63
63
|
};
|
|
64
|
+
export type ParseQueryResult = ParseWhereClauseResult;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {CypherParserState} parser_state
|
|
3
|
+
* @param {string} message
|
|
4
|
+
* @returns {{diagnostic: $k$$k$$l$$k$$k$$l$config$l$load$j$patram$j$config$k$types$k$ts.PatramDiagnostic, success: false}}
|
|
5
|
+
*/
|
|
6
|
+
export function failAtCurrent(parser_state: CypherParserState, message: string): {
|
|
7
|
+
diagnostic: $k$$k$$l$$k$$k$$l$config$l$load$j$patram$j$config$k$types$k$ts.PatramDiagnostic;
|
|
8
|
+
success: false;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @param {CypherParserState} parser_state
|
|
12
|
+
* @param {string} keyword
|
|
13
|
+
* @returns {CypherToken}
|
|
14
|
+
*/
|
|
15
|
+
export function expectKeyword(parser_state: CypherParserState, keyword: string): CypherToken;
|
|
16
|
+
/**
|
|
17
|
+
* @param {CypherParserState} parser_state
|
|
18
|
+
* @param {string} symbol
|
|
19
|
+
* @returns {CypherToken}
|
|
20
|
+
*/
|
|
21
|
+
export function expectSymbol(parser_state: CypherParserState, symbol: string): CypherToken;
|
|
22
|
+
/**
|
|
23
|
+
* @param {CypherParserState} parser_state
|
|
24
|
+
* @param {string} keyword
|
|
25
|
+
* @returns {boolean}
|
|
26
|
+
*/
|
|
27
|
+
export function consumeKeyword(parser_state: CypherParserState, keyword: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @param {CypherParserState} parser_state
|
|
30
|
+
* @param {string} symbol
|
|
31
|
+
* @returns {boolean}
|
|
32
|
+
*/
|
|
33
|
+
export function consumeSymbol(parser_state: CypherParserState, symbol: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @param {CypherParserState} parser_state
|
|
36
|
+
* @param {string} keyword
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
export function peekKeyword(parser_state: CypherParserState, keyword: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* @param {CypherParserState} parser_state
|
|
42
|
+
* @param {number} offset
|
|
43
|
+
* @param {string} symbol
|
|
44
|
+
* @returns {boolean}
|
|
45
|
+
*/
|
|
46
|
+
export function peekSymbolAt(parser_state: CypherParserState, offset: number, symbol: string): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* @param {CypherParserState} parser_state
|
|
49
|
+
* @returns {CypherToken | undefined}
|
|
50
|
+
*/
|
|
51
|
+
export function consumeToken(parser_state: CypherParserState): CypherToken | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* @param {CypherParserState} parser_state
|
|
54
|
+
* @returns {CypherToken | undefined}
|
|
55
|
+
*/
|
|
56
|
+
export function peekToken(parser_state: CypherParserState): CypherToken | undefined;
|
|
57
|
+
import type { CypherParserState } from './cypher.types.d.ts';
|
|
58
|
+
import type * as $k$$k$$l$$k$$k$$l$config$l$load$j$patram$j$config$k$types$k$ts from '../../config/load-patram-config.types.d.ts';
|
|
59
|
+
import type { CypherToken } from './cypher.types.d.ts';
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/** @import * as $k$$k$$l$$k$$k$$l$config$l$load$j$patram$j$config$k$types$k$ts from '../../config/load-patram-config.types.ts'; */
|
|
2
|
+
/**
|
|
3
|
+
* @import { CypherParserState, CypherToken } from './cypher.types.ts';
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { fail } from './cypher-support.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {CypherParserState} parser_state
|
|
10
|
+
* @param {string} message
|
|
11
|
+
* @returns {{diagnostic: $k$$k$$l$$k$$k$$l$config$l$load$j$patram$j$config$k$types$k$ts.PatramDiagnostic, success: false}}
|
|
12
|
+
*/
|
|
13
|
+
export function failAtCurrent(parser_state, message) {
|
|
14
|
+
const token = peekToken(parser_state);
|
|
15
|
+
|
|
16
|
+
return fail(
|
|
17
|
+
token ? token.column : parser_state.query_text.length + 1,
|
|
18
|
+
message,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {CypherParserState} parser_state
|
|
24
|
+
* @param {string} keyword
|
|
25
|
+
* @returns {CypherToken}
|
|
26
|
+
*/
|
|
27
|
+
export function expectKeyword(parser_state, keyword) {
|
|
28
|
+
const token = consumeToken(parser_state);
|
|
29
|
+
|
|
30
|
+
if (!isKeywordToken(token, keyword)) {
|
|
31
|
+
throw new Error(`Expected the ${keyword} keyword.`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return /** @type {CypherToken} */ (token);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {CypherParserState} parser_state
|
|
39
|
+
* @param {string} symbol
|
|
40
|
+
* @returns {CypherToken}
|
|
41
|
+
*/
|
|
42
|
+
export function expectSymbol(parser_state, symbol) {
|
|
43
|
+
const token = consumeToken(parser_state);
|
|
44
|
+
|
|
45
|
+
if (!isSymbolToken(token, symbol)) {
|
|
46
|
+
throw new Error(`Expected the "${symbol}" token.`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return /** @type {CypherToken} */ (token);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {CypherParserState} parser_state
|
|
54
|
+
* @param {string} keyword
|
|
55
|
+
* @returns {boolean}
|
|
56
|
+
*/
|
|
57
|
+
export function consumeKeyword(parser_state, keyword) {
|
|
58
|
+
const token = peekToken(parser_state);
|
|
59
|
+
|
|
60
|
+
if (!isKeywordToken(token, keyword)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
parser_state.index += 1;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {CypherParserState} parser_state
|
|
70
|
+
* @param {string} symbol
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
export function consumeSymbol(parser_state, symbol) {
|
|
74
|
+
const token = peekToken(parser_state);
|
|
75
|
+
|
|
76
|
+
if (!isSymbolToken(token, symbol)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
parser_state.index += 1;
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {CypherParserState} parser_state
|
|
86
|
+
* @param {string} keyword
|
|
87
|
+
* @returns {boolean}
|
|
88
|
+
*/
|
|
89
|
+
export function peekKeyword(parser_state, keyword) {
|
|
90
|
+
return isKeywordToken(peekToken(parser_state), keyword);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {CypherParserState} parser_state
|
|
95
|
+
* @param {number} offset
|
|
96
|
+
* @param {string} symbol
|
|
97
|
+
* @returns {boolean}
|
|
98
|
+
*/
|
|
99
|
+
export function peekSymbolAt(parser_state, offset, symbol) {
|
|
100
|
+
return isSymbolToken(
|
|
101
|
+
parser_state.tokens[parser_state.index + offset],
|
|
102
|
+
symbol,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {CypherParserState} parser_state
|
|
108
|
+
* @returns {CypherToken | undefined}
|
|
109
|
+
*/
|
|
110
|
+
export function consumeToken(parser_state) {
|
|
111
|
+
const token = parser_state.tokens[parser_state.index];
|
|
112
|
+
|
|
113
|
+
if (token === undefined) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
parser_state.index += 1;
|
|
118
|
+
return token;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {CypherParserState} parser_state
|
|
123
|
+
* @returns {CypherToken | undefined}
|
|
124
|
+
*/
|
|
125
|
+
export function peekToken(parser_state) {
|
|
126
|
+
return parser_state.tokens[parser_state.index];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {CypherToken | undefined} token
|
|
131
|
+
* @param {string} keyword
|
|
132
|
+
* @returns {boolean}
|
|
133
|
+
*/
|
|
134
|
+
function isKeywordToken(token, keyword) {
|
|
135
|
+
return (
|
|
136
|
+
token !== undefined &&
|
|
137
|
+
token.kind === 'identifier' &&
|
|
138
|
+
token.value.toUpperCase() === keyword
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {CypherToken | undefined} token
|
|
144
|
+
* @param {string} symbol
|
|
145
|
+
* @returns {boolean}
|
|
146
|
+
*/
|
|
147
|
+
function isSymbolToken(token, symbol) {
|
|
148
|
+
return (
|
|
149
|
+
token !== undefined && token.kind === 'symbol' && token.value === symbol
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { PatramDiagnostic, PatramRepoConfig } from '../../config/load-patram-config.types.d.ts';
|
|
3
|
+
* @import {
|
|
4
|
+
* ParsedAggregateComparison,
|
|
5
|
+
* ParsedExpression,
|
|
6
|
+
* ParsedFieldTerm,
|
|
7
|
+
* ParsedTerm,
|
|
8
|
+
* } from '../parse-where-clause.types.d.ts';
|
|
9
|
+
* @import { CypherNodePattern } from './cypher.types.d.ts';
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @param {number} column
|
|
13
|
+
* @param {string} message
|
|
14
|
+
* @returns {{ diagnostic: PatramDiagnostic, success: false }}
|
|
15
|
+
*/
|
|
16
|
+
export function fail(column: number, message: string): {
|
|
17
|
+
diagnostic: PatramDiagnostic;
|
|
18
|
+
success: false;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @param {string} relation_type
|
|
22
|
+
* @returns {string}
|
|
23
|
+
*/
|
|
24
|
+
export function relationTypeToRelationName(relation_type: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} value
|
|
27
|
+
* @returns {value is ParsedAggregateComparison}
|
|
28
|
+
*/
|
|
29
|
+
export function isAggregateComparison(value: string): value is ParsedAggregateComparison;
|
|
30
|
+
/**
|
|
31
|
+
* @param {CypherNodePattern} node_pattern
|
|
32
|
+
* @param {PatramRepoConfig | null} repo_config
|
|
33
|
+
* @returns {ParsedExpression | null}
|
|
34
|
+
*/
|
|
35
|
+
export function createNodeLabelExpression(node_pattern: CypherNodePattern, repo_config: PatramRepoConfig | null): ParsedExpression | null;
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} field_name
|
|
38
|
+
* @param {ParsedFieldTerm['operator']} operator
|
|
39
|
+
* @param {string} value
|
|
40
|
+
* @param {number} column
|
|
41
|
+
* @returns {{ success: true, expression: ParsedExpression }}
|
|
42
|
+
*/
|
|
43
|
+
export function createFieldExpression(field_name: string, operator: ParsedFieldTerm["operator"], value: string, column: number): {
|
|
44
|
+
success: true;
|
|
45
|
+
expression: ParsedExpression;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* @param {string} field_name
|
|
49
|
+
* @param {'in' | 'not in'} operator
|
|
50
|
+
* @param {string[]} values
|
|
51
|
+
* @param {number} column
|
|
52
|
+
* @returns {{ success: true, expression: ParsedExpression }}
|
|
53
|
+
*/
|
|
54
|
+
export function createFieldSetExpression(field_name: string, operator: "in" | "not in", values: string[], column: number): {
|
|
55
|
+
success: true;
|
|
56
|
+
expression: ParsedExpression;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @param {number} column
|
|
60
|
+
* @returns {ParsedExpression}
|
|
61
|
+
*/
|
|
62
|
+
export function createAlwaysTrueExpression(column: number): ParsedExpression;
|
|
63
|
+
/**
|
|
64
|
+
* @param {ParsedExpression[]} expressions
|
|
65
|
+
* @returns {ParsedExpression}
|
|
66
|
+
*/
|
|
67
|
+
export function collapseAndExpressions(expressions: ParsedExpression[]): ParsedExpression;
|
|
68
|
+
/**
|
|
69
|
+
* @param {'and' | 'or'} kind
|
|
70
|
+
* @param {ParsedExpression[]} expressions
|
|
71
|
+
* @returns {ParsedExpression}
|
|
72
|
+
*/
|
|
73
|
+
export function collapseBooleanExpression(kind: "and" | "or", expressions: ParsedExpression[]): ParsedExpression;
|
|
74
|
+
import type { PatramDiagnostic } from '../../config/load-patram-config.types.d.ts';
|
|
75
|
+
import type { ParsedAggregateComparison } from '../parse-where-clause.types.d.ts';
|
|
76
|
+
import type { CypherNodePattern } from './cypher.types.d.ts';
|
|
77
|
+
import type { PatramRepoConfig } from '../../config/load-patram-config.types.d.ts';
|
|
78
|
+
import type { ParsedExpression } from '../parse-where-clause.types.d.ts';
|
|
79
|
+
import type { ParsedFieldTerm } from '../parse-where-clause.types.d.ts';
|