rescript-relay 0.0.0-cli-61b2cdf6 → 0.0.0-next-af0f6500

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/compiler.js ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var spawn = require("child_process").spawn;
5
+ var path = require("path");
6
+
7
+ var input = process.argv.slice(2);
8
+
9
+ spawn(path.join(__dirname, "rescript-relay-compiler.exe"), input, {
10
+ stdio: "inherit",
11
+ }).on("exit", process.exit);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rescript-relay",
3
- "version": "0.0.0-cli-61b2cdf6",
3
+ "version": "0.0.0-next-af0f6500",
4
4
  "main": "src/RescriptRelay.res",
5
5
  "license": "MIT",
6
6
  "author": "Gabriel Nordeborn",
@@ -19,51 +19,51 @@
19
19
  "reasonml",
20
20
  "rescript"
21
21
  ],
22
+ "exports": {
23
+ "./src/utils": {
24
+ "require": "./src/utils.js",
25
+ "import": "./src/utils.mjs"
26
+ },
27
+ "./src/*": "./src/*",
28
+ "./package.json": "./package.json"
29
+ },
22
30
  "bin": {
23
- "rescript-relay-compiler": "compiler/compiler-cli.js",
31
+ "rescript-relay-compiler": "compiler.js",
24
32
  "rescript-relay-cli": "cli/cli.js"
25
33
  },
26
34
  "scripts": {
27
35
  "build": "rescript build -with-deps",
28
- "build:test": "compiler/compiler-cli.js",
36
+ "build:test": "./build-compiler-dev.sh && ./rescript-relay-compiler",
29
37
  "postinstall": "node postinstall.js",
30
38
  "test": "jest",
31
39
  "test:ci": "jest --ci --runInBand"
32
40
  },
33
41
  "devDependencies": {
42
+ "rescript": "^9.1.2",
34
43
  "@rescript/react": "0.10.3",
35
- "@testing-library/jest-dom": "^4.2.4",
36
- "@testing-library/react": "^9.4.0",
44
+ "@testing-library/jest-dom": "^5.16.3",
45
+ "@testing-library/react": "^13.0.0-alpha.6",
37
46
  "bs-fetch": "^0.5.0",
38
- "graphql": "14.5.0",
39
47
  "graphql-query-test-mock": "^0.12.1",
40
- "jest": "^24.9.0",
48
+ "jest": "^27.2.4",
41
49
  "nock": "^11.7.0",
42
50
  "node-fetch": "^2.6.0",
43
- "react": "0.0.0-experimental-4e08fb10c",
44
- "react-dom": "0.0.0-experimental-4e08fb10c",
45
- "react-relay": "^11.0.0",
46
- "reason-promise": "^1.0.2",
47
- "relay-compiler": "^11.0.0",
48
- "relay-config": "^11.0.0",
49
- "relay-runtime": "^11.0.0"
51
+ "react": "18.0.0",
52
+ "react-dom": "18.0.0",
53
+ "react-relay": "14.1.0",
54
+ "relay-runtime": "14.1.0"
50
55
  },
51
56
  "peerDependencies": {
52
57
  "@rescript/react": "*",
53
- "graphql": "*",
54
- "react-relay": "*",
55
- "rescript": "^9.1.2",
56
- "reason-promise": "^1.0.2",
57
- "relay-compiler": "*",
58
- "relay-config": "*",
59
- "relay-runtime": "*"
58
+ "react-relay": ">=11.0.0",
59
+ "relay-runtime": "*",
60
+ "rescript": "^9.1.2"
60
61
  },
61
62
  "dependencies": {
62
- "mkdirp-sync": "^0.0.3",
63
- "rescript": "^9.1.2"
63
+ "detect-libc": "^2.0.1"
64
64
  },
65
65
  "resolutions": {
66
- "react": "0.0.0-experimental-4e08fb10c",
67
- "react-dom": "0.0.0-experimental-4e08fb10c"
66
+ "react": "18.0.0",
67
+ "react-dom": "18.0.0"
68
68
  }
69
69
  }
package/postinstall.js CHANGED
@@ -10,16 +10,32 @@
10
10
  var path = require("path");
11
11
  var cp = require("child_process");
12
12
  var fs = require("fs");
