@r5v/mongoose-paginate 1.0.6 → 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.
Files changed (66) hide show
  1. package/README.md +7 -2
  2. package/dist/pagingQuery.js +3 -4
  3. package/dist/{aggregationPagingQuery.d.ts → types/aggregationPagingQuery.d.ts} +2 -2
  4. package/dist/types/aggregationPagingQuery.d.ts.map +1 -0
  5. package/dist/types/index.d.ts.map +1 -0
  6. package/dist/types/index.js +2 -0
  7. package/dist/{pagingQuery.d.ts → types/pagingQuery.d.ts} +2 -2
  8. package/dist/types/pagingQuery.d.ts.map +1 -0
  9. package/dist/types/tests/dotNotation.spec.d.ts.map +1 -0
  10. package/dist/types/tests/findProtectedPaths.spec.d.ts.map +1 -0
  11. package/dist/types/tests/getPathsWithRef.spec.d.ts.map +1 -0
  12. package/dist/types/tests/getPropertyFromDotNotation.spec.d.ts.map +1 -0
  13. package/dist/types/tests/insertPopulate.spec.d.ts.map +1 -0
  14. package/dist/types/tests/pagingQuery.spec.d.ts.map +1 -0
  15. package/dist/types/tests/parseSortString.spec.d.ts.map +1 -0
  16. package/dist/types/types/index.d.ts +59 -0
  17. package/dist/types/types/index.d.ts.map +1 -0
  18. package/dist/types/utils/buildPopulateFromString.d.ts +8 -0
  19. package/dist/types/utils/buildPopulateFromString.d.ts.map +1 -0
  20. package/dist/{utils → types/utils}/dotNotation.d.ts +1 -0
  21. package/dist/types/utils/dotNotation.d.ts.map +1 -0
  22. package/dist/types/utils/findKeyWithValue.d.ts.map +1 -0
  23. package/dist/types/utils/findProtectedPaths.d.ts.map +1 -0
  24. package/dist/types/utils/getPathsWithRef.d.ts.map +1 -0
  25. package/dist/types/utils/isJsonString.d.ts.map +1 -0
  26. package/dist/types/utils/isValidDateString.d.ts.map +1 -0
  27. package/dist/{utils → types/utils}/parseParams.d.ts +1 -1
  28. package/dist/types/utils/parseParams.d.ts.map +1 -0
  29. package/dist/types/utils/parsePopulateQuery.d.ts.map +1 -0
  30. package/dist/types/utils/parseSortString.d.ts.map +1 -0
  31. package/dist/utils/buildPopulateFromString.js +58 -0
  32. package/package.json +1 -1
  33. package/dist/aggregationPagingQuery.d.ts.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/pagingQuery.d.ts.map +0 -1
  36. package/dist/tests/dotNotation.spec.d.ts.map +0 -1
  37. package/dist/tests/findProtectedPaths.spec.d.ts.map +0 -1
  38. package/dist/tests/getPathsWithRef.spec.d.ts.map +0 -1
  39. package/dist/tests/getPropertyFromDotNotation.spec.d.ts.map +0 -1
  40. package/dist/tests/insertPopulate.spec.d.ts.map +0 -1
  41. package/dist/tests/pagingQuery.spec.d.ts.map +0 -1
  42. package/dist/tests/parseSortString.spec.d.ts.map +0 -1
  43. package/dist/utils/dotNotation.d.ts.map +0 -1
  44. package/dist/utils/findKeyWithValue.d.ts.map +0 -1
  45. package/dist/utils/findProtectedPaths.d.ts.map +0 -1
  46. package/dist/utils/getPathsWithRef.d.ts.map +0 -1
  47. package/dist/utils/isJsonString.d.ts.map +0 -1
  48. package/dist/utils/isValidDateString.d.ts.map +0 -1
  49. package/dist/utils/parseParams.d.ts.map +0 -1
  50. package/dist/utils/parsePopulateQuery.d.ts.map +0 -1
  51. package/dist/utils/parseSortString.d.ts.map +0 -1
  52. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
  53. /package/dist/{tests → types/tests}/dotNotation.spec.d.ts +0 -0
  54. /package/dist/{tests → types/tests}/findProtectedPaths.spec.d.ts +0 -0
  55. /package/dist/{tests → types/tests}/getPathsWithRef.spec.d.ts +0 -0
  56. /package/dist/{tests → types/tests}/getPropertyFromDotNotation.spec.d.ts +0 -0
  57. /package/dist/{tests → types/tests}/insertPopulate.spec.d.ts +0 -0
  58. /package/dist/{tests → types/tests}/pagingQuery.spec.d.ts +0 -0
  59. /package/dist/{tests → types/tests}/parseSortString.spec.d.ts +0 -0
  60. /package/dist/{utils → types/utils}/findKeyWithValue.d.ts +0 -0
  61. /package/dist/{utils → types/utils}/findProtectedPaths.d.ts +0 -0
  62. /package/dist/{utils → types/utils}/getPathsWithRef.d.ts +0 -0
  63. /package/dist/{utils → types/utils}/isJsonString.d.ts +0 -0
  64. /package/dist/{utils → types/utils}/isValidDateString.d.ts +0 -0
  65. /package/dist/{utils → types/utils}/parsePopulateQuery.d.ts +0 -0
  66. /package/dist/{utils → types/utils}/parseSortString.d.ts +0 -0
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,6 +1,6 @@
1
1
  import { Model, Aggregate } from "mongoose";
