Skip to content

Commit f5ab7c2

Browse files
committed
fix(bundle): use minimal conf to allow treeshaking
1 parent 6cf524d commit f5ab7c2

14 files changed

+63
-73
lines changed

src/services/tmdb-client/api/tmdb-api.endpoint.ts src/services/tmdb-client/api/tmdb-api.endpoints.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ export const tmdbApi = {
66
v4,
77
};
88

9-
const { auth } = v4;
10-
export const minimalTmdbApi = { v4: { auth } };
9+
export type TmdbApi = typeof tmdbApi;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { auth } from '~/services/tmdb-client/api/endpoints/v4/auth.endpoint';
2+
3+
export const minimalTmdbApi = { v4: { auth } };

src/services/tmdb-client/clients/base-tmdb-client.ts

+5-12
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ import type {
1212
TmdbPaginatedData,
1313
} from '~/models/tmdb/tmdb-client.model';
1414

15+
import type { TmdbApi } from '~/services/tmdb-client/api/tmdb-api.endpoints';
16+
1517
import { TraktApiHeaders } from '~/models/trakt/trakt-client.model';
1618
import { BaseApiHeaders, type BaseBody, BaseClient, BaseHeaderContentType, parseBody, parseUrl } from '~/services/common/base-client';
17-
import { minimalTmdbApi, type tmdbApi } from '~/services/tmdb-client/api/tmdb-api.endpoint';
18-
19-
/**
20-
* The extracted type signature of the TmdbApi
21-
*/
22-
type ITmdbEndpoints = typeof tmdbApi;
2319

2420
/** Needed to type Object assignment */
2521
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- To allow type extension
26-
export interface BaseTmdbClient extends ITmdbEndpoints {}
22+
export interface BaseTmdbClient extends TmdbApi {}
2723

