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

@pg-access/core

v0.1.0

Published

Type-safe DSL and AST for declaring PostgreSQL authorization policies. Framework-agnostic, produces no SQL.

Downloads

188

Readme

@pg-access/core

Type-safe DSL and AST for declaring PostgreSQL authorization policies. Framework-agnostic and side-effect-free: it produces a plain policy tree, never SQL and never a database connection. @pg-access/postgres compiles that tree into real Row-Level Security statements; @pg-access/cli wraps both into a migration workflow.

Usage

import { and, authenticated, defineAuth, owner, publicAccess, role } from "@pg-access/core";

export default defineAuth({
  projects: {
    rows: {
      select: owner("user_id"),
      insert: and(authenticated(), owner("user_id")),
      update: owner("user_id"),
      delete: owner("user_id"),
    },
  },
  posts: {
    rows: {
      select: publicAccess(),
      update: role("editor"),
    },
  },
});

defineAuth(config) validates the config and returns an AuthNode, the AST every other package consumes. It throws on structural mistakes (an unknown operation key, an empty table, a malformed expression) so a broken config fails at load time rather than producing surprising SQL later.

Expressions

Each operation (select / insert / update / delete) takes one expression describing which rows the caller may act on:

  • owner(column) - the row's column equals the caller's user id (auth.uid() in the default Postgres dialect).
  • authenticated() - any signed-in caller.
  • publicAccess() - everyone, signed in or not.
  • role(name) - the caller's JWT carries name among its roles.
  • and(...) / or(...) / not(expr) - compose the above. not compiles to IS NOT TRUE, so an absent claim is treated as "not allowed" rather than NULL.

Omitting an operation key leaves that operation with no pg-access policy (Postgres then denies it once RLS is enabled, unless another policy grants it).

Also exported

validate(config) runs the same checks defineAuth does but returns a ValidationResult instead of throwing. OPERATIONS / isOperation are the operation-name constants and guard. The *Node types describe every node the AST can contain, for tools that walk or transform it.

See the pg-access docs for the end-to-end guide.