Skip to content

Commit c7c5545

Browse files
authored
[VET-2546] **Breaking Change** Do not flatten request body nor unflatten response body for db.options (#283)
* remove unflattened properties for get/getAll/set/getAvailable
1 parent 0836325 commit c7c5545

3 files changed

Lines changed: 16 additions & 36 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ Expects the following parameters:
502502

503503
- database (`string`)
504504

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

507507
- params (`object`)
508508

lib/db/options.js

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const flat = require('flat');
44
const DB_OPTIONS = require('./dbopts');
55
const { httpBody } = require('../response-transforms');
66

7+
const FLATTENED_DB_OPTIONS = flat.flatten(DB_OPTIONS);
8+
79
const dispatchDBOptions = (conn, config, body) => {
810
config.headers.set('Content-Type', 'application/json');
911

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

1517
if (body) {
16-
requestOptions.body = JSON.stringify(flat(body, { safe: true }));
18+
requestOptions.body = JSON.stringify(body);
1719
}
1820
return fetch(
1921
conn.request('admin', 'databases', config.database, 'options'),
@@ -33,17 +35,8 @@ const get = (conn, database, params) => {
3335
// TODO now that `getAll` is available, remove use of DB_OPTIONS and require
3436
// user to specify which options they want
3537
// Do we want to do this for v3+ of stardog.js?
36-
params || DB_OPTIONS // the default list of options to GET values for
37-
)
38-
.then(httpBody)
39-
.then(res => {
40-
if (res.status === 200) {
41-
return Object.assign({}, res, {
42-
body: flat.unflatten(res.body),
43-
});
44-
}
45-
return res;
46-
});
38+
params || FLATTENED_DB_OPTIONS // the default list of options to GET values for
39+
).then(httpBody);
4740
};
4841

4942
const getAll = (conn, database) => {
@@ -52,16 +45,7 @@ const getAll = (conn, database) => {
5245
headers,
5346
database,
5447
method: 'GET',
55-
})
56-
.then(httpBody)
57-
.then(res => {
58-
if (res.status === 200) {
59-
return Object.assign({}, res, {
60-
body: flat.unflatten(res.body),
61-
});
62-
}
63-
return res;
64-
});
48+
}).then(httpBody);
6549
};
6650

6751
const set = (conn, database, databaseOptions, params) => {
@@ -83,16 +67,7 @@ const getAvailable = conn => {
8367
return fetch(conn.request('admin', 'config_properties'), {
8468
method: 'GET',
8569
headers,
86-
})
87-
.then(httpBody)
88-
.then(res => {
89-
if (res.status === 200) {
90-
return Object.assign({}, res, {
91-
body: flat.unflatten(res.body),
92-
});
93-
}
94-
return res;
95-
});
70+
}).then(httpBody);
9671
};
9772

9873
module.exports = { get, getAll, set, getAvailable };

test/getDBOptions.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ describe('options.get()', () => {
2727
it('should get the options of a DB', () =>
2828
options.get(conn, database).then(res => {
2929
expect(res.status).toEqual(200);
30+
expect(typeof res.body).toEqual('object');
3031
expect(res.body).toMatchObject({
31-
index: {
32-
type: 'Disk',
33-
},
32+
'index.type': 'Disk',
3433
});
3534
}));
3635
});
@@ -49,6 +48,9 @@ describe('options.getAll()', () => {
4948
options.getAll(conn, database).then(res => {
5049
expect(res.status).toEqual(200);
5150
expect(typeof res.body).toEqual('object');
51+
expect(res.body).toMatchObject({
52+
'index.type': 'Disk',
53+
});
5254
}));
5355
});
5456

@@ -61,5 +63,8 @@ describe('options.getAvailable', () => {
6163
options.getAvailable(conn).then(res => {
6264
expect(res.status).toEqual(200);
6365
expect(typeof res.body).toEqual('object');
66+
expect(res.body).toMatchObject({
67+
'docs.path': {},
68+
});
6469
}));
6570
});

0 commit comments

Comments
 (0)