{"size": 1131, "ext": "js", "max_stars_repo_path": "app/adapters/bucket-type.js", "max_stars_repo_name": "basho-labs/riak-explorer-gui", "max_stars_repo_stars_event_min_datetime": "2015-10-09T01:46:50.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-21T08:15:58.000Z", "max_issues_repo_path": "app/adapters/bucket-type.js", "max_issues_repo_name": "basho-labs/riak-explorer-gui", "max_issues_repo_issues_event_min_datetime": "2015-10-21T20:20:42.000Z", "max_issues_repo_issues_event_max_datetime": "2019-01-03T13:59:30.000Z", "max_forks_repo_path": "app/adapters/bucket-type.js", "max_forks_repo_name": "basho-labs/riak-explorer-gui", "max_forks_repo_forks_event_min_datetime": "2016-01-05T14:53:35.000Z", "max_forks_repo_forks_event_max_datetime": "2017-10-20T11:43:16.000Z"}
{"max_stars_count": 17, "max_issues_count": 87, "max_forks_count": 4, "avg_line_length": 29.0, "max_line_length": 87, "alphanum_fraction": 0.6666666667}
import ApplicationAdapter from './application';
import Ember from 'ember';

/**
 * @class BucketTypeAdapter
 * @namespace Adapters
 * @extends ApplicationAdapter
 */
export default ApplicationAdapter.extend({
  /**
   * Overrides application adapter query method.
   * Used to read bucket types from a given cluster.
   *
   * @method query
   * @return {Object} Promise object of the requested bucket type
   */
  query(store, type, query) {
    let url = `explore/clusters/${query.clusterName}/bucket_types`;

    let promise = this.ajax(url, 'GET').then(function(data) {
      // Remove any time series table bucket types, they are added by the TableAdapter.
      // Time series tables are identified by the "ddl" property.
      data.bucket_types = data.bucket_types.filter(function(bt) {
        return Ember.isNone(bt.props.ddl);
      });

      data.bucket_types.forEach(function(bucketType) {
        // Use compound key strategy to form name/id
        bucketType.name = bucketType.id;
        bucketType.id = `${query.clusterName}/${bucketType.name}`;
      });

      return data;
    });

    return promise;
  }
});
