@e-mc/db 0.0.1 → 0.0.3

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/index.js CHANGED
@@ -120,7 +120,7 @@ class Db extends core_1.ClientDb {
120
120
  ({ disconnect, parallel } = parallel);
121
121
  }
122
122
  const terminate = () => {
123
- this.applyState(batch, 8 /* TRANSACTION.TERMINATE */);
123
+ this.applyState(batch, 8 /* TRANSACTION_DB.TERMINATE */);
124
124
  if (typeof disconnect === 'function') {
125
125
  try {
126
126
  disconnect();
@@ -130,7 +130,7 @@ class Db extends core_1.ClientDb {
130
130
  }
131
131
  };
132
132
  const cleanup = () => {
133
- this.applyState(batch, 16 /* TRANSACTION.ABORT */);
133
+ this.applyState(batch, 16 /* TRANSACTION_DB.ABORT */);
134
134
  terminate();
135
135
  if (outResult) {
136
136
  for (let i = 0, length = outResult.length; i < length; ++i) {
@@ -161,7 +161,7 @@ class Db extends core_1.ClientDb {
161
161
  .catch(() => cleanup());
162
162
  }
163
163
  handleFail(err, item, options) {
164
- this.add(item, 32 /* TRANSACTION.FAIL */);
164
+ this.add(item, 32 /* TRANSACTION_DB.FAIL */);
165
165
  item.transactionFail = true;
166
166
  if (options && typeof options.errorQuery === 'function') {
167
167
  if (options.errorQuery(err, item, options.commandType)) {
@@ -186,11 +186,11 @@ class Db extends core_1.ClientDb {
186
186
  const tasks = (items || this.pending).map(data => {
187
187
  data.ignoreCache ?? (data.ignoreCache = true);
188
188
  return this.executeQuery(data).catch(() => {
189
- this.applyState([data], 16 /* TRANSACTION.ABORT */);
189
+ this.applyState([data], 16 /* TRANSACTION_DB.ABORT */);
190
190
  return [];
191
191
  });
192
192
  });
193
- return tasks.length === 0 ? Promise.resolve(false) : this.allSettled(tasks, ["Execute unassigned queries" /* CMD_DB.EXEC_QUERYUNASSIGNED */, this.moduleName]).then(result => result.length > 0).catch(() => false);
193
+ return tasks.length === 0 ? Promise.resolve(false) : this.allSettled(tasks, ["Execute unassigned queries" /* VAL_DB.EXEC_QUERYUNASSIGNED */, this.moduleName]).then(result => result.length > 0).catch(() => false);
194
194
  }
195
195
  readTLSCert(value, cache) {
196
196
  if ((0, types_1.isString)(value)) {
@@ -1,18 +1,11 @@
1
- import type { MongoDBDataSource, MongoDBSortValue } from '../../types/lib/db';
1
+ import type { MongoDBDataSource, MongoDBFilterValue, MongoDBSortValue } from '../../types/lib/db';
2
2
 
3
3
  import type { IDbSourceClient } from '../types';
4
4
 
5
5
  import type { CommandOperationOptions, Document, Filter, Sort, SortDirection } from 'mongodb';
6
6
 
7
- interface DocumentFilterValue {
8
- value?: DocumentFilter;
9
- options?: CommandOperationOptions;
10
- }
11
-
12
- type DocumentFilter = Filter<Document>;
13
-
14
7
  declare const MongoDB: IDbSourceClient<MongoDBDataSource> & {
15
- getFilterValue: (query: DocumentFilter | DocumentFilterValue, coerce?: boolean) => [DocumentFilter, CommandOperationOptions?];
8
+ getFilterValue: (query: Filter<Document> | MongoDBFilterValue, coerce?: boolean) => [Filter<Document>, CommandOperationOptions?];
16
9
  getSortValue: (sort: Sort | string | MongoDBSortValue, coerce?: boolean) => [Sort | string, SortDirection?];
17
10
  };
18
11
 
package/mongodb/index.js CHANGED
@@ -382,7 +382,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
382
382
  const clients = [];
383
383
  let mongoClient, mongoCredential, mongoCache = 0, onceCredential = connectOnce ? getCacheObject(batch[0]) : undefined;
384
384
  const getConnection = async (item, credential) => {
385
- item.transactionState = 64 /* TRANSACTION.AUTH */;
385
+ item.transactionState = 64 /* TRANSACTION_DB.AUTH */;
386
386
  const pool = item.usePool && pool_1.default.findKey(POOL_STATE, item.usePool, getPoolKey(connectOnce ? batch[0] : item), ...connectOnce ? [item, batch[0]] : [item]);
387
387
  let client;
388
388
  if (pool) {
@@ -410,7 +410,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
410
410
  mongoClient = client;
411
411
  mongoCredential = credential;
412
412
  }
413
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
413
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
414
414
  return client;
415
415
  };
416
416
  for (let i = 0; i < length; ++i) {
@@ -435,7 +435,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
435
435
  }
436
436
  continue;
437
437
  }
438
- item.transactionState = 1 /* TRANSACTION.ACTIVE */;
438
+ item.transactionState = 1 /* TRANSACTION_DB.ACTIVE */;
439
439
  const getCollection = (target) => target.db(name, client?.db).collection(table, client?.collection);
440
440
  const credential = mongoCredential || onceCredential || getCacheObject(item);
441
441
  const renewCache = ignoreCache === 0;
@@ -466,7 +466,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
466
466
  else {
467
467
  outResult[i] = rows;
468
468
  }
469
- this.add(item, 4 /* TRANSACTION.COMMIT */ | 128 /* TRANSACTION.CACHE */);
469
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */ | 128 /* TRANSACTION_DB.CACHE */);
470
470
  return true;
471
471
  }
472
472
  return false;
@@ -594,7 +594,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
594
594
  reject(error);
595
595
  }
596
596
  else {
597
- this.add(item, 4 /* TRANSACTION.COMMIT */);
597
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
598
598
  resolve(!error ? this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue) : rows);
599
599
  }
600
600
  })
@@ -605,7 +605,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
605
605
  }
606
606
  }
607
607
  if (rows) {
608
- this.add(item, 4 /* TRANSACTION.COMMIT */);
608
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
609
609
  if (targetObject) {
610
610
  rows = targetObject(item, rows);
611
611
  }
package/mssql/index.js CHANGED
@@ -261,11 +261,11 @@ async function executeBatchQuery(batch, options = '', outResult) {
261
261
  const pools = [];
262
262
  let mssqlPool, mssqlClient, mssqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
263
263
  const getConnection = async (item, credential) => {
264
- item.transactionState = 64 /* TRANSACTION.AUTH */;
264
+ item.transactionState = 64 /* TRANSACTION_DB.AUTH */;
265
265
  let client;
266
266
  if (mssqlPool) {
267
267
  pools.push(client = await mssqlPool.getConnection());
268
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
268
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
269
269
  return client;
270
270
  }
271
271
  const pool = item.usePool && pool_1.default.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -317,7 +317,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
317
317
  }
318
318
  mssqlCredential = credential;
319
319
  }
320
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
320
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
321
321
  return client;
322
322
  };
323
323
  for (let i = 0; i < length; ++i) {
@@ -340,7 +340,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
340
340
  }
341
341
  continue;
342
342
  }
