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.
Files changed (42) hide show
  1. package/dist/cjs/Array.js +2 -3
  2. package/dist/cjs/Array.js.map +1 -1
  3. package/dist/cjs/Context.js.map +1 -1
  4. package/dist/cjs/Duration.js +3 -0
  5. package/dist/cjs/Duration.js.map +1 -1
  6. package/dist/cjs/Effect.js.map +1 -1
  7. package/dist/cjs/ParseResult.js +162 -169
  8. package/dist/cjs/ParseResult.js.map +1 -1
  9. package/dist/cjs/Schema.js +1 -1
  10. package/dist/cjs/Schema.js.map +1 -1
  11. package/dist/cjs/internal/version.js +1 -1
  12. package/dist/cjs/internal/version.js.map +1 -1
  13. package/dist/dts/Array.d.ts +34 -1
  14. package/dist/dts/Array.d.ts.map +1 -1
  15. package/dist/dts/Context.d.ts +4 -2
  16. package/dist/dts/Context.d.ts.map +1 -1
  17. package/dist/dts/Duration.d.ts.map +1 -1
  18. package/dist/dts/Effect.d.ts.map +1 -1
  19. package/dist/dts/ParseResult.d.ts.map +1 -1
  20. package/dist/dts/STM.d.ts +1 -1
  21. package/dist/dts/Schema.d.ts.map +1 -1
  22. package/dist/esm/Array.js +2 -2
  23. package/dist/esm/Array.js.map +1 -1
  24. package/dist/esm/Context.js.map +1 -1
  25. package/dist/esm/Duration.js +3 -0
  26. package/dist/esm/Duration.js.map +1 -1
  27. package/dist/esm/Effect.js.map +1 -1
  28. package/dist/esm/ParseResult.js +162 -169
  29. package/dist/esm/ParseResult.js.map +1 -1
  30. package/dist/esm/Schema.js +1 -1
  31. package/dist/esm/Schema.js.map +1 -1
  32. package/dist/esm/internal/version.js +1 -1
  33. package/dist/esm/internal/version.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/Array.ts +35 -2
  36. package/src/Context.ts +6 -2
  37. package/src/Duration.ts +3 -0
  38. package/src/Effect.ts +1 -1
  39. package/src/ParseResult.ts +172 -190
  40. package/src/STM.ts +1 -1
  41. package/src/Schema.ts +1 -1
  42. package/src/internal/version.ts +1 -1
