AlbumQuery and ArtistQuery types on MusicService

This commit is contained in:
simojenki
2021-03-02 10:24:55 +11:00
parent bdee01d2c7
commit 06024e8e36
5 changed files with 39 additions and 76 deletions

View File

@@ -38,31 +38,35 @@ export type Album = {
};
export type Paging = {
_index?: number;
_count?: number;
_index: number;
_count: number;
};
export type Result<T> = {
results: T[],
total: number
}
results: T[];
total: number;
};
export function slice2<T>({ _index, _count }: Paging) {
const i0 = _index || 0;
const i1 = _count ? i0 + _count : undefined;
return (things: T[]): [T[], number] => [things.slice(i0, i1), things.length]
return (things: T[]): [T[], number] => [
things.slice(_index, _index + _count),
things.length,
];
}
export const asResult = <T>([results, total]: [T[], number]) => ({ results, total })
export const asResult = <T>([results, total]: [T[], number]) => ({
results,
total,
});
export type ArtistQuery = Paging
export type AlbumQuery = Paging & {
artistId?: string
}
export interface MusicLibrary {
artists({ _index, _count }: Paging): Promise<Result<Artist>>;
artists(q: ArtistQuery): Promise<Result<Artist>>;
artist(id: string): Artist;
albums({
artistId,
_index,
_count,
}: {
artistId?: string;
} & Paging): Promise<Result<Album>>;
albums(q: AlbumQuery): Promise<Result<Album>>;
}