isite 2024.8.5 → 2024.8.7
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/LICENSE +21 -21
- package/README.md +1384 -1387
- package/apps/charts/site_files/html/PieChart.html +35 -35
- package/apps/charts/site_files/html/PieChart2.html +35 -35
- package/apps/charts/site_files/html/XYChart.html +42 -42
- package/apps/charts/site_files/html/column.html +60 -60
- package/apps/charts/site_files/html/gauge.html +44 -44
- package/apps/charts/site_files/html/index.html +92 -92
- package/apps/charts/site_files/html/line-graph.html +42 -42
- package/apps/charts/site_files/html/pie-chart-rounded-corners.html +38 -38
- package/apps/charts/site_files/html/simple-3D-pie-chart.html +43 -43
- package/apps/charts/site_files/js/chart-animated.js +2 -2
- package/apps/charts/site_files/json/PieChart.json +41 -41
- package/apps/charts/site_files/json/PieChart2.json +23 -23
- package/apps/charts/site_files/json/XYChart.json +74 -74
- package/apps/charts/site_files/json/bar-chart.json +99 -99
- package/apps/charts/site_files/json/column-chart.json +80 -80
- package/apps/charts/site_files/json/gauge.json +36 -36
- package/apps/charts/site_files/json/line-graph.json +1867 -1867
- package/apps/charts/site_files/json/pie-chart-rounded-corners.json +42 -42
- package/apps/charts/site_files/json/simple-3D-pie-chart.json +50 -50
- package/apps/client-side/package-lock.json +5 -5
- package/apps/client-side/package.json +21 -21
- package/apps/client-side/site_files/css/bootstrap3.css +5 -5
- package/apps/client-side/site_files/css/bootstrap4.css +6 -6
- package/apps/client-side/site_files/css/bootstrap5.css +6 -6
- package/apps/client-side/site_files/css/checkbox.css +125 -125
- package/apps/client-side/site_files/css/font-awesome.css +4616 -4616
- package/apps/client-side/site_files/css/font-awesome.min.css +4 -4
- package/apps/client-side/site_files/css/fonts.css +85 -85
- package/apps/client-side/site_files/css/help.css +51 -51
- package/apps/client-side/site_files/css/main-menu.css +66 -66
- package/apps/client-side/site_files/css/print.css +144 -144
- package/apps/client-side/site_files/css/prism.css +139 -139
- package/apps/client-side/site_files/css/progress.css +7 -7
- package/apps/client-side/site_files/css/radio.css +103 -103
- package/apps/client-side/site_files/css/scrollbar.css +13 -13
- package/apps/client-side/site_files/css/semantic.css +363 -363
- package/apps/client-side/site_files/css/table.css +87 -87
- package/apps/client-side/site_files/css/treeview.css +84 -84
- package/apps/client-side/site_files/css/ui.css +28 -28
- package/apps/client-side/site_files/css/video-js.min.css +1 -0
- package/apps/client-side/site_files/fonts/fontawesome-webfont.svg +2671 -2671
- package/apps/client-side/site_files/fonts/glyphicons-halflings-regular.svg +287 -287
- package/apps/client-side/site_files/fonts/icons.svg +684 -684
- package/apps/client-side/site_files/js/Youtube.min.js +1 -0
- package/apps/client-side/site_files/js/angular-animate.js +4179 -4179
- package/apps/client-side/site_files/js/angular.js +36599 -36599
- package/apps/client-side/site_files/js/angular.min.js +351 -351
- package/apps/client-side/site_files/js/angular.min.js.map +8 -8
- package/apps/client-side/site_files/js/barcode.js +1 -1
- package/apps/client-side/site_files/js/base64.js +319 -319
- package/apps/client-side/site_files/js/bootstrap-5-directive.js +1456 -1456
- package/apps/client-side/site_files/js/bootstrap3.js +6 -6
- package/apps/client-side/site_files/js/bootstrap4.js +6 -6
- package/apps/client-side/site_files/js/bootstrap5.js +6 -6
- package/apps/client-side/site_files/js/custom.js +149 -149
- package/apps/client-side/site_files/js/directive.min.js +1 -1
- package/apps/client-side/site_files/js/hijri.js +965 -965
- package/apps/client-side/site_files/js/jquery.js +2 -2
- package/apps/client-side/site_files/js/moment.js +4511 -4511
- package/apps/client-side/site_files/js/prism.js +6 -6
- package/apps/client-side/site_files/js/qrcode.js +1398 -1398
- package/apps/client-side/site_files/js/semantic.js +10 -10
- package/apps/client-side/site_files/js/video.min.js +53 -0
- package/apps/client-side/site_files/js/xlsx.js +23 -23
- package/apps/client-side/site_files/semantic-themes/default/assets/fonts/brand-icons.svg +1008 -1008
- package/apps/client-side/site_files/semantic-themes/default/assets/fonts/icons.svg +1518 -1518
- package/apps/client-side/site_files/semantic-themes/default/assets/fonts/outline-icons.svg +366 -366
- package/apps/client-side/site_files/webfonts/fa-brands-400.svg +3717 -3717
- package/apps/client-side/site_files/webfonts/fa-regular-400.svg +801 -801
- package/apps/client-side/site_files/webfonts/fa-solid-900.svg +5034 -5034
- package/apps/security/README.md +12 -12
- package/apps/security/app.js +288 -288
- package/apps/security/libs/notifications.js +89 -89
- package/apps/security/site_files/html/add_modal.html +36 -36
- package/apps/security/site_files/html/content.html +36 -36
- package/apps/security/site_files/html/delete_modal.html +31 -31
- package/apps/security/site_files/html/head.html +7 -7
- package/apps/security/site_files/html/index.html +80 -80
- package/apps/security/site_files/html/login_modal.html +24 -24
- package/apps/security/site_files/html/logout_modal.html +21 -21
- package/apps/security/site_files/html/navbar.html +8 -8
- package/apps/security/site_files/html/register_modal.html +32 -32
- package/apps/security/site_files/html/update_modal.html +28 -28
- package/apps/security/site_files/html/view.html +74 -74
- package/apps/security/site_files/html/view_modal.html +32 -32
- package/apps/security/site_files/js/app.js +1 -1
- package/apps/security/site_files/js/index.js +278 -278
- package/apps/security/site_files/js/login.js +35 -35
- package/apps/security/site_files/js/logout.js +22 -22
- package/apps/security/site_files/js/navbar.js +26 -26
- package/apps/security/site_files/js/register.js +30 -30
- package/apps/security/site_files/json/permissions.json +7 -7
- package/apps/security/site_files/json/roles.json +33 -33
- package/apps/security/site_files/json/words.json +28 -28
- package/gulpfile.js +17 -17
- package/isite.postman_collection.json +7 -7
- package/isite_files/css/bootstrap.css +5 -5
- package/isite_files/css/font-awesome.css +4 -4
- package/isite_files/css/prism.css +139 -139
- package/isite_files/fonts/fontawesome-webfont.svg +2671 -2671
- package/isite_files/fonts/glyphicons-halflings-regular.svg +287 -287
- package/isite_files/html/files.html +9 -9
- package/isite_files/html/head.html +12 -12
- package/isite_files/html/index.html +30 -30
- package/isite_files/html/installing.html +27 -27
- package/isite_files/html/navbar.html +51 -51
- package/isite_files/html/routes.html +13 -13
- package/isite_files/html/sessions.html +13 -13
- package/isite_files/html/vars.html +9 -9
- package/isite_files/js/angular.js +334 -334
- package/isite_files/js/bootstrap.js +6 -6
- package/isite_files/js/custom.js +149 -149
- package/isite_files/js/jquery.js +4 -4
- package/isite_files/js/prism.js +6 -6
- package/lib/README.md +1 -1
- package/lib/collection.js +92 -41
- package/lib/collectionFile.js +21 -18
- package/lib/cookie.js +81 -81
- package/lib/dashboard.js +189 -189
- package/lib/mongodb.js +819 -756
- package/lib/parser.js +910 -910
- package/lib/security.js +48 -57
- package/lib/session.js +153 -153
- package/object-options/index.js +3 -3
- package/object-options/lib/isite.code-workspace +10 -10
- package/package.json +58 -58
- package/ssl/create_ssl.sh +3 -3
package/lib/mongodb.js
CHANGED
|
@@ -1,756 +1,819 @@
|
|
|
1
|
-
module.exports = function init(____0) {
|
|
2
|
-
const mongodb = require('mongodb');
|
|
3
|
-
|
|
4
|
-
let url = '';
|
|
5
|
-
if (!____0.options.mongodb.url) {
|
|
6
|
-
url = ____0.options.mongodb.host + ':' + ____0.options.mongodb.port;
|
|
7
|
-
if (____0.options.mongodb.
|
|
8
|
-
url = encodeURIComponent(____0.options.mongodb.
|
|
9
|
-
}
|
|
10
|
-
url = ____0.options.mongodb.protocal + url;
|
|
11
|
-
} else {
|
|
12
|
-
url = encodeURI(____0.options.mongodb.url);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const _mongo = function () {};
|
|
16
|
-
|
|
17
|
-
_mongo.lib = mongodb;
|
|
18
|
-
|
|
19
|
-
_mongo.ObjectID = mongodb.ObjectId;
|
|
20
|
-
_mongo.connection = url;
|
|
21
|
-
_mongo.collections_indexed = [];
|
|
22
|
-
|
|
23
|
-
//ulimit -n 10000
|
|
24
|
-
_mongo.dbList = [];
|
|
25
|
-
|
|
26
|
-
_mongo.connections = [];
|
|
27
|
-
_mongo.closeDbBusy = !1;
|
|
28
|
-
____0.on('[close-database]', (args, callback) => {
|
|
29
|
-
callback = callback || function () {};
|
|
30
|
-
|
|
31
|
-
if (_mongo.closeDbBusy == !0) {
|
|
32
|
-
setTimeout(() => {
|
|
33
|
-
____0.call('[close-database]', args, callback);
|
|
34
|
-
}, 2000);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (_mongo.connections.length === 0) {
|
|
39
|
-
callback();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_mongo.closeDbBusy = !0;
|
|
44
|
-
console.log('Closing mongodb Connection Count : ' + _mongo.connections.length);
|
|
45
|
-
for (let i = 0; i < _mongo.connections.length; i++) {
|
|
46
|
-
console.log('Closing Database : ' + _mongo.connections[i].name);
|
|
47
|
-
_mongo.connections[i].client.close();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
setTimeout(() => {
|
|
51
|
-
_mongo.closeDbBusy = !1;
|
|
52
|
-
callback();
|
|
53
|
-
}, 1000);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
_mongo.handleDoc = function (doc, isProperty = false) {
|
|
57
|
-
if (!doc) {
|
|
58
|
-
return doc;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (Array.isArray(doc)) {
|
|
62
|
-
doc.forEach((v, i) => {
|
|
63
|
-
doc[i] = _mongo.handleDoc(v, true);
|
|
64
|
-
});
|
|
65
|
-
return doc;
|
|
66
|
-
} else if (typeof doc === 'object') {
|
|
67
|
-
for (let key in doc) {
|
|
68
|
-
if (typeof key === 'string' && key.indexOf('$') === 0) {
|
|
69
|
-
delete doc[key];
|
|
70
|
-
} else if (typeof doc[key] === 'string' && ____0.fn.isDate(doc[key])) {
|
|
71
|
-
doc[key] = new Date(doc[key]);
|
|
72
|
-
} else if (Array.isArray(doc[key])) {
|
|
73
|
-
doc[key].forEach((v, i) => {
|
|
74
|
-
doc[key][i] = _mongo.handleDoc(v, true);
|
|
75
|
-
});
|
|
76
|
-
} else if (typeof doc[key] === 'object') {
|
|
77
|
-
doc[key] = _mongo.handleDoc(doc[key], true);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return isProperty ? doc : { ...doc };
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
_mongo.connectDBBusy = !1;
|
|
86
|
-
_mongo.connectDB = async function (name, callback) {
|
|
87
|
-
if (_mongo.connectDBBusy === !0) {
|
|
88
|
-
setTimeout(() => {
|
|
89
|
-
_mongo.connectDB(name, callback);
|
|
90
|
-
}, 100);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
_mongo.connectDBBusy = !0;
|
|
95
|
-
|
|
96
|
-
if (name === undefined) {
|
|
97
|
-
name = ____0.options.mongodb.db;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!____0.options.mongodb.enabled) {
|
|
101
|
-
callback(
|
|
102
|
-
{
|
|
103
|
-
message: 'mongodb Not Enabled',
|
|
104
|
-
},
|
|
105
|
-
null
|
|
106
|
-
);
|
|
107
|
-
_mongo.connectDBBusy = !1;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
for (let i = 0; i < _mongo.connections.length; i++) {
|
|
112
|
-
if (_mongo.connections[i].name === name) {
|
|
113
|
-
callback(null, _mongo.connections[i].db);
|
|
114
|
-
_mongo.connectDBBusy = !1;
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
let db_name = ____0.options.mongodb.prefix.db + name;
|
|
120
|
-
let db_url = _mongo.connection;
|
|
121
|
-
____0.log('\n ( Connecting DB : ' + db_url + ' ) \n');
|
|
122
|
-
const mongodbClient = new mongodb.MongoClient(db_url, {
|
|
123
|
-
serverSelectionTimeoutMS: 1000 * 60,
|
|
124
|
-
connectTimeoutMS: 1000 * 60,
|
|
125
|
-
socketTimeoutMS: 1000 * 60 * 5,
|
|
126
|
-
...____0.options.mongodb.config,
|
|
127
|
-
});
|
|
128
|
-
mongodbClient
|
|
129
|
-
.connect()
|
|
130
|
-
.then((client) => {
|
|
131
|
-
if (client) {
|
|
132
|
-
const db = client.db(db_name);
|
|
133
|
-
|
|
134
|
-
_mongo.connections.push({
|
|
135
|
-
name: name,
|
|
136
|
-
url: db_url,
|
|
137
|
-
db: db,
|
|
138
|
-
client: client,
|
|
139
|
-
connected: !0,
|
|
140
|
-
});
|
|
141
|
-
____0.log('\n ( Connected DB : ' + db_name + ' ) : ' + db_url + '\n');
|
|
142
|
-
callback(null, db);
|
|
143
|
-
} else {
|
|
144
|
-
err.message += ' , ' + db_url;
|
|
145
|
-
____0.log('\n ( Connected DB Error: ' + err.message + ' ) \n');
|
|
146
|
-
____0.log(err);
|
|
147
|
-
callback(err, null);
|
|
148
|
-
}
|
|
149
|
-
_mongo.connectDBBusy = !1;
|
|
150
|
-
})
|
|
151
|
-
.catch((err) => {
|
|
152
|
-
____0.log(err);
|
|
153
|
-
callback(err, null);
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
_mongo.createIndex = function (options, callback) {
|
|
158
|
-
callback =
|
|
159
|
-
callback ||
|
|
160
|
-
function (...args) {
|
|
161
|
-
console.log(args);
|
|
162
|
-
};
|
|
163
|
-
_mongo.connectDB(options.dbName, function (err, db) {
|
|
164
|
-
if (!err) {
|
|
165
|
-
if (options.collectionName === undefined) {
|
|
166
|
-
options.collectionName = ____0.options.mongodb.collection;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
db.collection(____0.options.mongodb.prefix.collection + options.collectionName)
|
|
170
|
-
.createIndex(options.obj, options.option)
|
|
171
|
-
.then((result) => {
|
|
172
|
-
callback(null, result);
|
|
173
|
-
if (____0.options.mongodb.events) {
|
|
174
|
-
____0.call('mongodb after create index', {
|
|
175
|
-
db: options.dbName,
|
|
176
|
-
collection: options.collectionName,
|
|
177
|
-
obj: options.obj,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
.catch((err) => {
|
|
182
|
-
callback(err);
|
|
183
|
-
});
|
|
184
|
-
} else {
|
|
185
|
-
callback(err);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
db.collection(____0.options.mongodb.prefix.collection +
|
|
202
|
-
.
|
|
203
|
-
.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
})
|
|
295
|
-
.catch((err) => {
|
|
296
|
-
callback(err);
|
|
297
|
-
});
|
|
298
|
-
} else {
|
|
299
|
-
callback(err);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
_mongo.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
.
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
)
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
1
|
+
module.exports = function init(____0) {
|
|
2
|
+
const mongodb = require('mongodb');
|
|
3
|
+
|
|
4
|
+
let url = '';
|
|
5
|
+
if (!____0.options.mongodb.url) {
|
|
6
|
+
url = ____0.options.mongodb.host + ':' + ____0.options.mongodb.port;
|
|
7
|
+
if (____0.options.mongodb.username && ____0.options.mongodb.password) {
|
|
8
|
+
url = encodeURIComponent(____0.options.mongodb.username) + ':' + encodeURIComponent(____0.options.mongodb.password) + '@' + ____0.options.mongodb.host + ':' + ____0.options.mongodb.port;
|
|
9
|
+
}
|
|
10
|
+
url = ____0.options.mongodb.protocal + url;
|
|
11
|
+
} else {
|
|
12
|
+
url = encodeURI(____0.options.mongodb.url);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const _mongo = function () {};
|
|
16
|
+
|
|
17
|
+
_mongo.lib = mongodb;
|
|
18
|
+
|
|
19
|
+
_mongo.ObjectID = mongodb.ObjectId;
|
|
20
|
+
_mongo.connection = url;
|
|
21
|
+
_mongo.collections_indexed = [];
|
|
22
|
+
|
|
23
|
+
//ulimit -n 10000
|
|
24
|
+
_mongo.dbList = [];
|
|
25
|
+
|
|
26
|
+
_mongo.connections = [];
|
|
27
|
+
_mongo.closeDbBusy = !1;
|
|
28
|
+
____0.on('[close-database]', (args, callback) => {
|
|
29
|
+
callback = callback || function () {};
|
|
30
|
+
|
|
31
|
+
if (_mongo.closeDbBusy == !0) {
|
|
32
|
+
setTimeout(() => {
|
|
33
|
+
____0.call('[close-database]', args, callback);
|
|
34
|
+
}, 2000);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (_mongo.connections.length === 0) {
|
|
39
|
+
callback();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_mongo.closeDbBusy = !0;
|
|
44
|
+
console.log('Closing mongodb Connection Count : ' + _mongo.connections.length);
|
|
45
|
+
for (let i = 0; i < _mongo.connections.length; i++) {
|
|
46
|
+
console.log('Closing Database : ' + _mongo.connections[i].name);
|
|
47
|
+
_mongo.connections[i].client.close();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
_mongo.closeDbBusy = !1;
|
|
52
|
+
callback();
|
|
53
|
+
}, 1000);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
_mongo.handleDoc = function (doc, isProperty = false) {
|
|
57
|
+
if (!doc) {
|
|
58
|
+
return doc;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (Array.isArray(doc)) {
|
|
62
|
+
doc.forEach((v, i) => {
|
|
63
|
+
doc[i] = _mongo.handleDoc(v, true);
|
|
64
|
+
});
|
|
65
|
+
return doc;
|
|
66
|
+
} else if (typeof doc === 'object') {
|
|
67
|
+
for (let key in doc) {
|
|
68
|
+
if (typeof key === 'string' && key.indexOf('$') === 0) {
|
|
69
|
+
delete doc[key];
|
|
70
|
+
} else if (typeof doc[key] === 'string' && ____0.fn.isDate(doc[key])) {
|
|
71
|
+
doc[key] = new Date(doc[key]);
|
|
72
|
+
} else if (Array.isArray(doc[key])) {
|
|
73
|
+
doc[key].forEach((v, i) => {
|
|
74
|
+
doc[key][i] = _mongo.handleDoc(v, true);
|
|
75
|
+
});
|
|
76
|
+
} else if (typeof doc[key] === 'object') {
|
|
77
|
+
doc[key] = _mongo.handleDoc(doc[key], true);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return isProperty ? doc : { ...doc };
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
_mongo.connectDBBusy = !1;
|
|
86
|
+
_mongo.connectDB = async function (name, callback) {
|
|
87
|
+
if (_mongo.connectDBBusy === !0) {
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
_mongo.connectDB(name, callback);
|
|
90
|
+
}, 100);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_mongo.connectDBBusy = !0;
|
|
95
|
+
|
|
96
|
+
if (name === undefined) {
|
|
97
|
+
name = ____0.options.mongodb.db;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!____0.options.mongodb.enabled) {
|
|
101
|
+
callback(
|
|
102
|
+
{
|
|
103
|
+
message: 'mongodb Not Enabled',
|
|
104
|
+
},
|
|
105
|
+
null
|
|
106
|
+
);
|
|
107
|
+
_mongo.connectDBBusy = !1;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
for (let i = 0; i < _mongo.connections.length; i++) {
|
|
112
|
+
if (_mongo.connections[i].name === name) {
|
|
113
|
+
callback(null, _mongo.connections[i].db);
|
|
114
|
+
_mongo.connectDBBusy = !1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let db_name = ____0.options.mongodb.prefix.db + name;
|
|
120
|
+
let db_url = _mongo.connection;
|
|
121
|
+
____0.log('\n ( Connecting DB : ' + db_url + ' ) \n');
|
|
122
|
+
const mongodbClient = new mongodb.MongoClient(db_url, {
|
|
123
|
+
serverSelectionTimeoutMS: 1000 * 60,
|
|
124
|
+
connectTimeoutMS: 1000 * 60,
|
|
125
|
+
socketTimeoutMS: 1000 * 60 * 5,
|
|
126
|
+
...____0.options.mongodb.config,
|
|
127
|
+
});
|
|
128
|
+
mongodbClient
|
|
129
|
+
.connect()
|
|
130
|
+
.then((client) => {
|
|
131
|
+
if (client) {
|
|
132
|
+
const db = client.db(db_name);
|
|
133
|
+
|
|
134
|
+
_mongo.connections.push({
|
|
135
|
+
name: name,
|
|
136
|
+
url: db_url,
|
|
137
|
+
db: db,
|
|
138
|
+
client: client,
|
|
139
|
+
connected: !0,
|
|
140
|
+
});
|
|
141
|
+
____0.log('\n ( Connected DB : ' + db_name + ' ) : ' + db_url + '\n');
|
|
142
|
+
callback(null, db);
|
|
143
|
+
} else {
|
|
144
|
+
err.message += ' , ' + db_url;
|
|
145
|
+
____0.log('\n ( Connected DB Error: ' + err.message + ' ) \n');
|
|
146
|
+
____0.log(err);
|
|
147
|
+
callback(err, null);
|
|
148
|
+
}
|
|
149
|
+
_mongo.connectDBBusy = !1;
|
|
150
|
+
})
|
|
151
|
+
.catch((err) => {
|
|
152
|
+
____0.log(err);
|
|
153
|
+
callback(err, null);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
_mongo.createIndex = function (options, callback) {
|
|
158
|
+
callback =
|
|
159
|
+
callback ||
|
|
160
|
+
function (...args) {
|
|
161
|
+
console.log(args);
|
|
162
|
+
};
|
|
163
|
+
_mongo.connectDB(options.dbName, function (err, db) {
|
|
164
|
+
if (!err) {
|
|
165
|
+
if (options.collectionName === undefined) {
|
|
166
|
+
options.collectionName = ____0.options.mongodb.collection;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
db.collection(____0.options.mongodb.prefix.collection + options.collectionName)
|
|
170
|
+
.createIndex(options.obj, options.option)
|
|
171
|
+
.then((result) => {
|
|
172
|
+
callback(null, result);
|
|
173
|
+
if (____0.options.mongodb.events) {
|
|
174
|
+
____0.call('mongodb after create index', {
|
|
175
|
+
db: options.dbName,
|
|
176
|
+
collection: options.collectionName,
|
|
177
|
+
obj: options.obj,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
.catch((err) => {
|
|
182
|
+
callback(err);
|
|
183
|
+
});
|
|
184
|
+
} else {
|
|
185
|
+
callback(err);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
_mongo.dropIndex = function (options, callback) {
|
|
190
|
+
callback =
|
|
191
|
+
callback ||
|
|
192
|
+
function (...args) {
|
|
193
|
+
console.log(args);
|
|
194
|
+
};
|
|
195
|
+
_mongo.connectDB(options.dbName, function (err, db) {
|
|
196
|
+
if (!err) {
|
|
197
|
+
if (options.collectionName === undefined) {
|
|
198
|
+
options.collectionName = ____0.options.mongodb.collection;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
db.collection(____0.options.mongodb.prefix.collection + options.collectionName)
|
|
202
|
+
.dropIndex(options.obj, options.option)
|
|
203
|
+
.then((result) => {
|
|
204
|
+
callback(null, result);
|
|
205
|
+
if (____0.options.mongodb.events) {
|
|
206
|
+
____0.call('mongodb after drop index', {
|
|
207
|
+
db: options.dbName,
|
|
208
|
+
collection: options.collectionName,
|
|
209
|
+
obj: options.obj,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
.catch((err) => {
|
|
214
|
+
callback(err);
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
callback(err);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
_mongo.dropIndexes = function (options, callback) {
|
|
222
|
+
callback =
|
|
223
|
+
callback ||
|
|
224
|
+
function (...args) {
|
|
225
|
+
console.log(args);
|
|
226
|
+
};
|
|
227
|
+
_mongo.connectDB(options.dbName, function (err, db) {
|
|
228
|
+
if (!err) {
|
|
229
|
+
if (options.collectionName === undefined) {
|
|
230
|
+
options.collectionName = ____0.options.mongodb.collection;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
db.collection(____0.options.mongodb.prefix.collection + options.collectionName)
|
|
234
|
+
.dropIndexes()
|
|
235
|
+
.then((result) => {
|
|
236
|
+
callback(null, result);
|
|
237
|
+
if (____0.options.mongodb.events) {
|
|
238
|
+
____0.call('mongodb after drop index', {
|
|
239
|
+
db: options.dbName,
|
|
240
|
+
collection: options.collectionName,
|
|
241
|
+
obj: options.obj,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
.catch((err) => {
|
|
246
|
+
callback(err);
|
|
247
|
+
});
|
|
248
|
+
} else {
|
|
249
|
+
callback(err);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
_mongo.aggregate = function (obj, callback) {
|
|
254
|
+
callback =
|
|
255
|
+
callback ||
|
|
256
|
+
function (...args) {
|
|
257
|
+
console.log(args);
|
|
258
|
+
};
|
|
259
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
260
|
+
if (!err) {
|
|
261
|
+
if (obj.collectionName === undefined) {
|
|
262
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
263
|
+
}
|
|
264
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
265
|
+
.aggregate(obj.arr)
|
|
266
|
+
.toArray()
|
|
267
|
+
.then((docs) => {
|
|
268
|
+
callback(null, docs);
|
|
269
|
+
})
|
|
270
|
+
.catch((err) => {
|
|
271
|
+
callback(err);
|
|
272
|
+
});
|
|
273
|
+
} else {
|
|
274
|
+
callback(err);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
_mongo.dropCollection = function (obj, callback) {
|
|
280
|
+
callback =
|
|
281
|
+
callback ||
|
|
282
|
+
function (...args) {
|
|
283
|
+
console.log(args);
|
|
284
|
+
};
|
|
285
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
286
|
+
if (!err) {
|
|
287
|
+
if (obj.collectionName === undefined) {
|
|
288
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
289
|
+
}
|
|
290
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
291
|
+
.drop()
|
|
292
|
+
.then((delOK) => {
|
|
293
|
+
callback(null, delOK);
|
|
294
|
+
})
|
|
295
|
+
.catch((err) => {
|
|
296
|
+
callback(err);
|
|
297
|
+
});
|
|
298
|
+
} else {
|
|
299
|
+
callback(err);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
_mongo.insertOneAsyncBusy = !1;
|
|
305
|
+
_mongo.insertOneAsyncList = [];
|
|
306
|
+
_mongo.insertOneAsync = function (obj, callback) {
|
|
307
|
+
if (obj) {
|
|
308
|
+
_mongo.insertOneAsyncList.push({
|
|
309
|
+
obj: obj,
|
|
310
|
+
callback: callback,
|
|
311
|
+
});
|
|
312
|
+
_mongo.insertOneAsync(null);
|
|
313
|
+
} else {
|
|
314
|
+
if (_mongo.insertOneAsyncBusy) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
var _obj = _mongo.insertOneAsyncList[0];
|
|
319
|
+
if (_obj) {
|
|
320
|
+
_mongo.insertOneAsyncBusy = !0;
|
|
321
|
+
_mongo.insertOne(_obj.obj, function (err, obj) {
|
|
322
|
+
_mongo.insertOneAsyncList.splice(0, 1);
|
|
323
|
+
_obj.callback(err, obj);
|
|
324
|
+
_mongo.insertOneAsyncBusy = !1;
|
|
325
|
+
_mongo.insertOneAsync(null);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
_mongo.insertOne = function (obj, callback) {
|
|
332
|
+
callback =
|
|
333
|
+
callback ||
|
|
334
|
+
function (...args) {
|
|
335
|
+
console.log(args);
|
|
336
|
+
};
|
|
337
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
338
|
+
if (!err) {
|
|
339
|
+
if (obj.collectionName === undefined) {
|
|
340
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
obj.doc = _mongo.handleDoc(obj.doc);
|
|
344
|
+
|
|
345
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
346
|
+
.insertOne(obj.doc)
|
|
347
|
+
.then((result) => {
|
|
348
|
+
callback(null, { ...obj.doc, _id: result.insertedId }, result);
|
|
349
|
+
|
|
350
|
+
if (____0.options.mongodb.events) {
|
|
351
|
+
____0.call('mongodb after insert', {
|
|
352
|
+
db: obj.dbName,
|
|
353
|
+
collection: obj.collectionName,
|
|
354
|
+
doc: result,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
})
|
|
358
|
+
.catch((err) => {
|
|
359
|
+
callback(err);
|
|
360
|
+
});
|
|
361
|
+
} else {
|
|
362
|
+
callback(err);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
_mongo.insert = _mongo.insertMany = function (obj, callback) {
|
|
368
|
+
callback =
|
|
369
|
+
callback ||
|
|
370
|
+
function (...args) {
|
|
371
|
+
console.log(args);
|
|
372
|
+
};
|
|
373
|
+
if (!obj.docs || obj.docs.length === 0) {
|
|
374
|
+
callback({
|
|
375
|
+
message: 'docs array length is 0',
|
|
376
|
+
});
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
380
|
+
if (!err) {
|
|
381
|
+
if (!obj.collectionName) {
|
|
382
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
383
|
+
}
|
|
384
|
+
obj.docs.forEach((doc, i) => {
|
|
385
|
+
obj.docs[i] = _mongo.handleDoc(doc);
|
|
386
|
+
});
|
|
387
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
388
|
+
.insertMany(obj.docs, obj.options)
|
|
389
|
+
.then((result) => {
|
|
390
|
+
callback(null, obj.docs, result);
|
|
391
|
+
|
|
392
|
+
if (____0.options.mongodb.events) {
|
|
393
|
+
____0.call('mongodb after insert many', {
|
|
394
|
+
db: obj.dbName,
|
|
395
|
+
collection: obj.collectionName,
|
|
396
|
+
docs: obj.docs,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
})
|
|
400
|
+
.catch((err) => {
|
|
401
|
+
console.error(' _mongo.insertMany() ', err.message);
|
|
402
|
+
|
|
403
|
+
callback(err, obj.docs, result);
|
|
404
|
+
});
|
|
405
|
+
} else {
|
|
406
|
+
console.error(' _mongo.insertMany() ', err.message);
|
|
407
|
+
|
|
408
|
+
callback(err);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
_mongo.findOne = function (obj, callback) {
|
|
414
|
+
callback =
|
|
415
|
+
callback ||
|
|
416
|
+
function (...args) {
|
|
417
|
+
console.log(args);
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
421
|
+
if (!err) {
|
|
422
|
+
if (obj.collectionName === undefined) {
|
|
423
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
if (obj.where === undefined) {
|
|
427
|
+
callback({
|
|
428
|
+
message: 'where not set',
|
|
429
|
+
});
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (typeof obj.where === 'string') {
|
|
434
|
+
obj.where = {
|
|
435
|
+
_id: new _mongo.ObjectID(obj.where),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
if (typeof obj.where._id === 'string') {
|
|
440
|
+
obj.where._id = new _mongo.ObjectID(obj.where._id);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (obj.select === undefined) {
|
|
444
|
+
obj.select = {};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
let options = {
|
|
448
|
+
projection: obj.select || {},
|
|
449
|
+
limit: 1,
|
|
450
|
+
skip: null,
|
|
451
|
+
sort: null,
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
455
|
+
.findOne(obj.where, options)
|
|
456
|
+
.then((doc) => {
|
|
457
|
+
callback(null, doc);
|
|
458
|
+
if (____0.options.mongodb.events) {
|
|
459
|
+
____0.call('mongodb after find', {
|
|
460
|
+
db: obj.dbName,
|
|
461
|
+
collection: obj.collectionName,
|
|
462
|
+
doc: doc,
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
.catch((err) => {
|
|
467
|
+
callback(err);
|
|
468
|
+
});
|
|
469
|
+
} else {
|
|
470
|
+
callback(err);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
_mongo.find = _mongo.findMany = function (obj, callback) {
|
|
476
|
+
callback =
|
|
477
|
+
callback ||
|
|
478
|
+
function (...args) {
|
|
479
|
+
console.log(args);
|
|
480
|
+
};
|
|
481
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
482
|
+
if (!err) {
|
|
483
|
+
if (obj.collectionName === undefined) {
|
|
484
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
488
|
+
.countDocuments(obj.where)
|
|
489
|
+
.then((count) => {
|
|
490
|
+
if (count > 0) {
|
|
491
|
+
let options = {
|
|
492
|
+
projection: obj.select || {},
|
|
493
|
+
limit: obj.limit ? parseInt(obj.limit) : ____0.options.mongodb.limit,
|
|
494
|
+
skip: obj.skip ? parseInt(obj.skip) : 0,
|
|
495
|
+
sort: obj.sort || null,
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
499
|
+
.find(obj.where, options)
|
|
500
|
+
.toArray()
|
|
501
|
+
.then((docs) => {
|
|
502
|
+
callback(null, docs, count);
|
|
503
|
+
if (____0.options.mongodb.events) {
|
|
504
|
+
____0.call('mongodb after find many', {
|
|
505
|
+
db: obj.dbName,
|
|
506
|
+
collection: obj.collectionName,
|
|
507
|
+
docs: docs,
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
})
|
|
511
|
+
.catch((err) => {
|
|
512
|
+
callback(err, [], 0);
|
|
513
|
+
});
|
|
514
|
+
} else {
|
|
515
|
+
callback(null, [], count);
|
|
516
|
+
}
|
|
517
|
+
})
|
|
518
|
+
.catch((err) => {
|
|
519
|
+
callback(err, [], 0);
|
|
520
|
+
});
|
|
521
|
+
} else {
|
|
522
|
+
callback(err);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
_mongo.distinct = function (obj, callback) {
|
|
528
|
+
callback =
|
|
529
|
+
callback ||
|
|
530
|
+
function (...args) {
|
|
531
|
+
console.log(args);
|
|
532
|
+
};
|
|
533
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
534
|
+
if (!err) {
|
|
535
|
+
if (obj.collectionName === undefined) {
|
|
536
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
537
|
+
}
|
|
538
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
539
|
+
.distinct(obj.field)
|
|
540
|
+
.then((docs) => {
|
|
541
|
+
callback(null, docs);
|
|
542
|
+
})
|
|
543
|
+
.catch((err) => {
|
|
544
|
+
callback(err);
|
|
545
|
+
});
|
|
546
|
+
} else {
|
|
547
|
+
callback(err);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
_mongo.updateOne = function (obj, callback) {
|
|
553
|
+
callback =
|
|
554
|
+
callback ||
|
|
555
|
+
function (...args) {
|
|
556
|
+
console.log(args);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
560
|
+
if (!err) {
|
|
561
|
+
if (obj.collectionName === undefined) {
|
|
562
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (obj.where && obj.where._id && typeof obj.where._id === 'string') {
|
|
566
|
+
obj.where._id = new _mongo.ObjectID(obj.where._id);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
let $update = {};
|
|
570
|
+
if (obj.set) {
|
|
571
|
+
$update.$set = obj.set;
|
|
572
|
+
if ($update.$set._id) {
|
|
573
|
+
delete $update.$set._id;
|
|
574
|
+
}
|
|
575
|
+
$update.$set = _mongo.handleDoc($update.$set);
|
|
576
|
+
}
|
|
577
|
+
if (obj.unset) {
|
|
578
|
+
$update.$unset = obj.unset;
|
|
579
|
+
}
|
|
580
|
+
if (obj.rename) {
|
|
581
|
+
$update.$rename = obj.rename;
|
|
582
|
+
}
|
|
583
|
+
_mongo.findOne(
|
|
584
|
+
{
|
|
585
|
+
dbName: obj.dbName,
|
|
586
|
+
collectionName: obj.collectionName,
|
|
587
|
+
where: obj.where,
|
|
588
|
+
},
|
|
589
|
+
(err, doc) => {
|
|
590
|
+
if (!err) {
|
|
591
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
592
|
+
.updateOne(obj.where, $update)
|
|
593
|
+
.then((result) => {
|
|
594
|
+
_mongo.findOne(
|
|
595
|
+
{
|
|
596
|
+
dbName: obj.dbName,
|
|
597
|
+
collectionName: obj.collectionName,
|
|
598
|
+
where: obj.where,
|
|
599
|
+
},
|
|
600
|
+
(err2, doc2) => {
|
|
601
|
+
callback(
|
|
602
|
+
null,
|
|
603
|
+
{
|
|
604
|
+
doc: doc2,
|
|
605
|
+
old_doc: doc,
|
|
606
|
+
where: obj.where,
|
|
607
|
+
update: $update,
|
|
608
|
+
db: obj.dbName,
|
|
609
|
+
collection: obj.collectionName,
|
|
610
|
+
},
|
|
611
|
+
result
|
|
612
|
+
);
|
|
613
|
+
if (____0.options.mongodb.events) {
|
|
614
|
+
____0.call('mongodb after update', {
|
|
615
|
+
db: obj.dbName,
|
|
616
|
+
collection: obj.collectionName,
|
|
617
|
+
doc: doc2,
|
|
618
|
+
old_doc: doc,
|
|
619
|
+
where: obj.where,
|
|
620
|
+
update: $update,
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
);
|
|
625
|
+
})
|
|
626
|
+
.catch((err) => {
|
|
627
|
+
callback(err);
|
|
628
|
+
});
|
|
629
|
+
} else {
|
|
630
|
+
callback(err);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
);
|
|
634
|
+
} else {
|
|
635
|
+
callback(err);
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
_mongo.update = _mongo.updateMany = function (obj, callback) {
|
|
641
|
+
callback =
|
|
642
|
+
callback ||
|
|
643
|
+
function (...args) {
|
|
644
|
+
console.log(args);
|
|
645
|
+
};
|
|
646
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
647
|
+
if (!err) {
|
|
648
|
+
if (obj.collectionName === undefined) {
|
|
649
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
let $update = {};
|
|
653
|
+
if (obj.set) {
|
|
654
|
+
$update.$set = obj.set;
|
|
655
|
+
}
|
|
656
|
+
if (obj.unset) {
|
|
657
|
+
$update.$unset = obj.unset;
|
|
658
|
+
}
|
|
659
|
+
if (obj.rename) {
|
|
660
|
+
$update.$rename = obj.rename;
|
|
661
|
+
}
|
|
662
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
663
|
+
.updateMany(obj.where, $update)
|
|
664
|
+
.then((result) => {
|
|
665
|
+
callback(
|
|
666
|
+
null,
|
|
667
|
+
{
|
|
668
|
+
result: result,
|
|
669
|
+
exists: result.result?.n,
|
|
670
|
+
count: result.result?.nModified,
|
|
671
|
+
ok: result.result?.ok,
|
|
672
|
+
where: obj.where,
|
|
673
|
+
update: $update,
|
|
674
|
+
},
|
|
675
|
+
result
|
|
676
|
+
);
|
|
677
|
+
if (____0.options.mongodb.events) {
|
|
678
|
+
____0.call('mongodb after update many', {
|
|
679
|
+
db: obj.dbName,
|
|
680
|
+
collection: obj.collectionName,
|
|
681
|
+
exists: result.result?.n,
|
|
682
|
+
count: result.result?.nModified,
|
|
683
|
+
ok: result.result?.ok,
|
|
684
|
+
where: obj.where,
|
|
685
|
+
update: $update,
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
})
|
|
689
|
+
.catch((err) => {
|
|
690
|
+
callback(err);
|
|
691
|
+
});
|
|
692
|
+
} else {
|
|
693
|
+
callback(err);
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
_mongo.deleteOne = function (obj, callback) {
|
|
699
|
+
callback =
|
|
700
|
+
callback ||
|
|
701
|
+
function (...args) {
|
|
702
|
+
console.log(args);
|
|
703
|
+
};
|
|
704
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
705
|
+
if (!err) {
|
|
706
|
+
if (obj.collectionName === undefined) {
|
|
707
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
_mongo.findOne(
|
|
711
|
+
{
|
|
712
|
+
where: obj.where,
|
|
713
|
+
select: {},
|
|
714
|
+
collectionName: obj.collectionName,
|
|
715
|
+
dbName: obj.dbName,
|
|
716
|
+
},
|
|
717
|
+
function (err, doc) {
|
|
718
|
+
if (!err && doc) {
|
|
719
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
720
|
+
.deleteOne(obj.where)
|
|
721
|
+
.then((result) => {
|
|
722
|
+
callback(
|
|
723
|
+
null,
|
|
724
|
+
{
|
|
725
|
+
db: obj.dbName,
|
|
726
|
+
collection: obj.collectionName,
|
|
727
|
+
count: result.deletedCount,
|
|
728
|
+
doc: doc,
|
|
729
|
+
},
|
|
730
|
+
result
|
|
731
|
+
);
|
|
732
|
+
if (____0.options.mongodb.events) {
|
|
733
|
+
____0.call('mongodb after delete', {
|
|
734
|
+
db: obj.dbName,
|
|
735
|
+
collection: obj.collectionName,
|
|
736
|
+
doc: doc,
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
})
|
|
740
|
+
.catch((err) => {
|
|
741
|
+
callback(err);
|
|
742
|
+
});
|
|
743
|
+
} else {
|
|
744
|
+
callback({
|
|
745
|
+
message: 'Not Exists : ' + JSON.stringify(obj.where),
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
);
|
|
750
|
+
} else {
|
|
751
|
+
callback(err);
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
_mongo.delete = _mongo.deleteMany = function (obj, callback) {
|
|
757
|
+
callback =
|
|
758
|
+
callback ||
|
|
759
|
+
function (...args) {
|
|
760
|
+
console.log(args);
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
if (obj.where === undefined) {
|
|
764
|
+
callback(
|
|
765
|
+
{
|
|
766
|
+
message: 'where not set',
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
db: obj.dbName,
|
|
770
|
+
collection: obj.collectionName,
|
|
771
|
+
|
|
772
|
+
count: 0,
|
|
773
|
+
ok: 0,
|
|
774
|
+
exists: 0,
|
|
775
|
+
},
|
|
776
|
+
result
|
|
777
|
+
);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
_mongo.connectDB(obj.dbName, function (err, db) {
|
|
782
|
+
if (!err) {
|
|
783
|
+
if (obj.collectionName === undefined) {
|
|
784
|
+
obj.collectionName = ____0.options.mongodb.collection;
|
|
785
|
+
}
|
|
786
|
+
db.collection(____0.options.mongodb.prefix.collection + obj.collectionName)
|
|
787
|
+
.deleteMany(obj.where)
|
|
788
|
+
.then((result) => {
|
|
789
|
+
callback(
|
|
790
|
+
null,
|
|
791
|
+
{
|
|
792
|
+
db: obj.dbName,
|
|
793
|
+
collection: obj.collectionName,
|
|
794
|
+
|
|
795
|
+
count: result.deletedCount,
|
|
796
|
+
},
|
|
797
|
+
result
|
|
798
|
+
);
|
|
799
|
+
if (____0.options.mongodb.events) {
|
|
800
|
+
____0.call('mongodb after delete many', {
|
|
801
|
+
db: obj.dbName,
|
|
802
|
+
collection: obj.collectionName,
|
|
803
|
+
|
|
804
|
+
where: obj.where,
|
|
805
|
+
count: result.deletedCount,
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
})
|
|
809
|
+
.catch((err) => {
|
|
810
|
+
callback(err);
|
|
811
|
+
});
|
|
812
|
+
} else {
|
|
813
|
+
callback(err);
|
|
814
|
+
}
|
|
815
|
+
});
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
return _mongo;
|
|
819
|
+
};
|