@resolveio/server-lib 20.0.26 → 20.0.28
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/client-server-app.js +1 -47
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +1 -50
- package/collections/app-status.collection.js.map +1 -1
- package/collections/counter.collection.js +1 -53
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +1 -88
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +1 -84
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +1 -65
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +1 -60
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +1 -72
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +1 -55
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +1 -63
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +1 -67
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log-ts.collection.js +1 -77
- package/collections/log-ts.collection.js.map +1 -1
- package/collections/log.collection.js +1 -76
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +1 -64
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-response.collection.js +1 -65
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +1 -62
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +1 -74
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +1 -68
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +1 -55
- package/collections/notification.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +1 -108
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +1 -86
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +1 -148
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +1 -93
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +1 -56
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +1 -265
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +1 -101
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +1 -87
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +1 -58
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +1 -763
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -11
- package/http/health.js.map +1 -1
- package/http/home.js +1 -65
- package/http/home.js.map +1 -1
- package/index.js +1 -126
- package/index.js.map +1 -1
- package/managers/cron.manager.js +1 -322
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +1 -593
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +1 -2259
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +1 -350
- package/managers/monitor.manager.js.map +1 -1
- package/managers/subscription.manager.js +1 -1110
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.js +1 -102
- package/managers/subscription.performance.js.map +1 -1
- package/methods/accounts.js +1 -291
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +1 -616
- package/methods/aws.js.map +1 -1
- package/methods/collections.js +1 -499
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +1 -121
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +1 -1337
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +1 -8
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +1 -370
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +1 -564
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +1 -731
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +1 -859
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +1 -245
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +1 -3
- package/models/app-status.model.js.map +1 -1
- package/models/billing-logged-in-users.model.js +1 -3
- package/models/billing-logged-in-users.model.js.map +1 -1
- package/models/collection-document.model.js +1 -3
- package/models/collection-document.model.js.map +1 -1
- package/models/counter.model.js +1 -3
- package/models/counter.model.js.map +1 -1
- package/models/cron-job-history.model.js +1 -3
- package/models/cron-job-history.model.js.map +1 -1
- package/models/cron-job.model.js +1 -3
- package/models/cron-job.model.js.map +1 -1
- package/models/dialog.model.js +1 -3
- package/models/dialog.model.js.map +1 -1
- package/models/email-history.model.js +1 -3
- package/models/email-history.model.js.map +1 -1
- package/models/email-verified.model.js +1 -3
- package/models/email-verified.model.js.map +1 -1
- package/models/file.model.js +1 -3
- package/models/file.model.js.map +1 -1
- package/models/flag.model.js +1 -3
- package/models/flag.model.js.map +1 -1
- package/models/log-method-latency.model.js +1 -3
- package/models/log-method-latency.model.js.map +1 -1
- package/models/log-subscription.model.js +1 -3
- package/models/log-subscription.model.js.map +1 -1
- package/models/log.model.js +1 -3
- package/models/log.model.js.map +1 -1
- package/models/logged-in-users.model.js +1 -3
- package/models/logged-in-users.model.js.map +1 -1
- package/models/method-response.model.js +1 -3
- package/models/method-response.model.js.map +1 -1
- package/models/method.model.js +1 -3
- package/models/method.model.js.map +1 -1
- package/models/monitor-cpu.model.js +1 -3
- package/models/monitor-cpu.model.js.map +1 -1
- package/models/monitor-memory.model.js +1 -3
- package/models/monitor-memory.model.js.map +1 -1
- package/models/monitor-mongo.model.js +1 -3
- package/models/monitor-mongo.model.js.map +1 -1
- package/models/notification.model.js +1 -3
- package/models/notification.model.js.map +1 -1
- package/models/pagination.model.js +1 -23
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +1 -3
- package/models/permission.model.js.map +1 -1
- package/models/report-builder-dashboard-builder.model.js +1 -3
- package/models/report-builder-dashboard-builder.model.js.map +1 -1
- package/models/report-builder-library.model.js +1 -3
- package/models/report-builder-library.model.js.map +1 -1
- package/models/report-builder-report.model.js +1 -3
- package/models/report-builder-report.model.js.map +1 -1
- package/models/report-builder.model.js +1 -3
- package/models/report-builder.model.js.map +1 -1
- package/models/select-data-label.model.js +1 -3
- package/models/select-data-label.model.js.map +1 -1
- package/models/server-response.model.js +1 -3
- package/models/server-response.model.js.map +1 -1
- package/models/subscription.model.js +1 -3
- package/models/subscription.model.js.map +1 -1
- package/models/support-ticket.model.js +1 -3
- package/models/support-ticket.model.js.map +1 -1
- package/models/user-group.model.js +1 -3
- package/models/user-group.model.js.map +1 -1
- package/models/user-guide.model.js +1 -3
- package/models/user-guide.model.js.map +1 -1
- package/models/user.model.js +1 -3
- package/models/user.model.js.map +1 -1
- package/package.json +6 -4
- package/public_api.js +1 -74
- package/public_api.js.map +1 -1
- package/publications/app-status.js +1 -16
- package/publications/app-status.js.map +1 -1
- package/publications/cron-jobs.js +1 -32
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +1 -36
- package/publications/files.js.map +1 -1
- package/publications/flags.js +1 -22
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +1 -164
- package/publications/logs.js.map +1 -1
- package/publications/method-responses.js +1 -16
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +1 -16
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +1 -42
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +1 -89
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +1 -50
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +1 -16
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +1 -16
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +1 -16
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +1 -770
- package/server-app.js.map +1 -1
- package/util/common.js +1 -546
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +1 -452
- package/util/schema-report-builder.js.map +1 -1
package/methods/collections.js
CHANGED
|
@@ -1,500 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadCollectionMethods = void 0;
|
|
4
|
-
var common_1 = require("../util/common");
|
|
5
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
6
|
-
var pagination_model_1 = require("../models/pagination.model");
|
|
7
|
-
var index_1 = require("../index");
|
|
8
|
-
var mongo_manager_1 = require("../managers/mongo.manager");
|
|
9
|
-
function loadCollectionMethods(methodManager) {
|
|
10
|
-
methodManager.methods({
|
|
11
|
-
collectionListAll: {
|
|
12
|
-
function: function () {
|
|
13
|
-
return new Promise(function (resolve, reject) {
|
|
14
|
-
resolve(index_1.ResolveIOServer.getMongoManager().collections().map(function (a) { return a.collectionName; }).sort(function (a, b) { return a.localeCompare(b); }));
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
collectionListRB: {
|
|
19
|
-
function: function () {
|
|
20
|
-
return new Promise(function (resolve, reject) {
|
|
21
|
-
resolve(index_1.ResolveIOServer.getMongoManager().collections().filter(function (a) { return a.useRB; }).map(function (a) { return a.collectionName; }).sort(function (a, b) { return a.localeCompare(b); }));
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
// Query database for any collection and query
|
|
26
|
-
findOne: {
|
|
27
|
-
check: new simpl_schema_1.default({
|
|
28
|
-
collection: {
|
|
29
|
-
type: String
|
|
30
|
-
},
|
|
31
|
-
query: {
|
|
32
|
-
type: Object,
|
|
33
|
-
blackbox: true
|
|
34
|
-
}
|
|
35
|
-
}),
|
|
36
|
-
function: function (collection, query) {
|
|
37
|
-
if (query === void 0) { query = {}; }
|
|
38
|
-
return new Promise(function (resolve, reject) {
|
|
39
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
40
|
-
reject('Invalid collection');
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne(query).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
find: {
|
|
49
|
-
check: new simpl_schema_1.default({
|
|
50
|
-
collection: {
|
|
51
|
-
type: String
|
|
52
|
-
},
|
|
53
|
-
query: {
|
|
54
|
-
type: Object,
|
|
55
|
-
blackbox: true
|
|
56
|
-
},
|
|
57
|
-
sort: {
|
|
58
|
-
type: Object,
|
|
59
|
-
blackbox: true,
|
|
60
|
-
optional: true
|
|
61
|
-
}
|
|
62
|
-
}),
|
|
63
|
-
function: function (collection, query, sortQuery) {
|
|
64
|
-
if (query === void 0) { query = {}; }
|
|
65
|
-
if (sortQuery === void 0) { sortQuery = {}; }
|
|
66
|
-
return new Promise(function (resolve, reject) {
|
|
67
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
68
|
-
reject('Invalid collection');
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).find(query, { sort: sortQuery }).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
findWithOptions: {
|
|
77
|
-
check: new simpl_schema_1.default({
|
|
78
|
-
collection: {
|
|
79
|
-
type: String
|
|
80
|
-
},
|
|
81
|
-
query: {
|
|
82
|
-
type: Object,
|
|
83
|
-
blackbox: true
|
|
84
|
-
},
|
|
85
|
-
options: {
|
|
86
|
-
type: pagination_model_1.PaginationOptionsSchema
|
|
87
|
-
}
|
|
88
|
-
}),
|
|
89
|
-
function: function (collection, query, options) {
|
|
90
|
-
return new Promise(function (resolve, reject) {
|
|
91
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
92
|
-
reject('Invalid collection');
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
var optionsQuery = {};
|
|
96
|
-
if (options.fields && Object.keys(options.fields).length) {
|
|
97
|
-
optionsQuery['projection'] = options.fields;
|
|
98
|
-
}
|
|
99
|
-
if (options.sort && Object.keys(options.sort).length) {
|
|
100
|
-
optionsQuery['sort'] = options.sort;
|
|
101
|
-
}
|
|
102
|
-
if (options.limit) {
|
|
103
|
-
optionsQuery['limit'] = options.limit;
|
|
104
|
-
}
|
|
105
|
-
if (options.skip) {
|
|
106
|
-
optionsQuery['skip'] = options.skip;
|
|
107
|
-
}
|
|
108
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).find(query, optionsQuery).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
// Insert 1 document
|
|
114
|
-
// @Inputs: collection, document
|
|
115
|
-
// @Outputs: res = _id of new document, err = not inserted
|
|
116
|
-
insertDocument: {
|
|
117
|
-
check: new simpl_schema_1.default({
|
|
118
|
-
collection: {
|
|
119
|
-
type: String
|
|
120
|
-
},
|
|
121
|
-
document: {
|
|
122
|
-
type: Object,
|
|
123
|
-
blackbox: true
|
|
124
|
-
}
|
|
125
|
-
}),
|
|
126
|
-
function: function (collection, document) {
|
|
127
|
-
return new Promise(function (resolve, reject) {
|
|
128
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
129
|
-
reject('Invalid collection');
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
var id_1 = (0, mongo_manager_1.objectIdHexString)();
|
|
133
|
-
document['_id'] = id_1;
|
|
134
|
-
document['__v'] = 0;
|
|
135
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).insertOne(document).then(function () { return resolve(id_1); }, function (err) { return reject(err); });
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
// Insert 1 document
|
|
141
|
-
// @Inputs: collection, document
|
|
142
|
-
// @Outputs: res = _id of new document, err = not inserted
|
|
143
|
-
insertManyDocuments: {
|
|
144
|
-
check: new simpl_schema_1.default({
|
|
145
|
-
collection: {
|
|
146
|
-
type: String
|
|
147
|
-
},
|
|
148
|
-
documents: {
|
|
149
|
-
type: Array
|
|
150
|
-
},
|
|
151
|
-
'documents.$': {
|
|
152
|
-
type: Object,
|
|
153
|
-
blackbox: true
|
|
154
|
-
}
|
|
155
|
-
}),
|
|
156
|
-
function: function (collection, documents) {
|
|
157
|
-
return new Promise(function (resolve, reject) {
|
|
158
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
159
|
-
reject('Invalid collection');
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
documents.forEach(function (document) {
|
|
163
|
-
document['_id'] = (0, mongo_manager_1.objectIdHexString)();
|
|
164
|
-
document['__v'] = 0;
|
|
165
|
-
});
|
|
166
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).insertMany(documents).then(function () { return resolve(documents.map(function (a) { return a['_id']; })); }, function (err) { return reject(err); });
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
// Replaces 1 document with new document (from _id)
|
|
172
|
-
// @Inputs: collection, document id
|
|
173
|
-
// @Outputs: res = 1 (updated 1), err = not updated/wrong version
|
|
174
|
-
// Search for doc, check version, if found then try and update
|
|
175
|
-
updateDocument: {
|
|
176
|
-
check: new simpl_schema_1.default({
|
|
177
|
-
collection: {
|
|
178
|
-
type: String
|
|
179
|
-
},
|
|
180
|
-
f_document: {
|
|
181
|
-
type: Object,
|
|
182
|
-
blackbox: true
|
|
183
|
-
}
|
|
184
|
-
}),
|
|
185
|
-
function: function (collection, f_document) {
|
|
186
|
-
return new Promise(function (resolve, reject) {
|
|
187
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
188
|
-
reject('Invalid collection');
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document).then(function (res) { return resolve(res); }, function (err) { return reject(err); });
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
// Updates 1 document's props (from _id)
|
|
197
|
-
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
198
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
199
|
-
// Search for doc, check version, if found then try and update props
|
|
200
|
-
updateDocumentProps: {
|
|
201
|
-
check: new simpl_schema_1.default({
|
|
202
|
-
collection: {
|
|
203
|
-
type: String
|
|
204
|
-
},
|
|
205
|
-
doc_id: {
|
|
206
|
-
type: String
|
|
207
|
-
},
|
|
208
|
-
updateParams: {
|
|
209
|
-
type: Array
|
|
210
|
-
},
|
|
211
|
-
'updateParams.$': {
|
|
212
|
-
type: Object,
|
|
213
|
-
blackbox: true
|
|
214
|
-
},
|
|
215
|
-
doc__v: {
|
|
216
|
-
type: Number,
|
|
217
|
-
optional: true
|
|
218
|
-
}
|
|
219
|
-
}),
|
|
220
|
-
function: function (collection, doc_id, updateParams, doc__v) {
|
|
221
|
-
return new Promise(function (resolve, reject) {
|
|
222
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
223
|
-
reject('Invalid collection');
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id }).then(function (currDoc) {
|
|
227
|
-
if (currDoc) {
|
|
228
|
-
var modifiedDoc_1 = (0, common_1.deepCopy)(currDoc);
|
|
229
|
-
updateParams.forEach(function (data) {
|
|
230
|
-
modifiedDoc_1[data.prop] = data.data;
|
|
231
|
-
});
|
|
232
|
-
if (!doc__v || modifiedDoc_1.__v === doc__v) {
|
|
233
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc_1._id }, modifiedDoc_1, {}, false, false, currDoc).then(function (res) {
|
|
234
|
-
resolve(res);
|
|
235
|
-
}, function (err) { return reject(err); });
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
console.log(new Date(), 'invalid version - ' + collection, currDoc.__v, doc__v);
|
|
239
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
240
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
241
|
-
_id: {
|
|
242
|
-
_id: currDoc._id,
|
|
243
|
-
__v: doc__v
|
|
244
|
-
}
|
|
245
|
-
}).then(function (oldDoc) {
|
|
246
|
-
var newCurrDocId = currDoc._id;
|
|
247
|
-
var newCurrDocV = currDoc.__v;
|
|
248
|
-
if (oldDoc) {
|
|
249
|
-
var updatedDoc = (0, common_1.getMongoMergeUpdatedDoc)(modifiedDoc_1, currDoc, oldDoc);
|
|
250
|
-
updatedDoc._id = newCurrDocId;
|
|
251
|
-
updatedDoc.__v = newCurrDocV;
|
|
252
|
-
currDoc._id = newCurrDocId;
|
|
253
|
-
currDoc.__v = newCurrDocV;
|
|
254
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
255
|
-
resolve(res);
|
|
256
|
-
}, function (err) { return reject(err); });
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
reject('Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV + ', Trying to update with :' + doc__v);
|
|
260
|
-
}
|
|
261
|
-
}, function () { });
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
reject('No Document');
|
|
270
|
-
}
|
|
271
|
-
}, function () { });
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
updateDocumentOffline: {
|
|
277
|
-
check: new simpl_schema_1.default({
|
|
278
|
-
collection: {
|
|
279
|
-
type: String
|
|
280
|
-
},
|
|
281
|
-
f_document: {
|
|
282
|
-
type: Object,
|
|
283
|
-
blackbox: true
|
|
284
|
-
}
|
|
285
|
-
}),
|
|
286
|
-
function: function (collection, f_document) {
|
|
287
|
-
return new Promise(function (resolve, reject) {
|
|
288
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
289
|
-
reject('Invalid collection');
|
|
290
|
-
}
|
|
291
|
-
else {
|
|
292
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: f_document['_id'] }).then(function (currDoc) {
|
|
293
|
-
if (currDoc) {
|
|
294
|
-
if (currDoc.__v === f_document['__v']) {
|
|
295
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: f_document['_id'] }, f_document, {}, false, false, currDoc).then(function (res) {
|
|
296
|
-
resolve(res);
|
|
297
|
-
}, function (err) { return reject(err); });
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, f_document['__v']);
|
|
301
|
-
var newCurrDocId_1 = currDoc._id;
|
|
302
|
-
var newCurrDocV_1 = currDoc.__v;
|
|
303
|
-
var oldDocV_1 = f_document['__v'];
|
|
304
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
305
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
306
|
-
_id: {
|
|
307
|
-
_id: newCurrDocId_1,
|
|
308
|
-
__v: oldDocV_1
|
|
309
|
-
}
|
|
310
|
-
}).then(function (oldDoc) {
|
|
311
|
-
if (oldDoc) {
|
|
312
|
-
var updatedDoc = (0, common_1.getMongoMergeUpdatedDoc)(f_document, currDoc, oldDoc);
|
|
313
|
-
updatedDoc._id = newCurrDocId_1;
|
|
314
|
-
updatedDoc.__v = newCurrDocV_1;
|
|
315
|
-
currDoc._id = newCurrDocId_1;
|
|
316
|
-
currDoc.__v = newCurrDocV_1;
|
|
317
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId_1 }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
318
|
-
resolve(res);
|
|
319
|
-
}, function (err) { return reject(err); });
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV_1 + ', Trying to update with :' + oldDocV_1);
|
|
323
|
-
}
|
|
324
|
-
}, function () { });
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
reject('No Document');
|
|
333
|
-
}
|
|
334
|
-
}, function () { });
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
},
|
|
339
|
-
// Updates 1 document's props (from _id)
|
|
340
|
-
// @Inputs: collection, document id, document version, update paramters ({prop: 'xxx', data: 'yyy})
|
|
341
|
-
// @Outputs: res = 1 (updated 1), res = 0 (not updated), err = not updated/wrong version
|
|
342
|
-
// Search for doc, check version, if found then try and update props
|
|
343
|
-
updateDocumentPropsOffline: {
|
|
344
|
-
check: new simpl_schema_1.default({
|
|
345
|
-
collection: {
|
|
346
|
-
type: String
|
|
347
|
-
},
|
|
348
|
-
doc_id: {
|
|
349
|
-
type: String
|
|
350
|
-
},
|
|
351
|
-
updateParams: {
|
|
352
|
-
type: Array
|
|
353
|
-
},
|
|
354
|
-
'updateParams.$': {
|
|
355
|
-
type: Object,
|
|
356
|
-
blackbox: true
|
|
357
|
-
},
|
|
358
|
-
doc__v: {
|
|
359
|
-
type: Number
|
|
360
|
-
}
|
|
361
|
-
}),
|
|
362
|
-
function: function (collection, doc_id, updateParams, doc__v) {
|
|
363
|
-
return new Promise(function (resolve, reject) {
|
|
364
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
365
|
-
reject('Invalid collection');
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).findOne({ _id: doc_id }, null, true).then(function (currDoc) {
|
|
369
|
-
if (currDoc) {
|
|
370
|
-
var modifiedDoc_2 = (0, common_1.deepCopy)(currDoc);
|
|
371
|
-
updateParams.forEach(function (data) {
|
|
372
|
-
modifiedDoc_2[data.prop] = data.data;
|
|
373
|
-
});
|
|
374
|
-
if (modifiedDoc_2.__v === doc__v) {
|
|
375
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: modifiedDoc_2._id }, modifiedDoc_2, {}, false, false, currDoc).then(function (res) {
|
|
376
|
-
resolve(res);
|
|
377
|
-
}, function (err) { return reject(err); });
|
|
378
|
-
}
|
|
379
|
-
else {
|
|
380
|
-
console.log('OFFLINE - invalid version - ' + collection, currDoc.__v, doc__v);
|
|
381
|
-
var newCurrDocId_2 = currDoc._id;
|
|
382
|
-
var newCurrDocV_2 = currDoc.__v;
|
|
383
|
-
if (index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions')) {
|
|
384
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection + '.versions').findOne({
|
|
385
|
-
_id: {
|
|
386
|
-
_id: currDoc._id,
|
|
387
|
-
__v: doc__v
|
|
388
|
-
}
|
|
389
|
-
}).then(function (oldDoc) {
|
|
390
|
-
if (oldDoc) {
|
|
391
|
-
var updatedDoc = (0, common_1.getMongoMergeUpdatedDoc)(modifiedDoc_2, currDoc, oldDoc);
|
|
392
|
-
updatedDoc._id = newCurrDocId_2;
|
|
393
|
-
updatedDoc.__v = newCurrDocV_2;
|
|
394
|
-
currDoc._id = newCurrDocId_2;
|
|
395
|
-
currDoc.__v = newCurrDocV_2;
|
|
396
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).replaceOne({ _id: newCurrDocId_2 }, updatedDoc, {}, false, false, currDoc).then(function (res) {
|
|
397
|
-
resolve(res);
|
|
398
|
-
}, function (err) { return reject(err); });
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
reject('OFFLINE - Invalid Version And Could Not Find History Props - DB: ' + newCurrDocV_2 + ', Trying to update with :' + doc__v);
|
|
402
|
-
}
|
|
403
|
-
}, function () { });
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
reject('Invalid Version And We Are NOT Using Versions On This Collection!');
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
reject('No Document');
|
|
412
|
-
}
|
|
413
|
-
}, function () { });
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
// Removes 1 document (from _id)
|
|
419
|
-
// @Inputs: collection, document id
|
|
420
|
-
// @Outputs: res = 1 (deleted), res = 0 (not deleted), err = not deleted
|
|
421
|
-
// Search for doc, if found then try and remove
|
|
422
|
-
removeDocument: {
|
|
423
|
-
check: new simpl_schema_1.default({
|
|
424
|
-
collection: {
|
|
425
|
-
type: String
|
|
426
|
-
},
|
|
427
|
-
doc_id: {
|
|
428
|
-
type: String
|
|
429
|
-
}
|
|
430
|
-
}),
|
|
431
|
-
function: function (collection, doc_id) {
|
|
432
|
-
return new Promise(function (resolve, reject) {
|
|
433
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
434
|
-
reject('Invalid collection');
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).deleteOne({ _id: doc_id }).then(function (res) {
|
|
438
|
-
resolve(res);
|
|
439
|
-
}, function (err) {
|
|
440
|
-
reject(err);
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
},
|
|
446
|
-
removeDocumentWithQuery: {
|
|
447
|
-
check: new simpl_schema_1.default({
|
|
448
|
-
collection: {
|
|
449
|
-
type: String
|
|
450
|
-
},
|
|
451
|
-
query: {
|
|
452
|
-
type: Object,
|
|
453
|
-
blackbox: true
|
|
454
|
-
}
|
|
455
|
-
}),
|
|
456
|
-
function: function (collection, query) {
|
|
457
|
-
return new Promise(function (resolve, reject) {
|
|
458
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
459
|
-
reject('Invalid collection');
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).deleteOne(query).then(function (res) {
|
|
463
|
-
resolve(res);
|
|
464
|
-
}, function (err) {
|
|
465
|
-
reject(err);
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
},
|
|
471
|
-
removeDocumentsWithQuery: {
|
|
472
|
-
check: new simpl_schema_1.default({
|
|
473
|
-
collection: {
|
|
474
|
-
type: String
|
|
475
|
-
},
|
|
476
|
-
query: {
|
|
477
|
-
type: Object,
|
|
478
|
-
blackbox: true
|
|
479
|
-
}
|
|
480
|
-
}),
|
|
481
|
-
function: function (collection, query) {
|
|
482
|
-
return new Promise(function (resolve, reject) {
|
|
483
|
-
if (!index_1.ResolveIOServer.getMongoManager().collection(collection)) {
|
|
484
|
-
reject('Invalid collection');
|
|
485
|
-
}
|
|
486
|
-
else {
|
|
487
|
-
index_1.ResolveIOServer.getMongoManager().collection(collection).deleteMany(query).then(function (res) {
|
|
488
|
-
resolve(res);
|
|
489
|
-
}, function (err) {
|
|
490
|
-
reject(err);
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
exports.loadCollectionMethods = loadCollectionMethods;
|
|
499
|
-
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.loadCollectionMethods=void 0;var common_1=require("../util/common"),simpl_schema_1=require("simpl-schema"),pagination_model_1=require("../models/pagination.model"),index_1=require("../index"),mongo_manager_1=require("../managers/mongo.manager");function loadCollectionMethods(e){e.methods({collectionListAll:{function:function(){return new Promise(function(e,n){e(index_1.ResolveIOServer.getMongoManager().collections().map(function(e){return e.collectionName}).sort(function(e,n){return e.localeCompare(n)}))})}},collectionListRB:{function:function(){return new Promise(function(e,n){e(index_1.ResolveIOServer.getMongoManager().collections().filter(function(e){return e.useRB}).map(function(e){return e.collectionName}).sort(function(e,n){return e.localeCompare(n)}))})}},findOne:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,t){return void 0===t&&(t={}),new Promise(function(n,o){index_1.ResolveIOServer.getMongoManager().collection(e)?index_1.ResolveIOServer.getMongoManager().collection(e).findOne(t).then(function(e){return n(e)},function(e){return o(e)}):o("Invalid collection")})}},find:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},sort:{type:Object,blackbox:!0,optional:!0}}),function:function(e,t,i){return void 0===t&&(t={}),void 0===i&&(i={}),new Promise(function(n,o){index_1.ResolveIOServer.getMongoManager().collection(e)?index_1.ResolveIOServer.getMongoManager().collection(e).find(t,{sort:i}).then(function(e){return n(e)},function(e){return o(e)}):o("Invalid collection")})}},findWithOptions:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0},options:{type:pagination_model_1.PaginationOptionsSchema}}),function:function(t,i,c){return new Promise(function(n,o){var e;index_1.ResolveIOServer.getMongoManager().collection(t)?(e={},c.fields&&Object.keys(c.fields).length&&(e.projection=c.fields),c.sort&&Object.keys(c.sort).length&&(e.sort=c.sort),c.limit&&(e.limit=c.limit),c.skip&&(e.skip=c.skip),index_1.ResolveIOServer.getMongoManager().collection(t).find(i,e).then(function(e){return n(e)},function(e){return o(e)})):o("Invalid collection")})}},insertDocument:{check:new simpl_schema_1.default({collection:{type:String},document:{type:Object,blackbox:!0}}),function:function(t,i){return new Promise(function(e,n){var o;index_1.ResolveIOServer.getMongoManager().collection(t)?(o=(0,mongo_manager_1.objectIdHexString)(),i._id=o,i.__v=0,index_1.ResolveIOServer.getMongoManager().collection(t).insertOne(i).then(function(){return e(o)},function(e){return n(e)})):n("Invalid collection")})}},insertManyDocuments:{check:new simpl_schema_1.default({collection:{type:String},documents:{type:Array},"documents.$":{type:Object,blackbox:!0}}),function:function(o,t){return new Promise(function(e,n){index_1.ResolveIOServer.getMongoManager().collection(o)?(t.forEach(function(e){e._id=(0,mongo_manager_1.objectIdHexString)(),e.__v=0}),index_1.ResolveIOServer.getMongoManager().collection(o).insertMany(t).then(function(){return e(t.map(function(e){return e._id}))},function(e){return n(e)})):n("Invalid collection")})}},updateDocument:{check:new simpl_schema_1.default({collection:{type:String},f_document:{type:Object,blackbox:!0}}),function:function(e,t){return new Promise(function(n,o){index_1.ResolveIOServer.getMongoManager().collection(e)?index_1.ResolveIOServer.getMongoManager().collection(e).replaceOne({_id:t._id},t).then(function(e){return n(e)},function(e){return o(e)}):o("Invalid collection")})}},updateDocumentProps:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String},updateParams:{type:Array},"updateParams.$":{type:Object,blackbox:!0},doc__v:{type:Number,optional:!0}}),function:function(l,e,n,a){return new Promise(function(c,r){index_1.ResolveIOServer.getMongoManager().collection(l)?index_1.ResolveIOServer.getMongoManager().collection(l).findOne({_id:e}).then(function(t){var i;t?(i=(0,common_1.deepCopy)(t),n.forEach(function(e){i[e.prop]=e.data}),a&&i.__v!==a?(console.log(new Date,"invalid version - "+l,t.__v,a),index_1.ResolveIOServer.getMongoManager().collection(l+".versions")?index_1.ResolveIOServer.getMongoManager().collection(l+".versions").findOne({_id:{_id:t._id,__v:a}}).then(function(e){var n=t._id,o=t.__v;e?((e=(0,common_1.getMongoMergeUpdatedDoc)(i,t,e))._id=n,e.__v=o,t._id=n,t.__v=o,index_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:n},e,{},!1,!1,t).then(function(e){c(e)},function(e){return r(e)})):r("Invalid Version And Could Not Find History Props - DB: "+o+", Trying to update with :"+a)},function(){}):r("Invalid Version And We Are NOT Using Versions On This Collection!")):index_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:i._id},i,{},!1,!1,t).then(function(e){c(e)},function(e){return r(e)})):r("No Document")},function(){}):r("Invalid collection")})}},updateDocumentOffline:{check:new simpl_schema_1.default({collection:{type:String},f_document:{type:Object,blackbox:!0}}),function:function(l,a){return new Promise(function(c,r){index_1.ResolveIOServer.getMongoManager().collection(l)?index_1.ResolveIOServer.getMongoManager().collection(l).findOne({_id:a._id}).then(function(n){var o,t,i;n?n.__v===a.__v?index_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:a._id},a,{},!1,!1,n).then(function(e){c(e)},function(e){return r(e)}):(console.log("OFFLINE - invalid version - "+l,n.__v,a.__v),o=n._id,t=n.__v,i=a.__v,index_1.ResolveIOServer.getMongoManager().collection(l+".versions")?index_1.ResolveIOServer.getMongoManager().collection(l+".versions").findOne({_id:{_id:o,__v:i}}).then(function(e){e?((e=(0,common_1.getMongoMergeUpdatedDoc)(a,n,e))._id=o,e.__v=t,n._id=o,n.__v=t,index_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:o},e,{},!1,!1,n).then(function(e){c(e)},function(e){return r(e)})):r("OFFLINE - Invalid Version And Could Not Find History Props - DB: "+t+", Trying to update with :"+i)},function(){}):r("Invalid Version And We Are NOT Using Versions On This Collection!")):r("No Document")},function(){}):r("Invalid collection")})}},updateDocumentPropsOffline:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String},updateParams:{type:Array},"updateParams.$":{type:Object,blackbox:!0},doc__v:{type:Number}}),function:function(l,e,a,u){return new Promise(function(c,r){index_1.ResolveIOServer.getMongoManager().collection(l)?index_1.ResolveIOServer.getMongoManager().collection(l).findOne({_id:e},null,!0).then(function(n){var o,t,i;n?(o=(0,common_1.deepCopy)(n),a.forEach(function(e){o[e.prop]=e.data}),o.__v===u?index_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:o._id},o,{},!1,!1,n).then(function(e){c(e)},function(e){return r(e)}):(console.log("OFFLINE - invalid version - "+l,n.__v,u),t=n._id,i=n.__v,index_1.ResolveIOServer.getMongoManager().collection(l+".versions")?index_1.ResolveIOServer.getMongoManager().collection(l+".versions").findOne({_id:{_id:n._id,__v:u}}).then(function(e){e?((e=(0,common_1.getMongoMergeUpdatedDoc)(o,n,e))._id=t,e.__v=i,n._id=t,n.__v=i,index_1.ResolveIOServer.getMongoManager().collection(l).replaceOne({_id:t},e,{},!1,!1,n).then(function(e){c(e)},function(e){return r(e)})):r("OFFLINE - Invalid Version And Could Not Find History Props - DB: "+i+", Trying to update with :"+u)},function(){}):r("Invalid Version And We Are NOT Using Versions On This Collection!"))):r("No Document")},function(){}):r("Invalid collection")})}},removeDocument:{check:new simpl_schema_1.default({collection:{type:String},doc_id:{type:String}}),function:function(e,t){return new Promise(function(n,o){index_1.ResolveIOServer.getMongoManager().collection(e)?index_1.ResolveIOServer.getMongoManager().collection(e).deleteOne({_id:t}).then(function(e){n(e)},function(e){o(e)}):o("Invalid collection")})}},removeDocumentWithQuery:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,t){return new Promise(function(n,o){index_1.ResolveIOServer.getMongoManager().collection(e)?index_1.ResolveIOServer.getMongoManager().collection(e).deleteOne(t).then(function(e){n(e)},function(e){o(e)}):o("Invalid collection")})}},removeDocumentsWithQuery:{check:new simpl_schema_1.default({collection:{type:String},query:{type:Object,blackbox:!0}}),function:function(e,t){return new Promise(function(n,o){index_1.ResolveIOServer.getMongoManager().collection(e)?index_1.ResolveIOServer.getMongoManager().collection(e).deleteMany(t).then(function(e){n(e)},function(e){o(e)}):o("Invalid collection")})}}})}exports.loadCollectionMethods=loadCollectionMethods;
|
|
500
2
|
//# sourceMappingURL=collections.js.map
|