@resolveio/server-lib 9.0.14 → 9.0.16

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.
@@ -55,6 +55,7 @@ var mongodb_1 = require("mongodb");
55
55
  var index_1 = require("../index");
56
56
  var user_collection_1 = require("../collections/user.collection");
57
57
  var common_1 = require("../util/common");
58
+ var log_collection_1 = require("../collections/log.collection");
58
59
  var crypto = require('crypto');
59
60
  var scmp = require('scmp');
60
61
  var MongoManager = /** @class */ (function () {
@@ -144,9 +145,9 @@ var Collection = /** @class */ (function () {
144
145
  Collection.prototype.aggregateStream = function (pipeline, options) {
145
146
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).aggregate(pipeline, options).stream();
146
147
  };
147
- Collection.prototype.countDocuments = function (filterQuery, options) {
148
- if (filterQuery === void 0) { filterQuery = {}; }
149
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).countDocuments(filterQuery, options);
148
+ Collection.prototype.countDocuments = function (filter, options) {
149
+ if (filter === void 0) { filter = {}; }
150
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).countDocuments(filter, options);
150
151
  };
151
152
  Collection.prototype.create = function (f_docs, options) {
152
153
  var docs = [];
@@ -161,16 +162,71 @@ var Collection = /** @class */ (function () {
161
162
  Collection.prototype.createIndexes = function (indexSpecs, options) {
162
163
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).createIndexes(indexSpecs, options);
163
164
  };
164
- Collection.prototype.deleteMany = function (filterQuery, options) {
165
- if (filterQuery === void 0) { filterQuery = {}; }
166
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteMany(filterQuery, options);
165
+ Collection.prototype.deleteMany = function (filter, options) {
166
+ if (filter === void 0) { filter = {}; }
167
+ return __awaiter(this, void 0, void 0, function () {
168
+ var docs;
169
+ var _this = this;
170
+ return __generator(this, function (_a) {
171
+ switch (_a.label) {
172
+ case 0:
173
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
174
+ return [4 /*yield*/, this.find(filter)];
175
+ case 1:
176
+ docs = _a.sent();
177
+ docs.forEach(function (doc) {
178
+ log_collection_1.Logs.create({
179
+ _id: objectIdHexString(),
180
+ type: 'document',
181
+ collection: _this.collectionName,
182
+ id_document: doc['_id'],
183
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
184
+ method: 'deleteMany',
185
+ id_user: '',
186
+ user: '',
187
+ messageId: '',
188
+ route: ''
189
+ });
190
+ });
191
+ _a.label = 2;
192
+ case 2: return [2 /*return*/, index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteMany(filter, options)];
193
+ }
194
+ });
195
+ });
167
196
  };
168
- Collection.prototype.deleteOne = function (filterQuery, options) {
169
- if (filterQuery === void 0) { filterQuery = {}; }
170
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filterQuery, options);
197
+ Collection.prototype.deleteOne = function (filter, options) {
198
+ if (filter === void 0) { filter = {}; }
199
+ return __awaiter(this, void 0, void 0, function () {
200
+ var doc;
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0:
204
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
205
+ return [4 /*yield*/, this.findOne(filter)];
206
+ case 1:
207
+ doc = _a.sent();
208
+ if (doc) {
209
+ log_collection_1.Logs.create({
210
+ _id: objectIdHexString(),
211
+ type: 'document',
212
+ collection: this.collectionName,
213
+ id_document: doc['_id'],
214
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
215
+ method: 'deleteMany',
216
+ id_user: '',
217
+ user: '',
218
+ messageId: '',
219
+ route: ''
220
+ });
221
+ }
222
+ _a.label = 2;
223
+ case 2: return [2 /*return*/, index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filter, options)];
224
+ }
225
+ });
226
+ });
171
227
  };
172
- Collection.prototype.distinct = function (key, query, options) {
173
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).distinct(key, query, options);
228
+ Collection.prototype.distinct = function (key, filter, options) {
229
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).distinct(key, filter, options);
174
230
  };
175
231
  Collection.prototype.drop = function (options) {
176
232
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).drop(options);
@@ -181,61 +237,205 @@ var Collection = /** @class */ (function () {
181
237
  Collection.prototype.dropIndexes = function (options) {
182
238
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).dropIndexes(options);
183
239
  };
184
- Collection.prototype.find = function (filterQuery, options) {
185
- if (filterQuery === void 0) { filterQuery = {}; }
186
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filterQuery, options).toArray();
240
+ Collection.prototype.find = function (filter, options) {
241
+ if (filter === void 0) { filter = {}; }
242
+ if (this.collectionName !== 'logs') {
243
+ log_collection_1.Logs.create({
244
+ _id: objectIdHexString(),
245
+ type: 'query',
246
+ collection: this.collectionName,
247
+ id_document: '',
248
+ payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
249
+ method: 'find',
250
+ id_user: '',
251
+ user: '',
252
+ messageId: '',
253
+ route: ''
254
+ });
255
+ }
256
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).toArray();
187
257
  };
