Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const photoSize = new schema.Entity('photoCachedSizes', {
location: fileLocations,
}, {
idAttribute: v => v.location.local_id,
})
// TODO: there should be processStrategy
const photoCachedSize = new schema.Entity('photoSizes', {}, {
idAttribute: v => v.location.local_id,
})
const metaPhotoSize = {
photoSize,
photoCachedSize,
}
export const document = new schema.Entity('documents', {
thumb: new schema.Union(metaPhotoSize, '_'),
}, {
processStrategy: processDoc,
idAttribute: pipe(prop('id'), e => +e),
})
const photo = new schema.Entity('photos', {
sizes: new schema.Array(metaPhotoSize, '_'),
}, {
processStrategy: processPhoto,
idAttribute: pipe(prop('id'), e => +e),
})
const webpage = new schema.Object({
document,
photo,
})
Manifest: 'manifest',
Canvas: 'canvas',
AnnotationCollection: 'annotationCollection',
AnnotationPage: 'annotationPage',
Annotation: 'annotation',
Range: 'range',
// Content resources.
Application: 'contentResource',
Dataset: 'contentResource',
Image: 'contentResource',
Sound: 'contentResource',
Text: 'contentResource',
Video: 'contentResource',
TextualBody: 'contentResource',
};
const resource = new schema.Union(
{
collection,
manifest,
canvas,
annotationCollection,
annotationPage,
annotation,
range,
contentResource,
service,
},
(entity: any): DereferencableResourceTypes => {
if (RESOURCE_TYPE_MAP[entity.type]) {
return RESOURCE_TYPE_MAP[entity.type];
}
if (entity.profile) {
describe('when a schema', () => {
const postSchema = new schema.Entity('posts');
const userSchema = new schema.Entity('users');
postSchema.define({
user: userSchema,
});
const unionItemSchema = new schema.Union({
post: postSchema,
user: userSchema,
}, 'type');
const response = {
unionItems: [
{
id: 1,
title: 'Some Post',
user: {
id: 1,
name: 'Dan',
},
type: 'post',
},
{
describe('when a schema', () => {
const postSchema = new Schema.Entity('posts');
const userSchema = new Schema.Entity('users');
postSchema.define({
user: userSchema,
});
const unionItemSchema = new Schema.Union({
post: postSchema,
user: userSchema,
}, 'type');
const response = {
unionItems: [
{
id: 1,
title: 'Some Post',
user: {
id: 1,
name: 'Dan',
},
type: 'post',
},
{
describe('when defining a relationship', () => {
const groupSchema = new Schema.Entity('groups');
const userSchema = new Schema.Entity('users');
const member = new Schema.Union({
user: userSchema,
group: groupSchema,
}, 'type');
groupSchema.define({
owner: member,
});
const response = {
groups: [
{
id: 1,
owner: {
id: 1,
type: 'user',
name: 'Dan',
union (callback: Normalizr.SchemaFunction): Normalizr.Union {
return new Normalizr.Union(this.schemas, callback)
}
import { schema } from "normalizr";
import { postType } from "./postTypes";
import { taxonomy } from "./taxonomies";
import { author } from "./authors";
import { attachment } from "./attachments";
export const entity = new schema.Union(
{
postType,
taxonomy,
author,
attachment
},
val => {
if (val.taxonomy) return "taxonomy";
else if (val.media_type) return "attachment";
else if (val.name) return "author";
return "postType";
}
);
export const list = new schema.Array(entity);
const textMedia = (
keys: string[],
entity = new schema.Entity('media', {}, mediaSettings),
) =>
zipObj(keys, map(() => entity, keys))
export const mediaIndexation = [
'media',
'documents',
'photos',
'photoSizes',
'photoCachedSizes',
]
export const media = new schema.Union({
...textMedia([
'messageMediaUnsupported',
'messageMediaContact',
'messageMediaEmpty',
'messageMediaVenue',
'messageMediaGeo',
]),
messageMediaDocument,
messageMediaPhoto,
messageMediaGame,
messageMediaInvoice,
messageMediaWebPage,
}, '_')
},
entity => {
switch (entity.type) {
case 'Collection':
return 'collection';
case 'Manifest':
return 'manifest';
case 'AnnotationCollection':
return 'annotationCollection';
default:
return 'contentResource';
}
}
);
const canvasOrReference = new schema.Union(
{
selector,
canvasReference,
canvas,
},
entity => {
if (entity && entity.id && entity.id.indexOf('#') !== -1) {
return 'selector';
}
if (entity.type === 'SpecificResource') {
return 'canvasReference';
}
return 'canvas';
}
);
TextualBody: 'contentResource',
};
const annotationBody = new schema.Union(
{
contentResource,
choice,
},
(input: any): AnnotationBodyTypes => {
if (annotationBodyMappings[input.type]) {
return annotationBodyMappings[input.type];
}
return 'contentResource';
}
);
const rangeItem = new schema.Union(
{
canvas,
selector,
range,
canvasReference,
},
input => {
if (input && input.id && input.id.indexOf('#') !== -1) {
return 'selector';
}
switch (input.type) {
case 'Canvas':
return 'canvas';
case 'Range':
return 'range';