rescript-relay 3.5.1 → 4.0.0

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # master
2
2
 
3
+ # 4.0.0
4
+
5
+ - Support `@exhaustive` on interfaces as well.
6
+ - Remove `ReactDOMExperimental` module, since everything needed is in the official RescriptReact bindings now.
7
+ - Move fully to ReScript v12. From `4.x`, only v12 is supported.
8
+
3
9
  # 3.5.1
4
10
 
5
11
  - Build Linux PPX binary in Debian 11 (bullseye) container to improve compatibility with older glibc versions. The binary now requires glibc 2.31 instead of 2.39, supporting Amazon Linux 2023 (Vercel), Ubuntu 20.04+, Debian 11+, and RHEL 9+.
package/README.md CHANGED
@@ -69,7 +69,7 @@ let make = (~user) => {
69
69
  <div>
70
70
  <p>
71
71
  {React.string(
72
- userData.firstName ++ (" has " ++ (userData.friendCount->string_of_int ++ " friends.")),
72
+ userData.firstName ++ (" has " ++ (userData.friendCount->Int.toString ++ " friends.")),
73
73
  )}
74
74
  </p>
75
75
  </div>
@@ -100,11 +100,21 @@ let make = () => {
100
100
 
101
101
  ## Note about versioning
102
102
 
103
- There's plenty of work ongoing to bring RescriptRelay to full ReScript v11 support, including uncurried mode. Here's the versioning scheme that'll be followed going forward:
103
+ RescriptRelay has moved through a few major lines with different ReScript baselines. Use the compatibility guide below to pick the right versions:
104
+
105
+ ### Compatibility
106
+
107
+ | RescriptRelay | Required ReScript |
108
+ | ------------- | ----------------- |
109
+ | 4.x and newer | v12.x (or newer) |
110
+ | 3.x and below | v11.x (or older) |
111
+
112
+ Additional context on historical focus areas:
104
113
 
105
114
  - 1.x will receive critical bug fixes etc, but new features won't be added
106
- - 2.x will focus on compatibility with ReScript v11, and uncurried mode (uncurried mode will be optional). This is intended to make the transition to v11+ smooth
107
- - 3.x is fully embracing uncurried mode (no curried mode available), and adds a bunch of new stuff + change existing APIs to make them better and more ergonomic
115
+ - 2.x focuses on compatibility with ReScript v11, and uncurried mode (uncurried mode can be optional). This is intended to make the transition to v11+ smooth
116
+ - 3.x fully embraces uncurried mode (no curried mode available), and adds a bunch of new stuff + changes existing APIs to make them better and more ergonomic
117
+ - 4.x focuses exclusively on ReScript v12+.
108
118
 
109
119
  ## Examples
110
120
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rescript-relay",
3
- "version": "3.5.1",
3
+ "version": "4.0.0",
4
4
  "main": "src/RescriptRelay.res",
5
5
  "license": "MIT",
6
6
  "author": "Gabriel Nordeborn",
@@ -33,31 +33,36 @@
33
33
  },
34
34
  "scripts": {
35
35
  "build": "rescript",
36
- "build:test": "./build-compiler-dev.sh && ./rescript-relay-compiler",
36
+ "build:test": "./build-compiler-dev.sh && ./rescript-relay-compiler && ENABLE_PERSISTING=true ./rescript-relay-compiler && rm ./__tests_preloaded__/__generated__/RelaySchemaAssets_graphql.res",
37
37
  "postinstall": "node postinstall.js",
38
- "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
39
- "test:ci": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --ci --runInBand"
38
+ "test": "jest",
39
+ "test:ci": "jest --ci --runInBand"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@glennsl/rescript-fetch": "^0.2.0",
43
- "@rescript/react": "0.12.2",
43
+ "@rescript/react": "0.14.0",
44
44
  "@testing-library/jest-dom": "^5.16.3",
45
45
  "@testing-library/react": "^13.0.0-alpha.6",
46
46
  "graphql-query-test-mock": "^0.12.1",
47
47
  "jest": "^27.2.4",
48
+ "@babel/core": "^7.24.0",
49
+ "@babel/preset-env": "^7.24.0",
50
+ "@babel/plugin-syntax-dynamic-import": "^7.8.3",
51
+ "babel-jest": "^27.2.4",
52
+ "babel-plugin-dynamic-import-node": "^2.3.3",
48
53
  "nock": "^11.7.0",
49
54
  "node-fetch": "^2.6.0",
50
55
  "react": "18.2.0",
51
56
  "react-dom": "18.2.0",
52
57
  "react-relay": "20.1.1",
53
58
  "relay-runtime": "20.1.1",
54
- "rescript": "11.1.1"
59
+ "rescript": "12.0.0-rc.3"
55
60
  },
56
61
  "peerDependencies": {
57
62
  "@rescript/react": ">=0.13.0",
58
63
  "react-relay": "20.1.1",
59
64
  "relay-runtime": "20.1.1",
60
- "rescript": "^11.0.0"
65
+ "rescript": "^12.0.0-0"
61
66
  },
62
67
  "dependencies": {
63
68
  "detect-libc": "^2.0.1"
package/ppx-linux CHANGED
Binary file
package/ppx-macos-arm64 CHANGED
Binary file
package/ppx-macos-latest CHANGED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,45 +1,42 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
- var React = require("react");
5
- var Utils = require("./utils");
6
- var Js_dict = require("rescript/lib/js/js_dict.js");
7
- var Belt_Array = require("rescript/lib/js/belt_Array.js");
8
- var Belt_Option = require("rescript/lib/js/belt_Option.js");
9
- var Caml_option = require("rescript/lib/js/caml_option.js");
10
- var ReactRelay = require("react-relay");
11
- var RelayRuntime = require("relay-runtime");
12
- var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
13
- var LiveResolverStore = require("relay-runtime/lib/store/live-resolvers/LiveResolverStore").default;
14
- var LiveResolverStore$1 = require("relay-runtime/lib/store/live-resolvers/LiveResolverStore");
4
+ let React = require("react");
5
+ let Utils = require("./utils");
6
+ let ReactRelay = require("react-relay");
7
+ let Stdlib_Option = require("@rescript/runtime/lib/js/Stdlib_Option.js");
8
+ let RelayRuntime = require("relay-runtime");
9
+ let Primitive_option = require("@rescript/runtime/lib/js/Primitive_option.js");
10
+ let Primitive_exceptions = require("@rescript/runtime/lib/js/Primitive_exceptions.js");
11
+ let LiveResolverStore = require("relay-runtime/lib/store/live-resolvers/LiveResolverStore").default;
12
+ let LiveResolverStore$1 = require("relay-runtime/lib/store/live-resolvers/LiveResolverStore");
15
13
 
16
14
  function toOption(t) {
17
15
  if (t.ok === true) {
18
- return Caml_option.some(t.value);
16
+ return Primitive_option.some(t.value);
19
17
  }
20
-
21
18
  }
22
19
 
23
20
  function toResult(t) {
24
21
  if (t.ok === true) {
25
22
  return {
26
- TAG: "Ok",
27
- _0: t.value
28
- };
23
+ TAG: "Ok",
24
+ _0: t.value
25
+ };
29
26
  } else {
30
27
  return {
31
- TAG: "Error",
32
- _0: t.errors
33
- };
28
+ TAG: "Error",
29
+ _0: t.errors
30
+ };
34
31
  }
35
32
  }
36
33
 
37
- var CatchResult = {
34
+ let CatchResult = {
38
35
  toOption: toOption,
39
36
  toResult: toResult
40
37
  };
41
38
 
42
- var SuspenseSentinel = {};
39
+ let SuspenseSentinel = {};
43
40
 
44
41
  function convertObj(prim0, prim1, prim2, prim3) {
45
42
  return Utils.traverser(prim0, prim1, prim2, prim3);
@@ -47,114 +44,111 @@ function convertObj(prim0, prim1, prim2, prim3) {
47
44
 
48
45
  function optArrayOfNullableToOptArrayOfOpt(x) {
49
46
  if (x !== undefined) {
50
- return Belt_Array.map(x, (function (prim) {
51
- if (prim == null) {
52
- return ;
53
- } else {
54
- return Caml_option.some(prim);
55
- }
56
- }));
47
+ return x.map(prim => {
48
+ if (prim == null) {
49
+ return;
50
+ } else {
51
+ return Primitive_option.some(prim);
52
+ }
53
+ });
57
54
  }
58
-
59
55
  }
60
56
 
61
57
  function getLinkedRecords(t, name, $$arguments) {
62
- return optArrayOfNullableToOptArrayOfOpt(Caml_option.nullable_to_opt(t.getLinkedRecords(name, $$arguments)));
58
+ return optArrayOfNullableToOptArrayOfOpt(Primitive_option.fromNullable(t.getLinkedRecords(name, $$arguments)));
63
59
  }
64
60
 
65
- var RecordProxy = {
61
+ let RecordProxy = {
66
62
  getLinkedRecords: getLinkedRecords
67
63
  };
68
64
 
69
65
  function getPluralRootField(t, fieldName) {
70
- return optArrayOfNullableToOptArrayOfOpt(Caml_option.nullable_to_opt(t.getPluralRootField(fieldName)));
66
+ return optArrayOfNullableToOptArrayOfOpt(Primitive_option.fromNullable(t.getPluralRootField(fieldName)));
71
67
  }
72
68
 
73
69
  function invalidateRecordsByIds(store, recordIds) {
74
- recordIds.forEach(function (dataId) {
75
- Belt_Option.forEach(Caml_option.nullable_to_opt(store.get(dataId)), (function (r) {
76
- r.invalidateRecord();
77
- }));
78
- });
70
+ recordIds.forEach(dataId => Stdlib_Option.forEach(Primitive_option.fromNullable(store.get(dataId)), r => {
71
+ r.invalidateRecord();
72
+ }));
79
73
  }
80
74
 
81
- var RecordSourceSelectorProxy = {
75
+ let RecordSourceSelectorProxy = {
82
76
  getPluralRootField: getPluralRootField,
83
77
  invalidateRecordsByIds: invalidateRecordsByIds
84
78
  };
85
79
 
86
- var ReadOnlyRecordSourceProxy = {};
80
+ let ReadOnlyRecordSourceProxy = {};
87
81
 
88
82
  function unwrapNormalizationArgument(wrapped) {
89
- var match = wrapped.kind;
83
+ let match = wrapped.kind;
90
84
  if (match === "Literal") {
91
85
  return {
92
- TAG: "Literal",
93
- _0: wrapped
94
- };
86
+ TAG: "Literal",
87
+ _0: wrapped
88
+ };
95
89
  } else if (match === "ListValue") {
96
90
  return {
97
- TAG: "ListValue",
98
- _0: wrapped
99
- };
91
+ TAG: "ListValue",
92
+ _0: wrapped
93
+ };
100
94
  } else if (match === "ObjectValue") {
101
95
  return {
102
- TAG: "ObjectValue",
103
- _0: wrapped
104
- };
96
+ TAG: "ObjectValue",
97
+ _0: wrapped
98
+ };
105
99
  } else {
106
100
  return {
107
- TAG: "Variable",
108
- _0: wrapped
109
- };
101
+ TAG: "Variable",
102
+ _0: wrapped
103
+ };
110
104
  }
111
105
  }
112
106
 
113
107
  function makeScalarMissingFieldHandler(handle) {
114
108
  return {
115
- kind: "scalar",
116
- handle: handle
117
- };
109
+ kind: "scalar",
110
+ handle: handle
111
+ };
118
112
  }
