relay-runtime 9.0.0 → 9.1.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 (111) hide show
  1. package/handlers/RelayDefaultHandlerProvider.js.flow +34 -0
  2. package/handlers/connection/ConnectionHandler.js.flow +549 -0
  3. package/handlers/connection/ConnectionInterface.js.flow +92 -0
  4. package/index.js +1 -1
  5. package/index.js.flow +314 -0
  6. package/lib/handlers/connection/ConnectionHandler.js +1 -3
  7. package/lib/index.js +1 -2
  8. package/lib/mutations/RelayDeclarativeMutationConfig.js +22 -45
  9. package/lib/mutations/RelayRecordProxy.js +1 -3
  10. package/lib/mutations/RelayRecordSourceMutator.js +1 -3
  11. package/lib/mutations/RelayRecordSourceProxy.js +1 -3
  12. package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -3
  13. package/lib/mutations/commitMutation.js +2 -0
  14. package/lib/mutations/validateMutation.js +13 -4
  15. package/lib/network/RelayObservable.js +9 -9
  16. package/lib/network/RelayQueryResponseCache.js +8 -6
  17. package/lib/query/fetchQueryInternal.js +1 -8
  18. package/lib/store/DataChecker.js +23 -51
  19. package/lib/store/RelayConcreteVariables.js +6 -2
  20. package/lib/store/RelayModernEnvironment.js +30 -12
  21. package/lib/store/RelayModernFragmentSpecResolver.js +9 -13
  22. package/lib/store/RelayModernQueryExecutor.js +73 -37
  23. package/lib/store/RelayModernRecord.js +14 -9
  24. package/lib/store/RelayModernStore.js +107 -70
  25. package/lib/store/RelayOperationTracker.js +35 -78
  26. package/lib/store/RelayOptimisticRecordSource.js +7 -5
  27. package/lib/store/RelayPublishQueue.js +1 -3
  28. package/lib/store/RelayReader.js +1 -3
  29. package/lib/store/RelayRecordSource.js +1 -3
  30. package/lib/store/RelayRecordSourceMapImpl.js +13 -18
  31. package/lib/store/RelayReferenceMarker.js +2 -6
  32. package/lib/store/RelayResponseNormalizer.js +9 -10
  33. package/lib/store/StoreInspector.js +7 -5
  34. package/lib/store/normalizeRelayPayload.js +6 -2
  35. package/lib/subscription/requestSubscription.js +4 -2
  36. package/lib/util/RelayFeatureFlags.js +1 -1
  37. package/lib/util/RelayReplaySubject.js +1 -3
  38. package/lib/util/createPayloadFor3DField.js +7 -2
  39. package/mutations/RelayDeclarativeMutationConfig.js.flow +380 -0
  40. package/mutations/RelayRecordProxy.js.flow +165 -0
  41. package/mutations/RelayRecordSourceMutator.js.flow +238 -0
  42. package/mutations/RelayRecordSourceProxy.js.flow +164 -0
  43. package/mutations/RelayRecordSourceSelectorProxy.js.flow +119 -0
  44. package/mutations/applyOptimisticMutation.js.flow +76 -0
  45. package/mutations/commitLocalUpdate.js.flow +24 -0
  46. package/mutations/commitMutation.js.flow +184 -0
  47. package/mutations/validateMutation.js.flow +211 -0
  48. package/network/ConvertToExecuteFunction.js.flow +49 -0
  49. package/network/RelayNetwork.js.flow +84 -0
  50. package/network/RelayNetworkTypes.js.flow +123 -0
  51. package/network/RelayObservable.js.flow +634 -0
  52. package/network/RelayQueryResponseCache.js.flow +111 -0
  53. package/package.json +1 -1
  54. package/query/GraphQLTag.js.flow +166 -0
  55. package/query/fetchQuery.js.flow +47 -0
  56. package/query/fetchQueryInternal.js.flow +349 -0
  57. package/relay-runtime.js +2 -2
  58. package/relay-runtime.min.js +2 -2
  59. package/store/ClientID.js.flow +43 -0
  60. package/store/DataChecker.js.flow +426 -0
  61. package/store/RelayConcreteVariables.js.flow +96 -0
  62. package/store/RelayModernEnvironment.js.flow +526 -0
  63. package/store/RelayModernFragmentSpecResolver.js.flow +426 -0
  64. package/store/RelayModernOperationDescriptor.js.flow +88 -0
  65. package/store/RelayModernQueryExecutor.js.flow +1327 -0
  66. package/store/RelayModernRecord.js.flow +403 -0
  67. package/store/RelayModernSelector.js.flow +444 -0
  68. package/store/RelayModernStore.js.flow +757 -0
  69. package/store/RelayOperationTracker.js.flow +164 -0
  70. package/store/RelayOptimisticRecordSource.js.flow +119 -0
  71. package/store/RelayPublishQueue.js.flow +401 -0
  72. package/store/RelayReader.js.flow +376 -0
  73. package/store/RelayRecordSource.js.flow +29 -0
  74. package/store/RelayRecordSourceMapImpl.js.flow +87 -0
  75. package/store/RelayRecordState.js.flow +37 -0
  76. package/store/RelayReferenceMarker.js.flow +236 -0
  77. package/store/RelayResponseNormalizer.js.flow +556 -0
  78. package/store/RelayStoreTypes.js.flow +873 -0
  79. package/store/RelayStoreUtils.js.flow +218 -0
  80. package/store/StoreInspector.js.flow +173 -0
  81. package/store/ViewerPattern.js.flow +26 -0
  82. package/store/cloneRelayHandleSourceField.js.flow +66 -0
  83. package/store/createFragmentSpecResolver.js.flow +55 -0
  84. package/store/createRelayContext.js.flow +44 -0
  85. package/store/defaultGetDataID.js.flow +27 -0
  86. package/store/hasOverlappingIDs.js.flow +34 -0
  87. package/store/isRelayModernEnvironment.js.flow +27 -0
  88. package/store/normalizeRelayPayload.js.flow +51 -0
  89. package/store/readInlineData.js.flow +75 -0
  90. package/subscription/requestSubscription.js.flow +100 -0
  91. package/util/JSResourceTypes.flow.js.flow +20 -0
  92. package/util/NormalizationNode.js.flow +191 -0
  93. package/util/ReaderNode.js.flow +208 -0
  94. package/util/RelayConcreteNode.js.flow +80 -0
  95. package/util/RelayDefaultHandleKey.js.flow +17 -0
  96. package/util/RelayError.js.flow +33 -0
  97. package/util/RelayFeatureFlags.js.flow +30 -0
  98. package/util/RelayProfiler.js.flow +284 -0
  99. package/util/RelayReplaySubject.js.flow +134 -0
  100. package/util/RelayRuntimeTypes.js.flow +70 -0
  101. package/util/createPayloadFor3DField.js.flow +43 -0
  102. package/util/deepFreeze.js.flow +36 -0
  103. package/util/generateID.js.flow +21 -0
  104. package/util/getFragmentIdentifier.js.flow +52 -0
  105. package/util/getRelayHandleKey.js.flow +41 -0
  106. package/util/getRequestIdentifier.js.flow +41 -0
  107. package/util/isPromise.js.flow +21 -0
  108. package/util/isScalarAndEqual.js.flow +26 -0
  109. package/util/recycleNodesInto.js.flow +80 -0
  110. package/util/resolveImmediate.js.flow +30 -0
  111. package/util/stableCopy.js.flow +35 -0
