effect 3.12.8 → 3.12.10
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/dist/cjs/Array.js +2 -3
- package/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/Context.js.map +1 -1
- package/dist/cjs/Duration.js +3 -0
- package/dist/cjs/Duration.js.map +1 -1
- package/dist/cjs/Effect.js.map +1 -1
- package/dist/cjs/ParseResult.js +162 -169
- package/dist/cjs/ParseResult.js.map +1 -1
- package/dist/cjs/Schema.js +1 -1
- package/dist/cjs/Schema.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/cjs/internal/version.js.map +1 -1
- package/dist/dts/Array.d.ts +34 -1
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/Context.d.ts +4 -2
- package/dist/dts/Context.d.ts.map +1 -1
- package/dist/dts/Duration.d.ts.map +1 -1
- package/dist/dts/Effect.d.ts.map +1 -1
- package/dist/dts/ParseResult.d.ts.map +1 -1
- package/dist/dts/STM.d.ts +1 -1
- package/dist/dts/Schema.d.ts.map +1 -1
- package/dist/esm/Array.js +2 -2
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/Context.js.map +1 -1
- package/dist/esm/Duration.js +3 -0
- package/dist/esm/Duration.js.map +1 -1
- package/dist/esm/Effect.js.map +1 -1
- package/dist/esm/ParseResult.js +162 -169
- package/dist/esm/ParseResult.js.map +1 -1
- package/dist/esm/Schema.js +1 -1
- package/dist/esm/Schema.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/dist/esm/internal/version.js.map +1 -1
- package/package.json +1 -1
- package/src/Array.ts +35 -2
- package/src/Context.ts +6 -2
- package/src/Duration.ts +3 -0
- package/src/Effect.ts +1 -1
- package/src/ParseResult.ts +172 -190
- package/src/STM.ts +1 -1
- package/src/Schema.ts +1 -1
- package/src/internal/version.ts +1 -1
package/dist/cjs/ParseResult.js
CHANGED
|
@@ -279,56 +279,39 @@ const _try = exports.try = Either.try;
|
|
|
279
279
|
* @since 3.10.0
|
|
280
280
|
*/
|
|
281
281
|
const fromOption = exports.fromOption = Either.fromOption;
|
|
282
|
+
const isEither = Either.isEither;
|
|
282
283
|
/**
|
|
283
284
|
* @category optimisation
|
|
284
285
|
* @since 3.10.0
|
|
285
286
|
*/
|
|
286
287
|
const flatMap = exports.flatMap = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
if (s["_tag"] === "Right") {
|
|
292
|
-
return f(s.right);
|
|
293
|
-
}
|
|
294
|
-
return Effect.flatMap(self, f);
|
|
288
|
+
return isEither(self) ? Either.match(self, {
|
|
289
|
+
onLeft: Either.left,
|
|
290
|
+
onRight: f
|
|
291
|
+
}) : Effect.flatMap(self, f);
|
|
295
292
|
});
|
|
296
293
|
/**
|
|
297
294
|
* @category optimisation
|
|
298
295
|
* @since 3.10.0
|
|
299
296
|
*/
|
|
300
297
|
const map = exports.map = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
301
|
-
|
|
302
|
-
if (s["_tag"] === "Left") {
|
|
303
|
-
return s;
|
|
304
|
-
}
|
|
305
|
-
if (s["_tag"] === "Right") {
|
|
306
|
-
return Either.right(f(s.right));
|
|
307
|
-
}
|
|
308
|
-
return Effect.map(self, f);
|
|
298
|
+
return isEither(self) ? Either.map(self, f) : Effect.map(self, f);
|
|
309
299
|
});
|
|
310
300
|
/**
|
|
311
301
|
* @category optimisation
|
|
312
302
|
* @since 3.10.0
|
|
313
303
|
*/
|
|
314
304
|
const mapError = exports.mapError = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
315
|
-
|
|
316
|
-
if (s["_tag"] === "Left") {
|
|
317
|
-
return Either.left(f(s.left));
|
|
318
|
-
}
|
|
319
|
-
if (s["_tag"] === "Right") {
|
|
320
|
-
return s;
|
|
321
|
-
}
|
|
322
|
-
return Effect.mapError(self, f);
|
|
305
|
+
return isEither(self) ? Either.mapLeft(self, f) : Effect.mapError(self, f);
|
|
323
306
|
});
|
|
307
|
+
// TODO(4.0): remove
|
|
324
308
|
/**
|
|
325
309
|
* @category optimisation
|
|
326
310
|
* @since 3.10.0
|
|
327
311
|
*/
|
|
328
312
|
const eitherOrUndefined = self => {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return s;
|
|
313
|
+
if (isEither(self)) {
|
|
314
|
+
return self;
|
|
332
315
|
}
|
|
333
316
|
};
|
|
334
317
|
/**
|
|
@@ -337,28 +320,20 @@ const eitherOrUndefined = self => {
|
|
|
337
320
|
*/
|
|
338
321
|
exports.eitherOrUndefined = eitherOrUndefined;
|
|
339
322
|
const mapBoth = exports.mapBoth = /*#__PURE__*/(0, _Function.dual)(2, (self, options) => {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
if (s["_tag"] === "Right") {
|
|
345
|
-
return Either.right(options.onSuccess(s.right));
|
|
346
|
-
}
|
|
347
|
-
return Effect.mapBoth(self, options);
|
|
323
|
+
return isEither(self) ? Either.mapBoth(self, {
|
|
324
|
+
onLeft: options.onFailure,
|
|
325
|
+
onRight: options.onSuccess
|
|
326
|
+
}) : Effect.mapBoth(self, options);
|
|
348
327
|
});
|
|
349
328
|
/**
|
|
350
329
|
* @category optimisation
|
|
351
330
|
* @since 3.10.0
|
|
352
331
|
*/
|
|
353
332
|
const orElse = exports.orElse = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
if (s["_tag"] === "Right") {
|
|
359
|
-
return s;
|
|
360
|
-
}
|
|
361
|
-
return Effect.catchAll(self, f);
|
|
333
|
+
return isEither(self) ? Either.match(self, {
|
|
334
|
+
onLeft: f,
|
|
335
|
+
onRight: Either.right
|
|
336
|
+
}) : Effect.catchAll(self, f);
|
|
362
337
|
});
|
|
363
338
|
/** @internal */
|
|
364
339
|
const mergeInternalOptions = (options, overrideOptions) => {
|
|
@@ -731,11 +706,10 @@ const go = (ast, isDecoding) => {
|
|
|
731
706
|
} else {
|
|
732
707
|
const parser = elements[i];
|
|
733
708
|
const te = parser(input[i], options);
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
if (Either.isLeft(eu)) {
|
|
709
|
+
if (isEither(te)) {
|
|
710
|
+
if (Either.isLeft(te)) {
|
|
737
711
|
// the input element is present but is not valid
|
|
738
|
-
const e = new Pointer(i, input,
|
|
712
|
+
const e = new Pointer(i, input, te.left);
|
|
739
713
|
if (allErrors) {
|
|
740
714
|
es.push([stepKey++, e]);
|
|
741
715
|
continue;
|
|
@@ -743,7 +717,7 @@ const go = (ast, isDecoding) => {
|
|
|
743
717
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)));
|
|
744
718
|
}
|
|
745
719
|
}
|
|
746
|
-
output.push([stepKey++,
|
|
720
|
+
output.push([stepKey++, te.right]);
|
|
747
721
|
} else {
|
|
748
722
|
const nk = stepKey++;
|
|
749
723
|
const index = i;
|
|
@@ -777,10 +751,9 @@ const go = (ast, isDecoding) => {
|
|
|
777
751
|
const [head, ...tail] = rest;
|
|
778
752
|
for (; i < len - tail.length; i++) {
|
|
779
753
|
const te = head(input[i], options);
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
const e = new Pointer(i, input, eu.left);
|
|
754
|
+
if (isEither(te)) {
|
|
755
|
+
if (Either.isLeft(te)) {
|
|
756
|
+
const e = new Pointer(i, input, te.left);
|
|
784
757
|
if (allErrors) {
|
|
785
758
|
es.push([stepKey++, e]);
|
|
786
759
|
continue;
|
|
@@ -788,7 +761,7 @@ const go = (ast, isDecoding) => {
|
|
|
788
761
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)));
|
|
789
762
|
}
|
|
790
763
|
} else {
|
|
791
|
-
output.push([stepKey++,
|
|
764
|
+
output.push([stepKey++, te.right]);
|
|
792
765
|
}
|
|
793
766
|
} else {
|
|
794
767
|
const nk = stepKey++;
|
|
@@ -824,11 +797,10 @@ const go = (ast, isDecoding) => {
|
|
|
824
797
|
continue;
|
|
825
798
|
} else {
|
|
826
799
|
const te = tail[j](input[i], options);
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
if (Either.isLeft(eu)) {
|
|
800
|
+
if (isEither(te)) {
|
|
801
|
+
if (Either.isLeft(te)) {
|
|
830
802
|
// the input element is present but is not valid
|
|
831
|
-
const e = new Pointer(i, input,
|
|
803
|
+
const e = new Pointer(i, input, te.left);
|
|
832
804
|
if (allErrors) {
|
|
833
805
|
es.push([stepKey++, e]);
|
|
834
806
|
continue;
|
|
@@ -836,7 +808,7 @@ const go = (ast, isDecoding) => {
|
|
|
836
808
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)));
|
|
837
809
|
}
|
|
838
810
|
}
|
|
839
|
-
output.push([stepKey++,
|
|
811
|
+
output.push([stepKey++, te.right]);
|
|
840
812
|
} else {
|
|
841
813
|
const nk = stepKey++;
|
|
842
814
|
const index = i;
|
|
@@ -926,8 +898,8 @@ const go = (ast, isDecoding) => {
|
|
|
926
898
|
if (onExcessPropertyError || onExcessPropertyPreserve) {
|
|
927
899
|
inputKeys = util_.ownKeys(input);
|
|
928
900
|
for (const key of inputKeys) {
|
|
929
|
-
const
|
|
930
|
-
if (Either.isLeft(
|
|
901
|
+
const te = expected(key, options);
|
|
902
|
+
if (isEither(te) && Either.isLeft(te)) {
|
|
931
903
|
// key is unexpected
|
|
932
904
|
if (onExcessPropertyError) {
|
|
933
905
|
const e = new Pointer(key, input, new Unexpected(input[key], `is unexpected, expected: ${String(expectedAST)}`));
|
|
@@ -965,10 +937,9 @@ const go = (ast, isDecoding) => {
|
|
|
965
937
|
}
|
|
966
938
|
const parser = propertySignatures[i][0];
|
|
967
939
|
const te = parser(input[name], options);
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
const e = new Pointer(name, input, hasKey ? eu.left : new Missing(ps));
|
|
940
|
+
if (isEither(te)) {
|
|
941
|
+
if (Either.isLeft(te)) {
|
|
942
|
+
const e = new Pointer(name, input, hasKey ? te.left : new Missing(ps));
|
|
972
943
|
if (allErrors) {
|
|
973
944
|
es.push([stepKey++, e]);
|
|
974
945
|
continue;
|
|
@@ -976,7 +947,7 @@ const go = (ast, isDecoding) => {
|
|
|
976
947
|
return Either.left(new Composite(ast, input, e, output));
|
|
977
948
|
}
|
|
978
949
|
}
|
|
979
|
-
output[name] =
|
|
950
|
+
output[name] = te.right;
|
|
980
951
|
} else {
|
|
981
952
|
const nk = stepKey++;
|
|
982
953
|
const index = name;
|
|
@@ -1013,16 +984,15 @@ const go = (ast, isDecoding) => {
|
|
|
1013
984
|
// ---------------------------------------------
|
|
1014
985
|
// handle keys
|
|
1015
986
|
// ---------------------------------------------
|
|
1016
|
-
const keu =
|
|
1017
|
-
if (keu && Either.isRight(keu)) {
|
|
987
|
+
const keu = parameter(key, options);
|
|
988
|
+
if (isEither(keu) && Either.isRight(keu)) {
|
|
1018
989
|
// ---------------------------------------------
|
|
1019
990
|
// handle values
|
|
1020
991
|
// ---------------------------------------------
|
|
1021
992
|
const vpr = type(input[key], options);
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
const e = new Pointer(key, input, veu.left);
|
|
993
|
+
if (isEither(vpr)) {
|
|
994
|
+
if (Either.isLeft(vpr)) {
|
|
995
|
+
const e = new Pointer(key, input, vpr.left);
|
|
1026
996
|
if (allErrors) {
|
|
1027
997
|
es.push([stepKey++, e]);
|
|
1028
998
|
continue;
|
|
@@ -1031,7 +1001,7 @@ const go = (ast, isDecoding) => {
|
|
|
1031
1001
|
}
|
|
1032
1002
|
} else {
|
|
1033
1003
|
if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) {
|
|
1034
|
-
output[key] =
|
|
1004
|
+
output[key] = vpr.right;
|
|
1035
1005
|
}
|
|
1036
1006
|
}
|
|
1037
1007
|
} else {
|
|
@@ -1173,12 +1143,11 @@ const go = (ast, isDecoding) => {
|
|
|
1173
1143
|
// the members of a union are ordered based on which one should be decoded first,
|
|
1174
1144
|
// therefore if one member has added a task, all subsequent members must
|
|
1175
1145
|
// also add a task to the queue even if they are synchronous
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
return eu;
|
|
1146
|
+
if (isEither(pr) && (!queue || queue.length === 0)) {
|
|
1147
|
+
if (Either.isRight(pr)) {
|
|
1148
|
+
return pr;
|
|
1180
1149
|
} else {
|
|
1181
|
-
es.push([stepKey++,
|
|
1150
|
+
es.push([stepKey++, pr.left]);
|
|
1182
1151
|
}
|
|
1183
1152
|
} else {
|
|
1184
1153
|
const nk = stepKey++;
|
|
@@ -1347,11 +1316,9 @@ const handleForbidden = (effect, ast, actual, options) => {
|
|
|
1347
1316
|
if (options?.isEffectAllowed === true) {
|
|
1348
1317
|
return effect;
|
|
1349
1318
|
}
|
|
1350
|
-
// Convert the effect to an Either, if possible
|
|
1351
|
-
const eu = eitherOrUndefined(effect);
|
|
1352
1319
|
// If the effect is already an Either, return it directly
|
|
1353
|
-
if (
|
|
1354
|
-
return
|
|
1320
|
+
if (isEither(effect)) {
|
|
1321
|
+
return effect;
|
|
1355
1322
|
}
|
|
1356
1323
|
// Otherwise, attempt to execute the effect synchronously
|
|
1357
1324
|
const scheduler = new Scheduler.SyncScheduler();
|
|
@@ -1423,8 +1390,11 @@ const makeTree = (value, forest = []) => ({
|
|
|
1423
1390
|
* @since 3.10.0
|
|
1424
1391
|
*/
|
|
1425
1392
|
const TreeFormatter = exports.TreeFormatter = {
|
|
1426
|
-
formatIssue: issue =>
|
|
1427
|
-
formatIssueSync: issue =>
|
|
1393
|
+
formatIssue: issue => map(formatTree(issue), drawTree),
|
|
1394
|
+
formatIssueSync: issue => {
|
|
1395
|
+
const e = TreeFormatter.formatIssue(issue);
|
|
1396
|
+
return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e);
|
|
1397
|
+
},
|
|
1428
1398
|
formatError: error => TreeFormatter.formatIssue(error.issue),
|
|
1429
1399
|
formatErrorSync: error => TreeFormatter.formatIssueSync(error.issue)
|
|
1430
1400
|
};
|
|
@@ -1460,21 +1430,35 @@ const formatRefinementKind = kind => {
|
|
|
1460
1430
|
}
|
|
1461
1431
|
};
|
|
1462
1432
|
const getAnnotated = issue => "ast" in issue ? Option.some(issue.ast) : Option.none();
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1433
|
+
// TODO: replace with Either.void when 3.13 lands
|
|
1434
|
+
const Either_void = /*#__PURE__*/Either.right(undefined);
|
|
1435
|
+
const getCurrentMessage = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getMessageAnnotation), Option.match({
|
|
1436
|
+
onNone: () => Either_void,
|
|
1437
|
+
onSome: messageAnnotation => {
|
|
1438
|
+
const union = messageAnnotation(issue);
|
|
1439
|
+
if (Predicate.isString(union)) {
|
|
1440
|
+
return Either.right({
|
|
1441
|
+
message: union,
|
|
1442
|
+
override: false
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
if (Effect.isEffect(union)) {
|
|
1446
|
+
return Effect.map(union, message => ({
|
|
1447
|
+
message,
|
|
1448
|
+
override: false
|
|
1449
|
+
}));
|
|
1450
|
+
}
|
|
1451
|
+
if (Predicate.isString(union.message)) {
|
|
1452
|
+
return Either.right({
|
|
1453
|
+
message: union.message,
|
|
1454
|
+
override: union.override
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
return Effect.map(union.message, message => ({
|
|
1458
|
+
message,
|
|
1459
|
+
override: union.override
|
|
1460
|
+
}));
|
|
1461
|
+
}
|
|
1478
1462
|
}));
|
|
1479
1463
|
const createParseIssueGuard = tag => issue => issue._tag === tag;
|
|
1480
1464
|
/**
|
|
@@ -1486,110 +1470,119 @@ const createParseIssueGuard = tag => issue => issue._tag === tag;
|
|
|
1486
1470
|
const isComposite = exports.isComposite = /*#__PURE__*/createParseIssueGuard("Composite");
|
|
1487
1471
|
const isRefinement = /*#__PURE__*/createParseIssueGuard("Refinement");
|
|
1488
1472
|
const isTransformation = /*#__PURE__*/createParseIssueGuard("Transformation");
|
|
1489
|
-
const getMessage = issue => getCurrentMessage(issue)
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1473
|
+
const getMessage = issue => flatMap(getCurrentMessage(issue), currentMessage => {
|
|
1474
|
+
if (currentMessage !== undefined) {
|
|
1475
|
+
const useInnerMessage = !currentMessage.override && (isComposite(issue) || isRefinement(issue) && issue.kind === "From" || isTransformation(issue) && issue.kind !== "Transformation");
|
|
1476
|
+
return useInnerMessage ? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Either_void : Either.right(currentMessage.message);
|
|
1477
|
+
}
|
|
1478
|
+
return Either_void;
|
|
1479
|
+
});
|
|
1480
|
+
const getParseIssueTitleAnnotation = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getParseIssueTitleAnnotation), Option.filterMap(annotation => Option.fromNullable(annotation(issue))), Option.getOrUndefined);
|
|
1494
1481
|
/** @internal */
|
|
1495
1482
|
function getRefinementExpected(ast) {
|
|
1496
1483
|
return AST.getDescriptionAnnotation(ast).pipe(Option.orElse(() => AST.getTitleAnnotation(ast)), Option.orElse(() => AST.getAutoTitleAnnotation(ast)), Option.orElse(() => AST.getIdentifierAnnotation(ast)), Option.getOrElse(() => `{ ${ast.from} | filter }`));
|
|
1497
1484
|
}
|
|
1498
|
-
function getDefaultTypeMessage(
|
|
1499
|
-
if (
|
|
1500
|
-
return
|
|
1485
|
+
function getDefaultTypeMessage(issue) {
|
|
1486
|
+
if (issue.message !== undefined) {
|
|
1487
|
+
return issue.message;
|
|
1501
1488
|
}
|
|
1502
|
-
const expected = AST.isRefinement(
|
|
1503
|
-
return `Expected ${expected}, actual ${util_.formatUnknown(
|
|
1489
|
+
const expected = AST.isRefinement(issue.ast) ? getRefinementExpected(issue.ast) : String(issue.ast);
|
|
1490
|
+
return `Expected ${expected}, actual ${util_.formatUnknown(issue.actual)}`;
|
|
1504
1491
|
}
|
|
1505
|
-
const formatTypeMessage =
|
|
1506
|
-
const getParseIssueTitle = issue =>
|
|
1507
|
-
const formatForbiddenMessage =
|
|
1508
|
-
const formatUnexpectedMessage =
|
|
1509
|
-
const formatMissingMessage =
|
|
1510
|
-
const
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
}
|
|
1517
|
-
const formatTree =
|
|
1518
|
-
switch (
|
|
1492
|
+
const formatTypeMessage = issue => map(getMessage(issue), message => message ?? getParseIssueTitleAnnotation(issue) ?? getDefaultTypeMessage(issue));
|
|
1493
|
+
const getParseIssueTitle = issue => getParseIssueTitleAnnotation(issue) ?? String(issue.ast);
|
|
1494
|
+
const formatForbiddenMessage = issue => issue.message ?? "is forbidden";
|
|
1495
|
+
const formatUnexpectedMessage = issue => issue.message ?? "is unexpected";
|
|
1496
|
+
const formatMissingMessage = issue => {
|
|
1497
|
+
const missingMessageAnnotation = AST.getMissingMessageAnnotation(issue.ast);
|
|
1498
|
+
if (Option.isSome(missingMessageAnnotation)) {
|
|
1499
|
+
const annotation = missingMessageAnnotation.value();
|
|
1500
|
+
return Predicate.isString(annotation) ? Either.right(annotation) : annotation;
|
|
1501
|
+
}
|
|
1502
|
+
return Either.right(issue.message ?? "is missing");
|
|
1503
|
+
};
|
|
1504
|
+
const formatTree = issue => {
|
|
1505
|
+
switch (issue._tag) {
|
|
1519
1506
|
case "Type":
|
|
1520
|
-
return
|
|
1507
|
+
return map(formatTypeMessage(issue), makeTree);
|
|
1521
1508
|
case "Forbidden":
|
|
1522
|
-
return
|
|
1509
|
+
return Either.right(makeTree(getParseIssueTitle(issue), [makeTree(formatForbiddenMessage(issue))]));
|
|
1523
1510
|
case "Unexpected":
|
|
1524
|
-
return
|
|
1511
|
+
return Either.right(makeTree(formatUnexpectedMessage(issue)));
|
|
1525
1512
|
case "Missing":
|
|
1526
|
-
return
|
|
1513
|
+
return map(formatMissingMessage(issue), makeTree);
|
|
1527
1514
|
case "Transformation":
|
|
1528
|
-
return
|
|
1515
|
+
return flatMap(getMessage(issue), message => {
|
|
1516
|
+
if (message !== undefined) {
|
|
1517
|
+
return Either.right(makeTree(message));
|
|
1518
|
+
}
|
|
1519
|
+
return map(formatTree(issue.issue), tree => makeTree(getParseIssueTitle(issue), [makeTree(formatTransformationKind(issue.kind), [tree])]));
|
|
1520
|
+
});
|
|
1529
1521
|
case "Refinement":
|
|
1530
|
-
return
|
|
1522
|
+
return flatMap(getMessage(issue), message => {
|
|
1523
|
+
if (message !== undefined) {
|
|
1524
|
+
return Either.right(makeTree(message));
|
|
1525
|
+
}
|
|
1526
|
+
return map(formatTree(issue.issue), tree => makeTree(getParseIssueTitle(issue), [makeTree(formatRefinementKind(issue.kind), [tree])]));
|
|
1527
|
+
});
|
|
1531
1528
|
case "Pointer":
|
|
1532
|
-
return
|
|
1529
|
+
return map(formatTree(issue.issue), tree => makeTree(util_.formatPath(issue.path), [tree]));
|
|
1533
1530
|
case "Composite":
|
|
1534
|
-
{
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1531
|
+
return flatMap(getMessage(issue), message => {
|
|
1532
|
+
if (message !== undefined) {
|
|
1533
|
+
return Either.right(makeTree(message));
|
|
1534
|
+
}
|
|
1535
|
+
const parseIssueTitle = getParseIssueTitle(issue);
|
|
1536
|
+
return util_.isNonEmpty(issue.issues) ? map(Effect.forEach(issue.issues, formatTree), forest => makeTree(parseIssueTitle, forest)) : map(formatTree(issue.issues), tree => makeTree(parseIssueTitle, [tree]));
|
|
1537
|
+
});
|
|
1538
1538
|
}
|
|
1539
1539
|
};
|
|
1540
|
+
const makeArrayFormatterIssue = (_tag, path, message) => ({
|
|
1541
|
+
_tag,
|
|
1542
|
+
path,
|
|
1543
|
+
message
|
|
1544
|
+
});
|
|
1540
1545
|
/**
|
|
1541
1546
|
* @category formatting
|
|
1542
1547
|
* @since 3.10.0
|
|
1543
1548
|
*/
|
|
1544
1549
|
const ArrayFormatter = exports.ArrayFormatter = {
|
|
1545
|
-
formatIssue: issue =>
|
|
1546
|
-
formatIssueSync: issue =>
|
|
1550
|
+
formatIssue: issue => getArrayFormatterIssues(issue),
|
|
1551
|
+
formatIssueSync: issue => {
|
|
1552
|
+
const e = ArrayFormatter.formatIssue(issue);
|
|
1553
|
+
return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e);
|
|
1554
|
+
},
|
|
1547
1555
|
formatError: error => ArrayFormatter.formatIssue(error.issue),
|
|
1548
1556
|
formatErrorSync: error => ArrayFormatter.formatIssueSync(error.issue)
|
|
1549
1557
|
};
|
|
1550
|
-
const
|
|
1551
|
-
const
|
|
1552
|
-
onFailure,
|
|
1553
|
-
onSuccess: message => succeedArrayFormatterIssue({
|
|
1554
|
-
_tag: issue._tag,
|
|
1555
|
-
path,
|
|
1556
|
-
message
|
|
1557
|
-
})
|
|
1558
|
-
});
|
|
1559
|
-
const formatArray = (e, path = []) => {
|
|
1560
|
-
const _tag = e._tag;
|
|
1558
|
+
const getArrayFormatterIssues = (issue, path = []) => {
|
|
1559
|
+
const _tag = issue._tag;
|
|
1561
1560
|
switch (_tag) {
|
|
1562
1561
|
case "Type":
|
|
1563
|
-
return
|
|
1564
|
-
_tag,
|
|
1565
|
-
path,
|
|
1566
|
-
message
|
|
1567
|
-
}]);
|
|
1562
|
+
return map(formatTypeMessage(issue), message => [makeArrayFormatterIssue(_tag, path, message)]);
|
|
1568
1563
|
case "Forbidden":
|
|
1569
|
-
return
|
|
1570
|
-
_tag,
|
|
1571
|
-
path,
|
|
1572
|
-
message: formatForbiddenMessage(e)
|
|
1573
|
-
});
|
|
1564
|
+
return Either.right([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))]);
|
|
1574
1565
|
case "Unexpected":
|
|
1575
|
-
return
|
|
1576
|
-
_tag,
|
|
1577
|
-
path,
|
|
1578
|
-
message: formatUnexpectedMessage(e)
|
|
1579
|
-
});
|
|
1566
|
+
return Either.right([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))]);
|
|
1580
1567
|
case "Missing":
|
|
1581
|
-
return
|
|
1582
|
-
_tag,
|
|
1583
|
-
path,
|
|
1584
|
-
message
|
|
1585
|
-
}]);
|
|
1568
|
+
return map(formatMissingMessage(issue), message => [makeArrayFormatterIssue(_tag, path, message)]);
|
|
1586
1569
|
case "Pointer":
|
|
1587
|
-
return
|
|
1570
|
+
return getArrayFormatterIssues(issue.issue, path.concat(issue.path));
|
|
1588
1571
|
case "Composite":
|
|
1589
|
-
return
|
|
1572
|
+
return flatMap(getMessage(issue), message => {
|
|
1573
|
+
if (message !== undefined) {
|
|
1574
|
+
return Either.right([makeArrayFormatterIssue(issue._tag, path, message)]);
|
|
1575
|
+
}
|
|
1576
|
+
return util_.isNonEmpty(issue.issues) ? map(Effect.forEach(issue.issues, issue => getArrayFormatterIssues(issue, path)), Arr.flatten) : getArrayFormatterIssues(issue.issues, path);
|
|
1577
|
+
});
|
|
1590
1578
|
case "Refinement":
|
|
1591
1579
|
case "Transformation":
|
|
1592
|
-
return
|
|
1580
|
+
return flatMap(getMessage(issue), message => {
|
|
1581
|
+
if (message !== undefined) {
|
|
1582
|
+
return Either.right([makeArrayFormatterIssue(issue._tag, path, message)]);
|
|
1583
|
+
}
|
|
1584
|
+
return getArrayFormatterIssues(issue.issue, path);
|
|
1585
|
+
});
|
|
1593
1586
|
}
|
|
1594
1587
|
};
|
|
1595
1588
|
//# sourceMappingURL=ParseResult.js.map
|