From 0843f93cd9bad8063029c8f06a651194b05fc4dc Mon Sep 17 00:00:00 2001 From: Vincenzo Chianese Date: Tue, 29 Oct 2019 07:24:32 -0700 Subject: [PATCH] refactor: convert once to TaskEither --- packages/core/src/factory.ts | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/core/src/factory.ts b/packages/core/src/factory.ts index a46e72cb8..2823392ef 100644 --- a/packages/core/src/factory.ts +++ b/packages/core/src/factory.ts @@ -24,20 +24,22 @@ export function factory( const config = defaults(c, defaultConfig); return pipe( - TaskEither.fromEither(components.route({ resources, input })), - TaskEither.chain(resource => - TaskEither.fromEither( - pipe( - sequenceValidation( - config.validateRequest ? components.validateInput({ resource, element: input }) : Either.right(input), - config.checkSecurity ? validateSecurity(input, resource) : Either.right(input) - ), - Either.map(() => ({ resource, inputValidations: [] })), - Either.orElse< - NonEmptyArray, - { resource: Resource; inputValidations: IPrismDiagnostic[] }, - Error - >(inputValidations => Either.right({ resource, inputValidations })) + TaskEither.fromEither( + pipe( + components.route({ resources, input }), + Either.chain(resource => + pipe( + sequenceValidation( + config.validateRequest ? components.validateInput({ resource, element: input }) : Either.right(input), + config.checkSecurity ? validateSecurity(input, resource) : Either.right(input) + ), + Either.map(() => ({ resource, inputValidations: [] })), + Either.orElse< + NonEmptyArray, + { resource: Resource; inputValidations: IPrismDiagnostic[] }, + Error + >(inputValidations => Either.right({ resource, inputValidations })) + ) ) ) ),