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

@valv/core

v0.7.2

Published

ORM + Access Control Layer for AI Agents

Downloads

1,333

Readme

@valv/core

The database-agnostic core of valv: the query grammar an LLM emits, the validator that checks it against your schema and policy, the policy injector, the shared SQL emitter, and the tool layer.

npm license

Most users install an adapter, not this package directly@valv/clickhouse or @valv/prisma wrap core with introspection and a dialect. See the root README for the full guide. Reach for @valv/core directly only to build a custom adapter.

What this package exports

| Area | Exports | |---|---| | Orchestration | Valv (instantiated by adapters via createValv) | | Query grammar | QuerySchema; types Query, Expr, SelectItem | | Write grammar | InsertSchema, UpdateSchema, DeleteSchema; types Insert, Update, Delete, InjectedMutation | | Policy | PolicyFn, PolicyResult, FieldPolicy, DefaultContext | | Emission | emit, emitInsert/emitUpdate/emitDelete, the Dialect interface, BASE_FUNCTIONS, FnDef, ArgSpec | | Output shape | resultSchema, ResultColumn | | Tool formats | anthropic, openai, gemini formatters; NeutralTool, ToolToggle | | Adapter contract | ValvAdapter, SchemaMap, CompiledQuery, BoundParam, MutationResult | | Errors | ValidationError, PolicyViolationError; serializeResult |

Building an adapter

Everything above the database is shared, so a new adapter is three methods plus a small dialect. The shared emit does clause assembly, parenthesisation, and parameter ordering — your dialect only says how to quote identifiers and render placeholders.

import type { ValvAdapter, SchemaMap, Query, CompiledQuery, FnDef, Dialect } from "@valv/core"
import { emit, BASE_FUNCTIONS } from "@valv/core"

const myDialect: Dialect = {
  quoteId: (id) => `"${id.replace(/"/g, '""')}"`,
  placeholder: (i) => `$${i + 1}`,
  // functions: { ...dialect-specific aggregates }
}

class MyAdapter implements ValvAdapter {
  async introspect(): Promise<SchemaMap> {
    // describe your tables → resources, fields (with coarse `type` + `nativeType`), relations
  }
  compile(query: Query, catalog: SchemaMap): CompiledQuery {
    return emit(query, catalog, myDialect)
  }
  async execute(sql: string, params?: unknown[]): Promise<unknown[]> {
    // run the parameterized statement, return rows
  }
  functions(): Record<string, FnDef> {
    return { ...BASE_FUNCTIONS, ...myDialect.functions }
  }
  // Optional — implement to support writes. The mutation is already validated
  // and policy-injected; emit it with emitInsert/emitUpdate/emitDelete and run it.
  // mutate?(m: InjectedMutation, catalog: SchemaMap): Promise<MutationResult>
}

Validation and policy injection never reach the adapter — security stays in core. A Dialect can also declare extra functions (FnDef: argument signature, return type, render), which become callable in the query grammar and are surfaced to the model through the query tool's enum. Writes are optional: implement mutate (the mutation arrives already validated and policy-injected) to opt in, or omit it for a read-only adapter.

Type-safe resource names

InferResources derives resource names from a typed client, so a misspelled policy key is a compile error:

import type { InferResources } from "@valv/core"
const valv = await createValv<typeof prisma, Ctx>(prisma)  // policy keys autocomplete

License

MIT