@r5v/mongoose-paginate 1.0.7 → 1.0.9

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 CHANGED
@@ -76,7 +76,7 @@ PagingQuery(Express.Request, mongoose.Model, options )
76
76
  | $limit | number | limit the number of returned objects | PagingQuery, AggregationPagingQuery |
77
77
  | $skip | number | skip to the next object on the request | PagingQuery, AggregationPagingQuery |
78
78
  | $paging | 'false'\|0\|'no' | turn off paging, on by default | PagingQuery, AggregationPagingQuery |
79
- | $populate | comma separated dot notation string \n books,publishers | using refs and virtuals, a dot notation string will populate the model using .populate | PagingQuery |
79
+ | $populate | comma separated dot notation string \n books,publishers | using refs and virtuals, a dot notation string will populate the model using .populate. will deep populate and select using \"authors\[name\].books\[title\],publishers\[name\]" notation | PagingQuery |
80
80
  | $select | comma separated dot notation string \n books,-_id \| -_id,-name,address.-address1 | using the select notation uses the mongoose name \| -name syntax to filter the output. use this in conjunction with the $populate query to filter keys \n ie books.title,books.publisher \| -name,books.-title | PagingQuery, AggregationPagingQuery |
81
81
  | $lean | no value needed, this will return a lean query result | returns a lean result. does not require a value | PagingQuery |
82
82
  | $sort | space separated mongoose sort string \n name -value | inserts sort into the query. In aggregation queries this will insert a sort after the existing pipeline | PagingQuery, AggregationPagingQuery |
@@ -97,6 +97,11 @@ PagingQuery(Express.Request, mongoose.Model, options )
97
97
  | 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 | [] |
98
98
  | removeProtected \(REMOVED\) | boolean | auto remove protected (select: false) for root Model | AggregationPagingQuery | | false |
99
99
 
100
+ ## Utilities
101
+ |Name| Description |
102
+ |:---|:-------------------------------------------------------------------------------------------------|
103
+ |buildPopulate| creates a populate object from dot notation string "author\[name\].books,user.publisher\[name\]" |
104
+
100
105
  ## Build
101
106
 
