@coldsmirk/inkstone-elasticsearch 0.26.1 → 0.27.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @coldsmirk/inkstone-elasticsearch
2
2
 
3
- Elasticsearch request editing intelligence for Monaco: requests in Kibana's console spelling (`GET /orders/_search` on the first line, the body after), endpoint and index completion on the path, body keys by where the caret stands (the query DSL's clauses under `query`, a `bool`'s clauses, the aggregation types, a mapping's field options …), the request read as the engine reads it, markers, and a drop-in React `<ElasticsearchEditor>`.
3
+ Elasticsearch request editing intelligence for Monaco and CodeMirror: requests in Kibana's console spelling (`GET /orders/_search` on the first line, the body after), endpoint and index completion on the path, body keys by where the caret stands (the query DSL's clauses under `query`, a `bool`'s clauses, the aggregation types, a mapping's field options …), the request read as the engine reads it, markers, and a drop-in React `<ElasticsearchEditor>`.
4
4
 
5
5
  Part of [inkstone](https://github.com/coldsmirk/inkstone). Built for the [**polyglot**](https://github.com/coldsmirk/polyglot) sidecar's Elasticsearch engine, which takes one request in this very spelling.
6
6
 
@@ -8,6 +8,7 @@ Part of [inkstone](https://github.com/coldsmirk/inkstone). Built for the [**poly
8
8
 
9
9
  - **`@coldsmirk/inkstone-elasticsearch`** — the framework-free core: the request reader, the endpoint table, the body vocabulary, the assist, the markers. Zero editor dependencies.
10
10
  - **`@coldsmirk/inkstone-elasticsearch/monaco`** — `defineElasticsearchLanguage(monaco)` (the `elasticsearch` id with its Monarch grammar, once per monaco module), `registerElasticsearchLanguage(monaco, modelPath, hooks)` (completion and hover for one model), `setElasticsearchMarkers`. Peer: `monaco-editor`.
11
+ - **`@coldsmirk/inkstone-elasticsearch/codemirror`** — the same assist bound to CodeMirror 6: `elasticsearchCompletion(assist)` and `elasticsearchBodyCompletion(assist)` (completion sources), `elasticsearchHover(assist, wording)`, `elasticsearchDiagnostics(markers, wording)`. No grammar of its own — a body is JSON, so pair it with `@codemirror/lang-json`; it does not close brackets or quotes either, so add `closeBrackets()` where a key's own quotes matter. Peers: `@codemirror/autocomplete`, `@codemirror/view`.
11
12
  - **`@coldsmirk/inkstone-elasticsearch/react`** — `<ElasticsearchEditor>`: a controlled request editor built on `@coldsmirk/inkstone-react`'s `<MonacoEditor>`, with a run key (Ctrl/Cmd-Enter handing over the live caret), caret tracking, an insert handle for index trees, and the markers refreshed on every change. Peers: `monaco-editor`, `react`.
12
13
 
13
14
  ## The shape
@@ -1,4 +1,4 @@
1
- import { a as ElasticsearchAssist, o as ElasticsearchBodyAssist, t as ElasticsearchMarker } from "./markers-DnaVJoMY.js";
1
+ import { a as ElasticsearchAssist, o as ElasticsearchBodyAssist, t as ElasticsearchMarker } from "./markers-CCVlVnBt.js";
2
2
  import { CompletionSource } from "@codemirror/autocomplete";
3
3
  import { Diagnostic } from "@codemirror/lint";
4
4
  import { Extension } from "@codemirror/state";
@@ -1,4 +1,3 @@
1
- import { snippet } from "@codemirror/autocomplete";
2
1
  import { hoverTooltip } from "@codemirror/view";
3
2
  //#region src/codemirror.ts
4
3
  const TYPES = {
@@ -15,7 +14,7 @@ function completion(candidate, at) {
15
14
  detail: candidate.detail,
16
15
  info: candidate.documentation,
17
16
  boost: -candidate.sortGroup * 10 - at / 1e3,
18
- apply: candidate.snippet === true ? snippet(candidate.insertText) : candidate.insertText
17
+ apply: candidate.insertText
19
18
  };
20
19
  }
21
20
  function resultOf(candidates, pos) {
@@ -51,7 +50,7 @@ function elasticsearchDiagnostics(markers, wording) {
51
50
  return {
52
51
  from: marker.from,
53
52
  to: marker.to,
54
- severity: marker.severity === "error" ? "error" : marker.severity === "warning" ? "warning" : "info",
53
+ severity: marker.severity,
55
54
  message: wording(marker)
56
55
  };
57
56
  });
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as runnableRequest, C as RequestRefusal, D as readRequest, E as keyPosition, O as requestAt, S as RequestRead, T as caretContext, _ as endpointOf, a as ElasticsearchAssist, b as REQUEST_METHODS, c as ElasticsearchCompletionCandidate, d as createElasticsearchBodyAssist, f as API_ENDPOINTS, g as bodyKindOf, h as bodyKeys, i as CatalogIndex, j as takesLines, k as requestSpans, l as ElasticsearchHoverCard, m as BodyKind, n as ElasticsearchMarkerCode, o as ElasticsearchBodyAssist, p as ApiEndpoint, r as requestMarkers, s as ElasticsearchCatalog, t as ElasticsearchMarker, u as createElasticsearchAssist, v as CaretContext, w as RunnableRequest, x as RequestMethod, y as KeyPosition } from "./markers-DnaVJoMY.js";
1
+ import { A as runnableRequest, C as RequestRefusal, D as readRequest, E as keyPosition, O as requestAt, S as RequestRead, T as caretContext, _ as endpointOf, a as ElasticsearchAssist, b as REQUEST_METHODS, c as ElasticsearchCompletionCandidate, d as createElasticsearchBodyAssist, f as API_ENDPOINTS, g as bodyKindOf, h as bodyKeys, i as CatalogIndex, j as takesLines, k as requestSpans, l as ElasticsearchHoverCard, m as BodyKind, n as ElasticsearchMarkerCode, o as ElasticsearchBodyAssist, p as ApiEndpoint, r as requestMarkers, s as ElasticsearchCatalog, t as ElasticsearchMarker, u as createElasticsearchAssist, v as CaretContext, w as RunnableRequest, x as RequestMethod, y as KeyPosition } from "./markers-CCVlVnBt.js";
2
2
  export { API_ENDPOINTS, type ApiEndpoint, type BodyKind, type CaretContext, type CatalogIndex, type ElasticsearchAssist, type ElasticsearchBodyAssist, type ElasticsearchCatalog, type ElasticsearchCompletionCandidate, type ElasticsearchHoverCard, type ElasticsearchMarker, type ElasticsearchMarkerCode, type KeyPosition, REQUEST_METHODS, type RequestMethod, type RequestRead, type RequestRefusal, type RunnableRequest, bodyKeys, bodyKindOf, caretContext, createElasticsearchAssist, createElasticsearchBodyAssist, endpointOf, keyPosition, readRequest, requestAt, requestMarkers, requestSpans, runnableRequest, takesLines };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as readRequest, c as runnableRequest, d as bodyKeys, f as bodyKindOf, i as keyPosition, l as takesLines, n as REQUEST_METHODS, o as requestAt, p as endpointOf, r as caretContext, s as requestSpans, t as requestMarkers, u as API_ENDPOINTS } from "./markers-DwYWlWEq.js";
