@khanacademy/wonder-blocks-data 7.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/es/index.js +321 -759
  3. package/dist/index.js +1188 -802
  4. package/package.json +3 -3
  5. package/src/__docs__/_overview_ssr_.stories.mdx +13 -13
  6. package/src/__docs__/exports.abort-inflight-requests.stories.mdx +20 -0
  7. package/src/__docs__/exports.data.stories.mdx +3 -3
  8. package/src/__docs__/{exports.fulfill-all-data-requests.stories.mdx → exports.fetch-tracked-requests.stories.mdx} +5 -5
  9. package/src/__docs__/exports.get-gql-request-id.stories.mdx +24 -0
  10. package/src/__docs__/{exports.has-unfulfilled-requests.stories.mdx → exports.has-tracked-requests-to-be-fetched.stories.mdx} +4 -4
  11. package/src/__docs__/exports.intialize-hydration-cache.stories.mdx +29 -0
  12. package/src/__docs__/exports.purge-caches.stories.mdx +23 -0
  13. package/src/__docs__/{exports.remove-all-from-cache.stories.mdx → exports.purge-hydration-cache.stories.mdx} +4 -4
  14. package/src/__docs__/{exports.clear-shared-cache.stories.mdx → exports.purge-shared-cache.stories.mdx} +4 -4
  15. package/src/__docs__/exports.track-data.stories.mdx +4 -4
  16. package/src/__docs__/exports.use-cached-effect.stories.mdx +7 -4
  17. package/src/__docs__/exports.use-gql.stories.mdx +1 -33
  18. package/src/__docs__/exports.use-server-effect.stories.mdx +1 -1
  19. package/src/__docs__/exports.use-shared-cache.stories.mdx +2 -2
  20. package/src/__docs__/types.fetch-policy.stories.mdx +44 -0
  21. package/src/__docs__/types.response-cache.stories.mdx +1 -1
  22. package/src/__tests__/generated-snapshot.test.js +5 -5
  23. package/src/components/__tests__/data.test.js +2 -6
  24. package/src/hooks/__tests__/use-cached-effect.test.js +341 -100
  25. package/src/hooks/__tests__/use-hydratable-effect.test.js +15 -9
  26. package/src/hooks/__tests__/use-shared-cache.test.js +6 -6
  27. package/src/hooks/use-cached-effect.js +169 -93
  28. package/src/hooks/use-hydratable-effect.js +8 -1
  29. package/src/hooks/use-shared-cache.js +2 -2
  30. package/src/index.js +14 -78
  31. package/src/util/__tests__/get-gql-request-id.test.js +74 -0
  32. package/src/util/__tests__/graphql-document-node-parser.test.js +542 -0
  33. package/src/util/__tests__/hydration-cache-api.test.js +35 -0
  34. package/src/util/__tests__/purge-caches.test.js +29 -0
  35. package/src/util/__tests__/request-api.test.js +188 -0
  36. package/src/util/__tests__/request-fulfillment.test.js +42 -0
  37. package/src/util/__tests__/ssr-cache.test.js +68 -60
  38. package/src/util/__tests__/to-gql-operation.test.js +42 -0
  39. package/src/util/data-error.js +6 -0
  40. package/src/util/get-gql-request-id.js +50 -0
  41. package/src/util/graphql-document-node-parser.js +133 -0
  42. package/src/util/graphql-types.js +30 -0
  43. package/src/util/hydration-cache-api.js +28 -0
  44. package/src/util/purge-caches.js +15 -0
  45. package/src/util/request-api.js +66 -0
  46. package/src/util/request-fulfillment.js +32 -12
  47. package/src/util/request-tracking.js +1 -1
  48. package/src/util/ssr-cache.js +11 -24
  49. package/src/util/to-gql-operation.js +44 -0
  50. package/src/util/types.js +31 -0
  51. package/src/__docs__/exports.intialize-cache.stories.mdx +0 -29
  52. package/src/__docs__/exports.remove-from-cache.stories.mdx +0 -25
  53. package/src/__docs__/exports.request-fulfillment.stories.mdx +0 -36
package/dist/index.js CHANGED
@@ -82,23 +82,17 @@ module.exports =
82
82
  /******/
83
83
  /******/
84
84
  /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 27);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 35);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ([
89
89
  /* 0 */
90
- /***/ (function(module, exports) {
91
-
92
- module.exports = require("react");
93
-
94
- /***/ }),
95
- /* 1 */
96
90
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
97
91
 
98
92
  "use strict";
99
93
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return DataErrors; });
100
94
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return DataError; });
101
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
95
+ /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
102
96
  /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__);
103
97
 
104
98
 
@@ -126,6 +120,12 @@ const DataErrors = Object.freeze({
126
120
  */
127
121
  Network: "Network",
128
122
 
123
+ /**
124
+ * There was a problem due to the state of the system not matching the
125
+ * requested operation or input.
126
+ */
127
+ NotAllowed: "NotAllowed",
128
+
129
129
  /**
130
130
  * Response could not be parsed.
131
131
  */
@@ -157,20 +157,50 @@ class DataError extends _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_
157
157
 
158
158
  }
159
159
 
160
+ /***/ }),
161
+ /* 1 */
162
+ /***/ (function(module, exports) {
163
+
164
+ module.exports = require("react");
165
+
160
166
  /***/ }),
161
167
  /* 2 */
168
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
169
+
170
+ "use strict";
171
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return FetchPolicy; });
172
+ // TODO(somewhatabstract, FEI-4172): Update eslint-plugin-flowtype when
173
+ // they've fixed https://github.com/gajus/eslint-plugin-flowtype/issues/502
174
+
175
+ /* eslint-disable no-undef */
176
+
177
+ /**
178
+ * Defines the various fetch policies that can be applied to requests.
179
+ */
180
+ const FetchPolicy = __webpack_require__(22).Mirrored(["CacheBeforeNetwork", "CacheAndNetwork", "CacheOnly", "NetworkOnly"]);
181
+ /* eslint-enable no-undef */
182
+
183
+ /**
184
+ * Define what can be cached.
185
+ *
186
+ * We disallow functions and undefined as undefined represents a cache miss
187
+ * and functions are not allowed.
188
+ */
189
+
190
+ /***/ }),
191
+ /* 3 */
162
192
  /***/ (function(module, exports) {
163
193
 
164
194
  module.exports = require("@khanacademy/wonder-blocks-core");
165
195
 
166
196
  /***/ }),
167
- /* 3 */
197
+ /* 4 */
168
198
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
169
199
 
170
200
  "use strict";
171
201
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return GqlErrors; });
172
202
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlError; });
173
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
203
+ /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
174
204
  /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__);
175
205
 
176
206
 
@@ -215,7 +245,100 @@ class GqlError extends _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0
215
245
  }
216
246
 
217
247
  /***/ }),
218
- /* 4 */
248
+ /* 5 */
249
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
250
+
251
+ "use strict";
252
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return purgeSharedCache; });
253
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return useSharedCache; });
254
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
255
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
256
+ /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
257
+ /* harmony import */ var _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
258
+
259
+
260
+
261
+
262
+ /**
263
+ * This is the cache.
264
+ * It's incredibly complex.
265
+ * Very in-memory. So cache. Such complex. Wow.
266
+ */
267
+ const cache = new _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__[/* ScopedInMemoryCache */ "a"]();
268
+ /**
269
+ * Purge the in-memory cache or a single scope within it.
270
+ */
271
+
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
+ };
281
+ /**
282
+ * Hook to retrieve data from and store data in an in-memory cache.
283
+ *
284
+ * @returns {[?ReadOnlyCacheValue, CacheValueFn]}
285
+ * Returns an array containing the current cache entry (or undefined), a
286
+ * function to set the cache entry (passing null or undefined to this function
287
+ * will delete the entry).
288
+ *
289
+ * To clear a single scope within the cache or the entire cache,
290
+ * the `clearScopedCache` export is available.
291
+ *
292
+ * NOTE: Unlike useState or useReducer, we don't automatically update folks
293
+ * if the value they reference changes. We might add it later (if we need to),
294
+ * but the likelihood here is that things won't be changing in this cache in a
295
+ * way where we would need that. If we do (and likely only in specific
296
+ * circumstances), we should consider adding a simple boolean useState that can
297
+ * be toggled to cause a rerender whenever the referenced cached data changes
298
+ * so that callers can re-render on cache changes. However, we should make
299
+ * sure this toggling is optional - or we could use a callback argument, to
300
+ * achieve this on an as-needed basis.
301
+ */
302
+
303
+ const useSharedCache = (id, scope, initialValue) => {
304
+ // Verify arguments.
305
+ if (!id || typeof id !== "string") {
306
+ throw new _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataError */ "a"]("id must be a non-empty string", _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataErrors */ "b"].InvalidInput);
307
+ }
308
+
309
+ if (!scope || typeof scope !== "string") {
310
+ throw new _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataError */ "a"]("scope must be a non-empty string", _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataErrors */ "b"].InvalidInput);
311
+ } // Memoize our APIs.
312
+ // This one allows callers to set or replace the cached value.
313
+
314
+
315
+ const cacheValue = react__WEBPACK_IMPORTED_MODULE_0__["useCallback"](value => value == null ? cache.purge(scope, id) : cache.set(scope, id, value), [id, scope]); // We don't memo-ize the current value, just in case the cache was updated
316
+ // since our last run through. Also, our cache does not know what type it
317
+ // stores, so we have to cast it to the type we're exporting. This is a
318
+ // dev time courtesy, rather than a runtime thing.
319
+ // $FlowIgnore[incompatible-type]
320
+
321
+ let currentValue = cache.get(scope, id); // If we have an initial value, we need to add it to the cache
322
+ // and use it as our current value.
323
+
324
+ if (currentValue == null && initialValue !== undefined) {
325
+ // Get the initial value.
326
+ const value = typeof initialValue === "function" ? initialValue() : initialValue;
327
+
328
+ if (value != null) {
329
+ // Update the cache.
330
+ cacheValue(value); // Make sure we return this value as our current value.
331
+
332
+ currentValue = value;
333
+ }
334
+ } // Now we have everything, let's return it.
335
+
336
+
337
+ return [currentValue, cacheValue];
338
+ };
339
+
340
+ /***/ }),
341
+ /* 6 */
219
342
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
220
343
 
221
344
  "use strict";
@@ -244,17 +367,32 @@ const Status = Object.freeze({
244
367
  });
245
368
 
246
369
  /***/ }),
247
- /* 5 */
370
+ /* 7 */
371
+ /***/ (function(module, exports) {
372
+
373
+ module.exports = require("@khanacademy/wonder-stuff-core");
374
+
375
+ /***/ }),
376
+ /* 8 */
248
377
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
249
378
 
250
379
  "use strict";
251
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SsrCache; });
252
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
253
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
254
- /* harmony import */ var _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
380
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return TrackerContext; });
381
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestTracker; });
382
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
383
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
384
+ /* harmony import */ var _ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
385
+ /* harmony import */ var _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
255
386
 
256
387
 
257
- const DefaultScope = "default";
388
+
389
+
390
+ /**
391
+ * Used to inject our tracking function into the render framework.
392
+ *
393
+ * INTERNAL USE ONLY
394
+ */
395
+ const TrackerContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
258
396
  /**
259
397
  * The default instance is stored here.
260
398
  * It's created below in the Default() static property.
@@ -262,252 +400,86 @@ const DefaultScope = "default";
262
400
 
263
401
  let _default;
264
402
  /**
265
- * Implements the response cache.
403
+ * Implements request tracking and fulfillment.
266
404
  *
267
405
  * INTERNAL USE ONLY
268
406
  */
