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

     1  import classic from 'ember-classic-decorator';
     2  import ApplicationSerializer from './application';
     3  
     4  @classic
     5  export default class VariableSerializer extends ApplicationSerializer {
     6    separateNanos = ['CreateTime', 'ModifyTime'];
     7  
     8    normalize(typeHash, hash) {
     9      // ID is a composite of both the job ID and the namespace the job is in
    10      hash.ID = `${hash.Path}@${hash.Namespace || 'default'}`;
    11      return super.normalize(typeHash, hash);
    12    }
    13  
    14    // Transform API's Items object into an array of a KeyValue objects
    15    normalizeFindRecordResponse(store, typeClass, hash, id, ...args) {
    16      if (!hash.Items) {
    17        hash.Items = { '': '' };
    18      }
    19      hash.KeyValues = Object.entries(hash.Items).map(([key, value]) => {
    20        return {
    21          key,
    22          value,
    23        };
    24      });
    25      delete hash.Items;
    26      return super.normalizeFindRecordResponse(
    27        store,
    28        typeClass,
    29        hash,
    30        id,
    31        ...args
    32      );
    33    }
    34  
    35    // Transform our KeyValues array into an Items object
    36    serialize(snapshot, options) {
    37      const json = super.serialize(snapshot, options);
    38      json.ID = json.Path;
    39      json.Items = json.KeyValues.reduce((acc, { key, value }) => {
    40        acc[key] = value;
    41        return acc;
    42      }, {});
    43      delete json.KeyValues;
    44      delete json.ModifyTime;
    45      delete json.CreateTime;
    46      return json;
    47    }
    48  }