1
+ import { a as readRequest, c as runnableRequest, d as bodyKeys, f as bodyKindOf, i as keyPosition, l as takesLines, n as REQUEST_METHODS, o as requestAt, p as endpointOf, r as caretContext, s as requestSpans, t as requestMarkers, u as API_ENDPOINTS } from "./markers-DDAAW21w.js";
2
2
  //#region src/assist.ts
3
3
  const NO_CATALOG = { indices: () => [] };
4
4
  function createElasticsearchBodyAssist(kind) {
@@ -15,14 +15,13 @@ function keyCandidates(kind, at) {
15
15
  label: key,
16
16
  kind: "key",
17
17
  insertText: key,
18
- replace: at.typed.length,
18
+ replace: at.reach,
19
19
  sortGroup: 0
20
20
  } : {
21
21
  label: key,
22
22
  kind: "key",
23
- insertText: `"${key}": $0`,
24
- snippet: true,
25
- replace: 0,
23
+ insertText: `"${key}": `,
24
+ replace: at.reach,
26
25
  sortGroup: 0
27
26
  });
28
27
  }
@@ -119,6 +119,10 @@ type CaretContext = {
119
119
  * The key's characters typed before the caret, inside an opened quote where one stands.
120
120
  */
121
121
  typed: string;
122
+ /**
123
+ * How many characters before the caret a completion replaces (`KeyPosition.reach`).
124
+ */
125
+ reach: number;
122
126
  /**
123
127
  * Whether the caret is inside an opened quote.
124
128
  */
@@ -146,6 +150,16 @@ interface KeyPosition {
146
150
  * whether a completion inserts the name alone or the whole `"key": ` around it.
147
151
  */
148
152
  quoted: boolean;
153
+ /**
154
+ * How many characters before the caret a completion replaces: what the reader has already
155
+ * put where the key goes, quotes included where they typed them.
156
+ *
157
+ * Stated rather than derived from `typed`, because the two part company exactly where it
158
+ * matters. A key the reader has closed — `{"query"`, the caret after the quote, no colon
159
+ * yet — has five characters typed and seven to reach back over, and reaching over none
160
+ * wrote the completion *after* the key: `{"query""aggs": `.
161
+ */
162
+ reach: number;
149
163
  }
150
164
  /**
151
165
  * Whether the end of `body` — the text before the caret — is a key position in an object, and
@@ -210,11 +224,11 @@ interface ElasticsearchCatalog {
210
224
  interface ElasticsearchCompletionCandidate {
211
225
  label: string;
212
226
  kind: "method" | "endpoint" | "index" | "alias" | "key";
213
- insertText: string;
214
227
  /**
215
- * `insertText` is a snippet (`$0` marks the caret) rather than plain text.
228
+ * What the editor writes in place of what `replace` reaches back over. Plain text: the
229
+ * caret lands at its end, which is where a key's value goes.
216
230
  */
217
- snippet?: boolean;
231
+ insertText: string;
218
232
  /**
219
233
  * How many characters before the caret the insert replaces — the segment or the key typed
220
234
  * so far, which the editor's own word rules do not see whole (a path segment holds `_` and
@@ -618,7 +618,6 @@ const FIELD_KEYS = [
618
618
  "similarity",
619
619
  "term_vector",
620
620
  "norms",
621
- "index_options",
622
621
  "eager_global_ordinals",
623
622
  "meta",
624
623
  "dims",
@@ -1088,7 +1087,8 @@ function caretContext(text, offset) {
1088
1087
  path: [],
1089
1088
  request,
1090
1089
  typed: "",
1091
- quoted: false
1090
+ quoted: false,
1091
+ reach: 0
1092
1092
  } : { kind: "none" };
1093
1093
  const bodyFrom = span.from + request.bodySpan.from;
1094
1094
  const position = keyPosition(text.slice(bodyFrom, offset));
@@ -1146,7 +1146,8 @@ function keyPosition(body) {
1146
1146
  if (end === -1) return atKey(frames) ? {
1147
1147
  path: pathOf(frames),
1148
1148
  typed: body.slice(i + 1),
1149
- quoted: true
1149
+ quoted: true,
1150
+ reach: body.length - (i + 1)
1150
1151
  } : null;
1151
1152
  pending = body.slice(i + 1, end);
1152
1153
  i = end + 1;
@@ -1155,11 +1156,14 @@ function keyPosition(body) {
1155
1156
  structure(frames, c, pending);
1156
1157
  i++;
1157
1158
  }
1158
- return atKey(frames) ? {
1159
+ if (!atKey(frames)) return null;
1160
+ const written = /"(?<quoted>(?:[^"\\]|\\.)*)"$|(?<bare>[\w.*@$-]+)$/u.exec(body);
1161
+ return {
1159
1162
  path: pathOf(frames),
1160
- typed: "",
1161
- quoted: false
1162
- } : null;
1163
+ typed: written?.groups?.quoted ?? written?.groups?.bare ?? "",
1164
+ quoted: false,
1165
+ reach: written?.[0].length ?? 0
1166
+ };
1163
1167
  }
1164
1168
  function closingQuote(body, from) {
1165
1169
  let i = from;
package/dist/monaco.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ElasticsearchAssist, t as ElasticsearchMarker } from "./markers-DnaVJoMY.js";
1
+ import { a as ElasticsearchAssist, t as ElasticsearchMarker } from "./markers-CCVlVnBt.js";
2
2
  import * as monacoEditor from "monaco-editor";
3
3
  import { IDisposable, editor } from "monaco-editor";
4
4
  //#region src/monaco.d.ts
package/dist/monaco.js CHANGED
@@ -102,7 +102,6 @@ function registerElasticsearchLanguage(monaco, modelPath, hooks, languageId = EL
102
102
  label: candidate.label,
103
103
  kind: kinds[candidate.kind],
104
104
  insertText: candidate.insertText,
105
- insertTextRules: candidate.snippet ? monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet : void 0,
106
105
  detail: candidate.detail,
107
106
  documentation: candidate.documentation,
108
107
  range: new monaco.Range(position.lineNumber, Math.max(1, position.column - candidate.replace), position.lineNumber, position.column),
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ElasticsearchAssist, t as ElasticsearchMarker } from "./markers-DnaVJoMY.js";
1
+ import { a as ElasticsearchAssist, t as ElasticsearchMarker } from "./markers-CCVlVnBt.js";
2
2
  import { MonacoModule } from "./monaco.js";
3
3
  import { ReactNode } from "react";
4
4
  import { editor } from "monaco-editor";
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as requestMarkers } from "./markers-DwYWlWEq.js";
1
+ import { t as requestMarkers } from "./markers-DDAAW21w.js";
2
2
  import { ELASTICSEARCH_LANGUAGE_ID, defineElasticsearchLanguage, registerElasticsearchLanguage, setElasticsearchMarkers } from "./monaco.js";
3
3
  import { MonacoEditor } from "@coldsmirk/inkstone-react/monaco";
4
4
  import { useEffect, useInsertionEffect, useRef, useState } from "react";
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@coldsmirk/inkstone-elasticsearch",
3
- "version": "0.26.1",
4
- "description": "Elasticsearch request editing intelligence for Monaco: the console spelling (a method and a path, the body after), endpoint and index completion, body keys by context, request markers, and a drop-in React request editor.",
3
+ "version": "0.27.1",
4
+ "description": "Elasticsearch request editing intelligence for Monaco and CodeMirror: the console spelling (a method and a path, the body after), endpoint and index completion, body keys by context — a bare `_search` body included — request markers, and a drop-in React request editor.",
5
5
  "keywords": [
6
6
  "elasticsearch",
7
7
  "monaco",
8
+ "codemirror",
8
9
  "completion",
9
10
  "editor",
10
11
  "autocomplete",
@@ -54,7 +55,7 @@
54
55
  "monaco-editor": "^0.56.0",
55
56
  "react": "^19.2.8",
56
57
  "react-dom": "^19.2.8",
57
- "@coldsmirk/inkstone-react": "^0.26.1"
58
+ "@coldsmirk/inkstone-react": "^0.27.1"
58
59
  },
59
60
  "peerDependencies": {
60
61
  "@codemirror/autocomplete": "^6.20.3",
@@ -63,7 +64,7 @@
63
64
  "@codemirror/view": "^6.43.0",
64
65
  "monaco-editor": "^0.56.0",
65
66
  "react": ">=19",
66
- "@coldsmirk/inkstone-react": "^0.26.1"
67
+ "@coldsmirk/inkstone-react": "^0.27.1"
67
68
  },
68
69
  "peerDependenciesMeta": {
69
70
  "@codemirror/autocomplete": {