codehooks-js 1.3.0 → 1.3.2

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {agg} from './aggregation/index.mjs';
2
2
  import {crudlify as crud} from './crudlify/index.mjs';
3
3
  import {serveStatic as ws, render as renderView} from './webserver.mjs';
4
- import {Steps, StepsConfig} from './workflow/index.mjs';
4
+ import {Steps as Workflow, StepsConfig as WorkflowConfig} from './workflow/index.mjs';
5
5
 
6
6
  function createRoute(str) {
7
7
  if(str instanceof RegExp) {
@@ -117,9 +117,9 @@ class Codehooks {
117
117
  })
118
118
  }
119
119
 
120
- createSteps = (name, description, steps, options={}) => {
121
- Steps.register(this, name, description, steps, options);
122
- return Steps;
120
+ createWorkflow = (name, description, steps, options={}) => {
121
+ Workflow.register(this, name, description, steps, options);
122
+ return Workflow;
123
123
  }
124
124
 
125
125
  init = (hook) => {
@@ -193,10 +193,10 @@ export const aggregation = agg;
193
193
  export const crudlify = crud;
194
194
  export const coho = _coho;
195
195
  export const app = _coho;
196
- export const stepsconfig = StepsConfig;
196
+ export const workflowconfig = WorkflowConfig;
197
197
  export {
198
- Steps,
199
- StepsConfig
198
+ Workflow,
199
+ WorkflowConfig
200
200
  };
201
201
  export const realtime = {
202
202
  createChannel: (path, ...hook) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codehooks-js",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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
@@ -4,7 +4,7 @@ export const aggregation: typeof agg;
4
4
  export const crudlify: typeof crud;
5
5
  export const coho: Codehooks;
6
6
  export const app: Codehooks;
7
- export const stepsconfig: {
7
+ export const workflowconfig: {
8
8
  setCollectionName: any;
9
9
  setQueuePrefix: any;
10
10
  };
@@ -62,7 +62,7 @@ declare class Codehooks {
62
62
  set: (key: any, val: any) => void;
63
63
  render: (view: any, data: any, cb: any) => Promise<void>;
64
64
  crudlify: (schema?: {}, options?: {}) => Promise<import("./crudlify/lib/eventhooks.mjs").EventHooks>;
65
- createSteps: (name: any, description: any, steps: any, options?: {}) => {
65
+ createWorkflow: (name: any, description: any, steps: any, options?: {}) => {
66
66
  definitions: Map<any, any>;
67
67
  getDefinition(stepsName: string, stepName: string): Function;
68
68
  validateStepDefinition(step: Function): void;
@@ -77,7 +77,7 @@ declare class Codehooks {
77
77
  qId: string;
78
78
  }>;
79
79
  getStepsStatus(id: string): Promise<any>;
80
- listSteps(filter: any): Promise<any[]>;
80
+ getInstances(filter: any): Promise<any[]>;
81
81
  cancelSteps(id: string): Promise<any>;
82
82
  [EventEmitter.captureRejectionSymbol]?<K>(error: Error, event: string | symbol, ...args: any[]): void;
83
83
  addListener<K>(eventName: string | symbol, listener: (...args: any[]) => void): any;
@@ -124,7 +124,7 @@ declare class Codehooks {
124
124
  };
125
125
  addListener: (observer: any) => void;
126
126
  }
127
- import { Steps } from './workflow/index.mjs';
128
- import { StepsConfig } from './workflow/index.mjs';
127
+ import { Steps as Workflow } from './workflow/index.mjs';
128
+ import { StepsConfig as WorkflowConfig } from './workflow/index.mjs';
129
129
  declare const _coho: Codehooks;
130
- export { Steps, StepsConfig };
130
+ export { Workflow, WorkflowConfig };
@@ -112,7 +112,7 @@ declare class StepsEngine extends EventEmitter<[never]> {
112
112
  * @param {Object} filter - Filter criteria for steps workflows
113
113
  * @returns {Promise<Array>} List of steps instances
114
114
  */
115
- listSteps(filter: any): Promise<any[]>;
115
+ getInstances(filter: any): Promise<any[]>;
116
116
  /**
117
117
  * Cancel a steps instance
118
118
  * @param {string} id - ID of the steps instance to cancel
@@ -117,7 +117,7 @@ class StepsEngine extends EventEmitter {
117
117
  const isFinished = nextStep === null;
118
118
 
119
119
  // Handle single next step
120
- StepsEngine.getInstance().emit('stepStarted', { stepsName, step: nextStep, state: newState, instanceId });
120
+ StepsEngine.getInstance().emit('stepStarted', { workflowName: stepsName, step: nextStep, state: newState, instanceId });
121
121
  const connection = await Datastore.open();
122
122
  // remove the _id from the newState
123
123
  delete newState._id;
@@ -126,7 +126,7 @@ class StepsEngine extends EventEmitter {
126
126
  { _id: instanceId },
127
127
  { $set: { ...newState, nextStep: nextStep, updatedAt: new Date().toISOString(), isFinished: isFinished } });
128
128
 
129
- StepsEngine.getInstance().emit('stateUpdated', { stepsName, state: newState, instanceId });
129
+ StepsEngine.getInstance().emit('stateUpdated', { workflowName: stepsName, state: newState, instanceId });
130
130
 
131
131
  // Get the next step function
132
132
  const func = StepsEngine.getInstance().getDefinition(stepsName, nextStep);
@@ -134,7 +134,7 @@ class StepsEngine extends EventEmitter {
134
134
  // Check if the step is waiting for input
135
135
  if (options && options.waitForInput === true) {
136
136
  console.log('Steps workflow is paused, waiting for input for at step', nextStep);
137
- this.emit('stepWaiting', { stepsName, step: nextStep, instanceId });
137
+ this.emit('stepWaiting', { workflowName: stepsName, step: nextStep, instanceId });
138
138
  return;
139
139
  }
140
140
 
@@ -173,7 +173,7 @@ class StepsEngine extends EventEmitter {
173
173
  instanceId: instanceId
174
174
  });
175
175
 
176
- StepsEngine.getInstance().emit('stepEnqueued', { stepsName, step: nextStep, state: newState, instanceId });
176
+ StepsEngine.getInstance().emit('stepEnqueued', { workflowName: stepsName, step: nextStep, state: newState, instanceId });
177
177
  } catch (error) {
178
178
  console.log('error', error.message);
179
179
  throw error;
@@ -203,7 +203,7 @@ class StepsEngine extends EventEmitter {
203
203
  * @throws {Error} If step definition is invalid
204
204
  */
205
205
  async register(app, name, description, definition) {
206
- StepsEngine.getInstance().emit('stepsRegistered', { name, description });
206
+ StepsEngine.getInstance().emit('workflowCreated', { name, description });
207
207
 
208
208
  // Validate each step in the definition
209
209
  for (const [stepName, step] of Object.entries(definition)) {
@@ -238,7 +238,7 @@ class StepsEngine extends EventEmitter {
238
238
  * @throws {Error} If starting steps fails
239
239
  */
240
240
  async start(name, initialState) {
241
- StepsEngine.getInstance().emit('stepsStarted', { name, initialState });
241
+ StepsEngine.getInstance().emit('workflowStarted', { name, initialState });
242
242
 
243
243
  return new Promise(async (resolve, reject) => {
244
244
  try {
@@ -316,7 +316,7 @@ class StepsEngine extends EventEmitter {
316
316
  }
317
317
 
318
318
  console.log('continue state', state);
319
- StepsEngine.getInstance().emit('stepContinued', { stepsName, step: state.nextStep, instanceId });
319
+ StepsEngine.getInstance().emit('workflowContinued', { stepsName, step: state.nextStep, instanceId });
320
320
 
321
321
  return new Promise(async (resolve, reject) => {
322
322
  const { _id: ID } = await connection.enqueue(`${StepsEngine.queuePrefix}`, {
@@ -349,7 +349,7 @@ class StepsEngine extends EventEmitter {
349
349
  * @param {Object} filter - Filter criteria for steps workflows
350
350
  * @returns {Promise<Array>} List of steps instances
351
351
  */
352
- async listSteps(filter) {
352
+ async getInstances(filter) {
353
353
  return new Promise(async (resolve, reject) => {
354
354
  const connection = await Datastore.open();
355
355
  const states = await connection.find(StepsEngine.collectionName, filter).toArray();
@@ -364,7 +364,7 @@ class StepsEngine extends EventEmitter {
364
364
  * @returns {Promise<Object>} The cancellation result
365
365
  */
366
366
  async cancelSteps(id) {
367
- StepsEngine.getInstance().emit('stepsCancelled', { id });
367
+ StepsEngine.getInstance().emit('cancelled', { id });
368
368
  return new Promise(async (resolve, reject) => {
369
369
  const connection = await Datastore.open();
370
370
  const state = await connection.updateOne(StepsEngine.collectionName,