2020-03-25 12:51:26 +00:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
2020-05-02 06:38:05 +00:00
|
|
|
// Convert a map[string]interface{} into an array of objects
|
|
|
|
// where the key becomes a property at propKey.
|
|
|
|
// This is destructive. The original object is mutated to avoid
|
|
|
|
// excessive copies of the originals which would otherwise just
|
|
|
|
// be garbage collected.
|
|
|
|
const unmap = (hash, propKey) =>
|
2020-09-05 02:44:21 +00:00
|
|
|
Object.keys(hash)
|
|
|
|
.sort()
|
|
|
|
.map(key => {
|
|
|
|
const record = hash[key];
|
|
|
|
record[propKey] = key;
|
|
|
|
return record;
|
|
|
|
});
|
2020-05-02 06:38:05 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class Plugin extends ApplicationSerializer {
|
2020-03-25 12:51:26 +00:00
|
|
|
normalize(typeHash, hash) {
|
2020-05-03 04:31:17 +00:00
|
|
|
hash.PlainId = hash.ID;
|
2020-03-25 12:51:26 +00:00
|
|
|
|
|
|
|
// TODO This shouldn't hardcode `csi/` as part of the ID,
|
|
|
|
// but it is necessary to make the correct find request and the
|
|
|
|
// payload does not contain the required information to derive
|
|
|
|
// this identifier.
|
|
|
|
hash.ID = `csi/${hash.ID}`;
|
|
|
|
|
2020-05-02 06:38:05 +00:00
|
|
|
const nodes = hash.Nodes || {};
|
|
|
|
const controllers = hash.Controllers || {};
|
|
|
|
|
|
|
|
hash.Nodes = unmap(nodes, 'NodeID');
|
|
|
|
hash.Controllers = unmap(controllers, 'NodeID');
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
return super.normalize(typeHash, hash);
|
|
|
|
}
|
|
|
|
}
|