269
407
 
270
408
 
271
- class SsrCache {
409
+ class RequestTracker {
272
410
  static get Default() {
273
411
  if (!_default) {
274
- _default = new SsrCache();
412
+ _default = new RequestTracker();
275
413
  }
276
414
 
277
415
  return _default;
278
416
  }
417
+ /**
418
+ * These are the caches for tracked requests, their handlers, and responses.
419
+ */
279
420
 
280
- constructor(hydrationCache = null, ssrOnlyCache = null) {
281
- this.initialize = source => {
282
- if (this._hydrationCache.inUse) {
283
- throw new Error("Cannot initialize data response cache more than once");
284
- }
285
-
286
- this._hydrationCache = new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]({
287
- // $FlowIgnore[incompatible-call]
288
- [DefaultScope]: source
289
- });
290
- };
291
-
292
- this.cacheData = (id, data, hydrate) => this._setCachedResponse(id, {
293
- data
294
- }, hydrate);
295
-
296
- this.cacheError = (id, error, hydrate) => {
297
- const errorMessage = typeof error === "string" ? error : error.message;
298
- return this._setCachedResponse(id, {
299
- error: errorMessage
300
- }, hydrate);
301
- };
302
-
303
- this.getEntry = id => {
304
- var _this$_ssrOnlyCache$g, _this$_ssrOnlyCache;
305
-
306
- // Get the cached entry for this value.
307
- // We first look in the ssr cache and then the hydration cache.
308
- const internalEntry = (_this$_ssrOnlyCache$g = (_this$_ssrOnlyCache = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache.get(DefaultScope, id)) != null ? _this$_ssrOnlyCache$g : this._hydrationCache.get(DefaultScope, id); // If we are not server-side and we hydrated something, let's clear
309
- // that from the hydration cache to save memory.
310
-
311
- if (this._ssrOnlyCache == null && internalEntry != null) {
312
- // We now delete this from our hydration cache as we don't need it.
313
- // This does mean that if another handler of the same type but
314
- // without some sort of linked cache won't get the value, but
315
- // that's not an expected use-case. If two different places use the
316
- // same handler and options (i.e. the same request), then the
317
- // handler should cater to that to ensure they share the result.
318
- this._hydrationCache.purge(DefaultScope, id);
319
- } // Getting the typing right between the in-memory cache and this
320
- // is hard. Just telling flow it's OK.
321
- // $FlowIgnore[incompatible-return]
322
421
 
422
+ constructor(responseCache = undefined) {
423
+ this._trackedRequests = {};
323
424
 
324
- return internalEntry;
425
+ this.trackDataRequest = (id, handler, hydrate) => {
426
+ /**
427
+ * If we don't already have this tracked, then let's track it.
428
+ */
429
+ if (this._trackedRequests[id] == null) {
430
+ this._trackedRequests[id] = {
431
+ handler,
432
+ hydrate
433
+ };
434
+ }
325
435
  };
326
436
 
327
- this.remove = id => {
328
- var _this$_ssrOnlyCache$p, _this$_ssrOnlyCache2;
329
-
330
- // NOTE(somewhatabstract): We could invoke removeAll with a predicate
331
- // to match the key of the entry we're removing, but that's an
332
- // inefficient way to remove a single item, so let's not do that.
333
- // Delete the entry from the appropriate cache.
334
- return this._hydrationCache.purge(DefaultScope, id) || ((_this$_ssrOnlyCache$p = (_this$_ssrOnlyCache2 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache2.purge(DefaultScope, id)) != null ? _this$_ssrOnlyCache$p : false);
437
+ this.reset = () => {
438
+ this._trackedRequests = {};
335
439
  };
336
440
 
337
- this.removeAll = predicate => {
338
- var _this$_ssrOnlyCache3;
441
+ this.fulfillTrackedRequests = () => {
442
+ const promises = [];
443
+ const {
444
+ cacheData,
445
+ cacheError
446
+ } = this._responseCache;
339
447
 
340
- const realPredicate = predicate ? // We know what we're putting into the cache so let's assume it
341
- // conforms.
342
- // $FlowIgnore[incompatible-call]
343
- (_, key, cachedEntry) => predicate(key, cachedEntry) : undefined; // Apply the predicate to what we have in our caches.
448
+ for (const requestKey of Object.keys(this._trackedRequests)) {
449
+ const options = this._trackedRequests[requestKey];
344
450
 
345
- this._hydrationCache.purgeAll(realPredicate);
451
+ try {
452
+ promises.push(this._requestFulfillment.fulfill(requestKey, { ...options
453
+ }).then(result => {
454
+ switch (result.status) {
455
+ case "success":
456
+ /**
457
+ * Let's cache the data!
458
+ *
459
+ * NOTE: This only caches when we're
460
+ * server side.
461
+ */
462
+ cacheData(requestKey, result.data, options.hydrate);
463
+ break;
346
464
 
347
- (_this$_ssrOnlyCache3 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache3.purgeAll(realPredicate);
348
- };
349
-
350
- this.cloneHydratableData = () => {
351
- var _cache$DefaultScope;
352
-
353
- // We return our hydration cache only.
354
- const cache = this._hydrationCache.clone(); // If we're empty, we still want to return an object, so we default
355
- // to an empty object.
356
- // We only need the default scope out of our scoped in-memory cache.
357
- // We know that it conforms to our expectations.
358
- // $FlowIgnore[incompatible-return]
359
-
360
-
361
- return (_cache$DefaultScope = cache[DefaultScope]) != null ? _cache$DefaultScope : {};
362
- };
363
-
364
- this._ssrOnlyCache = _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() ? ssrOnlyCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]() : undefined;
365
- this._hydrationCache = hydrationCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]();
366
- }
367
-
368
- _setCachedResponse(id, entry, hydrate) {
369
- const frozenEntry = Object.freeze(entry);
370
-
371
- if (_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
372
- // We are server-side.
373
- // We need to store this value.
374
- if (hydrate) {
375
- this._hydrationCache.set(DefaultScope, id, frozenEntry);
376
- } else {
377
- var _this$_ssrOnlyCache4;
378
-
379
- // Usually, when server-side, this cache will always be present.
380
- // We do fake server-side in our doc example though, when it
381
- // won't be.
382
- (_this$_ssrOnlyCache4 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache4.set(DefaultScope, id, frozenEntry);
383
- }
384
- }
385
-
386
- return frozenEntry;
387
- }
388
- /**
389
- * Initialize the cache from a given cache state.
390
- *
391
- * This can only be called if the cache is not already in use.
392
- */
393
-
394
-
395
- }
396
-
397
- /***/ }),
398
- /* 6 */
399
- /***/ (function(module, exports) {
400
-
401
- module.exports = require("@khanacademy/wonder-stuff-core");
402
-
403
- /***/ }),
404
- /* 7 */
405
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
406
-
407
- "use strict";
408
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return TrackerContext; });
409
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestTracker; });
410
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
411
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
412
- /* harmony import */ var _ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
413
- /* harmony import */ var _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
414
-
415
-
416
-
417
-
418
- /**
419
- * Used to inject our tracking function into the render framework.
420
- *
421
- * INTERNAL USE ONLY
422
- */
423
- const TrackerContext = new react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
424
- /**
425
- * The default instance is stored here.
426
- * It's created below in the Default() static property.
427
- */
428
-
429
- let _default;
430
- /**
431
- * Implements request tracking and fulfillment.
432
- *
433
- * INTERNAL USE ONLY
434
- */
435
-
436
-
437
- class RequestTracker {
438
- static get Default() {
439
- if (!_default) {
440
- _default = new RequestTracker();
441
- }
442
-
443
- return _default;
444
- }
445
- /**
446
- * These are the caches for tracked requests, their handlers, and responses.
447
- */
448
-
449
-
450
- constructor(responseCache = undefined) {
451
- this._trackedRequests = {};
452
-
453
- this.trackDataRequest = (id, handler, hydrate) => {
454
- /**
455
- * If we don't already have this tracked, then let's track it.
456
- */
457
- if (this._trackedRequests[id] == null) {
458
- this._trackedRequests[id] = {
459
- handler,
460
- hydrate
461
- };
462
- }
463
- };
464
-
465
- this.reset = () => {
466
- this._trackedRequests = {};
467
- };
468
-
469
- this.fulfillTrackedRequests = () => {
470
- const promises = [];
471
- const {
472
- cacheData,
473
- cacheError
474
- } = this._responseCache;
475
-
476
- for (const requestKey of Object.keys(this._trackedRequests)) {
477
- const options = this._trackedRequests[requestKey];
478
-
479
- try {
480
- promises.push(this._requestFulfillment.fulfill(requestKey, { ...options
481
- }).then(result => {
482
- switch (result.status) {
483
- case "success":
484
- /**
485
- * Let's cache the data!
486
- *
487
- * NOTE: This only caches when we're
488
- * server side.
489
- */
490
- cacheData(requestKey, result.data, options.hydrate);
491
- break;
492
-
493
- case "error":
494
- /**
495
- * Let's cache the error!
496
- *
497
- * NOTE: This only caches when we're
498
- * server side.
499
- */
500
- cacheError(requestKey, result.error, options.hydrate);
501
- break;
502
- } // For status === "loading":
503
- // Could never get here unless we wrote
504
- // the code wrong. Rather than bloat
505
- // code with useless error, just ignore.
506
- // For status === "aborted":
507
- // We won't cache this.
508
- // We don't hydrate aborted requests,
509
- // so the client would just see them
510
- // as unfulfilled data.
465
+ case "error":
466
+ /**
467
+ * Let's cache the error!
468
+ *
469
+ * NOTE: This only caches when we're
470
+ * server side.
471
+ */
472
+ cacheError(requestKey, result.error, options.hydrate);
473
+ break;
474
+ } // For status === "loading":
475
+ // Could never get here unless we wrote
476
+ // the code wrong. Rather than bloat
477
+ // code with useless error, just ignore.
478
+ // For status === "aborted":
479
+ // We won't cache this.
480
+ // We don't hydrate aborted requests,
481
+ // so the client would just see them
482
+ // as unfulfilled data.
511
483
 
512
484
 
513
485
  return;
@@ -579,105 +551,253 @@ class RequestTracker {
579
551
  }
580
552
 
581
553
  /***/ }),
582
- /* 8 */
554
+ /* 9 */
583
555
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
584
556
 
585
557
  "use strict";
586
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return clearSharedCache; });
587
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return useSharedCache; });
588
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
589
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
590
- /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
591
- /* harmony import */ var _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
592
-
593
-
558
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SsrCache; });
559
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
560
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
561
+ /* harmony import */ var _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13);
594
562
 
595
563
 
564
+ const DefaultScope = "default";
596
565
  /**
597
- * This is the cache.
598
- * It's incredibly complex.
599
- * Very in-memory. So cache. Such complex. Wow.
600
- */
601
- const cache = new _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__[/* ScopedInMemoryCache */ "a"]();
602
- /**
603
- * Clear the in-memory cache or a single scope within it.
566
+ * The default instance is stored here.
567
+ * It's created below in the Default() static property.
604
568
  */
605
569
 
606
- const clearSharedCache = (scope = "") => {
607
- // If we have a valid scope (empty string is falsy), then clear that scope.
608
- if (scope && typeof scope === "string") {
609
- cache.purgeScope(scope);
610
- } else {
611
- // Just reset the object. This should be sufficient.
612
- cache.purgeAll();
613
- }
614
- };
570
+ let _default;
615
571
  /**
616
- * Hook to retrieve data from and store data in an in-memory cache.
617
- *
618
- * @returns {[?ReadOnlyCacheValue, CacheValueFn]}
619
- * Returns an array containing the current cache entry (or undefined), a
620
- * function to set the cache entry (passing null or undefined to this function
621
- * will delete the entry).
622
- *
623
- * To clear a single scope within the cache or the entire cache,
624
- * the `clearScopedCache` export is available.
572
+ * Implements the response cache.
625
573
  *
626
- * NOTE: Unlike useState or useReducer, we don't automatically update folks
627
- * if the value they reference changes. We might add it later (if we need to),
628
- * but the likelihood here is that things won't be changing in this cache in a
629
- * way where we would need that. If we do (and likely only in specific
630
- * circumstances), we should consider adding a simple boolean useState that can
631
- * be toggled to cause a rerender whenever the referenced cached data changes
632
- * so that callers can re-render on cache changes. However, we should make
633
- * sure this toggling is optional - or we could use a callback argument, to
634
- * achieve this on an as-needed basis.
574
+ * INTERNAL USE ONLY
635
575
  */
636
576
 
637
- const useSharedCache = (id, scope, initialValue) => {
638
- // Verify arguments.
639
- if (!id || typeof id !== "string") {
640
- throw new _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataError */ "a"]("id must be a non-empty string", _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataErrors */ "b"].InvalidInput);
641
- }
642
-
643
- if (!scope || typeof scope !== "string") {
644
- throw new _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataError */ "a"]("scope must be a non-empty string", _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataErrors */ "b"].InvalidInput);
645
- } // Memoize our APIs.
646
- // This one allows callers to set or replace the cached value.
647
577
 
578
+ class SsrCache {
579
+ static get Default() {
580
+ if (!_default) {
581
+ _default = new SsrCache();
582
+ }
648
583
 
649
- const cacheValue = react__WEBPACK_IMPORTED_MODULE_0__["useCallback"](value => value == null ? cache.purge(scope, id) : cache.set(scope, id, value), [id, scope]); // We don't memo-ize the current value, just in case the cache was updated
650
- // since our last run through. Also, our cache does not know what type it
651
- // stores, so we have to cast it to the type we're exporting. This is a
652
- // dev time courtesy, rather than a runtime thing.
653
- // $FlowIgnore[incompatible-type]
584
+ return _default;
585
+ }
654
586
 
655
- let currentValue = cache.get(scope, id); // If we have an initial value, we need to add it to the cache
656
- // and use it as our current value.
587
+ constructor(hydrationCache = null, ssrOnlyCache = null) {
588
+ this.initialize = source => {
589
+ if (this._hydrationCache.inUse) {
590
+ throw new Error("Cannot initialize data response cache more than once");
591
+ }
657
592
 
658
- if (currentValue == null && initialValue !== undefined) {
659
- // Get the initial value.
660
- const value = typeof initialValue === "function" ? initialValue() : initialValue;
593
+ this._hydrationCache = new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]({
594
+ // $FlowIgnore[incompatible-call]
595
+ [DefaultScope]: source
596
+ });
597
+ };
661
598
 
662
- if (value != null) {
663
- // Update the cache.
664
- cacheValue(value); // Make sure we return this value as our current value.
599
+ this.cacheData = (id, data, hydrate) => this._setCachedResponse(id, {
600
+ data
601
+ }, hydrate);
665
602
 
666
- currentValue = value;
667
- }
668
- } // Now we have everything, let's return it.
603
+ this.cacheError = (id, error, hydrate) => {
604
+ const errorMessage = typeof error === "string" ? error : error.message;
605
+ return this._setCachedResponse(id, {
606
+ error: errorMessage
607
+ }, hydrate);
608
+ };
669
609
 
610
+ this.getEntry = id => {
611
+ var _this$_ssrOnlyCache$g, _this$_ssrOnlyCache;
612
+
613
+ // Get the cached entry for this value.
614
+ // We first look in the ssr cache and then the hydration cache.
615
+ const internalEntry = (_this$_ssrOnlyCache$g = (_this$_ssrOnlyCache = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache.get(DefaultScope, id)) != null ? _this$_ssrOnlyCache$g : this._hydrationCache.get(DefaultScope, id); // If we are not server-side and we hydrated something, let's clear
616
+ // that from the hydration cache to save memory.
617
+
618
+ if (this._ssrOnlyCache == null && internalEntry != null) {
619
+ // We now delete this from our hydration cache as we don't need it.
620
+ // This does mean that if another handler of the same type but
621
+ // without some sort of linked cache won't get the value, but
622
+ // that's not an expected use-case. If two different places use the
623
+ // same handler and options (i.e. the same request), then the
624
+ // handler should cater to that to ensure they share the result.
625
+ this._hydrationCache.purge(DefaultScope, id);
626
+ } // Getting the typing right between the in-memory cache and this
627
+ // is hard. Just telling flow it's OK.
628
+ // $FlowIgnore[incompatible-return]
629
+
630
+
631
+ return internalEntry;
632
+ };
633
+
634
+ this.purgeData = predicate => {
635
+ var _this$_ssrOnlyCache2;
636
+
637
+ const realPredicate = predicate ? // We know what we're putting into the cache so let's assume it
638
+ // conforms.
639
+ // $FlowIgnore[incompatible-call]
640
+ (_, key, cachedEntry) => predicate(key, cachedEntry) : undefined; // Apply the predicate to what we have in our caches.
641
+
642
+ this._hydrationCache.purgeAll(realPredicate);
643
+
644
+ (_this$_ssrOnlyCache2 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache2.purgeAll(realPredicate);
645
+ };
646
+
647
+ this.cloneHydratableData = () => {
648
+ var _cache$DefaultScope;
649
+
650
+ // We return our hydration cache only.
651
+ const cache = this._hydrationCache.clone(); // If we're empty, we still want to return an object, so we default
652
+ // to an empty object.
653
+ // We only need the default scope out of our scoped in-memory cache.
654
+ // We know that it conforms to our expectations.
655
+ // $FlowIgnore[incompatible-return]
656
+
657
+
658
+ return (_cache$DefaultScope = cache[DefaultScope]) != null ? _cache$DefaultScope : {};
659
+ };
660
+
661
+ // The default instance gets made on first reference and if that happens
662
+ // before server-side mode is turned on, the Default instance would
663
+ // never have an SSR-only cache instance, which would then mean that if
664
+ // server-side mode got turned on, it wouldn't work right.
665
+ // This should only be an issue of surprise during testing, so, let's
666
+ // always have an instance in that circumstance.
667
+ this._ssrOnlyCache = false || _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() ? ssrOnlyCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]() : undefined;
668
+ this._hydrationCache = hydrationCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]();
669
+ }
670
+
671
+ _setCachedResponse(id, entry, hydrate) {
672
+ const frozenEntry = Object.freeze(entry);
673
+
674
+ if (_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
675
+ // We are server-side.
676
+ // We need to store this value.
677
+ if (hydrate) {
678
+ this._hydrationCache.set(DefaultScope, id, frozenEntry);
679
+ } else {
680
+ var _this$_ssrOnlyCache3;
681
+
682
+ // Usually, when server-side, this cache will always be present.
683
+ // We do fake server-side in our doc example though, when it
684
+ // won't be.
685
+ (_this$_ssrOnlyCache3 = this._ssrOnlyCache) == null ? void 0 : _this$_ssrOnlyCache3.set(DefaultScope, id, frozenEntry);
686
+ }
687
+ }
688
+
689
+ return frozenEntry;
690
+ }
691
+ /**
692
+ * Initialize the cache from a given cache state.
693
+ *
694
+ * This can only be called if the cache is not already in use.
695
+ */
670
696
 
671
- return [currentValue, cacheValue];
672
- };
697
+
698
+ }
673
699
 
