@documentdb-js/shell-runtime 0.8.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/LICENSE.md +21 -0
- package/README.md +94 -0
- package/dist/CommandInterceptor.d.ts +55 -0
- package/dist/CommandInterceptor.d.ts.map +1 -0
- package/dist/CommandInterceptor.js +87 -0
- package/dist/CommandInterceptor.js.map +1 -0
- package/dist/CommandInterceptor.test.d.ts +2 -0
- package/dist/CommandInterceptor.test.d.ts.map +1 -0
- package/dist/CommandInterceptor.test.js +195 -0
- package/dist/CommandInterceptor.test.js.map +1 -0
- package/dist/DocumentDBServiceProvider.d.ts +48 -0
- package/dist/DocumentDBServiceProvider.d.ts.map +1 -0
- package/dist/DocumentDBServiceProvider.js +59 -0
- package/dist/DocumentDBServiceProvider.js.map +1 -0
- package/dist/DocumentDBShellRuntime.d.ts +144 -0
- package/dist/DocumentDBShellRuntime.d.ts.map +1 -0
- package/dist/DocumentDBShellRuntime.js +521 -0
- package/dist/DocumentDBShellRuntime.js.map +1 -0
- package/dist/DocumentDBShellRuntime.test.d.ts +2 -0
- package/dist/DocumentDBShellRuntime.test.d.ts.map +1 -0
- package/dist/DocumentDBShellRuntime.test.js +200 -0
- package/dist/DocumentDBShellRuntime.test.js.map +1 -0
- package/dist/HelpProvider.d.ts +45 -0
- package/dist/HelpProvider.d.ts.map +1 -0
- package/dist/HelpProvider.js +179 -0
- package/dist/HelpProvider.js.map +1 -0
- package/dist/HelpProvider.test.d.ts +2 -0
- package/dist/HelpProvider.test.d.ts.map +1 -0
- package/dist/HelpProvider.test.js +133 -0
- package/dist/HelpProvider.test.js.map +1 -0
- package/dist/ResultTransformer.d.ts +58 -0
- package/dist/ResultTransformer.d.ts.map +1 -0
- package/dist/ResultTransformer.js +96 -0
- package/dist/ResultTransformer.js.map +1 -0
- package/dist/ResultTransformer.test.d.ts +2 -0
- package/dist/ResultTransformer.test.d.ts.map +1 -0
- package/dist/ResultTransformer.test.js +166 -0
- package/dist/ResultTransformer.test.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +30 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @documentdb-js/shell-runtime
|
|
2
|
+
|
|
3
|
+
[DocumentDB](https://documentdb.io/) is an open-source document database built on PostgreSQL, with native BSON support, rich indexing, and vector search. It uses the MongoDB-compatible wire protocol, runs locally with Docker, and is MIT licensed.
|
|
4
|
+
|
|
5
|
+
This package is a sandboxed JavaScript evaluation engine for DocumentDB — provides shell command handling, result transformation, and help generation. Supports both single-shot evaluation (playground/scratchpad style) and persistent REPL sessions (interactive shell style).
|
|
6
|
+
|
|
7
|
+
> **Pre-1.0 notice** — The API may change between minor versions until `1.0.0` is released.
|
|
8
|
+
> If you depend on this package and need stability guarantees sooner, please
|
|
9
|
+
> [open an issue](https://github.com/microsoft/vscode-documentdb/issues) and let us know.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **JavaScript evaluation** — executes user code in a sandboxed `vm.Context` against a target database
|
|
14
|
+
- **Command interception** — routes shell commands (`help`, `exit`, `cls`) before evaluation
|
|
15
|
+
- **Result transformation** — normalizes evaluation results into a protocol-agnostic `ShellEvaluationResult`
|
|
16
|
+
- **Help text** — generates DocumentDB-specific help output
|
|
17
|
+
- **Service provider** — bridges the evaluation engine to the MongoDB Node.js driver
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @documentdb-js/shell-runtime
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires `mongodb` ≥ 6.0.0 as a peer dependency.
|
|
26
|
+
|
|
27
|
+
## Eval Modes
|
|
28
|
+
|
|
29
|
+
The runtime supports two modes via the `persistent` option:
|
|
30
|
+
|
|
31
|
+
| Mode | `persistent` | Behavior |
|
|
32
|
+
| ------------------ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
33
|
+
| Fresh context | `false` (default) | New `ShellInstanceState` + `vm.Context` per `evaluate()` call. No variable leakage between runs. |
|
|
34
|
+
| Persistent context | `true` | Reuses the same `ShellInstanceState`, `ShellEvaluator`, and `vm.Context` across calls. Variables, cursor state (`it`), and the `db` reference persist between evaluations. |
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { MongoClient } from 'mongodb';
|
|
40
|
+
import { DocumentDBShellRuntime } from '@documentdb-js/shell-runtime';
|
|
41
|
+
|
|
42
|
+
// The caller owns the MongoClient — create, connect, and close it yourself.
|
|
43
|
+
// The runtime never opens or closes the connection.
|
|
44
|
+
const mongoClient = new MongoClient(connectionString);
|
|
45
|
+
await mongoClient.connect();
|
|
46
|
+
|
|
47
|
+
// Constructor signature:
|
|
48
|
+
// new DocumentDBShellRuntime(mongoClient, callbacks?, options?)
|
|
49
|
+
//
|
|
50
|
+
// callbacks: { onConsoleOutput?, onLog? }
|
|
51
|
+
// options: { persistent?, productName?, displayBatchSize? }
|
|
52
|
+
|
|
53
|
+
// Fresh context (playground mode — default)
|
|
54
|
+
const playground = new DocumentDBShellRuntime(mongoClient, {
|
|
55
|
+
onConsoleOutput: (output) => console.log(output),
|
|
56
|
+
});
|
|
57
|
+
const result = await playground.evaluate('db.users.find({})', 'myDatabase');
|
|
58
|
+
|
|
59
|
+
// Persistent context (interactive shell mode)
|
|
60
|
+
const shell = new DocumentDBShellRuntime(
|
|
61
|
+
mongoClient,
|
|
62
|
+
{ onConsoleOutput: (output) => console.log(output) }, // callbacks
|
|
63
|
+
{ persistent: true }, // options
|
|
64
|
+
);
|
|
65
|
+
await shell.evaluate('const x = 1', 'myDatabase');
|
|
66
|
+
await shell.evaluate('x + 1', 'myDatabase'); // returns 2 — variable survived
|
|
67
|
+
|
|
68
|
+
// Dispose the runtime when done — this does NOT close the MongoClient.
|
|
69
|
+
shell.dispose();
|
|
70
|
+
|
|
71
|
+
// Close the MongoClient when the session is over.
|
|
72
|
+
// The runtime intentionally never closes it, so the same client
|
|
73
|
+
// can be reused across multiple evaluate() calls and runtime instances.
|
|
74
|
+
await mongoClient.close();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Components
|
|
78
|
+
|
|
79
|
+
| File | Role |
|
|
80
|
+
| --------------------------- | ----------------------------------------------------------------------------- |
|
|
81
|
+
| `DocumentDBShellRuntime` | Main entry point — `evaluate(code, databaseName, options)` |
|
|
82
|
+
| `CommandInterceptor` | Pre-eval command routing (regex-based detection) |
|
|
83
|
+
| `ResultTransformer` | Post-eval result normalization (cursor iteration, `cursorHasMore` extraction) |
|
|
84
|
+
| `DocumentDBServiceProvider` | Evaluation engine ↔ MongoDB driver bridge (leverages `@mongosh` internals) |
|
|
85
|
+
| `HelpProvider` | Help text generation |
|
|
86
|
+
| `types.ts` | Public API types (`ShellEvaluationResult`, `ShellRuntimeOptions`, etc.) |
|
|
87
|
+
|
|
88
|
+
## Origin
|
|
89
|
+
|
|
90
|
+
This package was developed while building features for the [DocumentDB VS Code extension](https://github.com/microsoft/vscode-documentdb), which remains the primary consumer. The runtime is designed to work with any Node.js application that has a `MongoClient` and needs to evaluate shell-style JavaScript against a DocumentDB database.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
[MIT](LICENSE.md)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { HelpProvider } from './HelpProvider';
|
|
2
|
+
import { type ShellEvaluationResult } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Pre-eval command routing for shell input.
|
|
5
|
+
*
|
|
6
|
+
* Intercepts commands that should be handled without going through the
|
|
7
|
+
* @mongosh evaluation pipeline. Handles:
|
|
8
|
+
* - `help` / `help()` → show help text
|
|
9
|
+
* - `exit` / `quit` → signal shell exit
|
|
10
|
+
* - `cls` / `clear` → signal screen clear
|
|
11
|
+
*/
|
|
12
|
+
export declare class CommandInterceptor {
|
|
13
|
+
private readonly _helpProvider;
|
|
14
|
+
/**
|
|
15
|
+
* Matches standalone `help` invocations:
|
|
16
|
+
* - `help` (bare keyword)
|
|
17
|
+
* - `help()` (function call, no arguments)
|
|
18
|
+
* - `` help`...` `` (tagged template literal — any content between backticks)
|
|
19
|
+
*
|
|
20
|
+
* Does NOT match when `help` is part of a larger expression
|
|
21
|
+
* (e.g. `helper()`, `var help = 1`, `help("topic")`).
|
|
22
|
+
*/
|
|
23
|
+
private static readonly HELP_PATTERN;
|
|
24
|
+
/**
|
|
25
|
+
* Matches standalone `exit` or `quit` keywords, with optional parens and trailing semicolon.
|
|
26
|
+
* - `exit`, `quit` (bare keywords)
|
|
27
|
+
* - `exit()`, `quit()` (function call form — common in mongosh)
|
|
28
|
+
* - `exit;`, `quit;`, `exit();`, `quit();` (with semicolon)
|
|
29
|
+
* - ` exit `, ` quit ` (with whitespace — trimmed before matching)
|
|
30
|
+
*
|
|
31
|
+
* Does NOT match:
|
|
32
|
+
* - `exit(0)`, `quit(0)` (function calls with arguments)
|
|
33
|
+
* - `exitFunction()`, `var exit = 1` (substrings)
|
|
34
|
+
* - `db.exit` (property access)
|
|
35
|
+
*/
|
|
36
|
+
private static readonly EXIT_PATTERN;
|
|
37
|
+
/**
|
|
38
|
+
* Matches standalone `cls` or `clear` keywords, with optional trailing semicolon.
|
|
39
|
+
* - `cls`, `clear` (bare keywords)
|
|
40
|
+
* - `cls;`, `clear;` (with semicolon)
|
|
41
|
+
*
|
|
42
|
+
* Does NOT match:
|
|
43
|
+
* - `clear()`, `cls()` (function calls)
|
|
44
|
+
* - `clearInterval()`, `clearTimeout()` (substrings)
|
|
45
|
+
*/
|
|
46
|
+
private static readonly CLEAR_PATTERN;
|
|
47
|
+
constructor(helpProvider?: HelpProvider);
|
|
48
|
+
/**
|
|
49
|
+
* Check if the input is a command that should be intercepted.
|
|
50
|
+
* Returns a result if intercepted, undefined if the input should
|
|
51
|
+
* proceed through normal evaluation.
|
|
52
|
+
*/
|
|
53
|
+
tryIntercept(input: string): ShellEvaluationResult | undefined;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=CommandInterceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandInterceptor.d.ts","sourceRoot":"","sources":["../src/CommandInterceptor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAErD;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAE7C;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAA+B;IAEnE;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAgC;IAEpE;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAuB;gBAEhD,YAAY,CAAC,EAAE,YAAY;IAIvC;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;CA4BjE"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CommandInterceptor = void 0;
|
|
8
|
+
const HelpProvider_1 = require("./HelpProvider");
|
|
9
|
+
/**
|
|
10
|
+
* Pre-eval command routing for shell input.
|
|
11
|
+
*
|
|
12
|
+
* Intercepts commands that should be handled without going through the
|
|
13
|
+
* @mongosh evaluation pipeline. Handles:
|
|
14
|
+
* - `help` / `help()` → show help text
|
|
15
|
+
* - `exit` / `quit` → signal shell exit
|
|
16
|
+
* - `cls` / `clear` → signal screen clear
|
|
17
|
+
*/
|
|
18
|
+
class CommandInterceptor {
|
|
19
|
+
_helpProvider;
|
|
20
|
+
/**
|
|
21
|
+
* Matches standalone `help` invocations:
|
|
22
|
+
* - `help` (bare keyword)
|
|
23
|
+
* - `help()` (function call, no arguments)
|
|
24
|
+
* - `` help`...` `` (tagged template literal — any content between backticks)
|
|
25
|
+
*
|
|
26
|
+
* Does NOT match when `help` is part of a larger expression
|
|
27
|
+
* (e.g. `helper()`, `var help = 1`, `help("topic")`).
|
|
28
|
+
*/
|
|
29
|
+
static HELP_PATTERN = /^help(?:\(\)|\s*`[^]*`)?$/;
|
|
30
|
+
/**
|
|
31
|
+
* Matches standalone `exit` or `quit` keywords, with optional parens and trailing semicolon.
|
|
32
|
+
* - `exit`, `quit` (bare keywords)
|
|
33
|
+
* - `exit()`, `quit()` (function call form — common in mongosh)
|
|
34
|
+
* - `exit;`, `quit;`, `exit();`, `quit();` (with semicolon)
|
|
35
|
+
* - ` exit `, ` quit ` (with whitespace — trimmed before matching)
|
|
36
|
+
*
|
|
37
|
+
* Does NOT match:
|
|
38
|
+
* - `exit(0)`, `quit(0)` (function calls with arguments)
|
|
39
|
+
* - `exitFunction()`, `var exit = 1` (substrings)
|
|
40
|
+
* - `db.exit` (property access)
|
|
41
|
+
*/
|
|
42
|
+
static EXIT_PATTERN = /^(?:exit|quit)(?:\(\))?;?$/;
|
|
43
|
+
/**
|
|
44
|
+
* Matches standalone `cls` or `clear` keywords, with optional trailing semicolon.
|
|
45
|
+
* - `cls`, `clear` (bare keywords)
|
|
46
|
+
* - `cls;`, `clear;` (with semicolon)
|
|
47
|
+
*
|
|
48
|
+
* Does NOT match:
|
|
49
|
+
* - `clear()`, `cls()` (function calls)
|
|
50
|
+
* - `clearInterval()`, `clearTimeout()` (substrings)
|
|
51
|
+
*/
|
|
52
|
+
static CLEAR_PATTERN = /^(?:cls|clear);?$/;
|
|
53
|
+
constructor(helpProvider) {
|
|
54
|
+
this._helpProvider = helpProvider ?? new HelpProvider_1.HelpProvider();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if the input is a command that should be intercepted.
|
|
58
|
+
* Returns a result if intercepted, undefined if the input should
|
|
59
|
+
* proceed through normal evaluation.
|
|
60
|
+
*/
|
|
61
|
+
tryIntercept(input) {
|
|
62
|
+
const trimmed = input.trim();
|
|
63
|
+
// Help command (bare, function call, or tagged template literal)
|
|
64
|
+
if (CommandInterceptor.HELP_PATTERN.test(trimmed)) {
|
|
65
|
+
return this._helpProvider.getHelpResult();
|
|
66
|
+
}
|
|
67
|
+
// Exit / quit — signal shell close
|
|
68
|
+
if (CommandInterceptor.EXIT_PATTERN.test(trimmed)) {
|
|
69
|
+
return {
|
|
70
|
+
type: 'exit',
|
|
71
|
+
printable: '',
|
|
72
|
+
durationMs: 0,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Clear / cls — signal screen clear
|
|
76
|
+
if (CommandInterceptor.CLEAR_PATTERN.test(trimmed)) {
|
|
77
|
+
return {
|
|
78
|
+
type: 'clear',
|
|
79
|
+
printable: '',
|
|
80
|
+
durationMs: 0,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.CommandInterceptor = CommandInterceptor;
|
|
87
|
+
//# sourceMappingURL=CommandInterceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandInterceptor.js","sourceRoot":"","sources":["../src/CommandInterceptor.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iDAA8C;AAG9C;;;;;;;;GAQG;AACH,MAAa,kBAAkB;IACV,aAAa,CAAe;IAE7C;;;;;;;;OAQG;IACK,MAAM,CAAU,YAAY,GAAG,2BAA2B,CAAC;IAEnE;;;;;;;;;;;OAWG;IACK,MAAM,CAAU,YAAY,GAAG,4BAA4B,CAAC;IAEpE;;;;;;;;OAQG;IACK,MAAM,CAAU,aAAa,GAAG,mBAAmB,CAAC;IAE5D,YAAY,YAA2B;QACnC,IAAI,CAAC,aAAa,GAAG,YAAY,IAAI,IAAI,2BAAY,EAAE,CAAC;IAC5D,CAAC;IAED;;;;OAIG;IACH,YAAY,CAAC,KAAa;QACtB,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAE7B,iEAAiE;QACjE,IAAI,kBAAkB,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAChD,OAAO,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC;QAC9C,CAAC;QAED,mCAAmC;QACnC,IAAI,kBAAkB,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAChD,OAAO;gBACH,IAAI,EAAE,MAAM;gBACZ,SAAS,EAAE,EAAE;gBACb,UAAU,EAAE,CAAC;aAChB,CAAC;QACN,CAAC;QAED,oCAAoC;QACpC,IAAI,kBAAkB,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACjD,OAAO;gBACH,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,EAAE;gBACb,UAAU,EAAE,CAAC;aAChB,CAAC;QACN,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;;AA3EL,gDA4EC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandInterceptor.test.d.ts","sourceRoot":"","sources":["../src/CommandInterceptor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const CommandInterceptor_1 = require("./CommandInterceptor");
|
|
8
|
+
describe('CommandInterceptor', () => {
|
|
9
|
+
let interceptor;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
interceptor = new CommandInterceptor_1.CommandInterceptor();
|
|
12
|
+
});
|
|
13
|
+
describe('help command', () => {
|
|
14
|
+
it('intercepts "help"', () => {
|
|
15
|
+
const result = interceptor.tryIntercept('help');
|
|
16
|
+
expect(result).toBeDefined();
|
|
17
|
+
expect(result.type).toBe('Help');
|
|
18
|
+
expect(result.durationMs).toBe(0);
|
|
19
|
+
});
|
|
20
|
+
it('intercepts "help()"', () => {
|
|
21
|
+
const result = interceptor.tryIntercept('help()');
|
|
22
|
+
expect(result).toBeDefined();
|
|
23
|
+
expect(result.type).toBe('Help');
|
|
24
|
+
});
|
|
25
|
+
it('intercepts "help" with leading/trailing whitespace', () => {
|
|
26
|
+
const result = interceptor.tryIntercept(' help ');
|
|
27
|
+
expect(result).toBeDefined();
|
|
28
|
+
expect(result.type).toBe('Help');
|
|
29
|
+
});
|
|
30
|
+
it('intercepts "help()" with leading/trailing whitespace', () => {
|
|
31
|
+
const result = interceptor.tryIntercept(' help() ');
|
|
32
|
+
expect(result).toBeDefined();
|
|
33
|
+
expect(result.type).toBe('Help');
|
|
34
|
+
});
|
|
35
|
+
it('intercepts help with empty tagged template literal', () => {
|
|
36
|
+
const result = interceptor.tryIntercept('help``');
|
|
37
|
+
expect(result).toBeDefined();
|
|
38
|
+
expect(result.type).toBe('Help');
|
|
39
|
+
expect(result.durationMs).toBe(0);
|
|
40
|
+
});
|
|
41
|
+
it('intercepts help with non-empty tagged template literal', () => {
|
|
42
|
+
const result = interceptor.tryIntercept('help`some content`');
|
|
43
|
+
expect(result).toBeDefined();
|
|
44
|
+
expect(result.type).toBe('Help');
|
|
45
|
+
});
|
|
46
|
+
it('intercepts help with tagged template literal with whitespace before backtick', () => {
|
|
47
|
+
const result = interceptor.tryIntercept('help `text`');
|
|
48
|
+
expect(result).toBeDefined();
|
|
49
|
+
expect(result.type).toBe('Help');
|
|
50
|
+
});
|
|
51
|
+
it('intercepts help tagged template literal with leading/trailing whitespace', () => {
|
|
52
|
+
const result = interceptor.tryIntercept(' help`` ');
|
|
53
|
+
expect(result).toBeDefined();
|
|
54
|
+
expect(result.type).toBe('Help');
|
|
55
|
+
});
|
|
56
|
+
it('does not intercept "help(arg)"', () => {
|
|
57
|
+
const result = interceptor.tryIntercept('help("collections")');
|
|
58
|
+
expect(result).toBeUndefined();
|
|
59
|
+
});
|
|
60
|
+
it('does not intercept code containing "help" as substring', () => {
|
|
61
|
+
expect(interceptor.tryIntercept('var help = 1')).toBeUndefined();
|
|
62
|
+
expect(interceptor.tryIntercept('helper()')).toBeUndefined();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('exit / quit commands', () => {
|
|
66
|
+
it('intercepts "exit"', () => {
|
|
67
|
+
const result = interceptor.tryIntercept('exit');
|
|
68
|
+
expect(result).toBeDefined();
|
|
69
|
+
expect(result.type).toBe('exit');
|
|
70
|
+
expect(result.durationMs).toBe(0);
|
|
71
|
+
});
|
|
72
|
+
it('intercepts "quit"', () => {
|
|
73
|
+
const result = interceptor.tryIntercept('quit');
|
|
74
|
+
expect(result).toBeDefined();
|
|
75
|
+
expect(result.type).toBe('exit');
|
|
76
|
+
expect(result.durationMs).toBe(0);
|
|
77
|
+
});
|
|
78
|
+
it('intercepts "exit" with leading/trailing whitespace', () => {
|
|
79
|
+
const result = interceptor.tryIntercept(' exit ');
|
|
80
|
+
expect(result).toBeDefined();
|
|
81
|
+
expect(result.type).toBe('exit');
|
|
82
|
+
});
|
|
83
|
+
it('intercepts "quit" with leading/trailing whitespace', () => {
|
|
84
|
+
const result = interceptor.tryIntercept(' quit ');
|
|
85
|
+
expect(result).toBeDefined();
|
|
86
|
+
expect(result.type).toBe('exit');
|
|
87
|
+
});
|
|
88
|
+
it('intercepts "exit;" with trailing semicolon', () => {
|
|
89
|
+
const result = interceptor.tryIntercept('exit;');
|
|
90
|
+
expect(result).toBeDefined();
|
|
91
|
+
expect(result.type).toBe('exit');
|
|
92
|
+
});
|
|
93
|
+
it('intercepts "quit;" with trailing semicolon', () => {
|
|
94
|
+
const result = interceptor.tryIntercept('quit;');
|
|
95
|
+
expect(result).toBeDefined();
|
|
96
|
+
expect(result.type).toBe('exit');
|
|
97
|
+
});
|
|
98
|
+
it('intercepts "exit()" as exit command', () => {
|
|
99
|
+
const result = interceptor.tryIntercept('exit()');
|
|
100
|
+
expect(result).toBeDefined();
|
|
101
|
+
expect(result.type).toBe('exit');
|
|
102
|
+
});
|
|
103
|
+
it('intercepts "quit()" as exit command', () => {
|
|
104
|
+
const result = interceptor.tryIntercept('quit()');
|
|
105
|
+
expect(result).toBeDefined();
|
|
106
|
+
expect(result.type).toBe('exit');
|
|
107
|
+
});
|
|
108
|
+
it('intercepts "exit();" with trailing semicolon', () => {
|
|
109
|
+
const result = interceptor.tryIntercept('exit();');
|
|
110
|
+
expect(result).toBeDefined();
|
|
111
|
+
expect(result.type).toBe('exit');
|
|
112
|
+
});
|
|
113
|
+
it('intercepts "quit();" with trailing semicolon', () => {
|
|
114
|
+
const result = interceptor.tryIntercept('quit();');
|
|
115
|
+
expect(result).toBeDefined();
|
|
116
|
+
expect(result.type).toBe('exit');
|
|
117
|
+
});
|
|
118
|
+
it('does not intercept "exitFunction()"', () => {
|
|
119
|
+
expect(interceptor.tryIntercept('exitFunction()')).toBeUndefined();
|
|
120
|
+
});
|
|
121
|
+
it('does not intercept "var exit = 1"', () => {
|
|
122
|
+
expect(interceptor.tryIntercept('var exit = 1')).toBeUndefined();
|
|
123
|
+
});
|
|
124
|
+
it('does not intercept "db.exit"', () => {
|
|
125
|
+
expect(interceptor.tryIntercept('db.exit')).toBeUndefined();
|
|
126
|
+
});
|
|
127
|
+
it('does not intercept "process.exit(0)"', () => {
|
|
128
|
+
expect(interceptor.tryIntercept('process.exit(0)')).toBeUndefined();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe('cls / clear commands', () => {
|
|
132
|
+
it('intercepts "cls"', () => {
|
|
133
|
+
const result = interceptor.tryIntercept('cls');
|
|
134
|
+
expect(result).toBeDefined();
|
|
135
|
+
expect(result.type).toBe('clear');
|
|
136
|
+
expect(result.durationMs).toBe(0);
|
|
137
|
+
});
|
|
138
|
+
it('intercepts "clear"', () => {
|
|
139
|
+
const result = interceptor.tryIntercept('clear');
|
|
140
|
+
expect(result).toBeDefined();
|
|
141
|
+
expect(result.type).toBe('clear');
|
|
142
|
+
expect(result.durationMs).toBe(0);
|
|
143
|
+
});
|
|
144
|
+
it('intercepts "cls" with leading/trailing whitespace', () => {
|
|
145
|
+
const result = interceptor.tryIntercept(' cls ');
|
|
146
|
+
expect(result).toBeDefined();
|
|
147
|
+
expect(result.type).toBe('clear');
|
|
148
|
+
});
|
|
149
|
+
it('intercepts "clear" with leading/trailing whitespace', () => {
|
|
150
|
+
const result = interceptor.tryIntercept(' clear ');
|
|
151
|
+
expect(result).toBeDefined();
|
|
152
|
+
expect(result.type).toBe('clear');
|
|
153
|
+
});
|
|
154
|
+
it('intercepts "cls;" with trailing semicolon', () => {
|
|
155
|
+
const result = interceptor.tryIntercept('cls;');
|
|
156
|
+
expect(result).toBeDefined();
|
|
157
|
+
expect(result.type).toBe('clear');
|
|
158
|
+
});
|
|
159
|
+
it('intercepts "clear;" with trailing semicolon', () => {
|
|
160
|
+
const result = interceptor.tryIntercept('clear;');
|
|
161
|
+
expect(result).toBeDefined();
|
|
162
|
+
expect(result.type).toBe('clear');
|
|
163
|
+
});
|
|
164
|
+
it('does not intercept "clear()"', () => {
|
|
165
|
+
expect(interceptor.tryIntercept('clear()')).toBeUndefined();
|
|
166
|
+
});
|
|
167
|
+
it('does not intercept "cls()"', () => {
|
|
168
|
+
expect(interceptor.tryIntercept('cls()')).toBeUndefined();
|
|
169
|
+
});
|
|
170
|
+
it('does not intercept "clearInterval()"', () => {
|
|
171
|
+
expect(interceptor.tryIntercept('clearInterval()')).toBeUndefined();
|
|
172
|
+
});
|
|
173
|
+
it('does not intercept "clearTimeout(timer)"', () => {
|
|
174
|
+
expect(interceptor.tryIntercept('clearTimeout(timer)')).toBeUndefined();
|
|
175
|
+
});
|
|
176
|
+
it('does not intercept "var clear = true"', () => {
|
|
177
|
+
expect(interceptor.tryIntercept('var clear = true')).toBeUndefined();
|
|
178
|
+
});
|
|
179
|
+
it('does not intercept "db.clear"', () => {
|
|
180
|
+
expect(interceptor.tryIntercept('db.clear')).toBeUndefined();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
describe('non-intercepted input', () => {
|
|
184
|
+
it('does not intercept regular code', () => {
|
|
185
|
+
expect(interceptor.tryIntercept('db.users.find({})')).toBeUndefined();
|
|
186
|
+
expect(interceptor.tryIntercept('show dbs')).toBeUndefined();
|
|
187
|
+
expect(interceptor.tryIntercept('use admin')).toBeUndefined();
|
|
188
|
+
});
|
|
189
|
+
it('does not intercept empty input', () => {
|
|
190
|
+
expect(interceptor.tryIntercept('')).toBeUndefined();
|
|
191
|
+
expect(interceptor.tryIntercept(' ')).toBeUndefined();
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=CommandInterceptor.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandInterceptor.test.js","sourceRoot":"","sources":["../src/CommandInterceptor.test.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAEhG,6DAA0D;AAE1D,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAChC,IAAI,WAA+B,CAAC;IAEpC,UAAU,CAAC,GAAG,EAAE;QACZ,WAAW,GAAG,IAAI,uCAAkB,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YACzB,MAAM,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;YAC7B,MAAM,CAAC,MAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAClC,MAAM,CAAC,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C,CAAC;QAEH,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;YACrC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;QACnC,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;YACvC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;YACtE,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;YAC7D,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QAClE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;YACtC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;YACrD,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QAC5D,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NodeDriverServiceProvider } from '@mongosh/service-provider-node-driver';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { type MongoClient } from 'mongodb';
|
|
4
|
+
/**
|
|
5
|
+
* Result of creating a DocumentDB service provider.
|
|
6
|
+
* Returns both the provider and the event bus (needed by ShellInstanceState).
|
|
7
|
+
*/
|
|
8
|
+
export interface ServiceProviderWithBus {
|
|
9
|
+
readonly serviceProvider: DocumentDBServiceProvider;
|
|
10
|
+
readonly bus: EventEmitter;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* DocumentDB-specific service provider for @mongosh.
|
|
14
|
+
*
|
|
15
|
+
* Currently a thin wrapper around `NodeDriverServiceProvider` that configures
|
|
16
|
+
* DocumentDB-specific product metadata.
|
|
17
|
+
*
|
|
18
|
+
* Future extensions:
|
|
19
|
+
* - Block unsupported operations (e.g. `watch()`, `createChangeStream()`)
|
|
20
|
+
* with clear "Not supported by DocumentDB" error messages
|
|
21
|
+
* - Override methods to provide DocumentDB-specific behavior
|
|
22
|
+
*
|
|
23
|
+
* @see future-work.md §"operator-registry.methods" for the planned
|
|
24
|
+
* unsupported-method blocking via a static method registry.
|
|
25
|
+
*/
|
|
26
|
+
export declare class DocumentDBServiceProvider extends NodeDriverServiceProvider {
|
|
27
|
+
/**
|
|
28
|
+
* Create a DocumentDB service provider from an existing MongoClient.
|
|
29
|
+
*
|
|
30
|
+
* Returns both the provider and the shared event bus (needed by
|
|
31
|
+
* `ShellInstanceState` constructor).
|
|
32
|
+
*
|
|
33
|
+
* @param mongoClient - Connected MongoClient instance (caller owns lifecycle)
|
|
34
|
+
* @param productName - Product name for @mongosh metadata
|
|
35
|
+
* @param productDocsLink - Product documentation link for @mongosh metadata
|
|
36
|
+
*/
|
|
37
|
+
static createForDocumentDB(mongoClient: MongoClient, productName?: string, productDocsLink?: string): ServiceProviderWithBus;
|
|
38
|
+
/**
|
|
39
|
+
* Override close() to NOT close the underlying MongoClient.
|
|
40
|
+
*
|
|
41
|
+
* The caller (worker thread) owns the MongoClient lifecycle. The base
|
|
42
|
+
* class's close() calls `mongoClient.close()`, which would break
|
|
43
|
+
* subsequent evaluations in fresh-context mode (playground) where
|
|
44
|
+
* `ShellInstanceState.close()` cascades through the service provider.
|
|
45
|
+
*/
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=DocumentDBServiceProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentDBServiceProvider.d.ts","sourceRoot":"","sources":["../src/DocumentDBServiceProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAK3C;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACnC,QAAQ,CAAC,eAAe,EAAE,yBAAyB,CAAC;IACpD,QAAQ,CAAC,GAAG,EAAE,YAAY,CAAC;CAC9B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,yBAA0B,SAAQ,yBAAyB;IACpE;;;;;;;;;OASG;IACH,MAAM,CAAC,mBAAmB,CACtB,WAAW,EAAE,WAAW,EACxB,WAAW,CAAC,EAAE,MAAM,EACpB,eAAe,CAAC,EAAE,MAAM,GACzB,sBAAsB;IASzB;;;;;;;OAOG;IACY,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAIxC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DocumentDBServiceProvider = void 0;
|
|
8
|
+
const service_provider_node_driver_1 = require("@mongosh/service-provider-node-driver");
|
|
9
|
+
const events_1 = require("events");
|
|
10
|
+
const DEFAULT_PRODUCT_NAME = 'DocumentDB for VS Code';
|
|
11
|
+
const DEFAULT_PRODUCT_DOCS_LINK = 'https://github.com/microsoft/vscode-documentdb';
|
|
12
|
+
/**
|
|
13
|
+
* DocumentDB-specific service provider for @mongosh.
|
|
14
|
+
*
|
|
15
|
+
* Currently a thin wrapper around `NodeDriverServiceProvider` that configures
|
|
16
|
+
* DocumentDB-specific product metadata.
|
|
17
|
+
*
|
|
18
|
+
* Future extensions:
|
|
19
|
+
* - Block unsupported operations (e.g. `watch()`, `createChangeStream()`)
|
|
20
|
+
* with clear "Not supported by DocumentDB" error messages
|
|
21
|
+
* - Override methods to provide DocumentDB-specific behavior
|
|
22
|
+
*
|
|
23
|
+
* @see future-work.md §"operator-registry.methods" for the planned
|
|
24
|
+
* unsupported-method blocking via a static method registry.
|
|
25
|
+
*/
|
|
26
|
+
class DocumentDBServiceProvider extends service_provider_node_driver_1.NodeDriverServiceProvider {
|
|
27
|
+
/**
|
|
28
|
+
* Create a DocumentDB service provider from an existing MongoClient.
|
|
29
|
+
*
|
|
30
|
+
* Returns both the provider and the shared event bus (needed by
|
|
31
|
+
* `ShellInstanceState` constructor).
|
|
32
|
+
*
|
|
33
|
+
* @param mongoClient - Connected MongoClient instance (caller owns lifecycle)
|
|
34
|
+
* @param productName - Product name for @mongosh metadata
|
|
35
|
+
* @param productDocsLink - Product documentation link for @mongosh metadata
|
|
36
|
+
*/
|
|
37
|
+
static createForDocumentDB(mongoClient, productName, productDocsLink) {
|
|
38
|
+
const bus = new events_1.EventEmitter();
|
|
39
|
+
const serviceProvider = new DocumentDBServiceProvider(mongoClient, bus, {
|
|
40
|
+
productDocsLink: productDocsLink ?? DEFAULT_PRODUCT_DOCS_LINK,
|
|
41
|
+
productName: productName ?? DEFAULT_PRODUCT_NAME,
|
|
42
|
+
});
|
|
43
|
+
return { serviceProvider, bus };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Override close() to NOT close the underlying MongoClient.
|
|
47
|
+
*
|
|
48
|
+
* The caller (worker thread) owns the MongoClient lifecycle. The base
|
|
49
|
+
* class's close() calls `mongoClient.close()`, which would break
|
|
50
|
+
* subsequent evaluations in fresh-context mode (playground) where
|
|
51
|
+
* `ShellInstanceState.close()` cascades through the service provider.
|
|
52
|
+
*/
|
|
53
|
+
async close() {
|
|
54
|
+
// Intentionally empty — the MongoClient is owned by the worker thread
|
|
55
|
+
// and will be closed when the worker shuts down.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.DocumentDBServiceProvider = DocumentDBServiceProvider;
|
|
59
|
+
//# sourceMappingURL=DocumentDBServiceProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DocumentDBServiceProvider.js","sourceRoot":"","sources":["../src/DocumentDBServiceProvider.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,wFAAkF;AAClF,mCAAsC;AAGtC,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AACtD,MAAM,yBAAyB,GAAG,gDAAgD,CAAC;AAWnF;;;;;;;;;;;;;GAaG;AACH,MAAa,yBAA0B,SAAQ,wDAAyB;IACpE;;;;;;;;;OASG;IACH,MAAM,CAAC,mBAAmB,CACtB,WAAwB,EACxB,WAAoB,EACpB,eAAwB;QAExB,MAAM,GAAG,GAAG,IAAI,qBAAY,EAAE,CAAC;QAC/B,MAAM,eAAe,GAAG,IAAI,yBAAyB,CAAC,WAAW,EAAE,GAAG,EAAE;YACpE,eAAe,EAAE,eAAe,IAAI,yBAAyB;YAC7D,WAAW,EAAE,WAAW,IAAI,oBAAoB;SACnD,CAAC,CAAC;QACH,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,CAAC;IACpC,CAAC;IAED;;;;;;;OAOG;IACM,KAAK,CAAC,KAAK;QAChB,sEAAsE;QACtE,iDAAiD;IACrD,CAAC;CACJ;AApCD,8DAoCC"}
|