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