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