relay-runtime 1.7.0-rc.1 → 2.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.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/index.js +1 -1
  3. package/lib/ConvertToExecuteFunction.js +12 -75
  4. package/lib/DataChecker.js +400 -0
  5. package/lib/NormalizationNode.js +14 -0
  6. package/lib/ReaderNode.js +10 -0
  7. package/lib/RelayCombinedEnvironmentTypes.js +10 -0
  8. package/lib/RelayConcreteNode.js +12 -29
  9. package/lib/RelayConcreteVariables.js +17 -11
  10. package/lib/RelayConnectionHandler.js +98 -42
  11. package/lib/RelayConnectionInterface.js +5 -13
  12. package/lib/RelayCore.js +17 -14
  13. package/lib/RelayDeclarativeMutationConfig.js +69 -34
  14. package/lib/RelayDefaultHandleKey.js +1 -2
  15. package/lib/RelayDefaultHandlerProvider.js +6 -5
  16. package/lib/RelayError.js +6 -9
  17. package/lib/RelayInMemoryRecordSource.js +20 -22
  18. package/lib/RelayModernEnvironment.js +140 -229
  19. package/lib/RelayModernFragmentSpecResolver.js +110 -102
  20. package/lib/RelayModernGraphQLTag.js +53 -15
  21. package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
  22. package/lib/RelayModernQueryExecutor.js +172 -0
  23. package/lib/RelayModernRecord.js +97 -38
  24. package/lib/RelayModernSelector.js +89 -33
  25. package/lib/RelayModernStore.js +301 -0
  26. package/lib/RelayNetwork.js +16 -28
  27. package/lib/RelayNetworkLogger.js +2 -3
  28. package/lib/RelayNetworkLoggerTransaction.js +32 -30
  29. package/lib/RelayNetworkTypes.js +1 -2
  30. package/lib/RelayObservable.js +127 -155
  31. package/lib/RelayProfiler.js +35 -22
  32. package/lib/RelayPublishQueue.js +144 -96
  33. package/lib/RelayQueryResponseCache.js +37 -21
  34. package/lib/RelayReader.js +194 -61
  35. package/lib/RelayRecordProxy.js +50 -31
  36. package/lib/RelayRecordSourceMutator.js +92 -51
  37. package/lib/RelayRecordSourceProxy.js +43 -35
  38. package/lib/RelayRecordSourceSelectorProxy.js +22 -21
  39. package/lib/RelayRecordState.js +1 -3
  40. package/lib/RelayReferenceMarker.js +110 -37
  41. package/lib/RelayResponseNormalizer.js +248 -82
  42. package/lib/RelayRuntimeTypes.js +1 -3
  43. package/lib/RelayStoreTypes.js +1 -2
  44. package/lib/RelayStoreUtils.js +37 -19
  45. package/lib/RelayViewerHandler.js +14 -10
  46. package/lib/applyRelayModernOptimisticMutation.js +8 -8
  47. package/lib/cloneRelayHandleSourceField.js +8 -9
  48. package/lib/commitLocalUpdate.js +1 -2
  49. package/lib/commitRelayModernMutation.js +21 -14
  50. package/lib/createRelayNetworkLogger.js +11 -9
  51. package/lib/deepFreeze.js +2 -3
  52. package/lib/fetchRelayModernQuery.js +10 -12
  53. package/lib/generateRelayClientID.js +4 -2
  54. package/lib/getRelayHandleKey.js +5 -6
  55. package/lib/hasOverlappingIDs.js +3 -2
  56. package/lib/index.js +59 -62
  57. package/lib/isPromise.js +1 -2
  58. package/lib/isRelayModernEnvironment.js +1 -3
  59. package/lib/isScalarAndEqual.js +1 -3
  60. package/lib/normalizePayload.js +17 -15
  61. package/lib/normalizeRelayPayload.js +9 -9
  62. package/lib/recycleNodesInto.js +25 -9
  63. package/lib/requestRelaySubscription.js +25 -58
  64. package/lib/simpleClone.js +2 -3
  65. package/lib/stableCopy.js +5 -3
  66. package/lib/validateMutation.js +146 -0
  67. package/package.json +3 -3
  68. package/relay-runtime.js +4 -0
  69. package/relay-runtime.min.js +9 -0
  70. package/lib/RelayDataLoader.js +0 -302
  71. package/lib/RelayMarkSweepStore.js +0 -242
  72. package/lib/deferrableFragmentKey.js +0 -20
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  *
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  /**
@@ -40,22 +39,49 @@
40
39
  * ```
41
40
  */
