Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mongosh/service-provider-server

Package Overview
Dependencies
Maintainers
7
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mongosh/service-provider-server - npm Package Compare versions

Comparing version 0.0.1-alpha.12 to 0.0.1-alpha.13

lib/test-implementation.integration.d.ts

69

lib/cli-service-provider.d.ts
import { MongoClient } from 'mongodb';
import { ServiceProvider, Document, Cursor, Result, BulkWriteResult } from '@mongosh/service-provider-core';
import { ServiceProvider, Document, Cursor, Result, BulkWriteResult, DatabaseOptions, WriteConcern, CommandOptions } from '@mongosh/service-provider-core';
import NodeOptions from './node/node-options';

@@ -12,37 +12,42 @@ declare type DropDatabaseResult = {

constructor(mongoClient: MongoClient);
convertToCapped(database: string, collection: string, size: number): Promise<any>;
renameCollection(database: string, oldName: string, newName: string, options?: Document, dbOptions?: DatabaseOptions): Promise<any>;
findAndModify(database: string, collection: string, query: Document, sort: any[] | Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<any>;
convertToCapped(database: string, collection: string, size: number, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<any>;
private db;
aggregate(database: string, collection: string, pipeline?: Document[], options?: Document, dbOptions?: Document): Cursor;
aggregateDb(database: string, pipeline?: Document[], options?: Document, dbOptions?: Document): Cursor;
bulkWrite(database: string, collection: string, requests: any, options?: Document, dbOptions?: Document): Promise<BulkWriteResult>;
aggregate(database: string, collection: string, pipeline?: Document[], options?: Document, dbOptions?: DatabaseOptions): Cursor;
aggregateDb(database: string, pipeline?: Document[], options?: Document, dbOptions?: DatabaseOptions): Cursor;
bulkWrite(database: string, collection: string, requests: any, options?: Document, dbOptions?: DatabaseOptions): Promise<BulkWriteResult>;
close(force: boolean): Promise<void>;
count(database: string, collection: string, query?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
countDocuments(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
deleteMany(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
deleteOne(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
distinct(database: string, collection: string, fieldName: string, filter?: Document, options?: Document, dbOptions?: Document): Promise<any>;
estimatedDocumentCount(database: string, collection: string, options?: Document, dbOptions?: Document): Promise<Result>;
find(database: string, collection: string, filter?: Document, options?: Document): Cursor;
findOneAndDelete(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
findOneAndReplace(database: string, collection: string, filter?: Document, replacement?: Document, options?: Document): Promise<Result>;
findOneAndUpdate(database: string, collection: string, filter?: Document, update?: Document, options?: Document): Promise<Result>;
insertMany(database: string, collection: string, docs?: Document[], options?: Document, dbOptions?: Document): Promise<Result>;
insertOne(database: string, collection: string, doc?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
isCapped(database: string, collection: string): Promise<Result>;
remove(database: string, collection: string, query?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
save(database: string, collection: string, doc: Document, options?: Document, dbOptions?: Document): Promise<Result>;
replaceOne(database: string, collection: string, filter?: Document, replacement?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
runCommand(database: string, spec?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
count(database: string, collection: string, query?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
countDocuments(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
deleteMany(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
deleteOne(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
distinct(database: string, collection: string, fieldName: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<any>;
estimatedDocumentCount(database: string, collection: string, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
find(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Cursor;
findOneAndDelete(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
findOneAndReplace(database: string, collection: string, filter?: Document, replacement?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
findOneAndUpdate(database: string, collection: string, filter?: Document, update?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
insertMany(database: string, collection: string, docs?: Document[], options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
insertOne(database: string, collection: string, doc?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
isCapped(database: string, collection: string, dbOptions?: DatabaseOptions): Promise<Result>;
remove(database: string, collection: string, query?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
save(database: string, collection: string, doc: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
replaceOne(database: string, collection: string, filter?: Document, replacement?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
runCommand(database: string, spec?: Document, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<Result>;
listDatabases(database: string): Promise<Result>;
updateMany(database: string, collection: string, filter?: Document, update?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
updateOne(database: string, collection: string, filter?: Document, update?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
getServerVersion(): Promise<string>;
dropDatabase(db: string, writeConcern?: Document): Promise<DropDatabaseResult>;
createIndexes(database: string, collection: string, indexSpecs: Document[], options?: Document, dbOptions?: Document): Promise<Result>;
getIndexes(database: string, collection: string, dbOptions?: Document): Promise<Result>;
dropIndexes(database: string, collection: string, indexes: string | string[] | Document | Document[], options?: Document, dbOptions?: Document): Promise<Result>;
listCollections(database: string, filter?: Document, options?: Document, dbOptions?: Document): Promise<Result>;
stats(database: string, collection: string, options?: Document, dbOptions?: Document): Promise<any>;
reIndex(database: string, collection: string, options?: Document, dbOptions?: Document): Promise<Result>;
updateMany(database: string, collection: string, filter?: Document, update?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
updateOne(database: string, collection: string, filter?: Document, update?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
getTopology(): any;
buildInfo(): Promise<Result>;
getCmdLineOpts(): Promise<Result>;
dropDatabase(db: string, writeConcern?: WriteConcern): Promise<DropDatabaseResult>;
createIndexes(database: string, collection: string, indexSpecs: Document[], options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
getIndexes(database: string, collection: string, dbOptions?: DatabaseOptions): Promise<Result>;
dropIndexes(database: string, collection: string, indexes: string | string[] | Document | Document[], options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<Result>;
listCollections(database: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
stats(database: string, collection: string, options?: Document, dbOptions?: DatabaseOptions): Promise<any>;
reIndex(database: string, collection: string, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<Result>;
dropCollection(database: string, collection: string, dbOptions?: DatabaseOptions): Promise<boolean>;
}
export default CliServiceProvider;

@@ -79,4 +79,27 @@ "use strict";

};
CliServiceProvider.prototype.convertToCapped = function (database, collection, size) {
CliServiceProvider.prototype.renameCollection = function (database, oldName, newName, options, dbOptions) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.db(database, dbOptions)
.renameCollection(oldName, newName, options)];
case 1: return [2, _a.sent()];
}
});
});
};
CliServiceProvider.prototype.findAndModify = function (database, collection, query, sort, update, options, dbOptions) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.db(database, dbOptions)
.collection(collection)
.findAndModify(query, sort, update, options)];
case 1: return [2, _a.sent()];
}
});
});
};
CliServiceProvider.prototype.convertToCapped = function (database, collection, size, options, dbOptions) {
return __awaiter(this, void 0, void 0, function () {
var result;

@@ -88,3 +111,3 @@ return __generator(this, function (_a) {

size: size
}, {})];
}, options, dbOptions)];
case 1:

@@ -101,7 +124,4 @@ result = _a.sent();

CliServiceProvider.prototype.db = function (name, options) {
if (options === void 0) { options = {}; }
if (Object.keys(options).length !== 0) {
return this.mongoClient.db(name, options);
}
return this.mongoClient.db(name);
var optionsWithForceNewInstace = __assign(__assign({}, options), { returnNonCachedInstance: true });
return this.mongoClient.db(name, optionsWithForceNewInstace);
};

@@ -111,4 +131,3 @@ CliServiceProvider.prototype.aggregate = function (database, collection, pipeline, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return new node_cursor_1.default(this.db(database)
return new node_cursor_1.default(this.db(database, dbOptions)
.collection(collection)

@@ -120,3 +139,2 @@ .aggregate(pipeline, options));

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
var db = this.db(database, dbOptions);

@@ -127,3 +145,2 @@ return new node_cursor_1.default(db.aggregate(pipeline, options));

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions)

@@ -139,4 +156,5 @@ .collection(collection)

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).count(query);
return this.db(database, dbOptions)
.collection(collection)
.count(query, options);
};

@@ -146,5 +164,5 @@ CliServiceProvider.prototype.countDocuments = function (database, collection, filter, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
countDocuments(filter, options);
return this.db(database, dbOptions)
.collection(collection)
.countDocuments(filter, options);
};

@@ -154,5 +172,5 @@ CliServiceProvider.prototype.deleteMany = function (database, collection, filter, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
deleteMany(filter, options);
return this.db(database, dbOptions)
.collection(collection)
.deleteMany(filter, options);
};

@@ -162,5 +180,5 @@ CliServiceProvider.prototype.deleteOne = function (database, collection, filter, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
deleteOne(filter, options);
return this.db(database, dbOptions)
.collection(collection)
.deleteOne(filter, options);
};

@@ -170,3 +188,2 @@ CliServiceProvider.prototype.distinct = function (database, collection, fieldName, filter, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions)

@@ -178,7 +195,7 @@ .collection(collection)

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
estimatedDocumentCount(options);
return this.db(database, dbOptions)
.collection(collection)
.estimatedDocumentCount(options);
};
CliServiceProvider.prototype.find = function (database, collection, filter, options) {
CliServiceProvider.prototype.find = function (database, collection, filter, options, dbOptions) {
if (filter === void 0) { filter = {}; }

@@ -196,3 +213,5 @@ if (options === void 0) { options = {}; }

}
return new node_cursor_1.default(this.db(database).collection(collection).find(filter, options));
return new node_cursor_1.default(this.db(database, dbOptions)
.collection(collection)
.find(filter, options));
};

@@ -202,7 +221,7 @@ CliServiceProvider.prototype.findOneAndDelete = function (database, collection, filter, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
return this.db(database, dbOptions)
.collection(collection).
findOneAndDelete(filter, options);
};
CliServiceProvider.prototype.findOneAndReplace = function (database, collection, filter, replacement, options) {
CliServiceProvider.prototype.findOneAndReplace = function (database, collection, filter, replacement, options, dbOptions) {
if (filter === void 0) { filter = {}; }

@@ -216,6 +235,5 @@ if (replacement === void 0) { replacement = {}; }

}
return this.db(database).collection(collection).
findOneAndReplace(filter, replacement, findOneAndReplaceOptions);
return this.db(database, dbOptions).collection(collection).findOneAndReplace(filter, replacement, findOneAndReplaceOptions);
};
CliServiceProvider.prototype.findOneAndUpdate = function (database, collection, filter, update, options) {
CliServiceProvider.prototype.findOneAndUpdate = function (database, collection, filter, update, options, dbOptions) {
if (filter === void 0) { filter = {}; }

@@ -229,4 +247,5 @@ if (update === void 0) { update = {}; }

}
return this.db(database).collection(collection).
findOneAndUpdate(filter, update, findOneAndUpdateOptions);
return this.db(database, dbOptions)
.collection(collection)
.findOneAndUpdate(filter, update, findOneAndUpdateOptions);
};

@@ -236,5 +255,5 @@ CliServiceProvider.prototype.insertMany = function (database, collection, docs, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
insertMany(docs, options);
return this.db(database, dbOptions)
.collection(collection)
.insertMany(docs, options);
};

@@ -244,8 +263,8 @@ CliServiceProvider.prototype.insertOne = function (database, collection, doc, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
insertOne(doc, options);
return this.db(database, dbOptions)
.collection(collection)
.insertOne(doc, options);
};
CliServiceProvider.prototype.isCapped = function (database, collection) {
return this.db(database).collection(collection).isCapped();
CliServiceProvider.prototype.isCapped = function (database, collection, dbOptions) {
return this.db(database, dbOptions).collection(collection).isCapped();
};

@@ -255,9 +274,8 @@ CliServiceProvider.prototype.remove = function (database, collection, query, options, dbOptions) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
remove(query, options);
return this.db(database, dbOptions)
.collection(collection)
.remove(query, options);
};
CliServiceProvider.prototype.save = function (database, collection, doc, options, dbOptions) {
if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).

@@ -270,11 +288,10 @@ save(doc, options);

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
replaceOne(filter, replacement, options);
return this.db(database, dbOptions)
.collection(collection)
.replaceOne(filter, replacement, options);
};
CliServiceProvider.prototype.runCommand = function (database, spec, options, dbOptions) {
if (spec === void 0) { spec = {}; }
if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).command(spec, options);
var db = this.db(database, dbOptions);
return db.command(spec, options);
};

@@ -288,12 +305,9 @@ CliServiceProvider.prototype.listDatabases = function (database) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.db(database, dbOptions).collection(collection).
updateMany(filter, update, options)];
case 1:
result = _a.sent();
return [2, result];
case 0: return [4, this.db(database, dbOptions)
.collection(collection)
.updateMany(filter, update, options)];
case 1: return [2, _a.sent()];
}

@@ -307,7 +321,10 @@ });

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return this.db(database, dbOptions).collection(collection).
updateOne(filter, update, options);
return this.db(database, dbOptions)
.collection(collection)
.updateOne(filter, update, options);
};
CliServiceProvider.prototype.getServerVersion = function () {
CliServiceProvider.prototype.getTopology = function () {
return this.mongoClient.topology;
};
CliServiceProvider.prototype.buildInfo = function () {
return __awaiter(this, void 0, void 0, function () {

@@ -322,6 +339,5 @@ var result;

result = _a.sent();
if (!result) {
if (!result)
return [2];
}
return [2, result.version];
return [2, result];
}

@@ -331,2 +347,17 @@ });

};
CliServiceProvider.prototype.getCmdLineOpts = function () {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.runCommand('admin', { getCmdLineOpts: 1 }, {})];
case 1:
result = _a.sent();
if (!result)
return [2];
return [2, result];
}
});
});
};
CliServiceProvider.prototype.dropDatabase = function (db, writeConcern) {

@@ -350,3 +381,2 @@ if (writeConcern === void 0) { writeConcern = {}; }

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -361,3 +391,2 @@ return __generator(this, function (_a) {

CliServiceProvider.prototype.getIndexes = function (database, collection, dbOptions) {
if (dbOptions === void 0) { dbOptions = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -388,3 +417,2 @@ return __generator(this, function (_a) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -401,3 +429,2 @@ return __generator(this, function (_a) {

if (options === void 0) { options = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -426,2 +453,11 @@ return __generator(this, function (_a) {

};
CliServiceProvider.prototype.dropCollection = function (database, collection, dbOptions) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2, this.db(database, dbOptions)
.collection(collection)
.drop()];
});
});
};
return CliServiceProvider;

@@ -428,0 +464,0 @@ }());

import CliServiceProvider from './cli-service-provider';
import { MongoClient } from 'mongodb';
interface DataService {
client: {
client: MongoClient;
};
}
declare class CompassServiceProvider extends CliServiceProvider {
static fromDataService(dataService: DataService): CompassServiceProvider;
}
export default CompassServiceProvider;

@@ -20,2 +20,3 @@ "use strict";

var cli_service_provider_1 = __importDefault(require("./cli-service-provider"));
var mongosh_transport_server_1 = require("mongosh-transport-server");
var CompassServiceProvider = (function (_super) {

@@ -26,6 +27,10 @@ __extends(CompassServiceProvider, _super);

}
CompassServiceProvider.fromDataService = function (dataService) {
var mongoClient = dataService.client.client;
var nodeTransport = new mongosh_transport_server_1.NodeTransport(mongoClient);
return new CompassServiceProvider(nodeTransport);
};
return CompassServiceProvider;
}(cli_service_provider_1.default));
;
exports.default = CompassServiceProvider;
//# sourceMappingURL=compass-service-provider.js.map
{
"name": "@mongosh/service-provider-server",
"version": "0.0.1-alpha.12",
"version": "0.0.1-alpha.13",
"description": "MongoDB Shell Server Service Provider Package",

@@ -42,6 +42,6 @@ "main": "lib/index.js",

"dependencies": {
"@mongosh/service-provider-core": "^0.0.1-alpha.12",
"@mongosh/service-provider-core": "^0.0.1-alpha.13",
"mongodb": "3.5.3 || ^3.5.5"
},
"gitHead": "a1274954b1ebbc654260b5c0ecf61f9f38b178fc"
"gitHead": "cbd3d640a1a089fd677f7136e3d80f70bce7633f"
}

@@ -339,3 +339,3 @@ import CliServiceProvider from './cli-service-provider';

describe('#getServerVersion', () => {
describe('#buildInfo', () => {
context('when the filter is empty', () => {

@@ -345,7 +345,7 @@ let result;

beforeEach(async() => {
result = await serviceProvider.getServerVersion();
result = await serviceProvider.buildInfo();
});
it('returns a semver', () => {
expect(result).to.match(/^\d+.\d+/);
expect(result.version).to.match(/^\d+.\d+/);
});

@@ -352,0 +352,0 @@ });

@@ -194,2 +194,31 @@ import mongodb, { MongoClient, Db } from 'mongodb';

describe('#findAndModify', () => {
const commandResult = { result: { n: 1, ok: 1 } };
const findMock = sinon.mock().once().withArgs(
{ query: 1 },
{ sort: 1 },
{ update: 1 },
{ options: 1 }
).resolves(commandResult);
beforeEach(() => {
const collectionStub = sinon.createStubInstance(Collection, {
findAndModify: findMock
});
serviceProvider = new CliServiceProvider(createClientStub(collectionStub));
});
it('executes the command against the database', async() => {
const result = await serviceProvider.findAndModify(
'music', 'bands',
{ query: 1 },
{ sort: 1 },
{ update: 1 },
{ options: 1 }
);
expect(result).to.deep.equal(commandResult);
findMock.verify();
});
});
describe('#findOneAndDelete', () => {

@@ -443,3 +472,3 @@ const commandResult = { result: { n: 1, ok: 1 } };

describe('#getServerVersion', () => {
describe('#buildInfo', () => {
let commandMock;

@@ -449,6 +478,13 @@ let dbMock;

const buildInfoResult = {
version: '4.0.0',
gitVersion: 'a4b751dcf51dd249c5865812b390cfd1c0129c30',
javascriptEngine: 'mozjs',
versionArray: [4, 0, 0, 0],
};
beforeEach(() => {
commandMock = sinon.mock()
.withArgs({ buildInfo: 1 }, {})
.resolves({ version: '4.0.0' });
.resolves(buildInfoResult);

@@ -471,4 +507,4 @@ const dbStub = sinon.createStubInstance(Db, {

it('executes the command against the admin database', async() => {
const result = await serviceProvider.getServerVersion();
expect(result).to.deep.equal('4.0.0');
const result = await serviceProvider.buildInfo();
expect(result).to.deep.equal(buildInfoResult);
dbMock.verify();

@@ -479,2 +515,48 @@ commandMock.verify();

describe('#getCmdLineOpts', () => {
let commandMock;
let dbMock;
let clientStub: MongoClient;
const cmdLineOptsResult = {
argv: [
'/opt/mongodb-osx-x86_64-enterprise-3.6.3/bin/mongod',
'--dbpath=/Users/user/testdata'
],
parsed: {
storage: {
dbPath: '/Users/user/testdata'
}
},
ok: 1
};
beforeEach(() => {
commandMock = sinon.mock()
.withArgs({ getCmdLineOpts: 1 }, {})
.resolves(cmdLineOptsResult);
const dbStub = sinon.createStubInstance(Db, {
command: commandMock
});
dbMock = sinon.mock()
.withArgs('admin')
.returns(dbStub);
clientStub = sinon.createStubInstance(MongoClient, {
db: dbMock
});
serviceProvider = new CliServiceProvider(clientStub);
});
it('executes getCmdLineOpts against an admin db', async() => {
const result = await serviceProvider.getCmdLineOpts();
expect(result).to.deep.equal(cmdLineOptsResult);
dbMock.verify();
commandMock.verify();
});
});
describe('#convertToCapped', () => {

@@ -487,3 +569,3 @@ let commandMock;

commandMock = sinon.mock()
.withArgs({ convertToCapped: 'coll1', size: 1000 }, {})
.withArgs({ convertToCapped: 'coll1', size: 1000 })
.resolves({ ok: 1 });

@@ -593,3 +675,3 @@

commandMock = sinon.mock()
.withArgs({ dropIndexes: 'coll1', index: ['index-1'] }, {})
.withArgs({ dropIndexes: 'coll1', index: ['index-1'] })
.resolves({ ok: 1 });

@@ -697,3 +779,3 @@

commandMock = sinon.mock()
.withArgs({ reIndex: 'coll1' }, {})
.withArgs({ reIndex: 'coll1' })
.resolves({ ok: 1 });

@@ -723,2 +805,46 @@

});
describe('#renameCollection', () => {
let commandMock;
let dbMock;
let clientStub: MongoClient;
beforeEach(() => {
commandMock = sinon.mock()
.withArgs(
'coll1',
'newName',
{
dropTarget: true,
session: 1
})
.resolves({ ok: 1 });
const dbStub = sinon.createStubInstance(Db, {
renameCollection: commandMock
});
dbMock = sinon.mock()
.withArgs('db1')
.returns(dbStub);
clientStub = sinon.createStubInstance(MongoClient, {
db: dbMock
});
serviceProvider = new CliServiceProvider(clientStub);
});
it('executes the command against the database', async() => {
const result = await serviceProvider.renameCollection(
'db1',
'coll1',
'newName',
{ dropTarget: true, session: 1 }
);
expect(result).to.deep.equal({ ok: 1 });
dbMock.verify();
commandMock.verify();
});
});
});

@@ -1,2 +0,5 @@

import { MongoClient, Db } from 'mongodb';
import {
MongoClient,
Db
} from 'mongodb';

@@ -8,3 +11,6 @@ import {

Result,
BulkWriteResult
BulkWriteResult,
DatabaseOptions,
WriteConcern,
CommandOptions
} from '@mongosh/service-provider-core';

@@ -69,2 +75,26 @@

async renameCollection(
database: string,
oldName: string,
newName: string,
options?: Document,
dbOptions?: DatabaseOptions): Promise<any> {
return await this.db(database, dbOptions)
.renameCollection(oldName, newName, options);
}
async findAndModify(
database: string,
collection: string,
query: Document,
sort: any[] | Document,
update: Document,
options?: Document,
dbOptions?: DatabaseOptions
): Promise<any> {
return await this.db(database, dbOptions)
.collection(collection)
.findAndModify(query, sort, update, options);
}
/**

@@ -80,3 +110,9 @@ * Converts an existing, non-capped collection to

*/
async convertToCapped(database: string, collection: string, size: number): Promise<any> {
async convertToCapped(
database: string,
collection: string,
size: number,
options?: CommandOptions,
dbOptions?: DatabaseOptions
): Promise<any> {
const result: any = await this.runCommand(

@@ -88,3 +124,4 @@ database,

},
{}
options,
dbOptions
);

@@ -107,7 +144,15 @@

*/
private db(name: string, options: Document = {}): Db {
if (Object.keys(options).length !== 0) {
return this.mongoClient.db(name, options);
}
return this.mongoClient.db(name);
private db(name: string, options?: DatabaseOptions): Db {
const optionsWithForceNewInstace: DatabaseOptions = {
...options,
// Without this option any read/write concerns
// and read preferences, as well as other db options
// will only affect one (the first) method call per db.
// Each subsequent calls would use the same options as
// the previous one.
returnNonCachedInstance: true
};
return this.mongoClient.db(name, optionsWithForceNewInstace);
}

@@ -131,8 +176,3 @@

* @param dbOptions
* readConcern:
* level: <String local|majority|linearizable|available>
* writeConcern:
* j: Optional<Boolean>
* w: Optional<Int32 | String>
* wtimeoutMS: Optional<Int64>
* @returns {Cursor} The aggregation cursor.

@@ -145,6 +185,5 @@ */

options: Document = {},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
dbOptions: Document = {}): Cursor {
dbOptions?: DatabaseOptions): Cursor {
return new NodeCursor(
this.db(database)
this.db(database, dbOptions)
.collection(collection)

@@ -168,8 +207,5 @@ .aggregate(pipeline, options)

* @param dbOptions
* readConcern:
* level: <String local|majority|linearizable|available>
* writeConcern:
* j: Optional<Boolean>
* w: Optional<Int32 | String>
* wtimeoutMS: Optional<Int64>
* j: Optional<Boolean>
* w: Optional<Int32 | String>
* wtimeoutMS: Optional<Int64>
* @return {any}

@@ -181,3 +217,3 @@ */

options: Document = {},
dbOptions: Document = {}): Cursor {
dbOptions?: DatabaseOptions): Cursor {
const db: any = (this.db(database, dbOptions) as any);

@@ -195,6 +231,7 @@ return new NodeCursor(db.aggregate(pipeline, options));

* @param dbOptions
* writeConcern:
* j: Optional<Boolean>
* w: Optional<Int32 | String>
* wtimeoutMS: Optional<Int64>
* j: Optional<Boolean>
* w: Optional<Int32 | String>
* wtimeoutMS: Optional<Int64>
* readConcern:
* level: <String local|majority|linearizable|available>
* @return {any}

@@ -207,3 +244,3 @@ */

options: Document = {},
dbOptions: Document = {}): Promise<BulkWriteResult> {
dbOptions?: DatabaseOptions): Promise<BulkWriteResult> {
return this.db(database, dbOptions)

@@ -244,6 +281,7 @@ .collection(collection)

query: Document = {},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).count(query);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.count(query, options);
}

@@ -269,5 +307,6 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
countDocuments(filter, options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.countDocuments(filter, options);
}

@@ -291,5 +330,6 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
deleteMany(filter, options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.deleteMany(filter, options);
}

@@ -313,5 +353,6 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
deleteOne(filter, options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.deleteOne(filter, options);
}

@@ -337,3 +378,3 @@

options: Document = {},
dbOptions: Document = {}): Promise<any> {
dbOptions?: DatabaseOptions): Promise<any> {
return this.db(database, dbOptions)

@@ -358,5 +399,6 @@ .collection(collection)

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
estimatedDocumentCount(options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.estimatedDocumentCount(options);
}

@@ -378,3 +420,4 @@

filter: Document = {},
options: Document = {}): Cursor {
options: Document = {},
dbOptions?: DatabaseOptions): Cursor {
const findOptions: any = { ...options };

@@ -391,3 +434,5 @@ if ('allowPartialResults' in findOptions) {

return new NodeCursor(
this.db(database).collection(collection).find(filter, options)
this.db(database, dbOptions)
.collection(collection)
.find(filter, options)
);

@@ -412,4 +457,5 @@ }

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection).
findOneAndDelete(filter, options);

@@ -434,3 +480,4 @@ }

replacement: Document = {},
options: Document = {}): Promise<Result> {
options: Document = {},
dbOptions?: DatabaseOptions): Promise<Result> {
const findOneAndReplaceOptions: any = { ...options };

@@ -441,4 +488,6 @@ if ('returnDocument' in options) {

}
return (this.db(database).collection(collection) as any).
findOneAndReplace(filter, replacement, findOneAndReplaceOptions);
return (
this.db(database, dbOptions).collection(collection) as any
).findOneAndReplace(filter, replacement, findOneAndReplaceOptions);
}

@@ -462,3 +511,4 @@

update: Document = {},
options: Document = {}): Promise<Result> {
options: Document = {},
dbOptions?: DatabaseOptions): Promise<Result> {
const findOneAndUpdateOptions: any = { ...options };

@@ -469,4 +519,10 @@ if ('returnDocument' in options) {

}
return (this.db(database).collection(collection) as any).
findOneAndUpdate(filter, update, findOneAndUpdateOptions);
return this.db(database, dbOptions)
.collection(collection)
.findOneAndUpdate(
filter,
update,
findOneAndUpdateOptions
);
}

@@ -477,9 +533,9 @@

*
* @param {String} database - The database name.
* @param {String} collection - The collection name.
* @param {Array} docs - The documents.
* @param {Object} options - The insert many options.
* @param {Object} dbOptions - The database options (i.e. readConcern, writeConcern. etc).
* @param {string} database - The database name.
* @param {string} collection - The collection name.
* @param {Document[]} [docs=[]] - The documents.
* @param {Document} [options={}] - options - The insert many options.
* @param {DatabaseOptions} [dbOptions] - The database options.
*
* @returns {Promise} The promise of the result.
* @returns {Promise<Result>}
*/

@@ -491,5 +547,6 @@ insertMany(

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
insertMany(docs, options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.insertMany(docs, options);
}

@@ -513,5 +570,6 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
insertOne(doc, options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.insertOne(doc, options);
}

@@ -528,4 +586,5 @@

database: string,
collection: string): Promise<Result> {
return this.db(database).collection(collection).isCapped();
collection: string,
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions).collection(collection).isCapped();
}

@@ -547,5 +606,6 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
remove(query, options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.remove(query, options);
}

@@ -571,3 +631,3 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions).collection(collection).

@@ -595,5 +655,7 @@ save(doc, options);

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
replaceOne(filter, replacement, options);
dbOptions?: DatabaseOptions
): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.replaceOne(filter, replacement, options);
}

@@ -613,5 +675,10 @@

spec: Document = {},
options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return (this.db(database, dbOptions) as any).command(spec, options as any);
options?: CommandOptions,
dbOptions?: DatabaseOptions
): Promise<Result> {
const db: any = this.db(database, dbOptions);
return db.command(
spec,
options
);
}

@@ -648,7 +715,6 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
const result = await this.db(database, dbOptions).collection(collection).
updateMany(filter, update, options);
return result;
dbOptions?: DatabaseOptions): Promise<Result> {
return await this.db(database, dbOptions)
.collection(collection)
.updateMany(filter, update, options);
}

@@ -674,13 +740,23 @@

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
return this.db(database, dbOptions).collection(collection).
updateOne(filter, update, options);
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)
.collection(collection)
.updateOne(filter, update, options);
}
/**
* Returns the server version.
* Return current topology.
*
* @returns {Promise} The server version.
* @returns {Promise} topology.
*/
async getServerVersion(): Promise<string> {
getTopology(): any {
return this.mongoClient.topology;
}
/**
* Return buildInfo.
*
* @returns {Promise} buildInfo.
*/
async buildInfo(): Promise<Result> {
const result: any = await this.runCommand(

@@ -694,10 +770,23 @@ 'admin',

if (!result) {
return;
}
if (!result) return;
return result.version;
return result;
}
/**
* Return cmdLineOpts.
*
* @returns {Promise} buildInfo.
*/
async getCmdLineOpts(): Promise<Result> {
const result: any = await this.runCommand(
'admin', { getCmdLineOpts: 1 }, {}
);
if (!result) return;
return result;
}
/**
* Drop a database

@@ -712,3 +801,3 @@ *

db: string,
writeConcern: Document = {}
writeConcern: WriteConcern = {}
): Promise<DropDatabaseResult> {

@@ -740,3 +829,3 @@ const nativeResult = await (this.db(db) as any)

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)

@@ -761,3 +850,3 @@ .collection(collection)

collection: string,
dbOptions: Document = {}): Promise<Result> {
dbOptions?: DatabaseOptions): Promise<Result> {
return this.db(database, dbOptions)

@@ -770,10 +859,11 @@ .collection(collection)

/**
* Drop indexes for a collection.
* Drop indexes for a collection
*
* @param {String} database - The db name.
* @param {String} collection - The collection name.
* @param {string|string[]|Object|Object[]} indexes the indexes to be removed.
* @param {Object} options - The command options.
* @param {Object} dbOptions - The database options (i.e. readConcern, writeConcern. etc).
* @return {Promise}
* @param {string} database - the db name.
* @param {string} collection - the collection name.
* @param {(string|string[]|Document|Document[])} indexes - the indexes to be removed.
* @param {CommandOptions} [options] - The command options.
* @param {DatabaseOptions} [dbOptions] - The database options.
*
* @returns {Promise<Result>}
*/

@@ -784,4 +874,4 @@ async dropIndexes(

indexes: string|string[]|Document|Document[],
options?: Document,
dbOptions?: Document): Promise<Result> {
options?: CommandOptions,
dbOptions?: DatabaseOptions): Promise<Result> {
return await this.runCommand(database, {

@@ -808,3 +898,3 @@ dropIndexes: collection,

options: Document = {},
dbOptions: Document = {}): Promise<Result> {
dbOptions?: DatabaseOptions): Promise<Result> {
return await this.db(database, dbOptions).listCollections(

@@ -828,3 +918,3 @@ filter, options

options: Document = {},
dbOptions: Document = {}): Promise<any> {
dbOptions?: DatabaseOptions): Promise<any> {
return await this.db(database, dbOptions)

@@ -836,2 +926,5 @@ .collection(collection)

/**
* TODO: - To keep this as close to driver, since we use runCommand here,
* we should move it to the mapper layer.
*
* Reindex all indexes on the collection.

@@ -848,4 +941,5 @@ *

collection: string,
options?: Document,
dbOptions?: Document): Promise<Result> {
options?: CommandOptions,
dbOptions?: DatabaseOptions
): Promise<Result> {
return await this.runCommand(database, {

@@ -855,4 +949,23 @@ reIndex: collection

}
/**
* Drops a the collection.
*
* @param {String} database - The db name.
* @param {String} collection - The collection name.
* @param {Object} dbOptions - The database options (i.e. readConcern, writeConcern. etc).
*
* @return {Promise}
*/
async dropCollection(
database: string,
collection: string,
dbOptions?: DatabaseOptions
): Promise<boolean> {
return this.db(database, dbOptions)
.collection(collection)
.drop();
}
}
export default CliServiceProvider;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc