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

@gestio-school/pkg

v0.4.0

Published

Infra comum das APIs Gestio School: multitenancy Prisma (pool único), middleware de tenant, CORS e handler das Cloud Functions

Readme

@gestio-school/pkg

Infra comum das APIs Gestio School (fonte única): multitenancy Prisma com pool único compartilhado entre escolas, middleware de tenant (:id_school da URL decide o schema) e CORS padrão.

Módulos

  • createMultitenantPrisma — fábrica: 1 pool mariadb para a instância inteira; client por escola é leve e só qualifica o database no SQL gerado. Pool sem database default (raw sem qualificar falha alto — Error 1046 — em vez de vazar para o tenant errado). Suporta ?socket=/cloudsql/... (prod) e host:porta (dev/túnel).
  • createTenantMiddleware — hook preValidation que injeta req.prisma resolvendo params.id_school → query.id_school → header x-id-school (só inteiro positivo; inválido cai no default).
  • resolveTenantId — a regra de resolução, exportada para testes/usos avulsos.
  • createCorsPlugin — CORS padrão das APIs.
  • createFunctionHandler — ponte req/res do Functions Framework → Fastify, com tratamento do boot que falha: headers de CORS no caminho de erro (senão o browser mostra "CORS error" e esconde o 5xx), erro serializado de forma legível e encerramento do processo para não servir 5xx em cache até o Cloud Run reciclar a instância.

Uso (numa API)

import mariadb from "mariadb";
import {PrismaMariaDb} from "@prisma/adapter-mariadb";
import {PrismaClient} from "./generated/client";
import {createMultitenantPrisma, createTenantMiddleware} from "@gestio-school/pkg";

const mt = createMultitenantPrisma({
  databaseUrl: process.env.DATABASE_URL!,
  PrismaClient, PrismaMariaDb, createPool: mariadb.createPool,
});
// fastify.register(mt.plugin) + fastify.register(createTenantMiddleware(mt))

Handler da Cloud Function

import fastify from "fastify";
import {createFunctionHandler} from "@gestio-school/pkg";
import app from "./app";

const server = fastify({logger: false, pluginTimeout: 30000});
server.register(app);

export const v1_exemplo = createFunctionHandler(server);

Num boot quebrado o avvio guarda o erro do primeiro ready() e toda chamada seguinte rejeita na hora com o mesmo erro — a instância devolve 5xx em todas as rotas, em ~200ms, até o Cloud Run reciclá-la. Por isso o default é responder 503 e sair (exitOnBootFailure), para a próxima request pegar instância limpa.

A lib não depende de @prisma/client/mariadb: cada API injeta o client gerado e o driver nas versões dela.

Consumo pelas APIs (npmjs público)

O pacote é publicado público no npmjs — só o dist/ compilado vai no tarball (files: ["dist"]); testes e repo continuam privados. Zero token: npm i funciona no dev, no Actions e no build do GCP.

npm i @gestio-school/pkg

Release

  1. Bump da versão no package.json (npm version patch|minor local, sem push automático).
  2. Commit + tag vX.Y.Z + push da tag → o workflow publish.yml roda testes e publica (secret NPM_TOKEN).
  3. Nas APIs: npm update @gestio-school/pkg (ou bump da range no package.json).

Testes

npm test

Inclui o teste de isolamento ponta a ponta (test/isolation.spec.ts): URL → middleware → prisma, com 50 requests concorrentes intercalando escolas — dados de uma escola nunca aparecem na resposta de outra.