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

@pgbo/fastify

v3.1.0

Published

Fastify route factory for pgbo Business Objects — CRUD, metadata, value helps, pagination

Readme

@pgbo/fastify

Fastify route factory for @pgbo/core Business Objects. Routes are registered via projections — explicit whitelists that declare which actions, columns, and rows are reachable over HTTP.

Install

npm install @pgbo/core @pgbo/fastify fastify

Quick start

import Fastify from 'fastify'
import { createDatabase } from '@pgbo/core'
import { defineProjection } from '@pgbo/core/bo'
import { registerProjection } from '@pgbo/fastify'
import { warehouseBO, warehouseView } from './schema.js'

const warehousePublic = defineProjection(warehouseBO, {
  name: 'warehouse',
  actions: { read: true, create: true, update: true, delete: true },
})

const app = Fastify()
const db = createDatabase({ connectionString: 'postgresql://localhost/mydb' })

registerProjection(app, db, {
  projection: warehousePublic,
  view: warehouseView,
  extractContext: (req) => ({
    app,
    db,
    userId: req.headers['x-user-id'] as string,
    tenantId: req.headers['x-tenant-id'] as string,
    locale: 'en',
  }),
})

await app.listen({ port: 3000 })

Features

  • Explicit action whitelist — accidental exposure is impossible. An action is reachable only when named true in the projection.
  • Column narrowing — responses and metadata return only projected columns
  • Root WHERE — out-of-scope rows 404 even if they exist in the database
  • GET {prefix} — paginated list with search, filter, multi-column sort
  • GET {prefix}/:param — single item with composition enrichment
  • GET /bo/{projection} — narrowed metadata with labelKey fallback
  • GET /bo/{projection}/valueHelp/{vhName} — dropdown data sources
  • POST / PUT / DELETE — when whitelisted; afterWrite hooks; global-record write protection
  • POST /bo/{projection}/{actionName} — one route per whitelisted custom action
  • File / binary responses — return a FileResponse from an action handler
  • registerViewRoute — read-only paginated view endpoint (no projection)

Projections

One BO, many tailored surfaces:

import { defineProjection } from '@pgbo/core/bo'

// Public — read-only, only safe fields visible
const areaPublic = defineProjection(areaBO, {
  name: 'areaPublic',
  actions: { read: true },
  columns: ['id', 'slug', 'name'],
})

// Admin — full CRUD + one custom action; internalExport NOT whitelisted
const areaAdmin = defineProjection(areaBO, {
  name: 'areaAdmin',
  actions: { read: true, create: true, update: true, delete: true, rebuildCache: true },
})

// Published-only subset
const areaPublished = defineProjection(areaBO, {
  name: 'areaPublished',
  actions: { read: true, update: true },
  where: { status: 'PUBLISHED' },
})

All three can be registered on the same Fastify instance. The admin and public surfaces coexist without duplicating the BO definition.

Custom actions and file responses

import type { FileResponse } from '@pgbo/fastify'

export const documentBO = defineBO(documentTable, {
  actions: {
    create: {}, update: {}, delete: {},
    reverse: {
      handler: async (ctx, data) => reverseDocument(data.id),
    },
    pdf: {
      handler: async (ctx, data): Promise<FileResponse> => ({
        data: await renderPdf(data.id),
        contentType: 'application/pdf',
        filename: `${data.documentNumber}.pdf`,
        inline: true,
      }),
    },
  },
})

const documentProjection = defineProjection(documentBO, {
  name: 'document',
  actions: { read: true, create: true, reverse: true, pdf: true },
  // 'update' and 'delete' NOT whitelisted — even though they exist on the BO
})
  • Custom action returning a value → JSON body, status 200
  • Custom action returning undefined / null → status 204 (no body)
  • Custom action returning FileResponse → binary body with Content-Type + Content-Disposition

Full documentation: https://tim-riep.github.io/pgbo/. Source and issues: https://github.com/tim-riep/pgbo.

License

MIT © Tim Riep