@@ -0,0 +1,36 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * Recursively "deep" freezes the supplied object.
17
+ *
18
+ * For convenience, and for consistency with the behavior of `Object.freeze`,
19
+ * returns the now-frozen original object.
20
+ */
21
+ function deepFreeze<T: {...}>(object: T): T {
22
+ Object.freeze(object);
23
+ Object.getOwnPropertyNames(object).forEach(name => {
24
+ const property = object[name];
25
+ if (
26
+ property &&
27
+ typeof property === 'object' &&
28
+ !Object.isFrozen(property)
29
+ ) {
30
+ deepFreeze(property);
31
+ }
32
+ });
33
+ return object;
34
+ }
35
+
36
+ module.exports = deepFreeze;
@@ -0,0 +1,21 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ let id = 100000;
16
+
17
+ function generateID(): number {
18
+ return id++;
19
+ }
20
+
21
+ module.exports = generateID;
@@ -0,0 +1,52 @@
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
+ * @flow strict-local
8
+ * @format
9
+ * @emails oncall+relay
10
+ */
11
+
12
+ // flowlint ambiguous-object-type:error
13
+
14
+ 'use strict';
15
+
16
+ const stableCopy = require('./stableCopy');
17
+
18
+ const {
19
+ getDataIDsFromFragment,
20
+ getVariablesFromFragment,
21
+ getSelector,
22
+ } = require('../store/RelayModernSelector');
23
+
24
+ import type {ReaderFragment} from './ReaderNode';
25
+
26
+ function getFragmentIdentifier(
27
+ fragmentNode: ReaderFragment,
28
+ fragmentRef: mixed,
29
+ ): string {
30
+ const selector = getSelector(fragmentNode, fragmentRef);
31
+ const fragmentOwnerIdentifier =
32
+ selector == null
33
+ ? 'null'
34
+ : selector.kind === 'SingularReaderSelector'
35
+ ? selector.owner.identifier
36
+ : '[' +
37
+ selector.selectors.map(sel => sel.owner.identifier).join(',') +
38
+ ']';
39
+ const fragmentVariables = getVariablesFromFragment(fragmentNode, fragmentRef);
40
+ const dataIDs = getDataIDsFromFragment(fragmentNode, fragmentRef);
41
+ return (
42
+ fragmentOwnerIdentifier +
43
+ '/' +
44
+ fragmentNode.name +
45
+ '/' +
46
+ JSON.stringify(stableCopy(fragmentVariables)) +
47
+ '/' +
48
+ (JSON.stringify(dataIDs) ?? 'missing')
49
+ );
50
+ }
51
+
52
+ module.exports = getFragmentIdentifier;
@@ -0,0 +1,41 @@
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
+ * @flow
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ const invariant = require('invariant');
16
+
17
+ const {DEFAULT_HANDLE_KEY} = require('./RelayDefaultHandleKey');
18
+
19
+ /**
20
+ * @internal
21
+ *
22
+ * Helper to create a unique name for a handle field based on the handle name, handle key and
23
+ * source field.
24
+ */
25
+ function getRelayHandleKey(
26
+ handleName: string,
27
+ key: ?string,
28
+ fieldName: ?string,
29
+ ): string {
30
+ if (key && key !== DEFAULT_HANDLE_KEY) {
31
+ return `__${key}_${handleName}`;
32
+ }
33
+
34
+ invariant(
35
+ fieldName != null,
36
+ 'getRelayHandleKey: Expected either `fieldName` or `key` in `handle` to be provided',
37
+ );
38
+ return `__${fieldName}_${handleName}`;
39
+ }
40
+
41
+ module.exports = getRelayHandleKey;
@@ -0,0 +1,41 @@
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
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ const invariant = require('invariant');
16
+ const stableCopy = require('./stableCopy');
17
+
18
+ import type {RequestParameters} from './RelayConcreteNode';
19
+ import type {Variables} from './RelayRuntimeTypes';
20
+
21
+ export opaque type RequestIdentifier: string = string;
22
+
23
+ /**
24
+ * Returns a stable identifier for the given pair of `RequestParameters` +
25
+ * variables.
26
+ */
27
+ function getRequestIdentifier(
28
+ parameters: RequestParameters,
29
+ variables: Variables,
30
+ ): RequestIdentifier {
31
+ const requestID = parameters.id != null ? parameters.id : parameters.text;
32
+ invariant(
33
+ requestID != null,
34
+ 'getRequestIdentifier: Expected request `%s` to have either a ' +
35
+ 'valid `id` or `text` property',
36
+ parameters.name,
37
+ );
38
+ return requestID + JSON.stringify(stableCopy(variables));
39
+ }
40
+
41
+ module.exports = getRequestIdentifier;
@@ -0,0 +1,21 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ declare function isPromise(p: mixed): boolean %checks(p instanceof Promise);
16
+
17
+ function isPromise(p: $FlowFixMe): boolean {
18
+ return !!p && typeof p.then === 'function';
19
+ }
20
+
21
+ module.exports = isPromise;
@@ -0,0 +1,26 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * A fast test to determine if two values are equal scalars:
17
+ * - compares scalars such as booleans, strings, numbers by value
18
+ * - compares functions by identity
19
+ * - returns false for complex values, since these cannot be cheaply tested for
20
+ * equality (use `areEquals` instead)
21
+ */
22
+ function isScalarAndEqual(valueA: mixed, valueB: mixed): boolean {
23
+ return valueA === valueB && (valueA === null || typeof valueA !== 'object');
24
+ }
25
+
26
+ module.exports = isScalarAndEqual;
@@ -0,0 +1,80 @@
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
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * Recycles subtrees from `prevData` by replacing equal subtrees in `nextData`.
17
+ */
18
+ function recycleNodesInto<T>(prevData: T, nextData: T): T {
19
+ if (
20
+ prevData === nextData ||
21
+ typeof prevData !== 'object' ||
22
+ !prevData ||
23
+ typeof nextData !== 'object' ||
24
+ !nextData
25
+ ) {
26
+ return nextData;
27
+ }
28
+ let canRecycle = false;
29
+
30
+ // Assign local variables to preserve Flow type refinement.
31
+ const prevArray = Array.isArray(prevData) ? prevData : null;
32
+ const nextArray = Array.isArray(nextData) ? nextData : null;
33
+ if (prevArray && nextArray) {
34
+ canRecycle =
35
+ nextArray.reduce((wasEqual, nextItem, ii) => {
36
+ const prevValue = prevArray[ii];
37
+ const nextValue = recycleNodesInto(prevValue, nextItem);
38
+ if (nextValue !== nextArray[ii]) {
39
+ if (__DEV__) {
40
+ if (!Object.isFrozen(nextArray)) {
41
+ nextArray[ii] = nextValue;
42
+ }
43
+ } else {
44
+ nextArray[ii] = nextValue;
45
+ }
46
+ }
47
+ return wasEqual && nextValue === prevArray[ii];
48
+ }, true) && prevArray.length === nextArray.length;
49
+ } else if (!prevArray && !nextArray) {
50
+ // Assign local variables to preserve Flow type refinement.
51
+ const prevObject = prevData;
52
+ const nextObject = nextData;
53
+ const prevKeys = Object.keys(prevObject);
54
+ const nextKeys = Object.keys(nextObject);
55
+ canRecycle =
56
+ nextKeys.reduce((wasEqual, key) => {
57
+ const prevValue = prevObject[key];
58
+ const nextValue = recycleNodesInto(prevValue, nextObject[key]);
59
+ if (nextValue !== nextObject[key]) {
60
+ if (__DEV__) {
61
+ if (!Object.isFrozen(nextObject)) {
62
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This
63
+ * comment suppresses an error found when Flow v0.98 was deployed.
64
+ * To see the error delete this comment and run Flow. */
65
+ nextObject[key] = nextValue;
66
+ }
67
+ } else {
68
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
69
+ * suppresses an error found when Flow v0.98 was deployed. To see
70
+ * the error delete this comment and run Flow. */
71
+ nextObject[key] = nextValue;
72
+ }
73
+ }
74
+ return wasEqual && nextValue === prevObject[key];
75
+ }, true) && prevKeys.length === nextKeys.length;
76
+ }
77
+ return canRecycle ? prevData : nextData;
78
+ }
79
+
80
+ module.exports = recycleNodesInto;
@@ -0,0 +1,30 @@
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
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ var resolvedPromise = Promise.resolve();
16
+
17
+ /**
18
+ * An alternative to setImmediate based on Promise.
19
+ */
20
+ function resolveImmediate(callback: () => void) {
21
+ resolvedPromise.then(callback).catch(throwNext);
22
+ }
23
+
24
+ function throwNext(error) {
25
+ setTimeout(() => {
26
+ throw error;
27
+ }, 0);
28
+ }
29
+
30
+ module.exports = resolveImmediate;
@@ -0,0 +1,35 @@
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
+ * @flow
8
+ * @format
9
+ */
10
+
11
+ // flowlint ambiguous-object-type:error
12
+
13
+ 'use strict';
14
+
15
+ /**
16
+ * Creates a copy of the provided value, ensuring any nested objects have their
17
+ * keys sorted such that equivalent values would have identical JSON.stringify
18
+ * results.
19
+ */
20
+ function stableCopy<T: mixed>(value: T): T {
21
+ if (!value || typeof value !== 'object') {
22
+ return value;
23
+ }
24
+ if (Array.isArray(value)) {
25
+ return value.map(stableCopy);
26
+ }
27
+ const keys = Object.keys(value).sort();
28
+ const stable = {};
29
+ for (let i = 0; i < keys.length; i++) {
30
+ stable[keys[i]] = stableCopy(value[keys[i]]);
31
+ }
32
+ return (stable: any);
33
+ }
34
+
35
+ module.exports = stableCopy;