anilink-api-wrapper 1.17.6 → 1.18.1

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.
@@ -12,6 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.UpdateUserMutation = void 0;
13
13
  const APIWrapper_1 = require("../../../base/APIWrapper");
14
14
  const RequestHandler_1 = require("../../../base/RequestHandler");
15
+ const ScoreFormat_1 = require("../types/ScoreFormat");
16
+ const UserStaffNameLanguage_1 = require("../types/UserStaffNameLanguage");
17
+ const UserTitleLanguage_1 = require("../types/UserTitleLanguage");
18
+ const ValidateVariables_1 = require("../../../base/ValidateVariables");
19
+ const NotificationOptions_1 = require("../types/NotificationOptions");
20
+ const MediaListOptions_1 = require("../types/MediaListOptions");
21
+ const DisabledListActivity_1 = require("../types/DisabledListActivity");
15
22
  /**
16
23
  * `UpdateUserMutation` is a class representing a mutation to update a user.
17
24
  * It includes a method to update a user.
@@ -29,11 +36,31 @@ class UpdateUserMutation extends APIWrapper_1.APIWrapper {
29
36
  /**
30
37
  * `updateUser` is a method that sends a mutation request to update a user.
31
38
  *
32
- * @param variables - The variables for the mutation.
33
- * @returns The response from the mutation request.
39
+ * @param variables - An object of type `UpdateUserVariables` representing the variables for the mutation.
40
+ * @returns A Promise that resolves to an object of type `UpdateUserResponse`. This object includes the updated user details
41
+ * @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
34
42
  */
