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,376 @@
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 RelayModernRecord = require('./RelayModernRecord');
16
+
17
+ const invariant = require('invariant');
18
+
19
+ const {
20
+ CLIENT_EXTENSION,
21
+ CONDITION,
22
+ DEFER,
23
+ FRAGMENT_SPREAD,
24
+ INLINE_DATA_FRAGMENT_SPREAD,
25
+ INLINE_FRAGMENT,
26
+ LINKED_FIELD,
27
+ MODULE_IMPORT,
28
+ SCALAR_FIELD,
29
+ STREAM,
30
+ } = require('../util/RelayConcreteNode');
31
+ const {
32
+ FRAGMENTS_KEY,
33
+ FRAGMENT_OWNER_KEY,
34
+ FRAGMENT_PROP_NAME_KEY,
35
+ ID_KEY,
36
+ MODULE_COMPONENT_KEY,
37
+ getArgumentValues,
38
+ getStorageKey,
39
+ getModuleComponentKey,
40
+ } = require('./RelayStoreUtils');
41
+
42
+ import type {
43
+ ReaderFragmentSpread,
44
+ ReaderInlineDataFragmentSpread,
45
+ ReaderLinkedField,
46
+ ReaderModuleImport,
47
+ ReaderNode,
48
+ ReaderScalarField,
49
+ ReaderSelection,
50
+ } from '../util/ReaderNode';
51
+ import type {DataID, Variables} from '../util/RelayRuntimeTypes';
52
+ import type {
53
+ Record,
54
+ RecordSource,
55
+ RequestDescriptor,
56
+ SelectorData,
57
+ SingularReaderSelector,
58
+ Snapshot,
59
+ } from './RelayStoreTypes';
60
+
61
+ function read(
62
+ recordSource: RecordSource,
63
+ selector: SingularReaderSelector,
64
+ ): Snapshot {
65
+ const reader = new RelayReader(recordSource, selector);
66
+ return reader.read();
67
+ }
68
+
69
+ /**
70
+ * @private
71
+ */
72
+ class RelayReader {
73
+ _isMissingData: boolean;
74
+ _owner: RequestDescriptor;
75
+ _recordSource: RecordSource;
76
+ _seenRecords: {[dataID: DataID]: ?Record, ...};
77
+ _selector: SingularReaderSelector;
78
+ _variables: Variables;
79
+
80
+ constructor(recordSource: RecordSource, selector: SingularReaderSelector) {
81
+ this._isMissingData = false;
82
+ this._owner = selector.owner;
83
+ this._recordSource = recordSource;
84
+ this._seenRecords = {};
85
+ this._selector = selector;
86
+ this._variables = selector.variables;
87
+ }
88
+
89
+ read(): Snapshot {
90
+ const {node, dataID} = this._selector;
91
+ const data = this._traverse(node, dataID, null);
92
+ return {
93
+ data,
94
+ isMissingData: this._isMissingData,
95
+ seenRecords: this._seenRecords,
96
+ selector: this._selector,
97
+ };
98
+ }
99
+
100
+ _traverse(
101
+ node: ReaderNode,
102
+ dataID: DataID,
103
+ prevData: ?SelectorData,
104
+ ): ?SelectorData {
105
+ const record = this._recordSource.get(dataID);
106
+ this._seenRecords[dataID] = record;
107
+ if (record == null) {
108
+ if (record === undefined) {
109
+ this._isMissingData = true;
110
+ }
111
+ return record;
112
+ }
113
+ const data = prevData || {};
114
+ this._traverseSelections(node.selections, record, data);
115
+ return data;
116
+ }
117
+
118
+ _getVariableValue(name: string): mixed {
119
+ invariant(
120
+ this._variables.hasOwnProperty(name),
121
+ 'RelayReader(): Undefined variable `%s`.',
122
+ name,
123
+ );
124
+ return this._variables[name];
125
+ }
126
+
127
+ _traverseSelections(
128
+ selections: $ReadOnlyArray<ReaderSelection>,
129
+ record: Record,
130
+ data: SelectorData,
131
+ ): void {
132
+ for (let i = 0; i < selections.length; i++) {
133
+ const selection = selections[i];
134
+ switch (selection.kind) {
135
+ case SCALAR_FIELD:
136
+ this._readScalar(selection, record, data);
137
+ break;
138
+ case LINKED_FIELD:
139
+ if (selection.plural) {
140
+ this._readPluralLink(selection, record, data);
141
+ } else {
142
+ this._readLink(selection, record, data);
143
+ }
144
+ break;
145
+ case CONDITION:
146
+ const conditionValue = this._getVariableValue(selection.condition);
147
+ if (conditionValue === selection.passingValue) {
148
+ this._traverseSelections(selection.selections, record, data);
149
+ }
150
+ break;
151
+ case INLINE_FRAGMENT:
152
+ const typeName = RelayModernRecord.getType(record);
153
+ if (typeName != null && typeName === selection.type) {
154
+ this._traverseSelections(selection.selections, record, data);
155
+ }
156
+ break;
157
+ case FRAGMENT_SPREAD:
158
+ this._createFragmentPointer(selection, record, data);
159
+ break;
160
+ case MODULE_IMPORT:
161
+ this._readModuleImport(selection, record, data);
162
+ break;
163
+ case INLINE_DATA_FRAGMENT_SPREAD:
164
+ this._createInlineDataFragmentPointer(selection, record, data);
165
+ break;
166
+ case DEFER:
167
+ case CLIENT_EXTENSION:
168
+ const isMissingData = this._isMissingData;
169
+ this._traverseSelections(selection.selections, record, data);
170
+ this._isMissingData = isMissingData;
171
+ break;
172
+ case STREAM:
173
+ this._traverseSelections(selection.selections, record, data);
174
+ break;
175
+ default:
176
+ (selection: empty);
177
+ invariant(
178
+ false,
179
+ 'RelayReader(): Unexpected ast kind `%s`.',
180
+ selection.kind,
181
+ );
182
+ }
183
+ }
184
+ }
185
+
186
+ _readScalar(
187
+ field: ReaderScalarField,
188
+ record: Record,
189
+ data: SelectorData,
190
+ ): void {
191
+ const applicationName = field.alias ?? field.name;
192
+ const storageKey = getStorageKey(field, this._variables);
193
+ const value = RelayModernRecord.getValue(record, storageKey);
194
+ if (value === undefined) {
195
+ this._isMissingData = true;
196
+ }
197
+ data[applicationName] = value;
198
+ }
199
+
200
+ _readLink(
201
+ field: ReaderLinkedField,
202
+ record: Record,
203
+ data: SelectorData,
204
+ ): void {
205
+ const applicationName = field.alias ?? field.name;
206
+ const storageKey = getStorageKey(field, this._variables);
207
+ const linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
208
+ if (linkedID == null) {
209
+ data[applicationName] = linkedID;
210
+ if (linkedID === undefined) {
211
+ this._isMissingData = true;
212
+ }
213
+ return;
214
+ }
215
+
216
+ const prevData = data[applicationName];
217
+ invariant(
218
+ prevData == null || typeof prevData === 'object',
219
+ 'RelayReader(): Expected data for field `%s` on record `%s` ' +
220
+ 'to be an object, got `%s`.',
221
+ applicationName,
222
+ RelayModernRecord.getDataID(record),
223
+ prevData,
224
+ );
225
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
226
+ * suppresses an error found when Flow v0.98 was deployed. To see the error
227
+ * delete this comment and run Flow. */
228
+ data[applicationName] = this._traverse(field, linkedID, prevData);
229
+ }
230
+
231
+ _readPluralLink(
232
+ field: ReaderLinkedField,
233
+ record: Record,
234
+ data: SelectorData,
235
+ ): void {
236
+ const applicationName = field.alias ?? field.name;
237
+ const storageKey = getStorageKey(field, this._variables);
238
+ const linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
239
+
240
+ if (linkedIDs == null) {
241
+ data[applicationName] = linkedIDs;
242
+ if (linkedIDs === undefined) {
243
+ this._isMissingData = true;
244
+ }
245
+ return;
246
+ }
247
+
248
+ const prevData = data[applicationName];
249
+ invariant(
250
+ prevData == null || Array.isArray(prevData),
251
+ 'RelayReader(): Expected data for field `%s` on record `%s` ' +
252
+ 'to be an array, got `%s`.',
253
+ applicationName,
254
+ RelayModernRecord.getDataID(record),
255
+ prevData,
256
+ );
257
+ const linkedArray = prevData || [];
258
+ linkedIDs.forEach((linkedID, nextIndex) => {
259
+ if (linkedID == null) {
260
+ if (linkedID === undefined) {
261
+ this._isMissingData = true;
262
+ }
263
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
264
+ * suppresses an error found when Flow v0.98 was deployed. To see the
265
+ * error delete this comment and run Flow. */
266
+ linkedArray[nextIndex] = linkedID;
267
+ return;
268
+ }
269
+ const prevItem = linkedArray[nextIndex];
270
+ invariant(
271
+ prevItem == null || typeof prevItem === 'object',
272
+ 'RelayReader(): Expected data for field `%s` on record `%s` ' +
273
+ 'to be an object, got `%s`.',
274
+ applicationName,
275
+ RelayModernRecord.getDataID(record),
276
+ prevItem,
277
+ );
278
+ /* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
279
+ * suppresses an error found when Flow v0.98 was deployed. To see the
280
+ * error delete this comment and run Flow. */
281
+ linkedArray[nextIndex] = this._traverse(field, linkedID, prevItem);
282
+ });
283
+ data[applicationName] = linkedArray;
284
+ }
285
+
286
+ /**
287
+ * Reads a ReaderModuleImport, which was generated from using the @module
288
+ * directive.
289
+ */
290
+ _readModuleImport(
291
+ moduleImport: ReaderModuleImport,
292
+ record: Record,
293
+ data: SelectorData,
294
+ ): void {
295
+ // Determine the component module from the store: if the field is missing
296
+ // it means we don't know what component to render the match with.
297
+ const componentKey = getModuleComponentKey(moduleImport.documentName);
298
+ const component = RelayModernRecord.getValue(record, componentKey);
299
+ if (component == null) {
300
+ if (component === undefined) {
301
+ this._isMissingData = true;
302
+ }
303
+ return;
304
+ }
305
+
306
+ // Otherwise, read the fragment and module associated to the concrete
307
+ // type, and put that data with the result:
308
+ // - For the matched fragment, create the relevant fragment pointer and add
309
+ // the expected fragmentPropName
310
+ // - For the matched module, create a reference to the module
311
+ this._createFragmentPointer(
312
+ {
313
+ kind: 'FragmentSpread',
314
+ name: moduleImport.fragmentName,
315
+ args: null,
316
+ },
317
+ record,
318
+ data,
319
+ );
320
+ data[FRAGMENT_PROP_NAME_KEY] = moduleImport.fragmentPropName;
321
+ data[MODULE_COMPONENT_KEY] = component;
322
+ }
323
+
324
+ _createFragmentPointer(
325
+ fragmentSpread: ReaderFragmentSpread,
326
+ record: Record,
327
+ data: SelectorData,
328
+ ): void {
329
+ let fragmentPointers = data[FRAGMENTS_KEY];
330
+ if (fragmentPointers == null) {
331
+ fragmentPointers = data[FRAGMENTS_KEY] = {};
332
+ }
333
+ invariant(
334
+ typeof fragmentPointers === 'object' && fragmentPointers != null,
335
+ 'RelayReader: Expected fragment spread data to be an object, got `%s`.',
336
+ fragmentPointers,
337
+ );
338
+ if (data[ID_KEY] == null) {
339
+ data[ID_KEY] = RelayModernRecord.getDataID(record);
340
+ }
341
+ // $FlowFixMe - writing into read-only field
342
+ fragmentPointers[fragmentSpread.name] = fragmentSpread.args
343
+ ? getArgumentValues(fragmentSpread.args, this._variables)
344
+ : {};
345
+ data[FRAGMENT_OWNER_KEY] = this._owner;
346
+ }
347
+
348
+ _createInlineDataFragmentPointer(
349
+ inlineDataFragmentSpread: ReaderInlineDataFragmentSpread,
350
+ record: Record,
351
+ data: SelectorData,
352
+ ): void {
353
+ let fragmentPointers = data[FRAGMENTS_KEY];
354
+ if (fragmentPointers == null) {
355
+ fragmentPointers = data[FRAGMENTS_KEY] = {};
356
+ }
357
+ invariant(
358
+ typeof fragmentPointers === 'object' && fragmentPointers != null,
359
+ 'RelayReader: Expected fragment spread data to be an object, got `%s`.',
360
+ fragmentPointers,
361
+ );
362
+ if (data[ID_KEY] == null) {
363
+ data[ID_KEY] = RelayModernRecord.getDataID(record);
364
+ }
365
+ const inlineData = {};
366
+ this._traverseSelections(
367
+ inlineDataFragmentSpread.selections,
368
+ record,
369
+ inlineData,
370
+ );
371
+ // $FlowFixMe - writing into read-only field
372
+ fragmentPointers[inlineDataFragmentSpread.name] = inlineData;
373
+ }
374
+ }
375
+
376
+ module.exports = {read};
@@ -0,0 +1,29 @@
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 RelayRecordSourceMapImpl = require('./RelayRecordSourceMapImpl');
16
+
17
+ import type {MutableRecordSource, RecordMap} from './RelayStoreTypes';
18
+
19
+ class RelayRecordSource {
20
+ constructor(records?: RecordMap): MutableRecordSource {
21
+ return RelayRecordSource.create(records);
22
+ }
23
+
24
+ static create(records?: RecordMap): MutableRecordSource {
25
+ return new RelayRecordSourceMapImpl(records);
26
+ }
27
+ }
28
+
29
+ module.exports = RelayRecordSource;
@@ -0,0 +1,87 @@
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 RelayRecordState = require('./RelayRecordState');
16
+
17
+ import type {DataID} from '../util/RelayRuntimeTypes';
18
+ import type {RecordState} from './RelayRecordState';
19
+ import type {MutableRecordSource, Record, RecordMap} from './RelayStoreTypes';
20
+
21
+ const {EXISTENT, NONEXISTENT, UNKNOWN} = RelayRecordState;
22
+
23
+ /**
24
+ * An implementation of the `MutableRecordSource` interface (defined in
25
+ * `RelayStoreTypes`) that holds all records in memory (JS Map).
26
+ */
27
+ class RelayMapRecordSourceMapImpl implements MutableRecordSource {
28
+ _records: Map<DataID, ?Record>;
29
+
30
+ constructor(records?: RecordMap) {
31
+ this._records = new Map();
32
+ if (records != null) {
33
+ Object.keys(records).forEach(key => {
34
+ this._records.set(key, records[key]);
35
+ });
36
+ }
37
+ }
38
+
39
+ clear(): void {
40
+ this._records = new Map();
41
+ }
42
+
43
+ delete(dataID: DataID): void {
44
+ this._records.set(dataID, null);
45
+ }
46
+
47
+ get(dataID: DataID): ?Record {
48
+ return this._records.get(dataID);
49
+ }
50
+
51
+ getRecordIDs(): Array<DataID> {
52
+ return Array.from(this._records.keys());
53
+ }
54
+
55
+ getStatus(dataID: DataID): RecordState {
56
+ if (!this._records.has(dataID)) {
57
+ return UNKNOWN;
58
+ }
59
+ return this._records.get(dataID) == null ? NONEXISTENT : EXISTENT;
60
+ }
61
+
62
+ has(dataID: DataID): boolean {
63
+ return this._records.has(dataID);
64
+ }
65
+
66
+ remove(dataID: DataID): void {
67
+ this._records.delete(dataID);
68
+ }
69
+
70
+ set(dataID: DataID, record: Record): void {
71
+ this._records.set(dataID, record);
72
+ }
73
+
74
+ size(): number {
75
+ return this._records.size;
76
+ }
77
+
78
+ toJSON(): {[DataID]: ?Record, ...} {
79
+ const obj = {};
80
+ for (const [key, value] of this._records) {
81
+ obj[key] = value;
82
+ }
83
+ return obj;
84
+ }
85
+ }
86
+
87
+ module.exports = RelayMapRecordSourceMapImpl;
@@ -0,0 +1,37 @@
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
+ export type RecordState = $Keys<typeof RelayRecordState>;
16
+
17
+ const RelayRecordState = {
18
+ /**
19
+ * Record exists (either fetched from the server or produced by a local,
20
+ * optimistic update).
21
+ */
22
+ EXISTENT: 'EXISTENT',
23
+
24
+ /**
25
+ * Record is known not to exist (either as the result of a mutation, or
26
+ * because the server returned `null` when queried for the record).
27
+ */
28
+ NONEXISTENT: 'NONEXISTENT',
29
+
30
+ /**
31
+ * Record State is unknown because it has not yet been fetched from the
32
+ * server.
33
+ */
34
+ UNKNOWN: 'UNKNOWN',
35
+ };
36
+
37
+ module.exports = RelayRecordState;