relay-runtime 1.3.0 → 1.5.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/LICENSE +16 -26
- package/index.js +3 -6
- package/lib/ConvertToExecuteFunction.js +73 -0
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConcreteVariables.js +11 -6
- package/lib/RelayConnectionHandler.js +2 -4
- package/lib/RelayConnectionInterface.js +3 -5
- package/lib/RelayCore.js +4 -6
- package/lib/RelayDataLoader.js +2 -4
- package/lib/RelayDeclarativeMutationConfig.js +316 -0
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDefaultHandlerProvider.js +2 -4
- package/lib/RelayError.js +2 -6
- package/lib/RelayInMemoryRecordSource.js +2 -4
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayMarkSweepStore.js +22 -5
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayModernEnvironment.js +120 -135
- package/lib/RelayModernFragmentSpecResolver.js +81 -55
- package/lib/RelayModernGraphQLTag.js +8 -17
- package/lib/RelayModernOperationSelector.js +8 -8
- package/lib/RelayModernRecord.js +8 -8
- package/lib/RelayModernSelector.js +54 -43
- package/lib/RelayNetwork.js +9 -11
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayNetworkLogger.js +2 -4
- package/lib/RelayNetworkLoggerTransaction.js +18 -20
- package/lib/RelayNetworkTypes.js +2 -4
- package/lib/RelayObservable.js +193 -120
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayPublishQueue.js +17 -9
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayQueryResponseCache.js +3 -5
- package/lib/RelayReader.js +18 -8
- package/lib/RelayRecordProxy.js +12 -11
- package/lib/RelayRecordSourceMutator.js +9 -9
- package/lib/RelayRecordSourceProxy.js +15 -13
- package/lib/RelayRecordSourceSelectorProxy.js +2 -4
- package/lib/RelayRecordState.js +2 -4
- package/lib/RelayReferenceMarker.js +2 -4
- package/lib/RelayResponseNormalizer.js +34 -25
- package/lib/RelayRuntime.js +25 -14
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelayStoreTypes.js +2 -4
- package/lib/RelayStoreUtils.js +66 -26
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayViewerHandler.js +4 -5
- package/lib/applyRelayModernOptimisticMutation.js +9 -8
- package/lib/cloneRelayHandleSourceField.js +4 -11
- package/lib/commitLocalUpdate.js +2 -4
- package/lib/commitRelayModernMutation.js +24 -22
- package/lib/createRelayNetworkLogger.js +25 -27
- package/lib/dedent.js +2 -5
- package/lib/deepFreeze.js +3 -5
- package/lib/deferrableFragmentKey.js +21 -0
- package/lib/fetchRelayModernQuery.js +13 -21
- package/lib/generateRelayClientID.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/hasOverlappingIDs.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isPromise.js +2 -5
- package/lib/isRelayModernEnvironment.js +2 -4
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/normalizePayload.js +10 -13
- package/lib/normalizeRelayPayload.js +8 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestRelaySubscription.js +20 -34
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/package.json +4 -5
- package/relay-runtime.js +2307 -2665
- package/relay-runtime.min.js +6 -9
- package/ARCHITECTURE.md +0 -232
- package/PATENTS +0 -33
- package/lib/ConvertToObserveFunction.js +0 -39
- package/lib/RelayDebugger.js +0 -199
- package/lib/RelayRecordSourceInspector.js +0 -289
- package/lib/RelayStoreProxyDebugger.js +0 -44
- package/lib/formatStorageKey.js +0 -37
- package/lib/prettyStringify.js +0 -35
- package/lib/setRelayModernMutationConfigs.js +0 -302
- package/lib/stableJSONStringify.js +0 -45
package/PATENTS
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
Additional Grant of Patent Rights Version 2
|
|
2
|
-
|
|
3
|
-
"Software" means the Relay software distributed by Facebook, Inc.
|
|
4
|
-
|
|
5
|
-
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
|
|
6
|
-
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
|
|
7
|
-
(subject to the termination provision below) license under any Necessary
|
|
8
|
-
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
|
|
9
|
-
transfer the Software. For avoidance of doubt, no license is granted under
|
|
10
|
-
Facebook's rights in any patent claims that are infringed by (i) modifications
|
|
11
|
-
to the Software made by you or any third party or (ii) the Software in
|
|
12
|
-
combination with any software or other technology.
|
|
13
|
-
|
|
14
|
-
The license granted hereunder will terminate, automatically and without notice,
|
|
15
|
-
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
|
|
16
|
-
directly or indirectly, or take a direct financial interest in, any Patent
|
|
17
|
-
Assertion: (i) against Facebook or any of its subsidiaries or corporate
|
|
18
|
-
affiliates, (ii) against any party if such Patent Assertion arises in whole or
|
|
19
|
-
in part from any software, technology, product or service of Facebook or any of
|
|
20
|
-
its subsidiaries or corporate affiliates, or (iii) against any party relating
|
|
21
|
-
to the Software. Notwithstanding the foregoing, if Facebook or any of its
|
|
22
|
-
subsidiaries or corporate affiliates files a lawsuit alleging patent
|
|
23
|
-
infringement against you in the first instance, and you respond by filing a
|
|
24
|
-
patent infringement counterclaim in that lawsuit against that party that is
|
|
25
|
-
unrelated to the Software, the license granted hereunder will not terminate
|
|
26
|
-
under section (i) of this paragraph due to such counterclaim.
|
|
27
|
-
|
|
28
|
-
A "Necessary Claim" is a claim of a patent owned by Facebook that is
|
|
29
|
-
necessarily infringed by the Software standing alone.
|
|
30
|
-
|
|
31
|
-
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
|
|
32
|
-
or contributory infringement or inducement to infringe any patent, including a
|
|
33
|
-
cross-claim or counterclaim.
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
* @providesModule ConvertToObserveFunction
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Converts a FetchFunction into an ObserveFunction for use by RelayNetwork.
|
|
18
|
-
*/
|
|
19
|
-
function convertFetch(fn) {
|
|
20
|
-
return function fetch(operation, variables, cacheConfig, uploadables) {
|
|
21
|
-
return require('./RelayObservable').from(fn(operation, variables, cacheConfig, uploadables));
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Converts a SubscribeFunction into an ObserveFunction for use by RelayNetwork.
|
|
27
|
-
*/
|
|
28
|
-
function convertSubscribe(fn) {
|
|
29
|
-
return function subscribe(operation, variables, cacheConfig) {
|
|
30
|
-
return require('./RelayObservable').fromLegacy(function (observer) {
|
|
31
|
-
return fn(operation, variables, cacheConfig, observer);
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
module.exports = {
|
|
37
|
-
convertFetch: convertFetch,
|
|
38
|
-
convertSubscribe: convertSubscribe
|
|
39
|
-
};
|
package/lib/RelayDebugger.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
* @providesModule RelayDebugger
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
19
|
-
|
|
20
|
-
var RelayDebugger = function () {
|
|
21
|
-
function RelayDebugger() {
|
|
22
|
-
(0, _classCallCheck3['default'])(this, RelayDebugger);
|
|
23
|
-
|
|
24
|
-
this._idCounter = 1;
|
|
25
|
-
this._envDebuggers = new Map();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
RelayDebugger.prototype.registerEnvironment = function registerEnvironment(env) {
|
|
29
|
-
var idString = 'RelayModernEnvironment' + this._idCounter++;
|
|
30
|
-
this._envDebuggers.set(idString, new EnvironmentDebugger(env, idString));
|
|
31
|
-
return idString;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
RelayDebugger.prototype.getEnvironmentDebugger = function getEnvironmentDebugger(id) {
|
|
35
|
-
var envDebugger = this._envDebuggers.get(id);
|
|
36
|
-
if (!envDebugger) {
|
|
37
|
-
throw new Error('No registered environment: ' + id);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return envDebugger;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
RelayDebugger.prototype.getRegisteredEnvironmentIds = function getRegisteredEnvironmentIds() {
|
|
44
|
-
return Array.from(this._envDebuggers.keys());
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return RelayDebugger;
|
|
48
|
-
}();
|
|
49
|
-
|
|
50
|
-
var EnvironmentDebugger = function () {
|
|
51
|
-
function EnvironmentDebugger(environment, id) {
|
|
52
|
-
(0, _classCallCheck3['default'])(this, EnvironmentDebugger);
|
|
53
|
-
|
|
54
|
-
this._environment = environment;
|
|
55
|
-
this._id = id;
|
|
56
|
-
this._envIsDirty = false;
|
|
57
|
-
this._monkeyPatchSource();
|
|
58
|
-
|
|
59
|
-
this._recordedMutationEvents = [];
|
|
60
|
-
this._isRecordingMutationEvents = false;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
EnvironmentDebugger.prototype.getEnvironment = function getEnvironment() {
|
|
64
|
-
return this._environment;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
EnvironmentDebugger.prototype.getId = function getId() {
|
|
68
|
-
return this._id;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
EnvironmentDebugger.prototype.getMatchingRecords = function getMatchingRecords(matchStr, matchType) {
|
|
72
|
-
var inspector = require('./RelayRecordSourceInspector').getForEnvironment(this._environment);
|
|
73
|
-
|
|
74
|
-
function isMatching(record) {
|
|
75
|
-
if (matchType === 'idtype') {
|
|
76
|
-
return record.id.includes(matchStr) || !!record.type && record.type.includes(matchStr);
|
|
77
|
-
}
|
|
78
|
-
if (matchType === 'id') {
|
|
79
|
-
return record.id.includes(matchStr);
|
|
80
|
-
}
|
|
81
|
-
if (matchType === 'type') {
|
|
82
|
-
return !!record.type && record.type.includes(matchStr);
|
|
83
|
-
}
|
|
84
|
-
if (matchType === 'predicate') {
|
|
85
|
-
var recordInspector = inspector.get(record.id);
|
|
86
|
-
var fields = recordInspector && recordInspector.inspect();
|
|
87
|
-
if (typeof fields === 'object' && fields !== null) {
|
|
88
|
-
throw new Error('Not implemented');
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
throw new Error('Unknown match type: ' + matchType);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return inspector.getRecords().filter(isMatching);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
EnvironmentDebugger.prototype.getRecord = function getRecord(id) {
|
|
99
|
-
var inspector = require('./RelayRecordSourceInspector').getForEnvironment(this._environment);
|
|
100
|
-
var recordInspector = inspector.get(id);
|
|
101
|
-
return recordInspector && recordInspector.inspect();
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
EnvironmentDebugger.prototype._monkeyPatchSource = function _monkeyPatchSource() {
|
|
105
|
-
var _this = this;
|
|
106
|
-
|
|
107
|
-
var source = this._environment.getStore().getSource();
|
|
108
|
-
var originalSet = source.set;
|
|
109
|
-
var originalRemove = source.remove;
|
|
110
|
-
|
|
111
|
-
source.set = function () {
|
|
112
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
113
|
-
args[_key] = arguments[_key];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
originalSet.apply(source, args);
|
|
117
|
-
_this.triggerDirty();
|
|
118
|
-
};
|
|
119
|
-
source.remove = function () {
|
|
120
|
-
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
121
|
-
args[_key2] = arguments[_key2];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
originalRemove.apply(source, args);
|
|
125
|
-
_this.triggerDirty();
|
|
126
|
-
};
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
EnvironmentDebugger.prototype.triggerDirty = function triggerDirty() {
|
|
130
|
-
this._envIsDirty = true;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
EnvironmentDebugger.prototype.isDirty = function isDirty() {
|
|
134
|
-
return this._envIsDirty;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
EnvironmentDebugger.prototype.resetDirty = function resetDirty() {
|
|
138
|
-
this._envIsDirty = false;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
EnvironmentDebugger.prototype.startRecordingMutationEvents = function startRecordingMutationEvents() {
|
|
142
|
-
this._isRecordingMutationEvents = true;
|
|
143
|
-
this._recordedMutationEvents = [];
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
EnvironmentDebugger.prototype.stopRecordingMutationEvents = function stopRecordingMutationEvents() {
|
|
147
|
-
this._isRecordingMutationEvents = false;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
EnvironmentDebugger.prototype.getRecordedMutationEvents = function getRecordedMutationEvents() {
|
|
151
|
-
return this._recordedMutationEvents;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
EnvironmentDebugger.prototype.recordMutationEvent = function recordMutationEvent(_ref) {
|
|
155
|
-
var eventName = _ref.eventName,
|
|
156
|
-
seriesId = _ref.seriesId,
|
|
157
|
-
payload = _ref.payload,
|
|
158
|
-
mutation = _ref.mutation,
|
|
159
|
-
fn = _ref.fn;
|
|
160
|
-
|
|
161
|
-
if (this._isRecordingMutationEvents) {
|
|
162
|
-
var getSnapshot = function getSnapshot() {
|
|
163
|
-
var snapshot = {};
|
|
164
|
-
var ids = source.getRecordIDs();
|
|
165
|
-
ids.forEach(function (id) {
|
|
166
|
-
snapshot[id] = source.get(id);
|
|
167
|
-
});
|
|
168
|
-
return snapshot;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
var source = this._environment.getStore().getSource();
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var _snapshotBefore = getSnapshot();
|
|
175
|
-
fn();
|
|
176
|
-
var _snapshotAfter = getSnapshot();
|
|
177
|
-
|
|
178
|
-
var event = {
|
|
179
|
-
eventName: eventName,
|
|
180
|
-
seriesId: seriesId,
|
|
181
|
-
payload: payload,
|
|
182
|
-
snapshotBefore: _snapshotBefore,
|
|
183
|
-
snapshotAfter: _snapshotAfter,
|
|
184
|
-
mutation: mutation
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
this._recordedMutationEvents.push(event);
|
|
188
|
-
} else {
|
|
189
|
-
fn();
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
return EnvironmentDebugger;
|
|
194
|
-
}();
|
|
195
|
-
|
|
196
|
-
module.exports = {
|
|
197
|
-
RelayDebugger: RelayDebugger,
|
|
198
|
-
EnvironmentDebugger: EnvironmentDebugger
|
|
199
|
-
};
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
* @providesModule RelayRecordSourceInspector
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
19
|
-
|
|
20
|
-
var _require = require('./RelayStoreUtils'),
|
|
21
|
-
ROOT_ID = _require.ROOT_ID,
|
|
22
|
-
ROOT_TYPE = _require.ROOT_TYPE;
|
|
23
|
-
|
|
24
|
-
var _require2 = require('./RelayStoreUtils'),
|
|
25
|
-
REF_KEY = _require2.REF_KEY,
|
|
26
|
-
REFS_KEY = _require2.REFS_KEY;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A class intended for introspecting a RecordSource and its Records during
|
|
30
|
-
* development.
|
|
31
|
-
*/
|
|
32
|
-
var RelayRecordSourceInspector = function () {
|
|
33
|
-
RelayRecordSourceInspector.getForEnvironment = function getForEnvironment(environment) {
|
|
34
|
-
return new RelayRecordSourceInspector(environment.getStore().getSource());
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function RelayRecordSourceInspector(source) {
|
|
38
|
-
(0, _classCallCheck3['default'])(this, RelayRecordSourceInspector);
|
|
39
|
-
|
|
40
|
-
this._proxies = {};
|
|
41
|
-
this._source = source;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Returns an inspector for the record with the given id, or null/undefined if
|
|
46
|
-
* that record is deleted/unfetched.
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
RelayRecordSourceInspector.prototype.get = function get(dataID) {
|
|
51
|
-
if (!this._proxies.hasOwnProperty(dataID)) {
|
|
52
|
-
var record = this._source.get(dataID);
|
|
53
|
-
if (record != null) {
|
|
54
|
-
this._proxies[dataID] = new RecordInspector(this, record);
|
|
55
|
-
} else {
|
|
56
|
-
this._proxies[dataID] = record;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return this._proxies[dataID];
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Returns a list of "<id>: <type>" for each record in the store that has an
|
|
64
|
-
* `id`.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
RelayRecordSourceInspector.prototype.getNodes = function getNodes() {
|
|
69
|
-
var _this = this;
|
|
70
|
-
|
|
71
|
-
var nodes = [];
|
|
72
|
-
this._source.getRecordIDs().forEach(function (dataID) {
|
|
73
|
-
if (dataID.indexOf('client:') === 0) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
var record = _this._source.get(dataID);
|
|
77
|
-
nodes.push(RecordSummary.createFromRecord(dataID, record));
|
|
78
|
-
});
|
|
79
|
-
return nodes;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Returns a list of "<id>: <type>" for all records in the store including
|
|
84
|
-
* those that do not have an `id`.
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
RelayRecordSourceInspector.prototype.getRecords = function getRecords() {
|
|
89
|
-
var _this2 = this;
|
|
90
|
-
|
|
91
|
-
return this._source.getRecordIDs().map(function (dataID) {
|
|
92
|
-
var record = _this2._source.get(dataID);
|
|
93
|
-
return RecordSummary.createFromRecord(dataID, record);
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Returns an inspector for the synthesized "root" object, allowing access to
|
|
99
|
-
* e.g. the `viewer` object or the results of other fields on the "Query"
|
|
100
|
-
* type.
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
RelayRecordSourceInspector.prototype.getRoot = function getRoot() {
|
|
105
|
-
var root = this.get(ROOT_ID);
|
|
106
|
-
require('fbjs/lib/invariant')(root && root.getType() === ROOT_TYPE, 'RelayRecordSourceProxy#getRoot(): Expected the source to contain a ' + 'root record.');
|
|
107
|
-
// Make viewer more accessible: if a record is not present on the original
|
|
108
|
-
// field name but is present on the viewer handle field, rewrite the getter
|
|
109
|
-
// to make `root.viewer` work.
|
|
110
|
-
if (root.viewer == null) {
|
|
111
|
-
var viewerHandle = require('./getRelayHandleKey')('viewer', null, 'viewer');
|
|
112
|
-
var unsafeRoot = root; // to access getter properties
|
|
113
|
-
if (unsafeRoot[viewerHandle] != null) {
|
|
114
|
-
Object.defineProperty(unsafeRoot, 'viewer', {
|
|
115
|
-
configurable: true,
|
|
116
|
-
enumerable: true,
|
|
117
|
-
get: function get() {
|
|
118
|
-
return unsafeRoot[viewerHandle];
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return root;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return RelayRecordSourceInspector;
|
|
127
|
-
}();
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Internal class for inspecting a single Record.
|
|
131
|
-
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
var RecordInspector = function () {
|
|
135
|
-
function RecordInspector(sourceInspector, record) {
|
|
136
|
-
var _this3 = this;
|
|
137
|
-
|
|
138
|
-
(0, _classCallCheck3['default'])(this, RecordInspector);
|
|
139
|
-
|
|
140
|
-
this._record = record;
|
|
141
|
-
this._sourceInspector = sourceInspector;
|
|
142
|
-
|
|
143
|
-
// Make it easier to inspect the record in a debugger console:
|
|
144
|
-
// defined properties appear in autocomplete when typing "obj."
|
|
145
|
-
require('fbjs/lib/forEachObject')(record, function (value, key) {
|
|
146
|
-
var identifier = key.replace(/[^_a-zA-Z0-9]/g, '_');
|
|
147
|
-
if (typeof value === 'object' && value !== null) {
|
|
148
|
-
if (value.hasOwnProperty(REF_KEY)) {
|
|
149
|
-
Object.defineProperty(_this3, identifier, {
|
|
150
|
-
configurable: true,
|
|
151
|
-
enumerable: true,
|
|
152
|
-
get: function get() {
|
|
153
|
-
return this.getLinkedRecord(key);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
} else if (value.hasOwnProperty(REFS_KEY)) {
|
|
157
|
-
Object.defineProperty(_this3, identifier, {
|
|
158
|
-
configurable: true,
|
|
159
|
-
enumerable: true,
|
|
160
|
-
get: function get() {
|
|
161
|
-
return this.getLinkedRecords(key);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
} else {
|
|
166
|
-
Object.defineProperty(_this3, identifier, {
|
|
167
|
-
configurable: true,
|
|
168
|
-
enumerable: true,
|
|
169
|
-
get: function get() {
|
|
170
|
-
return this.getValue(key);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Get the cache id of the given record. For types that implement the `Node`
|
|
179
|
-
* interface (or that have an `id`) this will be `id`, for other types it will be
|
|
180
|
-
* a synthesized identifier based on the field path from the nearest ancestor
|
|
181
|
-
* record that does have an `id`.
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
RecordInspector.prototype.getDataID = function getDataID() {
|
|
186
|
-
return require('./RelayModernRecord').getDataID(this._record);
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Returns a list of the fields that have been fetched on the current record.
|
|
191
|
-
*/
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
RecordInspector.prototype.getFields = function getFields() {
|
|
195
|
-
return Object.keys(this._record).sort();
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Returns the type of the record.
|
|
200
|
-
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
RecordInspector.prototype.getType = function getType() {
|
|
204
|
-
return require('./RelayModernRecord').getType(this._record);
|
|
205
|
-
};
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Returns a copy of the internal representation of the record.
|
|
209
|
-
*/
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
RecordInspector.prototype.inspect = function inspect() {
|
|
213
|
-
return require('./simpleClone')(this._record);
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Returns the value of a scalar field. May throw if the given field is
|
|
218
|
-
* present but not actually scalar.
|
|
219
|
-
*/
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
RecordInspector.prototype.getValue = function getValue(name, args) {
|
|
223
|
-
var storageKey = args ? require('./formatStorageKey')(name, args) : name;
|
|
224
|
-
return require('./RelayModernRecord').getValue(this._record, storageKey);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Returns an inspector for the given scalar "linked" field (a field whose
|
|
229
|
-
* value is another Record instead of a scalar). May throw if the field is
|
|
230
|
-
* present but not a scalar linked record.
|
|
231
|
-
*/
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
RecordInspector.prototype.getLinkedRecord = function getLinkedRecord(name, args) {
|
|
235
|
-
var storageKey = args ? require('./formatStorageKey')(name, args) : name;
|
|
236
|
-
var linkedID = require('./RelayModernRecord').getLinkedRecordID(this._record, storageKey);
|
|
237
|
-
return linkedID != null ? this._sourceInspector.get(linkedID) : linkedID;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Returns an array of inspectors for the given plural "linked" field (a field
|
|
242
|
-
* whose value is an array of Records instead of a scalar). May throw if the
|
|
243
|
-
* field is present but not a plural linked record.
|
|
244
|
-
*/
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
RecordInspector.prototype.getLinkedRecords = function getLinkedRecords(name, args) {
|
|
248
|
-
var _this4 = this;
|
|
249
|
-
|
|
250
|
-
var storageKey = args ? require('./formatStorageKey')(name, args) : name;
|
|
251
|
-
var linkedIDs = require('./RelayModernRecord').getLinkedRecordIDs(this._record, storageKey);
|
|
252
|
-
if (linkedIDs == null) {
|
|
253
|
-
return linkedIDs;
|
|
254
|
-
}
|
|
255
|
-
return linkedIDs.map(function (linkedID) {
|
|
256
|
-
return linkedID != null ? _this4._sourceInspector.get(linkedID) : linkedID;
|
|
257
|
-
});
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
return RecordInspector;
|
|
261
|
-
}();
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* An internal class to provide a console-friendly string representation of a
|
|
265
|
-
* Record.
|
|
266
|
-
*/
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
var RecordSummary = function () {
|
|
270
|
-
RecordSummary.createFromRecord = function createFromRecord(id, record) {
|
|
271
|
-
var type = record ? require('./RelayModernRecord').getType(record) : null;
|
|
272
|
-
return new RecordSummary(id, type);
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
function RecordSummary(id, type) {
|
|
276
|
-
(0, _classCallCheck3['default'])(this, RecordSummary);
|
|
277
|
-
|
|
278
|
-
this.id = id;
|
|
279
|
-
this.type = type;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
RecordSummary.prototype.toString = function toString() {
|
|
283
|
-
return this.type ? this.id + ': ' + this.type : this.id;
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
return RecordSummary;
|
|
287
|
-
}();
|
|
288
|
-
|
|
289
|
-
module.exports = RelayRecordSourceInspector;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
* @providesModule RelayStoreProxyDebugger
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
/* eslint-disable no-console-disallow */
|
|
17
|
-
|
|
18
|
-
function dump(proxy) {
|
|
19
|
-
if (proxy instanceof require('./RelayRecordSourceSelectorProxy')) {
|
|
20
|
-
var recordSource = proxy.__recordSource;
|
|
21
|
-
if (recordSource instanceof require('./RelayRecordSourceProxy')) {
|
|
22
|
-
dumpRelayRecordSourceProxy(recordSource);
|
|
23
|
-
}
|
|
24
|
-
} else if (proxy instanceof require('./RelayRecordSourceProxy')) {
|
|
25
|
-
dumpRelayRecordSourceProxy(proxy);
|
|
26
|
-
} else {
|
|
27
|
-
require('fbjs/lib/warning')(false, 'RelayStoreProxyDebugger: not supported yet.');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function dumpRelayRecordSourceProxy(proxy) {
|
|
32
|
-
var mutatorSources = proxy.__mutator.__sources;
|
|
33
|
-
if (mutatorSources.length !== 2) {
|
|
34
|
-
require('fbjs/lib/warning')(false, 'RelayStoreProxyDebugger: expected the mutator sources to have sink and base. ' + 'This is a Relay side bug; please report it to the Relay team.');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
console.groupCollapsed('RelayStoreProxyDebugger', '');
|
|
38
|
-
// Create a 'deep copy' of the records through an extra json encode/decode step.
|
|
39
|
-
console.log('Modified Records: ', JSON.parse(JSON.stringify(mutatorSources[0])));
|
|
40
|
-
console.log('Original Records: ', JSON.parse(JSON.stringify(mutatorSources[1])));
|
|
41
|
-
console.groupEnd();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = { dump: dump };
|
package/lib/formatStorageKey.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
* @providesModule formatStorageKey
|
|
10
|
-
*
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Given a `fieldName` (eg. "foo") and an object representing arguments and
|
|
18
|
-
* values (eg. `{first: 10, orberBy: "name"}`) returns a unique storage key
|
|
19
|
-
* (ie. `foo{"first":10,"orderBy":"name"}`).
|
|
20
|
-
*/
|
|
21
|
-
function formatStorageKey(fieldName, argsWithValues) {
|
|
22
|
-
if (!argsWithValues) {
|
|
23
|
-
return fieldName;
|
|
24
|
-
}
|
|
25
|
-
var filtered = null;
|
|
26
|
-
require('fbjs/lib/forEachObject')(argsWithValues, function (value, argName) {
|
|
27
|
-
if (value != null) {
|
|
28
|
-
if (!filtered) {
|
|
29
|
-
filtered = {};
|
|
30
|
-
}
|
|
31
|
-
filtered[argName] = value;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return fieldName + (filtered ? require('./stableJSONStringify')(filtered) : '');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
module.exports = formatStorageKey;
|
package/lib/prettyStringify.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the BSD-style license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @providesModule prettyStringify
|
|
11
|
-
* @format
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Simple wrapper for `JSON.stringify` that adds whitespace to aid readability:
|
|
18
|
-
*
|
|
19
|
-
* ```
|
|
20
|
-
* const object = {a: 1, b 2};
|
|
21
|
-
*
|
|
22
|
-
* JSON.stringify(object); // {"a":1,"b":2}
|
|
23
|
-
*
|
|
24
|
-
* prettyStringify(object); // {
|
|
25
|
-
* // "a": 1,
|
|
26
|
-
* // "b": 2
|
|
27
|
-
* // }
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
function prettyStringify(stringifiable) {
|
|
32
|
-
return JSON.stringify(stringifiable, null, 2);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
module.exports = prettyStringify;
|