@pi-r/atlas 0.6.7 → 0.7.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.
package/README.md CHANGED
@@ -1,12 +1,9 @@
1
- # @pi-r/atlas
1
+ ### @pi-r/atlas
2
2
 
3
- PEP 402 - Forever Dodgers
4
-
5
- ## Documentation
3
+ https://e-mc.readthedocs.io/en/latest/cloud/atlas.html
6
4
 
7
- - [E-mc](https://e-mc.readthedocs.io/en/latest/cloud/atlas.html)
8
- - [squared](https://squared.readthedocs.io)
5
+ PEP 402 - Forever Dodgers
9
6
 
10
- ## LICENSE
7
+ ### LICENSE
11
8
 
12
9
  MIT
package/client/index.js CHANGED
@@ -4,11 +4,11 @@ const mongodb = require("mongodb");
4
4
  const types_1 = require("@e-mc/types");
5
5
  const util_1 = require("@e-mc/cloud/util");
6
6
  const mongodb_1 = require("@pi-r/mongodb");
7
- const Module = require("@e-mc/module");
7
+ const Cloud = require("@e-mc/cloud");
8
8
  function sanitizeCredentials(credential) {
9
9
  const { username, password } = credential;
10
10
  if (username) {
11
- credential.auth || (credential.auth = password ? { username, password } : { username });
11
+ credential.auth ||= password ? { username, password } : { username };
12
12
  delete credential.username;
13
13
  }
14
14
  if (password) {
@@ -17,7 +17,7 @@ function sanitizeCredentials(credential) {
17
17
  }
18
18
  function validateDatabase(credential, data) {
19
19
  const auth = credential.auth;
20
- return !!(data.table && Module.isURL(data.uri) && ((auth === null || auth === void 0 ? void 0 : auth.username) || credential.username || (0, util_1.hasBasicAuth)(data.uri)));
20
+ return !!(data.table && Cloud.isURL(data.uri) && (auth?.username || credential.username || (0, util_1.hasBasicAuth)(data.uri)));
21
21
  }
22
22
  exports.validateDatabase = validateDatabase;
23
23
  function createDatabaseClient(credential, data) {
@@ -30,7 +30,6 @@ async function executeQuery(credential, data, sessionKey) {
30
30
  }
31
31
  exports.executeQuery = executeQuery;
32
32
  async function executeBatchQuery(credential, batch, sessionKey) {
33
- var _a, _b;
34
33
  const length = batch.length;
35
34
  const result = new Array(length);
36
35
  const clients = {};
@@ -38,8 +37,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
38
37
  const coercing = this.hasCoerce("atlas", 'options');
39
38
  const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
40
39
  const createClient = async (item, options) => {
41
- var _a;
42
- return clients[_a = item.uri + Module.asString(options, true)] || (clients[_a] = await createDatabaseClient.call(this, options, item).connect());
40
+ return clients[item.uri + Cloud.asString(options, true)] ||= await createDatabaseClient.call(this, options, item).connect();
43
41
  };
44
42
  const closeClient = () => {
45
43
  for (const key in clients) {
@@ -59,14 +57,14 @@ async function executeBatchQuery(credential, batch, sessionKey) {
59
57
  limit = 1;
60
58
  }
61
59
  const options = item.options ? length === 1 ? Object.assign(item.options, credential) : { ...item.options, ...credential } : length === 1 ? credential : { ...credential };
62
- let rows, queryString = caching && ignoreCache !== true ? (name || '') + '_' + table + '_' + limit + Module.asString(options, true) + (sort ? Module.asString(sort, true) : '') + (client ? Module.asString(client, true) : '') : '', auth, pipeline;
60
+ let rows, queryString = caching && ignoreCache !== true ? (name || '') + '_' + table + '_' + limit + Cloud.asString(options, true) + (sort ? Cloud.asString(sort, true) : '') + (client ? Cloud.asString(client, true) : '') : '', auth, pipeline;
63
61
  if (queryString) {
64
62
  sanitizeCredentials(options);
65
63
  auth = { uri: item.uri, options };
66
64
  }
67
- const getInstance = (target) => target.db(name, client === null || client === void 0 ? void 0 : client.db);
68
- const getCollection = (target) => getInstance(target).collection(table, client === null || client === void 0 ? void 0 : client.collection);
69
- const runCommand = async (target, document) => getInstance(target).command(document, client === null || client === void 0 ? void 0 : client.command);
65
+ const getInstance = (target) => target.db(name, client?.db);
66
+ const getCollection = (target) => getInstance(target).collection(table, client?.collection);
67
+ const runCommand = async (target, document) => getInstance(target).command(document, client?.command);
70
68
  const getCache = () => {
71
69
  if (ignoreCache !== 1) {
72
70
  cacheValue.renewCache = ignoreCache === 0;
@@ -85,7 +83,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
85
83
  (0, types_1.coerceObject)(update);
86
84
  }
87
85
  if (Array.isArray(update)) {
88
- const insertOptions = (_a = item.execute) === null || _a === void 0 ? void 0 : _a.insert;
86
+ const insertOptions = item.execute?.insert;
89
87
  if (insertOptions && coercing) {
90
88
  (0, types_1.coerceObject)(insertOptions);
91
89
  }
@@ -102,7 +100,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
102
100
  }
103
101
  if (pipeline || query) {
104
102
  if (queryString) {
105
- queryString += Module.asString(aggregate || query, true);
103
+ queryString += Cloud.asString(aggregate || query, true);
106
104
  if ((aggregate || !update) && (rows = getCache())) {
107
105
  result[i] = rows;
108
106
  continue;
@@ -134,7 +132,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
134
132
  }
135
133
  else {
136
134
  if (update && updateType === 1) {
137
- const updateOptions = (_b = item.execute) === null || _b === void 0 ? void 0 : _b.update;
135
+ const updateOptions = item.execute?.update;
138
136
  if (updateOptions && coercing) {
139
137
  (0, types_1.coerceObject)(updateOptions);
140
138
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/atlas",
3
- "version": "0.6.7",
3
+ "version": "0.7.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.8.8",
24
- "@e-mc/db": "^0.8.8",
25
- "@e-mc/module": "^0.8.8",
26
- "@e-mc/types": "^0.8.8",
27
- "@pi-r/mongodb": "^0.6.7",
28
- "mongodb": "^6.5.0"
23
+ "@e-mc/cloud": "^0.9.2",
24
+ "@e-mc/db": "^0.9.2",
25
+ "@e-mc/module": "^0.9.2",
26
+ "@e-mc/types": "^0.9.2",
27
+ "@pi-r/mongodb": "^0.7.1",
28
+ "mongodb": "^6.6.2"
29
29
  }
30
30
  }
@@ -0,0 +1,14 @@
1
+ import type { CloudDatabase } from '@e-mc/types/lib/cloud';
2
+
3
+ import type { MongoDBClientDBOptions, MongoDBFilterValue } from '@pi-r/mongodb/types';
4
+
5
+ import type { Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, UpdateFilter } from 'mongodb';
6
+
7
+ export interface AtlasDatabaseQuery extends CloudDatabase<Filter<Document> | MongoDBFilterValue, MongoClientOptions, UpdateFilter<Document> | OptionalUnlessRequiredId<unknown>[], AtlasDatabaseCredential>, MongoDBClientDBOptions {
8
+ source: "cloud";
9
+ service: "atlas";
10
+ uri: string;
11
+ updateType?: 0 | 1 | 2 | 3;
12
+ }
13
+
14
+ export interface AtlasDatabaseCredential extends AuthValue, MongoClientOptions {}