Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
group12.define({
creator: unionOf(member12, { schemaAttribute: inferSchema })
});
const group13 = new Schema('groups');
const user13 = new Schema('users');
const member13 = unionOf({
users: user13,
groups: group13
}, { schemaAttribute: 'type' });
group13.define({
owner: member13,
members: arrayOf(member13),
relationships: valuesOf(member13)
});
// normalize(obj, schema, [options])
const article14 = new Schema('articles');
const user14 = new Schema('users');
article14.define({
author: user14,
contributors: arrayOf(user14),
meta: {
likes: arrayOf({
user: user14
})
}
});
const user11 = new Schema('users');
const group11 = new Schema('groups');
const collaborator11 = {
users: user11,
groups: group11
};
// You can specify the name of the attribute that determines the schema
article11.define({
collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: 'type' })
});
// Or you can specify a function to infer it
function inferSchema11(entity: any) { /* ... */ }
article11.define({
collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: inferSchema })
});
// unionOf(schemaMap, [options])
const group12 = new Schema('groups');
const user12 = new Schema('users');
// a member can be either a user or a group
const member12 = {
users: user12,
groups: group12
};
// You can specify the name of the attribute that determines the schema
group12.define({
owner: unionOf(member12, { schemaAttribute: 'type' })
assets: arrayOf(asset9, { schemaAttribute: 'type' })
});
// Or you can specify a function to infer it
function inferSchema9(entity: any) { /* ... */ }
article9.define({
assets: arrayOf(asset9, { schemaAttribute: inferSchema9 })
});
// valuesOf(schema, [options])
const article10 = new Schema('articles');
const user10 = new Schema('users');
article10.define({
collaboratorsByRole: valuesOf(user10)
});
const article11 = new Schema('articles');
const user11 = new Schema('users');
const group11 = new Schema('groups');
const collaborator11 = {
users: user11,
groups: group11
};
// You can specify the name of the attribute that determines the schema
article11.define({
collaboratorsByRole: valuesOf(collaborator11, { schemaAttribute: 'type' })
});
// Or you can specify a function to infer it
// @flow
import Normalizr from 'normalizr';
(Normalizr.normalize({ foo: '' }, {}): Object);
(Normalizr.normalize([{ foo: '' }], {}): Object);
(Normalizr.valuesOf({}): Normalizr$Schema);
// $ExpectError
(Normalizr.normalize(): Object);
});
const pacContribution = new Schema('pacContributions', {
idAttribute: 'contributorPayee'
});
const businessContribution = new Schema('businessContributions', {
idAttribute: 'contributorPayee'
});
const contributions = ({
owner: campaign,
individual: arrayOf(indivContribution),
business: arrayOf(businessContribution),
pac: arrayOf(pacContribution),
states: arrayOf(stateContribution)
});
campaign.define({
listByName: valuesOf(campaign, {
schemaAttribute: 'candidateName'
})
});
const search = new Schema('searches');
search.define({
list: arrayOf(campaign)
});
// contribution.define({
// owner: campaign
// });
indivContribution.define({
owner: campaign,
listByType: valuesOf(transaction, {
schemaAttribute: 'bookType'
})
});
});
// contribution.define({
// owner: campaign
// });
indivContribution.define({
owner: campaign,
listByType: valuesOf(transaction, {
schemaAttribute: 'bookType'
})
});
donor.define({
owner: transaction,
listByName: valuesOf(transaction, {
schemaAttribute: 'contributorPayee'
}),
relationships: valuesOf(campaign)
});
export const Schemas = {
CAMPAIGN: campaign,
CAMPAIGN_ARRAY: arrayOf(campaign),
TRANSACTION: transaction,
TRANSACTION_ARRAY: arrayOf(transaction),
EXPENDITURE: transaction,
EXPENDITURE_ARRAY: arrayOf(transaction),
DONOR: donor,
DONOR_ARRAY: arrayOf(donor),
LIST: list,
STATE_CONTRIBUTION: stateContribution,
STATE_CONTRIBUTION_ARRAY: arrayOf(stateContribution),
INDIV_CONTRIBUTION: indivContribution,
INDIV_CONTRIBUTION_ARRAY: arrayOf(indivContribution),
BIZ_CONTRIBUTION: businessContribution,
const search = new Schema('searches');
search.define({
list: arrayOf(campaign)
});
// contribution.define({
// owner: campaign
// });
indivContribution.define({
owner: campaign,
listByType: valuesOf(transaction, {
schemaAttribute: 'bookType'
})
});
donor.define({
owner: transaction,
listByName: valuesOf(transaction, {
schemaAttribute: 'contributorPayee'
}),
relationships: valuesOf(campaign)
});
export const Schemas = {
CAMPAIGN: campaign,
CAMPAIGN_ARRAY: arrayOf(campaign),
TRANSACTION: transaction,
TRANSACTION_ARRAY: arrayOf(transaction),
EXPENDITURE: transaction,
EXPENDITURE_ARRAY: arrayOf(transaction),
DONOR: donor,
DONOR_ARRAY: arrayOf(donor),
LIST: list,
STATE_CONTRIBUTION: stateContribution,
STATE_CONTRIBUTION_ARRAY: arrayOf(stateContribution),
define() {
return _valuesOf(this.model.schema ? this.model.schema.model : this.model.define())
}
}
return Normalize(response, _.mapValues(_query, (entity, key) => {
const model = entity._isUnion ?
_unionOf(_.mapValues(entity.models, model => model.schema.model), {schemaAttribute: entity.schemaAttribute})
: entity.model()
switch (entity._modelType) {
case "valuesOf":
return _valuesOf(model)
case "arrayOf":
return _arrayOf(model)
}
if (Array.isArray(response[key])) return _arrayOf(model)
if (hasValuesOf(response[key], model)) return _valuesOf(model)
return model
}))
}
return Normalize(response, _.mapValues(_query, (entity, key) => {
const model = entity._isUnion ?
_unionOf(_.mapValues(entity.models, model => model.schema.model), {schemaAttribute: entity.schemaAttribute})
: entity.model()
switch (entity._modelType) {
case "valuesOf":
return _valuesOf(model)
case "arrayOf":
return _arrayOf(model)
}
if (Array.isArray(response[key])) return _arrayOf(model)
if (hasValuesOf(response[key], model)) return _valuesOf(model)
return model
}))
}