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

Function rename

packages/effect/src/SchemaAST.ts:2947–2993  ·  view source on GitHub ↗
(ast: AST, mapping: { readonly [K in PropertyKey]?: PropertyKey })

Source from the content-addressed store, hash-verified

2945
2946/** @internal */
2947export const rename = (ast: AST, mapping: { readonly [K in PropertyKey]?: PropertyKey }): AST => {
2948 switch (ast._tag) {
2949 case "TypeLiteral": {
2950 const propertySignatureTransformations: Array<PropertySignatureTransformation> = []
2951 for (const key of Reflect.ownKeys(mapping)) {
2952 const name = mapping[key]
2953 if (name !== undefined) {
2954 propertySignatureTransformations.push(
2955 new PropertySignatureTransformation(
2956 key,
2957 name,
2958 identity,
2959 identity
2960 )
2961 )
2962 }
2963 }
2964 if (propertySignatureTransformations.length === 0) {
2965 return ast
2966 }
2967 return new Transformation(
2968 ast,
2969 new TypeLiteral(
2970 ast.propertySignatures.map((ps) => {
2971 const name = mapping[ps.name]
2972 return new PropertySignature(
2973 name === undefined ? ps.name : name,
2974 typeAST(ps.type),
2975 ps.isOptional,
2976 ps.isReadonly,
2977 ps.annotations
2978 )
2979 }),
2980 ast.indexSignatures
2981 ),
2982 new TypeLiteralTransformation(propertySignatureTransformations)
2983 )
2984 }
2985 case "Union":
2986 return Union.make(ast.types.map((ast) => rename(ast, mapping)))
2987 case "Suspend":
2988 return new Suspend(() => rename(ast.f(), mapping))
2989 case "Transformation":
2990 return compose(ast, rename(typeAST(ast), mapping))
2991 }
2992 throw new Error(errors_.getASTUnsupportedRenameSchemaErrorMessage(ast))
2993}
2994
2995const formatKeyword = (ast: AST): string => Option.getOrElse(getExpected(ast), () => ast._tag)
2996

Callers

nothing calls this directly

Calls 5

typeASTFunction · 0.85
composeFunction · 0.70
mapMethod · 0.65
makeMethod · 0.65
fMethod · 0.65

Tested by

no test coverage detected