@effect/schema
Advanced tools
Comparing version 0.68.5 to 0.68.6
@@ -100,24 +100,3 @@ "use strict"; | ||
}; | ||
const getInnerMessage = issue => { | ||
switch (issue._tag) { | ||
case "Refinement": | ||
{ | ||
if (issue.kind === "From") { | ||
return getMessage(issue.issue); | ||
} | ||
break; | ||
} | ||
case "Transformation": | ||
{ | ||
return getMessage(issue.issue); | ||
} | ||
} | ||
return Option.none(); | ||
}; | ||
const getAnnotated = issue => { | ||
if ("ast" in issue) { | ||
return Option.some(issue.ast); | ||
} | ||
return Option.none(); | ||
}; | ||
const getAnnotated = issue => "ast" in issue ? Option.some(issue.ast) : Option.none(); | ||
const getCurrentMessage = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getMessageAnnotation), Effect.flatMap(annotation => { | ||
@@ -139,12 +118,11 @@ const out = annotation(issue); | ||
})); | ||
const createParseIssueGuard = tag => issue => issue._tag === tag; | ||
const isComposite = /*#__PURE__*/createParseIssueGuard("Composite"); | ||
const isRefinement = /*#__PURE__*/createParseIssueGuard("Refinement"); | ||
const isTransformation = /*#__PURE__*/createParseIssueGuard("Transformation"); | ||
/** @internal */ | ||
const getMessage = issue => { | ||
const current = getCurrentMessage(issue); | ||
return getInnerMessage(issue).pipe(Effect.flatMap(inner => Effect.map(current, current => current.override ? current.message : inner)), Effect.catchAll(() => Effect.flatMap(current, current => { | ||
if (!current.override && (issue._tag === "Refinement" && issue.kind !== "Predicate" || issue._tag === "Transformation" && issue.kind !== "Transformation")) { | ||
return Option.none(); | ||
} | ||
return Effect.succeed(current.message); | ||
}))); | ||
}; | ||
const getMessage = issue => getCurrentMessage(issue).pipe(Effect.flatMap(currentMessage => { | ||
const useInnerMessage = !currentMessage.override && (isComposite(issue) || isRefinement(issue) && issue.kind === "From" || isTransformation(issue) && issue.kind !== "Transformation"); | ||
return useInnerMessage ? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Option.none() : Effect.succeed(currentMessage.message); | ||
})); | ||
exports.getMessage = getMessage; | ||
@@ -151,0 +129,0 @@ const getParseIssueTitleAnnotation = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getParseIssueTitleAnnotation), Option.filterMap(annotation => Option.fromNullable(annotation(issue)))); |
@@ -64,24 +64,3 @@ /** | ||
}; | ||
const getInnerMessage = issue => { | ||
switch (issue._tag) { | ||
case "Refinement": | ||
{ | ||
if (issue.kind === "From") { | ||
return getMessage(issue.issue); | ||
} | ||
break; | ||
} | ||
case "Transformation": | ||
{ | ||
return getMessage(issue.issue); | ||
} | ||
} | ||
return Option.none(); | ||
}; | ||
const getAnnotated = issue => { | ||
if ("ast" in issue) { | ||
return Option.some(issue.ast); | ||
} | ||
return Option.none(); | ||
}; | ||
const getAnnotated = issue => "ast" in issue ? Option.some(issue.ast) : Option.none(); | ||
const getCurrentMessage = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getMessageAnnotation), Effect.flatMap(annotation => { | ||
@@ -103,12 +82,11 @@ const out = annotation(issue); | ||
})); | ||
const createParseIssueGuard = tag => issue => issue._tag === tag; | ||
const isComposite = /*#__PURE__*/createParseIssueGuard("Composite"); | ||
const isRefinement = /*#__PURE__*/createParseIssueGuard("Refinement"); | ||
const isTransformation = /*#__PURE__*/createParseIssueGuard("Transformation"); | ||
/** @internal */ | ||
export const getMessage = issue => { | ||
const current = getCurrentMessage(issue); | ||
return getInnerMessage(issue).pipe(Effect.flatMap(inner => Effect.map(current, current => current.override ? current.message : inner)), Effect.catchAll(() => Effect.flatMap(current, current => { | ||
if (!current.override && (issue._tag === "Refinement" && issue.kind !== "Predicate" || issue._tag === "Transformation" && issue.kind !== "Transformation")) { | ||
return Option.none(); | ||
} | ||
return Effect.succeed(current.message); | ||
}))); | ||
}; | ||
export const getMessage = issue => getCurrentMessage(issue).pipe(Effect.flatMap(currentMessage => { | ||
const useInnerMessage = !currentMessage.override && (isComposite(issue) || isRefinement(issue) && issue.kind === "From" || isTransformation(issue) && issue.kind !== "Transformation"); | ||
return useInnerMessage ? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Option.none() : Effect.succeed(currentMessage.message); | ||
})); | ||
const getParseIssueTitleAnnotation = issue => getAnnotated(issue).pipe(Option.flatMap(AST.getParseIssueTitleAnnotation), Option.filterMap(annotation => Option.fromNullable(annotation(issue)))); | ||
@@ -115,0 +93,0 @@ /** @internal */ |
{ | ||
"name": "@effect/schema", | ||
"version": "0.68.5", | ||
"version": "0.68.6", | ||
"description": "Modeling the schema of data structures as first-class values", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -85,31 +85,13 @@ /** | ||
const getInnerMessage = ( | ||
issue: ParseResult.ParseIssue | ||
): Effect.Effect<string, Cause.NoSuchElementException> => { | ||
switch (issue._tag) { | ||
case "Refinement": { | ||
if (issue.kind === "From") { | ||
return getMessage(issue.issue) | ||
} | ||
break | ||
} | ||
case "Transformation": { | ||
return getMessage(issue.issue) | ||
} | ||
} | ||
return Option.none() | ||
} | ||
const getAnnotated = (issue: ParseResult.ParseIssue): Option.Option<AST.Annotated> => | ||
"ast" in issue ? Option.some(issue.ast) : Option.none() | ||
const getAnnotated = (issue: ParseResult.ParseIssue): Option.Option<AST.Annotated> => { | ||
if ("ast" in issue) { | ||
return Option.some(issue.ast) | ||
} | ||
return Option.none() | ||
interface CurrentMessage { | ||
readonly message: string | ||
readonly override: boolean | ||
} | ||
const getCurrentMessage: ( | ||
const getCurrentMessage = ( | ||
issue: ParseResult.ParseIssue | ||
) => Effect.Effect<{ message: string; override: boolean }, Cause.NoSuchElementException> = ( | ||
issue: ParseResult.ParseIssue | ||
) => | ||
): Effect.Effect<CurrentMessage, Cause.NoSuchElementException> => | ||
getAnnotated(issue).pipe( | ||
@@ -129,24 +111,26 @@ Option.flatMap(AST.getMessageAnnotation), | ||
const createParseIssueGuard = | ||
<T extends ParseResult.ParseIssue["_tag"]>(tag: T) => | ||
(issue: ParseResult.ParseIssue): issue is Extract<ParseResult.ParseIssue, { _tag: T }> => issue._tag === tag | ||
const isComposite = createParseIssueGuard("Composite") | ||
const isRefinement = createParseIssueGuard("Refinement") | ||
const isTransformation = createParseIssueGuard("Transformation") | ||
/** @internal */ | ||
export const getMessage: ( | ||
issue: ParseResult.ParseIssue | ||
) => Effect.Effect<string, Cause.NoSuchElementException> = (issue: ParseResult.ParseIssue) => { | ||
const current = getCurrentMessage(issue) | ||
return getInnerMessage(issue).pipe( | ||
Effect.flatMap((inner) => Effect.map(current, (current) => current.override ? current.message : inner)), | ||
Effect.catchAll(() => | ||
Effect.flatMap(current, (current) => { | ||
if ( | ||
!current.override && ( | ||
(issue._tag === "Refinement" && issue.kind !== "Predicate") || | ||
(issue._tag === "Transformation" && issue.kind !== "Transformation") | ||
) | ||
) { | ||
return Option.none() | ||
} | ||
return Effect.succeed(current.message) | ||
}) | ||
) | ||
) => Effect.Effect<string, Cause.NoSuchElementException> = (issue: ParseResult.ParseIssue) => | ||
getCurrentMessage(issue).pipe( | ||
Effect.flatMap((currentMessage) => { | ||
const useInnerMessage = !currentMessage.override && ( | ||
isComposite(issue) || | ||
(isRefinement(issue) && issue.kind === "From") || | ||
(isTransformation(issue) && issue.kind !== "Transformation") | ||
) | ||
return useInnerMessage | ||
? isTransformation(issue) || isRefinement(issue) ? getMessage(issue.issue) : Option.none() | ||
: Effect.succeed(currentMessage.message) | ||
}) | ||
) | ||
} | ||
@@ -153,0 +137,0 @@ const getParseIssueTitleAnnotation = (issue: ParseResult.ParseIssue): Option.Option<string> => |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2418036
9088
40558