@e-mc/db 0.12.17 → 0.12.18

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 +6 -6
  2. package/index.js +54 -25
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.12.17/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.18/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DbDataSource } from "./squared";
@@ -206,11 +206,11 @@ const [rows1, rows2] = await instance.executeBatchQuery([
206
206
 
207
207
  ## References
208
208
 
209
- - https://www.unpkg.com/@e-mc/types@0.12.17/lib/squared.d.ts
210
- - https://www.unpkg.com/@e-mc/types@0.12.17/lib/core.d.ts
211
- - https://www.unpkg.com/@e-mc/types@0.12.17/lib/db.d.ts
212
- - https://www.unpkg.com/@e-mc/types@0.12.17/lib/http.d.ts
213
- - https://www.unpkg.com/@e-mc/types@0.12.17/lib/settings.d.ts
209
+ - https://www.unpkg.com/@e-mc/types@0.12.18/lib/squared.d.ts
210
+ - https://www.unpkg.com/@e-mc/types@0.12.18/lib/core.d.ts
211
+ - https://www.unpkg.com/@e-mc/types@0.12.18/lib/db.d.ts
212
+ - https://www.unpkg.com/@e-mc/types@0.12.18/lib/http.d.ts
213
+ - https://www.unpkg.com/@e-mc/types@0.12.18/lib/settings.d.ts
214
214
 
215
215
  * https://www.npmjs.com/package/@types/node
216
216
 
package/index.js CHANGED
@@ -90,32 +90,56 @@ class Db extends core_1.ClientDb {
90
90
  }
91
91
  }
92
92
  applyCommand(...items) {
93
- let settings;
93
+ const sourceMap = {};
94
94
  for (let i = 0, length = items.length; i < length; ++i) {
95
95
  const item = items[i];
96
96
  const command = item.withCommand;
97
- if (!command) {
98
- continue;
99
- }
100
- if (!settings && !(0, types_1.isPlainObject)(settings = this.getUserSettings()?.[item.source]?.commands)) {
101
- return;
102
- }
103
- let name, table;
104
- 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]);
105
- const data = settings[group]?.[procedure];
106
- if (!(0, types_1.isPlainObject)(data)) {
107
- continue;
108
- }
109
- if ('uri' in data) {
110
- delete data.uri;
111
- }
112
- if ('credential' in data) {
113
- delete data.credential;
97
+ if (command) {
98
+ const source = item.source;
99
+ const data = sourceMap[source];
100
+ if (!data) {
101
+ const settings = this.getUserSettings()?.[source]?.commands;
102
+ if (settings) {
103
+ sourceMap[source] = [settings, [item]];
104
+ }
105
+ else {
106
+ sourceMap[source] = [null, []];
107
+ }
108
+ }
109
+ else if (data[0]) {
110
+ data[1].push(item);
111
+ }
114
112
  }
115
- if ('usePool' in data) {
116
- delete data.usePool;
113
+ }
114
+ for (const source in sourceMap) {
115
+ const [settings, commands] = sourceMap[source];
116
+ if (settings) {
117
+ for (let i = 0, length = commands.length, group, procedure; i < length; ++i) {
118
+ const item = commands[i];
119
+ const command = item.withCommand;
120
+ if (Array.isArray(command)) {
121
+ [group, procedure] = command;
122
+ }
123
+ else {
124
+ const { name, table } = item;
125
+ group = name && table ? name + ':' + table : table || name || (typeof item.document === 'string' ? item.document : '');
126
+ procedure = command;
127
+ }
128
+ const data = settings[group]?.[procedure];
129
+ if ((0, types_1.isPlainObject)(data)) {
130
+ if ('uri' in data) {
131
+ delete data.uri;
132
+ }
133
+ if ('credential' in data) {
134
+ delete data.credential;
135
+ }
136
+ if ('usePool' in data) {
137
+ delete data.usePool;
138
+ }
139
+ Object.assign(item, data);
140
+ }
141
+ }
117
142
  }
118
- Object.assign(item, data);
119
143
  }
120
144
  }
121
145
  async executeQuery(item, options) {
@@ -137,9 +161,9 @@ class Db extends core_1.ClientDb {
137
161
  return this.getClient(batch[0].source).executeBatchQuery.call(this, batch, options, outResult);
138
162
  }
139
163
  async processRows(batch, tasks, parallel, outResult) {
140
- let disconnect;
164
+ let errorAsEmpty, disconnect;
141
165
  if ((0, types_1.isObject)(parallel)) {
142
- ({ disconnect, parallel } = parallel);
166
+ ({ parallel, errorAsEmpty, disconnect } = parallel);
143
167
  }
144
168
  const terminate = () => {
145
169
  this.applyState(batch, 8);
@@ -155,8 +179,13 @@ class Db extends core_1.ClientDb {
155
179
  this.applyState(batch, 16);
156
180
  terminate();
157
181
  if (outResult) {
158
- for (let i = 0, length = outResult.length; i < length; ++i) {
159
- outResult[i] = null;
182
+ if (errorAsEmpty) {
183
+ outResult.length = 0;
184
+ }
185
+ else {
186
+ for (let i = 0, length = outResult.length; i < length; ++i) {
187
+ outResult[i] = null;
188
+ }
160
189
  }
161
190
  return outResult;
162
191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.12.17",
3
+ "version": "0.12.18",
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": "MIT",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/core": "0.12.17",
23
- "@e-mc/request": "0.12.17",
24
- "@e-mc/types": "0.12.17"
22
+ "@e-mc/core": "0.12.18",
23
+ "@e-mc/request": "0.12.18",
24
+ "@e-mc/types": "0.12.18"
25
25
  }
26
26
  }