@resolveio/server-lib 9.0.34 → 9.0.36

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.
Files changed (192) hide show
  1. package/client-server-app.js +48 -7
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +11 -8
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/app-version.collection.js +11 -8
  6. package/collections/app-version.collection.js.map +1 -1
  7. package/collections/counter.collection.js +11 -8
  8. package/collections/counter.collection.js.map +1 -1
  9. package/collections/cron-job-history.collection.js +12 -9
  10. package/collections/cron-job-history.collection.js.map +1 -1
  11. package/collections/cron-job.collection.js +11 -8
  12. package/collections/cron-job.collection.js.map +1 -1
  13. package/collections/email-history.collection.js +11 -8
  14. package/collections/email-history.collection.js.map +1 -1
  15. package/collections/email-verified.collection.js +12 -9
  16. package/collections/email-verified.collection.js.map +1 -1
  17. package/collections/file.collection.js +11 -8
  18. package/collections/file.collection.js.map +1 -1
  19. package/collections/flag.collection.js +11 -8
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +14 -11
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +16 -13
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +19 -16
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +12 -9
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-call.collection.js +13 -10
  30. package/collections/method-call.collection.js.map +1 -1
  31. package/collections/method-response.collection.js +13 -10
  32. package/collections/method-response.collection.js.map +1 -1
  33. package/collections/monitor-cpu.collection.js +16 -13
  34. package/collections/monitor-cpu.collection.js.map +1 -1
  35. package/collections/monitor-https-inbound.collection.js +16 -13
  36. package/collections/monitor-https-inbound.collection.js.map +1 -1
  37. package/collections/monitor-https-outbound.collection.js +18 -15
  38. package/collections/monitor-https-outbound.collection.js.map +1 -1
  39. package/collections/monitor-memory.collection.js +15 -12
  40. package/collections/monitor-memory.collection.js.map +1 -1
  41. package/collections/monitor-mongo.collection.js +15 -12
  42. package/collections/monitor-mongo.collection.js.map +1 -1
  43. package/collections/notification.collection.js +11 -8
  44. package/collections/notification.collection.js.map +1 -1
  45. package/collections/queue-flag.collection.js +12 -9
  46. package/collections/queue-flag.collection.js.map +1 -1
  47. package/collections/queue-method.collection.js +12 -9
  48. package/collections/queue-method.collection.js.map +1 -1
  49. package/collections/queue-response.collection.js +12 -9
  50. package/collections/queue-response.collection.js.map +1 -1
  51. package/collections/report-builder-dashboard-builder.collection.js +13 -10
  52. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  53. package/collections/report-builder-library.collection.js +14 -11
  54. package/collections/report-builder-library.collection.js.map +1 -1
  55. package/collections/report-builder-report.collection.js +14 -11
  56. package/collections/report-builder-report.collection.js.map +1 -1
  57. package/collections/user-group.collection.js +14 -11
  58. package/collections/user-group.collection.js.map +1 -1
  59. package/collections/user-guide.collection.js +11 -8
  60. package/collections/user-guide.collection.js.map +1 -1
  61. package/collections/user.collection.js +15 -12
  62. package/collections/user.collection.js.map +1 -1
  63. package/cron/cron.js +25 -25
  64. package/cron/cron.js.map +1 -1
  65. package/fixtures/cron-jobs.js +80 -30
  66. package/fixtures/cron-jobs.js.map +1 -1
  67. package/fixtures/init.js +59 -9
  68. package/fixtures/init.js.map +1 -1
  69. package/http/auth.js +460 -344
  70. package/http/auth.js.map +1 -1
  71. package/http/health.js +5 -1
  72. package/http/health.js.map +1 -1
  73. package/http/home.js +11 -7
  74. package/http/home.js.map +1 -1
  75. package/index.js +98 -36
  76. package/index.js.map +1 -1
  77. package/managers/cron.manager.js +157 -78
  78. package/managers/cron.manager.js.map +1 -1
  79. package/managers/method.manager.js +302 -314
  80. package/managers/method.manager.js.map +1 -1
  81. package/managers/mongo.manager.js +1010 -741
  82. package/managers/mongo.manager.js.map +1 -1
  83. package/managers/monitor.manager.js +254 -171
  84. package/managers/monitor.manager.js.map +1 -1
  85. package/managers/queue-method.manager.js +166 -69
  86. package/managers/queue-method.manager.js.map +1 -1
  87. package/managers/subscription.manager.js +714 -515
  88. package/managers/subscription.manager.js.map +1 -1
  89. package/methods/accounts.js +183 -111
  90. package/methods/accounts.js.map +1 -1
  91. package/methods/aws.js +262 -156
  92. package/methods/aws.js.map +1 -1
  93. package/methods/cloudconvert.js +180 -100
  94. package/methods/cloudconvert.js.map +1 -1
  95. package/methods/collections.js +110 -103
  96. package/methods/collections.js.map +1 -1
  97. package/methods/counters.js +79 -29
  98. package/methods/counters.js.map +1 -1
  99. package/methods/cron-jobs.js +884 -819
  100. package/methods/cron-jobs.js.map +1 -1
  101. package/methods/flags.js +5 -1
  102. package/methods/flags.js.map +1 -1
  103. package/methods/logs.js +313 -258
  104. package/methods/logs.js.map +1 -1
  105. package/methods/monitor.js +348 -289
  106. package/methods/monitor.js.map +1 -1
  107. package/methods/pdf.js +340 -341
  108. package/methods/pdf.js.map +1 -1
  109. package/methods/report-builder.js +657 -565
  110. package/methods/report-builder.js.map +1 -1
  111. package/methods/support.js +185 -67
  112. package/methods/support.js.map +1 -1
  113. package/models/app-status.model.js +2 -1
  114. package/models/app-version.model.js +2 -1
  115. package/models/billing-logged-in-users.model.js +2 -1
  116. package/models/collection-document.model.js +2 -1
  117. package/models/counter.model.js +2 -1
  118. package/models/cron-job-history.model.js +2 -1
  119. package/models/cron-job.model.js +2 -1
  120. package/models/dialog.model.js +2 -1
  121. package/models/email-history.model.js +2 -1
  122. package/models/email-verified.model.js +2 -1
  123. package/models/file.model.js +2 -1
  124. package/models/flag.model.js +2 -1
  125. package/models/log-method-latency.model.js +2 -1
  126. package/models/log-subscription.model.js +2 -1
  127. package/models/log.model.js +2 -1
  128. package/models/logged-in-users.model.js +2 -1
  129. package/models/method-call.model.js +2 -1
  130. package/models/method-response.model.js +2 -1
  131. package/models/method.model.js +2 -1
  132. package/models/monitor-cpu.model.js +2 -1
  133. package/models/monitor-https-inbound.model.js +2 -1
  134. package/models/monitor-https-outbound.model.js +2 -1
  135. package/models/monitor-memory.model.js +2 -1
  136. package/models/monitor-mongo.model.js +2 -1
  137. package/models/notification.model.js +2 -1
  138. package/models/pagination.model.js +5 -2
  139. package/models/pagination.model.js.map +1 -1
  140. package/models/permission.model.js +2 -1
  141. package/models/queue-method.model.js +2 -1
  142. package/models/queue-response.model.js +2 -1
  143. package/models/report-builder-dashboard-builder.model.js +2 -1
  144. package/models/report-builder-library.model.js +2 -1
  145. package/models/report-builder-report.model.js +2 -1
  146. package/models/report-builder.model.js +2 -1
  147. package/models/select-data-label.model.js +2 -1
  148. package/models/server-response.model.js +2 -1
  149. package/models/subscription.model.js +2 -1
  150. package/models/support-ticket.model.js +2 -1
  151. package/models/user-group.model.js +2 -1
  152. package/models/user-guide.model.js +2 -1
  153. package/models/user.model.js +2 -1
  154. package/package.json +1 -1
  155. package/public_api.js +82 -70
  156. package/public_api.js.map +1 -1
  157. package/publications/app-status.js +8 -4
  158. package/publications/app-status.js.map +1 -1
  159. package/publications/app-version.js +8 -4
  160. package/publications/app-version.js.map +1 -1
  161. package/publications/cron-jobs.js +13 -9
  162. package/publications/cron-jobs.js.map +1 -1
  163. package/publications/files.js +15 -11
  164. package/publications/files.js.map +1 -1
  165. package/publications/flags.js +11 -7
  166. package/publications/flags.js.map +1 -1
  167. package/publications/logs.js +35 -31
  168. package/publications/logs.js.map +1 -1
  169. package/publications/method-calls.js +8 -4
  170. package/publications/method-calls.js.map +1 -1
  171. package/publications/method-responses.js +8 -4
  172. package/publications/method-responses.js.map +1 -1
  173. package/publications/notifications.js +8 -4
  174. package/publications/notifications.js.map +1 -1
  175. package/publications/report-builder-dashboard-builders.js +12 -8
  176. package/publications/report-builder-dashboard-builders.js.map +1 -1
  177. package/publications/report-builder-libraries.js +66 -16
  178. package/publications/report-builder-libraries.js.map +1 -1
  179. package/publications/report-builder-reports.js +21 -17
  180. package/publications/report-builder-reports.js.map +1 -1
  181. package/publications/super-admin.js +7 -3
  182. package/publications/super-admin.js.map +1 -1
  183. package/publications/user-groups.js +8 -4
  184. package/publications/user-groups.js.map +1 -1
  185. package/publications/user-guides.js +8 -4
  186. package/publications/user-guides.js.map +1 -1
  187. package/server-app.js +534 -393
  188. package/server-app.js.map +1 -1
  189. package/util/common.js +92 -55
  190. package/util/common.js.map +1 -1
  191. package/util/schema-report-builder.js +134 -76
  192. package/util/schema-report-builder.js.map +1 -1
