@mongosh/service-provider-server
Advanced tools
Comparing version 1.7.1 to 1.8.0
import { MongoClient, ReadPreference, ClientMetadata, ReadPreferenceFromOptions, ReadPreferenceLike, OperationOptions } from 'mongodb'; | ||
import { ServiceProvider, getConnectInfo, ReplPlatform, ServiceProviderCore, ShellAuthOptions, AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult, ClientSessionOptions, Collection, CountDocumentsOptions, CountOptions, CreateCollectionOptions, CreateIndexesOptions, FindCursor, Db, DbOptions, DeleteOptions, DeleteResult, DistinctOptions, Document, DropCollectionOptions, DropDatabaseOptions, EstimatedDocumentCountOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, IndexDescription, InsertManyResult, InsertOneOptions, InsertOneResult, ListCollectionsOptions, ListDatabasesOptions, ListIndexesOptions, MongoClientOptions, ReadConcern, RenameOptions, ReplaceOptions, RunCommandOptions, ClientSession, UpdateOptions, UpdateResult, WriteConcern, ChangeStreamOptions, ChangeStream, FLE, AutoEncryptionOptions } from '@mongosh/service-provider-core'; | ||
import { ServiceProvider, getConnectInfo, ReplPlatform, ServiceProviderCore, ShellAuthOptions, AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult, ClientSessionOptions, Collection, CountDocumentsOptions, CountOptions, CreateCollectionOptions, CreateIndexesOptions, FindCursor, Db, DbOptions, DeleteOptions, DeleteResult, DistinctOptions, Document, DropCollectionOptions, DropDatabaseOptions, EstimatedDocumentCountOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, FindOptions, IndexDescription, InsertManyResult, InsertOneOptions, InsertOneResult, ListCollectionsOptions, ListDatabasesOptions, ListIndexesOptions, MongoClientOptions, ReadConcern, RenameOptions, ReplaceOptions, RunCommandOptions, ClientSession, UpdateOptions, UpdateResult, WriteConcern, ChangeStreamOptions, ChangeStream, FLE, AutoEncryptionOptions, ClientEncryption as MongoCryptClientEncryption } from '@mongosh/service-provider-core'; | ||
import { DevtoolsConnectOptions } from '@mongodb-js/devtools-connect'; | ||
import type { MongoshBus } from '@mongosh/types'; | ||
import ConnectionString from 'mongodb-connection-string-url'; | ||
import { CreateEncryptedCollectionOptions } from '@mongosh/service-provider-core'; | ||
declare type DropDatabaseResult = { | ||
@@ -55,3 +56,2 @@ ok: 0 | 1; | ||
insertOne(database: string, collection: string, doc?: Document, options?: InsertOneOptions, dbOptions?: DbOptions): Promise<InsertOneResult>; | ||
remove(database: string, collection: string, query?: Document, options?: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>; | ||
replaceOne(database: string, collection: string, filter?: Document, replacement?: Document, options?: ReplaceOptions, dbOptions?: DbOptions): Promise<UpdateResult>; | ||
@@ -75,2 +75,6 @@ runCommand(database: string, spec?: Document, options?: RunCommandOptions, dbOptions?: DbOptions): Promise<Document>; | ||
}>; | ||
createEncryptedCollection(dbName: string, collName: string, options: CreateEncryptedCollectionOptions, libmongocrypt: MongoCryptClientEncryption): Promise<{ | ||
collection: Collection; | ||
encryptedFields: Document; | ||
}>; | ||
initializeBulkOp(dbName: string, collName: string, ordered: boolean, options?: BulkWriteOptions, dbOptions?: DbOptions): Promise<any>; | ||
@@ -77,0 +81,0 @@ getReadPreference(): ReadPreference; |
@@ -14,18 +14,17 @@ "use strict"; | ||
const bsonlib = { | ||
Binary: mongodb_1.Binary, | ||
Code: mongodb_1.Code, | ||
DBRef: mongodb_1.DBRef, | ||
Double: mongodb_1.Double, | ||
Int32: mongodb_1.Int32, | ||
Long: mongodb_1.Long, | ||
MinKey: mongodb_1.MinKey, | ||
MaxKey: mongodb_1.MaxKey, | ||
ObjectId: mongodb_1.ObjectId, | ||
Timestamp: mongodb_1.Timestamp, | ||
Decimal128: mongodb_1.Decimal128, | ||
BSONSymbol: mongodb_1.BSONSymbol, | ||
Map: service_provider_core_1.bson.Map, | ||
calculateObjectSize: service_provider_core_1.bson.calculateObjectSize, | ||
EJSON: service_provider_core_1.bson.EJSON, | ||
BSONRegExp: mongodb_1.BSONRegExp | ||
Binary: mongodb_1.BSON.Binary, | ||
Code: mongodb_1.BSON.Code, | ||
DBRef: mongodb_1.BSON.DBRef, | ||
Double: mongodb_1.BSON.Double, | ||
Int32: mongodb_1.BSON.Int32, | ||
Long: mongodb_1.BSON.Long, | ||
MinKey: mongodb_1.BSON.MinKey, | ||
MaxKey: mongodb_1.BSON.MaxKey, | ||
ObjectId: mongodb_1.BSON.ObjectId, | ||
Timestamp: mongodb_1.BSON.Timestamp, | ||
Decimal128: mongodb_1.BSON.Decimal128, | ||
BSONSymbol: mongodb_1.BSON.BSONSymbol, | ||
calculateObjectSize: mongodb_1.BSON.calculateObjectSize, | ||
EJSON: mongodb_1.BSON.EJSON, | ||
BSONRegExp: mongodb_1.BSON.BSONRegExp | ||
}; | ||
@@ -245,6 +244,2 @@ const DEFAULT_DRIVER_OPTIONS = Object.freeze({}); | ||
} | ||
remove(database, collection, query = {}, options = {}, dbOptions) { | ||
options = { ...this.baseCmdOptions, ...options }; | ||
return this.db(database, dbOptions).collection(collection).remove(query, options); | ||
} | ||
replaceOne(database, collection, filter = {}, replacement = {}, options = {}, dbOptions) { | ||
@@ -331,2 +326,5 @@ options = { ...this.baseCmdOptions, ...options }; | ||
} | ||
async createEncryptedCollection(dbName, collName, options, libmongocrypt) { | ||
return await libmongocrypt.createEncryptedCollection(this.db(dbName), collName, options); | ||
} | ||
async initializeBulkOp(dbName, collName, ordered, options = {}, dbOptions) { | ||
@@ -333,0 +331,0 @@ if (ordered) { |
{ | ||
"name": "@mongosh/service-provider-server", | ||
"version": "1.7.1", | ||
"version": "1.8.0", | ||
"description": "MongoDB Shell Server Service Provider Package", | ||
@@ -55,11 +55,11 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@mongodb-js/devtools-connect": "^1.4.3", | ||
"@mongosh/errors": "1.7.1", | ||
"@mongosh/service-provider-core": "1.7.1", | ||
"@mongosh/types": "1.7.1", | ||
"@mongodb-js/devtools-connect": "^1.4.4", | ||
"@mongosh/errors": "1.8.0", | ||
"@mongosh/service-provider-core": "1.8.0", | ||
"@mongosh/types": "1.8.0", | ||
"@types/sinon-chai": "^3.2.3", | ||
"aws4": "^1.11.0", | ||
"kerberos": "^2.0.0", | ||
"mongodb": "^4.13.0", | ||
"mongodb-client-encryption": "^2.4.0", | ||
"mongodb": "^5.1.0", | ||
"mongodb-client-encryption": "^2.6.0", | ||
"mongodb-connection-string-url": "^2.6.0", | ||
@@ -70,5 +70,5 @@ "saslprep": "mongodb-js/saslprep#v1.0.4" | ||
"kerberos": "^2.0.0", | ||
"mongodb-client-encryption": "^2.4.0" | ||
"mongodb-client-encryption": "^2.6.0" | ||
}, | ||
"gitHead": "1bf0d7775443ac1849cc2597465d54eca867acea" | ||
"gitHead": "9cf53bc336c79e505cf034bf5e6f3b3b3796cf25" | ||
} |
@@ -422,19 +422,2 @@ import CliServiceProvider from './cli-service-provider'; | ||
describe('#remove', () => { | ||
const filter = { name: 'Aphex Twin' }; | ||
context('when the filter is empty', () => { | ||
let result; | ||
beforeEach(async() => { | ||
result = await serviceProvider.remove('music', 'bands', filter); | ||
}); | ||
it('executes the remove op with and resolves the result', () => { | ||
expect(result.acknowledged).to.equal(true); | ||
expect(result.deletedCount).to.equal(0); | ||
}); | ||
}); | ||
}); | ||
describe('#replaceOne', () => { | ||
@@ -441,0 +424,0 @@ const filter = { name: 'Aphex Twin' }; |
@@ -9,2 +9,3 @@ import { CommonErrors } from '@mongosh/errors'; | ||
import { EventEmitter } from 'events'; | ||
import type { ClientEncryption, ClientEncryptionDataKeyProvider } from '@mongosh/service-provider-core'; | ||
@@ -78,3 +79,3 @@ chai.use(sinonChai); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.bulkWrite.resolves(commandResult); | ||
collectionStub.bulkWrite.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -111,3 +112,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.deleteMany.resolves(commandResult); | ||
collectionStub.deleteMany.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -128,3 +129,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.deleteOne.resolves(commandResult); | ||
collectionStub.deleteOne.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -213,3 +214,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.findOneAndDelete.resolves(commandResult); | ||
collectionStub.findOneAndDelete.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -232,3 +233,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.findOneAndReplace.resolves(commandResult); | ||
collectionStub.findOneAndReplace.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -252,3 +253,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.findOneAndUpdate.resolves(commandResult); | ||
collectionStub.findOneAndUpdate.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -271,3 +272,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.insertMany.resolves(commandResult); | ||
collectionStub.insertMany.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -289,3 +290,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.insertOne.resolves(commandResult); | ||
collectionStub.insertOne.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -384,3 +385,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.updateOne.resolves(commandResult); | ||
collectionStub.updateOne.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -403,3 +404,3 @@ }); | ||
collectionStub = stubInterface<Collection>(); | ||
collectionStub.updateMany.resolves(commandResult); | ||
collectionStub.updateMany.resolves(commandResult as any); | ||
serviceProvider = new CliServiceProvider(createClientStub(collectionStub), bus); | ||
@@ -564,3 +565,3 @@ }); | ||
clientStub = stubInterface<MongoClient>(); | ||
dbStub.renameCollection.resolves({ ok: 1 }); | ||
dbStub.renameCollection.resolves({ ok: 1 } as any); | ||
clientStub.db.returns(dbStub); | ||
@@ -596,9 +597,3 @@ serviceProvider = new CliServiceProvider(clientStub, bus); | ||
clientStub = stubInterface<MongoClient>(); | ||
dbStub.createCollection.resolves({ | ||
toArray: () => { | ||
return Promise.resolve([ | ||
{ collectionType: 1 } | ||
]); | ||
} | ||
}); | ||
dbStub.createCollection.resolves({} as any); | ||
clientStub.db.returns(dbStub); | ||
@@ -616,2 +611,43 @@ serviceProvider = new CliServiceProvider(clientStub, bus); | ||
describe('#createEncryptedCollection', () => { | ||
let dbStub: StubbedInstance<Db>; | ||
let clientStub: StubbedInstance<MongoClient>; | ||
let libmongoc: StubbedInstance<ClientEncryption>; | ||
const createCollOptions = { | ||
provider: 'local' as ClientEncryptionDataKeyProvider, | ||
createCollectionOptions: { | ||
encryptedFields: { | ||
fields: [{ | ||
path: 'ssn', | ||
bsonType: 'string' | ||
}] | ||
} | ||
} | ||
}; | ||
beforeEach(() => { | ||
dbStub = stubInterface<Db>(); | ||
clientStub = stubInterface<MongoClient>(); | ||
clientStub.db.returns(dbStub); | ||
serviceProvider = new CliServiceProvider(clientStub, bus); | ||
libmongoc = stubInterface<ClientEncryption>(); | ||
}); | ||
it('calls calls libmongocrypt.createEncryptedCollection', async() => { | ||
await serviceProvider.createEncryptedCollection('db1', 'coll1', createCollOptions, libmongoc); | ||
expect(libmongoc.createEncryptedCollection).calledOnceWithExactly( | ||
dbStub, | ||
'coll1', | ||
createCollOptions | ||
); | ||
}); | ||
it('returns whatever libmongocrypt.createEncryptedCollection returns', async() => { | ||
const resolvedValue = { collection: { name: 'secretCol' }, encryptedFields: [] } as any; | ||
libmongoc.createEncryptedCollection.resolves(resolvedValue); | ||
const returnValue = await serviceProvider.createEncryptedCollection('db1', 'coll1', createCollOptions, libmongoc); | ||
expect(returnValue).to.deep.equal(resolvedValue); | ||
}); | ||
}); | ||
describe('sessions', () => { | ||
@@ -696,3 +732,4 @@ let clientStub: StubbedInstance<MongoClient>; | ||
clientStub = stubInterface<MongoClient>(); | ||
dbStub.command.callsFake(() => { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
dbStub.command.callsFake(async() => { | ||
return { ok: 1 }; | ||
@@ -743,3 +780,4 @@ }); | ||
it('correctly gathers info on the fake deployment', async() => { | ||
dbStub.command.callsFake((params) => { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
dbStub.command.callsFake(async(params) => { | ||
if (params.buildInfo) { | ||
@@ -746,0 +784,0 @@ return { ok: 1, _t: 1 }; |
@@ -6,19 +6,7 @@ import { | ||
ReadPreference, | ||
BSONRegExp, | ||
Binary, | ||
Code, | ||
DBRef, | ||
Double, | ||
Int32, | ||
Long, | ||
MinKey, | ||
MaxKey, | ||
ObjectId, | ||
Timestamp, | ||
Decimal128, | ||
BSONSymbol, | ||
ClientMetadata, | ||
ReadPreferenceFromOptions, | ||
ReadPreferenceLike, | ||
OperationOptions | ||
OperationOptions, | ||
BSON | ||
} from 'mongodb'; | ||
@@ -77,5 +65,5 @@ | ||
ChangeStream, | ||
bson as BSON, | ||
FLE, | ||
AutoEncryptionOptions | ||
AutoEncryptionOptions, | ||
ClientEncryption as MongoCryptClientEncryption | ||
} from '@mongosh/service-provider-core'; | ||
@@ -89,20 +77,20 @@ | ||
import { EventEmitter } from 'events'; | ||
import { CreateEncryptedCollectionOptions } from '@mongosh/service-provider-core'; | ||
const bsonlib = { | ||
Binary, | ||
Code, | ||
DBRef, | ||
Double, | ||
Int32, | ||
Long, | ||
MinKey, | ||
MaxKey, | ||
ObjectId, | ||
Timestamp, | ||
Decimal128, | ||
BSONSymbol, | ||
Map: BSON.Map, | ||
Binary: BSON.Binary, | ||
Code: BSON.Code, | ||
DBRef: BSON.DBRef, | ||
Double: BSON.Double, | ||
Int32: BSON.Int32, | ||
Long: BSON.Long, | ||
MinKey: BSON.MinKey, | ||
MaxKey: BSON.MaxKey, | ||
ObjectId: BSON.ObjectId, | ||
Timestamp: BSON.Timestamp, | ||
Decimal128: BSON.Decimal128, | ||
BSONSymbol: BSON.BSONSymbol, | ||
calculateObjectSize: BSON.calculateObjectSize, | ||
EJSON: BSON.EJSON, | ||
BSONRegExp | ||
BSONRegExp: BSON.BSONRegExp | ||
}; | ||
@@ -732,27 +720,2 @@ | ||
/** | ||
* Deprecated remove command. | ||
* | ||
* @param {String} database - The db name. | ||
* @param {String} collection - The collection name. | ||
* @param {Object} query - The query. | ||
* @param {Object} options - The options. | ||
* @param dbOptions | ||
* @return {Promise} | ||
*/ | ||
remove( | ||
database: string, | ||
collection: string, | ||
query: Document = {}, | ||
options: DeleteOptions = {}, | ||
dbOptions?: DbOptions): Promise<DeleteResult> { | ||
options = { ...this.baseCmdOptions, ...options }; | ||
/* NOTE: the 4.x branch of the driver does not define a separate def for remove that doesn't take a | ||
callback, and since remove is deprecated it's not worth asking for a change to the driver. So ts-ignore it is. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
return this.db(database, dbOptions).collection(collection).remove(query, options); | ||
} | ||
/** | ||
* Replace a document with another. | ||
@@ -865,4 +828,3 @@ * | ||
.collection(collection) | ||
.updateMany(filter, update, options) as Promise<UpdateResult>; | ||
// `as UpdateResult` because we know we didn't request .explain() here. | ||
.updateMany(filter, update, options); | ||
} | ||
@@ -892,4 +854,3 @@ | ||
.collection(collection) | ||
.updateOne(filter, update, options) as Promise<UpdateResult>; | ||
// `as UpdateResult` because we know we didn't request .explain() here. | ||
.updateOne(filter, update, options); | ||
} | ||
@@ -1047,2 +1008,15 @@ | ||
async createEncryptedCollection( | ||
dbName: string, | ||
collName: string, | ||
options: CreateEncryptedCollectionOptions, | ||
libmongocrypt: MongoCryptClientEncryption | ||
): Promise<{ collection: Collection, encryptedFields: Document }> { | ||
return await libmongocrypt.createEncryptedCollection( | ||
this.db(dbName), | ||
collName, | ||
options | ||
); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
@@ -1049,0 +1023,0 @@ async initializeBulkOp( |
@@ -25,8 +25,11 @@ import { expect } from 'chai'; | ||
await testDb.collection('ctrlc').insertOne({}); | ||
void testDb.collection('ctrlc').find({ // never resolves | ||
let err: any; | ||
testDb.collection('ctrlc').find({ | ||
$where: 'while(true) { /* loop1 */ }' | ||
}).toArray(); | ||
}).toArray().catch(e => { err = e; }); | ||
await delay(100); | ||
const result = await forceCloseMongoClient(client); | ||
expect(result.forceClosedConnections).to.equal(1); | ||
await delay(1); | ||
expect(err.message).to.include('Topology is closed'); | ||
@@ -33,0 +36,0 @@ client = await MongoClient.connect(await testServer.connectionString()); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
148445
+ Added@mongosh/errors@1.8.0(transitive)
+ Added@mongosh/service-provider-core@1.8.0(transitive)
+ Added@mongosh/types@1.8.0(transitive)
+ Addedbson@5.5.1(transitive)
+ Addedmongodb@5.9.2(transitive)
- Removed@mongosh/errors@1.7.1(transitive)
- Removed@mongosh/service-provider-core@1.7.1(transitive)
- Removed@mongosh/types@1.7.1(transitive)
- Removedbson@4.7.2(transitive)
- Removedmongodb@4.17.2(transitive)
Updated@mongosh/errors@1.8.0
Updated@mongosh/types@1.8.0
Updatedmongodb@^5.1.0