-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.js
28 lines (25 loc) · 868 Bytes
/
mod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { R } from './deps.js'
import { asyncFetch, createHeaders, handleResponse } from './async-fetch.js'
import adapter from './adapter.js'
const { mergeDeepLeft, defaultTo, pipe } = R
export default function ElasticsearchAdapter(config) {
return Object.freeze({
id: 'elasticsearch',
port: 'search',
load: pipe(
defaultTo({}),
mergeDeepLeft(config), // perfer config over what's passed from previous load
),
link: (env) => () => {
if (!env.url) throw new Error('Config URL is required elastic search')
const headers = createHeaders(config.username, config.password)
// TODO: probably shouldn't use origin, so to support mounting elasticsearch on path
return adapter({
config: new URL(env.url),
asyncFetch: asyncFetch(fetch),
headers,
handleResponse,
})
},
})
}