tanstack-cacher 1.3.1 → 1.3.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.
Files changed (3) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +29 -0
  3. package/package.json +7 -7
package/index.d.ts CHANGED
@@ -39,6 +39,7 @@ declare class QueryCacheManager<TData, TItem> {
39
39
  getItemsFromCache(): TItem[];
40
40
  getDataFromCache(): TData | undefined;
41
41
  invalidate(): void;
42
+ refetch(key?: string | string[]): void;
42
43
  createHandlers(): CacheHandlers<TItem>;
43
44
  }
44
45
 
package/index.js CHANGED
@@ -303,6 +303,35 @@ var QueryCacheManager = class {
303
303
  invalidate() {
304
304
  this.config.queryClient.invalidateQueries({ queryKey: this.config.queryKey });
305
305
  }
306
+ /**
307
+ * Refetch query immediately
308
+ */
309
+ refetch(key) {
310
+ try {
311
+ if (!key) {
312
+ this.config.queryClient.refetchQueries({
313
+ queryKey: this.config.queryKey,
314
+ exact: true
315
+ });
316
+ return;
317
+ }
318
+ if (Array.isArray(key)) {
319
+ key.forEach((keyItem) => {
320
+ this.config.queryClient.refetchQueries({
321
+ queryKey: [keyItem],
322
+ exact: true
323
+ });
324
+ });
325
+ } else {
326
+ this.config.queryClient.refetchQueries({
327
+ queryKey: [key],
328
+ exact: true
329
+ });
330
+ }
331
+ } catch (error) {
332
+ console.error("[QueryCacheManager] Refetch failed:", error);
333
+ }
334
+ }
306
335
  /**
307
336
  * Get handlers for use with mutations
308
337
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tanstack-cacher",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
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"