@tutkli/jikan-ts 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  2. package/.idea/jikan-ts.iml +12 -0
  3. package/.idea/jsLinters/eslint.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/prettier.xml +6 -0
  6. package/.idea/vcs.xml +6 -0
  7. package/CHANGELOG.md +16 -0
  8. package/dist/index.d.ts +11 -11
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +4 -4
  11. package/dist/index.js.map +1 -1
  12. package/package.json +1 -1
  13. package/.editorconfig +0 -16
  14. package/.eslintignore +0 -17
  15. package/.eslintrc.json +0 -27
  16. package/.prettierrc.json +0 -8
  17. package/jest.config.js +0 -25
  18. package/src/__tests__/anime-client.spec.ts +0 -33
  19. package/src/__tests__/manga-client.spec.ts +0 -33
  20. package/src/__tests__/top-client.spec.ts +0 -33
  21. package/src/clients/anime.client.ts +0 -233
  22. package/src/clients/base.client.ts +0 -82
  23. package/src/clients/index.ts +0 -4
  24. package/src/clients/jikan.client.ts +0 -28
  25. package/src/clients/manga.client.ts +0 -142
  26. package/src/clients/top.client.ts +0 -52
  27. package/src/config/cache.config.ts +0 -8
  28. package/src/config/index.ts +0 -2
  29. package/src/config/logger.config.ts +0 -25
  30. package/src/constants/base.constant.ts +0 -3
  31. package/src/constants/endpoints.constant.ts +0 -29
  32. package/src/constants/index.ts +0 -2
  33. package/src/index.ts +0 -4
  34. package/src/models/Anime/anime-character.model.ts +0 -11
  35. package/src/models/Anime/anime-episode.model.ts +0 -12
  36. package/src/models/Anime/anime-picture.model.ts +0 -5
  37. package/src/models/Anime/anime-staff.model.ts +0 -6
  38. package/src/models/Anime/anime-statistics.model.ts +0 -6
  39. package/src/models/Anime/anime-video.model.ts +0 -38
  40. package/src/models/Anime/anime.model.ts +0 -95
  41. package/src/models/Anime/index.ts +0 -7
  42. package/src/models/Common/character.model.ts +0 -18
  43. package/src/models/Common/image.model.ts +0 -12
  44. package/src/models/Common/index.ts +0 -6
  45. package/src/models/Common/person.model.ts +0 -8
  46. package/src/models/Common/recommendation.model.ts +0 -12
  47. package/src/models/Common/resource.model.ts +0 -31
  48. package/src/models/Common/statistics.model.ts +0 -13
  49. package/src/models/Manga/index.ts +0 -2
  50. package/src/models/Manga/manga-statistics.model.ts +0 -6
  51. package/src/models/Manga/manga.model.ts +0 -58
  52. package/src/models/Params/index.ts +0 -2
  53. package/src/models/Params/search-params.model.ts +0 -72
  54. package/src/models/Params/top-params.model.ts +0 -41
  55. package/src/models/Response/index.ts +0 -1
  56. package/src/models/Response/response.model.ts +0 -21
  57. package/src/models/index.ts +0 -5
  58. package/tsconfig.eslint.json +0 -5
  59. package/tsconfig.json +0 -23
