@e22m4u/js-repository-mongodb-adapter 0.5.6 → 0.6.2
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 +4 -4
- package/dist/cjs/index.cjs +843 -37
- package/package.json +2 -2
- package/src/mongodb-adapter.js +18 -4
- package/src/mongodb-adapter.spec.js +361 -147
- package/src/utils/index.js +3 -0
- package/src/utils/model-name-to-collection-name.js +26 -0
- package/src/utils/model-name-to-collection-name.spec.js +89 -0
- package/src/utils/pluralize.js +63 -0
- package/src/utils/pluralize.spec.js +110 -0
- package/src/utils/to-camel-case.js +18 -0
- package/src/utils/to-camel-case.spec.js +75 -0
package/dist/cjs/index.cjs
CHANGED
|
@@ -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,6 +958,7 @@ 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
963
|
"ALPNProtocols",
|
|
168
964
|
"allowPartialTrustChain",
|
|
@@ -311,7 +1107,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
311
1107
|
* @private
|
|
312
1108
|
*/
|
|
313
1109
|
_getIdPropName(modelName) {
|
|
314
|
-
return this.getService(
|
|
1110
|
+
return this.getService(import_js_repository9.ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
|
|
315
1111
|
modelName
|
|
316
1112
|
);
|
|
317
1113
|
}
|
|
@@ -322,7 +1118,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
322
1118
|
* @private
|
|
323
1119
|
*/
|
|
324
1120
|
_getIdColName(modelName) {
|
|
325
|
-
return this.getService(
|
|
1121
|
+
return this.getService(import_js_repository9.ModelDefinitionUtils).getPrimaryKeyAsColumnName(
|
|
326
1122
|
modelName
|
|
327
1123
|
);
|
|
328
1124
|
}
|
|
@@ -361,11 +1157,11 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
361
1157
|
*/
|
|
362
1158
|
_toDatabase(modelName, modelData) {
|
|
363
1159
|
const tableData = this.getService(
|
|
364
|
-
|
|
1160
|
+
import_js_repository9.ModelDefinitionUtils
|
|
365
1161
|
).convertPropertyNamesToColumnNames(modelName, modelData);
|
|
366
1162
|
const idColName = this._getIdColName(modelName);
|
|
367
1163
|
if (idColName !== "id" && idColName !== "_id")
|
|
368
|
-
throw new
|
|
1164
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
369
1165
|
'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
|
|
370
1166
|
idColName
|
|
371
1167
|
);
|
|
@@ -393,7 +1189,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
393
1189
|
if ("_id" in tableData) {
|
|
394
1190
|
const idColName = this._getIdColName(modelName);
|
|
395
1191
|
if (idColName !== "id" && idColName !== "_id")
|
|
396
|
-
throw new
|
|
1192
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
397
1193
|
'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
|
|
398
1194
|
idColName
|
|
399
1195
|
);
|
|
@@ -403,7 +1199,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
403
1199
|
}
|
|
404
1200
|
}
|
|
405
1201
|
const modelData = this.getService(
|
|
406
|
-
|
|
1202
|
+
import_js_repository9.ModelDefinitionUtils
|
|
407
1203
|
).convertColumnNamesToPropertyNames(modelName, tableData);
|
|
408
1204
|
return transformValuesDeep(modelData, (value) => {
|
|
409
1205
|
if (value instanceof import_mongodb2.ObjectId) return String(value);
|
|
@@ -411,6 +1207,16 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
411
1207
|
return value;
|
|
412
1208
|
});
|
|
413
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(modelDef.name);
|
|
1219
|
+
}
|
|
414
1220
|
/**
|
|
415
1221
|
* Get collection.
|
|
416
1222
|
*
|
|
@@ -421,8 +1227,8 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
421
1227
|
_getCollection(modelName) {
|
|
422
1228
|
let collection = this._collections.get(modelName);
|
|
423
1229
|
if (collection) return collection;
|
|
424
|
-
const
|
|
425
|
-
collection = this.client.db(this.settings.database).collection(
|
|
1230
|
+
const collectionName = this._getCollectionNameByModelName(modelName);
|
|
1231
|
+
collection = this.client.db(this.settings.database).collection(collectionName);
|
|
426
1232
|
this._collections.set(modelName, collection);
|
|
427
1233
|
return collection;
|
|
428
1234
|
}
|
|
@@ -434,7 +1240,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
434
1240
|
* @private
|
|
435
1241
|
*/
|
|
436
1242
|
_getIdType(modelName) {
|
|
437
|
-
const utils = this.getService(
|
|
1243
|
+
const utils = this.getService(import_js_repository9.ModelDefinitionUtils);
|
|
438
1244
|
const pkPropName = utils.getPrimaryKeyAsPropertyName(modelName);
|
|
439
1245
|
return utils.getDataTypeByPropertyName(modelName, pkPropName);
|
|
440
1246
|
}
|
|
@@ -448,16 +1254,16 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
448
1254
|
*/
|
|
449
1255
|
_getColName(modelName, propName) {
|
|
450
1256
|
if (!propName || typeof propName !== "string")
|
|
451
|
-
throw new
|
|
1257
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
452
1258
|
"Property name must be a non-empty String, but %v given.",
|
|
453
1259
|
propName
|
|
454
1260
|
);
|
|
455
|
-
const utils = this.getService(
|
|
1261
|
+
const utils = this.getService(import_js_repository9.ModelDefinitionUtils);
|
|
456
1262
|
let colName = propName;
|
|
457
1263
|
try {
|
|
458
1264
|
colName = utils.getColumnNameByPropertyName(modelName, propName);
|
|
459
1265
|
} catch (error) {
|
|
460
|
-
if (!(error instanceof
|
|
1266
|
+
if (!(error instanceof import_js_repository10.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
|
|
461
1267
|
throw error;
|
|
462
1268
|
}
|
|
463
1269
|
}
|
|
@@ -473,18 +1279,18 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
473
1279
|
*/
|
|
474
1280
|
_convertPropNamesChainToColNamesChain(modelName, propsChain) {
|
|
475
1281
|
if (!modelName || typeof modelName !== "string")
|
|
476
|
-
throw new
|
|
1282
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
477
1283
|
"Model name must be a non-empty String, but %v given.",
|
|
478
1284
|
modelName
|
|
479
1285
|
);
|
|
480
1286
|
if (!propsChain || typeof propsChain !== "string")
|
|
481
|
-
throw new
|
|
1287
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
482
1288
|
"Properties chain must be a non-empty String, but %v given.",
|
|
483
1289
|
propsChain
|
|
484
1290
|
);
|
|
485
1291
|
propsChain = propsChain.replace(/\.{2,}/g, ".");
|
|
486
1292
|
const propNames = propsChain.split(".");
|
|
487
|
-
const utils = this.getService(
|
|
1293
|
+
const utils = this.getService(import_js_repository9.ModelDefinitionUtils);
|
|
488
1294
|
let currModelName = modelName;
|
|
489
1295
|
return propNames.map((currPropName) => {
|
|
490
1296
|
if (!currModelName) return currPropName;
|
|
@@ -511,7 +1317,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
511
1317
|
if (fields.indexOf("_id") === -1) fields.push("_id");
|
|
512
1318
|
return fields.reduce((acc, field) => {
|
|
513
1319
|
if (!field || typeof field !== "string")
|
|
514
|
-
throw new
|
|
1320
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
515
1321
|
'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
|
|
516
1322
|
field
|
|
517
1323
|
);
|
|
@@ -538,7 +1344,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
538
1344
|
const idPropName = this._getIdPropName(modelName);
|
|
539
1345
|
return clause.reduce((acc, order) => {
|
|
540
1346
|
if (!order || typeof order !== "string")
|
|
541
|
-
throw new
|
|
1347
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
542
1348
|
'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
|
|
543
1349
|
order
|
|
544
1350
|
);
|
|
@@ -550,7 +1356,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
550
1356
|
try {
|
|
551
1357
|
field = this._convertPropNamesChainToColNamesChain(modelName, field);
|
|
552
1358
|
} catch (error) {
|
|
553
|
-
if (!(error instanceof
|
|
1359
|
+
if (!(error instanceof import_js_repository10.InvalidArgumentError) || error.message.indexOf("does not have the property") === -1) {
|
|
554
1360
|
throw error;
|
|
555
1361
|
}
|
|
556
1362
|
}
|
|
@@ -570,7 +1376,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
570
1376
|
_buildQuery(modelName, clause) {
|
|
571
1377
|
if (clause == null) return;
|
|
572
1378
|
if (typeof clause !== "object" || Array.isArray(clause))
|
|
573
|
-
throw new
|
|
1379
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
574
1380
|
'The provided option "where" should be an Object, but %v given.',
|
|
575
1381
|
clause
|
|
576
1382
|
);
|
|
@@ -579,7 +1385,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
579
1385
|
Object.keys(clause).forEach((key) => {
|
|
580
1386
|
var _a, _b;
|
|
581
1387
|
if (String(key).indexOf("$") !== -1)
|
|
582
|
-
throw new
|
|
1388
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
583
1389
|
'The symbol "$" is not supported, but %v given.',
|
|
584
1390
|
key
|
|
585
1391
|
);
|
|
@@ -587,7 +1393,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
587
1393
|
if (key === "and" || key === "or" || key === "nor") {
|
|
588
1394
|
if (cond == null) return;
|
|
589
1395
|
if (!Array.isArray(cond))
|
|
590
|
-
throw new
|
|
1396
|
+
throw new import_js_repository11.InvalidOperatorValueError(key, "an Array", cond);
|
|
591
1397
|
if (cond.length === 0) return;
|
|
592
1398
|
cond = cond.map((c) => this._buildQuery(modelName, c));
|
|
593
1399
|
cond = cond.filter((c) => c != null);
|
|
@@ -640,7 +1446,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
640
1446
|
}
|
|
641
1447
|
if ("inq" in cond) {
|
|
642
1448
|
if (!cond.inq || !Array.isArray(cond.inq))
|
|
643
|
-
throw new
|
|
1449
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
644
1450
|
"inq",
|
|
645
1451
|
"an Array of possible values",
|
|
646
1452
|
cond.inq
|
|
@@ -654,7 +1460,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
654
1460
|
}
|
|
655
1461
|
if ("nin" in cond) {
|
|
656
1462
|
if (!cond.nin || !Array.isArray(cond.nin))
|
|
657
|
-
throw new
|
|
1463
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
658
1464
|
"nin",
|
|
659
1465
|
"an Array of possible values",
|
|
660
1466
|
cond
|
|
@@ -668,7 +1474,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
668
1474
|
}
|
|
669
1475
|
if ("between" in cond) {
|
|
670
1476
|
if (!Array.isArray(cond.between) || cond.between.length !== 2)
|
|
671
|
-
throw new
|
|
1477
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
672
1478
|
"between",
|
|
673
1479
|
"an Array of 2 elements",
|
|
674
1480
|
cond.between
|
|
@@ -679,7 +1485,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
679
1485
|
}
|
|
680
1486
|
if ("exists" in cond) {
|
|
681
1487
|
if (typeof cond.exists !== "boolean")
|
|
682
|
-
throw new
|
|
1488
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
683
1489
|
"exists",
|
|
684
1490
|
"a Boolean",
|
|
685
1491
|
cond.exists
|
|
@@ -688,7 +1494,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
688
1494
|
}
|
|
689
1495
|
if ("like" in cond) {
|
|
690
1496
|
if (typeof cond.like !== "string" && !(cond.like instanceof RegExp))
|
|
691
|
-
throw new
|
|
1497
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
692
1498
|
"like",
|
|
693
1499
|
"a String or RegExp",
|
|
694
1500
|
cond.like
|
|
@@ -697,7 +1503,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
697
1503
|
}
|
|
698
1504
|
if ("nlike" in cond) {
|
|
699
1505
|
if (typeof cond.nlike !== "string" && !(cond.nlike instanceof RegExp))
|
|
700
|
-
throw new
|
|
1506
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
701
1507
|
"nlike",
|
|
702
1508
|
"a String or RegExp",
|
|
703
1509
|
cond.nlike
|
|
@@ -706,7 +1512,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
706
1512
|
}
|
|
707
1513
|
if ("ilike" in cond) {
|
|
708
1514
|
if (typeof cond.ilike !== "string" && !(cond.ilike instanceof RegExp))
|
|
709
|
-
throw new
|
|
1515
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
710
1516
|
"ilike",
|
|
711
1517
|
"a String or RegExp",
|
|
712
1518
|
cond.ilike
|
|
@@ -715,7 +1521,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
715
1521
|
}
|
|
716
1522
|
if ("nilike" in cond) {
|
|
717
1523
|
if (typeof cond.nilike !== "string" && !(cond.nilike instanceof RegExp)) {
|
|
718
|
-
throw new
|
|
1524
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
719
1525
|
"nilike",
|
|
720
1526
|
"a String or RegExp",
|
|
721
1527
|
cond.nilike
|
|
@@ -725,7 +1531,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
725
1531
|
}
|
|
726
1532
|
if ("regexp" in cond) {
|
|
727
1533
|
if (typeof cond.regexp !== "string" && !(cond.regexp instanceof RegExp)) {
|
|
728
|
-
throw new
|
|
1534
|
+
throw new import_js_repository11.InvalidOperatorValueError(
|
|
729
1535
|
"regexp",
|
|
730
1536
|
"a String or RegExp",
|
|
731
1537
|
cond.regexp
|
|
@@ -733,7 +1539,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
733
1539
|
}
|
|
734
1540
|
const flags = cond.flags || void 0;
|
|
735
1541
|
if (flags && typeof flags !== "string")
|
|
736
|
-
throw new
|
|
1542
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
737
1543
|
"RegExp flags must be a String, but %v given.",
|
|
738
1544
|
cond.flags
|
|
739
1545
|
);
|
|
@@ -765,7 +1571,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
765
1571
|
if (idValue == null || idValue === "" || idValue === 0) {
|
|
766
1572
|
const pkType = this._getIdType(modelName);
|
|
767
1573
|
if (pkType !== import_js_repository4.DataType.STRING && pkType !== import_js_repository4.DataType.ANY)
|
|
768
|
-
throw new
|
|
1574
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
769
1575
|
"MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
|
|
770
1576
|
(0, import_js_repository5.capitalize)(pkType),
|
|
771
1577
|
idPropName
|
|
@@ -799,7 +1605,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
799
1605
|
const table = this._getCollection(modelName);
|
|
800
1606
|
const { matchedCount } = await table.replaceOne({ _id: id }, tableData);
|
|
801
1607
|
if (matchedCount < 1)
|
|
802
|
-
throw new
|
|
1608
|
+
throw new import_js_repository10.InvalidArgumentError("Identifier %v is not found.", String(id));
|
|
803
1609
|
const projection = this._buildProjection(
|
|
804
1610
|
modelName,
|
|
805
1611
|
filter && filter.fields
|
|
@@ -822,7 +1628,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
822
1628
|
if (idValue == null || idValue === "" || idValue === 0) {
|
|
823
1629
|
const pkType = this._getIdType(modelName);
|
|
824
1630
|
if (pkType !== import_js_repository4.DataType.STRING && pkType !== import_js_repository4.DataType.ANY)
|
|
825
|
-
throw new
|
|
1631
|
+
throw new import_js_repository10.InvalidArgumentError(
|
|
826
1632
|
"MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
|
|
827
1633
|
(0, import_js_repository5.capitalize)(pkType),
|
|
828
1634
|
idPropName
|
|
@@ -882,7 +1688,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
882
1688
|
const table = this._getCollection(modelName);
|
|
883
1689
|
const { matchedCount } = await table.updateOne({ _id: id }, { $set: tableData });
|
|
884
1690
|
if (matchedCount < 1)
|
|
885
|
-
throw new
|
|
1691
|
+
throw new import_js_repository10.InvalidArgumentError("Identifier %v is not found.", String(id));
|
|
886
1692
|
const projection = this._buildProjection(
|
|
887
1693
|
modelName,
|
|
888
1694
|
filter && filter.fields
|
|
@@ -926,7 +1732,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
926
1732
|
);
|
|
927
1733
|
const patchedData = await table.findOne({ _id: id }, { projection });
|
|
928
1734
|
if (!patchedData)
|
|
929
|
-
throw new
|
|
1735
|
+
throw new import_js_repository10.InvalidArgumentError("Identifier %v is not found.", String(id));
|
|
930
1736
|
return this._fromDatabase(modelName, patchedData);
|
|
931
1737
|
}
|
|
932
1738
|
/**
|
|
@@ -978,7 +1784,7 @@ var _MongodbAdapter = class _MongodbAdapter extends import_js_repository3.Adapte
|
|
|
978
1784
|
async count(modelName, where = void 0) {
|
|
979
1785
|
const query = this._buildQuery(modelName, where);
|
|
980
1786
|
const table = this._getCollection(modelName);
|
|
981
|
-
return await table.
|
|
1787
|
+
return await table.countDocuments(query);
|
|
982
1788
|
}
|
|
983
1789
|
};
|
|
984
1790
|
__name(_MongodbAdapter, "MongodbAdapter");
|