Skip to content

Commit

Permalink
refactor: minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 4, 2021
1 parent 9146fb2 commit 7528854
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/ts/pipes/flp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const eventifyPipe: IPipe = {
}

const batched = await Promise.all(
data
// @ts-ignore
.map((data) => eventifyPipe.execute({ data }, identity)),
data.map((data) =>
eventifyPipe.execute({ data } as ITransmittable, identity),
),
)

const [arrayRejected, arrayResolved] = batched.reduce(
Expand Down
7 changes: 5 additions & 2 deletions src/main/ts/pipes/httpBatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpMethod } from '@qiwi/substrate'
import { HttpMethod, Extends } from '@qiwi/substrate'

import { IPipe } from '../interfaces'
import { IHttpHeaders } from './http'
Expand All @@ -11,6 +11,9 @@ export type IHttpBatchPipeOpts = {
headers?: IHttpHeaders
}

const asArray = <T>(value: T): Extends<T, any[], T, T[]> =>
(Array.isArray(value) ? value: [value]) as Extends<T, any[], T, T[]>

export const createHttpBatchPipe = ({
url,
batchUrl,
Expand All @@ -22,7 +25,7 @@ export const createHttpBatchPipe = ({
.map((url) => ({ url, headers, method }))

const batchOpts = batchUrl
? ([] as string[]).concat(batchUrl).map((url) => ({ url, headers, method }))
? (asArray(batchUrl) as string[]).map((url) => ({ url, headers, method }))
: opts

const httpPipe = createHttpPipeFallback(opts)
Expand Down

0 comments on commit 7528854

Please sign in to comment.