@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/src/JSON.js
CHANGED
|
@@ -12,42 +12,54 @@ var FieldValue = {};
|
|
|
12
12
|
|
|
13
13
|
var $$TypeError = /* @__PURE__ */Caml_exceptions.create("JSON.TypeError");
|
|
14
14
|
|
|
15
|
-
function usingString(f
|
|
16
|
-
return
|
|
15
|
+
function usingString(f) {
|
|
16
|
+
return function (value) {
|
|
17
|
+
return f(value);
|
|
18
|
+
};
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
function usingInt(f
|
|
20
|
-
return
|
|
21
|
+
function usingInt(f) {
|
|
22
|
+
return function (value) {
|
|
23
|
+
return f(value);
|
|
24
|
+
};
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
function usingFloat(f
|
|
24
|
-
return
|
|
27
|
+
function usingFloat(f) {
|
|
28
|
+
return function (value) {
|
|
29
|
+
return f(value);
|
|
30
|
+
};
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
function usingBoolean(f
|
|
28
|
-
return
|
|
33
|
+
function usingBoolean(f) {
|
|
34
|
+
return function (value) {
|
|
35
|
+
return f(value);
|
|
36
|
+
};
|
|
29
37
|
}
|
|
30
38
|
|
|
31
|
-
function usingArray(f
|
|
32
|
-
return
|
|
39
|
+
function usingArray(f) {
|
|
40
|
+
return function (value) {
|
|
41
|
+
return f(value);
|
|
42
|
+
};
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
function usingObject(f
|
|
36
|
-
return
|
|
45
|
+
function usingObject(f) {
|
|
46
|
+
return function (value) {
|
|
47
|
+
return f(value);
|
|
48
|
+
};
|
|
37
49
|
}
|
|
38
50
|
|
|
39
51
|
function variadicInt(hint, fromJs) {
|
|
40
52
|
return {
|
|
41
|
-
TAG:
|
|
42
|
-
_0:
|
|
43
|
-
_1: (function (
|
|
44
|
-
var internalValue =
|
|
53
|
+
TAG: "Morphism",
|
|
54
|
+
_0: "Int",
|
|
55
|
+
_1: (function (value) {
|
|
56
|
+
var internalValue = fromJs(value);
|
|
45
57
|
if (internalValue !== undefined) {
|
|
46
58
|
return Caml_option.valFromOption(internalValue);
|
|
47
59
|
}
|
|
48
60
|
throw {
|
|
49
61
|
RE_EXN_ID: $$TypeError,
|
|
50
|
-
_1: "This Int(" + String(
|
|
62
|
+
_1: "This Int(" + String(value) + ") not a valid value here. Hint: " + hint,
|
|
51
63
|
Error: new Error()
|
|
52
64
|
};
|
|
53
65
|
})
|
|
@@ -56,16 +68,16 @@ function variadicInt(hint, fromJs) {
|
|
|
56
68
|
|
|
57
69
|
function variadicString(hint, fromJs) {
|
|
58
70
|
return {
|
|
59
|
-
TAG:
|
|
60
|
-
_0:
|
|
61
|
-
_1: (function (
|
|
62
|
-
var internalValue =
|
|
71
|
+
TAG: "Morphism",
|
|
72
|
+
_0: "String",
|
|
73
|
+
_1: (function (value) {
|
|
74
|
+
var internalValue = fromJs(value);
|
|
63
75
|
if (internalValue !== undefined) {
|
|
64
76
|
return Caml_option.valFromOption(internalValue);
|
|
65
77
|
}
|
|
66
78
|
throw {
|
|
67
79
|
RE_EXN_ID: $$TypeError,
|
|
68
|
-
_1: "This String(\"" +
|
|
80
|
+
_1: "This String(\"" + value + "\") not a valid value here. Hint: " + hint,
|
|
69
81
|
Error: new Error()
|
|
70
82
|
};
|
|
71
83
|
})
|
|
@@ -73,50 +85,50 @@ function variadicString(hint, fromJs) {
|
|
|
73
85
|
}
|
|
74
86
|
|
|
75
87
|
function toString(type_) {
|
|
76
|
-
if (typeof type_
|
|
88
|
+
if (typeof type_ !== "object") {
|
|
77
89
|
switch (type_) {
|
|
78
|
-
case
|
|
90
|
+
case "Any" :
|
|
79
91
|
return "Any";
|
|
80
|
-
case
|
|
92
|
+
case "String" :
|
|
81
93
|
return "String";
|
|
82
|
-
case
|
|
94
|
+
case "Int" :
|
|
83
95
|
return "Integer";
|
|
84
|
-
case
|
|
96
|
+
case "Float" :
|
|
85
97
|
return "Float";
|
|
86
|
-
case
|
|
98
|
+
case "Boolean" :
|
|
87
99
|
return "Boolean";
|
|
88
|
-
case
|
|
89
|
-
case
|
|
100
|
+
case "Date" :
|
|
101
|
+
case "Datetime" :
|
|
90
102
|
return "Date";
|
|
91
|
-
case
|
|
103
|
+
case "Self" :
|
|
92
104
|
return "Self (recursive)";
|
|
93
105
|
|
|
94
106
|
}
|
|
95
107
|
} else {
|
|
96
|
-
switch (type_.TAG
|
|
97
|
-
case
|
|
98
|
-
return "Literal: " + type_._0
|
|
99
|
-
case
|
|
108
|
+
switch (type_.TAG) {
|
|
109
|
+
case "Literal" :
|
|
110
|
+
return "Literal: " + type_._0;
|
|
111
|
+
case "Array" :
|
|
100
112
|
return "Array of " + toString(type_._0);
|
|
101
|
-
case
|
|
113
|
+
case "Tuple" :
|
|
102
114
|
return "Tuple of (" + Curry._2(Prelude.$$Array.map, type_._0, toString).join(", ") + ")";
|
|
103
|
-
case
|
|
115
|
+
case "Object" :
|
|
104
116
|
var desc = Curry._2(Prelude.$$Array.map, type_._0, (function (param) {
|
|
105
|
-
return
|
|
117
|
+
return param[0] + ": " + toString(param[1]);
|
|
106
118
|
})).join(", ");
|
|
107
119
|
return "Object of {" + desc + "}";
|
|
108
|
-
case
|
|
109
|
-
case
|
|
120
|
+
case "Optional" :
|
|
121
|
+
case "OptionalWithDefault" :
|
|
110
122
|
return "Null of " + toString(type_._0);
|
|
111
|
-
case
|
|
112
|
-
return "Mapping of " + toString(type_._0)
|
|
113
|
-
case
|
|
123
|
+
case "Mapping" :
|
|
124
|
+
return "Mapping of " + toString(type_._0);
|
|
125
|
+
case "Deserializer" :
|
|
114
126
|
return type_._0.name;
|
|
115
|
-
case
|
|
127
|
+
case "Collection" :
|
|
116
128
|
return "Collection of " + type_._0.name;
|
|
117
|
-
case
|
|
118
|
-
return "Protected " + toString(type_._0)
|
|
119
|
-
case
|
|
129
|
+
case "DefaultWhenInvalid" :
|
|
130
|
+
return "Protected " + toString(type_._0);
|
|
131
|
+
case "Morphism" :
|
|
120
132
|
return toString(type_._0) + " to apply a morphism";
|
|
121
133
|
|
|
122
134
|
}
|
|
@@ -124,25 +136,25 @@ function toString(type_) {
|
|
|
124
136
|
}
|
|
125
137
|
|
|
126
138
|
function _taggedToString(tagged) {
|
|
127
|
-
if (typeof tagged
|
|
139
|
+
if (typeof tagged !== "object") {
|
|
128
140
|
switch (tagged) {
|
|
129
|
-
case
|
|
141
|
+
case "JSONFalse" :
|
|
130
142
|
return "Boolean(false)";
|
|
131
|
-
case
|
|
143
|
+
case "JSONTrue" :
|
|
132
144
|
return "Boolean(true)";
|
|
133
|
-
case
|
|
145
|
+
case "JSONNull" :
|
|
134
146
|
return "Null";
|
|
135
147
|
|
|
136
148
|
}
|
|
137
149
|
} else {
|
|
138
|
-
switch (tagged.TAG
|
|
139
|
-
case
|
|
150
|
+
switch (tagged.TAG) {
|
|
151
|
+
case "JSONString" :
|
|
140
152
|
return "String(\"" + tagged._0 + "\")";
|
|
141
|
-
case
|
|
153
|
+
case "JSONNumber" :
|
|
142
154
|
return "Number(" + String(tagged._0) + ")";
|
|
143
|
-
case
|
|
155
|
+
case "JSONObject" :
|
|
144
156
|
return "Object(" + Prelude.$$default(JSON.stringify(tagged._0), "...") + ")";
|
|
145
|
-
case
|
|
157
|
+
case "JSONArray" :
|
|
146
158
|
return "Array(" + Prelude.$$default(JSON.stringify(tagged._0), "...") + ")";
|
|
147
159
|
|
|
148
160
|
}
|
|
@@ -152,14 +164,14 @@ function _taggedToString(tagged) {
|
|
|
152
164
|
function extractValue(values, field, shape, self) {
|
|
153
165
|
var value = Curry._2(Prelude.Dict.get, values, field);
|
|
154
166
|
if (value !== undefined) {
|
|
155
|
-
return fromUntagged(
|
|
167
|
+
return fromUntagged(value, shape, self);
|
|
156
168
|
}
|
|
157
|
-
if (typeof shape
|
|
158
|
-
switch (shape.TAG
|
|
159
|
-
case
|
|
169
|
+
if (typeof shape === "object") {
|
|
170
|
+
switch (shape.TAG) {
|
|
171
|
+
case "OptionalWithDefault" :
|
|
160
172
|
return shape._1;
|
|
161
|
-
case
|
|
162
|
-
case
|
|
173
|
+
case "Optional" :
|
|
174
|
+
case "DefaultWhenInvalid" :
|
|
163
175
|
return fromUntagged(null, shape, self);
|
|
164
176
|
default:
|
|
165
177
|
|
|
@@ -179,66 +191,64 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
179
191
|
var exit = 0;
|
|
180
192
|
var s;
|
|
181
193
|
var f;
|
|
182
|
-
if (typeof shape
|
|
194
|
+
if (typeof shape !== "object") {
|
|
183
195
|
switch (shape) {
|
|
184
|
-
case
|
|
196
|
+
case "Any" :
|
|
185
197
|
return untagged;
|
|
186
|
-
case
|
|
187
|
-
if (typeof match
|
|
198
|
+
case "String" :
|
|
199
|
+
if (typeof match !== "object") {
|
|
188
200
|
exit = 1;
|
|
189
201
|
} else {
|
|
190
|
-
if (match.TAG ===
|
|
202
|
+
if (match.TAG === "JSONString") {
|
|
191
203
|
return match._0;
|
|
192
204
|
}
|
|
193
205
|
exit = 1;
|
|
194
206
|
}
|
|
195
207
|
break;
|
|
196
|
-
case
|
|
197
|
-
if (typeof match
|
|
208
|
+
case "Int" :
|
|
209
|
+
if (typeof match !== "object") {
|
|
198
210
|
exit = 1;
|
|
199
211
|
} else {
|
|
200
|
-
if (match.TAG ===
|
|
212
|
+
if (match.TAG === "JSONNumber") {
|
|
201
213
|
return match._0 | 0;
|
|
202
214
|
}
|
|
203
215
|
exit = 1;
|
|
204
216
|
}
|
|
205
217
|
break;
|
|
206
|
-
case
|
|
207
|
-
if (typeof match
|
|
218
|
+
case "Float" :
|
|
219
|
+
if (typeof match !== "object") {
|
|
208
220
|
exit = 1;
|
|
209
221
|
} else {
|
|
210
|
-
if (match.TAG ===
|
|
222
|
+
if (match.TAG === "JSONNumber") {
|
|
211
223
|
return match._0;
|
|
212
224
|
}
|
|
213
225
|
exit = 1;
|
|
214
226
|
}
|
|
215
227
|
break;
|
|
216
|
-
case
|
|
217
|
-
if (typeof match
|
|
228
|
+
case "Boolean" :
|
|
229
|
+
if (typeof match !== "object") {
|
|
218
230
|
switch (match) {
|
|
219
|
-
case
|
|
231
|
+
case "JSONFalse" :
|
|
220
232
|
return false;
|
|
221
|
-
case
|
|
233
|
+
case "JSONTrue" :
|
|
222
234
|
return true;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
break;
|
|
226
|
-
|
|
235
|
+
default:
|
|
236
|
+
exit = 1;
|
|
227
237
|
}
|
|
228
238
|
} else {
|
|
229
239
|
exit = 1;
|
|
230
240
|
}
|
|
231
241
|
break;
|
|
232
|
-
case
|
|
233
|
-
if (typeof match
|
|
242
|
+
case "Date" :
|
|
243
|
+
if (typeof match !== "object") {
|
|
234
244
|
exit = 1;
|
|
235
245
|
} else {
|
|
236
|
-
switch (match.TAG
|
|
237
|
-
case
|
|
246
|
+
switch (match.TAG) {
|
|
247
|
+
case "JSONString" :
|
|
238
248
|
s = match._0;
|
|
239
249
|
exit = 2;
|
|
240
250
|
break;
|
|
241
|
-
case
|
|
251
|
+
case "JSONNumber" :
|
|
242
252
|
f = match._0;
|
|
243
253
|
exit = 3;
|
|
244
254
|
break;
|
|
@@ -247,16 +257,16 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
247
257
|
}
|
|
248
258
|
}
|
|
249
259
|
break;
|
|
250
|
-
case
|
|
251
|
-
if (typeof match
|
|
260
|
+
case "Datetime" :
|
|
261
|
+
if (typeof match !== "object") {
|
|
252
262
|
exit = 1;
|
|
253
263
|
} else {
|
|
254
|
-
switch (match.TAG
|
|
255
|
-
case
|
|
264
|
+
switch (match.TAG) {
|
|
265
|
+
case "JSONString" :
|
|
256
266
|
s = match._0;
|
|
257
267
|
exit = 2;
|
|
258
268
|
break;
|
|
259
|
-
case
|
|
269
|
+
case "JSONNumber" :
|
|
260
270
|
f = match._0;
|
|
261
271
|
exit = 3;
|
|
262
272
|
break;
|
|
@@ -265,18 +275,18 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
265
275
|
}
|
|
266
276
|
}
|
|
267
277
|
break;
|
|
268
|
-
case
|
|
278
|
+
case "Self" :
|
|
269
279
|
_shape = self;
|
|
270
280
|
continue ;
|
|
271
281
|
|
|
272
282
|
}
|
|
273
283
|
} else {
|
|
274
|
-
switch (shape.TAG
|
|
275
|
-
case
|
|
276
|
-
if (typeof match
|
|
284
|
+
switch (shape.TAG) {
|
|
285
|
+
case "Literal" :
|
|
286
|
+
if (typeof match !== "object") {
|
|
277
287
|
exit = 1;
|
|
278
288
|
} else {
|
|
279
|
-
if (match.TAG ===
|
|
289
|
+
if (match.TAG === "JSONString") {
|
|
280
290
|
var text = match._0;
|
|
281
291
|
var expected = shape._0;
|
|
282
292
|
if (text === expected) {
|
|
@@ -284,18 +294,18 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
284
294
|
}
|
|
285
295
|
throw {
|
|
286
296
|
RE_EXN_ID: $$TypeError,
|
|
287
|
-
_1: "Expecting literal " + expected + ", got " + text
|
|
297
|
+
_1: "Expecting literal " + expected + ", got " + text,
|
|
288
298
|
Error: new Error()
|
|
289
299
|
};
|
|
290
300
|
}
|
|
291
301
|
exit = 1;
|
|
292
302
|
}
|
|
293
303
|
break;
|
|
294
|
-
case
|
|
295
|
-
if (typeof match
|
|
304
|
+
case "Array" :
|
|
305
|
+
if (typeof match !== "object") {
|
|
296
306
|
exit = 1;
|
|
297
307
|
} else {
|
|
298
|
-
if (match.TAG ===
|
|
308
|
+
if (match.TAG === "JSONArray") {
|
|
299
309
|
var shape$1 = shape._0;
|
|
300
310
|
return Curry._2(Prelude.$$Array.map, match._0, (function(shape$1){
|
|
301
311
|
return function (item) {
|
|
@@ -306,11 +316,11 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
306
316
|
exit = 1;
|
|
307
317
|
}
|
|
308
318
|
break;
|
|
309
|
-
case
|
|
310
|
-
if (typeof match
|
|
319
|
+
case "Tuple" :
|
|
320
|
+
if (typeof match !== "object") {
|
|
311
321
|
exit = 1;
|
|
312
322
|
} else {
|
|
313
|
-
if (match.TAG ===
|
|
323
|
+
if (match.TAG === "JSONArray") {
|
|
314
324
|
var items = match._0;
|
|
315
325
|
var bases = shape._0;
|
|
316
326
|
var lenbases = bases.length;
|
|
@@ -322,18 +332,18 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
322
332
|
}
|
|
323
333
|
throw {
|
|
324
334
|
RE_EXN_ID: $$TypeError,
|
|
325
|
-
_1: "Expecting " + String(lenbases) + " items, got " + String(lenitems)
|
|
335
|
+
_1: "Expecting " + String(lenbases) + " items, got " + String(lenitems),
|
|
326
336
|
Error: new Error()
|
|
327
337
|
};
|
|
328
338
|
}
|
|
329
339
|
exit = 1;
|
|
330
340
|
}
|
|
331
341
|
break;
|
|
332
|
-
case
|
|
333
|
-
if (typeof match
|
|
342
|
+
case "Object" :
|
|
343
|
+
if (typeof match !== "object") {
|
|
334
344
|
exit = 1;
|
|
335
345
|
} else {
|
|
336
|
-
if (match.TAG ===
|
|
346
|
+
if (match.TAG === "JSONObject") {
|
|
337
347
|
var values = match._0;
|
|
338
348
|
return Curry._1(Prelude.Dict.fromArray, Curry._2(Prelude.$$Array.map, shape._0, (function(values){
|
|
339
349
|
return function (param) {
|
|
@@ -347,7 +357,7 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
347
357
|
if (msg.RE_EXN_ID === $$TypeError) {
|
|
348
358
|
throw {
|
|
349
359
|
RE_EXN_ID: $$TypeError,
|
|
350
|
-
_1: "Field \"" + field + "\": " + msg._1
|
|
360
|
+
_1: "Field \"" + field + "\": " + msg._1,
|
|
351
361
|
Error: new Error()
|
|
352
362
|
};
|
|
353
363
|
}
|
|
@@ -363,33 +373,35 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
363
373
|
exit = 1;
|
|
364
374
|
}
|
|
365
375
|
break;
|
|
366
|
-
case
|
|
376
|
+
case "Optional" :
|
|
367
377
|
var shape$2 = shape._0;
|
|
368
|
-
if (typeof match
|
|
369
|
-
if (match
|
|
378
|
+
if (typeof match !== "object") {
|
|
379
|
+
if (match === "JSONNull") {
|
|
370
380
|
return undefined;
|
|
371
381
|
}
|
|
372
382
|
_shape = shape$2;
|
|
373
383
|
continue ;
|
|
384
|
+
} else {
|
|
385
|
+
_shape = shape$2;
|
|
386
|
+
continue ;
|
|
374
387
|
}
|
|
375
|
-
|
|
376
|
-
continue ;
|
|
377
|
-
case /* OptionalWithDefault */5 :
|
|
388
|
+
case "OptionalWithDefault" :
|
|
378
389
|
var shape$3 = shape._0;
|
|
379
|
-
if (typeof match
|
|
380
|
-
if (match
|
|
390
|
+
if (typeof match !== "object") {
|
|
391
|
+
if (match === "JSONNull") {
|
|
381
392
|
return shape._1;
|
|
382
393
|
}
|
|
383
394
|
_shape = shape$3;
|
|
384
395
|
continue ;
|
|
396
|
+
} else {
|
|
397
|
+
_shape = shape$3;
|
|
398
|
+
continue ;
|
|
385
399
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
case /* Mapping */6 :
|
|
389
|
-
if (typeof match === "number") {
|
|
400
|
+
case "Mapping" :
|
|
401
|
+
if (typeof match !== "object") {
|
|
390
402
|
exit = 1;
|
|
391
403
|
} else {
|
|
392
|
-
if (match.TAG ===
|
|
404
|
+
if (match.TAG === "JSONObject") {
|
|
393
405
|
var f$1 = shape._0;
|
|
394
406
|
return Prelude.Dict.mapValues(match._0, (function(f$1){
|
|
395
407
|
return function (v) {
|
|
@@ -400,9 +412,9 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
400
412
|
exit = 1;
|
|
401
413
|
}
|
|
402
414
|
break;
|
|
403
|
-
case
|
|
404
|
-
var res =
|
|
405
|
-
if (res.TAG ===
|
|
415
|
+
case "Deserializer" :
|
|
416
|
+
var res = shape._0.fromJSON(untagged);
|
|
417
|
+
if (res.TAG === "Ok") {
|
|
406
418
|
return res._0;
|
|
407
419
|
}
|
|
408
420
|
throw {
|
|
@@ -410,11 +422,11 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
410
422
|
_1: res._0,
|
|
411
423
|
Error: new Error()
|
|
412
424
|
};
|
|
413
|
-
case
|
|
414
|
-
if (typeof match
|
|
425
|
+
case "Collection" :
|
|
426
|
+
if (typeof match !== "object") {
|
|
415
427
|
exit = 1;
|
|
416
428
|
} else {
|
|
417
|
-
if (match.TAG ===
|
|
429
|
+
if (match.TAG === "JSONArray") {
|
|
418
430
|
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
431
|
return prim;
|
|
420
432
|
}));
|
|
@@ -422,7 +434,7 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
422
434
|
exit = 1;
|
|
423
435
|
}
|
|
424
436
|
break;
|
|
425
|
-
case
|
|
437
|
+
case "DefaultWhenInvalid" :
|
|
426
438
|
try {
|
|
427
439
|
return fromUntagged(untagged, shape._0, self);
|
|
428
440
|
}
|
|
@@ -434,8 +446,8 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
434
446
|
}
|
|
435
447
|
throw msg;
|
|
436
448
|
}
|
|
437
|
-
case
|
|
438
|
-
return
|
|
449
|
+
case "Morphism" :
|
|
450
|
+
return shape._1(fromUntagged(untagged, shape._0, self));
|
|
439
451
|
|
|
440
452
|
}
|
|
441
453
|
}
|
|
@@ -451,7 +463,7 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
451
463
|
if (Number.isNaN(r.getDate())) {
|
|
452
464
|
throw {
|
|
453
465
|
RE_EXN_ID: $$TypeError,
|
|
454
|
-
_1: "Invalid date " + s
|
|
466
|
+
_1: "Invalid date " + s,
|
|
455
467
|
Error: new Error()
|
|
456
468
|
};
|
|
457
469
|
}
|
|
@@ -461,7 +473,7 @@ function fromUntagged(untagged, _shape, self) {
|
|
|
461
473
|
if (Number.isNaN(r$1.getDate())) {
|
|
462
474
|
throw {
|
|
463
475
|
RE_EXN_ID: $$TypeError,
|
|
464
|
-
_1: "Invalid date " + f.toString()
|
|
476
|
+
_1: "Invalid date " + f.toString(),
|
|
465
477
|
Error: new Error()
|
|
466
478
|
};
|
|
467
479
|
}
|
|
@@ -476,74 +488,80 @@ function checkFieldsSanity(name, _fields, _optional) {
|
|
|
476
488
|
var optional = _optional;
|
|
477
489
|
var fields = _fields;
|
|
478
490
|
var exit = 0;
|
|
479
|
-
if (typeof fields
|
|
491
|
+
if (typeof fields !== "object") {
|
|
480
492
|
switch (fields) {
|
|
481
|
-
case
|
|
482
|
-
case
|
|
483
|
-
case
|
|
484
|
-
case
|
|
493
|
+
case "Any" :
|
|
494
|
+
case "Boolean" :
|
|
495
|
+
case "Date" :
|
|
496
|
+
case "Datetime" :
|
|
485
497
|
return {
|
|
486
|
-
TAG:
|
|
498
|
+
TAG: "Ok",
|
|
487
499
|
_0: undefined
|
|
488
500
|
};
|
|
489
|
-
case
|
|
501
|
+
case "Self" :
|
|
490
502
|
if (optional) {
|
|
491
503
|
return {
|
|
492
|
-
TAG:
|
|
504
|
+
TAG: "Ok",
|
|
493
505
|
_0: undefined
|
|
494
506
|
};
|
|
495
507
|
} else {
|
|
496
508
|
return {
|
|
497
|
-
TAG:
|
|
498
|
-
_0:
|
|
509
|
+
TAG: "Error",
|
|
510
|
+
_0: name + ": Trivial infinite recursion 'let fields = Self'"
|
|
499
511
|
};
|
|
500
512
|
}
|
|
501
513
|
default:
|
|
502
514
|
return {
|
|
503
|
-
TAG:
|
|
515
|
+
TAG: "Ok",
|
|
504
516
|
_0: undefined
|
|
505
517
|
};
|
|
506
518
|
}
|
|
507
519
|
} else {
|
|
508
|
-
switch (fields.TAG
|
|
509
|
-
case
|
|
520
|
+
switch (fields.TAG) {
|
|
521
|
+
case "Tuple" :
|
|
510
522
|
return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(Curry._2(Prelude.$$Array.mapWithIndex, fields._0, (function(optional){
|
|
511
|
-
return function (index, field
|
|
512
|
-
return
|
|
523
|
+
return function (index, field) {
|
|
524
|
+
return function () {
|
|
525
|
+
return checkFieldsSanity(name + "[" + String(index) + "]", field, optional);
|
|
526
|
+
};
|
|
513
527
|
}
|
|
514
528
|
}(optional)))), (function (param) {
|
|
515
529
|
|
|
516
530
|
}));
|
|
517
|
-
case
|
|
531
|
+
case "Object" :
|
|
518
532
|
return Curry._2(Prelude.ManyResults.map, Prelude.ManyResults.bailU(Curry._2(Prelude.$$Array.map, fields._0, (function(optional){
|
|
519
|
-
return function (param
|
|
520
|
-
|
|
533
|
+
return function (param) {
|
|
534
|
+
var field = param[1];
|
|
535
|
+
var fieldName = param[0];
|
|
536
|
+
return function () {
|
|
537
|
+
return checkFieldsSanity(name + "::" + fieldName, field, optional);
|
|
538
|
+
};
|
|
521
539
|
}
|
|
522
540
|
}(optional)))), (function (param) {
|
|
523
541
|
|
|
524
542
|
}));
|
|
525
|
-
case
|
|
526
|
-
case
|
|
543
|
+
case "Array" :
|
|
544
|
+
case "Mapping" :
|
|
527
545
|
_optional = true;
|
|
528
546
|
_fields = fields._0;
|
|
529
547
|
continue ;
|
|
530
|
-
case
|
|
531
|
-
case
|
|
548
|
+
case "Deserializer" :
|
|
549
|
+
case "Collection" :
|
|
532
550
|
exit = 2;
|
|
533
551
|
break;
|
|
534
|
-
case
|
|
535
|
-
case
|
|
536
|
-
case
|
|
552
|
+
case "Optional" :
|
|
553
|
+
case "OptionalWithDefault" :
|
|
554
|
+
case "DefaultWhenInvalid" :
|
|
537
555
|
exit = 1;
|
|
538
556
|
break;
|
|
539
|
-
case
|
|
557
|
+
case "Morphism" :
|
|
540
558
|
return {
|
|
541
|
-
TAG:
|
|
559
|
+
TAG: "Ok",
|
|
542
560
|
_0: undefined
|
|
543
561
|
};
|
|
544
562
|
default:
|
|
545
563
|
return {
|
|
546
|
-
TAG:
|
|
564
|
+
TAG: "Ok",
|
|
547
565
|
_0: undefined
|
|
548
566
|
};
|
|
549
567
|
}
|
|
@@ -554,16 +572,16 @@ function checkFieldsSanity(name, _fields, _optional) {
|
|
|
554
572
|
_fields = fields._0;
|
|
555
573
|
continue ;
|
|
556
574
|
case 2 :
|
|
557
|
-
var msg =
|
|
558
|
-
if (msg.TAG ===
|
|
575
|
+
var msg = fields._0.checkFieldsSanity(undefined);
|
|
576
|
+
if (msg.TAG === "Ok") {
|
|
559
577
|
return {
|
|
560
|
-
TAG:
|
|
578
|
+
TAG: "Ok",
|
|
561
579
|
_0: undefined
|
|
562
580
|
};
|
|
563
581
|
} else {
|
|
564
582
|
return {
|
|
565
|
-
TAG:
|
|
566
|
-
_0:
|
|
583
|
+
TAG: "Error",
|
|
584
|
+
_0: name + "/ " + msg._0
|
|
567
585
|
};
|
|
568
586
|
}
|
|
569
587
|
|
|
@@ -589,8 +607,8 @@ var Field = {
|
|
|
589
607
|
|
|
590
608
|
function MakeDeserializer(S) {
|
|
591
609
|
var fields = S.fields;
|
|
592
|
-
var name = "Deserializer " + "JSON" + ", " + "File \"JSON.res\", line
|
|
593
|
-
var checkFieldsSanity$1 = function (
|
|
610
|
+
var name = "Deserializer " + "JSON" + ", " + "File \"JSON.res\", line 319, characters 39-47";
|
|
611
|
+
var checkFieldsSanity$1 = function () {
|
|
594
612
|
return checkFieldsSanity(name, fields, false);
|
|
595
613
|
};
|
|
596
614
|
var fromJSON = function (json) {
|
|
@@ -602,14 +620,14 @@ function MakeDeserializer(S) {
|
|
|
602
620
|
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
|
|
603
621
|
if (e.RE_EXN_ID === $$TypeError) {
|
|
604
622
|
return {
|
|
605
|
-
TAG:
|
|
623
|
+
TAG: "Error",
|
|
606
624
|
_0: e._1
|
|
607
625
|
};
|
|
608
626
|
}
|
|
609
627
|
throw e;
|
|
610
628
|
}
|
|
611
629
|
return {
|
|
612
|
-
TAG:
|
|
630
|
+
TAG: "Ok",
|
|
613
631
|
_0: res
|
|
614
632
|
};
|
|
615
633
|
};
|