42
41
  function getSelector(operationVariables, fragment, item) {
43
- !(typeof item === 'object' && item !== null && !Array.isArray(item)) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernSelector: Expected value for fragment `%s` to be an object, got ' + '`%s`.', fragment.name, JSON.stringify(item)) : require('fbjs/lib/invariant')(false) : void 0;
44
- var dataID = item[require('./RelayStoreUtils').ID_KEY];
45
- var fragments = item[require('./RelayStoreUtils').FRAGMENTS_KEY];
42
+ !(typeof item === 'object' && item !== null && !Array.isArray(item)) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernSelector: Expected value for fragment `%s` to be an object, got ' + '`%s`.', fragment.name, JSON.stringify(item)) : require("fbjs/lib/invariant")(false) : void 0;
43
+
44
+ var dataID = item[require("./RelayStoreUtils").ID_KEY];
45
+
46
+ var fragments = item[require("./RelayStoreUtils").FRAGMENTS_KEY];
47
+
48
+ var owner = item[require("./RelayStoreUtils").FRAGMENT_OWNER_KEY];
49
+
46
50
  if (typeof dataID === 'string' && typeof fragments === 'object' && fragments !== null && typeof fragments[fragment.name] === 'object' && fragments[fragment.name] !== null) {
47
51
  var argumentVariables = fragments[fragment.name];
48
- var fragmentVariables = require('./RelayConcreteVariables').getFragmentVariables(fragment, operationVariables, argumentVariables);
52
+
53
+ if (owner != null && typeof owner === 'object') {
54
+ // $FlowFixMe - TODO T39154660
55
+ var typedOwner = owner;
56
+ var ownerOperationVariables = typedOwner.variables;
57
+
58
+ var _fragmentVariables = require("./RelayConcreteVariables").getFragmentVariables(fragment, ownerOperationVariables, argumentVariables);
59
+
60
+ return {
61
+ owner: typedOwner,
62
+ selector: {
63
+ dataID: dataID,
64
+ node: fragment,
65
+ variables: _fragmentVariables
66
+ }
67
+ };
68
+ }
69
+
70
+ var fragmentVariables = require("./RelayConcreteVariables").getFragmentVariables(fragment, operationVariables, argumentVariables);
71
+
49
72
  return {
50
- dataID: dataID,
51
- node: fragment,
52
- variables: fragmentVariables
73
+ owner: null,
74
+ selector: {
75
+ dataID: dataID,
76
+ node: fragment,
77
+ variables: fragmentVariables
78
+ }
53
79
  };
54
80
  }
55
- process.env.NODE_ENV !== 'production' ? require('fbjs/lib/warning')(false, 'RelayModernSelector: Expected object to contain data for fragment `%s`, got ' + '`%s`. Make sure that the parent operation/fragment included fragment ' + '`...%s` without `@relay(mask: false)`.', fragment.name, JSON.stringify(item), fragment.name) : void 0;
81
+
82
+ process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayModernSelector: Expected object to contain data for fragment `%s`, got ' + '`%s`. Make sure that the parent operation/fragment included fragment ' + '`...%s` without `@relay(mask: false)`.', fragment.name, JSON.stringify(item), fragment.name) : void 0;
56
83
  return null;
57
84
  }
58
-
59
85
  /**
60
86
  * @public
61
87
  *
@@ -64,10 +90,13 @@ function getSelector(operationVariables, fragment, item) {
64
90
  * items. This is similar to `getSelector` but for "plural" fragments that
65
91
  * expect an array of results and therefore return an array of selectors.
66
92
  */
