@resolveio/server-lib 9.0.34 → 9.0.35

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 +1001 -739
  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,199 @@ 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, doc;
548
+ return __generator(this, function (_a) {
549
+ switch (_a.label) {
550
+ case 0:
551
+ validation = this.simplschema.newContext().validate(replacement);
552
+ if (!!validation.isValid()) return [3 /*break*/, 1];
553
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
554
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndReplace - ' + this.collectionName, [validation.validationErrors(), replacement]);
555
+ reject(validation.validationErrors());
556
+ return [3 /*break*/, 4];
557
+ case 1:
558
+ if (this.timestamps) {
559
+ replacement['updatedAt'] = new Date();
560
+ }
561
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
562
+ return [4 /*yield*/, this.findOne(filter)];
563
+ case 2:
564
+ doc = _a.sent();
565
+ if (doc) {
566
+ log_collection_1.Logs.insertOne({
567
+ _id: objectIdHexString(),
568
+ type: 'document',
569
+ collection: this.collectionName,
570
+ id_document: doc['_id'],
571
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
572
+ method: 'findOneAndReplace',
573
+ id_user: '',
574
+ user: '',
575
+ messageId: '',
576
+ route: ''
577
+ });
578
+ }
579
+ _a.label = 3;
580
+ case 3:
581
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndReplace(filter, replacement, options).then(function (res) {
582
+ if (res.ok) {
583
+ resolve(res.value);
584
+ }
585
+ else {
586
+ reject(res.lastErrorObject);
587
+ }
588
+ }, function (err) { return reject(err); });
589
+ _a.label = 4;
590
+ case 4: return [2 /*return*/];
476
591
  }
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
- }
592
+ });
593
+ }); });
594
+ };
595
+ Collection.prototype.findOneAndUpdate = function (filter, update, options, bypassLogs) {
596
+ var _this = this;
597
+ if (filter === void 0) { filter = {}; }
598
+ if (bypassLogs === void 0) { bypassLogs = false; }
599
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
600
+ var validation, doc;
601
+ return __generator(this, function (_a) {
602
+ switch (_a.label) {
603
+ case 0:
604
+ validation = this.simplschema.newContext().validate(update, { modifier: true });
605
+ if (!!validation.isValid()) return [3 /*break*/, 1];
606
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
607
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on findOneAndUpdate - ' + this.collectionName, [validation.validationErrors(), update]);
608
+ reject(validation.validationErrors());
609
+ return [3 /*break*/, 4];
610
+ case 1:
611
+ if (this.timestamps) {
612
+ if (!update['$set']) {
613
+ update['$set'] = { updatedAt: new Date() };
614
+ }
615
+ else {
616
+ update['$set']['updatedAt'] = new Date();
617
+ }
618
+ }
619
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
620
+ return [4 /*yield*/, this.findOne(filter)];
621
+ case 2:
622
+ doc = _a.sent();
623
+ if (doc) {
624
+ log_collection_1.Logs.insertOne({
625
+ _id: objectIdHexString(),
626
+ type: 'document',
627
+ collection: this.collectionName,
628
+ id_document: doc['_id'],
629
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
630
+ method: 'findOneAndUpdate',
631
+ id_user: '',
632
+ user: '',
633
+ messageId: '',
634
+ route: ''
635
+ });
636
+ }
637
+ _a.label = 3;
638
+ case 3:
639
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).findOneAndUpdate(filter, update, options).then(function (res) {
640
+ if (res.ok) {
641
+ resolve(res.value);
642
+ }
643
+ else {
644
+ reject(res.lastErrorObject);
645
+ }
646
+ }, function (err) { return reject(err); });
647
+ _a.label = 4;
648
+ case 4: return [2 /*return*/];
493
649
  }
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) => {
650
+ });
651
+ }); });
652
+ };
653
+ Collection.prototype.indexes = function (options) {
654
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).indexes(options);
655
+ };
656
+ Collection.prototype.indexExists = function (indexes, options) {
657
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).indexExists(indexes, options);
658
+ };
659
+ Collection.prototype.insertMany = function (docs, options, bypassLogs) {
660
+ var _this = this;
661
+ if (bypassLogs === void 0) { bypassLogs = false; }
662
+ return new Promise(function (resolve, reject) {
513
663
  if (!docs.length) {
514
664
  reject('No Documents');
515
665
  return;
516
666
  }
517
- let validationResults = [];
518
- docs.forEach(doc => {
519
- const validation = this.simplschema.newContext().validate(doc);
667
+ var validationResults = [];
668
+ docs.forEach(function (doc) {
669
+ var validation = _this.simplschema.newContext().validate(doc);
520
670
  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]);
671
+ console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
672
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertMany - ' + _this.collectionName, [validation.validationErrors(), doc]);
523
673
  validationResults.push(false);
524
674
  }
525
675
  else {
526
676
  validationResults.push(true);
527
677
  }
528
678
  });
529
- let validDocs = docs.filter((a, idx) => validationResults[idx]);
530
- validDocs.forEach(doc => {
531
- if (this.timestamps) {
679
+ var validDocs = docs.filter(function (a, idx) { return validationResults[idx]; });
680
+ validDocs.forEach(function (doc) {
681
+ if (_this.timestamps) {
532
682
  doc['createdAt'] = new Date();
533
683
  doc['updatedAt'] = new Date();
534
684
  }
535
- if (this.createLogs && !bypassLogs) {
536
- Logs.insertOne({
685
+ if (_this.createLogs && !bypassLogs) {
686
+ log_collection_1.Logs.insertOne({
537
687
  _id: objectIdHexString(),
538
688
  type: 'document',
539
- collection: this.collectionName,
689
+ collection: _this.collectionName,
540
690
  id_document: doc['_id'],
541
- payload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
691
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
542
692
  method: 'insertMany',
543
693
  id_user: '',
544
694
  user: '',
@@ -548,39 +698,41 @@ export class Collection {
548
698
  }
549
699
  });
550
700
  if (validDocs.length) {
551
- ResolveIOServer.getMainDB().collection(this.collectionName).insertMany(validDocs, options).then(res => {
701
+ index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).insertMany(validDocs, options).then(function (res) {
552
702
  if (res.result.ok) {
553
703
  resolve(validDocs);
554
704
  }
555
705
  else {
556
706
  reject(res.result.ok);
557
707
  }
558
- }, err => {
708
+ }, function (err) {
559
709
  reject(err);
560
710
  });
561
711
  }
562
712
  });
563
- }
564
- insertOne(doc, options, bypassLogs = false) {
565
- return new Promise((resolve, reject) => {
566
- const validation = this.simplschema.newContext().validate(doc);
713
+ };
714
+ Collection.prototype.insertOne = function (doc, options, bypassLogs) {
715
+ var _this = this;
716
+ if (bypassLogs === void 0) { bypassLogs = false; }
717
+ return new Promise(function (resolve, reject) {
718
+ var validation = _this.simplschema.newContext().validate(doc);
567
719
  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]);
720
+ console.log(new Date(), _this.collectionName, 'Schema Errors', validation.validationErrors());
721
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on insertOne - ' + _this.collectionName, [validation.validationErrors(), doc]);
570
722
  reject(validation.validationErrors());
571
723
  }
572
724
  else {
573
- if (this.timestamps) {
725
+ if (_this.timestamps) {
574
726
  doc['createdAt'] = new Date();
575
727
  doc['updatedAt'] = new Date();
576
728
  }
577
- if (this.createLogs && !bypassLogs) {
578
- Logs.insertOne({
729
+ if (_this.createLogs && !bypassLogs) {
730
+ log_collection_1.Logs.insertOne({
579
731
  _id: objectIdHexString(),
580
732
  type: 'document',
581
- collection: this.collectionName,
733
+ collection: _this.collectionName,
582
734
  id_document: doc['_id'],
583
- payload: getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
735
+ payload: common_1.getBinarySize(JSON.stringify([doc, options])) < 200000 ? JSON.stringify([doc, options], null, 2) : 'Too Big',
584
736
  method: 'insertOne',
585
737
  id_user: '',
586
738
  user: '',
@@ -588,50 +740,59 @@ export class Collection {
588
740
  route: ''
589
741
  });
590
742
  }
591
- ResolveIOServer.getMainDB().collection(this.collectionName).insertOne(doc, options).then(res => {
743
+ index_1.ResolveIOServer.getMainDB().collection(_this.collectionName).insertOne(doc, options).then(function (res) {
592
744
  if (res.result.ok) {
593
745
  resolve(doc);
594
746
  }
595
747
  else {
596
748
  reject(res.result.ok);
597
749
  }
598
- }, err => {
750
+ }, function (err) {
599
751
  reject(err);
600
752
  });
601
753
  }
602
754
  });
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) {
755
+ };
756
+ Collection.prototype.listIndexes = function (options) {
757
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).listIndexes(options);
758
+ };
759
+ Collection.prototype.reIndex = function (options) {
760
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).reIndex(options);
761
+ };
762
+ Collection.prototype.rename = function (newName, options) {
763
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).rename(newName, options);
764
+ };
765
+ Collection.prototype.replaceOne = function (filter, replacement, options, bypassLogs, bypassDocument) {
766
+ var _this = this;
767
+ if (bypassLogs === void 0) { bypassLogs = false; }
768
+ if (bypassDocument === void 0) { bypassDocument = false; }
769
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
770
+ var validation, doc, versionDoc, prevDoc, docId, docVersion, updatedDoc;
771
+ return __generator(this, function (_a) {
772
+ switch (_a.label) {
773
+ case 0:
774
+ validation = this.simplschema.newContext().validate(replacement);
775
+ if (!!validation.isValid()) return [3 /*break*/, 1];
776
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
777
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on replaceOne - ' + this.collectionName, [validation.validationErrors(), replacement]);
778
+ reject(validation.validationErrors());
779
+ return [3 /*break*/, 11];
780
+ case 1:
781
+ if (this.timestamps) {
782
+ replacement['updatedAt'] = new Date();
783
+ }
784
+ if (!!bypassDocument) return [3 /*break*/, 10];
785
+ return [4 /*yield*/, this.findOne(filter)];
786
+ case 2:
787
+ doc = _a.sent();
788
+ if (!doc) return [3 /*break*/, 8];
628
789
  if (this.createLogs && !bypassLogs) {
629
- Logs.insertOne({
790
+ log_collection_1.Logs.insertOne({
630
791
  _id: objectIdHexString(),
631
792
  type: 'document',
632
793
  collection: this.collectionName,
633
794
  id_document: doc['_id'],
634
- payload: getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
795
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, replacement, options])) < 200000 ? JSON.stringify([doc, filter, replacement, options], null, 2) : 'Too Big',
635
796
  method: 'replaceOne',
636
797
  id_user: '',
637
798
  user: '',
@@ -639,402 +800,503 @@ export class Collection {
639
800
  route: ''
640
801
  });
641
802
  }
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
- });
803
+ if (!this.useVersions) return [3 /*break*/, 6];
804
+ versionDoc = common_1.deepCopy(doc);
805
+ versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
806
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
807
+ if (doc['__v'] >= 4) {
808
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [
809
+ { '_id._id': doc['_id'] },
810
+ { '_id.__v': { $lte: doc['__v'] - 4 } }
811
+ ] });
812
+ }
813
+ if (!(doc['__v'] === replacement['__v'])) return [3 /*break*/, 3];
814
+ replacement['__v'] += 1;
815
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
816
+ if (res.result.ok) {
817
+ resolve(res.result.nModified);
664
818
  }
665
819
  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
- }
820
+ reject(res.result.ok);
694
821
  }
695
- }
696
- else {
697
- ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(res => {
822
+ }, function (err) {
823
+ reject(err);
824
+ });
825
+ return [3 /*break*/, 5];
826
+ case 3:
827
+ console.log('invalid version - ' + this.collectionName, doc['__v'], replacement['__v']);
828
+ return [4 /*yield*/, index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).findOne({
829
+ $and: [
830
+ { '_id._id': doc['_id'] },
831
+ { '_id.__v': replacement['__v'] }
832
+ ]
833
+ })];
834
+ case 4:
835
+ prevDoc = _a.sent();
836
+ if (prevDoc) {
837
+ docId = doc['_id'];
838
+ docVersion = doc['__v'];
839
+ updatedDoc = common_1.getMongoMergeUpdatedDoc(replacement, doc, prevDoc);
840
+ updatedDoc['_id'] = docId;
841
+ updatedDoc['__v'] = docVersion + 1;
842
+ updatedDoc['updatedAt'] = new Date();
843
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, updatedDoc, options).then(function (res) {
698
844
  if (res.result.ok) {
699
845
  resolve(res.result.nModified);
700
846
  }
701
847
  else {
702
848
  reject(res.result.ok);
703
849
  }
704
- }, err => {
850
+ }, function (err) {
705
851
  reject(err);
706
852
  });
707
853
  }
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
854
  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
- ] });
818
- }
819
- if (!update.$inc) {
820
- update.$inc = { __v: 1 };
821
- }
822
- else if (!update.$inc.__v) {
823
- update.$inc.__v = 1;
855
+ reject('Invalid Version And Could Not Find History - DB: ' + doc['__v'] + ', Trying to update with :' + replacement['__v']);
824
856
  }
825
- ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(res => {
857
+ _a.label = 5;
858
+ case 5: return [3 /*break*/, 7];
859
+ case 6:
860
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
826
861
  if (res.result.ok) {
827
862
  resolve(res.result.nModified);
828
863
  }
829
864
  else {
830
865
  reject(res.result.ok);
831
866
  }
832
- }, err => reject(err));
833
- }
834
- else {
835
- ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(res => {
867
+ }, function (err) {
868
+ reject(err);
869
+ });
870
+ _a.label = 7;
871
+ case 7: return [3 /*break*/, 9];
872
+ case 8:
873
+ reject('No Document');
874
+ _a.label = 9;
875
+ case 9: return [3 /*break*/, 11];
876
+ case 10:
877
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).replaceOne(filter, replacement, options).then(function (res) {
836
878
  if (res.result.ok) {
837
879
  resolve(res.result.nModified);
838
880
  }
839
881
  else {
840
882
  reject(res.result.ok);
841
883
  }
842
- }, err => reject(err));
843
- }
844
- }
845
- else {
846
- reject('No Document');
884
+ }, function (err) {
885
+ reject(err);
886
+ });
887
+ _a.label = 11;
888
+ case 11: return [2 /*return*/];
847
889
  }
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);
890
+ });
891
+ }); });
892
+ };
893
+ Collection.prototype.stats = function (options) {
894
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).stats(options);
895
+ };
896
+ Collection.prototype.updateMany = function (filter, update, options, bypassLogs) {
897
+ var _this = this;
898
+ if (bypassLogs === void 0) { bypassLogs = false; }
899
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
900
+ var validation, docs;
901
+ var _this = this;
902
+ return __generator(this, function (_a) {
903
+ switch (_a.label) {
904
+ case 0:
905
+ if (this.timestamps) {
906
+ if (!update.$set) {
907
+ update.$set = { updatedAt: new Date() };
908
+ }
909
+ else {
910
+ update.$set['updatedAt'] = new Date();
911
+ }
912
+ }
913
+ validation = this.simplschema.newContext().validate(update, { modifier: true });
914
+ if (!!validation.isValid()) return [3 /*break*/, 1];
915
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
916
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateMany - ' + this.collectionName, [validation.validationErrors(), update]);
917
+ reject(validation.validationErrors());
918
+ return [3 /*break*/, 4];
919
+ case 1:
920
+ if (!(this.createLogs && !bypassLogs)) return [3 /*break*/, 3];
921
+ return [4 /*yield*/, this.find(filter)];
922
+ case 2:
923
+ docs = _a.sent();
924
+ docs.forEach(function (doc) {
925
+ log_collection_1.Logs.insertOne({
926
+ _id: objectIdHexString(),
927
+ type: 'document',
928
+ collection: _this.collectionName,
929
+ id_document: doc['_id'],
930
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
931
+ method: 'updateMany',
932
+ id_user: '',
933
+ user: '',
934
+ messageId: '',
935
+ route: ''
936
+ });
937
+ });
938
+ _a.label = 3;
939
+ case 3:
940
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateMany(filter, update, options).then(function (res) {
941
+ if (res.result.ok) {
942
+ resolve(res.result.nModified);
943
+ }
944
+ else {
945
+ reject(res.result.ok);
946
+ }
947
+ }, function (err) { return reject(err); });
948
+ _a.label = 4;
949
+ case 4: return [2 /*return*/];
865
950
  }
866
- else {
867
- cb(null, null, authUser.error);
951
+ });
952
+ }); });
953
+ };
954
+ Collection.prototype.updateOne = function (filter, update, options, bypassLogs) {
955
+ var _this = this;
956
+ if (bypassLogs === void 0) { bypassLogs = false; }
957
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
958
+ var validation, doc, versionDoc;
959
+ return __generator(this, function (_a) {
960
+ switch (_a.label) {
961
+ case 0:
962
+ if (this.timestamps) {
963
+ if (!update.$set) {
964
+ update.$set = { updatedAt: new Date() };
965
+ }
966
+ else {
967
+ update.$set['updatedAt'] = new Date();
968
+ }
969
+ }
970
+ validation = this.simplschema.newContext().validate(update, { modifier: true });
971
+ if (!!validation.isValid()) return [3 /*break*/, 1];
972
+ console.log(new Date(), this.collectionName, 'Schema Errors', validation.validationErrors());
973
+ index_1.ResolveIOServer.getMainServer().getMethodManager().callMethodInternal('insertErrorLog', 'Schema Failed on updateOne - ' + this.collectionName, [validation.validationErrors(), update]);
974
+ reject(validation.validationErrors());
975
+ return [3 /*break*/, 3];
976
+ case 1: return [4 /*yield*/, this.findOne(filter)];
977
+ case 2:
978
+ doc = _a.sent();
979
+ if (doc) {
980
+ if (this.createLogs && !bypassLogs) {
981
+ log_collection_1.Logs.insertOne({
982
+ _id: objectIdHexString(),
983
+ type: 'document',
984
+ collection: this.collectionName,
985
+ id_document: doc['_id'],
986
+ payload: common_1.getBinarySize(JSON.stringify([doc, filter, update, options])) < 200000 ? JSON.stringify([doc, filter, update, options], null, 2) : 'Too Big',
987
+ method: 'updateOne',
988
+ id_user: '',
989
+ user: '',
990
+ messageId: '',
991
+ route: ''
992
+ });
993
+ }
994
+ if (this.useVersions) {
995
+ versionDoc = common_1.deepCopy(doc);
996
+ versionDoc['_id'] = { _id: doc['_id'], __v: doc['__v'] };
997
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).insertOne(versionDoc);
998
+ if (doc['__v'] >= 4) {
999
+ index_1.ResolveIOServer.getMongoManager().collection(this.versionCollection).deleteMany({ $and: [
1000
+ { '_id._id': doc['_id'] },
1001
+ { '_id.__v': { $lte: doc['__v'] - 4 } }
1002
+ ] });
1003
+ }
1004
+ if (!update.$inc) {
1005
+ update.$inc = { __v: 1 };
1006
+ }
1007
+ else if (!update.$inc.__v) {
1008
+ update.$inc.__v = 1;
1009
+ }
1010
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
1011
+ if (res.result.ok) {
1012
+ resolve(res.result.nModified);
1013
+ }
1014
+ else {
1015
+ reject(res.result.ok);
1016
+ }
1017
+ }, function (err) { return reject(err); });
1018
+ }
1019
+ else {
1020
+ index_1.ResolveIOServer.getMainDB().collection(this.collectionName).updateOne(filter, update, options).then(function (res) {
1021
+ if (res.result.ok) {
1022
+ resolve(res.result.nModified);
1023
+ }
1024
+ else {
1025
+ reject(res.result.ok);
1026
+ }
1027
+ }, function (err) { return reject(err); });
1028
+ }
1029
+ }
1030
+ else {
1031
+ reject('No Document');
1032
+ }
1033
+ _a.label = 3;
1034
+ case 3: return [2 /*return*/];
868
1035
  }
