@fncts/schema 0.0.22 → 0.0.24
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/AST.d.ts +60 -29
- package/ASTAnnotationMap.d.ts +4 -1
- package/ParseError/ParseError.d.ts +28 -13
- package/_cjs/AST.cjs +279 -137
- package/_cjs/AST.cjs.map +1 -1
- package/_cjs/ASTAnnotation.cjs +5 -3
- package/_cjs/ASTAnnotation.cjs.map +1 -1
- package/_cjs/ASTAnnotationMap.cjs +18 -9
- package/_cjs/ASTAnnotationMap.cjs.map +1 -1
- package/_cjs/InvalidInterpretationError.cjs +1 -6
- package/_cjs/InvalidInterpretationError.cjs.map +1 -1
- package/_cjs/ParseError/ParseError.cjs +91 -14
- package/_cjs/ParseError/ParseError.cjs.map +1 -1
- package/_cjs/Schema/api/hashMap.cjs +1 -1
- package/_cjs/Schema/api/hashMap.cjs.map +1 -1
- package/_cjs/Schema/api/hashSet.cjs +1 -1
- package/_cjs/Schema/api/hashSet.cjs.map +1 -1
- package/_cjs/Schema/api/list.cjs +3 -1
- package/_cjs/Schema/api/list.cjs.map +1 -1
- package/_cjs/Schema/api/map.cjs +1 -1
- package/_cjs/Schema/api/map.cjs.map +1 -1
- package/_cjs/Schema/api/set.cjs +1 -1
- package/_cjs/Schema/api/set.cjs.map +1 -1
- package/_cjs/Schema/definition.cjs +3 -4
- package/_cjs/Schema/definition.cjs.map +1 -1
- package/_mjs/AST.mjs +277 -136
- package/_mjs/AST.mjs.map +1 -1
- package/_mjs/ASTAnnotation.mjs +5 -3
- package/_mjs/ASTAnnotation.mjs.map +1 -1
- package/_mjs/ASTAnnotationMap.mjs +18 -9
- package/_mjs/ASTAnnotationMap.mjs.map +1 -1
- package/_mjs/InvalidInterpretationError.mjs +1 -6
- package/_mjs/InvalidInterpretationError.mjs.map +1 -1
- package/_mjs/ParseError/ParseError.mjs +90 -14
- package/_mjs/ParseError/ParseError.mjs.map +1 -1
- package/_mjs/Schema/api/hashMap.mjs +1 -1
- package/_mjs/Schema/api/hashMap.mjs.map +1 -1
- package/_mjs/Schema/api/hashSet.mjs +1 -1
- package/_mjs/Schema/api/hashSet.mjs.map +1 -1
- package/_mjs/Schema/api/list.mjs +3 -1
- package/_mjs/Schema/api/list.mjs.map +1 -1
- package/_mjs/Schema/api/map.mjs +1 -1
- package/_mjs/Schema/api/map.mjs.map +1 -1
- package/_mjs/Schema/api/set.mjs +1 -1
- package/_mjs/Schema/api/set.mjs.map +1 -1
- package/_mjs/Schema/definition.mjs +2 -3
- package/_mjs/Schema/definition.mjs.map +1 -1
- package/_src/AST.ts +226 -28
- package/_src/ASTAnnotationMap.ts +14 -1
- package/_src/ParseError/ParseError.ts +128 -13
- package/_src/Schema/api/hashMap.ts +1 -1
- package/_src/Schema/api/hashSet.ts +1 -1
- package/_src/Schema/api/list.ts +3 -1
- package/_src/Schema/api/map.ts +1 -1
- package/_src/Schema/api/set.ts +1 -1
- package/package.json +3 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EqualsContext } from "@fncts/base/data/Equatable";
|
|
1
2
|
import type { Declaration, Refinement, Transform, Tuple, TypeLiteral, Union } from "@fncts/schema/AST";
|
|
2
3
|
|
|
3
4
|
export const enum ParseErrorTag {
|
|
@@ -30,16 +31,31 @@ export type ParseError =
|
|
|
30
31
|
| UnionError
|
|
31
32
|
| IterableError;
|
|
32
33
|
|
|
34
|
+
type ParseErrorNode = ParseError | IndexError | KeyError | MissingError | UnexpectedError | UnionMemberError;
|
|
35
|
+
|
|
36
|
+
function hasTag<K extends ParseErrorNode["_tag"]>(u: unknown, tag: K): u is Extract<ParseErrorNode, { _tag: K }> {
|
|
37
|
+
return typeof u === "object" && u !== null && "_tag" in u && (u as ParseErrorNode)._tag === tag;
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
/**
|
|
34
41
|
* @tsplus companion fncts.schema.ParseError.DeclarationError
|
|
35
42
|
*/
|
|
36
|
-
export class DeclarationError {
|
|
43
|
+
export class DeclarationError implements Equatable {
|
|
37
44
|
readonly _tag = ParseErrorTag.Declaration;
|
|
38
45
|
constructor(
|
|
39
46
|
readonly ast: Declaration,
|
|
40
47
|
readonly actual: unknown,
|
|
41
48
|
readonly error: ParseError,
|
|
42
49
|
) {}
|
|
50
|
+
|
|
51
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
52
|
+
return (
|
|
53
|
+
hasTag(that, ParseErrorTag.Declaration) &&
|
|
54
|
+
context.comparator(this.ast, that.ast) &&
|
|
55
|
+
context.comparator(this.actual, that.actual) &&
|
|
56
|
+
context.comparator(this.error, that.error)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
43
59
|
}
|
|
44
60
|
|
|
45
61
|
/**
|
|
@@ -53,12 +69,20 @@ export function declarationError(ast: Declaration, actual: unknown, error: Parse
|
|
|
53
69
|
/**
|
|
54
70
|
* @tsplus companion fncts.schema.ParseError.TypeError
|
|
55
71
|
*/
|
|
56
|
-
export class TypeError {
|
|
72
|
+
export class TypeError implements Equatable {
|
|
57
73
|
readonly _tag = ParseErrorTag.Type;
|
|
58
74
|
constructor(
|
|
59
75
|
readonly ast: AST,
|
|
60
76
|
readonly actual: unknown,
|
|
61
77
|
) {}
|
|
78
|
+
|
|
79
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
80
|
+
return (
|
|
81
|
+
hasTag(that, ParseErrorTag.Type) &&
|
|
82
|
+
context.comparator(this.ast, that.ast) &&
|
|
83
|
+
context.comparator(this.actual, that.actual)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
62
86
|
}
|
|
63
87
|
|
|
64
88
|
/**
|
|
@@ -72,7 +96,7 @@ export function typeError(expected: AST, actual: unknown): TypeError {
|
|
|
72
96
|
/**
|
|
73
97
|
* @tsplus companion fncts.schema.ParseError.TypeLiteralError
|
|
74
98
|
*/
|
|
75
|
-
export class TypeLiteralError {
|
|
99
|
+
export class TypeLiteralError implements Equatable {
|
|
76
100
|
readonly _tag = ParseErrorTag.TypeLiteral;
|
|
77
101
|
constructor(
|
|
78
102
|
readonly ast: TypeLiteral,
|
|
@@ -80,6 +104,16 @@ export class TypeLiteralError {
|
|
|
80
104
|
readonly errors: Vector<KeyError>,
|
|
81
105
|
readonly output: { readonly [x: string]: unknown } = {},
|
|
82
106
|
) {}
|
|
107
|
+
|
|
108
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
109
|
+
return (
|
|
110
|
+
hasTag(that, ParseErrorTag.TypeLiteral) &&
|
|
111
|
+
context.comparator(this.ast, that.ast) &&
|
|
112
|
+
context.comparator(this.actual, that.actual) &&
|
|
113
|
+
context.comparator(this.errors, that.errors) &&
|
|
114
|
+
context.comparator(this.output, that.output)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
83
117
|
}
|
|
84
118
|
|
|
85
119
|
/**
|
|
@@ -98,7 +132,7 @@ export function typeLiteralError(
|
|
|
98
132
|
/**
|
|
99
133
|
* @tsplus companion fncts.schema.ParseError.TupleError
|
|
100
134
|
*/
|
|
101
|
-
export class TupleError {
|
|
135
|
+
export class TupleError implements Equatable {
|
|
102
136
|
readonly _tag = ParseErrorTag.Tuple;
|
|
103
137
|
constructor(
|
|
104
138
|
readonly ast: Tuple,
|
|
@@ -106,6 +140,16 @@ export class TupleError {
|
|
|
106
140
|
readonly errors: Vector<IndexError>,
|
|
107
141
|
readonly output: ReadonlyArray<unknown> = [],
|
|
108
142
|
) {}
|
|
143
|
+
|
|
144
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
145
|
+
return (
|
|
146
|
+
hasTag(that, ParseErrorTag.Tuple) &&
|
|
147
|
+
context.comparator(this.ast, that.ast) &&
|
|
148
|
+
context.comparator(this.actual, that.actual) &&
|
|
149
|
+
context.comparator(this.errors, that.errors) &&
|
|
150
|
+
context.comparator(this.output, that.output)
|
|
151
|
+
);
|
|
152
|
+
}
|
|
109
153
|
}
|
|
110
154
|
|
|
111
155
|
/**
|
|
@@ -124,12 +168,20 @@ export function tupleError(
|
|
|
124
168
|
/**
|
|
125
169
|
* @tsplus companion fncts.schema.ParseError.IndexError
|
|
126
170
|
*/
|
|
127
|
-
export class IndexError {
|
|
171
|
+
export class IndexError implements Equatable {
|
|
128
172
|
readonly _tag = ParseErrorTag.Index;
|
|
129
173
|
constructor(
|
|
130
174
|
readonly index: number,
|
|
131
175
|
readonly error: ParseError | MissingError | UnexpectedError,
|
|
132
176
|
) {}
|
|
177
|
+
|
|
178
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
179
|
+
return (
|
|
180
|
+
hasTag(that, ParseErrorTag.Index) &&
|
|
181
|
+
context.comparator(this.index, that.index) &&
|
|
182
|
+
context.comparator(this.error, that.error)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
133
185
|
}
|
|
134
186
|
|
|
135
187
|
/**
|
|
@@ -143,13 +195,22 @@ export function indexError(index: number, error: ParseError | MissingError | Une
|
|
|
143
195
|
/**
|
|
144
196
|
* @tsplus companion fncts.schema.ParseError.KeyError
|
|
145
197
|
*/
|
|
146
|
-
export class KeyError {
|
|
198
|
+
export class KeyError implements Equatable {
|
|
147
199
|
readonly _tag = ParseErrorTag.Key;
|
|
148
200
|
constructor(
|
|
149
201
|
readonly keyAST: AST,
|
|
150
202
|
readonly key: any,
|
|
151
203
|
readonly error: ParseError | MissingError | UnexpectedError,
|
|
152
204
|
) {}
|
|
205
|
+
|
|
206
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
207
|
+
return (
|
|
208
|
+
hasTag(that, ParseErrorTag.Key) &&
|
|
209
|
+
context.comparator(this.keyAST, that.keyAST) &&
|
|
210
|
+
context.comparator(this.key, that.key) &&
|
|
211
|
+
context.comparator(this.error, that.error)
|
|
212
|
+
);
|
|
213
|
+
}
|
|
153
214
|
}
|
|
154
215
|
|
|
155
216
|
/**
|
|
@@ -163,8 +224,12 @@ export function keyError(keyAST: AST, key: any, error: ParseError | MissingError
|
|
|
163
224
|
/**
|
|
164
225
|
* @tsplus companion fncts.schema.ParseError.MissingError
|
|
165
226
|
*/
|
|
166
|
-
export class MissingError {
|
|
227
|
+
export class MissingError implements Equatable {
|
|
167
228
|
readonly _tag = ParseErrorTag.Missing;
|
|
229
|
+
|
|
230
|
+
[Symbol.equals](that: unknown): boolean {
|
|
231
|
+
return hasTag(that, ParseErrorTag.Missing);
|
|
232
|
+
}
|
|
168
233
|
}
|
|
169
234
|
|
|
170
235
|
/**
|
|
@@ -175,9 +240,13 @@ export const missingError = new MissingError();
|
|
|
175
240
|
/**
|
|
176
241
|
* @tsplus companion fncts.schema.ParseError.UnexpectedError
|
|
177
242
|
*/
|
|
178
|
-
export class UnexpectedError {
|
|
243
|
+
export class UnexpectedError implements Equatable {
|
|
179
244
|
readonly _tag = ParseErrorTag.Unexpected;
|
|
180
245
|
constructor(readonly actual: unknown) {}
|
|
246
|
+
|
|
247
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
248
|
+
return hasTag(that, ParseErrorTag.Unexpected) && context.comparator(this.actual, that.actual);
|
|
249
|
+
}
|
|
181
250
|
}
|
|
182
251
|
|
|
183
252
|
/**
|
|
@@ -191,13 +260,22 @@ export function unexpectedError(actual: unknown): UnexpectedError {
|
|
|
191
260
|
/**
|
|
192
261
|
* @tsplus companion fncts.schema.ParseError.UnionError
|
|
193
262
|
*/
|
|
194
|
-
export class UnionError {
|
|
263
|
+
export class UnionError implements Equatable {
|
|
195
264
|
readonly _tag = ParseErrorTag.Union;
|
|
196
265
|
constructor(
|
|
197
266
|
readonly ast: Union,
|
|
198
267
|
readonly actual: unknown,
|
|
199
268
|
readonly errors: Vector<TypeError | TypeLiteralError | UnionMemberError>,
|
|
200
269
|
) {}
|
|
270
|
+
|
|
271
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
272
|
+
return (
|
|
273
|
+
hasTag(that, ParseErrorTag.Union) &&
|
|
274
|
+
context.comparator(this.ast, that.ast) &&
|
|
275
|
+
context.comparator(this.actual, that.actual) &&
|
|
276
|
+
context.comparator(this.errors, that.errors)
|
|
277
|
+
);
|
|
278
|
+
}
|
|
201
279
|
}
|
|
202
280
|
|
|
203
281
|
/**
|
|
@@ -215,12 +293,20 @@ export function unionError(
|
|
|
215
293
|
/**
|
|
216
294
|
* @tsplus companion fncts.schema.ParseError.UnionMemberError
|
|
217
295
|
*/
|
|
218
|
-
export class UnionMemberError {
|
|
296
|
+
export class UnionMemberError implements Equatable {
|
|
219
297
|
readonly _tag = ParseErrorTag.UnionMember;
|
|
220
298
|
constructor(
|
|
221
299
|
readonly ast: AST,
|
|
222
300
|
readonly error: ParseError,
|
|
223
301
|
) {}
|
|
302
|
+
|
|
303
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
304
|
+
return (
|
|
305
|
+
hasTag(that, ParseErrorTag.UnionMember) &&
|
|
306
|
+
context.comparator(this.ast, that.ast) &&
|
|
307
|
+
context.comparator(this.error, that.error)
|
|
308
|
+
);
|
|
309
|
+
}
|
|
224
310
|
}
|
|
225
311
|
|
|
226
312
|
/**
|
|
@@ -234,7 +320,7 @@ export function unionMemberError(ast: AST, error: ParseError): UnionMemberError
|
|
|
234
320
|
/**
|
|
235
321
|
* @tsplus companion fncts.schema.ParseError.RefinementError
|
|
236
322
|
*/
|
|
237
|
-
export class RefinementError {
|
|
323
|
+
export class RefinementError implements Equatable {
|
|
238
324
|
readonly _tag = ParseErrorTag.Refinement;
|
|
239
325
|
constructor(
|
|
240
326
|
readonly ast: Refinement,
|
|
@@ -242,6 +328,16 @@ export class RefinementError {
|
|
|
242
328
|
readonly kind: "From" | "Predicate",
|
|
243
329
|
readonly error: ParseError,
|
|
244
330
|
) {}
|
|
331
|
+
|
|
332
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
333
|
+
return (
|
|
334
|
+
hasTag(that, ParseErrorTag.Refinement) &&
|
|
335
|
+
context.comparator(this.ast, that.ast) &&
|
|
336
|
+
context.comparator(this.actual, that.actual) &&
|
|
337
|
+
context.comparator(this.kind, that.kind) &&
|
|
338
|
+
context.comparator(this.error, that.error)
|
|
339
|
+
);
|
|
340
|
+
}
|
|
245
341
|
}
|
|
246
342
|
|
|
247
343
|
/**
|
|
@@ -260,7 +356,7 @@ export function refinementError(
|
|
|
260
356
|
/**
|
|
261
357
|
* @tsplus companion fncts.schema.ParseError.TransformationError
|
|
262
358
|
*/
|
|
263
|
-
export class TransformationError {
|
|
359
|
+
export class TransformationError implements Equatable {
|
|
264
360
|
readonly _tag = ParseErrorTag.Transformation;
|
|
265
361
|
constructor(
|
|
266
362
|
readonly ast: Transform,
|
|
@@ -268,6 +364,16 @@ export class TransformationError {
|
|
|
268
364
|
readonly kind: "Encoded" | "Transformation" | "Type",
|
|
269
365
|
readonly error: ParseError,
|
|
270
366
|
) {}
|
|
367
|
+
|
|
368
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
369
|
+
return (
|
|
370
|
+
hasTag(that, ParseErrorTag.Transformation) &&
|
|
371
|
+
context.comparator(this.ast, that.ast) &&
|
|
372
|
+
context.comparator(this.actual, that.actual) &&
|
|
373
|
+
context.comparator(this.kind, that.kind) &&
|
|
374
|
+
context.comparator(this.error, that.error)
|
|
375
|
+
);
|
|
376
|
+
}
|
|
271
377
|
}
|
|
272
378
|
|
|
273
379
|
/**
|
|
@@ -286,13 +392,22 @@ export function transformationError(
|
|
|
286
392
|
/**
|
|
287
393
|
* @tsplus companion fncts.schema.ParseError.IterableError
|
|
288
394
|
*/
|
|
289
|
-
export class IterableError {
|
|
395
|
+
export class IterableError implements Equatable {
|
|
290
396
|
readonly _tag = ParseErrorTag.Iterable;
|
|
291
397
|
constructor(
|
|
292
398
|
readonly ast: AST,
|
|
293
399
|
readonly actual: unknown,
|
|
294
400
|
readonly errors: Vector<IndexError | KeyError>,
|
|
295
401
|
) {}
|
|
402
|
+
|
|
403
|
+
[Symbol.equals](that: unknown, context: EqualsContext): boolean {
|
|
404
|
+
return (
|
|
405
|
+
hasTag(that, ParseErrorTag.Iterable) &&
|
|
406
|
+
context.comparator(this.ast, that.ast) &&
|
|
407
|
+
context.comparator(this.actual, that.actual) &&
|
|
408
|
+
context.comparator(this.errors, that.errors)
|
|
409
|
+
);
|
|
410
|
+
}
|
|
296
411
|
}
|
|
297
412
|
|
|
298
413
|
/**
|
|
@@ -78,7 +78,7 @@ function hashMapParser(isDecoding: boolean) {
|
|
|
78
78
|
const tv = valueParser(v, options);
|
|
79
79
|
Either.concrete(tv);
|
|
80
80
|
if (tv.isLeft()) {
|
|
81
|
-
errors.push(ParseError.KeyError(key.ast, k,
|
|
81
|
+
errors.push(ParseError.KeyError(key.ast, k, tv.left));
|
|
82
82
|
if (!allErrors) {
|
|
83
83
|
return ParseResult.fail(ParseError.IterableError(schema.ast, u, errors));
|
|
84
84
|
}
|
|
@@ -61,7 +61,7 @@ function hashSetParser(isDecoding: boolean) {
|
|
|
61
61
|
const tv = parseValue(v, options);
|
|
62
62
|
Either.concrete(tv);
|
|
63
63
|
if (tv.isLeft()) {
|
|
64
|
-
errors.push(ParseError.KeyError(value.ast,
|
|
64
|
+
errors.push(ParseError.KeyError(value.ast, v, tv.left));
|
|
65
65
|
if (!allErrors) {
|
|
66
66
|
return ParseResult.fail(ParseError.IterableError(schema.ast, u, errors));
|
|
67
67
|
}
|
package/_src/Schema/api/list.ts
CHANGED
|
@@ -47,12 +47,13 @@ function parser(isDecoding: boolean) {
|
|
|
47
47
|
const out = new ListBuffer<unknown>();
|
|
48
48
|
const errors = Vector.emptyPushable<IndexError>();
|
|
49
49
|
const allErrors = options?.allErrors;
|
|
50
|
-
|
|
50
|
+
let index = 0;
|
|
51
51
|
for (const v of u) {
|
|
52
52
|
const t = parseValue(v, options);
|
|
53
53
|
Either.concrete(t);
|
|
54
54
|
if (t.isLeft()) {
|
|
55
55
|
errors.push(ParseError.IndexError(index, t.left));
|
|
56
|
+
index++;
|
|
56
57
|
if (allErrors) {
|
|
57
58
|
continue;
|
|
58
59
|
}
|
|
@@ -60,6 +61,7 @@ function parser(isDecoding: boolean) {
|
|
|
60
61
|
} else {
|
|
61
62
|
out.append(t.right);
|
|
62
63
|
}
|
|
64
|
+
index++;
|
|
63
65
|
}
|
|
64
66
|
return errors.isNonEmpty()
|
|
65
67
|
? ParseResult.fail(ParseError.IterableError(schema.ast, u, errors))
|
package/_src/Schema/api/map.ts
CHANGED
|
@@ -71,7 +71,7 @@ function mapParser(isDecoding: boolean) {
|
|
|
71
71
|
const tv = valueParser(v, options);
|
|
72
72
|
Either.concrete(tv);
|
|
73
73
|
if (tv.isLeft()) {
|
|
74
|
-
errors.push(ParseError.KeyError(key.ast, k,
|
|
74
|
+
errors.push(ParseError.KeyError(key.ast, k, tv.left));
|
|
75
75
|
if (!allErrors) {
|
|
76
76
|
return ParseResult.fail(ParseError.IterableError(schema.ast, u, errors));
|
|
77
77
|
}
|
package/_src/Schema/api/set.ts
CHANGED
|
@@ -54,7 +54,7 @@ function setParser(isDecoding: boolean) {
|
|
|
54
54
|
const tv = parseValue(v, options);
|
|
55
55
|
Either.concrete(tv);
|
|
56
56
|
if (tv.isLeft()) {
|
|
57
|
-
errors.push(ParseError.KeyError(value.ast,
|
|
57
|
+
errors.push(ParseError.KeyError(value.ast, v, tv.left));
|
|
58
58
|
if (!allErrors) {
|
|
59
59
|
return ParseResult.fail(ParseError.IterableError(schema.ast, u, errors));
|
|
60
60
|
}
|
package/package.json
CHANGED