@common-stack/store-mongo 0.1.9 → 0.1.19

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/README.md CHANGED
@@ -4,6 +4,6 @@
4
4
 
5
5
  `npm link`
6
6
  `npm link @xtermstack/xterm-core`
7
- `npm install`
7
+ `yarn install`
8
8
  `tsc`
9
- `npm run test`
9
+ `yarn test`
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_SORTING: {
2
+ id: string;
3
+ };
@@ -0,0 +1 @@
1
+ export * from './default-options';
@@ -0,0 +1,7 @@
1
+ import * as DataLoader from 'dataloader';
2
+ import { IBaseService } from '../interfaces';
3
+ export declare class BulkDataLoader<T extends {
4
+ id: string;
5
+ }> extends DataLoader<string, T> {
6
+ constructor(service: IBaseService<T>);
7
+ }
@@ -0,0 +1 @@
1
+ export * from './bulk-dataloader';
package/lib/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
1
  export * from './interfaces';
2
2
  export * from './helpers';
3
+ export * from './services';
4
+ export * from './store';
5
+ export * from './dataloaders';
package/lib/index.js CHANGED
@@ -87,6 +87,113 @@ module.exports =
87
87
  /************************************************************************/
88
88
  /******/ ({
89
89
 
90
+ /***/ "./src/constants/default-options.ts":
91
+ /*!******************************************!*\
92
+ !*** ./src/constants/default-options.ts ***!
93
+ \******************************************/
94
+ /*! no static exports found */
95
+ /***/ (function(module, exports, __webpack_require__) {
96
+
97
+ "use strict";
98
+
99
+ Object.defineProperty(exports, "__esModule", { value: true });
100
+ exports.DEFAULT_SORTING = void 0;
101
+ exports.DEFAULT_SORTING = {
102
+ id: 'asc',
103
+ };
104
+
105
+
106
+ /***/ }),
107
+
108
+ /***/ "./src/constants/index.ts":
109
+ /*!********************************!*\
110
+ !*** ./src/constants/index.ts ***!
111
+ \********************************/
112
+ /*! no static exports found */
113
+ /***/ (function(module, exports, __webpack_require__) {
114
+
115
+ "use strict";
116
+
117
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
118
+ if (k2 === undefined) k2 = k;
119
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
120
+ }) : (function(o, m, k, k2) {
121
+ if (k2 === undefined) k2 = k;
122
+ o[k2] = m[k];
123
+ }));
124
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
125
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
126
+ };
127
+ Object.defineProperty(exports, "__esModule", { value: true });
128
+ __exportStar(__webpack_require__(/*! ./default-options */ "./src/constants/default-options.ts"), exports);
129
+
130
+
131
+ /***/ }),
132
+
133
+ /***/ "./src/dataloaders/bulk-dataloader.ts":
134
+ /*!********************************************!*\
135
+ !*** ./src/dataloaders/bulk-dataloader.ts ***!
136
+ \********************************************/
137
+ /*! no static exports found */
138
+ /***/ (function(module, exports, __webpack_require__) {
139
+
140
+ "use strict";
141
+
142
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
143
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
144
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
145
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
146
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
147
+ };
148
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
149
+ return function (target, key) { decorator(target, key, paramIndex); }
150
+ };
151
+ Object.defineProperty(exports, "__esModule", { value: true });
152
+ exports.BulkDataLoader = void 0;
153
+ const DataLoader = __webpack_require__(/*! dataloader */ "dataloader");
154
+ const inversify_1 = __webpack_require__(/*! inversify */ "inversify");
155
+ let BulkDataLoader = class BulkDataLoader extends DataLoader {
156
+ constructor(service) {
157
+ super(async (ids) => {
158
+ const data = await service.getByIds(ids);
159
+ return ids.map((id) => data.find((record) => record.id === id));
160
+ });
161
+ }
162
+ };
163
+ BulkDataLoader = __decorate([
164
+ inversify_1.injectable(),
165
+ __param(0, inversify_1.unmanaged())
166
+ ], BulkDataLoader);
167
+ exports.BulkDataLoader = BulkDataLoader;
168
+
169
+
170
+ /***/ }),
171
+
172
+ /***/ "./src/dataloaders/index.ts":
173
+ /*!**********************************!*\
174
+ !*** ./src/dataloaders/index.ts ***!
175
+ \**********************************/
176
+ /*! no static exports found */
177
+ /***/ (function(module, exports, __webpack_require__) {
178
+
179
+ "use strict";
180
+
181
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
182
+ if (k2 === undefined) k2 = k;
183
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
184
+ }) : (function(o, m, k, k2) {
185
+ if (k2 === undefined) k2 = k;
186
+ o[k2] = m[k];
187
+ }));
188
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
189
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
190
+ };
191
+ Object.defineProperty(exports, "__esModule", { value: true });
192
+ __exportStar(__webpack_require__(/*! ./bulk-dataloader */ "./src/dataloaders/bulk-dataloader.ts"), exports);
193
+
194
+
195
+ /***/ }),
196
+
90
197
  /***/ "./src/helpers/index.ts":
91
198
  /*!******************************!*\
92
199
  !*** ./src/helpers/index.ts ***!
@@ -104,7 +211,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
104
211
  o[k2] = m[k];
105
212
  }));
106
213
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
107
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
214
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
108
215
  };
109
216
  Object.defineProperty(exports, "__esModule", { value: true });
110
217
  __exportStar(__webpack_require__(/*! ./mongoose-connection */ "./src/helpers/mongoose-connection.ts"), exports);
@@ -163,11 +270,76 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
163
270
  o[k2] = m[k];
164
271
  }));
165
272
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
166
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
273
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
167
274
  };
168
275
  Object.defineProperty(exports, "__esModule", { value: true });
169
276
  __exportStar(__webpack_require__(/*! ./interfaces */ "./src/interfaces/index.ts"), exports);
170
277
  __exportStar(__webpack_require__(/*! ./helpers */ "./src/helpers/index.ts"), exports);
