@eagleoutice/flowr 2.1.11 → 2.1.12

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 (62) hide show
  1. package/README.md +1 -0
  2. package/cli/repl/commands/repl-query.js +1 -1
  3. package/cli/repl/server/connection.js +1 -1
  4. package/core/steps/pipeline/default-pipelines.d.ts +6 -0
  5. package/core/steps/pipeline/default-pipelines.js +6 -0
  6. package/dataflow/graph/vertex.d.ts +4 -0
  7. package/dataflow/graph/vertex.js +3 -1
  8. package/documentation/doc-util/doc-dfg.js +1 -1
  9. package/documentation/doc-util/doc-query.js +1 -1
  10. package/documentation/doc-util/doc-search.d.ts +25 -0
  11. package/documentation/doc-util/doc-search.js +121 -0
  12. package/documentation/doc-util/doc-types.d.ts +10 -2
  13. package/documentation/doc-util/doc-types.js +81 -3
  14. package/documentation/print-dataflow-graph-wiki.js +1 -1
  15. package/documentation/print-interface-wiki.js +24 -13
  16. package/documentation/print-normalized-ast-wiki.js +4 -4
  17. package/documentation/print-query-wiki.js +22 -0
  18. package/documentation/print-search-wiki.d.ts +1 -0
  19. package/documentation/print-search-wiki.js +74 -0
  20. package/package.json +2 -1
  21. package/queries/base-query-format.d.ts +2 -2
  22. package/queries/catalog/call-context-query/call-context-query-executor.d.ts +1 -1
  23. package/queries/catalog/call-context-query/call-context-query-executor.js +1 -1
  24. package/queries/catalog/cluster-query/cluster-query-executor.d.ts +1 -1
  25. package/queries/catalog/cluster-query/cluster-query-executor.js +1 -1
  26. package/queries/catalog/dataflow-query/dataflow-query-executor.d.ts +1 -1
  27. package/queries/catalog/dataflow-query/dataflow-query-executor.js +1 -1
  28. package/queries/catalog/dependencies-query/dependencies-query-executor.js +2 -2
  29. package/queries/catalog/lineage-query/lineage-query-executor.d.ts +1 -1
  30. package/queries/catalog/lineage-query/lineage-query-executor.js +1 -1
  31. package/queries/catalog/search-query/search-query-executor.d.ts +3 -0
  32. package/queries/catalog/search-query/search-query-executor.js +27 -0
  33. package/queries/catalog/search-query/search-query-format.d.ts +72 -0
  34. package/queries/catalog/search-query/search-query-format.js +29 -0
  35. package/queries/catalog/static-slice-query/static-slice-query-executor.d.ts +1 -1
  36. package/queries/catalog/static-slice-query/static-slice-query-executor.js +1 -1
  37. package/queries/query.d.ts +59 -1
  38. package/queries/query.js +3 -1
  39. package/r-bridge/lang-4.x/ast/model/type.d.ts +4 -0
  40. package/r-bridge/lang-4.x/ast/model/type.js +3 -1
  41. package/search/flowr-search-builder.d.ts +193 -0
  42. package/search/flowr-search-builder.js +192 -0
  43. package/search/flowr-search-executor.d.ts +9 -0
  44. package/search/flowr-search-executor.js +16 -0
  45. package/search/flowr-search-filters.d.ts +74 -0
  46. package/search/flowr-search-filters.js +136 -0
  47. package/search/flowr-search-printer.d.ts +10 -0
  48. package/search/flowr-search-printer.js +85 -0
  49. package/search/flowr-search-traverse.d.ts +7 -0
  50. package/search/flowr-search-traverse.js +12 -0
  51. package/search/flowr-search.d.ts +58 -0
  52. package/search/flowr-search.js +29 -0
  53. package/search/search-executor/search-generators.d.ts +37 -0
  54. package/search/search-executor/search-generators.js +64 -0
  55. package/search/search-executor/search-transformer.d.ts +57 -0
  56. package/search/search-executor/search-transformer.js +99 -0
  57. package/search/search-optimizer/search-optimizer.d.ts +9 -0
  58. package/search/search-optimizer/search-optimizer.js +89 -0
  59. package/util/arrays.d.ts +13 -0
  60. package/util/assert.d.ts +1 -1
  61. package/util/mermaid/mermaid.js +17 -0
  62. package/util/version.js +1 -1