119
113
 
120
114
  function makeLinkedMissingFieldHandler(handle) {
121
115
  return {
122
- kind: "linked",
123
- handle: handle
124
- };
116
+ kind: "linked",
117
+ handle: handle
118
+ };
125
119
  }
126
120
 
127
121
  function makePluralLinkedMissingFieldHandler(handle) {
128
122
  return {
129
- kind: "pluralLinked",
130
- handle: handle
131
- };
123
+ kind: "pluralLinked",
124
+ handle: handle
125
+ };
132
126
  }
133
127
 
134
- var MissingFieldHandler = {
128
+ let MissingFieldHandler = {
135
129
  unwrapNormalizationArgument: unwrapNormalizationArgument,
136
130
  makeScalarMissingFieldHandler: makeScalarMissingFieldHandler,
137
131
  makeLinkedMissingFieldHandler: makeLinkedMissingFieldHandler,
138
132
  makePluralLinkedMissingFieldHandler: makePluralLinkedMissingFieldHandler
139
133
  };
140
134
 
141
- var nodeInterfaceMissingFieldHandler = makeLinkedMissingFieldHandler(function (field, record, args, _store) {
142
- var match = field.name;
143
- var match$1 = args.id;
144
- if ((record == null) || !(match === "node" && record.getType() === RelayRuntime.ROOT_TYPE && !(match$1 == null))) {
145
- return ;
146
- } else {
147
- return Caml_option.some(match$1);
148
- }
149
- });
135
+ let nodeInterfaceMissingFieldHandler = makeLinkedMissingFieldHandler((field, record, args, _store) => {
136
+ let match = field.name;
137
+ let match$1 = args.id;
138
+ if ((record == null) || match !== "node" || record.getType() !== RelayRuntime.ROOT_TYPE || (match$1 == null)) {
139
+ return;
140
+ } else {
141
+ return Primitive_option.some(match$1);
142
+ }
143
+ });
150
144
 
151
- var ConnectionHandler = {};
145
+ let ConnectionHandler = {};
152
146
 
153
- var Disposable = {};
147
+ let Disposable = {};
154
148
 
155
- var Observable = {};
149
+ let Observable = {};
156
150
 
157
- var preloadResources = (function preloadResources(operation, variables, response) {
151
+ let preloadResources = (function preloadResources(operation, variables, response) {
158
152
  let metadata = operation.metadata;
159
153
  if (metadata == null) return;
160
154
  let codesplits = metadata.codesplits;
@@ -221,159 +215,149 @@ var preloadResources = (function preloadResources(operation, variables, response
221
215
  }
222
216
  });
223
217
 
224
- var Network = {
218
+ let Network = {
225
219
  preloadResources: preloadResources
226
220
  };
227
221
 
228
- var RecordSource = {};
222
+ let RecordSource = {};
229
223
 
230
224
  function make(source, gcReleaseBufferSize, queryCacheExpirationTime) {
231
225
  return new RelayRuntime.Store(source, {
232
- gcReleaseBufferSize: gcReleaseBufferSize,
233
- queryCacheExpirationTime: queryCacheExpirationTime
234
- });
226
+ gcReleaseBufferSize: gcReleaseBufferSize,
227
+ queryCacheExpirationTime: queryCacheExpirationTime
228
+ });
235
229
  }
236
230
 
237
231
  function makeLiveStore(source, gcReleaseBufferSize, queryCacheExpirationTime) {
238
232
  return new LiveResolverStore(source, {
239
- gcReleaseBufferSize: gcReleaseBufferSize,
240
- queryCacheExpirationTime: queryCacheExpirationTime
241
- });
233
+ gcReleaseBufferSize: gcReleaseBufferSize,
234
+ queryCacheExpirationTime: queryCacheExpirationTime
235
+ });
242
236
  }
243
237
 
244
238
  function _makeLiveStoreCjs(source, gcReleaseBufferSize, queryCacheExpirationTime) {
245
239
  return new LiveResolverStore$1(source, {
246
- gcReleaseBufferSize: gcReleaseBufferSize,
247
- queryCacheExpirationTime: queryCacheExpirationTime
248
- });
240
+ gcReleaseBufferSize: gcReleaseBufferSize,
241
+ queryCacheExpirationTime: queryCacheExpirationTime
242
+ });
249
243
  }
