@samet-it/be-db-common 1.1.9 → 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 +4 -4
- package/dist/repo/db.repo.js +27 -26
- package/dist/repo/index.types.d.ts +6 -6
- 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
|
*
|
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,13 +48,13 @@ 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
|
}
|
|
59
60
|
this._checkOptions();
|
|
@@ -421,18 +422,18 @@ class DbRepo {
|
|
|
421
422
|
}
|
|
422
423
|
if (opt === null || opt === void 0 ? void 0 : opt.silent) {
|
|
423
424
|
if (size < 100) {
|
|
424
|
-
this.logger.warn(
|
|
425
|
+
this.logger.warn(common_1.errorCommon.text(err, ((_b = opt.name) !== null && _b !== void 0 ? _b : 'Database error'), size));
|
|
425
426
|
}
|
|
426
427
|
return;
|
|
427
428
|
}
|
|
428
429
|
if (size < 100) {
|
|
429
|
-
this.logger.error(
|
|
430
|
+
this.logger.error(common_1.errorCommon.text(err, ((_c = opt.name) !== null && _c !== void 0 ? _c : 'Database error'), size));
|
|
430
431
|
}
|
|
431
432
|
if (err instanceof error_1.DbError) {
|
|
432
433
|
throw err;
|
|
433
434
|
}
|
|
434
435
|
else {
|
|
435
|
-
throw
|
|
436
|
+
throw common_1.errorCommon.forcedCast(error_1.DbError, err, { queryName: opt.name });
|
|
436
437
|
}
|
|
437
438
|
}
|
|
438
439
|
/** {@inheritDoc} */
|
|
@@ -532,7 +533,7 @@ class DbRepo {
|
|
|
532
533
|
found = yield this.cache.getByPrimary(key, opt);
|
|
533
534
|
}
|
|
534
535
|
catch (e) {
|
|
535
|
-
this.logger.warn(
|
|
536
|
+
this.logger.warn(common_1.errorCommon.text(e, 'getByPrimary', 'cache', 'getByPrimary'));
|
|
536
537
|
}
|
|
537
538
|
if (found) {
|
|
538
539
|
return found;
|
|
@@ -542,7 +543,7 @@ class DbRepo {
|
|
|
542
543
|
if (!opt.noCache && found && this.cache.isConnected) {
|
|
543
544
|
this.cache.ingestDoc(found, opt)
|
|
544
545
|
.then()
|
|
545
|
-
.catch(e => this.logger.warn(
|
|
546
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'getByPrimary', 'cache', 'ingestDoc')));
|
|
546
547
|
}
|
|
547
548
|
return found;
|
|
548
549
|
});
|
|
@@ -571,14 +572,14 @@ class DbRepo {
|
|
|
571
572
|
}
|
|
572
573
|
}
|
|
573
574
|
catch (e) {
|
|
574
|
-
this.logger.warn(
|
|
575
|
+
this.logger.warn(common_1.errorCommon.text(e, 'getBySecondary', 'cache', 'getBySecondary'));
|
|
575
576
|
}
|
|
576
577
|
}
|
|
577
578
|
found = yield this.$getBySecondary(key, opt, true);
|
|
578
579
|
if (found && this.cache.isConnected) {
|
|
579
580
|
this.cache.ingestDoc(found, opt)
|
|
580
581
|
.then()
|
|
581
|
-
.catch(e => this.logger.warn(
|
|
582
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'getBySecondary', 'cache', 'ingestDoc')));
|
|
582
583
|
}
|
|
583
584
|
return found;
|
|
584
585
|
});
|
|
@@ -616,7 +617,7 @@ class DbRepo {
|
|
|
616
617
|
}
|
|
617
618
|
}
|
|
618
619
|
catch (e) {
|
|
619
|
-
this.logger.warn(
|
|
620
|
+
this.logger.warn(common_1.errorCommon.text(e, 'existsByPrimary', 'cache', 'getByPrimary'));
|
|
620
621
|
}
|
|
621
622
|
}
|
|
622
623
|
return this.$existsByPrimary(key, opt, true);
|
|
@@ -645,7 +646,7 @@ class DbRepo {
|
|
|
645
646
|
}
|
|
646
647
|
}
|
|
647
648
|
catch (e) {
|
|
648
|
-
this.logger.warn(
|
|
649
|
+
this.logger.warn(common_1.errorCommon.text(e, 'existsBySecondary', 'cache', 'getBySecondary'));
|
|
649
650
|
}
|
|
650
651
|
}
|
|
651
652
|
return this.$existsBySecondary(key, opt, true);
|
|
@@ -672,7 +673,7 @@ class DbRepo {
|
|
|
672
673
|
founds = yield this.cache.getByPrimaryMore(result.urns, opt);
|
|
673
674
|
}
|
|
674
675
|
catch (e) {
|
|
675
|
-
this.logger.warn(
|
|
676
|
+
this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'getByPrimary'));
|
|
676
677
|
}
|
|
677
678
|
founds.forEach(val => {
|
|
678
679
|
const index = result.urns.indexOf(val.urn);
|
|
@@ -688,7 +689,7 @@ class DbRepo {
|
|
|
688
689
|
if (!opt.noCache && this.cache.isConnected) {
|
|
689
690
|
founds.forEach(found => this.cache.ingestDoc(found, opt)
|
|
690
691
|
.then()
|
|
691
|
-
.catch(e => this.logger.warn(
|
|
692
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'ingestDoc'))));
|
|
692
693
|
}
|
|
693
694
|
docs.push(...founds);
|
|
694
695
|
}
|
|
@@ -700,7 +701,7 @@ class DbRepo {
|
|
|
700
701
|
founds = yield this.cache.getBySecondaryMore(result.ids, opt);
|
|
701
702
|
}
|
|
702
703
|
catch (e) {
|
|
703
|
-
this.logger.warn(
|
|
704
|
+
this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'getBySecondary'));
|
|
704
705
|
}
|
|
705
706
|
founds.forEach(val => {
|
|
706
707
|
const index = result.ids.indexOf(val.id);
|
|
@@ -716,7 +717,7 @@ class DbRepo {
|
|
|
716
717
|
if (!opt.noCache && this.cache.isConnected) {
|
|
717
718
|
founds.forEach(found => this.cache.ingestDoc(found, opt)
|
|
718
719
|
.then()
|
|
719
|
-
.catch(e => this.logger.warn(
|
|
720
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'list', 'cache', 'ingestDoc'))));
|
|
720
721
|
}
|
|
721
722
|
docs.push(...founds);
|
|
722
723
|
}
|
|
@@ -826,7 +827,7 @@ class DbRepo {
|
|
|
826
827
|
if (!opt.noCache && this.cache.isConnected) {
|
|
827
828
|
this.cache.clearDoc(replacedKey, opt)
|
|
828
829
|
.then()
|
|
829
|
-
.catch(e => this.logger.warn(
|
|
830
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'replace', 'cache', 'clearDoc')));
|
|
830
831
|
}
|
|
831
832
|
return replacedKey;
|
|
832
833
|
});
|
|
@@ -864,7 +865,7 @@ class DbRepo {
|
|
|
864
865
|
if (!opt.noCache && this.cache.isConnected) {
|
|
865
866
|
this.cache.clearDoc(createdKey, opt)
|
|
866
867
|
.then()
|
|
867
|
-
.catch(e => this.logger.warn(
|
|
868
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'upsert', 'cache', 'clearDoc')));
|
|
868
869
|
}
|
|
869
870
|
return createdKey;
|
|
870
871
|
});
|
|
@@ -919,7 +920,7 @@ class DbRepo {
|
|
|
919
920
|
if (updatedKey && !opt.noCache && this.cache.isConnected) {
|
|
920
921
|
this.cache.clearDoc(updatedKey, opt)
|
|
921
922
|
.then()
|
|
922
|
-
.catch(e => this.logger.warn(
|
|
923
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'updateByPrimary', 'cache', 'clearDoc')));
|
|
923
924
|
}
|
|
924
925
|
return updatedKey;
|
|
925
926
|
});
|
|
@@ -962,7 +963,7 @@ class DbRepo {
|
|
|
962
963
|
if (updatedKey && !opt.noCache && this.cache.isConnected) {
|
|
963
964
|
this.cache.clearDoc(updatedKey, opt)
|
|
964
965
|
.then()
|
|
965
|
-
.catch(e => this.logger.warn(
|
|
966
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'updateBySecondary', 'cache', 'clearDoc')));
|
|
966
967
|
}
|
|
967
968
|
return updatedKey;
|
|
968
969
|
});
|
|
@@ -1035,7 +1036,7 @@ class DbRepo {
|
|
|
1035
1036
|
if (removedKey && !opt.noCache && this.cache.isConnected) {
|
|
1036
1037
|
this.cache.clearDoc(removedKey, opt)
|
|
1037
1038
|
.then()
|
|
1038
|
-
.catch(e => this.logger.warn(
|
|
1039
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'removeByPrimary', 'cache', 'clearDoc')));
|
|
1039
1040
|
}
|
|
1040
1041
|
return removedKey;
|
|
1041
1042
|
});
|
|
@@ -1061,7 +1062,7 @@ class DbRepo {
|
|
|
1061
1062
|
if (removedKey && !opt.noCache && this.cache.isConnected) {
|
|
1062
1063
|
this.cache.clearDoc(removedKey, opt)
|
|
1063
1064
|
.then()
|
|
1064
|
-
.catch(e => this.logger.warn(
|
|
1065
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'removeBySecondary', 'cache', 'clearDoc')));
|
|
1065
1066
|
}
|
|
1066
1067
|
return removedKey;
|
|
1067
1068
|
});
|
|
@@ -1097,14 +1098,14 @@ class DbRepo {
|
|
|
1097
1098
|
if (!ignoreCheck) {
|
|
1098
1099
|
(0, type_1.assertText)(key, Object.assign({ field: 'urn' }, param));
|
|
1099
1100
|
}
|
|
1100
|
-
if (!(0,
|
|
1101
|
+
if (!(0, common_1.isText)(opt.trashId)) {
|
|
1101
1102
|
opt.trashId = (0, node_crypto_1.randomUUID)();
|
|
1102
1103
|
}
|
|
1103
1104
|
const trashedKey = yield this.$trashByPrimary(key, opt, true);
|
|
1104
1105
|
if (trashedKey && !opt.noCache && this.cache.isConnected) {
|
|
1105
1106
|
this.cache.clearDoc(trashedKey, opt)
|
|
1106
1107
|
.then()
|
|
1107
|
-
.catch(e => this.logger.warn(
|
|
1108
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'trashByPrimary', 'cache', 'clearDoc')));
|
|
1108
1109
|
}
|
|
1109
1110
|
return trashedKey;
|
|
1110
1111
|
});
|
|
@@ -1129,14 +1130,14 @@ class DbRepo {
|
|
|
1129
1130
|
if (this.isIdSame) {
|
|
1130
1131
|
return this.trashByPrimary(this._keyToUrn(key), opt, ignoreCheck);
|
|
1131
1132
|
}
|
|
1132
|
-
if (!(0,
|
|
1133
|
+
if (!(0, common_1.isText)(opt.trashId)) {
|
|
1133
1134
|
opt.trashId = (0, node_crypto_1.randomUUID)();
|
|
1134
1135
|
}
|
|
1135
1136
|
const trashedKey = yield this.$trashBySecondary(key, opt, true);
|
|
1136
1137
|
if (trashedKey && !opt.noCache && this.cache.isConnected) {
|
|
1137
1138
|
this.cache.clearDoc(trashedKey, opt)
|
|
1138
1139
|
.then()
|
|
1139
|
-
.catch(e => this.logger.warn(
|
|
1140
|
+
.catch(e => this.logger.warn(common_1.errorCommon.text(e, 'trashBySecondary', 'cache', 'clearDoc')));
|
|
1140
1141
|
}
|
|
1141
1142
|
return trashedKey;
|
|
1142
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
|
*
|
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
|
}
|