@r5v/mongoose-paginate 1.0.12 → 1.0.14

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 (104) hide show
  1. package/README.md +207 -12
  2. package/dist/{types/aggregationPagingQuery.d.ts → aggregationPagingQuery.d.ts} +6 -7
  3. package/dist/aggregationPagingQuery.d.ts.map +1 -0
  4. package/dist/aggregationPagingQuery.js +13 -5
  5. package/dist/index.d.ts +9 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +18 -1
  8. package/dist/{types/pagingQuery.d.ts → pagingQuery.d.ts} +6 -7
  9. package/dist/pagingQuery.d.ts.map +1 -0
  10. package/dist/pagingQuery.js +8 -3
  11. package/dist/tests/aggregationPagingQuery.spec.d.ts +2 -0
  12. package/dist/tests/aggregationPagingQuery.spec.d.ts.map +1 -0
  13. package/dist/tests/aggregationPagingQuery.spec.js +365 -0
  14. package/dist/tests/buildPopulateFromString.spec.d.ts +2 -0
  15. package/dist/tests/buildPopulateFromString.spec.d.ts.map +1 -0
  16. package/dist/tests/buildPopulateFromString.spec.js +223 -0
  17. package/dist/tests/dotNotation.spec.d.ts.map +1 -0
  18. package/dist/tests/findProtectedPaths.spec.d.ts.map +1 -0
  19. package/dist/tests/findProtectedPaths.spec.js +128 -6
  20. package/dist/tests/getPathsWithRef.spec.d.ts.map +1 -0
  21. package/dist/tests/getPathsWithRef.spec.js +92 -18
  22. package/dist/tests/getPropertyFromDotNotation.spec.d.ts.map +1 -0
  23. package/dist/tests/insertPopulate.spec.d.ts.map +1 -0
  24. package/dist/tests/isJsonString.spec.d.ts +2 -0
  25. package/dist/tests/isJsonString.spec.d.ts.map +1 -0
  26. package/dist/tests/isJsonString.spec.js +116 -0
  27. package/dist/tests/isValidDateString.spec.d.ts +2 -0
  28. package/dist/tests/isValidDateString.spec.d.ts.map +1 -0
  29. package/dist/tests/isValidDateString.spec.js +116 -0
  30. package/dist/tests/pagingQuery.spec.d.ts.map +1 -0
  31. package/dist/tests/pagingQuery.spec.js +238 -13
  32. package/dist/tests/parseParams.spec.d.ts +2 -0
  33. package/dist/tests/parseParams.spec.d.ts.map +1 -0
  34. package/dist/tests/parseParams.spec.js +212 -0
  35. package/dist/tests/parseSortString.spec.d.ts.map +1 -0
  36. package/dist/tests/schemaTraversal.spec.d.ts +2 -0
  37. package/dist/tests/schemaTraversal.spec.d.ts.map +1 -0
  38. package/dist/tests/schemaTraversal.spec.js +139 -0
  39. package/dist/types/index.d.ts +66 -3
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/dist/utils/buildPopulateFromString.d.ts +8 -0
  42. package/dist/utils/buildPopulateFromString.d.ts.map +1 -0
  43. package/dist/utils/buildPopulateFromString.js +54 -49
  44. package/dist/utils/dotNotation.d.ts +11 -0
  45. package/dist/utils/dotNotation.d.ts.map +1 -0
  46. package/dist/utils/dotNotation.js +2 -2
  47. package/dist/utils/findKeyWithValue.d.ts.map +1 -0
  48. package/dist/utils/findProtectedPaths.d.ts.map +1 -0
  49. package/dist/utils/findProtectedPaths.js +14 -56
  50. package/dist/utils/getPathsWithRef.d.ts +5 -0
  51. package/dist/utils/getPathsWithRef.d.ts.map +1 -0
  52. package/dist/utils/getPathsWithRef.js +59 -96
  53. package/dist/utils/index.d.ts +9 -0
  54. package/dist/utils/index.d.ts.map +1 -0
  55. package/dist/utils/index.js +33 -0
  56. package/dist/utils/isJsonString.d.ts.map +1 -0
  57. package/dist/utils/isValidDateString.d.ts.map +1 -0
  58. package/dist/utils/parseParams.d.ts.map +1 -0
  59. package/dist/utils/parseParams.js +14 -12
  60. package/dist/utils/parsePopulateQuery.d.ts.map +1 -0
  61. package/dist/utils/parsePopulateQuery.js +1 -1
  62. package/dist/{types/utils → utils}/parseSortString.d.ts +1 -1
  63. package/dist/utils/parseSortString.d.ts.map +1 -0
  64. package/dist/utils/schemaTraversal.d.ts +9 -0
  65. package/dist/utils/schemaTraversal.d.ts.map +1 -0
  66. package/dist/utils/schemaTraversal.js +37 -0
  67. package/package.json +23 -2
  68. package/dist/types/aggregationPagingQuery.d.ts.map +0 -1
  69. package/dist/types/pagingQuery.d.ts.map +0 -1
  70. package/dist/types/tests/dotNotation.spec.d.ts.map +0 -1
  71. package/dist/types/tests/findProtectedPaths.spec.d.ts.map +0 -1
  72. package/dist/types/tests/getPathsWithRef.spec.d.ts.map +0 -1
  73. package/dist/types/tests/getPropertyFromDotNotation.spec.d.ts.map +0 -1
  74. package/dist/types/tests/insertPopulate.spec.d.ts.map +0 -1
  75. package/dist/types/tests/pagingQuery.spec.d.ts.map +0 -1
  76. package/dist/types/tests/parseSortString.spec.d.ts.map +0 -1
  77. package/dist/types/types/index.d.ts +0 -59
  78. package/dist/types/types/index.d.ts.map +0 -1
  79. package/dist/types/utils/buildPopulateFromString.d.ts +0 -8
  80. package/dist/types/utils/buildPopulateFromString.d.ts.map +0 -1
  81. package/dist/types/utils/dotNotation.d.ts +0 -11
  82. package/dist/types/utils/dotNotation.d.ts.map +0 -1
  83. package/dist/types/utils/findKeyWithValue.d.ts.map +0 -1
  84. package/dist/types/utils/findProtectedPaths.d.ts.map +0 -1
  85. package/dist/types/utils/getPathsWithRef.d.ts +0 -5
  86. package/dist/types/utils/getPathsWithRef.d.ts.map +0 -1
  87. package/dist/types/utils/isJsonString.d.ts.map +0 -1
  88. package/dist/types/utils/isValidDateString.d.ts.map +0 -1
  89. package/dist/types/utils/parseParams.d.ts.map +0 -1
  90. package/dist/types/utils/parsePopulateQuery.d.ts.map +0 -1
  91. package/dist/types/utils/parseSortString.d.ts.map +0 -1
  92. /package/dist/{types/tests → tests}/dotNotation.spec.d.ts +0 -0
  93. /package/dist/{types/tests → tests}/findProtectedPaths.spec.d.ts +0 -0
  94. /package/dist/{types/tests → tests}/getPathsWithRef.spec.d.ts +0 -0
  95. /package/dist/{types/tests → tests}/getPropertyFromDotNotation.spec.d.ts +0 -0
  96. /package/dist/{types/tests → tests}/insertPopulate.spec.d.ts +0 -0
  97. /package/dist/{types/tests → tests}/pagingQuery.spec.d.ts +0 -0
  98. /package/dist/{types/tests → tests}/parseSortString.spec.d.ts +0 -0
  99. /package/dist/{types/utils → utils}/findKeyWithValue.d.ts +0 -0
  100. /package/dist/{types/utils → utils}/findProtectedPaths.d.ts +0 -0
  101. /package/dist/{types/utils → utils}/isJsonString.d.ts +0 -0
  102. /package/dist/{types/utils → utils}/isValidDateString.d.ts +0 -0
  103. /package/dist/{types/utils → utils}/parseParams.d.ts +0 -0
  104. /package/dist/{types/utils → utils}/parsePopulateQuery.d.ts +0 -0
