@kaiko.io/rescript-deser 3.1.0 → 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/.bsbuild +0 -0
- package/lib/bs/.bsdeps +8 -0
- package/lib/bs/.compiler.log +2 -0
- package/lib/bs/.ninja_log +28 -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/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/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/es6/src/JSON.js +628 -0
- package/lib/es6/tests/QUnit.js +2 -0
- package/lib/es6/tests/index.js +284 -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/.dir-locals.el +0 -6
- package/.gitlab-ci.yml +0 -52
- package/Makefile +0 -32
- package/bsconfig.json +0 -20
|
@@ -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.1.
|
|
3
|
+
"version": "3.1.2",
|
|
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.2",
|
|
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/.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
|
-
}
|