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

anbaric-state-machine

v1.20.1

Published

This is the state machine library that one can use to add state management to an application. It will, by default, be locally runnable but can deployed to the Anbaric Cloud via the CLI

Downloads

6,003

Readme

anbaric-state-machine

The public state machine library: the StateMachine itself, the concrete actors, the auditor, and in-memory implementations of the anbaric-tsapi contracts. App developers usually install anbaric, which re-exports this package.

StateMachine

new StateMachine(workflowId, states, startState, dataSchema,
    persistence = JobPersistenceFactory.instance(),
    queue = QueueFactory.instance())

Construction subscribes a consumer (ConsumerFactory.instance(queue)) to the workflow, so jobs progress automatically whenever the queue delivers them. cleanUp() releases the consumer.

startJob(properties?, actor?) : Promise<Job> — validates the properties (every key must be in the schema and pass its validation; required definitions must be present), persists the job and enqueues it. startedBy is the actor's id, or the workflowId when no actor is given. Throws Invalid properties / Unauthorized.

updateJob(jobId, properties, actor) : Promise<void> — explicit change with a declared actor. Validates (required-ness is not re-checked on update), merges the changed properties through save (which audits Properties updated), re-enqueues.

executeAction(jobId, action) : Promise<void> — runs one action now, its embedded actor as the responsible party. Refuses when the action's predicate rejects the job (Action predicate unmet) or when the returned properties fail the schema (The action generated invalid properties). Persists the returned properties and re-enqueues.

Progression (internal, driven by the consumer): for the job's current state, every action whose predicate accepts the job is run; each returned property map is schema-validated (invalid output is discarded and audited, not applied) and merged into the job. Then transitions are evaluated in order — the first whose predicate accepts wins, at most one per progression, and transitions to undefined states are skipped. The transition is recorded in the job's history with the workflow as actor. Only when something actually changed is the job saved and re-enqueued — so multi-state flows chain automatically and an unchanged progression is a no-op. All changes are audited through a transaction flushed at the end.

Actors

Code and Human implement the Actor interface as pure identity objects: new Code(id, role = "code"), new Human(id, role). An Agent is an actor too, but carries a Client for its model calls — construct a concrete OpenAIAgent (or AnbaricServicesAgent from anbaric-services-client) rather than a bare agent. Behaviour never lives on a plain actor — an Action's run field carries the code, the actor says who is responsible.

Auditing

AuditorFactory.instance() returns the configured Auditor (a ConsoleAuditor by default, a CloudAuditor when ANBARIC_AUDITOR_TYPE=cloud). Its audit(resourceType, resourceId, actor, interactions, description, details) records who did what to which resource; the persistence bases call it for you, so app code rarely calls it directly.

In-memory implementations and factories

InMemoryJobPersistence, InMemoryQueue (implements Dequeue, with schedule releasing messages when due), PullConsumer (polls a Dequeue on an interval, re-enqueues on failure or missing subscriber).

Factories switch on environment and default to in-memory:

| Factory | Env var | cloud gives | | --- | --- | --- | | JobPersistenceFactory.instance() | ANBARIC_JOB_PERSISTENCE_TYPE | CloudJobPersistence | | QueueFactory.instance() | ANBARIC_QUEUE_TYPE | CloudQueue | | ConsumerFactory.instance(queue) | — structural — | PullConsumer when the queue supports dequeueSome, else the push CloudConsumer |

An Anbaric platform injects the cloud values into deployed apps; never set them manually in app code.