ani-client 2.0.1 → 2.0.3

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
@@ -446,6 +446,13 @@ var RELATIONS_FIELDS = `
446
446
  averageScore
447
447
  studios { nodes { id name isAnimationStudio siteUrl } }
448
448
  siteUrl
449
+ nextAiringEpisode {
450
+ id
451
+ airingAt
452
+ episode
453
+ mediaId
454
+ timeUntilAiring
455
+ }
449
456
  }
450
457
  }
451
458
  }
@@ -965,6 +972,44 @@ query ($id: Int!) {
965
972
  }
966
973
  }`;
967
974
  }
975
+ function buildMediaCharactersQuery(options = {}) {
976
+ const sortClause = options.sort === false ? "" : ", sort: [ROLE, RELEVANCE, ID]";
977
+ const voiceActorBlock = options.voiceActors ? `
978
+ voiceActors {
979
+ ${VOICE_ACTOR_FIELDS_COMPACT}
980
+ }` : "";
981
+ return `
982
+ query ($mediaId: Int!, $page: Int, $perPage: Int) {
983
+ Media(id: $mediaId) {
984
+ characters(page: $page, perPage: $perPage${sortClause}) {
985
+ pageInfo { total perPage currentPage lastPage hasNextPage }
986
+ edges {
987
+ role
988
+ node {
989
+ ${CHARACTER_FIELDS_COMPACT}
990
+ }${voiceActorBlock}
991
+ }
992
+ }
993
+ }
994
+ }`;
995
+ }
996
+ function buildMediaStaffQuery(options = {}) {
997
+ const sortClause = options.sort === false ? "" : ", sort: [RELEVANCE, ID]";
998
+ return `
999
+ query ($mediaId: Int!, $page: Int, $perPage: Int) {
1000
+ Media(id: $mediaId) {
1001
+ staff(page: $page, perPage: $perPage${sortClause}) {
1002
+ pageInfo { total perPage currentPage lastPage hasNextPage }
1003
+ edges {
1004
+ role
1005
+ node {
1006
+ ${STAFF_FIELDS}
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+ }`;
1012
+ }
968
1013
  function buildBatchQuery(ids, typeName, fields, prefix) {
969
1014
  const aliases = ids.map((id, i) => `${prefix}${i}: ${typeName}(id: ${id}) { ${fields} }`).join("\n ");
970
1015
  return `query {
@@ -1617,6 +1662,25 @@ async function getMedia(client, id, include) {
1617
1662
  const data = await client.request(query, { id });
1618
1663
  return data.Media;
1619
1664
  }
1665
+ async function getMediaCharacters(client, mediaId, options = {}) {
1666
+ validateId(mediaId, "mediaId");
1667
+ const query = buildMediaCharactersQuery(options);
1668
+ const data = await client.request(
1669
+ query,
1670
+ { mediaId, page: options.page ?? 1, perPage: clampPerPage(options.perPage ?? 25) }
1671
+ );
1672
+ return { pageInfo: data.Media.characters.pageInfo, results: data.Media.characters.edges };
1673
+ }
1674
+ async function getMediaStaff(client, mediaId, options = {}) {
1675
+ validateId(mediaId, "mediaId");
1676
+ const query = buildMediaStaffQuery(options);
1677
+ const data = await client.request(query, {
1678
+ mediaId,
1679
+ page: options.page ?? 1,
1680
+ perPage: clampPerPage(options.perPage ?? 25)
1681
+ });
1682
+ return { pageInfo: data.Media.staff.pageInfo, results: data.Media.staff.edges };
1683
+ }
1620
1684
  async function getMediaByMalId(client, malId, type) {
1621
1685
  validateId(malId, "malId");
1622
1686
  const data = await client.request(QUERY_MEDIA_BY_MAL_ID, {
@@ -1901,7 +1965,7 @@ function mapFavorites(fav) {
1901
1965
 
1902
1966
  // src/client/index.ts
1903
1967
  var DEFAULT_API_URL = "https://graphql.anilist.co";
1904
- var LIB_VERSION = "2.0.1" ;
1968
+ var LIB_VERSION = "2.0.3" ;
1905
1969
  var AniListClient = class {
1906
1970
  apiUrl;
1907
1971
  headers;
@@ -2044,6 +2108,12 @@ var AniListClient = class {
2044
2108
  async getMedia(id, include) {
2045
2109
  return getMedia(this, id, include);
2046
2110
  }
2111
+ async getMediaCharacters(mediaId, options = {}) {
2112
+ return getMediaCharacters(this, mediaId, options);
2113
+ }
2114
+ async getMediaStaff(mediaId, options = {}) {
2115
+ return getMediaStaff(this, mediaId, options);
2116
+ }
2047
2117
  /**
2048
2118
  * Search for anime or manga.
2049
2119
  *
@@ -2078,7 +2148,7 @@ var AniListClient = class {
2078
2148
  return getRecentlyUpdatedManga(this, options);
2079
2149
  }
2080
2150
  /**
2081
- * @deprecated Use `getRecentlyUpdatedManga` instead. This alias will be removed in v2.
2151
+ * @deprecated Use `getRecentlyUpdatedManga()` instead. This alias will be removed in v3.
2082
2152
  */
2083
2153
  async getAiredChapters(options = {}) {
2084
2154
  return this.getRecentlyUpdatedManga(options);