250
244
 
251
- var Store = {
245
+ let Store = {
252
246
  make: make,
253
247
  makeLiveStore: makeLiveStore,
254
248
  _makeLiveStoreCjs: _makeLiveStoreCjs
255
249
  };
256
250
 
257
- var RelayFieldLogger = {};
251
+ let RelayFieldLogger = {};
258
252
 
259
253
  function make$1(network, store, getDataID, treatMissingFieldsAsNull, missingFieldHandlers, relayFieldLogger, isServer) {
260
254
  return new RelayRuntime.Environment({
261
- network: network,
262
- store: store,
263
- getDataID: getDataID,
264
- treatMissingFieldsAsNull: treatMissingFieldsAsNull,
265
- missingFieldHandlers: missingFieldHandlers !== undefined ? Belt_Array.concat(missingFieldHandlers, [nodeInterfaceMissingFieldHandler]) : [nodeInterfaceMissingFieldHandler],
266
- relayFieldLogger: relayFieldLogger,
267
- isServer: isServer
268
- });
255
+ network: network,
256
+ store: store,
257
+ getDataID: getDataID,
258
+ treatMissingFieldsAsNull: treatMissingFieldsAsNull,
259
+ missingFieldHandlers: missingFieldHandlers !== undefined ? missingFieldHandlers.concat([nodeInterfaceMissingFieldHandler]) : [nodeInterfaceMissingFieldHandler],
260
+ relayFieldLogger: relayFieldLogger,
261
+ isServer: isServer
262
+ });
269
263
  }
