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

@xmachines/play

v2.0.0

Published

Universal Player Architecture for XMachines

Readme

@xmachines/play

Core protocol layer for the Universal Player Architecture — defines PlayEvent, PlayError, and architectural contracts enabling loose coupling between business logic and runtime adapters.

License: MIT Version

Part of the XMachines JS monorepo.


Installation

pnpm add @xmachines/play

Node.js >= 22.0.0 required. All packages are ES modules ("type": "module").


Overview

@xmachines/play is the foundational package in the XMachines ecosystem. It defines the minimal set of types and utilities that all other @xmachines/* packages build upon:

  • PlayEvent<TPayload> — the universal event contract for Actor ↔ Infrastructure communication
  • PlayError — the typed base class for all @xmachines/* runtime errors
  • NonNullableError — thrown when a required value is null or undefined
  • assertNonNullable() — assertion utility that narrows T | null | undefined to T

These protocols implement the architectural invariants defined in the Play RFC:

| # | Invariant | Description | | ------ | -------------------------- | ------------------------------------------------------------------ | | INV-01 | Actor Authority | The Actor is the final authority; guards decide all transitions | | INV-02 | Strict Separation | Business logic never imports UI frameworks or routing libraries | | INV-04 | Passive Infrastructure | Infrastructure observes Actor signals; it never enforces guards | | INV-05 | Signal-Only Reactivity | TC39 Signals are the exclusive cross-boundary communication medium |


Usage

PlayEvent<TPayload>

The minimal event contract: any object with a type: string property. Framework-agnostic — works with XState, Robot, and any other state machine library.

import type { PlayEvent } from "@xmachines/play";

// Flexible (accepts any additional fields):
const event: PlayEvent = { type: "auth.login", userId: "user123" };

// Type-safe (with generic payload):
type LoginEvent = PlayEvent<{ userId: string; timestamp: number }>;

const loginEvent: LoginEvent = {
	type: "auth.login",
	userId: "user123",
	timestamp: Date.now(),
};

// TypeScript error: missing required field
const invalid: LoginEvent = { type: "auth.login" }; // Error!

PlayError

Base class for all @xmachines/* runtime errors. Every error has a stable scope (throwing class/module) and code (machine-readable identifier). Always branch on .code or subclass — never on .message.

import { PlayError } from "@xmachines/play";
import { NonNullableError } from "@xmachines/play/errors";

try {
	bridge.connect();
} catch (err) {
	if (err instanceof NonNullableError) {
		// err.scope === "assertNonNullable"
		// err.code  === "PLAY_NON_NULLABLE"
		console.error(`Missing value: ${err.message}`);
	} else if (err instanceof PlayError) {
		// Any other @xmachines/* error
		console.error(`[${err.scope}:${err.code}] ${err.message}`);
	} else {
		throw err;
	}
}

Extend PlayError in your own @xmachines/*-compatible packages:

import { PlayError } from "@xmachines/play";

export class MyPackageError extends PlayError {
	constructor(message: string, options?: ErrorOptions) {
		super("MyScope", "MY_PACKAGE_ERROR_CODE", message, options);
		this.name = "MyPackageError";
	}
}

assertNonNullable(value, name?)

Assertion utility that returns value typed as NonNullable<V> or throws NonNullableError. Eliminates unsafe ! non-null assertions.

import { assertNonNullable } from "@xmachines/play";

// Inject + assert in one line — no intermediate variable or `!` needed:
const actor = assertNonNullable(inject<AuthActor>("actor"), "actor");

// DOM element lookup:
const el = assertNonNullable(document.getElementById("app"), "#app");

API Summary

Exported from @xmachines/play

| Export | Kind | Description | | --------------------- | ---------- | ---------------------------------------------------------------- | | PlayEvent<TPayload> | type | Universal event contract — { type: string } & TPayload | | PlayError | class | Base class for all @xmachines/* typed errors | | NonNullableError | class | Thrown by assertNonNullable when a value is null/undefined | | assertNonNullable | function | Asserts non-null, returns narrowed value |

Exported from @xmachines/play/errors

| Export | Kind | Description | | ------------------ | ------- | --------------------------------------------------------- | | PlayError | class | Re-exported base error class | | NonNullableError | class | scope: "assertNonNullable", code: "PLAY_NON_NULLABLE" |


Error Codes

| Code | Class | Thrown When | | ------------------- | ------------------ | ---------------------------------------------------- | | PLAY_NON_NULLABLE | NonNullableError | assertNonNullable() receives null or undefined |

Other @xmachines/* packages export their own error subclasses from their respective ./errors subpath:

| Package | Import path | | ---------------------------- | ----------------------------------- | | @xmachines/play | @xmachines/play/errors | | @xmachines/play-router | @xmachines/play-router/errors | | @xmachines/play-xstate | @xmachines/play-xstate/errors | | @xmachines/play-react | @xmachines/play-react/errors | | @xmachines/play-solid | @xmachines/play-solid/errors | | @xmachines/play-vue-router | @xmachines/play-vue-router/errors |


Testing

Run tests for this package in isolation:

pnpm --filter @xmachines/play test

Or from the package directory:

pnpm test

Tests use Vitest and cover the PlayError class construction, inheritance, cause support, and subclassing patterns.


License

MIT © Mikael Karon

See LICENSE for details.