@kaiko.io/rescript-deser 3.1.1 → 3.1.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/lib/bs/.bsdeps +1 -1
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.ninja_log +27 -92
- package/lib/bs/build.ninja +5 -5
- package/lib/bs/src/JSON.cmj +0 -0
- package/lib/bs/src/JSON.cmt +0 -0
- package/lib/bs/tests/QUnit.cmj +0 -0
- package/lib/bs/tests/QUnit.cmt +0 -0
- package/lib/bs/tests/index.cmj +0 -0
- package/lib/bs/tests/index.cmt +0 -0
- package/lib/es6/src/JSON.js +628 -0
- package/lib/es6/tests/QUnit.js +2 -0
- package/lib/es6/tests/index.js +284 -0
- package/package.json +2 -2
- package/lib/bs/src/Deser.cmt +0 -0
- package/lib/bs/tests/Vitest.cmt +0 -0
- package/lib/bs/tests/basic.test.cmt +0 -0
package/lib/bs/.bsdeps
CHANGED
package/lib/bs/.compiler.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#Start(
|
|
2
|
-
#Done(
|
|
1
|
+
#Start(1688382096677)
|
|
2
|
+
#Done(1688382096677)
|
package/lib/bs/.ninja_log
CHANGED
|
@@ -1,93 +1,28 @@
|
|
|
1
1
|
# ninja log v6
|
|
2
|
-
0
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
0
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
0 34 1688379868009393830 ../js/tests/Vitest.js 5cdaa44fe168d6d
|
|
30
|
-
0 18 1688379247618956759 src/JSON.cmj fa5cf520a8be3344
|
|
31
|
-
0 18 1688379247618956759 src/JSON.cmi fa5cf520a8be3344
|
|
32
|
-
0 18 1688379247618956759 ../js/src/JSON.js fa5cf520a8be3344
|
|
33
|
-
0 30 1688379868009393830 tests/Vitest.cmj cc2f06b9e262dacc
|
|
34
|
-
0 30 1688379868009393830 tests/Vitest.cmi cc2f06b9e262dacc
|
|
35
|
-
0 30 1688379868009393830 ../js/tests/Vitest.js cc2f06b9e262dacc
|
|
36
|
-
30 42 1688379891392992407 tests/basic.test.cmj 68fbf486ceda534b
|
|
37
|
-
30 42 1688379891392992407 tests/basic.test.cmi 68fbf486ceda534b
|
|
38
|
-
30 42 1688379891392992407 ../js/tests/basic.test.js 68fbf486ceda534b
|
|
39
|
-
0 17 1688379247618956759 src/JSON.cmj e156d0c178c482e3
|
|
40
|
-
0 17 1688379247618956759 src/JSON.cmi e156d0c178c482e3
|
|
41
|
-
0 17 1688379247618956759 ../js/src/JSON.js e156d0c178c482e3
|
|
42
|
-
0 29 1688379868009393830 tests/Vitest.cmj 2125bb8631fd6b6f
|
|
43
|
-
0 29 1688379868009393830 tests/Vitest.cmi 2125bb8631fd6b6f
|
|
44
|
-
0 29 1688379868009393830 ../js/tests/Vitest.js 2125bb8631fd6b6f
|
|
45
|
-
29 42 1688379891392992407 tests/basic.test.cmj 796dce8c08df8f5f
|
|
46
|
-
29 42 1688379891392992407 tests/basic.test.cmi 796dce8c08df8f5f
|
|
47
|
-
29 42 1688379891392992407 ../js/tests/basic.test.js 796dce8c08df8f5f
|
|
48
|
-
0 3 1688379247615623387 src/JSON.d d00ba87460d947fd
|
|
49
|
-
0 3 1688379935600160219 tests/basic.test.d e38380efe2655d28
|
|
50
|
-
3 15 1688379935600160219 tests/basic.test.cmj 796dce8c08df8f5f
|
|
51
|
-
3 15 1688379935600160219 tests/basic.test.cmi 796dce8c08df8f5f
|
|
52
|
-
3 15 1688379935600160219 ../js/tests/basic.test.js 796dce8c08df8f5f
|
|
53
|
-
0 3 1688379946993622648 tests/basic.test.d 6f90ecc99fcd468a
|
|
54
|
-
1 10 1688379947003622761 src/Deser.ast cd0b25377a211e66
|
|
55
|
-
10 13 1688379947006956132 src/Deser.d a9b5860301395adf
|
|
56
|
-
13 31 1688379947023622987 src/Deser.cmj 5c89bf2838f6ce97
|
|
57
|
-
13 31 1688379947023622987 src/Deser.cmi 5c89bf2838f6ce97
|
|
58
|
-
13 31 1688379947023622987 ../js/src/Deser.js 5c89bf2838f6ce97
|
|
59
|
-
0 12 1688379977457301032 tests/basic.test.ast b18ba9a9379ce270
|
|
60
|
-
12 15 1688379977460634403 tests/basic.test.d 6f90ecc99fcd468a
|
|
61
|
-
0 10 1688379985814062321 tests/basic.test.ast b18ba9a9379ce270
|
|
62
|
-
10 13 1688379985814062321 tests/basic.test.d 6f90ecc99fcd468a
|
|
63
|
-
0 14 1688380005404284107 tests/basic.test.ast b18ba9a9379ce270
|
|
64
|
-
14 17 1688380005404284107 tests/basic.test.d 6f90ecc99fcd468a
|
|
65
|
-
17 29 1688380005404284107 tests/basic.test.cmj 796dce8c08df8f5f
|
|
66
|
-
17 29 1688380005404284107 tests/basic.test.cmi 796dce8c08df8f5f
|
|
67
|
-
17 29 1688380005404284107 ../js/tests/basic.test.js 796dce8c08df8f5f
|
|
68
|
-
0 3 1688380455412698631 tests/basic.test.d e38380efe2655d28
|
|
69
|
-
0 10 1688380455419365372 src/JSON.ast 23930881e232c07e
|
|
70
|
-
10 13 1688380455422698743 src/JSON.d d00ba87460d947fd
|
|
71
|
-
13 32 1688380455442698969 src/JSON.cmj e156d0c178c482e3
|
|
72
|
-
13 32 1688380455442698969 src/JSON.cmi e156d0c178c482e3
|
|
73
|
-
13 32 1688380455442698969 ../js/src/JSON.js e156d0c178c482e3
|
|
74
|
-
0 7 1688380477149610260 tests/basic.test.ast b18ba9a9379ce270
|
|
75
|
-
7 10 1688380477152943631 tests/basic.test.d e38380efe2655d28
|
|
76
|
-
10 23 1688380477152943631 tests/basic.test.cmj 796dce8c08df8f5f
|
|
77
|
-
10 23 1688380477152943631 tests/basic.test.cmi 796dce8c08df8f5f
|
|
78
|
-
10 23 1688380477152943631 ../js/tests/basic.test.js 796dce8c08df8f5f
|
|
79
|
-
0 7 1688380979805268331 tests/QUnit.ast ae640b6aefd35348
|
|
80
|
-
0 7 1688380979805268331 tests/index.ast b5b685b3adc59946
|
|
81
|
-
0 8 1688380979805268331 src/JSON.ast 23930881e232c07e
|
|
82
|
-
7 9 1688380979808601702 tests/QUnit.d 4a2631c992d93ce7
|
|
83
|
-
7 9 1688380979808601702 tests/index.d 5a4db9cdecd186b3
|
|
84
|
-
8 10 1688380979805268331 src/JSON.d cd2d6773c781340f
|
|
85
|
-
9 18 1688380979815268443 tests/QUnit.cmj 743026e625d40f7c
|
|
86
|
-
9 18 1688380979815268443 tests/QUnit.cmi 743026e625d40f7c
|
|
87
|
-
9 18 1688380979815268443 ../js/tests/QUnit.js 743026e625d40f7c
|
|
88
|
-
10 27 1688380979805268331 src/JSON.cmj a900e769d0db9273
|
|
89
|
-
10 27 1688380979805268331 src/JSON.cmi a900e769d0db9273
|
|
90
|
-
10 27 1688380979805268331 ../js/src/JSON.js a900e769d0db9273
|
|
91
|
-
27 38 1688380979835268668 tests/index.cmj a7f18a4fafd85d7d
|
|
92
|
-
27 38 1688380979835268668 tests/index.cmi a7f18a4fafd85d7d
|
|
93
|
-
27 38 1688380979835268668 ../js/tests/index.js a7f18a4fafd85d7d
|
|
2
|
+
0 27 1688381837613117393 tests/QUnit.ast ae640b6aefd35348
|
|
3
|
+
0 28 1688381837613117393 tests/index.ast b5b685b3adc59946
|
|
4
|
+
0 29 1688381837613117393 src/JSON.ast 23930881e232c07e
|
|
5
|
+
28 32 1688381837619784009 tests/QUnit.d 4a2631c992d93ce7
|
|
6
|
+
29 32 1688381837619784009 src/JSON.d cd2d6773c781340f
|
|
7
|
+
28 33 1688381837619784009 tests/index.d 5a4db9cdecd186b3
|
|
8
|
+
32 41 1688381837626450625 tests/QUnit.cmj af48764142174424
|
|
9
|
+
32 41 1688381837626450625 tests/QUnit.cmi af48764142174424
|
|
10
|
+
32 41 1688381837626450625 ../es6/tests/QUnit.js af48764142174424
|
|
11
|
+
33 50 1688381837636450550 src/JSON.cmj 4715564a08207e44
|
|
12
|
+
33 50 1688381837636450550 src/JSON.cmi 4715564a08207e44
|
|
13
|
+
33 50 1688381837636450550 ../es6/src/JSON.js 4715564a08207e44
|
|
14
|
+
50 62 1688381837646450474 tests/index.cmj afa68ed03027d968
|
|
15
|
+
50 62 1688381837646450474 tests/index.cmi afa68ed03027d968
|
|
16
|
+
50 62 1688381837646450474 ../es6/tests/index.js afa68ed03027d968
|
|
17
|
+
0 8 1688381837619784009 tests/QUnit.cmj f85ad7fabdfec222
|
|
18
|
+
0 8 1688381837619784009 tests/QUnit.cmi f85ad7fabdfec222
|
|
19
|
+
0 8 1688381837619784009 ../es6/tests/QUnit.js f85ad7fabdfec222
|
|
20
|
+
0 8 1688381837619784009 ../js/tests/QUnit.js f85ad7fabdfec222
|
|
21
|
+
0 18 1688381837619784009 src/JSON.cmj 9628ec2442bee34e
|
|
22
|
+
0 18 1688381837619784009 src/JSON.cmi 9628ec2442bee34e
|
|
23
|
+
0 18 1688381837619784009 ../es6/src/JSON.js 9628ec2442bee34e
|
|
24
|
+
0 18 1688381837619784009 ../js/src/JSON.js 9628ec2442bee34e
|
|
25
|
+
18 30 1688382079735404980 tests/index.cmj a5ae0db315b2706d
|
|
26
|
+
18 30 1688382079735404980 tests/index.cmi a5ae0db315b2706d
|
|
27
|
+
18 30 1688382079735404980 ../es6/tests/index.js a5ae0db315b2706d
|
|
28
|
+
18 30 1688382079735404980 ../js/tests/index.js a5ae0db315b2706d
|
package/lib/bs/build.ninja
CHANGED
|
@@ -8,20 +8,20 @@ rule deps_dev
|
|
|
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 -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$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/@kaiko.io/rescript-prelude/lib/ocaml -warn-error +8+11+26+27+33+56 -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$in_d:.js -bs-package-output es6:lib/es6/$in_d:.js -bs-v $g_finger $i
|
|
12
12
|
dyndep = 1
|
|
13
13
|
restat = 1
|
|
14
|
-
o tests/index.cmj tests/index.cmi ../js/tests/index.js : mij_dev tests/index.ast
|
|
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
|
-
o tests/QUnit.cmj tests/QUnit.cmi ../js/tests/QUnit.js : mij_dev tests/QUnit.ast
|
|
17
|
+
o tests/QUnit.cmj tests/QUnit.cmi ../es6/tests/QUnit.js ../js/tests/QUnit.js : mij_dev tests/QUnit.ast
|
|
18
18
|
o src/JSON.ast : astj ../../src/JSON.res
|
|
19
19
|
rule deps
|
|
20
20
|
command = /home/manu/src/kaiko/rescript-deser/node_modules/rescript/linux/bsb_helper.exe -hash 84aecc33f8594375b23a1a137b057f93 $in
|
|
21
21
|
restat = 1
|
|
22
22
|
o src/JSON.d : deps src/JSON.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 -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$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/@kaiko.io/rescript-prelude/lib/ocaml -warn-error +8+11+26+27+33+56 -bs-package-name @kaiko.io/rescript-deser -bs-package-output commonjs:lib/js/$in_d:.js -bs-package-output es6: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 ../js/src/JSON.js : mij src/JSON.ast
|
|
27
|
+
o src/JSON.cmj src/JSON.cmi ../es6/src/JSON.js ../js/src/JSON.js : mij src/JSON.ast
|
package/lib/bs/src/JSON.cmj
CHANGED
|
Binary file
|
package/lib/bs/src/JSON.cmt
CHANGED
|
Binary file
|
package/lib/bs/tests/QUnit.cmj
CHANGED
|
Binary file
|
package/lib/bs/tests/QUnit.cmt
CHANGED
|
Binary file
|
package/lib/bs/tests/index.cmj
CHANGED
|
Binary file
|
package/lib/bs/tests/index.cmt
CHANGED
|
Binary file
|
|
@@ -0,0 +1,628 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Curry from "rescript/lib/es6/curry.js";
|
|
4
|
+
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";
|
|
6
|
+
import * as Caml_option from "rescript/lib/es6/caml_option.js";
|
|
7
|
+
import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js";
|
|
8
|
+
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
|
|
9
|
+
|
|
10
|
+
var FieldValue = {};
|
|
11
|
+
|
|
12
|
+
var $$TypeError = /* @__PURE__ */Caml_exceptions.create("JSON.TypeError");
|
|
13
|
+
|
|
14
|
+
function usingString(f, value) {
|
|
15
|
+
return Curry._1(f, value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function usingInt(f, value) {
|
|
19
|
+
return Curry._1(f, value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function usingFloat(f, value) {
|
|
23
|
+
return Curry._1(f, value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function usingBoolean(f, value) {
|
|
27
|
+
return Curry._1(f, value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function usingArray(f, value) {
|
|
31
|
+
return Curry._1(f, value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function usingObject(f, value) {
|
|
35
|
+
return Curry._1(f, value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function variadicInt(hint, fromJs) {
|
|
39
|
+
return {
|
|
40
|
+
TAG: /* Morphism */10,
|
|
41
|
+
_0: /* Int */2,
|
|
42
|
+
_1: (function (param) {
|
|
43
|
+
var internalValue = Curry._1(fromJs, param);
|
|
44
|
+
if (internalValue !== undefined) {
|
|
45
|
+
return Caml_option.valFromOption(internalValue);
|
|
46
|
+
}
|
|
47
|
+
throw {
|
|
48
|
+
RE_EXN_ID: $$TypeError,
|
|
49
|
+
_1: "This Int(" + String(param) + ") not a valid value here. Hint: " + hint + "",
|
|
50
|
+
Error: new Error()
|
|
51
|
+
};
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function variadicString(hint, fromJs) {
|
|
57
|
+
return {
|
|
58
|
+
TAG: /* Morphism */10,
|
|
59
|
+
_0: /* String */1,
|
|
60
|
+
_1: (function (param) {
|
|
61
|
+
var internalValue = Curry._1(fromJs, param);
|
|
62
|
+
if (internalValue !== undefined) {
|
|
63
|
+
return Caml_option.valFromOption(internalValue);
|
|
64
|
+
}
|
|
65
|
+
throw {
|
|
66
|
+
RE_EXN_ID: $$TypeError,
|
|
67
|
+
_1: "This String(\"" + param + "\") not a valid value here. Hint: " + hint + "",
|
|
68
|
+
Error: new Error()
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function toString(type_) {
|
|
75
|
+
if (typeof type_ === "number") {
|
|
76
|
+
switch (type_) {
|
|
77
|
+
case /* Any */0 :
|
|
78
|
+
return "Any";
|
|
79
|
+
case /* String */1 :
|
|
80
|
+
return "String";
|
|
81
|
+
case /* Int */2 :
|
|
82
|
+
return "Integer";
|
|
83
|
+
case /* Float */3 :
|
|
84
|
+
return "Float";
|
|
85
|
+
case /* Boolean */4 :
|
|
86
|
+
return "Boolean";
|
|
87
|
+
case /* Date */5 :
|
|
88
|
+
case /* Datetime */6 :
|
|
89
|
+
return "Date";
|
|
90
|
+
case /* Self */7 :
|
|
91
|
+
return "Self (recursive)";
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
switch (type_.TAG | 0) {
|
|
96
|
+
case /* Literal */0 :
|
|
97
|
+
return "Literal: " + type_._0 + "";
|
|
98
|
+
case /* Array */1 :
|
|
99
|
+
return "Array of " + toString(type_._0);
|
|
100
|
+
case /* Tuple */2 :
|
|
101
|
+
return "Tuple of (" + Curry._2(Prelude.$$Array.map, type_._0, toString).join(", ") + ")";
|
|
102
|
+
case /* Object */3 :
|
|
103
|
+
var desc = Curry._2(Prelude.$$Array.map, type_._0, (function (param) {
|
|
104
|
+
return "" + param[0] + ": " + toString(param[1]) + "";
|
|
105
|
+
})).join(", ");
|
|
106
|
+
return "Object of {" + desc + "}";
|
|
107
|
+
case /* Optional */4 :
|
|
108
|
+
case /* OptionalWithDefault */5 :
|
|
109
|
+
return "Null of " + toString(type_._0);
|
|
110
|
+
case /* Mapping */6 :
|
|
111
|
+
return "Mapping of " + toString(type_._0) + "";
|
|
112
|
+
case /* Deserializer */7 :
|
|
113
|
+
return type_._0.name;
|
|
114
|
+
case /* Collection */8 :
|
|
115
|
+
return "Collection of " + type_._0.name;
|
|
116
|
+
case /* DefaultWhenInvalid */9 :
|
|
117
|
+
return "Protected " + toString(type_._0) + "";
|
|
118
|
+
case /* Morphism */10 :
|
|
119
|
+
return toString(type_._0) + " to apply a morphism";
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function _taggedToString(tagged) {
|
|
126
|
+
if (typeof tagged === "number") {
|
|
127
|
+
switch (tagged) {
|
|
128
|
+
case /* JSONFalse */0 :
|
|
129
|
+
return "Boolean(false)";
|
|
130
|
+
case /* JSONTrue */1 :
|
|
131
|
+
return "Boolean(true)";
|
|
132
|
+
case /* JSONNull */2 :
|
|
133
|
+
return "Null";
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
switch (tagged.TAG | 0) {
|
|
138
|
+
case /* JSONString */0 :
|
|
139
|
+
return "String(\"" + tagged._0 + "\")";
|
|
140
|
+
case /* JSONNumber */1 :
|
|
141
|
+
return "Number(" + String(tagged._0) + ")";
|
|
142
|
+
case /* JSONObject */2 :
|
|
143
|
+
return "Object(" + Prelude.$$default(JSON.stringify(tagged._0), "...") + ")";
|
|
144
|
+
case /* JSONArray */3 :
|
|
145
|
+
return "Array(" + Prelude.$$default(JSON.stringify(tagged._0), "...") + ")";
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function extractValue(values, field, shape, self) {
|
|
152
|
+
var value = Curry._2(Prelude.Dict.get, values, field);
|
|
153
|
+
if (value !== undefined) {
|
|
154
|
+
return fromUntagged(Caml_option.valFromOption(value), shape, self);
|
|
155
|
+
}
|
|
156
|
+
if (typeof shape !== "number") {
|
|
157
|
+
switch (shape.TAG | 0) {
|
|
158
|
+
case /* OptionalWithDefault */5 :
|
|
159
|
+
return shape._1;
|
|
160
|
+
case /* Optional */4 :
|
|
161
|
+
case /* DefaultWhenInvalid */9 :
|
|
162
|
+
return fromUntagged(null, shape, self);
|
|
163
|
+
default:
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
throw {
|
|
168
|
+
RE_EXN_ID: $$TypeError,
|
|
169
|
+
_1: "Missing non-optional field '" + field + "'",
|
|
170
|
+
Error: new Error()
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function fromUntagged(untagged, _shape, self) {
|
|
175
|
+
while(true) {
|
|
176
|
+
var shape = _shape;
|
|
177
|
+
var match = Js_json.classify(untagged);
|
|
178
|
+
var exit = 0;
|
|
179
|
+
var s;
|
|
180
|
+
var f;
|
|
181
|
+
if (typeof shape === "number") {
|
|
182
|
+
switch (shape) {
|
|
183
|
+
case /* Any */0 :
|
|
184
|
+
return untagged;
|
|
185
|
+
case /* String */1 :
|
|
186
|
+
if (typeof match === "number") {
|
|
187
|
+
exit = 1;
|
|
188
|
+
} else {
|
|
189
|
+
if (match.TAG === /* JSONString */0) {
|
|
190
|
+
return match._0;
|
|
191
|
+
}
|
|
192
|
+
exit = 1;
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
case /* Int */2 :
|
|
196
|
+
if (typeof match === "number") {
|
|
197
|
+
exit = 1;
|
|
198
|
+
} else {
|
|
199
|
+
if (match.TAG === /* JSONNumber */1) {
|
|
200
|
+
return match._0 | 0;
|
|
201
|
+
}
|
|
202
|
+
exit = 1;
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case /* Float */3 :
|
|
206
|
+
if (typeof match === "number") {
|
|
207
|
+
exit = 1;
|
|
208
|
+
} else {
|
|
209
|
+
if (match.TAG === /* JSONNumber */1) {
|
|
210
|
+
return match._0;
|
|
211
|
+
}
|
|
212
|
+
exit = 1;
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case /* Boolean */4 :
|
|
216
|
+
if (typeof match === "number") {
|
|
217
|
+
switch (match) {
|
|
218
|
+
case /* JSONFalse */0 :
|
|
219
|
+
return false;
|
|
220
|
+
case /* JSONTrue */1 :
|
|
221
|
+
return true;
|
|
222
|
+
case /* JSONNull */2 :
|
|
223
|
+
exit = 1;
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
exit = 1;
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
case /* Date */5 :
|
|
232
|
+
if (typeof match === "number") {
|
|
233
|
+
exit = 1;
|
|
234
|
+
} else {
|
|
235
|
+
switch (match.TAG | 0) {
|
|
236
|
+
case /* JSONString */0 :
|
|
237
|
+
s = match._0;
|
|
238
|
+
exit = 2;
|
|
239
|
+
break;
|
|
240
|
+
case /* JSONNumber */1 :
|
|
241
|
+
f = match._0;
|
|
242
|
+
exit = 3;
|
|
243
|
+
break;
|
|
244
|
+
default:
|
|
245
|
+
exit = 1;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
case /* Datetime */6 :
|
|
250
|
+
if (typeof match === "number") {
|
|
251
|
+
exit = 1;
|
|
252
|
+
} else {
|
|
253
|
+
switch (match.TAG | 0) {
|
|
254
|
+
case /* JSONString */0 :
|
|
255
|
+
s = match._0;
|
|
256
|
+
exit = 2;
|
|
257
|
+
break;
|
|
258
|
+
case /* JSONNumber */1 :
|
|
259
|
+
f = match._0;
|
|
260
|
+
exit = 3;
|
|
261
|
+
break;
|
|
262
|
+
default:
|
|
263
|
+
exit = 1;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
case /* Self */7 :
|
|
268
|
+
_shape = self;
|
|
269
|
+
continue ;
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
switch (shape.TAG | 0) {
|
|
274
|
+
case /* Literal */0 :
|
|
275
|
+
if (typeof match === "number") {
|
|
276
|
+
exit = 1;
|
|
277
|
+
} else {
|
|
278
|
+
if (match.TAG === /* JSONString */0) {
|
|
279
|
+
var text = match._0;
|
|
280
|
+
var expected = shape._0;
|
|
281
|
+
if (text === expected) {
|
|
282
|
+
return text;
|
|
283
|
+
}
|
|
284
|
+
throw {
|
|
285
|
+
RE_EXN_ID: $$TypeError,
|
|
286
|
+
_1: "Expecting literal " + expected + ", got " + text + "",
|
|
287
|
+
Error: new Error()
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
exit = 1;
|
|
291
|
+
}
|
|
292
|
+
break;
|
|
293
|
+
case /* Array */1 :
|
|
294
|
+
if (typeof match === "number") {
|
|
295
|
+
exit = 1;
|
|
296
|
+
} else {
|
|
297
|
+
if (match.TAG === /* JSONArray */3) {
|
|
298
|
+
var shape$1 = shape._0;
|
|
299
|
+
return Curry._2(Prelude.$$Array.map, match._0, (function(shape$1){
|
|
300
|
+
return function (item) {
|
|
301
|
+
return fromUntagged(item, shape$1, self);
|
|
302
|
+
}
|
|
303
|
+
}(shape$1)));
|
|
304
|
+
}
|
|
305
|
+
exit = 1;
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
308
|
+
case /* Tuple */2 :
|
|
309
|
+
if (typeof match === "number") {
|
|
310
|
+
exit = 1;
|
|
311
|
+
} else {
|
|
312
|
+
if (match.TAG === /* JSONArray */3) {
|
|
313
|
+
var items = match._0;
|
|
314
|
+
var bases = shape._0;
|
|
315
|
+
var lenbases = bases.length;
|
|
316
|
+
var lenitems = items.length;
|
|
317
|
+
if (lenbases === lenitems) {
|
|
318
|
+
return Curry._3(Prelude.$$Array.zipBy, items, bases, (function (i, b) {
|
|
319
|
+
return fromUntagged(i, b, self);
|
|
320
|
+
}));
|
|
321
|
+
}
|
|
322
|
+
throw {
|
|
323
|
+
RE_EXN_ID: $$TypeError,
|
|
324
|
+
_1: "Expecting " + String(lenbases) + " items, got " + String(lenitems) + "",
|
|
325
|
+
Error: new Error()
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
exit = 1;
|
|
329
|
+
}
|
|
330
|
+
break;
|
|
331
|
+
case /* Object */3 :
|
|
332
|
+
if (typeof match === "number") {
|
|
333
|
+
exit = 1;
|
|
334
|
+
} else {
|
|
335
|
+
if (match.TAG === /* JSONObject */2) {
|
|
336
|
+
var values = match._0;
|
|
337
|
+
return Curry._1(Prelude.Dict.fromArray, Curry._2(Prelude.$$Array.map, shape._0, (function(values){
|
|
338
|
+
return function (param) {
|
|
339
|
+
var field = param[0];
|
|
340
|
+
var value;
|
|
341
|
+
try {
|
|
342
|
+
value = extractValue(values, field, param[1], self);
|
|
343
|
+
}
|
|
344
|
+
catch (raw_msg){
|
|
345
|
+
var msg = Caml_js_exceptions.internalToOCamlException(raw_msg);
|
|
346
|
+
if (msg.RE_EXN_ID === $$TypeError) {
|
|
347
|
+
throw {
|
|
348
|
+
RE_EXN_ID: $$TypeError,
|
|
349
|
+
_1: "Field \"" + field + "\": " + msg._1 + "",
|
|
350
|
+
Error: new Error()
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
throw msg;
|
|
354
|
+
}
|
|
355
|
+
return [
|
|
356
|
+
field,
|
|
357
|
+
value
|
|
358
|
+
];
|
|
359
|
+
}
|
|
360
|
+
}(values))));
|
|
361
|
+
}
|
|
362
|
+
exit = 1;
|
|
363
|
+
}
|
|
364
|
+
break;
|
|
365
|
+
case /* Optional */4 :
|
|
366
|
+
var shape$2 = shape._0;
|
|
367
|
+
if (typeof match === "number") {
|
|
368
|
+
if (match >= 2) {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
_shape = shape$2;
|
|
372
|
+
continue ;
|
|
373
|
+
}
|
|
374
|
+
_shape = shape$2;
|
|
375
|
+
continue ;
|
|
376
|
+
case /* OptionalWithDefault */5 :
|
|
377
|
+
var shape$3 = shape._0;
|
|
378
|
+
if (typeof match === "number") {
|
|
379
|
+
if (match >= 2) {
|
|
380
|
+
return shape._1;
|
|
381
|
+
}
|
|
382
|
+
_shape = shape$3;
|
|
383
|
+
continue ;
|
|
384
|
+
}
|
|
385
|
+
_shape = shape$3;
|
|
386
|
+
continue ;
|
|
387
|
+
case /* Mapping */6 :
|
|
388
|
+
if (typeof match === "number") {
|
|
389
|
+
exit = 1;
|
|
390
|
+
} else {
|
|
391
|
+
if (match.TAG === /* JSONObject */2) {
|
|
392
|
+
var f$1 = shape._0;
|
|
393
|
+
return Prelude.Dict.mapValues(match._0, (function(f$1){
|
|
394
|
+
return function (v) {
|
|
395
|
+
return fromUntagged(v, f$1, self);
|
|
396
|
+
}
|
|
397
|
+
}(f$1)));
|
|
398
|
+
}
|
|
399
|
+
exit = 1;
|
|
400
|
+
}
|
|
401
|
+
break;
|
|
402
|
+
case /* Deserializer */7 :
|
|
403
|
+
var res = Curry._1(shape._0.fromJSON, untagged);
|
|
404
|
+
if (res.TAG === /* Ok */0) {
|
|
405
|
+
return res._0;
|
|
406
|
+
}
|
|
407
|
+
throw {
|
|
408
|
+
RE_EXN_ID: $$TypeError,
|
|
409
|
+
_1: res._0,
|
|
410
|
+
Error: new Error()
|
|
411
|
+
};
|
|
412
|
+
case /* Collection */8 :
|
|
413
|
+
if (typeof match === "number") {
|
|
414
|
+
exit = 1;
|
|
415
|
+
} else {
|
|
416
|
+
if (match.TAG === /* JSONArray */3) {
|
|
417
|
+
return Curry._2(Prelude.$$Array.map, Prelude.$$Array.keepSome(Curry._2(Prelude.$$Array.map, Curry._2(Prelude.$$Array.map, match._0, shape._0.fromJSON), Prelude.Result.warn)), (function (prim) {
|
|
418
|
+
return prim;
|
|
419
|
+
}));
|
|
420
|
+
}
|
|
421
|
+
exit = 1;
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
case /* DefaultWhenInvalid */9 :
|
|
425
|
+
try {
|
|
426
|
+
return fromUntagged(untagged, shape._0, self);
|
|
427
|
+
}
|
|
428
|
+
catch (raw_msg){
|
|
429
|
+
var msg = Caml_js_exceptions.internalToOCamlException(raw_msg);
|
|
430
|
+
if (msg.RE_EXN_ID === $$TypeError) {
|
|
431
|
+
console.warn("Detected and ignore (with default): ", msg._1);
|
|
432
|
+
return shape._1;
|
|
433
|
+
}
|
|
434
|
+
throw msg;
|
|
435
|
+
}
|
|
436
|
+
case /* Morphism */10 :
|
|
437
|
+
return Curry._1(shape._1, fromUntagged(untagged, shape._0, self));
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
switch (exit) {
|
|
442
|
+
case 1 :
|
|
443
|
+
throw {
|
|
444
|
+
RE_EXN_ID: $$TypeError,
|
|
445
|
+
_1: "Expected " + toString(shape) + ", but got " + _taggedToString(match) + " instead",
|
|
446
|
+
Error: new Error()
|
|
447
|
+
};
|
|
448
|
+
case 2 :
|
|
449
|
+
var r = new Date(s);
|
|
450
|
+
if (Number.isNaN(r.getDate())) {
|
|
451
|
+
throw {
|
|
452
|
+
RE_EXN_ID: $$TypeError,
|
|
453
|
+
_1: "Invalid date " + s + "",
|
|
454
|
+
Error: new Error()
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
return r;
|
|
458
|
+
case 3 :
|
|
459
|
+
var r$1 = new Date(f);
|
|
460
|
+
if (Number.isNaN(r$1.getDate())) {
|
|
461
|
+
throw {
|
|
462
|
+
RE_EXN_ID: $$TypeError,
|
|
463
|
+
_1: "Invalid date " + f.toString() + "",
|
|
464
|
+
Error: new Error()
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
return r$1;
|
|
468
|
+
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function checkFieldsSanity(name, _fields, _optional) {
|
|
474
|
+
while(true) {
|
|
475
|
+
var optional = _optional;
|
|
476
|
+
var fields = _fields;
|
|
477
|
+
var exit = 0;
|
|
478
|
+
if (typeof fields === "number") {
|
|
479
|
+
switch (fields) {
|
|
480
|
+
case /* Any */0 :
|
|
481
|
+
case /* Boolean */4 :
|
|
482
|
+
case /* Date */5 :
|
|
483
|
+
case /* Datetime */6 :
|
|
484
|
+
return {
|
|
485
|
+
TAG: /* Ok */0,
|
|
486
|
+
_0: undefined
|
|
487
|
+
};
|
|
488
|
+
case /* Self */7 :
|
|
489
|
+
if (optional) {
|
|
490
|
+
return {
|
|
491
|
+
TAG: /* Ok */0,
|
|
492
|
+
_0: undefined
|
|
493
|
+
};
|
|
494
|
+
} else {
|
|
495
|
+
return {
|
|
496
|
+
TAG: /* Error */1,
|
|
497
|
+
_0: "" + name + ": Trivial infinite recursion 'let fields = Self'"
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
default:
|
|
501
|
+
return {
|
|
502
|
+
TAG: /* Ok */0,
|
|
503
|
+
_0: undefined
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
switch (fields.TAG | 0) {
|
|
508
|
+
case /* Tuple */2 :
|
|
509
|
+
return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(Curry._2(Prelude.$$Array.mapWithIndex, fields._0, (function(optional){
|
|
510
|
+
return function (index, field, param) {
|
|
511
|
+
return checkFieldsSanity("" + name + "[" + String(index) + "]", field, optional);
|
|
512
|
+
}
|
|
513
|
+
}(optional)))), (function (param) {
|
|
514
|
+
|
|
515
|
+
}));
|
|
516
|
+
case /* Object */3 :
|
|
517
|
+
return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(Curry._2(Prelude.$$Array.map, fields._0, (function(optional){
|
|
518
|
+
return function (param, param$1) {
|
|
519
|
+
return checkFieldsSanity("" + name + "::" + param[0] + "", param[1], optional);
|
|
520
|
+
}
|
|
521
|
+
}(optional)))), (function (param) {
|
|
522
|
+
|
|
523
|
+
}));
|
|
524
|
+
case /* Array */1 :
|
|
525
|
+
case /* Mapping */6 :
|
|
526
|
+
_optional = true;
|
|
527
|
+
_fields = fields._0;
|
|
528
|
+
continue ;
|
|
529
|
+
case /* Deserializer */7 :
|
|
530
|
+
case /* Collection */8 :
|
|
531
|
+
exit = 2;
|
|
532
|
+
break;
|
|
533
|
+
case /* Optional */4 :
|
|
534
|
+
case /* OptionalWithDefault */5 :
|
|
535
|
+
case /* DefaultWhenInvalid */9 :
|
|
536
|
+
exit = 1;
|
|
537
|
+
break;
|
|
538
|
+
case /* Morphism */10 :
|
|
539
|
+
return {
|
|
540
|
+
TAG: /* Ok */0,
|
|
541
|
+
_0: undefined
|
|
542
|
+
};
|
|
543
|
+
default:
|
|
544
|
+
return {
|
|
545
|
+
TAG: /* Ok */0,
|
|
546
|
+
_0: undefined
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
switch (exit) {
|
|
551
|
+
case 1 :
|
|
552
|
+
_optional = true;
|
|
553
|
+
_fields = fields._0;
|
|
554
|
+
continue ;
|
|
555
|
+
case 2 :
|
|
556
|
+
var msg = Curry._1(fields._0.checkFieldsSanity, undefined);
|
|
557
|
+
if (msg.TAG === /* Ok */0) {
|
|
558
|
+
return {
|
|
559
|
+
TAG: /* Ok */0,
|
|
560
|
+
_0: undefined
|
|
561
|
+
};
|
|
562
|
+
} else {
|
|
563
|
+
return {
|
|
564
|
+
TAG: /* Error */1,
|
|
565
|
+
_0: "" + name + "/ " + msg._0 + ""
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
var Field = {
|
|
574
|
+
usingString: usingString,
|
|
575
|
+
usingInt: usingInt,
|
|
576
|
+
usingFloat: usingFloat,
|
|
577
|
+
usingBoolean: usingBoolean,
|
|
578
|
+
usingArray: usingArray,
|
|
579
|
+
usingObject: usingObject,
|
|
580
|
+
variadicInt: variadicInt,
|
|
581
|
+
variadicString: variadicString,
|
|
582
|
+
toString: toString,
|
|
583
|
+
_taggedToString: _taggedToString,
|
|
584
|
+
extractValue: extractValue,
|
|
585
|
+
fromUntagged: fromUntagged,
|
|
586
|
+
checkFieldsSanity: checkFieldsSanity
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
function MakeDeserializer(S) {
|
|
590
|
+
var fields = S.fields;
|
|
591
|
+
var name = "Deserializer " + "JSON" + ", " + "File \"JSON.res\", line 321, characters 39-47" + "";
|
|
592
|
+
var checkFieldsSanity$1 = function (param) {
|
|
593
|
+
return checkFieldsSanity(name, fields, false);
|
|
594
|
+
};
|
|
595
|
+
var fromJSON = function (json) {
|
|
596
|
+
var res;
|
|
597
|
+
try {
|
|
598
|
+
res = fromUntagged(json, fields, fields);
|
|
599
|
+
}
|
|
600
|
+
catch (raw_e){
|
|
601
|
+
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
|
|
602
|
+
if (e.RE_EXN_ID === $$TypeError) {
|
|
603
|
+
return {
|
|
604
|
+
TAG: /* Error */1,
|
|
605
|
+
_0: e._1
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
throw e;
|
|
609
|
+
}
|
|
610
|
+
return {
|
|
611
|
+
TAG: /* Ok */0,
|
|
612
|
+
_0: res
|
|
613
|
+
};
|
|
614
|
+
};
|
|
615
|
+
return {
|
|
616
|
+
name: name,
|
|
617
|
+
fromJSON: fromJSON,
|
|
618
|
+
checkFieldsSanity: checkFieldsSanity$1
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
export {
|
|
623
|
+
FieldValue ,
|
|
624
|
+
$$TypeError ,
|
|
625
|
+
Field ,
|
|
626
|
+
MakeDeserializer ,
|
|
627
|
+
}
|
|
628
|
+
/* No side effect */
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as $$JSON from "../src/JSON.js";
|
|
4
|
+
import * as Curry from "rescript/lib/es6/curry.js";
|
|
5
|
+
import * as Qunit from "qunit";
|
|
6
|
+
import * as Prelude from "@kaiko.io/rescript-prelude/lib/es6/src/Prelude.js";
|
|
7
|
+
|
|
8
|
+
var fields = {
|
|
9
|
+
TAG: /* Object */3,
|
|
10
|
+
_0: [
|
|
11
|
+
[
|
|
12
|
+
"note",
|
|
13
|
+
/* String */1
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"date",
|
|
17
|
+
/* Date */5
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"extra",
|
|
21
|
+
{
|
|
22
|
+
TAG: /* Optional */4,
|
|
23
|
+
_0: /* String */1
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
var Deserializer = $$JSON.MakeDeserializer({
|
|
30
|
+
fields: fields
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var Appointment = {
|
|
34
|
+
Deserializer: Deserializer
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
Qunit.module("Basic deserializer", (function (param) {
|
|
38
|
+
var valid = [
|
|
39
|
+
[
|
|
40
|
+
{"note": "Bicentennial doctor's appointment", "date": "2100-01-01"},
|
|
41
|
+
{
|
|
42
|
+
note: "Bicentennial doctor's appointment",
|
|
43
|
+
date: new Date("2100-01-01"),
|
|
44
|
+
extra: undefined
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
{
|
|
49
|
+
"note": "Bicentennial doctor's appointment",
|
|
50
|
+
"date": "2100-01-01",
|
|
51
|
+
"extra": "Don't take your stop-aging pills the night before the appointment",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
note: "Bicentennial doctor's appointment",
|
|
55
|
+
date: new Date("2100-01-01"),
|
|
56
|
+
extra: "Don't take your stop-aging pills the night before the appointment"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
];
|
|
60
|
+
Qunit.test("Correctly deserializes data", (function (qunit) {
|
|
61
|
+
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 = Curry._1(Deserializer.fromJSON, data);
|
|
66
|
+
if (result.TAG === /* Ok */0) {
|
|
67
|
+
qunit.deepEqual(result._0, param[1], "result == expected");
|
|
68
|
+
return ;
|
|
69
|
+
}
|
|
70
|
+
console.error(result._0);
|
|
71
|
+
}));
|
|
72
|
+
}));
|
|
73
|
+
var invalid = [[
|
|
74
|
+
"Missing non-optional field",
|
|
75
|
+
{"extra": "Bicentennial doctor's appointment", "date": "2100-01-01"}
|
|
76
|
+
]];
|
|
77
|
+
Qunit.test("Correctly catches invalid data", (function (qunit) {
|
|
78
|
+
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 = Curry._1(Deserializer.fromJSON, data);
|
|
83
|
+
if (result.TAG === /* Ok */0) {
|
|
84
|
+
console.error("Invalid being accepted: ", result._0);
|
|
85
|
+
return ;
|
|
86
|
+
}
|
|
87
|
+
console.log("Correctly detected:", result._0);
|
|
88
|
+
qunit.ok(true, true);
|
|
89
|
+
}));
|
|
90
|
+
}));
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
Qunit.module("Recursive deserializer", (function (param) {
|
|
94
|
+
var fields = {
|
|
95
|
+
TAG: /* Object */3,
|
|
96
|
+
_0: [
|
|
97
|
+
[
|
|
98
|
+
"data",
|
|
99
|
+
/* Any */0
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"children",
|
|
103
|
+
{
|
|
104
|
+
TAG: /* Array */1,
|
|
105
|
+
_0: /* Self */7
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
var DeserializerImpl = $$JSON.MakeDeserializer({
|
|
111
|
+
fields: fields
|
|
112
|
+
});
|
|
113
|
+
var checkFieldsSanity = DeserializerImpl.checkFieldsSanity;
|
|
114
|
+
var fromJSON = function (data) {
|
|
115
|
+
return Curry._2(Prelude.Result.map, Curry._1(DeserializerImpl.fromJSON, data), (function (prim) {
|
|
116
|
+
return prim;
|
|
117
|
+
}));
|
|
118
|
+
};
|
|
119
|
+
var valid = [[
|
|
120
|
+
{"data": "A", "children": [{"data": "A1", "children": []}, {"data": "B", "children": [{"data": "C", "children": []}, {"data": "D", "children": []}]}]},
|
|
121
|
+
{
|
|
122
|
+
data: "A",
|
|
123
|
+
children: [
|
|
124
|
+
{
|
|
125
|
+
data: "A1",
|
|
126
|
+
children: []
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
data: "B",
|
|
130
|
+
children: [
|
|
131
|
+
{
|
|
132
|
+
data: "C",
|
|
133
|
+
children: []
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
data: "D",
|
|
137
|
+
children: []
|
|
138
|
+
}
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
]];
|
|
144
|
+
Qunit.test("Trivial recursion detection: Ok", (function (qunit) {
|
|
145
|
+
qunit.expect(1);
|
|
146
|
+
qunit.deepEqual(Curry._1(checkFieldsSanity, undefined), {
|
|
147
|
+
TAG: /* Ok */0,
|
|
148
|
+
_0: undefined
|
|
149
|
+
}, "Ok");
|
|
150
|
+
}));
|
|
151
|
+
Qunit.test("Infinite list", (function (qunit) {
|
|
152
|
+
var fields = {
|
|
153
|
+
TAG: /* Object */3,
|
|
154
|
+
_0: [
|
|
155
|
+
[
|
|
156
|
+
"head",
|
|
157
|
+
/* String */1
|
|
158
|
+
],
|
|
159
|
+
[
|
|
160
|
+
"tail",
|
|
161
|
+
/* Self */7
|
|
162
|
+
]
|
|
163
|
+
]
|
|
164
|
+
};
|
|
165
|
+
var InfiniteList = $$JSON.MakeDeserializer({
|
|
166
|
+
fields: fields
|
|
167
|
+
});
|
|
168
|
+
qunit.expect(1);
|
|
169
|
+
qunit.deepEqual(Curry._1(Prelude.Result.isError, Curry._1(InfiniteList.checkFieldsSanity, undefined)), true, "Ok");
|
|
170
|
+
}));
|
|
171
|
+
Qunit.test("Finite list", (function (qunit) {
|
|
172
|
+
var fields = {
|
|
173
|
+
TAG: /* Object */3,
|
|
174
|
+
_0: [
|
|
175
|
+
[
|
|
176
|
+
"head",
|
|
177
|
+
/* String */1
|
|
178
|
+
],
|
|
179
|
+
[
|
|
180
|
+
"tail",
|
|
181
|
+
{
|
|
182
|
+
TAG: /* Optional */4,
|
|
183
|
+
_0: /* Self */7
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
]
|
|
187
|
+
};
|
|
188
|
+
var List = $$JSON.MakeDeserializer({
|
|
189
|
+
fields: fields
|
|
190
|
+
});
|
|
191
|
+
qunit.expect(1);
|
|
192
|
+
qunit.deepEqual(Curry._1(List.checkFieldsSanity, undefined), {
|
|
193
|
+
TAG: /* Ok */0,
|
|
194
|
+
_0: undefined
|
|
195
|
+
}, "Ok");
|
|
196
|
+
}));
|
|
197
|
+
Qunit.test("Correctly deserializes recursive data", (function (qunit) {
|
|
198
|
+
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 */0) {
|
|
204
|
+
qunit.deepEqual(result._0, param[1], "result == expected");
|
|
205
|
+
return ;
|
|
206
|
+
}
|
|
207
|
+
console.error(result._0);
|
|
208
|
+
}));
|
|
209
|
+
}));
|
|
210
|
+
Qunit.test("Recursion in sub-deserializer", (function (qunit) {
|
|
211
|
+
var fields = {
|
|
212
|
+
TAG: /* Object */3,
|
|
213
|
+
_0: [
|
|
214
|
+
[
|
|
215
|
+
"head",
|
|
216
|
+
/* String */1
|
|
217
|
+
],
|
|
218
|
+
[
|
|
219
|
+
"tail",
|
|
220
|
+
{
|
|
221
|
+
TAG: /* Optional */4,
|
|
222
|
+
_0: /* Self */7
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
]
|
|
226
|
+
};
|
|
227
|
+
var List = $$JSON.MakeDeserializer({
|
|
228
|
+
fields: fields
|
|
229
|
+
});
|
|
230
|
+
var fields$1 = {
|
|
231
|
+
TAG: /* Object */3,
|
|
232
|
+
_0: [
|
|
233
|
+
[
|
|
234
|
+
"records",
|
|
235
|
+
{
|
|
236
|
+
TAG: /* Deserializer */7,
|
|
237
|
+
_0: List
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
[
|
|
241
|
+
"next",
|
|
242
|
+
{
|
|
243
|
+
TAG: /* Optional */4,
|
|
244
|
+
_0: /* Self */7
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
]
|
|
248
|
+
};
|
|
249
|
+
var Ledger = $$JSON.MakeDeserializer({
|
|
250
|
+
fields: fields$1
|
|
251
|
+
});
|
|
252
|
+
var data = {"records": {"head": "A", "tail": {"head": "B"}},
|
|
253
|
+
"next": {"records": {"head": "A", "tail": {"head": "B"}}}};
|
|
254
|
+
var expected = {
|
|
255
|
+
records: {
|
|
256
|
+
head: "A",
|
|
257
|
+
tail: {
|
|
258
|
+
head: "B",
|
|
259
|
+
tail: undefined
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
next: {
|
|
263
|
+
records: {
|
|
264
|
+
head: "A",
|
|
265
|
+
tail: {
|
|
266
|
+
head: "B",
|
|
267
|
+
tail: undefined
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
next: undefined
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
qunit.expect(1);
|
|
274
|
+
qunit.deepEqual(Curry._1(Ledger.fromJSON, data), {
|
|
275
|
+
TAG: /* Ok */0,
|
|
276
|
+
_0: expected
|
|
277
|
+
}, "nice ledger");
|
|
278
|
+
}));
|
|
279
|
+
}));
|
|
280
|
+
|
|
281
|
+
export {
|
|
282
|
+
Appointment ,
|
|
283
|
+
}
|
|
284
|
+
/* Deserializer Not a pure module */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaiko.io/rescript-deser",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"json",
|
|
6
6
|
"deserializer",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"README.md"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@kaiko.io/rescript-prelude": "^6.2.
|
|
22
|
+
"@kaiko.io/rescript-prelude": "^6.2.2",
|
|
23
23
|
"rescript": "^10.1.4"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
package/lib/bs/src/Deser.cmt
DELETED
|
Binary file
|
package/lib/bs/tests/Vitest.cmt
DELETED
|
Binary file
|
|
Binary file
|