@khanacademy/wonder-blocks-data 11.0.5 → 11.0.6
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 +8 -0
- package/dist/es/index.js +72 -165
- package/dist/index.js +72 -165
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -10,64 +10,6 @@ const FetchPolicy = {
|
|
|
10
10
|
NetworkOnly: "NetworkOnly"
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
function _typeof(obj) {
|
|
14
|
-
"@babel/helpers - typeof";
|
|
15
|
-
|
|
16
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
17
|
-
return typeof obj;
|
|
18
|
-
} : function (obj) {
|
|
19
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
20
|
-
}, _typeof(obj);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function _toPrimitive(input, hint) {
|
|
24
|
-
if (_typeof(input) !== "object" || input === null) return input;
|
|
25
|
-
var prim = input[Symbol.toPrimitive];
|
|
26
|
-
if (prim !== undefined) {
|
|
27
|
-
var res = prim.call(input, hint || "default");
|
|
28
|
-
if (_typeof(res) !== "object") return res;
|
|
29
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
30
|
-
}
|
|
31
|
-
return (hint === "string" ? String : Number)(input);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function _toPropertyKey(arg) {
|
|
35
|
-
var key = _toPrimitive(arg, "string");
|
|
36
|
-
return _typeof(key) === "symbol" ? key : String(key);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function _defineProperties(target, props) {
|
|
40
|
-
for (var i = 0; i < props.length; i++) {
|
|
41
|
-
var descriptor = props[i];
|
|
42
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
43
|
-
descriptor.configurable = true;
|
|
44
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
45
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
49
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
50
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
51
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
52
|
-
writable: false
|
|
53
|
-
});
|
|
54
|
-
return Constructor;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function _setPrototypeOf(o, p) {
|
|
58
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
59
|
-
o.__proto__ = p;
|
|
60
|
-
return o;
|
|
61
|
-
};
|
|
62
|
-
return _setPrototypeOf(o, p);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function _inheritsLoose(subClass, superClass) {
|
|
66
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
67
|
-
subClass.prototype.constructor = subClass;
|
|
68
|
-
_setPrototypeOf(subClass, superClass);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
13
|
const DataErrors = Object.freeze({
|
|
72
14
|
Unknown: "Unknown",
|
|
73
15
|
Internal: "Internal",
|
|
@@ -77,28 +19,28 @@ const DataErrors = Object.freeze({
|
|
|
77
19
|
Parse: "Parse",
|
|
78
20
|
Hydrated: "Hydrated"
|
|
79
21
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
function DataError(message, kind, {
|
|
22
|
+
class DataError extends KindError {
|
|
23
|
+
constructor(message, kind, {
|
|
83
24
|
metadata,
|
|
84
25
|
cause
|
|
85
26
|
} = {}) {
|
|
86
|
-
|
|
27
|
+
super(message, kind, {
|
|
87
28
|
metadata,
|
|
88
29
|
cause,
|
|
89
30
|
name: "Data"
|
|
90
|
-
})
|
|
31
|
+
});
|
|
91
32
|
}
|
|
92
|
-
|
|
93
|
-
}(KindError);
|
|
33
|
+
}
|
|
94
34
|
|
|
95
|
-
|
|
96
|
-
|
|
35
|
+
class ScopedInMemoryCache {
|
|
36
|
+
constructor(initialCache = {}) {
|
|
97
37
|
this._cache = void 0;
|
|
98
38
|
this._cache = initialCache;
|
|
99
39
|
}
|
|
100
|
-
|
|
101
|
-
|
|
40
|
+
get inUse() {
|
|
41
|
+
return Object.keys(this._cache).length > 0;
|
|
42
|
+
}
|
|
43
|
+
set(scope, id, value) {
|
|
102
44
|
var _this$_cache$scope;
|
|
103
45
|
if (!id || typeof id !== "string") {
|
|
104
46
|
throw new DataError("id must be non-empty string", DataErrors.InvalidInput);
|
|
@@ -111,12 +53,12 @@ let ScopedInMemoryCache = function () {
|
|
|
111
53
|
}
|
|
112
54
|
this._cache[scope] = (_this$_cache$scope = this._cache[scope]) != null ? _this$_cache$scope : {};
|
|
113
55
|
this._cache[scope][id] = value;
|
|
114
|
-
}
|
|
115
|
-
|
|
56
|
+
}
|
|
57
|
+
get(scope, id) {
|
|
116
58
|
var _this$_cache$scope$id, _this$_cache$scope2;
|
|
117
59
|
return (_this$_cache$scope$id = (_this$_cache$scope2 = this._cache[scope]) == null ? void 0 : _this$_cache$scope2[id]) != null ? _this$_cache$scope$id : null;
|
|
118
|
-
}
|
|
119
|
-
|
|
60
|
+
}
|
|
61
|
+
purge(scope, id) {
|
|
120
62
|
var _this$_cache$scope3;
|
|
121
63
|
if (!((_this$_cache$scope3 = this._cache[scope]) != null && _this$_cache$scope3[id])) {
|
|
122
64
|
return;
|
|
@@ -125,8 +67,8 @@ let ScopedInMemoryCache = function () {
|
|
|
125
67
|
if (Object.keys(this._cache[scope]).length === 0) {
|
|
126
68
|
delete this._cache[scope];
|
|
127
69
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
70
|
+
}
|
|
71
|
+
purgeScope(scope, predicate) {
|
|
130
72
|
if (!this._cache[scope]) {
|
|
131
73
|
return;
|
|
132
74
|
}
|
|
@@ -142,8 +84,8 @@ let ScopedInMemoryCache = function () {
|
|
|
142
84
|
if (Object.keys(this._cache[scope]).length === 0) {
|
|
143
85
|
delete this._cache[scope];
|
|
144
86
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
87
|
+
}
|
|
88
|
+
purgeAll(predicate) {
|
|
147
89
|
if (predicate == null) {
|
|
148
90
|
this._cache = {};
|
|
149
91
|
return;
|
|
@@ -151,32 +93,21 @@ let ScopedInMemoryCache = function () {
|
|
|
151
93
|
for (const scope of Object.keys(this._cache)) {
|
|
152
94
|
this.purgeScope(scope, (id, value) => predicate(scope, id, value));
|
|
153
95
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
}]);
|
|
161
|
-
return ScopedInMemoryCache;
|
|
162
|
-
}();
|
|
163
|
-
|
|
164
|
-
let SerializableInMemoryCache = function (_ScopedInMemoryCache) {
|
|
165
|
-
_inheritsLoose(SerializableInMemoryCache, _ScopedInMemoryCache);
|
|
166
|
-
function SerializableInMemoryCache(initialCache = {}) {
|
|
167
|
-
var _this;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class SerializableInMemoryCache extends ScopedInMemoryCache {
|
|
100
|
+
constructor(initialCache = {}) {
|
|
168
101
|
try {
|
|
169
|
-
|
|
102
|
+
super(clone(initialCache));
|
|
170
103
|
} catch (e) {
|
|
171
104
|
throw new DataError(`An error occurred trying to initialize from a response cache snapshot: ${e}`, DataErrors.InvalidInput);
|
|
172
105
|
}
|
|
173
|
-
return _this;
|
|
174
106
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
_proto.clone = function clone$1() {
|
|
107
|
+
set(scope, id, value) {
|
|
108
|
+
super.set(scope, id, Object.freeze(clone(value)));
|
|
109
|
+
}
|
|
110
|
+
clone() {
|
|
180
111
|
try {
|
|
181
112
|
return clone(this._cache);
|
|
182
113
|
} catch (e) {
|
|
@@ -184,14 +115,19 @@ let SerializableInMemoryCache = function (_ScopedInMemoryCache) {
|
|
|
184
115
|
cause: e
|
|
185
116
|
});
|
|
186
117
|
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
}(ScopedInMemoryCache);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
190
120
|
|
|
191
121
|
const DefaultScope$2 = "default";
|
|
192
122
|
let _default$2;
|
|
193
|
-
|
|
194
|
-
|
|
123
|
+
class SsrCache {
|
|
124
|
+
static get Default() {
|
|
125
|
+
if (!_default$2) {
|
|
126
|
+
_default$2 = new SsrCache();
|
|
127
|
+
}
|
|
128
|
+
return _default$2;
|
|
129
|
+
}
|
|
130
|
+
constructor(hydrationCache = null, ssrOnlyCache = null) {
|
|
195
131
|
this._hydrationCache = void 0;
|
|
196
132
|
this._ssrOnlyCache = void 0;
|
|
197
133
|
this.initialize = source => {
|
|
@@ -232,8 +168,7 @@ let SsrCache = function () {
|
|
|
232
168
|
this._ssrOnlyCache = ssrOnlyCache || new SerializableInMemoryCache();
|
|
233
169
|
this._hydrationCache = hydrationCache || new SerializableInMemoryCache();
|
|
234
170
|
}
|
|
235
|
-
|
|
236
|
-
_proto._setCachedResponse = function _setCachedResponse(id, entry, hydrate) {
|
|
171
|
+
_setCachedResponse(id, entry, hydrate) {
|
|
237
172
|
const frozenEntry = Object.freeze(entry);
|
|
238
173
|
if (Server.isServerSide()) {
|
|
239
174
|
if (hydrate) {
|
|
@@ -243,18 +178,8 @@ let SsrCache = function () {
|
|
|
243
178
|
}
|
|
244
179
|
}
|
|
245
180
|
return frozenEntry;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
key: "Default",
|
|
249
|
-
get: function () {
|
|
250
|
-
if (!_default$2) {
|
|
251
|
-
_default$2 = new SsrCache();
|
|
252
|
-
}
|
|
253
|
-
return _default$2;
|
|
254
|
-
}
|
|
255
|
-
}]);
|
|
256
|
-
return SsrCache;
|
|
257
|
-
}();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
258
183
|
|
|
259
184
|
const initializeHydrationCache = source => SsrCache.Default.initialize(source);
|
|
260
185
|
const purgeHydrationCache = predicate => SsrCache.Default.purgeData(predicate);
|
|
@@ -275,8 +200,8 @@ function _extends() {
|
|
|
275
200
|
}
|
|
276
201
|
|
|
277
202
|
let _default$1;
|
|
278
|
-
|
|
279
|
-
|
|
203
|
+
class RequestFulfillment {
|
|
204
|
+
constructor() {
|
|
280
205
|
this._requests = {};
|
|
281
206
|
this.fulfill = (id, {
|
|
282
207
|
handler,
|
|
@@ -317,22 +242,24 @@ let RequestFulfillment = function () {
|
|
|
317
242
|
Object.keys(this._requests).forEach(id => this.abort(id));
|
|
318
243
|
};
|
|
319
244
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (!_default$1) {
|
|
324
|
-
_default$1 = new RequestFulfillment();
|
|
325
|
-
}
|
|
326
|
-
return _default$1;
|
|
245
|
+
static get Default() {
|
|
246
|
+
if (!_default$1) {
|
|
247
|
+
_default$1 = new RequestFulfillment();
|
|
327
248
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
249
|
+
return _default$1;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
331
252
|
|
|
332
253
|
const TrackerContext = React.createContext(null);
|
|
333
254
|
let _default;
|
|
334
|
-
|
|
335
|
-
|
|
255
|
+
class RequestTracker {
|
|
256
|
+
static get Default() {
|
|
257
|
+
if (!_default) {
|
|
258
|
+
_default = new RequestTracker();
|
|
259
|
+
}
|
|
260
|
+
return _default;
|
|
261
|
+
}
|
|
262
|
+
constructor(responseCache = undefined) {
|
|
336
263
|
this._trackedRequests = {};
|
|
337
264
|
this._responseCache = void 0;
|
|
338
265
|
this._requestFulfillment = void 0;
|
|
@@ -377,22 +304,10 @@ let RequestTracker = function () {
|
|
|
377
304
|
this._responseCache = responseCache || SsrCache.Default;
|
|
378
305
|
this._requestFulfillment = new RequestFulfillment();
|
|
379
306
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
}], [{
|
|
386
|
-
key: "Default",
|
|
387
|
-
get: function () {
|
|
388
|
-
if (!_default) {
|
|
389
|
-
_default = new RequestTracker();
|
|
390
|
-
}
|
|
391
|
-
return _default;
|
|
392
|
-
}
|
|
393
|
-
}]);
|
|
394
|
-
return RequestTracker;
|
|
395
|
-
}();
|
|
307
|
+
get hasUnfulfilledRequests() {
|
|
308
|
+
return Object.keys(this._trackedRequests).length > 0;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
396
311
|
|
|
397
312
|
const SSRCheck = () => {
|
|
398
313
|
if (Server.isServerSide()) {
|
|
@@ -448,22 +363,16 @@ const purgeCaches = () => {
|
|
|
448
363
|
purgeHydrationCache();
|
|
449
364
|
};
|
|
450
365
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
function TrackData() {
|
|
454
|
-
return _React$Component.apply(this, arguments) || this;
|
|
455
|
-
}
|
|
456
|
-
var _proto = TrackData.prototype;
|
|
457
|
-
_proto.render = function render() {
|
|
366
|
+
class TrackData extends React.Component {
|
|
367
|
+
render() {
|
|
458
368
|
if (!Server.isServerSide()) {
|
|
459
369
|
throw new Error("This component is not for use during client-side rendering");
|
|
460
370
|
}
|
|
461
371
|
return React.createElement(TrackerContext.Provider, {
|
|
462
372
|
value: RequestTracker.Default.trackDataRequest
|
|
463
373
|
}, this.props.children);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
}(React.Component);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
467
376
|
|
|
468
377
|
const loadingStatus = Object.freeze({
|
|
469
378
|
status: "loading"
|
|
@@ -685,7 +594,7 @@ const InterceptRequests = ({
|
|
|
685
594
|
children
|
|
686
595
|
}) => {
|
|
687
596
|
const interceptors = React.useContext(InterceptContext);
|
|
688
|
-
const updatedInterceptors = React.useMemo(() => [
|
|
597
|
+
const updatedInterceptors = React.useMemo(() => [...interceptors, interceptor], [interceptors, interceptor]);
|
|
689
598
|
return React.createElement(InterceptContext.Provider, {
|
|
690
599
|
value: updatedInterceptors
|
|
691
600
|
}, children);
|
|
@@ -741,20 +650,18 @@ const GqlErrors = Object.freeze({
|
|
|
741
650
|
BadResponse: "BadResponse",
|
|
742
651
|
ErrorResult: "ErrorResult"
|
|
743
652
|
});
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
function GqlError(message, kind, {
|
|
653
|
+
class GqlError extends KindError {
|
|
654
|
+
constructor(message, kind, {
|
|
747
655
|
metadata,
|
|
748
656
|
cause
|
|
749
657
|
} = {}) {
|
|
750
|
-
|
|
658
|
+
super(message, kind, {
|
|
751
659
|
metadata,
|
|
752
660
|
cause,
|
|
753
661
|
name: "Gql"
|
|
754
|
-
})
|
|
662
|
+
});
|
|
755
663
|
}
|
|
756
|
-
|
|
757
|
-
}(KindError);
|
|
664
|
+
}
|
|
758
665
|
|
|
759
666
|
const getGqlDataFromResponse = async response => {
|
|
760
667
|
const bodyText = await response.text();
|
package/dist/index.js
CHANGED
|
@@ -33,64 +33,6 @@ const FetchPolicy = {
|
|
|
33
33
|
NetworkOnly: "NetworkOnly"
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
function _typeof(obj) {
|
|
37
|
-
"@babel/helpers - typeof";
|
|
38
|
-
|
|
39
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
40
|
-
return typeof obj;
|
|
41
|
-
} : function (obj) {
|
|
42
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
43
|
-
}, _typeof(obj);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function _toPrimitive(input, hint) {
|
|
47
|
-
if (_typeof(input) !== "object" || input === null) return input;
|
|
48
|
-
var prim = input[Symbol.toPrimitive];
|
|
49
|
-
if (prim !== undefined) {
|
|
50
|
-
var res = prim.call(input, hint || "default");
|
|
51
|
-
if (_typeof(res) !== "object") return res;
|
|
52
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
53
|
-
}
|
|
54
|
-
return (hint === "string" ? String : Number)(input);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function _toPropertyKey(arg) {
|
|
58
|
-
var key = _toPrimitive(arg, "string");
|
|
59
|
-
return _typeof(key) === "symbol" ? key : String(key);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function _defineProperties(target, props) {
|
|
63
|
-
for (var i = 0; i < props.length; i++) {
|
|
64
|
-
var descriptor = props[i];
|
|
65
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
66
|
-
descriptor.configurable = true;
|
|
67
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
68
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
72
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
73
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
74
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
75
|
-
writable: false
|
|
76
|
-
});
|
|
77
|
-
return Constructor;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function _setPrototypeOf(o, p) {
|
|
81
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
82
|
-
o.__proto__ = p;
|
|
83
|
-
return o;
|
|
84
|
-
};
|
|
85
|
-
return _setPrototypeOf(o, p);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function _inheritsLoose(subClass, superClass) {
|
|
89
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
90
|
-
subClass.prototype.constructor = subClass;
|
|
91
|
-
_setPrototypeOf(subClass, superClass);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
36
|
const DataErrors = Object.freeze({
|
|
95
37
|
Unknown: "Unknown",
|
|
96
38
|
Internal: "Internal",
|
|
@@ -100,28 +42,28 @@ const DataErrors = Object.freeze({
|
|
|
100
42
|
Parse: "Parse",
|
|
101
43
|
Hydrated: "Hydrated"
|
|
102
44
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
function DataError(message, kind, {
|
|
45
|
+
class DataError extends wonderStuffCore.KindError {
|
|
46
|
+
constructor(message, kind, {
|
|
106
47
|
metadata,
|
|
107
48
|
cause
|
|
108
49
|
} = {}) {
|
|
109
|
-
|
|
50
|
+
super(message, kind, {
|
|
110
51
|
metadata,
|
|
111
52
|
cause,
|
|
112
53
|
name: "Data"
|
|
113
|
-
})
|
|
54
|
+
});
|
|
114
55
|
}
|
|
115
|
-
|
|
116
|
-
}(wonderStuffCore.KindError);
|
|
56
|
+
}
|
|
117
57
|
|
|
118
|
-
|
|
119
|
-
|
|
58
|
+
class ScopedInMemoryCache {
|
|
59
|
+
constructor(initialCache = {}) {
|
|
120
60
|
this._cache = void 0;
|
|
121
61
|
this._cache = initialCache;
|
|
122
62
|
}
|
|
123
|
-
|
|
124
|
-
|
|
63
|
+
get inUse() {
|
|
64
|
+
return Object.keys(this._cache).length > 0;
|
|
65
|
+
}
|
|
66
|
+
set(scope, id, value) {
|
|
125
67
|
var _this$_cache$scope;
|
|
126
68
|
if (!id || typeof id !== "string") {
|
|
127
69
|
throw new DataError("id must be non-empty string", DataErrors.InvalidInput);
|
|
@@ -134,12 +76,12 @@ let ScopedInMemoryCache = function () {
|
|
|
134
76
|
}
|
|
135
77
|
this._cache[scope] = (_this$_cache$scope = this._cache[scope]) != null ? _this$_cache$scope : {};
|
|
136
78
|
this._cache[scope][id] = value;
|
|
137
|
-
}
|
|
138
|
-
|
|
79
|
+
}
|
|
80
|
+
get(scope, id) {
|
|
139
81
|
var _this$_cache$scope$id, _this$_cache$scope2;
|
|
140
82
|
return (_this$_cache$scope$id = (_this$_cache$scope2 = this._cache[scope]) == null ? void 0 : _this$_cache$scope2[id]) != null ? _this$_cache$scope$id : null;
|
|
141
|
-
}
|
|
142
|
-
|
|
83
|
+
}
|
|
84
|
+
purge(scope, id) {
|
|
143
85
|
var _this$_cache$scope3;
|
|
144
86
|
if (!((_this$_cache$scope3 = this._cache[scope]) != null && _this$_cache$scope3[id])) {
|
|
145
87
|
return;
|
|
@@ -148,8 +90,8 @@ let ScopedInMemoryCache = function () {
|
|
|
148
90
|
if (Object.keys(this._cache[scope]).length === 0) {
|
|
149
91
|
delete this._cache[scope];
|
|
150
92
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
93
|
+
}
|
|
94
|
+
purgeScope(scope, predicate) {
|
|
153
95
|
if (!this._cache[scope]) {
|
|
154
96
|
return;
|
|
155
97
|
}
|
|
@@ -165,8 +107,8 @@ let ScopedInMemoryCache = function () {
|
|
|
165
107
|
if (Object.keys(this._cache[scope]).length === 0) {
|
|
166
108
|
delete this._cache[scope];
|
|
167
109
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
110
|
+
}
|
|
111
|
+
purgeAll(predicate) {
|
|
170
112
|
if (predicate == null) {
|
|
171
113
|
this._cache = {};
|
|
172
114
|
return;
|
|
@@ -174,32 +116,21 @@ let ScopedInMemoryCache = function () {
|
|
|
174
116
|
for (const scope of Object.keys(this._cache)) {
|
|
175
117
|
this.purgeScope(scope, (id, value) => predicate(scope, id, value));
|
|
176
118
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
}]);
|
|
184
|
-
return ScopedInMemoryCache;
|
|
185
|
-
}();
|
|
186
|
-
|
|
187
|
-
let SerializableInMemoryCache = function (_ScopedInMemoryCache) {
|
|
188
|
-
_inheritsLoose(SerializableInMemoryCache, _ScopedInMemoryCache);
|
|
189
|
-
function SerializableInMemoryCache(initialCache = {}) {
|
|
190
|
-
var _this;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
class SerializableInMemoryCache extends ScopedInMemoryCache {
|
|
123
|
+
constructor(initialCache = {}) {
|
|
191
124
|
try {
|
|
192
|
-
|
|
125
|
+
super(wonderStuffCore.clone(initialCache));
|
|
193
126
|
} catch (e) {
|
|
194
127
|
throw new DataError(`An error occurred trying to initialize from a response cache snapshot: ${e}`, DataErrors.InvalidInput);
|
|
195
128
|
}
|
|
196
|
-
return _this;
|
|
197
129
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
_proto.clone = function clone() {
|
|
130
|
+
set(scope, id, value) {
|
|
131
|
+
super.set(scope, id, Object.freeze(wonderStuffCore.clone(value)));
|
|
132
|
+
}
|
|
133
|
+
clone() {
|
|
203
134
|
try {
|
|
204
135
|
return wonderStuffCore.clone(this._cache);
|
|
205
136
|
} catch (e) {
|
|
@@ -207,14 +138,19 @@ let SerializableInMemoryCache = function (_ScopedInMemoryCache) {
|
|
|
207
138
|
cause: e
|
|
208
139
|
});
|
|
209
140
|
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}(ScopedInMemoryCache);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
213
143
|
|
|
214
144
|
const DefaultScope$2 = "default";
|
|
215
145
|
let _default$2;
|
|
216
|
-
|
|
217
|
-
|
|
146
|
+
class SsrCache {
|
|
147
|
+
static get Default() {
|
|
148
|
+
if (!_default$2) {
|
|
149
|
+
_default$2 = new SsrCache();
|
|
150
|
+
}
|
|
151
|
+
return _default$2;
|
|
152
|
+
}
|
|
153
|
+
constructor(hydrationCache = null, ssrOnlyCache = null) {
|
|
218
154
|
this._hydrationCache = void 0;
|
|
219
155
|
this._ssrOnlyCache = void 0;
|
|
220
156
|
this.initialize = source => {
|
|
@@ -255,8 +191,7 @@ let SsrCache = function () {
|
|
|
255
191
|
this._ssrOnlyCache = ssrOnlyCache || new SerializableInMemoryCache();
|
|
256
192
|
this._hydrationCache = hydrationCache || new SerializableInMemoryCache();
|
|
257
193
|
}
|
|
258
|
-
|
|
259
|
-
_proto._setCachedResponse = function _setCachedResponse(id, entry, hydrate) {
|
|
194
|
+
_setCachedResponse(id, entry, hydrate) {
|
|
260
195
|
const frozenEntry = Object.freeze(entry);
|
|
261
196
|
if (wonderBlocksCore.Server.isServerSide()) {
|
|
262
197
|
if (hydrate) {
|
|
@@ -266,18 +201,8 @@ let SsrCache = function () {
|
|
|
266
201
|
}
|
|
267
202
|
}
|
|
268
203
|
return frozenEntry;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
key: "Default",
|
|
272
|
-
get: function () {
|
|
273
|
-
if (!_default$2) {
|
|
274
|
-
_default$2 = new SsrCache();
|
|
275
|
-
}
|
|
276
|
-
return _default$2;
|
|
277
|
-
}
|
|
278
|
-
}]);
|
|
279
|
-
return SsrCache;
|
|
280
|
-
}();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
281
206
|
|
|
282
207
|
const initializeHydrationCache = source => SsrCache.Default.initialize(source);
|
|
283
208
|
const purgeHydrationCache = predicate => SsrCache.Default.purgeData(predicate);
|
|
@@ -298,8 +223,8 @@ function _extends() {
|
|
|
298
223
|
}
|
|
299
224
|
|
|
300
225
|
let _default$1;
|
|
301
|
-
|
|
302
|
-
|
|
226
|
+
class RequestFulfillment {
|
|
227
|
+
constructor() {
|
|
303
228
|
this._requests = {};
|
|
304
229
|
this.fulfill = (id, {
|
|
305
230
|
handler,
|
|
@@ -340,22 +265,24 @@ let RequestFulfillment = function () {
|
|
|
340
265
|
Object.keys(this._requests).forEach(id => this.abort(id));
|
|
341
266
|
};
|
|
342
267
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (!_default$1) {
|
|
347
|
-
_default$1 = new RequestFulfillment();
|
|
348
|
-
}
|
|
349
|
-
return _default$1;
|
|
268
|
+
static get Default() {
|
|
269
|
+
if (!_default$1) {
|
|
270
|
+
_default$1 = new RequestFulfillment();
|
|
350
271
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
272
|
+
return _default$1;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
354
275
|
|
|
355
276
|
const TrackerContext = React__namespace.createContext(null);
|
|
356
277
|
let _default;
|
|
357
|
-
|
|
358
|
-
|
|
278
|
+
class RequestTracker {
|
|
279
|
+
static get Default() {
|
|
280
|
+
if (!_default) {
|
|
281
|
+
_default = new RequestTracker();
|
|
282
|
+
}
|
|
283
|
+
return _default;
|
|
284
|
+
}
|
|
285
|
+
constructor(responseCache = undefined) {
|
|
359
286
|
this._trackedRequests = {};
|
|
360
287
|
this._responseCache = void 0;
|
|
361
288
|
this._requestFulfillment = void 0;
|
|
@@ -400,22 +327,10 @@ let RequestTracker = function () {
|
|
|
400
327
|
this._responseCache = responseCache || SsrCache.Default;
|
|
401
328
|
this._requestFulfillment = new RequestFulfillment();
|
|
402
329
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
}], [{
|
|
409
|
-
key: "Default",
|
|
410
|
-
get: function () {
|
|
411
|
-
if (!_default) {
|
|
412
|
-
_default = new RequestTracker();
|
|
413
|
-
}
|
|
414
|
-
return _default;
|
|
415
|
-
}
|
|
416
|
-
}]);
|
|
417
|
-
return RequestTracker;
|
|
418
|
-
}();
|
|
330
|
+
get hasUnfulfilledRequests() {
|
|
331
|
+
return Object.keys(this._trackedRequests).length > 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
419
334
|
|
|
420
335
|
const SSRCheck = () => {
|
|
421
336
|
if (wonderBlocksCore.Server.isServerSide()) {
|
|
@@ -471,22 +386,16 @@ const purgeCaches = () => {
|
|
|
471
386
|
purgeHydrationCache();
|
|
472
387
|
};
|
|
473
388
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
function TrackData() {
|
|
477
|
-
return _React$Component.apply(this, arguments) || this;
|
|
478
|
-
}
|
|
479
|
-
var _proto = TrackData.prototype;
|
|
480
|
-
_proto.render = function render() {
|
|
389
|
+
class TrackData extends React__namespace.Component {
|
|
390
|
+
render() {
|
|
481
391
|
if (!wonderBlocksCore.Server.isServerSide()) {
|
|
482
392
|
throw new Error("This component is not for use during client-side rendering");
|
|
483
393
|
}
|
|
484
394
|
return React__namespace.createElement(TrackerContext.Provider, {
|
|
485
395
|
value: RequestTracker.Default.trackDataRequest
|
|
486
396
|
}, this.props.children);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
}(React__namespace.Component);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
490
399
|
|
|
491
400
|
const loadingStatus = Object.freeze({
|
|
492
401
|
status: "loading"
|
|
@@ -708,7 +617,7 @@ const InterceptRequests = ({
|
|
|
708
617
|
children
|
|
709
618
|
}) => {
|
|
710
619
|
const interceptors = React__namespace.useContext(InterceptContext);
|
|
711
|
-
const updatedInterceptors = React__namespace.useMemo(() => [
|
|
620
|
+
const updatedInterceptors = React__namespace.useMemo(() => [...interceptors, interceptor], [interceptors, interceptor]);
|
|
712
621
|
return React__namespace.createElement(InterceptContext.Provider, {
|
|
713
622
|
value: updatedInterceptors
|
|
714
623
|
}, children);
|
|
@@ -764,20 +673,18 @@ const GqlErrors = Object.freeze({
|
|
|
764
673
|
BadResponse: "BadResponse",
|
|
765
674
|
ErrorResult: "ErrorResult"
|
|
766
675
|
});
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
function GqlError(message, kind, {
|
|
676
|
+
class GqlError extends wonderStuffCore.KindError {
|
|
677
|
+
constructor(message, kind, {
|
|
770
678
|
metadata,
|
|
771
679
|
cause
|
|
772
680
|
} = {}) {
|
|
773
|
-
|
|
681
|
+
super(message, kind, {
|
|
774
682
|
metadata,
|
|
775
683
|
cause,
|
|
776
684
|
name: "Gql"
|
|
777
|
-
})
|
|
685
|
+
});
|
|
778
686
|
}
|
|
779
|
-
|
|
780
|
-
}(wonderStuffCore.KindError);
|
|
687
|
+
}
|
|
781
688
|
|
|
782
689
|
const getGqlDataFromResponse = async response => {
|
|
783
690
|
const bodyText = await response.text();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-data",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.6",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.18.6",
|
|
17
|
-
"@khanacademy/wonder-blocks-core": "^5.0.
|
|
17
|
+
"@khanacademy/wonder-blocks-core": "^5.0.4"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@khanacademy/wonder-stuff-core": "^1.2.2",
|
|
21
21
|
"react": "16.14.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"wb-dev-build-settings": "^0.9.
|
|
24
|
+
"wb-dev-build-settings": "^0.9.5"
|
|
25
25
|
},
|
|
26
26
|
"author": "",
|
|
27
27
|
"license": "MIT"
|