npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@affordance/core

v0.6.0

Published

Adaptive case management with guarded steps, async execution, and pluggable storage.

Readme

@affordance/core

Compute available work from current domain facts and actor permissions. A Step's handler owns persistence, transactions, final business admission and external calls. Affordance validates state/input, evaluates Guards and invokes it once.

import { actor, caseType, createBackgroundRuntime, createEngine, stepsOf } from '@affordance/core'
import { z } from 'zod'

const State = z.object({ ein: z.string().nullable() })
const step = stepsOf(State, actor<{ id: string }>())
const definition = caseType({
  name: 'deal', state: State,
  steps: [
    step({
      name: 'record-ein', input: z.object({ ein: z.string() }),
      handler: async ({ reference, actor, input, state }) => {
        const saved = await deals.recordEin(reference, actor, input)
        return { ...state, ein: saved.ein } // Already persisted; evidence only.
      },
    }),
    step({
      name: 'notify',
      handler: async ({ reference, executionId }) => {
        await notifications.send(reference, { executionId })
        // No return: success without a diff journal.
      },
    }),
  ],
})

// Bind an authoritative loader using your adapter, e.g. storage.bindCase(definition, { load }).
const runtime = createBackgroundRuntime()
const engine = createEngine({
  storage, caseTypes: [binding],
  operations: { journalTimeoutMs: 1000 },
  launch: { runtime, leaseMs: 60_000 },
})
const result = await engine.run(caseId, 'record-ein', { actor, input: { ein: '12-3456789' } })
// result.journal.status: 'skipped' | 'recorded' | 'failed'
const { executionId } = await engine.launch(caseId, 'notify', { actor })
const execution = await engine.getExecution(executionId)
// running | completed | unresolved | resolved; null for unknown IDs and ordinary runs.
await runtime.drain() // Stop new launches and await owned tasks during application shutdown.

run waits for handler completion and a bounded optional journal attempt. launch returns after handler entry while the runtime owns the remaining work. Both use the same Promise<State | void> contract and handler context. There are no injected repositories, transaction callbacks, or completion wrappers. undefined skips the journal; a valid State produces an observed diff, even if unchanged. Returned State never becomes current Case State. Subsequent reads use the binding.

A thrown handler error propagates unchanged from run; committed effects may already exist. A launched handler error appears as unresolved status. Invalid evidence and journal failure do not reverse successful handler completion or retry business code. The journal timeout includes adapter acquisition wait. An already-started write may finish late under the original execution ID.

The supplied runtime is for a long-lived Node process and keeps outstanding tasks alive until they settle. It cannot survive process death or a serverless host freezing after a request. Such hosts need an independently owned runtime with a real handler-entry acknowledgment. A queue acceptance alone is insufficient. There is no replay, heartbeat, automatic retry, compensation or recovery worker.

Launch ownership excludes other participating launches for the same Case. Expiration leaves a block until application/operator reconciliation:

await engine.resolveExecution(executionId, { actor, reason: 'Reconciled with provider' })

Resolution is not cancellation. Leases do not fence domain or provider writes; an old handler can still write after expiry or resolution. Ordinary runs and unrelated writers do not participate. The host must authorize status and resolution.

Safe actor attribution defaults to a string actor or string actor.id, otherwise null. Configure operations.actorIdentity for another string identity. Request input and authentication objects are not journaled by this pipeline. Define Case State as the intended journal projection; schema validation applies before and after. Keep credentials and unrelated data out of that schema.

This breaking beta removes execute, executeNonAtomic, transaction-bound handler repositories and the atomic adapter port. Framework journal/lease data is not migrated. See architecture.