@@ -6,54 +6,23 @@ import { MongoClientOptions } from '@mongosh/service-provider-core';
6
6
import { Runtime } from '@mongosh/browser-runtime-core' ;
7
7
import { EvaluationListener } from '@mongosh/shell-evaluator' ;
8
8
import spawnChildFromSource , { kill } from './spawn-child-from-source' ;
9
- import { Caller , createCaller , exposeAll , WithClose } from './rpc' ;
9
+ import { Caller , createCaller } from './rpc' ;
10
+ import { ChildProcessEvaluationListener } from './child-process-evaluation-listener' ;
10
11
import type { WorkerRuntime as WorkerThreadWorkerRuntime } from './worker-runtime' ;
11
12
import childProcessProxySrc from 'inline-entry-loader!./child-process-proxy' ;
12
13
13
14
type ChildProcessRuntime = Caller < WorkerThreadWorkerRuntime > ;
14
-
15
- class WorkerEvaluationListener {
16
- exposedListener : WithClose < EvaluationListener > ;
17
-
18
- constructor ( workerRuntime : WorkerRuntime , childProcess : ChildProcess ) {
19
- this . exposedListener = exposeAll < EvaluationListener > (
20
- {
21
- onPrompt ( question , type ) {
22
- return (
23
- workerRuntime . evaluationListener ?. onPrompt ?.( question , type ) ?? ''
24
- ) ;
25
- } ,
26
- onPrint ( values ) {
27
- return workerRuntime . evaluationListener ?. onPrint ?.( values ) ;
28
- } ,
29
- toggleTelemetry ( enabled ) {
30
- return workerRuntime . evaluationListener ?. toggleTelemetry ?.( enabled ) ;
31
- } ,
32
- onClearCommand ( ) {
33
- return workerRuntime . evaluationListener ?. onClearCommand ?.( ) ;
34
- } ,
35
- onExit ( ) {
36
- return (
37
- workerRuntime . evaluationListener ?. onExit ?.( ) ??
38
- ( Promise . resolve ( ) as Promise < never > )
39
- ) ;
40
- }
41
- } ,
42
- childProcess
43
- ) ;
44
- }
45
- }
46
-
47
15
class WorkerRuntime implements Runtime {
48
16
private initOptions : {
49
17
uri : string ;
50
18
driverOptions : MongoClientOptions ;
51
19
cliOptions : { nodb ?: boolean } ;
20
+ spawnOptions : SpawnOptionsWithoutStdio ;
52
21
} ;
53
22
54
23
evaluationListener : EvaluationListener | null = null ;
55
24
56
- private childProcessEvaluationListener ! : WorkerEvaluationListener ;
25
+ private childProcessEvaluationListener ! : ChildProcessEvaluationListener ;
57
26
58
27
private childProcess ! : ChildProcess ;
59
28
@@ -64,27 +33,31 @@ class WorkerRuntime implements Runtime {
64
33
constructor (
65
34
uri : string ,
66
35
driverOptions : MongoClientOptions = { } ,
67
- cliOptions : { nodb ?: boolean } = { }
36
+ cliOptions : { nodb ?: boolean } = { } ,
37
+ spawnOptions : SpawnOptionsWithoutStdio = { }
68
38
) {
69
- this . initOptions = { uri, driverOptions, cliOptions } ;
39
+ this . initOptions = { uri, driverOptions, cliOptions, spawnOptions } ;
70
40
this . initWorkerPromise = this . initWorker ( ) ;
71
41
}
72
42
73
43
private async initWorker ( ) {
74
- this . childProcess = await spawnChildFromSource ( childProcessProxySrc ) ;
44
+ const { uri, driverOptions, cliOptions, spawnOptions } = this . initOptions ;
45
+
46
+ this . childProcess = await spawnChildFromSource (
47
+ childProcessProxySrc ,
48
+ spawnOptions
49
+ ) ;
75
50
76
51
this . childProcessRuntime = createCaller (
77
52
[ 'init' , 'evaluate' , 'getCompletions' , 'setEvaluationListener' ] ,
78
53
this . childProcess
79
54
) ;
80
55
81
- this . childProcessEvaluationListener = new WorkerEvaluationListener (
56
+ this . childProcessEvaluationListener = new ChildProcessEvaluationListener (
82
57
this ,
83
58
this . childProcess
84
59
) ;
85
60
86
- const { uri, driverOptions, cliOptions } = this . initOptions ;
87
-
88
61
await this . childProcessRuntime . init ( uri , driverOptions , cliOptions ) ;
89
62
}
90
63
0 commit comments