@fncts/schema 0.0.24 → 0.0.25
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/LICENSE +26 -0
- package/_cjs/AST.cjs +1093 -1226
- package/_cjs/AST.cjs.map +1 -1
- package/_cjs/ASTAnnotation.cjs +114 -85
- package/_cjs/ASTAnnotation.cjs.map +1 -1
- package/_cjs/ASTAnnotationMap.cjs +43 -41
- package/_cjs/ASTAnnotationMap.cjs.map +1 -1
- package/_cjs/Eq.cjs +113 -145
- package/_cjs/Eq.cjs.map +1 -1
- package/_cjs/Gen.cjs +131 -167
- package/_cjs/Gen.cjs.map +1 -1
- package/_cjs/Guard.cjs +167 -267
- package/_cjs/Guard.cjs.map +1 -1
- package/_cjs/InvalidInterpretationError.cjs +9 -10
- package/_cjs/InvalidInterpretationError.cjs.map +1 -1
- package/_cjs/ParseError/ParseError.cjs +283 -284
- package/_cjs/ParseError/ParseError.cjs.map +1 -1
- package/_cjs/ParseError/ParseErrorFormatter.cjs +0 -2
- package/_cjs/ParseError/PathFormatter.cjs +55 -87
- package/_cjs/ParseError/PathFormatter.cjs.map +1 -1
- package/_cjs/ParseError/TreeFormatter.cjs +70 -102
- package/_cjs/ParseError/TreeFormatter.cjs.map +1 -1
- package/_cjs/ParseError.cjs +35 -50
- package/_cjs/ParseResult.cjs +15 -15
- package/_cjs/ParseResult.cjs.map +1 -1
- package/_cjs/Parser/api.cjs +54 -50
- package/_cjs/Parser/api.cjs.map +1 -1
- package/_cjs/Parser/definition.cjs +17 -16
- package/_cjs/Parser/definition.cjs.map +1 -1
- package/_cjs/Parser/interpreter.cjs +276 -358
- package/_cjs/Parser/interpreter.cjs.map +1 -1
- package/_cjs/Parser.cjs +12 -39
- package/_cjs/Schema/api/conc.cjs +64 -59
- package/_cjs/Schema/api/conc.cjs.map +1 -1
- package/_cjs/Schema/api/either.cjs +73 -72
- package/_cjs/Schema/api/either.cjs.map +1 -1
- package/_cjs/Schema/api/hashMap.cjs +85 -85
- package/_cjs/Schema/api/hashMap.cjs.map +1 -1
- package/_cjs/Schema/api/hashSet.cjs +75 -69
- package/_cjs/Schema/api/hashSet.cjs.map +1 -1
- package/_cjs/Schema/api/list.cjs +74 -66
- package/_cjs/Schema/api/list.cjs.map +1 -1
- package/_cjs/Schema/api/map.cjs +81 -83
- package/_cjs/Schema/api/map.cjs.map +1 -1
- package/_cjs/Schema/api/maybe.cjs +56 -49
- package/_cjs/Schema/api/maybe.cjs.map +1 -1
- package/_cjs/Schema/api/set.cjs +68 -61
- package/_cjs/Schema/api/set.cjs.map +1 -1
- package/_cjs/Schema/api.cjs +332 -350
- package/_cjs/Schema/api.cjs.map +1 -1
- package/_cjs/Schema/definition.cjs +28 -26
- package/_cjs/Schema/definition.cjs.map +1 -1
- package/_cjs/Schema/derivations.cjs +85 -100
- package/_cjs/Schema/derivations.cjs.map +1 -1
- package/_cjs/Schema.cjs +95 -127
- package/_cjs/Show.cjs +91 -151
- package/_cjs/Show.cjs.map +1 -1
- package/_cjs/chunk.cjs +28 -0
- package/_cjs/global.cjs +0 -2
- package/_cjs/index.cjs +0 -2
- package/_cjs/utils.cjs +41 -46
- package/_cjs/utils.cjs.map +1 -1
- package/_mjs/AST.mjs +996 -1161
- package/_mjs/AST.mjs.map +1 -1
- package/_mjs/ASTAnnotation.mjs +77 -73
- package/_mjs/ASTAnnotation.mjs.map +1 -1
- package/_mjs/ASTAnnotationMap.mjs +31 -29
- package/_mjs/ASTAnnotationMap.mjs.map +1 -1
- package/_mjs/Eq.mjs +101 -134
- package/_mjs/Eq.mjs.map +1 -1
- package/_mjs/Gen.mjs +117 -157
- package/_mjs/Gen.mjs.map +1 -1
- package/_mjs/Guard.mjs +154 -257
- package/_mjs/Guard.mjs.map +1 -1
- package/_mjs/InvalidInterpretationError.mjs +8 -4
- package/_mjs/InvalidInterpretationError.mjs.map +1 -1
- package/_mjs/ParseError/ParseError.mjs +266 -262
- package/_mjs/ParseError/ParseError.mjs.map +1 -1
- package/_mjs/ParseError/ParseErrorFormatter.mjs +0 -2
- package/_mjs/ParseError/PathFormatter.mjs +51 -80
- package/_mjs/ParseError/PathFormatter.mjs.map +1 -1
- package/_mjs/ParseError/TreeFormatter.mjs +62 -94
- package/_mjs/ParseError/TreeFormatter.mjs.map +1 -1
- package/_mjs/ParseError.mjs +5 -6
- package/_mjs/ParseResult.mjs +13 -9
- package/_mjs/ParseResult.mjs.map +1 -1
- package/_mjs/Parser/api.mjs +43 -39
- package/_mjs/Parser/api.mjs.map +1 -1
- package/_mjs/Parser/definition.mjs +12 -8
- package/_mjs/Parser/definition.mjs.map +1 -1
- package/_mjs/Parser/interpreter.mjs +262 -348
- package/_mjs/Parser/interpreter.mjs.map +1 -1
- package/_mjs/Parser.mjs +4 -5
- package/_mjs/Schema/api/conc.mjs +41 -45
- package/_mjs/Schema/api/conc.mjs.map +1 -1
- package/_mjs/Schema/api/either.mjs +55 -61
- package/_mjs/Schema/api/either.mjs.map +1 -1
- package/_mjs/Schema/api/hashMap.mjs +61 -71
- package/_mjs/Schema/api/hashMap.mjs.map +1 -1
- package/_mjs/Schema/api/hashSet.mjs +53 -56
- package/_mjs/Schema/api/hashSet.mjs.map +1 -1
- package/_mjs/Schema/api/list.mjs +50 -53
- package/_mjs/Schema/api/list.mjs.map +1 -1
- package/_mjs/Schema/api/map.mjs +59 -69
- package/_mjs/Schema/api/map.mjs.map +1 -1
- package/_mjs/Schema/api/maybe.mjs +34 -36
- package/_mjs/Schema/api/maybe.mjs.map +1 -1
- package/_mjs/Schema/api/set.mjs +47 -48
- package/_mjs/Schema/api/set.mjs.map +1 -1
- package/_mjs/Schema/api.mjs +304 -346
- package/_mjs/Schema/api.mjs.map +1 -1
- package/_mjs/Schema/definition.mjs +21 -17
- package/_mjs/Schema/definition.mjs.map +1 -1
- package/_mjs/Schema/derivations.mjs +71 -90
- package/_mjs/Schema/derivations.mjs.map +1 -1
- package/_mjs/Schema.mjs +12 -15
- package/_mjs/Show.mjs +79 -139
- package/_mjs/Show.mjs.map +1 -1
- package/_mjs/global.mjs +0 -2
- package/_mjs/index.mjs +0 -2
- package/_mjs/utils.mjs +35 -37
- package/_mjs/utils.mjs.map +1 -1
- package/package.json +7 -3
- package/_cjs/ParseError/ParseErrorFormatter.cjs.map +0 -1
- package/_cjs/ParseError.cjs.map +0 -1
- package/_cjs/Parser.cjs.map +0 -1
- package/_cjs/Schema.cjs.map +0 -1
- package/_cjs/global.cjs.map +0 -1
- package/_cjs/index.cjs.map +0 -1
- package/_mjs/ParseError/ParseErrorFormatter.mjs.map +0 -1
- package/_mjs/ParseError.mjs.map +0 -1
- package/_mjs/Parser.mjs.map +0 -1
- package/_mjs/Schema.mjs.map +0 -1
- package/_mjs/global.mjs.map +0 -1
- package/_mjs/index.mjs.map +0 -1
|
@@ -1,358 +1,272 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { getKeysForIndexSignature, getTemplateLiteralRegex, memoize, ownKeys } from "../utils.mjs";
|
|
2
|
+
import { getSearchTree } from "../AST.mjs";
|
|
3
|
+
import { DeclarationError } from "../ParseError/ParseError.mjs";
|
|
4
4
|
import * as tsplus_module_4 from "@fncts/base/collection/immutable/Vector/api";
|
|
5
|
-
import * as tsplus_module_5 from "@fncts/base/data/Maybe/api";
|
|
6
5
|
import * as tsplus_module_6 from "@fncts/schema/AST";
|
|
7
|
-
import * as
|
|
8
|
-
import * as tsplus_module_8 from "@fncts/base/collection/immutable/Vector/internal";
|
|
9
|
-
import * as tsplus_module_9 from "@fncts/base/data/Maybe/definition";
|
|
6
|
+
import * as tsplus_module_5 from "@fncts/base/data/Maybe/api";
|
|
10
7
|
import { globalValue } from "@fncts/base/data/Global";
|
|
8
|
+
import * as tsplus_module_3 from "@fncts/schema/ParseResult";
|
|
9
|
+
import * as tsplus_module_9 from "@fncts/base/data/Maybe/definition";
|
|
11
10
|
import { isBigInt, isBoolean, isNumber, isObject, isRecord, isString, isSymbol, isUndefined } from "@fncts/base/util/predicates";
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
import * as tsplus_module_7 from "@fncts/schema/ParseError/ParseError";
|
|
12
|
+
import * as tsplus_module_8 from "@fncts/base/collection/immutable/Vector/internal";
|
|
13
|
+
import * as tsplus_module_1 from "@fncts/base/data/Either/api";
|
|
14
|
+
import * as tsplus_module_2 from "@fncts/schema/Parser/definition";
|
|
15
|
+
//#region build/esm/Parser/interpreter.js
|
|
16
|
+
const decodeMemoMap = globalValue(Symbol.for("fncts.schema.Parser.decodeMemoMap"), () => /* @__PURE__ */ new WeakMap());
|
|
17
|
+
const encodeMemoMap = globalValue(Symbol.for("fncts.schema.Parser.encodeMemoMap"), () => /* @__PURE__ */ new WeakMap());
|
|
17
18
|
function goMemo(ast, isDecoding) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
memoMap.set(ast, parser);
|
|
25
|
-
return parser;
|
|
19
|
+
const memoMap = isDecoding ? decodeMemoMap : encodeMemoMap;
|
|
20
|
+
const memo = memoMap.get(ast);
|
|
21
|
+
if (memo) return memo;
|
|
22
|
+
const parser = go(ast, isDecoding);
|
|
23
|
+
memoMap.set(ast, parser);
|
|
24
|
+
return parser;
|
|
26
25
|
}
|
|
27
26
|
function go(ast, isDecoding) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const map = new Map();
|
|
267
|
-
tsplus_module_4.forEach(ast => {
|
|
268
|
-
map.set(ast, goMemo(ast, isDecoding));
|
|
269
|
-
})(ast.types);
|
|
270
|
-
return tsplus_module_2.make((input, options) => {
|
|
271
|
-
const errors = tsplus_module_4.emptyPushable();
|
|
272
|
-
let candidates = [];
|
|
273
|
-
if (len > 0) {
|
|
274
|
-
if (isRecord(input)) {
|
|
275
|
-
for (let i = 0; i < len; i++) {
|
|
276
|
-
const name = ownKeys[i];
|
|
277
|
-
const buckets = searchTree.keys[name].buckets;
|
|
278
|
-
if (Object.prototype.hasOwnProperty.call(input, name)) {
|
|
279
|
-
const literal = String(input[name]);
|
|
280
|
-
if (Object.prototype.hasOwnProperty.call(buckets, literal)) {
|
|
281
|
-
candidates = candidates.concat(buckets[literal]);
|
|
282
|
-
} else {
|
|
283
|
-
const literals = tsplus_module_6.createUnion(tsplus_module_4.from(searchTree.keys[name].literals));
|
|
284
|
-
tsplus_module_8.push(tsplus_module_7.typeLiteralError(tsplus_module_6.createTypeLiteral(tsplus_module_4.vector(tsplus_module_6.createPropertySignature(name, literals, false, true)), tsplus_module_4.vector()), input, tsplus_module_4.vector(tsplus_module_7.keyError(tsplus_module_6.createKey(name), name, tsplus_module_7.typeError(searchTree.keys[name].ast, input[name])))))(errors);
|
|
285
|
-
}
|
|
286
|
-
} else {
|
|
287
|
-
const literals = tsplus_module_6.createUnion(tsplus_module_4.from(searchTree.keys[name].literals));
|
|
288
|
-
tsplus_module_8.push(tsplus_module_7.typeLiteralError(tsplus_module_6.createTypeLiteral(tsplus_module_4.vector(tsplus_module_6.createPropertySignature(name, literals, false, true)), tsplus_module_4.vector()), input, tsplus_module_4.vector(tsplus_module_7.keyError(tsplus_module_6.createKey(name), name, tsplus_module_7.missingError))))(errors);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
} else {
|
|
292
|
-
tsplus_module_8.push(tsplus_module_7.typeError(tsplus_module_6.unknownRecord, input))(errors);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (searchTree.otherwise.length > 0) {
|
|
296
|
-
candidates = candidates.concat(searchTree.otherwise);
|
|
297
|
-
}
|
|
298
|
-
for (let i = 0; i < candidates.length; i++) {
|
|
299
|
-
const candidate = candidates[i];
|
|
300
|
-
const pr = map.get(candidate)(input, options);
|
|
301
|
-
void 0;
|
|
302
|
-
if (tsplus_module_1.isRight(pr)) {
|
|
303
|
-
return pr;
|
|
304
|
-
} else {
|
|
305
|
-
tsplus_module_8.push(tsplus_module_7.unionMemberError(candidate, pr.left))(errors);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return tsplus_module_4.isNonEmpty(errors) ? errors.length === 1 && tsplus_module_4.unsafeGet(0)(errors)._tag === 1 /* ParseErrorTag.Type */ ? tsplus_module_3.fail(tsplus_module_4.unsafeGet(0)(errors)) : tsplus_module_3.fail(tsplus_module_7.unionError(ast, input, tsplus_module_4.from(errors))) : tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.neverKeyword, input));
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
case 19 /* ASTTag.Lazy */:
|
|
312
|
-
{
|
|
313
|
-
const f = () => goMemo(ast.getAST(), isDecoding);
|
|
314
|
-
const get = memoize(f);
|
|
315
|
-
return tsplus_module_2.make((a, options) => get()(a, options));
|
|
316
|
-
}
|
|
317
|
-
case 20 /* ASTTag.Refinement */:
|
|
318
|
-
{
|
|
319
|
-
if (isDecoding) {
|
|
320
|
-
const from = goMemo(ast.from, isDecoding);
|
|
321
|
-
return tsplus_module_2.make((input, options) => tsplus_module_1.flatMap(a => tsplus_module_1.mapLeft(failure => tsplus_module_7.refinementError(ast, input, "Predicate", failure))(ast.decode(a, options)))(tsplus_module_1.mapLeft(failure => tsplus_module_7.refinementError(ast, input, "From", failure))(from(input, options))));
|
|
322
|
-
} else {
|
|
323
|
-
const from = goMemo(ast.from, true);
|
|
324
|
-
const to = goMemo(tsplus_module_6.getTo(ast.from), false);
|
|
325
|
-
return tsplus_module_2.make((input, options) => tsplus_module_1.flatMap(a => from(a, options))(tsplus_module_1.flatMap(a => ast.decode(a, options))(to(input, options))));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
case 21 /* ASTTag.Transform */:
|
|
329
|
-
{
|
|
330
|
-
const transformation = isDecoding ? ast.decode : ast.encode;
|
|
331
|
-
const from = isDecoding ? goMemo(ast.from, true) : goMemo(ast.to, false);
|
|
332
|
-
const to = isDecoding ? goMemo(ast.to, true) : goMemo(ast.from, false);
|
|
333
|
-
return tsplus_module_2.make((input, options) => tsplus_module_1.flatMap(a => tsplus_module_1.mapLeft(failure => tsplus_module_7.transformationError(ast, input, isDecoding ? "Type" : "Encoded", failure))(to(a, options)))(tsplus_module_1.flatMap(a => tsplus_module_1.mapLeft(failure => tsplus_module_7.transformationError(ast, input, "Transformation", failure))(transformation(a, options)))(tsplus_module_1.mapLeft(failure => tsplus_module_7.transformationError(ast, input, isDecoding ? "Encoded" : "Type", failure))(from(input, options)))));
|
|
334
|
-
}
|
|
335
|
-
case 22 /* ASTTag.Validation */:
|
|
336
|
-
{
|
|
337
|
-
return tsplus_module_2.make((u, options) => {
|
|
338
|
-
const missedBrands = tsplus_module_4.emptyPushable();
|
|
339
|
-
const allErrors = options?.allErrors;
|
|
340
|
-
for (const validation of ast.validation) {
|
|
341
|
-
if (!validation.validate(u)) {
|
|
342
|
-
tsplus_module_8.push(validation)(missedBrands);
|
|
343
|
-
if (allErrors) {
|
|
344
|
-
continue;
|
|
345
|
-
} else {
|
|
346
|
-
return tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.createValidation(ast.from, missedBrands, ast.annotations), u));
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
return missedBrands.length > 0 ? tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.createValidation(ast.from, missedBrands, ast.annotations), u)) : tsplus_module_3.succeed(u);
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
}
|
|
27
|
+
switch (ast._tag) {
|
|
28
|
+
case 0: {
|
|
29
|
+
const parse = isDecoding ? ast.decode(...ast.typeParameters) : ast.encode(...ast.typeParameters);
|
|
30
|
+
return tsplus_module_2.make((input, options) => tsplus_module_1.mapLeft((error) => new DeclarationError(ast, input, error))(parse(input, options)));
|
|
31
|
+
}
|
|
32
|
+
case 1: return tsplus_module_2.fromRefinement(ast, (u) => u === ast.literal);
|
|
33
|
+
case 2: return tsplus_module_2.fromRefinement(ast, (u) => u === ast.symbol);
|
|
34
|
+
case 3:
|
|
35
|
+
case 4: return tsplus_module_2.fromRefinement(ast, isUndefined);
|
|
36
|
+
case 5: return tsplus_module_2.fromRefinement(ast, (_) => false);
|
|
37
|
+
case 6:
|
|
38
|
+
case 7: return tsplus_module_2.make(tsplus_module_3.succeed);
|
|
39
|
+
case 8: return tsplus_module_2.fromRefinement(ast, isString);
|
|
40
|
+
case 9: return tsplus_module_2.fromRefinement(ast, isNumber);
|
|
41
|
+
case 10: return tsplus_module_2.fromRefinement(ast, isBoolean);
|
|
42
|
+
case 11: return tsplus_module_2.fromRefinement(ast, isBigInt);
|
|
43
|
+
case 12: return tsplus_module_2.fromRefinement(ast, isSymbol);
|
|
44
|
+
case 13: return tsplus_module_2.fromRefinement(ast, isObject);
|
|
45
|
+
case 14: return tsplus_module_2.fromRefinement(ast, (u) => tsplus_module_4.some(([_, value]) => value === u)(ast.enums));
|
|
46
|
+
case 15: {
|
|
47
|
+
const regex = getTemplateLiteralRegex(ast);
|
|
48
|
+
return tsplus_module_2.fromRefinement(ast, (u) => isString(u) && regex.test(u));
|
|
49
|
+
}
|
|
50
|
+
case 16: {
|
|
51
|
+
const elements = tsplus_module_4.map((e) => goMemo(e.type, isDecoding))(ast.elements);
|
|
52
|
+
const rest = tsplus_module_5.map((rest) => tsplus_module_4.map((ast) => goMemo(ast, isDecoding))(rest))(ast.rest);
|
|
53
|
+
return tsplus_module_2.make((input, options) => {
|
|
54
|
+
if (!Array.isArray(input)) return tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.unknownArray, input));
|
|
55
|
+
const output = [];
|
|
56
|
+
const errors = tsplus_module_4.emptyPushable();
|
|
57
|
+
const allErrors = options?.allErrors;
|
|
58
|
+
let i = 0;
|
|
59
|
+
for (; i < elements.length; i++) if (input.length < i + 1) {
|
|
60
|
+
if (!tsplus_module_4.unsafeGet(i)(ast.elements).isOptional) {
|
|
61
|
+
const e = tsplus_module_7.indexError(i, tsplus_module_7.missingError);
|
|
62
|
+
if (allErrors) {
|
|
63
|
+
tsplus_module_8.push(e)(errors);
|
|
64
|
+
continue;
|
|
65
|
+
} else return tsplus_module_3.fail(tsplus_module_7.tupleError(ast, input, tsplus_module_4.vector(e), output));
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
const t = tsplus_module_4.unsafeGet(i)(elements)(input[i], options);
|
|
69
|
+
if (tsplus_module_1.isLeft(t)) {
|
|
70
|
+
const e = tsplus_module_7.indexError(i, t.left);
|
|
71
|
+
if (allErrors) {
|
|
72
|
+
tsplus_module_8.push(e)(errors);
|
|
73
|
+
continue;
|
|
74
|
+
} else return tsplus_module_3.fail(tsplus_module_7.tupleError(ast, input, tsplus_module_4.vector(e), output));
|
|
75
|
+
}
|
|
76
|
+
output.push(t.right);
|
|
77
|
+
}
|
|
78
|
+
if (tsplus_module_9.isJust(rest)) {
|
|
79
|
+
const head = tsplus_module_4.unsafeHead(rest.value);
|
|
80
|
+
const tail = tsplus_module_4.tail(rest.value);
|
|
81
|
+
for (; i < input.length - tail.length; i++) {
|
|
82
|
+
const t = head(input[i], options);
|
|
83
|
+
if (tsplus_module_1.isLeft(t)) {
|
|
84
|
+
const e = tsplus_module_7.indexError(i, t.left);
|
|
85
|
+
if (allErrors) {
|
|
86
|
+
tsplus_module_8.push(e)(errors);
|
|
87
|
+
continue;
|
|
88
|
+
} else return tsplus_module_3.fail(tsplus_module_7.tupleError(ast, input, tsplus_module_4.vector(e), output));
|
|
89
|
+
}
|
|
90
|
+
output.push(t.right);
|
|
91
|
+
}
|
|
92
|
+
for (let j = 0; j < tail.length; j++) {
|
|
93
|
+
i += j;
|
|
94
|
+
if (input.length < i + 1) {
|
|
95
|
+
const e = tsplus_module_7.indexError(i, tsplus_module_7.missingError);
|
|
96
|
+
if (allErrors) {
|
|
97
|
+
tsplus_module_8.push(e)(errors);
|
|
98
|
+
continue;
|
|
99
|
+
} else return tsplus_module_3.fail(tsplus_module_7.tupleError(ast, input, tsplus_module_4.vector(e), output));
|
|
100
|
+
} else {
|
|
101
|
+
const t = tsplus_module_4.unsafeGet(j)(tail)(input[i], options);
|
|
102
|
+
if (tsplus_module_1.isLeft(t)) {
|
|
103
|
+
const e = tsplus_module_7.indexError(i, t.left);
|
|
104
|
+
if (allErrors) {
|
|
105
|
+
tsplus_module_8.push(e)(errors);
|
|
106
|
+
continue;
|
|
107
|
+
} else return tsplus_module_3.fail(tsplus_module_7.tupleError(ast, input, tsplus_module_4.vector(e), output));
|
|
108
|
+
}
|
|
109
|
+
output.push(t.right);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
const isUnexpectedAllowed = options?.isUnexpectedAllowed;
|
|
114
|
+
for (; i < input.length; i++) {
|
|
115
|
+
const e = tsplus_module_7.indexError(i, tsplus_module_7.unexpectedError(input[i]));
|
|
116
|
+
if (!isUnexpectedAllowed) if (allErrors) {
|
|
117
|
+
tsplus_module_8.push(e)(errors);
|
|
118
|
+
continue;
|
|
119
|
+
} else return tsplus_module_3.fail(tsplus_module_7.tupleError(ast, input, tsplus_module_4.vector(e), output));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return tsplus_module_4.isNonEmpty(errors) ? tsplus_module_3.fail(tsplus_module_7.tupleError(ast, input, errors, output)) : tsplus_module_3.succeed(output);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
case 17: {
|
|
126
|
+
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) return tsplus_module_2.fromRefinement(ast, (u) => u !== null);
|
|
127
|
+
const propertySignatureTypes = tsplus_module_4.map((f) => goMemo(f.type, isDecoding))(ast.propertySignatures);
|
|
128
|
+
const indexSignatures = tsplus_module_4.map((is) => [goMemo(is.parameter, isDecoding), goMemo(is.type, isDecoding)])(ast.indexSignatures);
|
|
129
|
+
return tsplus_module_2.make((input, options) => {
|
|
130
|
+
if (!isRecord(input)) return tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.unknownRecord, input));
|
|
131
|
+
const output = {};
|
|
132
|
+
const expectedKeys = {};
|
|
133
|
+
const errors = tsplus_module_4.emptyPushable();
|
|
134
|
+
const allErrors = options?.allErrors;
|
|
135
|
+
for (let i = 0; i < propertySignatureTypes.length; i++) {
|
|
136
|
+
const ps = tsplus_module_4.unsafeGet(i)(ast.propertySignatures);
|
|
137
|
+
const parser = tsplus_module_4.unsafeGet(i)(propertySignatureTypes);
|
|
138
|
+
const name = ps.name;
|
|
139
|
+
expectedKeys[name] = null;
|
|
140
|
+
if (!Object.prototype.hasOwnProperty.call(input, name)) {
|
|
141
|
+
if (!ps.isOptional) {
|
|
142
|
+
const e = tsplus_module_7.keyError(tsplus_module_6.createKey(name), name, tsplus_module_7.missingError);
|
|
143
|
+
if (allErrors) {
|
|
144
|
+
tsplus_module_8.push(e)(errors);
|
|
145
|
+
continue;
|
|
146
|
+
} else return tsplus_module_3.fail(tsplus_module_7.typeLiteralError(ast, input, tsplus_module_4.vector(e), output));
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
const t = parser(input[name], options);
|
|
150
|
+
if (tsplus_module_1.isLeft(t)) {
|
|
151
|
+
const e = tsplus_module_7.keyError(tsplus_module_6.createKey(name), name, t.left);
|
|
152
|
+
if (allErrors) {
|
|
153
|
+
tsplus_module_8.push(e)(errors);
|
|
154
|
+
continue;
|
|
155
|
+
} else return tsplus_module_3.fail(tsplus_module_7.typeLiteralError(ast, input, tsplus_module_4.vector(e), output));
|
|
156
|
+
}
|
|
157
|
+
output[name] = t.right;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (indexSignatures.length > 0) for (let i = 0; i < indexSignatures.length; i++) {
|
|
161
|
+
const [parameter, type] = tsplus_module_4.unsafeGet(i)(indexSignatures);
|
|
162
|
+
const keys = getKeysForIndexSignature(input, tsplus_module_4.unsafeGet(i)(ast.indexSignatures).parameter);
|
|
163
|
+
for (const key of keys) {
|
|
164
|
+
if (Object.prototype.hasOwnProperty.call(expectedKeys, key)) continue;
|
|
165
|
+
let t = parameter(key, options);
|
|
166
|
+
if (tsplus_module_1.isLeft(t)) {
|
|
167
|
+
const e = tsplus_module_7.keyError(tsplus_module_6.createKey(key), key, t.left);
|
|
168
|
+
if (allErrors) {
|
|
169
|
+
tsplus_module_8.push(e)(errors);
|
|
170
|
+
continue;
|
|
171
|
+
} else return tsplus_module_3.fail(tsplus_module_7.typeLiteralError(ast, input, tsplus_module_4.vector(e), output));
|
|
172
|
+
}
|
|
173
|
+
t = type(input[key], options);
|
|
174
|
+
if (tsplus_module_1.isLeft(t)) {
|
|
175
|
+
const e = tsplus_module_7.keyError(tsplus_module_6.createKey(key), key, t.left);
|
|
176
|
+
tsplus_module_8.push(e)(errors);
|
|
177
|
+
if (allErrors) continue;
|
|
178
|
+
else return tsplus_module_3.fail(tsplus_module_7.typeLiteralError(ast, input, tsplus_module_4.vector(e), output));
|
|
179
|
+
}
|
|
180
|
+
output[key] = t.right;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const isUnexpectedAllowed = options?.isUnexpectedAllowed;
|
|
185
|
+
for (const key of ownKeys(input)) if (!Object.prototype.hasOwnProperty.call(expectedKeys, key)) {
|
|
186
|
+
if (!isUnexpectedAllowed) {
|
|
187
|
+
const e = tsplus_module_7.keyError(tsplus_module_6.createKey(key), key, tsplus_module_7.unexpectedError(input[key]));
|
|
188
|
+
if (allErrors) {
|
|
189
|
+
tsplus_module_8.push(e)(errors);
|
|
190
|
+
continue;
|
|
191
|
+
} else return tsplus_module_3.fail(tsplus_module_7.typeLiteralError(ast, input, tsplus_module_4.vector(e), output));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return tsplus_module_4.isNonEmpty(errors) ? tsplus_module_3.fail(tsplus_module_7.typeLiteralError(ast, input, errors, output)) : tsplus_module_3.succeed(output);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
case 18: {
|
|
199
|
+
const searchTree = getSearchTree(ast.types, isDecoding);
|
|
200
|
+
const ownKeys = Reflect.ownKeys(searchTree.keys);
|
|
201
|
+
const len = ownKeys.length;
|
|
202
|
+
const map = /* @__PURE__ */ new Map();
|
|
203
|
+
tsplus_module_4.forEach((ast) => {
|
|
204
|
+
map.set(ast, goMemo(ast, isDecoding));
|
|
205
|
+
})(ast.types);
|
|
206
|
+
return tsplus_module_2.make((input, options) => {
|
|
207
|
+
const errors = tsplus_module_4.emptyPushable();
|
|
208
|
+
let candidates = [];
|
|
209
|
+
if (len > 0) if (isRecord(input)) for (let i = 0; i < len; i++) {
|
|
210
|
+
const name = ownKeys[i];
|
|
211
|
+
const buckets = searchTree.keys[name].buckets;
|
|
212
|
+
if (Object.prototype.hasOwnProperty.call(input, name)) {
|
|
213
|
+
const literal = String(input[name]);
|
|
214
|
+
if (Object.prototype.hasOwnProperty.call(buckets, literal)) candidates = candidates.concat(buckets[literal]);
|
|
215
|
+
else {
|
|
216
|
+
const literals = tsplus_module_6.createUnion(tsplus_module_4.from(searchTree.keys[name].literals));
|
|
217
|
+
tsplus_module_8.push(tsplus_module_7.typeLiteralError(tsplus_module_6.createTypeLiteral(tsplus_module_4.vector(tsplus_module_6.createPropertySignature(name, literals, false, true)), tsplus_module_4.vector()), input, tsplus_module_4.vector(tsplus_module_7.keyError(tsplus_module_6.createKey(name), name, tsplus_module_7.typeError(searchTree.keys[name].ast, input[name])))))(errors);
|
|
218
|
+
}
|
|
219
|
+
} else {
|
|
220
|
+
const literals = tsplus_module_6.createUnion(tsplus_module_4.from(searchTree.keys[name].literals));
|
|
221
|
+
tsplus_module_8.push(tsplus_module_7.typeLiteralError(tsplus_module_6.createTypeLiteral(tsplus_module_4.vector(tsplus_module_6.createPropertySignature(name, literals, false, true)), tsplus_module_4.vector()), input, tsplus_module_4.vector(tsplus_module_7.keyError(tsplus_module_6.createKey(name), name, tsplus_module_7.missingError))))(errors);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else tsplus_module_8.push(tsplus_module_7.typeError(tsplus_module_6.unknownRecord, input))(errors);
|
|
225
|
+
if (searchTree.otherwise.length > 0) candidates = candidates.concat(searchTree.otherwise);
|
|
226
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
227
|
+
const candidate = candidates[i];
|
|
228
|
+
const pr = map.get(candidate)(input, options);
|
|
229
|
+
if (tsplus_module_1.isRight(pr)) return pr;
|
|
230
|
+
else tsplus_module_8.push(tsplus_module_7.unionMemberError(candidate, pr.left))(errors);
|
|
231
|
+
}
|
|
232
|
+
return tsplus_module_4.isNonEmpty(errors) ? errors.length === 1 && tsplus_module_4.unsafeGet(0)(errors)._tag === 1 ? tsplus_module_3.fail(tsplus_module_4.unsafeGet(0)(errors)) : tsplus_module_3.fail(tsplus_module_7.unionError(ast, input, tsplus_module_4.from(errors))) : tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.neverKeyword, input));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
case 19: {
|
|
236
|
+
const f = () => goMemo(ast.getAST(), isDecoding);
|
|
237
|
+
const get = memoize(f);
|
|
238
|
+
return tsplus_module_2.make((a, options) => get()(a, options));
|
|
239
|
+
}
|
|
240
|
+
case 20: if (isDecoding) {
|
|
241
|
+
const from = goMemo(ast.from, isDecoding);
|
|
242
|
+
return tsplus_module_2.make((input, options) => tsplus_module_1.flatMap((a) => tsplus_module_1.mapLeft((failure) => tsplus_module_7.refinementError(ast, input, "Predicate", failure))(ast.decode(a, options)))(tsplus_module_1.mapLeft((failure) => tsplus_module_7.refinementError(ast, input, "From", failure))(from(input, options))));
|
|
243
|
+
} else {
|
|
244
|
+
const from = goMemo(ast.from, true);
|
|
245
|
+
const to = goMemo(tsplus_module_6.getTo(ast.from), false);
|
|
246
|
+
return tsplus_module_2.make((input, options) => tsplus_module_1.flatMap((a) => from(a, options))(tsplus_module_1.flatMap((a) => ast.decode(a, options))(to(input, options))));
|
|
247
|
+
}
|
|
248
|
+
case 21: {
|
|
249
|
+
const transformation = isDecoding ? ast.decode : ast.encode;
|
|
250
|
+
const from = isDecoding ? goMemo(ast.from, true) : goMemo(ast.to, false);
|
|
251
|
+
const to = isDecoding ? goMemo(ast.to, true) : goMemo(ast.from, false);
|
|
252
|
+
return tsplus_module_2.make((input, options) => tsplus_module_1.flatMap((a) => tsplus_module_1.mapLeft((failure) => tsplus_module_7.transformationError(ast, input, isDecoding ? "Type" : "Encoded", failure))(to(a, options)))(tsplus_module_1.flatMap((a) => tsplus_module_1.mapLeft((failure) => tsplus_module_7.transformationError(ast, input, "Transformation", failure))(transformation(a, options)))(tsplus_module_1.mapLeft((failure) => tsplus_module_7.transformationError(ast, input, isDecoding ? "Encoded" : "Type", failure))(from(input, options)))));
|
|
253
|
+
}
|
|
254
|
+
case 22: return tsplus_module_2.make((u, options) => {
|
|
255
|
+
const missedBrands = tsplus_module_4.emptyPushable();
|
|
256
|
+
const allErrors = options?.allErrors;
|
|
257
|
+
for (const validation of ast.validation) if (!validation.validate(u)) {
|
|
258
|
+
tsplus_module_8.push(validation)(missedBrands);
|
|
259
|
+
if (allErrors) continue;
|
|
260
|
+
else return tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.createValidation(ast.from, missedBrands, ast.annotations), u));
|
|
261
|
+
}
|
|
262
|
+
return missedBrands.length > 0 ? tsplus_module_3.fail(tsplus_module_7.typeError(tsplus_module_6.createValidation(ast.from, missedBrands, ast.annotations), u)) : tsplus_module_3.succeed(u);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
354
265
|
}
|
|
355
|
-
|
|
356
|
-
|
|
266
|
+
function parserFor(ast, isDecoding) {
|
|
267
|
+
return goMemo(ast, isDecoding);
|
|
357
268
|
}
|
|
269
|
+
//#endregion
|
|
270
|
+
export { parserFor };
|
|
271
|
+
|
|
358
272
|
//# sourceMappingURL=interpreter.mjs.map
|