refactor: inherit default curl parser values (#2169)

This commit is contained in:
kyteinsky
2022-04-04 21:38:12 +05:30
committed by GitHub
parent dcbc3b6356
commit eea8a44746
16 changed files with 1354 additions and 977 deletions

View File

@@ -0,0 +1,43 @@
import { pipe, flow } from "fp-ts/function"
import * as O from "fp-ts/Option"
import * as A from "fp-ts/Array"
import * as Sep from "fp-ts/Separated"
import { HoppRESTParam } from "@hoppscotch/data"
const isDangling = ([_, value]: [string, string]) => !value
/**
* Converts queries to HoppRESTParam format and separates dangling ones
* @param params Array of key value pairs of queries
* @returns Object containing separated queries and dangling queries
*/
export function getQueries(params: Array<[string, string]>): {
queries: Array<HoppRESTParam>
danglingParams: Array<string>
} {
return pipe(
params,
O.of,
O.map(
flow(
A.partition(isDangling),
Sep.bimap(
A.map(([key, value]) => ({
key,
value,
active: true,
})),
A.map(([key]) => key)
),
(sep) => ({
queries: sep.left,
danglingParams: sep.right,
})
)
),
O.getOrElseW(() => ({
queries: [],
danglingParams: [],
}))
)
}