| 91 | } |
| 92 | |
| 93 | function effectifyAST(ast: AST.AST): AST.AST { |
| 94 | switch (ast._tag) { |
| 95 | case "TupleType": |
| 96 | return new AST.TupleType( |
| 97 | ast.elements.map((e) => new AST.OptionalType(effectifyAST(e.type), e.isOptional, e.annotations)), |
| 98 | ast.rest.map((annotatedAST) => new AST.Type(effectifyAST(annotatedAST.type), annotatedAST.annotations)), |
| 99 | ast.isReadonly, |
| 100 | ast.annotations |
| 101 | ) |
| 102 | case "TypeLiteral": |
| 103 | return new AST.TypeLiteral( |
| 104 | ast.propertySignatures.map((p) => |
| 105 | new AST.PropertySignature(p.name, effectifyAST(p.type), p.isOptional, p.isReadonly, p.annotations) |
| 106 | ), |
| 107 | ast.indexSignatures.map((is) => { |
| 108 | return new AST.IndexSignature(is.parameter, effectifyAST(is.type), is.isReadonly) |
| 109 | }), |
| 110 | ast.annotations |
| 111 | ) |
| 112 | case "Union": |
| 113 | return AST.Union.make(ast.types.map((ast) => effectifyAST(ast)), ast.annotations) |
| 114 | case "Suspend": |
| 115 | return new AST.Suspend(() => effectifyAST(ast.f()), ast.annotations) |
| 116 | case "Refinement": |
| 117 | return new AST.Refinement( |
| 118 | effectifyAST(ast.from), |
| 119 | ast.filter, |
| 120 | ast.annotations |
| 121 | ) |
| 122 | case "Transformation": |
| 123 | return new AST.Transformation( |
| 124 | effectifyAST(ast.from), |
| 125 | effectifyAST(ast.to), |
| 126 | new AST.FinalTransformation( |
| 127 | effectifyDecode(ParseResult.getFinalTransformation(ast.transformation, true)), |
| 128 | effectifyDecode(ParseResult.getFinalTransformation(ast.transformation, false)) |
| 129 | ), |
| 130 | ast.annotations |
| 131 | ) |
| 132 | } |
| 133 | const schema = S.make(ast) |
| 134 | const decode = S.decode(schema) |
| 135 | const encode = S.encode(schema) |
| 136 | return new AST.Transformation( |
| 137 | AST.encodedAST(ast), |
| 138 | AST.typeAST(ast), |
| 139 | new AST.FinalTransformation( |
| 140 | (a, options) => |
| 141 | Effect.flatMap(Effect.sleep("10 millis"), () => ParseResult.mapError(decode(a, options), (e) => e.issue)), |
| 142 | (a, options) => |
| 143 | Effect.flatMap(Effect.sleep("10 millis"), () => ParseResult.mapError(encode(a, options), (e) => e.issue)) |
| 144 | ) |
| 145 | ) |
| 146 | } |
| 147 | |
| 148 | function effectify<A, I>(schema: S.Schema<A, I, never>): S.Schema<A, I, never> { |
| 149 | return S.make(effectifyAST(schema.ast)) |