Skip to content

Commit 4168a91

Browse files
committed
fix: build error
1 parent 9791a91 commit 4168a91

File tree

5 files changed

+248
-277
lines changed

5 files changed

+248
-277
lines changed

src/MusicLibraryImpl.native.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/MusicLibraryImpl.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/NativeMusicLibrary.ts

Lines changed: 245 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,247 @@
1-
// Re-export all types from the shared types file
2-
export * from './types';
1+
import type { TurboModule } from 'react-native';
2+
import { TurboModuleRegistry } from 'react-native';
33

4-
// Platform-specific module import
5-
// React Native Metro bundler will automatically pick the right file based on platform:
6-
// - MusicLibraryImpl.native.ts for iOS/Android
7-
// - MusicLibraryImpl.web.ts for web
8-
import MusicLibrary from './MusicLibraryImpl';
4+
/**
5+
* Sorting keys for music library items
6+
*/
7+
export type SortByKey =
8+
| 'default'
9+
| 'artist'
10+
| 'album'
11+
| 'duration'
12+
| 'createdAt'
13+
| 'modifiedAt'
14+
| 'genre'
15+
| 'trackCount';
16+
export type SortByValue = [SortByKey, boolean] | SortByKey;
917

10-
export default MusicLibrary;
18+
export type InternalSortByValue = `${SortByKey} ${'ASC' | 'DESC'}`;
19+
20+
export const SortByObject = {
21+
default: 'default',
22+
artist: 'artist',
23+
album: 'album',
24+
duration: 'duration',
25+
createdAt: 'createdAt',
26+
modifiedAt: 'modifiedAt',
27+
genre: 'genre',
28+
trackCount: 'trackCount',
29+
};
30+
31+
/**
32+
* Basic assets options
33+
*/
34+
export interface AssetsOptions {
35+
/**
36+
* Cursor for pagination - ID of the last item from previous page
37+
* @default undefined
38+
*/
39+
after?: string;
40+
41+
/**
42+
* Maximum number of items to return
43+
* @default 20
44+
*/
45+
first?: number;
46+
47+
/**
48+
* Sorting configuration
49+
* Can be a single key or a tuple of [key, ascending]
50+
* @example
51+
* 'title' // Sort by title descending (default)
52+
* ['title', true] // Sort by title ascending
53+
*/
54+
sortBy?: SortByValue | SortByValue[];
55+
56+
/**
57+
* Directory path to search for tracks
58+
* @default undefined
59+
*/
60+
directory?: string;
61+
}
62+
63+
/**
64+
* Internal assets options used by native module
65+
*/
66+
export interface InternalAssetsOptions {
67+
after?: string;
68+
first: number;
69+
sortBy: InternalSortByValue[];
70+
directory?: string;
71+
}
72+
73+
export interface IPaginatedResult<T> {
74+
/**
75+
* Array of items returned
76+
* @default []
77+
*/
78+
items: T[];
79+
80+
/**
81+
* Whether there are more items available
82+
* @default false
83+
*/
84+
hasNextPage: boolean;
85+
86+
/**
87+
* Cursor for next page (ID of last item)
88+
* @default undefined
89+
*/
90+
endCursor?: string;
91+
92+
/**
93+
* Total count of items (optional, may be expensive to compute)
94+
* @default undefined
95+
*/
96+
totalCount?: number;
97+
}
98+
99+
export interface Track {
100+
id: string;
101+
102+
/**
103+
* Track title
104+
* @default ''
105+
*/
106+
title: string;
107+
108+
/** Track artwork (file URI) */
109+
artwork: string;
110+
111+
/**
112+
* Artist name
113+
* @default ''
114+
*/
115+
artist: string;
116+
117+
/**
118+
* Album name
119+
* @default ''
120+
*/
121+
album: string;
122+
123+
/** Music genre */
124+
genre: string;
125+
126+
/**
127+
* Duration in seconds
128+
* @default 0
129+
*/
130+
duration: number;
131+
132+
/**
133+
* File URI or path
134+
* @default ''
135+
*/
136+
uri: string;
137+
138+
/**
139+
* Date added to library (Unix timestamp, optional)
140+
* @default undefined
141+
*/
142+
createdAt?: number;
143+
144+
/**
145+
* Date modified (Unix timestamp, optional)
146+
* @default undefined
147+
*/
148+
modifiedAt?: number;
149+
150+
/**
151+
* File size in bytes (optional)
152+
* @default undefined
153+
*/
154+
fileSize?: number;
155+
}
156+
157+
export interface Album {
158+
id: string;
159+
160+
/**
161+
* Album name
162+
* @default ''
163+
*/
164+
title: string;
165+
166+
/**
167+
* Primary artist
168+
* @default ''
169+
*/
170+
artist: string;
171+
172+
/**
173+
* Album artwork (base64 encoded image or URL, optional)
174+
* @default undefined
175+
*/
176+
artwork?: string;
177+
178+
/**
179+
* Number of tracks in album
180+
* @default 0
181+
*/
182+
trackCount: number;
183+
184+
/**
185+
* Total duration in seconds
186+
* @default 0
187+
*/
188+
duration: number;
189+
190+
/**
191+
* Release year (optional)
192+
* @default undefined
193+
*/
194+
year?: number;
195+
}
196+
197+
export interface Artist {
198+
id: string;
199+
200+
/**
201+
* Artist name
202+
* @default ''
203+
*/
204+
title: string;
205+
206+
/**
207+
* Number of albums
208+
* @default 0
209+
*/
210+
albumCount: number;
211+
212+
/**
213+
* Total number of tracks
214+
* @default 0
215+
*/
216+
trackCount: number;
217+
}
218+
219+
export interface Genre {
220+
id: string;
221+
222+
/**
223+
* Genre name
224+
* @default ''
225+
*/
226+
title: string;
227+
228+
/**
229+
* Number of tracks in this genre
230+
* @default 0
231+
*/
232+
trackCount: number;
233+
}
234+
235+
export type TrackResult = IPaginatedResult<Track>;
236+
export type AlbumResult = IPaginatedResult<Album>;
237+
export type ArtistResult = IPaginatedResult<Artist>;
238+
export type GenreResult = IPaginatedResult<Genre>;
239+
240+
export interface Spec extends TurboModule {
241+
getTracksAsync(options: InternalAssetsOptions): Promise<TrackResult>;
242+
getAlbumsAsync(options: InternalAssetsOptions): Promise<AlbumResult>;
243+
getArtistsAsync(options: InternalAssetsOptions): Promise<ArtistResult>;
244+
getGenresAsync(options: InternalAssetsOptions): Promise<GenreResult>;
245+
}
246+
247+
export default TurboModuleRegistry.getEnforcing<Spec>('MusicLibrary');
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type {
2-
MusicLibraryModule,
2+
Spec,
33
TrackResult,
44
AlbumResult,
55
ArtistResult,
66
GenreResult,
7-
} from './types';
7+
} from './NativeMusicLibrary';
88

99
const showWebWarning = () => {
1010
if (__DEV__) {
@@ -16,7 +16,7 @@ const showWebWarning = () => {
1616
};
1717

1818
// Web fallback implementation
19-
const MusicLibrary: MusicLibraryModule = {
19+
const MusicLibrary: Spec = {
2020
async getTracksAsync(): Promise<TrackResult> {
2121
showWebWarning();
2222
return {

0 commit comments

Comments
 (0)