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

@mongosh/service-provider-core

Package Overview
Dependencies
Maintainers
11
Versions
123
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.5.0 to 0.5.1

src/printable-bson.spec.ts

16

lib/bulk.d.ts

@@ -24,10 +24,2 @@ import Document from './document';

}
export interface ServiceProviderBulkFindOp {
remove(): ServiceProviderBulkOp;
removeOne(): ServiceProviderBulkOp;
replaceOne(replacement: Document): ServiceProviderBulkOp;
updateOne(update: Document): ServiceProviderBulkOp;
update(update: Document): ServiceProviderBulkOp;
upsert(): ServiceProviderBulkFindOp;
}
export default interface ServiceProviderBulkOp {

@@ -45,1 +37,9 @@ s: {

}
export interface ServiceProviderBulkFindOp {
remove(): ServiceProviderBulkOp;
removeOne(): ServiceProviderBulkOp;
replaceOne(replacement: Document): ServiceProviderBulkOp;
updateOne(update: Document): ServiceProviderBulkOp;
update(update: Document): ServiceProviderBulkOp;
upsert(): ServiceProviderBulkFindOp;
}
export default interface Closable {
close(boolean: any): Promise<void>;
close(force: boolean): Promise<void>;
}

@@ -6,9 +6,9 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var mongodb_build_info_1 = __importDefault(require("mongodb-build-info"));
const mongodb_build_info_1 = __importDefault(require("mongodb-build-info"));
function getConnectInfo(uri, mongoshVersion, buildInfo, cmdLineOpts, topology) {
var _a = mongodb_build_info_1.default.getGenuineMongoDB(buildInfo, cmdLineOpts), is_genuine = _a.isGenuine, non_genuine_server_name = _a.serverName;
var _b = mongodb_build_info_1.default.getDataLake(buildInfo), is_data_lake = _b.isDataLake, dl_version = _b.dlVersion;
var auth_type = topology.s.credentials
const { isGenuine: is_genuine, serverName: non_genuine_server_name } = mongodb_build_info_1.default.getGenuineMongoDB(buildInfo, cmdLineOpts);
const { isDataLake: is_data_lake, dlVersion: dl_version } = mongodb_build_info_1.default.getDataLake(buildInfo);
const auth_type = topology.s.credentials
? topology.s.credentials.mechanism : null;
var _c = mongodb_build_info_1.default.getBuildEnv(buildInfo), server_os = _c.serverOs, server_arch = _c.serverArch;
const { serverOs: server_os, serverArch: server_arch } = mongodb_build_info_1.default.getBuildEnv(buildInfo);
return {

@@ -20,11 +20,11 @@ is_atlas: mongodb_build_info_1.default.isAtlas(uri),

mongosh_version: mongoshVersion,
server_os: server_os,
uri: uri,
server_arch: server_arch,
server_os,
uri,
server_arch,
is_enterprise: mongodb_build_info_1.default.isEnterprise(buildInfo),
auth_type: auth_type,
is_data_lake: is_data_lake,
dl_version: dl_version,
is_genuine: is_genuine,
non_genuine_server_name: non_genuine_server_name
auth_type,
is_data_lake,
dl_version,
is_genuine,
non_genuine_server_name
};

@@ -31,0 +31,0 @@ }

@@ -22,7 +22,5 @@ import Document from './document';

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>;
close(options: Document): Promise<unknown>;
clone(): ServiceProviderCursor;

@@ -33,9 +31,7 @@ isClosed(): boolean;

count(): Promise<number>;
forEach(f: any): Promise<void>;
forEach(f: (doc: Document) => void): Promise<void>;
hasNext(): Promise<boolean>;
hint(index: string): ServiceProviderCursor;
isExhausted(): Promise<boolean>;
itcount(): Promise<number>;
limit(value: number): ServiceProviderCursor;
map(f: any): ServiceProviderCursor;
map(f: (doc: Document) => Document): ServiceProviderCursor;
max(indexBounds: Document): ServiceProviderCursor;

@@ -46,11 +42,6 @@ maxTimeMS(value: number): ServiceProviderCursor;

next(): Promise<any>;
noServiceProviderCursorTimeout(): ServiceProviderCursor;
oplogReplay(): ServiceProviderCursor;
project(spec: Document): ServiceProviderCursor;
returnKey(enabled: boolean): ServiceProviderCursor;
size(): Promise<number>;
skip(value: number): ServiceProviderCursor;
sort(spec: Document): ServiceProviderCursor;
tailable(): ServiceProviderCursor;
readPref(mode: string, tagSet?: Document[]): ServiceProviderCursor;
toArray(): Promise<Document[]>;

@@ -57,0 +48,0 @@ explain(verbosity: string): Promise<any>;

@@ -18,4 +18,5 @@ import ServiceProvider, { ServiceProviderCore } from './service-provider';

declare const DEFAULT_DB = "test";
import bson from 'bson';
import * as bson from 'bson';
import ServiceProviderBulkOp, { ServiceProviderBulkFindOp, BulkBatch } from './bulk';
export { ServiceProvider, BulkWriteResult, Document, Cursor, CursorFlag, CURSOR_FLAGS, Result, ReadConcern, WriteConcern, ReadPreference, ReadPreferenceMode, CommandOptions, BaseOptions, AuthOptions, DatabaseOptions, getConnectInfo, ReplPlatform, CliOptions, generateUri, Scheme, DEFAULT_DB, ServiceProviderCore, bson, ServiceProviderBulkFindOp, ServiceProviderBulkOp, BulkBatch };
import makePrintableBson, { bsonStringifiers } from './printable-bson';
export { ServiceProvider, BulkWriteResult, Document, Cursor, CursorFlag, CURSOR_FLAGS, Result, ReadConcern, WriteConcern, ReadPreference, ReadPreferenceMode, CommandOptions, BaseOptions, AuthOptions, DatabaseOptions, getConnectInfo, ReplPlatform, CliOptions, generateUri, Scheme, DEFAULT_DB, ServiceProviderCore, bson, makePrintableBson, bsonStringifiers, ServiceProviderBulkFindOp, ServiceProviderBulkOp, BulkBatch };

@@ -25,20 +25,23 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.bson = exports.ServiceProviderCore = exports.DEFAULT_DB = exports.Scheme = exports.generateUri = exports.ReplPlatform = exports.getConnectInfo = exports.ReadPreferenceMode = exports.CURSOR_FLAGS = void 0;
var service_provider_1 = require("./service-provider");
exports.bsonStringifiers = exports.makePrintableBson = exports.bson = exports.ServiceProviderCore = exports.DEFAULT_DB = exports.Scheme = exports.generateUri = exports.ReplPlatform = exports.getConnectInfo = exports.ReadPreferenceMode = exports.CURSOR_FLAGS = void 0;
const service_provider_1 = require("./service-provider");
Object.defineProperty(exports, "ServiceProviderCore", { enumerable: true, get: function () { return service_provider_1.ServiceProviderCore; } });
var cursor_1 = require("./cursor");
const cursor_1 = require("./cursor");
Object.defineProperty(exports, "CURSOR_FLAGS", { enumerable: true, get: function () { return cursor_1.CURSOR_FLAGS; } });
var read_preference_1 = require("./read-preference");
const read_preference_1 = require("./read-preference");
Object.defineProperty(exports, "ReadPreferenceMode", { enumerable: true, get: function () { return read_preference_1.ReadPreferenceMode; } });
var connect_info_1 = __importDefault(require("./connect-info"));
const connect_info_1 = __importDefault(require("./connect-info"));
exports.getConnectInfo = connect_info_1.default;
var platform_1 = require("./platform");
const platform_1 = require("./platform");
Object.defineProperty(exports, "ReplPlatform", { enumerable: true, get: function () { return platform_1.ReplPlatform; } });
var uri_generator_1 = __importStar(require("./uri-generator"));
const uri_generator_1 = __importStar(require("./uri-generator"));
exports.generateUri = uri_generator_1.default;
Object.defineProperty(exports, "Scheme", { enumerable: true, get: function () { return uri_generator_1.Scheme; } });
var DEFAULT_DB = 'test';
const DEFAULT_DB = 'test';
exports.DEFAULT_DB = DEFAULT_DB;
var bson_1 = __importDefault(require("bson"));
exports.bson = bson_1.default;
const bson = __importStar(require("bson"));
exports.bson = bson;
const printable_bson_1 = __importStar(require("./printable-bson"));
exports.makePrintableBson = printable_bson_1.default;
Object.defineProperty(exports, "bsonStringifiers", { enumerable: true, get: function () { return printable_bson_1.bsonStringifiers; } });
//# sourceMappingURL=index.js.map

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

export default function (bson: any): void;
export declare const bsonStringifiers: Record<string, (this: any) => string>;
export default function (bson?: any): void;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var bson_1 = __importDefault(require("bson"));
function default_1(bson) {
if (!bson) {
bson = bson_1.default;
}
var toString = require('util').inspect.custom || 'inspect';
bson.ObjectId.prototype[toString] = function () {
return "ObjectId(\"" + this.toHexString() + "\")";
};
bson.ObjectId.prototype.asPrintable = bson.ObjectId.prototype[toString];
bson.DBRef.prototype[toString] = function () {
return "DBRef(\"" + this.namespace + "\", \"" + (this.oid === undefined || this.oid.toString === undefined ?
exports.bsonStringifiers = void 0;
const BSON = __importStar(require("bson"));
const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
exports.bsonStringifiers = {
ObjectID: function () {
return `ObjectId("${this.toHexString()}")`;
},
DBRef: function () {
return `DBRef("${this.namespace}", "${this.oid === undefined || this.oid.toString === undefined ?
this.oid :
this.oid.toString()) + "\"" + (this.db ? ", \"" + this.db + "\"" : '') + ")";
};
bson.DBRef.prototype.asPrintable = bson.DBRef.prototype[toString];
bson.MaxKey.prototype[toString] = function () {
this.oid.toString()}"${this.db ? `, "${this.db}"` : ''})`;
},
MaxKey: function () {
return '{ "$maxKey" : 1 }';
};
bson.MaxKey.prototype.asPrintable = bson.MaxKey.prototype[toString];
bson.MinKey.prototype[toString] = function () {
},
MinKey: function () {
return '{ "$minKey" : 1 }';
};
bson.MinKey.prototype.asPrintable = bson.MinKey.prototype[toString];
bson.Timestamp.prototype[toString] = function () {
return "Timestamp(" + this.getLowBits().toString() + ", " + this.getHighBits().toString() + ")";
};
bson.Timestamp.prototype.asPrintable = bson.Timestamp.prototype[toString];
if ('Symbol' in bson) {
bson.Symbol.prototype[toString] = function () {
return "\"" + this.valueOf() + "\"";
};
}
if ('BSONSymbol' in bson) {
bson.BSONSymbol.prototype[toString] = function () {
return "\"" + this.valueOf() + "\"";
};
}
bson.Code.prototype[toString] = function () {
var j = this.toJSON();
return "{ \"code\" : \"" + j.code + "\"" + (j.scope ? ", \"scope\" : " + JSON.stringify(j.scope) : '') + " }";
};
bson.Code.prototype.asPrintable = bson.Code.prototype[toString];
bson.Decimal128.prototype[toString] = function () {
return "NumberDecimal(\"" + this.toString() + "\")";
};
bson.Decimal128.prototype.asPrintable = bson.Decimal128.prototype[toString];
bson.Int32.prototype[toString] = function () {
return "NumberInt(" + this.valueOf() + ")";
};
bson.Int32.prototype.asPrintable = bson.Int32.prototype[toString];
bson.Long.prototype[toString] = function () {
return "NumberLong(\"" + this.toString() + "\")";
};
bson.Long.prototype.asPrintable = bson.Long.prototype[toString];
bson.Binary.prototype[toString] = function () {
var asBuffer = this.value(true);
},
Timestamp: function () {
return `Timestamp(${this.getLowBits().toString()}, ${this.getHighBits().toString()})`;
},
Symbol: function () {
return `"${this.valueOf()}"`;
},
BSONSymbol: function () {
return `"${this.valueOf()}"`;
},
Code: function () {
const j = this.toJSON();
return `{ "code" : "${j.code}"${j.scope ? `, "scope" : ${JSON.stringify(j.scope)}` : ''} }`;
},
Decimal128: function () {
return `NumberDecimal("${this.toString()}")`;
},
Int32: function () {
return `NumberInt(${this.valueOf()})`;
},
Long: function () {
return `NumberLong("${this.toString()}")`;
},
Binary: function () {
const asBuffer = this.value(true);
switch (this.sub_type) {
case bson.Binary.SUBTYPE_MD5:
return "MD5(\"" + asBuffer.toString('hex') + "\")";
case bson.Binary.SUBTYPE_UUID:
case BSON.Binary.SUBTYPE_MD5:
return `MD5("${asBuffer.toString('hex')}")`;
case BSON.Binary.SUBTYPE_UUID:
if (asBuffer.length === 16) {
var hex = asBuffer.toString('hex');
var asUUID = hex.match(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/)
const hex = asBuffer.toString('hex');
const asUUID = hex.match(/^(.{8})(.{4})(.{4})(.{4})(.{12})$/)
.slice(1, 6).join('-');
return "UUID(\"" + asUUID + "\")";
return `UUID("${asUUID}")`;
}
default:
return "BinData(" + this.sub_type + ", \"" + asBuffer.toString('base64') + "\")";
return `BinData(${this.sub_type}, "${asBuffer.toString('base64')}")`;
}
};
bson.Binary.prototype.asPrintable = bson.Binary.prototype[toString];
},
};
exports.bsonStringifiers.ObjectId = exports.bsonStringifiers.ObjectID;
function default_1(bson) {
if (!bson) {
bson = BSON;
}
for (const [key, stringifier] of Object.entries(exports.bsonStringifiers)) {
if (!(key in bson)) {
continue;
}
const cls = bson[key];
for (const key of [inspectCustom, 'inspect']) {
try {
cls.prototype[key] = stringifier;
}
catch (_a) {
}
}
}
}
exports.default = default_1;
//# sourceMappingURL=printable-bson.js.map

@@ -8,12 +8,12 @@ import Document from './document';

aggregateDb(database: string, pipeline: Document[], options?: Document, dbOptions?: DatabaseOptions): Cursor;
count(db: string, coll: string, query?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
countDocuments(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
count(db: string, coll: string, query?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<number>;
countDocuments(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<number>;
distinct(database: string, collection: string, fieldName: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
estimatedDocumentCount(database: string, collection: string, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
estimatedDocumentCount(database: string, collection: string, options?: Document, dbOptions?: DatabaseOptions): Promise<number>;
find(database: string, collection: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Cursor;
getTopology(): any;
isCapped(database: string, collection: string, dbOptions?: DatabaseOptions): Promise<Result>;
getIndexes(database: string, collection: string, 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<Result>;
isCapped(database: string, collection: string, dbOptions?: DatabaseOptions): Promise<any>;
getIndexes(database: string, collection: string, dbOptions?: DatabaseOptions): Promise<any[]>;
listCollections(database: string, filter?: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<any[]>;
stats(database: string, collection: string, options?: Document, dbOptions?: DatabaseOptions): Promise<any>;
}

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

declare type Result = any;
declare type Result = unknown;
export default Result;

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

import Admin from './admin';
import BSON from 'bson';
export default interface ServiceProvider extends Readable, Writable, Closable, Admin {
}
export declare class ServiceProviderCore {
bsonLibrary: any;
constructor(bsonLibrary: any);
bsonLibrary: typeof BSON;
constructor(bsonLibrary?: any);
}

@@ -7,6 +7,6 @@ "use strict";

exports.ServiceProviderCore = void 0;
var printable_bson_1 = __importDefault(require("./printable-bson"));
var errors_1 = require("@mongosh/errors");
var ServiceProviderCore = (function () {
function ServiceProviderCore(bsonLibrary) {
const printable_bson_1 = __importDefault(require("./printable-bson"));
const errors_1 = require("@mongosh/errors");
class ServiceProviderCore {
constructor(bsonLibrary) {
if (bsonLibrary === undefined) {

@@ -18,5 +18,4 @@ throw new errors_1.MongoshInternalError('BSON Library is undefined. This is an internal error, please file a ticket!');

}
return ServiceProviderCore;
}());
}
exports.ServiceProviderCore = ServiceProviderCore;
//# sourceMappingURL=service-provider.js.map

@@ -7,5 +7,5 @@ "use strict";

exports.Scheme = void 0;
var i18n_1 = __importDefault(require("@mongosh/i18n"));
var index_1 = require("./index");
var errors_1 = require("@mongosh/errors");
const i18n_1 = __importDefault(require("@mongosh/i18n"));
const index_1 = require("./index");
const errors_1 = require("@mongosh/errors");
var Scheme;

@@ -17,5 +17,5 @@ (function (Scheme) {

exports.Scheme = Scheme;
var DEFAULT_HOST = '127.0.0.1';
var DEFAULT_PORT = '27017';
var CONFLICT = 'cli-repl.uri-generator.no-host-port';
const DEFAULT_HOST = '127.0.0.1';
const DEFAULT_PORT = '27017';
const CONFLICT = 'cli-repl.uri-generator.no-host-port';
function validateConflicts(options) {

@@ -37,3 +37,3 @@ if (options.host || options.port) {

if (options.host && options.host.includes(':')) {
var port = options.host.split(':')[1];
const port = options.host.split(':')[1];
if (!options.port || options.port === port) {

@@ -47,5 +47,6 @@ return port;

function generateUri(options) {
var uri = options._[0];
var _a;
const uri = (_a = options._) === null || _a === void 0 ? void 0 : _a[0];
if (!uri) {
return "" + Scheme.Mongo + generateHost(options) + ":" + generatePort(options);
return `${Scheme.Mongo}${generateHost(options)}:${generatePort(options)}`;
}

@@ -56,10 +57,10 @@ if (uri.startsWith(Scheme.Mongo) || uri.startsWith(Scheme.MongoSrv)) {

}
var uriMatch = /^([A-Za-z0-9][A-Za-z0-9.-]+):?(\d+)?[\/]?(\S+)?$/gi;
var parts = uriMatch.exec(uri);
const uriMatch = /^([A-Za-z0-9][A-Za-z0-9.-]+):?(\d+)?[\/]?(\S+)?$/gi;
const parts = uriMatch.exec(uri);
if (parts === null) {
throw new errors_1.MongoshInvalidInputError("Invalid URI: " + uri);
throw new errors_1.MongoshInvalidInputError(`Invalid URI: ${uri}`);
}
var host = parts[1];
var port = parts[2];
var db = parts[3];
let host = parts[1];
const port = parts[2];
let db = parts[3];
if (!port && !db && host.indexOf('.') < 0) {

@@ -72,5 +73,5 @@ db = host;

}
return "" + Scheme.Mongo + (host || generateHost(options)) + ":" + (port || generatePort(options)) + "/" + (db || index_1.DEFAULT_DB);
return `${Scheme.Mongo}${host || generateHost(options)}:${port || generatePort(options)}/${db || index_1.DEFAULT_DB}`;
}
exports.default = generateUri;
//# sourceMappingURL=uri-generator.js.map

@@ -7,18 +7,65 @@ import Document from './document';

import DatabaseOptions from './database-options';
declare type DeleteWriteResult = {
result: {
ok?: number;
n?: number;
};
connection?: any;
deletedCount?: number;
};
declare type FindAndModifyResult = {
value?: any;
lastErrorObject?: any;
ok?: number;
};
declare type InsertResult = {
insertedCount: number;
ops: any[];
connection: any;
result: {
ok: number;
n: number;
};
};
declare type InsertOneResult = InsertResult & {
insertedId: any;
};
declare type InsertManyResult = InsertResult & {
insertedIds: {
[key: number]: any;
};
};
declare type UpdateResult = {
result: {
ok: number;
n: number;
nModified: number;
};
connection: any;
matchedCount: number;
modifiedCount: number;
upsertedCount: number;
upsertedId: {
_id: any;
};
};
declare type ReplaceResult = UpdateResult & {
ops: any[];
};
export default interface Writable {
runCommand(db: string, spec: Document, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<Result>;
runCommandWithCheck(db: string, spec: Document, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<Result>;
runCommand(db: string, spec: Document, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<any>;
runCommandWithCheck(db: string, spec: Document, options?: CommandOptions, dbOptions?: DatabaseOptions): Promise<any>;
dropDatabase(database: string, writeConcern?: WriteConcern, dbOptions?: DatabaseOptions): Promise<Result>;
bulkWrite(database: string, collection: string, requests: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<BulkWriteResult>;
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>;
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>;
replaceOne(database: string, collection: string, filter: Document, replacement: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
updateMany(database: string, collection: string, filter: Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
findAndModify(database: string, collection: string, query: Document, sort: any[] | Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): any;
updateOne(database: string, collection: string, filter: Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;
deleteMany(database: string, collection: string, filter: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<DeleteWriteResult>;
deleteOne(database: string, collection: string, filter: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<DeleteWriteResult>;
findOneAndDelete(database: string, collection: string, filter: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<FindAndModifyResult>;
findOneAndReplace(database: string, collection: string, filter: Document, replacement: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<FindAndModifyResult>;
findOneAndUpdate(database: string, collection: string, filter: Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<FindAndModifyResult>;
insertMany(database: string, collection: string, docs: Document[], options?: Document, dbOptions?: DatabaseOptions): Promise<InsertManyResult>;
insertOne(database: string, collection: string, doc: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<InsertOneResult>;
replaceOne(database: string, collection: string, filter: Document, replacement: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<ReplaceResult>;
updateMany(database: string, collection: string, filter: Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<UpdateResult>;
findAndModify(database: string, collection: string, query: Document, sort: any[] | Document | undefined, update: Document | undefined, options?: Document, dbOptions?: DatabaseOptions): Promise<FindAndModifyResult>;
updateOne(database: string, collection: string, filter: Document, update: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<UpdateResult>;
save(database: string, collection: string, doc: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;

@@ -34,1 +81,2 @@ remove(database: string, collection: string, query: Document, options?: Document, dbOptions?: DatabaseOptions): Promise<Result>;

}
export {};
{
"name": "@mongosh/service-provider-core",
"version": "0.5.0",
"version": "0.5.1",
"description": "MongoDB Shell Core Service Provider Package",

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

"dependencies": {
"@mongosh/errors": "^0.5.0",
"@mongosh/i18n": "^0.5.0",
"bson": "4.0.4",
"mongodb-build-info": "^1.0.0"
"@mongosh/errors": "^0.5.1",
"@mongosh/i18n": "^0.5.1",
"bson": "^4.2.0",
"mongodb-build-info": "^1.1.1"
},

@@ -48,3 +48,3 @@ "dependency-check": {

},
"gitHead": "3b9b52c082c7e1c3c42e8d73d14c4cd0f05155bf"
"gitHead": "c81dccda2cc98d1d926a3acbac66240e5ed4f73c"
}

@@ -50,2 +50,31 @@ import Document from './document';

export default interface ServiceProviderBulkOp {
/**
* Internal state
*/
s: {
batches: BulkBatch[];
currentUpdateBatch: BulkBatch;
currentRemoveBatch: BulkBatch;
currentInsertBatch: BulkBatch;
currentBatch: BulkBatch;
};
/**
* Execute the operation.
*/
execute(): Promise<DriverBulkResult>;
/**
* Find
*/
find(document: Document): ServiceProviderBulkFindOp;
/**
* Insert
*/
insert(document: Document): ServiceProviderBulkOp;
}
export interface ServiceProviderBulkFindOp {

@@ -82,30 +111,1 @@ /**

}
export default interface ServiceProviderBulkOp {
/**
* Internal state
*/
s: {
batches: BulkBatch[];
currentUpdateBatch: BulkBatch;
currentRemoveBatch: BulkBatch;
currentInsertBatch: BulkBatch;
currentBatch: BulkBatch;
};
/**
* Execute the operation.
*/
execute(): Promise<DriverBulkResult>;
/**
* Find
*/
find(document: Document): ServiceProviderBulkFindOp;
/**
* Insert
*/
insert(document: Document): ServiceProviderBulkOp;
}

@@ -7,3 +7,3 @@ export default interface Closable {

*/
close(boolean): Promise<void>;
close(force: boolean): Promise<void>;
}

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

/* eslint camelcase: 0, @typescript-eslint/camelcase: 0 */
/* eslint camelcase: 0, camelcase: 0 */
import { expect } from 'chai';

@@ -3,0 +3,0 @@ import getConnectInfo from './connect-info';

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

/* eslint camelcase: 0, @typescript-eslint/camelcase: 0 */
/* eslint-disable camelcase */
// ^ segment data is in snake_case: forgive me javascript, for i have sinned.

@@ -3,0 +3,0 @@

@@ -36,10 +36,2 @@ import Document from './document';

addCursorFlag(flag: CursorFlag, value: boolean): any;
/**
* Add a cursor flag as an option to the cursor.
*
* @param {number} option - The flag number.
*
* @returns {ServiceProviderCursor} The cursor.
*/
addOption(option: number): ServiceProviderCursor;

@@ -56,9 +48,2 @@ /**

/**
* Set cursor to allow partial results.
*
* @returns {ServiceProviderCursor} The cursor.
*/
allowPartialResults(): ServiceProviderCursor;
/**
* Set the cursor batch size.

@@ -77,3 +62,3 @@ *

*/
close(options: Document): Promise<void>;
close(options: Document): Promise<unknown>;

@@ -120,3 +105,3 @@ /**

forEach(f): Promise<void>;
forEach(f: (doc: Document) => void): Promise<void>;

@@ -140,12 +125,2 @@ /**

/**
* cursor.isExhausted() returns true if the cursor is closed and there are no
* remaining objects in the batch.
*
* @returns Promise<boolean> - whether the cursor is exhausted
*/
isExhausted(): Promise<boolean>;
itcount(): Promise<number>;
/**
* Set the limit of documents to return.

@@ -159,3 +134,3 @@ *

map(f): ServiceProviderCursor;
map(f: (doc: Document) => Document): ServiceProviderCursor;

@@ -201,16 +176,2 @@ /**

/**
* Tell the cursor not to timeout.
*
* @returns {ServiceProviderCursor} The cursor.
*/
noServiceProviderCursorTimeout(): ServiceProviderCursor;
/**
* CursorFlag the cursor as an oplog replay.
*
* @returns {ServiceProviderCursor} The cursor.
*/
oplogReplay(): ServiceProviderCursor;
/**
* Set the projection on the cursor.

@@ -233,4 +194,2 @@ *

size(): Promise<number>;
/**

@@ -255,18 +214,2 @@ * Set the skip value.

/**
* CursorFlag the cursor as tailable.
*
* @returns {ServiceProviderCursor} The cursor.
*/
tailable(): ServiceProviderCursor;
/**
* Set read preference for the cursor.
*
* @param {string} mode - the read preference mode
* @param {Document[]} [tagSet] - the tag set
* @returns {ServiceProviderCursor}
*/
readPref(mode: string, tagSet?: Document[]): ServiceProviderCursor;
/**
* Get the documents from the cursor as an array of objects.

@@ -273,0 +216,0 @@ */

@@ -18,4 +18,5 @@ import ServiceProvider, { ServiceProviderCore } from './service-provider';

const DEFAULT_DB = 'test';
import bson from 'bson';
import * as bson from 'bson';
import ServiceProviderBulkOp, { ServiceProviderBulkFindOp, BulkBatch } from './bulk';
import makePrintableBson, { bsonStringifiers } from './printable-bson';

@@ -46,2 +47,4 @@ export {

bson,
makePrintableBson,
bsonStringifiers,
ServiceProviderBulkFindOp,

@@ -48,0 +51,0 @@ ServiceProviderBulkOp,

@@ -1,19 +0,10 @@

import BSON from 'bson';
/**
* This method modifies the BSON class passed in as argument. This is required so that
* we can have the driver return our BSON classes without having to write our own serializer.
* @param {Object} bson
*/
export default function(bson): void {
if (!bson) {
bson = BSON;
}
const toString = require('util').inspect.custom || 'inspect';
import * as BSON from 'bson';
const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
bson.ObjectId.prototype[toString] = function(): string {
export const bsonStringifiers: Record<string, (this: any) => string> = {
ObjectID: function(): string {
return `ObjectId("${this.toHexString()}")`;
};
bson.ObjectId.prototype.asPrintable = bson.ObjectId.prototype[toString];
},
bson.DBRef.prototype[toString] = function(): string {
DBRef: function(): string {
// NOTE: if OID is an ObjectId class it will just print the oid string.

@@ -25,59 +16,48 @@ return `DBRef("${this.namespace}", "${

}"${this.db ? `, "${this.db}"` : ''})`;
};
bson.DBRef.prototype.asPrintable = bson.DBRef.prototype[toString];
},
bson.MaxKey.prototype[toString] = function(): string {
MaxKey: function(): string {
return '{ "$maxKey" : 1 }';
};
bson.MaxKey.prototype.asPrintable = bson.MaxKey.prototype[toString];
},
bson.MinKey.prototype[toString] = function(): string {
MinKey: function(): string {
return '{ "$minKey" : 1 }';
};
bson.MinKey.prototype.asPrintable = bson.MinKey.prototype[toString];
},
bson.Timestamp.prototype[toString] = function(): string {
Timestamp: function(): string {
return `Timestamp(${this.getLowBits().toString()}, ${this.getHighBits().toString()})`;
};
bson.Timestamp.prototype.asPrintable = bson.Timestamp.prototype[toString];
},
// The old shell could not print Symbols so this was undefined behavior
if ('Symbol' in bson) {
bson.Symbol.prototype[toString] = function(): string {
return `"${this.valueOf()}"`;
};
}
if ('BSONSymbol' in bson) {
bson.BSONSymbol.prototype[toString] = function(): string {
return `"${this.valueOf()}"`;
};
}
Symbol: function(): string {
return `"${this.valueOf()}"`;
},
bson.Code.prototype[toString] = function(): string {
BSONSymbol: function(): string {
return `"${this.valueOf()}"`;
},
Code: function(): string {
const j = this.toJSON();
return `{ "code" : "${j.code}"${j.scope ? `, "scope" : ${JSON.stringify(j.scope)}` : ''} }`;
};
bson.Code.prototype.asPrintable = bson.Code.prototype[toString];
},
bson.Decimal128.prototype[toString] = function(): string {
Decimal128: function(): string {
return `NumberDecimal("${this.toString()}")`;
};
bson.Decimal128.prototype.asPrintable = bson.Decimal128.prototype[toString];
},
bson.Int32.prototype[toString] = function(): string {
Int32: function(): string {
return `NumberInt(${this.valueOf()})`;
};
bson.Int32.prototype.asPrintable = bson.Int32.prototype[toString];
},
bson.Long.prototype[toString] = function(): string {
Long: function(): string {
return `NumberLong("${this.toString()}")`;
};
bson.Long.prototype.asPrintable = bson.Long.prototype[toString];
},
bson.Binary.prototype[toString] = function(): string {
Binary: function(): string {
const asBuffer = this.value(true);
switch (this.sub_type) {
case bson.Binary.SUBTYPE_MD5:
case BSON.Binary.SUBTYPE_MD5:
return `MD5("${asBuffer.toString('hex')}")`;
case bson.Binary.SUBTYPE_UUID:
case BSON.Binary.SUBTYPE_UUID:
if (asBuffer.length === 16) {

@@ -97,4 +77,32 @@ // Format '0123456789abcdef0123456789abcdef' into

}
};
bson.Binary.prototype.asPrintable = bson.Binary.prototype[toString];
},
};
bsonStringifiers.ObjectId = bsonStringifiers.ObjectID;
/**
* This method modifies the BSON class passed in as argument. This is required so that
* we can have the driver return our BSON classes without having to write our own serializer.
* @param {Object} bson
*/
export default function(bson?: any): void {
if (!bson) {
bson = BSON;
}
for (const [ key, stringifier ] of Object.entries(bsonStringifiers)) {
if (!(key in bson)) {
continue;
}
const cls = bson[key];
for (const key of [inspectCustom, 'inspect']) {
try {
(cls as any).prototype[key] = stringifier;
} catch {
// This may fail because bson.ObjectId.prototype[toString] can exist as a
// read-only property. https://github.com/mongodb/js-bson/pull/412 takes
// care of this. In the CLI repl and Compass this still works fine, because
// those are on bson@1.x.
}
}
}
}

@@ -64,3 +64,3 @@ import Document from './document';

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<number>;

@@ -83,3 +83,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<number>;

@@ -120,3 +120,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<number>;

@@ -160,3 +160,3 @@ /**

collection: string,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<any>;

@@ -176,3 +176,3 @@ /**

collection: string,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<any[]>;

@@ -193,3 +193,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<any[]>;

@@ -211,4 +211,4 @@ /**

dbOptions?: DatabaseOptions
): Promise<Result>;
): Promise<any>;
}
/* eslint no-undef: 0 */
type Result = any;
type Result = unknown;
export default Result;

@@ -6,2 +6,3 @@ import Readable from './readable';

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

@@ -15,4 +16,4 @@

export class ServiceProviderCore {
public bsonLibrary;
constructor(bsonLibrary) {
public bsonLibrary: typeof BSON;
constructor(bsonLibrary?: any) {
if (bsonLibrary === undefined) {

@@ -19,0 +20,0 @@ throw new MongoshInternalError('BSON Library is undefined. This is an internal error, please file a ticket!');

@@ -106,3 +106,3 @@ /* eslint complexity: 0*/

function generateUri(options: CliOptions): string {
const uri = options._[0];
const uri = options._?.[0];

@@ -129,3 +129,3 @@ // There is no URI provided, use default 127.0.0.1:27017

let host = parts[1];
let host: string | undefined = parts[1];
const port = parts[2];

@@ -132,0 +132,0 @@ let db = parts[3];

@@ -8,2 +8,36 @@ import Document from './document';

type DeleteWriteResult = {
result: {
ok?: number;
n?: number;
};
connection?: any;
deletedCount?: number;
};
type FindAndModifyResult = {
value?: any;
lastErrorObject?: any;
ok?: number;
};
type InsertResult = {
insertedCount: number;
ops: any[];
connection: any;
result: { ok: number; n: number };
};
type InsertOneResult = InsertResult & { insertedId: any };
type InsertManyResult = InsertResult & { insertedIds: { [key: number]: any } };
type UpdateResult = {
result: { ok: number; n: number; nModified: number };
connection: any;
matchedCount: number;
modifiedCount: number;
upsertedCount: number;
upsertedId: { _id: any };
};
type ReplaceResult = UpdateResult & { ops: any [] };
/**

@@ -26,3 +60,3 @@ * Interface for write operations in the CRUD specification.

dbOptions?: DatabaseOptions
): Promise<Result>;
): Promise<any>;

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

dbOptions?: DatabaseOptions
): Promise<Result>;
): Promise<any>;

@@ -93,3 +127,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<DeleteWriteResult>;

@@ -112,3 +146,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<DeleteWriteResult>;

@@ -131,3 +165,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<FindAndModifyResult>;

@@ -152,3 +186,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<FindAndModifyResult>;

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

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<FindAndModifyResult>;

@@ -192,3 +226,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<InsertManyResult>;

@@ -211,3 +245,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<InsertOneResult>;

@@ -232,3 +266,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<ReplaceResult>;

@@ -253,3 +287,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<UpdateResult>;

@@ -273,7 +307,7 @@ /**

query: Document,
sort: any[] | Document,
update: Document,
sort: any[] | Document | undefined,
update: Document | undefined,
options?: Document,
dbOptions?: DatabaseOptions
);
): Promise<FindAndModifyResult>;

@@ -298,3 +332,3 @@ /**

options?: Document,
dbOptions?: DatabaseOptions): Promise<Result>;
dbOptions?: DatabaseOptions): Promise<UpdateResult>;

@@ -301,0 +335,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

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