relay-runtime 11.0.2 → 13.0.0-rc.2

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 (219) hide show
  1. package/README.md +67 -0
  2. package/handlers/RelayDefaultHandlerProvider.js.flow +3 -3
  3. package/handlers/connection/ConnectionHandler.js.flow +9 -18
  4. package/handlers/connection/ConnectionInterface.js.flow +1 -1
  5. package/handlers/connection/MutationHandlers.js.flow +8 -12
  6. package/index.js +1 -1
  7. package/index.js.flow +57 -35
  8. package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
  9. package/lib/handlers/connection/ConnectionHandler.js +13 -19
  10. package/lib/handlers/connection/ConnectionInterface.js +1 -1
  11. package/lib/handlers/connection/MutationHandlers.js +4 -7
  12. package/lib/index.js +59 -44
  13. package/lib/multi-actor-environment/ActorIdentifier.js +12 -2
  14. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +64 -20
  15. package/lib/multi-actor-environment/ActorUtils.js +27 -0
  16. package/lib/multi-actor-environment/MultiActorEnvironment.js +324 -61
  17. package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
  18. package/lib/multi-actor-environment/index.js +6 -2
  19. package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -2
  20. package/lib/mutations/RelayRecordProxy.js +4 -3
  21. package/lib/mutations/RelayRecordSourceMutator.js +4 -3
  22. package/lib/mutations/RelayRecordSourceProxy.js +13 -5
  23. package/lib/mutations/RelayRecordSourceSelectorProxy.js +19 -6
  24. package/lib/mutations/applyOptimisticMutation.js +7 -7
  25. package/lib/mutations/commitLocalUpdate.js +1 -1
  26. package/lib/mutations/commitMutation.js +15 -11
  27. package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +242 -0
  28. package/lib/mutations/validateMutation.js +11 -6
  29. package/lib/network/ConvertToExecuteFunction.js +3 -2
  30. package/lib/network/RelayNetwork.js +4 -3
  31. package/lib/network/RelayNetworkTypes.js +1 -1
  32. package/lib/network/RelayObservable.js +1 -1
  33. package/lib/network/RelayQueryResponseCache.js +22 -6
  34. package/lib/network/wrapNetworkWithLogObserver.js +79 -0
  35. package/lib/query/GraphQLTag.js +3 -2
  36. package/lib/query/PreloadableQueryRegistry.js +1 -1
  37. package/lib/query/fetchQuery.js +7 -6
  38. package/lib/query/fetchQueryInternal.js +1 -1
  39. package/lib/query/fetchQuery_DEPRECATED.js +3 -2
  40. package/lib/store/ClientID.js +8 -2
  41. package/lib/store/DataChecker.js +124 -55
  42. package/lib/store/OperationExecutor.js +489 -215
  43. package/lib/store/RelayConcreteVariables.js +27 -9
  44. package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
  45. package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
  46. package/lib/store/RelayModernEnvironment.js +100 -120
  47. package/lib/store/RelayModernFragmentSpecResolver.js +53 -27
  48. package/lib/store/RelayModernOperationDescriptor.js +3 -2
  49. package/lib/store/RelayModernRecord.js +48 -13
  50. package/lib/store/RelayModernSelector.js +15 -9
  51. package/lib/store/RelayModernStore.js +56 -23
  52. package/lib/store/RelayOperationTracker.js +34 -24
  53. package/lib/store/RelayOptimisticRecordSource.js +1 -1
  54. package/lib/store/RelayPublishQueue.js +35 -11
  55. package/lib/store/RelayReader.js +257 -72
  56. package/lib/store/RelayRecordSource.js +88 -4
  57. package/lib/store/RelayRecordState.js +1 -1
  58. package/lib/store/RelayReferenceMarker.js +34 -22
  59. package/lib/store/RelayResponseNormalizer.js +172 -96
  60. package/lib/store/RelayStoreReactFlightUtils.js +5 -11
  61. package/lib/store/RelayStoreSubscriptions.js +15 -10
  62. package/lib/store/RelayStoreTypes.js +1 -1
  63. package/lib/store/RelayStoreUtils.js +13 -8
  64. package/lib/store/ResolverCache.js +213 -0
  65. package/lib/store/ResolverFragments.js +10 -6
  66. package/lib/store/StoreInspector.js +1 -1
  67. package/lib/store/TypeID.js +1 -1
  68. package/lib/store/ViewerPattern.js +1 -1
  69. package/lib/store/cloneRelayHandleSourceField.js +6 -5
  70. package/lib/store/cloneRelayScalarHandleSourceField.js +6 -5
  71. package/lib/store/createFragmentSpecResolver.js +1 -1
  72. package/lib/store/createRelayContext.js +5 -3
  73. package/lib/store/defaultGetDataID.js +1 -1
  74. package/lib/store/defaultRequiredFieldLogger.js +1 -1
  75. package/lib/store/hasOverlappingIDs.js +1 -1
  76. package/lib/store/isRelayModernEnvironment.js +1 -1
  77. package/lib/store/normalizeRelayPayload.js +1 -1
  78. package/lib/store/readInlineData.js +7 -3
  79. package/lib/subscription/requestSubscription.js +32 -34
  80. package/lib/util/JSResourceTypes.flow.js +1 -1
  81. package/lib/util/NormalizationNode.js +1 -1
  82. package/lib/util/ReaderNode.js +1 -1
  83. package/lib/util/RelayConcreteNode.js +3 -1
  84. package/lib/util/RelayDefaultHandleKey.js +1 -1
  85. package/lib/util/RelayError.js +1 -1
  86. package/lib/util/RelayFeatureFlags.js +10 -7
  87. package/lib/util/RelayProfiler.js +1 -1
  88. package/lib/util/RelayReplaySubject.js +22 -7
  89. package/lib/util/RelayRuntimeTypes.js +1 -7
  90. package/lib/util/StringInterner.js +71 -0
  91. package/lib/util/createPayloadFor3DField.js +1 -1
  92. package/lib/util/deepFreeze.js +1 -1
  93. package/lib/util/generateID.js +1 -1
  94. package/lib/util/getAllRootVariables.js +29 -0
  95. package/lib/util/getFragmentIdentifier.js +16 -8
  96. package/lib/util/getOperation.js +3 -2
  97. package/lib/util/getPaginationMetadata.js +41 -0
  98. package/lib/util/getPaginationVariables.js +66 -0
  99. package/lib/util/getPendingOperationsForFragment.js +55 -0
  100. package/lib/util/getRefetchMetadata.js +36 -0
  101. package/lib/util/getRelayHandleKey.js +3 -3
  102. package/lib/util/getRequestIdentifier.js +3 -3
  103. package/lib/util/getValueAtPath.js +51 -0
  104. package/lib/util/isEmptyObject.js +2 -2
  105. package/lib/util/isPromise.js +1 -1
  106. package/lib/util/isScalarAndEqual.js +1 -1
  107. package/lib/util/recycleNodesInto.js +1 -1
  108. package/lib/util/registerEnvironmentWithDevTools.js +26 -0
  109. package/lib/util/reportMissingRequiredFields.js +1 -1
  110. package/lib/util/resolveImmediate.js +1 -1
  111. package/lib/util/stableCopy.js +1 -1
  112. package/lib/util/withDuration.js +31 -0
  113. package/multi-actor-environment/ActorIdentifier.js.flow +18 -2
  114. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +94 -58
  115. package/multi-actor-environment/ActorUtils.js.flow +33 -0
  116. package/multi-actor-environment/MultiActorEnvironment.js.flow +366 -93
  117. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +88 -23
  118. package/multi-actor-environment/index.js.flow +3 -1
  119. package/mutations/RelayDeclarativeMutationConfig.js.flow +33 -27
  120. package/mutations/RelayRecordProxy.js.flow +5 -6
  121. package/mutations/RelayRecordSourceMutator.js.flow +5 -7
  122. package/mutations/RelayRecordSourceProxy.js.flow +20 -11
  123. package/mutations/RelayRecordSourceSelectorProxy.js.flow +23 -8
  124. package/mutations/applyOptimisticMutation.js.flow +14 -15
  125. package/mutations/commitLocalUpdate.js.flow +2 -2
  126. package/mutations/commitMutation.js.flow +36 -47
  127. package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +318 -0
  128. package/mutations/validateMutation.js.flow +27 -17
  129. package/network/ConvertToExecuteFunction.js.flow +3 -3
  130. package/network/RelayNetwork.js.flow +5 -6
  131. package/network/RelayNetworkTypes.js.flow +1 -1
  132. package/network/RelayObservable.js.flow +2 -2
  133. package/network/RelayQueryResponseCache.js.flow +35 -22
  134. package/network/wrapNetworkWithLogObserver.js.flow +99 -0
  135. package/package.json +2 -2
  136. package/query/GraphQLTag.js.flow +11 -11
  137. package/query/PreloadableQueryRegistry.js.flow +5 -3
  138. package/query/fetchQuery.js.flow +19 -19
  139. package/query/fetchQueryInternal.js.flow +7 -10
  140. package/query/fetchQuery_DEPRECATED.js.flow +7 -7
  141. package/relay-runtime.js +2 -2
  142. package/relay-runtime.min.js +2 -2
  143. package/store/ClientID.js.flow +15 -4
  144. package/store/DataChecker.js.flow +142 -60
  145. package/store/OperationExecutor.js.flow +575 -320
  146. package/store/RelayConcreteVariables.js.flow +28 -9
  147. package/store/RelayExperimentalGraphResponseHandler.js.flow +121 -0
  148. package/store/RelayExperimentalGraphResponseTransform.js.flow +470 -0
  149. package/store/RelayModernEnvironment.js.flow +91 -115
  150. package/store/RelayModernFragmentSpecResolver.js.flow +56 -32
  151. package/store/RelayModernOperationDescriptor.js.flow +13 -8
  152. package/store/RelayModernRecord.js.flow +68 -12
  153. package/store/RelayModernSelector.js.flow +25 -15
  154. package/store/RelayModernStore.js.flow +67 -32
  155. package/store/RelayOperationTracker.js.flow +60 -44
  156. package/store/RelayOptimisticRecordSource.js.flow +3 -3
  157. package/store/RelayPublishQueue.js.flow +74 -32
  158. package/store/RelayReader.js.flow +319 -100
  159. package/store/RelayRecordSource.js.flow +73 -7
  160. package/store/RelayRecordState.js.flow +1 -1
  161. package/store/RelayReferenceMarker.js.flow +41 -27
  162. package/store/RelayResponseNormalizer.js.flow +204 -86
  163. package/store/RelayStoreReactFlightUtils.js.flow +5 -12
  164. package/store/RelayStoreSubscriptions.js.flow +20 -12
  165. package/store/RelayStoreTypes.js.flow +200 -41
  166. package/store/RelayStoreUtils.js.flow +25 -12
  167. package/store/ResolverCache.js.flow +249 -0
  168. package/store/ResolverFragments.js.flow +16 -20
  169. package/store/StoreInspector.js.flow +3 -3
  170. package/store/TypeID.js.flow +2 -2
  171. package/store/ViewerPattern.js.flow +3 -3
  172. package/store/cloneRelayHandleSourceField.js.flow +6 -7
  173. package/store/cloneRelayScalarHandleSourceField.js.flow +6 -7
  174. package/store/createFragmentSpecResolver.js.flow +4 -5
  175. package/store/createRelayContext.js.flow +4 -4
  176. package/store/defaultGetDataID.js.flow +1 -1
  177. package/store/defaultRequiredFieldLogger.js.flow +1 -1
  178. package/store/hasOverlappingIDs.js.flow +1 -1
  179. package/store/isRelayModernEnvironment.js.flow +1 -1
  180. package/store/normalizeRelayPayload.js.flow +7 -8
  181. package/store/readInlineData.js.flow +8 -9
  182. package/subscription/requestSubscription.js.flow +55 -51
  183. package/util/JSResourceTypes.flow.js.flow +1 -1
  184. package/util/NormalizationNode.js.flow +11 -4
  185. package/util/ReaderNode.js.flow +25 -2
  186. package/util/RelayConcreteNode.js.flow +5 -1
  187. package/util/RelayDefaultHandleKey.js.flow +1 -1
  188. package/util/RelayError.js.flow +1 -1
  189. package/util/RelayFeatureFlags.js.flow +23 -15
  190. package/util/RelayProfiler.js.flow +1 -1
  191. package/util/RelayReplaySubject.js.flow +10 -10
  192. package/util/RelayRuntimeTypes.js.flow +70 -3
  193. package/util/StringInterner.js.flow +69 -0
  194. package/util/createPayloadFor3DField.js.flow +4 -4
  195. package/util/deepFreeze.js.flow +1 -1
  196. package/util/generateID.js.flow +1 -1
  197. package/util/getAllRootVariables.js.flow +36 -0
  198. package/util/getFragmentIdentifier.js.flow +28 -16
  199. package/util/getOperation.js.flow +3 -3
  200. package/util/getPaginationMetadata.js.flow +69 -0
  201. package/util/getPaginationVariables.js.flow +108 -0
  202. package/util/getPendingOperationsForFragment.js.flow +62 -0
  203. package/util/getRefetchMetadata.js.flow +76 -0
  204. package/util/getRelayHandleKey.js.flow +2 -3
  205. package/util/getRequestIdentifier.js.flow +4 -4
  206. package/util/getValueAtPath.js.flow +46 -0
  207. package/util/isEmptyObject.js.flow +2 -1
  208. package/util/isPromise.js.flow +1 -1
  209. package/util/isScalarAndEqual.js.flow +1 -1
  210. package/util/recycleNodesInto.js.flow +1 -1
  211. package/util/registerEnvironmentWithDevTools.js.flow +33 -0
  212. package/util/reportMissingRequiredFields.js.flow +1 -1
  213. package/util/resolveImmediate.js.flow +2 -2
  214. package/util/stableCopy.js.flow +1 -1
  215. package/util/withDuration.js.flow +32 -0
  216. package/lib/store/RelayRecordSourceMapImpl.js +0 -107
  217. package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
  218. package/store/RelayRecordSourceMapImpl.js.flow +0 -91
  219. package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ * @emails oncall+relay
