@mongosh/service-provider-server
Advanced tools
Comparing version 0.13.2 to 0.14.0
@@ -1,2 +0,2 @@ | ||
import { MongoClient, ReadPreference, ClientMetadata, Topology, ReadPreferenceFromOptions, ReadPreferenceLike, OperationOptions } from 'mongodb'; | ||
import { MongoClient, ReadPreference, ClientMetadata, ReadPreferenceFromOptions, ReadPreferenceLike, OperationOptions } from 'mongodb'; | ||
import { ServiceProvider, getConnectInfo, ReplPlatform, ServiceProviderCore, ShellAuthOptions, AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteOptions, BulkWriteResult, ClientSessionOptions, CollStatsOptions, 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, ConnectionString, FLE, AutoEncryptionOptions } from '@mongosh/service-provider-core'; | ||
@@ -9,3 +9,3 @@ declare type DropDatabaseResult = { | ||
buildInfo: any; | ||
topology: Topology; | ||
topology: any; | ||
extraInfo: ExtraConnectionInfo; | ||
@@ -59,3 +59,3 @@ }; | ||
updateOne(database: string, collection: string, filter?: Document, update?: Document, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>; | ||
getTopology(): Topology | undefined; | ||
getTopology(): any | undefined; | ||
dropDatabase(db: string, options?: DropDatabaseOptions, dbOptions?: DbOptions): Promise<DropDatabaseResult>; | ||
@@ -62,0 +62,0 @@ createIndexes(database: string, collection: string, indexSpecs: IndexDescription[], options?: CreateIndexesOptions, dbOptions?: DbOptions): Promise<string[]>; |
@@ -55,2 +55,20 @@ "use strict"; | ||
} | ||
let resolveDnsHelpers = undefined; | ||
async function resolveMongodbSrv(uri) { | ||
if (uri.startsWith('mongodb+srv://')) { | ||
try { | ||
resolveDnsHelpers !== null && resolveDnsHelpers !== void 0 ? resolveDnsHelpers : (resolveDnsHelpers = { | ||
resolve: require('resolve-mongodb-srv'), | ||
osDns: require('os-dns-native') | ||
}); | ||
} | ||
catch (_a) { } | ||
if (resolveDnsHelpers !== undefined) { | ||
return await resolveDnsHelpers.resolve(uri, { | ||
dns: resolveDnsHelpers.osDns.withNodeFallback | ||
}); | ||
} | ||
} | ||
return uri; | ||
} | ||
async function connectMongoClient(uri, clientOptions, MClient = mongodb_1.MongoClient) { | ||
@@ -62,2 +80,3 @@ var _a, _b; | ||
delete optionsWithoutFLE.autoEncryption; | ||
delete optionsWithoutFLE.serverApi; | ||
const client = new MClient(uri, optionsWithoutFLE); | ||
@@ -73,2 +92,3 @@ await connectWithFailFast(client); | ||
} | ||
uri = await resolveMongodbSrv(uri); | ||
const client = new MClient(uri, clientOptions); | ||
@@ -75,0 +95,0 @@ await connectWithFailFast(client); |
{ | ||
"name": "@mongosh/service-provider-server", | ||
"version": "0.13.2", | ||
"version": "0.14.0", | ||
"description": "MongoDB Shell Server Service Provider Package", | ||
@@ -41,8 +41,8 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@mongosh/errors": "0.13.2", | ||
"@mongosh/service-provider-core": "0.13.2", | ||
"@mongosh/errors": "0.14.0", | ||
"@mongosh/service-provider-core": "0.14.0", | ||
"@types/sinon": "^7.5.1", | ||
"@types/sinon-chai": "^3.2.3", | ||
"aws4": "^1.11.0", | ||
"mongodb": "4.0.0-beta.4", | ||
"mongodb": "4.0.0-beta.5", | ||
"saslprep": "mongodb-js/saslprep#v1.0.4" | ||
@@ -54,5 +54,7 @@ }, | ||
"optionalDependencies": { | ||
"mongodb-client-encryption": "^1.2.3" | ||
"mongodb-client-encryption": "^1.2.3", | ||
"os-dns-native": "^1.0.3", | ||
"resolve-mongodb-srv": "^1.0.1" | ||
}, | ||
"gitHead": "7517f44ef756760060666c20f0de964564fb3aa2" | ||
"gitHead": "39df2de64c8448b4afaee905a038d615345a1e44" | ||
} |
@@ -67,2 +67,17 @@ import CliServiceProvider from './cli-service-provider'; | ||
describe('.suspend', () => { | ||
it('allows disconnecting and reconnecting the CliServiceProvider', async() => { | ||
await serviceProvider.runCommandWithCheck('admin', { ping: 1 }); | ||
const reconnect = await serviceProvider.suspend(); | ||
try { | ||
await serviceProvider.runCommandWithCheck('admin', { ping: 1 }); | ||
expect.fail('missed exception'); | ||
} catch (err) { | ||
expect(err.name).to.equal('MongoError'); | ||
} | ||
await reconnect(); | ||
await serviceProvider.runCommandWithCheck('admin', { ping: 1 }); | ||
}); | ||
}); | ||
describe('.authenticate', () => { | ||
@@ -655,2 +670,33 @@ beforeEach(async() => { | ||
}); | ||
context('post-5.0', () => { | ||
skipIfServerVersion(testServer, '< 5.0'); | ||
it('allows time-series', async() => { | ||
await db.createCollection('coll1', { timeseries: { timeField: 'time' } } ); | ||
const collections = await serviceProvider.listCollections(dbName, {}, { nameOnly: true }); | ||
expect( | ||
collections | ||
).to.deep.contain({ | ||
name: 'coll1', | ||
type: 'timeseries' | ||
}); | ||
expect( | ||
collections | ||
).to.deep.contain({ | ||
name: 'system.buckets.coll1', | ||
type: 'collection' | ||
}); | ||
expect( | ||
collections | ||
).to.deep.contain({ | ||
name: 'system.views', | ||
type: 'collection' | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -657,0 +703,0 @@ |
import { | ||
Auth, | ||
AuthMechanismId, | ||
AuthMechanism, | ||
MongoClient, | ||
@@ -19,3 +19,2 @@ ReadPreference, | ||
ClientMetadata, | ||
Topology, | ||
ReadPreferenceFromOptions, | ||
@@ -114,3 +113,3 @@ ReadPreferenceLike, | ||
buildInfo: any; | ||
topology: Topology; | ||
topology: any; | ||
extraInfo: ExtraConnectionInfo; | ||
@@ -164,2 +163,24 @@ }; | ||
let resolveDnsHelpers: { | ||
resolve: typeof import('resolve-mongodb-srv'), | ||
osDns: typeof import('os-dns-native') | ||
} | undefined = undefined; | ||
async function resolveMongodbSrv(uri: string): Promise<string> { | ||
if (uri.startsWith('mongodb+srv://')) { | ||
try { | ||
resolveDnsHelpers ??= { | ||
resolve: require('resolve-mongodb-srv'), | ||
osDns: require('os-dns-native') | ||
}; | ||
} catch { /* ignore */ } | ||
if (resolveDnsHelpers !== undefined) { | ||
return await resolveDnsHelpers.resolve(uri, { | ||
dns: resolveDnsHelpers.osDns.withNodeFallback | ||
}); | ||
} | ||
} | ||
return uri; | ||
} | ||
/** | ||
@@ -176,5 +197,6 @@ * Connect a MongoClient. If AutoEncryption is requested, first connect without the encryption options and verify that | ||
!clientOptions.autoEncryption.bypassAutoEncryption) { | ||
// connect first without autoEncryptionOptions | ||
// connect first without autoEncryption and serverApi options. | ||
const optionsWithoutFLE = { ...clientOptions }; | ||
delete optionsWithoutFLE.autoEncryption; | ||
delete optionsWithoutFLE.serverApi; | ||
const client = new MClient(uri, optionsWithoutFLE); | ||
@@ -192,2 +214,3 @@ await connectWithFailFast(client); | ||
} | ||
uri = await resolveMongodbSrv(uri); | ||
const client = new MClient(uri, clientOptions); | ||
@@ -299,3 +322,3 @@ await connectWithFailFast(client); | ||
} | ||
const topology = this.getTopology() as Topology; | ||
const topology = this.getTopology(); | ||
const { version } = require('../package.json'); | ||
@@ -957,4 +980,4 @@ const [cmdLineOpts = null, atlasVersion = null] = await Promise.all([ | ||
*/ | ||
getTopology(): Topology | undefined { | ||
return this.mongoClient.topology; | ||
getTopology(): any | undefined { | ||
return (this.mongoClient as any).topology; | ||
} | ||
@@ -1106,3 +1129,3 @@ | ||
auth, | ||
...(authDoc.mechanism ? { authMechanism: authDoc.mechanism as AuthMechanismId } : {}), | ||
...(authDoc.mechanism ? { authMechanism: authDoc.mechanism as AuthMechanism } : {}), | ||
...(authDoc.authDb ? { authSource: authDoc.authDb } : {}) | ||
@@ -1109,0 +1132,0 @@ }); |
import { MongoshInternalError } from '@mongosh/errors'; | ||
import { Callback, CloseOptions, Connection, ConnectionPool } from 'mongodb'; | ||
import { Callback, CloseOptions } from 'mongodb'; | ||
// We "rename" any here for more clarity below | ||
type ConnectionPool = any; | ||
type Connection = any; | ||
let alreadyPatched = false; | ||
@@ -29,3 +33,3 @@ | ||
const pool = this; | ||
originalCheckOut.call(this, function(this: any, error, connection) { | ||
originalCheckOut.call(this, function(this: any, error: any, connection: Connection) { | ||
if (connection) { | ||
@@ -32,0 +36,0 @@ let connections = poolToConnections.get(pool); |
Sorry, the diff of this file is not supported yet
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
159947
3272
10
+ Added@mongosh/errors@0.14.0(transitive)
+ Added@mongosh/i18n@0.14.0(transitive)
+ Added@mongosh/service-provider-core@0.14.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedipv6-normalize@1.0.1(transitive)
+ Addedmongodb@4.0.0-beta.5(transitive)
+ Addedms@2.1.3(transitive)
+ Addednode-addon-api@4.3.0(transitive)
+ Addedos-dns-native@1.2.1(transitive)
+ Addedresolve-mongodb-srv@1.1.5(transitive)
+ Addedtr46@5.0.0(transitive)
+ Addedwhatwg-url@14.0.0(transitive)
- Removed@mongosh/errors@0.13.2(transitive)
- Removed@mongosh/i18n@0.13.2(transitive)
- Removed@mongosh/service-provider-core@0.13.2(transitive)
- Removedmongodb@4.0.0-beta.4(transitive)
Updated@mongosh/errors@0.14.0
Updatedmongodb@4.0.0-beta.5