relay-runtime 11.0.0-rc.0 → 12.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/handlers/connection/ConnectionHandler.js.flow +7 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +20 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +12 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +15 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +148 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +406 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayRecordProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceMutator.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +7 -2
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +5 -2
- package/lib/mutations/validateMutation.js +39 -17
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayObservable.js +3 -1
- package/lib/network/RelayQueryResponseCache.js +20 -3
- package/lib/network/wrapNetworkWithLogObserver.js +78 -0
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +1 -1
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/store/DataChecker.js +132 -50
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +524 -187
- package/lib/store/RelayConcreteVariables.js +29 -4
- package/lib/store/RelayModernEnvironment.js +137 -220
- package/lib/store/RelayModernFragmentSpecResolver.js +49 -23
- package/lib/store/RelayModernRecord.js +36 -2
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +53 -22
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +30 -8
- package/lib/store/RelayReader.js +177 -29
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +53 -28
- package/lib/store/RelayResponseNormalizer.js +247 -108
- package/lib/store/RelayStoreReactFlightUtils.js +7 -11
- package/lib/store/RelayStoreSubscriptions.js +8 -5
- package/lib/store/RelayStoreUtils.js +10 -4
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createRelayContext.js +2 -2
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +32 -6
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +5 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +67 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +217 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +485 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +245 -0
- package/multi-actor-environment/index.js.flow +27 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
- package/mutations/commitMutation.js.flow +3 -1
- package/mutations/validateMutation.js.flow +42 -16
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +2 -0
- package/network/RelayQueryResponseCache.js.flow +31 -17
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +3 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +5 -1
- package/store/DataChecker.js.flow +148 -44
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +578 -237
- package/store/RelayConcreteVariables.js.flow +31 -1
- package/store/RelayModernEnvironment.js.flow +132 -220
- package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
- package/store/RelayModernOperationDescriptor.js.flow +9 -3
- package/store/RelayModernRecord.js.flow +49 -0
- package/store/RelayModernStore.js.flow +57 -17
- package/store/RelayOperationTracker.js.flow +56 -34
- package/store/RelayPublishQueue.js.flow +37 -11
- package/store/RelayReader.js.flow +186 -27
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +51 -21
- package/store/RelayResponseNormalizer.js.flow +251 -67
- package/store/RelayStoreReactFlightUtils.js.flow +6 -9
- package/store/RelayStoreSubscriptions.js.flow +10 -3
- package/store/RelayStoreTypes.js.flow +144 -21
- package/store/RelayStoreUtils.js.flow +19 -4
- package/store/ResolverCache.js.flow +247 -0
- package/store/ResolverFragments.js.flow +128 -0
- package/store/createRelayContext.js.flow +1 -1
- package/store/defaultGetDataID.js.flow +3 -1
- package/subscription/requestSubscription.js.flow +43 -8
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +29 -2
- package/util/RelayConcreteNode.js.flow +3 -0
- package/util/RelayFeatureFlags.js.flow +10 -6
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +7 -6
- package/util/RelayRuntimeTypes.js.flow +4 -2
- package/util/deepFreeze.js.flow +2 -1
- package/util/getPaginationMetadata.js.flow +74 -0
- package/util/getPaginationVariables.js.flow +112 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +80 -0
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -20,24 +20,25 @@ var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
|
20
20
|
|
|
21
21
|
var areEqual = require("fbjs/lib/areEqual");
|
|
22
22
|
|
|
23
|
-
var
|
|
23
|
+
var getPendingOperationsForFragment = require('../util/getPendingOperationsForFragment');
|
|
24
|
+
|
|
25
|
+
var invariant = require('invariant');
|
|
24
26
|
|
|
25
27
|
var isScalarAndEqual = require('../util/isScalarAndEqual');
|
|
26
28
|
|
|
29
|
+
var recycleNodesInto = require('../util/recycleNodesInto');
|
|
30
|
+
|
|
27
31
|
var reportMissingRequiredFields = require('../util/reportMissingRequiredFields');
|
|
28
32
|
|
|
29
33
|
var warning = require("fbjs/lib/warning");
|
|
30
34
|
|
|
31
|
-
var _require = require('
|
|
32
|
-
|
|
35
|
+
var _require = require('./RelayModernOperationDescriptor'),
|
|
36
|
+
createRequestDescriptor = _require.createRequestDescriptor;
|
|
33
37
|
|
|
34
|
-
var _require2 = require('./
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
areEqualSelectors = _require3.areEqualSelectors,
|
|
39
|
-
createReaderSelector = _require3.createReaderSelector,
|
|
40
|
-
getSelectorsFromObject = _require3.getSelectorsFromObject;
|
|
38
|
+
var _require2 = require('./RelayModernSelector'),
|
|
39
|
+
areEqualSelectors = _require2.areEqualSelectors,
|
|
40
|
+
createReaderSelector = _require2.createReaderSelector,
|
|
41
|
+
getSelectorsFromObject = _require2.getSelectorsFromObject;
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
44
|
* A utility for resolving and subscribing to the results of a fragment spec
|
|
@@ -129,13 +130,17 @@ var RelayModernFragmentSpecResolver = /*#__PURE__*/function () {
|
|
|
129
130
|
return this._data;
|
|
130
131
|
};
|
|
131
132
|
|
|
132
|
-
_proto.setCallback = function setCallback(callback) {
|
|
133
|
+
_proto.setCallback = function setCallback(props, callback) {
|
|
133
134
|
this._callback = callback;
|
|
135
|
+
|
|
136
|
+
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
|
137
|
+
this.setProps(props);
|
|
138
|
+
}
|
|
134
139
|
};
|
|
135
140
|
|
|
136
141
|
_proto.setProps = function setProps(props) {
|
|
137
|
-
var ownedSelectors = getSelectorsFromObject(this._fragments, props);
|
|
138
142
|
this._props = {};
|
|
143
|
+
var ownedSelectors = getSelectorsFromObject(this._fragments, props);
|
|
139
144
|
|
|
140
145
|
for (var _key3 in ownedSelectors) {
|
|
141
146
|
if (ownedSelectors.hasOwnProperty(_key3)) {
|
|
@@ -150,14 +155,14 @@ var RelayModernFragmentSpecResolver = /*#__PURE__*/function () {
|
|
|
150
155
|
resolver = null;
|
|
151
156
|
} else if (ownedSelector.kind === 'PluralReaderSelector') {
|
|
152
157
|
if (resolver == null) {
|
|
153
|
-
resolver = new SelectorListResolver(this._context.environment, this._rootIsQueryRenderer, ownedSelector, this._onChange);
|
|
158
|
+
resolver = new SelectorListResolver(this._context.environment, this._rootIsQueryRenderer, ownedSelector, this._callback != null, this._onChange);
|
|
154
159
|
} else {
|
|
155
160
|
!(resolver instanceof SelectorListResolver) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernFragmentSpecResolver: Expected prop `%s` to always be an array.', _key3) : invariant(false) : void 0;
|
|
156
161
|
resolver.setSelector(ownedSelector);
|
|
157
162
|
}
|
|
158
163
|
} else {
|
|
159
164
|
if (resolver == null) {
|
|
160
|
-
resolver = new SelectorResolver(this._context.environment, this._rootIsQueryRenderer, ownedSelector, this._onChange);
|
|
165
|
+
resolver = new SelectorResolver(this._context.environment, this._rootIsQueryRenderer, ownedSelector, this._callback != null, this._onChange);
|
|
161
166
|
} else {
|
|
162
167
|
!(resolver instanceof SelectorResolver) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernFragmentSpecResolver: Expected prop `%s` to always be an object.', _key3) : invariant(false) : void 0;
|
|
163
168
|
resolver.setSelector(ownedSelector);
|
|
@@ -194,7 +199,7 @@ var RelayModernFragmentSpecResolver = /*#__PURE__*/function () {
|
|
|
194
199
|
|
|
195
200
|
|
|
196
201
|
var SelectorResolver = /*#__PURE__*/function () {
|
|
197
|
-
function SelectorResolver(environment, rootIsQueryRenderer, selector, callback) {
|
|
202
|
+
function SelectorResolver(environment, rootIsQueryRenderer, selector, subscribeOnConstruction, callback) {
|
|
198
203
|
var _this2 = this;
|
|
199
204
|
|
|
200
205
|
(0, _defineProperty2["default"])(this, "_onChange", function (snapshot) {
|
|
@@ -214,7 +219,14 @@ var SelectorResolver = /*#__PURE__*/function () {
|
|
|
214
219
|
this._environment = environment;
|
|
215
220
|
this._rootIsQueryRenderer = rootIsQueryRenderer;
|
|
216
221
|
this._selector = selector;
|
|
217
|
-
|
|
222
|
+
|
|
223
|
+
if (RelayFeatureFlags.ENABLE_CONTAINERS_SUBSCRIBE_ON_COMMIT === true) {
|
|
224
|
+
if (subscribeOnConstruction) {
|
|
225
|
+
this._subscription = environment.subscribe(_snapshot, this._onChange);
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
this._subscription = environment.subscribe(_snapshot, this._onChange);
|
|
229
|
+
}
|
|
218
230
|
}
|
|
219
231
|
|
|
220
232
|
var _proto2 = SelectorResolver.prototype;
|
|
@@ -228,9 +240,7 @@ var SelectorResolver = /*#__PURE__*/function () {
|
|
|
228
240
|
};
|
|
229
241
|
|
|
230
242
|
_proto2.resolve = function resolve() {
|
|
231
|
-
if (
|
|
232
|
-
var _getPromiseForActiveR;
|
|
233
|
-
|
|
243
|
+
if (this._isMissingData === true) {
|
|
234
244
|
// NOTE: This branch exists to handle the case in which:
|
|
235
245
|
// - A RelayModern container is rendered as a descendant of a Relay Hook
|
|
236
246
|
// root using a "partial" renderPolicy (this means that eargerly
|
|
@@ -252,13 +262,28 @@ var SelectorResolver = /*#__PURE__*/function () {
|
|
|
252
262
|
// This should eventually go away with something like @optional, where we only
|
|
253
263
|
// suspend at specific boundaries depending on whether the boundary
|
|
254
264
|
// can be fulfilled or not.
|
|
255
|
-
var
|
|
265
|
+
var pendingOperationsResult = getPendingOperationsForFragment(this._environment, this._selector.node, this._selector.owner);
|
|
266
|
+
var promise = pendingOperationsResult === null || pendingOperationsResult === void 0 ? void 0 : pendingOperationsResult.promise;
|
|
256
267
|
|
|
257
268
|
if (promise != null) {
|
|
258
269
|
if (this._rootIsQueryRenderer) {
|
|
259
270
|
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Relay Container for fragment `%s` has missing data and ' + 'would suspend. When using features such as @defer or @module, ' + 'use `useFragment` instead of a Relay Container.', this._selector.node.name) : void 0;
|
|
260
271
|
} else {
|
|
272
|
+
var _pendingOperationsRes;
|
|
273
|
+
|
|
274
|
+
var pendingOperations = (_pendingOperationsRes = pendingOperationsResult === null || pendingOperationsResult === void 0 ? void 0 : pendingOperationsResult.pendingOperations) !== null && _pendingOperationsRes !== void 0 ? _pendingOperationsRes : [];
|
|
261
275
|
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Relay Container for fragment `%s` suspended. When using ' + 'features such as @defer or @module, use `useFragment` instead ' + 'of a Relay Container.', this._selector.node.name) : void 0;
|
|
276
|
+
|
|
277
|
+
this._environment.__log({
|
|
278
|
+
name: 'suspense.fragment',
|
|
279
|
+
data: this._data,
|
|
280
|
+
fragment: this._selector.node,
|
|
281
|
+
isRelayHooks: false,
|
|
282
|
+
isMissingData: this._isMissingData,
|
|
283
|
+
isPromiseCached: false,
|
|
284
|
+
pendingOperations: pendingOperations
|
|
285
|
+
});
|
|
286
|
+
|
|
262
287
|
throw promise;
|
|
263
288
|
}
|
|
264
289
|
}
|
|
@@ -280,7 +305,7 @@ var SelectorResolver = /*#__PURE__*/function () {
|
|
|
280
305
|
|
|
281
306
|
var snapshot = this._environment.lookup(selector);
|
|
282
307
|
|
|
283
|
-
this._data = snapshot.data;
|
|
308
|
+
this._data = recycleNodesInto(this._data, snapshot.data);
|
|
284
309
|
this._isMissingData = snapshot.isMissingData;
|
|
285
310
|
this._missingRequiredFields = snapshot.missingRequiredFields;
|
|
286
311
|
this._selector = selector;
|
|
@@ -319,7 +344,7 @@ var SelectorResolver = /*#__PURE__*/function () {
|
|
|
319
344
|
|
|
320
345
|
|
|
321
346
|
var SelectorListResolver = /*#__PURE__*/function () {
|
|
322
|
-
function SelectorListResolver(environment, rootIsQueryRenderer, selector, callback) {
|
|
347
|
+
function SelectorListResolver(environment, rootIsQueryRenderer, selector, subscribeOnConstruction, callback) {
|
|
323
348
|
var _this3 = this;
|
|
324
349
|
|
|
325
350
|
(0, _defineProperty2["default"])(this, "_onChange", function (data) {
|
|
@@ -333,6 +358,7 @@ var SelectorListResolver = /*#__PURE__*/function () {
|
|
|
333
358
|
this._resolvers = [];
|
|
334
359
|
this._stale = true;
|
|
335
360
|
this._rootIsQueryRenderer = rootIsQueryRenderer;
|
|
361
|
+
this._subscribeOnConstruction = subscribeOnConstruction;
|
|
336
362
|
this.setSelector(selector);
|
|
337
363
|
}
|
|
338
364
|
|
|
@@ -384,7 +410,7 @@ var SelectorListResolver = /*#__PURE__*/function () {
|
|
|
384
410
|
if (ii < this._resolvers.length) {
|
|
385
411
|
this._resolvers[ii].setSelector(selectors[ii]);
|
|
386
412
|
} else {
|
|
387
|
-
this._resolvers[ii] = new SelectorResolver(this._environment, this._rootIsQueryRenderer, selectors[ii], this._onChange);
|
|
413
|
+
this._resolvers[ii] = new SelectorResolver(this._environment, this._rootIsQueryRenderer, selectors[ii], this._subscribeOnConstruction, this._onChange);
|
|
388
414
|
}
|
|
389
415
|
}
|
|
390
416
|
|
|
@@ -18,7 +18,7 @@ var areEqual = require("fbjs/lib/areEqual");
|
|
|
18
18
|
|
|
19
19
|
var deepFreeze = require('../util/deepFreeze');
|
|
20
20
|
|
|
21
|
-
var invariant = require(
|
|
21
|
+
var invariant = require('invariant');
|
|
22
22
|
|
|
23
23
|
var warning = require("fbjs/lib/warning");
|
|
24
24
|
|
|
@@ -26,6 +26,7 @@ var _require = require('./ClientID'),
|
|
|
26
26
|
isClientID = _require.isClientID;
|
|
27
27
|
|
|
28
28
|
var _require2 = require('./RelayStoreUtils'),
|
|
29
|
+
ACTOR_IDENTIFIER_KEY = _require2.ACTOR_IDENTIFIER_KEY,
|
|
29
30
|
ID_KEY = _require2.ID_KEY,
|
|
30
31
|
REF_KEY = _require2.REF_KEY,
|
|
31
32
|
REFS_KEY = _require2.REFS_KEY,
|
|
@@ -336,6 +337,37 @@ function setLinkedRecordIDs(record, storageKey, linkedIDs) {
|
|
|
336
337
|
links[REFS_KEY] = linkedIDs;
|
|
337
338
|
record[storageKey] = links;
|
|
338
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* @public
|
|
342
|
+
*
|
|
343
|
+
* Set the value of a field to a reference to another record in the actor specific store.
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
function setActorLinkedRecordID(record, storageKey, actorIdentifier, linkedID) {
|
|
348
|
+
// See perf note above for why we aren't using computed property access.
|
|
349
|
+
var link = {};
|
|
350
|
+
link[REF_KEY] = linkedID;
|
|
351
|
+
link[ACTOR_IDENTIFIER_KEY] = actorIdentifier;
|
|
352
|
+
record[storageKey] = link;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* @public
|
|
356
|
+
*
|
|
357
|
+
* Get link to a record and the actor identifier for the store.
|
|
358
|
+
*/
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
function getActorLinkedRecordID(record, storageKey) {
|
|
362
|
+
var link = record[storageKey];
|
|
363
|
+
|
|
364
|
+
if (link == null) {
|
|
365
|
+
return link;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
!(typeof link === 'object' && typeof link[REF_KEY] === 'string' && link[ACTOR_IDENTIFIER_KEY] != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernRecord.getActorLinkedRecordID(): Expected `%s.%s` to be an actor specific linked ID, ' + 'was `%s`.', record[ID_KEY], storageKey, JSON.stringify(link)) : invariant(false) : void 0;
|
|
369
|
+
return [link[ACTOR_IDENTIFIER_KEY], link[REF_KEY]];
|
|
370
|
+
}
|
|
339
371
|
|
|
340
372
|
module.exports = {
|
|
341
373
|
clone: clone,
|
|
@@ -352,5 +384,7 @@ module.exports = {
|
|
|
352
384
|
setValue: setValue,
|
|
353
385
|
setLinkedRecordID: setLinkedRecordID,
|
|
354
386
|
setLinkedRecordIDs: setLinkedRecordIDs,
|
|
355
|
-
update: update
|
|
387
|
+
update: update,
|
|
388
|
+
getActorLinkedRecordID: getActorLinkedRecordID,
|
|
389
|
+
setActorLinkedRecordID: setActorLinkedRecordID
|
|
356
390
|
};
|
|
@@ -24,8 +24,6 @@ var RelayModernRecord = require('./RelayModernRecord');
|
|
|
24
24
|
|
|
25
25
|
var RelayOptimisticRecordSource = require('./RelayOptimisticRecordSource');
|
|
26
26
|
|
|
27
|
-
var RelayProfiler = require('../util/RelayProfiler');
|
|
28
|
-
|
|
29
27
|
var RelayReader = require('./RelayReader');
|
|
30
28
|
|
|
31
29
|
var RelayReferenceMarker = require('./RelayReferenceMarker');
|
|
@@ -34,21 +32,26 @@ var RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
|
|
|
34
32
|
|
|
35
33
|
var RelayStoreSubscriptions = require('./RelayStoreSubscriptions');
|
|
36
34
|
|
|
37
|
-
var RelayStoreSubscriptionsUsingMapByID = require('./RelayStoreSubscriptionsUsingMapByID');
|
|
38
|
-
|
|
39
35
|
var RelayStoreUtils = require('./RelayStoreUtils');
|
|
40
36
|
|
|
41
37
|
var deepFreeze = require('../util/deepFreeze');
|
|
42
38
|
|
|
43
39
|
var defaultGetDataID = require('./defaultGetDataID');
|
|
44
40
|
|
|
45
|
-
var invariant = require(
|
|
41
|
+
var invariant = require('invariant');
|
|
46
42
|
|
|
47
43
|
var resolveImmediate = require('../util/resolveImmediate');
|
|
48
44
|
|
|
49
|
-
var _require = require('
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
var _require = require('../multi-actor-environment/ActorIdentifier'),
|
|
46
|
+
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE = _require.INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
47
|
+
assertInternalActorIndentifier = _require.assertInternalActorIndentifier;
|
|
48
|
+
|
|
49
|
+
var _require2 = require('./RelayStoreUtils'),
|
|
50
|
+
ROOT_ID = _require2.ROOT_ID,
|
|
51
|
+
ROOT_TYPE = _require2.ROOT_TYPE;
|
|
52
|
+
|
|
53
|
+
var _require3 = require('./ResolverCache'),
|
|
54
|
+
RecordResolverCache = _require3.RecordResolverCache;
|
|
52
55
|
|
|
53
56
|
var DEFAULT_RELEASE_BUFFER_SIZE = 10;
|
|
54
57
|
/**
|
|
@@ -110,8 +113,12 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
110
113
|
this._releaseBuffer = [];
|
|
111
114
|
this._roots = new Map();
|
|
112
115
|
this._shouldScheduleGC = false;
|
|
113
|
-
this.
|
|
116
|
+
this._resolverCache = new RecordResolverCache(function () {
|
|
117
|
+
return _this._getMutableRecordSource();
|
|
118
|
+
});
|
|
119
|
+
this._storeSubscriptions = new RelayStoreSubscriptions(options === null || options === void 0 ? void 0 : options.log, this._resolverCache);
|
|
114
120
|
this._updatedRecordIDs = new Set();
|
|
121
|
+
this._shouldProcessClientComponents = options === null || options === void 0 ? void 0 : options.shouldProcessClientComponents;
|
|
115
122
|
initializeRecordSource(this._recordSource);
|
|
116
123
|
}
|
|
117
124
|
|
|
@@ -123,11 +130,19 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
123
130
|
return (_this$_optimisticSour = this._optimisticSource) !== null && _this$_optimisticSour !== void 0 ? _this$_optimisticSour : this._recordSource;
|
|
124
131
|
};
|
|
125
132
|
|
|
133
|
+
_proto._getMutableRecordSource = function _getMutableRecordSource() {
|
|
134
|
+
var _this$_optimisticSour2;
|
|
135
|
+
|
|
136
|
+
return (_this$_optimisticSour2 = this._optimisticSource) !== null && _this$_optimisticSour2 !== void 0 ? _this$_optimisticSour2 : this._recordSource;
|
|
137
|
+
};
|
|
138
|
+
|
|
126
139
|
_proto.check = function check(operation, options) {
|
|
127
|
-
var
|
|
140
|
+
var _options$handlers, _options$getSourceFor, _options$getTargetFor, _options$defaultActor;
|
|
128
141
|
|
|
129
142
|
var selector = operation.root;
|
|
130
|
-
|
|
143
|
+
|
|
144
|
+
var source = this._getMutableRecordSource();
|
|
145
|
+
|
|
131
146
|
var globalInvalidationEpoch = this._globalInvalidationEpoch;
|
|
132
147
|
|
|
133
148
|
var rootEntry = this._roots.get(operation.request.identifier);
|
|
@@ -136,7 +151,7 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
136
151
|
|
|
137
152
|
if (globalInvalidationEpoch != null) {
|
|
138
153
|
// If so, check if the operation we're checking was last written
|
|
139
|
-
// before or after invalidation
|
|
154
|
+
// before or after invalidation occurred.
|
|
140
155
|
if (operationLastWrittenAt == null || operationLastWrittenAt <= globalInvalidationEpoch) {
|
|
141
156
|
// If the operation was written /before/ global invalidation occurred,
|
|
142
157
|
// or if this operation has never been written to the store before,
|
|
@@ -148,9 +163,16 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
148
163
|
}
|
|
149
164
|
}
|
|
150
165
|
|
|
151
|
-
var target = (_options$target = options === null || options === void 0 ? void 0 : options.target) !== null && _options$target !== void 0 ? _options$target : source;
|
|
152
166
|
var handlers = (_options$handlers = options === null || options === void 0 ? void 0 : options.handlers) !== null && _options$handlers !== void 0 ? _options$handlers : [];
|
|
153
|
-
var
|
|
167
|
+
var getSourceForActor = (_options$getSourceFor = options === null || options === void 0 ? void 0 : options.getSourceForActor) !== null && _options$getSourceFor !== void 0 ? _options$getSourceFor : function (actorIdentifier) {
|
|
168
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
169
|
+
return source;
|
|
170
|
+
};
|
|
171
|
+
var getTargetForActor = (_options$getTargetFor = options === null || options === void 0 ? void 0 : options.getTargetForActor) !== null && _options$getTargetFor !== void 0 ? _options$getTargetFor : function (actorIdentifier) {
|
|
172
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
173
|
+
return source;
|
|
174
|
+
};
|
|
175
|
+
var operationAvailability = DataChecker.check(getSourceForActor, getTargetForActor, (_options$defaultActor = options === null || options === void 0 ? void 0 : options.defaultActorIdentifier) !== null && _options$defaultActor !== void 0 ? _options$defaultActor : INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE, selector, handlers, this._operationLoader, this._getDataID, this._shouldProcessClientComponents);
|
|
154
176
|
return getAvailabilityStatus(operationAvailability, operationLastWrittenAt, rootEntry === null || rootEntry === void 0 ? void 0 : rootEntry.fetchTime, this._queryCacheExpirationTime);
|
|
155
177
|
};
|
|
156
178
|
|
|
@@ -235,7 +257,7 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
235
257
|
|
|
236
258
|
_proto.lookup = function lookup(selector) {
|
|
237
259
|
var source = this.getSource();
|
|
238
|
-
var snapshot = RelayReader.read(source, selector);
|
|
260
|
+
var snapshot = RelayReader.read(source, selector, this._resolverCache);
|
|
239
261
|
|
|
240
262
|
if (process.env.NODE_ENV !== "production") {
|
|
241
263
|
deepFreeze(snapshot);
|
|
@@ -265,6 +287,14 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
265
287
|
this._globalInvalidationEpoch = this._currentWriteEpoch;
|
|
266
288
|
}
|
|
267
289
|
|
|
290
|
+
if (RelayFeatureFlags.ENABLE_RELAY_RESOLVERS) {
|
|
291
|
+
// When a record is updated, we need to also handle records that depend on it,
|
|
292
|
+
// specifically Relay Resolver result records containing results based on the
|
|
293
|
+
// updated records. This both adds to updatedRecordIDs and invalidates any
|
|
294
|
+
// cached data as needed.
|
|
295
|
+
this._resolverCache.invalidateDataIDs(this._updatedRecordIDs);
|
|
296
|
+
}
|
|
297
|
+
|
|
268
298
|
var source = this.getSource();
|
|
269
299
|
var updatedOwners = [];
|
|
270
300
|
|
|
@@ -323,9 +353,8 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
323
353
|
};
|
|
324
354
|
|
|
325
355
|
_proto.publish = function publish(source, idsMarkedForInvalidation) {
|
|
326
|
-
var
|
|
356
|
+
var target = this._getMutableRecordSource();
|
|
327
357
|
|
|
328
|
-
var target = (_this$_optimisticSour3 = this._optimisticSource) !== null && _this$_optimisticSour3 !== void 0 ? _this$_optimisticSour3 : this._recordSource;
|
|
329
358
|
updateTargetFromSource(target, source, // We increment the current epoch at the end of the set of updates,
|
|
330
359
|
// in notify(). Here, we pass what will be the incremented value of
|
|
331
360
|
// the epoch to use to write to invalidated records.
|
|
@@ -376,6 +405,10 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
376
405
|
|
|
377
406
|
_proto.toJSON = function toJSON() {
|
|
378
407
|
return 'RelayModernStore()';
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
_proto.getEpoch = function getEpoch() {
|
|
411
|
+
return this._currentWriteEpoch;
|
|
379
412
|
} // Internal API
|
|
380
413
|
;
|
|
381
414
|
|
|
@@ -549,7 +582,7 @@ var RelayModernStore = /*#__PURE__*/function () {
|
|
|
549
582
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
550
583
|
var operation = _step2.value.operation;
|
|
551
584
|
var selector = operation.root;
|
|
552
|
-
RelayReferenceMarker.mark(this._recordSource, selector, references, this._operationLoader); // Yield for other work after each operation
|
|
585
|
+
RelayReferenceMarker.mark(this._recordSource, selector, references, this._operationLoader, this._shouldProcessClientComponents); // Yield for other work after each operation
|
|
553
586
|
|
|
554
587
|
yield; // If the store was updated, restart
|
|
555
588
|
|
|
@@ -647,7 +680,8 @@ function updateTargetFromSource(target, source, currentWriteEpoch, idsMarkedForI
|
|
|
647
680
|
}
|
|
648
681
|
|
|
649
682
|
RelayModernRecord.setValue(nextRecord, RelayStoreUtils.INVALIDATED_AT_KEY, currentWriteEpoch);
|
|
650
|
-
invalidatedRecordIDs.add(dataID);
|
|
683
|
+
invalidatedRecordIDs.add(dataID); // $FlowFixMe[incompatible-call]
|
|
684
|
+
|
|
651
685
|
target.set(dataID, nextRecord);
|
|
652
686
|
});
|
|
653
687
|
} // Update the target based on the changes present in source
|
|
@@ -745,7 +779,4 @@ function getAvailabilityStatus(operationAvailability, operationLastWrittenAt, op
|
|
|
745
779
|
};
|
|
746
780
|
}
|
|
747
781
|
|
|
748
|
-
RelayProfiler.instrumentMethods(RelayModernStore.prototype, {
|
|
749
|
-
lookup: 'RelayModernStore.prototype.lookup'
|
|
750
|
-
});
|
|
751
782
|
module.exports = RelayModernStore;
|
|
@@ -14,13 +14,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
16
16
|
|
|
17
|
-
var invariant = require(
|
|
17
|
+
var invariant = require('invariant');
|
|
18
18
|
|
|
19
19
|
var RelayOperationTracker = /*#__PURE__*/function () {
|
|
20
20
|
function RelayOperationTracker() {
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
21
|
+
this._ownersToPendingOperations = new Map();
|
|
22
|
+
this._pendingOperationsToOwners = new Map();
|
|
23
|
+
this._ownersToPendingPromise = new Map();
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Update the map of current processing operations with the set of
|
|
@@ -46,19 +46,19 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
46
46
|
var owner = _step.value;
|
|
47
47
|
var ownerIdentifier = owner.identifier;
|
|
48
48
|
|
|
49
|
-
var pendingOperationsAffectingOwner = this.
|
|
49
|
+
var pendingOperationsAffectingOwner = this._ownersToPendingOperations.get(ownerIdentifier);
|
|
50
50
|
|
|
51
51
|
if (pendingOperationsAffectingOwner != null) {
|
|
52
52
|
// In this case the `ownerIdentifier` already affected by some operations
|
|
53
53
|
// We just need to detect, is it the same operation that we already
|
|
54
54
|
// have in the list, or it's a new operation
|
|
55
55
|
if (!pendingOperationsAffectingOwner.has(pendingOperationIdentifier)) {
|
|
56
|
-
pendingOperationsAffectingOwner.
|
|
56
|
+
pendingOperationsAffectingOwner.set(pendingOperationIdentifier, pendingOperation);
|
|
57
57
|
newlyAffectedOwnersIdentifier.add(ownerIdentifier);
|
|
58
58
|
}
|
|
59
59
|
} else {
|
|
60
60
|
// This is a new `ownerIdentifier` that is affected by the operation
|
|
61
|
-
this.
|
|
61
|
+
this._ownersToPendingOperations.set(ownerIdentifier, new Map([[pendingOperationIdentifier, pendingOperation]]));
|
|
62
62
|
|
|
63
63
|
newlyAffectedOwnersIdentifier.add(ownerIdentifier);
|
|
64
64
|
}
|
|
@@ -73,10 +73,10 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
73
73
|
if (newlyAffectedOwnersIdentifier.size === 0) {
|
|
74
74
|
return;
|
|
75
75
|
} // But, if some owners were affected we need to add them to
|
|
76
|
-
// the `
|
|
76
|
+
// the `_pendingOperationsToOwners` set
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
var
|
|
79
|
+
var ownersAffectedByPendingOperation = this._pendingOperationsToOwners.get(pendingOperationIdentifier) || new Set();
|
|
80
80
|
|
|
81
81
|
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(newlyAffectedOwnersIdentifier),
|
|
82
82
|
_step2;
|
|
@@ -87,7 +87,7 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
87
87
|
|
|
88
88
|
this._resolveOwnerResolvers(_ownerIdentifier);
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
ownersAffectedByPendingOperation.add(_ownerIdentifier);
|
|
91
91
|
}
|
|
92
92
|
} catch (err) {
|
|
93
93
|
_iterator2.e(err);
|
|
@@ -95,7 +95,7 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
95
95
|
_iterator2.f();
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
this.
|
|
98
|
+
this._pendingOperationsToOwners.set(pendingOperationIdentifier, ownersAffectedByPendingOperation);
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
101
|
* Once pending operation is completed we need to remove it
|
|
@@ -106,7 +106,7 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
106
106
|
_proto.complete = function complete(pendingOperation) {
|
|
107
107
|
var pendingOperationIdentifier = pendingOperation.identifier;
|
|
108
108
|
|
|
109
|
-
var affectedOwnersIdentifier = this.
|
|
109
|
+
var affectedOwnersIdentifier = this._pendingOperationsToOwners.get(pendingOperationIdentifier);
|
|
110
110
|
|
|
111
111
|
if (affectedOwnersIdentifier == null) {
|
|
112
112
|
return;
|
|
@@ -125,7 +125,7 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
125
125
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
126
126
|
var ownerIdentifier = _step3.value;
|
|
127
127
|
|
|
128
|
-
var pendingOperationsAffectingOwner = this.
|
|
128
|
+
var pendingOperationsAffectingOwner = this._ownersToPendingOperations.get(ownerIdentifier);
|
|
129
129
|
|
|
130
130
|
if (!pendingOperationsAffectingOwner) {
|
|
131
131
|
continue;
|
|
@@ -155,7 +155,7 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
155
155
|
|
|
156
156
|
this._resolveOwnerResolvers(_ownerIdentifier2);
|
|
157
157
|
|
|
158
|
-
this.
|
|
158
|
+
this._ownersToPendingOperations["delete"](_ownerIdentifier2);
|
|
159
159
|
} // Update all ownerIdentifier that were updated by `pendingOperationIdentifier` but still
|
|
160
160
|
// are affected by other operations
|
|
161
161
|
|
|
@@ -181,30 +181,35 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
181
181
|
_iterator5.f();
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
this.
|
|
184
|
+
this._pendingOperationsToOwners["delete"](pendingOperationIdentifier);
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
_proto._resolveOwnerResolvers = function _resolveOwnerResolvers(ownerIdentifier) {
|
|
188
|
-
var promiseEntry = this.
|
|
188
|
+
var promiseEntry = this._ownersToPendingPromise.get(ownerIdentifier);
|
|
189
189
|
|
|
190
190
|
if (promiseEntry != null) {
|
|
191
191
|
promiseEntry.resolve();
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
-
this.
|
|
194
|
+
this._ownersToPendingPromise["delete"](ownerIdentifier);
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
_proto.
|
|
197
|
+
_proto.getPendingOperationsAffectingOwner = function getPendingOperationsAffectingOwner(owner) {
|
|
198
198
|
var ownerIdentifier = owner.identifier;
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
var pendingOperationsForOwner = this._ownersToPendingOperations.get(ownerIdentifier);
|
|
201
|
+
|
|
202
|
+
if (pendingOperationsForOwner == null || pendingOperationsForOwner.size === 0) {
|
|
201
203
|
return null;
|
|
202
204
|
}
|
|
203
205
|
|
|
204
|
-
var cachedPromiseEntry = this.
|
|
206
|
+
var cachedPromiseEntry = this._ownersToPendingPromise.get(ownerIdentifier);
|
|
205
207
|
|
|
206
208
|
if (cachedPromiseEntry != null) {
|
|
207
|
-
return
|
|
209
|
+
return {
|
|
210
|
+
promise: cachedPromiseEntry.promise,
|
|
211
|
+
pendingOperations: cachedPromiseEntry.pendingOperations
|
|
212
|
+
};
|
|
208
213
|
}
|
|
209
214
|
|
|
210
215
|
var resolve;
|
|
@@ -212,13 +217,18 @@ var RelayOperationTracker = /*#__PURE__*/function () {
|
|
|
212
217
|
resolve = r;
|
|
213
218
|
});
|
|
214
219
|
!(resolve != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayOperationTracker: Expected resolver to be defined. If you' + 'are seeing this, it is likely a bug in Relay.') : invariant(false) : void 0;
|
|
220
|
+
var pendingOperations = Array.from(pendingOperationsForOwner.values());
|
|
215
221
|
|
|
216
|
-
this.
|
|
222
|
+
this._ownersToPendingPromise.set(ownerIdentifier, {
|
|
217
223
|
promise: promise,
|
|
218
|
-
resolve: resolve
|
|
224
|
+
resolve: resolve,
|
|
225
|
+
pendingOperations: pendingOperations
|
|
219
226
|
});
|
|
220
227
|
|
|
221
|
-
return
|
|
228
|
+
return {
|
|
229
|
+
promise: promise,
|
|
230
|
+
pendingOperations: pendingOperations
|
|
231
|
+
};
|
|
222
232
|
};
|
|
223
233
|
|
|
224
234
|
return RelayOperationTracker;
|