@kaiko.io/rescript-deser 5.0.1 → 6.0.0-alpha.2

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/README.md CHANGED
@@ -1,7 +1,15 @@
1
- # bs-deser
1
+ # Deser
2
2
 
3
3
  Simple JSON deserializer for ReScript.
4
4
 
5
+ **Note**: In Rescript 12, this will be kind of useless. So this will be
6
+ likely be the last version series of Deser.
7
+
8
+ **Important**: Version 6+ changed the name of the module from `JSON` to
9
+ `Deser` to avoid clashes with `RescriptCore.JSON`.
10
+
11
+ You may want to watch the tests live here: https://kaiko-systems.gitlab.io/rescript-deser/
12
+
5
13
  ## Description
6
14
 
7
15
  This module allows you to create deserialize structures from JSON into an
@@ -12,7 +20,7 @@ type-correct.
12
20
 
13
21
  ## Usage
14
22
 
15
- You need to create a description of your data using ``JSON.Field.t``.
23
+ You need to create a description of your data using ``Deser.Field.t``.
16
24
 
17
25
  ```rescript
18
26
  module MyData = {
@@ -25,9 +33,9 @@ module MyData = {
25
33
  }
26
34
  }
27
35
 
28
- module MyDataDeserializer = JSON.MakeDeserializer({
36
+ module MyDataDeserializer = Deser.MakeDeserializer({
29
37
  type t = MyData.t
30
- open JSON.Field
38
+ open Deser.Field
31
39
 
32
40
  let fields = Object([
33
41
  ("id", String),
@@ -74,43 +82,43 @@ module type Serializable = {
74
82
  - `Date`, parses either a string representation of a date (datetime) or a
75
83
  floating point representation of date (datetime) into `Js.Date.t`; we make
76
84
  sure the result is valid and won't return NaN afterwards.
77
-
85
+
78
86
  This basically calls, `Js.Date.fromString` or `Js.Date.fromFloat`; and tests
79
87
  the resulting value.
80
-
88
+
81
89
  `Datetime` is an alias for `Date`.
82
-
90
+
83
91
  - `Optional(Field.t)`, allow the field to be missing from the JSON data in
84
92
  which case, return `None`; if the field is present and valid return
85
93
  `Some(value)`.
86
-
94
+
87
95
  - `OptionalWithDefault(Field.t, FieldValue.t)`; same as optional but return a
88
96
  default value instead. Notice, this is unsafe if the actual type of the
89
97
  default value does not match the expected type.
90
-
98
+
91
99
  - `Tuple(array<Field.t>)`, parses a JSON list with an exact number of items of
92
100
  varying types.
93
101
 
94
102
  - `Object(array<(string, Field.t)>)`, parses a JSON object that should have
95
103
  exactly the fields described; missing items are not allowed unless they are
96
104
  `Optional`, `OptionalWithDefault`.
97
-
105
+
98
106
  - `Mapping(Field.t)`, parses a JSON object with unknown keys (of type string)
99
107
  and a given type of value. Valid values have the internal type
100
108
  `Prelude.Dict.t`.
101
-
109
+
102
110
  - `Deserializer(module(Deserializer))`, parses an JSON object with the function
103
111
  `fromJSON` of another deserializer. This allows the composition of
104
112
  deserializers.
105
-
113
+
106
114
  - `Collection(module(Deserializer))`, parses a list of items with the function
107
- `fromJSON` of another deserializer. Invalid items are ignored.
108
-
115
+ `fromJSON` of another deserializer. Invalid items are ignored.
116
+
109
117
  This is basically a shortcut to
110
118
  `Array(DefaultWhenInvalid(Optional(Deserializer(module(M))),
111
119
  FieldValue.null))`, with the additional post-processing to remove `None`
112
120
  values.
113
-
121
+
114
122
  - `DefaultWhenInvalid(Field.t, FieldValue.t)`, if the JSON contains an invalid
115
123
  value, use a default instead.
116
124
 
@@ -151,4 +159,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
151
159
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
152
160
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
153
161
  SOFTWARE.
154
-
package/lib/bs/.bsbuild CHANGED
Binary file
package/lib/bs/.bsdeps CHANGED
@@ -2,8 +2,8 @@
2
2
  /home/manu/src/kaiko/rescript-deser
3
3
  0
4
4
  0
5
- rescript.json 0x1.9ca88a0b3f476p+30
6
- tests 0x1.93fb8b23e3f01p+30
7
- src/ 0x1.9683f1e026f57p+30
5
+ rescript.json 0x1.9d272e38c4598p+30
6
+ tests 0x1.9d272e38c7c35p+30
7
+ src/ 0x1.9d272e38c4598p+30
8
8
  ===
9
9
  /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/rescript.exe 0x1.9bfaa0e1df3b2p+30
@@ -1,2 +1,2 @@
1
- #Start(1730814618733)
2
- #Done(1730814618768)
1
+ #Start(1732894377391)
2
+ #Done(1732894377391)
package/lib/bs/.ninja_log CHANGED
@@ -1,43 +1,31 @@
1
1
  # ninja log v6
2
- 0 5 1730814327787200781 tests/QUnit.ast 57ee93358e339a9a
3
- 0 5 1730814327787200781 tests/index.ast dc1dfb2fd51740e6
4
- 5 7 1730814327790534214 tests/QUnit.d 4a2631c992d93ce7
5
- 5 7 1730814327790534214 tests/index.d 5a4db9cdecd186b3
6
- 0 7 1730814327790534214 src/JSON.ast 649b5b6311a6b7e3
7
- 7 9 1730814327790534214 src/JSON.d cd2d6773c781340f
8
- 7 14 1730814327797201080 tests/QUnit.cmj e668f43fbb8ee318
9
- 7 14 1730814327797201080 tests/QUnit.cmi e668f43fbb8ee318
10
- 7 14 1730814327797201080 ../es6/tests/QUnit.js e668f43fbb8ee318
11
- 7 14 1730814327797201080 ../js/tests/QUnit.js e668f43fbb8ee318
12
- 9 27 1730814327810534813 src/JSON.cmj 5528d45e9269dbc7
13
- 9 27 1730814327810534813 src/JSON.cmi 5528d45e9269dbc7
14
- 9 27 1730814327810534813 ../es6/src/JSON.js 5528d45e9269dbc7
15
- 9 27 1730814327810534813 ../js/src/JSON.js 5528d45e9269dbc7
16
- 27 40 1730814327823868546 tests/index.cmj 2318094a30b68775
17
- 27 40 1730814327823868546 tests/index.cmi 2318094a30b68775
18
- 27 40 1730814327823868546 ../es6/tests/index.js 2318094a30b68775
19
- 27 40 1730814327823868546 ../js/tests/index.js 2318094a30b68775
20
- 0 9 1730814327790534214 tests/QUnit.cmj bbb941b31c5437b8
21
- 0 9 1730814327790534214 tests/QUnit.cmi bbb941b31c5437b8
22
- 0 9 1730814327790534214 ../es6/tests/QUnit.js bbb941b31c5437b8
23
- 0 9 1730814327790534214 ../js/tests/QUnit.js bbb941b31c5437b8
24
- 0 19 1730814327790534214 src/JSON.cmj dde7600b09c15a91
25
- 0 19 1730814327790534214 src/JSON.cmi dde7600b09c15a91
26
- 0 19 1730814327790534214 ../es6/src/JSON.js dde7600b09c15a91
27
- 0 19 1730814327790534214 ../js/src/JSON.js dde7600b09c15a91
28
- 19 33 1730814327807201380 tests/index.cmj 417742d12a492c9c
29
- 19 33 1730814327807201380 tests/index.cmi 417742d12a492c9c
30
- 19 33 1730814327807201380 ../es6/tests/index.js 417742d12a492c9c
31
- 19 33 1730814327807201380 ../js/tests/index.js 417742d12a492c9c
32
- 0 9 1730814327790534214 tests/QUnit.cmj 2ff3910d4c2b9db9
33
- 0 9 1730814327790534214 tests/QUnit.cmi 2ff3910d4c2b9db9
34
- 0 9 1730814327790534214 ../es6/tests/QUnit.js 2ff3910d4c2b9db9
35
- 0 9 1730814327790534214 ../js/tests/QUnit.js 2ff3910d4c2b9db9
36
- 1 24 1730814327790534214 src/JSON.cmj 6ce2f96753b60cef
37
- 1 24 1730814327790534214 src/JSON.cmi 6ce2f96753b60cef
38
- 1 24 1730814327790534214 ../es6/src/JSON.js 6ce2f96753b60cef
39
- 1 24 1730814327790534214 ../js/src/JSON.js 6ce2f96753b60cef
40
- 24 35 1730814327807201380 tests/index.cmj 318bc4b129e02820
41
- 24 35 1730814327807201380 tests/index.cmi 318bc4b129e02820
42
- 24 35 1730814327807201380 ../es6/tests/index.js 318bc4b129e02820
43
- 24 35 1730814327807201380 ../js/tests/index.js 318bc4b129e02820
2
+ 1 9 1732888969609093921 tests/index.ast 901a254e17150891
3
+ 0 9 1732888969605760485 tests/QUnit.ast 24679400da87e6b0
4
+ 0 11 1732888969609093921 src/Deser.ast 60777bbe51986b3b
5
+ 9 11 1732888969609093921 tests/QUnit.d f74946ee3200f9fa
6
+ 9 12 1732888969609093921 tests/index.d 44655d60e4c70d26
7
+ 11 13 1732888969612427357 src/Deser.d 691c816990b589e8
8
+ 11 18 1732888969615760793 tests/QUnit.cmj dfd5051a1aed6ad1
9
+ 11 18 1732888969615760793 tests/QUnit.cmi dfd5051a1aed6ad1
10
+ 11 18 1732888969615760793 ../es6/tests/QUnit.js dfd5051a1aed6ad1
11
+ 11 18 1732888969615760793 ../js/tests/QUnit.js dfd5051a1aed6ad1
12
+ 14 36 1732888969635761410 src/Deser.cmj 59c93988df369be8
13
+ 14 36 1732888969635761410 src/Deser.cmi 59c93988df369be8
14
+ 14 36 1732888969635761410 ../es6/src/Deser.js 59c93988df369be8
15
+ 14 36 1732888969635761410 ../js/src/Deser.js 59c93988df369be8
16
+ 36 48 1732888969645761719 tests/index.cmj 1492142736e6fe59
17
+ 36 48 1732888969645761719 tests/index.cmi 1492142736e6fe59
18
+ 36 48 1732888969645761719 ../es6/tests/index.js 1492142736e6fe59
19
+ 36 48 1732888969645761719 ../js/tests/index.js 1492142736e6fe59
20
+ 1 7 1732889720608155890 tests/index.ast 901a254e17150891
21
+ 7 9 1732889720608155890 tests/index.d 44655d60e4c70d26
22
+ 1 9 1732889720611489309 src/Deser.ast 60777bbe51986b3b
23
+ 9 10 1732889720611489309 src/Deser.d 691c816990b589e8
24
+ 10 29 1732889720611489309 src/Deser.cmj 59c93988df369be8
25
+ 10 29 1732889720611489309 src/Deser.cmi 59c93988df369be8
26
+ 10 29 1732889720611489309 ../es6/src/Deser.js 59c93988df369be8
27
+ 10 29 1732889720611489309 ../js/src/Deser.js 59c93988df369be8
28
+ 29 43 1732889720608155890 tests/index.cmj 1492142736e6fe59
29
+ 29 43 1732889720608155890 tests/index.cmi 1492142736e6fe59
30
+ 29 43 1732889720608155890 ../es6/tests/index.js 1492142736e6fe59
31
+ 29 43 1732889720608155890 ../js/tests/index.js 1492142736e6fe59
@@ -1 +1 @@
1
- { "dirs" : [ "tests" , "src/" ] , "pkgs" : [ [ "@kaiko.io/rescript-prelude" , "/home/manu/src/kaiko/rescript-deser/node_modules/@kaiko.io/rescript-prelude" ] ] , "generated" : [] }
1
+ { "dirs" : [ "tests" , "src/" ] , "pkgs" : [ [ "@rescript/core" , "/home/manu/src/kaiko/rescript-deser/node_modules/@rescript/core" ] ] , "generated" : [] }
@@ -1,27 +1,27 @@
1
1
  rescript = 1
2
- g_finger := /home/manu/src/kaiko/rescript-deser/node_modules/@kaiko.io/rescript-prelude/lib/ocaml/install.stamp
2
+ g_finger := /home/manu/src/kaiko/rescript-deser/node_modules/@rescript/core/lib/ocaml/install.stamp
3
3
  rule astj
4
- command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsc.exe -warn-error +8+11+26+27+33+56 -bs-v 11.1.4 -uncurried -absname -bs-ast -o $out $i
4
+ command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsc.exe -warn-error +8+11+26+33+56 -bs-v 11.1.4 -uncurried -absname -bs-ast -o $out $i
5
5
  o tests/index.ast : astj ../../tests/index.res
6
6
  rule deps_dev
7
- command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsb_helper.exe -g -hash 84aecc33f8594375b23a1a137b057f93 $in
7
+ command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsb_helper.exe -g -hash 9a7a4be86983dcab705bb67a1ec483c7 $in
8
8
  restat = 1
9
9
  o tests/index.d : deps_dev tests/index.ast
10
10
  rule mij_dev
11
- command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsc.exe -I tests -I src/ -I /home/manu/src/kaiko/rescript-deser/node_modules/@kaiko.io/rescript-prelude/lib/ocaml -warn-error +8+11+26+27+33+56 -uncurried -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$in_d:.js -bs-package-output esmodule:lib/es6/$in_d:.js -bs-v $g_finger $i
11
+ command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsc.exe -I tests -I src/ -I /home/manu/src/kaiko/rescript-deser/node_modules/@rescript/core/lib/ocaml -warn-error +8+11+26+33+56 -uncurried -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$in_d:.js -bs-package-output esmodule:lib/es6/$in_d:.js -bs-v $g_finger $i
12
12
  dyndep = 1
13
13
  restat = 1
14
14
  o tests/index.cmj tests/index.cmi ../es6/tests/index.js ../js/tests/index.js : mij_dev tests/index.ast
15
15
  o tests/QUnit.ast : astj ../../tests/QUnit.res
16
16
  o tests/QUnit.d : deps_dev tests/QUnit.ast
17
17
  o tests/QUnit.cmj tests/QUnit.cmi ../es6/tests/QUnit.js ../js/tests/QUnit.js : mij_dev tests/QUnit.ast
18
- o src/JSON.ast : astj ../../src/JSON.res
18
+ o src/Deser.ast : astj ../../src/Deser.res
19
19
  rule deps
20
- command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsb_helper.exe -hash 84aecc33f8594375b23a1a137b057f93 $in
20
+ command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsb_helper.exe -hash 9a7a4be86983dcab705bb67a1ec483c7 $in
21
21
  restat = 1
22
- o src/JSON.d : deps src/JSON.ast
22
+ o src/Deser.d : deps src/Deser.ast
23
23
  rule mij
24
- command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsc.exe -I src/ -I /home/manu/src/kaiko/rescript-deser/node_modules/@kaiko.io/rescript-prelude/lib/ocaml -warn-error +8+11+26+27+33+56 -uncurried -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$in_d:.js -bs-package-output esmodule:lib/es6/$in_d:.js -bs-v $g_finger $i
24
+ command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsc.exe -I src/ -I /home/manu/src/kaiko/rescript-deser/node_modules/@rescript/core/lib/ocaml -warn-error +8+11+26+33+56 -uncurried -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$in_d:.js -bs-package-output esmodule:lib/es6/$in_d:.js -bs-v $g_finger $i
25
25
  dyndep = 1
26
26
  restat = 1
27
- o src/JSON.cmj src/JSON.cmi ../es6/src/JSON.js ../js/src/JSON.js : mij src/JSON.ast
27
+ o src/Deser.cmj src/Deser.cmi ../es6/src/Deser.js ../js/src/Deser.js : mij src/Deser.ast
@@ -3,8 +3,8 @@ rule cp
3
3
  command = cp $i $out
4
4
  rule touch
5
5
  command = touch $out
6
- o JSON.cmi : cp ../bs/src/JSON.cmi
7
- o JSON.cmj : cp ../bs/src/JSON.cmj
8
- o JSON.cmt : cp ../bs/src/JSON.cmt
9
- o JSON.res : cp ../../src/JSON.res
10
- build install.stamp : touch JSON.cmi JSON.cmj
6
+ o Deser.cmi : cp ../bs/src/Deser.cmi
7
+ o Deser.cmj : cp ../bs/src/Deser.cmj
8
+ o Deser.cmt : cp ../bs/src/Deser.cmt
9
+ o Deser.res : cp ../../src/Deser.res
10
+ build install.stamp : touch Deser.cmi Deser.cmj
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1 +1 @@
1
- tests/index.cmj : src/JSON.cmj src/JSON.cmi tests/QUnit.cmj tests/QUnit.cmi
1
+ tests/index.cmj : src/Deser.cmj src/Deser.cmi tests/QUnit.cmj tests/QUnit.cmi
@@ -1,15 +1,18 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as Curry from "rescript/lib/es6/curry.js";
4
3
  import * as Js_json from "rescript/lib/es6/js_json.js";
5
- import * as Prelude from "@kaiko.io/rescript-prelude/lib/es6/src/Prelude.js";
4
+ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
5
+ import * as Core__Dict from "@rescript/core/lib/es6/src/Core__Dict.js";
6
6
  import * as Caml_option from "rescript/lib/es6/caml_option.js";
7
+ import * as Core__Array from "@rescript/core/lib/es6/src/Core__Array.js";
8
+ import * as Core__Option from "@rescript/core/lib/es6/src/Core__Option.js";
9
+ import * as Core__Result from "@rescript/core/lib/es6/src/Core__Result.js";
7
10
  import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
8
11
  import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
9
12
 
10
13
  var FieldValue = {};
11
14
 
12
- var $$TypeError = /* @__PURE__ */Caml_exceptions.create("JSON.TypeError");
15
+ var $$TypeError = /* @__PURE__ */Caml_exceptions.create("Deser.TypeError");
13
16
 
14
17
  function usingString(f) {
15
18
  return function (value) {
@@ -58,7 +61,7 @@ function variadicInt(hint, fromJs) {
58
61
  }
59
62
  throw {
60
63
  RE_EXN_ID: $$TypeError,
61
- _1: "This Int(" + String(value) + ") not a valid value here. Hint: " + hint,
64
+ _1: "This Int(" + value.toString() + ") not a valid value here. Hint: " + hint,
62
65
  Error: new Error()
63
66
  };
64
67
  })
@@ -150,18 +153,18 @@ function _taggedToString(tagged) {
150
153
  case "JSONString" :
151
154
  return "String(\"" + tagged._0 + "\")";
152
155
  case "JSONNumber" :
153
- return "Number(" + String(tagged._0) + ")";
156
+ return "Number(" + tagged._0.toString() + ")";
154
157
  case "JSONObject" :
155
- return "Object(" + Prelude.default(JSON.stringify(tagged._0), "...") + ")";
158
+ return "Object(" + Core__Option.getOr(JSON.stringify(tagged._0), "...") + ")";
156
159
  case "JSONArray" :
157
- return "Array(" + Prelude.default(JSON.stringify(tagged._0), "...") + ")";
160
+ return "Array(" + Core__Option.getOr(JSON.stringify(tagged._0), "...") + ")";
158
161
 
159
162
  }
160
163
  }
161
164
  }
162
165
 
163
166
  function extractValue(values, field, shape, self) {
164
- var value = Curry._2(Prelude.Dict.get, values, field);
167
+ var value = values[field];
165
168
  if (value !== undefined) {
166
169
  return fromUntagged(value, shape, self);
167
170
  }
@@ -325,13 +328,13 @@ function fromUntagged(untagged, _shape, self) {
325
328
  var lenbases = bases.length;
326
329
  var lenitems = items.length;
327
330
  if (lenbases === lenitems) {
328
- return Curry._3(Prelude.$$Array.zipBy, items, bases, (function (i, b) {
331
+ return Belt_Array.zipBy(items, bases, (function (i, b) {
329
332
  return fromUntagged(i, b, self);
330
333
  }));
331
334
  }
332
335
  throw {
333
336
  RE_EXN_ID: $$TypeError,
334
- _1: "Expecting " + String(lenbases) + " items, got " + String(lenitems),
337
+ _1: "Expecting " + lenbases.toString() + " items, got " + lenitems.toString(),
335
338
  Error: new Error()
336
339
  };
337
340
  }
@@ -344,7 +347,7 @@ function fromUntagged(untagged, _shape, self) {
344
347
  } else {
345
348
  if (match.TAG === "JSONObject") {
346
349
  var values = match._0;
347
- return Curry._1(Prelude.Dict.fromArray, shape._0.map((function(values){
350
+ return Object.fromEntries(shape._0.map((function(values){
348
351
  return function (param) {
349
352
  var field = param[0];
350
353
  var value;
@@ -402,7 +405,7 @@ function fromUntagged(untagged, _shape, self) {
402
405
  } else {
403
406
  if (match.TAG === "JSONObject") {
404
407
  var f$1 = shape._0;
405
- return Prelude.Dict.mapValues(match._0, (function(f$1){
408
+ return Core__Dict.mapValues(match._0, (function(f$1){
406
409
  return function (v) {
407
410
  return fromUntagged(v, f$1, self);
408
411
  }
@@ -426,7 +429,9 @@ function fromUntagged(untagged, _shape, self) {
426
429
  exit = 1;
427
430
  } else {
428
431
  if (match.TAG === "JSONArray") {
429
- return Prelude.$$Array.keepSome(match._0.map(shape._0.fromJSON).map(Prelude.Result.warn)).map(function (prim) {
432
+ return match._0.map(shape._0.fromJSON).filter(function (x) {
433
+ return Core__Result.isOk(x);
434
+ }).map(function (prim) {
430
435
  return prim;
431
436
  });
432
437
  }
@@ -510,17 +515,26 @@ function checkFieldsSanity(name, _fields, _optional) {
510
515
  } else {
511
516
  switch (fields.TAG) {
512
517
  case "Tuple" :
513
- return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(fields._0.map((function(optional){
518
+ return Core__Result.map(Core__Array.reduce(fields._0.map((function(optional){
514
519
  return function (field, index) {
515
520
  return function () {
516
- return checkFieldsSanity(name + "[" + String(index) + "]", field, optional);
521
+ return checkFieldsSanity(name + "[" + index.toString() + "]", field, optional);
517
522
  };
518
523
  }
519
- }(optional)))), (function (param) {
524
+ }(optional))), {
525
+ TAG: "Ok",
526
+ _0: []
527
+ }, (function (res, nextitem) {
528
+ return Core__Result.flatMap(res, (function (arr) {
529
+ return Core__Result.map(nextitem(), (function (i) {
530
+ return arr.concat([i]);
531
+ }));
532
+ }));
533
+ })), (function (param) {
520
534
 
521
535
  }));
522
536
  case "Object" :
523
- return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(fields._0.map((function(optional){
537
+ return Core__Result.map(Core__Array.reduce(fields._0.map((function(optional){
524
538
  return function (param) {
525
539
  var field = param[1];
526
540
  var fieldName = param[0];
@@ -528,7 +542,16 @@ function checkFieldsSanity(name, _fields, _optional) {
528
542
  return checkFieldsSanity(name + "::" + fieldName, field, optional);
529
543
  };
530
544
  }
531
- }(optional)))), (function (param) {
545
+ }(optional))), {
546
+ TAG: "Ok",
547
+ _0: []
548
+ }, (function (res, nextitem) {
549
+ return Core__Result.flatMap(res, (function (arr) {
550
+ return Core__Result.map(nextitem(), (function (i) {
551
+ return arr.concat([i]);
552
+ }));
553
+ }));
554
+ })), (function (param) {
532
555
 
533
556
  }));
534
557
  case "Array" :
@@ -593,7 +616,7 @@ var Field = {
593
616
 
594
617
  function MakeDeserializer(S) {
595
618
  var fields = S.fields;
596
- var name = "Deserializer " + "JSON" + ", " + "File \"JSON.res\", line 319, characters 39-47";
619
+ var name = "Deserializer " + "Deser" + ", " + "File \"Deser.res\", line 322, characters 39-47";
597
620
  var checkFieldsSanity$1 = function () {
598
621
  return checkFieldsSanity(name, fields, false);
599
622
  };
@@ -1,9 +1,8 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
- import * as $$JSON from "../src/JSON.js";
4
- import * as Curry from "rescript/lib/es6/curry.js";
3
+ import * as Deser from "../src/Deser.js";
5
4
  import * as Qunit from "qunit";
6
- import * as Prelude from "@kaiko.io/rescript-prelude/lib/es6/src/Prelude.js";
5
+ import * as Core__Result from "@rescript/core/lib/es6/src/Core__Result.js";
7
6
 
8
7
  var fields = {
9
8
  TAG: "Object",
@@ -26,7 +25,7 @@ var fields = {
26
25
  ]
27
26
  };
28
27
 
29
- var Deserializer = $$JSON.MakeDeserializer({
28
+ var Deserializer = Deser.MakeDeserializer({
30
29
  fields: fields
31
30
  });
32
31
 
@@ -59,16 +58,16 @@ Qunit.module("Basic deserializer", (function (param) {
59
58
  ];
60
59
  Qunit.test("Correctly deserializes data", (function (qunit) {
61
60
  qunit.expect(valid.length);
62
- Curry._2(Prelude.$$Array.forEach, valid, (function (param) {
63
- var data = param[0];
64
- console.log("Running sample", data);
65
- var result = Deserializer.fromJSON(data);
66
- if (result.TAG === "Ok") {
67
- qunit.deepEqual(result._0, param[1], "result == expected");
68
- return ;
69
- }
70
- console.error(result._0);
71
- }));
61
+ valid.forEach(function (param) {
62
+ var data = param[0];
63
+ console.log("Running sample", data);
64
+ var result = Deserializer.fromJSON(data);
65
+ if (result.TAG === "Ok") {
66
+ qunit.deepEqual(result._0, param[1], "result == expected");
67
+ return ;
68
+ }
69
+ console.error(result._0);
70
+ });
72
71
  }));
73
72
  var invalid = [[
74
73
  "Missing non-optional field",
@@ -76,17 +75,17 @@ Qunit.module("Basic deserializer", (function (param) {
76
75
  ]];
77
76
  Qunit.test("Correctly catches invalid data", (function (qunit) {
78
77
  qunit.expect(invalid.length);
79
- Curry._2(Prelude.$$Array.forEach, invalid, (function (param) {
80
- var data = param[1];
81
- console.log("Running sample", param[0], data);
82
- var result = Deserializer.fromJSON(data);
83
- if (result.TAG === "Ok") {
84
- console.error("Invalid being accepted: ", result._0);
85
- return ;
86
- }
87
- console.log("Correctly detected:", result._0);
88
- qunit.ok(true, true);
89
- }));
78
+ invalid.forEach(function (param) {
79
+ var data = param[1];
80
+ console.log("Running sample", param[0], data);
81
+ var result = Deserializer.fromJSON(data);
82
+ if (result.TAG === "Ok") {
83
+ console.error("Invalid being accepted: ", result._0);
84
+ return ;
85
+ }
86
+ console.log("Correctly detected:", result._0);
87
+ qunit.ok(true, true);
88
+ });
90
89
  }));
91
90
  }));
92
91
 
@@ -107,13 +106,13 @@ Qunit.module("Recursive deserializer", (function (param) {
107
106
  ]
108
107
  ]
109
108
  };
110
- var DeserializerImpl = $$JSON.MakeDeserializer({
109
+ var DeserializerImpl = Deser.MakeDeserializer({
111
110
  fields: fields
112
111
  });
113
112
  var checkFieldsSanity = DeserializerImpl.checkFieldsSanity;
114
113
  var fromJSON = function (data) {
115
- return Curry._2(Prelude.Result.map, DeserializerImpl.fromJSON(data), (function (prim) {
116
- return prim;
114
+ return Core__Result.map(DeserializerImpl.fromJSON(data), (function (x) {
115
+ return x;
117
116
  }));
118
117
  };
119
118
  var valid = [[
@@ -162,11 +161,11 @@ Qunit.module("Recursive deserializer", (function (param) {
162
161
  ]
163
162
  ]
164
163
  };
165
- var InfiniteList = $$JSON.MakeDeserializer({
164
+ var InfiniteList = Deser.MakeDeserializer({
166
165
  fields: fields
167
166
  });
168
167
  qunit.expect(1);
169
- qunit.deepEqual(Curry._1(Prelude.Result.isError, InfiniteList.checkFieldsSanity()), true, "Ok");
168
+ qunit.deepEqual(Core__Result.isError(InfiniteList.checkFieldsSanity()), true, "Ok");
170
169
  }));
171
170
  Qunit.test("Finite list", (function (qunit) {
172
171
  var fields = {
@@ -185,7 +184,7 @@ Qunit.module("Recursive deserializer", (function (param) {
185
184
  ]
186
185
  ]
187
186
  };
188
- var List = $$JSON.MakeDeserializer({
187
+ var List = Deser.MakeDeserializer({
189
188
  fields: fields
190
189
  });
191
190
  qunit.expect(1);
@@ -196,16 +195,16 @@ Qunit.module("Recursive deserializer", (function (param) {
196
195
  }));
197
196
  Qunit.test("Correctly deserializes recursive data", (function (qunit) {
198
197
  qunit.expect(valid.length);
199
- Curry._2(Prelude.$$Array.forEach, valid, (function (param) {
200
- var data = param[0];
201
- console.log("Running sample", data);
202
- var result = fromJSON(data);
203
- if (result.TAG === "Ok") {
204
- qunit.deepEqual(result._0, param[1], "result == expected");
205
- return ;
206
- }
207
- console.error(result._0);
208
- }));
198
+ valid.forEach(function (param) {
199
+ var data = param[0];
200
+ console.log("Running sample", data);
201
+ var result = fromJSON(data);
202
+ if (result.TAG === "Ok") {
203
+ qunit.deepEqual(result._0, param[1], "result == expected");
204
+ return ;
205
+ }
206
+ console.error(result._0);
207
+ });
209
208
  }));
210
209
  Qunit.test("Recursion in sub-deserializer", (function (qunit) {
211
210
  var fields = {
@@ -224,7 +223,7 @@ Qunit.module("Recursive deserializer", (function (param) {
224
223
  ]
225
224
  ]
226
225
  };
227
- var List = $$JSON.MakeDeserializer({
226
+ var List = Deser.MakeDeserializer({
228
227
  fields: fields
229
228
  });
230
229
  var fields$1 = {
@@ -246,7 +245,7 @@ Qunit.module("Recursive deserializer", (function (param) {
246
245
  ]
247
246
  ]
248
247
  };
249
- var Ledger = $$JSON.MakeDeserializer({
248
+ var Ledger = Deser.MakeDeserializer({
250
249
  fields: fields$1
251
250
  });
252
251
  var data = {"records": {"head": "A", "tail": {"head": "B"}},
@@ -1,16 +1,19 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
- var Curry = require("rescript/lib/js/curry.js");
5
4
  var Js_json = require("rescript/lib/js/js_json.js");
6
- var Prelude = require("@kaiko.io/rescript-prelude/lib/js/src/Prelude.js");
5
+ var Belt_Array = require("rescript/lib/js/belt_Array.js");
6
+ var Core__Dict = require("@rescript/core/lib/js/src/Core__Dict.js");
7
7
  var Caml_option = require("rescript/lib/js/caml_option.js");
8
+ var Core__Array = require("@rescript/core/lib/js/src/Core__Array.js");
9
+ var Core__Option = require("@rescript/core/lib/js/src/Core__Option.js");
10
+ var Core__Result = require("@rescript/core/lib/js/src/Core__Result.js");
8
11
  var Caml_exceptions = require("rescript/lib/js/caml_exceptions.js");
9
12
  var Caml_js_exceptions = require("rescript/lib/js/caml_js_exceptions.js");
10
13
 
11
14
  var FieldValue = {};
12
15
 
13
- var $$TypeError = /* @__PURE__ */Caml_exceptions.create("JSON.TypeError");
16
+ var $$TypeError = /* @__PURE__ */Caml_exceptions.create("Deser.TypeError");
14
17
 
15
18
  function usingString(f) {
16
19
  return function (value) {
@@ -59,7 +62,7 @@ function variadicInt(hint, fromJs) {
59
62
  }
60
63
  throw {
61
64
  RE_EXN_ID: $$TypeError,
62
- _1: "This Int(" + String(value) + ") not a valid value here. Hint: " + hint,
65
+ _1: "This Int(" + value.toString() + ") not a valid value here. Hint: " + hint,
63
66
  Error: new Error()
64
67
  };
65
68
  })
@@ -151,18 +154,18 @@ function _taggedToString(tagged) {
151
154
  case "JSONString" :
152
155
  return "String(\"" + tagged._0 + "\")";
153
156
  case "JSONNumber" :
154
- return "Number(" + String(tagged._0) + ")";
157
+ return "Number(" + tagged._0.toString() + ")";
155
158
  case "JSONObject" :
156
- return "Object(" + Prelude.default(JSON.stringify(tagged._0), "...") + ")";
159
+ return "Object(" + Core__Option.getOr(JSON.stringify(tagged._0), "...") + ")";
157
160
  case "JSONArray" :
158
- return "Array(" + Prelude.default(JSON.stringify(tagged._0), "...") + ")";
161
+ return "Array(" + Core__Option.getOr(JSON.stringify(tagged._0), "...") + ")";
159
162
 
160
163
  }
161
164
  }
162
165
  }
163
166
 
164
167
  function extractValue(values, field, shape, self) {
165
- var value = Curry._2(Prelude.Dict.get, values, field);
168
+ var value = values[field];
166
169
  if (value !== undefined) {
167
170
  return fromUntagged(value, shape, self);
168
171
  }
@@ -326,13 +329,13 @@ function fromUntagged(untagged, _shape, self) {
326
329
  var lenbases = bases.length;
327
330
  var lenitems = items.length;
328
331
  if (lenbases === lenitems) {
329
- return Curry._3(Prelude.$$Array.zipBy, items, bases, (function (i, b) {
332
+ return Belt_Array.zipBy(items, bases, (function (i, b) {
330
333
  return fromUntagged(i, b, self);
331
334
  }));
332
335
  }
333
336
  throw {
334
337
  RE_EXN_ID: $$TypeError,
335
- _1: "Expecting " + String(lenbases) + " items, got " + String(lenitems),
338
+ _1: "Expecting " + lenbases.toString() + " items, got " + lenitems.toString(),
336
339
  Error: new Error()
337
340
  };
338
341
  }
@@ -345,7 +348,7 @@ function fromUntagged(untagged, _shape, self) {
345
348
  } else {
346
349
  if (match.TAG === "JSONObject") {
347
350
  var values = match._0;
348
- return Curry._1(Prelude.Dict.fromArray, shape._0.map((function(values){
351
+ return Object.fromEntries(shape._0.map((function(values){
349
352
  return function (param) {
350
353
  var field = param[0];
351
354
  var value;
@@ -403,7 +406,7 @@ function fromUntagged(untagged, _shape, self) {
403
406
  } else {
404
407
  if (match.TAG === "JSONObject") {
405
408
  var f$1 = shape._0;
406
- return Prelude.Dict.mapValues(match._0, (function(f$1){
409
+ return Core__Dict.mapValues(match._0, (function(f$1){
407
410
  return function (v) {
408
411
  return fromUntagged(v, f$1, self);
409
412
  }
@@ -427,7 +430,9 @@ function fromUntagged(untagged, _shape, self) {
427
430
  exit = 1;
428
431
  } else {
429
432
  if (match.TAG === "JSONArray") {
430
- return Prelude.$$Array.keepSome(match._0.map(shape._0.fromJSON).map(Prelude.Result.warn)).map(function (prim) {
433
+ return match._0.map(shape._0.fromJSON).filter(function (x) {
434
+ return Core__Result.isOk(x);
435
+ }).map(function (prim) {
431
436
  return prim;
432
437
  });
433
438
  }
@@ -511,17 +516,26 @@ function checkFieldsSanity(name, _fields, _optional) {
511
516
  } else {
512
517
  switch (fields.TAG) {
513
518
  case "Tuple" :
514
- return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(fields._0.map((function(optional){
519
+ return Core__Result.map(Core__Array.reduce(fields._0.map((function(optional){
515
520
  return function (field, index) {
516
521
  return function () {
517
- return checkFieldsSanity(name + "[" + String(index) + "]", field, optional);
522
+ return checkFieldsSanity(name + "[" + index.toString() + "]", field, optional);
518
523
  };
519
524
  }
520
- }(optional)))), (function (param) {
525
+ }(optional))), {
526
+ TAG: "Ok",
527
+ _0: []
528
+ }, (function (res, nextitem) {
529
+ return Core__Result.flatMap(res, (function (arr) {
530
+ return Core__Result.map(nextitem(), (function (i) {
531
+ return arr.concat([i]);
532
+ }));
533
+ }));
534
+ })), (function (param) {
521
535
 
522
536
  }));
523
537
  case "Object" :
524
- return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(fields._0.map((function(optional){
538
+ return Core__Result.map(Core__Array.reduce(fields._0.map((function(optional){
525
539
  return function (param) {
526
540
  var field = param[1];
527
541
  var fieldName = param[0];
@@ -529,7 +543,16 @@ function checkFieldsSanity(name, _fields, _optional) {
529
543
  return checkFieldsSanity(name + "::" + fieldName, field, optional);
530
544
  };
531
545
  }
532
- }(optional)))), (function (param) {
546
+ }(optional))), {
547
+ TAG: "Ok",
548
+ _0: []
549
+ }, (function (res, nextitem) {
550
+ return Core__Result.flatMap(res, (function (arr) {
551
+ return Core__Result.map(nextitem(), (function (i) {
552
+ return arr.concat([i]);
553
+ }));
554
+ }));
555
+ })), (function (param) {
533
556
 
534
557
  }));
535
558
  case "Array" :
@@ -594,7 +617,7 @@ var Field = {
594
617
 
595
618
  function MakeDeserializer(S) {
596
619
  var fields = S.fields;
597
- var name = "Deserializer " + "JSON" + ", " + "File \"JSON.res\", line 319, characters 39-47";
620
+ var name = "Deserializer " + "Deser" + ", " + "File \"Deser.res\", line 322, characters 39-47";
598
621
  var checkFieldsSanity$1 = function () {
599
622
  return checkFieldsSanity(name, fields, false);
600
623
  };
@@ -1,10 +1,9 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
  'use strict';
3
3
 
4
- var $$JSON = require("../src/JSON.js");
5
- var Curry = require("rescript/lib/js/curry.js");
4
+ var Deser = require("../src/Deser.js");
6
5
  var Qunit = require("qunit");
7
- var Prelude = require("@kaiko.io/rescript-prelude/lib/js/src/Prelude.js");
6
+ var Core__Result = require("@rescript/core/lib/js/src/Core__Result.js");
8
7
 
9
8
  var fields = {
10
9
  TAG: "Object",
@@ -27,7 +26,7 @@ var fields = {
27
26
  ]
28
27
  };
29
28
 
30
- var Deserializer = $$JSON.MakeDeserializer({
29
+ var Deserializer = Deser.MakeDeserializer({
31
30
  fields: fields
32
31
  });
33
32
 
@@ -60,16 +59,16 @@ Qunit.module("Basic deserializer", (function (param) {
60
59
  ];
61
60
  Qunit.test("Correctly deserializes data", (function (qunit) {
62
61
  qunit.expect(valid.length);
63
- Curry._2(Prelude.$$Array.forEach, valid, (function (param) {
64
- var data = param[0];
65
- console.log("Running sample", data);
66
- var result = Deserializer.fromJSON(data);
67
- if (result.TAG === "Ok") {
68
- qunit.deepEqual(result._0, param[1], "result == expected");
69
- return ;
70
- }
71
- console.error(result._0);
72
- }));
62
+ valid.forEach(function (param) {
63
+ var data = param[0];
64
+ console.log("Running sample", data);
65
+ var result = Deserializer.fromJSON(data);
66
+ if (result.TAG === "Ok") {
67
+ qunit.deepEqual(result._0, param[1], "result == expected");
68
+ return ;
69
+ }
70
+ console.error(result._0);
71
+ });
73
72
  }));
74
73
  var invalid = [[
75
74
  "Missing non-optional field",
@@ -77,17 +76,17 @@ Qunit.module("Basic deserializer", (function (param) {
77
76
  ]];
78
77
  Qunit.test("Correctly catches invalid data", (function (qunit) {
79
78
  qunit.expect(invalid.length);
80
- Curry._2(Prelude.$$Array.forEach, invalid, (function (param) {
81
- var data = param[1];
82
- console.log("Running sample", param[0], data);
83
- var result = Deserializer.fromJSON(data);
84
- if (result.TAG === "Ok") {
85
- console.error("Invalid being accepted: ", result._0);
86
- return ;
87
- }
88
- console.log("Correctly detected:", result._0);
89
- qunit.ok(true, true);
90
- }));
79
+ invalid.forEach(function (param) {
80
+ var data = param[1];
81
+ console.log("Running sample", param[0], data);
82
+ var result = Deserializer.fromJSON(data);
83
+ if (result.TAG === "Ok") {
84
+ console.error("Invalid being accepted: ", result._0);
85
+ return ;
86
+ }
87
+ console.log("Correctly detected:", result._0);
88
+ qunit.ok(true, true);
89
+ });
91
90
  }));
92
91
  }));
93
92
 
@@ -108,13 +107,13 @@ Qunit.module("Recursive deserializer", (function (param) {
108
107
  ]
109
108
  ]
110
109
  };
111
- var DeserializerImpl = $$JSON.MakeDeserializer({
110
+ var DeserializerImpl = Deser.MakeDeserializer({
112
111
  fields: fields
113
112
  });
114
113
  var checkFieldsSanity = DeserializerImpl.checkFieldsSanity;
115
114
  var fromJSON = function (data) {
116
- return Curry._2(Prelude.Result.map, DeserializerImpl.fromJSON(data), (function (prim) {
117
- return prim;
115
+ return Core__Result.map(DeserializerImpl.fromJSON(data), (function (x) {
116
+ return x;
118
117
  }));
119
118
  };
120
119
  var valid = [[
@@ -163,11 +162,11 @@ Qunit.module("Recursive deserializer", (function (param) {
163
162
  ]
164
163
  ]
165
164
  };
166
- var InfiniteList = $$JSON.MakeDeserializer({
165
+ var InfiniteList = Deser.MakeDeserializer({
167
166
  fields: fields
168
167
  });
169
168
  qunit.expect(1);
170
- qunit.deepEqual(Curry._1(Prelude.Result.isError, InfiniteList.checkFieldsSanity()), true, "Ok");
169
+ qunit.deepEqual(Core__Result.isError(InfiniteList.checkFieldsSanity()), true, "Ok");
171
170
  }));
172
171
  Qunit.test("Finite list", (function (qunit) {
173
172
  var fields = {
@@ -186,7 +185,7 @@ Qunit.module("Recursive deserializer", (function (param) {
186
185
  ]
187
186
  ]
188
187
  };
189
- var List = $$JSON.MakeDeserializer({
188
+ var List = Deser.MakeDeserializer({
190
189
  fields: fields
191
190
  });
192
191
  qunit.expect(1);
@@ -197,16 +196,16 @@ Qunit.module("Recursive deserializer", (function (param) {
197
196
  }));
198
197
  Qunit.test("Correctly deserializes recursive data", (function (qunit) {
199
198
  qunit.expect(valid.length);
200
- Curry._2(Prelude.$$Array.forEach, valid, (function (param) {
201
- var data = param[0];
202
- console.log("Running sample", data);
203
- var result = fromJSON(data);
204
- if (result.TAG === "Ok") {
205
- qunit.deepEqual(result._0, param[1], "result == expected");
206
- return ;
207
- }
208
- console.error(result._0);
209
- }));
199
+ valid.forEach(function (param) {
200
+ var data = param[0];
201
+ console.log("Running sample", data);
202
+ var result = fromJSON(data);
203
+ if (result.TAG === "Ok") {
204
+ qunit.deepEqual(result._0, param[1], "result == expected");
205
+ return ;
206
+ }
207
+ console.error(result._0);
208
+ });
210
209
  }));
211
210
  Qunit.test("Recursion in sub-deserializer", (function (qunit) {
212
211
  var fields = {
@@ -225,7 +224,7 @@ Qunit.module("Recursive deserializer", (function (param) {
225
224
  ]
226
225
  ]
227
226
  };
228
- var List = $$JSON.MakeDeserializer({
227
+ var List = Deser.MakeDeserializer({
229
228
  fields: fields
230
229
  });
231
230
  var fields$1 = {
@@ -247,7 +246,7 @@ Qunit.module("Recursive deserializer", (function (param) {
247
246
  ]
248
247
  ]
249
248
  };
250
- var Ledger = $$JSON.MakeDeserializer({
249
+ var Ledger = Deser.MakeDeserializer({
251
250
  fields: fields$1
252
251
  });
253
252
  var data = {"records": {"head": "A", "tail": {"head": "B"}},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaiko.io/rescript-deser",
3
- "version": "5.0.1",
3
+ "version": "6.0.0-alpha.2",
4
4
  "keywords": [
5
5
  "json",
6
6
  "deserializer",
@@ -15,18 +15,20 @@
15
15
  "lib",
16
16
  "src",
17
17
  "tests",
18
- "www",
19
18
  "rescript.json",
20
19
  "README.md"
21
20
  ],
22
21
  "peerDependencies": {
23
- "@kaiko.io/rescript-prelude": ">=7.2.0",
22
+ "@rescript/core": ">=1.6",
24
23
  "rescript": ">=11.1.0"
25
24
  },
26
25
  "devDependencies": {
27
- "@kaiko.io/rescript-prelude": "7.2.0",
28
- "esbuild": "0.15.7",
29
- "qunit": "2.16.0",
30
- "rescript": "11.1.4"
26
+ "@babel/code-frame": "7.18.6",
27
+ "@jihchi/vite-plugin-rescript": "^6.0",
28
+ "@rescript/core": "^1.6.0",
29
+ "@rescript/tools": "0.6.4",
30
+ "qunit": "^2.16.0",
31
+ "rescript": "^11.1.0",
32
+ "vite": "^5.4.0"
31
33
  }
32
34
  }
package/rescript.json CHANGED
@@ -10,9 +10,8 @@
10
10
  "type": "dev"
11
11
  }
12
12
  ],
13
- "suffix": ".js",
14
13
  "bs-dependencies": [
15
- "@kaiko.io/rescript-prelude"
14
+ "@rescript/core"
16
15
  ],
17
16
  "uncurried": true,
18
17
  "package-specs": [
@@ -24,6 +23,6 @@
24
23
  }
25
24
  ],
26
25
  "warnings": {
27
- "error": "+8+11+26+27+33+56"
26
+ "error": "+8+11+26+33+56"
28
27
  }
29
28
  }
@@ -1,4 +1,4 @@
1
- open Prelude
1
+ open RescriptCore
2
2
 
3
3
  module FieldValue = {
4
4
  type t
@@ -142,8 +142,8 @@ module Field = {
142
142
  | Js.Json.JSONNull => "Null"
143
143
  | Js.Json.JSONString(text) => `String("${text}")`
144
144
  | Js.Json.JSONNumber(number) => `Number(${number->Float.toString})`
145
- | Js.Json.JSONObject(obj) => `Object(${obj->Js.Json.stringifyAny->default("...")})`
146
- | Js.Json.JSONArray(array) => `Array(${array->Js.Json.stringifyAny->default("...")})`
145
+ | Js.Json.JSONObject(obj) => `Object(${obj->Js.Json.stringifyAny->Option.getOr("...")})`
146
+ | Js.Json.JSONArray(array) => `Array(${array->Js.Json.stringifyAny->Option.getOr("...")})`
147
147
  }
148
148
  }
149
149
 
@@ -182,7 +182,7 @@ module Field = {
182
182
  let lenbases = bases->Array.length
183
183
  let lenitems = items->Array.length
184
184
  if lenbases == lenitems {
185
- let values = Array.zipBy(items, bases, (i, b) => fromUntagged(i, b, self))
185
+ let values = Belt.Array.zipBy(items, bases, (i, b) => fromUntagged(i, b, self))
186
186
  values->FieldValue.array
187
187
  } else {
188
188
  raise(
@@ -236,8 +236,7 @@ module Field = {
236
236
  module M = unpack(m: Deserializer)
237
237
  items
238
238
  ->Array.map(M.fromJSON)
239
- ->Array.map(Result.warn)
240
- ->Array.keepSome
239
+ ->Array.filter(x => x->Result.isOk)
241
240
  ->Array.map(FieldValue.any)
242
241
  ->FieldValue.array
243
242
  }
@@ -292,8 +291,10 @@ module Field = {
292
291
  fields
293
292
  ->Array.map(((fieldName, field)) => () =>
294
293
  checkFieldsSanity(`${name}::${fieldName}`, field, optional))
295
- ->ManyResults.bailU
296
- ->ManyResults.map(_ => ())
294
+ ->Array.reduce(Ok([]), (res, nextitem) =>
295
+ res->Result.flatMap(arr => nextitem()->Result.map(i => arr->Array.concat([i])))
296
+ )
297
+ ->Result.map(_ => ())
297
298
 
298
299
  /// Mappings and arrays can be empty, so their payloads are
299
300
  /// automatically optional.
@@ -303,8 +304,10 @@ module Field = {
303
304
  fields
304
305
  ->Array.mapWithIndex((field, index) => () =>
305
306
  checkFieldsSanity(`${name}[${index->Int.toString}]`, field, optional))
306
- ->ManyResults.bailU
307
- ->ManyResults.map(_ => ())
307
+ ->Array.reduce(Ok([]), (res, nextitem) =>
308
+ res->Result.flatMap(arr => nextitem()->Result.map(i => arr->Array.concat([i])))
309
+ )
310
+ ->Result.map(_ => ())
308
311
  }
309
312
  }
310
313
 
package/tests/index.res CHANGED
@@ -1,8 +1,5 @@
1
- open JSON
2
1
  open QUnit
3
- open Prelude
4
-
5
- %%private(external cast: 'a => 'b = "%identity")
2
+ open RescriptCore
6
3
 
7
4
  module Appointment = {
8
5
  type t = {
@@ -10,9 +7,9 @@ module Appointment = {
10
7
  date: Js.Date.t,
11
8
  extra: option<string>,
12
9
  }
13
- module Deserializer = MakeDeserializer({
10
+ module Deserializer = Deser.MakeDeserializer({
14
11
  type t = t
15
- open JSON.Field
12
+ open Deser.Field
16
13
 
17
14
  let fields = Object([("note", String), ("date", Date), ("extra", Optional(String))])
18
15
  })
@@ -86,13 +83,13 @@ module_("Recursive deserializer", _ => {
86
83
  children: array<t<'a>>,
87
84
  }
88
85
 
89
- module DeserializerImpl = MakeDeserializer({
86
+ module DeserializerImpl = Deser.MakeDeserializer({
90
87
  type payload
91
88
  type rec t = {
92
89
  data: payload,
93
90
  children: array<t>,
94
91
  }
95
- open JSON.Field
92
+ open Deser.Field
96
93
 
97
94
  let fields = Object([("data", Any), ("children", Array(Self))])
98
95
  })
@@ -100,7 +97,7 @@ module_("Recursive deserializer", _ => {
100
97
  module Deserializer = {
101
98
  include DeserializerImpl
102
99
 
103
- let fromJSON = data => data->DeserializerImpl.fromJSON->Result.map(cast)
100
+ let fromJSON = data => data->DeserializerImpl.fromJSON->Result.map(x => x->Obj.magic)
104
101
  }
105
102
  }
106
103
 
@@ -123,8 +120,8 @@ module_("Recursive deserializer", _ => {
123
120
  })
124
121
 
125
122
  test("Infinite list", qunit => {
126
- module InfiniteList = MakeDeserializer({
127
- open JSON.Field
123
+ module InfiniteList = Deser.MakeDeserializer({
124
+ open Deser.Field
128
125
 
129
126
  type t
130
127
  let fields = Object([("head", String), ("tail", Self)])
@@ -135,8 +132,8 @@ module_("Recursive deserializer", _ => {
135
132
  })
136
133
 
137
134
  test("Finite list", qunit => {
138
- module List = MakeDeserializer({
139
- open JSON.Field
135
+ module List = Deser.MakeDeserializer({
136
+ open Deser.Field
140
137
 
141
138
  type t
142
139
  let fields = Object([("head", String), ("tail", Optional(Self))])
@@ -160,15 +157,15 @@ module_("Recursive deserializer", _ => {
160
157
  })
161
158
 
162
159
  test("Recursion in sub-deserializer", qunit => {
163
- module List = MakeDeserializer({
164
- open JSON.Field
160
+ module List = Deser.MakeDeserializer({
161
+ open Deser.Field
165
162
 
166
163
  type t
167
164
  let fields = Object([("head", String), ("tail", Optional(Self))])
168
165
  })
169
166
 
170
- module Ledger = MakeDeserializer({
171
- open JSON.Field
167
+ module Ledger = Deser.MakeDeserializer({
168
+ open Deser.Field
172
169
 
173
170
  type t
174
171
  let fields = Object([("records", Deserializer(module(List))), ("next", Optional(Self))])
@@ -187,6 +184,6 @@ module_("Recursive deserializer", _ => {
187
184
  }
188
185
 
189
186
  qunit->expect(1)
190
- qunit->deepEqual(data->Ledger.fromJSON->cast, Ok(expected), "nice ledger")
187
+ qunit->deepEqual(data->Ledger.fromJSON->Obj.magic, Ok(expected), "nice ledger")
191
188
  })
192
189
  })
Binary file
Binary file
Binary file
package/www/index.html DELETED
@@ -1,20 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
- <link rel="shortcut icon" href="#" />
9
- <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.16.0.css" type="text/css" media="screen" />
10
- <title>Document</title>
11
- </head>
12
-
13
- <script type="module" defer src="index.js"></script>
14
-
15
- <body>
16
- <div id="qunit"></div>
17
- <div id="qunit-fixture"></div>
18
- </body>
19
-
20
- </html>
File without changes
File without changes