Skip to main content

maestro_midds_schema/
lib.rs

1//! MIDDS (Musical Industry Digital Distribution Standard) GraphQL types for the Maestro blockchain indexer.
2//!
3//! This crate provides GraphQL schema types for the Allfeat MIDDS pallets,
4//! which handle musical works, recordings, and releases.
5//!
6//! # Example
7//!
8//! ```rust
9//! use maestro_midds_schema::{MusicalWork, Recording, Release, PartyId};
10//! ```
11
12use chrono::{DateTime, Utc};
13use serde::{Deserialize, Serialize};
14
15pub use maestro_graphql_schema::PageInfo;
16
17// =============================================================================
18// Party Identifier Types
19// =============================================================================
20
21/// A party identifier (IPI, ISNI, or both).
22#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct PartyId {
25    /// IPI (Interested Party Information) number, if available.
26    pub ipi: Option<i64>,
27    /// ISNI (International Standard Name Identifier), if available.
28    pub isni: Option<String>,
29}
30
31/// A creator of a musical work.
32#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
33#[serde(rename_all = "camelCase")]
34pub struct Creator {
35    /// The party identifier.
36    pub party_id: PartyId,
37    /// The role of the creator (Author, Composer, Arranger, Adapter, Publisher).
38    pub role: String,
39}
40
41/// A date (year, month, day).
42#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct Date {
45    /// Year component.
46    pub year: i32,
47    /// Month component (1-12).
48    pub month: i32,
49    /// Day component (1-31).
50    pub day: i32,
51}
52
53// =============================================================================
54// Musical Work Types
55// =============================================================================
56
57/// A musical work (composition) registered on-chain.
58#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct MusicalWork {
61    /// Unique MIDDS identifier.
62    pub id: i64,
63    /// Provider account (hex encoded with 0x prefix).
64    pub provider: String,
65    /// Blake2-256 hash of the SCALE-encoded data (hex encoded with 0x prefix).
66    pub hash: String,
67    /// Cost deposited by the provider.
68    pub data_cost: String,
69    /// Block number when registered.
70    pub registered_at_block: i64,
71    /// Timestamp when registered.
72    pub registered_at_timestamp: Option<DateTime<Utc>>,
73    /// International Standard Musical Work Code.
74    pub iswc: String,
75    /// Title of the work.
76    pub title: String,
77    /// Year the work was created.
78    pub creation_year: Option<i32>,
79    /// Whether the work is instrumental (no lyrics).
80    pub instrumental: Option<bool>,
81    /// Language of the lyrics.
82    pub language: Option<String>,
83    /// Tempo in beats per minute.
84    pub bpm: Option<i32>,
85    /// Musical key.
86    pub key: Option<String>,
87    /// Type of work (Original, Medley, Mashup, Adaptation).
88    pub work_type: Option<String>,
89    /// List of creators with their roles.
90    pub creators: Vec<Creator>,
91}
92
93/// A single musical work in a paginated list.
94#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
95#[serde(rename_all = "camelCase")]
96pub struct MusicalWorkEdge {
97    /// The musical work.
98    pub node: MusicalWork,
99    /// Cursor for pagination.
100    pub cursor: String,
101}
102
103/// Paginated list of musical works.
104#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
105#[serde(rename_all = "camelCase")]
106pub struct MusicalWorkConnection {
107    /// List of musical work edges.
108    pub edges: Vec<MusicalWorkEdge>,
109    /// Pagination information.
110    pub page_info: PageInfo,
111    /// Total count of musical works (if available).
112    pub total_count: Option<i64>,
113}
114
115// =============================================================================
116// Recording Types
117// =============================================================================
118
119/// A recording registered on-chain.
120#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct Recording {
123    /// Unique MIDDS identifier.
124    pub id: i64,
125    /// Provider account (hex encoded with 0x prefix).
126    pub provider: String,
127    /// Blake2-256 hash of the SCALE-encoded data (hex encoded with 0x prefix).
128    pub hash: String,
129    /// Cost deposited by the provider.
130    pub data_cost: String,
131    /// Block number when registered.
132    pub registered_at_block: i64,
133    /// Timestamp when registered.
134    pub registered_at_timestamp: Option<DateTime<Utc>>,
135    /// International Standard Recording Code.
136    pub isrc: String,
137    /// Reference to the musical work this is a recording of.
138    pub musical_work_id: i64,
139    /// Main artist.
140    pub artist: PartyId,
141    /// Title of the recording.
142    pub title: String,
143    /// Year the recording was made.
144    pub recording_year: Option<i32>,
145    /// Duration in seconds.
146    pub duration: Option<i32>,
147    /// Tempo in beats per minute.
148    pub bpm: Option<i32>,
149    /// Musical key.
150    pub key: Option<String>,
151    /// Version type (Original, Live, Remix, etc.).
152    pub version: Option<String>,
153    /// Genre names.
154    pub genres: Vec<String>,
155    /// Producer party IDs.
156    pub producers: Vec<PartyId>,
157    /// Performer party IDs.
158    pub performers: Vec<PartyId>,
159}
160
161/// A single recording in a paginated list.
162#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
163#[serde(rename_all = "camelCase")]
164pub struct RecordingEdge {
165    /// The recording.
166    pub node: Recording,
167    /// Cursor for pagination.
168    pub cursor: String,
169}
170
171/// Paginated list of recordings.
172#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
173#[serde(rename_all = "camelCase")]
174pub struct RecordingConnection {
175    /// List of recording edges.
176    pub edges: Vec<RecordingEdge>,
177    /// Pagination information.
178    pub page_info: PageInfo,
179    /// Total count of recordings (if available).
180    pub total_count: Option<i64>,
181}
182
183// =============================================================================
184// Release Types
185// =============================================================================
186
187/// A release (album/single) registered on-chain.
188#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
189#[serde(rename_all = "camelCase")]
190pub struct Release {
191    /// Unique MIDDS identifier.
192    pub id: i64,
193    /// Provider account (hex encoded with 0x prefix).
194    pub provider: String,
195    /// Blake2-256 hash of the SCALE-encoded data (hex encoded with 0x prefix).
196    pub hash: String,
197    /// Cost deposited by the provider.
198    pub data_cost: String,
199    /// Block number when registered.
200    pub registered_at_block: i64,
201    /// Timestamp when registered.
202    pub registered_at_timestamp: Option<DateTime<Utc>>,
203    /// European Article Number / Universal Product Code.
204    pub ean_upc: String,
205    /// Creator of the release.
206    pub creator: PartyId,
207    /// Title of the release.
208    pub title: String,
209    /// Type of release (Lp, Ep, Single, etc.).
210    pub release_type: String,
211    /// Format (CD, Vinyl, Digital, etc.).
212    pub format: String,
213    /// Packaging type.
214    pub packaging: String,
215    /// Release status.
216    pub status: String,
217    /// Release date.
218    pub date: Date,
219    /// Country of release (ISO 3166-1 alpha-2).
220    pub country: String,
221    /// IDs of recordings in this release.
222    pub recording_ids: Vec<i64>,
223    /// Name of the distributor.
224    pub distributor_name: String,
225    /// Name of the manufacturer.
226    pub manufacturer_name: String,
227}
228
229/// A single release in a paginated list.
230#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
231#[serde(rename_all = "camelCase")]
232pub struct ReleaseEdge {
233    /// The release.
234    pub node: Release,
235    /// Cursor for pagination.
236    pub cursor: String,
237}
238
239/// Paginated list of releases.
240#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
241#[serde(rename_all = "camelCase")]
242pub struct ReleaseConnection {
243    /// List of release edges.
244    pub edges: Vec<ReleaseEdge>,
245    /// Pagination information.
246    pub page_info: PageInfo,
247    /// Total count of releases (if available).
248    pub total_count: Option<i64>,
249}
250
251// =============================================================================
252// Statistics Type
253// =============================================================================
254
255/// Statistics about MIDDS on-chain data.
256#[derive(async_graphql::SimpleObject, Clone, Debug, Serialize, Deserialize)]
257#[serde(rename_all = "camelCase")]
258pub struct MiddsStats {
259    /// Total number of musical works registered.
260    pub total_musical_works: i64,
261    /// Total number of recordings registered.
262    pub total_recordings: i64,
263    /// Total number of releases registered.
264    pub total_releases: i64,
265}