@khanacademy/wonder-blocks-data 8.0.3 → 9.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/dist/index.js CHANGED
@@ -175,17 +175,10 @@ module.exports = require("@khanacademy/wonder-blocks-core");
175
175
 
176
176
  "use strict";
177
177
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return FetchPolicy; });
178
- // TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
179
- // they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
180
-
181
- /* eslint-disable no-undef */
182
-
183
178
  /**
184
179
  * Defines the various fetch policies that can be applied to requests.
185
180
  */
186
- const FetchPolicy = __webpack_require__(22).Mirrored(["CacheBeforeNetwork", "CacheAndNetwork", "CacheOnly", "NetworkOnly"]);
187
- /* eslint-enable no-undef */
188
-
181
+ const FetchPolicy = __webpack_require__(23).Mirrored(["CacheBeforeNetwork", "CacheAndNetwork", "CacheOnly", "NetworkOnly"]);
189
182
  /**
190
183
  * Define what can be cached.
191
184
  *
@@ -249,7 +242,7 @@ class GqlError extends _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0
249
242
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
250
243
 
251
244
  "use strict";
252
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return purgeSharedCache; });
245
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SharedCache; });
253
246
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return useSharedCache; });
254
247
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
255
248
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
@@ -266,18 +259,13 @@ class GqlError extends _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0
266
259
  */
267
260
  const cache = new _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__[/* ScopedInMemoryCache */ "a"]();
268
261
  /**
269
- * Purge the in-memory cache or a single scope within it.
262
+ * Access to the shared in-memory cache.
263
+ *
264
+ * This is the cache used by `useSharedCache` and related hooks and
265
+ * components.
270
266
  */
271
267
 
272
- const purgeSharedCache = (scope = "") => {
273
- // If we have a valid scope (empty string is falsy), then clear that scope.
274
- if (scope && typeof scope === "string") {
275
- cache.purgeScope(scope);
276
- } else {
277
- // Just reset the object. This should be sufficient.
278
- cache.purgeAll();
279
- }
280
- };
268
+ const SharedCache = cache;
281
269
  /**
282
270
  * Hook to retrieve data from and store data in an in-memory cache.
283
271
  *
@@ -286,9 +274,6 @@ const purgeSharedCache = (scope = "") => {
286
274
  * function to set the cache entry (passing null or undefined to this function
287
275
  * will delete the entry).
288
276
  *
289
- * To clear a single scope within the cache or the entire cache,
290
- * the `clearScopedCache` export is available.
291
- *
292
277
  * NOTE: Unlike useState or useReducer, we don't automatically update folks
293
278
  * if the value they reference changes. We might add it later (if we need to),
294
279
  * but the likelihood here is that things won't be changing in this cache in a
@@ -931,7 +916,7 @@ class ScopedInMemoryCache {
931
916
  /**
932
917
  * Policies to define how a hydratable effect should behave client-side.
933
918
  */
934
- const WhenClientSide = __webpack_require__(22).Mirrored(["DoNotHydrate", "ExecuteWhenNoResult", "ExecuteWhenNoSuccessResult", "AlwaysExecute"]);
919
+ const WhenClientSide = __webpack_require__(23).Mirrored(["DoNotHydrate", "ExecuteWhenNoResult", "ExecuteWhenNoSuccessResult", "AlwaysExecute"]);
935
920
  const DefaultScope = "useHydratableEffect";
936
921
  /**
937
922
  * Hook to execute an async operation on server and client.
@@ -1125,8 +1110,8 @@ const purgeHydrationCache = predicate => _ssr_cache_js__WEBPACK_IMPORTED_MODULE_
1125
1110
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1126
1111
  /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
1127
1112
  /* harmony import */ var _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9);
1128
- /* harmony import */ var _util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(32);
1129
- /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(19);
1113
+ /* harmony import */ var _util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(33);
1114
+ /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(20);
1130
1115
 
1131
1116
 
1132
1117
 
