@samet-it/be-db-common 1.1.8 → 1.3.1
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/dist/connection/db.connection.d.ts +2 -2
- package/dist/connection/db.connection.js +5 -5
- package/dist/error/db-execute.error.d.ts +1 -1
- package/dist/error/db-invalid-value.error.d.ts +1 -1
- package/dist/error/db-not-supported.error.d.ts +1 -1
- package/dist/line/db-lines.impl.d.ts +1 -1
- package/dist/repo/db.repo.d.ts +48 -4
- package/dist/repo/db.repo.js +89 -30
- package/dist/repo/index.types.d.ts +11 -7
- package/package.json +6 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { DbConnectionLike, DbConnOpt, DbOnAfter, DbConnProps, DbEvent } from "./index.types";
|
|
2
|
+
import { Logger } from "@leyyo/common";
|
|
3
3
|
/**
|
|
4
4
|
* DB connection abstract class
|
|
5
5
|
*
|
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.DbConnection = void 0;
|
|
13
|
-
const be_base_common_1 = require("@samet-it/be-base-common");
|
|
14
13
|
const type_1 = require("@leyyo/type");
|
|
14
|
+
const common_1 = require("@leyyo/common");
|
|
15
15
|
// noinspection JSUnusedGlobalSymbols
|
|
16
16
|
/**
|
|
17
17
|
* DB connection abstract class
|
|
@@ -43,10 +43,10 @@ class DbConnection {
|
|
|
43
43
|
* Option of in-body usage in place of constructor param
|
|
44
44
|
* */
|
|
45
45
|
this._opt = {};
|
|
46
|
-
if (!(0, type_1.
|
|
46
|
+
if (!(0, type_1.isBareObject)(this._opt)) {
|
|
47
47
|
this._opt = {};
|
|
48
48
|
}
|
|
49
|
-
if ((0, type_1.
|
|
49
|
+
if ((0, type_1.isBareObject)(opt)) {
|
|
50
50
|
this._opt = Object.assign(Object.assign({}, this._opt), opt);
|
|
51
51
|
}
|
|
52
52
|
this._props = Object.assign(Object.assign({}, this._opt), { connectTryCount: 0, pingTryCount: 0 });
|
|
@@ -70,7 +70,7 @@ class DbConnection {
|
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
72
|
fn().then().catch(e => {
|
|
73
|
-
this.logger.warn(
|
|
73
|
+
this.logger.warn(common_1.errorCommon.text(e, 'on', name));
|
|
74
74
|
if (throwable) {
|
|
75
75
|
throw e;
|
|
76
76
|
}
|
|
@@ -88,7 +88,7 @@ class DbConnection {
|
|
|
88
88
|
if (items.length > 0) {
|
|
89
89
|
items.forEach(fn => {
|
|
90
90
|
fn().then().catch(e => {
|
|
91
|
-
this.logger.warn(
|
|
91
|
+
this.logger.warn(common_1.errorCommon.text(e, 'trigger', 'on', name));
|
|
92
92
|
if (throwable) {
|
|
93
93
|
throw e;
|
|
94
94
|
}
|
package/dist/repo/db.repo.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DbCheckKeysResult, DbRepoProps, DbRepoLike, DbRepoOpt, UrnDelimiter, DbCheckKeysTuple, DbExecOpt, DbMeta, DbRepoExtensionLambda, DbQueryResultOne, DbQueryResultMore } from "./index.types";
|
|
2
2
|
import { DefDims, Entity, IdDocLike, Pair, Portion, UrnDocLike, UrnTuple, View } from "@samet-it/be-base-common";
|
|
3
3
|
import { DbConnectionLike, UserFetcherLambda } from "../connection";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
4
|
+
import { KeyValue, Logger, Opt, StrKey } from "@leyyo/common";
|
|
5
|
+
import { QueryAny, QueryRegular } from "@leyyo/query";
|
|
6
|
+
import { CacheConnectionLike, CacheChannelLike, CacheExecOpt } from "@samet-it/be-cache-common";
|
|
7
|
+
import { DbLines } from "../line";
|
|
8
8
|
/**
|
|
9
9
|
* DB repository abstract class
|
|
10
10
|
*
|
|
@@ -42,19 +42,63 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
|
|
|
42
42
|
* @param {DbRepoOpt} opt - options
|
|
43
43
|
* */
|
|
44
44
|
protected constructor(conn: CONN, opt?: DbRepoOpt<ENT, ID>);
|
|
45
|
+
/**
|
|
46
|
+
* Check given options
|
|
47
|
+
* */
|
|
48
|
+
private _checkOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Generate time value by configuration
|
|
51
|
+
*
|
|
52
|
+
* - hasIsoDate: true => string iso datetime
|
|
53
|
+
* - hasIsoDate: false => number timestamp
|
|
54
|
+
*
|
|
55
|
+
* @return {(string|number)}
|
|
56
|
+
* */
|
|
45
57
|
protected get _now(): string | number;
|
|
58
|
+
/**
|
|
59
|
+
* Generate random index name
|
|
60
|
+
*
|
|
61
|
+
* @return {string}
|
|
62
|
+
* */
|
|
46
63
|
protected get _randomIndexName(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Check & validate index name
|
|
66
|
+
*
|
|
67
|
+
* @param {string} name - given index name
|
|
68
|
+
* @return {string} - validated index name
|
|
69
|
+
* */
|
|
47
70
|
protected _indexName(name: string): string;
|
|
48
71
|
/**
|
|
49
72
|
* Fetch urn from doc as doc.urn
|
|
50
73
|
* */
|
|
51
74
|
protected _urnFromDoc(doc: Partial<ENT>, method: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Check key, understand it urn, id or portion
|
|
77
|
+
*
|
|
78
|
+
* @param {any} value - given id value
|
|
79
|
+
* @return {DbCheckKeysTuple} - key tuple as [value, field]
|
|
80
|
+
* */
|
|
52
81
|
protected _checkKey(value: unknown): DbCheckKeysTuple<ID>;
|
|
53
82
|
/**
|
|
54
83
|
* Check array keys as id list or urn list
|
|
84
|
+
*
|
|
85
|
+
* @param {Array} keys - given keys
|
|
86
|
+
* @return {DbCheckKeysResult} - list of key tuple
|
|
55
87
|
* */
|
|
56
88
|
protected _checkKeys(keys: Array<unknown>): DbCheckKeysResult<ID>;
|
|
89
|
+
/**
|
|
90
|
+
* Is key urn or id
|
|
91
|
+
*
|
|
92
|
+
* @param {KeyValue} key - given key value
|
|
93
|
+
* @return boolean - is urn or not
|
|
94
|
+
* */
|
|
57
95
|
protected _isUrn(key: KeyValue): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Build key to urn value with prefix
|
|
98
|
+
*
|
|
99
|
+
* @param {KeyValue} key - given key value
|
|
100
|
+
* @return {string} - urn value
|
|
101
|
+
* */
|
|
58
102
|
protected _keyToUrn(key: KeyValue): string;
|
|
59
103
|
/** @inheritDoc */
|
|
60
104
|
get props(): Readonly<DbRepoProps<CONN, ENT, ID>>;
|
package/dist/repo/db.repo.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.DbRepo = void 0;
|
|
13
13
|
const node_crypto_1 = require("node:crypto");
|
|
14
14
|
const be_base_common_1 = require("@samet-it/be-base-common");
|
|
15
|
+
const common_1 = require("@leyyo/common");
|
|
15
16
|
const query_1 = require("@leyyo/query");
|
|
16
17
|
const type_1 = require("@leyyo/type");
|
|
17
18
|
const error_1 = require("../error");
|
|
@@ -47,18 +48,27 @@ class DbRepo {
|
|
|
47
48
|
* Option of in-body usage in place of constructor param
|
|
48
49
|
* */
|
|
49
50
|
this._opt = {};
|
|
50
|
-
if (!(0,
|
|
51
|
+
if (!(0, common_1.isFilledObj)(conn)) {
|
|
51
52
|
throw new error_1.DbInvalidValueError('Connection', { where: 'DbRepo', method: 'constructor', type: typeof conn });
|
|
52
53
|
}
|
|
53
|
-
if (!(0, type_1.
|
|
54
|
+
if (!(0, type_1.isBareObject)(this._opt)) {
|
|
54
55
|
this._opt = {};
|
|
55
56
|
}
|
|
56
|
-
if ((0, type_1.
|
|
57
|
+
if ((0, type_1.isBareObject)(opt)) {
|
|
57
58
|
this._opt = Object.assign(Object.assign({}, this._opt), opt);
|
|
58
59
|
}
|
|
60
|
+
this._checkOptions();
|
|
61
|
+
this._props = Object.assign({ conn }, this._opt);
|
|
62
|
+
delete this._opt;
|
|
63
|
+
}
|
|
64
|
+
// region protected-method
|
|
65
|
+
/**
|
|
66
|
+
* Check given options
|
|
67
|
+
* */
|
|
68
|
+
_checkOptions() {
|
|
59
69
|
// handle invalid cache
|
|
60
70
|
if (!this._opt.cache) {
|
|
61
|
-
this._opt.cache = { isConnected: false };
|
|
71
|
+
this._opt.cache = { isEnabled: false, isConnected: false };
|
|
62
72
|
}
|
|
63
73
|
if (this._opt.useVersion) {
|
|
64
74
|
if (typeof this._opt.version !== 'number') {
|
|
@@ -99,18 +109,46 @@ class DbRepo {
|
|
|
99
109
|
}
|
|
100
110
|
});
|
|
101
111
|
}
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
const directOpt = this._opt;
|
|
113
|
+
if (typeof directOpt.$toUrnTuple === 'function') {
|
|
114
|
+
this.$toUrnTuple = directOpt.$toUrnTuple;
|
|
115
|
+
}
|
|
116
|
+
if (typeof directOpt.$toDim === 'function') {
|
|
117
|
+
this.$toDim = (doc, dim) => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
return (yield directOpt.$toDim(doc, dim));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (!Array.isArray(directOpt.indexedFields)) {
|
|
122
|
+
directOpt.indexedFields = [];
|
|
123
|
+
}
|
|
104
124
|
}
|
|
105
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Generate time value by configuration
|
|
127
|
+
*
|
|
128
|
+
* - hasIsoDate: true => string iso datetime
|
|
129
|
+
* - hasIsoDate: false => number timestamp
|
|
130
|
+
*
|
|
131
|
+
* @return {(string|number)}
|
|
132
|
+
* */
|
|
106
133
|
get _now() {
|
|
107
134
|
return this.hasIsoDate ? new Date().toISOString() : Date.now();
|
|
108
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Generate random index name
|
|
138
|
+
*
|
|
139
|
+
* @return {string}
|
|
140
|
+
* */
|
|
109
141
|
get _randomIndexName() {
|
|
110
142
|
return 'idx_' + (0, node_crypto_1.randomUUID)().match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
|
|
111
143
|
.map(s => s.toLowerCase())
|
|
112
144
|
.join('_');
|
|
113
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Check & validate index name
|
|
148
|
+
*
|
|
149
|
+
* @param {string} name - given index name
|
|
150
|
+
* @return {string} - validated index name
|
|
151
|
+
* */
|
|
114
152
|
_indexName(name) {
|
|
115
153
|
if (typeof name !== 'string') {
|
|
116
154
|
return this._randomIndexName;
|
|
@@ -143,6 +181,12 @@ class DbRepo {
|
|
|
143
181
|
(0, type_1.assertText)(doc.urn, Object.assign({ field: 'urn' }, param));
|
|
144
182
|
return doc.urn;
|
|
145
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Check key, understand it urn, id or portion
|
|
186
|
+
*
|
|
187
|
+
* @param {any} value - given id value
|
|
188
|
+
* @return {DbCheckKeysTuple} - key tuple as [value, field]
|
|
189
|
+
* */
|
|
146
190
|
_checkKey(value) {
|
|
147
191
|
let id;
|
|
148
192
|
switch (typeof value) {
|
|
@@ -194,6 +238,9 @@ class DbRepo {
|
|
|
194
238
|
}
|
|
195
239
|
/**
|
|
196
240
|
* Check array keys as id list or urn list
|
|
241
|
+
*
|
|
242
|
+
* @param {Array} keys - given keys
|
|
243
|
+
* @return {DbCheckKeysResult} - list of key tuple
|
|
197
244
|
* */
|
|
198
245
|
_checkKeys(keys) {
|
|
199
246
|
const result = { urns: [], ids: [], ordered: [] };
|
|
@@ -215,9 +262,21 @@ class DbRepo {
|
|
|
215
262
|
}
|
|
216
263
|
return result;
|
|
217
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Is key urn or id
|
|
267
|
+
*
|
|
268
|
+
* @param {KeyValue} key - given key value
|
|
269
|
+
* @return boolean - is urn or not
|
|
270
|
+
* */
|
|
218
271
|
_isUrn(key) {
|
|
219
272
|
return (typeof key === 'string') && key.startsWith(this.urnPrefix + ':');
|
|
220
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Build key to urn value with prefix
|
|
276
|
+
*
|
|
277
|
+
* @param {KeyValue} key - given key value
|
|
278
|
+
* @return {string} - urn value
|
|
279
|
+
* */
|
|
221
280
|
_keyToUrn(key) {
|
|
222
281
|
return `${this.urnPrefix}:${key}`;
|
|
223
282
|
}
|
|
@@ -363,18 +422,18 @@ class DbRepo {
|
|
|
363
422
|
}
|
|
364
423
|
if (opt === null || opt === void 0 ? void 0 : opt.silent) {
|
|
365
424
|
if (size < 100) {
|
|
366
|
-
this.logger.warn(
|
|
425
|
+
this.logger.warn(common_1.errorCommon.text(err, ((_b = opt.name) !== null && _b !== void 0 ? _b : 'Database error'), size));
|
|
367
426
|
}
|
|
368
427
|
return;
|
|
369
428
|
}
|
|
370
429
|
if (size < 100) {
|
|
371
|
-
this.logger.error(
|
|
430
|
+
this.logger.error(common_1.errorCommon.text(err, ((_c = opt.name) !== null && _c !== void 0 ? _c : 'Database error'), size));
|
|
372
431
|
}
|
|
373
432
|
if (err instanceof error_1.DbError) {
|
|
374
433
|
throw err;
|
|
375
434
|
}
|
|
376
435
|
else {
|
|
377
|
-
throw
|
|
436
|
+
throw common_1.errorCommon.forcedCast(error_1.DbError, err, { queryName: opt.name });
|
|
378
437
|
}
|
|
379
438
|
}
|
|
380
439
|
/** {@inheritDoc} */
|
|
@@ -474,7 +533,7 @@ class DbRepo {
|
|
|
474
533
|
found = yield this.cache.getByPrimary(key, opt);
|
|
475
534
|
}
|
|
476
535
|
catch (e) {
|
|
477
|
-
this.logger.warn(
|
|
536
|
+
this.logger.warn(common_1.errorCommon.text(e, 'getByPrimary', 'cache', 'getByPrimary'));
|
|
478
537
|
}
|
|
479
538
|
if (found) {
|
|
480
539
|
return found;
|
|
@@ -484,7 +543,7 @@ class DbRepo {
|
|
|
484
543
|
if (!opt.noCache && found && this.cache.isConnected) {
|
|
485
544
|
this.cache.ingestDoc(found, opt)
|
|
486
545
|
.then()
|
|
487
|
-
.catch(e => this.logger.warn(
|
|
546
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'getByPrimary', 'cache', 'ingestDoc')));
|
|
488
547
|
}
|
|
489
548
|
return found;
|
|
490
549
|
});
|
|
@@ -513,14 +572,14 @@ class DbRepo {
|
|
|
513
572
|
}
|
|
514
573
|
}
|
|
515
574
|
catch (e) {
|
|
516
|
-
this.logger.warn(
|
|
575
|
+
this.logger.warn(common_1.errorCommon.text(e, 'getBySecondary', 'cache', 'getBySecondary'));
|
|
517
576
|
}
|
|
518
577
|
}
|
|
519
578
|
found = yield this.$getBySecondary(key, opt, true);
|
|
520
579
|
if (found && this.cache.isConnected) {
|
|
521
580
|
this.cache.ingestDoc(found, opt)
|
|
522
581
|
.then()
|
|
523
|
-
.catch(e => this.logger.warn(
|
|
582
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'getBySecondary', 'cache', 'ingestDoc')));
|
|
524
583
|
}
|
|
525
584
|
return found;
|
|
526
585
|
});
|
|
@@ -558,7 +617,7 @@ class DbRepo {
|
|
|
558
617
|
}
|
|
559
618
|
}
|
|
560
619
|
catch (e) {
|
|
561
|
-
this.logger.warn(
|
|
620
|
+
this.logger.warn(common_1.errorCommon.text(e, 'existsByPrimary', 'cache', 'getByPrimary'));
|
|
562
621
|
}
|
|
563
622
|
}
|
|
564
623
|
return this.$existsByPrimary(key, opt, true);
|
|
@@ -587,7 +646,7 @@ class DbRepo {
|
|
|
587
646
|
}
|
|
588
647
|
}
|
|
589
648
|
catch (e) {
|
|
590
|
-
this.logger.warn(
|
|
649
|
+
this.logger.warn(common_1.errorCommon.text(e, 'existsBySecondary', 'cache', 'getBySecondary'));
|
|
591
650
|
}
|
|
592
651
|
}
|
|
593
652
|
return this.$existsBySecondary(key, opt, true);
|
|
@@ -614,7 +673,7 @@ class DbRepo {
|
|
|
614
673
|
founds = yield this.cache.getByPrimaryMore(result.urns, opt);
|
|
615
674
|
}
|
|
616
675
|
catch (e) {
|
|
617
|
-
this.logger.warn(
|
|
676
|
+
this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'getByPrimary'));
|
|
618
677
|
}
|
|
619
678
|
founds.forEach(val => {
|
|
620
679
|
const index = result.urns.indexOf(val.urn);
|
|
@@ -630,7 +689,7 @@ class DbRepo {
|
|
|
630
689
|
if (!opt.noCache && this.cache.isConnected) {
|
|
631
690
|
founds.forEach(found => this.cache.ingestDoc(found, opt)
|
|
632
691
|
.then()
|
|
633
|
-
.catch(e => this.logger.warn(
|
|
692
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'ingestDoc'))));
|
|
634
693
|
}
|
|
635
694
|
docs.push(...founds);
|
|
636
695
|
}
|
|
@@ -642,7 +701,7 @@ class DbRepo {
|
|
|
642
701
|
founds = yield this.cache.getBySecondaryMore(result.ids, opt);
|
|
643
702
|
}
|
|
644
703
|
catch (e) {
|
|
645
|
-
this.logger.warn(
|
|
704
|
+
this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'getBySecondary'));
|
|
646
705
|
}
|
|
647
706
|
founds.forEach(val => {
|
|
648
707
|
const index = result.ids.indexOf(val.id);
|
|
@@ -658,7 +717,7 @@ class DbRepo {
|
|
|
658
717
|
if (!opt.noCache && this.cache.isConnected) {
|
|
659
718
|
founds.forEach(found => this.cache.ingestDoc(found, opt)
|
|
660
719
|
.then()
|
|
661
|
-
.catch(e => this.logger.warn(
|
|
720
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'ingestDoc'))));
|
|
662
721
|
}
|
|
663
722
|
docs.push(...founds);
|
|
664
723
|
}
|
|
@@ -768,7 +827,7 @@ class DbRepo {
|
|
|
768
827
|
if (!opt.noCache && this.cache.isConnected) {
|
|
769
828
|
this.cache.clearDoc(replacedKey, opt)
|
|
770
829
|
.then()
|
|
771
|
-
.catch(e => this.logger.warn(
|
|
830
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'replace', 'cache', 'clearDoc')));
|
|
772
831
|
}
|
|
773
832
|
return replacedKey;
|
|
774
833
|
});
|
|
@@ -806,7 +865,7 @@ class DbRepo {
|
|
|
806
865
|
if (!opt.noCache && this.cache.isConnected) {
|
|
807
866
|
this.cache.clearDoc(createdKey, opt)
|
|
808
867
|
.then()
|
|
809
|
-
.catch(e => this.logger.warn(
|
|
868
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'upsert', 'cache', 'clearDoc')));
|
|
810
869
|
}
|
|
811
870
|
return createdKey;
|
|
812
871
|
});
|
|
@@ -861,7 +920,7 @@ class DbRepo {
|
|
|
861
920
|
if (updatedKey && !opt.noCache && this.cache.isConnected) {
|
|
862
921
|
this.cache.clearDoc(updatedKey, opt)
|
|
863
922
|
.then()
|
|
864
|
-
.catch(e => this.logger.warn(
|
|
923
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'updateByPrimary', 'cache', 'clearDoc')));
|
|
865
924
|
}
|
|
866
925
|
return updatedKey;
|
|
867
926
|
});
|
|
@@ -904,7 +963,7 @@ class DbRepo {
|
|
|
904
963
|
if (updatedKey && !opt.noCache && this.cache.isConnected) {
|
|
905
964
|
this.cache.clearDoc(updatedKey, opt)
|
|
906
965
|
.then()
|
|
907
|
-
.catch(e => this.logger.warn(
|
|
966
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'updateBySecondary', 'cache', 'clearDoc')));
|
|
908
967
|
}
|
|
909
968
|
return updatedKey;
|
|
910
969
|
});
|
|
@@ -977,7 +1036,7 @@ class DbRepo {
|
|
|
977
1036
|
if (removedKey && !opt.noCache && this.cache.isConnected) {
|
|
978
1037
|
this.cache.clearDoc(removedKey, opt)
|
|
979
1038
|
.then()
|
|
980
|
-
.catch(e => this.logger.warn(
|
|
1039
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'removeByPrimary', 'cache', 'clearDoc')));
|
|
981
1040
|
}
|
|
982
1041
|
return removedKey;
|
|
983
1042
|
});
|
|
@@ -1003,7 +1062,7 @@ class DbRepo {
|
|
|
1003
1062
|
if (removedKey && !opt.noCache && this.cache.isConnected) {
|
|
1004
1063
|
this.cache.clearDoc(removedKey, opt)
|
|
1005
1064
|
.then()
|
|
1006
|
-
.catch(e => this.logger.warn(
|
|
1065
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'removeBySecondary', 'cache', 'clearDoc')));
|
|
1007
1066
|
}
|
|
1008
1067
|
return removedKey;
|
|
1009
1068
|
});
|
|
@@ -1039,14 +1098,14 @@ class DbRepo {
|
|
|
1039
1098
|
if (!ignoreCheck) {
|
|
1040
1099
|
(0, type_1.assertText)(key, Object.assign({ field: 'urn' }, param));
|
|
1041
1100
|
}
|
|
1042
|
-
if (!(0,
|
|
1101
|
+
if (!(0, common_1.isText)(opt.trashId)) {
|
|
1043
1102
|
opt.trashId = (0, node_crypto_1.randomUUID)();
|
|
1044
1103
|
}
|
|
1045
1104
|
const trashedKey = yield this.$trashByPrimary(key, opt, true);
|
|
1046
1105
|
if (trashedKey && !opt.noCache && this.cache.isConnected) {
|
|
1047
1106
|
this.cache.clearDoc(trashedKey, opt)
|
|
1048
1107
|
.then()
|
|
1049
|
-
.catch(e => this.logger.warn(
|
|
1108
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'trashByPrimary', 'cache', 'clearDoc')));
|
|
1050
1109
|
}
|
|
1051
1110
|
return trashedKey;
|
|
1052
1111
|
});
|
|
@@ -1071,14 +1130,14 @@ class DbRepo {
|
|
|
1071
1130
|
if (this.isIdSame) {
|
|
1072
1131
|
return this.trashByPrimary(this._keyToUrn(key), opt, ignoreCheck);
|
|
1073
1132
|
}
|
|
1074
|
-
if (!(0,
|
|
1133
|
+
if (!(0, common_1.isText)(opt.trashId)) {
|
|
1075
1134
|
opt.trashId = (0, node_crypto_1.randomUUID)();
|
|
1076
1135
|
}
|
|
1077
1136
|
const trashedKey = yield this.$trashBySecondary(key, opt, true);
|
|
1078
1137
|
if (trashedKey && !opt.noCache && this.cache.isConnected) {
|
|
1079
1138
|
this.cache.clearDoc(trashedKey, opt)
|
|
1080
1139
|
.then()
|
|
1081
|
-
.catch(e => this.logger.warn(
|
|
1140
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'trashBySecondary', 'cache', 'clearDoc')));
|
|
1082
1141
|
}
|
|
1083
1142
|
return trashedKey;
|
|
1084
1143
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { DefDims, Entity, IdDocLike, Pair, Portion, UrnDef, UrnDocLike, UrnTuple, View } from "@samet-it/be-base-common";
|
|
2
|
+
import { DbConnectionLike, UserFetcherLambda } from "../connection";
|
|
3
|
+
import { QueryAny, QueryRegular } from "@leyyo/query";
|
|
4
|
+
import { CacheChannelLike, CacheConnectionLike, CacheExecOpt } from "@samet-it/be-cache-common";
|
|
5
|
+
import { KeyValue, OmitError, Opt, StrKey } from "@leyyo/common";
|
|
6
|
+
import { DbLines } from "../line";
|
|
7
7
|
/**
|
|
8
8
|
* DB repository interface
|
|
9
9
|
*
|
|
@@ -954,6 +954,10 @@ export interface DbRepoProps<CONN extends DbConnectionLike, ENT extends Entity<I
|
|
|
954
954
|
* @type {number}
|
|
955
955
|
* */
|
|
956
956
|
urnLength?: number;
|
|
957
|
+
/**
|
|
958
|
+
* Indexed fields
|
|
959
|
+
* */
|
|
960
|
+
indexedFields?: Array<keyof ENT | string>;
|
|
957
961
|
}
|
|
958
962
|
/**
|
|
959
963
|
* DB keys result
|
|
@@ -1155,5 +1159,5 @@ export interface DbRepoDirectOpt<ENT extends Entity<ID>, ID extends KeyValue = K
|
|
|
1155
1159
|
/**
|
|
1156
1160
|
* Indexed fields
|
|
1157
1161
|
* */
|
|
1158
|
-
|
|
1162
|
+
indexedFields?: Array<keyof ENT | string>;
|
|
1159
1163
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@samet-it/be-db-common",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Backend DB Common",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,10 +64,10 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@leyyo/common": "^1.
|
|
68
|
-
"@leyyo/query": "^1.
|
|
69
|
-
"@leyyo/type": "^1.
|
|
70
|
-
"@samet-it/be-base-common": "^1.1
|
|
71
|
-
"@samet-it/be-cache-common": "^1.1
|
|
67
|
+
"@leyyo/common": "^1.3.7",
|
|
68
|
+
"@leyyo/query": "^1.3.1",
|
|
69
|
+
"@leyyo/type": "^1.3.3",
|
|
70
|
+
"@samet-it/be-base-common": "^1.3.1",
|
|
71
|
+
"@samet-it/be-cache-common": "^1.3.1"
|
|
72
72
|
}
|
|
73
73
|
}
|