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
5
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.3 to 0.0.1-alpha.4

1

lib/cli-service-provider.d.ts

@@ -12,2 +12,3 @@ import { MongoClient } from 'mongodb';

constructor(mongoClient: MongoClient);
convertToCapped(database: string, collection: string, size: number): Promise<any>;
private db;

@@ -14,0 +15,0 @@ aggregate(database: string, collection: string, pipeline?: Document[], options?: Document, dbOptions?: Document): Cursor;

@@ -79,2 +79,21 @@ "use strict";

};
CliServiceProvider.prototype.convertToCapped = function (database, collection, size) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.runCommand(database, {
convertToCapped: collection,
size: size
}, {})];
case 1:
result = _a.sent();
if (!result) {
return [2];
}
return [2, result];
}
});
});
};
CliServiceProvider.prototype.db = function (name, options) {

@@ -81,0 +100,0 @@ if (options === void 0) { options = {}; }

7

package.json
{
"name": "@mongosh/service-provider-server",
"version": "0.0.1-alpha.3",
"version": "0.0.1-alpha.4",
"description": "MongoDB Shell Server Service Provider Package",

@@ -15,2 +15,3 @@ "main": "lib/index.js",

},
"license": "SSPL",
"publishConfig": {

@@ -35,6 +36,6 @@ "access": "public"

"dependencies": {
"@mongosh/service-provider-core": "^0.0.1-alpha.3",
"@mongosh/service-provider-core": "^0.0.1-alpha.4",
"mongodb": "3.5.3 || ^3.5.5"
},
"gitHead": "59d381d0c880746faa6cb96d37525d42ffa49472"
"gitHead": "7944ac5be25a90e28d5d1b40c5e6dbfd12105e06"
}

@@ -388,2 +388,25 @@ import CliServiceProvider from './cli-service-provider';

});
describe('#convertToCapped', () => {
it('converts a collection to capped', async() => {
const collName = 'coll1';
const nativeCollection = db.collection(collName);
await nativeCollection.insertOne({ doc: 1 });
expect(
await nativeCollection.isCapped()
).to.be.false;
await serviceProvider.convertToCapped(
dbName,
collName,
10000
);
expect(
await nativeCollection.isCapped()
).to.be.true;
});
});
});

@@ -474,2 +474,35 @@ import mongodb, { MongoClient, Db } from 'mongodb';

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

@@ -69,2 +69,29 @@ import { MongoClient, Db } from 'mongodb';

/**
* Converts an existing, non-capped collection to
* a capped collection within the same database.
*
* @param {String} database - The db name.
* @param {String} collection - The collection name.
* @param {String} size - The maximum size, in bytes, for the capped collection.
*
* @return {Promise}
*/
async convertToCapped(database: string, collection: string, size: number): Promise<any> {
const result: any = await this.runCommand(
database,
{
convertToCapped: collection,
size: size
},
{}
);
if (!result) {
return;
}
return result;
}
/**
* Get the Db object from the client.

@@ -71,0 +98,0 @@ *

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