@@ -1190,7 +1175,7 @@ const useServerEffect = (requestId, handler, options = {}) => {
1190
1175
  /* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
1191
1176
  /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
1192
1177
  /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(5);
1193
- /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(19);
1178
+ /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(20);
1194
1179
  /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(3);
1195
1180
 
1196
1181
 
@@ -1343,10 +1328,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1343
1328
  // really make sense - the same requestId should be handled the same as
1344
1329
  // each other.
1345
1330
  // eslint-disable-next-line react-hooks/exhaustive-deps
1346
- }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // We need to trigger a re-render when the request ID changes as that
1347
- // indicates its a different request.
1348
-
1349
- const requestIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](requestId); // Calculate if we want to fetch the result or not.
1331
+ }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // Calculate if we want to fetch the result or not.
1350
1332
  // If this is true, we will do a new fetch, cancelling the previous fetch
1351
1333
  // if there is one inflight.
1352
1334
 
@@ -1363,9 +1345,8 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1363
1345
  return false;
1364
1346
 
1365
1347
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork:
1366
- // If we don't have a cached value or this is a new requestId,
1367
- // then we need to fetch.
1368
- return mostRecentResult == null || requestId !== requestIdRef.current;
1348
+ // If we don't have a cached value then we need to fetch.
1349
+ return mostRecentResult == null;
1369
1350
 
1370
1351
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheAndNetwork:
1371
1352
  case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly:
@@ -1373,9 +1354,7 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1373
1354
  // result, then we need to fetch one.
1374
1355
  return networkResultRef.current == null;
1375
1356
  }
1376
- }, [requestId, mostRecentResult, fetchPolicy, hardSkip]); // Let's make sure our ref is set to the most recent requestId.
1377
-
1378
- requestIdRef.current = requestId;
1357
+ }, [mostRecentResult, fetchPolicy, hardSkip]);
1379
1358
  react__WEBPACK_IMPORTED_MODULE_0__["useEffect"](() => {
1380
1359
  if (!shouldFetch) {
1381
1360
  return;
@@ -1405,6 +1384,76 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1405
1384
  /* 18 */
1406
1385
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1407
1386
 
1387
+ "use strict";
1388
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlDataFromResponse; });
1389
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1390
+ /* harmony import */ var _gql_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
1391
+
1392
+
1393
+ /**
1394
+ * Validate a GQL operation response and extract the data.
1395
+ */
1396
+
1397
+ const getGqlDataFromResponse = async response => {
1398
+ // Get the response as text, that way we can use the text in error
1399
+ // messaging, should our parsing fail.
1400
+ const bodyText = await response.text();
1401
+ let result;
1402
+
1403
+ try {
1404
+ result = JSON.parse(bodyText);
1405
+ } catch (e) {
1406
+ throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Failed to parse response", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Parse, {
1407
+ metadata: {
1408
+ statusCode: response.status,
1409
+ bodyText
1410
+ },
1411
+ cause: e
1412
+ });
1413
+ } // Check for a bad status code.
1414
+
1415
+
1416
+ if (response.status >= 300) {
1417
+ throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Response unsuccessful", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Network, {
1418
+ metadata: {
1419
+ statusCode: response.status,
1420
+ result
1421
+ }
1422
+ });
1423
+ } // Check that we have a valid result payload.
1424
+
1425
+
1426
+ if ( // Flow shouldn't be warning about this.
1427
+ // $FlowIgnore[method-unbinding]
1428
+ !Object.prototype.hasOwnProperty.call(result, "data") && // Flow shouldn't be warning about this.
1429
+ // $FlowIgnore[method-unbinding]
1430
+ !Object.prototype.hasOwnProperty.call(result, "errors")) {
1431
+ throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("Server response missing", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].BadResponse, {
1432
+ metadata: {
1433
+ statusCode: response.status,
1434
+ result
1435
+ }
1436
+ });
1437
+ } // If the response payload has errors, throw an error.
1438
+
1439
+
1440
+ if (result.errors != null && Array.isArray(result.errors) && result.errors.length > 0) {
1441
+ throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("GraphQL errors", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].ErrorResult, {
1442
+ metadata: {
1443
+ statusCode: response.status,
1444
+ result
1445
+ }
1446
+ });
1447
+ } // We got here, so return the data.
1448
+
1449
+
1450
+ return result.data;
1451
+ };
1452
+
1453
+ /***/ }),
1454
+ /* 19 */
1455
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1456
+
1408
1457
  "use strict";
1409
1458
  /* unused harmony export DocumentTypes */
1410
1459
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return graphQLDocumentNodeParser; });
@@ -1483,7 +1532,7 @@ function graphQLDocumentNodeParser(document) {
1483
1532
  }
1484
1533
 
1485
1534
  /***/ }),
1486
- /* 19 */
1535
+ /* 20 */
1487
1536
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1488
1537
 
1489
1538
  "use strict";
@@ -1534,7 +1583,7 @@ const useRequestInterception = (requestId, handler) => {
1534
1583
  };
1535
1584
 
