@tellaro/tql 3.0.2 → 3.1.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/dist/index.js +55 -50
- package/dist/src/index.d.ts +1 -0
- package/dist/src/queryPlan.d.ts +88 -0
- package/dist/src/queryPlan.js +34 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,78 +1,83 @@
|
|
|
1
|
-
import { AGGREGATION_FUNCTIONS as r, BOOLEAN_PREDICATE_MUTATORS as i, BOOLEAN_PREDICATE_MUTATOR_SET as o, COLLECTION_OPERATORS as T, COMPARISON_OPERATORS as a, KEYWORDS as E, LOGICAL_OPERATORS as
|
|
2
|
-
import { TqlParser as
|
|
3
|
-
import { CASE_SENSITIVE_MEMBERSHIP_OPERATORS as x, CASE_SENSITIVE_OPERATORS as y, CASE_SENSITIVE_WHOLE_VALUE_OPERATORS as
|
|
4
|
-
import { getCompletionTriggerCharacters as
|
|
5
|
-
import { findClosestMatch as
|
|
1
|
+
import { AGGREGATION_FUNCTIONS as r, BOOLEAN_PREDICATE_MUTATORS as i, BOOLEAN_PREDICATE_MUTATOR_SET as o, COLLECTION_OPERATORS as T, COMPARISON_OPERATORS as a, KEYWORDS as E, LOGICAL_OPERATORS as S, MUTATORS as l, NEGATION_SYMBOL_OPERATORS as O, SYMBOL_OPERATORS as n, TYPE_HINTS as A, TqlTokenizer as s, VISUALIZATION_TYPES as g, findPreviousToken as R, findTokenAtPosition as _, findTokenBefore as m, findTokensInRange as P, tokenizeTql as c, tokenizeTqlNoWhitespace as p } from "./src/tokenizer.js";
|
|
2
|
+
import { TqlParser as N, formatParseError as I, getTqlErrors as f, isValidTql as L, parseTql as d } from "./src/parser.js";
|
|
3
|
+
import { CASE_SENSITIVE_MEMBERSHIP_OPERATORS as x, CASE_SENSITIVE_OPERATORS as y, CASE_SENSITIVE_WHOLE_VALUE_OPERATORS as u, MAX_REGEX_PATTERN_LENGTH as M, TqlValidator as q, casePreservingForm as U, caseSensitiveSupport as z, formatValidationResult as V, getTqlIssues as Y, isValidTqlSyntax as F, validateTql as k } from "./src/validator.js";
|
|
4
|
+
import { getCompletionTriggerCharacters as G, getCompletions as B, getWordAtPosition as H, shouldTriggerCompletion as D } from "./src/completionProvider.js";
|
|
5
|
+
import { findClosestMatch as W, fuzzyFilter as X, fuzzyMatch as w, highlightMatch as K, levenshteinDistance as b } from "./src/fuzzyMatcher.js";
|
|
6
6
|
import { SchemaCache as j, createSchemaCache as J, getCachedField as $, getCachedFieldNames as ee, getCachedFieldType as te, getSchemaCache as re } from "./src/schemaCache.js";
|
|
7
|
-
import { ComplexityAnalyzer as oe, analyzeComplexity as Te, getComplexityMetrics as ae, getComplexityWarnings as Ee, isHighComplexity as
|
|
8
|
-
import { SemanticPreview as Oe, flattenLogicTree as ne, formatLogicTreeAscii as
|
|
9
|
-
import { buildStatsQuery as
|
|
7
|
+
import { ComplexityAnalyzer as oe, analyzeComplexity as Te, getComplexityMetrics as ae, getComplexityWarnings as Ee, isHighComplexity as Se } from "./src/complexityAnalyzer.js";
|
|
8
|
+
import { SemanticPreview as Oe, flattenLogicTree as ne, formatLogicTreeAscii as Ae, formatLogicTreeNode as se, generatePreview as ge, getFieldUsage as Re, getLogicTree as _e, getLogicTreeDepth as me, getOperatorSummary as Pe, getUniqueFields as ce } from "./src/semanticPreview.js";
|
|
9
|
+
import { buildStatsQuery as Ce, parseVizHintString as Ne } from "./src/builder.js";
|
|
10
|
+
import { QUERY_PLAN_EXPLAIN_KEYS as fe, QUERY_PLAN_EXPLAIN_VERSION as Le, QUERY_PLAN_RULES as de, summarizeQueryPlan as he } from "./src/queryPlan.js";
|
|
10
11
|
export {
|
|
11
12
|
r as AGGREGATION_FUNCTIONS,
|
|
12
13
|
i as BOOLEAN_PREDICATE_MUTATORS,
|
|
13
14
|
o as BOOLEAN_PREDICATE_MUTATOR_SET,
|
|
14
15
|
x as CASE_SENSITIVE_MEMBERSHIP_OPERATORS,
|
|
15
16
|
y as CASE_SENSITIVE_OPERATORS,
|
|
16
|
-
|
|
17
|
+
u as CASE_SENSITIVE_WHOLE_VALUE_OPERATORS,
|
|
17
18
|
T as COLLECTION_OPERATORS,
|
|
18
19
|
a as COMPARISON_OPERATORS,
|
|
19
20
|
oe as ComplexityAnalyzer,
|
|
20
21
|
E as KEYWORDS,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
S as LOGICAL_OPERATORS,
|
|
23
|
+
M as MAX_REGEX_PATTERN_LENGTH,
|
|
24
|
+
l as MUTATORS,
|
|
24
25
|
O as NEGATION_SYMBOL_OPERATORS,
|
|
26
|
+
fe as QUERY_PLAN_EXPLAIN_KEYS,
|
|
27
|
+
Le as QUERY_PLAN_EXPLAIN_VERSION,
|
|
28
|
+
de as QUERY_PLAN_RULES,
|
|
25
29
|
n as SYMBOL_OPERATORS,
|
|
26
30
|
j as SchemaCache,
|
|
27
31
|
Oe as SemanticPreview,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
A as TYPE_HINTS,
|
|
33
|
+
N as TqlParser,
|
|
34
|
+
s as TqlTokenizer,
|
|
35
|
+
q as TqlValidator,
|
|
36
|
+
g as VISUALIZATION_TYPES,
|
|
33
37
|
Te as analyzeComplexity,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
Ce as buildStatsQuery,
|
|
39
|
+
U as casePreservingForm,
|
|
40
|
+
z as caseSensitiveSupport,
|
|
37
41
|
J as createSchemaCache,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
W as findClosestMatch,
|
|
43
|
+
R as findPreviousToken,
|
|
44
|
+
_ as findTokenAtPosition,
|
|
45
|
+
m as findTokenBefore,
|
|
46
|
+
P as findTokensInRange,
|
|
43
47
|
ne as flattenLogicTree,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
Ae as formatLogicTreeAscii,
|
|
49
|
+
se as formatLogicTreeNode,
|
|
50
|
+
I as formatParseError,
|
|
51
|
+
V as formatValidationResult,
|
|
48
52
|
X as fuzzyFilter,
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
w as fuzzyMatch,
|
|
54
|
+
ge as generatePreview,
|
|
51
55
|
$ as getCachedField,
|
|
52
56
|
ee as getCachedFieldNames,
|
|
53
57
|
te as getCachedFieldType,
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
G as getCompletionTriggerCharacters,
|
|
59
|
+
B as getCompletions,
|
|
56
60
|
ae as getComplexityMetrics,
|
|
57
61
|
Ee as getComplexityWarnings,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
Re as getFieldUsage,
|
|
63
|
+
_e as getLogicTree,
|
|
64
|
+
me as getLogicTreeDepth,
|
|
65
|
+
Pe as getOperatorSummary,
|
|
62
66
|
re as getSchemaCache,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
f as getTqlErrors,
|
|
68
|
+
Y as getTqlIssues,
|
|
69
|
+
ce as getUniqueFields,
|
|
70
|
+
H as getWordAtPosition,
|
|
67
71
|
K as highlightMatch,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
Se as isHighComplexity,
|
|
73
|
+
L as isValidTql,
|
|
74
|
+
F as isValidTqlSyntax,
|
|
75
|
+
b as levenshteinDistance,
|
|
76
|
+
d as parseTql,
|
|
77
|
+
Ne as parseVizHintString,
|
|
78
|
+
D as shouldTriggerCompletion,
|
|
79
|
+
he as summarizeQueryPlan,
|
|
80
|
+
c as tokenizeTql,
|
|
76
81
|
p as tokenizeTqlNoWhitespace,
|
|
77
|
-
|
|
82
|
+
k as validateTql
|
|
78
83
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -17,3 +17,4 @@ export { ComplexityAnalyzer, analyzeComplexity, isHighComplexity, getComplexityW
|
|
|
17
17
|
export { SemanticPreview, generatePreview, getFieldUsage, getLogicTree, getUniqueFields, getOperatorSummary, formatLogicTreeNode, formatLogicTreeAscii, flattenLogicTree, getLogicTreeDepth } from './semanticPreview';
|
|
18
18
|
export { buildStatsQuery, parseVizHintString, type StatsQueryConfig, type AggregationConfig, type GroupByConfig, type VizHintConfig } from './builder';
|
|
19
19
|
export type { ComplexityScore, ComplexityWarning, ComplexityWarningType, ComplexityMetrics, ComplexityResult, ComplexityThresholds, MatchType, FieldUsage, LogicTreeNodeType, LogicTreeNode, PreviewResult, QueryHistoryEntry, UseQueryHistoryOptions } from './types';
|
|
20
|
+
export { QUERY_PLAN_EXPLAIN_VERSION, QUERY_PLAN_RULES, QUERY_PLAN_EXPLAIN_KEYS, summarizeQueryPlan, type QueryPlanExplain, type QueryPlanRewrite, type QueryPlanNotApplied, type QueryPlanRule, type QueryPlanMode, type QueryPlanLimit } from './queryPlan';
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OpenSearch query planner's explain document, as produced by the Rust
|
|
3
|
+
* crate (`QueryBuilder::explain`, `tql --explain-opensearch`) and the Python
|
|
4
|
+
* package (`TQL.explain_plan`, `OpenSearchBackend.explain`).
|
|
5
|
+
*
|
|
6
|
+
* This package builds no OpenSearch DSL itself; it ships the shape so UIs that
|
|
7
|
+
* render a plan (the backend returns it verbatim) are typed against the same
|
|
8
|
+
* contract the engines are tested against. The shape is versioned by
|
|
9
|
+
* `explain_version`; `tests/queryPlanParity.spec.ts` reads the engines' version
|
|
10
|
+
* constants, rule registries and the shared fixture, so this file goes red when
|
|
11
|
+
* they move. Design: `docs/developer/query-planner.md`.
|
|
12
|
+
*/
|
|
13
|
+
/** The `explain_version` this package's types describe. */
|
|
14
|
+
export declare const QUERY_PLAN_EXPLAIN_VERSION = 1;
|
|
15
|
+
/** Every rule a `rewrites` record can name, in pipeline order. */
|
|
16
|
+
export declare const QUERY_PLAN_RULES: readonly ["flatten", "double_negation", "constant_fold", "dedupe", "absorption", "factor_common", "or_wildcard_to_regexp", "or_term_to_terms"];
|
|
17
|
+
export type QueryPlanRule = (typeof QUERY_PLAN_RULES)[number];
|
|
18
|
+
export type QueryPlanMode = "off" | "logical" | "full";
|
|
19
|
+
/** The keys of an explain document, in the order the engines emit them. */
|
|
20
|
+
export declare const QUERY_PLAN_EXPLAIN_KEYS: readonly ["explain_version", "planner_version", "mode", "query", "options", "normalized", "optimized", "rewrites", "not_applied", "changed", "original_dsl", "optimized_dsl"];
|
|
21
|
+
export interface QueryPlanLimit {
|
|
22
|
+
setting: "index.max_regex_length" | "index.max_terms_count";
|
|
23
|
+
value: number;
|
|
24
|
+
}
|
|
25
|
+
/** One applied rewrite. `before`/`after` are rendered logical forms. */
|
|
26
|
+
export interface QueryPlanRewrite {
|
|
27
|
+
phase: "normalize" | "logical" | "physical";
|
|
28
|
+
rule: QueryPlanRule;
|
|
29
|
+
/** Child indices from the root, joined by `.`; the root is `""`. */
|
|
30
|
+
path: string;
|
|
31
|
+
before: string;
|
|
32
|
+
after: string;
|
|
33
|
+
/** Rule-specific facts: merged clauses, chunk count and the limit behind it, skipped members. */
|
|
34
|
+
detail?: {
|
|
35
|
+
context?: "should" | "must_not";
|
|
36
|
+
field?: string;
|
|
37
|
+
shape?: "contains" | "endswith" | "equals" | "startswith";
|
|
38
|
+
case_insensitive?: boolean;
|
|
39
|
+
members?: number;
|
|
40
|
+
literals?: number;
|
|
41
|
+
values?: number;
|
|
42
|
+
chunks?: number;
|
|
43
|
+
limit?: QueryPlanLimit;
|
|
44
|
+
chunk_lengths?: Array<number | null>;
|
|
45
|
+
skipped?: Array<{
|
|
46
|
+
member: string;
|
|
47
|
+
reason: string;
|
|
48
|
+
}>;
|
|
49
|
+
clauses?: Array<Record<string, unknown>>;
|
|
50
|
+
removed?: string[];
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** A merge the planner considered and left alone, and why. */
|
|
55
|
+
export interface QueryPlanNotApplied {
|
|
56
|
+
rule: QueryPlanRule;
|
|
57
|
+
path: string;
|
|
58
|
+
context: "should" | "must_not";
|
|
59
|
+
field: string;
|
|
60
|
+
members: number;
|
|
61
|
+
reason: string;
|
|
62
|
+
shape?: string;
|
|
63
|
+
case_insensitive?: boolean;
|
|
64
|
+
skipped?: Array<{
|
|
65
|
+
member: string;
|
|
66
|
+
reason: string;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
export interface QueryPlanExplain {
|
|
70
|
+
explain_version: number;
|
|
71
|
+
planner_version: number;
|
|
72
|
+
mode: QueryPlanMode;
|
|
73
|
+
query: string | null;
|
|
74
|
+
options: {
|
|
75
|
+
max_regex_length: number;
|
|
76
|
+
max_terms_count: number;
|
|
77
|
+
};
|
|
78
|
+
normalized: string;
|
|
79
|
+
optimized: string;
|
|
80
|
+
rewrites: QueryPlanRewrite[];
|
|
81
|
+
not_applied: QueryPlanNotApplied[];
|
|
82
|
+
/** False exactly when `rewrites` is empty and `optimized_dsl` is the original. */
|
|
83
|
+
changed: boolean;
|
|
84
|
+
original_dsl: Record<string, unknown>;
|
|
85
|
+
optimized_dsl: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
/** One line per rewrite, for a compact summary: `rule @ path: before -> after`. */
|
|
88
|
+
export declare function summarizeQueryPlan(plan: QueryPlanExplain): string[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const o = 1, n = [
|
|
2
|
+
"flatten",
|
|
3
|
+
"double_negation",
|
|
4
|
+
"constant_fold",
|
|
5
|
+
"dedupe",
|
|
6
|
+
"absorption",
|
|
7
|
+
"factor_common",
|
|
8
|
+
"or_wildcard_to_regexp",
|
|
9
|
+
"or_term_to_terms"
|
|
10
|
+
], r = [
|
|
11
|
+
"explain_version",
|
|
12
|
+
"planner_version",
|
|
13
|
+
"mode",
|
|
14
|
+
"query",
|
|
15
|
+
"options",
|
|
16
|
+
"normalized",
|
|
17
|
+
"optimized",
|
|
18
|
+
"rewrites",
|
|
19
|
+
"not_applied",
|
|
20
|
+
"changed",
|
|
21
|
+
"original_dsl",
|
|
22
|
+
"optimized_dsl"
|
|
23
|
+
];
|
|
24
|
+
function i(t) {
|
|
25
|
+
return t.changed ? t.rewrites.map(
|
|
26
|
+
(e) => `${e.rule}${e.path ? ` @ ${e.path}` : ""}: ${e.before} -> ${e.after}`
|
|
27
|
+
) : ["no rewrites: the query is sent as translated"];
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
r as QUERY_PLAN_EXPLAIN_KEYS,
|
|
31
|
+
o as QUERY_PLAN_EXPLAIN_VERSION,
|
|
32
|
+
n as QUERY_PLAN_RULES,
|
|
33
|
+
i as summarizeQueryPlan
|
|
34
|
+
};
|