From 9285966e42ded46c3898274e03970c06db934a1d Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Mon, 1 Feb 2021 12:36:45 +0100 Subject: [PATCH 1/2] refactor(service-provider-server): Make connect method return whatever constructor the static method was called on --- packages/service-provider-server/src/cli-service-provider.ts | 3 ++- .../src/compass/compass-service-provider.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/service-provider-server/src/cli-service-provider.ts b/packages/service-provider-server/src/cli-service-provider.ts index c79248f908..def48fc4be 100644 --- a/packages/service-provider-server/src/cli-service-provider.ts +++ b/packages/service-provider-server/src/cli-service-provider.ts @@ -169,6 +169,7 @@ class CliServiceProvider extends ServiceProviderCore implements ServiceProvider * @returns {Promise} The promise with cli service provider. */ static async connect( + this: typeof CliServiceProvider, uri: string, driverOptions: MongoClientOptions = {}, cliOptions: { nodb?: boolean } = {} @@ -183,7 +184,7 @@ class CliServiceProvider extends ServiceProviderCore implements ServiceProvider ) : new MongoClient(connectionString.toString(), clientOptions); - return new CliServiceProvider(mongoClient, clientOptions, connectionString); + return new this(mongoClient, clientOptions, connectionString); } public readonly platform: ReplPlatform; diff --git a/packages/service-provider-server/src/compass/compass-service-provider.ts b/packages/service-provider-server/src/compass/compass-service-provider.ts index 5a8c9b5d84..3178458608 100644 --- a/packages/service-provider-server/src/compass/compass-service-provider.ts +++ b/packages/service-provider-server/src/compass/compass-service-provider.ts @@ -1,6 +1,6 @@ import CliServiceProvider from '../cli-service-provider'; -import { MongoClient, MongoClientOptions } from 'mongodb'; -import { ConnectionString, ReplPlatform } from '@mongosh/service-provider-core'; +import { MongoClient } from 'mongodb'; +import { ConnectionString, ReplPlatform, MongoClientOptions } from '@mongosh/service-provider-core'; interface DataService { client: { From 5e8967334f019b7e66c0367008e185cdf68c091b Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Mon, 1 Feb 2021 12:48:37 +0100 Subject: [PATCH 2/2] refactor(node-runtime-worker-thread): Use Compass service provider to correctly resolve unsupported shell api methods --- .../src/worker-runtime.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/node-runtime-worker-thread/src/worker-runtime.ts b/packages/node-runtime-worker-thread/src/worker-runtime.ts index 4f8e7a6ccd..e0732c43c0 100644 --- a/packages/node-runtime-worker-thread/src/worker-runtime.ts +++ b/packages/node-runtime-worker-thread/src/worker-runtime.ts @@ -8,7 +8,7 @@ import { MongoClientOptions, ServiceProvider } from '@mongosh/service-provider-core'; -import { CliServiceProvider } from '@mongosh/service-provider-server'; +import { CompassServiceProvider } from '@mongosh/service-provider-server'; import { exposeAll, createCaller } from './rpc'; import { serializeEvaluationResult } from './serializer'; @@ -43,8 +43,16 @@ export type WorkerRuntime = Runtime & { }; const workerRuntime: WorkerRuntime = { - async init(uri, driverOptions = {}, cliOptions = {}) { - provider = await CliServiceProvider.connect(uri, driverOptions, cliOptions); + async init( + uri: string, + driverOptions: MongoClientOptions = {}, + cliOptions: { nodb?: boolean } = {} + ) { + provider = await CompassServiceProvider.connect( + uri, + driverOptions, + cliOptions + ); runtime = new ElectronRuntime( provider /** , TODO: `messageBus` support for telemetry in a separate ticket */ );