@resolveio/server-lib 9.0.25 → 9.0.26
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.
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { ChangeStreamOptions, ClientSession, CollectionAggregationOptions, CollectionInsertManyOptions, CollectionInsertOneOptions, CommonOptions, FilterQuery, FindOneAndDeleteOption, FindOneAndReplaceOption, FindOneAndUpdateOption, FindOneOptions, IndexOptions, IndexSpecification, MongoCountPreferences, MongoDistinctPreferences, ReadPreferenceOrMode, ReplaceOneOptions, UpdateManyOptions, UpdateOneOptions, UpdateQuery } from 'mongodb';
|
|
2
2
|
import { LookupTables } from '../models/report-builder.model';
|
|
3
3
|
import { UserModel } from '../models/user.model';
|
|
4
|
+
interface MongoQueueModel {
|
|
5
|
+
_id: number;
|
|
6
|
+
name_collection: string;
|
|
7
|
+
name_function: string;
|
|
8
|
+
data_function: any[];
|
|
9
|
+
name_function_addt: string;
|
|
10
|
+
data_function_addt: any[];
|
|
11
|
+
cbs: Function[];
|
|
12
|
+
cbs_next: Function[];
|
|
13
|
+
running: boolean;
|
|
14
|
+
}
|
|
4
15
|
export declare class MongoManager {
|
|
5
16
|
private _server;
|
|
6
17
|
private _collections;
|
|
18
|
+
private _mongoQueue;
|
|
19
|
+
private _mongoQueueId;
|
|
7
20
|
constructor(mainServer: any);
|
|
8
21
|
registerCollection(collection: Collection<any>): void;
|
|
9
22
|
collections(): Collection<any>[];
|
|
10
23
|
collection(collectionName: string): Collection<any> | UserCollection<any>;
|
|
24
|
+
addToQueue(mongoQueue: MongoQueueModel): void;
|
|
25
|
+
private runQueue;
|
|
11
26
|
}
|
|
12
27
|
export declare class Model<T> {
|
|
13
28
|
collection_main: Collection<T> | UserCollection<T>;
|
|
@@ -34,10 +49,10 @@ export declare class Collection<T> {
|
|
|
34
49
|
createIndexes(indexSpecs: IndexSpecification[], options?: {
|
|
35
50
|
session?: ClientSession;
|
|
36
51
|
}): Promise<any>;
|
|
37
|
-
deleteMany(filter?: FilterQuery<T>, options?: CommonOptions): Promise<
|
|
52
|
+
deleteMany(filter?: FilterQuery<T>, options?: CommonOptions): Promise<unknown>;
|
|
38
53
|
deleteOne(filter?: FilterQuery<T>, options?: CommonOptions & {
|
|
39
54
|
bypassDocumentValidation?: boolean;
|
|
40
|
-
}): Promise<
|
|
55
|
+
}): Promise<unknown>;
|
|
41
56
|
distinct(key: string, filter?: FilterQuery<T>, options?: MongoDistinctPreferences): Promise<T[]>;
|
|
42
57
|
drop(options?: {
|
|
43
58
|
session: ClientSession;
|
|
@@ -78,13 +93,13 @@ export declare class Collection<T> {
|
|
|
78
93
|
dropTarget?: boolean;
|
|
79
94
|
session?: ClientSession;
|
|
80
95
|
}): Promise<import("mongodb").Collection<any>>;
|
|
81
|
-
replaceOne(filter: FilterQuery<T>, replacement: T, options?: ReplaceOneOptions): Promise<
|
|
96
|
+
replaceOne(filter: FilterQuery<T>, replacement: T, options?: ReplaceOneOptions): Promise<number>;
|
|
82
97
|
stats(options?: {
|
|
83
98
|
scale: number;
|
|
84
99
|
session?: ClientSession;
|
|
85
100
|
}): Promise<import("mongodb").CollStats>;
|
|
86
|
-
updateMany(filter: FilterQuery<T>, update: UpdateQuery<T> | Partial<T>, options?: UpdateManyOptions): Promise<
|
|
87
|
-
updateOne(filter: FilterQuery<T>, update: UpdateQuery<T> | Partial<T>, options?: UpdateOneOptions): Promise<
|
|
101
|
+
updateMany(filter: FilterQuery<T>, update: UpdateQuery<T> | Partial<T>, options?: UpdateManyOptions): Promise<number>;
|
|
102
|
+
updateOne(filter: FilterQuery<T>, update: UpdateQuery<T> | Partial<T>, options?: UpdateOneOptions): Promise<number>;
|
|
88
103
|
watchCollection(options?: ChangeStreamOptions & {
|
|
89
104
|
session?: ClientSession;
|
|
90
105
|
}): import("mongodb").ChangeStream<any>;
|
|
@@ -103,6 +118,7 @@ export declare class UserCollection<T> extends Collection<T> {
|
|
|
103
118
|
setPassword(user: UserModel, password: string): Promise<unknown>;
|
|
104
119
|
changePassword(user: any, oldPassword: any, newPassword: any): Promise<unknown>;
|
|
105
120
|
register(user: any, password: any): Promise<unknown>;
|
|
106
|
-
resetAttempts(user: UserModel): Promise<
|
|
121
|
+
resetAttempts(user: UserModel): Promise<number>;
|
|
107
122
|
}
|
|
108
123
|
export declare function objectIdHexString(): string;
|
|
124
|
+
export {};
|
|
@@ -61,7 +61,10 @@ var scmp = require('scmp');
|
|
|
61
61
|
var MongoManager = /** @class */ (function () {
|
|
62
62
|
function MongoManager(mainServer) {
|
|
63
63
|
this._collections = [];
|
|
64
|
+
this._mongoQueue = [];
|
|
65
|
+
this._mongoQueueId = 0;
|
|
64
66
|
this._server = mainServer;
|
|
67
|
+
this.runQueue();
|
|
65
68
|
}
|
|
66
69
|
MongoManager.prototype.registerCollection = function (collection) {
|
|
67
70
|
this._collections.push(collection);
|
|
@@ -72,6 +75,85 @@ var MongoManager = /** @class */ (function () {
|
|
|
72
75
|
MongoManager.prototype.collection = function (collectionName) {
|
|
73
76
|
return this._collections.filter(function (a) { return a.collectionName === collectionName; })[0];
|
|
74
77
|
};
|
|
78
|
+
MongoManager.prototype.addToQueue = function (mongoQueue) {
|
|
79
|
+
var _mongoQueue = this._mongoQueue.filter(function (a) { return a.name_collection === mongoQueue.name_collection && a.name_function === mongoQueue.name_function && a.name_function_addt === mongoQueue.name_function_addt && JSON.stringify(a.data_function) === JSON.stringify(mongoQueue.data_function) && JSON.stringify(a.data_function_addt) === JSON.stringify(mongoQueue.data_function_addt); })[0];
|
|
80
|
+
if (_mongoQueue) {
|
|
81
|
+
if (!_mongoQueue.running) {
|
|
82
|
+
_mongoQueue.cbs.push(mongoQueue.cbs[0]);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
_mongoQueue.cbs_next.push(mongoQueue.cbs[0]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
mongoQueue._id = this._mongoQueueId;
|
|
90
|
+
this._mongoQueueId += 1;
|
|
91
|
+
this._mongoQueue.push(mongoQueue);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
MongoManager.prototype.runQueue = function () {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
96
|
+
var mongoQueue_1;
|
|
97
|
+
var _a, _b, _c;
|
|
98
|
+
var _this = this;
|
|
99
|
+
return __generator(this, function (_d) {
|
|
100
|
+
if (this._mongoQueue.filter(function (a) { return !a.running; }).length) {
|
|
101
|
+
mongoQueue_1 = this._mongoQueue.filter(function (a) { return !a.running; })[0];
|
|
102
|
+
mongoQueue_1.running = true;
|
|
103
|
+
if (!mongoQueue_1.name_function_addt) {
|
|
104
|
+
(_a = index_1.ResolveIOServer.getMainDB().collection(mongoQueue_1.name_collection))[mongoQueue_1.name_function].apply(_a, mongoQueue_1.data_function).then(function (res) {
|
|
105
|
+
mongoQueue_1.cbs.forEach(function (cb) {
|
|
106
|
+
cb(null, res);
|
|
107
|
+
});
|
|
108
|
+
if (mongoQueue_1.cbs_next.length) {
|
|
109
|
+
mongoQueue_1.running = false;
|
|
110
|
+
mongoQueue_1.cbs = mongoQueue_1.cbs_next;
|
|
111
|
+
mongoQueue_1.cbs_next = [];
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
115
|
+
}
|
|
116
|
+
}, function (err) {
|
|
117
|
+
mongoQueue_1.cbs.forEach(function (cb) {
|
|
118
|
+
cb(err, null);
|
|
119
|
+
});
|
|
120
|
+
mongoQueue_1.cbs_next.forEach(function (cb) {
|
|
121
|
+
cb(err, null);
|
|
122
|
+
});
|
|
123
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
(_b = (_c = index_1.ResolveIOServer.getMainDB().collection(mongoQueue_1.name_collection))[mongoQueue_1.name_function].apply(_c, mongoQueue_1.data_function))[mongoQueue_1.name_function_addt].apply(_b, mongoQueue_1.data_function_addt).then(function (res) {
|
|
128
|
+
mongoQueue_1.cbs.forEach(function (cb) {
|
|
129
|
+
cb(null, res);
|
|
130
|
+
});
|
|
131
|
+
if (mongoQueue_1.cbs_next.length) {
|
|
132
|
+
mongoQueue_1.running = false;
|
|
133
|
+
mongoQueue_1.cbs = mongoQueue_1.cbs_next;
|
|
134
|
+
mongoQueue_1.cbs_next = []; // BUG???
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
138
|
+
}
|
|
139
|
+
}, function (err) {
|
|
140
|
+
mongoQueue_1.cbs.forEach(function (cb) {
|
|
141
|
+
cb(err, null);
|
|
142
|
+
});
|
|
143
|
+
mongoQueue_1.cbs_next.forEach(function (cb) {
|
|
144
|
+
cb(err, null);
|
|
145
|
+
});
|
|
146
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
setTimeout(function () {
|
|
151
|
+
_this.runQueue();
|
|
152
|
+
}, 0);
|
|
153
|
+
return [2 /*return*/];
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
};
|
|
75
157
|
return MongoManager;
|
|
76
158
|
}());
|
|
77
159
|
exports.MongoManager = MongoManager;
|
|
@@ -136,10 +218,50 @@ var Collection = /** @class */ (function () {
|
|
|
136
218
|
}, 0);
|
|
137
219
|
}
|
|
138
220
|
Collection.prototype.aggregate = function (pipeline, options) {
|
|
139
|
-
|
|
221
|
+
var _this = this;
|
|
222
|
+
return new Promise(function (resolve, reject) {
|
|
223
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().addToQueue({
|
|
224
|
+
_id: 0,
|
|
225
|
+
name_collection: _this.collectionName,
|
|
226
|
+
name_function: 'aggregate',
|
|
227
|
+
name_function_addt: 'toArray',
|
|
228
|
+
data_function: [pipeline, options],
|
|
229
|
+
data_function_addt: [],
|
|
230
|
+
cbs: [function (err, res) {
|
|
231
|
+
if (err) {
|
|
232
|
+
reject(err);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
resolve(res);
|
|
236
|
+
}
|
|
237
|
+
}],
|
|
238
|
+
cbs_next: [],
|
|
239
|
+
running: false
|
|
240
|
+
});
|
|
241
|
+
});
|
|
140
242
|
};
|
|
141
243
|
Collection.prototype.aggregateCount = function (pipeline, options) {
|
|
142
|
-
|
|
244
|
+
var _this = this;
|
|
245
|
+
return new Promise(function (resolve, reject) {
|
|
246
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().addToQueue({
|
|
247
|
+
_id: 0,
|
|
248
|
+
name_collection: _this.collectionName,
|
|
249
|
+
name_function: 'aggregate',
|
|
250
|
+
name_function_addt: 'count',
|
|
251
|
+
data_function: [pipeline, options],
|
|
252
|
+
data_function_addt: [],
|
|
253
|
+
cbs: [function (err, res) {
|
|
254
|
+
if (err) {
|
|
255
|
+
reject(err);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
resolve(res);
|
|
259
|
+
}
|
|
260
|
+
}],
|
|
261
|
+
cbs_next: [],
|
|
262
|
+
running: false
|
|
263
|
+
});
|
|
264
|
+
});
|
|
143
265
|
};
|
|
144
266
|
Collection.prototype.aggregateCursor = function (pipeline, options) {
|
|
145
267
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).aggregate(pipeline, options);
|
|
@@ -165,8 +287,9 @@ var Collection = /** @class */ (function () {
|
|
|
165
287
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).createIndexes(indexSpecs, options);
|
|
166
288
|
};
|
|
167
289
|
Collection.prototype.deleteMany = function (filter, options) {
|
|
290
|
+
var _this = this;
|
|
168
291
|
if (filter === void 0) { filter = {}; }
|
|
169
|
-
return __awaiter(
|
|
292
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
170
293
|
var docs;
|
|
171
294
|
var _this = this;
|
|
172
295
|
return __generator(this, function (_a) {
|
|
@@ -191,14 +314,24 @@ var Collection = /** @class */ (function () {
|
|
|
191
314
|
});
|
|
192
315
|
});
|
|
193
316
|
_a.label = 2;
|
|
194
|
-
case 2:
|
|
317
|
+
case 2:
|
|
318
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteMany(filter, options).then(function (res) {
|
|
319
|
+
if (res.result.ok) {
|
|
320
|
+
resolve(res.deletedCount);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
reject(res.result.ok);
|
|
324
|
+
}
|
|
325
|
+
}, function (err) { return reject(err); });
|
|
326
|
+
return [2 /*return*/];
|
|
195
327
|
}
|
|
196
328
|
});
|
|
197
|
-
});
|
|
329
|
+
}); });
|
|
198
330
|
};
|
|
199
331
|
Collection.prototype.deleteOne = function (filter, options) {
|
|
332
|
+
var _this = this;
|
|
200
333
|
if (filter === void 0) { filter = {}; }
|
|
201
|
-
return __awaiter(
|
|
334
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
202
335
|
var doc;
|
|
203
336
|
return __generator(this, function (_a) {
|
|
204
337
|
switch (_a.label) {
|
|
@@ -222,10 +355,19 @@ var Collection = /** @class */ (function () {
|
|
|
222
355
|
});
|
|
223
356
|
}
|
|
224
357
|
_a.label = 2;
|
|
225
|
-
case 2:
|
|
358
|
+
case 2:
|
|
359
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filter, options).then(function (res) {
|
|
360
|
+
if (res.result.ok) {
|
|
361
|
+
resolve(res.deletedCount);
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
reject(res.result.ok);
|
|
365
|
+
}
|
|
366
|
+
}, function (err) { return reject(err); });
|
|
367
|
+
return [2 /*return*/];
|
|
226
368
|
}
|
|
227
369
|
});
|
|
228
|
-
});
|
|
370
|
+
}); });
|
|
229
371
|
};
|
|
230
372
|
Collection.prototype.distinct = function (key, filter, options) {
|
|
231
373
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).distinct(key, filter, options);
|
|
@@ -240,38 +382,44 @@ var Collection = /** @class */ (function () {
|
|
|
240
382
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).dropIndexes(options);
|
|
241
383
|
};
|
|
242
384
|
Collection.prototype.find = function (filter, options) {
|
|
385
|
+
var _this = this;
|
|
243
386
|
if (filter === void 0) { filter = {}; }
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
387
|
+
return new Promise(function (resolve, reject) {
|
|
388
|
+
if (_this.createLogs) {
|
|
389
|
+
log_collection_1.Logs.create({
|
|
390
|
+
_id: objectIdHexString(),
|
|
391
|
+
type: 'query',
|
|
392
|
+
collection: _this.collectionName,
|
|
393
|
+
id_document: '',
|
|
394
|
+
payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
|
|
395
|
+
method: 'find',
|
|
396
|
+
id_user: '',
|
|
397
|
+
user: '',
|
|
398
|
+
messageId: '',
|
|
399
|
+
route: ''
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().addToQueue({
|
|
403
|
+
_id: 0,
|
|
404
|
+
name_collection: _this.collectionName,
|
|
405
|
+
name_function: 'find',
|
|
406
|
+
name_function_addt: 'toArray',
|
|
407
|
+
data_function: [filter, options],
|
|
408
|
+
data_function_addt: [],
|
|
409
|
+
cbs: [function (err, res) {
|
|
410
|
+
if (err) {
|
|
411
|
+
reject(err);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
resolve(res);
|
|
415
|
+
}
|
|
416
|
+
}],
|
|
417
|
+
cbs_next: [],
|
|
418
|
+
running: false
|
|
256
419
|
});
|
|
257
|
-
}
|
|
258
|
-
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).toArray();
|
|
420
|
+
});
|
|
259
421
|
};
|
|
260
422
|
Collection.prototype.findById = function (id, options) {
|
|
261
|
-
if (this.createLogs) {
|
|
262
|
-
log_collection_1.Logs.create({
|
|
263
|
-
_id: objectIdHexString(),
|
|
264
|
-
type: 'query',
|
|
265
|
-
collection: this.collectionName,
|
|
266
|
-
id_document: id,
|
|
267
|
-
payload: common_1.getBinarySize(JSON.stringify([id, options])) < 200000 ? JSON.stringify([id, options], null, 2) : 'Too Big',
|
|
268
|
-
method: 'findById',
|
|
269
|
-
id_user: '',
|
|
270
|
-
user: '',
|
|
271
|
-
messageId: '',
|
|
272
|
-
route: ''
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
423
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOne({ _id: id }, options);
|
|
276
424
|
};
|
|
277
425
|
Collection.prototype.findCount = function (filter, options) {
|
|
@@ -301,28 +449,48 @@ var Collection = /** @class */ (function () {
|
|
|
301
449
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).stream(streamOptions);
|
|
302
450
|
};
|
|
303
451
|
Collection.prototype.findOne = function (filter, options) {
|
|
452
|
+
var _this = this;
|
|
304
453
|
if (filter === void 0) { filter = {}; }
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
454
|
+
return new Promise(function (resolve, reject) {
|
|
455
|
+
if (_this.createLogs) {
|
|
456
|
+
log_collection_1.Logs.create({
|
|
457
|
+
_id: objectIdHexString(),
|
|
458
|
+
type: 'query',
|
|
459
|
+
collection: _this.collectionName,
|
|
460
|
+
id_document: '',
|
|
461
|
+
payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
|
|
462
|
+
method: 'findOne',
|
|
463
|
+
id_user: '',
|
|
464
|
+
user: '',
|
|
465
|
+
messageId: '',
|
|
466
|
+
route: ''
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().addToQueue({
|
|
470
|
+
_id: 0,
|
|
471
|
+
name_collection: _this.collectionName,
|
|
472
|
+
name_function: 'findOne',
|
|
473
|
+
name_function_addt: '',
|
|
474
|
+
data_function: [filter, options],
|
|
475
|
+
data_function_addt: [],
|
|
476
|
+
cbs: [function (err, res) {
|
|
477
|
+
if (err) {
|
|
478
|
+
reject(err);
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
resolve(res);
|
|
482
|
+
}
|
|
483
|
+
}],
|
|
484
|
+
cbs_next: [],
|
|
485
|
+
running: false
|
|
317
486
|
});
|
|
318
|
-
}
|
|
319
|
-
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOne(filter, options);
|
|
487
|
+
});
|
|
320
488
|
};
|
|
321
489
|
Collection.prototype.findOneAndDelete = function (filter, options) {
|
|
490
|
+
var _this = this;
|
|
322
491
|
if (filter === void 0) { filter = {}; }
|
|
323
|
-
return __awaiter(
|
|
492
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
324
493
|
var doc;
|
|
325
|
-
var _this = this;
|
|
326
494
|
return __generator(this, function (_a) {
|
|
327
495
|
switch (_a.label) {
|
|
328
496
|
case 0:
|
|
@@ -345,16 +513,19 @@ var Collection = /** @class */ (function () {
|
|
|
345
513
|
});
|
|
346
514
|
}
|
|
347
515
|
_a.label = 2;
|
|
348
|
-
case 2:
|
|
349
|
-
|
|
516
|
+
case 2:
|
|
517
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndDelete(filter, options).then(function (res) {
|
|
518
|
+
if (res.ok) {
|
|
350
519
|
resolve(res.value);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
520
|
+
}
|
|
521
|
+
else {
|
|
522
|
+
reject(res.lastErrorObject);
|
|
523
|
+
}
|
|
524
|
+
}, function (err) { return reject(err); });
|
|
525
|
+
return [2 /*return*/];
|
|
355
526
|
}
|
|
356
527
|
});
|
|
357
|
-
});
|
|
528
|
+
}); });
|
|
358
529
|
};
|
|
359
530
|
Collection.prototype.findOneAndReplace = function (filter, replacement, options) {
|
|
360
531
|
var _this = this;
|
|
@@ -386,10 +557,13 @@ var Collection = /** @class */ (function () {
|
|
|
386
557
|
_a.label = 2;
|
|
387
558
|
case 2:
|
|
388
559
|
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(function (res) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
560
|
+
if (res.ok) {
|
|
561
|
+
resolve(res.value);
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
reject(res.lastErrorObject);
|
|
565
|
+
}
|
|
566
|
+
}, function (err) { return reject(err); });
|
|
393
567
|
return [2 /*return*/];
|
|
394
568
|
}
|
|
395
569
|
});
|
|
@@ -430,10 +604,13 @@ var Collection = /** @class */ (function () {
|
|
|
430
604
|
_a.label = 2;
|
|
431
605
|
case 2:
|
|
432
606
|
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(function (res) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
607
|
+
if (res.ok) {
|
|
608
|
+
resolve(res.value);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
reject(res.lastErrorObject);
|
|
612
|
+
}
|
|
613
|
+
}, function (err) { return reject(err); });
|
|
437
614
|
return [2 /*return*/];
|
|
438
615
|
}
|
|
439
616
|
});
|
|
@@ -525,7 +702,8 @@ var Collection = /** @class */ (function () {
|
|
|
525
702
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
|
|
526
703
|
};
|
|
527
704
|
Collection.prototype.replaceOne = function (filter, replacement, options) {
|
|
528
|
-
|
|
705
|
+
var _this = this;
|
|
706
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
529
707
|
var doc;
|
|
530
708
|
return __generator(this, function (_a) {
|
|
531
709
|
switch (_a.label) {
|
|
@@ -549,16 +727,28 @@ var Collection = /** @class */ (function () {
|
|
|
549
727
|
});
|
|
550
728
|
}
|
|
551
729
|
_a.label = 2;
|
|
552
|
-
case 2:
|
|
730
|
+
case 2:
|
|
731
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
|
|
732
|
+
if (res.result.ok) {
|
|
733
|
+
resolve(res.result.nModified);
|
|
734
|
+
}
|
|
735
|
+
else {
|
|
736
|
+
reject(res.result.ok);
|
|
737
|
+
}
|
|
738
|
+
}, function (err) {
|
|
739
|
+
reject(err);
|
|
740
|
+
});
|
|
741
|
+
return [2 /*return*/];
|
|
553
742
|
}
|
|
554
743
|
});
|
|
555
|
-
});
|
|
744
|
+
}); });
|
|
556
745
|
};
|
|
557
746
|
Collection.prototype.stats = function (options) {
|
|
558
747
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).stats(options);
|
|
559
748
|
};
|
|
560
749
|
Collection.prototype.updateMany = function (filter, update, options) {
|
|
561
|
-
|
|
750
|
+
var _this = this;
|
|
751
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
562
752
|
var docs;
|
|
563
753
|
var _this = this;
|
|
564
754
|
return __generator(this, function (_a) {
|
|
@@ -589,13 +779,24 @@ var Collection = /** @class */ (function () {
|
|
|
589
779
|
});
|
|
590
780
|
});
|
|
591
781
|
_a.label = 2;
|
|
592
|
-
case 2:
|
|
782
|
+
case 2:
|
|
783
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateMany(filter, update, options).then(function (res) {
|
|
784
|
+
if (res.result.ok) {
|
|
785
|
+
resolve(res.result.nModified);
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
reject(res.result.ok);
|
|
789
|
+
}
|
|
790
|
+
}, function (err) { return reject(err); });
|
|
791
|
+
return [2 /*return*/];
|
|
593
792
|
}
|
|
594
793
|
});
|
|
595
|
-
});
|
|
794
|
+
}); });
|
|
795
|
+
return;
|
|
596
796
|
};
|
|
597
797
|
Collection.prototype.updateOne = function (filter, update, options) {
|
|
598
|
-
|
|
798
|
+
var _this = this;
|
|
799
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
599
800
|
var doc;
|
|
600
801
|
return __generator(this, function (_a) {
|
|
601
802
|
switch (_a.label) {
|
|
@@ -625,10 +826,19 @@ var Collection = /** @class */ (function () {
|
|
|
625
826
|
});
|
|
626
827
|
}
|
|
627
828
|
_a.label = 2;
|
|
628
|
-
case 2:
|
|
829
|
+
case 2:
|
|
830
|
+
index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
|
|
831
|
+
if (res.result.ok) {
|
|
832
|
+
resolve(res.result.nModified);
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
reject(res.result.ok);
|
|
836
|
+
}
|
|
837
|
+
}, function (err) { return reject(err); });
|
|
838
|
+
return [2 /*return*/];
|
|
629
839
|
}
|
|
630
840
|
});
|
|
631
|
-
});
|
|
841
|
+
}); });
|
|
632
842
|
};
|
|
633
843
|
Collection.prototype.watchCollection = function (options) {
|
|
634
844
|
return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).watch(options);
|