refactor: inherit default curl parser values (#2169)
This commit is contained in:
43
packages/hoppscotch-app/helpers/curl/sub_helpers/queries.ts
Normal file
43
packages/hoppscotch-app/helpers/curl/sub_helpers/queries.ts
Normal 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: [],
|
||||
}))
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user