Skip to content

Commit

Permalink
Merge pull request #17 from tutkli/next
Browse files Browse the repository at this point in the history
next
  • Loading branch information
tutkli authored Jan 26, 2025
2 parents 605681a + fa93b36 commit 08181e3
Show file tree
Hide file tree
Showing 50 changed files with 480 additions and 152 deletions.
5 changes: 4 additions & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"*.{js,ts,css,scss,html,json,md}": "biome format --write ./src"
"*.{js,ts,css,scss,html,json,md}": [
"biome format --write ./src",
"biome check --write --unsafe ./src"
]
}
22 changes: 0 additions & 22 deletions .npmignore

This file was deleted.

25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,30 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v2.1.0](https://github.com/tutkli/jikan-ts/compare/v2.1.0...v2.1.0)
#### [v2.2.0](https://github.com/tutkli/jikan-ts/compare/v2.1.0...v2.2.0)

- feat: add axios cache configuration and integrate in clients [`#18`](https://github.com/tutkli/jikan-ts/pull/18)
- build: use bun as builder and test runner [`#14`](https://github.com/tutkli/jikan-ts/pull/14)
- feat: add ClubsClient [`d115e77`](https://github.com/tutkli/jikan-ts/commit/d115e77bbda651fc97f38fe1f1ae652109fca55d)
- build: replace tsup and vitest with bun [`601c3b1`](https://github.com/tutkli/jikan-ts/commit/601c3b1634582d93f3ca6c0d2051ac82aaaa8807)
- feat: add WatchClient with endpoints and models for watch API [`038de99`](https://github.com/tutkli/jikan-ts/commit/038de99e1ac4b90fdd10306305d3c92069c0cacb)
- refactor: reorganize imports and restructure module exports [`bf3e463`](https://github.com/tutkli/jikan-ts/commit/bf3e46381b107473cb2c137cec9ff0e3b8f974a3)
- feat: add MagazinesClient [`b3b268e`](https://github.com/tutkli/jikan-ts/commit/b3b268e8dcf37aecb18405ef345f460e07e47d90)
- refactor: relocate endpoint files to their own directory [`80decdb`](https://github.com/tutkli/jikan-ts/commit/80decdb75f744ea45438f59256fbddd37198a5e8)
- refactor: update "club" to "clubs" [`91d343f`](https://github.com/tutkli/jikan-ts/commit/91d343f6c98d52b849bd3ace26f0d84eff07a258)
- style: run biome linter [`4667eba`](https://github.com/tutkli/jikan-ts/commit/4667eba88ca7e7cc5b23cf45135d7aae43b21f0d)
- chore: generate changelog [`e12ac05`](https://github.com/tutkli/jikan-ts/commit/e12ac05b2fde0c5bdd55c8ac64b5dd7043f9236a)
- docs: update README [`2cd8aa1`](https://github.com/tutkli/jikan-ts/commit/2cd8aa16a366bdec5cbd1ddde39197fd41585a9b)
- chore: include dist, README, and LICENSE in package files [`3adc0a7`](https://github.com/tutkli/jikan-ts/commit/3adc0a7633d3fdf6ba9409f7b7802b40e6b8456e)
- refactor: remove vitest configuration file [`7b31390`](https://github.com/tutkli/jikan-ts/commit/7b313908ef5427d862f7a89c30e45ecd2a6e363d)
- refactor: rename BaseURL to BASE_URL and remove redundant config [`6c2b74f`](https://github.com/tutkli/jikan-ts/commit/6c2b74f771110b4a422526f1d6de23b075892a82)
- chore: run biome check in lintstaged [`2482df8`](https://github.com/tutkli/jikan-ts/commit/2482df89bed25130ea346f24b7c323238bac1c41)
- fix(watch.client): correct parameter handling in promo fetch [`ad166b9`](https://github.com/tutkli/jikan-ts/commit/ad166b9284da5ff2417577681c7745dfa298411a)
- feat: add WatchClient to Jikan client [`f7d8900`](https://github.com/tutkli/jikan-ts/commit/f7d890058a978c96f1756569cb69cb50be9adf94)
- feat: enforce `noUnusedImports` rule in linter config [`a34f8c2`](https://github.com/tutkli/jikan-ts/commit/a34f8c2bea263f062159cc21674d9b5ad833b21c)
- chore(deps): update lint-staged and typescript [`de8f7f5`](https://github.com/tutkli/jikan-ts/commit/de8f7f5517f4370c91c407d2a08d3f35a1621af3)
- chore: bump version to 2.2.0 [`1763ffc`](https://github.com/tutkli/jikan-ts/commit/1763ffceed0634e16071d6d474b9669a94003649)
- fix: use correct trailingCommas key in biome config [`5fbce96`](https://github.com/tutkli/jikan-ts/commit/5fbce9693077e186c88c05fb5ed53b7067c9e52d)

#### [v2.1.0](https://github.com/tutkli/jikan-ts/compare/v2.0.2...v2.1.0)

Expand Down
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

</p>

> Jikan API wrapper for Typescript and Node.js with built-in typings.
> Jikan API wrapper for TypeScript and Node.js with built-in typing.
## Features

Expand Down Expand Up @@ -75,7 +75,7 @@ const animeClient = new AnimeClient({
);
```

### Custom Axios instance
### Custom Axios Instance

Jikan uses `axios` as an `http` client and if you are not satisfied with the default client settings, then you can build your instance by passing it to the optional `axiosInstance` argument

Expand Down Expand Up @@ -105,15 +105,23 @@ const animeClient = new AnimeClient({

## Available Clients

- AnimeClient
- CharactersClient
- GenresClient
- MangaClient
- TopClient
- SchedulesClient
- SeasonsClient
- RandomClient
- JikanClient (Main client)
- [X] AnimeClient
- [X] CharactersClient
- [X] ClubsClient
- [X] GenresClient
- [X] MagazinesClient
- [X] MangaClient
- [ ] PeopleClient
- [ ] ProducersClient
- [X] RandomClient
- [ ] RecommendationsClient
- [ ] ReviewsClient
- [X] SchedulesClient
- [ ] UsersClient
- [X] SeasonsClient
- [X] TopClient
- [X] WatchClient
- [X] **JikanClient (Main client)**

## Leave you feedback

Expand Down
7 changes: 5 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true
"recommended": true,
"correctness": {
"noUnusedImports": "error"
}
},
"ignore": ["lib"]
},
Expand All @@ -23,7 +26,7 @@
"quoteStyle": "single",
"semicolons": "asNeeded",
"bracketSpacing": true,
"trailingComma": "none",
"trailingCommas": "none",
"arrowParentheses": "asNeeded"
}
}
Expand Down
Binary file modified bun.lockb
Binary file not shown.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tutkli/jikan-ts",
"version": "2.1.0",
"version": "2.2.0",
"description": "Node.js wrapper for the Jikan API with built-in typings.",
"source": "src/index.ts",
"main": "dist/index.js",
Expand All @@ -15,10 +15,10 @@
"version": "auto-changelog -p -l false && git add CHANGELOG.md",
"format": "biome format ./src",
"format:fix": "biome format --write ./src",
"lint": "biome check src",
"lint:ci": "biome ci src",
"lint:fix": "biome check --apply-unsafe ./src"
"lint": "biome check ./src",
"lint:fix": "biome check --write --unsafe ./src"
},
"files": ["dist/", "README.md", "LICENSE"],
"repository": {
"type": "git",
"url": "https://github.com/tutkli/jikan-ts.git"
Expand All @@ -45,7 +45,7 @@
"axios": "^1.7.9",
"axios-cache-interceptor": "^1.6.2",
"bun-plugin-dts": "^0.3.0",
"lint-staged": "^15.2.11",
"typescript": "5.7.2"
"lint-staged": "^15.4.2",
"typescript": "5.7.3"
}
}
2 changes: 1 addition & 1 deletion src/__tests__/anime-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, beforeEach, describe, expect, it } from 'bun:test'
import { AnimeClient } from '../clients'
import { AnimeClient } from '../clients/anime.client'
import type { AnimeSearchParams } from '../models'

describe('test Anime Client', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/genres-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { beforeAll, beforeEach, describe, expect, it } from 'bun:test'
import { GenresClient } from '../clients'
import { type Genre, GenresFilter, type JikanResponse } from '../models'
import { GenresClient } from '../clients/genres.client'
import type { Genre, JikanResponse } from '../models'

describe('test Genres Client', () => {
let client: GenresClient
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/manga-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { beforeAll, beforeEach, describe, expect, it } from 'bun:test'
import { MangaClient } from '../clients'
import { MangaClient } from '../clients/manga.client'
import type {
CommonCharacter,
JikanImages,
Expand Down
16 changes: 7 additions & 9 deletions src/__tests__/seasons-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { beforeAll, beforeEach, describe, expect, it } from 'bun:test'
import { SeasonsClient } from '../clients'
import {
type Anime,
AnimeSeason,
AnimeStatus,
type JikanResponse,
type JikanSeasonsParams,
type SeasonNowParams,
type SeasonsListData
import { SeasonsClient } from '../clients/seasons.client'
import type {
Anime,
JikanResponse,
JikanSeasonsParams,
SeasonNowParams,
SeasonsListData
} from '../models'

describe('test Seasons Client', () => {
Expand Down
18 changes: 7 additions & 11 deletions src/__tests__/top-client.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { beforeAll, beforeEach, describe, expect, it } from 'bun:test'
import { TopClient } from '../clients'
import {
type Anime,
AnimeStatus,
type AnimeTopParams,
type JikanResponse,
type Manga,
MangaStatus,
type MangaTopParams,
TopAnimeFilter,
TopMangaFilter
import { TopClient } from '../clients/top.client'
import type {
Anime,
AnimeTopParams,
JikanResponse,
Manga,
MangaTopParams
} from '../models'

describe('test Top Client', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/clients/anime.client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnimeEndpoints } from '../constants'
import { AnimeEndpoints } from '../endpoints/anime.endpoints'
import type {
Anime,
AnimeCharacter,
Expand Down
44 changes: 14 additions & 30 deletions src/clients/base.client.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import axios, { AxiosInstance, type AxiosError } from 'axios'
import {
type AxiosCacheInstance,
type CacheAxiosResponse,
type CacheOptions,
type InternalCacheRequestConfig,
setupCache
import type { AxiosError, AxiosInstance } from 'axios'
import type {
AxiosCacheInstance,
CacheAxiosResponse,
CacheOptions,
InternalCacheRequestConfig
} from 'axios-cache-interceptor'
import { getAxiosCacheInstance } from '../config/axios.config'
import {
handleRequest,
handleRequestError,
handleResponse,
handleResponseError
} from '../config'
import { BaseURL } from '../constants'
} from '../config/logging.config'
import type { JikanResponse } from '../models'

/**
Expand All @@ -32,17 +31,11 @@ export interface ClientArgs {
* @see https://axios-cache-interceptor.js.org/#/pages/configuration
*/
cacheOptions: Partial<CacheOptions>
/**
* **Base URL**
* Location of the JikanAPI. Leave empty to use the official JikanAPI instance.
*/
baseURL: string

/**
* **Axios Instance**
* Еhe ability to build your own axios instance if you need it
* The ability to build your own axios instance if you need it
*/
axiosInstance?: AxiosInstance
axiosInstance?: AxiosInstance | AxiosCacheInstance
}

/**
Expand All @@ -54,19 +47,10 @@ export abstract class BaseClient {
private api: AxiosCacheInstance

constructor(clientOptions: Partial<ClientArgs> = {}) {
const axiosInstance = clientOptions?.axiosInstance
? clientOptions.axiosInstance
: axios.create({
baseURL: clientOptions.baseURL ?? BaseURL,
headers: {
'Content-Type': 'application/json'
}
})

this.api = setupCache(axiosInstance, {
...clientOptions.cacheOptions,
cacheTakeover: false
})
this.api = getAxiosCacheInstance(
clientOptions.axiosInstance,
clientOptions.cacheOptions
)

if (clientOptions.enableLogging) {
this.addLoggingInterceptors()
Expand Down
2 changes: 1 addition & 1 deletion src/clients/characters.client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CharactersEndpoints } from '../constants'
import { CharactersEndpoints } from '../endpoints/characters.endpoints'
import type {
Character,
CharacterAnime,
Expand Down
63 changes: 63 additions & 0 deletions src/clients/clubs.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ClubsEndpoints } from '../endpoints/clubs.enpoints'
import type { ClubSearchParams } from '../models/clubs/clubs-params.model'
import type {
Club,
ClubMember,
ClubRelations,
ClubStaff
} from '../models/clubs/clubs.model'
import { BaseClient } from './base.client'

/**
* **Club Client**
*
* Client used to access the Club Endpoints.
*
* See also: [Jikan Documentation](https://docs.api.jikan.moe/)
*/
export class ClubsClient extends BaseClient {
/**
* @returns Club resource
* @param id Club ID
*/
public getClubsById(id: number) {
return this.getResource<Club>(ClubsEndpoints.clubById, { id })
}

/**
* @returns Club members resource
* @param id Club ID
* @param params
*/
public getClubMembers(id: number, params: Partial<{ page: number }> = {}) {
return this.getResource<ClubMember[]>(
ClubsEndpoints.clubMembers,
{ id },
params
)
}

/**
* @returns Club staff
* @param id Club ID
*/
public getClubStaff(id: number) {
return this.getResource<ClubStaff[]>(ClubsEndpoints.clubStaff, { id })
}

/**
* @returns Club relations
* @param id Club ID
*/
public getClubRelations(id: number) {
return this.getResource<ClubRelations>(ClubsEndpoints.clubRelations, { id })
}

/**
* @returns Search results for Clubs
* @param params
*/
public getClubSearch(params: Partial<ClubSearchParams> = {}) {
return this.getResource<Club[]>(ClubsEndpoints.clubSearch, {}, params)
}
}
2 changes: 1 addition & 1 deletion src/clients/genres.client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GenresEndpoints } from '../constants'
import { GenresEndpoints } from '../endpoints/genres.endpoints'
import type { Genre, GenresFilter } from '../models'
import { BaseClient } from './base.client'

Expand Down
10 changes: 0 additions & 10 deletions src/clients/index.ts

This file was deleted.

Loading

0 comments on commit 08181e3

Please sign in to comment.