|
1 | | -import type { TurboModule } from 'react-native'; |
2 | | -import { TurboModuleRegistry } from 'react-native'; |
| 1 | +// Re-export all types from the shared types file |
| 2 | +export * from './types'; |
3 | 3 |
|
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; |
| 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'; |
17 | 9 |
|
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'); |
| 10 | +export default MusicLibrary; |
0 commit comments