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

@casual-simulation/aux-common

v4.2.0

Published

Common library for AUX projects

Downloads

4,842

Readme

@casual-simulation/aux-common

npm (scoped)

Core shared library for CasualOS (formerly AUX). This package provides foundational types, utilities, and infrastructure used across all CasualOS components.

Overview

aux-common is the foundation of the CasualOS platform, containing:

  • Bot System: Core bot state management, calculations, actions, and events
  • Partitions: Pluggable storage backends for bot state (memory, Yjs CRDT, remote sync)
  • WebSockets: Real-time communication infrastructure for multi-user collaboration
  • RPC Framework: Type-safe remote procedure calls with comprehensive error handling
  • Documents: Collaborative document abstractions using Yjs CRDTs
  • Math Utilities: Vector, quaternion, and rotation classes for 3D graphics
  • Common Types: Actions, events, connections, permissions, and versioning
  • Records: Data record management and WebPush notifications
  • Forms: Form validation and error handling
  • State Machines: State machine abstractions for complex workflows
  • Yjs Utilities: Helper functions and IndexedDB persistence for CRDTs

Installation

npm install @casual-simulation/aux-common

Package Structure

aux-common/
├── bots/              # Core bot system (RuntimeBot, actions, events, calculations)
├── partitions/        # Storage backends (Memory, Yjs, Remote, OtherPlayers)
├── websockets/        # WebSocket clients and inst records protocol
├── common/            # Shared types (actions, connections, versioning)
├── rpc/               # Type-safe RPC framework with error codes
├── documents/         # Collaborative document abstractions (Yjs)
├── math/              # Vector2/3, Quaternion, Rotation classes
├── records/           # Data records and WebPush notifications
├── yjs/               # Yjs helper functions and IndexedDB persistence
├── http/              # HTTP interface types
├── forms/             # Form validation and errors
├── state-machine/     # State machine abstractions
├── polyfill/          # Browser polyfills
├── utils.ts           # General utility functions
├── Errors.ts          # Error types and handling
├── Event.ts           # Event system
└── AppVersion.ts      # Version management

Core Modules

Bots (bots/)

The bot system is the heart of CasualOS, representing interactive objects with tags and behaviors.

Key Exports:

  • RuntimeBot: Core bot interface with tags and state
  • BotActions: Actions for creating, updating, and removing bots
  • BotCalculations: Calculate bot properties (positions, rotations, colors)
  • BotEvents: Event types (onClick, onCombine, onDrag, etc.)
  • BotIndex: Fast lookup tables for bot queries
  • StateUpdatedEvent: Bot state change events

Example:

import {
    createBot,
    botAdded,
    calculateBotValue,
} from '@casual-simulation/aux-common';

const bot = createBot('player1', {
    name: 'Alice',
    position: { x: 0, y: 0, z: 0 },
    color: '#ff0000',
});

const name = calculateBotValue(null, bot, 'name'); // "Alice"

See bots/README.md for detailed documentation

Partitions (partitions/)

Partitions provide pluggable storage backends for bot state, enabling different persistence and synchronization strategies.

Key Exports:

  • AuxPartition: Base partition interface
  • MemoryPartition: In-memory storage (fast, volatile)
  • YjsPartition: Local Yjs CRDT with IndexedDB persistence
  • RemoteYjsPartition: Networked Yjs with server synchronization
  • OtherPlayersPartition: Multi-user player state aggregation
  • PartitionAuthSource: Authentication coordination

Example:

import { createMemoryPartition } from '@casual-simulation/aux-common';

const partition = createMemoryPartition({
    type: 'memory',
    initialState: {},
});

partition.onBotsAdded.subscribe((bots) => {
    console.log('Bots added:', bots);
});

See partitions/README.md for detailed documentation

WebSockets (websockets/)

WebSocket infrastructure for real-time communication and inst records synchronization.

Key Exports:

  • ConnectionClient: Base WebSocket client interface
  • AuthenticatedConnectionClient: Authentication wrapper
  • InstRecordsClient: Inst records protocol (branch watching, updates, device actions)
  • WebsocketEvents: Complete protocol message types
  • MemoryConnectionClient: In-memory client for testing

Example:

import { InstRecordsClient } from '@casual-simulation/aux-common';

const instClient = new InstRecordsClient(connectionClient);

const updates$ = instClient.watchBranchUpdates({
    recordName: 'myRecord',
    inst: 'myInst',
    branch: 'main',
});

updates$.subscribe((event) => {
    if (event.type === 'updates') {
        console.log('Received updates:', event.updates);
    }
});

See websockets/README.md for detailed documentation

Common (common/)

Foundational types and utilities used throughout CasualOS.

Key Exports:

  • Action: Base action type
  • RemoteActions: Device actions and results
  • ConnectionInfo: Connection metadata
  • ConnectionIndicator: Connection tokens and credentials
  • CurrentVersion: Version vectors for synchronization
  • StatusUpdate: Progress and status messages
  • DenialReason: Permission denial reasons

