JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21
  • Score
    100M100P100Q41299F
  • License MIT

Typed async workflows with automatic error inference. Build type-safe workflows with Result types, step caching, resume state, and human-in-the-loop support.

Package Exports

  • @jagreehal/workflow
  • @jagreehal/workflow/batch
  • @jagreehal/workflow/core
  • @jagreehal/workflow/resource
  • @jagreehal/workflow/visualize
  • @jagreehal/workflow/workflow

Readme

@jagreehal/workflow

Typed async workflows with automatic error inference.

Install

npm install @jagreehal/workflow

Quick Example

import { createWorkflow, ok, err, type AsyncResult } from '@jagreehal/workflow';

// Define operations that return Result types
const fetchUser = async (id: string): AsyncResult<User, 'NOT_FOUND'> => {
  const user = await db.users.find(id);
  return user ? ok(user) : err('NOT_FOUND');
};

const sendEmail = async (to: string): AsyncResult<void, 'SEND_FAILED'> => {
  const sent = await mailer.send(to, 'Welcome!');
  return sent ? ok(undefined) : err('SEND_FAILED');
};

// Create workflow - error types are inferred automatically
const workflow = createWorkflow({ fetchUser, sendEmail });

// Run workflow - step() unwraps results or exits early
const result = await workflow(async (step) => {
  const user = await step(fetchUser('123'));
  await step(sendEmail(user.email));
  return user;
});

// Handle result
if (result.ok) {
  console.log(result.value.name);
} else {
  // TypeScript knows: 'NOT_FOUND' | 'SEND_FAILED' | UnexpectedError
  console.error(result.error);
}

License

MIT