@mittwald/react-ghostmaker 1.5.0 → 1.5.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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { expectTypeOf, test } from "vitest";
|
|
2
2
|
import { ProjectGhost } from "./testMocks.js";
|
|
3
|
+
import { asGhost } from "./maybeGhost/asGhost.js";
|
|
3
4
|
test("return type is correct", () => {
|
|
4
5
|
const customerNameGhost = ProjectGhost.ofId("Project A")
|
|
5
6
|
.getDetailed()
|
|
@@ -23,3 +24,19 @@ test("transform return type is correct", () => {
|
|
|
23
24
|
.name.transform(() => 0);
|
|
24
25
|
expectTypeOf(transformedToNumber).toEqualTypeOf();
|
|
25
26
|
});
|
|
27
|
+
test("asGhost() works with generics", () => {
|
|
28
|
+
class A {
|
|
29
|
+
foo() {
|
|
30
|
+
//
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class B {
|
|
34
|
+
foo() {
|
|
35
|
+
//
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
function generic(prop) {
|
|
40
|
+
asGhost(prop).foo().use();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -6,6 +6,7 @@ import { queries } from "./queries.js";
|
|
|
6
6
|
import { ghostFnContext } from "./context.js";
|
|
7
7
|
import { invalidateGhosts } from "./invalidate.js";
|
|
8
8
|
import { hashObject } from "./hash.js";
|
|
9
|
+
import { resetGhosts } from "./reset.js";
|
|
9
10
|
export const useGhostChain = (target, chain, options) => {
|
|
10
11
|
const queryClient = useQueryClient();
|
|
11
12
|
const context = {
|
|
@@ -13,9 +14,11 @@ export const useGhostChain = (target, chain, options) => {
|
|
|
13
14
|
};
|
|
14
15
|
const value = chain.reduce((currentTarget, item) => useGhostChainItem(currentTarget, item, options, context), target);
|
|
15
16
|
const invalidate = () => invalidateGhosts(queryClient, queries.ghostChain(target, chain));
|
|
17
|
+
const reset = () => resetGhosts(queryClient, queries.ghostChain(target, chain));
|
|
16
18
|
return {
|
|
17
19
|
value,
|
|
18
20
|
invalidate,
|
|
21
|
+
reset,
|
|
19
22
|
};
|
|
20
23
|
};
|
|
21
24
|
const useGhostChainItem = (target, item, options = {}, context) => {
|
package/dist/types/types.d.ts
CHANGED
|
@@ -20,8 +20,9 @@ export interface ReactGhostMethods<T> extends Promise<T> {
|
|
|
20
20
|
}
|
|
21
21
|
export declare const transformFnProp: "___transformFn";
|
|
22
22
|
export declare const isGhostMarker: "___ghostMarker";
|
|
23
|
+
type GhostProp<V, TOriginal> = V extends AnyFunction ? (...args: Parameters<V>) => ReactGhost<Awaited<ReturnType<V>> | OrOptional<TOriginal>> : ReactGhost<V | OrOptional<TOriginal>>;
|
|
23
24
|
export type ReactGhost<T> = ReactGhostMethods<T> & {
|
|
24
|
-
[K in keyof NonNullable<T>]-?:
|
|
25
|
+
[K in keyof NonNullable<T>]-?: GhostProp<NonNullable<T>[K], T>;
|
|
25
26
|
};
|
|
26
27
|
export interface GhostChainItem {
|
|
27
28
|
propName: string | typeof transformFnProp;
|
|
@@ -31,12 +32,15 @@ export type GhostChain = GhostChainItem[];
|
|
|
31
32
|
export type GhostChainTargetType = UnknownRecord | Class<unknown> | null | undefined;
|
|
32
33
|
export type QueryKey = readonly unknown[];
|
|
33
34
|
export type InvalidateGhostFn = () => Promise<void>;
|
|
35
|
+
export type ResetGhostFn = () => Promise<void>;
|
|
34
36
|
export interface GhostChainContext {
|
|
35
37
|
queryKey: QueryKey;
|
|
36
38
|
}
|
|
37
39
|
export interface UseGhostReturn<T> {
|
|
38
40
|
value: T;
|
|
39
41
|
invalidate: InvalidateGhostFn;
|
|
42
|
+
reset: ResetGhostFn;
|
|
40
43
|
}
|
|
41
44
|
export declare function isReactGhost<T>(something: unknown): something is ReactGhost<T>;
|
|
42
45
|
export type ModelIdentifier = (model: unknown) => string | undefined;
|
|
46
|
+
export {};
|