@samet-it/be-db-common 1.3.6 → 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.
@@ -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 !== 'function') {
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().then().catch(e => {
72
- this.logger.warn(errorCommon.text(e, 'on', name));
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().then().catch(e => {
90
- this.logger.warn(errorCommon.text(e, 'trigger', 'on', name));
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('connected', this._onConnected, fn, false);
132
+ this._on("connected", this._onConnected, fn, false);
129
133
  }
130
134
  /** {@inheritDoc} */
131
135
  onDisconnected(fn) {
132
- this._on('disconnected', this._onDisconnected, fn, false);
136
+ this._on("disconnected", this._onDisconnected, fn, false);
133
137
  }
134
138
  /** {@inheritDoc} */
135
139
  onFirstConnected(fn) {
136
- this._on('first-connected', this._onFirstConnected, fn, true);
140
+ this._on("first-connected", this._onFirstConnected, fn, true);
137
141
  }
138
142
  // endregion callback
139
143
  /**
@@ -1,2 +1,2 @@
1
- export * from './index.types.js';
2
- export * from './db.connection.js';
1
+ export * from "./index.types.js";
2
+ export * from "./db.connection.js";
@@ -1,2 +1,2 @@
1
- export * from './index.types.js';
2
- export * from './db.connection.js';
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 = 'connected' | 'disconnected' | 'first-connected';
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 + ' : ' : ''}<${err.name}> ${err.message}`, { ...params, sql, queryName: name });
14
+ super(`${name ? name + " : " : ""}<${err.name}> ${err.message}`, {
15
+ ...params,
16
+ sql,
17
+ queryName: name,
18
+ });
15
19
  }
16
20
  }
@@ -1,4 +1,4 @@
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';
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";
@@ -1,4 +1,4 @@
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';
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 './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';
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";
@@ -1 +1 @@
1
- export declare const foretell_sametDbCommon: any[];
1
+ export declare const foretell_sametDbCommon: (() => void)[];
@@ -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, 'DbError', import('./error/db.error.js').then(m => m.DbError), { i18n: true, emit: true }),
10
- () => errorPool.lazy(FQN, 'DbExecuteError', import('./error/db-execute.error.js').then(m => m.DbExecuteError), { i18n: true, emit: true }),
11
- () => errorPool.lazy(FQN, 'DbInvalidValueError', import('./error/db-invalid-value.error.js').then(m => m.DbInvalidValueError), { i18n: true, emit: true }),
12
- () => errorPool.lazy(FQN, 'DbNotSupportedError', import('./error/db-not-supported.error.js').then(m => m.DbNotSupportedError), { i18n: true, emit: true }),
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 './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';
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";
@@ -7,6 +7,6 @@ export const loader_sametDbCommon = defineLoader(FQN,
7
7
  // dependencies
8
8
  ...loader_sametBaseCommon, ...loader_sametCacheCommon,
9
9
  // errors
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),
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('./repo/db.repo.js').then(m => m.DbRepo), () => import('./connection/db.connection.js').then(m => m.DbConnection));
12
+ () => import("./repo/db.repo.js").then((m) => m.DbRepo), () => import("./connection/db.connection.js").then((m) => m.DbConnection));
@@ -1 +1 @@
1
- export declare const NME: string, FQN: string, VER: string, CNF: import("@samet-it/be-base-common").LeyyoConfig;
1
+ export declare const NME: string, FQN: string, VER: string;
package/dist/internal.js CHANGED
@@ -1,2 +1,3 @@
1
- import { sysAll } from '@samet-it/be-base-common';
2
- export const { pck: { name: NME, fqn: FQN, version: VER }, config: CNF } = sysAll(import.meta.url);
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
- switch (typeof item) {
20
- case "string":
21
- const str = item.trim();
22
- return str ? str : undefined;
23
- default:
24
- return undefined;
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 !== 'string') {
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 !== 'string') {
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 !== 'string') {
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 (!['string', 'function'].includes(type)) {
74
- assertFunction(yes, { field: 'yes', method: 'both' });
73
+ if (!["string", "function"].includes(type)) {
74
+ assertFunction(yes, { field: "yes", method: "both" });
75
75
  }
76
- this.add((typeof yes === 'function') ? yes() : yes);
76
+ this.add(typeof yes === "function" ? yes() : yes);
77
77
  }
78
78
  else {
79
79
  const type = typeof no;
80
- if (!['string', 'function'].includes(type)) {
81
- assertFunction(no, { field: 'no', method: 'both' });
80
+ if (!["string", "function"].includes(type)) {
81
+ assertFunction(no, { field: "no", method: "both" });
82
82
  }
83
- this.add((typeof no === 'function') ? no() : no);
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 (!['string', 'function'].includes(type)) {
92
- assertFunction(yes, { field: 'yes', method: 'yes' });
91
+ if (!["string", "function"].includes(type)) {
92
+ assertFunction(yes, { field: "yes", method: "yes" });
93
93
  }
94
- this.add((typeof yes === 'function') ? yes() : yes);
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 (!['string', 'function'].includes(type)) {
103
- assertFunction(no, { field: 'no', method: 'no' });
102
+ if (!["string", "function"].includes(type)) {
103
+ assertFunction(no, { field: "no", method: "no" });
104
104
  }
105
- this.add((typeof no === 'function') ? no() : no);
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('\n');
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() {
@@ -1,2 +1,2 @@
1
- export * from './index.types.js';
2
- export * from './db-lines.impl.js';
1
+ export * from "./index.types.js";
2
+ export * from "./db-lines.impl.js";
@@ -1,2 +1,2 @@
1
- export * from './index.types.js';
2
- export * from './db-lines.impl.js';
1
+ export * from "./index.types.js";
2
+ export * from "./db-lines.impl.js";
@@ -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, 'printSql'>): Promise<T>;
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} */