Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/service-provider-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
Map,
calculateObjectSize,
Double,
EJSON
EJSON,
BSONRegExp
} from 'bson';
import { bsonStringifiers } from './printable-bson';
import ShellAuthOptions from './shell-auth-options';
Expand All @@ -43,7 +44,8 @@ const bson = {
Map,
calculateObjectSize,
Double,
EJSON
EJSON,
BSONRegExp
};

export {
Expand Down
4 changes: 4 additions & 0 deletions packages/service-provider-core/src/printable-bson.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ describe('BSON printers', function() {
expect(inspect(new bson.Binary('abc'))).to.equal('Binary(Buffer.from("616263", "hex"), 0)');
});

it('formats BSONRegExp correctly', function() {
expect(inspect(new bson.BSONRegExp('(?-i)AA_', 'im'))).to.equal('BSONRegExp("(?-i)AA_", "im")');
});

it('formats UUIDs correctly', function() {
expect(inspect(new bson.Binary(Buffer.from('0123456789abcdef0123456789abcdef', 'hex'), 4)))
.to.equal('UUID("01234567-89ab-cdef-0123-456789abcdef")');
Expand Down
4 changes: 4 additions & 0 deletions packages/service-provider-core/src/printable-bson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const bsonStringifiers: Record<string, (this: any) => string> = {
return `Long("${this.toString()}"${this.unsigned ? ', true' : ''})`;
},

BSONRegExp: function(): string {
return `BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(this.options)})`;
},

Binary: function(): string {
const asBuffer = this.value(true);
switch (this.sub_type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AuthMechanism,
MongoClient,
ReadPreference,
BSONRegExp,
Binary,
Code,
DBRef,
Expand Down Expand Up @@ -101,7 +102,8 @@ const bsonlib = {
BSONSymbol,
Map: BSON.Map,
calculateObjectSize: BSON.calculateObjectSize,
EJSON: BSON.EJSON
EJSON: BSON.EJSON,
BSONRegExp
};

type DropDatabaseResult = {
Expand Down
6 changes: 4 additions & 2 deletions packages/shell-api/src/shell-bson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ function constructHelp(className: string): Help {
export default function constructShellBson(bson: typeof BSON, printWarning: (msg: string) => void): any {
const bsonNames = [
'Binary', 'Code', 'DBRef', 'Decimal128', 'Double', 'Int32', 'Long',
'MaxKey', 'MinKey', 'ObjectId', 'Timestamp', 'Map', 'BSONSymbol'
'MaxKey', 'MinKey', 'ObjectId', 'Timestamp', 'Map', 'BSONSymbol',
'BSONRegExp'
] as const; // Statically set this so we can error if any are missing

// If the service provider doesn't provide a BSON version, use service-provider-core's BSON package (js-bson 4.x)
Expand Down Expand Up @@ -153,7 +154,8 @@ export default function constructShellBson(bson: typeof BSON, printWarning: (msg
Long: bson.Long,
Binary: bson.Binary,
Double: bson.Double,
EJSON: bson.EJSON
EJSON: bson.EJSON,
BSONRegExp: bson.BSONRegExp
} as any;

Object.keys(bsonPkg).forEach((className) => {
Expand Down