ani-client 2.1.4 → 2.2.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.
package/README.md CHANGED
@@ -10,8 +10,6 @@
10
10
  > A fully typed, zero-dependency client for the [AniList](https://anilist.co) GraphQL API.
11
11
  > Supports Node.js, Bun, Deno, and modern browsers.
12
12
 
13
- > 📌 **Note** – thanks for **1K+ downloads** this month on `npm` 🎉
14
-
15
13
  ## Features
16
14
 
17
15
  - **Zero dependencies** — uses the native `fetch` API
@@ -73,9 +71,6 @@ const client = new AniListClient({
73
71
  staleWhileRevalidateMs: 60_000, // serve stale for 1 min after expiry
74
72
  },
75
73
  });
76
-
77
- console.log(client.cacheStats);
78
- // { hits: 42, misses: 8, stales: 2, hitRate: 0.84 }
79
74
  ```
80
75
 
81
76
  For distributed setups, swap to the built-in Redis adapter:
@@ -220,7 +215,7 @@ const client = new AniListClient({
220
215
 
221
216
  | Runtime | Version |
222
217
  |----------|--------------------|
223
- | Node.js | ≥ 20 |
218
+ | Node.js | ≥ 22.13.0 |
224
219
  | Bun | ≥ 1.0 |
225
220
  | Deno | ≥ 1.28 |
226
221
  | Browsers | `fetch` + `AbortController` required |
@@ -246,6 +241,26 @@ Before opening an issue or a pull request, please read:
246
241
 
247
242
  This repository also includes GitHub issue templates and a pull request template to help keep reports and contributions consistent.
248
243
 
244
+ ## Development
245
+
246
+ Quick commands for local development and CI checks:
247
+
248
+ ```bash
249
+ pnpm install
250
+ pnpm run build # build dist
251
+ pnpm run typecheck # TypeScript strict checks
252
+ pnpm run lint # lint the codebase
253
+ pnpm test # run unit + integration tests
254
+ pnpm run docs:dev # run documentation site locally
255
+ ```
256
+
257
+ Notes:
258
+ - `tsconfig.json` has `strict: true` enabled to enforce stricter TypeScript checks.
259
+ - Dependabot is configured to open weekly dependency PRs — you will review and merge them manually.
260
+ - CI should validate `build`, `typecheck`, `lint`, and `test` before merging PRs.
261
+
262
+ This repository also includes GitHub issue templates and a pull request template to help keep reports and contributions consistent.
263
+
249
264
  ## License
250
265
 
251
266
  [MIT](LICENSE) © [gonzyui](https://github.com/gonzyui)
@@ -1 +1 @@
1
- export { f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from '../redis-AFbnh0Xa.mjs';
1
+ export { f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from '../redis-UeRs8nqC.mjs';
@@ -1 +1 @@
1
- export { f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from '../redis-AFbnh0Xa.js';
1
+ export { f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from '../redis-UeRs8nqC.js';
@@ -8,7 +8,7 @@ var RedisCache = class {
8
8
  constructor(options) {
9
9
  this.client = options.client;
10
10
  this.prefix = options.prefix ?? "ani:";
11
- this.ttl = options.ttl ?? 86400;
11
+ this.ttl = options.ttl !== void 0 ? Math.floor(options.ttl / 1e3) : 86400;
12
12
  }
13
13
  prefixedKey(key) {
14
14
  return `${this.prefix}${key}`;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cache/redis.ts"],"names":[],"mappings":";;;AAsCO,IAAM,aAAN,MAAyC;AAAA,EAC7B,MAAA;AAAA,EACA,MAAA;AAAA,EACA,GAAA;AAAA,EAEjB,YAAY,OAAA,EAA4B;AACtC,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,MAAA,GAAS,QAAQ,MAAA,IAAU,MAAA;AAChC,IAAA,IAAA,CAAK,GAAA,GAAM,QAAQ,GAAA,IAAO,KAAA;AAAA,EAC5B;AAAA,EAEQ,YAAY,GAAA,EAAqB;AACvC,IAAA,OAAO,CAAA,EAAG,IAAA,CAAK,MAAM,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC7B;AAAA,EAEA,MAAM,IAAO,GAAA,EAAqC;AAChD,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,MAAA,CAAO,IAAI,IAAA,CAAK,WAAA,CAAY,GAAG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A,GAAW,OAAA,CAAQ,MAAA,CAAO,CAAC,CAAA,KAAM,OAAA,CAAQ,IAAA,CAAK,CAAA,CAAE,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,MAAM,CAAC,CAAC,CAAA;AAChF,IAAA,IAAI,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG,OAAO,CAAA;AAClC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,QAAQ,CAAA;AAAA,EACpC;AACF","file":"redis.js","sourcesContent":["import type { CacheAdapter } from \"../types\";\n\n/**\n * Minimal interface representing a Redis client.\n * Compatible with both `ioredis` and `redis` (node-redis v4+).\n */\nexport interface RedisLikeClient {\n get(key: string): Promise<string | null>;\n set(key: string, value: string, ...args: unknown[]): Promise<unknown>;\n del(...keys: (string | string[])[]): Promise<number>;\n keys(pattern: string): Promise<string[]>;\n /** Optional SCAN-based iteration — used when available to avoid blocking the server. */\n scanIterator?(options: { MATCH: string; COUNT?: number }): AsyncIterable<string>;\n}\n\nexport interface RedisCacheOptions {\n /** A Redis client instance (ioredis or node-redis). */\n client: RedisLikeClient;\n /** Key prefix to namespace ani-client entries (default: `\"ani:\"`) */\n prefix?: string;\n /** TTL in seconds (default: 86 400 = 24 h) */\n ttl?: number;\n}\n\n/**\n * Redis-backed cache adapter for AniListClient.\n *\n * @example\n * ```ts\n * import Redis from \"ioredis\";\n * import { AniListClient, RedisCache } from \"ani-client\";\n *\n * const redis = new Redis();\n * const client = new AniListClient({\n * cacheAdapter: new RedisCache({ client: redis }),\n * });\n * ```\n */\nexport class RedisCache implements CacheAdapter {\n private readonly client: RedisLikeClient;\n private readonly prefix: string;\n private readonly ttl: number;\n\n constructor(options: RedisCacheOptions) {\n this.client = options.client;\n this.prefix = options.prefix ?? \"ani:\";\n this.ttl = options.ttl ?? 86_400;\n }\n\n private prefixedKey(key: string): string {\n return `${this.prefix}${key}`;\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const raw = await this.client.get(this.prefixedKey(key));\n if (raw === null) return undefined;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return undefined;\n }\n }\n\n async set<T>(key: string, data: T): Promise<void> {\n await this.client.set(this.prefixedKey(key), JSON.stringify(data), \"EX\", this.ttl);\n }\n\n async delete(key: string): Promise<boolean> {\n const count = await this.client.del(this.prefixedKey(key));\n return count > 0;\n }\n\n /**\n * Collect keys matching a pattern. Uses SCAN when available, falls back to KEYS.\n *\n * **Warning:** The `KEYS` fallback is O(N) and blocks the Redis server.\n * Provide a client with `scanIterator` support for production use.\n * @internal\n */\n private async collectKeys(pattern: string): Promise<string[]> {\n if (this.client.scanIterator) {\n const keys: string[] = [];\n for await (const key of this.client.scanIterator({ MATCH: pattern, COUNT: 100 })) {\n keys.push(key);\n }\n return keys;\n }\n return this.client.keys(pattern);\n }\n\n async clear(): Promise<void> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n if (keys.length > 0) {\n await this.client.del(...keys);\n }\n }\n\n /**\n * Get the actual number of keys with this prefix in Redis.\n */\n get size(): Promise<number> {\n return this.getSize();\n }\n\n /** @internal */\n private async getSize(): Promise<number> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n return keys.length;\n }\n\n async keys(): Promise<string[]> {\n const raw = await this.collectKeys(`${this.prefix}*`);\n return raw.map((k) => k.slice(this.prefix.length));\n }\n\n /**\n * Remove all entries whose key matches the given pattern.\n *\n * - **String**: treated as a substring match (e.g. `\"Media\"` removes all keys containing `\"Media\"`).\n * - **RegExp**: tested against each key directly.\n *\n * @param pattern — A string (substring match) or RegExp.\n * @returns Number of entries removed.\n */\n async invalidate(pattern: string | RegExp): Promise<number> {\n if (typeof pattern === \"string\") {\n const keys = await this.collectKeys(`${this.prefix}*${pattern}*`);\n if (keys.length === 0) return 0;\n return this.client.del(...keys);\n }\n\n const allKeys = await this.collectKeys(`${this.prefix}*`);\n const matching = allKeys.filter((k) => pattern.test(k.slice(this.prefix.length)));\n if (matching.length === 0) return 0;\n return this.client.del(...matching);\n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A,CAAA,CAAG,CAAA;AACpD,IAAA,OAAO,GAAA,CAAI,IAAI,CAAC,CAAA,KAAM,EAAE,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,MAAM,CAAC,CAAA;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,WAAW,OAAA,EAA2C;AAC1D,IAAA,IAAI,OAAO,YAAY,QAAA,EAAU;AAC/B,MAAA,MAAM,IAAA,GAAO,MAAM,IAAA,CAAK,WAAA,CAAY,GAAG,IAAA,CAAK,MAAM,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,CAAG,CAAA;AAChE,MAAA,IAAI,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG,OAAO,CAAA;AAC9B,MAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,IAAI,CAAA;AAAA,IAChC;AAEA,IAAA,MAAM,UAAU,MAAM,IAAA,CAAK,YAAY,CAAA,EAAG,IAAA,CAAK,MAAM,CAAA,CAAA,CAAG,CAAA;AACxD,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,MAAA,CAAO,CAAC,CAAA,KAAM,OAAA,CAAQ,IAAA,CAAK,CAAA,CAAE,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,MAAM,CAAC,CAAC,CAAA;AAChF,IAAA,IAAI,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG,OAAO,CAAA;AAClC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,QAAQ,CAAA;AAAA,EACpC;AACF","file":"redis.js","sourcesContent":["import type { CacheAdapter } from \"../types\";\n\n/**\n * Minimal interface representing a Redis client.\n * Compatible with both `ioredis` and `redis` (node-redis v4+).\n */\nexport interface RedisLikeClient {\n get(key: string): Promise<string | null>;\n set(key: string, value: string, ...args: unknown[]): Promise<unknown>;\n del(...keys: (string | string[])[]): Promise<number>;\n keys(pattern: string): Promise<string[]>;\n /** Optional SCAN-based iteration — used when available to avoid blocking the server. */\n scanIterator?(options: { MATCH: string; COUNT?: number }): AsyncIterable<string>;\n}\n\nexport interface RedisCacheOptions {\n /** A Redis client instance (ioredis or node-redis). */\n client: RedisLikeClient;\n /** Key prefix to namespace ani-client entries (default: `\"ani:\"`) */\n prefix?: string;\n /** TTL in milliseconds (default: 86 400 000 = 24h) */\n ttl?: number;\n}\n\n/**\n * Redis-backed cache adapter for AniListClient.\n *\n * @example\n * ```ts\n * import Redis from \"ioredis\";\n * import { AniListClient, RedisCache } from \"ani-client\";\n *\n * const redis = new Redis();\n * const client = new AniListClient({\n * cacheAdapter: new RedisCache({ client: redis }),\n * });\n * ```\n */\nexport class RedisCache implements CacheAdapter {\n private readonly client: RedisLikeClient;\n private readonly prefix: string;\n private readonly ttl: number;\n\n constructor(options: RedisCacheOptions) {\n this.client = options.client;\n this.prefix = options.prefix ?? \"ani:\";\n this.ttl = options.ttl !== undefined ? Math.floor(options.ttl / 1000) : 86_400;\n }\n\n private prefixedKey(key: string): string {\n return `${this.prefix}${key}`;\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const raw = await this.client.get(this.prefixedKey(key));\n if (raw === null) return undefined;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return undefined;\n }\n }\n\n async set<T>(key: string, data: T): Promise<void> {\n await this.client.set(this.prefixedKey(key), JSON.stringify(data), \"EX\", this.ttl);\n }\n\n async delete(key: string): Promise<boolean> {\n const count = await this.client.del(this.prefixedKey(key));\n return count > 0;\n }\n\n /**\n * Collect keys matching a pattern. Uses SCAN when available, falls back to KEYS.\n *\n * **Warning:** The `KEYS` fallback is O(N) and blocks the Redis server.\n * Provide a client with `scanIterator` support for production use.\n * @internal\n */\n private async collectKeys(pattern: string): Promise<string[]> {\n if (this.client.scanIterator) {\n const keys: string[] = [];\n for await (const key of this.client.scanIterator({ MATCH: pattern, COUNT: 100 })) {\n keys.push(key);\n }\n return keys;\n }\n return this.client.keys(pattern);\n }\n\n async clear(): Promise<void> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n if (keys.length > 0) {\n await this.client.del(...keys);\n }\n }\n\n /**\n * Get the actual number of keys with this prefix in Redis.\n */\n get size(): Promise<number> {\n return this.getSize();\n }\n\n /** @internal */\n private async getSize(): Promise<number> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n return keys.length;\n }\n\n async keys(): Promise<string[]> {\n const raw = await this.collectKeys(`${this.prefix}*`);\n return raw.map((k) => k.slice(this.prefix.length));\n }\n\n /**\n * Remove all entries whose key matches the given pattern.\n *\n * - **String**: treated as a substring match (e.g. `\"Media\"` removes all keys containing `\"Media\"`).\n * - **RegExp**: tested against each key directly.\n *\n * @param pattern — A string (substring match) or RegExp.\n * @returns Number of entries removed.\n */\n async invalidate(pattern: string | RegExp): Promise<number> {\n if (typeof pattern === \"string\") {\n const keys = await this.collectKeys(`${this.prefix}*${pattern}*`);\n if (keys.length === 0) return 0;\n return this.client.del(...keys);\n }\n\n const allKeys = await this.collectKeys(`${this.prefix}*`);\n const matching = allKeys.filter((k) => pattern.test(k.slice(this.prefix.length)));\n if (matching.length === 0) return 0;\n return this.client.del(...matching);\n }\n}\n"]}
@@ -6,7 +6,7 @@ var RedisCache = class {
6
6
  constructor(options) {
7
7
  this.client = options.client;
8
8
  this.prefix = options.prefix ?? "ani:";
9
- this.ttl = options.ttl ?? 86400;
9
+ this.ttl = options.ttl !== void 0 ? Math.floor(options.ttl / 1e3) : 86400;
10
10
  }
11
11
  prefixedKey(key) {
12
12
  return `${this.prefix}${key}`;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cache/redis.ts"],"names":[],"mappings":";AAsCO,IAAM,aAAN,MAAyC;AAAA,EAC7B,MAAA;AAAA,EACA,MAAA;AAAA,EACA,GAAA;AAAA,EAEjB,YAAY,OAAA,EAA4B;AACtC,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,MAAA,GAAS,QAAQ,MAAA,I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IAAA,CAAK,MAAM,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,CAAG,CAAA;AAChE,MAAA,IAAI,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG,OAAO,CAAA;AAC9B,MAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,IAAI,CAAA;AAAA,IAChC;AAEA,IAAA,MAAM,UAAU,MAAM,IAAA,CAAK,YAAY,CAAA,EAAG,IAAA,CAAK,MAAM,CAAA,CAAA,CAAG,CAAA;AACxD,IAAA,MAAM,QAAA,GAAW,OAAA,CAAQ,MAAA,CAAO,CAAC,CAAA,KAAM,OAAA,CAAQ,IAAA,CAAK,CAAA,CAAE,KAAA,CAAM,IAAA,CAAK,MAAA,CAAO,MAAM,CAAC,CAAC,CAAA;AAChF,IAAA,IAAI,QAAA,CAAS,MAAA,KAAW,CAAA,EAAG,OAAO,CAAA;AAClC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,QAAQ,CAAA;AAAA,EACpC;AACF","file":"redis.mjs","sourcesContent":["import type { CacheAdapter } from \"../types\";\n\n/**\n * Minimal interface representing a Redis client.\n * Compatible with both `ioredis` and `redis` (node-redis v4+).\n */\nexport interface RedisLikeClient {\n get(key: string): Promise<string | null>;\n set(key: string, value: string, ...args: unknown[]): Promise<unknown>;\n del(...keys: (string | string[])[]): Promise<number>;\n keys(pattern: string): Promise<string[]>;\n /** Optional SCAN-based iteration — used when available to avoid blocking the server. */\n scanIterator?(options: { MATCH: string; COUNT?: number }): AsyncIterable<string>;\n}\n\nexport interface RedisCacheOptions {\n /** A Redis client instance (ioredis or node-redis). */\n client: RedisLikeClient;\n /** Key prefix to namespace ani-client entries (default: `\"ani:\"`) */\n prefix?: string;\n /** TTL in seconds (default: 86 400 = 24 h) */\n ttl?: number;\n}\n\n/**\n * Redis-backed cache adapter for AniListClient.\n *\n * @example\n * ```ts\n * import Redis from \"ioredis\";\n * import { AniListClient, RedisCache } from \"ani-client\";\n *\n * const redis = new Redis();\n * const client = new AniListClient({\n * cacheAdapter: new RedisCache({ client: redis }),\n * });\n * ```\n */\nexport class RedisCache implements CacheAdapter {\n private readonly client: RedisLikeClient;\n private readonly prefix: string;\n private readonly ttl: number;\n\n constructor(options: RedisCacheOptions) {\n this.client = options.client;\n this.prefix = options.prefix ?? \"ani:\";\n this.ttl = options.ttl ?? 86_400;\n }\n\n private prefixedKey(key: string): string {\n return `${this.prefix}${key}`;\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const raw = await this.client.get(this.prefixedKey(key));\n if (raw === null) return undefined;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return undefined;\n }\n }\n\n async set<T>(key: string, data: T): Promise<void> {\n await this.client.set(this.prefixedKey(key), JSON.stringify(data), \"EX\", this.ttl);\n }\n\n async delete(key: string): Promise<boolean> {\n const count = await this.client.del(this.prefixedKey(key));\n return count > 0;\n }\n\n /**\n * Collect keys matching a pattern. Uses SCAN when available, falls back to KEYS.\n *\n * **Warning:** The `KEYS` fallback is O(N) and blocks the Redis server.\n * Provide a client with `scanIterator` support for production use.\n * @internal\n */\n private async collectKeys(pattern: string): Promise<string[]> {\n if (this.client.scanIterator) {\n const keys: string[] = [];\n for await (const key of this.client.scanIterator({ MATCH: pattern, COUNT: 100 })) {\n keys.push(key);\n }\n return keys;\n }\n return this.client.keys(pattern);\n }\n\n async clear(): Promise<void> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n if (keys.length > 0) {\n await this.client.del(...keys);\n }\n }\n\n /**\n * Get the actual number of keys with this prefix in Redis.\n */\n get size(): Promise<number> {\n return this.getSize();\n }\n\n /** @internal */\n private async getSize(): Promise<number> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n return keys.length;\n }\n\n async keys(): Promise<string[]> {\n const raw = await this.collectKeys(`${this.prefix}*`);\n return raw.map((k) => k.slice(this.prefix.length));\n }\n\n /**\n * Remove all entries whose key matches the given pattern.\n *\n * - **String**: treated as a substring match (e.g. `\"Media\"` removes all keys containing `\"Media\"`).\n * - **RegExp**: tested against each key directly.\n *\n * @param pattern — A string (substring match) or RegExp.\n * @returns Number of entries removed.\n */\n async invalidate(pattern: string | RegExp): Promise<number> {\n if (typeof pattern === \"string\") {\n const keys = await this.collectKeys(`${this.prefix}*${pattern}*`);\n if (keys.length === 0) return 0;\n return this.client.del(...keys);\n }\n\n const allKeys = await this.collectKeys(`${this.prefix}*`);\n const matching = allKeys.filter((k) => pattern.test(k.slice(this.prefix.length)));\n if (matching.length === 0) return 0;\n return this.client.del(...matching);\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/cache/redis.ts"],"names":[],"mappings":";AAsCO,IAAM,aAAN,MAAyC;AAAA,EAC7B,MAAA;AAAA,EACA,MAAA;AAAA,EACA,GAAA;AAAA,EAEjB,YAAY,OAAA,EAA4B;AACtC,IAAA,IAAA,CAAK,SAAS,OAAA,CAAQ,MAAA;AACtB,IAAA,IAAA,CAAK,MAAA,GAAS,QAAQ,MAAA,IAAU,MAAA;AAChC,IAAA,IAAA,CAAK,GAAA,GAAM,QAAQ,GAAA,KAAQ,MAAA,GAAY,KAAK,KAAA,CAAM,OAAA,CAAQ,GAAA,GAAM,GAAI,CAAA,GAAI,KAAA;AAAA,EAC1E;AAAA,EAEQ,YAAY,GAAA,EAAqB;AACvC,IAAA,OAAO,CAAA,EAAG,IAAA,CAAK,MAAM,CAAA,EAAG,GAAG,CAAA,CAAA;AAAA,EAC7B;AAAA,EAEA,MAAM,IAAO,GAAA,EAAqC;AAChD,IAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,MAAA,CAAO,IAAI,IAAA,CAAK,WAAA,CAAY,GAAG,CAAC,CAAA;AACvD,IAAA,IAAI,GAAA,KAAQ,MAAM,OAAO,MAAA;AACzB,IAAA,IAAI;AACF,MAAA,OAAO,IAAA,CAAK,MAAM,GAAG,CAAA;AAAA,IACvB,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,E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AG,OAAO,CAAA;AAClC,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,GAAG,QAAQ,CAAA;AAAA,EACpC;AACF","file":"redis.mjs","sourcesContent":["import type { CacheAdapter } from \"../types\";\n\n/**\n * Minimal interface representing a Redis client.\n * Compatible with both `ioredis` and `redis` (node-redis v4+).\n */\nexport interface RedisLikeClient {\n get(key: string): Promise<string | null>;\n set(key: string, value: string, ...args: unknown[]): Promise<unknown>;\n del(...keys: (string | string[])[]): Promise<number>;\n keys(pattern: string): Promise<string[]>;\n /** Optional SCAN-based iteration — used when available to avoid blocking the server. */\n scanIterator?(options: { MATCH: string; COUNT?: number }): AsyncIterable<string>;\n}\n\nexport interface RedisCacheOptions {\n /** A Redis client instance (ioredis or node-redis). */\n client: RedisLikeClient;\n /** Key prefix to namespace ani-client entries (default: `\"ani:\"`) */\n prefix?: string;\n /** TTL in milliseconds (default: 86 400 000 = 24h) */\n ttl?: number;\n}\n\n/**\n * Redis-backed cache adapter for AniListClient.\n *\n * @example\n * ```ts\n * import Redis from \"ioredis\";\n * import { AniListClient, RedisCache } from \"ani-client\";\n *\n * const redis = new Redis();\n * const client = new AniListClient({\n * cacheAdapter: new RedisCache({ client: redis }),\n * });\n * ```\n */\nexport class RedisCache implements CacheAdapter {\n private readonly client: RedisLikeClient;\n private readonly prefix: string;\n private readonly ttl: number;\n\n constructor(options: RedisCacheOptions) {\n this.client = options.client;\n this.prefix = options.prefix ?? \"ani:\";\n this.ttl = options.ttl !== undefined ? Math.floor(options.ttl / 1000) : 86_400;\n }\n\n private prefixedKey(key: string): string {\n return `${this.prefix}${key}`;\n }\n\n async get<T>(key: string): Promise<T | undefined> {\n const raw = await this.client.get(this.prefixedKey(key));\n if (raw === null) return undefined;\n try {\n return JSON.parse(raw) as T;\n } catch {\n return undefined;\n }\n }\n\n async set<T>(key: string, data: T): Promise<void> {\n await this.client.set(this.prefixedKey(key), JSON.stringify(data), \"EX\", this.ttl);\n }\n\n async delete(key: string): Promise<boolean> {\n const count = await this.client.del(this.prefixedKey(key));\n return count > 0;\n }\n\n /**\n * Collect keys matching a pattern. Uses SCAN when available, falls back to KEYS.\n *\n * **Warning:** The `KEYS` fallback is O(N) and blocks the Redis server.\n * Provide a client with `scanIterator` support for production use.\n * @internal\n */\n private async collectKeys(pattern: string): Promise<string[]> {\n if (this.client.scanIterator) {\n const keys: string[] = [];\n for await (const key of this.client.scanIterator({ MATCH: pattern, COUNT: 100 })) {\n keys.push(key);\n }\n return keys;\n }\n return this.client.keys(pattern);\n }\n\n async clear(): Promise<void> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n if (keys.length > 0) {\n await this.client.del(...keys);\n }\n }\n\n /**\n * Get the actual number of keys with this prefix in Redis.\n */\n get size(): Promise<number> {\n return this.getSize();\n }\n\n /** @internal */\n private async getSize(): Promise<number> {\n const keys = await this.collectKeys(`${this.prefix}*`);\n return keys.length;\n }\n\n async keys(): Promise<string[]> {\n const raw = await this.collectKeys(`${this.prefix}*`);\n return raw.map((k) => k.slice(this.prefix.length));\n }\n\n /**\n * Remove all entries whose key matches the given pattern.\n *\n * - **String**: treated as a substring match (e.g. `\"Media\"` removes all keys containing `\"Media\"`).\n * - **RegExp**: tested against each key directly.\n *\n * @param pattern — A string (substring match) or RegExp.\n * @returns Number of entries removed.\n */\n async invalidate(pattern: string | RegExp): Promise<number> {\n if (typeof pattern === \"string\") {\n const keys = await this.collectKeys(`${this.prefix}*${pattern}*`);\n if (keys.length === 0) return 0;\n return this.client.del(...keys);\n }\n\n const allKeys = await this.collectKeys(`${this.prefix}*`);\n const matching = allKeys.filter((k) => pattern.test(k.slice(this.prefix.length)));\n if (matching.length === 0) return 0;\n return this.client.del(...matching);\n }\n}\n"]}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FuzzyDate, P as PageInfo, E as ExternalLink, C as CacheAdapter, a as CacheOptions, b as PagedResult, A as AniListClientOptions, R as RateLimitInfo, c as ResponseMeta, d as RateLimitOptions } from './redis-AFbnh0Xa.mjs';
2
- export { e as AniListHooks, L as Logger, f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from './redis-AFbnh0Xa.mjs';
1
+ import { F as FuzzyDate, P as PageInfo, E as ExternalLink, C as CacheAdapter, a as CacheOptions, b as PagedResult, A as AniListClientOptions, R as RateLimitInfo, c as ResponseMeta, d as RateLimitOptions } from './redis-UeRs8nqC.mjs';
2
+ export { e as AniListHooks, L as Logger, f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from './redis-UeRs8nqC.mjs';
3
3
 
4
4
  declare enum MediaListStatus {
5
5
  CURRENT = "CURRENT",
@@ -934,6 +934,7 @@ declare class NormalizedCache implements CacheAdapter {
934
934
  private _hits;
935
935
  private _misses;
936
936
  private _stales;
937
+ private gcTimeout?;
937
938
  constructor(options?: CacheOptions);
938
939
  static key(query: string, variables: Record<string, unknown>): string;
939
940
  /** Normalizes a GraphQL response, extracting entities and returning a tree of references. */
@@ -955,6 +956,7 @@ declare class NormalizedCache implements CacheAdapter {
955
956
  entitiesCount: number;
956
957
  };
957
958
  resetStats(): void;
959
+ private scheduleGc;
958
960
  /**
959
961
  * Garbage-collect orphaned entities that are no longer referenced by any query.
960
962
  * Called automatically on LRU eviction to prevent unbounded entity store growth.
@@ -1106,13 +1108,13 @@ declare class AniListClient implements ClientBase {
1106
1108
  * @param options - Search / filter parameters
1107
1109
  * @returns Paginated results with matching media
1108
1110
  */
1109
- searchMedia(options?: SearchMediaOptions): Promise<PagedResult<Media>>;
1111
+ searchMedia(options?: SearchMediaOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1110
1112
  /** Get currently trending anime or manga. */
1111
- getTrending(options?: GeneralMediaQueryOptions): Promise<PagedResult<Media>>;
1113
+ getTrending(options?: GeneralMediaQueryOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1112
1114
  /** Get the most popular anime or manga. */
1113
- getPopular(options?: GeneralMediaQueryOptions): Promise<PagedResult<Media>>;
1115
+ getPopular(options?: GeneralMediaQueryOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1114
1116
  /** Get the highest-rated anime or manga. */
1115
- getTopRated(options?: GeneralMediaQueryOptions): Promise<PagedResult<Media>>;
1117
+ getTopRated(options?: GeneralMediaQueryOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1116
1118
  /** Get recently aired anime episodes. */
1117
1119
  getAiredEpisodes(options?: GetAiringOptions): Promise<PagedResult<AiringSchedule>>;
1118
1120
  /**
@@ -1120,11 +1122,7 @@ declare class AniListClient implements ClientBase {
1120
1122
  *
1121
1123
  * @param options - Pagination parameters
1122
1124
  */
1123
- getRecentlyUpdatedManga(options?: GetRecentChaptersOptions): Promise<PagedResult<Media>>;
1124
- /**
1125
- * @deprecated Use `getRecentlyUpdatedManga()` instead. This alias will be removed in v3.
1126
- */
1127
- getAiredChapters(options?: GetRecentChaptersOptions): Promise<PagedResult<Media>>;
1125
+ getRecentlyUpdatedManga(options?: GetRecentChaptersOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1128
1126
  /**
1129
1127
  * Fetch a media entry by its MyAnimeList (MAL) ID.
1130
1128
  *
@@ -1135,11 +1133,11 @@ declare class AniListClient implements ClientBase {
1135
1133
  /** Get the detailed schedule for the current week, sorted by day. */
1136
1134
  getWeeklySchedule(date?: Date, idNotIn?: number[]): Promise<WeeklySchedule>;
1137
1135
  /** Get upcoming (not yet released) media. */
1138
- getPlanning(options?: GetPlanningOptions): Promise<PagedResult<Media>>;
1136
+ getPlanning(options?: GetPlanningOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1139
1137
  /** Get recommendations for a specific media. */
1140
1138
  getRecommendations(mediaId: number, options?: Omit<GetRecommendationsOptions, "mediaId">): Promise<PagedResult<Recommendation>>;
1141
1139
  /** Get anime (or manga) for a specific season and year. */
1142
- getMediaBySeason(options: GetSeasonOptions): Promise<PagedResult<Media>>;
1140
+ getMediaBySeason(options: GetSeasonOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1143
1141
  /** Fetch a character by AniList ID. Pass `{ voiceActors: true }` to include VA data. */
1144
1142
  getCharacter(id: number, include?: CharacterIncludeOptions): Promise<Character>;
1145
1143
  /** Search for characters by name. */
@@ -1249,6 +1247,23 @@ declare class AniListClient implements ClientBase {
1249
1247
  withSignal(signal: AbortSignal): AniListClient;
1250
1248
  }
1251
1249
 
1250
+ /**
1251
+ * Represents a location in a GraphQL query where an error occurred.
1252
+ */
1253
+ interface GraphQLErrorLocation {
1254
+ line: number;
1255
+ column: number;
1256
+ }
1257
+ /**
1258
+ * Standard GraphQL error shape.
1259
+ */
1260
+ interface GraphQLError {
1261
+ message: string;
1262
+ locations?: GraphQLErrorLocation[];
1263
+ path?: (string | number)[];
1264
+ extensions?: Record<string, unknown>;
1265
+ [key: string]: unknown;
1266
+ }
1252
1267
  /**
1253
1268
  * Custom error class for AniList API errors.
1254
1269
  */
@@ -1256,8 +1271,8 @@ declare class AniListError extends Error {
1256
1271
  /** HTTP status code returned by the API */
1257
1272
  readonly status: number;
1258
1273
  /** Raw error body from the API response */
1259
- readonly errors: unknown[];
1260
- constructor(message: string, status: number, errors?: unknown[]);
1274
+ readonly errors: GraphQLError[];
1275
+ constructor(message: string, status: number, errors?: GraphQLError[] | unknown[]);
1261
1276
  }
1262
1277
 
1263
1278
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as FuzzyDate, P as PageInfo, E as ExternalLink, C as CacheAdapter, a as CacheOptions, b as PagedResult, A as AniListClientOptions, R as RateLimitInfo, c as ResponseMeta, d as RateLimitOptions } from './redis-AFbnh0Xa.js';
2
- export { e as AniListHooks, L as Logger, f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from './redis-AFbnh0Xa.js';
1
+ import { F as FuzzyDate, P as PageInfo, E as ExternalLink, C as CacheAdapter, a as CacheOptions, b as PagedResult, A as AniListClientOptions, R as RateLimitInfo, c as ResponseMeta, d as RateLimitOptions } from './redis-UeRs8nqC.js';
2
+ export { e as AniListHooks, L as Logger, f as RedisCache, g as RedisCacheOptions, h as RedisLikeClient } from './redis-UeRs8nqC.js';
3
3
 
4
4
  declare enum MediaListStatus {
5
5
  CURRENT = "CURRENT",
@@ -934,6 +934,7 @@ declare class NormalizedCache implements CacheAdapter {
934
934
  private _hits;
935
935
  private _misses;
936
936
  private _stales;
937
+ private gcTimeout?;
937
938
  constructor(options?: CacheOptions);
938
939
  static key(query: string, variables: Record<string, unknown>): string;
939
940
  /** Normalizes a GraphQL response, extracting entities and returning a tree of references. */
@@ -955,6 +956,7 @@ declare class NormalizedCache implements CacheAdapter {
955
956
  entitiesCount: number;
956
957
  };
957
958
  resetStats(): void;
959
+ private scheduleGc;
958
960
  /**
959
961
  * Garbage-collect orphaned entities that are no longer referenced by any query.
960
962
  * Called automatically on LRU eviction to prevent unbounded entity store growth.
@@ -1106,13 +1108,13 @@ declare class AniListClient implements ClientBase {
1106
1108
  * @param options - Search / filter parameters
1107
1109
  * @returns Paginated results with matching media
1108
1110
  */
1109
- searchMedia(options?: SearchMediaOptions): Promise<PagedResult<Media>>;
1111
+ searchMedia(options?: SearchMediaOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1110
1112
  /** Get currently trending anime or manga. */
1111
- getTrending(options?: GeneralMediaQueryOptions): Promise<PagedResult<Media>>;
1113
+ getTrending(options?: GeneralMediaQueryOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1112
1114
  /** Get the most popular anime or manga. */
1113
- getPopular(options?: GeneralMediaQueryOptions): Promise<PagedResult<Media>>;
1115
+ getPopular(options?: GeneralMediaQueryOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1114
1116
  /** Get the highest-rated anime or manga. */
1115
- getTopRated(options?: GeneralMediaQueryOptions): Promise<PagedResult<Media>>;
1117
+ getTopRated(options?: GeneralMediaQueryOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1116
1118
  /** Get recently aired anime episodes. */
1117
1119
  getAiredEpisodes(options?: GetAiringOptions): Promise<PagedResult<AiringSchedule>>;
1118
1120
  /**
@@ -1120,11 +1122,7 @@ declare class AniListClient implements ClientBase {
1120
1122
  *
1121
1123
  * @param options - Pagination parameters
1122
1124
  */
1123
- getRecentlyUpdatedManga(options?: GetRecentChaptersOptions): Promise<PagedResult<Media>>;
1124
- /**
1125
- * @deprecated Use `getRecentlyUpdatedManga()` instead. This alias will be removed in v3.
1126
- */
1127
- getAiredChapters(options?: GetRecentChaptersOptions): Promise<PagedResult<Media>>;
1125
+ getRecentlyUpdatedManga(options?: GetRecentChaptersOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1128
1126
  /**
1129
1127
  * Fetch a media entry by its MyAnimeList (MAL) ID.
1130
1128
  *
@@ -1135,11 +1133,11 @@ declare class AniListClient implements ClientBase {
1135
1133
  /** Get the detailed schedule for the current week, sorted by day. */
1136
1134
  getWeeklySchedule(date?: Date, idNotIn?: number[]): Promise<WeeklySchedule>;
1137
1135
  /** Get upcoming (not yet released) media. */
1138
- getPlanning(options?: GetPlanningOptions): Promise<PagedResult<Media>>;
1136
+ getPlanning(options?: GetPlanningOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1139
1137
  /** Get recommendations for a specific media. */
1140
1138
  getRecommendations(mediaId: number, options?: Omit<GetRecommendationsOptions, "mediaId">): Promise<PagedResult<Recommendation>>;
1141
1139
  /** Get anime (or manga) for a specific season and year. */
1142
- getMediaBySeason(options: GetSeasonOptions): Promise<PagedResult<Media>>;
1140
+ getMediaBySeason(options: GetSeasonOptions, include?: MediaIncludeOptions): Promise<PagedResult<Media>>;
1143
1141
  /** Fetch a character by AniList ID. Pass `{ voiceActors: true }` to include VA data. */
1144
1142
  getCharacter(id: number, include?: CharacterIncludeOptions): Promise<Character>;
1145
1143
  /** Search for characters by name. */
@@ -1249,6 +1247,23 @@ declare class AniListClient implements ClientBase {
1249
1247
  withSignal(signal: AbortSignal): AniListClient;
1250
1248
  }
1251
1249
 
1250
+ /**
1251
+ * Represents a location in a GraphQL query where an error occurred.
1252
+ */
1253
+ interface GraphQLErrorLocation {
1254
+ line: number;
1255
+ column: number;
1256
+ }
1257
+ /**
1258
+ * Standard GraphQL error shape.
1259
+ */
1260
+ interface GraphQLError {
1261
+ message: string;
1262
+ locations?: GraphQLErrorLocation[];
1263
+ path?: (string | number)[];
1264
+ extensions?: Record<string, unknown>;
1265
+ [key: string]: unknown;
1266
+ }
1252
1267
  /**
1253
1268
  * Custom error class for AniList API errors.
1254
1269
  */
@@ -1256,8 +1271,8 @@ declare class AniListError extends Error {
1256
1271
  /** HTTP status code returned by the API */
1257
1272
  readonly status: number;
1258
1273
  /** Raw error body from the API response */
1259
- readonly errors: unknown[];
1260
- constructor(message: string, status: number, errors?: unknown[]);
1274
+ readonly errors: GraphQLError[];
1275
+ constructor(message: string, status: number, errors?: GraphQLError[] | unknown[]);
1261
1276
  }
1262
1277
 
1263
1278
  /**