869
- }, err => {
870
- cb(err, null, null);
871
1036
  });
872
- };
1037
+ }); });
1038
+ };
1039
+ Collection.prototype.watchCollection = function (pipeline, options) {
1040
+ if (pipeline === void 0) { pipeline = []; }
1041
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).watch(pipeline, options);
1042
+ };
1043
+ Collection.prototype.watchCollectionWithAggregate = function (pipeline, options) {
1044
+ if (pipeline === void 0) { pipeline = []; }
1045
+ return index_1.ResolveIOServer.getMainDB().collection(this.collectionName).watch(pipeline, options);
1046
+ };
1047
+ return Collection;
1048
+ }());
1049
+ exports.Collection = Collection;
1050
+ var UserCollection = /** @class */ (function (_super) {
1051
+ __extends(UserCollection, _super);
1052
+ function UserCollection() {
1053
+ return _super !== null && _super.apply(this, arguments) || this;
873
1054
  }
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'
1055
+ UserCollection.prototype.authenticateStrategy = function () {
1056
+ var _this = this;
1057
+ return function (username, password, cb) { return __awaiter(_this, void 0, void 0, function () {
1058
+ var user;
1059
+ return __generator(this, function (_a) {
1060
+ switch (_a.label) {
1061
+ case 0: return [4 /*yield*/, user_collection_1.Users.findOne({ username: username })];
1062
+ case 1:
1063
+ user = _a.sent();
1064
+ this.authenticate(user, password).then(function (authUser) {
1065
+ if (authUser.data) {
1066
+ cb(null, user, null);
1067
+ }
1068
+ else {
1069
+ cb(null, null, authUser.error);
1070
+ }
1071
+ }, function (err) {
1072
+ cb(err, null, null);
931
1073
  });
932
- }
933
- else {
1074
+ return [2 /*return*/];
1075
+ }
1076
+ });
1077
+ }); };
1078
+ };
1079
+ UserCollection.prototype.authenticate = function (user, password) {
1080
+ var _this = this;
1081
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1082
+ var attemptsInterval, calculatedInterval;
1083
+ var _this = this;
1084
+ return __generator(this, function (_a) {
1085
+ switch (_a.label) {
1086
+ case 0:
1087
+ attemptsInterval = Math.pow(100, Math.log(user.attempts + 1));
1088
+ calculatedInterval = attemptsInterval < 300000 ? attemptsInterval : 300000;
1089
+ if (!user.last) return [3 /*break*/, 3];
1090
+ if (!(Date.now() - user.last.getTime() < calculatedInterval)) return [3 /*break*/, 2];
1091
+ user.last = new Date();
1092
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last } })];
1093
+ case 1:
1094
+ _a.sent();
934
1095
  resolve({
935
1096
  data: null,
936
- error: 'Invalid Username And Password'
1097
+ error: 'Attempt Too Soon'
937
1098
  });
938
- }
1099
+ return [2 /*return*/];
1100
+ case 2: return [3 /*break*/, 4];
1101
+ case 3:
1102
+ user.last = new Date();
1103
+ _a.label = 4;
1104
+ case 4:
1105
+ if (user.attempts >= 5) {
1106
+ resolve({
1107
+ data: null,
1108
+ error: 'Too Many Attempts'
1109
+ });
1110
+ return [2 /*return*/];
1111
+ }
1112
+ if (!user.salt) {
1113
+ resolve({
1114
+ data: null,
1115
+ error: 'No Salt Value Stored'
1116
+ });
1117
+ return [2 /*return*/];
1118
+ }
1119
+ pbkdf2(password, user.salt, {
1120
+ iterations: 25000,
1121
+ keylen: 512,
1122
+ digestAlgorithm: 'sha256'
1123
+ }, function (err, hashBuffer) { return __awaiter(_this, void 0, void 0, function () {
1124
+ return __generator(this, function (_a) {
1125
+ switch (_a.label) {
1126
+ case 0:
1127
+ if (err) {
1128
+ return [2 /*return*/, reject(err)];
1129
+ }
1130
+ if (!scmp(hashBuffer, Buffer.from(user.hash, 'hex'))) return [3 /*break*/, 2];
1131
+ user.last = new Date();
1132
+ user.attempts = 0;
1133
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
1134
+ case 1:
1135
+ _a.sent();
1136
+ resolve({
1137
+ data: user,
1138
+ error: ''
1139
+ });
1140
+ return [3 /*break*/, 4];
1141
+ case 2:
1142
+ user.last = new Date();
1143
+ user.attempts = user.attempts + 1;
1144
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { last: user.last, attempts: user.attempts } })];
1145
+ case 3:
1146
+ _a.sent();
1147
+ if (user.attempts >= 5) {
1148
+ resolve({
1149
+ data: null,
1150
+ error: 'Too Many Attempts'
1151
+ });
1152
+ }
1153
+ else {
1154
+ resolve({
1155
+ data: null,
1156
+ error: 'Invalid Username And Password'
1157
+ });
1158
+ }
1159
+ _a.label = 4;
1160
+ case 4: return [2 /*return*/];
1161
+ }
1162
+ });
1163
+ }); });
1164
+ return [2 /*return*/];
939
1165
  }
