@khanacademy/wonder-blocks-data 10.0.1 → 10.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js DELETED
@@ -1,2301 +0,0 @@
1
- module.exports =
2
- /******/ (function(modules) { // webpackBootstrap
3
- /******/ // The module cache
4
- /******/ var installedModules = {};
5
- /******/
6
- /******/ // The require function
7
- /******/ function __webpack_require__(moduleId) {
8
- /******/
9
- /******/ // Check if module is in cache
10
- /******/ if(installedModules[moduleId]) {
11
- /******/ return installedModules[moduleId].exports;
12
- /******/ }
13
- /******/ // Create a new module (and put it into the cache)
14
- /******/ var module = installedModules[moduleId] = {
15
- /******/ i: moduleId,
16
- /******/ l: false,
17
- /******/ exports: {}
18
- /******/ };
19
- /******/
20
- /******/ // Execute the module function
21
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
- /******/
23
- /******/ // Flag the module as loaded
24
- /******/ module.l = true;
25
- /******/
26
- /******/ // Return the exports of the module
27
- /******/ return module.exports;
28
- /******/ }
29
- /******/
30
- /******/
31
- /******/ // expose the modules object (__webpack_modules__)
32
- /******/ __webpack_require__.m = modules;
33
- /******/
34
- /******/ // expose the module cache
35
- /******/ __webpack_require__.c = installedModules;
36
- /******/
37
- /******/ // define getter function for harmony exports
38
- /******/ __webpack_require__.d = function(exports, name, getter) {
39
- /******/ if(!__webpack_require__.o(exports, name)) {
40
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41
- /******/ }
42
- /******/ };
43
- /******/
44
- /******/ // define __esModule on exports
45
- /******/ __webpack_require__.r = function(exports) {
46
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
- /******/ }
49
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
- /******/ };
51
- /******/
52
- /******/ // create a fake namespace object
53
- /******/ // mode & 1: value is a module id, require it
54
- /******/ // mode & 2: merge all properties of value into the ns
55
- /******/ // mode & 4: return value when already ns object
56
- /******/ // mode & 8|1: behave like require
57
- /******/ __webpack_require__.t = function(value, mode) {
58
- /******/ if(mode & 1) value = __webpack_require__(value);
59
- /******/ if(mode & 8) return value;
60
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61
- /******/ var ns = Object.create(null);
62
- /******/ __webpack_require__.r(ns);
63
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65
- /******/ return ns;
66
- /******/ };
67
- /******/
68
- /******/ // getDefaultExport function for compatibility with non-harmony modules
69
- /******/ __webpack_require__.n = function(module) {
70
- /******/ var getter = module && module.__esModule ?
71
- /******/ function getDefault() { return module['default']; } :
72
- /******/ function getModuleExports() { return module; };
73
- /******/ __webpack_require__.d(getter, 'a', getter);
74
- /******/ return getter;
75
- /******/ };
76
- /******/
77
- /******/ // Object.prototype.hasOwnProperty.call
78
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79
- /******/
80
- /******/ // __webpack_public_path__
81
- /******/ __webpack_require__.p = "";
82
- /******/
83
- /******/
84
- /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 35);
86
- /******/ })
87
- /************************************************************************/
88
- /******/ ([
89
- /* 0 */
90
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
91
-
92
- "use strict";
93
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return DataErrors; });
94
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return DataError; });
95
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
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__);
97
-
98
-
99
- /**
100
- * Error kinds for DataError.
101
- */
102
- const DataErrors = Object.freeze({
103
- /**
104
- * The kind of error is not known.
105
- */
106
- Unknown: "Unknown",
107
-
108
- /**
109
- * The error is internal to the executing code.
110
- */
111
- Internal: "Internal",
112
-
113
- /**
114
- * There was a problem with the provided input.
115
- */
116
- InvalidInput: "InvalidInput",
117
-
118
- /**
119
- * A network error occurred.
120
- */
121
- Network: "Network",
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
- /**
130
- * Response could not be parsed.
131
- */
132
- Parse: "Parse",
133
-
134
- /**
135
- * An error that occurred during SSR and was hydrated from cache
136
- */
137
- Hydrated: "Hydrated"
138
- });
139
- /**
140
- * An error from the Wonder Blocks Data API.
141
- *
142
- * Errors of this type will have names of the format:
143
- * `${kind}DataError`
144
- */
145
-
146
- class DataError extends _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__["KindError"] {
147
- constructor(message, kind, {
148
- metadata,
149
- cause
150
- } = {}) {
151
- super(message, kind, {
152
- metadata,
153
- cause,
154
- name: "Data"
155
- });
156
- }
157
-
158
- }
159
-
160
- /***/ }),
161
- /* 1 */
162
- /***/ (function(module, exports) {
163
-
164
- module.exports = require("react");
165
-
166
- /***/ }),
167
- /* 2 */
168
- /***/ (function(module, exports) {
169
-
170
- module.exports = require("@khanacademy/wonder-blocks-core");
171
-
172
- /***/ }),
173
- /* 3 */
174
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
175
-
176
- "use strict";
177
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return FetchPolicy; });
178
- /**
179
- * Defines the various fetch policies that can be applied to requests.
180
- */
181
- const FetchPolicy = __webpack_require__(23).Mirrored(["CacheBeforeNetwork", "CacheAndNetwork", "CacheOnly", "NetworkOnly"]);
182
- /**
183
- * Define what can be cached.
184
- *
185
- * We disallow functions and undefined as undefined represents a cache miss
186
- * and functions are not allowed.
187
- */
188
-
189
- /***/ }),
190
- /* 4 */
191
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
192
-
193
- "use strict";
194
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return GqlErrors; });
195
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlError; });
196
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
197
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__);
198
-
199
-
200
- /**
201
- * Error kinds for GqlError.
202
- */
203
- const GqlErrors = Object.freeze({
204
- /**
205
- * An internal framework error.
206
- */
207
- Internal: "Internal",
208
-
209
- /**
210
- * Response does not have the correct structure for a GraphQL response.
211
- */
212
- BadResponse: "BadResponse",
213
-
214
- /**
215
- * A valid GraphQL result with errors field in the payload.
216
- */
217
- ErrorResult: "ErrorResult"
218
- });
219
- /**
220
- * An error from the GQL API.
221
- *
222
- * Errors of this type will have names of the format:
223
- * `${kind}GqlError`
224
- */
225
-
226
- class GqlError extends _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__["KindError"] {
227
- constructor(message, kind, {
228
- metadata,
229
- cause
230
- } = {}) {
231
- super(message, kind, {
232
- metadata,
233
- cause,
234
- name: "Gql"
235
- });
236
- }
237
-
238
- }
239
-
240
- /***/ }),
241
- /* 5 */
242
- /***/ (function(module, exports) {
243
-
244
- module.exports = require("@khanacademy/wonder-stuff-core");
245
-
246
- /***/ }),
247
- /* 6 */
248
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
249
-
250
- "use strict";
251
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SharedCache; });
252
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return useSharedCache; });
253
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
254
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
255
- /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
256
- /* harmony import */ var _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
257
-
258
-
259
-
260
-
261
- /**
262
- * This is the cache.
263
- * It's incredibly complex.
264
- * Very in-memory. So cache. Such complex. Wow.
265
- */
266
- const cache = new _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__[/* ScopedInMemoryCache */ "a"]();
267
- /**
268
- * Access to the shared in-memory cache.
269
- *
270
- * This is the cache used by `useSharedCache` and related hooks and
271
- * components.
272
- */
273
-
274
- const SharedCache = cache;
275
- /**
276
- * Hook to retrieve data from and store data in an in-memory cache.
277
- *
278
- * @returns {[?ReadOnlyCacheValue, CacheValueFn]}
279
- * Returns an array containing the current cache entry (or undefined), a
280
- * function to set the cache entry (passing null or undefined to this function
281
- * will delete the entry).
282
- *
283
- * NOTE: Unlike useState or useReducer, we don't automatically update folks
284
- * if the value they reference changes. We might add it later (if we need to),
285
- * but the likelihood here is that things won't be changing in this cache in a
286
- * way where we would need that. If we do (and likely only in specific
287
- * circumstances), we should consider adding a simple boolean useState that can
288
- * be toggled to cause a rerender whenever the referenced cached data changes
289
- * so that callers can re-render on cache changes. However, we should make
290
- * sure this toggling is optional - or we could use a callback argument, to
291
- * achieve this on an as-needed basis.
292
- */
293
-
294
- const useSharedCache = (id, scope, initialValue) => {
295
- // Verify arguments.
296
- if (!id || typeof id !== "string") {
297
- 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);
298
- }
299
-
300
- if (!scope || typeof scope !== "string") {
301
- 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);
302
- } // Memoize our APIs.
303
- // This one allows callers to set or replace the cached value.
304
-
305
-
306
- 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
307
- // since our last run through. Also, our cache does not know what type it
308
- // stores, so we have to cast it to the type we're exporting. This is a
309
- // dev time courtesy, rather than a runtime thing.
310
- // $FlowIgnore[incompatible-type]
311
-
312
- let currentValue = cache.get(scope, id); // If we have an initial value, we need to add it to the cache
313
- // and use it as our current value.
314
-
315
- if (currentValue == null && initialValue !== undefined) {
316
- // Get the initial value.
317
- const value = typeof initialValue === "function" ? initialValue() : initialValue;
318
-
319
- if (value != null) {
320
- // Update the cache.
321
- cacheValue(value); // Make sure we return this value as our current value.
322
-
323
- currentValue = value;
324
- }
325
- } // Now we have everything, let's return it.
326
-
327
-
328
- return [currentValue, cacheValue];
329
- };
330
-
331
- /***/ }),
332
- /* 7 */
333
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
334
-
335
- "use strict";
336
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Status; });
337
- const loadingStatus = Object.freeze({
338
- status: "loading"
339
- });
340
- const abortedStatus = Object.freeze({
341
- status: "aborted"
342
- });
343
- /**
344
- * Create Result<TData> instances with specific statuses.
345
- */
346
-
347
- const Status = Object.freeze({
348
- loading: () => loadingStatus,
349
- aborted: () => abortedStatus,
350
- success: data => ({
351
- status: "success",
352
- data
353
- }),
354
- error: error => ({
355
- status: "error",
356
- error
357
- })
358
- });
359
-
360
- /***/ }),
361
- /* 8 */
362
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
363
-
364
- "use strict";
365
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return TrackerContext; });
366
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestTracker; });
367
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
368
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
369
- /* harmony import */ var _ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
370
- /* harmony import */ var _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
371
-
372
-
373
-
374
-
375
- /**
376
- * Used to inject our tracking function into the render framework.
377
- *
378
- * INTERNAL USE ONLY
379
- */
380
- const TrackerContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
381
- /**
382
- * The default instance is stored here.
383
- * It's created below in the Default() static property.
384
- */
385
-
386
- let _default;
387
- /**
388
- * Implements request tracking and fulfillment.
389
- *
390
- * INTERNAL USE ONLY
391
- */
392
-
393
-
394
- class RequestTracker {
395
- static get Default() {
396
- if (!_default) {
397
- _default = new RequestTracker();
398
- }
399
-
400
- return _default;
401
- }
402
- /**
403
- * These are the caches for tracked requests, their handlers, and responses.
404
- */
405
-
406
-
407
- constructor(responseCache = undefined) {
408
- this._trackedRequests = {};
409
-
410
- this.trackDataRequest = (id, handler, hydrate) => {
411
- /**
412
- * If we don't already have this tracked, then let's track it.
413
- */
414
- if (this._trackedRequests[id] == null) {
415
- this._trackedRequests[id] = {
416
- handler,
417
- hydrate
418
- };
419
- }
420
- };
421
-
422
- this.reset = () => {
423
- this._trackedRequests = {};
424
- };
425
-
426
- this.fulfillTrackedRequests = () => {
427
- const promises = [];
428
- const {
429
- cacheData,
430
- cacheError
431
- } = this._responseCache;
432
-
433
- for (const requestKey of Object.keys(this._trackedRequests)) {
434
- const options = this._trackedRequests[requestKey];
435
-
436
- try {
437
- promises.push(this._requestFulfillment.fulfill(requestKey, { ...options
438
- }).then(result => {
439
- switch (result.status) {
440
- case "success":
441
- /**
442
- * Let's cache the data!
443
- *
444
- * NOTE: This only caches when we're
445
- * server side.
446
- */
447
- cacheData(requestKey, result.data, options.hydrate);
448
- break;
449
-
450
- case "error":
451
- /**
452
- * Let's cache the error!
453
- *
454
- * NOTE: This only caches when we're
455
- * server side.
456
- */
457
- cacheError(requestKey, result.error, options.hydrate);
458
- break;
459
- } // For status === "loading":
460
- // Could never get here unless we wrote
461
- // the code wrong. Rather than bloat
462
- // code with useless error, just ignore.
463
- // For status === "aborted":
464
- // We won't cache this.
465
- // We don't hydrate aborted requests,
466
- // so the client would just see them
467
- // as unfulfilled data.
468
-
469
-
470
- return;
471
- }));
472
- } catch (e) {
473
- // This captures if there are problems in the code that
474
- // begins the requests.
475
- promises.push(Promise.resolve(cacheError(requestKey, e, options.hydrate)));
476
- }
477
- }
478
- /**
479
- * Clear out our tracked info.
480
- *
481
- * We call this now for a simpler API.
482
- *
483
- * If we reset the tracked calls after all promises resolve, any
484
- * request tracking done while promises are in flight would be lost.
485
- *
486
- * If we don't reset at all, then we have to expose the `reset` call
487
- * for consumers to use, or they'll only ever be able to accumulate
488
- * more and more tracked requests, having to fulfill them all every
489
- * time.
490
- *
491
- * Calling it here means we can have multiple "track -> request"
492
- * cycles in a row and in an easy to reason about manner.
493
- */
494
-
495
-
496
- this.reset();
497
- /**
498
- * Let's wait for everything to fulfill, and then clone the cached data.
499
- */
500
-
501
- return Promise.all(promises).then(() => this._responseCache.cloneHydratableData());
502
- };
503
-
504
- this._responseCache = responseCache || _ssr_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SsrCache */ "a"].Default;
505
- this._requestFulfillment = new _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestFulfillment */ "a"]();
506
- }
507
- /**
508
- * Track a request.
509
- *
510
- * This method caches a request and its handler for use during server-side
511
- * rendering to allow us to fulfill requests before producing a final render.
512
- */
513
-
514
-
515
- /**
516
- * Indicates if we have requests waiting to be fulfilled.
517
- */
518
- get hasUnfulfilledRequests() {
519
- return Object.keys(this._trackedRequests).length > 0;
520
- }
521
- /**
522
- * Initiate fulfillment of all tracked requests.
523
- *
524
- * This loops over the requests that were tracked using TrackData, and asks
525
- * the respective handlers to fulfill those requests in the order they were
526
- * tracked.
527
- *
528
- * Calling this method marks tracked requests as fulfilled; requests are
529
- * removed from the list of tracked requests by calling this method.
530
- *
531
- * @returns {Promise<ResponseCache>} The promise of the data that was
532
- * cached as a result of fulfilling the tracked requests.
533
- */
534
-
535
-
536
- }
537
-
538
- /***/ }),
539
- /* 9 */
540
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
541
-
542
- "use strict";
543
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SsrCache; });
544
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
545
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
546
- /* harmony import */ var _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(13);
547
-
548
-
549
- const DefaultScope = "default";
550
- /**
551
- * The default instance is stored here.
552
- * It's created below in the Default() static property.
553
- */
554
-
555
- let _default;
556
- /**
557
- * Implements the response cache.
558
- *
559
- * INTERNAL USE ONLY
560
- */
561
-
562
-
563
- class SsrCache {
564
- static get Default() {
565
- if (!_default) {
566
- _default = new SsrCache();
567
- }
568
-
569
- return _default;
570
- }
571
-
572
- constructor(hydrationCache = null, ssrOnlyCache = null) {
573
- this.initialize = source => {
574
- if (this._hydrationCache.inUse) {
575
- throw new Error("Cannot initialize data response cache more than once");
576
- }
577
-
578
- this._hydrationCache = new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]({
579
- // $FlowIgnore[incompatible-call]
580
- [DefaultScope]: source
581
- });
582
- };
583
-
584
- this.cacheData = (id, data, hydrate) => this._setCachedResponse(id, {
585
- data
586
- }, hydrate);
587
-
588
- this.cacheError = (id, error, hydrate) => {
589
- const errorMessage = typeof error === "string" ? error : error.message;
590
- return this._setCachedResponse(id, {
591
- error: errorMessage
592
- }, hydrate);
593
- };
594
-
595
- this.getEntry = id => {
596
- // Get the cached entry for this value.
597
- // We first look in the ssr cache, if we need to.
598
- const ssrEntry = _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() ? this._ssrOnlyCache.get(DefaultScope, id) : null; // Now we defer to the SSR value, and fallback to the hydration cache.
599
-
600
- const internalEntry = ssrEntry != null ? ssrEntry : this._hydrationCache.get(DefaultScope, id); // If we are not server-side and we hydrated something, let's clear
601
- // that from the hydration cache to save memory.
602
-
603
- if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide() && internalEntry != null) {
604
- // We now delete this from our hydration cache as we don't need it.
605
- // This does mean that if another handler of the same type but
606
- // without some sort of linked cache won't get the value, but
607
- // that's not an expected use-case. If two different places use the
608
- // same handler and options (i.e. the same request), then the
609
- // handler should cater to that to ensure they share the result.
610
- this._hydrationCache.purge(DefaultScope, id);
611
- } // Getting the typing right between the in-memory cache and this
612
- // is hard. Just telling flow it's OK.
613
- // $FlowIgnore[incompatible-return]
614
-
615
-
616
- return internalEntry;
617
- };
618
-
619
- this.purgeData = predicate => {
620
- const realPredicate = predicate ? // We know what we're putting into the cache so let's assume it
621
- // conforms.
622
- // $FlowIgnore[incompatible-call]
623
- (_, key, cachedEntry) => predicate(key, cachedEntry) : undefined; // Apply the predicate to what we have in our caches.
624
-
625
- this._hydrationCache.purgeAll(realPredicate);
626
-
627
- this._ssrOnlyCache.purgeAll(realPredicate);
628
- };
629
-
630
- this.cloneHydratableData = () => {
631
- var _cache$DefaultScope;
632
-
633
- // We return our hydration cache only.
634
- const cache = this._hydrationCache.clone(); // If we're empty, we still want to return an object, so we default
635
- // to an empty object.
636
- // We only need the default scope out of our scoped in-memory cache.
637
- // We know that it conforms to our expectations.
638
- // $FlowIgnore[incompatible-return]
639
-
640
-
641
- return (_cache$DefaultScope = cache[DefaultScope]) != null ? _cache$DefaultScope : {};
642
- };
643
-
644
- this._ssrOnlyCache = ssrOnlyCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]();
645
- this._hydrationCache = hydrationCache || new _serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_1__[/* SerializableInMemoryCache */ "a"]();
646
- }
647
-
648
- _setCachedResponse(id, entry, hydrate) {
649
- const frozenEntry = Object.freeze(entry);
650
-
651
- if (_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
652
- // We are server-side.
653
- // We need to store this value.
654
- if (hydrate) {
655
- this._hydrationCache.set(DefaultScope, id, frozenEntry);
656
- } else {
657
- // Usually, when server-side, this cache will always be present.
658
- // We do fake server-side in our doc example though, when it
659
- // won't be.
660
- this._ssrOnlyCache.set(DefaultScope, id, frozenEntry);
661
- }
662
- }
663
-
664
- return frozenEntry;
665
- }
666
- /**
667
- * Initialize the cache from a given cache state.
668
- *
669
- * This can only be called if the cache is not already in use.
670
- */
671
-
672
-
673
- }
674
-
675
- /***/ }),
676
- /* 10 */
677
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
678
-
679
- "use strict";
680
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RequestFulfillment; });
681
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
682
-
683
-
684
- let _default;
685
- /**
686
- * This fulfills a request, making sure that in-flight requests are shared.
687
- */
688
-
689
-
690
- class RequestFulfillment {
691
- constructor() {
692
- this._requests = {};
693
-
694
- this.fulfill = (id, {
695
- handler,
696
- hydrate = true
697
- }) => {
698
- /**
699
- * If we have an inflight request, we'll provide that.
700
- */
701
- const inflight = this._requests[id];
702
-
703
- if (inflight) {
704
- return inflight;
705
- }
706
- /**
707
- * We don't have an inflight request, so let's set one up.
708
- */
709
-
710
-
711
- const request = handler().then(data => ({
712
- status: "success",
713
- data
714
- })).catch(error => {
715
- 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, {
716
- metadata: {
717
- unexpectedError: error
718
- }
719
- }) : error; // Return aborted result if the request was aborted.
720
- // The only way to detect this reliably, it seems, is to
721
- // check the error name and see if it's "AbortError" (this
722
- // is also what Apollo does).
723
- // Even then, it's reliant on the handler supporting aborts.
724
- // TODO(somewhatabstract, FEI-4276): Add first class abort
725
- // support to the handler API.
726
-
727
- if (actualError.name === "AbortError") {
728
- return {
729
- status: "aborted"
730
- };
731
- }
732
-
733
- return {
734
- status: "error",
735
- error: actualError
736
- };
737
- }).finally(() => {
738
- delete this._requests[id];
739
- }); // Store the request in our cache.
740
-
741
- this._requests[id] = request;
742
- return request;
743
- };
744
-
745
- this.abort = id => {
746
- // TODO(somewhatabstract, FEI-4276): Add first class abort
747
- // support to the handler API.
748
- // For now, we will just clear the request out of the list.
749
- // When abort is implemented, the `finally` in the `fulfill` method
750
- // would handle the deletion.
751
- delete this._requests[id];
752
- };
753
-
754
- this.abortAll = () => {
755
- Object.keys(this._requests).forEach(id => this.abort(id));
756
- };
757
- }
758
-
759
- static get Default() {
760
- if (!_default) {
761
- _default = new RequestFulfillment();
762
- }
763
-
764
- return _default;
765
- }
766
-
767
- }
768
-
769
- /***/ }),
770
- /* 11 */
771
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
772
-
773
- "use strict";
774
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ScopedInMemoryCache; });
775
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
776
-
777
-
778
- /**
779
- * Describe an in-memory cache.
780
- */
781
- class ScopedInMemoryCache {
782
- constructor(initialCache = {}) {
783
- this._cache = initialCache;
784
- }
785
- /**
786
- * Indicate if this cache is being used or not.
787
- *
788
- * When the cache has entries, returns `true`; otherwise, returns `false`.
789
- */
790
-
791
-
792
- get inUse() {
793
- return Object.keys(this._cache).length > 0;
794
- }
795
- /**
796
- * Set a value in the cache.
797
- */
798
-
799
-
800
- set(scope, id, value) {
801
- var _this$_cache$scope;
802
-
803
- if (!id || typeof id !== "string") {
804
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("id must be non-empty string", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
805
- }
806
-
807
- if (!scope || typeof scope !== "string") {
808
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("scope must be non-empty string", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
809
- }
810
-
811
- if (typeof value === "function") {
812
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("value must be a non-function value", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
813
- }
814
-
815
- this._cache[scope] = (_this$_cache$scope = this._cache[scope]) != null ? _this$_cache$scope : {};
816
- this._cache[scope][id] = value;
817
- }
818
- /**
819
- * Retrieve a value from the cache.
820
- */
821
-
822
-
823
- get(scope, id) {
824
- var _this$_cache$scope$id, _this$_cache$scope2;
825
-
826
- return (_this$_cache$scope$id = (_this$_cache$scope2 = this._cache[scope]) == null ? void 0 : _this$_cache$scope2[id]) != null ? _this$_cache$scope$id : null;
827
- }
828
- /**
829
- * Purge an item from the cache.
830
- */
831
-
832
-
833
- purge(scope, id) {
834
- var _this$_cache$scope3;
835
-
836
- if (!((_this$_cache$scope3 = this._cache[scope]) != null && _this$_cache$scope3[id])) {
837
- return;
838
- }
839
-
840
- delete this._cache[scope][id];
841
-
842
- if (Object.keys(this._cache[scope]).length === 0) {
843
- delete this._cache[scope];
844
- }
845
- }
846
- /**
847
- * Purge a scope of items that match the given predicate.
848
- *
849
- * If the predicate is omitted, then all items in the scope are purged.
850
- */
851
-
852
-
853
- purgeScope(scope, predicate) {
854
- if (!this._cache[scope]) {
855
- return;
856
- }
857
-
858
- if (predicate == null) {
859
- delete this._cache[scope];
860
- return;
861
- }
862
-
863
- for (const key of Object.keys(this._cache[scope])) {
864
- if (predicate(key, this._cache[scope][key])) {
865
- delete this._cache[scope][key];
866
- }
867
- }
868
-
869
- if (Object.keys(this._cache[scope]).length === 0) {
870
- delete this._cache[scope];
871
- }
872
- }
873
- /**
874
- * Purge all items from the cache that match the given predicate.
875
- *
876
- * If the predicate is omitted, then all items in the cache are purged.
877
- */
878
-
879
-
880
- purgeAll(predicate) {
881
- if (predicate == null) {
882
- this._cache = {};
883
- return;
884
- }
885
-
886
- for (const scope of Object.keys(this._cache)) {
887
- this.purgeScope(scope, (id, value) => predicate(scope, id, value));
888
- }
889
- }
890
-
891
- }
892
-
893
- /***/ }),
894
- /* 12 */
895
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
896
-
897
- "use strict";
898
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return WhenClientSide; });
899
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return useHydratableEffect; });
900
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
901
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
902
- /* harmony import */ var _use_server_effect_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(16);
903
- /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
904
- /* harmony import */ var _use_cached_effect_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(17);
905
- /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(3);
906
-
907
-
908
-
909
- // TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
910
- // have fixed:
911
- // https://github.com/import-js/eslint-plugin-import/issues/2073
912
- // eslint-disable-next-line import/named
913
-
914
-
915
-
916
- /**
917
- * Policies to define how a hydratable effect should behave client-side.
918
- */
919
- const WhenClientSide = __webpack_require__(23).Mirrored(["DoNotHydrate", "ExecuteWhenNoResult", "ExecuteWhenNoSuccessResult", "AlwaysExecute"]);
920
- const DefaultScope = "useHydratableEffect";
921
- /**
922
- * Hook to execute an async operation on server and client.
923
- *
924
- * This hook executes the given handler on the server and on the client,
925
- * and, depending on the given options, can hydrate the server-side result.
926
- *
927
- * Results are cached on the client so they can be shared between equivalent
928
- * invocations. Cache changes from one hook instance do not trigger renders
929
- * in components that use the same requestID.
930
- */
931
-
932
- const useHydratableEffect = (requestId, handler, options = {}) => {
933
- const {
934
- clientBehavior = WhenClientSide.ExecuteWhenNoSuccessResult,
935
- skip = false,
936
- retainResultOnChange = false,
937
- onResultChanged,
938
- scope = DefaultScope
939
- } = options; // Now we instruct the server to perform the operation.
940
- // When client-side, this will look up any response for hydration; it does
941
- // not invoke the handler.
942
-
943
- const serverResult = Object(_use_server_effect_js__WEBPACK_IMPORTED_MODULE_1__[/* useServerEffect */ "a"])(requestId, handler, {
944
- // Only hydrate if our behavior isn't telling us not to.
945
- hydrate: clientBehavior !== WhenClientSide.DoNotHydrate,
946
- skip
947
- });
948
- const getDefaultCacheValue = react__WEBPACK_IMPORTED_MODULE_0__["useCallback"](() => {
949
- // If we don't have a requestId, it's our first render, the one
950
- // where we hydrated. So defer to our clientBehavior value.
951
- switch (clientBehavior) {
952
- case WhenClientSide.DoNotHydrate:
953
- case WhenClientSide.AlwaysExecute:
954
- // Either we weren't hydrating at all, or we don't care
955
- // if we hydrated something or not, either way, we're
956
- // doing a request.
957
- return null;
958
-
959
- case WhenClientSide.ExecuteWhenNoResult:
960
- // We only execute if we didn't hydrate something.
961
- // So, returning the hydration result as default for our
962
- // cache, will then prevent the cached effect running.
963
- return serverResult;
964
-
965
- case WhenClientSide.ExecuteWhenNoSuccessResult:
966
- // We only execute if we didn't hydrate a success result.
967
- if ((serverResult == null ? void 0 : serverResult.status) === "success") {
968
- // So, returning the hydration result as default for our
969
- // cache, will then prevent the cached effect running.
970
- return serverResult;
971
- }
972
-
973
- return null;
974
- } // There is no reason for this to change after the first render,
975
- // you might think, but the function closes around serverResult and if
976
- // the requestId changes, it still returns the hydrate result of the
977
- // first render of the previous requestId. This then means that the
978
- // hydrate result is still the same, and the effect is not re-executed
979
- // because the cache gets incorrectly defaulted.
980
- // However, we don't want to bother doing anything with this on
981
- // client behavior changing since that truly is irrelevant.
982
- // eslint-disable-next-line react-hooks/exhaustive-deps
983
-
984
- }, [serverResult]); // Instead of using state, which would be local to just this hook instance,
985
- // we use a shared in-memory cache.
986
-
987
- Object(_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_2__[/* useSharedCache */ "b"])(requestId, // The key of the cached item
988
- scope, // The scope of the cached items
989
- getDefaultCacheValue); // When we're client-side, we ultimately want the result from this call.
990
-
991
- const [clientResult] = Object(_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_3__[/* useCachedEffect */ "a"])(requestId, handler, {
992
- skip,
993
- onResultChanged,
994
- retainResultOnChange,
995
- scope,
996
- // Be explicit about our fetch policy for clarity.
997
- fetchPolicy: _util_types_js__WEBPACK_IMPORTED_MODULE_4__[/* FetchPolicy */ "a"].CacheBeforeNetwork
998
- }); // OK, now which result do we return.
999
- // Well, we return the serverResult on our very first call and then
1000
- // the clientResult thereafter. The great thing is that after the very
1001
- // first call, the serverResult is going to be `null` anyway.
1002
-
1003
- return serverResult != null ? serverResult : clientResult;
1004
- };
1005
-
1006
- /***/ }),
1007
- /* 13 */
1008
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1009
-
1010
- "use strict";
1011
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SerializableInMemoryCache; });
1012
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
1013
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__);
1014
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
1015
- /* harmony import */ var _scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(11);
1016
-
1017
-
1018
-
1019
-
1020
- /**
1021
- * Describe a serializable in-memory cache.
1022
- */
1023
- class SerializableInMemoryCache extends _scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_2__[/* ScopedInMemoryCache */ "a"] {
1024
- constructor(initialCache = {}) {
1025
- try {
1026
- super(Object(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__["clone"])(initialCache));
1027
- } catch (e) {
1028
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataError */ "a"](`An error occurred trying to initialize from a response cache snapshot: ${e}`, _data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataErrors */ "b"].InvalidInput);
1029
- }
1030
- }
1031
- /**
1032
- * Set a value in the cache.
1033
- */
1034
-
1035
-
1036
- set(scope, id, value) {
1037
- super.set(scope, id, Object.freeze(Object(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__["clone"])(value)));
1038
- }
1039
- /**
1040
- * Clone the cache.
1041
- */
1042
-
1043
-
1044
- clone() {
1045
- try {
1046
- return Object(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__["clone"])(this._cache);
1047
- } catch (e) {
1048
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataError */ "a"]("An error occurred while trying to clone the cache", _data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataErrors */ "b"].Internal, {
1049
- cause: e
1050
- });
1051
- }
1052
- }
1053
-
1054
- }
1055
-
1056
- /***/ }),
1057
- /* 14 */
1058
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1059
-
1060
- "use strict";
1061
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1062
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1063
-
1064
-
1065
- /**
1066
- * InterceptContext defines a map from request ID to interception methods.
1067
- *
1068
- * INTERNAL USE ONLY
1069
- */
1070
- const InterceptContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"]([]);
1071
- /* harmony default export */ __webpack_exports__["a"] = (InterceptContext);
1072
-
1073
- /***/ }),
1074
- /* 15 */
1075
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1076
-
1077
- "use strict";
1078
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return initializeHydrationCache; });
1079
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return purgeHydrationCache; });
1080
- /* harmony import */ var _ssr_cache_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9);
1081
-
1082
-
1083
- /**
1084
- * Initialize the hydration cache.
1085
- *
1086
- * @param {ResponseCache} source The cache content to use for initializing the
1087
- * cache.
1088
- * @throws {Error} If the cache is already initialized.
1089
- */
1090
- const initializeHydrationCache = source => _ssr_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* SsrCache */ "a"].Default.initialize(source);
1091
- /**
1092
- * Purge cached hydration responses that match the given predicate.
1093
- *
1094
- * @param {(id: string) => boolean} [predicate] The predicate to match against
1095
- * the cached hydration responses. If no predicate is provided, all cached
1096
- * hydration responses will be purged.
1097
- */
1098
-
1099
- const purgeHydrationCache = predicate => _ssr_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* SsrCache */ "a"].Default.purgeData(predicate);
1100
-
1101
- /***/ }),
1102
- /* 16 */
1103
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1104
-
1105
- "use strict";
1106
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useServerEffect; });
1107
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
1108
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1109
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1);
1110
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
1111
- /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
1112
- /* harmony import */ var _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(9);
1113
- /* harmony import */ var _util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(33);
1114
- /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(20);
1115
-
1116
-
1117
-
1118
-
1119
-
1120
-
1121
-
1122
- /**
1123
- * Hook to perform an asynchronous action during server-side rendering.
1124
- *
1125
- * This hook registers an asynchronous action to be performed during
1126
- * server-side rendering. The action is performed only once, and the result
1127
- * is cached against the given identifier so that subsequent calls return that
1128
- * cached result allowing components to render more of the component.
1129
- *
1130
- * This hook requires the Wonder Blocks Data functionality for resolving
1131
- * pending requests, as well as support for the hydration cache to be
1132
- * embedded into a page so that the result can by hydrated (if that is a
1133
- * requirement).
1134
- *
1135
- * The asynchronous action is never invoked on the client-side.
1136
- */
1137
- const useServerEffect = (requestId, handler, options = {}) => {
1138
- const {
1139
- hydrate = true,
1140
- skip = false
1141
- } = options; // Plug in to the request interception framework for code that wants
1142
- // to use that.
1143
-
1144
- const interceptedHandler = Object(_use_request_interception_js__WEBPACK_IMPORTED_MODULE_5__[/* useRequestInterception */ "a"])(requestId, handler); // If we're server-side or hydrating, we'll have a cached entry to use.
1145
- // So we get that and use it to initialize our state.
1146
- // This works in both hydration and SSR because the very first call to
1147
- // this will have cached data in those cases as it will be present on the
1148
- // initial render - and subsequent renders on the client it will be null.
1149
-
1150
- const cachedResult = _util_ssr_cache_js__WEBPACK_IMPORTED_MODULE_3__[/* SsrCache */ "a"].Default.getEntry(requestId); // We only track data requests when we are server-side, we are not skipping
1151
- // the request, and we don't already have a result, as given by the
1152
- // cachedData (which is also the initial value for the result state).
1153
-
1154
- const maybeTrack = Object(react__WEBPACK_IMPORTED_MODULE_1__["useContext"])(_util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* TrackerContext */ "b"]);
1155
-
1156
- if (!skip && cachedResult == null && _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
1157
- maybeTrack == null ? void 0 : maybeTrack(requestId, interceptedHandler, hydrate);
1158
- } // A null result means there was no result to hydrate.
1159
-
1160
-
1161
- return cachedResult == null ? null : Object(_util_result_from_cache_response_js__WEBPACK_IMPORTED_MODULE_4__[/* resultFromCachedResponse */ "a"])(cachedResult);
1162
- };
1163
-
1164
- /***/ }),
1165
- /* 17 */
1166
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1167
-
1168
- "use strict";
1169
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useCachedEffect; });
1170
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1171
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1172
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
1173
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
1174
- /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(0);
1175
- /* harmony import */ var _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
1176
- /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(7);
1177
- /* harmony import */ var _use_shared_cache_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6);
1178
- /* harmony import */ var _use_request_interception_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(20);
1179
- /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(3);
1180
-
1181
-
1182
-
1183
-
1184
-
1185
-
1186
-
1187
- // TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
1188
- // have fixed:
1189
- // https://github.com/import-js/eslint-plugin-import/issues/2073
1190
- // eslint-disable-next-line import/named
1191
-
1192
- const DefaultScope = "useCachedEffect";
1193
- /**
1194
- * Hook to execute and cache an async operation on the client.
1195
- *
1196
- * This hook executes the given handler on the client if there is no
1197
- * cached result to use.
1198
- *
1199
- * Results are cached so they can be shared between equivalent invocations.
1200
- * In-flight requests are also shared, so that concurrent calls will
1201
- * behave as one might exect. Cache updates invoked by one hook instance
1202
- * do not trigger renders in components that use the same requestID; however,
1203
- * that should not matter since concurrent requests will share the same
1204
- * in-flight request, and subsequent renders will grab from the cache.
1205
- *
1206
- * Once the request has been tried once and a non-loading response has been
1207
- * cached, the request will not executed made again.
1208
- */
1209
-
1210
- const useCachedEffect = (requestId, handler, options = {}) => {
1211
- var _ref;
1212
-
1213
- const {
1214
- fetchPolicy = _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork,
1215
- skip: hardSkip = false,
1216
- retainResultOnChange = false,
1217
- onResultChanged,
1218
- scope = DefaultScope
1219
- } = options; // Plug in to the request interception framework for code that wants
1220
- // to use that.
1221
-
1222
- 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,
1223
- // we use a shared in-memory cache.
1224
-
1225
- const [mostRecentResult, setMostRecentResult] = Object(_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_5__[/* useSharedCache */ "b"])(requestId, // The key of the cached item
1226
- scope // The scope of the cached items
1227
- // No default value. We don't want the loading status there; to ensure
1228
- // that all calls when the request is in-flight will update once that
1229
- // request is done, we want the cache to be empty until that point.
1230
- );
1231
- const forceUpdate = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["useForceUpdate"])(); // For the NetworkOnly fetch policy, we ignore the cached value.
1232
- // So we need somewhere else to store the network value.
1233
-
1234
- const networkResultRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](); // Set up the function that will do the fetching.
1235
-
1236
- const currentRequestRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"]();
1237
- const fetchRequest = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"](() => {
1238
- var _currentRequestRef$cu;
1239
-
1240
- // We aren't using useCallback here because we need to make sure that
1241
- // if we are rememo-izing, we cancel any inflight request for the old
1242
- // callback.
1243
- (_currentRequestRef$cu = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu.cancel();
1244
- currentRequestRef.current = null;
1245
- networkResultRef.current = null;
1246
-
1247
- const fetchFn = () => {
1248
- var _currentRequestRef$cu2, _currentRequestRef$cu3;
1249
-
1250
- if (fetchPolicy === _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheOnly) {
1251
- 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);
1252
- } // We use our request fulfillment here so that in-flight
1253
- // requests are shared. In order to ensure that we don't share
1254
- // in-flight requests for different scopes, we add the scope to the
1255
- // requestId.
1256
- // We do this as a courtesy to simplify usage in sandboxed
1257
- // uses like storybook where we want each story to perform their
1258
- // own requests from scratch and not share inflight requests across
1259
- // stories.
1260
- // Since this only occurs here, nothing else will care about this
1261
- // change except the request tracking.
1262
-
1263
-
1264
- const request = _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__[/* RequestFulfillment */ "a"].Default.fulfill(`${requestId}|${scope}`, {
1265
- handler: interceptedHandler
1266
- });
1267
-
1268
- if (request === ((_currentRequestRef$cu2 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu2.request)) {
1269
- // The request inflight is the same, so do nothing.
1270
- // NOTE: Perhaps if invoked via a refetch, we will want to
1271
- // override this behavior and force a new request?
1272
- return;
1273
- } // Clear the last network result.
1274
-
1275
-
1276
- networkResultRef.current = null; // Cancel the previous request.
1277
-
1278
- (_currentRequestRef$cu3 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu3.cancel(); // TODO(somewhatabstract, FEI-4276):
1279
- // Until our RequestFulfillment API supports cancelling/aborting, we
1280
- // will have to do it.
1281
-
1282
- let cancel = false; // NOTE: Our request fulfillment handles the error cases here.
1283
- // Catching shouldn't serve a purpose.
1284
- // eslint-disable-next-line promise/catch-or-return
1285
-
1286
- request.then(result => {
1287
- currentRequestRef.current = null;
1288
-
1289
- if (cancel) {
1290
- // We don't modify our result if the request was cancelled
1291
- // as it means that this hook no longer cares about that old
1292
- // request.
1293
- return;
1294
- } // Now we need to update the cache and notify or force a rerender.
1295
-
1296
-
1297
- setMostRecentResult(result);
1298
- networkResultRef.current = result;
1299
-
1300
- if (onResultChanged != null) {
1301
- // If we have a callback, call it to let our caller know we
1302
- // got a result.
1303
- onResultChanged(result);
1304
- } else {
1305
- // If there's no callback, and this is using cache in some
1306
- // capacity, just force a rerender.
1307
- forceUpdate();
1308
- }
1309
-
1310
- return; // Shut up eslint always-return rule.
1311
- });
1312
- currentRequestRef.current = {
1313
- requestId,
1314
- request,
1315
-
1316
- cancel() {
1317
- cancel = true;
1318
- _util_request_fulfillment_js__WEBPACK_IMPORTED_MODULE_3__[/* RequestFulfillment */ "a"].Default.abort(requestId);
1319
- }
1320
-
1321
- };
1322
- }; // Now we can return the new fetch function.
1323
-
1324
-
1325
- return fetchFn; // We deliberately ignore the handler here because we want folks to use
1326
- // interceptor functions inline in props for simplicity. This is OK
1327
- // since changing the handler without changing the requestId doesn't
1328
- // really make sense - the same requestId should be handled the same as
1329
- // each other.
1330
- // eslint-disable-next-line react-hooks/exhaustive-deps
1331
- }, [requestId, onResultChanged, forceUpdate, setMostRecentResult, fetchPolicy]); // Calculate if we want to fetch the result or not.
1332
- // If this is true, we will do a new fetch, cancelling the previous fetch
1333
- // if there is one inflight.
1334
-
1335
- const shouldFetch = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"](() => {
1336
- if (hardSkip) {
1337
- // We don't fetch if we've been told to hard skip.
1338
- return false;
1339
- }
1340
-
1341
- switch (fetchPolicy) {
1342
- case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheOnly:
1343
- // Don't want to do a network request if we're only
1344
- // interested in the cache.
1345
- return false;
1346
-
1347
- case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheBeforeNetwork:
1348
- // If we don't have a cached value then we need to fetch.
1349
- return mostRecentResult == null;
1350
-
1351
- case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].CacheAndNetwork:
1352
- case _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly:
1353
- // We don't care about the cache. If we don't have a network
1354
- // result, then we need to fetch one.
1355
- return networkResultRef.current == null;
1356
- }
1357
- }, [mostRecentResult, fetchPolicy, hardSkip]);
1358
- react__WEBPACK_IMPORTED_MODULE_0__["useEffect"](() => {
1359
- if (!shouldFetch) {
1360
- return;
1361
- }
1362
-
1363
- fetchRequest();
1364
- return () => {
1365
- var _currentRequestRef$cu4;
1366
-
1367
- (_currentRequestRef$cu4 = currentRequestRef.current) == null ? void 0 : _currentRequestRef$cu4.cancel();
1368
- currentRequestRef.current = null;
1369
- };
1370
- }, [shouldFetch, fetchRequest]); // We track the last result we returned in order to support the
1371
- // "retainResultOnChange" option.
1372
-
1373
- const lastResultAgnosticOfIdRef = react__WEBPACK_IMPORTED_MODULE_0__["useRef"](_util_status_js__WEBPACK_IMPORTED_MODULE_4__[/* Status */ "a"].loading());
1374
- 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
1375
- // we cache.
1376
-
1377
- const result = (_ref = fetchPolicy === _util_types_js__WEBPACK_IMPORTED_MODULE_7__[/* FetchPolicy */ "a"].NetworkOnly ? networkResultRef.current : mostRecentResult) != null ? _ref : loadingResult;
1378
- lastResultAgnosticOfIdRef.current = result; // We return the result and a function for triggering a refetch.
1379
-
1380
- return [result, fetchRequest];
1381
- };
1382
-
1383
- /***/ }),
1384
- /* 18 */
1385
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1386
-
1387
- "use strict";
1388
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlDataFromResponse; });
1389
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1390
- /* harmony import */ var _gql_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
1391
-
1392
-
1393
- /**
1394
- * Validate a GQL operation response and extract the data.
1395
- */
1396
-
1397
- const getGqlDataFromResponse = async response => {
1398
- // Get the response as text, that way we can use the text in error
1399
- // messaging, should our parsing fail.
1400
- const bodyText = await response.text();
1401
- let result;
1402
-
1403
- try {
1404
- result = JSON.parse(bodyText);
1405
- } catch (e) {
1406
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Failed to parse response", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Parse, {
1407
- metadata: {
1408
- statusCode: response.status,
1409
- bodyText
1410
- },
1411
- cause: e
1412
- });
1413
- } // Check for a bad status code.
1414
-
1415
-
1416
- if (response.status >= 300) {
1417
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Response unsuccessful", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].Network, {
1418
- metadata: {
1419
- statusCode: response.status,
1420
- result
1421
- }
1422
- });
1423
- } // Check that we have a valid result payload.
1424
-
1425
-
1426
- if ( // Flow shouldn't be warning about this.
1427
- // $FlowIgnore[method-unbinding]
1428
- !Object.prototype.hasOwnProperty.call(result, "data") && // Flow shouldn't be warning about this.
1429
- // $FlowIgnore[method-unbinding]
1430
- !Object.prototype.hasOwnProperty.call(result, "errors")) {
1431
- throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("Server response missing", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].BadResponse, {
1432
- metadata: {
1433
- statusCode: response.status,
1434
- result
1435
- }
1436
- });
1437
- } // If the response payload has errors, throw an error.
1438
-
1439
-
1440
- if (result.errors != null && Array.isArray(result.errors) && result.errors.length > 0) {
1441
- throw new _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlError */ "a"]("GraphQL errors", _gql_error_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlErrors */ "b"].ErrorResult, {
1442
- metadata: {
1443
- statusCode: response.status,
1444
- result
1445
- }
1446
- });
1447
- } // We got here, so return the data.
1448
-
1449
-
1450
- return result.data;
1451
- };
1452
-
1453
- /***/ }),
1454
- /* 19 */
1455
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1456
-
1457
- "use strict";
1458
- /* unused harmony export DocumentTypes */
1459
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return graphQLDocumentNodeParser; });
1460
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1461
-
1462
- const DocumentTypes = Object.freeze({
1463
- query: "query",
1464
- mutation: "mutation"
1465
- });
1466
- const cache = new Map();
1467
- /**
1468
- * Parse a GraphQL document node to determine some info about it.
1469
- *
1470
- * This is based on:
1471
- * https://github.com/apollographql/react-apollo/blob/3bc993b2ea91704bd6a2667f42d1940656c071ff/src/parser.ts
1472
- */
1473
-
1474
- function graphQLDocumentNodeParser(document) {
1475
- var _definition$name;
1476
-
1477
- const cached = cache.get(document);
1478
-
1479
- if (cached) {
1480
- return cached;
1481
- }
1482
- /**
1483
- * Saftey check for proper usage.
1484
- */
1485
-
1486
-
1487
- if (!(document != null && document.kind)) {
1488
- if (true) {
1489
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Bad DocumentNode", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1490
- } else {}
1491
- }
1492
-
1493
- const fragments = document.definitions.filter(x => x.kind === "FragmentDefinition");
1494
- const queries = document.definitions.filter(x => // $FlowIgnore[prop-missing]
1495
- x.kind === "OperationDefinition" && x.operation === "query");
1496
- const mutations = document.definitions.filter(x => // $FlowIgnore[prop-missing]
1497
- x.kind === "OperationDefinition" && x.operation === "mutation");
1498
- const subscriptions = document.definitions.filter(x => // $FlowIgnore[prop-missing]
1499
- x.kind === "OperationDefinition" && x.operation === "subscription");
1500
-
1501
- if (fragments.length && !queries.length && !mutations.length) {
1502
- if (true) {
1503
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Fragment only", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1504
- } else {}
1505
- }
1506
-
1507
- if (subscriptions.length) {
1508
- if (true) {
1509
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("No subscriptions", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1510
- } else {}
1511
- }
1512
-
1513
- if (queries.length + mutations.length > 1) {
1514
- if (true) {
1515
- throw new _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataError */ "a"]("Too many ops", _data_error_js__WEBPACK_IMPORTED_MODULE_0__[/* DataErrors */ "b"].InvalidInput);
1516
- } else {}
1517
- }
1518
-
1519
- const type = queries.length ? DocumentTypes.query : DocumentTypes.mutation;
1520
- const definitions = queries.length ? queries : mutations;
1521
- const definition = definitions[0];
1522
- const variables = definition.variableDefinitions || []; // fallback to using data if no name
1523
-
1524
- const name = ((_definition$name = definition.name) == null ? void 0 : _definition$name.kind) === "Name" ? definition.name.value : "data";
1525
- const payload = {
1526
- name,
1527
- type,
1528
- variables
1529
- };
1530
- cache.set(document, payload);
1531
- return payload;
1532
- }
1533
-
1534
- /***/ }),
1535
- /* 20 */
1536
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1537
-
1538
- "use strict";
1539
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useRequestInterception; });
1540
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1541
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1542
- /* harmony import */ var _components_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14);
1543
-
1544
-
1545
-
1546
- /**
1547
- * Allow request handling to be intercepted.
1548
- *
1549
- * Hook to take a uniquely identified request handler and return a
1550
- * method that will support request interception from the InterceptRequest
1551
- * component.
1552
- *
1553
- * If you want request interception to be supported with `useServerEffect` or
1554
- * any client-side effect that uses the handler, call this first to generate
1555
- * an intercepted handler, and then invoke `useServerEffect` (or other things)
1556
- * with that intercepted handler.
1557
- */
1558
- const useRequestInterception = (requestId, handler) => {
1559
- // Get the interceptors that have been registered.
1560
- const interceptors = react__WEBPACK_IMPORTED_MODULE_0__["useContext"](_components_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"]); // Now, we need to create a new handler that will check if the
1561
- // request is intercepted before ultimately calling the original handler
1562
- // if nothing intercepted it.
1563
- // We memoize this so that it only changes if something related to it
1564
- // changes.
1565
-
1566
- const interceptedHandler = react__WEBPACK_IMPORTED_MODULE_0__["useCallback"](() => {
1567
- // Call the interceptors from closest to furthest.
1568
- // If one returns a non-null result, then we keep that.
1569
- const interceptResponse = interceptors.reduceRight((prev, interceptor) => {
1570
- if (prev != null) {
1571
- return prev;
1572
- }
1573
-
1574
- return interceptor(requestId);
1575
- }, null); // If nothing intercepted this request, invoke the original handler.
1576
- // NOTE: We can't guarantee all interceptors return the same type
1577
- // as our handler, so how can flow know? Let's just suppress that.
1578
- // $FlowFixMe[incompatible-return]
1579
-
1580
- return interceptResponse != null ? interceptResponse : handler();
1581
- }, [handler, interceptors, requestId]);
1582
- return interceptedHandler;
1583
- };
1584
-
1585
- /***/ }),
1586
- /* 21 */
1587
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1588
-
1589
- "use strict";
1590
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlRouterContext; });
1591
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1592
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1593
-
1594
- const GqlRouterContext = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createContext"](null);
1595
-
1596
- /***/ }),
1597
- /* 22 */
1598
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1599
-
1600
- "use strict";
1601
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mergeGqlContext; });
1602
- /**
1603
- * Construct a complete GqlContext from current defaults and a partial context.
1604
- *
1605
- * Values in the partial context that are `undefined` will be ignored.
1606
- * Values in the partial context that are `null` will be deleted.
1607
- */
1608
- const mergeGqlContext = (defaultContext, overrides) => {
1609
- // Let's merge the partial context default context. We deliberately
1610
- // don't spread because spreading would overwrite default context
1611
- // values with undefined or null if the partial context includes a value
1612
- // explicitly set to undefined or null.
1613
- return Object.keys(overrides).reduce((acc, key) => {
1614
- // Undefined values are ignored.
1615
- if (overrides[key] !== undefined) {
1616
- if (overrides[key] === null) {
1617
- // Null indicates we delete this context value.
1618
- delete acc[key];
1619
- } else {
1620
- // Otherwise, we set it.
1621
- acc[key] = overrides[key];
1622
- }
1623
- }
1624
-
1625
- return acc;
1626
- }, { ...defaultContext
1627
- });
1628
- };
1629
-
1630
- /***/ }),
1631
- /* 23 */
1632
- /***/ (function(module, exports) {
1633
-
1634
- module.exports = require("flow-enums-runtime");
1635
-
1636
- /***/ }),
1637
- /* 24 */
1638
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1639
-
1640
- "use strict";
1641
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return fetchTrackedRequests; });
1642
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return hasTrackedRequestsToBeFetched; });
1643
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return abortInflightRequests; });
1644
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
1645
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__);
1646
- /* harmony import */ var _request_tracking_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8);
1647
- /* harmony import */ var _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
1648
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(0);
1649
-
1650
-
1651
-
1652
-
1653
-
1654
- const SSRCheck = () => {
1655
- if (_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_0__["Server"].isServerSide()) {
1656
- return null;
1657
- }
1658
-
1659
- if (true) {
1660
- return new _data_error_js__WEBPACK_IMPORTED_MODULE_3__[/* DataError */ "a"]("No CSR tracking", _data_error_js__WEBPACK_IMPORTED_MODULE_3__[/* DataErrors */ "b"].NotAllowed);
1661
- } else {}
1662
- };
1663
- /**
1664
- * Fetches all tracked data requests.
1665
- *
1666
- * This is for use with the `TrackData` component during server-side rendering.
1667
- *
1668
- * @throws {Error} If executed outside of server-side rendering.
1669
- * @returns {Promise<void>} A promise that resolves when all tracked requests
1670
- * have been fetched.
1671
- */
1672
-
1673
-
1674
- const fetchTrackedRequests = () => {
1675
- const ssrCheck = SSRCheck();
1676
-
1677
- if (ssrCheck != null) {
1678
- return Promise.reject(ssrCheck);
1679
- }
1680
-
1681
- return _request_tracking_js__WEBPACK_IMPORTED_MODULE_1__[/* RequestTracker */ "a"].Default.fulfillTrackedRequests();
1682
- };
1683
- /**
1684
- * Indicate if there are tracked requests waiting to be fetched.
1685
- *
1686
- * This is used in conjunction with `TrackData`.
1687
- *
1688
- * @throws {Error} If executed outside of server-side rendering.
1689
- * @returns {boolean} `true` if there are unfetched tracked requests;
1690
- * otherwise, `false`.
1691
- */
1692
-
1693
- const hasTrackedRequestsToBeFetched = () => {
1694
- const ssrCheck = SSRCheck();
1695
-
1696
- if (ssrCheck != null) {
1697
- throw ssrCheck;
1698
- }
1699
-
1700
- return _request_tracking_js__WEBPACK_IMPORTED_MODULE_1__[/* RequestTracker */ "a"].Default.hasUnfulfilledRequests;
1701
- };
1702
- /**
1703
- * Abort all in-flight requests.
1704
- *
1705
- * This aborts all requests currently inflight via our default request
1706
- * fulfillment.
1707
- */
1708
-
1709
- const abortInflightRequests = () => {
1710
- _request_fulfillment_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestFulfillment */ "a"].Default.abortAll();
1711
- };
1712
-
1713
- /***/ }),
1714
- /* 25 */
1715
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1716
-
1717
- "use strict";
1718
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return purgeCaches; });
1719
- /* harmony import */ var _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
1720
- /* harmony import */ var _hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
1721
-
1722
-
1723
- /**
1724
- * Purge all caches managed by Wonder Blocks Data.
1725
- *
1726
- * This is a convenience method that purges the shared cache and the hydration
1727
- * cache. It is useful for testing purposes to avoid having to reason about
1728
- * which caches may have been used during a given test run.
1729
- */
1730
-
1731
- const purgeCaches = () => {
1732
- _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_0__[/* SharedCache */ "a"].purgeAll();
1733
- Object(_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__[/* purgeHydrationCache */ "b"])();
1734
- };
1735
-
1736
- /***/ }),
1737
- /* 26 */
1738
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1739
-
1740
- "use strict";
1741
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return TrackData; });
1742
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1743
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1744
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
1745
- /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__);
1746
- /* harmony import */ var _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
1747
-
1748
-
1749
-
1750
-
1751
- /**
1752
- * Component to enable data request tracking when server-side rendering.
1753
- */
1754
- class TrackData extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
1755
- render() {
1756
- if (!_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_1__["Server"].isServerSide()) {
1757
- throw new Error("This component is not for use during client-side rendering");
1758
- }
1759
-
1760
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* TrackerContext */ "b"].Provider, {
1761
- value: _util_request_tracking_js__WEBPACK_IMPORTED_MODULE_2__[/* RequestTracker */ "a"].Default.trackDataRequest
1762
- }, this.props.children);
1763
- }
1764
-
1765
- }
1766
-
1767
- /***/ }),
1768
- /* 27 */
1769
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1770
-
1771
- "use strict";
1772
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1773
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1774
- /* harmony import */ var _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
1775
-
1776
-
1777
-
1778
- /**
1779
- * This component is the main component of Wonder Blocks Data. With this, data
1780
- * requirements can be placed in a React application in a manner that will
1781
- * support server-side rendering and efficient caching.
1782
- */
1783
- const Data = ({
1784
- requestId,
1785
- handler,
1786
- children,
1787
- retainResultOnChange = false,
1788
- clientBehavior = _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_1__[/* WhenClientSide */ "a"].ExecuteWhenNoSuccessResult
1789
- }) => {
1790
- const result = Object(_hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_1__[/* useHydratableEffect */ "b"])(requestId, handler, {
1791
- retainResultOnChange,
1792
- clientBehavior
1793
- });
1794
- return children(result);
1795
- };
1796
-
1797
- /* harmony default export */ __webpack_exports__["a"] = (Data);
1798
-
1799
- /***/ }),
1800
- /* 28 */
1801
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1802
-
1803
- "use strict";
1804
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
1805
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1806
- /* harmony import */ var _intercept_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14);
1807
-
1808
-
1809
-
1810
- /**
1811
- * This component provides a mechanism to intercept data requests.
1812
- * This is for use in testing.
1813
- *
1814
- * This component is not recommended for use in production code as it
1815
- * can prevent predictable functioning of the Wonder Blocks Data framework.
1816
- * One possible side-effect is that inflight requests from the interceptor could
1817
- * be picked up by `Data` component requests from outside the children of this
1818
- * component.
1819
- *
1820
- * Interceptions within the same component tree are chained such that the
1821
- * interceptor closest to the intercepted request is called first, and the
1822
- * furthest interceptor is called last.
1823
- */
1824
- const InterceptRequests = ({
1825
- interceptor,
1826
- children
1827
- }) => {
1828
- const interceptors = react__WEBPACK_IMPORTED_MODULE_0__["useContext"](_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"]);
1829
- const updatedInterceptors = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"]( // We could build this in reverse order so that our hook that does
1830
- // the interception didn't have to use reduceRight, but I think it
1831
- // is easier to think about if we do this in component tree order.
1832
- () => [].concat(interceptors, [interceptor]), [interceptors, interceptor]);
1833
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_intercept_context_js__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"].Provider, {
1834
- value: updatedInterceptors
1835
- }, children);
1836
- };
1837
-
1838
- /* harmony default export */ __webpack_exports__["a"] = (InterceptRequests);
1839
-
1840
- /***/ }),
1841
- /* 29 */
1842
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1843
-
1844
- "use strict";
1845
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return getGqlRequestId; });
1846
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5);
1847
- /* harmony import */ var _khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__);
1848
-
1849
-
1850
- const toString = value => {
1851
- var _JSON$stringify;
1852
-
1853
- if (typeof value === "string") {
1854
- return value;
1855
- }
1856
-
1857
- if (typeof value === "object" && value != null) {
1858
- if (value instanceof Date) {
1859
- return value.toISOString();
1860
- } else if (typeof value.toString === "function") {
1861
- return value.toString();
1862
- }
1863
- }
1864
-
1865
- return (_JSON$stringify = JSON.stringify(value)) != null ? _JSON$stringify : "";
1866
- };
1867
-
1868
- const toStringifiedVariables = (acc, key, value) => {
1869
- if (typeof value === "object" && value !== null) {
1870
- // If we have an object or array, we build sub-variables so that
1871
- // the ID is easily human-readable rather than having lots of
1872
- // extra %-encodings. This means that an object or array variable
1873
- // turns into x variables, where x is the field or element count of
1874
- // variable. See below for example.
1875
- const subValues = Object(_khanacademy_wonder_stuff_core__WEBPACK_IMPORTED_MODULE_0__["entries"])(value); // If we don't get any entries, it's possible this is a Date, Error,
1876
- // or some other non-standard value. While these generally should be
1877
- // avoided as variables, we should handle them gracefully.
1878
-
1879
- if (subValues.length !== 0) {
1880
- return subValues.reduce((innerAcc, [i, v]) => {
1881
- const subKey = `${key}.${i}`;
1882
- return toStringifiedVariables(innerAcc, subKey, v);
1883
- }, acc);
1884
- }
1885
- }
1886
-
1887
- acc[key] = toString(value);
1888
- return acc;
1889
- };
1890
- /**
1891
- * Get an identifier for a given request.
1892
- */
1893
-
1894
-
1895
- const getGqlRequestId = (operation, variables, context) => {
1896
- // We add all the bits for this into an array and then join them with
1897
- // a chosen separator.
1898
- const parts = []; // First, we push the context values.
1899
-
1900
- const sortableContext = new URLSearchParams(context); // $FlowIgnore[prop-missing] Flow has incomplete support for URLSearchParams
1901
-
1902
- sortableContext.sort();
1903
- parts.push(sortableContext.toString()); // Now we add the operation identifier.
1904
-
1905
- parts.push(operation.id); // Finally, if we have variables, we add those too.
1906
-
1907
- if (variables != null) {
1908
- // We need to turn each variable into a string.
1909
- // We also need to ensure we sort any sub-object keys.
1910
- // `toStringifiedVariables` helps us with this by hoisting nested
1911
- // data to individual variables for the purposes of ID generation.
1912
- //
1913
- // For example, consider variables:
1914
- // {x: [1,2,3], y: {a: 1, b: 2, c: 3}, z: 123}
1915
- //
1916
- // Each variable, x, y and z, would be stringified into
1917
- // stringifiedVariables as follows:
1918
- // x becomes {"x.0": "1", "x.1": "2", "x.2": "3"}
1919
- // y becomes {"y.a": "1", "y.b": "2", "y.c": "3"}
1920
- // z becomes {"z": "123"}
1921
- //
1922
- // This then leads to stringifiedVariables being:
1923
- // {
1924
- // "x.0": "1",
1925
- // "x.1": "2",
1926
- // "x.2": "3",
1927
- // "y.a": "1",
1928
- // "y.b": "2",
1929
- // "y.c": "3",
1930
- // "z": "123",
1931
- // }
1932
- //
1933
- // Thus allowing our use of URLSearchParams to both sort and easily
1934
- // encode the variables into an idempotent identifier for those
1935
- // variable values that is also human-readable.
1936
- const stringifiedVariables = Object.keys(variables).reduce((acc, key) => {
1937
- const value = variables[key];
1938
- return toStringifiedVariables(acc, key, value);
1939
- }, {}); // We use the same mechanism as context to sort and arrange the
1940
- // variables.
1941
-
1942
- const sortableVariables = new URLSearchParams(stringifiedVariables); // $FlowIgnore[prop-missing] Flow has incomplete support for URLSearchParams
1943
-
1944
- sortableVariables.sort();
1945
- parts.push(sortableVariables.toString());
1946
- }
1947
-
1948
- return parts.join("|");
1949
- };
1950
-
1951
- /***/ }),
1952
- /* 30 */
1953
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1954
-
1955
- "use strict";
1956
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return toGqlOperation; });
1957
- /* harmony import */ var _graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(19);
1958
-
1959
-
1960
- /**
1961
- * Convert a GraphQL DocumentNode to a base Wonder Blocks Data GqlOperation.
1962
- *
1963
- * If you want to include the query/mutation body, extend the result of this
1964
- * method and use the `graphql/language/printer` like:
1965
- *
1966
- * ```js
1967
- * import {print} from "graphql/language/printer";
1968
- *
1969
- * const gqlOpWithBody = {
1970
- * ...toGqlOperation(documentNode),
1971
- * query: print(documentNode),
1972
- * };
1973
- * ```
1974
- *
1975
- * If you want to enforce inclusion of __typename properties, then you can use
1976
- * `apollo-utilities` first to modify the document:
1977
- *
1978
- * ```js
1979
- * import {print} from "graphql/language/printer";
1980
- * import {addTypenameToDocument} from "apollo-utilities";
1981
- *
1982
- * const documentWithTypenames = addTypenameToDocument(documentNode);
1983
- * const gqlOpWithBody = {
1984
- * ...toGqlOperation(documentWithTypenames),
1985
- * query: print(documentWithTypenames),
1986
- * };
1987
- * ```
1988
- */
1989
- const toGqlOperation = documentNode => {
1990
- const definition = Object(_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_0__[/* graphQLDocumentNodeParser */ "a"])(documentNode);
1991
- const wbDataOperation = {
1992
- id: definition.name,
1993
- type: definition.type
1994
- };
1995
- return wbDataOperation;
1996
- };
1997
-
1998
- /***/ }),
1999
- /* 31 */
2000
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
2001
-
2002
- "use strict";
2003
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return GqlRouter; });
2004
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
2005
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
2006
- /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21);
2007
-
2008
-
2009
-
2010
- /**
2011
- * Configure GraphQL routing for GraphQL hooks and components.
2012
- *
2013
- * These can be nested. Components and hooks relying on the GraphQL routing
2014
- * will use the configuration from their closest ancestral GqlRouter.
2015
- */
2016
- const GqlRouter = ({
2017
- defaultContext: thisDefaultContext,
2018
- fetch: thisFetch,
2019
- children
2020
- }) => {
2021
- // We don't care if we're nested. We always force our callers to define
2022
- // everything. It makes for a clearer API and requires less error checking
2023
- // code (assuming our flow types are correct). We also don't default fetch
2024
- // to anything - our callers can tell us what function to use quite easily.
2025
- // If code that consumes this wants more nuanced nesting, it can implement
2026
- // it within its own GqlRouter than then defers to this one.
2027
- // We want to always use the same object if things haven't changed to avoid
2028
- // over-rendering consumers of our context, let's memoize the configuration.
2029
- // By doing this, if a component under children that uses this context
2030
- // uses React.memo, we won't force it to re-render every time we render
2031
- // because we'll only change the context value if something has actually
2032
- // changed.
2033
- const configuration = react__WEBPACK_IMPORTED_MODULE_0__["useMemo"](() => ({
2034
- fetch: thisFetch,
2035
- defaultContext: thisDefaultContext
2036
- }), [thisDefaultContext, thisFetch]);
2037
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_1__[/* GqlRouterContext */ "a"].Provider, {
2038
- value: configuration
2039
- }, children);
2040
- };
2041
-
2042
- /***/ }),
2043
- /* 32 */
2044
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
2045
-
2046
- "use strict";
2047
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGql; });
2048
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
2049
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
2050
- /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22);
2051
- /* harmony import */ var _use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(34);
2052
- /* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(18);
2053
-
2054
-
2055
-
2056
-
2057
-
2058
- /**
2059
- * Hook to obtain a gqlFetch function for performing GraphQL requests.
2060
- *
2061
- * The fetch function will resolve null if the request was aborted, otherwise
2062
- * it will resolve the data returned by the GraphQL server.
2063
- *
2064
- * Context is merged with the default context provided to the GqlRouter.
2065
- * Values in the partial context given to the returned fetch function will
2066
- * only be included if they have a value other than undefined.
2067
- */
2068
- const useGql = (context = {}) => {
2069
- // This hook only works if the `GqlRouter` has been used to setup context.
2070
- const gqlRouterContext = Object(_use_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__[/* useGqlRouterContext */ "a"])(context); // Let's memoize the gqlFetch function we create based off our context.
2071
- // That way, even if the context happens to change, if its values don't
2072
- // we give the same function instance back to our callers instead of
2073
- // making a new one. That then means they can safely use the return value
2074
- // in hooks deps without fear of it triggering extra renders.
2075
-
2076
- const gqlFetch = Object(react__WEBPACK_IMPORTED_MODULE_0__["useCallback"])((operation, options = Object.freeze({})) => {
2077
- const {
2078
- fetch,
2079
- defaultContext
2080
- } = gqlRouterContext;
2081
- const {
2082
- variables,
2083
- context = {}
2084
- } = options;
2085
- const finalContext = Object(_util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__[/* mergeGqlContext */ "a"])(defaultContext, context); // Invoke the fetch and extract the data.
2086
-
2087
- return fetch(operation, variables, finalContext).then(_util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_3__[/* getGqlDataFromResponse */ "a"]);
2088
- }, [gqlRouterContext]);
2089
- return gqlFetch;
2090
- };
2091
-
2092
- /***/ }),
2093
- /* 33 */
2094
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
2095
-
2096
- "use strict";
2097
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return resultFromCachedResponse; });
2098
- /* harmony import */ var _status_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
2099
- /* harmony import */ var _data_error_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
2100
-
2101
-
2102
-
2103
- /**
2104
- * Turns a cache entry into a stateful result.
2105
- */
2106
- const resultFromCachedResponse = cacheEntry => {
2107
- // No cache entry means no result to be hydrated.
2108
- if (cacheEntry == null) {
2109
- return null;
2110
- }
2111
-
2112
- const {
2113
- data,
2114
- error
2115
- } = cacheEntry;
2116
-
2117
- if (error != null) {
2118
- // Let's hydrate the error. We don't persist everything about the
2119
- // original error on the server, hence why we only superficially
2120
- // hydrate it to a GqlHydratedError.
2121
- return _status_js__WEBPACK_IMPORTED_MODULE_0__[/* Status */ "a"].error(new _data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataError */ "a"](error, _data_error_js__WEBPACK_IMPORTED_MODULE_1__[/* DataErrors */ "b"].Hydrated));
2122
- }
2123
-
2124
- if (data != null) {
2125
- return _status_js__WEBPACK_IMPORTED_MODULE_0__[/* Status */ "a"].success(data);
2126
- } // We shouldn't get here since we don't actually cache null data.
2127
-
2128
-
2129
- return _status_js__WEBPACK_IMPORTED_MODULE_0__[/* Status */ "a"].aborted();
2130
- };
2131
-
2132
- /***/ }),
2133
- /* 34 */
2134
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
2135
-
2136
- "use strict";
2137
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return useGqlRouterContext; });
2138
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
2139
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
2140
- /* harmony import */ var _util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(22);
2141
- /* harmony import */ var _util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(21);
2142
- /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
2143
-
2144
-
2145
-
2146
-
2147
-
2148
- /**
2149
- * Construct a GqlRouterContext from the current one and partial context.
2150
- */
2151
- const useGqlRouterContext = (contextOverrides = {}) => {
2152
- // This hook only works if the `GqlRouter` has been used to setup context.
2153
- const gqlRouterContext = Object(react__WEBPACK_IMPORTED_MODULE_0__["useContext"])(_util_gql_router_context_js__WEBPACK_IMPORTED_MODULE_2__[/* GqlRouterContext */ "a"]);
2154
-
2155
- if (gqlRouterContext == null) {
2156
- throw new _util_gql_error_js__WEBPACK_IMPORTED_MODULE_3__[/* GqlError */ "a"]("No GqlRouter", _util_gql_error_js__WEBPACK_IMPORTED_MODULE_3__[/* GqlErrors */ "b"].Internal);
2157
- }
2158
-
2159
- const {
2160
- fetch,
2161
- defaultContext
2162
- } = gqlRouterContext;
2163
- const contextRef = Object(react__WEBPACK_IMPORTED_MODULE_0__["useRef"])(defaultContext);
2164
- const mergedContext = Object(_util_merge_gql_context_js__WEBPACK_IMPORTED_MODULE_1__[/* mergeGqlContext */ "a"])(defaultContext, contextOverrides); // Now, we can see if this represents a new context and if so,
2165
- // update our ref and return the merged value.
2166
-
2167
- const refKeys = Object.keys(contextRef.current);
2168
- const mergedKeys = Object.keys(mergedContext);
2169
- const shouldWeUpdateRef = refKeys.length !== mergedKeys.length || mergedKeys.every(key => contextRef.current[key] !== mergedContext[key]);
2170
-
2171
- if (shouldWeUpdateRef) {
2172
- contextRef.current = mergedContext;
2173
- } // OK, now we're up-to-date, let's memoize our final result.
2174
-
2175
-
2176
- const finalContext = contextRef.current;
2177
- const finalRouterContext = Object(react__WEBPACK_IMPORTED_MODULE_0__["useMemo"])(() => ({
2178
- fetch,
2179
- defaultContext: finalContext
2180
- }), [fetch, finalContext]);
2181
- return finalRouterContext;
2182
- };
2183
-
2184
- /***/ }),
2185
- /* 35 */
2186
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
2187
-
2188
- "use strict";
2189
- __webpack_require__.r(__webpack_exports__);
2190
- /* harmony import */ var _util_types_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3);
2191
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "FetchPolicy", function() { return _util_types_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
2192
-
2193
- /* harmony import */ var _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
2194
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "initializeHydrationCache", function() { return _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
2195
-
2196
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeHydrationCache", function() { return _util_hydration_cache_api_js__WEBPACK_IMPORTED_MODULE_1__["b"]; });
2197
-
2198
- /* harmony import */ var _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(24);
2199
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fetchTrackedRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["b"]; });
2200
-
2201
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "hasTrackedRequestsToBeFetched", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["c"]; });
2202
-
2203
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "abortInflightRequests", function() { return _util_request_api_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
2204
-
2205
- /* harmony import */ var _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(25);
2206
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "purgeCaches", function() { return _util_purge_caches_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
2207
-
2208
- /* harmony import */ var _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(26);
2209
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "TrackData", function() { return _components_track_data_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
2210
-
2211
- /* harmony import */ var _components_data_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(27);
2212
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Data", function() { return _components_data_js__WEBPACK_IMPORTED_MODULE_5__["a"]; });
2213
-
2214
- /* harmony import */ var _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(28);
2215
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "InterceptRequests", function() { return _components_intercept_requests_js__WEBPACK_IMPORTED_MODULE_6__["a"]; });
2216
-
2217
- /* harmony import */ var _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(0);
2218
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataError", function() { return _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__["a"]; });
2219
-
2220
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DataErrors", function() { return _util_data_error_js__WEBPACK_IMPORTED_MODULE_7__["b"]; });
2221
-
2222
- /* harmony import */ var _hooks_use_server_effect_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(16);
2223
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useServerEffect", function() { return _hooks_use_server_effect_js__WEBPACK_IMPORTED_MODULE_8__["a"]; });
2224
-
2225
- /* harmony import */ var _hooks_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(17);
2226
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useCachedEffect", function() { return _hooks_use_cached_effect_js__WEBPACK_IMPORTED_MODULE_9__["a"]; });
2227
-
2228
- /* harmony import */ var _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(6);
2229
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useSharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__["b"]; });
2230
-
2231
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SharedCache", function() { return _hooks_use_shared_cache_js__WEBPACK_IMPORTED_MODULE_10__["a"]; });
2232
-
2233
- /* harmony import */ var _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(12);
2234
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useHydratableEffect", function() { return _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__["b"]; });
2235
-
2236
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "WhenClientSide", function() { return _hooks_use_hydratable_effect_js__WEBPACK_IMPORTED_MODULE_11__["a"]; });
2237
-
2238
- /* harmony import */ var _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(11);
2239
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ScopedInMemoryCache", function() { return _util_scoped_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_12__["a"]; });
2240
-
2241
- /* harmony import */ var _util_serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(13);
2242
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SerializableInMemoryCache", function() { return _util_serializable_in_memory_cache_js__WEBPACK_IMPORTED_MODULE_13__["a"]; });
2243
-
2244
- /* harmony import */ var _util_status_js__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(7);
2245
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Status", function() { return _util_status_js__WEBPACK_IMPORTED_MODULE_14__["a"]; });
2246
-
2247
- /* harmony import */ var _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(29);
2248
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getGqlRequestId", function() { return _util_get_gql_request_id_js__WEBPACK_IMPORTED_MODULE_15__["a"]; });
2249
-
2250
- /* harmony import */ var _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(18);
2251
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getGqlDataFromResponse", function() { return _util_get_gql_data_from_response_js__WEBPACK_IMPORTED_MODULE_16__["a"]; });
2252
-
2253
- /* harmony import */ var _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(19);
2254
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "graphQLDocumentNodeParser", function() { return _util_graphql_document_node_parser_js__WEBPACK_IMPORTED_MODULE_17__["a"]; });
2255
-
2256
- /* harmony import */ var _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(30);
2257
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "toGqlOperation", function() { return _util_to_gql_operation_js__WEBPACK_IMPORTED_MODULE_18__["a"]; });
2258
-
2259
- /* harmony import */ var _components_gql_router_js__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(31);
2260
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlRouter", function() { return _components_gql_router_js__WEBPACK_IMPORTED_MODULE_19__["a"]; });
2261
-
2262
- /* harmony import */ var _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(32);
2263
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "useGql", function() { return _hooks_use_gql_js__WEBPACK_IMPORTED_MODULE_20__["a"]; });
2264
-
2265
- /* harmony import */ var _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(4);
2266
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlError", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__["a"]; });
2267
-
2268
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GqlErrors", function() { return _util_gql_error_js__WEBPACK_IMPORTED_MODULE_21__["b"]; });
2269
-
2270
- // TODO(somewhatabstract, FEI-4174): Update eslint-plugin-import when they
2271
- // have fixed:
2272
- // https://github.com/import-js/eslint-plugin-import/issues/2073
2273
- // eslint-disable-next-line import/named
2274
-
2275
-
2276
-
2277
-
2278
-
2279
-
2280
-
2281
-
2282
-
2283
-
2284
-
2285
-
2286
-
2287
-
2288
- ////////////////////////////////////////////////////////////////////////////////
2289
- // GraphQL
2290
- ////////////////////////////////////////////////////////////////////////////////
2291
-
2292
-
2293
-
2294
-
2295
-
2296
-
2297
-
2298
-
2299
-
2300
- /***/ })
2301
- /******/ ]);