@khanacademy/wonder-blocks-data 10.0.5 → 10.1.1
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.
- package/CHANGELOG.md +38 -0
- package/dist/components/data.d.ts +52 -0
- package/dist/components/data.js.flow +63 -0
- package/dist/components/gql-router.d.ts +24 -0
- package/dist/components/gql-router.js.flow +33 -0
- package/dist/components/intercept-context.d.ts +10 -0
- package/dist/components/intercept-context.js.flow +19 -0
- package/dist/components/intercept-requests.d.ts +42 -0
- package/dist/components/intercept-requests.js.flow +51 -0
- package/dist/components/track-data.d.ts +11 -0
- package/dist/components/track-data.js.flow +18 -0
- package/dist/es/index.js +196 -214
- package/dist/hooks/use-cached-effect.d.ts +70 -0
- package/dist/hooks/use-cached-effect.js.flow +85 -0
- package/dist/hooks/use-gql-router-context.d.ts +5 -0
- package/dist/hooks/use-gql-router-context.js.flow +15 -0
- package/dist/hooks/use-gql.d.ts +12 -0
- package/dist/hooks/use-gql.js.flow +29 -0
- package/dist/hooks/use-hydratable-effect.d.ts +102 -0
- package/dist/hooks/use-hydratable-effect.js.flow +125 -0
- package/dist/hooks/use-request-interception.d.ts +14 -0
- package/dist/hooks/use-request-interception.js.flow +25 -0
- package/dist/hooks/use-server-effect.d.ts +39 -0
- package/dist/hooks/use-server-effect.js.flow +51 -0
- package/dist/hooks/use-shared-cache.d.ts +32 -0
- package/dist/hooks/use-shared-cache.js.flow +43 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +198 -219
- package/dist/index.js.flow +48 -2
- package/dist/util/data-error.d.ts +45 -0
- package/dist/util/data-error.js.flow +64 -0
- package/dist/util/get-gql-data-from-response.d.ts +4 -0
- package/dist/util/get-gql-data-from-response.js.flow +13 -0
- package/dist/util/get-gql-request-id.d.ts +5 -0
- package/dist/util/get-gql-request-id.js.flow +20 -0
- package/dist/util/gql-error.d.ts +28 -0
- package/dist/util/gql-error.js.flow +43 -0
- package/dist/util/gql-router-context.d.ts +3 -0
- package/dist/util/gql-router-context.js.flow +10 -0
- package/dist/util/gql-types.d.ts +34 -0
- package/dist/util/gql-types.js.flow +53 -0
- package/dist/util/graphql-document-node-parser.d.ts +18 -0
- package/dist/util/graphql-document-node-parser.js.flow +31 -0
- package/dist/util/graphql-types.d.ts +19 -0
- package/dist/util/graphql-types.js.flow +30 -0
- package/dist/util/hydration-cache-api.d.ts +17 -0
- package/dist/util/hydration-cache-api.js.flow +30 -0
- package/dist/util/merge-gql-context.d.ts +8 -0
- package/dist/util/merge-gql-context.js.flow +19 -0
- package/dist/util/purge-caches.d.ts +8 -0
- package/dist/util/purge-caches.js.flow +15 -0
- package/dist/util/request-api.d.ts +28 -0
- package/dist/util/request-api.js.flow +34 -0
- package/dist/util/request-fulfillment.d.ts +37 -0
- package/dist/util/request-fulfillment.js.flow +50 -0
- package/dist/util/request-tracking.d.ts +62 -0
- package/dist/util/request-tracking.js.flow +81 -0
- package/dist/util/result-from-cache-response.d.ts +5 -0
- package/dist/util/result-from-cache-response.js.flow +15 -0
- package/dist/util/scoped-in-memory-cache.d.ts +38 -0
- package/dist/util/scoped-in-memory-cache.js.flow +57 -0
- package/dist/util/serializable-in-memory-cache.d.ts +16 -0
- package/dist/util/serializable-in-memory-cache.js.flow +26 -0
- package/dist/util/ssr-cache.d.ts +51 -0
- package/dist/util/ssr-cache.js.flow +87 -0
- package/dist/util/status.d.ts +10 -0
- package/dist/util/status.js.flow +19 -0
- package/dist/util/to-gql-operation.d.ts +32 -0
- package/dist/util/to-gql-operation.js.flow +45 -0
- package/dist/util/types.d.ts +111 -0
- package/dist/util/types.js.flow +151 -0
- package/package.json +5 -6
- package/src/components/__tests__/{data.test.js → data.test.tsx} +50 -16
- package/src/components/__tests__/{gql-router.test.js → gql-router.test.tsx} +6 -7
- package/src/components/__tests__/{intercept-requests.test.js → intercept-requests.test.tsx} +4 -5
- package/src/components/__tests__/{track-data.test.js → track-data.test.tsx} +4 -5
- package/src/components/{data.js → data.ts} +13 -21
- package/src/components/{gql-router.js → gql-router.tsx} +14 -16
- package/src/components/{intercept-context.js → intercept-context.ts} +5 -4
- package/src/components/{intercept-requests.js → intercept-requests.tsx} +9 -10
- package/src/components/{track-data.js → track-data.tsx} +5 -6
- package/src/hooks/__tests__/{use-cached-effect.test.js → use-cached-effect.test.tsx} +65 -63
- package/src/hooks/__tests__/{use-gql-router-context.test.js → use-gql-router-context.test.tsx} +9 -9
- package/src/hooks/__tests__/{use-gql.test.js → use-gql.test.tsx} +23 -24
- package/src/hooks/__tests__/{use-hydratable-effect.test.js → use-hydratable-effect.test.ts} +52 -54
- package/src/hooks/__tests__/{use-request-interception.test.js → use-request-interception.test.tsx} +7 -5
- package/src/hooks/__tests__/{use-server-effect.test.js → use-server-effect.test.ts} +16 -10
- package/src/hooks/__tests__/{use-shared-cache.test.js → use-shared-cache.test.ts} +13 -13
- package/src/hooks/{use-cached-effect.js → use-cached-effect.ts} +34 -31
- package/src/hooks/{use-gql-router-context.js → use-gql-router-context.ts} +6 -7
- package/src/hooks/{use-gql.js → use-gql.ts} +9 -9
- package/src/hooks/{use-hydratable-effect.js → use-hydratable-effect.ts} +60 -67
- package/src/hooks/{use-request-interception.js → use-request-interception.ts} +6 -6
- package/src/hooks/{use-server-effect.js → use-server-effect.ts} +12 -14
- package/src/hooks/{use-shared-cache.js → use-shared-cache.ts} +16 -11
- package/src/index.ts +46 -0
- package/src/util/__tests__/{get-gql-data-from-response.test.js → get-gql-data-from-response.test.ts} +1 -2
- package/src/util/__tests__/{get-gql-request-id.test.js → get-gql-request-id.test.ts} +10 -12
- package/src/util/__tests__/{graphql-document-node-parser.test.js → graphql-document-node-parser.test.ts} +12 -13
- package/src/util/__tests__/{hydration-cache-api.test.js → hydration-cache-api.test.ts} +3 -4
- package/src/util/__tests__/{merge-gql-context.test.js → merge-gql-context.test.ts} +5 -6
- package/src/util/__tests__/{purge-caches.test.js → purge-caches.test.ts} +3 -4
- package/src/util/__tests__/{request-api.test.js → request-api.test.ts} +5 -5
- package/src/util/__tests__/{request-fulfillment.test.js → request-fulfillment.test.ts} +2 -3
- package/src/util/__tests__/{request-tracking.test.js → request-tracking.test.tsx} +15 -8
- package/src/util/__tests__/{result-from-cache-response.test.js → result-from-cache-response.test.ts} +3 -5
- package/src/util/__tests__/{scoped-in-memory-cache.test.js → scoped-in-memory-cache.test.ts} +5 -6
- package/src/util/__tests__/{serializable-in-memory-cache.test.js → serializable-in-memory-cache.test.ts} +8 -8
- package/src/util/__tests__/{ssr-cache.test.js → ssr-cache.test.ts} +5 -4
- package/src/util/__tests__/{to-gql-operation.test.js → to-gql-operation.test.ts} +5 -4
- package/src/util/{data-error.js → data-error.ts} +3 -4
- package/src/util/{get-gql-data-from-response.js → get-gql-data-from-response.ts} +3 -8
- package/src/util/{get-gql-request-id.js → get-gql-request-id.ts} +13 -17
- package/src/util/{gql-error.js → gql-error.ts} +3 -4
- package/src/util/gql-router-context.ts +6 -0
- package/src/util/{gql-types.js → gql-types.ts} +27 -23
- package/src/util/{graphql-document-node-parser.js → graphql-document-node-parser.ts} +8 -9
- package/src/util/graphql-types.ts +27 -0
- package/src/util/{hydration-cache-api.js → hydration-cache-api.ts} +6 -4
- package/src/util/{merge-gql-context.js → merge-gql-context.ts} +3 -3
- package/src/util/{purge-caches.js → purge-caches.ts} +2 -3
- package/src/util/{request-api.js → request-api.ts} +4 -5
- package/src/util/{request-fulfillment.js → request-fulfillment.ts} +15 -14
- package/src/util/{request-tracking.js → request-tracking.ts} +15 -16
- package/src/util/{result-from-cache-response.js → result-from-cache-response.ts} +6 -7
- package/src/util/{scoped-in-memory-cache.js → scoped-in-memory-cache.ts} +3 -4
- package/src/util/{serializable-in-memory-cache.js → serializable-in-memory-cache.ts} +5 -6
- package/src/util/{ssr-cache.js → ssr-cache.ts} +21 -20
- package/src/util/{status.js → status.ts} +5 -6
- package/src/util/{to-gql-operation.js → to-gql-operation.ts} +4 -5
- package/src/util/{types.js → types.ts} +41 -49
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/__docs__/_overview_.stories.mdx +0 -18
- package/src/__docs__/_overview_graphql.stories.mdx +0 -35
- package/src/__docs__/_overview_ssr_.stories.mdx +0 -185
- package/src/__docs__/_overview_testing_.stories.mdx +0 -123
- package/src/__docs__/exports.abort-inflight-requests.stories.mdx +0 -20
- package/src/__docs__/exports.data-error.stories.mdx +0 -23
- package/src/__docs__/exports.data-errors.stories.mdx +0 -23
- package/src/__docs__/exports.data.stories.mdx +0 -146
- package/src/__docs__/exports.fetch-tracked-requests.stories.mdx +0 -24
- package/src/__docs__/exports.get-gql-request-id.stories.mdx +0 -24
- package/src/__docs__/exports.gql-error.stories.mdx +0 -23
- package/src/__docs__/exports.gql-errors.stories.mdx +0 -20
- package/src/__docs__/exports.gql-router.stories.mdx +0 -29
- package/src/__docs__/exports.has-tracked-requests-to-be-fetched.stories.mdx +0 -20
- package/src/__docs__/exports.intercept-requests.stories.mdx +0 -69
- package/src/__docs__/exports.intialize-hydration-cache.stories.mdx +0 -29
- package/src/__docs__/exports.purge-caches.stories.mdx +0 -23
- package/src/__docs__/exports.purge-hydration-cache.stories.mdx +0 -24
- package/src/__docs__/exports.scoped-in-memory-cache.stories.mdx +0 -92
- package/src/__docs__/exports.serializable-in-memory-cache.stories.mdx +0 -112
- package/src/__docs__/exports.shared-cache.stories.mdx +0 -16
- package/src/__docs__/exports.status.stories.mdx +0 -31
- package/src/__docs__/exports.track-data.stories.mdx +0 -209
- package/src/__docs__/exports.use-cached-effect.stories.mdx +0 -44
- package/src/__docs__/exports.use-gql.stories.mdx +0 -41
- package/src/__docs__/exports.use-hydratable-effect.stories.mdx +0 -43
- package/src/__docs__/exports.use-server-effect.stories.mdx +0 -50
- package/src/__docs__/exports.use-shared-cache.stories.mdx +0 -30
- package/src/__docs__/exports.when-client-side.stories.mdx +0 -33
- package/src/__docs__/types.cached-response.stories.mdx +0 -29
- package/src/__docs__/types.error-options.stories.mdx +0 -21
- package/src/__docs__/types.fetch-policy.stories.mdx +0 -44
- package/src/__docs__/types.gql-context.stories.mdx +0 -20
- package/src/__docs__/types.gql-fetch-fn.stories.mdx +0 -24
- package/src/__docs__/types.gql-fetch-options.stories.mdx +0 -24
- package/src/__docs__/types.gql-operation-type.stories.mdx +0 -24
- package/src/__docs__/types.gql-operation.stories.mdx +0 -67
- package/src/__docs__/types.raw-scoped-cache.stories.mdx +0 -27
- package/src/__docs__/types.response-cache.stories.mdx +0 -33
- package/src/__docs__/types.result.stories.mdx +0 -39
- package/src/__docs__/types.scoped-cache.stories.mdx +0 -114
- package/src/__docs__/types.valid-cache-data.stories.mdx +0 -23
- package/src/index.js +0 -55
- package/src/util/gql-router-context.js +0 -6
- package/src/util/graphql-types.js +0 -30
- /package/src/hooks/__tests__/__snapshots__/{use-shared-cache.test.js.snap → use-shared-cache.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{scoped-in-memory-cache.test.js.snap → scoped-in-memory-cache.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{serializable-in-memory-cache.test.js.snap → serializable-in-memory-cache.test.ts.snap} +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Metadata } from "@khanacademy/wonder-stuff-core";
|
|
2
|
+
/**
|
|
3
|
+
* Defines the various fetch policies that can be applied to requests.
|
|
4
|
+
*/
|
|
5
|
+
export declare const FetchPolicy: {
|
|
6
|
+
/**
|
|
7
|
+
* If the data is in the cache, return that; otherwise, fetch from the
|
|
8
|
+
* server.
|
|
9
|
+
*/
|
|
10
|
+
readonly CacheBeforeNetwork: "CacheBeforeNetwork";
|
|
11
|
+
/**
|
|
12
|
+
* If the data is in the cache, return that; always fetch from the server
|
|
13
|
+
* regardless of cache.
|
|
14
|
+
*/
|
|
15
|
+
readonly CacheAndNetwork: "CacheAndNetwork";
|
|
16
|
+
/**
|
|
17
|
+
* If the data is in the cache, return that; otherwise, do nothing.
|
|
18
|
+
*/
|
|
19
|
+
readonly CacheOnly: "CacheOnly";
|
|
20
|
+
/**
|
|
21
|
+
* Ignore any existing cached result; always fetch from the server.
|
|
22
|
+
*/
|
|
23
|
+
readonly NetworkOnly: "NetworkOnly";
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Define what can be cached.
|
|
27
|
+
*
|
|
28
|
+
* We disallow functions and undefined as undefined represents a cache miss
|
|
29
|
+
* and functions are not allowed.
|
|
30
|
+
*/
|
|
31
|
+
export type ValidCacheData = string | boolean | number | Record<any, any> | Array<ValidCacheData | null | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* The normalized result of a request.
|
|
34
|
+
*/
|
|
35
|
+
export type Result<TData extends ValidCacheData> = {
|
|
36
|
+
status: "loading";
|
|
37
|
+
} | {
|
|
38
|
+
status: "success";
|
|
39
|
+
data: TData;
|
|
40
|
+
} | {
|
|
41
|
+
status: "error";
|
|
42
|
+
error: Error;
|
|
43
|
+
} | {
|
|
44
|
+
status: "aborted";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A cache entry for a fulfilled request response.
|
|
48
|
+
*/
|
|
49
|
+
export type CachedResponse<TData extends ValidCacheData> = {
|
|
50
|
+
readonly error: string;
|
|
51
|
+
readonly data?: undefined;
|
|
52
|
+
} | {
|
|
53
|
+
readonly data: TData;
|
|
54
|
+
readonly error?: undefined;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* A cache of fulfilled request responses.
|
|
58
|
+
*/
|
|
59
|
+
export type ResponseCache = {
|
|
60
|
+
[key: string]: CachedResponse<any>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* A cache with scoped sections.
|
|
64
|
+
*/
|
|
65
|
+
export type RawScopedCache = {
|
|
66
|
+
/**
|
|
67
|
+
* The cache is scoped to allow easier clearing of different types of usage.
|
|
68
|
+
*/
|
|
69
|
+
[scope: string]: {
|
|
70
|
+
/**
|
|
71
|
+
* Each value in the cache is then identified within a given scope.
|
|
72
|
+
*/
|
|
73
|
+
[id: string]: ValidCacheData;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Options to pass to error construction.
|
|
78
|
+
*/
|
|
79
|
+
export type ErrorOptions = {
|
|
80
|
+
/**
|
|
81
|
+
* Metadata to attach to the error.
|
|
82
|
+
*/
|
|
83
|
+
metadata?: Metadata | null | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* The error that caused the error being constructed.
|
|
86
|
+
*/
|
|
87
|
+
cause?: Error | null | undefined;
|
|
88
|
+
};
|
|
89
|
+
export interface ScopedCache {
|
|
90
|
+
set(scope: string, id: string, value: ValidCacheData): void;
|
|
91
|
+
/**
|
|
92
|
+
* Retrieve a value from the cache.
|
|
93
|
+
*/
|
|
94
|
+
get(scope: string, id: string): ValidCacheData | null | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Purge an item from the cache.
|
|
97
|
+
*/
|
|
98
|
+
purge(scope: string, id: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Purge a scope of items that match the given predicate.
|
|
101
|
+
*
|
|
102
|
+
* If the predicate is omitted, then all items in the scope are purged.
|
|
103
|
+
*/
|
|
104
|
+
purgeScope(scope: string, predicate?: (id: string, value: ValidCacheData) => boolean): void;
|
|
105
|
+
/**
|
|
106
|
+
* Purge all items from the cache that match the given predicate.
|
|
107
|
+
*
|
|
108
|
+
* If the predicate is omitted, then all items in the cache are purged.
|
|
109
|
+
*/
|
|
110
|
+
purgeAll(predicate?: (scope: string, id: string, value: ValidCacheData) => boolean): void;
|
|
111
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Metadata } from "@khanacademy/wonder-stuff-core";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Defines the various fetch policies that can be applied to requests.
|
|
12
|
+
*/
|
|
13
|
+
declare export var FetchPolicy: {
|
|
14
|
+
/**
|
|
15
|
+
* If the data is in the cache, return that; otherwise, fetch from the
|
|
16
|
+
* server.
|
|
17
|
+
*/
|
|
18
|
+
+CacheBeforeNetwork: "CacheBeforeNetwork",
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* If the data is in the cache, return that; always fetch from the server
|
|
22
|
+
* regardless of cache.
|
|
23
|
+
*/
|
|
24
|
+
+CacheAndNetwork: "CacheAndNetwork",
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* If the data is in the cache, return that; otherwise, do nothing.
|
|
28
|
+
*/
|
|
29
|
+
+CacheOnly: "CacheOnly",
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Ignore any existing cached result; always fetch from the server.
|
|
33
|
+
*/
|
|
34
|
+
+NetworkOnly: "NetworkOnly",
|
|
35
|
+
...
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Define what can be cached.
|
|
39
|
+
*
|
|
40
|
+
* We disallow functions and undefined as undefined represents a cache miss
|
|
41
|
+
* and functions are not allowed.
|
|
42
|
+
*/
|
|
43
|
+
export type ValidCacheData =
|
|
44
|
+
| string
|
|
45
|
+
| boolean
|
|
46
|
+
| number
|
|
47
|
+
| { [key: any]: any, ... }
|
|
48
|
+
| Array<ValidCacheData | null | void>;
|
|
49
|
+
/**
|
|
50
|
+
* The normalized result of a request.
|
|
51
|
+
*/
|
|
52
|
+
export type Result<TData: ValidCacheData> =
|
|
53
|
+
| {
|
|
54
|
+
status: "loading",
|
|
55
|
+
...
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
status: "success",
|
|
59
|
+
data: TData,
|
|
60
|
+
...
|
|
61
|
+
}
|
|
62
|
+
| {
|
|
63
|
+
status: "error",
|
|
64
|
+
error: Error,
|
|
65
|
+
...
|
|
66
|
+
}
|
|
67
|
+
| {
|
|
68
|
+
status: "aborted",
|
|
69
|
+
...
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* A cache entry for a fulfilled request response.
|
|
73
|
+
*/
|
|
74
|
+
export type CachedResponse<TData: ValidCacheData> =
|
|
75
|
+
| {
|
|
76
|
+
+error: string,
|
|
77
|
+
+data?: void,
|
|
78
|
+
...
|
|
79
|
+
}
|
|
80
|
+
| {
|
|
81
|
+
+data: TData,
|
|
82
|
+
+error?: void,
|
|
83
|
+
...
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* A cache of fulfilled request responses.
|
|
87
|
+
*/
|
|
88
|
+
export type ResponseCache = {
|
|
89
|
+
[key: string]: CachedResponse<any>,
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* A cache with scoped sections.
|
|
93
|
+
*/
|
|
94
|
+
export type RawScopedCache = {
|
|
95
|
+
/**
|
|
96
|
+
* The cache is scoped to allow easier clearing of different types of usage.
|
|
97
|
+
*/
|
|
98
|
+
[scope: string]: {
|
|
99
|
+
/**
|
|
100
|
+
* Each value in the cache is then identified within a given scope.
|
|
101
|
+
*/
|
|
102
|
+
[id: string]: ValidCacheData,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Options to pass to error construction.
|
|
107
|
+
*/
|
|
108
|
+
export type ErrorOptions = {
|
|
109
|
+
/**
|
|
110
|
+
* Metadata to attach to the error.
|
|
111
|
+
*/
|
|
112
|
+
metadata?: Metadata | null | void,
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The error that caused the error being constructed.
|
|
116
|
+
*/
|
|
117
|
+
cause?: Error | null | void,
|
|
118
|
+
...
|
|
119
|
+
};
|
|
120
|
+
export interface ScopedCache {
|
|
121
|
+
set(scope: string, id: string, value: ValidCacheData): void;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Retrieve a value from the cache.
|
|
125
|
+
*/
|
|
126
|
+
get(scope: string, id: string): ValidCacheData | null | void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Purge an item from the cache.
|
|
130
|
+
*/
|
|
131
|
+
purge(scope: string, id: string): void;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Purge a scope of items that match the given predicate.
|
|
135
|
+
*
|
|
136
|
+
* If the predicate is omitted, then all items in the scope are purged.
|
|
137
|
+
*/
|
|
138
|
+
purgeScope(
|
|
139
|
+
scope: string,
|
|
140
|
+
predicate?: (id: string, value: ValidCacheData) => boolean
|
|
141
|
+
): void;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Purge all items from the cache that match the given predicate.
|
|
145
|
+
*
|
|
146
|
+
* If the predicate is omitted, then all items in the cache are purged.
|
|
147
|
+
*/
|
|
148
|
+
purgeAll(
|
|
149
|
+
predicate?: (scope: string, id: string, value: ValidCacheData) => boolean
|
|
150
|
+
): void;
|
|
151
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-data",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.1.1",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,21 +8,20 @@
|
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/es/index.js",
|
|
11
|
-
"
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.18.6",
|
|
17
|
-
"@khanacademy/wonder-blocks-core": "^4.
|
|
17
|
+
"@khanacademy/wonder-blocks-core": "^4.8.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@khanacademy/wonder-stuff-core": "^1.2.
|
|
21
|
-
"flow-enums-runtime": "^0.0.6",
|
|
20
|
+
"@khanacademy/wonder-stuff-core": "^1.2.2",
|
|
22
21
|
"react": "16.14.0"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
|
-
"wb-dev-build-settings": "^0.7.
|
|
24
|
+
"wb-dev-build-settings": "^0.7.2"
|
|
26
25
|
},
|
|
27
26
|
"author": "",
|
|
28
27
|
"license": "MIT"
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
|
-
// @flow
|
|
3
2
|
import * as React from "react";
|
|
4
3
|
import {render, act} from "@testing-library/react";
|
|
5
4
|
|
|
@@ -7,20 +6,14 @@ import {render, act} from "@testing-library/react";
|
|
|
7
6
|
import * as ReactDOMServer from "react-dom/server";
|
|
8
7
|
import {Server, View} from "@khanacademy/wonder-blocks-core";
|
|
9
8
|
|
|
10
|
-
import {SharedCache} from "../../hooks/use-shared-cache
|
|
11
|
-
import TrackData from "../track-data
|
|
12
|
-
import {RequestFulfillment} from "../../util/request-fulfillment
|
|
13
|
-
import {SsrCache} from "../../util/ssr-cache
|
|
14
|
-
import {RequestTracker} from "../../util/request-tracking
|
|
15
|
-
import InterceptRequests from "../intercept-requests
|
|
16
|
-
import Data from "../data
|
|
17
|
-
import {
|
|
18
|
-
// TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
|
|
19
|
-
// have fixed:
|
|
20
|
-
// https://github.com/import-js/eslint-plugin-import/issues/2073
|
|
21
|
-
// eslint-disable-next-line import/named
|
|
22
|
-
WhenClientSide,
|
|
23
|
-
} from "../../hooks/use-hydratable-effect.js";
|
|
9
|
+
import {SharedCache} from "../../hooks/use-shared-cache";
|
|
10
|
+
import TrackData from "../track-data";
|
|
11
|
+
import {RequestFulfillment} from "../../util/request-fulfillment";
|
|
12
|
+
import {SsrCache} from "../../util/ssr-cache";
|
|
13
|
+
import {RequestTracker} from "../../util/request-tracking";
|
|
14
|
+
import InterceptRequests from "../intercept-requests";
|
|
15
|
+
import Data from "../data";
|
|
16
|
+
import {WhenClientSide} from "../../hooks/use-hydratable-effect";
|
|
24
17
|
|
|
25
18
|
describe("Data", () => {
|
|
26
19
|
beforeEach(() => {
|
|
@@ -61,9 +54,11 @@ describe("Data", () => {
|
|
|
61
54
|
// Act
|
|
62
55
|
render(
|
|
63
56
|
<Data handler={fakeHandler} requestId="ID">
|
|
57
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
64
58
|
{fakeChildrenFn}
|
|
65
59
|
</Data>,
|
|
66
60
|
);
|
|
61
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
67
62
|
await act(() => response);
|
|
68
63
|
|
|
69
64
|
// Assert
|
|
@@ -79,9 +74,11 @@ describe("Data", () => {
|
|
|
79
74
|
// Act
|
|
80
75
|
render(
|
|
81
76
|
<Data handler={fakeHandler} requestId="ID">
|
|
77
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
82
78
|
{fakeChildrenFn}
|
|
83
79
|
</Data>,
|
|
84
80
|
);
|
|
81
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
85
82
|
await act(() => response);
|
|
86
83
|
|
|
87
84
|
// Assert
|
|
@@ -93,7 +90,7 @@ describe("Data", () => {
|
|
|
93
90
|
it("should share single request across all uses", () => {
|
|
94
91
|
// Arrange
|
|
95
92
|
const fakeHandler = jest.fn(
|
|
96
|
-
() => new Promise((resolve, reject) => {}),
|
|
93
|
+
() => new Promise((resolve: any, reject: any) => {}),
|
|
97
94
|
);
|
|
98
95
|
const fakeChildrenFn = jest.fn(() => null);
|
|
99
96
|
|
|
@@ -101,9 +98,11 @@ describe("Data", () => {
|
|
|
101
98
|
render(
|
|
102
99
|
<View>
|
|
103
100
|
<Data handler={fakeHandler} requestId="ID">
|
|
101
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
104
102
|
{fakeChildrenFn}
|
|
105
103
|
</Data>
|
|
106
104
|
<Data handler={fakeHandler} requestId="ID">
|
|
105
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
107
106
|
{fakeChildrenFn}
|
|
108
107
|
</Data>
|
|
109
108
|
</View>,
|
|
@@ -125,6 +124,7 @@ describe("Data", () => {
|
|
|
125
124
|
// Act
|
|
126
125
|
render(
|
|
127
126
|
<Data handler={fakeHandler} requestId="ID">
|
|
127
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
128
128
|
{fakeChildrenFn}
|
|
129
129
|
</Data>,
|
|
130
130
|
);
|
|
@@ -159,6 +159,7 @@ describe("Data", () => {
|
|
|
159
159
|
// Act
|
|
160
160
|
render(
|
|
161
161
|
<Data handler={fakeHandler} requestId="ID">
|
|
162
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
162
163
|
{fakeChildrenFn}
|
|
163
164
|
</Data>,
|
|
164
165
|
);
|
|
@@ -190,6 +191,7 @@ describe("Data", () => {
|
|
|
190
191
|
// Act
|
|
191
192
|
render(
|
|
192
193
|
<Data handler={fakeHandler} requestId="ID">
|
|
194
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
193
195
|
{fakeChildrenFn}
|
|
194
196
|
</Data>,
|
|
195
197
|
);
|
|
@@ -220,6 +222,7 @@ describe("Data", () => {
|
|
|
220
222
|
// Act
|
|
221
223
|
render(
|
|
222
224
|
<Data handler={fakeHandler} requestId="ID">
|
|
225
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
223
226
|
{fakeChildrenFn}
|
|
224
227
|
</Data>,
|
|
225
228
|
);
|
|
@@ -249,6 +252,7 @@ describe("Data", () => {
|
|
|
249
252
|
const fakeChildrenFn = jest.fn(() => null);
|
|
250
253
|
const wrapper = render(
|
|
251
254
|
<Data handler={fakeHandler} requestId="ID">
|
|
255
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
252
256
|
{fakeChildrenFn}
|
|
253
257
|
</Data>,
|
|
254
258
|
);
|
|
@@ -261,6 +265,7 @@ describe("Data", () => {
|
|
|
261
265
|
// Act
|
|
262
266
|
wrapper.rerender(
|
|
263
267
|
<Data handler={fakeHandler} requestId="NEW_ID">
|
|
268
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
264
269
|
{fakeChildrenFn}
|
|
265
270
|
</Data>,
|
|
266
271
|
);
|
|
@@ -291,14 +296,17 @@ describe("Data", () => {
|
|
|
291
296
|
const fakeChildrenFn = jest.fn(() => null);
|
|
292
297
|
const wrapper = render(
|
|
293
298
|
<Data handler={oldHandler} requestId="ID">
|
|
299
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
294
300
|
{fakeChildrenFn}
|
|
295
301
|
</Data>,
|
|
296
302
|
);
|
|
297
303
|
wrapper.rerender(
|
|
298
304
|
<Data handler={oldHandler} requestId="NEW_ID">
|
|
305
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
299
306
|
{fakeChildrenFn}
|
|
300
307
|
</Data>,
|
|
301
308
|
);
|
|
309
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
302
310
|
await act(() => oldRequest);
|
|
303
311
|
|
|
304
312
|
// Assert
|
|
@@ -324,11 +332,13 @@ describe("Data", () => {
|
|
|
324
332
|
const fakeChildrenFn = jest.fn(() => null);
|
|
325
333
|
const wrapper = render(
|
|
326
334
|
<Data handler={oldHandler} requestId="ID">
|
|
335
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
327
336
|
{fakeChildrenFn}
|
|
328
337
|
</Data>,
|
|
329
338
|
);
|
|
330
339
|
wrapper.rerender(
|
|
331
340
|
<Data handler={oldHandler} requestId="NEW_ID">
|
|
341
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
332
342
|
{fakeChildrenFn}
|
|
333
343
|
</Data>,
|
|
334
344
|
);
|
|
@@ -354,6 +364,7 @@ describe("Data", () => {
|
|
|
354
364
|
jest.spyOn(
|
|
355
365
|
RequestFulfillment.Default,
|
|
356
366
|
"fulfill",
|
|
367
|
+
// @ts-expect-error [FEI-5019] - TS2345 - Argument of type 'Promise<{ status: string; error: Error; }>' is not assignable to parameter of type 'Promise<Result<ValidCacheData>>'.
|
|
357
368
|
).mockReturnValueOnce(catastrophe);
|
|
358
369
|
const oldHandler = jest.fn().mockResolvedValue("OLD DATA");
|
|
359
370
|
|
|
@@ -361,15 +372,18 @@ describe("Data", () => {
|
|
|
361
372
|
const fakeChildrenFn = jest.fn(() => null);
|
|
362
373
|
const wrapper = render(
|
|
363
374
|
<Data handler={oldHandler} requestId="ID">
|
|
375
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
364
376
|
{fakeChildrenFn}
|
|
365
377
|
</Data>,
|
|
366
378
|
);
|
|
367
379
|
wrapper.rerender(
|
|
368
380
|
<Data handler={oldHandler} requestId="NEW_ID">
|
|
381
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
369
382
|
{fakeChildrenFn}
|
|
370
383
|
</Data>,
|
|
371
384
|
);
|
|
372
385
|
await act(() =>
|
|
386
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
373
387
|
catastrophe.catch(() => {
|
|
374
388
|
/* ignore */
|
|
375
389
|
}),
|
|
@@ -395,6 +409,7 @@ describe("Data", () => {
|
|
|
395
409
|
render(
|
|
396
410
|
<InterceptRequests interceptor={interceptHandler}>
|
|
397
411
|
<Data handler={fakeHandler} requestId="ID">
|
|
412
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
398
413
|
{fakeChildrenFn}
|
|
399
414
|
</Data>
|
|
400
415
|
</InterceptRequests>,
|
|
@@ -416,6 +431,7 @@ describe("Data", () => {
|
|
|
416
431
|
render(
|
|
417
432
|
<InterceptRequests interceptor={interceptHandler}>
|
|
418
433
|
<Data handler={fakeHandler} requestId="ID">
|
|
434
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
419
435
|
{fakeChildrenFn}
|
|
420
436
|
</Data>
|
|
421
437
|
</InterceptRequests>,
|
|
@@ -443,10 +459,12 @@ describe("Data", () => {
|
|
|
443
459
|
requestId="ID1"
|
|
444
460
|
retainResultOnChange={true}
|
|
445
461
|
>
|
|
462
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
446
463
|
{fakeChildrenFn}
|
|
447
464
|
</Data>,
|
|
448
465
|
);
|
|
449
466
|
fakeChildrenFn.mockClear();
|
|
467
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
450
468
|
await act(() => response1);
|
|
451
469
|
wrapper.rerender(
|
|
452
470
|
<Data
|
|
@@ -454,9 +472,11 @@ describe("Data", () => {
|
|
|
454
472
|
requestId="ID2"
|
|
455
473
|
retainResultOnChange={true}
|
|
456
474
|
>
|
|
475
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
457
476
|
{fakeChildrenFn}
|
|
458
477
|
</Data>,
|
|
459
478
|
);
|
|
479
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
460
480
|
await act(() => response2);
|
|
461
481
|
|
|
462
482
|
// Assert
|
|
@@ -498,6 +518,7 @@ describe("Data", () => {
|
|
|
498
518
|
// Act
|
|
499
519
|
render(
|
|
500
520
|
<Data handler={fakeHandler} requestId="ID">
|
|
521
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
501
522
|
{fakeChildrenFn}
|
|
502
523
|
</Data>,
|
|
503
524
|
);
|
|
@@ -523,6 +544,7 @@ describe("Data", () => {
|
|
|
523
544
|
WhenClientSide.ExecuteWhenNoSuccessResult
|
|
524
545
|
}
|
|
525
546
|
>
|
|
547
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
526
548
|
{fakeChildrenFn}
|
|
527
549
|
</Data>,
|
|
528
550
|
);
|
|
@@ -543,6 +565,7 @@ describe("Data", () => {
|
|
|
543
565
|
requestId="ID"
|
|
544
566
|
clientBehavior={WhenClientSide.AlwaysExecute}
|
|
545
567
|
>
|
|
568
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
546
569
|
{fakeChildrenFn}
|
|
547
570
|
</Data>,
|
|
548
571
|
);
|
|
@@ -576,6 +599,7 @@ describe("Data", () => {
|
|
|
576
599
|
// Act
|
|
577
600
|
render(
|
|
578
601
|
<Data handler={fakeHandler} requestId="ID">
|
|
602
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
579
603
|
{fakeChildrenFn}
|
|
580
604
|
</Data>,
|
|
581
605
|
);
|
|
@@ -610,6 +634,7 @@ describe("Data", () => {
|
|
|
610
634
|
// Act
|
|
611
635
|
ReactDOMServer.renderToString(
|
|
612
636
|
<Data handler={fakeHandler} requestId="ID">
|
|
637
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
613
638
|
{fakeChildrenFn}
|
|
614
639
|
</Data>,
|
|
615
640
|
);
|
|
@@ -626,6 +651,7 @@ describe("Data", () => {
|
|
|
626
651
|
// Act
|
|
627
652
|
ReactDOMServer.renderToString(
|
|
628
653
|
<Data handler={fakeHandler} requestId="ID">
|
|
654
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
629
655
|
{fakeChildrenFn}
|
|
630
656
|
</Data>,
|
|
631
657
|
);
|
|
@@ -649,6 +675,7 @@ describe("Data", () => {
|
|
|
649
675
|
ReactDOMServer.renderToString(
|
|
650
676
|
<TrackData>
|
|
651
677
|
<Data handler={fakeHandler} requestId="ID">
|
|
678
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
652
679
|
{fakeChildrenFn}
|
|
653
680
|
</Data>
|
|
654
681
|
</TrackData>,
|
|
@@ -675,6 +702,7 @@ describe("Data", () => {
|
|
|
675
702
|
ReactDOMServer.renderToString(
|
|
676
703
|
<InterceptRequests interceptor={interceptedHandler}>
|
|
677
704
|
<Data handler={fakeHandler} requestId="ID">
|
|
705
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
678
706
|
{fakeChildrenFn}
|
|
679
707
|
</Data>
|
|
680
708
|
</InterceptRequests>,
|
|
@@ -702,6 +730,7 @@ describe("Data", () => {
|
|
|
702
730
|
<TrackData>
|
|
703
731
|
<InterceptRequests interceptor={interceptedHandler}>
|
|
704
732
|
<Data handler={fakeHandler} requestId="ID">
|
|
733
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
705
734
|
{fakeChildrenFn}
|
|
706
735
|
</Data>
|
|
707
736
|
</InterceptRequests>
|
|
@@ -737,6 +766,7 @@ describe("Data", () => {
|
|
|
737
766
|
// Act
|
|
738
767
|
ReactDOMServer.renderToString(
|
|
739
768
|
<Data handler={fakeHandler} requestId="ID">
|
|
769
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
740
770
|
{fakeChildrenFn}
|
|
741
771
|
</Data>,
|
|
742
772
|
);
|
|
@@ -753,6 +783,7 @@ describe("Data", () => {
|
|
|
753
783
|
// Act
|
|
754
784
|
ReactDOMServer.renderToString(
|
|
755
785
|
<Data handler={fakeHandler} requestId="ID">
|
|
786
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
756
787
|
{fakeChildrenFn}
|
|
757
788
|
</Data>,
|
|
758
789
|
);
|
|
@@ -775,6 +806,7 @@ describe("Data", () => {
|
|
|
775
806
|
// Act
|
|
776
807
|
ReactDOMServer.renderToString(
|
|
777
808
|
<Data handler={fakeHandler} requestId="ID">
|
|
809
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
778
810
|
{fakeChildrenFn}
|
|
779
811
|
</Data>,
|
|
780
812
|
);
|
|
@@ -799,6 +831,7 @@ describe("Data", () => {
|
|
|
799
831
|
ReactDOMServer.renderToString(
|
|
800
832
|
<TrackData>
|
|
801
833
|
<Data handler={fakeHandler} requestId="ID">
|
|
834
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
802
835
|
{fakeChildrenFn}
|
|
803
836
|
</Data>
|
|
804
837
|
</TrackData>,
|
|
@@ -824,6 +857,7 @@ describe("Data", () => {
|
|
|
824
857
|
ReactDOMServer.renderToString(
|
|
825
858
|
<InterceptRequests interceptor={interceptHandler}>
|
|
826
859
|
<Data handler={fakeHandler} requestId="ID">
|
|
860
|
+
{/* @ts-expect-error [FEI-5019] - TS2322 - Type 'Mock<null, [], any>' is not assignable to type '((result: Result<TData>) => ReactElement<any, string | JSXElementConstructor<any>>) & ReactNode'. */}
|
|
827
861
|
{fakeChildrenFn}
|
|
828
862
|
</Data>
|
|
829
863
|
</InterceptRequests>,
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render} from "@testing-library/react";
|
|
4
3
|
|
|
5
|
-
import {GqlRouterContext} from "../../util/gql-router-context
|
|
6
|
-
import {GqlRouter} from "../gql-router
|
|
4
|
+
import {GqlRouterContext} from "../../util/gql-router-context";
|
|
5
|
+
import {GqlRouter} from "../gql-router";
|
|
7
6
|
|
|
8
7
|
describe("GqlRouter", () => {
|
|
9
8
|
it("should provide the GqlRouterContext as configured", async () => {
|
|
10
9
|
// Arrange
|
|
11
10
|
const defaultContext = {
|
|
12
11
|
foo: "bar",
|
|
13
|
-
};
|
|
12
|
+
} as const;
|
|
14
13
|
const fetch = jest.fn();
|
|
15
|
-
const CaptureContext = ({captureFn}) => {
|
|
14
|
+
const CaptureContext = ({captureFn}: any) => {
|
|
16
15
|
captureFn(React.useContext(GqlRouterContext));
|
|
17
16
|
return null;
|
|
18
17
|
};
|
|
19
18
|
|
|
20
19
|
// Act
|
|
21
|
-
const result = await new Promise((resolve, reject) => {
|
|
20
|
+
const result = await new Promise((resolve: any, reject: any) => {
|
|
22
21
|
render(
|
|
23
22
|
<GqlRouter defaultContext={defaultContext} fetch={fetch}>
|
|
24
23
|
<CaptureContext captureFn={resolve} />
|
|
@@ -37,7 +36,7 @@ describe("GqlRouter", () => {
|
|
|
37
36
|
// Arrange
|
|
38
37
|
const defaultContext = {
|
|
39
38
|
foo: "bar",
|
|
40
|
-
};
|
|
39
|
+
} as const;
|
|
41
40
|
const fetch = jest.fn();
|
|
42
41
|
let renderCount = 0;
|
|
43
42
|
const Child = React.memo(() => {
|