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 🙏

© 2025 – Pkg Stats / Ryan Hefner

amparo-fastify

v0.1.60

Published

meta framework for beautiful, more expressive, safer typescript

Readme

556212E4-1A73-4B3D-8E2F-AFDA8EBBD088

amparo

Making Express controllers incredibly clean, type-safe, and readable while handling all error cases elegantly.

amparo empowers developers to write expressive, type-safe, and robust APIs by abstracting complexity and enforcing strict patterns, making it the perfect choice for modern Express applications.

amparo is a framework built to enforce type safety and simplify error handling in Express applications. It eliminates the need for try/catch blocks and promotes explicit response types for controller helpers, ensuring robust and predictable behavior. By abstracting repetitive patterns and focusing on readability, amparo empowers developers to write maintainable and elegant code.

Core Value Propositions

No try/catch Blocks - Elegant, Centralized Error Handling:

Simplifies edge-case management without requiring try/catch blocks. Allows for declarative and type-safe error handling with utilities like safe and assert.

Readable Async Flows:

Transform async/await into expressive, maintainable flows. Abstract away complex controller patterns while keeping the code concise and expressive.

Enforced Very Strong Type Safety That Balances Flexibility:

Enforce explicit response types for controller helpers, ensuring predictable and consistent API responses. Use generics to eliminate type ambiguity and runtime errors.


Key Features

safe

The safe function ensures that asynchronous operations are robustly handled, with overloads to accommodate custom error handlers or throwing typed errors. This makes error handling declarative, type-safe, and clean.

Overloads and Examples

Using a Custom Error Handler:
const result = await safe(
  asyncFunction(),
  (error) => ['Custom error message', ErrorName.internalServerError],
);
Throwing a Custom Error with a Message and Name:
const result = await safe(
  asyncFunction(),
  'Operation failed',
  ErrorName.badRequest,
);
Generic Promise Resolution:
const result = await safe(asyncFunction());

Each overload ensures the safe utility adapts to your needs while maintaining clarity and robustness in error handling.

Explicit Response Types for Controller Helpers

Controllers in amparo enforce strict type safety by requiring explicit response types for all controller helpers. This ensures that all API responses are predictable and maintainable.

The following example demonstrates how amparo enforces explicit types and simplifies complex controller patterns:

type ControllerHelper<T extends AppRequestVariant> = (
	request: AppRequest<T>,
	response: Response,
) => Promise<{
	request: AppRequest<T>;
	response: Response;
	data: unknown;
}>;

type ControllerBuilder = <T extends AppRequestVariant>(
	controllerHelper: ControllerHelper<T>,
) => (
	request: Request,
	responss: Response,
	next: NextFunction,
) => Promise<void>;
import controllerBuilder from './controllerBuilder';

// === Sign in ===

const signInControllerHelper = async (
	request: AppRequest<SigninRequest>,
	response: Response,
) => {
	const {
		body: { email, password },
	} = request;

	const {
		rows: [{ user_id: userId, password: hashedPassword, name }],
	} = assertWithTypeguard(
		await safe(
			pool.query<Pick<User, 'user_id' | 'password' | 'name'>>(
				'SELECT user_id, password, name FROM protected.users WHERE email = $1',
				[email],
			),
			'Error querying user',
			ErrorName.internalServerError,
		),
		hasRowsInResult,
		'Invalid email or password',
		ErrorName.authentication,
	);

	assert(
		await bcrypt.compare(password, hashedPassword),
		'Invalid email or password',
		ErrorName.authentication,
	);

	const token = assert(
		jwt.sign({ _id: userId }, environment.JWT_SECRET),
		'Error signing token',
		ErrorName.internalServerError,
	);

	response.cookie('token', token, {
		httpOnly: true,
		secure: true,
		domain: environment.API_DOMAIN,
		sameSite: 'strict',
		signed: true,
	});

	return {
		request,
		response,
		data: { message: 'User signed in successfully', username: name },
	};
};

const signinController = controllerBuilder(signInControllerHelper);

Benefits Recap

  • No try/catch blocks
  • Explicit Type Safety: Enforce response types to ensure consistent and predictable API behavior.
  • Elegant Error Handling: Simplify async error management without using try/catch.
  • Readable and Maintainable Code: Focus on core business logic with minimal boilerplate.

Making Express controllers incredibly clean, type-safe, and readable while handling all error cases elegantly.

amparo empowers developers to write expressive, type-safe, and robust APIs by abstracting complexity and enforcing strict patterns, making it the perfect choice for modern Express applications.