MCPcopy Index your code
hub / github.com/Effect-TS/effect / effectifyAST

Function effectifyAST

packages/effect/test/Schema/TestUtils.ts:93–146  ·  view source on GitHub ↗
(ast: AST.AST)

Source from the content-addressed store, hash-verified

91}
92
93function 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
148function effectify<A, I>(schema: S.Schema<A, I, never>): S.Schema<A, I, never> {
149 return S.make(effectifyAST(schema.ast))

Callers 1

effectifyFunction · 0.85

Calls 9

effectifyDecodeFunction · 0.85
decodeMethod · 0.80
encodeMethod · 0.80
mapMethod · 0.65
makeMethod · 0.65
fMethod · 0.65
sleepMethod · 0.65
decodeFunction · 0.50
encodeFunction · 0.50

Tested by

no test coverage detected