278
+ __exportStar(__webpack_require__(/*! ./services */ "./src/services/index.ts"), exports);
279
+ __exportStar(__webpack_require__(/*! ./store */ "./src/store/index.ts"), exports);
280
+ __exportStar(__webpack_require__(/*! ./dataloaders */ "./src/dataloaders/index.ts"), exports);
281
+
282
+
283
+ /***/ }),
284
+
285
+ /***/ "./src/interfaces/base-repository.ts":
286
+ /*!*******************************************!*\
287
+ !*** ./src/interfaces/base-repository.ts ***!
288
+ \*******************************************/
289
+ /*! no static exports found */
290
+ /***/ (function(module, exports, __webpack_require__) {
291
+
292
+ "use strict";
293
+
294
+ Object.defineProperty(exports, "__esModule", { value: true });
295
+
296
+
297
+ /***/ }),
298
+
299
+ /***/ "./src/interfaces/base-service.ts":
300
+ /*!****************************************!*\
301
+ !*** ./src/interfaces/base-service.ts ***!
302
+ \****************************************/
303
+ /*! no static exports found */
304
+ /***/ (function(module, exports, __webpack_require__) {
305
+
306
+ "use strict";
307
+
308
+ Object.defineProperty(exports, "__esModule", { value: true });
309
+
310
+
311
+ /***/ }),
312
+
313
+ /***/ "./src/interfaces/dataloaders.ts":
314
+ /*!***************************************!*\
315
+ !*** ./src/interfaces/dataloaders.ts ***!
316
+ \***************************************/
317
+ /*! no static exports found */
318
+ /***/ (function(module, exports, __webpack_require__) {
319
+
320
+ "use strict";
321
+
322
+ Object.defineProperty(exports, "__esModule", { value: true });
323
+
324
+
325
+ /***/ }),
326
+
327
+ /***/ "./src/interfaces/get-all-args.ts":
328
+ /*!****************************************!*\
329
+ !*** ./src/interfaces/get-all-args.ts ***!
330
+ \****************************************/
331
+ /*! no static exports found */
332
+ /***/ (function(module, exports, __webpack_require__) {
333
+
334
+ "use strict";
335
+
336
+ Object.defineProperty(exports, "__esModule", { value: true });
337
+ exports.ISortEnum = void 0;
338
+ var ISortEnum;
339
+ (function (ISortEnum) {
340
+ ISortEnum["ASC"] = "ASC";
341
+ ISortEnum["DESC"] = "DESC";
342
+ })(ISortEnum = exports.ISortEnum || (exports.ISortEnum = {}));
171
343
 
172
344
 
173
345
  /***/ }),
@@ -189,10 +361,14 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
189
361
  o[k2] = m[k];
190
362
  }));
191
363
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
192
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
364
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
193
365
  };
194
366
  Object.defineProperty(exports, "__esModule", { value: true });
195
367
  __exportStar(__webpack_require__(/*! ./mongoose-settings */ "./src/interfaces/mongoose-settings.ts"), exports);
368
+ __exportStar(__webpack_require__(/*! ./get-all-args */ "./src/interfaces/get-all-args.ts"), exports);
369
+ __exportStar(__webpack_require__(/*! ./base-repository */ "./src/interfaces/base-repository.ts"), exports);
370
+ __exportStar(__webpack_require__(/*! ./base-service */ "./src/interfaces/base-service.ts"), exports);
371
+ __exportStar(__webpack_require__(/*! ./dataloaders */ "./src/interfaces/dataloaders.ts"), exports);
196
372
 
197
373
 
198
374
  /***/ }),
@@ -209,6 +385,446 @@ __exportStar(__webpack_require__(/*! ./mongoose-settings */ "./src/interfaces/mo
209
385
  Object.defineProperty(exports, "__esModule", { value: true });
210
386
 
211
387
 
388
+ /***/ }),
389
+
390
+ /***/ "./src/services/base-service.ts":
391
+ /*!**************************************!*\
392
+ !*** ./src/services/base-service.ts ***!
393
+ \**************************************/
394
+ /*! no static exports found */
395
+ /***/ (function(module, exports, __webpack_require__) {
396
+
397
+ "use strict";
398
+
399
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
400
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
401
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
402
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
403
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
404
+ };
405
+ var __rest = (this && this.__rest) || function (s, e) {
406
+ var t = {};
407
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
408
+ t[p] = s[p];
409
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
410
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
411
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
412
+ t[p[i]] = s[p[i]];
413
+ }
414
+ return t;
415
+ };
416
+ Object.defineProperty(exports, "__esModule", { value: true });
417
+ exports.BaseService = void 0;
418
+ const inversify_1 = __webpack_require__(/*! inversify */ "inversify");
419
+ let BaseService = class BaseService {
420
+ constructor(repository) {
421
+ this.repository = repository;
422
+ this.repository = repository;
423
+ }
424
+ async getAllWithCount(options) {
425
+ const totalCount = await this.count(options.criteria);
426
+ const data = await this.getAll(options);
427
+ return {
428
+ totalCount,
429
+ data,
430
+ };
431
+ }
432
+ count(conditions) {
433
+ return this.repository.count(conditions);
434
+ }
435
+ get(id) {
436
+ return this.repository.get({ id });
437
+ }
438
+ getName(name) {
439
+ return this.repository.get({ name });
440
+ }
441
+ getAll(options) {
442
+ return this.repository.getAll(options);
443
+ }
444
+ getByIds(ids) {
445
+ return this.repository.bulkGet(ids);
446
+ }
447
+ create(data) {
448
+ return this.repository.create(data);
449
+ }
450
+ bulkCreate(data) {
451
+ return this.repository.bulkCreate(data);
452
+ }
453
+ async update(id, data, overwrite = false) {
454
+ return this.repository.update({ id }, data, { overwrite });
455
+ }
456
+ insert(data, overwrite = true) {
457
+ const { id } = data, rest = __rest(data, ["id"]);
458
+ if (id) {
459
+ const existing = this.repository.get({ id });
460
+ if (existing) {
461
+ return this.update(id, rest, overwrite);
462
+ }
463
+ }
464
+ return this.create(rest);
465
+ }
466
+ delete(id) {
467
+ return this.repository.delete({ id });
468
+ }
469
+ };
470
+ BaseService = __decorate([
471
+ inversify_1.injectable()
472
+ ], BaseService);
473
+ exports.BaseService = BaseService;
474
+
475
+
476
+ /***/ }),
477
+
478
+ /***/ "./src/services/index.ts":
479
+ /*!*******************************!*\
480
+ !*** ./src/services/index.ts ***!
481
+ \*******************************/
482
+ /*! no static exports found */
483
+ /***/ (function(module, exports, __webpack_require__) {
484
+
485
+ "use strict";
486
+
487
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
488
+ if (k2 === undefined) k2 = k;
489
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
490
+ }) : (function(o, m, k, k2) {
491
+ if (k2 === undefined) k2 = k;
492
+ o[k2] = m[k];
493
+ }));
494
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
495
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
496
+ };
497
+ Object.defineProperty(exports, "__esModule", { value: true });
498
+ __exportStar(__webpack_require__(/*! ./base-service */ "./src/services/base-service.ts"), exports);
499
+
500
+
501
+ /***/ }),
502
+
503
+ /***/ "./src/store/index.ts":
504
+ /*!****************************!*\
505
+ !*** ./src/store/index.ts ***!
506
+ \****************************/
507
+ /*! no static exports found */
508
+ /***/ (function(module, exports, __webpack_require__) {
509
+
510
+ "use strict";
511
+
512
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
513
+ if (k2 === undefined) k2 = k;
514
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
515
+ }) : (function(o, m, k, k2) {
516
+ if (k2 === undefined) k2 = k;
517
+ o[k2] = m[k];
518
+ }));
519
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
520
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
521
+ };
522
+ Object.defineProperty(exports, "__esModule", { value: true });
523
+ __exportStar(__webpack_require__(/*! ./models */ "./src/store/models/index.ts"), exports);
524
+ __exportStar(__webpack_require__(/*! ./repositories */ "./src/store/repositories/index.ts"), exports);
525
+
526
+
527
+ /***/ }),
528
+
529
+ /***/ "./src/store/models/common-options.ts":
530
+ /*!********************************************!*\
531
+ !*** ./src/store/models/common-options.ts ***!
532
+ \********************************************/
533
+ /*! no static exports found */
534
+ /***/ (function(module, exports, __webpack_require__) {
535
+
536
+ "use strict";
537
+
538
+ Object.defineProperty(exports, "__esModule", { value: true });
539
+ exports.addIdVirtualFields = exports.commonModeSchemaOptions = void 0;
540
+ exports.commonModeSchemaOptions = {
541
+ timestamps: true,
542
+ toJSON: {
543
+ virtuals: true,
544
+ },
545
+ toObject: {
546
+ virtuals: true,
547
+ getters: true,
548
+ transform(doc, ret) {
549
+ delete ret.__v;
550
+ delete ret._id;
551
+ },
552
+ },
553
+ };
554
+ const addIdVirtualFields = (schema) => {
555
+ schema.set('toJSON', {
556
+ virtuals: true,
557
+ });
558
+ return schema;
559
+ };
560
+ exports.addIdVirtualFields = addIdVirtualFields;
561
+
562
+
563
+ /***/ }),
564
+
565
+ /***/ "./src/store/models/index.ts":
566
+ /*!***********************************!*\
567
+ !*** ./src/store/models/index.ts ***!
568
+ \***********************************/
569
+ /*! no static exports found */
570
+ /***/ (function(module, exports, __webpack_require__) {
571
+
572
+ "use strict";
573
+
574
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
575
+ if (k2 === undefined) k2 = k;
576
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
577
+ }) : (function(o, m, k, k2) {
578
+ if (k2 === undefined) k2 = k;
579
+ o[k2] = m[k];
580
+ }));
581
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
582
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
583
+ };
584
+ Object.defineProperty(exports, "__esModule", { value: true });
585
+ __exportStar(__webpack_require__(/*! ./common-options */ "./src/store/models/common-options.ts"), exports);
586
+
587
+
588
+ /***/ }),
589
+
590
+ /***/ "./src/store/repositories/base-repository.ts":
591
+ /*!***************************************************!*\
592
+ !*** ./src/store/repositories/base-repository.ts ***!
593
+ \***************************************************/
594
+ /*! no static exports found */
595
+ /***/ (function(module, exports, __webpack_require__) {
596
+
597
+ "use strict";
598
+
599
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
600
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
601
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
602
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
603
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
604
+ };
605
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
606
+ return function (target, key) { decorator(target, key, paramIndex); }
607
+ };
608
+ var __rest = (this && this.__rest) || function (s, e) {
609
+ var t = {};
610
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
611
+ t[p] = s[p];
612
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
613
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
614
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
615
+ t[p[i]] = s[p[i]];
616
+ }
617
+ return t;
618
+ };
619
+ var BaseRepository_1;
620
+ Object.defineProperty(exports, "__esModule", { value: true });
621
+ exports.BaseRepository = void 0;
622
+ const lodash_1 = __webpack_require__(/*! lodash */ "lodash");
623
+ const inversify_1 = __webpack_require__(/*! inversify */ "inversify");
624
+ const constants_1 = __webpack_require__(/*! ../../constants */ "./src/constants/index.ts");
625
+ const DEFAULT_PAGINATION_LIMIT = 10;
626
+ let BaseRepository = BaseRepository_1 = class BaseRepository {
627
+ constructor(modelFunc, db, logger, options) {
628
+ this.modelFunc = modelFunc;
629
+ this.model = modelFunc(db);
630
+ this.options = options;
631
+ this.logger = logger.child({ className: BaseRepository_1.name });
632
+ }
633
+ async getAll(options) {
634
+ try {
635
+ const { criteria, selectedFields, sort, limit, skip } = options;
636
+ // map id to mongoose _id
637
+ const _a = criteria || { id: undefined }, { id } = _a, rest = __rest(_a, ["id"]);
638
+ const response = await this.model
639
+ .find(Object.assign(Object.assign({}, rest), (id ? { _id: id } : {})), selectedFields)
640
+ .limit(limit || DEFAULT_PAGINATION_LIMIT)
641
+ .skip(skip || 0)
642
+ .sort(lodash_1.isObject(sort) ? { [sort === null || sort === void 0 ? void 0 : sort.key]: sort.value } : constants_1.DEFAULT_SORTING)
643
+ .exec();
644
+ return response.map((i) => i === null || i === void 0 ? void 0 : i.toObject());
645
+ }
646
+ catch (e) {
647
+ this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(options)}`);
648
+ throw e;
649
+ }
650
+ }
651
+ // eslint-disable-next-line class-methods-use-this
652
+ mapConditions(conditions) {
653
+ const { id: _id } = conditions, remaining = __rest(conditions, ["id"]);
654
+ return Object.assign(Object.assign({}, (_id ? { _id } : {})), remaining);
655
+ }
656
+ async count(conditions) {
657
+ return this.model.count(conditions).exec();
658
+ }
659
+ async get(conditions, selectedFields) {
660
+ try {
661
+ const response = await this.model.findOne(this.mapConditions(conditions), selectedFields).exec();
662
+ return response === null || response === void 0 ? void 0 : response.toObject();
663
+ }
664
+ catch (e) {
665
+ this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(conditions)}`);
666
+ throw e;
667
+ }
668
+ }
669
+ async bulkGet(ids) {
670
+ try {
671
+ const results = await this.model.find().setOptions({ batchSize: 100 }).where('_id').in(ids).exec();
672
+ return results.map((i) => i.toObject());
673
+ }
674
+ catch (e) {
675
+ this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(ids)}`);
676
+ throw e;
677
+ }
678
+ }
679
+ async find(conditions, selectedFields) {
680
+ try {
681
+ const response = await this.model.findOne(conditions, selectedFields).exec();
682
+ return response === null || response === void 0 ? void 0 : response.toObject();
683
+ }
684
+ catch (e) {
685
+ this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(conditions)}`);
686
+ throw e;
687
+ }
688
+ }
689
+ async create(data) {
690
+ try {
691
+ const response = await this.model.create(data);
692
+ return response.toObject();
693
+ }
694
+ catch (e) {
695
+ this.logger.error(`Unable to create Model with data ${JSON.stringify(data)} due to ${e === null || e === void 0 ? void 0 : e.message}`);
696
+ throw e;
697
+ }
698
+ }
699
+ async bulkCreate(data) {
700
+ try {
701
+ const response = await this.model.insertMany(data, {
702
+ lean: true,
703
+ ordered: true,
704
+ });
705
+ return response;
706
+ }
707
+ catch (e) {
708
+ this.logger.error(`Unable to bulk create due to error`, e.message);
709
+ }
710
+ }
711
+ async upsert(conditions, update, options) {
712
+ return this.update(conditions, update, Object.assign({ upsert: true }, options));
713
+ }
714
+ async update(criteria, update, options) {
715
+ try {
716
+ const { id } = criteria, rest = __rest(criteria, ["id"]);
717
+ const processedCriteria = id ? Object.assign({ _id: id }, rest) : criteria;
718
+ const mergedOptions = Object.assign({ new: true, useFindAndModify: false }, options);
719
+ if (id) {
720
+ return (await this.model
721
+ .findByIdAndUpdate(id, update, mergedOptions)
722
+ .exec());
723
+ }
724
+ return (await this.model
725
+ .findOneAndUpdate(processedCriteria, update, mergedOptions)
726
+ .exec());
727
+ }
728
+ catch (e) {
729
+ this.logger.error(`Unable to Update with criteria ${JSON.stringify(criteria)} and data ${JSON.stringify(update)}`);
730
+ throw e;
731
+ }
732
+ }
733
+ async delete(criteria) {
734
+ try {
735
+ let deleted;
736
+ if (criteria === null || criteria === void 0 ? void 0 : criteria.id) {
737
+ deleted = await this.model.findByIdAndDelete(criteria.id);
738
+ }
739
+ else {
740
+ deleted = await this.model.findOneAndDelete(this.mapConditions(criteria));
741
+ }
742
+ return !!deleted;
743
+ }
744
+ catch (e) {
745
+ this.logger.error(`Unable to delete the model with criteria`, criteria);
746
+ throw e;
747
+ }
748
+ }
749
+ async bulkDelete(conditions) {
750
+ try {
751
+ const deleted = await this.model.deleteMany(conditions);
752
+ return (deleted === null || deleted === void 0 ? void 0 : deleted.deletedCount) || 0;
753
+ }
754
+ catch (e) {
755
+ this.logger.error(`Unable to delete the model with criteria`, conditions);
756
+ throw e;
757
+ }
758
+ }
759
+ };
760
+ BaseRepository = BaseRepository_1 = __decorate([
761
+ inversify_1.injectable(),
762
+ __param(0, inversify_1.unmanaged()),
763
+ __param(1, inversify_1.unmanaged()),
764
+ __param(2, inversify_1.unmanaged()),
765
+ __param(3, inversify_1.unmanaged())
766
+ ], BaseRepository);
767
+ exports.BaseRepository = BaseRepository;
768
+
769
+
770
+ /***/ }),
771
+
772
+ /***/ "./src/store/repositories/index.ts":
773
+ /*!*****************************************!*\
774
+ !*** ./src/store/repositories/index.ts ***!
775
+ \*****************************************/
776
+ /*! no static exports found */
777
+ /***/ (function(module, exports, __webpack_require__) {
778
+
779
+ "use strict";
780
+
781
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
782
+ if (k2 === undefined) k2 = k;
783
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
784
+ }) : (function(o, m, k, k2) {
785
+ if (k2 === undefined) k2 = k;
786
+ o[k2] = m[k];
787
+ }));
788
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
789
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
790
+ };
791
+ Object.defineProperty(exports, "__esModule", { value: true });
792
+ __exportStar(__webpack_require__(/*! ./base-repository */ "./src/store/repositories/base-repository.ts"), exports);
793
+
794
+
795
+ /***/ }),
796
+
797
+ /***/ "dataloader":
798
+ /*!*****************************!*\
799
+ !*** external "dataloader" ***!
800
+ \*****************************/
801
+ /*! no static exports found */
802
+ /***/ (function(module, exports) {
803
+
804
+ module.exports = require("dataloader");
805
+
806
+ /***/ }),
807
+
808
+ /***/ "inversify":
809
+ /*!****************************!*\
810
+ !*** external "inversify" ***!
811
+ \****************************/
812
+ /*! no static exports found */
813
+ /***/ (function(module, exports) {
814
+
815
+ module.exports = require("inversify");
816
+
817
+ /***/ }),
818
+
819
+ /***/ "lodash":
820
+ /*!*************************!*\
821
+ !*** external "lodash" ***!
822
+ \*************************/
823
+ /*! no static exports found */
824
+ /***/ (function(module, exports) {
825
+
826
+ module.exports = require("lodash");
827
+
212
828
  /***/ }),
