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

Function encodedAST_

packages/effect/src/SchemaAST.ts:2773–2836  ·  view source on GitHub ↗
(ast: AST, isBound: boolean)

Source from the content-addressed store, hash-verified

2771}
2772
2773const encodedAST_ = (ast: AST, isBound: boolean): AST => {
2774 switch (ast._tag) {
2775 case "Declaration": {
2776 const typeParameters = changeMap(ast.typeParameters, (ast) => encodedAST_(ast, isBound))
2777 return typeParameters === ast.typeParameters ?
2778 ast :
2779 new Declaration(typeParameters, ast.decodeUnknown, ast.encodeUnknown)
2780 }
2781 case "TupleType": {
2782 const elements = changeMap(ast.elements, (e) => {
2783 const type = encodedAST_(e.type, isBound)
2784 return type === e.type ? e : new OptionalType(type, e.isOptional)
2785 })
2786 const restASTs = getRestASTs(ast.rest)
2787 const rest = changeMap(restASTs, (ast) => encodedAST_(ast, isBound))
2788 return elements === ast.elements && rest === restASTs ?
2789 ast :
2790 new TupleType(elements, rest.map((ast) => new Type(ast)), ast.isReadonly)
2791 }
2792 case "TypeLiteral": {
2793 const propertySignatures = changeMap(ast.propertySignatures, (ps) => {
2794 const type = encodedAST_(ps.type, isBound)
2795 return type === ps.type
2796 ? ps
2797 : new PropertySignature(ps.name, type, ps.isOptional, ps.isReadonly)
2798 })
2799 const indexSignatures = changeMap(ast.indexSignatures, (is) => {
2800 const type = encodedAST_(is.type, isBound)
2801 return type === is.type ? is : new IndexSignature(is.parameter, type, is.isReadonly)
2802 })
2803 return propertySignatures === ast.propertySignatures && indexSignatures === ast.indexSignatures ?
2804 ast :
2805 new TypeLiteral(propertySignatures, indexSignatures)
2806 }
2807 case "Union": {
2808 const types = changeMap(ast.types, (ast) => encodedAST_(ast, isBound))
2809 return types === ast.types ? ast : Union.make(types)
2810 }
2811 case "Suspend": {
2812 let borrowedAnnotations = undefined
2813 const identifier = getJSONIdentifier(ast)
2814 if (Option.isSome(identifier)) {
2815 const suffix = isBound ? "Bound" : ""
2816 borrowedAnnotations = { [JSONIdentifierAnnotationId]: `${identifier.value}Encoded${suffix}` }
2817 }
2818 return new Suspend(() => encodedAST_(ast.f(), isBound), borrowedAnnotations)
2819 }
2820 case "Refinement": {
2821 const from = encodedAST_(ast.from, isBound)
2822 if (isBound) {
2823 if (from === ast.from) return ast
2824 if (getTransformationFrom(ast.from) === undefined && hasStableFilter(ast)) {
2825 return new Refinement(from, ast.filter, ast.annotations)
2826 }
2827 return from
2828 } else {
2829 return from
2830 }

Callers 2

encodedASTFunction · 0.85
encodedBoundASTFunction · 0.85

Calls 8

changeMapFunction · 0.85
getRestASTsFunction · 0.85
getJSONIdentifierFunction · 0.85
getTransformationFromFunction · 0.85
hasStableFilterFunction · 0.85
mapMethod · 0.65
makeMethod · 0.65
fMethod · 0.65

Tested by

no test coverage detected