674
700
  /***/ }),
675
- /* 9 */
701
+ /* 10 */
702
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
703
+
704
+ "use strict";
705
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestFulfillment; });
706
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
707
+
708
+
709
+ let _default;
710
+ /**
711
+ * This fulfills a request, making sure that in-flight requests are shared.
712
+ */
713
+
714
+
715
+ class RequestFulfillment {
716
+ constructor() {
717
+ this._requests = {};
718
+
719
+ this.fulfill = (id, {
720
+ handler,
721
+ hydrate = true
722
+ }) => {
723
+ /**
724
+ * If we have an inflight request, we'll provide that.
725
+ */
726
+ const inflight = this._requests[id];
727
+
728
+ if (inflight) {
729
+ return inflight;
730
+ }
731
+ /**
732
+ * We don't have an inflight request, so let's set one up.
733
+ */
734
+
735
+
736
+ const request = handler().then(data => ({
737
+ status: "success",
738
+ data
739
+ })).catch(error => {
740
+ const actualError = typeof error === "string" ? new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Request failed", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Unknown, {
741
+ metadata: {
742
+ unexpectedError: error
743
+ }
744
+ }) : error; // Return aborted result if the request was aborted.
745
+ // The only way to detect this reliably, it seems, is to
746
+ // check the error name and see if it's "AbortError" (this
747
+ // is also what Apollo does).
748
+ // Even then, it's reliant on the handler supporting aborts.
749
+ // TODO(somewhatabstract, FEI-4276): Add first class abort
750
+ // support to the handler API.
751
+
752
+ if (actualError.name === "AbortError") {
753
+ return {
754
+ status: "aborted"
755
+ };
756
+ }
757
+
758
+ return {
759
+ status: "error",
760
+ error: actualError
761
+ };
762
+ }).finally(() => {
763
+ delete this._requests[id];
764
+ }); // Store the request in our cache.
765
+
766
+ this._requests[id] = request;
767
+ return request;
768
+ };
769
+
770
+ this.abort = id => {
771
+ // TODO(somewhatabstract, FEI-4276): Add first class abort
772
+ // support to the handler API.
773
+ // For now, we will just clear the request out of the list.
774
+ // When abort is implemented, the `finally` in the `fulfill` method
775
+ // would handle the deletion.
776
+ delete this._requests[id];
777
+ };
778
+
779
+ this.abortAll = () => {
780
+ Object.keys(this._requests).forEach(id => this.abort(id));
781
+ };
782
+ }
783
+
784
+ static get Default() {
785
+ if (!_default) {
786
+ _default = new RequestFulfillment();
787
+ }
788
+
789
+ return _default;
790
+ }
791
+
792
+ }
793
+
794
+ /***/ }),
795
+ /* 11 */
676
796
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
677
797
 
678
798
  "use strict";
679
799
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ScopedInMemoryCache; });
680
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
800
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
681
801
 
682
802
 
683
803
  /**
@@ -796,107 +916,32 @@ class ScopedInMemoryCache {
796
916
  }
797
917
 
798
918
  /***/ }),
