ani-client 1.8.1 → 2.0.0

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.
package/dist/index.mjs CHANGED
@@ -434,7 +434,17 @@ var RELATIONS_FIELDS = `
434
434
  type
435
435
  format
436
436
  status
437
- coverImage { large medium }
437
+ startDate { year month day }
438
+ endDate { year month day }
439
+ season
440
+ seasonYear
441
+ episodes
442
+ chapters
443
+ volumes
444
+ coverImage { extraLarge large medium color }
445
+ genres
446
+ averageScore
447
+ studios { nodes { id name isAnimationStudio siteUrl } }
438
448
  siteUrl
439
449
  }
440
450
  }
@@ -711,8 +721,10 @@ query ($id: Int!) {
711
721
  var QUERY_MEDIA_SEARCH = `
712
722
  query (
713
723
  $search: String,
724
+ $countryOfOrigin: CountryCode,
714
725
  $type: MediaType,
715
726
  $format: MediaFormat,
727
+ $format_in: [MediaFormat],
716
728
  $status: MediaStatus,
717
729
  $season: MediaSeason,
718
730
  $seasonYear: Int,
@@ -731,8 +743,10 @@ query (
731
743
  pageInfo { total perPage currentPage lastPage hasNextPage }
732
744
  media(
733
745
  search: $search,
746
+ countryOfOrigin: $countryOfOrigin,
734
747
  type: $type,
735
748
  format: $format,
749
+ format_in: $format_in,
736
750
  status: $status,
737
751
  season: $season,
738
752
  seasonYear: $seasonYear,
@@ -750,16 +764,16 @@ query (
750
764
  }
751
765
  }`;
752
766
  var QUERY_TRENDING = `
753
- query ($type: MediaType, $page: Int, $perPage: Int) {
767
+ query ($type: MediaType, $isAdult: Boolean, $page: Int, $perPage: Int) {
754
768
  Page(page: $page, perPage: $perPage) {
755
769
  pageInfo { total perPage currentPage lastPage hasNextPage }
756
- media(type: $type, sort: TRENDING_DESC) {
770
+ media(type: $type, isAdult: $isAdult, sort: TRENDING_DESC) {
757
771
  ${MEDIA_FIELDS_BASE}
758
772
  }
759
773
  }
760
774
  }`;
761
775
  var QUERY_AIRING_SCHEDULE = `
762
- query ($airingAt_greater: Int, $airingAt_lesser: Int, $sort: [AiringSort], $page: Int, $perPage: Int) {
776
+ query ($airingAt_greater: Int, $airingAt_lesser: Int, $isAdult: Boolean, $sort: [AiringSort], $page: Int, $perPage: Int) {
763
777
  Page(page: $page, perPage: $perPage) {
764
778
  pageInfo { total perPage currentPage lastPage hasNextPage }
765
779
  airingSchedules(airingAt_greater: $airingAt_greater, airingAt_lesser: $airingAt_lesser, sort: $sort) {
@@ -768,35 +782,49 @@ query ($airingAt_greater: Int, $airingAt_lesser: Int, $sort: [AiringSort], $page
768
782
  timeUntilAiring
769
783
  episode
770
784
  mediaId
771
- media {
785
+ media(isAdult: $isAdult) {
772
786
  ${MEDIA_FIELDS_BASE}
773
787
  }
774
788
  }
775
789
  }
776
790
  }`;
777
791
  var QUERY_RECENT_CHAPTERS = `
778
- query ($page: Int, $perPage: Int) {
792
+ query ($isAdult: Boolean $page: Int, $perPage: Int) {
779
793
  Page(page: $page, perPage: $perPage) {
780
794
  pageInfo { total perPage currentPage lastPage hasNextPage }
781
- media(type: MANGA, status: RELEASING, sort: UPDATED_AT_DESC) {
795
+ media(type: MANGA, isAdult: $isAdult status: RELEASING, sort: UPDATED_AT_DESC) {
782
796
  ${MEDIA_FIELDS_BASE}
783
797
  }
784
798
  }
785
799
  }`;
786
800
  var QUERY_PLANNING = `
787
- query ($type: MediaType, $sort: [MediaSort], $page: Int, $perPage: Int) {
801
+ query ($type: MediaType, $isAdult: Boolean, $sort: [MediaSort], $page: Int, $perPage: Int) {
788
802
  Page(page: $page, perPage: $perPage) {
789
803
  pageInfo { total perPage currentPage lastPage hasNextPage }
790
- media(type: $type, status: NOT_YET_RELEASED, sort: $sort) {
804
+ media(type: $type, isAdult: $isAdult, status: NOT_YET_RELEASED, sort: $sort) {
791
805
  ${MEDIA_FIELDS_BASE}
792
806
  }
793
807
  }
794
808
  }`;
795
809
  var QUERY_MEDIA_BY_SEASON = `
796
- query ($season: MediaSeason!, $seasonYear: Int!, $type: MediaType, $sort: [MediaSort], $page: Int, $perPage: Int) {
810
+ query (
811
+ $season: MediaSeason!,
812
+ $seasonYear: Int!,
813
+ $type: MediaType,
814
+ $isAdult: Boolean,
815
+ $sort: [MediaSort],
816
+ $page: Int,
817
+ $perPage: Int
818
+ ) {
797
819
  Page(page: $page, perPage: $perPage) {
798
820
  pageInfo { total perPage currentPage lastPage hasNextPage }
799
- media(season: $season, seasonYear: $seasonYear, type: $type, sort: $sort) {
821
+ media(
822
+ season: $season,
823
+ seasonYear: $seasonYear,
824
+ type: $type,
825
+ isAdult: $isAdult,
826
+ sort: $sort
827
+ ) {
800
828
  ${MEDIA_FIELDS_BASE}
801
829
  }
802
830
  }
@@ -1195,7 +1223,7 @@ var RateLimiter = class {
1195
1223
  /** @internal — active sleep timers for cleanup */
1196
1224
  activeTimers = /* @__PURE__ */ new Set();
1197
1225
  constructor(options = {}) {
1198
- this.maxRequests = options.maxRequests ?? 85;
1226
+ this.maxRequests = options.maxRequests ?? 25;
1199
1227
  this.windowMs = options.windowMs ?? 6e4;
1200
1228
  this.maxRetries = options.maxRetries ?? 3;
1201
1229
  this.retryDelayMs = options.retryDelayMs ?? 2e3;
@@ -1598,12 +1626,24 @@ async function getMediaByMalId(client, malId, type) {
1598
1626
  return data.Media;
1599
1627
  }
1600
1628
  async function searchMedia(client, options = {}) {
1601
- const { query: search, page = 1, perPage = 20, genres, tags, genresExclude, tagsExclude, ...filters } = options;
1629
+ const {
1630
+ query: search,
1631
+ page = 1,
1632
+ perPage = 20,
1633
+ genres,
1634
+ tags,
1635
+ genresExclude,
1636
+ tagsExclude,
1637
+ format,
1638
+ ...filters
1639
+ } = options;
1602
1640
  return client.pagedRequest(
1603
1641
  QUERY_MEDIA_SEARCH,
1604
1642
  {
1605
1643
  search,
1606
1644
  ...filters,
1645
+ format: Array.isArray(format) ? void 0 : format,
1646
+ format_in: Array.isArray(format) ? format : void 0,
1607
1647
  genre_in: genres,
1608
1648
  tag_in: tags,
1609
1649
  genre_not_in: genresExclude,
@@ -1614,14 +1654,17 @@ async function searchMedia(client, options = {}) {
1614
1654
  "media"
1615
1655
  );
1616
1656
  }
1617
- async function getTrending(client, type = "ANIME" /* ANIME */, page = 1, perPage = 20) {
1618
- return client.pagedRequest(QUERY_TRENDING, { type, page, perPage: clampPerPage(perPage) }, "media");
1657
+ async function getTrending(client, options) {
1658
+ const { type = "ANIME" /* ANIME */, isAdult = false, page = 1, perPage = 20 } = options;
1659
+ return client.pagedRequest(QUERY_TRENDING, { type, isAdult, page, perPage: clampPerPage(perPage) }, "media");
1619
1660
  }
1620
- async function getPopular(client, type = "ANIME" /* ANIME */, page = 1, perPage = 20) {
1621
- return searchMedia(client, { type, sort: ["POPULARITY_DESC" /* POPULARITY_DESC */], page, perPage });
1661
+ async function getPopular(client, options) {
1662
+ const { type = "ANIME" /* ANIME */, isAdult = false, page = 1, perPage = 20 } = options;
1663
+ return searchMedia(client, { type, isAdult, sort: ["POPULARITY_DESC" /* POPULARITY_DESC */], page, perPage });
1622
1664
  }
1623
- async function getTopRated(client, type = "ANIME" /* ANIME */, page = 1, perPage = 20) {
1624
- return searchMedia(client, { type, sort: ["SCORE_DESC" /* SCORE_DESC */], page, perPage });
1665
+ async function getTopRated(client, options) {
1666
+ const { type = "ANIME" /* ANIME */, isAdult = false, page = 1, perPage = 20 } = options;
1667
+ return searchMedia(client, { type, isAdult, sort: ["SCORE_DESC" /* SCORE_DESC */], page, perPage });
1625
1668
  }
1626
1669
  async function getAiredEpisodes(client, options = {}) {
1627
1670
  const now = Math.floor(Date.now() / 1e3);
@@ -1630,6 +1673,7 @@ async function getAiredEpisodes(client, options = {}) {
1630
1673
  {
1631
1674
  airingAt_greater: options.airingAtGreater ?? now - 24 * 3600,
1632
1675
  airingAt_lesser: options.airingAtLesser ?? now,
1676
+ isAdult: options.isAdult ?? false,
1633
1677
  sort: options.sort,
1634
1678
  page: options.page ?? 1,
1635
1679
  perPage: clampPerPage(options.perPage ?? 20)
@@ -1641,6 +1685,7 @@ async function getRecentlyUpdatedManga(client, options = {}) {
1641
1685
  return client.pagedRequest(
1642
1686
  QUERY_RECENT_CHAPTERS,
1643
1687
  {
1688
+ isAdult: options.isAdult ?? false,
1644
1689
  page: options.page ?? 1,
1645
1690
  perPage: clampPerPage(options.perPage ?? 20)
1646
1691
  },
@@ -1652,6 +1697,7 @@ async function getPlanning(client, options = {}) {
1652
1697
  QUERY_PLANNING,
1653
1698
  {
1654
1699
  type: options.type,
1700
+ isAdult: options.isAdult ?? false,
1655
1701
  sort: options.sort ?? ["POPULARITY_DESC" /* POPULARITY_DESC */],
1656
1702
  page: options.page ?? 1,
1657
1703
  perPage: clampPerPage(options.perPage ?? 20)
@@ -1679,6 +1725,7 @@ async function getMediaBySeason(client, options) {
1679
1725
  season: options.season,
1680
1726
  seasonYear: options.seasonYear,
1681
1727
  type: options.type,
1728
+ isAdult: options.isAdult ?? false,
1682
1729
  sort: options.sort,
1683
1730
  page: options.page ?? 1,
1684
1731
  perPage: clampPerPage(options.perPage ?? 20)
@@ -1686,7 +1733,7 @@ async function getMediaBySeason(client, options) {
1686
1733
  "media"
1687
1734
  );
1688
1735
  }
1689
- async function getWeeklySchedule(client, date = /* @__PURE__ */ new Date()) {
1736
+ async function getWeeklySchedule(client, date = /* @__PURE__ */ new Date(), isAdult = false) {
1690
1737
  const schedule = {
1691
1738
  Monday: [],
1692
1739
  Tuesday: [],
@@ -1708,6 +1755,7 @@ async function getWeeklySchedule(client, date = /* @__PURE__ */ new Date()) {
1708
1755
  (page) => getAiredEpisodes(client, {
1709
1756
  airingAtGreater: startTimestamp,
1710
1757
  airingAtLesser: endTimestamp,
1758
+ isAdult,
1711
1759
  page,
1712
1760
  perPage: 50
1713
1761
  }),
@@ -1853,7 +1901,7 @@ function mapFavorites(fav) {
1853
1901
 
1854
1902
  // src/client/index.ts
1855
1903
  var DEFAULT_API_URL = "https://graphql.anilist.co";
1856
- var LIB_VERSION = "1.8.1" ;
1904
+ var LIB_VERSION = "2.0.0" ;
1857
1905
  var AniListClient = class {
1858
1906
  apiUrl;
1859
1907
  headers;
@@ -2006,16 +2054,16 @@ var AniListClient = class {
2006
2054
  return searchMedia(this, options);
2007
2055
  }
2008
2056
  /** Get currently trending anime or manga. */
2009
- async getTrending(type, page, perPage) {
2010
- return getTrending(this, type, page, perPage);
2057
+ async getTrending(options = {}) {
2058
+ return getTrending(this, options);
2011
2059
  }
2012
2060
  /** Get the most popular anime or manga. */
2013
- async getPopular(type, page, perPage) {
2014
- return getPopular(this, type, page, perPage);
2061
+ async getPopular(options = {}) {
2062
+ return getPopular(this, options);
2015
2063
  }
2016
2064
  /** Get the highest-rated anime or manga. */
2017
- async getTopRated(type, page, perPage) {
2018
- return getTopRated(this, type, page, perPage);
2065
+ async getTopRated(options = {}) {
2066
+ return getTopRated(this, options);
2019
2067
  }
2020
2068
  /** Get recently aired anime episodes. */
2021
2069
  async getAiredEpisodes(options = {}) {