@xnestjs/mongodb 1.5.2 → 1.6.0

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.
package/README.md CHANGED
@@ -64,6 +64,8 @@ export class MyModule {
64
64
  The library supports configuration through environment variables. Environment variables below is accepted.
65
65
  All environment variables starts with prefix (MONGODB_). This can be configured while registering the module.
66
66
 
67
+ <--- BEGIN env --->
68
+
67
69
  | Environment Variable | Type | Default | Description |
68
70
  |----------------------------------------|---------|---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
69
71
  | MONGODB_URL | String | mongodb://localhost:27017 | URL to MongoDB server |
@@ -104,3 +106,5 @@ All environment variables starts with prefix (MONGODB_). This can be configured
104
106
  | MONGODB_PROXY_PORT | String | | Configures a Socks5 proxy port used for creating TCP connections. |
105
107
  | MONGODB_PROXY_USERNAME | String | | Configures a Socks5 proxy username when the proxy in proxyHost requires username/password authentication. |
106
108
  | MONGODB_PROXY_PASSWORD | String | | Configures a Socks5 proxy password when the proxy in proxyHost requires username/password authentication. |
109
+
110
+ <--- END env --->
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMongodbConfig = getMongodbConfig;
4
+ const tslib_1 = require("tslib");
5
+ const node_process_1 = tslib_1.__importDefault(require("node:process"));
6
+ const objects_1 = require("@jsopen/objects");
7
+ const putil_varhelpers_1 = require("putil-varhelpers");
8
+ function getMongodbConfig(moduleOptions, prefix = 'MONGODB_') {
9
+ const options = (0, objects_1.clone)(moduleOptions);
10
+ const env = node_process_1.default.env;
11
+ options.url = options.url || (env[prefix + 'URL'] ?? 'mongodb://localhost:27017');
12
+ options.timeoutMS = options.timeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'TIMEOUT']);
13
+ options.replicaSet = options.replicaSet ?? env[prefix + 'REPLICA_SET'];
14
+ options.tls = options.tls ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS']);
15
+ options.tlsCertificateKeyFile = options.tlsCertificateKeyFile ?? env[prefix + 'TLS_CERT_FILE'];
16
+ options.tlsCertificateKeyFilePassword = options.tlsCertificateKeyFilePassword ?? env[prefix + 'TLS_CERT_FILE_PASS'];
17
+ options.tlsCAFile = options.tlsCAFile ?? env[prefix + 'TLS_CA_FILE'];
18
+ options.tlsCRLFile = options.tlsCRLFile ?? env[prefix + 'TLS_CRL_FILE'];
19
+ options.tlsAllowInvalidCertificates =
20
+ options.tlsAllowInvalidCertificates ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_ALLOW_INVALID_CERTIFICATES']);
21
+ options.tlsAllowInvalidCertificates =
22
+ options.tlsAllowInvalidHostnames ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_ALLOW_INVALID_HOSTNAMES']);
23
+ options.tlsInsecure = options.tlsInsecure ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_INSECURE']);
24
+ options.connectTimeoutMS = options.connectTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'CONNECT_TIMEOUT']);
25
+ options.socketTimeoutMS = options.socketTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SOCKET_TIMEOUT']);
26
+ options.database = options.database ?? env[prefix + 'DATABASE'];
27
+ options.srvMaxHosts = options.srvMaxHosts ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SRV_MAX_HOSTS']);
28
+ options.maxPoolSize = options.minPoolSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_POOL_SIZE']);
29
+ options.minPoolSize = options.maxPoolSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MIN_POOL_SIZE']);
30
+ options.maxConnecting = options.maxConnecting ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CONNECTING']);
31
+ options.maxIdleTimeMS = options.maxIdleTimeMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_IDLE_TIME']);
32
+ options.waitQueueTimeoutMS = options.waitQueueTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_WAIT_QUEUE_TIMEOUT']);
33
+ options.maxStalenessSeconds = options.maxStalenessSeconds ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_STALENESS_SECONDS']);
34
+ if (!options.auth?.username) {
35
+ options.auth = options.auth || {};
36
+ options.auth.username = options.auth.username ?? env[prefix + 'USERNAME'];
37
+ options.auth.password = options.auth.password ?? env[prefix + 'PASSWORD'];
38
+ }
39
+ options.authSource = options.authSource ?? env[prefix + 'AUTH_SOURCE'];
40
+ options.localThresholdMS = options.localThresholdMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'LOCAL_THRESHOLD']);
41
+ options.serverSelectionTimeoutMS =
42
+ options.serverSelectionTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SERVER_SELECTION_TIMEOUT']);
43
+ options.minHeartbeatFrequencyMS = options.minHeartbeatFrequencyMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_FREQUENCY']);
44
+ options.appName = options.appName ?? env[prefix + 'APP_NAME'];
45
+ options.retryReads = options.retryReads ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'RETRY_READS']);
46
+ options.retryWrites = options.retryWrites ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'RETRY_WRITES']);
47
+ options.directConnection = options.directConnection ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'DIRECT_CONNECTION']);
48
+ options.loadBalanced = options.loadBalanced ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LOAD_BALANCED']);
49
+ options.noDelay = options.noDelay ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'NO_DELAY']);
50
+ options.monitorCommands = options.monitorCommands ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'MONITOR_COMMANDS']);
51
+ options.proxyHost = options.proxyHost ?? env[prefix + 'PROXY_HOST'];
52
+ options.proxyPort = options.proxyPort ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PROXY_PORT']);
53
+ options.proxyUsername = options.proxyHost ?? env[prefix + 'PROXY_USERNAME'];
54
+ options.proxyPassword = options.proxyPassword ?? env[prefix + 'PROXY_PASSWORD'];
55
+ return options;
56
+ }
package/cjs/index.js CHANGED
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./constants.js"), exports);
5
+ tslib_1.__exportStar(require("./get-mongodb-config.js"), exports);
5
6
  tslib_1.__exportStar(require("./mongodb.module.js"), exports);
