codehooks-js 1.3.10 → 1.3.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codehooks-js",
3
- "version": "1.3.10",
3
+ "version": "1.3.11",
4
4
  "type": "module",
5
5
  "description": "Codehooks.io official library - provides express.JS like syntax",
6
6
  "main": "index.js",
package/types/index.d.ts CHANGED
@@ -1113,7 +1113,11 @@ export type WorkflowEvents = {
1113
1113
  /**
1114
1114
  * Definition of a workflow step function
1115
1115
  */
1116
- export type WorkflowDefinition = Record<string, (state: any, callback: (nextStep: string | string[] | null, newState: any, options?: any) => void) => Promise<void>>;
1116
+ export type WorkflowDefinition = Record<string, (
1117
+ state: any,
1118
+ callback: (nextStep: string | string[] | null, newState: any, options?: any) => void,
1119
+ waiterFunction?: (waiter?: any) => void
1120
+ ) => Promise<void>>;
1117
1121
 
1118
1122
  /**
1119
1123
  * Configuration options for a workflow step
@@ -261,6 +261,18 @@ class Workflow extends EventEmitter {
261
261
  return;
262
262
  }
263
263
  try {
264
+ const waiterFunction = async (state) => {
265
+ if (state) {
266
+ console.debug('waiter', state);
267
+ await connection.updateOne(this.#collectionName,
268
+ { _id: instanceId },
269
+ { $set: { ...state, updatedAt: new Date().toISOString() } });
270
+ resolve();
271
+ return;
272
+ } else {
273
+ resolve(); // no state update
274
+ }
275
+ }
264
276
  await func({...newState, instanceId: newState._id}, async (nextStep, userState, options) => {
265
277
  try {
266
278
  // Protect system-level properties
@@ -370,8 +382,8 @@ class Workflow extends EventEmitter {
370
382
  console.error('error', error.message);
371
383
  reject(error);
372
384
  }
373
- });
374
- resolve();
385
+ }, waiterFunction);
386
+ //resolve();
375
387
  } catch (error) {
376
388
  console.error('Error executing step function:', error);
377
389
  reject(error);