213
829
 
214
830
  /***/ "mongoose":
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/helpers/index.ts","webpack:///./src/helpers/mongoose-connection.ts","webpack:///./src/index.ts","webpack:///./src/interfaces/index.ts","webpack:///external \"mongoose\""],"names":[],"mappings":";;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;;;;;;;;;;;;;;AClFA,gHAAsC;;;;;;;;;;;;;;;;ACAtC,iEAAqC;AAErC,IAAI,iBAAyD,CAAC;AAC9D,8CAA8C;AAE9C,MAAM,aAAa,GAAqC,CAAC,QAAQ,EAAE,EAAE;IAEjE,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,EAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACT,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QAC1C,gCAAgC;QAChC,4DAA4D;IAChE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAmB,EAAE,EAAE;QAC7B,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;QACjD,aAAa;QACb,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;IACH,+BAA+B;IAC/B,MAAM,kBAAkB,GAAwB,QAAQ,CAAC,UAAU,CAAC;IAEpE,OAAO,kBAAkB,CAAC;AAC9B,CAAC,CAAC;AAIO,sCAAa;;;;;;;;;;;;;;;;;;;;;;;;;AC1BtB,4FAA6B;AAC7B,sFAA0B;;;;;;;;;;;;;;;;;;;;;;;;;ACD1B,+GAAoC;;;;;;;;;;;;;;;;;;;;;;;;;;ACApC,qC","file":"index.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/index.ts\");\n","export * from './mongoose-connection';\n","import * as mongoose from 'mongoose';\n\nlet connectionOptions: mongoose.ConnectionOptions | undefined;\n// (mongoose as any).Promise = global.Promise;\n\nconst generateMongo: (monoUrl) => mongoose.Connection = (mongoUrl) => {\n\n // creates default connection\n mongoose.connect(mongoUrl, {\n }).then(() => {\n console.info('mogoose connect - success');\n // console.info(`uri - ${uri}`);\n // console.info(`connectionOptions - ${connectionOptions}`);\n }).catch((err: mongoose.Error) => {\n console.error('mogoose connect - error - ', err);\n // throw err;\n process.kill(process.pid);\n });\n // to access default connection\n const mongooseConnection: mongoose.Connection = mongoose.connection;\n\n return mongooseConnection;\n};\n\n\n\nexport { generateMongo };\n","export * from './interfaces';\nexport * from './helpers';\n","export * from './mongoose-settings';\n","module.exports = require(\"mongoose\");"],"sourceRoot":""}
1
+ {"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/constants/default-options.ts","webpack:///./src/constants/index.ts","webpack:///./src/dataloaders/bulk-dataloader.ts","webpack:///./src/dataloaders/index.ts","webpack:///./src/helpers/index.ts","webpack:///./src/helpers/mongoose-connection.ts","webpack:///./src/index.ts","webpack:///./src/interfaces/get-all-args.ts","webpack:///./src/interfaces/index.ts","webpack:///./src/services/base-service.ts","webpack:///./src/services/index.ts","webpack:///./src/store/index.ts","webpack:///./src/store/models/common-options.ts","webpack:///./src/store/models/index.ts","webpack:///./src/store/repositories/base-repository.ts","webpack:///./src/store/repositories/index.ts","webpack:///external \"dataloader\"","webpack:///external \"inversify\"","webpack:///external \"lodash\"","webpack:///external \"mongoose\""],"names":[],"mappings":";;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA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gCAAS,EAAE;IAEX,gCAAS,EAAE;IAEX,gCAAS,EAAE;IAEX,gCAAS,EAAE;GAdP,cAAc,CAqK1B;AArKY,wCAAc;;;;;;;;;;;;;;;;;;;;;;;;;ACT3B,mHAAkC;;;;;;;;;;;;ACAlC,uC;;;;;;;;;;;ACAA,sC;;;;;;;;;;;ACAA,mC;;;;;;;;;;;ACAA,qC","file":"index.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/index.ts\");\n","export const DEFAULT_SORTING = {\n id: 'asc',\n};\n","export * from './default-options';\n","import * as DataLoader from 'dataloader';\nimport { injectable, unmanaged } from 'inversify';\nimport { IBaseService } from '../interfaces';\n\n@injectable()\nexport class BulkDataLoader<T extends { id: string }> extends DataLoader<string, T> {\n constructor(\n @unmanaged()\n service: IBaseService<T>,\n ) {\n super(async (ids: string[]) => {\n const data = await service.getByIds(ids);\n return ids.map((id) => data.find((record) => record.id === id));\n });\n }\n}\n","export * from './bulk-dataloader';\n","export * from './mongoose-connection';\n","import * as mongoose from 'mongoose';\n\nlet connectionOptions: mongoose.ConnectionOptions | undefined;\n// (mongoose as any).Promise = global.Promise;\n\nconst generateMongo: (monoUrl) => mongoose.Connection = (mongoUrl) => {\n\n // creates default connection\n mongoose.connect(mongoUrl, {\n }).then(() => {\n console.info('mogoose connect - success');\n // console.info(`uri - ${uri}`);\n // console.info(`connectionOptions - ${connectionOptions}`);\n }).catch((err: mongoose.Error) => {\n console.error('mogoose connect - error - ', err);\n // throw err;\n process.kill(process.pid);\n });\n // to access default connection\n const mongooseConnection: mongoose.Connection = mongoose.connection;\n\n return mongooseConnection;\n};\n\n\n\nexport { generateMongo };\n","export * from './interfaces';\nexport * from './helpers';\nexport * from './services';\nexport * from './store';\nexport * from './dataloaders';\n","import { FilterQuery } from 'mongoose';\n\nexport type ISort = {\n key: string;\n value: ISortEnum;\n};\n\nexport enum ISortEnum {\n ASC = 'ASC',\n DESC = 'DESC'\n}\n\nexport interface GetAllArgs<T> {\n criteria?: FilterQuery<T>;\n sort?: ISort;\n skip?: number;\n limit?: number;\n selectedFields?: string;\n}\n","export * from './mongoose-settings';\nexport * from './get-all-args';\nexport * from './base-repository';\nexport * from './base-service';\nexport * from './dataloaders';\n","import { Document, FilterQuery } from 'mongoose';\nimport { injectable } from 'inversify';\nimport { GetAllArgs, IBaseRepository, IBaseService } from '../interfaces';\n\n@injectable()\nexport class BaseService<T, C = Omit<T, 'id'>, U = C> implements IBaseService<T, C, U> {\n constructor(protected repository: IBaseRepository<T>) {\n this.repository = repository;\n }\n\n async getAllWithCount(options: GetAllArgs<Document<T>>): Promise<{ data: T[]; totalCount: number }> {\n const totalCount = await this.count(options.criteria);\n const data = await this.getAll(options);\n return {\n totalCount,\n data,\n };\n }\n\n count(conditions?: FilterQuery<Document<T>>): Promise<number> {\n return this.repository.count(conditions);\n }\n\n get(id: string): Promise<T> {\n return this.repository.get({ id });\n }\n\n getName(name: string): Promise<T> {\n return this.repository.get({ name });\n }\n\n getAll(options: GetAllArgs<Document<T>>): Promise<T[]> {\n return this.repository.getAll(options);\n }\n\n getByIds(ids: string[]): Promise<T[]> {\n return this.repository.bulkGet(ids);\n }\n\n create(data: C): Promise<T> {\n return this.repository.create<C>(data);\n }\n\n bulkCreate(data: C[]): Promise<T[]> {\n return this.repository.bulkCreate<C>(data);\n }\n\n async update(id: string, data: Partial<U>, overwrite = false): Promise<T> {\n return this.repository.update<U>({ id }, data, { overwrite });\n }\n\n insert(data: (C | U) & { id?: string }, overwrite = true): Promise<T> {\n const { id, ...rest } = data;\n if (id) {\n const existing = this.repository.get({ id });\n if (existing) {\n return this.update(id, rest as U, overwrite);\n }\n }\n return this.create(rest as C);\n }\n\n delete(id: string): Promise<boolean> {\n return this.repository.delete({ id });\n }\n}\n","export * from './base-service';\n","export * from './models';\nexport * from './repositories';\n","import { Schema } from 'mongoose';\n\nexport const commonModeSchemaOptions = {\n timestamps: true,\n toJSON: {\n virtuals: true,\n },\n toObject: {\n virtuals: true,\n getters: true,\n transform(doc, ret) {\n delete ret.__v;\n delete ret._id;\n },\n },\n};\n\nexport const addIdVirtualFields = (schema: Schema) => {\n schema.set('toJSON', {\n virtuals: true,\n });\n return schema;\n};\n","export * from './common-options';\n","import { isObject } from 'lodash';\nimport { logger as Logger } from '@cdm-logger/server';\nimport { Connection, Document, FilterQuery, Model, UpdateQuery } from 'mongoose';\nimport { injectable, unmanaged } from 'inversify';\nimport { GetAllArgs, IBaseRepository, IMongoOptions } from '../../interfaces';\nimport { DEFAULT_SORTING } from '../../constants';\n\nconst DEFAULT_PAGINATION_LIMIT = 10;\n@injectable()\nexport class BaseRepository<T, D = Document<T>> implements IBaseRepository<T, D> {\n private options: IMongoOptions;\n\n protected logger: typeof Logger;\n\n model: Model<D>;\n\n constructor(\n @unmanaged()\n private modelFunc: (db: Connection) => Model<D>,\n @unmanaged()\n db: Connection,\n @unmanaged()\n logger: typeof Logger,\n @unmanaged()\n options?: IMongoOptions,\n ) {\n this.model = modelFunc(db);\n this.options = options;\n this.logger = logger.child({ className: BaseRepository.name });\n }\n\n public async getAll(options: GetAllArgs<D>): Promise<T[]> {\n try {\n const { criteria, selectedFields, sort, limit, skip } = options;\n // map id to mongoose _id\n const { id, ...rest } = criteria || { id: undefined };\n const response = await this.model\n .find({ ...rest, ...(id ? { _id: id } : {}) }, selectedFields)\n .limit(limit || DEFAULT_PAGINATION_LIMIT)\n .skip(skip || 0)\n .sort(isObject(sort) ? { [sort?.key]: sort.value } : DEFAULT_SORTING)\n .exec();\n return response.map((i) => i?.toObject()) as T[];\n } catch (e) {\n this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(options)}`);\n throw e;\n }\n }\n\n // eslint-disable-next-line class-methods-use-this\n private mapConditions(conditions: FilterQuery<D>): FilterQuery<D> {\n const { id: _id, ...remaining } = conditions;\n return {\n ...(_id ? { _id } : {}),\n ...remaining,\n };\n }\n\n public async count(conditions?: FilterQuery<D>): Promise<number> {\n return this.model.count(conditions).exec();\n }\n\n public async get(conditions?: FilterQuery<D>, selectedFields?: string): Promise<T> {\n try {\n const response = await this.model.findOne(this.mapConditions(conditions), selectedFields).exec();\n return response?.toObject() as T;\n } catch (e) {\n this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(conditions)}`);\n throw e;\n }\n }\n\n public async bulkGet(ids: string[]): Promise<T[]> {\n try {\n const results = await this.model.find().setOptions({ batchSize: 100 }).where('_id').in(ids).exec();\n return results.map((i) => i.toObject()) as T[];\n } catch (e) {\n this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(ids)}`);\n throw e;\n }\n }\n\n public async find(conditions: Partial<FilterQuery<D>>, selectedFields?: string): Promise<T> {\n try {\n const response = await this.model.findOne(conditions, selectedFields).exec();\n return response?.toObject() as T;\n } catch (e) {\n this.logger.error(`Unable to retrieve Model with criteria ${JSON.stringify(conditions)}`);\n throw e;\n }\n }\n\n public async create<I>(data: I): Promise<T> {\n try {\n const response = await this.model.create(data);\n return response.toObject() as T;\n } catch (e) {\n this.logger.error(`Unable to create Model with data ${JSON.stringify(data)} due to ${e?.message}`);\n throw e;\n }\n }\n\n public async bulkCreate<I>(data: I[]): Promise<T[]> {\n try {\n const response = await this.model.insertMany(data, {\n lean: true,\n ordered: true,\n });\n return response as unknown as T[];\n } catch (e) {\n this.logger.error(`Unable to bulk create due to error`, e.message);\n }\n }\n\n public async upsert<I>(conditions: FilterQuery<D>, update: I, options?: Record<string, unknown>): Promise<T> {\n return this.update<I>(conditions, update, {\n upsert: true,\n ...options,\n });\n }\n\n public async update<I>(\n criteria: FilterQuery<D>,\n update: UpdateQuery<D>,\n options: Record<string, unknown>,\n ): Promise<T> {\n try {\n const { id, ...rest } = criteria;\n const processedCriteria = id ? { _id: id, ...rest } : criteria;\n const mergedOptions = {\n new: true,\n useFindAndModify: false,\n ...options,\n };\n if (id) {\n return (await this.model\n .findByIdAndUpdate(id, update as unknown as never, mergedOptions)\n .exec()) as unknown as Promise<T>;\n }\n return (await this.model\n .findOneAndUpdate(processedCriteria, update as unknown as never, mergedOptions)\n .exec()) as unknown as Promise<T>;\n } catch (e) {\n this.logger.error(\n `Unable to Update with criteria ${JSON.stringify(criteria)} and data ${JSON.stringify(update)}`,\n );\n throw e;\n }\n }\n\n public async delete(criteria: FilterQuery<D>): Promise<boolean> {\n try {\n let deleted;\n if (criteria?.id) {\n deleted = await this.model.findByIdAndDelete(criteria.id);\n } else {\n deleted = await this.model.findOneAndDelete(this.mapConditions(criteria));\n }\n return !!deleted;\n } catch (e) {\n this.logger.error(`Unable to delete the model with criteria`, criteria);\n throw e;\n }\n }\n\n public async bulkDelete(conditions: FilterQuery<D>): Promise<number> {\n try {\n const deleted = await this.model.deleteMany(conditions);\n return deleted?.deletedCount || 0;\n } catch (e) {\n this.logger.error(`Unable to delete the model with criteria`, conditions);\n throw e;\n }\n }\n}\n","export * from './base-repository';\n","module.exports = require(\"dataloader\");","module.exports = require(\"inversify\");","module.exports = require(\"lodash\");","module.exports = require(\"mongoose\");"],"sourceRoot":""}
@@ -0,0 +1,15 @@
1
+ import { FilterQuery, Document, Model, UpdateQuery } from 'mongoose';
2
+ import { GetAllArgs } from './get-all-args';
3
+ export interface IBaseRepository<T, D = Document<T>> {
4
+ model: Model<D>;
5
+ count(conditions?: FilterQuery<D>): Promise<number>;
6
+ getAll(options: GetAllArgs<D>): Promise<T[]>;
7
+ get(conditions?: FilterQuery<D>, selectedFields?: string): Promise<T>;
8
+ create<I>(data: I): Promise<T>;
9
+ upsert<I>(conditions: FilterQuery<D>, update: I, options: any): Promise<T>;
10
+ update<I>(criteria: FilterQuery<D>, update: UpdateQuery<D>, options?: any): Promise<T>;
11
+ delete(criteria: FilterQuery<D>): Promise<boolean>;
12
+ bulkGet(ids: string[], selectedFields?: string): Promise<T[]>;
13
+ bulkCreate<I>(data: I[]): Promise<T[]>;
14
+ bulkDelete(criteria: FilterQuery<D>): Promise<number>;
15
+ }
@@ -0,0 +1,19 @@
1
+ import { FilterQuery, Document } from 'mongoose';
2
+ import { GetAllArgs } from './get-all-args';
3
+ export interface IBaseService<T, C = Omit<T, 'id'>, U = C> {
4
+ count(conditions?: FilterQuery<Document<T>>): Promise<number>;
5
+ get(id: string): Promise<T>;
6
+ getAll(options?: GetAllArgs<Document<T>>): Promise<T[]>;
7
+ getByIds(ids: string[]): Promise<T[]>;
8
+ create(data: C): Promise<T>;
9
+ insert(data: (C | U) & {
10
+ id?: string;
11
+ }, overwrite?: boolean): Promise<T>;
12
+ bulkCreate(data: C[]): Promise<T[]>;
13
+ update(id: string, data: Partial<U>, overwrite?: boolean): Promise<T>;
14
+ delete(id: string): Promise<boolean>;
15
+ getAllWithCount(options: GetAllArgs<Document<T>>): Promise<{
16
+ data: T[];
17
+ totalCount: number;
18
+ }>;
19
+ }
@@ -0,0 +1,2 @@
1
+ import * as DataLoader from 'dataloader';
2
+ export declare type IDataLoader<T> = DataLoader<string, T>;
@@ -0,0 +1,16 @@
1
+ import { FilterQuery } from 'mongoose';
2
+ export declare type ISort = {
3
+ key: string;
4
+ value: ISortEnum;
5
+ };
6
+ export declare enum ISortEnum {
7
+ ASC = "ASC",
8
+ DESC = "DESC"
9
+ }
10
+ export interface GetAllArgs<T> {
11
+ criteria?: FilterQuery<T>;
12
+ sort?: ISort;
13
+ skip?: number;
14
+ limit?: number;
15
+ selectedFields?: string;
16
+ }
@@ -1 +1,5 @@
1
1
  export * from './mongoose-settings';
