db: metadata, collection name and type, fix add()

This commit is contained in:
Djkato 2023-07-17 23:19:22 +02:00
parent 1507b769c4
commit 4e0d491ea0
4 changed files with 35 additions and 7 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@euterpe.js/euterpe", "name": "@euterpe.js/euterpe",
"version": "1.0.0", "version": "1.0.1",
"type": "module", "type": "module",
"description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!", "description": "Fully featured solution for playing music on the web. Support for local library, audio visuals and more!",
"main": "./src/index.js", "main": "./src/index.js",

View file

@ -1,8 +1,7 @@
import * as Player from "@euterpe.js/player" import * as Player from "@euterpe.js/player"
import * as Library from "@euterpe.js/music-library" import * as Library from "@euterpe.js/music-library"
import * as Visualizer from "@euterpe.js/visualizer"
export { Player, Library, Visualizer, Euterpe, EuterpeBuilder } export { Euterpe, EuterpeBuilder }
/** /**
* Avoid Writing directly to any fields in this class! * Avoid Writing directly to any fields in this class!
*/ */

View file

@ -1,6 +1,6 @@
{ {
"name": "@euterpe.js/music-library", "name": "@euterpe.js/music-library",
"version": "1.0.2", "version": "1.0.3",
"type": "module", "type": "module",
"description": "A simple music library, acting as a Local DB as JS Object. Contains everything a person would need to store their music data for website playback.", "description": "A simple music library, acting as a Local DB as JS Object. Contains everything a person would need to store their music data for website playback.",
"main": "./src/index.js", "main": "./src/index.js",

View file

@ -5,7 +5,8 @@ export {
Collection, Collection,
DB, DB,
Artist, Artist,
Platforms Platforms,
CollectionType
} }
type ID = number type ID = number
enum RefTo { enum RefTo {
@ -13,6 +14,13 @@ enum RefTo {
Songs, Songs,
Collections Collections
} }
enum CollectionType {
Album = "Album",
EP = "EP",
Single = "Single",
Playlist = "Playlist",
Release = "Release",
}
enum Platforms { enum Platforms {
Youtube = "Youtube", Youtube = "Youtube",
Linktree = "Linktree", Linktree = "Linktree",
@ -55,7 +63,8 @@ interface SongConstructor {
bpm?: number bpm?: number
key?: string key?: string
fft_data?: number[] fft_data?: number[]
id?: ID id?: ID,
metadata: any
} }
class Song { class Song {
name: string name: string
@ -69,6 +78,7 @@ class Song {
bpm?: number bpm?: number
key?: string key?: string
fft_data?: number[] fft_data?: number[]
metadata: any
/** /**
* The ID is always there, don't worry :) * The ID is always there, don't worry :)
*/ */
@ -86,6 +96,7 @@ class Song {
this.key = data.key this.key = data.key
this.fft_data = data.fft_data this.fft_data = data.fft_data
this.id = data.id this.id = data.id
this.metadata = data.metadata
} }
} }
@ -96,6 +107,7 @@ interface ArtistConstructor {
collections?: Ref[] collections?: Ref[]
links?: [Platforms, URL][] links?: [Platforms, URL][]
id?: ID id?: ID
metadata: any
} }
class Artist { class Artist {
name = "" name = ""
@ -103,6 +115,7 @@ class Artist {
songs: Ref[] songs: Ref[]
collections: Ref[] collections: Ref[]
links?: [Platforms, URL][] links?: [Platforms, URL][]
metadata: any
/** /**
* The ID is always there, don't worry :) * The ID is always there, don't worry :)
*/ */
@ -114,6 +127,7 @@ class Artist {
this.collections = data.collections || [] this.collections = data.collections || []
this.links = data.links this.links = data.links
this.id = data.id this.id = data.id
this.metadata = data.metadata
} }
} }
interface CollectionConstructor { interface CollectionConstructor {
@ -123,13 +137,20 @@ interface CollectionConstructor {
duration: number duration: number
publish_date?: Date publish_date?: Date
id?: ID id?: ID
metadata: any
name?: string
type?: CollectionType
} }
class Collection { class Collection {
name?: string
type?: CollectionType
artists: Ref[] artists: Ref[]
songs: Ref[] songs: Ref[]
cover: URL cover: URL
duration: number duration: number
publish_date?: Date publish_date?: Date
metadata: any
/** /**
* The ID is always there, don't worry :) * The ID is always there, don't worry :)
*/ */
@ -141,6 +162,8 @@ class Collection {
this.duration = data.duration this.duration = data.duration
this.publish_date = data.publish_date this.publish_date = data.publish_date
this.id = data.id this.id = data.id
this.name = data.name
this.metadata = data.metadata
} }
} }
class DB { class DB {
@ -157,7 +180,13 @@ class DB {
* eg. adding song with refrence to artist, adds refrence of song to artist * eg. adding song with refrence to artist, adds refrence of song to artist
* and adds incremental ids * and adds incremental ids
*/ */
for (const input of stuff) { let inputs
if (typeof stuff[Symbol.iterator] != "function") {
inputs = [stuff]
} else {
inputs = stuff
}
for (const input of inputs) {
if (input instanceof Artist) { if (input instanceof Artist) {
const artist = input as Artist const artist = input as Artist
if (!artist.id) artist.id = this.artists.length if (!artist.id) artist.id = this.artists.length