270
264
 
271
265
  function findAllConnectionIds(environment, connectionKey, parentId) {
272
- var ids = [];
273
- var value = environment.getStore().getSource()._records.get(parentId);
266
+ let ids = [];
267
+ let value = environment.getStore().getSource()._records.get(parentId);
274
268
  if (value !== undefined) {
275
- Js_dict.entries(value).forEach(function (param) {
276
- if (param[0].startsWith("__" + connectionKey + "_connection")) {
277
- ids.push(param[1].__ref);
278
- return ;
279
- }
280
-
281
- });
269
+ Object.entries(value).forEach(param => {
270
+ if (param[0].startsWith("__" + connectionKey + "_connection")) {
271
+ ids.push(param[1].__ref);
272
+ return;
273
+ }
274
+ });
282
275
  }
283
276
  return ids;
284
277
  }
285
278
 
286
279
  function invalidateAllOfConnection(environment, connectionKey, parentId, excludedIdsOpt) {
287
- var excludedIds = excludedIdsOpt !== undefined ? excludedIdsOpt : [];
288
- RelayRuntime.commitLocalUpdate(environment, (function (store) {
289
- findAllConnectionIds(environment, connectionKey, parentId).forEach(function (dataId) {
290
- if (!excludedIds.includes(dataId)) {
291
- return Belt_Option.forEach(Caml_option.nullable_to_opt(store.get(dataId)), (function (r) {
292
- r.invalidateRecord();
293
- }));
294
- }
295
-
296
- });
297
- }));
280
+ let excludedIds = excludedIdsOpt !== undefined ? excludedIdsOpt : [];
281
+ RelayRuntime.commitLocalUpdate(environment, store => {
282
+ findAllConnectionIds(environment, connectionKey, parentId).forEach(dataId => {
283
+ if (!excludedIds.includes(dataId)) {
284
+ return Stdlib_Option.forEach(Primitive_option.fromNullable(store.get(dataId)), r => {
285
+ r.invalidateRecord();
286
+ });
287
+ }
288
+ });
289
+ });
298
290
  }
299
291
 
300
- var Environment = {
292
+ let Environment = {
301
293
  make: make$1,
302
294
  findAllConnectionIds: findAllConnectionIds,
303
295
  invalidateAllOfConnection: invalidateAllOfConnection
304
296
  };
305
297
 
306
298
  function RescriptRelay$Context$Provider(props) {
307
- var provider = ReactRelay.ReactRelayContext.Provider;
299
+ let provider = ReactRelay.ReactRelayContext.Provider;
308
300
  return React.createElement(provider, {
309
- value: {
310
- environment: props.environment
311
- },
312
- children: props.children
313
- });
301
+ value: {
302
+ environment: props.environment
303
+ },
304
+ children: props.children
305
+ });
314
306
  }
