Socket
Socket
Sign inDemoInstall

@mongosh/service-provider-core

Package Overview
Dependencies
Maintainers
8
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 0.0.8 to 0.1.0

lib/auth-options.d.ts

10

lib/admin.d.ts
import Result from './result';
import { ReplPlatform } from './platform';
import AuthOptions from './auth-options';
import CollectionOptions from './collection-options';
import DatabaseOptions from './database-options';
export default interface Admin {
platform: ReplPlatform;
initialDb: string;
bsonLibrary: any;
buildInfo(): Promise<Result>;

@@ -9,4 +15,4 @@ getCmdLineOpts(): Promise<Result>;

getConnectionInfo(): Promise<any>;
platform: ReplPlatform;
initialDb: string;
authenticate(authDoc: AuthOptions): Promise<any>;
createCollection(dbName: string, collName: string, opts: CollectionOptions, dbOptions?: DatabaseOptions): Promise<any>;
}

3

lib/command-options.d.ts
import WriteConcern from './write-concern';
export default interface CommandOptions {
import BaseOptions from './base-options';
export default interface CommandOptions extends BaseOptions {
writeConcern?: WriteConcern;
}
import Document from './document';
export default interface Cursor {
addOption(option: number): Cursor;
allowPartialResults(): Cursor;
batchSize(size: number): Cursor;
export declare const enum CursorFlag {
Tailable = "tailable",
SlaveOk = "slaveOk",
OplogReplay = "oplogReplay",
NoTimeout = "noCursorTimeout",
AwaitData = "awaitData",
Exhaust = "exhaust",
Partial = "partial"
}
export declare const CURSOR_FLAGS: {
2: CursorFlag;
4: CursorFlag;
8: CursorFlag;
16: CursorFlag;
32: CursorFlag;
64: CursorFlag;
128: CursorFlag;
};
export default interface ServiceProviderCursor {
addCursorFlag(flag: CursorFlag, value: boolean): any;
addOption(option: number): ServiceProviderCursor;
setReadPreference(mode: any): ServiceProviderCursor;
allowPartialResults(): ServiceProviderCursor;
batchSize(size: number): ServiceProviderCursor;
close(options: Document): Promise<void>;
clone(): Cursor;
clone(): ServiceProviderCursor;
isClosed(): boolean;
collation(spec: Document): Cursor;
comment(cmt: string): Cursor;
collation(spec: Document): ServiceProviderCursor;
comment(cmt: string): ServiceProviderCursor;
count(): Promise<number>;
forEach(f: any): Promise<void>;
hasNext(): Promise<boolean>;
hint(index: string): Cursor;
hint(index: string): ServiceProviderCursor;
isExhausted(): Promise<boolean>;
itcount(): Promise<number>;
limit(value: number): Cursor;
map(f: any): Cursor;
max(indexBounds: Document): Cursor;
maxTimeMS(value: number): Cursor;
min(indexBounds: Document): Cursor;
limit(value: number): ServiceProviderCursor;
map(f: any): ServiceProviderCursor;
max(indexBounds: Document): ServiceProviderCursor;
maxTimeMS(value: number): ServiceProviderCursor;
min(indexBounds: Document): ServiceProviderCursor;
next(): Promise<any>;
noCursorTimeout(): Cursor;
oplogReplay(): Cursor;
projection(spec: Document): Cursor;
returnKey(enabled: boolean): Cursor;
noServiceProviderCursorTimeout(): ServiceProviderCursor;
oplogReplay(): ServiceProviderCursor;
project(spec: Document): ServiceProviderCursor;
returnKey(enabled: boolean): ServiceProviderCursor;
size(): Promise<number>;
skip(value: number): Cursor;
sort(spec: Document): Cursor;
tailable(): Cursor;
readPref(mode: string, tagSet?: Document[]): Cursor;
skip(value: number): ServiceProviderCursor;
sort(spec: Document): ServiceProviderCursor;
tailable(): ServiceProviderCursor;
readPref(mode: string, tagSet?: Document[]): ServiceProviderCursor;
toArray(): Promise<Document[]>;
explain(verbosity: string): Promise<any>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CURSOR_FLAGS = {
2: "tailable",
4: "slaveOk",
8: "oplogReplay",
16: "noCursorTimeout",
32: "awaitData",
64: "exhaust",
128: "partial"
};
//# sourceMappingURL=cursor.js.map

@@ -1,4 +0,4 @@

import ServiceProvider from './service-provider';
import ServiceProvider, { ServiceProviderCore } from './service-provider';
import Document from './document';
import Cursor from './cursor';
import Cursor, { CursorFlag, CURSOR_FLAGS } from './cursor';
import Result from './result';

@@ -9,3 +9,5 @@ import BulkWriteResult from './bulk-write-result';

import CommandOptions from './command-options';
import BaseOptions from './base-options';
import DatabaseOptions from './database-options';
import AuthOptions from './auth-options';
import getConnectInfo from './connect-info';

@@ -16,2 +18,3 @@ import { ReplPlatform } from './platform';

declare const DEFAULT_DB = "test";
export { ServiceProvider, BulkWriteResult, Document, Cursor, Result, ReadConcern, WriteConcern, CommandOptions, DatabaseOptions, getConnectInfo, ReplPlatform, CliOptions, generateUri, Scheme, DEFAULT_DB };
import bson from 'bson';
export { ServiceProvider, BulkWriteResult, Document, Cursor, CursorFlag, CURSOR_FLAGS, Result, ReadConcern, WriteConcern, CommandOptions, BaseOptions, AuthOptions, DatabaseOptions, getConnectInfo, ReplPlatform, CliOptions, generateUri, Scheme, DEFAULT_DB, ServiceProviderCore, bson };

@@ -13,2 +13,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var service_provider_1 = require("./service-provider");
exports.ServiceProviderCore = service_provider_1.ServiceProviderCore;
var cursor_1 = require("./cursor");
exports.CURSOR_FLAGS = cursor_1.CURSOR_FLAGS;
var connect_info_1 = __importDefault(require("./connect-info"));

@@ -23,2 +27,4 @@ exports.getConnectInfo = connect_info_1.default;

exports.DEFAULT_DB = DEFAULT_DB;
var bson_1 = __importDefault(require("bson"));
exports.bson = bson_1.default;
//# sourceMappingURL=index.js.map

@@ -7,1 +7,5 @@ import Readable from './readable';

}
export declare class ServiceProviderCore {
bsonLibrary: any;
constructor(bsonLibrary: any);
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var printable_bson_1 = __importDefault(require("./printable-bson"));
var errors_1 = require("@mongosh/errors");
var ServiceProviderCore = (function () {
function ServiceProviderCore(bsonLibrary) {
if (bsonLibrary === undefined) {
throw new errors_1.MongoshInternalError('BSON Library is undefined. This is an internal error, please file a ticket!');
}
printable_bson_1.default(bsonLibrary);
this.bsonLibrary = bsonLibrary;
}
return ServiceProviderCore;
}());
exports.ServiceProviderCore = ServiceProviderCore;
//# sourceMappingURL=service-provider.js.map

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

var index_1 = require("./index");
var errors_1 = require("@mongosh/errors");
var Scheme;

@@ -20,9 +21,22 @@ (function (Scheme) {

if (options.host || options.port) {
throw new Error(i18n_1.default.__(CONFLICT));
throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(CONFLICT));
}
}
function generateHost(options) {
return options.host ? options.host : DEFAULT_HOST;
if (options.host) {
if (options.host.includes(':')) {
return options.host.split(':')[0];
}
return options.host;
}
return DEFAULT_HOST;
}
function generatePort(options) {
if (options.host && options.host.includes(':')) {
var port = options.host.split(':')[1];
if (!options.port || options.port === port) {
return port;
}
throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(CONFLICT));
}
return options.port ? options.port : DEFAULT_PORT;

@@ -29,0 +43,0 @@ }

{
"name": "@mongosh/service-provider-core",
"version": "0.0.8",
"version": "0.1.0",
"description": "MongoDB Shell Core Service Provider Package",

@@ -30,3 +30,5 @@ "main": "lib/index.js",

"dependencies": {
"@mongosh/i18n": "^0.0.8",
"@mongosh/errors": "^0.1.0",
"@mongosh/i18n": "^0.1.0",
"bson": "4.0.4",
"mongodb-build-info": "^1.0.0"

@@ -46,3 +48,3 @@ },

},
"gitHead": "ca72bca50bd9654910ea8f36bb6eb3c823cd8a49"
"gitHead": "57433c03fa9dbbd1a2448c396ec963174643fa1d"
}
import Result from './result';
import { ReplPlatform } from './platform';
import AuthOptions from './auth-options';
import CollectionOptions from './collection-options';
import DatabaseOptions from './database-options';
export default interface Admin {
/**
* What platform (Compass/CLI/Browser)
*/
platform: ReplPlatform;
/**
* The initial database
*/
initialDb: string;
/**
* The BSON package
*/
bsonLibrary: any;
/**

@@ -42,10 +60,10 @@ * Returns buildInfo.

/**
* What platform (Compass/CLI/Browser)
* Authenticate
*/
platform: ReplPlatform;
authenticate(authDoc: AuthOptions): Promise<any>;
/**
* The initial database
* createCollection
*/
initialDb: string;
createCollection(dbName: string, collName: string, opts: CollectionOptions, dbOptions?: DatabaseOptions): Promise<any>;
}
import WriteConcern from './write-concern';
import BaseOptions from './base-options';
export default interface CommandOptions {
export default interface CommandOptions extends BaseOptions {
writeConcern?: WriteConcern;
}
import Document from './document';
export default interface Cursor {
/**
* This is the interface based on the Node driver cursor.
* For future stitch cursors we will need to write a wrapper layer that
* makes the API the same as the Node driver.
*/
/**
* Enum for the available cursor flags.
*/
export const enum CursorFlag {
Tailable = 'tailable',
SlaveOk = 'slaveOk',
OplogReplay = 'oplogReplay',
NoTimeout = 'noCursorTimeout',
AwaitData = 'awaitData',
Exhaust = 'exhaust',
Partial = 'partial'
}
/**
* The cursor flags.
*/
export const CURSOR_FLAGS = {
2: CursorFlag.Tailable,
4: CursorFlag.SlaveOk,
8: CursorFlag.OplogReplay,
16: CursorFlag.NoTimeout,
32: CursorFlag.AwaitData,
64: CursorFlag.Exhaust,
128: CursorFlag.Partial
};
export default interface ServiceProviderCursor {
addCursorFlag(flag: CursorFlag, value: boolean): any;
/**

@@ -9,12 +41,21 @@ * Add a cursor flag as an option to the cursor.

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
addOption(option: number): Cursor;
addOption(option: number): ServiceProviderCursor;
/**
* Set the read preference.
*
* @param {string | ReadPreference } mode - the new read preference.
*
* @returns {ServiceProviderCursor}
*/
setReadPreference(mode: any): ServiceProviderCursor;
/**
* Set cursor to allow partial results.
*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
allowPartialResults(): Cursor;
allowPartialResults(): ServiceProviderCursor;

@@ -26,5 +67,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
batchSize(size: number): Cursor;
batchSize(size: number): ServiceProviderCursor;

@@ -34,3 +75,3 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/

@@ -42,5 +83,5 @@ close(options: Document): Promise<void>;

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
clone(): Cursor;
clone(): ServiceProviderCursor;

@@ -59,5 +100,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
collation(spec: Document): Cursor;
collation(spec: Document): ServiceProviderCursor;

@@ -69,5 +110,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
comment(cmt: string): Cursor;
comment(cmt: string): ServiceProviderCursor;

@@ -96,5 +137,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
hint(index: string): Cursor;
hint(index: string): ServiceProviderCursor;

@@ -116,7 +157,7 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
limit(value: number): Cursor;
limit(value: number): ServiceProviderCursor;
map(f): Cursor;
map(f): ServiceProviderCursor;

@@ -128,5 +169,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
max(indexBounds: Document): Cursor;
max(indexBounds: Document): ServiceProviderCursor;

@@ -138,5 +179,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
maxTimeMS(value: number): Cursor;
maxTimeMS(value: number): ServiceProviderCursor;

@@ -148,5 +189,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
min(indexBounds: Document): Cursor;
min(indexBounds: Document): ServiceProviderCursor;

@@ -158,12 +199,12 @@ next(): Promise<any>;

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
noCursorTimeout(): Cursor;
noServiceProviderCursorTimeout(): ServiceProviderCursor;
/**
* Flag the cursor as an oplog replay.
* CursorFlag the cursor as an oplog replay.
*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
oplogReplay(): Cursor;
oplogReplay(): ServiceProviderCursor;

@@ -175,5 +216,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
projection(spec: Document): Cursor;
project(spec: Document): ServiceProviderCursor;

@@ -185,5 +226,5 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
returnKey(enabled: boolean): Cursor;
returnKey(enabled: boolean): ServiceProviderCursor;

@@ -197,5 +238,5 @@ size(): Promise<number>;

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
skip(value: number): Cursor;
skip(value: number): ServiceProviderCursor;

@@ -207,12 +248,12 @@ /**

*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
sort(spec: Document): Cursor;
sort(spec: Document): ServiceProviderCursor;
/**
* Flag the cursor as tailable.
* CursorFlag the cursor as tailable.
*
* @returns {Cursor} The cursor.
* @returns {ServiceProviderCursor} The cursor.
*/
tailable(): Cursor;
tailable(): ServiceProviderCursor;

@@ -224,5 +265,5 @@ /**

* @param {Document[]} [tagSet] - the tag set
* @returns {Cursor}
* @returns {ServiceProviderCursor}
*/
readPref(mode: string, tagSet?: Document[]): Cursor;
readPref(mode: string, tagSet?: Document[]): ServiceProviderCursor;

@@ -229,0 +270,0 @@ /**

@@ -1,4 +0,4 @@

import ServiceProvider from './service-provider';
import ServiceProvider, { ServiceProviderCore } from './service-provider';
import Document from './document';
import Cursor from './cursor';
import Cursor, { CursorFlag, CURSOR_FLAGS } from './cursor';
import Result from './result';

@@ -9,3 +9,5 @@ import BulkWriteResult from './bulk-write-result';

import CommandOptions from './command-options';
import BaseOptions from './base-options';
import DatabaseOptions from './database-options';
import AuthOptions from './auth-options';
import getConnectInfo from './connect-info';

@@ -16,2 +18,3 @@ import { ReplPlatform } from './platform';

const DEFAULT_DB = 'test';
import bson from 'bson';

@@ -23,2 +26,4 @@ export {

Cursor,
CursorFlag,
CURSOR_FLAGS,
Result,

@@ -28,2 +33,4 @@ ReadConcern,

CommandOptions,
BaseOptions,
AuthOptions,
DatabaseOptions,

@@ -35,3 +42,5 @@ getConnectInfo,

Scheme,
DEFAULT_DB
DEFAULT_DB,
ServiceProviderCore,
bson
};

@@ -5,2 +5,4 @@ import Readable from './readable';

import Admin from './admin';
import makePrintableBson from './printable-bson';
import { MongoshInternalError } from '@mongosh/errors';

@@ -11,1 +13,12 @@ /**

export default interface ServiceProvider extends Readable, Writable, Closable, Admin {}
export class ServiceProviderCore {
public bsonLibrary;
constructor(bsonLibrary) {
if (bsonLibrary === undefined) {
throw new MongoshInternalError('BSON Library is undefined. This is an internal error, please file a ticket!');
}
makePrintableBson(bsonLibrary);
this.bsonLibrary = bsonLibrary;
}
}

@@ -20,2 +20,14 @@ import generateUri from './uri-generator';

});
it('handles both host and port', () => {
expect(generateUri({ _: [], host: 'localhost', port: '27018' })).to.equal('mongodb://localhost:27018');
});
it('handles host with port included', () => {
expect(generateUri({ _: [], host: 'localhost:27018' })).to.equal('mongodb://localhost:27018');
});
it('throws if host has port AND port set to other value', () => {
expect(generateUri.bind({ _: [], host: 'localhost:27018', port: '27019' })).to.throw();
});
it('handles host has port AND port set to equal value', () => {
expect(generateUri({ _: [], host: 'localhost:27018', port: '27018' })).to.equal('mongodb://localhost:27018');
});
});

@@ -22,0 +34,0 @@

@@ -6,2 +6,3 @@ /* eslint complexity: 0*/

import { DEFAULT_DB } from './index';
import { MongoshInvalidInputError } from '@mongosh/errors';

@@ -50,3 +51,3 @@ /**

if (options.host || options.port) {
throw new Error(i18n.__(CONFLICT));
throw new MongoshInvalidInputError(i18n.__(CONFLICT));
}

@@ -63,3 +64,9 @@ }

function generateHost(options: CliOptions): string {
return options.host ? options.host : DEFAULT_HOST;
if (options.host) {
if (options.host.includes(':')) {
return options.host.split(':')[0];
}
return options.host;
}
return DEFAULT_HOST;
}

@@ -75,2 +82,9 @@

function generatePort(options: CliOptions): string {
if (options.host && options.host.includes(':')) {
const port = options.host.split(':')[1];
if (!options.port || options.port === port) {
return port;
}
throw new MongoshInvalidInputError(i18n.__(CONFLICT));
}
return options.port ? options.port : DEFAULT_PORT;

@@ -77,0 +91,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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