343
- item.transactionState = 1 /* TRANSACTION.ACTIVE */;
343
+ item.transactionState = 1 /* TRANSACTION_DB.ACTIVE */;
344
344
  const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("mssql" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
345
345
  const renewCache = ignoreCache === 0;
346
346
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
@@ -356,7 +356,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
356
356
  else {
357
357
  outResult[i] = result;
358
358
  }
359
- this.add(item, 4 /* TRANSACTION.COMMIT */ | 128 /* TRANSACTION.CACHE */);
359
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */ | 128 /* TRANSACTION_DB.CACHE */);
360
360
  continue;
361
361
  }
362
362
  if (!ignoreCache && outCacheMiss) {
@@ -390,7 +390,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
390
390
  reject(error);
391
391
  }
392
392
  else {
393
- this.add(item, 4 /* TRANSACTION.COMMIT */);
393
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
394
394
  if (output) {
395
395
  output['__recordset__'] = 0;
396
396
  output['__returnvalue__'] = true;
package/mysql/index.js CHANGED
@@ -133,11 +133,11 @@ async function executeBatchQuery(batch, options = '', outResult) {
133
133
  const pools = [];
134
134
  let mysqlPool, mysqlClient, mysqlCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
135
135
  const getConnection = async (item, credential) => {
136
- item.transactionState = 64 /* TRANSACTION.AUTH */;
136
+ item.transactionState = 64 /* TRANSACTION_DB.AUTH */;
137
137
  let client;
138
138
  if (mysqlPool) {
139
139
  pools.push(client = await mysqlPool.getConnection());
140
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
140
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
141
141
  return client;
142
142
  }
143
143
  const pool = item.usePool && pool_1.default.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -177,7 +177,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
177
177
  }
178
178
  mysqlCredential = credential;
179
179
  }
180
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
180
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
181
181
  return client;
182
182
  };
183
183
  for (let i = 0, mysql2Client, mysql2Credential; i < length; ++i) {
@@ -210,7 +210,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
210
210
  }
211
211
  continue;
212
212
  }
