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

entity-walker

v2.2.0

Published

A type-safe, in-memory entity graph resolver for normalized data structures in TypeScript.

Downloads

54

Readme

Entity Walker

CI

Entity Walker is a zero-dependency, type-safe TypeScript graph library for navigating relational data through intuitive traversal chains.

Model your data as a graph of entities connected by foreign keys, then traverse relationships with full TypeScript autocomplete — forward and reverse — as if you were walking through your data.


Core Idea

Instead of writing nested loops or manual joins:

transactions.map(t =>
  subcategories.find(s =>
    mainCategories.find(m => ...)
  )
)

You simply walk the graph:

graph.transaction("tx1")
  .subcategory()
  .mainCategory()
  .value()?.name

What You Can Use It For

  • Read-heavy data models (dashboards, analytics, finance apps)

  • Normalized API data (client-side joins without nesting)

  • Deep entity navigation (multi-hop relationships)

  • Reverse lookups (find all entities pointing to another)

  • Data integrity validation

  • In-memory graph exploration

  • Rich node-list API.where(), .whereNode(), .ids(), .entities(), .select(), .unique(), .intersect(), .findEntity(), .findNode(), .isEmpty() and more work directly on related entity collections.

  • Scoped Traversal — Use .scoped() to snapshot the current state of a traversal, ensuring filters from earlier steps persist across deep path jumps.

  • Functional Encapsulation — Use .with() to return values or encapsulated intersections seamlessly from within a traversal chain.

  • Consistent defaults — every node exposes .value() (safe, returns undefined when missing) and .valueOrThrow() (throws when missing). No split between optional and required at the type level.

  • Performance-friendly — indexed O(1) lookups; even rebuilding the graph per query beats nested loops at scale.

  • Proxy-free alternativecreateNonProxyGraph produces an equivalent graph for environments without Proxy support.

  • Safe Initialization — Optional emptyNode and emptyNodeList factories for robust proxy-based initialization.

  • Data integrity checksgraph.info() detects missing FK targets and orphan entities at runtime.

Installation

npm install entity-walker

Quick Example

import { createGraph, ValidSchema, GraphEdges, GraphDef, Entities, EntityGraph } from "entity-walker";

type Transaction  = { id: string; subcategoryId: string };
type Subcategory  = { id: string; name: string; mainCategoryId: string };
type MainCategory = { id: string; name: string; expenseTypeId?: string };

type Schema = ValidSchema<{
  transaction:  Transaction;
  subcategory:  Subcategory;
  mainCategory: MainCategory;
}>;

const edges = {
  transaction: {
    subcategory: { bidirectional: true, resolve: t => t.subcategoryId },
  },
  subcategory: {
    mainCategory: { bidirectional: true, resolve: s => s.mainCategoryId },
  },
} as const satisfies GraphEdges<Schema>;

type CustomGraph = GraphDef<Schema, typeof edges>;

const entities: Entities<Schema> = {
  transaction:  [{ id: "tx1", subcategoryId: "sub1" }],
  subcategory:  [{ id: "sub1", name: "Groceries", mainCategoryId: "cat1" }],
  mainCategory: [{ id: "cat1", name: "Food" }],
};

const graph: EntityGraph<CustomGraph> = createGraph({ entities, edges });

// Forward traversal
const categoryName = graph
  .transaction("tx1")
  .subcategory()
  .mainCategory()
  .value()?.name; // "Food"

// Reverse traversal
const txIds = graph
  .mainCategory("cat1")
  .subcategoryNodes()
  .transactionNodes()
  .ids(); // ["tx1"]

Detailed Guides

| Guide | Description | |---|---| | Graph | Full reference for createGraph — the standard API with clean graph.entity("id") / node.relation() syntax powered by Proxy. | | Non-Proxy Graph | Full reference for createNonProxyGraph — identical behaviour using a .to() calling convention, compatible with environments that do not support Proxy. | | Graph Modification | Update (upsert), node-level field update, delete, and cascade-delete entities at runtime with automatic index maintenance. | | Debugging | Use graph.info() to inspect entity counts, missing FK targets, and orphan entities. |

Performance & Benchmarks

Entity Walker builds an in-memory index at construction time so every lookup is O(1). Even with several rebuilding the graph out-performs hand-written nested loops at scale:

image

The benchmark compares pure indexed for loops against Entity Walker (with Proxy and without Proxy) across increasing dataset sizes with random id access patterns on multi-hop (4 relations). Entity Walker's indexed lookups dominate as dataset size grows. Proxy vs non-Proxy performance differs by a small constant factor, but both are much faster than nested loops at scale. The non-Proxy version is faster than Proxy (average ~1ms faster), but the difference is negligible compared to the gap with nested loops.