rescript-relay 0.0.0-test-linux-7ced6072 → 0.0.0-test-rust-compiler-d42079d3
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 +61 -0
- package/README.md +1 -1
- package/bsconfig.json +1 -1
- package/cli/cli.js +478 -0
- package/package.json +15 -20
- package/postinstall.js +40 -13
- package/ppx-darwin +0 -0
- package/ppx-linux +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 +19 -20
- package/src/RescriptRelay.res +28 -26
- package/src/RescriptRelay.resi +22 -34
- package/src/experimental-router/RescriptRelayRouter.bs.js +419 -0
- package/src/experimental-router/RescriptRelayRouter.res +377 -0
- package/src/experimental-router/RescriptRelayRouter.resi +76 -0
- package/src/utils.js +8 -10
- 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
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
module RouteFamily = {
|
|
2
|
+
type t = {
|
|
3
|
+
preload: RescriptReactRouter.url => unit,
|
|
4
|
+
matchesUrl: RescriptReactRouter.url => bool,
|
|
5
|
+
render: RescriptReactRouter.url => React.element,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let matchesUrl = (t, url) => t.matchesUrl(url)
|
|
9
|
+
let preload = (t, url) => t.preload(url)
|
|
10
|
+
let render = (t, url) => t.render(url)
|
|
11
|
+
|
|
12
|
+
let make = (~matchUrl, ~prepare, ~render) => {
|
|
13
|
+
preload: url =>
|
|
14
|
+
switch matchUrl(url) {
|
|
15
|
+
| Some(params) =>
|
|
16
|
+
let _ = prepare(params)
|
|
17
|
+
| None => ()
|
|
18
|
+
},
|
|
19
|
+
matchesUrl: url =>
|
|
20
|
+
switch matchUrl(url) {
|
|
21
|
+
| Some(_) => true
|
|
22
|
+
| None => false
|
|
23
|
+
},
|
|
24
|
+
render: url =>
|
|
25
|
+
switch matchUrl(url) {
|
|
26
|
+
| Some(params) => params->prepare->render
|
|
27
|
+
| None => React.null
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module Url = {
|
|
33
|
+
type t = RescriptReactRouter.url
|
|
34
|
+
|
|
35
|
+
let getHash = url => {
|
|
36
|
+
switch url->Js.String2.indexOf("#") {
|
|
37
|
+
| index if index >= 0 => url->Js.String2.sliceToEnd(~from=index + 1)
|
|
38
|
+
| _ => Js.String2.make("")
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Start - taken from RescriptReactRouter
|
|
43
|
+
let arrayToList = a => {
|
|
44
|
+
let rec tolist = (i, res) =>
|
|
45
|
+
if i < 0 {
|
|
46
|
+
res
|
|
47
|
+
} else {
|
|
48
|
+
tolist(i - 1, list{Js.Array.unsafe_get(a, i), ...res})
|
|
49
|
+
}
|
|
50
|
+
tolist(Js.Array.length(a) - 1, list{})
|
|
51
|
+
}
|
|
52
|
+
let pathParse = str =>
|
|
53
|
+
switch str {
|
|
54
|
+
| ""
|
|
55
|
+
| "/" => list{}
|
|
56
|
+
| raw =>
|
|
57
|
+
/* remove the preceeding /, which every pathname seems to have */
|
|
58
|
+
let raw = Js.String.sliceToEnd(~from=1, raw)
|
|
59
|
+
/* remove the trailing /, which some pathnames might have. Ugh */
|
|
60
|
+
let raw = switch Js.String.get(raw, Js.String.length(raw) - 1) {
|
|
61
|
+
| "/" => Js.String.slice(~from=0, ~to_=-1, raw)
|
|
62
|
+
| _ => raw
|
|
63
|
+
}
|
|
64
|
+
/* remove search portion if present in string */
|
|
65
|
+
let raw = switch raw |> Js.String.splitAtMost("?", ~limit=2) {
|
|
66
|
+
| [path, _] => path
|
|
67
|
+
| _ => raw
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
raw
|
|
71
|
+
|> Js.String.split("/")
|
|
72
|
+
|> Js.Array.filter(item => String.length(item) != 0)
|
|
73
|
+
|> arrayToList
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let searchParse = str =>
|
|
77
|
+
switch str {
|
|
78
|
+
| ""
|
|
79
|
+
| "?" => ""
|
|
80
|
+
| raw =>
|
|
81
|
+
switch raw |> Js.String.splitAtMost("?", ~limit=2) {
|
|
82
|
+
| [_, search] => search
|
|
83
|
+
| _ => ""
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// End - taken from RescriptReactRouter
|
|
87
|
+
|
|
88
|
+
let parseUrl = (url: string): t => {
|
|
89
|
+
path: url->pathParse,
|
|
90
|
+
hash: url->getHash,
|
|
91
|
+
search: url->searchParse,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let make = url => url->parseUrl
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type routeEntry = {
|
|
98
|
+
route: option<RouteFamily.t>,
|
|
99
|
+
url: RescriptReactRouter.url,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type subscriberCallback = routeEntry => unit
|
|
103
|
+
type disposeSubscriber = unit => unit
|
|
104
|
+
|
|
105
|
+
type routerContext = {
|
|
106
|
+
get: unit => routeEntry,
|
|
107
|
+
preload: string => unit,
|
|
108
|
+
subscribe: subscriberCallback => disposeSubscriber,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let context = React.createContext(Obj.magic())
|
|
112
|
+
|
|
113
|
+
module Provider = {
|
|
114
|
+
let make = React.Context.provider(context)
|
|
115
|
+
|
|
116
|
+
let makeProps = (~value, ~children, ()) =>
|
|
117
|
+
{
|
|
118
|
+
"value": value,
|
|
119
|
+
"children": children,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
exception No_router_in_context
|
|
124
|
+
|
|
125
|
+
module NavigationUtils = {
|
|
126
|
+
@send
|
|
127
|
+
external replaceShallow: (Dom.history, @as(json`null`) _, @as("") _, ~href: string) => unit =
|
|
128
|
+
"replaceState"
|
|
129
|
+
|
|
130
|
+
let replaceShallow = path =>
|
|
131
|
+
switch (%external(history), %external(window)) {
|
|
132
|
+
| (None, _)
|
|
133
|
+
| (_, None) => ()
|
|
134
|
+
| (Some(history: Dom.history), Some(_window: Dom.window)) => replaceShallow(history, ~href=path)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@send
|
|
138
|
+
external pushShallow: (Dom.history, @as(json`null`) _, @as("") _, ~href: string) => unit =
|
|
139
|
+
"pushState"
|
|
140
|
+
|
|
141
|
+
let pushShallow = path =>
|
|
142
|
+
switch (%external(history), %external(window)) {
|
|
143
|
+
| (None, _)
|
|
144
|
+
| (_, None) => ()
|
|
145
|
+
| (Some(history: Dom.history), Some(_window: Dom.window)) => pushShallow(history, ~href=path)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let use = (): routerContext => React.useContext(context)
|
|
150
|
+
|
|
151
|
+
let make = routes => {
|
|
152
|
+
let initialUrl = RescriptReactRouter.dangerouslyGetInitialUrl()
|
|
153
|
+
|
|
154
|
+
let matchRoutes = (routes, url): option<RouteFamily.t> =>
|
|
155
|
+
routes->Belt.Array.getBy(r => r->RouteFamily.matchesUrl(url))
|
|
156
|
+
|
|
157
|
+
let currentRoute: ref<routeEntry> = ref({url: initialUrl, route: matchRoutes(routes, initialUrl)})
|
|
158
|
+
|
|
159
|
+
let subscribers: Js.Dict.t<option<subscriberCallback>> = Js.Dict.empty()
|
|
160
|
+
let subId = ref(0)
|
|
161
|
+
|
|
162
|
+
let getNextId = () => {
|
|
163
|
+
subId := subId.contents + 1
|
|
164
|
+
subId.contents->string_of_int
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let _ = RescriptReactRouter.watchUrl(url =>
|
|
168
|
+
if url.path != currentRoute.contents.url.path {
|
|
169
|
+
let route = matchRoutes(routes, url)
|
|
170
|
+
|
|
171
|
+
switch route {
|
|
172
|
+
| Some(r) => r->RouteFamily.preload(url)
|
|
173
|
+
| None => ()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let nextEntry = {route: route, url: url}
|
|
177
|
+
|
|
178
|
+
currentRoute := nextEntry
|
|
179
|
+
subscribers
|
|
180
|
+
->Js.Dict.values
|
|
181
|
+
->Belt.Array.forEach(x =>
|
|
182
|
+
switch x {
|
|
183
|
+
| Some(cb) => cb(nextEntry)
|
|
184
|
+
| None => ()
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
let router = {
|
|
191
|
+
get: () => currentRoute.contents,
|
|
192
|
+
preload: url => {
|
|
193
|
+
let asRouterUrl = url->Url.make
|
|
194
|
+
|
|
195
|
+
switch routes->matchRoutes(asRouterUrl) {
|
|
196
|
+
| Some(r) => r->RouteFamily.preload(asRouterUrl)
|
|
197
|
+
| None => ()
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
subscribe: cb => {
|
|
201
|
+
let id = getNextId()
|
|
202
|
+
subscribers->Js.Dict.set(id, Some(cb))
|
|
203
|
+
() => subscribers->Js.Dict.set(id, None)
|
|
204
|
+
},
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
router
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
type router = {
|
|
211
|
+
push: string => unit,
|
|
212
|
+
pushShallow: string => unit,
|
|
213
|
+
replace: string => unit,
|
|
214
|
+
replaceShallow: string => unit,
|
|
215
|
+
preload: string => unit,
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
let useRouter = () => {
|
|
219
|
+
let router = use()
|
|
220
|
+
|
|
221
|
+
React.useMemo1(() => {
|
|
222
|
+
push: RescriptReactRouter.push,
|
|
223
|
+
pushShallow: NavigationUtils.pushShallow,
|
|
224
|
+
replace: RescriptReactRouter.replace,
|
|
225
|
+
replaceShallow: NavigationUtils.pushShallow,
|
|
226
|
+
preload: router.preload,
|
|
227
|
+
}, [router.preload])
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
module RouteRenderer = {
|
|
231
|
+
@react.component
|
|
232
|
+
let make = (~renderPending=?, ~renderFallback=?, ~renderNotFound=?, ()) => {
|
|
233
|
+
let (initialized, setInitialized) = React.useState(() => false)
|
|
234
|
+
let router = use()
|
|
235
|
+
|
|
236
|
+
let (isPending, startTransition) = ReactExperimental.useTransition()
|
|
237
|
+
|
|
238
|
+
let (routeEntry, setRouteEntry) = React.useState(() => router.get())
|
|
239
|
+
|
|
240
|
+
switch (initialized, routeEntry.route) {
|
|
241
|
+
| (false, Some(r)) =>
|
|
242
|
+
r->RouteFamily.preload(routeEntry.url)
|
|
243
|
+
setInitialized(_ => true)
|
|
244
|
+
| _ => ()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
React.useEffect2(() => {
|
|
248
|
+
let currentEntry = router.get()
|
|
249
|
+
if routeEntry.url != currentEntry.url {
|
|
250
|
+
setRouteEntry(_ => currentEntry)
|
|
251
|
+
None
|
|
252
|
+
} else {
|
|
253
|
+
let dispose = router.subscribe(nextRoute =>
|
|
254
|
+
startTransition(() => setRouteEntry(_ => nextRoute))
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
Some(dispose)
|
|
258
|
+
}
|
|
259
|
+
}, (router, startTransition))
|
|
260
|
+
|
|
261
|
+
let renderedContent = switch (initialized, routeEntry.route) {
|
|
262
|
+
| (false, Some(_) | None) => None
|
|
263
|
+
| (true, Some(r)) => Some(r->RouteFamily.render(routeEntry.url))
|
|
264
|
+
| (true, None) => None
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
initialized
|
|
268
|
+
? <>
|
|
269
|
+
{switch renderPending {
|
|
270
|
+
| Some(renderPending) => renderPending(isPending)
|
|
271
|
+
| None => React.null
|
|
272
|
+
}}
|
|
273
|
+
<React.Suspense
|
|
274
|
+
fallback={switch renderFallback {
|
|
275
|
+
| Some(renderFallback) => renderFallback()
|
|
276
|
+
| None => React.null
|
|
277
|
+
}}>
|
|
278
|
+
{switch (renderedContent, renderNotFound) {
|
|
279
|
+
| (Some(content), _) => content
|
|
280
|
+
| (None, Some(renderNotFound)) => renderNotFound(routeEntry.url)
|
|
281
|
+
| (None, None) => React.null
|
|
282
|
+
}}
|
|
283
|
+
</React.Suspense>
|
|
284
|
+
</>
|
|
285
|
+
: React.null
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
let isModifiedEvent = e => {
|
|
290
|
+
open ReactEvent.Mouse
|
|
291
|
+
switch (e->metaKey, e->altKey, e->ctrlKey, e->shiftKey) {
|
|
292
|
+
| (true, _, _, _)
|
|
293
|
+
| (_, true, _, _) => true
|
|
294
|
+
| (_, _, true, _) => true
|
|
295
|
+
| (_, _, _, true) => true
|
|
296
|
+
| _ => false
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
module Link = {
|
|
301
|
+
@react.component
|
|
302
|
+
let make = (
|
|
303
|
+
~to_,
|
|
304
|
+
~title=?,
|
|
305
|
+
~id=?,
|
|
306
|
+
~className=?,
|
|
307
|
+
~classNameDynamic=?,
|
|
308
|
+
~target as browserTarget=?,
|
|
309
|
+
~mode=?,
|
|
310
|
+
~render=?,
|
|
311
|
+
~preloadOnHover=?,
|
|
312
|
+
~children,
|
|
313
|
+
~onClick=?,
|
|
314
|
+
(),
|
|
315
|
+
) => {
|
|
316
|
+
let router = use()
|
|
317
|
+
let url = RescriptReactRouter.useUrl()
|
|
318
|
+
|
|
319
|
+
let changeRoute = React.useCallback2(e => {
|
|
320
|
+
open ReactEvent.Mouse
|
|
321
|
+
switch (e->isDefaultPrevented, e->button, browserTarget, e->isModifiedEvent) {
|
|
322
|
+
| (false, 0, None | Some(#self), false) =>
|
|
323
|
+
e->preventDefault
|
|
324
|
+
let navigate = () =>
|
|
325
|
+
switch mode {
|
|
326
|
+
| None
|
|
327
|
+
| Some(#push) =>
|
|
328
|
+
RescriptReactRouter.push(to_)
|
|
329
|
+
| Some(#replace) => RescriptReactRouter.replace(to_)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
navigate()
|
|
333
|
+
()
|
|
334
|
+
| _ => ()
|
|
335
|
+
}
|
|
336
|
+
}, (to_, router))
|
|
337
|
+
|
|
338
|
+
let preload = React.useCallback2(() => router.preload(to_), (to_, router))
|
|
339
|
+
|
|
340
|
+
switch render {
|
|
341
|
+
| Some(render) =>
|
|
342
|
+
let linkUrl = to_->Url.make
|
|
343
|
+
render(~preload, ~changeRoute, ~currentUrl=url, ~linkUrl)
|
|
344
|
+
| None =>
|
|
345
|
+
<a
|
|
346
|
+
href=to_
|
|
347
|
+
target={switch browserTarget {
|
|
348
|
+
| Some(#self) => "_self"
|
|
349
|
+
| Some(#blank) => "_blank"
|
|
350
|
+
| None => ""
|
|
351
|
+
}}
|
|
352
|
+
?title
|
|
353
|
+
?id
|
|
354
|
+
className={className->Belt.Option.getWithDefault("") ++
|
|
355
|
+
switch classNameDynamic {
|
|
356
|
+
| Some(f) => " " ++ f(url, to_->Url.make)
|
|
357
|
+
| None => ""
|
|
358
|
+
}}
|
|
359
|
+
onClick={e => {
|
|
360
|
+
changeRoute(e)
|
|
361
|
+
switch onClick {
|
|
362
|
+
| None => ()
|
|
363
|
+
| Some(onClick) => onClick()
|
|
364
|
+
}
|
|
365
|
+
}}
|
|
366
|
+
onMouseDown={_ => preload()}
|
|
367
|
+
onTouchStart={_ => preload()}
|
|
368
|
+
onMouseEnter={_ =>
|
|
369
|
+
switch preloadOnHover {
|
|
370
|
+
| Some(true) => preload()
|
|
371
|
+
| Some(false) | None => ()
|
|
372
|
+
}}>
|
|
373
|
+
children
|
|
374
|
+
</a>
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module RouteFamily: {
|
|
2
|
+
type t
|
|
3
|
+
|
|
4
|
+
let matchesUrl: (t, RescriptReactRouter.url) => bool
|
|
5
|
+
let preload: (t, RescriptReactRouter.url) => unit
|
|
6
|
+
let render: (t, RescriptReactRouter.url) => React.element
|
|
7
|
+
let make: (
|
|
8
|
+
~matchUrl: RescriptReactRouter.url => option<'routeVariables>,
|
|
9
|
+
~prepare: 'routeVariables => 'prepared,
|
|
10
|
+
~render: 'prepared => React.element,
|
|
11
|
+
) => t
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type routerContext
|
|
15
|
+
|
|
16
|
+
module Provider: {
|
|
17
|
+
let makeProps: (
|
|
18
|
+
~value: routerContext,
|
|
19
|
+
~children: React.element,
|
|
20
|
+
unit,
|
|
21
|
+
) => {"value": routerContext, "children": React.element}
|
|
22
|
+
|
|
23
|
+
let make: React.component<{"value": routerContext, "children": React.element}>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exception No_router_in_context
|
|
27
|
+
|
|
28
|
+
type router = {
|
|
29
|
+
push: string => unit,
|
|
30
|
+
pushShallow: string => unit,
|
|
31
|
+
replace: string => unit,
|
|
32
|
+
replaceShallow: string => unit,
|
|
33
|
+
preload: string => unit,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let useRouter: unit => router
|
|
37
|
+
|
|
38
|
+
let make: array<RouteFamily.t> => routerContext
|
|
39
|
+
|
|
40
|
+
module RouteRenderer: {
|
|
41
|
+
@react.component
|
|
42
|
+
let make: (
|
|
43
|
+
~renderPending: bool => React.element=?,
|
|
44
|
+
~renderFallback: unit => React.element=?,
|
|
45
|
+
~renderNotFound: RescriptReactRouter.url => React.element=?,
|
|
46
|
+
unit,
|
|
47
|
+
) => React.element
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module Link: {
|
|
51
|
+
@react.component
|
|
52
|
+
let make: (
|
|
53
|
+
~to_: string,
|
|
54
|
+
~title: string=?,
|
|
55
|
+
~id: string=?,
|
|
56
|
+
~className: string=?,
|
|
57
|
+
~classNameDynamic: (RescriptReactRouter.url, RescriptReactRouter.url) => string=?,
|
|
58
|
+
~target: [#self | #blank]=?,
|
|
59
|
+
~mode: [#push | #replace]=?,
|
|
60
|
+
~render: (
|
|
61
|
+
~preload: unit => unit,
|
|
62
|
+
~changeRoute: ReactEvent.Mouse.t => unit,
|
|
63
|
+
~currentUrl: RescriptReactRouter.url,
|
|
64
|
+
~linkUrl: RescriptReactRouter.url,
|
|
65
|
+
) => React.element=?,
|
|
66
|
+
~preloadOnHover: bool=?,
|
|
67
|
+
~children: React.element,
|
|
68
|
+
~onClick: unit => unit=?,
|
|
69
|
+
unit,
|
|
70
|
+
) => React.element
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module NavigationUtils: {
|
|
74
|
+
let replaceShallow: string => unit
|
|
75
|
+
let pushShallow: string => unit
|
|
76
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -108,10 +108,7 @@ function traverse(
|
|
|
108
108
|
) {
|
|
109
109
|
isUnion = true;
|
|
110
110
|
|
|
111
|
-
var newPath = makeNewPath(currentPath, [
|
|
112
|
-
key,
|
|
113
|
-
v.__typename.toLowerCase(),
|
|
114
|
-
]);
|
|
111
|
+
var newPath = makeNewPath(currentPath, [key, v.__typename]);
|
|
115
112
|
|
|
116
113
|
var unionRootHasFragment =
|
|
117
114
|
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
@@ -186,10 +183,7 @@ function traverse(
|
|
|
186
183
|
) {
|
|
187
184
|
isUnion = true;
|
|
188
185
|
|
|
189
|
-
var newPath = makeNewPath(currentPath, [
|
|
190
|
-
key,
|
|
191
|
-
v.__typename.toLowerCase(),
|
|
192
|
-
]);
|
|
186
|
+
var newPath = makeNewPath(currentPath, [key, v.__typename]);
|
|
193
187
|
|
|
194
188
|
var unionRootHasFragment =
|
|
195
189
|
(instructionMap[getPathName(newPath)] || {}).f === "";
|
|
@@ -311,9 +305,11 @@ function traverser(
|
|
|
311
305
|
return nullableValue;
|
|
312
306
|
}
|
|
313
307
|
|
|
308
|
+
var n = unionRootConverter != null ? [v.__typename] : [];
|
|
309
|
+
|
|
314
310
|
var traversedObj = traverse(
|
|
315
311
|
instructionMaps,
|
|
316
|
-
|
|
312
|
+
n,
|
|
317
313
|
v,
|
|
318
314
|
instructionMap,
|
|
319
315
|
converters,
|
|
@@ -330,9 +326,11 @@ function traverser(
|
|
|
330
326
|
|
|
331
327
|
var newObj = Object.assign({}, root);
|
|
332
328
|
|
|
329
|
+
var n = unionRootConverter != null ? [newObj.__typename] : [];
|
|
330
|
+
|
|
333
331
|
var v = traverse(
|
|
334
332
|
instructionMaps,
|
|
335
|
-
|
|
333
|
+
n,
|
|
336
334
|
newObj,
|
|
337
335
|
instructionMap,
|
|
338
336
|
converters,
|
package/bin-darwin
DELETED
|
Binary file
|
package/bin-linux
DELETED
|
Binary file
|
package/compiler/compiler-cli.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const { spawn } = require("child_process");
|
|
4
|
-
|
|
5
|
-
let relayConfig = require("relay-config").loadConfig();
|
|
6
|
-
|
|
7
|
-
if (!relayConfig) {
|
|
8
|
-
console.error(
|
|
9
|
-
"Could not find relay.config.js. You must configure Relay through relay.config.js for RescriptRelay to work."
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (!relayConfig.artifactDirectory) {
|
|
16
|
-
console.error(
|
|
17
|
-
"RescriptRelay requires you to define 'artifactDirectory' (for outputing generated files in a single directory) in your relay.config.js. Please define it and re-run this command."
|
|
18
|
-
);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function runRelayCompiler(args) {
|
|
23
|
-
const proc = spawn("relay-compiler", args, {
|
|
24
|
-
stdio: "inherit",
|
|
25
|
-
})
|
|
26
|
-
// Propagate the relay compiler's exit code.
|
|
27
|
-
.on("close", process.exit.bind(process));
|
|
28
|
-
|
|
29
|
-
process.on("SIGINT", () => {
|
|
30
|
-
proc.kill("SIGINT");
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function findArg(name) {
|
|
35
|
-
return relayConfig[name];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function runCompiler() {
|
|
39
|
-
const schemaPath = findArg("schema");
|
|
40
|
-
|
|
41
|
-
if (schemaPath) {
|
|
42
|
-
runRelayCompiler(
|
|
43
|
-
[
|
|
44
|
-
"--language",
|
|
45
|
-
path.resolve(__dirname + "/../language-plugin/dist/index.js"),
|
|
46
|
-
process.argv.find((a) => a === "--watch"),
|
|
47
|
-
].filter(Boolean)
|
|
48
|
-
);
|
|
49
|
-
} else {
|
|
50
|
-
runRelayCompiler(["--help"]);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
runCompiler();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports=(()=>{"use strict";var e={338:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.find=void 0,t.find=function(e,t){return function(e,t){if(!e.includes("%relay"))return[];const n=e.match(/(?<=\[%relay)([\s\S]*?)(?=];)/g);if(n)return n.map((e=>({template:e.replace(/({\||\|})/g,""),keyName:null,sourceLocationOffset:{line:1,column:1}})));const r=e.match(/(?<=\%relay\([\s]*`)[\s\S.]+?(?=`[\s]*\))/g);return r?r.map((e=>({template:e,keyName:null,sourceLocationOffset:{line:1,column:1}}))):[]}(e)}},189:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.generateFromFlowTypes=void 0;const r=n(129),o=n(622);t.generateFromFlowTypes=e=>{var t;const n=r.spawnSync(o.resolve(o.join(__dirname,"../RescriptRelayBin.exe")),["generate-from-flow"],{cwd:__dirname,stdio:"pipe",encoding:"utf-8",input:JSON.stringify(e)});if(0!==n.status)throw null!==(t=n.error)&&void 0!==t?t:new Error("Error generating types");return n.output.filter(Boolean).join("")}},571:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.transforms=t.generate=void 0;const r=n(791),o=n(224),a=n(148),i=n(354),s=n(189),l=n(602);function c(e){const t=Object.assign({Int:"int",Float:"float"},e);return Object.keys(t).forEach((e=>{t[e]=l.maskDots(t[e])})),t}t.generate=function(e,t,n){var a;let i=r.generate(e,t,Object.assign(Object.assign({},n),{customScalars:c(n.customScalars)}));const l=o.makeOperationDescriptor(t),d=o.extractOperationInfo(t);return s.generateFromFlowTypes({content:i,operation_type:["Query","Mutation","Subscription"].includes(l.tag)?{operation:l.tag,operation_value:l.value}:{operation:"Fragment",fragment_value:l.value},print_config:{variables_holding_connection_ids:null!==(a=d.variablesHoldingConnectionIds)&&void 0!==a?a:null,connection:d.connection?{at_object_path:d.connection.atObjectPath,field_name:d.connection.fieldName,key:d.connection.key}:null}})},t.transforms=[i.transform,a.transform,...r.transforms]},942:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0});const r=n(366);e.exports=({moduleName:e,documentType:t,concreteText:n,typeText:o})=>{const a="ConcreteRequest"===t&&e.toLowerCase().endsWith("query_graphql")?"include RescriptRelay.MakeLoadQuery({\n type variables = Types.variables\n type loadedQueryRef = queryRef\n type response = Types.response\n type node = relayOperationNode\n let query = node\n let convertVariables = Internal.convertVariables\n });":"",{processedText:i,referencedNodes:s}=r.processConcreteText(n),l=`%raw(json\` ${i} \`)`;return[o||"",...s.length>0?[`%%private(let makeNode = (${s.map((({identifier:e})=>e)).join(", ")}): operationType => {`,...s.map((({identifier:e})=>` ignore(${e})`)),` ${l}`,"})",`let node: operationType = makeNode(${s.map((({moduleName:e})=>`${e}_graphql.node`)).join(", ")})`]:[`let node: operationType = ${l}`],"",a,""].join("\n")}},602:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.unmaskDots=t.maskDots=void 0,t.maskDots=e=>e.split(".").join("__oo__"),t.unmaskDots=e=>e.split("__oo__").join(".")},607:(e,t,n)=>{const r=n(571),o=n(942),{find:a}=n(338),i=n(622),s=n(747);function l(e){return t=>{const n=i.join(e,t.relPath);let r="";try{r=s.readFileSync(n,"utf8")}catch(e){return console.warn(`RelaySourceModuleParser: Unable to read the file "${n}". Looks like it was removed.`),!1}return r.indexOf("%relay")>=0}}e.exports=()=>({inputExtensions:["re","res"],outputExtension:"res",schemaExtensions:[],typeGenerator:r,formatModule:o,findGraphQLTags:a,isGeneratedFile:e=>e.endsWith("_graphql.res")||e.endsWith(".js")||e.endsWith(".mjs"),keepExtraFile:e=>e.endsWith(".js")||e.endsWith(".mjs"),getFileFilter:l,getModuleName:e=>`${e}_graphql`})},224:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.makeOperationDescriptor=t.extractOperationInfo=void 0;const r=n(195);function o(e,t,n){if("Root"===e.kind&&["mutation","subscription"].includes(e.operation)){const e=t.directives.filter((e=>["appendNode","prependNode","appendEdge","prependEdge","deleteEdge"].includes(e.name)));e.length>0&&e.forEach((e=>{const t=e.args.find((e=>"connections"===e.name)),r=null==t?void 0:t.value;r&&"Variable"===r.kind&&(n.variablesHoldingConnectionIds?n.variablesHoldingConnectionIds.push(r.variableName):n.variablesHoldingConnectionIds=[r.variableName])}))}}t.extractOperationInfo=function(e){let t={};const n="Fragment"===e.kind?"fragment":"response";return n?(function e(n,a){r.IRVisitor.visit(a,{ScalarField(e){o(a,e,t)},LinkedField(e){const r=e.directives.find((e=>"connection"===e.name));if(r&&!t.connection){let o=null;r.args.forEach((e=>{"key"===e.name&&"Literal"===e.value.kind&&(o=e.value.value)})),o&&(t=Object.assign(Object.assign({},t),{connection:{key:o,atObjectPath:[...n],fieldName:e.alias}}))}o(a,e,t),n.push(e.alias)},InlineFragment(t){t.typeCondition.name&&t.selections.forEach((r=>{e([...n,t.typeCondition.name.toLowerCase()],r)}))}})}([n],e),t):t},t.makeOperationDescriptor=function(e){if("Root"===e.kind)switch(e.operation){case"mutation":return{tag:"Mutation",value:e.name};case"query":return{tag:"Query",value:e.name};case"subscription":return{tag:"Subscription",value:e.name}}else if("Fragment"==e.kind)return{tag:"Fragment",value:[e.name,Boolean(e.metadata&&e.metadata.plural)]};throw new Error("Could not map root node. This should not happen.")}},148:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.transform=void 0;const r=n(724),{createUserError:o}=n(182),a=["and","as","asr","assert","begin","class","constraint","do","while","for","done","while","for","downto","else","end","exception","external","false","for","fun","function","functor","if","in","include","inherit","initializer","land","lazy","let","lor","lsl","lsr","lxor","match","method","mod","module","open","mutable","new","nonrec","object","of","open","open!","or","private","rec","let","module","sig","struct","then","to","true","try","type","val","virtual","val","method","class","when","while","with","switch"];let i=["fragment","t_fragment","subscription","mutation","response","variables","refetchVariables","t","fragmentRef","fragmentRefs","fragmentRefSelector","operationType"];function s(e){if(e.alias){let{disallowed:t,message:n}=function(e){let t=e[0];return/[A-Z]/.test(t)?{disallowed:!0,message:`Field names may not start with an uppercase letter. Please alias the '${e}' field to something starting with a lowercase letter.`}:a.includes(e)?{disallowed:!0,message:`'${e}' is a reserved keyword in ReasonML and therefore cannot be used as a field name. Please alias your field to something else.`}:i.includes(e)?{disallowed:!0,message:`'${e}' is a reserved keyword in RescriptRelay and therefore cannot be used as a field name. Please alias your field to something else.`}:{disallowed:!1,message:""}}(e.alias);if(t)throw o("Found an invalid field name: "+n,[e.loc])}e.selections&&e.selections.forEach(s)}function l(e){return s(e),e}t.transform=function(e){return r.transform(e,{ScalarField:l,LinkedField:l})}},354:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.transform=void 0;const r=n(724),{createUserError:o}=n(182),{hasUnaliasedSelection:a}=n(124);function i(e){const t=this.getContext().getSchema();let n=this.traverse(e);if(t.isAbstractType(t.getRawType(n.type))&&!a(n,"__typename"))throw o('Unions and interfaces must have the field __typename explicitly selected. Please add __typename to the fields selected by "'+e.alias+'" in your operation.',[e.loc]);return n}t.transform=function(e){return r.transform(e,{LinkedField:i})}},366:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.processConcreteText=void 0,t.processConcreteText=function(e){let t=/(require\('.\/)([A-Za-z_.0-9/]+)(.graphql.\w*'\))/gm,n=e;const r=[];let o;for(;null!==(o=t.exec(e));){let[e,t,a]=o;const i=`node_${a}`;r.push({moduleName:a,identifier:i}),n=n.replace(e,`node_${a}`)}return{processedText:n,referencedNodes:r}}},129:e=>{e.exports=require("child_process")},747:e=>{e.exports=require("fs")},622:e=>{e.exports=require("path")},195:e=>{e.exports=require("relay-compiler")},182:e=>{e.exports=require("relay-compiler/lib/core/CompilerError")},724:e=>{e.exports=require("relay-compiler/lib/core/IRTransformer")},791:e=>{e.exports=require("relay-compiler/lib/language/javascript/RelayFlowGenerator")},124:e=>{e.exports=require("relay-compiler/lib/transforms/TransformUtils")}},t={};return function n(r){if(t[r])return t[r].exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}(607)})();
|