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

@damatjs/types

v0.6.0

Published

Damat Types definition

Readme

@damatjs/types

Shared error classes and utility types for the Damat framework.

@damatjs/types is the lowest-level package in the Damat stack: a zero-dependency collection of HTTP-aware error classes (AppError and its subclasses) plus a small utility export. Almost every other Damat package depends on it so that errors thrown deep in the ORM, services, or workflow layers carry a consistent statusCode and machine-readable code all the way up to the HTTP boundary. If you are building on Damat, throw these errors instead of bare Errors and your HTTP handlers can map them to responses uniformly.

Part of the Damat monorepo · Full guide · Internals

Install

bun add @damatjs/types

Inside the monorepo it is consumed as a workspace package — depend on it with "*":

{
  "dependencies": {
    "@damatjs/types": "*"
  }
}

When to use

Use it when you want to:

  • Throw domain errors that already know their HTTP status and a stable error code (VALIDATION_ERROR, NOT_FOUND, UNAUTHORIZED, …).
  • Catch AppError in a single place (middleware, an error boundary) and translate it into an HTTP response without instanceof checks against many ad-hoc classes.
  • Attach structured details (e.g. field validation issues, retryAfter seconds) to an error for clients or logs.

Skip it when:

  • You need rich validation schemas — use Zod (@damatjs/deps/zod) and wrap the result in a ValidationError if you want a thrown error.
  • You want a generic, non-HTTP error type. AppError is intentionally HTTP-shaped.

Quick start

import {
  AppError,
  NotFoundError,
  ValidationError,
  RateLimitError,
} from "@damatjs/types";

function getUser(id: string) {
  const user = db.find(id);
  if (!user) throw new NotFoundError(`User ${id} not found`);
  return user;
}

// Throwing with structured details
throw new ValidationError("Invalid signup payload", {
  fields: { email: "must be a valid email" },
});

// 429 with a hint for the client
throw new RateLimitError("Too many requests", { retryAfter: 30 });

// A single catch site can map every error to a response
try {
  getUser("usr_404");
} catch (err) {
  if (err instanceof AppError) {
    // err.statusCode -> 404, err.code -> "NOT_FOUND", err.details -> undefined
    sendResponse(err.statusCode, { code: err.code, message: err.message, details: err.details });
  } else {
    throw err;
  }
}

API

All exports come from the single entry point @damatjs/types.

| Export | Kind | Summary | | --------------------- | ----- | -------------------------------------------------------------------------- | | AppError | class | Base error. statusCode, code, optional details. Defaults to 500. | | ValidationError | class | extends AppError → 400, code VALIDATION_ERROR. Takes details. | | AuthenticationError | class | extends AppError → 401, code UNAUTHORIZED. Default message. | | AuthorizationError | class | extends AppError → 403, code FORBIDDEN. Default message. | | NotFoundError | class | extends AppError → 404, code NOT_FOUND. Default message "Not found". | | RateLimitError | class | extends AppError → 429, code RATE_LIMITED. details.retryAfter?. | | initFramework | fn | Legacy no-op: logs "Framework initialized" and returns true. |

Error class reference

| Class | HTTP status | code | Constructor signature | | --------------------- | ----------- | ------------------ | ------------------------------------------------------ | | AppError | 500* | INTERNAL_ERROR* | (message, statusCode?, code?, details?) | | ValidationError | 400 | VALIDATION_ERROR | (message, details?) | | AuthenticationError | 401 | UNAUTHORIZED | (message = "Authentication required") | | AuthorizationError | 403 | FORBIDDEN | (message = "Access denied") | | NotFoundError | 404 | NOT_FOUND | (message = "Not found") | | RateLimitError | 429 | RATE_LIMITED | (message, details?: { retryAfter?: number }) |

* AppError defaults; both are overridable via constructor arguments.

Every instance exposes:

class AppError extends Error {
  readonly statusCode: number;
  readonly code: string;
  readonly details?: unknown;
}

No subpath exports — the package ships a single . entry.

How it fits

Dependencies: none (zero runtime dependencies).

In-repo dependents (depend on @damatjs/types via "*"):

  • @damatjs/framework
  • @damatjs/services (packages/service)
  • @damatjs/orm-pg (packages/orm/pg)
  • @damatjs/orm-connector (packages/orm/connector)
  • @damatjs/orm-processor (packages/orm/processor)
  • @damatjs/orm-migration (packages/orm/migration)
  • @damatjs/default (backend/default)

Because it has no dependencies, it sits at the bottom of the build graph and is safe to import from anywhere.

Documentation

License

MIT