188
258
  Collection.prototype.findById = function (id, options) {
259
+ if (this.collectionName !== 'logs') {
260
+ log_collection_1.Logs.create({
261
+ _id: objectIdHexString(),
262
+ type: 'query',
263
+ collection: this.collectionName,
264
+ id_document: id,
265
+ payload: common_1.getBinarySize(JSON.stringify([id, options])) < 200000 ? JSON.stringify([id, options], null, 2) : 'Too Big',
266
+ method: 'findById',
267
+ id_user: '',
268
+ user: '',
269
+ messageId: '',
270
+ route: ''
271
+ });
272
+ }
189
273
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOne({ _id: id }, options);
190
274
  };
191
- Collection.prototype.findCount = function (filterQuery, options) {
192
- if (filterQuery === void 0) { filterQuery = {}; }
193
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filterQuery, options).count();
194
- };
195
- Collection.prototype.findCursor = function (filterQuery, options) {
196
- if (filterQuery === void 0) { filterQuery = {}; }
197
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filterQuery, options);
198
- };
199
- Collection.prototype.findStream = function (filterQuery, options, streamOptions) {
200
- if (filterQuery === void 0) { filterQuery = {}; }
201
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filterQuery, options).stream(streamOptions);
202
- };
203
- Collection.prototype.findOne = function (filterQuery, options) {
204
- if (filterQuery === void 0) { filterQuery = {}; }
205
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOne(filterQuery, options);
275
+ Collection.prototype.findCount = function (filter, options) {
276
+ if (filter === void 0) { filter = {}; }
277
+ if (this.collectionName !== 'logs') {
278
+ log_collection_1.Logs.create({
279
+ _id: objectIdHexString(),
280
+ type: 'query',
281
+ collection: this.collectionName,
282
+ id_document: '',
283
+ payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
284
+ method: 'findCount',
285
+ id_user: '',
286
+ user: '',
287
+ messageId: '',
288
+ route: ''
289
+ });
290
+ }
291
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).count();
292
+ };
293
+ Collection.prototype.findCursor = function (filter, options) {
294
+ if (filter === void 0) { filter = {}; }
295
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options);
296
+ };
297
+ Collection.prototype.findStream = function (filter, options, streamOptions) {
298
+ if (filter === void 0) { filter = {}; }
299
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).stream(streamOptions);
300
+ };
301
+ Collection.prototype.findOne = function (filter, options) {
302
+ if (filter === void 0) { filter = {}; }
303
+ if (this.collectionName !== 'logs') {
304
+ log_collection_1.Logs.create({
305
+ _id: objectIdHexString(),
306
+ type: 'query',
307
+ collection: this.collectionName,
308
+ id_document: '',
309
+ payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
310
+ method: 'findOne',
311
+ id_user: '',
312
+ user: '',
313
+ messageId: '',
314
+ route: ''
315
+ });
316
+ }
317
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOne(filter, options);
206
318
  };