35
43
  updateUser(variables) {
36
44
  return __awaiter(this, void 0, void 0, function* () {
45
+ const variableTypeMappings = {
46
+ about: 'string',
47
+ titleLanguage: UserTitleLanguage_1.UserTitleLanguageMapping,
48
+ displayAdultContent: 'boolean',
49
+ airingNotifications: 'boolean',
50
+ scoreFormat: ScoreFormat_1.ScoreFormatMapping,
51
+ rowOrder: 'string',
52
+ profileColor: 'string',
53
+ donatorBadge: 'string',
54
+ notificationOptions: NotificationOptions_1.NotificationOptionsMapping,
55
+ timezone: 'string',
56
+ activityMergeTime: 'number',
57
+ animeListOptions: MediaListOptions_1.MediaListOptionsMapping,
58
+ mangaListOptions: MediaListOptions_1.MediaListOptionsMapping,
59
+ staffNameLanguage: UserStaffNameLanguage_1.UserStaffNameLanguageMapping,
60
+ restrictMessagesToFollowing: 'boolean',
61
+ disabledListActivity: DisabledListActivity_1.DisabledListActivityMapping
62
+ };
63
+ (0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
37
64
  const mutation = `
38
65
  mutation ($about: String, $titleLanguage: UserTitleLanguage, $displayAdultContent: Boolean, $airingNotifications: Boolean, $scoreFormat: ScoreFormat, $rowOrder: String, $profileColor: String, $donatorBadge: String, $notificationOptions: [NotificationOptionInput], $timezone: String, $activityMergeTime: Int, $animeListOptions: MediaListOptionsInput, $mangaListOptions: MediaListOptionsInput, $staffNameLanguage: UserStaffNameLanguage, $restrictMessagesToFollowing: Boolean, $disabledListActivity: [ListActivityOptionInput]) {
39
66
  UpdateUser(about: $about, titleLanguage: $titleLanguage, displayAdultContent: $displayAdultContent, airingNotifications: $airingNotifications, scoreFormat: $scoreFormat, rowOrder: $rowOrder, profileColor: $profileColor, donatorBadge: $donatorBadge, notificationOptions: $notificationOptions, timezone: $timezone, activityMergeTime: $activityMergeTime, animeListOptions: $animeListOptions, mangaListOptions: $mangaListOptions, staffNameLanguage: $staffNameLanguage, restrictMessagesToFollowing: $restrictMessagesToFollowing, disabledListActivity: $disabledListActivity) {
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DisabledListActivityMapping = void 0;
4
+ /**
5
+ * `DisabledListActivityMapping` is a constant that maps the `DisabledListActivity` fields to their expected types.
6
+ * The `disabled` field is mapped to 'boolean', and the `type` field is mapped to an array of possible values.
7
+ */
8
+ exports.DisabledListActivityMapping = {
9
+ disabled: 'boolean',
10
+ type: ['CURRENT', 'PLANNING', 'COMPLETED', 'DROPPED', 'PAUSED', 'REPEATING']
11
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaListOptionsMapping = void 0;
4
+ /**
5
+ * `MediaListOptionsMapping` is a constant that maps the `MediaListOptions` fields to their expected types.
6
+ * The `sectionOrder`, `customLists`, `advancedScoring`, and `theme` fields are mapped to 'string',
7
+ * and the `splitCompletedSectionByFormat` and `advancedScoringEnabled` fields are mapped to 'boolean'.
8
+ */
9
+ exports.MediaListOptionsMapping = {
10
+ sectionOrder: 'string',
11
+ splitCompletedSectionByFormat: 'boolean',
12
+ customLists: 'string',
13
+ advancedScoring: 'string',
14
+ advancedScoringEnabled: 'boolean',
15
+ theme: 'string'
16
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotificationOptionsMapping = void 0;
4
+ /**
5
+ * `NotificationOptionsMapping` is a constant that maps the `NotificationOptions` fields to their expected types.
6
+ * The `type` field is mapped to an array of possible values, and the `enabled` field is mapped to 'boolean'.
7
+ */
8
+ exports.NotificationOptionsMapping = {
9
+ type: [
10
+ 'ACTIVITY_MESSAGE',
11
+ 'ACTIVITY_REPLY',
12
+ 'FOLLOWING',
13
+ 'ACTIVITY_MENTION',
14
+ 'THREAD_COMMENT_MENTION',
15
+ 'THREAD_SUBSCRIBED',
16
+ 'THREAD_COMMENT_REPLY',
17
+ 'AIRING',
18
+ 'ACTIVITY_LIKE',
19
+ 'ACTIVITY_REPLY_LIKE',
20
+ 'THREAD_LIKE',
21
+ 'THREAD_COMMENT_LIKE',
22
+ 'ACTIVITY_REPLY_SUBSCRIBED',
23
+ 'RELATED_MEDIA_ADDITION',
24
+ 'MEDIA_DATA_CHANGE',
25
+ 'MEDIA_MERGE',
26
+ 'MEDIA_DELETION'
27
+ ],
28
+ enabled: 'boolean'
29
+ };
@@ -1,2 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ScoreFormatMapping = void 0;
4
+ /**
5
+ * `ScoreFormatMapping` is a mapping of `ScoreFormat` values to their string representations.
6
+ * It can be one of the following: 'POINT_100', 'POINT_10_DECIMAL', 'POINT_10', 'POINT_5', 'POINT_3'.
7
+ */
8
+ exports.ScoreFormatMapping = [
9
+ 'POINT_100',
10
+ 'POINT_10_DECIMAL',
11
+ 'POINT_10',
12
+ 'POINT_5',
13
+ 'POINT_3'
14
+ ];
@@ -1,2 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserStaffNameLanguageMapping = void 0;
4
+ /**
5
+ * `UserStaffNameLanguageMapping` is a mapping of `UserStaffNameLanguage` enum values to their corresponding string values.
6
+ * It can be one of the following: 'ROMAJI', 'ENGLISH', 'NATIVE', 'ROMAJI_STYLISED', 'ENGLISH_STYLISED', 'NATIVE_STYLISED'.
7
+ */
8
+ exports.UserStaffNameLanguageMapping = [
9
+ 'ROMAJI',
10
+ 'ENGLISH',
11
+ 'NATIVE',
12
+ 'ROMAJI_STYLISED',
13
+ 'ENGLISH_STYLISED',
14
+ 'NATIVE_STYLISED'
15
+ ];
@@ -1,2 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserTitleLanguageMapping = void 0;
4
+ /**
5
+ * `UserTitleLanguageMapping` is an object that maps each `UserTitleLanguage` to its corresponding string value.
6
+ * It can be one of the following: 'ROMAJI', 'ENGLISH', 'NATIVE', 'ROMAJI_STYLISED', 'ENGLISH_STYLISED', 'NATIVE_STYLISED'.
7
+ */
8
+ exports.UserTitleLanguageMapping = [
9
+ 'ROMAJI',
10
+ 'ENGLISH',
11
+ 'NATIVE',
12
+ 'ROMAJI_STYLISED',
13
+ 'ENGLISH_STYLISED',
14
+ 'NATIVE_STYLISED'
15
+ ];
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateVariables = void 0;
4
+ /**
5
+ * Validates the provided variables against the expected types.
6
+ *
7
+ * @param variables - The variables to validate. This is an object where each key is the name of a variable and the value is the value of the variable.
8
+ * @param variableTypeMappings - An object that maps variable names to their expected types. The expected type can be a string representing a primitive type, an array of possible values, or an object mapping property names to their expected types.
9
+ *
10
+ * @throws Will throw an error if any of the variables do not match their expected types. The error message will include the names of the invalid variables and their expected types.
11
+ */
12
+ function validateVariables(variables, variableTypeMappings) {
13
+ const errors = [];
14
+ for (const [variable, value] of Object.entries(variables)) {
15
+ const expectedType = variableTypeMappings[variable];
16
+ if (expectedType) {
17
+ if (Array.isArray(expectedType)) {
18
+ // If the value is an object, validate its properties
19
+ if (typeof value === 'object' && value !== null) {
20
+ for (const [prop, propValue] of Object.entries(value)) {
21
+ const expectedPropType = expectedType[prop];
22
+ if (expectedPropType && !expectedPropType.includes(propValue)) {
23
+ errors.push(`Invalid ${variable}.${prop}: ${propValue}. Expected one of: ${expectedPropType.join(', ')}`);
24
+ }
25
+ }
26
+ }
27
+ else if (!expectedType.includes(value)) {
28
+ // If the value is not an object, check if it is one of the array values
29
+ errors.push(`Invalid ${variable}: ${value}. Expected one of: ${expectedType.join(', ')}`);
30
+ }
31
+ }
32
+ else if (typeof expectedType === 'object') {
33
+ // If the expected type is an object, validate its properties
34
+ if (Array.isArray(value)) {
35
+ // If the value is an array, validate each object in the array
36
+ value.forEach((item, index) => {
37
+ for (const [prop, propValue] of Object.entries(item)) {
38
+ const expectedPropType = expectedType[prop];
39
+ if (expectedPropType) {
40
+ if (expectedPropType === 'boolean' && typeof propValue === 'boolean') {
41
+ // If the expected type is 'boolean' and the value is a boolean, the validation passes
42
+ }
43
+ else if (!expectedPropType.includes(propValue)) {
44
+ let expectedPropTypeString;
45
+ if (Array.isArray(expectedPropType)) {
46
+ expectedPropTypeString = expectedPropType.join(', ');
47
+ }
48
+ else {
49
+ expectedPropTypeString = expectedPropType.toString();
50
+ }
51
+ errors.push(`Invalid ${variable}[${index}].${prop}: ${propValue}. Expected one of: ${expectedPropTypeString}`);
52
+ }
53
+ }
54
+ }
55
+ });
56
+ }
57
+ else {
58
+ // If the value is not an array, validate its properties
59
+ for (const [prop, propValue] of Object.entries(value)) {
60
+ const expectedPropType = expectedType[prop];
61
+ if (expectedPropType) {
62
+ if (Array.isArray(propValue) && propValue.length === 1) {
63
+ // If the expected type is a string and the value is an array with a single string, treat it as a single string
64
+ if (typeof propValue[0] === 'string' && expectedPropType.includes(propValue[0])) {
65
+ // If the expected type is a string and the value is a string, check if the string is in the array
66
+ }
67
+ else if (typeof propValue[0] !== expectedPropType) {
68
+ errors.push(`Invalid ${variable}.${prop}: ${propValue[0]}. Expected type: ${expectedPropType}`);
69
+ }
70
+ }
71
+ else if (Array.isArray(propValue)) {
72
+ // If the expected type is an array and the value is an array, check if all elements in the array are of the expected type
73
+ if (!propValue.every(item => expectedPropType.includes(item))) {
74
+ let expectedPropTypeString;
75
+ if (Array.isArray(expectedPropType)) {
76
+ expectedPropTypeString = expectedPropType.join(', ');
77
+ }
78
+ else {
79
+ expectedPropTypeString = expectedPropType;
80
+ }
81
+ errors.push(`Invalid ${variable}.${prop}: ${propValue}. Expected type: ${expectedPropTypeString}`);
82
+ }
83
+ }
84
+ else if (typeof propValue === 'string' && expectedPropType.includes(propValue)) {
85
+ // If the expected type is an array and the value is a string, check if the string is in the array
86
+ }
87
+ else if (typeof propValue !== expectedPropType) {
88
+ let expectedPropTypeString;
89
+ if (Array.isArray(expectedPropType)) {
90
+ expectedPropTypeString = expectedPropType.join(', ');
91
+ }
92
+ else {
93
+ expectedPropTypeString = expectedPropType;
94
+ }
95
+ errors.push(`Invalid ${variable}.${prop}: ${propValue}. Expected type: ${expectedPropTypeString}`);
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+ else if (Array.isArray(value)) {
102
+ // If the value is an array, validate each item in the array
103
+ value.forEach((item, index) => {
104
+ if (typeof item !== expectedType) {
105
+ errors.push(`Invalid ${variable}[${index}]: ${item}. Expected type: ${expectedType}`);
106
+ }
107
+ });
108
+ }
109
+ else if (typeof value !== expectedType) {
110
+ errors.push(`Invalid ${variable}: ${value}. Expected type: ${expectedType}`);
111
+ }
112
+ }
113
+ }
114
+ if (errors.length > 0) {
115
+ throw new Error(errors.join('\n'));
116
+ }
117
+ }
118
+ exports.validateVariables = validateVariables;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anilink-api-wrapper",
3
- "version": "1.17.6",
3
+ "version": "1.18.1",
4
4
  "description": "Anilist API Wrapper",
5
5
  "main": "dist/AniLink.js",
6
6
  "scripts": {
package/typedoc.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- "out": "./docs",
3
- "entryPoints": ["./src"],
4
- "entryPointStrategy": "expand",
5
- "exclude": ["**/__tests__/**"],
6
- "name": "AniLink",
7
- "readme": "README.md",
8
- "plugin": ["typedoc-theme-hierarchy"],
9
- "theme": "hierarchy",
10
- "tsconfig": "./tsconfig.json",
11
- "excludePrivate": true,
12
- "excludeProtected": true,
13
- "excludeExternals": true,
14
- "includeVersion": true
15
- }