799
- /* 10 */
800
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
801
-
802
- "use strict";
803
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestFulfillment; });
804
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
805
-
806
-
807
- let _default;
808
- /**
809
- * This fulfills a request, making sure that in-flight requests are shared.
810
- */
811
-
812
-
813
- class RequestFulfillment {
814
- constructor() {
815
- this._requests = {};
816
-
817
- this.fulfill = (id, {
818
- handler,
819
- hydrate = true
820
- }) => {
821
- /**
822
- * If we have an inflight request, we'll provide that.
823
- */
824
- const inflight = this._requests[id];
825
-
826
- if (inflight) {
827
- return inflight;
828
- }
829
- /**
830
- * We don't have an inflight request, so let's set one up.
831
- */
832
-
833
-
834
- const request = handler().then(data => ({
835
- status: "success",
836
- data
837
- })).catch(error => {
838
- const actualError = typeof error === "string" ? new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Request failed", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Unknown, {
839
- metadata: {
840
- unexpectedError: error
841
- }
842
- }) : error; // Return aborted result if the request was aborted.
843
- // The only way to detect this reliably, it seems, is to
844
- // check the error name and see if it's "AbortError" (this
845
- // is also what Apollo does).
846
- // Even then, it's reliant on the handler supporting aborts.
847
- // TODO(somewhatabstract, FEI-4276): Add first class abort
848
- // support to the handler API.
849
-
850
- if (actualError.name === "AbortError") {
851
- return {
852
- status: "aborted"
853
- };
854
- }
855
-
856
- return {
857
- status: "error",
858
- error: actualError
859
- };
860
- }).finally(() => {
861
- delete this._requests[id];
862
- }); // Store the request in our cache.
863
-
864
- this._requests[id] = request;
865
- return request;
866
- };
867
- }
868
-
869
- static get Default() {
870
- if (!_default) {
871
- _default = new RequestFulfillment();
872
- }
873
-
874
- return _default;
875
- }
876
-
877
- }
878
-
879
- /***/ }),
880
- /* 11 */
919
+ /* 12 */
881
920
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
882
921
 
883
922
  "use strict";
884
923
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return WhenClientSide; });
885
924
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return useHydratableEffect; });
886
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
925
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
887
926
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
888
- /* harmony import */ var _use_server_effect_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14);
889
- /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
890
- /* harmony import */ var _use_cached_effect_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(15);
927
+ /* harmony import */ var _use_server_effect_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(16);
928
+ /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5);
929
+ /* harmony import */ var _use_cached_effect_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(17);
930
+ /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(2);
891
931
 
892
932
 
893
933
 
934
+ // TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
935
+ // have fixed:
936
+ // https://github.com/import-js/eslint-plugin-import/issues/2073
937
+ // eslint-disable-next-line import/named
938
+
894
939
 
895
940
 
896
941
  /**
897
942
  * Policies to define how a hydratable effect should behave client-side.
898
943
  */
899
- const WhenClientSide = __webpack_require__(28).Mirrored(["DoNotHydrate", "ExecuteWhenNoResult", "ExecuteWhenNoSuccessResult", "AlwaysExecute"]);
944
+ const WhenClientSide = __webpack_require__(22).Mirrored(["DoNotHydrate", "ExecuteWhenNoResult", "ExecuteWhenNoSuccessResult", "AlwaysExecute"]);
900
945
  const DefaultScope = "useHydratableEffect";
901
946
  /**
902
947
  * Hook to execute an async operation on server and client.
@@ -968,11 +1013,13 @@ const useHydratableEffect = (requestId, handler, options = {}) => {
968
1013
  scope, // The scope of the cached items
969
1014
  getDefaultCacheValue); // When we're client-side, we ultimately want the result from this call.
970
1015
 
971
- const clientResult = Object(_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_3__[/* useCachedEffect */ "a"])(requestId, handler, {
1016
+ const [clientResult] = Object(_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_3__[/* useCachedEffect */ "a"])(requestId, handler, {
972
1017
  skip,
973
1018
  onResultChanged,
974
1019
  retainResultOnChange,
975
- scope
1020
+ scope,
1021
+ // Be explicit about our fetch policy for clarity.
1022
+ fetchPolicy: _util_types_js__WEBPACK_IMPORTED_MODULE_4__[/* FetchPolicy */ "a"].CacheBeforeNetwork
976
1023
  }); // OK, now which result do we return.
977
1024
  // Well, we return the serverResult on our very first call and then
978
1025
  // the clientResult thereafter. The great thing is that after the very
@@ -982,15 +1029,15 @@ const useHydratableEffect = (requestId, handler, options = {}) => {
982
1029
  };
983
1030
 
984
1031
  /***/ }),
985
- /* 12 */
1032
+ /* 13 */
986
1033
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
987
1034
 
988
1035
  "use strict";
989
1036
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SerializableInMemoryCache; });
990
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
1037
+ /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
991
1038
  /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__);
992
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
993
- /* harmony import */ var _scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
1039
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1040
+ /* harmony import */ var _scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
994
1041
 
995
1042
 
996
1043
 
@@ -1032,11 +1079,11 @@ class SerializableInMemoryCache extends _scoped_in_memory_cache_js__WEBPACK_IMPO
1032
1079
  }
1033
1080
 
1034
1081
  /***/ }),
1035
- /* 13 */
1082
+ /* 14 */
1036
1083
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1037
1084
 
1038
1085
  "use strict";
1039
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1086
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1040
1087
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1041
1088
 
1042
1089
 
@@ -1049,23 +1096,51 @@ const InterceptContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["create
1049
1096
  /* harmony default export */ __webpack_exports__["a"] = (InterceptContext);
1050
1097
 
1051
1098
  /***/ }),
1052
- /* 14 */
1099
+ /* 15 */
1053
1100
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1054
1101
 
1055
1102
  "use strict";
1056
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useServerEffect; });
1057
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
1058
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1059
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1060
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1061
- /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7);
1062
- /* harmony import */ var _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5);
1063
- /* harmony import */ var _util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(24);
1064
- /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(16);
1065
-
1066
-
1067
-
1068
-
1103
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return initializeHydrationCache; });
1104
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return purgeHydrationCache; });
1105
+ /* harmony import */ var _ssr_cache_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9);
1106
+
1107
+
1108
+ /**
1109
+ * Initialize the hydration cache.
1110
+ *
1111
+ * @param {ResponseCache} source The cache content to use for initializing the
1112
+ * cache.
1113
+ * @throws {Error} If the cache is already initialized.
1114
+ */
1115
+ const initializeHydrationCache = source => _ssr_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* SsrCache */ "a"].Default.initialize(source);
1116
+ /**
1117
+ * Purge cached hydration responses that match the given predicate.
1118
+ *
1119
+ * @param {(id: string) => boolean} [predicate] The predicate to match against
1120
+ * the cached hydration responses. If no predicate is provided, all cached
1121
+ * hydration responses will be purged.
1122
+ */
1123
+
1124
+ const purgeHydrationCache = predicate => _ssr_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* SsrCache */ "a"].Default.purgeData(predicate);
1125
+
1126
+ /***/ }),
1127
+ /* 16 */
1128
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1129
+
1130
+ "use strict";
1131
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useServerEffect; });
1132
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
1133
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1134
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
1135
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1136
+ /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
1137
+ /* harmony import */ var _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9);
1138
+ /* harmony import */ var _util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(32);
1139
+ /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(19);
1140
+
1141
+
1142
+
1143
+
1069
1144
 
1070
1145
 
1071
1146
 
@@ -1112,24 +1187,32 @@ const useServerEffect = (requestId, handler, options = {}) => {
1112
1187
  };
1113
1188
 
1114
1189
  /***/ }),
1115
- /* 15 */
1190
+ /* 17 */
1116
1191
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1117
1192
 
1118
1193
  "use strict";
1119
1194
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useCachedEffect; });
1120
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1195
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1121
1196
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1122
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
1197
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
1123
1198
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
1124
- /* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
1125
- /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
1126
- /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8);
1127
- /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(16);
1199
+ /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(0);
1200
+ /* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
1201
+ /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
1202
+ /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(5);
1203
+ /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(19);
1204
+ /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(2);
1205
+
1206
+
1128
1207
 
1129
1208
 
1130
1209
 
1131
1210
 
1132
1211
 
1212
+ // TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
1213
+ // have fixed:
1214
+ // https://github.com/import-js/eslint-plugin-import/issues/2073
1215
+ // eslint-disable-next-line import/named
1133
1216
 
1134
1217
  const DefaultScope = "useCachedEffect";
1135
1218
  /**
@@ -1150,7 +1233,10 @@ const DefaultScope = "useCachedEffect";
1150
1233
  */
1151
1234
 
