@e22m4u/js-repository-mongodb-adapter 0.5.1 → 0.6.0

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.
@@ -2,6 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
6
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
@@ -16,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
21
 
20
22
  // src/index.js
21
23
  var index_exports = {};
@@ -28,6 +30,51 @@ module.exports = __toCommonJS(index_exports);
28
30
  var import_mongodb2 = require("mongodb");
29
31
  var import_mongodb3 = require("mongodb");
30
32
 
33
+ // src/utils/pluralize.js
34
+ var singularExceptions = [
35
+ /access$/i,
36
+ /address$/i,
37
+ /alias$/i,
38
+ /bonus$/i,
39
+ /boss$/i,
40
+ /bus$/i,
41
+ /business$/i,
42
+ /canvas$/i,
43
+ /class$/i,
44
+ /cross$/i,
45
+ /dress$/i,
46
+ /focus$/i,
47
+ /gas$/i,
48
+ /glass$/i,
49
+ /kiss$/i,
50
+ /lens$/i,
51
+ /loss$/i,
52
+ /pass$/i,
53
+ /plus$/i,
54
+ /process$/i,
55
+ /status$/i,
56
+ /success$/i,
57
+ /virus$/i
58
+ ];
59
+ function pluralize(input) {
60
+ if (!input || typeof input !== "string") {
61
+ return input;
62
+ }
63
+ if (/s$/i.test(input) && !singularExceptions.some((re) => re.test(input))) {
64
+ return input;
65
+ }
66
+ const lastChar = input.slice(-1);
67
+ const isLastCharUpper = lastChar === lastChar.toUpperCase() && lastChar !== lastChar.toLowerCase();
68
+ if (/(s|x|z|ch|sh)$/i.test(input)) {
69
+ return input + (isLastCharUpper ? "ES" : "es");
70
+ }
71
+ if (/[^aeiou]y$/i.test(input)) {
72
+ return input.slice(0, -1) + (isLastCharUpper ? "IES" : "ies");
73
+ }
74
+ return input + (isLastCharUpper ? "S" : "s");
75
+ }
76
+ __name(pluralize, "pluralize");
77
+
31
78
  // src/utils/is-iso-date.js
