( from: Union.ChildNode, to: nodeOfKind<RootKind>, ctx: IntersectionContext )
| 243 | ) |
| 244 | |
| 245 | const _pipeMorphed = ( |
| 246 | from: Union.ChildNode, |
| 247 | to: nodeOfKind<RootKind>, |
| 248 | ctx: IntersectionContext |
| 249 | ): Morph.Node | Disjoint => { |
| 250 | const fromIsMorph = from.is("morph") |
| 251 | |
| 252 | if (fromIsMorph) { |
| 253 | const morphs = [...from.morphs] |
| 254 | if (from.tail) { |
| 255 | // still piped from context, so allows appending additional morphs |
| 256 | const outIntersection = intersectOrPipeNodes(from.tail, to, ctx) |
| 257 | if (outIntersection instanceof Disjoint) return outIntersection |
| 258 | morphs[morphs.length - 1] = outIntersection |
| 259 | } else morphs.push(to) |
| 260 | |
| 261 | // a basisless constraint (e.g. from .narrow or .constrainOut) narrows |
| 262 | // declaredOut rather than replacing it; a full target becomes the tail |
| 263 | // whose own output is ._out |
| 264 | let declaredOut: BaseRoot | undefined |
| 265 | if ( |
| 266 | from.inner.declaredOut && |
| 267 | to.is("intersection") && |
| 268 | !to.basis && |
| 269 | !to.isUnknown() && |
| 270 | (isIoFinal() || (!from.inner.declaredOut.hasAlias && !to.hasAlias)) |
| 271 | ) { |
| 272 | const outTersection = intersectOrPipeNodes( |
| 273 | from.inner.declaredOut, |
| 274 | to, |
| 275 | ctx |
| 276 | ) |
| 277 | if (outTersection instanceof Disjoint) return outTersection |
| 278 | declaredOut = outTersection._out |
| 279 | } |
| 280 | |
| 281 | return ctx.$.node("morph", { |
| 282 | morphs, |
| 283 | ...(from.inner.declaredIn && { declaredIn: from.inner.declaredIn }), |
| 284 | ...(declaredOut && { declaredOut }), |
| 285 | inverse: from.inner.inverse as any |
| 286 | }) |
| 287 | } |
| 288 | |
| 289 | if (to.is("morph")) { |
| 290 | const inTersection = intersectOrPipeNodes(from, to._in, ctx) |
| 291 | if (inTersection instanceof Disjoint) return inTersection |
| 292 | |
| 293 | return ctx.$.node("morph", { morphs: [inTersection, to] }) |
| 294 | } |
| 295 | |
| 296 | // a branch that alters nothing, piped to what alters nothing and doesn't |
| 297 | // intersect it, is dropped as `null |> string` throws outside a union. One |
| 298 | // that does intersect stays a morph, so configuring the pipe leaves its |
| 299 | // output's description and JSON Schema its own |
| 300 | if (!from.alters && !to.alters) { |
| 301 | const intersection = intersectOrPipeNodes(from, to, ctx) |
| 302 | if (intersection instanceof Disjoint) return intersection |
no test coverage detected