@@ -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
- const s = self;
288
- if (s["_tag"] === "Left") {
289
- return s;
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
- const s = self;
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
- const s = self;
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
- const s = self;
330
- if (s["_tag"] === "Left" || s["_tag"] === "Right") {
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
- const s = self;
341
- if (s["_tag"] === "Left") {
342
- return Either.left(options.onFailure(s.left));
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
- const s = self;
355
- if (s["_tag"] === "Left") {
356
- return f(s.left);
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
- const eu = eitherOrUndefined(te);
735
- if (eu) {
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, eu.left);
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++, eu.right]);
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
- const eu = eitherOrUndefined(te);
781
- if (eu) {
782
- if (Either.isLeft(eu)) {
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++, eu.right]);
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
- const eu = eitherOrUndefined(te);
828
- if (eu) {
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, eu.left);
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++, eu.right]);
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 eu = eitherOrUndefined(expected(key, options));
930
- if (Either.isLeft(eu)) {
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
- const eu = eitherOrUndefined(te);
969
- if (eu) {
970
- if (Either.isLeft(eu)) {
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] = eu.right;
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 = eitherOrUndefined(parameter(key, options));
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
- const veu = eitherOrUndefined(vpr);
1023
- if (veu) {
1024
- if (Either.isLeft(veu)) {
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] = veu.right;
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
- const eu = !queue || queue.length === 0 ? eitherOrUndefined(pr) : undefined;
1177
- if (eu) {
1178
- if (Either.isRight(eu)) {
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++, eu.left]);
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 (eu) {
1354
- return eu;
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 => Effect.map(formatTree(issue), drawTree),
1427
- formatIssueSync: issue => Effect.runSync(TreeFormatter.formatIssue(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
- const getCurrentMessage = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getMessageAnnotation), Effect.flatMap(annotation => {
1464
- const out = annotation(issue);
1465
- return Predicate.isString(out) ? Effect.succeed({
1466
- message: out,
1467
- override: false
1468
- }) : Effect.isEffect(out) ? Effect.map(out, message => ({
1469
- message,
1470
- override: false
1471
- })) : Predicate.isString(out.message) ? Effect.succeed({
1472
- message: out.message,
1473
- override: out.override
1474
- }) : Effect.map(out.message, message => ({
1475
- message,
1476
- override: out.override
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).pipe(Effect.flatMap(currentMessage => {
1490
- const useInnerMessage = !currentMessage.override && (isComposite(issue) || isRefinement(issue) && issue.kind === "From" || isTransformation(issue) && issue.kind !== "Transformation");
1491
- return useInnerMessage ? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Option.none() : Effect.succeed(currentMessage.message);
1492
- }));
1493
- const getParseIssueTitleAnnotation = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getParseIssueTitleAnnotation), Option.filterMap(annotation => Option.fromNullable(annotation(issue))));
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(e) {
1499
- if (e.message !== undefined) {
1500
- return e.message;
1485
+ function getDefaultTypeMessage(issue) {
1486
+ if (issue.message !== undefined) {
1487
+ return issue.message;
1501
1488
  }
1502
- const expected = AST.isRefinement(e.ast) ? getRefinementExpected(e.ast) : String(e.ast);
1503
- return `Expected ${expected}, actual ${util_.formatUnknown(e.actual)}`;
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 = e => getMessage(e).pipe(Effect.orElse(() => getParseIssueTitleAnnotation(e)), Effect.catchAll(() => Effect.succeed(getDefaultTypeMessage(e))));
1506
- const getParseIssueTitle = issue => Option.getOrElse(getParseIssueTitleAnnotation(issue), () => String(issue.ast));
1507
- const formatForbiddenMessage = e => e.message ?? "is forbidden";
1508
- const formatUnexpectedMessage = e => e.message ?? "is unexpected";
1509
- const formatMissingMessage = e => AST.getMissingMessageAnnotation(e.ast).pipe(Effect.flatMap(annotation => {
1510
- const out = annotation();
1511
- return Predicate.isString(out) ? Effect.succeed(out) : out;
1512
- }), Effect.catchAll(() => Effect.succeed(e.message ?? "is missing")));
1513
- const getTree = (issue, onFailure) => Effect.matchEffect(getMessage(issue), {
1514
- onFailure,
1515
- onSuccess: message => Effect.succeed(makeTree(message))
1516
- });
1517
- const formatTree = e => {
1518
- switch (e._tag) {
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 Effect.map(formatTypeMessage(e), makeTree);
1507
+ return map(formatTypeMessage(issue), makeTree);
1521
1508
  case "Forbidden":
1522
- return Effect.succeed(makeTree(getParseIssueTitle(e), [makeTree(formatForbiddenMessage(e))]));
1509
+ return Either.right(makeTree(getParseIssueTitle(issue), [makeTree(formatForbiddenMessage(issue))]));
1523
1510
  case "Unexpected":
1524
- return Effect.succeed(makeTree(formatUnexpectedMessage(e)));
1511
+ return Either.right(makeTree(formatUnexpectedMessage(issue)));
1525
1512
  case "Missing":
1526
- return Effect.map(formatMissingMessage(e), makeTree);
1513
+ return map(formatMissingMessage(issue), makeTree);
1527
1514
  case "Transformation":
1528
- return getTree(e, () => Effect.map(formatTree(e.issue), tree => makeTree(getParseIssueTitle(e), [makeTree(formatTransformationKind(e.kind), [tree])])));
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 getTree(e, () => Effect.map(formatTree(e.issue), tree => makeTree(getParseIssueTitle(e), [makeTree(formatRefinementKind(e.kind), [tree])])));
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 Effect.map(formatTree(e.issue), tree => makeTree(util_.formatPath(e.path), [tree]));
1529
+ return map(formatTree(issue.issue), tree => makeTree(util_.formatPath(issue.path), [tree]));
1533
1530
  case "Composite":
1534
- {
1535
- const parseIssueTitle = getParseIssueTitle(e);
1536
- return getTree(e, () => util_.isNonEmpty(e.issues) ? Effect.map(Effect.forEach(e.issues, formatTree), forest => makeTree(parseIssueTitle, forest)) : Effect.map(formatTree(e.issues), tree => makeTree(parseIssueTitle, [tree])));
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 => formatArray(issue),
1546
- formatIssueSync: issue => Effect.runSync(ArrayFormatter.formatIssue(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 succeedArrayFormatterIssue = issue => Effect.succeed([issue]);
1551
- const getArray = (issue, path, onFailure) => Effect.matchEffect(getMessage(issue), {
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 Effect.map(formatTypeMessage(e), message => [{
1564
- _tag,
1565
- path,
1566
- message
1567
- }]);
1562
+ return map(formatTypeMessage(issue), message => [makeArrayFormatterIssue(_tag, path, message)]);
1568
1563
  case "Forbidden":
1569
- return succeedArrayFormatterIssue({
1570
- _tag,
1571
- path,
1572
- message: formatForbiddenMessage(e)
1573
- });
1564
+ return Either.right([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))]);
1574
1565
  case "Unexpected":
1575
- return succeedArrayFormatterIssue({
1576
- _tag,
1577
- path,
1578
- message: formatUnexpectedMessage(e)
1579
- });
1566
+ return Either.right([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))]);
1580
1567
  case "Missing":
1581
- return Effect.map(formatMissingMessage(e), message => [{
1582
- _tag,
1583
- path,
1584
- message
1585
- }]);
1568
+ return map(formatMissingMessage(issue), message => [makeArrayFormatterIssue(_tag, path, message)]);
1586
1569
  case "Pointer":
1587
- return formatArray(e.issue, path.concat(e.path));
1570
+ return getArrayFormatterIssues(issue.issue, path.concat(issue.path));
1588
1571
  case "Composite":
1589
- return getArray(e, path, () => util_.isNonEmpty(e.issues) ? Effect.map(Effect.forEach(e.issues, issue => formatArray(issue, path)), Arr.flatten) : formatArray(e.issues, path));
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 getArray(e, path, () => formatArray(e.issue, path));
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