Skip to content

Commit

Permalink
refactor: convert once to TaskEither
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Oct 29, 2019
1 parent 59b8076 commit 0843f93
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/core/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ export function factory<Resource, Input, Output, Config extends IPrismConfig>(
const config = defaults<unknown, Config>(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<IPrismDiagnostic>,
{ 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<IPrismDiagnostic>,
{ resource: Resource; inputValidations: IPrismDiagnostic[] },
Error
>(inputValidations => Either.right({ resource, inputValidations }))
)
)
)
),
Expand Down

0 comments on commit 0843f93

Please sign in to comment.