Socket
Socket
Sign inDemoInstall

@mongosh/service-provider-core

Package Overview
Dependencies
Maintainers
13
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 1.10.6 to 2.0.0

lib/bson-export.d.ts

4

lib/admin.d.ts

@@ -5,3 +5,3 @@ import type ShellAuthOptions from './shell-auth-options';

import type { ReplPlatform } from './platform';
import type { AWSEncryptionKeyOptions, AzureEncryptionKeyOptions, ClientEncryption as MongoCryptClientEncryption, ClientEncryptionDataKeyProvider, FLE, GCPEncryptionKeyOptions } from './all-fle-types';
import type { AWSEncryptionKeyOptions, AzureEncryptionKeyOptions, ClientEncryption as MongoCryptClientEncryption, ClientEncryptionDataKeyProvider, GCPEncryptionKeyOptions, ClientEncryption, ClientEncryptionOptions } from './all-fle-types';
export interface CreateEncryptedCollectionOptions {

@@ -40,3 +40,3 @@ provider: ClientEncryptionDataKeyProvider;

getRawClient(): any;
fle?: FLE | undefined;
createClientEncryption?(options: ClientEncryptionOptions): ClientEncryption;
getFleOptions?: () => AutoEncryptionOptions | undefined;

@@ -43,0 +43,0 @@ createEncryptedCollection?(dbName: string, collName: string, options: CreateEncryptedCollectionOptions, libmongocrypt: MongoCryptClientEncryption): Promise<{

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

export type { AWSEncryptionKeyOptions, AzureEncryptionKeyOptions, GCPEncryptionKeyOptions, ClientEncryption, ClientEncryptionCreateDataKeyCallback, ClientEncryptionCreateDataKeyProviderOptions, ClientEncryptionDataKeyProvider, ClientEncryptionDecryptCallback, ClientEncryptionEncryptCallback, ClientEncryptionEncryptOptions, ClientEncryptionOptions, ClientEncryptionTlsOptions, KMSProviders, } from 'mongodb-client-encryption';
export type FLE = typeof import('mongodb-client-encryption');
export type { AWSEncryptionKeyOptions, AzureEncryptionKeyOptions, GCPEncryptionKeyOptions, ClientEncryption, ClientEncryptionCreateDataKeyProviderOptions, ClientEncryptionDataKeyProvider, ClientEncryptionEncryptOptions, ClientEncryptionOptions, ClientEncryptionTlsOptions, KMSProviders, } from 'mongodb';

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

export type { AggregateOptions, AggregationCursor, AnyBulkWriteOperation, Batch, BulkWriteOptions, BulkWriteResult, ChangeStream, ChangeStreamOptions, ClientSession, CloseOptions, CollationOptions, CollStatsOptions, Collection, CommandOperationOptions, CountDocumentsOptions, CountOptions, CreateCollectionOptions, CreateIndexesOptions, ClientSessionOptions, ClusterTime, FindCursor, CursorFlag, RunCommandCursor, Db, DbOptions, DeleteOptions, DeleteResult, DistinctOptions, Document, DropCollectionOptions, DropDatabaseOptions, EstimatedDocumentCountOptions, ExplainOptions, ExplainVerbosityLike, FindOneAndDeleteOptions, FindOneAndUpdateOptions, FindOneAndReplaceOptions, FindOperators, FindOptions, HedgeOptions, IndexDescription, InsertManyResult, InsertOneOptions, InsertOneResult, ListCollectionsOptions, ListDatabasesOptions, ListIndexesOptions, MongoClientOptions, OrderedBulkOperation, ReadConcern, ReadConcernLike, ReadConcernLevel, ReadPreference, ReadPreferenceLike, ReadPreferenceFromOptions, ReadPreferenceMode, RenameOptions, ReplaceOptions, ResumeToken, RunCommandOptions, ServerSessionId, TagSet, TransactionOptions, UpdateOptions, UpdateResult, UnorderedBulkOperation, WriteConcern, ObjectId as ObjectIdType, Timestamp as TimestampType, Binary as BinaryType, TopologyDescription, TopologyType, ServerType, AutoEncryptionOptions, ServerApi, ServerApiVersion, MongoClient, } from 'mongodb';
export type { AggregateOptions, AggregationCursor, AnyBulkWriteOperation, Batch, BulkWriteOptions, BulkWriteResult, ChangeStream, ChangeStreamOptions, ClientSession, CloseOptions, CollationOptions, Collection, CommandOperationOptions, CountDocumentsOptions, CountOptions, CreateCollectionOptions, CreateIndexesOptions, ClientSessionOptions, ClusterTime, FindCursor, CursorFlag, RunCommandCursor, Db, DbOptions, DeleteOptions, DeleteResult, DistinctOptions, Document, DropCollectionOptions, DropDatabaseOptions, EstimatedDocumentCountOptions, ExplainOptions, ExplainVerbosityLike, FindOneAndDeleteOptions, FindOneAndUpdateOptions, FindOneAndReplaceOptions, FindOperators, FindOptions, HedgeOptions, IndexDescription, InsertManyResult, InsertOneOptions, InsertOneResult, ListCollectionsOptions, ListDatabasesOptions, ListIndexesOptions, MongoClientOptions, OrderedBulkOperation, ReadConcern, ReadConcernLike, ReadConcernLevel, ReadPreference, ReadPreferenceLike, ReadPreferenceFromOptions, ReadPreferenceMode, RenameOptions, ReplaceOptions, ResumeToken, RunCommandOptions, ServerSessionId, TagSet, TransactionOptions, UpdateOptions, UpdateResult, UnorderedBulkOperation, WriteConcern, ObjectId as ObjectIdType, Timestamp as TimestampType, Binary as BinaryType, TopologyDescription, TopologyType, ServerType, AutoEncryptionOptions, ServerApi, ServerApiVersion, MongoClient, } from 'mongodb';

@@ -12,2 +12,3 @@ export interface ConnectInfo {

is_data_federation: boolean;
is_stream: boolean;
dl_version?: string;

@@ -19,3 +20,4 @@ atlas_version?: string;

uri: string;
is_local_atlas: boolean;
}
export default function getConnectInfo(uri: string, mongoshVersion: string, buildInfo: any, atlasVersion: any, topology: any): ConnectInfo;
export default function getConnectInfo(uri: string, mongoshVersion: string, buildInfo: any, atlasVersion: any, topology: any, isLocalAtlas: boolean): ConnectInfo;

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

const mongodb_build_info_1 = __importDefault(require("mongodb-build-info"));
function getConnectInfo(uri, mongoshVersion, buildInfo, atlasVersion, topology) {
function getConnectInfo(uri, mongoshVersion, buildInfo, atlasVersion, topology, isLocalAtlas) {
var _a;

@@ -30,2 +30,3 @@ buildInfo !== null && buildInfo !== void 0 ? buildInfo : (buildInfo = {});

is_data_federation,
is_stream: mongodb_build_info_1.default.isAtlasStream(uri),
dl_version,

@@ -35,2 +36,3 @@ atlas_version: (_a = atlasVersion === null || atlasVersion === void 0 ? void 0 : atlasVersion.atlasVersion) !== null && _a !== void 0 ? _a : null,

non_genuine_server_name,
is_local_atlas: isLocalAtlas,
};

@@ -37,0 +39,0 @@ }

@@ -6,3 +6,2 @@ import './textencoder-polyfill';

declare const DEFAULT_DB = "test";
import { ObjectId, DBRef, MaxKey, MinKey, Timestamp, BSONSymbol, Code, Decimal128, Int32, Long, Binary, calculateObjectSize, Double, BSONRegExp } from 'bson';
import { bsonStringifiers } from './printable-bson';

@@ -14,24 +13,3 @@ import ShellAuthOptions from './shell-auth-options';

export { CreateEncryptedCollectionOptions, CheckMetadataConsistencyOptions, } from './admin';
declare const bson: {
ObjectId: typeof ObjectId;
DBRef: typeof DBRef;
MaxKey: typeof MaxKey;
MinKey: typeof MinKey;
Timestamp: typeof Timestamp;
BSONSymbol: typeof BSONSymbol;
Code: typeof Code;
Decimal128: typeof Decimal128;
Int32: typeof Int32;
Long: typeof Long;
Binary: typeof Binary;
calculateObjectSize: typeof calculateObjectSize;
Double: typeof Double;
EJSON: {
parse: (text: string, options?: import("bson").EJSONOptions | undefined) => any;
stringify: (value: any, replacer?: (string | number)[] | import("bson").EJSONOptions | ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined, options?: import("bson").EJSONOptions | undefined) => string;
serialize: (value: any, options?: import("bson").EJSONOptions | undefined) => import("bson").Document;
deserialize: (ejson: import("bson").Document, options?: import("bson").EJSONOptions | undefined) => any;
};
BSONRegExp: typeof BSONRegExp;
};
export { ServiceProvider, ShellAuthOptions, getConnectInfo, ReplPlatform, DEFAULT_DB, ServiceProviderCore, bson, bsonStringifiers, ConnectInfo, };
export { bson } from './bson-export';
export { ServiceProvider, ShellAuthOptions, getConnectInfo, ReplPlatform, DEFAULT_DB, ServiceProviderCore, bsonStringifiers, ConnectInfo, };

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.bsonStringifiers = exports.bson = exports.ServiceProviderCore = exports.DEFAULT_DB = exports.getConnectInfo = void 0;
exports.bsonStringifiers = exports.ServiceProviderCore = exports.DEFAULT_DB = exports.getConnectInfo = exports.bson = void 0;
require("./textencoder-polyfill");

@@ -29,3 +29,2 @@ const service_provider_1 = require("./service-provider");

exports.DEFAULT_DB = DEFAULT_DB;
const bson_1 = require("bson");
const printable_bson_1 = require("./printable-bson");

@@ -35,20 +34,4 @@ Object.defineProperty(exports, "bsonStringifiers", { enumerable: true, get: function () { return printable_bson_1.bsonStringifiers; } });

__exportStar(require("./all-fle-types"), exports);
const bson = {
ObjectId: bson_1.ObjectId,
DBRef: bson_1.DBRef,
MaxKey: bson_1.MaxKey,
MinKey: bson_1.MinKey,
Timestamp: bson_1.Timestamp,
BSONSymbol: bson_1.BSONSymbol,
Code: bson_1.Code,
Decimal128: bson_1.Decimal128,
Int32: bson_1.Int32,
Long: bson_1.Long,
Binary: bson_1.Binary,
calculateObjectSize: bson_1.calculateObjectSize,
Double: bson_1.Double,
EJSON: bson_1.EJSON,
BSONRegExp: bson_1.BSONRegExp,
};
exports.bson = bson;
var bson_export_1 = require("./bson-export");
Object.defineProperty(exports, "bson", { enumerable: true, get: function () { return bson_export_1.bson; } });
//# sourceMappingURL=index.js.map

@@ -1,3 +0,5 @@

import { bson as BSON } from './index';
export declare const bsonStringifiers: Record<string, (this: any, depth: any, options: any) => string>;
export default function (bson?: typeof BSON): void;
import { bson as BSON } from './bson-export';
type BSONClassKey = (typeof BSON)[Exclude<keyof typeof BSON, 'EJSON' | 'calculateObjectSize'>]['prototype']['_bsontype'];
export declare const bsonStringifiers: Record<BSONClassKey | 'ObjectID', (this: any, depth: any, options: any) => string>;
export declare function makePrintableBson(bson?: typeof BSON): void;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bsonStringifiers = void 0;
const index_1 = require("./index");
exports.makePrintableBson = exports.bsonStringifiers = void 0;
const bson_export_1 = require("./bson-export");
const util_1 = require("util");
const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
function removeNewFromInspectResult(str) {
return String(str).replace(/^(\s*)(new )/, '$1');
}
function makeClasslessInspect(className) {
const originalInspect = bson_export_1.bson[className].prototype.inspect;
return function (...args) {
return removeNewFromInspectResult(originalInspect.apply(this, args));
};
}
exports.bsonStringifiers = {
ObjectId: function () {
return `ObjectId("${this.toHexString()}")`;
},
ObjectId: makeClasslessInspect('ObjectId'),
ObjectID: makeClasslessInspect('ObjectId'),
DBRef: function (depth, options) {
return (`DBRef("${this.collection}", ` +
(0, util_1.inspect)(this.oid, options) +
(this.db ? `, "${this.db}"` : '') +
(this.db ? `, ${(0, util_1.inspect)(this.db, options)}` : '') +
')');
},
MaxKey: function () {
return 'MaxKey()';
},
MinKey: function () {
return 'MinKey()';
},
Timestamp: function () {
return `Timestamp({ t: ${this.getHighBits()}, i: ${this.getLowBits()} })`;
},
BSONSymbol: function () {
return `BSONSymbol("${this.valueOf()}")`;
},
Code: function () {
const j = this.toJSON();
return `Code("${j.code}"${j.scope ? `, ${JSON.stringify(j.scope)}` : ''})`;
},
Decimal128: function () {
return `Decimal128("${this.toString()}")`;
},
Int32: function () {
return `Int32(${this.valueOf()})`;
},
Long: function () {
return `Long("${this.toString()}"${this.unsigned ? ', true' : ''})`;
},
BSONRegExp: function () {
return `BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(this.options)})`;
},
MaxKey: makeClasslessInspect('MaxKey'),
MinKey: makeClasslessInspect('MinKey'),
Timestamp: makeClasslessInspect('Timestamp'),
BSONSymbol: makeClasslessInspect('BSONSymbol'),
Code: makeClasslessInspect('Code'),
Decimal128: makeClasslessInspect('Decimal128'),
Int32: makeClasslessInspect('Int32'),
Long: makeClasslessInspect('Long'),
Double: makeClasslessInspect('Double'),
BSONRegExp: makeClasslessInspect('BSONRegExp'),
Binary: function () {
const hexString = this.toString('hex');
switch (this.sub_type) {
case index_1.bson.Binary.SUBTYPE_MD5:
case bson_export_1.bson.Binary.SUBTYPE_MD5:
return `MD5("${hexString}")`;
case index_1.bson.Binary.SUBTYPE_UUID:
case bson_export_1.bson.Binary.SUBTYPE_UUID:
if (hexString.length === 32) {

@@ -59,10 +49,9 @@ const asUUID = /^(.{8})(.{4})(.{4})(.{4})(.{12})$/

default:
return `Binary(Buffer.from("${hexString}", "hex"), ${this.sub_type})`;
return `Binary.createFromBase64("${this.toString('base64')}", ${this.sub_type})`;
}
},
};
exports.bsonStringifiers.ObjectID = exports.bsonStringifiers.ObjectId;
function default_1(bson) {
function makePrintableBson(bson) {
if (!bson) {
bson = index_1.bson;
bson = bson_export_1.bson;
}

@@ -75,11 +64,7 @@ for (const [key, stringifier] of Object.entries(exports.bsonStringifiers)) {

for (const key of [inspectCustom, 'inspect']) {
try {
cls.prototype[key] = stringifier;
}
catch (_a) {
}
cls.prototype[key] = stringifier;
}
}
}
exports.default = default_1;
exports.makePrintableBson = makePrintableBson;
//# sourceMappingURL=printable-bson.js.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServiceProviderCore = void 0;
const errors_1 = require("@mongosh/errors");
const printable_bson_1 = __importDefault(require("./printable-bson"));
const printable_bson_1 = require("./printable-bson");
class ServiceProviderCore {

@@ -14,3 +11,3 @@ constructor(bsonLibrary) {

}
(0, printable_bson_1.default)(bsonLibrary);
(0, printable_bson_1.makePrintableBson)(bsonLibrary);
this.bsonLibrary = bsonLibrary;

@@ -17,0 +14,0 @@ }

@@ -11,3 +11,3 @@ import type { RunCommandCursor, RunCursorCommandOptions } from 'mongodb';

deleteOne(database: string, collection: string, filter: Document, options: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
findOneAndDelete(database: string, collection: string, filter: Document, options: FindOneAndDeleteOptions, dbOptions?: DbOptions): Promise<Document>;
findOneAndDelete(database: string, collection: string, filter: Document, options: FindOneAndDeleteOptions, dbOptions?: DbOptions): Promise<Document | null>;
findOneAndReplace(database: string, collection: string, filter: Document, replacement: Document, options: FindOneAndReplaceOptions, dbOptions?: DbOptions): Promise<Document>;

@@ -14,0 +14,0 @@ findOneAndUpdate(database: string, collection: string, filter: Document, update: Document | Document[], options: FindOneAndUpdateOptions, dbOptions?: DbOptions): Promise<Document>;

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

@@ -19,2 +19,4 @@ "main": "lib/index.js",

"test-ci": "node ../../scripts/run-if-package-requested.js npm test",
"test-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test",
"test-ci-coverage": "nyc --no-clean --cwd ../.. --reporter=none npm run test-ci",
"eslint": "eslint",

@@ -46,15 +48,15 @@ "lint": "npm run eslint . && npm run prettier -- --check .",

"@aws-sdk/credential-providers": "^3.347.1",
"@mongosh/errors": "1.10.6",
"bson": "^5.3.0",
"mongodb": "^5.7.0",
"@mongosh/errors": "2.0.0",
"bson": "^6.0.0",
"mongodb": "^6.0.0",
"mongodb-build-info": "^1.6.2",
"mongodb-client-encryption": "^2.8.0"
"mongodb-client-encryption": "^6.0.0"
},
"optionalDependencies": {
"mongodb-client-encryption": "^2.8.0"
"mongodb-client-encryption": "^6.0.0"
},
"devDependencies": {
"@mongodb-js/eslint-config-mongosh": "1.10.6",
"@mongodb-js/eslint-config-mongosh": "^1.0.0",
"@mongodb-js/prettier-config-devtools": "^1.0.1",
"@mongodb-js/tsconfig-mongosh": "1.10.6",
"@mongodb-js/tsconfig-mongosh": "^1.0.0",
"depcheck": "^1.4.3",

@@ -64,3 +66,3 @@ "eslint": "^7.25.0",

},
"gitHead": "6bcde16381f6258d9be713998c67c48a99cfd691"
"gitHead": "60053aa2f37dc6c3e4fe059e806565ec51ece9e8"
}

@@ -23,4 +23,5 @@ import type ShellAuthOptions from './shell-auth-options';

ClientEncryptionDataKeyProvider,
FLE,
GCPEncryptionKeyOptions,
ClientEncryption,
ClientEncryptionOptions,
} from './all-fle-types';

@@ -143,3 +144,3 @@

*/
fle?: FLE | undefined;
createClientEncryption?(options: ClientEncryptionOptions): ClientEncryption;

@@ -146,0 +147,0 @@ /**

@@ -6,7 +6,4 @@ export type {

ClientEncryption,
ClientEncryptionCreateDataKeyCallback,
ClientEncryptionCreateDataKeyProviderOptions,
ClientEncryptionDataKeyProvider,
ClientEncryptionDecryptCallback,
ClientEncryptionEncryptCallback,
ClientEncryptionEncryptOptions,

@@ -16,4 +13,2 @@ ClientEncryptionOptions,

KMSProviders,
} from 'mongodb-client-encryption';
export type FLE = typeof import('mongodb-client-encryption');
} from 'mongodb';

@@ -13,3 +13,2 @@ export type {

CollationOptions,
CollStatsOptions,
Collection,

@@ -16,0 +15,0 @@ CommandOperationOptions,

@@ -74,2 +74,3 @@ import { expect } from 'chai';

is_data_federation: false,
is_stream: false,
dl_version: null,

@@ -83,2 +84,3 @@ atlas_version: '20210330.0.0.1617063608',

uri: ATLAS_URI,
is_local_atlas: false,
};

@@ -91,3 +93,4 @@ expect(

ATLAS_VERSION,
TOPOLOGY_WITH_CREDENTIALS
TOPOLOGY_WITH_CREDENTIALS,
false
)

@@ -107,2 +110,3 @@ ).to.deep.equal(output);

is_data_federation: false,
is_stream: false,
dl_version: null,

@@ -116,2 +120,3 @@ atlas_version: '20210330.0.0.1617063608',

uri: ATLAS_URI,
is_local_atlas: false,
};

@@ -124,3 +129,4 @@ expect(

ATLAS_VERSION,
TOPOLOGY_NO_CREDENTIALS
TOPOLOGY_NO_CREDENTIALS,
false
)

@@ -130,2 +136,37 @@ ).to.deep.equal(output);

it('reports correct information when a stream uri is passed', function () {
const streamUri =
'mongodb://atlas-stream-67b8e1cd6d60357be377be7b-1dekw.virginia-usa.a.query.mongodb-dev.net/';
const output = {
is_atlas: true,
is_localhost: false,
is_do: false,
server_version: '3.2.0-rc2',
mongosh_version: '0.0.6',
is_enterprise: true,
auth_type: 'LDAP',
is_data_federation: false,
is_stream: true,
dl_version: null,
atlas_version: null,
is_genuine: true,
is_local_atlas: false,
non_genuine_server_name: 'mongodb',
server_arch: 'x86_64',
node_version: process.version,
server_os: 'osx',
uri: streamUri,
};
expect(
getConnectInfo(
streamUri,
'0.0.6',
BUILD_INFO,
null,
TOPOLOGY_WITH_CREDENTIALS,
false
)
).to.deep.equal(output);
});
it('reports correct information when an empty uri is passed', function () {

@@ -141,2 +182,3 @@ const output = {

is_data_federation: false,
is_stream: false,
dl_version: null,

@@ -150,5 +192,13 @@ atlas_version: null,

uri: '',
is_local_atlas: true,
};
expect(
getConnectInfo('', '0.0.6', BUILD_INFO, null, TOPOLOGY_WITH_CREDENTIALS)
getConnectInfo(
'',
'0.0.6',
BUILD_INFO,
null,
TOPOLOGY_WITH_CREDENTIALS,
true
)
).to.deep.equal(output);

@@ -167,2 +217,3 @@ });

is_data_federation: false,
is_stream: false,
dl_version: null,

@@ -176,7 +227,8 @@ atlas_version: null,

uri: '',
is_local_atlas: false,
};
expect(
getConnectInfo('', '0.0.6', null, null, TOPOLOGY_WITH_CREDENTIALS)
getConnectInfo('', '0.0.6', null, null, TOPOLOGY_WITH_CREDENTIALS, false)
).to.deep.equal(output);
});
});

@@ -16,2 +16,3 @@ // ^ segment data is in snake_case: forgive me javascript, for i have sinned.

is_data_federation: boolean;
is_stream: boolean;
dl_version?: string;

@@ -23,2 +24,3 @@ atlas_version?: string;

uri: string;
is_local_atlas: boolean;
}

@@ -31,3 +33,4 @@

atlasVersion: any,
topology: any
topology: any,
isLocalAtlas: boolean
): ConnectInfo {

@@ -60,2 +63,3 @@ buildInfo ??= {}; // We're currently not getting buildInfo with --apiStrict.

is_data_federation,
is_stream: getBuildInfo.isAtlasStream(uri),
dl_version,

@@ -65,3 +69,4 @@ atlas_version: atlasVersion?.atlasVersion ?? null,

non_genuine_server_name,
is_local_atlas: isLocalAtlas,
};
}

@@ -6,19 +6,2 @@ import './textencoder-polyfill'; // for mongodb-connection-string-url in the java-shell

const DEFAULT_DB = 'test';
import {
ObjectId,
DBRef,
MaxKey,
MinKey,
Timestamp,
BSONSymbol,
Code,
Decimal128,
Int32,
Long,
Binary,
calculateObjectSize,
Double,
EJSON,
BSONRegExp,
} from 'bson';
import { bsonStringifiers } from './printable-bson';

@@ -36,19 +19,3 @@ import ShellAuthOptions from './shell-auth-options';

const bson = {
ObjectId,
DBRef,
MaxKey,
MinKey,
Timestamp,
BSONSymbol,
Code,
Decimal128,
Int32,
Long,
Binary,
calculateObjectSize,
Double,
EJSON,
BSONRegExp,
};
export { bson } from './bson-export';

@@ -62,5 +29,4 @@ export {

ServiceProviderCore,
bson,
bsonStringifiers,
ConnectInfo,
};
import { expect } from 'chai';
import { bson } from './index';
import { inspect } from 'util';
import makePrintableBson from './printable-bson';
import { makePrintableBson } from './printable-bson';

@@ -22,8 +22,8 @@ describe('BSON printers', function () {

)
).to.equal('DBRef("a", ObjectId("5f16b8bebe434dc98cdfc9cb"), "db")');
).to.equal('DBRef("a", ObjectId("5f16b8bebe434dc98cdfc9cb"), \'db\')');
expect(inspect(new bson.DBRef('a', 'foo' as any, 'db'))).to.equal(
'DBRef("a", \'foo\', "db")'
"DBRef(\"a\", 'foo', 'db')"
);
expect(inspect(new bson.DBRef('a', { x: 1 } as any, 'db'))).to.equal(
'DBRef("a", { x: 1 }, "db")'
'DBRef("a", { x: 1 }, \'db\')'
);

@@ -71,8 +71,2 @@ });

it('formats BinData correctly', function () {
expect(inspect(new bson.Binary('abc'))).to.equal(
'Binary(Buffer.from("616263", "hex"), 0)'
);
});
it('formats BSONRegExp correctly', function () {

@@ -105,2 +99,8 @@ expect(inspect(new bson.BSONRegExp('(?-i)AA_', 'im'))).to.equal(

});
it('formats any other value with the new format using createfromBase64', function () {
expect(
inspect(bson.Binary.createFromBase64('SGVsbG8sIFdvcmxkIQo='))
).to.equal('Binary.createFromBase64("SGVsbG8sIFdvcmxkIQo=", 0)');
});
});

@@ -1,13 +0,33 @@

import { bson as BSON } from './index';
import { bson as BSON } from './bson-export';
import { inspect } from 'util';
const inspectCustom = Symbol.for('nodejs.util.inspect.custom');
type BSONClassKey = (typeof BSON)[Exclude<
keyof typeof BSON,
'EJSON' | 'calculateObjectSize'
>]['prototype']['_bsontype'];
// Turn e.g. 'new Double(...)' into 'Double(...)' but preserve possible leading whitespace
function removeNewFromInspectResult(str: string): string {
return String(str).replace(/^(\s*)(new )/, '$1');
}
// Create a Node.js-util-inspect() style custom inspect function that
// strips 'new ' from inspect results but otherwise uses the Node.js
// driver's bson library's inspect functions.
function makeClasslessInspect<K extends BSONClassKey>(className: K) {
const originalInspect = BSON[className].prototype.inspect;
return function (
this: (typeof BSON)[typeof className]['prototype'],
...args: any
) {
return removeNewFromInspectResult(originalInspect.apply(this, args as any));
};
}
export const bsonStringifiers: Record<
string,
BSONClassKey | 'ObjectID',
(this: any, depth: any, options: any) => string
> = {
ObjectId: function (this: typeof BSON.ObjectId.prototype): string {
return `ObjectId("${this.toHexString()}")`;
},
ObjectId: makeClasslessInspect('ObjectId'),
ObjectID: makeClasslessInspect('ObjectId'),
DBRef: function (

@@ -20,47 +40,17 @@ this: typeof BSON.DBRef.prototype,

`DBRef("${this.collection}", ` +
inspect(this.oid, options) +
(this.db ? `, "${this.db}"` : '') +
inspect(this.oid, options) + // The driver's inspect() does not account for non-ObjectID oid values
(this.db ? `, ${inspect(this.db, options)}` : '') +
')'
);
},
MaxKey: function (this: typeof BSON.MaxKey.prototype): string {
return 'MaxKey()';
},
MinKey: function (this: typeof BSON.MinKey.prototype): string {
return 'MinKey()';
},
Timestamp: function (this: typeof BSON.Timestamp.prototype): string {
return `Timestamp({ t: ${this.getHighBits()}, i: ${this.getLowBits()} })`;
},
BSONSymbol: function (this: typeof BSON.BSONSymbol.prototype): string {
return `BSONSymbol("${this.valueOf()}")`;
},
Code: function (this: typeof BSON.Code.prototype): string {
const j = this.toJSON();
return `Code("${j.code}"${j.scope ? `, ${JSON.stringify(j.scope)}` : ''})`;
},
Decimal128: function (this: typeof BSON.Decimal128.prototype): string {
return `Decimal128("${this.toString()}")`;
},
Int32: function (this: typeof BSON.Int32.prototype): string {
return `Int32(${this.valueOf()})`;
},
Long: function (this: typeof BSON.Long.prototype): string {
return `Long("${this.toString()}"${this.unsigned ? ', true' : ''})`;
},
BSONRegExp: function (this: typeof BSON.BSONRegExp.prototype): string {
return `BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(
this.options
)})`;
},
MaxKey: makeClasslessInspect('MaxKey'),
MinKey: makeClasslessInspect('MinKey'),
Timestamp: makeClasslessInspect('Timestamp'),
BSONSymbol: makeClasslessInspect('BSONSymbol'),
Code: makeClasslessInspect('Code'),
Decimal128: makeClasslessInspect('Decimal128'),
Int32: makeClasslessInspect('Int32'),
Long: makeClasslessInspect('Long'),
Double: makeClasslessInspect('Double'),
BSONRegExp: makeClasslessInspect('BSONRegExp'),
Binary: function (this: typeof BSON.Binary.prototype): string {

@@ -84,7 +74,8 @@ const hexString = this.toString('hex');

default:
return `Binary(Buffer.from("${hexString}", "hex"), ${this.sub_type})`;
return `Binary.createFromBase64("${this.toString('base64')}", ${
this.sub_type
})`;
}
},
};
bsonStringifiers.ObjectID = bsonStringifiers.ObjectId;

@@ -96,3 +87,3 @@ /**

*/
export default function (bson?: typeof BSON): void {
export function makePrintableBson(bson?: typeof BSON): void {
if (!bson) {

@@ -108,12 +99,5 @@ bson = BSON;

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.
}
(cls as any).prototype[key] = stringifier;
}
}
}
import { MongoshInternalError } from '@mongosh/errors';
import type Admin from './admin';
import type Closable from './closable';
import makePrintableBson from './printable-bson';
import { makePrintableBson } from './printable-bson';
import type Readable from './readable';

@@ -6,0 +6,0 @@ import type Writable from './writable';

@@ -13,2 +13,3 @@ // The java-shell doesn't have URL, so we fall back to a pure-JS implementation.

) {
// eslint-disable-next-line @typescript-eslint/no-implied-eval
Object.assign(Function('return this')(), textEncodingPolyfill());

@@ -15,0 +16,0 @@ }

@@ -164,3 +164,3 @@ import type { RunCommandCursor, RunCursorCommandOptions } from 'mongodb';

dbOptions?: DbOptions
): Promise<Document>;
): Promise<Document | null>;

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

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