@coldsmirk/inkstone-mongodb 0.25.0 → 0.26.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.
@@ -0,0 +1,26 @@
1
+ import { _ as MongodbFilterAssist, m as MongodbAssist, t as MongodbMarker } from "./markers-DjjkoOJP.js";
2
+ import { CompletionSource } from "@codemirror/autocomplete";
3
+ import { Diagnostic } from "@codemirror/lint";
4
+ import { Extension } from "@codemirror/state";
5
+ //#region src/codemirror.d.ts
6
+ /**
7
+ * Completion over a whole command document, off an assist built with the host's catalog.
8
+ */
9
+ declare function mongodbCompletion(assist: MongodbAssist): CompletionSource;
10
+ /**
11
+ * Completion over a query document standing on its own — a one-line filter field, whose
12
+ * document is the filter and nothing else (`createMongodbFilterAssist`).
13
+ */
14
+ declare function mongodbFilterCompletion(assist: MongodbFilterAssist): CompletionSource;
15
+ /**
16
+ * The command's card under the pointer, as `./monaco`'s hover provider gives it. The markdown
17
+ * is handed over as text: rendering it is the host's, since a tooltip's DOM is the host's
18
+ * design and this package ships none.
19
+ */
20
+ declare function mongodbHover(assist: MongodbAssist, render: (markdown: string[]) => HTMLElement): Extension;
21
+ /**
22
+ * This package's markers as CodeMirror's diagnostics, the words beside each code the host's.
23
+ */
24
+ declare function mongodbDiagnostics(markers: readonly MongodbMarker[], wording: (marker: MongodbMarker) => string): Diagnostic[];
25
+ //#endregion
26
+ export { mongodbCompletion, mongodbDiagnostics, mongodbFilterCompletion, mongodbHover };
@@ -0,0 +1,61 @@
1
+ import { snippet } from "@codemirror/autocomplete";
2
+ import { hoverTooltip } from "@codemirror/view";
3
+ //#region src/codemirror.ts
4
+ const TYPES = {
5
+ command: "keyword",
6
+ field: "property",
7
+ operator: "function",
8
+ stage: "function",
9
+ collection: "class",
10
+ database: "namespace"
11
+ };
12
+ function completion(candidate, at) {
13
+ return {
14
+ label: candidate.label,
15
+ type: TYPES[candidate.kind],
16
+ detail: candidate.detail,
17
+ info: candidate.documentation,
18
+ boost: -candidate.sortGroup * 10 - at / 1e3,
19
+ apply: candidate.snippet === true ? snippet(candidate.insertText) : candidate.insertText
20
+ };
21
+ }
22
+ function resultOf(candidates, pos) {
23
+ const first = candidates[0];
24
+ if (first === void 0) return null;
25
+ return {
26
+ from: pos - first.replace,
27
+ options: candidates.map((candidate, at) => completion(candidate, at)),
28
+ validFor: /^[\w.$-]*$/
29
+ };
30
+ }
31
+ function mongodbCompletion(assist) {
32
+ return (context) => resultOf(assist.complete(context.state.doc.toString(), context.pos), context.pos);
33
+ }
34
+ function mongodbFilterCompletion(assist) {
35
+ return (context) => resultOf(assist.complete(context.state.doc.toString(), context.pos), context.pos);
36
+ }
37
+ function mongodbHover(assist, render) {
38
+ return hoverTooltip((view, pos) => {
39
+ const card = assist.hover(view.state.doc.toString(), pos);
40
+ if (card === null) return null;
41
+ return {
42
+ pos: card.from,
43
+ end: card.to,
44
+ create: () => {
45
+ return { dom: render(card.markdown) };
46
+ }
47
+ };
48
+ });
49
+ }
50
+ function mongodbDiagnostics(markers, wording) {
51
+ return markers.map((marker) => {
52
+ return {
53
+ from: marker.from,
54
+ to: marker.to,
55
+ severity: marker.severity === "error" ? "error" : "info",
56
+ message: wording(marker)
57
+ };
58
+ });
59
+ }
60
+ //#endregion
61
+ export { mongodbCompletion, mongodbDiagnostics, mongodbFilterCompletion, mongodbHover };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { C as PUSH_MODIFIERS, D as keysAt, E as UPDATE_OPERATORS, S as MongoCommand, T as STAGES, _ as MongodbHoverCard, a as CaretContext, b as FIELD_OPERATORS, c as LITERALS, d as readDocument, f as runnableDocument, g as MongodbCompletionCandidate, h as MongodbCatalog, i as CONSTRUCTORS, l as RunnableDocument, m as MongodbAssist, n as MongodbMarkerCode, o as DocumentRead, p as CatalogCollection, r as documentMarkers, s as DocumentRefusal, t as MongodbMarker, u as caretContext, v as createMongodbAssist, w as QUERY_OPERATORS, x as MONGO_COMMANDS, y as EXPRESSION_OPERATORS } from "./markers-CQOm7diu.js";
2
- export { CONSTRUCTORS, type CaretContext, type CatalogCollection, type DocumentRead, type DocumentRefusal, EXPRESSION_OPERATORS, FIELD_OPERATORS, LITERALS, MONGO_COMMANDS, type MongoCommand, type MongodbAssist, type MongodbCatalog, type MongodbCompletionCandidate, type MongodbHoverCard, type MongodbMarker, type MongodbMarkerCode, PUSH_MODIFIERS, QUERY_OPERATORS, type RunnableDocument, STAGES, UPDATE_OPERATORS, caretContext, createMongodbAssist, documentMarkers, keysAt, readDocument, runnableDocument };
1
+ import { A as keysAt, C as MONGO_COMMANDS, D as QUERY_OPERATORS, E as QUERY_HOLDERS, O as STAGES, S as FIELD_OPERATORS, T as PUSH_MODIFIERS, _ as MongodbFilterAssist, a as CaretContext, b as createMongodbFilterAssist, c as LITERALS, d as readDocument, f as runnableDocument, g as MongodbCompletionCandidate, h as MongodbCatalog, i as CONSTRUCTORS, k as UPDATE_OPERATORS, l as RunnableDocument, m as MongodbAssist, n as MongodbMarkerCode, o as DocumentRead, p as CatalogCollection, r as documentMarkers, s as DocumentRefusal, t as MongodbMarker, u as caretContext, v as MongodbHoverCard, w as MongoCommand, x as EXPRESSION_OPERATORS, y as createMongodbAssist } from "./markers-DjjkoOJP.js";
2
+ export { CONSTRUCTORS, type CaretContext, type CatalogCollection, type DocumentRead, type DocumentRefusal, EXPRESSION_OPERATORS, FIELD_OPERATORS, LITERALS, MONGO_COMMANDS, type MongoCommand, type MongodbAssist, type MongodbCatalog, type MongodbCompletionCandidate, type MongodbFilterAssist, type MongodbHoverCard, type MongodbMarker, type MongodbMarkerCode, PUSH_MODIFIERS, QUERY_HOLDERS, QUERY_OPERATORS, type RunnableDocument, STAGES, UPDATE_OPERATORS, caretContext, createMongodbAssist, createMongodbFilterAssist, documentMarkers, keysAt, readDocument, runnableDocument };
package/dist/index.js CHANGED
@@ -1,7 +1,26 @@
1
- import { a as PUSH_MODIFIERS, c as UPDATE_OPERATORS, i as MONGO_COMMANDS, l as keysAt, n as EXPRESSION_OPERATORS, o as QUERY_OPERATORS, r as FIELD_OPERATORS, s as STAGES, t as documentMarkers } from "./markers-Bdvbut2O.js";
1
+ import { a as PUSH_MODIFIERS, c as STAGES, i as MONGO_COMMANDS, l as UPDATE_OPERATORS, n as EXPRESSION_OPERATORS, o as QUERY_HOLDERS, r as FIELD_OPERATORS, s as QUERY_OPERATORS, t as documentMarkers, u as keysAt } from "./markers-CbwviTiD.js";
2
2
  import { a as runnableDocument, i as readDocument, n as LITERALS, r as caretContext, t as CONSTRUCTORS } from "./document-CVB9YunA.js";
