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

@greffon/query

v0.1.1

Published

Greffon query layer: Queryable, QueryPlan, provider protocol, createContext, and the in-memory reference engine.

Downloads

16

Readme

@greffon/query

The query layer of Greffon, expression trees for TypeScript: Queryable and its operators, the immutable QueryPlan a provider receives, the provider protocol, and createContext. Operators keep the Array names they mirror, so a chain reads like the array transform the reference engine runs.

This package does no I/O. A provider executes the plan — @greffon/provider-memory over fixture arrays, @greffon/provider-postgres and @greffon/provider-sqlite as parameterized SQL. One query file runs on all three.

Install

npm install @greffon/query

Usage

import { createContext, defineRelations } from "@greffon/query";

interface User  { id: number; name: string; age: number; active: boolean; orders?: Order[] }
interface Order { id: number; userId: number; total: number }
interface Schema { users: User; orders: Order }

const relations = defineRelations<Schema>({
  users: { orders: { kind: "many", target: "orders", from: "id", to: "userId" } },
});

// Any provider fits: memoryProvider(fixtures) in tests, postgres(executor, schema) in production.
const db = createContext<Schema>(provider, { relations });

const bigSpenders = await db.users
  .filter((u) => u.active && u.orders?.some((o) => o.total > 100))
  .map((u) => ({ id: u.id, name: u.name }))
  .toArray();

Every operator returns a new immutable query; nothing runs until an executor. Before any I/O the plan is checked against the provider's declared capabilities; an unsupported op or untranslatable expression fails with a located, coded error, never a silent client-side fallback. .inMemory() is the explicit escape hatch into client-side JS.

API

  • Queryable: filter, map, orderBy/thenBy (and Descending variants), take/skip, distinct, groupBy, join/leftJoin, flatMap, include/thenInclude, inMemory; the executors toArray, first, firstOrThrow, single, count, some, every, sum/min/max/avg; and explain(), the statement with no I/O run.
  • createContext(provider, { relations, computed }): db.users is a Queryable<User>; queryable roots one source.
  • defineRelations: typed navigations behind include/thenInclude, flatMap, and some/every predicates.
  • defineComputed: computed properties/methods (u.isAdult, o.net(0.1)), inlined before a provider sees the plan.
  • QueryPlan / PlanOp / IncludeSpec, with PLAN_OP_KINDS and withOp: the plan a provider receives.
  • QueryProvider / Capabilities / capabilities: the protocol — name, capabilities(), execute, explain?.
  • The shared in-memory engine (runPlanInMemory, applyOps, Grouping) plus include-stitching helpers to reuse.
  • expr / isExpr / Expr: re-exported from @greffon/core for the common single import.

@greffon/query/testing is the provider-author kit: runConformance runs a corpus (operators, joins, includes, grouping, computed members) against your provider and the in-memory reference; sample fixtures, relations, and row types are included.

Docs

License

MIT