940
1166
  });
941
- });
942
- }
943
- serializeUser() {
944
- return (user, cb) => {
1167
+ }); });
1168
+ };
1169
+ UserCollection.prototype.serializeUser = function () {
1170
+ return function (user, cb) {
945
1171
  cb(null, user.username);
946
1172
  };
947
- }
948
- deserializeUser() {
949
- return (username, cb) => {
950
- Users.findOne({ username: username }).then(res => {
1173
+ };
1174
+ UserCollection.prototype.deserializeUser = function () {
1175
+ return function (username, cb) {
1176
+ user_collection_1.Users.findOne({ username: username }).then(function (res) {
951
1177
  cb(null, res);
952
- }, err => {
1178
+ }, function (err) {
953
1179
  cb(err, null);
954
1180
  });
955
1181
  };
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);
1182
+ };
1183
+ UserCollection.prototype.setPassword = function (user, password) {
1184
+ var _this = this;
1185
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1186
+ var saltBuffer, salt, hashRaw, hash;
1187
+ return __generator(this, function (_a) {
1188
+ switch (_a.label) {
1189
+ case 0:
1190
+ if (!!user) return [3 /*break*/, 1];
1191
+ reject('No User');
1192
+ return [3 /*break*/, 6];
1193
+ case 1:
1194
+ if (!!password) return [3 /*break*/, 2];
1195
+ reject('No Password');
1196
+ return [3 /*break*/, 6];
1197
+ case 2: return [4 /*yield*/, randomBytes(32)];
1198
+ case 3:
1199
+ saltBuffer = _a.sent();
1200
+ salt = saltBuffer.toString('hex');
1201
+ return [4 /*yield*/, pbkdf2Promisified(password, salt, {
1202
+ iterations: 25000,
1203
+ keylen: 512,
1204
+ digestAlgorithm: 'sha256'
1205
+ })];
1206
+ case 4:
1207
+ hashRaw = _a.sent();
1208
+ hash = Buffer.from(hashRaw, 'binary').toString('hex');
1209
+ return [4 /*yield*/, user_collection_1.Users.updateOne({ _id: user._id }, { $set: { hash: hash, salt: salt, services: {} } })];
1210
+ case 5:
1211
+ _a.sent();
1212
+ _a.label = 6;
1213
+ case 6: return [2 /*return*/];
994
1214
  }
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');
1215
+ });
1216
+ }); });
1217
+ };
1218
+ ;
1219
+ UserCollection.prototype.changePassword = function (user, oldPassword, newPassword) {
1220
+ var _this = this;
1221
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1222
+ var authUser;
1223
+ return __generator(this, function (_a) {
1224
+ switch (_a.label) {
1225
+ case 0:
1226
+ if (!!user) return [3 /*break*/, 1];
1227
+ reject('Missing User');
1228
+ return [3 /*break*/, 4];
1229
+ case 1:
1230
+ if (!(!oldPassword || !newPassword)) return [3 /*break*/, 2];
1231
+ reject('Missing Password');
1232
+ return [3 /*break*/, 4];
1233
+ case 2: return [4 /*yield*/, this.authenticate(user, oldPassword)];
1234
+ case 3:
1235
+ authUser = _a.sent();
1236
+ if (!authUser['data']) {
1237
+ reject(authUser['error']);
1238
+ }
1239
+ else {
1240
+ this.setPassword(user, newPassword);
1241
+ }
1242
+ _a.label = 4;
1243
+ case 4: return [2 /*return*/];
1007
1244
  }
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
- }
1245
+ });
1246
+ }); });
1247
+ };
1248
+ UserCollection.prototype.register = function (user, password) {
1249
+ var _this = this;
1250
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1251
+ var dbUser;
1252
+ return __generator(this, function (_a) {
1253
+ switch (_a.label) {
1254
+ case 0:
1255
+ if (!!user.username) return [3 /*break*/, 1];
1256
+ reject('Missing Username');
1257
+ return [3 /*break*/, 5];
1258
+ case 1: return [4 /*yield*/, user_collection_1.Users.findOne({ username: user.username })];
1259
+ case 2:
1260
+ dbUser = _a.sent();
1261
+ if (!dbUser) return [3 /*break*/, 3];
1262
+ reject('Username Exists');
1263
+ return [3 /*break*/, 5];
1264
+ case 3: return [4 /*yield*/, user_collection_1.Users.findOne({ email: user.email })];
1265
+ case 4:
1266
+ dbUser = _a.sent();
1267
+ if (dbUser) {
1268
+ reject('Email Exists');
1269
+ }
1270
+ else {
1271
+ user.setPassword(password);
1272
+ resolve(user);
1273
+ }
1274
+ _a.label = 5;
1275
+ case 5: return [2 /*return*/];
1017
1276
  }
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();
1277
+ });
1278
+ }); });
1279
+ };
1280
+ UserCollection.prototype.resetAttempts = function (user) {
1281
+ return user_collection_1.Users.updateOne({ _id: user._id }, { $set: { attempts: 0 } });
1282
+ };
1283
+ return UserCollection;
1284
+ }(Collection));
1285
+ exports.UserCollection = UserCollection;
1286
+ function objectIdHexString() {
1287
+ var objectId = new mongodb_1.ObjectId();
1027
1288
  return objectId.toHexString();
1028
1289
  }
1290
+ exports.objectIdHexString = objectIdHexString;
1029
1291
  function pbkdf2(password, salt, options, callback) {
1030
1292
  crypto.pbkdf2(password, salt, options.iterations, options.keylen, options.digestAlgorithm, callback);
1031
1293
  }
1032
1294
  ;
1033
1295
  function pbkdf2Promisified(password, salt, options) {
1034
- return new Promise((resolve, reject) => pbkdf2(password, salt, options, (err, hashRaw) => (err ? reject(err) : resolve(hashRaw))));
1296
+ return new Promise(function (resolve, reject) { return pbkdf2(password, salt, options, function (err, hashRaw) { return (err ? reject(err) : resolve(hashRaw)); }); });
1035
1297
  }
1036
1298
  function randomBytes(saltlen) {
1037
- return new Promise((resolve, reject) => crypto.randomBytes(saltlen, (err, saltBuffer) => (err ? reject(err) : resolve(saltBuffer))));
1299
+ return new Promise(function (resolve, reject) { return crypto.randomBytes(saltlen, function (err, saltBuffer) { return (err ? reject(err) : resolve(saltBuffer)); }); });
1038
1300
  }
1039
1301
 
1040
1302
  //# sourceMappingURL=mongo.manager.js.map