@resolveio/server-lib 9.0.19 → 9.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/collections/log.collection.js +7 -7
- package/collections/log.collection.js.map +1 -1
- package/managers/mongo.manager.d.ts +1 -0
- package/managers/mongo.manager.js +4 -2
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.js +1 -1
- package/managers/subscription.manager.js.map +1 -1
- package/methods/collections.js +152 -126
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +4 -4
- package/methods/counters.js.map +1 -1
- package/methods/monitor.js +1 -1
- package/methods/monitor.js.map +1 -1
- package/methods/report-builder.js +1 -1
- package/methods/report-builder.js.map +1 -1
- package/package.json +1 -1
- package/server-app.d.ts +1 -1
- package/server-app.js +1 -1
- package/server-app.js.map +1 -1
- package/util/schema-report-builder.js +3 -3
- package/util/schema-report-builder.js.map +1 -1
package/methods/collections.js
CHANGED
|
@@ -8,6 +8,22 @@ var index_1 = require("../index");
|
|
|
8
8
|
var mongo_manager_1 = require("../managers/mongo.manager");
|
|
9
9
|
function loadCollectionMethods(methodManager) {
|
|
10
10
|
methodManager.methods({
|
|
11
|
+
collectionListAll: {
|
|
12
|
+
skipQueue: true,
|
|
13
|
+
function: function () {
|
|
14
|
+
return new Promise(function (resolve, reject) {
|
|
15
|
+
resolve(index_1.ResolveIOServer.getMainServer().getMongoManager().collections().map(function (a) { return a.collectionName; }));
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
collectionListRB: {
|
|
20
|
+
skipQueue: true,
|
|
21
|
+
function: function () {
|
|
22
|
+
return new Promise(function (resolve, reject) {
|
|
23
|
+
resolve(index_1.ResolveIOServer.getMainServer().getMongoManager().collections().filter(function (a) { return a.useRB; }).map(function (a) { return a.collectionName; }));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
},
|
|
11
27
|
// Query database for any collection and query
|
|
12
28
|
findOne: {
|
|
13
29
|
skipQueue: true,
|
|
@@ -23,11 +39,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
23
39
|
function: function (collection, query) {
|
|
24
40
|
if (query === void 0) { query = {}; }
|
|
25
41
|
return new Promise(function (resolve, reject) {
|
|
26
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
42
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
27
43
|
reject('Invalid collection');
|
|
28
44
|
}
|
|
29
45
|
else {
|
|
30
|
-
index_1.ResolveIOServer.getMainServer().
|
|
46
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).findOne(query).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
31
47
|
}
|
|
32
48
|
});
|
|
33
49
|
}
|
|
@@ -52,11 +68,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
52
68
|
if (query === void 0) { query = {}; }
|
|
53
69
|
if (sortQuery === void 0) { sortQuery = {}; }
|
|
54
70
|
return new Promise(function (resolve, reject) {
|
|
55
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
71
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
56
72
|
reject('Invalid collection');
|
|
57
73
|
}
|
|
58
74
|
else {
|
|
59
|
-
index_1.ResolveIOServer.getMainServer().
|
|
75
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).find(query, { sort: sortQuery }).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
60
76
|
}
|
|
61
77
|
});
|
|
62
78
|
}
|
|
@@ -77,7 +93,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
77
93
|
}),
|
|
78
94
|
function: function (collection, query, options) {
|
|
79
95
|
return new Promise(function (resolve, reject) {
|
|
80
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
96
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
81
97
|
reject('Invalid collection');
|
|
82
98
|
}
|
|
83
99
|
else {
|
|
@@ -94,7 +110,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
94
110
|
if (options.skip) {
|
|
95
111
|
optionsQuery['skip'] = options.skip;
|
|
96
112
|
}
|
|
97
|
-
index_1.ResolveIOServer.getMainServer().
|
|
113
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).find(query, optionsQuery).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
98
114
|
}
|
|
99
115
|
});
|
|
100
116
|
}
|
|
@@ -115,13 +131,13 @@ function loadCollectionMethods(methodManager) {
|
|
|
115
131
|
function: function (collection, document) {
|
|
116
132
|
var _this = this;
|
|
117
133
|
return new Promise(function (resolve, reject) {
|
|
118
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
134
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
119
135
|
reject('Invalid collection');
|
|
120
136
|
}
|
|
121
137
|
else {
|
|
122
138
|
var schemaErrors = null;
|
|
123
139
|
try {
|
|
124
|
-
index_1.ResolveIOServer.getMainServer().
|
|
140
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)['simplschema'].validate(document);
|
|
125
141
|
}
|
|
126
142
|
catch (errors) {
|
|
127
143
|
schemaErrors = errors;
|
|
@@ -135,7 +151,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
135
151
|
var id_1 = mongo_manager_1.objectIdHexString();
|
|
136
152
|
document['_id'] = id_1;
|
|
137
153
|
document['__v'] = 0;
|
|
138
|
-
index_1.ResolveIOServer.getMainServer().
|
|
154
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).insertOne(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
139
155
|
}
|
|
140
156
|
}
|
|
141
157
|
});
|
|
@@ -160,7 +176,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
160
176
|
function: function (collection, documents) {
|
|
161
177
|
var _this = this;
|
|
162
178
|
return new Promise(function (res, rej) {
|
|
163
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
179
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
164
180
|
rej('Invalid collection');
|
|
165
181
|
}
|
|
166
182
|
else {
|
|
@@ -170,7 +186,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
170
186
|
promises.push(new Promise(function (resolve, reject) {
|
|
171
187
|
var schemaErrors = null;
|
|
172
188
|
try {
|
|
173
|
-
index_1.ResolveIOServer.getMainServer().
|
|
189
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)['simplschema'].validate(document_1);
|
|
174
190
|
}
|
|
175
191
|
catch (errors) {
|
|
176
192
|
schemaErrors = errors;
|
|
@@ -184,7 +200,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
184
200
|
var id_2 = mongo_manager_1.objectIdHexString();
|
|
185
201
|
document_1['_id'] = id_2;
|
|
186
202
|
document_1['__v'] = 0;
|
|
187
|
-
index_1.ResolveIOServer.getMainServer().
|
|
203
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).insertOne(document_1).then(function () { return resolve(id_2); }, function (err) { return reject(err); });
|
|
188
204
|
}
|
|
189
205
|
}));
|
|
190
206
|
};
|
|
@@ -213,11 +229,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
213
229
|
function: function (collection, f_document) {
|
|
214
230
|
var _this = this;
|
|
215
231
|
return new Promise(function (resolve, reject) {
|
|
216
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
232
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
217
233
|
reject('Invalid collection');
|
|
218
234
|
}
|
|
219
235
|
else {
|
|
220
|
-
index_1.ResolveIOServer.getMainServer().
|
|
236
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).findOne({ _id: f_document['_id'] }).then(function (currDoc) {
|
|
221
237
|
if (currDoc) {
|
|
222
238
|
if (currDoc.__v === f_document['__v']) {
|
|
223
239
|
var versionDoc = common_1.deepCopy(currDoc);
|
|
@@ -227,7 +243,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
227
243
|
};
|
|
228
244
|
var schemaErrors = null;
|
|
229
245
|
try {
|
|
230
|
-
index_1.ResolveIOServer.getMainServer().
|
|
246
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)['simplschema'].validate(f_document);
|
|
231
247
|
}
|
|
232
248
|
catch (errors) {
|
|
233
249
|
schemaErrors = errors;
|
|
@@ -239,15 +255,15 @@ function loadCollectionMethods(methodManager) {
|
|
|
239
255
|
}
|
|
240
256
|
else {
|
|
241
257
|
var updates_1 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
242
|
-
index_1.ResolveIOServer.getMainServer().
|
|
243
|
-
index_1.ResolveIOServer.getMainServer().
|
|
258
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
259
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
244
260
|
$and: [
|
|
245
261
|
{ '_id._id': currDoc._id },
|
|
246
262
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
247
263
|
]
|
|
248
264
|
}).then(function () {
|
|
249
265
|
if (updates_1) {
|
|
250
|
-
index_1.ResolveIOServer.getMainServer().
|
|
266
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
251
267
|
resolve(res.result.nModified);
|
|
252
268
|
}, function (err) { return reject(err); });
|
|
253
269
|
}
|
|
@@ -259,14 +275,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
259
275
|
});
|
|
260
276
|
}, function (err) {
|
|
261
277
|
console.log(err);
|
|
262
|
-
index_1.ResolveIOServer.getMainServer().
|
|
278
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
263
279
|
$and: [
|
|
264
280
|
{ '_id._id': currDoc._id },
|
|
265
281
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
266
282
|
]
|
|
267
283
|
}).then(function () {
|
|
268
284
|
if (updates_1) {
|
|
269
|
-
index_1.ResolveIOServer.getMainServer().
|
|
285
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_1).then(function (res) {
|
|
270
286
|
resolve(res.result.nModified);
|
|
271
287
|
}, function (err) { return reject(err); });
|
|
272
288
|
}
|
|
@@ -281,44 +297,49 @@ function loadCollectionMethods(methodManager) {
|
|
|
281
297
|
}
|
|
282
298
|
else {
|
|
283
299
|
console.log('invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
284
|
-
index_1.ResolveIOServer.getMainServer().
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
_id
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
index_1.ResolveIOServer.getMainServer().
|
|
303
|
-
index_1.ResolveIOServer.getMainServer().
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
300
|
+
if (index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions')) {
|
|
301
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').findOne({
|
|
302
|
+
$and: [
|
|
303
|
+
{ '_id._id': currDoc._id },
|
|
304
|
+
{ '_id.__v': f_document['__v'] }
|
|
305
|
+
]
|
|
306
|
+
}).then(function (oldDoc) {
|
|
307
|
+
var newCurrDocId = currDoc._id;
|
|
308
|
+
if (oldDoc) {
|
|
309
|
+
var versionDoc_1 = common_1.deepCopy(currDoc);
|
|
310
|
+
versionDoc_1._id = {
|
|
311
|
+
_id: currDoc._id,
|
|
312
|
+
__v: currDoc.__v
|
|
313
|
+
};
|
|
314
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(f_document, currDoc, oldDoc);
|
|
315
|
+
updatedDoc._id = newCurrDocId;
|
|
316
|
+
updatedDoc.__v++;
|
|
317
|
+
updatedDoc.updatedAt = new Date();
|
|
318
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
319
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc_1).then(function (doc) {
|
|
320
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
321
|
+
$and: [
|
|
322
|
+
{ '_id._id': versionDoc_1._id._id },
|
|
323
|
+
{ '_id.__v': { $lte: versionDoc_1._id.__v - 4 } }
|
|
324
|
+
]
|
|
325
|
+
}).then(function () {
|
|
326
|
+
resolve(res.result.nModified);
|
|
327
|
+
}, function (err) {
|
|
328
|
+
console.log(err);
|
|
329
|
+
});
|
|
310
330
|
}, function (err) {
|
|
311
331
|
console.log(err);
|
|
312
332
|
});
|
|
313
|
-
}, function (err) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
333
|
+
}, function (err) { return reject(err); });
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
reject('Invalid Version And Could Not Find History - DB: ' + currDoc.__v + ', Trying to update with :' + f_document['__v']);
|
|
337
|
+
}
|
|
338
|
+
}, function (errOldDoc) { });
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
342
|
+
}
|
|
322
343
|
}
|
|
323
344
|
}
|
|
324
345
|
else {
|
|
@@ -357,11 +378,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
357
378
|
function: function (collection, doc_id, updateParams, doc__v) {
|
|
358
379
|
var _this = this;
|
|
359
380
|
return new Promise(function (resolve, reject) {
|
|
360
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
381
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
361
382
|
reject('Invalid collection');
|
|
362
383
|
}
|
|
363
384
|
else {
|
|
364
|
-
index_1.ResolveIOServer.getMainServer().
|
|
385
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).findOne({ _id: doc_id }).then(function (currDoc) {
|
|
365
386
|
if (currDoc) {
|
|
366
387
|
var modifiedDoc_1 = common_1.deepCopy(currDoc);
|
|
367
388
|
updateParams.forEach(function (data) {
|
|
@@ -375,7 +396,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
375
396
|
};
|
|
376
397
|
var schemaErrors = null;
|
|
377
398
|
try {
|
|
378
|
-
index_1.ResolveIOServer.getMainServer().
|
|
399
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)['simplschema'].validate(modifiedDoc_1);
|
|
379
400
|
}
|
|
380
401
|
catch (errors) {
|
|
381
402
|
schemaErrors = errors;
|
|
@@ -387,15 +408,15 @@ function loadCollectionMethods(methodManager) {
|
|
|
387
408
|
}
|
|
388
409
|
else {
|
|
389
410
|
var updates_2 = common_1.getMongoUpdates(currDoc, modifiedDoc_1, true);
|
|
390
|
-
index_1.ResolveIOServer.getMainServer().
|
|
391
|
-
index_1.ResolveIOServer.getMainServer().
|
|
411
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
412
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
392
413
|
$and: [
|
|
393
414
|
{ '_id._id': currDoc._id },
|
|
394
415
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
395
416
|
]
|
|
396
417
|
}).then(function () {
|
|
397
418
|
if (updates_2) {
|
|
398
|
-
index_1.ResolveIOServer.getMainServer().
|
|
419
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
399
420
|
resolve(res.result.ok);
|
|
400
421
|
}, function (err) { return reject(err); });
|
|
401
422
|
}
|
|
@@ -407,14 +428,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
407
428
|
});
|
|
408
429
|
}, function (err) {
|
|
409
430
|
console.log(err);
|
|
410
|
-
index_1.ResolveIOServer.getMainServer().
|
|
431
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
411
432
|
$and: [
|
|
412
433
|
{ '_id._id': currDoc._id },
|
|
413
434
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
414
435
|
]
|
|
415
436
|
}).then(function () {
|
|
416
437
|
if (updates_2) {
|
|
417
|
-
index_1.ResolveIOServer.getMainServer().
|
|
438
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_1._id }, updates_2).then(function (res) {
|
|
418
439
|
resolve(res.result.n);
|
|
419
440
|
}, function (err) { return reject(err); });
|
|
420
441
|
}
|
|
@@ -429,44 +450,49 @@ function loadCollectionMethods(methodManager) {
|
|
|
429
450
|
}
|
|
430
451
|
else {
|
|
431
452
|
console.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);
|
|
432
|
-
index_1.ResolveIOServer.getMainServer().
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
_id
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
index_1.ResolveIOServer.getMainServer().
|
|
451
|
-
index_1.ResolveIOServer.getMainServer().
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
453
|
+
if (index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions')) {
|
|
454
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').findOne({
|
|
455
|
+
$and: [
|
|
456
|
+
{ '_id._id': currDoc._id },
|
|
457
|
+
{ '_id.__v': doc__v }
|
|
458
|
+
]
|
|
459
|
+
}).then(function (oldDoc) {
|
|
460
|
+
var newCurrDocId = currDoc._id;
|
|
461
|
+
if (oldDoc) {
|
|
462
|
+
var versionDoc_2 = common_1.deepCopy(currDoc);
|
|
463
|
+
versionDoc_2._id = {
|
|
464
|
+
_id: currDoc._id,
|
|
465
|
+
__v: currDoc.__v
|
|
466
|
+
};
|
|
467
|
+
var updatedDoc = common_1.getMongoMergeUpdatedDoc(modifiedDoc_1, currDoc, oldDoc);
|
|
468
|
+
updatedDoc._id = newCurrDocId;
|
|
469
|
+
updatedDoc.__v++;
|
|
470
|
+
updatedDoc.updatedAt = new Date();
|
|
471
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
472
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc_2).then(function (doc) {
|
|
473
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
474
|
+
$and: [
|
|
475
|
+
{ '_id._id': versionDoc_2._id._id },
|
|
476
|
+
{ '_id.__v': { $lte: versionDoc_2._id.__v - 4 } }
|
|
477
|
+
]
|
|
478
|
+
}).then(function () {
|
|
479
|
+
resolve(res.result.nModified);
|
|
480
|
+
}, function (err) {
|
|
481
|
+
console.log(err);
|
|
482
|
+
});
|
|
458
483
|
}, function (err) {
|
|
459
484
|
console.log(err);
|
|
460
485
|
});
|
|
461
|
-
}, function (err) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
486
|
+
}, function (err) { return reject(err); });
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
reject('Invalid Version And Could Not Find History Props - DB: ' + currDoc.__v + ', Trying to update with :' + doc__v);
|
|
490
|
+
}
|
|
491
|
+
}, function () { });
|
|
492
|
+
}
|
|
493
|
+
else {
|
|
494
|
+
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
495
|
+
}
|
|
470
496
|
}
|
|
471
497
|
}
|
|
472
498
|
else {
|
|
@@ -494,11 +520,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
494
520
|
function: function (collection, f_document, f_oldDocument) {
|
|
495
521
|
var _this = this;
|
|
496
522
|
return new Promise(function (resolve, reject) {
|
|
497
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
523
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
498
524
|
reject('Invalid collection');
|
|
499
525
|
}
|
|
500
526
|
else {
|
|
501
|
-
index_1.ResolveIOServer.getMainServer().
|
|
527
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).findOne({ _id: f_document['_id'] }).then(function (currDoc) {
|
|
502
528
|
if (currDoc) {
|
|
503
529
|
if (currDoc.__v === f_document['__v']) {
|
|
504
530
|
var versionDoc = common_1.deepCopy(currDoc);
|
|
@@ -508,7 +534,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
508
534
|
};
|
|
509
535
|
var schemaErrors = null;
|
|
510
536
|
try {
|
|
511
|
-
index_1.ResolveIOServer.getMainServer().
|
|
537
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)['simplschema'].validate(f_document);
|
|
512
538
|
}
|
|
513
539
|
catch (errors) {
|
|
514
540
|
schemaErrors = errors;
|
|
@@ -520,15 +546,15 @@ function loadCollectionMethods(methodManager) {
|
|
|
520
546
|
}
|
|
521
547
|
else {
|
|
522
548
|
var updates_3 = common_1.getMongoUpdates(currDoc, f_document, true);
|
|
523
|
-
index_1.ResolveIOServer.getMainServer().
|
|
524
|
-
index_1.ResolveIOServer.getMainServer().
|
|
549
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
550
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
525
551
|
$and: [
|
|
526
552
|
{ '_id._id': currDoc._id },
|
|
527
553
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
528
554
|
]
|
|
529
555
|
}).then(function () {
|
|
530
556
|
if (updates_3) {
|
|
531
|
-
index_1.ResolveIOServer.getMainServer().
|
|
557
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
532
558
|
resolve(res.result.nModified);
|
|
533
559
|
}, function (err) { return reject(err); });
|
|
534
560
|
}
|
|
@@ -540,14 +566,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
540
566
|
});
|
|
541
567
|
}, function (err) {
|
|
542
568
|
console.log(err);
|
|
543
|
-
index_1.ResolveIOServer.getMainServer().
|
|
569
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
544
570
|
$and: [
|
|
545
571
|
{ '_id._id': currDoc._id },
|
|
546
572
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
547
573
|
]
|
|
548
574
|
}).then(function () {
|
|
549
575
|
if (updates_3) {
|
|
550
|
-
index_1.ResolveIOServer.getMainServer().
|
|
576
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: f_document['_id'] }, updates_3).then(function (res) {
|
|
551
577
|
resolve(res.result.nModified);
|
|
552
578
|
}, function (err) { return reject(err); });
|
|
553
579
|
}
|
|
@@ -573,9 +599,9 @@ function loadCollectionMethods(methodManager) {
|
|
|
573
599
|
updatedDoc._id = newCurrDocId;
|
|
574
600
|
updatedDoc.__v++;
|
|
575
601
|
updatedDoc.updatedAt = new Date();
|
|
576
|
-
index_1.ResolveIOServer.getMainServer().
|
|
577
|
-
index_1.ResolveIOServer.getMainServer().
|
|
578
|
-
index_1.ResolveIOServer.getMainServer().
|
|
602
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
603
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc_3).then(function (doc) {
|
|
604
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
579
605
|
$and: [
|
|
580
606
|
{ '_id._id': versionDoc_3._id._id },
|
|
581
607
|
{ '_id.__v': { $lte: versionDoc_3._id.__v - 4 } }
|
|
@@ -633,11 +659,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
633
659
|
function: function (collection, doc_id, updateParams, doc__v, f_oldDocument) {
|
|
634
660
|
var _this = this;
|
|
635
661
|
return new Promise(function (resolve, reject) {
|
|
636
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
662
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
637
663
|
reject('Invalid collection');
|
|
638
664
|
}
|
|
639
665
|
else {
|
|
640
|
-
index_1.ResolveIOServer.getMainServer().
|
|
666
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).findOne({ _id: doc_id }).then(function (currDoc) {
|
|
641
667
|
if (currDoc) {
|
|
642
668
|
var modifiedDoc_2 = common_1.deepCopy(currDoc);
|
|
643
669
|
updateParams.forEach(function (data) {
|
|
@@ -651,7 +677,7 @@ function loadCollectionMethods(methodManager) {
|
|
|
651
677
|
};
|
|
652
678
|
var schemaErrors = null;
|
|
653
679
|
try {
|
|
654
|
-
index_1.ResolveIOServer.getMainServer().
|
|
680
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)['simplschema'].validate(modifiedDoc_2);
|
|
655
681
|
}
|
|
656
682
|
catch (errors) {
|
|
657
683
|
schemaErrors = errors;
|
|
@@ -663,15 +689,15 @@ function loadCollectionMethods(methodManager) {
|
|
|
663
689
|
}
|
|
664
690
|
else {
|
|
665
691
|
var updates_4 = common_1.getMongoUpdates(currDoc, modifiedDoc_2, true);
|
|
666
|
-
index_1.ResolveIOServer.getMainServer().
|
|
667
|
-
index_1.ResolveIOServer.getMainServer().
|
|
692
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc).then(function (doc) {
|
|
693
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
668
694
|
$and: [
|
|
669
695
|
{ '_id._id': currDoc._id },
|
|
670
696
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
671
697
|
]
|
|
672
698
|
}).then(function () {
|
|
673
699
|
if (updates_4) {
|
|
674
|
-
index_1.ResolveIOServer.getMainServer().
|
|
700
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
675
701
|
resolve(res.result.ok);
|
|
676
702
|
}, function (err) { return reject(err); });
|
|
677
703
|
}
|
|
@@ -683,14 +709,14 @@ function loadCollectionMethods(methodManager) {
|
|
|
683
709
|
});
|
|
684
710
|
}, function (err) {
|
|
685
711
|
console.log(err);
|
|
686
|
-
index_1.ResolveIOServer.getMainServer().
|
|
712
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
687
713
|
$and: [
|
|
688
714
|
{ '_id._id': currDoc._id },
|
|
689
715
|
{ '_id.__v': { $lte: currDoc.__v - 4 } }
|
|
690
716
|
]
|
|
691
717
|
}).then(function () {
|
|
692
718
|
if (updates_4) {
|
|
693
|
-
index_1.ResolveIOServer.getMainServer().
|
|
719
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).updateOne({ _id: modifiedDoc_2._id }, updates_4).then(function (res) {
|
|
694
720
|
resolve(res.result.ok);
|
|
695
721
|
}, function (err) { return reject(err); });
|
|
696
722
|
}
|
|
@@ -716,9 +742,9 @@ function loadCollectionMethods(methodManager) {
|
|
|
716
742
|
updatedDoc._id = newCurrDocId;
|
|
717
743
|
updatedDoc.__v++;
|
|
718
744
|
updatedDoc.updatedAt = new Date();
|
|
719
|
-
index_1.ResolveIOServer.getMainServer().
|
|
720
|
-
index_1.ResolveIOServer.getMainServer().
|
|
721
|
-
index_1.ResolveIOServer.getMainServer().
|
|
745
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc).then(function (res) {
|
|
746
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').create(versionDoc_4).then(function (doc) {
|
|
747
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection + '.versions').deleteMany({
|
|
722
748
|
$and: [
|
|
723
749
|
{ '_id._id': versionDoc_4._id._id },
|
|
724
750
|
{ '_id.__v': { $lte: versionDoc_4._id.__v - 4 } }
|
|
@@ -761,11 +787,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
761
787
|
}),
|
|
762
788
|
function: function (collection, doc_id) {
|
|
763
789
|
return new Promise(function (resolve, reject) {
|
|
764
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
790
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
765
791
|
reject('Invalid collection');
|
|
766
792
|
}
|
|
767
793
|
else {
|
|
768
|
-
index_1.ResolveIOServer.getMainServer().
|
|
794
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).deleteOne({ _id: doc_id }).then(function (res) {
|
|
769
795
|
resolve(res.result.ok);
|
|
770
796
|
}, function (err) {
|
|
771
797
|
reject(err);
|
|
@@ -786,11 +812,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
786
812
|
}),
|
|
787
813
|
function: function (collection, query) {
|
|
788
814
|
return new Promise(function (resolve, reject) {
|
|
789
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
815
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
790
816
|
reject('Invalid collection');
|
|
791
817
|
}
|
|
792
818
|
else {
|
|
793
|
-
index_1.ResolveIOServer.getMainServer().
|
|
819
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).deleteOne(query).then(function (res) {
|
|
794
820
|
resolve(res.result.ok);
|
|
795
821
|
}, function (err) {
|
|
796
822
|
reject(err);
|
|
@@ -811,11 +837,11 @@ function loadCollectionMethods(methodManager) {
|
|
|
811
837
|
}),
|
|
812
838
|
function: function (collection, query) {
|
|
813
839
|
return new Promise(function (resolve, reject) {
|
|
814
|
-
if (!index_1.ResolveIOServer.getMainServer().
|
|
840
|
+
if (!index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection)) {
|
|
815
841
|
reject('Invalid collection');
|
|
816
842
|
}
|
|
817
843
|
else {
|
|
818
|
-
index_1.ResolveIOServer.getMainServer().
|
|
844
|
+
index_1.ResolveIOServer.getMainServer().getMongoManager().collection(collection).deleteMany(query).then(function (res) {
|
|
819
845
|
resolve(res.result.ok);
|
|
820
846
|
}, function (err) {
|
|
821
847
|
reject(err);
|