@jovulic/flowstate v0.1.3
Flowstate
A library for defining, executing, and persisting stateful computation.
š Description
Flowstate is a lightweight library for constructing and executing stateful and serializable computations graphs. Flowstate handles operation dependencies, and the stateful execution of the workflow nodes. Flowstate also allows for workflow serialization and provides the ability to easily synchronize workflows such that the workflow is minimally impacted. Flowstate also provdies type information for the input into each operation in the graph.
An example use for the library is in a client-sever context. The library would be used to describe a workflow that includes potentially expensive operations, where you only want to compute the result of those operations once. The workflow could be saved and restored to resume computation or retrieve the result of completed computation, in addition to having updates propogated to the workflow while keeping that same computation state where possible.
⨠Features
ā
Stateful Execution ā Supports incremental evaluation of workflows.
ā
Serialization ā Workflows can be marshaled and unmarshaled for storage or transfer.
ā
Graph Dependency Management ā Uses a graph structure to manage execution order.
ā
Workflow Synchronization ā Supports smart updates without full recomputation.
ā
Typed Input ā Provides the computed types for the input into each operation.
š¦ Installation
Using npm:
npm install @jovulic/flowstateUsing yarn:
yarn add @jovulic/flowstateUsing pnpm:
pnpm add @jovulic/flowstateš Usage
Creating a Workflow
import { Workflow } from "@jovulic/flowstate";
const workflow = new Workflow();Adding Operations
Define operations within the workflow:
const firstOperation = workflow.first("start", async (context, input) => {
return input.value * 2;
});
const secondOperation = workflow.link(
[firstOperation],
"double",
async (context, input) => {
return input.start * 2;
},
);
const finalOperation = workflow.last(
[secondOperation],
"finish",
async (context, input) => {
return input.double;
},
);Running a Workflow
const result = await workflow.run({}, { value: 5 });
console.log(result); // { output: 20 }Marshalling and unmarshalling a Workflow
const serialized = workflow.marshal();
const restoredWorkflow = Workflow.unmarshal(serialized);Synchronizing a Workflow
const newWorkflow = new Workflow();
workflow.sync(newWorkflow); // workflow is now emptyš ļø Build
This project uses Nix for development to ensuring a consistent and reproducible environment. It is easy enough to build without it, but the following guide will be using Nix.
Follow these steps to build and work on the project locally:
Install Nix: If you don't have Nix installed, follow the instructions for your platform at https://nixos.org/download.html.
Clone the Repository: Clone the
flowstaterepository to your local machine.git clone https://github.com/jovulic/flowstate.git cd flowstateEnter the Development Shell: Use the following command to enter the Nix development shell. This will automatically install all the necessary dependencies defined in the
flake.nixfile.nix developThis command might take a while the first time as it downloads and installs the dependencies. Subsequent entries into the shell will be much faster.
Install NPM Dependencies: Once inside the Nix shell, you'll need to install the project's npm dependencies. Even though Nix provides Node.js and npm, the project dependencies are managed by npm. We do this via the
ctlcommand that is added into the development shell.ctl setupBuild the Library: You can now build the library.
ctl buildThis will create a
distdirectory containing the compiled library files.