@pi-r/mongodb 0.6.4 → 0.6.5

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,7 +1,10 @@
1
- ### @pi-r/mongodb
1
+ # @pi-r/mongodb
2
2
 
3
- https://e-mc.readthedocs.io/en/latest/db/mongodb.html
3
+ ## Documentation
4
4
 
5
- ### LICENSE
5
+ - [E-mc](https://e-mc.readthedocs.io/en/latest/db/mongodb.html)
6
+ - [squared](https://squared.readthedocs.io)
7
+
8
+ ## LICENSE
6
9
 
7
10
  MIT
package/client/index.js CHANGED
@@ -80,7 +80,7 @@ function setCredential(item) {
80
80
  const options = item.options || (item.options = {});
81
81
  let uri = item.uri;
82
82
  if (credential) {
83
- let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017 /* VALUES.PORT */), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
83
+ let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
84
84
  if (authMechanism === 'GSSAPI') {
85
85
  const principal = auth?.username || username || options.auth?.username;
86
86
  if ((0, types_1.isString)(principal)) {
@@ -95,10 +95,10 @@ function setCredential(item) {
95
95
  authentication = (0, util_1.getBasicAuth)(username, password);
96
96
  }
97
97
  if (!server && hostname) {
98
- server = hostname + ':' + (port || 27017 /* VALUES.PORT */);
98
+ server = hostname + ':' + (port || 27017);
99
99
  }
100
100
  if (!server) {
101
- throw (0, types_1.errorMessage)("mongodb" /* STRINGS.MODULE_NAME */, 'Not defined - server address');
101
+ throw (0, types_1.errorMessage)("mongodb", 'Not defined - server address');
102
102
  }
103
103
  uri = (protocol || 'mongodb:') + '//' + authentication + server;
104
104
  }
@@ -143,7 +143,7 @@ function setCredential(item) {
143
143
  uri += '&tls=true';
144
144
  }
145
145
  else {
146
- throw (0, types_1.errorMessage)("mongodb" /* STRINGS.MODULE_NAME */, 'Missing TLS/SSL credentials');
146
+ throw (0, types_1.errorMessage)("mongodb", 'Missing TLS/SSL credentials');
147
147
  }
148
148
  authSource || (authSource = '$external');
149
149
  break;
@@ -167,7 +167,7 @@ function setCredential(item) {
167
167
  item.uri = uri;
168
168
  }
169
169
  else if (!(0, types_1.isString)(uri)) {
170
- throw (0, types_1.errorMessage)("mongodb" /* STRINGS.MODULE_NAME */, 'Not defined - credentials');
170
+ throw (0, types_1.errorMessage)("mongodb", 'Not defined - credentials');
171
171
  }
172
172
  const usePool = item.usePool;
173
173
  if (!usePool) {
@@ -187,7 +187,7 @@ function setCredential(item) {
187
187
  return;
188
188
  }
189
189
  }
190
- const config = this.getPoolConfig("mongodb" /* STRINGS.MODULE_NAME */, password);
190
+ const config = this.getPoolConfig("mongodb", password);
191
191
  if (config) {
192
192
  const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
193
193
  if (min >= 0) {
@@ -249,12 +249,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
249
249
  if (!parallel) {
250
250
  outResult || (outResult = new Array(length));
251
251
  }
252
- const caching = this.hasCache("mongodb" /* STRINGS.MODULE_NAME */, sessionKey);
252
+ const caching = this.hasCache("mongodb", sessionKey);
253
253
  const tasks = new Array(length);
254
254
  const clients = [];
255
255
  let mongoClient, mongoCredential, mongoCache = 0, onceCredential = connectOnce ? getCacheObject(batch[0]) : undefined;
256
256
  const getConnection = async (item, credential) => {
257
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
257
+ item.transactionState = 64;
258
258
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(connectOnce ? batch[0] : item), ...connectOnce ? [item, batch[0]] : [item]);
259
259
  let client;
260
260
  if (pool) {
@@ -283,7 +283,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
283
283
  mongoClient = client;
284
284
  mongoCredential = credential;
285
285
  }
286
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
286
+ item.transactionState &= ~64;
287
287
  return client;
288
288
  };
289
289
  if (this.host?.username) {
@@ -294,7 +294,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
294
294
  const { source, name, table, id, aggregate, sort, client, cacheObjectKey, ignoreCache } = item;
295
295
  let { query, update, streamRow, limit = 0 } = item;
296
296
  if (!table) {
297
- const error = (0, types_1.errorMessage)(source, "Missing database table" /* ERR_DB.TABLE */);
297
+ const error = (0, types_1.errorMessage)(source, "Missing database table");
298
298
  ++mongoCache;
299
299
  if (this.handleFail(error, item, { errorQuery })) {
300
300
  if (!parallel) {
@@ -311,13 +311,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
311
311
  }
312
312
  continue;
313
313
  }
314
- item.transactionState = 1 /* DB_TRANSACTION.ACTIVE */;
314
+ item.transactionState = 1;
315
315
  const getInstance = (target) => target.db(name, client?.db);
316
316
  const getCollection = (target) => getInstance(target).collection(table, client?.collection);
317
317
  const runCommand = async (target, document) => getInstance(target).command(document, client?.command);
318
318
  const credential = mongoCredential || onceCredential || getCacheObject(item);
319
319
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
320
- const coercing = this.hasCoerce("mongodb" /* STRINGS.MODULE_NAME */, 'options', credential.uuidKey);
320
+ const coercing = this.hasCoerce("mongodb", 'options', credential.uuidKey);
321
321
  const targetObject = typeof checkObject === 'string' ? coercing && (0, types_1.asFunction)(checkObject) : checkObject;
322
322
  if (typeof streamRow === 'string') {
323
323
  streamRow = coercing && (0, types_1.asFunction)(streamRow);
@@ -343,7 +343,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
343
343
  else {
344
344
  outResult[i] = rows;
345
345
  }
346
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
346
+ this.add(item, 4 | 128);
347
347
  return true;
348
348
  }
349
349
  return false;
@@ -378,7 +378,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
378
378
  const command = item.command;
379
379
  if (command) {
380
380
  await Promise.all((!Array.isArray(command) ? [command] : command).map(async (cmd) => runCommand(instance, cmd)))
381
- .then(items => items.forEach(output => this.addLog(this.statusType.INFO, output, "mongodb" /* STRINGS.MODULE_NAME */, 'runCommand')));
381
+ .then(items => items.forEach(output => this.addLog(this.statusType.INFO, output, "mongodb", 'runCommand')));
382
382
  }
383
383
  const collection = getCollection(instance);
384
384
  if (update && coercing) {
@@ -482,7 +482,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
482
482
  reject(error);
483
483
  }
484
484
  else {
485
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
485
+ this.add(item, 4);
486
486
  resolve(!error ? this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue) : rows);
487
487
  }
488
488
  })
@@ -493,14 +493,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
493
493
  }
494
494
  }
495
495
  if (rows) {
496
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
496
+ this.add(item, 4);
497
497
  if (targetObject) {
498
498
  rows = targetObject(item, rows);
499
499
  }
500
500
  resolve(this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue));
501
501
  }
502
502
  else {
503
- throw (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */);
503
+ throw (0, types_1.errorMessage)(source, "Missing database query");
504
504
  }
505
505
  }
506
506
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "description": "MongoDB client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -21,9 +21,9 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/db": "^0.8.4",
25
- "@e-mc/request": "^0.8.4",
26
- "@e-mc/types": "^0.8.4",
27
- "mongodb": "^6.3.0"
24
+ "@e-mc/db": "^0.8.6",
25
+ "@e-mc/request": "^0.8.6",
26
+ "@e-mc/types": "^0.8.6",
27
+ "mongodb": "^6.4.0"
28
28
  }
29
29
  }