213
- item.transactionState = 1 /* TRANSACTION.ACTIVE */;
213
+ item.transactionState = 1 /* TRANSACTION_DB.ACTIVE */;
214
214
  const renewCache = ignoreCache === 0;
215
215
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
216
216
  let queryString = '';
@@ -225,7 +225,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
225
225
  else {
226
226
  outResult[i] = result;
227
227
  }
228
- this.add(item, 4 /* TRANSACTION.COMMIT */ | 128 /* TRANSACTION.CACHE */);
228
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */ | 128 /* TRANSACTION_DB.CACHE */);
229
229
  continue;
230
230
  }
231
231
  if (!ignoreCache && outCacheMiss) {
@@ -280,7 +280,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
280
280
  reject(error);
281
281
  }
282
282
  else {
283
- this.add(item, 4 /* TRANSACTION.COMMIT */);
283
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
284
284
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
285
285
  }
286
286
  });
@@ -292,7 +292,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
292
292
  }
293
293
  commandType = this.commandType.SELECT;
294
294
  const [rows] = await client.query(query, params);
295
- this.add(item, 4 /* TRANSACTION.COMMIT */);
295
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
296
296
  resolve(Array.isArray(rows) && !rows.some(row => row.constructor.name === 'OkPacket') ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
297
297
  }
298
298
  }
package/oracle/index.js CHANGED
@@ -181,11 +181,11 @@ async function executeBatchQuery(batch, options = '', outResult) {
181
181
  const clients = [];
182
182
  let oraclePool, oracleClient, oracleCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
183
183
  const getConnection = async (item, credential) => {
184
- item.transactionState = 64 /* TRANSACTION.AUTH */;
184
+ item.transactionState = 64 /* TRANSACTION_DB.AUTH */;
185
185
  let client;
186
186
  if (oraclePool) {
187
187
  clients.push(client = await oraclePool.getConnection());
188
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
188
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
189
189
  return client;
190
190
  }
191
191
  const pool = item.usePool && pool_1.default.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -223,7 +223,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
223
223
  }
224
224
  oracleCredential = credential;
225
225
  }
226
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
226
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
227
227
  return client;
228
228
  };
229
229
  for (let i = 0; i < length; ++i) {
@@ -246,7 +246,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
246
246
  }
247
247
  continue;
248
248
  }
249
- item.transactionState = 1 /* TRANSACTION.ACTIVE */;
249
+ item.transactionState = 1 /* TRANSACTION_DB.ACTIVE */;
250
250
  const streamRow = typeof item.streamRow === 'string' ? this.hasCoerce("oracle" /* STRINGS.MODULE_NAME */, 'options', null, credential) && (0, types_1.asFunction)(item.streamRow) : item.streamRow;
251
251
  const renewCache = ignoreCache === 0;
252
252
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
@@ -262,7 +262,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
262
262
  else {
263
263
  outResult[i] = result;
264
264
  }
265
- this.add(item, 4 /* TRANSACTION.COMMIT */ | 128 /* TRANSACTION.CACHE */);
265
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */ | 128 /* TRANSACTION_DB.CACHE */);
266
266
  continue;
267
267
  }
268
268
  if (!ignoreCache && outCacheMiss) {
@@ -313,7 +313,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
313
313
  reject(error);
314
314
  }
315
315
  else {
316
- this.add(item, 4 /* TRANSACTION.COMMIT */);
316
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
317
317
  resolve(!error ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : rows);
318
318
  }
319
319
  })
@@ -321,7 +321,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
321
321
  }
322
322
  else {
323
323
  const { rows } = await client.execute(query, params || [], executeOptions);
324
- this.add(item, 4 /* TRANSACTION.COMMIT */);
324
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
325
325
  resolve(rows ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
326
326
  }
327
327
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@e-mc/db",
3
- "version": "0.0.1",
4
- "description": "DB modules for e-mc.",
3
+ "version": "0.0.3",
4
+ "description": "DB modules for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "publishConfig": {
@@ -20,7 +20,7 @@
20
20
  "license": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.0.1",
24
- "@e-mc/request": "0.0.1"
23
+ "@e-mc/core": "0.0.3",
24
+ "@e-mc/request": "0.0.3"
25
25
  }
26
26
  }
