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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nodeteam/nestjs-pipes

v1.5.1

Published

Pipes collection for Nest.JS app

Downloads

734

Readme

Installation

npm install --save @nodeteam/nestjs-pipes

Usage

// import pipes
import { WherePipe, OrderByPipe } from '@nodeteam/nestjs-pipes';
// import types
import { Pipes } from '@nodeteam/nestjs-pipes/index';

#OrderByPipe

@Query('orderBy', OrderByPipe) orderBy?: Pipes.Order,

Examples:

  • Sort the rows by the column firstName in ascending order
https://example.com/?sortBy=firstName:asc

Test case:

  it('should convert value like "name:asc, address:desc" to { name: "asc", address: "desc" }', () => {
    const value = 'name:asc, address:desc';
    const result = pipe.transform(value);
    expect(result).toEqual({
      address: 'desc',
      name: 'asc',
    });
  });

#WherePipe

Operators realized:

in - where=zipCode: in array(11111, 22222)

lt - where=age: lt int(12)

lt - where=age: lt int(12)

lte - where=age: lte int(12)

gt - where=age: gt int(12)

gte - where=age: gte int(12)

equals - where=age: equals int(12)

not - where=age: not int(12)

contains - where=firstName: contains string(John) or where=firstName: contains John

startsWith - where=firstName: startsWith string(John) or where=firstName: startsWith John

endsWith - where=firstName: endsWith string(John) or where=firstName: endsWith John

every - where=firstName: every string(John) or where=firstName: every John

some - where=firstName: some string(John) or where=firstName: some John

none - where=firstName: none string(John) or where=firstName: none John

OR - where=OR:[ firstName: contains Jhon, lastName: contains Doe]

Where types realized:

string - where=firstName: contains string(John)

int - where=age: gt int(12)

float - where=age: gt float(12.5)

boolean - where=active: equals boolean(true)

bool - where=active: equals boolean(true)

date - where=createdAt: gt date(2019-01-01)

datetime - where=createdAt: gt datetime(2019-01-01 12:00:00)

array - where=zipCode: in array(int(111111), int(222222))

@Query('where', WherePipe) where?: Pipes.Where

Examples:

  • Select all the rows where the column firstName is equal to John
https://example.com/?where=firstName:John
  • Select all the rows where createdAt is greater than 2023-01-13 12:04:27.689
https://example.com/?where=createdAt: gt date(2023-01-13 12:04:27.689)
  • Select all rows where id is not equal to 1
https://example.com/?where=id: not int(12)
  • Select all rows where id is greater than 1 and email contains @gmail.com
https://example.com/?where=id: gt int(1), email: contains @gmail.com
  • Select all rows where ids are 1, 2 or 3 or age is 18
https://example.com/?where=OR:[id: in array(1,2,3), age: int(18)]
  • Select all rows where the user's email contains @gmail.com.
https://example.com/?where=user.email: contains @gmail.com
  • Select all users whose firstName contains Admin but exclude users whose roles are CUSTOMER.
https://example.com/?where=profile.firstName: contains Admin, NOT: roles: hasSome CUSTOMER
https://example.com/?where=OR:[ email: contains [email protected], isVerified: equals boolean(true) ],  NOT: email: contains [email protected]

WherePipe vs OrderByPipe

Examples:

  • Select all the rows where the column firstName is equal to John and sort the rows by the column firstName in ascending order
https://example.com/?where=firstName:John&sortBy=firstName:asc

Test case:

  it('should parse "OR" with array values from string "OR:[id:in array(int(1),int(2),int(3)), user: contains Jhon]"', () => {
    const string =
      "OR:[id:in array(int(1),int(2),int(3)), user: contains Jhon]";

    expect(pipe.transform(string)).toEqual({
      OR: [
        {
          id: {
            in: [1, 2, 3]
          }
        },
        {
          user: {
            contains: "Jhon"
          }
        }
      ],
    });
  });

#SelectPipe

@Query('select', SelectPipe) select?: Pipes.Select

Examples:

  • Select the columns firstName and lastName
https://example.com/?select=firstName,lastName
  • Exclude the columns firstName and lastName
https://example.com/?select=-firstName,-lastName

Test case:

  it('should transform string user like { user:true }', () => {
    const value = 'user';

    const result = pipe.transform(value);

    expect(result).toEqual({
      user: true,
    });
  });