Repository navigation
Open
Labels
Description
What is the problem this feature would solve?
A more concise way to express cases such as the following:
import { Record, Schema as S, Tuple } from "effect"
import { ModuleSpecifier, RecoveryInstruction } from "../schema/index.ts"
import { DiagnosticOrigin } from "./DiagnosticOrigin.ts"
/** A diagnostic for an observed extension failure; interruption is cancellation and creates no extension diagnostic. */
export type Diagnostic = typeof Diagnostic.Type
export const Diagnostic = S.TaggedUnion({
Error: {
/** Safe, normalized failure details when remediation is unknown; excludes raw error objects and source excerpts. */
error: S.NonEmptyString.check(S.isPattern(/\S/u)).annotate({
description:
"Safe, normalized failure details when remediation is unknown; excludes raw error objects and source excerpts."
})
},
Instruction: {
/** Actionable remediation including relevant failure context, replacing standalone error details. */
instruction: RecoveryInstruction.annotateKey({
description: "Actionable remediation including relevant failure context, replacing standalone error details."
})
}
})
.pipe((schema) => S.Union(Record.values(schema.cases)))
.mapMembers(
Tuple.map(
S.fieldsAssign({
/** The configured segmenter or enrichment module that failed. */
module: ModuleSpecifier.annotateKey({
description: "The configured segmenter or enrichment module that failed."
}),
/** The extension kind and lifecycle stage: setup origins have no location, segmenter execution references a supplied change, and enrichment execution references a trait-local input. */
origin: DiagnosticOrigin
})
)
)
.annotate({
description:
"A diagnostic for an observed extension failure; interruption is cancellation and creates no extension diagnostic."
})
.pipe(S.toTaggedUnion("_tag"))What is the feature you are proposing to solve the problem?
Not sure what the exact API would look like––but ideally one wouldn't need to turn the initial tagged union schema into a union schema (in order to map its members) and then turn it back into a tagged union schema.
What alternatives have you considered?
No response
Activity