@elastic/monaco-esql 2.0.0 → 3.0.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/README.md +1 -1
- package/lib/definitions.d.ts +7 -1
- package/lib/definitions.js +30 -7
- package/lib/monarch.js +18 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ To highlight ES|QL code in Monaco editor, you need to register ES|QL language
|
|
|
12
12
|
and its Monarch grammar:
|
|
13
13
|
|
|
14
14
|
```js
|
|
15
|
-
import { monarchLanguage } from '@elastic/monaco-esql';
|
|
15
|
+
import { language as monarchLanguage } from '@elastic/monaco-esql/lib/monarch-shared';
|
|
16
16
|
|
|
17
17
|
monaco.languages.register({id: 'esql'});
|
|
18
18
|
monaco.languages.setMonarchTokensProvider('esql', monarchLanguage);
|
package/lib/definitions.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const sourceCommands: string[];
|
|
2
|
+
export declare const processingCommands: string[];
|
|
2
3
|
export declare const options: string[];
|
|
3
4
|
export declare const literals: string[];
|
|
4
5
|
export declare const functions: string[];
|
|
@@ -9,3 +10,8 @@ export declare const operators: {
|
|
|
9
10
|
other: string[];
|
|
10
11
|
};
|
|
11
12
|
};
|
|
13
|
+
export type TemporalUnit = [unit: string, ...abbreviations: string[]];
|
|
14
|
+
/**
|
|
15
|
+
* @see https://www.elastic.co/docs/reference/query-languages/esql/esql-time-spans#esql-time-spans-table
|
|
16
|
+
*/
|
|
17
|
+
export declare const temporalUnits: TemporalUnit[];
|
package/lib/definitions.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.operators = exports.delimiters = exports.functions = exports.literals = exports.options = exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.temporalUnits = exports.operators = exports.delimiters = exports.functions = exports.literals = exports.options = exports.processingCommands = exports.sourceCommands = void 0;
|
|
4
|
+
exports.sourceCommands = [
|
|
5
|
+
"FROM",
|
|
6
|
+
"ROW",
|
|
7
|
+
"EXPLAIN",
|
|
8
|
+
"SHOW INFO",
|
|
9
|
+
"SHOW",
|
|
10
|
+
"TS",
|
|
11
|
+
];
|
|
12
|
+
exports.processingCommands = [
|
|
13
|
+
"CHANGE_POINT",
|
|
14
|
+
"COMPLETION",
|
|
5
15
|
"DISSECT",
|
|
6
16
|
"DROP",
|
|
7
17
|
"ENRICH",
|
|
8
18
|
"EVAL",
|
|
9
|
-
"EXPLAIN",
|
|
10
19
|
"FORK",
|
|
11
|
-
"
|
|
20
|
+
"FORK",
|
|
12
21
|
"FULL JOIN",
|
|
13
22
|
"GROK",
|
|
14
23
|
"INFO",
|
|
15
24
|
"INLINESTATS",
|
|
25
|
+
"INSIST",
|
|
16
26
|
"JOIN",
|
|
17
27
|
"KEEP",
|
|
18
28
|
"LEFT JOIN",
|
|
@@ -23,11 +33,10 @@ exports.commands = [
|
|
|
23
33
|
"METRICS",
|
|
24
34
|
"MV_EXPAND",
|
|
25
35
|
"RENAME",
|
|
36
|
+
"RERANK",
|
|
26
37
|
"RIGHT JOIN",
|
|
27
38
|
"RIGHT",
|
|
28
|
-
"
|
|
29
|
-
"SHOW INFO",
|
|
30
|
-
"SHOW",
|
|
39
|
+
"RRF",
|
|
31
40
|
"SORT",
|
|
32
41
|
"STATS",
|
|
33
42
|
"WHERE",
|
|
@@ -216,3 +225,17 @@ exports.operators = {
|
|
|
216
225
|
other: ["ASC", "DESC", "FIRST", "LAST", "NULLS", "NOT"],
|
|
217
226
|
},
|
|
218
227
|
};
|
|
228
|
+
/**
|
|
229
|
+
* @see https://www.elastic.co/docs/reference/query-languages/esql/esql-time-spans#esql-time-spans-table
|
|
230
|
+
*/
|
|
231
|
+
exports.temporalUnits = [
|
|
232
|
+
["YEAR", "Y", "YR", "YEARS"],
|
|
233
|
+
["QUARTER", "Q", "QUARTERS"],
|
|
234
|
+
["MONTH", "MO", "MONTHS"],
|
|
235
|
+
["WEEK", "W", "WEEKS"],
|
|
236
|
+
["DAY", "D", "DAYS"],
|
|
237
|
+
["HOUR", "H", "HOURS"],
|
|
238
|
+
["MINUTE", "MIN", "MINUTES"],
|
|
239
|
+
["SECOND", "S", "SEC", "SECONDS"],
|
|
240
|
+
["MILLISECOND", "MS", "MILLISECONDS"],
|
|
241
|
+
];
|
package/lib/monarch.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = void 0;
|
|
4
4
|
const create = (deps = {}) => {
|
|
5
|
-
const {
|
|
5
|
+
const { sourceCommands = [], processingCommands = [], options = [], literals = [], functions = [], delimiters = [], temporalUnits = [], } = deps;
|
|
6
|
+
const timeUnits = temporalUnits.flat().sort((a, b) => (a > b ? -1 : 1));
|
|
6
7
|
return {
|
|
7
8
|
// Uncomment when developing.
|
|
8
9
|
// defaultToken: "invalid",
|
|
9
10
|
// ES|QL is case-insensitive.
|
|
10
11
|
ignoreCase: true,
|
|
11
12
|
// Lists of known language keywords and built-ins.
|
|
12
|
-
|
|
13
|
+
sourceCommands,
|
|
14
|
+
processingCommands,
|
|
13
15
|
options,
|
|
14
16
|
literals,
|
|
15
17
|
functions,
|
|
@@ -35,7 +37,8 @@ const create = (deps = {}) => {
|
|
|
35
37
|
/[a-zA-Z_$][\w$]*/,
|
|
36
38
|
{
|
|
37
39
|
cases: {
|
|
38
|
-
"@
|
|
40
|
+
"@sourceCommands": { token: "keyword.command.source.$0" },
|
|
41
|
+
"@processingCommands": { token: "keyword.command.processing.$0" },
|
|
39
42
|
"@options": { token: "keyword.option.$0" },
|
|
40
43
|
"@literals": { token: "keyword.literal.$0" },
|
|
41
44
|
"@functions": { token: "identifier.function.$0" },
|
|
@@ -91,11 +94,18 @@ const create = (deps = {}) => {
|
|
|
91
94
|
commandName: [
|
|
92
95
|
// First tries to match all known command names.
|
|
93
96
|
[
|
|
94
|
-
|
|
95
|
-
{ token: "keyword.command.
|
|
97
|
+
sourceCommands.join("|"),
|
|
98
|
+
{ token: "keyword.command.source.$0", switchTo: "@root" },
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
processingCommands.join("|"),
|
|
102
|
+
{ token: "keyword.command.processing.$0", switchTo: "@root" },
|
|
96
103
|
],
|
|
97
104
|
// If command name is not well known, just matches the first word.
|
|
98
|
-
[
|
|
105
|
+
[
|
|
106
|
+
/\w+\b/,
|
|
107
|
+
{ token: "keyword.command.processing.$0", switchTo: "@root" },
|
|
108
|
+
],
|
|
99
109
|
],
|
|
100
110
|
// ------------------------------------------------------------- Expressions
|
|
101
111
|
expression: [
|
|
@@ -112,6 +122,7 @@ const create = (deps = {}) => {
|
|
|
112
122
|
[/`/, "string", "@column_escape_part"],
|
|
113
123
|
],
|
|
114
124
|
literal: [
|
|
125
|
+
{ include: "@timeInterval" },
|
|
115
126
|
{ include: "@number" },
|
|
116
127
|
// Params
|
|
117
128
|
[
|
|
@@ -125,6 +136,7 @@ const create = (deps = {}) => {
|
|
|
125
136
|
},
|
|
126
137
|
],
|
|
127
138
|
],
|
|
139
|
+
timeInterval: [[`(@digits)\\s*(${timeUnits.join("|")})`, "number.time"]],
|
|
128
140
|
number: [
|
|
129
141
|
[/(@digits)[eE]([\-+]?(@digits))?/, "number.float"],
|
|
130
142
|
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, "number.float"],
|