@r5v/mongoose-paginate 1.0.7 → 1.0.8

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 |
@@ -127,4 +127,9 @@ $ yarn run start
127
127
 
128
128
 
129
129
  ## NOTES
130
- 1. removeProtected removed from aggregation query due to inconsistent results after publication
130
+ 1. removeProtected removed from aggregation query due to inconsistent results after publication
131
+
132
+
133
+ ### 1.0.8
134
+
135
+ Adds Deep Populate and Select Notation
@@ -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 +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.8",
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",