@kaiko.io/rescript-deser 4.0.0-rc.2 → 4.0.0-rc.3
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/.bsbuild +0 -0
- package/lib/bs/.bsdeps +4 -5
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.ninja_log +5 -18
- package/lib/bs/build.ninja +5 -18
- 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/es6/src/JSON.js +1 -27
- package/lib/ocaml/.compiler.log +2 -0
- package/lib/ocaml/.ninja_log +6 -0
- package/lib/ocaml/JSON.cmi +0 -0
- package/lib/ocaml/JSON.cmj +0 -0
- package/lib/ocaml/JSON.cmt +0 -0
- package/lib/ocaml/JSON.res +343 -0
- package/package.json +1 -1
- package/src/JSON.res +9 -37
- package/lib/bs/.sourcedirs.json +0 -1
- 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/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 +0 -1
- package/lib/es6/tests/QUnit.js +0 -2
- package/lib/es6/tests/index.js +0 -288
- package/lib/js/src/JSON.js +0 -671
- package/lib/js/tests/QUnit.js +0 -2
- package/lib/js/tests/index.js +0 -287
- /package/lib/{bs/tests/QUnit.d → ocaml/install.stamp} +0 -0
package/lib/es6/tests/index.js
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
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",
|
|
10
|
-
_0: [
|
|
11
|
-
[
|
|
12
|
-
"note",
|
|
13
|
-
"String"
|
|
14
|
-
],
|
|
15
|
-
[
|
|
16
|
-
"date",
|
|
17
|
-
"Date"
|
|
18
|
-
],
|
|
19
|
-
[
|
|
20
|
-
"extra",
|
|
21
|
-
{
|
|
22
|
-
TAG: "Optional",
|
|
23
|
-
_0: "String"
|
|
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 = 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
|
-
}));
|
|
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 = 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
|
-
}));
|
|
90
|
-
}));
|
|
91
|
-
}));
|
|
92
|
-
|
|
93
|
-
Qunit.module("Recursive deserializer", (function (param) {
|
|
94
|
-
var fields = {
|
|
95
|
-
TAG: "Object",
|
|
96
|
-
_0: [
|
|
97
|
-
[
|
|
98
|
-
"data",
|
|
99
|
-
"Any"
|
|
100
|
-
],
|
|
101
|
-
[
|
|
102
|
-
"children",
|
|
103
|
-
{
|
|
104
|
-
TAG: "Array",
|
|
105
|
-
_0: "Self"
|
|
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, 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(checkFieldsSanity(), {
|
|
147
|
-
TAG: "Ok",
|
|
148
|
-
_0: undefined
|
|
149
|
-
}, "Ok");
|
|
150
|
-
}));
|
|
151
|
-
Qunit.test("Infinite list", (function (qunit) {
|
|
152
|
-
var fields = {
|
|
153
|
-
TAG: "Object",
|
|
154
|
-
_0: [
|
|
155
|
-
[
|
|
156
|
-
"head",
|
|
157
|
-
"String"
|
|
158
|
-
],
|
|
159
|
-
[
|
|
160
|
-
"tail",
|
|
161
|
-
"Self"
|
|
162
|
-
]
|
|
163
|
-
]
|
|
164
|
-
};
|
|
165
|
-
var InfiniteList = $$JSON.MakeDeserializer({
|
|
166
|
-
fields: fields
|
|
167
|
-
});
|
|
168
|
-
qunit.expect(1);
|
|
169
|
-
qunit.deepEqual(Curry._1(Prelude.Result.isError, InfiniteList.checkFieldsSanity()), true, "Ok");
|
|
170
|
-
}));
|
|
171
|
-
Qunit.test("Finite list", (function (qunit) {
|
|
172
|
-
var fields = {
|
|
173
|
-
TAG: "Object",
|
|
174
|
-
_0: [
|
|
175
|
-
[
|
|
176
|
-
"head",
|
|
177
|
-
"String"
|
|
178
|
-
],
|
|
179
|
-
[
|
|
180
|
-
"tail",
|
|
181
|
-
{
|
|
182
|
-
TAG: "Optional",
|
|
183
|
-
_0: "Self"
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
]
|
|
187
|
-
};
|
|
188
|
-
var List = $$JSON.MakeDeserializer({
|
|
189
|
-
fields: fields
|
|
190
|
-
});
|
|
191
|
-
qunit.expect(1);
|
|
192
|
-
qunit.deepEqual(List.checkFieldsSanity(), {
|
|
193
|
-
TAG: "Ok",
|
|
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") {
|
|
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",
|
|
213
|
-
_0: [
|
|
214
|
-
[
|
|
215
|
-
"head",
|
|
216
|
-
"String"
|
|
217
|
-
],
|
|
218
|
-
[
|
|
219
|
-
"tail",
|
|
220
|
-
{
|
|
221
|
-
TAG: "Optional",
|
|
222
|
-
_0: "Self"
|
|
223
|
-
}
|
|
224
|
-
]
|
|
225
|
-
]
|
|
226
|
-
};
|
|
227
|
-
var List = $$JSON.MakeDeserializer({
|
|
228
|
-
fields: fields
|
|
229
|
-
});
|
|
230
|
-
var fields$1 = {
|
|
231
|
-
TAG: "Object",
|
|
232
|
-
_0: [
|
|
233
|
-
[
|
|
234
|
-
"records",
|
|
235
|
-
{
|
|
236
|
-
TAG: "Deserializer",
|
|
237
|
-
_0: {
|
|
238
|
-
name: List.name,
|
|
239
|
-
fromJSON: List.fromJSON,
|
|
240
|
-
checkFieldsSanity: List.checkFieldsSanity
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
],
|
|
244
|
-
[
|
|
245
|
-
"next",
|
|
246
|
-
{
|
|
247
|
-
TAG: "Optional",
|
|
248
|
-
_0: "Self"
|
|
249
|
-
}
|
|
250
|
-
]
|
|
251
|
-
]
|
|
252
|
-
};
|
|
253
|
-
var Ledger = $$JSON.MakeDeserializer({
|
|
254
|
-
fields: fields$1
|
|
255
|
-
});
|
|
256
|
-
var data = {"records": {"head": "A", "tail": {"head": "B"}},
|
|
257
|
-
"next": {"records": {"head": "A", "tail": {"head": "B"}}}};
|
|
258
|
-
var expected = {
|
|
259
|
-
records: {
|
|
260
|
-
head: "A",
|
|
261
|
-
tail: {
|
|
262
|
-
head: "B",
|
|
263
|
-
tail: undefined
|
|
264
|
-
}
|
|
265
|
-
},
|
|
266
|
-
next: {
|
|
267
|
-
records: {
|
|
268
|
-
head: "A",
|
|
269
|
-
tail: {
|
|
270
|
-
head: "B",
|
|
271
|
-
tail: undefined
|
|
272
|
-
}
|
|
273
|
-
},
|
|
274
|
-
next: undefined
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
qunit.expect(1);
|
|
278
|
-
qunit.deepEqual(Ledger.fromJSON(data), {
|
|
279
|
-
TAG: "Ok",
|
|
280
|
-
_0: expected
|
|
281
|
-
}, "nice ledger");
|
|
282
|
-
}));
|
|
283
|
-
}));
|
|
284
|
-
|
|
285
|
-
export {
|
|
286
|
-
Appointment ,
|
|
287
|
-
}
|
|
288
|
-
/* Deserializer Not a pure module */
|