Skip to content

pumped-fn

A lightweight effect system for TypeScript with managed lifecycles and minimal reactivity.

Activation

  • load layered map → understand Scope boundary, Atom effects, ExecutionContext operations
  • follow API grid when coding
  • twoslash snippet shows canonical usage; copy + adapt

Layered map

Core Concepts

┌─────────────────────────────────────────────────────────────┐
│                         Scope                               │
│  (long-lived execution boundary)                            │
│                                                             │
│   ┌─────────┐      ┌─────────┐      ┌─────────┐            │
│   │  Atom   │ ──── │  Atom   │ ──── │  Atom   │            │
│   │ (effect)│      │ (effect)│      │ (effect)│            │
│   └─────────┘      └─────────┘      └─────────┘            │
│        │                                  │                 │
│        └──────────────┬───────────────────┘                 │
│                       ▼                                     │
│   ┌─────────────────────────────────────────────────────┐   │
│   │              ExecutionContext                       │   │
│   │  (short-lived operation with input, tags, cleanup)  │   │
│   └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘
ConceptPurpose
ScopeLong-lived boundary that manages atom lifecycles
AtomA managed effect with lifecycle (create, cache, cleanup, recreate)
ExecutionContextShort-lived context for running operations with input and tags
ControllerHandle for observing and controlling an atom's state
TagContextual value passed through execution

API grid

LayerAPIUsageTests
ScopecreateScope, scope.dispose, scope.createContextlifecycle boundary, create execution contextspackages/lite/tests/
Atomsatom, controller, presetdefine managed effects, observe state, override valuespackages/lite/tests/
ExecutionContextctx.exec, ctx.close, ctx.cleanuprun operations, manage cleanuppackages/lite/tests/
Flowflowdefine operation templates with depspackages/lite/tests/
Tagstag, tags.required, tags.optionalcontextual values through executionpackages/lite/tests/
ExtensionsLite.Extensioncross-cutting wrapResolve/wrapExec hookspackages/lite/tests/

Effect Lifecycle

Canonical twoslash

ts
import { 
atom
,
flow
,
createScope
,
tag
,
controller
} from "@pumped-fn/lite";
const
requestId
=
tag
<string>({
label
: "req.id" });
const
dbAtom
=
atom
({
factory
: async (
ctx
) => {
const
conn
= {
query
: async (
sql
: string) => ({
rows
: [] }) };
ctx
.cleanup(() =>
console
.
log
("closing db"));
return
conn
;
}, }); const
repoAtom
=
atom
({
deps
: {
db
:
dbAtom
},
factory
: (
ctx
, {
db
}) => ({
findById
: async (
id
: string) =>
db
.query(`SELECT * WHERE id = ${
id
}`),
}), }); const
getUser
=
flow
({
deps
: {
repo
:
repoAtom
},
factory
: async (
ctx
, {
repo
}) => {
return
repo
.findById(
ctx
.input as string);
}, }); const
scope
= await
createScope
();
const
ctx
=
scope
.createContext();
const
user
= await
ctx
.exec({
flow
:
getUser
,
input
: "user-123" });
await
ctx
.close();
await
scope
.dispose();

Verification

  • pnpm -F @pumped-fn/lite typecheck
  • pnpm -F @pumped-fn/lite test
  • pnpm docs:build

Released under the MIT License.