@@ -1,29 +1,81 @@
1
- import SimpleSchema from 'simpl-schema';
2
- import { ObjectId } from 'mongodb';
3
- import { ResolveIOServer } from '../index';
4
- import { Users } from '../collections/user.collection';
5
- import { buildRbLookups, buildRbSchema, deepCopy, getBinarySize, getMongoMergeUpdatedDoc } from '../util/common';
6
- import { Logs } from '../collections/log.collection';
7
- const crypto = require('crypto');
8
- const scmp = require('scmp');
9
- export class MongoManager {
10
- constructor() {
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
17
+ return new (P || (P = Promise))(function (resolve, reject) {
18
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
19
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
22
+ });
23
+ };
24
+ var __generator = (this && this.__generator) || function (thisArg, body) {
25
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
26
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
27
+ function verb(n) { return function (v) { return step([n, v]); }; }
28
+ function step(op) {
29
+ if (f) throw new TypeError("Generator is already executing.");
30
+ while (_) try {
31
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
32
+ if (y = 0, t) op = [op[0] & 2, t.value];
33
+ switch (op[0]) {
34
+ case 0: case 1: t = op; break;
35
+ case 4: _.label++; return { value: op[1], done: false };
36
+ case 5: _.label++; y = op[1]; op = [0]; continue;
37
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
38
+ default:
39
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
40
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
41
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
42
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
43
+ if (t[2]) _.ops.pop();
44
+ _.trys.pop(); continue;
45
+ }
46
+ op = body.call(thisArg, _);
47
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
48
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
49
+ }
50
+ };
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.objectIdHexString = exports.UserCollection = exports.Collection = exports.Model = exports.MongoManager = void 0;
53
+ var simpl_schema_1 = require("simpl-schema");
54
+ var mongodb_1 = require("mongodb");
55
+ var index_1 = require("../index");
56
+ var user_collection_1 = require("../collections/user.collection");
57
+ var common_1 = require("../util/common");
58
+ var log_collection_1 = require("../collections/log.collection");
59
+ var crypto = require('crypto');
60
+ var scmp = require('scmp');
61
+ var MongoManager = /** @class */ (function () {
62
+ function MongoManager() {
11
63
  this._collections = [];
12
64
  this._mongoQueue = [];
13
65
  this._mongoQueueId = 0;
14
66
  this.runQueue();
15
67
  }
16
- registerCollection(collection) {
68
+ MongoManager.prototype.registerCollection = function (collection) {
17
69
  this._collections.push(collection);
18
- }
19
- collections() {
70
+ };
71
+ MongoManager.prototype.collections = function () {
20
72
  return this._collections;
21
- }
22
- collection(collectionName) {
23
- return this._collections.filter(a => a.collectionName === collectionName)[0];
24
- }
25
- addToQueue(mongoQueue) {
26
- let _mongoQueue = this._mongoQueue.filter(a => 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];
73
+ };
74
+ MongoManager.prototype.collection = function (collectionName) {
75
+ return this._collections.filter(function (a) { return a.collectionName === collectionName; })[0];
76
+ };
77
+ MongoManager.prototype.addToQueue = function (mongoQueue) {
78
+ 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];
27
79
  if (_mongoQueue) {
28
80
  if (!_mongoQueue.running) {
29
81
  _mongoQueue.cbs.push(mongoQueue.cbs[0]);
@@ -37,64 +89,78 @@ export class MongoManager {
37
89
  this._mongoQueueId += 1;
38
90
  this._mongoQueue.push(mongoQueue);
39
91
  }
40
- }
41
- async runQueue() {
42
- setInterval(() => {
43
- if (this._mongoQueue.filter(a => !a.running).length) {
44
- let mongoQueue = this._mongoQueue.filter(a => !a.running)[0];
45
- mongoQueue.running = true;
46
- if (!mongoQueue.name_function_addt) {
47
- ResolveIOServer.getMainDB().collection(mongoQueue.name_collection)[mongoQueue.name_function](...mongoQueue.data_function).then(res => {
48
- mongoQueue.cbs.forEach(cb => {
49
- cb(null, res);
50
- });
51
- if (mongoQueue.cbs_next.length) {
52
- mongoQueue.running = false;
53
- mongoQueue.cbs = mongoQueue.cbs_next;
54
- mongoQueue.cbs_next = [];
55
- }
56
- else {
57
- this._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);
58
- }
59
- }, err => {
60
- mongoQueue.cbs.forEach(cb => {
61
- cb(err, null);
62
- });
63
- mongoQueue.cbs_next.forEach(cb => {
64
- cb(err, null);
65
- });
66
- this._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);
67
- });
68
- }
69
- else {
70
- ResolveIOServer.getMainDB().collection(mongoQueue.name_collection)[mongoQueue.name_function](...mongoQueue.data_function)[mongoQueue.name_function_addt](...mongoQueue.data_function_addt).then(res => {
71
- mongoQueue.cbs.forEach(cb => {
72
- cb(null, res);
73
- });
74
- if (mongoQueue.cbs_next.length) {
75
- mongoQueue.running = false;
76
- mongoQueue.cbs = mongoQueue.cbs_next;
77
- mongoQueue.cbs_next = []; // BUG???
92
+ };
93
+ MongoManager.prototype.runQueue = function () {
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ var _this = this;
96
+ return __generator(this, function (_a) {
97
+ setInterval(function () {
98
+ var _a, _b, _c;
99
+ if (_this._mongoQueue.filter(function (a) { return !a.running; }).length) {
100
+ var mongoQueue_1 = _this._mongoQueue.filter(function (a) { return !a.running; })[0];
101
+ mongoQueue_1.running = true;
102
+ if (!mongoQueue_1.name_function_addt) {
103
+ (_a = index_1.ResolveIOServer.getMainDB().collection(mongoQueue_1.name_collection))[mongoQueue_1.name_function].apply(_a, mongoQueue_1.data_function).then(function (res) {
104
+ mongoQueue_1.cbs.forEach(function (cb) {
105
+ cb(null, res);
106
+ });
107
+ if (mongoQueue_1.cbs_next.length) {
108
+ mongoQueue_1.running = false;
109
+ mongoQueue_1.cbs = mongoQueue_1.cbs_next;
110
+ mongoQueue_1.cbs_next = [];
111
+ }
112
+ else {
113
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
114
+ }
115
+ }, function (err) {
116
+ mongoQueue_1.cbs.forEach(function (cb) {
117
+ cb(err, null);
118
+ });
119
+ mongoQueue_1.cbs_next.forEach(function (cb) {
120
+ cb(err, null);
121
+ });
122
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
123
+ });
78
124
  }
79
125
  else {
80
- this._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);
126
+ (_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) {
127
+ mongoQueue_1.cbs.forEach(function (cb) {
128
+ cb(null, res);
129
+ });
130
+ if (mongoQueue_1.cbs_next.length) {
131
+ mongoQueue_1.running = false;
132
+ mongoQueue_1.cbs = mongoQueue_1.cbs_next;
133
+ mongoQueue_1.cbs_next = []; // BUG???
134
+ }
135
+ else {
136
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
137
+ }
138
+ }, function (err) {
139
+ mongoQueue_1.cbs.forEach(function (cb) {
140
+ cb(err, null);
141
+ });
142
+ mongoQueue_1.cbs_next.forEach(function (cb) {
143
+ cb(err, null);
144
+ });
145
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
146
+ });
81
147
  }
82
- }, err => {
83
- mongoQueue.cbs.forEach(cb => {
84
- cb(err, null);
85
- });
86
- mongoQueue.cbs_next.forEach(cb => {
87
- cb(err, null);
88
- });
89
- this._mongoQueue.splice(this._mongoQueue.map(a => a._id).indexOf(mongoQueue._id), 1);
90
- });
91
- }
92
- }
93
- }, 10);
94
- }
95
- }
96
- export class Model {
97
- constructor(collectionName, schema, useVersionCollection = false, useReportBuilder = true, reportBuilderLookupTables = [], timestamps = true, createLogs = true) {
148
+ }
149
+ }, 10);
150
+ return [2 /*return*/];
151
+ });
152
+ });
153
+ };
154
+ return MongoManager;
155
+ }());
156
+ exports.MongoManager = MongoManager;
157
+ var Model = /** @class */ (function () {
158
+ function Model(collectionName, schema, useVersionCollection, useReportBuilder, reportBuilderLookupTables, timestamps, createLogs) {
159
+ if (useVersionCollection === void 0) { useVersionCollection = false; }
160
+ if (useReportBuilder === void 0) { useReportBuilder = true; }
161
+ if (reportBuilderLookupTables === void 0) { reportBuilderLookupTables = []; }
162
+ if (timestamps === void 0) { timestamps = true; }
163
+ if (createLogs === void 0) { createLogs = true; }
98
164
  this.collection_main = null;
99
165
  this.collection_version = null;
100
166
  if (collectionName === 'users') {
@@ -105,7 +171,7 @@ export class Model {
105
171
  }
106
172
  if (useVersionCollection) {
107
173
  this.collection_main.useVersions = true;
108
- let versionSchema = deepCopy(schema);
174
+ var versionSchema = common_1.deepCopy(schema);
109
175
  versionSchema['_id'].type = 'Object';
110
176
  versionSchema['_id'].blackbox = true;
111
177
  if (collectionName === 'users') {
@@ -118,9 +184,12 @@ export class Model {
118
184
  this.collection_main.versionCollection = collectionName + '.versions';
119
185
  }
120
186
  }
121
- }
122
- export class Collection {
123
- constructor(collectionName, schema, useReportBuilder, reportBuilderLookupTables, timestamps, createLogs) {
187
+ return Model;
188
+ }());
189
+ exports.Model = Model;
190
+ var Collection = /** @class */ (function () {
191
+ function Collection(collectionName, schema, useReportBuilder, reportBuilderLookupTables, timestamps, createLogs) {
192
+ var _this = this;
124
193
  this.collectionName = '';
125
194
  this.simplschema = null;
126
195
  this.rbSchema = null;
@@ -130,32 +199,33 @@ export class Collection {
130
199
  this.createLogs = true;
131
200
  this.useRB = false;
132
201
  this.collectionName = collectionName;
133
- this.simplschema = new SimpleSchema(schema);
202
+ this.simplschema = new simpl_schema_1.default(schema);
134
203
  this.timestamps = timestamps;
135
204
  this.createLogs = createLogs;
136
205
  if (useReportBuilder) {
137
206
  this.useRB = true;
138
- let schemaCopy = deepCopy(schema);
139
- let rbSchema = buildRbLookups(reportBuilderLookupTables, schemaCopy, []);
140
- this.rbSchema = buildRbSchema(rbSchema);
207
+ var schemaCopy = common_1.deepCopy(schema);
208
+ var rbSchema = common_1.buildRbLookups(reportBuilderLookupTables, schemaCopy, []);
209
+ this.rbSchema = common_1.buildRbSchema(rbSchema);
141
210
  }
142
- let interval = setInterval(() => {
143
- if (ResolveIOServer && ResolveIOServer.getMainServer() && ResolveIOServer.getMongoManager()) {
144
- ResolveIOServer.getMongoManager().registerCollection(this);
211
+ var interval = setInterval(function () {
212
+ if (index_1.ResolveIOServer && index_1.ResolveIOServer.getMainServer() && index_1.ResolveIOServer.getMongoManager()) {
213
+ index_1.ResolveIOServer.getMongoManager().registerCollection(_this);
145
214
  clearInterval(interval);
146
215
  }
147
216
  }, 1);
148
217
  }
149
- aggregate(pipeline, options) {
150
- return new Promise((resolve, reject) => {
151
- ResolveIOServer.getMongoManager().addToQueue({
218
+ Collection.prototype.aggregate = function (pipeline, options) {
219
+ var _this = this;
220
+ return new Promise(function (resolve, reject) {
221
+ index_1.ResolveIOServer.getMongoManager().addToQueue({
152
222
  _id: 0,
153
- name_collection: this.collectionName,
223
+ name_collection: _this.collectionName,
154
224
  name_function: 'aggregate',
155
225
  name_function_addt: 'toArray',
156
226
  data_function: [pipeline, options],
157
227
  data_function_addt: [],
158
- cbs: [(err, res) => {
228
+ cbs: [function (err, res) {
159
229
  if (err) {
160
230
  reject(err);
161
231
  }
@@ -167,17 +237,18 @@ export class Collection {
167
237
  running: false
168
238
  });
169
239
  });
170
- }
171
- aggregateCount(pipeline, options) {
172
- return new Promise((resolve, reject) => {
173
- ResolveIOServer.getMongoManager().addToQueue({
240
+ };
241
+ Collection.prototype.aggregateCount = function (pipeline, options) {
242
+ var _this = this;
243
+ return new Promise(function (resolve, reject) {
244
+ index_1.ResolveIOServer.getMongoManager().addToQueue({
174
245
  _id: 0,
175
- name_collection: this.collectionName,
246
+ name_collection: _this.collectionName,
176
247
  name_function: 'aggregate',
177
248
  name_function_addt: 'count',
178
249
  data_function: [pipeline, options],
179
250
  data_function_addt: [],
180
- cbs: [(err, res) => {
251
+ cbs: [function (err, res) {
181
252
  if (err) {
182
253
  reject(err);
183
254
  }
@@ -189,116 +260,147 @@ export class Collection {
189
260
  running: false
190
261
  });
191
262
  });
192
- }
193
- aggregateCursor(pipeline, options) {
194
- return ResolveIOServer.getMainDB().collection(this.collectionName).aggregate(pipeline, options);
195
- }
196
- aggregateStream(pipeline, options) {
197
- return ResolveIOServer.getMainDB().collection(this.collectionName).aggregate(pipeline, options).stream();
198
- }
199
- countDocuments(filter = {}, options) {
200
- return ResolveIOServer.getMainDB().collection(this.collectionName).countDocuments(filter, options);
201
- }
202
- create(f_docs, options) {
203
- let docs = [];
263
+ };
264
+ Collection.prototype.aggregateCursor = function (pipeline, options) {
265
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).aggregate(pipeline, options);
266
+ };
267
+ Collection.prototype.aggregateStream = function (pipeline, options) {
268
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).aggregate(pipeline, options).stream();
269
+ };
270
+ Collection.prototype.countDocuments = function (filter, options) {
271
+ if (filter === void 0) { filter = {}; }
272
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).countDocuments(filter, options);
273
+ };
274
+ Collection.prototype.create = function (f_docs, options) {
275
+ var docs = [];
204
276
  if (!Array.isArray(f_docs)) {
205
277
  return this.insertOne(f_docs, options);
206
278
  }
207
279
  return this.insertMany(f_docs, options);
208
- }
209
- createIndex(fieldOrSpec, options) {
210
- return ResolveIOServer.getMainDB().collection(this.collectionName).createIndex(fieldOrSpec, options);
211
- }
212
- createIndexes(indexSpecs, options) {
213
- return ResolveIOServer.getMainDB().collection(this.collectionName).createIndexes(indexSpecs, options);
214
- }
215
- deleteMany(filter = {}, options, bypassLogs = false) {
216
- return new Promise(async (resolve, reject) => {
217
- if (this.createLogs && !bypassLogs) {
218
- let docs = await this.find(filter);
219
- docs.forEach(doc => {
220
- Logs.insertOne({
221
- _id: objectIdHexString(),
222
- type: 'document',
223
- collection: this.collectionName,
224
- id_document: doc['_id'],
225
- payload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
226
- method: 'deleteMany',
227
- id_user: '',
228
- user: '',
229
- messageId: '',
230
- route: ''
231
- });
232
- if (this.useVersions) {
233
- doc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
234
- ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(doc);
235
- }
236
- });
237
- }
238
- ResolveIOServer.getMainDB().collection(this.collectionName).deleteMany(filter, options).then(res => {
239
- if (res.result.ok) {
240
- resolve(res.deletedCount);
241
- }
242
- else {
243
- reject(res.result.ok);
244
- }
245
- }, err => reject(err));
246
- });
247
- }
248
- deleteOne(filter = {}, options, bypassLogs = false) {
249
- return new Promise(async (resolve, reject) => {
250
- if (this.createLogs && !bypassLogs) {
251
- let doc = await this.findOne(filter);
252
- if (doc) {
253
- Logs.insertOne({
254
- _id: objectIdHexString(),
255
- type: 'document',
256
- collection: this.collectionName,
257
- id_document: doc['_id'],
258
- payload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
259
- method: 'deleteOne',
260
- id_user: '',
261
- user: '',
262
- messageId: '',
263
- route: ''
264
- });
265
- if (this.useVersions) {
266
- doc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
267
- ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(doc);
268
- }
269
- }
270
- }
271
- ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filter, options).then(res => {
272
- if (res.result.ok) {
273
- resolve(res.deletedCount);
280
+ };
281
+ Collection.prototype.createIndex = function (fieldOrSpec, options) {
282
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).createIndex(fieldOrSpec, options);
283
+ };
284
+ Collection.prototype.createIndexes = function (indexSpecs, options) {
285
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).createIndexes(indexSpecs, options);
286
+ };
287
+ Collection.prototype.deleteMany = function (filter, options, bypassLogs) {
288
+ var _this = this;
289
+ if (filter === void 0) { filter = {}; }
290
+ if (bypassLogs === void 0) { bypassLogs = false; }
291
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
292
+ var docs;
293
+ var _this = this;
294
+ return __generator(this, function (_a) {
295
+ switch (_a.label) {
296
+ case 0:
297
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
298
+ return [4 /*yield*/, this.find(filter)];
299
+ case 1:
300
+ docs = _a.sent();
301
+ docs.forEach(function (doc) {
302
+ log_collection_1.Logs.insertOne({
303
+ _id: objectIdHexString(),
304
+ type: 'document',
305
+ collection: _this.collectionName,
306
+ id_document: doc['_id'],
307
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
308
+ method: 'deleteMany',
309
+ id_user: '',
310
+ user: '',
311
+ messageId: '',
312
+ route: ''
313
+ });
314
+ if (_this.useVersions) {
315
+ doc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
316
+ index_1.ResolveIOServer.getMongoManager().collection(_this.versionCollection).insertOne(doc);
317
+ }
318
+ });
319
+ _a.label = 2;
320
+ case 2:
321
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteMany(filter, options).then(function (res) {
322
+ if (res.result.ok) {
323
+ resolve(res.deletedCount);
324
+ }
325
+ else {
326
+ reject(res.result.ok);
327
+ }
328
+ }, function (err) { return reject(err); });
329
+ return [2 /*return*/];
274
330
  }
275
- else {
276
- reject(res.result.ok);
331
+ });
332
+ }); });
333
+ };
334
+ Collection.prototype.deleteOne = function (filter, options, bypassLogs) {
335
+ var _this = this;
336
+ if (filter === void 0) { filter = {}; }
337
+ if (bypassLogs === void 0) { bypassLogs = false; }
338
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
339
+ var doc;
340
+ return __generator(this, function (_a) {
341
+ switch (_a.label) {
342
+ case 0:
343
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
344
+ return [4 /*yield*/, this.findOne(filter)];
345
+ case 1:
346
+ doc = _a.sent();
347
+ if (doc) {
348
+ log_collection_1.Logs.insertOne({
349
+ _id: objectIdHexString(),
350
+ type: 'document',
351
+ collection: this.collectionName,
352
+ id_document: doc['_id'],
353
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
354
+ method: 'deleteOne',
355
+ id_user: '',
356
+ user: '',
357
+ messageId: '',
358
+ route: ''
359
+ });
360
+ if (this.useVersions) {
361
+ doc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
362
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(doc);
363
+ }
364
+ }
365
+ _a.label = 2;
366
+ case 2:
367
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).deleteOne(filter, options).then(function (res) {
368
+ if (res.result.ok) {
369
+ resolve(res.deletedCount);
370
+ }
371
+ else {
372
+ reject(res.result.ok);
373
+ }
374
+ }, function (err) { return reject(err); });
375
+ return [2 /*return*/];
277
376
  }
278
- }, err => reject(err));
279
- });
280
- }
281
- distinct(key, filter, options) {
282
- return ResolveIOServer.getMainDB().collection(this.collectionName).distinct(key, filter, options);
283
- }
284
- drop(options) {
285
- return ResolveIOServer.getMainDB().collection(this.collectionName).drop(options);
286
- }
287
- dropIndex(indexName, options) {
288
- return ResolveIOServer.getMainDB().collection(this.collectionName).dropIndex(indexName, options);
289
- }
290
- dropIndexes(options) {
291
- return ResolveIOServer.getMainDB().collection(this.collectionName).dropIndexes(options);
292
- }
293
- find(filter = {}, options, bypassLogs = false) {
294
- return new Promise((resolve, reject) => {
295
- if (this.createLogs && !bypassLogs) {
296
- Logs.insertOne({
377
+ });
378
+ }); });
379
+ };
380
+ Collection.prototype.distinct = function (key, filter, options) {
381
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).distinct(key, filter, options);
382
+ };
383
+ Collection.prototype.drop = function (options) {
384
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).drop(options);
385
+ };
386
+ Collection.prototype.dropIndex = function (indexName, options) {
387
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).dropIndex(indexName, options);
388
+ };
389
+ Collection.prototype.dropIndexes = function (options) {
390
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).dropIndexes(options);
391
+ };
392
+ Collection.prototype.find = function (filter, options, bypassLogs) {
393
+ var _this = this;
394
+ if (filter === void 0) { filter = {}; }
395
+ if (bypassLogs === void 0) { bypassLogs = false; }
396
+ return new Promise(function (resolve, reject) {
397
+ if (_this.createLogs && !bypassLogs) {
398
+ log_collection_1.Logs.insertOne({
297
399
  _id: objectIdHexString(),
298
400
  type: 'query',
299
- collection: this.collectionName,
401
+ collection: _this.collectionName,
300
402
  id_document: '',
301
- payload: getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
403
+ payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
302
404
  method: 'find',
303
405
  id_user: '',
304
406
  user: '',
@@ -306,14 +408,14 @@ export class Collection {
306
408
  route: ''
307
409
  });
308
410
  }
309
- ResolveIOServer.getMongoManager().addToQueue({
411
+ index_1.ResolveIOServer.getMongoManager().addToQueue({
310
412
  _id: 0,
311
- name_collection: this.collectionName,
413
+ name_collection: _this.collectionName,
312
414
  name_function: 'find',
313
415
  name_function_addt: 'toArray',
314
416
  data_function: [filter, options],
315
417
  data_function_addt: [],
316
- cbs: [(err, res) => {
418
+ cbs: [function (err, res) {
317
419
  if (err) {
318
420
  reject(err);
319
421
  }
@@ -325,18 +427,20 @@ export class Collection {
325
427
  running: false
326
428
  });
327
429
  });
328
- }
329
- findById(id, options) {
330
- return ResolveIOServer.getMainDB().collection(this.collectionName).findOne({ _id: id }, options);
331
- }
332
- findCount(filter = {}, options, bypassLogs = false) {
430
+ };
431
+ Collection.prototype.findById = function (id, options) {
432
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOne({ _id: id }, options);
433
+ };
434
+ Collection.prototype.findCount = function (filter, options, bypassLogs) {
435
+ if (filter === void 0) { filter = {}; }
436
+ if (bypassLogs === void 0) { bypassLogs = false; }
333
437
  if (this.createLogs && !bypassLogs) {
334
- Logs.insertOne({
438
+ log_collection_1.Logs.insertOne({
335
439
  _id: objectIdHexString(),
336
440
  type: 'query',
337
441
  collection: this.collectionName,
338
442
  id_document: '',
339
- payload: getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
443
+ payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
340
444
  method: 'findCount',
341
445
  id_user: '',
342
446
  user: '',
@@ -344,23 +448,28 @@ export class Collection {
344
448
  route: ''
345
449
  });
346
450
  }
347
- return ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).count();
348
- }
349
- findCursor(filter = {}, options) {
350
- return ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options);
351
- }
352
- findStream(filter = {}, options, streamOptions) {
353
- return ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).stream(streamOptions);
354
- }
355
- findOne(filter = {}, options, bypassLogs = false) {
356
- return new Promise((resolve, reject) => {
357
- if (this.createLogs && !bypassLogs) {
358
- Logs.insertOne({
451
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).count();
452
+ };
453
+ Collection.prototype.findCursor = function (filter, options) {
454
+ if (filter === void 0) { filter = {}; }
455
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options);
456
+ };
457
+ Collection.prototype.findStream = function (filter, options, streamOptions) {
458
+ if (filter === void 0) { filter = {}; }
459
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).find(filter, options).stream(streamOptions);
460
+ };
461
+ Collection.prototype.findOne = function (filter, options, bypassLogs) {
462
+ var _this = this;
463
+ if (filter === void 0) { filter = {}; }
464
+ if (bypassLogs === void 0) { bypassLogs = false; }
465
+ return new Promise(function (resolve, reject) {
466
+ if (_this.createLogs && !bypassLogs) {
467
+ log_collection_1.Logs.insertOne({
359
468
  _id: objectIdHexString(),
360
469
  type: 'query',
361
- collection: this.collectionName,
470
+ collection: _this.collectionName,
362
471
  id_document: '',
363
- payload: getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
472
+ payload: common_1.getBinarySize(JSON.stringify([filter, options])) < 200000 ? JSON.stringify([filter, options], null, 2) : 'Too Big',
364
473
  method: 'findOne',
365
474
  id_user: '',
366
475
  user: '',
@@ -368,14 +477,14 @@ export class Collection {
368
477
  route: ''
369
478
  });
370
479
  }
371
- ResolveIOServer.getMongoManager().addToQueue({
480
+ index_1.ResolveIOServer.getMongoManager().addToQueue({
372
481
  _id: 0,
373
- name_collection: this.collectionName,
482
+ name_collection: _this.collectionName,
374
483
  name_function: 'findOne',
375
484
  name_function_addt: '',
376
485
  data_function: [filter, options],
377
486
  data_function_addt: [],
378
- cbs: [(err, res) => {
487
+ cbs: [function (err, res) {
379
488
  if (err) {
380
489
  reject(err);
381
490
  }
@@ -387,158 +496,202 @@ export class Collection {
387
496
  running: false
388
497
  });
389
498
  });
390
- }
391
- findOneAndDelete(filter = {}, options, bypassLogs = false) {
392
- return new Promise(async (resolve, reject) => {
393
- if (this.createLogs && !bypassLogs) {
394
- let doc = await this.findOne(filter);
395
- if (doc) {
396
- Logs.insertOne({
397
- _id: objectIdHexString(),
398
- type: 'document',
399
- collection: this.collectionName,
400
- id_document: doc['_id'],
401
- payload: getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
402
- method: 'findOneAndDelete',
403
- id_user: '',
404
- user: '',
405
- messageId: '',
406
- route: ''
407
- });
408
- }
409
- }
410
- ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndDelete(filter, options).then(res => {
411
- if (res.ok) {
412
- resolve(res.value);
413
- }
414
- else {
415
- reject(res.lastErrorObject);
416
- }
417
- }, err => reject(err));
418
- });
419
- }
420
- findOneAndReplace(filter = {}, replacement, options, bypassLogs = false) {
421
- return new Promise(async (resolve, reject) => {
422
- const validation = this.simplschema.newContext().validate(replacement);
423
- if (!validation.isValid()) {
424
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
425
- ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);
426
- reject(validation.validationErrors());
427
- }
428
- else {
429
- if (this.timestamps) {
430
- replacement['updatedAt'] = new Date();
431
- }
432
- if (this.createLogs && !bypassLogs) {
433
- let doc = await this.findOne(filter);
434
- if (doc) {
435
- Logs.insertOne({
436
- _id: objectIdHexString(),
437
- type: 'document',
438
- collection: this.collectionName,
439
- id_document: doc['_id'],
440
- payload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
441
- method: 'findOneAndReplace',
442
- id_user: '',
443
- user: '',
444
- messageId: '',
445
- route: ''
446
- });
447
- }
499
+ };
500
+ Collection.prototype.findOneAndDelete = function (filter, options, bypassLogs) {
501
+ var _this = this;
502
+ if (filter === void 0) { filter = {}; }
503
+ if (bypassLogs === void 0) { bypassLogs = false; }
504
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
505
+ var doc;
506
+ return __generator(this, function (_a) {
507
+ switch (_a.label) {
508
+ case 0:
509
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 2];
510
+ return [4 /*yield*/, this.findOne(filter)];
511
+ case 1:
512
+ doc = _a.sent();
513
+ if (doc) {
514
+ log_collection_1.Logs.insertOne({
515
+ _id: objectIdHexString(),
516
+ type: 'document',
517
+ collection: this.collectionName,
518
+ id_document: doc['_id'],
519
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, options])) < 200000 ? JSON.stringify([doc, filter, options], null, 2) : 'Too Big',
520
+ method: 'findOneAndDelete',
521
+ id_user: '',
522
+ user: '',
523
+ messageId: '',
524
+ route: ''
525
+ });
526
+ }
527
+ _a.label = 2;
528
+ case 2:
529
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndDelete(filter, options).then(function (res) {
530
+ if (res.ok) {
531
+ resolve(res.value);
532
+ }
533
+ else {
534
+ reject(res.lastErrorObject);
535
+ }
536
+ }, function (err) { return reject(err); });
537
+ return [2 /*return*/];
448
538
  }
449
- ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(res => {
450
- if (res.ok) {
451
- resolve(res.value);
452
- }
453
- else {
454
- reject(res.lastErrorObject);
455
- }
456
- }, err => reject(err));
457
- }
458
- });
459
- }
460
- findOneAndUpdate(filter = {}, update, options, bypassLogs = false) {
461
- return new Promise(async (resolve, reject) => {
462
- const validation = this.simplschema.newContext().validate(update, { modifier: true });
463
- if (!validation.isValid()) {
464
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
465
- ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);
466
- reject(validation.validationErrors());
467
- }
468
- else {
469
- if (this.timestamps) {
470
- if (!update['$set']) {
471
- update['$set'] = { updatedAt: new Date() };
472
- }
473
- else {
474
- update['$set']['updatedAt'] = new Date();
475
- }
539
+ });
540
+ }); });
541
+ };
542
+ Collection.prototype.findOneAndReplace = function (filter, replacement, options, bypassLogs) {
543
+ var _this = this;
544
+ if (filter === void 0) { filter = {}; }
545
+ if (bypassLogs === void 0) { bypassLogs = false; }
546
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
547
+ var validation, isValid, doc;
548
+ return __generator(this, function (_a) {
549
+ switch (_a.label) {
550
+ case 0:
551
+ validation = this.simplschema.newContext();
552
+ isValid = validation.validate(replacement);
553
+ if (!!isValid) return [3 /*break*/, 1];
554
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
555
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);
556
+ reject(validation.validationErrors());
557
+ return [3 /*break*/, 4];
558
+ case 1:
559
+ if (this.timestamps) {
560
+ replacement['updatedAt'] = new Date();
561
+ }
562
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
563
+ return [4 /*yield*/, this.findOne(filter)];
564
+ case 2:
565
+ doc = _a.sent();
566
+ if (doc) {
567
+ log_collection_1.Logs.insertOne({
568
+ _id: objectIdHexString(),
569
+ type: 'document',
570
+ collection: this.collectionName,
571
+ id_document: doc['_id'],
572
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
573
+ method: 'findOneAndReplace',
574
+ id_user: '',
575
+ user: '',
576
+ messageId: '',
577
+ route: ''
578
+ });
579
+ }
580
+ _a.label = 3;
581
+ case 3:
582
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(function (res) {
583
+ if (res.ok) {
584
+ resolve(res.value);
585
+ }
586
+ else {
587
+ reject(res.lastErrorObject);
588
+ }
589
+ }, function (err) { return reject(err); });
590
+ _a.label = 4;
591
+ case 4: return [2 /*return*/];
476
592
  }
477
- if (this.createLogs && !bypassLogs) {
478
- let doc = await this.findOne(filter);
479
- if (doc) {
480
- Logs.insertOne({
481
- _id: objectIdHexString(),
482
- type: 'document',
483
- collection: this.collectionName,
484
- id_document: doc['_id'],
485
- payload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
486
- method: 'findOneAndUpdate',
487
- id_user: '',
488
- user: '',
489
- messageId: '',
490
- route: ''
491
- });
492
- }
593
+ });
594
+ }); });
595
+ };
596
+ Collection.prototype.findOneAndUpdate = function (filter, update, options, bypassLogs) {
597
+ var _this = this;
598
+ if (filter === void 0) { filter = {}; }
599
+ if (bypassLogs === void 0) { bypassLogs = false; }
600
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
601
+ var validation, isValid, doc;
602
+ return __generator(this, function (_a) {
603
+ switch (_a.label) {
604
+ case 0:
605
+ validation = this.simplschema.newContext();
606
+ isValid = validation.validate(update, { modifier: true });
607
+ if (!!isValid) return [3 /*break*/, 1];
608
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
609
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);
610
+ reject(validation.validationErrors());
611
+ return [3 /*break*/, 4];
612
+ case 1:
613
+ if (this.timestamps) {
614
+ if (!update['$set']) {
615
+ update['$set'] = { updatedAt: new Date() };
616
+ }
617
+ else {
618
+ update['$set']['updatedAt'] = new Date();
619
+ }
620
+ }
621
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
622
+ return [4 /*yield*/, this.findOne(filter)];
623
+ case 2:
624
+ doc = _a.sent();
625
+ if (doc) {
626
+ log_collection_1.Logs.insertOne({
627
+ _id: objectIdHexString(),
628
+ type: 'document',
629
+ collection: this.collectionName,
630
+ id_document: doc['_id'],
631
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
632
+ method: 'findOneAndUpdate',
633
+ id_user: '',
634
+ user: '',
635
+ messageId: '',
636
+ route: ''
637
+ });
638
+ }
639
+ _a.label = 3;
640
+ case 3:
641
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(function (res) {
642
+ if (res.ok) {
643
+ resolve(res.value);
644
+ }
645
+ else {
646
+ reject(res.lastErrorObject);
647
+ }
648
+ }, function (err) { return reject(err); });
649
+ _a.label = 4;
650
+ case 4: return [2 /*return*/];
493
651
  }
494
- ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(res => {
495
- if (res.ok) {
496
- resolve(res.value);
497
- }
498
- else {
499
- reject(res.lastErrorObject);
500
- }
501
- }, err => reject(err));
502
- }
503
- });
504
- }
505
- indexes(options) {
506
- return ResolveIOServer.getMainDB().collection(this.collectionName).indexes(options);
507
- }
508
- indexExists(indexes, options) {
509
- return ResolveIOServer.getMainDB().collection(this.collectionName).indexExists(indexes, options);
510
- }
511
- insertMany(docs, options, bypassLogs = false) {
512
- return new Promise((resolve, reject) => {
652
+ });
653
+ }); });
654
+ };
655
+ Collection.prototype.indexes = function (options) {
656
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).indexes(options);
657
+ };
658
+ Collection.prototype.indexExists = function (indexes, options) {
659
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).indexExists(indexes, options);
660
+ };
661
+ Collection.prototype.insertMany = function (docs, options, bypassLogs) {
662
+ var _this = this;
663
+ if (bypassLogs === void 0) { bypassLogs = false; }
664
+ return new Promise(function (resolve, reject) {
513
665
  if (!docs.length) {
514
666
  reject('No Documents');
515
667
  return;
516
668
  }
517
- let validationResults = [];
518
- docs.forEach(doc => {
519
- const validation = this.simplschema.newContext().validate(doc);
520
- if (!validation.isValid()) {
521
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
522
- ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertMany - ' + this.collectionName, [validation.validationErrors(), doc]);
669
+ var validationResults = [];
670
+ docs.forEach(function (doc) {
671
+ var validation = _this.simplschema.newContext();
672
+ var isValid = validation.validate(doc);
673
+ if (!isValid) {
674
+ console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
675
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertMany - ' + _this.collectionName, [validation.validationErrors(), doc]);
523
676
  validationResults.push(false);
524
677
  }
525
678
  else {
526
679
  validationResults.push(true);
527
680
  }
528
681
  });
529
- let validDocs = docs.filter((a, idx) => validationResults[idx]);
530
- validDocs.forEach(doc => {
531
- if (this.timestamps) {
682
+ var validDocs = docs.filter(function (a, idx) { return validationResults[idx]; });
683
+ validDocs.forEach(function (doc) {
684
+ if (_this.timestamps) {
532
685
  doc['createdAt'] = new Date();
533
686
  doc['updatedAt'] = new Date();
534
687
  }
535
- if (this.createLogs && !bypassLogs) {
536
- Logs.insertOne({
688
+ if (_this.createLogs && !bypassLogs) {
689
+ log_collection_1.Logs.insertOne({
537
690
  _id: objectIdHexString(),
538
691
  type: 'document',
539
- collection: this.collectionName,
692
+ collection: _this.collectionName,
540
693
  id_document: doc['_id'],
541
- payload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
694
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
542
695
  method: 'insertMany',
543
696
  id_user: '',
544
697
  user: '',
@@ -548,39 +701,42 @@ export class Collection {
548
701
  }
549
702
  });
550
703
  if (validDocs.length) {
551
- ResolveIOServer.getMainDB().collection(this.collectionName).insertMany(validDocs, options).then(res => {
704
+ index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).insertMany(validDocs, options).then(function (res) {
552
705
  if (res.result.ok) {
553
706
  resolve(validDocs);
554
707
  }
555
708
  else {
556
709
  reject(res.result.ok);
557
710
  }
558
- }, err => {
711
+ }, function (err) {
559
712
  reject(err);
560
713
  });
561
714
  }
562
715
  });
563
- }
564
- insertOne(doc, options, bypassLogs = false) {
565
- return new Promise((resolve, reject) => {
566
- const validation = this.simplschema.newContext().validate(doc);
567
- if (!validation.isValid()) {
568
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
569
- ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertOne - ' + this.collectionName, [validation.validationErrors(), doc]);
716
+ };
717
+ Collection.prototype.insertOne = function (doc, options, bypassLogs) {
718
+ var _this = this;
719
+ if (bypassLogs === void 0) { bypassLogs = false; }
720
+ return new Promise(function (resolve, reject) {
721
+ var validation = _this.simplschema.newContext();
722
+ var isValid = validation.validate(doc);
723
+ if (!isValid) {
724
+ console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
725
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertOne - ' + _this.collectionName, [validation.validationErrors(), doc]);
570
726
  reject(validation.validationErrors());
571
727
  }
572
728
  else {
573
- if (this.timestamps) {
729
+ if (_this.timestamps) {
574
730
  doc['createdAt'] = new Date();
575
731
  doc['updatedAt'] = new Date();
576
732
  }
577
- if (this.createLogs && !bypassLogs) {
578
- Logs.insertOne({
733
+ if (_this.createLogs && !bypassLogs) {
734
+ log_collection_1.Logs.insertOne({
579
735
  _id: objectIdHexString(),
580
736
  type: 'document',
581
- collection: this.collectionName,
737
+ collection: _this.collectionName,
582
738
  id_document: doc['_id'],
583
- payload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
739
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
584
740
  method: 'insertOne',
585
741
  id_user: '',
586
742
  user: '',
@@ -588,50 +744,60 @@ export class Collection {
588
744
  route: ''
589
745
  });
590
746
  }
591
- ResolveIOServer.getMainDB().collection(this.collectionName).insertOne(doc, options).then(res => {
747
+ index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).insertOne(doc, options).then(function (res) {
592
748
  if (res.result.ok) {
593
749
  resolve(doc);
594
750
  }
595
751
  else {
596
752
  reject(res.result.ok);
597
753
  }
598
- }, err => {
754
+ }, function (err) {
599
755
  reject(err);
600
756
  });
601
757
  }
602
758
  });
603
- }
604
- listIndexes(options) {
605
- return ResolveIOServer.getMainDB().collection(this.collectionName).listIndexes(options);
606
- }
607
- reIndex(options) {
608
- return ResolveIOServer.getMainDB().collection(this.collectionName).reIndex(options);
609
- }
610
- rename(newName, options) {
611
- return ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
612
- }
613
- replaceOne(filter, replacement, options, bypassLogs = false, bypassDocument = false) {
614
- return new Promise(async (resolve, reject) => {
615
- const validation = this.simplschema.newContext().validate(replacement);
616
- if (!validation.isValid()) {
617
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
618
- ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on replaceOne - ' + this.collectionName, [validation.validationErrors(), replacement]);
619
- reject(validation.validationErrors());
620
- }
621
- else {
622
- if (this.timestamps) {
623
- replacement['updatedAt'] = new Date();
624
- }
625
- if (!bypassDocument) {
626
- let doc = await this.findOne(filter);
627
- if (doc) {
759
+ };
760
+ Collection.prototype.listIndexes = function (options) {
761
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).listIndexes(options);
762
+ };
763
+ Collection.prototype.reIndex = function (options) {
764
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).reIndex(options);
765
+ };
766
+ Collection.prototype.rename = function (newName, options) {
767
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
768
+ };
769
+ Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, bypassDocument) {
770
+ var _this = this;
771
+ if (bypassLogs === void 0) { bypassLogs = false; }
772
+ if (bypassDocument === void 0) { bypassDocument = false; }
773
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
774
+ var validation, isValid, doc, versionDoc, prevDoc, docId, docVersion, updatedDoc;
775
+ return __generator(this, function (_a) {
776
+ switch (_a.label) {
777
+ case 0:
778
+ validation = this.simplschema.newContext();
779
+ isValid = validation.validate(replacement);
780
+ if (!!isValid) return [3 /*break*/, 1];
781
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
782
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on replaceOne - ' + this.collectionName, [validation.validationErrors(), replacement]);
783
+ reject(validation.validationErrors());
784
+ return [3 /*break*/, 11];
785
+ case 1:
786
+ if (this.timestamps) {
787
+ replacement['updatedAt'] = new Date();
788
+ }
789
+ if (!!bypassDocument) return [3 /*break*/, 10];
790
+ return [4 /*yield*/, this.findOne(filter)];
791
+ case 2:
792
+ doc = _a.sent();
793
+ if (!doc) return [3 /*break*/, 8];
628
794
  if (this.createLogs && !bypassLogs) {
629
- Logs.insertOne({
795
+ log_collection_1.Logs.insertOne({
630
796
  _id: objectIdHexString(),
631
797
  type: 'document',
632
798
  collection: this.collectionName,
633
799
  id_document: doc['_id'],
634
- payload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
800
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
635
801
  method: 'replaceOne',
636
802
  id_user: '',
637
803
  user: '',
@@ -639,402 +805,505 @@ export class Collection {
639
805
  route: ''
640
806
  });
641
807
  }
642
- if (this.useVersions) {
643
- let versionDoc = deepCopy(doc);
644
- versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
645
- ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
646
- if (doc['__v'] >= 4) {
647
- ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [
648
- { '_id._id': doc['_id'] },
649
- { '_id.__v': { $lte: doc['__v'] - 4 } }
650
- ] });
651
- }
652
- if (doc['__v'] === replacement['__v']) {
653
- replacement['__v'] += 1;
654
- ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(res => {
655
- if (res.result.ok) {
656
- resolve(res.result.nModified);
657
- }
658
- else {
659
- reject(res.result.ok);
660
- }
661
- }, err => {
662
- reject(err);
663
- });
808
+ if (!this.useVersions) return [3 /*break*/, 6];
809
+ versionDoc = common_1.deepCopy(doc);
810
+ versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
811
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
812
+ if (doc['__v'] >= 4) {
813
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [
814
+ { '_id._id': doc['_id'] },
815
+ { '_id.__v': { $lte: doc['__v'] - 4 } }
816
+ ] });
817
+ }
818
+ if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 3];
819
+ replacement['__v'] += 1;
820
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
821
+ if (res.result.ok) {
822
+ resolve(res.result.nModified);
664
823
  }
665
824
  else {
666
- console.log('invalid version - ' + this.collectionName, doc['__v'], replacement['__v']);
667
- let prevDoc = await ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({
668
- $and: [
669
- { '_id._id': doc['_id'] },
670
- { '_id.__v': replacement['__v'] }
671
- ]
672
- });
673
- if (prevDoc) {
674
- let docId = doc['_id'];
675
- let docVersion = doc['__v'];
676
- let updatedDoc = getMongoMergeUpdatedDoc(replacement, doc, prevDoc);
677
- updatedDoc['_id'] = docId;
678
- updatedDoc['__v'] = docVersion + 1;
679
- updatedDoc['updatedAt'] = new Date();
680
- ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, updatedDoc, options).then(res => {
681
- if (res.result.ok) {
682
- resolve(res.result.nModified);
683
- }
684
- else {
685
- reject(res.result.ok);
686
- }
687
- }, err => {
688
- reject(err);
689
- });
690
- }
691
- else {
692
- reject('Invalid Version And Could Not Find History - DB: ' + doc['__v'] + ', Trying to update with :' + replacement['__v']);
693
- }
825
+ reject(res.result.ok);
694
826
  }
695
- }
696
- else {
697
- ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(res => {
827
+ }, function (err) {
828
+ reject(err);
829
+ });
830
+ return [3 /*break*/, 5];
831
+ case 3:
832
+ console.log('invalid version - ' + this.collectionName, doc['__v'], replacement['__v']);
833
+ return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({
834
+ $and: [
835
+ { '_id._id': doc['_id'] },
836
+ { '_id.__v': replacement['__v'] }
837
+ ]
838
+ })];
839
+ case 4:
840
+ prevDoc = _a.sent();
841
+ if (prevDoc) {
842
+ docId = doc['_id'];
843
+ docVersion = doc['__v'];
844
+ updatedDoc = common_1.getMongoMergeUpdatedDoc(replacement, doc, prevDoc);
845
+ updatedDoc['_id'] = docId;
846
+ updatedDoc['__v'] = docVersion + 1;
847
+ updatedDoc['updatedAt'] = new Date();
848
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, updatedDoc, options).then(function (res) {
698
849
  if (res.result.ok) {
699
850
  resolve(res.result.nModified);
700
851
  }
701
852
  else {
702
853
  reject(res.result.ok);
703
854
  }
704
- }, err => {
855
+ }, function (err) {
705
856
  reject(err);
706
857
  });
707
858
  }
708
- }
709
- else {
710
- reject('No Document');
711
- }
712
- }
713
- else {
714
- ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(res => {
715
- if (res.result.ok) {
716
- resolve(res.result.nModified);
717
- }
718
859
  else {
719
- reject(res.result.ok);
720
- }
721
- }, err => {
722
- reject(err);
723
- });
724
- }
725
- }
726
- });
727
- }
728
- stats(options) {
729
- return ResolveIOServer.getMainDB().collection(this.collectionName).stats(options);
730
- }
731
- updateMany(filter, update, options, bypassLogs = false) {
732
- return new Promise(async (resolve, reject) => {
733
- if (this.timestamps) {
734
- if (!update.$set) {
735
- update.$set = { updatedAt: new Date() };
736
- }
737
- else {
738
- update.$set['updatedAt'] = new Date();
739
- }
740
- }
741
- const validation = this.simplschema.newContext().validate(update, { modifier: true });
742
- if (!validation.isValid()) {
743
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
744
- ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateMany - ' + this.collectionName, [validation.validationErrors(), update]);
745
- reject(validation.validationErrors());
746
- }
747
- else {
748
- if (this.createLogs && !bypassLogs) {
749
- let docs = await this.find(filter);
750
- docs.forEach(doc => {
751
- Logs.insertOne({
752
- _id: objectIdHexString(),
753
- type: 'document',
754
- collection: this.collectionName,
755
- id_document: doc['_id'],
756
- payload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
757
- method: 'updateMany',
758
- id_user: '',
759
- user: '',
760
- messageId: '',
761
- route: ''
762
- });
763
- });
764
- }
765
- ResolveIOServer.getMainDB().collection(this.collectionName).updateMany(filter, update, options).then(res => {
766
- if (res.result.ok) {
767
- resolve(res.result.nModified);
768
- }
769
- else {
770
- reject(res.result.ok);
771
- }
772
- }, err => reject(err));
773
- }
774
- });
775
- }
776
- updateOne(filter, update, options, bypassLogs = false) {
777
- return new Promise(async (resolve, reject) => {
778
- if (this.timestamps) {
779
- if (!update.$set) {
780
- update.$set = { updatedAt: new Date() };
781
- }
782
- else {
783
- update.$set['updatedAt'] = new Date();
784
- }
785
- }
786
- const validation = this.simplschema.newContext().validate(update, { modifier: true });
787
- if (!validation.isValid()) {
788
- console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
789
- ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateOne - ' + this.collectionName, [validation.validationErrors(), update]);
790
- reject(validation.validationErrors());
791
- }
792
- else {
793
- let doc = await this.findOne(filter);
794
- if (doc) {
795
- if (this.createLogs && !bypassLogs) {
796
- Logs.insertOne({
797
- _id: objectIdHexString(),
798
- type: 'document',
799
- collection: this.collectionName,
800
- id_document: doc['_id'],
801
- payload: getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
802
- method: 'updateOne',
803
- id_user: '',
804
- user: '',
805
- messageId: '',
806
- route: ''
807
- });
808
- }
809
- if (this.useVersions) {
810
- let versionDoc = deepCopy(doc);
811
- versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
812
- ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
813
- if (doc['__v'] >= 4) {
814
- ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [
815
- { '_id._id': doc['_id'] },
816
- { '_id.__v': { $lte: doc['__v'] - 4 } }
817
- ] });
860
+ reject('Invalid Version And Could Not Find History - DB: ' + doc['__v'] + ', Trying to update with :' + replacement['__v']);
818
861
  }
819
- if (!update.$inc) {
820
- update.$inc = { __v: 1 };
821
- }
822
- else if (!update.$inc.__v) {
823
- update.$inc.__v = 1;
824
- }
825
- ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(res => {
862
+ _a.label = 5;
863
+ case 5: return [3 /*break*/, 7];
864
+ case 6:
865
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
826
866
  if (res.result.ok) {
827
867
  resolve(res.result.nModified);
828
868
  }
829
869
  else {
830
870
  reject(res.result.ok);
831
871
  }
832
- }, err => reject(err));
833
- }
834
- else {
835
- ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(res => {
872
+ }, function (err) {
873
+ reject(err);
874
+ });
875
+ _a.label = 7;
876
+ case 7: return [3 /*break*/, 9];
877
+ case 8:
878
+ reject('No Document');
879
+ _a.label = 9;
880
+ case 9: return [3 /*break*/, 11];
881
+ case 10:
882
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
836
883
  if (res.result.ok) {
837
884
  resolve(res.result.nModified);
838
885
  }
839
886
  else {
840
887
  reject(res.result.ok);
841
888
  }
842
- }, err => reject(err));
843
- }
844
- }
845
- else {
846
- reject('No Document');
889
+ }, function (err) {
890
+ reject(err);
891
+ });
892
+ _a.label = 11;
893
+ case 11: return [2 /*return*/];
847
894
  }
848
- }
849
- });
850
- }
851
- watchCollection(pipeline = [], options) {
852
- return ResolveIOServer.getMainDB().collection(this.collectionName).watch(pipeline, options);
853
- }
854
- watchCollectionWithAggregate(pipeline = [], options) {
855
- return ResolveIOServer.getMainDB().collection(this.collectionName).watch(pipeline, options);
856
- }
857
- }
858
- export class UserCollection extends Collection {
859
- authenticateStrategy() {
860
- return async (username, password, cb) => {
861
- let user = await Users.findOne({ username: username });
862
- this.authenticate(user, password).then(authUser => {
863
- if (authUser.data) {
864
- cb(null, user, null);
895
+ });
896
+ }); });
897
+ };
898
+ Collection.prototype.stats = function (options) {
899
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).stats(options);
900
+ };
901
+ Collection.prototype.updateMany = function (filter, update, options, bypassLogs) {
902
+ var _this = this;
903
+ if (bypassLogs === void 0) { bypassLogs = false; }
904
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
905
+ var validation, isValid, docs;
906
+ var _this = this;
907
+ return __generator(this, function (_a) {
908
+ switch (_a.label) {
909
+ case 0:
910
+ if (this.timestamps) {
911
+ if (!update.$set) {
912
+ update.$set = { updatedAt: new Date() };
913
+ }
914
+ else {
915
+ update.$set['updatedAt'] = new Date();
916
+ }
917
+ }
918
+ validation = this.simplschema.newContext();
919
+ isValid = validation.validate(update, { modifier: true });
920
+ if (!!isValid) return [3 /*break*/, 1];
921
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
922
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateMany - ' + this.collectionName, [validation.validationErrors(), update]);
923
+ reject(validation.validationErrors());
924
+ return [3 /*break*/, 4];
925
+ case 1:
926
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
927
+ return [4 /*yield*/, this.find(filter)];
928
+ case 2:
929
+ docs = _a.sent();
930
+ docs.forEach(function (doc) {
931
+ log_collection_1.Logs.insertOne({
932
+ _id: objectIdHexString(),
933
+ type: 'document',
934
+ collection: _this.collectionName,
935
+ id_document: doc['_id'],
936
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
937
+ method: 'updateMany',
938
+ id_user: '',
939
+ user: '',
940
+ messageId: '',
941
+ route: ''
942
+ });
943
+ });
944
+ _a.label = 3;
945
+ case 3:
946
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateMany(filter, update, options).then(function (res) {
947
+ if (res.result.ok) {
948
+ resolve(res.result.nModified);
949
+ }
950
+ else {
951
+ reject(res.result.ok);
952
+ }
953
+ }, function (err) { return reject(err); });
954
+ _a.label = 4;
955
+ case 4: return [2 /*return*/];
865
956
  }
866
- else {
867
- cb(null, null, authUser.error);
957
+ });
958
+ }); });
959
+ };
960
+ Collection.prototype.updateOne = function (filter, update, options, bypassLogs) {
961
+ var _this = this;
962
+ if (bypassLogs === void 0) { bypassLogs = false; }
963
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
964
+ var validation, isValid, doc, versionDoc;
965
+ return __generator(this, function (_a) {
966
+ switch (_a.label) {
967
+ case 0:
968
+ if (this.timestamps) {
969
+ if (!update.$set) {
970
+ update.$set = { updatedAt: new Date() };
971
+ }
972
+ else {
973
+ update.$set['updatedAt'] = new Date();
974
+ }
975
+ }
976
+ validation = this.simplschema.newContext();
977
+ isValid = validation.validate(update, { modifier: true });
978
+ if (!!isValid) return [3 /*break*/, 1];
979
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
980
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateOne - ' + this.collectionName, [validation.validationErrors(), update]);
981
+ reject(validation.validationErrors());
982
+ return [3 /*break*/, 3];
983
+ case 1: return [4 /*yield*/, this.findOne(filter)];
984
+ case 2:
985
+ doc = _a.sent();
986
+ if (doc) {
987
+ if (this.createLogs && !bypassLogs) {
988
+ log_collection_1.Logs.insertOne({
989
+ _id: objectIdHexString(),
990
+ type: 'document',
991
+ collection: this.collectionName,
992
+ id_document: doc['_id'],
993
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
994
+ method: 'updateOne',
995
+ id_user: '',
996
+ user: '',
997
+ messageId: '',
998
+ route: ''
999
+ });
1000
+ }
1001
+ if (this.useVersions) {
1002
+ versionDoc = common_1.deepCopy(doc);
1003
+ versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
1004
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
1005
+ if (doc['__v'] >= 4) {
1006
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [
1007
+ { '_id._id': doc['_id'] },
1008
+ { '_id.__v': { $lte: doc['__v'] - 4 } }
1009
+ ] });
1010
+ }
1011
+ if (!update.$inc) {
1012
+ update.$inc = { __v: 1 };
1013
+ }
1014
+ else if (!update.$inc.__v) {
1015
+ update.$inc.__v = 1;
1016
+ }
1017
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
1018
+ if (res.result.ok) {
1019
+ resolve(res.result.nModified);
1020
+ }
1021
+ else {
1022
+ reject(res.result.ok);
1023
+ }
1024
+ }, function (err) { return reject(err); });
1025
+ }
1026
+ else {
1027
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
1028
+ if (res.result.ok) {
1029
+ resolve(res.result.nModified);
1030
+ }
1031
+ else {
1032
+ reject(res.result.ok);
1033
+ }
1034
+ }, function (err) { return reject(err); });
1035
+ }
1036
+ }
1037
+ else {
1038
+ reject('No Document');
1039
+ }
1040
+ _a.label = 3;
1041
+ case 3: return [2 /*return*/];
868
1042
  }
869
- }, err => {
870
- cb(err, null, null);
871
1043
  });
872
- };
1044
+ }); });
1045
+ };
1046
+ Collection.prototype.watchCollection = function (pipeline, options) {
1047
+ if (pipeline === void 0) { pipeline = []; }
1048
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).watch(pipeline, options);
1049
+ };
1050
+ Collection.prototype.watchCollectionWithAggregate = function (pipeline, options) {
1051
+ if (pipeline === void 0) { pipeline = []; }
1052
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).watch(pipeline, options);
1053
+ };
1054
+ return Collection;
1055
+ }());
1056
+ exports.Collection = Collection;
1057
+ var UserCollection = /** @class */ (function (_super) {
1058
+ __extends(UserCollection, _super);
1059
+ function UserCollection() {
1060
+ return _super !== null && _super.apply(this, arguments) || this;
873
1061
  }
874
- authenticate(user, password) {
875
- return new Promise(async (resolve, reject) => {
876
- const attemptsInterval = Math.pow(100, Math.log(user.attempts + 1));
877
- const calculatedInterval = attemptsInterval < 300000 ? attemptsInterval : 300000;
878
- if (user.last) {
879
- if (Date.now() - user.last.getTime() < calculatedInterval) {
880
- user.last = new Date();
881
- await Users.updateOne({ _id: user._id }, { $set: { last: user.last } });
882
- resolve({
883
- data: null,
884
- error: 'Attempt Too Soon'
885
- });
886
- return;
887
- }
888
- }
889
- else {
890
- user.last = new Date();
891
- }
892
- if (user.attempts >= 5) {
893
- resolve({
894
- data: null,
895
- error: 'Too Many Attempts'
896
- });
897
- return;
898
- }
899
- if (!user.salt) {
900
- resolve({
901
- data: null,
902
- error: 'No Salt Value Stored'
903
- });
904
- return;
905
- }
906
- pbkdf2(password, user.salt, {
907
- iterations: 25000,
908
- keylen: 512,
909
- digestAlgorithm: 'sha256'
910
- }, async (err, hashBuffer) => {
911
- if (err) {
912
- return reject(err);
913
- }
914
- if (scmp(hashBuffer, Buffer.from(user.hash, 'hex'))) {
915
- user.last = new Date();
916
- user.attempts = 0;
917
- await Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } });
918
- resolve({
919
- data: user,
920
- error: ''
921
- });
922
- }
923
- else {
924
- user.last = new Date();
925
- user.attempts = user.attempts + 1;
926
- await Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } });
927
- if (user.attempts >= 5) {
928
- resolve({
929
- data: null,
930
- error: 'Too Many Attempts'
1062
+ UserCollection.prototype.authenticateStrategy = function () {
1063
+ var _this = this;
1064
+ return function (username, password, cb) { return __awaiter(_this, void 0, void 0, function () {
1065
+ var user;
1066
+ return __generator(this, function (_a) {
1067
+ switch (_a.label) {
1068
+ case 0: return [4 /*yield*/, user_collection_1.Users.findOne({ username: username })];
1069
+ case 1:
1070
+ user = _a.sent();
1071
+ this.authenticate(user, password).then(function (authUser) {
1072
+ if (authUser.data) {
1073
+ cb(null, user, null);
1074
+ }
1075
+ else {
1076
+ cb(null, null, authUser.error);
1077
+ }
1078
+ }, function (err) {
1079
+ cb(err, null, null);
931
1080
  });
932
- }
933
- else {
1081
+ return [2 /*return*/];
1082
+ }
1083
+ });
1084
+ }); };
1085
+ };
1086
+ UserCollection.prototype.authenticate = function (user, password) {
1087
+ var _this = this;
1088
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1089
+ var attemptsInterval, calculatedInterval;
1090
+ var _this = this;
1091
+ return __generator(this, function (_a) {
1092
+ switch (_a.label) {
1093
+ case 0:
1094
+ attemptsInterval = Math.pow(100, Math.log(user.attempts + 1));
1095
+ calculatedInterval = attemptsInterval < 300000 ? attemptsInterval : 300000;
1096
+ if (!user.last) return [3 /*break*/, 3];
1097
+ if (!(Date.now() - user.last.getTime() < calculatedInterval)) return [3 /*break*/, 2];
1098
+ user.last = new Date();
1099
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last } })];
1100
+ case 1:
1101
+ _a.sent();
934
1102
  resolve({
935
1103
  data: null,
936
- error: 'Invalid Username And Password'
1104
+ error: 'Attempt Too Soon'
937
1105
  });
938
- }
1106
+ return [2 /*return*/];
1107
+ case 2: return [3 /*break*/, 4];
1108
+ case 3:
1109
+ user.last = new Date();
1110
+ _a.label = 4;
1111
+ case 4:
1112
+ if (user.attempts >= 5) {
1113
+ resolve({
1114
+ data: null,
1115
+ error: 'Too Many Attempts'
1116
+ });
1117
+ return [2 /*return*/];
1118
+ }
1119
+ if (!user.salt) {
1120
+ resolve({
1121
+ data: null,
1122
+ error: 'No Salt Value Stored'
1123
+ });
1124
+ return [2 /*return*/];
1125
+ }
1126
+ pbkdf2(password, user.salt, {
1127
+ iterations: 25000,
1128
+ keylen: 512,
1129
+ digestAlgorithm: 'sha256'
1130
+ }, function (err, hashBuffer) { return __awaiter(_this, void 0, void 0, function () {
1131
+ return __generator(this, function (_a) {
1132
+ switch (_a.label) {
1133
+ case 0:
1134
+ if (err) {
1135
+ return [2 /*return*/, reject(err)];
1136
+ }
1137
+ if (!scmp(hashBuffer, Buffer.from(user.hash, 'hex'))) return [3 /*break*/, 2];
1138
+ user.last = new Date();
1139
+ user.attempts = 0;
1140
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
1141
+ case 1:
1142
+ _a.sent();
1143
+ resolve({
1144
+ data: user,
1145
+ error: ''
1146
+ });
1147
+ return [3 /*break*/, 4];
1148
+ case 2:
1149
+ user.last = new Date();
1150
+ user.attempts = user.attempts + 1;
1151
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
1152
+ case 3:
1153
+ _a.sent();
1154
+ if (user.attempts >= 5) {
1155
+ resolve({
1156
+ data: null,
1157
+ error: 'Too Many Attempts'
1158
+ });
1159
+ }
1160
+ else {
1161
+ resolve({
1162
+ data: null,
1163
+ error: 'Invalid Username And Password'
1164
+ });
1165
+ }
1166
+ _a.label = 4;
1167
+ case 4: return [2 /*return*/];
1168
+ }
1169
+ });
1170
+ }); });
1171
+ return [2 /*return*/];
939
1172
  }
940
1173
  });
941
- });
942
- }
943
- serializeUser() {
944
- return (user, cb) => {
1174
+ }); });
1175
+ };
1176
+ UserCollection.prototype.serializeUser = function () {
1177
+ return function (user, cb) {
945
1178
  cb(null, user.username);
946
1179
  };
947
- }
948
- deserializeUser() {
949
- return (username, cb) => {
950
- Users.findOne({ username: username }).then(res => {
1180
+ };
1181
+ UserCollection.prototype.deserializeUser = function () {
1182
+ return function (username, cb) {
1183
+ user_collection_1.Users.findOne({ username: username }).then(function (res) {
951
1184
  cb(null, res);
952
- }, err => {
1185
+ }, function (err) {
953
1186
  cb(err, null);
954
1187
  });
955
1188
  };
956
- }
957
- setPassword(user, password) {
958
- return new Promise(async (resolve, reject) => {
959
- if (!user) {
960
- reject('No User');
961
- }
962
- else if (!password) {
963
- reject('No Password');
964
- }
965
- else {
966
- let saltBuffer = await randomBytes(32);
967
- let salt = saltBuffer.toString('hex');
968
- let hashRaw = await pbkdf2Promisified(password, salt, {
969
- iterations: 25000,
970
- keylen: 512,
971
- digestAlgorithm: 'sha256'
972
- });
973
- let hash = Buffer.from(hashRaw, 'binary').toString('hex');
974
- await Users.updateOne({ _id: user._id }, { $set: { hash: hash, salt: salt, services: {} } });
975
- }
976
- });
977
- }
978
- ;
979
- changePassword(user, oldPassword, newPassword) {
980
- return new Promise(async (resolve, reject) => {
981
- if (!user) {
982
- reject('Missing User');
983
- }
984
- else if (!oldPassword || !newPassword) {
985
- reject('Missing Password');
986
- }
987
- else {
988
- let authUser = await this.authenticate(user, oldPassword);
989
- if (!authUser['data']) {
990
- reject(authUser['error']);
991
- }
992
- else {
993
- this.setPassword(user, newPassword);
1189
+ };
1190
+ UserCollection.prototype.setPassword = function (user, password) {
1191
+ var _this = this;
1192
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1193
+ var saltBuffer, salt, hashRaw, hash;
1194
+ return __generator(this, function (_a) {
1195
+ switch (_a.label) {
1196
+ case 0:
1197
+ if (!!user) return [3 /*break*/, 1];
1198
+ reject('No User');
1199
+ return [3 /*break*/, 6];
1200
+ case 1:
1201
+ if (!!password) return [3 /*break*/, 2];
1202
+ reject('No Password');
1203
+ return [3 /*break*/, 6];
1204
+ case 2: return [4 /*yield*/, randomBytes(32)];
1205
+ case 3:
1206
+ saltBuffer = _a.sent();
1207
+ salt = saltBuffer.toString('hex');
1208
+ return [4 /*yield*/, pbkdf2Promisified(password, salt, {
1209
+ iterations: 25000,
1210
+ keylen: 512,
1211
+ digestAlgorithm: 'sha256'
1212
+ })];
1213
+ case 4:
1214
+ hashRaw = _a.sent();
1215
+ hash = Buffer.from(hashRaw, 'binary').toString('hex');
1216
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { hash: hash, salt: salt, services: {} } })];
1217
+ case 5:
1218
+ _a.sent();
1219
+ _a.label = 6;
1220
+ case 6: return [2 /*return*/];
994
1221
  }
995
- }
996
- });
997
- }
998
- register(user, password) {
999
- return new Promise(async (resolve, reject) => {
1000
- if (!user.username) {
1001
- reject('Missing Username');
1002
- }
1003
- else {
1004
- let dbUser = await Users.findOne({ username: user.username });
1005
- if (dbUser) {
1006
- reject('Username Exists');
1222
+ });
1223
+ }); });
1224
+ };
1225
+ ;
1226
+ UserCollection.prototype.changePassword = function (user, oldPassword, newPassword) {
1227
+ var _this = this;
1228
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1229
+ var authUser;
1230
+ return __generator(this, function (_a) {
1231
+ switch (_a.label) {
1232
+ case 0:
1233
+ if (!!user) return [3 /*break*/, 1];
1234
+ reject('Missing User');
1235
+ return [3 /*break*/, 4];
1236
+ case 1:
1237
+ if (!(!oldPassword || !newPassword)) return [3 /*break*/, 2];
1238
+ reject('Missing Password');
1239
+ return [3 /*break*/, 4];
1240
+ case 2: return [4 /*yield*/, this.authenticate(user, oldPassword)];
1241
+ case 3:
1242
+ authUser = _a.sent();
1243
+ if (!authUser['data']) {
1244
+ reject(authUser['error']);
1245
+ }
1246
+ else {
1247
+ this.setPassword(user, newPassword);
1248
+ }
1249
+ _a.label = 4;
1250
+ case 4: return [2 /*return*/];
1007
1251
  }
1008
- else {
1009
- dbUser = await Users.findOne({ email: user.email });
1010
- if (dbUser) {
1011
- reject('Email Exists');
1012
- }
1013
- else {
1014
- user.setPassword(password);
1015
- resolve(user);
1016
- }
1252
+ });
1253
+ }); });
1254
+ };
1255
+ UserCollection.prototype.register = function (user, password) {
1256
+ var _this = this;
1257
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1258
+ var dbUser;
1259
+ return __generator(this, function (_a) {
1260
+ switch (_a.label) {
1261
+ case 0:
1262
+ if (!!user.username) return [3 /*break*/, 1];
1263
+ reject('Missing Username');
1264
+ return [3 /*break*/, 5];
1265
+ case 1: return [4 /*yield*/, user_collection_1.Users.findOne({ username: user.username })];
1266
+ case 2:
1267
+ dbUser = _a.sent();
1268
+ if (!dbUser) return [3 /*break*/, 3];
1269
+ reject('Username Exists');
1270
+ return [3 /*break*/, 5];
1271
+ case 3: return [4 /*yield*/, user_collection_1.Users.findOne({ email: user.email })];
1272
+ case 4:
1273
+ dbUser = _a.sent();
1274
+ if (dbUser) {
1275
+ reject('Email Exists');
1276
+ }
1277
+ else {
1278
+ user.setPassword(password);
1279
+ resolve(user);
1280
+ }
1281
+ _a.label = 5;
1282
+ case 5: return [2 /*return*/];
1017
1283
  }
1018
- }
1019
- });
1020
- }
1021
- resetAttempts(user) {
1022
- return Users.updateOne({ _id: user._id }, { $set: { attempts: 0 } });
1023
- }
1024
- }
1025
- export function objectIdHexString() {
1026
- let objectId = new ObjectId();
1284
+ });
1285
+ }); });
1286
+ };
1287
+ UserCollection.prototype.resetAttempts = function (user) {
1288
+ return user_collection_1.Users.updateOne({ _id: user._id }, { $set: { attempts: 0 } });
1289
+ };
1290
+ return UserCollection;
1291
+ }(Collection));
1292
+ exports.UserCollection = UserCollection;
1293
+ function objectIdHexString() {
1294
+ var objectId = new mongodb_1.ObjectId();
1027
1295
  return objectId.toHexString();
1028
1296
  }
1297
+ exports.objectIdHexString = objectIdHexString;
1029
1298
  function pbkdf2(password, salt, options, callback) {
1030
1299
  crypto.pbkdf2(password, salt, options.iterations, options.keylen, options.digestAlgorithm, callback);
1031
1300
  }
1032
1301
  ;
1033
1302
  function pbkdf2Promisified(password, salt, options) {
1034
- return new Promise((resolve, reject) => pbkdf2(password, salt, options, (err, hashRaw) => (err ? reject(err) : resolve(hashRaw))));
1303
+ return new Promise(function (resolve, reject) { return pbkdf2(password, salt, options, function (err, hashRaw) { return (err ? reject(err) : resolve(hashRaw)); }); });
1035
1304
  }
1036
1305
  function randomBytes(saltlen) {
1037
- return new Promise((resolve, reject) => crypto.randomBytes(saltlen, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer))));
1306
+ return new Promise(function (resolve, reject) { return crypto.randomBytes(saltlen, function (err, saltBuffer) { return (err ? reject(err) : resolve(saltBuffer)); }); });
1038
1307
  }
1039
1308
 
1040
1309
  //# sourceMappingURL=mongo.manager.js.map