Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/shell-api/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,14 +600,12 @@ export async function setHideIndex(coll: Collection, index: string | Document, h
);
}

export function assertCLI(platform: ReplPlatform): void {
export function assertCLI(platform: ReplPlatform, features: string): void {
if (
platform !== ReplPlatform.CLI
) {
throw new MongoshUnimplementedError(
`new Mongo connection are not supported for current platform: ${
ReplPlatform[platform]
}`,
`${features} are not supported for current platform: ${ReplPlatform[platform]}`,
CommonErrors.NotImplemented
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/shell-api/src/shell-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('ShellApi', () => {
returnsPromise: true,
deprecated: false,
returnType: { type: 'unknown', attributes: {} },
platforms: ALL_PLATFORMS,
platforms: [ ReplPlatform.CLI ],
topologies: ALL_TOPOLOGIES,
serverVersions: ALL_SERVER_VERSIONS
});
Expand Down Expand Up @@ -516,7 +516,7 @@ describe('ShellApi', () => {
expect.fail('missed exception');
} catch (e) {
// We should be getting an exception because we’re not actually exiting.
expect(e.message).to.contain('exit not supported for current platform');
expect(e.message).to.contain('onExit listener returned');
}
expect(evaluationListener.onExit).to.have.been.calledWith();
});
Expand Down
18 changes: 9 additions & 9 deletions packages/shell-api/src/shell-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CommandResult, CursorIterationResult } from './result';
import ShellInternalState from './shell-internal-state';
import { assertArgsDefined, assertCLI } from './helpers';
import { DEFAULT_DB, ReplPlatform } from '@mongosh/service-provider-core';
import { CommonErrors, MongoshUnimplementedError } from '@mongosh/errors';
import { CommonErrors, MongoshUnimplementedError, MongoshInternalError } from '@mongosh/errors';
import { DBQuery } from './deprecated';
import { promisify } from 'util';
import { ClientSideFieldLevelEncryptionOptions } from './field-level-encryption';
Expand Down Expand Up @@ -46,27 +46,27 @@ export default class ShellApi extends ShellApiClass {

@directShellCommand
@returnsPromise
async exit(): Promise<void> {
@platforms([ ReplPlatform.CLI ] )
async exit(): Promise<never> {
assertCLI(this.internalState.initialServiceProvider.platform, 'the exit/quit commands');
await this.internalState.close(true);
// This should never actually return.
await this.internalState.evaluationListener.onExit?.();
throw new MongoshUnimplementedError(
`exit not supported for current platform: ${ReplPlatform[this.internalState.initialServiceProvider.platform]}`,
CommonErrors.NotImplemented
);
throw new MongoshInternalError('.onExit listener returned');
}

@directShellCommand
@returnsPromise
async quit(): Promise<void> {
@platforms([ ReplPlatform.CLI ] )
async quit(): Promise<never> {
return await this.exit();
}

@returnsPromise
@returnType('Mongo')
@platforms([ ReplPlatform.CLI ] )
public async Mongo(uri?: string, options?: ClientSideFieldLevelEncryptionOptions): Promise<Mongo> {
assertCLI(this.internalState.initialServiceProvider.platform);
assertCLI(this.internalState.initialServiceProvider.platform, 'new Mongo connections');
const mongo = new Mongo(this.internalState, uri, options);
await mongo.connect();
this.internalState.mongos.push(mongo);
Expand All @@ -78,7 +78,7 @@ export default class ShellApi extends ShellApiClass {
@platforms([ ReplPlatform.CLI ] )
async connect(uri: string, user?: string, pwd?: string): Promise<Database> {
assertArgsDefined(uri);
assertCLI(this.internalState.initialServiceProvider.platform);
assertCLI(this.internalState.initialServiceProvider.platform, 'new Mongo connections');
const mongo = new Mongo(this.internalState, uri);
await mongo.connect(user, pwd);
this.internalState.mongos.push(mongo);
Expand Down