@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 CHANGED
@@ -14,6 +14,7 @@ const actions = [
14
14
  "auth",
15
15
  "execService",
16
16
  "upload",
17
+ "batch",
17
18
  ];
18
19
 
19
20
  function getAction(action: string) {
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -45,4 +45,4 @@
45
45
  "urlencode": "^2.0.0",
46
46
  "uuid": "^10.0.0"
47
47
  }
48
- }
48
+ }
package/types/index.ts CHANGED
@@ -418,7 +418,8 @@ export type Q = {
418
418
  | "authCollection"
419
419
  | "auth"
420
420
  | "upload"
421
- | "execService";
421
+ | "execService"
422
+ | "batch";
422
423
  };
423
424
 
424
425
  export type endpointCtx = {