@@ -1,4 +1,67 @@
1
- export { PagingQuery } from './pagingQuery';
2
- export { AggregationPagingQuery } from './aggregationPagingQuery';
3
- export { buildPopulate } from './utils/buildPopulateFromString';
1
+ import mongoose, { QueryOptions, SortOrder, AggregateOptions } from "mongoose";
2
+ import { ParsedQs } from "qs";
3
+ /**
4
+ * Minimal request interface that only requires a query property.
5
+ * This allows consumers to use custom Express request types without
6
+ * running into index signature compatibility issues.
7
+ */
8
+ export interface RequestLike {
9
+ query: ParsedQs | Record<string, unknown>;
10
+ }
11
+ export interface QueryParameters extends ParsedQs {
12
+ $filter: string;
13
+ $limit: string;
14
+ $skip: string;
15
+ $sort: string;
16
+ $paging: "yes" | "no" | "0" | "false";
17
+ $populate: string;
18
+ $select: string;
19
+ $count: string;
20
+ }
21
+ export interface StandardParsedRequestParams {
22
+ $filter?: {
23
+ [key: string]: any;
24
+ };
25
+ $limit: number;
26
+ $skip: number;
27
+ $paging?: boolean;
28
+ $populate?: string[];
29
+ $select?: string;
30
+ }
31
+ export interface PagingQueryParsedRequestParams extends StandardParsedRequestParams {
32
+ $lean?: boolean;
33
+ $sort?: [string, SortOrder][];
34
+ }
35
+ export interface AggregateQueryParsedRequestParams extends StandardParsedRequestParams {
36
+ $preSort: {
37
+ [key: string]: SortOrder;
38
+ };
39
+ $sort: {
40
+ [key: string]: SortOrder;
41
+ };
42
+ $count: string[];
43
+ $postFilter: {
44
+ [key: string]: any;
45
+ };
46
+ }
47
+ export interface StandardQueryOptions extends QueryOptions {
48
+ disablePaging?: boolean;
49
+ disableFilter?: boolean;
50
+ }
51
+ export interface PagingQueryOptions extends StandardQueryOptions {
52
+ staticFilter?: {
53
+ [key: string]: any;
54
+ };
55
+ single?: boolean;
56
+ }
57
+ export interface AggregateQueryOptions extends Omit<AggregateOptions, 'comment'> {
58
+ enableFilter?: boolean;
59
+ disablePaging?: boolean;
60
+ disablePostFilter?: boolean;
61
+ disablePreSort?: boolean;
62
+ staticPostFilter?: {
63
+ [key: string]: any;
64
+ };
65
+ pipeline: mongoose.PipelineStage[];
66
+ }
4
67
  //# 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;AAC/D,OAAO,EAAC,aAAa,EAAC,MAAM,iCAAiC,CAAA"}
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;;;;GAIG;AACH,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC7C,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,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,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;CACpB;AAED,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,gBAAgB,EAAC,SAAS,CAAC;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,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: string): 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;AAgED,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY,EAAE,CAQhE"}
@@ -1,58 +1,63 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildPopulate = buildPopulate;
4
+ const SEGMENT_PATTERN = /^([^\[]+)(?:\[([^\]]+)\])?$/;
5
+ // Private module-level functions
6
+ function splitPaths(str) {
7
+ const paths = [];
8
+ let current = '';
9
+ let depth = 0;
10
+ for (const char of str) {
11
+ if (char === '[')
12
+ depth++;
13
+ else if (char === ']')
14
+ depth--;
15
+ if (char === ',' && depth === 0) {
16
+ paths.push(current.trim());
17
+ current = '';
18
+ }
19
+ else {
20
+ current += char;
21
+ }
22
+ }
23
+ if (current)
24
+ paths.push(current.trim());
25
+ return paths;
26
+ }
27
+ function parseSegment(segment) {
28
+ var _a;
29
+ const match = segment.match(SEGMENT_PATTERN);
30
+ if (!match)
31
+ return { name: segment };
32
+ return {
33
+ name: match[1],
34
+ select: (_a = match[2]) === null || _a === void 0 ? void 0 : _a.replace(/,/g, ' ')
35
+ };
36
+ }
37
+ function processLevel(paths) {
38
+ if (!(paths === null || paths === void 0 ? void 0 : paths.length))
39
+ return [];
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
+ // Only this is exported
4
58
  function buildPopulate(pathString) {
5
59
  if (!pathString)
6
60
  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
61
  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
62
  return processLevel(paths);
58
63
  }
@@ -0,0 +1,11 @@
1
+ export declare const getPropertyFromDotNotation: (obj: any, path: string) => any;
2
+ export declare const dotNotationToObject: (dotString: string, value?: unknown) => {};
3
+ export declare const createObjectFromDotNotation: (dotNotationMap: {
4
+ [key: string]: any;
5
+ }) => {};
6
+ export declare const setPropertyFromDotNotation: (obj: Record<string, unknown>, path: string, value: unknown) => Record<string, unknown>;
7
+ export declare const setPropertiesFromDotNotation: (obj: Record<string, unknown>, dotNotationMap: Record<string, unknown>) => Record<string, unknown>;
8
+ export declare const setPropertyFromDotNotationImmutable: (obj: Record<string, unknown>, path: string, value: unknown) => Record<string, unknown>;
9
+ export declare const setPropertiesFromDotNotationImmutable: (obj: Record<string, unknown>, dotNotationMap: Record<string, unknown>) => Record<string, unknown>;
10
+ export type setPropertiesFromDotNotationImmutable = typeof setPropertiesFromDotNotationImmutable;
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,WAAW,MAAM,EAAE,QAAO,OAAc,OAoB3E,CAAA;AAGD,eAAO,MAAO,2BAA2B,GAAI,gBAAe;IAAC,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;CAAC,OAwB7E,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,EAAE,OAAO,OAAO,4BA4BpG,CAAC;AAGF,eAAO,MAAM,4BAA4B,GAAI,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,4BAcjH,CAAC;AAGF,eAAO,MAAM,mCAAmC,GAAI,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,EAAE,OAAO,OAAO,4BA6B7G,CAAC;AAGF,eAAO,MAAM,qCAAqC,GAAI,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,4BAgB1H,CAAC;AACF,MAAM,MAAM,qCAAqC,GAAG,OAAO,qCAAqC,CAAC"}
@@ -95,7 +95,7 @@ const setPropertyFromDotNotationImmutable = (obj, path, value) => {
95
95
  throw new Error('Path must be a non-empty string');
96
96
  }
97
97
  const keys = path.split('.');
98
- const result = JSON.parse(JSON.stringify(obj)); // Deep clone
98
+ const result = structuredClone(obj);
99
99
  let current = result;
100
100
  // Navigate to the parent of the target property
101
101
  for (let i = 0; i < keys.length - 1; i++) {
@@ -120,7 +120,7 @@ const setPropertiesFromDotNotationImmutable = (obj, dotNotationMap) => {
120
120
  if (!dotNotationMap || typeof dotNotationMap !== 'object') {
121
121
  throw new Error('Dot notation map must be a valid object');
122
122
  }
123
- const result = JSON.parse(JSON.stringify(obj)); // Deep clone
123
+ const result = structuredClone(obj);
124
124
  for (const [path, value] of Object.entries(dotNotationMap)) {
125
125
  (0, exports.setPropertyFromDotNotation)(result, path, value);
126
126
  }
@@ -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;AAG/B,eAAO,MAAM,kBAAkB,GAAI,OAAO,KAAK,CAAC,GAAG,CAAC,KAAG,MAAM,EAqB5D,CAAC"}
@@ -1,66 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findProtectedPaths = void 0;
4
+ const schemaTraversal_1 = require("./schemaTraversal");
4
5
  const findProtectedPaths = (model) => {
5
6
  const schema = model.schema;
6
- const data = [];
7
- schema.eachPath((p, i) => {
8
- const str = JSON.stringify(i);
9
- data.push(str);
10
- });
11
7
  const pathsSet = new Set();
12
- function buildFullPath(parentPath, childPath) {
13
- if (!parentPath)
14
- return childPath;
15
- if (!childPath)
16
- return parentPath;
17
- return `${parentPath}.${childPath}`;
18
- }
19
- // Recursive function to traverse nested objects and find selected: false
20
- function traverseObject(obj, currentPath = '') {
21
- // Check if current object has selected === false
22
- if (obj.selected === false && obj.path) {
23
- const fullPath = buildFullPath(currentPath, obj.path);
24
- pathsSet.add(fullPath);
25
- }
26
- // Check options.selected
27
- if (obj.options && obj.options.selected === false && obj.path) {
28
- const fullPath = buildFullPath(currentPath, obj.path);
29
- pathsSet.add(fullPath);
30
- }
31
- // Check for nested paths in complex schema objects
32
- if (obj.options && obj.options.type && obj.options.type.paths) {
33
- const nestedPaths = obj.options.type.paths;
34
- const parentPath = obj.path || currentPath;
35
- for (const [key, nestedObj] of Object.entries(nestedPaths)) {
36
- if (nestedObj.selected === false) {
37
- const fullPath = buildFullPath(parentPath, nestedObj.path);
38
- pathsSet.add(fullPath);
39
- }
40
- // Recursively traverse nested objects
41
- traverseObject(nestedObj, parentPath);
8
+ schema.eachPath((path, schemaType) => {
9
+ (0, schemaTraversal_1.traverseSchemaObject)(schemaType, (obj, currentPath) => {
10
+ // Check if current object has selected === false
11
+ if (obj.selected === false && obj.path) {
12
+ const fullPath = (0, schemaTraversal_1.buildFullPath)(currentPath, obj.path);
13
+ pathsSet.add(fullPath);
14
+ }
15
+ // Check options.selected
16
+ if (obj.options && obj.options.selected === false && obj.path) {
17
+ const fullPath = (0, schemaTraversal_1.buildFullPath)(currentPath, obj.path);
18
+ pathsSet.add(fullPath);
42
19
  }
43
- }
44
- // Check other nested structures that might contain paths
45
- if (obj.options && obj.options.type && typeof obj.options.type === 'object') {
46
- const parentPath = obj.path || currentPath;
47
- traverseObject(obj.options.type, parentPath);
48
- }
49
- }
50
- // Iterate through each JSON string in the array
51
- for (const jsonString of data) {
52
- try {
53
- // Parse the JSON string
54
- const obj = JSON.parse(jsonString);
55
- // Start traversal from root
56
- traverseObject(obj);
57
- }
58
- catch (error) {
59
- console.error('Error parsing JSON:', error);
60
- continue;
61
- }
62
- }
63
- // Convert Set back to Array and return
20
+ });
21
+ });
64
22
  return Array.from(pathsSet);
65
23
  };
66
24
  exports.findProtectedPaths = findProtectedPaths;
@@ -0,0 +1,5 @@
1
+ export declare const getPathsWithRef: (data: any[] | string) => {
2
+ path: string;
3
+ options: any;
4
+ }[];
5
+ //# sourceMappingURL=getPathsWithRef.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPathsWithRef.d.ts","sourceRoot":"","sources":["../../src/utils/getPathsWithRef.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,eAAe,GAAI,MAAM,GAAG,EAAE,GAAG,MAAM,KAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,EAqDpF,CAAC"}
@@ -1,110 +1,73 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPathsWithRef = void 0;
4
+ const schemaTraversal_1 = require("./schemaTraversal");
5
+ // Private module-level function
6
+ function hasRefInOptions(options) {
7
+ if (!options || typeof options !== 'object')
8
+ return false;
9
+ // Direct ref property
10
+ if (options.ref)
11
+ return true;
12
+ // Check in nested type array
13
+ if (Array.isArray(options.type)) {
14
+ return options.type.some(item => item && typeof item === 'object' && item.ref);
15
+ }
16
+ // Check in nested type object
17
+ if (options.type && typeof options.type === 'object' && options.type.ref) {
18
+ return true;
19
+ }
20
+ return false;
21
+ }
4
22
  const getPathsWithRef = (data) => {
5
23
  const results = [];
6
- const processedPaths = new Set(); // To avoid duplicates
7
- // Helper function to build full dot notation path
8
- function buildFullPath(parentPath, childPath) {
9
- if (!parentPath)
10
- return childPath;
11
- if (!childPath)
12
- return parentPath;
13
- return `${parentPath}.${childPath}`;
14
- }
15
- // Function to check if options object contains ref
16
- function hasRefInOptions(options) {
17
- if (!options || typeof options !== 'object')
18
- return false;
19
- // Direct ref property
20
- if (options.ref)
21
- return true;
22
- // Check in nested type array
23
- if (Array.isArray(options.type)) {
24
- return options.type.some(item => item && typeof item === 'object' && item.ref);
24
+ const processedPaths = new Set();
25
+ // Normalize input to array of objects
26
+ let objects;
27
+ if (typeof data === 'string') {
28
+ try {
29
+ const parsed = JSON.parse(data);
30
+ objects = Array.isArray(parsed) ? parsed : [parsed];
25
31
  }
26
- // Check in nested type object
27
- if (options.type && typeof options.type === 'object' && options.type.ref) {
28
- return true;
32
+ catch (_a) {
33
+ // If it's not valid JSON, return empty results
34
+ return results;
29
35
  }
30
- return false;
31
36
  }
32
- // Recursive function to traverse nested objects and find ref options
33
- function traverseObject(obj, currentPath = '') {
34
- // Check if current object has options with ref
35
- if (obj.path && obj.options && hasRefInOptions(obj.options)) {
36
- const fullPath = buildFullPath(currentPath, obj.path);
37
- if (!processedPaths.has(fullPath)) {
38
- processedPaths.add(fullPath);
39
- results.push({
40
- path: fullPath,
41
- options: obj.options
42
- });
43
- }
44
- }
45
- // Check caster for array types (like books array)
46
- if (obj.caster && obj.caster.options && hasRefInOptions(obj.caster.options)) {
47
- const fullPath = buildFullPath(currentPath, obj.path || obj.caster.path);
48
- if (!processedPaths.has(fullPath)) {
49
- processedPaths.add(fullPath);
50
- results.push({
51
- path: fullPath,
52
- options: obj.caster.options
53
- });
37
+ else if (Array.isArray(data)) {
38
+ objects = data;
39
+ }
40
+ else {
41
+ return results;
42
+ }
43
+ for (const obj of objects) {
44
+ (0, schemaTraversal_1.traverseSchemaObject)(obj, (schemaObj, currentPath) => {
45
+ var _a, _b;
46
+ const fullPath = (0, schemaTraversal_1.buildFullPath)(currentPath, schemaObj.path);
47
+ // Check direct options.ref
48
+ if (schemaObj.path && schemaObj.options && hasRefInOptions(schemaObj.options)) {
49
+ if (!processedPaths.has(fullPath)) {
50
+ processedPaths.add(fullPath);
51
+ results.push({ path: fullPath, options: schemaObj.options });
52
+ }
54
53
  }
55
- }
56
- // Check $embeddedSchemaType for array types
57
- if (obj.$embeddedSchemaType && obj.$embeddedSchemaType.options && hasRefInOptions(obj.$embeddedSchemaType.options)) {
58
- const fullPath = buildFullPath(currentPath, obj.path || obj.$embeddedSchemaType.path);
59
- if (!processedPaths.has(fullPath)) {
60
- processedPaths.add(fullPath);
61
- results.push({
62
- path: fullPath,
63
- options: obj.$embeddedSchemaType.options
64
- });
54
+ // Check caster.options.ref (for arrays)
55
+ if (((_a = schemaObj.caster) === null || _a === void 0 ? void 0 : _a.options) && hasRefInOptions(schemaObj.caster.options)) {
56
+ const casterPath = (0, schemaTraversal_1.buildFullPath)(currentPath, schemaObj.path || schemaObj.caster.path);
57
+ if (!processedPaths.has(casterPath)) {
58
+ processedPaths.add(casterPath);
59
+ results.push({ path: casterPath, options: schemaObj.caster.options });
60
+ }
65
61
  }
66
- }
67
- // Check for nested paths in complex schema objects
68
- if (obj.options && obj.options.type && obj.options.type.paths) {
69
- const nestedPaths = obj.options.type.paths;
70
- const parentPath = obj.path || currentPath;
71
- for (const [key, nestedObj] of Object.entries(nestedPaths)) {
72
- traverseObject(nestedObj, parentPath);
62
+ // Check $embeddedSchemaType.options.ref (for arrays)
63
+ if (((_b = schemaObj.$embeddedSchemaType) === null || _b === void 0 ? void 0 : _b.options) && hasRefInOptions(schemaObj.$embeddedSchemaType.options)) {
64
+ const embeddedPath = (0, schemaTraversal_1.buildFullPath)(currentPath, schemaObj.path || schemaObj.$embeddedSchemaType.path);
65
+ if (!processedPaths.has(embeddedPath)) {
66
+ processedPaths.add(embeddedPath);
67
+ results.push({ path: embeddedPath, options: schemaObj.$embeddedSchemaType.options });
68
+ }
73
69
  }
74
- }
75
- // Check other nested structures
76
- if (obj.options && obj.options.type && typeof obj.options.type === 'object') {
77
- const parentPath = obj.path || currentPath;
78
- traverseObject(obj.options.type, parentPath);
79
- }
80
- }
81
- // Handle the comma-separated format in the provided data
82
- let jsonObjects = [];
83
- if (typeof data === 'string') {
84
- // Split by comma and clean up each JSON string
85
- const jsonStrings = data.split(',{').map((str, index) => {
86
- if (index === 0)
87
- return str.startsWith(',') ? str.slice(1) : str;
88
- return '{' + str;
89
- }).filter(str => str.trim());
90
- jsonObjects = jsonStrings;
91
- }
92
- else if (Array.isArray(data)) {
93
- jsonObjects = data.map(item => typeof item === 'string' ? item : JSON.stringify(item));
94
- }
95
- // Process each JSON object
96
- for (const jsonString of jsonObjects) {
97
- try {
98
- const cleanJsonString = jsonString.trim();
99
- if (!cleanJsonString)
100
- continue;
101
- const obj = JSON.parse(cleanJsonString);
102
- traverseObject(obj);
103
- }
104
- catch (error) {
105
- console.error('Error parsing JSON:', error);
106
- continue;
107
- }
70
+ });
108
71
  }
109
72
  return results;
110
73
  };
@@ -0,0 +1,9 @@
1
+ export { buildPopulate } from './buildPopulateFromString';
2
+ export { parsePopulateArray } from './parsePopulateQuery';
3
+ export { parseSortString, parseAggregateSortString } from './parseSortString';
4
+ export { getPropertyFromDotNotation, dotNotationToObject, createObjectFromDotNotation, setPropertyFromDotNotation, setPropertiesFromDotNotation, setPropertyFromDotNotationImmutable, setPropertiesFromDotNotationImmutable } from './dotNotation';
5
+ export { isJsonString } from './isJsonString';
6
+ export { isValidDateString } from './isValidDateString';
7
+ export { parseParams } from './parseParams';
8
+ export { buildFullPath, traverseSchemaObject } from './schemaTraversal';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAGzD,OAAO,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAA;AAG7E,OAAO,EACH,0BAA0B,EAC1B,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,4BAA4B,EAC5B,mCAAmC,EACnC,qCAAqC,EACxC,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traverseSchemaObject = exports.buildFullPath = exports.parseParams = exports.isValidDateString = exports.isJsonString = exports.setPropertiesFromDotNotationImmutable = exports.setPropertyFromDotNotationImmutable = exports.setPropertiesFromDotNotation = exports.setPropertyFromDotNotation = exports.createObjectFromDotNotation = exports.dotNotationToObject = exports.getPropertyFromDotNotation = exports.parseAggregateSortString = exports.parseSortString = exports.parsePopulateArray = exports.buildPopulate = void 0;
4
+ // Populate utilities
5
+ var buildPopulateFromString_1 = require("./buildPopulateFromString");
6
+ Object.defineProperty(exports, "buildPopulate", { enumerable: true, get: function () { return buildPopulateFromString_1.buildPopulate; } });
7
+ var parsePopulateQuery_1 = require("./parsePopulateQuery");
8
+ Object.defineProperty(exports, "parsePopulateArray", { enumerable: true, get: function () { return parsePopulateQuery_1.parsePopulateArray; } });
9
+ // Sort utilities
10
+ var parseSortString_1 = require("./parseSortString");
11
+ Object.defineProperty(exports, "parseSortString", { enumerable: true, get: function () { return parseSortString_1.parseSortString; } });
12
+ Object.defineProperty(exports, "parseAggregateSortString", { enumerable: true, get: function () { return parseSortString_1.parseAggregateSortString; } });
13
+ // Dot notation utilities
14
+ var dotNotation_1 = require("./dotNotation");
15
+ Object.defineProperty(exports, "getPropertyFromDotNotation", { enumerable: true, get: function () { return dotNotation_1.getPropertyFromDotNotation; } });
16
+ Object.defineProperty(exports, "dotNotationToObject", { enumerable: true, get: function () { return dotNotation_1.dotNotationToObject; } });
17
+ Object.defineProperty(exports, "createObjectFromDotNotation", { enumerable: true, get: function () { return dotNotation_1.createObjectFromDotNotation; } });
18
+ Object.defineProperty(exports, "setPropertyFromDotNotation", { enumerable: true, get: function () { return dotNotation_1.setPropertyFromDotNotation; } });
19
+ Object.defineProperty(exports, "setPropertiesFromDotNotation", { enumerable: true, get: function () { return dotNotation_1.setPropertiesFromDotNotation; } });
20
+ Object.defineProperty(exports, "setPropertyFromDotNotationImmutable", { enumerable: true, get: function () { return dotNotation_1.setPropertyFromDotNotationImmutable; } });
21
+ Object.defineProperty(exports, "setPropertiesFromDotNotationImmutable", { enumerable: true, get: function () { return dotNotation_1.setPropertiesFromDotNotationImmutable; } });
22
+ // Validation utilities
23
+ var isJsonString_1 = require("./isJsonString");
24
+ Object.defineProperty(exports, "isJsonString", { enumerable: true, get: function () { return isJsonString_1.isJsonString; } });
25
+ var isValidDateString_1 = require("./isValidDateString");
26
+ Object.defineProperty(exports, "isValidDateString", { enumerable: true, get: function () { return isValidDateString_1.isValidDateString; } });
27
+ // Parameter parsing
28
+ var parseParams_1 = require("./parseParams");
29
+ Object.defineProperty(exports, "parseParams", { enumerable: true, get: function () { return parseParams_1.parseParams; } });
30
+ // Schema traversal utilities
31
+ var schemaTraversal_1 = require("./schemaTraversal");
32
+ Object.defineProperty(exports, "buildFullPath", { enumerable: true, get: function () { return schemaTraversal_1.buildFullPath; } });
33
+ Object.defineProperty(exports, "traverseSchemaObject", { enumerable: true, get: function () { return schemaTraversal_1.traverseSchemaObject; } });
@@ -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"}
@@ -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,iCA6CvL,CAAA"}
@@ -12,29 +12,31 @@ const parseParams = (defaultParams, params, isAggregate = false) => {
12
12
  keys.forEach((k) => {
13
13
  if (__params.hasOwnProperty(k)) {
14
14
  if (k === "$filter" || k === "$postFilter") {
15
- parsedParams[k] =
16
- typeof params[k] === "string"
17
- ? JSON.parse(params[k])
18
- : params[k];
15
+ if (typeof params[k] === "string") {
16
+ try {
17
+ parsedParams[k] = JSON.parse(params[k]);
18
+ }
19
+ catch (e) {
20
+ throw new Error(`Invalid JSON in ${k} parameter: ${e.message}`);
21
+ }
22
+ }
23
+ else {
24
+ parsedParams[k] = params[k];
25
+ }
19
26
  }
20
27
  if (k === "$limit" || k === "$skip") {
21
28
  parsedParams[k] = parseInt(params[k].toString());
22
29
  }
23
30
  if (k === "$paging") {
24
31
  const str = params[k].toLowerCase();
25
- parsedParams[k] = !(str === 'false' || str === 'no' || str == '0');
32
+ parsedParams[k] = !(str === 'false' || str === 'no' || str === '0');
26
33
  }
27
34
  if (k === "$sort" || k === "$preSort") {
28
35
  parsedParams[k] = isAggregate ? (0, parseSortString_1.parseAggregateSortString)(params[k]) : (0, parseSortString_1.parseSortString)(params[k]);
29
36
  }
30
- if (k === "$count" || k === "$includes" || k === "$populate") {
37
+ if (k === "$count" || k === "$populate") {
31
38
  const v = params[k].split(",").map((v) => v.trim());
32
- if (k === "$includes") {
33
- parsedParams["$populate"] = v;
34
- }
35
- else {
36
- parsedParams[k] = v;
37
- }
39
+ parsedParams[k] = v;
38
40
  }
39
41
  if (k === "$select") {
40
42
  parsedParams[k] = params[k];
@@ -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"}
@@ -4,7 +4,7 @@ exports.parsePopulateArray = void 0;
4
4
  const parsePopulateArray = (populateArr, selectArr) => {
5
5
  return populateArr.reduce((acc, curr) => {
6
6
  const matched = selectArr.filter(item => {
7
- const rgx = new RegExp(`^${curr}($|\.?)`, "g");
7
+ const rgx = new RegExp(`^${curr}($|\.?)`);
8
8
  return rgx.test(item);
9
9
  });
10
10
  const pop = { path: curr };
@@ -1,6 +1,6 @@
1
1
  import { SortOrder } from "mongoose";
2
2
  export declare const parseSortString: (sortString: string) => [string, SortOrder][];
3
- export declare const parseAggregateSortString: (sortString: any) => {
3
+ export declare const parseAggregateSortString: (sortString: string) => {
4
4
  [key: string]: SortOrder;
5
5
  };
6
6
  //# sourceMappingURL=parseSortString.d.ts.map