package/postgres/index.js CHANGED
@@ -122,11 +122,11 @@ async function executeBatchQuery(batch, options = '', outResult) {
122
122
  const pools = [];
123
123
  let postgresPool, postgresClient, postgresCredential, onceCredential = connectOnce ? batch[0].credential : undefined;
124
124
  const getConnection = async (item, credential) => {
125
- item.transactionState = 64 /* TRANSACTION.AUTH */;
125
+ item.transactionState = 64 /* TRANSACTION_DB.AUTH */;
126
126
  let client;
127
127
  if (postgresPool) {
128
128
  pools.push(client = await postgresPool.getConnection());
129
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
129
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
130
130
  return client;
131
131
  }
132
132
  const pool = item.usePool && pool_1.default.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -168,7 +168,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
168
168
  }
169
169
  postgresCredential = credential;
170
170
  }
171
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
171
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
172
172
  return client;
173
173
  };
174
174
  for (let i = 0; i < length; ++i) {
@@ -191,7 +191,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
191
191
  }
192
192
  continue;
193
193
  }
194
- item.transactionState = 1 /* TRANSACTION.ACTIVE */;
194
+ item.transactionState = 1 /* TRANSACTION_DB.ACTIVE */;
195
195
  const renewCache = ignoreCache === 0;
196
196
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
197
197
  let queryString = '';
@@ -206,7 +206,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
206
206
  else {
207
207
  outResult[i] = result;
208
208
  }
209
- this.add(item, 4 /* TRANSACTION.COMMIT */ | 128 /* TRANSACTION.CACHE */);
209
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */ | 128 /* TRANSACTION_DB.CACHE */);
210
210
  continue;
211
211
  }
212
212
  if (!ignoreCache && outCacheMiss) {
@@ -233,7 +233,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
233
233
  }
234
234
  commandType = this.commandType.SELECT;
235
235
  const { rows, command } = await client.query(query, params);
236
- this.add(item, 4 /* TRANSACTION.COMMIT */);
236
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
237
237
  resolve(rows.length || command === 'SELECT' ? this.setQueryResult(source, removePoolProperties(credential), queryString, rows, cacheValue) : null);
238
238
  }
239
239
  catch (err) {
package/redis/index.js CHANGED
@@ -177,7 +177,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
177
177
  const clients = [];
178
178
  let redisClient, redisCredential, redisCache = 0, onceCredential = connectOnce ? batch[0].options?.client : undefined;
179
179
  const getConnection = async (item, credential) => {
180
- item.transactionState = 64 /* TRANSACTION.AUTH */;
180
+ item.transactionState = 64 /* TRANSACTION_DB.AUTH */;
181
181
  let client;
182
182
  if (item.usePool) {
183
183
  const pool = pool_1.default.findKey(POOL_STATE, item.usePool, getPoolKey(credential), ...connectOnce ? [item, batch[0]] : [item]);
@@ -199,7 +199,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
199
199
  redisClient = client;
200
200
  redisCredential = credential;
201
201
  }
202
- item.transactionState &= ~64 /* TRANSACTION.AUTH */;
202
+ item.transactionState &= ~64 /* TRANSACTION_DB.AUTH */;
203
203
  return client;
204
204
  };
205
205
  for (let i = 0; i < length; ++i) {
@@ -223,7 +223,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
223
223
  }
224
224
  continue;
225
225
  }
226
- item.transactionState = 1 /* TRANSACTION.ACTIVE */;
226
+ item.transactionState = 1 /* TRANSACTION_DB.ACTIVE */;
227
227
  const uuidKey = (credential.uuidKey || (credential.uuidKey = (onceCredential ? batch[0] : item).credential?.uuidKey));
228
228
  const targetObject = typeof checkObject === 'string' ? this.hasCoerce("redis" /* STRINGS.MODULE_NAME */, 'options', uuidKey) && (0, types_1.asFunction)(checkObject) : checkObject;
229
229
  const renewCache = ignoreCache === 0;
@@ -252,7 +252,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
252
252
  else {
253
253
  outResult[i] = rows;
254
254
  }
255
- this.add(item, 4 /* TRANSACTION.COMMIT */ | 128 /* TRANSACTION.CACHE */);
255
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */ | 128 /* TRANSACTION_DB.CACHE */);
256
256
  continue;
257
257
  }
258
258
  if (!ignoreCache && outCacheMiss) {
@@ -502,7 +502,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
502
502
  if (rows === undefined) {
503
503
  throw (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */);
504
504
  }
505
- this.add(item, 4 /* TRANSACTION.COMMIT */);
505
+ this.add(item, 4 /* TRANSACTION_DB.COMMIT */);
506
506
  resolve(this.setQueryResult(source, removePoolProperties(redisCredential || credential), queryString, rows, cacheValue));
507
507
  }
508
508
  catch (err) {