tanstack-cacher 1.4.4 → 1.5.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 +5 -2
  2. package/index.js +17 -4
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -50,8 +50,11 @@ declare class QueryCacheManager<TData, TItem> {
50
50
 
51
51
  type CacheManagerConstructor = new <TData, TItem>(config: CacheConfig<TData, TItem>) => QueryCacheManager<TData, TItem>;
52
52
  declare class CacheManagerFactory {
53
+ private queryClient;
53
54
  private managerClass;
54
55
  setManagerClass(managerClass: CacheManagerConstructor): void;
56
+ setQueryClient(client: QueryClient): void;
57
+ getQueryClient(): QueryClient | null;
55
58
  resetManagerClass(): void;
56
59
  create<TData, TItem>(config: CacheConfig<TData, TItem>): QueryCacheManager<TData, TItem>;
57
60
  getManagerClass(): CacheManagerConstructor;
@@ -84,7 +87,7 @@ interface CacheContextType {
84
87
 
85
88
  declare const useCacherContext: () => CacheContextType;
86
89
 
87
- declare const useCustomMutation: <TData, TError, TVariables = void>(options: CustomMutationOptions<TData, TError, TVariables>) => _tanstack_react_query.UseMutationResult<TData, TError, TVariables, unknown>;
90
+ declare const useCacherMutation: <TData, TError, TVariables = void>(options: CustomMutationOptions<TData, TError, TVariables>) => _tanstack_react_query.UseMutationResult<TData, TError, TVariables, unknown>;
88
91
 
89
92
  declare const useQueryCacheManagers: <T extends Record<string, QueryCacheManager<any, any>>>(configs: { [K in keyof T]: {
90
93
  queryKey: readonly unknown[];
@@ -102,4 +105,4 @@ type CacheOptions<TData = any, TItem = any> = Omit<CacheConfig<TData, TItem>, 'q
102
105
  declare const resetCacheManager: (queryKey: QueryKey) => void;
103
106
  declare const resetAllCacheManagers: () => void;
104
107
 
105
- export { type CacheConfig, type CacheHandlers, type CacheManagerConstructor, type CacheOptions, CacheProvider, type CustomMutationOptions, type InsertPosition, type PaginationConfig, QueryCacheManager, cacheManagerFactory, resetAllCacheManagers, resetCacheManager, useCacherContext, useCustomMutation, useQueryCacheManagers };
108
+ export { type CacheConfig, type CacheHandlers, type CacheManagerConstructor, type CacheOptions, CacheProvider, type CustomMutationOptions, type InsertPosition, type PaginationConfig, QueryCacheManager, cacheManagerFactory, resetAllCacheManagers, resetCacheManager, useCacherContext, useCacherMutation, useQueryCacheManagers };
package/index.js CHANGED
@@ -387,16 +387,25 @@ var QueryCacheManager = class {
387
387
  // src/managers/QueryCacheManager/CacheManagerFactory.ts
388
388
  var CacheManagerFactory = class {
389
389
  constructor() {
390
+ this.queryClient = null;
390
391
  this.managerClass = QueryCacheManager;
391
392
  }
392
393
  setManagerClass(managerClass) {
393
394
  this.managerClass = managerClass;
394
395
  }
396
+ setQueryClient(client) {
397
+ this.queryClient = client;
398
+ }
399
+ getQueryClient() {
400
+ return this.queryClient;
401
+ }
395
402
  resetManagerClass() {
396
403
  this.managerClass = QueryCacheManager;
397
404
  }
398
405
  create(config) {
399
- return new this.managerClass(config);
406
+ return new this.managerClass({
407
+ ...config
408
+ });
400
409
  }
401
410
  getManagerClass() {
402
411
  return this.managerClass;
@@ -404,8 +413,8 @@ var CacheManagerFactory = class {
404
413
  };
405
414
  var cacheManagerFactory = new CacheManagerFactory();
406
415
 
407
- // src/hooks/useCustomMutation.ts
408
- var useCustomMutation = (options) => {
416
+ // src/hooks/useCacherMutation.ts
417
+ var useCacherMutation = (options) => {
409
418
  const {
410
419
  onError,
411
420
  onSuccess,
@@ -463,6 +472,10 @@ var useQueryCacheManagers = (configs) => {
463
472
  return managers;
464
473
  };
465
474
  var CacheProvider = ({ config, children }) => {
475
+ const queryClient = reactQuery.useQueryClient();
476
+ React.useEffect(() => {
477
+ cacheManagerFactory.setQueryClient(queryClient);
478
+ }, [queryClient]);
466
479
  return /* @__PURE__ */ React__default.default.createElement(CacheContext.Provider, { value: config }, children);
467
480
  };
468
481
 
@@ -499,7 +512,7 @@ exports.cacheManagerFactory = cacheManagerFactory;
499
512
  exports.resetAllCacheManagers = resetAllCacheManagers;
500
513
  exports.resetCacheManager = resetCacheManager;
501
514
  exports.useCacherContext = useCacherContext;
502
- exports.useCustomMutation = useCustomMutation;
515
+ exports.useCacherMutation = useCacherMutation;
503
516
  exports.useQueryCacheManagers = useQueryCacheManagers;
504
517
  Object.keys(reactQuery).forEach(function (k) {
505
518
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tanstack-cacher",
3
- "version": "1.4.4",
3
+ "version": "1.5.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": {
@@ -81,4 +81,4 @@
81
81
  "tsup": "^8.3.5",
82
82
  "typescript": "^5.7.2"
83
83
  }
84
- }
84
+ }