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

@bemedev/app-valibot

v2.5.0

Published

Valibot schemas and validation helpers for @bemedev/app

Readme

@bemedev/app-valibot

Runtime validation library powered by Valibot for @bemedev/app state machine configurations.

@bemedev/app-valibot ensures that state machine definitions adhere to strict structural integrity, valid target paths, correct state node types (atomic, compound, parallel), valid transition arrays, and properly structured actions, guards, and actor configurations before machine instantiation.


Table of Contents


Installation

pnpm add @bemedev/app-valibot valibot

Quick Start

import { validateMachine } from '@bemedev/app-valibot';

const machineConfig = {
  initial: 'idle',
  states: {
    idle: { on: { FETCH: 'loading' } },
    loading: { on: { SUCCESS: 'success', FAILURE: 'failure' } },
    success: {},
    failure: {},
  },
};

// 1. Throws ValiError if invalid
const validConfig = validateMachine(machineConfig);

// 2. Safe parse returning success status and issues
const result = validateMachine.safe(machineConfig);
if (result.success) {
  console.log('Machine configuration is valid!');
} else {
  console.error('Validation issues:', result.issues);
}

Validation API

validate / validateMachine

function validateMachine<T>(config: unknown): NodeConfig2;

Extracts all valid state targets from the configuration tree, constructs a target-constrained Config_Schema, and validates the input using v.parse. Throws a ValiError if validation fails. validate is exported as an alias for validateMachine.

validateMachine.safe

function validateMachine.safe(config: unknown): SafeParseResult

Same as validateMachine, but uses v.safeParse. Returns { success: true, output } or { success: false, issues }.

getTargetsFromConfig

function getTargetsFromConfig(node: NodeConfig2): BetterSet<string>;

Recursively inspects a state machine configuration tree and returns a BetterSet of all valid slash-separated target path strings (e.g., '/', '/idle', '/loading', '/auth/login'). These path strings are passed to transition schemas to ensure all transition target references exist within the machine tree.


Schema Architecture

1. Machine & State Hierarchy (Config_Schema, NodeConfig_Schema)

The root configuration schema validates top-level machine properties and recursive child state nodes:

  • Node Types (checkNodeType):
    • atomic: Must NOT define states or initial.
    • compound: Must define both states and initial.
    • parallel: Must define states and MUST NOT define initial.
  • Properties:
    • initial: Optional string key of the initial state for compound nodes.
    • states: Optional map of state keys to nested NodeConfig_Schema definitions (evaluated lazily via v.lazy()).
    • entry / exit: Single or array of action configurations.
    • tags: Single string or array of strings.
    • activities: Record of activity names to activity configurations.
    • description: Human-readable summary string.
    • strict: Optional boolean to enforce strict configuration rules.

2. Transitions & Edges (Transitions_Schema, TransitionConfig_Schema)

Transitions represent state changes triggered by events, timers, or transient conditions:

  • Event Transitions (on): Map of event names to single transitions or arrays of conditional transitions (SingleOrArrayT_Schema).
  • Delayed Transitions (after): Map of delay durations or delay keys to transitions.
  • Eventless Transitions (always): Array or single transition evaluated immediately upon entering a state (AlwaysConfig_Schema).
  • Transition Object Validation:
    • target: Target path string. Must match one of the valid targets collected by getTargetsFromConfig.
    • actions: Executed upon transition traversal.
    • cond / guards: Predicates that must evaluate to true for the transition to take place.
  • Ordered Guard Rules (ArrayTransitions_Schema):
    • Validates array transition orders, ensuring that fallback transitions (without guards) are placed last in transition arrays.

3. Actions (ActionConfig_Schema)

Validates action specifications in entry, exit, and transition actions:

  • String Action: Name referencing an action registered in machine options.
  • Describer Object: Object containing an execution handler and optional metadata:
    {
      exec: (state, event) => { ... },
      description: 'Updates user profile'
    }

4. Guards & Logical Trees (GuardConfig_Schema, UnionGuard_Schema)

Guards control whether a transition can trigger:

  • Named Guard: String key corresponding to a guard function in machine options.
  • Describer Guard: Object with cond predicate function and description.
  • Logical Guard Trees: Recursive boolean logic schemas:
    • and: Array of guards that must all evaluate to true.
    • or: Array of guards where at least one must evaluate to true.
    • not: Inverts the result of an inner guard.

5. Actors & Emitters (ActorConfig_Schema, ChildConfig_Schema, EmitterConfig_Schema)

Validates invoked actors and stream emitters attached to state nodes:

  • ChildConfig_Schema: Spawns sub-state machines with context mappings (contexts) and event handlers (on).
  • EmitterConfig_Schema: Manages observables/reactive streams with next emission handlers, error failure handlers, and complete (FinallyConfigSchema) completion handlers.
  • FinallyConfigSchema: Validates final action and guard pipelines executed upon actor completion.

License

MIT