6
7
  tslib_1.__exportStar(require("./types.js"), exports);
@@ -5,20 +5,19 @@ exports.MongodbCoreModule = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const assert = tslib_1.__importStar(require("node:assert"));
7
7
  const crypto = tslib_1.__importStar(require("node:crypto"));
8
- const process = tslib_1.__importStar(require("node:process"));
9
8
  const objects_1 = require("@jsopen/objects");
10
9
  const common_1 = require("@nestjs/common");
11
10
  const colors = tslib_1.__importStar(require("ansi-colors"));
12
11
  const mongodb_1 = require("mongodb");
13
- const putil_varhelpers_1 = require("putil-varhelpers");
14
12
  const constants_js_1 = require("./constants.js");
13
+ const get_mongodb_config_js_1 = require("./get-mongodb-config.js");
15
14
  const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
16
15
  let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
17
16
  /**
18
17
  * Configures and returns a dynamic module for MongoDB integration.
19
18
  */
20
19
  static forRoot(moduleOptions) {
21
- const connectionOptions = this._readConnectionOptions(moduleOptions.useValue || {}, moduleOptions.envPrefix);
20
+ const connectionOptions = (0, get_mongodb_config_js_1.getMongodbConfig)(moduleOptions.useValue || {}, moduleOptions.envPrefix);
22
21
  return this._createDynamicModule(moduleOptions, {
23
22
  global: moduleOptions.global,
24
23
  providers: [
@@ -42,7 +41,7 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
42
41
  inject: asyncOptions.inject,
43
42
  useFactory: async (...args) => {
44
43
  const opts = await asyncOptions.useFactory(...args);
45
- return this._readConnectionOptions(opts, asyncOptions.envPrefix);
44
+ return (0, get_mongodb_config_js_1.getMongodbConfig)(opts, asyncOptions.envPrefix);
46
45
  },
47
46
  },
48
47
  ],
@@ -92,55 +91,6 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
92
91
  exports: [constants_js_1.MONGODB_CONNECTION_OPTIONS, token, dbToken, ...(metadata.exports ?? [])],
93
92
  };
94
93
  }
