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

monolite-core

v0.9.1

Published

Kernel of the monolite toolkit: shared errors, contracts and Node-only primitives.

Readme

monolite-core

The kernel of the monolite toolkit. Every other package depends on it, which is exactly why it depends on nothing: no Express, no database driver, no DI container, no runtime dependencies at all. Anything added here becomes mandatory for every package downstream, so only the shared vocabulary lives in it — the error type BLLs throw, the mapper that turns anything thrown into an HTTP-shaped answer, the contracts other packages implement, and the two implementations that need nothing beyond Node's standard library.

Requires Node 20 or newer.

What it exports

Errors

| Export | Kind | What it is | | --- | --- | --- | | AppError | class | The error BLLs throw on purpose. Carries an HTTP status, a stable code for the client to branch on, optional field-level errors, and an ES2022 cause so the original failure is never lost. | | AppErrorOptions | type | code, errors and cause for the AppError constructor. | | ErrorDetail | type | A single { field, message } validation detail. | | normalizeError | function | Turns anything thrown — AppError, a Zod failure, a JWT error, a body-parser error, a raw driver error — into a NormalizedError. | | NormalizedError | type | { statusCode, code, message, errors?, isOperational }. | | causeChain | function | Walks the cause chain of an error, depth-bounded. |

normalizeError is where the toolkit's promise that a module behaves the same on any engine is actually kept. Oracle, PostgreSQL, MySQL/MariaDB, SQL Server and MongoDB failures are all folded into the same six outcomes (unique violation, missing required field, check violation, dangling reference, reference still in use, value too large) plus "database unavailable", so a duplicate key answers 409 DB_UNIQUE_VIOLATION whichever engine raised it. It identifies drivers by the fingerprint they leave on the error object, and it follows cause, parent and original to find it, because repositories — and Sequelize — wrap the real error several layers deep.

Zod failures are recognised structurally rather than with instanceof, so the kernel maps them without depending on Zod.

Contracts

| Export | What implements it | | --- | --- | | ILogger | The logging backend. Levels only — request-logging middleware belongs to the HTTP package. | | CurrentUser, RequestContextData, IRequestContext | The ambient request context. CurrentUser carries id, name, email and roles; the auth package fills roles in while decoding the token. | | HealthReport, IHealthProbe | Liveness and readiness, kept apart on purpose: a process whose database is down is alive but not ready. | | IConnectionCheck | The one method the health probe needs from a connection: authenticate(). | | HealthProbeOptions | Configuration for HealthProbe. |

Implementations

| Export | What it does | | --- | --- | | AsyncRequestContext | IRequestContext on top of AsyncLocalStorage. Node's equivalent of IHttpContextAccessor: the store survives every await, so a repository three layers down still sees the user of the request without being handed it. | | SYSTEM_USER | The audit name ("System") used when there is no request in flight — startup, scheduled jobs, seeds. | | HealthProbe | IHealthProbe with a short result cache and a bounded wait, so probing from several replicas does not become real load and a hung database does not hang the check. It never throws: a failed check is the answer. |

Usage

import {
  AppError,
  AsyncRequestContext,
  HealthProbe,
  normalizeError,
  SYSTEM_USER,
} from "monolite-core";

const context = new AsyncRequestContext();

// Anything run inside `run` — however deep, however async — sees this user.
await context.run(
  {
    requestId: "3f9c1a7e",
    user: { id: "42", name: "ada", email: "[email protected]", roles: ["admin"] },
  },
  async () => {
    context.getCurrentUserName(); // "ada", or SYSTEM_USER outside a request

    try {
      throw new AppError("Appointment overlaps another one", 409, true, {
        code: "APPOINTMENT_OVERLAP",
      });
    } catch (error) {
      const normalized = normalizeError(error);
      // { statusCode: 409, code: "APPOINTMENT_OVERLAP", isOperational: true, ... }
      console.log(normalized.statusCode, normalized.code);
    }
  }
);

// Readiness for a load balancer. `connection` is anything with `authenticate()`;
// leave it out for an in-memory data source and `database` reports
// "not_applicable".
const probe = new HealthProbe({ dataSource: "postgres", connection: sequelize });

await probe.report();
// { ready: true, dataSource: "postgres", database: "up", shuttingDown: false }

process.on("SIGTERM", () => {
  // From here on the probe reports `ready: false` immediately, so traffic is
  // taken away before the process actually stops accepting it.
  probe.beginShutdown();
});

License

MIT