@r5v/mongoose-paginate 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -4
- package/dist/aggregationPagingQuery.js +2 -2
- package/dist/pagingQuery.js +2 -2
- package/dist/types/aggregationPagingQuery.d.ts +2 -2
- package/dist/types/aggregationPagingQuery.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/types/index.d.ts +59 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,9 +89,11 @@ PagingQuery(Express.Request, mongoose.Model, options )
|
|
|
89
89
|
| Key | Value | Description | Class Availability | Required | Default |
|
|
90
90
|
|:----------------------------|:---------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------|:---------|:--------|
|
|
91
91
|
| disablePaging | boolean | disables paging and $paging param use | PagingQuery, AggregationPagingQuery | | false |
|
|
92
|
-
|
|
|
93
|
-
|
|
|
94
|
-
|
|
|
92
|
+
| disableFilter | boolean | disables the $filter param on req. | PagingQuery | | false |
|
|
93
|
+
| enableFilter | boolean | enables the $filter param on req for aggregation queries. | AggregationPagingQuery | | false |
|
|
94
|
+
| enablePreSort | boolean | enables the $preSort param on req for aggregation queries. | AggregationPagingQuery | | false |
|
|
95
|
+
| single | boolean | disables paging on the query. converts from .find query to .findOne() | PagingQuery | | false |
|
|
96
|
+
| enablePostFilter | boolean | enables the ability to create a dynamic filter per request using the $postFilter parameter | AggregationPagingQuery | | false |
|
|
95
97
|
| staticPostFilter | Mongo Filter Object | create a filter on the pipeline that is added after all the pipeline stages. this cannot be overwritten by params | AggregationPagingQuery | | {} |
|
|
96
98
|
| staticFilter | Mongo Filter Object | create a filter on the pipeline that is added before all the pipeline stages. on find requests, this is added to the filter object. this cannot be overwritten by params | AggregationPagingQuery | | {} |
|
|
97
99
|
| pipeline | MongoPipelineStage[] | pipeline request object. if the first item in pipeline stage is a $match or another required first stage operator. it will be placed before all other modifiers | AggregationPagingQuery | true | [] |
|
|
@@ -134,7 +136,12 @@ $ yarn run start
|
|
|
134
136
|
## NOTES
|
|
135
137
|
1. removeProtected removed from aggregation query due to inconsistent results after publication
|
|
136
138
|
|
|
137
|
-
### 1.0.
|
|
139
|
+
### 1.0.12
|
|
140
|
+
- Fix issue with AggregationPagingQuery where static post filter would not be applied if $postFilter param was not supplied
|
|
141
|
+
- updated typings on AggregationPagingQuery to include enablePostFilter, enableFilter, and enablePreSort
|
|
142
|
+
- flipped PagingQuery back to `disableFilter` instead of `enableFilter` option \# this was set incorrectly in 1.0.11 but still defaults to false
|
|
143
|
+
|
|
144
|
+
### 1.0.11
|
|
138
145
|
Fix Issue with Typescript build
|
|
139
146
|
|
|
140
147
|
### 1.0.9
|
|
@@ -91,7 +91,7 @@ class AggregationPagingQuery {
|
|
|
91
91
|
if (Object.keys(typeCastFilter).length !== 0) {
|
|
92
92
|
this.query.match(typeCastFilter);
|
|
93
93
|
}
|
|
94
|
-
if (this.options.
|
|
94
|
+
if (this.options.enablePreSort && Object.keys($preSort).length) {
|
|
95
95
|
this.query.sort($preSort);
|
|
96
96
|
}
|
|
97
97
|
if (!firstObj) {
|
|
@@ -104,7 +104,7 @@ class AggregationPagingQuery {
|
|
|
104
104
|
if ($count.length) {
|
|
105
105
|
this.createCounts();
|
|
106
106
|
}
|
|
107
|
-
if (Object.keys($postFilter).length !== 0) {
|
|
107
|
+
if ((Object.keys($postFilter).length !== 0 && enablePostFilter) || staticPostFilter !== undefined) {
|
|
108
108
|
this.query.match(typeCastPostFilter);
|
|
109
109
|
}
|
|
110
110
|
if (Object.keys($sort).length) {
|
package/dist/pagingQuery.js
CHANGED
|
@@ -43,8 +43,8 @@ class PagingQuery {
|
|
|
43
43
|
this.isJsonString = isJsonString_1.isJsonString;
|
|
44
44
|
this.initQuery = () => {
|
|
45
45
|
const { $filter, $sort, $select, $skip, $limit, $populate, $lean } = this.params;
|
|
46
|
-
const _a = this.options, { single, staticFilter, disablePaging,
|
|
47
|
-
const filter =
|
|
46
|
+
const _a = this.options, { single, staticFilter, disablePaging, disableFilter } = _a, options = __rest(_a, ["single", "staticFilter", "disablePaging", "disableFilter"]);
|
|
47
|
+
const filter = disableFilter ? Object.assign({}, staticFilter) : Object.assign(Object.assign({}, $filter), staticFilter);
|
|
48
48
|
this.query = single ? this.model.findOne(filter) : this.model.find(filter);
|
|
49
49
|
this.query.setOptions(options);
|
|
50
50
|
if (disablePaging || single) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Model, Aggregate } from "mongoose";
|
|
2
2
|
import type { Request } from "express";
|
|
3
|
-
import type { AggregateQueryOptions,
|
|
3
|
+
import type { AggregateQueryOptions, QueryParameters, AggregateQueryParsedRequestParams } from './types';
|
|
4
4
|
export declare class AggregationPagingQuery {
|
|
5
5
|
params: AggregateQueryParsedRequestParams;
|
|
6
6
|
options: AggregateQueryOptions;
|
|
7
7
|
query: Aggregate<Array<any>> | undefined;
|
|
8
8
|
protectedPaths: string[];
|
|
9
9
|
model: Model<any>;
|
|
10
|
-
constructor(req: Request<{}, any, any, Partial<
|
|
10
|
+
constructor(req: Request<{}, any, any, Partial<QueryParameters>>, model: Model<any>, options: AggregateQueryOptions);
|
|
11
11
|
findProtectedPaths: (model: Model<any>) => string[];
|
|
12
12
|
parseParams: (defaultParams: import("./types").PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams, params: import("qs").ParsedQs, isAggregate?: boolean) => import("./types").PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams;
|
|
13
13
|
isValidDateString: (value: string) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregationPagingQuery.d.ts","sourceRoot":"","sources":["../../src/aggregationPagingQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,SAAS,EAKZ,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAC,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"aggregationPagingQuery.d.ts","sourceRoot":"","sources":["../../src/aggregationPagingQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,SAAS,EAKZ,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAC,qBAAqB,EAAE,eAAe,EAAE,iCAAiC,EAAC,MAAM,SAAS,CAAA;AAQtG,qBAAa,sBAAsB;IAC/B,MAAM,EAAG,iCAAiC,CAazC;IACD,OAAO,EAAE,qBAAqB,CAK7B;IACD,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAA;IACxC,cAAc,EAAE,MAAM,EAAE,CAAK;IAC7B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;gBACL,GAAG,EAAE,OAAO,CAAC,EAAE,EAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,qBAAqB;IAQlH,kBAAkB,kCAAqB;IACvC,WAAW,sPAAc;IACzB,iBAAiB,6BAAoB;IACrC,YAAY,2BAAe;IAC3B,eAAe,mEAAkB;IACjC,wBAAwB;;MAA2B;IACnD,YAAY,aAOX;IACD,SAAS,sBAkDR;IACD,cAAc,GAAI,UAAU,GAAG,KAAG,GAAG,CAmCpC;IAED,OAAO,CAAC,qBAAqB,CAS5B;IACD,IAAI,qBAgCH;CAEJ"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import mongoose, { QueryOptions, SortOrder, AggregateOptions } from "mongoose";
|
|
2
|
+
import { ParsedQs } from "qs";
|
|
3
|
+
export interface QueryParameters extends ParsedQs {
|
|
4
|
+
$filter: string;
|
|
5
|
+
$limit: string;
|
|
6
|
+
$skip: string;
|
|
7
|
+
$sort: string;
|
|
8
|
+
$paging: "yes" | "no" | "0" | "false";
|
|
9
|
+
$populate: string;
|
|
10
|
+
$includes: string;
|
|
11
|
+
$select: string;
|
|
12
|
+
$count: string;
|
|
13
|
+
}
|
|
14
|
+
export interface StandardParsedRequestParams {
|
|
15
|
+
$filter?: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
18
|
+
$limit: number;
|
|
19
|
+
$skip: number;
|
|
20
|
+
$paging?: boolean;
|
|
21
|
+
$populate?: string[];
|
|
22
|
+
$includes?: string[];
|
|
23
|
+
$select?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface PagingQueryParsedRequestParams extends StandardParsedRequestParams {
|
|
26
|
+
$lean?: boolean;
|
|
27
|
+
$sort?: [string, SortOrder][];
|
|
28
|
+
}
|
|
29
|
+
export interface AggregateQueryParsedRequestParams extends StandardParsedRequestParams {
|
|
30
|
+
$preSort: {
|
|
31
|
+
[key: string]: SortOrder;
|
|
32
|
+
};
|
|
33
|
+
$sort: {
|
|
34
|
+
[key: string]: SortOrder;
|
|
35
|
+
};
|
|
36
|
+
$count: string[];
|
|
37
|
+
$postFilter: {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface StandardQueryOptions extends QueryOptions {
|
|
42
|
+
disablePaging?: boolean;
|
|
43
|
+
disableFilter?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface PagingQueryOptions extends StandardQueryOptions {
|
|
46
|
+
staticFilter?: {
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
};
|
|
49
|
+
single?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface AggregateQueryOptions extends StandardQueryOptions, Omit<AggregateOptions, 'comment'> {
|
|
52
|
+
disablePostFilter?: boolean;
|
|
53
|
+
disablePreSort?: boolean;
|
|
54
|
+
staticPostFilter?: {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
};
|
|
57
|
+
pipeline: mongoose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