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

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