2
2
  import type { Request } from "express";
3
- import type { AggregateQueryOptions, ExpressQuery, AggregateQueryParsedRequestParams } from './index.d';
3
+ import type { AggregateQueryOptions, ExpressQuery, AggregateQueryParsedRequestParams } from './types';
4
4
  export declare class AggregationPagingQuery {
5
5
  params: AggregateQueryParsedRequestParams;
6
6
  options: AggregateQueryOptions;
@@ -9,7 +9,7 @@ export declare class AggregationPagingQuery {
9
9
  model: Model<any>;
10
10
  constructor(req: Request<{}, any, any, Partial<ExpressQuery>>, model: Model<any>, options: AggregateQueryOptions);
11
11
  findProtectedPaths: (model: Model<any>) => string[];
12
- parseParams: (defaultParams: import("./index.d").PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams, params: import("qs").ParsedQs, isAggregate?: boolean) => import("./index.d").PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams;
12
+ parseParams: (defaultParams: import("./types").PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams, params: import("qs").ParsedQs, isAggregate?: boolean) => import("./types").PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams;
13
13
  isValidDateString: (value: string) => boolean;
14
14
  isJsonString: (str: string) => boolean;
15
15
  parseSortString: (sortString: string) => [string, import("mongoose").SortOrder][];
@@ -0,0 +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,YAAY,EAAE,iCAAiC,EAAC,MAAM,SAAS,CAAA;AAQnG,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,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,qBAAqB;IAQ/G,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 @@
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"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import type { PagingQueryParsedRequestParams, PagingQueryOptions } from './index.d';
1
+ import type { PagingQueryParsedRequestParams, PagingQueryOptions } from './types';
2
2
  import { Model, QueryWithHelpers } from "mongoose";
3
3
  import type { Request } from 'express';
4
4
  export declare class PagingQuery {
@@ -10,7 +10,7 @@ export declare class PagingQuery {
10
10
  private isJsonString;
11
11
  private initQuery;
12
12
  parseSortString: (sortString: string) => [string, import("mongoose").SortOrder][];
13
- parseParams: (defaultParams: PagingQueryParsedRequestParams | import("./index.d").AggregateQueryParsedRequestParams, params: import("qs").ParsedQs, isAggregate?: boolean) => PagingQueryParsedRequestParams | import("./index.d").AggregateQueryParsedRequestParams;
13
+ parseParams: (defaultParams: PagingQueryParsedRequestParams | import("./types").AggregateQueryParsedRequestParams, params: import("qs").ParsedQs, isAggregate?: boolean) => PagingQueryParsedRequestParams | import("./types").AggregateQueryParsedRequestParams;
14
14
  exec: () => Promise<any>;
15
15
  }
16
16
  //# sourceMappingURL=pagingQuery.d.ts.map
@@ -0,0 +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;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 @@
1
+ {"version":3,"file":"dotNotation.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/dotNotation.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findProtectedPaths.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/findProtectedPaths.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPathsWithRef.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/getPathsWithRef.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPropertyFromDotNotation.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/getPropertyFromDotNotation.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insertPopulate.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/insertPopulate.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagingQuery.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/pagingQuery.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSortString.spec.d.ts","sourceRoot":"","sources":["../../../src/tests/parseSortString.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,59 @@
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
@@ -0,0 +1 @@
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"}
@@ -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"}
@@ -7,4 +7,5 @@ export declare const setPropertyFromDotNotation: (obj: any, path: any, value: an
7
7
  export declare const setPropertiesFromDotNotation: (obj: any, dotNotationMap: any) => any;
8
8
  export declare const setPropertyFromDotNotationImmutable: (obj: any, path: any, value: any) => any;
9
9
  export declare const setPropertiesFromDotNotationImmutable: (obj: any, dotNotationMap: any) => any;
10
+ export type setPropertiesFromDotNotationImmutable = typeof setPropertiesFromDotNotationImmutable;
10
11
  //# sourceMappingURL=dotNotation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dotNotation.d.ts","sourceRoot":"","sources":["../../../src/utils/dotNotation.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,GAAI,KAAI,GAAG,EAAE,MAAK,MAAM,QAI9D,CAAA;AACD,eAAO,MAAM,mBAAmB,GAAI,cAAS,EAAE,QAAM,GAAU,OAoB9D,CAAA;AAGD,eAAO,MAAO,2BAA2B,GAAI,gBAAe;IAAC,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;CAAC,OAwB7E,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,QAAG,EAAE,SAAI,EAAE,UAAK,QA4B1D,CAAC;AAGF,eAAO,MAAM,4BAA4B,GAAI,QAAG,EAAE,mBAAc,QAc/D,CAAC;AAGF,eAAO,MAAM,mCAAmC,GAAI,QAAG,EAAE,SAAI,EAAE,UAAK,QA6BnE,CAAC;AAGF,eAAO,MAAM,qCAAqC,GAAI,QAAG,EAAE,mBAAc,QAgBxE,CAAC;AACF,MAAM,MAAM,qCAAqC,GAAG,OAAO,qCAAqC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findKeyWithValue.d.ts","sourceRoot":"","sources":["../../../src/utils/findKeyWithValue.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,GAAI,QAAG,EAAE,cAAS,EAAE,gBAAW,YAe3D,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findProtectedPaths.d.ts","sourceRoot":"","sources":["../../../src/utils/findProtectedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAE/B,eAAO,MAAM,kBAAkB,GAAI,OAAO,KAAK,CAAC,GAAG,CAAC,KAAG,MAAM,EAsE5D,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPathsWithRef.d.ts","sourceRoot":"","sources":["../../../src/utils/getPathsWithRef.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAE,SAAI;UACT,MAAM;aAAW,GAAG;GAoH5C,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isJsonString.d.ts","sourceRoot":"","sources":["../../../src/utils/isJsonString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,YAOvC,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidDateString.d.ts","sourceRoot":"","sources":["../../../src/utils/isValidDateString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,OAKjD,CAAA"}
@@ -1,4 +1,4 @@
1
1
  import { ParsedQs } from "qs";
2
- import type { PagingQueryParsedRequestParams, AggregateQueryParsedRequestParams } from '../index.d';
2
+ import type { PagingQueryParsedRequestParams, AggregateQueryParsedRequestParams } from '../types';
3
3
  export declare const parseParams: (defaultParams: PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams, params: ParsedQs, isAggregate?: boolean) => PagingQueryParsedRequestParams | AggregateQueryParsedRequestParams;
4
4
  //# sourceMappingURL=parseParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../../src/utils/parseParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,IAAI,CAAC;AAC5B,OAAO,KAAK,EACR,8BAA8B,EAC9B,iCAAiC,EACpC,MAAM,UAAU,CAAA;AAGjB,eAAO,MAAM,WAAW,GAAI,eAAe,8BAA8B,GAAG,iCAAiC,EAAE,QAAQ,QAAQ,EAAE,qBAAmB,KAAG,8BAA8B,GAAG,iCA4CvL,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parsePopulateQuery.d.ts","sourceRoot":"","sources":["../../../src/utils/parsePopulateQuery.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,GAAI,aAAa,MAAM,EAAE,EAAE,WAAW,MAAM,EAAE;UAmB1D,MAAM;aAAW,GAAG;GAGtC,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSortString.d.ts","sourceRoot":"","sources":["../../../src/utils/parseSortString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,0BAyBjD,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,eAAU,KAAE;IAAC,CAAC,GAAG,EAAC,MAAM,GAAE,SAAS,CAAA;CAO3E,CAAA"}
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@r5v/mongoose-paginate",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "scripts": {
@@ -1 +0,0 @@
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,YAAY,EAAE,iCAAiC,EAAC,MAAM,WAAW,CAAA;AAQrG,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,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,qBAAqB;IAQ/G,kBAAkB,kCAAqB;IACvC,WAAW,0PAAc;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"}
@@ -1 +0,0 @@
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 +0,0 @@
1
- {"version":3,"file":"pagingQuery.d.ts","sourceRoot":"","sources":["../src/pagingQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,8BAA8B,EAAE,kBAAkB,EAAC,MAAM,WAAW,CAAA;AACjF,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,0PAAc;IACzB,IAAI,qBAuBH;CACJ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dotNotation.spec.d.ts","sourceRoot":"","sources":["../../src/tests/dotNotation.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"findProtectedPaths.spec.d.ts","sourceRoot":"","sources":["../../src/tests/findProtectedPaths.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPathsWithRef.spec.d.ts","sourceRoot":"","sources":["../../src/tests/getPathsWithRef.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPropertyFromDotNotation.spec.d.ts","sourceRoot":"","sources":["../../src/tests/getPropertyFromDotNotation.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"insertPopulate.spec.d.ts","sourceRoot":"","sources":["../../src/tests/insertPopulate.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"pagingQuery.spec.d.ts","sourceRoot":"","sources":["../../src/tests/pagingQuery.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseSortString.spec.d.ts","sourceRoot":"","sources":["../../src/tests/parseSortString.spec.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dotNotation.d.ts","sourceRoot":"","sources":["../../src/utils/dotNotation.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,GAAI,KAAI,GAAG,EAAE,MAAK,MAAM,QAI9D,CAAA;AACD,eAAO,MAAM,mBAAmB,GAAI,cAAS,EAAE,QAAM,GAAU,OAoB9D,CAAA;AAGD,eAAO,MAAO,2BAA2B,GAAI,gBAAe;IAAC,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;CAAC,OAwB7E,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,QAAG,EAAE,SAAI,EAAE,UAAK,QA4B1D,CAAC;AAGF,eAAO,MAAM,4BAA4B,GAAI,QAAG,EAAE,mBAAc,QAc/D,CAAC;AAGF,eAAO,MAAM,mCAAmC,GAAI,QAAG,EAAE,SAAI,EAAE,UAAK,QA6BnE,CAAC;AAGF,eAAO,MAAM,qCAAqC,GAAI,QAAG,EAAE,mBAAc,QAgBxE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"findKeyWithValue.d.ts","sourceRoot":"","sources":["../../src/utils/findKeyWithValue.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,GAAI,QAAG,EAAE,cAAS,EAAE,gBAAW,YAe3D,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"findProtectedPaths.d.ts","sourceRoot":"","sources":["../../src/utils/findProtectedPaths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,UAAU,CAAC;AAE/B,eAAO,MAAM,kBAAkB,GAAI,OAAO,KAAK,CAAC,GAAG,CAAC,KAAG,MAAM,EAsE5D,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getPathsWithRef.d.ts","sourceRoot":"","sources":["../../src/utils/getPathsWithRef.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAE,SAAI;UACT,MAAM;aAAW,GAAG;GAoH5C,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"isJsonString.d.ts","sourceRoot":"","sources":["../../src/utils/isJsonString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,YAOvC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"isValidDateString.d.ts","sourceRoot":"","sources":["../../src/utils/isValidDateString.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,OAKjD,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseParams.d.ts","sourceRoot":"","sources":["../../src/utils/parseParams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,IAAI,CAAC;AAC5B,OAAO,KAAK,EAAC,8BAA8B,EAAE,iCAAiC,EAAC,MAAM,YAAY,CAAA;AAGjG,eAAO,MAAM,WAAW,GAAI,eAAe,8BAA8B,GAAG,iCAAiC,EAAE,QAAQ,QAAQ,EAAE,qBAAmB,KAAG,8BAA8B,GAAG,iCA4CvL,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parsePopulateQuery.d.ts","sourceRoot":"","sources":["../../src/utils/parsePopulateQuery.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,GAAI,aAAa,MAAM,EAAE,EAAE,WAAW,MAAM,EAAE;UAmB1D,MAAM;aAAW,GAAG;GAGtC,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseSortString.d.ts","sourceRoot":"","sources":["../../src/utils/parseSortString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,0BAyBjD,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,eAAU,KAAE;IAAC,CAAC,GAAG,EAAC,MAAM,GAAE,SAAS,CAAA;CAO3E,CAAA"}
File without changes
File without changes