Skip to content

Commit

Permalink
Merge pull request #149 from thornbill/shake-that
Browse files Browse the repository at this point in the history
Fix tree-shaking of the SDK
  • Loading branch information
thornbill authored Jun 17, 2022
2 parents 1a69409 + 8543500 commit 86270ae
Show file tree
Hide file tree
Showing 69 changed files with 895 additions and 319 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ A TypeScript SDK for Jellyfin.

> Warning: This project is under active development, so API changes may occur.
## Breaking Changes

### v0.5.0

* Build directory is now `lib` instead of `dist`.
Any imports used that were previously in `dist` will need updated.
[#147](https://github.com/thornbill/jellyfin-sdk-typescript/pull/147)
* Duplicated exports were removed.
Any imports may need updated if you referenced one of the duplicates.
[#148](https://github.com/thornbill/jellyfin-sdk-typescript/pull/148)
* API classes are no longer exposed via getters.
Instead you need to call a function passing the `Api` instance as a parameter. For example: `getSystemApi(api)`. While I do feel this is a slightly worse developer experience, it was a necessary change to support tree-shaking. [#149](https://github.com/thornbill/jellyfin-sdk-typescript/pull/149)

## Install

```sh
Expand Down Expand Up @@ -61,11 +74,11 @@ const api = jellyfin.createApi(best.address);
// are available as api.systemApi.

// Fetch the public system info
const info = await api.systemApi.getPublicSystemInfo();
const info = await getSystemApi(api).getPublicSystemInfo();
console.log('Info =>', info.data);

// Fetch the list of public users
const users = await api.userApi.getPublicUsers();
const users = await getUserApi(api).getPublicUsers();
console.log('Users =>', users.data);

// A helper method for authentication has been added to the SDK because
Expand All @@ -76,7 +89,7 @@ console.log('Auth =>', auth.data);

// Authentication state is stored internally in the Api class, so now
// requests that require authentication can be made normally
const libraries = await api.libraryApi.getMediaFolders();
const libraries = await getLibraryApi(api).getMediaFolders();
console.log('Libraries =>', libraries.data);

// A helper method for logging out the current user has been added to the
Expand Down
67 changes: 1 addition & 66 deletions src/__tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mocked } from 'ts-jest/utils';

import { Api, AUTHORIZATION_HEADER } from '..';
import { SERVER_URL, TEST_CLIENT, TEST_DEVICE } from '../__helpers__/common';
import { ActivityLogApi, ApiKeyApi, ArtistsApi, AudioApi, BrandingApi, ChannelsApi, CollectionApi, ConfigurationApi, DashboardApi, DevicesApi, DisplayPreferencesApi, DlnaApi, DlnaServerApi, DynamicHlsApi, EnvironmentApi, FilterApi, GenresApi, HlsSegmentApi, ImageApi, ImageByNameApi, ImageType, InstantMixApi, ItemLookupApi, ItemRefreshApi, ItemsApi, ItemUpdateApi, LibraryApi, LibraryStructureApi, LiveTvApi, LocalizationApi, MediaInfoApi, MoviesApi, MusicGenresApi, NotificationsApi, PackageApi, PersonsApi, PlaylistsApi, PlaystateApi, PluginsApi, QuickConnectApi, RemoteImageApi, ScheduledTasksApi, SearchApi, SessionApi, StartupApi, StudiosApi, SubtitleApi, SuggestionsApi, SyncPlayApi, SystemApi, TimeSyncApi, TrailersApi, TvShowsApi, UniversalAudioApi, UserApi, UserLibraryApi, UserViewsApi, VideoAttachmentsApi, VideoHlsApi, VideosApi, YearsApi } from '../generated-client';
import { ImageType } from '../generated-client/models';
import { getAuthorizationHeader } from '../utils';

jest.mock('axios', () => ({
Expand Down Expand Up @@ -79,69 +79,4 @@ describe('Api', () => {
expect(api.getItemImageUrl('TEST', ImageType.Backdrop, { fillWidth: 100, fillHeight: 100 }))
.toBe('https://example.com/Items/TEST/Images/Backdrop?fillWidth=100&fillHeight=100');
});

it('should return api instances', () => {
const api = new Api(SERVER_URL, TEST_CLIENT, TEST_DEVICE);

expect(api.activityLogApi).toBeInstanceOf(ActivityLogApi);
expect(api.apiKeyApi).toBeInstanceOf(ApiKeyApi);
expect(api.artistsApi).toBeInstanceOf(ArtistsApi);
expect(api.audioApi).toBeInstanceOf(AudioApi);
expect(api.brandingApi).toBeInstanceOf(BrandingApi);
expect(api.channelsApi).toBeInstanceOf(ChannelsApi);
expect(api.collectionApi).toBeInstanceOf(CollectionApi);
expect(api.configurationApi).toBeInstanceOf(ConfigurationApi);
expect(api.dashboardApi).toBeInstanceOf(DashboardApi);
expect(api.devicesApi).toBeInstanceOf(DevicesApi);
expect(api.displayPreferencesApi).toBeInstanceOf(DisplayPreferencesApi);
expect(api.dlnaApi).toBeInstanceOf(DlnaApi);
expect(api.dlnaServerApi).toBeInstanceOf(DlnaServerApi);
expect(api.dynamicHlsApi).toBeInstanceOf(DynamicHlsApi);
expect(api.environmentApi).toBeInstanceOf(EnvironmentApi);
expect(api.filterApi).toBeInstanceOf(FilterApi);
expect(api.genresApi).toBeInstanceOf(GenresApi);
expect(api.hlsSegmentApi).toBeInstanceOf(HlsSegmentApi);
expect(api.imageApi).toBeInstanceOf(ImageApi);
expect(api.imageByNameApi).toBeInstanceOf(ImageByNameApi);
expect(api.instantMixApi).toBeInstanceOf(InstantMixApi);
expect(api.itemLookupApi).toBeInstanceOf(ItemLookupApi);
expect(api.itemRefreshApi).toBeInstanceOf(ItemRefreshApi);
expect(api.itemUpdateApi).toBeInstanceOf(ItemUpdateApi);
expect(api.itemsApi).toBeInstanceOf(ItemsApi);
expect(api.libraryApi).toBeInstanceOf(LibraryApi);
expect(api.libraryStructureApi).toBeInstanceOf(LibraryStructureApi);
expect(api.liveTvApi).toBeInstanceOf(LiveTvApi);
expect(api.localizationApi).toBeInstanceOf(LocalizationApi);
expect(api.mediaInfoApi).toBeInstanceOf(MediaInfoApi);
expect(api.moviesApi).toBeInstanceOf(MoviesApi);
expect(api.musicGenresApi).toBeInstanceOf(MusicGenresApi);
expect(api.notificationsApi).toBeInstanceOf(NotificationsApi);
expect(api.packageApi).toBeInstanceOf(PackageApi);
expect(api.personsApi).toBeInstanceOf(PersonsApi);
expect(api.playlistsApi).toBeInstanceOf(PlaylistsApi);
expect(api.playstateApi).toBeInstanceOf(PlaystateApi);
expect(api.pluginsApi).toBeInstanceOf(PluginsApi);
expect(api.quickConnectApi).toBeInstanceOf(QuickConnectApi);
expect(api.remoteImageApi).toBeInstanceOf(RemoteImageApi);
expect(api.scheduledTasksApi).toBeInstanceOf(ScheduledTasksApi);
expect(api.searchApi).toBeInstanceOf(SearchApi);
expect(api.sessionApi).toBeInstanceOf(SessionApi);
expect(api.startupApi).toBeInstanceOf(StartupApi);
expect(api.studiosApi).toBeInstanceOf(StudiosApi);
expect(api.subtitleApi).toBeInstanceOf(SubtitleApi);
expect(api.suggestionsApi).toBeInstanceOf(SuggestionsApi);
expect(api.syncPlayApi).toBeInstanceOf(SyncPlayApi);
expect(api.systemApi).toBeInstanceOf(SystemApi);
expect(api.timeSyncApi).toBeInstanceOf(TimeSyncApi);
expect(api.trailersApi).toBeInstanceOf(TrailersApi);
expect(api.tvShowsApi).toBeInstanceOf(TvShowsApi);
expect(api.universalAudioApi).toBeInstanceOf(UniversalAudioApi);
expect(api.userApi).toBeInstanceOf(UserApi);
expect(api.userLibraryApi).toBeInstanceOf(UserLibraryApi);
expect(api.userViewsApi).toBeInstanceOf(UserViewsApi);
expect(api.videoAttachmentsApi).toBeInstanceOf(VideoAttachmentsApi);
expect(api.videoHlsApi).toBeInstanceOf(VideoHlsApi);
expect(api.videosApi).toBeInstanceOf(VideosApi);
expect(api.yearsApi).toBeInstanceOf(YearsApi);
});
});
Loading

0 comments on commit 86270ae

Please sign in to comment.