* [COMPLIANCE] Add Copyright and License Headers * chore: 🤖 update Copyright headers to satisfy our lint rules --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
28 lines
619 B
JavaScript
28 lines
619 B
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import Transform from '@ember-data/serializer/transform';
|
|
|
|
export default class ObjectAsArrayTransform extends Transform {
|
|
deserialize(serialized) {
|
|
const obj = serialized || {};
|
|
return Object.entries(obj).map(([key, value]) => ({ key, value }));
|
|
}
|
|
serialize(deserialized) {
|
|
const array = deserialized || [];
|
|
|
|
if (!array.length) {
|
|
return null;
|
|
}
|
|
|
|
return array.reduce((result, currentValue) => {
|
|
const { key, value } = currentValue;
|
|
result[key] = value;
|
|
|
|
return result;
|
|
}, {});
|
|
}
|
|
}
|