32
79
  function isIsoDate(value) {
33
80
  if (!value) return false;
@@ -48,6 +95,16 @@ function isObjectId(value) {
48
95
  }
49
96
  __name(isObjectId, "isObjectId");
50
97
 
98
+ // src/utils/to-camel-case.js
99
+ function toCamelCase(input) {
100
+ if (!input) return "";
101
+ const spacedString = String(input).replace(/([-_])/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2");
102
+ const intermediateCased = spacedString.toLowerCase().replace(/\s(.)/g, ($1) => $1.toUpperCase()).replace(/\s/g, "");
103
+ if (!intermediateCased) return "";
104
+ return intermediateCased.charAt(0).toLowerCase() + intermediateCased.slice(1);
105
+ }
106
+ __name(toCamelCase, "toCamelCase");
107
+
51
108
  // src/utils/create-mongodb-url.js
52
109
  var import_js_repository = require("@e22m4u/js-repository");
53
110
  function createMongodbUrl(options = {}) {
@@ -149,6 +206,17 @@ function transformValuesDeep(value, transformer) {
149
206
  }
150
207
  __name(transformValuesDeep, "transformValuesDeep");
151
208
 
209
+ // src/utils/model-name-to-collection-name.js
210
+ function modelNameToCollectionName(modelName) {
211
+ const ccName = toCamelCase(modelName);
212
+ const woModel = ccName.replace(/Model$/i, "");
213
+ if (woModel.length <= 2) {
214
+ return pluralize(ccName);
215
+ }
216
+ return pluralize(woModel);
217
+ }
218
+ __name(modelNameToCollectionName, "modelNameToCollectionName");
219
+
152
220
  // src/mongodb-adapter.js
153
221
  var import_js_repository3 = require("@e22m4u/js-repository");
154
222
  var import_js_repository4 = require("@e22m4u/js-repository");
@@ -156,6 +224,733 @@ var import_js_repository5 = require("@e22m4u/js-repository");
156
224
 
157
225
  // node_modules/@e22m4u/js-service/src/errors/invalid-argument-error.js
158
226
  var import_js_format = require("@e22m4u/js-format");
227
+ var _InvalidArgumentError = class _InvalidArgumentError extends import_js_format.Errorf {
228
+ };
229
+ __name(_InvalidArgumentError, "InvalidArgumentError");
230
+ var InvalidArgumentError3 = _InvalidArgumentError;
231
+
232
+ // node_modules/@e22m4u/js-service/src/service-container.js
233
+ var SERVICE_CONTAINER_CLASS_NAME = "ServiceContainer";
234
+ var _ServiceContainer = class _ServiceContainer {
235
+ /**
236
+ * Services map.
237
+ *
238
+ * @type {Map<any, any>}
239
+ * @private
240
+ */
241
+ _services = /* @__PURE__ */ new Map();
242
+ /**
243
+ * Parent container.
244
+ *
245
+ * @type {ServiceContainer}
246
+ * @private
247
+ */
248
+ _parent;
249
+ /**
250
+ * Constructor.
251
+ *
252
+ * @param {ServiceContainer|undefined} parent
253
+ */
254
+ constructor(parent = void 0) {
255
+ if (parent != null) {
256
+ if (!(parent instanceof _ServiceContainer))
257
+ throw new InvalidArgumentError3(
258
+ 'The provided parameter "parent" of ServicesContainer.constructor must be an instance ServiceContainer, but %v given.',
259
+ parent
260
+ );
261
+ this._parent = parent;
262
+ }
263
+ }
264
+ /**
265
+ * Получить родительский сервис-контейнер или выбросить ошибку.
266
+ *
267
+ * @returns {ServiceContainer}
268
+ */
269
+ getParent() {
270
+ if (!this._parent)
271
+ throw new InvalidArgumentError3("The service container has no parent.");
272
+ return this._parent;
273
+ }
274
+ /**
275
+ * Проверить наличие родительского сервис-контейнера.
276
+ *
277
+ * @returns {boolean}
278
+ */
279
+ hasParent() {
280
+ return Boolean(this._parent);
281
+ }
282
+ /**
283
+ * Получить существующий или новый экземпляр.
284
+ *
285
+ * @param {*} ctor
286
+ * @param {*} args
287
+ * @returns {*}
288
+ */
289
+ get(ctor, ...args) {
290
+ if (!ctor || typeof ctor !== "function")
291
+ throw new InvalidArgumentError3(
292
+ "The first argument of ServicesContainer.get must be a class constructor, but %v given.",
293
+ ctor
294
+ );
295
+ if (!this._services.has(ctor) && this._parent && this._parent.has(ctor)) {
296
+ return this._parent.get(ctor);
297
+ }
298
+ let service = this._services.get(ctor);
299
+ if (!service) {
300
+ const ctors = this._services.keys();
301
+ const inheritedCtor = ctors.find((v) => v.prototype instanceof ctor);
302
+ if (inheritedCtor) {
303
+ service = this._services.get(inheritedCtor);
304
+ ctor = inheritedCtor;
305
+ }
306
+ }
307
+ if (!service || args.length) {
308
+ service = Array.isArray(ctor.kinds) && ctor.kinds.includes(SERVICE_CLASS_NAME) ? new ctor(this, ...args) : new ctor(...args);
309
+ this._services.set(ctor, service);
310
+ } else if (typeof service === "function") {
311
+ service = service();
312
+ this._services.set(ctor, service);
313
+ }
314
+ return service;
315
+ }
316
+ /**
317
+ * Получить существующий или новый экземпляр,
318
+ * только если конструктор зарегистрирован.
319
+ *
320
+ * @param {*} ctor
321
+ * @param {*} args
322
+ * @returns {*}
323
+ */
324
+ getRegistered(ctor, ...args) {
325
+ if (!this.has(ctor))
326
+ throw new InvalidArgumentError3(
327
+ "The constructor %v is not registered.",
328
+ ctor
329
+ );
330
+ return this.get(ctor, ...args);
331
+ }
332
+ /**
333
+ * Проверить существование конструктора в контейнере.
334
+ *
335
+ * @param {*} ctor
336
+ * @returns {boolean}
337
+ */
338
+ has(ctor) {
339
+ if (this._services.has(ctor)) return true;
340
+ if (this._parent) return this._parent.has(ctor);
341
+ const ctors = this._services.keys();
342
+ const inheritedCtor = ctors.find((v) => v.prototype instanceof ctor);
343
+ if (inheritedCtor) return true;
344
+ return false;
345
+ }
346
+ /**
347
+ * Добавить конструктор в контейнер.
348
+ *
349
+ * @param {*} ctor
350
+ * @param {*} args
351
+ * @returns {this}
352
+ */
353
+ add(ctor, ...args) {
354
+ if (!ctor || typeof ctor !== "function")
355
+ throw new InvalidArgumentError3(
356
+ "The first argument of ServicesContainer.add must be a class constructor, but %v given.",
357
+ ctor
358
+ );
359
+ const factory = /* @__PURE__ */ __name(() => Array.isArray(ctor.kinds) && ctor.kinds.includes(SERVICE_CLASS_NAME) ? new ctor(this, ...args) : new ctor(...args), "factory");
360
+ this._services.set(ctor, factory);
361
+ return this;
362
+ }
363
+ /**
364
+ * Добавить конструктор и создать экземпляр.
365
+ *
366
+ * @param {*} ctor
367
+ * @param {*} args
368
+ * @returns {this}
369
+ */
370
+ use(ctor, ...args) {
371
+ if (!ctor || typeof ctor !== "function")
372
+ throw new InvalidArgumentError3(
373
+ "The first argument of ServicesContainer.use must be a class constructor, but %v given.",
374
+ ctor
375
+ );
376
+ const service = Array.isArray(ctor.kinds) && ctor.kinds.includes(SERVICE_CLASS_NAME) ? new ctor(this, ...args) : new ctor(...args);
377
+ this._services.set(ctor, service);
378
+ return this;
379
+ }
380
+ /**
381
+ * Добавить конструктор и связанный экземпляр.
382
+ *
383
+ * @param {*} ctor
384
+ * @param {*} service
385
+ * @returns {this}
386
+ */
387
+ set(ctor, service) {
388
+ if (!ctor || typeof ctor !== "function")
389
+ throw new InvalidArgumentError3(
390
+ "The first argument of ServicesContainer.set must be a class constructor, but %v given.",
391
+ ctor
392
+ );
393
+ if (!service || typeof service !== "object" || Array.isArray(service))
394
+ throw new InvalidArgumentError3(
395
+ "The second argument of ServicesContainer.set must be an Object, but %v given.",
396
+ service
397
+ );
398
+ this._services.set(ctor, service);
399
+ return this;
400
+ }
401
+ };
402
+ __name(_ServiceContainer, "ServiceContainer");
403
+ /**
404
+ * Kinds.
405
+ *
406
+ * @type {string[]}
407
+ */
408
+ __publicField(_ServiceContainer, "kinds", [SERVICE_CONTAINER_CLASS_NAME]);
409
+ var ServiceContainer = _ServiceContainer;
410
+
411
+ // node_modules/@e22m4u/js-service/src/utils/is-service-container.js
412
+ function isServiceContainer(container) {
413
+ return Boolean(
414
+ container && typeof container === "object" && typeof container.constructor === "function" && Array.isArray(container.constructor.kinds) && container.constructor.kinds.includes(SERVICE_CONTAINER_CLASS_NAME)
415
+ );
416
+ }
417
+ __name(isServiceContainer, "isServiceContainer");
418
+
419
+ // node_modules/@e22m4u/js-service/src/service.js
420
+ var SERVICE_CLASS_NAME = "Service";
421
+ var _Service = class _Service {
422
+ /**
423
+ * Container.
424
+ *
425
+ * @type {ServiceContainer}
426
+ */
427
+ container;
428
+ /**
429
+ * Constructor.
430
+ *
431
+ * @param {ServiceContainer|undefined} container
432
+ */
433
+ constructor(container = void 0) {
434
+ this.container = isServiceContainer(container) ? container : new ServiceContainer();
435
+ }
436
+ /**
437
+ * Получить существующий или новый экземпляр.
438
+ *
439
+ * @param {*} ctor
440
+ * @param {*} args
441
+ * @returns {*}
442
+ */
443
+ getService(ctor, ...args) {
444
+ return this.container.get(ctor, ...args);
445
+ }
446
+ /**
447
+ * Получить существующий или новый экземпляр,
448
+ * только если конструктор зарегистрирован.
449
+ *
450
+ * @param {*} ctor
451
+ * @param {*} args
452
+ * @returns {*}
453
+ */
454
+ getRegisteredService(ctor, ...args) {
455
+ return this.container.getRegistered(ctor, ...args);
456
+ }
457
+ /**
458
+ * Проверка существования конструктора в контейнере.
459
+ *
460
+ * @param {*} ctor
461
+ * @returns {boolean}
462
+ */
463
+ hasService(ctor) {
464
+ return this.container.has(ctor);
465
+ }
466
+ /**
467
+ * Добавить конструктор в контейнер.
468
+ *
469
+ * @param {*} ctor
470
+ * @param {*} args
471
+ * @returns {this}
472
+ */
473
+ addService(ctor, ...args) {
474
+ this.container.add(ctor, ...args);
475
+ return this;
476
+ }
477
+ /**
478
+ * Добавить конструктор и создать экземпляр.
479
+ *
480
+ * @param {*} ctor
481
+ * @param {*} args
482
+ * @returns {this}
483
+ */
484
+ useService(ctor, ...args) {
485
+ this.container.use(ctor, ...args);
486
+ return this;
487
+ }
488
+ /**
489
+ * Добавить конструктор и связанный экземпляр.
490
+ *
491
+ * @param {*} ctor
492
+ * @param {*} service
493
+ * @returns {this}
494
+ */
495
+ setService(ctor, service) {
496
+ this.container.set(ctor, service);
497
+ return this;
498
+ }
499
+ };
500
+ __name(_Service, "Service");
501
+ /**
502
+ * Kinds.
503
+ *
504
+ * @type {string[]}
505
+ */
506
+ __publicField(_Service, "kinds", [SERVICE_CLASS_NAME]);
507
+ var Service = _Service;
508
+
509
+ // node_modules/@e22m4u/js-debug/src/utils/to-camel-case.js
510
+ function toCamelCase2(input) {
511
+ return input.replace(/(^\w|[A-Z]|\b\w)/g, (c) => c.toUpperCase()).replace(/\W+/g, "").replace(/(^\w)/g, (c) => c.toLowerCase());
512
+ }
513
+ __name(toCamelCase2, "toCamelCase");
514
+
515
+ // node_modules/@e22m4u/js-debug/src/utils/is-non-array-object.js
516
+ function isNonArrayObject(input) {
517
+ return Boolean(input && typeof input === "object" && !Array.isArray(input));
518
+ }
519
+ __name(isNonArrayObject, "isNonArrayObject");
520
+
521
+ // node_modules/@e22m4u/js-debug/src/utils/generate-random-hex.js
522
+ function generateRandomHex(length = 4) {
523
+ if (length <= 0) {
524
+ return "";
525
+ }
526
+ const firstCharCandidates = "abcdef";
527
+ const restCharCandidates = "0123456789abcdef";
528
+ let result = "";
529
+ const firstCharIndex = Math.floor(Math.random() * firstCharCandidates.length);
530
+ result += firstCharCandidates[firstCharIndex];
531
+ for (let i = 1; i < length; i++) {
532
+ const randomIndex = Math.floor(Math.random() * restCharCandidates.length);
533
+ result += restCharCandidates[randomIndex];
534
+ }
535
+ return result;
536
+ }
537
+ __name(generateRandomHex, "generateRandomHex");
538
+
539
+ // node_modules/@e22m4u/js-debug/src/debuggable.js
540
+ var _Debuggable = class _Debuggable {
541
+ /**
542
+ * Debug.
543
+ *
544
+ * @type {Function}
545
+ */
546
+ debug;
547
+ /**
548
+ * Ctor Debug.
549
+ *
550
+ * @type {Function}
551
+ */
552
+ ctorDebug;
553
+ /**
554
+ * Возвращает функцию-отладчик с сегментом пространства имен
555
+ * указанного в параметре метода.
556
+ *
557
+ * @param {Function} method
558
+ * @returns {Function}
559
+ */
560
+ getDebuggerFor(method) {
561
+ return this.debug.withHash().withNs(method.name);
562
+ }
563
+ /**
564
+ * Constructor.
565
+ *
566
+ * @param {object|undefined} container
567
+ * @param {DebuggableOptions|undefined} options
568
+ */
569
+ constructor(options = void 0) {
570
+ const className = toCamelCase2(this.constructor.name);
571
+ options = typeof options === "object" && options || {};
572
+ const namespace = options.namespace && String(options.namespace) || void 0;
573
+ if (namespace) {
574
+ this.debug = createDebugger(namespace, className);
575
+ } else {
576
+ this.debug = createDebugger(className);
577
+ }
578
+ const noEnvNs = Boolean(options.noEnvNs);
579
+ if (noEnvNs) this.debug = this.debug.withoutEnvNs();
580
+ this.ctorDebug = this.debug.withNs("constructor").withHash();
581
+ this.ctorDebug(_Debuggable.INSTANTIATION_MESSAGE);
582
+ }
583
+ };
584
+ __name(_Debuggable, "Debuggable");
585
+ /**
586
+ * Instantiation message;
587
+ *
588
+ * @type {string}
589
+ */
590
+ __publicField(_Debuggable, "INSTANTIATION_MESSAGE", "Instantiated.");
591
+ var Debuggable = _Debuggable;
592
+
593
+ // node_modules/@e22m4u/js-debug/src/create-debugger.js
594
+ var import_js_format2 = require("@e22m4u/js-format");
595
+ var import_js_format3 = require("@e22m4u/js-format");
596
+
597
+ // node_modules/@e22m4u/js-debug/src/create-colorized-dump.js
598
+ var import_util = require("util");
599
+ var INSPECT_OPTIONS = {
600
+ showHidden: false,
601
+ depth: null,
602
+ colors: true,
603
+ compact: false
604
+ };
605
+ function createColorizedDump(value) {
606
+ return (0, import_util.inspect)(value, INSPECT_OPTIONS);
607
+ }
608
+ __name(createColorizedDump, "createColorizedDump");
609
+
610
+ // node_modules/@e22m4u/js-debug/src/create-debugger.js
611
+ var AVAILABLE_COLORS = [
612
+ 20,
613
+ 21,
614
+ 26,
615
+ 27,
616
+ 32,
617
+ 33,
618
+ 38,
619
+ 39,
620
+ 40,
621
+ 41,
622
+ 42,
623
+ 43,
624
+ 44,
625
+ 45,
626
+ 56,
627
+ 57,
628
+ 62,
629
+ 63,
630
+ 68,
631
+ 69,
632
+ 74,
633
+ 75,
634
+ 76,
635
+ 77,
636
+ 78,
637
+ 79,
638
+ 80,
639
+ 81,
640
+ 92,
641
+ 93,
642
+ 98,
643
+ 99,
644
+ 112,
645
+ 113,
646
+ 128,
647
+ 129,
648
+ 134,
649
+ 135,
650
+ 148,
651
+ 149,
652
+ 160,
653
+ 161,
654
+ 162,
655
+ 163,
656
+ 164,
657
+ 165,
658
+ 166,
659
+ 167,
660
+ 168,
661
+ 169,
662
+ 170,
663
+ 171,
664
+ 172,
665
+ 173,
666
+ 178,
667
+ 179,
668
+ 184,
669
+ 185,
670
+ 196,
671
+ 197,
672
+ 198,
673
+ 199,
674
+ 200,
675
+ 201,
676
+ 202,
677
+ 203,
678
+ 204,
679
+ 205,
680
+ 206,
681
+ 207,
682
+ 208,
683
+ 209,
684
+ 214,
685
+ 215,
686
+ 220,
687
+ 221
688
+ ];
689
+ var DEFAULT_OFFSET_STEP_SPACES = 2;
690
+ function pickColorCode(input) {
691
+ if (typeof input !== "string")
692
+ throw new import_js_format2.Errorf(
693
+ 'The parameter "input" of the function pickColorCode must be a String, but %v given.',
694
+ input
695
+ );
696
+ let hash = 0;
697
+ for (let i = 0; i < input.length; i++) {
698
+ hash = (hash << 5) - hash + input.charCodeAt(i);
699
+ hash |= 0;
700
+ }
701
+ return AVAILABLE_COLORS[Math.abs(hash) % AVAILABLE_COLORS.length];
702
+ }
703
+ __name(pickColorCode, "pickColorCode");
704
+ function wrapStringByColorCode(input, color) {
705
+ if (typeof input !== "string")
706
+ throw new import_js_format2.Errorf(
707
+ 'The parameter "input" of the function wrapStringByColorCode must be a String, but %v given.',
708
+ input
709
+ );
710
+ if (typeof color !== "number")
711
+ throw new import_js_format2.Errorf(
712
+ 'The parameter "color" of the function wrapStringByColorCode must be a Number, but %v given.',
713
+ color
714
+ );
715
+ const colorCode = "\x1B[3" + (Number(color) < 8 ? color : "8;5;" + color);
716
+ return `${colorCode};1m${input}\x1B[0m`;
717
+ }
718
+ __name(wrapStringByColorCode, "wrapStringByColorCode");
719
+ function matchPattern(pattern, input) {
720
+ if (typeof pattern !== "string")
721
+ throw new import_js_format2.Errorf(
722
+ 'The parameter "pattern" of the function matchPattern must be a String, but %v given.',
723
+ pattern
724
+ );
725
+ if (typeof input !== "string")
726
+ throw new import_js_format2.Errorf(
727
+ 'The parameter "input" of the function matchPattern must be a String, but %v given.',
728
+ input
729
+ );
730
+ const regexpStr = pattern.replace(/\*/g, ".*?");
731
+ const regexp = new RegExp("^" + regexpStr + "$");
732
+ return regexp.test(input);
733
+ }
734
+ __name(matchPattern, "matchPattern");
735
+ function createDebugger(namespaceOrOptions = void 0, ...namespaceSegments) {
736
+ if (namespaceOrOptions && typeof namespaceOrOptions !== "string" && !isNonArrayObject(namespaceOrOptions)) {
737
+ throw new import_js_format2.Errorf(
738
+ 'The parameter "namespace" of the function createDebugger must be a String or an Object, but %v given.',
739
+ namespaceOrOptions
740
+ );
741
+ }
742
+ const withCustomState = isNonArrayObject(namespaceOrOptions);
743
+ const state = withCustomState ? namespaceOrOptions : {};
744
+ state.envNsSegments = Array.isArray(state.envNsSegments) ? state.envNsSegments : [];
745
+ state.nsSegments = Array.isArray(state.nsSegments) ? state.nsSegments : [];
746
+ state.pattern = typeof state.pattern === "string" ? state.pattern : "";
747
+ state.hash = typeof state.hash === "string" ? state.hash : "";
748
+ state.offsetSize = typeof state.offsetSize === "number" ? state.offsetSize : 0;
749
+ state.offsetStep = typeof state.offsetStep !== "string" ? " ".repeat(DEFAULT_OFFSET_STEP_SPACES) : state.offsetStep;
750
+ state.delimiter = state.delimiter && typeof state.delimiter === "string" ? state.delimiter : ":";
751
+ if (!withCustomState) {
752
+ if (typeof process !== "undefined" && process.env && process.env["DEBUGGER_NAMESPACE"]) {
753
+ state.envNsSegments.push(process.env.DEBUGGER_NAMESPACE);
754
+ }
755
+ if (typeof namespaceOrOptions === "string")
756
+ state.nsSegments.push(namespaceOrOptions);
757
+ }
758
+ namespaceSegments.forEach((segment) => {
759
+ if (!segment || typeof segment !== "string")
760
+ throw new import_js_format2.Errorf(
761
+ "Namespace segment must be a non-empty String, but %v given.",
762
+ segment
763
+ );
764
+ state.nsSegments.push(segment);
765
+ });
766
+ if (typeof process !== "undefined" && process.env && process.env["DEBUG"]) {
767
+ state.pattern = process.env["DEBUG"];
768
+ } else if (typeof localStorage !== "undefined" && typeof localStorage.getItem("debug") === "string") {
769
+ state.pattern = localStorage.getItem("debug");
770
+ }
771
+ const isDebuggerEnabled = /* @__PURE__ */ __name(() => {
772
+ const nsStr = [...state.envNsSegments, ...state.nsSegments].join(
773
+ state.delimiter
774
+ );
775
+ const patterns = state.pattern.split(/[\s,]+/).filter((p) => p.length > 0);
776
+ if (patterns.length === 0 && state.pattern !== "*") return false;
777
+ for (const singlePattern of patterns) {
778
+ if (matchPattern(singlePattern, nsStr)) return true;
779
+ }
780
+ return false;
781
+ }, "isDebuggerEnabled");
782
+ const getPrefix = /* @__PURE__ */ __name(() => {
783
+ let tokens = [];
784
+ [...state.envNsSegments, ...state.nsSegments, state.hash].filter(Boolean).forEach((token) => {
785
+ const extractedTokens = token.split(state.delimiter).filter(Boolean);
786
+ tokens = [...tokens, ...extractedTokens];
787
+ });
788
+ let res = tokens.reduce((acc, token, index) => {
789
+ const isLast = tokens.length - 1 === index;
790
+ const tokenColor = pickColorCode(token);
791
+ acc += wrapStringByColorCode(token, tokenColor);
792
+ if (!isLast) acc += state.delimiter;
793
+ return acc;
794
+ }, "");
795
+ if (state.offsetSize > 0) res += state.offsetStep.repeat(state.offsetSize);
796
+ return res;
797
+ }, "getPrefix");
798
+ function debugFn(messageOrData, ...args) {
799
+ if (!isDebuggerEnabled()) return;
800
+ const prefix = getPrefix();
801
+ const multiString = (0, import_js_format3.format)(messageOrData, ...args);
802
+ const rows = multiString.split("\n");
803
+ rows.forEach((message) => {
804
+ prefix ? console.log(`${prefix} ${message}`) : console.log(message);
805
+ });
806
+ }
807
+ __name(debugFn, "debugFn");
808
+ debugFn.withNs = function(namespace, ...args) {
809
+ const stateCopy = JSON.parse(JSON.stringify(state));
810
+ [namespace, ...args].forEach((ns) => {
811
+ if (!ns || typeof ns !== "string")
812
+ throw new import_js_format2.Errorf(
813
+ "Debugger namespace must be a non-empty String, but %v given.",
814
+ ns
815
+ );
816
+ stateCopy.nsSegments.push(ns);
817
+ });
818
+ return createDebugger(stateCopy);
819
+ };
820
+ debugFn.withHash = function(hashLength = 4) {
821
+ const stateCopy = JSON.parse(JSON.stringify(state));
822
+ if (!hashLength || typeof hashLength !== "number" || hashLength < 1) {
823
+ throw new import_js_format2.Errorf(
824
+ "Debugger hash must be a positive Number, but %v given.",
825
+ hashLength
826
+ );
827
+ }
828
+ stateCopy.hash = generateRandomHex(hashLength);
829
+ return createDebugger(stateCopy);
830
+ };
831
+ debugFn.withOffset = function(offsetSize) {
832
+ const stateCopy = JSON.parse(JSON.stringify(state));
833
+ if (!offsetSize || typeof offsetSize !== "number" || offsetSize < 1) {
834
+ throw new import_js_format2.Errorf(
835
+ "Debugger offset must be a positive Number, but %v given.",
836
+ offsetSize
837
+ );
838
+ }
839
+ stateCopy.offsetSize = offsetSize;
840
+ return createDebugger(stateCopy);
841
+ };
842
+ debugFn.withoutEnvNs = function() {
843
+ const stateCopy = JSON.parse(JSON.stringify(state));
844
+ stateCopy.envNsSegments = [];
845
+ return createDebugger(stateCopy);
846
+ };
847
+ debugFn.inspect = function(valueOrDesc, ...args) {
848
+ if (!isDebuggerEnabled()) return;
849
+ const prefix = getPrefix();
850
+ let multiString = "";
851
+ if (typeof valueOrDesc === "string" && args.length) {
852
+ multiString += `${valueOrDesc}
853
+ `;
854
+ const multilineDump = args.map((v) => createColorizedDump(v)).join("\n");
855
+ const dumpRows = multilineDump.split("\n");
856
+ multiString += dumpRows.map((v) => `${state.offsetStep}${v}`).join("\n");
857
+ } else {
858
+ multiString += [valueOrDesc, ...args].map((v) => createColorizedDump(v)).join("\n");
859
+ }
860
+ const rows = multiString.split("\n");
861
+ rows.forEach((message) => {
862
+ prefix ? console.log(`${prefix} ${message}`) : console.log(message);
863
+ });
864
+ };
865
+ debugFn.state = state;
866
+ return debugFn;
867
+ }
868
+ __name(createDebugger, "createDebugger");
869
+
870
+ // node_modules/@e22m4u/js-service/src/debuggable-service.js
871
+ var _DebuggableService = class _DebuggableService extends Debuggable {
872
+ /**
873
+ * Service.
874
+ *
875
+ * @type {Service}
876
+ */
877
+ _service;
878
+ /**
879
+ * Container.
880
+ *
881
+ * @type {ServiceContainer}
882
+ */
883
+ get container() {
884
+ return this._service.container;
885
+ }
886
+ /**
887
+ * Получить существующий или новый экземпляр.
888
+ *
889
+ * @type {Service['getService']}
890
+ */
891
+ get getService() {
892
+ return this._service.getService;
893
+ }
894
+ /**
895
+ * Получить существующий или новый экземпляр,
896
+ * только если конструктор зарегистрирован.
897
+ *
898
+ * @type {Service['getRegisteredService']}
899
+ */
900
+ get getRegisteredService() {
901
+ return this._service.getRegisteredService;
902
+ }
903
+ /**
904
+ * Проверка существования конструктора в контейнере.
905
+ *
906
+ * @type {Service['hasService']}
907
+ */
908
+ get hasService() {
909
+ return this._service.hasService;
910
+ }
911
+ /**
912
+ * Добавить конструктор в контейнер.
913
+ *
914
+ * @type {Service['addService']}
915
+ */
916
+ get addService() {
917
+ return this._service.addService;
918
+ }
919
+ /**
920
+ * Добавить конструктор и создать экземпляр.
921
+ *
922
+ * @type {Service['useService']}
923
+ */
924
+ get useService() {
925
+ return this._service.useService;
926
+ }
927
+ /**
928
+ * Добавить конструктор и связанный экземпляр.
929
+ *
930
+ * @type {Service['setService']}
931
+ */
932
+ get setService() {
933
+ return this._service.setService;
934
+ }
935
+ /**
936
+ * Constructor.
937
+ *
938
+ * @param {ServiceContainer|undefined} container
939
+ * @param {import('@e22m4u/js-debug').DebuggableOptions|undefined} options
940
+ */
941
+ constructor(container = void 0, options = void 0) {
942
+ super(options);
943
+ this._service = new Service(container);
944
+ }
945
+ };
946
+ __name(_DebuggableService, "DebuggableService");
947
+ /**
948
+ * Kinds.
949
+ *
950
+ * @type {string[]}
951
+ */
952
+ __publicField(_DebuggableService, "kinds", Service.kinds);
953
+ var DebuggableService = _DebuggableService;
159
954
 
160
955
  // src/mongodb-adapter.js
161
956
  var import_js_repository6 = require("@e22m4u/js-repository");
@@ -163,35 +958,84 @@ var import_js_repository7 = require("@e22m4u/js-repository");
163
958
  var import_js_repository8 = require("@e22m4u/js-repository");
164
959
  var import_js_repository9 = require("@e22m4u/js-repository");
165
960
  var import_js_repository10 = require("@e22m4u/js-repository");
961
+ var import_js_repository11 = require("@e22m4u/js-repository");
166
962
  var MONGODB_OPTION_NAMES = [
167
- "appname",
963
+ "ALPNProtocols",
964
+ "allowPartialTrustChain",
965
+ "appName",
966
+ "auth",
168
967
  "authMechanism",
169
968
  "authMechanismProperties",
170
969
  "authSource",
970
+ "autoEncryption",
971
+ "autoSelectFamily",
972
+ "autoSelectFamilyAttemptTimeout",
973
+ "bsonRegExp",
974
+ "ca",
975
+ "cert",
976
+ "checkKeys",
977
+ "checkServerIdentity",
978
+ "ciphers",
171
979
  "compressors",
172
980
  "connectTimeoutMS",
981
+ "crl",
173
982
  "directConnection",
983
+ "driverInfo",
984
+ "ecdhCurve",
985
+ "enableUtf8Validation",
986
+ "family",
987
+ "fieldsAsRaw",
988
+ "forceServerObjectId",
174
989
  "heartbeatFrequencyMS",
990
+ "hints",
991
+ "ignoreUndefined",
175
992
  "journal",
993
+ "keepAliveInitialDelay",
994
+ "key",
176
995
  "loadBalanced",
996
+ "localAddress",
997
+ "localPort",
177
998
  "localThresholdMS",
999
+ "lookup",
1000
+ "maxConnecting",
178
1001
  "maxIdleTimeMS",
179
1002
  "maxPoolSize",
180
- "maxConnecting",
181
1003
  "maxStalenessSeconds",
1004
+ "minDHSize",
1005
+ "minHeartbeatFrequencyMS",
182
1006
  "minPoolSize",
1007
+ "mongodbLogComponentSeverities",
1008
+ "mongodbLogMaxDocumentLength",
1009
+ "mongodbLogPath",
1010
+ "monitorCommands",
1011
+ "noDelay",
1012
+ "passphrase",
1013
+ "pfx",
1014
+ "pkFactory",
1015
+ "promoteBuffers",
1016
+ "promoteLongs",
1017
+ "promoteValues",
183
1018
  "proxyHost",
1019
+ "proxyPassword",
184
1020
  "proxyPort",
185
1021
  "proxyUsername",
186
- "proxyPassword",
1022
+ "raw",
1023
+ "readConcern",
187
1024
  "readConcernLevel",
188
1025
  "readPreference",
189
1026
  "readPreferenceTags",
1027
+ "rejectUnauthorized",
190
1028
  "replicaSet",
191
1029
  "retryReads",
192
1030
  "retryWrites",
1031
+ "secureContext",
1032
+ "secureProtocol",
1033
+ "serializeFunctions",
1034
+ "serverApi",
1035
+ "serverMonitoringMode",
193
1036
  "serverSelectionTimeoutMS",
194
- "serverSelectionTryOnce",
1037
+ "servername",
1038
+ "session",
195
1039
  "socketTimeoutMS",
196
1040
  "srvMaxHosts",
197
1041
  "srvServiceName",
@@ -201,12 +1045,15 @@ var MONGODB_OPTION_NAMES = [
201
1045
  "tlsAllowInvalidCertificates",
202
1046
  "tlsAllowInvalidHostnames",
203
1047
  "tlsCAFile",
1048
+ "tlsCRLFile",
204
1049
  "tlsCertificateKeyFile",
205
1050
  "tlsCertificateKeyFilePassword",
206
1051
  "tlsInsecure",
1052
+ "useBigInt64",
207
1053
  "w",
208
1054
  "waitQueueTimeoutMS",
209
- "wTimeoutMS",
1055
+ "writeConcern",
1056
+ "wtimeoutMS",
210
1057
  "zlibCompressionLevel"
211
1058
  ];
212
1059
  var DEFAULT_SETTINGS = {
@@ -260,7 +1107,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
260
1107
  * @private
261
1108
  */
262
1109
  _getIdPropName(modelName) {
263
- return this.getService(import_js_repository8.ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
1110
+ return this.getService(import_js_repository9.ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
264
1111
  modelName
265
1112
  );
266
1113
  }
@@ -271,7 +1118,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
271
1118
  * @private
272
1119
  */
273
1120
  _getIdColName(modelName) {
274
- return this.getService(import_js_repository8.ModelDefinitionUtils).getPrimaryKeyAsColumnName(
1121
+ return this.getService(import_js_repository9.ModelDefinitionUtils).getPrimaryKeyAsColumnName(
275
1122
  modelName
276
1123
  );
277
1124
  }
@@ -310,11 +1157,11 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
310
1157
  */
311
1158
  _toDatabase(modelName, modelData) {
312
1159
  const tableData = this.getService(
313
- import_js_repository8.ModelDefinitionUtils
1160
+ import_js_repository9.ModelDefinitionUtils
314
1161
  ).convertPropertyNamesToColumnNames(modelName, modelData);
315
1162
  const idColName = this._getIdColName(modelName);
316
1163
  if (idColName !== "id" && idColName !== "_id")
317
- throw new import_js_repository9.InvalidArgumentError(
1164
+ throw new import_js_repository10.InvalidArgumentError(
318
1165
  'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
319
1166
  idColName
320
1167
  );
@@ -342,7 +1189,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
342
1189
  if ("_id" in tableData) {
343
1190
  const idColName = this._getIdColName(modelName);
344
1191
  if (idColName !== "id" && idColName !== "_id")
345
- throw new import_js_repository9.InvalidArgumentError(
1192
+ throw new import_js_repository10.InvalidArgumentError(
346
1193
  'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
347
1194
  idColName
348
1195
  );
@@ -352,7 +1199,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
352
1199
  }
353
1200
  }
354
1201
  const modelData = this.getService(
355
- import_js_repository8.ModelDefinitionUtils
1202
+ import_js_repository9.ModelDefinitionUtils
356
1203
  ).convertColumnNamesToPropertyNames(modelName, tableData);
357
1204
  return transformValuesDeep(modelData, (value) => {
358
1205
  if (value instanceof import_mongodb2.ObjectId) return String(value);
@@ -360,6 +1207,16 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
360
1207
  return value;
361
1208
  });
362
1209
  }
1210
+ /**
1211
+ * Get collection name by model name.
1212
+ *
1213
+ * @param {string} modelName
1214
+ */
1215
+ _getCollectionNameByModelName(modelName) {
1216
+ const modelDef = this.getService(import_js_repository8.DefinitionRegistry).getModel(modelName);
1217
+ if (modelDef.tableName != null) return modelDef.tableName;
1218
+ return modelNameToCollectionName(modelName);
1219
+ }
363
1220
  /**
364
1221
  * Get collection.
365
1222
  *
@@ -370,8 +1227,8 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
370
1227
  _getCollection(modelName) {
371
1228
  let collection = this._collections.get(modelName);
372
1229
  if (collection) return collection;
373
- const tableName = this.getService(import_js_repository8.ModelDefinitionUtils).getTableNameByModelName(modelName);
374
- collection = this.client.db(this.settings.database).collection(tableName);
1230
+ const collectionName = this._getCollectionNameByModelName(modelName);
1231
+ collection = this.client.db(this.settings.database).collection(collectionName);
375
1232
  this._collections.set(modelName, collection);
376
1233
  return collection;
377
1234
  }
@@ -383,7 +1240,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
383
1240
  * @private
384
1241
  */
385
1242
  _getIdType(modelName) {
386
- const utils = this.getService(import_js_repository8.ModelDefinitionUtils);
1243
+ const utils = this.getService(import_js_repository9.ModelDefinitionUtils);
387
1244
  const pkPropName = utils.getPrimaryKeyAsPropertyName(modelName);
388
1245
  return utils.getDataTypeByPropertyName(modelName, pkPropName);
389
1246
  }
@@ -397,16 +1254,16 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
397
1254
  */
398
1255
  _getColName(modelName, propName) {
399
1256
  if (!propName || typeof propName !== "string")
400
- throw new import_js_repository9.InvalidArgumentError(
1257
+ throw new import_js_repository10.InvalidArgumentError(
401
1258
  "Property name must be a non-empty String, but %v given.",
402
1259
  propName
403
1260
  );
404
- const utils = this.getService(import_js_repository8.ModelDefinitionUtils);
1261
+ const utils = this.getService(import_js_repository9.ModelDefinitionUtils);
405
1262
  let colName = propName;
406
1263
  try {
407
1264
  colName = utils.getColumnNameByPropertyName(modelName, propName);
408
1265
  } catch (error) {
409
- if (!(error instanceof import_js_repository9.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
1266
+ if (!(error instanceof import_js_repository10.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
410
1267
  throw error;
411
1268
  }
412
1269
  }
@@ -422,18 +1279,18 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
422
1279
  */
423
1280
  _convertPropNamesChainToColNamesChain(modelName, propsChain) {
424
1281
  if (!modelName || typeof modelName !== "string")
425
- throw new import_js_repository9.InvalidArgumentError(
1282
+ throw new import_js_repository10.InvalidArgumentError(
426
1283
  "Model name must be a non-empty String, but %v given.",
427
1284
  modelName
428
1285
  );
429
1286
  if (!propsChain || typeof propsChain !== "string")
430
- throw new import_js_repository9.InvalidArgumentError(
1287
+ throw new import_js_repository10.InvalidArgumentError(
431
1288
  "Properties chain must be a non-empty String, but %v given.",
432
1289
  propsChain
433
1290
  );
434
1291
  propsChain = propsChain.replace(/\.{2,}/g, ".");
435
1292
  const propNames = propsChain.split(".");
436
- const utils = this.getService(import_js_repository8.ModelDefinitionUtils);
1293
+ const utils = this.getService(import_js_repository9.ModelDefinitionUtils);
437
1294
  let currModelName = modelName;
438
1295
  return propNames.map((currPropName) => {
439
1296
  if (!currModelName) return currPropName;
@@ -460,7 +1317,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
460
1317
  if (fields.indexOf("_id") === -1) fields.push("_id");
461
1318
  return fields.reduce((acc, field) => {
462
1319
  if (!field || typeof field !== "string")
463
- throw new import_js_repository9.InvalidArgumentError(
1320
+ throw new import_js_repository10.InvalidArgumentError(
464
1321
  'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
465
1322
  field
466
1323
  );
@@ -487,7 +1344,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
487
1344
  const idPropName = this._getIdPropName(modelName);
488
1345
  return clause.reduce((acc, order) => {
489
1346
  if (!order || typeof order !== "string")
490
- throw new import_js_repository9.InvalidArgumentError(
1347
+ throw new import_js_repository10.InvalidArgumentError(
491
1348
  'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
492
1349
  order
493
1350
  );
@@ -499,7 +1356,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
499
1356
  try {
500
1357
  field = this._convertPropNamesChainToColNamesChain(modelName, field);
501
1358
  } catch (error) {
502
- if (!(error instanceof import_js_repository9.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
1359
+ if (!(error instanceof import_js_repository10.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
503
1360
  throw error;
504
1361
  }
505
1362
  }
@@ -519,7 +1376,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
519
1376
  _buildQuery(modelName, clause) {
520
1377
  if (clause == null) return;
521
1378
  if (typeof clause !== "object" || Array.isArray(clause))
522
- throw new import_js_repository9.InvalidArgumentError(
1379
+ throw new import_js_repository10.InvalidArgumentError(
523
1380
  'The provided option "where" should be an Object, but %v given.',
524
1381
  clause
525
1382
  );
@@ -528,7 +1385,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
528
1385
  Object.keys(clause).forEach((key) => {
529
1386
  var _a, _b;
530
1387
  if (String(key).indexOf("$") !== -1)
531
- throw new import_js_repository9.InvalidArgumentError(
1388
+ throw new import_js_repository10.InvalidArgumentError(
532
1389
  'The symbol "$" is not supported, but %v given.',
533
1390
  key
534
1391
  );
@@ -536,7 +1393,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
536
1393
  if (key === "and" || key === "or" || key === "nor") {
537
1394
  if (cond == null) return;
538
1395
  if (!Array.isArray(cond))
539
- throw new import_js_repository10.InvalidOperatorValueError(key, "an Array", cond);
1396
+ throw new import_js_repository11.InvalidOperatorValueError(key, "an Array", cond);
540
1397
  if (cond.length === 0) return;
541
1398
  cond = cond.map((c) => this._buildQuery(modelName, c));
542
1399
  cond = cond.filter((c) => c != null);
@@ -589,7 +1446,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
589
1446
  }
590
1447
  if ("inq" in cond) {
591
1448
  if (!cond.inq || !Array.isArray(cond.inq))
592
- throw new import_js_repository10.InvalidOperatorValueError(
1449
+ throw new import_js_repository11.InvalidOperatorValueError(
593
1450
  "inq",
594
1451
  "an Array of possible values",
595
1452
  cond.inq
@@ -603,7 +1460,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
603
1460
  }
604
1461
  if ("nin" in cond) {
605
1462
  if (!cond.nin || !Array.isArray(cond.nin))
606
- throw new import_js_repository10.InvalidOperatorValueError(
1463
+ throw new import_js_repository11.InvalidOperatorValueError(
607
1464
  "nin",
608
1465
  "an Array of possible values",
609
1466
  cond
@@ -617,7 +1474,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
617
1474
  }
618
1475
  if ("between" in cond) {
619
1476
  if (!Array.isArray(cond.between) || cond.between.length !== 2)
620
- throw new import_js_repository10.InvalidOperatorValueError(
1477
+ throw new import_js_repository11.InvalidOperatorValueError(
621
1478
  "between",
622
1479
  "an Array of 2 elements",
623
1480
  cond.between
@@ -628,7 +1485,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
628
1485
  }
629
1486
  if ("exists" in cond) {
630
1487
  if (typeof cond.exists !== "boolean")
631
- throw new import_js_repository10.InvalidOperatorValueError(
1488
+ throw new import_js_repository11.InvalidOperatorValueError(
632
1489
  "exists",
633
1490
  "a Boolean",
634
1491
  cond.exists
@@ -637,7 +1494,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
637
1494
  }
638
1495
  if ("like" in cond) {
639
1496
  if (typeof cond.like !== "string" && !(cond.like instanceof RegExp))
640
- throw new import_js_repository10.InvalidOperatorValueError(
1497
+ throw new import_js_repository11.InvalidOperatorValueError(
641
1498
  "like",
642
1499
  "a String or RegExp",
643
1500
  cond.like
@@ -646,7 +1503,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
646
1503
  }
647
1504
  if ("nlike" in cond) {
648
1505
  if (typeof cond.nlike !== "string" && !(cond.nlike instanceof RegExp))
649
- throw new import_js_repository10.InvalidOperatorValueError(
1506
+ throw new import_js_repository11.InvalidOperatorValueError(
650
1507
  "nlike",
651
1508
  "a String or RegExp",
652
1509
  cond.nlike
@@ -655,7 +1512,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
655
1512
  }
656
1513
  if ("ilike" in cond) {
657
1514
  if (typeof cond.ilike !== "string" && !(cond.ilike instanceof RegExp))
658
- throw new import_js_repository10.InvalidOperatorValueError(
1515
+ throw new import_js_repository11.InvalidOperatorValueError(
659
1516
  "ilike",
660
1517
  "a String or RegExp",
661
1518
  cond.ilike
@@ -664,7 +1521,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
664
1521
  }
665
1522
  if ("nilike" in cond) {
666
1523
  if (typeof cond.nilike !== "string" && !(cond.nilike instanceof RegExp)) {
667
- throw new import_js_repository10.InvalidOperatorValueError(
1524
+ throw new import_js_repository11.InvalidOperatorValueError(
668
1525
  "nilike",
669
1526
  "a String or RegExp",
670
1527
  cond.nilike
@@ -674,7 +1531,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
674
1531
  }
675
1532
  if ("regexp" in cond) {
676
1533
  if (typeof cond.regexp !== "string" && !(cond.regexp instanceof RegExp)) {
677
- throw new import_js_repository10.InvalidOperatorValueError(
1534
+ throw new import_js_repository11.InvalidOperatorValueError(
678
1535
  "regexp",
679
1536
  "a String or RegExp",
680
1537
  cond.regexp
@@ -682,7 +1539,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
682
1539
  }
683
1540
  const flags = cond.flags || void 0;
684
1541
  if (flags && typeof flags !== "string")
685
- throw new import_js_repository9.InvalidArgumentError(
1542
+ throw new import_js_repository10.InvalidArgumentError(
686
1543
  "RegExp flags must be a String, but %v given.",
687
1544
  cond.flags
688
1545
  );
@@ -714,7 +1571,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
714
1571
  if (idValue == null || idValue === "" || idValue === 0) {
715
1572
  const pkType = this._getIdType(modelName);
716
1573
  if (pkType !== import_js_repository4.DataType.STRING && pkType !== import_js_repository4.DataType.ANY)
717
- throw new import_js_repository9.InvalidArgumentError(
1574
+ throw new import_js_repository10.InvalidArgumentError(
718
1575
  "MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
719
1576
  (0, import_js_repository5.capitalize)(pkType),
720
1577
  idPropName
@@ -748,7 +1605,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
748
1605
  const table = this._getCollection(modelName);
749
1606
  const { matchedCount } = await table.replaceOne({ _id: id }, tableData);
750
1607
  if (matchedCount < 1)
751
- throw new import_js_repository9.InvalidArgumentError("Identifier %v is not found.", String(id));
1608
+ throw new import_js_repository10.InvalidArgumentError("Identifier %v is not found.", String(id));
752
1609
  const projection = this._buildProjection(
753
1610
  modelName,
754
1611
  filter && filter.fields
@@ -771,7 +1628,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
771
1628
  if (idValue == null || idValue === "" || idValue === 0) {
772
1629
  const pkType = this._getIdType(modelName);
773
1630
  if (pkType !== import_js_repository4.DataType.STRING && pkType !== import_js_repository4.DataType.ANY)
774
- throw new import_js_repository9.InvalidArgumentError(
1631
+ throw new import_js_repository10.InvalidArgumentError(
775
1632
  "MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
776
1633
  (0, import_js_repository5.capitalize)(pkType),
777
1634
  idPropName
@@ -831,7 +1688,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
831
1688
  const table = this._getCollection(modelName);
832
1689
  const { matchedCount } = await table.updateOne({ _id: id }, { $set: tableData });
833
1690
  if (matchedCount < 1)
834
- throw new import_js_repository9.InvalidArgumentError("Identifier %v is not found.", String(id));
1691
+ throw new import_js_repository10.InvalidArgumentError("Identifier %v is not found.", String(id));
835
1692
  const projection = this._buildProjection(
836
1693
  modelName,
837
1694
  filter && filter.fields
@@ -875,7 +1732,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
875
1732
  );
876
1733
  const patchedData = await table.findOne({ _id: id }, { projection });
877
1734
  if (!patchedData)
878
- throw new import_js_repository9.InvalidArgumentError("Identifier %v is not found.", String(id));
1735
+ throw new import_js_repository10.InvalidArgumentError("Identifier %v is not found.", String(id));
879
1736
  return this._fromDatabase(modelName, patchedData);
880
1737
  }
881
1738
  /**
@@ -927,7 +1784,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
927
1784
  async count(modelName, where = void 0) {
928
1785
  const query = this._buildQuery(modelName, where);
929
1786
  const table = this._getCollection(modelName);
930
- return await table.count(query);
1787
+ return await table.countDocuments(query);
931
1788
  }
932
1789
  };
933
1790
  __name(_MongodbAdapter, "MongodbAdapter");