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/src/ParseResult.ts
CHANGED
|
@@ -307,6 +307,8 @@ export const fromOption: {
|
|
|
307
307
|
<A>(self: Option.Option<A>, onNone: () => ParseIssue): Either.Either<A, ParseIssue>
|
|
308
308
|
} = Either.fromOption
|
|
309
309
|
|
|
310
|
+
const isEither: <A, E, R>(self: Effect.Effect<A, E, R>) => self is Either.Either<A, E> = Either.isEither as any
|
|
311
|
+
|
|
310
312
|
/**
|
|
311
313
|
* @category optimisation
|
|
312
314
|
* @since 3.10.0
|
|
@@ -331,14 +333,9 @@ export const flatMap: {
|
|
|
331
333
|
self: Effect.Effect<A, E, R>,
|
|
332
334
|
f: (a: A) => Effect.Effect<B, E1, R1>
|
|
333
335
|
): Effect.Effect<B, E | E1, R | R1> => {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
if (s["_tag"] === "Right") {
|
|
339
|
-
return f(s.right)
|
|
340
|
-
}
|
|
341
|
-
return Effect.flatMap(self, f)
|
|
336
|
+
return isEither(self) ?
|
|
337
|
+
Either.match(self, { onLeft: Either.left, onRight: f }) :
|
|
338
|
+
Effect.flatMap(self, f)
|
|
342
339
|
})
|
|
343
340
|
|
|
344
341
|
/**
|
|
@@ -357,14 +354,9 @@ export const map: {
|
|
|
357
354
|
*/
|
|
358
355
|
<A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R>
|
|
359
356
|
} = dual(2, <A, E, R, B>(self: Effect.Effect<A, E, R>, f: (a: A) => B): Effect.Effect<B, E, R> => {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
if (s["_tag"] === "Right") {
|
|
365
|
-
return Either.right(f(s.right))
|
|
366
|
-
}
|
|
367
|
-
return Effect.map(self, f)
|
|
357
|
+
return isEither(self) ?
|
|
358
|
+
Either.map(self, f) :
|
|
359
|
+
Effect.map(self, f)
|
|
368
360
|
})
|
|
369
361
|
|
|
370
362
|
/**
|
|
@@ -383,16 +375,12 @@ export const mapError: {
|
|
|
383
375
|
*/
|
|
384
376
|
<A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R>
|
|
385
377
|
} = dual(2, <A, E, R, E2>(self: Effect.Effect<A, E, R>, f: (e: E) => E2): Effect.Effect<A, E2, R> => {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
}
|
|
390
|
-
if (s["_tag"] === "Right") {
|
|
391
|
-
return s
|
|
392
|
-
}
|
|
393
|
-
return Effect.mapError(self, f)
|
|
378
|
+
return isEither(self) ?
|
|
379
|
+
Either.mapLeft(self, f) :
|
|
380
|
+
Effect.mapError(self, f)
|
|
394
381
|
})
|
|
395
382
|
|
|
383
|
+
// TODO(4.0): remove
|
|
396
384
|
/**
|
|
397
385
|
* @category optimisation
|
|
398
386
|
* @since 3.10.0
|
|
@@ -400,9 +388,8 @@ export const mapError: {
|
|
|
400
388
|
export const eitherOrUndefined = <A, E, R>(
|
|
401
389
|
self: Effect.Effect<A, E, R>
|
|
402
390
|
): Either.Either<A, E> | undefined => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
return s
|
|
391
|
+
if (isEither(self)) {
|
|
392
|
+
return self
|
|
406
393
|
}
|
|
407
394
|
}
|
|
408
395
|
|
|
@@ -430,14 +417,9 @@ export const mapBoth: {
|
|
|
430
417
|
self: Effect.Effect<A, E, R>,
|
|
431
418
|
options: { readonly onFailure: (e: E) => E2; readonly onSuccess: (a: A) => A2 }
|
|
432
419
|
): Effect.Effect<A2, E2, R> => {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
if (s["_tag"] === "Right") {
|
|
438
|
-
return Either.right(options.onSuccess(s.right))
|
|
439
|
-
}
|
|
440
|
-
return Effect.mapBoth(self, options)
|
|
420
|
+
return isEither(self) ?
|
|
421
|
+
Either.mapBoth(self, { onLeft: options.onFailure, onRight: options.onSuccess }) :
|
|
422
|
+
Effect.mapBoth(self, options)
|
|
441
423
|
})
|
|
442
424
|
|
|
443
425
|
/**
|
|
@@ -464,14 +446,9 @@ export const orElse: {
|
|
|
464
446
|
self: Effect.Effect<A, E, R>,
|
|
465
447
|
f: (e: E) => Effect.Effect<A2, E2, R2>
|
|
466
448
|
): Effect.Effect<A2 | A, E2, R2 | R> => {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
if (s["_tag"] === "Right") {
|
|
472
|
-
return s
|
|
473
|
-
}
|
|
474
|
-
return Effect.catchAll(self, f)
|
|
449
|
+
return isEither(self) ?
|
|
450
|
+
Either.match(self, { onLeft: f, onRight: Either.right }) :
|
|
451
|
+
Effect.catchAll(self, f)
|
|
475
452
|
})
|
|
476
453
|
|
|
477
454
|
/**
|
|
@@ -1018,11 +995,10 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1018
995
|
} else {
|
|
1019
996
|
const parser = elements[i]
|
|
1020
997
|
const te = parser(input[i], options)
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
if (Either.isLeft(eu)) {
|
|
998
|
+
if (isEither(te)) {
|
|
999
|
+
if (Either.isLeft(te)) {
|
|
1024
1000
|
// the input element is present but is not valid
|
|
1025
|
-
const e = new Pointer(i, input,
|
|
1001
|
+
const e = new Pointer(i, input, te.left)
|
|
1026
1002
|
if (allErrors) {
|
|
1027
1003
|
es.push([stepKey++, e])
|
|
1028
1004
|
continue
|
|
@@ -1030,7 +1006,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1030
1006
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)))
|
|
1031
1007
|
}
|
|
1032
1008
|
}
|
|
1033
|
-
output.push([stepKey++,
|
|
1009
|
+
output.push([stepKey++, te.right])
|
|
1034
1010
|
} else {
|
|
1035
1011
|
const nk = stepKey++
|
|
1036
1012
|
const index = i
|
|
@@ -1063,10 +1039,9 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1063
1039
|
const [head, ...tail] = rest
|
|
1064
1040
|
for (; i < len - tail.length; i++) {
|
|
1065
1041
|
const te = head(input[i], options)
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
const e = new Pointer(i, input, eu.left)
|
|
1042
|
+
if (isEither(te)) {
|
|
1043
|
+
if (Either.isLeft(te)) {
|
|
1044
|
+
const e = new Pointer(i, input, te.left)
|
|
1070
1045
|
if (allErrors) {
|
|
1071
1046
|
es.push([stepKey++, e])
|
|
1072
1047
|
continue
|
|
@@ -1074,7 +1049,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1074
1049
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)))
|
|
1075
1050
|
}
|
|
1076
1051
|
} else {
|
|
1077
|
-
output.push([stepKey++,
|
|
1052
|
+
output.push([stepKey++, te.right])
|
|
1078
1053
|
}
|
|
1079
1054
|
} else {
|
|
1080
1055
|
const nk = stepKey++
|
|
@@ -1110,11 +1085,10 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1110
1085
|
continue
|
|
1111
1086
|
} else {
|
|
1112
1087
|
const te = tail[j](input[i], options)
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
if (Either.isLeft(eu)) {
|
|
1088
|
+
if (isEither(te)) {
|
|
1089
|
+
if (Either.isLeft(te)) {
|
|
1116
1090
|
// the input element is present but is not valid
|
|
1117
|
-
const e = new Pointer(i, input,
|
|
1091
|
+
const e = new Pointer(i, input, te.left)
|
|
1118
1092
|
if (allErrors) {
|
|
1119
1093
|
es.push([stepKey++, e])
|
|
1120
1094
|
continue
|
|
@@ -1122,7 +1096,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1122
1096
|
return Either.left(new Composite(ast, input, e, sortByIndex(output)))
|
|
1123
1097
|
}
|
|
1124
1098
|
}
|
|
1125
|
-
output.push([stepKey++,
|
|
1099
|
+
output.push([stepKey++, te.right])
|
|
1126
1100
|
} else {
|
|
1127
1101
|
const nk = stepKey++
|
|
1128
1102
|
const index = i
|
|
@@ -1221,8 +1195,8 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1221
1195
|
if (onExcessPropertyError || onExcessPropertyPreserve) {
|
|
1222
1196
|
inputKeys = util_.ownKeys(input)
|
|
1223
1197
|
for (const key of inputKeys) {
|
|
1224
|
-
const
|
|
1225
|
-
if (Either.isLeft(
|
|
1198
|
+
const te = expected(key, options)
|
|
1199
|
+
if (isEither(te) && Either.isLeft(te)) {
|
|
1226
1200
|
// key is unexpected
|
|
1227
1201
|
if (onExcessPropertyError) {
|
|
1228
1202
|
const e = new Pointer(
|
|
@@ -1275,10 +1249,9 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1275
1249
|
}
|
|
1276
1250
|
const parser = propertySignatures[i][0]
|
|
1277
1251
|
const te = parser(input[name], options)
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
const e = new Pointer(name, input, hasKey ? eu.left : new Missing(ps))
|
|
1252
|
+
if (isEither(te)) {
|
|
1253
|
+
if (Either.isLeft(te)) {
|
|
1254
|
+
const e = new Pointer(name, input, hasKey ? te.left : new Missing(ps))
|
|
1282
1255
|
if (allErrors) {
|
|
1283
1256
|
es.push([stepKey++, e])
|
|
1284
1257
|
continue
|
|
@@ -1286,7 +1259,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1286
1259
|
return Either.left(new Composite(ast, input, e, output))
|
|
1287
1260
|
}
|
|
1288
1261
|
}
|
|
1289
|
-
output[name] =
|
|
1262
|
+
output[name] = te.right
|
|
1290
1263
|
} else {
|
|
1291
1264
|
const nk = stepKey++
|
|
1292
1265
|
const index = name
|
|
@@ -1324,16 +1297,15 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1324
1297
|
// ---------------------------------------------
|
|
1325
1298
|
// handle keys
|
|
1326
1299
|
// ---------------------------------------------
|
|
1327
|
-
const keu =
|
|
1328
|
-
if (keu && Either.isRight(keu)) {
|
|
1300
|
+
const keu = parameter(key, options)
|
|
1301
|
+
if (isEither(keu) && Either.isRight(keu)) {
|
|
1329
1302
|
// ---------------------------------------------
|
|
1330
1303
|
// handle values
|
|
1331
1304
|
// ---------------------------------------------
|
|
1332
1305
|
const vpr = type(input[key], options)
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
const e = new Pointer(key, input, veu.left)
|
|
1306
|
+
if (isEither(vpr)) {
|
|
1307
|
+
if (Either.isLeft(vpr)) {
|
|
1308
|
+
const e = new Pointer(key, input, vpr.left)
|
|
1337
1309
|
if (allErrors) {
|
|
1338
1310
|
es.push([stepKey++, e])
|
|
1339
1311
|
continue
|
|
@@ -1342,7 +1314,7 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1342
1314
|
}
|
|
1343
1315
|
} else {
|
|
1344
1316
|
if (!Object.prototype.hasOwnProperty.call(expectedKeysMap, key)) {
|
|
1345
|
-
output[key] =
|
|
1317
|
+
output[key] = vpr.right
|
|
1346
1318
|
}
|
|
1347
1319
|
}
|
|
1348
1320
|
} else {
|
|
@@ -1494,12 +1466,11 @@ const go = (ast: AST.AST, isDecoding: boolean): Parser => {
|
|
|
1494
1466
|
// the members of a union are ordered based on which one should be decoded first,
|
|
1495
1467
|
// therefore if one member has added a task, all subsequent members must
|
|
1496
1468
|
// also add a task to the queue even if they are synchronous
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
return eu
|
|
1469
|
+
if (isEither(pr) && (!queue || queue.length === 0)) {
|
|
1470
|
+
if (Either.isRight(pr)) {
|
|
1471
|
+
return pr
|
|
1501
1472
|
} else {
|
|
1502
|
-
es.push([stepKey++,
|
|
1473
|
+
es.push([stepKey++, pr.left])
|
|
1503
1474
|
}
|
|
1504
1475
|
} else {
|
|
1505
1476
|
const nk = stepKey++
|
|
@@ -1694,11 +1665,9 @@ const handleForbidden = <A, R>(
|
|
|
1694
1665
|
return effect
|
|
1695
1666
|
}
|
|
1696
1667
|
|
|
1697
|
-
// Convert the effect to an Either, if possible
|
|
1698
|
-
const eu = eitherOrUndefined(effect)
|
|
1699
1668
|
// If the effect is already an Either, return it directly
|
|
1700
|
-
if (
|
|
1701
|
-
return
|
|
1669
|
+
if (isEither(effect)) {
|
|
1670
|
+
return effect
|
|
1702
1671
|
}
|
|
1703
1672
|
|
|
1704
1673
|
// Otherwise, attempt to execute the effect synchronously
|
|
@@ -1823,8 +1792,11 @@ export interface ParseResultFormatter<A> {
|
|
|
1823
1792
|
* @since 3.10.0
|
|
1824
1793
|
*/
|
|
1825
1794
|
export const TreeFormatter: ParseResultFormatter<string> = {
|
|
1826
|
-
formatIssue: (issue) =>
|
|
1827
|
-
formatIssueSync: (issue) =>
|
|
1795
|
+
formatIssue: (issue) => map(formatTree(issue), drawTree),
|
|
1796
|
+
formatIssueSync: (issue) => {
|
|
1797
|
+
const e = TreeFormatter.formatIssue(issue)
|
|
1798
|
+
return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e)
|
|
1799
|
+
},
|
|
1828
1800
|
formatError: (error) => TreeFormatter.formatIssue(error.issue),
|
|
1829
1801
|
formatErrorSync: (error) => TreeFormatter.formatIssueSync(error.issue)
|
|
1830
1802
|
}
|
|
@@ -1872,20 +1844,27 @@ interface CurrentMessage {
|
|
|
1872
1844
|
readonly override: boolean
|
|
1873
1845
|
}
|
|
1874
1846
|
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1847
|
+
// TODO: replace with Either.void when 3.13 lands
|
|
1848
|
+
const Either_void = Either.right(undefined)
|
|
1849
|
+
|
|
1850
|
+
const getCurrentMessage = (issue: ParseIssue): Effect.Effect<CurrentMessage | undefined> =>
|
|
1878
1851
|
getAnnotated(issue).pipe(
|
|
1879
1852
|
Option.flatMap(AST.getMessageAnnotation),
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1853
|
+
Option.match({
|
|
1854
|
+
onNone: () => Either_void,
|
|
1855
|
+
onSome: (messageAnnotation) => {
|
|
1856
|
+
const union = messageAnnotation(issue)
|
|
1857
|
+
if (Predicate.isString(union)) {
|
|
1858
|
+
return Either.right({ message: union, override: false })
|
|
1859
|
+
}
|
|
1860
|
+
if (Effect.isEffect(union)) {
|
|
1861
|
+
return Effect.map(union, (message) => ({ message, override: false }))
|
|
1862
|
+
}
|
|
1863
|
+
if (Predicate.isString(union.message)) {
|
|
1864
|
+
return Either.right({ message: union.message, override: union.override })
|
|
1865
|
+
}
|
|
1866
|
+
return Effect.map(union.message, (message) => ({ message, override: union.override }))
|
|
1867
|
+
}
|
|
1889
1868
|
})
|
|
1890
1869
|
)
|
|
1891
1870
|
|
|
@@ -1904,28 +1883,28 @@ export const isComposite = createParseIssueGuard("Composite")
|
|
|
1904
1883
|
const isRefinement = createParseIssueGuard("Refinement")
|
|
1905
1884
|
const isTransformation = createParseIssueGuard("Transformation")
|
|
1906
1885
|
|
|
1907
|
-
const getMessage:
|
|
1908
|
-
issue
|
|
1909
|
-
|
|
1910
|
-
getCurrentMessage(issue).pipe(
|
|
1911
|
-
Effect.flatMap((currentMessage) => {
|
|
1886
|
+
const getMessage = (issue: ParseIssue): Effect.Effect<string | undefined> =>
|
|
1887
|
+
flatMap(getCurrentMessage(issue), (currentMessage) => {
|
|
1888
|
+
if (currentMessage !== undefined) {
|
|
1912
1889
|
const useInnerMessage = !currentMessage.override && (
|
|
1913
1890
|
isComposite(issue) ||
|
|
1914
1891
|
(isRefinement(issue) && issue.kind === "From") ||
|
|
1915
1892
|
(isTransformation(issue) && issue.kind !== "Transformation")
|
|
1916
1893
|
)
|
|
1917
1894
|
return useInnerMessage
|
|
1918
|
-
? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) :
|
|
1919
|
-
:
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1895
|
+
? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Either_void
|
|
1896
|
+
: Either.right(currentMessage.message)
|
|
1897
|
+
}
|
|
1898
|
+
return Either_void
|
|
1899
|
+
})
|
|
1922
1900
|
|
|
1923
|
-
const getParseIssueTitleAnnotation = (issue: ParseIssue):
|
|
1901
|
+
const getParseIssueTitleAnnotation = (issue: ParseIssue): string | undefined =>
|
|
1924
1902
|
getAnnotated(issue).pipe(
|
|
1925
1903
|
Option.flatMap(AST.getParseIssueTitleAnnotation),
|
|
1926
1904
|
Option.filterMap(
|
|
1927
1905
|
(annotation) => Option.fromNullable(annotation(issue))
|
|
1928
|
-
)
|
|
1906
|
+
),
|
|
1907
|
+
Option.getOrUndefined
|
|
1929
1908
|
)
|
|
1930
1909
|
|
|
1931
1910
|
/** @internal */
|
|
@@ -1938,82 +1917,79 @@ export function getRefinementExpected(ast: AST.Refinement): string {
|
|
|
1938
1917
|
)
|
|
1939
1918
|
}
|
|
1940
1919
|
|
|
1941
|
-
function getDefaultTypeMessage(
|
|
1942
|
-
if (
|
|
1943
|
-
return
|
|
1920
|
+
function getDefaultTypeMessage(issue: Type): string {
|
|
1921
|
+
if (issue.message !== undefined) {
|
|
1922
|
+
return issue.message
|
|
1944
1923
|
}
|
|
1945
|
-
const expected = AST.isRefinement(
|
|
1946
|
-
return `Expected ${expected}, actual ${util_.formatUnknown(
|
|
1924
|
+
const expected = AST.isRefinement(issue.ast) ? getRefinementExpected(issue.ast) : String(issue.ast)
|
|
1925
|
+
return `Expected ${expected}, actual ${util_.formatUnknown(issue.actual)}`
|
|
1947
1926
|
}
|
|
1948
1927
|
|
|
1949
|
-
const formatTypeMessage = (
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1928
|
+
const formatTypeMessage = (issue: Type): Effect.Effect<string> =>
|
|
1929
|
+
map(
|
|
1930
|
+
getMessage(issue),
|
|
1931
|
+
(message) => message ?? getParseIssueTitleAnnotation(issue) ?? getDefaultTypeMessage(issue)
|
|
1953
1932
|
)
|
|
1954
1933
|
|
|
1955
1934
|
const getParseIssueTitle = (
|
|
1956
1935
|
issue: Forbidden | Transformation | Refinement | Composite
|
|
1957
|
-
): string =>
|
|
1936
|
+
): string => getParseIssueTitleAnnotation(issue) ?? String(issue.ast)
|
|
1958
1937
|
|
|
1959
|
-
const formatForbiddenMessage = (
|
|
1938
|
+
const formatForbiddenMessage = (issue: Forbidden): string => issue.message ?? "is forbidden"
|
|
1960
1939
|
|
|
1961
|
-
const formatUnexpectedMessage = (
|
|
1940
|
+
const formatUnexpectedMessage = (issue: Unexpected): string => issue.message ?? "is unexpected"
|
|
1962
1941
|
|
|
1963
|
-
const formatMissingMessage = (
|
|
1964
|
-
AST.getMissingMessageAnnotation(
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
const getTree = (issue: ParseIssue, onFailure: () => Effect.Effect<Tree<string>>) =>
|
|
1973
|
-
Effect.matchEffect(getMessage(issue), {
|
|
1974
|
-
onFailure,
|
|
1975
|
-
onSuccess: (message) => Effect.succeed(makeTree(message))
|
|
1976
|
-
})
|
|
1942
|
+
const formatMissingMessage = (issue: Missing): Effect.Effect<string> => {
|
|
1943
|
+
const missingMessageAnnotation = AST.getMissingMessageAnnotation(issue.ast)
|
|
1944
|
+
if (Option.isSome(missingMessageAnnotation)) {
|
|
1945
|
+
const annotation = missingMessageAnnotation.value()
|
|
1946
|
+
return Predicate.isString(annotation) ? Either.right(annotation) : annotation
|
|
1947
|
+
}
|
|
1948
|
+
return Either.right(issue.message ?? "is missing")
|
|
1949
|
+
}
|
|
1977
1950
|
|
|
1978
|
-
const formatTree = (
|
|
1979
|
-
|
|
1980
|
-
): Effect.Effect<Tree<string>> => {
|
|
1981
|
-
switch (e._tag) {
|
|
1951
|
+
const formatTree = (issue: ParseIssue): Effect.Effect<Tree<string>> => {
|
|
1952
|
+
switch (issue._tag) {
|
|
1982
1953
|
case "Type":
|
|
1983
|
-
return
|
|
1954
|
+
return map(formatTypeMessage(issue), makeTree)
|
|
1984
1955
|
case "Forbidden":
|
|
1985
|
-
return
|
|
1956
|
+
return Either.right(makeTree(getParseIssueTitle(issue), [makeTree(formatForbiddenMessage(issue))]))
|
|
1986
1957
|
case "Unexpected":
|
|
1987
|
-
return
|
|
1958
|
+
return Either.right(makeTree(formatUnexpectedMessage(issue)))
|
|
1988
1959
|
case "Missing":
|
|
1989
|
-
return
|
|
1960
|
+
return map(formatMissingMessage(issue), makeTree)
|
|
1990
1961
|
case "Transformation":
|
|
1991
|
-
return
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1962
|
+
return flatMap(getMessage(issue), (message) => {
|
|
1963
|
+
if (message !== undefined) {
|
|
1964
|
+
return Either.right(makeTree(message))
|
|
1965
|
+
}
|
|
1966
|
+
return map(
|
|
1967
|
+
formatTree(issue.issue),
|
|
1968
|
+
(tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatTransformationKind(issue.kind), [tree])])
|
|
1969
|
+
)
|
|
1970
|
+
})
|
|
1996
1971
|
case "Refinement":
|
|
1997
|
-
return
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
)
|
|
2004
|
-
|
|
1972
|
+
return flatMap(getMessage(issue), (message) => {
|
|
1973
|
+
if (message !== undefined) {
|
|
1974
|
+
return Either.right(makeTree(message))
|
|
1975
|
+
}
|
|
1976
|
+
return map(
|
|
1977
|
+
formatTree(issue.issue),
|
|
1978
|
+
(tree) => makeTree(getParseIssueTitle(issue), [makeTree(formatRefinementKind(issue.kind), [tree])])
|
|
1979
|
+
)
|
|
1980
|
+
})
|
|
2005
1981
|
case "Pointer":
|
|
2006
|
-
return
|
|
2007
|
-
case "Composite":
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
1982
|
+
return map(formatTree(issue.issue), (tree) => makeTree(util_.formatPath(issue.path), [tree]))
|
|
1983
|
+
case "Composite":
|
|
1984
|
+
return flatMap(getMessage(issue), (message) => {
|
|
1985
|
+
if (message !== undefined) {
|
|
1986
|
+
return Either.right(makeTree(message))
|
|
1987
|
+
}
|
|
1988
|
+
const parseIssueTitle = getParseIssueTitle(issue)
|
|
1989
|
+
return util_.isNonEmpty(issue.issues)
|
|
1990
|
+
? map(Effect.forEach(issue.issues, formatTree), (forest) => makeTree(parseIssueTitle, forest))
|
|
1991
|
+
: map(formatTree(issue.issues), (tree) => makeTree(parseIssueTitle, [tree]))
|
|
1992
|
+
})
|
|
2017
1993
|
}
|
|
2018
1994
|
}
|
|
2019
1995
|
|
|
@@ -2040,52 +2016,58 @@ export interface ArrayFormatterIssue {
|
|
|
2040
2016
|
readonly message: string
|
|
2041
2017
|
}
|
|
2042
2018
|
|
|
2019
|
+
const makeArrayFormatterIssue = (
|
|
2020
|
+
_tag: ArrayFormatterIssue["_tag"],
|
|
2021
|
+
path: ArrayFormatterIssue["path"],
|
|
2022
|
+
message: ArrayFormatterIssue["message"]
|
|
2023
|
+
): ArrayFormatterIssue => ({ _tag, path, message })
|
|
2024
|
+
|
|
2043
2025
|
/**
|
|
2044
2026
|
* @category formatting
|
|
2045
2027
|
* @since 3.10.0
|
|
2046
2028
|
*/
|
|
2047
2029
|
export const ArrayFormatter: ParseResultFormatter<Array<ArrayFormatterIssue>> = {
|
|
2048
|
-
formatIssue: (issue) =>
|
|
2049
|
-
formatIssueSync: (issue) =>
|
|
2030
|
+
formatIssue: (issue) => getArrayFormatterIssues(issue),
|
|
2031
|
+
formatIssueSync: (issue) => {
|
|
2032
|
+
const e = ArrayFormatter.formatIssue(issue)
|
|
2033
|
+
return isEither(e) ? Either.getOrThrow(e) : Effect.runSync(e)
|
|
2034
|
+
},
|
|
2050
2035
|
formatError: (error) => ArrayFormatter.formatIssue(error.issue),
|
|
2051
2036
|
formatErrorSync: (error) => ArrayFormatter.formatIssueSync(error.issue)
|
|
2052
2037
|
}
|
|
2053
2038
|
|
|
2054
|
-
const
|
|
2055
|
-
|
|
2056
|
-
const getArray = (
|
|
2039
|
+
const getArrayFormatterIssues = (
|
|
2057
2040
|
issue: ParseIssue,
|
|
2058
|
-
path: ReadonlyArray<PropertyKey>,
|
|
2059
|
-
onFailure: () => Effect.Effect<Array<ArrayFormatterIssue>>
|
|
2060
|
-
) =>
|
|
2061
|
-
Effect.matchEffect(getMessage(issue), {
|
|
2062
|
-
onFailure,
|
|
2063
|
-
onSuccess: (message) => succeedArrayFormatterIssue({ _tag: issue._tag, path, message })
|
|
2064
|
-
})
|
|
2065
|
-
|
|
2066
|
-
const formatArray = (
|
|
2067
|
-
e: ParseIssue | Pointer,
|
|
2068
2041
|
path: ReadonlyArray<PropertyKey> = []
|
|
2069
2042
|
): Effect.Effect<Array<ArrayFormatterIssue>> => {
|
|
2070
|
-
const _tag =
|
|
2043
|
+
const _tag = issue._tag
|
|
2071
2044
|
switch (_tag) {
|
|
2072
2045
|
case "Type":
|
|
2073
|
-
return
|
|
2046
|
+
return map(formatTypeMessage(issue), (message) => [makeArrayFormatterIssue(_tag, path, message)])
|
|
2074
2047
|
case "Forbidden":
|
|
2075
|
-
return
|
|
2048
|
+
return Either.right([makeArrayFormatterIssue(_tag, path, formatForbiddenMessage(issue))])
|
|
2076
2049
|
case "Unexpected":
|
|
2077
|
-
return
|
|
2050
|
+
return Either.right([makeArrayFormatterIssue(_tag, path, formatUnexpectedMessage(issue))])
|
|
2078
2051
|
case "Missing":
|
|
2079
|
-
return
|
|
2052
|
+
return map(formatMissingMessage(issue), (message) => [makeArrayFormatterIssue(_tag, path, message)])
|
|
2080
2053
|
case "Pointer":
|
|
2081
|
-
return
|
|
2054
|
+
return getArrayFormatterIssues(issue.issue, path.concat(issue.path))
|
|
2082
2055
|
case "Composite":
|
|
2083
|
-
return
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2056
|
+
return flatMap(getMessage(issue), (message) => {
|
|
2057
|
+
if (message !== undefined) {
|
|
2058
|
+
return Either.right([makeArrayFormatterIssue(issue._tag, path, message)])
|
|
2059
|
+
}
|
|
2060
|
+
return util_.isNonEmpty(issue.issues)
|
|
2061
|
+
? map(Effect.forEach(issue.issues, (issue) => getArrayFormatterIssues(issue, path)), Arr.flatten)
|
|
2062
|
+
: getArrayFormatterIssues(issue.issues, path)
|
|
2063
|
+
})
|
|
2087
2064
|
case "Refinement":
|
|
2088
2065
|
case "Transformation":
|
|
2089
|
-
return
|
|
2066
|
+
return flatMap(getMessage(issue), (message) => {
|
|
2067
|
+
if (message !== undefined) {
|
|
2068
|
+
return Either.right([makeArrayFormatterIssue(issue._tag, path, message)])
|
|
2069
|
+
}
|
|
2070
|
+
return getArrayFormatterIssues(issue.issue, path)
|
|
2071
|
+
})
|
|
2090
2072
|
}
|
|
2091
2073
|
}
|
package/src/STM.ts
CHANGED
|
@@ -81,7 +81,7 @@ export interface STM<out A, out E = never, out R = never>
|
|
|
81
81
|
* @category models
|
|
82
82
|
*/
|
|
83
83
|
export interface STMUnify<A extends { [Unify.typeSymbol]?: any }> extends Effect.EffectUnify<A> {
|
|
84
|
-
STM?: () => A[Unify.typeSymbol] extends STM<infer A0, infer E0, infer R0> | infer _ ? STM<
|
|
84
|
+
STM?: () => A[Unify.typeSymbol] extends STM<infer A0, infer E0, infer R0> | infer _ ? STM<A0, E0, R0> : never
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
package/src/Schema.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @since 3.10.0
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import * as internalCause_ from "effect/internal/cause"
|
|
6
5
|
import type { ArbitraryAnnotation, ArbitraryGenerationContext, LazyArbitrary } from "./Arbitrary.js"
|
|
7
6
|
import * as array_ from "./Array.js"
|
|
8
7
|
import * as bigDecimal_ from "./BigDecimal.js"
|
|
@@ -29,6 +28,7 @@ import { dual, identity } from "./Function.js"
|
|
|
29
28
|
import { globalValue } from "./GlobalValue.js"
|
|
30
29
|
import * as hashMap_ from "./HashMap.js"
|
|
31
30
|
import * as hashSet_ from "./HashSet.js"
|
|
31
|
+
import * as internalCause_ from "./internal/cause.js"
|
|
32
32
|
import * as errors_ from "./internal/schema/errors.js"
|
|
33
33
|
import * as schemaId_ from "./internal/schema/schemaId.js"
|
|
34
34
|
import * as util_ from "./internal/schema/util.js"
|
package/src/internal/version.ts
CHANGED