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