Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// You can specify the name of the attribute that determines the schema
group12.define({
owner: unionOf(member12, { schemaAttribute: 'type' })
});
// Or you can specify a function to infer it
function inferSchema(entity: any) { /* ... */ }
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({
// 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' })
});
// Or you can specify a function to infer it
function inferSchema(entity: any) { /* ... */ }
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)
});
});
// 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' })
});
// Or you can specify a function to infer it
function inferSchema(entity: any) { /* ... */ }
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' });
_.forEach(models, (modelData: ModelDataType | UnionDataType, modelName: string) => {
if (modelData._unionDataType) {
/* filter out all non-existing models and warn about them */
const existingModels = _.filter(modelData.models, model => {
if (models[model]) return true
// eslint-disable-next-line no-console
console.warn(`Model "${model}" on union ${modelName} points to an unknown model`)
})
/* create a normalizr union */
modelData.normalizrSchema = unionOf(_.mapValues(_.mapKeys(existingModels, model => model), model =>
models[model].normalizrSchema
), {schemaAttribute: modelData.schemaAttribute}
)
}
})
}
union.define = () => unionOf(_.mapValues(models, model => model.schema.model), attribute)
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
}))
}