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

@rxova/journey-core

v0.7.0

Published

Journey core state machine.

Downloads

816

Readme

@rxova/journey-core

Headless runtime for non-linear journeys.

Install

pnpm add @rxova/journey-core
yarn add @rxova/journey-core
npm i @rxova/journey-core
bun add @rxova/journey-core

Runs in Bun-based SPAs and other standard ESM runtimes.

What You Get

  • Deterministic transition matching (first match wins).
  • Timeline + pointer navigation model (history.timeline + history.index).
  • Built-in navigation and terminal events: goToNextStep(), goToPreviousStep(), goToLastVisitedStep(), completeJourney(), terminateJourney().
  • Async guard/effect lifecycle state in snapshot.async.
  • Typed observability stream via subscribeEvent.
  • Step metadata updates via updateStepMetadata.
  • Optional persistence with schema versioning and migration hooks.

Quickstart

import { createJourneyMachine } from "@rxova/journey-core";

type StepId = "start" | "review";
type Event = "goToNextStep" | "completeJourney" | "back";
type Ctx = { name: string };

const journey = {
  initial: "start",
  context: { name: "" },
  steps: {
    start: { meta: { label: "Start" } },
    review: { meta: { label: "Review" } }
  },
  transitions: [
    { from: "start", event: "goToNextStep", to: "review" },
    { from: "review", event: "completeJourney" }
  ]
};

const machine = createJourneyMachine<Ctx, StepId, Event>(journey);
await machine.goToNextStep();
await machine.goToPreviousStep();
await machine.completeJourney();

const snapshot = machine.getSnapshot();
console.log(snapshot.history.timeline, snapshot.history.index, snapshot.currentStepId);

By default, goToNextStep() completes the machine when the current step declares no goToNextStep transition. Set completeOnNoNextStep: false in createJourneyMachine(...) options to opt out.

Behavioral Guarantees

  • Transition selection is ordered: the first matching transition wins.
  • Same-step transitions are non-reentrant: when a transition resolves to the current step id, Journey emits transition.start/transition.success but skips step.exit and step.enter.
  • send({ type: "back" }) falls back to previous-step navigation when no explicit back transition exists.
  • Once status is complete or terminated, pointer navigation and transitions no-op until resetMachine().
  • Forward navigation after moving back truncates timeline tail before appending the next step.
  • Snapshot shape is stable: currentStepId === history.timeline[history.index].

Async Lifecycle

When guards/effects are async, step async state is tracked in snapshot.async.byStep[stepId]:

  • evaluating-when: async guard in progress
  • running-effect: async effect in progress
  • error: guard/effect failed
  • idle: no active async work

clearStepError(stepId?) resets a step from error to idle.

updateContext() updates the current snapshot immediately, but it does not rebase an async transition that is already running. Async guards and effects keep the context they started with, and a running effect can later commit over a newer updateContext() call. If a context change must affect a transition, apply it before send(...) or wait for the transition promise to settle.

send(...) and convenience helpers resolve with transitioned: false and error when a guard or effect fails. They still emit transition.error and leave the source step in async error phase.

Persistence

Persistence is optional and disabled automatically if storage is unavailable.

const machine = createJourneyMachine(journey, {
  persistence: {
    key: "checkout:journey",
    version: 2,
    clearOnReset: false,
    migrate: (legacySnapshot, persistedVersion) => {
      if (persistedVersion < 2) {
        return {
          currentStepId: "start",
          history: { timeline: ["start"], index: 0 },
          context: { name: "" },
          status: "running",
          visited: { start: true, review: false },
          stepMeta: { start: undefined, review: undefined }
        };
      }
      return legacySnapshot as never;
    },
    onError: (error) => {
      console.error("Persistence error", error);
    }
  }
});

Hydration coercion is defensive: malformed timeline/index/visited/status values fall back to safe defaults.

Observability

Use subscribeEvent to inspect transition and navigation lifecycle events:

  • journey.start
  • transition.start
  • transition.success
  • transition.error
  • step.exit
  • step.enter
  • navigation.previous
  • navigation.lastVisited
  • journey.complete
  • journey.close
  • metadata.updated

Use subscribeStart(...), subscribeComplete(...), and subscribeTerminate(...) when you only care about a specific lifecycle event.

journey.start is delivered immediately to each subscribeEvent(...) listener with the machine's startup step and startup timestamp.

Transition Ergonomics

import { createTransitions, tx } from "@rxova/journey-core";

const transitions = createTransitions(
  tx.from("start").on("goToNextStep").to("review"),
  tx
    .from("review")
    .on("goToNextStep")
    .choose(
      tx.when(({ context }) => context.canSubmit).to("done", { id: "review-submit" }),
      tx.otherwise().to("review", { id: "review-stay" })
    ),
  tx.from("review").toComplete()
);