ocustate
v1.1.6
Published
Ocunapse State-Machine
Readme
OCUSTATE State Machine Runner
Getting Started
First, import the library...
npm install ocustateExample Code
import { StateMachine, EventListener, State, NextAction, loadStatesCollection, runMachine } from 'ocustate';
class StateManager implements EventListener {
private states?: State[];
constructor(states?: State[]) {
this.states = states;
}
async setMachinePath(forState: string): Promise<string | State[]> {
return this.states ?? [];
}
async executeState(state: State): Promise<string | NextAction> {
console.log(`Executiing state ${state.name} (action: ${state.action})`);
return NextAction.NextState;
}
}
export default async function Home() {
try {
StateMachine.AddEventListener(new StateManager());
const workflows = await loadStatesCollection('<<SYSTEM_NAME>>');
console.log(`Workflows: ${JSON.stringify(workflows, null, 4)}`);
await runMachine('<<Workflow>>', '<<State to execute>>');
} catch (e) {
console.log((e as Error).message);
}
return (
<main className='flex min-h-screen flex-col items-center justify-center p-24'>
<h1>Loaded</h1>
</main>
);
}