93
+
94
+
67
95
  function getSelectorList(operationVariables, fragment, items) {
68
96
  var selectors = null;
69
97
  items.forEach(function (item) {
70
98
  var selector = item != null ? getSelector(operationVariables, fragment, item) : null;
99
+
71
100
  if (selector != null) {
72
101
  selectors = selectors || [];
73
102
  selectors.push(selector);
@@ -75,7 +104,6 @@ function getSelectorList(operationVariables, fragment, items) {
75
104
  });
76
105
  return selectors;
77
106
  }
78
-
79
107
  /**
80
108
  * @public
81
109
  *
@@ -86,26 +114,30 @@ function getSelectorList(operationVariables, fragment, items) {
86
114
  * uses this function to convert (props, fragments) into selectors so that it
87
115
  * can read the results to pass to the inner component.
88
116
  */
117
+
118
+
89
119
  function getSelectorsFromObject(operationVariables, fragments, object) {
90
120
  var selectors = {};
121
+
91
122
  for (var _key in fragments) {
92
123
  if (fragments.hasOwnProperty(_key)) {
93
124
  var fragment = fragments[_key];
94
125
  var item = object[_key];
126
+
95
127
  if (item == null) {
96
128
  selectors[_key] = item;
97
129
  } else if (fragment.metadata && fragment.metadata.plural === true) {
98
- !Array.isArray(item) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key, JSON.stringify(item), fragment.name) : require('fbjs/lib/invariant')(false) : void 0;
130
+ !Array.isArray(item) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key, JSON.stringify(item), fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
99
131
  selectors[_key] = getSelectorList(operationVariables, fragment, item);
100
132
  } else {
101
- !!Array.isArray(item) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key, JSON.stringify(item), fragment.name) : require('fbjs/lib/invariant')(false) : void 0;
133
+ !!Array.isArray(item) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key, JSON.stringify(item), fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
102
134
  selectors[_key] = getSelector(operationVariables, fragment, item);
103
135
  }
104
136
  }
105
137
  }
138
+
106
139
  return selectors;
107
140
  }
108
-
109
141
  /**
110
142
  * @public
111
143
  *
@@ -115,33 +147,40 @@ function getSelectorsFromObject(operationVariables, fragments, object) {
115
147
  * Similar to `getSelectorsFromObject()`, this function can be useful in
116
148
  * determining the "identity" of the props passed to a component.
117
149
  */
150
+
151
+
118
152
  function getDataIDsFromObject(fragments, object) {
119
153
  var ids = {};
154
+
120
155
  for (var _key2 in fragments) {
121
156
  if (fragments.hasOwnProperty(_key2)) {
122
157
  var fragment = fragments[_key2];
123
158
  var item = object[_key2];
159
+
124
160
  if (item == null) {
125
161
  ids[_key2] = item;
126
162
  } else if (fragment.metadata && fragment.metadata.plural === true) {
127
- !Array.isArray(item) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key2, JSON.stringify(item), fragment.name) : require('fbjs/lib/invariant')(false) : void 0;
163
+ !Array.isArray(item) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key2, JSON.stringify(item), fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
128
164
  ids[_key2] = getDataIDs(fragment, item);
129
165
  } else {
130
- !!Array.isArray(item) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key2, JSON.stringify(item), fragment.name) : require('fbjs/lib/invariant')(false) : void 0;
166
+ !!Array.isArray(item) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key2, JSON.stringify(item), fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
131
167
  ids[_key2] = getDataID(fragment, item);
132
168
  }
133
169
  }
134
170
  }
171
+
135
172
  return ids;
136
173
  }
137
-
138
174
  /**
139
175
  * @internal
140
176
  */
