@samet-it/be-db-common 1.3.5 → 1.3.7

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.
@@ -1,13 +1,25 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { errorHandler, setFqn } from "@samet-it/be-base-common";
3
- import { errorCommon, isFilledObj, isText } from "@samet-it/be-base-common";
2
+ import { setFqn, } from "@samet-it/be-base-common";
3
+ import { errorCommon, isFilledObj, isText, } from "@samet-it/be-base-common";
4
4
  import { queryParser } from "@leyyo/query";
5
- import { assertArray, assertInteger, assertMessage, assertObject, assertText } from "@samet-it/be-base-common";
5
+ import { assertArray, assertInteger, assertMessage, assertObject, assertText, } from "@samet-it/be-base-common";
6
6
  import { DbError, DbInvalidValueError, DbNotSupportedError } from "../error/index.js";
7
7
  import { isBareObject } from "@samet-it/be-base-common";
8
8
  import { FQN } from "../internal.js";
9
- const FORBIDDEN_KEYS = ['id', 'urn', '_trashId', 'createdAt', 'createdBy', 'updatedAt', 'updatedBy', "_rev", '_search', '_alpha', '_irregular'];
10
- const STRICT_KEYS = ['id', 'urn', '_trashId', "_rev", '_irregular'];
9
+ const FORBIDDEN_KEYS = [
10
+ "id",
11
+ "urn",
12
+ "_trashId",
13
+ "createdAt",
14
+ "createdBy",
15
+ "updatedAt",
16
+ "updatedBy",
17
+ "_rev",
18
+ "_search",
19
+ "_alpha",
20
+ "_irregular",
21
+ ];
22
+ const STRICT_KEYS = ["id", "urn", "_trashId", "_rev", "_irregular"];
11
23
  // noinspection JSUnusedGlobalSymbols
12
24
  /**
13
25
  * DB repository abstract class
@@ -49,7 +61,11 @@ export class DbRepo {
49
61
  * */
