@mongosh/node-runtime-worker-thread 1.1.7 → 1.2.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/dist/child-process-proxy.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/worker-runtime.d.ts +2 -2
- package/dist/worker-runtime.js +131 -114
- package/package.json +8 -8
- package/src/child-process-evaluation-listener.ts +3 -0
- package/src/child-process-proxy.ts +4 -1
- package/src/index.ts +4 -4
- package/src/worker-runtime.spec.ts +16 -0
- package/src/worker-runtime.ts +9 -6
- package/webpack.config.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongosh/node-runtime-worker-thread",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "MongoDB shell runtime that lives in a worker thread",
|
|
5
5
|
"homepage": "https://github.com/mongodb-js/mongosh",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"prepublish": "npm run webpack-build"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@mongosh/browser-runtime-core": "1.1
|
|
32
|
-
"@mongosh/browser-runtime-electron": "1.1
|
|
33
|
-
"@mongosh/service-provider-core": "1.1
|
|
34
|
-
"@mongosh/service-provider-server": "1.1
|
|
35
|
-
"@mongosh/types": "1.1
|
|
36
|
-
"bson": "^4.6.
|
|
31
|
+
"@mongosh/browser-runtime-core": "1.2.1",
|
|
32
|
+
"@mongosh/browser-runtime-electron": "1.2.1",
|
|
33
|
+
"@mongosh/service-provider-core": "1.2.1",
|
|
34
|
+
"@mongosh/service-provider-server": "1.2.1",
|
|
35
|
+
"@mongosh/types": "1.2.1",
|
|
36
|
+
"bson": "^4.6.1",
|
|
37
37
|
"mocha": "^7.1.2",
|
|
38
38
|
"postmsg-rpc": "^2.4.0",
|
|
39
39
|
"terser-webpack-plugin": "^4.2.3",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"interruptor": "^1.0.1"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "62b1dff4ce48f4dd3706d4fd9ccd4582df403ee3"
|
|
48
48
|
}
|
|
@@ -20,6 +20,9 @@ export class ChildProcessEvaluationListener {
|
|
|
20
20
|
setConfig(key, value) {
|
|
21
21
|
return workerRuntime.evaluationListener?.setConfig?.(key, value) ?? Promise.resolve('ignored');
|
|
22
22
|
},
|
|
23
|
+
resetConfig(key) {
|
|
24
|
+
return workerRuntime.evaluationListener?.resetConfig?.(key) ?? Promise.resolve('ignored');
|
|
25
|
+
},
|
|
23
26
|
validateConfig(key, value) {
|
|
24
27
|
return workerRuntime.evaluationListener?.validateConfig?.(key, value) ?? Promise.resolve(null);
|
|
25
28
|
},
|
|
@@ -95,7 +95,10 @@ exposeAll(worker, process);
|
|
|
95
95
|
|
|
96
96
|
const evaluationListener = Object.assign(
|
|
97
97
|
createCaller(
|
|
98
|
-
[
|
|
98
|
+
[
|
|
99
|
+
'onPrint', 'onPrompt', 'getConfig', 'setConfig', 'resetConfig',
|
|
100
|
+
'validateConfig', 'listConfigOptions', 'onClearCommand', 'onExit'
|
|
101
|
+
],
|
|
99
102
|
process
|
|
100
103
|
),
|
|
101
104
|
{
|
package/src/index.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/* ^^^ we test the dist directly, so isntanbul can't calculate the coverage correctly */
|
|
3
3
|
|
|
4
4
|
import { ChildProcess, spawn, SpawnOptionsWithoutStdio } from 'child_process';
|
|
5
|
-
import {
|
|
5
|
+
import type { DevtoolsConnectOptions } from '@mongosh/service-provider-server';
|
|
6
6
|
import {
|
|
7
7
|
Runtime,
|
|
8
8
|
RuntimeEvaluationListener,
|
|
9
9
|
RuntimeEvaluationResult
|
|
10
10
|
} from '@mongosh/browser-runtime-core';
|
|
11
|
-
import { MongoshBus } from '@mongosh/types';
|
|
11
|
+
import type { MongoshBus } from '@mongosh/types';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { EventEmitter, once } from 'events';
|
|
14
14
|
import { kill } from './spawn-child-from-source';
|
|
@@ -48,7 +48,7 @@ function parseStderrToError(str: string): Error | null {
|
|
|
48
48
|
class WorkerRuntime implements Runtime {
|
|
49
49
|
private initOptions: {
|
|
50
50
|
uri: string;
|
|
51
|
-
driverOptions:
|
|
51
|
+
driverOptions: DevtoolsConnectOptions;
|
|
52
52
|
cliOptions: { nodb?: boolean };
|
|
53
53
|
spawnOptions: SpawnOptionsWithoutStdio;
|
|
54
54
|
};
|
|
@@ -74,7 +74,7 @@ class WorkerRuntime implements Runtime {
|
|
|
74
74
|
|
|
75
75
|
constructor(
|
|
76
76
|
uri: string,
|
|
77
|
-
driverOptions:
|
|
77
|
+
driverOptions: DevtoolsConnectOptions = {},
|
|
78
78
|
cliOptions: { nodb?: boolean } = {},
|
|
79
79
|
spawnOptions: SpawnOptionsWithoutStdio = {},
|
|
80
80
|
eventEmitter: MongoshBus = new EventEmitter()
|
|
@@ -495,6 +495,7 @@ describe('worker', () => {
|
|
|
495
495
|
},
|
|
496
496
|
getConfig() {},
|
|
497
497
|
setConfig() {},
|
|
498
|
+
resetConfig() {},
|
|
498
499
|
validateConfig() {},
|
|
499
500
|
listConfigOptions() { return ['displayBatchSize']; },
|
|
500
501
|
onRunInterruptible() {}
|
|
@@ -504,6 +505,7 @@ describe('worker', () => {
|
|
|
504
505
|
spySandbox.spy(evalListener, 'onPrompt');
|
|
505
506
|
spySandbox.spy(evalListener, 'getConfig');
|
|
506
507
|
spySandbox.spy(evalListener, 'setConfig');
|
|
508
|
+
spySandbox.spy(evalListener, 'resetConfig');
|
|
507
509
|
spySandbox.spy(evalListener, 'validateConfig');
|
|
508
510
|
spySandbox.spy(evalListener, 'listConfigOptions');
|
|
509
511
|
spySandbox.spy(evalListener, 'onRunInterruptible');
|
|
@@ -582,6 +584,20 @@ describe('worker', () => {
|
|
|
582
584
|
});
|
|
583
585
|
});
|
|
584
586
|
|
|
587
|
+
describe('resetConfig', () => {
|
|
588
|
+
it('should be called when shell evaluates `config.reset()`', async() => {
|
|
589
|
+
const { init, evaluate } = caller;
|
|
590
|
+
const evalListener = createSpiedEvaluationListener();
|
|
591
|
+
|
|
592
|
+
exposed = exposeAll(evalListener, worker);
|
|
593
|
+
|
|
594
|
+
await init('mongodb://nodb/', {}, { nodb: true });
|
|
595
|
+
|
|
596
|
+
await evaluate('config.reset("displayBatchSize")');
|
|
597
|
+
expect(evalListener.resetConfig).to.have.been.calledWith('displayBatchSize');
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
|
|
585
601
|
describe('listConfigOptions', () => {
|
|
586
602
|
it('should be called when shell evaluates `config[asPrintable]`', async() => {
|
|
587
603
|
const { init, evaluate } = caller;
|
package/src/worker-runtime.ts
CHANGED
|
@@ -8,14 +8,16 @@ import {
|
|
|
8
8
|
RuntimeEvaluationResult
|
|
9
9
|
} from '@mongosh/browser-runtime-core';
|
|
10
10
|
import { ElectronRuntime } from '@mongosh/browser-runtime-electron';
|
|
11
|
-
import {
|
|
12
|
-
MongoClientOptions,
|
|
11
|
+
import type {
|
|
13
12
|
ServiceProvider
|
|
14
13
|
} from '@mongosh/service-provider-core';
|
|
15
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
CompassServiceProvider,
|
|
16
|
+
DevtoolsConnectOptions
|
|
17
|
+
} from '@mongosh/service-provider-server';
|
|
16
18
|
import { exposeAll, createCaller } from './rpc';
|
|
17
19
|
import { serializeEvaluationResult } from './serializer';
|
|
18
|
-
import { MongoshBus } from '@mongosh/types';
|
|
20
|
+
import type { MongoshBus } from '@mongosh/types';
|
|
19
21
|
import { Lock, UNLOCKED } from './lock';
|
|
20
22
|
import { runInterruptible, InterruptHandle } from 'interruptor';
|
|
21
23
|
|
|
@@ -48,6 +50,7 @@ const evaluationListener = createCaller<WorkerRuntimeEvaluationListener>(
|
|
|
48
50
|
'onPrompt',
|
|
49
51
|
'getConfig',
|
|
50
52
|
'setConfig',
|
|
53
|
+
'resetConfig',
|
|
51
54
|
'validateConfig',
|
|
52
55
|
'listConfigOptions',
|
|
53
56
|
'onClearCommand',
|
|
@@ -72,7 +75,7 @@ const messageBus: MongoshBus = Object.assign(
|
|
|
72
75
|
export type WorkerRuntime = Runtime & {
|
|
73
76
|
init(
|
|
74
77
|
uri: string,
|
|
75
|
-
driverOptions?:
|
|
78
|
+
driverOptions?: DevtoolsConnectOptions,
|
|
76
79
|
cliOptions?: { nodb?: boolean }
|
|
77
80
|
): Promise<void>;
|
|
78
81
|
|
|
@@ -82,7 +85,7 @@ export type WorkerRuntime = Runtime & {
|
|
|
82
85
|
const workerRuntime: WorkerRuntime = {
|
|
83
86
|
async init(
|
|
84
87
|
uri: string,
|
|
85
|
-
driverOptions:
|
|
88
|
+
driverOptions: DevtoolsConnectOptions = {},
|
|
86
89
|
cliOptions: { nodb?: boolean } = {}
|
|
87
90
|
) {
|
|
88
91
|
// XXX The types here work out fine, and tsc accepts this code
|
package/webpack.config.js
CHANGED
|
@@ -42,7 +42,8 @@ const config = {
|
|
|
42
42
|
'mongodb-client-encryption': 'commonjs2 mongodb-client-encryption',
|
|
43
43
|
kerberos: 'commonjs2 kerberos',
|
|
44
44
|
snappy: 'commonjs2 snappy',
|
|
45
|
-
interruptor: 'commonjs2 interruptor'
|
|
45
|
+
interruptor: 'commonjs2 interruptor',
|
|
46
|
+
'os-dns-native': 'commonjs2 os-dns-native',
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
|