@ebarahona/loopback-connector-mongodb 1.0.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/LICENSE +21 -0
- package/README.md +526 -0
- package/dist/connector/coercion.d.ts +30 -0
- package/dist/connector/coercion.js +75 -0
- package/dist/connector/coercion.js.map +1 -0
- package/dist/connector/errors.d.ts +13 -0
- package/dist/connector/errors.js +20 -0
- package/dist/connector/errors.js.map +1 -0
- package/dist/connector/index.d.ts +6 -0
- package/dist/connector/index.js +24 -0
- package/dist/connector/index.js.map +1 -0
- package/dist/connector/mongo.connector.d.ts +171 -0
- package/dist/connector/mongo.connector.js +567 -0
- package/dist/connector/mongo.connector.js.map +1 -0
- package/dist/connector/property-mapping.d.ts +64 -0
- package/dist/connector/property-mapping.js +105 -0
- package/dist/connector/property-mapping.js.map +1 -0
- package/dist/connector/query-builder.d.ts +42 -0
- package/dist/connector/query-builder.js +204 -0
- package/dist/connector/query-builder.js.map +1 -0
- package/dist/datasource/index.d.ts +3 -0
- package/dist/datasource/index.js +10 -0
- package/dist/datasource/index.js.map +1 -0
- package/dist/datasource/mongo.datasource.d.ts +17 -0
- package/dist/datasource/mongo.datasource.factory.d.ts +30 -0
- package/dist/datasource/mongo.datasource.factory.js +44 -0
- package/dist/datasource/mongo.datasource.factory.js.map +1 -0
- package/dist/datasource/mongo.datasource.js +40 -0
- package/dist/datasource/mongo.datasource.js.map +1 -0
- package/dist/datasource/mongo.datasource.provider.d.ts +17 -0
- package/dist/datasource/mongo.datasource.provider.js +42 -0
- package/dist/datasource/mongo.datasource.provider.js.map +1 -0
- package/dist/helpers/config-validator.d.ts +34 -0
- package/dist/helpers/config-validator.js +79 -0
- package/dist/helpers/config-validator.js.map +1 -0
- package/dist/helpers/connection-manager.d.ts +78 -0
- package/dist/helpers/connection-manager.js +212 -0
- package/dist/helpers/connection-manager.js.map +1 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +15 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/topology.d.ts +23 -0
- package/dist/helpers/topology.js +27 -0
- package/dist/helpers/topology.js.map +1 -0
- package/dist/helpers/url-builder.d.ts +7 -0
- package/dist/helpers/url-builder.js +30 -0
- package/dist/helpers/url-builder.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +38 -0
- package/dist/keys.js +38 -0
- package/dist/keys.js.map +1 -0
- package/dist/mongo.component.d.ts +59 -0
- package/dist/mongo.component.js +138 -0
- package/dist/mongo.component.js.map +1 -0
- package/dist/providers/index.d.ts +0 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +7 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/mongo.service.d.ts +61 -0
- package/dist/services/mongo.service.impl.d.ts +58 -0
- package/dist/services/mongo.service.impl.js +211 -0
- package/dist/services/mongo.service.impl.js.map +1 -0
- package/dist/services/mongo.service.js +3 -0
- package/dist/services/mongo.service.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoConfigError = void 0;
|
|
4
|
+
exports.validateConfig = validateConfig;
|
|
5
|
+
exports.redactUrl = redactUrl;
|
|
6
|
+
/**
|
|
7
|
+
* Error thrown when the connector config fails framework-level
|
|
8
|
+
* validation before any MongoDB driver call is made.
|
|
9
|
+
*
|
|
10
|
+
* Messages never contain credentials -- the offending URL or
|
|
11
|
+
* config object is redacted before formatting.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
class MongoConfigError extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'MongoConfigError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.MongoConfigError = MongoConfigError;
|
|
22
|
+
const SUPPORTED_SCHEMES = new Set(['mongodb:', 'mongodb+srv:']);
|
|
23
|
+
/**
|
|
24
|
+
* Validate connector config. Throws MongoConfigError for cases the
|
|
25
|
+
* driver would otherwise surface as opaque runtime errors:
|
|
26
|
+
* - neither `url` nor `host` set
|
|
27
|
+
* - `url` is not a parseable mongodb:// or mongodb+srv:// URL
|
|
28
|
+
*
|
|
29
|
+
* Everything else (auth shape, TLS, pool sizing) is passed through
|
|
30
|
+
* to the driver, which has good error messages for those.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
function validateConfig(config) {
|
|
35
|
+
if (!config) {
|
|
36
|
+
throw new MongoConfigError('MongoDB config is missing. Bind MongoBindings.CONFIG or ' +
|
|
37
|
+
'pass settings to the DataSource.');
|
|
38
|
+
}
|
|
39
|
+
if (!config.url && !config.host) {
|
|
40
|
+
throw new MongoConfigError('MongoDB config requires either `url` or `host`. Got neither.');
|
|
41
|
+
}
|
|
42
|
+
if (config.url) {
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
parsed = new URL(config.url);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
throw new MongoConfigError(`MongoDB url is not a valid URL: ${redactUrl(config.url)}`);
|
|
49
|
+
}
|
|
50
|
+
if (!SUPPORTED_SCHEMES.has(parsed.protocol)) {
|
|
51
|
+
throw new MongoConfigError(`MongoDB url scheme must be mongodb:// or mongodb+srv://, ` +
|
|
52
|
+
`got "${parsed.protocol}" in ${redactUrl(config.url)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Replace `username:password@` with `<credentials>@` in a connection
|
|
58
|
+
* string. Safe to log. Handles credentials containing literal `@`
|
|
59
|
+
* characters by parsing the URL rather than relying on regex.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
function redactUrl(url) {
|
|
64
|
+
try {
|
|
65
|
+
const parsed = new URL(url);
|
|
66
|
+
if (parsed.username || parsed.password) {
|
|
67
|
+
parsed.username = '';
|
|
68
|
+
parsed.password = '';
|
|
69
|
+
return parsed.toString().replace('//', '//<credentials>@');
|
|
70
|
+
}
|
|
71
|
+
return url;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Fall back to regex-based redaction if URL parsing fails (e.g.
|
|
75
|
+
// for non-URL inputs reused for logging).
|
|
76
|
+
return url.replace(/\/\/[^/]*@/, '//<credentials>@');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=config-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-validator.js","sourceRoot":"","sources":["../../src/helpers/config-validator.ts"],"names":[],"mappings":";;;AA+BA,wCA8BC;AASD,8BAcC;AAlFD;;;;;;;;GAQG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IAEzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,SAAI,GAAG,kBAAkB,CAAC;IAG5C,CAAC;CACF;AALD,4CAKC;AAED,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAC,MAAwC;IACrE,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,gBAAgB,CACxB,0DAA0D;YACxD,kCAAkC,CACrC,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAChC,MAAM,IAAI,gBAAgB,CACxB,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,IAAI,MAAW,CAAC;QAChB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,gBAAgB,CACxB,mCAAmC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC3D,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,gBAAgB,CACxB,2DAA2D;gBACzD,QAAQ,MAAM,CAAC,QAAQ,QAAQ,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CACzD,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,GAAW;IACnC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACvC,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC;YACrB,MAAM,CAAC,QAAQ,GAAG,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACP,gEAAgE;QAChE,0CAA0C;QAC1C,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IACvD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Db } from 'mongodb';
|
|
2
|
+
import { MongoClient } from 'mongodb';
|
|
3
|
+
import type { MongoConnectorConfig } from '../types';
|
|
4
|
+
import type { TopologyInfo } from './topology';
|
|
5
|
+
/**
|
|
6
|
+
* Thrown when an operation against the connection manager is invalid
|
|
7
|
+
* for its current state (no client connected, manager disposed, etc.).
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare class MongoConnectionError extends Error {
|
|
12
|
+
readonly name = "MongoConnectionError";
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Centralized connection manager for the MongoDB client.
|
|
17
|
+
*
|
|
18
|
+
* Owns one MongoClient singleton. Both the juggler connector and
|
|
19
|
+
* MongoService use the same manager, guaranteeing one connection
|
|
20
|
+
* pool, one lifecycle, and one topology state.
|
|
21
|
+
*
|
|
22
|
+
* - `connect()` is idempotent and concurrency-safe.
|
|
23
|
+
* - `disconnect()` is idempotent and coordinates with in-flight connects.
|
|
24
|
+
* - Repeated start/stop cycles are safe (test restarts, hot reload).
|
|
25
|
+
* - A generation counter prevents stale connect from overriding disconnect.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export declare class MongoConnectionManager {
|
|
30
|
+
private readonly config;
|
|
31
|
+
private client?;
|
|
32
|
+
private db?;
|
|
33
|
+
private state;
|
|
34
|
+
private connectPromise?;
|
|
35
|
+
private disconnectPromise?;
|
|
36
|
+
private topologyInfo?;
|
|
37
|
+
private generation;
|
|
38
|
+
constructor(config: MongoConnectorConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Connect to MongoDB. Idempotent and concurrency-safe.
|
|
41
|
+
* Concurrent calls share the same connection promise.
|
|
42
|
+
* If disconnect is in progress, awaits the real disconnect
|
|
43
|
+
* promise (no spin wait, no timeout) before starting connect.
|
|
44
|
+
*/
|
|
45
|
+
connect(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Disconnect from MongoDB. Idempotent and concurrency-safe.
|
|
48
|
+
* Concurrent calls share the same disconnect promise.
|
|
49
|
+
* Waits for any in-flight connect to settle before closing.
|
|
50
|
+
* Uses generation counter to prevent stale connect from
|
|
51
|
+
* overriding this disconnect.
|
|
52
|
+
*/
|
|
53
|
+
disconnect(): Promise<void>;
|
|
54
|
+
private doDisconnect;
|
|
55
|
+
/**
|
|
56
|
+
* Get the connected MongoClient. Throws if not connected.
|
|
57
|
+
*/
|
|
58
|
+
getClient(): MongoClient;
|
|
59
|
+
/**
|
|
60
|
+
* Get the default Db instance. Throws if not connected.
|
|
61
|
+
*/
|
|
62
|
+
getDb(name?: string): Db;
|
|
63
|
+
/**
|
|
64
|
+
* Get topology info. Best-effort detection using driver internals.
|
|
65
|
+
* Returns unknown topology if not connected.
|
|
66
|
+
*/
|
|
67
|
+
getTopology(): TopologyInfo;
|
|
68
|
+
/**
|
|
69
|
+
* Whether the client is connected.
|
|
70
|
+
*/
|
|
71
|
+
isConnected(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Ping the server. Throws if not connected or server unreachable.
|
|
74
|
+
*/
|
|
75
|
+
ping(): Promise<void>;
|
|
76
|
+
private doConnect;
|
|
77
|
+
private extractDatabaseFromUrl;
|
|
78
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MongoConnectionManager = exports.MongoConnectionError = void 0;
|
|
7
|
+
const mongodb_1 = require("mongodb");
|
|
8
|
+
const debug_1 = __importDefault(require("debug"));
|
|
9
|
+
const url_builder_1 = require("./url-builder");
|
|
10
|
+
const config_validator_1 = require("./config-validator");
|
|
11
|
+
const topology_1 = require("./topology");
|
|
12
|
+
const debug = (0, debug_1.default)('loopback:connector:mongodb:connection');
|
|
13
|
+
/**
|
|
14
|
+
* Thrown when an operation against the connection manager is invalid
|
|
15
|
+
* for its current state (no client connected, manager disposed, etc.).
|
|
16
|
+
*
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
class MongoConnectionError extends Error {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.name = 'MongoConnectionError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.MongoConnectionError = MongoConnectionError;
|
|
26
|
+
/**
|
|
27
|
+
* Centralized connection manager for the MongoDB client.
|
|
28
|
+
*
|
|
29
|
+
* Owns one MongoClient singleton. Both the juggler connector and
|
|
30
|
+
* MongoService use the same manager, guaranteeing one connection
|
|
31
|
+
* pool, one lifecycle, and one topology state.
|
|
32
|
+
*
|
|
33
|
+
* - `connect()` is idempotent and concurrency-safe.
|
|
34
|
+
* - `disconnect()` is idempotent and coordinates with in-flight connects.
|
|
35
|
+
* - Repeated start/stop cycles are safe (test restarts, hot reload).
|
|
36
|
+
* - A generation counter prevents stale connect from overriding disconnect.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
class MongoConnectionManager {
|
|
41
|
+
constructor(config) {
|
|
42
|
+
this.config = config;
|
|
43
|
+
this.state = 'disconnected';
|
|
44
|
+
this.generation = 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Connect to MongoDB. Idempotent and concurrency-safe.
|
|
48
|
+
* Concurrent calls share the same connection promise.
|
|
49
|
+
* If disconnect is in progress, awaits the real disconnect
|
|
50
|
+
* promise (no spin wait, no timeout) before starting connect.
|
|
51
|
+
*/
|
|
52
|
+
async connect() {
|
|
53
|
+
if (this.isConnected())
|
|
54
|
+
return;
|
|
55
|
+
if (this.disconnectPromise) {
|
|
56
|
+
try {
|
|
57
|
+
await this.disconnectPromise;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// disconnect failed; proceed with a fresh connect
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (this.isConnected())
|
|
64
|
+
return;
|
|
65
|
+
if (this.connectPromise) {
|
|
66
|
+
await this.connectPromise;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const gen = this.generation;
|
|
70
|
+
this.state = 'connecting';
|
|
71
|
+
this.connectPromise = this.doConnect(gen).finally(() => {
|
|
72
|
+
this.connectPromise = undefined;
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
await this.connectPromise;
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (this.generation === gen) {
|
|
79
|
+
this.state = 'disconnected';
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Disconnect from MongoDB. Idempotent and concurrency-safe.
|
|
86
|
+
* Concurrent calls share the same disconnect promise.
|
|
87
|
+
* Waits for any in-flight connect to settle before closing.
|
|
88
|
+
* Uses generation counter to prevent stale connect from
|
|
89
|
+
* overriding this disconnect.
|
|
90
|
+
*/
|
|
91
|
+
async disconnect() {
|
|
92
|
+
if (this.disconnectPromise) {
|
|
93
|
+
await this.disconnectPromise;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (this.state === 'disconnected' && !this.client && !this.connectPromise) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.generation++;
|
|
100
|
+
this.state = 'disconnecting';
|
|
101
|
+
this.disconnectPromise = this.doDisconnect().finally(() => {
|
|
102
|
+
this.disconnectPromise = undefined;
|
|
103
|
+
});
|
|
104
|
+
await this.disconnectPromise;
|
|
105
|
+
}
|
|
106
|
+
async doDisconnect() {
|
|
107
|
+
if (this.connectPromise) {
|
|
108
|
+
try {
|
|
109
|
+
await this.connectPromise;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// connect failed; proceed with disconnect
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (this.client) {
|
|
116
|
+
try {
|
|
117
|
+
await this.client.close();
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
debug('disconnect error: %O', err);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
this.client = undefined;
|
|
124
|
+
this.db = undefined;
|
|
125
|
+
this.topologyInfo = undefined;
|
|
126
|
+
this.state = 'disconnected';
|
|
127
|
+
debug('disconnected');
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get the connected MongoClient. Throws if not connected.
|
|
131
|
+
*/
|
|
132
|
+
getClient() {
|
|
133
|
+
if (!this.client || this.state !== 'connected') {
|
|
134
|
+
throw new MongoConnectionError('MongoClient is not connected');
|
|
135
|
+
}
|
|
136
|
+
return this.client;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get the default Db instance. Throws if not connected.
|
|
140
|
+
*/
|
|
141
|
+
getDb(name) {
|
|
142
|
+
if (!this.client || this.state !== 'connected') {
|
|
143
|
+
throw new MongoConnectionError('MongoClient is not connected');
|
|
144
|
+
}
|
|
145
|
+
if (name)
|
|
146
|
+
return this.client.db(name);
|
|
147
|
+
if (!this.db) {
|
|
148
|
+
throw new MongoConnectionError('MongoClient is not connected');
|
|
149
|
+
}
|
|
150
|
+
return this.db;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get topology info. Best-effort detection using driver internals.
|
|
154
|
+
* Returns unknown topology if not connected.
|
|
155
|
+
*/
|
|
156
|
+
getTopology() {
|
|
157
|
+
if (!this.client) {
|
|
158
|
+
return { isReplicaSet: false, topologyType: 'Unknown' };
|
|
159
|
+
}
|
|
160
|
+
return (0, topology_1.detectTopology)(this.client);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Whether the client is connected.
|
|
164
|
+
*/
|
|
165
|
+
isConnected() {
|
|
166
|
+
return this.state === 'connected';
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Ping the server. Throws if not connected or server unreachable.
|
|
170
|
+
*/
|
|
171
|
+
async ping() {
|
|
172
|
+
const db = this.getDb();
|
|
173
|
+
await db.command({ ping: 1 });
|
|
174
|
+
}
|
|
175
|
+
async doConnect(gen) {
|
|
176
|
+
(0, config_validator_1.validateConfig)(this.config);
|
|
177
|
+
const url = (0, url_builder_1.buildConnectionUrl)(this.config);
|
|
178
|
+
debug('connecting to %s', (0, config_validator_1.redactUrl)(url));
|
|
179
|
+
const client = new mongodb_1.MongoClient(url, this.config.clientOptions);
|
|
180
|
+
try {
|
|
181
|
+
await client.connect();
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
await client.close().catch(() => { });
|
|
185
|
+
throw err;
|
|
186
|
+
}
|
|
187
|
+
// Check generation: if disconnect happened during connect, don't
|
|
188
|
+
// set connected state -- close the client we just opened
|
|
189
|
+
if (this.generation !== gen) {
|
|
190
|
+
await client.close().catch(() => { });
|
|
191
|
+
throw new MongoConnectionError('Connection cancelled by disconnect');
|
|
192
|
+
}
|
|
193
|
+
this.client = client;
|
|
194
|
+
const dbName = this.config.database ?? this.extractDatabaseFromUrl(url);
|
|
195
|
+
this.db = client.db(dbName);
|
|
196
|
+
this.topologyInfo = (0, topology_1.detectTopology)(client);
|
|
197
|
+
this.state = 'connected';
|
|
198
|
+
debug('connected to database [%s] (topology: %s)', dbName, this.topologyInfo.topologyType);
|
|
199
|
+
}
|
|
200
|
+
extractDatabaseFromUrl(url) {
|
|
201
|
+
try {
|
|
202
|
+
const parsed = new URL(url);
|
|
203
|
+
const path = parsed.pathname;
|
|
204
|
+
return path.startsWith('/') ? path.slice(1) || 'test' : 'test';
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return 'test';
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.MongoConnectionManager = MongoConnectionManager;
|
|
212
|
+
//# sourceMappingURL=connection-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection-manager.js","sourceRoot":"","sources":["../../src/helpers/connection-manager.ts"],"names":[],"mappings":";;;;;;AACA,qCAAoC;AACpC,kDAAiC;AAEjC,+CAAiD;AACjD,yDAA6D;AAE7D,y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,GAAW;QACxC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC;YAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;QACjE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;CACF;AA/LD,wDA+LC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { detectTopology } from './topology';
|
|
2
|
+
export type { TopologyInfo } from './topology';
|
|
3
|
+
export { MongoConnectionManager, MongoConnectionError, } from './connection-manager';
|
|
4
|
+
export { buildConnectionUrl } from './url-builder';
|
|
5
|
+
export { MongoConfigError, validateConfig, redactUrl } from './config-validator';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactUrl = exports.validateConfig = exports.MongoConfigError = exports.buildConnectionUrl = exports.MongoConnectionError = exports.MongoConnectionManager = exports.detectTopology = void 0;
|
|
4
|
+
var topology_1 = require("./topology");
|
|
5
|
+
Object.defineProperty(exports, "detectTopology", { enumerable: true, get: function () { return topology_1.detectTopology; } });
|
|
6
|
+
var connection_manager_1 = require("./connection-manager");
|
|
7
|
+
Object.defineProperty(exports, "MongoConnectionManager", { enumerable: true, get: function () { return connection_manager_1.MongoConnectionManager; } });
|
|
8
|
+
Object.defineProperty(exports, "MongoConnectionError", { enumerable: true, get: function () { return connection_manager_1.MongoConnectionError; } });
|
|
9
|
+
var url_builder_1 = require("./url-builder");
|
|
10
|
+
Object.defineProperty(exports, "buildConnectionUrl", { enumerable: true, get: function () { return url_builder_1.buildConnectionUrl; } });
|
|
11
|
+
var config_validator_1 = require("./config-validator");
|
|
12
|
+
Object.defineProperty(exports, "MongoConfigError", { enumerable: true, get: function () { return config_validator_1.MongoConfigError; } });
|
|
13
|
+
Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return config_validator_1.validateConfig; } });
|
|
14
|
+
Object.defineProperty(exports, "redactUrl", { enumerable: true, get: function () { return config_validator_1.redactUrl; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAAlC,0GAAA,cAAc,OAAA;AAEtB,2DAG8B;AAF5B,4HAAA,sBAAsB,OAAA;AACtB,0HAAA,oBAAoB,OAAA;AAEtB,6CAAiD;AAAzC,iHAAA,kBAAkB,OAAA;AAC1B,uDAA+E;AAAvE,oHAAA,gBAAgB,OAAA;AAAE,kHAAA,cAAc,OAAA;AAAE,6GAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { MongoClient } from 'mongodb';
|
|
2
|
+
/**
|
|
3
|
+
* Describes the deployment topology shape of a connected MongoClient
|
|
4
|
+
* (standalone, replica set, sharded, or unknown).
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface TopologyInfo {
|
|
9
|
+
isReplicaSet: boolean;
|
|
10
|
+
topologyType: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Detect the topology type of a connected MongoClient.
|
|
14
|
+
* Call after client.connect() has resolved.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Relies on driver internals (`client.topology.description.type`)
|
|
18
|
+
* which are not guaranteed stable across MongoDB driver majors and
|
|
19
|
+
* may need to be revisited on driver upgrades.
|
|
20
|
+
*
|
|
21
|
+
* @experimental
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectTopology(client: MongoClient): TopologyInfo;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectTopology = detectTopology;
|
|
4
|
+
/**
|
|
5
|
+
* Detect the topology type of a connected MongoClient.
|
|
6
|
+
* Call after client.connect() has resolved.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Relies on driver internals (`client.topology.description.type`)
|
|
10
|
+
* which are not guaranteed stable across MongoDB driver majors and
|
|
11
|
+
* may need to be revisited on driver upgrades.
|
|
12
|
+
*
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
function detectTopology(client) {
|
|
16
|
+
// Access the internal topology description
|
|
17
|
+
// The topology property is available after connection
|
|
18
|
+
const description = client.topology?.description;
|
|
19
|
+
const type = description?.type ?? 'Unknown';
|
|
20
|
+
return {
|
|
21
|
+
isReplicaSet: type === 'ReplicaSetWithPrimary' ||
|
|
22
|
+
type === 'ReplicaSetNoPrimary' ||
|
|
23
|
+
type === 'Sharded',
|
|
24
|
+
topologyType: type,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=topology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"topology.js","sourceRoot":"","sources":["../../src/helpers/topology.ts"],"names":[],"mappings":";;AAwBA,wCAkBC;AA7BD;;;;;;;;;;GAUG;AACH,SAAgB,cAAc,CAAC,MAAmB;IAChD,2CAA2C;IAC3C,sDAAsD;IACtD,MAAM,WAAW,GACf,MAGD,CAAC,QAAQ,EAAE,WAAW,CAAC;IAExB,MAAM,IAAI,GAAG,WAAW,EAAE,IAAI,IAAI,SAAS,CAAC;IAE5C,OAAO;QACL,YAAY,EACV,IAAI,KAAK,uBAAuB;YAChC,IAAI,KAAK,qBAAqB;YAC9B,IAAI,KAAK,SAAS;QACpB,YAAY,EAAE,IAAI;KACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MongoConnectorConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Build a MongoDB connection URL from config.
|
|
4
|
+
* Single source of truth -- used by both the connection manager
|
|
5
|
+
* and the juggler initialize path.
|
|
6
|
+
*/
|
|
7
|
+
export declare function buildConnectionUrl(config: MongoConnectorConfig): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildConnectionUrl = buildConnectionUrl;
|
|
4
|
+
/**
|
|
5
|
+
* Build a MongoDB connection URL from config.
|
|
6
|
+
* Single source of truth -- used by both the connection manager
|
|
7
|
+
* and the juggler initialize path.
|
|
8
|
+
*/
|
|
9
|
+
function buildConnectionUrl(config) {
|
|
10
|
+
if (config.url)
|
|
11
|
+
return config.url;
|
|
12
|
+
const host = config.host ?? 'localhost';
|
|
13
|
+
const port = config.port ?? 27017;
|
|
14
|
+
const database = config.database ?? 'test';
|
|
15
|
+
let auth = '';
|
|
16
|
+
if (config.username && config.password) {
|
|
17
|
+
const user = encodeURIComponent(config.username);
|
|
18
|
+
const pass = encodeURIComponent(config.password);
|
|
19
|
+
auth = `${user}:${pass}@`;
|
|
20
|
+
}
|
|
21
|
+
const params = new URLSearchParams();
|
|
22
|
+
if (config.authSource)
|
|
23
|
+
params.set('authSource', config.authSource);
|
|
24
|
+
if (config.replicaSet)
|
|
25
|
+
params.set('replicaSet', config.replicaSet);
|
|
26
|
+
const queryString = params.toString();
|
|
27
|
+
const suffix = queryString ? `?${queryString}` : '';
|
|
28
|
+
return `mongodb://${auth}${host}:${port}/${database}${suffix}`;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=url-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-builder.js","sourceRoot":"","sources":["../../src/helpers/url-builder.ts"],"names":[],"mappings":";;AAOA,gDAsBC;AA3BD;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,MAA4B;IAC7D,IAAI,MAAM,CAAC,GAAG;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC;IAElC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,WAAW,CAAC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC;IAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC;IAE3C,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,GAAG,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC;IAC5B,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAI,MAAM,CAAC,UAAU;QAAE,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IACnE,IAAI,MAAM,CAAC,UAAU;QAAE,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAEnE,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;IACtC,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAEpD,OAAO,aAAa,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI,QAAQ,GAAG,MAAM,EAAE,CAAC;AACjE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { MongoComponent, MongoLifecycleObserver } from './mongo.component';
|
|
2
|
+
export { MongoBindings } from './keys';
|
|
3
|
+
export type { MongoConnectorConfig } from './types';
|
|
4
|
+
export { MongoConnector, initialize } from './connector';
|
|
5
|
+
export type { ModelDefinition, PropertyDefinition } from './connector';
|
|
6
|
+
export { MongoDataSource, MongoDataSourceProvider, MongoDataSourceFactoryProvider, } from './datasource';
|
|
7
|
+
export type { MongoDataSourceFactory } from './datasource';
|
|
8
|
+
export { MongoConfigError, validateConfig, redactUrl } from './helpers';
|
|
9
|
+
export { MongoService } from './services';
|
|
10
|
+
export { MongoServiceImpl } from './services';
|
|
11
|
+
export { MongoConnectionManager } from './helpers';
|
|
12
|
+
export type { TopologyInfo } from './helpers';
|
|
13
|
+
export { MongoConnectorError } from './connector';
|
|
14
|
+
export { MongoTopologyError } from './services';
|
|
15
|
+
export { MongoConnectionError } from './helpers';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoConnectionError = exports.MongoTopologyError = exports.MongoConnectorError = exports.MongoConnectionManager = exports.MongoServiceImpl = exports.redactUrl = exports.validateConfig = exports.MongoConfigError = exports.MongoDataSourceFactoryProvider = exports.MongoDataSourceProvider = exports.MongoDataSource = exports.initialize = exports.MongoConnector = exports.MongoBindings = exports.MongoLifecycleObserver = exports.MongoComponent = void 0;
|
|
4
|
+
// Component
|
|
5
|
+
var mongo_component_1 = require("./mongo.component");
|
|
6
|
+
Object.defineProperty(exports, "MongoComponent", { enumerable: true, get: function () { return mongo_component_1.MongoComponent; } });
|
|
7
|
+
Object.defineProperty(exports, "MongoLifecycleObserver", { enumerable: true, get: function () { return mongo_component_1.MongoLifecycleObserver; } });
|
|
8
|
+
// Binding keys
|
|
9
|
+
var keys_1 = require("./keys");
|
|
10
|
+
Object.defineProperty(exports, "MongoBindings", { enumerable: true, get: function () { return keys_1.MongoBindings; } });
|
|
11
|
+
// Connector (public: class + juggler initializer)
|
|
12
|
+
var connector_1 = require("./connector");
|
|
13
|
+
Object.defineProperty(exports, "MongoConnector", { enumerable: true, get: function () { return connector_1.MongoConnector; } });
|
|
14
|
+
Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return connector_1.initialize; } });
|
|
15
|
+
// DataSource (shared-manager juggler DataSource + provider + factory)
|
|
16
|
+
var datasource_1 = require("./datasource");
|
|
17
|
+
Object.defineProperty(exports, "MongoDataSource", { enumerable: true, get: function () { return datasource_1.MongoDataSource; } });
|
|
18
|
+
Object.defineProperty(exports, "MongoDataSourceProvider", { enumerable: true, get: function () { return datasource_1.MongoDataSourceProvider; } });
|
|
19
|
+
Object.defineProperty(exports, "MongoDataSourceFactoryProvider", { enumerable: true, get: function () { return datasource_1.MongoDataSourceFactoryProvider; } });
|
|
20
|
+
// Config validation
|
|
21
|
+
var helpers_1 = require("./helpers");
|
|
22
|
+
Object.defineProperty(exports, "MongoConfigError", { enumerable: true, get: function () { return helpers_1.MongoConfigError; } });
|
|
23
|
+
Object.defineProperty(exports, "validateConfig", { enumerable: true, get: function () { return helpers_1.validateConfig; } });
|
|
24
|
+
Object.defineProperty(exports, "redactUrl", { enumerable: true, get: function () { return helpers_1.redactUrl; } });
|
|
25
|
+
var services_1 = require("./services");
|
|
26
|
+
Object.defineProperty(exports, "MongoServiceImpl", { enumerable: true, get: function () { return services_1.MongoServiceImpl; } });
|
|
27
|
+
// Connection management
|
|
28
|
+
var helpers_2 = require("./helpers");
|
|
29
|
+
Object.defineProperty(exports, "MongoConnectionManager", { enumerable: true, get: function () { return helpers_2.MongoConnectionManager; } });
|
|
30
|
+
// Typed error classes for instanceof matching
|
|
31
|
+
var connector_2 = require("./connector");
|
|
32
|
+
Object.defineProperty(exports, "MongoConnectorError", { enumerable: true, get: function () { return connector_2.MongoConnectorError; } });
|
|
33
|
+
var services_2 = require("./services");
|
|
34
|
+
Object.defineProperty(exports, "MongoTopologyError", { enumerable: true, get: function () { return services_2.MongoTopologyError; } });
|
|
35
|
+
var helpers_3 = require("./helpers");
|
|
36
|
+
Object.defineProperty(exports, "MongoConnectionError", { enumerable: true, get: function () { return helpers_3.MongoConnectionError; } });
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,YAAY;AACZ,qDAAyE;AAAjE,iHAAA,cAAc,OAAA;AAAE,yHAAA,sBAAsB,OAAA;AAE9C,eAAe;AACf,+BAAqC;AAA7B,qGAAA,aAAa,OAAA;AAKrB,kDAAkD;AAClD,yCAAuD;AAA/C,2GAAA,cAAc,OAAA;AAAE,uGAAA,UAAU,OAAA;AAGlC,sEAAsE;AACtE,2CAIsB;AAHpB,6GAAA,eAAe,OAAA;AACf,qHAAA,uBAAuB,OAAA;AACvB,4HAAA,8BAA8B,OAAA;AAIhC,oBAAoB;AACpB,qCAAsE;AAA9D,2GAAA,gBAAgB,OAAA;AAAE,yGAAA,cAAc,OAAA;AAAE,oGAAA,SAAS,OAAA;AAInD,uCAA4C;AAApC,4GAAA,gBAAgB,OAAA;AAExB,wBAAwB;AACxB,qCAAiD;AAAzC,iHAAA,sBAAsB,OAAA;AAG9B,8CAA8C;AAC9C,yCAAgD;AAAxC,gHAAA,mBAAmB,OAAA;AAC3B,uCAA8C;AAAtC,8GAAA,kBAAkB,OAAA;AAC1B,qCAA+C;AAAvC,+GAAA,oBAAoB,OAAA"}
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BindingKey } from '@loopback/core';
|
|
2
|
+
import type { juggler } from '@loopback/repository';
|
|
3
|
+
import type { MongoService } from './services/mongo.service';
|
|
4
|
+
import type { MongoConnectorConfig } from './types';
|
|
5
|
+
import type { MongoConnectionManager } from './helpers/connection-manager';
|
|
6
|
+
import type { MongoDataSourceFactory } from './datasource/mongo.datasource.factory';
|
|
7
|
+
/**
|
|
8
|
+
* Binding keys for the MongoDB component.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare namespace MongoBindings {
|
|
13
|
+
/**
|
|
14
|
+
* Binding key for the shared MongoConnectionManager singleton.
|
|
15
|
+
* Owns the MongoClient and connection lifecycle.
|
|
16
|
+
*/
|
|
17
|
+
const CONNECTION_MANAGER: BindingKey<MongoConnectionManager>;
|
|
18
|
+
/**
|
|
19
|
+
* Binding key for the MongoService.
|
|
20
|
+
*/
|
|
21
|
+
const SERVICE: BindingKey<MongoService>;
|
|
22
|
+
/**
|
|
23
|
+
* Binding key for the connector configuration.
|
|
24
|
+
*/
|
|
25
|
+
const CONFIG: BindingKey<MongoConnectorConfig>;
|
|
26
|
+
/**
|
|
27
|
+
* Binding key for the shared juggler DataSource. The connector
|
|
28
|
+
* behind it uses the shared MongoConnectionManager, so repositories
|
|
29
|
+
* and MongoService share one connection pool.
|
|
30
|
+
*/
|
|
31
|
+
const DATASOURCE: BindingKey<juggler.DataSource>;
|
|
32
|
+
/**
|
|
33
|
+
* Binding key for a factory that builds MongoDataSource instances
|
|
34
|
+
* for multi-tenant or multi-database use. Each instance shares the
|
|
35
|
+
* singleton MongoConnectionManager (one MongoClient, one pool).
|
|
36
|
+
*/
|
|
37
|
+
const DATASOURCE_FACTORY: BindingKey<MongoDataSourceFactory>;
|
|
38
|
+
}
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MongoBindings = void 0;
|
|
4
|
+
const core_1 = require("@loopback/core");
|
|
5
|
+
/**
|
|
6
|
+
* Binding keys for the MongoDB component.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
var MongoBindings;
|
|
11
|
+
(function (MongoBindings) {
|
|
12
|
+
/**
|
|
13
|
+
* Binding key for the shared MongoConnectionManager singleton.
|
|
14
|
+
* Owns the MongoClient and connection lifecycle.
|
|
15
|
+
*/
|
|
16
|
+
MongoBindings.CONNECTION_MANAGER = core_1.BindingKey.create('mongo.connection-manager');
|
|
17
|
+
/**
|
|
18
|
+
* Binding key for the MongoService.
|
|
19
|
+
*/
|
|
20
|
+
MongoBindings.SERVICE = core_1.BindingKey.create('mongo.service');
|
|
21
|
+
/**
|
|
22
|
+
* Binding key for the connector configuration.
|
|
23
|
+
*/
|
|
24
|
+
MongoBindings.CONFIG = core_1.BindingKey.create('mongo.config');
|
|
25
|
+
/**
|
|
26
|
+
* Binding key for the shared juggler DataSource. The connector
|
|
27
|
+
* behind it uses the shared MongoConnectionManager, so repositories
|
|
28
|
+
* and MongoService share one connection pool.
|
|
29
|
+
*/
|
|
30
|
+
MongoBindings.DATASOURCE = core_1.BindingKey.create('datasources.mongo');
|
|
31
|
+
/**
|
|
32
|
+
* Binding key for a factory that builds MongoDataSource instances
|
|
33
|
+
* for multi-tenant or multi-database use. Each instance shares the
|
|
34
|
+
* singleton MongoConnectionManager (one MongoClient, one pool).
|
|
35
|
+
*/
|
|
36
|
+
MongoBindings.DATASOURCE_FACTORY = core_1.BindingKey.create('datasources.mongo.factory');
|
|
37
|
+
})(MongoBindings || (exports.MongoBindings = MongoBindings = {}));
|
|
38
|
+
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";;;AAAA,yCAA0C;AAO1C;;;;GAIG;AACH,IAAiB,aAAa,CAmC7B;AAnCD,WAAiB,aAAa;IAC5B;;;OAGG;IACU,gCAAkB,GAAG,iBAAU,CAAC,MAAM,CACjD,0BAA0B,CAC3B,CAAC;IAEF;;OAEG;IACU,qBAAO,GAAG,iBAAU,CAAC,MAAM,CAAe,eAAe,CAAC,CAAC;IAExE;;OAEG;IACU,oBAAM,GAAG,iBAAU,CAAC,MAAM,CAAuB,cAAc,CAAC,CAAC;IAE9E;;;;OAIG;IACU,wBAAU,GACrB,iBAAU,CAAC,MAAM,CAAqB,mBAAmB,CAAC,CAAC;IAE7D;;;;OAIG;IACU,gCAAkB,GAAG,iBAAU,CAAC,MAAM,CACjD,2BAA2B,CAC5B,CAAC;AACJ,CAAC,EAnCgB,aAAa,6BAAb,aAAa,QAmC7B"}
|