1536
1585
  /***/ }),
1537
- /* 20 */
1586
+ /* 21 */
1538
1587
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1539
1588
 
1540
1589
  "use strict";
@@ -1545,7 +1594,7 @@ const useRequestInterception = (requestId, handler) => {
1545
1594
  const GqlRouterContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
1546
1595
 
1547
1596
  /***/ }),
1548
- /* 21 */
1597
+ /* 22 */
1549
1598
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1550
1599
 
1551
1600
  "use strict";
@@ -1579,13 +1628,13 @@ const mergeGqlContext = (defaultContext, overrides) => {
1579
1628
  };
1580
1629
 
1581
1630
  /***/ }),
1582
- /* 22 */
1631
+ /* 23 */
1583
1632
  /***/ (function(module, exports) {
1584
1633
 
1585
1634
  module.exports = require("flow-enums-runtime");
1586
1635
 
1587
1636
  /***/ }),
1588
- /* 23 */
1637
+ /* 24 */
1589
1638
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1590
1639
 
1591
1640
  "use strict";
@@ -1662,7 +1711,7 @@ const abortInflightRequests = () => {
1662
1711
  };
1663
1712
 
1664
1713
  /***/ }),
1665
- /* 24 */
1714
+ /* 25 */
1666
1715
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1667
1716
 
1668
1717
  "use strict";
@@ -1680,12 +1729,12 @@ const abortInflightRequests = () => {
1680
1729
  */
1681
1730
 
1682
1731
  const purgeCaches = () => {
1683
- Object(_hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* purgeSharedCache */ "a"])();
1732
+ _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* SharedCache */ "a"].purgeAll();
1684
1733
  Object(_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__[/* purgeHydrationCache */ "b"])();
1685
1734
  };
1686
1735
 
1687
1736
  /***/ }),
1688
- /* 25 */
1737
+ /* 26 */
1689
1738
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1690
1739
 
1691
1740
  "use strict";
@@ -1716,7 +1765,7 @@ class TrackData extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
1716
1765
  }
1717
1766
 
1718
1767
  /***/ }),
1719
- /* 26 */
1768
+ /* 27 */
1720
1769
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1721
1770
 
1722
1771
  "use strict";
@@ -1748,7 +1797,7 @@ const Data = ({
1748
1797
  /* harmony default export */ __webpack_exports__["a"] = (Data);
1749
1798
 
1750
1799
  /***/ }),
1751
- /* 27 */
1800
+ /* 28 */
1752
1801
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1753
1802
 
1754
1803
  "use strict";
@@ -1789,7 +1838,7 @@ const InterceptRequests = ({
1789
1838
  /* harmony default export */ __webpack_exports__["a"] = (InterceptRequests);
1790
1839
 
1791
1840
  /***/ }),
1792
- /* 28 */
1841
+ /* 29 */
1793
1842
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1794
1843
 
1795
1844
  "use strict";
@@ -1838,12 +1887,12 @@ const getGqlRequestId = (operation, variables, context) => {
1838
1887
  };
1839
1888
 
1840
1889
  /***/ }),
1841
- /* 29 */
1890
+ /* 30 */
1842
1891
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1843
1892
 
1844
1893
  "use strict";
1845
1894
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return toGqlOperation; });
1846
- /* harmony import */ var _graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
1895
+ /* harmony import */ var _graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(19);
1847
1896
 
1848
1897
 
1849
1898
  /**
@@ -1885,14 +1934,14 @@ const toGqlOperation = documentNode => {
1885
1934
  };
1886
1935
 
1887
1936
  /***/ }),
1888
- /* 30 */
1937
+ /* 31 */
1889
1938
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1890
1939
 
1891
1940
  "use strict";
1892
1941
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlRouter; });
1893
1942
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1894
1943
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1895
- /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(20);
1944
+ /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
1896
1945
 
1897
1946
 
1898
1947
 
@@ -1929,16 +1978,16 @@ const GqlRouter = ({
1929
1978
  };
1930
1979
 
1931
1980
  /***/ }),
1932
- /* 31 */
1981
+ /* 32 */
1933
1982
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1934
1983
 
1935
1984
  "use strict";
1936
1985
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGql; });
1937
1986
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1938
1987
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1939
- /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
1940
- /* harmony import */ var _use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(33);
1941
- /* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(34);
1988
+ /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22);
1989
+ /* harmony import */ var _use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(34);
1990
+ /* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(18);
1942
1991
 
1943
1992
 
1944
1993
 
@@ -1979,7 +2028,7 @@ const useGql = (context = {}) => {
1979
2028
  };
1980
2029
 
1981
2030
  /***/ }),
