2016-08-10 21:36:11 +02:00
|
|
|
/**
|
|
|
|
* This file defines API related models.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// NPM imports
|
2016-08-05 00:00:25 +02:00
|
|
|
import { Schema, arrayOf } from "normalizr";
|
|
|
|
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
// Define normalizr schemas for major entities returned by the API
|
|
|
|
export const artist = new Schema("artist"); /** Artist schema */
|
|
|
|
export const album = new Schema("album"); /** Album schema */
|
|
|
|
export const song = new Schema("song"); /** Song schema */
|
|
|
|
|
|
|
|
// Explicit relations between them
|
|
|
|
artist.define({ // Artist has albums and songs (tracks)
|
2016-08-05 00:00:25 +02:00
|
|
|
albums: arrayOf(album),
|
2016-08-10 23:50:23 +02:00
|
|
|
songs: arrayOf(song),
|
2016-08-05 00:00:25 +02:00
|
|
|
});
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
album.define({ // Album has artist, tracks and tags
|
2016-08-05 00:00:25 +02:00
|
|
|
artist: artist,
|
2016-08-10 23:50:23 +02:00
|
|
|
tracks: arrayOf(song),
|
2016-08-05 00:00:25 +02:00
|
|
|
});
|
|
|
|
|
2016-08-10 21:36:11 +02:00
|
|
|
song.define({ // Track has artist and album
|
2016-08-05 00:00:25 +02:00
|
|
|
artist: artist,
|
2016-08-10 23:50:23 +02:00
|
|
|
album: album,
|
2016-08-05 00:00:25 +02:00
|
|
|
});
|