177
+
178
+
141
179
  function getDataIDs(fragment, items) {
142
- var ids = void 0;
180
+ var ids;
143
181
  items.forEach(function (item) {
144
182
  var id = item != null ? getDataID(fragment, item) : null;
183
+
145
184
  if (id != null) {
146
185
  ids = ids || [];
147
186
  ids.push(id);
@@ -149,20 +188,23 @@ function getDataIDs(fragment, items) {
149
188
  });
150
189
  return ids || null;
151
190
  }
152
-
153
191
  /**
154
192
  * @internal
155
193
  */
194
+
195
+
156
196
  function getDataID(fragment, item) {
157
- !(typeof item === 'object' && item !== null && !Array.isArray(item)) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernSelector: Expected value for fragment `%s` to be an object, got ' + '`%s`.', fragment.name, JSON.stringify(item)) : require('fbjs/lib/invariant')(false) : void 0;
158
- var dataID = item[require('./RelayStoreUtils').ID_KEY];
197
+ !(typeof item === 'object' && item !== null && !Array.isArray(item)) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernSelector: Expected value for fragment `%s` to be an object, got ' + '`%s`.', fragment.name, JSON.stringify(item)) : require("fbjs/lib/invariant")(false) : void 0;
198
+
199
+ var dataID = item[require("./RelayStoreUtils").ID_KEY];
200
+
159
201
  if (typeof dataID === 'string') {
160
202
  return dataID;
161
203
  }
162
- process.env.NODE_ENV !== 'production' ? require('fbjs/lib/warning')(false, 'RelayModernSelector: Expected object to contain data for fragment `%s`, got ' + '`%s`. Make sure that the parent operation/fragment included fragment ' + '`...%s` without `@relay(mask: false)`.', fragment.name, JSON.stringify(item), fragment.name) : void 0;
204
+
205
+ process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayModernSelector: Expected object to contain data for fragment `%s`, got ' + '`%s`. Make sure that the parent operation/fragment included fragment ' + '`...%s` without `@relay(mask: false)`.', fragment.name, JSON.stringify(item), fragment.name) : void 0;
163
206
  return null;
164
207
  }
165
-
166
208
  /**
167
209
  * @public
168
210
  *
@@ -173,48 +215,60 @@ function getDataID(fragment, item) {
173
215
  * This can be useful in determing what varaibles were used to fetch the data
174
216
  * for a Relay container, for example.
175
217
  */
218
+
219
+
176
220
  function getVariablesFromObject(operationVariables, fragments, object) {
177
221
  var variables = {};
222
+
178
223
  for (var _key3 in fragments) {
179
224
  if (fragments.hasOwnProperty(_key3)) {
180
225
  var _ret = function () {
181
226
  var fragment = fragments[_key3];
182
227
  var item = object[_key3];
228
+
183
229
  if (item == null) {
184
- return 'continue';
230
+ return "continue";
185
231
  } else if (fragment.metadata && fragment.metadata.plural === true) {
186
- !Array.isArray(item) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key3, JSON.stringify(item), fragment.name) : require('fbjs/lib/invariant')(false) : void 0;
232
+ !Array.isArray(item) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernSelector: Expected value for key `%s` to be an array, got `%s`. ' + 'Remove `@relay(plural: true)` from fragment `%s` to allow the prop to be an object.', _key3, JSON.stringify(item), fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
187
233
  item.forEach(function (value) {
188
234
  if (value != null) {
189
235
  var itemVariables = getVariables(operationVariables, fragment, value);
236
+
190
237
  if (itemVariables) {
191
238
  Object.assign(variables, itemVariables);
192
239
  }
193
240
  }
194
241
  });
195
242
  } else {
196
- !!Array.isArray(item) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key3, JSON.stringify(item), fragment.name) : require('fbjs/lib/invariant')(false) : void 0;
243
+ !!Array.isArray(item) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernFragmentSpecResolver: Expected value for key `%s` to be an object, got `%s`. ' + 'Add `@relay(plural: true)` to fragment `%s` to allow the prop to be an array of items.', _key3, JSON.stringify(item), fragment.name) : require("fbjs/lib/invariant")(false) : void 0;
197
244
  var itemVariables = getVariables(operationVariables, fragment, item);
245
+
198
246
  if (itemVariables) {
199
247
  Object.assign(variables, itemVariables);
200
248
  }
201
249
  }
202
250
  }();
203
251
 
204
- if (_ret === 'continue') continue;
252
+ if (_ret === "continue") continue;
205
253
  }
206
254
  }
255
+
207
256
  return variables;
208
257
  }
