tanstack-cacher 1.5.1 → 1.6.0

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.
Files changed (3) hide show
  1. package/index.d.ts +3 -0
  2. package/index.js +22 -0
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -36,6 +36,9 @@ declare class QueryCacheManager<TData, TItem> {
36
36
  update(updatedItem: Partial<TItem>, matcher?: (item: TItem) => boolean): void;
37
37
  updateWithCustomLogic(updater: (oldData: any) => any): void;
38
38
  delete(itemOrId: TItem | string | number, matcher?: (item: TItem) => boolean): void;
39
+ updateArrayAtPath<TItem = any>(path: string, updater: TItem | TItem[] | ((items: TItem[]) => TItem[]), options?: {
40
+ position?: InsertPosition;
41
+ }): void;
39
42
  replace(newData: TData): void;
40
43
  clear(): void;
41
44
  getItemsFromCache(): TItem[];
package/index.js CHANGED
@@ -268,6 +268,28 @@ var QueryCacheManager = class {
268
268
  this.invalidate();
269
269
  }
270
270
  }
271
+ updateArrayAtPath(path, updater, options) {
272
+ try {
273
+ this.config.queryClient.setQueryData(this.config.queryKey, (oldData) => {
274
+ if (!oldData) return oldData;
275
+ const current = getAtPath(oldData, path, []);
276
+ const safeCurrent = Array.isArray(current) ? current : [];
277
+ let updatedItems;
278
+ if (typeof updater === "function") {
279
+ updatedItems = updater(safeCurrent);
280
+ } else if (Array.isArray(updater)) {
281
+ updatedItems = updater;
282
+ } else {
283
+ const position = options?.position ?? "start";
284
+ updatedItems = position === "start" ? [updater, ...safeCurrent] : [...safeCurrent, updater];
285
+ }
286
+ return setAtPath(oldData, path, updatedItems);
287
+ });
288
+ } catch (error) {
289
+ console.error("[QueryCacheManager] updateArrayAtPath failed:", error);
290
+ this.invalidate();
291
+ }
292
+ }
271
293
  /**
272
294
  * Replace full data
273
295
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tanstack-cacher",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "A lightweight cache management utility for TanStack Query that simplifies adding, updating, deleting, and synchronizing cached data",
5
5
  "license": "MIT",
6
6
  "repository": {