# @nodeteam/nestjs-pipes

> Pipes collection for Nest.JS app

Latest version **1.5.1** (published 2024-08-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @nodeteam/nestjs-pipes
pnpm add @nodeteam/nestjs-pipes
yarn add @nodeteam/nestjs-pipes
bun add @nodeteam/nestjs-pipes
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2024-08-06 |
| First published | 2023-02-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 178.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | NodeTeam |
| Maintainers | nodeteamdev |
| Keywords | nestjs, pipes, prisma |

## Links

- npm: https://www.npmjs.com/package/@nodeteam/nestjs-pipes
- Repository: https://github.com/nodeteamdev/nestjs-pipes
- Homepage: https://github.com/nodeteamdev/nestjs-pipes#readme
- Issues: https://github.com/nodeteamdev/nestjs-pipes/issues
- npm.io page: https://npm.io/package/@nodeteam/nestjs-pipes

## Dependencies (5)

- [jest](https://npm.io/package/jest.md) ^29.4.2
- [ts-jest](https://npm.io/package/ts-jest.md) ^29.0.5
- [typescript](https://npm.io/package/typescript.md) ^4.9.5
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^9.3.8
- [@nestjs/testing](https://npm.io/package/@nestjs/testing.md) ^9.3.8

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.5.1 (latest) — 2024-08-06
- 1.5.0 — 2024-08-06
- 1.2.5 — 2023-05-26
- 1.2.4 — 2023-05-25
- 1.2.3 — 2023-05-25
- 1.2.2 — 2023-05-11
- 1.2.1 — 2023-03-20
- 1.2.0 — 2023-03-14
- 1.1.3 — 2023-02-10
- 1.1.2 — 2023-02-10
- 1.1.1 — 2023-02-10
- 1.1.0 — 2023-02-10
- 1.0.9 — 2023-02-10
- 1.0.8 — 2023-02-10
- 1.0.7 — 2023-02-10
- … 7 more at https://npm.io/package/@nodeteam/nestjs-pipes/versions

## README

# Installation

```bash
npm install --save @nodeteam/nestjs-pipes
```

# Usage

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

# #OrderByPipe

```typescript
@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:
```typescript
  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))`

```typescript
@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
```

* Select user who has the email `super-admin@gmail.com` or `verified` users but exclude user whose email contains `test@gmail.com`.
```
https://example.com/?where=OR:[ email: contains super-admin@gmail.com, isVerified: equals boolean(true) ],  NOT: email: contains sendgridupboost@gmail.com
```

# 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:
```typescript
  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

```typescript
@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:
```typescript
  it('should transform string user like { user:true }', () => {
    const value = 'user';

    const result = pipe.transform(value);

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

---
_Source: https://npm.io/package/@nodeteam/nestjs-pipes · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
