tanstack-cacher 1.4.3 → 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 +3 -3
  2. package/index.js +7 -8
  3. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -10,7 +10,7 @@ interface PaginationConfig {
10
10
  pageSizePath?: string;
11
11
  }
12
12
  interface CacheConfig<TData, TItem> {
13
- queryClient?: QueryClient;
13
+ queryClient: QueryClient;
14
14
  queryKey: QueryKey;
15
15
  itemsPath?: string;
16
16
  pagination?: PaginationConfig;
@@ -87,7 +87,7 @@ interface CacheContextType {
87
87
 
88
88
  declare const useCacherContext: () => CacheContextType;
89
89
 
90
- 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>;
91
91
 
92
92
  declare const useQueryCacheManagers: <T extends Record<string, QueryCacheManager<any, any>>>(configs: { [K in keyof T]: {
93
93
  queryKey: readonly unknown[];
@@ -105,4 +105,4 @@ type CacheOptions<TData = any, TItem = any> = Omit<CacheConfig<TData, TItem>, 'q
105
105
  declare const resetCacheManager: (queryKey: QueryKey) => void;
106
106
  declare const resetAllCacheManagers: () => void;
107
107
 
108
- 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
@@ -82,14 +82,13 @@ var DEFAULT_PAGINATION_PATHS = {
82
82
  };
83
83
 
84
84
  // src/managers/QueryCacheManager/QueryCache.manager.ts
85
- var defaultQueryClient = new reactQuery.QueryClient();
86
85
  var QueryCacheManager = class {
87
86
  constructor(config) {
88
87
  const isPaginated = Boolean(config.pagination);
89
88
  this.config = {
90
89
  ...config,
91
90
  itemsPath: config.itemsPath ?? "data.content",
92
- queryClient: config.queryClient ?? defaultQueryClient,
91
+ queryClient: config.queryClient,
93
92
  isPaginated,
94
93
  keyExtractor: config.keyExtractor || ((item) => item.id),
95
94
  pagination: isPaginated ? {
@@ -405,8 +404,7 @@ var CacheManagerFactory = class {
405
404
  }
406
405
  create(config) {
407
406
  return new this.managerClass({
408
- ...config,
409
- queryClient: this.queryClient
407
+ ...config
410
408
  });
411
409
  }
412
410
  getManagerClass() {
@@ -415,8 +413,8 @@ var CacheManagerFactory = class {
415
413
  };
416
414
  var cacheManagerFactory = new CacheManagerFactory();
417
415
 
418
- // src/hooks/useCustomMutation.ts
419
- var useCustomMutation = (options) => {
416
+ // src/hooks/useCacherMutation.ts
417
+ var useCacherMutation = (options) => {
420
418
  const {
421
419
  onError,
422
420
  onSuccess,
@@ -430,13 +428,14 @@ var useCustomMutation = (options) => {
430
428
  ...rest
431
429
  } = options;
432
430
  const cacherContext = useCacherContext();
431
+ const queryClient = reactQuery.useQueryClient();
433
432
  const shouldNotifyError = notify || notifyError;
434
433
  const shouldNotifySuccess = notify || notifySuccess;
435
434
  const cacheActionsToRun = Array.isArray(cacheActions) ? cacheActions : cacheActions ? [cacheActions] : [];
436
435
  const runCacheActions = (data) => {
437
436
  cacheActionsToRun.forEach((action) => {
438
437
  const { type, ...config } = action;
439
- const manager = cacheManagerFactory.create(config);
438
+ const manager = cacheManagerFactory.create({ ...config, queryClient });
440
439
  runCacheManagers(type, manager, data);
441
440
  });
442
441
  };
@@ -513,7 +512,7 @@ exports.cacheManagerFactory = cacheManagerFactory;
513
512
  exports.resetAllCacheManagers = resetAllCacheManagers;
514
513
  exports.resetCacheManager = resetCacheManager;
515
514
  exports.useCacherContext = useCacherContext;
516
- exports.useCustomMutation = useCustomMutation;
515
+ exports.useCacherMutation = useCacherMutation;
517
516
  exports.useQueryCacheManagers = useQueryCacheManagers;
518
517
  Object.keys(reactQuery).forEach(function (k) {
519
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.3",
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
+ }