ani-client 2.0.2 → 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/README.md +7 -0
- package/dist/index.d.mts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +65 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -972,6 +972,44 @@ query ($id: Int!) {
|
|
|
972
972
|
}
|
|
973
973
|
}`;
|
|
974
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
|
+
}
|
|
975
1013
|
function buildBatchQuery(ids, typeName, fields, prefix) {
|
|
976
1014
|
const aliases = ids.map((id, i) => `${prefix}${i}: ${typeName}(id: ${id}) { ${fields} }`).join("\n ");
|
|
977
1015
|
return `query {
|
|
@@ -1624,6 +1662,25 @@ async function getMedia(client, id, include) {
|
|
|
1624
1662
|
const data = await client.request(query, { id });
|
|
1625
1663
|
return data.Media;
|
|
1626
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
|
+
}
|
|
1627
1684
|
async function getMediaByMalId(client, malId, type) {
|
|
1628
1685
|
validateId(malId, "malId");
|
|
1629
1686
|
const data = await client.request(QUERY_MEDIA_BY_MAL_ID, {
|
|
@@ -1908,7 +1965,7 @@ function mapFavorites(fav) {
|
|
|
1908
1965
|
|
|
1909
1966
|
// src/client/index.ts
|
|
1910
1967
|
var DEFAULT_API_URL = "https://graphql.anilist.co";
|
|
1911
|
-
var LIB_VERSION = "2.0.
|
|
1968
|
+
var LIB_VERSION = "2.0.3" ;
|
|
1912
1969
|
var AniListClient = class {
|
|
1913
1970
|
apiUrl;
|
|
1914
1971
|
headers;
|
|
@@ -2051,6 +2108,12 @@ var AniListClient = class {
|
|
|
2051
2108
|
async getMedia(id, include) {
|
|
2052
2109
|
return getMedia(this, id, include);
|
|
2053
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
|
+
}
|
|
2054
2117
|
/**
|
|
2055
2118
|
* Search for anime or manga.
|
|
2056
2119
|
*
|
|
@@ -2085,7 +2148,7 @@ var AniListClient = class {
|
|
|
2085
2148
|
return getRecentlyUpdatedManga(this, options);
|
|
2086
2149
|
}
|
|
2087
2150
|
/**
|
|
2088
|
-
* @deprecated Use `getRecentlyUpdatedManga` instead. This alias will be removed in
|
|
2151
|
+
* @deprecated Use `getRecentlyUpdatedManga()` instead. This alias will be removed in v3.
|
|
2089
2152
|
*/
|
|
2090
2153
|
async getAiredChapters(options = {}) {
|
|
2091
2154
|
return this.getRecentlyUpdatedManga(options);
|