@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
package/src/index.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export {FetchPolicy} from "./util/types";
|
|
2
|
+
export type {
|
|
3
|
+
ErrorOptions,
|
|
4
|
+
ResponseCache,
|
|
5
|
+
CachedResponse,
|
|
6
|
+
Result,
|
|
7
|
+
RawScopedCache,
|
|
8
|
+
ValidCacheData,
|
|
9
|
+
ScopedCache,
|
|
10
|
+
} from "./util/types";
|
|
11
|
+
|
|
12
|
+
export * from "./util/hydration-cache-api";
|
|
13
|
+
export * from "./util/request-api";
|
|
14
|
+
export {purgeCaches} from "./util/purge-caches";
|
|
15
|
+
export {default as TrackData} from "./components/track-data";
|
|
16
|
+
export {default as Data} from "./components/data";
|
|
17
|
+
export {default as InterceptRequests} from "./components/intercept-requests";
|
|
18
|
+
export {DataError, DataErrors} from "./util/data-error";
|
|
19
|
+
export {useServerEffect} from "./hooks/use-server-effect";
|
|
20
|
+
export {useCachedEffect} from "./hooks/use-cached-effect";
|
|
21
|
+
export {useSharedCache, SharedCache} from "./hooks/use-shared-cache";
|
|
22
|
+
export {
|
|
23
|
+
useHydratableEffect,
|
|
24
|
+
WhenClientSide,
|
|
25
|
+
} from "./hooks/use-hydratable-effect";
|
|
26
|
+
export {ScopedInMemoryCache} from "./util/scoped-in-memory-cache";
|
|
27
|
+
export {SerializableInMemoryCache} from "./util/serializable-in-memory-cache";
|
|
28
|
+
export {Status} from "./util/status";
|
|
29
|
+
|
|
30
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
31
|
+
// GraphQL
|
|
32
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
33
|
+
export {getGqlRequestId} from "./util/get-gql-request-id";
|
|
34
|
+
export {getGqlDataFromResponse} from "./util/get-gql-data-from-response";
|
|
35
|
+
export {graphQLDocumentNodeParser} from "./util/graphql-document-node-parser";
|
|
36
|
+
export {toGqlOperation} from "./util/to-gql-operation";
|
|
37
|
+
export {GqlRouter} from "./components/gql-router";
|
|
38
|
+
export {useGql} from "./hooks/use-gql";
|
|
39
|
+
export {GqlError, GqlErrors} from "./util/gql-error";
|
|
40
|
+
export type {
|
|
41
|
+
GqlContext,
|
|
42
|
+
GqlOperation,
|
|
43
|
+
GqlOperationType,
|
|
44
|
+
GqlFetchOptions,
|
|
45
|
+
GqlFetchFn,
|
|
46
|
+
} from "./util/gql-types";
|
package/src/util/__tests__/{get-gql-data-from-response.test.js → get-gql-data-from-response.test.ts}
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {getGqlDataFromResponse} from "../get-gql-data-from-response.js";
|
|
1
|
+
import {getGqlDataFromResponse} from "../get-gql-data-from-response";
|
|
3
2
|
|
|
4
3
|
describe("#getGqlDataFromReponse", () => {
|
|
5
4
|
it("should throw if the response cannot be parsed", async () => {
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {getGqlRequestId} from "../get-gql-request-id.js";
|
|
1
|
+
import {getGqlRequestId} from "../get-gql-request-id";
|
|
4
2
|
|
|
5
3
|
describe("#getGqlRequestId", () => {
|
|
6
4
|
it("should include the id of the query", () => {
|
|
@@ -8,7 +6,7 @@ describe("#getGqlRequestId", () => {
|
|
|
8
6
|
const operation = {
|
|
9
7
|
type: "query",
|
|
10
8
|
id: "myQuery",
|
|
11
|
-
};
|
|
9
|
+
} as const;
|
|
12
10
|
|
|
13
11
|
// Act
|
|
14
12
|
const requestId = getGqlRequestId(operation, null, {
|
|
@@ -27,12 +25,12 @@ describe("#getGqlRequestId", () => {
|
|
|
27
25
|
const operation = {
|
|
28
26
|
type: "query",
|
|
29
27
|
id: "myQuery",
|
|
30
|
-
};
|
|
28
|
+
} as const;
|
|
31
29
|
const context = {
|
|
32
30
|
context3: "value3",
|
|
33
31
|
context2: "value2",
|
|
34
32
|
context1: "value1",
|
|
35
|
-
};
|
|
33
|
+
} as const;
|
|
36
34
|
|
|
37
35
|
// Act
|
|
38
36
|
const requestId = getGqlRequestId(operation, null, context);
|
|
@@ -49,14 +47,14 @@ describe("#getGqlRequestId", () => {
|
|
|
49
47
|
const operation = {
|
|
50
48
|
type: "query",
|
|
51
49
|
id: "myQuery",
|
|
52
|
-
};
|
|
50
|
+
} as const;
|
|
53
51
|
const variables = {
|
|
54
52
|
variable4: null,
|
|
55
53
|
variable2: 42,
|
|
56
54
|
variable1: "value1",
|
|
57
55
|
variable5: true,
|
|
58
56
|
variable3: undefined,
|
|
59
|
-
};
|
|
57
|
+
} as const;
|
|
60
58
|
|
|
61
59
|
// Act
|
|
62
60
|
const requestId = getGqlRequestId(operation, variables, {
|
|
@@ -77,7 +75,7 @@ describe("#getGqlRequestId", () => {
|
|
|
77
75
|
const operation = {
|
|
78
76
|
type: "query",
|
|
79
77
|
id: "myQuery",
|
|
80
|
-
};
|
|
78
|
+
} as const;
|
|
81
79
|
const variables = {
|
|
82
80
|
variable4: null,
|
|
83
81
|
variable2: 42,
|
|
@@ -89,7 +87,7 @@ describe("#getGqlRequestId", () => {
|
|
|
89
87
|
nested1: "nested1",
|
|
90
88
|
},
|
|
91
89
|
variable7: [1, 2, 3],
|
|
92
|
-
};
|
|
90
|
+
} as const;
|
|
93
91
|
|
|
94
92
|
// Act
|
|
95
93
|
const requestId = getGqlRequestId(operation, variables, {
|
|
@@ -110,13 +108,13 @@ describe("#getGqlRequestId", () => {
|
|
|
110
108
|
const operation = {
|
|
111
109
|
type: "query",
|
|
112
110
|
id: "myQuery",
|
|
113
|
-
};
|
|
111
|
+
} as const;
|
|
114
112
|
const variables = {
|
|
115
113
|
variable1: {
|
|
116
114
|
date: new Date("2020-01-01"),
|
|
117
115
|
error: new Error("BOOM!"),
|
|
118
116
|
},
|
|
119
|
-
};
|
|
117
|
+
} as const;
|
|
120
118
|
|
|
121
119
|
// Act
|
|
122
120
|
const requestId = getGqlRequestId(operation, variables, {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {graphQLDocumentNodeParser} from "../graphql-document-node-parser.js";
|
|
1
|
+
import {graphQLDocumentNodeParser} from "../graphql-document-node-parser";
|
|
3
2
|
|
|
4
3
|
describe("#graphQLDocumentNodeParser", () => {
|
|
5
4
|
describe("in production - shorter error messages", () => {
|
|
@@ -61,7 +60,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
61
60
|
},
|
|
62
61
|
},
|
|
63
62
|
],
|
|
64
|
-
};
|
|
63
|
+
} as const;
|
|
65
64
|
|
|
66
65
|
// Act
|
|
67
66
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -87,7 +86,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
87
86
|
},
|
|
88
87
|
},
|
|
89
88
|
],
|
|
90
|
-
};
|
|
89
|
+
} as const;
|
|
91
90
|
|
|
92
91
|
// Act
|
|
93
92
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -122,7 +121,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
122
121
|
},
|
|
123
122
|
},
|
|
124
123
|
],
|
|
125
|
-
};
|
|
124
|
+
} as const;
|
|
126
125
|
|
|
127
126
|
// Act
|
|
128
127
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -157,7 +156,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
157
156
|
},
|
|
158
157
|
},
|
|
159
158
|
],
|
|
160
|
-
};
|
|
159
|
+
} as const;
|
|
161
160
|
|
|
162
161
|
// Act
|
|
163
162
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -192,7 +191,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
192
191
|
},
|
|
193
192
|
},
|
|
194
193
|
],
|
|
195
|
-
};
|
|
194
|
+
} as const;
|
|
196
195
|
|
|
197
196
|
// Act
|
|
198
197
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -207,7 +206,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
207
206
|
describe("not in production - more informative error messages", () => {
|
|
208
207
|
it("should throw if the document lacks the kind property", () => {
|
|
209
208
|
// Arrange
|
|
210
|
-
const documentNode =
|
|
209
|
+
const documentNode = {} as any;
|
|
211
210
|
|
|
212
211
|
// Act
|
|
213
212
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -250,7 +249,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
250
249
|
},
|
|
251
250
|
},
|
|
252
251
|
],
|
|
253
|
-
};
|
|
252
|
+
} as const;
|
|
254
253
|
|
|
255
254
|
// Act
|
|
256
255
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -276,7 +275,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
276
275
|
},
|
|
277
276
|
},
|
|
278
277
|
],
|
|
279
|
-
};
|
|
278
|
+
} as const;
|
|
280
279
|
|
|
281
280
|
// Act
|
|
282
281
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -311,7 +310,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
311
310
|
},
|
|
312
311
|
},
|
|
313
312
|
],
|
|
314
|
-
};
|
|
313
|
+
} as const;
|
|
315
314
|
|
|
316
315
|
// Act
|
|
317
316
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -346,7 +345,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
346
345
|
},
|
|
347
346
|
},
|
|
348
347
|
],
|
|
349
|
-
};
|
|
348
|
+
} as const;
|
|
350
349
|
|
|
351
350
|
// Act
|
|
352
351
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -381,7 +380,7 @@ describe("#graphQLDocumentNodeParser", () => {
|
|
|
381
380
|
},
|
|
382
381
|
},
|
|
383
382
|
],
|
|
384
|
-
};
|
|
383
|
+
} as const;
|
|
385
384
|
|
|
386
385
|
// Act
|
|
387
386
|
const underTest = () => graphQLDocumentNodeParser(documentNode);
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import {SsrCache} from "../ssr-cache.js";
|
|
1
|
+
import {SsrCache} from "../ssr-cache";
|
|
3
2
|
|
|
4
3
|
import {
|
|
5
4
|
initializeHydrationCache,
|
|
6
5
|
purgeHydrationCache,
|
|
7
|
-
} from "../hydration-cache-api
|
|
6
|
+
} from "../hydration-cache-api";
|
|
8
7
|
|
|
9
8
|
describe("#initializeHydrationCache", () => {
|
|
10
9
|
it("should call SsrCache.Default.initialize", () => {
|
|
11
10
|
// Arrange
|
|
12
|
-
const sourceCache = {};
|
|
11
|
+
const sourceCache: Record<string, any> = {};
|
|
13
12
|
const initSpy = jest.spyOn(SsrCache.Default, "initialize");
|
|
14
13
|
|
|
15
14
|
// Act
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {mergeGqlContext} from "../merge-gql-context.js";
|
|
1
|
+
import {mergeGqlContext} from "../merge-gql-context";
|
|
3
2
|
|
|
4
3
|
describe("#mergeGqlContext", () => {
|
|
5
4
|
it("should combine the default context with the given overrides", () => {
|
|
6
5
|
// Arrange
|
|
7
6
|
const baseContext = {
|
|
8
7
|
foo: "bar",
|
|
9
|
-
};
|
|
8
|
+
} as const;
|
|
10
9
|
|
|
11
10
|
// Act
|
|
12
11
|
const result = mergeGqlContext<any>(baseContext, {
|
|
@@ -24,7 +23,7 @@ describe("#mergeGqlContext", () => {
|
|
|
24
23
|
// Arrange
|
|
25
24
|
const baseContext = {
|
|
26
25
|
foo: "bar",
|
|
27
|
-
};
|
|
26
|
+
} as const;
|
|
28
27
|
|
|
29
28
|
// Act
|
|
30
29
|
const result = mergeGqlContext<any>(baseContext, {
|
|
@@ -41,7 +40,7 @@ describe("#mergeGqlContext", () => {
|
|
|
41
40
|
// Arrange
|
|
42
41
|
const baseContext = {
|
|
43
42
|
foo: "bar",
|
|
44
|
-
};
|
|
43
|
+
} as const;
|
|
45
44
|
|
|
46
45
|
// Act
|
|
47
46
|
const result = mergeGqlContext<any>(baseContext, {
|
|
@@ -59,7 +58,7 @@ describe("#mergeGqlContext", () => {
|
|
|
59
58
|
const baseContext = {
|
|
60
59
|
foo: "bar",
|
|
61
60
|
fiz: "baz",
|
|
62
|
-
};
|
|
61
|
+
} as const;
|
|
63
62
|
|
|
64
63
|
// Act
|
|
65
64
|
const result = mergeGqlContext<any>(baseContext, {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import * as HydrationCacheApi from "../hydration-cache-api.js";
|
|
1
|
+
import {SharedCache} from "../../hooks/use-shared-cache";
|
|
2
|
+
import * as HydrationCacheApi from "../hydration-cache-api";
|
|
4
3
|
|
|
5
|
-
import {purgeCaches} from "../purge-caches
|
|
4
|
+
import {purgeCaches} from "../purge-caches";
|
|
6
5
|
|
|
7
6
|
describe("#purgeCaches", () => {
|
|
8
7
|
it("should purge the shared cache", () => {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
3
|
-
import {RequestFulfillment} from "../request-fulfillment
|
|
4
|
-
import {RequestTracker} from "../request-tracking
|
|
2
|
+
import {RequestFulfillment} from "../request-fulfillment";
|
|
3
|
+
import {RequestTracker} from "../request-tracking";
|
|
5
4
|
|
|
6
5
|
import {
|
|
7
6
|
abortInflightRequests,
|
|
8
7
|
fetchTrackedRequests,
|
|
9
8
|
hasTrackedRequestsToBeFetched,
|
|
10
|
-
} from "../request-api
|
|
9
|
+
} from "../request-api";
|
|
11
10
|
|
|
12
11
|
describe("#fetchTrackedRequests", () => {
|
|
13
12
|
describe("when server-side", () => {
|
|
@@ -31,7 +30,7 @@ describe("#fetchTrackedRequests", () => {
|
|
|
31
30
|
|
|
32
31
|
it("should return the response cache", async () => {
|
|
33
32
|
// Arrange
|
|
34
|
-
const responseCache = {};
|
|
33
|
+
const responseCache: Record<string, any> = {};
|
|
35
34
|
jest.spyOn(
|
|
36
35
|
RequestTracker.Default,
|
|
37
36
|
"fulfillTrackedRequests",
|
|
@@ -124,6 +123,7 @@ describe("#hasTrackedRequestsToBeFetched", () => {
|
|
|
124
123
|
const result = hasTrackedRequestsToBeFetched();
|
|
125
124
|
|
|
126
125
|
// Assert
|
|
126
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'toBeTrue' does not exist on type 'JestMatchers<boolean>'.
|
|
127
127
|
expect(result).toBeTrue();
|
|
128
128
|
});
|
|
129
129
|
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {DataError} from "../data-error.js";
|
|
1
|
+
import {RequestFulfillment} from "../request-fulfillment";
|
|
2
|
+
import {DataError} from "../data-error";
|
|
4
3
|
|
|
5
4
|
describe("RequestFulfillment", () => {
|
|
6
5
|
it("should provide static default instance", () => {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render} from "@testing-library/react";
|
|
4
3
|
|
|
5
4
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
6
|
-
import {RequestTracker, TrackerContext} from "../request-tracking
|
|
7
|
-
import {SsrCache} from "../ssr-cache
|
|
5
|
+
import {RequestTracker, TrackerContext} from "../request-tracking";
|
|
6
|
+
import {SsrCache} from "../ssr-cache";
|
|
8
7
|
|
|
9
8
|
describe("../request-tracking.js", () => {
|
|
10
9
|
describe("TrackerContext", () => {
|
|
@@ -12,10 +11,10 @@ describe("../request-tracking.js", () => {
|
|
|
12
11
|
// Arrange
|
|
13
12
|
|
|
14
13
|
// Act
|
|
15
|
-
const result = await new Promise((resolve, reject) => {
|
|
14
|
+
const result = await new Promise((resolve: any, reject: any) => {
|
|
16
15
|
render(
|
|
17
16
|
<TrackerContext.Consumer>
|
|
18
|
-
{(fn) => resolve(fn)}
|
|
17
|
+
{(fn: any) => resolve(fn)}
|
|
19
18
|
</TrackerContext.Consumer>,
|
|
20
19
|
);
|
|
21
20
|
});
|
|
@@ -164,9 +163,12 @@ describe("../request-tracking.js", () => {
|
|
|
164
163
|
// Arrange
|
|
165
164
|
const requestTracker = createRequestTracker();
|
|
166
165
|
const fakeBadRequestHandler = () =>
|
|
167
|
-
new Promise((resolve, reject) =>
|
|
166
|
+
new Promise((resolve: any, reject: any) =>
|
|
167
|
+
reject("OH NO!"),
|
|
168
|
+
);
|
|
168
169
|
requestTracker.trackDataRequest(
|
|
169
170
|
"ID",
|
|
171
|
+
// @ts-expect-error [FEI-5019] - TS2345 - Argument of type '() => Promise<unknown>' is not assignable to parameter of type '() => Promise<ValidCacheData>'.
|
|
170
172
|
fakeBadRequestHandler,
|
|
171
173
|
true,
|
|
172
174
|
);
|
|
@@ -191,19 +193,22 @@ describe("../request-tracking.js", () => {
|
|
|
191
193
|
* - Handlers that resolve
|
|
192
194
|
*/
|
|
193
195
|
const fakeBadRequestHandler = () =>
|
|
194
|
-
new Promise((resolve, reject) =>
|
|
196
|
+
new Promise((resolve: any, reject: any) =>
|
|
197
|
+
reject("OH NO!"),
|
|
198
|
+
);
|
|
195
199
|
const fakeBadHandler = () => {
|
|
196
200
|
throw new Error("OH NO!");
|
|
197
201
|
};
|
|
198
202
|
const fakeValidHandler = (() => {
|
|
199
203
|
let counter = 0;
|
|
200
|
-
return (o) => {
|
|
204
|
+
return (o: any) => {
|
|
201
205
|
counter++;
|
|
202
206
|
return Promise.resolve(`DATA:${counter}`);
|
|
203
207
|
};
|
|
204
208
|
})();
|
|
205
209
|
requestTracker.trackDataRequest(
|
|
206
210
|
"BAD_REQUEST",
|
|
211
|
+
// @ts-expect-error [FEI-5019] - TS2345 - Argument of type '() => Promise<unknown>' is not assignable to parameter of type '() => Promise<ValidCacheData>'.
|
|
207
212
|
fakeBadRequestHandler,
|
|
208
213
|
true,
|
|
209
214
|
);
|
|
@@ -214,11 +219,13 @@ describe("../request-tracking.js", () => {
|
|
|
214
219
|
);
|
|
215
220
|
requestTracker.trackDataRequest(
|
|
216
221
|
"VALID_HANDLER1",
|
|
222
|
+
// @ts-expect-error [FEI-5019] - TS2345 - Argument of type '(o: any) => Promise<string>' is not assignable to parameter of type '() => Promise<string>'.
|
|
217
223
|
fakeValidHandler,
|
|
218
224
|
true,
|
|
219
225
|
);
|
|
220
226
|
requestTracker.trackDataRequest(
|
|
221
227
|
"VALID_HANDLER2",
|
|
228
|
+
// @ts-expect-error [FEI-5019] - TS2345 - Argument of type '(o: any) => Promise<string>' is not assignable to parameter of type '() => Promise<string>'.
|
|
222
229
|
fakeValidHandler,
|
|
223
230
|
true,
|
|
224
231
|
);
|
package/src/util/__tests__/{result-from-cache-response.test.js → result-from-cache-response.test.ts}
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {resultFromCachedResponse} from "../result-from-cache-response.js";
|
|
1
|
+
import {resultFromCachedResponse} from "../result-from-cache-response";
|
|
3
2
|
|
|
4
3
|
describe("#resultFromCachedResponse", () => {
|
|
5
4
|
it("should return null cache entry is null", () => {
|
|
@@ -18,7 +17,7 @@ describe("#resultFromCachedResponse", () => {
|
|
|
18
17
|
const cacheEntry = {
|
|
19
18
|
data: "DATA",
|
|
20
19
|
error: undefined,
|
|
21
|
-
};
|
|
20
|
+
} as const;
|
|
22
21
|
|
|
23
22
|
// Act
|
|
24
23
|
const result = resultFromCachedResponse(cacheEntry);
|
|
@@ -71,8 +70,7 @@ describe("#resultFromCachedResponse", () => {
|
|
|
71
70
|
};
|
|
72
71
|
|
|
73
72
|
// Act
|
|
74
|
-
//
|
|
75
|
-
// $FlowIgnore[prop-missing]
|
|
73
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'error' does not exist on type 'Result<ValidCacheData> | null | undefined'.
|
|
76
74
|
const {error} = resultFromCachedResponse(cacheEntry);
|
|
77
75
|
|
|
78
76
|
// Assert
|
package/src/util/__tests__/{scoped-in-memory-cache.test.js → scoped-in-memory-cache.test.ts}
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {ScopedInMemoryCache} from "../scoped-in-memory-cache.js";
|
|
1
|
+
import {ScopedInMemoryCache} from "../scoped-in-memory-cache";
|
|
3
2
|
|
|
4
3
|
describe("ScopedInMemoryCache", () => {
|
|
5
4
|
describe("#set", () => {
|
|
@@ -9,7 +8,7 @@ describe("ScopedInMemoryCache", () => {
|
|
|
9
8
|
${""}
|
|
10
9
|
${5}
|
|
11
10
|
${() => "BOO"}
|
|
12
|
-
`("should throw if the id is $id", ({id}) => {
|
|
11
|
+
`("should throw if the id is $id", ({id}: any) => {
|
|
13
12
|
// Arrange
|
|
14
13
|
const cache = new ScopedInMemoryCache();
|
|
15
14
|
|
|
@@ -26,7 +25,7 @@ describe("ScopedInMemoryCache", () => {
|
|
|
26
25
|
${""}
|
|
27
26
|
${5}
|
|
28
27
|
${() => "BOO"}
|
|
29
|
-
`("should throw if the scope is $scope", ({scope}) => {
|
|
28
|
+
`("should throw if the scope is $scope", ({scope}: any) => {
|
|
30
29
|
// Arrange
|
|
31
30
|
const cache = new ScopedInMemoryCache();
|
|
32
31
|
|
|
@@ -190,7 +189,7 @@ describe("ScopedInMemoryCache", () => {
|
|
|
190
189
|
});
|
|
191
190
|
|
|
192
191
|
// Act
|
|
193
|
-
cache.purgeScope("scope1", (id, value) => value === "a");
|
|
192
|
+
cache.purgeScope("scope1", (id: any, value: any) => value === "a");
|
|
194
193
|
const result = cache._cache;
|
|
195
194
|
|
|
196
195
|
// Assert
|
|
@@ -257,7 +256,7 @@ describe("ScopedInMemoryCache", () => {
|
|
|
257
256
|
});
|
|
258
257
|
|
|
259
258
|
// Act
|
|
260
|
-
cache.purgeAll((scope, id, value) => value === "2");
|
|
259
|
+
cache.purgeAll((scope: any, id: any, value: any) => value === "2");
|
|
261
260
|
const result = cache._cache;
|
|
262
261
|
|
|
263
262
|
// Assert
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as WSCore from "@khanacademy/wonder-stuff-core";
|
|
3
|
-
import {SerializableInMemoryCache} from "../serializable-in-memory-cache
|
|
2
|
+
import {SerializableInMemoryCache} from "../serializable-in-memory-cache";
|
|
4
3
|
|
|
5
4
|
describe("SerializableInMemoryCache", () => {
|
|
6
5
|
describe("#constructor", () => {
|
|
@@ -10,11 +9,12 @@ describe("SerializableInMemoryCache", () => {
|
|
|
10
9
|
scope: {
|
|
11
10
|
key: "value",
|
|
12
11
|
},
|
|
13
|
-
};
|
|
12
|
+
} as const;
|
|
14
13
|
|
|
15
14
|
// Act
|
|
16
15
|
const cache = new SerializableInMemoryCache(sourceData);
|
|
17
16
|
// Try to mutate the cache.
|
|
17
|
+
// @ts-expect-error [FEI-5019] - TS2540 - Cannot assign to 'scope' because it is a read-only property.
|
|
18
18
|
sourceData["scope"] = {key: "SOME_NEW_DATA"};
|
|
19
19
|
const result = cache.get("scope", "key");
|
|
20
20
|
|
|
@@ -50,7 +50,7 @@ describe("SerializableInMemoryCache", () => {
|
|
|
50
50
|
${""}
|
|
51
51
|
${5}
|
|
52
52
|
${() => "BOO"}
|
|
53
|
-
`("should throw if the id is $id", ({id}) => {
|
|
53
|
+
`("should throw if the id is $id", ({id}: any) => {
|
|
54
54
|
// Arrange
|
|
55
55
|
const cache = new SerializableInMemoryCache();
|
|
56
56
|
|
|
@@ -67,7 +67,7 @@ describe("SerializableInMemoryCache", () => {
|
|
|
67
67
|
${""}
|
|
68
68
|
${5}
|
|
69
69
|
${() => "BOO"}
|
|
70
|
-
`("should throw if the scope is $scope", ({scope}) => {
|
|
70
|
+
`("should throw if the scope is $scope", ({scope}: any) => {
|
|
71
71
|
// Arrange
|
|
72
72
|
const cache = new SerializableInMemoryCache();
|
|
73
73
|
|
|
@@ -231,7 +231,7 @@ describe("SerializableInMemoryCache", () => {
|
|
|
231
231
|
});
|
|
232
232
|
|
|
233
233
|
// Act
|
|
234
|
-
cache.purgeScope("scope1", (id, value) => value === "a");
|
|
234
|
+
cache.purgeScope("scope1", (id: any, value: any) => value === "a");
|
|
235
235
|
const result = cache.clone();
|
|
236
236
|
|
|
237
237
|
// Assert
|
|
@@ -298,7 +298,7 @@ describe("SerializableInMemoryCache", () => {
|
|
|
298
298
|
});
|
|
299
299
|
|
|
300
300
|
// Act
|
|
301
|
-
cache.purgeAll((scope, id, value) => value === "2");
|
|
301
|
+
cache.purgeAll((scope: any, id: any, value: any) => value === "2");
|
|
302
302
|
const result = cache.clone();
|
|
303
303
|
|
|
304
304
|
// Assert
|
|
@@ -330,7 +330,7 @@ describe("SerializableInMemoryCache", () => {
|
|
|
330
330
|
scope1: {key: "2"},
|
|
331
331
|
scope2: {key: "1"},
|
|
332
332
|
scope3: {key: "2"},
|
|
333
|
-
};
|
|
333
|
+
} as const;
|
|
334
334
|
const cache = new SerializableInMemoryCache(data);
|
|
335
335
|
|
|
336
336
|
// Act
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import {Server} from "@khanacademy/wonder-blocks-core";
|
|
3
|
-
import {SsrCache} from "../ssr-cache
|
|
4
|
-
import {SerializableInMemoryCache} from "../serializable-in-memory-cache
|
|
2
|
+
import {SsrCache} from "../ssr-cache";
|
|
3
|
+
import {SerializableInMemoryCache} from "../serializable-in-memory-cache";
|
|
5
4
|
|
|
6
5
|
describe("../ssr-cache.js", () => {
|
|
7
6
|
afterEach(() => {
|
|
@@ -126,11 +125,12 @@ describe("../ssr-cache.js", () => {
|
|
|
126
125
|
const cache = new SsrCache();
|
|
127
126
|
const sourceData = {
|
|
128
127
|
MY_KEY: {data: "THE_DATA"},
|
|
129
|
-
};
|
|
128
|
+
} as const;
|
|
130
129
|
|
|
131
130
|
// Act
|
|
132
131
|
cache.initialize(sourceData);
|
|
133
132
|
// Try to mutate the cache.
|
|
133
|
+
// @ts-expect-error [FEI-5019] - TS2540 - Cannot assign to 'MY_KEY' because it is a read-only property.
|
|
134
134
|
sourceData["MY_KEY"] = {data: "SOME_NEW_DATA"};
|
|
135
135
|
const result = cache.getEntry("MY_KEY");
|
|
136
136
|
|
|
@@ -448,6 +448,7 @@ describe("../ssr-cache.js", () => {
|
|
|
448
448
|
const cloneSpy = jest
|
|
449
449
|
.spyOn(hydrationCache, "clone")
|
|
450
450
|
.mockReturnValue({
|
|
451
|
+
// @ts-expect-error [FEI-5019] - TS2322 - Type 'string' is not assignable to type '{ [id: string]: ValidCacheData; }'.
|
|
451
452
|
default: "CLONE!",
|
|
452
453
|
});
|
|
453
454
|
const cache = new SsrCache(hydrationCache);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import * as GDNP from "../graphql-document-node-parser.js";
|
|
1
|
+
import {toGqlOperation} from "../to-gql-operation";
|
|
2
|
+
import * as GDNP from "../graphql-document-node-parser";
|
|
4
3
|
|
|
5
|
-
jest.mock("../graphql-document-node-parser
|
|
4
|
+
jest.mock("../graphql-document-node-parser");
|
|
6
5
|
|
|
7
6
|
describe("#toGqlOperation", () => {
|
|
8
7
|
it("should parse the document node", () => {
|
|
@@ -10,6 +9,7 @@ describe("#toGqlOperation", () => {
|
|
|
10
9
|
const documentNode: any = {};
|
|
11
10
|
const parserSpy = jest
|
|
12
11
|
.spyOn(GDNP, "graphQLDocumentNodeParser")
|
|
12
|
+
// @ts-expect-error [FEI-5019] - TS2345 - Argument of type '{ name: string; type: string; }' is not assignable to parameter of type 'IDocumentDefinition'.
|
|
13
13
|
.mockReturnValue({
|
|
14
14
|
name: "operationName",
|
|
15
15
|
type: "query",
|
|
@@ -25,6 +25,7 @@ describe("#toGqlOperation", () => {
|
|
|
25
25
|
it("should return the Wonder Blocks Data representation of the given document node", () => {
|
|
26
26
|
// Arrange
|
|
27
27
|
const documentNode: any = {};
|
|
28
|
+
// @ts-expect-error [FEI-5019] - TS2345 - Argument of type '{ name: string; type: string; }' is not assignable to parameter of type 'IDocumentDefinition'.
|
|
28
29
|
jest.spyOn(GDNP, "graphQLDocumentNodeParser").mockReturnValue({
|
|
29
30
|
name: "operationName",
|
|
30
31
|
type: "mutation",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import {KindError} from "@khanacademy/wonder-stuff-core";
|
|
3
|
-
import type {ErrorOptions} from "./types
|
|
2
|
+
import type {ErrorOptions} from "./types";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Error kinds for DataError.
|
|
@@ -52,8 +51,8 @@ export const DataErrors = Object.freeze({
|
|
|
52
51
|
export class DataError extends KindError {
|
|
53
52
|
constructor(
|
|
54
53
|
message: string,
|
|
55
|
-
kind:
|
|
56
|
-
{metadata, cause}: ErrorOptions =
|
|
54
|
+
kind: typeof DataErrors[keyof typeof DataErrors],
|
|
55
|
+
{metadata, cause}: ErrorOptions = {} as Partial<ErrorOptions>,
|
|
57
56
|
) {
|
|
58
57
|
super(message, kind, {
|
|
59
58
|
metadata,
|