mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 13:43:41 +00:00
Move pipeAsync to @strapi/utils
This commit is contained in:
parent
7f285fb755
commit
d6516116b2
@ -15,7 +15,7 @@ const {
|
||||
intersection,
|
||||
} = require('lodash/fp');
|
||||
|
||||
const { contentTypes, traverseEntity, sanitize } = require('@strapi/utils');
|
||||
const { contentTypes, traverseEntity, sanitize, pipeAsync } = require('@strapi/utils');
|
||||
|
||||
const {
|
||||
constants,
|
||||
@ -44,7 +44,7 @@ module.exports = ({ action, ability, model }) => {
|
||||
|
||||
const permittedFields = fields.shouldIncludeAll ? null : getOutputFields(fields.permitted);
|
||||
|
||||
return sanitize.utils.pipeAsync(
|
||||
return pipeAsync(
|
||||
// Remove roles from createdBy & updateBy fields
|
||||
omitCreatorRoles,
|
||||
// Remove not allowed fields (RBAC)
|
||||
@ -59,7 +59,7 @@ module.exports = ({ action, ability, model }) => {
|
||||
|
||||
const permittedFields = fields.shouldIncludeAll ? null : getInputFields(fields.permitted);
|
||||
|
||||
return sanitize.utils.pipeAsync(
|
||||
return pipeAsync(
|
||||
// Remove not allowed fields (RBAC)
|
||||
traverseEntity(allowedFields(permittedFields), { schema }),
|
||||
// Remove roles from createdBy & updateBy fields
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const { prop, pick } = require('lodash/fp');
|
||||
const { MANY_RELATIONS } = require('@strapi/utils').relations.constants;
|
||||
const { setCreatorFields, sanitize } = require('@strapi/utils');
|
||||
const { setCreatorFields, pipeAsync } = require('@strapi/utils');
|
||||
|
||||
const { getService, wrapBadRequest, pickWritableAttributes } = require('../utils');
|
||||
const { validateBulkDeleteInput, validatePagination } = require('./validation');
|
||||
@ -79,7 +79,7 @@ module.exports = {
|
||||
const pickPermittedFields = permissionChecker.sanitizeCreateInput;
|
||||
const setCreator = setCreatorFields({ user });
|
||||
|
||||
const sanitizeFn = sanitize.utils.pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
||||
const sanitizeFn = pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
||||
|
||||
await wrapBadRequest(async () => {
|
||||
const sanitizedBody = await sanitizeFn(body);
|
||||
@ -119,7 +119,7 @@ module.exports = {
|
||||
const pickPermittedFields = permissionChecker.sanitizeUpdateInput(entity);
|
||||
const setCreator = setCreatorFields({ user, isEdition: true });
|
||||
|
||||
const sanitizeFn = sanitize.utils.pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
||||
const sanitizeFn = pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
||||
|
||||
await wrapBadRequest(async () => {
|
||||
const sanitizedBody = await sanitizeFn(body);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const { setCreatorFields, sanitize } = require('@strapi/utils');
|
||||
const { setCreatorFields, pipeAsync } = require('@strapi/utils');
|
||||
|
||||
const { getService, wrapBadRequest, pickWritableAttributes } = require('../utils');
|
||||
|
||||
@ -66,7 +66,7 @@ module.exports = {
|
||||
? setCreatorFields({ user, isEdition: true })
|
||||
: setCreatorFields({ user });
|
||||
|
||||
const sanitizeFn = sanitize.utils.pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
||||
const sanitizeFn = pipeAsync(pickWritables, pickPermittedFields, setCreator);
|
||||
|
||||
await wrapBadRequest(async () => {
|
||||
if (!entity) {
|
||||
|
||||
@ -32,6 +32,7 @@ const providerFactory = require('./provider-factory');
|
||||
const pagination = require('./pagination');
|
||||
const sanitize = require('./sanitize');
|
||||
const traverseEntity = require('./traverse-entity');
|
||||
const pipeAsync = require('./pipe-async');
|
||||
|
||||
module.exports = {
|
||||
yup,
|
||||
@ -65,4 +66,5 @@ module.exports = {
|
||||
hooks,
|
||||
providerFactory,
|
||||
pagination,
|
||||
pipeAsync,
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const pipeAsync = (...methods) => async data => {
|
||||
module.exports = (...methods) => async data => {
|
||||
let res = data;
|
||||
|
||||
for (const method of methods) {
|
||||
@ -9,7 +9,3 @@ const pipeAsync = (...methods) => async data => {
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
pipeAsync,
|
||||
};
|
||||
@ -4,8 +4,9 @@ const { isArray } = require('lodash/fp');
|
||||
|
||||
const traverseEntity = require('../traverse-entity');
|
||||
const { getNonWritableAttributes } = require('../content-types');
|
||||
const pipeAsync = require('../pipe-async');
|
||||
|
||||
const visitors = require('./visitors');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = {
|
||||
contentAPI: {
|
||||
@ -26,7 +27,7 @@ module.exports = {
|
||||
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
||||
}
|
||||
|
||||
return utils.pipeAsync(...transforms)(data);
|
||||
return pipeAsync(...transforms)(data);
|
||||
},
|
||||
|
||||
output(data, schema, { auth } = {}) {
|
||||
@ -43,7 +44,7 @@ module.exports = {
|
||||
transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
|
||||
}
|
||||
|
||||
return utils.pipeAsync(...transforms)(data);
|
||||
return pipeAsync(...transforms)(data);
|
||||
},
|
||||
},
|
||||
|
||||
@ -52,12 +53,11 @@ module.exports = {
|
||||
return Promise.all(data.map(entry => this.eventHub(entry, schema)));
|
||||
}
|
||||
|
||||
return utils.pipeAsync(
|
||||
return pipeAsync(
|
||||
traverseEntity(visitors.removePassword, { schema }),
|
||||
traverseEntity(visitors.removePrivate, { schema })
|
||||
)(data);
|
||||
},
|
||||
|
||||
utils,
|
||||
visitors,
|
||||
};
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const { get } = require('lodash/fp');
|
||||
|
||||
const { sanitize } = require('@strapi/utils');
|
||||
const { sanitize, pipeAsync } = require('@strapi/utils');
|
||||
|
||||
module.exports = ({ strapi }) => {
|
||||
const { service: getGraphQLService } = strapi.plugin('graphql');
|
||||
@ -62,11 +62,7 @@ module.exports = ({ strapi }) => {
|
||||
const unwrapData = get(attributeName);
|
||||
|
||||
// Sanitizer definition
|
||||
const sanitizeMorphAttribute = sanitize.utils.pipeAsync(
|
||||
wrapData,
|
||||
sanitizeData,
|
||||
unwrapData
|
||||
);
|
||||
const sanitizeMorphAttribute = pipeAsync(wrapData, sanitizeData, unwrapData);
|
||||
|
||||
return sanitizeMorphAttribute(data);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user