95
- static _readConnectionOptions(moduleOptions, prefix = 'MONGODB_') {
96
- const options = (0, objects_1.clone)(moduleOptions);
97
- const env = process.env;
98
- options.url = options.url || (env[prefix + 'URL'] ?? 'mongodb://localhost:27017');
99
- options.timeoutMS = options.timeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'TIMEOUT']);
100
- options.replicaSet = options.replicaSet ?? env[prefix + 'REPLICA_SET'];
101
- options.tls = options.tls ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS']);
102
- options.tlsCertificateKeyFile = options.tlsCertificateKeyFile ?? env[prefix + 'TLS_CERT_FILE'];
103
- options.tlsCertificateKeyFilePassword = options.tlsCertificateKeyFilePassword ?? env[prefix + 'TLS_CERT_FILE_PASS'];
104
- options.tlsCAFile = options.tlsCAFile ?? env[prefix + 'TLS_CA_FILE'];
105
- options.tlsCRLFile = options.tlsCRLFile ?? env[prefix + 'TLS_CRL_FILE'];
106
- options.tlsAllowInvalidCertificates =
107
- options.tlsAllowInvalidCertificates ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_ALLOW_INVALID_CERTIFICATES']);
108
- options.tlsAllowInvalidCertificates =
109
- options.tlsAllowInvalidHostnames ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_ALLOW_INVALID_HOSTNAMES']);
110
- options.tlsInsecure = options.tlsInsecure ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_INSECURE']);
111
- options.connectTimeoutMS = options.connectTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'CONNECT_TIMEOUT']);
112
- options.socketTimeoutMS = options.socketTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SOCKET_TIMEOUT']);
113
- options.database = options.database ?? env[prefix + 'DATABASE'];
114
- options.srvMaxHosts = options.srvMaxHosts ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SRV_MAX_HOSTS']);
115
- options.maxPoolSize = options.minPoolSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_POOL_SIZE']);
116
- options.minPoolSize = options.maxPoolSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MIN_POOL_SIZE']);
117
- options.maxConnecting = options.maxConnecting ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CONNECTING']);
118
- options.maxIdleTimeMS = options.maxIdleTimeMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_IDLE_TIME']);
119
- options.waitQueueTimeoutMS = options.waitQueueTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_WAIT_QUEUE_TIMEOUT']);
120
- options.maxStalenessSeconds = options.maxStalenessSeconds ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_STALENESS_SECONDS']);
121
- if (!options.auth?.username) {
122
- options.auth = options.auth || {};
123
- options.auth.username = options.auth.username ?? env[prefix + 'USERNAME'];
124
- options.auth.password = options.auth.password ?? env[prefix + 'PASSWORD'];
125
- }
126
- options.authSource = options.authSource ?? env[prefix + 'AUTH_SOURCE'];
127
- options.localThresholdMS = options.localThresholdMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'LOCAL_THRESHOLD']);
128
- options.serverSelectionTimeoutMS =
129
- options.serverSelectionTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SERVER_SELECTION_TIMEOUT']);
130
- options.minHeartbeatFrequencyMS = options.minHeartbeatFrequencyMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_FREQUENCY']);
131
- options.appName = options.appName ?? env[prefix + 'APP_NAME'];
132
- options.retryReads = options.retryReads ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'RETRY_READS']);
133
- options.retryWrites = options.retryWrites ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'RETRY_WRITES']);
134
- options.directConnection = options.directConnection ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'DIRECT_CONNECTION']);
135
- options.loadBalanced = options.loadBalanced ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LOAD_BALANCED']);
136
- options.noDelay = options.noDelay ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'NO_DELAY']);
137
- options.monitorCommands = options.monitorCommands ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'MONITOR_COMMANDS']);
138
- options.proxyHost = options.proxyHost ?? env[prefix + 'PROXY_HOST'];
139
- options.proxyPort = options.proxyPort ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PROXY_PORT']);
140
- options.proxyUsername = options.proxyHost ?? env[prefix + 'PROXY_USERNAME'];
141
- options.proxyPassword = options.proxyPassword ?? env[prefix + 'PROXY_PASSWORD'];
142
- return options;
143
- }
144
94
  /**
145
95
  *
146
96
  * @constructor
@@ -0,0 +1,52 @@
1
+ import process from 'node:process';
2
+ import { clone } from '@jsopen/objects';
3
+ import { toBoolean, toInt } from 'putil-varhelpers';
4
+ export function getMongodbConfig(moduleOptions, prefix = 'MONGODB_') {
5
+ const options = clone(moduleOptions);
6
+ const env = process.env;
7
+ options.url = options.url || (env[prefix + 'URL'] ?? 'mongodb://localhost:27017');
8
+ options.timeoutMS = options.timeoutMS ?? toInt(env[prefix + 'TIMEOUT']);
9
+ options.replicaSet = options.replicaSet ?? env[prefix + 'REPLICA_SET'];
10
+ options.tls = options.tls ?? toBoolean(env[prefix + 'TLS']);
11
+ options.tlsCertificateKeyFile = options.tlsCertificateKeyFile ?? env[prefix + 'TLS_CERT_FILE'];
12
+ options.tlsCertificateKeyFilePassword = options.tlsCertificateKeyFilePassword ?? env[prefix + 'TLS_CERT_FILE_PASS'];
13
+ options.tlsCAFile = options.tlsCAFile ?? env[prefix + 'TLS_CA_FILE'];
14
+ options.tlsCRLFile = options.tlsCRLFile ?? env[prefix + 'TLS_CRL_FILE'];
15
+ options.tlsAllowInvalidCertificates =
16
+ options.tlsAllowInvalidCertificates ?? toBoolean(env[prefix + 'TLS_ALLOW_INVALID_CERTIFICATES']);
17
+ options.tlsAllowInvalidCertificates =
18
+ options.tlsAllowInvalidHostnames ?? toBoolean(env[prefix + 'TLS_ALLOW_INVALID_HOSTNAMES']);
19
+ options.tlsInsecure = options.tlsInsecure ?? toBoolean(env[prefix + 'TLS_INSECURE']);
20
+ options.connectTimeoutMS = options.connectTimeoutMS ?? toInt(env[prefix + 'CONNECT_TIMEOUT']);
21
+ options.socketTimeoutMS = options.socketTimeoutMS ?? toInt(env[prefix + 'SOCKET_TIMEOUT']);
22
+ options.database = options.database ?? env[prefix + 'DATABASE'];
23
+ options.srvMaxHosts = options.srvMaxHosts ?? toInt(env[prefix + 'SRV_MAX_HOSTS']);
24
+ options.maxPoolSize = options.minPoolSize ?? toInt(env[prefix + 'MAX_POOL_SIZE']);
25
+ options.minPoolSize = options.maxPoolSize ?? toInt(env[prefix + 'MIN_POOL_SIZE']);
26
+ options.maxConnecting = options.maxConnecting ?? toInt(env[prefix + 'MAX_CONNECTING']);
27
+ options.maxIdleTimeMS = options.maxIdleTimeMS ?? toInt(env[prefix + 'MAX_IDLE_TIME']);
28
+ options.waitQueueTimeoutMS = options.waitQueueTimeoutMS ?? toInt(env[prefix + 'MAX_WAIT_QUEUE_TIMEOUT']);
29
+ options.maxStalenessSeconds = options.maxStalenessSeconds ?? toInt(env[prefix + 'MAX_STALENESS_SECONDS']);
30
+ if (!options.auth?.username) {
31
+ options.auth = options.auth || {};
32
+ options.auth.username = options.auth.username ?? env[prefix + 'USERNAME'];
33
+ options.auth.password = options.auth.password ?? env[prefix + 'PASSWORD'];
34
+ }
35
+ options.authSource = options.authSource ?? env[prefix + 'AUTH_SOURCE'];
36
+ options.localThresholdMS = options.localThresholdMS ?? toInt(env[prefix + 'LOCAL_THRESHOLD']);
37
+ options.serverSelectionTimeoutMS =
38
+ options.serverSelectionTimeoutMS ?? toInt(env[prefix + 'SERVER_SELECTION_TIMEOUT']);
39
+ options.minHeartbeatFrequencyMS = options.minHeartbeatFrequencyMS ?? toInt(env[prefix + 'HEARTBEAT_FREQUENCY']);
40
+ options.appName = options.appName ?? env[prefix + 'APP_NAME'];
41
+ options.retryReads = options.retryReads ?? toBoolean(env[prefix + 'RETRY_READS']);
42
+ options.retryWrites = options.retryWrites ?? toBoolean(env[prefix + 'RETRY_WRITES']);
43
+ options.directConnection = options.directConnection ?? toBoolean(env[prefix + 'DIRECT_CONNECTION']);
44
+ options.loadBalanced = options.loadBalanced ?? toBoolean(env[prefix + 'LOAD_BALANCED']);
45
+ options.noDelay = options.noDelay ?? toBoolean(env[prefix + 'NO_DELAY']);
46
+ options.monitorCommands = options.monitorCommands ?? toBoolean(env[prefix + 'MONITOR_COMMANDS']);
47
+ options.proxyHost = options.proxyHost ?? env[prefix + 'PROXY_HOST'];
48
+ options.proxyPort = options.proxyPort ?? toInt(env[prefix + 'PROXY_PORT']);
49
+ options.proxyUsername = options.proxyHost ?? env[prefix + 'PROXY_USERNAME'];
50
+ options.proxyPassword = options.proxyPassword ?? env[prefix + 'PROXY_PASSWORD'];
51
+ return options;
52
+ }
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './constants.js';
2
+ export * from './get-mongodb-config.js';
2
3
  export * from './mongodb.module.js';
3
4
  export * from './types.js';
@@ -2,20 +2,19 @@ var MongodbCoreModule_1;
2
2
  import { __decorate, __metadata, __param } from "tslib";
3
3
  import * as assert from 'node:assert';
4
4
  import * as crypto from 'node:crypto';
5
- import * as process from 'node:process';
6
- import { clone, omit } from '@jsopen/objects';
5
+ import { omit } from '@jsopen/objects';
7
6
  import { Inject, Logger } from '@nestjs/common';
8
7
  import * as colors from 'ansi-colors';
9
8
  import { Db, MongoClient } from 'mongodb';
10
- import { toBoolean, toInt } from 'putil-varhelpers';
11
9
  import { MONGODB_CONNECTION_OPTIONS, MONGODB_MODULE_ID } from './constants.js';
10
+ import { getMongodbConfig } from './get-mongodb-config.js';
12
11
  const CLIENT_TOKEN = Symbol('CLIENT_TOKEN');
13
12
  let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
14
13
  /**
15
14
  * Configures and returns a dynamic module for MongoDB integration.
16
15
  */
