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.14 to 0.0.1-alpha.15

2

lib/cli-service-provider.d.ts

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

getCmdLineOpts(): Promise<Result>;
dropDatabase(db: string, writeConcern?: WriteConcern): Promise<DropDatabaseResult>;
dropDatabase(db: string, writeConcern?: WriteConcern, dbOptions?: DatabaseOptions): Promise<DropDatabaseResult>;
createIndexes(database: string, collection: string, indexSpecs: Document[], options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;

@@ -46,0 +46,0 @@ getIndexes(database: string, collection: string, dbOptions?: DatabaseOptions): Promise<Result>;

@@ -339,4 +339,5 @@ "use strict";

};
CliServiceProvider.prototype.dropDatabase = function (db, writeConcern) {
CliServiceProvider.prototype.dropDatabase = function (db, writeConcern, dbOptions) {
if (writeConcern === void 0) { writeConcern = {}; }
if (dbOptions === void 0) { dbOptions = {}; }
return __awaiter(this, void 0, void 0, function () {

@@ -346,3 +347,3 @@ var nativeResult, ok;

switch (_a.label) {
case 0: return [4, this.db(db)
case 0: return [4, this.db(db, dbOptions)
.dropDatabase(writeConcern)];

@@ -349,0 +350,0 @@ case 1:

@@ -7,3 +7,3 @@ import { CollationDocument } from 'mongodb';

OplogReplay = "oplogReplay",
NoTimeout = "noTimeout",
NoTimeout = "noCursorTimeout",
AwaitData = "awaitData",

@@ -16,3 +16,3 @@ Exhaust = "exhaust",

constructor(cursor: any);
addOption(option: number): NodeCursor;
addOption(optionFlagNumber: number): NodeCursor;
allowPartialResults(): NodeCursor;

@@ -36,10 +36,6 @@ batchSize(size: number): NodeCursor;

next(): Promise<any>;
modifiers(): any;
noCursorTimeout(): NodeCursor;
objsLeftInBatch(): any;
oplogReplay(): NodeCursor;
projection(spec: Document): NodeCursor;
pretty(): void;
readConcern(): any;
readPref(preference: string): NodeCursor;
readPref(mode: string, tagSet?: Document[]): NodeCursor;
returnKey(enabled: boolean): NodeCursor;

@@ -46,0 +42,0 @@ size(): Promise<number>;

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

Object.defineProperty(exports, "__esModule", { value: true });
var errors_1 = require("@mongosh/errors");
var FLAGS = {

@@ -55,3 +56,3 @@ 2: "tailable",

8: "oplogReplay",
16: "noTimeout",
16: "noCursorTimeout",
32: "awaitData",

@@ -65,8 +66,11 @@ 64: "exhaust",

}
NodeCursor.prototype.addOption = function (option) {
var opt = FLAGS[option];
if (opt === "slaveOk" || !opt) {
return this;
NodeCursor.prototype.addOption = function (optionFlagNumber) {
var optionFlag = FLAGS[optionFlagNumber];
if (!optionFlag) {
throw new errors_1.MongoshInvalidInputError("Unknown option flag number: " + optionFlagNumber + ".");
}
this.cursor.addCursorFlag(opt, true);
if (optionFlag === "slaveOk") {
throw new errors_1.MongoshUnimplementedError('the slaveOk option is not yet supported.');
}
this.cursor.addCursorFlag(optionFlag, true);
return this;

@@ -149,6 +153,17 @@ };

return __awaiter(this, void 0, void 0, function () {
var count;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4, this.cursor.toArray()];
case 1: return [2, (_a.sent()).length];
case 0:
count = 0;
_a.label = 1;
case 1: return [4, this.hasNext()];
case 2:
if (!_a.sent()) return [3, 4];
return [4, this.next()];
case 3:
_a.sent();
count++;
return [3, 1];
case 4: return [2, count];
}

@@ -181,10 +196,6 @@ });

};
NodeCursor.prototype.modifiers = function () {
};
NodeCursor.prototype.noCursorTimeout = function () {
this.addFlag("noTimeout");
this.addFlag("noCursorTimeout");
return this;
};
NodeCursor.prototype.objsLeftInBatch = function () {
};
NodeCursor.prototype.oplogReplay = function () {

@@ -197,8 +208,7 @@ return this.addFlag("oplogReplay");

};
NodeCursor.prototype.pretty = function () {
};
NodeCursor.prototype.readConcern = function () {
};
NodeCursor.prototype.readPref = function (preference) {
this.cursor.setReadPreference(preference);
NodeCursor.prototype.readPref = function (mode, tagSet) {
if (tagSet) {
throw new errors_1.MongoshUnimplementedError('the tagSet argument is not yet supported.');
}
this.cursor.setReadPreference(mode);
return this;

@@ -205,0 +215,0 @@ };

{
"name": "@mongosh/service-provider-server",
"version": "0.0.1-alpha.14",
"version": "0.0.1-alpha.15",
"description": "MongoDB Shell Server Service Provider Package",

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

"dependencies": {
"@mongosh/service-provider-core": "^0.0.1-alpha.14",
"@mongosh/errors": "^0.0.1-alpha.15",
"@mongosh/service-provider-core": "^0.0.1-alpha.15",
"@types/sinon": "^7.5.1",
"@types/sinon-chai": "^3.2.3",
"mongodb": "3.5.3 || ^3.5.5"
},
"gitHead": "d505622df7589da25592a1abfe62cb76de702b3b"
"gitHead": "7a03e706a3ec26c8d93425b90feaadab6dcf3cdd"
}

@@ -59,3 +59,3 @@ import mongodb, { MongoClient, Db } from 'mongodb';

expect(result).to.deep.equal(aggResult);
aggMock.verify();
(aggMock as any).verify();
});

@@ -79,3 +79,3 @@ });

expect(result).to.deep.equal(commandResult);
bulkMock.verify();
(bulkMock as any).verify();
});

