@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
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Server, useForceUpdate } from '@khanacademy/wonder-blocks-core';
|
|
2
2
|
import { KindError, clone, entries } from '@khanacademy/wonder-stuff-core';
|
|
3
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
4
3
|
import * as React from 'react';
|
|
5
4
|
import { useContext, useRef, useMemo, useCallback } from 'react';
|
|
6
5
|
|
|
@@ -11,6 +10,64 @@ const FetchPolicy = {
|
|
|
11
10
|
NetworkOnly: "NetworkOnly"
|
|
12
11
|
};
|
|
13
12
|
|
|
13
|
+
function _typeof(obj) {
|
|
14
|
+
"@babel/helpers - typeof";
|
|
15
|
+
|
|
16
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
17
|
+
return typeof obj;
|
|
18
|
+
} : function (obj) {
|
|
19
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
20
|
+
}, _typeof(obj);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function _toPrimitive(input, hint) {
|
|
24
|
+
if (_typeof(input) !== "object" || input === null) return input;
|
|
25
|
+
var prim = input[Symbol.toPrimitive];
|
|
26
|
+
if (prim !== undefined) {
|
|
27
|
+
var res = prim.call(input, hint || "default");
|
|
28
|
+
if (_typeof(res) !== "object") return res;
|
|
29
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
30
|
+
}
|
|
31
|
+
return (hint === "string" ? String : Number)(input);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _toPropertyKey(arg) {
|
|
35
|
+
var key = _toPrimitive(arg, "string");
|
|
36
|
+
return _typeof(key) === "symbol" ? key : String(key);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _defineProperties(target, props) {
|
|
40
|
+
for (var i = 0; i < props.length; i++) {
|
|
41
|
+
var descriptor = props[i];
|
|
42
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
43
|
+
descriptor.configurable = true;
|
|
44
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
45
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
49
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
50
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
51
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
52
|
+
writable: false
|
|
53
|
+
});
|
|
54
|
+
return Constructor;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function _setPrototypeOf(o, p) {
|
|
58
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
59
|
+
o.__proto__ = p;
|
|
60
|
+
return o;
|
|
61
|
+
};
|
|
62
|
+
return _setPrototypeOf(o, p);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function _inheritsLoose(subClass, superClass) {
|
|
66
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
67
|
+
subClass.prototype.constructor = subClass;
|
|
68
|
+
_setPrototypeOf(subClass, superClass);
|
|
69
|
+
}
|
|
70
|
+
|
|
14
71
|
const DataErrors = Object.freeze({
|
|
15
72
|
Unknown: "Unknown",
|
|
16
73
|
Internal: "Internal",
|
|
@@ -20,116 +77,106 @@ const DataErrors = Object.freeze({
|
|
|
20
77
|
Parse: "Parse",
|
|
21
78
|
Hydrated: "Hydrated"
|
|
22
79
|
});
|
|
23
|
-
|
|
24
|
-
|
|
80
|
+
let DataError = function (_KindError) {
|
|
81
|
+
_inheritsLoose(DataError, _KindError);
|
|
82
|
+
function DataError(message, kind, {
|
|
25
83
|
metadata,
|
|
26
84
|
cause
|
|
27
85
|
} = {}) {
|
|
28
|
-
|
|
86
|
+
return _KindError.call(this, message, kind, {
|
|
29
87
|
metadata,
|
|
30
88
|
cause,
|
|
31
89
|
name: "Data"
|
|
32
|
-
});
|
|
90
|
+
}) || this;
|
|
33
91
|
}
|
|
92
|
+
return DataError;
|
|
93
|
+
}(KindError);
|
|
34
94
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
constructor(initialCache = {}) {
|
|
95
|
+
let ScopedInMemoryCache = function () {
|
|
96
|
+
function ScopedInMemoryCache(initialCache = {}) {
|
|
97
|
+
this._cache = void 0;
|
|
39
98
|
this._cache = initialCache;
|
|
40
99
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return Object.keys(this._cache).length > 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
set(scope, id, value) {
|
|
100
|
+
var _proto = ScopedInMemoryCache.prototype;
|
|
101
|
+
_proto.set = function set(scope, id, value) {
|
|
47
102
|
var _this$_cache$scope;
|
|
48
|
-
|
|
49
103
|
if (!id || typeof id !== "string") {
|
|
50
104
|
throw new DataError("id must be non-empty string", DataErrors.InvalidInput);
|
|
51
105
|
}
|
|
52
|
-
|
|
53
106
|
if (!scope || typeof scope !== "string") {
|
|
54
107
|
throw new DataError("scope must be non-empty string", DataErrors.InvalidInput);
|
|
55
108
|
}
|
|
56
|
-
|
|
57
109
|
if (typeof value === "function") {
|
|
58
110
|
throw new DataError("value must be a non-function value", DataErrors.InvalidInput);
|
|
59
111
|
}
|
|
60
|
-
|
|
61
112
|
this._cache[scope] = (_this$_cache$scope = this._cache[scope]) != null ? _this$_cache$scope : {};
|
|
62
113
|
this._cache[scope][id] = value;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
get(scope, id) {
|
|
114
|
+
};
|
|
115
|
+
_proto.get = function get(scope, id) {
|
|
66
116
|
var _this$_cache$scope$id, _this$_cache$scope2;
|
|
67
|
-
|
|
68
117
|
return (_this$_cache$scope$id = (_this$_cache$scope2 = this._cache[scope]) == null ? void 0 : _this$_cache$scope2[id]) != null ? _this$_cache$scope$id : null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
purge(scope, id) {
|
|
118
|
+
};
|
|
119
|
+
_proto.purge = function purge(scope, id) {
|
|
72
120
|
var _this$_cache$scope3;
|
|
73
|
-
|
|
74
121
|
if (!((_this$_cache$scope3 = this._cache[scope]) != null && _this$_cache$scope3[id])) {
|
|
75
122
|
return;
|
|
76
123
|
}
|
|
77
|
-
|
|
78
124
|
delete this._cache[scope][id];
|
|
79
|
-
|
|
80
125
|
if (Object.keys(this._cache[scope]).length === 0) {
|
|
81
126
|
delete this._cache[scope];
|
|
82
127
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
purgeScope(scope, predicate) {
|
|
128
|
+
};
|
|
129
|
+
_proto.purgeScope = function purgeScope(scope, predicate) {
|
|
86
130
|
if (!this._cache[scope]) {
|
|
87
131
|
return;
|
|
88
132
|
}
|
|
89
|
-
|
|
90
133
|
if (predicate == null) {
|
|
91
134
|
delete this._cache[scope];
|
|
92
135
|
return;
|
|
93
136
|
}
|
|
94
|
-
|
|
95
137
|
for (const key of Object.keys(this._cache[scope])) {
|
|
96
138
|
if (predicate(key, this._cache[scope][key])) {
|
|
97
139
|
delete this._cache[scope][key];
|
|
98
140
|
}
|
|
99
141
|
}
|
|
100
|
-
|
|
101
142
|
if (Object.keys(this._cache[scope]).length === 0) {
|
|
102
143
|
delete this._cache[scope];
|
|
103
144
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
purgeAll(predicate) {
|
|
145
|
+
};
|
|
146
|
+
_proto.purgeAll = function purgeAll(predicate) {
|
|
107
147
|
if (predicate == null) {
|
|
108
148
|
this._cache = {};
|
|
109
149
|
return;
|
|
110
150
|
}
|
|
111
|
-
|
|
112
151
|
for (const scope of Object.keys(this._cache)) {
|
|
113
152
|
this.purgeScope(scope, (id, value) => predicate(scope, id, value));
|
|
114
153
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
154
|
+
};
|
|
155
|
+
_createClass(ScopedInMemoryCache, [{
|
|
156
|
+
key: "inUse",
|
|
157
|
+
get: function () {
|
|
158
|
+
return Object.keys(this._cache).length > 0;
|
|
159
|
+
}
|
|
160
|
+
}]);
|
|
161
|
+
return ScopedInMemoryCache;
|
|
162
|
+
}();
|
|
163
|
+
|
|
164
|
+
let SerializableInMemoryCache = function (_ScopedInMemoryCache) {
|
|
165
|
+
_inheritsLoose(SerializableInMemoryCache, _ScopedInMemoryCache);
|
|
166
|
+
function SerializableInMemoryCache(initialCache = {}) {
|
|
167
|
+
var _this;
|
|
121
168
|
try {
|
|
122
|
-
|
|
169
|
+
_this = _ScopedInMemoryCache.call(this, clone(initialCache)) || this;
|
|
123
170
|
} catch (e) {
|
|
124
171
|
throw new DataError(`An error occurred trying to initialize from a response cache snapshot: ${e}`, DataErrors.InvalidInput);
|
|
125
172
|
}
|
|
173
|
+
return _this;
|
|
126
174
|
}
|
|
127
|
-
|
|
128
|
-
set(scope, id, value) {
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
clone() {
|
|
175
|
+
var _proto = SerializableInMemoryCache.prototype;
|
|
176
|
+
_proto.set = function set(scope, id, value) {
|
|
177
|
+
_ScopedInMemoryCache.prototype.set.call(this, scope, id, Object.freeze(clone(value)));
|
|
178
|
+
};
|
|
179
|
+
_proto.clone = function clone$1() {
|
|
133
180
|
try {
|
|
134
181
|
return clone(this._cache);
|
|
135
182
|
} catch (e) {
|
|
@@ -137,79 +184,57 @@ class SerializableInMemoryCache extends ScopedInMemoryCache {
|
|
|
137
184
|
cause: e
|
|
138
185
|
});
|
|
139
186
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
}
|
|
187
|
+
};
|
|
188
|
+
return SerializableInMemoryCache;
|
|
189
|
+
}(ScopedInMemoryCache);
|
|
143
190
|
|
|
144
191
|
const DefaultScope$2 = "default";
|
|
145
|
-
|
|
146
192
|
let _default$2;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
_default$2 = new SsrCache();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return _default$2;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
constructor(hydrationCache = null, ssrOnlyCache = null) {
|
|
193
|
+
let SsrCache = function () {
|
|
194
|
+
function SsrCache(hydrationCache = null, ssrOnlyCache = null) {
|
|
195
|
+
this._hydrationCache = void 0;
|
|
196
|
+
this._ssrOnlyCache = void 0;
|
|
158
197
|
this.initialize = source => {
|
|
159
198
|
if (this._hydrationCache.inUse) {
|
|
160
199
|
throw new Error("Cannot initialize data response cache more than once");
|
|
161
200
|
}
|
|
162
|
-
|
|
163
201
|
this._hydrationCache = new SerializableInMemoryCache({
|
|
164
202
|
[DefaultScope$2]: source
|
|
165
203
|
});
|
|
166
204
|
};
|
|
167
|
-
|
|
168
205
|
this.cacheData = (id, data, hydrate) => this._setCachedResponse(id, {
|
|
169
206
|
data
|
|
170
207
|
}, hydrate);
|
|
171
|
-
|
|
172
208
|
this.cacheError = (id, error, hydrate) => {
|
|
173
209
|
const errorMessage = typeof error === "string" ? error : error.message;
|
|
174
210
|
return this._setCachedResponse(id, {
|
|
175
211
|
error: errorMessage
|
|
176
212
|
}, hydrate);
|
|
177
213
|
};
|
|
178
|
-
|
|
179
214
|
this.getEntry = id => {
|
|
180
215
|
const ssrEntry = Server.isServerSide() ? this._ssrOnlyCache.get(DefaultScope$2, id) : null;
|
|
181
216
|
const internalEntry = ssrEntry != null ? ssrEntry : this._hydrationCache.get(DefaultScope$2, id);
|
|
182
|
-
|
|
183
217
|
if (!Server.isServerSide() && internalEntry != null) {
|
|
184
218
|
this._hydrationCache.purge(DefaultScope$2, id);
|
|
185
219
|
}
|
|
186
|
-
|
|
187
220
|
return internalEntry;
|
|
188
221
|
};
|
|
189
|
-
|
|
190
222
|
this.purgeData = predicate => {
|
|
191
223
|
const realPredicate = predicate ? (_, key, cachedEntry) => predicate(key, cachedEntry) : undefined;
|
|
192
|
-
|
|
193
224
|
this._hydrationCache.purgeAll(realPredicate);
|
|
194
|
-
|
|
195
225
|
this._ssrOnlyCache.purgeAll(realPredicate);
|
|
196
226
|
};
|
|
197
|
-
|
|
198
227
|
this.cloneHydratableData = () => {
|
|
199
228
|
var _cache$DefaultScope;
|
|
200
|
-
|
|
201
229
|
const cache = this._hydrationCache.clone();
|
|
202
|
-
|
|
203
230
|
return (_cache$DefaultScope = cache[DefaultScope$2]) != null ? _cache$DefaultScope : {};
|
|
204
231
|
};
|
|
205
|
-
|
|
206
232
|
this._ssrOnlyCache = ssrOnlyCache || new SerializableInMemoryCache();
|
|
207
233
|
this._hydrationCache = hydrationCache || new SerializableInMemoryCache();
|
|
208
234
|
}
|
|
209
|
-
|
|
210
|
-
_setCachedResponse(id, entry, hydrate) {
|
|
235
|
+
var _proto = SsrCache.prototype;
|
|
236
|
+
_proto._setCachedResponse = function _setCachedResponse(id, entry, hydrate) {
|
|
211
237
|
const frozenEntry = Object.freeze(entry);
|
|
212
|
-
|
|
213
238
|
if (Server.isServerSide()) {
|
|
214
239
|
if (hydrate) {
|
|
215
240
|
this._hydrationCache.set(DefaultScope$2, id, frozenEntry);
|
|
@@ -217,31 +242,50 @@ class SsrCache {
|
|
|
217
242
|
this._ssrOnlyCache.set(DefaultScope$2, id, frozenEntry);
|
|
218
243
|
}
|
|
219
244
|
}
|
|
220
|
-
|
|
221
245
|
return frozenEntry;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
246
|
+
};
|
|
247
|
+
_createClass(SsrCache, null, [{
|
|
248
|
+
key: "Default",
|
|
249
|
+
get: function () {
|
|
250
|
+
if (!_default$2) {
|
|
251
|
+
_default$2 = new SsrCache();
|
|
252
|
+
}
|
|
253
|
+
return _default$2;
|
|
254
|
+
}
|
|
255
|
+
}]);
|
|
256
|
+
return SsrCache;
|
|
257
|
+
}();
|
|
225
258
|
|
|
226
259
|
const initializeHydrationCache = source => SsrCache.Default.initialize(source);
|
|
227
260
|
const purgeHydrationCache = predicate => SsrCache.Default.purgeData(predicate);
|
|
228
261
|
|
|
229
|
-
|
|
262
|
+
function _extends() {
|
|
263
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
264
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
265
|
+
var source = arguments[i];
|
|
266
|
+
for (var key in source) {
|
|
267
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
268
|
+
target[key] = source[key];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return target;
|
|
273
|
+
};
|
|
274
|
+
return _extends.apply(this, arguments);
|
|
275
|
+
}
|
|
230
276
|
|
|
231
|
-
|
|
232
|
-
|
|
277
|
+
let _default$1;
|
|
278
|
+
let RequestFulfillment = function () {
|
|
279
|
+
function RequestFulfillment() {
|
|
233
280
|
this._requests = {};
|
|
234
|
-
|
|
235
281
|
this.fulfill = (id, {
|
|
236
282
|
handler,
|
|
237
283
|
hydrate: _hydrate = true
|
|
238
284
|
}) => {
|
|
239
285
|
const inflight = this._requests[id];
|
|
240
|
-
|
|
241
286
|
if (inflight) {
|
|
242
287
|
return inflight;
|
|
243
288
|
}
|
|
244
|
-
|
|
245
289
|
const request = handler().then(data => ({
|
|
246
290
|
status: "success",
|
|
247
291
|
data
|
|
@@ -251,13 +295,11 @@ class RequestFulfillment {
|
|
|
251
295
|
unexpectedError: error
|
|
252
296
|
}
|
|
253
297
|
}) : error;
|
|
254
|
-
|
|
255
298
|
if (actualError.name === "AbortError") {
|
|
256
299
|
return {
|
|
257
300
|
status: "aborted"
|
|
258
301
|
};
|
|
259
302
|
}
|
|
260
|
-
|
|
261
303
|
return {
|
|
262
304
|
status: "error",
|
|
263
305
|
error: actualError
|
|
@@ -268,42 +310,32 @@ class RequestFulfillment {
|
|
|
268
310
|
this._requests[id] = request;
|
|
269
311
|
return request;
|
|
270
312
|
};
|
|
271
|
-
|
|
272
313
|
this.abort = id => {
|
|
273
314
|
delete this._requests[id];
|
|
274
315
|
};
|
|
275
|
-
|
|
276
316
|
this.abortAll = () => {
|
|
277
317
|
Object.keys(this._requests).forEach(id => this.abort(id));
|
|
278
318
|
};
|
|
279
319
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
_default$1
|
|
320
|
+
_createClass(RequestFulfillment, null, [{
|
|
321
|
+
key: "Default",
|
|
322
|
+
get: function () {
|
|
323
|
+
if (!_default$1) {
|
|
324
|
+
_default$1 = new RequestFulfillment();
|
|
325
|
+
}
|
|
326
|
+
return _default$1;
|
|
284
327
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
328
|
+
}]);
|
|
329
|
+
return RequestFulfillment;
|
|
330
|
+
}();
|
|
290
331
|
|
|
291
332
|
const TrackerContext = React.createContext(null);
|
|
292
|
-
|
|
293
333
|
let _default;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
static get Default() {
|
|
297
|
-
if (!_default) {
|
|
298
|
-
_default = new RequestTracker();
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
return _default;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
constructor(responseCache = undefined) {
|
|
334
|
+
let RequestTracker = function () {
|
|
335
|
+
function RequestTracker(responseCache = undefined) {
|
|
305
336
|
this._trackedRequests = {};
|
|
306
|
-
|
|
337
|
+
this._responseCache = void 0;
|
|
338
|
+
this._requestFulfillment = void 0;
|
|
307
339
|
this.trackDataRequest = (id, handler, hydrate) => {
|
|
308
340
|
if (this._trackedRequests[id] == null) {
|
|
309
341
|
this._trackedRequests[id] = {
|
|
@@ -312,82 +344,78 @@ class RequestTracker {
|
|
|
312
344
|
};
|
|
313
345
|
}
|
|
314
346
|
};
|
|
315
|
-
|
|
316
347
|
this.reset = () => {
|
|
317
348
|
this._trackedRequests = {};
|
|
318
349
|
};
|
|
319
|
-
|
|
320
350
|
this.fulfillTrackedRequests = () => {
|
|
321
351
|
const promises = [];
|
|
322
352
|
const {
|
|
323
353
|
cacheData,
|
|
324
354
|
cacheError
|
|
325
355
|
} = this._responseCache;
|
|
326
|
-
|
|
327
356
|
for (const requestKey of Object.keys(this._trackedRequests)) {
|
|
328
357
|
const options = this._trackedRequests[requestKey];
|
|
329
|
-
|
|
330
358
|
try {
|
|
331
359
|
promises.push(this._requestFulfillment.fulfill(requestKey, _extends({}, options)).then(result => {
|
|
332
360
|
switch (result.status) {
|
|
333
361
|
case "success":
|
|
334
362
|
cacheData(requestKey, result.data, options.hydrate);
|
|
335
363
|
break;
|
|
336
|
-
|
|
337
364
|
case "error":
|
|
338
365
|
cacheError(requestKey, result.error, options.hydrate);
|
|
339
366
|
break;
|
|
340
367
|
}
|
|
341
|
-
|
|
342
368
|
return;
|
|
343
369
|
}));
|
|
344
370
|
} catch (e) {
|
|
345
371
|
promises.push(Promise.resolve(cacheError(requestKey, e, options.hydrate)));
|
|
346
372
|
}
|
|
347
373
|
}
|
|
348
|
-
|
|
349
374
|
this.reset();
|
|
350
375
|
return Promise.all(promises).then(() => this._responseCache.cloneHydratableData());
|
|
351
376
|
};
|
|
352
|
-
|
|
353
377
|
this._responseCache = responseCache || SsrCache.Default;
|
|
354
378
|
this._requestFulfillment = new RequestFulfillment();
|
|
355
379
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
380
|
+
_createClass(RequestTracker, [{
|
|
381
|
+
key: "hasUnfulfilledRequests",
|
|
382
|
+
get: function () {
|
|
383
|
+
return Object.keys(this._trackedRequests).length > 0;
|
|
384
|
+
}
|
|
385
|
+
}], [{
|
|
386
|
+
key: "Default",
|
|
387
|
+
get: function () {
|
|
388
|
+
if (!_default) {
|
|
389
|
+
_default = new RequestTracker();
|
|
390
|
+
}
|
|
391
|
+
return _default;
|
|
392
|
+
}
|
|
393
|
+
}]);
|
|
394
|
+
return RequestTracker;
|
|
395
|
+
}();
|
|
362
396
|
|
|
363
397
|
const SSRCheck = () => {
|
|
364
398
|
if (Server.isServerSide()) {
|
|
365
399
|
return null;
|
|
366
400
|
}
|
|
367
|
-
|
|
368
401
|
if (process.env.NODE_ENV === "production") {
|
|
369
402
|
return new DataError("No CSR tracking", DataErrors.NotAllowed);
|
|
370
403
|
} else {
|
|
371
404
|
return new DataError("Data requests are not tracked for fulfillment when when client-side", DataErrors.NotAllowed);
|
|
372
405
|
}
|
|
373
406
|
};
|
|
374
|
-
|
|
375
407
|
const fetchTrackedRequests = () => {
|
|
376
408
|
const ssrCheck = SSRCheck();
|
|
377
|
-
|
|
378
409
|
if (ssrCheck != null) {
|
|
379
410
|
return Promise.reject(ssrCheck);
|
|
380
411
|
}
|
|
381
|
-
|
|
382
412
|
return RequestTracker.Default.fulfillTrackedRequests();
|
|
383
413
|
};
|
|
384
414
|
const hasTrackedRequestsToBeFetched = () => {
|
|
385
415
|
const ssrCheck = SSRCheck();
|
|
386
|
-
|
|
387
416
|
if (ssrCheck != null) {
|
|
388
417
|
throw ssrCheck;
|
|
389
418
|
}
|
|
390
|
-
|
|
391
419
|
return RequestTracker.Default.hasUnfulfilledRequests;
|
|
392
420
|
};
|
|
393
421
|
const abortInflightRequests = () => {
|
|
@@ -400,23 +428,18 @@ const useSharedCache = (id, scope, initialValue) => {
|
|
|
400
428
|
if (!id || typeof id !== "string") {
|
|
401
429
|
throw new DataError("id must be a non-empty string", DataErrors.InvalidInput);
|
|
402
430
|
}
|
|
403
|
-
|
|
404
431
|
if (!scope || typeof scope !== "string") {
|
|
405
432
|
throw new DataError("scope must be a non-empty string", DataErrors.InvalidInput);
|
|
406
433
|
}
|
|
407
|
-
|
|
408
434
|
const cacheValue = React.useCallback(value => value == null ? cache$1.purge(scope, id) : cache$1.set(scope, id, value), [id, scope]);
|
|
409
435
|
let currentValue = cache$1.get(scope, id);
|
|
410
|
-
|
|
411
436
|
if (currentValue == null && initialValue !== undefined) {
|
|
412
437
|
const value = typeof initialValue === "function" ? initialValue() : initialValue;
|
|
413
|
-
|
|
414
438
|
if (value != null) {
|
|
415
439
|
cacheValue(value);
|
|
416
440
|
currentValue = value;
|
|
417
441
|
}
|
|
418
442
|
}
|
|
419
|
-
|
|
420
443
|
return [currentValue, cacheValue];
|
|
421
444
|
};
|
|
422
445
|
|
|
@@ -425,18 +448,22 @@ const purgeCaches = () => {
|
|
|
425
448
|
purgeHydrationCache();
|
|
426
449
|
};
|
|
427
450
|
|
|
428
|
-
|
|
429
|
-
|
|
451
|
+
let TrackData = function (_React$Component) {
|
|
452
|
+
_inheritsLoose(TrackData, _React$Component);
|
|
453
|
+
function TrackData() {
|
|
454
|
+
return _React$Component.apply(this, arguments) || this;
|
|
455
|
+
}
|
|
456
|
+
var _proto = TrackData.prototype;
|
|
457
|
+
_proto.render = function render() {
|
|
430
458
|
if (!Server.isServerSide()) {
|
|
431
459
|
throw new Error("This component is not for use during client-side rendering");
|
|
432
460
|
}
|
|
433
|
-
|
|
434
461
|
return React.createElement(TrackerContext.Provider, {
|
|
435
462
|
value: RequestTracker.Default.trackDataRequest
|
|
436
463
|
}, this.props.children);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
}
|
|
464
|
+
};
|
|
465
|
+
return TrackData;
|
|
466
|
+
}(React.Component);
|
|
440
467
|
|
|
441
468
|
const loadingStatus = Object.freeze({
|
|
442
469
|
status: "loading"
|
|
@@ -461,20 +488,16 @@ const resultFromCachedResponse = cacheEntry => {
|
|
|
461
488
|
if (cacheEntry == null) {
|
|
462
489
|
return null;
|
|
463
490
|
}
|
|
464
|
-
|
|
465
491
|
const {
|
|
466
492
|
data,
|
|
467
493
|
error
|
|
468
494
|
} = cacheEntry;
|
|
469
|
-
|
|
470
495
|
if (error != null) {
|
|
471
496
|
return Status.error(new DataError(error, DataErrors.Hydrated));
|
|
472
497
|
}
|
|
473
|
-
|
|
474
498
|
if (data != null) {
|
|
475
499
|
return Status.success(data);
|
|
476
500
|
}
|
|
477
|
-
|
|
478
501
|
return Status.aborted();
|
|
479
502
|
};
|
|
480
503
|
|
|
@@ -487,7 +510,6 @@ const useRequestInterception = (requestId, handler) => {
|
|
|
487
510
|
if (prev != null) {
|
|
488
511
|
return prev;
|
|
489
512
|
}
|
|
490
|
-
|
|
491
513
|
return interceptor(requestId);
|
|
492
514
|
}, null);
|
|
493
515
|
return interceptResponse != null ? interceptResponse : handler();
|
|
@@ -503,18 +525,15 @@ const useServerEffect = (requestId, handler, options = {}) => {
|
|
|
503
525
|
const interceptedHandler = useRequestInterception(requestId, handler);
|
|
504
526
|
const cachedResult = SsrCache.Default.getEntry(requestId);
|
|
505
527
|
const maybeTrack = useContext(TrackerContext);
|
|
506
|
-
|
|
507
528
|
if (!skip && cachedResult == null && Server.isServerSide()) {
|
|
508
529
|
maybeTrack == null ? void 0 : maybeTrack(requestId, interceptedHandler, hydrate);
|
|
509
530
|
}
|
|
510
|
-
|
|
511
531
|
return cachedResult == null ? null : resultFromCachedResponse(cachedResult);
|
|
512
532
|
};
|
|
513
533
|
|
|
514
534
|
const DefaultScope$1 = "useCachedEffect";
|
|
515
535
|
const useCachedEffect = (requestId, handler, options = {}) => {
|
|
516
536
|
var _ref;
|
|
517
|
-
|
|
518
537
|
const {
|
|
519
538
|
fetchPolicy = FetchPolicy.CacheBeforeNetwork,
|
|
520
539
|
skip: hardSkip = false,
|
|
@@ -529,73 +548,57 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
529
548
|
const currentRequestRef = React.useRef();
|
|
530
549
|
const fetchRequest = React.useMemo(() => {
|
|
531
550
|
var _currentRequestRef$cu;
|
|
532
|
-
|
|
533
551
|
(_currentRequestRef$cu = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu.cancel();
|
|
534
552
|
currentRequestRef.current = null;
|
|
535
553
|
networkResultRef.current = null;
|
|
536
|
-
|
|
537
554
|
const fetchFn = () => {
|
|
538
555
|
var _currentRequestRef$cu2, _currentRequestRef$cu3;
|
|
539
|
-
|
|
540
556
|
if (fetchPolicy === FetchPolicy.CacheOnly) {
|
|
541
557
|
throw new DataError("Cannot fetch with CacheOnly policy", DataErrors.NotAllowed);
|
|
542
558
|
}
|
|
543
|
-
|
|
544
559
|
const request = RequestFulfillment.Default.fulfill(`${requestId}|${scope}`, {
|
|
545
560
|
handler: interceptedHandler
|
|
546
561
|
});
|
|
547
|
-
|
|
548
562
|
if (request === ((_currentRequestRef$cu2 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu2.request)) {
|
|
549
563
|
return;
|
|
550
564
|
}
|
|
551
|
-
|
|
552
565
|
networkResultRef.current = null;
|
|
553
566
|
(_currentRequestRef$cu3 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu3.cancel();
|
|
554
567
|
let cancel = false;
|
|
555
568
|
request.then(result => {
|
|
556
569
|
currentRequestRef.current = null;
|
|
557
|
-
|
|
558
570
|
if (cancel) {
|
|
559
571
|
return;
|
|
560
572
|
}
|
|
561
|
-
|
|
562
573
|
setMostRecentResult(result);
|
|
563
574
|
networkResultRef.current = result;
|
|
564
|
-
|
|
565
575
|
if (onResultChanged != null) {
|
|
566
576
|
onResultChanged(result);
|
|
567
577
|
} else {
|
|
568
578
|
forceUpdate();
|
|
569
579
|
}
|
|
570
|
-
|
|
571
580
|
return;
|
|
572
581
|
});
|
|
573
582
|
currentRequestRef.current = {
|
|
574
583
|
requestId,
|
|
575
584
|
request,
|
|
576
|
-
|
|
577
585
|
cancel() {
|
|
578
586
|
cancel = true;
|
|
579
587
|
RequestFulfillment.Default.abort(requestId);
|
|
580
588
|
}
|
|
581
|
-
|
|
582
589
|
};
|
|
583
590
|
};
|
|
584
|
-
|
|
585
591
|
return fetchFn;
|
|
586
592
|
}, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]);
|
|
587
593
|
const shouldFetch = React.useMemo(() => {
|
|
588
594
|
if (hardSkip) {
|
|
589
595
|
return false;
|
|
590
596
|
}
|
|
591
|
-
|
|
592
597
|
switch (fetchPolicy) {
|
|
593
598
|
case FetchPolicy.CacheOnly:
|
|
594
599
|
return false;
|
|
595
|
-
|
|
596
600
|
case FetchPolicy.CacheBeforeNetwork:
|
|
597
601
|
return mostRecentResult == null;
|
|
598
|
-
|
|
599
602
|
case FetchPolicy.CacheAndNetwork:
|
|
600
603
|
case FetchPolicy.NetworkOnly:
|
|
601
604
|
return networkResultRef.current == null;
|
|
@@ -605,11 +608,9 @@ const useCachedEffect = (requestId, handler, options = {}) => {
|
|
|
605
608
|
if (!shouldFetch) {
|
|
606
609
|
return;
|
|
607
610
|
}
|
|
608
|
-
|
|
609
611
|
fetchRequest();
|
|
610
612
|
return () => {
|
|
611
613
|
var _currentRequestRef$cu4;
|
|
612
|
-
|
|
613
614
|
(_currentRequestRef$cu4 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu4.cancel();
|
|
614
615
|
currentRequestRef.current = null;
|
|
615
616
|
};
|
|
@@ -645,15 +646,12 @@ const useHydratableEffect = (requestId, handler, options = {}) => {
|
|
|
645
646
|
case WhenClientSide.DoNotHydrate:
|
|
646
647
|
case WhenClientSide.AlwaysExecute:
|
|
647
648
|
return null;
|
|
648
|
-
|
|
649
649
|
case WhenClientSide.ExecuteWhenNoResult:
|
|
650
650
|
return serverResult;
|
|
651
|
-
|
|
652
651
|
case WhenClientSide.ExecuteWhenNoSuccessResult:
|
|
653
652
|
if ((serverResult == null ? void 0 : serverResult.status) === "success") {
|
|
654
653
|
return serverResult;
|
|
655
654
|
}
|
|
656
|
-
|
|
657
655
|
return null;
|
|
658
656
|
}
|
|
659
657
|
}, [serverResult]);
|
|
@@ -695,11 +693,9 @@ const InterceptRequests = ({
|
|
|
695
693
|
|
|
696
694
|
const toString = value => {
|
|
697
695
|
var _JSON$stringify;
|
|
698
|
-
|
|
699
696
|
if (typeof value === "string") {
|
|
700
697
|
return value;
|
|
701
698
|
}
|
|
702
|
-
|
|
703
699
|
if (typeof value === "object" && value != null) {
|
|
704
700
|
if (value instanceof Date) {
|
|
705
701
|
return value.toISOString();
|
|
@@ -707,14 +703,11 @@ const toString = value => {
|
|
|
707
703
|
return value.toString();
|
|
708
704
|
}
|
|
709
705
|
}
|
|
710
|
-
|
|
711
706
|
return (_JSON$stringify = JSON.stringify(value)) != null ? _JSON$stringify : "";
|
|
712
707
|
};
|
|
713
|
-
|
|
714
708
|
const toStringifiedVariables = (acc, key, value) => {
|
|
715
709
|
if (typeof value === "object" && value !== null) {
|
|
716
710
|
const subValues = entries(value);
|
|
717
|
-
|
|
718
711
|
if (subValues.length !== 0) {
|
|
719
712
|
return subValues.reduce((innerAcc, [i, v]) => {
|
|
720
713
|
const subKey = `${key}.${i}`;
|
|
@@ -722,18 +715,15 @@ const toStringifiedVariables = (acc, key, value) => {
|
|
|
722
715
|
}, acc);
|
|
723
716
|
}
|
|
724
717
|
}
|
|
725
|
-
|
|
726
718
|
acc[key] = toString(value);
|
|
727
719
|
return acc;
|
|
728
720
|
};
|
|
729
|
-
|
|
730
721
|
const getGqlRequestId = (operation, variables, context) => {
|
|
731
722
|
const parts = [];
|
|
732
723
|
const sortableContext = new URLSearchParams(context);
|
|
733
724
|
sortableContext.sort();
|
|
734
725
|
parts.push(sortableContext.toString());
|
|
735
726
|
parts.push(operation.id);
|
|
736
|
-
|
|
737
727
|
if (variables != null) {
|
|
738
728
|
const stringifiedVariables = Object.keys(variables).reduce((acc, key) => {
|
|
739
729
|
const value = variables[key];
|
|
@@ -743,7 +733,6 @@ const getGqlRequestId = (operation, variables, context) => {
|
|
|
743
733
|
sortableVariables.sort();
|
|
744
734
|
parts.push(sortableVariables.toString());
|
|
745
735
|
}
|
|
746
|
-
|
|
747
736
|
return parts.join("|");
|
|
748
737
|
};
|
|
749
738
|
|
|
@@ -752,24 +741,24 @@ const GqlErrors = Object.freeze({
|
|
|
752
741
|
BadResponse: "BadResponse",
|
|
753
742
|
ErrorResult: "ErrorResult"
|
|
754
743
|
});
|
|
755
|
-
|
|
756
|
-
|
|
744
|
+
let GqlError = function (_KindError) {
|
|
745
|
+
_inheritsLoose(GqlError, _KindError);
|
|
746
|
+
function GqlError(message, kind, {
|
|
757
747
|
metadata,
|
|
758
748
|
cause
|
|
759
749
|
} = {}) {
|
|
760
|
-
|
|
750
|
+
return _KindError.call(this, message, kind, {
|
|
761
751
|
metadata,
|
|
762
752
|
cause,
|
|
763
753
|
name: "Gql"
|
|
764
|
-
});
|
|
754
|
+
}) || this;
|
|
765
755
|
}
|
|
766
|
-
|
|
767
|
-
}
|
|
756
|
+
return GqlError;
|
|
757
|
+
}(KindError);
|
|
768
758
|
|
|
769
759
|
const getGqlDataFromResponse = async response => {
|
|
770
760
|
const bodyText = await response.text();
|
|
771
761
|
let result;
|
|
772
|
-
|
|
773
762
|
try {
|
|
774
763
|
result = JSON.parse(bodyText);
|
|
775
764
|
} catch (e) {
|
|
@@ -781,7 +770,6 @@ const getGqlDataFromResponse = async response => {
|
|
|
781
770
|
cause: e
|
|
782
771
|
});
|
|
783
772
|
}
|
|
784
|
-
|
|
785
773
|
if (response.status >= 300) {
|
|
786
774
|
throw new DataError("Response unsuccessful", DataErrors.Network, {
|
|
787
775
|
metadata: {
|
|
@@ -790,7 +778,6 @@ const getGqlDataFromResponse = async response => {
|
|
|
790
778
|
}
|
|
791
779
|
});
|
|
792
780
|
}
|
|
793
|
-
|
|
794
781
|
if (!Object.prototype.hasOwnProperty.call(result, "data") && !Object.prototype.hasOwnProperty.call(result, "errors")) {
|
|
795
782
|
throw new GqlError("Server response missing", GqlErrors.BadResponse, {
|
|
796
783
|
metadata: {
|
|
@@ -799,7 +786,6 @@ const getGqlDataFromResponse = async response => {
|
|
|
799
786
|
}
|
|
800
787
|
});
|
|
801
788
|
}
|
|
802
|
-
|
|
803
789
|
if (result.errors != null && Array.isArray(result.errors) && result.errors.length > 0) {
|
|
804
790
|
throw new GqlError("GraphQL errors", GqlErrors.ErrorResult, {
|
|
805
791
|
metadata: {
|
|
@@ -808,7 +794,6 @@ const getGqlDataFromResponse = async response => {
|
|
|
808
794
|
}
|
|
809
795
|
});
|
|
810
796
|
}
|
|
811
|
-
|
|
812
797
|
return result.data;
|
|
813
798
|
};
|
|
814
799
|
|
|
@@ -819,13 +804,10 @@ const DocumentTypes = Object.freeze({
|
|
|
819
804
|
const cache = new Map();
|
|
820
805
|
function graphQLDocumentNodeParser(document) {
|
|
821
806
|
var _definition$name;
|
|
822
|
-
|
|
823
807
|
const cached = cache.get(document);
|
|
824
|
-
|
|
825
808
|
if (cached) {
|
|
826
809
|
return cached;
|
|
827
810
|
}
|
|
828
|
-
|
|
829
811
|
if (!(document != null && document.kind)) {
|
|
830
812
|
if (process.env.NODE_ENV === "production") {
|
|
831
813
|
throw new DataError("Bad DocumentNode", DataErrors.InvalidInput);
|
|
@@ -833,12 +815,10 @@ function graphQLDocumentNodeParser(document) {
|
|
|
833
815
|
throw new DataError(`Argument of ${JSON.stringify(document)} passed to parser was not a valid GraphQL ` + `DocumentNode. You may need to use 'graphql-tag' or another method ` + `to convert your operation into a document`, DataErrors.InvalidInput);
|
|
834
816
|
}
|
|
835
817
|
}
|
|
836
|
-
|
|
837
818
|
const fragments = document.definitions.filter(x => x.kind === "FragmentDefinition");
|
|
838
819
|
const queries = document.definitions.filter(x => x.kind === "OperationDefinition" && x.operation === "query");
|
|
839
820
|
const mutations = document.definitions.filter(x => x.kind === "OperationDefinition" && x.operation === "mutation");
|
|
840
821
|
const subscriptions = document.definitions.filter(x => x.kind === "OperationDefinition" && x.operation === "subscription");
|
|
841
|
-
|
|
842
822
|
if (fragments.length && !queries.length && !mutations.length) {
|
|
843
823
|
if (process.env.NODE_ENV === "production") {
|
|
844
824
|
throw new DataError("Fragment only", DataErrors.InvalidInput);
|
|
@@ -846,7 +826,6 @@ function graphQLDocumentNodeParser(document) {
|
|
|
846
826
|
throw new DataError(`Passing only a fragment to 'graphql' is not supported. ` + `You must include a query or mutation as well`, DataErrors.InvalidInput);
|
|
847
827
|
}
|
|
848
828
|
}
|
|
849
|
-
|
|
850
829
|
if (subscriptions.length) {
|
|
851
830
|
if (process.env.NODE_ENV === "production") {
|
|
852
831
|
throw new DataError("No subscriptions", DataErrors.InvalidInput);
|
|
@@ -854,7 +833,6 @@ function graphQLDocumentNodeParser(document) {
|
|
|
854
833
|
throw new DataError(`We do not support subscriptions. ` + `${JSON.stringify(document)} had ${subscriptions.length} subscriptions`, DataErrors.InvalidInput);
|
|
855
834
|
}
|
|
856
835
|
}
|
|
857
|
-
|
|
858
836
|
if (queries.length + mutations.length > 1) {
|
|
859
837
|
if (process.env.NODE_ENV === "production") {
|
|
860
838
|
throw new DataError("Too many ops", DataErrors.InvalidInput);
|
|
@@ -862,7 +840,6 @@ function graphQLDocumentNodeParser(document) {
|
|
|
862
840
|
throw new DataError(`We only support one query or mutation per component. ` + `${JSON.stringify(document)} had ${queries.length} queries and ` + `${mutations.length} mutations. `, DataErrors.InvalidInput);
|
|
863
841
|
}
|
|
864
842
|
}
|
|
865
|
-
|
|
866
843
|
const type = queries.length ? DocumentTypes.query : DocumentTypes.mutation;
|
|
867
844
|
const definitions = queries.length ? queries : mutations;
|
|
868
845
|
const definition = definitions[0];
|
|
@@ -911,18 +888,15 @@ const mergeGqlContext = (defaultContext, overrides) => {
|
|
|
911
888
|
acc[key] = overrides[key];
|
|
912
889
|
}
|
|
913
890
|
}
|
|
914
|
-
|
|
915
891
|
return acc;
|
|
916
892
|
}, _extends({}, defaultContext));
|
|
917
893
|
};
|
|
918
894
|
|
|
919
895
|
const useGqlRouterContext = (contextOverrides = {}) => {
|
|
920
896
|
const gqlRouterContext = useContext(GqlRouterContext);
|
|
921
|
-
|
|
922
897
|
if (gqlRouterContext == null) {
|
|
923
898
|
throw new GqlError("No GqlRouter", GqlErrors.Internal);
|
|
924
899
|
}
|
|
925
|
-
|
|
926
900
|
const {
|
|
927
901
|
fetch,
|
|
928
902
|
defaultContext
|
|
@@ -932,11 +906,9 @@ const useGqlRouterContext = (contextOverrides = {}) => {
|
|
|
932
906
|
const refKeys = Object.keys(contextRef.current);
|
|
933
907
|
const mergedKeys = Object.keys(mergedContext);
|
|
934
908
|
const shouldWeUpdateRef = refKeys.length !== mergedKeys.length || mergedKeys.every(key => contextRef.current[key] !== mergedContext[key]);
|
|
935
|
-
|
|
936
909
|
if (shouldWeUpdateRef) {
|
|
937
910
|
contextRef.current = mergedContext;
|
|
938
911
|
}
|
|
939
|
-
|
|
940
912
|
const finalContext = contextRef.current;
|
|
941
913
|
const finalRouterContext = useMemo(() => ({
|
|
942
914
|
fetch,
|