tanstack-cacher 1.3.1 → 1.3.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.
Files changed (3) hide show
  1. package/index.d.ts +2 -0
  2. package/index.js +35 -0
  3. package/package.json +7 -7
package/index.d.ts CHANGED
@@ -33,12 +33,14 @@ declare class QueryCacheManager<TData, TItem> {
33
33
  private updatePaginationOnRemove;
34
34
  add(newItem: TItem, position?: InsertPosition): void;
35
35
  update(updatedItem: Partial<TItem>, matcher?: (item: TItem) => boolean): void;
36
+ updateWithCustomLogic(updater: (oldData: any) => any): void;
36
37
  delete(itemOrId: TItem | string | number, matcher?: (item: TItem) => boolean): void;
37
38
  replace(newData: TData): void;
38
39
  clear(): void;
39
40
  getItemsFromCache(): TItem[];
40
41
  getDataFromCache(): TData | undefined;
41
42
  invalidate(): void;
43
+ refetch(key?: string | string[]): void;
42
44
  createHandlers(): CacheHandlers<TItem>;
43
45
  }
44
46
 
package/index.js CHANGED
@@ -217,6 +217,12 @@ var QueryCacheManager = class {
217
217
  this.invalidate();
218
218
  }
219
219
  }
220
+ updateWithCustomLogic(updater) {
221
+ this.config.queryClient.setQueryData(this.config.queryKey, (oldData) => {
222
+ if (!oldData) return oldData;
223
+ return updater(oldData);
224
+ });
225
+ }
220
226
  /**
221
227
  * Remove item from cache
222
228
  *
@@ -303,6 +309,35 @@ var QueryCacheManager = class {
303
309
  invalidate() {
304
310
  this.config.queryClient.invalidateQueries({ queryKey: this.config.queryKey });
305
311
  }
312
+ /**
313
+ * Refetch query immediately
314
+ */
315
+ refetch(key) {
316
+ try {
317
+ if (!key) {
318
+ this.config.queryClient.refetchQueries({
319
+ queryKey: this.config.queryKey,
320
+ exact: true
321
+ });
322
+ return;
323
+ }
324
+ if (Array.isArray(key)) {
325
+ key.forEach((keyItem) => {
326
+ this.config.queryClient.refetchQueries({
327
+ queryKey: [keyItem],
328
+ exact: true
329
+ });
330
+ });
331
+ } else {
332
+ this.config.queryClient.refetchQueries({
333
+ queryKey: [key],
334
+ exact: true
335
+ });
336
+ }
337
+ } catch (error) {
338
+ console.error("[QueryCacheManager] Refetch failed:", error);
339
+ }
340
+ }
306
341
  /**
307
342
  * Get handlers for use with mutations
308
343
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tanstack-cacher",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
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": {
@@ -49,15 +49,15 @@
49
49
  "node": ">=16"
50
50
  },
51
51
  "scripts": {
52
- "build": "tsup && npm run copy-dist",
53
- "copy-dist": "cp dist/index.js index.js && cp dist/index.d.ts index.d.ts",
54
- "locale-build": "tsup",
55
52
  "dev": "tsup --watch",
56
- "lint": "eslint src --ext .ts,.tsx",
57
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
53
+ "locale-build": "tsup",
58
54
  "type-check": "tsc --noEmit",
59
55
  "prepublishOnly": "npm run build",
60
- "test": "echo \"No tests yet\" && exit 0"
56
+ "lint": "eslint src --ext .ts,.tsx",
57
+ "build": "tsup && npm run copy-dist",
58
+ "test": "echo \"No tests yet\" && exit 0",
59
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
60
+ "copy-dist": "cp dist/index.js index.js && cp dist/index.d.ts index.d.ts"
61
61
  },
62
62
  "dependencies": {
63
63
  "@tanstack/react-query": "^5.62.11"