Skip to content

Commit 9c84ee6

Browse files
authored
refactor(node-runtime-worker-thread): Use Compass service provider to correctly resolve unsupported shell api methods (#594)
* refactor(service-provider-server): Make connect method return whatever constructor the static method was called on * refactor(node-runtime-worker-thread): Use Compass service provider to correctly resolve unsupported shell api methods
1 parent 07adf13 commit 9c84ee6

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/node-runtime-worker-thread/src/worker-runtime.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
MongoClientOptions,
99
ServiceProvider
1010
} from '@mongosh/service-provider-core';
11-
import { CliServiceProvider } from '@mongosh/service-provider-server';
11+
import { CompassServiceProvider } from '@mongosh/service-provider-server';
1212
import { exposeAll, createCaller } from './rpc';
1313
import { serializeEvaluationResult } from './serializer';
1414

@@ -43,8 +43,16 @@ export type WorkerRuntime = Runtime & {
4343
};
4444

4545
const workerRuntime: WorkerRuntime = {
46-
async init(uri, driverOptions = {}, cliOptions = {}) {
47-
provider = await CliServiceProvider.connect(uri, driverOptions, cliOptions);
46+
async init(
47+
uri: string,
48+
driverOptions: MongoClientOptions = {},
49+
cliOptions: { nodb?: boolean } = {}
50+
) {
51+
provider = await CompassServiceProvider.connect(
52+
uri,
53+
driverOptions,
54+
cliOptions
55+
);
4856
runtime = new ElectronRuntime(
4957
provider /** , TODO: `messageBus` support for telemetry in a separate ticket */
5058
);

packages/service-provider-server/src/cli-service-provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class CliServiceProvider extends ServiceProviderCore implements ServiceProvider
169169
* @returns {Promise} The promise with cli service provider.
170170
*/
171171
static async connect(
172+
this: typeof CliServiceProvider,
172173
uri: string,
173174
driverOptions: MongoClientOptions = {},
174175
cliOptions: { nodb?: boolean } = {}
@@ -183,7 +184,7 @@ class CliServiceProvider extends ServiceProviderCore implements ServiceProvider
183184
) :
184185
new MongoClient(connectionString.toString(), clientOptions);
185186

186-
return new CliServiceProvider(mongoClient, clientOptions, connectionString);
187+
return new this(mongoClient, clientOptions, connectionString);
187188
}
188189

189190
public readonly platform: ReplPlatform;

packages/service-provider-server/src/compass/compass-service-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import CliServiceProvider from '../cli-service-provider';
2-
import { MongoClient, MongoClientOptions } from 'mongodb';
3-
import { ConnectionString, ReplPlatform } from '@mongosh/service-provider-core';
2+
import { MongoClient } from 'mongodb';
3+
import { ConnectionString, ReplPlatform, MongoClientOptions } from '@mongosh/service-provider-core';
44

55
interface DataService {
66
client: {

0 commit comments

Comments
 (0)