1152
1235
  const useCachedEffect = (requestId, handler, options = {}) => {
1236
+ var _ref;
1237
+
1153
1238
  const {
1239
+ fetchPolicy = _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork,
1154
1240
  skip: hardSkip = false,
1155
1241
  retainResultOnChange = false,
1156
1242
  onResultChanged,
@@ -1158,124 +1244,263 @@ const useCachedEffect = (requestId, handler, options = {}) => {
1158
1244
  } = options; // Plug in to the request interception framework for code that wants
1159
1245
  // to use that.
1160
1246
 
1161
- const interceptedHandler = Object(_use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__[/* useRequestInterception */ "a"])(requestId, handler); // Instead of using state, which would be local to just this hook instance,
1247
+ const interceptedHandler = Object(_use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__[/* useRequestInterception */ "a"])(requestId, handler); // Instead of using state, which would be local to just this hook instance,
1162
1248
  // we use a shared in-memory cache.
1163
1249
 
1164
- const [mostRecentResult, setMostRecentResult] = Object(_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_4__[/* useSharedCache */ "b"])(requestId, // The key of the cached item
1250
+ const [mostRecentResult, setMostRecentResult] = Object(_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_5__[/* useSharedCache */ "b"])(requestId, // The key of the cached item
1165
1251
  scope // The scope of the cached items
1166
1252
  // No default value. We don't want the loading status there; to ensure
1167
1253
  // that all calls when the request is in-flight will update once that
1168
1254
  // request is done, we want the cache to be empty until that point.
1169
- ); // Build a function that will update the cache and either invoke the
1170
- // callback provided in options, or force an update.
1171
-
1172
- const forceUpdate = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["useForceUpdate"])();
1173
- const setCacheAndNotify = react__WEBPACK_IMPORTED_MODULE_0__["useCallback"](value => {
1174
- setMostRecentResult(value); // If our caller provided a cacheUpdated callback, we use that.
1175
- // Otherwise, we toggle our little state update.
1176
-
1177
- if (onResultChanged != null) {
1178
- onResultChanged(value);
1179
- } else {
1180
- forceUpdate();
1181
- }
1182
- }, [setMostRecentResult, onResultChanged, forceUpdate]); // We need to trigger a re-render when the request ID changes as that
1183
- // indicates its a different request. We don't default the current id as
1184
- // this is a proxy for the first render, where we will make the request
1185
- // if we don't already have a cached value.
1186
-
1187
- const requestIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"]();
1188
- const previousRequestId = requestIdRef.current; // Calculate our soft skip state.
1189
- // Soft skip changes are things that should skip the effect if something
1190
- // else triggers the effect to run, but should not itself trigger the effect
1191
- // (which would cancel a previous invocation).
1192
-
1193
- const softSkip = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"](() => {
1194
- if (requestId === previousRequestId) {
1195
- // If the requestId is unchanged, it means we already rendered at
1196
- // least once and so we already made the request at least once. So
1197
- // we can bail out right here.
1198
- return true;
1199
- } // If we already have a cached value, we're going to skip.
1200
-
1201
-
1202
- if (mostRecentResult != null) {
1203
- return true;
1255
+ );
1256
+ const forceUpdate = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["useForceUpdate"])(); // For the NetworkOnly fetch policy, we ignore the cached value.
1257
+ // So we need somewhere else to store the network value.
1258
+
1259
+ const networkResultRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](); // Set up the function that will do the fetching.
1260
+
1261
+ const currentRequestRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"]();
1262
+ const fetchRequest = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"](() => {
1263
+ var _currentRequestRef$cu;
1264
+
1265
+ // We aren't using useCallback here because we need to make sure that
1266
+ // if we are rememo-izing, we cancel any inflight request for the old
1267
+ // callback.
1268
+ (_currentRequestRef$cu = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu.cancel();
1269
+ currentRequestRef.current = null;
1270
+ networkResultRef.current = null;
1271
+
1272
+ const fetchFn = () => {
1273
+ var _currentRequestRef$cu2, _currentRequestRef$cu3;
1274
+
1275
+ if (fetchPolicy === _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheOnly) {
1276
+ throw new _util_data_error_js__WEBPACK_IMPORTED_MODULE_2__[/* DataError */ "a"]("Cannot fetch with CacheOnly policy", _util_data_error_js__WEBPACK_IMPORTED_MODULE_2__[/* DataErrors */ "b"].NotAllowed);
1277
+ } // We use our request fulfillment here so that in-flight
1278
+ // requests are shared. In order to ensure that we don't share
1279
+ // in-flight requests for different scopes, we add the scope to the
1280
+ // requestId.
1281
+ // We do this as a courtesy to simplify usage in sandboxed
1282
+ // uses like storybook where we want each story to perform their
1283
+ // own requests from scratch and not share inflight requests across
1284
+ // stories.
1285
+ // Since this only occurs here, nothing else will care about this
1286
+ // change except the request tracking.
1287
+
1288
+
1289
+ const request = _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__[/* RequestFulfillment */ "a"].Default.fulfill(`${requestId}|${scope}`, {
1290
+ handler: interceptedHandler
1291
+ });
1292
+
1293
+ if (request === ((_currentRequestRef$cu2 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu2.request)) {
1294
+ // The request inflight is the same, so do nothing.
1295
+ // NOTE: Perhaps if invoked via a refetch, we will want to
1296
+ // override this behavior and force a new request?
1297
+ return;
1298
+ } // Clear the last network result.
1299
+
1300
+
1301
+ networkResultRef.current = null; // Cancel the previous request.
1302
+
1303
+ (_currentRequestRef$cu3 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu3.cancel(); // TODO(somewhatabstract, FEI-4276):
1304
+ // Until our RequestFulfillment API supports cancelling/aborting, we
1305
+ // will have to do it.
1306
+
1307
+ let cancel = false; // NOTE: Our request fulfillment handles the error cases here.
1308
+ // Catching shouldn't serve a purpose.
1309
+ // eslint-disable-next-line promise/catch-or-return
1310
+
1311
+ request.then(result => {
1312
+ currentRequestRef.current = null;
1313
+
1314
+ if (cancel) {
1315
+ // We don't modify our result if the request was cancelled
1316
+ // as it means that this hook no longer cares about that old
1317
+ // request.
1318
+ return;
1319
+ } // Now we need to update the cache and notify or force a rerender.
1320
+
1321
+
1322
+ setMostRecentResult(result);
1323
+ networkResultRef.current = result;
1324
+
1325
+ if (onResultChanged != null) {
1326
+ // If we have a callback, call it to let our caller know we
1327
+ // got a result.
1328
+ onResultChanged(result);
1329
+ } else {
1330
+ // If there's no callback, and this is using cache in some
1331
+ // capacity, just force a rerender.
1332
+ forceUpdate();
1333
+ }
1334
+
1335
+ return; // Shut up eslint always-return rule.
1336
+ });
1337
+ currentRequestRef.current = {
1338
+ requestId,
1339
+ request,
1340
+
1341
+ cancel() {
1342
+ cancel = true;
1343
+ _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__[/* RequestFulfillment */ "a"].Default.abort(requestId);
1344
+ }
1345
+
1346
+ };
1347
+ }; // Now we can return the new fetch function.
1348
+
1349
+
1350
+ return fetchFn; // We deliberately ignore the handler here because we want folks to use
1351
+ // interceptor functions inline in props for simplicity. This is OK
1352
+ // since changing the handler without changing the requestId doesn't
1353
+ // really make sense - the same requestId should be handled the same as
1354
+ // each other.
1355
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1356
+ }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // We need to trigger a re-render when the request ID changes as that
1357
+ // indicates its a different request.
1358
+
1359
+ const requestIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](requestId); // Calculate if we want to fetch the result or not.
1360
+ // If this is true, we will do a new fetch, cancelling the previous fetch
1361
+ // if there is one inflight.
1362
+
1363
+ const shouldFetch = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"](() => {
1364
+ if (hardSkip) {
1365
+ // We don't fetch if we've been told to hard skip.
1366
+ return false;
1204
1367
  }
1205
1368
 
1206
- return false;
1207
- }, [requestId, previousRequestId, mostRecentResult]); // So now we make sure the client-side request happens per our various
1208
- // options.
1369
+ switch (fetchPolicy) {
1370
+ case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheOnly:
1371
+ // Don't want to do a network request if we're only
1372
+ // interested in the cache.
1373
+ return false;
1374
+
1375
+ case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork:
1376
+ // If we don't have a cached value or this is a new requestId,
1377
+ // then we need to fetch.
1378
+ return mostRecentResult == null || requestId !== requestIdRef.current;
1209
1379
 
1380
+ case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheAndNetwork:
1381
+ case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly:
1382
+ // We don't care about the cache. If we don't have a network
1383
+ // result, then we need to fetch one.
1384
+ return networkResultRef.current == null;
1385
+ }
1386
+ }, [requestId, mostRecentResult, fetchPolicy, hardSkip]); // Let's make sure our ref is set to the most recent requestId.
1387
+
1388
+ requestIdRef.current = requestId;
1210
1389
  react__WEBPACK_IMPORTED_MODULE_0__["useEffect"](() => {
1211
- let cancel = false; // We don't do anything if we've been told to hard skip (a hard skip
1212
- // means we should cancel the previous request and is therefore a
1213
- // dependency on that), or we have determined we have already done
1214
- // enough and can soft skip (a soft skip doesn't trigger the request
1215
- // to re-run; we don't want to cancel the in progress effect if we're
1216
- // soft skipping.
1217
-
1218
- if (hardSkip || softSkip) {
1390
+ if (!shouldFetch) {
1219
1391
  return;
1220
- } // If we got here, we're going to perform the request.
1221
- // Let's make sure our ref is set to the most recent requestId.
1222
-
1223
-
1224
- requestIdRef.current = requestId; // OK, we've done all our checks and things. It's time to make the
1225
- // request. We use our request fulfillment here so that in-flight
1226
- // requests are shared.
1227
- // NOTE: Our request fulfillment handles the error cases here.
1228
- // Catching shouldn't serve a purpose.
1229
- // eslint-disable-next-line promise/catch-or-return
1230
-
1231
- _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestFulfillment */ "a"].Default.fulfill(requestId, {
1232
- handler: interceptedHandler
1233
- }).then(result => {
1234
- if (cancel) {
1235
- // We don't modify our result if an earlier effect was
1236
- // cancelled as it means that this hook no longer cares about
1237
- // that old request.
1238
- return;
1239
- }
1392
+ }
1240
1393
 
1241
- setCacheAndNotify(result);
1242
- return; // Shut up eslint always-return rule.
1243
- });
1394
+ fetchRequest();
1244
1395
  return () => {
1245
- // TODO(somewhatabstract, FEI-4276): Eventually, we will want to be
1246
- // able abort in-flight requests, but for now, we don't have that.
1247
- // (Of course, we will only want to abort them if no one is waiting
1248
- // on them)
1249
- // For now, we just block cancelled requests from changing our
1250
- // cache.
1251
- cancel = true;
1252
- }; // We only want to run this effect if the requestId, or skip values
1253
- // change. These are the only two things that should affect the
1254
- // cancellation of a pending request. We do not update if the handler
1255
- // changes, in order to simplify the API - otherwise, callers would
1256
- // not be able to use inline functions with this hook.
1257
- // eslint-disable-next-line react-hooks/exhaustive-deps
1258
- }, [hardSkip, requestId]); // We track the last result we returned in order to support the
1396
+ var _currentRequestRef$cu4;
1397
+
1398
+ (_currentRequestRef$cu4 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu4.cancel();
1399
+ currentRequestRef.current = null;
1400
+ };
1401
+ }, [shouldFetch, fetchRequest]); // We track the last result we returned in order to support the
1259
1402
  // "retainResultOnChange" option.
1260
1403
 
1261
- const lastResultAgnosticOfIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](_util_status_js__WEBPACK_IMPORTED_MODULE_3__[/* Status */ "a"].loading());
1262
- const loadingResult = retainResultOnChange ? lastResultAgnosticOfIdRef.current : _util_status_js__WEBPACK_IMPORTED_MODULE_3__[/* Status */ "a"].loading(); // Loading is a transient state, so we only use it here; it's not something
1404
+ const lastResultAgnosticOfIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](_util_status_js__WEBPACK_IMPORTED_MODULE_4__[/* Status */ "a"].loading());
1405
+ const loadingResult = retainResultOnChange ? lastResultAgnosticOfIdRef.current : _util_status_js__WEBPACK_IMPORTED_MODULE_4__[/* Status */ "a"].loading(); // Loading is a transient state, so we only use it here; it's not something
1263
1406
  // we cache.
1264
1407
 
1265
- const result = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"](() => mostRecentResult != null ? mostRecentResult : loadingResult, [mostRecentResult, loadingResult]);
1266
- lastResultAgnosticOfIdRef.current = result;
1267
- return result;
1408
+ const result = (_ref = fetchPolicy === _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly ? networkResultRef.current : mostRecentResult) != null ? _ref : loadingResult;
1409
+ lastResultAgnosticOfIdRef.current = result; // We return the result and a function for triggering a refetch.
1410
+
1411
+ return [result, fetchRequest];
1268
1412
  };
1269
1413
 
1270
1414
  /***/ }),
1271
- /* 16 */
1415
+ /* 18 */
1416
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1417
+
1418
+ "use strict";
1419
+ /* unused harmony export DocumentTypes */
1420
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return graphQLDocumentNodeParser; });
1421
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1422
+
1423
+ const DocumentTypes = Object.freeze({
1424
+ query: "query",
1425
+ mutation: "mutation"
1426
+ });
1427
+ const cache = new Map();
1428
+ /**
1429
+ * Parse a GraphQL document node to determine some info about it.
1430
+ *
1431
+ * This is based on:
1432
+ * https://github.com/apollographql/react-apollo/blob/3bc993b2ea91704bd6a2667f42d1940656c071ff/src/parser.ts
1433
+ */
1434
+
1435
+ function graphQLDocumentNodeParser(document) {
1436
+ var _definition$name;
1437
+
1438
+ const cached = cache.get(document);
1439
+
1440
+ if (cached) {
1441
+ return cached;
1442
+ }
1443
+ /**
1444
+ * Saftey check for proper usage.
1445
+ */
1446
+
1447
+
1448
+ if (!(document != null && document.kind)) {
1449
+ if (true) {
1450
+ throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Bad DocumentNode", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1451
+ } else {}
1452
+ }
1453
+
1454
+ const fragments = document.definitions.filter(x => x.kind === "FragmentDefinition");
1455
+ const queries = document.definitions.filter(x => // $FlowIgnore[prop-missing]
1456
+ x.kind === "OperationDefinition" && x.operation === "query");
1457
+ const mutations = document.definitions.filter(x => // $FlowIgnore[prop-missing]
1458
+ x.kind === "OperationDefinition" && x.operation === "mutation");
1459
+ const subscriptions = document.definitions.filter(x => // $FlowIgnore[prop-missing]
1460
+ x.kind === "OperationDefinition" && x.operation === "subscription");
1461
+
1462
+ if (fragments.length && !queries.length && !mutations.length) {
1463
+ if (true) {
1464
+ throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Fragment only", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1465
+ } else {}
1466
+ }
1467
+
1468
+ if (subscriptions.length) {
1469
+ if (true) {
1470
+ throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("No subscriptions", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1471
+ } else {}
1472
+ }
1473
+
1474
+ if (queries.length + mutations.length > 1) {
1475
+ if (true) {
1476
+ throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Too many ops", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1477
+ } else {}
1478
+ }
1479
+
1480
+ const type = queries.length ? DocumentTypes.query : DocumentTypes.mutation;
1481
+ const definitions = queries.length ? queries : mutations;
1482
+ const definition = definitions[0];
1483
+ const variables = definition.variableDefinitions || []; // fallback to using data if no name
1484
+
1485
+ const name = ((_definition$name = definition.name) == null ? void 0 : _definition$name.kind) === "Name" ? definition.name.value : "data";
1486
+ const payload = {
1487
+ name,
1488
+ type,
1489
+ variables
1490
+ };
1491
+ cache.set(document, payload);
1492
+ return payload;
1493
+ }
1494
+
1495
+ /***/ }),
1496
+ /* 19 */
1272
1497
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1273
1498
 
