ani-client 2.1.0 → 2.1.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 +134 -60
- package/dist/index.d.mts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +236 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +236 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,13 +7,10 @@
|
|
|
7
7
|
[](https://www.typescriptlang.org/)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
|
|
10
|
-
> A fully typed, zero-dependency client for the [AniList](https://anilist.co) GraphQL API.
|
|
10
|
+
> A fully typed, zero-dependency client for the [AniList](https://anilist.co) GraphQL API.
|
|
11
|
+
> Supports Node.js, Bun, Deno, and modern browsers.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
**Support server** [Discord server](https://discord.gg/3P7twDurUD)
|
|
15
|
-
|
|
16
|
-
## Highlights
|
|
13
|
+
## Features
|
|
17
14
|
|
|
18
15
|
- **Zero dependencies** — uses the native `fetch` API
|
|
19
16
|
- **Universal** — Node.js ≥ 20, Bun, Deno, and modern browsers
|
|
@@ -21,24 +18,23 @@
|
|
|
21
18
|
- **LRU cache** with TTL, stale-while-revalidate, and hit/miss stats
|
|
22
19
|
- **Rate-limit protection** with exponential backoff, retries, and custom strategies
|
|
23
20
|
- **Request deduplication** — concurrent identical queries share a single in-flight request
|
|
24
|
-
- **Batch queries** — fetch up to 50 media
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
27
|
-
- **AbortSignal support** — cancel globally or per-request with `withSignal()`
|
|
21
|
+
- **Batch queries** — fetch up to 50 media, characters, or staff in a single API call
|
|
22
|
+
- **Auto-pagination** — async iterator that yields items across all pages
|
|
23
|
+
- **AbortSignal support** — cancel globally or per-request via `withSignal()`
|
|
28
24
|
- **Injectable logger** — plug in `console`, pino, winston, or any compatible logger
|
|
29
|
-
- **Redis-ready** — swap the cache
|
|
25
|
+
- **Redis-ready** — swap the in-memory cache with the built-in `RedisCache` adapter
|
|
30
26
|
|
|
31
|
-
##
|
|
27
|
+
## Installation
|
|
32
28
|
|
|
33
29
|
```bash
|
|
34
30
|
npm install ani-client
|
|
35
|
-
#
|
|
31
|
+
# pnpm
|
|
36
32
|
pnpm add ani-client
|
|
37
|
-
#
|
|
33
|
+
# yarn
|
|
38
34
|
yarn add ani-client
|
|
39
35
|
```
|
|
40
36
|
|
|
41
|
-
## Quick
|
|
37
|
+
## Quick Start
|
|
42
38
|
|
|
43
39
|
```ts
|
|
44
40
|
import { AniListClient, MediaType } from "ani-client";
|
|
@@ -57,56 +53,51 @@ const results = await client.searchMedia({
|
|
|
57
53
|
perPage: 10,
|
|
58
54
|
});
|
|
59
55
|
|
|
60
|
-
//
|
|
56
|
+
// Lookup by MyAnimeList ID
|
|
61
57
|
const fma = await client.getMediaByMalId(5114);
|
|
62
|
-
|
|
63
|
-
// Paginated media relationships
|
|
64
|
-
const characters = await client.getMediaCharacters(1, { page: 1, perPage: 25, voiceActors: true });
|
|
65
|
-
const staff = await client.getMediaStaff(1, { page: 1, perPage: 25 });
|
|
66
58
|
```
|
|
67
59
|
|
|
68
|
-
##
|
|
60
|
+
## Usage
|
|
69
61
|
|
|
70
|
-
### Caching
|
|
62
|
+
### Caching
|
|
63
|
+
|
|
64
|
+
The client caches every response in memory by default. You can tune TTL, capacity, and enable stale-while-revalidate:
|
|
71
65
|
|
|
72
66
|
```ts
|
|
73
67
|
const client = new AniListClient({
|
|
74
68
|
cache: {
|
|
75
|
-
ttl: 1000 * 60 * 5,
|
|
76
|
-
maxSize: 200,
|
|
77
|
-
staleWhileRevalidateMs: 60_000,
|
|
69
|
+
ttl: 1000 * 60 * 5, // 5 min TTL
|
|
70
|
+
maxSize: 200, // LRU capacity
|
|
71
|
+
staleWhileRevalidateMs: 60_000, // serve stale for 1 min after expiry
|
|
78
72
|
},
|
|
79
73
|
});
|
|
80
74
|
|
|
81
|
-
// Check cache performance
|
|
82
75
|
console.log(client.cacheStats);
|
|
83
76
|
// { hits: 42, misses: 8, stales: 2, hitRate: 0.84 }
|
|
84
77
|
```
|
|
85
78
|
|
|
86
|
-
|
|
79
|
+
For distributed setups, swap to the built-in Redis adapter:
|
|
87
80
|
|
|
88
81
|
```ts
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
import { AniListClient, RedisCache } from "ani-client";
|
|
83
|
+
import { createClient } from "redis";
|
|
91
84
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Structured logging
|
|
85
|
+
const redis = createClient();
|
|
86
|
+
await redis.connect();
|
|
97
87
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// debug: "Request complete" { durationMs: 120, status: 200 }
|
|
88
|
+
const client = new AniListClient({
|
|
89
|
+
cacheAdapter: new RedisCache(redis),
|
|
90
|
+
});
|
|
102
91
|
```
|
|
103
92
|
|
|
104
|
-
### Rate
|
|
93
|
+
### Rate Limiting
|
|
94
|
+
|
|
95
|
+
The client is pre-configured to stay within AniList's 30 req/min limit. You can override the defaults and provide a custom retry strategy:
|
|
105
96
|
|
|
106
97
|
```ts
|
|
107
98
|
const client = new AniListClient({
|
|
108
99
|
rateLimit: {
|
|
109
|
-
maxRequests:
|
|
100
|
+
maxRequests: 25,
|
|
110
101
|
windowMs: 60_000,
|
|
111
102
|
maxRetries: 3,
|
|
112
103
|
retryOnNetworkError: true,
|
|
@@ -114,17 +105,26 @@ const client = new AniListClient({
|
|
|
114
105
|
},
|
|
115
106
|
});
|
|
116
107
|
|
|
108
|
+
// Inspect the rate limit state after any request
|
|
117
109
|
console.log(client.rateLimitInfo);
|
|
118
|
-
// { remaining:
|
|
110
|
+
// { remaining: 22, limit: 25, reset: 1741104000 }
|
|
119
111
|
```
|
|
120
112
|
|
|
121
|
-
### Batch
|
|
113
|
+
### Batch Requests
|
|
114
|
+
|
|
115
|
+
Fetch multiple entries in a single API call (chunks of 50):
|
|
122
116
|
|
|
123
117
|
```ts
|
|
124
|
-
|
|
125
|
-
const
|
|
118
|
+
const anime = await client.getMediaBatch([1, 5, 6, 20]);
|
|
119
|
+
const characters = await client.getCharacterBatch([1, 2, 3]);
|
|
120
|
+
const staff = await client.getStaffBatch([95269, 95270]);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Auto-Pagination
|
|
124
|
+
|
|
125
|
+
Use the built-in async iterator to walk through all pages automatically:
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
```ts
|
|
128
128
|
for await (const anime of client.paginate(
|
|
129
129
|
(page) => client.searchMedia({ query: "Gundam", page, perPage: 50 }),
|
|
130
130
|
5, // max 5 pages
|
|
@@ -133,32 +133,106 @@ for await (const anime of client.paginate(
|
|
|
133
133
|
}
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
###
|
|
136
|
+
### Request Cancellation
|
|
137
|
+
|
|
138
|
+
Scope any client instance to an `AbortSignal` for per-request cancellation:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
const controller = new AbortController();
|
|
142
|
+
const scoped = client.withSignal(controller.signal);
|
|
143
|
+
|
|
144
|
+
setTimeout(() => controller.abort(), 3_000);
|
|
145
|
+
const anime = await scoped.getMedia(1); // cancelled after 3s
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Logging
|
|
149
|
+
|
|
150
|
+
Pass any `console`-compatible logger to trace requests and cache events:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
const client = new AniListClient({ logger: console });
|
|
154
|
+
// debug: "API request" { variables: { id: 1 } }
|
|
155
|
+
// debug: "Request complete" { durationMs: 120 }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Media Relationships
|
|
159
|
+
|
|
160
|
+
Paginated access to a media's characters and staff:
|
|
137
161
|
|
|
138
162
|
```ts
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
163
|
+
const characters = await client.getMediaCharacters(1, {
|
|
164
|
+
page: 1,
|
|
165
|
+
perPage: 25,
|
|
166
|
+
voiceActors: true,
|
|
167
|
+
});
|
|
168
|
+
|
|
143
169
|
const staff = await client.getMediaStaff(1, { page: 1, perPage: 25 });
|
|
144
|
-
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Users, Characters, Studios & More
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const user = await client.getUser("AniList");
|
|
176
|
+
const favs = await client.getUserFavorites("AniList", { perPage: 50 });
|
|
177
|
+
const char = await client.getCharacter(1, { voiceActors: true });
|
|
178
|
+
const studio = await client.getStudio(21, { media: { perPage: 50 } });
|
|
145
179
|
const schedule = await client.getWeeklySchedule();
|
|
180
|
+
const review = await client.getReview(760);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Error Handling
|
|
184
|
+
|
|
185
|
+
All API errors throw an `AniListError` with a `status` code and the raw GraphQL `errors` array:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import { AniListError } from "ani-client";
|
|
189
|
+
|
|
190
|
+
try {
|
|
191
|
+
await client.getMedia(999999999);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
if (e instanceof AniListError) {
|
|
194
|
+
console.error(e.message); // "Not Found"
|
|
195
|
+
console.error(e.status); // 404
|
|
196
|
+
console.error(e.errors); // raw GraphQL errors array
|
|
197
|
+
}
|
|
198
|
+
}
|
|
146
199
|
```
|
|
147
200
|
|
|
201
|
+
### Lifecycle Hooks
|
|
202
|
+
|
|
203
|
+
Intercept requests, responses, cache events, and errors:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
const client = new AniListClient({
|
|
207
|
+
hooks: {
|
|
208
|
+
onRequest: (query, variables) => console.log("→", variables),
|
|
209
|
+
onResponse: (query, durationMs, fromCache) => console.log(`← ${durationMs}ms`),
|
|
210
|
+
onCacheHit: (key) => console.log("cache hit", key),
|
|
211
|
+
onRateLimit: (retryAfterMs) => console.warn(`rate limited, retrying in ${retryAfterMs}ms`),
|
|
212
|
+
onError: (error) => console.error(error.message),
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Requirements
|
|
218
|
+
|
|
219
|
+
| Runtime | Version |
|
|
220
|
+
|----------|--------------------|
|
|
221
|
+
| Node.js | ≥ 20 |
|
|
222
|
+
| Bun | ≥ 1.0 |
|
|
223
|
+
| Deno | ≥ 1.28 |
|
|
224
|
+
| Browsers | `fetch` + `AbortController` required |
|
|
225
|
+
|
|
148
226
|
## Documentation
|
|
149
227
|
|
|
150
|
-
Full API reference, guides (caching, pagination,
|
|
228
|
+
Full API reference, configuration options, and guides (caching, pagination, hooks, Redis, etc.):
|
|
151
229
|
|
|
152
230
|
**[ani-client.js.org](https://ani-client.js.org)**
|
|
153
231
|
|
|
154
|
-
##
|
|
232
|
+
## Community
|
|
155
233
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
| Node.js | ≥ 20 |
|
|
159
|
-
| Bun | ≥ 1.0 |
|
|
160
|
-
| Deno | ≥ 1.28 |
|
|
161
|
-
| Browsers | Any with `fetch` + `AbortController` |
|
|
234
|
+
- 💬 [Discord server](https://discord.gg/3P7twDurUD)
|
|
235
|
+
- ✨ [Showcase — see who's using ani-client](https://ani-client.js.org/showcase)
|
|
162
236
|
|
|
163
237
|
## Contributing
|
|
164
238
|
|
|
@@ -166,4 +240,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, coding standards,
|
|
|
166
240
|
|
|
167
241
|
## License
|
|
168
242
|
|
|
169
|
-
[MIT](LICENSE) © gonzyui
|
|
243
|
+
[MIT](LICENSE) © [gonzyui](https://github.com/gonzyui)
|
package/dist/index.d.mts
CHANGED
|
@@ -29,6 +29,17 @@ interface ExternalLink {
|
|
|
29
29
|
interface CacheAdapter {
|
|
30
30
|
/** Retrieve a cached value, or `undefined` if missing / expired. */
|
|
31
31
|
get<T>(key: string): T | undefined | Promise<T | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve a cached value along with its stale status (for stale-while-revalidate).
|
|
34
|
+
* If implemented, the client will use this to trigger background revalidation.
|
|
35
|
+
*/
|
|
36
|
+
getWithMeta?<T>(key: string): {
|
|
37
|
+
data: T;
|
|
38
|
+
stale: boolean;
|
|
39
|
+
} | undefined | Promise<{
|
|
40
|
+
data: T;
|
|
41
|
+
stale: boolean;
|
|
42
|
+
} | undefined>;
|
|
32
43
|
/** Store a value in the cache. */
|
|
33
44
|
set<T>(key: string, data: T): void | Promise<void>;
|
|
34
45
|
/** Remove a specific entry. Returns `true` if the key existed. */
|
|
@@ -1070,6 +1081,47 @@ interface SearchThreadOptions {
|
|
|
1070
1081
|
perPage?: number;
|
|
1071
1082
|
}
|
|
1072
1083
|
|
|
1084
|
+
/**
|
|
1085
|
+
* Normalized Cache Adapter for AniListClient.
|
|
1086
|
+
*
|
|
1087
|
+
* This cache intercepts GraphQL responses, extracts objects with `__typename` and `id`,
|
|
1088
|
+
* and stores them flat in an entity store.
|
|
1089
|
+
* This ensures data consistency across all queries (e.g., `getMedia(1)` and `searchMedia`
|
|
1090
|
+
* share the exact same `Media` object).
|
|
1091
|
+
*/
|
|
1092
|
+
declare class NormalizedCache implements CacheAdapter {
|
|
1093
|
+
private readonly ttl;
|
|
1094
|
+
private readonly maxSize;
|
|
1095
|
+
private readonly enabled;
|
|
1096
|
+
private readonly swrMs;
|
|
1097
|
+
private readonly queryStore;
|
|
1098
|
+
private readonly entityStore;
|
|
1099
|
+
private _hits;
|
|
1100
|
+
private _misses;
|
|
1101
|
+
private _stales;
|
|
1102
|
+
constructor(options?: CacheOptions);
|
|
1103
|
+
static key(query: string, variables: Record<string, unknown>): string;
|
|
1104
|
+
/** Normalizes a GraphQL response, extracting entities and returning a tree of references. */
|
|
1105
|
+
private normalize;
|
|
1106
|
+
/** Reconstructs a GraphQL response from references. */
|
|
1107
|
+
private denormalize;
|
|
1108
|
+
getWithMeta<T>(key: string): {
|
|
1109
|
+
data: T;
|
|
1110
|
+
stale: boolean;
|
|
1111
|
+
} | undefined;
|
|
1112
|
+
get<T>(key: string): T | undefined;
|
|
1113
|
+
set<T>(key: string, data: T): void;
|
|
1114
|
+
delete(key: string): boolean;
|
|
1115
|
+
clear(): void;
|
|
1116
|
+
get size(): number;
|
|
1117
|
+
keys(): string[];
|
|
1118
|
+
invalidate(pattern: string | RegExp): number;
|
|
1119
|
+
get stats(): CacheStats & {
|
|
1120
|
+
entitiesCount: number;
|
|
1121
|
+
};
|
|
1122
|
+
resetStats(): void;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1073
1125
|
/** Cache performance statistics. */
|
|
1074
1126
|
interface CacheStats {
|
|
1075
1127
|
/** Total cache hits. */
|
|
@@ -1098,6 +1150,13 @@ declare class MemoryCache implements CacheAdapter {
|
|
|
1098
1150
|
* With stale-while-revalidate enabled, returns stale data within the grace window
|
|
1099
1151
|
* and flags it so the caller can refresh in the background.
|
|
1100
1152
|
*/
|
|
1153
|
+
/**
|
|
1154
|
+
* Retrieve a cached value and its stale status.
|
|
1155
|
+
*/
|
|
1156
|
+
getWithMeta<T>(key: string): {
|
|
1157
|
+
data: T;
|
|
1158
|
+
stale: boolean;
|
|
1159
|
+
} | undefined;
|
|
1101
1160
|
get<T>(key: string): T | undefined;
|
|
1102
1161
|
/** Store a value in the cache. */
|
|
1103
1162
|
set<T>(key: string, data: T): void;
|
|
@@ -1473,4 +1532,4 @@ declare class RateLimiter {
|
|
|
1473
1532
|
|
|
1474
1533
|
declare function parseAniListMarkdown(text: string): string;
|
|
1475
1534
|
|
|
1476
|
-
export { type AiringSchedule, AiringSort, AniListClient, type AniListClientOptions, AniListError, type AniListHooks, type CacheAdapter, type CacheOptions, type CacheStats, type Character, type CharacterImage, type CharacterIncludeOptions, type CharacterMediaEdge, type CharacterName, CharacterRole, CharacterSort, type DayOfWeek, type ExternalLink, type FavoriteCharacterNode, type FavoriteMediaNode, type FavoriteStaffNode, type FavoriteStudioNode, type FuzzyDate, type GetAiringOptions, type GetMediaCharactersOptions, type GetMediaStaffOptions, type GetPlanningOptions, type GetRecentChaptersOptions, type GetRecommendationsOptions, type GetSeasonOptions, type GetUserMediaListOptions, type Logger, type Media, type MediaCharacterConnection, type MediaCharacterEdge, type MediaConnection, type MediaCoverImage, type MediaEdge, MediaFormat, type MediaIncludeOptions, type MediaListEntry, MediaListSort, MediaListStatus, type MediaRecommendationNode, MediaRelationType, MediaSeason, MediaSort, MediaSource, type MediaStaffConnection, type MediaStaffEdge, type MediaStats, MediaStatus, type MediaTag, type MediaTitle, type MediaTrailer, MediaType, MemoryCache, type NextAiringEpisode, type PageInfo, type PagedResult, type RateLimitInfo, type RateLimitOptions, RateLimiter, type Recommendation, RecommendationSort, RedisCache, type RedisCacheOptions, type RedisLikeClient, type ResponseMeta, type Review, ReviewSort, type ScoreDistribution, type SearchCharacterOptions, type SearchMediaOptions, type SearchReviewOptions, type SearchStaffOptions, type SearchStudioOptions, type SearchThreadOptions, type SearchUserOptions, type Staff, type StaffImage, type StaffIncludeOptions, type StaffMediaNode, type StaffName, StaffSort, type StatusDistribution, type StreamingEpisode, type Studio, type StudioConnection, type StudioIncludeOptions, StudioSort, type Thread, type ThreadCategory, type ThreadMediaCategory, ThreadSort, type User, type UserAvatar, type UserFavorites, type UserFavoritesOptions, UserSort, type UserStatistics, type VoiceActor, type WeeklySchedule, parseAniListMarkdown };
|
|
1535
|
+
export { type AiringSchedule, AiringSort, AniListClient, type AniListClientOptions, AniListError, type AniListHooks, type CacheAdapter, type CacheOptions, type CacheStats, type Character, type CharacterImage, type CharacterIncludeOptions, type CharacterMediaEdge, type CharacterName, CharacterRole, CharacterSort, type DayOfWeek, type ExternalLink, type FavoriteCharacterNode, type FavoriteMediaNode, type FavoriteStaffNode, type FavoriteStudioNode, type FuzzyDate, type GetAiringOptions, type GetMediaCharactersOptions, type GetMediaStaffOptions, type GetPlanningOptions, type GetRecentChaptersOptions, type GetRecommendationsOptions, type GetSeasonOptions, type GetUserMediaListOptions, type Logger, type Media, type MediaCharacterConnection, type MediaCharacterEdge, type MediaConnection, type MediaCoverImage, type MediaEdge, MediaFormat, type MediaIncludeOptions, type MediaListEntry, MediaListSort, MediaListStatus, type MediaRecommendationNode, MediaRelationType, MediaSeason, MediaSort, MediaSource, type MediaStaffConnection, type MediaStaffEdge, type MediaStats, MediaStatus, type MediaTag, type MediaTitle, type MediaTrailer, MediaType, MemoryCache, type NextAiringEpisode, NormalizedCache, type PageInfo, type PagedResult, type RateLimitInfo, type RateLimitOptions, RateLimiter, type Recommendation, RecommendationSort, RedisCache, type RedisCacheOptions, type RedisLikeClient, type ResponseMeta, type Review, ReviewSort, type ScoreDistribution, type SearchCharacterOptions, type SearchMediaOptions, type SearchReviewOptions, type SearchStaffOptions, type SearchStudioOptions, type SearchThreadOptions, type SearchUserOptions, type Staff, type StaffImage, type StaffIncludeOptions, type StaffMediaNode, type StaffName, StaffSort, type StatusDistribution, type StreamingEpisode, type Studio, type StudioConnection, type StudioIncludeOptions, StudioSort, type Thread, type ThreadCategory, type ThreadMediaCategory, ThreadSort, type User, type UserAvatar, type UserFavorites, type UserFavoritesOptions, UserSort, type UserStatistics, type VoiceActor, type WeeklySchedule, parseAniListMarkdown };
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,17 @@ interface ExternalLink {
|
|
|
29
29
|
interface CacheAdapter {
|
|
30
30
|
/** Retrieve a cached value, or `undefined` if missing / expired. */
|
|
31
31
|
get<T>(key: string): T | undefined | Promise<T | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve a cached value along with its stale status (for stale-while-revalidate).
|
|
34
|
+
* If implemented, the client will use this to trigger background revalidation.
|
|
35
|
+
*/
|
|
36
|
+
getWithMeta?<T>(key: string): {
|
|
37
|
+
data: T;
|
|
38
|
+
stale: boolean;
|
|
39
|
+
} | undefined | Promise<{
|
|
40
|
+
data: T;
|
|
41
|
+
stale: boolean;
|
|
42
|
+
} | undefined>;
|
|
32
43
|
/** Store a value in the cache. */
|
|
33
44
|
set<T>(key: string, data: T): void | Promise<void>;
|
|
34
45
|
/** Remove a specific entry. Returns `true` if the key existed. */
|
|
@@ -1070,6 +1081,47 @@ interface SearchThreadOptions {
|
|
|
1070
1081
|
perPage?: number;
|
|
1071
1082
|
}
|
|
1072
1083
|
|
|
1084
|
+
/**
|
|
1085
|
+
* Normalized Cache Adapter for AniListClient.
|
|
1086
|
+
*
|
|
1087
|
+
* This cache intercepts GraphQL responses, extracts objects with `__typename` and `id`,
|
|
1088
|
+
* and stores them flat in an entity store.
|
|
1089
|
+
* This ensures data consistency across all queries (e.g., `getMedia(1)` and `searchMedia`
|
|
1090
|
+
* share the exact same `Media` object).
|
|
1091
|
+
*/
|
|
1092
|
+
declare class NormalizedCache implements CacheAdapter {
|
|
1093
|
+
private readonly ttl;
|
|
1094
|
+
private readonly maxSize;
|
|
1095
|
+
private readonly enabled;
|
|
1096
|
+
private readonly swrMs;
|
|
1097
|
+
private readonly queryStore;
|
|
1098
|
+
private readonly entityStore;
|
|
1099
|
+
private _hits;
|
|
1100
|
+
private _misses;
|
|
1101
|
+
private _stales;
|
|
1102
|
+
constructor(options?: CacheOptions);
|
|
1103
|
+
static key(query: string, variables: Record<string, unknown>): string;
|
|
1104
|
+
/** Normalizes a GraphQL response, extracting entities and returning a tree of references. */
|
|
1105
|
+
private normalize;
|
|
1106
|
+
/** Reconstructs a GraphQL response from references. */
|
|
1107
|
+
private denormalize;
|
|
1108
|
+
getWithMeta<T>(key: string): {
|
|
1109
|
+
data: T;
|
|
1110
|
+
stale: boolean;
|
|
1111
|
+
} | undefined;
|
|
1112
|
+
get<T>(key: string): T | undefined;
|
|
1113
|
+
set<T>(key: string, data: T): void;
|
|
1114
|
+
delete(key: string): boolean;
|
|
1115
|
+
clear(): void;
|
|
1116
|
+
get size(): number;
|
|
1117
|
+
keys(): string[];
|
|
1118
|
+
invalidate(pattern: string | RegExp): number;
|
|
1119
|
+
get stats(): CacheStats & {
|
|
1120
|
+
entitiesCount: number;
|
|
1121
|
+
};
|
|
1122
|
+
resetStats(): void;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1073
1125
|
/** Cache performance statistics. */
|
|
1074
1126
|
interface CacheStats {
|
|
1075
1127
|
/** Total cache hits. */
|
|
@@ -1098,6 +1150,13 @@ declare class MemoryCache implements CacheAdapter {
|
|
|
1098
1150
|
* With stale-while-revalidate enabled, returns stale data within the grace window
|
|
1099
1151
|
* and flags it so the caller can refresh in the background.
|
|
1100
1152
|
*/
|
|
1153
|
+
/**
|
|
1154
|
+
* Retrieve a cached value and its stale status.
|
|
1155
|
+
*/
|
|
1156
|
+
getWithMeta<T>(key: string): {
|
|
1157
|
+
data: T;
|
|
1158
|
+
stale: boolean;
|
|
1159
|
+
} | undefined;
|
|
1101
1160
|
get<T>(key: string): T | undefined;
|
|
1102
1161
|
/** Store a value in the cache. */
|
|
1103
1162
|
set<T>(key: string, data: T): void;
|
|
@@ -1473,4 +1532,4 @@ declare class RateLimiter {
|
|
|
1473
1532
|
|
|
1474
1533
|
declare function parseAniListMarkdown(text: string): string;
|
|
1475
1534
|
|
|
1476
|
-
export { type AiringSchedule, AiringSort, AniListClient, type AniListClientOptions, AniListError, type AniListHooks, type CacheAdapter, type CacheOptions, type CacheStats, type Character, type CharacterImage, type CharacterIncludeOptions, type CharacterMediaEdge, type CharacterName, CharacterRole, CharacterSort, type DayOfWeek, type ExternalLink, type FavoriteCharacterNode, type FavoriteMediaNode, type FavoriteStaffNode, type FavoriteStudioNode, type FuzzyDate, type GetAiringOptions, type GetMediaCharactersOptions, type GetMediaStaffOptions, type GetPlanningOptions, type GetRecentChaptersOptions, type GetRecommendationsOptions, type GetSeasonOptions, type GetUserMediaListOptions, type Logger, type Media, type MediaCharacterConnection, type MediaCharacterEdge, type MediaConnection, type MediaCoverImage, type MediaEdge, MediaFormat, type MediaIncludeOptions, type MediaListEntry, MediaListSort, MediaListStatus, type MediaRecommendationNode, MediaRelationType, MediaSeason, MediaSort, MediaSource, type MediaStaffConnection, type MediaStaffEdge, type MediaStats, MediaStatus, type MediaTag, type MediaTitle, type MediaTrailer, MediaType, MemoryCache, type NextAiringEpisode, type PageInfo, type PagedResult, type RateLimitInfo, type RateLimitOptions, RateLimiter, type Recommendation, RecommendationSort, RedisCache, type RedisCacheOptions, type RedisLikeClient, type ResponseMeta, type Review, ReviewSort, type ScoreDistribution, type SearchCharacterOptions, type SearchMediaOptions, type SearchReviewOptions, type SearchStaffOptions, type SearchStudioOptions, type SearchThreadOptions, type SearchUserOptions, type Staff, type StaffImage, type StaffIncludeOptions, type StaffMediaNode, type StaffName, StaffSort, type StatusDistribution, type StreamingEpisode, type Studio, type StudioConnection, type StudioIncludeOptions, StudioSort, type Thread, type ThreadCategory, type ThreadMediaCategory, ThreadSort, type User, type UserAvatar, type UserFavorites, type UserFavoritesOptions, UserSort, type UserStatistics, type VoiceActor, type WeeklySchedule, parseAniListMarkdown };
|
|
1535
|
+
export { type AiringSchedule, AiringSort, AniListClient, type AniListClientOptions, AniListError, type AniListHooks, type CacheAdapter, type CacheOptions, type CacheStats, type Character, type CharacterImage, type CharacterIncludeOptions, type CharacterMediaEdge, type CharacterName, CharacterRole, CharacterSort, type DayOfWeek, type ExternalLink, type FavoriteCharacterNode, type FavoriteMediaNode, type FavoriteStaffNode, type FavoriteStudioNode, type FuzzyDate, type GetAiringOptions, type GetMediaCharactersOptions, type GetMediaStaffOptions, type GetPlanningOptions, type GetRecentChaptersOptions, type GetRecommendationsOptions, type GetSeasonOptions, type GetUserMediaListOptions, type Logger, type Media, type MediaCharacterConnection, type MediaCharacterEdge, type MediaConnection, type MediaCoverImage, type MediaEdge, MediaFormat, type MediaIncludeOptions, type MediaListEntry, MediaListSort, MediaListStatus, type MediaRecommendationNode, MediaRelationType, MediaSeason, MediaSort, MediaSource, type MediaStaffConnection, type MediaStaffEdge, type MediaStats, MediaStatus, type MediaTag, type MediaTitle, type MediaTrailer, MediaType, MemoryCache, type NextAiringEpisode, NormalizedCache, type PageInfo, type PagedResult, type RateLimitInfo, type RateLimitOptions, RateLimiter, type Recommendation, RecommendationSort, RedisCache, type RedisCacheOptions, type RedisLikeClient, type ResponseMeta, type Review, ReviewSort, type ScoreDistribution, type SearchCharacterOptions, type SearchMediaOptions, type SearchReviewOptions, type SearchStaffOptions, type SearchStudioOptions, type SearchThreadOptions, type SearchUserOptions, type Staff, type StaffImage, type StaffIncludeOptions, type StaffMediaNode, type StaffName, StaffSort, type StatusDistribution, type StreamingEpisode, type Studio, type StudioConnection, type StudioIncludeOptions, StudioSort, type Thread, type ThreadCategory, type ThreadMediaCategory, ThreadSort, type User, type UserAvatar, type UserFavorites, type UserFavoritesOptions, UserSort, type UserStatistics, type VoiceActor, type WeeklySchedule, parseAniListMarkdown };
|