### Install Sequential Workflow Machine Packages Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Install the necessary packages for the sequential workflow machine using NPM. ```bash npm i sequential-workflow-model sequential-workflow-machine ``` -------------------------------- ### New Activity Creation Syntax Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/CHANGELOG.md Illustrates the updated syntax for `create*Activity` functions, where the step type is the first argument and configuration is the second. ```ts // Old syntax const fooActivity = createAtomActivity({ stepType: 'foo', init: /* ... */, handler: /* ... */ }); // New syntax const fooActivity = createAtomActivity('foo', { init: /* ... */, handler: /* ... */ }); ``` -------------------------------- ### Create and Run Workflow Machine Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Build the workflow machine using the activity set and definition, then create an interpreter to run the workflow. ```typescript import { createWorkflowMachineBuilder } from 'sequential-workflow-machine'; const builder = createWorkflowMachineBuilder(activitySet); const machine = builder.build(definition); const interpreter = machine.create({ init: () => { return { html: null, }; } }); interpreter.onChange(() => { /* ... */ }); interpreter.onDone(() => { /* ... */ }); interpreter.start(); ``` -------------------------------- ### Skip Fork Activity Branches Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/CHANGELOG.md Demonstrates how to return a value from the `skip()` function within a fork activity handler to skip all branches. ```js createForkActivity('if', { init: () => ({ /* ... */ }), handler: async (step, globalState, activityState) => { // ... return skip(); } }) ``` -------------------------------- ### Prepare Workflow Definition Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Prepare the workflow definition object, specifying properties and the sequence of steps. ```typescript const definition: MyDefinition = { properties: { verbose: true, }, sequence: [ { id: '0x00001', componentType: 'task', type: 'downloadHtml', name: 'Download google.com', properties: { pageUrl: 'https://www.google.com', }, }, ], }; ``` -------------------------------- ### Create Atom Activity From Handler Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/CHANGELOG.md Demonstrates the `createAtomActivityFromHandler` function for creating an activity with a concise syntax and no activity state. ```ts const fooActivity = createAtomActivityFromHandler('foo', async (step, globalState) => { // handler }); ``` -------------------------------- ### Create Activity Set Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Create an activity set, which is a collection of all supported activities for the workflow machine. ```typescript import { createActivitySet } from 'sequential-workflow-machine'; const activitySet = createActivitySet([ downloadHtmlActivity, ]); ``` -------------------------------- ### Create Atom Activity Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Create a basic atom activity for a step type. This activity handles the execution of an atomic step and updates the global state. ```typescript import { createAtomActivity } from 'sequential-workflow-machine'; interface DownloadHtmlStepState { attempt: number; } const downloadHtmlActivity = createAtomActivity('downloadHtml', { init: () => ({ attempt: 0, }), handler: async (step: DownloadHtmlStep, globalState: WorkflowGlobalState, activityState: DownloadHtmlStepState) => { globalState.html = await downloadHtml(step.properties.pageUrl); activityState.attempt++; }, }); ``` -------------------------------- ### Prepare Global State Interface Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Define the TypeScript interface for the global state of the workflow. ```typescript interface WorkflowGlobalState { html: string | null; } ``` -------------------------------- ### Break Parent Loop Without Specifying Name Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/CHANGELOG.md Shows how to use `loopName: (step) => -1` in the `createBreakActivity` configuration to break the immediate parent loop. ```ts createBreakActivity('break', { loopName: (step) => -1, // ... }); ``` -------------------------------- ### Define Workflow Definition Type Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Define the TypeScript interface for your workflow definition, including any custom properties. ```typescript import { Definition } from 'sequential-workflow-model'; interface MyDefinition extends Definition { properties: { verbose: boolean; }; } ``` -------------------------------- ### Define Step Type Source: https://github.com/nocode-js/sequential-workflow-machine/blob/main/README.md Define the TypeScript interface for a specific step type within your workflow, including its component type, type name, and properties. ```typescript import { Step } from 'sequential-workflow-model'; interface DownloadHtmlStep extends Step { componentType: 'task'; type: 'downloadHtml'; properties: { pageUrl: string; }; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.