@xnestjs/mongodb 1.7.0 → 1.8.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 +21 -23
- package/cjs/get-mongodb-config.js +49 -24
- package/cjs/mongodb-core.module.js +17 -4
- package/cjs/mongodb.health.js +2 -1
- package/esm/get-mongodb-config.js +49 -24
- package/esm/mongodb-core.module.js +18 -5
- package/esm/mongodb.health.js +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -22,17 +22,16 @@ import { Module } from '@nestjs/common';
|
|
|
22
22
|
import { MongoModule } from '@xnestjs/mongodb';
|
|
23
23
|
|
|
24
24
|
@Module({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
imports: [
|
|
26
|
+
MongodbModule.forRoot({
|
|
27
|
+
useValue: {
|
|
28
|
+
url: 'https://mydbserver:27017',
|
|
29
|
+
database: 'test',
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
33
|
})
|
|
34
|
-
export class MyModule {
|
|
35
|
-
}
|
|
34
|
+
export class MyModule {}
|
|
36
35
|
```
|
|
37
36
|
|
|
38
37
|
### Register async
|
|
@@ -45,29 +44,28 @@ import { Module } from '@nestjs/common';
|
|
|
45
44
|
import { MongoModule } from '@xnestjs/mongodb';
|
|
46
45
|
|
|
47
46
|
@Module({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
imports: [
|
|
48
|
+
MongodbModule.forRootAsync({
|
|
49
|
+
inject: [ConfigModule],
|
|
50
|
+
useFactory: (config: ConfigService) => ({
|
|
51
|
+
url: config.get('MONGODB_URL'),
|
|
52
|
+
database: config.get('MONGODB_DATABASE'),
|
|
53
|
+
}),
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
57
56
|
})
|
|
58
|
-
export class MyModule {
|
|
59
|
-
}
|
|
57
|
+
export class MyModule {}
|
|
60
58
|
```
|
|
61
59
|
|
|
62
60
|
## Environment Variables
|
|
63
61
|
|
|
64
62
|
The library supports configuration through environment variables. Environment variables below is accepted.
|
|
65
|
-
All environment variables starts with prefix (
|
|
63
|
+
All environment variables starts with prefix (MONGODB\_). This can be configured while registering the module.
|
|
66
64
|
|
|
67
65
|
<--- BEGIN env --->
|
|
68
66
|
|
|
69
67
|
| Environment Variable | Type | Default | Description |
|
|
70
|
-
|
|
68
|
+
| -------------------------------------- | ------- | ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
71
69
|
| MONGODB_URL | String | mongodb://localhost:27017 | URL to MongoDB server |
|
|
72
70
|
| MONGODB_USERNAME | String | | The username for auth |
|
|
73
71
|
| MONGODB_PASSWORD | String | | The password for auth |
|
|
@@ -8,49 +8,74 @@ const putil_varhelpers_1 = require("putil-varhelpers");
|
|
|
8
8
|
function getMongodbConfig(moduleOptions, prefix = 'MONGODB_') {
|
|
9
9
|
const options = (0, objects_1.clone)(moduleOptions);
|
|
10
10
|
const env = node_process_1.default.env;
|
|
11
|
-
options.url =
|
|
11
|
+
options.url =
|
|
12
|
+
options.url || (env[prefix + 'URL'] ?? 'mongodb://localhost:27017');
|
|
12
13
|
options.timeoutMS = options.timeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'TIMEOUT']);
|
|
13
14
|
options.replicaSet = options.replicaSet ?? env[prefix + 'REPLICA_SET'];
|
|
14
15
|
options.tls = options.tls ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS']);
|
|
15
|
-
options.tlsCertificateKeyFile =
|
|
16
|
-
|
|
16
|
+
options.tlsCertificateKeyFile =
|
|
17
|
+
options.tlsCertificateKeyFile ?? env[prefix + 'TLS_CERT_FILE'];
|
|
18
|
+
options.tlsCertificateKeyFilePassword =
|
|
19
|
+
options.tlsCertificateKeyFilePassword ?? env[prefix + 'TLS_CERT_FILE_PASS'];
|
|
17
20
|
options.tlsCAFile = options.tlsCAFile ?? env[prefix + 'TLS_CA_FILE'];
|
|
18
21
|
options.tlsCRLFile = options.tlsCRLFile ?? env[prefix + 'TLS_CRL_FILE'];
|
|
19
22
|
options.tlsAllowInvalidCertificates =
|
|
20
|
-
options.tlsAllowInvalidCertificates ??
|
|
23
|
+
options.tlsAllowInvalidCertificates ??
|
|
24
|
+
(0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_ALLOW_INVALID_CERTIFICATES']);
|
|
21
25
|
options.tlsAllowInvalidCertificates =
|
|
22
|
-
options.tlsAllowInvalidHostnames ??
|
|
23
|
-
|
|
24
|
-
options.
|
|
25
|
-
|
|
26
|
+
options.tlsAllowInvalidHostnames ??
|
|
27
|
+
(0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_ALLOW_INVALID_HOSTNAMES']);
|
|
28
|
+
options.tlsInsecure =
|
|
29
|
+
options.tlsInsecure ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'TLS_INSECURE']);
|
|
30
|
+
options.connectTimeoutMS =
|
|
31
|
+
options.connectTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'CONNECT_TIMEOUT']);
|
|
32
|
+
options.socketTimeoutMS =
|
|
33
|
+
options.socketTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SOCKET_TIMEOUT']);
|
|
26
34
|
options.database = options.database ?? env[prefix + 'DATABASE'];
|
|
27
|
-
options.srvMaxHosts =
|
|
28
|
-
|
|
29
|
-
options.
|
|
30
|
-
|
|
31
|
-
options.
|
|
32
|
-
|
|
33
|
-
options.
|
|
35
|
+
options.srvMaxHosts =
|
|
36
|
+
options.srvMaxHosts ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'SRV_MAX_HOSTS']);
|
|
37
|
+
options.maxPoolSize =
|
|
38
|
+
options.minPoolSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_POOL_SIZE']);
|
|
39
|
+
options.minPoolSize =
|
|
40
|
+
options.maxPoolSize ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MIN_POOL_SIZE']);
|
|
41
|
+
options.maxConnecting =
|
|
42
|
+
options.maxConnecting ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_CONNECTING']);
|
|
43
|
+
options.maxIdleTimeMS =
|
|
44
|
+
options.maxIdleTimeMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_IDLE_TIME']);
|
|
45
|
+
options.waitQueueTimeoutMS =
|
|
46
|
+
options.waitQueueTimeoutMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_WAIT_QUEUE_TIMEOUT']);
|
|
47
|
+
options.maxStalenessSeconds =
|
|
48
|
+
options.maxStalenessSeconds ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'MAX_STALENESS_SECONDS']);
|
|
34
49
|
if (!options.auth?.username) {
|
|
35
50
|
options.auth = options.auth || {};
|
|
36
51
|
options.auth.username = options.auth.username ?? env[prefix + 'USERNAME'];
|
|
37
52
|
options.auth.password = options.auth.password ?? env[prefix + 'PASSWORD'];
|
|
38
53
|
}
|
|
39
54
|
options.authSource = options.authSource ?? env[prefix + 'AUTH_SOURCE'];
|
|
40
|
-
options.localThresholdMS =
|
|
55
|
+
options.localThresholdMS =
|
|
56
|
+
options.localThresholdMS ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'LOCAL_THRESHOLD']);
|
|
41
57
|
options.serverSelectionTimeoutMS =
|
|
42
|
-
options.serverSelectionTimeoutMS ??
|
|
43
|
-
|
|
58
|
+
options.serverSelectionTimeoutMS ??
|
|
59
|
+
(0, putil_varhelpers_1.toInt)(env[prefix + 'SERVER_SELECTION_TIMEOUT']);
|
|
60
|
+
options.minHeartbeatFrequencyMS =
|
|
61
|
+
options.minHeartbeatFrequencyMS ??
|
|
62
|
+
(0, putil_varhelpers_1.toInt)(env[prefix + 'HEARTBEAT_FREQUENCY']);
|
|
44
63
|
options.appName = options.appName ?? env[prefix + 'APP_NAME'];
|
|
45
|
-
options.retryReads =
|
|
46
|
-
|
|
47
|
-
options.
|
|
48
|
-
|
|
64
|
+
options.retryReads =
|
|
65
|
+
options.retryReads ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'RETRY_READS']);
|
|
66
|
+
options.retryWrites =
|
|
67
|
+
options.retryWrites ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'RETRY_WRITES']);
|
|
68
|
+
options.directConnection =
|
|
69
|
+
options.directConnection ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'DIRECT_CONNECTION']);
|
|
70
|
+
options.loadBalanced =
|
|
71
|
+
options.loadBalanced ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'LOAD_BALANCED']);
|
|
49
72
|
options.noDelay = options.noDelay ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'NO_DELAY']);
|
|
50
|
-
options.monitorCommands =
|
|
73
|
+
options.monitorCommands =
|
|
74
|
+
options.monitorCommands ?? (0, putil_varhelpers_1.toBoolean)(env[prefix + 'MONITOR_COMMANDS']);
|
|
51
75
|
options.proxyHost = options.proxyHost ?? env[prefix + 'PROXY_HOST'];
|
|
52
76
|
options.proxyPort = options.proxyPort ?? (0, putil_varhelpers_1.toInt)(env[prefix + 'PROXY_PORT']);
|
|
53
77
|
options.proxyUsername = options.proxyHost ?? env[prefix + 'PROXY_USERNAME'];
|
|
54
|
-
options.proxyPassword =
|
|
78
|
+
options.proxyPassword =
|
|
79
|
+
options.proxyPassword ?? env[prefix + 'PROXY_PASSWORD'];
|
|
55
80
|
return options;
|
|
56
81
|
}
|
|
@@ -55,7 +55,11 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
55
55
|
provide: token,
|
|
56
56
|
inject: [constants_js_1.MONGODB_CONNECTION_OPTIONS],
|
|
57
57
|
useFactory: async (connectionOptions) => {
|
|
58
|
-
const mongoOptions = (0, objects_1.omit)(connectionOptions, [
|
|
58
|
+
const mongoOptions = (0, objects_1.omit)(connectionOptions, [
|
|
59
|
+
'url',
|
|
60
|
+
'database',
|
|
61
|
+
'lazyConnect',
|
|
62
|
+
]);
|
|
59
63
|
if (mongoOptions.auth && !mongoOptions.auth?.username)
|
|
60
64
|
delete mongoOptions.auth;
|
|
61
65
|
return new mongodb_1.MongoClient(connectionOptions.url, mongoOptions);
|
|
@@ -65,7 +69,9 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
65
69
|
provide: dbToken,
|
|
66
70
|
inject: [token, constants_js_1.MONGODB_CONNECTION_OPTIONS],
|
|
67
71
|
useFactory: async (client, connectionOptions) => {
|
|
68
|
-
return connectionOptions.database
|
|
72
|
+
return connectionOptions.database
|
|
73
|
+
? client.db(connectionOptions.database)
|
|
74
|
+
: undefined;
|
|
69
75
|
},
|
|
70
76
|
},
|
|
71
77
|
{
|
|
@@ -74,7 +80,9 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
74
80
|
},
|
|
75
81
|
{
|
|
76
82
|
provide: common_1.Logger,
|
|
77
|
-
useValue: typeof opts.logger === 'string'
|
|
83
|
+
useValue: typeof opts.logger === 'string'
|
|
84
|
+
? new common_1.Logger(opts.logger)
|
|
85
|
+
: opts.logger,
|
|
78
86
|
},
|
|
79
87
|
];
|
|
80
88
|
return {
|
|
@@ -88,7 +96,12 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
88
96
|
useValue: crypto.randomUUID(),
|
|
89
97
|
},
|
|
90
98
|
],
|
|
91
|
-
exports: [
|
|
99
|
+
exports: [
|
|
100
|
+
constants_js_1.MONGODB_CONNECTION_OPTIONS,
|
|
101
|
+
token,
|
|
102
|
+
dbToken,
|
|
103
|
+
...(metadata.exports ?? []),
|
|
104
|
+
],
|
|
92
105
|
};
|
|
93
106
|
}
|
|
94
107
|
/**
|
package/cjs/mongodb.health.js
CHANGED
|
@@ -18,7 +18,8 @@ let MongodbHealthIndicator = class MongodbHealthIndicator {
|
|
|
18
18
|
}
|
|
19
19
|
async pingCheck(key, options) {
|
|
20
20
|
const { HealthIndicatorService } = await Promise.resolve().then(() => tslib_1.__importStar(require('@nestjs/terminus')));
|
|
21
|
-
this.healthIndicatorService =
|
|
21
|
+
this.healthIndicatorService =
|
|
22
|
+
this.healthIndicatorService || new HealthIndicatorService();
|
|
22
23
|
const indicator = this.healthIndicatorService.check(key);
|
|
23
24
|
let connection;
|
|
24
25
|
try {
|
|
@@ -4,49 +4,74 @@ import { toBoolean, toInt } from 'putil-varhelpers';
|
|
|
4
4
|
export function getMongodbConfig(moduleOptions, prefix = 'MONGODB_') {
|
|
5
5
|
const options = clone(moduleOptions);
|
|
6
6
|
const env = process.env;
|
|
7
|
-
options.url =
|
|
7
|
+
options.url =
|
|
8
|
+
options.url || (env[prefix + 'URL'] ?? 'mongodb://localhost:27017');
|
|
8
9
|
options.timeoutMS = options.timeoutMS ?? toInt(env[prefix + 'TIMEOUT']);
|
|
9
10
|
options.replicaSet = options.replicaSet ?? env[prefix + 'REPLICA_SET'];
|
|
10
11
|
options.tls = options.tls ?? toBoolean(env[prefix + 'TLS']);
|
|
11
|
-
options.tlsCertificateKeyFile =
|
|
12
|
-
|
|
12
|
+
options.tlsCertificateKeyFile =
|
|
13
|
+
options.tlsCertificateKeyFile ?? env[prefix + 'TLS_CERT_FILE'];
|
|
14
|
+
options.tlsCertificateKeyFilePassword =
|
|
15
|
+
options.tlsCertificateKeyFilePassword ?? env[prefix + 'TLS_CERT_FILE_PASS'];
|
|
13
16
|
options.tlsCAFile = options.tlsCAFile ?? env[prefix + 'TLS_CA_FILE'];
|
|
14
17
|
options.tlsCRLFile = options.tlsCRLFile ?? env[prefix + 'TLS_CRL_FILE'];
|
|
15
18
|
options.tlsAllowInvalidCertificates =
|
|
16
|
-
options.tlsAllowInvalidCertificates ??
|
|
19
|
+
options.tlsAllowInvalidCertificates ??
|
|
20
|
+
toBoolean(env[prefix + 'TLS_ALLOW_INVALID_CERTIFICATES']);
|
|
17
21
|
options.tlsAllowInvalidCertificates =
|
|
18
|
-
options.tlsAllowInvalidHostnames ??
|
|
19
|
-
|
|
20
|
-
options.
|
|
21
|
-
|
|
22
|
+
options.tlsAllowInvalidHostnames ??
|
|
23
|
+
toBoolean(env[prefix + 'TLS_ALLOW_INVALID_HOSTNAMES']);
|
|
24
|
+
options.tlsInsecure =
|
|
25
|
+
options.tlsInsecure ?? toBoolean(env[prefix + 'TLS_INSECURE']);
|
|
26
|
+
options.connectTimeoutMS =
|
|
27
|
+
options.connectTimeoutMS ?? toInt(env[prefix + 'CONNECT_TIMEOUT']);
|
|
28
|
+
options.socketTimeoutMS =
|
|
29
|
+
options.socketTimeoutMS ?? toInt(env[prefix + 'SOCKET_TIMEOUT']);
|
|
22
30
|
options.database = options.database ?? env[prefix + 'DATABASE'];
|
|
23
|
-
options.srvMaxHosts =
|
|
24
|
-
|
|
25
|
-
options.
|
|
26
|
-
|
|
27
|
-
options.
|
|
28
|
-
|
|
29
|
-
options.
|
|
31
|
+
options.srvMaxHosts =
|
|
32
|
+
options.srvMaxHosts ?? toInt(env[prefix + 'SRV_MAX_HOSTS']);
|
|
33
|
+
options.maxPoolSize =
|
|
34
|
+
options.minPoolSize ?? toInt(env[prefix + 'MAX_POOL_SIZE']);
|
|
35
|
+
options.minPoolSize =
|
|
36
|
+
options.maxPoolSize ?? toInt(env[prefix + 'MIN_POOL_SIZE']);
|
|
37
|
+
options.maxConnecting =
|
|
38
|
+
options.maxConnecting ?? toInt(env[prefix + 'MAX_CONNECTING']);
|
|
39
|
+
options.maxIdleTimeMS =
|
|
40
|
+
options.maxIdleTimeMS ?? toInt(env[prefix + 'MAX_IDLE_TIME']);
|
|
41
|
+
options.waitQueueTimeoutMS =
|
|
42
|
+
options.waitQueueTimeoutMS ?? toInt(env[prefix + 'MAX_WAIT_QUEUE_TIMEOUT']);
|
|
43
|
+
options.maxStalenessSeconds =
|
|
44
|
+
options.maxStalenessSeconds ?? toInt(env[prefix + 'MAX_STALENESS_SECONDS']);
|
|
30
45
|
if (!options.auth?.username) {
|
|
31
46
|
options.auth = options.auth || {};
|
|
32
47
|
options.auth.username = options.auth.username ?? env[prefix + 'USERNAME'];
|
|
33
48
|
options.auth.password = options.auth.password ?? env[prefix + 'PASSWORD'];
|
|
34
49
|
}
|
|
35
50
|
options.authSource = options.authSource ?? env[prefix + 'AUTH_SOURCE'];
|
|
36
|
-
options.localThresholdMS =
|
|
51
|
+
options.localThresholdMS =
|
|
52
|
+
options.localThresholdMS ?? toInt(env[prefix + 'LOCAL_THRESHOLD']);
|
|
37
53
|
options.serverSelectionTimeoutMS =
|
|
38
|
-
options.serverSelectionTimeoutMS ??
|
|
39
|
-
|
|
54
|
+
options.serverSelectionTimeoutMS ??
|
|
55
|
+
toInt(env[prefix + 'SERVER_SELECTION_TIMEOUT']);
|
|
56
|
+
options.minHeartbeatFrequencyMS =
|
|
57
|
+
options.minHeartbeatFrequencyMS ??
|
|
58
|
+
toInt(env[prefix + 'HEARTBEAT_FREQUENCY']);
|
|
40
59
|
options.appName = options.appName ?? env[prefix + 'APP_NAME'];
|
|
41
|
-
options.retryReads =
|
|
42
|
-
|
|
43
|
-
options.
|
|
44
|
-
|
|
60
|
+
options.retryReads =
|
|
61
|
+
options.retryReads ?? toBoolean(env[prefix + 'RETRY_READS']);
|
|
62
|
+
options.retryWrites =
|
|
63
|
+
options.retryWrites ?? toBoolean(env[prefix + 'RETRY_WRITES']);
|
|
64
|
+
options.directConnection =
|
|
65
|
+
options.directConnection ?? toBoolean(env[prefix + 'DIRECT_CONNECTION']);
|
|
66
|
+
options.loadBalanced =
|
|
67
|
+
options.loadBalanced ?? toBoolean(env[prefix + 'LOAD_BALANCED']);
|
|
45
68
|
options.noDelay = options.noDelay ?? toBoolean(env[prefix + 'NO_DELAY']);
|
|
46
|
-
options.monitorCommands =
|
|
69
|
+
options.monitorCommands =
|
|
70
|
+
options.monitorCommands ?? toBoolean(env[prefix + 'MONITOR_COMMANDS']);
|
|
47
71
|
options.proxyHost = options.proxyHost ?? env[prefix + 'PROXY_HOST'];
|
|
48
72
|
options.proxyPort = options.proxyPort ?? toInt(env[prefix + 'PROXY_PORT']);
|
|
49
73
|
options.proxyUsername = options.proxyHost ?? env[prefix + 'PROXY_USERNAME'];
|
|
50
|
-
options.proxyPassword =
|
|
74
|
+
options.proxyPassword =
|
|
75
|
+
options.proxyPassword ?? env[prefix + 'PROXY_PASSWORD'];
|
|
51
76
|
return options;
|
|
52
77
|
}
|
|
@@ -3,7 +3,7 @@ import { __decorate, __metadata, __param } from "tslib";
|
|
|
3
3
|
import * as assert from 'node:assert';
|
|
4
4
|
import * as crypto from 'node:crypto';
|
|
5
5
|
import { omit } from '@jsopen/objects';
|
|
6
|
-
import { Inject, Logger } from '@nestjs/common';
|
|
6
|
+
import { Inject, Logger, } from '@nestjs/common';
|
|
7
7
|
import colors from 'ansi-colors';
|
|
8
8
|
import { Db, MongoClient } from 'mongodb';
|
|
9
9
|
import { MONGODB_CONNECTION_OPTIONS, MONGODB_MODULE_ID } from './constants.js';
|
|
@@ -52,7 +52,11 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
52
52
|
provide: token,
|
|
53
53
|
inject: [MONGODB_CONNECTION_OPTIONS],
|
|
54
54
|
useFactory: async (connectionOptions) => {
|
|
55
|
-
const mongoOptions = omit(connectionOptions, [
|
|
55
|
+
const mongoOptions = omit(connectionOptions, [
|
|
56
|
+
'url',
|
|
57
|
+
'database',
|
|
58
|
+
'lazyConnect',
|
|
59
|
+
]);
|
|
56
60
|
if (mongoOptions.auth && !mongoOptions.auth?.username)
|
|
57
61
|
delete mongoOptions.auth;
|
|
58
62
|
return new MongoClient(connectionOptions.url, mongoOptions);
|
|
@@ -62,7 +66,9 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
62
66
|
provide: dbToken,
|
|
63
67
|
inject: [token, MONGODB_CONNECTION_OPTIONS],
|
|
64
68
|
useFactory: async (client, connectionOptions) => {
|
|
65
|
-
return connectionOptions.database
|
|
69
|
+
return connectionOptions.database
|
|
70
|
+
? client.db(connectionOptions.database)
|
|
71
|
+
: undefined;
|
|
66
72
|
},
|
|
67
73
|
},
|
|
68
74
|
{
|
|
@@ -71,7 +77,9 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
71
77
|
},
|
|
72
78
|
{
|
|
73
79
|
provide: Logger,
|
|
74
|
-
useValue: typeof opts.logger === 'string'
|
|
80
|
+
useValue: typeof opts.logger === 'string'
|
|
81
|
+
? new Logger(opts.logger)
|
|
82
|
+
: opts.logger,
|
|
75
83
|
},
|
|
76
84
|
];
|
|
77
85
|
return {
|
|
@@ -85,7 +93,12 @@ let MongodbCoreModule = MongodbCoreModule_1 = class MongodbCoreModule {
|
|
|
85
93
|
useValue: crypto.randomUUID(),
|
|
86
94
|
},
|
|
87
95
|
],
|
|
88
|
-
exports: [
|
|
96
|
+
exports: [
|
|
97
|
+
MONGODB_CONNECTION_OPTIONS,
|
|
98
|
+
token,
|
|
99
|
+
dbToken,
|
|
100
|
+
...(metadata.exports ?? []),
|
|
101
|
+
],
|
|
89
102
|
};
|
|
90
103
|
}
|
|
91
104
|
/**
|
package/esm/mongodb.health.js
CHANGED
|
@@ -15,7 +15,8 @@ let MongodbHealthIndicator = class MongodbHealthIndicator {
|
|
|
15
15
|
}
|
|
16
16
|
async pingCheck(key, options) {
|
|
17
17
|
const { HealthIndicatorService } = await import('@nestjs/terminus');
|
|
18
|
-
this.healthIndicatorService =
|
|
18
|
+
this.healthIndicatorService =
|
|
19
|
+
this.healthIndicatorService || new HealthIndicatorService();
|
|
19
20
|
const indicator = this.healthIndicatorService.check(key);
|
|
20
21
|
let connection;
|
|
21
22
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xnestjs/mongodb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.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.
|
|
16
|
+
"mongodb": "^6.15.0"
|
|
17
17
|
},
|
|
18
18
|
"type": "module",
|
|
19
19
|
"exports": {
|