rescript-relay 0.0.0-autocodesplit-09ee6f6c
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/CHANGELOG.md +942 -0
- package/README.md +111 -0
- package/cli/cli.js +472 -0
- package/compiler.js +11 -0
- package/package.json +65 -0
- package/postinstall.js +189 -0
- package/ppx-linux +0 -0
- package/ppx-macos-arm64 +0 -0
- package/ppx-macos-latest +0 -0
- package/ppx-windows-latest +0 -0
- package/relay-compiler-linux-musl/relay +0 -0
- package/relay-compiler-linux-x64/relay +0 -0
- package/relay-compiler-macos-arm64/relay +0 -0
- package/relay-compiler-macos-x64/relay +0 -0
- package/relay-compiler-win-x64/relay.exe +0 -0
- package/rescript.json +19 -0
- package/src/ReactDOMExperimental.bs.js +23 -0
- package/src/ReactDOMExperimental.res +16 -0
- package/src/ReactExperimental.bs.js +23 -0
- package/src/ReactExperimental.res +21 -0
- package/src/ReactExperimental.resi +18 -0
- package/src/RescriptRelay.bs.js +329 -0
- package/src/RescriptRelay.res +858 -0
- package/src/RescriptRelay.resi +897 -0
- package/src/RescriptRelayUtils.bs.js +76 -0
- package/src/RescriptRelayUtils.res +89 -0
- package/src/RescriptRelayUtils.resi +36 -0
- package/src/RescriptRelay_Fragment.bs.js +122 -0
- package/src/RescriptRelay_Fragment.res +243 -0
- package/src/RescriptRelay_Fragment.resi +85 -0
- package/src/RescriptRelay_Internal.bs.js +102 -0
- package/src/RescriptRelay_Internal.res +71 -0
- package/src/RescriptRelay_Internal.resi +20 -0
- package/src/RescriptRelay_Mutation.bs.js +57 -0
- package/src/RescriptRelay_Mutation.res +144 -0
- package/src/RescriptRelay_Mutation.resi +52 -0
- package/src/RescriptRelay_Query.bs.js +101 -0
- package/src/RescriptRelay_Query.res +177 -0
- package/src/RescriptRelay_Query.resi +62 -0
- package/src/RescriptRelay_RelayResolvers.bs.js +13 -0
- package/src/RescriptRelay_RelayResolvers.res +21 -0
- package/src/RescriptRelay_RelayResolvers.resi +10 -0
- package/src/RescriptRelay_Subscriptions.bs.js +24 -0
- package/src/RescriptRelay_Subscriptions.res +50 -0
- package/src/RescriptRelay_Subscriptions.resi +14 -0
- package/src/utils.js +418 -0
- package/src/utils.mjs +418 -0
package/src/utils.js
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
function getNewObj(maybeNewObj, currentObj) {
|
|
2
|
+
return maybeNewObj || Object.assign({}, currentObj);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function getPathName(path) {
|
|
6
|
+
return path.join("_");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function makeNewPath(currentPath, newKeys) {
|
|
10
|
+
return [].concat(currentPath, newKeys);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getTypename(v) {
|
|
14
|
+
if (v != null && typeof v === "object" && v.__typename != null) {
|
|
15
|
+
return v.__typename;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function unwrapInputUnion(obj) {
|
|
20
|
+
if (obj != null && typeof obj === "object" && "__$inputUnion" in obj) {
|
|
21
|
+
return {
|
|
22
|
+
[obj["__$inputUnion"]]: obj["_0"],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return obj;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Runs on each object in the tree and follows the provided instructions
|
|
31
|
+
* to apply transforms etc.
|
|
32
|
+
*/
|
|
33
|
+
function traverse(
|
|
34
|
+
fullInstructionMap,
|
|
35
|
+
currentPath,
|
|
36
|
+
currentObj,
|
|
37
|
+
instructionMap,
|
|
38
|
+
converters,
|
|
39
|
+
nullableValue,
|
|
40
|
+
instructionPaths,
|
|
41
|
+
addFragmentOnRoot
|
|
42
|
+
) {
|
|
43
|
+
// We lazily set up a new object for each "level", as we don't want to mutate
|
|
44
|
+
// what comes back from the Relay store, and nor do we want to create new
|
|
45
|
+
// objects unless we need to. And we only need to when we need to change
|
|
46
|
+
// something.
|
|
47
|
+
var newObj;
|
|
48
|
+
|
|
49
|
+
if (addFragmentOnRoot) {
|
|
50
|
+
newObj = getNewObj(newObj, currentObj);
|
|
51
|
+
newObj.fragmentRefs = Object.assign({}, newObj);
|
|
52
|
+
newObj.updatableFragmentRefs = newObj.fragmentRefs;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (var key in currentObj) {
|
|
56
|
+
// Ensure we don't move into internal properties coming from Relay, with the
|
|
57
|
+
// exception of the few names allowed to start with double underscores
|
|
58
|
+
// ("__typename" and "__id"), and any Relay provided variables.
|
|
59
|
+
if (
|
|
60
|
+
key.startsWith("__") &&
|
|
61
|
+
key !== "__typename" &&
|
|
62
|
+
key !== "__id" &&
|
|
63
|
+
!key.startsWith("__relay_internal")
|
|
64
|
+
)
|
|
65
|
+
continue;
|
|
66
|
+
|
|
67
|
+
var isUnion = false;
|
|
68
|
+
var originalValue = currentObj[key];
|
|
69
|
+
|
|
70
|
+
// Instructions are stored by the path in the object where they apply
|
|
71
|
+
var thisPath = makeNewPath(currentPath, [key]);
|
|
72
|
+
var path = getPathName(thisPath);
|
|
73
|
+
|
|
74
|
+
var instructions = instructionMap[path] || {};
|
|
75
|
+
|
|
76
|
+
if (currentObj[key] == null) {
|
|
77
|
+
newObj = getNewObj(newObj, currentObj);
|
|
78
|
+
newObj[key] = nullableValue;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
var shouldConvertRootObj =
|
|
83
|
+
typeof instructions["r"] === "string" &&
|
|
84
|
+
fullInstructionMap[instructions["r"]];
|
|
85
|
+
|
|
86
|
+
var shouldAddFragmentFn = instructions["f"] === "";
|
|
87
|
+
|
|
88
|
+
var shouldConvertEnum =
|
|
89
|
+
typeof instructions["e"] === "string" && !!converters[instructions["e"]];
|
|
90
|
+
|
|
91
|
+
// This is true for non-arrays that are to be converted
|
|
92
|
+
var shouldConvertCustomField =
|
|
93
|
+
typeof instructions["c"] === "string" && !!converters[instructions["c"]];
|
|
94
|
+
|
|
95
|
+
// This is true for arrays that are to be converted. This and the above
|
|
96
|
+
// won't be true at the same time.
|
|
97
|
+
var shouldConvertCustomFieldArray =
|
|
98
|
+
typeof instructions["ca"] === "string" &&
|
|
99
|
+
!!converters[instructions["ca"]];
|
|
100
|
+
|
|
101
|
+
// Special case when this is a custom field that's an array. Ensures we
|
|
102
|
+
// don't accidentally move into the array when we're not supposed to.
|
|
103
|
+
if (shouldConvertCustomFieldArray && Array.isArray(currentObj[key])) {
|
|
104
|
+
newObj = getNewObj(newObj, currentObj);
|
|
105
|
+
newObj[key] = currentObj[key].map(converters[instructions["ca"]]);
|
|
106
|
+
return newObj;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var shouldBlockTraversal = typeof instructions["b"] === "string";
|
|
110
|
+
var allowGoingIntoArray = shouldBlockTraversal
|
|
111
|
+
? instructions["b"] === "a"
|
|
112
|
+
: true;
|
|
113
|
+
|
|
114
|
+
if (shouldBlockTraversal && !allowGoingIntoArray) {
|
|
115
|
+
newObj = getNewObj(newObj, currentObj);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
var shouldConvertUnion =
|
|
120
|
+
typeof instructions["u"] === "string" && !!converters[instructions["u"]];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Handle arrays
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
// Special case when this is a custom field that's an array. Ensures we
|
|
127
|
+
// don't accidentally move into the array when we're not supposed to.
|
|
128
|
+
if (shouldConvertCustomField && Array.isArray(currentObj[key])) {
|
|
129
|
+
newObj = getNewObj(newObj, currentObj);
|
|
130
|
+
newObj[key] = converters[instructions["c"]](originalValue);
|
|
131
|
+
return newObj;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (Array.isArray(currentObj[key])) {
|
|
135
|
+
newObj = getNewObj(newObj, currentObj);
|
|
136
|
+
newObj[key] = currentObj[key].map(function (v) {
|
|
137
|
+
if (v == null) {
|
|
138
|
+
return nullableValue;
|
|
139
|
+
}
|
|
140
|
+
if (shouldConvertRootObj) {
|
|
141
|
+
return traverser(
|
|
142
|
+
unwrapInputUnion(v),
|
|
143
|
+
fullInstructionMap,
|
|
144
|
+
converters,
|
|
145
|
+
nullableValue,
|
|
146
|
+
instructions["r"]
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (shouldConvertEnum) {
|
|
151
|
+
return converters[instructions["e"]](v);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (shouldConvertCustomField) {
|
|
155
|
+
return converters[instructions["c"]](v);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (shouldConvertUnion && v != null && typeof v === "object") {
|
|
159
|
+
var typename = getTypename(v);
|
|
160
|
+
|
|
161
|
+
if (typename != null) {
|
|
162
|
+
isUnion = true;
|
|
163
|
+
var unionObj = v;
|
|
164
|
+
|
|
165
|
+
// Means we're wrapping, and this will be a ReScript value.
|
|
166
|
+
if (nullableValue === null) {
|
|
167
|
+
// Convert it back to a flat JS value
|
|
168
|
+
unionObj = converters[instructions["u"]](v);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
var newPath = makeNewPath(currentPath, [key, typename]);
|
|
172
|
+
|
|
173
|
+
var unionRootHasFragment =
|
|
174
|
+
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
175
|
+
|
|
176
|
+
var traversedValue = traverse(
|
|
177
|
+
fullInstructionMap,
|
|
178
|
+
newPath,
|
|
179
|
+
unionObj,
|
|
180
|
+
instructionMap,
|
|
181
|
+
converters,
|
|
182
|
+
nullableValue,
|
|
183
|
+
instructionPaths,
|
|
184
|
+
unionRootHasFragment
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
// Undefined means we're going from JS to ReScript, in which case we
|
|
188
|
+
// need to run the conversion here rather than earlier.
|
|
189
|
+
return nullableValue === undefined
|
|
190
|
+
? converters[instructions["u"]](traversedValue)
|
|
191
|
+
: traversedValue;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (shouldAddFragmentFn && typeof v === "object" && !Array.isArray(v)) {
|
|
196
|
+
var objWithFragmentFn = Object.assign({}, v);
|
|
197
|
+
objWithFragmentFn.fragmentRefs = Object.assign({}, objWithFragmentFn);
|
|
198
|
+
objWithFragmentFn.updatableFragmentRefs =
|
|
199
|
+
objWithFragmentFn.fragmentRefs;
|
|
200
|
+
return objWithFragmentFn;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return v;
|
|
204
|
+
});
|
|
205
|
+
} else {
|
|
206
|
+
/**
|
|
207
|
+
* Handle normal values.
|
|
208
|
+
*/
|
|
209
|
+
var v = currentObj[key];
|
|
210
|
+
|
|
211
|
+
if (shouldConvertRootObj) {
|
|
212
|
+
newObj = getNewObj(newObj, currentObj);
|
|
213
|
+
newObj[key] = traverser(
|
|
214
|
+
unwrapInputUnion(v),
|
|
215
|
+
fullInstructionMap,
|
|
216
|
+
converters,
|
|
217
|
+
nullableValue,
|
|
218
|
+
instructions["r"]
|
|
219
|
+
);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (shouldConvertEnum) {
|
|
224
|
+
newObj = getNewObj(newObj, currentObj);
|
|
225
|
+
newObj[key] = converters[instructions["e"]](v);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (shouldConvertCustomField) {
|
|
229
|
+
newObj = getNewObj(newObj, currentObj);
|
|
230
|
+
newObj[key] = converters[instructions["c"]](v);
|
|
231
|
+
// Ensure that the custom scalar value itself isn't traversed more.
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (shouldConvertUnion && v != null && typeof v === "object") {
|
|
236
|
+
var typename = getTypename(v);
|
|
237
|
+
|
|
238
|
+
if (typename != null) {
|
|
239
|
+
isUnion = true;
|
|
240
|
+
var unionObj = v;
|
|
241
|
+
|
|
242
|
+
// Means we're wrapping, and this will be a ReScript value.
|
|
243
|
+
if (nullableValue === null) {
|
|
244
|
+
// Convert it back to a flat JS value
|
|
245
|
+
unionObj = converters[instructions["u"]](v);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
var newPath = makeNewPath(currentPath, [key, typename]);
|
|
249
|
+
|
|
250
|
+
var unionRootHasFragment =
|
|
251
|
+
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
252
|
+
|
|
253
|
+
var traversedValue = traverse(
|
|
254
|
+
fullInstructionMap,
|
|
255
|
+
newPath,
|
|
256
|
+
unionObj,
|
|
257
|
+
instructionMap,
|
|
258
|
+
converters,
|
|
259
|
+
nullableValue,
|
|
260
|
+
instructionPaths,
|
|
261
|
+
unionRootHasFragment
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
newObj = getNewObj(newObj, currentObj);
|
|
265
|
+
|
|
266
|
+
newObj[key] =
|
|
267
|
+
// Undefined means we're going from JS to ReScript, in which case we
|
|
268
|
+
// need to run the conversion here rather than earlier.
|
|
269
|
+
nullableValue === undefined
|
|
270
|
+
? converters[instructions["u"]](traversedValue)
|
|
271
|
+
: traversedValue;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (shouldAddFragmentFn && typeof v === "object" && !Array.isArray(v)) {
|
|
276
|
+
newObj = getNewObj(newObj, currentObj);
|
|
277
|
+
var objWithFragmentFn = Object.assign({}, v);
|
|
278
|
+
objWithFragmentFn.fragmentRefs = Object.assign({}, objWithFragmentFn);
|
|
279
|
+
objWithFragmentFn.updatableFragmentRefs =
|
|
280
|
+
objWithFragmentFn.fragmentRefs;
|
|
281
|
+
|
|
282
|
+
newObj[key] = objWithFragmentFn;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (originalValue != null && !isUnion) {
|
|
287
|
+
var nextObj = (newObj && newObj[key]) || currentObj[key];
|
|
288
|
+
|
|
289
|
+
if (typeof nextObj === "object" && !Array.isArray(originalValue)) {
|
|
290
|
+
var traversedObj = traverse(
|
|
291
|
+
fullInstructionMap,
|
|
292
|
+
thisPath,
|
|
293
|
+
nextObj,
|
|
294
|
+
instructionMap,
|
|
295
|
+
converters,
|
|
296
|
+
nullableValue,
|
|
297
|
+
instructionPaths
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
if (traversedObj !== nextObj) {
|
|
301
|
+
newObj = getNewObj(newObj, currentObj);
|
|
302
|
+
newObj[key] = traversedObj;
|
|
303
|
+
}
|
|
304
|
+
} else if (Array.isArray(originalValue) && !shouldBlockTraversal) {
|
|
305
|
+
newObj = getNewObj(newObj, currentObj);
|
|
306
|
+
newObj[key] = nextObj.map(function (o) {
|
|
307
|
+
if (typeof o === "object" && o != null && !Array.isArray(o)) {
|
|
308
|
+
return traverse(
|
|
309
|
+
fullInstructionMap,
|
|
310
|
+
thisPath,
|
|
311
|
+
o,
|
|
312
|
+
instructionMap,
|
|
313
|
+
converters,
|
|
314
|
+
nullableValue,
|
|
315
|
+
instructionPaths
|
|
316
|
+
);
|
|
317
|
+
} else if (o == null) {
|
|
318
|
+
return nullableValue;
|
|
319
|
+
} else {
|
|
320
|
+
return o;
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return newObj || currentObj;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* This function takes an object (snapshot from the Relay store) and applies a
|
|
332
|
+
* set of conversions deeply on the object (instructions coming from "converters"-prop).
|
|
333
|
+
* It converts nullable values either to null or undefined, and it wraps/unwraps enums
|
|
334
|
+
* and unions.
|
|
335
|
+
*
|
|
336
|
+
* It preserves structural integrity where possible, and return new objects where properties
|
|
337
|
+
* have been modified.
|
|
338
|
+
*/
|
|
339
|
+
function traverser(
|
|
340
|
+
root,
|
|
341
|
+
instructionMaps_,
|
|
342
|
+
theConverters,
|
|
343
|
+
nullableValue,
|
|
344
|
+
rootObjectKey
|
|
345
|
+
) {
|
|
346
|
+
if (!root) {
|
|
347
|
+
return nullableValue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
var instructionMaps = instructionMaps_ || {};
|
|
351
|
+
var instructionMap = instructionMaps[rootObjectKey || "__root"] || {};
|
|
352
|
+
|
|
353
|
+
var converters = theConverters == null ? {} : theConverters;
|
|
354
|
+
var instructionPaths = Object.keys(instructionMap);
|
|
355
|
+
|
|
356
|
+
// We'll add the fragmentRefs reference to the root if needed here.
|
|
357
|
+
var fragmentsOnRoot = (instructionMap[""] || {}).f === "";
|
|
358
|
+
var unionRootConverter = converters[(instructionMap[""] || {}).u];
|
|
359
|
+
|
|
360
|
+
if (Array.isArray(root)) {
|
|
361
|
+
return root.map(function (v) {
|
|
362
|
+
if (v == null) {
|
|
363
|
+
return nullableValue;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
var n = [];
|
|
367
|
+
|
|
368
|
+
// Since a root level union is treated as a "new root level", we'll need
|
|
369
|
+
// to do a separate check here of whether there's a fragment on the root
|
|
370
|
+
// we need to account for, or not.
|
|
371
|
+
if (unionRootConverter != null) {
|
|
372
|
+
n = [v.__typename];
|
|
373
|
+
fragmentsOnRoot = (instructionMap[v.__typename] || {}).f === "";
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
var traversedObj = traverse(
|
|
377
|
+
instructionMaps,
|
|
378
|
+
n,
|
|
379
|
+
v,
|
|
380
|
+
instructionMap,
|
|
381
|
+
converters,
|
|
382
|
+
nullableValue,
|
|
383
|
+
instructionPaths,
|
|
384
|
+
fragmentsOnRoot
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
return unionRootConverter != null
|
|
388
|
+
? unionRootConverter(traversedObj)
|
|
389
|
+
: traversedObj;
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
var newObj = Object.assign({}, root);
|
|
394
|
+
|
|
395
|
+
var n = [];
|
|
396
|
+
|
|
397
|
+
// Same as in the union array check above - if there's a fragment in the new
|
|
398
|
+
// root created by the union, we need to account for that separately here.
|
|
399
|
+
if (unionRootConverter != null) {
|
|
400
|
+
n = [newObj.__typename];
|
|
401
|
+
fragmentsOnRoot = (instructionMap[newObj.__typename] || {}).f === "";
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
var v = traverse(
|
|
405
|
+
instructionMaps,
|
|
406
|
+
n,
|
|
407
|
+
newObj,
|
|
408
|
+
instructionMap,
|
|
409
|
+
converters,
|
|
410
|
+
nullableValue,
|
|
411
|
+
instructionPaths,
|
|
412
|
+
fragmentsOnRoot
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
return unionRootConverter != null ? unionRootConverter(v) : v;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
module.exports = { traverser };
|