anilink-api-wrapper 1.17.6 → 1.18.2
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 +77 -0
- package/dist/apis/anilist/mutation/SaveMediaListEntry.js +25 -2
- package/dist/apis/anilist/mutation/UpdateMediaListEntries.js +24 -3
- package/dist/apis/anilist/mutation/UpdateUser.js +29 -2
- package/dist/apis/anilist/types/DisabledListActivity.js +11 -0
- package/dist/apis/anilist/types/FuzzyDate.js +12 -0
- package/dist/apis/anilist/types/MediaListOptions.js +16 -0
- package/dist/apis/anilist/types/MediaListStatus.js +13 -0
- package/dist/apis/anilist/types/NotificationOptions.js +29 -0
- package/dist/apis/anilist/types/ScoreFormat.js +12 -0
- package/dist/apis/anilist/types/UserStaffNameLanguage.js +13 -0
- package/dist/apis/anilist/types/UserTitleLanguage.js +13 -0
- package/dist/base/ValidateVariables.js +125 -0
- package/package.json +1 -1
- package/typedoc.json +0 -15
package/README.md
CHANGED
|
@@ -108,6 +108,83 @@ List of methods in `anilist.mutation`:
|
|
|
108
108
|
- saveMediaListEntry
|
|
109
109
|
- updateMediaListEntries
|
|
110
110
|
|
|
111
|
+
## Error Handling
|
|
112
|
+
|
|
113
|
+
AniLink will throw an error if the AniList API returns an error. You can catch these errors using a try-catch block.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
try {
|
|
117
|
+
const user = await aniLink.anilist.query.user({id: 542244});
|
|
118
|
+
console.log(user);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error(error);
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This includes status codes and error messages returned by the AniList API. Here is an example rate limit handler to catch the errors thrown by AniLink:
|
|
125
|
+
|
|
126
|
+
### Typescript
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
async function handleRateLimit(apiCall: () => Promise<any>, retryAfter = 60) {
|
|
130
|
+
try {
|
|
131
|
+
let response;
|
|
132
|
+
try {
|
|
133
|
+
response = await apiCall();
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
console.log(response.data);
|
|
138
|
+
return response;
|
|
139
|
+
} catch (error: any) {
|
|
140
|
+
if (error.response && error.response.status === 429) {
|
|
141
|
+
console.log('Rate limit exceeded, waiting for 1 minute before retrying...');
|
|
142
|
+
await new Promise(resolve => setTimeout(resolve, retryAfter * 1000));
|
|
143
|
+
console.log('Retrying...');
|
|
144
|
+
return handleRateLimit(apiCall, retryAfter);
|
|
145
|
+
} else {
|
|
146
|
+
if (error.response && error.response.data) {
|
|
147
|
+
throw error.response.data;
|
|
148
|
+
} else {
|
|
149
|
+
throw error.response || error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Javascript
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
async function handleRateLimit(apiCall, retryAfter = 60) {
|
|
160
|
+
// Same as above
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The possible error codes returned by the AniList API are:
|
|
165
|
+
- 400: Bad Request (e.g. missing variables, invalid variables, or invalid query)
|
|
166
|
+
- 401: Unauthorized (e.g. invalid authentication token)
|
|
167
|
+
- 404: Not Found (e.g. user not found)
|
|
168
|
+
- 429: Too Many Requests (e.g. rate limit exceeded)
|
|
169
|
+
- 500: Internal Server Error (e.g. AniList server error)
|
|
170
|
+
|
|
171
|
+
### Missing or Invalid Variables
|
|
172
|
+
|
|
173
|
+
AniLink will also throw an error if any variables are missing or invalid. For example, if you try to query a user providing a string instead of ID, AniLink will throw an error. Most variables are optional however there a few that are required.
|
|
174
|
+
```typescript
|
|
175
|
+
try {
|
|
176
|
+
const user = await aniLink.anilist.query.user({id: '542244'});
|
|
177
|
+
console.log(user);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error(error);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Example Error Thrown:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
Invalid id: 542244. Expected type: number
|
|
187
|
+
```
|
|
111
188
|
|
|
112
189
|
## Examples
|
|
113
190
|
|
|
@@ -13,6 +13,9 @@ exports.SaveMediaListEntryMutation = void 0;
|
|
|
13
13
|
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
14
14
|
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
15
15
|
const FuzzyDate_1 = require("../interfaces/FuzzyDate");
|
|
16
|
+
const MediaListStatus_1 = require("../types/MediaListStatus");
|
|
17
|
+
const FuzzyDate_2 = require("../types/FuzzyDate");
|
|
18
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
16
19
|
/**
|
|
17
20
|
* `SaveMediaListEntryMutation` is a class representing a mutation to save a media list entry.
|
|
18
21
|
* It includes a method to save a media list entry.
|
|
@@ -30,11 +33,31 @@ class SaveMediaListEntryMutation extends APIWrapper_1.APIWrapper {
|
|
|
30
33
|
/**
|
|
31
34
|
* `saveMediaListEntry` is a method that sends a mutation request to save a media list entry.
|
|
32
35
|
*
|
|
33
|
-
* @param variables -
|
|
34
|
-
* @returns
|
|
36
|
+
* @param variables - An object of type `SaveMediaListEntryVariables` representing the variables for the mutation.
|
|
37
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
38
|
+
* @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
|
|
35
39
|
*/
|
|
36
40
|
saveMediaListEntry(variables) {
|
|
37
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const variableTypeMappings = {
|
|
43
|
+
id: 'number',
|
|
44
|
+
mediaId: 'number',
|
|
45
|
+
status: MediaListStatus_1.MediaListStatusMappings,
|
|
46
|
+
score: 'number',
|
|
47
|
+
scoreRaw: 'number',
|
|
48
|
+
progress: 'number',
|
|
49
|
+
progressVolumes: 'number',
|
|
50
|
+
repeat: 'number',
|
|
51
|
+
priority: 'number',
|
|
52
|
+
private: 'boolean',
|
|
53
|
+
notes: 'string',
|
|
54
|
+
hiddenFromStatusLists: 'boolean',
|
|
55
|
+
customLists: 'string[]',
|
|
56
|
+
advancedScores: 'number[]',
|
|
57
|
+
startedAt: FuzzyDate_2.FuzzyDateMappings,
|
|
58
|
+
completedAt: FuzzyDate_2.FuzzyDateMappings
|
|
59
|
+
};
|
|
60
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
38
61
|
const mutation = `
|
|
39
62
|
mutation ($id: Int, $mediaId: Int, $status: MediaListStatus, $score: Float, $scoreRaw: Int, $progress: Int, $progressVolumes: Int, $repeat: Int, $priority: Int, $private: Boolean, $notes: String, $hiddenFromStatusLists: Boolean, $customLists: [String], $advancedScores: [Float], $startedAt: FuzzyDateInput, $completedAt: FuzzyDateInput) {
|
|
40
63
|
SaveMediaListEntry(id: $id, mediaId: $mediaId, status: $status, score: $score, scoreRaw: $scoreRaw, progress: $progress, progressVolumes: $progressVolumes, repeat: $repeat, priority: $priority, private: $private, notes: $notes, hiddenFromStatusLists: $hiddenFromStatusLists, customLists: $customLists, advancedScores: $advancedScores, startedAt: $startedAt, completedAt: $completedAt) {
|
|
@@ -13,6 +13,9 @@ exports.UpdateMediaListEntriesMutation = void 0;
|
|
|
13
13
|
const APIWrapper_1 = require("../../../base/APIWrapper");
|
|
14
14
|
const RequestHandler_1 = require("../../../base/RequestHandler");
|
|
15
15
|
const FuzzyDate_1 = require("../interfaces/FuzzyDate");
|
|
16
|
+
const MediaListStatus_1 = require("../types/MediaListStatus");
|
|
17
|
+
const ValidateVariables_1 = require("../../../base/ValidateVariables");
|
|
18
|
+
const FuzzyDate_2 = require("../types/FuzzyDate");
|
|
16
19
|
/**
|
|
17
20
|
* `UpdateMediaListEntriesMutation` is a class representing a mutation to update media list entries.
|
|
18
21
|
* It includes a method to update media list entries.
|
|
@@ -30,11 +33,29 @@ class UpdateMediaListEntriesMutation extends APIWrapper_1.APIWrapper {
|
|
|
30
33
|
/**
|
|
31
34
|
* `updateMediaListEntries` is a method that sends a mutation request to update media list entries.
|
|
32
35
|
*
|
|
33
|
-
* @param variables -
|
|
34
|
-
* @returns
|
|
35
|
-
|
|
36
|
+
* @param variables - An object of type `UpdateMediaListEntriesVariables` representing the variables for the mutation.
|
|
37
|
+
* @returns A Promise that resolves to the response from the mutation request.
|
|
38
|
+
* @throws Will throw an error if the mutation request fails or if the provided variables do not pass the validation checks.
|
|
39
|
+
* */
|
|
36
40
|
updateMediaListEntries(variables) {
|
|
37
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const variableTypeMappings = {
|
|
43
|
+
status: MediaListStatus_1.MediaListStatusMappings,
|
|
44
|
+
score: 'number',
|
|
45
|
+
scoreRaw: 'number',
|
|
46
|
+
progress: 'number',
|
|
47
|
+
progressVolumes: 'number',
|
|
48
|
+
repeat: 'number',
|
|
49
|
+
priority: 'number',
|
|
50
|
+
private: 'boolean',
|
|
51
|
+
notes: 'string',
|
|
52
|
+
hiddenFromStatusLists: 'boolean',
|
|
53
|
+
advancedScores: 'number[]',
|
|
54
|
+
startedAt: FuzzyDate_2.FuzzyDateMappings,
|
|
55
|
+
completedAt: FuzzyDate_2.FuzzyDateMappings,
|
|
56
|
+
ids: 'number[]'
|
|
57
|
+
};
|
|
58
|
+
(0, ValidateVariables_1.validateVariables)(variables, variableTypeMappings);
|
|
38
59
|
const mutation = `
|
|
39
60
|
mutation ($status: MediaListStatus, $score: Float, $scoreRaw: Int, $progress: Int, $progressVolumes: Int, $repeat: Int, $priority: Int, $private: Boolean, $notes: String, $hiddenFromStatusLists: Boolean, $advancedScores: [Float], $startedAt: FuzzyDateInput, $completedAt: FuzzyDateInput, $ids: [Int]) {
|
|
40
61
|
UpdateMediaListEntries(status: $status, score: $score, scoreRaw: $scoreRaw, progress: $progress, progressVolumes: $progressVolumes, repeat: $repeat, priority: $priority, private: $private, notes: $notes, hiddenFromStatusLists: $hiddenFromStatusLists, advancedScores: $advancedScores, startedAt: $startedAt, completedAt: $completedAt, ids: $ids) {
|
|
@@ -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 -
|
|
33
|
-
* @returns
|
|
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,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FuzzyDateMappings = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `FuzzyDateMappings` is a constant that maps the `FuzzyDateInput` fields to their expected types.
|
|
6
|
+
* The `year`, `month`, and `day` fields are mapped to 'number'.
|
|
7
|
+
*/
|
|
8
|
+
exports.FuzzyDateMappings = {
|
|
9
|
+
year: 'number',
|
|
10
|
+
month: 'number',
|
|
11
|
+
day: 'number'
|
|
12
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -1,2 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MediaListStatusMappings = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `MediaListStatusMappings` is a constant that maps the `MediaListStatus` values to their expected types.
|
|
6
|
+
* The values are mapped to 'string'.
|
|
7
|
+
*/
|
|
8
|
+
exports.MediaListStatusMappings = [
|
|
9
|
+
'CURRENT',
|
|
10
|
+
'PLANNING',
|
|
11
|
+
'COMPLETED',
|
|
12
|
+
'DROPPED',
|
|
13
|
+
'PAUSED',
|
|
14
|
+
'REPEATING'
|
|
15
|
+
];
|
|
@@ -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,125 @@
|
|
|
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 (typeof expectedType === 'string' && expectedType.endsWith('[]')) {
|
|
18
|
+
// If the expected type is an array, check if the actual value is an array and if its elements are of the correct type
|
|
19
|
+
const elementType = expectedType.slice(0, -2); // Remove the '[]' from the end
|
|
20
|
+
if (!Array.isArray(value) || !value.every((element) => typeof element === elementType)) {
|
|
21
|
+
errors.push(`Invalid ${variable}: ${value}. Expected type: ${expectedType}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (Array.isArray(expectedType)) {
|
|
25
|
+
// If the value is an object, validate its properties
|
|
26
|
+
if (typeof value === 'object' && value !== null) {
|
|
27
|
+
for (const [prop, propValue] of Object.entries(value)) {
|
|
28
|
+
const expectedPropType = expectedType[prop];
|
|
29
|
+
if (expectedPropType && !expectedPropType.includes(propValue)) {
|
|
30
|
+
errors.push(`Invalid ${variable}.${prop}: ${propValue}. Expected one of: ${expectedPropType.join(', ')}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (!expectedType.includes(value)) {
|
|
35
|
+
// If the value is not an object, check if it is one of the array values
|
|
36
|
+
errors.push(`Invalid ${variable}: ${value}. Expected one of: ${expectedType.join(', ')}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (typeof expectedType === 'object') {
|
|
40
|
+
// If the expected type is an object, validate its properties
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
// If the value is an array, validate each object in the array
|
|
43
|
+
value.forEach((item, index) => {
|
|
44
|
+
for (const [prop, propValue] of Object.entries(item)) {
|
|
45
|
+
const expectedPropType = expectedType[prop];
|
|
46
|
+
if (expectedPropType) {
|
|
47
|
+
if (expectedPropType === 'boolean' && typeof propValue === 'boolean') {
|
|
48
|
+
// If the expected type is 'boolean' and the value is a boolean, the validation passes
|
|
49
|
+
}
|
|
50
|
+
else if (!expectedPropType.includes(propValue)) {
|
|
51
|
+
let expectedPropTypeString;
|
|
52
|
+
if (Array.isArray(expectedPropType)) {
|
|
53
|
+
expectedPropTypeString = expectedPropType.join(', ');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
expectedPropTypeString = expectedPropType.toString();
|
|
57
|
+
}
|
|
58
|
+
errors.push(`Invalid ${variable}[${index}].${prop}: ${propValue}. Expected one of: ${expectedPropTypeString}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// If the value is not an array, validate its properties
|
|
66
|
+
for (const [prop, propValue] of Object.entries(value)) {
|
|
67
|
+
const expectedPropType = expectedType[prop];
|
|
68
|
+
if (expectedPropType) {
|
|
69
|
+
if (Array.isArray(propValue) && propValue.length === 1) {
|
|
70
|
+
// If the expected type is a string and the value is an array with a single string, treat it as a single string
|
|
71
|
+
if (typeof propValue[0] === 'string' && expectedPropType.includes(propValue[0])) {
|
|
72
|
+
// If the expected type is a string and the value is a string, check if the string is in the array
|
|
73
|
+
}
|
|
74
|
+
else if (typeof propValue[0] !== expectedPropType) {
|
|
75
|
+
errors.push(`Invalid ${variable}.${prop}: ${propValue[0]}. Expected type: ${expectedPropType}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (Array.isArray(propValue)) {
|
|
79
|
+
// 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
|
|
80
|
+
if (!propValue.every(item => expectedPropType.includes(item))) {
|
|
81
|
+
let expectedPropTypeString;
|
|
82
|
+
if (Array.isArray(expectedPropType)) {
|
|
83
|
+
expectedPropTypeString = expectedPropType.join(', ');
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
expectedPropTypeString = expectedPropType;
|
|
87
|
+
}
|
|
88
|
+
errors.push(`Invalid ${variable}.${prop}: ${propValue}. Expected type: ${expectedPropTypeString}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else if (typeof propValue === 'string' && expectedPropType.includes(propValue)) {
|
|
92
|
+
// If the expected type is an array and the value is a string, check if the string is in the array
|
|
93
|
+
}
|
|
94
|
+
else if (typeof propValue !== expectedPropType) {
|
|
95
|
+
let expectedPropTypeString;
|
|
96
|
+
if (Array.isArray(expectedPropType)) {
|
|
97
|
+
expectedPropTypeString = expectedPropType.join(', ');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
expectedPropTypeString = expectedPropType;
|
|
101
|
+
}
|
|
102
|
+
errors.push(`Invalid ${variable}.${prop}: ${propValue}. Expected type: ${expectedPropTypeString}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else if (Array.isArray(value)) {
|
|
109
|
+
// If the value is an array, validate each item in the array
|
|
110
|
+
value.forEach((item, index) => {
|
|
111
|
+
if (typeof item !== expectedType) {
|
|
112
|
+
errors.push(`Invalid ${variable}[${index}]: ${item}. Expected type: ${expectedType}`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
else if (typeof value !== expectedType) {
|
|
117
|
+
errors.push(`Invalid ${variable}: ${value}. Expected type: ${expectedType}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (errors.length > 0) {
|
|
122
|
+
throw new Error(errors.join('\n'));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.validateVariables = validateVariables;
|
package/package.json
CHANGED
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
|
-
}
|