315
307
 
316
- var Provider = {
308
+ let Provider = {
317
309
  make: RescriptRelay$Context$Provider
318
310
  };
319
311
 
320
- var Context = {
312
+ let Context = {
321
313
  Provider: Provider
322
314
  };
323
315
 
324
- var EnvironmentNotFoundInContext = /* @__PURE__ */Caml_exceptions.create("RescriptRelay.EnvironmentNotFoundInContext");
316
+ let EnvironmentNotFoundInContext = /* @__PURE__ */Primitive_exceptions.create("RescriptRelay.EnvironmentNotFoundInContext");
325
317
 
326
318
  function useEnvironmentFromContext() {
327
- var context = React.useContext(ReactRelay.ReactRelayContext);
319
+ let context = React.useContext(ReactRelay.ReactRelayContext);
328
320
  if (context !== undefined) {
329
- return Caml_option.valFromOption(context).environment;
321
+ return Primitive_option.valFromOption(context).environment;
330
322
  }
331
323
  throw {
332
- RE_EXN_ID: EnvironmentNotFoundInContext,
333
- Error: new Error()
334
- };
324
+ RE_EXN_ID: EnvironmentNotFoundInContext,
325
+ Error: new Error()
326
+ };
335
327
  }
336
328
 
337
329
  function MakeLoadQuery(C) {
338
- var load = function (environment, variables, fetchPolicy, fetchKey, networkCacheConfig) {
339
- return ReactRelay.loadQuery(environment, C.query, C.convertVariables(variables), {
340
- fetchKey: fetchKey,
341
- fetchPolicy: fetchPolicy,
342
- networkCacheConfig: networkCacheConfig
343
- });
344
- };
345
- var queryRefToObservable = function (token) {
346
- return Caml_option.nullable_to_opt(token.source);
347
- };
348
- var queryRefToPromise = function (token) {
349
- return new Promise((function (resolve, param) {
350
- var o = queryRefToObservable(token);
351
- if (o !== undefined) {
352
- Caml_option.valFromOption(o).subscribe({
353
- complete: (function () {
354
- resolve({
355
- TAG: "Ok",
356
- _0: undefined
357
- });
358
- })
359
- });
360
- return ;
361
- } else {
362
- return resolve({
363
- TAG: "Error",
364
- _0: undefined
365
- });
366
- }
367
- }));
368
- };
330
+ let load = (environment, variables, fetchPolicy, fetchKey, networkCacheConfig) => ReactRelay.loadQuery(environment, C.query, C.convertVariables(variables), {
331
+ fetchKey: fetchKey,
332
+ fetchPolicy: fetchPolicy,
333
+ networkCacheConfig: networkCacheConfig
334
+ });
335
+ let queryRefToObservable = token => Primitive_option.fromNullable(token.source);
336
+ let queryRefToPromise = token => new Promise((resolve, param) => {
337
+ let o = queryRefToObservable(token);
338
+ if (o !== undefined) {
339
+ Primitive_option.valFromOption(o).subscribe({
340
+ complete: () => resolve({
341
+ TAG: "Ok",
342
+ _0: undefined
343
+ })
344
+ });
345
+ return;
346
+ } else {
347
+ return resolve({
348
+ TAG: "Error",
349
+ _0: undefined
350
+ });
351
+ }
352
+ });
369
353
  return {
370
- load: load,
371
- queryRefToObservable: queryRefToObservable,
372
- queryRefToPromise: queryRefToPromise
373
- };
354
+ load: load,
355
+ queryRefToObservable: queryRefToObservable,
356
+ queryRefToPromise: queryRefToPromise
357
+ };
374
358
  }
375
359
 
376
- var Mutation_failed = /* @__PURE__ */Caml_exceptions.create("RescriptRelay.Mutation_failed");
360
+ let Mutation_failed = /* @__PURE__ */Primitive_exceptions.create("RescriptRelay.Mutation_failed");
377
361
 
378
362
  exports.CatchResult = CatchResult;
379
363
  exports.SuspenseSentinel = SuspenseSentinel;