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

@ayatkevich/slon

v0.2.0

Published

## Introduction

Readme

SLON – Semantically-Loose Object Network

Introduction

SLON (Semantically-Loose Object Network) is an experimental data structure implemented in PostgreSQL. It provides a flexible and dynamic way to model relationships between objects using custom PostgreSQL types, operators, and functions. SLON is designed to facilitate complex queries and pattern matching over a network of interconnected nodes, making it suitable for representing hierarchical or graph-based data within a relational database.

Installation

To use SLON, you need to execute the provided SQL script (slon.sql) in your PostgreSQL database. This script defines the custom types, functions, operators, and the main slon table that constitute the SLON data structure.

-- Execute the SLON SQL script
\i slon.sql

Concepts

Symbols

A Symbol is the basic unit in SLON, identified by a text id. Symbols can be constructed using the @ operator.

Creation:

-- Create a symbol
SELECT @'A' AS symbol;

Special Symbol:

  • '*': A wildcard symbol that matches any symbol during equality checks.

Equality:

Two symbols are considered equal if:

  • Their ids are equal, or
  • Either symbol is the wildcard '*'.

Example:

-- Symbols equality
SELECT @'A' = @'A' AS result;  -- true
SELECT @'A' = @'B' AS result;  -- false
SELECT @'A' = @'*' AS result;  -- true

Objects

An Object in SLON is a pair of symbols: a left symbol and a right symbol. Objects can represent relationships or properties.

Construction:

-- Create an object from two symbols
SELECT @'A' | @'a' AS object;

-- Simplified syntax without '@' operator
SELECT 'A' | 'a' AS object;

Equality:

Objects are equal if:

  • Both their left symbols are equal, and
  • Both their right symbols are equal.

Pattern Matching with Wildcards:

-- Object equality with wildcard
SELECT ('A' | '*') = ('A' | 'a') AS result;  -- true
SELECT ('*' | '*') = ('B' | 'b') AS result;  -- true
SELECT ('A' | '*') = ('B' | 'b') AS result;  -- false

Nodes

A Node is an object that may optionally have a payload (another object). Nodes represent entities with potential additional data.

Construction:

-- Create a node with an effect and a payload
SELECT ('A' | 'a') & ('B' | 'b') AS node;

-- Create a node with only an effect
SELECT &('A' | 'a') AS node;

Equality:

Nodes are equal if:

  • Their effects are equal, and
  • Their payloads are equal, or
  • One of the effects is '* | *' and the payload is NULL.

Example:

-- Nodes equality
SELECT ('A' | 'a') & ('B' | 'b') = ('A' | 'a') & ('B' | 'b') AS result;  -- true
SELECT ('A' | 'a') & ('B' | 'b') = ('A' | 'a') & ('*' | 'b') AS result;  -- true
SELECT ('A' | 'a') & ('B' | 'b') = ('B' | 'b') & ('A' | 'a') AS result;  -- false

The Network (SLON Table)

The Network is represented by the slon table, which stores nodes and their relationships.

Table Structure:

CREATE TABLE "slon" (
  "node" "slon_node" NOT NULL,
  "related_to" TEXT REFERENCES "slon" ("id") ON DELETE CASCADE,
  "index" SERIAL,
  "id" TEXT PRIMARY KEY GENERATED ALWAYS AS ("index" || '. ' || ("node")."id") STORED
);

Inserting Nodes:

  • Top-Level Node:

    INSERT INTO "slon" ("node") VALUES (&('program' | 'A'));
  • Related Node:

    INSERT INTO "slon" ("node", "related_to")
    VALUES (&('trace' | 'A'), '1. program | A');

Usage

Building the Network

Example:

-- Insert a program node
WITH program AS (
  INSERT INTO "slon" ("node")
  VALUES (&('program' | 'A'))
  RETURNING id
)
-- Insert a trace node related to the program
INSERT INTO "slon" ("node", "related_to")
VALUES (&('trace' | 'A'), (SELECT id FROM program));

Querying the Network

SLON provides custom operators and functions to query nodes and their relationships.

Basic Queries:

-- Query top-level nodes
SELECT (? ('*' | '*')).id FROM "slon";

-- Query nodes matching a specific pattern
SELECT (? ('program' | '*')).id FROM "slon";

Chained Queries:

-- Query steps of all traces of any program
SELECT (? ('trace' | ? ('program' | '*')) ? ('*' | '*')).id FROM "slon";

Alternative Syntax:

SELECT
  program.id AS programId,
  trace.id AS traceId,
  step.id AS stepId
FROM
  slon_query('program' | '*') AS program,
  slon_query('trace' | program) AS trace,
  slon_query(trace, '*' | '*') AS step
ORDER BY step.index;

Pattern Matching with Wildcards

Wildcards allow for flexible pattern matching within queries.

Example:

-- Query nodes where the left symbol is 'A' and any right symbol
SELECT (? ('A' | '*')).id FROM "slon";

Use Cases

Simplified PostgreSQL Schema Navigation

SLON can simplify navigating and querying the PostgreSQL schema.

Inserting Tables and Columns into SLON:

WITH
  tables AS (
    INSERT INTO "slon" ("node")
    SELECT ('table' | pg_class.relname) & ('oid' | pg_class.oid::text)
    FROM pg_class
    WHERE relkind = 'r' AND relnamespace = 'public'::regnamespace
    RETURNING id
  ),
  columns AS (
    INSERT INTO "slon" ("node", "related_to")
    SELECT &('column' | pg_attribute.attname), tables.id
    FROM tables
    JOIN pg_attribute ON (tables.node).payload.right.id = pg_attribute.attrelid::text
    WHERE pg_attribute.attnum > 0
    RETURNING id
  )
SELECT * FROM tables, columns;

Querying Columns of a Specific Table:

-- Get all columns of the 'slon' table
SELECT ((? ('table' | 'slon') ? ('column' | '*')).node).id FROM "slon";

Result:

column | node
column | related_to
column | index
column | id

Testing

The provided test suite (spec.js) demonstrates various use cases and validates the behavior of the SLON data structure.

License

This project is licensed under the MIT License.