2
+ export * from './get-all-args';
3
+ export * from './base-repository';
4
+ export * from './base-service';
5
+ export * from './dataloaders';
@@ -0,0 +1,22 @@
1
+ import { Document, FilterQuery } from 'mongoose';
2
+ import { GetAllArgs, IBaseRepository, IBaseService } from '../interfaces';
3
+ export declare class BaseService<T, C = Omit<T, 'id'>, U = C> implements IBaseService<T, C, U> {
4
+ protected repository: IBaseRepository<T>;
5
+ constructor(repository: IBaseRepository<T>);
6
+ getAllWithCount(options: GetAllArgs<Document<T>>): Promise<{
7
+ data: T[];
8
+ totalCount: number;
9
+ }>;
10
+ count(conditions?: FilterQuery<Document<T>>): Promise<number>;
11
+ get(id: string): Promise<T>;
12
+ getName(name: string): Promise<T>;
13
+ getAll(options: GetAllArgs<Document<T>>): Promise<T[]>;
14
+ getByIds(ids: string[]): Promise<T[]>;
15
+ create(data: C): Promise<T>;
16
+ bulkCreate(data: C[]): Promise<T[]>;
17
+ update(id: string, data: Partial<U>, overwrite?: boolean): Promise<T>;
18
+ insert(data: (C | U) & {
19
+ id?: string;
20
+ }, overwrite?: boolean): Promise<T>;
21
+ delete(id: string): Promise<boolean>;
22
+ }
@@ -0,0 +1 @@
1
+ export * from './base-service';
@@ -0,0 +1,2 @@
1
+ export * from './models';
2
+ export * from './repositories';
@@ -0,0 +1,13 @@
1
+ import { Schema } from 'mongoose';
2
+ export declare const commonModeSchemaOptions: {
3
+ timestamps: boolean;
4
+ toJSON: {
5
+ virtuals: boolean;
6
+ };
7
+ toObject: {
8
+ virtuals: boolean;
9
+ getters: boolean;
10
+ transform(doc: any, ret: any): void;
11
+ };
12
+ };
13
+ export declare const addIdVirtualFields: (schema: Schema) => Schema<import("mongoose").Document<any, any, any>, import("mongoose").Model<import("mongoose").Document<any, any, any>, any, any>, undefined, {}>;
@@ -0,0 +1 @@
1
+ export * from './common-options';
@@ -0,0 +1,22 @@
1
+ import { logger as Logger } from '@cdm-logger/server';
2
+ import { Connection, Document, FilterQuery, Model, UpdateQuery } from 'mongoose';
3
+ import { GetAllArgs, IBaseRepository, IMongoOptions } from '../../interfaces';
4
+ export declare class BaseRepository<T, D = Document<T>> implements IBaseRepository<T, D> {
5
+ private modelFunc;
6
+ private options;
7
+ protected logger: typeof Logger;
8
+ model: Model<D>;
9
+ constructor(modelFunc: (db: Connection) => Model<D>, db: Connection, logger: typeof Logger, options?: IMongoOptions);
10
+ getAll(options: GetAllArgs<D>): Promise<T[]>;
11
+ private mapConditions;
12
+ count(conditions?: FilterQuery<D>): Promise<number>;
13
+ get(conditions?: FilterQuery<D>, selectedFields?: string): Promise<T>;
14
+ bulkGet(ids: string[]): Promise<T[]>;
15
+ find(conditions: Partial<FilterQuery<D>>, selectedFields?: string): Promise<T>;
16
+ create<I>(data: I): Promise<T>;
17
+ bulkCreate<I>(data: I[]): Promise<T[]>;
18
+ upsert<I>(conditions: FilterQuery<D>, update: I, options?: Record<string, unknown>): Promise<T>;
19
+ update<I>(criteria: FilterQuery<D>, update: UpdateQuery<D>, options: Record<string, unknown>): Promise<T>;
20
+ delete(criteria: FilterQuery<D>): Promise<boolean>;
21
+ bulkDelete(conditions: FilterQuery<D>): Promise<number>;
22
+ }
@@ -0,0 +1 @@
1
+ export * from './base-repository';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@common-stack/store-mongo",
3
- "version": "0.1.9",
3
+ "version": "0.1.19",
4
4
  "description": "Sample core for higher packages to depend on",
