Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@prisma-utils/nestjs-request-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma-utils/nestjs-request-parser - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

26

CHANGELOG.md

@@ -0,1 +1,27 @@

# [1.1.0](https://github.com/prisma-utils/prisma-utils/compare/@prisma-utils/nestjs-request-parser@1.0.1...@prisma-utils/nestjs-request-parser@1.1.0) (2022-07-14)
### :bug: Bug Fixes
* get rid of logger ([b7d6a76](https://github.com/prisma-utils/prisma-utils/commit/b7d6a76de22315e56426f7fc23fe2ab02e38878b))
* release script - again ([16e43cb](https://github.com/prisma-utils/prisma-utils/commit/16e43cb3acbe209df58d95e2b98b9dd3ca9eb192))
* **request-parser:** pass options to decorator ([9f80d1e](https://github.com/prisma-utils/prisma-utils/commit/9f80d1ef32c64e9e8abeb78d27a668f8413cd2cb))
* trigger release ([9869203](https://github.com/prisma-utils/prisma-utils/commit/986920360f71906bbdc988cc073cec7716b6eb68))
* trigger release ([1c340df](https://github.com/prisma-utils/prisma-utils/commit/1c340df3723b0c1f8f68a130fa2e60bef84af969))
* trigger release ([8dd0e2d](https://github.com/prisma-utils/prisma-utils/commit/8dd0e2d26d061e552295b11dc141aa912e721218))
* update docs and trigger new version ([633944e](https://github.com/prisma-utils/prisma-utils/commit/633944e297f74bf9cbaa96abee119c07373a170f))
* update release script ([9cc6541](https://github.com/prisma-utils/prisma-utils/commit/9cc65411aab268860b77b3218ed4aa7073980f37))
### :memo: Documentation
* minor change ([7712302](https://github.com/prisma-utils/prisma-utils/commit/77123024ce4bab74f05058156c6c60f401754dd3))
* **request-parser:** update docs ([e623f05](https://github.com/prisma-utils/prisma-utils/commit/e623f0581146a21218d16db0fae19b826974de11))
### :sparkles: Features
* change to fragments ([df5ca66](https://github.com/prisma-utils/prisma-utils/commit/df5ca661e66f45b0841c7f03ac0e98890fbc65f8))
* prisma 4 ([7f3081b](https://github.com/prisma-utils/prisma-utils/commit/7f3081b5184770904dc1483d1714478c3bf19cc3))
## [1.0.1](https://github.com/prisma-utils/prisma-utils/compare/@prisma-utils/nestjs-request-parser@1.0.0...@prisma-utils/nestjs-request-parser@1.0.1) (2022-06-30)

@@ -2,0 +28,0 @@

4

package.json
{
"name": "@prisma-utils/nestjs-request-parser",
"version": "1.1.0",
"version": "1.2.0",
"type": "commonjs",

@@ -16,5 +16,5 @@ "publishConfig": {

"dependencies": {
"@nestjs/common": "^8.0.0"
"@nestjs/common": "^9.0.0"
},
"peerDependencies": {}
}

@@ -25,15 +25,22 @@ # Request-Parser

```bash
example.com/api/users?sort=-id,name&limit=20&page=5
example.com/api/users?sort=-id,name&limit=20&page=5&filter={"email": {"endsWith": "googlemail.com"}}
```
will return 20 entries from the 5th page (i.e., entry 81 - 100). Entries are ordered by id (descending) and name (ascending).
will return users with an email address that ends with `googlemail.com`. The route will return 20 entries from the 5th page (i.e., entry 81 - 100). Entries are ordered by id (descending) and name (ascending).
### Query Parameter Schema
| name | description | default |
| ----- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| sort | `order by` attribute. Comma separated list of attributes. `-` in front of a attribute (i.e., `-id`) means order by attribute `descending`. | `id` |
| limit | `limit` the result to a specific number of entries. Provides the possibility to set a maximum value as well | 20 |
| page | describe the page that should be retrieved (use in combination with `limit`) | 1 |
| name | description | default |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `sort` | `order by` attribute. Comma separated list of attributes. `-` in front of a attribute (i.e., `-id`) means order by attribute `descending`. | `id` |
| `limit` | `limit` the result to a specific number of entries. Provides the possibility to set a maximum value as well | 20 |
| `page` | describe the page that should be retrieved (use in combination with `limit`) | 1 |
| `filter` | describe an additional filter/where clause that may be appended to the `findX` call. | `{}` |
#### Filter
The `filter` parameter should be passed as an object. Please note that this library does not validate / properly parse the passed object. Basically, you are free to use whatever style / format you would like. It would, however, be a good idea to use a similar idea as Prisma does (see the [official documentation](https://www.prisma.io/docs/concepts/components/prisma-client/filtering-and-sorting#filtering)).
The `filter` parameter value must be `JSON.parse`able, otherwise the default value (`{}`) is used.
### Default Configuration

@@ -51,3 +58,6 @@

"orderParamName": "sort",
"orderDefaultValue": "id"
"orderDefaultValue": "id",
"filterParamName": "filter",
"filterDefaultValue": {}
}

@@ -54,0 +64,0 @@ ```

@@ -6,2 +6,3 @@ export interface ParsedQueryModel {

sort: ParsedQuerySortModel[];
filter: object;
}

@@ -8,0 +9,0 @@ export interface ParsedQuerySortModel {

@@ -9,2 +9,4 @@ export interface RequestQueryOptions {

orderDefaultValue: string;
filterParamName: string;
filterDefaultValue: object;
}

@@ -10,3 +10,4 @@ import { ParsedQueryModel } from '../models/parsed-query.model';

private calculateSkip;
private parseFilter;
private parseSort;
}

@@ -9,2 +9,4 @@ "use strict";

maxLimit: 100,
filterParamName: 'filter',
filterDefaultValue: {},
pageParamName: 'page',

@@ -31,2 +33,3 @@ pageDefaultValue: 1,

const sort = this.parseSort();
const filter = this.parseFilter();
return {

@@ -37,7 +40,8 @@ page: page,

sort: sort,
filter: filter,
};
}
parsePage() {
const pageParam = this.query[this.options.pageParamName];
const page = parseInt(pageParam) || this.options.pageDefaultValue;
const pageRequestData = this.query[this.options.pageParamName];
const page = parseInt(pageRequestData) || this.options.pageDefaultValue;
if (page < 1) {

@@ -49,4 +53,4 @@ return this.options.pageDefaultValue;

parseLimit() {
const limitParam = this.query[this.options.limitParamName];
let limit = parseInt(limitParam) || this.options.limitDefaultValue;
const limitRequestData = this.query[this.options.limitParamName];
let limit = parseInt(limitRequestData) || this.options.limitDefaultValue;
if (limit < 1) {

@@ -63,6 +67,18 @@ limit = this.options.limitDefaultValue;

}
parseFilter() {
let filter = {};
const filterRequestData = this.query[this.options.filterParamName] ||
this.options.filterDefaultValue;
try {
filter = JSON.parse(filterRequestData);
}
catch (e) {
return filter;
}
return filter;
}
parseSort() {
const sort = [];
const sortParam = this.query[this.options.orderParamName] || this.options.orderDefaultValue;
const sortQuery = sortParam.trim();
const sortRequestData = this.query[this.options.orderParamName] || this.options.orderDefaultValue;
const sortQuery = sortRequestData.trim();
if (sortQuery !== undefined) {

@@ -69,0 +85,0 @@ if (sortQuery.length > 0) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc