|
| 1 | +import { ModuleCompute, ModuleDefinition } from '@nodescript/core/types'; |
| 2 | + |
| 3 | +type P = { |
| 4 | + condition: boolean; |
| 5 | + value: unknown; |
| 6 | + token: string; |
| 7 | + message: string; |
| 8 | + status: number; |
| 9 | +}; |
| 10 | + |
| 11 | +type R = Promise<unknown>; |
| 12 | + |
| 13 | +export const module: ModuleDefinition<P, R> = { |
| 14 | + version: '1.0.1', |
| 15 | + moduleName: 'Flow / Skip', |
| 16 | + description: ` |
| 17 | + Skips the evaluation if condition is true, otherwise returns the value. |
| 18 | + Skipped evaluation results in a control exception (by default with 204 status). |
| 19 | + The flow can subsequently be resumed with Flow / Continue. |
| 20 | + `, |
| 21 | + params: { |
| 22 | + condition: { |
| 23 | + schema: { type: 'boolean' }, |
| 24 | + }, |
| 25 | + value: { |
| 26 | + schema: { type: 'any' }, |
| 27 | + deferred: true, |
| 28 | + }, |
| 29 | + token: { |
| 30 | + schema: { type: 'string', default: '' }, |
| 31 | + advanced: true, |
| 32 | + }, |
| 33 | + message: { |
| 34 | + schema: { type: 'string', default: 'Evaluation skipped' }, |
| 35 | + advanced: true, |
| 36 | + }, |
| 37 | + status: { |
| 38 | + schema: { type: 'number', default: 204 }, |
| 39 | + advanced: true, |
| 40 | + }, |
| 41 | + }, |
| 42 | + result: { |
| 43 | + async: true, |
| 44 | + schema: { type: 'any' }, |
| 45 | + } |
| 46 | +}; |
| 47 | + |
| 48 | +export const compute: ModuleCompute<P, R> = async (params, ctx) => { |
| 49 | + const { condition, value, token, message, status } = params; |
| 50 | + if (condition) { |
| 51 | + return ctx.skipEvaluation(message, token, status); |
| 52 | + } |
| 53 | + return await ctx.resolveDeferred(value); |
| 54 | +}; |
0 commit comments