5
5
  "license": "ISC",
6
6
  "author": "CDMBase LLC",
@@ -19,8 +19,11 @@
19
19
  "watch": "npm run build:lib:watch"
20
20
  },
21
21
  "dependencies": {
22
- "@common-stack/core": "^0.1.9",
23
- "sequelize": "^5.21.3"
22
+ "@common-stack/core": "^0.1.19"
23
+ },
24
+ "peerDependencies": {
25
+ "dataloader": ">=2.0.0",
26
+ "mongoose": ">=5.13.5"
24
27
  },
25
28
  "publishConfig": {
26
29
  "access": "public"
@@ -28,5 +31,5 @@
28
31
  "typescript": {
29
32
  "definition": "lib/index.d.ts"
30
33
  },
31
- "gitHead": "8e7e4d7698d499e4069fb38a300b3520fd4e1fa3"
34
+ "gitHead": "07b5a92c5d84b83b96389ee85c2e1174c0ef75c6"
32
35
  }
package/CHANGELOG.md DELETED
@@ -1,160 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- ## [0.1.9](https://github.com/cdmbase/common-stack/compare/v0.1.8...v0.1.9) (2021-10-07)
7
-
8
- **Note:** Version bump only for package @common-stack/store-mongo
9
-
10
-
11
-
12
-
13
-
14
- ## [0.1.7](https://github.com/cdmbase/common-stack/compare/v0.1.6...v0.1.7) (2021-08-11)
15
-
16
- **Note:** Version bump only for package @common-stack/store-mongo
17
-
18
-
19
-
20
-
21
-
22
- ## [0.1.6](https://github.com/cdmbase/common-stack/compare/v0.1.5...v0.1.6) (2021-08-11)
23
-
24
- **Note:** Version bump only for package @common-stack/store-mongo
25
-
26
-
27
-
28
-
29
-
30
- ## [0.1.5](https://github.com/cdmbase/common-stack/compare/v0.1.4...v0.1.5) (2021-08-11)
31
-
32
- **Note:** Version bump only for package @common-stack/store-mongo
33
-
34
-
35
-
36
-
37
-
38
- ## [0.1.4](https://github.com/cdmbase/common-stack/compare/v0.1.3...v0.1.4) (2021-08-11)
39
-
40
- **Note:** Version bump only for package @common-stack/store-mongo
41
-
42
-
43
-
44
-
45
-
46
- ## [0.1.3](https://github.com/cdmbase/common-stack/compare/v0.1.2...v0.1.3) (2021-08-11)
47
-
48
- **Note:** Version bump only for package @common-stack/store-mongo
49
-
50
-
51
-
52
-
53
-
54
- ## [0.1.1](https://github.com/cdmbase/common-stack/compare/v0.0.264...v0.1.1) (2021-08-05)
55
-
56
- **Note:** Version bump only for package @common-stack/store-mongo
57
-
58
-
59
-
60
-
61
-
62
- ## [0.0.264](https://github.com/cdmbase/common-stack/compare/v0.0.263...v0.0.264) (2021-07-04)
63
-
64
- **Note:** Version bump only for package @common-stack/store-mongo
65
-
66
-
67
-
68
-
69
-
70
- ## [0.0.263](https://github.com/cdmbase/common-stack/compare/v0.0.262...v0.0.263) (2021-07-03)
71
-
72
- **Note:** Version bump only for package @common-stack/store-mongo
73
-
74
-
75
-
76
-
77
-
78
- ## [0.0.262](https://github.com/cdmbase/common-stack/compare/v0.0.261...v0.0.262) (2021-06-23)
79
-
80
- **Note:** Version bump only for package @common-stack/store-mongo
81
-
82
-
83
-
84
-
85
-
86
- ## [0.0.261](https://github.com/cdmbase/common-stack/compare/v0.0.260...v0.0.261) (2021-06-01)
87
-
88
- **Note:** Version bump only for package @common-stack/store-mongo
89
-
90
-
91
-
92
-
93
-
94
- ## [0.0.260](https://github.com/cdmbase/common-stack/compare/v0.0.259...v0.0.260) (2021-05-28)
95
-
96
- **Note:** Version bump only for package @common-stack/store-mongo
97
-
98
-
99
-
100
-
101
-
102
- ## [0.0.259](https://github.com/cdmbase/common-stack/compare/v0.0.258...v0.0.259) (2021-05-28)
103
-
104
- **Note:** Version bump only for package @common-stack/store-mongo
105
-
106
-
107
-
108
-
109
-
110
- ## [0.0.258](https://github.com/cdmbase/common-stack/compare/v0.0.257...v0.0.258) (2021-05-14)
111
-
112
- **Note:** Version bump only for package @common-stack/store-mongo
113
-
114
-
115
-
116
-
117
-
118
- ## [0.0.257](https://github.com/cdmbase/common-stack/compare/v0.0.256...v0.0.257) (2021-05-05)
119
-
120
- **Note:** Version bump only for package @common-stack/store-mongo
121
-
122
-
123
-
124
-
125
-
126
- ## [0.0.256](https://github.com/cdmbase/common-stack/compare/v0.0.255...v0.0.256) (2021-05-05)
127
-
128
- **Note:** Version bump only for package @common-stack/store-mongo
129
-
130
-
131
-
132
-
133
-
134
- ## [0.0.255](https://github.com/cdmbase/common-stack/compare/v0.0.254...v0.0.255) (2021-04-03)
135
-
136
- **Note:** Version bump only for package @common-stack/store-mongo
137
-
138
-
139
-
140
-
141
-
142
- ## [0.0.254](https://github.com/cdmbase/common-stack/compare/v0.0.253...v0.0.254) (2021-03-31)
143
-
144
- **Note:** Version bump only for package @common-stack/store-mongo
145
-
146
-
147
-
148
-
149
-
150
- ## [0.0.253](https://github.com/cdmbase/common-stack/compare/v0.0.252...v0.0.253) (2021-03-31)
151
-
152
- **Note:** Version bump only for package @common-stack/store-mongo
153
-
154
-
155
-
156
-
157
-
158
- ## [0.0.252](https://github.com/cdmbase/common-stack/compare/v0.0.251...v0.0.252) (2021-03-29)
159
-
160
- **Note:** Version bump only for package @common-stack/store-mongo