@@ -0,0 +1,193 @@
1
+ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
2
+ import type { FlowrSearchElement, FlowrSearchElements, FlowrSearchGetFilter } from './flowr-search';
3
+ import type { FlowrFilterExpression } from './flowr-search-filters';
4
+ import type { FlowrSearchGeneratorNode, GeneratorNames } from './search-executor/search-generators';
5
+ import type { FlowrSearchTransformerNode, GetOutputOfTransformer, TransformerNames } from './search-executor/search-transformer';
6
+ import type { SlicingCriteria } from '../slicing/criterion/parse';
7
+ import type { ParentInformation } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
8
+ type FlowrCriteriaReturn<C extends SlicingCriteria> = FlowrSearchElements<ParentInformation, C extends [] ? never : C extends [infer _] ? [
9
+ FlowrSearchElement<ParentInformation>
10
+ ] : FlowrSearchElement<ParentInformation>[]>;
11
+ /**
12
+ * This object holds all the methods to generate search queries.
13
+ * For compatibility, please use the {@link Q} identifier object to access these methods.
14
+ */
15
+ export declare const FlowrSearchGenerator: {
16
+ /**
17
+ * Initialize a search query with the given elements.
18
+ * <b>This is not intended to serialize well</b> wrt. the nodes,
19
+ * see {@link FlowrSearchGenerator.criterion} for a serializable alternative (passing the ids with `$id`).
20
+ */
21
+ readonly from: (from: FlowrSearchElement<ParentInformation> | FlowrSearchElement<ParentInformation>[]) => FlowrSearchBuilder<"from">;
22
+ /**
23
+ * Returns all elements (nodes/dataflow vertices) from the given data.
24
+ */
25
+ readonly all: () => FlowrSearchBuilder<"all">;
26
+ /**
27
+ * Returns all elements that match the given {@link FlowrSearchGetFilters|filters}.
28
+ * You may pass a negative line number to count from the back.
29
+ * Please note that this is currently only working for single files, it approximates over the nodes, and it is not to be used for "production".
30
+ */
31
+ readonly get: (filter: FlowrSearchGetFilter) => FlowrSearchBuilder<"get">;
32
+ /**
33
+ * Returns all elements that match the given {@link SlicingCriteria|criteria}
34
+ * (e.g., `criterion('2@x', '3@<-')`,
35
+ * to retrieve the first use of `x` in the second line and the first `<-` assignment in the third line).
36
+ * This will throw an error, if any criteria cannot be resolved to an id.
37
+ */
38
+ readonly criterion: <Criteria extends SlicingCriteria>(...criterion: Criteria) => FlowrSearchBuilder<"criterion", [], ParentInformation, FlowrCriteriaReturn<Criteria>>;
39
+ /**
40
+ * Short form of {@link get} with only the
41
+ * {@link FlowrSearchGetFilters#line|line} and {@link FlowrSearchGetFilters#column|column} filters:
42
+ * `get({line, column})`.
43
+ */
44
+ readonly loc: (line?: number, column?: number) => FlowrSearchBuilder<"get">;
45
+ /**
46
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} and {@link FlowrSearchGetFilters#line|line} filters:
47
+ * `get({name, line})`.
48
+ */
49
+ readonly varInLine: (name: string, line: number) => FlowrSearchBuilder<"get">;
50
+ /**
51
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} filter:
52
+ * `get({name})`.
53
+ */
54
+ readonly var: (name: string) => FlowrSearchBuilder<"get">;
55
+ /**
56
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#id|id} filter:
57
+ * `get({id})`.
58
+ */
59
+ readonly id: (id: NodeId) => FlowrSearchBuilder<"get">;
60
+ };
61
+ /**
62
+ * This is the root object to use for creating searches.
63
+ * See the {@link FlowrSearchGenerator} for the available methods.
64
+ * After the query is generated,
65
+ * you can use what is provided by the {@link FlowrSearchBuilder} to further refine the search.
66
+ */
67
+ export declare const Q: {
68
+ /**
69
+ * Initialize a search query with the given elements.
70
+ * <b>This is not intended to serialize well</b> wrt. the nodes,
71
+ * see {@link FlowrSearchGenerator.criterion} for a serializable alternative (passing the ids with `$id`).
72
+ */
73
+ readonly from: (from: FlowrSearchElement<ParentInformation> | FlowrSearchElement<ParentInformation>[]) => FlowrSearchBuilder<"from">;
74
+ /**
75
+ * Returns all elements (nodes/dataflow vertices) from the given data.
76
+ */
77
+ readonly all: () => FlowrSearchBuilder<"all">;
78
+ /**
79
+ * Returns all elements that match the given {@link FlowrSearchGetFilters|filters}.
80
+ * You may pass a negative line number to count from the back.
81
+ * Please note that this is currently only working for single files, it approximates over the nodes, and it is not to be used for "production".
82
+ */
83
+ readonly get: (filter: FlowrSearchGetFilter) => FlowrSearchBuilder<"get">;
84
+ /**
85
+ * Returns all elements that match the given {@link SlicingCriteria|criteria}
86
+ * (e.g., `criterion('2@x', '3@<-')`,
87
+ * to retrieve the first use of `x` in the second line and the first `<-` assignment in the third line).
88
+ * This will throw an error, if any criteria cannot be resolved to an id.
89
+ */
90
+ readonly criterion: <Criteria extends SlicingCriteria>(...criterion: Criteria) => FlowrSearchBuilder<"criterion", [], ParentInformation, FlowrCriteriaReturn<Criteria>>;
91
+ /**
92
+ * Short form of {@link get} with only the
93
+ * {@link FlowrSearchGetFilters#line|line} and {@link FlowrSearchGetFilters#column|column} filters:
94
+ * `get({line, column})`.
95
+ */
96
+ readonly loc: (line?: number, column?: number) => FlowrSearchBuilder<"get">;
97
+ /**
98
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} and {@link FlowrSearchGetFilters#line|line} filters:
99
+ * `get({name, line})`.
100
+ */
101
+ readonly varInLine: (name: string, line: number) => FlowrSearchBuilder<"get">;
102
+ /**
103
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} filter:
104
+ * `get({name})`.
105
+ */
106
+ readonly var: (name: string) => FlowrSearchBuilder<"get">;
107
+ /**
108
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#id|id} filter:
109
+ * `get({id})`.
110
+ */
111
+ readonly id: (id: NodeId) => FlowrSearchBuilder<"get">;
112
+ };
113
+ export type FlowrSearchBuilderType<Generator extends GeneratorNames = GeneratorNames, Transformers extends TransformerNames[] = TransformerNames[], Info = ParentInformation, ElementType = FlowrSearchElements<Info, FlowrSearchElement<Info>[]>> = FlowrSearchBuilder<Generator, Transformers, Info, ElementType>;
114
+ type GetElements<F> = F extends FlowrSearchElements<infer Info, infer Elements> ? Elements extends FlowrSearchElement<Info>[] ? Elements : never : never;
115
+ /**
116
+ * The search query is a combination of a generator and a list of transformers
117
+ * and allows this view to pass such queries in a serialized form.
118
+ *
119
+ * @typeParam Transformers - The list of transformers that are applied to the generator's output.
120
+ */
121
+ export interface FlowrSearch<Info = ParentInformation, _Generator extends GeneratorNames = GeneratorNames, _Transformers extends readonly TransformerNames[] = readonly TransformerNames[], _ElementType = FlowrSearchElements<Info, FlowrSearchElement<Info>[]>> {
122
+ readonly generator: FlowrSearchGeneratorNode;
123
+ readonly search: readonly FlowrSearchTransformerNode[];
124
+ }
125
+ type FlowrSearchBuilderOut<Generator extends GeneratorNames, Transformers extends TransformerNames[], Info, Transformer extends TransformerNames> = FlowrSearchBuilder<Generator, [...Transformers, Transformer], Info, GetOutputOfTransformer<Transformer>>;
126
+ /**
127
+ * Allows you to construct a search query from a {@link FlowrSearchGeneratorNode}.
128
+ * Please use the {@link Q} object to create an object of this class!
129
+ * In the end, you _can_ freeze the search by calling {@link FlowrSearchBuilder#build},
130
+ * however, the search executors may do that for you.
131
+ *
132
+ * @see {@link FlowrSearchGenerator}
133
+ * @see {@link FlowrSearch}
134
+ * @see {@link FlowrSearchLike}
135
+ */
136
+ export declare class FlowrSearchBuilder<Generator extends GeneratorNames, Transformers extends TransformerNames[] = [], Info = ParentInformation, ElementType = FlowrSearchElements<Info, FlowrSearchElement<Info>[]>> {
137
+ private readonly generator;
138
+ private readonly search;
139
+ constructor(generator: FlowrSearchGeneratorNode);
140
+ /**
141
+ * only returns the elements that match the given filter.
142
+ */
143
+ filter(filter: FlowrFilterExpression): FlowrSearchBuilderOut<Generator, Transformers, Info, 'filter'>;
144
+ /**
145
+ * first either returns the first element of the search or nothing, if no elements are present.
146
+ */
147
+ first(): FlowrSearchBuilderOut<Generator, Transformers, Info, 'first'>;
148
+ /**
149
+ * last either returns the last element of the search or nothing, if no elements are present.
150
+ */
151
+ last(): FlowrSearchBuilderOut<Generator, Transformers, Info, 'last'>;
152
+ /**
153
+ * index returns the element at the given index if it exists
154
+ */
155
+ index<Idx extends number>(index: Idx): FlowrSearchBuilderOut<Generator, Transformers, Info, 'index'>;
156
+ /**
157
+ * tail returns all elements of the search except the first one.
158
+ */
159
+ tail(): FlowrSearchBuilderOut<Generator, Transformers, Info, 'tail'>;
160
+ /**
161
+ * take returns the first `count` elements of the search.
162
+ */
163
+ take<Count extends number>(count: Count): FlowrSearchBuilderOut<Generator, Transformers, Info, 'take'>;
164
+ /**
165
+ * skip returns all elements of the search except the first `count` ones.
166
+ */
167
+ skip<Count extends number>(count: Count): FlowrSearchBuilderOut<Generator, Transformers, Info, 'skip'>;
168
+ /**
169
+ * select returns only the elements at the given indices.
170
+ */
171
+ select<Select extends number[]>(...select: Select): FlowrSearchBuilderOut<Generator, Transformers, Info, 'select'>;
172
+ /**
173
+ * merge combines the search results with those of another search.
174
+ */
175
+ merge<Generator2 extends GeneratorNames, Transformers2 extends TransformerNames[], OtherElementType extends FlowrSearchElements<Info, FlowrSearchElement<Info>[]>>(other: FlowrSearchBuilder<Generator2, Transformers2, Info, OtherElementType>): FlowrSearchBuilder<Generator, Transformers, Info, FlowrSearchElements<Info, [...GetElements<ElementType>, ...GetElements<OtherElementType>]>>;
176
+ /**
177
+ * Construct the final search (this may happen automatically with most search handlers).
178
+ *
179
+ * @param shouldOptimize - This may optimize the search.
180
+ */
181
+ build(shouldOptimize?: boolean): FlowrSearch<Info, Generator, Transformers, ElementType>;
182
+ }
183
+ /**
184
+ * This type summarizes all types that can be used in places in which the API expects you to provide a search query.
185
+ * @see {@link FlowrSearch}
186
+ */
187
+ export type FlowrSearchLike = FlowrSearch | FlowrSearchBuilderType;
188
+ export type SearchOutput<Search> = Search extends FlowrSearch ? Search : Search extends FlowrSearchBuilderType<infer Generator, infer Transformers, infer Info, infer Elements> ? FlowrSearch<Info, Generator, Transformers, Elements> : never;
189
+ /**
190
+ * Freezes any accepted {@link FlowrSearchLike} into a {@link FlowrSearch}.
191
+ */
192
+ export declare function getFlowrSearch<Search extends FlowrSearchLike>(search: Search, optimizeIfBuild?: boolean): SearchOutput<Search>;
193
+ export {};
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowrSearchBuilder = exports.Q = exports.FlowrSearchGenerator = void 0;
4
+ exports.getFlowrSearch = getFlowrSearch;
5
+ const search_optimizer_1 = require("./search-optimizer/search-optimizer");
6
+ const assert_1 = require("../util/assert");
7
+ /**
8
+ * This object holds all the methods to generate search queries.
9
+ * For compatibility, please use the {@link Q} identifier object to access these methods.
10
+ */
11
+ exports.FlowrSearchGenerator = {
12
+ /**
13
+ * Initialize a search query with the given elements.
14
+ * <b>This is not intended to serialize well</b> wrt. the nodes,
15
+ * see {@link FlowrSearchGenerator.criterion} for a serializable alternative (passing the ids with `$id`).
16
+ */
17
+ from(from) {
18
+ return new FlowrSearchBuilder({ type: 'generator', name: 'from', args: { from } });
19
+ },
20
+ /**
21
+ * Returns all elements (nodes/dataflow vertices) from the given data.
22
+ */
23
+ all() {
24
+ return new FlowrSearchBuilder({ type: 'generator', name: 'all', args: undefined });
25
+ },
26
+ /**
27
+ * Returns all elements that match the given {@link FlowrSearchGetFilters|filters}.
28
+ * You may pass a negative line number to count from the back.
29
+ * Please note that this is currently only working for single files, it approximates over the nodes, and it is not to be used for "production".
30
+ */
31
+ get(filter) {
32
+ (0, assert_1.guard)(!filter.nameIsRegex || filter.name, 'If nameIsRegex is set, a name should be provided');
33
+ (0, assert_1.guard)(!filter.line || filter.line != 0, 'If line is set, it must be different from 0 as there is no 0 line');
34
+ (0, assert_1.guard)(!filter.column || filter.column > 0, 'If column is set, it must be greater than 0, but was ' + filter.column);
35
+ return new FlowrSearchBuilder({ type: 'generator', name: 'get', args: { filter } });
36
+ },
37
+ /**
38
+ * Returns all elements that match the given {@link SlicingCriteria|criteria}
39
+ * (e.g., `criterion('2@x', '3@<-')`,
40
+ * to retrieve the first use of `x` in the second line and the first `<-` assignment in the third line).
41
+ * This will throw an error, if any criteria cannot be resolved to an id.
42
+ */
43
+ criterion(...criterion) {
44
+ (0, assert_1.guard)(criterion.length > 0, 'At least one criterion must be provided');
45
+ return new FlowrSearchBuilder({ type: 'generator', name: 'criterion', args: { criterion } });
46
+ },
47
+ /**
48
+ * Short form of {@link get} with only the
49
+ * {@link FlowrSearchGetFilters#line|line} and {@link FlowrSearchGetFilters#column|column} filters:
50
+ * `get({line, column})`.
51
+ */
52
+ loc(line, column) {
53
+ return exports.FlowrSearchGenerator.get({ line, column });
54
+ },
55
+ /**
56
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} and {@link FlowrSearchGetFilters#line|line} filters:
57
+ * `get({name, line})`.
58
+ */
59
+ varInLine(name, line) {
60
+ return exports.FlowrSearchGenerator.get({ name, line });
61
+ },
62
+ /**
63
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#name|name} filter:
64
+ * `get({name})`.
65
+ */
66
+ var(name) {
67
+ return exports.FlowrSearchGenerator.get({ name });
68
+ },
69
+ /**
70
+ * Short form of {@link get} with only the {@link FlowrSearchGetFilters#id|id} filter:
71
+ * `get({id})`.
72
+ */
73
+ id(id) {
74
+ return exports.FlowrSearchGenerator.get({ id });
75
+ }
76
+ };
77
+ /**
78
+ * This is the root object to use for creating searches.
79
+ * See the {@link FlowrSearchGenerator} for the available methods.
80
+ * After the query is generated,
81
+ * you can use what is provided by the {@link FlowrSearchBuilder} to further refine the search.
82
+ */
83
+ exports.Q = exports.FlowrSearchGenerator;
84
+ /**
85
+ * Allows you to construct a search query from a {@link FlowrSearchGeneratorNode}.
86
+ * Please use the {@link Q} object to create an object of this class!
87
+ * In the end, you _can_ freeze the search by calling {@link FlowrSearchBuilder#build},
88
+ * however, the search executors may do that for you.
89
+ *
90
+ * @see {@link FlowrSearchGenerator}
91
+ * @see {@link FlowrSearch}
92
+ * @see {@link FlowrSearchLike}
93
+ */
94
+ class FlowrSearchBuilder {
95
+ generator;
96
+ search = [];
97
+ constructor(generator) {
98
+ this.generator = generator;
99
+ }
100
+ /**
101
+ * only returns the elements that match the given filter.
102
+ */
103
+ filter(filter) {
104
+ this.search.push({ type: 'transformer', name: 'filter', args: { filter: filter } });
105
+ return this;
106
+ }
107
+ /**
108
+ * first either returns the first element of the search or nothing, if no elements are present.
109
+ */
110
+ first() {
111
+ this.search.push({ type: 'transformer', name: 'first', args: undefined });
112
+ return this;
113
+ }
114
+ /**
115
+ * last either returns the last element of the search or nothing, if no elements are present.
116
+ */
117
+ last() {
118
+ this.search.push({ type: 'transformer', name: 'last', args: undefined });
119
+ return this;
120
+ }
121
+ /**
122
+ * index returns the element at the given index if it exists
123
+ */
124
+ index(index) {
125
+ (0, assert_1.guard)(index >= 0, 'Index must be greater or equal to 0, but was ' + index);
126
+ this.search.push({ type: 'transformer', name: 'index', args: { index } });
127
+ return this;
128
+ }
129
+ /**
130
+ * tail returns all elements of the search except the first one.
131
+ */
132
+ tail() {
133
+ this.search.push({ type: 'transformer', name: 'tail', args: undefined });
134
+ return this;
135
+ }
136
+ /**
137
+ * take returns the first `count` elements of the search.
138
+ */
139
+ take(count) {
140
+ (0, assert_1.guard)(count >= 0, 'Count must be greater or equal to 0, but was ' + count);
141
+ this.search.push({ type: 'transformer', name: 'take', args: { count } });
142
+ return this;
143
+ }
144
+ /**
145
+ * skip returns all elements of the search except the first `count` ones.
146
+ */
147
+ skip(count) {
148
+ (0, assert_1.guard)(count >= 0, 'Count must be greater or equal to 0, but was ' + count);
149
+ this.search.push({ type: 'transformer', name: 'skip', args: { count } });
150
+ return this;
151
+ }
152
+ /**
153
+ * select returns only the elements at the given indices.
154
+ */
155
+ select(...select) {
156
+ (0, assert_1.guard)(select.length > 0, 'At least one index must be provided');
157
+ (0, assert_1.guard)(select.every(i => i >= 0), () => 'All indices must be greater or equal to 0, but were ' + JSON.stringify(select));
158
+ this.search.push({ type: 'transformer', name: 'select', args: { select } });
159
+ return this;
160
+ }
161
+ /**
162
+ * merge combines the search results with those of another search.
163
+ */
164
+ merge(other /* | FlowrSearch<Info, Generator2, Transformers2, OtherElementType> */
165
+ // @ts-expect-error -- this works when merging, there is no info disparity
166
+ ) {
167
+ this.search.push({ type: 'transformer', name: 'merge', args: { generator: other.generator, search: other.search } });
168
+ return this;
169
+ }
170
+ /**
171
+ * Construct the final search (this may happen automatically with most search handlers).
172
+ *
173
+ * @param shouldOptimize - This may optimize the search.
174
+ */
175
+ build(shouldOptimize = true) {
176
+ return shouldOptimize ? (0, search_optimizer_1.optimize)(this.generator, this.search) : {
177
+ generator: this.generator,
178
+ search: this.search
179
+ };
180
+ }
181
+ }
182
+ exports.FlowrSearchBuilder = FlowrSearchBuilder;
183
+ /**
184
+ * Freezes any accepted {@link FlowrSearchLike} into a {@link FlowrSearch}.
185
+ */
186
+ function getFlowrSearch(search, optimizeIfBuild = true) {
187
+ if (search instanceof FlowrSearchBuilder) {
188
+ return search.build(optimizeIfBuild);
189
+ }
190
+ return search;
191
+ }
192
+ //# sourceMappingURL=flowr-search-builder.js.map
@@ -0,0 +1,9 @@
1
+ import type { FlowrSearch, FlowrSearchLike, SearchOutput } from './flowr-search-builder';
2
+ import type { FlowrSearchElements, FlowrSearchInput } from './flowr-search';
3
+ import type { Pipeline } from '../core/steps/pipeline/pipeline';
4
+ type GetSearchElements<S> = S extends FlowrSearch<infer _, infer _, infer _, infer Elements> ? Elements extends FlowrSearchElements<infer _, infer E> ? E : never : never;
5
+ /**
6
+ * Run a search with the given search query and data.
7
+ */
8
+ export declare function runSearch<S extends FlowrSearchLike, P extends Pipeline>(search: S, data: FlowrSearchInput<P>): GetSearchElements<SearchOutput<S>>;
9
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runSearch = runSearch;
4
+ const flowr_search_builder_1 = require("./flowr-search-builder");
5
+ const search_generators_1 = require("./search-executor/search-generators");
6
+ const search_transformer_1 = require("./search-executor/search-transformer");
7
+ /**
8
+ * Run a search with the given search query and data.
9
+ */
10
+ function runSearch(search, data) {
11
+ const s = (0, flowr_search_builder_1.getFlowrSearch)(search);
12
+ return s.search.reduce((acc, transformer) => (0, search_transformer_1.getTransformer)(transformer.name)(data, acc, transformer.args),
13
+ /* support multiple arguments may be abstracted away in search frontend */
14
+ (0, search_generators_1.getGenerator)(s.generator.name)(data, s.generator.args)).getElements();
15
+ }
16
+ //# sourceMappingURL=flowr-search-executor.js.map
@@ -0,0 +1,74 @@
1
+ import { RType } from '../r-bridge/lang-4.x/ast/model/type';
2
+ import type { VertexType } from '../dataflow/graph/vertex';
3
+ import type { NormalizedAst, ParentInformation } from '../r-bridge/lang-4.x/ast/model/processing/decorate';
4
+ import type { DataflowInformation } from '../dataflow/info';
5
+ import type { RNode } from '../r-bridge/lang-4.x/ast/model/model';
6
+ export type FlowrFilterName = keyof typeof FlowrFilters;
7
+ export declare enum FlowrFilter {
8
+ DropEmptyArguments = "drop-empty-arguments"
9
+ }
10
+ export declare const ValidFlowrFilters: Set<string>;
11
+ export declare const ValidFlowrFiltersReverse: {
12
+ [k: string]: string;
13
+ };
14
+ export declare const FlowrFilters: {
15
+ readonly "drop-empty-arguments": (n: RNode<ParentInformation>) => boolean;
16
+ };
17
+ type ValidFilterTypes = FlowrFilterName | RType | VertexType;
18
+ /**
19
+ * By default, we provide filter for every {@link RType} and {@link VertexType}.
20
+ */
21
+ export type FlowrFilterExpression = FlowrFilterCombinator | ValidFilterTypes;
22
+ interface BooleanBinaryNode<Composite> {
23
+ readonly type: 'and' | 'or' | 'xor';
24
+ readonly left: Composite;
25
+ readonly right: Composite;
26
+ }
27
+ interface BooleanUnaryNode<Composite> {
28
+ readonly type: 'not';
29
+ readonly operand: Composite;
30
+ }
31
+ type LeafRType = {
32
+ readonly type: 'r-type';
33
+ readonly value: RType;
34
+ };
35
+ type LeafVertexType = {
36
+ readonly type: 'vertex-type';
37
+ readonly value: VertexType;
38
+ };
39
+ type LeafSpecial = {
40
+ readonly type: 'special';
41
+ readonly value: string;
42
+ };
43
+ type Leaf = LeafRType | LeafVertexType | LeafSpecial;
44
+ type BooleanNode = BooleanBinaryNode<BooleanNode> | BooleanUnaryNode<BooleanNode> | Leaf;
45
+ type BooleanNodeOrCombinator = BooleanNode | FlowrFilterCombinator;
46
+ /**
47
+ * @see {@link FlowrFilterCombinator.is}
48
+ * @see {@link evalFilter}
49
+ * @see {@link binaryTreeToString}
50
+ */
51
+ export declare class FlowrFilterCombinator {
52
+ private tree;
53
+ protected constructor(init: BooleanNodeOrCombinator);
54
+ static is(value: BooleanNodeOrCombinator | ValidFilterTypes): FlowrFilterCombinator;
55
+ and(right: BooleanNodeOrCombinator | ValidFilterTypes): this;
56
+ or(right: BooleanNodeOrCombinator | ValidFilterTypes): this;
57
+ xor(right: BooleanNodeOrCombinator | ValidFilterTypes): this;
58
+ private binaryRight;
59
+ not(): this;
60
+ private unary;
61
+ private unpack;
62
+ get(): BooleanNode;
63
+ }
64
+ export declare function binaryTreeToString(tree: BooleanNode): string;
65
+ export declare function isBinaryTree(tree: unknown): tree is {
66
+ tree: BooleanNode;
67
+ };
68
+ interface FilterData {
69
+ readonly node: RNode<ParentInformation>;
70
+ readonly normalize: NormalizedAst;
71
+ readonly dataflow: DataflowInformation;
72
+ }
73
+ export declare function evalFilter(filter: FlowrFilterExpression, data: FilterData): boolean;
74
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowrFilterCombinator = exports.FlowrFilters = exports.ValidFlowrFiltersReverse = exports.ValidFlowrFilters = exports.FlowrFilter = void 0;
4
+ exports.binaryTreeToString = binaryTreeToString;
5
+ exports.isBinaryTree = isBinaryTree;
6
+ exports.evalFilter = evalFilter;
7
+ const type_1 = require("../r-bridge/lang-4.x/ast/model/type");
8
+ const vertex_1 = require("../dataflow/graph/vertex");
9
+ var FlowrFilter;
10
+ (function (FlowrFilter) {
11
+ FlowrFilter["DropEmptyArguments"] = "drop-empty-arguments";
12
+ })(FlowrFilter || (exports.FlowrFilter = FlowrFilter = {}));
13
+ exports.ValidFlowrFilters = new Set(Object.values(FlowrFilter));
14
+ exports.ValidFlowrFiltersReverse = Object.fromEntries(Object.entries(FlowrFilter).map(([k, v]) => [v, k]));
15
+ exports.FlowrFilters = {
16
+ [FlowrFilter.DropEmptyArguments]: (n) => {
17
+ return n.type !== type_1.RType.Argument || n.name !== undefined;
18
+ }
19
+ };
20
+ /**
21
+ * @see {@link FlowrFilterCombinator.is}
22
+ * @see {@link evalFilter}
23
+ * @see {@link binaryTreeToString}
24
+ */
25
+ class FlowrFilterCombinator {
26
+ tree;
27
+ constructor(init) {
28
+ this.tree = this.unpack(init);
29
+ }
30
+ static is(value) {
31
+ if (typeof value === 'object') {
32
+ return new this(value);
33
+ }
34
+ else if (type_1.ValidRTypes.has(value)) {
35
+ return new this({ type: 'r-type', value: value });
36
+ }
37
+ else if (vertex_1.ValidVertexTypes.has(value)) {
38
+ return new this({ type: 'vertex-type', value: value });
39
+ }
40
+ else if (exports.ValidFlowrFilters.has(value)) {
41
+ return new this({ type: 'special', value: value });
42
+ }
43
+ else {
44
+ throw new Error(`Invalid filter value: ${value}`);
45
+ }
46
+ }
47
+ and(right) {
48
+ return this.binaryRight('and', right);
49
+ }
50
+ or(right) {
51
+ return this.binaryRight('or', right);
52
+ }
53
+ xor(right) {
54
+ return this.binaryRight('xor', right);
55
+ }
56
+ binaryRight(op, right) {
57
+ this.tree = {
58
+ type: op,
59
+ left: this.tree,
60
+ right: this.unpack(FlowrFilterCombinator.is(right))
61
+ };
62
+ return this;
63
+ }
64
+ not() {
65
+ return this.unary('not');
66
+ }
67
+ unary(op) {
68
+ this.tree = {
69
+ type: op,
70
+ operand: this.tree
71
+ };
72
+ return this;
73
+ }
74
+ unpack(val) {
75
+ return val instanceof FlowrFilterCombinator ? val.tree : val;
76
+ }
77
+ get() {
78
+ return this.tree;
79
+ }
80
+ }
81
+ exports.FlowrFilterCombinator = FlowrFilterCombinator;
82
+ function binaryTreeToString(tree) {
83
+ const res = treeToStringImpl(tree, 0);
84
+ // drop outer parens
85
+ if (res.startsWith('(') && res.endsWith(')')) {
86
+ return res.slice(1, -1);
87
+ }
88
+ else {
89
+ return res;
90
+ }
91
+ }
92
+ const typeToSymbol = {
93
+ 'and': '∧',
94
+ 'or': '∨',
95
+ 'xor': '⊕',
96
+ 'not': '¬'
97
+ };
98
+ function treeToStringImpl(tree, depth) {
99
+ if (tree.type === 'r-type' || tree.type === 'vertex-type' || tree.type === 'special') {
100
+ return tree.value;
101
+ }
102
+ if (tree.type === 'not') {
103
+ return `${typeToSymbol[tree.type]}${treeToStringImpl(tree.operand, depth)}`;
104
+ }
105
+ const left = treeToStringImpl(tree.left, depth + 1);
106
+ const right = treeToStringImpl(tree.right, depth + 1);
107
+ return `(${left} ${typeToSymbol[tree.type]} ${right})`;
108
+ }
109
+ function isBinaryTree(tree) {
110
+ return typeof tree === 'object' && tree !== null && 'tree' in tree;
111
+ }
112
+ const evalVisit = {
113
+ and: ({ left, right }, data) => evalTree(left, data) && evalTree(right, data),
114
+ or: ({ left, right }, data) => evalTree(left, data) || evalTree(right, data),
115
+ xor: ({ left, right }, data) => evalTree(left, data) !== evalTree(right, data),
116
+ not: ({ operand }, data) => !evalTree(operand, data),
117
+ 'r-type': ({ value }, { node }) => node.type === value,
118
+ 'vertex-type': ({ value }, { dataflow: { graph }, node }) => graph.getVertex(node.info.id)?.tag === value,
119
+ 'special': ({ value }, { node }) => {
120
+ const getHandler = exports.FlowrFilters[value];
121
+ if (getHandler) {
122
+ return getHandler(node);
123
+ }
124
+ throw new Error(`Special filter not implemented: ${value}`);
125
+ }
126
+ };
127
+ function evalTree(tree, data) {
128
+ /* we ensure that the types fit */
129
+ return evalVisit[tree.type](tree, data);
130
+ }
131
+ function evalFilter(filter, data) {
132
+ /* common lift, this can be improved easily :D */
133
+ const tree = FlowrFilterCombinator.is(filter);
134
+ return evalTree(tree.get(), data);
135
+ }
136
+ //# sourceMappingURL=flowr-search-filters.js.map
@@ -0,0 +1,10 @@
1
+ import type { FlowrSearchLike } from './flowr-search-builder';
2
+ export interface FlowrSearchMermaidBuilderOptions {
3
+ header?: string;
4
+ }
5
+ /**
6
+ * Converts a {@link FlowrSearchLike} object to a mermaid flowchart.
7
+ */
8
+ export declare function flowrSearchToMermaid(search: FlowrSearchLike, conf?: FlowrSearchMermaidBuilderOptions): string;
9
+ export declare function flowrSearchToAscii(search: FlowrSearchLike): string;
10
+ export declare function flowrSearchToCode(search: FlowrSearchLike): string;