@khanacademy/wonder-blocks-data 10.1.0 → 10.1.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.
- package/CHANGELOG.md +31 -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 +184 -212
- 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 +186 -217
- 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} +42 -2
- package/src/components/__tests__/{gql-router.test.js → gql-router.test.tsx} +4 -5
- package/src/components/__tests__/{intercept-requests.test.js → intercept-requests.test.tsx} +2 -3
- package/src/components/__tests__/{track-data.test.js → track-data.test.tsx} +2 -3
- package/src/components/{data.js → data.ts} +11 -15
- package/src/components/{gql-router.js → gql-router.tsx} +12 -14
- package/src/components/{intercept-context.js → intercept-context.ts} +4 -3
- package/src/components/{intercept-requests.js → intercept-requests.tsx} +7 -8
- package/src/components/{track-data.js → track-data.tsx} +4 -5
- package/src/hooks/__tests__/{use-cached-effect.test.js → use-cached-effect.test.tsx} +55 -50
- package/src/hooks/__tests__/{use-gql-router-context.test.js → use-gql-router-context.test.tsx} +7 -7
- package/src/hooks/__tests__/{use-gql.test.js → use-gql.test.tsx} +20 -21
- package/src/hooks/__tests__/{use-hydratable-effect.test.js → use-hydratable-effect.test.ts} +42 -37
- package/src/hooks/__tests__/{use-request-interception.test.js → use-request-interception.test.tsx} +5 -3
- package/src/hooks/__tests__/{use-server-effect.test.js → use-server-effect.test.ts} +8 -2
- package/src/hooks/__tests__/{use-shared-cache.test.js → use-shared-cache.test.ts} +12 -12
- package/src/hooks/{use-cached-effect.js → use-cached-effect.ts} +27 -20
- package/src/hooks/{use-gql-router-context.js → use-gql-router-context.ts} +2 -3
- package/src/hooks/{use-gql.js → use-gql.ts} +5 -5
- package/src/hooks/{use-hydratable-effect.js → use-hydratable-effect.ts} +53 -58
- package/src/hooks/{use-request-interception.js → use-request-interception.ts} +4 -4
- package/src/hooks/{use-server-effect.js → use-server-effect.ts} +7 -9
- package/src/hooks/{use-shared-cache.js → use-shared-cache.ts} +13 -8
- package/src/{index.js → index.ts} +0 -1
- package/src/util/__tests__/{get-gql-data-from-response.test.js → get-gql-data-from-response.test.ts} +0 -1
- package/src/util/__tests__/{get-gql-request-id.test.js → get-gql-request-id.test.ts} +9 -11
- package/src/util/__tests__/{graphql-document-node-parser.test.js → graphql-document-node-parser.test.ts} +11 -12
- package/src/util/__tests__/{hydration-cache-api.test.js → hydration-cache-api.test.ts} +1 -2
- package/src/util/__tests__/{merge-gql-context.test.js → merge-gql-context.test.ts} +4 -5
- package/src/util/__tests__/{purge-caches.test.js → purge-caches.test.ts} +0 -1
- package/src/util/__tests__/{request-api.test.js → request-api.test.ts} +2 -2
- package/src/util/__tests__/{request-fulfillment.test.js → request-fulfillment.test.ts} +0 -1
- package/src/util/__tests__/{request-tracking.test.js → request-tracking.test.tsx} +13 -6
- package/src/util/__tests__/{result-from-cache-response.test.js → result-from-cache-response.test.ts} +2 -4
- package/src/util/__tests__/{scoped-in-memory-cache.test.js → scoped-in-memory-cache.test.ts} +4 -5
- package/src/util/__tests__/{serializable-in-memory-cache.test.js → serializable-in-memory-cache.test.ts} +7 -7
- package/src/util/__tests__/{ssr-cache.test.js → ssr-cache.test.ts} +3 -2
- package/src/util/__tests__/{to-gql-operation.test.js → to-gql-operation.test.ts} +2 -1
- package/src/util/{data-error.js → data-error.ts} +2 -3
- package/src/util/{get-gql-data-from-response.js → get-gql-data-from-response.ts} +1 -6
- package/src/util/{get-gql-request-id.js → get-gql-request-id.ts} +12 -16
- package/src/util/{gql-error.js → gql-error.ts} +2 -3
- 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} +6 -7
- package/src/util/graphql-types.ts +27 -0
- package/src/util/{hydration-cache-api.js → hydration-cache-api.ts} +4 -2
- package/src/util/{merge-gql-context.js → merge-gql-context.ts} +2 -2
- package/src/util/{purge-caches.js → purge-caches.ts} +0 -1
- package/src/util/{request-api.js → request-api.ts} +0 -1
- package/src/util/{request-fulfillment.js → request-fulfillment.ts} +13 -12
- package/src/util/{request-tracking.js → request-tracking.ts} +12 -13
- package/src/util/{result-from-cache-response.js → result-from-cache-response.ts} +3 -4
- package/src/util/{scoped-in-memory-cache.js → scoped-in-memory-cache.ts} +1 -2
- package/src/util/{serializable-in-memory-cache.js → serializable-in-memory-cache.ts} +2 -3
- package/src/util/{ssr-cache.js → ssr-cache.ts} +19 -18
- package/src/util/{status.js → status.ts} +4 -5
- package/src/util/{to-gql-operation.js → to-gql-operation.ts} +1 -2
- package/src/util/{types.js → types.ts} +39 -48
- 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/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.1.
|
|
3
|
+
"version": "10.1.2",
|
|
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.9.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.3"
|
|
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
|
|
|
@@ -55,9 +54,11 @@ describe("Data", () => {
|
|
|
55
54
|
// Act
|
|
56
55
|
render(
|
|
57
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'. */}
|
|
58
58
|
{fakeChildrenFn}
|
|
59
59
|
</Data>,
|
|
60
60
|
);
|
|
61
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
61
62
|
await act(() => response);
|
|
62
63
|
|
|
63
64
|
// Assert
|
|
@@ -73,9 +74,11 @@ describe("Data", () => {
|
|
|
73
74
|
// Act
|
|
74
75
|
render(
|
|
75
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'. */}
|
|
76
78
|
{fakeChildrenFn}
|
|
77
79
|
</Data>,
|
|
78
80
|
);
|
|
81
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
79
82
|
await act(() => response);
|
|
80
83
|
|
|
81
84
|
// Assert
|
|
@@ -87,7 +90,7 @@ describe("Data", () => {
|
|
|
87
90
|
it("should share single request across all uses", () => {
|
|
88
91
|
// Arrange
|
|
89
92
|
const fakeHandler = jest.fn(
|
|
90
|
-
() => new Promise((resolve, reject) => {}),
|
|
93
|
+
() => new Promise((resolve: any, reject: any) => {}),
|
|
91
94
|
);
|
|
92
95
|
const fakeChildrenFn = jest.fn(() => null);
|
|
93
96
|
|
|
@@ -95,9 +98,11 @@ describe("Data", () => {
|
|
|
95
98
|
render(
|
|
96
99
|
<View>
|
|
97
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'. */}
|
|
98
102
|
{fakeChildrenFn}
|
|
99
103
|
</Data>
|
|
100
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'. */}
|
|
101
106
|
{fakeChildrenFn}
|
|
102
107
|
</Data>
|
|
103
108
|
</View>,
|
|
@@ -119,6 +124,7 @@ describe("Data", () => {
|
|
|
119
124
|
// Act
|
|
120
125
|
render(
|
|
121
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'. */}
|
|
122
128
|
{fakeChildrenFn}
|
|
123
129
|
</Data>,
|
|
124
130
|
);
|
|
@@ -153,6 +159,7 @@ describe("Data", () => {
|
|
|
153
159
|
// Act
|
|
154
160
|
render(
|
|
155
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'. */}
|
|
156
163
|
{fakeChildrenFn}
|
|
157
164
|
</Data>,
|
|
158
165
|
);
|
|
@@ -184,6 +191,7 @@ describe("Data", () => {
|
|
|
184
191
|
// Act
|
|
185
192
|
render(
|
|
186
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'. */}
|
|
187
195
|
{fakeChildrenFn}
|
|
188
196
|
</Data>,
|
|
189
197
|
);
|
|
@@ -214,6 +222,7 @@ describe("Data", () => {
|
|
|
214
222
|
// Act
|
|
215
223
|
render(
|
|
216
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'. */}
|
|
217
226
|
{fakeChildrenFn}
|
|
218
227
|
</Data>,
|
|
219
228
|
);
|
|
@@ -243,6 +252,7 @@ describe("Data", () => {
|
|
|
243
252
|
const fakeChildrenFn = jest.fn(() => null);
|
|
244
253
|
const wrapper = render(
|
|
245
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'. */}
|
|
246
256
|
{fakeChildrenFn}
|
|
247
257
|
</Data>,
|
|
248
258
|
);
|
|
@@ -255,6 +265,7 @@ describe("Data", () => {
|
|
|
255
265
|
// Act
|
|
256
266
|
wrapper.rerender(
|
|
257
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'. */}
|
|
258
269
|
{fakeChildrenFn}
|
|
259
270
|
</Data>,
|
|
260
271
|
);
|
|
@@ -285,14 +296,17 @@ describe("Data", () => {
|
|
|
285
296
|
const fakeChildrenFn = jest.fn(() => null);
|
|
286
297
|
const wrapper = render(
|
|
287
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'. */}
|
|
288
300
|
{fakeChildrenFn}
|
|
289
301
|
</Data>,
|
|
290
302
|
);
|
|
291
303
|
wrapper.rerender(
|
|
292
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'. */}
|
|
293
306
|
{fakeChildrenFn}
|
|
294
307
|
</Data>,
|
|
295
308
|
);
|
|
309
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
296
310
|
await act(() => oldRequest);
|
|
297
311
|
|
|
298
312
|
// Assert
|
|
@@ -318,11 +332,13 @@ describe("Data", () => {
|
|
|
318
332
|
const fakeChildrenFn = jest.fn(() => null);
|
|
319
333
|
const wrapper = render(
|
|
320
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'. */}
|
|
321
336
|
{fakeChildrenFn}
|
|
322
337
|
</Data>,
|
|
323
338
|
);
|
|
324
339
|
wrapper.rerender(
|
|
325
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'. */}
|
|
326
342
|
{fakeChildrenFn}
|
|
327
343
|
</Data>,
|
|
328
344
|
);
|
|
@@ -348,6 +364,7 @@ describe("Data", () => {
|
|
|
348
364
|
jest.spyOn(
|
|
349
365
|
RequestFulfillment.Default,
|
|
350
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>>'.
|
|
351
368
|
).mockReturnValueOnce(catastrophe);
|
|
352
369
|
const oldHandler = jest.fn().mockResolvedValue("OLD DATA");
|
|
353
370
|
|
|
@@ -355,15 +372,18 @@ describe("Data", () => {
|
|
|
355
372
|
const fakeChildrenFn = jest.fn(() => null);
|
|
356
373
|
const wrapper = render(
|
|
357
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'. */}
|
|
358
376
|
{fakeChildrenFn}
|
|
359
377
|
</Data>,
|
|
360
378
|
);
|
|
361
379
|
wrapper.rerender(
|
|
362
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'. */}
|
|
363
382
|
{fakeChildrenFn}
|
|
364
383
|
</Data>,
|
|
365
384
|
);
|
|
366
385
|
await act(() =>
|
|
386
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
367
387
|
catastrophe.catch(() => {
|
|
368
388
|
/* ignore */
|
|
369
389
|
}),
|
|
@@ -389,6 +409,7 @@ describe("Data", () => {
|
|
|
389
409
|
render(
|
|
390
410
|
<InterceptRequests interceptor={interceptHandler}>
|
|
391
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'. */}
|
|
392
413
|
{fakeChildrenFn}
|
|
393
414
|
</Data>
|
|
394
415
|
</InterceptRequests>,
|
|
@@ -410,6 +431,7 @@ describe("Data", () => {
|
|
|
410
431
|
render(
|
|
411
432
|
<InterceptRequests interceptor={interceptHandler}>
|
|
412
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'. */}
|
|
413
435
|
{fakeChildrenFn}
|
|
414
436
|
</Data>
|
|
415
437
|
</InterceptRequests>,
|
|
@@ -437,10 +459,12 @@ describe("Data", () => {
|
|
|
437
459
|
requestId="ID1"
|
|
438
460
|
retainResultOnChange={true}
|
|
439
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'. */}
|
|
440
463
|
{fakeChildrenFn}
|
|
441
464
|
</Data>,
|
|
442
465
|
);
|
|
443
466
|
fakeChildrenFn.mockClear();
|
|
467
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
444
468
|
await act(() => response1);
|
|
445
469
|
wrapper.rerender(
|
|
446
470
|
<Data
|
|
@@ -448,9 +472,11 @@ describe("Data", () => {
|
|
|
448
472
|
requestId="ID2"
|
|
449
473
|
retainResultOnChange={true}
|
|
450
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'. */}
|
|
451
476
|
{fakeChildrenFn}
|
|
452
477
|
</Data>,
|
|
453
478
|
);
|
|
479
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
454
480
|
await act(() => response2);
|
|
455
481
|
|
|
456
482
|
// Assert
|
|
@@ -492,6 +518,7 @@ describe("Data", () => {
|
|
|
492
518
|
// Act
|
|
493
519
|
render(
|
|
494
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'. */}
|
|
495
522
|
{fakeChildrenFn}
|
|
496
523
|
</Data>,
|
|
497
524
|
);
|
|
@@ -517,6 +544,7 @@ describe("Data", () => {
|
|
|
517
544
|
WhenClientSide.ExecuteWhenNoSuccessResult
|
|
518
545
|
}
|
|
519
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'. */}
|
|
520
548
|
{fakeChildrenFn}
|
|
521
549
|
</Data>,
|
|
522
550
|
);
|
|
@@ -537,6 +565,7 @@ describe("Data", () => {
|
|
|
537
565
|
requestId="ID"
|
|
538
566
|
clientBehavior={WhenClientSide.AlwaysExecute}
|
|
539
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'. */}
|
|
540
569
|
{fakeChildrenFn}
|
|
541
570
|
</Data>,
|
|
542
571
|
);
|
|
@@ -570,6 +599,7 @@ describe("Data", () => {
|
|
|
570
599
|
// Act
|
|
571
600
|
render(
|
|
572
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'. */}
|
|
573
603
|
{fakeChildrenFn}
|
|
574
604
|
</Data>,
|
|
575
605
|
);
|
|
@@ -604,6 +634,7 @@ describe("Data", () => {
|
|
|
604
634
|
// Act
|
|
605
635
|
ReactDOMServer.renderToString(
|
|
606
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'. */}
|
|
607
638
|
{fakeChildrenFn}
|
|
608
639
|
</Data>,
|
|
609
640
|
);
|
|
@@ -620,6 +651,7 @@ describe("Data", () => {
|
|
|
620
651
|
// Act
|
|
621
652
|
ReactDOMServer.renderToString(
|
|
622
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'. */}
|
|
623
655
|
{fakeChildrenFn}
|
|
624
656
|
</Data>,
|
|
625
657
|
);
|
|
@@ -643,6 +675,7 @@ describe("Data", () => {
|
|
|
643
675
|
ReactDOMServer.renderToString(
|
|
644
676
|
<TrackData>
|
|
645
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'. */}
|
|
646
679
|
{fakeChildrenFn}
|
|
647
680
|
</Data>
|
|
648
681
|
</TrackData>,
|
|
@@ -669,6 +702,7 @@ describe("Data", () => {
|
|
|
669
702
|
ReactDOMServer.renderToString(
|
|
670
703
|
<InterceptRequests interceptor={interceptedHandler}>
|
|
671
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'. */}
|
|
672
706
|
{fakeChildrenFn}
|
|
673
707
|
</Data>
|
|
674
708
|
</InterceptRequests>,
|
|
@@ -696,6 +730,7 @@ describe("Data", () => {
|
|
|
696
730
|
<TrackData>
|
|
697
731
|
<InterceptRequests interceptor={interceptedHandler}>
|
|
698
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'. */}
|
|
699
734
|
{fakeChildrenFn}
|
|
700
735
|
</Data>
|
|
701
736
|
</InterceptRequests>
|
|
@@ -731,6 +766,7 @@ describe("Data", () => {
|
|
|
731
766
|
// Act
|
|
732
767
|
ReactDOMServer.renderToString(
|
|
733
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'. */}
|
|
734
770
|
{fakeChildrenFn}
|
|
735
771
|
</Data>,
|
|
736
772
|
);
|
|
@@ -747,6 +783,7 @@ describe("Data", () => {
|
|
|
747
783
|
// Act
|
|
748
784
|
ReactDOMServer.renderToString(
|
|
749
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'. */}
|
|
750
787
|
{fakeChildrenFn}
|
|
751
788
|
</Data>,
|
|
752
789
|
);
|
|
@@ -769,6 +806,7 @@ describe("Data", () => {
|
|
|
769
806
|
// Act
|
|
770
807
|
ReactDOMServer.renderToString(
|
|
771
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'. */}
|
|
772
810
|
{fakeChildrenFn}
|
|
773
811
|
</Data>,
|
|
774
812
|
);
|
|
@@ -793,6 +831,7 @@ describe("Data", () => {
|
|
|
793
831
|
ReactDOMServer.renderToString(
|
|
794
832
|
<TrackData>
|
|
795
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'. */}
|
|
796
835
|
{fakeChildrenFn}
|
|
797
836
|
</Data>
|
|
798
837
|
</TrackData>,
|
|
@@ -818,6 +857,7 @@ describe("Data", () => {
|
|
|
818
857
|
ReactDOMServer.renderToString(
|
|
819
858
|
<InterceptRequests interceptor={interceptHandler}>
|
|
820
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'. */}
|
|
821
861
|
{fakeChildrenFn}
|
|
822
862
|
</Data>
|
|
823
863
|
</InterceptRequests>,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render} from "@testing-library/react";
|
|
4
3
|
|
|
@@ -10,15 +9,15 @@ describe("GqlRouter", () => {
|
|
|
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(() => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render} from "@testing-library/react";
|
|
4
3
|
|
|
@@ -12,11 +11,11 @@ describe("InterceptRequests", () => {
|
|
|
12
11
|
|
|
13
12
|
it("should update context with fulfillRequest method", () => {
|
|
14
13
|
// Arrange
|
|
15
|
-
const fakeHandler = (requestId): Promise<string> =>
|
|
14
|
+
const fakeHandler = (requestId: any): Promise<string> =>
|
|
16
15
|
Promise.resolve("data");
|
|
17
16
|
const props = {
|
|
18
17
|
interceptor: fakeHandler,
|
|
19
|
-
};
|
|
18
|
+
} as const;
|
|
20
19
|
const captureContextFn = jest.fn();
|
|
21
20
|
|
|
22
21
|
// Act
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
4
3
|
import {render, screen} from "@testing-library/react";
|
|
@@ -41,11 +40,11 @@ describe("TrackData", () => {
|
|
|
41
40
|
jest.spyOn(Server, "isServerSide").mockReturnValue(true);
|
|
42
41
|
|
|
43
42
|
// Act
|
|
44
|
-
const result = await new Promise((resolve, reject) => {
|
|
43
|
+
const result = await new Promise((resolve: any, reject: any) => {
|
|
45
44
|
render(
|
|
46
45
|
<TrackData>
|
|
47
46
|
<TrackerContext.Consumer>
|
|
48
|
-
{(fn) => resolve(fn)}
|
|
47
|
+
{(fn: any) => resolve(fn)}
|
|
49
48
|
</TrackerContext.Consumer>
|
|
50
49
|
</TrackData>,
|
|
51
50
|
);
|