@mongosh/node-runtime-worker-thread 1.1.9 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mongosh/node-runtime-worker-thread",
3
- "version": "1.1.9",
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,11 +28,11 @@
28
28
  "prepublish": "npm run webpack-build"
29
29
  },
30
30
  "devDependencies": {
31
- "@mongosh/browser-runtime-core": "1.1.9",
32
- "@mongosh/browser-runtime-electron": "1.1.9",
33
- "@mongosh/service-provider-core": "1.1.9",
34
- "@mongosh/service-provider-server": "1.1.9",
35
- "@mongosh/types": "1.1.9",
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
36
  "bson": "^4.6.1",
37
37
  "mocha": "^7.1.2",
38
38
  "postmsg-rpc": "^2.4.0",
@@ -44,5 +44,5 @@
44
44
  "dependencies": {
45
45
  "interruptor": "^1.0.1"
46
46
  },
47
- "gitHead": "1a200600554f6aa59ec10aaedb915f67771eb7fd"
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
- ['onPrint', 'onPrompt', 'getConfig', 'setConfig', 'validateConfig', 'listConfigOptions', 'onClearCommand', 'onExit'],
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 { MongoClientOptions } from '@mongosh/service-provider-core';
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: MongoClientOptions;
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: MongoClientOptions = {},
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;
@@ -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 { CompassServiceProvider } from '@mongosh/service-provider-server';
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?: MongoClientOptions,
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: MongoClientOptions = {},
88
+ driverOptions: DevtoolsConnectOptions = {},
86
89
  cliOptions: { nodb?: boolean } = {}
87
90
  ) {
88
91
  // XXX The types here work out fine, and tsc accepts this code