-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathoptions.js
More file actions
72 lines (62 loc) · 1.72 KB
/
options.js
File metadata and controls
72 lines (62 loc) · 1.72 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const flat = require('flat');
const DB_OPTIONS = require('./dbopts');
const { httpBody } = require('../response-transforms');
const FLATTENED_DB_OPTIONS = flat.flatten(DB_OPTIONS);
const dispatchDBOptions = (conn, config, body) => {
config.headers.set('Content-Type', 'application/json; charset=utf-8');
const requestOptions = {
method: config.method,
headers: config.headers,
};
if (body) {
requestOptions.body = JSON.stringify(body);
}
return fetch(
conn.request('admin', 'databases', config.database, 'options'),
requestOptions
);
};
const get = (conn, database, params) => {
const headers = conn.headers();
return dispatchDBOptions(
conn,
{
headers,
database,
method: 'PUT',
},
// TODO now that `getAll` is available, remove use of DB_OPTIONS and require
// user to specify which options they want
// Do we want to do this for v3+ of stardog.js?
params || FLATTENED_DB_OPTIONS // the default list of options to GET values for
).then(httpBody);
};
const getAll = (conn, database) => {
const headers = conn.headers();
return dispatchDBOptions(conn, {
headers,
database,
method: 'GET',
}).then(httpBody);
};
const set = (conn, database, databaseOptions, params) => {
const headers = conn.headers();
return dispatchDBOptions(
conn,
{
headers,
database,
method: 'POST',
},
databaseOptions
).then(httpBody);
};
const getAvailable = conn => {
const headers = conn.headers();
headers.set('Content-Type', 'application/json; charset=utf-8');
return fetch(conn.request('admin', 'config_properties'), {
method: 'GET',
headers,
}).then(httpBody);
};
module.exports = { get, getAll, set, getAvailable };