@@ -98,3 +98,3 @@ });

expect(result).to.deep.equal(countResult);
countMock.verify();
(countMock as any).verify();
});

@@ -117,3 +117,3 @@ });

expect(result).to.deep.equal(commandResult);
deleteMock.verify();
(deleteMock as any).verify();
});

@@ -136,3 +136,3 @@ });

expect(result).to.deep.equal(commandResult);
deleteMock.verify();
(deleteMock as any).verify();
});

@@ -156,3 +156,3 @@ });

expect(result).to.deep.equal(distinctResult);
distinctMock.verify();
(distinctMock as any).verify();
});

@@ -175,3 +175,3 @@ });

expect(result).to.deep.equal(countResult);
countMock.verify();
(countMock as any).verify();
});

@@ -197,3 +197,3 @@ });

expect(result).to.deep.equal(findResult);
findMock.verify();
(findMock as any).verify();
});

@@ -227,3 +227,3 @@ });

expect(result).to.deep.equal(commandResult);
findMock.verify();
(findMock as any).verify();
});

@@ -246,3 +246,3 @@ });

expect(result).to.deep.equal(commandResult);
findMock.verify();
(findMock as any).verify();
});

@@ -269,3 +269,3 @@ });

expect(result).to.deep.equal(commandResult);
findMock.verify();
(findMock as any).verify();
});

@@ -292,3 +292,3 @@ });

expect(result).to.deep.equal(commandResult);
findMock.verify();
(findMock as any).verify();
});

@@ -312,3 +312,3 @@ });

expect(result).to.deep.equal(commandResult);
insertMock.verify();
(insertMock as any).verify();
});

@@ -332,3 +332,3 @@ });

expect(result).to.deep.equal(commandResult);
insertMock.verify();
(insertMock as any).verify();
});

@@ -354,3 +354,3 @@ });

expect(result).to.deep.equal(commandResult);
replaceMock.verify();
(replaceMock as any).verify();
});

@@ -385,3 +385,3 @@ });

expect(result).to.deep.equal(commandResult);
commandMock.verify();
(commandMock as any).verify();
});

@@ -407,3 +407,3 @@ });

expect(result).to.deep.equal(commandResult);
updateMock.verify();
(updateMock as any).verify();
});

@@ -429,3 +429,3 @@ });

expect(result).to.deep.equal(commandResult);
updateMock.verify();
(updateMock as any).verify();
});

@@ -474,3 +474,3 @@ });

expect((clientStub.db as any).calledWith('db1'));
dropDatabaseMock.verify();
(dropDatabaseMock as any).verify();
});

@@ -485,3 +485,3 @@ });

expect((clientStub.db as any).calledWith('db1'));
dropDatabaseMock.verify();
(dropDatabaseMock as any).verify();
});

@@ -526,4 +526,4 @@ });

expect(result).to.deep.equal(buildInfoResult);
dbMock.verify();
commandMock.verify();
(dbMock as any).verify();
(commandMock as any).verify();
});

@@ -573,4 +573,4 @@ });

expect(result).to.deep.equal(cmdLineOptsResult);
dbMock.verify();
commandMock.verify();
(dbMock as any).verify();
(commandMock as any).verify();
});

@@ -607,4 +607,4 @@ });

expect(result).to.deep.equal({ ok: 1 });
dbMock.verify();
commandMock.verify();
(dbMock as any).verify();
(commandMock as any).verify();
});

@@ -646,3 +646,3 @@ });

expect(result).to.deep.equal(nativeMethodResult);
nativeMethodMock.verify();
(nativeMethodMock as any).verify();
});

