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

@spanql/ql-lib

v0.1.1

Published

Isomorphic symmetrical query serialization and GNS matrix mapping library for SpanQL.

Readme

@spanql/ql-lib

Isomorphic query serialization, DSL parsing, and GNS matrix mapping utilities for SpanQL.

This is the low-level, zero-dependency engine of the SpanQL framework. It can run in any JavaScript or TypeScript environment—including browsers, servers, edge workers (Cloudflare Workers, Vercel Edge), and serverless environments—without modifications.


Installation

Install via npm:

npm install @spanql/ql-lib

Key Features

  1. Deterministic GNS Registry: Maps complex hierarchical selection paths to indexed bitmask slots based on a schema mapping config.
  2. Textual DSL Parser: Tokenizes and parses YAML-like indented queries into a query Abstract Syntax Tree (AST).
  3. Symmetrical Serialization: Symmetrical serialization of queries into compact, URL-safe wire payloads:
    • r: Root entity context ID.
    • q: Base64-encoded topology bitmask.
    • p: Serialized parameter maps.
  4. Strict Schema Verification: Verifies schema structures and enforces character whitelist guards and reserved words constraints.

Core API Reference

1. GNSRegistry

The GNSRegistry maintains a static slot allocation map of attributes, relationships, and modifiers up to a certain recursion depth.

import { GNSRegistry } from '@spanql/ql-lib';

const schemaConfig = {
  author: {
    id: 'ID',
    name: 'string',
    books: '[book]'
  },
  book: {
    id: 'ID',
    title: 'string',
    author: 'author'
  }
};

const gns = new GNSRegistry(schemaConfig, {
  rootContextIds: { author: 1, book: 2 }
});

// Lookup slot index of a selection path starting at a root context
const slotIdx = gns.lookup('author.books.title', 'author'); 
console.log(slotIdx); // -> unique integer index

// Reverse lookup of slot index back to path
const path = gns.revLookup(slotIdx, 'author');
console.log(path); // -> 'author.books.title'

2. DSL Parsing

The parseSpanQL utility converts textual query representation into an unhydrated AST.

import { parseSpanQL } from '@spanql/ql-lib';

const queryText = `
author:
  name
  books:
    title
    _limit: 5
`;

const ast = parseSpanQL(queryText);
console.log(ast.root); // -> "author"
console.log(ast.entries); // -> array of query nodes

3. Symmetrical Query Serialization

Convert logical queries into wire format parameters, and vice versa.

Encoding (Query AST/JSON -> URL parameters)

Use encodeQuery to serialize selections and parameters.

import { encodeQuery } from '@spanql/ql-lib';

const queryInput = {
  root: 'author',
  nodes: [
    { path: 'author.name' },
    { path: 'author.books.title', value: 'Dune' }
  ]
};

const wireParams = encodeQuery(queryInput, gns);
console.log(wireParams);
// -> { r: 1, q: "...", p: "[...]" }

Decoding (URL parameters -> Query tree representation)

Use decodeQuery to inflate wire parameters back to a structured Query Tree on the gateway server.

import { decodeQuery } from '@spanql/ql-lib';

const wirePayload = { r: 1, q: "...", p: "[...]" };
const queryTree = decodeQuery(wirePayload, gns);

4. Schema Verification

Ensure that the schema configuration is syntactically sound and adheres to naming guards.

import { validateSchemaConfig } from '@spanql/ql-lib';

try {
  validateSchemaConfig(schemaConfig);
  console.log('Schema is valid.');
} catch (err) {
  console.error('Validation failed:', err.message);
}

File Structure

For full architectural details of the internals of this package, refer to FILE_STRUCTURE.md.