rescript-relay 0.0.0-cli-687699fd → 0.0.0-linux-musl-d5435e23
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 +141 -0
- package/README.md +7 -11
- package/bsconfig.json +1 -1
- package/cli/cli.js +29 -35
- package/compiler.js +11 -0
- package/package.json +23 -23
- package/postinstall.js +43 -13
- package/ppx-darwin +0 -0
- package/ppx-linux +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/src/ReactDOMExperimental.bs.js +19 -1
- package/src/ReactDOMExperimental.res +16 -3
- package/src/ReactExperimental.bs.js +1 -16
- package/src/ReactExperimental.res +4 -20
- package/src/RescriptRelay.bs.js +32 -21
- package/src/RescriptRelay.res +76 -31
- package/src/RescriptRelay.resi +66 -39
- package/src/experimental-router/RescriptRelayRouter.bs.js +15 -4
- package/src/experimental-router/RescriptRelayRouter.res +11 -2
- package/src/experimental-router/RescriptRelayRouter.resi +2 -0
- package/src/utils.js +182 -190
- package/src/utils.mjs +339 -0
- package/bin-darwin +0 -0
- package/bin-linux +0 -0
- package/compiler/compiler-cli.js +0 -54
- package/language-plugin/dist/index.js +0 -1
package/src/utils.js
CHANGED
|
@@ -24,6 +24,10 @@ function traverse(
|
|
|
24
24
|
instructionPaths,
|
|
25
25
|
addFragmentOnRoot
|
|
26
26
|
) {
|
|
27
|
+
// We lazily set up a new object for each "level", as we don't want to mutate
|
|
28
|
+
// what comes back from the Relay store, and nor do we want to create new
|
|
29
|
+
// objects unless we need to. And we only need to when we need to change
|
|
30
|
+
// something.
|
|
27
31
|
var newObj;
|
|
28
32
|
|
|
29
33
|
if (addFragmentOnRoot) {
|
|
@@ -39,193 +43,168 @@ function traverse(
|
|
|
39
43
|
var thisPath = makeNewPath(currentPath, [key]);
|
|
40
44
|
var path = getPathName(thisPath);
|
|
41
45
|
|
|
42
|
-
var instructions = instructionMap[path];
|
|
46
|
+
var instructions = instructionMap[path] || {};
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (currentObj[key] == null) {
|
|
49
|
+
newObj = getNewObj(newObj, currentObj);
|
|
50
|
+
newObj[key] = nullableValue;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
newObj = getNewObj(newObj, currentObj);
|
|
53
|
-
newObj[key] = nullableValue;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
var shouldConvertRootObj =
|
|
57
|
-
typeof instructions["r"] === "string" &&
|
|
58
|
-
fullInstructionMap[instructions["r"]];
|
|
54
|
+
var shouldConvertRootObj =
|
|
55
|
+
typeof instructions["r"] === "string" &&
|
|
56
|
+
fullInstructionMap[instructions["r"]];
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
var shouldAddFragmentFn = instructions["f"] === "";
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
!!converters[instructions["e"]];
|
|
60
|
+
var shouldConvertEnum =
|
|
61
|
+
typeof instructions["e"] === "string" && !!converters[instructions["e"]];
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
!!converters[instructions["c"]];
|
|
63
|
+
var shouldConvertCustomField =
|
|
64
|
+
typeof instructions["c"] === "string" && !!converters[instructions["c"]];
|
|
69
65
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
!!converters[instructions["u"]];
|
|
66
|
+
var shouldConvertUnion =
|
|
67
|
+
typeof instructions["u"] === "string" && !!converters[instructions["u"]];
|
|
73
68
|
|
|
74
|
-
|
|
69
|
+
var isTopLevelNodeField = typeof instructions["tnf"] === "string";
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (shouldConvertRootObj) {
|
|
87
|
-
return traverser(
|
|
88
|
-
v,
|
|
89
|
-
fullInstructionMap,
|
|
90
|
-
converters,
|
|
91
|
-
nullableValue,
|
|
92
|
-
instructions["r"]
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (shouldConvertEnum) {
|
|
97
|
-
return converters[instructions["e"]](v);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (shouldConvertCustomField) {
|
|
101
|
-
return converters[instructions["c"]](v);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
shouldConvertUnion &&
|
|
106
|
-
typeof v === "object" &&
|
|
107
|
-
typeof v.__typename === "string"
|
|
108
|
-
) {
|
|
109
|
-
isUnion = true;
|
|
110
|
-
|
|
111
|
-
var newPath = makeNewPath(currentPath, [
|
|
112
|
-
key,
|
|
113
|
-
v.__typename.toLowerCase(),
|
|
114
|
-
]);
|
|
115
|
-
|
|
116
|
-
var unionRootHasFragment =
|
|
117
|
-
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
118
|
-
|
|
119
|
-
var traversedValue = traverse(
|
|
120
|
-
fullInstructionMap,
|
|
121
|
-
newPath,
|
|
122
|
-
v,
|
|
123
|
-
instructionMap,
|
|
124
|
-
converters,
|
|
125
|
-
nullableValue,
|
|
126
|
-
instructionPaths,
|
|
127
|
-
unionRootHasFragment
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
return converters[instructions["u"]](traversedValue);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (shouldAddFragmentFn && typeof v === "object") {
|
|
134
|
-
var objWithFragmentFn = Object.assign({}, v);
|
|
135
|
-
objWithFragmentFn.fragmentRefs = Object.assign(
|
|
136
|
-
{},
|
|
137
|
-
objWithFragmentFn
|
|
138
|
-
);
|
|
139
|
-
return objWithFragmentFn;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return v;
|
|
143
|
-
});
|
|
144
|
-
} else {
|
|
145
|
-
/**
|
|
146
|
-
* Handle normal values.
|
|
147
|
-
*/
|
|
148
|
-
var v = currentObj[key];
|
|
149
|
-
|
|
150
|
-
if (shouldConvertRootObj) {
|
|
151
|
-
newObj = getNewObj(newObj, currentObj);
|
|
152
|
-
newObj[key] = traverser(
|
|
153
|
-
v,
|
|
154
|
-
fullInstructionMap,
|
|
155
|
-
converters,
|
|
156
|
-
nullableValue,
|
|
157
|
-
instructions["r"]
|
|
158
|
-
);
|
|
159
|
-
}
|
|
71
|
+
/**
|
|
72
|
+
* Handle arrays
|
|
73
|
+
*/
|
|
74
|
+
if (Array.isArray(currentObj[key])) {
|
|
75
|
+
newObj = getNewObj(newObj, currentObj);
|
|
76
|
+
newObj[key] = currentObj[key].map(function (v) {
|
|
77
|
+
if (v == null) {
|
|
78
|
+
return nullableValue;
|
|
79
|
+
}
|
|
160
80
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
81
|
+
if (shouldConvertRootObj) {
|
|
82
|
+
return traverser(
|
|
83
|
+
v,
|
|
84
|
+
fullInstructionMap,
|
|
85
|
+
converters,
|
|
86
|
+
nullableValue,
|
|
87
|
+
instructions["r"]
|
|
88
|
+
);
|
|
89
|
+
}
|
|
171
90
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
91
|
+
if (shouldConvertEnum) {
|
|
92
|
+
return converters[instructions["e"]](v);
|
|
93
|
+
}
|
|
176
94
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
95
|
+
if (shouldConvertCustomField) {
|
|
96
|
+
return converters[instructions["c"]](v);
|
|
97
|
+
}
|
|
181
98
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
99
|
+
if (
|
|
100
|
+
shouldConvertUnion &&
|
|
101
|
+
typeof v === "object" &&
|
|
102
|
+
typeof v.__typename === "string"
|
|
103
|
+
) {
|
|
104
|
+
isUnion = true;
|
|
105
|
+
|
|
106
|
+
var newPath = makeNewPath(currentPath, [key, v.__typename]);
|
|
107
|
+
|
|
108
|
+
var unionRootHasFragment =
|
|
109
|
+
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
110
|
+
|
|
111
|
+
var traversedValue = traverse(
|
|
112
|
+
fullInstructionMap,
|
|
113
|
+
newPath,
|
|
114
|
+
v,
|
|
115
|
+
instructionMap,
|
|
116
|
+
converters,
|
|
117
|
+
nullableValue,
|
|
118
|
+
instructionPaths,
|
|
119
|
+
unionRootHasFragment
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return converters[instructions["u"]](traversedValue);
|
|
123
|
+
}
|
|
188
124
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
125
|
+
if (shouldAddFragmentFn && typeof v === "object") {
|
|
126
|
+
var objWithFragmentFn = Object.assign({}, v);
|
|
127
|
+
objWithFragmentFn.fragmentRefs = Object.assign({}, objWithFragmentFn);
|
|
128
|
+
return objWithFragmentFn;
|
|
129
|
+
}
|
|
193
130
|
|
|
194
|
-
|
|
195
|
-
|
|
131
|
+
return v;
|
|
132
|
+
});
|
|
133
|
+
} else {
|
|
134
|
+
/**
|
|
135
|
+
* Handle normal values.
|
|
136
|
+
*/
|
|
137
|
+
var v = currentObj[key];
|
|
196
138
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
139
|
+
if (shouldConvertRootObj) {
|
|
140
|
+
newObj = getNewObj(newObj, currentObj);
|
|
141
|
+
newObj[key] = traverser(
|
|
142
|
+
v,
|
|
143
|
+
fullInstructionMap,
|
|
144
|
+
converters,
|
|
145
|
+
nullableValue,
|
|
146
|
+
instructions["r"]
|
|
147
|
+
);
|
|
148
|
+
}
|
|
207
149
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
150
|
+
if (isTopLevelNodeField) {
|
|
151
|
+
if (
|
|
152
|
+
v == null ||
|
|
153
|
+
!v.hasOwnProperty("__typename") ||
|
|
154
|
+
v.__typename !== instructions["tnf"]
|
|
155
|
+
) {
|
|
156
|
+
newObj = getNewObj(newObj, currentObj);
|
|
157
|
+
newObj[key] = nullableValue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
211
160
|
|
|
212
|
-
|
|
213
|
-
|
|
161
|
+
if (shouldConvertEnum) {
|
|
162
|
+
newObj = getNewObj(newObj, currentObj);
|
|
163
|
+
newObj[key] = converters[instructions["e"]](v);
|
|
164
|
+
}
|
|
214
165
|
|
|
215
|
-
|
|
166
|
+
if (shouldConvertCustomField) {
|
|
167
|
+
newObj = getNewObj(newObj, currentObj);
|
|
168
|
+
newObj[key] = converters[instructions["c"]](v);
|
|
169
|
+
}
|
|
216
170
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
171
|
+
if (
|
|
172
|
+
shouldConvertUnion &&
|
|
173
|
+
v != null &&
|
|
174
|
+
typeof v === "object" &&
|
|
175
|
+
typeof v.__typename === "string"
|
|
176
|
+
) {
|
|
177
|
+
isUnion = true;
|
|
221
178
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
179
|
+
var newPath = makeNewPath(currentPath, [key, v.__typename]);
|
|
180
|
+
|
|
181
|
+
var unionRootHasFragment =
|
|
182
|
+
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
183
|
+
|
|
184
|
+
var traversedValue = traverse(
|
|
185
|
+
fullInstructionMap,
|
|
186
|
+
newPath,
|
|
187
|
+
v,
|
|
188
|
+
instructionMap,
|
|
189
|
+
converters,
|
|
190
|
+
nullableValue,
|
|
191
|
+
instructionPaths,
|
|
192
|
+
unionRootHasFragment
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
newObj = getNewObj(newObj, currentObj);
|
|
196
|
+
newObj[key] = converters[instructions["u"]](traversedValue);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (shouldAddFragmentFn && typeof v === "object") {
|
|
200
|
+
newObj = getNewObj(newObj, currentObj);
|
|
201
|
+
var objWithFragmentFn = Object.assign({}, v);
|
|
202
|
+
objWithFragmentFn.fragmentRefs = Object.assign({}, objWithFragmentFn);
|
|
203
|
+
newObj[key] = objWithFragmentFn;
|
|
225
204
|
}
|
|
226
205
|
}
|
|
227
206
|
|
|
228
|
-
if (
|
|
207
|
+
if (originalValue != null && !isUnion) {
|
|
229
208
|
var nextObj = (newObj && newObj[key]) || currentObj[key];
|
|
230
209
|
|
|
231
210
|
if (typeof nextObj === "object" && !Array.isArray(originalValue)) {
|
|
@@ -246,17 +225,21 @@ function traverse(
|
|
|
246
225
|
} else if (Array.isArray(originalValue)) {
|
|
247
226
|
newObj = getNewObj(newObj, currentObj);
|
|
248
227
|
newObj[key] = nextObj.map(function (o) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
228
|
+
if (typeof o === "object" && o != null) {
|
|
229
|
+
return traverse(
|
|
230
|
+
fullInstructionMap,
|
|
231
|
+
thisPath,
|
|
232
|
+
o,
|
|
233
|
+
instructionMap,
|
|
234
|
+
converters,
|
|
235
|
+
nullableValue,
|
|
236
|
+
instructionPaths
|
|
237
|
+
);
|
|
238
|
+
} else if (o == null) {
|
|
239
|
+
return nullableValue;
|
|
240
|
+
} else {
|
|
241
|
+
return o;
|
|
242
|
+
}
|
|
260
243
|
});
|
|
261
244
|
}
|
|
262
245
|
}
|
|
@@ -276,7 +259,7 @@ function traverse(
|
|
|
276
259
|
*/
|
|
277
260
|
function traverser(
|
|
278
261
|
root,
|
|
279
|
-
|
|
262
|
+
instructionMaps_,
|
|
280
263
|
theConverters,
|
|
281
264
|
nullableValue,
|
|
282
265
|
rootObjectKey
|
|
@@ -285,22 +268,12 @@ function traverser(
|
|
|
285
268
|
return nullableValue;
|
|
286
269
|
}
|
|
287
270
|
|
|
288
|
-
var instructionMaps =
|
|
289
|
-
var instructionMap = instructionMaps[rootObjectKey || "__root"];
|
|
290
|
-
|
|
291
|
-
// No instructions
|
|
292
|
-
if (!instructionMap) {
|
|
293
|
-
return root;
|
|
294
|
-
}
|
|
271
|
+
var instructionMaps = instructionMaps_ || {};
|
|
272
|
+
var instructionMap = instructionMaps[rootObjectKey || "__root"] || {};
|
|
295
273
|
|
|
296
274
|
var converters = theConverters == null ? {} : theConverters;
|
|
297
275
|
var instructionPaths = Object.keys(instructionMap);
|
|
298
276
|
|
|
299
|
-
// Nothing to convert, bail early
|
|
300
|
-
if (instructionPaths.length === 0) {
|
|
301
|
-
return root;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
277
|
// We'll add the fragmentRefs reference to the root if needed here.
|
|
305
278
|
var fragmentsOnRoot = (instructionMap[""] || {}).f === "";
|
|
306
279
|
var unionRootConverter = converters[(instructionMap[""] || {}).u];
|
|
@@ -311,9 +284,19 @@ function traverser(
|
|
|
311
284
|
return nullableValue;
|
|
312
285
|
}
|
|
313
286
|
|
|
287
|
+
var n = [];
|
|
288
|
+
|
|
289
|
+
// Since a root level union is treated as a "new root level", we'll need
|
|
290
|
+
// to do a separate check here of whether there's a fragment on the root
|
|
291
|
+
// we need to account for, or not.
|
|
292
|
+
if (unionRootConverter != null) {
|
|
293
|
+
n = [v.__typename];
|
|
294
|
+
fragmentsOnRoot = (instructionMap[v.__typename] || {}).f === "";
|
|
295
|
+
}
|
|
296
|
+
|
|
314
297
|
var traversedObj = traverse(
|
|
315
298
|
instructionMaps,
|
|
316
|
-
|
|
299
|
+
n,
|
|
317
300
|
v,
|
|
318
301
|
instructionMap,
|
|
319
302
|
converters,
|
|
@@ -330,9 +313,18 @@ function traverser(
|
|
|
330
313
|
|
|
331
314
|
var newObj = Object.assign({}, root);
|
|
332
315
|
|
|
316
|
+
var n = [];
|
|
317
|
+
|
|
318
|
+
// Same as in the union array check above - if there's a fragment in the new
|
|
319
|
+
// root created by the union, we need to account for that separately here.
|
|
320
|
+
if (unionRootConverter != null) {
|
|
321
|
+
n = [newObj.__typename];
|
|
322
|
+
fragmentsOnRoot = (instructionMap[newObj.__typename] || {}).f === "";
|
|
323
|
+
}
|
|
324
|
+
|
|
333
325
|
var v = traverse(
|
|
334
326
|
instructionMaps,
|
|
335
|
-
|
|
327
|
+
n,
|
|
336
328
|
newObj,
|
|
337
329
|
instructionMap,
|
|
338
330
|
converters,
|