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

To help you get started, we’ve selected a few @ember-data/serializer 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 / serializers / database / connection.js View on Github external
import RESTSerializer from '@ember-data/serializer/rest';

export default RESTSerializer.extend({
  primaryKey: 'name',

  serializeAttribute(snapshot, json, key, attributes) {
    // Don't send values that are undefined
    if (
      undefined !== snapshot.attr(key) &&
      (snapshot.record.get('isNew') || snapshot.changedAttributes()[key])
    ) {
      this._super(snapshot, json, key, attributes);
    }
  },

  normalizeSecrets(payload) {
    if (payload.data.keys && Array.isArray(payload.data.keys)) {
      const connections = payload.data.keys.map(secret => ({ name: secret, backend: payload.backend }));
      return connections;
github jelhan / croodle / app / serializers / application.js View on Github external
import { inject as service } from '@ember/service';

/*
 * extends DS.RESTSerializer to implement encryption
 *
 * By default every attribute hash is encrypted using SJCL.
 * This is configurable by options parameter of DS.attr().
 *
 * Options:
 * - encrypted (boolean)
 *   If false the attribute won't be encrypted.
 * - includePlainOnCreate (string)
 *   If set the attribute will be included plain (not encrypted) when
 *   recorde is created. Value is the attributes name used.
 */
export default RESTSerializer.extend({
  isNewSerializerAPI: true,

  encryption: service(),

  /*
   * implement decryption
   */
  normalize(modelClass, resourceHash, prop) {

    // run before serialization of attribute hash
    modelClass.eachAttribute(function(key, attributes) {
      if (
        attributes.options.encrypted !== false
      ) {
        if (typeof resourceHash[key] !== 'undefined' && resourceHash[key] !== null) {
          resourceHash[key] = this.encryption.decrypt(resourceHash[key]);
github NREL / api-umbrella / src / api-umbrella / admin-ui / app / serializers / application.js View on Github external
import JSONSerializer from '@ember-data/serializer/json';
import { underscore } from '@ember/string';

export default JSONSerializer.extend({
  // Use camel-cased attribute names in the JS models, but underscore the
  // attribute names for any server-side communication.
  keyForAttribute(attr) {
    return underscore(attr);
  },

  // For single records, look for the data under the customizable
  // "singlePayloadKey" attribute name on the response.
  normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
    let key = primaryModelClass.singlePayloadKey;
    if(key) {
      payload = payload[key];
    }

    return this._super(store, primaryModelClass, payload, id, requestType);
  },
github emberjs / data / packages / serializer / addon / json-api.js View on Github external
extractRelationship(relationshipHash) {
      let normalizedRelationship = this._super(...arguments);

      // Customize relationship meta
      normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);

      return normalizedRelationship;
    }
  });

@since 1.13.0 @class JSONAPISerializer @extends JSONSerializer / const JSONAPISerializer = JSONSerializer.extend({ /* @method _normalizeDocumentHelper @param {Object} documentHash @return {Object} @private */ _normalizeDocumentHelper(documentHash) { if (typeOf(documentHash.data) === 'object') { documentHash.data = this._normalizeResourceHelper(documentHash.data); } else if (Array.isArray(documentHash.data)) { let ret = new Array(documentHash.data.length);

  for (let i = 0; i < documentHash.data.length; i++) {
    let data = documentHash.data[i];
    ret[i] = this._normalizeResourceHelper(data);
  }
github puzzle / cryptopus / frontend / app / serializers / application.js View on Github external
import JSONAPISerializer from "@ember-data/serializer/json-api";
import { underscore } from "@ember/string";

export default JSONAPISerializer.extend({
  keyForAttribute(attr) {
    return underscore(attr);
  },

  keyForRelationship(key) {
    return underscore(key);
  },

  serializeBelongsTo(snapshot, json, relationship) {
    // do not serialize the attribute!
    if (relationship.options && relationship.options.readOnly) {
      return;
    }
    this._super(...arguments);
  }
});
github emberjs / data / packages / unpublished-fastboot-test-app / app / serializers / application.ts View on Github external
import JSONSerializer from '@ember-data/serializer/json';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default JSONSerializer.extend(EmbeddedRecordsMixin, {});
github hashicorp / vault / ui / app / serializers / cluster.js View on Github external
import RESTSerializer, { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
import { assign } from '@ember/polyfills';
import { decamelize } from '@ember/string';

export default RESTSerializer.extend(EmbeddedRecordsMixin, {
  keyForAttribute: function(attr) {
    return decamelize(attr);
  },

  attrs: {
    nodes: { embedded: 'always' },
  },

  pushPayload(store, payload) {
    const transformedPayload = this.normalizeResponse(
      store,
      store.modelFor('cluster'),
      payload,
      null,
      'findAll'
    );
github jelhan / croodle / app / serializers / answer.js View on Github external
import RESTSerializer from '@ember-data/serializer/rest';

export default RESTSerializer.extend({
});
github hashicorp / vault / ui / app / serializers / pki-certificate.js View on Github external
import RESTSerializer from '@ember-data/serializer/rest';
import { isNone, isBlank } from '@ember/utils';
import { assign } from '@ember/polyfills';
import { decamelize } from '@ember/string';

export default RESTSerializer.extend({
  keyForAttribute: function(attr) {
    return decamelize(attr);
  },

  pushPayload(store, payload) {
    const transformedPayload = this.normalizeResponse(
      store,
      store.modelFor(payload.modelName),
      payload,
      payload.id,
      'findRecord'
    );
    return store.push(transformedPayload);
  },

  normalizeItems(payload) {
github hashicorp / vault / ui / app / serializers / replication-attributes.js View on Github external
import RESTSerializer from '@ember-data/serializer/rest';
import { decamelize } from '@ember/string';

export default RESTSerializer.extend({
  keyForAttribute: function(attr) {
    return decamelize(attr);
  },
});

@ember-data/serializer

Provides Legacy JSON, JSON:API and REST Implementations of the Serializer Interface for use with @ember-data/store

MIT
Latest version published 1 month ago

Package Health Score

89 / 100
Full package analysis