3
3
  //#region src/assist.ts
4
4
  const NO_CATALOG = { collections: () => [] };
5
+ function createMongodbFilterAssist(fields = () => []) {
6
+ return { complete: (filter, offset) => {
7
+ const context = caretContext(filter, offset);
8
+ if (context.kind !== "key") return [];
9
+ const under = context.path.at(-1);
10
+ const named = under === void 0 || QUERY_HOLDERS.has(under) ? fields().filter((field) => !context.siblings.includes(field)) : [];
11
+ const keys = keysAt(["filter", ...context.path], context.siblings);
12
+ return [...named, ...keys].map((key) => {
13
+ return {
14
+ label: key,
15
+ kind: key.startsWith("$") ? "operator" : "field",
16
+ insertText: context.quoted ? key : `"${key}": $0`,
17
+ ...!context.quoted && { snippet: true },
18
+ replace: context.typed.length,
19
+ sortGroup: key.startsWith("$") ? 1 : 0
20
+ };
21
+ });
22
+ } };
23
+ }
5
24
  function documentationOf(command) {
6
25
  return command.fields.length === 0 ? command.summary : `${command.summary}\n\nFields: ${command.fields.join(", ")}`;
7
26
  }
@@ -87,4 +106,4 @@ function createMongodbAssist(catalog = NO_CATALOG, commands = MONGO_COMMANDS) {
87
106
  };
