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

@xpresser/abolish

v2.3.3

Published

Using Abolish validator in Xpresserjs

Readme

Xpresser Validator (Abolish)

This plugins extends xpresser's RequestEngine to provide different validation methods that abolish supports.

Installation

npm install @xpresser/abolish
# or
yarn add @xpresser/abolish

Add to your project

Add the plugin to your plugins.json file:

{
  "npm://@xpresser/abolish": true
}

Add Types (For TypeScript)

Add to the bottom your xpresser.d.ts file:

import "@xpresser/abolish/xpresser";

Import Plugin Config

Note: Make sure you have xjs-cli installed.

xjs import abolish configs

This should create a configs/abolish.(ts|js) file. where you can extend Abolish and configure it.

Http Methods

These methods are available in the http object.

  • http.validate - Validate objects on the fly.
  • http.validateAsync - Async version of http.validate.
  • http.validateQuery - Validate query object with defined rules.
  • http.validateQueryAsync - Async version of http.validateQuery.
  • http.validateBody - Validate body object with defined rules.
  • http.validateBodyAsync - Async version of http.validateBody.
  • http.validatedBody - Returns validated body set by Abolish Middleware.

If you are conversant with Abolish you should be able to understand how the methods mentioned above works.

For example if we have a controller action.

export = {
    async index(http) {
        // `http.validate`
        const [error, validatedData] = http.validate(someObject, rules);
        // `http.validateAsync`
        const [error2, validatedData2] = await http.validateAsync(someObject, rules);
        
        // `http.validateQuery`
        const [error3, validatedData3] = http.validateQuery(rules);
        // `http.validateQueryAsync`
        const [error4, validatedData4] = await http.validateQueryAsync(rules);
        
        // `http.validateBody`
        const [error5, validatedData5] = http.validateBody(rules);
        // `http.validateBodyAsync`
        const [error6, validatedData6] = await http.validateBodyAsync(rules);
        
        // `http.validatedBody`
        const validatedData7 = http.validatedBody();
        
    }
}

Abolish Middleware

This plugin provides a middleware that will validate the request body and return the validated data via http.validatedBody().

Register Middleware

To register the Middleware, add the following to your use.json file:

{
  "middlewares": {
    "Abolish": "npm://@xpresser/abolish/AbolishMiddleware.js"
  }
}

Or add it globally:

{
  "globalMiddlewares": [
    "npm://@xpresser/abolish/AbolishMiddleware.js"
  ]
}

Add Validation Routes Files

Create a file @ backend/ValidationRules.(js|ts) and add the following to it:

JS
const RoutesGuard = require("@xpresser/abolish/RoutesGuard");

// ===== Initialize RoutesGuard =====
const guard = new RoutesGuard();

// ===== Define validation for Routes =====
// ===== Syntax =====
guard["post" | "patch" | "put"]("Controller@action", rules);
guard["post" | "patch" | "put"]("/exact/path/to/route", rules);

// ===== Example =====
guard.post("AuthController@login", {
    email: "required|email",
    password: "required|min:6"
});

module.exports = guard;
TS
import RoutesGuard from "@xpresser/abolish/RoutesGuard";

// ===== Initialize RoutesGuard =====
const guard = new RoutesGuard();

// ===== Define validation for Routes =====
// ===== Syntax =====
guard["post" | "patch" | "put"]("Controller@action", rules);
guard["post" | "patch" | "put"]("/exact/path/to/route", rules);

// ===== Example =====
guard.post("AuthController@login", {
    email: "required|email",
    password: "required|min:6"
});

export = guard;

Apply Middleware

To apply the middleware, add the following to your controller middlewares;

const controller = {
    middlewares: {
        "Abolish": "*", // for all actions
        // OR
        "Abolish": "action", // for specific action
        // OR
        "Abolish": ["action1", "action2"] // for multiple actions
    }
}