@pi-r/atlas 0.3.5 → 0.3.6

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,7 +1,7 @@
1
- Copyright 2024 An Pham
2
-
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
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
1
+ Copyright 2023 An Pham
2
+
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
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
7
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,5 @@
1
- # @pi-r/atlas
2
-
3
- PEP 402 - Forever
4
-
5
- ## LICENSE
6
-
1
+ # @pi-r/atlas
2
+
3
+ ## LICENSE
4
+
7
5
  MIT
package/client/index.js CHANGED
@@ -1,19 +1,17 @@
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");
5
4
  const types_1 = require("@e-mc/types");
6
5
  const util_1 = require("@e-mc/cloud/util");
7
6
  const mongodb_1 = require("@pi-r/mongodb");
8
7
  const Module = require("@e-mc/module");
9
8
  const MONGODB_V3 = Module.checkSemVer('mongodb', 1, 4);
10
9
  function sanitizeCredentials(item, credential) {
11
- var _a;
12
10
  const { username, password } = credential;
13
11
  if (username) {
14
12
  const auth = password ? { username, password } : { username };
15
13
  if (MONGODB_V3) {
16
- credential.auth = password || !((_a = credential.auth) === null || _a === void 0 ? void 0 : _a.password) ? auth : credential.auth;
14
+ credential.auth = password || !credential.auth || !credential.auth.password ? auth : credential.auth;
17
15
  }
18
16
  else {
19
17
  credential.auth || (credential.auth = auth);
@@ -27,8 +25,8 @@ function sanitizeCredentials(item, credential) {
27
25
  if (!(0, util_1.hasBasicAuth)(item.uri)) {
28
26
  const auth = (0, util_1.getBasicAuth)(credential.auth);
29
27
  if (auth) {
30
- const [protocol, hostname] = item.uri.split('://');
31
- item.uri = protocol + '://' + auth + hostname;
28
+ const url = item.uri.split('://');
29
+ item.uri = url[0] + '://' + auth + url[1];
32
30
  }
33
31
  }
34
32
  delete credential.auth;
@@ -40,8 +38,15 @@ function validateDatabase(credential, data) {
40
38
  }
41
39
  exports.validateDatabase = validateDatabase;
42
40
  function createDatabaseClient(credential, data) {
43
- sanitizeCredentials(data, credential);
44
- return new mongodb.MongoClient(data.uri, credential);
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
+ }
45
50
  }
46
51
  exports.createDatabaseClient = createDatabaseClient;
47
52
  async function executeQuery(credential, data, sessionKey) {
@@ -190,6 +195,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
190
195
  }
191
196
  exports.executeBatchQuery = executeBatchQuery;
192
197
  function getObjectId(value) {
193
- return { '_id': new mongodb.ObjectId(value) };
198
+ const { ObjectId } = require('mongodb');
199
+ return { '_id': new ObjectId(value) };
194
200
  }
195
201
  exports.getObjectId = getObjectId;
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "@pi-r/atlas",
3
- "version": "0.3.5",
4
- "description": "MongoDB Atlas cloud functions for E-mc.",
5
- "main": "client/index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/anpham6/pi-r.git",
12
- "directory": "src/cloud/atlas"
13
- },
14
- "keywords": [
15
- "squared",
16
- "e-mc",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/pi-r#readme",
22
- "dependencies": {
23
- "@e-mc/cloud": "^0.6.7",
24
- "@e-mc/db": "^0.6.7",
25
- "@e-mc/module": "^0.6.7",
26
- "@e-mc/types": "^0.6.7",
27
- "@pi-r/mongodb": "^0.3.5",
28
- "mongodb": "^5.9.2"
29
- }
30
- }
1
+ {
2
+ "name": "@pi-r/atlas",
3
+ "version": "0.3.6",
4
+ "description": "MongoDB Atlas cloud functions for E-mc.",
5
+ "main": "client/index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
+ "directory": "src/cloud/atlas"
13
+ },
14
+ "keywords": [
15
+ "squared",
16
+ "e-mc",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/pi-r#readme",
22
+ "dependencies": {
23
+ "@e-mc/cloud": "^0.6.16",
24
+ "@e-mc/db": "^0.6.16",
25
+ "@e-mc/module": "^0.6.16",
26
+ "@e-mc/types": "^0.6.16",
27
+ "@pi-r/mongodb": "^0.3.6",
28
+ "mongodb": "^5.9.2"
29
+ }
30
+ }
@@ -0,0 +1,15 @@
1
+ import type { CloudDatabase } from '@e-mc/types/lib/cloud';
2
+ import type { AuthValue } from '@e-mc/types/lib/http';
3
+
4
+ import type { MongoDBClientDBOptions, MongoDBFilterValue } from '@pi-r/mongodb/types';
5
+
6
+ import type { Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, UpdateFilter } from 'mongodb';
7
+
8
+ export interface AtlasDatabaseQuery extends CloudDatabase<Filter<Document> | MongoDBFilterValue, MongoClientOptions, UpdateFilter<Document> | OptionalUnlessRequiredId<unknown>[], AtlasDatabaseCredential>, MongoDBClientDBOptions {
9
+ source: "cloud";
10
+ service: "atlas";
11
+ uri: string;
12
+ updateType?: 0 | 1 | 2 | 3;
13
+ }
14
+
15
+ export interface AtlasDatabaseCredential extends AuthValue, MongoClientOptions {}