88
107
  }
89
108
  //#endregion
90
- export { CONSTRUCTORS, EXPRESSION_OPERATORS, FIELD_OPERATORS, LITERALS, MONGO_COMMANDS, PUSH_MODIFIERS, QUERY_OPERATORS, STAGES, UPDATE_OPERATORS, caretContext, createMongodbAssist, documentMarkers, keysAt, readDocument, runnableDocument };
109
+ export { CONSTRUCTORS, EXPRESSION_OPERATORS, FIELD_OPERATORS, LITERALS, MONGO_COMMANDS, PUSH_MODIFIERS, QUERY_HOLDERS, QUERY_OPERATORS, STAGES, UPDATE_OPERATORS, caretContext, createMongodbAssist, createMongodbFilterAssist, documentMarkers, keysAt, readDocument, runnableDocument };
@@ -1020,4 +1020,4 @@ function documentMarkers(text, commands = MONGO_COMMANDS) {
1020
1020
  return [];
1021
1021
  }
1022
1022
  //#endregion
1023
- export { PUSH_MODIFIERS as a, UPDATE_OPERATORS as c, MONGO_COMMANDS as i, keysAt as l, EXPRESSION_OPERATORS as n, QUERY_OPERATORS as o, FIELD_OPERATORS as r, STAGES as s, documentMarkers as t };
1023
+ export { PUSH_MODIFIERS as a, STAGES as c, MONGO_COMMANDS as i, UPDATE_OPERATORS as l, EXPRESSION_OPERATORS as n, QUERY_HOLDERS as o, FIELD_OPERATORS as r, QUERY_OPERATORS as s, documentMarkers as t, keysAt as u };
@@ -28,6 +28,16 @@ declare const UPDATE_OPERATORS: string[];
28
28
  declare const PUSH_MODIFIERS: string[];
29
29
  declare const STAGES: string[];
30
30
  declare const EXPRESSION_OPERATORS: string[];
31
+ /**
32
+ * The keys whose value is a query: a filter, and every logical operator's branches.
33
+ */
34
+ /**
35
+ * The keys whose value is a query document: what is under one is a field name or a logical
36
+ * operator, and what is under a *field* of one is a comparison operator. Exported because a
37
+ * filter can also stand on its own, with no key above it to say so
38
+ * (`createMongodbFilterAssist`).
39
+ */
40
+ declare const QUERY_HOLDERS: Set<string>;
31
41
  /**
32
42
  * The keys to offer at a key position, by the keys enclosing the caret and — at the top level
33
43
  * — the keys already there, the first of which names the command. Empty where the names are
@@ -80,6 +90,27 @@ interface MongodbAssist {
80
90
  complete: (text: string, offset: number) => MongodbCompletionCandidate[];
81
91
  hover: (text: string, offset: number) => MongodbHoverCard | null;
82
92
  }
93
+ /**
94
+ * Completion for a query document standing on its own, with no command around it to say what
95
+ * it is the filter of — a filter typed into a one-line field, which is how a console browses
96
+ * a collection without a command written out.
97
+ */
98
+ interface MongodbFilterAssist {
99
+ complete: (filter: string, offset: number) => MongodbCompletionCandidate[];
100
+ }
101
+ /**
102
+ * The query vocabulary alone, for a surface that holds a filter and nothing else.
103
+ *
104
+ * The document is read as though it were the value of a `filter` key, which it is in every
105
+ * command that takes one: `keysAt` then answers a filter's own vocabulary at every depth —
106
+ * the logical operators at the top, a field's comparison operators inside it — with nothing
107
+ * about a filter restated here.
108
+ *
109
+ * `fields` is the collection's own, which the package cannot know and the host can: they go
110
+ * first, and only where a field name is what belongs — under a query holder, never inside
111
+ * the operator object of a field.
112
+ */
113
+ declare function createMongodbFilterAssist(fields?: () => readonly string[]): MongodbFilterAssist;
83
114
  /**
84
115
  * Completion for keys and for the values that name a collection or a database, hover for the
85
116
  * command under its key — all reading the document through `document.ts`.
@@ -215,4 +246,4 @@ interface MongodbMarker {
215
246
  */
216
247
  declare function documentMarkers(text: string, commands?: readonly MongoCommand[]): MongodbMarker[];
217
248
  //#endregion
