isite 2022.9.17 → 2022.9.18

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