1use serde::{Deserialize, Deserializer, Serialize, Serializer};
2use uuid::Uuid;
3
4#[derive(Debug)]
5pub struct UuidRow(pub Uuid);
6
7impl<'de> Deserialize<'de> for UuidRow {
8 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
9 where
10 D: Deserializer<'de>,
11 {
12 let inner = Vec::deserialize(deserializer)?;
13 Ok(UuidRow(Uuid::from_slice(&inner).unwrap()))
14 }
15}
16
17impl Serialize for UuidRow {
18 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
19 where
20 S: Serializer,
21 {
22 self.0.serialize(serializer)
23 }
24}
25
26#[derive(Debug, Serialize, Deserialize)]
27pub struct AlbumRow {
28 pub album_id: UuidRow,
29 pub title: String,
30 pub edition: Option<String>,
31 pub catalog: String,
32 pub artist: String,
33 pub release_date: String,
34 #[serde(rename(serialize = "type"))]
35 pub album_type: String,
36}
37
38#[derive(Debug, Serialize, Deserialize)]
39pub struct DiscRow {
40 pub album_id: UuidRow,
41 pub disc_id: u8,
42 pub title: String,
43 pub artist: String,
44 pub catalog: String,
45 #[serde(rename(serialize = "type"))]
46 pub disc_type: String,
47}
48
49#[derive(Debug, Serialize, Deserialize)]
50pub struct TrackRow {
51 pub album_id: UuidRow,
52 pub disc_id: u8,
53 pub track_id: u8,
54 pub title: String,
55 pub artist: String,
56 #[serde(rename(serialize = "type"))]
57 pub track_type: String,
58}
59
60#[derive(Debug, Serialize, Deserialize)]
61pub struct TagRow {
62 pub album_id: UuidRow,
63 pub disc_id: Option<u8>,
64 pub track_id: Option<u8>,
65 pub name: String,
66 #[serde(rename(serialize = "type"))]
67 pub tag_type: String,
68}
69
70#[cfg(target_arch = "wasm32")]
71pub mod wasm {
72 use wasm_bindgen::prelude::*;
73
74 #[wasm_bindgen(typescript_custom_section)]
75 const DB_TYPES: &'static str = r#"
76type TrackType = "normal" | "instrumental" | "absolute" | "drama" | "radio" | "vocal";
77
78interface AlbumRow {
79 album_id: string;
80 title: string;
81 edition?: string;
82 catalog: string;
83 artist: string;
84 release_date: string;
85 type: TrackType;
86}
87
88type AlbumRowArray = AlbumRow[];
89
90interface DiscRow {
91 album_id: string;
92 disc_id: number;
93 title: string;
94 artist: string;
95 catalog: string;
96 type: TrackType;
97}
98
99type DiscRowArray = DiscRow[];
100
101interface TrackRow {
102 album_id: string;
103 disc_id: number;
104 track_id: number;
105 title: string;
106 artist: string;
107 type: TrackType;
108}
109
110type TrackRowArray = TrackRow[];
111"#;
112
113 #[wasm_bindgen]
114 extern "C" {
115 #[wasm_bindgen(typescript_type = "AlbumRow | undefined")]
116 pub type IAlbumRow;
117
118 #[wasm_bindgen(typescript_type = "AlbumRowArray")]
119 pub type IAlbumRowArray;
120
121 #[wasm_bindgen(typescript_type = "DiscRow | undefined")]
122 pub type IDiscRow;
123
124 #[wasm_bindgen(typescript_type = "DiscRowArray")]
125 pub type IDiscRowArray;
126
127 #[wasm_bindgen(typescript_type = "TrackRow | undefined")]
128 pub type ITrackRow;
129
130 #[wasm_bindgen(typescript_type = "TrackRowArray")]
131 pub type ITrackRowArray;
132 }
133}