1274
1499
  "use strict";
1275
1500
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useRequestInterception; });
1276
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1501
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1277
1502
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1278
- /* harmony import */ var _components_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13);
1503
+ /* harmony import */ var _components_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14);
1279
1504
 
1280
1505
 
1281
1506
 
@@ -1313,67 +1538,289 @@ const useRequestInterception = (requestId, handler) => {
1313
1538
  // as our handler, so how can flow know? Let's just suppress that.
1314
1539
  // $FlowFixMe[incompatible-return]
1315
1540
 
1316
- return interceptResponse != null ? interceptResponse : handler();
1317
- }, [handler, interceptors, requestId]);
1318
- return interceptedHandler;
1541
+ return interceptResponse != null ? interceptResponse : handler();
1542
+ }, [handler, interceptors, requestId]);
1543
+ return interceptedHandler;
1544
+ };
1545
+
1546
+ /***/ }),
1547
+ /* 20 */
1548
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1549
+
1550
+ "use strict";
1551
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlRouterContext; });
1552
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1553
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1554
+
1555
+ const GqlRouterContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
1556
+
1557
+ /***/ }),
1558
+ /* 21 */
1559
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1560
+
1561
+ "use strict";
1562
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mergeGqlContext; });
1563
+ /**
1564
+ * Construct a complete GqlContext from current defaults and a partial context.
1565
+ *
1566
+ * Values in the partial context that are `undefined` will be ignored.
1567
+ * Values in the partial context that are `null` will be deleted.
1568
+ */
1569
+ const mergeGqlContext = (defaultContext, overrides) => {
1570
+ // Let's merge the partial context default context. We deliberately
1571
+ // don't spread because spreading would overwrite default context
1572
+ // values with undefined or null if the partial context includes a value
1573
+ // explicitly set to undefined or null.
1574
+ return Object.keys(overrides).reduce((acc, key) => {
1575
+ // Undefined values are ignored.
1576
+ if (overrides[key] !== undefined) {
1577
+ if (overrides[key] === null) {
1578
+ // Null indicates we delete this context value.
1579
+ delete acc[key];
1580
+ } else {
1581
+ // Otherwise, we set it.
1582
+ acc[key] = overrides[key];
1583
+ }
1584
+ }
1585
+
1586
+ return acc;
1587
+ }, { ...defaultContext
1588
+ });
1589
+ };
1590
+
1591
+ /***/ }),
1592
+ /* 22 */
1593
+ /***/ (function(module, exports, __webpack_require__) {
1594
+
1595
+ "use strict";
1596
+ /**
1597
+ * Copyright (c) Facebook, Inc. and its affiliates.
1598
+ *
1599
+ * This source code is licensed under the MIT license found in the
1600
+ * LICENSE file in the root directory of this source tree.
1601
+ */
1602
+
1603
+
1604
+
1605
+ // Below we want to use `hasOwnProperty` on an object that doesn't have
1606
+ // `Object.prototype` in its proto chain, so we must extract it here.
1607
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
1608
+
1609
+ // Map from an enum object to a reverse map of its values to names
1610
+ var reverseMapCache = typeof WeakMap === 'function' ? new WeakMap() : new Map();
1611
+
1612
+ // Computes the reverse mapping of the enum object: from value to name.
1613
+ // Flow Enum values are unique (enforced by the parser), so this is a
1614
+ // one to one mapping.
1615
+ function getReverseMap(enumObject) {
1616
+ var reverseMap = reverseMapCache.get(enumObject);
1617
+ if (reverseMap !== undefined) {
1618
+ return reverseMap;
1619
+ }
1620
+ // We aren't using `Object.values` because that gets enumerable
1621
+ // properties, and our properties aren't enumerable.
1622
+ var newReverseMap = new Map();
1623
+ Object.getOwnPropertyNames(enumObject).forEach(function (name) {
1624
+ newReverseMap.set(enumObject[name], name);
1625
+ });
1626
+ reverseMapCache.set(enumObject, newReverseMap);
1627
+ return newReverseMap;
1628
+ }
1629
+
1630
+ var EnumPrototype = Object.freeze(
1631
+ Object.defineProperties(Object.create(null), {
1632
+ isValid: {
1633
+ value: function (x) {
1634
+ return getReverseMap(this).has(x);
1635
+ },
1636
+ },
1637
+ cast: {
1638
+ value: function (x) {
1639
+ return this.isValid(x) ? x : undefined;
1640
+ },
1641
+ },
1642
+ members: {
1643
+ value: function () {
1644
+ return getReverseMap(this).keys();
1645
+ },
1646
+ },
1647
+ getName: {
1648
+ value: function (value) {
1649
+ return getReverseMap(this).get(value);
1650
+ }
1651
+ }
1652
+ })
1653
+ );
1654
+
1655
+ // `members` is an object mapping name to value.
1656
+ function Enum(members) {
1657
+ var o = Object.create(EnumPrototype);
1658
+ for (var k in members) {
1659
+ if (hasOwnProperty.call(members, k)) {
1660
+ // Create non-enumerable properties.
1661
+ Object.defineProperty(o, k, {value: members[k]});
1662
+ }
1663
+ }
1664
+ return Object.freeze(o);
1665
+ }
1666
+
1667
+ // Mirrored enum (string enum with no member initializers).
1668
+ // Optimized implementation, taking advantage of the fact that
1669
+ // keys and values are identical.
1670
+ var EnumMirroredPrototype = Object.freeze(
1671
+ Object.defineProperties(Object.create(null), {
1672
+ isValid: {
1673
+ value: function (x) {
1674
+ if (typeof x === 'string') {
1675
+ return hasOwnProperty.call(this, x);
1676
+ }
1677
+ return false;
1678
+ },
1679
+ },
1680
+ cast: {
1681
+ value: EnumPrototype.cast,
1682
+ },
1683
+ members: {
1684
+ value: function () {
1685
+ // We aren't using `Object.values` because that gets enumerable
1686
+ // properties, and our properties aren't enumerable.
1687
+ return Object.getOwnPropertyNames(this).values();
1688
+ },
1689
+ },
1690
+ getName: {
1691
+ value: function (value) {
1692
+ return value;
1693
+ }
1694
+ }
1695
+ })
1696
+ );
1697
+
1698
+ // `members` is an array of names (which, are also the values).
1699
+ Enum.Mirrored = function EnumMirrored(members) {
1700
+ var o = Object.create(EnumMirroredPrototype);
1701
+ for (var i = 0, len = members.length; i < len; ++i) {
1702
+ // Value is same as key. Also, non-enumerable.
1703
+ Object.defineProperty(o, members[i], {value: members[i]});
1704
+ }
1705
+ return Object.freeze(o);
1706
+ };
1707
+
1708
+ Object.freeze(Enum.Mirrored);
1709
+
1710
+ module.exports = Object.freeze(Enum);
1711
+
1712
+
1713
+ /***/ }),
1714
+ /* 23 */
1715
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1716
+
1717
+ "use strict";
1718
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return fetchTrackedRequests; });
1719
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return hasTrackedRequestsToBeFetched; });
1720
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return abortInflightRequests; });
1721
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
1722
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1723
+ /* harmony import */ var _request_tracking_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
1724
+ /* harmony import */ var _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
1725
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(0);
1726
+
1727
+
1728
+
1729
+
1730
+
1731
+ const SSRCheck = () => {
1732
+ if (_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
1733
+ return null;
1734
+ }
1735
+
1736
+ if (true) {
1737
+ return new _data_error_js__WEBPACK_IMPORTED_MODULE_3__[/* DataError */ "a"]("No CSR tracking", _data_error_js__WEBPACK_IMPORTED_MODULE_3__[/* DataErrors */ "b"].NotAllowed);
1738
+ } else {}
1739
+ };
1740
+ /**
1741
+ * Fetches all tracked data requests.
1742
+ *
1743
+ * This is for use with the `TrackData` component during server-side rendering.
1744
+ *
1745
+ * @throws {Error} If executed outside of server-side rendering.
1746
+ * @returns {Promise<void>} A promise that resolves when all tracked requests
1747
+ * have been fetched.
1748
+ */
1749
+
1750
+
1751
+ const fetchTrackedRequests = () => {
1752
+ const ssrCheck = SSRCheck();
1753
+
1754
+ if (ssrCheck != null) {
1755
+ return Promise.reject(ssrCheck);
1756
+ }
1757
+
1758
+ return _request_tracking_js__WEBPACK_IMPORTED_MODULE_1__[/* RequestTracker */ "a"].Default.fulfillTrackedRequests();
1319
1759
  };
1760
+ /**
1761
+ * Indicate if there are tracked requests waiting to be fetched.
1762
+ *
1763
+ * This is used in conjunction with `TrackData`.
1764
+ *
1765
+ * @throws {Error} If executed outside of server-side rendering.
1766
+ * @returns {boolean} `true` if there are unfetched tracked requests;
1767
+ * otherwise, `false`.
1768
+ */
1320
1769
 
1321
- /***/ }),
1322
- /* 17 */
1323
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1770
+ const hasTrackedRequestsToBeFetched = () => {
1771
+ const ssrCheck = SSRCheck();
1324
1772
 
1325
- "use strict";
1326
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlRouterContext; });
1327
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1328
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1773
+ if (ssrCheck != null) {
1774
+ throw ssrCheck;
1775
+ }
1329
1776
 
1330
- const GqlRouterContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
1777
+ return _request_tracking_js__WEBPACK_IMPORTED_MODULE_1__[/* RequestTracker */ "a"].Default.hasUnfulfilledRequests;
1778
+ };
1779
+ /**
1780
+ * Abort all in-flight requests.
1781
+ *
1782
+ * This aborts all requests currently inflight via our default request
1783
+ * fulfillment.
1784
+ */
1785
+
1786
+ const abortInflightRequests = () => {
1787
+ _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestFulfillment */ "a"].Default.abortAll();
1788
+ };
1331
1789
 
1332
1790
  /***/ }),
1333
- /* 18 */
1791
+ /* 24 */
1334
1792
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1335
1793
 
1336
1794
  "use strict";
