relay-forms-nodeps 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc.js +5 -0
- package/LICENSE +21 -0
- package/README.md +124 -0
- package/lib/RelayFormsTypes.d.ts +37 -0
- package/lib/RelayFormsTypes.js +5 -0
- package/lib/Utils.d.ts +11 -0
- package/lib/Utils.js +87 -0
- package/lib/es/RelayFormsTypes.d.ts +37 -0
- package/lib/es/RelayFormsTypes.js +0 -0
- package/lib/es/Utils.d.ts +11 -0
- package/lib/es/Utils.js +81 -0
- package/lib/es/index.d.ts +9 -0
- package/lib/es/index.js +7 -0
- package/lib/es/relay/RelayModernRecord.d.ts +107 -0
- package/lib/es/relay/RelayModernRecord.js +183 -0
- package/lib/es/relay/RelayModernSelector.d.ts +11 -0
- package/lib/es/relay/RelayModernSelector.js +29 -0
- package/lib/es/relay/RelayModernStore.d.ts +51 -0
- package/lib/es/relay/RelayModernStore.js +355 -0
- package/lib/es/relay/RelayReader.d.ts +14 -0
- package/lib/es/relay/RelayReader.js +86 -0
- package/lib/es/relay/RelayRecordProxy.d.ts +28 -0
- package/lib/es/relay/RelayRecordProxy.js +57 -0
- package/lib/es/relay/RelayRecordSource.d.ts +28 -0
- package/lib/es/relay/RelayRecordSource.js +70 -0
- package/lib/es/relay/RelayRecordSourceMutator.d.ts +36 -0
- package/lib/es/relay/RelayRecordSourceMutator.js +75 -0
- package/lib/es/relay/RelayRecordSourceProxy.d.ts +25 -0
- package/lib/es/relay/RelayRecordSourceProxy.js +52 -0
- package/lib/es/relay/RelayReferenceMarker.d.ts +10 -0
- package/lib/es/relay/RelayReferenceMarker.js +54 -0
- package/lib/es/relay/RelayStoreProvider.d.ts +7 -0
- package/lib/es/relay/RelayStoreProvider.js +16 -0
- package/lib/es/relay/RelayStoreUtils.d.ts +51 -0
- package/lib/es/relay/RelayStoreUtils.js +199 -0
- package/lib/es/relay/RelayTypes.d.ts +92 -0
- package/lib/es/relay/RelayTypes.js +0 -0
- package/lib/es/relay/queries.d.ts +86 -0
- package/lib/es/relay/queries.js +68 -0
- package/lib/es/useForceUpdate.d.ts +1 -0
- package/lib/es/useForceUpdate.js +8 -0
- package/lib/es/useFormSetValue.d.ts +2 -0
- package/lib/es/useFormSetValue.js +84 -0
- package/lib/es/useFormState.d.ts +2 -0
- package/lib/es/useFormState.js +49 -0
- package/lib/es/useFormSubmit.d.ts +2 -0
- package/lib/es/useFormSubmit.js +105 -0
- package/lib/es/useFormValue.d.ts +2 -0
- package/lib/es/useFormValue.js +19 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +20 -0
- package/lib/relay/RelayModernRecord.d.ts +107 -0
- package/lib/relay/RelayModernRecord.js +188 -0
- package/lib/relay/RelayModernSelector.d.ts +11 -0
- package/lib/relay/RelayModernSelector.js +36 -0
- package/lib/relay/RelayModernStore.d.ts +51 -0
- package/lib/relay/RelayModernStore.js +359 -0
- package/lib/relay/RelayReader.d.ts +14 -0
- package/lib/relay/RelayReader.js +92 -0
- package/lib/relay/RelayRecordProxy.d.ts +28 -0
- package/lib/relay/RelayRecordProxy.js +60 -0
- package/lib/relay/RelayRecordSource.d.ts +28 -0
- package/lib/relay/RelayRecordSource.js +75 -0
- package/lib/relay/RelayRecordSourceMutator.d.ts +36 -0
- package/lib/relay/RelayRecordSourceMutator.js +80 -0
- package/lib/relay/RelayRecordSourceProxy.d.ts +25 -0
- package/lib/relay/RelayRecordSourceProxy.js +57 -0
- package/lib/relay/RelayReferenceMarker.d.ts +10 -0
- package/lib/relay/RelayReferenceMarker.js +60 -0
- package/lib/relay/RelayStoreProvider.d.ts +7 -0
- package/lib/relay/RelayStoreProvider.js +22 -0
- package/lib/relay/RelayStoreUtils.d.ts +51 -0
- package/lib/relay/RelayStoreUtils.js +208 -0
- package/lib/relay/RelayTypes.d.ts +92 -0
- package/lib/relay/RelayTypes.js +5 -0
- package/lib/relay/queries.d.ts +86 -0
- package/lib/relay/queries.js +73 -0
- package/lib/umd/relay-forms-nodeps.js +1478 -0
- package/lib/umd/relay-forms-nodeps.js.map +1 -0
- package/lib/umd/relay-forms-nodeps.min.js +2 -0
- package/lib/umd/relay-forms-nodeps.min.js.map +1 -0
- package/lib/useForceUpdate.d.ts +1 -0
- package/lib/useForceUpdate.js +14 -0
- package/lib/useFormSetValue.d.ts +2 -0
- package/lib/useFormSetValue.js +90 -0
- package/lib/useFormState.d.ts +2 -0
- package/lib/useFormState.js +54 -0
- package/lib/useFormSubmit.d.ts +2 -0
- package/lib/useFormSubmit.js +110 -0
- package/lib/useFormValue.d.ts +2 -0
- package/lib/useFormValue.js +25 -0
- package/package.json +89 -0
- package/replace.config.js +5 -0
- package/rollup.config.js +92 -0
- package/tsconfig.esm.json +7 -0
- package/yarn-error.log +127 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* @flow strict-local
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
15
|
+
var _ = {
|
|
16
|
+
label: 0,
|
|
17
|
+
sent: function () {
|
|
18
|
+
if (t[0] & 1) throw t[1];
|
|
19
|
+
return t[1];
|
|
20
|
+
},
|
|
21
|
+
trys: [],
|
|
22
|
+
ops: []
|
|
23
|
+
},
|
|
24
|
+
f,
|
|
25
|
+
y,
|
|
26
|
+
t,
|
|
27
|
+
g;
|
|
28
|
+
return g = {
|
|
29
|
+
next: verb(0),
|
|
30
|
+
"throw": verb(1),
|
|
31
|
+
"return": verb(2)
|
|
32
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
33
|
+
return this;
|
|
34
|
+
}), g;
|
|
35
|
+
function verb(n) {
|
|
36
|
+
return function (v) {
|
|
37
|
+
return step([n, v]);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function step(op) {
|
|
41
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
42
|
+
while (_) try {
|
|
43
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
44
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
45
|
+
switch (op[0]) {
|
|
46
|
+
case 0:
|
|
47
|
+
case 1:
|
|
48
|
+
t = op;
|
|
49
|
+
break;
|
|
50
|
+
case 4:
|
|
51
|
+
_.label++;
|
|
52
|
+
return {
|
|
53
|
+
value: op[1],
|
|
54
|
+
done: false
|
|
55
|
+
};
|
|
56
|
+
case 5:
|
|
57
|
+
_.label++;
|
|
58
|
+
y = op[1];
|
|
59
|
+
op = [0];
|
|
60
|
+
continue;
|
|
61
|
+
case 7:
|
|
62
|
+
op = _.ops.pop();
|
|
63
|
+
_.trys.pop();
|
|
64
|
+
continue;
|
|
65
|
+
default:
|
|
66
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
67
|
+
_ = 0;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
71
|
+
_.label = op[1];
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
75
|
+
_.label = t[1];
|
|
76
|
+
t = op;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
if (t && _.label < t[2]) {
|
|
80
|
+
_.label = t[2];
|
|
81
|
+
_.ops.push(op);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
if (t[2]) _.ops.pop();
|
|
85
|
+
_.trys.pop();
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
op = body.call(thisArg, _);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
op = [6, e];
|
|
91
|
+
y = 0;
|
|
92
|
+
} finally {
|
|
93
|
+
f = t = 0;
|
|
94
|
+
}
|
|
95
|
+
if (op[0] & 5) throw op[1];
|
|
96
|
+
return {
|
|
97
|
+
value: op[0] ? op[1] : void 0,
|
|
98
|
+
done: true
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
Object.defineProperty(exports, "__esModule", {
|
|
103
|
+
value: true
|
|
104
|
+
});
|
|
105
|
+
var RelayModernRecord_1 = require("./RelayModernRecord");
|
|
106
|
+
var RelayReader_1 = require("./RelayReader");
|
|
107
|
+
var RelayRecordSource_1 = require("./RelayRecordSource");
|
|
108
|
+
var RelayRecordSourceMutator_1 = require("./RelayRecordSourceMutator");
|
|
109
|
+
var RelayRecordSourceProxy_1 = require("./RelayRecordSourceProxy");
|
|
110
|
+
var RelayReferenceMarker_1 = require("./RelayReferenceMarker");
|
|
111
|
+
var RelayStoreUtils_1 = require("./RelayStoreUtils");
|
|
112
|
+
var resolvedPromise = Promise.resolve();
|
|
113
|
+
/**
|
|
114
|
+
* An alternative to setImmediate based on Promise.
|
|
115
|
+
*/
|
|
116
|
+
function resolveImmediate(callback) {
|
|
117
|
+
resolvedPromise.then(callback).catch(throwNext);
|
|
118
|
+
}
|
|
119
|
+
function throwNext(error) {
|
|
120
|
+
setTimeout(function () {
|
|
121
|
+
throw error;
|
|
122
|
+
}, 0);
|
|
123
|
+
}
|
|
124
|
+
var ROOT_ID = RelayStoreUtils_1.RelayStoreUtils.ROOT_ID;
|
|
125
|
+
function createStore() {
|
|
126
|
+
return new RelayModernStore(new RelayRecordSource_1.RelayRecordSource());
|
|
127
|
+
}
|
|
128
|
+
exports.createStore = createStore;
|
|
129
|
+
/**
|
|
130
|
+
* @public
|
|
131
|
+
*
|
|
132
|
+
* An implementation of the `Store` interface defined in `RelayStoreTypes`.
|
|
133
|
+
*
|
|
134
|
+
* Note that a Store takes ownership of all records provided to it: other
|
|
135
|
+
* objects may continue to hold a reference to such records but may not mutate
|
|
136
|
+
* them. The static Relay core is architected to avoid mutating records that may have been
|
|
137
|
+
* passed to a store: operations that mutate records will either create fresh
|
|
138
|
+
* records or clone existing records and modify the clones. Record immutability
|
|
139
|
+
* is also enforced in development mode by freezing all records passed to a store.
|
|
140
|
+
*/
|
|
141
|
+
var RelayModernStore = /** @class */function () {
|
|
142
|
+
function RelayModernStore(source) {
|
|
143
|
+
var _this = this;
|
|
144
|
+
this._gcStep = function () {
|
|
145
|
+
if (_this._gcRun) {
|
|
146
|
+
if (_this._gcRun.next().done) {
|
|
147
|
+
_this._gcRun = null;
|
|
148
|
+
} else {
|
|
149
|
+
resolveImmediate(_this._gcStep);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
this._currentWriteEpoch = 0;
|
|
154
|
+
this._gcRun = null;
|
|
155
|
+
this._recordSource = source;
|
|
156
|
+
this._roots = new Map();
|
|
157
|
+
this._updatedRecordIDs = new Set();
|
|
158
|
+
this._subs = new Set();
|
|
159
|
+
initializeRecordSource(this._recordSource);
|
|
160
|
+
}
|
|
161
|
+
RelayModernStore.prototype.getSource = function () {
|
|
162
|
+
return this._recordSource;
|
|
163
|
+
};
|
|
164
|
+
RelayModernStore.prototype.commitUpdate = function (updater) {
|
|
165
|
+
var sink = new RelayRecordSource_1.RelayRecordSource();
|
|
166
|
+
var mutator = new RelayRecordSourceMutator_1.RelayRecordSourceMutator(this.getSource(), sink);
|
|
167
|
+
var recordSourceProxy = new RelayRecordSourceProxy_1.RelayRecordSourceProxy(mutator);
|
|
168
|
+
updater(recordSourceProxy);
|
|
169
|
+
this.publish(sink);
|
|
170
|
+
this.notify();
|
|
171
|
+
};
|
|
172
|
+
RelayModernStore.prototype.retain = function (operation) {
|
|
173
|
+
var _this = this;
|
|
174
|
+
var id = operation.identifier;
|
|
175
|
+
var disposed = false;
|
|
176
|
+
var dispose = function () {
|
|
177
|
+
// Ensure each retain can only dispose once
|
|
178
|
+
if (disposed) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
disposed = true;
|
|
182
|
+
// For Flow: guard against the entry somehow not existing
|
|
183
|
+
var rootEntry = _this._roots.get(id);
|
|
184
|
+
if (rootEntry == null) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
// Decrement the ref count: if it becomes zero it is eligible
|
|
188
|
+
// for release.
|
|
189
|
+
rootEntry.refCount -= 1;
|
|
190
|
+
if (rootEntry.refCount === 0) {
|
|
191
|
+
_this._roots.delete(id);
|
|
192
|
+
_this.scheduleGC();
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
var rootEntry = this._roots.get(id);
|
|
196
|
+
if (rootEntry != null) {
|
|
197
|
+
// If we've previously retained this operation, increment the refCount
|
|
198
|
+
rootEntry.refCount += 1;
|
|
199
|
+
} else {
|
|
200
|
+
// Otherwise create a new entry for the operation
|
|
201
|
+
this._roots.set(id, {
|
|
202
|
+
operation: operation,
|
|
203
|
+
refCount: 1
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
dispose: dispose
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
RelayModernStore.prototype.lookup = function (selector) {
|
|
211
|
+
var source = this.getSource();
|
|
212
|
+
return RelayReader_1.relayRead(source, selector);
|
|
213
|
+
};
|
|
214
|
+
// This method will return a list of updated owners from the subscriptions
|
|
215
|
+
RelayModernStore.prototype.notify = function () {
|
|
216
|
+
var _this = this;
|
|
217
|
+
this._currentWriteEpoch += 1;
|
|
218
|
+
var updateIds = this._updatedRecordIDs;
|
|
219
|
+
var hasUpdatedRecords = updateIds.size !== 0;
|
|
220
|
+
var source = this.getSource();
|
|
221
|
+
this._subs.forEach(function (subscription) {
|
|
222
|
+
_this._updateSub(source, subscription, updateIds, hasUpdatedRecords);
|
|
223
|
+
});
|
|
224
|
+
this._updatedRecordIDs.clear();
|
|
225
|
+
};
|
|
226
|
+
RelayModernStore.prototype._updateSub = function (source, subscription, updatedRecordIDs, hasUpdatedRecords) {
|
|
227
|
+
var callback = subscription.callback,
|
|
228
|
+
snapshot = subscription.snapshot;
|
|
229
|
+
var hasOverlappingUpdates = hasUpdatedRecords && RelayStoreUtils_1.hasOverlappingIDs(snapshot.seenRecords, updatedRecordIDs);
|
|
230
|
+
if (hasOverlappingUpdates) {
|
|
231
|
+
var nextSnapshot = RelayReader_1.relayRead(source, snapshot.selector);
|
|
232
|
+
var nextData = RelayStoreUtils_1.recycleNodesInto(snapshot.data, nextSnapshot.data);
|
|
233
|
+
nextSnapshot = {
|
|
234
|
+
data: nextData,
|
|
235
|
+
seenRecords: nextSnapshot.seenRecords,
|
|
236
|
+
selector: nextSnapshot.selector
|
|
237
|
+
};
|
|
238
|
+
subscription.snapshot = nextSnapshot;
|
|
239
|
+
if (nextSnapshot.data !== snapshot.data) {
|
|
240
|
+
callback(nextSnapshot);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
RelayModernStore.prototype.publish = function (source) {
|
|
245
|
+
var target = this.getSource();
|
|
246
|
+
updateTargetFromSource(target, source, this._updatedRecordIDs);
|
|
247
|
+
};
|
|
248
|
+
RelayModernStore.prototype.subscribe = function (snapshot, callback) {
|
|
249
|
+
var _this = this;
|
|
250
|
+
var subscription = {
|
|
251
|
+
callback: callback,
|
|
252
|
+
snapshot: snapshot
|
|
253
|
+
};
|
|
254
|
+
var dispose = function () {
|
|
255
|
+
_this._subs.delete(subscription);
|
|
256
|
+
};
|
|
257
|
+
this._subs.add(subscription);
|
|
258
|
+
return {
|
|
259
|
+
dispose: dispose
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
RelayModernStore.prototype.scheduleGC = function () {
|
|
263
|
+
if (this._gcRun) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
this._gcRun = this._collect();
|
|
267
|
+
resolveImmediate(this._gcStep);
|
|
268
|
+
};
|
|
269
|
+
RelayModernStore.prototype._collect = function () {
|
|
270
|
+
var startEpoch, references, _i, _a, operation, storeIDs, ii, dataID;
|
|
271
|
+
return __generator(this, function (_b) {
|
|
272
|
+
switch (_b.label) {
|
|
273
|
+
case 0:
|
|
274
|
+
if (!true) return [3 /*break*/, 5];
|
|
275
|
+
startEpoch = this._currentWriteEpoch;
|
|
276
|
+
references = new Set();
|
|
277
|
+
_i = 0, _a = this._roots.values();
|
|
278
|
+
_b.label = 1;
|
|
279
|
+
case 1:
|
|
280
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
281
|
+
operation = _a[_i].operation;
|
|
282
|
+
RelayReferenceMarker_1.mark(this._recordSource, operation.fragment, references);
|
|
283
|
+
// Yield for other work after each operation
|
|
284
|
+
return [4 /*yield*/];
|
|
285
|
+
case 2:
|
|
286
|
+
// Yield for other work after each operation
|
|
287
|
+
_b.sent();
|
|
288
|
+
// If the store was updated, restart
|
|
289
|
+
if (startEpoch !== this._currentWriteEpoch) {
|
|
290
|
+
return [3 /*break*/, 0];
|
|
291
|
+
}
|
|
292
|
+
_b.label = 3;
|
|
293
|
+
case 3:
|
|
294
|
+
_i++;
|
|
295
|
+
return [3 /*break*/, 1];
|
|
296
|
+
case 4:
|
|
297
|
+
// Sweep records without references
|
|
298
|
+
if (references.size === 0) {
|
|
299
|
+
// Short-circuit if *nothing* is referenced
|
|
300
|
+
this._recordSource.clear();
|
|
301
|
+
} else {
|
|
302
|
+
storeIDs = this._recordSource.getRecordIDs();
|
|
303
|
+
for (ii = 0; ii < storeIDs.length; ii++) {
|
|
304
|
+
dataID = storeIDs[ii];
|
|
305
|
+
if (!references.has(dataID)) {
|
|
306
|
+
this._recordSource.remove(dataID);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return [2 /*return*/];
|
|
311
|
+
case 5:
|
|
312
|
+
return [2 /*return*/];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
return RelayModernStore;
|
|
318
|
+
}();
|
|
319
|
+
exports.RelayModernStore = RelayModernStore;
|
|
320
|
+
function initializeRecordSource(target) {
|
|
321
|
+
if (!target.has(ROOT_ID)) {
|
|
322
|
+
var rootRecord = RelayModernRecord_1.RelayModernRecord.create(ROOT_ID);
|
|
323
|
+
target.set(ROOT_ID, rootRecord);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Updates the target with information from source, also updating a mapping of
|
|
328
|
+
* which records in the target were changed as a result.
|
|
329
|
+
* Additionally, will mark records as invalidated at the current write epoch
|
|
330
|
+
* given the set of record ids marked as stale in this update.
|
|
331
|
+
*/
|
|
332
|
+
function updateTargetFromSource(target, source, updatedRecordIDs) {
|
|
333
|
+
// Update the target based on the changes present in source
|
|
334
|
+
var dataIDs = source.getRecordIDs();
|
|
335
|
+
for (var ii = 0; ii < dataIDs.length; ii++) {
|
|
336
|
+
var dataID = dataIDs[ii];
|
|
337
|
+
var sourceRecord = source.get(dataID);
|
|
338
|
+
var targetRecord = target.get(dataID);
|
|
339
|
+
if (sourceRecord && targetRecord) {
|
|
340
|
+
// ReactFlightClientResponses are lazy and only materialize when readRoot
|
|
341
|
+
// is called when we read the field, so if the record is a Flight field
|
|
342
|
+
// we always use the new record's data regardless of whether
|
|
343
|
+
// it actually changed. Let React take care of reconciliation instead.
|
|
344
|
+
var nextRecord = RelayModernRecord_1.RelayModernRecord.update(targetRecord, sourceRecord);
|
|
345
|
+
if (nextRecord !== targetRecord) {
|
|
346
|
+
updatedRecordIDs.add(dataID);
|
|
347
|
+
target.set(dataID, nextRecord);
|
|
348
|
+
}
|
|
349
|
+
} else if (sourceRecord === null) {
|
|
350
|
+
target.delete(dataID);
|
|
351
|
+
if (targetRecord !== null) {
|
|
352
|
+
updatedRecordIDs.add(dataID);
|
|
353
|
+
}
|
|
354
|
+
} else if (sourceRecord) {
|
|
355
|
+
target.set(dataID, sourceRecord);
|
|
356
|
+
updatedRecordIDs.add(dataID);
|
|
357
|
+
} // don't add explicit undefined
|
|
358
|
+
}
|
|
359
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
export declare function relayRead(recordSource: any, selector: any): {
|
|
11
|
+
data: any;
|
|
12
|
+
seenRecords: any;
|
|
13
|
+
selector: any;
|
|
14
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*
|
|
10
|
+
* @flow strict-local
|
|
11
|
+
* @format
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", {
|
|
14
|
+
value: true
|
|
15
|
+
});
|
|
16
|
+
var RelayModernRecord_1 = require("./RelayModernRecord");
|
|
17
|
+
var RelayStoreUtils_1 = require("./RelayStoreUtils");
|
|
18
|
+
function relayRead(recordSource, selector) {
|
|
19
|
+
var reader = new RelayReader(recordSource, selector);
|
|
20
|
+
return reader.read();
|
|
21
|
+
}
|
|
22
|
+
exports.relayRead = relayRead;
|
|
23
|
+
/**
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
var RelayReader = /** @class */function () {
|
|
27
|
+
function RelayReader(recordSource, selector) {
|
|
28
|
+
this._recordSource = recordSource;
|
|
29
|
+
this._seenRecords = new Set();
|
|
30
|
+
this._selector = selector;
|
|
31
|
+
}
|
|
32
|
+
RelayReader.prototype.read = function () {
|
|
33
|
+
var _a = this._selector,
|
|
34
|
+
node = _a.node,
|
|
35
|
+
dataID = _a.dataID;
|
|
36
|
+
var data = this._traverse(node, dataID, null);
|
|
37
|
+
return {
|
|
38
|
+
data: data,
|
|
39
|
+
seenRecords: this._seenRecords,
|
|
40
|
+
selector: this._selector
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
RelayReader.prototype._traverse = function (node, dataID, prevData) {
|
|
44
|
+
if (dataID == null) {
|
|
45
|
+
return dataID;
|
|
46
|
+
}
|
|
47
|
+
var record = this._recordSource.get(dataID);
|
|
48
|
+
this._seenRecords.add(dataID);
|
|
49
|
+
if (record == null) {
|
|
50
|
+
return record;
|
|
51
|
+
}
|
|
52
|
+
var data = prevData || {};
|
|
53
|
+
this._traverseSelections(node.selections, record, data);
|
|
54
|
+
return data;
|
|
55
|
+
};
|
|
56
|
+
RelayReader.prototype._traverseSelections = function (selections, record, data) {
|
|
57
|
+
var _this = this;
|
|
58
|
+
var _loop_1 = function (i) {
|
|
59
|
+
var selection = selections[i];
|
|
60
|
+
var name_1 = selection.name;
|
|
61
|
+
var prevData = data[name_1];
|
|
62
|
+
var value = null;
|
|
63
|
+
if (selection.kind == RelayStoreUtils_1.LINKED_FIELD) {
|
|
64
|
+
if (selection.plural) {
|
|
65
|
+
var ids = RelayModernRecord_1.RelayModernRecord.getLinkedRecordIDs(record, name_1);
|
|
66
|
+
if (ids != null) {
|
|
67
|
+
var linkedArray_1 = prevData || [];
|
|
68
|
+
ids.forEach(function (linkedID, nextIndex) {
|
|
69
|
+
var prevItem = linkedArray_1[nextIndex];
|
|
70
|
+
linkedArray_1[nextIndex] = _this._traverse(selection, linkedID, prevItem);
|
|
71
|
+
});
|
|
72
|
+
value = linkedArray_1;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
var id = RelayModernRecord_1.RelayModernRecord.getLinkedRecordID(record, name_1);
|
|
76
|
+
value = this_1._traverse(selection, id, prevData);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
// relay-forms, now default scalar
|
|
80
|
+
value = RelayModernRecord_1.RelayModernRecord.getValue(record, name_1);
|
|
81
|
+
//this._readScalar(selection, record, data);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
data[name_1] = value;
|
|
85
|
+
};
|
|
86
|
+
var this_1 = this;
|
|
87
|
+
for (var i = 0; i < selections.length; i++) {
|
|
88
|
+
_loop_1(i);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return RelayReader;
|
|
92
|
+
}();
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
import { RelayRecordSourceMutator } from './RelayRecordSourceMutator';
|
|
11
|
+
import { RecordProxy } from './RelayTypes';
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*
|
|
15
|
+
* A helper class for manipulating a given record from a record source via an
|
|
16
|
+
* imperative/OO-style API.
|
|
17
|
+
*/
|
|
18
|
+
export declare class RelayRecordProxy implements RecordProxy {
|
|
19
|
+
_dataID: any;
|
|
20
|
+
_mutator: RelayRecordSourceMutator;
|
|
21
|
+
_source: any;
|
|
22
|
+
constructor(source: any, mutator: any, dataID: any);
|
|
23
|
+
getDataID(): string;
|
|
24
|
+
setValue(value: any, name: string): this;
|
|
25
|
+
setLinkedRecord(record: RecordProxy, name: string): this;
|
|
26
|
+
getLinkedRecords(name: string): Array<RecordProxy | null | undefined> | null | undefined;
|
|
27
|
+
setLinkedRecords(records: any, name: string): RecordProxy;
|
|
28
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
* @flow strict-local
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*
|
|
20
|
+
* A helper class for manipulating a given record from a record source via an
|
|
21
|
+
* imperative/OO-style API.
|
|
22
|
+
*/
|
|
23
|
+
var RelayRecordProxy = /** @class */function () {
|
|
24
|
+
function RelayRecordProxy(source, mutator, dataID) {
|
|
25
|
+
this._dataID = dataID;
|
|
26
|
+
this._mutator = mutator;
|
|
27
|
+
this._source = source;
|
|
28
|
+
}
|
|
29
|
+
RelayRecordProxy.prototype.getDataID = function () {
|
|
30
|
+
return this._dataID;
|
|
31
|
+
};
|
|
32
|
+
RelayRecordProxy.prototype.setValue = function (value, name) {
|
|
33
|
+
this._mutator.setValue(this._dataID, name, value);
|
|
34
|
+
return this;
|
|
35
|
+
};
|
|
36
|
+
RelayRecordProxy.prototype.setLinkedRecord = function (record, name) {
|
|
37
|
+
var linkedID = record.getDataID();
|
|
38
|
+
this._mutator.setLinkedRecordID(this._dataID, name, linkedID);
|
|
39
|
+
return this;
|
|
40
|
+
};
|
|
41
|
+
RelayRecordProxy.prototype.getLinkedRecords = function (name) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
var linkedIDs = this._mutator.getLinkedRecordIDs(this._dataID, name);
|
|
44
|
+
if (linkedIDs == null) {
|
|
45
|
+
return linkedIDs;
|
|
46
|
+
}
|
|
47
|
+
return linkedIDs.map(function (linkedID) {
|
|
48
|
+
return linkedID != null ? _this._source.get(linkedID) : linkedID;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
RelayRecordProxy.prototype.setLinkedRecords = function (records, name) {
|
|
52
|
+
var linkedIDs = records.map(function (record) {
|
|
53
|
+
return record && record.getDataID();
|
|
54
|
+
});
|
|
55
|
+
this._mutator.setLinkedRecordIDs(this._dataID, name, linkedIDs);
|
|
56
|
+
return this;
|
|
57
|
+
};
|
|
58
|
+
return RelayRecordProxy;
|
|
59
|
+
}();
|
|
60
|
+
exports.RelayRecordProxy = RelayRecordProxy;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
import { MutableRecordSource, Record, RecordState } from './RelayTypes';
|
|
11
|
+
/**
|
|
12
|
+
* An implementation of the `MutableRecordSource` interface (defined in
|
|
13
|
+
* `RelayStoreTypes`) that holds all records in memory (JS Map).
|
|
14
|
+
*/
|
|
15
|
+
export declare class RelayRecordSource implements MutableRecordSource {
|
|
16
|
+
_records: any;
|
|
17
|
+
constructor(records?: any);
|
|
18
|
+
clear(): void;
|
|
19
|
+
delete(dataID: any): void;
|
|
20
|
+
get(dataID: any): Record | null | undefined;
|
|
21
|
+
getRecordIDs(): Array<string>;
|
|
22
|
+
getStatus(dataID: any): RecordState;
|
|
23
|
+
has(dataID: any): boolean;
|
|
24
|
+
remove(dataID: any): void;
|
|
25
|
+
set(dataID: any, record: any): void;
|
|
26
|
+
size(): number;
|
|
27
|
+
toJSON(): any;
|
|
28
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @flow strict-local
|
|
10
|
+
* @format
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
var RelayStoreUtils_1 = require("./RelayStoreUtils");
|
|
16
|
+
var EXISTENT = RelayStoreUtils_1.RelayRecordState.EXISTENT,
|
|
17
|
+
NONEXISTENT = RelayStoreUtils_1.RelayRecordState.NONEXISTENT,
|
|
18
|
+
UNKNOWN = RelayStoreUtils_1.RelayRecordState.UNKNOWN;
|
|
19
|
+
/**
|
|
20
|
+
* An implementation of the `MutableRecordSource` interface (defined in
|
|
21
|
+
* `RelayStoreTypes`) that holds all records in memory (JS Map).
|
|
22
|
+
*/
|
|
23
|
+
var RelayRecordSource = /** @class */function () {
|
|
24
|
+
function RelayRecordSource(records) {
|
|
25
|
+
var _this = this;
|
|
26
|
+
this._records = new Map();
|
|
27
|
+
if (records != null) {
|
|
28
|
+
Object.keys(records).forEach(function (key) {
|
|
29
|
+
_this._records.set(key, records[key]);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
RelayRecordSource.prototype.clear = function () {
|
|
34
|
+
this._records = new Map();
|
|
35
|
+
};
|
|
36
|
+
RelayRecordSource.prototype.delete = function (dataID) {
|
|
37
|
+
this._records.set(dataID, null);
|
|
38
|
+
};
|
|
39
|
+
RelayRecordSource.prototype.get = function (dataID) {
|
|
40
|
+
return this._records.get(dataID);
|
|
41
|
+
};
|
|
42
|
+
RelayRecordSource.prototype.getRecordIDs = function () {
|
|
43
|
+
return Array.from(this._records.keys());
|
|
44
|
+
};
|
|
45
|
+
RelayRecordSource.prototype.getStatus = function (dataID) {
|
|
46
|
+
if (!this._records.has(dataID)) {
|
|
47
|
+
return UNKNOWN;
|
|
48
|
+
}
|
|
49
|
+
return this._records.get(dataID) == null ? NONEXISTENT : EXISTENT;
|
|
50
|
+
};
|
|
51
|
+
RelayRecordSource.prototype.has = function (dataID) {
|
|
52
|
+
return this._records.has(dataID);
|
|
53
|
+
};
|
|
54
|
+
RelayRecordSource.prototype.remove = function (dataID) {
|
|
55
|
+
this._records.delete(dataID);
|
|
56
|
+
};
|
|
57
|
+
RelayRecordSource.prototype.set = function (dataID, record) {
|
|
58
|
+
this._records.set(dataID, record);
|
|
59
|
+
};
|
|
60
|
+
RelayRecordSource.prototype.size = function () {
|
|
61
|
+
return this._records.size;
|
|
62
|
+
};
|
|
63
|
+
RelayRecordSource.prototype.toJSON = function () {
|
|
64
|
+
var obj = {};
|
|
65
|
+
for (var _i = 0, _a = this._records.entries(); _i < _a.length; _i++) {
|
|
66
|
+
var _b = _a[_i],
|
|
67
|
+
key = _b[0],
|
|
68
|
+
value = _b[1];
|
|
69
|
+
obj[key] = value;
|
|
70
|
+
}
|
|
71
|
+
return obj;
|
|
72
|
+
};
|
|
73
|
+
return RelayRecordSource;
|
|
74
|
+
}();
|
|
75
|
+
exports.RelayRecordSource = RelayRecordSource;
|
|
@@ -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-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
import { MutableRecordSource, Record, RecordSource } from './RelayTypes';
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*
|
|
14
|
+
* Wrapper API that is an amalgam of the `RelayModernRecord` API and
|
|
15
|
+
* `MutableRecordSource` interface, implementing copy-on-write semantics for records
|
|
16
|
+
* in a record source.
|
|
17
|
+
*
|
|
18
|
+
* Modifications are applied to fresh copies of records:
|
|
19
|
+
* - Records in `base` are never modified.
|
|
20
|
+
* - Modifications cause a fresh version of a record to be created in `sink`.
|
|
21
|
+
* These sink records contain only modified fields.
|
|
22
|
+
*/
|
|
23
|
+
export declare class RelayRecordSourceMutator {
|
|
24
|
+
__sources: Array<RecordSource>;
|
|
25
|
+
_base: RecordSource;
|
|
26
|
+
_sink: MutableRecordSource;
|
|
27
|
+
constructor(base: any, sink: any);
|
|
28
|
+
_getSinkRecord(dataID: any): Record;
|
|
29
|
+
create(dataID: any): void;
|
|
30
|
+
delete(dataID: any): void;
|
|
31
|
+
getStatus(dataID: any): "EXISTENT" | "NONEXISTENT" | "UNKNOWN";
|
|
32
|
+
setValue(dataID: any, storageKey: string, value: any): void;
|
|
33
|
+
setLinkedRecordID(dataID: any, storageKey: any, linkedID: any): void;
|
|
34
|
+
getLinkedRecordIDs(dataID: any, storageKey: string): any;
|
|
35
|
+
setLinkedRecordIDs(dataID: any, storageKey: string, linkedIDs: any): void;
|
|
36
|
+
}
|