1982
- /* 32 */
2031
+ /* 33 */
1983
2032
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1984
2033
 
1985
2034
  "use strict";
@@ -2019,15 +2068,15 @@ const resultFromCachedResponse = cacheEntry => {
2019
2068
  };
2020
2069
 
2021
2070
  /***/ }),
2022
- /* 33 */
2071
+ /* 34 */
2023
2072
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
2024
2073
 
2025
2074
  "use strict";
2026
2075
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGqlRouterContext; });
2027
2076
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
2028
2077
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
2029
- /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
2030
- /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20);
2078
+ /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22);
2079
+ /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21);
2031
2080
  /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
2032
2081
 
2033
2082
 
@@ -2070,76 +2119,6 @@ const useGqlRouterContext = (contextOverrides = {}) => {
2070
2119
  return finalRouterContext;
2071
2120
  };
2072
2121
 
2073
- /***/ }),
2074
- /* 34 */
2075
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
2076
-
2077
- "use strict";
2078
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlDataFromResponse; });
2079
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
2080
- /* harmony import */ var _gql_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
2081
-
2082
-
2083
- /**
2084
- * Validate a GQL operation response and extract the data.
2085
- */
2086
-
2087
- const getGqlDataFromResponse = async response => {
2088
- // Get the response as text, that way we can use the text in error
2089
- // messaging, should our parsing fail.
2090
- const bodyText = await response.text();
2091
- let result;
2092
-
2093
- try {
2094
- result = JSON.parse(bodyText);
2095
- } catch (e) {
2096
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Failed to parse response", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Parse, {
2097
- metadata: {
2098
- statusCode: response.status,
2099
- bodyText
2100
- },
2101
- cause: e
2102
- });
2103
- } // Check for a bad status code.
2104
-
2105
-
2106
- if (response.status >= 300) {
2107
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Response unsuccessful", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Network, {
2108
- metadata: {
2109
- statusCode: response.status,
2110
- result
2111
- }
2112
- });
2113
- } // Check that we have a valid result payload.
2114
-
2115
-
2116
- if ( // Flow shouldn't be warning about this.
2117
- // $FlowIgnore[method-unbinding]
2118
- !Object.prototype.hasOwnProperty.call(result, "data") && // Flow shouldn't be warning about this.
2119
- // $FlowIgnore[method-unbinding]
2120
- !Object.prototype.hasOwnProperty.call(result, "errors")) {
2121
- throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("Server response missing", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].BadResponse, {
2122
- metadata: {
2123
- statusCode: response.status,
2124
- result
2125
- }
2126
- });
2127
- } // If the response payload has errors, throw an error.
2128
-
2129
-
2130
- if (result.errors != null && Array.isArray(result.errors) && result.errors.length > 0) {
2131
- throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("GraphQL errors", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].ErrorResult, {
2132
- metadata: {
2133
- statusCode: response.status,
2134
- result
2135
- }
2136
- });
2137
- } // We got here, so return the data.
2138
-
2139
-
2140
- return result.data;
2141
- };
2142
-
2143
2122
  /***/ }),
2144
2123
  /* 35 */
2145
2124
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
@@ -2154,23 +2133,23 @@ __webpack_require__.r(__webpack_exports__);
2154
2133
 
2155
2134
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeHydrationCache", function() { return _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__["b"]; });
2156
2135
 
2157
- /* harmony import */ var _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(23);
2136
+ /* harmony import */ var _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(24);
2158
2137
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fetchTrackedRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["b"]; });
2159
2138
 
2160
2139
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "hasTrackedRequestsToBeFetched", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["c"]; });
2161
2140
 
2162
2141
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "abortInflightRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
2163
2142
 
2164
- /* harmony import */ var _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(24);
2143
+ /* harmony import */ var _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(25);
2165
2144
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeCaches", function() { return _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
2166
2145
 
2167
- /* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(25);
2146
+ /* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(26);
2168
2147
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TrackData", function() { return _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
2169
2148
 
2170
- /* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(26);
2149
+ /* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(27);
2171
2150
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Data", function() { return _components_data_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
2172
2151
 
2173
- /* harmony import */ var _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(27);
2152
+ /* harmony import */ var _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(28);
2174
2153
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "InterceptRequests", function() { return _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__["a"]; });
2175
2154
 
2176
2155
  /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(0);
