| 1668 | |
| 1669 | /** @internal */ |
| 1670 | export const getFinalTransformation = ( |
| 1671 | transformation: AST.TransformationKind, |
| 1672 | isDecoding: boolean |
| 1673 | ): ( |
| 1674 | fromA: any, |
| 1675 | options: AST.ParseOptions, |
| 1676 | self: AST.Transformation, |
| 1677 | fromI: any |
| 1678 | ) => Effect.Effect<any, ParseIssue, any> => { |
| 1679 | switch (transformation._tag) { |
| 1680 | case "FinalTransformation": |
| 1681 | return isDecoding ? transformation.decode : transformation.encode |
| 1682 | case "ComposeTransformation": |
| 1683 | return Either.right |
| 1684 | case "TypeLiteralTransformation": |
| 1685 | return (input) => { |
| 1686 | let out: Effect.Effect<any, ParseIssue, any> = Either.right(input) |
| 1687 | |
| 1688 | // --------------------------------------------- |
| 1689 | // handle property signature transformations |
| 1690 | // --------------------------------------------- |
| 1691 | for (const pst of transformation.propertySignatureTransformations) { |
| 1692 | const [from, to] = isDecoding ? |
| 1693 | [pst.from, pst.to] : |
| 1694 | [pst.to, pst.from] |
| 1695 | const transformation = isDecoding ? pst.decode : pst.encode |
| 1696 | const f = (input: any) => { |
| 1697 | const o = transformation( |
| 1698 | Object.prototype.hasOwnProperty.call(input, from) ? |
| 1699 | Option.some(input[from]) : |
| 1700 | Option.none() |
| 1701 | ) |
| 1702 | delete input[from] |
| 1703 | if (Option.isSome(o)) { |
| 1704 | input[to] = o.value |
| 1705 | } |
| 1706 | return input |
| 1707 | } |
| 1708 | out = map(out, f) |
| 1709 | } |
| 1710 | return out |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | // ---------------- |
| 1716 | // Formatters |