50
62
  constructor(conn, opt) {
51
63
  if (!isFilledObj(conn)) {
52
- throw new DbInvalidValueError('Connection', { where: 'DbRepo', method: 'constructor', type: typeof conn });
64
+ throw new DbInvalidValueError("Connection", {
65
+ where: "DbRepo",
66
+ method: "constructor",
67
+ type: typeof conn,
68
+ });
53
69
  }
54
70
  if (!isBareObject(this._opt)) {
55
71
  this._opt = {};
@@ -71,23 +87,27 @@ export class DbRepo {
71
87
  this._opt.cache = { isEnabled: false, isConnected: false };
72
88
  }
73
89
  if (this._opt.useVersion) {
74
- if (typeof this._opt.version !== 'number') {
75
- throw new DbInvalidValueError('Model version', { where: 'DbRepo', method: 'constructor', type: typeof this._opt.version });
90
+ if (typeof this._opt.version !== "number") {
91
+ throw new DbInvalidValueError("Model version", {
92
+ where: "DbRepo",
93
+ method: "constructor",
94
+ type: typeof this._opt.version,
95
+ });
76
96
  }
77
97
  }
78
98
  else {
79
99
  this._opt.version = undefined;
80
100
  }
81
- if (typeof this._opt.urnDelimiter !== 'string') {
82
- this._opt.urnDelimiter = ',';
101
+ if (typeof this._opt.urnDelimiter !== "string") {
102
+ this._opt.urnDelimiter = ",";
83
103
  }
84
104
  else {
85
105
  this._opt.urnDelimiter = this._opt.urnDelimiter.trim();
86
- if (![',', '|', ';', '/'].includes(this._opt.urnDelimiter)) {
87
- this._opt.urnDelimiter = ',';
106
+ if (![",", "|", ";", "/"].includes(this._opt.urnDelimiter)) {
107
+ this._opt.urnDelimiter = ",";
88
108
  }
89
109
  }
90
- if (typeof this._opt.urnPrefix !== 'string') {
110
+ if (typeof this._opt.urnPrefix !== "string") {
91
111
  this._opt.urnPrefix = undefined;
92
112
  }
93
113
  else {
@@ -97,23 +117,27 @@ export class DbRepo {
97
117
  }
98
118
  }
99
119
  if (!this._opt.urnPrefix) {
100
- throw new DbInvalidValueError('Urn prefix', { where: 'DbRepo', method: 'constructor', type: typeof this._opt.urnPrefix });
120
+ throw new DbInvalidValueError("Urn prefix", {
121
+ where: "DbRepo",
122
+ method: "constructor",
123
+ type: typeof this._opt.urnPrefix,
124
+ });
101
125
  }
102
126
  if (!Array.isArray(this._opt.forbiddenSet)) {
103
127
  this._opt.forbiddenSet = [...FORBIDDEN_KEYS];
104
128
  }
105
129
  else {
106
- STRICT_KEYS.forEach(k => {
130
+ STRICT_KEYS.forEach((k) => {
107
131
  if (!this._opt.forbiddenSet.includes(k)) {
108
132
  this._opt.forbiddenSet.push(k);
109
133
  }
110
134
  });
111
135
  }
112
136
  const directOpt = this._opt;
113
- if (typeof directOpt.$toUrnTuple === 'function') {
137
+ if (typeof directOpt.$toUrnTuple === "function") {
114
138
  this.$toUrnTuple = directOpt.$toUrnTuple;
115
139
  }
116
- if (typeof directOpt.$toDim === 'function') {
140
+ if (typeof directOpt.$toDim === "function") {
117
141
  this.$toDim = async (doc, dim) => {
118
142
  return (await directOpt.$toDim(doc, dim));
119
143
  };
@@ -139,9 +163,11 @@ export class DbRepo {
139
163
  * @return {string}
140
164
  * */
141
165
  get _randomIndexName() {
142
- return 'idx_' + randomUUID().match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
143
- .map(s => s.toLowerCase())
144
- .join('_');
166
+ return ("idx_" +
167
+ randomUUID()
168
+ .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
169
+ .map((s) => s.toLowerCase())
170
+ .join("_"));
145
171
  }
146
172
  /**
147
173
  * Check & validate index name
@@ -150,22 +176,23 @@ export class DbRepo {
150
176
  * @return {string} - validated index name
151
177
  * */
152
178
  _indexName(name) {
153
- if (typeof name !== 'string') {
179
+ if (typeof name !== "string") {
154
180
  return this._randomIndexName;
155
181
  }
156
182
  name = name.trim();
157
- if (name === '') {
183
+ if (name === "") {
158
184
  return this._randomIndexName;
159
185
  }
160
- name = name.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
161
- .map(s => s.toLowerCase())
162
- .join('_');
163
- name = name.replace(/^_+|_+$/g, '');
164
- if (name === '') {
186
+ name = name
187
+ .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
188
+ .map((s) => s.toLowerCase())
189
+ .join("_");
190
+ name = name.replace(/^_+|_+$/g, "");
191
+ if (name === "") {
165
192
  return this._randomIndexName;
166
193
  }
167
- if (!name.startsWith('idx_')) {
168
- name = 'idx_' + name;
194
+ if (!name.startsWith("idx_")) {
195
+ name = "idx_" + name;
169
196
  }
170
197
  if (name.length > 30) {
171
198
  name = name.substring(0, 30);
@@ -176,9 +203,9 @@ export class DbRepo {
176
203
  * Fetch urn from doc as doc.urn
177
204
  * */
178
205
  _urnFromDoc(doc, method) {
179
- const param = { where: 'DbRepo', path: this.path, method };
180
- assertObject(doc, { field: 'doc', ...param });
181
- assertText(doc.urn, { field: 'urn', ...param });
206
+ const param = { where: "DbRepo", path: this.path, method };
207
+ assertObject(doc, { field: "doc", ...param });
208
+ assertText(doc.urn, { field: "urn", ...param });
182
209
  return doc.urn;
183
210
  }
184
211
  /**
@@ -189,12 +216,14 @@ export class DbRepo {
189
216
  * */
190
217
  _checkKey(value) {
191
218
  let id;
219
+ let str;
220
+ let obj;
192
221
  switch (typeof value) {
193
222
  case "string":
194
- const str = value.trim();
223
+ str = value.trim();
195
224
  if (str) {
196
225
  if (this._isUrn(str)) {
197
- return [str, 'urn'];
226
+ return [str, "urn"];
198
227
  }
199
228
  else {
200
229
  if (this.hasNumericId) {
@@ -205,27 +234,27 @@ export class DbRepo {
205
234
  // nothing
206
235
  }
207
236
  if (id !== undefined) {
208
- return [id, 'id'];
237
+ return [id, "id"];
209
238
  }
210
239
  }
211
240
  else {
212
- return [str, 'id'];
241
+ return [str, "id"];
213
242
  }
214
243
  }
215
244
  }
216
245
  break;
217
246
  case "number":
218
247
  if (this.hasNumericId) {
219
- return [value, 'id'];
248
+ return [value, "id"];
220
249
  }
221
250
  else {
222
- return [value.toString(10), 'id'];
251
+ return [value.toString(10), "id"];
223
252
  }
224
253
  case "object":
225
254
  if (!value) {
226
255
  return [undefined, undefined];
227
256
  }
228
- const obj = value;
257
+ obj = value;
229
258
  if (obj.urn !== undefined) {
230
259
  return this._checkKey(obj.urn);
231
260
  }
@@ -250,11 +279,11 @@ export class DbRepo {
250
279
  for (const item of keys) {
251
280
  const [key, field] = this._checkKey(item);
252
281
  if (field) {
253
- if ((field === 'urn') && !result.urns.includes(key)) {
282
+ if (field === "urn" && !result.urns.includes(key)) {
254
283
  result.urns.push(key);
255
284
  result.ordered.push([key, field]);
256
285
  }
257
- else if ((field === 'id') && !result.ids.includes(key)) {
286
+ else if (field === "id" && !result.ids.includes(key)) {
258
287
  result.ids.push(key);
259
288
  result.ordered.push([key, field]);
260
289
  }
@@ -269,7 +298,7 @@ export class DbRepo {
269
298
  * @return boolean - is urn or not
270
299
  * */
271
300
  _isUrn(key) {
272
- return (typeof key === 'string') && key.startsWith(this.urnPrefix + ':');
301
+ return typeof key === "string" && key.startsWith(this.urnPrefix + ":");
273
302
  }
274
303
  /**
275
304
  * Build key to urn value with prefix
@@ -413,19 +442,19 @@ export class DbRepo {
413
442
  // region field-value
414
443
  /** {@inheritDoc} */
415
444
  checkError(err, opt) {
416
- const size = errorHandler.addStat(err);
445
+ const size = errorCommon.addStat(err);
417
446
  const ignoredErrors = opt?.ignoredErrors ?? [];
418
447
  if (ignoredErrors.includes(err) || ignoredErrors.includes(err.name)) {
419
448
  return;
420
449
  }
421
450
  if (opt?.silent) {
422
451
  if (size < 100) {
423
- this.logger.warn(errorCommon.text(err, (opt.name ?? 'Database error'), size));
452
+ this.logger.warn(errorCommon.text(err, (opt.name ?? "Database error"), size));
424
453
  }
425
454
  return;
426
455
  }
427
456
  if (size < 100) {
428
- this.logger.error(errorCommon.text(err, (opt.name ?? 'Database error'), size));
457
+ this.logger.error(errorCommon.text(err, (opt.name ?? "Database error"), size));
429
458
  }
430
459
  if (err instanceof DbError) {
431
460
  throw err;
@@ -443,21 +472,21 @@ export class DbRepo {
443
472
  }
444
473
  /** {@inheritDoc} */
445
474
  rows(rows) {
446
- if (rows && Array.isArray(rows) && (rows.length > 0)) {
447
- return rows.filter(row => row['_trashId'] === undefined);
475
+ if (rows && Array.isArray(rows) && rows.length > 0) {
476
+ return rows.filter((row) => row["_trashId"] === undefined);
448
477
  }
449
478
  return [];
450
479
  }
451
480
  /** {@inheritDoc} */
452
481
  row(row) {
453
- if (row && row['_trashId'] === undefined) {
482
+ if (row && row["_trashId"] === undefined) {
454
483
  return row;
455
484
  }
456
485
  return undefined;
457
486
  }
458
487
  /** {@inheritDoc} */
459
488
  first(rows) {
460
- if (rows && Array.isArray(rows) && (rows.length > 0)) {
489
+ if (rows && Array.isArray(rows) && rows.length > 0) {
461
490
  return rows[0];
462
491
  }
463
492
  return undefined;
@@ -466,11 +495,11 @@ export class DbRepo {
466
495
  // region option
467
496
  /** {@inheritDoc} */
468
497
  buildOpt(p1, name) {
469
- const opt = (typeof p1 === 'string' ? { name: p1 } : { ...p1 });
470
- if (typeof opt.name === undefined && typeof name !== undefined) {
498
+ const opt = (typeof p1 === "string" ? { name: p1 } : { ...p1 });
499
+ if (opt.name === undefined && name !== undefined) {
471
500
  opt.name = name;
472
501
  }
473
- opt.name = opt.name ? `[${opt.name}]` : '';
502
+ opt.name = opt.name ? `[${opt.name}]` : "";
474
503
  return opt;
475
504
  }
476
505
  // endregion option
@@ -494,15 +523,15 @@ export class DbRepo {
494
523
  /** @inheritDoc */
495
524
  toUrn(urnRec) {
496
525
  let code = this.$toUrnTuple(urnRec).join(this.urnDelimiter);
497
- if (code.includes(':')) {
498
- code = code.split(':').join(';');
526
+ if (code.includes(":")) {
527
+ code = code.split(":").join(";");
499
528
  }
500
529
  return `${this.urnPrefix}:${code}`;
501
530
  }
502
531
  /** @inheritDoc */
503
532
  toUrnKey(p1) {
504
533
  if (isText(p1)) {
505
- return p1.split(':').pop();
534
+ return p1.split(":").pop();
506
535
  }
507
536
  const doc = p1;
508
537
  if (isFilledObj(doc)) {
@@ -512,13 +541,13 @@ export class DbRepo {
512
541
  }
513
542
  /** @inheritDoc */
514
543
  $toUrnTuple(urnRec) {
515
- return [urnRec['id']];
544
+ return [urnRec["id"]];
516
545
  }
517
546
  // endregion urn
518
547
  // region get
519
548
  /** @inheritDoc */
520
549
  async get(keyLike, p1) {
521
- const opt = this.buildOpt(p1, 'get');
550
+ const opt = this.buildOpt(p1, "get");
522
551
  const [key, field] = this._checkKey(keyLike);
523
552
  switch (field) {
524
553
  case "urn":
@@ -526,14 +555,25 @@ export class DbRepo {
526
555
  case "id":
527
556
  return this.getBySecondary(key, opt, true);
528
557
  default:
529
- assertMessage('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'get', queryName: opt.name });
558
+ assertMessage("Invalid key", {
559
+ field: "key",
560
+ value: keyLike,
561
+ where: "DbRepo",
562
+ method: "get",
563
+ queryName: opt.name,
564
+ });
530
565
  }
531
566
  }
532
567
  /** @inheritDoc */
533
568
  async getByPrimary(key, p1, ignoreCheck) {
534
- const opt = this.buildOpt(p1, 'getByPrimary');
569
+ const opt = this.buildOpt(p1, "getByPrimary");
535
570
  if (!ignoreCheck) {
536
- assertText(key, { field: 'key', where: 'DbRepo', method: 'getByPrimary', queryName: opt.name });
571
+ assertText(key, {
572
+ field: "key",
573
+ where: "DbRepo",
574
+ method: "getByPrimary",
575
+ queryName: opt.name,
576
+ });
537
577
  }
538
578
  let found;
539
579
  if (!opt.noCache && this.cache.isConnected) {
@@ -541,7 +581,7 @@ export class DbRepo {
541
581
  found = await this.cache.getByPrimary(key, opt);
542
582
  }
543
583
  catch (e) {
544
- this.logger.warn(errorCommon.text(e, 'getByPrimary', 'cache', 'getByPrimary'));
584
+ this.logger.warn(errorCommon.text(e, "getByPrimary", "cache", "getByPrimary"));
545
585
  }
546
586
  if (found) {
547
587
  return found;
@@ -549,21 +589,32 @@ export class DbRepo {
549
589
  }
550
590
  found = await this.$getByPrimary(key, opt, true);
551
591
  if (!opt.noCache && found && this.cache.isConnected) {
552
- this.cache.ingestDoc(found, opt)
592
+ this.cache
593
+ .ingestDoc(found, opt)
553
594
  .then()
554
- .catch(e => this.logger.warn(errorCommon.text(e, 'getByPrimary', 'cache', 'ingestDoc')));
595
+ .catch((e) => this.logger.warn(errorCommon.text(e, "getByPrimary", "cache", "ingestDoc")));
555
596
  }
556
597
  return found;
557
598
  }
558
599
  /** @inheritDoc */
559
600
  async getBySecondary(key, p1, ignoreCheck) {
560
- const opt = this.buildOpt(p1, 'getBySecondary');
601
+ const opt = this.buildOpt(p1, "getBySecondary");
561
602
  if (!ignoreCheck) {
562
603
  if (this.hasNumericId) {
563
- assertInteger(key, { field: 'key', where: 'DbRepo', method: 'getBySecondary', queryName: opt.name });
604
+ assertInteger(key, {
605
+ field: "key",
606
+ where: "DbRepo",
607
+ method: "getBySecondary",
608
+ queryName: opt.name,
609
+ });
564
610
  }
565
611
  else {
566
- assertText(key, { field: 'key', where: 'DbRepo', method: 'getBySecondary', queryName: opt.name });
612
+ assertText(key, {
613
+ field: "key",
614
+ where: "DbRepo",
615
+ method: "getBySecondary",
616
+ queryName: opt.name,
617
+ });
567
618
  }
568
619
  }
569
620
  if (this.isIdSame) {
@@ -578,14 +629,15 @@ export class DbRepo {
578
629
  }
579
630
  }
580
631
  catch (e) {
581
- this.logger.warn(errorCommon.text(e, 'getBySecondary', 'cache', 'getBySecondary'));
632
+ this.logger.warn(errorCommon.text(e, "getBySecondary", "cache", "getBySecondary"));
582
633
  }
583
634
  }
584
635
  found = await this.$getBySecondary(key, opt, true);
585
636
  if (found && this.cache.isConnected) {
586
- this.cache.ingestDoc(found, opt)
637
+ this.cache
638
+ .ingestDoc(found, opt)
587
639
  .then()
588
- .catch(e => this.logger.warn(errorCommon.text(e, 'getBySecondary', 'cache', 'ingestDoc')));
640
+ .catch((e) => this.logger.warn(errorCommon.text(e, "getBySecondary", "cache", "ingestDoc")));
589
641
  }
590
642
  return found;
591
643
  }
@@ -593,7 +645,7 @@ export class DbRepo {
593
645
  // region exists
594
646
  /** @inheritDoc */
595
647
  async exists(keyLike, p1) {
596
- const opt = this.buildOpt(p1, 'exists');
648
+ const opt = this.buildOpt(p1, "exists");
597
649
  const [key, field] = this._checkKey(keyLike);
598
650
  switch (field) {
599
651
  case "urn":
@@ -601,15 +653,26 @@ export class DbRepo {
601
653
  case "id":
602
654
  return this.existsBySecondary(key, opt, true);
603
655
  default:
604
- assertMessage('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'exists', queryName: opt.name });
656
+ assertMessage("Invalid key", {
657
+ field: "key",
658
+ value: keyLike,
659
+ where: "DbRepo",
660
+ method: "exists",
661
+ queryName: opt.name,
662
+ });
605
663
  break;
606
664
  }
607
665
  }
608
666
  /** @inheritDoc */
609
667
  async existsByPrimary(key, p1, ignoreCheck) {
610
- const opt = this.buildOpt(p1, 'existsByPrimary');
668
+ const opt = this.buildOpt(p1, "existsByPrimary");
611
669
  if (!ignoreCheck) {
612
- assertText(key, { field: 'key', where: 'DbRepo', method: 'existsByPrimary', queryName: opt.name });
670
+ assertText(key, {
671
+ field: "key",
672
+ where: "DbRepo",
673
+ method: "existsByPrimary",
674
+ queryName: opt.name,
675
+ });
613
676
  }
614
677
  if (!opt.noCache && this.cache.isConnected) {
615
678
  try {
@@ -619,20 +682,30 @@ export class DbRepo {
619
682
  }
620
683
  }
621
684
  catch (e) {
622
- this.logger.warn(errorCommon.text(e, 'existsByPrimary', 'cache', 'getByPrimary'));
685
+ this.logger.warn(errorCommon.text(e, "existsByPrimary", "cache", "getByPrimary"));
623
686
  }
624
687
  }
625
688
  return this.$existsByPrimary(key, opt, true);
626
689
  }
627
690
  /** @inheritDoc */
628
691
  async existsBySecondary(key, p1, ignoreCheck) {
629
- const opt = this.buildOpt(p1, 'existsBySecondary');
692
+ const opt = this.buildOpt(p1, "existsBySecondary");
630
693
  if (!ignoreCheck) {
631
694
  if (this.hasNumericId) {
632
- assertInteger(key, { field: 'key', where: 'DbRepo', method: 'existsBySecondary', queryName: opt.name });
695
+ assertInteger(key, {
696
+ field: "key",
697
+ where: "DbRepo",
698
+ method: "existsBySecondary",
699
+ queryName: opt.name,
700
+ });
633
701
  }
634
702
  else {
635
- assertText(key, { field: 'key', where: 'DbRepo', method: 'existsBySecondary', queryName: opt.name });
703
+ assertText(key, {
704
+ field: "key",
705
+ where: "DbRepo",
706
+ method: "existsBySecondary",
707
+ queryName: opt.name,
708
+ });
636
709
  }
637
710
  }
638
711
  if (!this.isIdSame) {
@@ -646,7 +719,7 @@ export class DbRepo {
646
719
  }
647
720
  }
648
721
  catch (e) {
649
- this.logger.warn(errorCommon.text(e, 'existsBySecondary', 'cache', 'getBySecondary'));
722
+ this.logger.warn(errorCommon.text(e, "existsBySecondary", "cache", "getBySecondary"));
650
723
  }
651
724
  }
652
725
  return this.$existsBySecondary(key, opt, true);
@@ -655,9 +728,14 @@ export class DbRepo {
655
728
  // region list
656
729
  /** @inheritDoc */
657
730
  async list(keyLikes, p1, ignoreCheck) {
658
- const opt = this.buildOpt(p1, 'list');
731
+ const opt = this.buildOpt(p1, "list");
659
732
  if (!ignoreCheck) {
660
- assertArray(keyLikes, { field: 'keys', where: 'DbRepo', method: 'list', queryName: opt.name });
733
+ assertArray(keyLikes, {
734
+ field: "keys",
735
+ where: "DbRepo",
736
+ method: "list",
737
+ queryName: opt.name,
738
+ });
661
739
  }
662
740
  const result = this._checkKeys(keyLikes);
663
741
  if (result.ordered.length < 1) {
@@ -671,9 +749,9 @@ export class DbRepo {
671
749
  founds = await this.cache.getByPrimaryMore(result.urns, opt);
672
750
  }
673
751
  catch (e) {
674
- this.logger.warn(errorCommon.text(e, 'list', 'cache', 'getByPrimary'));
752
+ this.logger.warn(errorCommon.text(e, "list", "cache", "getByPrimary"));
675
753
  }
676
- founds.forEach(val => {
754
+ founds.forEach((val) => {
677
755
  const index = result.urns.indexOf(val.urn);
678
756
  if (index >= 0) {
679
757
  result.urns.splice(index, 1);
@@ -685,9 +763,10 @@ export class DbRepo {
685
763
  founds = await this.$listByPrimary(result.urns, opt, true);
686
764
  if (founds.length > 0) {
687
765
  if (!opt.noCache && this.cache.isConnected) {
688
- founds.forEach(found => this.cache.ingestDoc(found, opt)
766
+ founds.forEach((found) => this.cache
767
+ .ingestDoc(found, opt)
689
768
  .then()
690
- .catch(e => this.logger.warn(errorCommon.text(e, 'list', 'cache', 'ingestDoc'))));
769
+ .catch((e) => this.logger.warn(errorCommon.text(e, "list", "cache", "ingestDoc"))));
691
770
  }
692
771
  docs.push(...founds);
693
772
  }
@@ -699,9 +778,9 @@ export class DbRepo {
699
778
  founds = await this.cache.getBySecondaryMore(result.ids, opt);
700
779
  }
701
780
  catch (e) {
702
- this.logger.warn(errorCommon.text(e, 'list', 'cache', 'getBySecondary'));
781
+ this.logger.warn(errorCommon.text(e, "list", "cache", "getBySecondary"));
703
782
  }
704
- founds.forEach(val => {
783
+ founds.forEach((val) => {
705
784
  const index = result.ids.indexOf(val.id);
706
785
  if (index >= 0) {
707
786
  result.ids.splice(index, 1);
@@ -713,43 +792,44 @@ export class DbRepo {
713
792
  founds = await this.$listBySecondary(result.ids, opt, true);
714
793
  if (founds.length > 0) {
715
794
  if (!opt.noCache && this.cache.isConnected) {
716
- founds.forEach(found => this.cache.ingestDoc(found, opt)
795
+ founds.forEach((found) => this.cache
796
+ .ingestDoc(found, opt)
717
797
  .then()
718
- .catch(e => this.logger.warn(errorCommon.text(e, 'list', 'cache', 'ingestDoc'))));
798
+ .catch((e) => this.logger.warn(errorCommon.text(e, "list", "cache", "ingestDoc"))));
719
799
  }
720
800
  docs.push(...founds);
721
801
  }
722
802
  }
723
803
  }
724
- return result.ordered.map(o => docs.find(d => d[o[1]] === o[0]));
804
+ return result.ordered.map((o) => docs.find((d) => d[o[1]] === o[0]));
725
805
  }
726
806
  // endregion list
727
807
  // region filter
728
808
  /** @inheritDoc */
729
809
  async filter(query, p1) {
730
- const opt = this.buildOpt(p1, 'filter');
810
+ const opt = this.buildOpt(p1, "filter");
731
811
  return this.$filter(queryParser.exec(query, [], opt.name), opt);
732
812
  }
733
813
  // endregion filter
734
814
  // region insert
735
815
  /** @inheritDoc */
736
816
  async insert(doc, p1, ignoreCheck) {
737
- const opt = this.buildOpt(p1, 'insert');
738
- const param = { where: 'DbRepo', method: 'insert', queryName: opt.name };
817
+ const opt = this.buildOpt(p1, "insert");
818
+ const param = { where: "DbRepo", method: "insert", queryName: opt.name };
739
819
  if (this.isNoInsert) {
740
- throw new DbNotSupportedError('Insert', param);
820
+ throw new DbNotSupportedError("Insert", param);
741
821
  }
742
822
  if (!ignoreCheck) {
743
- assertObject(doc, { field: 'doc', ...param });
823
+ assertObject(doc, { field: "doc", ...param });
744
824
  if (this.hasNumericId) {
745
- assertInteger(doc.id, { field: 'doc.id', ...param });
825
+ assertInteger(doc.id, { field: "doc.id", ...param });
746
826
  }
747
827
  else {
748
- assertText(doc.id, { field: 'doc.id', ...param });
828
+ assertText(doc.id, { field: "doc.id", ...param });
749
829
  }
750
- assertText(doc.urn, { field: 'doc.urn', ...param });
830
+ assertText(doc.urn, { field: "doc.urn", ...param });
751
831
  }
752
- if (!doc._trashId !== undefined) {
832
+ if (doc._trashId !== undefined) {
753
833
  delete doc._trashId;
754
834
  }
755
835
  if (this.hasCreatedAt) {
@@ -757,7 +837,7 @@ export class DbRepo {
757
837
  }
758
838
  let userId;
759
839
  if (this.hasCreatedBy && this.userFetcher) {
760
- doc.createdBy = await this.userFetcher();
840
+ doc.createdBy = (await this.userFetcher());
761
841
  userId = doc.createdBy;
762
842
  }
763
843
  if (this.hasUpdatedAt) {
@@ -768,20 +848,20 @@ export class DbRepo {
768
848
  doc.createdBy = userId;
769
849
  }
770
850
  else {
771
- doc.createdBy = await this.userFetcher();
851
+ doc.createdBy = (await this.userFetcher());
772
852
  }
773
853
  }
774
854
  return this.$insert(doc, opt);
775
855
  }
776
856
  /** @inheritDoc */
777
857
  async inserts(docs, p1, ignoreCheck) {
778
- const opt = this.buildOpt(p1, 'inserts');
779
- const param = { where: 'DbRepo', method: 'inserts', queryName: opt.name };
858
+ const opt = this.buildOpt(p1, "inserts");
859
+ const param = { where: "DbRepo", method: "inserts", queryName: opt.name };
780
860
  if (this.isNoInsert) {
781
- throw new DbNotSupportedError('Insert', param);
861
+ throw new DbNotSupportedError("Insert", param);
782
862
  }
783
863
  if (!ignoreCheck) {
784
- assertArray(docs, { field: 'docs', ...param });
864
+ assertArray(docs, { field: "docs", ...param });
785
865
  }
786
866
  const insertedIds = [];
787
867
  for (const doc of docs) {
@@ -793,15 +873,30 @@ export class DbRepo {
793
873
  // region replace
794
874
  /** @inheritDoc */
795
875
  async replace(doc, p1, ignoreCheck) {
796
- const opt = this.buildOpt(p1, 'replace');
876
+ const opt = this.buildOpt(p1, "replace");
797
877
  if (!ignoreCheck) {
798
- assertObject(doc, { field: 'doc', where: 'DbRepo', method: 'replace', queryName: opt.name });
799
- assertText(doc.urn, { field: 'doc.urn', where: 'DbRepo', method: 'replace', queryName: opt.name });
878
+ assertObject(doc, { field: "doc", where: "DbRepo", method: "replace", queryName: opt.name });
879
+ assertText(doc.urn, {
880
+ field: "doc.urn",
881
+ where: "DbRepo",
882
+ method: "replace",
883
+ queryName: opt.name,
884
+ });
800
885
  if (this.hasNumericId) {
801
- assertInteger(doc.id, { field: 'doc.id', where: 'DbRepo', method: 'replace', queryName: opt.name });
886
+ assertInteger(doc.id, {
887
+ field: "doc.id",
888
+ where: "DbRepo",
889
+ method: "replace",
890
+ queryName: opt.name,
891
+ });
802
892
  }
803
893
  else {
804
- assertText(doc.id, { field: 'doc.id', where: 'DbRepo', method: 'replace', queryName: opt.name });
894
+ assertText(doc.id, {
895
+ field: "doc.id",
896
+ where: "DbRepo",
897
+ method: "replace",
898
+ queryName: opt.name,
899
+ });
805
900
  }
806
901
  }
807
902
  if (doc._trashId !== undefined) {
@@ -811,13 +906,14 @@ export class DbRepo {
811
906
  doc.updatedAt = this._now;
812
907
  }
813
908
  if (this.hasUpdatedBy && this.userFetcher) {
814
- doc.createdBy = await this.userFetcher();
909
+ doc.createdBy = (await this.userFetcher());
815
910
  }
816
911
  const replacedKey = await this.$replace(doc, opt, true);
817
912
  if (!opt.noCache && this.cache.isConnected) {
818
- this.cache.clearDoc(replacedKey, opt)
913
+ this.cache
914
+ .clearDoc(replacedKey, opt)
819
915
  .then()
820
- .catch(e => this.logger.warn(errorCommon.text(e, 'replace', 'cache', 'clearDoc')));
916
+ .catch((e) => this.logger.warn(errorCommon.text(e, "replace", "cache", "clearDoc")));
821
917
  }
822
918
  return replacedKey;
823
919
  }
@@ -825,19 +921,19 @@ export class DbRepo {
825
921
  // region upsert
826
922
  /** @inheritDoc */
827
923
  async upsert(doc, p1, ignoreCheck) {
828
- const opt = this.buildOpt(p1, 'upsert');
829
- const param = { where: 'DbRepo', method: 'upsert', queryName: opt.name };
924
+ const opt = this.buildOpt(p1, "upsert");
925
+ const param = { where: "DbRepo", method: "upsert", queryName: opt.name };
830
926
  if (this.isNoInsert || this.isNoUpdate) {
831
- throw new DbNotSupportedError('Upsert', param);
927
+ throw new DbNotSupportedError("Upsert", param);
832
928
  }
833
929
  if (!ignoreCheck) {
834
- assertObject(doc, { field: 'doc', ...param });
835
- assertText(doc.urn, { field: 'doc.urn', ...param });
930
+ assertObject(doc, { field: "doc", ...param });
931
+ assertText(doc.urn, { field: "doc.urn", ...param });
836
932
  if (this.hasNumericId) {
837
- assertInteger(doc.id, { field: 'doc.id', ...param });
933
+ assertInteger(doc.id, { field: "doc.id", ...param });
838
934
  }
839
935
  else {
840
- assertText(doc.id, { field: 'doc.id', ...param });
936
+ assertText(doc.id, { field: "doc.id", ...param });
841
937
  }
842
938
  }
843
939
  if (doc._trashId !== undefined) {
@@ -847,13 +943,14 @@ export class DbRepo {
847
943
  doc.updatedAt = this._now;
848
944
  }
849
945
  if (this.hasUpdatedBy && this.userFetcher) {
850
- doc.createdBy = await this.userFetcher();
946
+ doc.createdBy = (await this.userFetcher());
851
947
  }
852
948
  const createdKey = await this.$replace(doc, opt, true);
853
949
  if (!opt.noCache && this.cache.isConnected) {
854
- this.cache.clearDoc(createdKey, opt)
950
+ this.cache
951
+ .clearDoc(createdKey, opt)
855
952
  .then()
856
- .catch(e => this.logger.warn(errorCommon.text(e, 'upsert', 'cache', 'clearDoc')));
953
+ .catch((e) => this.logger.warn(errorCommon.text(e, "upsert", "cache", "clearDoc")));
857
954
  }
858
955
  return createdKey;
859
956
  }
@@ -861,9 +958,9 @@ export class DbRepo {
861
958
  // region update
862
959
  /** @inheritDoc */
863
960
  async update(k1, doc, p1, ignoreCheck) {
864
- const opt = this.buildOpt(p1, 'update');
961
+ const opt = this.buildOpt(p1, "update");
865
962
  if (!ignoreCheck) {
866
- assertObject(doc, { field: 'doc', where: 'DbRepo', method: 'update', queryName: opt.name });
963
+ assertObject(doc, { field: "doc", where: "DbRepo", method: "update", queryName: opt.name });
867
964
  }
868
965
  const [key, field] = this._checkKey(k1);
869
966
  switch (field) {
@@ -872,24 +969,30 @@ export class DbRepo {
872
969
  case "id":
873
970
  return this.updateBySecondary(key, doc, opt, true);
874
971
  default:
875
- assertMessage('Invalid key', { field: 'key', value: k1, where: 'DbRepo', method: 'update', queryName: opt.name });
972
+ assertMessage("Invalid key", {
973
+ field: "key",
974
+ value: k1,
975
+ where: "DbRepo",
976
+ method: "update",
977
+ queryName: opt.name,
978
+ });
876
979
  }
877
980
  }
878
981
  /** @inheritDoc */
879
982
  async updateByPrimary(key, doc, p1, ignoreCheck) {
880
- const opt = this.buildOpt(p1, 'updateByPrimary');
881
- const param = { where: 'DbRepo', method: 'updateByPrimary', queryName: opt.name };
983
+ const opt = this.buildOpt(p1, "updateByPrimary");
984
+ const param = { where: "DbRepo", method: "updateByPrimary", queryName: opt.name };
882
985
  if (this.isNoUpdate) {
883
- throw new DbNotSupportedError('Update', param);
986
+ throw new DbNotSupportedError("Update", param);
884
987
  }
885
988
  if (!ignoreCheck) {
886
- assertText(key, { field: 'key', ...param });
887
- assertObject(doc, { field: 'doc', ...param });
989
+ assertText(key, { field: "key", ...param });
990
+ assertObject(doc, { field: "doc", ...param });
888
991
  }
889
992
  if (doc._trashId !== undefined) {
890
993
  delete doc._trashId;
891
994
  }
892
- this._props.forbiddenSet.forEach(f => {
995
+ this._props.forbiddenSet.forEach((f) => {
893
996
  if (doc[f] !== undefined) {
894
997
  delete doc[f];
895
998
  }
@@ -898,31 +1001,32 @@ export class DbRepo {
898
1001
  doc.updatedAt = this._now;
899
1002
  }
900
1003
  if (this.hasUpdatedBy && this.userFetcher) {
901
- doc.createdBy = await this.userFetcher();
1004
+ doc.createdBy = (await this.userFetcher());
902
1005
  }
903
1006
  const updatedKey = await this.$updateByPrimary(key, doc, opt, true);
904
1007
  if (updatedKey && !opt.noCache && this.cache.isConnected) {
905
- this.cache.clearDoc(updatedKey, opt)
1008
+ this.cache
1009
+ .clearDoc(updatedKey, opt)
906
1010
  .then()
907
- .catch(e => this.logger.warn(errorCommon.text(e, 'updateByPrimary', 'cache', 'clearDoc')));
1011
+ .catch((e) => this.logger.warn(errorCommon.text(e, "updateByPrimary", "cache", "clearDoc")));
908
1012
  }
909
1013
  return updatedKey;
910
1014
  }
911
1015
  /** @inheritDoc */
912
1016
  async updateBySecondary(key, doc, p1, ignoreCheck) {
913
- const opt = this.buildOpt(p1, 'updateBySecondary');
914
- const param = { where: 'DbRepo', method: 'updateBySecondary', queryName: opt.name };
1017
+ const opt = this.buildOpt(p1, "updateBySecondary");
1018
+ const param = { where: "DbRepo", method: "updateBySecondary", queryName: opt.name };
915
1019
  if (this.isNoUpdate) {
916
- throw new DbNotSupportedError('Update', param);
1020
+ throw new DbNotSupportedError("Update", param);
917
1021
  }
918
1022
  if (!ignoreCheck) {
919
1023
  if (this.hasNumericId) {
920
- assertInteger(key, { field: 'key', ...param });
1024
+ assertInteger(key, { field: "key", ...param });
921
1025
  }
922
1026
  else {
923
- assertText(key, { field: 'key', ...param });
1027
+ assertText(key, { field: "key", ...param });
924
1028
  }
925
- assertObject(doc, { field: 'doc', ...param });
1029
+ assertObject(doc, { field: "doc", ...param });
926
1030
  }
927
1031
  if (this.isIdSame) {
928
1032
  return this.updateBySecondary(this._keyToUrn(key), doc, opt, true);
@@ -930,7 +1034,7 @@ export class DbRepo {
930
1034
  if (doc._trashId !== undefined) {
931
1035
  delete doc._trashId;
932
1036
  }
933
- this._props.forbiddenSet.forEach(f => {
1037
+ this._props.forbiddenSet.forEach((f) => {
934
1038
  if (doc[f] !== undefined) {
935
1039
  delete doc[f];
936
1040
  }
@@ -939,13 +1043,14 @@ export class DbRepo {
939
1043
  doc.updatedAt = this._now;
940
1044
  }
941
1045
  if (this.hasUpdatedBy && this.userFetcher) {
942
- doc.createdBy = await this.userFetcher();
1046
+ doc.createdBy = (await this.userFetcher());
943
1047
  }
944
1048
  const updatedKey = await this.$updateBySecondary(key, doc, opt, true);
945
1049
  if (updatedKey && !opt.noCache && this.cache.isConnected) {
946
- this.cache.clearDoc(updatedKey, opt)
1050
+ this.cache
1051
+ .clearDoc(updatedKey, opt)
947
1052
  .then()
948
- .catch(e => this.logger.warn(errorCommon.text(e, 'updateBySecondary', 'cache', 'clearDoc')));
1053
+ .catch((e) => this.logger.warn(errorCommon.text(e, "updateBySecondary", "cache", "clearDoc")));
949
1054
  }
950
1055
  return updatedKey;
951
1056
  }
@@ -953,12 +1058,13 @@ export class DbRepo {
953
1058
  // region set
954
1059
  /** @inheritDoc */
955
1060
  async set(key, doc, p1, ignoreCheck) {
956
- const opt = this.buildOpt(p1, 'set');
1061
+ const opt = this.buildOpt(p1, "set");
957
1062
  if (!ignoreCheck) {
958
- assertObject(doc, { field: 'doc', where: 'DbRepo', method: 'set', queryName: opt.name });
1063
+ assertObject(doc, { field: "doc", where: "DbRepo", method: "set", queryName: opt.name });
959
1064
  }
960
1065
  for (const [f, v] of Object.entries(doc)) {
961
- if (v === undefined) { // dont allow undefined
1066
+ if (v === undefined) {
1067
+ // dont allow undefined
962
1068
  delete doc[f];
963
1069
  }
964
1070
  }
@@ -966,15 +1072,26 @@ export class DbRepo {
966
1072
  }
967
1073
  /** @inheritDoc */
968
1074
  async unset(key, fields, p1, ignoreCheck) {
969
- const opt = this.buildOpt(p1, 'unset');
1075
+ const opt = this.buildOpt(p1, "unset");
970
1076
  if (!ignoreCheck) {
971
- assertArray(fields, { field: 'fields', where: 'DbRepo', method: 'unset', queryName: opt.name });
1077
+ assertArray(fields, {
1078
+ field: "fields",
1079
+ where: "DbRepo",
1080
+ method: "unset",
1081
+ queryName: opt.name,
1082
+ });
972
1083
  fields.forEach((field, index) => {
973
- assertText(field, { field: field, where: 'DbRepo', method: 'unset', index, queryName: opt.name });
1084
+ assertText(field, {
1085
+ field: field,
1086
+ where: "DbRepo",
1087
+ method: "unset",
1088
+ index,
1089
+ queryName: opt.name,
1090
+ });
974
1091
  });
975
1092
  }
976
1093
  const doc = {};
977
- fields.forEach(f => {
1094
+ fields.forEach((f) => {
978
1095
  if (!this._props.forbiddenSet.includes(f)) {
979
1096
  doc[f] = undefined;
980
1097
  }
@@ -985,7 +1102,7 @@ export class DbRepo {
985
1102
  // region remove
986
1103
  /** @inheritDoc */
987
1104
  async remove(keyLike, p1) {
988
- const opt = this.buildOpt(p1, 'remove');
1105
+ const opt = this.buildOpt(p1, "remove");
989
1106
  const [key, field] = this._checkKey(keyLike);
990
1107
  switch (field) {
991
1108
  case "urn":
@@ -993,48 +1110,56 @@ export class DbRepo {
993
1110
  case "id":
994
1111
  return this.removeBySecondary(key, opt, true);
995
1112
  default:
996
- assertMessage('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'remove', queryName: opt.name });
1113
+ assertMessage("Invalid key", {
1114
+ field: "key",
1115
+ value: keyLike,
1116
+ where: "DbRepo",
1117
+ method: "remove",
1118
+ queryName: opt.name,
1119
+ });
997
1120
  }
998
1121
  }
999
1122
  /** @inheritDoc */
1000
1123
  async removeByPrimary(key, p1, ignoreCheck) {
1001
- const opt = this.buildOpt(p1, 'removeByPrimary');
1002
- const param = { where: 'DbRepo', method: 'removeByPrimary', queryName: opt.name };
1124
+ const opt = this.buildOpt(p1, "removeByPrimary");
1125
+ const param = { where: "DbRepo", method: "removeByPrimary", queryName: opt.name };
1003
1126
  if (this.isNoRemove) {
1004
- throw new DbNotSupportedError('Remove', param);
1127
+ throw new DbNotSupportedError("Remove", param);
1005
1128
  }
1006
1129
  if (!ignoreCheck) {
1007
- assertText(key, { field: 'key', ...param });
1130
+ assertText(key, { field: "key", ...param });
1008
1131
  }
1009
1132
  const removedKey = await this.$removeByPrimary(key, opt, true);
1010
1133
  if (removedKey && !opt.noCache && this.cache.isConnected) {
1011
- this.cache.clearDoc(removedKey, opt)
1134
+ this.cache
1135
+ .clearDoc(removedKey, opt)
1012
1136
  .then()
1013
- .catch(e => this.logger.warn(errorCommon.text(e, 'removeByPrimary', 'cache', 'clearDoc')));
1137
+ .catch((e) => this.logger.warn(errorCommon.text(e, "removeByPrimary", "cache", "clearDoc")));
1014
1138
  }
1015
1139
  return removedKey;
1016
1140
  }
1017
1141
  /** @inheritDoc */
1018
1142
  async removeBySecondary(key, p1, ignoreCheck) {
1019
- const opt = this.buildOpt(p1, 'removeBySecondary');
1020
- const param = { where: 'DbRepo', method: 'removeByPrimary', queryName: opt.name };
1143
+ const opt = this.buildOpt(p1, "removeBySecondary");
1144
+ const param = { where: "DbRepo", method: "removeByPrimary", queryName: opt.name };
1021
1145
  if (this.isNoRemove) {
1022
- throw new DbNotSupportedError('Remove', param);
1146
+ throw new DbNotSupportedError("Remove", param);
1023
1147
  }
1024
1148
  if (this.hasNumericId) {
1025
- assertInteger(key, { field: 'key', param });
1149
+ assertInteger(key, { field: "key", param });
1026
1150
  }
1027
1151
  else {
1028
- assertText(key, { field: 'key', param });
1152
+ assertText(key, { field: "key", param });
1029
1153
  }
1030
1154
  if (this.isIdSame) {
1031
1155
  return this.removeByPrimary(this._keyToUrn(key), opt, ignoreCheck);
1032
1156
  }
1033
1157
  const removedKey = await this.$removeBySecondary(key, opt, true);
1034
1158
  if (removedKey && !opt.noCache && this.cache.isConnected) {
1035
- this.cache.clearDoc(removedKey, opt)
1159
+ this.cache
1160
+ .clearDoc(removedKey, opt)
1036
1161
  .then()
1037
- .catch(e => this.logger.warn(errorCommon.text(e, 'removeBySecondary', 'cache', 'clearDoc')));
1162
+ .catch((e) => this.logger.warn(errorCommon.text(e, "removeBySecondary", "cache", "clearDoc")));
1038
1163
  }
1039
1164
  return removedKey;
1040
1165
  }
@@ -1042,7 +1167,7 @@ export class DbRepo {
1042
1167
  // region trash
1043
1168
  /** @inheritDoc */
1044
1169
  async trash(keyLike, p1) {
1045
- const opt = this.buildOpt(p1, 'trash');
1170
+ const opt = this.buildOpt(p1, "trash");
1046
1171
  const [key, field] = this._checkKey(keyLike);
1047
1172
  switch (field) {
1048
1173
  case "urn":
@@ -1050,48 +1175,55 @@ export class DbRepo {
1050
1175
  case "id":
1051
1176
  return this.trashBySecondary(key, opt, true);
1052
1177
  default:
1053
- assertMessage('Invalid key', { field: 'key', value: keyLike, where: 'DbRepo', method: 'trash', queryName: opt.name });
1178
+ assertMessage("Invalid key", {
1179
+ field: "key",
1180
+ value: keyLike,
1181
+ where: "DbRepo",
1182
+ method: "trash",
1183
+ queryName: opt.name,
1184
+ });
1054
1185
  }
1055
1186
  }
1056
1187
  /** @inheritDoc */
1057
1188
  async trashByPrimary(key, p1, ignoreCheck) {
1058
- const opt = this.buildOpt(p1, 'trashByPrimary');
1059
- const param = { where: 'DbRepo', method: 'trashByPrimary', queryName: opt.name };
1189
+ const opt = this.buildOpt(p1, "trashByPrimary");
1190
+ const param = { where: "DbRepo", method: "trashByPrimary", queryName: opt.name };
1060
1191
  if (!this.hasSoftDelete) {
1061
- throw new DbNotSupportedError('Soft Delete', param);
1192
+ throw new DbNotSupportedError("Soft Delete", param);
1062
1193
  }
1063
1194
  if (this.isNoTrash) {
1064
- throw new DbNotSupportedError('Trash', param);
1195
+ throw new DbNotSupportedError("Trash", param);
1065
1196
  }
1066
1197
  if (!ignoreCheck) {
1067
- assertText(key, { field: 'urn', ...param });
1198
+ assertText(key, { field: "urn", ...param });
1068
1199
  }
1069
1200
  if (!isText(opt.trashId)) {
1070
1201
  opt.trashId = randomUUID();
1071
1202
  }
1072
1203
  const trashedKey = await this.$trashByPrimary(key, opt, true);
1073
1204
  if (trashedKey && !opt.noCache && this.cache.isConnected) {
1074
- this.cache.clearDoc(trashedKey, opt)
1205
+ this.cache
1206
+ .clearDoc(trashedKey, opt)
1075
1207
  .then()
1076
- .catch(e => this.logger.warn(errorCommon.text(e, 'trashByPrimary', 'cache', 'clearDoc')));
1208
+ .catch((e) => this.logger.warn(errorCommon.text(e, "trashByPrimary", "cache", "clearDoc")));
1077
1209
  }
1078
1210
  return trashedKey;
1079
1211
  }
1080
1212
  /** @inheritDoc */
1081
1213
  async trashBySecondary(key, p1, ignoreCheck) {
1082
- const opt = this.buildOpt(p1, 'trashBySecondary');
1083
- const param = { where: 'DbRepo', method: 'trashBySecondary', queryName: opt.name };
1214
+ const opt = this.buildOpt(p1, "trashBySecondary");
1215
+ const param = { where: "DbRepo", method: "trashBySecondary", queryName: opt.name };
1084
1216
  if (!this.hasSoftDelete) {
1085
- throw new DbNotSupportedError('Soft Delete', param);
1217
+ throw new DbNotSupportedError("Soft Delete", param);
1086
1218
  }
1087
1219
  if (this.isNoTrash) {
1088
- throw new DbNotSupportedError('Trash', param);
1220
+ throw new DbNotSupportedError("Trash", param);
1089
1221
  }
1090
1222
  if (this.hasNumericId) {
1091
- assertInteger(key, { field: 'key', ...param });
1223
+ assertInteger(key, { field: "key", ...param });
1092
1224
  }
1093
1225
  else {
1094
- assertText(key, { field: 'key', ...param });
1226
+ assertText(key, { field: "key", ...param });
1095
1227
  }
1096
1228
  if (this.isIdSame) {
1097
1229
  return this.trashByPrimary(this._keyToUrn(key), opt, ignoreCheck);
@@ -1101,9 +1233,10 @@ export class DbRepo {
1101
1233
  }
1102
1234
  const trashedKey = await this.$trashBySecondary(key, opt, true);
1103
1235
  if (trashedKey && !opt.noCache && this.cache.isConnected) {
1104
- this.cache.clearDoc(trashedKey, opt)
1236
+ this.cache
1237
+ .clearDoc(trashedKey, opt)
1105
1238
  .then()
1106
- .catch(e => this.logger.warn(errorCommon.text(e, 'trashBySecondary', 'cache', 'clearDoc')));
1239
+ .catch((e) => this.logger.warn(errorCommon.text(e, "trashBySecondary", "cache", "clearDoc")));
1107
1240
  }
1108
1241
  return trashedKey;
1109
1242
  }
@@ -1116,11 +1249,11 @@ export class DbRepo {
1116
1249
  }
1117
1250
  switch (dim) {
1118
1251
  case "view":
1119
- return await this.toView(doc);
1252
+ return (await this.toView(doc));
1120
1253
  case "pair":
1121
- return await this.toPair(doc);
1254
+ return (await this.toPair(doc));
1122
1255
  case "portion":
1123
- return await this.toPortion(doc);
1256
+ return (await this.toPortion(doc));
1124
1257
  default: // portion
1125
1258
  if (this.isIdSame) {
1126
1259
  return { id: doc.id };
@@ -1132,12 +1265,12 @@ export class DbRepo {
1132
1265
  }
1133
1266
  /** @inheritDoc */
1134
1267
  async getDim(key, dim) {
1135
- const doc = await this.get(key, { name: `getDim/${dim ?? 'def'}` });
1268
+ const doc = await this.get(key, { name: `getDim/${dim ?? "def"}` });
1136
1269
  return doc ? this.$toDim(doc, dim) : undefined;
1137
1270
  }
1138
1271
  /** @inheritDoc */
1139
1272
  async listDims(keys, dim, ignoreCheck) {
1140
- const docs = await this.list(keys, { name: `listDims/${dim ?? 'def'}` }, ignoreCheck);
1273
+ const docs = await this.list(keys, { name: `listDims/${dim ?? "def"}` }, ignoreCheck);
1141
1274
  if (docs.length < 1) {
1142
1275
  return [];
1143
1276
  }
@@ -1206,7 +1339,7 @@ export class DbRepo {
1206
1339
  async getPortion(key) {
1207
1340
  if (this.isIdSame) {
1208
1341
  const [identifier, field] = this._checkKey(key);
1209
- if (field === 'id') {
1342
+ if (field === "id") {
1210
1343
  return { id: identifier };
1211
1344
  }
1212
1345
  }
@@ -1219,7 +1352,7 @@ export class DbRepo {
1219
1352
  const idResult = this._checkKeys(keys);
1220
1353
  if (!idResult?.urns?.length) {
1221
1354
  if (Array.isArray(idResult?.ids)) {
1222
- return idResult.ids.map(id => {
1355
+ return idResult.ids.map((id) => {
1223
1356
  return { id };
1224
1357
  });
1225
1358
  }