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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@runtimed/schema

v0.3.0

Published

Schema definitions for Anode - event-sourced notebook system

Readme

@runtimed/schema

LiveStore schema for Anode notebooks, defining events, tables, and types with conflict-free cell ordering and real-time collaboration support.

Usage

import { createCellBetween, events, schema, tables } from "@runtimed/schema";

// Create cells using the helper (recommended approach)
const createEvent = createCellBetween(
  {
    id: "cell-123",
    cellType: "code",
    createdBy: "my-runtime",
  },
  cellBefore, // CellReference | null
  cellAfter // CellReference | null
);
store.commit(createEvent);

// Query tables
const cells = store.query(tables.cells.select().where({ cellType: "code" }));
const outputs = store.query(
  tables.outputs.select().where({ cellId: "cell-123" })
);

Core Functions

createCellBetween

Primary helper for creating cells with proper fractional indexing. Internally uses events.cellCreated2.

createCellBetween(
  cellData: {
    id: string;
    cellType: CellType;
    createdBy: string;
  },
  cellBefore: CellReference | null,
  cellAfter: CellReference | null,
  jitterProvider?: JitterProvider
): ReturnType<typeof events.cellCreated2>

Examples:

// Insert at beginning
const event = createCellBetween(cellData, null, firstCell);

// Insert at end
const event = createCellBetween(cellData, lastCell, null);

// Insert between cells
const event = createCellBetween(cellData, cell1, cell2);

// Custom jitter for testing
const event = createCellBetween(cellData, null, null, mockJitterProvider);

moveCellBetween

Helper for repositioning existing cells with conflict-free ordering.

moveCellBetween(
  cellId: string,
  cellBefore: CellReference | null,
  cellAfter: CellReference | null,
  jitterProvider?: JitterProvider
): ReturnType<typeof events.cellMoved2>

Schema Structure

Events

Cell Lifecycle:

  • cellCreated2 - Created via createCellBetween with fractional indexing
  • cellUpdated - Content or metadata changes
  • cellDeleted - Cell removal
  • cellMoved2 - Position changes via moveCellBetween

Execution:

  • executionRequested - Queued for execution
  • executionStarted - Runtime begins processing
  • executionCompleted - Finished with success/error state

Outputs:

  • cellOutputAdded - Rich display data, stdout, stderr
  • cellOutputsCleared - Remove all outputs for cell

Runtime Management:

  • runtimeSessionStarted - New runtime connection
  • runtimeSessionHeartbeat - Keep-alive signal
  • runtimeSessionTerminated - Runtime disconnect

Tables

cells - Cell content and state

  • id, cellType, source, fractionalIndex
  • createdAt, updatedAt, createdBy
  • executionCount, lastExecutedAt

outputs - Rich execution results

  • cellId, outputType, data (MediaBundle)
  • executionCount, createdAt

executionQueue - Pending executions

  • cellId, status, requestedAt
  • startedAt, sessionId

runtimeSessions - Active runtimes

  • sessionId, runtimeType, startedAt
  • lastHeartbeatAt, capabilities

notebook - Metadata

  • id, title, createdAt, updatedAt

Key Types

type CellType = "code" | "markdown" | "sql" | "ai";

interface CellData {
  id: string;
  cellType: CellType;
  source: string;
  fractionalIndex: string;
  createdBy: string;
  executionCount: number;
}

interface CellReference {
  id: string;
  fractionalIndex: string;
}

interface MediaBundle {
  [mimeType: string]: string;
  // e.g., "text/plain", "text/html", "image/png"
}

Fractional Indexing

Cell ordering uses fractional indices to avoid conflicts during concurrent edits:

// Indices are lexicographically ordered strings
"a" < "b" < "c" < "z";
"a0" < "a1" < "a2";
"aV" < "aW" < "aX";

// Always room to insert between any two indices
fractionalIndexBetween("a", "b"); // → "aV" (example)
fractionalIndexBetween("aV", "aW"); // → "aVV"

Important Constraints

Materializer Purity: All materializers must be deterministic functions. No Date(), Math.random(), or external state access. Use event data only.

Event Immutability: Once committed, events cannot be modified. Design schema changes carefully.

Cell Creation: Always use createCellBetween instead of direct events.cellCreated2 to ensure proper indexing.

Session Overlap: Runtime restarts create new sessionId values. Handle overlapping sessions during transitions.

Concurrent Safety: Fractional indices prevent ordering conflicts when multiple clients create cells simultaneously.

Development Notes

Package Configuration:

  • package.json - npm publishing and Node.js/TypeScript compatibility

Type Safety: All events and tables are fully typed. LiveStore enforces schema at runtime.

Testing: Use createTestJitterProvider() for deterministic fractional indices in tests.

Migration from Legacy Events

Before (deprecated):

store.commit(events.cellCreated({ cellId, cellType, source, position }));

After (current):

const event = createCellBetween(
  { id: cellId, cellType, createdBy: "runtime" },
  cellBefore,
  cellAfter
);
store.commit(event);

The helper handles fractional indexing automatically and uses the current cellCreated2 event internally.