17
16
  static forRoot(moduleOptions) {
18
- const connectionOptions = this._readConnectionOptions(moduleOptions.useValue || {}, moduleOptions.envPrefix);
17
+ const connectionOptions = getMongodbConfig(moduleOptions.useValue || {}, moduleOptions.envPrefix);
19
18
  return this._createDynamicModule(moduleOptions, {
20
19
  global: moduleOptions.global,
21
20
  providers: [
@@ -39,7 +38,7 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
39
38
  inject: asyncOptions.inject,
40
39
  useFactory: async (...args) => {
41
40
  const opts = await asyncOptions.useFactory(...args);
42
- return this._readConnectionOptions(opts, asyncOptions.envPrefix);
41
+ return getMongodbConfig(opts, asyncOptions.envPrefix);
43
42
  },
44
43
  },
45
44
  ],
@@ -89,55 +88,6 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
89
88
  exports: [MONGODB_CONNECTION_OPTIONS, token, dbToken, ...(metadata.exports ?? [])],
90
89
  };
91
90
  }
92
- static _readConnectionOptions(moduleOptions, prefix = 'MONGODB_') {
93
- const options = clone(moduleOptions);
94
- const env = process.env;
95
- options.url = options.url || (env[prefix + 'URL'] ?? 'mongodb://localhost:27017');
96
- options.timeoutMS = options.timeoutMS ?? toInt(env[prefix + 'TIMEOUT']);
97
- options.replicaSet = options.replicaSet ?? env[prefix + 'REPLICA_SET'];
98
- options.tls = options.tls ?? toBoolean(env[prefix + 'TLS']);
99
- options.tlsCertificateKeyFile = options.tlsCertificateKeyFile ?? env[prefix + 'TLS_CERT_FILE'];
100
- options.tlsCertificateKeyFilePassword = options.tlsCertificateKeyFilePassword ?? env[prefix + 'TLS_CERT_FILE_PASS'];
101
- options.tlsCAFile = options.tlsCAFile ?? env[prefix + 'TLS_CA_FILE'];
102
- options.tlsCRLFile = options.tlsCRLFile ?? env[prefix + 'TLS_CRL_FILE'];
103
- options.tlsAllowInvalidCertificates =
104
- options.tlsAllowInvalidCertificates ?? toBoolean(env[prefix + 'TLS_ALLOW_INVALID_CERTIFICATES']);
105
- options.tlsAllowInvalidCertificates =
106
- options.tlsAllowInvalidHostnames ?? toBoolean(env[prefix + 'TLS_ALLOW_INVALID_HOSTNAMES']);
107
- options.tlsInsecure = options.tlsInsecure ?? toBoolean(env[prefix + 'TLS_INSECURE']);
108
- options.connectTimeoutMS = options.connectTimeoutMS ?? toInt(env[prefix + 'CONNECT_TIMEOUT']);
109
- options.socketTimeoutMS = options.socketTimeoutMS ?? toInt(env[prefix + 'SOCKET_TIMEOUT']);
110
- options.database = options.database ?? env[prefix + 'DATABASE'];
111
- options.srvMaxHosts = options.srvMaxHosts ?? toInt(env[prefix + 'SRV_MAX_HOSTS']);
112
- options.maxPoolSize = options.minPoolSize ?? toInt(env[prefix + 'MAX_POOL_SIZE']);
113
- options.minPoolSize = options.maxPoolSize ?? toInt(env[prefix + 'MIN_POOL_SIZE']);
114
- options.maxConnecting = options.maxConnecting ?? toInt(env[prefix + 'MAX_CONNECTING']);
115
- options.maxIdleTimeMS = options.maxIdleTimeMS ?? toInt(env[prefix + 'MAX_IDLE_TIME']);
116
- options.waitQueueTimeoutMS = options.waitQueueTimeoutMS ?? toInt(env[prefix + 'MAX_WAIT_QUEUE_TIMEOUT']);
117
- options.maxStalenessSeconds = options.maxStalenessSeconds ?? toInt(env[prefix + 'MAX_STALENESS_SECONDS']);
118
- if (!options.auth?.username) {
119
- options.auth = options.auth || {};
120
- options.auth.username = options.auth.username ?? env[prefix + 'USERNAME'];
121
- options.auth.password = options.auth.password ?? env[prefix + 'PASSWORD'];
122
- }
123
- options.authSource = options.authSource ?? env[prefix + 'AUTH_SOURCE'];
124
- options.localThresholdMS = options.localThresholdMS ?? toInt(env[prefix + 'LOCAL_THRESHOLD']);
125
- options.serverSelectionTimeoutMS =
126
- options.serverSelectionTimeoutMS ?? toInt(env[prefix + 'SERVER_SELECTION_TIMEOUT']);
127
- options.minHeartbeatFrequencyMS = options.minHeartbeatFrequencyMS ?? toInt(env[prefix + 'HEARTBEAT_FREQUENCY']);
128
- options.appName = options.appName ?? env[prefix + 'APP_NAME'];
129
- options.retryReads = options.retryReads ?? toBoolean(env[prefix + 'RETRY_READS']);
130
- options.retryWrites = options.retryWrites ?? toBoolean(env[prefix + 'RETRY_WRITES']);
131
- options.directConnection = options.directConnection ?? toBoolean(env[prefix + 'DIRECT_CONNECTION']);
132
- options.loadBalanced = options.loadBalanced ?? toBoolean(env[prefix + 'LOAD_BALANCED']);
133
- options.noDelay = options.noDelay ?? toBoolean(env[prefix + 'NO_DELAY']);
134
- options.monitorCommands = options.monitorCommands ?? toBoolean(env[prefix + 'MONITOR_COMMANDS']);
135
- options.proxyHost = options.proxyHost ?? env[prefix + 'PROXY_HOST'];
136
- options.proxyPort = options.proxyPort ?? toInt(env[prefix + 'PROXY_PORT']);
137
- options.proxyUsername = options.proxyHost ?? env[prefix + 'PROXY_USERNAME'];
138
- options.proxyPassword = options.proxyPassword ?? env[prefix + 'PROXY_PASSWORD'];
139
- return options;
140
- }
141
91
  /**
142
92
  *
143
93
  * @constructor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xnestjs/mongodb",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "NestJS extension library for MongoDb",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -13,7 +13,7 @@
13
13
  "peerDependencies": {
14
14
  "@nestjs/common": "^10.0.0 || ^11.0.0",
15
15
  "@nestjs/core": "^10.0.0 || ^11.0.0",
16
- "mongodb": "^6.0.0"
16
+ "mongodb": "^6.14.0"
17
17
  },
18
18
  "type": "module",
19
19
  "exports": {
@@ -0,0 +1,2 @@
1
+ import type { MongodbConnectionOptions } from './types.js';
2
+ export declare function getMongodbConfig(moduleOptions: MongodbConnectionOptions, prefix?: string): MongodbConnectionOptions;
package/types/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './constants.js';
2
+ export * from './get-mongodb-config.js';
2
3
  export * from './mongodb.module.js';
3
4
  export * from './types.js';
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './constants.js';
2
+ export * from './get-mongodb-config.js';
2
3
  export * from './mongodb.module.js';
3
4
  export * from './types.js';
@@ -14,7 +14,6 @@ export declare class MongodbCoreModule implements OnApplicationShutdown, OnAppli
14
14
  */
15
15
  static forRootAsync(asyncOptions: MongodbModuleAsyncOptions): DynamicModule;
16
16
  private static _createDynamicModule;
17
- private static _readConnectionOptions;
18
17
  /**
19
18
  *
20
19
  * @constructor