| 1686 | |
| 1687 | /** @internal */ |
| 1688 | export const getFinalTransformation = ( |
| 1689 | transformation: AST.TransformationKind, |
| 1690 | isDecoding: boolean |
| 1691 | ): ( |
| 1692 | fromA: any, |
| 1693 | options: AST.ParseOptions, |
| 1694 | self: AST.Transformation, |
| 1695 | fromI: any |
| 1696 | ) => Effect.Effect<any, ParseIssue, any> => { |
| 1697 | switch (transformation._tag) { |
| 1698 | case "FinalTransformation": |
| 1699 | return isDecoding ? transformation.decode : transformation.encode |
| 1700 | case "ComposeTransformation": |
| 1701 | return Either.right |
| 1702 | case "TypeLiteralTransformation": |
| 1703 | return (input) => { |
| 1704 | let out: Effect.Effect<any, ParseIssue, any> = Either.right(input) |
| 1705 | |
| 1706 | // --------------------------------------------- |
| 1707 | // handle property signature transformations |
| 1708 | // --------------------------------------------- |
| 1709 | for (const pst of transformation.propertySignatureTransformations) { |
| 1710 | const [from, to] = isDecoding ? |
| 1711 | [pst.from, pst.to] : |
| 1712 | [pst.to, pst.from] |
| 1713 | const transformation = isDecoding ? pst.decode : pst.encode |
| 1714 | const f = (input: any) => { |
| 1715 | const o = transformation( |
| 1716 | Object.prototype.hasOwnProperty.call(input, from) ? |
| 1717 | Option.some(input[from]) : |
| 1718 | Option.none() |
| 1719 | ) |
| 1720 | delete input[from] |
| 1721 | if (Option.isSome(o)) { |
| 1722 | input[to] = o.value |
| 1723 | } |
| 1724 | return input |
| 1725 | } |
| 1726 | out = map(out, f) |
| 1727 | } |
| 1728 | return out |
| 1729 | } |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | // ---------------- |
| 1734 | // Formatters |