Example:

import type {
    Action,
    ConnectionInfo,
    CurrentVersion,
} from '@casual-simulation/aux-common';

const action: Action = {
    type: 'show_toast',
    message: 'Hello, world!',
};

See common/README.md for detailed documentation

RPC (rpc/)

Type-safe remote procedure call framework with comprehensive error handling.

Key Exports:

  • RPCResult: Result types (success/error)
  • ErrorCodes: 100+ standardized error codes
  • RPCError: Error type with code and message
  • Procedure types: GetAccountInfoProcedure, CreateRecordProcedure, etc.

Example:

import type { GetAccountInfoProcedure } from '@casual-simulation/aux-common';

const result = await client.call('getAccountInfo', {});

if (result.success) {
    console.log('User:', result.data.user);
} else {
    console.error('Error:', result.errorCode, result.errorMessage);
}

Documents (documents/)

Collaborative document abstractions using Yjs CRDTs.

Key Exports:

  • YjsSharedDocument: Local Yjs document with persistence
  • RemoteYjsSharedDocument: Networked Yjs with server sync
  • SharedMap, SharedArray, SharedText: Collaborative data structures

Example:

import { YjsSharedDocument } from '@casual-simulation/aux-common';

const doc = new YjsSharedDocument({
    type: 'yjs',
    branch: 'my-doc',
});

const map = doc.getMap('data');
map.set('key', 'value');

See documents/README.md for detailed documentation

Math (math/)

Vector, quaternion, and rotation classes for 3D graphics and spatial calculations.

Key Exports:

  • Vector2: 2D vectors with arithmetic and geometric operations
  • Vector3: 3D vectors with cross product and direction constants
  • Quaternion: Quaternion representation of rotations
  • Rotation: High-level rotation interface with multiple construction methods

Example:

import { Vector3, Rotation } from '@casual-simulation/aux-common';

const position = new Vector3(1, 2, 3);
const direction = position.normalize();

const rotation = new Rotation({
    axis: new Vector3(0, 0, 1),
    angle: Math.PI / 2,
});

See math/README.md for detailed documentation

Yjs (yjs/)

Yjs utilities and IndexedDB persistence for CRDTs.

Key Exports:

  • YjsIndexedDBPersistence: Local storage with automatic trimming
  • getStateVector: Get version vector from Yjs document
  • createRelativePositionFromStateVector: CRDT-safe positions
  • getTextChar: Character-level text access

Example:

import {
    YjsIndexedDBPersistence,
    getStateVector,
} from '@casual-simulation/aux-common';
import * as Y from 'yjs';

const doc = new Y.Doc();
const persistence = new YjsIndexedDBPersistence('my-doc', doc);

await persistence.whenSynced;
console.log('Document loaded from IndexedDB');

const stateVector = getStateVector(doc);
console.log('State:', stateVector);

See yjs/README.md for detailed documentation

Usage Examples

Basic Bot Management

import {
    createBot,
    botAdded,
    botUpdated,
    createMemoryPartition,
} from '@casual-simulation/aux-common';

// Create partition
const partition = createMemoryPartition({
    type: 'memory',
    initialState: {},
});

// Add bot
await partition.applyEvents([
    botAdded(
        createBot('bot1', {
            name: 'My Bot',
            color: '#ff0000',
        })
    ),
]);

// Update bot
await partition.applyEvents([
    botUpdated('bot1', {
        tags: { color: '#00ff00' },
    }),
]);

// Subscribe to changes
partition.onBotsUpdated.subscribe((updates) => {
    console.log('Bots updated:', updates);
});

Calculate Bot Formulas

import {
    createBot,
    createCalculationContext,
    calculateFormulaValue,
} from '@casual-simulation/aux-common';

const bot1 = createBot('test1', {
    quantity: 10,
});
const bot2 = createBot('test2', {
    quantity: 5,
});
const bot3 = createBot('test3', {
    quantity: 5,
});

const context = createCalculationContext([bot1, bot2, bot3]);

const formula = '=math.sum(getBotTagValues("#quantity"))';
const result = calculateFormulaValue(context, formula);

console.log(result); // 20

Calculate Action Events

import {
    createBot,
    calculateFormulaEvents,
} from '@casual-simulation/aux-common';

const state = {
    test1: createBot('test1', { quantity: 10 }),
    test2: createBot('test2', { quantity: 5 }),
    test3: createBot('test3', { quantity: 5 }),
};

const formula = `
    let total = math.sum(getBotTagValues("#quantity"));
    player.toast("The total is " + total);
`;
const events = calculateFormulaEvents(state, formula);

for (let event of events) {
    if (event.type === 'local') {
        if (event.name === 'show_toast') {
            console.log('[Toast]', event.message);
        }
    }
}
// Outputs: [Toast] The total is 20

Real-Time Collaboration

import {
    InstRecordsClient,
    AuthenticatedConnectionClient,
    createRemoteClientYjsPartition,
} from '@casual-simulation/aux-common';

