@kaiko.io/rescript-deser 6.0.0 → 7.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/README.md +3 -3
- package/lib/bs/.bsdeps +4 -4
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.ninja_log +55 -43
- package/lib/bs/.project-files-cache +0 -0
- package/lib/bs/___incremental/Deser.cmi +0 -0
- package/lib/bs/___incremental/Deser.cmj +0 -0
- package/lib/bs/___incremental/Deser.cmt +0 -0
- package/lib/bs/___incremental/Deser.res +351 -0
- package/lib/bs/___incremental/index.cmi +0 -0
- package/lib/bs/___incremental/index.cmj +0 -0
- package/lib/bs/___incremental/index.cmt +0 -0
- package/lib/bs/___incremental/index.res +189 -0
- package/lib/bs/src/Deser.ast +0 -0
- package/lib/bs/src/Deser.cmi +0 -0
- package/lib/bs/src/Deser.cmj +0 -0
- package/lib/bs/src/Deser.cmt +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.cmt +0 -0
- package/lib/es6/src/Deser.js +133 -237
- package/lib/js/src/Deser.js +133 -237
- package/package.json +2 -1
- package/src/Deser.res +80 -74
- package/tests/index.res +10 -10
- package/tests/run-tests.js +192 -0
package/lib/js/src/Deser.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var Js_json = require("rescript/lib/js/js_json.js");
|
|
5
4
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
|
6
5
|
var Core__Dict = require("@rescript/core/lib/js/src/Core__Dict.js");
|
|
7
6
|
var Caml_option = require("rescript/lib/js/caml_option.js");
|
|
@@ -139,28 +138,26 @@ function toString(type_) {
|
|
|
139
138
|
}
|
|
140
139
|
|
|
141
140
|
function _taggedToString(tagged) {
|
|
142
|
-
if (typeof tagged !== "object") {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
141
|
+
if (!Array.isArray(tagged) && (tagged === null || typeof tagged !== "object") && typeof tagged !== "number" && typeof tagged !== "string" && typeof tagged !== "boolean") {
|
|
142
|
+
return "Null";
|
|
143
|
+
}
|
|
144
|
+
if (Array.isArray(tagged)) {
|
|
145
|
+
return "Array(" + Core__Option.getOr(JSON.stringify(tagged), "...") + ")";
|
|
146
|
+
}
|
|
147
|
+
switch (typeof tagged) {
|
|
148
|
+
case "boolean" :
|
|
149
|
+
if (tagged) {
|
|
147
150
|
return "Boolean(true)";
|
|
148
|
-
|
|
149
|
-
return "
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
case "JSONObject" :
|
|
159
|
-
return "Object(" + Core__Option.getOr(JSON.stringify(tagged._0), "...") + ")";
|
|
160
|
-
case "JSONArray" :
|
|
161
|
-
return "Array(" + Core__Option.getOr(JSON.stringify(tagged._0), "...") + ")";
|
|
162
|
-
|
|
163
|
-
}
|
|
151
|
+
} else {
|
|
152
|
+
return "Boolean(false)";
|
|
153
|
+
}
|
|
154
|
+
case "string" :
|
|
155
|
+
return "String(\"" + tagged + "\")";
|
|
156
|
+
case "number" :
|
|
157
|
+
return "Number(" + tagged.toString() + ")";
|
|
158
|
+
case "object" :
|
|
159
|
+
return "Object(" + Core__Option.getOr(JSON.stringify(tagged), "...") + ")";
|
|
160
|
+
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
163
|
|
|
@@ -190,93 +187,34 @@ function extractValue(values, field, shape, self) {
|
|
|
190
187
|
function fromUntagged(untagged, _shape, self) {
|
|
191
188
|
while(true) {
|
|
192
189
|
var shape = _shape;
|
|
193
|
-
var match = Js_json.classify(untagged);
|
|
194
190
|
var exit = 0;
|
|
195
|
-
var s;
|
|
196
|
-
var f;
|
|
197
191
|
if (typeof shape !== "object") {
|
|
198
192
|
switch (shape) {
|
|
199
193
|
case "Any" :
|
|
200
194
|
return untagged;
|
|
201
195
|
case "String" :
|
|
202
|
-
if (typeof
|
|
203
|
-
|
|
204
|
-
} else {
|
|
205
|
-
if (match.TAG === "JSONString") {
|
|
206
|
-
return match._0;
|
|
207
|
-
}
|
|
208
|
-
exit = 1;
|
|
196
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && typeof untagged === "string") {
|
|
197
|
+
return untagged;
|
|
209
198
|
}
|
|
210
199
|
break;
|
|
211
200
|
case "Int" :
|
|
212
|
-
if (typeof
|
|
213
|
-
|
|
214
|
-
} else {
|
|
215
|
-
if (match.TAG === "JSONNumber") {
|
|
216
|
-
return match._0 | 0;
|
|
217
|
-
}
|
|
218
|
-
exit = 1;
|
|
201
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && typeof untagged === "number") {
|
|
202
|
+
return untagged | 0;
|
|
219
203
|
}
|
|
220
204
|
break;
|
|
221
205
|
case "Float" :
|
|
222
|
-
if (typeof
|
|
223
|
-
|
|
224
|
-
} else {
|
|
225
|
-
if (match.TAG === "JSONNumber") {
|
|
226
|
-
return match._0;
|
|
227
|
-
}
|
|
228
|
-
exit = 1;
|
|
206
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && typeof untagged === "number") {
|
|
207
|
+
return untagged;
|
|
229
208
|
}
|
|
230
209
|
break;
|
|
231
210
|
case "Boolean" :
|
|
232
|
-
if (typeof
|
|
233
|
-
|
|
234
|
-
case "JSONFalse" :
|
|
235
|
-
return false;
|
|
236
|
-
case "JSONTrue" :
|
|
237
|
-
return true;
|
|
238
|
-
default:
|
|
239
|
-
exit = 1;
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
exit = 1;
|
|
211
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && typeof untagged === "boolean") {
|
|
212
|
+
return untagged;
|
|
243
213
|
}
|
|
244
214
|
break;
|
|
245
215
|
case "Date" :
|
|
246
|
-
if (typeof match !== "object") {
|
|
247
|
-
exit = 1;
|
|
248
|
-
} else {
|
|
249
|
-
switch (match.TAG) {
|
|
250
|
-
case "JSONString" :
|
|
251
|
-
s = match._0;
|
|
252
|
-
exit = 2;
|
|
253
|
-
break;
|
|
254
|
-
case "JSONNumber" :
|
|
255
|
-
f = match._0;
|
|
256
|
-
exit = 3;
|
|
257
|
-
break;
|
|
258
|
-
default:
|
|
259
|
-
exit = 1;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
break;
|
|
263
216
|
case "Datetime" :
|
|
264
|
-
|
|
265
|
-
exit = 1;
|
|
266
|
-
} else {
|
|
267
|
-
switch (match.TAG) {
|
|
268
|
-
case "JSONString" :
|
|
269
|
-
s = match._0;
|
|
270
|
-
exit = 2;
|
|
271
|
-
break;
|
|
272
|
-
case "JSONNumber" :
|
|
273
|
-
f = match._0;
|
|
274
|
-
exit = 3;
|
|
275
|
-
break;
|
|
276
|
-
default:
|
|
277
|
-
exit = 1;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
217
|
+
exit = 2;
|
|
280
218
|
break;
|
|
281
219
|
case "Self" :
|
|
282
220
|
_shape = self;
|
|
@@ -286,133 +224,91 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
286
224
|
} else {
|
|
287
225
|
switch (shape.TAG) {
|
|
288
226
|
case "Literal" :
|
|
289
|
-
if (typeof
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
var text = match._0;
|
|
294
|
-
var expected = shape._0;
|
|
295
|
-
if (text === expected) {
|
|
296
|
-
return text;
|
|
297
|
-
}
|
|
298
|
-
throw {
|
|
299
|
-
RE_EXN_ID: $$TypeError,
|
|
300
|
-
_1: "Expecting literal " + expected + ", got " + text,
|
|
301
|
-
Error: new Error()
|
|
302
|
-
};
|
|
227
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && typeof untagged === "string") {
|
|
228
|
+
var expected = shape._0;
|
|
229
|
+
if (untagged === expected) {
|
|
230
|
+
return untagged;
|
|
303
231
|
}
|
|
304
|
-
|
|
232
|
+
throw {
|
|
233
|
+
RE_EXN_ID: $$TypeError,
|
|
234
|
+
_1: "Expecting literal " + expected + ", got " + untagged,
|
|
235
|
+
Error: new Error()
|
|
236
|
+
};
|
|
305
237
|
}
|
|
306
238
|
break;
|
|
307
239
|
case "Array" :
|
|
308
|
-
if (typeof
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return fromUntagged(item, shape$1, self);
|
|
316
|
-
}
|
|
317
|
-
}(shape$1)));
|
|
318
|
-
}
|
|
319
|
-
exit = 1;
|
|
240
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && Array.isArray(untagged)) {
|
|
241
|
+
var shape$1 = shape._0;
|
|
242
|
+
return untagged.map((function(shape$1){
|
|
243
|
+
return function (item) {
|
|
244
|
+
return fromUntagged(item, shape$1, self);
|
|
245
|
+
}
|
|
246
|
+
}(shape$1)));
|
|
320
247
|
}
|
|
321
248
|
break;
|
|
322
249
|
case "Tuple" :
|
|
323
|
-
if (typeof
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (lenbases === lenitems) {
|
|
332
|
-
return Belt_Array.zipBy(items, bases, (function (i, b) {
|
|
333
|
-
return fromUntagged(i, b, self);
|
|
334
|
-
}));
|
|
335
|
-
}
|
|
336
|
-
throw {
|
|
337
|
-
RE_EXN_ID: $$TypeError,
|
|
338
|
-
_1: "Expecting " + lenbases.toString() + " items, got " + lenitems.toString(),
|
|
339
|
-
Error: new Error()
|
|
340
|
-
};
|
|
250
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && Array.isArray(untagged)) {
|
|
251
|
+
var bases = shape._0;
|
|
252
|
+
var lenbases = bases.length;
|
|
253
|
+
var lenitems = untagged.length;
|
|
254
|
+
if (lenbases === lenitems) {
|
|
255
|
+
return Belt_Array.zipBy(untagged, bases, (function (i, b) {
|
|
256
|
+
return fromUntagged(i, b, self);
|
|
257
|
+
}));
|
|
341
258
|
}
|
|
342
|
-
|
|
259
|
+
throw {
|
|
260
|
+
RE_EXN_ID: $$TypeError,
|
|
261
|
+
_1: "Expecting " + lenbases.toString() + " items, got " + lenitems.toString(),
|
|
262
|
+
Error: new Error()
|
|
263
|
+
};
|
|
343
264
|
}
|
|
344
265
|
break;
|
|
345
266
|
case "Object" :
|
|
346
|
-
if (typeof
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
var
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
throw {
|
|
362
|
-
RE_EXN_ID: $$TypeError,
|
|
363
|
-
_1: "Field \"" + field + "\": " + msg._1,
|
|
364
|
-
Error: new Error()
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
throw msg;
|
|
267
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && typeof untagged === "object" && !Array.isArray(untagged)) {
|
|
268
|
+
return Object.fromEntries(shape._0.map(function (param) {
|
|
269
|
+
var field = param[0];
|
|
270
|
+
var value;
|
|
271
|
+
try {
|
|
272
|
+
value = extractValue(untagged, field, param[1], self);
|
|
273
|
+
}
|
|
274
|
+
catch (raw_msg){
|
|
275
|
+
var msg = Caml_js_exceptions.internalToOCamlException(raw_msg);
|
|
276
|
+
if (msg.RE_EXN_ID === $$TypeError) {
|
|
277
|
+
throw {
|
|
278
|
+
RE_EXN_ID: $$TypeError,
|
|
279
|
+
_1: "Field \"" + field + "\": " + msg._1,
|
|
280
|
+
Error: new Error()
|
|
281
|
+
};
|
|
368
282
|
}
|
|
369
|
-
|
|
370
|
-
field,
|
|
371
|
-
value
|
|
372
|
-
];
|
|
283
|
+
throw msg;
|
|
373
284
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
285
|
+
return [
|
|
286
|
+
field,
|
|
287
|
+
value
|
|
288
|
+
];
|
|
289
|
+
}));
|
|
377
290
|
}
|
|
378
291
|
break;
|
|
379
292
|
case "Optional" :
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (match === "JSONNull") {
|
|
383
|
-
return undefined;
|
|
384
|
-
}
|
|
385
|
-
_shape = shape$2;
|
|
386
|
-
continue ;
|
|
387
|
-
} else {
|
|
388
|
-
_shape = shape$2;
|
|
389
|
-
continue ;
|
|
293
|
+
if (!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") {
|
|
294
|
+
return undefined;
|
|
390
295
|
}
|
|
296
|
+
_shape = shape._0;
|
|
297
|
+
continue ;
|
|
391
298
|
case "OptionalWithDefault" :
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (match === "JSONNull") {
|
|
395
|
-
return shape._1;
|
|
396
|
-
}
|
|
397
|
-
_shape = shape$3;
|
|
398
|
-
continue ;
|
|
399
|
-
} else {
|
|
400
|
-
_shape = shape$3;
|
|
401
|
-
continue ;
|
|
299
|
+
if (!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") {
|
|
300
|
+
return shape._1;
|
|
402
301
|
}
|
|
302
|
+
_shape = shape._0;
|
|
303
|
+
continue ;
|
|
403
304
|
case "Mapping" :
|
|
404
|
-
if (typeof
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return fromUntagged(v, f$1, self);
|
|
412
|
-
}
|
|
413
|
-
}(f$1)));
|
|
414
|
-
}
|
|
415
|
-
exit = 1;
|
|
305
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && typeof untagged === "object" && !Array.isArray(untagged)) {
|
|
306
|
+
var f = shape._0;
|
|
307
|
+
return Core__Dict.mapValues(untagged, (function(f){
|
|
308
|
+
return function (v) {
|
|
309
|
+
return fromUntagged(v, f, self);
|
|
310
|
+
}
|
|
311
|
+
}(f)));
|
|
416
312
|
}
|
|
417
313
|
break;
|
|
418
314
|
case "Deserializer" :
|
|
@@ -426,17 +322,15 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
426
322
|
Error: new Error()
|
|
427
323
|
};
|
|
428
324
|
case "Collection" :
|
|
429
|
-
if (typeof
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}).map(function (prim) {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
exit = 1;
|
|
325
|
+
if (!(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean") && Array.isArray(untagged)) {
|
|
326
|
+
return Core__Array.filterMap(untagged.map(shape._0.fromJSON), (function (x) {
|
|
327
|
+
if (x.TAG === "Ok") {
|
|
328
|
+
return Caml_option.some(x._0);
|
|
329
|
+
}
|
|
330
|
+
console.warn("Deser", "Could not deserialize value in the collection", x._0);
|
|
331
|
+
})).map(function (prim) {
|
|
332
|
+
return prim;
|
|
333
|
+
});
|
|
440
334
|
}
|
|
441
335
|
break;
|
|
442
336
|
case "DefaultWhenInvalid" :
|
|
@@ -456,35 +350,37 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
456
350
|
|
|
457
351
|
}
|
|
458
352
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
return r$1;
|
|
486
|
-
|
|
353
|
+
if (exit === 2 && !(!Array.isArray(untagged) && (untagged === null || typeof untagged !== "object") && typeof untagged !== "number" && typeof untagged !== "string" && typeof untagged !== "boolean")) {
|
|
354
|
+
switch (typeof untagged) {
|
|
355
|
+
case "string" :
|
|
356
|
+
var r = new Date(untagged);
|
|
357
|
+
if (isNaN(r.getDate())) {
|
|
358
|
+
throw {
|
|
359
|
+
RE_EXN_ID: $$TypeError,
|
|
360
|
+
_1: "Invalid date " + untagged,
|
|
361
|
+
Error: new Error()
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
return r;
|
|
365
|
+
case "number" :
|
|
366
|
+
var r$1 = new Date(untagged);
|
|
367
|
+
if (isNaN(r$1.getDate())) {
|
|
368
|
+
throw {
|
|
369
|
+
RE_EXN_ID: $$TypeError,
|
|
370
|
+
_1: "Invalid date " + untagged.toString(),
|
|
371
|
+
Error: new Error()
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
return r$1;
|
|
375
|
+
default:
|
|
376
|
+
|
|
377
|
+
}
|
|
487
378
|
}
|
|
379
|
+
throw {
|
|
380
|
+
RE_EXN_ID: $$TypeError,
|
|
381
|
+
_1: "Expected " + toString(shape) + ", but got " + _taggedToString(untagged) + " instead",
|
|
382
|
+
Error: new Error()
|
|
383
|
+
};
|
|
488
384
|
};
|
|
489
385
|
}
|
|
490
386
|
|
|
@@ -617,7 +513,7 @@ var Field = {
|
|
|
617
513
|
|
|
618
514
|
function MakeDeserializer(S) {
|
|
619
515
|
var fields = S.fields;
|
|
620
|
-
var name = "Deserializer " + "Deser" + ", " + "File \"Deser.res\", line
|
|
516
|
+
var name = "Deserializer " + "Deser" + ", " + "File \"Deser.res\", line 328, characters 39-47";
|
|
621
517
|
var checkFieldsSanity$1 = function () {
|
|
622
518
|
return checkFieldsSanity(name, fields, false);
|
|
623
519
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaiko.io/rescript-deser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-alpha.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"json",
|
|
6
6
|
"deserializer",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@babel/code-frame": "7.18.6",
|
|
27
27
|
"@jihchi/vite-plugin-rescript": "^6.0",
|
|
28
|
+
"@playwright/test": "1.56.1",
|
|
28
29
|
"@rescript/core": "^1.6.0",
|
|
29
30
|
"@rescript/tools": "0.6.4",
|
|
30
31
|
"qunit": "^2.16.0",
|