@@ -2187,7 +2166,7 @@ __webpack_require__.r(__webpack_exports__);
2187
2166
  /* harmony import */ var _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(5);
2188
2167
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useSharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__["b"]; });
2189
2168
 
2190
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeSharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__["a"]; });
2169
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__["a"]; });
2191
2170
 
2192
2171
  /* harmony import */ var _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(12);
2193
2172
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useHydratableEffect", function() { return _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__["b"]; });
@@ -2203,25 +2182,28 @@ __webpack_require__.r(__webpack_exports__);
2203
2182
  /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(6);
2204
2183
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Status", function() { return _util_status_js__WEBPACK_IMPORTED_MODULE_14__["a"]; });
2205
2184
 
2206
- /* harmony import */ var _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(28);
2185
+ /* harmony import */ var _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(29);
2207
2186
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getGqlRequestId", function() { return _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__["a"]; });
2208
2187
 
2209
- /* harmony import */ var _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(18);
2210
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "graphQLDocumentNodeParser", function() { return _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_16__["a"]; });
2188
+ /* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(18);
2189
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getGqlDataFromResponse", function() { return _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_16__["a"]; });
2211
2190
 
2212
- /* harmony import */ var _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(29);
2213
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toGqlOperation", function() { return _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_17__["a"]; });
2191
+ /* harmony import */ var _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(19);
2192
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "graphQLDocumentNodeParser", function() { return _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_17__["a"]; });
2214
2193
 
2215
- /* harmony import */ var _components_gql_router_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(30);
2216
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlRouter", function() { return _components_gql_router_js__WEBPACK_IMPORTED_MODULE_18__["a"]; });
2194
+ /* harmony import */ var _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(30);
2195
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toGqlOperation", function() { return _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_18__["a"]; });
2217
2196
 
2218
- /* harmony import */ var _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(31);
2219
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useGql", function() { return _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_19__["a"]; });
2197
+ /* harmony import */ var _components_gql_router_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(31);
2198
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlRouter", function() { return _components_gql_router_js__WEBPACK_IMPORTED_MODULE_19__["a"]; });
2220
2199
 
2221
- /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(4);
2222
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlError", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_20__["a"]; });
2200
+ /* harmony import */ var _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(32);
2201
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useGql", function() { return _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_20__["a"]; });
2223
2202
 
2224
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlErrors", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_20__["b"]; });
2203
+ /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(4);
2204
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlError", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__["a"]; });
2205
+
2206
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlErrors", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__["b"]; });
2225
2207
 
2226
2208
  // TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
2227
2209
  // have fixed:
@@ -2252,5 +2234,6 @@ __webpack_require__.r(__webpack_exports__);
2252
2234
 
2253
2235
 
2254
2236
 
2237
+
2255
2238
  /***/ })
2256
2239
  /******/ ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-data",
3
- "version": "8.0.3",
3
+ "version": "9.0.0",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -13,7 +13,7 @@
13
13
  "test": "echo \"Error: no test specified\" && exit 1"
14
14
  },
15
15
  "dependencies": {
16
- "@babel/runtime": "^7.16.3",
16
+ "@babel/runtime": "^7.18.6",
17
17
  "@khanacademy/wonder-blocks-core": "^4.3.2"
18
18
  },