102
107
  ```text
@@ -127,4 +132,11 @@ $ yarn run start
127
132
 
128
133
 
129
134
  ## NOTES
130
- 1. removeProtected removed from aggregation query due to inconsistent results after publication
135
+ 1. removeProtected removed from aggregation query due to inconsistent results after publication
136
+
137
+ ### 1.0.9
138
+ Fix Issue with Typescript add buildPopulate Export
139
+
140
+ ### 1.0.8
141
+ Adds Deep Populate and Select Notation
142
+
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AggregationPagingQuery = exports.PagingQuery = void 0;
3
+ exports.buildPopulate = exports.AggregationPagingQuery = exports.PagingQuery = void 0;
4
4
  var pagingQuery_1 = require("./pagingQuery");
5
5
  Object.defineProperty(exports, "PagingQuery", { enumerable: true, get: function () { return pagingQuery_1.PagingQuery; } });
6
6
  var aggregationPagingQuery_1 = require("./aggregationPagingQuery");
7
7
  Object.defineProperty(exports, "AggregationPagingQuery", { enumerable: true, get: function () { return aggregationPagingQuery_1.AggregationPagingQuery; } });
8
+ var buildPopulateFromString_1 = require("./utils/buildPopulateFromString");
9
+ Object.defineProperty(exports, "buildPopulate", { enumerable: true, get: function () { return buildPopulateFromString_1.buildPopulate; } });
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.PagingQuery = void 0;
24
24
  const parseSortString_1 = require("./utils/parseSortString");
25
- const parsePopulateQuery_1 = require("./utils/parsePopulateQuery");
25
+ const buildPopulateFromString_1 = require("./utils/buildPopulateFromString");
26
26
  const parseParams_1 = require("./utils/parseParams");
27
27
  const isJsonString_1 = require("./utils/isJsonString");
28
28
  class PagingQuery {
@@ -54,8 +54,7 @@ class PagingQuery {
54
54
  this.query.sort($sort);
55
55
  }
56
56
  if ($populate) {
57
- const selectArr = $select && $select.split(",").map((v) => v.trim()) || [];
58
- const popArr = (0, parsePopulateQuery_1.parsePopulateArray)($populate, selectArr);
57
+ const popArr = (0, buildPopulateFromString_1.buildPopulate)($populate.join(","));
59
58
  popArr.forEach(path => {
60
59
  this.query.populate(path);
61
60
  });
@@ -65,7 +64,7 @@ class PagingQuery {
65
64
  if (!this.isJsonString($select)) {
66
65
  selectStr = $select
67
66
  .split(",")
68
- .filter(item => !($populate || []).some(p => item.trim().startsWith("p")))
67
+ .filter(item => !($populate || []).some(p => item.trim().startsWith(p)))
69
68
  .join(" ");
70
69
  }
71
70
  this.query.select(selectStr);
@@ -1,3 +1,4 @@
1
1
  export { PagingQuery } from './pagingQuery';
2
2
  export { AggregationPagingQuery } from './aggregationPagingQuery';
3
+ export { buildPopulate } from './utils/buildPopulateFromString';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AACzC,OAAO,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAA;AACzC,OAAO,EAAC,sBAAsB,EAAC,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAC,MAAM,iCAAiC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"pagingQuery.d.ts","sourceRoot":"","sources":["../../src/pagingQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,8BAA8B,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAA;AAC/E,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAA;AAQpC,qBAAa,WAAW;IACpB,MAAM,EAAE,8BAA8B,CAUrC;IACD,OAAO,EAAE,kBAAkB,CAAK;IAChC,KAAK,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAO;IAC/C,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;gBAEL,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM;IAMtF,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,SAAS,CAqChB;IACD,eAAe,mEAAkB;IACjC,WAAW,sPAAc;IACzB,IAAI,qBAuBH;CACJ"}
1
+ {"version":3,"file":"pagingQuery.d.ts","sourceRoot":"","sources":["../../src/pagingQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,8BAA8B,EAAE,kBAAkB,EAAC,MAAM,SAAS,CAAA;AAC/E,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAA;AASpC,qBAAa,WAAW;IACpB,MAAM,EAAE,8BAA8B,CAUrC;IACD,OAAO,EAAE,kBAAkB,CAAK;IAChC,KAAK,EAAE,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAO;IAC/C,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;gBAEL,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAM;IAMtF,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,SAAS,CAqChB;IACD,eAAe,mEAAkB;IACjC,WAAW,sPAAc;IACzB,IAAI,qBAuBH;CACJ"}
@@ -0,0 +1,8 @@
1
+ interface PopulateItem {
2
+ path: string;
3
+ select?: string;
4
+ populate?: PopulateItem[];
5
+ }
6
+ export declare function buildPopulate(pathString: any): PopulateItem[];
7
+ export {};
8
+ //# sourceMappingURL=buildPopulateFromString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildPopulateFromString.d.ts","sourceRoot":"","sources":["../../../src/utils/buildPopulateFromString.ts"],"names":[],"mappings":"AACA,UAAU,YAAY;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAA;CAC5B;AAED,wBAAgB,aAAa,CAAC,UAAU,KAAA,GAAE,YAAY,EAAE,CAsDvD"}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildPopulate = buildPopulate;
4
+ function buildPopulate(pathString) {
5
+ if (!pathString)
6
+ return [];
7
+ const splitPaths = (str) => {
8
+ const paths = [];
9
+ let current = '';
10
+ let depth = 0;
11
+ for (const char of str) {
12
+ if (char === '[')
13
+ depth++;
14
+ else if (char === ']')
15
+ depth--;
16
+ if (char === ',' && depth === 0) {
17
+ paths.push(current.trim());
18
+ current = '';
19
+ }
20
+ else {
21
+ current += char;
22
+ }
23
+ }
24
+ if (current)
25
+ paths.push(current.trim());
26
+ return paths;
27
+ };
28
+ const parseSegment = (segment) => {
29
+ var _a;
30
+ const match = segment.match(/^([^\[]+)(?:\[([^\]]+)\])?$/);
31
+ if (!match)
32
+ return { name: segment };
33
+ return {
34
+ name: match[1],
35
+ select: (_a = match[2]) === null || _a === void 0 ? void 0 : _a.replace(/,/g, ' ')
36
+ };
37
+ };
38
+ const paths = splitPaths(pathString).map(p => p.split('.').map(parseSegment));
39
+ const processLevel = (paths) => {
40
+ const groups = {};
41
+ for (const [first, ...rest] of paths) {
42
+ const key = first.name;
43
+ if (!groups[key])
44
+ groups[key] = { select: first.select, children: [] };
45
+ if (rest.length)
46
+ groups[key].children.push(rest);
47
+ }
48
+ return Object.entries(groups).map(([key, { select, children }]) => {
49
+ const obj = { path: key };
50
+ if (select)
51
+ obj.select = select;
52
+ if (children.length)
53
+ obj.populate = processLevel(children);
54
+ return obj;
55
+ });
56
+ };
57
+ return processLevel(paths);
58
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@r5v/mongoose-paginate",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "main": "./dist/index.js",
5
- "types": "./dist/types/index.d.ts",
5
+ "types": "./dist/index.d.ts",
6
6
  "scripts": {
7
7
  "prebuild": "rimraf dist/",
8
8
  "build": "tsc",
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,59 +0,0 @@
1
- import mongoose, { QueryOptions, SortOrder, AggregateOptions } from "mongoose";
2
- import { ParsedQs } from "qs";
3
- export interface ExpressQuery 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.PipelineStage[];
58
- }
59
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,EAAE,EAAC,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAC,QAAQ,EAAC,MAAM,IAAI,CAAC;AAE5B,MAAM,WAAW,YAAa,SAAQ,QAAQ;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,OAAO,CAAA;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,2BAA2B;IACxC,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,8BAA+B,SAAQ,2BAA2B;IAC/E,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAA;CAEhC;AACD,MAAM,WAAW,iCAAkC,SAAQ,2BAA2B;IAClF,QAAQ,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IACtC,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,CAAA;IACnC,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,WAAW,EAAE;QAAC,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;KAAC,CAAA;CAClC;AACD,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACtD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED,MAAM,WAAW,kBAAmB,SAAQ,oBAAoB;IAC5D,YAAY,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;IACrC,MAAM,CAAC,EAAE,OAAO,CAAC;CAGpB;AACD,MAAM,WAAW,qBAAsB,SAAQ,oBAAoB,EAAE,IAAI,CAAC,gBAAgB,EAAC,SAAS,CAAC;IAEjG,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAE,CAAA;IACxC,QAAQ,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAA;CACrC"}