github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/serializers/plugin.js (about)

     1  import ApplicationSerializer from './application';
     2  import classic from 'ember-classic-decorator';
     3  
     4  // Convert a map[string]interface{} into an array of objects
     5  // where the key becomes a property at propKey.
     6  // This is destructive. The original object is mutated to avoid
     7  // excessive copies of the originals which would otherwise just
     8  // be garbage collected.
     9  const unmap = (hash, propKey) =>
    10    Object.keys(hash)
    11      .sort()
    12      .map((key) => {
    13        const record = hash[key];
    14        record[propKey] = key;
    15        return record;
    16      });
    17  
    18  @classic
    19  export default class Plugin extends ApplicationSerializer {
    20    normalize(typeHash, hash) {
    21      hash.PlainId = hash.ID;
    22  
    23      // TODO This shouldn't hardcode `csi/` as part of the ID,
    24      // but it is necessary to make the correct find request and the
    25      // payload does not contain the required information to derive
    26      // this identifier.
    27      hash.ID = `csi/${hash.ID}`;
    28  
    29      const nodes = hash.Nodes || {};
    30      const controllers = hash.Controllers || {};
    31  
    32      hash.Nodes = unmap(nodes, 'NodeID');
    33      hash.Controllers = unmap(controllers, 'NodeID');
    34  
    35      return super.normalize(typeHash, hash);
    36    }
    37  }