1337
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mergeGqlContext; });
1795
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return purgeCaches; });
1796
+ /* harmony import */ var _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
1797
+ /* harmony import */ var _hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
1798
+
1799
+
1338
1800
  /**
1339
- * Construct a complete GqlContext from current defaults and a partial context.
1801
+ * Purge all caches managed by Wonder Blocks Data.
1340
1802
  *
1341
- * Values in the partial context that are `undefined` will be ignored.
1342
- * Values in the partial context that are `null` will be deleted.
1803
+ * This is a convenience method that purges the shared cache and the hydration
1804
+ * cache. It is useful for testing purposes to avoid having to reason about
1805
+ * which caches may have been used during a given test run.
1343
1806
  */
1344
- const mergeGqlContext = (defaultContext, overrides) => {
1345
- // Let's merge the partial context default context. We deliberately
1346
- // don't spread because spreading would overwrite default context
1347
- // values with undefined or null if the partial context includes a value
1348
- // explicitly set to undefined or null.
1349
- return Object.keys(overrides).reduce((acc, key) => {
1350
- // Undefined values are ignored.
1351
- if (overrides[key] !== undefined) {
1352
- if (overrides[key] === null) {
1353
- // Null indicates we delete this context value.
1354
- delete acc[key];
1355
- } else {
1356
- // Otherwise, we set it.
1357
- acc[key] = overrides[key];
1358
- }
1359
- }
1360
1807
 
1361
- return acc;
1362
- }, { ...defaultContext
1363
- });
1808
+ const purgeCaches = () => {
1809
+ Object(_hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* purgeSharedCache */ "a"])();
1810
+ Object(_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__[/* purgeHydrationCache */ "b"])();
1364
1811
  };
1365
1812
 
1366
1813
  /***/ }),
1367
- /* 19 */
1814
+ /* 25 */
1368
1815
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1369
1816
 
1370
1817
  "use strict";
1371
1818
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return TrackData; });
1372
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1819
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1373
1820
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1374
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
1821
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
1375
1822
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
1376
- /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7);
1823
+ /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
1377
1824
 
1378
1825
 
1379
1826
 
@@ -1395,13 +1842,13 @@ class TrackData extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
1395
1842
  }
1396
1843
 
1397
1844
  /***/ }),
1398
- /* 20 */
1845
+ /* 26 */
1399
1846
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1400
1847
 
1401
1848
  "use strict";
1402
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1849
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1403
1850
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1404
- /* harmony import */ var _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(11);
1851
+ /* harmony import */ var _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
1405
1852
 
1406
1853
 
1407
1854
 
@@ -1427,13 +1874,13 @@ const Data = ({
1427
1874
  /* harmony default export */ __webpack_exports__["a"] = (Data);
1428
1875
 
1429
1876
  /***/ }),
1430
- /* 21 */
1877
+ /* 27 */
1431
1878
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1432
1879
 
1433
1880
  "use strict";
1434
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1881
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1435
1882
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1436
- /* harmony import */ var _intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13);
1883
+ /* harmony import */ var _intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14);
1437
1884
 
1438
1885
 
1439
1886
 
@@ -1468,14 +1915,110 @@ const InterceptRequests = ({
1468
1915
  /* harmony default export */ __webpack_exports__["a"] = (InterceptRequests);
1469
1916
 
1470
1917
  /***/ }),
1471
- /* 22 */
1918
+ /* 28 */
1919
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1920
+
1921
+ "use strict";
1922
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlRequestId; });
1923
+ const toString = valid => {
1924
+ var _JSON$stringify;
1925
+
1926
+ if (typeof valid === "string") {
1927
+ return valid;
1928
+ }
1929
+
1930
+ return (_JSON$stringify = JSON.stringify(valid)) != null ? _JSON$stringify : "";
1931
+ };
1932
+ /**
1933
+ * Get an identifier for a given request.
1934
+ */
1935
+
1936
+
1937
+ const getGqlRequestId = (operation, variables, context) => {
1938
+ // We add all the bits for this into an array and then join them with
1939
+ // a chosen separator.
1940
+ const parts = []; // First, we push the context values.
1941
+
1942
+ const sortableContext = new URLSearchParams(context); // $FlowIgnore[prop-missing] Flow has incomplete support for URLSearchParams
1943
+
1944
+ sortableContext.sort();
1945
+ parts.push(sortableContext.toString()); // Now we add the operation identifier.
1946
+
1947
+ parts.push(operation.id); // Finally, if we have variables, we add those too.
1948
+
1949
+ if (variables != null) {
1950
+ // We need to turn each variable into a string.
1951
+ const stringifiedVariables = Object.keys(variables).reduce((acc, key) => {
1952
+ acc[key] = toString(variables[key]);
1953
+ return acc;
1954
+ }, {}); // We use the same mechanism as context to sort and arrange the
1955
+ // variables.
1956
+
1957
+ const sortableVariables = new URLSearchParams(stringifiedVariables); // $FlowIgnore[prop-missing] Flow has incomplete support for URLSearchParams
1958
+
1959
+ sortableVariables.sort();
1960
+ parts.push(sortableVariables.toString());
1961
+ }
1962
+
1963
+ return parts.join("|");
1964
+ };
1965
+
1966
+ /***/ }),
1967
+ /* 29 */
1968
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
1969
+
1970
+ "use strict";
1971
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return toGqlOperation; });
1972
+ /* harmony import */ var _graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(18);
1973
+
1974
+
1975
+ /**
1976
+ * Convert a GraphQL DocumentNode to a base Wonder Blocks Data GqlOperation.
1977
+ *
1978
+ * If you want to include the query/mutation body, extend the result of this
1979
+ * method and use the `graphql/language/printer` like:
1980
+ *
1981
+ * ```js
1982
+ * import {print} from "graphql/language/printer";
1983
+ *
1984
+ * const gqlOpWithBody = {
1985
+ * ...toGqlOperation(documentNode),
1986
+ * query: print(documentNode),
1987
+ * };
1988
+ * ```
1989
+ *
1990
+ * If you want to enforce inclusion of __typename properties, then you can use
1991
+ * `apollo-utilities` first to modify the document:
1992
+ *
1993
+ * ```js
1994
+ * import {print} from "graphql/language/printer";
1995
+ * import {addTypenameToDocument} from "apollo-utilities";
1996
+ *
1997
+ * const documentWithTypenames = addTypenameToDocument(documentNode);
1998
+ * const gqlOpWithBody = {
1999
+ * ...toGqlOperation(documentWithTypenames),
2000
+ * query: print(documentWithTypenames),
2001
+ * };
2002
+ * ```
2003
+ */
2004
+ const toGqlOperation = documentNode => {
2005
+ const definition = Object(_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__[/* graphQLDocumentNodeParser */ "a"])(documentNode);
2006
+ const wbDataOperation = {
2007
+ id: definition.name,
2008
+ type: definition.type
2009
+ };
2010
+ return wbDataOperation;
2011
+ };
2012
+
2013
+ /***/ }),
2014
+ /* 30 */
1472
2015
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1473
2016
 
1474
2017
  "use strict";
1475
2018
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlRouter; });
1476
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
2019
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1477
2020
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1478
- /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(17);
2021
+ /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(20);
1479
2022
 
1480
2023
 
1481
2024
 
@@ -1512,16 +2055,16 @@ const GqlRouter = ({
1512
2055
  };
1513
2056
 
1514
2057
  /***/ }),
1515
- /* 23 */
2058
+ /* 31 */
1516
2059
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1517
2060
 
1518
2061
  "use strict";
1519
2062
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGql; });
1520
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
2063
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1521
2064
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1522
- /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(18);
1523
- /* harmony import */ var _use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(25);
1524
- /* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(26);
2065
+ /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
2066
+ /* harmony import */ var _use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(33);
2067
+ /* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(34);
1525
2068
 
1526
2069
 
1527
2070
 
@@ -1562,13 +2105,13 @@ const useGql = (context = {}) => {
1562
2105
  };
1563
2106
 
1564
2107
  /***/ }),
1565
- /* 24 */
2108
+ /* 32 */
1566
2109
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1567
2110
 
1568
2111
  "use strict";
1569
2112
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return resultFromCachedResponse; });
1570
- /* harmony import */ var _status_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4);
1571
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
2113
+ /* harmony import */ var _status_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
2114
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1572
2115
 
1573
2116
 
1574
2117
 
@@ -1602,16 +2145,16 @@ const resultFromCachedResponse = cacheEntry => {
1602
2145
  };
1603
2146
 
1604
2147
  /***/ }),
1605
- /* 25 */
2148
+ /* 33 */
1606
2149
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1607
2150
 
1608
2151
  "use strict";
1609
2152
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGqlRouterContext; });
1610
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
2153
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1611
2154
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1612
- /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(18);
1613
- /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(17);
1614
- /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(3);
2155
+ /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
2156
+ /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20);
2157
+ /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
1615
2158
 
1616
2159
 
1617
2160
 
@@ -1654,13 +2197,13 @@ const useGqlRouterContext = (contextOverrides = {}) => {
1654
2197
  };
1655
2198
 
1656
2199
  /***/ }),
1657
- /* 26 */
2200
+ /* 34 */
1658
2201
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1659
2202
 
1660
2203
  "use strict";
1661
2204
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlDataFromResponse; });
1662
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1663
- /* harmony import */ var _gql_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
2205
+ /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
2206
+ /* harmony import */ var _gql_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
1664
2207
 
1665
2208
 
1666
2209
  /**
@@ -1724,272 +2267,115 @@ const getGqlDataFromResponse = async response => {
1724
2267
  };
1725
2268
 
1726
2269
  /***/ }),
1727
- /* 27 */
2270
+ /* 35 */
1728
2271
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1729
2272
 
1730
2273
  "use strict";
1731
2274
  __webpack_require__.r(__webpack_exports__);
1732
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "initializeCache", function() { return initializeCache; });
1733
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fulfillAllDataRequests", function() { return fulfillAllDataRequests; });
1734
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hasUnfulfilledRequests", function() { return hasUnfulfilledRequests; });
1735
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeFromCache", function() { return removeFromCache; });
1736
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "removeAllFromCache", function() { return removeAllFromCache; });
1737
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
1738
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1739
- /* harmony import */ var _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
1740
- /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(7);
1741
- /* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(19);
1742
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TrackData", function() { return _components_track_data_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
1743
-
1744
- /* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(20);
1745
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Data", function() { return _components_data_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
1746
-
1747
- /* harmony import */ var _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(21);
1748
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "InterceptRequests", function() { return _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
1749
-
1750
- /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(1);
1751
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataError", function() { return _util_data_error_js__WEBPACK_IMPORTED_MODULE_6__["a"]; });
1752
-
1753
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataErrors", function() { return _util_data_error_js__WEBPACK_IMPORTED_MODULE_6__["b"]; });
1754
-
1755
- /* harmony import */ var _hooks_use_server_effect_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(14);
1756
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useServerEffect", function() { return _hooks_use_server_effect_js__WEBPACK_IMPORTED_MODULE_7__["a"]; });
1757
-
1758
- /* harmony import */ var _hooks_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(15);
1759
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useCachedEffect", function() { return _hooks_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_8__["a"]; });
1760
-
1761
- /* harmony import */ var _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(8);
1762
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useSharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_9__["b"]; });
1763
-
1764
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "clearSharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_9__["a"]; });
2275
+ /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
2276
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FetchPolicy", function() { return _util_types_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
1765
2277
 