209
-
210
258
  /**
211
259
  * @internal
212
260
  */
261
+
262
+
213
263
  function getVariables(operationVariables, fragment, item) {
214
- var selector = getSelector(operationVariables, fragment, item);
215
- return selector ? selector.variables : null;
216
- }
264
+ var ownedSelector = getSelector(operationVariables, fragment, item);
265
+
266
+ if (!ownedSelector) {
267
+ return null;
268
+ }
217
269
 
270
+ return ownedSelector.selector.variables;
271
+ }
218
272
  /**
219
273
  * @public
220
274
  *
@@ -222,8 +276,10 @@ function getVariables(operationVariables, fragment, item) {
222
276
  * that this function returns `false` when the two queries/fragments are
223
277
  * different objects, even if they select the same fields.
224
278
  */
279
+
280
+
225
281
  function areEqualSelectors(thisSelector, thatSelector) {
226
- return thisSelector.dataID === thatSelector.dataID && thisSelector.node === thatSelector.node && require('fbjs/lib/areEqual')(thisSelector.variables, thatSelector.variables);
282
+ return thisSelector.selector.dataID === thatSelector.selector.dataID && thisSelector.selector.node === thatSelector.selector.node && require("fbjs/lib/areEqual")(thisSelector.selector.variables, thatSelector.selector.variables);
227
283
  }
228
284
 
