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

@za-utils/next-decorators

v1.0.6

Published

NextJS Decorators for TypeScript

Readme

NextJS Decorators for API

A simple set of decorators for NextJS so you don't have to write a lot of code yourself

Decorators

List of all decorators in lib


####Main required decorators

@Req() - required, makes it clear that this is not anyhow what function

@ErrorHandler() - required, install an exception handler to your controller


####Request types

@All() - allow all types of incoming requests

@Get() - allow incoming requests with type GET only

@Post() - allow incoming requests with type POST only

@Delete() - allow incoming requests with type DELETE only

@Head() - allow incoming requests with type HEAD only

@Options() - allow incoming requests with type OPTIONS only

@Put() - allow incoming requests with type PUT only

@Patch() - allow incoming requests with type PATCH only


####Middlewares

@Middleware((req: Request, res: Response) => Promise<void> | void) - normal middleware, pass a function to it that takes two request and response parameters and returns nothing, it can be a regular function or asynchronous, you can throw exceptions in your function

@ExpressMiddleware((req: Request, res: Response, next: Function) => Promise<void> | void) - Express similar to middleware, takes in another parameter next, the function that it should perform


####Validation

Validation decorators can take two parameters, a scheme and a custom Ajv instance (optional)

@QuerySchema(schema, Ajv?)

@BodySchema(schema, Ajv?)

@ResponseSchema(schema, Ajv?)

How to use

First you need to import everything you need

Below I’ll just show what you can get from there

Errors

import {BaseError, MethodNotAllowedError, BadRequestError, ServerInternalError} from '@za-utils/next-decorators';

Types RequestError is generic type RequestError<T extents Error = Error> = BaseError & T;

import {RequestError} from '@za-utils/next-decorators';

Types Request & Response is generic type Request<T = any> = NextApiRequest & T & Response<T = any> = NextApiResponse & T;

import {Request, Response} from '@za-utils/next-decorators';

Required decorators

import {ErrorHandler, Req} from '@za-utils/next-decorators';

Method decorators

import {All, Get, Post, Delete, Head, Options, Put, Patch} from '@za-utils/next-decorators';

Middleware

import {Middleware, ExpressMiddleware} from '@za-utils/next-decorators';

Validators

import {QuerySchema, BodySchema, ResponseSchema} from '@za-utils/next-decorators';

Note that ResponseSchema, unlike QuerySchema and BodySchema, throws a Server Internal Error

Sample controller

Controller.ts

import {Req, Get, Post, Middleware, ErrorHandler, RequestError, Request, Response} from '@za-utils/next-decorators'; import {BodySchema} from "./index";

export class MyRoutesController {
    @Req()
    @Get()
    someGetRoute(req: Request, res: Response){
        console.log('no need to use req.send, req.json, req.end');

        return {
            some: 'answer'
        };
    }

    @Req()
    @Get()
    async asyncHandler(req: Request, res: Response){
        return {
            some: 'answer'
        };
    }

    @Req()
    @Get()
    @Middleware((req: Request, res: Response) => {
        if(!req.cookies)
            throw new Error('my custom error');
    })
    async middlewareHandler(req: Request, res: Response){
        console.log('this code will not start');

        return {
            some: 'answer'
        };
    }

    @Req()
    @Post()
    @BodySchema({
        type: 'object',
        properties: {
            some: {
                type: 'string'
            }   
        }
    })
    async middlewareHandler(req: Request, res: Response){
        return {
            ok: true,
            body: req.body
        };
    }

    @ErrorHandler()
    errorHandler(error: RequestError, req: Request, res: Response){
        console.log('im catch error', error);
    
        return {
            message: 'Sorry, its a error'
        };
    }
}

./pages/api/test.ts

import {MyRoutesController} from '../../Controller.ts';

const controller = new MyRoutesController();

export default controller.someGetRoute;

Ok, good

My web site: https://zaycev.dev/

(if it doesn’t work, then I haven’t finished everything yet, check back tomorrow)

Thanks for your attention


Alex Zaycev