2022-05-30 17:10:44 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
|
|
|
@classic
|
|
|
|
export default class VariableSerializer extends ApplicationSerializer {
|
2022-07-06 18:17:10 +00:00
|
|
|
separateNanos = ['CreateTime', 'ModifyTime'];
|
2022-05-30 17:10:44 +00:00
|
|
|
|
2022-08-15 15:56:09 +00:00
|
|
|
normalize(typeHash, hash) {
|
|
|
|
// ID is a composite of both the job ID and the namespace the job is in
|
|
|
|
hash.ID = `${hash.Path}@${hash.Namespace || 'default'}`;
|
|
|
|
return super.normalize(typeHash, hash);
|
|
|
|
}
|
|
|
|
|
2022-05-30 17:10:44 +00:00
|
|
|
// Transform API's Items object into an array of a KeyValue objects
|
|
|
|
normalizeFindRecordResponse(store, typeClass, hash, id, ...args) {
|
|
|
|
if (!hash.Items) {
|
|
|
|
hash.Items = { '': '' };
|
|
|
|
}
|
|
|
|
hash.KeyValues = Object.entries(hash.Items).map(([key, value]) => {
|
|
|
|
return {
|
|
|
|
key,
|
|
|
|
value,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
delete hash.Items;
|
|
|
|
return super.normalizeFindRecordResponse(
|
|
|
|
store,
|
|
|
|
typeClass,
|
|
|
|
hash,
|
|
|
|
id,
|
|
|
|
...args
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transform our KeyValues array into an Items object
|
|
|
|
serialize(snapshot, options) {
|
|
|
|
const json = super.serialize(snapshot, options);
|
2022-08-15 15:56:09 +00:00
|
|
|
json.ID = json.Path;
|
2022-05-30 17:10:44 +00:00
|
|
|
json.Items = json.KeyValues.reduce((acc, { key, value }) => {
|
|
|
|
acc[key] = value;
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
delete json.KeyValues;
|
2022-07-06 18:17:10 +00:00
|
|
|
delete json.ModifyTime;
|
|
|
|
delete json.CreateTime;
|
2022-05-30 17:10:44 +00:00
|
|
|
return json;
|
|
|
|
}
|
|
|
|
}
|