218
- export { PUSH_MODIFIERS as C, keysAt as D, UPDATE_OPERATORS as E, MongoCommand as S, STAGES as T, MongodbHoverCard as _, CaretContext as a, FIELD_OPERATORS as b, LITERALS as c, readDocument as d, runnableDocument as f, MongodbCompletionCandidate as g, MongodbCatalog as h, CONSTRUCTORS as i, RunnableDocument as l, MongodbAssist as m, MongodbMarkerCode as n, DocumentRead as o, CatalogCollection as p, documentMarkers as r, DocumentRefusal as s, MongodbMarker as t, caretContext as u, createMongodbAssist as v, QUERY_OPERATORS as w, MONGO_COMMANDS as x, EXPRESSION_OPERATORS as y };
249
+ export { keysAt as A, MONGO_COMMANDS as C, QUERY_OPERATORS as D, QUERY_HOLDERS as E, STAGES as O, FIELD_OPERATORS as S, PUSH_MODIFIERS as T, MongodbFilterAssist as _, CaretContext as a, createMongodbFilterAssist as b, LITERALS as c, readDocument as d, runnableDocument as f, MongodbCompletionCandidate as g, MongodbCatalog as h, CONSTRUCTORS as i, UPDATE_OPERATORS as k, RunnableDocument as l, MongodbAssist as m, MongodbMarkerCode as n, DocumentRead as o, CatalogCollection as p, documentMarkers as r, DocumentRefusal as s, MongodbMarker as t, caretContext as u, MongodbHoverCard as v, MongoCommand as w, EXPRESSION_OPERATORS as x, createMongodbAssist as y };
package/dist/monaco.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { m as MongodbAssist, t as MongodbMarker } from "./markers-CQOm7diu.js";
1
+ import { m as MongodbAssist, t as MongodbMarker } from "./markers-DjjkoOJP.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/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { m as MongodbAssist, t as MongodbMarker } from "./markers-CQOm7diu.js";
1
+ import { m as MongodbAssist, t as MongodbMarker } from "./markers-DjjkoOJP.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 documentMarkers } from "./markers-Bdvbut2O.js";
1
+ import { t as documentMarkers } from "./markers-CbwviTiD.js";
2
2
  import { MONGODB_LANGUAGE_ID, defineMongodbLanguage, registerMongodbLanguage, setMongodbMarkers } 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@coldsmirk/inkstone-mongodb",
3
- "version": "0.25.0",
3
+ "version": "0.26.1",
4
4
  "description": "MongoDB command editing intelligence for Monaco: a command document in the shell's own spelling, the database commands and their fields, query, update and aggregation operators by context, collection completion, markers, and a drop-in React command editor.",
5
5
  "keywords": [
6
6
  "mongodb",
@@ -28,32 +28,56 @@
28
28
  "types": "./dist/index.d.ts",
29
29
  "default": "./dist/index.js"
30
30
  },
31
+ "./codemirror": {
32
+ "types": "./dist/codemirror.d.ts",
33
+ "default": "./dist/codemirror.js"
34
+ },
31
35
  "./monaco": {
32
36
  "types": "./dist/monaco.d.ts",
33
37
  "default": "./dist/monaco.js"
34
38
  },
39
+ "./package.json": "./package.json",
35
40
  "./react": {
36
41
  "types": "./dist/react.d.ts",
37
42
  "default": "./dist/react.js"
38
- },
39
- "./package.json": "./package.json"
43
+ }
40
44
  },
41
45
  "types": "./dist/index.d.ts",
42
46
  "files": [
43
47
  "dist"
44
48
  ],
45
49
  "devDependencies": {
50
+ "@codemirror/autocomplete": "^6.20.3",
51
+ "@codemirror/lint": "^6.9.7",
52
+ "@codemirror/state": "^6.6.0",
53
+ "@codemirror/view": "^6.43.0",
46
54
  "monaco-editor": "^0.56.0",
47
55
  "react": "^19.2.8",
48
56
  "react-dom": "^19.2.8",
49
- "@coldsmirk/inkstone-react": "^0.25.0"
57
+ "@coldsmirk/inkstone-react": "^0.26.1"
50
58
  },
51
59
  "peerDependencies": {
60
+ "@codemirror/autocomplete": "^6.20.3",
61
+ "@codemirror/lint": "^6.9.7",
62
+ "@codemirror/state": "^6.6.0",
63
+ "@codemirror/view": "^6.43.0",
52
64
  "monaco-editor": "^0.56.0",
53
65
  "react": ">=19",
54
- "@coldsmirk/inkstone-react": "^0.25.0"
66
+ "@coldsmirk/inkstone-react": "^0.26.1"
55
67
  },
56
68
  "peerDependenciesMeta": {
69
+ "@codemirror/autocomplete": {
70
+ "optional": true
71
+ },
72
+ "@codemirror/lint": {
73
+ "optional": true
74
+ },
75
+ "@codemirror/state": {
76
+ "optional": true
77
+ },
78
+ "@codemirror/view": {
79
+ "optional": true
80
+ },
57
81
  "@coldsmirk/inkstone-react": {
58
82
  "optional": true
59
83
  },