@pi-r/mongodb 0.5.0 → 0.5.2

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 2023 Wit Studio
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,5 +1,7 @@
1
- ### @pi-r/mongodb
1
+ # @pi-r/mongodb
2
2
 
3
- ### LICENSE
3
+ PEP 402 - Forever Vivy
4
+
5
+ ## LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -82,7 +82,7 @@ function setCredential(item) {
82
82
  const options = item.options || (item.options = {});
83
83
  let uri = item.uri;
84
84
  if (credential) {
85
- let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017 /* VALUES.PORT */), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
85
+ let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
86
86
  if (authMechanism === 'GSSAPI') {
87
87
  const principal = auth?.username || username || options.auth?.username;
88
88
  if ((0, types_1.isString)(principal)) {
@@ -97,10 +97,10 @@ function setCredential(item) {
97
97
  authentication = (0, util_1.getBasicAuth)(username, password);
98
98
  }
99
99
  if (!server && hostname) {
100
- server = hostname + ':' + (port || 27017 /* VALUES.PORT */);
100
+ server = hostname + ':' + (port || 27017);
101
101
  }
102
102
  if (!server) {
103
- throw (0, types_1.errorMessage)("mongodb" /* STRINGS.MODULE_NAME */, 'Not defined - server address');
103
+ throw (0, types_1.errorMessage)("mongodb", 'Not defined - server address');
104
104
  }
105
105
  uri = (protocol || 'mongodb:') + '//' + authentication + server;
106
106
  }
@@ -148,7 +148,7 @@ function setCredential(item) {
148
148
  uri += '&tls=true';
149
149
  }
150
150
  else {
151
- throw (0, types_1.errorMessage)("mongodb" /* STRINGS.MODULE_NAME */, 'Missing TLS/SSL credentials');
151
+ throw (0, types_1.errorMessage)("mongodb", 'Missing TLS/SSL credentials');
152
152
  }
153
153
  authSource || (authSource = '$external');
154
154
  break;
@@ -172,7 +172,7 @@ function setCredential(item) {
172
172
  item.uri = uri;
173
173
  }
174
174
  else if (!(0, types_1.isString)(uri)) {
175
- throw (0, types_1.errorMessage)("mongodb" /* STRINGS.MODULE_NAME */, 'Not defined - credentials');
175
+ throw (0, types_1.errorMessage)("mongodb", 'Not defined - credentials');
176
176
  }
177
177
  const usePool = item.usePool;
178
178
  if (usePool) {
@@ -187,7 +187,7 @@ function setCredential(item) {
187
187
  const poolKey = getPoolKey(item);
188
188
  if (poolKey) {
189
189
  if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
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) {
@@ -253,12 +253,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
253
253
  if (!parallel) {
254
254
  outResult || (outResult = new Array(length));
255
255
  }
256
- const caching = this.hasCache("mongodb" /* STRINGS.MODULE_NAME */, sessionKey);
256
+ const caching = this.hasCache("mongodb", sessionKey);
257
257
  const tasks = new Array(length);
258
258
  const clients = [];
259
259
  let mongoClient, mongoCredential, mongoCache = 0, onceCredential = connectOnce ? getCacheObject(batch[0]) : undefined;
260
260
  const getConnection = async (item, credential) => {
261
- item.transactionState = 64 /* DB_TRANSACTION.AUTH */;
261
+ item.transactionState = 64;
262
262
  const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(connectOnce ? batch[0] : item), ...connectOnce ? [item, batch[0]] : [item]);
263
263
  let client;
264
264
  if (pool) {
@@ -286,7 +286,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
286
286
  mongoClient = client;
287
287
  mongoCredential = credential;
288
288
  }
289
- item.transactionState &= ~64 /* DB_TRANSACTION.AUTH */;
289
+ item.transactionState &= ~64;
290
290
  return client;
291
291
  };
292
292
  for (let i = 0; i < length; ++i) {
@@ -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,12 +311,12 @@ 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 getCollection = (target) => target.db(name, client?.db).collection(table, client?.collection);
316
316
  const credential = mongoCredential || onceCredential || getCacheObject(item);
317
317
  const renewCache = ignoreCache === 0;
318
318
  const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
319
- const coercing = this.hasCoerce("mongodb" /* STRINGS.MODULE_NAME */, 'options', credential.uuidKey);
319
+ const coercing = this.hasCoerce("mongodb", 'options', credential.uuidKey);
320
320
  const targetObject = typeof checkObject === 'string' ? coercing && (0, types_1.asFunction)(checkObject) : checkObject;
321
321
  if (typeof streamRow === 'string') {
322
322
  streamRow = coercing && (0, types_1.asFunction)(streamRow);
@@ -342,7 +342,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
342
342
  else {
343
343
  outResult[i] = rows;
344
344
  }
345
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */ | 128 /* DB_TRANSACTION.CACHE */);
345
+ this.add(item, 4 | 128);
346
346
  return true;
347
347
  }
348
348
  return false;
@@ -477,7 +477,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
477
477
  reject(error);
478
478
  }
479
479
  else {
480
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
480
+ this.add(item, 4);
481
481
  resolve(!error ? this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue) : rows);
482
482
  }
483
483
  })
@@ -488,14 +488,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
488
488
  }
489
489
  }
490
490
  if (rows) {
491
- this.add(item, 4 /* DB_TRANSACTION.COMMIT */);
491
+ this.add(item, 4);
492
492
  if (targetObject) {
493
493
  rows = targetObject(item, rows);
494
494
  }
495
495
  resolve(this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue));
496
496
  }
497
497
  else {
498
- throw (0, types_1.errorMessage)(source, "Missing database query" /* ERR_DB.QUERY */);
498
+ throw (0, types_1.errorMessage)(source, "Missing database query");
499
499
  }
500
500
  }
501
501
  catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "MongoDB client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/anpham6/pi-r.git",
12
+ "url": "git+https://github.com/anpham6/pi-r.git",
13
13
  "directory": "src/db/mongodb"
14
14
  },
15
15
  "keywords": [
@@ -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.7.0",
25
- "@e-mc/request": "^0.7.0",
26
- "@e-mc/types": "^0.7.0",
27
- "mongodb": "^6.3.0"
24
+ "@e-mc/db": "^0.7.2",
25
+ "@e-mc/request": "^0.7.2",
26
+ "@e-mc/types": "^0.7.2",
27
+ "mongodb": "^6.4.0"
28
28
  }
29
29
  }