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/esm/ParseResult.js
CHANGED
|
@@ -263,56 +263,39 @@ _try as try };
|
|
|
263
263
|
* @since 3.10.0
|
|
264
264
|
*/
|
|
265
265
|
export const fromOption = Either.fromOption;
|
|
266
|
+
const isEither = Either.isEither;
|
|
266
267
|
/**
|
|
267
268
|
* @category optimisation
|
|
268
269
|
* @since 3.10.0
|
|
269
270
|
*/
|
|
270
271
|
export const flatMap = /*#__PURE__*/dual(2, (self, f) => {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
if (s["_tag"] === "Right") {
|
|
276
|
-
return f(s.right);
|
|
277
|
-
}
|
|
278
|
-
return Effect.flatMap(self, f);
|
|
272
|
+
return isEither(self) ? Either.match(self, {
|
|
273
|
+
onLeft: Either.left,
|
|
274
|
+
onRight: f
|
|
275
|
+
}) : Effect.flatMap(self, f);
|
|
279
276
|
});
|
|
280
277
|
/**
|
|
281
278
|
* @category optimisation
|
|
282
279
|
* @since 3.10.0
|
|
283
280
|
*/
|
|
284
281
|
export const map = /*#__PURE__*/dual(2, (self, f) => {
|
|
285
|
-
|
|
286
|
-
if (s["_tag"] === "Left") {
|
|
287
|
-
return s;
|
|
288
|
-
}
|
|
289
|
-
if (s["_tag"] === "Right") {
|
|
290
|
-
return Either.right(f(s.right));
|
|
291
|
-
}
|
|
292
|
-
return Effect.map(self, f);
|
|
282
|
+
return isEither(self) ? Either.map(self, f) : Effect.map(self, f);
|
|
293
283
|
});
|
|
294
284
|
/**
|
|
295
285
|
* @category optimisation
|
|
296
286
|
* @since 3.10.0
|
|
297
287
|
*/
|
|
298
288
|
export const mapError = /*#__PURE__*/dual(2, (self, f) => {
|
|
299
|
-
|
|
300
|
-
if (s["_tag"] === "Left") {
|
|
301
|
-
return Either.left(f(s.left));
|
|
302
|
-
}
|
|
303
|
-
if (s["_tag"] === "Right") {
|
|
304
|
-
return s;
|
|
305
|
-
}
|
|
306
|
-
return Effect.mapError(self, f);
|
|
289
|
+
return isEither(self) ? Either.mapLeft(self, f) : Effect.mapError(self, f);
|
|
307
290
|
});
|
|
291
|
+
// TODO(4.0): remove
|
|
308
292
|
/**
|
|
309
293
|
* @category optimisation
|
|
310
294
|
* @since 3.10.0
|
|
311
295
|
*/
|
|
312
296
|
export const eitherOrUndefined = self => {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return s;
|
|
297
|
+
if (isEither(self)) {
|
|
298
|
+
return self;
|
|
316
299
|
}
|
|
317
300
|
};
|
|
318
301
|
/**
|
|
@@ -320,28 +303,20 @@ export const eitherOrUndefined = self => {
|
|
|
320
303
|
* @since 3.10.0
|
|
321
304
|
*/
|
|
322
305
|
export const mapBoth = /*#__PURE__*/dual(2, (self, options) => {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
if (s["_tag"] === "Right") {
|
|
328
|
-
return Either.right(options.onSuccess(s.right));
|
|
329
|
-
}
|
|
330
|
-
return Effect.mapBoth(self, options);
|
|
306
|
+
return isEither(self) ? Either.mapBoth(self, {
|
|
307
|
+
onLeft: options.onFailure,
|
|
308
|
+
onRight: options.onSuccess
|
|
309
|
+
}) : Effect.mapBoth(self, options);
|
|
331
310
|
});
|
|
332
311
|
/**
|
|
333
312
|
* @category optimisation
|
|
334
313
|
* @since 3.10.0
|
|
335
314
|
*/
|
|
336
315
|
export const orElse = /*#__PURE__*/dual(2, (self, f) => {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
if (s["_tag"] === "Right") {
|
|
342
|
-
return s;
|
|
343
|
-
}
|
|
344
|
-
return Effect.catchAll(self, f);
|
|
316
|
+
return isEither(self) ? Either.match(self, {
|
|
317
|
+
onLeft: f,
|
|
318
|
+
onRight: Either.right
|
|
319
|
+
}) : Effect.catchAll(self, f);
|
|
345
320
|
});
|
|
346
321
|
/** @internal */
|
|
347
322
|
export const mergeInternalOptions = (options, overrideOptions) => {
|
|
@@ -696,11 +671,10 @@ const go = (ast, isDecoding) => {
|
|
|
696
671
|
} else {
|
|
697
672
|
const parser = elements[i];
|
|
698
673
|
const te = parser(input[i], options);
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
if (Either.isLeft(eu)) {
|
|
674
|
+
if (isEither(te)) {
|
|
675
|
+
if (Either.isLeft(te)) {
|
|
702
676
|
// the input element is present but is not valid
|
|
703
|
-
const e = new Pointer(i, input,
|
|
677
|
+
const e = new Pointer(i, input, te.left);
|
|
704
678
|
if (allErrors) {
|
|
705
679
|
es.push([stepKey++, e]);
|
|
706
680
|
continue;
|
|
@@ -708,7 +682,7 @@ const go = (ast, isDecoding) => {
|
|
|
708
682
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)));
|
|
709
683
|
}
|
|
710
684
|
}
|
|
711
|
-
output.push([stepKey++,
|
|
685
|
+
output.push([stepKey++, te.right]);
|
|
712
686
|
} else {
|
|
713
687
|
const nk = stepKey++;
|
|
714
688
|
const index = i;
|
|
@@ -742,10 +716,9 @@ const go = (ast, isDecoding) => {
|
|
|
742
716
|
const [head, ...tail] = rest;
|
|
743
717
|
for (; i < len - tail.length; i++) {
|
|
744
718
|
const te = head(input[i], options);
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
const e = new Pointer(i, input, eu.left);
|
|
719
|
+
if (isEither(te)) {
|
|
720
|
+
if (Either.isLeft(te)) {
|
|
721
|
+
const e = new Pointer(i, input, te.left);
|
|
749
722
|
if (allErrors) {
|
|
750
723
|
es.push([stepKey++, e]);
|
|
751
724
|
continue;
|
|
@@ -753,7 +726,7 @@ const go = (ast, isDecoding) => {
|
|
|
753
726
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)));
|
|
754
727
|
}
|
|
755
728
|
} else {
|
|
756
|
-
output.push([stepKey++,
|
|
729
|
+
output.push([stepKey++, te.right]);
|
|
757
730
|
}
|
|
758
731
|
} else {
|
|
759
732
|
const nk = stepKey++;
|
|
@@ -789,11 +762,10 @@ const go = (ast, isDecoding) => {
|
|
|
789
762
|
continue;
|
|
790
763
|
} else {
|
|
791
764
|
const te = tail[j](input[i], options);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
if (Either.isLeft(eu)) {
|
|
765
|
+
if (isEither(te)) {
|
|
766
|
+
if (Either.isLeft(te)) {
|
|
795
767
|
// the input element is present but is not valid
|
|
796
|
-
const e = new Pointer(i, input,
|
|
768
|
+
const e = new Pointer(i, input, te.left);
|
|
797
769
|
if (allErrors) {
|
|
798
770
|
es.push([stepKey++, e]);
|
|
799
771
|
continue;
|
|
@@ -801,7 +773,7 @@ const go = (ast, isDecoding) => {
|
|
|
801
773
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)));
|
|
802
774
|
}
|
|
803
775
|
}
|
|
804
|
-
output.push([stepKey++,
|
|
776
|
+
output.push([stepKey++, te.right]);
|
|
805
777
|
} else {
|
|
806
778
|
const nk = stepKey++;
|
|
807
779
|
const index = i;
|
|
@@ -891,8 +863,8 @@ const go = (ast, isDecoding) => {
|
|
|
891
863
|
if (onExcessPropertyError || onExcessPropertyPreserve) {
|
|
892
864
|
inputKeys = util_.ownKeys(input);
|
|
893
865
|
for (const key of inputKeys) {
|
|
894
|
-
const
|
|
895
|
-
if (Either.isLeft(
|
|
866
|
+
const te = expected(key, options);
|
|
867
|
+
if (isEither(te) && Either.isLeft(te)) {
|
|
896
868
|
// key is unexpected
|
|
897
869
|
if (onExcessPropertyError) {
|
|
898
870
|
const e = new Pointer(key, input, new Unexpected(input[key], `is unexpected, expected: ${String(expectedAST)}`));
|
|
@@ -930,10 +902,9 @@ const go = (ast, isDecoding) => {
|
|
|
930
902
|
}
|
|
931
903
|
const parser = propertySignatures[i][0];
|
|
932
904
|
const te = parser(input[name], options);
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
const e = new Pointer(name, input, hasKey ? eu.left : new Missing(ps));
|
|
905
|
+
if (isEither(te)) {
|
|
906
|
+
if (Either.isLeft(te)) {
|
|
907
|
+
const e = new Pointer(name, input, hasKey ? te.left : new Missing(ps));
|
|
937
908
|
if (allErrors) {
|
|
938
909
|
es.push([stepKey++, e]);
|
|
939
910
|
continue;
|
|
@@ -941,7 +912,7 @@ const go = (ast, isDecoding) => {
|
|
|
941
912
|
return Either.left(new Composite(ast, input, e, output));
|
|
942
913
|
}
|
|
943
914
|
}
|
|
944
|
-
output[name] =
|
|
915
|
+
output[name] = te.right;
|
|
945
916
|
} else {
|
|
946
917
|
const nk = stepKey++;
|
|
947
918
|
const index = name;
|
|
@@ -978,16 +949,15 @@ const go = (ast, isDecoding) => {
|
|
|
978
949
|
// ---------------------------------------------
|
|
979
950
|
// handle keys
|
|
980
951
|
// ---------------------------------------------
|
|
981
|
-
const keu =
|
|
982
|
-
if (keu && Either.isRight(keu)) {
|
|
952
|
+
const keu = parameter(key, options);
|
|
953
|
+
if (isEither(keu) && Either.isRight(keu)) {
|
|
983
954
|
// ---------------------------------------------
|
|
984
955
|
// handle values
|
|
985
956
|
// ---------------------------------------------
|
|
986
957
|
const vpr = type(input[key], options);
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
const e = new Pointer(key, input, veu.left);
|
|
958
|
+
if (isEither(vpr)) {
|
|
959
|
+
if (Either.isLeft(vpr)) {
|
|
960
|
+
const e = new Pointer(key, input, vpr.left);
|
|
991
961
|
if (allErrors) {
|
|
992
962
|
es.push([stepKey++, e]);
|
|
993
963
|
continue;
|
|
@@ -996,7 +966,7 @@ const go = (ast, isDecoding) => {
|
|
|
996
966
|
}
|
|
997
967
|
} else {
|
|
998
968
|
if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) {
|
|
999
|
-
output[key] =
|
|
969
|
+
output[key] = vpr.right;
|
|
1000
970
|
}
|
|
1001
971
|
}
|
|
1002
972
|
} else {
|
|
@@ -1138,12 +1108,11 @@ const go = (ast, isDecoding) => {
|
|
|
1138
1108
|
// the members of a union are ordered based on which one should be decoded first,
|
|
1139
1109
|
// therefore if one member has added a task, all subsequent members must
|
|
1140
1110
|
// also add a task to the queue even if they are synchronous
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
return eu;
|
|
1111
|
+
if (isEither(pr) && (!queue || queue.length === 0)) {
|
|
1112
|
+
if (Either.isRight(pr)) {
|
|
1113
|
+
return pr;
|
|
1145
1114
|
} else {
|
|
1146
|
-
es.push([stepKey++,
|
|
1115
|
+
es.push([stepKey++, pr.left]);
|
|
1147
1116
|
}
|
|
1148
1117
|
} else {
|
|
1149
1118
|
const nk = stepKey++;
|
|
@@ -1310,11 +1279,9 @@ const handleForbidden = (effect, ast, actual, options) => {
|
|
|
1310
1279
|
if (options?.isEffectAllowed === true) {
|
|
1311
1280
|
return effect;
|
|
1312
1281
|
}
|
|
1313
|
-
// Convert the effect to an Either, if possible
|
|
1314
|
-
const eu = eitherOrUndefined(effect);
|
|
1315
1282
|
// If the effect is already an Either, return it directly
|
|
1316
|
-
if (
|
|
1317
|
-
return
|
|
1283
|
+
if (isEither(effect)) {
|
|
1284
|
+
return effect;
|
|
1318
1285
|
}
|
|
1319
1286
|
// Otherwise, attempt to execute the effect synchronously
|
|
1320
1287
|
const scheduler = new Scheduler.SyncScheduler();
|
|
@@ -1385,8 +1352,11 @@ const makeTree = (value, forest = []) => ({
|
|
|
1385
1352
|
* @since 3.10.0
|
|
1386
1353
|
*/
|
|
1387
1354
|
export const TreeFormatter = {
|
|
1388
|
-
formatIssue: issue =>
|
|
1389
|
-
formatIssueSync: issue =>
|
|
1355
|
+
formatIssue: issue => map(formatTree(issue), drawTree),
|
|
1356
|
+
formatIssueSync: issue => {
|
|
1357
|
+
const e = TreeFormatter.formatIssue(issue);
|
|
1358
|
+
return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e);
|
|
1359
|
+
},
|
|
1390
1360
|
formatError: error => TreeFormatter.formatIssue(error.issue),
|
|
1391
1361
|
formatErrorSync: error => TreeFormatter.formatIssueSync(error.issue)
|
|
1392
1362
|
};
|
|
@@ -1422,21 +1392,35 @@ const formatRefinementKind = kind => {
|
|
|
1422
1392
|
}
|
|
1423
1393
|
};
|
|
1424
1394
|
const getAnnotated = issue => "ast" in issue ? Option.some(issue.ast) : Option.none();
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1395
|
+
// TODO: replace with Either.void when 3.13 lands
|
|
1396
|
+
const Either_void = /*#__PURE__*/Either.right(undefined);
|
|
1397
|
+
const getCurrentMessage = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getMessageAnnotation), Option.match({
|
|
1398
|
+
onNone: () => Either_void,
|
|
1399
|
+
onSome: messageAnnotation => {
|
|
1400
|
+
const union = messageAnnotation(issue);
|
|
1401
|
+
if (Predicate.isString(union)) {
|
|
1402
|
+
return Either.right({
|
|
1403
|
+
message: union,
|
|
1404
|
+
override: false
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
if (Effect.isEffect(union)) {
|
|
1408
|
+
return Effect.map(union, message => ({
|
|
1409
|
+
message,
|
|
1410
|
+
override: false
|
|
1411
|
+
}));
|
|
1412
|
+
}
|
|
1413
|
+
if (Predicate.isString(union.message)) {
|
|
1414
|
+
return Either.right({
|
|
1415
|
+
message: union.message,
|
|
1416
|
+
override: union.override
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
return Effect.map(union.message, message => ({
|
|
1420
|
+
message,
|
|
1421
|
+
override: union.override
|
|
1422
|
+
}));
|
|
1423
|
+
}
|
|
1440
1424
|
}));
|
|
1441
1425
|
const createParseIssueGuard = tag => issue => issue._tag === tag;
|
|
1442
1426
|
/**
|
|
@@ -1448,110 +1432,119 @@ const createParseIssueGuard = tag => issue => issue._tag === tag;
|
|
|
1448
1432
|
export const isComposite = /*#__PURE__*/createParseIssueGuard("Composite");
|
|
1449
1433
|
const isRefinement = /*#__PURE__*/createParseIssueGuard("Refinement");
|
|
1450
1434
|
const isTransformation = /*#__PURE__*/createParseIssueGuard("Transformation");
|
|
1451
|
-
const getMessage = issue => getCurrentMessage(issue)
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1435
|
+
const getMessage = issue => flatMap(getCurrentMessage(issue), currentMessage => {
|
|
1436
|
+
if (currentMessage !== undefined) {
|
|
1437
|
+
const useInnerMessage = !currentMessage.override && (isComposite(issue) || isRefinement(issue) && issue.kind === "From" || isTransformation(issue) && issue.kind !== "Transformation");
|
|
1438
|
+
return useInnerMessage ? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Either_void : Either.right(currentMessage.message);
|
|
1439
|
+
}
|
|
1440
|
+
return Either_void;
|
|
1441
|
+
});
|
|
1442
|
+
const getParseIssueTitleAnnotation = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getParseIssueTitleAnnotation), Option.filterMap(annotation => Option.fromNullable(annotation(issue))), Option.getOrUndefined);
|
|
1456
1443
|
/** @internal */
|
|
1457
1444
|
export function getRefinementExpected(ast) {
|
|
1458
1445
|
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 }`));
|
|
1459
1446
|
}
|
|
1460
|
-
function getDefaultTypeMessage(
|
|
1461
|
-
if (
|
|
1462
|
-
return
|
|
1447
|
+
function getDefaultTypeMessage(issue) {
|
|
1448
|
+
if (issue.message !== undefined) {
|
|
1449
|
+
return issue.message;
|
|
1463
1450
|
}
|
|
1464
|
-
const expected = AST.isRefinement(
|
|
1465
|
-
return `Expected ${expected}, actual ${util_.formatUnknown(
|
|
1451
|
+
const expected = AST.isRefinement(issue.ast) ? getRefinementExpected(issue.ast) : String(issue.ast);
|
|
1452
|
+
return `Expected ${expected}, actual ${util_.formatUnknown(issue.actual)}`;
|
|
1466
1453
|
}
|
|
1467
|
-
const formatTypeMessage =
|
|
1468
|
-
const getParseIssueTitle = issue =>
|
|
1469
|
-
const formatForbiddenMessage =
|
|
1470
|
-
const formatUnexpectedMessage =
|
|
1471
|
-
const formatMissingMessage =
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
}
|
|
1479
|
-
const formatTree =
|
|
1480
|
-
switch (
|
|
1454
|
+
const formatTypeMessage = issue => map(getMessage(issue), message => message ?? getParseIssueTitleAnnotation(issue) ?? getDefaultTypeMessage(issue));
|
|
1455
|
+
const getParseIssueTitle = issue => getParseIssueTitleAnnotation(issue) ?? String(issue.ast);
|
|
1456
|
+
const formatForbiddenMessage = issue => issue.message ?? "is forbidden";
|
|
1457
|
+
const formatUnexpectedMessage = issue => issue.message ?? "is unexpected";
|
|
1458
|
+
const formatMissingMessage = issue => {
|
|
1459
|
+
const missingMessageAnnotation = AST.getMissingMessageAnnotation(issue.ast);
|
|
1460
|
+
if (Option.isSome(missingMessageAnnotation)) {
|
|
1461
|
+
const annotation = missingMessageAnnotation.value();
|
|
1462
|
+
return Predicate.isString(annotation) ? Either.right(annotation) : annotation;
|
|
1463
|
+
}
|
|
1464
|
+
return Either.right(issue.message ?? "is missing");
|
|
1465
|
+
};
|
|
1466
|
+
const formatTree = issue => {
|
|
1467
|
+
switch (issue._tag) {
|
|
1481
1468
|
case "Type":
|
|
1482
|
-
return
|
|
1469
|
+
return map(formatTypeMessage(issue), makeTree);
|
|
1483
1470
|
case "Forbidden":
|
|
1484
|
-
return
|
|
1471
|
+
return Either.right(makeTree(getParseIssueTitle(issue), [makeTree(formatForbiddenMessage(issue))]));
|
|
1485
1472
|
case "Unexpected":
|
|
1486
|
-
return
|
|
1473
|
+
return Either.right(makeTree(formatUnexpectedMessage(issue)));
|
|
1487
1474
|
case "Missing":
|
|
1488
|
-
return
|
|
1475
|
+
return map(formatMissingMessage(issue), makeTree);
|
|
1489
1476
|
case "Transformation":
|
|
1490
|
-
return
|
|
1477
|
+
return flatMap(getMessage(issue), message => {
|
|
1478
|
+
if (message !== undefined) {
|
|
1479
|
+
return Either.right(makeTree(message));
|
|
1480
|
+
}
|
|
1481
|
+
return map(formatTree(issue.issue), tree => makeTree(getParseIssueTitle(issue), [makeTree(formatTransformationKind(issue.kind), [tree])]));
|
|
1482
|
+
});
|
|
1491
1483
|
case "Refinement":
|
|
1492
|
-
return
|
|
1484
|
+
return flatMap(getMessage(issue), message => {
|
|
1485
|
+
if (message !== undefined) {
|
|
1486
|
+
return Either.right(makeTree(message));
|
|
1487
|
+
}
|
|
1488
|
+
return map(formatTree(issue.issue), tree => makeTree(getParseIssueTitle(issue), [makeTree(formatRefinementKind(issue.kind), [tree])]));
|
|
1489
|
+
});
|
|
1493
1490
|
case "Pointer":
|
|
1494
|
-
return
|
|
1491
|
+
return map(formatTree(issue.issue), tree => makeTree(util_.formatPath(issue.path), [tree]));
|
|
1495
1492
|
case "Composite":
|
|
1496
|
-
{
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1493
|
+
return flatMap(getMessage(issue), message => {
|
|
1494
|
+
if (message !== undefined) {
|
|
1495
|
+
return Either.right(makeTree(message));
|
|
1496
|
+
}
|
|
1497
|
+
const parseIssueTitle = getParseIssueTitle(issue);
|
|
1498
|
+
return util_.isNonEmpty(issue.issues) ? map(Effect.forEach(issue.issues, formatTree), forest => makeTree(parseIssueTitle, forest)) : map(formatTree(issue.issues), tree => makeTree(parseIssueTitle, [tree]));
|
|
1499
|
+
});
|
|
1500
1500
|
}
|
|
1501
1501
|
};
|
|
1502
|
+
const makeArrayFormatterIssue = (_tag, path, message) => ({
|
|
1503
|
+
_tag,
|
|
1504
|
+
path,
|
|
1505
|
+
message
|
|
1506
|
+
});
|
|
1502
1507
|
/**
|
|
1503
1508
|
* @category formatting
|
|
1504
1509
|
* @since 3.10.0
|
|
1505
1510
|
*/
|
|
1506
1511
|
export const ArrayFormatter = {
|
|
1507
|
-
formatIssue: issue =>
|
|
1508
|
-
formatIssueSync: issue =>
|
|
1512
|
+
formatIssue: issue => getArrayFormatterIssues(issue),
|
|
1513
|
+
formatIssueSync: issue => {
|
|
1514
|
+
const e = ArrayFormatter.formatIssue(issue);
|
|
1515
|
+
return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e);
|
|
1516
|
+
},
|
|
1509
1517
|
formatError: error => ArrayFormatter.formatIssue(error.issue),
|
|
1510
1518
|
formatErrorSync: error => ArrayFormatter.formatIssueSync(error.issue)
|
|
1511
1519
|
};
|
|
1512
|
-
const
|
|
1513
|
-
const
|
|
1514
|
-
onFailure,
|
|
1515
|
-
onSuccess: message => succeedArrayFormatterIssue({
|
|
1516
|
-
_tag: issue._tag,
|
|
1517
|
-
path,
|
|
1518
|
-
message
|
|
1519
|
-
})
|
|
1520
|
-
});
|
|
1521
|
-
const formatArray = (e, path = []) => {
|
|
1522
|
-
const _tag = e._tag;
|
|
1520
|
+
const getArrayFormatterIssues = (issue, path = []) => {
|
|
1521
|
+
const _tag = issue._tag;
|
|
1523
1522
|
switch (_tag) {
|
|
1524
1523
|
case "Type":
|
|
1525
|
-
return
|
|
1526
|
-
_tag,
|
|
1527
|
-
path,
|
|
1528
|
-
message
|
|
1529
|
-
}]);
|
|
1524
|
+
return map(formatTypeMessage(issue), message => [makeArrayFormatterIssue(_tag, path, message)]);
|
|
1530
1525
|
case "Forbidden":
|
|
1531
|
-
return
|
|
1532
|
-
_tag,
|
|
1533
|
-
path,
|
|
1534
|
-
message: formatForbiddenMessage(e)
|
|
1535
|
-
});
|
|
1526
|
+
return Either.right([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))]);
|
|
1536
1527
|
case "Unexpected":
|
|
1537
|
-
return
|
|
1538
|
-
_tag,
|
|
1539
|
-
path,
|
|
1540
|
-
message: formatUnexpectedMessage(e)
|
|
1541
|
-
});
|
|
1528
|
+
return Either.right([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))]);
|
|
1542
1529
|
case "Missing":
|
|
1543
|
-
return
|
|
1544
|
-
_tag,
|
|
1545
|
-
path,
|
|
1546
|
-
message
|
|
1547
|
-
}]);
|
|
1530
|
+
return map(formatMissingMessage(issue), message => [makeArrayFormatterIssue(_tag, path, message)]);
|
|
1548
1531
|
case "Pointer":
|
|
1549
|
-
return
|
|
1532
|
+
return getArrayFormatterIssues(issue.issue, path.concat(issue.path));
|
|
1550
1533
|
case "Composite":
|
|
1551
|
-
return
|
|
1534
|
+
return flatMap(getMessage(issue), message => {
|
|
1535
|
+
if (message !== undefined) {
|
|
1536
|
+
return Either.right([makeArrayFormatterIssue(issue._tag, path, message)]);
|
|
1537
|
+
}
|
|
1538
|
+
return util_.isNonEmpty(issue.issues) ? map(Effect.forEach(issue.issues, issue => getArrayFormatterIssues(issue, path)), Arr.flatten) : getArrayFormatterIssues(issue.issues, path);
|
|
1539
|
+
});
|
|
1552
1540
|
case "Refinement":
|
|
1553
1541
|
case "Transformation":
|
|
1554
|
-
return
|
|
1542
|
+
return flatMap(getMessage(issue), message => {
|
|
1543
|
+
if (message !== undefined) {
|
|
1544
|
+
return Either.right([makeArrayFormatterIssue(issue._tag, path, message)]);
|
|
1545
|
+
}
|
|
1546
|
+
return getArrayFormatterIssues(issue.issue, path);
|
|
1547
|
+
});
|
|
1555
1548
|
}
|
|
1556
1549
|
};
|
|
1557
1550
|
//# sourceMappingURL=ParseResult.js.map
|