2824
const isPageResponse = (response: TmdbApiResponseData | TmdbApiResponsePageData): response is TmdbApiResponsePageData =>
2925
'page' in response && 'total_pages' in response && 'total_results' in response;
@@ -55,17 +51,14 @@ const parseResponse = (response: TmdbApiResponseData | TmdbApiResponsePageData)
5551
* @class BaseTmdbClient
5652
*/
5753
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- To allow type extension
58-
export class BaseTmdbClient
59-
extends BaseClient<TmdbApiQuery, TmdbApiResponse, TmdbClientSettings, TmdbClientAuthentication>
60-
implements ITmdbEndpoints
61-
{
54+
export class BaseTmdbClient extends BaseClient<TmdbApiQuery, TmdbApiResponse, TmdbClientSettings, TmdbClientAuthentication> implements TmdbApi {
6255
/**
6356
* Creates an instance of BaseTmdbClient.
6457
* @param options - The options for the client.
6558
* @param authentication - The authentication for the client.
6659
* @param api - The API endpoints for the client.
6760
*/
68-
constructor(options: TmdbClientOptions, authentication: TmdbClientAuthentication = {}, api: ITmdbApi = minimalTmdbApi) {
61+
constructor(options: TmdbClientOptions, authentication: TmdbClientAuthentication = {}, api: ITmdbApi = {}) {
6962
super(options, authentication, api);
7063
}
7164

src/services/tmdb-client/clients/tmdb-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TmdbClientAuthentication, TmdbClientOptions } from '~/models/tmdb/tmdb-client.model';
22

3-
import { tmdbApi } from '~/services/tmdb-client/api/tmdb-api.endpoint';
3+
import { minimalTmdbApi } from '~/services/tmdb-client/api/tmdb-minimal-api.endpoints';
44
import { BaseTmdbClient } from '~/services/tmdb-client/clients/base-tmdb-client';
55
import { Config } from '~/settings/tmdb.api';
66

@@ -18,7 +18,7 @@ export class TmdbClient extends BaseTmdbClient {
1818
* @param authentication - The authentication for the client.
1919
*/
2020
constructor(settings: TmdbClientOptions, authentication: TmdbClientAuthentication = {}) {
21-
super(settings, authentication, tmdbApi);
21+
super(settings, authentication, minimalTmdbApi);
2222
}
2323

2424
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { authentication } from '~/services/trakt-client/api/endpoints/authentication.endpoint';
2+
3+
export const minimalTraktApi = { authentication };

src/services/trakt-client/api/trakt-api.endpoints.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ export const traktApi = {
155155
users,
156156
};
157157

158-
export const minimalTraktApi = { authentication };
158+
export type TraktApi = typeof traktApi;

src/services/trakt-client/clients/base-trakt-client.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import type {
99
TraktClientSettings,
1010
} from '~/models/trakt/trakt-client.model';
1111

12+
import type { TraktApi } from '~/services/trakt-client/api/trakt-api.endpoints';
1213
import type { Primitive } from '~/utils/typescript.utils';
1314

1415
import { TraktApiHeaders } from '~/models/trakt/trakt-client.model';
1516

1617
import { type BaseBody, BaseClient, BaseHeaderContentType, parseBody, parseUrl } from '~/services/common/base-client';
17-
import { minimalTraktApi, type traktApi } from '~/services/trakt-client/api/trakt-api.endpoints';
1818
import { isFilter, TraktApiFilterValidator } from '~/services/trakt-client/api/trakt-api.filters';
1919

2020
/**
@@ -100,32 +100,24 @@ export const parseResponse = <T>(response: Response): TraktApiResponse<T> => {
100100
return _response;
101101
};
102102

103-
/**
104-
* The extracted type signature of the TraktApi
105-
*/
106-
type ITraktEndpoints = typeof traktApi;
107-
108103
/** Needed to type Object assignment */
109104
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- To allow type extension
110-
export interface BaseTraktClient extends ITraktEndpoints {}
105+
export interface BaseTraktClient extends TraktApi {}
111106

112107
/**
113108
* Represents a Trakt API client with common functionality.
114109
*
115110
* @class BaseTraktClient
116111
*/
117112
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- To allow type extension
118-
export class BaseTraktClient
119-
extends BaseClient<TraktApiQuery, TraktApiResponse, TraktClientSettings, TraktClientAuthentication>
120-
implements ITraktEndpoints
121-
{
113+
export class BaseTraktClient extends BaseClient<TraktApiQuery, TraktApiResponse, TraktClientSettings, TraktClientAuthentication> implements TraktApi {
122114
/**
123115
* Creates an instance of BaseTraktClient.
124116
* @param options - The options for the client.
125117
* @param authentication - The authentication for the client.
126118
* @param api - The API endpoints for the client.
127119
*/
128-
constructor(options: TraktClientOptions, authentication: TraktClientAuthentication = {}, api: ITraktApi = minimalTraktApi) {
120+
constructor(options: TraktClientOptions, authentication: TraktClientAuthentication = {}, api: ITraktApi = {}) {
129121
super(options, authentication, api);
130122
}
131123

src/services/trakt-client/clients/trakt-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type {
1313
import type { TraktApiInit, TraktApiResponse, TraktClientOptions } from '~/models/trakt/trakt-client.model';
1414

1515
import { TraktApiHeaders } from '~/models/trakt/trakt-client.model';
16-
import { traktApi } from '~/services/trakt-client/api/trakt-api.endpoints';
16+
import { minimalTraktApi } from '~/services/trakt-client/api/trakt-api-minimal.endpoints';
1717
import { randomHex } from '~/utils/crypto.utils';
1818

1919
/**
@@ -56,7 +56,7 @@ export class TraktClient extends BaseTraktClient {
5656
* @param authentication - The authentication for the client.
5757
*/
5858
constructor(settings: TraktClientOptions, authentication: TraktClientAuthentication = {}) {
59-
super(settings, authentication, traktApi);
59+
super(settings, authentication, minimalTraktApi);
6060
}
6161

6262
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { TvdbClientEndpoint } from '~/models/tvdb/tvdb-client.model';
2+
import { HttpMethod } from '~/utils/http.utils';
3+
4+
/**
5+
* Create an auth token. The token has one month validation length.
6+
*
7+
* @see [login]{@link https://thetvdb.github.io/v4-api/#/Login}
8+
*/
9+
export const login = new TvdbClientEndpoint<
10+
{
11+
apiKey: string;
12+
pin?: string;
13+
},
14+
{
15+
token: string;
16+
},
17+
false
18+
>({
19+
method: HttpMethod.POST,
20+
url: '/login',
21+
opts: {
22+
cache: false,
23+
},
24+
body: {
25+
apiKey: true,
26+
pin: false,
27+
},
28+
});

src/services/tvdb-client/api/tvdb-api.endpoint.ts src/services/tvdb-client/api/tvdb-api.endpoints.ts

+3-27
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { episodes } from '~/services/tvdb-client/api/endpoints/episodes.endpoint
1818
import { favorites } from '~/services/tvdb-client/api/endpoints/favorites.endpoint';
1919
import { genres } from '~/services/tvdb-client/api/endpoints/genres.endpoint';
2020
import { lists } from '~/services/tvdb-client/api/endpoints/lists.endpoint';
21+
import { login } from '~/services/tvdb-client/api/endpoints/login.endpoint';
2122
import { movies } from '~/services/tvdb-client/api/endpoints/movies.endpoint';
2223
import { people } from '~/services/tvdb-client/api/endpoints/people.endpoints';
2324
import { search } from '~/services/tvdb-client/api/endpoints/search.endpoint';
@@ -30,31 +31,7 @@ import { HttpMethod } from '~/utils/http.utils';
3031
* @see [documentation]{@link https://thetvdb.github.io/v4-api/#/Login/post_login}
3132
*/
3233
export const tvdbApi = {
33-
/**
34-
* Create an auth token. The token has one month validation length.
35-
*
36-
* @see [login]{@link https://thetvdb.github.io/v4-api/#/Login}
37-
*/
38-
login: new TvdbClientEndpoint<
39-
{
40-
apiKey: string;
41-
pin?: string;
42-
},
43-
{
44-
token: string;
45-
},
46-
false
47-
>({
48-
method: HttpMethod.POST,
49-
url: '/login',
50-
opts: {
51-
cache: false,
52-
},
53-
body: {
54-
apiKey: true,
55-
pin: false,
56-
},
57-
}),
34+
login,
5835
artwork,
5936
awards,
6037
/**
@@ -238,5 +215,4 @@ export const tvdbApi = {
238215
favorites,
239216
};
240217

241-
const { login } = tvdbApi;
242-
export const minimalTvdbApi = { login };
218+
export type TvdbApi = typeof tvdbApi;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { login } from '~/services/tvdb-client/api/endpoints/login.endpoint';
2+
3+
export const minimalTvdbApi = { login };

src/services/tvdb-client/clients/base-tvdb-client.ts

+5-12
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,29 @@ import type {
1010
TvdbClientSettings,
1111
} from '~/models/tvdb/tvdb-client.model';
1212

13+
import type { TvdbApi } from '~/services/tvdb-client/api/tvdb-api.endpoints';
14+
1315
import { TraktApiHeaders } from '~/models/trakt/trakt-client.model';
1416
import { BaseApiHeaders, type BaseBody, BaseClient, BaseHeaderContentType, parseBody, parseUrl } from '~/services/common/base-client';
15-
import { minimalTvdbApi, type tvdbApi } from '~/services/tvdb-client/api/tvdb-api.endpoint';
16-
17-
/**
18-
* The extracted type signature of the TvdbApi
19-
*/
20-
type ITvdbEndpoints = typeof tvdbApi;
2117

2218
/** Needed to type Object assignment */
2319
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- To allow type extension
24-
export interface BaseTvdbClient extends ITvdbEndpoints {}
20+
export interface BaseTvdbClient extends TvdbApi {}
2521

2622
/**
2723
* Represents a Tvdb API client with common functionality.
2824
*
2925
* @class BaseTvdbClient
3026
*/
3127
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -- To allow type extension
32-
export class BaseTvdbClient
33-
extends BaseClient<TvdbApiQuery, TvdbApiResponse, TvdbClientSettings, TvdbClientAuthentication>
34-
implements ITvdbEndpoints
35-
{
28+
export class BaseTvdbClient extends BaseClient<TvdbApiQuery, TvdbApiResponse, TvdbClientSettings, TvdbClientAuthentication> implements TvdbApi {
3629
/**
3730
* Creates an instance of BaseTvdbClient.
3831
* @param options - The options for the client.
3932
* @param authentication - The authentication for the client.
4033
* @param api - The API endpoints for the client.
4134
*/
42-
constructor(options: TvdbClientOptions, authentication: TvdbClientAuthentication = {}, api: ITvdbApi = minimalTvdbApi) {
35+
constructor(options: TvdbClientOptions, authentication: TvdbClientAuthentication = {}, api: ITvdbApi = {}) {
4336
super(options, authentication, api);
4437
}
4538

src/services/tvdb-client/clients/tvdb-client.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { HttpMethod } from '../../../utils/http.utils';
77
import { BaseApiHeaders, BaseHeaderContentType } from '../../common/base-client';
88

99
import { hasOwnProperty } from '../../common/test.utils';
10-
import { tvdbApi } from '../api/tvdb-api.endpoint';
10+
import { tvdbApi } from '../api/tvdb-api.endpoints';
1111

1212
import { TvdbClient } from './tvdb-client';
1313

src/services/tvdb-client/clients/tvdb-client.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TvdbClientAuthentication, TvdbClientOptions } from '~/models/tvdb/tvdb-client.model';
22

3-
import { tvdbApi } from '~/services/tvdb-client/api/tvdb-api.endpoint';
3+
import { minimalTvdbApi } from '~/services/tvdb-client/api/tvdb-minimal-api.endpoints';
44
import { BaseTvdbClient } from '~/services/tvdb-client/clients/base-tvdb-client';
55

66
/**
@@ -17,7 +17,7 @@ export class TvdbClient extends BaseTvdbClient {
1717
* @param authentication - The authentication for the client.
1818
*/
1919
constructor(settings: TvdbClientOptions, authentication: TvdbClientAuthentication = {}) {
20-
super(settings, authentication, tvdbApi);
20+
super(settings, authentication, minimalTvdbApi);
2121
}
2222

2323
/**

0 commit comments

Comments
 (0)