anilink-api-wrapper 1.25.0 → 1.27.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/README.md +6 -0
- package/dist/AniLink.js +19 -1
- package/dist/apis/anilist/interfaces/responses/mutation/Favourites.js +83 -0
- package/dist/apis/anilist/mutation/DeleteReview.js +61 -0
- package/dist/apis/anilist/mutation/SaveRecommendation.js +66 -0
- package/dist/apis/anilist/mutation/SaveReview.js +68 -0
- package/dist/apis/anilist/mutation/ToggleFavourite.js +66 -0
- package/dist/apis/anilist/mutation/ToggleFollow.js +62 -0
- package/dist/apis/anilist/mutation/UpdateFavouriteOrder.js +73 -0
- package/dist/apis/anilist/types/RecommendationRating.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -126,6 +126,12 @@ List of methods in `anilist.mutation`:
|
|
|
126
126
|
- deleteActivityReply
|
|
127
127
|
- toggleLike
|
|
128
128
|
- toggleLikeV2
|
|
129
|
+
- toggleFollow
|
|
130
|
+
- toggleFavourite
|
|
131
|
+
- updateFavouriteOrder
|
|
132
|
+
- saveReview
|
|
133
|
+
- deleteReview
|
|
134
|
+
- saveRecommendation
|
|
129
135
|
|
|
130
136
|
### Error Handling
|
|
131
137
|
|
package/dist/AniLink.js
CHANGED
|
@@ -59,6 +59,12 @@ const SaveActivityReply_1 = require("./apis/anilist/mutation/SaveActivityReply")
|
|
|
59
59
|
const DeleteActivityReply_1 = require("./apis/anilist/mutation/DeleteActivityReply");
|
|
60
60
|
const ToggleLike_1 = require("./apis/anilist/mutation/ToggleLike");
|
|
61
61
|
const ToggleLikeV2_1 = require("./apis/anilist/mutation/ToggleLikeV2");
|
|
62
|
+
const ToggleFollow_1 = require("./apis/anilist/mutation/ToggleFollow");
|
|
63
|
+
const ToggleFavourite_1 = require("./apis/anilist/mutation/ToggleFavourite");
|
|
64
|
+
const UpdateFavouriteOrder_1 = require("./apis/anilist/mutation/UpdateFavouriteOrder");
|
|
65
|
+
const SaveReview_1 = require("./apis/anilist/mutation/SaveReview");
|
|
66
|
+
const DeleteReview_1 = require("./apis/anilist/mutation/DeleteReview");
|
|
67
|
+
const SaveRecommendation_1 = require("./apis/anilist/mutation/SaveRecommendation");
|
|
62
68
|
/**
|
|
63
69
|
* `AniLink` is a class for interacting with the APIs.
|
|
64
70
|
* It provides methods for querying and mutating data.
|
|
@@ -134,6 +140,12 @@ class AniLink {
|
|
|
134
140
|
const deleteActivityReplyMutationInstance = new DeleteActivityReply_1.DeleteActivityReplyMutation(authToken);
|
|
135
141
|
const toggleLikeMutationInstance = new ToggleLike_1.ToggleLikeMutation(authToken);
|
|
136
142
|
const toggleLikeV2MutationInstance = new ToggleLikeV2_1.ToggleLikeV2Mutation(authToken);
|
|
143
|
+
const toggleFollowMutationInstance = new ToggleFollow_1.ToggleFollowMutation(authToken);
|
|
144
|
+
const toggleFavouriteMutationInstance = new ToggleFavourite_1.ToggleFavouriteMutation(authToken);
|
|
145
|
+
const updateFavouriteOrderMutationInstance = new UpdateFavouriteOrder_1.UpdateFavouriteOrderMutation(authToken);
|
|
146
|
+
const saveReviewMutationInstance = new SaveReview_1.SaveReviewMutation(authToken);
|
|
147
|
+
const deleteReviewMutationInstance = new DeleteReview_1.DeleteReviewMutation(authToken);
|
|
148
|
+
const saveRecommendationMutationInstance = new SaveRecommendation_1.SaveRecommendationMutation(authToken);
|
|
137
149
|
this.anilist = {
|
|
138
150
|
query: {
|
|
139
151
|
user: userQueryInstance.user.bind(userQueryInstance),
|
|
@@ -197,7 +209,13 @@ class AniLink {
|
|
|
197
209
|
saveActivityReply: saveActivityReplyMutationInstance.saveActivityReply.bind(saveActivityReplyMutationInstance),
|
|
198
210
|
deleteActivityReply: deleteActivityReplyMutationInstance.deleteActivityReply.bind(deleteActivityReplyMutationInstance),
|
|
199
211
|
toggleLike: toggleLikeMutationInstance.toggleLike.bind(toggleLikeMutationInstance),
|
|
200
|
-
toggleLikeV2: toggleLikeV2MutationInstance.toggleLikeV2.bind(toggleLikeV2MutationInstance)
|
|
212
|
+
toggleLikeV2: toggleLikeV2MutationInstance.toggleLikeV2.bind(toggleLikeV2MutationInstance),
|
|
213
|
+
toggleFollow: toggleFollowMutationInstance.toggleFollow.bind(toggleFollowMutationInstance),
|
|
214
|
+
toggleFavourite: toggleFavouriteMutationInstance.toggleFavourite.bind(toggleFavouriteMutationInstance),
|
|
215
|
+
updateFavouriteOrder: updateFavouriteOrderMutationInstance.updateFavouriteOrder.bind(updateFavouriteOrderMutationInstance),
|
|
216
|
+
saveReview: saveReviewMutationInstance.saveReview.bind(saveReviewMutationInstance),
|
|
217
|
+
deleteReview: deleteReviewMutationInstance.deleteReview.bind(deleteReviewMutationInstance),
|
|
218
|
+
saveRecommendation: saveRecommendationMutationInstance.saveRecommendation.bind(saveRecommendationMutationInstance)
|
|
201
219
|
}
|
|
202
220
|
};
|
|
203
221
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FavouritesSchema = void 0;
|
|
4
|
+
const Title_1 = require("../../Title");
|
|
5
|
+
/**
|
|
6
|
+
* `FavouritesSchema` is a constant representing the GraphQL schema for a favourites query.
|
|
7
|
+
* It includes the anime, manga, characters, staff, and studios schema.
|
|
8
|
+
*/
|
|
9
|
+
exports.FavouritesSchema = `
|
|
10
|
+
anime {
|
|
11
|
+
edges {
|
|
12
|
+
id
|
|
13
|
+
node {
|
|
14
|
+
id
|
|
15
|
+
${Title_1.TitleSchema}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
nodes {
|
|
19
|
+
id
|
|
20
|
+
${Title_1.TitleSchema}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
manga {
|
|
24
|
+
edges {
|
|
25
|
+
id
|
|
26
|
+
node {
|
|
27
|
+
id
|
|
28
|
+
${Title_1.TitleSchema}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
nodes {
|
|
32
|
+
id
|
|
33
|
+
${Title_1.TitleSchema}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
characters {
|
|
37
|
+
edges {
|
|
38
|
+
id
|
|
39
|
+
node {
|
|
40
|
+
id
|
|
41
|
+
name {
|
|
42
|
+
full
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
nodes {
|
|
47
|
+
id
|
|
48
|
+
name {
|
|
49
|
+
full
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
staff {
|
|
54
|
+
edges {
|
|
55
|
+
id
|
|
56
|
+
node {
|
|
57
|
+
id
|
|
58
|
+
name {
|
|
59
|
+
full
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
nodes {
|
|
64
|
+
id
|
|
65
|
+
name {
|
|
66
|
+
full
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
studios {
|
|
71
|
+
edges {
|
|
72
|
+
id
|
|
73
|
+
node {
|
|
74
|
+
id
|
|
75
|
+
name
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
nodes {
|
|
79
|
+
id
|
|
80
|
+
name
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DeleteReviewMutation = void 0;
|
|
13
|
+
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
14
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
15
|
+
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
16
|
+
/**
|
|
17
|
+
* `DeleteReviewMutation` is a class representing a mutation to delete a review.
|
|
18
|
+
* It includes a method to delete a review.
|
|
19
|
+
*/
|
|
20
|
+
class DeleteReviewMutation extends APIWrapper_1.APIWrapper {
|
|
21
|
+
/**
|
|
22
|
+
* Constructs a new `DeleteReviewMutation` instance.
|
|
23
|
+
*
|
|
24
|
+
* @param authToken - The authentication token.
|
|
25
|
+
*/
|
|
26
|
+
constructor(authToken) {
|
|
27
|
+
super('https://graphql.anilist.co');
|
|
28
|
+
this.authToken = authToken;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* `deleteReview` is a method that sends a mutation request to delete a review.
|
|
32
|
+
*
|
|
33
|
+
* @param variables - An object of type `DeleteReviewVariables` representing the variables for the mutation.
|
|
34
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
35
|
+
* @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
|
|
36
|
+
*/
|
|
37
|
+
deleteReview(variables) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (!this.authToken) {
|
|
40
|
+
throw new Error('DeleteReviewMutation requires an authentication token. Create a new instance of AniLink and pass the token as an argument.');
|
|
41
|
+
}
|
|
42
|
+
if (!variables.id) {
|
|
43
|
+
throw new Error('id variable is required');
|
|
44
|
+
}
|
|
45
|
+
const variableTypeMappings = {
|
|
46
|
+
id: 'number'
|
|
47
|
+
};
|
|
48
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
49
|
+
const mutation = `
|
|
50
|
+
mutation ($id: Int) {
|
|
51
|
+
DeleteReview(id: $id) {
|
|
52
|
+
deleted
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
const data = { query: mutation, variables };
|
|
57
|
+
return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.DeleteReviewMutation = DeleteReviewMutation;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SaveRecommendationMutation = void 0;
|
|
13
|
+
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
14
|
+
const Recommendation_1 = require("../interfaces/responses/query/Recommendation");
|
|
15
|
+
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
16
|
+
const RecommendationRating_1 = require("../types/RecommendationRating");
|
|
17
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
18
|
+
/**
|
|
19
|
+
* `SaveRecommendationMutation` is a class representing a mutation to save a recommendation.
|
|
20
|
+
* It includes a method to save a recommendation.
|
|
21
|
+
*/
|
|
22
|
+
class SaveRecommendationMutation extends APIWrapper_1.APIWrapper {
|
|
23
|
+
/**
|
|
24
|
+
* Constructs a new `SaveRecommendationMutation` instance.
|
|
25
|
+
*
|
|
26
|
+
* @param authToken - The authentication token.
|
|
27
|
+
*/
|
|
28
|
+
constructor(authToken) {
|
|
29
|
+
super('https://graphql.anilist.co');
|
|
30
|
+
this.authToken = authToken;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `saveReview` is a method that sends a mutation request to save a recommendation.
|
|
34
|
+
*
|
|
35
|
+
* @param variables - An object of type `SaveRecommendationVariables` representing the variables for the mutation.
|
|
36
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
37
|
+
* @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
|
|
38
|
+
*/
|
|
39
|
+
saveRecommendation(variables) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (!this.authToken) {
|
|
42
|
+
throw new Error('SaveReviewMutation requires an authentication token. Create a new instance of AniLink and pass the token as an argument.');
|
|
43
|
+
}
|
|
44
|
+
if (!variables.mediaId || !variables.mediaRecommendationId || !variables.rating) {
|
|
45
|
+
throw new Error('mediaId, mediaRecommendationId, and rating variables are required.');
|
|
46
|
+
}
|
|
47
|
+
const variableTypeMappings = {
|
|
48
|
+
mediaId: 'number',
|
|
49
|
+
mediaRecommendationId: 'number',
|
|
50
|
+
rating: RecommendationRating_1.RecommendationRatingMappings,
|
|
51
|
+
asHtml: 'boolean'
|
|
52
|
+
};
|
|
53
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
54
|
+
const mutation = `
|
|
55
|
+
mutation ($mediaId: Int, $mediaRecommendationId: Int, $rating: RecommendationRating, $asHtml: Boolean) {
|
|
56
|
+
SaveRecommendation(mediaId: $mediaId, mediaRecommendationId: $mediaRecommendationId, rating: $rating) {
|
|
57
|
+
${Recommendation_1.RecommendationSchema}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
const data = { query: mutation, variables };
|
|
62
|
+
return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.SaveRecommendationMutation = SaveRecommendationMutation;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SaveReviewMutation = void 0;
|
|
13
|
+
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
14
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
15
|
+
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
16
|
+
const Review_1 = require("../interfaces/responses/query/Review");
|
|
17
|
+
/**
|
|
18
|
+
* `SaveReviewMutation` is a class representing a mutation to save a review.
|
|
19
|
+
* It includes a method to save a review.
|
|
20
|
+
*/
|
|
21
|
+
class SaveReviewMutation extends APIWrapper_1.APIWrapper {
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a new `SaveReviewMutation` instance.
|
|
24
|
+
*
|
|
25
|
+
* @param authToken - The authentication token.
|
|
26
|
+
*/
|
|
27
|
+
constructor(authToken) {
|
|
28
|
+
super('https://graphql.anilist.co');
|
|
29
|
+
this.authToken = authToken;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `saveReview` is a method that sends a mutation request to save a review.
|
|
33
|
+
*
|
|
34
|
+
* @param variables - An object of type `SaveReviewVariables` representing the variables for the mutation.
|
|
35
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
36
|
+
* @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
|
|
37
|
+
*/
|
|
38
|
+
saveReview(variables) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!this.authToken) {
|
|
41
|
+
throw new Error('SaveReviewMutation requires an authentication token. Create a new instance of AniLink and pass the token as an argument.');
|
|
42
|
+
}
|
|
43
|
+
if (!variables.id && !variables.mediaId) {
|
|
44
|
+
throw new Error('id or mediaId variable is required');
|
|
45
|
+
}
|
|
46
|
+
const variableTypeMappings = {
|
|
47
|
+
id: 'number',
|
|
48
|
+
mediaId: 'number',
|
|
49
|
+
body: 'string',
|
|
50
|
+
summary: 'string',
|
|
51
|
+
score: 'number',
|
|
52
|
+
private: 'boolean',
|
|
53
|
+
asHtml: 'boolean'
|
|
54
|
+
};
|
|
55
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
56
|
+
const mutation = `
|
|
57
|
+
mutation ($id: Int, $mediaId: Int, $body: String, $summary: String, $score: Int, $private: Boolean, $asHtml: Boolean) {
|
|
58
|
+
SaveReview(id: $id, mediaId: $mediaId, body: $body, summary: $summary, score: $score, private: $private) {
|
|
59
|
+
${Review_1.ReviewSchema}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
const data = { query: mutation, variables };
|
|
64
|
+
return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.SaveReviewMutation = SaveReviewMutation;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ToggleFavouriteMutation = void 0;
|
|
13
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
14
|
+
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
15
|
+
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
16
|
+
const Favourites_1 = require("../interfaces/responses/mutation/Favourites");
|
|
17
|
+
/**
|
|
18
|
+
* `ToggleFavouriteMutation` is a class that contains the method to toggle a favourite.
|
|
19
|
+
* It includes a method to toggle a favourite.
|
|
20
|
+
*/
|
|
21
|
+
class ToggleFavouriteMutation extends APIWrapper_1.APIWrapper {
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a new `ToggleFavouriteMutation` instance.
|
|
24
|
+
*
|
|
25
|
+
* @param authToken - The authentication token.
|
|
26
|
+
*/
|
|
27
|
+
constructor(authToken) {
|
|
28
|
+
super('https://graphql.anilist.co');
|
|
29
|
+
this.authToken = authToken;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `toggleFavourite` is a method that sends a mutation request to toggle a favourite.
|
|
33
|
+
*
|
|
34
|
+
* @param variables - An object of type `ToggleFavouriteVariables` representing the variables for the mutation.
|
|
35
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
36
|
+
* @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
|
|
37
|
+
*/
|
|
38
|
+
toggleFavourite(variables) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!this.authToken) {
|
|
41
|
+
throw new Error('ToggleFavouriteMutation requires an authentication token. Create a new instance of AniLink and pass the token as an argument.');
|
|
42
|
+
}
|
|
43
|
+
if (!variables.animeId && !variables.mangaId && !variables.characterId && !variables.staffId && !variables.studioId) {
|
|
44
|
+
throw new Error('animeId, mangaId, characterId, staffId, or studioId variable is required');
|
|
45
|
+
}
|
|
46
|
+
const variableTypeMappings = {
|
|
47
|
+
animeId: 'number',
|
|
48
|
+
mangaId: 'number',
|
|
49
|
+
characterId: 'number',
|
|
50
|
+
staffId: 'number',
|
|
51
|
+
studioId: 'number'
|
|
52
|
+
};
|
|
53
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
54
|
+
const mutation = `
|
|
55
|
+
mutation ($animeId: Int, $mangaId: Int, $characterId: Int, $staffId: Int, $studioId: Int) {
|
|
56
|
+
ToggleFavourite (animeId: $animeId, mangaId: $mangaId, characterId: $characterId, staffId: $staffId, studioId: $studioId) {
|
|
57
|
+
${Favourites_1.FavouritesSchema}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
const data = { query: mutation, variables };
|
|
62
|
+
return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.ToggleFavouriteMutation = ToggleFavouriteMutation;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ToggleFollowMutation = void 0;
|
|
13
|
+
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
14
|
+
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
15
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
16
|
+
const Basic_1 = require("../interfaces/Basic");
|
|
17
|
+
/**
|
|
18
|
+
* `ToggleFollowMutation` is a class representing a mutation to toggle a follow.
|
|
19
|
+
* It includes a method to toggle a follow.
|
|
20
|
+
*/
|
|
21
|
+
class ToggleFollowMutation extends APIWrapper_1.APIWrapper {
|
|
22
|
+
/**
|
|
23
|
+
* Constructs a new `ToggleFollowMutation` instance.
|
|
24
|
+
*
|
|
25
|
+
* @param authToken - The authentication token.
|
|
26
|
+
*/
|
|
27
|
+
constructor(authToken) {
|
|
28
|
+
super('https://graphql.anilist.co');
|
|
29
|
+
this.authToken = authToken;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* `ToggleFollow` is a method that sends a mutation request to toggle a follow.
|
|
33
|
+
*
|
|
34
|
+
* @param variables - An object of type `ToggleFollowVariables` representing the variables for the mutation.
|
|
35
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
36
|
+
* @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
|
|
37
|
+
* */
|
|
38
|
+
toggleFollow(variables) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!this.authToken) {
|
|
41
|
+
throw new Error('ToggleFollowMutation requires an authentication token. Create a new instance of AniLink and pass the token as an argument.');
|
|
42
|
+
}
|
|
43
|
+
if (!variables.userId) {
|
|
44
|
+
throw new Error('userId variable is required');
|
|
45
|
+
}
|
|
46
|
+
const variableTypeMappings = {
|
|
47
|
+
userId: 'number'
|
|
48
|
+
};
|
|
49
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
50
|
+
const mutation = `
|
|
51
|
+
mutation ($userId: Int) {
|
|
52
|
+
ToggleFollow (userId: $userId) {
|
|
53
|
+
${Basic_1.BasicUserSchema}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
const data = { query: mutation, variables };
|
|
58
|
+
return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ToggleFollowMutation = ToggleFollowMutation;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.UpdateFavouriteOrderMutation = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* `UpdateFavouriteOrderVariables` is an interface that contains the variables that are required to update the order of the favourite anime/manga.
|
|
15
|
+
*/
|
|
16
|
+
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
17
|
+
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
18
|
+
const Favourites_1 = require("../interfaces/responses/mutation/Favourites");
|
|
19
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
20
|
+
/**
|
|
21
|
+
* `UpdateFavouriteOrderMutation` is a class that contains the method to update the order of the favourites.
|
|
22
|
+
* It includes a method to update the order of the favourites.
|
|
23
|
+
*/
|
|
24
|
+
class UpdateFavouriteOrderMutation extends APIWrapper_1.APIWrapper {
|
|
25
|
+
/**
|
|
26
|
+
* Constructs a new `UpdateFavouriteOrderMutation` instance.
|
|
27
|
+
*
|
|
28
|
+
* @param authToken - The authentication token.
|
|
29
|
+
*/
|
|
30
|
+
constructor(authToken) {
|
|
31
|
+
super('https://graphql.anilist.co');
|
|
32
|
+
this.authToken = authToken;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* `updateFavouriteOrder` is a method that sends a mutation request to update the order of the favourites.
|
|
36
|
+
*
|
|
37
|
+
* @param variables - An object of type `UpdateFavouriteOrderVariables` representing the variables for the mutation.
|
|
38
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
39
|
+
*/
|
|
40
|
+
updateFavouriteOrder(variables) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
if (!this.authToken) {
|
|
43
|
+
throw new Error('ToggleFavouriteMutation requires an authentication token. Create a new instance of AniLink and pass the token as an argument.');
|
|
44
|
+
}
|
|
45
|
+
if ((!variables.animeIds && variables.animeOrder) || (!variables.mangaIds && variables.mangaOrder) || (!variables.characterIds && variables.characterOrder) || (!variables.staffIds && variables.staffOrder) || (!variables.studioIds && variables.studioOrder)) {
|
|
46
|
+
throw new Error('The order array requires the corresponding id array to be present.');
|
|
47
|
+
}
|
|
48
|
+
const variableTypeMappings = {
|
|
49
|
+
animeIds: 'number[]',
|
|
50
|
+
mangaIds: 'number[]',
|
|
51
|
+
characterIds: 'number[]',
|
|
52
|
+
staffIds: 'number[]',
|
|
53
|
+
studioIds: 'number[]',
|
|
54
|
+
animeOrder: 'number[]',
|
|
55
|
+
mangaOrder: 'number[]',
|
|
56
|
+
characterOrder: 'number[]',
|
|
57
|
+
staffOrder: 'number[]',
|
|
58
|
+
studioOrder: 'number[]'
|
|
59
|
+
};
|
|
60
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
61
|
+
const mutation = `
|
|
62
|
+
mutation ($animeIds: [Int], $mangaIds: [Int], $characterIds: [Int], $staffIds: [Int], $studioIds: [Int], $animeOrder: [Int], $mangaOrder: [Int], $characterOrder: [Int], $staffOrder: [Int], $studioOrder: [Int]) {
|
|
63
|
+
UpdateFavouriteOrder (animeIds: $animeIds, mangaIds: $mangaIds, characterIds: $characterIds, staffIds: $staffIds, studioIds: $studioIds, animeOrder: $animeOrder, mangaOrder: $mangaOrder, characterOrder: $characterOrder, staffOrder: $staffOrder, studioOrder: $studioOrder) {
|
|
64
|
+
${Favourites_1.FavouritesSchema}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
const data = { query: mutation, variables };
|
|
69
|
+
return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.UpdateFavouriteOrderMutation = UpdateFavouriteOrderMutation;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RecommendationRatingMappings = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `RecommendationRatingMappings` is a mapping of `RecommendationRating` enum values to their corresponding string values.
|
|
6
|
+
* It can be one of the following: 'NO_RATING', 'RATE_UP', 'RATE_DOWN'.
|
|
7
|
+
*/
|
|
8
|
+
exports.RecommendationRatingMappings = [
|
|
9
|
+
'NO_RATING',
|
|
10
|
+
'RATE_UP',
|
|
11
|
+
'RATE_DOWN'
|
|
12
|
+
];
|