@kaiko.io/rescript-deser 3.1.3 → 4.0.0-alpha.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/lib/bs/.bsdeps +5 -5
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.ninja_log +70 -27
- package/lib/bs/build.ninja +3 -3
- 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/tests/Appointment.cmt +0 -0
- package/lib/bs/tests/QUnit.ast +0 -0
- package/lib/bs/tests/QUnit.cmi +0 -0
- package/lib/bs/tests/QUnit.cmt +0 -0
- package/lib/bs/tests/Recursive.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.cmt +0 -0
- package/lib/bs/tests/old.cmt +0 -0
- package/lib/es6/src/JSON.js +187 -169
- package/lib/es6/tests/index.js +37 -37
- package/lib/js/src/JSON.js +187 -169
- package/lib/js/tests/index.js +37 -37
- package/package.json +3 -3
- package/src/JSON.res +10 -12
package/lib/js/tests/index.js
CHANGED
|
@@ -7,21 +7,21 @@ var Qunit = require("qunit");
|
|
|
7
7
|
var Prelude = require("@kaiko.io/rescript-prelude/lib/js/src/Prelude.js");
|
|
8
8
|
|
|
9
9
|
var fields = {
|
|
10
|
-
TAG:
|
|
10
|
+
TAG: "Object",
|
|
11
11
|
_0: [
|
|
12
12
|
[
|
|
13
13
|
"note",
|
|
14
|
-
|
|
14
|
+
"String"
|
|
15
15
|
],
|
|
16
16
|
[
|
|
17
17
|
"date",
|
|
18
|
-
|
|
18
|
+
"Date"
|
|
19
19
|
],
|
|
20
20
|
[
|
|
21
21
|
"extra",
|
|
22
22
|
{
|
|
23
|
-
TAG:
|
|
24
|
-
_0:
|
|
23
|
+
TAG: "Optional",
|
|
24
|
+
_0: "String"
|
|
25
25
|
}
|
|
26
26
|
]
|
|
27
27
|
]
|
|
@@ -63,8 +63,8 @@ Qunit.module("Basic deserializer", (function (param) {
|
|
|
63
63
|
Curry._2(Prelude.$$Array.forEach, valid, (function (param) {
|
|
64
64
|
var data = param[0];
|
|
65
65
|
console.log("Running sample", data);
|
|
66
|
-
var result =
|
|
67
|
-
if (result.TAG ===
|
|
66
|
+
var result = Deserializer.fromJSON(data);
|
|
67
|
+
if (result.TAG === "Ok") {
|
|
68
68
|
qunit.deepEqual(result._0, param[1], "result == expected");
|
|
69
69
|
return ;
|
|
70
70
|
}
|
|
@@ -80,8 +80,8 @@ Qunit.module("Basic deserializer", (function (param) {
|
|
|
80
80
|
Curry._2(Prelude.$$Array.forEach, invalid, (function (param) {
|
|
81
81
|
var data = param[1];
|
|
82
82
|
console.log("Running sample", param[0], data);
|
|
83
|
-
var result =
|
|
84
|
-
if (result.TAG ===
|
|
83
|
+
var result = Deserializer.fromJSON(data);
|
|
84
|
+
if (result.TAG === "Ok") {
|
|
85
85
|
console.error("Invalid being accepted: ", result._0);
|
|
86
86
|
return ;
|
|
87
87
|
}
|
|
@@ -93,17 +93,17 @@ Qunit.module("Basic deserializer", (function (param) {
|
|
|
93
93
|
|
|
94
94
|
Qunit.module("Recursive deserializer", (function (param) {
|
|
95
95
|
var fields = {
|
|
96
|
-
TAG:
|
|
96
|
+
TAG: "Object",
|
|
97
97
|
_0: [
|
|
98
98
|
[
|
|
99
99
|
"data",
|
|
100
|
-
|
|
100
|
+
"Any"
|
|
101
101
|
],
|
|
102
102
|
[
|
|
103
103
|
"children",
|
|
104
104
|
{
|
|
105
|
-
TAG:
|
|
106
|
-
_0:
|
|
105
|
+
TAG: "Array",
|
|
106
|
+
_0: "Self"
|
|
107
107
|
}
|
|
108
108
|
]
|
|
109
109
|
]
|
|
@@ -113,7 +113,7 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
113
113
|
});
|
|
114
114
|
var checkFieldsSanity = DeserializerImpl.checkFieldsSanity;
|
|
115
115
|
var fromJSON = function (data) {
|
|
116
|
-
return Curry._2(Prelude.Result.map,
|
|
116
|
+
return Curry._2(Prelude.Result.map, DeserializerImpl.fromJSON(data), (function (prim) {
|
|
117
117
|
return prim;
|
|
118
118
|
}));
|
|
119
119
|
};
|
|
@@ -144,22 +144,22 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
144
144
|
]];
|
|
145
145
|
Qunit.test("Trivial recursion detection: Ok", (function (qunit) {
|
|
146
146
|
qunit.expect(1);
|
|
147
|
-
qunit.deepEqual(
|
|
148
|
-
TAG:
|
|
147
|
+
qunit.deepEqual(checkFieldsSanity(undefined), {
|
|
148
|
+
TAG: "Ok",
|
|
149
149
|
_0: undefined
|
|
150
150
|
}, "Ok");
|
|
151
151
|
}));
|
|
152
152
|
Qunit.test("Infinite list", (function (qunit) {
|
|
153
153
|
var fields = {
|
|
154
|
-
TAG:
|
|
154
|
+
TAG: "Object",
|
|
155
155
|
_0: [
|
|
156
156
|
[
|
|
157
157
|
"head",
|
|
158
|
-
|
|
158
|
+
"String"
|
|
159
159
|
],
|
|
160
160
|
[
|
|
161
161
|
"tail",
|
|
162
|
-
|
|
162
|
+
"Self"
|
|
163
163
|
]
|
|
164
164
|
]
|
|
165
165
|
};
|
|
@@ -167,21 +167,21 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
167
167
|
fields: fields
|
|
168
168
|
});
|
|
169
169
|
qunit.expect(1);
|
|
170
|
-
qunit.deepEqual(Curry._1(Prelude.Result.isError,
|
|
170
|
+
qunit.deepEqual(Curry._1(Prelude.Result.isError, InfiniteList.checkFieldsSanity(undefined)), true, "Ok");
|
|
171
171
|
}));
|
|
172
172
|
Qunit.test("Finite list", (function (qunit) {
|
|
173
173
|
var fields = {
|
|
174
|
-
TAG:
|
|
174
|
+
TAG: "Object",
|
|
175
175
|
_0: [
|
|
176
176
|
[
|
|
177
177
|
"head",
|
|
178
|
-
|
|
178
|
+
"String"
|
|
179
179
|
],
|
|
180
180
|
[
|
|
181
181
|
"tail",
|
|
182
182
|
{
|
|
183
|
-
TAG:
|
|
184
|
-
_0:
|
|
183
|
+
TAG: "Optional",
|
|
184
|
+
_0: "Self"
|
|
185
185
|
}
|
|
186
186
|
]
|
|
187
187
|
]
|
|
@@ -190,8 +190,8 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
190
190
|
fields: fields
|
|
191
191
|
});
|
|
192
192
|
qunit.expect(1);
|
|
193
|
-
qunit.deepEqual(
|
|
194
|
-
TAG:
|
|
193
|
+
qunit.deepEqual(List.checkFieldsSanity(undefined), {
|
|
194
|
+
TAG: "Ok",
|
|
195
195
|
_0: undefined
|
|
196
196
|
}, "Ok");
|
|
197
197
|
}));
|
|
@@ -201,7 +201,7 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
201
201
|
var data = param[0];
|
|
202
202
|
console.log("Running sample", data);
|
|
203
203
|
var result = fromJSON(data);
|
|
204
|
-
if (result.TAG ===
|
|
204
|
+
if (result.TAG === "Ok") {
|
|
205
205
|
qunit.deepEqual(result._0, param[1], "result == expected");
|
|
206
206
|
return ;
|
|
207
207
|
}
|
|
@@ -210,17 +210,17 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
210
210
|
}));
|
|
211
211
|
Qunit.test("Recursion in sub-deserializer", (function (qunit) {
|
|
212
212
|
var fields = {
|
|
213
|
-
TAG:
|
|
213
|
+
TAG: "Object",
|
|
214
214
|
_0: [
|
|
215
215
|
[
|
|
216
216
|
"head",
|
|
217
|
-
|
|
217
|
+
"String"
|
|
218
218
|
],
|
|
219
219
|
[
|
|
220
220
|
"tail",
|
|
221
221
|
{
|
|
222
|
-
TAG:
|
|
223
|
-
_0:
|
|
222
|
+
TAG: "Optional",
|
|
223
|
+
_0: "Self"
|
|
224
224
|
}
|
|
225
225
|
]
|
|
226
226
|
]
|
|
@@ -229,20 +229,20 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
229
229
|
fields: fields
|
|
230
230
|
});
|
|
231
231
|
var fields$1 = {
|
|
232
|
-
TAG:
|
|
232
|
+
TAG: "Object",
|
|
233
233
|
_0: [
|
|
234
234
|
[
|
|
235
235
|
"records",
|
|
236
236
|
{
|
|
237
|
-
TAG:
|
|
237
|
+
TAG: "Deserializer",
|
|
238
238
|
_0: List
|
|
239
239
|
}
|
|
240
240
|
],
|
|
241
241
|
[
|
|
242
242
|
"next",
|
|
243
243
|
{
|
|
244
|
-
TAG:
|
|
245
|
-
_0:
|
|
244
|
+
TAG: "Optional",
|
|
245
|
+
_0: "Self"
|
|
246
246
|
}
|
|
247
247
|
]
|
|
248
248
|
]
|
|
@@ -272,8 +272,8 @@ Qunit.module("Recursive deserializer", (function (param) {
|
|
|
272
272
|
}
|
|
273
273
|
};
|
|
274
274
|
qunit.expect(1);
|
|
275
|
-
qunit.deepEqual(
|
|
276
|
-
TAG:
|
|
275
|
+
qunit.deepEqual(Ledger.fromJSON(data), {
|
|
276
|
+
TAG: "Ok",
|
|
277
277
|
_0: expected
|
|
278
278
|
}, "nice ledger");
|
|
279
279
|
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaiko.io/rescript-deser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"json",
|
|
6
6
|
"deserializer",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"README.md"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@kaiko.io/rescript-prelude": "
|
|
24
|
-
"rescript": "
|
|
23
|
+
"@kaiko.io/rescript-prelude": "7.0.0-alpha.3",
|
|
24
|
+
"rescript": "next"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"esbuild": "^0.15.7",
|
package/src/JSON.res
CHANGED
|
@@ -72,12 +72,12 @@ module Field = {
|
|
|
72
72
|
|
|
73
73
|
| Self
|
|
74
74
|
|
|
75
|
-
let usingString = (f: string => 'a
|
|
76
|
-
let usingInt = (f: int => 'a
|
|
77
|
-
let usingFloat = (f: float => 'a
|
|
78
|
-
let usingBoolean = (f: bool => 'a
|
|
79
|
-
let usingArray = (f: array<'a> => 'b
|
|
80
|
-
let usingObject = (f: 'a => 'b
|
|
75
|
+
let usingString = (f: string => 'a) => value => value->FieldValue.asString->f->FieldValue.any
|
|
76
|
+
let usingInt = (f: int => 'a) => value => value->FieldValue.asInt->f->FieldValue.any
|
|
77
|
+
let usingFloat = (f: float => 'a) => value => value->FieldValue.asFloat->f->FieldValue.any
|
|
78
|
+
let usingBoolean = (f: bool => 'a) => value => value->FieldValue.asBoolean->f->FieldValue.any
|
|
79
|
+
let usingArray = (f: array<'a> => 'b) => value => value->FieldValue.asArray->f->FieldValue.any
|
|
80
|
+
let usingObject = (f: 'a => 'b) => value => value->FieldValue.asObject->f->FieldValue.any
|
|
81
81
|
|
|
82
82
|
let variadicInt = (hint: string, fromJs: int => option<'variadicType>) => Morphism(
|
|
83
83
|
Int,
|
|
@@ -290,9 +290,8 @@ module Field = {
|
|
|
290
290
|
|
|
291
291
|
| (Object(fields), optional) =>
|
|
292
292
|
fields
|
|
293
|
-
->Array.map(((fieldName, field)
|
|
294
|
-
checkFieldsSanity(`${name}::${fieldName}`, field, optional)
|
|
295
|
-
)
|
|
293
|
+
->Array.map(((fieldName, field)) => () =>
|
|
294
|
+
checkFieldsSanity(`${name}::${fieldName}`, field, optional))
|
|
296
295
|
->ManyResults.bailU
|
|
297
296
|
->ManyResults.map(_ => ())
|
|
298
297
|
|
|
@@ -302,9 +301,8 @@ module Field = {
|
|
|
302
301
|
|
|
303
302
|
| (Tuple(fields), optional) =>
|
|
304
303
|
fields
|
|
305
|
-
->Array.mapWithIndex((index, field
|
|
306
|
-
checkFieldsSanity(`${name}[${index->Int.toString}]`, field, optional)
|
|
307
|
-
)
|
|
304
|
+
->Array.mapWithIndex((index, field) => () =>
|
|
305
|
+
checkFieldsSanity(`${name}[${index->Int.toString}]`, field, optional))
|
|
308
306
|
->ManyResults.bailU
|
|
309
307
|
->ManyResults.map(_ => ())
|
|
310
308
|
}
|