Skip to content

Commit 5ee3af0

Browse files
committed
Merge with develop.
2 parents 4556d91 + 614753c commit 5ee3af0

17 files changed

+1132
-854
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,26 @@ app.get('/', (req, res) => {
4747
#### The middleware uses the following defaults:
4848
```js
4949
options = {
50+
use_page: false,
51+
client_db: 'mongodb',
52+
date_field: {
53+
start_at: 'created_at',
54+
end_at: 'created_at'
55+
},
5056
default: {
57+
fields: {},
58+
sort: {},
59+
filters: {},
5160
pagination: {
5261
limit: Number.MAX_SAFE_INTEGER,
5362
skip: 0,
5463
page: 1
55-
},
56-
fields: {},
57-
sort: {},
58-
filters: {}
59-
},
60-
use_page: false,
61-
client_db: 'mongodb',
62-
date_field: date_field: {
63-
start_at: 'created_at',
64-
end_at: 'created_at'
65-
}
64+
}
65+
}
6666
}
6767
```
6868
If the options are not provided, the default values will be used for the treatment of queries strings.
6969

70-
7170
### 2. Using custom configurations:
7271
```js
7372
const express = require('express')
@@ -80,7 +79,7 @@ app.use(qs({
8079
date_field: {
8180
start_at: 'timestamp',
8281
end_at: 'timestamp'
83-
}
82+
},
8483
default: {
8584
fields: {name: 1 , age: 1, number: 1, _id: 0},
8685
sort: { created_at: 'desc' },
@@ -110,11 +109,13 @@ app.use(qs({
110109

111110
For more details, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/2.-Usage-Examples) page.
112111

113-
### 3. Supported Query Strings
112+
## Supported Query Strings
114113

115114
For informations and details about the supported query strings, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/3.-Supported-Query-Strings) page.
116115

116+
## New Features
117117

118+
- Support for parser functions. For informations and details about parser functions, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/4.-Parsers) page.
118119
## Future Features
119120
- ¹Support for relational databases such as MySQL, PostgreSQL and SQLite.
120121

index.d.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ export = queryStringsParser
44
declare namespace queryStringsParser {
55
export interface QueryStringsParser {
66
(options?: IOptions): any
7+
8+
parseFields(query?: string | object, options?: IOptions): any
9+
10+
parseSort(query?: string | object, options?: IOptions): any
11+
12+
parsePagination(query?: string | object, pagination?: IPagination, use_page?: boolean): any
13+
14+
parseFilter(query?: string | object, options?: IOptions): any
15+
16+
parseDate(query?: string | object, date_fields?: IDateFields): any
717
}
818

919
export interface IOptions {
1020
default?: IDefault
1121
use_page?: boolean
1222
client_db?: string
13-
date_field?: string
23+
date_fields?: IDateFields
1424
}
1525

1626
export interface IDefault {
@@ -25,4 +35,9 @@ declare namespace queryStringsParser {
2535
skip?: number
2636
limit?: number
2737
}
38+
39+
export interface IDateFields {
40+
start_at?: string
41+
end_at?: string
42+
}
2843
}

index.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,27 @@
22

33
const read = require('./lib/read')
44

5+
56
exports = module.exports = function (params) {
6-
read.set_default()
7-
return read.options(params)
7+
return read.parser(params)
8+
}
9+
10+
exports = module.exports.parseFields = function (_query, _default) {
11+
return read.parseFields(_query, _default)
12+
}
13+
14+
exports = module.exports.parseSort = function (_query, _default) {
15+
return read.parseSort(_query, _default)
16+
}
17+
18+
exports = module.exports.parsePagination = function (_query, _default, _use_page) {
19+
return read.parsePagination(_query, _default, _use_page)
20+
}
21+
22+
exports = module.exports.parseFilter = function (_query, _default) {
23+
return read.parseFilter(_query, _default)
24+
}
25+
26+
exports = module.exports.parseDate = function (_query, _default) {
27+
return read.parseDate(_query, _default)
828
}

lib/mapper/fields.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
'use strict'
22

33
function fields(query, options) {
4+
var result = {}
45
if (query.fields) {
56
if (query.fields instanceof Array) {
6-
return processQuery(query.fields.join(','))
7+
result = processQuery(query.fields.join(','))
8+
} else {
9+
result = processQuery(query.fields)
710
}
8-
return processQuery(query.fields)
11+
return validate_fields(result, options.default.fields)
912
}
1013
return options.default.fields
1114
}
@@ -21,6 +24,10 @@ function processQuery(query) {
2124
return elems
2225
}
2326

27+
function validate_fields(_values, _default) {
28+
return Object.assign(_values, _default)
29+
}
30+
2431
exports = module.exports = {
2532
fields: fields
2633
}

0 commit comments

Comments
 (0)