Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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]);
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);
},
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);
}
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);
}
});
import JSONSerializer from '@ember-data/serializer/json';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
export default JSONSerializer.extend(EmbeddedRecordsMixin, {});
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'
);
import RESTSerializer from '@ember-data/serializer/rest';
export default RESTSerializer.extend({
});
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) {
import RESTSerializer from '@ember-data/serializer/rest';
import { decamelize } from '@ember/string';
export default RESTSerializer.extend({
keyForAttribute: function(attr) {
return decamelize(attr);
},
});