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