Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ Expects the following parameters:

- database (`string`)

- databaseOptions (`object`)
- databaseOptions (`{ [propertyKey: string]: any }`)

- params (`object`)

Expand Down
39 changes: 7 additions & 32 deletions lib/db/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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');

Expand All @@ -13,7 +15,7 @@ const dispatchDBOptions = (conn, config, body) => {
};

if (body) {
requestOptions.body = JSON.stringify(flat(body, { safe: true }));
requestOptions.body = JSON.stringify(body);
}
return fetch(
conn.request('admin', 'databases', config.database, 'options'),
Expand All @@ -33,17 +35,8 @@ const get = (conn, database, params) => {
// 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 || DB_OPTIONS // the default list of options to GET values for
)
.then(httpBody)
.then(res => {
if (res.status === 200) {
return Object.assign({}, res, {
body: flat.unflatten(res.body),
});
}
return res;
});
params || FLATTENED_DB_OPTIONS // the default list of options to GET values for
).then(httpBody);
};

const getAll = (conn, database) => {
Expand All @@ -52,16 +45,7 @@ const getAll = (conn, database) => {
headers,
database,
method: 'GET',
})
.then(httpBody)
.then(res => {
if (res.status === 200) {
return Object.assign({}, res, {
body: flat.unflatten(res.body),
});
}
return res;
});
}).then(httpBody);
};

const set = (conn, database, databaseOptions, params) => {
Expand All @@ -83,16 +67,7 @@ const getAvailable = conn => {
return fetch(conn.request('admin', 'config_properties'), {
method: 'GET',
headers,
})
.then(httpBody)
.then(res => {
if (res.status === 200) {
return Object.assign({}, res, {
body: flat.unflatten(res.body),
});
}
return res;
});
}).then(httpBody);
};

module.exports = { get, getAll, set, getAvailable };
11 changes: 8 additions & 3 deletions test/getDBOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ describe('options.get()', () => {
it('should get the options of a DB', () =>
options.get(conn, database).then(res => {
expect(res.status).toEqual(200);
expect(typeof res.body).toEqual('object');
expect(res.body).toMatchObject({
index: {
type: 'Disk',
},
'index.type': 'Disk',
});
}));
});
Expand All @@ -49,6 +48,9 @@ describe('options.getAll()', () => {
options.getAll(conn, database).then(res => {
expect(res.status).toEqual(200);
expect(typeof res.body).toEqual('object');
expect(res.body).toMatchObject({
'index.type': 'Disk',
});
}));
});

Expand All @@ -61,5 +63,8 @@ describe('options.getAvailable', () => {
options.getAvailable(conn).then(res => {
expect(res.status).toEqual(200);
expect(typeof res.body).toEqual('object');
expect(res.body).toMatchObject({
'docs.path': {},
});
}));
});