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

@terminals-tech/graph

v0.1.0

Published

Language-first event graph system. Extract relationships from text, find patterns, and navigate event chains.

Readme

@terminals-tech/graph

Language-first event graph system. Zero dependencies. <600 lines.

Extract relationships from text, find patterns, and navigate event chains - all in pure JavaScript.

Installation

npm install @terminals-tech/graph

What This Is

Events are text. Text naturally forms graphs through language patterns (causal words, temporal markers, entity references). This package makes those implicit relationships explicit and queryable.

Instead of complex machine learning, we use simple text processing to extract tremendous value from your event data.

Quick Start

import { TextGraph, PatternMatcher, GraphProcessor } from '@terminals-tech/graph'

// Your events (from any source)
const events = [
  { id: '1', type: 'user-login', description: 'User logged in' },
  { id: '2', type: 'page-view', description: 'Dashboard opened after login' },
  { id: '3', type: 'error', description: 'Failed to load data due to timeout' },
  { id: '4', type: 'retry', description: 'System retried because of error' }
]

// Extract relationships from text
const textGraph = new TextGraph()
const graph = textGraph.buildGraph(events)

// Find what caused the error
const causes = textGraph.findCauses(graph, '3')
// Returns: events that led to the error

// Detect patterns
const matcher = new PatternMatcher()
const patterns = matcher.extractPatterns(events)
// Returns: common sequences like "login → dashboard → error"

// Scale to 100K+ events
const processor = new GraphProcessor()
events.forEach(e => processor.addEvent(e, []))
const important = processor.calculatePageRank()
// Returns: most important events by connectivity

Three Phases of Power

Phase 1: Text Graph (Ships Today)

Extract causal chains, temporal sequences, and entity relationships from natural language:

const textGraph = new TextGraph()

// Automatically finds relationships like:
// "X caused Y" → causal edge
// "A then B" → temporal edge
// "C requires D" → dependency edge

const relations = textGraph.extractRelations(
  "Settings failed to load due to network timeout"
)
// Returns: [{ type: 'causal', from: 'network timeout', to: 'failed to load' }]

Phase 2: Pattern Recognition (No ML Required)

Find recurring patterns, detect anomalies, and predict likely next events:

const matcher = new PatternMatcher()

// Find patterns
const patterns = matcher.extractPatterns(events, 3) // 3-grams
// "login → browse → purchase" occurs 47 times

// Detect anomalies
const anomalies = matcher.detectAnomalies(events)
// "Direct purchase without browsing is unusual"

// Predict next
const predictions = matcher.predictNext(events)
// "85% chance user will click save"

Phase 3: Scale & Intelligence

Handle 100K+ events with graph algorithms that run entirely in the browser:

const processor = new GraphProcessor()

// PageRank for importance
const important = processor.calculatePageRank()
// "Database connection lost" has highest impact

// Find clusters
const clusters = processor.findClusters()
// Discovers 12 independent workflows

// Navigate paths
const path = processor.findPath('login', 'purchase')
// Shows: login → browse → add-to-cart → checkout → purchase

Real-World Use Cases

Debugging Production Issues

// What caused the crash?
const causes = textGraph.findCauses(graph, 'crash-event-id')

// What else was happening?
const context = processor.getSubgraph('crash-event-id', depth: 2)

// Is this pattern unusual?
const anomalies = matcher.detectAnomalies(eventsAroundCrash)

Understanding User Journeys

// How do users get from A to B?
const paths = processor.findAllPaths('signup', 'first-purchase')

// What do successful users do differently?
const successPatterns = matcher.extractPatterns(successfulUsers)
const failurePatterns = matcher.extractPatterns(failedUsers)

Monitoring System Health

// Detect unusual patterns in real-time
eventStream.subscribe(event => {
  const anomalies = matcher.detectAnomalies(recentEvents)
  if (anomalies.length > 0) {
    alert(`Unusual pattern: ${anomalies[0].reason}`)
  }
})

Integration with @terminals-tech/core

Works seamlessly with the Terminals event store:

import terminals from '@terminals-tech/core'
import { EventGraph } from '@terminals-tech/graph'

const term = terminals.init()
const graph = new EventGraph()

// Automatic graph building from event store
term.store.subscribe((event, state) => {
  graph.processEvents(term.store.getEvents())
  
  // Real-time insights
  const predictions = graph.predictNext(term.store.getEvents())
  console.log('Next likely:', predictions[0])
})

Performance

  • Phase 1: 0ms extraction (pure regex)
  • Phase 2: 50ms for 10K events
  • Phase 3: <1s for 100K events
  • Memory: ~100 bytes per event
  • Dependencies: Zero

API Reference

TextGraph

  • extractRelations(text) - Find relationships in text
  • buildGraph(events) - Convert events to graph
  • findCauses(graph, eventId) - Find what caused an event
  • findEffects(graph, eventId) - Find what an event caused

PatternMatcher

  • extractPatterns(events, n) - Find n-gram patterns
  • detectAnomalies(events) - Find unusual sequences
  • predictNext(events) - Predict likely next events
  • findCycles(events) - Find repeating patterns

GraphProcessor

  • addEvent(event, relations) - Add incrementally
  • calculatePageRank() - Find important nodes
  • findClusters() - Group related events
  • findPath(from, to) - Navigate between events

Philosophy

We believe that language is already the most sophisticated graph representation we have. Every sentence encodes nodes (entities), edges (relationships), and weights (emphasis).

By working with language directly instead of abstracting it into matrices, we get:

  • Interpretability: Users can read the connections
  • Editability: Users can modify relationships
  • Composability: New events naturally integrate
  • Zero-shot generalization: Works on any text

License

MIT © Intuition Labs


Built with ❤️ for developers who want insights from events without the complexity of machine learning.