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

@chrono-os/prisma-nest

v0.1.1

Published

Prisma 7 + Postgres sem os dois footguns: driver adapter impossível de esquecer e boot que prova o banco com SELECT 1 (o $connect() virou no-op). Fábrica do PrismaPg, ping reutilizável e PrismaService para NestJS.

Downloads

296

Readme

@chrono-os/prisma-nest

Prisma 7 com Postgres (@prisma/adapter-pg) sem os dois erros que o parque já pagou em separado: esquecer o driver adapter e confiar no $connect(). Entrega a fábrica do adapter, um ping reutilizável por health check e a classe base do PrismaService para NestJS.

Os dois footguns

1. super() sem adapter só quebra em runtime. No Prisma 7, new PrismaClient() sem driver adapter lança A driver adapter is required. O typecheck passa. Em class PrismaService extends PrismaClient, quem instancia é o super(), que nem aparece num grep por new PrismaClient. Aqui o super() é do pacote e sempre recebe o adapter.

2. $connect() virou no-op. Com driver adapter, $connect() só cria o pool do pg, que é preguiçoso, e resolve com o banco fora do ar (medido em 71 ms contra endereço morto no painel-conteudo; o teste tests/prisma-real.test.ts reproduz). O try/catch em volta dele é código morto e o log "Database connected" mente. O boot deste pacote roda SELECT 1 com timeout.

Nest

import { Injectable } from '@nestjs/common'
import { PrismaClient } from '@prisma/client' // ou o caminho do seu `output`
import { createPrismaService } from '@chrono-os/prisma-nest/nest'

@Injectable()
export class PrismaService extends createPrismaService(PrismaClient, {
  politicaBoot: 'avisar',          // 'falhar' derruba o boot se o banco não responder
  timeoutPingMs: 5000,
  adapter: { max: 10, connectionTimeoutMillis: 5000 },
  client: { log: ['error'] },      // resto das opções do PrismaClient, menos `adapter`
}) {}
  • 'avisar' (default) loga e sobe; rotas com banco falham até ele voltar e o /health conta a verdade. 'falhar' faz o bootstrap do Nest rejeitar.
  • adapter aceita uma função, avaliada no construtor, para ler um env validado sem tocar nele no import: adapter: () => ({ url: env.DATABASE_URL }).
  • onModuleDestroy chama $disconnect(), que fecha o pool. O Nest só chama esse hook no SIGTERM se o main.ts tiver app.enableShutdownHooks().

Fora do Nest (singleton, worker, script, Fastify)

import { criarAdapterPg, pingBanco, verificarBancoNoBoot } from '@chrono-os/prisma-nest'

export const prisma = new PrismaClient({ adapter: criarAdapterPg() })
await verificarBancoNoBoot(prisma, { politica: 'falhar' })
health.registrar('db', pingBanco(prisma, 2000)) // () => Promise<{ latenciaMs }>

O entry raiz não importa Nest.

criarAdapterPg(opts)

| Opção | Default | Nota | |---|---|---| | url | process.env.DATABASE_URL | Lida na chamada, nunca no import. | | max | 10 | Teto do pool por client. Dois clients no mesmo processo somam. | | connectionTimeoutMillis | 5000 | O default do pg é 0, que espera para sempre. | | ssl | não definido | Se a URL tiver sslmode= ou ssl=, a URL vence (regra do pg). | | schema | não definido | PrismaPgOptions.schema. | | permitirSemUrl | false | Sem URL, usa um placeholder que nunca conecta em vez de lançar. | | onPoolError | loga via logger.error | Conexão ociosa que morreu (Postgres reiniciado). | | pg | | Qualquer outra chave do pg.PoolConfig. |

Credencial fora de log e erro

Nenhuma mensagem do pacote inclui a URL. Erro de ping e de boot passa por mascararSegredos: a URL conhecida vira [DATABASE_URL], a senha solta vira *** e qualquer postgres://user:senha@ restante perde a senha. O erro que sai do pingBanco é um Error novo (com o code do Prisma preservado), sem o objeto original.

Testes

yarn test gera o client do schema de teste e roda unit + Prisma real contra endereço morto. A integração com Postgres de verdade roda com PRISMA_NEST_IT_URL definida (instruções em tests/integracao-pg.test.ts).