@khanacademy/wonder-blocks-data 11.0.16 → 12.0.0
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 +13 -0
- package/dist/es/index.js +14 -12
- package/dist/hooks/use-hydratable-effect.d.ts +6 -6
- package/dist/index.js +14 -12
- package/dist/util/types.d.ts +6 -6
- package/package.json +3 -3
- package/src/hooks/use-hydratable-effect.ts +6 -7
- package/src/util/types.ts +6 -7
- package/tsconfig-build.tsbuildinfo +1 -1
- package/dist/components/data.js.flow +0 -63
- package/dist/components/gql-router.js.flow +0 -33
- package/dist/components/intercept-context.js.flow +0 -18
- package/dist/components/intercept-requests.js.flow +0 -51
- package/dist/components/track-data.js.flow +0 -16
- package/dist/hooks/use-cached-effect.js.flow +0 -83
- package/dist/hooks/use-gql-router-context.js.flow +0 -14
- package/dist/hooks/use-gql.js.flow +0 -28
- package/dist/hooks/use-hydratable-effect.js.flow +0 -122
- package/dist/hooks/use-request-interception.js.flow +0 -24
- package/dist/hooks/use-server-effect.js.flow +0 -49
- package/dist/hooks/use-shared-cache.js.flow +0 -42
- package/dist/index.js.flow +0 -47
- package/dist/util/data-error.js.flow +0 -62
- package/dist/util/get-gql-data-from-response.js.flow +0 -12
- package/dist/util/get-gql-request-id.js.flow +0 -16
- package/dist/util/gql-error.js.flow +0 -41
- package/dist/util/gql-router-context.js.flow +0 -10
- package/dist/util/gql-types.js.flow +0 -50
- package/dist/util/graphql-document-node-parser.js.flow +0 -29
- package/dist/util/graphql-types.js.flow +0 -30
- package/dist/util/hydration-cache-api.js.flow +0 -29
- package/dist/util/merge-gql-context.js.flow +0 -18
- package/dist/util/purge-caches.js.flow +0 -14
- package/dist/util/request-api.js.flow +0 -33
- package/dist/util/request-fulfillment.js.flow +0 -48
- package/dist/util/request-tracking.js.flow +0 -81
- package/dist/util/result-from-cache-response.js.flow +0 -14
- package/dist/util/scoped-in-memory-cache.js.flow +0 -56
- package/dist/util/serializable-in-memory-cache.js.flow +0 -25
- package/dist/util/ssr-cache.js.flow +0 -86
- package/dist/util/status.js.flow +0 -17
- package/dist/util/to-gql-operation.js.flow +0 -41
- package/dist/util/types.js.flow +0 -142
- package/src/util/graphql-types.js.flow +0 -30
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { ValidCacheData, CachedResponse, ResponseCache } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Initialize the hydration cache.
|
|
11
|
-
* @param {ResponseCache} source The cache content to use for initializing the
|
|
12
|
-
* cache.
|
|
13
|
-
* @throws {Error} If the cache is already initialized.
|
|
14
|
-
*/
|
|
15
|
-
declare export var initializeHydrationCache: (source: ResponseCache) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Purge cached hydration responses that match the given predicate.
|
|
18
|
-
* @param {(id: string) => boolean} [predicate] The predicate to match against
|
|
19
|
-
* the cached hydration responses. If no predicate is provided, all cached
|
|
20
|
-
* hydration responses will be purged.
|
|
21
|
-
*/
|
|
22
|
-
declare export var purgeHydrationCache: (
|
|
23
|
-
predicate?:
|
|
24
|
-
| ((
|
|
25
|
-
key: string,
|
|
26
|
-
cacheEntry?: $ReadOnly<CachedResponse<ValidCacheData>> | null | void
|
|
27
|
-
) => boolean)
|
|
28
|
-
| void
|
|
29
|
-
) => void;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { GqlContext } from "./gql-types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Construct a complete GqlContext from current defaults and a partial context.
|
|
11
|
-
*
|
|
12
|
-
* Values in the partial context that are `undefined` will be ignored.
|
|
13
|
-
* Values in the partial context that are `null` will be deleted.
|
|
14
|
-
*/
|
|
15
|
-
declare export var mergeGqlContext: <TContext: GqlContext>(
|
|
16
|
-
defaultContext: TContext,
|
|
17
|
-
overrides: $Rest<TContext, {}>
|
|
18
|
-
) => TContext;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Purge all caches managed by Wonder Blocks Data.
|
|
9
|
-
*
|
|
10
|
-
* This is a convenience method that purges the shared cache and the hydration
|
|
11
|
-
* cache. It is useful for testing purposes to avoid having to reason about
|
|
12
|
-
* which caches may have been used during a given test run.
|
|
13
|
-
*/
|
|
14
|
-
declare export var purgeCaches: () => void;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { ResponseCache } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Fetches all tracked data requests.
|
|
11
|
-
*
|
|
12
|
-
* This is for use with the `TrackData` component during server-side rendering.
|
|
13
|
-
* @throws {Error} If executed outside of server-side rendering.
|
|
14
|
-
* @returns {Promise<void>} A promise that resolves when all tracked requests
|
|
15
|
-
* have been fetched.
|
|
16
|
-
*/
|
|
17
|
-
declare export var fetchTrackedRequests: () => Promise<ResponseCache>;
|
|
18
|
-
/**
|
|
19
|
-
* Indicate if there are tracked requests waiting to be fetched.
|
|
20
|
-
*
|
|
21
|
-
* This is used in conjunction with `TrackData`.
|
|
22
|
-
* @throws {Error} If executed outside of server-side rendering.
|
|
23
|
-
* @returns {boolean} `true` if there are unfetched tracked requests;
|
|
24
|
-
* otherwise, `false`.
|
|
25
|
-
*/
|
|
26
|
-
declare export var hasTrackedRequestsToBeFetched: () => boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Abort all in-flight requests.
|
|
29
|
-
*
|
|
30
|
-
* This aborts all requests currently inflight via our default request
|
|
31
|
-
* fulfillment.
|
|
32
|
-
*/
|
|
33
|
-
declare export var abortInflightRequests: () => void;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { Result, ValidCacheData } from "./types";
|
|
8
|
-
declare type RequestCache = {
|
|
9
|
-
[id: string]: Promise<Result<any>>,
|
|
10
|
-
};
|
|
11
|
-
declare type FulfillOptions<TData: ValidCacheData> = {|
|
|
12
|
-
handler: () => Promise<TData>,
|
|
13
|
-
hydrate?: boolean,
|
|
14
|
-
|};
|
|
15
|
-
/**
|
|
16
|
-
* This fulfills a request, making sure that in-flight requests are shared.
|
|
17
|
-
*/
|
|
18
|
-
declare export class RequestFulfillment {
|
|
19
|
-
static Default: RequestFulfillment;
|
|
20
|
-
_requests: RequestCache;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get a promise of a request for a given handler and options.
|
|
24
|
-
*
|
|
25
|
-
* This will return an inflight request if one exists, otherwise it will
|
|
26
|
-
* make a new request. Inflight requests are deleted once they resolve.
|
|
27
|
-
*/
|
|
28
|
-
fulfill: <TData: ValidCacheData>(
|
|
29
|
-
id: string,
|
|
30
|
-
options: FulfillOptions<TData>
|
|
31
|
-
) => Promise<Result<TData>>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Abort an inflight request.
|
|
35
|
-
*
|
|
36
|
-
* NOTE: Currently, this does not perform an actual abort. It merely
|
|
37
|
-
* removes the request from being tracked.
|
|
38
|
-
*/
|
|
39
|
-
abort: (id: string) => void;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Abort all inflight requests.
|
|
43
|
-
*
|
|
44
|
-
* NOTE: Currently, this does not perform actual aborts. It merely
|
|
45
|
-
* removes the requests from our tracking.
|
|
46
|
-
*/
|
|
47
|
-
abortAll: () => void;
|
|
48
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import * as React from "react";
|
|
8
|
-
import { SsrCache } from "./ssr-cache";
|
|
9
|
-
import { RequestFulfillment } from "./request-fulfillment";
|
|
10
|
-
import type { ResponseCache, ValidCacheData } from "./types";
|
|
11
|
-
declare type TrackerFn = <TData: ValidCacheData>(
|
|
12
|
-
id: string,
|
|
13
|
-
handler: () => Promise<TData>,
|
|
14
|
-
hydrate: boolean
|
|
15
|
-
) => void;
|
|
16
|
-
declare type RequestCache = {
|
|
17
|
-
[id: string]: {|
|
|
18
|
-
hydrate: boolean,
|
|
19
|
-
handler: () => Promise<any>,
|
|
20
|
-
|},
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Used to inject our tracking function into the render framework.
|
|
24
|
-
*
|
|
25
|
-
* INTERNAL USE ONLY
|
|
26
|
-
*/
|
|
27
|
-
declare var TrackerContext: React.Context<TrackerFn | null | void>;
|
|
28
|
-
declare export { TrackerContext };
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Implements request tracking and fulfillment.
|
|
32
|
-
*
|
|
33
|
-
* INTERNAL USE ONLY
|
|
34
|
-
*/
|
|
35
|
-
declare export class RequestTracker {
|
|
36
|
-
static Default: RequestTracker;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* These are the caches for tracked requests, their handlers, and responses.
|
|
40
|
-
*/
|
|
41
|
-
_trackedRequests: RequestCache;
|
|
42
|
-
_responseCache: SsrCache;
|
|
43
|
-
_requestFulfillment: RequestFulfillment;
|
|
44
|
-
constructor(responseCache?: SsrCache | null): this;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Track a request.
|
|
48
|
-
*
|
|
49
|
-
* This method caches a request and its handler for use during server-side
|
|
50
|
-
* rendering to allow us to fulfill requests before producing a final render.
|
|
51
|
-
*/
|
|
52
|
-
trackDataRequest: <TData: ValidCacheData>(
|
|
53
|
-
id: string,
|
|
54
|
-
handler: () => Promise<TData>,
|
|
55
|
-
hydrate: boolean
|
|
56
|
-
) => void;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Reset our tracking info.
|
|
60
|
-
*/
|
|
61
|
-
reset: () => void;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Indicates if we have requests waiting to be fulfilled.
|
|
65
|
-
*/
|
|
66
|
-
hasUnfulfilledRequests: boolean;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Initiate fulfillment of all tracked requests.
|
|
70
|
-
*
|
|
71
|
-
* This loops over the requests that were tracked using TrackData, and asks
|
|
72
|
-
* the respective handlers to fulfill those requests in the order they were
|
|
73
|
-
* tracked.
|
|
74
|
-
*
|
|
75
|
-
* Calling this method marks tracked requests as fulfilled; requests are
|
|
76
|
-
* removed from the list of tracked requests by calling this method.
|
|
77
|
-
* @returns {Promise<ResponseCache>} The promise of the data that was
|
|
78
|
-
* cached as a result of fulfilling the tracked requests.
|
|
79
|
-
*/
|
|
80
|
-
fulfillTrackedRequests: () => Promise<ResponseCache>;
|
|
81
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { ValidCacheData, CachedResponse, Result } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Turns a cache entry into a stateful result.
|
|
11
|
-
*/
|
|
12
|
-
declare export var resultFromCachedResponse: <TData: ValidCacheData>(
|
|
13
|
-
cacheEntry?: CachedResponse<TData> | null | void
|
|
14
|
-
) => Result<TData> | null | void;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { ScopedCache, RawScopedCache, ValidCacheData } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Describe an in-memory cache.
|
|
11
|
-
*/
|
|
12
|
-
declare export class ScopedInMemoryCache implements ScopedCache {
|
|
13
|
-
_cache: RawScopedCache;
|
|
14
|
-
constructor(initialCache?: RawScopedCache): this;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Indicate if this cache is being used or not.
|
|
18
|
-
*
|
|
19
|
-
* When the cache has entries, returns `true`; otherwise, returns `false`.
|
|
20
|
-
*/
|
|
21
|
-
inUse: boolean;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Set a value in the cache.
|
|
25
|
-
*/
|
|
26
|
-
set(scope: string, id: string, value: ValidCacheData): void;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Retrieve a value from the cache.
|
|
30
|
-
*/
|
|
31
|
-
get(scope: string, id: string): ValidCacheData | null | void;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Purge an item from the cache.
|
|
35
|
-
*/
|
|
36
|
-
purge(scope: string, id: string): void;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Purge a scope of items that match the given predicate.
|
|
40
|
-
*
|
|
41
|
-
* If the predicate is omitted, then all items in the scope are purged.
|
|
42
|
-
*/
|
|
43
|
-
purgeScope(
|
|
44
|
-
scope: string,
|
|
45
|
-
predicate?: (id: string, value: ValidCacheData) => boolean
|
|
46
|
-
): void;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Purge all items from the cache that match the given predicate.
|
|
50
|
-
*
|
|
51
|
-
* If the predicate is omitted, then all items in the cache are purged.
|
|
52
|
-
*/
|
|
53
|
-
purgeAll(
|
|
54
|
-
predicate?: (scope: string, id: string, value: ValidCacheData) => boolean
|
|
55
|
-
): void;
|
|
56
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import { ScopedInMemoryCache } from "./scoped-in-memory-cache";
|
|
8
|
-
import type { ValidCacheData, RawScopedCache } from "./types";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Describe a serializable in-memory cache.
|
|
12
|
-
*/
|
|
13
|
-
declare export class SerializableInMemoryCache extends ScopedInMemoryCache {
|
|
14
|
-
constructor(initialCache?: RawScopedCache): this;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Set a value in the cache.
|
|
18
|
-
*/
|
|
19
|
-
set(scope: string, id: string, value: ValidCacheData): void;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Clone the cache.
|
|
23
|
-
*/
|
|
24
|
-
clone(): RawScopedCache;
|
|
25
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import { SerializableInMemoryCache } from "./serializable-in-memory-cache";
|
|
8
|
-
import type { ValidCacheData, CachedResponse, ResponseCache } from "./types";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Implements the response cache.
|
|
12
|
-
*
|
|
13
|
-
* INTERNAL USE ONLY
|
|
14
|
-
*/
|
|
15
|
-
declare export class SsrCache {
|
|
16
|
-
static Default: SsrCache;
|
|
17
|
-
_hydrationCache: SerializableInMemoryCache;
|
|
18
|
-
_ssrOnlyCache: SerializableInMemoryCache;
|
|
19
|
-
constructor(
|
|
20
|
-
hydrationCache?: SerializableInMemoryCache | null,
|
|
21
|
-
ssrOnlyCache?: SerializableInMemoryCache | null
|
|
22
|
-
): this;
|
|
23
|
-
_setCachedResponse<TData: ValidCacheData>(
|
|
24
|
-
id: string,
|
|
25
|
-
entry: CachedResponse<TData>,
|
|
26
|
-
hydrate: boolean
|
|
27
|
-
): CachedResponse<TData>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Initialize the cache from a given cache state.
|
|
31
|
-
*
|
|
32
|
-
* This can only be called if the cache is not already in use.
|
|
33
|
-
*/
|
|
34
|
-
initialize: (source: ResponseCache) => void;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Cache data for a specific response.
|
|
38
|
-
*
|
|
39
|
-
* This is a noop when client-side.
|
|
40
|
-
*/
|
|
41
|
-
cacheData: <TData: ValidCacheData>(
|
|
42
|
-
id: string,
|
|
43
|
-
data: TData,
|
|
44
|
-
hydrate: boolean
|
|
45
|
-
) => CachedResponse<TData>;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Cache an error for a specific response.
|
|
49
|
-
*
|
|
50
|
-
* This is a noop when client-side.
|
|
51
|
-
*/
|
|
52
|
-
cacheError: <TData: ValidCacheData>(
|
|
53
|
-
id: string,
|
|
54
|
-
error: Error | string,
|
|
55
|
-
hydrate: boolean
|
|
56
|
-
) => CachedResponse<TData>;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Retrieve data from our cache.
|
|
60
|
-
*/
|
|
61
|
-
getEntry: <TData: ValidCacheData>(
|
|
62
|
-
id: string
|
|
63
|
-
) => $ReadOnly<CachedResponse<TData>> | null | void;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Remove from cache, any entries matching the given handler and predicate.
|
|
67
|
-
*
|
|
68
|
-
* This will, if present therein, remove matching values from the framework
|
|
69
|
-
* in-memory cache.
|
|
70
|
-
*
|
|
71
|
-
* It returns a count of all records removed.
|
|
72
|
-
*/
|
|
73
|
-
purgeData: (
|
|
74
|
-
predicate?: (
|
|
75
|
-
key: string,
|
|
76
|
-
cachedEntry: $ReadOnly<CachedResponse<ValidCacheData>>
|
|
77
|
-
) => boolean
|
|
78
|
-
) => void;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Deep clone the hydration cache.
|
|
82
|
-
*
|
|
83
|
-
* By design, this only clones the data that is to be used for hydration.
|
|
84
|
-
*/
|
|
85
|
-
cloneHydratableData: () => ResponseCache;
|
|
86
|
-
}
|
package/dist/util/status.js.flow
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { Result, ValidCacheData } from "./types";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Create Result<TData> instances with specific statuses.
|
|
11
|
-
*/
|
|
12
|
-
declare export var Status: $ReadOnly<{|
|
|
13
|
-
loading: <TData: ValidCacheData>() => Result<TData>,
|
|
14
|
-
aborted: <TData_1: ValidCacheData>() => Result<TData_1>,
|
|
15
|
-
success: <TData_2: ValidCacheData>(data: TData_2) => Result<TData_2>,
|
|
16
|
-
error: <TData_3: ValidCacheData>(error: Error) => Result<TData_3>,
|
|
17
|
-
|}>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { GqlOperation } from "./gql-types";
|
|
8
|
-
import type { DocumentNode } from "./graphql-types";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Convert a GraphQL DocumentNode to a base Wonder Blocks Data GqlOperation.
|
|
12
|
-
*
|
|
13
|
-
* If you want to include the query/mutation body, extend the result of this
|
|
14
|
-
* method and use the `graphql/language/printer` like:
|
|
15
|
-
*
|
|
16
|
-
* ```js
|
|
17
|
-
* import {print} from "graphql/language/printer";
|
|
18
|
-
*
|
|
19
|
-
* const gqlOpWithBody = {
|
|
20
|
-
* ...toGqlOperation(documentNode),
|
|
21
|
-
* query: print(documentNode),
|
|
22
|
-
* };
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* If you want to enforce inclusion of __typename properties, then you can use
|
|
26
|
-
* `apollo-utilities` first to modify the document:
|
|
27
|
-
*
|
|
28
|
-
* ```js
|
|
29
|
-
* import {print} from "graphql/language/printer";
|
|
30
|
-
* import {addTypenameToDocument} from "apollo-utilities";
|
|
31
|
-
*
|
|
32
|
-
* const documentWithTypenames = addTypenameToDocument(documentNode);
|
|
33
|
-
* const gqlOpWithBody = {
|
|
34
|
-
* ...toGqlOperation(documentWithTypenames),
|
|
35
|
-
* query: print(documentWithTypenames),
|
|
36
|
-
* };
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
declare export var toGqlOperation: <TData, TVariables: { [key: any]: any }>(
|
|
40
|
-
documentNode: DocumentNode
|
|
41
|
-
) => GqlOperation<TData, TVariables>;
|
package/dist/util/types.js.flow
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for data
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
import type { Metadata } from "@khanacademy/wonder-stuff-core";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Defines the various fetch policies that can be applied to requests.
|
|
11
|
-
*/
|
|
12
|
-
declare export var FetchPolicy: {|
|
|
13
|
-
/**
|
|
14
|
-
* If the data is in the cache, return that; otherwise, fetch from the
|
|
15
|
-
* server.
|
|
16
|
-
*/
|
|
17
|
-
+CacheBeforeNetwork: "CacheBeforeNetwork",
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* If the data is in the cache, return that; always fetch from the server
|
|
21
|
-
* regardless of cache.
|
|
22
|
-
*/
|
|
23
|
-
+CacheAndNetwork: "CacheAndNetwork",
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* If the data is in the cache, return that; otherwise, do nothing.
|
|
27
|
-
*/
|
|
28
|
-
+CacheOnly: "CacheOnly",
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Ignore any existing cached result; always fetch from the server.
|
|
32
|
-
*/
|
|
33
|
-
+NetworkOnly: "NetworkOnly",
|
|
34
|
-
|};
|
|
35
|
-
/**
|
|
36
|
-
* Define what can be cached.
|
|
37
|
-
*
|
|
38
|
-
* We disallow functions and undefined as undefined represents a cache miss
|
|
39
|
-
* and functions are not allowed.
|
|
40
|
-
*/
|
|
41
|
-
export type ValidCacheData =
|
|
42
|
-
| string
|
|
43
|
-
| boolean
|
|
44
|
-
| number
|
|
45
|
-
| { [key: any]: any }
|
|
46
|
-
| Array<ValidCacheData | null | void>;
|
|
47
|
-
/**
|
|
48
|
-
* The normalized result of a request.
|
|
49
|
-
*/
|
|
50
|
-
export type Result<TData: ValidCacheData> =
|
|
51
|
-
| {|
|
|
52
|
-
status: "loading",
|
|
53
|
-
|}
|
|
54
|
-
| {|
|
|
55
|
-
status: "success",
|
|
56
|
-
data: TData,
|
|
57
|
-
|}
|
|
58
|
-
| {|
|
|
59
|
-
status: "error",
|
|
60
|
-
error: Error,
|
|
61
|
-
|}
|
|
62
|
-
| {|
|
|
63
|
-
status: "aborted",
|
|
64
|
-
|};
|
|
65
|
-
/**
|
|
66
|
-
* A cache entry for a fulfilled request response.
|
|
67
|
-
*/
|
|
68
|
-
export type CachedResponse<TData: ValidCacheData> =
|
|
69
|
-
| {|
|
|
70
|
-
+error: string,
|
|
71
|
-
+data?: void,
|
|
72
|
-
|}
|
|
73
|
-
| {|
|
|
74
|
-
+data: TData,
|
|
75
|
-
+error?: void,
|
|
76
|
-
|};
|
|
77
|
-
/**
|
|
78
|
-
* A cache of fulfilled request responses.
|
|
79
|
-
*/
|
|
80
|
-
export type ResponseCache = {
|
|
81
|
-
[key: string]: CachedResponse<any>,
|
|
82
|
-
};
|
|
83
|
-
/**
|
|
84
|
-
* A cache with scoped sections.
|
|
85
|
-
*/
|
|
86
|
-
export type RawScopedCache = {
|
|
87
|
-
/**
|
|
88
|
-
* The cache is scoped to allow easier clearing of different types of usage.
|
|
89
|
-
*/
|
|
90
|
-
[scope: string]: {
|
|
91
|
-
/**
|
|
92
|
-
* Each value in the cache is then identified within a given scope.
|
|
93
|
-
*/
|
|
94
|
-
[id: string]: ValidCacheData,
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Options to pass to error construction.
|
|
99
|
-
*/
|
|
100
|
-
export type ErrorOptions = {|
|
|
101
|
-
/**
|
|
102
|
-
* Metadata to attach to the error.
|
|
103
|
-
*/
|
|
104
|
-
metadata?: Metadata | null | void,
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* The error that caused the error being constructed.
|
|
108
|
-
*/
|
|
109
|
-
cause?: Error | null | void,
|
|
110
|
-
|};
|
|
111
|
-
export interface ScopedCache {
|
|
112
|
-
set(scope: string, id: string, value: ValidCacheData): void;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Retrieve a value from the cache.
|
|
116
|
-
*/
|
|
117
|
-
get(scope: string, id: string): ValidCacheData | null | void;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Purge an item from the cache.
|
|
121
|
-
*/
|
|
122
|
-
purge(scope: string, id: string): void;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Purge a scope of items that match the given predicate.
|
|
126
|
-
*
|
|
127
|
-
* If the predicate is omitted, then all items in the scope are purged.
|
|
128
|
-
*/
|
|
129
|
-
purgeScope(
|
|
130
|
-
scope: string,
|
|
131
|
-
predicate?: (id: string, value: ValidCacheData) => boolean
|
|
132
|
-
): void;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Purge all items from the cache that match the given predicate.
|
|
136
|
-
*
|
|
137
|
-
* If the predicate is omitted, then all items in the cache are purged.
|
|
138
|
-
*/
|
|
139
|
-
purgeAll(
|
|
140
|
-
predicate?: (scope: string, id: string, value: ValidCacheData) => boolean
|
|
141
|
-
): void;
|
|
142
|
-
}
|
|
@@ -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
|
-
};
|