@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,567 @@
|
|
|
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.MongoConnector = exports.MongoConnectorError = void 0;
|
|
7
|
+
exports.initialize = initialize;
|
|
8
|
+
const mongodb_1 = require("mongodb");
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const coercion_1 = require("./coercion");
|
|
11
|
+
const query_builder_1 = require("./query-builder");
|
|
12
|
+
const property_mapping_1 = require("./property-mapping");
|
|
13
|
+
const connection_manager_1 = require("../helpers/connection-manager");
|
|
14
|
+
const config_validator_1 = require("../helpers/config-validator");
|
|
15
|
+
const errors_1 = require("./errors");
|
|
16
|
+
Object.defineProperty(exports, "MongoConnectorError", { enumerable: true, get: function () { return errors_1.MongoConnectorError; } });
|
|
17
|
+
const debug = (0, debug_1.default)('loopback:connector:mongodb');
|
|
18
|
+
/**
|
|
19
|
+
* Methods that loopback-datasource-juggler 6.x invokes via its
|
|
20
|
+
* callback-based DAO bridge (`invokeConnectorMethod`). Modern code
|
|
21
|
+
* uses these as promise-returning methods directly; this list only
|
|
22
|
+
* exists so the constructor can install per-instance shims that
|
|
23
|
+
* also fire a trailing Node-style callback when one is supplied
|
|
24
|
+
* positionally by the juggler runtime.
|
|
25
|
+
*/
|
|
26
|
+
const JUGGLER_BRIDGED_METHODS = [
|
|
27
|
+
'create',
|
|
28
|
+
'find',
|
|
29
|
+
'all',
|
|
30
|
+
'updateAll',
|
|
31
|
+
'deleteAll',
|
|
32
|
+
'count',
|
|
33
|
+
'replaceById',
|
|
34
|
+
'updateOrCreate',
|
|
35
|
+
'findOrCreate',
|
|
36
|
+
'exists',
|
|
37
|
+
'update',
|
|
38
|
+
'destroyAll',
|
|
39
|
+
'updateAttributes',
|
|
40
|
+
'save',
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* MongoDB connector for LoopBack 4.
|
|
44
|
+
*
|
|
45
|
+
* Implements the loopback-connector Connector interface using the
|
|
46
|
+
* native MongoDB Node.js driver 7.x.
|
|
47
|
+
*
|
|
48
|
+
* Uses a shared MongoConnectionManager for connection lifecycle.
|
|
49
|
+
* When used via MongoComponent, the same manager is shared with
|
|
50
|
+
* MongoService. When used standalone via juggler DataSource, the
|
|
51
|
+
* connector creates its own manager.
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
class MongoConnector {
|
|
56
|
+
/**
|
|
57
|
+
* @param settings - Connector configuration
|
|
58
|
+
* @param connectionManager - Optional shared connection manager.
|
|
59
|
+
* When provided (e.g. by MongoComponent), the connector uses
|
|
60
|
+
* the shared MongoClient and does NOT own disconnect.
|
|
61
|
+
* When omitted (standalone juggler use), the connector creates
|
|
62
|
+
* and owns its own manager.
|
|
63
|
+
*/
|
|
64
|
+
constructor(settings, connectionManager) {
|
|
65
|
+
this.name = 'mongodb';
|
|
66
|
+
this._models = {};
|
|
67
|
+
this.settings = {
|
|
68
|
+
allowExtendedOperators: true,
|
|
69
|
+
strictObjectIDCoercion: false,
|
|
70
|
+
...settings,
|
|
71
|
+
};
|
|
72
|
+
if (connectionManager) {
|
|
73
|
+
this.connectionManager = connectionManager;
|
|
74
|
+
this.ownsConnectionManager = false;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this.connectionManager = new connection_manager_1.MongoConnectionManager(this.settings);
|
|
78
|
+
this.ownsConnectionManager = true;
|
|
79
|
+
}
|
|
80
|
+
this.installJugglerBridge();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Install per-instance shims for the juggler 6.x DAO bridge.
|
|
84
|
+
*
|
|
85
|
+
* Juggler 6.x's `invokeConnectorMethod` invokes connector methods
|
|
86
|
+
* with `connector[method](modelName, ...args, opts?, cb)`, ignores
|
|
87
|
+
* any returned promise, and waits for `cb(err, result)` to fire.
|
|
88
|
+
* The class methods themselves stay strictly promise-returning;
|
|
89
|
+
* the shim simply extracts a trailing callback (if present) and
|
|
90
|
+
* relays settlement to it without altering the call's promise
|
|
91
|
+
* return value.
|
|
92
|
+
*
|
|
93
|
+
* This is the only place in the connector that inspects an
|
|
94
|
+
* argument to see if it's a function.
|
|
95
|
+
*/
|
|
96
|
+
installJugglerBridge() {
|
|
97
|
+
for (const name of JUGGLER_BRIDGED_METHODS) {
|
|
98
|
+
const original = this[name];
|
|
99
|
+
if (typeof original !== 'function')
|
|
100
|
+
continue;
|
|
101
|
+
const bound = original.bind(this);
|
|
102
|
+
// Five positional parameters so `Function.length === 5`. Juggler
|
|
103
|
+
// 6.x's `invokeConnectorMethod` uses `connector[method].length`
|
|
104
|
+
// to decide whether to pass `options` before the callback; any
|
|
105
|
+
// bridged method must report length >= argCount + 3 across all
|
|
106
|
+
// call sites (max argCount is 2 -> needs length >= 5).
|
|
107
|
+
function bridged(_a, _b, _c, _d, _e) {
|
|
108
|
+
const args = Array.from(arguments);
|
|
109
|
+
let cb;
|
|
110
|
+
if (args.length > 0 && typeof args[args.length - 1] === 'function') {
|
|
111
|
+
cb = args.pop();
|
|
112
|
+
}
|
|
113
|
+
const promise = bound(...args);
|
|
114
|
+
if (cb) {
|
|
115
|
+
promise.then(result => cb(null, result), err => cb(err));
|
|
116
|
+
}
|
|
117
|
+
return promise;
|
|
118
|
+
}
|
|
119
|
+
Object.defineProperty(this, name, {
|
|
120
|
+
value: bridged,
|
|
121
|
+
writable: true,
|
|
122
|
+
configurable: true,
|
|
123
|
+
enumerable: false,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// ---- Connection lifecycle ----
|
|
128
|
+
/**
|
|
129
|
+
* Connect to MongoDB. Delegates to the connection manager.
|
|
130
|
+
* Idempotent and concurrency-safe.
|
|
131
|
+
*/
|
|
132
|
+
async connect() {
|
|
133
|
+
await this.connectionManager.connect();
|
|
134
|
+
return this.connectionManager.getDb();
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Disconnect from MongoDB.
|
|
138
|
+
*
|
|
139
|
+
* Only disconnects if this connector owns its connection manager
|
|
140
|
+
* (standalone juggler DataSource use). When the manager is shared
|
|
141
|
+
* via MongoComponent, the lifecycle observer owns disconnect --
|
|
142
|
+
* calling this is a no-op.
|
|
143
|
+
*/
|
|
144
|
+
async disconnect() {
|
|
145
|
+
if (!this.ownsConnectionManager) {
|
|
146
|
+
debug('disconnect skipped (shared connection manager)');
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
await this.connectionManager.disconnect();
|
|
150
|
+
}
|
|
151
|
+
async ping() {
|
|
152
|
+
await this.connectionManager.ping();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Get the shared connection manager.
|
|
156
|
+
*/
|
|
157
|
+
getConnectionManager() {
|
|
158
|
+
return this.connectionManager;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the native MongoClient instance.
|
|
162
|
+
*/
|
|
163
|
+
getClient() {
|
|
164
|
+
try {
|
|
165
|
+
return this.connectionManager.getClient();
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get the native Db instance.
|
|
173
|
+
*/
|
|
174
|
+
getDb() {
|
|
175
|
+
try {
|
|
176
|
+
return this.connectionManager.getDb();
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// ---- Model definition ----
|
|
183
|
+
define(modelDefinition) {
|
|
184
|
+
const modelName = modelDefinition.model.modelName;
|
|
185
|
+
this._models[modelName] = modelDefinition;
|
|
186
|
+
debug('defined model [%s]', modelName);
|
|
187
|
+
}
|
|
188
|
+
getModelDefinition(modelName) {
|
|
189
|
+
return this._models[modelName];
|
|
190
|
+
}
|
|
191
|
+
// ---- CRUD operations ----
|
|
192
|
+
async create(modelName, data, options) {
|
|
193
|
+
const collection = await this.getCollection(modelName);
|
|
194
|
+
const modelDef = this._models[modelName];
|
|
195
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
196
|
+
let idValue = data[idName];
|
|
197
|
+
const doc = { ...data };
|
|
198
|
+
if (idValue === null || idValue === undefined) {
|
|
199
|
+
delete doc[idName];
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
doc._id = (0, coercion_1.coerceId)(idValue, modelDef?.properties[idName], this.settings.strictObjectIDCoercion);
|
|
203
|
+
if (idName !== '_id')
|
|
204
|
+
delete doc[idName];
|
|
205
|
+
}
|
|
206
|
+
const dbDoc = (0, property_mapping_1.toDatabase)(modelDef, doc);
|
|
207
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
208
|
+
const result = await collection.insertOne(dbDoc, sessionOpts);
|
|
209
|
+
if (idValue === null || idValue === undefined) {
|
|
210
|
+
idValue = result.insertedId;
|
|
211
|
+
}
|
|
212
|
+
debug('create [%s] id=%s', modelName, idValue);
|
|
213
|
+
return idValue;
|
|
214
|
+
}
|
|
215
|
+
async find(modelName, id, options) {
|
|
216
|
+
const collection = await this.getCollection(modelName);
|
|
217
|
+
const modelDef = this._models[modelName];
|
|
218
|
+
const coercedId = (0, coercion_1.coerceId)(id, modelDef?.properties[(0, property_mapping_1.getIdPropertyName)(modelDef)], this.settings.strictObjectIDCoercion);
|
|
219
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
220
|
+
const idFilter = { _id: coercedId };
|
|
221
|
+
const doc = await collection.findOne(idFilter, sessionOpts);
|
|
222
|
+
if (!doc)
|
|
223
|
+
return null;
|
|
224
|
+
return this.fromDb(modelName, doc);
|
|
225
|
+
}
|
|
226
|
+
async all(modelName, filter, options) {
|
|
227
|
+
const collection = await this.getCollection(modelName);
|
|
228
|
+
const modelDef = this._models[modelName];
|
|
229
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
230
|
+
const where = (0, query_builder_1.buildWhere)(filter?.where, idName);
|
|
231
|
+
const sort = (0, query_builder_1.buildSort)(filter?.order, idName);
|
|
232
|
+
const projection = (0, query_builder_1.buildFields)(filter?.fields, idName);
|
|
233
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
234
|
+
const findOptions = { ...sessionOpts };
|
|
235
|
+
if (projection)
|
|
236
|
+
findOptions.projection = projection;
|
|
237
|
+
// Driver 7 removed the implicit getMore batch cap. Provide a sane
|
|
238
|
+
// default when the caller does not supply an explicit limit.
|
|
239
|
+
if (filter?.limit === undefined &&
|
|
240
|
+
filter?.skip === undefined &&
|
|
241
|
+
filter?.offset === undefined) {
|
|
242
|
+
findOptions.batchSize = 1000;
|
|
243
|
+
}
|
|
244
|
+
let cursor = collection.find(where, findOptions);
|
|
245
|
+
if (sort)
|
|
246
|
+
cursor = cursor.sort(sort);
|
|
247
|
+
if (filter?.limit)
|
|
248
|
+
cursor = cursor.limit(filter.limit);
|
|
249
|
+
if (filter?.skip)
|
|
250
|
+
cursor = cursor.skip(filter.skip);
|
|
251
|
+
else if (filter?.offset)
|
|
252
|
+
cursor = cursor.skip(filter.offset);
|
|
253
|
+
const docs = await cursor.toArray();
|
|
254
|
+
return docs.map(doc => this.fromDb(modelName, doc));
|
|
255
|
+
}
|
|
256
|
+
async updateAll(modelName, where, data, options) {
|
|
257
|
+
const collection = await this.getCollection(modelName);
|
|
258
|
+
const modelDef = this._models[modelName];
|
|
259
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
260
|
+
const query = (0, query_builder_1.buildWhere)(where, idName);
|
|
261
|
+
const update = this.buildUpdate(modelName, data);
|
|
262
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
263
|
+
const result = await collection.updateMany(query, update, sessionOpts);
|
|
264
|
+
debug('updateAll [%s] matched=%d modified=%d', modelName, result.matchedCount, result.modifiedCount);
|
|
265
|
+
return { count: result.modifiedCount };
|
|
266
|
+
}
|
|
267
|
+
async deleteAll(modelName, where, options) {
|
|
268
|
+
const collection = await this.getCollection(modelName);
|
|
269
|
+
const modelDef = this._models[modelName];
|
|
270
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
271
|
+
const query = (0, query_builder_1.buildWhere)(where, idName);
|
|
272
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
273
|
+
const result = await collection.deleteMany(query, sessionOpts);
|
|
274
|
+
debug('deleteAll [%s] deleted=%d', modelName, result.deletedCount);
|
|
275
|
+
return { count: result.deletedCount };
|
|
276
|
+
}
|
|
277
|
+
async count(modelName, where, options) {
|
|
278
|
+
const collection = await this.getCollection(modelName);
|
|
279
|
+
const modelDef = this._models[modelName];
|
|
280
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
281
|
+
const query = (0, query_builder_1.buildWhere)(where, idName);
|
|
282
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
283
|
+
return collection.countDocuments(query, sessionOpts);
|
|
284
|
+
}
|
|
285
|
+
async replaceById(modelName, id, data, options) {
|
|
286
|
+
const collection = await this.getCollection(modelName);
|
|
287
|
+
const modelDef = this._models[modelName];
|
|
288
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
289
|
+
const coercedId = (0, coercion_1.coerceId)(id, modelDef?.properties[idName], this.settings.strictObjectIDCoercion);
|
|
290
|
+
const replacement = { ...data };
|
|
291
|
+
delete replacement[idName];
|
|
292
|
+
delete replacement._id;
|
|
293
|
+
const dbDoc = (0, property_mapping_1.toDatabase)(modelDef, replacement);
|
|
294
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
295
|
+
const idFilter = { _id: coercedId };
|
|
296
|
+
const result = await collection.replaceOne(idFilter, dbDoc, sessionOpts);
|
|
297
|
+
return { count: result.modifiedCount };
|
|
298
|
+
}
|
|
299
|
+
async updateOrCreate(modelName, data, options) {
|
|
300
|
+
const collection = await this.getCollection(modelName);
|
|
301
|
+
const modelDef = this._models[modelName];
|
|
302
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
303
|
+
const id = data[idName];
|
|
304
|
+
if (id === null || id === undefined) {
|
|
305
|
+
const insertedId = await this.create(modelName, data, options);
|
|
306
|
+
return { ...data, [idName]: insertedId };
|
|
307
|
+
}
|
|
308
|
+
const coercedId = (0, coercion_1.coerceId)(id, modelDef?.properties[idName], this.settings.strictObjectIDCoercion);
|
|
309
|
+
const replacement = { ...data };
|
|
310
|
+
delete replacement[idName];
|
|
311
|
+
delete replacement._id;
|
|
312
|
+
const dbDoc = (0, property_mapping_1.toDatabase)(modelDef, replacement);
|
|
313
|
+
const sessionOpts = this.extractSessionOptions(options);
|
|
314
|
+
const idFilter = { _id: coercedId };
|
|
315
|
+
const result = await collection.findOneAndReplace(idFilter, dbDoc, {
|
|
316
|
+
upsert: true,
|
|
317
|
+
returnDocument: 'after',
|
|
318
|
+
...sessionOpts,
|
|
319
|
+
});
|
|
320
|
+
return result ? this.fromDb(modelName, result) : data;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Find a document matching `filter` or create it from `data`.
|
|
324
|
+
*
|
|
325
|
+
* @experimental
|
|
326
|
+
*
|
|
327
|
+
* KNOWN LIMITATION: on a duplicate-key conflict (error 11000), the
|
|
328
|
+
* follow-up lookup re-uses the caller's `filter`. If the conflicting
|
|
329
|
+
* unique index covers a field NOT in `filter`, the returned document
|
|
330
|
+
* may be unrelated to the duplicate. Use `upsert` via
|
|
331
|
+
* `updateOrCreate()` or the connector's raw `replaceOne` for stricter
|
|
332
|
+
* semantics until this is addressed in a future release.
|
|
333
|
+
*/
|
|
334
|
+
async findOrCreate(modelName, filter, data, options) {
|
|
335
|
+
try {
|
|
336
|
+
const id = await this.create(modelName, data, options);
|
|
337
|
+
const modelDef = this._models[modelName];
|
|
338
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
339
|
+
return [{ ...data, [idName]: id }, true];
|
|
340
|
+
}
|
|
341
|
+
catch (err) {
|
|
342
|
+
if (err.code === 11000) {
|
|
343
|
+
const existing = await this.all(modelName, filter, options);
|
|
344
|
+
if (existing.length > 0) {
|
|
345
|
+
return [existing[0], false];
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
throw err;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async exists(modelName, id, options) {
|
|
352
|
+
const result = await this.find(modelName, id, options);
|
|
353
|
+
return result !== null;
|
|
354
|
+
}
|
|
355
|
+
// ---- Juggler-compatible aliases ----
|
|
356
|
+
// The juggler DataAccessObject expects specific method names
|
|
357
|
+
// that differ from our public API.
|
|
358
|
+
/**
|
|
359
|
+
* Juggler alias for updateAll.
|
|
360
|
+
*/
|
|
361
|
+
async update(modelName, where, data, options) {
|
|
362
|
+
return this.updateAll(modelName, where, data, options);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Juggler alias for deleteAll.
|
|
366
|
+
*/
|
|
367
|
+
async destroyAll(modelName, where, options) {
|
|
368
|
+
return this.deleteAll(modelName, where, options);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Juggler: update specific attributes on a single document by id.
|
|
372
|
+
*/
|
|
373
|
+
async updateAttributes(modelName, id, data, options) {
|
|
374
|
+
const modelDef = this._models[modelName];
|
|
375
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
376
|
+
await this.updateAll(modelName, { [idName]: id }, data, options);
|
|
377
|
+
const updated = await this.find(modelName, id, options);
|
|
378
|
+
if (!updated) {
|
|
379
|
+
throw new errors_1.MongoConnectorError(`Document not found after updateAttributes: ${modelName}/${String(id)}`);
|
|
380
|
+
}
|
|
381
|
+
return updated;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Juggler: save (upsert) a document.
|
|
385
|
+
*/
|
|
386
|
+
async save(modelName, data, options) {
|
|
387
|
+
return this.updateOrCreate(modelName, data, options);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Raw-driver escape hatch. Calls the named MongoDB Collection method
|
|
391
|
+
* directly with the provided args.
|
|
392
|
+
*
|
|
393
|
+
* The `SAFE_COMMANDS` allowlist controls which methods may be called;
|
|
394
|
+
* argument shape is NOT validated. Malformed args can cause data
|
|
395
|
+
* loss (e.g. an empty filter on `deleteMany`). Prefer the typed
|
|
396
|
+
* helpers on `MongoService` or the connector's CRUD methods.
|
|
397
|
+
*
|
|
398
|
+
* @experimental
|
|
399
|
+
* @throws MongoConnectorError if the command is not in the allowlist
|
|
400
|
+
* or is not a function on the Collection.
|
|
401
|
+
*/
|
|
402
|
+
async execute(modelName, command, ...args) {
|
|
403
|
+
if (!MongoConnector.SAFE_COMMANDS.has(command)) {
|
|
404
|
+
throw new errors_1.MongoConnectorError(`Command "${command}" is not in the allowlist. ` +
|
|
405
|
+
'Use getClient() for unrestricted access.');
|
|
406
|
+
}
|
|
407
|
+
const collection = await this.getCollection(modelName);
|
|
408
|
+
const method = collection[command];
|
|
409
|
+
if (typeof method !== 'function') {
|
|
410
|
+
throw new errors_1.MongoConnectorError(`Unknown MongoDB collection command: ${command}`);
|
|
411
|
+
}
|
|
412
|
+
debug('execute [%s].%s', modelName, command);
|
|
413
|
+
return method.apply(collection, args);
|
|
414
|
+
}
|
|
415
|
+
// ---- Transactions ----
|
|
416
|
+
/**
|
|
417
|
+
* Begin a MongoDB transaction and return the underlying session.
|
|
418
|
+
*
|
|
419
|
+
* NOTE: this method does NOT auto-retry on `TransientTransactionError`
|
|
420
|
+
* or `UnknownTransactionCommitResult`. The juggler shape mandates
|
|
421
|
+
* separate begin/commit/rollback. For new code, prefer
|
|
422
|
+
* `MongoService.withTransaction()`, which wraps the retry loop
|
|
423
|
+
* automatically.
|
|
424
|
+
*/
|
|
425
|
+
async beginTransaction(options) {
|
|
426
|
+
if (!this.connectionManager.isConnected()) {
|
|
427
|
+
await this.connectionManager.connect();
|
|
428
|
+
}
|
|
429
|
+
const client = this.connectionManager.getClient();
|
|
430
|
+
const session = client.startSession();
|
|
431
|
+
session.startTransaction(options);
|
|
432
|
+
debug('transaction started');
|
|
433
|
+
return session;
|
|
434
|
+
}
|
|
435
|
+
async commit(session) {
|
|
436
|
+
try {
|
|
437
|
+
await session.commitTransaction();
|
|
438
|
+
}
|
|
439
|
+
finally {
|
|
440
|
+
try {
|
|
441
|
+
await session.endSession();
|
|
442
|
+
}
|
|
443
|
+
catch (cleanupErr) {
|
|
444
|
+
debug('endSession after commit failed: %O', cleanupErr);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
debug('transaction committed');
|
|
448
|
+
}
|
|
449
|
+
async rollback(session) {
|
|
450
|
+
try {
|
|
451
|
+
await session.abortTransaction();
|
|
452
|
+
}
|
|
453
|
+
finally {
|
|
454
|
+
try {
|
|
455
|
+
await session.endSession();
|
|
456
|
+
}
|
|
457
|
+
catch (cleanupErr) {
|
|
458
|
+
debug('endSession after rollback failed: %O', cleanupErr);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
debug('transaction rolled back');
|
|
462
|
+
}
|
|
463
|
+
// ---- Internal helpers ----
|
|
464
|
+
collectionForModel(modelName) {
|
|
465
|
+
// Routes to the connector's configured database. For shared-
|
|
466
|
+
// manager use, this lets multiple MongoDataSource instances
|
|
467
|
+
// target different databases on one MongoClient pool.
|
|
468
|
+
const db = this.connectionManager.getDb(this.settings.database);
|
|
469
|
+
const modelDef = this._models[modelName];
|
|
470
|
+
const mongoSettings = modelDef?.settings?.mongodb;
|
|
471
|
+
const collectionName = mongoSettings?.collection ?? mongoSettings?.table ?? modelName;
|
|
472
|
+
return db.collection(collectionName);
|
|
473
|
+
}
|
|
474
|
+
async getCollection(modelName) {
|
|
475
|
+
if (!this.connectionManager.isConnected()) {
|
|
476
|
+
await this.connectionManager.connect();
|
|
477
|
+
}
|
|
478
|
+
return this.collectionForModel(modelName);
|
|
479
|
+
}
|
|
480
|
+
buildUpdate(modelName, data) {
|
|
481
|
+
const modelDef = this._models[modelName];
|
|
482
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
483
|
+
const setData = { ...data };
|
|
484
|
+
delete setData[idName];
|
|
485
|
+
delete setData._id;
|
|
486
|
+
const dbData = (0, property_mapping_1.toDatabase)(modelDef, setData);
|
|
487
|
+
if (this.settings.allowExtendedOperators) {
|
|
488
|
+
const hasOperators = Object.keys(dbData).some(k => k.startsWith('$'));
|
|
489
|
+
if (hasOperators)
|
|
490
|
+
return dbData;
|
|
491
|
+
}
|
|
492
|
+
return { $set: dbData };
|
|
493
|
+
}
|
|
494
|
+
fromDb(modelName, doc) {
|
|
495
|
+
const modelDef = this._models[modelName];
|
|
496
|
+
const idName = (0, property_mapping_1.getIdPropertyName)(modelDef);
|
|
497
|
+
const data = (0, property_mapping_1.fromDatabase)(modelDef, doc);
|
|
498
|
+
if (data._id !== undefined && idName !== '_id') {
|
|
499
|
+
data[idName] = data._id;
|
|
500
|
+
delete data._id;
|
|
501
|
+
}
|
|
502
|
+
return data;
|
|
503
|
+
}
|
|
504
|
+
extractSessionOptions(options) {
|
|
505
|
+
if (!options?.transaction)
|
|
506
|
+
return {};
|
|
507
|
+
return { session: options.transaction };
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
exports.MongoConnector = MongoConnector;
|
|
511
|
+
// ---- Direct execution ----
|
|
512
|
+
MongoConnector.SAFE_COMMANDS = new Set([
|
|
513
|
+
'find',
|
|
514
|
+
'findOne',
|
|
515
|
+
'insertOne',
|
|
516
|
+
'insertMany',
|
|
517
|
+
'updateOne',
|
|
518
|
+
'updateMany',
|
|
519
|
+
'replaceOne',
|
|
520
|
+
'deleteOne',
|
|
521
|
+
'deleteMany',
|
|
522
|
+
'aggregate',
|
|
523
|
+
'countDocuments',
|
|
524
|
+
'estimatedDocumentCount',
|
|
525
|
+
'distinct',
|
|
526
|
+
'findOneAndUpdate',
|
|
527
|
+
'findOneAndReplace',
|
|
528
|
+
'findOneAndDelete',
|
|
529
|
+
'bulkWrite',
|
|
530
|
+
'createIndex',
|
|
531
|
+
'createIndexes',
|
|
532
|
+
'dropIndex',
|
|
533
|
+
'dropIndexes',
|
|
534
|
+
'listIndexes',
|
|
535
|
+
'indexExists',
|
|
536
|
+
'indexes',
|
|
537
|
+
'watch',
|
|
538
|
+
'isCapped',
|
|
539
|
+
'stats',
|
|
540
|
+
]);
|
|
541
|
+
/**
|
|
542
|
+
* Initialize function for loopback-datasource-juggler.
|
|
543
|
+
* Creates a standalone connector with its own connection manager.
|
|
544
|
+
*
|
|
545
|
+
* Juggler invokes this with `(dataSource, callback)` and expects
|
|
546
|
+
* the callback to signal "setup done." This is the one place the
|
|
547
|
+
* connector still exposes a callback contract.
|
|
548
|
+
*
|
|
549
|
+
* @public
|
|
550
|
+
*/
|
|
551
|
+
function initialize(dataSource, callback) {
|
|
552
|
+
const settings = dataSource.settings ?? {};
|
|
553
|
+
(0, config_validator_1.validateConfig)(settings);
|
|
554
|
+
const connector = new MongoConnector(settings);
|
|
555
|
+
connector.dataSource = dataSource;
|
|
556
|
+
dataSource.connector = connector;
|
|
557
|
+
dataSource.ObjectID = mongodb_1.ObjectId;
|
|
558
|
+
if (callback) {
|
|
559
|
+
if (settings.lazyConnect) {
|
|
560
|
+
process.nextTick(() => callback(null));
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
connector.connect().then(() => callback(null), (err) => callback(err));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
//# sourceMappingURL=mongo.connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongo.connector.js","sourceRoot":"","sources":["../../src/connector/mongo.connector.ts"],"names":[],"mappings":";;;;;;AAivBA,gCAqBC;AA9vBD,qCAAiC;AACjC,kDAAiC;AAEjC,yCAAoC;AACpC,mDAAmE;AAEnE,yDAA+E;AAC/E,sEAAqE;AACrE,kEAA2D;AAC3D,qCAA6C;AAErC,oGAFA,4BAAmB,OAEA;AAE3B,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,4BAA4B,CAAC,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,uBAAuB,GAAG;IAC9B,QAAQ;IACR,MAAM;IACN,KAAK;IACL,WAAW;IACX,WAAW;IACX,OAAO;IACP,aAAa;IACb,gBAAgB;IAChB,cAAc;IACd,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,kBAAkB;IAClB,MAAM;CACE,CAAC;AAEX;;;;;;;;;;;;GAYG;AACH,MAAa,cAAc;IASzB;;;;;;;OAOG;IACH,YACE,QAA8B,EAC9B,iBAA0C;QAlB5C,SAAI,GAAG,SAAS,CAAC;QAMT,YAAO,GAAoC,EAAE,CAAC;QAcpD,IAAI,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EAAC,QAAQ,CAAC,CAAC;IACzB,MAAM,SAAS,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC/C,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;IAClC,UAAU,CAAC,SAAS,GAAG,SAAS,CAAC;IAChC,UAAsC,CAAC,QAAQ,GAAG,kBAAQ,CAAC;IAE5D,IAAI,QAAQ,EAAE,CAAC;QACb,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;YACzB,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,OAAO,EAAE,CAAC,IAAI,CACtB,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EACpB,CAAC,GAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAC9B,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Property and model mapping helpers for the MongoDB connector.
|
|
3
|
+
*
|
|
4
|
+
* Decimal128 values returned through this connector pass through
|
|
5
|
+
* `parseFloat` and may lose precision outside JS Number range. A
|
|
6
|
+
* `decimalAsString` mode is planned.
|
|
7
|
+
*/
|
|
8
|
+
import type { Document } from 'mongodb';
|
|
9
|
+
/**
|
|
10
|
+
* Model property definition as stored by the juggler connector.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export interface PropertyDefinition {
|
|
15
|
+
type?: unknown;
|
|
16
|
+
mongodb?: {
|
|
17
|
+
fieldName?: string;
|
|
18
|
+
dataType?: string;
|
|
19
|
+
};
|
|
20
|
+
id?: boolean | number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Model definition as stored by the juggler connector.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export interface ModelDefinition {
|
|
28
|
+
model: {
|
|
29
|
+
modelName: string;
|
|
30
|
+
};
|
|
31
|
+
properties: Record<string, PropertyDefinition>;
|
|
32
|
+
settings?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Convert a model instance to its database representation.
|
|
36
|
+
* Handles:
|
|
37
|
+
* - Custom field name mappings (property.mongodb.fieldName)
|
|
38
|
+
* - GeoPoint to GeoJSON conversion
|
|
39
|
+
* - Decimal128 coercion
|
|
40
|
+
*
|
|
41
|
+
* @param modelDef - The model definition
|
|
42
|
+
* @param data - The data to convert
|
|
43
|
+
*/
|
|
44
|
+
export declare function toDatabase(modelDef: ModelDefinition | undefined, data: Record<string, unknown>): Document;
|
|
45
|
+
/**
|
|
46
|
+
* Convert a database document to a model instance.
|
|
47
|
+
* Handles:
|
|
48
|
+
* - Custom field name mappings (reverse)
|
|
49
|
+
* - Binary to Buffer conversion
|
|
50
|
+
* - Decimal128 to number conversion
|
|
51
|
+
* - ObjectId to string conversion for non-ObjectId properties
|
|
52
|
+
*
|
|
53
|
+
* @param modelDef - The model definition
|
|
54
|
+
* @param data - The database document
|
|
55
|
+
*/
|
|
56
|
+
export declare function fromDatabase(modelDef: ModelDefinition | undefined, data: Document): Record<string, unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* Get the database column name for a model property.
|
|
59
|
+
*/
|
|
60
|
+
export declare function getDatabaseColumnName(modelDef: ModelDefinition | undefined, propertyName: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get the ID property name for a model.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getIdPropertyName(modelDef: ModelDefinition | undefined): string;
|