@strapi/utils 4.0.0 → 4.0.4
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/lib/convert-query-params.js +2 -0
- package/lib/pagination.js +14 -2
- package/package.json +6 -3
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,
|
|
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.
|
|
3
|
+
"version": "4.0.4",
|
|
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",
|
|
@@ -39,8 +42,8 @@
|
|
|
39
42
|
"yup": "0.32.9"
|
|
40
43
|
},
|
|
41
44
|
"engines": {
|
|
42
|
-
"node": ">=12.
|
|
45
|
+
"node": ">=12.22.0 <=16.x.x",
|
|
43
46
|
"npm": ">=6.0.0"
|
|
44
47
|
},
|
|
45
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "d81919ac2272948b3f5d3b25a4cf8cc7b6994460"
|
|
46
49
|
}
|