isite 2025.1.12 → 2025.1.15

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/lib/collection.js CHANGED
@@ -1,893 +1,889 @@
1
1
  module.exports = function init(____0, options, db) {
2
- const $collection = {};
2
+ const $collection = {};
3
3
 
4
- ____0.on(____0.strings[4], (_) => {
5
- $collection.taskBusy = !_;
6
- });
4
+ ____0.on(____0.strings[4], (_) => {
5
+ $collection.taskBusy = !_;
6
+ });
7
7
 
8
- if (typeof options === 'string') {
9
- options = {
10
- collection: options,
11
- };
12
- }
13
-
14
- $collection.options = { ...____0.options.mongodb, ...options };
15
- $collection.options.db = $collection.options.db.trim().replace(' ', '');
16
- $collection.options.collection = $collection.options.collection.trim().replace(' ', '');
17
- $collection.identityEnabled = $collection.options.identity.enabled;
18
- $collection.name = $collection.options.db + '.' + $collection.options.collection;
19
- $collection.guid = ____0.hide($collection.options);
20
- if ((co = ____0.collectionList.find((c) => c.guid == $collection.guid))) {
21
- return co;
22
- }
23
- $collection.db = $collection.options.db;
24
- $collection.collection = $collection.options.collection;
25
- $collection.docs = [];
26
-
27
- $collection.insertBusy = !1;
28
- $collection.updateBusy = !1;
29
- $collection.deleteBusy = !1;
30
-
31
- $collection.taskBusy = !1;
32
- $collection.taskList = [];
33
- $collection.taskCount = 0;
34
-
35
- $collection.callback = function (...args) {
36
- ____0.log(...args);
37
- };
38
-
39
- $collection.checkTaskList = function () {
40
- // console.log('canRunTask : ' + $collection.taskCount + ' , count : ' + $collection.taskList.length)
41
- if ($collection.taskBusy) {
42
- return;
43
- }
44
- if ($collection.taskList.length == 0) {
45
- return;
8
+ if (typeof options === 'string') {
9
+ options = {
10
+ collection: options,
11
+ };
46
12
  }
47
13
 
48
- $collection.taskBusy = !0;
49
- $collection.taskCount++;
50
- let task = $collection.taskList.shift();
51
-
52
- if (task.type == 'add') {
53
- $collection.add(task.options, task.callback, true);
54
- } else if (task.type == 'addAll') {
55
- $collection.addAll(task.options, task.callback, true);
56
- } else if (task.type == 'update') {
57
- $collection.update(task.options, task.callback, true);
58
- } else if (task.type == 'updateAll') {
59
- $collection.updateAll(task.options, task.callback, true);
60
- } else if (task.type == 'delete') {
61
- $collection.delete(task.options, task.callback, true);
62
- } else if (task.type == 'deleteAll') {
63
- $collection.deleteAll(task.options, task.callback, true);
64
- } else if (task.type == 'get') {
65
- $collection.get(task.options, task.callback, true);
66
- } else if (task.type == 'getAll') {
67
- $collection.getAll(task.options, task.callback, true);
68
- } else if (task.type == 'count') {
69
- $collection.getCount(task.options, task.callback, true);
14
+ $collection.options = { ...____0.options.mongodb, ...options };
15
+ $collection.options.db = $collection.options.db.trim().replace(' ', '');
16
+ $collection.options.collection = $collection.options.collection.trim().replace(' ', '');
17
+ $collection.identityEnabled = $collection.options.identity.enabled;
18
+ $collection.name = $collection.options.db + '.' + $collection.options.collection;
19
+ $collection.guid = ____0.hide($collection.options);
20
+ if ((co = ____0.collectionList.find((c) => c.guid == $collection.guid))) {
21
+ return co;
70
22
  }
71
- };
23
+ $collection.db = $collection.options.db;
24
+ $collection.collection = $collection.options.collection;
25
+ $collection.docs = [];
72
26
 
73
- $collection.insertOne =
74
- $collection.insert =
75
- $collection.add =
76
- $collection.addOne =
77
- ($doc, callback, canRunTask = false) => {
78
- callback = callback || $collection.callback;
79
- if (!canRunTask) {
80
- $collection.taskList.push({
81
- options: $doc,
82
- callback: callback,
83
- type: 'add',
84
- });
85
- } else {
86
- $doc.id = typeof $doc.id === 'number' ? $doc.id : null;
87
-
88
- if ($collection.identityEnabled === !0 && !$doc.id) {
89
- $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID;
90
- ____0.mongodb.collections_indexed[$collection.collection].nextID = $collection.step + ____0.mongodb.collections_indexed[$collection.collection].nextID;
27
+ $collection.insertBusy = !1;
28
+ $collection.updateBusy = !1;
29
+ $collection.deleteBusy = !1;
91
30
 
92
- if ($doc.id + 1 !== ____0.mongodb.collections_indexed[$collection.collection].nextID) {
93
- $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID - 1;
94
- }
95
- }
31
+ $collection.taskBusy = !1;
32
+ $collection.taskList = [];
33
+ $collection.taskCount = 0;
96
34
 
97
- if ($collection.identityEnabled === !0 && $doc.id >= ____0.mongodb.collections_indexed[$collection.collection].nextID) {
98
- ____0.mongodb.collections_indexed[$collection.collection].nextID = $doc.id + 1;
99
- }
35
+ $collection.callback = function (...args) {
36
+ ____0.log(...args);
37
+ };
100
38
 
101
- ____0.mongodb.insertOne(
102
- {
103
- collectionName: $collection.collection,
104
- dbName: $collection.db,
105
- doc: $doc,
106
- },
107
- function (err, docInserted) {
108
- callback(err, docInserted, $doc);
109
- $collection.taskBusy = !1;
110
- }
111
- );
39
+ $collection.checkTaskList = function () {
40
+ $collection.taskBusy = !0;
41
+ $collection.taskCount++;
42
+
43
+ // console.log($collection.name + ' : canRunTask : ' + $collection.taskCount + ' , in-Waiting : ' + $collection.taskList.length);
44
+
45
+ let task = $collection.taskList.shift();
46
+
47
+ if (task.type == 'add') {
48
+ $collection.add(task.options, task.callback, true);
49
+ } else if (task.type == 'addAll') {
50
+ $collection.addAll(task.options, task.callback, true);
51
+ } else if (task.type == 'update') {
52
+ $collection.update(task.options, task.callback, true);
53
+ } else if (task.type == 'updateAll') {
54
+ $collection.updateAll(task.options, task.callback, true);
55
+ } else if (task.type == 'delete') {
56
+ $collection.delete(task.options, task.callback, true);
57
+ } else if (task.type == 'deleteAll') {
58
+ $collection.deleteAll(task.options, task.callback, true);
59
+ } else if (task.type == 'get') {
60
+ $collection.get(task.options, task.callback, true);
61
+ } else if (task.type == 'getAll') {
62
+ $collection.getAll(task.options, task.callback, true);
63
+ } else if (task.type == 'count') {
64
+ $collection.getCount(task.options, task.callback, true);
112
65
  }
113
- };
114
- $collection.update =
115
- $collection.updateOne =
116
- $collection.edit =
117
- $collection.editOne =
118
- (options, callback, canRunTask = false) => {
66
+ };
67
+
68
+ $collection.insertOne =
69
+ $collection.insert =
70
+ $collection.add =
71
+ $collection.addOne =
72
+ ($doc, callback, canRunTask = false) => {
73
+ callback = callback || $collection.callback;
74
+ if (!canRunTask) {
75
+ $collection.taskList.push({
76
+ options: $doc,
77
+ callback: callback,
78
+ type: 'add',
79
+ });
80
+ } else {
81
+ $doc.id = typeof $doc.id === 'number' ? $doc.id : null;
82
+
83
+ if ($collection.identityEnabled === !0 && !$doc.id) {
84
+ $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID;
85
+ ____0.mongodb.collections_indexed[$collection.collection].nextID = $collection.step + ____0.mongodb.collections_indexed[$collection.collection].nextID;
86
+
87
+ if ($doc.id + 1 !== ____0.mongodb.collections_indexed[$collection.collection].nextID) {
88
+ $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID - 1;
89
+ }
90
+ }
91
+
92
+ if ($collection.identityEnabled === !0 && $doc.id >= ____0.mongodb.collections_indexed[$collection.collection].nextID) {
93
+ ____0.mongodb.collections_indexed[$collection.collection].nextID = $doc.id + 1;
94
+ }
95
+
96
+ ____0.mongodb.insertOne(
97
+ {
98
+ collectionName: $collection.collection,
99
+ dbName: $collection.db,
100
+ doc: $doc,
101
+ },
102
+ function (err, docInserted) {
103
+ callback(err, docInserted, $doc);
104
+ $collection.taskBusy = !1;
105
+ }
106
+ );
107
+ }
108
+ };
109
+ $collection.update =
110
+ $collection.updateOne =
111
+ $collection.edit =
112
+ $collection.editOne =
113
+ (options, callback, canRunTask = false) => {
114
+ callback = callback || $collection.callback;
115
+ if (!canRunTask) {
116
+ $collection.taskList.push({
117
+ options: options,
118
+ callback: callback,
119
+ type: 'update',
120
+ });
121
+ } else {
122
+ let newOptions = {};
123
+
124
+ if (options.set) {
125
+ newOptions.set = options.set;
126
+ } else {
127
+ newOptions.set = options;
128
+ }
129
+
130
+ if (options.unset) {
131
+ newOptions.unset = options.unset;
132
+ }
133
+ if (options.rename) {
134
+ newOptions.rename = options.rename;
135
+ }
136
+
137
+ if (options.where) {
138
+ newOptions.where = options.where;
139
+ } else {
140
+ newOptions.where = {
141
+ _id: newOptions.set._id,
142
+ id: newOptions.set.id,
143
+ };
144
+ }
145
+
146
+ if (newOptions.where === undefined || newOptions.set === undefined) {
147
+ callback({
148
+ message: '\n updateOne() : Must Assign [ Where & Set ] Properties \n' + JSON.stringify(options),
149
+ });
150
+
151
+ $collection.taskBusy = !1;
152
+ return;
153
+ }
154
+
155
+ if (newOptions.where && newOptions.where.id && typeof newOptions.where.id == 'string') {
156
+ newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
157
+ }
158
+
159
+ ____0.mongodb.updateOne(
160
+ {
161
+ collectionName: $collection.collection,
162
+ dbName: $collection.db,
163
+ where: newOptions.where,
164
+ set: newOptions.set || {},
165
+ unset: newOptions.unset || {},
166
+ rename: newOptions.rename || {},
167
+ },
168
+ function (err, result) {
169
+ callback(err, result);
170
+ $collection.taskBusy = !1;
171
+ }
172
+ );
173
+ }
174
+ };
175
+ $collection.delete =
176
+ $collection.deleteOne =
177
+ $collection.remove =
178
+ $collection.removeOne =
179
+ ($options, callback, canRunTask = false) => {
180
+ callback = callback || $collection.callback;
181
+
182
+ if (!$options) {
183
+ return;
184
+ }
185
+
186
+ if (!canRunTask) {
187
+ $collection.taskList.push({
188
+ options: $options,
189
+ callback: callback,
190
+ type: 'delete',
191
+ });
192
+ } else {
193
+ let newOptions = {};
194
+
195
+ if ($options.where === undefined) {
196
+ newOptions.where = $options;
197
+ } else {
198
+ newOptions = $options;
199
+ }
200
+
201
+ if (newOptions.where === undefined) {
202
+ callback({
203
+ message: '\n delete() : Must Assign [ Where ] Propertie \n' + JSON.stringify(options),
204
+ });
205
+
206
+ $collection.taskBusy = !1;
207
+ return;
208
+ }
209
+
210
+ if (newOptions.where.id && newOptions.where.id && typeof newOptions.where.id === 'string') {
211
+ newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
212
+ }
213
+
214
+ ____0.mongodb.deleteOne(
215
+ {
216
+ collectionName: $collection.collection,
217
+ dbName: $collection.db,
218
+ where: newOptions.where,
219
+ },
220
+ function (err, result) {
221
+ callback(err, result);
222
+ $collection.taskBusy = !1;
223
+ }
224
+ );
225
+ }
226
+ };
227
+ $collection.get =
228
+ $collection.getOne =
229
+ $collection.find =
230
+ $collection.findOne =
231
+ $collection.select =
232
+ $collection.selectOne =
233
+ (options, callback, canRunTask = false) => {
234
+ callback = callback || $collection.callback;
235
+ if (!canRunTask) {
236
+ $collection.taskList.push({
237
+ options: options,
238
+ callback: callback,
239
+ type: 'get',
240
+ });
241
+ } else {
242
+ let newOptions = {};
243
+
244
+ if (options.where === undefined) {
245
+ newOptions.where = options;
246
+ } else {
247
+ newOptions.where = options.where;
248
+ }
249
+ if (options.select === undefined) {
250
+ newOptions.select = {};
251
+ } else {
252
+ newOptions.select = options.select;
253
+ }
254
+ if (options.sort === undefined) {
255
+ newOptions.sort = {};
256
+ } else {
257
+ newOptions.sort = options.sort;
258
+ }
259
+
260
+ if (newOptions.where.id && newOptions.where.id && typeof newOptions.where.id === 'string') {
261
+ newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
262
+ }
263
+
264
+ ____0.mongodb.findOne(
265
+ {
266
+ collectionName: $collection.collection,
267
+ dbName: $collection.db,
268
+ where: newOptions.where,
269
+ select: newOptions.select,
270
+ sort: newOptions.sort,
271
+ },
272
+ function (err, doc) {
273
+ callback(err, doc);
274
+ $collection.taskBusy = !1;
275
+ }
276
+ );
277
+ }
278
+ };
279
+ $collection.count = $collection.getCount = function (options, callback, canRunTask = false) {
119
280
  callback = callback || $collection.callback;
120
281
  if (!canRunTask) {
121
- $collection.taskList.push({
122
- options: options,
123
- callback: callback,
124
- type: 'update',
125
- });
126
- } else {
127
- let newOptions = {};
128
-
129
- if (options.set) {
130
- newOptions.set = options.set;
131
- } else {
132
- newOptions.set = options;
133
- }
134
-
135
- if (options.unset) {
136
- newOptions.unset = options.unset;
137
- }
138
- if (options.rename) {
139
- newOptions.rename = options.rename;
140
- }
141
-
142
- if (options.where) {
143
- newOptions.where = options.where;
144
- } else {
145
- newOptions.where = {
146
- _id: newOptions.set._id,
147
- id: newOptions.set.id,
148
- };
149
- }
150
-
151
- if (newOptions.where === undefined || newOptions.set === undefined) {
152
- callback({
153
- message: '\n updateOne() : Must Assign [ Where & Set ] Properties \n' + JSON.stringify(options),
282
+ $collection.taskList.push({
283
+ options: options,
284
+ callback: callback,
285
+ type: 'count',
154
286
  });
287
+ } else {
288
+ let newOptions = { where: {} };
155
289
 
156
- $collection.taskBusy = !1;
157
- return;
158
- }
159
-
160
- if (newOptions.where && newOptions.where.id && typeof newOptions.where.id == 'string') {
161
- newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
162
- }
163
-
164
- ____0.mongodb.updateOne(
165
- {
166
- collectionName: $collection.collection,
167
- dbName: $collection.db,
168
- where: newOptions.where,
169
- set: newOptions.set || {},
170
- unset: newOptions.unset || {},
171
- rename: newOptions.rename || {},
172
- },
173
- function (err, result) {
174
- callback(err, result);
175
- $collection.taskBusy = !1;
290
+ if (options.where) {
291
+ newOptions.where = options.where;
292
+ } else {
293
+ newOptions.where = options;
176
294
  }
177
- );
178
- }
179
- };
180
- $collection.delete =
181
- $collection.deleteOne =
182
- $collection.remove =
183
- $collection.removeOne =
184
- ($options, callback, canRunTask = false) => {
185
- callback = callback || $collection.callback;
186
295
 
187
- if (!$options) {
188
- return;
296
+ ____0.mongodb.count(
297
+ {
298
+ collectionName: $collection.collection,
299
+ dbName: $collection.db,
300
+ where: newOptions.where || {},
301
+ },
302
+ function (err, count) {
303
+ callback(err, count);
304
+ $collection.taskBusy = !1;
305
+ }
306
+ );
189
307
  }
308
+ };
309
+ $collection.getMany =
310
+ $collection.getAll =
311
+ $collection.findAll =
312
+ $collection.findMany =
313
+ $collection.selectAll =
314
+ $collection.selectMany =
315
+ (options, callback, canRunTask = false) => {
316
+ callback = callback || $collection.callback;
317
+ if (!canRunTask) {
318
+ $collection.taskList.push({
319
+ options: options,
320
+ callback: callback,
321
+ type: 'getAll',
322
+ });
323
+ } else {
324
+ let newOptions = { where: {} };
325
+
326
+ if (!options.where && !options.select && !options.limit && !options.sort && !options.skip) {
327
+ newOptions.where = options;
328
+ }
329
+ if (options.where) {
330
+ newOptions.where = options.where;
331
+ }
332
+ if (options.select) {
333
+ newOptions.select = options.select;
334
+ }
335
+ if (options.limit) {
336
+ newOptions.limit = options.limit;
337
+ }
338
+ if (options.sort) {
339
+ newOptions.sort = options.sort;
340
+ }
341
+ if (options.skip) {
342
+ newOptions.skip = options.skip;
343
+ }
344
+ if (newOptions.where.id && typeof newOptions.where.id === 'string') {
345
+ newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
346
+ }
347
+
348
+ ____0.mongodb.findMany(
349
+ {
350
+ collectionName: $collection.collection,
351
+ dbName: $collection.db,
352
+ where: newOptions.where || {},
353
+ select: newOptions.select || {},
354
+ limit: newOptions.limit || ____0.options.mongodb.limit,
355
+ sort: newOptions.sort || null,
356
+ skip: newOptions.skip || 0,
357
+ },
358
+ function (err, docs, count) {
359
+ callback(err, docs, count);
360
+ $collection.taskBusy = !1;
361
+ }
362
+ );
363
+ }
364
+ };
365
+ $collection.insertMany =
366
+ $collection.addMany =
367
+ $collection.insertAll =
368
+ $collection.addAll =
369
+ (docs, callback, canRunTask = false) => {
370
+ callback = callback || $collection.callback;
371
+
372
+ if (!Array.isArray(docs) || docs.length === 0) {
373
+ callback({
374
+ message: '!docs or docs.length = 0 ',
375
+ });
376
+ return;
377
+ }
378
+
379
+ if (!canRunTask) {
380
+ $collection.taskList.push({
381
+ options: docs,
382
+ callback: callback,
383
+ type: 'addAll',
384
+ });
385
+ } else {
386
+ docs = docs.filter((d) => d !== null && typeof d == 'object');
387
+ docs.forEach(($doc) => {
388
+ if ($collection.identityEnabled === !0 && !$doc.id) {
389
+ $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID;
390
+ ____0.mongodb.collections_indexed[$collection.collection].nextID = $collection.step + ____0.mongodb.collections_indexed[$collection.collection].nextID;
391
+
392
+ if ($doc.id + 1 !== ____0.mongodb.collections_indexed[$collection.collection].nextID) {
393
+ $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID - 1;
394
+ }
395
+ }
396
+
397
+ if ($collection.identityEnabled === !0 && $doc.id >= ____0.mongodb.collections_indexed[$collection.collection].nextID) {
398
+ ____0.mongodb.collections_indexed[$collection.collection].nextID = $doc.id + 1;
399
+ }
400
+ });
401
+ ____0.mongodb.insertMany(
402
+ {
403
+ collectionName: $collection.collection,
404
+ dbName: $collection.db,
405
+ docs: docs,
406
+ options: { ordered: true },
407
+ },
408
+ (err, result) => {
409
+ callback(err, result);
410
+ $collection.taskBusy = !1;
411
+ }
412
+ );
413
+ }
414
+ };
415
+ $collection.updateMany =
416
+ $collection.editMany =
417
+ $collection.updateAll =
418
+ $collection.editAll =
419
+ (options, callback, canRunTask = false) => {
420
+ callback = callback || $collection.callback;
421
+
422
+ if (!canRunTask) {
423
+ $collection.taskList.push({
424
+ options: options,
425
+ callback: callback,
426
+ type: 'updateAll',
427
+ });
428
+ } else {
429
+ if (options.where === undefined || options.set === undefined) {
430
+ callback({
431
+ message: '\n updateMany() : Must Assign [ where , set ] Properties \n ' + JSON.stringify(options),
432
+ });
433
+
434
+ $collection.taskBusy = !1;
435
+ return;
436
+ }
437
+
438
+ if (options.where && options.where.id && typeof options.where.id == 'string') {
439
+ options.where.id = ____0.toInt(options.where.id) || options.where.id;
440
+ }
441
+
442
+ ____0.mongodb.updateMany(
443
+ {
444
+ collectionName: $collection.collection,
445
+ dbName: $collection.db,
446
+ where: options.where,
447
+ set: options.set || {},
448
+ unset: options.unset,
449
+ rename: options.rename,
450
+ },
451
+ (err, result) => {
452
+ callback(err, result);
453
+
454
+ $collection.taskBusy = !1;
455
+ }
456
+ );
457
+ }
458
+ };
459
+ $collection.deleteMany =
460
+ $collection.removeMany =
461
+ $collection.deleteAll =
462
+ $collection.removeAll =
463
+ ($options, callback, canRunTask = false) => {
464
+ callback = callback || $collection.callback;
465
+ if (!canRunTask) {
466
+ $collection.taskList.push({
467
+ options: $options,
468
+ callback: callback,
469
+ type: 'deleteAll',
470
+ });
471
+ } else {
472
+ let options = {};
473
+ if ($options.where === undefined) {
474
+ options.where = $options;
475
+ } else {
476
+ options = $options;
477
+ }
478
+
479
+ if (options.where && options.where.id && typeof options.where.id === 'string') {
480
+ options.where.id = ____0.toInt(options.where.id) || options.where.id;
481
+ }
482
+
483
+ ____0.mongodb.deleteMany(
484
+ {
485
+ collectionName: $collection.collection,
486
+ dbName: $collection.db,
487
+ where: options.where,
488
+ },
489
+ function (err, result) {
490
+ callback(err, result);
491
+
492
+ $collection.taskBusy = !1;
493
+ }
494
+ );
495
+ }
496
+ };
190
497
 
191
- if (!canRunTask) {
192
- $collection.taskList.push({
193
- options: $options,
194
- callback: callback,
195
- type: 'delete',
196
- });
197
- } else {
198
- let newOptions = {};
199
-
200
- if ($options.where === undefined) {
201
- newOptions.where = $options;
202
- } else {
203
- newOptions = $options;
204
- }
205
-
206
- if (newOptions.where === undefined) {
207
- callback({
208
- message: '\n delete() : Must Assign [ Where ] Propertie \n' + JSON.stringify(options),
209
- });
210
-
211
- $collection.taskBusy = !1;
212
- return;
213
- }
214
-
215
- if (newOptions.where.id && newOptions.where.id && typeof newOptions.where.id === 'string') {
216
- newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
217
- }
498
+ $collection.ObjectId = $collection.ObjectID = function (_id) {
499
+ if (typeof _id === 'string' && _id.length === 24) {
500
+ return ____0.mongodb.ObjectID(_id);
501
+ }
502
+ return ____0.mongodb.ObjectID();
503
+ };
218
504
 
219
- ____0.mongodb.deleteOne(
505
+ $collection.drop = (callback) => {
506
+ callback = callback || $collection.callback;
507
+ ____0.mongodb.dropCollection(
220
508
  {
221
- collectionName: $collection.collection,
222
- dbName: $collection.db,
223
- where: newOptions.where,
509
+ collectionName: $collection.collection,
510
+ dbName: $collection.db,
224
511
  },
225
- function (err, result) {
226
- callback(err, result);
227
- $collection.taskBusy = !1;
512
+ (err, ok) => {
513
+ if (ok) {
514
+ ____0.mongodb.collections_indexed[$collection.collection].nextID = 1;
515
+ }
516
+ callback(err, ok);
228
517
  }
229
- );
230
- }
231
- };
232
- $collection.get =
233
- $collection.getOne =
234
- $collection.find =
235
- $collection.findOne =
236
- $collection.select =
237
- $collection.selectOne =
238
- (options, callback, canRunTask = false) => {
518
+ );
519
+ };
520
+
521
+ $collection.createUnique = (obj, callback) => {
239
522
  callback = callback || $collection.callback;
240
- if (!canRunTask) {
241
- $collection.taskList.push({
242
- options: options,
243
- callback: callback,
244
- type: 'get',
245
- });
246
- } else {
247
- let newOptions = {};
248
-
249
- if (options.where === undefined) {
250
- newOptions.where = options;
251
- } else {
252
- newOptions.where = options.where;
253
- }
254
- if (options.select === undefined) {
255
- newOptions.select = {};
256
- } else {
257
- newOptions.select = options.select;
258
- }
259
- if (options.sort === undefined) {
260
- newOptions.sort = {};
261
- } else {
262
- newOptions.sort = options.sort;
263
- }
264
-
265
- if (newOptions.where.id && newOptions.where.id && typeof newOptions.where.id === 'string') {
266
- newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
267
- }
268
-
269
- ____0.mongodb.findOne(
523
+
524
+ ____0.mongodb.createIndex(
270
525
  {
271
- collectionName: $collection.collection,
272
- dbName: $collection.db,
273
- where: newOptions.where,
274
- select: newOptions.select,
275
- sort: newOptions.sort,
526
+ collectionName: $collection.collection,
527
+ dbName: $collection.db,
528
+ obj: obj,
529
+ option: {
530
+ unique: true,
531
+ dropDups: true,
532
+ },
276
533
  },
277
- function (err, doc) {
278
- callback(err, doc);
279
- $collection.taskBusy = !1;
534
+ (err, result) => {
535
+ callback(err, result);
280
536
  }
281
- );
282
- }
283
- };
284
- $collection.count = $collection.getCount = function (options, callback, canRunTask = false) {
285
- callback = callback || $collection.callback;
286
- if (!canRunTask) {
287
- $collection.taskList.push({
288
- options: options,
289
- callback: callback,
290
- type: 'count',
291
- });
292
- } else {
293
- let newOptions = { where: {} };
294
-
295
- if (options.where) {
296
- newOptions.where = options.where;
297
- } else {
298
- newOptions.where = options;
299
- }
300
-
301
- ____0.mongodb.count(
302
- {
303
- collectionName: $collection.collection,
304
- dbName: $collection.db,
305
- where: newOptions.where || {},
306
- },
307
- function (err, count) {
308
- callback(err, count);
309
- $collection.taskBusy = !1;
310
- }
311
- );
312
- }
313
- };
314
- $collection.getMany =
315
- $collection.getAll =
316
- $collection.findAll =
317
- $collection.findMany =
318
- $collection.selectAll =
319
- $collection.selectMany =
320
- (options, callback, canRunTask = false) => {
537
+ );
538
+ };
539
+
540
+ $collection.createIndex = (obj, options, callback) => {
321
541
  callback = callback || $collection.callback;
322
- if (!canRunTask) {
323
- $collection.taskList.push({
324
- options: options,
325
- callback: callback,
326
- type: 'getAll',
327
- });
328
- } else {
329
- let newOptions = { where: {} };
330
-
331
- if (!options.where && !options.select && !options.limit && !options.sort && !options.skip) {
332
- newOptions.where = options;
333
- }
334
- if (options.where) {
335
- newOptions.where = options.where;
336
- }
337
- if (options.select) {
338
- newOptions.select = options.select;
339
- }
340
- if (options.limit) {
341
- newOptions.limit = options.limit;
342
- }
343
- if (options.sort) {
344
- newOptions.sort = options.sort;
345
- }
346
- if (options.skip) {
347
- newOptions.skip = options.skip;
348
- }
349
- if (newOptions.where.id && typeof newOptions.where.id === 'string') {
350
- newOptions.where.id = ____0.toInt(newOptions.where.id) || newOptions.where.id;
351
- }
352
-
353
- ____0.mongodb.findMany(
542
+
543
+ if (typeof options == 'function') {
544
+ callback = options;
545
+ }
546
+
547
+ ____0.mongodb.createIndex(
354
548
  {
355
- collectionName: $collection.collection,
356
- dbName: $collection.db,
357
- where: newOptions.where || {},
358
- select: newOptions.select || {},
359
- limit: newOptions.limit || ____0.options.mongodb.limit,
360
- sort: newOptions.sort || null,
361
- skip: newOptions.skip || 0,
549
+ collectionName: $collection.collection,
550
+ dbName: $collection.db,
551
+ obj: obj,
552
+ options: options,
362
553
  },
363
- function (err, docs, count) {
364
- callback(err, docs, count);
365
- $collection.taskBusy = !1;
554
+ (err, result) => {
555
+ callback(err, result);
366
556
  }
367
- );
368
- }
369
- };
370
- $collection.insertMany =
371
- $collection.addMany =
372
- $collection.insertAll =
373
- $collection.addAll =
374
- (docs, callback, canRunTask = false) => {
557
+ );
558
+ };
559
+ $collection.dropIndex = (obj, options, callback) => {
375
560
  callback = callback || $collection.callback;
376
561
 
377
- if (!Array.isArray(docs) || docs.length === 0) {
378
- callback({
379
- message: '!docs or docs.length = 0 ',
380
- });
381
- return;
562
+ if (typeof options == 'function') {
563
+ callback = options;
382
564
  }
383
565
 
384
- if (!canRunTask) {
385
- $collection.taskList.push({
386
- options: docs,
387
- callback: callback,
388
- type: 'addAll',
389
- });
390
- } else {
391
- docs = docs.filter((d) => d !== null && typeof d == 'object');
392
- docs.forEach(($doc) => {
393
- if ($collection.identityEnabled === !0 && !$doc.id) {
394
- $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID;
395
- ____0.mongodb.collections_indexed[$collection.collection].nextID = $collection.step + ____0.mongodb.collections_indexed[$collection.collection].nextID;
396
-
397
- if ($doc.id + 1 !== ____0.mongodb.collections_indexed[$collection.collection].nextID) {
398
- $doc.id = ____0.mongodb.collections_indexed[$collection.collection].nextID - 1;
399
- }
400
- }
401
-
402
- if ($collection.identityEnabled === !0 && $doc.id >= ____0.mongodb.collections_indexed[$collection.collection].nextID) {
403
- ____0.mongodb.collections_indexed[$collection.collection].nextID = $doc.id + 1;
404
- }
405
- });
406
- ____0.mongodb.insertMany(
566
+ ____0.mongodb.dropIndex(
407
567
  {
408
- collectionName: $collection.collection,
409
- dbName: $collection.db,
410
- docs: docs,
411
- options: { ordered: true },
568
+ collectionName: $collection.collection,
569
+ dbName: $collection.db,
570
+ obj: obj,
571
+ options: options,
412
572
  },
413
573
  (err, result) => {
414
- callback(err, result);
415
- $collection.taskBusy = !1;
574
+ callback(err, result);
416
575
  }
417
- );
418
- }
419
- };
420
- $collection.updateMany =
421
- $collection.editMany =
422
- $collection.updateAll =
423
- $collection.editAll =
424
- (options, callback, canRunTask = false) => {
576
+ );
577
+ };
578
+ $collection.dropIndexes = (options, callback) => {
425
579
  callback = callback || $collection.callback;
426
580
 
427
- if (!canRunTask) {
428
- $collection.taskList.push({
429
- options: options,
430
- callback: callback,
431
- type: 'updateAll',
432
- });
433
- } else {
434
- if (options.where === undefined || options.set === undefined) {
435
- callback({
436
- message: '\n updateMany() : Must Assign [ where , set ] Properties \n ' + JSON.stringify(options),
437
- });
438
-
439
- $collection.taskBusy = !1;
440
- return;
441
- }
442
-
443
- if (options.where && options.where.id && typeof options.where.id == 'string') {
444
- options.where.id = ____0.toInt(options.where.id) || options.where.id;
445
- }
581
+ if (typeof options == 'function') {
582
+ callback = options;
583
+ }
446
584
 
447
- ____0.mongodb.updateMany(
585
+ ____0.mongodb.dropIndexes(
448
586
  {
449
- collectionName: $collection.collection,
450
- dbName: $collection.db,
451
- where: options.where,
452
- set: options.set || {},
453
- unset: options.unset,
454
- rename: options.rename,
587
+ collectionName: $collection.collection,
588
+ dbName: $collection.db,
589
+ options: options,
455
590
  },
456
591
  (err, result) => {
457
- callback(err, result);
458
-
459
- $collection.taskBusy = !1;
592
+ callback(err, result);
460
593
  }
461
- );
462
- }
463
- };
464
- $collection.deleteMany =
465
- $collection.removeMany =
466
- $collection.deleteAll =
467
- $collection.removeAll =
468
- ($options, callback, canRunTask = false) => {
594
+ );
595
+ };
596
+ $collection.aggregate = (arr, callback) => {
469
597
  callback = callback || $collection.callback;
470
- if (!canRunTask) {
471
- $collection.taskList.push({
472
- options: $options,
473
- callback: callback,
474
- type: 'deleteAll',
475
- });
476
- } else {
477
- let options = {};
478
- if ($options.where === undefined) {
479
- options.where = $options;
480
- } else {
481
- options = $options;
482
- }
483
-
484
- if (options.where && options.where.id && typeof options.where.id === 'string') {
485
- options.where.id = ____0.toInt(options.where.id) || options.where.id;
486
- }
487
-
488
- ____0.mongodb.deleteMany(
598
+
599
+ ____0.mongodb.aggregate(
489
600
  {
490
- collectionName: $collection.collection,
491
- dbName: $collection.db,
492
- where: options.where,
601
+ collectionName: $collection.collection,
602
+ dbName: $collection.db,
603
+ arr: arr,
493
604
  },
494
- function (err, result) {
495
- callback(err, result);
496
-
497
- $collection.taskBusy = !1;
605
+ (err, docs) => {
606
+ callback(err, docs);
498
607
  }
499
- );
608
+ );
609
+ };
610
+
611
+ $collection.findDuplicate = (obj, callback) => {
612
+ callback = callback || $collection.callback;
613
+
614
+ if (typeof obj === 'string') {
615
+ obj = {
616
+ value: '$' + obj,
617
+ };
500
618
  }
501
- };
502
619
 
503
- $collection.ObjectId = $collection.ObjectID = function (_id) {
504
- if (typeof _id === 'string' && _id.length === 24) {
505
- return ____0.mongodb.ObjectID(_id);
506
- }
507
- return ____0.mongodb.ObjectID();
508
- };
509
-
510
- $collection.drop = (callback) => {
511
- callback = callback || $collection.callback;
512
- ____0.mongodb.dropCollection(
513
- {
514
- collectionName: $collection.collection,
515
- dbName: $collection.db,
516
- },
517
- (err, ok) => {
518
- if (ok) {
519
- ____0.mongodb.collections_indexed[$collection.collection].nextID = 1;
620
+ for (let [key, val] of Object.entries(obj)) {
621
+ if (val == 1) {
622
+ if (key.contains('.')) {
623
+ delete obj[key];
624
+ obj[key.replace('.', '_')] = '$' + key;
625
+ } else {
626
+ obj[key] = '$' + key;
627
+ }
628
+ }
520
629
  }
521
- callback(err, ok);
522
- }
523
- );
524
- };
525
-
526
- $collection.createUnique = (obj, callback) => {
527
- callback = callback || $collection.callback;
528
-
529
- ____0.mongodb.createIndex(
530
- {
531
- collectionName: $collection.collection,
532
- dbName: $collection.db,
533
- obj: obj,
534
- option: {
535
- unique: true,
536
- dropDups: true,
537
- },
538
- },
539
- (err, result) => {
540
- callback(err, result);
541
- }
542
- );
543
- };
544
-
545
- $collection.createIndex = (obj, options, callback) => {
546
- callback = callback || $collection.callback;
547
-
548
- if (typeof options == 'function') {
549
- callback = options;
550
- }
551
630
 
552
- ____0.mongodb.createIndex(
553
- {
554
- collectionName: $collection.collection,
555
- dbName: $collection.db,
556
- obj: obj,
557
- options: options,
558
- },
559
- (err, result) => {
560
- callback(err, result);
561
- }
562
- );
563
- };
564
- $collection.dropIndex = (obj, options, callback) => {
565
- callback = callback || $collection.callback;
566
-
567
- if (typeof options == 'function') {
568
- callback = options;
569
- }
631
+ let arr = [];
632
+ arr.push({
633
+ $group: {
634
+ _id: obj,
635
+ list: {
636
+ $addToSet: '$_id',
637
+ },
638
+ count: {
639
+ $sum: 1,
640
+ },
641
+ },
642
+ });
643
+ arr.push({
644
+ $match: {
645
+ count: {
646
+ $gt: 1,
647
+ },
648
+ },
649
+ });
650
+ arr.push({
651
+ $sort: {
652
+ count: -1,
653
+ },
654
+ });
655
+ $collection.aggregate(arr, (err, docs) => {
656
+ callback(err, docs);
657
+ });
658
+ };
570
659
 
571
- ____0.mongodb.dropIndex(
572
- {
573
- collectionName: $collection.collection,
574
- dbName: $collection.db,
575
- obj: obj,
576
- options: options,
577
- },
578
- (err, result) => {
579
- callback(err, result);
580
- }
581
- );
582
- };
583
- $collection.dropIndexes = (options, callback) => {
584
- callback = callback || $collection.callback;
585
-
586
- if (typeof options == 'function') {
587
- callback = options;
588
- }
660
+ $collection.deleteDuplicate = $collection.removeDuplicate = (obj, callback) => {
661
+ callback = callback || $collection.callback;
589
662
 
590
- ____0.mongodb.dropIndexes(
591
- {
592
- collectionName: $collection.collection,
593
- dbName: $collection.db,
594
- options: options,
595
- },
596
- (err, result) => {
597
- callback(err, result);
598
- }
599
- );
600
- };
601
- $collection.aggregate = (arr, callback) => {
602
- callback = callback || $collection.callback;
603
-
604
- ____0.mongodb.aggregate(
605
- {
606
- collectionName: $collection.collection,
607
- dbName: $collection.db,
608
- arr: arr,
609
- },
610
- (err, docs) => {
611
- callback(err, docs);
612
- }
613
- );
614
- };
615
-
616
- $collection.findDuplicate = (obj, callback) => {
617
- callback = callback || $collection.callback;
618
-
619
- if (typeof obj === 'string') {
620
- obj = {
621
- value: '$' + obj,
622
- };
623
- }
663
+ $collection.findDuplicate(obj, (err, result) => {
664
+ if (!err) {
665
+ let count = 0;
666
+ let total = 0;
667
+ let errors = [];
668
+ let lastErr = null;
669
+ for (let i = 0; i < result.length; i++) {
670
+ for (let j = result[i].list.length - 1; j > 0; j--) {
671
+ count++;
672
+ total++;
673
+ $collection.delete(result[i].list[j].toString(), (err, result) => {
674
+ count--;
675
+ if (err) {
676
+ lastErr = err;
677
+ errors.push(err);
678
+ }
679
+ if (count === 0) {
680
+ callback(lastErr, {
681
+ count: total,
682
+ errors: errors,
683
+ });
684
+ }
685
+ });
686
+ }
687
+ }
688
+ if (count === 0) {
689
+ callback(lastErr, {
690
+ count: total,
691
+ errors: errors,
692
+ });
693
+ }
694
+ }
695
+ });
696
+ };
624
697
 
625
- for (let [key, val] of Object.entries(obj)) {
626
- if (val == 1) {
627
- if (key.contains('.')) {
628
- delete obj[key];
629
- obj[key.replace('.', '_')] = '$' + key;
630
- } else {
631
- obj[key] = '$' + key;
632
- }
633
- }
634
- }
698
+ $collection.loadAll = (options, callback) => {
699
+ callback = callback || $collection.callback;
635
700
 
636
- let arr = [];
637
- arr.push({
638
- $group: {
639
- _id: obj,
640
- list: {
641
- $addToSet: '$_id',
642
- },
643
- count: {
644
- $sum: 1,
645
- },
646
- },
647
- });
648
- arr.push({
649
- $match: {
650
- count: {
651
- $gt: 1,
652
- },
653
- },
654
- });
655
- arr.push({
656
- $sort: {
657
- count: -1,
658
- },
659
- });
660
- $collection.aggregate(arr, (err, docs) => {
661
- callback(err, docs);
662
- });
663
- };
664
-
665
- $collection.deleteDuplicate = $collection.removeDuplicate = (obj, callback) => {
666
- callback = callback || $collection.callback;
667
-
668
- $collection.findDuplicate(obj, (err, result) => {
669
- if (!err) {
670
- let count = 0;
671
- let total = 0;
672
- let errors = [];
673
- let lastErr = null;
674
- for (let i = 0; i < result.length; i++) {
675
- for (let j = result[i].list.length - 1; j > 0; j--) {
676
- count++;
677
- total++;
678
- $collection.delete(result[i].list[j].toString(), (err, result) => {
679
- count--;
680
- if (err) {
681
- lastErr = err;
682
- errors.push(err);
683
- }
684
- if (count === 0) {
685
- callback(lastErr, {
686
- count: total,
687
- errors: errors,
701
+ ____0.mongodb.findMany(
702
+ {
703
+ collectionName: $collection.collection,
704
+ dbName: $collection.db,
705
+ where: options.where || {},
706
+ select: options.select || {},
707
+ limit: options.limit || 1000000,
708
+ sort: options.sort || null,
709
+ skip: options.skip || 0,
710
+ },
711
+ function (err, docs) {
712
+ if (!err && docs) {
713
+ $collection.docs = docs;
714
+ }
715
+ if (callback) callback(err, docs);
716
+ }
717
+ );
718
+ };
719
+
720
+ $collection.import = function (file_path, callback) {
721
+ callback = callback || $collection.callback;
722
+
723
+ if (____0.isFileExistsSync(file_path)) {
724
+ console.log('[ imported file exists ]');
725
+ let docs = ____0.fromJson(____0.readFileSync(file_path).toString());
726
+ console.log('[ imported file readed ]');
727
+ if (Array.isArray(docs)) {
728
+ docs.forEach((doc) => {
729
+ $collection.addOne(doc, (err, doc2) => {
730
+ if (!err && doc) {
731
+ console.log('[ import doc ] ' + doc2.id);
732
+ } else {
733
+ console.log(err);
734
+ }
735
+ });
736
+ });
737
+ callback(null, []);
738
+ } else if (____0.typeof(docs) === 'Object') {
739
+ $collection.addOne(docs, (err, doc2) => {
740
+ callback(err, doc2);
741
+ });
742
+ } else {
743
+ console.log('can not import unknown type : ' + ____0.typeof(docs));
744
+ callback({
745
+ message: 'can not import unknown type : ' + ____0.typeof(docs),
688
746
  });
689
- }
747
+ }
748
+ } else {
749
+ console.log('file not exists : ' + file_path);
750
+ callback({
751
+ message: 'file not exists : ' + file_path,
690
752
  });
691
- }
692
- }
693
- if (count === 0) {
694
- callback(lastErr, {
695
- count: total,
696
- errors: errors,
697
- });
698
- }
699
- }
700
- });
701
- };
702
-
703
- $collection.loadAll = (options, callback) => {
704
- callback = callback || $collection.callback;
705
-
706
- ____0.mongodb.findMany(
707
- {
708
- collectionName: $collection.collection,
709
- dbName: $collection.db,
710
- where: options.where || {},
711
- select: options.select || {},
712
- limit: options.limit || 1000000,
713
- sort: options.sort || null,
714
- skip: options.skip || 0,
715
- },
716
- function (err, docs) {
717
- if (!err && docs) {
718
- $collection.docs = docs;
719
753
  }
720
- if (callback) callback(err, docs);
721
- }
722
- );
723
- };
724
-
725
- $collection.import = function (file_path, callback) {
726
- callback = callback || $collection.callback;
727
-
728
- if (____0.isFileExistsSync(file_path)) {
729
- console.log('[ imported file exists ]');
730
- let docs = ____0.fromJson(____0.readFileSync(file_path).toString());
731
- console.log('[ imported file readed ]');
732
- if (Array.isArray(docs)) {
733
- docs.forEach((doc) => {
734
- $collection.addOne(doc, (err, doc2) => {
735
- if (!err && doc) {
736
- console.log('[ import doc ] ' + doc2.id);
754
+ };
755
+
756
+ $collection.export = function (options, file_path, callback) {
757
+ callback = callback || $collection.callback;
758
+ let response = {
759
+ done: !1,
760
+ file_path: file_path,
761
+ };
762
+ $collection.getMany(options, (err, docs) => {
763
+ if (!err && docs) {
764
+ response.docs = docs;
765
+ ____0.writeFile(file_path, JSON.stringify(docs), (err) => {
766
+ if (err) {
767
+ response.err = err;
768
+ } else {
769
+ response.done = !0;
770
+ }
771
+ callback(response);
772
+ });
737
773
  } else {
738
- console.log(err);
774
+ response.err = err;
775
+ callback(response);
739
776
  }
740
- });
741
777
  });
742
- callback(null, []);
743
- } else if (____0.typeof(docs) === 'Object') {
744
- $collection.addOne(docs, (err, doc2) => {
745
- callback(err, doc2);
746
- });
747
- } else {
748
- console.log('can not import unknown type : ' + ____0.typeof(docs));
749
- callback({
750
- message: 'can not import unknown type : ' + ____0.typeof(docs),
751
- });
752
- }
753
- } else {
754
- console.log('file not exists : ' + file_path);
755
- callback({
756
- message: 'file not exists : ' + file_path,
757
- });
758
- }
759
- };
760
-
761
- $collection.export = function (options, file_path, callback) {
762
- callback = callback || $collection.callback;
763
- let response = {
764
- done: !1,
765
- file_path: file_path,
766
778
  };
767
- $collection.getMany(options, (err, docs) => {
768
- if (!err && docs) {
769
- response.docs = docs;
770
- ____0.writeFile(file_path, JSON.stringify(docs), (err) => {
771
- if (err) {
772
- response.err = err;
773
- } else {
774
- response.done = !0;
775
- }
776
- callback(response);
777
- });
778
- } else {
779
- response.err = err;
780
- callback(response);
781
- }
782
- });
783
- };
784
-
785
- // id Handle
786
-
787
- if ($collection.identityEnabled) {
788
- $collection.createUnique(
789
- {
790
- id: 1,
791
- },
792
- () => {}
793
- );
794
-
795
- if ((deleteDuplicate = false)) {
796
- $collection.aggregate(
797
- [
798
- {
799
- $group: {
800
- _id: {
801
- id: '$id',
802
- },
803
- dups: {
804
- $push: '$_id',
805
- },
806
- count: {
807
- $sum: 1,
808
- },
809
- },
810
- },
811
- {
812
- $match: {
813
- count: {
814
- $gt: 1,
815
- },
779
+
780
+ // id Handle
781
+
782
+ if ($collection.identityEnabled) {
783
+ $collection.createUnique(
784
+ {
785
+ id: 1,
816
786
  },
817
- },
818
- ],
819
- function (err, docs) {
820
- if (!err && docs) {
821
- let arr = [];
822
- docs.forEach((doc) => {
823
- doc.dups.shift();
824
- doc.dups.forEach((dup) => {
825
- arr.push(dup);
826
- });
827
- });
828
- $collection.deleteAll(
829
- {
830
- _id: {
831
- $in: arr,
832
- },
833
- },
834
- (err, result) => {
835
- $collection.createUnique(
836
- {
837
- id: 1,
838
- },
839
- () => {}
840
- );
841
- }
787
+ () => {}
788
+ );
789
+
790
+ if ((deleteDuplicate = false)) {
791
+ $collection.aggregate(
792
+ [
793
+ {
794
+ $group: {
795
+ _id: {
796
+ id: '$id',
797
+ },
798
+ dups: {
799
+ $push: '$_id',
800
+ },
801
+ count: {
802
+ $sum: 1,
803
+ },
804
+ },
805
+ },
806
+ {
807
+ $match: {
808
+ count: {
809
+ $gt: 1,
810
+ },
811
+ },
812
+ },
813
+ ],
814
+ function (err, docs) {
815
+ if (!err && docs) {
816
+ let arr = [];
817
+ docs.forEach((doc) => {
818
+ doc.dups.shift();
819
+ doc.dups.forEach((dup) => {
820
+ arr.push(dup);
821
+ });
822
+ });
823
+ $collection.deleteAll(
824
+ {
825
+ _id: {
826
+ $in: arr,
827
+ },
828
+ },
829
+ (err, result) => {
830
+ $collection.createUnique(
831
+ {
832
+ id: 1,
833
+ },
834
+ () => {}
835
+ );
836
+ }
837
+ );
838
+ }
839
+ return;
840
+ }
842
841
  );
843
- }
844
- return;
845
842
  }
846
- );
847
- }
848
843
 
849
- $collection.handleIndex = function () {
850
- $collection.taskBusy = !0;
851
- $collection.identityEnabled = !0;
852
- $collection.step = ____0.options.mongodb.identity.step;
853
- if (!____0.mongodb.collections_indexed[$collection.collection]) {
854
- ____0.mongodb.collections_indexed[$collection.collection] = {
855
- nextID: ____0.options.mongodb.identity.start,
856
- };
857
- }
858
-
859
- let id = ____0.options.mongodb.identity.start;
860
-
861
- $collection.findMany(
862
- {
863
- select: {
864
- id: 1,
865
- },
866
- sort: {
867
- id: -1,
868
- },
869
- limit: 1,
870
- },
871
- (err, docs, count) => {
872
- if (!err && docs && docs[0] && docs[0].id) {
873
- if (typeof docs[0].id === 'number' && docs[0].id >= id) {
874
- id = docs[0].id + 1;
875
- } else {
876
- id += count;
844
+ $collection.handleIndex = function () {
845
+ $collection.taskBusy = !0;
846
+ $collection.identityEnabled = !0;
847
+ $collection.step = ____0.options.mongodb.identity.step;
848
+ if (!____0.mongodb.collections_indexed[$collection.collection]) {
849
+ ____0.mongodb.collections_indexed[$collection.collection] = {
850
+ nextID: ____0.options.mongodb.identity.start,
851
+ };
877
852
  }
878
- }
879
853
 
880
- ____0.mongodb.collections_indexed[$collection.collection].nextID = id;
881
- $collection.taskBusy = !1;
882
- }
883
- );
884
- };
854
+ let id = ____0.options.mongodb.identity.start;
855
+
856
+ $collection.findMany(
857
+ {
858
+ select: {
859
+ id: 1,
860
+ },
861
+ sort: {
862
+ id: -1,
863
+ },
864
+ limit: 1,
865
+ },
866
+ (err, docs, count) => {
867
+ if (!err && docs && docs[0] && docs[0].id) {
868
+ if (typeof docs[0].id === 'number' && docs[0].id >= id) {
869
+ id = docs[0].id + 1;
870
+ } else {
871
+ id += count;
872
+ }
873
+ }
874
+
875
+ ____0.mongodb.collections_indexed[$collection.collection].nextID = id;
876
+ $collection.taskBusy = !1;
877
+ },
878
+ true
879
+ );
880
+ };
885
881
 
886
- $collection.handleIndex();
887
- } else {
888
- ____0.mongodb.collections_indexed[$collection.collection] = { nextID: 1 };
889
- }
882
+ $collection.handleIndex();
883
+ } else {
884
+ ____0.mongodb.collections_indexed[$collection.collection] = { nextID: 1 };
885
+ }
890
886
 
891
- ____0.collectionList.push($collection);
892
- return $collection;
887
+ ____0.collectionList.push($collection);
888
+ return $collection;
893
889
  };