@strapi/utils 4.0.0 → 4.0.1

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.
@@ -110,6 +110,8 @@ const convertLimitQueryParams = limitQuery => {
110
110
  throw new Error(`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`);
111
111
  }
112
112
 
113
+ if (limitAsANumber === -1) return null;
114
+
113
115
  return limitAsANumber;
114
116
  };
115
117
 
package/lib/pagination.js CHANGED
@@ -27,7 +27,7 @@ const withMaxLimit = (limit, maxLimit = -1) => {
27
27
  // Ensure minimum page & pageSize values (page >= 1, pageSize >= 0, start >= 0, limit >= 0)
28
28
  const ensureMinValues = ({ start, limit }) => ({
29
29
  start: Math.max(start, 0),
30
- limit: Math.max(limit, 1),
30
+ limit: limit === -1 ? limit : Math.max(limit, 1),
31
31
  });
32
32
 
33
33
  const ensureMaxValues = (maxLimit = -1) => ({ start, limit }) => ({
@@ -35,6 +35,12 @@ const ensureMaxValues = (maxLimit = -1) => ({ start, limit }) => ({
35
35
  limit: withMaxLimit(limit, maxLimit),
36
36
  });
37
37
 
38
+ // Apply maxLimit as the limit when limit is -1
39
+ const withNoLimit = (pagination, maxLimit = -1) => ({
40
+ ...pagination,
41
+ limit: pagination.limit === -1 ? maxLimit : pagination.limit,
42
+ });
43
+
38
44
  const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {}) => {
39
45
  const defaultValues = merge(STRAPI_DEFAULTS, defaults);
40
46
 
@@ -67,7 +73,10 @@ const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {}) => {
67
73
 
68
74
  // Page / PageSize
69
75
  if (usePagePagination) {
70
- const { page, pageSize } = merge(defaultValues.page, args);
76
+ const { page, pageSize } = merge(defaultValues.page, {
77
+ ...args,
78
+ pageSize: Math.max(1, args.pageSize),
79
+ });
71
80
 
72
81
  Object.assign(pagination, {
73
82
  start: (page - 1) * pageSize,
@@ -75,6 +84,9 @@ const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {}) => {
75
84
  });
76
85
  }
77
86
 
87
+ // Handle -1 limit
88
+ Object.assign(pagination, withNoLimit(pagination, maxLimit));
89
+
78
90
  const replacePaginationAttributes = pipe(
79
91
  // Remove pagination attributes
80
92
  omit(paginationAttributes),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/utils",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Shared utilities for the Strapi packages",
5
5
  "keywords": [
6
6
  "strapi",
@@ -31,6 +31,9 @@
31
31
  "directories": {
32
32
  "lib": "./lib"
33
33
  },
34
+ "scripts": {
35
+ "test:unit": "jest --verbose"
36
+ },
34
37
  "dependencies": {
35
38
  "@sindresorhus/slugify": "1.1.0",
36
39
  "date-fns": "2.24.0",
@@ -42,5 +45,5 @@
42
45
  "node": ">=12.x.x <=16.x.x",
43
46
  "npm": ">=6.0.0"
44
47
  },
45
- "gitHead": "b181702f0202b2c6d645d42b195a831f25cd0b03"
48
+ "gitHead": "e2cd01e8c6cbfeba15ad7787e38b6eebcbb92221"
46
49
  }