rescript-relay 1.0.5 → 1.1.1

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.
@@ -1,18 +1,16 @@
1
- @ocaml.doc("Tries to return a record from a nested path of linked records.")
1
+ /**Tries to return a record from a nested path of linked records.*/
2
2
  let resolveNestedRecord: (
3
3
  ~rootRecord: option<RescriptRelay.RecordProxy.t>,
4
4
  ~path: list<string>,
5
5
  ) => option<RescriptRelay.RecordProxy.t>
6
6
 
7
- @ocaml.doc(
8
- "Tries to return a record from a nested path of linked records, starting from the root. "
9
- )
7
+ /**Tries to return a record from a nested path of linked records, starting from the root.*/
10
8
  let resolveNestedRecordFromRoot: (
11
9
  ~store: RescriptRelay.RecordSourceSelectorProxy.t,
12
10
  ~path: list<string>,
13
11
  ) => option<RescriptRelay.RecordProxy.t>
14
12
 
15
- @ocaml.doc("Helpers for handling connections. ")
13
+ /**Helpers for handling connections.*/
16
14
  type insertAt =
17
15
  | Start
18
16
  | End
package/src/utils.js CHANGED
@@ -87,9 +87,24 @@ function traverse(
87
87
  var shouldConvertEnum =
88
88
  typeof instructions["e"] === "string" && !!converters[instructions["e"]];
89
89
 
90
+ // This is true for non-arrays that are to be converted
90
91
  var shouldConvertCustomField =
91
92
  typeof instructions["c"] === "string" && !!converters[instructions["c"]];
92
93
 
94
+ // This is true for arrays that are to be converted. This and the above
95
+ // won't be true at the same time.
96
+ var shouldConvertCustomFieldArray =
97
+ typeof instructions["ca"] === "string" &&
98
+ !!converters[instructions["ca"]];
99
+
100
+ // Special case when this is a custom field that's an array. Ensures we
101
+ // don't accidentally move into the array when we're not supposed to.
102
+ if (shouldConvertCustomFieldArray && Array.isArray(currentObj[key])) {
103
+ newObj = getNewObj(newObj, currentObj);
104
+ newObj[key] = currentObj[key].map(converters[instructions["ca"]]);
105
+ return newObj;
106
+ }
107
+
93
108
  var shouldBlockTraversal = typeof instructions["b"] === "string";
94
109
  var allowGoingIntoArray = shouldBlockTraversal
95
110
  ? instructions["b"] === "a"
@@ -108,6 +123,15 @@ function traverse(
108
123
  /**
109
124
  * Handle arrays
110
125
  */
126
+
127
+ // Special case when this is a custom field that's an array. Ensures we
128
+ // don't accidentally move into the array when we're not supposed to.
129
+ if (shouldConvertCustomField && Array.isArray(currentObj[key])) {
130
+ newObj = getNewObj(newObj, currentObj);
131
+ newObj[key] = converters[instructions["c"]](originalValue);
132
+ return newObj;
133
+ }
134
+
111
135
  if (Array.isArray(currentObj[key])) {
112
136
  newObj = getNewObj(newObj, currentObj);
113
137
  newObj[key] = currentObj[key].map(function (v) {
@@ -218,6 +242,8 @@ function traverse(
218
242
  if (shouldConvertCustomField) {
219
243
  newObj = getNewObj(newObj, currentObj);
220
244
  newObj[key] = converters[instructions["c"]](v);
245
+ // Ensure that the custom scalar value itself isn't traversed more.
246
+ continue;
221
247
  }
222
248
 
223
249
  if (shouldConvertUnion && v != null && typeof v === "object") {
package/src/utils.mjs CHANGED
@@ -87,9 +87,24 @@ function traverse(
87
87
  var shouldConvertEnum =
88
88
  typeof instructions["e"] === "string" && !!converters[instructions["e"]];
89
89
 
90
+ // This is true for non-arrays that are to be converted
90
91
  var shouldConvertCustomField =
91
92
  typeof instructions["c"] === "string" && !!converters[instructions["c"]];
92
93
 
94
+ // This is true for arrays that are to be converted. This and the above
95
+ // won't be true at the same time.
96
+ var shouldConvertCustomFieldArray =
97
+ typeof instructions["ca"] === "string" &&
98
+ !!converters[instructions["ca"]];
99
+
100
+ // Special case when this is a custom field that's an array. Ensures we
101
+ // don't accidentally move into the array when we're not supposed to.
102
+ if (shouldConvertCustomFieldArray && Array.isArray(currentObj[key])) {
103
+ newObj = getNewObj(newObj, currentObj);
104
+ newObj[key] = currentObj[key].map(converters[instructions["ca"]]);
105
+ return newObj;
106
+ }
107
+
93
108
  var shouldBlockTraversal = typeof instructions["b"] === "string";
94
109
  var allowGoingIntoArray = shouldBlockTraversal
95
110
  ? instructions["b"] === "a"
@@ -108,6 +123,15 @@ function traverse(
108
123
  /**
109
124
  * Handle arrays
110
125
  */
126
+
127
+ // Special case when this is a custom field that's an array. Ensures we
128
+ // don't accidentally move into the array when we're not supposed to.
129
+ if (shouldConvertCustomField && Array.isArray(currentObj[key])) {
130
+ newObj = getNewObj(newObj, currentObj);
131
+ newObj[key] = converters[instructions["c"]](originalValue);
132
+ return newObj;
133
+ }
134
+
111
135
  if (Array.isArray(currentObj[key])) {
112
136
  newObj = getNewObj(newObj, currentObj);
113
137
  newObj[key] = currentObj[key].map(function (v) {
@@ -218,6 +242,8 @@ function traverse(
218
242
  if (shouldConvertCustomField) {
219
243
  newObj = getNewObj(newObj, currentObj);
220
244
  newObj[key] = converters[instructions["c"]](v);
245
+ // Ensure that the custom scalar value itself isn't traversed more.
246
+ continue;
221
247
  }
222
248
 
223
249
  if (shouldConvertUnion && v != null && typeof v === "object") {