13
- var os = require("os");
13
+ var { isNonGlibcLinux } = require("detect-libc");
14
14
  var platform = process.platform;
15
15
 
16
+ function getRelayCompilerPlatformSuffix() {
17
+ if (process.platform === "win32") {
18
+ return "win-x64";
19
+ } else if (process.platform === "darwin" && process.arch === "x64") {
20
+ return "macos-x64";
21
+ } else if (process.platform === "darwin" && process.arch === "arm64") {
22
+ return "macos-arm64";
23
+ } else if (process.platform === "linux" && isNonGlibcLinux) {
24
+ return "linux-musl";
25
+ } else if (process.platform === "linux" && process.arch === "x64") {
26
+ return "linux-x64";
27
+ }
28
+
29
+ return "linux-x64";
30
+ }
31
+
16
32
  /**
17
33
  * Since os.arch returns node binary's target arch, not
18
34
  * the system arch.
19
35
  * Credits: https://github.com/feross/arch/blob/af080ff61346315559451715c5393d8e86a6d33c/index.js#L10-L58
20
36
  */
21
37
 
22
- function arch() {
38
+ function ppxArch() {
23
39
  /**
24
40
  * Use Rosetta for ARM on macOS
25
41
  */
@@ -80,44 +96,78 @@ function arch() {
80
96
  }
81
97
 
82
98
  function copyPlatformBinaries(platform) {
99
+ /**
100
+ * Copy the PPX
101
+ */
83
102
  fs.copyFileSync(
84
103
  path.join(__dirname, "ppx-" + platform),
85
104
  path.join(__dirname, "ppx")
86
105
  );
87
106
  fs.chmodSync(path.join(__dirname, "ppx"), 0777);
88
107
 
108
+ // Windows seems to need an .exe file as well.
109
+ if (platform === "windows-latest") {
110
+ fs.copyFileSync(
111
+ path.join(__dirname, "ppx-" + platform),
112
+ path.join(__dirname, "ppx.exe")
113
+ );
114
+ fs.chmodSync(path.join(__dirname, "ppx.exe"), 0777);
115
+ }
116
+
117
+ /**
118
+ * Copy the Relay compiler
119
+ */
120
+
121
+ var platformSuffix = getRelayCompilerPlatformSuffix();
122
+
89
123
  fs.copyFileSync(
90
- path.join(__dirname, "bin-" + platform),
91
- path.join(__dirname, "language-plugin", "RescriptRelayBin.exe")
92
- );
93
- fs.chmodSync(
94
- path.join(__dirname, "language-plugin", "RescriptRelayBin.exe"),
95
- 0777
124
+ path.join(
125
+ __dirname,
126
+ "relay-compiler-" + platformSuffix,
127
+ platformSuffix === "win-x64" ? "relay.exe" : "relay"
128
+ ),
129
+ path.join(__dirname, "rescript-relay-compiler.exe")
96
130
  );
131
+ fs.chmodSync(path.join(__dirname, "rescript-relay-compiler.exe"), 0777);
97
132
  }
98
133
 
99
134
  function removeInitialBinaries() {
100
- fs.unlinkSync(path.join(__dirname, "ppx-darwin"));
135
+ fs.unlinkSync(path.join(__dirname, "ppx-macos-latest"));
136
+ fs.unlinkSync(path.join(__dirname, "ppx-windows-latest"));
101
137
  fs.unlinkSync(path.join(__dirname, "ppx-linux"));
102
- fs.unlinkSync(path.join(__dirname, "bin-darwin"));
103
- fs.unlinkSync(path.join(__dirname, "bin-linux"));
138
+ fs.rmSync(path.join(__dirname, "relay-compiler-linux-x64"), {
139
+ recursive: true,
140
+ force: true,
141
+ });
142
+ fs.rmSync(path.join(__dirname, "relay-compiler-macos-x64"), {
143
+ recursive: true,
144
+ force: true,
145
+ });
146
+ fs.rmSync(path.join(__dirname, "relay-compiler-macos-arm64"), {
147
+ recursive: true,
148
+ force: true,
149
+ });
150
+ fs.rmSync(path.join(__dirname, "relay-compiler-linux-musl"), {
151
+ recursive: true,
152
+ force: true,
153
+ });
104
154
  }
105
155
 
106
156
  switch (platform) {
107
157
  case "win32": {
108
- if (arch() !== "x64") {
158
+ if (ppxArch() !== "x64") {
109
159
  console.warn("error: x86 is currently not supported on Windows");
110
160
  process.exit(1);
111
161
  }
112
-
113
- throw new Error("Windows currently not supported.");
114
- copyPlatformBinaries("windows");
162
+ copyPlatformBinaries("windows-latest");
115
163
  break;
116
164
  }
117
165
  case "linux":
118
- case "darwin":
119
166
  copyPlatformBinaries(platform);
120
167
  break;
168
+ case "darwin":
169
+ copyPlatformBinaries("macos-latest");
170
+ break;
121
171
  default:
122
172
  console.warn("error: no release built for the " + platform + " platform");
123
173
  process.exit(1);
package/ppx-linux CHANGED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,2 +1,20 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
- /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */
2
+ 'use strict';
3
+
4
+ var Client = require("react-dom/client");
5
+
6
+ function renderConcurrentRootAtElementWithId(content, id) {
7
+ var element = document.getElementById(id);
8
+ if (element == null) {
9
+ throw {
10
+ RE_EXN_ID: "Invalid_argument",
11
+ _1: "ReactExperimental.renderConcurrentRootAtElementWithId : no element of id " + id + " found in the HTML.",
12
+ Error: new Error()
13
+ };
14
+ }
15
+ Client.createRoot(element).render(content);
16
+
17
+ }
18
+
19
+ exports.renderConcurrentRootAtElementWithId = renderConcurrentRootAtElementWithId;
20
+ /* react-dom/client Not a pure module */
@@ -1,7 +1,19 @@
1
1
  include ReactDOM.Experimental
2
2
 
3
- @module("react-dom")
4
- external unstable_createRoot: Dom.element => root = "unstable_createRoot"
3
+ @module("react-dom/client")
4
+ external createRoot: Dom.element => root = "createRoot"
5
5
 
6
- @module("react-dom")
7
- external unstable_createBlockingRoot: Dom.element => root = "unstable_createBlockingRoot"
6
+ @val @return(nullable)
7
+ external getElementById: string => option<Dom.element> = "document.getElementById"
8
+
9
+ let renderConcurrentRootAtElementWithId: (React.element, string) => unit = (content, id) =>
10
+ switch getElementById(id) {
11
+ | None =>
12
+ raise(
13
+ Invalid_argument(
14
+ "ReactExperimental.renderConcurrentRootAtElementWithId : no element of id " ++
15
+ id ++ " found in the HTML.",
16
+ ),
17
+ )
18
+ | Some(element) => createRoot(element)->render(content)
19
+ }
@@ -1,23 +1,21 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
- var ReactDom = require("react-dom");
4
+ var React = require("react");
5
5
 
6
- var SuspenseList = {};
7
-
8
- function renderConcurrentRootAtElementWithId(content, id) {
9
- var element = document.getElementById(id);
10
- if (element == null) {
11
- throw {
12
- RE_EXN_ID: "Invalid_argument",
13
- _1: "ReactExperimental.renderConcurrentRootAtElementWithId : no element of id " + id + " found in the HTML.",
14
- Error: new Error()
15
- };
16
- }
17
- ReactDom.unstable_createRoot(element).render(content);
18
-
6
+ function useTransition(param) {
7
+ var match = React.useTransition();
8
+ var startTransition = match[1];
9
+ return [
10
+ match[0],
11
+ React.useCallback((function (cb) {
12
+ return startTransition(cb, undefined);
13
+ }), [startTransition])
14
+ ];
19
15
  }
20
16
 
17
+ var SuspenseList = {};
18
+
19
+ exports.useTransition = useTransition;
21
20
  exports.SuspenseList = SuspenseList;
22
- exports.renderConcurrentRootAtElementWithId = renderConcurrentRootAtElementWithId;
23
- /* react-dom Not a pure module */
21
+ /* react Not a pure module */
@@ -1,32 +1,21 @@
1
- type callback<'input, 'output> = 'input => 'output
2
-
3
1
  @module("react")
4
- external unstable_useDeferredValue: 'value => 'value = "unstable_useDeferredValue"
2
+ external useDeferredValue: 'value => 'value = "useDeferredValue"
5
3
 
6
4
  @module("react")
7
- external unstable_useTransition: unit => (callback<callback<unit, unit>, unit>, bool) =
8
- "unstable_useTransition"
5
+ external useTransitionWithOptions: unit => (
6
+ bool,
7
+ (. unit => unit, option<{"name": option<string>}>) => unit,
8
+ ) = "useTransition"
9
+
10
+ let useTransition = () => {
11
+ let (isPending, startTransition) = useTransitionWithOptions()
12
+ (isPending, React.useCallback1(cb => startTransition(. cb, None), [startTransition]))
13
+ }
9
14
 
10
15
  module SuspenseList = {
11
16
  @module("react") @react.component
12
17
  external make: (
13
18
  ~children: React.element,
14
19
  ~revealOrder: [#forwards | #backwards | #together]=?,
15
- ) => React.element = "unstable_SuspenseList"
20
+ ) => React.element = "SuspenseList"
16
21
  }
17
-
18
- @val @return(nullable)
19
- external getElementById: string => option<Dom.element> = "document.getElementById"
20
-
21
- let renderConcurrentRootAtElementWithId: (React.element, string) => unit = (content, id) =>
22
- switch getElementById(id) {
23
- | None =>
24
- raise(
25
- Invalid_argument(
26
- "ReactExperimental.renderConcurrentRootAtElementWithId : no element of id " ++
27
- id ++ " found in the HTML.",
28
- ),
29
- )
30
- | Some(element) =>
31
- ReactDOMExperimental.unstable_createRoot(element)->ReactDOMExperimental.render(content)
32
- }
@@ -0,0 +1,18 @@
1
+ @module("react")
2
+ external useDeferredValue: 'value => 'value = "useDeferredValue"
3
+
4
+ @module("react")
5
+ external useTransitionWithOptions: unit => (
6
+ bool,
7
+ (. unit => unit, option<{"name": option<string>}>) => unit,
8
+ ) = "useTransition"
9
+
10
+ let useTransition: unit => (bool, React.callback<unit => unit, unit>)
11
+
12
+ module SuspenseList: {
13
+ @module("react") @react.component
14
+ external make: (
15
+ ~children: React.element,
16
+ ~revealOrder: [#forwards | #backwards | #together]=?,
17
+ ) => React.element = "SuspenseList"
18
+ }
@@ -4,13 +4,12 @@
4
4
  var Curry = require("rescript/lib/js/curry.js");
5
5
  var React = require("react");
6
6
  var Utils = require("./utils");
7
- var $$Promise = require("reason-promise/src/js/promise.bs.js");
8
7
  var Belt_Array = require("rescript/lib/js/belt_Array.js");
8
+ var Belt_Option = require("rescript/lib/js/belt_Option.js");
9
9
  var Caml_option = require("rescript/lib/js/caml_option.js");
10
10
  var ReactRelay = require("react-relay");
11
11
  var RelayRuntime = require("relay-runtime");
12
12
  var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
13
- var Hooks = require("react-relay/hooks");
14
13
 
15
14
  function convertObj(prim0, prim1, prim2, prim3) {
16
15
  return Utils.traverser(prim0, prim1, prim2, prim3);
@@ -131,7 +130,11 @@ var Store = {
131
130
  make: make
132
131
  };
133
132
 
134
- function make$1(network, store, getDataID, treatMissingFieldsAsNull, missingFieldHandlers, param) {
133
+ function toJs(f, arg) {
134
+ return Curry._3(f, arg.kind, arg.owner, arg.fieldPath);
135
+ }
136
+
137
+ function make$1(network, store, getDataID, treatMissingFieldsAsNull, missingFieldHandlers, requiredFieldLogger, isServer, param) {
135
138
  var tmp = {
136
139
  network: network,
137
140
  store: store,
@@ -143,6 +146,13 @@ function make$1(network, store, getDataID, treatMissingFieldsAsNull, missingFiel
143
146
  if (treatMissingFieldsAsNull !== undefined) {
144
147
  tmp.treatMissingFieldsAsNull = Caml_option.valFromOption(treatMissingFieldsAsNull);
145
148
  }
149
+ var tmp$1 = Belt_Option.map(requiredFieldLogger, toJs);
150
+ if (tmp$1 !== undefined) {
151
+ tmp.requiredFieldLogger = Caml_option.valFromOption(tmp$1);
152
+ }
153
+ if (isServer !== undefined) {
154
+ tmp.isServer = Caml_option.valFromOption(isServer);
155
+ }
146
156
  return new RelayRuntime.Environment(tmp);
147
157
  }
148
158
 
@@ -150,11 +160,10 @@ var Environment = {
150
160
  make: make$1
151
161
  };
152
162
 
153
- var provider = ReactRelay.ReactRelayContext.Provider;
154
-
155
163
  function RescriptRelay$Context$Provider(Props) {
156
164
  var environment = Props.environment;
157
165
  var children = Props.children;
166
+ var provider = ReactRelay.ReactRelayContext.Provider;
158
167
  return React.createElement(provider, {
159
168
  value: {
160
169
  environment: environment
@@ -167,6 +176,10 @@ var Provider = {
167
176
  make: RescriptRelay$Context$Provider
168
177
  };
169
178
 
179
+ var Context = {
180
+ Provider: Provider
181
+ };
182
+
170
183
  var EnvironmentNotFoundInContext = /* @__PURE__ */Caml_exceptions.create("RescriptRelay.EnvironmentNotFoundInContext");
171
184
 
172
185
  function useEnvironmentFromContext(param) {
@@ -210,7 +223,7 @@ function mapFetchQueryFetchPolicy(x) {
210
223
 
211
224
  function MakeLoadQuery(C) {
212
225
  var load = function (environment, variables, fetchPolicy, fetchKey, networkCacheConfig, param) {
213
- return Hooks.loadQuery(environment, C.query, Curry._1(C.convertVariables, variables), {
226
+ return ReactRelay.loadQuery(environment, C.query, Curry._1(C.convertVariables, variables), {
214
227
  fetchKey: fetchKey,
215
228
  fetchPolicy: mapFetchPolicy(fetchPolicy),
216
229
  networkCacheConfig: networkCacheConfig
@@ -220,25 +233,25 @@ function MakeLoadQuery(C) {
220
233
  return Caml_option.nullable_to_opt(token.source);
221
234
  };
222
235
  var queryRefToPromise = function (token) {
223
- var match = $$Promise.pending(undefined);
224
- var resolve = match[1];
225
- var o = queryRefToObservable(token);
226
- if (o !== undefined) {
227
- Caml_option.valFromOption(o).subscribe({
228
- complete: (function (param) {
229
- return Curry._1(resolve, {
230
- TAG: /* Ok */0,
231
- _0: undefined
232
- });
233
- })
234
- });
235
- } else {
236
- Curry._1(resolve, {
237
- TAG: /* Error */1,
238
- _0: undefined
239
- });
240
- }
241
- return match[0];
236
+ return new Promise((function (resolve, param) {
237
+ var o = queryRefToObservable(token);
238
+ if (o !== undefined) {
239
+ Caml_option.valFromOption(o).subscribe({
240
+ complete: (function (param) {
241
+ return resolve({
242
+ TAG: /* Ok */0,
243
+ _0: undefined
244
+ });
245
+ })
246
+ });
247
+ return ;
248
+ } else {
249
+ return resolve({
250
+ TAG: /* Error */1,
251
+ _0: undefined
252
+ });
253
+ }
254
+ }));
242
255
  };
243
256
  return {
244
257
  load: load,
@@ -249,9 +262,7 @@ function MakeLoadQuery(C) {
249
262
 
250
263
  var Mutation_failed = /* @__PURE__ */Caml_exceptions.create("RescriptRelay.Mutation_failed");
251
264
 
252
- var Context = {
253
- Provider: Provider
254
- };
265
+ var RequiredFieldLogger = {};
255
266
 
256
267
  exports.convertObj = convertObj;
257
268
  exports.RecordProxy = RecordProxy;
@@ -264,6 +275,7 @@ exports.Network = Network;
264
275
  exports.RecordSource = RecordSource;
265
276
  exports.Store = Store;
266
277
  exports.Disposable = Disposable;
278
+ exports.RequiredFieldLogger = RequiredFieldLogger;
267
279
  exports.Environment = Environment;
268
280
  exports.mapFetchPolicy = mapFetchPolicy;
269
281
  exports.mapFetchQueryFetchPolicy = mapFetchQueryFetchPolicy;