github.com/hernad/nomad@v1.6.112/ui/app/serializers/plugin.js (about)

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