@@ -1,33 +0,0 @@
1
- import { MangaClient } from '../clients';
2
- import { MangaSearchParams } from '../models/Params';
3
- import { JikanResponse, JikanUniqueResponse, Manga } from '../models';
4
-
5
- describe('test Manga Client', () => {
6
- let client: MangaClient;
7
- beforeAll(() => {
8
- client = new MangaClient();
9
- });
10
- beforeEach(async () => {
11
- await new Promise((resolve) => setTimeout(resolve, 1000));
12
- });
13
-
14
- it('should get mangas filtered by params', async () => {
15
- const params: MangaSearchParams = { limit: 3, score: 9 };
16
- const data = await client.getMangaSearch(params).then((response: JikanResponse<Manga>) => response.data);
17
-
18
- expect(data).toHaveLength(3);
19
- for (const anime of data) {
20
- expect(anime.score).toBeGreaterThanOrEqual(9);
21
- }
22
- });
23
-
24
- it('should get a full manga by its ID', async () => {
25
- const data = await client.getMangaFullById(1).then((response: JikanUniqueResponse<Manga>) => response.data);
26
- expect(data.mal_id).toBe(1);
27
- });
28
-
29
- it('should get an manga by its ID', async () => {
30
- const data = await client.getMangaById(1).then((response: JikanUniqueResponse<Manga>) => response.data);
31
- expect(data.mal_id).toBe(1);
32
- });
33
- });
@@ -1,33 +0,0 @@
1
- import { AnimeTopParams, MangaTopParams, TopAnimeFilter, TopMangaFilter } from '../models/Params';
2
- import { Anime, AnimeStatus, JikanResponse, Manga, MangaStatus } from '../models';
3
- import { TopClient } from '../clients/top.client';
4
-
5
- describe('test Top Client', () => {
6
- let client: TopClient;
7
- beforeAll(() => {
8
- client = new TopClient();
9
- });
10
- beforeEach(async () => {
11
- await new Promise((resolve) => setTimeout(resolve, 1000));
12
- });
13
-
14
- it('should get top animes filtered by params', async () => {
15
- const params: AnimeTopParams = { limit: 3, filter: TopAnimeFilter.airing };
16
- const data = await client.getTopAnime(params).then((response: JikanResponse<Anime>) => response.data);
17
-
18
- expect(data).toHaveLength(3);
19
- for (const anime of data) {
20
- expect(anime.status).toBe(AnimeStatus.airing);
21
- }
22
- });
23
-
24
- it('should get top mangas filtered by params', async () => {
25
- const params: MangaTopParams = { limit: 3, filter: TopMangaFilter.publishing };
26
- const data = await client.getTopManga(params).then((response: JikanResponse<Manga>) => response.data);
27
-
28
- expect(data).toHaveLength(3);
29
- for (const manga of data) {
30
- expect(manga.status).toBe(MangaStatus.publishing);
31
- }
32
- });
33
- });
@@ -1,233 +0,0 @@
1
- import { BaseClient, ClientArgs } from './base.client';
2
- import { AnimeEndpoints } from '../constants';
3
- import { CacheAxiosResponse } from 'axios-cache-interceptor';
4
- import { AxiosError } from 'axios';
5
- import {
6
- Anime,
7
- AnimeCharacter,
8
- AnimeEpisode,
9
- AnimePicture,
10
- AnimeStaff,
11
- AnimeStatistics,
12
- AnimeVideo,
13
- AnimeVideoEpisode,
14
- JikanResponse,
15
- JikanUniqueResponse,
16
- Recommendation,
17
- } from '../models';
18
- import { AnimeSearchParams } from '../models/Params';
19
-
20
- /**
21
- * **Anime Client**
22
- *
23
- * Client used to access the Anime Endpoints:
24
- * - [AnimeSearch](https://docs.api.jikan.moe/#tag/anime)
25
- * - [AnimeFullById](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeFullById)
26
- * - [AnimeById](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeById)
27
- * - [AnimeCharacters](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeCharacters)
28
- * - [AnimeStaff](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeStaff)
29
- * - [AnimeEpisodes](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeEpisodes)
30
- * - [AnimeEpisodeById](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeEpisodeById)
31
- * - [AnimeVideos](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeVideos)
32
- * - [AnimeVideosEpisodes](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeVideosEpisodes)
33
- * - [AnimePictures](https://docs.api.jikan.moe/#tag/anime/operation/getAnimePictures)
34
- * - [AnimeStatistics](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeStatistics)
35
- * - [AnimeRecommendations](https://docs.api.jikan.moe/#tag/anime/operation/getAnimeRecommendations)
36
- *
37
- * See also: [JikanAPI](https://docs.api.jikan.moe/)
38
- */
39
- export class AnimeClient extends BaseClient {
40
- /**
41
- * @argument clientOptions Options for the client.
42
- */
43
- constructor(clientOptions?: ClientArgs) {
44
- super(clientOptions);
45
- }
46
-
47
- /**
48
- * Get all the filtered Animes. Returns all the Animes if no filters are given.
49
- * @param searchParams Filter parameters
50
- * @returns A JikanResponse with Anime data
51
- */
52
- public async getAnimeSearch(searchParams?: AnimeSearchParams): Promise<JikanResponse<Anime>> {
53
- return new Promise<JikanResponse<Anime>>((resolve, reject) => {
54
- const endpoint = `${AnimeEndpoints.AnimeSearch}`;
55
- this.api
56
- .get<JikanResponse<Anime>>(endpoint, { params: searchParams })
57
- .then((response: CacheAxiosResponse<JikanResponse<Anime>>) => resolve(response.data))
58
- .catch((error: AxiosError<string>) => reject(error));
59
- });
60
- }
61
-
62
- /**
63
- * Get a complete Anime resource data
64
- * @param mal_id The Anime ID
65
- * @returns A JikanUniqueResponse with Anime data
66
- */
67
- public async getAnimeFullById(mal_id: number): Promise<JikanUniqueResponse<Anime>> {
68
- return new Promise<JikanUniqueResponse<Anime>>((resolve, reject) => {
69
- const endpoint = `${AnimeEndpoints.AnimeFullById.replace('{id}', String(mal_id))}`;
70
- this.api
71
- .get<JikanUniqueResponse<Anime>>(endpoint)
72
- .then((response: CacheAxiosResponse<JikanUniqueResponse<Anime>>) => resolve(response.data))
73
- .catch((error: AxiosError<string>) => reject(error));
74
- });
75
- }
76
-
77
- /**
78
- * Get Anime resource data
79
- * @param mal_id The Anime ID
80
- * @returns A JikanUniqueResponse with Anime data
81
- */
82
- public async getAnimeById(mal_id: number): Promise<JikanUniqueResponse<Anime>> {
83
- return new Promise<JikanUniqueResponse<Anime>>((resolve, reject) => {
84
- const endpoint = `${AnimeEndpoints.AnimeById.replace('{id}', String(mal_id))}`;
85
- this.api
86
- .get<JikanUniqueResponse<Anime>>(endpoint)
87
- .then((response: CacheAxiosResponse<JikanUniqueResponse<Anime>>) => resolve(response.data))
88
- .catch((error: AxiosError<string>) => reject(error));
89
- });
90
- }
91
-
92
- /**
93
- * Get Characters of a specific Anime
94
- * @param mal_id The Anime ID
95
- * @returns A JikanResponse with AnimeCharacter data
96
- */
97
- public async getAnimeCharacters(mal_id: number): Promise<JikanResponse<AnimeCharacter>> {
98
- return new Promise<JikanResponse<AnimeCharacter>>((resolve, reject) => {
99
- const endpoint = `${AnimeEndpoints.AnimeCharacters.replace('{id}', String(mal_id))}`;
100
- this.api
101
- .get<JikanResponse<AnimeCharacter>>(endpoint)
102
- .then((response: CacheAxiosResponse<JikanResponse<AnimeCharacter>>) => resolve(response.data))
103
- .catch((error: AxiosError<string>) => reject(error));
104
- });
105
- }
106
-
107
- /**
108
- * Get Staff of a specific Anime
109
- * @param mal_id The Anime ID
110
- * @returns A JikanResponse with AnimeStaff data
111
- */
112
- public async getAnimeStaff(mal_id: number): Promise<JikanResponse<AnimeStaff>> {
113
- return new Promise<JikanResponse<AnimeStaff>>((resolve, reject) => {
114
- const endpoint = `${AnimeEndpoints.AnimeStaff.replace('{id}', String(mal_id))}`;
115
- this.api
116
- .get<JikanResponse<AnimeStaff>>(endpoint)
117
- .then((response: CacheAxiosResponse<JikanResponse<AnimeStaff>>) => resolve(response.data))
118
- .catch((error: AxiosError<string>) => reject(error));
119
- });
120
- }
121
-
122
- /**
123
- * Get a list of all the episodes of a specific Anime
124
- * @param mal_id The Anime ID
125
- * @returns A JikanResponse with AnimeEpisode data
126
- */
127
- public async getAnimeEpisodes(mal_id: number): Promise<JikanResponse<AnimeEpisode>> {
128
- return new Promise<JikanResponse<AnimeEpisode>>((resolve, reject) => {
129
- const endpoint = `${AnimeEndpoints.AnimeEpisodes.replace('{id}', String(mal_id))}`;
130
- this.api
131
- .get<JikanResponse<AnimeEpisode>>(endpoint)
132
- .then((response: CacheAxiosResponse<JikanResponse<AnimeEpisode>>) => resolve(response.data))
133
- .catch((error: AxiosError<string>) => reject(error));
134
- });
135
- }
136
-
137
- /**
138
- * Get a single Episode of a specific Anime by its ID
139
- * @param anime_mal_id The Anime ID
140
- * @param episode_mal_id The Episode ID
141
- * @returns A JikanUniqueResponse with AnimeEpisode data
142
- */
143
- public async getAnimeEpisodeById(
144
- anime_mal_id: number,
145
- episode_mal_id: number
146
- ): Promise<JikanUniqueResponse<AnimeEpisode>> {
147
- return new Promise<JikanUniqueResponse<AnimeEpisode>>((resolve, reject) => {
148
- const endpoint = `${AnimeEndpoints.AnimeEpisodeById.replace('{id}', String(anime_mal_id)).replace(
149
- '{episode}',
150
- String(episode_mal_id)
151
- )}`;
152
- this.api
153
- .get<JikanUniqueResponse<AnimeEpisode>>(endpoint)
154
- .then((response: CacheAxiosResponse<JikanUniqueResponse<AnimeEpisode>>) => resolve(response.data))
155
- .catch((error: AxiosError<string>) => reject(error));
156
- });
157
- }
158
-
159
- /**
160
- * Get Videos related to a specific Anime
161
- * @param mal_id The Anime ID
162
- * @returns A JikanUniqueResponse with AnimeVideo data
163
- */
164
- public async getAnimeVideos(mal_id: number): Promise<JikanUniqueResponse<AnimeVideo>> {
165
- return new Promise<JikanUniqueResponse<AnimeVideo>>((resolve, reject) => {
166
- const endpoint = `${AnimeEndpoints.AnimeVideos.replace('{id}', String(mal_id))}`;
167
- this.api
168
- .get<JikanUniqueResponse<AnimeVideo>>(endpoint)
169
- .then((response: CacheAxiosResponse<JikanUniqueResponse<AnimeVideo>>) => resolve(response.data))
170
- .catch((error: AxiosError<string>) => reject(error));
171
- });
172
- }
173
-
174
- /**
175
- * Get Episode Videos related to a specific Anime
176
- * @param mal_id The Anime ID
177
- * @returns A JikanResponse with AnimeVideoEpisode data
178
- */
179
- public async getAnimeVideosEpisode(mal_id: number): Promise<JikanResponse<AnimeVideoEpisode>> {
180
- return new Promise<JikanResponse<AnimeVideoEpisode>>((resolve, reject) => {
181
- const endpoint = `${AnimeEndpoints.AnimeVideosEpisodes.replace('{id}', String(mal_id))}`;
182
- this.api
183
- .get<JikanResponse<AnimeVideoEpisode>>(endpoint)
184
- .then((response: CacheAxiosResponse<JikanResponse<AnimeVideoEpisode>>) => resolve(response.data))
185
- .catch((error: AxiosError<string>) => reject(error));
186
- });
187
- }
188
-
189
- /**
190
- * Get Pictures related to a specific Anime
191
- * @param mal_id The Anime ID
192
- * @returns A JikanResponse with AnimePicture data
193
- */
194
- public async getAnimePictures(mal_id: number): Promise<JikanResponse<AnimePicture>> {
195
- return new Promise<JikanResponse<AnimePicture>>((resolve, reject) => {
196
- const endpoint = `${AnimeEndpoints.AnimePictures.replace('{id}', String(mal_id))}`;
197
- this.api
198
- .get<JikanResponse<AnimePicture>>(endpoint)
199
- .then((response: CacheAxiosResponse<JikanResponse<AnimePicture>>) => resolve(response.data))
200
- .catch((error: AxiosError<string>) => reject(error));
201
- });
202
- }
203
-
204
- /**
205
- * Get Statistics related to a specific Anime
206
- * @param mal_id The Anime ID
207
- * @returns A JikanUniqueResponse with AnimeStatistics data
208
- */
209
- public async getAnimeStatistics(mal_id: number): Promise<JikanUniqueResponse<AnimeStatistics>> {
210
- return new Promise<JikanUniqueResponse<AnimeStatistics>>((resolve, reject) => {
211
- const endpoint = `${AnimeEndpoints.AnimeStatistics.replace('{id}', String(mal_id))}`;
212
- this.api
213
- .get<JikanUniqueResponse<AnimeStatistics>>(endpoint)
214
- .then((response: CacheAxiosResponse<JikanUniqueResponse<AnimeStatistics>>) => resolve(response.data))
215
- .catch((error: AxiosError<string>) => reject(error));
216
- });
217
- }
218
-
219
- /**
220
- * Get Recommendations related to a specific Anime
221
- * @param mal_id The Anime ID
222
- * @returns A JikanResponse with Recommendation data
223
- */
224
- public async getAnimeRecommendation(mal_id: number): Promise<JikanResponse<Recommendation>> {
225
- return new Promise<JikanResponse<Recommendation>>((resolve, reject) => {
226
- const endpoint = `${AnimeEndpoints.AnimeRecommendations.replace('{id}', String(mal_id))}`;
227
- this.api
228
- .get<JikanResponse<Recommendation>>(endpoint)
229
- .then((response: CacheAxiosResponse<JikanResponse<Recommendation>>) => resolve(response.data))
230
- .catch((error: AxiosError<string>) => reject(error));
231
- });
232
- }
233
- }
@@ -1,82 +0,0 @@
1
- import { Logger, LoggerOptions } from 'pino';
2
- import {
3
- AxiosCacheInstance,
4
- CacheAxiosResponse,
5
- CacheOptions,
6
- CacheRequestConfig,
7
- setupCache,
8
- } from 'axios-cache-interceptor';
9
- import axios, { AxiosError } from 'axios';
10
- import { BaseURL } from '../constants';
11
- import {
12
- createLogger,
13
- DEFAULT_CACHE_OPTIONS,
14
- handleRequest,
15
- handleRequestError,
16
- handleResponse,
17
- handleResponseError,
18
- } from '../config';
19
-
20
- /**
21
- * **Client Args**
22
- * Used to pass optional configuration for logging and cache to the clients.
23
- */
24
- export interface ClientArgs {
25
- /**
26
- * **Logger Options**
27
- * Options for the client logger.
28
- * @see https://getpino.io/#/docs/api?id=options
29
- */
30
- logOptions?: LoggerOptions;
31
- /**
32
- * **Axios Cache Options**
33
- * Options for cache.
34
- * @see https://axios-cache-interceptor.js.org/#/pages/configuration
35
- */
36
- cacheOptions?: CacheOptions;
37
- /**
38
- * **Base URL**
39
- * Location of the JikanAPI. Leave empty to use the official JikanAPI instance.
40
- */
41
- baseURL?: string;
42
- }
43
-
44
- /**
45
- * **Base Client** This client is responsible for creating an Axios Instance and the cache and logging configurations
46
- */
47
- export abstract class BaseClient {
48
- public api: AxiosCacheInstance;
49
- public logger: Logger;
50
-
51
- constructor(clientOptions?: ClientArgs) {
52
- this.api = setupCache(
53
- axios.create({
54
- baseURL: clientOptions?.baseURL ?? BaseURL.REST,
55
- headers: {
56
- 'Content-Type': 'application/json',
57
- },
58
- }),
59
- {
60
- storage: clientOptions?.cacheOptions?.storage ?? DEFAULT_CACHE_OPTIONS.storage,
61
- generateKey: clientOptions?.cacheOptions?.generateKey ?? DEFAULT_CACHE_OPTIONS.generateKey,
62
- headerInterpreter: clientOptions?.cacheOptions?.headerInterpreter ?? DEFAULT_CACHE_OPTIONS.headerInterpreter,
63
- debug: clientOptions?.cacheOptions?.debug ?? DEFAULT_CACHE_OPTIONS.debug,
64
- }
65
- );
66
-
67
- this.logger = createLogger({
68
- enabled: !(clientOptions?.logOptions?.enabled === undefined || clientOptions?.logOptions.enabled === false),
69
- ...clientOptions?.logOptions,
70
- });
71
-
72
- this.api.interceptors.request.use(
73
- (config: CacheRequestConfig) => handleRequest(config, this.logger),
74
- (error: AxiosError<string>) => handleRequestError(error, this.logger)
75
- );
76
-
77
- this.api.interceptors.response.use(
78
- (response: CacheAxiosResponse) => handleResponse(response, this.logger),
79
- (error: AxiosError<string>) => handleResponseError(error, this.logger)
80
- );
81
- }
82
- }
@@ -1,4 +0,0 @@
1
- export * from './base.client';
2
- export * from './anime.client';
3
- export * from './manga.client';
4
- export * from './jikan.client';
@@ -1,28 +0,0 @@
1
- import { BaseClient, ClientArgs } from './base.client';
2
- import { AnimeClient } from './anime.client';
3
- import { MangaClient } from './manga.client';
4
- import { TopClient } from './top.client';
5
-
6
- /**
7
- * **Jikan Client**
8
- *
9
- * The main client used to access all the JikanAPI Endpoints:
10
- * - [Anime](https://docs.api.jikan.moe/#tag/anime)
11
- * - [Manga](https://docs.api.jikan.moe/#tag/manga)
12
- * - [Top](https://docs.api.jikan.moe/#tag/top)
13
- *
14
- * See also: [JikanAPI Documentation](https://docs.api.jikan.moe/)
15
- */
16
- export class JikanClient extends BaseClient {
17
- public anime: AnimeClient;
18
- public manga: MangaClient;
19
- public top: TopClient;
20
-
21
- constructor(clientOptions?: ClientArgs) {
22
- super(clientOptions);
23
-
24
- this.anime = new AnimeClient(clientOptions);
25
- this.manga = new MangaClient(clientOptions);
26
- this.top = new TopClient(clientOptions);
27
- }
28
- }
@@ -1,142 +0,0 @@
1
- import { BaseClient, ClientArgs } from './base.client';
2
- import { MangaEndpoints } from '../constants';
3
- import { CacheAxiosResponse } from 'axios-cache-interceptor';
4
- import { AxiosError } from 'axios';
5
- import {
6
- CommonCharacter,
7
- JikanImages,
8
- JikanResponse,
9
- JikanUniqueResponse,
10
- Manga,
11
- MangaStatistics,
12
- Recommendation,
13
- } from '../models';
14
- import { MangaSearchParams } from '../models/Params';
15
-
16
- /**
17
- * **Manga Client**
18
- *
19
- * Client used to access the Manga Endpoints:
20
- * - [MangaSearch](https://docs.api.jikan.moe/#tag/manga)
21
- * - [MangaFullById](https://docs.api.jikan.moe/#tag/manga/operation/getMangaFullById)
22
- * - [MangaById](https://docs.api.jikan.moe/#tag/manga/operation/getMangaById)
23
- * - [MangaCharacters](https://docs.api.jikan.moe/#tag/manga/operation/getMangaCharacters)
24
- * - [MangaPictures](https://docs.api.jikan.moe/#tag/manga/operation/getMangaPictures)
25
- * - [MangaStatistics](https://docs.api.jikan.moe/#tag/manga/operation/getMangaStatistics)
26
- * - [MangaRecommendations](https://docs.api.jikan.moe/#tag/manga/operation/getMangaRecommendations)
27
- *
28
- * See also: [JikanAPI Documentation](https://docs.api.jikan.moe/)
29
- */
30
- export class MangaClient extends BaseClient {
31
- /**
32
- * @argument clientOptions Options for the client.
33
- */
34
- constructor(clientOptions?: ClientArgs) {
35
- super(clientOptions);
36
- }
37
-
38
- /**
39
- * Get all the filtered Mangas. Returns all the Mangas if no filters are given.
40
- * @param searchParams Filter parameters
41
- * @returns A JikanResponse with Manga data
42
- */
43
- public async getMangaSearch(searchParams: MangaSearchParams): Promise<JikanResponse<Manga>> {
44
- return new Promise<JikanResponse<Manga>>((resolve, reject) => {
45
- const endpoint = `${MangaEndpoints.MangaSearch}`;
46
- this.api
47
- .get<JikanResponse<Manga>>(endpoint, { params: searchParams })
48
- .then((response: CacheAxiosResponse<JikanResponse<Manga>>) => resolve(response.data))
49
- .catch((error: AxiosError<string>) => reject(error));
50
- });
51
- }
52
-
53
- /**
54
- * Get a Manga with full information by its ID
55
- * @param mal_id The Manga ID
56
- * @returns A JikanUniqueResponse with Manga data
57
- */
58
- public async getMangaFullById(mal_id: number): Promise<JikanUniqueResponse<Manga>> {
59
- return new Promise<JikanUniqueResponse<Manga>>((resolve, reject) => {
60
- const endpoint = `${MangaEndpoints.MangaFullById.replace('{id}', String(mal_id))}`;
61
- this.api
62
- .get<JikanUniqueResponse<Manga>>(endpoint)
63
- .then((response: CacheAxiosResponse<JikanUniqueResponse<Manga>>) => resolve(response.data))
64
- .catch((error: AxiosError<string>) => reject(error));
65
- });
66
- }
67
-
68
- /**
69
- * Get a Manga by its ID
70
- * @param mal_id The Manga ID
71
- * @returns A JikanUniqueResponse with Manga data
72
- */
73
- public async getMangaById(mal_id: number): Promise<JikanUniqueResponse<Manga>> {
74
- return new Promise<JikanUniqueResponse<Manga>>((resolve, reject) => {
75
- const endpoint = `${MangaEndpoints.MangaById.replace('{id}', String(mal_id))}`;
76
- this.api
77
- .get<JikanUniqueResponse<Manga>>(endpoint)
78
- .then((response: CacheAxiosResponse<JikanUniqueResponse<Manga>>) => resolve(response.data))
79
- .catch((error: AxiosError<string>) => reject(error));
80
- });
81
- }
82
-
83
- /**
84
- * Get Characters of a specific Manga
85
- * @param mal_id The Manga ID
86
- * @returns A JikanResponse with CommonCharacter data
87
- */
88
- public async getMangaCharacters(mal_id: number): Promise<JikanResponse<CommonCharacter>> {
89
- return new Promise<JikanResponse<CommonCharacter>>((resolve, reject) => {
90
- const endpoint = `${MangaEndpoints.MangaCharacters.replace('{id}', String(mal_id))}`;
91
- this.api
92
- .get<JikanResponse<CommonCharacter>>(endpoint)
93
- .then((response: CacheAxiosResponse<JikanResponse<CommonCharacter>>) => resolve(response.data))
94
- .catch((error: AxiosError<string>) => reject(error));
95
- });
96
- }
97
-
98
- /**
99
- * Get Pictures related to a specific Manga
100
- * @param mal_id The Manga ID
101
- * @returns A JikanResponse with JikanImages data
102
- */
103
- public async getMangaPictures(mal_id: number): Promise<JikanResponse<JikanImages>> {
104
- return new Promise<JikanResponse<JikanImages>>((resolve, reject) => {
105
- const endpoint = `${MangaEndpoints.MangaPictures.replace('{id}', String(mal_id))}`;
106
- this.api
107
- .get<JikanResponse<JikanImages>>(endpoint)
108
- .then((response: CacheAxiosResponse<JikanResponse<JikanImages>>) => resolve(response.data))
109
- .catch((error: AxiosError<string>) => reject(error));
110
- });
111
- }
112
-
113
- /**
114
- * Get Statistics related to a specific Manga
115
- * @param mal_id The Manga ID
116
- * @returns A JikanUniqueResponse with MangaStatistics data
117
- */
118
- public async getAnimeStatistics(mal_id: number): Promise<JikanUniqueResponse<MangaStatistics>> {
119
- return new Promise<JikanUniqueResponse<MangaStatistics>>((resolve, reject) => {
120
- const endpoint = `${MangaEndpoints.MangaStatistics.replace('{id}', String(mal_id))}`;
121
- this.api
122
- .get<JikanUniqueResponse<MangaStatistics>>(endpoint)
123
- .then((response: CacheAxiosResponse<JikanUniqueResponse<MangaStatistics>>) => resolve(response.data))
124
- .catch((error: AxiosError<string>) => reject(error));
125
- });
126
- }
127
-
128
- /**
129
- * Get Recommendations related to a specific Manga
130
- * @param mal_id The Manga ID
131
- * @returns A JikanResponse with Recommendation data
132
- */
133
- public async getMangaRecommendation(mal_id: number): Promise<JikanResponse<Recommendation>> {
134
- return new Promise<JikanResponse<Recommendation>>((resolve, reject) => {
135
- const endpoint = `${MangaEndpoints.MangaRecommendations.replace('{id}', String(mal_id))}`;
136
- this.api
137
- .get<JikanResponse<Recommendation>>(endpoint)
138
- .then((response: CacheAxiosResponse<JikanResponse<Recommendation>>) => resolve(response.data))
139
- .catch((error: AxiosError<string>) => reject(error));
140
- });
141
- }
142
- }
@@ -1,52 +0,0 @@
1
- import { BaseClient, ClientArgs } from './base.client';
2
- import { Anime, JikanResponse, Manga } from '../models';
3
- import { TopEndpoints } from '../constants';
4
- import { CacheAxiosResponse } from 'axios-cache-interceptor';
5
- import { AxiosError } from 'axios';
6
- import { AnimeTopParams, MangaTopParams } from '../models/Params';
7
-
8
- /**
9
- * **Anime Client**
10
- *
11
- * Client used to access the Top Endpoints:
12
- * - [TopAnime](https://docs.api.jikan.moe/#tag/top/operation/getTopAnime)
13
- * - [TopManga](https://docs.api.jikan.moe/#tag/top/operation/getTopManga)
14
- *
15
- * See also: [JikanAPI Documentation](https://docs.api.jikan.moe/)
16
- */
17
- export class TopClient extends BaseClient {
18
- /**
19
- * @argument clientOptions Options for the client.
20
- */
21
- constructor(clientOptions?: ClientArgs) {
22
- super(clientOptions);
23
- }
24
-
25
- /**
26
- * Get the top Animes
27
- * @returns A JikanResponse with Anime data
28
- */
29
- public async getTopAnime(searchParams: AnimeTopParams): Promise<JikanResponse<Anime>> {
30
- return new Promise<JikanResponse<Anime>>((resolve, reject) => {
31
- const endpoint = `${TopEndpoints.TopAnime}`;
32
- this.api
33
- .get<JikanResponse<Anime>>(endpoint, { params: searchParams })
34
- .then((response: CacheAxiosResponse<JikanResponse<Anime>>) => resolve(response.data))
35
- .catch((error: AxiosError<string>) => reject(error));
36
- });
37
- }
38
-
39
- /**
40
- * Get the top Mangas
41
- * @returns A JikanResponse with Manga data
42
- */
43
- public async getTopManga(searchParams: MangaTopParams): Promise<JikanResponse<Manga>> {
44
- return new Promise<JikanResponse<Manga>>((resolve, reject) => {
45
- const endpoint = `${TopEndpoints.TopManga}`;
46
- this.api
47
- .get<JikanResponse<Manga>>(endpoint, { params: searchParams })
48
- .then((response: CacheAxiosResponse<JikanResponse<Manga>>) => resolve(response.data))
49
- .catch((error: AxiosError<string>) => reject(error));
50
- });
51
- }
52
- }
@@ -1,8 +0,0 @@
1
- import { buildMemoryStorage, defaultHeaderInterpreter, defaultKeyGenerator } from 'axios-cache-interceptor';
2
-
3
- export const DEFAULT_CACHE_OPTIONS = {
4
- storage: buildMemoryStorage(),
5
- generateKey: defaultKeyGenerator,
6
- headerInterpreter: defaultHeaderInterpreter,
7
- debug: undefined,
8
- };
@@ -1,2 +0,0 @@
1
- export * from './cache.config';
2
- export * from './logger.config';
@@ -1,25 +0,0 @@
1
- import pino, { DestinationStream, Logger, LoggerOptions } from 'pino';
2
- import { AxiosError } from 'axios';
3
- import { CacheAxiosResponse, CacheRequestConfig } from 'axios-cache-interceptor';
4
-
5
- export const createLogger = (options: LoggerOptions | DestinationStream): Logger => pino(options);
6
-
7
- export const handleRequest = (config: CacheRequestConfig, logger: Logger): CacheRequestConfig => {
8
- logger.info(`[ Request Config ] ${config.method?.toUpperCase() || ''} | ${config.url || ''}`);
9
- return config;
10
- };
11
-
12
- export const handleRequestError = (error: AxiosError, logger: Logger): Promise<AxiosError> => {
13
- logger.error(`[ Request Error] CODE ${error.code || 'UNKNOWN'} | ${error.message}`);
14
- throw error;
15
- };
16
-
17
- export const handleResponse = (response: CacheAxiosResponse, logger: Logger): CacheAxiosResponse => {
18
- logger.info(response.data);
19
- return response;
20
- };
21
-
22
- export const handleResponseError = (error: AxiosError, logger: Logger): Promise<AxiosError> => {
23
- logger.error(`[ Response Error ] CODE ${error.code || 'UNKNOWN'} | ${error.message}`);
24
- throw error;
25
- };
@@ -1,3 +0,0 @@
1
- export enum BaseURL {
2
- REST = 'https://api.jikan.moe/v4',
3
- }