@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,37 @@
|
|
|
1
|
+
import type { Result, ValidCacheData } from "./types";
|
|
2
|
+
type RequestCache = {
|
|
3
|
+
[id: string]: Promise<Result<any>>;
|
|
4
|
+
};
|
|
5
|
+
type FulfillOptions<TData extends ValidCacheData> = {
|
|
6
|
+
handler: () => Promise<TData>;
|
|
7
|
+
hydrate?: boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* This fulfills a request, making sure that in-flight requests are shared.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RequestFulfillment {
|
|
13
|
+
static get Default(): RequestFulfillment;
|
|
14
|
+
_requests: RequestCache;
|
|
15
|
+
/**
|
|
16
|
+
* Get a promise of a request for a given handler and options.
|
|
17
|
+
*
|
|
18
|
+
* This will return an inflight request if one exists, otherwise it will
|
|
19
|
+
* make a new request. Inflight requests are deleted once they resolve.
|
|
20
|
+
*/
|
|
21
|
+
fulfill: <TData extends ValidCacheData>(id: string, options: FulfillOptions<TData>) => Promise<Result<TData>>;
|
|
22
|
+
/**
|
|
23
|
+
* Abort an inflight request.
|
|
24
|
+
*
|
|
25
|
+
* NOTE: Currently, this does not perform an actual abort. It merely
|
|
26
|
+
* removes the request from being tracked.
|
|
27
|
+
*/
|
|
28
|
+
abort: (id: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Abort all inflight requests.
|
|
31
|
+
*
|
|
32
|
+
* NOTE: Currently, this does not perform actual aborts. It merely
|
|
33
|
+
* removes the requests from our tracking.
|
|
34
|
+
*/
|
|
35
|
+
abortAll: () => void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for request-fulfillment
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Result, ValidCacheData } from "./types";
|
|
9
|
+
declare type RequestCache = {
|
|
10
|
+
[id: string]: Promise<Result<any>>,
|
|
11
|
+
};
|
|
12
|
+
declare type FulfillOptions<TData: ValidCacheData> = {
|
|
13
|
+
handler: () => Promise<TData>,
|
|
14
|
+
hydrate?: boolean,
|
|
15
|
+
...
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* This fulfills a request, making sure that in-flight requests are shared.
|
|
19
|
+
*/
|
|
20
|
+
declare export class RequestFulfillment {
|
|
21
|
+
static Default: RequestFulfillment;
|
|
22
|
+
_requests: RequestCache;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get a promise of a request for a given handler and options.
|
|
26
|
+
*
|
|
27
|
+
* This will return an inflight request if one exists, otherwise it will
|
|
28
|
+
* make a new request. Inflight requests are deleted once they resolve.
|
|
29
|
+
*/
|
|
30
|
+
fulfill: <TData: ValidCacheData>(
|
|
31
|
+
id: string,
|
|
32
|
+
options: FulfillOptions<TData>
|
|
33
|
+
) => Promise<Result<TData>>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Abort an inflight request.
|
|
37
|
+
*
|
|
38
|
+
* NOTE: Currently, this does not perform an actual abort. It merely
|
|
39
|
+
* removes the request from being tracked.
|
|
40
|
+
*/
|
|
41
|
+
abort: (id: string) => void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Abort all inflight requests.
|
|
45
|
+
*
|
|
46
|
+
* NOTE: Currently, this does not perform actual aborts. It merely
|
|
47
|
+
* removes the requests from our tracking.
|
|
48
|
+
*/
|
|
49
|
+
abortAll: () => void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { SsrCache } from "./ssr-cache";
|
|
3
|
+
import { RequestFulfillment } from "./request-fulfillment";
|
|
4
|
+
import type { ResponseCache, ValidCacheData } from "./types";
|
|
5
|
+
type TrackerFn = <TData extends ValidCacheData>(id: string, handler: () => Promise<TData>, hydrate: boolean) => void;
|
|
6
|
+
type RequestCache = {
|
|
7
|
+
[id: string]: {
|
|
8
|
+
hydrate: boolean;
|
|
9
|
+
handler: () => Promise<any>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Used to inject our tracking function into the render framework.
|
|
14
|
+
*
|
|
15
|
+
* INTERNAL USE ONLY
|
|
16
|
+
*/
|
|
17
|
+
export declare const TrackerContext: React.Context<TrackerFn | null | undefined>;
|
|
18
|
+
/**
|
|
19
|
+
* Implements request tracking and fulfillment.
|
|
20
|
+
*
|
|
21
|
+
* INTERNAL USE ONLY
|
|
22
|
+
*/
|
|
23
|
+
export declare class RequestTracker {
|
|
24
|
+
static get Default(): RequestTracker;
|
|
25
|
+
/**
|
|
26
|
+
* These are the caches for tracked requests, their handlers, and responses.
|
|
27
|
+
*/
|
|
28
|
+
_trackedRequests: RequestCache;
|
|
29
|
+
_responseCache: SsrCache;
|
|
30
|
+
_requestFulfillment: RequestFulfillment;
|
|
31
|
+
constructor(responseCache?: SsrCache | null);
|
|
32
|
+
/**
|
|
33
|
+
* Track a request.
|
|
34
|
+
*
|
|
35
|
+
* This method caches a request and its handler for use during server-side
|
|
36
|
+
* rendering to allow us to fulfill requests before producing a final render.
|
|
37
|
+
*/
|
|
38
|
+
trackDataRequest: <TData extends ValidCacheData>(id: string, handler: () => Promise<TData>, hydrate: boolean) => void;
|
|
39
|
+
/**
|
|
40
|
+
* Reset our tracking info.
|
|
41
|
+
*/
|
|
42
|
+
reset: () => void;
|
|
43
|
+
/**
|
|
44
|
+
* Indicates if we have requests waiting to be fulfilled.
|
|
45
|
+
*/
|
|
46
|
+
get hasUnfulfilledRequests(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Initiate fulfillment of all tracked requests.
|
|
49
|
+
*
|
|
50
|
+
* This loops over the requests that were tracked using TrackData, and asks
|
|
51
|
+
* the respective handlers to fulfill those requests in the order they were
|
|
52
|
+
* tracked.
|
|
53
|
+
*
|
|
54
|
+
* Calling this method marks tracked requests as fulfilled; requests are
|
|
55
|
+
* removed from the list of tracked requests by calling this method.
|
|
56
|
+
*
|
|
57
|
+
* @returns {Promise<ResponseCache>} The promise of the data that was
|
|
58
|
+
* cached as a result of fulfilling the tracked requests.
|
|
59
|
+
*/
|
|
60
|
+
fulfillTrackedRequests: () => Promise<ResponseCache>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for request-tracking
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import { SsrCache } from "./ssr-cache";
|
|
10
|
+
import { RequestFulfillment } from "./request-fulfillment";
|
|
11
|
+
import type { ResponseCache, ValidCacheData } from "./types";
|
|
12
|
+
declare type TrackerFn = <TData: ValidCacheData>(
|
|
13
|
+
id: string,
|
|
14
|
+
handler: () => Promise<TData>,
|
|
15
|
+
hydrate: boolean
|
|
16
|
+
) => void;
|
|
17
|
+
declare type RequestCache = {
|
|
18
|
+
[id: string]: {
|
|
19
|
+
hydrate: boolean,
|
|
20
|
+
handler: () => Promise<any>,
|
|
21
|
+
...
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Used to inject our tracking function into the render framework.
|
|
26
|
+
*
|
|
27
|
+
* INTERNAL USE ONLY
|
|
28
|
+
*/
|
|
29
|
+
declare export var TrackerContext: React.Context<TrackerFn | null | void>;
|
|
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
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ValidCacheData, CachedResponse, Result } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Turns a cache entry into a stateful result.
|
|
4
|
+
*/
|
|
5
|
+
export declare const resultFromCachedResponse: <TData extends ValidCacheData>(cacheEntry?: CachedResponse<TData> | null | undefined) => Result<TData> | null | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for result-from-cache-response
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ValidCacheData, CachedResponse, Result } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Turns a cache entry into a stateful result.
|
|
12
|
+
*/
|
|
13
|
+
declare export var resultFromCachedResponse: <TData: ValidCacheData>(
|
|
14
|
+
cacheEntry?: CachedResponse<TData> | null | void
|
|
15
|
+
) => Result<TData> | null | void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ScopedCache, RawScopedCache, ValidCacheData } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Describe an in-memory cache.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ScopedInMemoryCache implements ScopedCache {
|
|
6
|
+
_cache: RawScopedCache;
|
|
7
|
+
constructor(initialCache?: RawScopedCache);
|
|
8
|
+
/**
|
|
9
|
+
* Indicate if this cache is being used or not.
|
|
10
|
+
*
|
|
11
|
+
* When the cache has entries, returns `true`; otherwise, returns `false`.
|
|
12
|
+
*/
|
|
13
|
+
get inUse(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Set a value in the cache.
|
|
16
|
+
*/
|
|
17
|
+
set(scope: string, id: string, value: ValidCacheData): void;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieve a value from the cache.
|
|
20
|
+
*/
|
|
21
|
+
get(scope: string, id: string): ValidCacheData | null | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Purge an item from the cache.
|
|
24
|
+
*/
|
|
25
|
+
purge(scope: string, id: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Purge a scope of items that match the given predicate.
|
|
28
|
+
*
|
|
29
|
+
* If the predicate is omitted, then all items in the scope are purged.
|
|
30
|
+
*/
|
|
31
|
+
purgeScope(scope: string, predicate?: (id: string, value: ValidCacheData) => boolean): void;
|
|
32
|
+
/**
|
|
33
|
+
* Purge all items from the cache that match the given predicate.
|
|
34
|
+
*
|
|
35
|
+
* If the predicate is omitted, then all items in the cache are purged.
|
|
36
|
+
*/
|
|
37
|
+
purgeAll(predicate?: (scope: string, id: string, value: ValidCacheData) => boolean): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for scoped-in-memory-cache
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ScopedCache, RawScopedCache, ValidCacheData } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Describe an in-memory cache.
|
|
12
|
+
*/
|
|
13
|
+
declare export class ScopedInMemoryCache extends ScopedCache {
|
|
14
|
+
_cache: RawScopedCache;
|
|
15
|
+
constructor(initialCache?: RawScopedCache): this;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Indicate if this cache is being used or not.
|
|
19
|
+
*
|
|
20
|
+
* When the cache has entries, returns `true`; otherwise, returns `false`.
|
|
21
|
+
*/
|
|
22
|
+
inUse: boolean;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Set a value in the cache.
|
|
26
|
+
*/
|
|
27
|
+
set(scope: string, id: string, value: ValidCacheData): void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve a value from the cache.
|
|
31
|
+
*/
|
|
32
|
+
get(scope: string, id: string): ValidCacheData | null | void;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Purge an item from the cache.
|
|
36
|
+
*/
|
|
37
|
+
purge(scope: string, id: string): void;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Purge a scope of items that match the given predicate.
|
|
41
|
+
*
|
|
42
|
+
* If the predicate is omitted, then all items in the scope are purged.
|
|
43
|
+
*/
|
|
44
|
+
purgeScope(
|
|
45
|
+
scope: string,
|
|
46
|
+
predicate?: (id: string, value: ValidCacheData) => boolean
|
|
47
|
+
): void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Purge all items from the cache that match the given predicate.
|
|
51
|
+
*
|
|
52
|
+
* If the predicate is omitted, then all items in the cache are purged.
|
|
53
|
+
*/
|
|
54
|
+
purgeAll(
|
|
55
|
+
predicate?: (scope: string, id: string, value: ValidCacheData) => boolean
|
|
56
|
+
): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ScopedInMemoryCache } from "./scoped-in-memory-cache";
|
|
2
|
+
import type { ValidCacheData, RawScopedCache } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Describe a serializable in-memory cache.
|
|
5
|
+
*/
|
|
6
|
+
export declare class SerializableInMemoryCache extends ScopedInMemoryCache {
|
|
7
|
+
constructor(initialCache?: RawScopedCache);
|
|
8
|
+
/**
|
|
9
|
+
* Set a value in the cache.
|
|
10
|
+
*/
|
|
11
|
+
set(scope: string, id: string, value: ValidCacheData): void;
|
|
12
|
+
/**
|
|
13
|
+
* Clone the cache.
|
|
14
|
+
*/
|
|
15
|
+
clone(): RawScopedCache;
|
|
16
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for serializable-in-memory-cache
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ScopedInMemoryCache } from "./scoped-in-memory-cache";
|
|
9
|
+
import type { ValidCacheData, RawScopedCache } from "./types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Describe a serializable in-memory cache.
|
|
13
|
+
*/
|
|
14
|
+
declare export class SerializableInMemoryCache extends ScopedInMemoryCache {
|
|
15
|
+
constructor(initialCache?: RawScopedCache): this;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Set a value in the cache.
|
|
19
|
+
*/
|
|
20
|
+
set(scope: string, id: string, value: ValidCacheData): void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Clone the cache.
|
|
24
|
+
*/
|
|
25
|
+
clone(): RawScopedCache;
|
|
26
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SerializableInMemoryCache } from "./serializable-in-memory-cache";
|
|
2
|
+
import type { ValidCacheData, CachedResponse, ResponseCache } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Implements the response cache.
|
|
5
|
+
*
|
|
6
|
+
* INTERNAL USE ONLY
|
|
7
|
+
*/
|
|
8
|
+
export declare class SsrCache {
|
|
9
|
+
static get Default(): SsrCache;
|
|
10
|
+
_hydrationCache: SerializableInMemoryCache;
|
|
11
|
+
_ssrOnlyCache: SerializableInMemoryCache;
|
|
12
|
+
constructor(hydrationCache?: SerializableInMemoryCache | null, ssrOnlyCache?: SerializableInMemoryCache | null);
|
|
13
|
+
_setCachedResponse<TData extends ValidCacheData>(id: string, entry: CachedResponse<TData>, hydrate: boolean): CachedResponse<TData>;
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the cache from a given cache state.
|
|
16
|
+
*
|
|
17
|
+
* This can only be called if the cache is not already in use.
|
|
18
|
+
*/
|
|
19
|
+
initialize: (source: ResponseCache) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Cache data for a specific response.
|
|
22
|
+
*
|
|
23
|
+
* This is a noop when client-side.
|
|
24
|
+
*/
|
|
25
|
+
cacheData: <TData extends ValidCacheData>(id: string, data: TData, hydrate: boolean) => CachedResponse<TData>;
|
|
26
|
+
/**
|
|
27
|
+
* Cache an error for a specific response.
|
|
28
|
+
*
|
|
29
|
+
* This is a noop when client-side.
|
|
30
|
+
*/
|
|
31
|
+
cacheError: <TData extends ValidCacheData>(id: string, error: Error | string, hydrate: boolean) => CachedResponse<TData>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieve data from our cache.
|
|
34
|
+
*/
|
|
35
|
+
getEntry: <TData extends ValidCacheData>(id: string) => Readonly<CachedResponse<TData>> | null | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Remove from cache, any entries matching the given handler and predicate.
|
|
38
|
+
*
|
|
39
|
+
* This will, if present therein, remove matching values from the framework
|
|
40
|
+
* in-memory cache.
|
|
41
|
+
*
|
|
42
|
+
* It returns a count of all records removed.
|
|
43
|
+
*/
|
|
44
|
+
purgeData: (predicate?: (key: string, cachedEntry: Readonly<CachedResponse<ValidCacheData>>) => boolean) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Deep clone the hydration cache.
|
|
47
|
+
*
|
|
48
|
+
* By design, this only clones the data that is to be used for hydration.
|
|
49
|
+
*/
|
|
50
|
+
cloneHydratableData: () => ResponseCache;
|
|
51
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for ssr-cache
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { SerializableInMemoryCache } from "./serializable-in-memory-cache";
|
|
9
|
+
import type { ValidCacheData, CachedResponse, ResponseCache } from "./types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Implements the response cache.
|
|
13
|
+
*
|
|
14
|
+
* INTERNAL USE ONLY
|
|
15
|
+
*/
|
|
16
|
+
declare export class SsrCache {
|
|
17
|
+
static Default: SsrCache;
|
|
18
|
+
_hydrationCache: SerializableInMemoryCache;
|
|
19
|
+
_ssrOnlyCache: SerializableInMemoryCache;
|
|
20
|
+
constructor(
|
|
21
|
+
hydrationCache?: SerializableInMemoryCache | null,
|
|
22
|
+
ssrOnlyCache?: SerializableInMemoryCache | null
|
|
23
|
+
): this;
|
|
24
|
+
_setCachedResponse<TData: ValidCacheData>(
|
|
25
|
+
id: string,
|
|
26
|
+
entry: CachedResponse<TData>,
|
|
27
|
+
hydrate: boolean
|
|
28
|
+
): CachedResponse<TData>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the cache from a given cache state.
|
|
32
|
+
*
|
|
33
|
+
* This can only be called if the cache is not already in use.
|
|
34
|
+
*/
|
|
35
|
+
initialize: (source: ResponseCache) => void;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Cache data for a specific response.
|
|
39
|
+
*
|
|
40
|
+
* This is a noop when client-side.
|
|
41
|
+
*/
|
|
42
|
+
cacheData: <TData: ValidCacheData>(
|
|
43
|
+
id: string,
|
|
44
|
+
data: TData,
|
|
45
|
+
hydrate: boolean
|
|
46
|
+
) => CachedResponse<TData>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Cache an error for a specific response.
|
|
50
|
+
*
|
|
51
|
+
* This is a noop when client-side.
|
|
52
|
+
*/
|
|
53
|
+
cacheError: <TData: ValidCacheData>(
|
|
54
|
+
id: string,
|
|
55
|
+
error: Error | string,
|
|
56
|
+
hydrate: boolean
|
|
57
|
+
) => CachedResponse<TData>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve data from our cache.
|
|
61
|
+
*/
|
|
62
|
+
getEntry: <TData: ValidCacheData>(
|
|
63
|
+
id: string
|
|
64
|
+
) => $ReadOnly<CachedResponse<TData>> | null | void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Remove from cache, any entries matching the given handler and predicate.
|
|
68
|
+
*
|
|
69
|
+
* This will, if present therein, remove matching values from the framework
|
|
70
|
+
* in-memory cache.
|
|
71
|
+
*
|
|
72
|
+
* It returns a count of all records removed.
|
|
73
|
+
*/
|
|
74
|
+
purgeData: (
|
|
75
|
+
predicate?: (
|
|
76
|
+
key: string,
|
|
77
|
+
cachedEntry: $ReadOnly<CachedResponse<ValidCacheData>>
|
|
78
|
+
) => boolean
|
|
79
|
+
) => void;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Deep clone the hydration cache.
|
|
83
|
+
*
|
|
84
|
+
* By design, this only clones the data that is to be used for hydration.
|
|
85
|
+
*/
|
|
86
|
+
cloneHydratableData: () => ResponseCache;
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Result, ValidCacheData } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Create Result<TData> instances with specific statuses.
|
|
4
|
+
*/
|
|
5
|
+
export declare const Status: Readonly<{
|
|
6
|
+
loading: <TData extends ValidCacheData = ValidCacheData>() => Result<TData>;
|
|
7
|
+
aborted: <TData_1 extends ValidCacheData = ValidCacheData>() => Result<TData_1>;
|
|
8
|
+
success: <TData_2 extends ValidCacheData>(data: TData_2) => Result<TData_2>;
|
|
9
|
+
error: <TData_3 extends ValidCacheData = ValidCacheData>(error: Error) => Result<TData_3>;
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for status
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Result, ValidCacheData } from "./types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create Result<TData> instances with specific statuses.
|
|
12
|
+
*/
|
|
13
|
+
declare export var Status: $ReadOnly<{
|
|
14
|
+
loading: <TData: ValidCacheData>() => Result<TData>,
|
|
15
|
+
aborted: <TData_1: ValidCacheData>() => Result<TData_1>,
|
|
16
|
+
success: <TData_2: ValidCacheData>(data: TData_2) => Result<TData_2>,
|
|
17
|
+
error: <TData_3: ValidCacheData>(error: Error) => Result<TData_3>,
|
|
18
|
+
...
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { GqlOperation } from "./gql-types";
|
|
2
|
+
import type { DocumentNode } from "./graphql-types";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a GraphQL DocumentNode to a base Wonder Blocks Data GqlOperation.
|
|
5
|
+
*
|
|
6
|
+
* If you want to include the query/mutation body, extend the result of this
|
|
7
|
+
* method and use the `graphql/language/printer` like:
|
|
8
|
+
*
|
|
9
|
+
* ```js
|
|
10
|
+
* import {print} from "graphql/language/printer";
|
|
11
|
+
*
|
|
12
|
+
* const gqlOpWithBody = {
|
|
13
|
+
* ...toGqlOperation(documentNode),
|
|
14
|
+
* query: print(documentNode),
|
|
15
|
+
* };
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* If you want to enforce inclusion of __typename properties, then you can use
|
|
19
|
+
* `apollo-utilities` first to modify the document:
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* import {print} from "graphql/language/printer";
|
|
23
|
+
* import {addTypenameToDocument} from "apollo-utilities";
|
|
24
|
+
*
|
|
25
|
+
* const documentWithTypenames = addTypenameToDocument(documentNode);
|
|
26
|
+
* const gqlOpWithBody = {
|
|
27
|
+
* ...toGqlOperation(documentWithTypenames),
|
|
28
|
+
* query: print(documentWithTypenames),
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const toGqlOperation: <TData, TVariables extends Record<any, any>>(documentNode: DocumentNode) => GqlOperation<TData, TVariables>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for to-gql-operation
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { GqlOperation } from "./gql-types";
|
|
9
|
+
import type { DocumentNode } from "./graphql-types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Convert a GraphQL DocumentNode to a base Wonder Blocks Data GqlOperation.
|
|
13
|
+
*
|
|
14
|
+
* If you want to include the query/mutation body, extend the result of this
|
|
15
|
+
* method and use the `graphql/language/printer` like:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import {print} from "graphql/language/printer";
|
|
19
|
+
*
|
|
20
|
+
* const gqlOpWithBody = {
|
|
21
|
+
* ...toGqlOperation(documentNode),
|
|
22
|
+
* query: print(documentNode),
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* If you want to enforce inclusion of __typename properties, then you can use
|
|
27
|
+
* `apollo-utilities` first to modify the document:
|
|
28
|
+
*
|
|
29
|
+
* ```js
|
|
30
|
+
* import {print} from "graphql/language/printer";
|
|
31
|
+
* import {addTypenameToDocument} from "apollo-utilities";
|
|
32
|
+
*
|
|
33
|
+
* const documentWithTypenames = addTypenameToDocument(documentNode);
|
|
34
|
+
* const gqlOpWithBody = {
|
|
35
|
+
* ...toGqlOperation(documentWithTypenames),
|
|
36
|
+
* query: print(documentWithTypenames),
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare export var toGqlOperation: <
|
|
41
|
+
TData,
|
|
42
|
+
TVariables: { [key: any]: any, ... }
|
|
43
|
+
>(
|
|
44
|
+
documentNode: DocumentNode
|
|
45
|
+
) => GqlOperation<TData, TVariables>;
|