@strapi/utils 4.7.2-exp.24dd7d95972fa822bf43e9b095b51027402c229e → 4.8.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.
- package/coverage/clover.xml +638 -0
- package/coverage/coverage-final.json +24 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +146 -0
- package/coverage/lcov-report/lib/async.js.html +223 -0
- package/coverage/lcov-report/lib/content-types.js.html +643 -0
- package/coverage/lcov-report/lib/env-helper.js.html +319 -0
- package/coverage/lcov-report/lib/errors.js.html +397 -0
- package/coverage/lcov-report/lib/format-yup-error.js.html +145 -0
- package/coverage/lcov-report/lib/hooks.js.html +415 -0
- package/coverage/lcov-report/lib/import-default.js.html +115 -0
- package/coverage/lcov-report/lib/index.html +326 -0
- package/coverage/lcov-report/lib/pagination.js.html +382 -0
- package/coverage/lcov-report/lib/parse-type.js.html +385 -0
- package/coverage/lcov-report/lib/policy.js.html +472 -0
- package/coverage/lcov-report/lib/print-value.js.html +241 -0
- package/coverage/lcov-report/lib/provider-factory.js.html +433 -0
- package/coverage/lcov-report/lib/relations.js.html +178 -0
- package/coverage/lcov-report/lib/sanitize/visitors/allowed-fields.js.html +367 -0
- package/coverage/lcov-report/lib/sanitize/visitors/index.html +191 -0
- package/coverage/lcov-report/lib/sanitize/visitors/index.js.html +112 -0
- package/coverage/lcov-report/lib/sanitize/visitors/remove-password.js.html +106 -0
- package/coverage/lcov-report/lib/sanitize/visitors/remove-private.js.html +118 -0
- package/coverage/lcov-report/lib/sanitize/visitors/remove-restricted-relations.js.html +316 -0
- package/coverage/lcov-report/lib/sanitize/visitors/restricted-fields.js.html +181 -0
- package/coverage/lcov-report/lib/string-formatting.js.html +322 -0
- package/coverage/lcov-report/lib/validators.js.html +445 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/lib/index.js +2 -2
- package/lib/sanitize/index.js +91 -101
- package/lib/sanitize/sanitizers.js +6 -0
- package/lib/traverse/factory.js +4 -1
- package/lib/traverse/query-filters.js +2 -2
- package/lib/traverse/query-sort.js +11 -0
- package/package.json +2 -2
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
var addSorting = (function() {
|
|
3
|
+
'use strict';
|
|
4
|
+
var cols,
|
|
5
|
+
currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// returns the summary table element
|
|
11
|
+
function getTable() {
|
|
12
|
+
return document.querySelector('.coverage-summary');
|
|
13
|
+
}
|
|
14
|
+
// returns the thead element of the summary table
|
|
15
|
+
function getTableHeader() {
|
|
16
|
+
return getTable().querySelector('thead tr');
|
|
17
|
+
}
|
|
18
|
+
// returns the tbody element of the summary table
|
|
19
|
+
function getTableBody() {
|
|
20
|
+
return getTable().querySelector('tbody');
|
|
21
|
+
}
|
|
22
|
+
// returns the th element for nth column
|
|
23
|
+
function getNthColumn(n) {
|
|
24
|
+
return getTableHeader().querySelectorAll('th')[n];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function onFilterInput() {
|
|
28
|
+
const searchValue = document.getElementById('fileSearch').value;
|
|
29
|
+
const rows = document.getElementsByTagName('tbody')[0].children;
|
|
30
|
+
for (let i = 0; i < rows.length; i++) {
|
|
31
|
+
const row = rows[i];
|
|
32
|
+
if (
|
|
33
|
+
row.textContent
|
|
34
|
+
.toLowerCase()
|
|
35
|
+
.includes(searchValue.toLowerCase())
|
|
36
|
+
) {
|
|
37
|
+
row.style.display = '';
|
|
38
|
+
} else {
|
|
39
|
+
row.style.display = 'none';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// loads the search box
|
|
45
|
+
function addSearchBox() {
|
|
46
|
+
var template = document.getElementById('filterTemplate');
|
|
47
|
+
var templateClone = template.content.cloneNode(true);
|
|
48
|
+
templateClone.getElementById('fileSearch').oninput = onFilterInput;
|
|
49
|
+
template.parentElement.appendChild(templateClone);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// loads all columns
|
|
53
|
+
function loadColumns() {
|
|
54
|
+
var colNodes = getTableHeader().querySelectorAll('th'),
|
|
55
|
+
colNode,
|
|
56
|
+
cols = [],
|
|
57
|
+
col,
|
|
58
|
+
i;
|
|
59
|
+
|
|
60
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
61
|
+
colNode = colNodes[i];
|
|
62
|
+
col = {
|
|
63
|
+
key: colNode.getAttribute('data-col'),
|
|
64
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
|
65
|
+
type: colNode.getAttribute('data-type') || 'string'
|
|
66
|
+
};
|
|
67
|
+
cols.push(col);
|
|
68
|
+
if (col.sortable) {
|
|
69
|
+
col.defaultDescSort = col.type === 'number';
|
|
70
|
+
colNode.innerHTML =
|
|
71
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return cols;
|
|
75
|
+
}
|
|
76
|
+
// attaches a data attribute to every tr element with an object
|
|
77
|
+
// of data values keyed by column name
|
|
78
|
+
function loadRowData(tableRow) {
|
|
79
|
+
var tableCols = tableRow.querySelectorAll('td'),
|
|
80
|
+
colNode,
|
|
81
|
+
col,
|
|
82
|
+
data = {},
|
|
83
|
+
i,
|
|
84
|
+
val;
|
|
85
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
86
|
+
colNode = tableCols[i];
|
|
87
|
+
col = cols[i];
|
|
88
|
+
val = colNode.getAttribute('data-value');
|
|
89
|
+
if (col.type === 'number') {
|
|
90
|
+
val = Number(val);
|
|
91
|
+
}
|
|
92
|
+
data[col.key] = val;
|
|
93
|
+
}
|
|
94
|
+
return data;
|
|
95
|
+
}
|
|
96
|
+
// loads all row data
|
|
97
|
+
function loadData() {
|
|
98
|
+
var rows = getTableBody().querySelectorAll('tr'),
|
|
99
|
+
i;
|
|
100
|
+
|
|
101
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
102
|
+
rows[i].data = loadRowData(rows[i]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// sorts the table using the data for the ith column
|
|
106
|
+
function sortByIndex(index, desc) {
|
|
107
|
+
var key = cols[index].key,
|
|
108
|
+
sorter = function(a, b) {
|
|
109
|
+
a = a.data[key];
|
|
110
|
+
b = b.data[key];
|
|
111
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
112
|
+
},
|
|
113
|
+
finalSorter = sorter,
|
|
114
|
+
tableBody = document.querySelector('.coverage-summary tbody'),
|
|
115
|
+
rowNodes = tableBody.querySelectorAll('tr'),
|
|
116
|
+
rows = [],
|
|
117
|
+
i;
|
|
118
|
+
|
|
119
|
+
if (desc) {
|
|
120
|
+
finalSorter = function(a, b) {
|
|
121
|
+
return -1 * sorter(a, b);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
126
|
+
rows.push(rowNodes[i]);
|
|
127
|
+
tableBody.removeChild(rowNodes[i]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
rows.sort(finalSorter);
|
|
131
|
+
|
|
132
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
133
|
+
tableBody.appendChild(rows[i]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// removes sort indicators for current column being sorted
|
|
137
|
+
function removeSortIndicators() {
|
|
138
|
+
var col = getNthColumn(currentSort.index),
|
|
139
|
+
cls = col.className;
|
|
140
|
+
|
|
141
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
142
|
+
col.className = cls;
|
|
143
|
+
}
|
|
144
|
+
// adds sort indicators for current column being sorted
|
|
145
|
+
function addSortIndicators() {
|
|
146
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
|
147
|
+
? ' sorted-desc'
|
|
148
|
+
: ' sorted';
|
|
149
|
+
}
|
|
150
|
+
// adds event listeners for all sorter widgets
|
|
151
|
+
function enableUI() {
|
|
152
|
+
var i,
|
|
153
|
+
el,
|
|
154
|
+
ithSorter = function ithSorter(i) {
|
|
155
|
+
var col = cols[i];
|
|
156
|
+
|
|
157
|
+
return function() {
|
|
158
|
+
var desc = col.defaultDescSort;
|
|
159
|
+
|
|
160
|
+
if (currentSort.index === i) {
|
|
161
|
+
desc = !currentSort.desc;
|
|
162
|
+
}
|
|
163
|
+
sortByIndex(i, desc);
|
|
164
|
+
removeSortIndicators();
|
|
165
|
+
currentSort.index = i;
|
|
166
|
+
currentSort.desc = desc;
|
|
167
|
+
addSortIndicators();
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
171
|
+
if (cols[i].sortable) {
|
|
172
|
+
// add the click event handler on the th so users
|
|
173
|
+
// dont have to click on those tiny arrows
|
|
174
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
175
|
+
if (el.addEventListener) {
|
|
176
|
+
el.addEventListener('click', ithSorter(i));
|
|
177
|
+
} else {
|
|
178
|
+
el.attachEvent('onclick', ithSorter(i));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// adds sorting functionality to the UI
|
|
184
|
+
return function() {
|
|
185
|
+
if (!getTable()) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
cols = loadColumns();
|
|
189
|
+
loadData();
|
|
190
|
+
addSearchBox();
|
|
191
|
+
addSortIndicators();
|
|
192
|
+
enableUI();
|
|
193
|
+
};
|
|
194
|
+
})();
|
|
195
|
+
|
|
196
|
+
window.addEventListener('load', addSorting);
|
package/lib/index.js
CHANGED
|
@@ -41,8 +41,8 @@ const { pipeAsync, mapAsync, reduceAsync, forEachAsync } = require('./async');
|
|
|
41
41
|
const convertQueryParams = require('./convert-query-params');
|
|
42
42
|
const importDefault = require('./import-default');
|
|
43
43
|
const template = require('./template');
|
|
44
|
-
const traverse = require('./traverse');
|
|
45
44
|
const file = require('./file');
|
|
45
|
+
const traverse = require('./traverse');
|
|
46
46
|
|
|
47
47
|
module.exports = {
|
|
48
48
|
yup,
|
|
@@ -91,6 +91,6 @@ module.exports = {
|
|
|
91
91
|
validateYupSchemaSync,
|
|
92
92
|
convertQueryParams,
|
|
93
93
|
importDefault,
|
|
94
|
-
traverse,
|
|
95
94
|
file,
|
|
95
|
+
traverse,
|
|
96
96
|
};
|
package/lib/sanitize/index.js
CHANGED
|
@@ -11,138 +11,128 @@ const traverseEntity = require('../traverse-entity');
|
|
|
11
11
|
|
|
12
12
|
const { traverseQueryFilters, traverseQuerySort, traverseQueryPopulate } = require('../traverse');
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const nonWritableAttributes = getNonWritableAttributes(schema);
|
|
22
|
-
|
|
23
|
-
const transforms = [
|
|
24
|
-
// Remove non writable attributes
|
|
25
|
-
traverseEntity(visitors.restrictedFields(nonWritableAttributes), { schema }),
|
|
26
|
-
];
|
|
14
|
+
const createContentAPISanitizers = () => {
|
|
15
|
+
const sanitizeInput = (data, schema, { auth } = {}) => {
|
|
16
|
+
if (isArray(data)) {
|
|
17
|
+
return Promise.all(data.map((entry) => sanitizeInput(entry, schema, { auth })));
|
|
18
|
+
}
|
|
27
19
|
|
|
28
|
-
|
|
29
|
-
// Remove restricted relations
|
|
30
|
-
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
|
31
|
-
}
|
|
20
|
+
const nonWritableAttributes = getNonWritableAttributes(schema);
|
|
32
21
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
const transforms = [
|
|
23
|
+
// Remove non writable attributes
|
|
24
|
+
traverseEntity(visitors.restrictedFields(nonWritableAttributes), { schema }),
|
|
25
|
+
];
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
if (auth) {
|
|
28
|
+
// Remove restricted relations
|
|
29
|
+
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
|
30
|
+
}
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
// Apply sanitizers from registry if exists
|
|
33
|
+
strapi.sanitizers
|
|
34
|
+
.get('content-api.input')
|
|
35
|
+
.forEach((sanitizer) => transforms.push(sanitizer(schema)));
|
|
45
36
|
|
|
46
|
-
|
|
37
|
+
return pipeAsync(...transforms)(data);
|
|
38
|
+
};
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
40
|
+
const sanitizeOuput = (data, schema, { auth } = {}) => {
|
|
41
|
+
if (isArray(data)) {
|
|
42
|
+
return Promise.all(data.map((entry) => sanitizeOuput(entry, schema, { auth })));
|
|
43
|
+
}
|
|
51
44
|
|
|
52
|
-
|
|
53
|
-
strapi.sanitizers
|
|
54
|
-
.get('content-api.output')
|
|
55
|
-
.forEach((sanitizer) => transforms.push(sanitizer(schema)));
|
|
45
|
+
const transforms = [sanitizers.defaultSanitizeOutput(schema)];
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
if (auth) {
|
|
48
|
+
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
|
49
|
+
}
|
|
59
50
|
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
// Apply sanitizers from registry if exists
|
|
52
|
+
strapi.sanitizers
|
|
53
|
+
.get('content-api.output')
|
|
54
|
+
.forEach((sanitizer) => transforms.push(sanitizer(schema)));
|
|
62
55
|
|
|
63
|
-
|
|
56
|
+
return pipeAsync(...transforms)(data);
|
|
57
|
+
};
|
|
64
58
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
59
|
+
const sanitizeQuery = async (query, schema, { auth } = {}) => {
|
|
60
|
+
const { filters, sort, fields, populate } = query;
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
Object.assign(sanitizedParams, { sort: await this.sort(sort, schema, { auth }) });
|
|
71
|
-
}
|
|
62
|
+
const sanitizedQuery = cloneDeep(query);
|
|
72
63
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
if (filters) {
|
|
65
|
+
Object.assign(sanitizedQuery, { filters: await sanitizeFilters(filters, schema, { auth }) });
|
|
66
|
+
}
|
|
76
67
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
if (sort) {
|
|
69
|
+
Object.assign(sanitizedQuery, { sort: await sanitizeSort(sort, schema, { auth }) });
|
|
70
|
+
}
|
|
80
71
|
|
|
81
|
-
|
|
82
|
-
|
|
72
|
+
if (fields) {
|
|
73
|
+
Object.assign(sanitizedQuery, { fields: await sanitizeFields(fields, schema) });
|
|
74
|
+
}
|
|
83
75
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
76
|
+
if (populate) {
|
|
77
|
+
Object.assign(sanitizedQuery, { populate: await sanitizePopulate(populate, schema) });
|
|
78
|
+
}
|
|
88
79
|
|
|
89
|
-
|
|
80
|
+
return sanitizedQuery;
|
|
81
|
+
};
|
|
90
82
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
83
|
+
const sanitizeFilters = (filters, schema, { auth } = {}) => {
|
|
84
|
+
if (isArray(filters)) {
|
|
85
|
+
return Promise.all(filters.map((filter) => sanitizeFilters(filter, schema, { auth })));
|
|
86
|
+
}
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
strapi.sanitizers
|
|
97
|
-
.get('content-api.filters')
|
|
98
|
-
.forEach((sanitizer) => transforms.push(sanitizer(schema)));
|
|
88
|
+
const transforms = [sanitizers.defaultSanitizeFilters(schema)];
|
|
99
89
|
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
if (auth) {
|
|
91
|
+
transforms.push(traverseQueryFilters(visitors.removeRestrictedRelations(auth), { schema }));
|
|
92
|
+
}
|
|
102
93
|
|
|
103
|
-
|
|
104
|
-
|
|
94
|
+
return pipeAsync(...transforms)(filters);
|
|
95
|
+
};
|
|
105
96
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
97
|
+
const sanitizeSort = (sort, schema, { auth } = {}) => {
|
|
98
|
+
const transforms = [sanitizers.defaultSanitizeSort(schema)];
|
|
109
99
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.forEach((sanitizer) => transforms.push(sanitizer(schema)));
|
|
100
|
+
if (auth) {
|
|
101
|
+
transforms.push(traverseQuerySort(visitors.removeRestrictedRelations(auth), { schema }));
|
|
102
|
+
}
|
|
114
103
|
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
return pipeAsync(...transforms)(sort);
|
|
105
|
+
};
|
|
117
106
|
|
|
118
|
-
|
|
119
|
-
|
|
107
|
+
const sanitizeFields = (fields, schema) => {
|
|
108
|
+
const transforms = [sanitizers.defaultSanitizeFields(schema)];
|
|
120
109
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.get('content-api.fields')
|
|
124
|
-
.forEach((sanitizer) => transforms.push(sanitizer(schema)));
|
|
110
|
+
return pipeAsync(...transforms)(fields);
|
|
111
|
+
};
|
|
125
112
|
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
const sanitizePopulate = (populate, schema, { auth } = {}) => {
|
|
114
|
+
const transforms = [sanitizers.defaultSanitizePopulate(schema)];
|
|
128
115
|
|
|
129
|
-
|
|
130
|
-
|
|
116
|
+
if (auth) {
|
|
117
|
+
transforms.push(traverseQueryPopulate(visitors.removeRestrictedRelations(auth), { schema }));
|
|
118
|
+
}
|
|
131
119
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
traverseQueryPopulate(visitors.removeRestrictedRelations(auth), { schema })
|
|
135
|
-
);
|
|
136
|
-
}
|
|
120
|
+
return pipeAsync(...transforms)(populate);
|
|
121
|
+
};
|
|
137
122
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
123
|
+
return {
|
|
124
|
+
input: sanitizeInput,
|
|
125
|
+
output: sanitizeOuput,
|
|
126
|
+
query: sanitizeQuery,
|
|
127
|
+
filters: sanitizeFilters,
|
|
128
|
+
sort: sanitizeSort,
|
|
129
|
+
fields: sanitizeFields,
|
|
130
|
+
populate: sanitizePopulate,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
142
133
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
},
|
|
134
|
+
module.exports = {
|
|
135
|
+
contentAPI: createContentAPISanitizers(),
|
|
146
136
|
|
|
147
137
|
sanitizers,
|
|
148
138
|
visitors,
|
|
@@ -38,6 +38,8 @@ const defaultSanitizeFilters = curry((schema, filters) => {
|
|
|
38
38
|
traverseQueryFilters(removeDynamicZones, { schema }),
|
|
39
39
|
// Remove morpTo relations from filters
|
|
40
40
|
traverseQueryFilters(removeMorphToRelations, { schema }),
|
|
41
|
+
// Remove passwords from filters
|
|
42
|
+
traverseQueryFilters(removePassword, { schema }),
|
|
41
43
|
// Remove private from filters
|
|
42
44
|
traverseQueryFilters(removePrivate, { schema }),
|
|
43
45
|
// Remove empty objects
|
|
@@ -69,6 +71,8 @@ const defaultSanitizeSort = curry((schema, sort) => {
|
|
|
69
71
|
traverseQuerySort(removeMorphToRelations, { schema }),
|
|
70
72
|
// Remove private from sort
|
|
71
73
|
traverseQuerySort(removePrivate, { schema }),
|
|
74
|
+
// Remove passwords from filters
|
|
75
|
+
traverseQuerySort(removePassword, { schema }),
|
|
72
76
|
// Remove keys for empty non-scalar values
|
|
73
77
|
traverseQuerySort(
|
|
74
78
|
({ key, attribute, value }, { remove }) => {
|
|
@@ -94,6 +98,8 @@ const defaultSanitizeFields = curry((schema, fields) => {
|
|
|
94
98
|
),
|
|
95
99
|
// Remove private fields
|
|
96
100
|
traverseQueryFields(removePrivate, { schema }),
|
|
101
|
+
// Remove password fields
|
|
102
|
+
traverseQueryFields(removePassword, { schema }),
|
|
97
103
|
// Remove nil values from fields array
|
|
98
104
|
(value) => (isArray(value) ? value.filter((field) => !isNil(field)) : value)
|
|
99
105
|
)(fields);
|
package/lib/traverse/factory.js
CHANGED
|
@@ -37,7 +37,10 @@ module.exports = () => {
|
|
|
37
37
|
const keys = utils.keys(out);
|
|
38
38
|
|
|
39
39
|
for (const key of keys) {
|
|
40
|
-
const attribute =
|
|
40
|
+
const attribute =
|
|
41
|
+
schema?.attributes?.[key] ??
|
|
42
|
+
// look for the attribute when key is in snake_case
|
|
43
|
+
schema?.attributes?.[strapi.db.metadata.get(schema?.uid).columnToAttribute[key]];
|
|
41
44
|
|
|
42
45
|
const newPath = { ...path };
|
|
43
46
|
|
|
@@ -11,8 +11,8 @@ const filters = traverseFactory()
|
|
|
11
11
|
async (visitor, options, filters, { recurse }) => {
|
|
12
12
|
return Promise.all(
|
|
13
13
|
filters.map((filter, i) => {
|
|
14
|
-
// In filters, only operators such as $and or $or
|
|
15
|
-
// array, thus we can update the raw path but not the attribute one
|
|
14
|
+
// In filters, only operators such as $and, $in, $notIn or $or and implicit operators like [...]
|
|
15
|
+
// can have a value array, thus we can update the raw path but not the attribute one
|
|
16
16
|
const newPath = { ...options.path, raw: `${options.path.raw}[${i}]` };
|
|
17
17
|
|
|
18
18
|
return recurse(visitor, { ...options, path: newPath }, filter);
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const {
|
|
4
4
|
curry,
|
|
5
5
|
isString,
|
|
6
|
+
isObject,
|
|
6
7
|
map,
|
|
7
8
|
trim,
|
|
8
9
|
split,
|
|
@@ -21,6 +22,7 @@ const ORDER_VALUES = Object.values(ORDERS);
|
|
|
21
22
|
|
|
22
23
|
const isSortOrder = (value) => ORDER_VALUES.includes(value.toLowerCase());
|
|
23
24
|
const isStringArray = (value) => Array.isArray(value) && value.every(isString);
|
|
25
|
+
const isObjectArray = (value) => Array.isArray(value) && value.every(isObject);
|
|
24
26
|
const isNestedSorts = (value) => isString(value) && value.split(',').length > 1;
|
|
25
27
|
|
|
26
28
|
const sort = traverseFactory()
|
|
@@ -45,6 +47,15 @@ const sort = traverseFactory()
|
|
|
45
47
|
);
|
|
46
48
|
}
|
|
47
49
|
)
|
|
50
|
+
.intercept(
|
|
51
|
+
// Array of objects [{ foo: 'asc' }, { bar: 'desc', baz: 'asc' }] => map(recurse), then filter out empty items
|
|
52
|
+
isObjectArray,
|
|
53
|
+
async (visitor, options, sort, { recurse }) => {
|
|
54
|
+
return Promise.all(sort.map((nestedSort) => recurse(visitor, options, nestedSort))).then(
|
|
55
|
+
(res) => res.filter((nestedSort) => !isEmpty(nestedSort))
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
)
|
|
48
59
|
// Parse string values
|
|
49
60
|
.parse(
|
|
50
61
|
(sort) => typeof sort === 'string',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"node": ">=14.19.1 <=18.x.x",
|
|
47
47
|
"npm": ">=6.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "b3cb13cb14302ba2ccf2ab6fab774f08efe9f1b7"
|
|
50
50
|
}
|