@e-mc/db 0.12.9 → 0.13.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.
Files changed (3) hide show
  1. package/README.md +15 -7
  2. package/index.js +18 -12
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @e-mc/db
2
2
 
3
- * NodeJS 18
3
+ * NodeJS 18.20.5 LTS
4
4
  * ES2022
5
5
 
6
6
  ## General Usage
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.9/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.13.1/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DbDataSource } from "./squared";
@@ -45,6 +45,14 @@ interface IDb extends IClientDb<IHost, DbModule, DbDataSource, DbSourceOptions,
45
45
  getPoolConfig(source: string, uuidKey?: string): Required<PoolConfig> | undefined;
46
46
  get sourceType(): DB_TYPE;
47
47
  get commandType(): SQL_COMMAND;
48
+
49
+ /* EventEmitter */
50
+ on(event: "db:result", listener: (batch: DbDataSource[], result: BatchQueryResult) => void): this;
51
+ on(event: "db:fail", listener: (err: unknown, item: DbDataSource) => void): this;
52
+ once(event: "db:result", listener: (batch: DbDataSource[], result: BatchQueryResult) => void): this;
53
+ once(event: "db:fail", listener: (err: unknown, item: DbDataSource) => void): this;
54
+ emit(event: "db:result", batch: DbDataSource[], result: BatchQueryResult): boolean;
55
+ emit(event: "db:fail", err: unknown, item: DbDataSource): boolean;
48
56
  }
49
57
 
50
58
  interface DbConstructor extends ClientDbConstructor<IHost> {
@@ -206,11 +214,11 @@ const [rows1, rows2] = await instance.executeBatchQuery([
206
214
 
207
215
  ## References
208
216
 
209
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/squared.d.ts
210
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/core.d.ts
211
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/db.d.ts
212
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/http.d.ts
213
- - https://www.unpkg.com/@e-mc/types@0.12.9/lib/settings.d.ts
217
+ - https://www.unpkg.com/@e-mc/types@0.13.1/lib/squared.d.ts
218
+ - https://www.unpkg.com/@e-mc/types@0.13.1/lib/core.d.ts
219
+ - https://www.unpkg.com/@e-mc/types@0.13.1/lib/db.d.ts
220
+ - https://www.unpkg.com/@e-mc/types@0.13.1/lib/http.d.ts
221
+ - https://www.unpkg.com/@e-mc/types@0.13.1/lib/settings.d.ts
214
222
 
215
223
  * https://www.npmjs.com/package/@types/node
216
224
 
package/index.js CHANGED
@@ -11,6 +11,7 @@ function sanitizePoolConfig(value) {
11
11
  value.min ??= -1;
12
12
  value.max ??= -1;
13
13
  value.idle ??= -1;
14
+ value.idle_max ??= -1;
14
15
  value.queue_max ??= -1;
15
16
  value.queue_idle ??= -1;
16
17
  value.purge ??= 0;
@@ -100,19 +101,18 @@ class Db extends core_1.ClientDb {
100
101
  let name, table;
101
102
  const [group, procedure] = Array.isArray(command) ? command : ({ name, table } = item, [(name || table ? name && table ? name + ':' + table : table || name : typeof item.document === 'string' && item.document) || '', command]);
102
103
  const data = settings[group]?.[procedure];
103
- if (!(0, types_1.isPlainObject)(data)) {
104
- continue;
105
- }
106
- if ('uri' in data) {
107
- delete data.uri;
108
- }
109
- if ('credential' in data) {
110
- delete data.credential;
111
- }
112
- if ('usePool' in data) {
113
- delete data.usePool;
104
+ if ((0, types_1.isPlainObject)(data)) {
105
+ if ('uri' in data) {
106
+ delete data.uri;
107
+ }
108
+ if ('credential' in data) {
109
+ delete data.credential;
110
+ }
111
+ if ('usePool' in data) {
112
+ delete data.usePool;
113
+ }
114
+ Object.assign(item, data);
114
115
  }
115
- Object.assign(item, data);
116
116
  }
117
117
  }
118
118
  async executeQuery(item, options) {
@@ -164,6 +164,7 @@ class Db extends core_1.ClientDb {
164
164
  }
165
165
  if (!parallel && outResult) {
166
166
  terminate();
167
+ this.emit('db:result', batch, outResult);
167
168
  return outResult;
168
169
  }
169
170
  return Promise.all(tasks)
@@ -179,8 +180,10 @@ class Db extends core_1.ClientDb {
179
180
  for (let i = 0, length = outResult.length; i < length; ++i) {
180
181
  outResult[i] = result[i] || null;
181
182
  }
183
+ this.emit('db:result', batch, outResult);
182
184
  return outResult;
183
185
  }
186
+ this.emit('db:result', batch, result);
184
187
  return result;
185
188
  })
186
189
  .catch(cleanup);
@@ -193,6 +196,7 @@ class Db extends core_1.ClientDb {
193
196
  if (item.willAbort) {
194
197
  this.abort(err);
195
198
  }
199
+ this.emit('db:fail', err, item);
196
200
  return true;
197
201
  }
198
202
  }
@@ -202,6 +206,7 @@ class Db extends core_1.ClientDb {
202
206
  }
203
207
  this.writeFail(["Unable to execute query", item.source], err, 65536);
204
208
  }
209
+ this.emit('db:fail', err, item);
205
210
  return false;
206
211
  }
207
212
  async commit(items) {
@@ -266,6 +271,7 @@ class Db extends core_1.ClientDb {
266
271
  result.min ??= config.min;
267
272
  result.max ??= config.max;
268
273
  result.idle ??= config.idle;
274
+ result.idle_max ??= config.idle_max;
269
275
  result.queue_max ??= config.queue_max;
270
276
  result.queue_idle ??= config.queue_idle;
271
277
  result.timeout ??= config.timeout;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.12.9",
3
+ "version": "0.13.1",
4
4
  "description": "DB modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/core": "0.12.9",
23
- "@e-mc/request": "0.12.9",
24
- "@e-mc/types": "0.12.9"
22
+ "@e-mc/core": "0.13.1",
23
+ "@e-mc/request": "0.13.1",
24
+ "@e-mc/types": "0.13.1"
25
25
  }
26
26
  }