@dnax/core 0.74.2 → 0.74.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.
@@ -2589,13 +2589,15 @@ class useRest {
2589
2589
  this.#session?.startTransaction();
2590
2590
  }
2591
2591
  } catch (err: any) {
2592
- if (!options?.silent) {
2592
+ if (options?.silent) {
2593
2593
  consola.error(err?.message | err);
2594
+ } else {
2595
+ throw new Error(err?.message || err);
2594
2596
  }
2595
2597
  }
2596
2598
  }
2597
2599
 
2598
- async abortTransaction() {
2600
+ async abortTransaction(options?: { silent?: boolean }) {
2599
2601
  return new Promise(async (resolve, reject) => {
2600
2602
  try {
2601
2603
  if (this.#session) {
@@ -2603,12 +2605,16 @@ class useRest {
2603
2605
  return resolve(true);
2604
2606
  }
2605
2607
  } catch (err: any) {
2606
- return reject(err?.message || err);
2608
+ if (options?.silent) {
2609
+ console.error(err?.message || err);
2610
+ } else {
2611
+ return reject(err?.message || err);
2612
+ }
2607
2613
  }
2608
2614
  });
2609
2615
  }
2610
2616
 
2611
- async endSession() {
2617
+ async endSession(options?: { silent?: boolean }) {
2612
2618
  return new Promise(async (resolve, reject) => {
2613
2619
  try {
2614
2620
  if (this.#session) {
@@ -2617,12 +2623,19 @@ class useRest {
2617
2623
  }
2618
2624
  return resolve(true);
2619
2625
  } catch (err: any) {
2620
- return reject(err?.message || err);
2626
+ if (options?.silent) {
2627
+ console.error(err?.message || err);
2628
+ } else {
2629
+ return reject(err?.message || err);
2630
+ }
2621
2631
  }
2622
2632
  });
2623
2633
  }
2624
2634
 
2625
- async commitTransaction(options?: { closeSession?: boolean }) {
2635
+ async commitTransaction(options?: {
2636
+ closeSession?: boolean;
2637
+ silent?: boolean;
2638
+ }) {
2626
2639
  return new Promise(async (resolve, reject) => {
2627
2640
  if (this.#session) {
2628
2641
  await this.#session
@@ -2636,7 +2649,11 @@ class useRest {
2636
2649
  resolve(true);
2637
2650
  })
2638
2651
  .catch((err: any) => {
2639
- reject(err?.message || err);
2652
+ if (options?.silent) {
2653
+ console.error(err?.message || err);
2654
+ } else {
2655
+ return reject(err?.message || err);
2656
+ }
2640
2657
  });
2641
2658
  }
2642
2659
  });
@@ -222,7 +222,7 @@ function toBson<T>(
222
222
  }
223
223
 
224
224
  // updateMany
225
- if (options?.action == "updateMany") {
225
+ if (options?.action == "updateMany" && Array.isArray(data)) {
226
226
  data?.map((d) => {
227
227
  d.updatedAt = new Date();
228
228
  });
@@ -0,0 +1,60 @@
1
+ import { useRest } from "../../driver/mongo/rest";
2
+ import type { sessionCtx } from "../../types";
3
+ import type { socketIoType } from "../../lib/socket/instance";
4
+ type ActivityType = {
5
+ name: string;
6
+ exec: (ctx: {
7
+ input: any;
8
+ rest: InstanceType<typeof useRest>;
9
+ session: sessionCtx;
10
+ isAuth: boolean;
11
+ io: socketIoType;
12
+ }) => Promise<{ output: any; error: any; success: boolean }>;
13
+ };
14
+
15
+ type workflowConfig = {
16
+ name: string;
17
+ activities: ActivityType[];
18
+ };
19
+
20
+ class Workflow {
21
+ private config: workflowConfig;
22
+ constructor(config: workflowConfig) {
23
+ this.config = config;
24
+ }
25
+ async run(context: {
26
+ rest: InstanceType<typeof useRest>;
27
+ session: sessionCtx;
28
+ isAuth: boolean;
29
+ io: socketIoType;
30
+ input: any;
31
+ }) {
32
+ let l = this.config.activities.length || 0;
33
+ let index = 0;
34
+ if (index < l) {
35
+ let activity = this.config.activities[index];
36
+ let r = {
37
+ output: null,
38
+ error: null,
39
+ success: false,
40
+ };
41
+ if (index > 0) {
42
+ r = await activity.exec({
43
+ input: context.input,
44
+ rest: context.rest,
45
+ session: context.session,
46
+ isAuth: context.isAuth,
47
+ io: context.io,
48
+ });
49
+ } else {
50
+ await activity.exec({
51
+ input: r.output,
52
+ rest: context.rest,
53
+ session: context.session,
54
+ isAuth: context.isAuth,
55
+ io: context.io,
56
+ });
57
+ }
58
+ }
59
+ }
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.74.2",
3
+ "version": "0.74.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {},