ani-client 2.1.2 → 2.1.3

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/dist/index.mjs CHANGED
@@ -245,6 +245,7 @@ var NormalizedCache = class {
245
245
  if (this.maxSize > 0 && this.queryStore.size >= this.maxSize) {
246
246
  const firstKey = this.queryStore.keys().next().value;
247
247
  if (firstKey !== void 0) this.queryStore.delete(firstKey);
248
+ this.gc();
248
249
  }
249
250
  this.queryStore.set(key, { data: normalizedData, expiresAt: Date.now() + this.ttl });
250
251
  }
@@ -288,6 +289,43 @@ var NormalizedCache = class {
288
289
  this._misses = 0;
289
290
  this._stales = 0;
290
291
  }
292
+ /**
293
+ * Garbage-collect orphaned entities that are no longer referenced by any query.
294
+ * Called automatically on LRU eviction to prevent unbounded entity store growth.
295
+ */
296
+ gc() {
297
+ const referencedRefs = /* @__PURE__ */ new Set();
298
+ const collectRefs = (data) => {
299
+ if (Array.isArray(data)) {
300
+ for (const item of data) collectRefs(item);
301
+ return;
302
+ }
303
+ if (data !== null && typeof data === "object") {
304
+ const obj = data;
305
+ if (typeof obj.__ref === "string") {
306
+ referencedRefs.add(obj.__ref);
307
+ const entity = this.entityStore.get(obj.__ref);
308
+ if (entity && !referencedRefs.has(`_visited:${obj.__ref}`)) {
309
+ referencedRefs.add(`_visited:${obj.__ref}`);
310
+ collectRefs(entity);
311
+ }
312
+ return;
313
+ }
314
+ for (const v of Object.values(obj)) collectRefs(v);
315
+ }
316
+ };
317
+ for (const entry of this.queryStore.values()) {
318
+ collectRefs(entry.data);
319
+ }
320
+ let removed = 0;
321
+ for (const ref of this.entityStore.keys()) {
322
+ if (!referencedRefs.has(ref)) {
323
+ this.entityStore.delete(ref);
324
+ removed++;
325
+ }
326
+ }
327
+ return removed;
328
+ }
291
329
  };
292
330
 
293
331
  // src/cache/index.ts
@@ -313,13 +351,10 @@ var MemoryCache = class {
313
351
  return `${normalized}|${JSON.stringify(sortObjectKeys(variables))}`;
314
352
  }
315
353
  /**
316
- * Retrieve a cached value, or `undefined` if missing / expired.
354
+ * Retrieve a cached value and its stale status.
317
355
  * With stale-while-revalidate enabled, returns stale data within the grace window
318
356
  * and flags it so the caller can refresh in the background.
319
357
  */
320
- /**
321
- * Retrieve a cached value and its stale status.
322
- */
323
358
  getWithMeta(key) {
324
359
  if (!this.enabled) return void 0;
325
360
  const entry = this.store.get(key);
@@ -2188,7 +2223,11 @@ async function getReview(client, id) {
2188
2223
  }
2189
2224
  async function searchReviews(client, options = {}) {
2190
2225
  const { mediaId, userId, sort, page = 1, perPage = 20 } = options;
2191
- return client.pagedRequest(QUERY_REVIEWS, { mediaId, userId, sort, page, perPage }, "reviews");
2226
+ return client.pagedRequest(
2227
+ QUERY_REVIEWS,
2228
+ { mediaId, userId, sort, page, perPage: clampPerPage(perPage) },
2229
+ "reviews"
2230
+ );
2192
2231
  }
2193
2232
 
2194
2233
  // src/client/staff.ts
@@ -2322,7 +2361,7 @@ function mapFavorites(fav) {
2322
2361
 
2323
2362
  // src/client/index.ts
2324
2363
  var DEFAULT_API_URL = "https://graphql.anilist.co";
2325
- var LIB_VERSION = "2.1.2" ;
2364
+ var LIB_VERSION = "2.1.3" ;
2326
2365
  var AniListClient = class {
2327
2366
  apiUrl;
2328
2367
  headers;
@@ -2535,8 +2574,8 @@ var AniListClient = class {
2535
2574
  return getMediaByMalId(this, malId, type);
2536
2575
  }
2537
2576
  /** Get the detailed schedule for the current week, sorted by day. */
2538
- async getWeeklySchedule(date) {
2539
- return getWeeklySchedule(this, date);
2577
+ async getWeeklySchedule(date, idNotIn) {
2578
+ return getWeeklySchedule(this, date, idNotIn);
2540
2579
  }
2541
2580
  /** Get upcoming (not yet released) media. */
2542
2581
  async getPlanning(options = {}) {