@mongosh/service-provider-core
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -80,3 +80,3 @@ "use strict"; | ||
function generateUriNormalized(options) { | ||
var _a; | ||
var _a, _b, _c; | ||
const uri = options.connectionSpecifier; | ||
@@ -86,3 +86,3 @@ const replSetHostMatch = ((_a = options.host) !== null && _a !== void 0 ? _a : '').match(/^(?<replSetName>[^/]+)\/(?<hosts>([A-Za-z0-9.-]+(:\d+)?,?)+)$/); | ||
const { replSetName, hosts } = replSetHostMatch.groups; | ||
const connectionString = new mongodb_connection_string_url_1.default(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri !== null && uri !== void 0 ? uri : index_1.DEFAULT_DB)}`); | ||
const connectionString = new mongodb_connection_string_url_1.default(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`); | ||
connectionString.hosts = hosts.split(',').filter(host => host.trim()); | ||
@@ -92,2 +92,9 @@ connectionString.searchParams.set('replicaSet', replSetName); | ||
} | ||
const seedList = ((_b = options.host) !== null && _b !== void 0 ? _b : '').match(/^(?<hosts>([A-Za-z0-9.-]+(:\d+)?,?)+)$/); | ||
if (seedList && ((_c = options.host) === null || _c === void 0 ? void 0 : _c.includes(','))) { | ||
const { hosts } = seedList.groups; | ||
const connectionString = new mongodb_connection_string_url_1.default(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`); | ||
connectionString.hosts = hosts.split(',').filter(host => host.trim()); | ||
return addShellConnectionStringParameters(connectionString); | ||
} | ||
if (!uri) { | ||
@@ -94,0 +101,0 @@ return new mongodb_connection_string_url_1.default(`${Scheme.Mongo}${generateHost(options)}:${generatePort(options)}/?directConnection=true`); |
{ | ||
"name": "@mongosh/service-provider-core", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "MongoDB Shell Core Service Provider Package", | ||
@@ -30,4 +30,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@mongosh/errors": "1.0.0", | ||
"@mongosh/i18n": "1.0.0", | ||
"@mongosh/errors": "1.0.1", | ||
"@mongosh/i18n": "1.0.1", | ||
"bson": "^4.4.1", | ||
@@ -52,3 +52,3 @@ "mongodb": "addaleax/node-mongodb-native#71d4c39e5c858f49d10e840df626eca4da653e28", | ||
}, | ||
"gitHead": "fe7811b4af0d4553a2405a4912d548607c2cd515" | ||
"gitHead": "2f34d96bc82a6f4ca7e3dad61a8e141272b036e4" | ||
} |
@@ -402,3 +402,3 @@ import { CommonErrors, MongoshInvalidInputError } from '@mongosh/errors'; | ||
context('when the --host option contains invalid characters', () => { | ||
const options = { host: 'a,b,c' }; | ||
const options = { host: 'a$b,c' }; | ||
@@ -409,3 +409,3 @@ it('returns the uri', () => { | ||
} catch (e) { | ||
expect(e.message).to.contain('The --host argument contains an invalid character: ,'); | ||
expect(e.message).to.contain('The --host argument contains an invalid character: $'); | ||
expect(e).to.be.instanceOf(MongoshInvalidInputError); | ||
@@ -419,18 +419,33 @@ expect(e.code).to.equal(CommonErrors.InvalidArgument); | ||
context('when the --host option contains a replica set', () => { | ||
it('returns a URI for the hosts and ports specified in --host', () => { | ||
const options = { host: 'replsetname/host1:123,host2,host3:456,' }; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/test?replicaSet=replsetname'); | ||
context('when the --host option contains a seed list', () => { | ||
context('without a replica set', () => { | ||
it('returns a URI for the hosts and ports specified in --host', () => { | ||
const options = { host: 'host1:123,host2,host3:456,' }; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/'); | ||
}); | ||
it('returns a URI for the hosts and ports specified in --host and database name', () => { | ||
const options = { | ||
host: 'host1:123,host2,host3:456,', | ||
connectionSpecifier: 'admin' | ||
}; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/admin'); | ||
}); | ||
}); | ||
context('with a replica set', () => { | ||
it('returns a URI for the hosts and ports specified in --host', () => { | ||
const options = { host: 'replsetname/host1:123,host2,host3:456,' }; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/?replicaSet=replsetname'); | ||
}); | ||
it('returns a URI for the hosts and ports specified in --host and database name', () => { | ||
const options = { host: 'replsetname/host1:123,host2,host3:456', connectionSpecifier: 'admin' }; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/admin?replicaSet=replsetname'); | ||
}); | ||
it('returns a URI for the hosts and ports specified in --host and database name', () => { | ||
const options = { host: 'replsetname/host1:123,host2,host3:456', connectionSpecifier: 'admin' }; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/admin?replicaSet=replsetname'); | ||
}); | ||
it('returns a URI for the hosts and ports specified in --host and database name with escaped chars', () => { | ||
const options = { host: 'replsetname/host1:123,host2,host3:456', connectionSpecifier: 'admin?foo=bar' }; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/admin%3Ffoo%3Dbar?replicaSet=replsetname'); | ||
it('returns a URI for the hosts and ports specified in --host and database name with escaped chars', () => { | ||
const options = { host: 'replsetname/host1:123,host2,host3:456', connectionSpecifier: 'admin?foo=bar' }; | ||
expect(generateUri(options)).to.equal('mongodb://host1:123,host2,host3:456/admin%3Ffoo%3Dbar?replicaSet=replsetname'); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -152,6 +152,7 @@ /* eslint complexity: 0*/ | ||
const replSetHostMatch = (options.host ?? '').match( | ||
/^(?<replSetName>[^/]+)\/(?<hosts>([A-Za-z0-9.-]+(:\d+)?,?)+)$/); | ||
/^(?<replSetName>[^/]+)\/(?<hosts>([A-Za-z0-9.-]+(:\d+)?,?)+)$/ | ||
); | ||
if (replSetHostMatch) { | ||
const { replSetName, hosts } = replSetHostMatch.groups as { replSetName: string, hosts: string }; | ||
const connectionString = new ConnectionString(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri ?? DEFAULT_DB)}`); | ||
const connectionString = new ConnectionString(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`); | ||
connectionString.hosts = hosts.split(',').filter(host => host.trim()); | ||
@@ -162,2 +163,14 @@ connectionString.searchParams.set('replicaSet', replSetName); | ||
// If the --host argument contains multiple hosts as a seed list | ||
// we directly do not do additional host/port parsing | ||
const seedList = (options.host ?? '').match( | ||
/^(?<hosts>([A-Za-z0-9.-]+(:\d+)?,?)+)$/ | ||
); | ||
if (seedList && options.host?.includes(',')) { | ||
const { hosts } = seedList.groups as { hosts: string }; | ||
const connectionString = new ConnectionString(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`); | ||
connectionString.hosts = hosts.split(',').filter(host => host.trim()); | ||
return addShellConnectionStringParameters(connectionString); | ||
} | ||
// There is no URI provided, use default 127.0.0.1:27017 | ||
@@ -164,0 +177,0 @@ if (!uri) { |
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
125786
2610
+ Added@mongosh/errors@1.0.1(transitive)
+ Added@mongosh/i18n@1.0.1(transitive)
- Removed@mongosh/errors@1.0.0(transitive)
- Removed@mongosh/i18n@1.0.0(transitive)
Updated@mongosh/errors@1.0.1
Updated@mongosh/i18n@1.0.1