19
19
  "peerDependencies": {
@@ -86,7 +86,7 @@ import {
86
86
  TrackData,
87
87
  hasTrackedRequestsToBeFetched,
88
88
  fetchTrackedRequests,
89
- purgeSharedCache,
89
+ SharedCache,
90
90
  } from "@khanacademy/wonder-blocks-data";
91
91
 
92
92
  // Don't forget to import your app!
@@ -113,7 +113,7 @@ async function renderApp(): Promise<string> {
113
113
  * shared cache used by the `useSharedCache` hook as this is transient
114
114
  * cache that does not itself get directly hydrated.
115
115
  */
116
- purgeSharedCache();
116
+ SharedCache.purgeAll();
117
117
 
118
118
  // Render the tracked component.
119
119
  renderedComponent = renderToString(trackedElement);
@@ -20,4 +20,4 @@ The `purgeCaches` method will purge the following caches managed by Wonder Block
20
20
  - Shared in-memory cache as used by [`useSharedCache`](/docs/data-exports-usesharedcache--page) and other hooks
21
21
  - Hydration cache as used during server-side rendering
22
22
 
23
- This is equivalent to calling both `purgeSharedCache()` and `purgeHydrationCache()`, and is especially useful when writing tests or setting up a test environment.
23
+ This is equivalent to calling both `SharedCache.purgeAll()` and `purgeHydrationCache()`, and is especially useful when writing tests or setting up a test environment.
@@ -11,12 +11,12 @@ import {Meta} from "@storybook/addon-docs";
11
11
 
12
12
  # ScopedInMemoryCache
13
13
 
14
- This class implements an in-memory cache that can contain different scopes of cached data. This allows for quick removal of entire classes of data as identified by their scopes without having to iterate each cached item to find them.
14
+ This class implements an in-memory cache that can contain different scopes of cached data. This allows for quick removal of entire classes of data as identified by their scopes without having to iterate each cached item to find them. It implements the [`ScopedCache`](/docs/data-types-scopedcache--page) interface.
15
15
 
16
16
  ## constructor()
17
17
 
18
18
  ```ts
19
- new ScopedInMemoryCache(initialCache?: ScopedCache)
19
+ new ScopedInMemoryCache(initialCache?: RawScopedCache)
20
20
  ```
21
21
 
22
22
  Creates a new instance. An initial state for the cache can be provided.
@@ -34,7 +34,7 @@ Is `true` if the cache contains any data; otherwise, `false`.
34
34
  ## set()
35
35
 
36
36
  ```ts
37
- set<TValue: ValidCacheData>(
37
+ set(
38
38
  scope: string,
39
39
  id: string,
40
40
  value: TValue,
@@ -16,7 +16,7 @@ This class is a specialization of [`ScopedInMemoryCache`](/docs/data-exports-sco
16
16
  ## constructor()
17
17
 
18
18
  ```ts
19
- new SerializableInMemoryCache(initialCache?: ScopedCache)
19
+ new SerializableInMemoryCache(initialCache?: RawScopedCache)
20
20
  ```
21
21
 
22
22
  Creates a new instance. The `initialCache`, if provided, will be cloned and used as the initial state of the cache.
@@ -67,7 +67,7 @@ Gets a value from the cache. If a value with the given identifier (`id`) is not
67
67
  ## clone()
68
68
 
69
69
  ```ts
70
- clone(): ScopedCache;
70
+ clone(): RawScopedCache;
71
71
  ```
72
72
 
73
73
  Returns a clone of the current cache.
@@ -0,0 +1,16 @@
1
+ import {Meta} from "@storybook/addon-docs";
2
+
3
+ <Meta
4
+ title="Data / Exports / SharedCache"
5
+ parameters={{
6
+ chromatic: {
7
+ disableSnapshot: true,
8
+ },
9
+ }}
10
+ />
11
+
12
+ # SharedCache
13
+
14
+ The `SharedCache` export can be used to view and modify the in-memory cache used by [`useSharedCache`](/docs/data-exports-usesharedcache--page) hook and the hooks and components that relate to it.
15
+
16
+ The `SharedCache` export implements the [`ScopedCache` interface type](/docs/data-types-scopedcache--page).
@@ -19,12 +19,12 @@ function useSharedCache<TValue: ValidCacheData>(
19
19
  ): [?TValue, CacheValueFn<TValue>];
20
20
  ```
21
21
 
22
- The `useSharedCache` hook provides access to a shared in-memory cache. This cache is not part of the cache hydrated by Wonder Blocks Data, so [`purgeSharedCache`](/docs/data-exports-purgesharedcache--page) must be called between server-side render cycles.
22
+ The `useSharedCache` hook provides access to a shared in-memory cache. This cache is not part of the cache hydrated by Wonder Blocks Data, so [`SharedCache.purgeAll()`](/docs/data-exports-sharedcache--page) must be called between server-side render cycles.
23
23
 
24
24
  The hook returns a tuple of the currently cached value, or `null` if none is cached, and a function that can be used to set the cached value.
25
25
 
26
26
  The shared cache is passive and as such does not notify of changes to its contents.
27
27
 
28
- Each cached item is identified by an id and a scope. The scope is used to group items. Whole scopes can be cleared by specifying the specific scope when calling [`purgeSharedCache`](/docs/data-exports-purgesharedcache--page).
28
+ Each cached item is identified by an id and a scope. The scope is used to group items. Whole scopes can be cleared by specifying the specific scope when calling [`SharedCache.purgeScope()`](/docs/data-exports-sharedcache--page).
29
29
 
30
30
  An optional argument, `initialValue` can be given. This can be either the value to be cached itself or a function that returns the value to be cached (functions themselves are not valid cachable values). This allows for expensive initialization to only occur when it is necessary.