@khanacademy/wonder-blocks-data 11.0.4 → 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.
Files changed (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/components/data.js.flow +0 -1
  3. package/dist/components/gql-router.js.flow +1 -2
  4. package/dist/components/intercept-context.js.flow +1 -2
  5. package/dist/components/intercept-requests.js.flow +1 -2
  6. package/dist/components/track-data.js.flow +1 -2
  7. package/dist/es/index.js +72 -165
  8. package/dist/hooks/use-cached-effect.js.flow +1 -2
  9. package/dist/hooks/use-gql-router-context.js.flow +1 -2
  10. package/dist/hooks/use-gql.js.flow +1 -2
  11. package/dist/hooks/use-hydratable-effect.js.flow +1 -2
  12. package/dist/hooks/use-request-interception.js.flow +1 -2
  13. package/dist/hooks/use-server-effect.js.flow +1 -2
  14. package/dist/hooks/use-shared-cache.js.flow +1 -2
  15. package/dist/index.js +72 -165
  16. package/dist/index.js.flow +1 -2
  17. package/dist/util/data-error.js.flow +1 -2
  18. package/dist/util/get-gql-data-from-response.js.flow +1 -2
  19. package/dist/util/get-gql-request-id.js.flow +1 -2
  20. package/dist/util/gql-error.js.flow +1 -2
  21. package/dist/util/gql-router-context.js.flow +1 -2
  22. package/dist/util/gql-types.js.flow +1 -2
  23. package/dist/util/graphql-document-node-parser.js.flow +1 -2
  24. package/dist/util/graphql-types.js.flow +28 -24
  25. package/dist/util/hydration-cache-api.js.flow +1 -2
  26. package/dist/util/merge-gql-context.js.flow +1 -2
  27. package/dist/util/purge-caches.js.flow +1 -2
  28. package/dist/util/request-api.js.flow +1 -2
  29. package/dist/util/request-fulfillment.js.flow +1 -2
  30. package/dist/util/request-tracking.js.flow +1 -2
  31. package/dist/util/result-from-cache-response.js.flow +1 -2
  32. package/dist/util/scoped-in-memory-cache.js.flow +1 -2
  33. package/dist/util/serializable-in-memory-cache.js.flow +1 -2
  34. package/dist/util/ssr-cache.js.flow +1 -2
  35. package/dist/util/status.js.flow +1 -2
  36. package/dist/util/to-gql-operation.js.flow +1 -2
  37. package/dist/util/types.js.flow +1 -2
  38. package/package.json +3 -3
  39. package/src/util/graphql-types.js.flow +30 -0
  40. package/src/util/graphql-types.ts +1 -0
  41. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @khanacademy/wonder-blocks-data
2
2
 
3
+ ## 11.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - c20f48f3: Don't transpile classes when building bundles
8
+ - Updated dependencies [c20f48f3]
9
+ - @khanacademy/wonder-blocks-core@5.0.4
10
+
11
+ ## 11.0.5
12
+
13
+ ### Patch Changes
14
+
15
+ - 43155769: Fix DocumentNode type definition
16
+
3
17
  ## 11.0.4
4
18
 
5
19
  ### Patch Changes
@@ -4,7 +4,6 @@
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import * as React from "react";
9
8
  import { WhenClientSide } from "../hooks/use-hydratable-effect";
10
9
  import type { Result, ValidCacheData } from "../util/types";
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for gql-router
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import * as React from "react";
9
8
  import type { GqlContext, GqlFetchFn } from "../util/gql-types";
10
9
  declare type Props<TContext: GqlContext> = {|
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for intercept-context
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import * as React from "react";
9
8
  import type { ValidCacheData } from "../util/types";
10
9
  declare type InterceptContextData = $ReadOnlyArray<
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for intercept-requests
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import * as React from "react";
9
8
  import type { ValidCacheData } from "../util/types";
10
9
  declare type Props<TData: ValidCacheData> = {|
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for track-data
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import * as React from "react";
9
8
  declare type TrackDataProps = {|
10
9
  children: React.Node,
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
- let DataError = function (_KindError) {
81
- _inheritsLoose(DataError, _KindError);
82
- function DataError(message, kind, {
22
+ class DataError extends KindError {
23
+ constructor(message, kind, {
83
24
  metadata,
84
25
  cause
85
26
  } = {}) {
86
- return _KindError.call(this, message, kind, {
27
+ super(message, kind, {
87
28
  metadata,
88
29
  cause,
89
30
  name: "Data"
90
- }) || this;
31
+ });
91
32
  }
92
- return DataError;
93
- }(KindError);
33
+ }
94
34
 
95
- let ScopedInMemoryCache = function () {
96
- function ScopedInMemoryCache(initialCache = {}) {
35
+ class ScopedInMemoryCache {
36
+ constructor(initialCache = {}) {
97
37
  this._cache = void 0;
98
38
  this._cache = initialCache;
99
39
  }
100
- var _proto = ScopedInMemoryCache.prototype;
101
- _proto.set = function set(scope, id, value) {
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
- _proto.get = function get(scope, id) {
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
- _proto.purge = function purge(scope, id) {
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
- _proto.purgeScope = function purgeScope(scope, predicate) {
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
- _proto.purgeAll = function purgeAll(predicate) {
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
- _createClass(ScopedInMemoryCache, [{
156
- key: "inUse",
157
- get: function () {
158
- return Object.keys(this._cache).length > 0;
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
- _this = _ScopedInMemoryCache.call(this, clone(initialCache)) || this;
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
- var _proto = SerializableInMemoryCache.prototype;
176
- _proto.set = function set(scope, id, value) {
177
- _ScopedInMemoryCache.prototype.set.call(this, scope, id, Object.freeze(clone(value)));
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
- return SerializableInMemoryCache;
189
- }(ScopedInMemoryCache);
118
+ }
119
+ }
190
120
 
191
121
  const DefaultScope$2 = "default";
192
122
  let _default$2;
193
- let SsrCache = function () {
194
- function SsrCache(hydrationCache = null, ssrOnlyCache = null) {
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
- var _proto = SsrCache.prototype;
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
- _createClass(SsrCache, null, [{
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
- let RequestFulfillment = function () {
279
- function RequestFulfillment() {
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
- _createClass(RequestFulfillment, null, [{
321
- key: "Default",
322
- get: function () {
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
- return RequestFulfillment;
330
- }();
249
+ return _default$1;
250
+ }
251
+ }
331
252
 
332
253
  const TrackerContext = React.createContext(null);
333
254
  let _default;
334
- let RequestTracker = function () {
335
- function RequestTracker(responseCache = undefined) {
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
- _createClass(RequestTracker, [{
381
- key: "hasUnfulfilledRequests",
382
- get: function () {
383
- return Object.keys(this._trackedRequests).length > 0;
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
- let TrackData = function (_React$Component) {
452
- _inheritsLoose(TrackData, _React$Component);
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
- return TrackData;
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(() => [].concat(interceptors, [interceptor]), [interceptors, interceptor]);
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
- let GqlError = function (_KindError) {
745
- _inheritsLoose(GqlError, _KindError);
746
- function GqlError(message, kind, {
653
+ class GqlError extends KindError {
654
+ constructor(message, kind, {
747
655
  metadata,
748
656
  cause
749
657
  } = {}) {
750
- return _KindError.call(this, message, kind, {
658
+ super(message, kind, {
751
659
  metadata,
752
660
  cause,
753
661
  name: "Gql"
754
- }) || this;
662
+ });
755
663
  }
756
- return GqlError;
757
- }(KindError);
664
+ }
758
665
 
759
666
  const getGqlDataFromResponse = async response => {
760
667
  const bodyText = await response.text();
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for use-cached-effect
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type { Result, ValidCacheData } from "../util/types";
9
8
  import { FetchPolicy } from "../util/types";
10
9
  declare type CachedEffectOptions<TData: ValidCacheData> = {|
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for use-gql-router-context
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type { GqlRouterConfiguration, GqlContext } from "../util/gql-types";
9
8
 
10
9
  /**
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for use-gql
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type {
9
8
  GqlContext,
10
9
  GqlOperation,
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for use-hydratable-effect
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type { Result, ValidCacheData } from "../util/types";
9
8
 
10
9
  /**
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for use-request-interception
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type { ValidCacheData } from "../util/types";
9
8
 
10
9
  /**
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for use-server-effect
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type { Result, ValidCacheData } from "../util/types";
9
8
  declare type ServerEffectOptions = {|
10
9
  /**
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Flowtype definitions for use-shared-cache
2
+ * Flowtype definitions for data
3
3
  * Generated by Flowgen from a Typescript Definition
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
-
8
7
  import type { ValidCacheData, ScopedCache } from "../util/types";
9
8
 
10
9
  /**