207
- Collection.prototype.findOneAndDelete = function (filterQuery, options) {
208
- var _this = this;
209
- if (filterQuery === void 0) { filterQuery = {}; }
210
- return new Promise(function (resolve, reject) {
211
- index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).findOneAndDelete(filterQuery, options).then(function (res) {
212
- resolve(res.value);
213
- }, function (err) {
214
- reject(err);
319
+ Collection.prototype.findOneAndDelete = function (filter, options) {
320
+ if (filter === void 0) { filter = {}; }
321
+ return __awaiter(this, void 0, void 0, function () {
322
+ var doc;
323
+ var _this = this;
324
+ return __generator(this, function (_a) {
325
+ switch (_a.label) {
326
+ case 0:
327
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
328
+ return [4 /*yield*/, this.findOne(filter)];
329
+ case 1:
330
+ doc = _a.sent();
331
+ if (doc) {
332
+ log_collection_1.Logs.create({
333
+ _id: objectIdHexString(),
334
+ type: 'document',
335
+ collection: this.collectionName,
336
+ id_document: doc['_id'],
337
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
338
+ method: 'findOneAndDelete',
339
+ id_user: '',
340
+ user: '',
341
+ messageId: '',
342
+ route: ''
343
+ });
344
+ }
345
+ _a.label = 2;
346
+ case 2: return [2 /*return*/, new Promise(function (resolve, reject) {
347
+ index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).findOneAndDelete(filter, options).then(function (res) {
348
+ resolve(res.value);
349
+ }, function (err) {
350
+ reject(err);
351
+ });
352
+ })];
353
+ }
215
354
  });
216
355
  });
217
356
  };
218
- Collection.prototype.findOneAndReplace = function (filterQuery, replacement, options) {
357
+ Collection.prototype.findOneAndReplace = function (filter, replacement, options) {
219
358
  var _this = this;
220
- if (filterQuery === void 0) { filterQuery = {}; }
221
- return new Promise(function (resolve, reject) {
222
- index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).findOneAndReplace(filterQuery, replacement, options).then(function (res) {
223
- resolve(res.value);
224
- }, function (err) {
225
- reject(err);
359
+ if (filter === void 0) { filter = {}; }
360
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
361
+ var doc;
362
+ return __generator(this, function (_a) {
363
+ switch (_a.label) {
364
+ case 0:
365
+ replacement['updatedAt'] = new Date();
366
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
367
+ return [4 /*yield*/, this.findOne(filter)];
368
+ case 1:
369
+ doc = _a.sent();
370
+ if (doc) {
371
+ log_collection_1.Logs.create({
372
+ _id: objectIdHexString(),
373
+ type: 'document',
374
+ collection: this.collectionName,
375
+ id_document: doc['_id'],
376
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
377
+ method: 'findOneAndReplace',
378
+ id_user: '',
379
+ user: '',
380
+ messageId: '',
381
+ route: ''
382
+ });
383
+ }
384
+ _a.label = 2;
385
+ case 2:
386
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(function (res) {
387
+ resolve(res.value);
388
+ }, function (err) {
389
+ reject(err);
390
+ });
391
+ return [2 /*return*/];
392
+ }
226
393
  });
227
- });
394
+ }); });
228
395
  };
229
- Collection.prototype.findOneAndUpdate = function (filterQuery, update, options) {
396
+ Collection.prototype.findOneAndUpdate = function (filter, update, options) {
230
397
  var _this = this;
231
- if (filterQuery === void 0) { filterQuery = {}; }
232
- return new Promise(function (resolve, reject) {
233
- index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).findOneAndUpdate(filterQuery, update, options).then(function (res) {
234
- resolve(res.value);
235
- }, function (err) {
236
- reject(err);
398
+ if (filter === void 0) { filter = {}; }
399
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
400
+ var doc;
401
+ return __generator(this, function (_a) {
402
+ switch (_a.label) {
403
+ case 0:
404
+ if (!update['$set']) {
405
+ update['$set'] = { updatedAt: new Date() };
406
+ }
407
+ else {
408
+ update['$set']['updatedAt'] = new Date();
409
+ }
410
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
411
+ return [4 /*yield*/, this.findOne(filter)];
412
+ case 1:
413
+ doc = _a.sent();
414
+ if (doc) {
415
+ log_collection_1.Logs.create({
416
+ _id: objectIdHexString(),
417
+ type: 'document',
418
+ collection: this.collectionName,
419
+ id_document: doc['_id'],
420
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
421
+ method: 'findOneAndUpdate',
422
+ id_user: '',
423
+ user: '',
424
+ messageId: '',
425
+ route: ''
426
+ });
427
+ }
428
+ _a.label = 2;
429
+ case 2:
430
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(function (res) {
431
+ resolve(res.value);
432
+ }, function (err) {
433
+ reject(err);
434
+ });
435
+ return [2 /*return*/];
436
+ }
237
437
  });
238
- });
438
+ }); });
239
439
  };
240
440
  Collection.prototype.indexes = function (options) {
241
441
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).indexes(options);
@@ -252,6 +452,22 @@ var Collection = /** @class */ (function () {
252
452
  doc['updatedAt'] = new Date();
253
453
  });
254
454
  }
