MCPcopy
hub / github.com/Effect-TS/effect / optionalToRequired

Function optionalToRequired

packages/effect/src/Schema.ts:2249–2264  ·  view source on GitHub ↗
(
  from: Schema<FA, FI, FR>,
  to: Schema<TA, TI, TR>,
  options: {
    readonly decode: (o: option_.Option<FA>) => TI
    readonly encode: (ti: TI) => option_.Option<FA>
  }
)

Source from the content-addressed store, hash-verified

2247 * @since 3.10.0
2248 */
2249export const optionalToRequired = <FA, FI, FR, TA, TI, TR>(
2250 from: Schema<FA, FI, FR>,
2251 to: Schema<TA, TI, TR>,
2252 options: {
2253 readonly decode: (o: option_.Option<FA>) => TI
2254 readonly encode: (ti: TI) => option_.Option<FA>
2255 }
2256): PropertySignature<":", TA, never, "?:", FI, false, FR | TR> =>
2257 makePropertySignature(
2258 new PropertySignatureTransformation(
2259 new FromPropertySignature(from.ast, true, true, {}, undefined),
2260 new ToPropertySignature(to.ast, false, true, {}, undefined),
2261 (o) => option_.some(options.decode(o)),
2262 option_.flatMap(options.encode)
2263 )
2264 )
2265
2266/**
2267 * Converts an optional property to a required one through a transformation `Type -> Option`.

Callers 1

Calls 2

makePropertySignatureFunction · 0.85
decodeMethod · 0.80

Tested by

no test coverage detected