1766
- /* harmony import */ var _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(11);
1767
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useHydratableEffect", function() { return _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_10__["b"]; });
2278
+ /* harmony import */ var _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
2279
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "initializeHydrationCache", function() { return _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
1768
2280
 
1769
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WhenClientSide", function() { return _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_10__["a"]; });
2281
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeHydrationCache", function() { return _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__["b"]; });
1770
2282
 
1771
- /* harmony import */ var _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(9);
1772
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ScopedInMemoryCache", function() { return _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_11__["a"]; });
2283
+ /* harmony import */ var _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(23);
2284
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fetchTrackedRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["b"]; });
1773
2285
 
1774
- /* harmony import */ var _util_serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(12);
1775
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SerializableInMemoryCache", function() { return _util_serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_12__["a"]; });
2286
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "hasTrackedRequestsToBeFetched", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["c"]; });
1776
2287
 
1777
- /* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(10);
1778
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RequestFulfillment", function() { return _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_13__["a"]; });
2288
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "abortInflightRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
1779
2289
 
1780
- /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(4);
1781
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Status", function() { return _util_status_js__WEBPACK_IMPORTED_MODULE_14__["a"]; });
1782
-
1783
- /* harmony import */ var _components_gql_router_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(22);
1784
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlRouter", function() { return _components_gql_router_js__WEBPACK_IMPORTED_MODULE_15__["a"]; });
2290
+ /* harmony import */ var _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(24);
2291
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeCaches", function() { return _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
1785
2292
 
1786
- /* harmony import */ var _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(23);
1787
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useGql", function() { return _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_16__["a"]; });
2293
+ /* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(25);
2294
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TrackData", function() { return _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
1788
2295
 
1789
- /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(3);
1790
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlError", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_17__["a"]; });
2296
+ /* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(26);
2297
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Data", function() { return _components_data_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
1791
2298
 
1792
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlErrors", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_17__["b"]; });
2299
+ /* harmony import */ var _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(27);
2300
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "InterceptRequests", function() { return _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__["a"]; });
1793
2301
 
2302
+ /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(0);
2303
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataError", function() { return _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__["a"]; });
1794
2304
 
2305
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataErrors", function() { return _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__["b"]; });
1795
2306
 
2307
+ /* harmony import */ var _hooks_use_server_effect_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(16);
2308
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useServerEffect", function() { return _hooks_use_server_effect_js__WEBPACK_IMPORTED_MODULE_8__["a"]; });
1796
2309
 
2310
+ /* harmony import */ var _hooks_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(17);
2311
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useCachedEffect", function() { return _hooks_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_9__["a"]; });
1797
2312
 
1798
- /**
1799
- * Initialize the hydration cache.
1800
- *
1801
- * @param {ResponseCache} source The cache content to use for initializing the
1802
- * cache.
1803
- * @throws {Error} If the cache is already initialized.
1804
- */
1805
- const initializeCache = source => _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SsrCache */ "a"].Default.initialize(source);
1806
- /**
1807
- * Fulfill all tracked data requests.
1808
- *
1809
- * This is for use with the `TrackData` component during server-side rendering.
1810
- *
1811
- * @throws {Error} If executed outside of server-side rendering.
1812
- * @returns {Promise<void>} A promise that resolves when all tracked requests
1813
- * have been fulfilled.
1814
- */
2313
+ /* harmony import */ var _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(5);
2314
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useSharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__["b"]; });
1815
2315
 
1816
- const fulfillAllDataRequests = () => {
1817
- if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
1818
- return Promise.reject(new Error("Data requests are not tracked when client-side"));
1819
- }
2316
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeSharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__["a"]; });
1820
2317
 
1821
- return _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestTracker */ "a"].Default.fulfillTrackedRequests();
1822
- };
1823
- /**
1824
- * Indicate if there are unfulfilled tracked requests.
1825
- *
1826
- * This is used in conjunction with `TrackData`.
1827
- *
1828
- * @throws {Error} If executed outside of server-side rendering.
1829
- * @returns {boolean} `true` if there are unfulfilled tracked requests;
1830
- * otherwise, `false`.
1831
- */
2318
+ /* harmony import */ var _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(12);
2319
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useHydratableEffect", function() { return _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__["b"]; });
1832
2320
 
1833
- const hasUnfulfilledRequests = () => {
1834
- if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
1835
- throw new Error("Data requests are not tracked when client-side");
1836
- }
2321
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WhenClientSide", function() { return _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__["a"]; });
1837
2322
 
1838
- return _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestTracker */ "a"].Default.hasUnfulfilledRequests;
1839
- };
1840
- /**
1841
- * Remove the request identified from the cached hydration responses.
1842
- *
1843
- * @param {string} id The request ID of the response to remove from the cache.
1844
- */
2323
+ /* harmony import */ var _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(11);
2324
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ScopedInMemoryCache", function() { return _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_12__["a"]; });
1845
2325
 
1846
- const removeFromCache = id => _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SsrCache */ "a"].Default.remove(id);
1847
- /**
1848
- * Remove all cached hydration responses that match the given predicate.
1849
- *
1850
- * @param {(id: string) => boolean} [predicate] The predicate to match against
1851
- * the cached hydration responses. If no predicate is provided, all cached
1852
- * hydration responses will be removed.
1853
- */
2326
+ /* harmony import */ var _util_serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(13);
2327
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SerializableInMemoryCache", function() { return _util_serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_13__["a"]; });
1854
2328
 
1855
- const removeAllFromCache = predicate => _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SsrCache */ "a"].Default.removeAll(predicate);
2329
+ /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(6);
2330
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Status", function() { return _util_status_js__WEBPACK_IMPORTED_MODULE_14__["a"]; });
1856
2331
 
2332
+ /* harmony import */ var _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(28);
2333
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getGqlRequestId", function() { return _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__["a"]; });
1857
2334
 
2335
+ /* harmony import */ var _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(18);
2336
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "graphQLDocumentNodeParser", function() { return _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_16__["a"]; });
1858
2337
 
2338
+ /* harmony import */ var _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(29);
2339
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toGqlOperation", function() { return _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_17__["a"]; });
1859
2340
 
2341
+ /* harmony import */ var _components_gql_router_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(30);
2342
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlRouter", function() { return _components_gql_router_js__WEBPACK_IMPORTED_MODULE_18__["a"]; });
1860
2343
 
2344
+ /* harmony import */ var _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(31);
2345
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useGql", function() { return _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_19__["a"]; });
1861
2346
 
2347
+ /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(4);
2348
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlError", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_20__["a"]; });
1862
2349
 
2350
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlErrors", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_20__["b"]; });
1863
2351
 
2352
+ // TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
2353
+ // have fixed:
2354
+ // https://github.com/import-js/eslint-plugin-import/issues/2073
2355
+ // eslint-disable-next-line import/named
1864
2356
 
1865
2357
 
1866
2358
 
1867
- // GraphQL
1868
2359
 
1869
2360
 
1870
2361
 
1871
2362
 
1872
2363
 
1873
- /***/ }),
1874
- /* 28 */
1875
- /***/ (function(module, exports, __webpack_require__) {
1876
2364
 
1877
- "use strict";
1878
- /**
1879
- * Copyright (c) Facebook, Inc. and its affiliates.
1880
- *
1881
- * This source code is licensed under the MIT license found in the
1882
- * LICENSE file in the root directory of this source tree.
1883
- */
1884
2365
 
1885
2366
 
1886
2367
 
1887
- // Below we want to use `hasOwnProperty` on an object that doesn't have
1888
- // `Object.prototype` in its proto chain, so we must extract it here.
1889
- var hasOwnProperty = Object.prototype.hasOwnProperty;
1890
2368
 
1891
- // Map from an enum object to a reverse map of its values to names
1892
- var reverseMapCache = typeof WeakMap === 'function' ? new WeakMap() : new Map();
1893
2369
 
1894
- // Computes the reverse mapping of the enum object: from value to name.
1895
- // Flow Enum values are unique (enforced by the parser), so this is a
1896
- // one to one mapping.
1897
- function getReverseMap(enumObject) {
1898
- var reverseMap = reverseMapCache.get(enumObject);
1899
- if (reverseMap !== undefined) {
1900
- return reverseMap;
1901
- }
1902
- // We aren't using `Object.values` because that gets enumerable
1903
- // properties, and our properties aren't enumerable.
1904
- var newReverseMap = new Map();
1905
- Object.getOwnPropertyNames(enumObject).forEach(function (name) {
1906
- newReverseMap.set(enumObject[name], name);
1907
- });
1908
- reverseMapCache.set(enumObject, newReverseMap);
1909
- return newReverseMap;
1910
- }
2370
+ ////////////////////////////////////////////////////////////////////////////////
2371
+ // GraphQL
2372
+ ////////////////////////////////////////////////////////////////////////////////
1911
2373
 
1912
- var EnumPrototype = Object.freeze(
1913
- Object.defineProperties(Object.create(null), {
1914
- isValid: {
1915
- value: function (x) {
1916
- return getReverseMap(this).has(x);
1917
- },
1918
- },
1919
- cast: {
1920
- value: function (x) {
1921
- return this.isValid(x) ? x : undefined;
1922
- },
1923
- },
1924
- members: {
1925
- value: function () {
1926
- return getReverseMap(this).keys();
1927
- },
1928
- },
1929
- getName: {
1930
- value: function (value) {
1931
- return getReverseMap(this).get(value);
1932
- }
1933
- }
1934
- })
1935
- );
1936
2374
 
1937
- // `members` is an object mapping name to value.
1938
- function Enum(members) {
1939
- var o = Object.create(EnumPrototype);
1940
- for (var k in members) {
1941
- if (hasOwnProperty.call(members, k)) {
1942
- // Create non-enumerable properties.
1943
- Object.defineProperty(o, k, {value: members[k]});
1944
- }
1945
- }
1946
- return Object.freeze(o);
1947
- }
1948
2375
 
1949
- // Mirrored enum (string enum with no member initializers).
1950
- // Optimized implementation, taking advantage of the fact that
1951
- // keys and values are identical.
1952
- var EnumMirroredPrototype = Object.freeze(
1953
- Object.defineProperties(Object.create(null), {
1954
- isValid: {
1955
- value: function (x) {
1956
- if (typeof x === 'string') {
1957
- return hasOwnProperty.call(this, x);
1958
- }
1959
- return false;
1960
- },
1961
- },
1962
- cast: {
1963
- value: EnumPrototype.cast,
1964
- },
1965
- members: {
1966
- value: function () {
1967
- // We aren't using `Object.values` because that gets enumerable
1968
- // properties, and our properties aren't enumerable.
1969
- return Object.getOwnPropertyNames(this).values();
1970
- },
1971
- },
1972
- getName: {
1973
- value: function (value) {
1974
- return value;
1975
- }
1976
- }
1977
- })
1978
- );
1979
2376
 
1980
- // `members` is an array of names (which, are also the values).
1981
- Enum.Mirrored = function EnumMirrored(members) {
1982
- var o = Object.create(EnumMirroredPrototype);
1983
- for (var i = 0, len = members.length; i < len; ++i) {
1984
- // Value is same as key. Also, non-enumerable.
1985
- Object.defineProperty(o, members[i], {value: members[i]});
1986
- }
1987
- return Object.freeze(o);
1988
- };
1989
2377
 
1990
- Object.freeze(Enum.Mirrored);
1991
2378
 
1992
- module.exports = Object.freeze(Enum);
1993
2379
 
1994
2380
 
1995
2381
  /***/ })