@pi-r/atlas 0.2.3 → 0.3.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 (2) hide show
  1. package/client/index.js +7 -14
  2. package/package.json +7 -7
package/client/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getObjectId = exports.executeBatchQuery = exports.executeQuery = exports.createDatabaseClient = exports.validateDatabase = void 0;
4
+ const mongodb = require("mongodb");
4
5
  const types_1 = require("@e-mc/types");
5
6
  const util_1 = require("@e-mc/cloud/util");
6
7
  const mongodb_1 = require("@pi-r/mongodb");
@@ -11,7 +12,7 @@ function sanitizeCredentials(item, credential) {
11
12
  if (username) {
12
13
  const auth = password ? { username, password } : { username };
13
14
  if (MONGODB_V3) {
14
- credential.auth = password || !credential.auth || !credential.auth.password ? auth : credential.auth;
15
+ credential.auth = password || !credential.auth?.password ? auth : credential.auth;
15
16
  }
16
17
  else {
17
18
  credential.auth || (credential.auth = auth);
@@ -25,8 +26,8 @@ function sanitizeCredentials(item, credential) {
25
26
  if (!(0, util_1.hasBasicAuth)(item.uri)) {
26
27
  const auth = (0, util_1.getBasicAuth)(credential.auth);
27
28
  if (auth) {
28
- const url = item.uri.split('://');
29
- item.uri = url[0] + '://' + auth + url[1];
29
+ const [protocol, hostname] = item.uri.split('://');
30
+ item.uri = protocol + '://' + auth + hostname;
30
31
  }
31
32
  }
32
33
  delete credential.auth;
@@ -38,15 +39,8 @@ function validateDatabase(credential, data) {
38
39
  }
39
40
  exports.validateDatabase = validateDatabase;
40
41
  function createDatabaseClient(credential, data) {
41
- try {
42
- sanitizeCredentials(data, credential);
43
- const { MongoClient } = require('mongodb');
44
- return new MongoClient(data.uri, credential);
45
- }
46
- catch (err) {
47
- this.checkPackage(err, 'mongodb', { passThrough: true });
48
- throw err;
49
- }
42
+ sanitizeCredentials(data, credential);
43
+ return new mongodb.MongoClient(data.uri, credential);
50
44
  }
51
45
  exports.createDatabaseClient = createDatabaseClient;
52
46
  async function executeQuery(credential, data, sessionKey) {
@@ -194,7 +188,6 @@ async function executeBatchQuery(credential, batch, sessionKey) {
194
188
  }
195
189
  exports.executeBatchQuery = executeBatchQuery;
196
190
  function getObjectId(value) {
197
- const { ObjectId } = require('mongodb');
198
- return { '_id': new ObjectId(value) };
191
+ return { '_id': new mongodb.ObjectId(value) };
199
192
  }
200
193
  exports.getObjectId = getObjectId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/atlas",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "description": "MongoDB Atlas cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -20,11 +20,11 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.5.3",
24
- "@e-mc/db": "^0.5.3",
25
- "@e-mc/module": "^0.5.3",
26
- "@e-mc/types": "^0.5.3",
27
- "@pi-r/mongodb": "^0.2.3",
28
- "mongodb": "^5.7.0"
23
+ "@e-mc/cloud": "^0.6.0",
24
+ "@e-mc/db": "^0.6.0",
25
+ "@e-mc/module": "^0.6.0",
26
+ "@e-mc/types": "^0.6.0",
27
+ "@pi-r/mongodb": "^0.3.1",
28
+ "mongodb": "^5.9.1"
29
29
  }
30
30
  }