@pi-r/atlas 0.10.1 → 0.10.3
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/client/index.js +28 -6
- package/package.json +7 -7
- package/types/index.d.ts +2 -1
package/client/index.js
CHANGED
|
@@ -62,7 +62,16 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
62
62
|
const coercing = this.hasCoerce("atlas", 'options');
|
|
63
63
|
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
64
64
|
const createClient = async (item, options) => {
|
|
65
|
-
|
|
65
|
+
const key = length > 1 ? (0, types_1.hashKey)(item.uri + Cloud.asString(options, true)) : '_';
|
|
66
|
+
let client = clients[key];
|
|
67
|
+
if (client) {
|
|
68
|
+
return client;
|
|
69
|
+
}
|
|
70
|
+
client = createDatabaseClient.call(this, options, item);
|
|
71
|
+
if (item.driverInfo) {
|
|
72
|
+
client.appendMetadata(item.driverInfo);
|
|
73
|
+
}
|
|
74
|
+
return clients[key] ||= await client.connect();
|
|
66
75
|
};
|
|
67
76
|
const closeClient = () => {
|
|
68
77
|
for (const key in clients) {
|
|
@@ -71,7 +80,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
71
80
|
};
|
|
72
81
|
for (let i = 0; i < length; ++i) {
|
|
73
82
|
const item = batch[i];
|
|
74
|
-
const { service, name, table, id, aggregate, sort, client, ignoreCache } = item;
|
|
83
|
+
const { service, name, table, id, aggregate, distinct, sort, client, ignoreCache } = item;
|
|
75
84
|
if (!table) {
|
|
76
85
|
closeClient();
|
|
77
86
|
throw (0, util_1.formatError)(item, "Missing database table");
|
|
@@ -137,14 +146,16 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
137
146
|
rows = await items.toArray();
|
|
138
147
|
}
|
|
139
148
|
else {
|
|
140
|
-
const [filter, operation] = (0, mongodb_1.getFilterValue)(query, coercing);
|
|
141
|
-
|
|
149
|
+
const [filter, operation = {}] = (0, mongodb_1.getFilterValue)(query, coercing);
|
|
150
|
+
if (sort) {
|
|
151
|
+
operation.sort = (0, mongodb_1.getSortValue)(sort, coercing)[0];
|
|
152
|
+
}
|
|
142
153
|
if (limit === 1) {
|
|
143
|
-
const document = update ? await collection[updateType === 2 ? 'findOneAndReplace' : updateType === 3 ? 'findOneAndDelete' : 'findOneAndUpdate'](filter, update, operation) : await collection.findOne(filter, operation);
|
|
154
|
+
const document = update ? await collection[item.updateType === 2 ? 'findOneAndReplace' : item.updateType === 3 ? 'findOneAndDelete' : 'findOneAndUpdate'](filter, update, operation) : await collection.findOne(filter, operation);
|
|
144
155
|
rows = document ? [document] : [];
|
|
145
156
|
}
|
|
146
157
|
else {
|
|
147
|
-
if (update && updateType === 1) {
|
|
158
|
+
if (update && item.updateType === 1) {
|
|
148
159
|
const updateOptions = item.execute?.update;
|
|
149
160
|
if (updateOptions && coercing) {
|
|
150
161
|
(0, types_1.coerceObject)(updateOptions);
|
|
@@ -162,6 +173,17 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
162
173
|
}
|
|
163
174
|
}
|
|
164
175
|
}
|
|
176
|
+
else if (distinct) {
|
|
177
|
+
if (queryString) {
|
|
178
|
+
queryString += Cloud.asString(distinct, true);
|
|
179
|
+
if (rows = this.getCacheResult(service, auth, queryString, cacheValue, ignoreCache)) {
|
|
180
|
+
result[i] = rows;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const [a, b, c] = Array.isArray(distinct) ? distinct : [distinct];
|
|
185
|
+
rows = await (b ? c ? collection.distinct(a, b, c) : collection.distinct(a, b) : collection.distinct(a));
|
|
186
|
+
}
|
|
165
187
|
else if (!aggregate) {
|
|
166
188
|
if (queryString && (rows = this.getCacheResult(service, auth, queryString, cacheValue, ignoreCache))) {
|
|
167
189
|
result[i] = rows;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/atlas",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"description": "MongoDB Atlas cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/cloud": "^0.12.
|
|
23
|
-
"@e-mc/db": "^0.12.
|
|
24
|
-
"@e-mc/module": "^0.12.
|
|
25
|
-
"@e-mc/types": "^0.12.
|
|
26
|
-
"@pi-r/mongodb": "^0.10.
|
|
27
|
-
"mongodb": "^6.
|
|
22
|
+
"@e-mc/cloud": "^0.12.7",
|
|
23
|
+
"@e-mc/db": "^0.12.7",
|
|
24
|
+
"@e-mc/module": "^0.12.7",
|
|
25
|
+
"@e-mc/types": "^0.12.7",
|
|
26
|
+
"@pi-r/mongodb": "^0.10.3",
|
|
27
|
+
"mongodb": "^6.19.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import type { AuthValue } from '@e-mc/types/lib/http';
|
|
|
3
3
|
|
|
4
4
|
import type { MongoDBClientDBOptions, MongoDBFilterValue } from '@pi-r/mongodb/types';
|
|
5
5
|
|
|
6
|
-
import type { Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, UpdateFilter } from 'mongodb';
|
|
6
|
+
import type { Document, DriverInfo, Filter, MongoClientOptions, OptionalUnlessRequiredId, UpdateFilter } from 'mongodb';
|
|
7
7
|
|
|
8
8
|
export interface AtlasDatabaseQuery extends CloudDatabase<Filter<Document> | MongoDBFilterValue, MongoClientOptions, UpdateFilter<Document> | OptionalUnlessRequiredId<unknown>[], AtlasDatabaseCredential>, MongoDBClientDBOptions {
|
|
9
9
|
source: "cloud";
|
|
10
10
|
service: "atlas";
|
|
11
11
|
uri: string;
|
|
12
12
|
updateType?: 0 | 1 | 2 | 3;
|
|
13
|
+
driverInfo?: DriverInfo;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export interface AtlasDatabaseCredential extends AuthValue, MongoClientOptions {}
|