-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.js
44 lines (40 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { adapter } from './adapter.js'
import { asyncFetch, createHeaders, handleResponse } from './async-fetch.js'
/**
* @param {object} config
* @returns {object}
*/
export default function CouchDataAdapter(config) {
/**
* @param {object} env
*/
function load() {
return config
}
/**
* @param {object} env
* @returns {function}
*/
function link(env = { url: 'http://localhost:5984' }) {
/**
* @param {object} adapter
* @returns {object}
*/
return function () {
// parse url
const config = new URL(env.url)
return adapter({
config,
asyncFetch: asyncFetch(fetch),
headers: createHeaders(config.username, config.password),
handleResponse,
})
}
}
return Object.freeze({
id: 'couchdb-data-adapter',
port: 'data',
load,
link,
})
}