@qp-mongosh/service-provider-core 0.0.0-dev.5 → 0.0.0-dev.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.eslintignore +2 -2
  2. package/.eslintrc.js +1 -1
  3. package/AUTHORS +11 -11
  4. package/LICENSE +200 -200
  5. package/lib/admin.d.ts +28 -28
  6. package/lib/admin.js +2 -2
  7. package/lib/all-fle-types.d.ts +2 -2
  8. package/lib/all-fle-types.js +2 -2
  9. package/lib/all-transport-types.d.ts +1 -1
  10. package/lib/all-transport-types.js +2 -2
  11. package/lib/cli-options.d.ts +43 -43
  12. package/lib/cli-options.js +2 -2
  13. package/lib/closable.d.ts +4 -4
  14. package/lib/closable.js +2 -2
  15. package/lib/connect-info.d.ts +19 -19
  16. package/lib/connect-info.js +34 -34
  17. package/lib/index.d.ts +31 -31
  18. package/lib/index.js +55 -55
  19. package/lib/platform.d.ts +6 -6
  20. package/lib/platform.js +10 -10
  21. package/lib/printable-bson.d.ts +3 -3
  22. package/lib/printable-bson.js +81 -81
  23. package/lib/readable.d.ts +18 -18
  24. package/lib/readable.js +2 -2
  25. package/lib/service-provider.d.ts +11 -11
  26. package/lib/service-provider.js +18 -18
  27. package/lib/shell-auth-options.d.ts +7 -7
  28. package/lib/shell-auth-options.js +2 -2
  29. package/lib/textencoder-polyfill.d.ts +2 -2
  30. package/lib/textencoder-polyfill.js +21 -21
  31. package/lib/uri-generator.d.ts +8 -8
  32. package/lib/uri-generator.js +175 -175
  33. package/lib/writable.d.ts +22 -22
  34. package/lib/writable.js +2 -2
  35. package/package.json +54 -54
  36. package/src/admin.ts +119 -119
  37. package/src/all-fle-types.ts +17 -17
  38. package/src/all-transport-types.ts +80 -80
  39. package/src/cli-options.ts +49 -49
  40. package/src/closable.ts +14 -14
  41. package/src/connect-info.spec.ts +192 -192
  42. package/src/connect-info.ts +57 -57
  43. package/src/index.ts +62 -62
  44. package/src/platform.ts +6 -6
  45. package/src/printable-bson.spec.ts +75 -75
  46. package/src/printable-bson.ts +103 -103
  47. package/src/readable.ts +242 -242
  48. package/src/service-provider.ts +23 -23
  49. package/src/shell-auth-options.ts +7 -7
  50. package/src/textencoder-polyfill.spec.ts +11 -11
  51. package/src/textencoder-polyfill.ts +30 -30
  52. package/src/uri-generator.spec.ts +481 -481
  53. package/src/uri-generator.ts +265 -265
  54. package/src/writable.ts +367 -367
  55. package/tsconfig.json +12 -12
  56. package/tsconfig.lint.json +8 -8
@@ -1,22 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.textEncodingPolyfill = void 0;
4
- if (typeof TextDecoder !== 'function' || typeof TextEncoder !== 'function') {
5
- Object.assign(Function('return this')(), textEncodingPolyfill());
6
- }
7
- function textEncodingPolyfill() {
8
- class TextEncoder {
9
- encode(string) {
10
- return Buffer.from(string, 'utf8');
11
- }
12
- }
13
- class TextDecoder {
14
- decode(bytes) {
15
- const str = Buffer.from(bytes).toString('utf8');
16
- return str.slice(+str.startsWith('\ufeff'));
17
- }
18
- }
19
- return { TextDecoder, TextEncoder };
20
- }
21
- exports.textEncodingPolyfill = textEncodingPolyfill;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.textEncodingPolyfill = void 0;
4
+ if (typeof TextDecoder !== 'function' || typeof TextEncoder !== 'function') {
5
+ Object.assign(Function('return this')(), textEncodingPolyfill());
6
+ }
7
+ function textEncodingPolyfill() {
8
+ class TextEncoder {
9
+ encode(string) {
10
+ return Buffer.from(string, 'utf8');
11
+ }
12
+ }
13
+ class TextDecoder {
14
+ decode(bytes) {
15
+ const str = Buffer.from(bytes).toString('utf8');
16
+ return str.slice(+str.startsWith('\ufeff'));
17
+ }
18
+ }
19
+ return { TextDecoder, TextEncoder };
20
+ }
21
+ exports.textEncodingPolyfill = textEncodingPolyfill;
22
22
  //# sourceMappingURL=textencoder-polyfill.js.map
