@dnax/core 0.8.6 → 0.8.7
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/app/ctrl.ts +1 -0
- package/driver/mongo/rest.ts +45 -0
- package/package.json +2 -2
- package/types/index.ts +2 -1
package/app/ctrl.ts
CHANGED
package/driver/mongo/rest.ts
CHANGED
|
@@ -43,6 +43,18 @@ type optionCb = {
|
|
|
43
43
|
elementAt?: Number | null;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
type QueryBatchType<T extends "findOne" | "find"> = {
|
|
47
|
+
as: string;
|
|
48
|
+
collection: string;
|
|
49
|
+
action: T;
|
|
50
|
+
filter: {
|
|
51
|
+
id: string;
|
|
52
|
+
_id: string;
|
|
53
|
+
params: T extends "findOne" ? findOneParam : findParam;
|
|
54
|
+
};
|
|
55
|
+
options: optionCb;
|
|
56
|
+
};
|
|
57
|
+
|
|
46
58
|
const omitUpdate = [
|
|
47
59
|
"$set._id",
|
|
48
60
|
"$set.id",
|
|
@@ -418,6 +430,39 @@ class useRest {
|
|
|
418
430
|
}
|
|
419
431
|
});
|
|
420
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
*
|
|
435
|
+
* @param queries
|
|
436
|
+
* @returns [{ [key: string]: any }]
|
|
437
|
+
*/
|
|
438
|
+
async batch<T extends "findOne" | "find">(queries: QueryBatchType<T>[]) {
|
|
439
|
+
return new Promise(async (resolve, reject) => {
|
|
440
|
+
try {
|
|
441
|
+
let result = {} as any;
|
|
442
|
+
for await (let query of queries) {
|
|
443
|
+
let resultName = query.as || query.collection;
|
|
444
|
+
if (query.action == "findOne") {
|
|
445
|
+
result[resultName] = await this.findOne(
|
|
446
|
+
query.collection,
|
|
447
|
+
query.filter.id,
|
|
448
|
+
query.filter.params,
|
|
449
|
+
query.options
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
if (query.action == "find") {
|
|
453
|
+
result[resultName] = await this.find(
|
|
454
|
+
query.collection,
|
|
455
|
+
query.filter.params,
|
|
456
|
+
query.options
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return resolve(result);
|
|
461
|
+
} catch (err) {
|
|
462
|
+
return reject(err);
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
421
466
|
|
|
422
467
|
/**
|
|
423
468
|
*
|
package/package.json
CHANGED