@khanacademy/wonder-blocks-data 10.1.0 → 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 +24 -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
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {Meta} from "@storybook/addon-docs";
|
|
2
|
-
|
|
3
|
-
<Meta
|
|
4
|
-
title="Data / Types / GqlOperationType"
|
|
5
|
-
parameters={{
|
|
6
|
-
chromatic: {
|
|
7
|
-
disableSnapshot: true,
|
|
8
|
-
},
|
|
9
|
-
}}
|
|
10
|
-
/>
|
|
11
|
-
|
|
12
|
-
# GqlOperationType
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
type GqlOperationType = "mutation" | "query";
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Unlike some GraphQL clients, the Wonder Blocks Data GraphQL support avoids requiring the full GraphQL document node at runtime. This allows the client to be lighter weight and introduces the option for calling code to perform some GraphQL request optimizations at build time, such as formatting the document node as a string and therefore not requiring additional dependencies at runtime.
|
|
19
|
-
|
|
20
|
-
In order to allow consumers of our GraphQL support to include some validation of the GraphQL document node at runtime (such as ensuring that mutations are not performed in unsupported scenarios), we the type of the operation is included in the operation definition.
|
|
21
|
-
|
|
22
|
-
This type represents the valid values for that field.
|
|
23
|
-
|
|
24
|
-
See the section on [GraphQL](/docs/data-graphql--page) for more information.
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {Meta} from "@storybook/addon-docs";
|
|
2
|
-
|
|
3
|
-
<Meta
|
|
4
|
-
title="Data / Types / GqlOperation<>"
|
|
5
|
-
parameters={{
|
|
6
|
-
chromatic: {
|
|
7
|
-
disableSnapshot: true,
|
|
8
|
-
},
|
|
9
|
-
}}
|
|
10
|
-
/>
|
|
11
|
-
|
|
12
|
-
# GqlOperation<>
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
type GqlOperation<
|
|
16
|
-
TData,
|
|
17
|
-
TVariables: {...} = Empty,
|
|
18
|
-
> = {
|
|
19
|
-
type: GqlOperationType,
|
|
20
|
-
id: string,
|
|
21
|
-
[key: string]: mixed,
|
|
22
|
-
...
|
|
23
|
-
};
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
The `GqlOperation<>` type provides the Wonder Blocks Data definition of a GraphQL query or mutation. It has two required fields:
|
|
27
|
-
|
|
28
|
-
* `type`: The type of operation. It can be either `"query"` or `"mutation"`.
|
|
29
|
-
* `id`: The unique identifier of the operation.
|
|
30
|
-
|
|
31
|
-
Unlike some GraphQL clients, the definition of the operation (the document node, for example) is not required by the Wonder Blocks Data implementation. If a specific use requires that information, the calling code is able to provide it.
|
|
32
|
-
|
|
33
|
-
Consider the following GraphQL query (using `graphql-tag`):
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
const MyQuery = gql`
|
|
37
|
-
query myQuery {
|
|
38
|
-
user {
|
|
39
|
-
id
|
|
40
|
-
name
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
`;
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Rather than using the full `DocumentNode` at runtime, one could envisage a build step that converts it to a `GqlOperation<>` at compile time by parsing the `DocumentNode` to determine the operation type and extract the name of the operation. If the actual definition is needed for sending to the server in the request, this can be obtained from `graphql/language/printer`. This would then reduce the dependencies needed to perform GraphQL operations at runtime.
|
|
47
|
-
|
|
48
|
-
The resulting `GqlOperation<>` would look like this:
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
{
|
|
52
|
-
type: "query",
|
|
53
|
-
id: "myQuery",
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
Or, if say, the query definition were needed (for example, Apollo will send requests with the `query` field):
|
|
58
|
-
|
|
59
|
-
```ts
|
|
60
|
-
{
|
|
61
|
-
type: "query",
|
|
62
|
-
id: "myQuery",
|
|
63
|
-
query: "query myQuery { user { id name } }",
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
See the section on [GraphQL](/docs/data-graphql--page) for more information.
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {Meta} from "@storybook/addon-docs";
|
|
2
|
-
|
|
3
|
-
<Meta
|
|
4
|
-
title="Data / Types / RawScopedCache"
|
|
5
|
-
parameters={{
|
|
6
|
-
chromatic: {
|
|
7
|
-
disableSnapshot: true,
|
|
8
|
-
},
|
|
9
|
-
}}
|
|
10
|
-
/>
|
|
11
|
-
|
|
12
|
-
# RawScopedCache
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
type RawScopedCache = {
|
|
16
|
-
[scope: string]: {
|
|
17
|
-
[id: string]: ValidCacheData,
|
|
18
|
-
...
|
|
19
|
-
},
|
|
20
|
-
...
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
`RawScopedCache` describes a cache that has distinct scoped sections in its raw object form. This is the representation of the caches used internally by Wonder Blocks Data to support the scoping of requests when using hooks such as [`useSharedCache`](/docs/data-exports-use-shared-cache--page), [`useCachedEffect`](/docs/data-exports-use-cached-effect--page), and [`useHydratableEffect`](/docs/data-exports-use-hydratable-effect--page).
|
|
26
|
-
|
|
27
|
-
See the section on [server-side rendering](/docs/data-server-side-rendering-and-hydration--page) for more information.
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {Meta} from "@storybook/addon-docs";
|
|
2
|
-
|
|
3
|
-
<Meta
|
|
4
|
-
title="Data / Types / ResponseCache"
|
|
5
|
-
parameters={{
|
|
6
|
-
chromatic: {
|
|
7
|
-
disableSnapshot: true,
|
|
8
|
-
},
|
|
9
|
-
}}
|
|
10
|
-
/>
|
|
11
|
-
|
|
12
|
-
# ResponseCache
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
type ResponseCache = {
|
|
16
|
-
[key: string]: CachedResponse<any>,
|
|
17
|
-
...
|
|
18
|
-
};
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
`ResponseCache` describes the serialized cache that is used to hydrate responses. An example of a valid `ResponseCache` instance is shown below. Generally, you would not generate this object directly, but rather use the returned data from [`fetchTrackedRequests`](/docs/data-exports-fetchtrackedrequests--page).
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
const responseCache: ResponseCache = {
|
|
25
|
-
DATA_ID_1: {error: "It go 💥boom 😢"},
|
|
26
|
-
DATA_ID_2: {data: ["array", "of", "data"]},
|
|
27
|
-
DATA_ID_3: {data: {some: "data"}},
|
|
28
|
-
};
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
In this example, the cache contains data retrieved for three different requests.
|
|
32
|
-
|
|
33
|
-
Each entry in the cache is of type [`CachedResponse`](/docs/data-types-cachedresponse--page). See the section on [server-side rendering](/docs/data-server-side-rendering-and-hydration--page) for more information.
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {Meta} from "@storybook/addon-docs";
|
|
2
|
-
|
|
3
|
-
<Meta
|
|
4
|
-
title="Data / Types / Result<>"
|
|
5
|
-
parameters={{
|
|
6
|
-
chromatic: {
|
|
7
|
-
disableSnapshot: true,
|
|
8
|
-
},
|
|
9
|
-
}}
|
|
10
|
-
/>
|
|
11
|
-
|
|
12
|
-
# Result<>
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
type Result<TData: ValidCacheData> =
|
|
16
|
-
| {|
|
|
17
|
-
status: "loading",
|
|
18
|
-
|}
|
|
19
|
-
| {|
|
|
20
|
-
status: "success",
|
|
21
|
-
data: TData,
|
|
22
|
-
|}
|
|
23
|
-
| {|
|
|
24
|
-
status: "error",
|
|
25
|
-
error: Error,
|
|
26
|
-
|}
|
|
27
|
-
| {|
|
|
28
|
-
status: "aborted",
|
|
29
|
-
|};
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
The `Result<>` type is used to describe the result of an asynchronous operation. It is the primary type used by hooks and components in Wonder Blocks Data to convey the status of asynchronous tasks.
|
|
33
|
-
|
|
34
|
-
There are four states represented by the `Result<>` type:
|
|
35
|
-
|
|
36
|
-
* `loading`: The operation is in pending.
|
|
37
|
-
* `success`: The operation completed successfully.
|
|
38
|
-
* `error`: The operation failed.
|
|
39
|
-
* `aborted`: The operation was aborted.
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import {Meta} from "@storybook/addon-docs";
|
|
2
|
-
|
|
3
|
-
<Meta
|
|
4
|
-
title="Data / Types / ScopedCache"
|
|
5
|
-
parameters={{
|
|
6
|
-
chromatic: {
|
|
7
|
-
disableSnapshot: true,
|
|
8
|
-
},
|
|
9
|
-
}}
|
|
10
|
-
/>
|
|
11
|
-
|
|
12
|
-
# ScopedCache
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
interface ScopedCache {
|
|
16
|
-
set(scope: string, id: string, value: ValidCacheData): void;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Retrieve a value from the cache.
|
|
20
|
-
*/
|
|
21
|
-
get(scope: string, id: string): ?ValidCacheData;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Purge an item from the cache.
|
|
25
|
-
*/
|
|
26
|
-
purge(scope: string, id: string): void;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Purge a scope of items that match the given predicate.
|
|
30
|
-
*
|
|
31
|
-
* If the predicate is omitted, then all items in the scope are purged.
|
|
32
|
-
*/
|
|
33
|
-
purgeScope(
|
|
34
|
-
scope: string,
|
|
35
|
-
predicate?: (id: string, value: ValidCacheData) => boolean,
|
|
36
|
-
): void;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Purge all items from the cache that match the given predicate.
|
|
40
|
-
*
|
|
41
|
-
* If the predicate is omitted, then all items in the cache are purged.
|
|
42
|
-
*/
|
|
43
|
-
purgeAll(
|
|
44
|
-
predicate?: (
|
|
45
|
-
scope: string,
|
|
46
|
-
id: string,
|
|
47
|
-
value: ValidCacheData,
|
|
48
|
-
) => boolean,
|
|
49
|
-
): void;
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
This interface defines how to interact with a scoped cache, such as [`ScopedInMemoryCache`](/docs/data-exports-scopedinmemorycache--page).
|
|
54
|
-
|
|
55
|
-
## set()
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
set(
|
|
59
|
-
scope: string,
|
|
60
|
-
id: string,
|
|
61
|
-
value: TValue,
|
|
62
|
-
): void;
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Sets a value in the cache within a given scope.
|
|
66
|
-
|
|
67
|
-
### Throws
|
|
68
|
-
|
|
69
|
-
| Error Type | Error Name | Reason |
|
|
70
|
-
| ------ | ------ | ------ |
|
|
71
|
-
| [`DataError`](/docs/data-exports-dataerror--page) | `InvalidInputDataError` | `id` and `scope` must be non-empty strings |
|
|
72
|
-
| [`DataError`](/docs/data-exports-dataerror--page) | `InvalidInputDataError` | `value` must be a non-function value |
|
|
73
|
-
|
|
74
|
-
## get()
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
get(scope: string, id: string): ?ValidCacheData;
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Gets a value from the cache. If a value with the given identifier (`id`) is not found within the given scope (`scope`) of the cache, `null` is returned.
|
|
81
|
-
|
|
82
|
-
## purge()
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
purge(scope: string, id: string): void;
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Purges the value from the cache. If a value with the given identifier (`id`) is not found within the given scope (`scope`) of the cache, nothing happens.
|
|
89
|
-
|
|
90
|
-
## purgeScope()
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
purgeScope(
|
|
94
|
-
scope: string,
|
|
95
|
-
predicate?: (id: string, value: ValidCacheData) => boolean,
|
|
96
|
-
): void;
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Purges items within a given scope (`scope`) of the cache from that scope. If a predicate is provided, only items for which the predicate returns `true` will be purged; otherwise, the entire scope will be purged.
|
|
100
|
-
|
|
101
|
-
## purgeAll()
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
purgeAll(
|
|
105
|
-
predicate?: (
|
|
106
|
-
scope: string,
|
|
107
|
-
id: string,
|
|
108
|
-
value: ValidCacheData,
|
|
109
|
-
) => boolean,
|
|
110
|
-
): void;
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
Purges all items from the cache. If a predicate is provided, only items for which the predicate returns `true` will be purged; otherwise, the entire cache will be purged.
|
|
114
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {Meta} from "@storybook/addon-docs";
|
|
2
|
-
|
|
3
|
-
<Meta
|
|
4
|
-
title="Data / Types / ValidCacheData"
|
|
5
|
-
parameters={{
|
|
6
|
-
chromatic: {
|
|
7
|
-
disableSnapshot: true,
|
|
8
|
-
},
|
|
9
|
-
}}
|
|
10
|
-
/>
|
|
11
|
-
|
|
12
|
-
# ValidCacheData
|
|
13
|
-
|
|
14
|
-
```ts
|
|
15
|
-
type ValidCacheData =
|
|
16
|
-
| string
|
|
17
|
-
| boolean
|
|
18
|
-
| number
|
|
19
|
-
| {...}
|
|
20
|
-
| Array<?ValidCacheData>;
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
This type represents the data that is allowed into the various caches provided and used by Wonder Blocks Data.
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
// NOTE(somewhatabstract):
|
|
3
|
-
// These types are bare minimum to support document parsing. They're derived
|
|
4
|
-
// from graphql@14.5.8, the last version that provided flow types.
|
|
5
|
-
// Doing this avoids us having to take a dependency on that library just for
|
|
6
|
-
// these types.
|
|
7
|
-
export interface DefinitionNode {
|
|
8
|
-
+kind: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export type VariableDefinitionNode = {
|
|
12
|
-
+kind: "VariableDefinition",
|
|
13
|
-
...
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export interface OperationDefinitionNode extends DefinitionNode {
|
|
17
|
-
+kind: "OperationDefinition";
|
|
18
|
-
+operation: string;
|
|
19
|
-
+variableDefinitions: $ReadOnlyArray<VariableDefinitionNode>;
|
|
20
|
-
+name?: {|
|
|
21
|
-
+kind: mixed,
|
|
22
|
-
+value: string,
|
|
23
|
-
|};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type DocumentNode = {
|
|
27
|
-
+kind: "Document",
|
|
28
|
-
+definitions: $ReadOnlyArray<DefinitionNode>,
|
|
29
|
-
...
|
|
30
|
-
};
|
|
File without changes
|
|
File without changes
|