MCPcopy Create free account
hub / github.com/Effect-TS/effect / flipAST

Function flipAST

packages/effect/src/SchemaAST.ts:4890–4911  ·  view source on GitHub ↗
(ast: AST)

Source from the content-addressed store, hash-verified

4888})
4889
4890function flipAST(ast: AST): AST {
4891 if (ast.encoding) {
4892 return flipEncoding(ast, ast.encoding)
4893 }
4894 const owned = projectOwner(ast, flip)
4895 if (owned) return owned
4896 if (isSuspend(ast)) {
4897 const previous = flippedThunks.get(ast.thunk)
4898 if (previous) return copy(ast, { thunk: previous.source.thunk })
4899 const flipped = ast.recur(flip)
4900 // Register the projection here so decoding alone does not pull in flip.
4901 flippedThunks.set(flipped.thunk, {
4902 source: ast,
4903 project(node) {
4904 const thunk = memoizeThunk(() => reverseBody(ast.thunk(), thunk))
4905 return copy(node, { thunk })
4906 }
4907 })
4908 return flipped
4909 }
4910 return "flip" in ast ? ast.flip(flip) : ast
4911}
4912
4913function reverseBody(body: AST, edge: Suspend["thunk"]): AST {
4914 if (types.get(body) !== body) return stripEncoding(flip(body))

Callers 1

SchemaAST.tsFile · 0.85

Calls 7

flipEncodingFunction · 0.85
projectOwnerFunction · 0.85
copyFunction · 0.70
getMethod · 0.65
recurMethod · 0.65
setMethod · 0.65
flipMethod · 0.65

Tested by

no test coverage detected