@mongosh/browser-runtime-core 3.13.0 → 3.16.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/lib/autocompleter/shell-api-autocompleter.d.ts +9 -1
- package/lib/autocompleter/shell-api-autocompleter.js +16 -7
- package/lib/autocompleter/shell-api-autocompleter.js.map +1 -1
- package/lib/open-context-runtime.js +1 -1
- package/lib/open-context-runtime.js.map +1 -1
- package/package.json +7 -6
- package/src/autocompleter/shell-api-autocompleter.spec.ts +21 -4
- package/src/autocompleter/shell-api-autocompleter.ts +38 -6
- package/src/open-context-runtime.ts +1 -3
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
|
|
1
2
|
import type { AutocompleteParameters } from '@mongosh/autocomplete';
|
|
2
3
|
import type { Autocompleter, Completion } from './autocompleter';
|
|
4
|
+
type AutocompleteShellInstanceState = {
|
|
5
|
+
getAutocompleteParameters: () => AutocompleteParameters;
|
|
6
|
+
getAutocompletionContext: () => AutocompletionContext;
|
|
7
|
+
};
|
|
3
8
|
export declare class ShellApiAutocompleter implements Autocompleter {
|
|
9
|
+
private shellInstanceState;
|
|
4
10
|
private parameters;
|
|
5
|
-
|
|
11
|
+
private newMongoshCompleter;
|
|
12
|
+
constructor(shellInstanceState: AutocompleteShellInstanceState);
|
|
6
13
|
getCompletions(code: string): Promise<Completion[]>;
|
|
7
14
|
}
|
|
15
|
+
export {};
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ShellApiAutocompleter = void 0;
|
|
7
|
-
const autocomplete_1 =
|
|
4
|
+
const autocomplete_1 = require("@mongosh/autocomplete");
|
|
8
5
|
class ShellApiAutocompleter {
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
6
|
+
constructor(shellInstanceState) {
|
|
7
|
+
this.shellInstanceState = shellInstanceState;
|
|
11
8
|
}
|
|
12
9
|
async getCompletions(code) {
|
|
13
10
|
if (!code) {
|
|
14
11
|
return [];
|
|
15
12
|
}
|
|
16
|
-
|
|
13
|
+
let completions;
|
|
14
|
+
if (process.env.USE_NEW_AUTOCOMPLETE) {
|
|
15
|
+
if (!this.newMongoshCompleter) {
|
|
16
|
+
this.newMongoshCompleter = await (0, autocomplete_1.initNewAutocompleter)(this.shellInstanceState);
|
|
17
|
+
}
|
|
18
|
+
completions = await this.newMongoshCompleter(code);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (!this.parameters) {
|
|
22
|
+
this.parameters = this.shellInstanceState.getAutocompleteParameters();
|
|
23
|
+
}
|
|
24
|
+
completions = await (0, autocomplete_1.completer)(this.parameters, code);
|
|
25
|
+
}
|
|
17
26
|
if (!completions || !completions.length) {
|
|
18
27
|
return [];
|
|
19
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-api-autocompleter.js","sourceRoot":"","sources":["../../src/autocompleter/shell-api-autocompleter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shell-api-autocompleter.js","sourceRoot":"","sources":["../../src/autocompleter/shell-api-autocompleter.ts"],"names":[],"mappings":";;;AAKA,wDAAwE;AAQxE,MAAa,qBAAqB;IAWhC,YAAY,kBAAkD;QAC5D,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,IAAY;QAC/B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,WAA8B,CAAC;QAEnC,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,CAAC;YACrC,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBAC9B,IAAI,CAAC,mBAAmB,GAAG,MAAM,IAAA,mCAAoB,EACnD,IAAI,CAAC,kBAAkB,CACxB,CAAC;YACJ,CAAC;YAED,WAAW,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;gBACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,yBAAyB,EAAE,CAAC;YACxE,CAAC;YACD,WAAW,GAAG,MAAM,IAAA,wBAAS,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;YACxC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAChD,OAAO;gBACL,UAAU;aACX,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAjDD,sDAiDC"}
|
|
@@ -19,7 +19,7 @@ class OpenContextRuntime {
|
|
|
19
19
|
async getCompletions(code) {
|
|
20
20
|
var _a;
|
|
21
21
|
if (!this.autocompleter) {
|
|
22
|
-
this.autocompleter = new shell_api_autocompleter_1.ShellApiAutocompleter(this.instanceState
|
|
22
|
+
this.autocompleter = new shell_api_autocompleter_1.ShellApiAutocompleter(this.instanceState);
|
|
23
23
|
(_a = this.updatedConnectionInfoPromise) !== null && _a !== void 0 ? _a : (this.updatedConnectionInfoPromise = this.instanceState.fetchConnectionInfo());
|
|
24
24
|
await this.updatedConnectionInfoPromise;
|
|
25
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open-context-runtime.js","sourceRoot":"","sources":["../src/open-context-runtime.ts"],"names":[],"mappings":";;;AAEA,qFAAgF;AAMhF,mCAAsC;AACtC,kDAAwD;AAExD,8DAA0D;AAkB1D,MAAa,kBAAkB;IAQ7B,YACE,eAAgC,EAChC,sBAA8C,EAC9C,UAAuB;QATjB,kBAAa,GAAiC,IAAI,CAAC;QAGnD,uBAAkB,GAAqC,IAAI,CAAC;QAC5D,iCAA4B,GAA4B,IAAI,CAAC;QAOnE,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;QACrD,IAAI,CAAC,aAAa,GAAG,IAAI,8BAAkB,CACzC,eAAe,EACf,UAAU,IAAI,IAAI,qBAAY,EAAE,CACjC,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,aAAa,GAAG,IAAI,CAAC;QACxC,IAAI,CAAC,cAAc,GAAG,IAAI,gCAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC7D,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,IAAY;;QAC/B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,IAAI,CAAC,aAAa,GAAG,IAAI,+CAAqB,
|
|
1
|
+
{"version":3,"file":"open-context-runtime.js","sourceRoot":"","sources":["../src/open-context-runtime.ts"],"names":[],"mappings":";;;AAEA,qFAAgF;AAMhF,mCAAsC;AACtC,kDAAwD;AAExD,8DAA0D;AAkB1D,MAAa,kBAAkB;IAQ7B,YACE,eAAgC,EAChC,sBAA8C,EAC9C,UAAuB;QATjB,kBAAa,GAAiC,IAAI,CAAC;QAGnD,uBAAkB,GAAqC,IAAI,CAAC;QAC5D,iCAA4B,GAA4B,IAAI,CAAC;QAOnE,IAAI,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;QACrD,IAAI,CAAC,aAAa,GAAG,IAAI,8BAAkB,CACzC,eAAe,EACf,UAAU,IAAI,IAAI,qBAAY,EAAE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AAC,QAAQ,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,cAAc;;QAClB,MAAA,IAAI,CAAC,4BAA4B,oCAAjC,IAAI,CAAC,4BAA4B,GAC/B,IAAI,CAAC,aAAa,CAAC,mBAAmB,EAAE,EAAC;QAC3C,MAAM,IAAI,CAAC,4BAA4B,CAAC;QACxC,OAAO,MAAM,IAAI,CAAC,aAAa,CAAC,gBAAgB,EAAE,CAAC;IACrD,CAAC;CACF;AA9DD,gDA8DC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/browser-runtime-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "Mongosh browser runtime core",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -39,9 +39,10 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@mongodb-js/eslint-config-mongosh": "^1.0.0",
|
|
42
|
+
"@mongodb-js/mongodb-ts-autocomplete": "^0.2.5",
|
|
42
43
|
"@mongodb-js/prettier-config-devtools": "^1.0.1",
|
|
43
44
|
"@mongodb-js/tsconfig-mongosh": "^1.0.0",
|
|
44
|
-
"@mongosh/types": "3.8.
|
|
45
|
+
"@mongosh/types": "3.8.2",
|
|
45
46
|
"bson": "^6.10.3",
|
|
46
47
|
"depcheck": "^1.4.7",
|
|
47
48
|
"eslint": "^7.25.0",
|
|
@@ -49,10 +50,10 @@
|
|
|
49
50
|
"rimraf": "^3.0.2"
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
|
-
"@mongosh/autocomplete": "^3.
|
|
53
|
+
"@mongosh/autocomplete": "^3.16.0",
|
|
53
54
|
"@mongosh/service-provider-core": "3.3.3",
|
|
54
|
-
"@mongosh/shell-api": "^3.
|
|
55
|
-
"@mongosh/shell-evaluator": "^3.
|
|
55
|
+
"@mongosh/shell-api": "^3.16.0",
|
|
56
|
+
"@mongosh/shell-evaluator": "^3.16.0"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "ac4db1326a3c7ad18fff9a6ac06d1ca4604b0467"
|
|
58
59
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ShellApiAutocompleter } from './shell-api-autocompleter';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
import { Topologies } from '@mongosh/shell-api';
|
|
4
|
+
import type { AutocompleteParameters } from '@mongosh/autocomplete';
|
|
5
|
+
import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
|
|
4
6
|
|
|
5
|
-
const
|
|
7
|
+
const standalone440Parameters: AutocompleteParameters = {
|
|
6
8
|
topology: () => Topologies.Standalone,
|
|
7
9
|
apiVersionInfo: () => undefined,
|
|
8
10
|
connectionInfo: () => ({
|
|
@@ -11,8 +13,23 @@ const standalone440 = {
|
|
|
11
13
|
server_version: '4.4.0',
|
|
12
14
|
is_local_atlas: false,
|
|
13
15
|
}),
|
|
14
|
-
getCollectionCompletionsForCurrentDb: () => ['bananas'],
|
|
15
|
-
getDatabaseCompletions: () => ['databaseOne'],
|
|
16
|
+
getCollectionCompletionsForCurrentDb: () => Promise.resolve(['bananas']),
|
|
17
|
+
getDatabaseCompletions: () => Promise.resolve(['databaseOne']),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const standalone440Context: AutocompletionContext = {
|
|
21
|
+
currentDatabaseAndConnection: () => ({
|
|
22
|
+
connectionId: 'connection-1',
|
|
23
|
+
databaseName: 'databaseOne',
|
|
24
|
+
}),
|
|
25
|
+
databasesForConnection: () => Promise.resolve(['databaseOne']),
|
|
26
|
+
collectionsForDatabase: () => Promise.resolve(['bananas', 'coll1']),
|
|
27
|
+
schemaInformationForCollection: () => Promise.resolve({}),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const shellInstanceState = {
|
|
31
|
+
getAutocompleteParameters: () => standalone440Parameters,
|
|
32
|
+
getAutocompletionContext: () => standalone440Context,
|
|
16
33
|
};
|
|
17
34
|
|
|
18
35
|
describe('Autocompleter', function () {
|
|
@@ -20,7 +37,7 @@ describe('Autocompleter', function () {
|
|
|
20
37
|
let autocompleter: ShellApiAutocompleter;
|
|
21
38
|
|
|
22
39
|
beforeEach(function () {
|
|
23
|
-
autocompleter = new ShellApiAutocompleter(
|
|
40
|
+
autocompleter = new ShellApiAutocompleter(shellInstanceState);
|
|
24
41
|
});
|
|
25
42
|
|
|
26
43
|
it('returns completions for text before cursor', async function () {
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
|
|
2
|
+
import type {
|
|
3
|
+
AutocompleteParameters,
|
|
4
|
+
CompletionResults,
|
|
5
|
+
} from '@mongosh/autocomplete';
|
|
6
|
+
import { completer, initNewAutocompleter } from '@mongosh/autocomplete';
|
|
3
7
|
import type { Autocompleter, Completion } from './autocompleter';
|
|
4
8
|
|
|
9
|
+
type AutocompleteShellInstanceState = {
|
|
10
|
+
getAutocompleteParameters: () => AutocompleteParameters;
|
|
11
|
+
getAutocompletionContext: () => AutocompletionContext;
|
|
12
|
+
};
|
|
13
|
+
|
|
5
14
|
export class ShellApiAutocompleter implements Autocompleter {
|
|
6
|
-
private
|
|
15
|
+
private shellInstanceState: AutocompleteShellInstanceState;
|
|
16
|
+
|
|
17
|
+
// old autocomplete only:
|
|
18
|
+
private parameters: AutocompleteParameters | undefined;
|
|
19
|
+
|
|
20
|
+
// new autocomplete only:
|
|
21
|
+
private newMongoshCompleter:
|
|
22
|
+
| ((line: string) => Promise<CompletionResults>)
|
|
23
|
+
| undefined;
|
|
7
24
|
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
25
|
+
constructor(shellInstanceState: AutocompleteShellInstanceState) {
|
|
26
|
+
this.shellInstanceState = shellInstanceState;
|
|
10
27
|
}
|
|
11
28
|
|
|
12
29
|
async getCompletions(code: string): Promise<Completion[]> {
|
|
@@ -14,7 +31,22 @@ export class ShellApiAutocompleter implements Autocompleter {
|
|
|
14
31
|
return [];
|
|
15
32
|
}
|
|
16
33
|
|
|
17
|
-
|
|
34
|
+
let completions: CompletionResults;
|
|
35
|
+
|
|
36
|
+
if (process.env.USE_NEW_AUTOCOMPLETE) {
|
|
37
|
+
if (!this.newMongoshCompleter) {
|
|
38
|
+
this.newMongoshCompleter = await initNewAutocompleter(
|
|
39
|
+
this.shellInstanceState
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
completions = await this.newMongoshCompleter(code);
|
|
44
|
+
} else {
|
|
45
|
+
if (!this.parameters) {
|
|
46
|
+
this.parameters = this.shellInstanceState.getAutocompleteParameters();
|
|
47
|
+
}
|
|
48
|
+
completions = await completer(this.parameters, code);
|
|
49
|
+
}
|
|
18
50
|
|
|
19
51
|
if (!completions || !completions.length) {
|
|
20
52
|
return [];
|
|
@@ -52,9 +52,7 @@ export class OpenContextRuntime implements Runtime {
|
|
|
52
52
|
|
|
53
53
|
async getCompletions(code: string): Promise<Completion[]> {
|
|
54
54
|
if (!this.autocompleter) {
|
|
55
|
-
this.autocompleter = new ShellApiAutocompleter(
|
|
56
|
-
this.instanceState.getAutocompleteParameters()
|
|
57
|
-
);
|
|
55
|
+
this.autocompleter = new ShellApiAutocompleter(this.instanceState);
|
|
58
56
|
this.updatedConnectionInfoPromise ??=
|
|
59
57
|
this.instanceState.fetchConnectionInfo();
|
|
60
58
|
await this.updatedConnectionInfoPromise;
|