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