455
+ if (_this.collectionName !== 'logs') {
456
+ docs.forEach(function (doc) {
457
+ log_collection_1.Logs.create({
458
+ _id: objectIdHexString(),
459
+ type: 'document',
460
+ collection: _this.collectionName,
461
+ id_document: doc['_id'],
462
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
463
+ method: 'insertMany',
464
+ id_user: '',
465
+ user: '',
466
+ messageId: '',
467
+ route: ''
468
+ });
469
+ });
470
+ }
255
471
  index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).insertMany(docs, options).then(function (res) {
256
472
  if (res.result.ok) {
257
473
  resolve(docs);
@@ -271,6 +487,20 @@ var Collection = /** @class */ (function () {
271
487
  doc['createdAt'] = new Date();
272
488
  doc['updatedAt'] = new Date();
273
489
  }
490
+ if (_this.collectionName !== 'logs') {
491
+ log_collection_1.Logs.create({
492
+ _id: objectIdHexString(),
493
+ type: 'document',
494
+ collection: _this.collectionName,
495
+ id_document: doc['_id'],
496
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
497
+ method: 'insertOne',
498
+ id_user: '',
499
+ user: '',
500
+ messageId: '',
501
+ route: ''
502
+ });
503
+ }
274
504
  index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).insertOne(doc, options).then(function (res) {
275
505
  if (res.result.ok) {
276
506
  resolve(doc);
@@ -292,29 +522,111 @@ var Collection = /** @class */ (function () {
292
522
  Collection.prototype.rename = function (newName, options) {
293
523
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
294
524
  };
295
- Collection.prototype.replaceOne = function (filter, doc, options) {
296
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, doc, options);
525
+ Collection.prototype.replaceOne = function (filter, replacement, options) {
526
+ return __awaiter(this, void 0, void 0, function () {
527
+ var doc;
528
+ return __generator(this, function (_a) {
529
+ switch (_a.label) {
530
+ case 0:
531
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
532
+ return [4 /*yield*/, this.findOne(filter)];
533
+ case 1:
534
+ doc = _a.sent();
535
+ if (doc) {
536
+ log_collection_1.Logs.create({
537
+ _id: objectIdHexString(),
538
+ type: 'document',
539
+ collection: this.collectionName,
540
+ id_document: doc['_id'],
541
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
542
+ method: 'replaceOne',
543
+ id_user: '',
544
+ user: '',
545
+ messageId: '',
546
+ route: ''
547
+ });
548
+ }
549
+ _a.label = 2;
550
+ case 2: return [2 /*return*/, index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options)];
551
+ }
552
+ });
553
+ });
297
554
  };
298
555
  Collection.prototype.stats = function (options) {
299
556
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).stats(options);
300
557
  };
301
558
  Collection.prototype.updateMany = function (filter, update, options) {
302
- if (!update['$set']) {
303
- update['$set'] = { updatedAt: new Date() };
304
- }
305
- else {
306
- update['$set']['updatedAt'] = new Date();
307
- }
308
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateMany(filter, update, options);
559
+ return __awaiter(this, void 0, void 0, function () {
560
+ var docs;
561
+ var _this = this;
562
+ return __generator(this, function (_a) {
563
+ switch (_a.label) {
564
+ case 0:
565
+ if (!update['$set']) {
566
+ update['$set'] = { updatedAt: new Date() };
567
+ }
568
+ else {
569
+ update['$set']['updatedAt'] = new Date();
570
+ }
571
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
572
+ return [4 /*yield*/, this.find(filter)];
573
+ case 1:
574
+ docs = _a.sent();
575
+ docs.forEach(function (doc) {
576
+ log_collection_1.Logs.create({
577
+ _id: objectIdHexString(),
578
+ type: 'document',
579
+ collection: _this.collectionName,
580
+ id_document: doc['_id'],
581
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
582
+ method: 'updateMany',
583
+ id_user: '',
584
+ user: '',
585
+ messageId: '',
586
+ route: ''
587
+ });
588
+ });
589
+ _a.label = 2;
590
+ case 2: return [2 /*return*/, index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateMany(filter, update, options)];
591
+ }
592
+ });
593
+ });
309
594
  };
310
595
  Collection.prototype.updateOne = function (filter, update, options) {
311
- if (!update['$set']) {
312
- update['$set'] = { updatedAt: new Date() };
313
- }
314
- else {
315
- update['$set']['updatedAt'] = new Date();
316
- }
317
- return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options);
596
+ return __awaiter(this, void 0, void 0, function () {
597
+ var doc;
598
+ return __generator(this, function (_a) {
599
+ switch (_a.label) {
600
+ case 0:
601
+ if (!update['$set']) {
602
+ update['$set'] = { updatedAt: new Date() };
603
+ }
604
+ else {
605
+ update['$set']['updatedAt'] = new Date();
606
+ }
607
+ if (!(this.collectionName !== 'logs')) return [3 /*break*/, 2];
608
+ return [4 /*yield*/, this.findOne(filter)];
609
+ case 1:
610
+ doc = _a.sent();
611
+ if (doc) {
612
+ log_collection_1.Logs.create({
613
+ _id: objectIdHexString(),
614
+ type: 'document',
615
+ collection: this.collectionName,
616
+ id_document: doc['_id'],
617
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
618
+ method: 'updateOne',
619
+ id_user: '',
620
+ user: '',
621
+ messageId: '',
622
+ route: ''
623
+ });
624
+ }
625
+ _a.label = 2;
626
+ case 2: return [2 /*return*/, index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options)];
627
+ }
628
+ });
629
+ });
318
630
  };
319
631
  Collection.prototype.watchCollection = function (options) {
320
632
  return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).watch(options);