@@ -682,3 +682,3 @@ });

expect(result).to.deep.equal(indexSpecs);
nativeMethodMock.verify();
(nativeMethodMock as any).verify();
});

@@ -715,4 +715,4 @@ });

expect(result).to.deep.equal({ ok: 1 });
dbMock.verify();
commandMock.verify();
(dbMock as any).verify();
(commandMock as any).verify();
});

@@ -762,4 +762,4 @@ });

dbMock.verify();
commandMock.verify();
(dbMock as any).verify();
(commandMock as any).verify();
});

@@ -788,3 +788,3 @@ });

expect(result).to.deep.equal(expectedResult);
statsMock.verify();
(statsMock as any).verify();
});

@@ -821,4 +821,4 @@ });

expect(result).to.deep.equal({ ok: 1 });
dbMock.verify();
commandMock.verify();
(dbMock as any).verify();
(commandMock as any).verify();
});

@@ -866,6 +866,6 @@ });

expect(result).to.deep.equal({ ok: 1 });
dbMock.verify();
commandMock.verify();
(dbMock as any).verify();
(commandMock as any).verify();
});
});
});

@@ -766,5 +766,6 @@ import {

db: string,
writeConcern: WriteConcern = {}
writeConcern: WriteConcern = {},
dbOptions: DatabaseOptions = {}
): Promise<DropDatabaseResult> {
const nativeResult = await (this.db(db) as any)
const nativeResult = await (this.db(db, dbOptions) as any)
.dropDatabase(writeConcern);

@@ -771,0 +772,0 @@

@@ -0,9 +1,13 @@

import sinon, { SinonStubbedInstance } from 'sinon';
import chai from 'chai';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);
const { expect } = chai;
import NodeCursor, { Flag } from './node-cursor';
import { Cursor } from 'mongodb';
import { expect } from 'chai';
import sinon from 'sinon';
describe('NodeCursor', () => {
describe('#addOption', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -24,6 +28,14 @@ let mock;

});
it('throws if a SlaveOk flag passed', () => {
expect(() => nodeCursor.addOption(4)).to.throw('the slaveOk option is not yet supported.');
});
it('throws if an unknown flag passed', () => {
expect(() => nodeCursor.addOption(123123)).to.throw('Unknown option flag number: 123123');
});
});
describe('#allowPartialResults', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -47,3 +59,3 @@ let mock;

describe('#batchSize', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -67,3 +79,3 @@ let mock;

describe('#close', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -88,3 +100,3 @@ let mock;

describe('#collation', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -109,3 +121,3 @@ let mock;

describe('#comment', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -130,3 +142,3 @@ let mock;

describe('#count', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -150,3 +162,3 @@ let mock;

describe('#hasNext', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -170,3 +182,3 @@ let mock;

describe('#isExhausted', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor: NodeCursor;

@@ -206,3 +218,3 @@ let hasNextMock;

describe('#hint', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -227,3 +239,3 @@ let mock;

describe('#limit', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -248,3 +260,3 @@ let mock;

describe('#max', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -269,3 +281,3 @@ let mock;

describe('#maxTimeMS', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -290,3 +302,3 @@ let mock;

describe('#min', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -311,3 +323,3 @@ let mock;

describe('#noCursorTimeout', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -331,3 +343,3 @@ let mock;

describe('#oplogReplay', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -351,3 +363,3 @@ let mock;

describe('#projection', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -372,3 +384,3 @@ let mock;

describe('#readPref', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -390,6 +402,10 @@ let mock;

});
it('throws MongoshUnimplementedError if tagset is passed', () => {
expect(() => nodeCursor.readPref(value, [])).to.throw('the tagSet argument is not yet supported.');
});
});
describe('#returnKey', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -413,45 +429,4 @@ let mock;

// TODO: fix implementation
// describe('#showDiskLoc', () => {
// let cursor;
// let nodeCursor;
// let mock;
// beforeEach(() => {
// mock = sinon.mock().withArgs(true);
// cursor = sinon.createStubInstance(Cursor, {
// showRecordId: mock
// });
// nodeCursor = new NodeCursor(cursor);
// });
// it('fluidly sets the show disk location flag', () => {
// expect(nodeCursor.showDiskLoc()).to.equal(nodeCursor);
// mock.verify();
// });
// });
// TODO: fix implementation
// describe('#showRecordId', () => {
// let cursor;
// let nodeCursor;
// let mock;
// const value = true;
// beforeEach(() => {
// mock = sinon.mock().withArgs(value);
// cursor = sinon.createStubInstance(Cursor, {
// showRecordId: mock
// });
// nodeCursor = new NodeCursor(cursor);
// });
// it('fluidly sets the show record id value', () => {
// expect(nodeCursor.showRecordId(value)).to.equal(nodeCursor);
// mock.verify();
// });
// });
describe('#skip', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -476,3 +451,3 @@ let mock;

describe('#sort', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -497,3 +472,3 @@ let mock;

describe('#tailable', () => {
let cursor;
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;

@@ -516,2 +491,21 @@ let mock;

describe('#itcount', () => {
let cursor: SinonStubbedInstance<Cursor>;
let nodeCursor;
beforeEach(() => {
cursor = sinon.createStubInstance(Cursor);
nodeCursor = new NodeCursor(cursor);
});
it('returns the iteration count', async() => {
cursor.hasNext.onCall(0).resolves(true);
cursor.hasNext.onCall(1).resolves(true);
cursor.hasNext.onCall(2).resolves(false);
cursor.next.resolves({});
expect(await nodeCursor.itcount()).to.equal(2);
});
});
describe('#explain', () => {

@@ -518,0 +512,0 @@ let nativeCursorStub;

import { Cursor as NativeCursor, CollationDocument } from 'mongodb';
import { Cursor } from '@mongosh/service-provider-core';
import { MongoshUnimplementedError, MongoshInvalidInputError } from '@mongosh/errors';

@@ -11,3 +12,3 @@ /**

OplogReplay = 'oplogReplay',
NoTimeout = 'noTimeout',
NoTimeout = 'noCursorTimeout',
AwaitData = 'awaitData',

@@ -50,12 +51,18 @@ Exhaust = 'exhaust',

*
* @param {number} option - The flag number.
* @param {number} optionFlagNumber - The flag number.
*
* @returns {NodeCursor} The cursor.
*/
addOption(option: number): NodeCursor {
const opt = FLAGS[option];
if (opt === Flag.SlaveOk || !opt) {
return this; // TODO
addOption(optionFlagNumber: number): NodeCursor {
const optionFlag = FLAGS[optionFlagNumber];
if (!optionFlag) {
throw new MongoshInvalidInputError(`Unknown option flag number: ${optionFlagNumber}.`);
}
this.cursor.addCursorFlag(opt, true);
if (optionFlag === Flag.SlaveOk) {
throw new MongoshUnimplementedError('the slaveOk option is not yet supported.');
}
this.cursor.addCursorFlag(optionFlag, true);
return this;

@@ -161,3 +168,2 @@ }

/**

@@ -174,3 +180,10 @@ * cursor.isExhausted() returns true if the cursor is closed and there are no

async itcount(): Promise<number> {
return (await this.cursor.toArray()).length;
let count = 0;
while (await this.hasNext()) {
await this.next();
count++;
}
return count;
}

@@ -235,6 +248,2 @@

modifiers(): any { // TODO
}
/**

@@ -250,6 +259,2 @@ * Tell the cursor not to timeout.

objsLeftInBatch(): any {
// TODO
}
/**

@@ -276,10 +281,2 @@ * Flag the cursor as an oplog replay.

pretty(): void {
// TODO
}
readConcern(/** v */): any {
// TODO
}
/**

@@ -289,7 +286,13 @@ * Set the read preference.

* @param {string} preference - The read preference.
* @param {string} tagSet - The tag set.
*
* @returns {NodeCursor} The cursor.
*/
readPref(preference: string): NodeCursor {
this.cursor.setReadPreference(preference as any);
readPref(mode: string, tagSet?: Document[]): NodeCursor {
if (tagSet) {
throw new MongoshUnimplementedError('the tagSet argument is not yet supported.');
}
this.cursor.setReadPreference(mode as any);
return this;

@@ -310,28 +313,2 @@ }

// TODO: showRecordId takes an object:
// https://github.com/mongodb/node-mongodb-native/blob/4c852e7e926776c9aa7a74842accfcd813dafa87/lib/cursor/cursor.js#L341
// /**
// * Enable showing disk location.
// *
// * @returns {NodeCursor} The cursor.
// */
// showDiskLoc(): NodeCursor {
// this.cursor.showRecordId(true);
// return this;
// }
// TODO: showRecordId takes an object:
// https://github.com/mongodb/node-mongodb-native/blob/4c852e7e926776c9aa7a74842accfcd813dafa87/lib/cursor/cursor.js#L341
// /**
// * Enable/disable showing the disk location.
// *
// * @param {boolean} enabled - The value.
// *
// * @returns {NodeCursor} The cursor.
// */
// showRecordId(enabled: boolean): NodeCursor {
// this.cursor.showRecordId(enabled);
// return this;
// }
size(): Promise<number> {

@@ -396,3 +373,3 @@ return this.cursor.count(); // TODO: size same as count?

const fullExplain = await this.cursor.explain();
const fullExplain: any = await this.cursor.explain();

@@ -399,0 +376,0 @@ const explain: any = {

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