How to use @ember-data/adapter - 10 common examples

To help you get started, we’ve selected a few @ember-data/adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hashicorp / vault / ui / app / routes / vault / cluster / access / identity / aliases / show.js View on Github external
model(params) {
    let { section } = params;
    let itemType = this.modelFor('vault.cluster.access.identity') + '-alias';
    let tabs = TABS[itemType];
    let modelType = `identity/${itemType}`;
    if (!tabs.includes(section)) {
      const error = new AdapterError();
      set(error, 'httpStatus', 404);
      throw error;
    }
    // TODO peekRecord here to see if we have the record already
    return hash({
      model: this.store.findRecord(modelType, params.item_alias_id),
      section,
    });
  },
github hashicorp / vault / ui / app / routes / vault / cluster / access / identity / show.js View on Github external
model(params) {
    let { section } = params;
    let itemType = this.modelFor('vault.cluster.access.identity');
    let tabs = TABS[itemType];
    let modelType = `identity/${itemType}`;
    if (!tabs.includes(section)) {
      const error = new AdapterError();
      set(error, 'httpStatus', 404);
      throw error;
    }

    // if the record is in the store use that
    let model = this.store.peekRecord(modelType, params.item_id);

    // if we don't have creationTime, we only have a partial model so reload
    if (model && !model.get('creationTime')) {
      model = model.reload();
    }

    // if there's no model, we need to fetch it
    if (!model) {
      model = this.store.findRecord(modelType, params.item_id);
    }
github puzzle / cryptopus / frontend / app / adapters / application.js View on Github external
import JSONAPIAdapter from "@ember-data/adapter/json-api";
import { computed } from "@ember/object";
import { pluralize } from "ember-inflector";
import { underscore } from "@ember/string";
import ENV from "../config/environment";

export default JSONAPIAdapter.extend({
  namespace: "api",

  pathForType(type) {
    return pluralize(underscore(type));
  },

  headers: computed(function () {
    /* eslint-disable no-undef  */
    return {
      "X-CSRF-Token": ENV.CSRFToken,
      "content-type": "application/json"
    };
    /* eslint-enable no-undef  */
  })
});
github NREL / api-umbrella / src / api-umbrella / admin-ui / app / adapters / application.js View on Github external
import RESTAdapter from '@ember-data/adapter/rest';
import flatten from 'lodash-es/flatten';
import isArray from 'lodash-es/isArray';
import isPlainObject from 'lodash-es/isPlainObject';
import isString from 'lodash-es/isString';

export default RESTAdapter.extend({
  // Build the URL using the customizable "urlRoot" attribute that can be set
  // on the model class.
  buildURL(modelName, id, snapshot) {
    if(snapshot && snapshot.type && snapshot.type.urlRoot) {
      let url = snapshot.type.urlRoot;
      if(id) {
        url += '/' + encodeURIComponent(id);
      }

      return url;
    } else {
      return this._super(...arguments);
    }
  },

  // Ember data requires that errors from the API be returned as an array. This
github jelhan / croodle / app / adapters / application.js View on Github external
import RESTAdapter from '@ember-data/adapter/rest';
import { inject as service } from '@ember/service';
import AdapterFetch from 'ember-fetch/mixins/adapter-fetch';

export default RESTAdapter.extend(AdapterFetch, {
  encryption: service(),

  // set namespace to api.php in same subdirectory
  namespace:
    window.location.pathname
    // remove index.html if it's there
    .replace(/index.html$/, '')
    // remove tests prefix which is added by testem (starting with a number)
    .replace(/\/\d+\/tests/, '')
    // remove tests prefix which is added by tests run in browser
    .replace(/tests/, '')
    // remove leading and trailing slash
    .replace(/\/$/, '')
    // add api.php
    .concat('/api/index.php')
    // remove leading slash
github emberjs / data / packages / adapter / addon / rest.js View on Github external
export default RESTAdapter.extend({
    headers: computed(function() {
      return {
        'API_KEY': get(document.cookie.match(/apiKey\=([^;]*)/), '1'),
        'ANOTHER_HEADER': 'Some header value'
      };
    }).volatile()
  });

@class RESTAdapter @constructor @extends Adapter @uses BuildURLMixin */ const RESTAdapter = Adapter.extend(BuildURLMixin, { defaultSerializer: '-rest',

_defaultContentType: 'application/json; charset=utf-8',

fastboot: computed({ // Avoid computed property override deprecation in fastboot as suggested by: // https://deprecations.emberjs.com/v3.x/#toc_computed-property-override get() { if (this._fastboot) { return this._fastboot; } return (this._fastboot = getOwner(this).lookup('service:fastboot')); }, set(key, value) { return (this._fastboot = value); },

github hashicorp / vault / ui / app / routes / vault / cluster / access / identity.js View on Github external
model(params) {
    let model = MODEL_FROM_PARAM[params.item_type];
    if (!model) {
      const error = new AdapterError();
      set(error, 'httpStatus', 404);
      throw error;
    }
    return model;
  },
});
github hashicorp / vault / ui / app / routes / vault / cluster / access / method / section.js View on Github external
model(params) {
    const { section_name: section } = params;
    if (section !== 'configuration') {
      const error = new AdapterError();
      set(error, 'httpStatus', 404);
      throw error;
    }
    let backend = this.modelFor('vault.cluster.access.method');
    this.wizard.transitionFeatureMachine(this.wizard.featureState, 'DETAILS', backend.type);
    return backend;
  },
github hashicorp / vault / ui / app / routes / vault / cluster / access / method.js View on Github external
return this.store.findAll('auth-method').then(modelArray => {
      const model = modelArray.findBy('id', path);
      if (!model) {
        const error = new AdapterError();
        set(error, 'httpStatus', 404);
        throw error;
      }
      return this.pathHelp.getPaths(model.apiPath, path).then(paths => {
        model.set('paths', paths);
        return model;
      });
    });
  },
github emberjs / data / packages / adapter / addon / rest.js View on Github external
switch (status) {
      case 401:
        return new UnauthorizedError(errors, detailedMessage);
      case 403:
        return new ForbiddenError(errors, detailedMessage);
      case 404:
        return new NotFoundError(errors, detailedMessage);
      case 409:
        return new ConflictError(errors, detailedMessage);
      default:
        if (status >= 500) {
          return new ServerError(errors, detailedMessage);
        }
    }

    return new AdapterError(errors, detailedMessage);
  },