anilink-api-wrapper 1.28.0 → 1.29.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 CHANGED
@@ -55,6 +55,20 @@ const aniLink = new AniLink();
55
55
 
56
56
  AniLink for AniList is divided into two main sections: `anilist.query` and `anilist.mutation`. The `anilist.query` section contains methods for querying data from the AniList API, while the `anilist.mutation` section contains methods for mutating data.
57
57
 
58
+ #### Custom Queries and Mutations
59
+
60
+ If needed there is a custom section `anilist.custom` that allows the user to pass a custom query or mutation to the AniList API.
61
+
62
+ The method accepts two parameters: the query or mutation string and an optional variables object.
63
+
64
+ ```typescript
65
+ const viewer = await aniLink.anilist.custom('query {Viewer {id}}');
66
+
67
+ const mutation = 'mutation ($about: String) {UpdateUser (about: $about) {id}}';
68
+ const variables = { about: "New about text" };
69
+ const response = await aniLink.anilist.custom(mutation, variables);
70
+ ```
71
+
58
72
  #### Query Methods
59
73
 
60
74
  The `anilist.query` section is further divided into main query methods and page query methods. The main query methods return a single piece of data, while the page query methods return pages of data.
package/dist/AniLink.js CHANGED
@@ -72,6 +72,7 @@ const SaveThreadComment_1 = require("./apis/anilist/mutation/SaveThreadComment")
72
72
  const DeleteThreadComment_1 = require("./apis/anilist/mutation/DeleteThreadComment");
73
73
  const UpdateAniChartSettings_1 = require("./apis/anilist/mutation/UpdateAniChartSettings");
74
74
  const UpdateAniChartHighlights_1 = require("./apis/anilist/mutation/UpdateAniChartHighlights");
75
+ const Custom_1 = require("./apis/anilist/Custom");
75
76
  /**
76
77
  * `AniLink` is a class for interacting with the APIs.
77
78
  * It provides methods for querying and mutating data.
@@ -89,6 +90,7 @@ class AniLink {
89
90
  * ```
90
91
  */
91
92
  constructor(authToken) {
93
+ const customInstance = new Custom_1.CustomRequest(authToken);
92
94
  const userQueryInstance = new User_1.UserQuery(authToken);
93
95
  const mediaQueryInstance = new Media_1.MediaQuery(authToken);
94
96
  const mediaTrendQueryInstance = new MediaTrend_1.MediaTrendQuery(authToken);
@@ -161,6 +163,7 @@ class AniLink {
161
163
  const updateAniChartSettingsMutationInstance = new UpdateAniChartSettings_1.UpdateAniChartSettingsMutation(authToken);
162
164
  const updateAniChartHighlightsMutationInstance = new UpdateAniChartHighlights_1.UpdateAniChartHighlightsMutation(authToken);
163
165
  this.anilist = {
166
+ custom: customInstance.custom.bind(customInstance),
164
167
  query: {
165
168
  user: userQueryInstance.user.bind(userQueryInstance),
166
169
  media: mediaQueryInstance.media.bind(mediaQueryInstance),
@@ -0,0 +1,42 @@
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.CustomRequest = void 0;
13
+ const APIWrapper_1 = require("../../base/APIWrapper");
14
+ const RequestHandler_1 = require("../../base/RequestHandler");
15
+ /**
16
+ * `CustomRequest` is a class representing a custom query or mutation by the user.
17
+ */
18
+ class CustomRequest extends APIWrapper_1.APIWrapper {
19
+ /**
20
+ * Constructs a new `ActivityQuery` instance.
21
+ *
22
+ * @param authToken - The authentication token.
23
+ */
24
+ constructor(authToken) {
25
+ super('https://graphql.anilist.co');
26
+ this.authToken = authToken;
27
+ }
28
+ /**
29
+ * `custom` is a method that sends a custom query or mutation by the user.
30
+ *
31
+ * @param query - The query for the request.
32
+ * @param variables - The variables for the request. This parameter is optional.
33
+ * @returns The response from the query request.
34
+ */
35
+ custom(query_1) {
36
+ return __awaiter(this, arguments, void 0, function* (query, variables = {}) {
37
+ const data = { query, variables };
38
+ return yield (0, RequestHandler_1.sendRequest)(this.baseURL, 'POST', data, this.authToken);
39
+ });
40
+ }
41
+ }
42
+ exports.CustomRequest = CustomRequest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anilink-api-wrapper",
3
- "version": "1.28.0",
3
+ "version": "1.29.0",
4
4
  "description": "API wrapper for AniManga sites such as Anilist, MyAnimeList, Kitsu.",
5
5
  "main": "dist/AniLink.js",
6
6
  "scripts": {