@mittwald/react-ghostmaker 1.4.9 → 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.
@@ -1,10 +1,6 @@
1
+ import { withEachGhost } from "./withEachGhost.js";
1
2
  export async function invalidateGhosts(queryClient, queryKey) {
2
- for (let i = 1; i <= queryKey.length; i++) {
3
- const partialKey = queryKey.slice(0, i);
4
- const exact = i < queryKey.length;
5
- await queryClient.invalidateQueries({
6
- queryKey: partialKey,
7
- exact,
8
- });
9
- }
3
+ await withEachGhost(queryKey, async (filter) => {
4
+ await queryClient.invalidateQueries(filter);
5
+ });
10
6
  }
@@ -5,6 +5,7 @@ import { RenderComponent } from "./RenderComponent.js";
5
5
  import { resolveGhostChain } from "./resolveGhostChain.js";
6
6
  import { invalidateGhosts } from "./invalidate.js";
7
7
  import { queries } from "./queries.js";
8
+ import { resetGhosts } from "./reset.js";
8
9
  function buildGhostDeep(target, ghostChain) {
9
10
  const proxyTarget = (() => {
10
11
  // Dummy function to allow ghosting function calls
@@ -28,6 +29,7 @@ function buildGhostDeep(target, ghostChain) {
28
29
  return ghost;
29
30
  },
30
31
  invalidate: (queryClient) => invalidateGhosts(queryClient, queries.ghostChain(target, ghostChain)),
32
+ reset: (queryClient) => resetGhosts(queryClient, queries.ghostChain(target, ghostChain)),
31
33
  };
32
34
  const ghost = new Proxy(proxyTarget, {
33
35
  get: ($, prop) => {
@@ -0,0 +1,6 @@
1
+ import { withEachGhost } from "./withEachGhost.js";
2
+ export async function resetGhosts(queryClient, queryKey) {
3
+ await withEachGhost(queryKey, async (filter) => {
4
+ await queryClient.resetQueries(filter);
5
+ });
6
+ }
@@ -0,0 +1,10 @@
1
+ export const withEachGhost = async (queryKey, callback) => {
2
+ for (let i = 1; i <= queryKey.length; i++) {
3
+ const partialKey = queryKey.slice(0, i);
4
+ const exact = i < queryKey.length;
5
+ await callback({
6
+ queryKey: partialKey,
7
+ exact,
8
+ });
9
+ }
10
+ };
@@ -0,0 +1,3 @@
1
+ import { type QueryClient } from "@tanstack/react-query";
2
+ import type { QueryKey } from "./types.ts";
3
+ export declare function resetGhosts(queryClient: QueryClient, queryKey: QueryKey): Promise<void>;
@@ -16,6 +16,7 @@ export interface ReactGhostMethods<T> extends Promise<T> {
16
16
  render: (transform?: (item: T) => ReactNode) => ReactNode;
17
17
  transform: <U, U2 = U>(fn: (item: T extends ReactGhost<infer T2> ? T2 : T) => U2, dependencies?: DependencyList) => ReactGhost<U2>;
18
18
  invalidate: (queryClient: QueryClient) => Promise<void>;
19
+ reset: (queryClient: QueryClient) => Promise<void>;
19
20
  }
20
21
  export declare const transformFnProp: "___transformFn";
21
22
  export declare const isGhostMarker: "___ghostMarker";
@@ -0,0 +1,2 @@
1
+ import type { QueryFilters, QueryKey } from "@tanstack/react-query";
2
+ export declare const withEachGhost: (queryKey: QueryKey, callback: (queryFilters: QueryFilters) => Promise<void>) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/react-ghostmaker",
3
- "version": "1.4.9",
3
+ "version": "1.5.0",
4
4
  "author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
5
5
  "contributors": [
6
6
  "Marco Falkenberg <m.falkenberg@mittwald.de>"