@@ -1,8 +1,8 @@
1
- import CliOptions from './cli-options';
2
- declare enum Scheme {
3
- Mongo = "mongodb://",
4
- MongoSrv = "mongodb+srv://"
5
- }
6
- declare function generateUri(options: CliOptions): string;
7
- export default generateUri;
8
- export { Scheme };
1
+ import CliOptions from './cli-options';
2
+ declare enum Scheme {
3
+ Mongo = "mongodb://",
4
+ MongoSrv = "mongodb+srv://"
5
+ }
6
+ declare function generateUri(options: CliOptions): string;
7
+ export default generateUri;
8
+ export { Scheme };
@@ -1,176 +1,176 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Scheme = void 0;
30
- const errors_1 = require("@qp-mongosh/errors");
31
- const i18n_1 = __importDefault(require("@qp-mongosh/i18n"));
32
- const mongodb_connection_string_url_1 = __importStar(require("mongodb-connection-string-url"));
33
- const index_1 = require("./index");
34
- var Scheme;
35
- (function (Scheme) {
36
- Scheme["Mongo"] = "mongodb://";
37
- Scheme["MongoSrv"] = "mongodb+srv://";
38
- })(Scheme || (Scheme = {}));
39
- exports.Scheme = Scheme;
40
- const DEFAULT_HOST = '127.0.0.1';
41
- const DEFAULT_PORT = '27017';
42
- const CONFLICT = 'cli-repl.uri-generator.no-host-port';
43
- const INVALID_HOST = 'cli-repl.uri-generator.invalid-host';
44
- const HOST_LIST_PORT_MISMATCH = 'cli-repl.uri-generator.host-list-port-mismatch';
45
- const DIVERGING_SERVICE_NAME = 'cli-repl.uri-generator.diverging-service-name';
46
- const GSSAPI_SERVICE_NAME_UNSUPPORTED = 'cli-repl.uri-generator.gssapi-service-name-unsupported';
47
- function validateConflicts(options, connectionString) {
48
- if (options.host || options.port) {
49
- throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(CONFLICT), errors_1.CommonErrors.InvalidArgument);
50
- }
51
- if (options.gssapiServiceName && (connectionString === null || connectionString === void 0 ? void 0 : connectionString.searchParams.has('authMechanismProperties'))) {
52
- const authProperties = new mongodb_connection_string_url_1.CommaAndColonSeparatedRecord(connectionString.searchParams.get('authMechanismProperties'));
53
- const serviceName = authProperties.get('SERVICE_NAME');
54
- if (serviceName !== undefined && options.gssapiServiceName !== serviceName) {
55
- throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(DIVERGING_SERVICE_NAME), errors_1.CommonErrors.InvalidArgument);
56
- }
57
- }
58
- if (connectionString === null || connectionString === void 0 ? void 0 : connectionString.searchParams.has('gssapiServiceName')) {
59
- throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(GSSAPI_SERVICE_NAME_UNSUPPORTED), errors_1.CommonErrors.InvalidArgument);
60
- }
61
- }
62
- function validateHost(host) {
63
- const invalidCharacter = host.match(/[^a-zA-Z0-9.:\[\]_-]/);
64
- if (invalidCharacter) {
65
- throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(INVALID_HOST) + ': ' + invalidCharacter[0], errors_1.CommonErrors.InvalidArgument);
66
- }
67
- }
68
- function validateHostSeedList(hosts, fixedPort) {
69
- const trimmedHosts = hosts.split(',').map(h => h.trim()).filter(h => !!h);
70
- const hostList = [];
71
- trimmedHosts.forEach(h => {
72
- const [host, port] = h.split(':');
73
- if (fixedPort && port !== undefined && port !== fixedPort) {
74
- throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(HOST_LIST_PORT_MISMATCH), errors_1.CommonErrors.InvalidArgument);
75
- }
76
- hostList.push(`${host}${(port || fixedPort) ? ':' + (port || fixedPort) : ''}`);
77
- });
78
- return hostList;
79
- }
80
- function generateHost(options) {
81
- if (options.host) {
82
- validateHost(options.host);
83
- if (options.host.includes(':')) {
84
- return options.host.split(':')[0];
85
- }
86
- return options.host;
87
- }
88
- return DEFAULT_HOST;
89
- }
90
- function generatePort(options) {
91
- if (options.host && options.host.includes(':')) {
92
- validateHost(options.host);
93
- const port = options.host.split(':')[1];
94
- if (!options.port || options.port === port) {
95
- return port;
96
- }
97
- throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(CONFLICT), errors_1.CommonErrors.InvalidArgument);
98
- }
99
- return options.port ? options.port : DEFAULT_PORT;
100
- }
101
- function generateUri(options) {
102
- if (options.nodb) {
103
- return '';
104
- }
105
- const connectionString = generateUriNormalized(options);
106
- if (connectionString.hosts.every(host => ['localhost', '127.0.0.1'].includes(host.split(':')[0]))) {
107
- const params = connectionString.searchParams;
108
- if (!params.has('serverSelectionTimeoutMS')) {
109
- params.set('serverSelectionTimeoutMS', '2000');
110
- }
111
- }
112
- return connectionString.toString();
113
- }
114
- function generateUriNormalized(options) {
115
- var _a, _b, _c;
116
- const uri = options.connectionSpecifier;
117
- const replSetHostMatch = ((_a = options.host) !== null && _a !== void 0 ? _a : '').match(/^(?<replSetName>[^/]+)\/(?<hosts>([A-Za-z0-9._-]+(:\d+)?,?)+)$/);
118
- if (replSetHostMatch) {
119
- const { replSetName, hosts } = replSetHostMatch.groups;
120
- const connectionString = new mongodb_connection_string_url_1.default(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`);
121
- connectionString.hosts = validateHostSeedList(hosts, options.port);
122
- connectionString.searchParams.set('replicaSet', replSetName);
123
- return addShellConnectionStringParameters(connectionString);
124
- }
125
- const seedList = ((_b = options.host) !== null && _b !== void 0 ? _b : '').match(/^(?<hosts>([A-Za-z0-9._-]+(:\d+)?,?)+)$/);
126
- if (seedList && ((_c = options.host) === null || _c === void 0 ? void 0 : _c.includes(','))) {
127
- const { hosts } = seedList.groups;
128
- const connectionString = new mongodb_connection_string_url_1.default(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`);
129
- connectionString.hosts = validateHostSeedList(hosts, options.port);
130
- return addShellConnectionStringParameters(connectionString);
131
- }
132
- if (!uri) {
133
- return new mongodb_connection_string_url_1.default(`${Scheme.Mongo}${generateHost(options)}:${generatePort(options)}/?directConnection=true`);
134
- }
135
- if (uri.startsWith(Scheme.MongoSrv)) {
136
- const connectionString = new mongodb_connection_string_url_1.default(uri);
137
- validateConflicts(options, connectionString);
138
- return connectionString;
139
- }
140
- else if (uri.startsWith(Scheme.Mongo)) {
141
- const connectionString = new mongodb_connection_string_url_1.default(uri);
142
- validateConflicts(options, connectionString);
143
- return addShellConnectionStringParameters(connectionString);
144
- }
145
- const uriMatch = /^([A-Za-z0-9][A-Za-z0-9._-]+):?(\d+)?(?:\/(\S*))?$/gi;
146
- let parts = uriMatch.exec(uri);
147
- if (parts === null) {
148
- if (/[/\\. "$]/.test(uri)) {
149
- throw new errors_1.MongoshInvalidInputError(`Invalid URI: ${uri}`, errors_1.CommonErrors.InvalidArgument);
150
- }
151
- else {
152
- parts = [uri, uri];
153
- }
154
- }
155
- let host = parts === null || parts === void 0 ? void 0 : parts[1];
156
- const port = parts === null || parts === void 0 ? void 0 : parts[2];
157
- let dbAndQueryString = parts === null || parts === void 0 ? void 0 : parts[3];
158
- if (!port && !dbAndQueryString && host.indexOf('.') < 0) {
159
- dbAndQueryString = host;
160
- host = undefined;
161
- }
162
- if (host || port) {
163
- validateConflicts(options);
164
- }
165
- return addShellConnectionStringParameters(new mongodb_connection_string_url_1.default(`${Scheme.Mongo}${host || generateHost(options)}:${port || generatePort(options)}/${encodeURIComponent(dbAndQueryString || index_1.DEFAULT_DB)}`));
166
- }
167
- function addShellConnectionStringParameters(uri) {
168
- uri = uri.clone();
169
- const params = uri.searchParams;
170
- if (!params.has('replicaSet') && !params.has('directConnection') && !params.has('loadBalanced') && uri.hosts.length === 1) {
171
- params.set('directConnection', 'true');
172
- }
173
- return uri;
174
- }
175
- exports.default = generateUri;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Scheme = void 0;
30
+ const errors_1 = require("@qp-mongosh/errors");
31
+ const i18n_1 = __importDefault(require("@qp-mongosh/i18n"));
32
+ const mongodb_connection_string_url_1 = __importStar(require("mongodb-connection-string-url"));
33
+ const index_1 = require("./index");
34
+ var Scheme;
35
+ (function (Scheme) {
36
+ Scheme["Mongo"] = "mongodb://";
37
+ Scheme["MongoSrv"] = "mongodb+srv://";
38
+ })(Scheme || (Scheme = {}));
39
+ exports.Scheme = Scheme;
40
+ const DEFAULT_HOST = '127.0.0.1';
41
+ const DEFAULT_PORT = '27017';
42
+ const CONFLICT = 'cli-repl.uri-generator.no-host-port';
43
+ const INVALID_HOST = 'cli-repl.uri-generator.invalid-host';
44
+ const HOST_LIST_PORT_MISMATCH = 'cli-repl.uri-generator.host-list-port-mismatch';
45
+ const DIVERGING_SERVICE_NAME = 'cli-repl.uri-generator.diverging-service-name';
46
+ const GSSAPI_SERVICE_NAME_UNSUPPORTED = 'cli-repl.uri-generator.gssapi-service-name-unsupported';
47
+ function validateConflicts(options, connectionString) {
48
+ if (options.host || options.port) {
49
+ throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(CONFLICT), errors_1.CommonErrors.InvalidArgument);
50
+ }
51
+ if (options.gssapiServiceName && (connectionString === null || connectionString === void 0 ? void 0 : connectionString.searchParams.has('authMechanismProperties'))) {
52
+ const authProperties = new mongodb_connection_string_url_1.CommaAndColonSeparatedRecord(connectionString.searchParams.get('authMechanismProperties'));
53
+ const serviceName = authProperties.get('SERVICE_NAME');
54
+ if (serviceName !== undefined && options.gssapiServiceName !== serviceName) {
55
+ throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(DIVERGING_SERVICE_NAME), errors_1.CommonErrors.InvalidArgument);
56
+ }
57
+ }
58
+ if (connectionString === null || connectionString === void 0 ? void 0 : connectionString.searchParams.has('gssapiServiceName')) {
59
+ throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(GSSAPI_SERVICE_NAME_UNSUPPORTED), errors_1.CommonErrors.InvalidArgument);
60
+ }
61
+ }
62
+ function validateHost(host) {
63
+ const invalidCharacter = host.match(/[^a-zA-Z0-9.:\[\]_-]/);
64
+ if (invalidCharacter) {
65
+ throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(INVALID_HOST) + ': ' + invalidCharacter[0], errors_1.CommonErrors.InvalidArgument);
66
+ }
67
+ }
68
+ function validateHostSeedList(hosts, fixedPort) {
69
+ const trimmedHosts = hosts.split(',').map(h => h.trim()).filter(h => !!h);
70
+ const hostList = [];
71
+ trimmedHosts.forEach(h => {
72
+ const [host, port] = h.split(':');
73
+ if (fixedPort && port !== undefined && port !== fixedPort) {
74
+ throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(HOST_LIST_PORT_MISMATCH), errors_1.CommonErrors.InvalidArgument);
75
+ }
76
+ hostList.push(`${host}${(port || fixedPort) ? ':' + (port || fixedPort) : ''}`);
77
+ });
78
+ return hostList;
79
+ }
80
+ function generateHost(options) {
81
+ if (options.host) {
82
+ validateHost(options.host);
83
+ if (options.host.includes(':')) {
84
+ return options.host.split(':')[0];
85
+ }
86
+ return options.host;
87
+ }
88
+ return DEFAULT_HOST;
89
+ }
90
+ function generatePort(options) {
91
+ if (options.host && options.host.includes(':')) {
92
+ validateHost(options.host);
93
+ const port = options.host.split(':')[1];
94
+ if (!options.port || options.port === port) {
95
+ return port;
96
+ }
97
+ throw new errors_1.MongoshInvalidInputError(i18n_1.default.__(CONFLICT), errors_1.CommonErrors.InvalidArgument);
98
+ }
99
+ return options.port ? options.port : DEFAULT_PORT;
100
+ }
101
+ function generateUri(options) {
102
+ if (options.nodb) {
103
+ return '';
104
+ }
105
+ const connectionString = generateUriNormalized(options);
106
+ if (connectionString.hosts.every(host => ['localhost', '127.0.0.1'].includes(host.split(':')[0]))) {
107
+ const params = connectionString.searchParams;
108
+ if (!params.has('serverSelectionTimeoutMS')) {
109
+ params.set('serverSelectionTimeoutMS', '2000');
110
+ }
111
+ }
112
+ return connectionString.toString();
113
+ }
114
+ function generateUriNormalized(options) {
115
+ var _a, _b, _c;
116
+ const uri = options.connectionSpecifier;
117
+ const replSetHostMatch = ((_a = options.host) !== null && _a !== void 0 ? _a : '').match(/^(?<replSetName>[^/]+)\/(?<hosts>([A-Za-z0-9._-]+(:\d+)?,?)+)$/);
118
+ if (replSetHostMatch) {
119
+ const { replSetName, hosts } = replSetHostMatch.groups;
120
+ const connectionString = new mongodb_connection_string_url_1.default(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`);
121
+ connectionString.hosts = validateHostSeedList(hosts, options.port);
122
+ connectionString.searchParams.set('replicaSet', replSetName);
123
+ return addShellConnectionStringParameters(connectionString);
124
+ }
125
+ const seedList = ((_b = options.host) !== null && _b !== void 0 ? _b : '').match(/^(?<hosts>([A-Za-z0-9._-]+(:\d+)?,?)+)$/);
126
+ if (seedList && ((_c = options.host) === null || _c === void 0 ? void 0 : _c.includes(','))) {
127
+ const { hosts } = seedList.groups;
128
+ const connectionString = new mongodb_connection_string_url_1.default(`${Scheme.Mongo}replacemeHost/${encodeURIComponent(uri || '')}`);
129
+ connectionString.hosts = validateHostSeedList(hosts, options.port);
130
+ return addShellConnectionStringParameters(connectionString);
131
+ }
132
+ if (!uri) {
133
+ return new mongodb_connection_string_url_1.default(`${Scheme.Mongo}${generateHost(options)}:${generatePort(options)}/?directConnection=true`);
134
+ }
135
+ if (uri.startsWith(Scheme.MongoSrv)) {
136
+ const connectionString = new mongodb_connection_string_url_1.default(uri);
137
+ validateConflicts(options, connectionString);
138
+ return connectionString;
139
+ }
140
+ else if (uri.startsWith(Scheme.Mongo)) {
141
+ const connectionString = new mongodb_connection_string_url_1.default(uri);
142
+ validateConflicts(options, connectionString);
143
+ return addShellConnectionStringParameters(connectionString);
144
+ }
145
+ const uriMatch = /^([A-Za-z0-9][A-Za-z0-9._-]+):?(\d+)?(?:\/(\S*))?$/gi;
146
+ let parts = uriMatch.exec(uri);
147
+ if (parts === null) {
148
+ if (/[/\\. "$]/.test(uri)) {
149
+ throw new errors_1.MongoshInvalidInputError(`Invalid URI: ${uri}`, errors_1.CommonErrors.InvalidArgument);
150
+ }
151
+ else {
152
+ parts = [uri, uri];
153
+ }
154
+ }
155
+ let host = parts === null || parts === void 0 ? void 0 : parts[1];
156
+ const port = parts === null || parts === void 0 ? void 0 : parts[2];
157
+ let dbAndQueryString = parts === null || parts === void 0 ? void 0 : parts[3];
158
+ if (!port && !dbAndQueryString && host.indexOf('.') < 0) {
159
+ dbAndQueryString = host;
160
+ host = undefined;
161
+ }
162
+ if (host || port) {
163
+ validateConflicts(options);
164
+ }
165
+ return addShellConnectionStringParameters(new mongodb_connection_string_url_1.default(`${Scheme.Mongo}${host || generateHost(options)}:${port || generatePort(options)}/${encodeURIComponent(dbAndQueryString || index_1.DEFAULT_DB)}`));
166
+ }
167
+ function addShellConnectionStringParameters(uri) {
168
+ uri = uri.clone();
169
+ const params = uri.searchParams;
170
+ if (!params.has('replicaSet') && !params.has('directConnection') && !params.has('loadBalanced') && uri.hosts.length === 1) {
171
+ params.set('directConnection', 'true');
172
+ }
173
+ return uri;
174
+ }
175
+ exports.default = generateUri;
176
176
  //# sourceMappingURL=uri-generator.js.map
package/lib/writable.d.ts CHANGED
@@ -1,22 +1,22 @@
1
- import type { Document, InsertOneOptions, InsertOneResult, Collection, RenameOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, BulkWriteOptions, AnyBulkWriteOperation, DeleteOptions, DeleteResult, InsertManyResult, ReplaceOptions, UpdateResult, UpdateOptions, DropDatabaseOptions, CreateIndexesOptions, DropCollectionOptions, BulkWriteResult, RunCommandOptions, DbOptions, OrderedBulkOperation, UnorderedBulkOperation } from './all-transport-types';
2
- export default interface Writable {
3
- runCommand(db: string, spec: Document, options: RunCommandOptions, dbOptions?: DbOptions): Promise<Document>;
4
- runCommandWithCheck(db: string, spec: Document, options: RunCommandOptions, dbOptions?: DbOptions): Promise<Document>;
5
- dropDatabase(database: string, options: DropDatabaseOptions, dbOptions?: DbOptions): Promise<Document>;
6
- bulkWrite(database: string, collection: string, requests: AnyBulkWriteOperation[], options: BulkWriteOptions, dbOptions?: DbOptions): Promise<BulkWriteResult>;
7
- deleteMany(database: string, collection: string, filter: Document, options: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
8
- deleteOne(database: string, collection: string, filter: Document, options: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
9
- findOneAndDelete(database: string, collection: string, filter: Document, options: FindOneAndDeleteOptions, dbOptions?: DbOptions): Promise<Document>;
10
- findOneAndReplace(database: string, collection: string, filter: Document, replacement: Document, options: FindOneAndReplaceOptions, dbOptions?: DbOptions): Promise<Document>;
11
- findOneAndUpdate(database: string, collection: string, filter: Document, update: Document | Document[], options: FindOneAndUpdateOptions, dbOptions?: DbOptions): Promise<Document>;
12
- insertMany(database: string, collection: string, docs: Document[], options: BulkWriteOptions, dbOptions?: DbOptions): Promise<InsertManyResult>;
13
- insertOne(database: string, collection: string, doc: Document, options: InsertOneOptions, dbOptions?: DbOptions): Promise<InsertOneResult>;
14
- replaceOne(database: string, collection: string, filter: Document, replacement: Document, options?: ReplaceOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
15
- updateMany(database: string, collection: string, filter: Document, update: Document, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
16
- updateOne(database: string, collection: string, filter: Document, update: Document, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
17
- remove(database: string, collection: string, query: Document, options?: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
18
- createIndexes(database: string, collection: string, indexSpecs: Document[], options?: CreateIndexesOptions, dbOptions?: DbOptions): Promise<string[]>;
19
- dropCollection(database: string, collection: string, options: DropCollectionOptions, dbOptions?: DbOptions): Promise<boolean>;
20
- renameCollection(database: string, oldName: string, newName: string, options?: RenameOptions, dbOptions?: DbOptions): Promise<Collection>;
21
- initializeBulkOp(dbName: string, collName: string, ordered: boolean, options?: BulkWriteOptions, dbOptions?: DbOptions): Promise<OrderedBulkOperation | UnorderedBulkOperation>;
22
- }
1
+ import type { Document, InsertOneOptions, InsertOneResult, Collection, RenameOptions, FindOneAndDeleteOptions, FindOneAndReplaceOptions, FindOneAndUpdateOptions, BulkWriteOptions, AnyBulkWriteOperation, DeleteOptions, DeleteResult, InsertManyResult, ReplaceOptions, UpdateResult, UpdateOptions, DropDatabaseOptions, CreateIndexesOptions, DropCollectionOptions, BulkWriteResult, RunCommandOptions, DbOptions, OrderedBulkOperation, UnorderedBulkOperation } from './all-transport-types';
2
+ export default interface Writable {
3
+ runCommand(db: string, spec: Document, options: RunCommandOptions, dbOptions?: DbOptions): Promise<Document>;
4
+ runCommandWithCheck(db: string, spec: Document, options: RunCommandOptions, dbOptions?: DbOptions): Promise<Document>;
5
+ dropDatabase(database: string, options: DropDatabaseOptions, dbOptions?: DbOptions): Promise<Document>;
6
+ bulkWrite(database: string, collection: string, requests: AnyBulkWriteOperation[], options: BulkWriteOptions, dbOptions?: DbOptions): Promise<BulkWriteResult>;
7
+ deleteMany(database: string, collection: string, filter: Document, options: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
8
+ deleteOne(database: string, collection: string, filter: Document, options: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
9
+ findOneAndDelete(database: string, collection: string, filter: Document, options: FindOneAndDeleteOptions, dbOptions?: DbOptions): Promise<Document>;
10
+ findOneAndReplace(database: string, collection: string, filter: Document, replacement: Document, options: FindOneAndReplaceOptions, dbOptions?: DbOptions): Promise<Document>;
11
+ findOneAndUpdate(database: string, collection: string, filter: Document, update: Document | Document[], options: FindOneAndUpdateOptions, dbOptions?: DbOptions): Promise<Document>;
12
+ insertMany(database: string, collection: string, docs: Document[], options: BulkWriteOptions, dbOptions?: DbOptions): Promise<InsertManyResult>;
13
+ insertOne(database: string, collection: string, doc: Document, options: InsertOneOptions, dbOptions?: DbOptions): Promise<InsertOneResult>;
14
+ replaceOne(database: string, collection: string, filter: Document, replacement: Document, options?: ReplaceOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
15
+ updateMany(database: string, collection: string, filter: Document, update: Document, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
16
+ updateOne(database: string, collection: string, filter: Document, update: Document, options?: UpdateOptions, dbOptions?: DbOptions): Promise<UpdateResult>;
17
+ remove(database: string, collection: string, query: Document, options?: DeleteOptions, dbOptions?: DbOptions): Promise<DeleteResult>;
18
+ createIndexes(database: string, collection: string, indexSpecs: Document[], options?: CreateIndexesOptions, dbOptions?: DbOptions): Promise<string[]>;
19
+ dropCollection(database: string, collection: string, options: DropCollectionOptions, dbOptions?: DbOptions): Promise<boolean>;
20
+ renameCollection(database: string, oldName: string, newName: string, options?: RenameOptions, dbOptions?: DbOptions): Promise<Collection>;
21
+ initializeBulkOp(dbName: string, collName: string, ordered: boolean, options?: BulkWriteOptions, dbOptions?: DbOptions): Promise<OrderedBulkOperation | UnorderedBulkOperation>;
22
+ }
package/lib/writable.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=writable.js.map
package/package.json CHANGED
@@ -1,54 +1,54 @@
1
- {
2
- "name": "@qp-mongosh/service-provider-core",
3
- "version": "0.0.0-dev.5",
4
- "description": "MongoDB Shell Core Service Provider Package",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "config": {
8
- "unsafe-perm": true
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git://github.com/mongodb-js/mongosh.git"
13
- },
14
- "scripts": {
15
- "compile-ts": "tsc -p tsconfig.json",
16
- "prepublish": "npm run compile-ts",
17
- "test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"",
18
- "test-ci": "node ../../scripts/run-if-package-requested.js npm test",
19
- "lint": "eslint --report-unused-disable-directives \"./{src,test}/**/*.{js,ts,tsx}\"",
20
- "check": "npm run lint && depcheck --skip-missing=true"
21
- },
22
- "license": "Apache-2.0",
23
- "publishConfig": {
24
- "access": "public"
25
- },
26
- "engines": {
27
- "node": ">=12.4.0"
28
- },
29
- "mongosh": {
30
- "unitTestsOnly": true
31
- },
32
- "dependencies": {
33
- "@qp-mongosh/errors": "0.0.0-dev.5",
34
- "@qp-mongosh/i18n": "0.0.0-dev.5",
35
- "bson": "^4.6.1",
36
- "qp-mongodb": "0.0.0-dev.5",
37
- "mongodb-build-info": "^1.2.0",
38
- "mongodb-connection-string-url": "^2.3.2"
39
- },
40
- "optionalDependencies": {
41
- "mongodb-client-encryption": "^2.0.0"
42
- },
43
- "dependency-check": {
44
- "entries": [
45
- "src/**/*.js"
46
- ],
47
- "ignore": [
48
- "sinon",
49
- "chai",
50
- "uuid",
51
- "encoding"
52
- ]
53
- }
54
- }
1
+ {
2
+ "name": "@qp-mongosh/service-provider-core",
3
+ "version": "0.0.0-dev.9",
4
+ "description": "MongoDB Shell Core Service Provider Package",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "config": {
8
+ "unsafe-perm": true
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git://github.com/mongodb-js/mongosh.git"
13
+ },
14
+ "scripts": {
15
+ "compile-ts": "tsc -p tsconfig.json",
16
+ "prepublish": "npm run compile-ts",
17
+ "test": "mocha -r \"../../scripts/import-expansions.js\" --timeout 60000 -r ts-node/register \"./src/**/*.spec.ts\"",
18
+ "test-ci": "node ../../scripts/run-if-package-requested.js npm test",
19
+ "lint": "eslint --report-unused-disable-directives \"./{src,test}/**/*.{js,ts,tsx}\"",
20
+ "check": "npm run lint && depcheck --skip-missing=true"
21
+ },
22
+ "license": "Apache-2.0",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "engines": {
27
+ "node": ">=12.4.0"
28
+ },
29
+ "mongosh": {
30
+ "unitTestsOnly": true
31
+ },
32
+ "dependencies": {
33
+ "@qp-mongosh/errors": "0.0.0-dev.9",
34
+ "@qp-mongosh/i18n": "0.0.0-dev.9",
35
+ "bson": "^4.6.1",
36
+ "qp-mongodb": "0.0.0-dev.9",
37
+ "mongodb-build-info": "^1.2.0",
38
+ "mongodb-connection-string-url": "^2.3.2"
39
+ },
40
+ "optionalDependencies": {
41
+ "mongodb-client-encryption": "^2.0.0"
42
+ },
43
+ "dependency-check": {
44
+ "entries": [
45
+ "src/**/*.js"
46
+ ],
47
+ "ignore": [
48
+ "sinon",
49
+ "chai",
50
+ "uuid",
51
+ "encoding"
52
+ ]
53
+ }
54
+ }