8
+ *
9
+ * @format
10
+ */
11
+ // flowlint ambiguous-object-type:error
12
+ 'use strict';
13
+
14
+ var invariant = require('invariant');
15
+
16
+ function getRefetchMetadata(fragmentNode, componentDisplayName) {
17
+ var _fragmentNode$metadat, _fragmentNode$metadat2;
18
+
19
+ !(((_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) !== true) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected fragment `%s` not to be plural when using ' + '`%s`. Remove `@relay(plural: true)` from fragment `%s` ' + 'in order to use it with `%s`.', fragmentNode.name, componentDisplayName, fragmentNode.name, componentDisplayName) : invariant(false) : void 0;
20
+ var refetchMetadata = (_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.refetch;
21
+ !(refetchMetadata != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected fragment `%s` to be refetchable when using `%s`. ' + 'Did you forget to add a @refetchable directive to the fragment?', componentDisplayName, fragmentNode.name) : invariant(false) : void 0; // handle both commonjs and es modules
22
+
23
+ var refetchableRequest = refetchMetadata.operation["default"] ? refetchMetadata.operation["default"] : refetchMetadata.operation;
24
+ var fragmentRefPathInResponse = refetchMetadata.fragmentPathInResult;
25
+ !(typeof refetchableRequest !== 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected refetch query to be an ' + "operation and not a string when using `%s`. If you're seeing this, " + 'this is likely a bug in Relay.', componentDisplayName) : invariant(false) : void 0;
26
+ var identifierField = refetchMetadata.identifierField;
27
+ !(identifierField == null || typeof identifierField === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: getRefetchMetadata(): Expected `identifierField` to be a string.') : invariant(false) : void 0;
28
+ return {
29
+ fragmentRefPathInResponse: fragmentRefPathInResponse,
30
+ identifierField: identifierField,
31
+ refetchableRequest: refetchableRequest,
32
+ refetchMetadata: refetchMetadata
33
+ };
34
+ }
35
+
36
+ module.exports = getRefetchMetadata;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -10,10 +10,10 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
13
- var invariant = require('invariant');
14
-
15
13
  var _require = require('./RelayDefaultHandleKey'),
16
14
  DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
15
+
16
+ var invariant = require('invariant');
17
17
  /**
18
18
  * @internal
19
19
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -10,10 +10,10 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
13
- var invariant = require('invariant');
14
-
15
13
  var stableCopy = require('./stableCopy');
16
14
 
15
+ var invariant = require('invariant');
16
+
17
17
  /**
18
18
  * Returns a stable identifier for the given pair of `RequestParameters` +
19
19
  * variables.
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ * @emails oncall+relay
8
+ *
9
+ * @format
10
+ */
11
+ // flowlint ambiguous-object-type:error
12
+ 'use strict';
13
+
14
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
15
+
16
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
17
+
18
+ var invariant = require('invariant');
19
+
20
+ function getValueAtPath(data, path) {
21
+ var result = data;
22
+
23
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(path),
24
+ _step;
25
+
26
+ try {
27
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
28
+ var key = _step.value;
29
+
30
+ if (result == null) {
31
+ return null;
32
+ }
33
+
34
+ if (typeof key === 'number') {
35
+ !Array.isArray(result) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an array when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
36
+ result = result[key];
37
+ } else {
38
+ !(typeof result === 'object' && !Array.isArray(result)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an object when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
39
+ result = result[key];
40
+ }
41
+ }
42
+ } catch (err) {
43
+ _iterator.e(err);
44
+ } finally {
45
+ _iterator.f();
46
+ }
47
+
48
+ return result;
49
+ }
50
+
51
+ module.exports = getValueAtPath;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -8,7 +8,7 @@
8
8
  * @format
9
9
  * @emails oncall+relay
10
10
  */
11
- 'use strict';
11
+ 'use strict'; // $FlowFixMe[method-unbinding] added when improving typing for this parameters
12
12
 
13
13
  var hasOwnProperty = Object.prototype.hasOwnProperty;
14
14
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ *
8
+ * @format
9
+ * @emails oncall+relay
10
+ */
11
+ // flowlint ambiguous-object-type:error
12
+ 'use strict';
13
+
14
+ function registerEnvironmentWithDevTools(environment) {
15
+ // Register this Relay Environment with Relay DevTools if it exists.
16
+ // Note: this must always be the last step in the constructor.
17
+ var _global = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : undefined;
18
+
19
+ var devToolsHook = _global && _global.__RELAY_DEVTOOLS_HOOK__;
20
+
21
+ if (devToolsHook) {
22
+ devToolsHook.registerEnvironment(environment);
23
+ }
24
+ }
25
+
26
+ module.exports = registerEnvironmentWithDevTools;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ *
8
+ * @format
9
+ */
10
+ // flowlint ambiguous-object-type:error
11
+ 'use strict';
12
+
13
+ var _window, _window$performance;
14
+
15
+ var isPerformanceNowAvailable = typeof window !== 'undefined' && typeof ((_window = window) === null || _window === void 0 ? void 0 : (_window$performance = _window.performance) === null || _window$performance === void 0 ? void 0 : _window$performance.now) === 'function';
16
+
17
+ function currentTimestamp() {
18
+ if (isPerformanceNowAvailable) {
19
+ return window.performance.now();
20
+ }
21
+
22
+ return Date.now();
23
+ }
24
+
25
+ function withDuration(cb) {
26
+ var startTime = currentTimestamp();
27
+ var result = cb();
28
+ return [currentTimestamp() - startTime, result];
29
+ }
30
+
31
+ module.exports = withDuration;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -16,12 +16,28 @@
16
16
  */
17
17
  export opaque type ActorIdentifier = string;
18
18
 
19
+ const invariant = require('invariant');
20
+
21
+ const INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE: ActorIdentifier =
22
+ 'INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE';
23
+
24
+ function assertInternalActorIndentifier(
25
+ actorIdentifier: ActorIdentifier,
26
+ ): void {
27
+ invariant(
28
+ actorIdentifier === INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
29
+ 'Expected to use only internal version of the `actorIdentifier`. "%s" was provided.',
30
+ actorIdentifier,
31
+ );
32
+ }
33
+
19
34
  module.exports = {
35
+ assertInternalActorIndentifier,
20
36
  getActorIdentifier(actorID: string): ActorIdentifier {
21
37
  return (actorID: ActorIdentifier);
22
38
  },
23
-
24
39
  getDefaultActorIdentifier(): ActorIdentifier {
25
40
  throw new Error('Not Implemented');
26
41
  },
42
+ INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
27
43
  };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and 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.
@@ -11,25 +11,25 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- const RelayOperationTracker = require('../store/RelayOperationTracker');
15
-
14
+ import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
16
15
  import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
17
16
  import type {INetwork} from '../network/RelayNetworkTypes';
18
17
  import type RelayObservable from '../network/RelayObservable';
19
18
  import type {
19
+ ExecuteMutationConfig,
20
+ LogFunction,
21
+ MutationParameters,
22
+ OperationAvailability,
23
+ OperationDescriptor,
24
+ OperationTracker,
20
25
  OptimisticResponseConfig,
21
26
  OptimisticUpdateFunction,
22
- OperationDescriptor,
23
- OperationAvailability,
24
- Snapshot,
27
+ RequiredFieldLogger,
25
28
  SelectorStoreUpdater,
26
29
  SingularReaderSelector,
27
- StoreUpdater,
28
- RequiredFieldLogger,
29
- ExecuteMutationConfig,
30
- LogFunction,
30
+ Snapshot,
31
31
  Store,
32
- OperationTracker,
32
+ StoreUpdater,
33
33
  } from '../store/RelayStoreTypes';
34
34
  import type {Disposable, RenderPolicy} from '../util/RelayRuntimeTypes';
35
35
  import type {ActorIdentifier} from './ActorIdentifier';
@@ -38,12 +38,17 @@ import type {
38
38
  IMultiActorEnvironment,
39
39
  } from './MultiActorEnvironmentTypes';
40
40
 
41
- function todo() {
42
- throw new Error('Not implementd');
43
- }
41
+ const wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
42
+ const defaultGetDataID = require('../store/defaultGetDataID');
43
+ const RelayOperationTracker = require('../store/RelayOperationTracker');
44
+ const RelayPublishQueue = require('../store/RelayPublishQueue');
45
+ const registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
44
46
 
45
47
  export type ActorSpecificEnvironmentConfig = $ReadOnly<{
46
48
  actorIdentifier: ActorIdentifier,
49
+ configName: ?string,
50
+ defaultRenderPolicy: RenderPolicy,
51
+ handlerProvider: HandlerProvider,
47
52
  logFn: LogFunction,
48
53
  multiActorEnvironment: IMultiActorEnvironment,
49
54
  network: INetwork,
@@ -52,18 +57,20 @@ export type ActorSpecificEnvironmentConfig = $ReadOnly<{
52
57
  }>;
53
58
 
54
59
  class ActorSpecificEnvironment implements IActorEnvironment {
55
- +options: mixed;
56
60
  __log: LogFunction;
57
- requiredFieldLogger: RequiredFieldLogger;
58
- +_store: Store;
61
+ +_defaultRenderPolicy: RenderPolicy;
59
62
  +_network: INetwork;
60
63
  +_operationTracker: OperationTracker;
61
-
62
- // Actor specific properties
64
+ +_publishQueue: RelayPublishQueue;
65
+ +_store: Store;
63
66
  +actorIdentifier: ActorIdentifier;
67
+ +configName: ?string;
64
68
  +multiActorEnvironment: IMultiActorEnvironment;
69
+ +options: mixed;
70
+ requiredFieldLogger: RequiredFieldLogger;
65
71
 
66
72
  constructor(config: ActorSpecificEnvironmentConfig) {
73
+ this.configName = config.configName;
67
74
  this.actorIdentifier = config.actorIdentifier;
68
75
  this.multiActorEnvironment = config.multiActorEnvironment;
69
76
 
@@ -71,51 +78,83 @@ class ActorSpecificEnvironment implements IActorEnvironment {
71
78
  this.requiredFieldLogger = config.requiredFieldLogger;
72
79
  this._operationTracker = new RelayOperationTracker();
73
80
  this._store = config.store;
74
- this._network = config.network;
81
+ this._network = wrapNetworkWithLogObserver(this, config.network);
82
+ this._publishQueue = new RelayPublishQueue(
83
+ config.store,
84
+ config.handlerProvider,
85
+ defaultGetDataID,
86
+ );
87
+ this._defaultRenderPolicy = config.defaultRenderPolicy;
88
+ // TODO:T92305692 Remove `options` in favor of directly using `actorIdentifier` on the environment
89
+ this.options = {
90
+ actorID: this.actorIdentifier,
91
+ };
92
+
93
+ // We need to add this here to pass `isRelayModernEnvironment` check
94
+ // $FlowFixMe[prop-missing]
95
+ this['@@RelayModernEnvironment'] = true;
96
+
97
+ if (__DEV__) {
98
+ const {inspect} = require('../store/StoreInspector');
99
+ (this: $FlowFixMe).DEBUG_inspect = (dataID: ?string) =>
100
+ inspect(this, dataID);
101
+ }
102
+
103
+ // Register this Relay Environment with Relay DevTools if it exists.
104
+ // Note: this must always be the last step in the constructor.
105
+ registerEnvironmentWithDevTools(this);
106
+ }
107
+
108
+ getPublishQueue(): RelayPublishQueue {
109
+ return this._publishQueue;
75
110
  }
76
111
 
77
112
  UNSTABLE_getDefaultRenderPolicy(): RenderPolicy {
78
- return todo();
113
+ return this._defaultRenderPolicy;
79
114
  }
80
115
 
81
- applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable {
82
- return this.multiActorEnvironment.applyMutation(
83
- this.actorIdentifier,
84
- optimisticConfig,
85
- );
116
+ applyMutation<TMutation: MutationParameters>(
117
+ optimisticConfig: OptimisticResponseConfig<TMutation>,
118
+ ): Disposable {
119
+ return this.multiActorEnvironment.applyMutation(this, optimisticConfig);
86
120
  }
87
121
 
88
122
  applyUpdate(optimisticUpdate: OptimisticUpdateFunction): Disposable {
89
- return this.multiActorEnvironment.applyUpdate(
90
- this.actorIdentifier,
123
+ return this.multiActorEnvironment.applyUpdate(this, optimisticUpdate);
124
+ }
125
+
126
+ revertUpdate(optimisticUpdate: OptimisticUpdateFunction): void {
127
+ return this.multiActorEnvironment.revertUpdate(this, optimisticUpdate);
128
+ }
129
+
130
+ replaceUpdate(
131
+ optimisticUpdate: OptimisticUpdateFunction,
132
+ replacementUpdate: OptimisticUpdateFunction,
133
+ ): void {
134
+ return this.multiActorEnvironment.replaceUpdate(
135
+ this,
91
136
  optimisticUpdate,
137
+ replacementUpdate,
92
138
  );
93
139
  }
94
140
 
95
141
  check(operation: OperationDescriptor): OperationAvailability {
96
- return this.multiActorEnvironment.check(this.actorIdentifier, operation);
142
+ return this.multiActorEnvironment.check(this, operation);
97
143
  }
98
144
 
99
145
  subscribe(
100
146
  snapshot: Snapshot,
101
147
  callback: (snapshot: Snapshot) => void,
102
148
  ): Disposable {
103
- return this.multiActorEnvironment.subscribe(
104
- this.actorIdentifier,
105
- snapshot,
106
- callback,
107
- );
149
+ return this.multiActorEnvironment.subscribe(this, snapshot, callback);
108
150
  }
109
151
 
110
152
  retain(operation: OperationDescriptor): Disposable {
111
- return this.multiActorEnvironment.retain(this.actorIdentifier, operation);
153
+ return this.multiActorEnvironment.retain(this, operation);
112
154
  }
113
155
 
114
156
  commitUpdate(updater: StoreUpdater): void {
115
- return this.multiActorEnvironment.commitUpdate(
116
- this.actorIdentifier,
117
- updater,
118
- );
157
+ return this.multiActorEnvironment.commitUpdate(this, updater);
119
158
  }
120
159
 
121
160
  /**
@@ -126,7 +165,7 @@ class ActorSpecificEnvironment implements IActorEnvironment {
126
165
  payload: PayloadData,
127
166
  ): void {
128
167
  return this.multiActorEnvironment.commitPayload(
129
- this.actorIdentifier,
168
+ this,
130
169
  operationDescriptor,
131
170
  payload,
132
171
  );
@@ -145,44 +184,41 @@ class ActorSpecificEnvironment implements IActorEnvironment {
145
184
  }
146
185
 
147
186
  lookup(selector: SingularReaderSelector): Snapshot {
148
- return this.multiActorEnvironment.lookup(this.actorIdentifier, selector);
187
+ return this.multiActorEnvironment.lookup(this, selector);
149
188
  }
150
189
 
151
190
  execute(config: {
152
191
  operation: OperationDescriptor,
153
- updater?: ?SelectorStoreUpdater,
154
192
  }): RelayObservable<GraphQLResponse> {
155
- return this.multiActorEnvironment.execute(this.actorIdentifier, config);
193
+ return this.multiActorEnvironment.execute(this, config);
194
+ }
195
+
196
+ executeSubscription<TMutation: MutationParameters>(config: {
197
+ operation: OperationDescriptor,
198
+ updater?: ?SelectorStoreUpdater<TMutation['response']>,
199
+ }): RelayObservable<GraphQLResponse> {
200
+ return this.multiActorEnvironment.executeSubscription(this, config);
156
201
  }
157
202
 
158
- executeMutation(
159
- options: ExecuteMutationConfig,
203
+ executeMutation<TMutation: MutationParameters>(
204
+ options: ExecuteMutationConfig<TMutation>,
160
205
  ): RelayObservable<GraphQLResponse> {
161
- return this.multiActorEnvironment.executeMutation(
162
- this.actorIdentifier,
163
- options,
164
- );
206
+ return this.multiActorEnvironment.executeMutation(this, options);
165
207
  }
166
208
 
167
209
  executeWithSource(options: {
168
210
  operation: OperationDescriptor,
169
211
  source: RelayObservable<GraphQLResponse>,
170
212
  }): RelayObservable<GraphQLResponse> {
171
- return this.multiActorEnvironment.executeWithSource(
172
- this.actorIdentifier,
173
- options,
174
- );
213
+ return this.multiActorEnvironment.executeWithSource(this, options);
175
214
  }
176
215
 
177
216
  isRequestActive(requestIdentifier: string): boolean {
178
- return this.multiActorEnvironment.isRequestActive(
179
- this.actorIdentifier,
180
- requestIdentifier,
181
- );
217
+ return this.multiActorEnvironment.isRequestActive(this, requestIdentifier);
182
218
  }
183
219
 
184
220
  isServer(): boolean {
185
- return todo();
221
+ return this.multiActorEnvironment.isServer();
186
222
  }
187
223
  }
188
224
 
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ * @emails oncall+relay
8
+ * @flow strict-local
9
+ * @format
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const ACTOR_IDENTIFIER_FIELD_NAME = 'actor_key';
15
+
16
+ import type {ActorIdentifier} from './ActorIdentifier';
17
+
18
+ const {getActorIdentifier} = require('./ActorIdentifier');
19
+
20
+ function getActorIdentifierFromPayload(payload: mixed): ?ActorIdentifier {
21
+ if (
22
+ payload != null &&
23
+ typeof payload === 'object' &&
24
+ typeof payload[ACTOR_IDENTIFIER_FIELD_NAME] === 'string'
25
+ ) {
26
+ return getActorIdentifier(payload[ACTOR_IDENTIFIER_FIELD_NAME]);
27
+ }
28
+ }
29
+
30
+ module.exports = {
31
+ ACTOR_IDENTIFIER_FIELD_NAME,
32
+ getActorIdentifierFromPayload,
33
+ };