@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.
- package/dist/connection/db.connection.js +13 -9
- package/dist/connection/index.d.ts +2 -2
- package/dist/connection/index.js +2 -2
- package/dist/connection/index.types.d.ts +1 -1
- package/dist/error/db-execute.error.js +5 -1
- package/dist/error/index.d.ts +4 -4
- package/dist/error/index.js +4 -4
- package/dist/index.d.ts +6 -6
- package/dist/index.foretell.d.ts +1 -1
- package/dist/index.foretell.js +6 -4
- package/dist/index.js +6 -6
- package/dist/index.loader.js +2 -2
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +3 -2
- package/dist/line/db-lines.impl.js +29 -29
- package/dist/line/index.d.ts +2 -2
- package/dist/line/index.js +2 -2
- package/dist/repo/db.repo.d.ts +1 -1
- package/dist/repo/db.repo.js +323 -190
- package/dist/repo/index.d.ts +2 -2
- package/dist/repo/index.js +2 -2
- package/dist/repo/index.types.d.ts +17 -17
- package/package.json +21 -34
|
@@ -61,15 +61,17 @@ export class DbConnection {
|
|
|
61
61
|
* @param {boolean?} throwable - throw an error if it fails
|
|
62
62
|
* */
|
|
63
63
|
_on(name, items, fn, throwable) {
|
|
64
|
-
if (typeof fn !==
|
|
64
|
+
if (typeof fn !== "function") {
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
67
|
if (!this._props.isConnected) {
|
|
68
68
|
items.push(fn);
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
fn()
|
|
72
|
-
|
|
71
|
+
fn()
|
|
72
|
+
.then()
|
|
73
|
+
.catch((e) => {
|
|
74
|
+
this.logger.warn(errorCommon.text(e, "on", name));
|
|
73
75
|
if (throwable) {
|
|
74
76
|
throw e;
|
|
75
77
|
}
|
|
@@ -85,9 +87,11 @@ export class DbConnection {
|
|
|
85
87
|
* */
|
|
86
88
|
_triggerOnCase(name, items, throwable) {
|
|
87
89
|
if (items.length > 0) {
|
|
88
|
-
items.forEach(fn => {
|
|
89
|
-
fn()
|
|
90
|
-
|
|
90
|
+
items.forEach((fn) => {
|
|
91
|
+
fn()
|
|
92
|
+
.then()
|
|
93
|
+
.catch((e) => {
|
|
94
|
+
this.logger.warn(errorCommon.text(e, "trigger", "on", name));
|
|
91
95
|
if (throwable) {
|
|
92
96
|
throw e;
|
|
93
97
|
}
|
|
@@ -125,15 +129,15 @@ export class DbConnection {
|
|
|
125
129
|
// region callback
|
|
126
130
|
/** {@inheritDoc} */
|
|
127
131
|
onConnected(fn) {
|
|
128
|
-
this._on(
|
|
132
|
+
this._on("connected", this._onConnected, fn, false);
|
|
129
133
|
}
|
|
130
134
|
/** {@inheritDoc} */
|
|
131
135
|
onDisconnected(fn) {
|
|
132
|
-
this._on(
|
|
136
|
+
this._on("disconnected", this._onDisconnected, fn, false);
|
|
133
137
|
}
|
|
134
138
|
/** {@inheritDoc} */
|
|
135
139
|
onFirstConnected(fn) {
|
|
136
|
-
this._on(
|
|
140
|
+
this._on("first-connected", this._onFirstConnected, fn, true);
|
|
137
141
|
}
|
|
138
142
|
// endregion callback
|
|
139
143
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./db.connection.js";
|
package/dist/connection/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./db.connection.js";
|
|
@@ -151,7 +151,7 @@ export type DbOnAfter = () => Promise<void>;
|
|
|
151
151
|
/**
|
|
152
152
|
* DB connection events
|
|
153
153
|
* */
|
|
154
|
-
export type DbEvent =
|
|
154
|
+
export type DbEvent = "connected" | "disconnected" | "first-connected";
|
|
155
155
|
/**
|
|
156
156
|
* User fetcher lambda
|
|
157
157
|
* - It uses ASL
|
|
@@ -11,6 +11,10 @@ export class DbExecuteError extends DbError {
|
|
|
11
11
|
* @param {Opt} params - parameters
|
|
12
12
|
* */
|
|
13
13
|
constructor(err, name, sql, params) {
|
|
14
|
-
super(`${name ? name +
|
|
14
|
+
super(`${name ? name + " : " : ""}<${err.name}> ${err.message}`, {
|
|
15
|
+
...params,
|
|
16
|
+
sql,
|
|
17
|
+
queryName: name,
|
|
18
|
+
});
|
|
15
19
|
}
|
|
16
20
|
}
|
package/dist/error/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./db.error.js";
|
|
2
|
+
export * from "./db-execute.error.js";
|
|
3
|
+
export * from "./db-invalid-value.error.js";
|
|
4
|
+
export * from "./db-not-supported.error.js";
|
package/dist/error/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./db.error.js";
|
|
2
|
+
export * from "./db-execute.error.js";
|
|
3
|
+
export * from "./db-invalid-value.error.js";
|
|
4
|
+
export * from "./db-not-supported.error.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
1
|
+
export * from "./connection/index.js";
|
|
2
|
+
export * from "./line/index.js";
|
|
3
|
+
export * from "./repo/index.js";
|
|
4
|
+
export * from "./error/index.js";
|
|
5
|
+
export * from "./index.foretell.js";
|
|
6
|
+
export * from "./index.loader.js";
|
package/dist/index.foretell.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const foretell_sametDbCommon:
|
|
1
|
+
export declare const foretell_sametDbCommon: (() => void)[];
|
package/dist/index.foretell.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { FQN } from "./internal.js";
|
|
2
2
|
import { errorPool } from "@samet-it/be-base-common";
|
|
3
3
|
import { foretell_sametBaseCommon } from "@samet-it/be-base-common";
|
|
4
|
+
import { foretell_sametCacheCommon } from "@samet-it/be-cache-common/dist/index.foretell.js";
|
|
4
5
|
// noinspection JSUnusedGlobalSymbols
|
|
5
6
|
export const foretell_sametDbCommon = [
|
|
6
7
|
// dependencies
|
|
7
8
|
...foretell_sametBaseCommon,
|
|
9
|
+
...foretell_sametCacheCommon,
|
|
8
10
|
// errors
|
|
9
|
-
() => errorPool.lazy(FQN,
|
|
10
|
-
() => errorPool.lazy(FQN,
|
|
11
|
-
() => errorPool.lazy(FQN,
|
|
12
|
-
() => errorPool.lazy(FQN,
|
|
11
|
+
() => errorPool.lazy(FQN, "DbError", import("./error/db.error.js").then((m) => m.DbError), { i18n: true, emit: true }),
|
|
12
|
+
() => errorPool.lazy(FQN, "DbExecuteError", import("./error/db-execute.error.js").then((m) => m.DbExecuteError), { i18n: true, emit: true }),
|
|
13
|
+
() => errorPool.lazy(FQN, "DbInvalidValueError", import("./error/db-invalid-value.error.js").then((m) => m.DbInvalidValueError), { i18n: true, emit: true }),
|
|
14
|
+
() => errorPool.lazy(FQN, "DbNotSupportedError", import("./error/db-not-supported.error.js").then((m) => m.DbNotSupportedError), { i18n: true, emit: true }),
|
|
13
15
|
];
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
1
|
+
export * from "./connection/index.js";
|
|
2
|
+
export * from "./line/index.js";
|
|
3
|
+
export * from "./repo/index.js";
|
|
4
|
+
export * from "./error/index.js";
|
|
5
|
+
export * from "./index.foretell.js";
|
|
6
|
+
export * from "./index.loader.js";
|
package/dist/index.loader.js
CHANGED
|
@@ -7,6 +7,6 @@ export const loader_sametDbCommon = defineLoader(FQN,
|
|
|
7
7
|
// dependencies
|
|
8
8
|
...loader_sametBaseCommon, ...loader_sametCacheCommon,
|
|
9
9
|
// errors
|
|
10
|
-
() => import(
|
|
10
|
+
() => import("./error/db.error.js").then((m) => m.DbError), () => import("./error/db-execute.error.js").then((m) => m.DbExecuteError), () => import("./error/db-invalid-value.error.js").then((m) => m.DbInvalidValueError), () => import("./error/db-not-supported.error.js").then((m) => m.DbNotSupportedError),
|
|
11
11
|
// classes
|
|
12
|
-
() => import(
|
|
12
|
+
() => import("./repo/db.repo.js").then((m) => m.DbRepo), () => import("./connection/db.connection.js").then((m) => m.DbConnection));
|
package/dist/internal.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const NME: string, FQN: string, VER: string
|
|
1
|
+
export declare const NME: string, FQN: string, VER: string;
|
package/dist/internal.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { packageJson } from "@leyyo/common";
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
3
|
+
export const { name: NME, fqn: FQN, version: VER } = packageJson(import.meta.url);
|
|
@@ -15,20 +15,20 @@ class DbLinesImpl {
|
|
|
15
15
|
return this;
|
|
16
16
|
}
|
|
17
17
|
parts = parts
|
|
18
|
-
.map(item => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
.map((item) => {
|
|
19
|
+
if (typeof item === "string") {
|
|
20
|
+
const str = item.trim();
|
|
21
|
+
return str ? str : undefined;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return undefined;
|
|
25
25
|
}
|
|
26
26
|
})
|
|
27
|
-
.filter(item => item !== undefined);
|
|
27
|
+
.filter((item) => item !== undefined);
|
|
28
28
|
if (parts.length < 1) {
|
|
29
29
|
return this;
|
|
30
30
|
}
|
|
31
|
-
this._lines.push({ mark, content: parts.join(
|
|
31
|
+
this._lines.push({ mark, content: parts.join(" ") });
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
34
34
|
/** @inheritDoc */
|
|
@@ -41,10 +41,10 @@ class DbLinesImpl {
|
|
|
41
41
|
}
|
|
42
42
|
/** @inheritDoc */
|
|
43
43
|
remove(mark) {
|
|
44
|
-
if (typeof mark !==
|
|
44
|
+
if (typeof mark !== "string") {
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
|
-
const index = this._lines.findIndex(line => line.mark === mark);
|
|
47
|
+
const index = this._lines.findIndex((line) => line.mark === mark);
|
|
48
48
|
if (index < 0) {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
@@ -53,15 +53,15 @@ class DbLinesImpl {
|
|
|
53
53
|
}
|
|
54
54
|
/** @inheritDoc */
|
|
55
55
|
replace(mark, line) {
|
|
56
|
-
if (typeof mark !==
|
|
56
|
+
if (typeof mark !== "string") {
|
|
57
57
|
return false;
|
|
58
58
|
}
|
|
59
|
-
const index = this._lines.findIndex(line => line.mark === mark);
|
|
59
|
+
const index = this._lines.findIndex((line) => line.mark === mark);
|
|
60
60
|
if (index < 0) {
|
|
61
61
|
return false;
|
|
62
62
|
}
|
|
63
|
-
if (typeof line !==
|
|
64
|
-
line =
|
|
63
|
+
if (typeof line !== "string") {
|
|
64
|
+
line = "";
|
|
65
65
|
}
|
|
66
66
|
this._lines[index] = { mark, content: line };
|
|
67
67
|
return true;
|
|
@@ -70,17 +70,17 @@ class DbLinesImpl {
|
|
|
70
70
|
both(flag, yes, no) {
|
|
71
71
|
if (flag) {
|
|
72
72
|
const type = typeof yes;
|
|
73
|
-
if (![
|
|
74
|
-
assertFunction(yes, { field:
|
|
73
|
+
if (!["string", "function"].includes(type)) {
|
|
74
|
+
assertFunction(yes, { field: "yes", method: "both" });
|
|
75
75
|
}
|
|
76
|
-
this.add(
|
|
76
|
+
this.add(typeof yes === "function" ? yes() : yes);
|
|
77
77
|
}
|
|
78
78
|
else {
|
|
79
79
|
const type = typeof no;
|
|
80
|
-
if (![
|
|
81
|
-
assertFunction(no, { field:
|
|
80
|
+
if (!["string", "function"].includes(type)) {
|
|
81
|
+
assertFunction(no, { field: "no", method: "both" });
|
|
82
82
|
}
|
|
83
|
-
this.add(
|
|
83
|
+
this.add(typeof no === "function" ? no() : no);
|
|
84
84
|
}
|
|
85
85
|
return this;
|
|
86
86
|
}
|
|
@@ -88,10 +88,10 @@ class DbLinesImpl {
|
|
|
88
88
|
yes(flag, yes) {
|
|
89
89
|
if (flag) {
|
|
90
90
|
const type = typeof yes;
|
|
91
|
-
if (![
|
|
92
|
-
assertFunction(yes, { field:
|
|
91
|
+
if (!["string", "function"].includes(type)) {
|
|
92
|
+
assertFunction(yes, { field: "yes", method: "yes" });
|
|
93
93
|
}
|
|
94
|
-
this.add(
|
|
94
|
+
this.add(typeof yes === "function" ? yes() : yes);
|
|
95
95
|
}
|
|
96
96
|
return this;
|
|
97
97
|
}
|
|
@@ -99,10 +99,10 @@ class DbLinesImpl {
|
|
|
99
99
|
no(flag, no) {
|
|
100
100
|
if (!flag) {
|
|
101
101
|
const type = typeof no;
|
|
102
|
-
if (![
|
|
103
|
-
assertFunction(no, { field:
|
|
102
|
+
if (!["string", "function"].includes(type)) {
|
|
103
|
+
assertFunction(no, { field: "no", method: "no" });
|
|
104
104
|
}
|
|
105
|
-
this.add(
|
|
105
|
+
this.add(typeof no === "function" ? no() : no);
|
|
106
106
|
}
|
|
107
107
|
return this;
|
|
108
108
|
}
|
|
@@ -113,11 +113,11 @@ class DbLinesImpl {
|
|
|
113
113
|
}
|
|
114
114
|
/** @inheritDoc */
|
|
115
115
|
end() {
|
|
116
|
-
return this.lines.join(
|
|
116
|
+
return this.lines.join("\n");
|
|
117
117
|
}
|
|
118
118
|
/** @inheritDoc */
|
|
119
119
|
get lines() {
|
|
120
|
-
return this._lines.map(line => line.content);
|
|
120
|
+
return this._lines.map((line) => line.content);
|
|
121
121
|
}
|
|
122
122
|
/** @inheritDoc */
|
|
123
123
|
get size() {
|
package/dist/line/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./db-lines.impl.js";
|
package/dist/line/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./db-lines.impl.js";
|
package/dist/repo/db.repo.d.ts
CHANGED
|
@@ -179,7 +179,7 @@ export declare abstract class DbRepo<CONN extends DbConnectionLike, OPT extends
|
|
|
179
179
|
/** {@inheritDoc} */
|
|
180
180
|
buildOpt(p1?: Partial<OPT> | string, name?: string): OPT;
|
|
181
181
|
/** {@inheritDoc} */
|
|
182
|
-
exec<T>(fn: Promise<T>, p1?: string | Omit<OPT,
|
|
182
|
+
exec<T>(fn: Promise<T>, p1?: string | Omit<OPT, "printSql">): Promise<T>;
|
|
183
183
|
/** {@inheritDoc} */
|
|
184
184
|
abstract more<T>(sql: string | DbLines, name?: string | DbExecOpt): Promise<DbQueryResultMore<T, META>>;
|
|
185
185
|
/** {@inheritDoc} */
|