229
285
  module.exports = {
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * strict-local
8
+ * @format
9
+ */
10
+ 'use strict';
11
+
12
+ var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
13
+
14
+ /**
15
+ * @public
16
+ *
17
+ * An implementation of the `Store` interface defined in `RelayStoreTypes`.
18
+ *
19
+ * Note that a Store takes ownership of all records provided to it: other
20
+ * objects may continue to hold a reference to such records but may not mutate
21
+ * them. The static Relay core is architected to avoid mutating records that may have been
22
+ * passed to a store: operations that mutate records will either create fresh
23
+ * records or clone existing records and modify the clones. Record immutability
24
+ * is also enforced in development mode by freezing all records passed to a store.
25
+ */
26
+ var RelayModernStore =
27
+ /*#__PURE__*/
28
+ function () {
29
+ function RelayModernStore(source) {
30
+ var gcScheduler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : require("fbjs/lib/resolveImmediate");
31
+ var operationLoader = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
32
+
33
+ // Prevent mutation of a record from outside the store.
34
+ if (process.env.NODE_ENV !== "production") {
35
+ var storeIDs = source.getRecordIDs();
36
+
37
+ for (var ii = 0; ii < storeIDs.length; ii++) {
38
+ var record = source.get(storeIDs[ii]);
39
+
40
+ if (record) {
41
+ require("./RelayModernRecord").freeze(record);
42
+ }
43
+ }
44
+ }
45
+
46
+ this._gcScheduler = gcScheduler;
47
+ this._hasScheduledGC = false;
48
+ this._index = 0;
49
+ this._operationLoader = operationLoader;
50
+ this._recordSource = source;
51
+ this._roots = new Map();
52
+ this._subscriptions = new Set();
53
+ this._updatedRecordIDs = {};
54
+ this._gcHoldCounter = 0;
55
+ this._shouldScheduleGC = false;
56
+ }
57
+
58
+ var _proto = RelayModernStore.prototype;
59
+
60
+ _proto.getSource = function getSource() {
61
+ return this._recordSource;
62
+ };
63
+
64
+ _proto.check = function check(selector) {
65
+ return require("./DataChecker").check(this._recordSource, this._recordSource, selector, [], this._operationLoader);
66
+ };
67
+
68
+ _proto.retain = function retain(selector) {
69
+ var _this = this;
70
+
71
+ var index = this._index++;
72
+
73
+ var dispose = function dispose() {
74
+ _this._roots["delete"](index);
75
+
76
+ _this._scheduleGC();
77
+ };
78
+
79
+ this._roots.set(index, selector);
80
+
81
+ return {
82
+ dispose: dispose
83
+ };
84
+ };
85
+
86
+ _proto.lookup = function lookup(selector, owner) {
87
+ var snapshot = require("./RelayReader").read(this._recordSource, selector, owner);
88
+
89
+ if (process.env.NODE_ENV !== "production") {
90
+ require("./deepFreeze")(snapshot);
91
+ }
92
+
93
+ return snapshot;
94
+ };
95
+
96
+ _proto.notify = function notify() {
97
+ var _this2 = this;
98
+
99
+ this._subscriptions.forEach(function (subscription) {
100
+ _this2._updateSubscription(subscription);
101
+ });
102
+
103
+ this._updatedRecordIDs = {};
104
+ };
105
+
106
+ _proto.publish = function publish(source) {
107
+ updateTargetFromSource(this._recordSource, source, this._updatedRecordIDs);
108
+ };
109
+
110
+ _proto.subscribe = function subscribe(snapshot, callback) {
111
+ var _this3 = this;
112
+
113
+ var subscription = {
114
+ callback: callback,
115
+ snapshot: snapshot
116
+ };
117
+
118
+ var dispose = function dispose() {
119
+ _this3._subscriptions["delete"](subscription);
120
+ };
121
+
122
+ this._subscriptions.add(subscription);
123
+
124
+ return {
125
+ dispose: dispose
126
+ };
127
+ };
128
+
129
+ _proto.holdGC = function holdGC() {
130
+ var _this4 = this;
131
+
132
+ this._gcHoldCounter++;
133
+
134
+ var dispose = function dispose() {
135
+ if (_this4._gcHoldCounter > 0) {
136
+ _this4._gcHoldCounter--;
137
+
138
+ if (_this4._gcHoldCounter === 0 && _this4._shouldScheduleGC) {
139
+ _this4._scheduleGC();
140
+
141
+ _this4._shouldScheduleGC = false;
142
+ }
143
+ }
144
+ };
145
+
146
+ return {
147
+ dispose: dispose
148
+ };
149
+ };
150
+
151
+ _proto.toJSON = function toJSON() {
152
+ return 'RelayModernStore()';
153
+ }; // Internal API
154
+
155
+
156
+ _proto.__getUpdatedRecordIDs = function __getUpdatedRecordIDs() {
157
+ return this._updatedRecordIDs;
158
+ };
159
+
160
+ _proto._updateSubscription = function _updateSubscription(subscription) {
161
+ var callback = subscription.callback,
162
+ snapshot = subscription.snapshot;
163
+
164
+ if (!require("./hasOverlappingIDs")(snapshot, this._updatedRecordIDs)) {
165
+ return;
166
+ }
167
+
168
+ var _RelayReader$read = require("./RelayReader").read(this._recordSource, snapshot, snapshot.owner),
169
+ data = _RelayReader$read.data,
170
+ seenRecords = _RelayReader$read.seenRecords;
171
+
172
+ var nextData = require("./recycleNodesInto")(snapshot.data, data);
173
+
174
+ var nextSnapshot = (0, _objectSpread2["default"])({}, snapshot, {
175
+ data: nextData,
176
+ seenRecords: seenRecords
177
+ });
178
+
179
+ if (process.env.NODE_ENV !== "production") {
180
+ require("./deepFreeze")(nextSnapshot);
181
+ }
182
+
183
+ subscription.snapshot = nextSnapshot;
184
+
185
+ if (nextSnapshot.data !== snapshot.data) {
186
+ callback(nextSnapshot);
187
+ }
188
+ };
189
+
190
+ _proto._scheduleGC = function _scheduleGC() {
191
+ var _this5 = this;
192
+
193
+ if (this._gcHoldCounter > 0) {
194
+ this._shouldScheduleGC = true;
195
+ return;
196
+ }
197
+
198
+ if (this._hasScheduledGC) {
199
+ return;
200
+ }
201
+
202
+ this._hasScheduledGC = true;
203
+
204
+ this._gcScheduler(function () {
205
+ _this5.__gc();
206
+
207
+ _this5._hasScheduledGC = false;
208
+ });
209
+ };
210
+
211
+ _proto.__gc = function __gc() {
212
+ var _this6 = this;
213
+
214
+ var references = new Set(); // Mark all records that are traversable from a root
215
+
216
+ this._roots.forEach(function (selector) {
217
+ require("./RelayReferenceMarker").mark(_this6._recordSource, selector, references, _this6._operationLoader);
218
+ }); // Short-circuit if *nothing* is referenced
219
+
220
+
221
+ if (!references.size) {
222
+ this._recordSource.clear();
223
+
224
+ return;
225
+ } // Evict any unreferenced nodes
226
+
227
+
228
+ var storeIDs = this._recordSource.getRecordIDs();
229
+
230
+ for (var ii = 0; ii < storeIDs.length; ii++) {
231
+ var dataID = storeIDs[ii];
232
+
233
+ if (!references.has(dataID)) {
234
+ this._recordSource.remove(dataID);
235
+ }
236
+ }
237
+ };
238
+
239
+ return RelayModernStore;
240
+ }();
241
+ /**
242
+ * Updates the target with information from source, also updating a mapping of
243
+ * which records in the target were changed as a result.
244
+ */
245
+
246
+
247
+ function updateTargetFromSource(target, source, updatedRecordIDs) {
248
+ var dataIDs = source.getRecordIDs();
249
+
250
+ for (var ii = 0; ii < dataIDs.length; ii++) {
251
+ var dataID = dataIDs[ii];
252
+ var sourceRecord = source.get(dataID);
253
+ var targetRecord = target.get(dataID); // Prevent mutation of a record from outside the store.
254
+
255
+ if (process.env.NODE_ENV !== "production") {
256
+ if (sourceRecord) {
257
+ require("./RelayModernRecord").freeze(sourceRecord);
258
+ }
259
+ }
260
+
261
+ if (sourceRecord === require("./RelayStoreUtils").UNPUBLISH_RECORD_SENTINEL) {
262
+ // Unpublish a record
263
+ target.remove(dataID);
264
+ updatedRecordIDs[dataID] = true;
265
+ } else if (sourceRecord && targetRecord) {
266
+ var nextRecord = require("./RelayModernRecord").update(targetRecord, sourceRecord);
267
+
268
+ if (nextRecord !== targetRecord) {
269
+ // Prevent mutation of a record from outside the store.
270
+ if (process.env.NODE_ENV !== "production") {
271
+ require("./RelayModernRecord").freeze(nextRecord);
272
+ }
273
+
274
+ updatedRecordIDs[dataID] = true;
275
+ target.set(dataID, nextRecord);
276
+ }
277
+ } else if (sourceRecord === null) {
278
+ target["delete"](dataID);
279
+
280
+ if (targetRecord !== null) {
281
+ updatedRecordIDs[dataID] = true;
282
+ }
283
+ } else if (sourceRecord) {
284
+ target.set(dataID, sourceRecord);
285
+ updatedRecordIDs[dataID] = true;
286
+ } // don't add explicit undefined
287
+
288
+ }
289
+ }
290
+
291
+ require("./RelayProfiler").instrumentMethods(RelayModernStore.prototype, {
292
+ lookup: 'RelayModernStore.prototype.lookup',
293
+ notify: 'RelayModernStore.prototype.notify',
294
+ publish: 'RelayModernStore.prototype.publish',
295
+ retain: 'RelayModernStore.prototype.retain',
296
+ subscribe: 'RelayModernStore.prototype.subscribe',
297
+ __gc: 'RelayModernStore.prototype.__gc',
298
+ holdGC: 'RelayModernStore.prototype.holdGC'
299
+ });
300
+
301
+ module.exports = RelayModernStore;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
12
  /**
@@ -16,45 +15,34 @@
16
15
  */
17
16
  function create(fetchFn, subscribeFn) {
18
17
  // Convert to functions that returns RelayObservable.
19
- var observeFetch = require('./ConvertToExecuteFunction').convertFetch(fetchFn);
20
- var observeSubscribe = subscribeFn ? require('./ConvertToExecuteFunction').convertSubscribe(subscribeFn) : undefined;
21
- var observeSubscribeWithEvents = subscribeFn ? require('./ConvertToExecuteFunction').convertSubscribeWithEvents(subscribeFn) : undefined;
18
+ var observeFetch = require("./ConvertToExecuteFunction").convertFetch(fetchFn);
19
+
20
+ var observeSubscribe = subscribeFn ? require("./ConvertToExecuteFunction").convertSubscribe(subscribeFn) : undefined;
22
21
 
23
22
  function execute(request, variables, cacheConfig, uploadables) {
24
23
  if (request.operationKind === 'subscription') {
25
- !observeSubscribe ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayNetwork: This network layer does not support Subscriptions. ' + 'To use Subscriptions, provide a custom network layer.') : require('fbjs/lib/invariant')(false) : void 0;
26
-
27
- !!uploadables ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayNetwork: Cannot provide uploadables while subscribing.') : require('fbjs/lib/invariant')(false) : void 0;
24
+ !observeSubscribe ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNetwork: This network layer does not support Subscriptions. ' + 'To use Subscriptions, provide a custom network layer.') : require("fbjs/lib/invariant")(false) : void 0;
25
+ !!uploadables ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNetwork: Cannot provide uploadables while subscribing.') : require("fbjs/lib/invariant")(false) : void 0;
28
26
  return observeSubscribe(request, variables, cacheConfig);
29
27
  }
30
28
 
31
29
  var pollInterval = cacheConfig.poll;
32
- if (pollInterval != null) {
33
- !!uploadables ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayNetwork: Cannot provide uploadables while polling.') : require('fbjs/lib/invariant')(false) : void 0;
34
- return observeFetch(request, variables, { force: true }).poll(pollInterval);
35
- }
36
30
 
37
- return observeFetch(request, variables, cacheConfig, uploadables);
38
- }
39
-
40
- function executeWithEvents(request, variables, cacheConfig, uploadables) {
41
- if (request.operationKind === 'subscription') {
42
- !observeSubscribeWithEvents ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayNetwork: This network layer does not support Subscriptions. ' + 'To use Subscriptions, provide a custom network layer.') : require('fbjs/lib/invariant')(false) : void 0;
43
-
44
- !!uploadables ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayNetwork: Cannot provide uploadables while subscribing.') : require('fbjs/lib/invariant')(false) : void 0;
45
- return observeSubscribeWithEvents(request, variables, cacheConfig);
46
- }
47
-
48
- var pollInterval = cacheConfig.poll;
49
31
  if (pollInterval != null) {
50
- !!uploadables ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayNetwork: Cannot provide uploadables while polling.') : require('fbjs/lib/invariant')(false) : void 0;
51
- return observeFetch(request, variables, { force: true }).poll(pollInterval);
32
+ !!uploadables ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayNetwork: Cannot provide uploadables while polling.') : require("fbjs/lib/invariant")(false) : void 0;
33
+ return observeFetch(request, variables, {
34
+ force: true
35
+ }).poll(pollInterval);
52
36
  }
53
37
 
54
38
  return observeFetch(request, variables, cacheConfig, uploadables);
55
39
  }
56
40
 
57
- return { execute: execute, executeWithEvents: executeWithEvents };
41
+ return {
42
+ execute: execute
43
+ };
58
44
  }
59
45
 
60
- module.exports = { create: create };
46
+ module.exports = {
47
+ create: create
48
+ };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2013-present, Facebook, Inc.
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -7,7 +7,6 @@
7
7
  * strict-local
8
8
  * @format
9
9
  */
10
-
11
10
  'use strict';
12
11
 
13
- module.exports = require('./createRelayNetworkLogger')(require('./RelayNetworkLoggerTransaction'));
12
+ module.exports = require("./createRelayNetworkLogger")(require("./RelayNetworkLoggerTransaction"));