Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import _ from 'lodash';
import { Deserializer } from 'jsonapi-serializer';
import * as logger from '../services/logger';
const deserializer = new Deserializer({
keyForAttribute: 'camelCase'
});
// jsonapi-serializer seems to ignore non-included relationships no matter what its docs say
// therefore, support an option to use our own deserialization when specified(default still jsonapi-serializer)
function deserializePlainSingle(json) {
const relationships = json.relationships;
const relationshipKeys = _.keys(relationships);
const relationshipIds = {};
_.forEach(relationshipKeys, key => {
relationshipIds[key] = _.get(relationships[key], 'data.id');
})
return {
...relationshipIds,
import { Serializer, Deserializer, Error } from "jsonapi-serializer";
declare let firstName: string;
declare let lastName: string;
const UserSerializer = new Serializer("users", {
id: "id",
attributes: ["firstName", "lastName"],
keyForAttribute: "camelCase",
pluralizeType: false
});
const users = UserSerializer.serialize({ firstName, lastName });
const UserDeserializer = new Deserializer({
id: "id",
keyForAttribute: "camelCase",
pluralizeType: false,
typeAsAttribute: true
});
UserDeserializer.deserialize(users);
new Error({
code: "_code",
detail: "_detail",
id: "_id",
links: {
about: "_about"
},
source: {
const JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
module.exports = new JSONAPIDeserializer({
keyForAttribute: 'camelCase',
});
.then(data => (canDeserialize(data) ? new JSONAPIDeserializer(deserializeOptions).deserialize(data) : data))
.catch(err => {
const JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
module.exports = new JSONAPIDeserializer({
keyForAttribute: 'camelCase',
projects: {
valueForRelationship: (relationship, included) => included,
},
});
.then(response => new Deserializer({
keyForAttribute: 'underscore_case'
}).deserialize(response, (err, faqs) => sortBy(faqs, 'order')));
}
onSuccess: (response) => {
new Deserializer({
keyForAttribute: 'underscore_case'
}).deserialize(response, (err, tools) => {
resolve(sortBy(tools, 'name'));
});
},
onError: (error) => {
const JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
module.exports = new JSONAPIDeserializer({
keyForAttribute: 'camelCase',
environments: {
valueForRelationship: (relationship, included) => included,
},
renderings: {
valueForRelationship: (relationship, included) => included,
},
});
onSuccess: (response) => {
new Deserializer({ keyForAttribute: 'underscore_case' }).deserialize(response, (err, pages) => {
resolve(sortBy(pages, 'name'));
});
},
onError: (error) => {
onSuccess: (response) => {
new Deserializer({
keyForAttribute: 'underscore_case'
}).deserialize(response, (err, tool) => {
resolve(tool);
});
},
onError: (error) => {