// Set up connection
const authClient = new AuthenticatedConnectionClient(baseClient, authSource);
const instClient = new InstRecordsClient(authClient);

// Create remote partition
const partition = await createRemoteClientYjsPartition(
    {
        type: 'yjs_client',
        client: instClient,
        recordName: 'project',
        inst: 'workspace',
        branch: 'main',
    },
    authSource
);

partition.connect();

// Watch for updates
partition.onBotsAdded.subscribe((bots) => {
    console.log('Bots added:', bots);
});

3D Calculations

import {
    Vector3,
    Rotation,
    calculateBotValue,
} from '@casual-simulation/aux-common';

const bot = createBot('player', {
    position: { x: 1, y: 2, z: 3 },
    rotation: { x: 0, y: 0, z: Math.PI / 4 },
});

const position = calculateBotValue(null, bot, 'position') as Vector3;
const rotation = calculateBotValue(null, bot, 'rotation') as Rotation;

const forward = new Vector3(0, 1, 0);
const worldForward = rotation.rotateVector3(forward);

const newPosition = position.add(worldForward.multiplyScalar(5));

Architecture

┌─────────────────────────────────────────────────────────────┐
│                        CasualOS                             │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌────────────────────────────────────────────────────┐   │
│  │              Application Layer                     │   │
│  │  (aux-vm, aux-runtime, aux-web, casualos-cli)     │   │
│  └────────────────────┬───────────────────────────────┘   │
│                       │                                     │
│  ┌────────────────────▼───────────────────────────────┐   │
│  │              @casual-simulation/aux-common         │   │
│  ├────────────────────────────────────────────────────┤   │
│  │                                                    │   │
│  │  ┌──────────┐  ┌───────────┐  ┌──────────────┐  │   │
│  │  │   Bots   │  │Partitions │  │  WebSockets  │  │   │
│  │  │          │  │           │  │              │  │   │
│  │  │ Actions  │  │  Memory   │  │ InstRecords  │  │   │
│  │  │ Events   │  │  Yjs      │  │ Connection   │  │   │
│  │  │ Calcs    │  │  Remote   │  │ Auth         │  │   │
│  │  └──────────┘  └───────────┘  └──────────────┘  │   │
│  │                                                    │   │
│  │  ┌──────────┐  ┌───────────┐  ┌──────────────┐  │   │
│  │  │   RPC    │  │ Documents │  │     Math     │  │   │
│  │  │          │  │           │  │              │  │   │
│  │  │ Errors   │  │ SharedMap │  │ Vector2/3    │  │   │
│  │  │ Results  │  │ SharedText│  │ Quaternion   │  │   │
│  │  │ Procs    │  │ Yjs CRDT  │  │ Rotation     │  │   │
│  │  └──────────┘  └───────────┘  └──────────────┘  │   │
│  │                                                    │   │
│  │  ┌──────────┐  ┌───────────┐  ┌──────────────┐  │   │
│  │  │  Common  │  │    Yjs    │  │   Records    │  │   │
│  │  │          │  │           │  │              │  │   │
│  │  │ Actions  │  │ Helpers   │  │  WebPush     │  │   │
│  │  │ Connect  │  │ IndexedDB │  │  Policies    │  │   │
│  │  │ Versions │  │ Persist   │  │  Schemas     │  │   │
│  │  └──────────┘  └───────────┘  └──────────────┘  │   │
│  │                                                    │   │
│  └────────────────────────────────────────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Key Concepts

Bot-Centric Architecture

CasualOS uses a bot-centric model where everything is a bot with tags:

  • Bots: Objects with ID and tags (key-value pairs)
  • Tags: Properties that define bot behavior and appearance
  • Actions: Events that modify bot state
  • Calculations: Compute derived properties from tags

Partition-Based Storage

Storage is abstracted through partitions:

  • Memory: Fast, volatile in-memory storage
  • Yjs: Local CRDT with IndexedDB persistence
  • Remote: Networked CRDT with server synchronization
  • OtherPlayers: Multi-user player state aggregation

Real-Time Collaboration

Multi-user collaboration via:

  • Yjs CRDTs: Conflict-free replicated data types
  • WebSocket Protocol: Inst records protocol for updates
  • State Vectors: Track document versions
  • Operational Transforms: Apply edits at specific versions

Type-Safe Communication

Type safety across the stack:

  • RPC Framework: Type-safe remote procedures
  • Zod Schemas: Runtime validation
  • Error Codes: Standardized error handling
  • Observable Streams: RxJS for reactive programming

License

AGPL-3.0-only

Related Packages

  • @casual-simulation/aux-runtime: Runtime execution engine
  • @casual-simulation/aux-vm: Virtual machine implementations
  • @casual-simulation/aux-web: Web application UI
  • @casual-simulation/aux-records: Server-side record management
  • @casual-simulation/casualos-cli: Command-line interface

Contributing

See DEVELOPERS.md for development guidelines.

Version

Current version: 3.8.1

See CHANGELOG.md for version history