import { mapMap , } from "collection-utils" ; import { lookupKey , AccessorNames , makeAccessorNames } from "./AccessorNames" ; import { EnumType } from "../Type" ; import { TypeAttributeKind } from "./TypeAttributes" ; import { JSONSchema } from "../input/JSONSchemaStore" ; import { Ref , JSONSchemaType , JSONSchemaAttributes } from "../input/JSONSchemaInput" ; class EnumValuesTypeAttributeKind extends TypeAttributeKind < AccessorNames > { constructor ( ) { super ( "enumValues" ) ; } makeInferred ( _ ) { return undefined ; } } export const enumValuesTypeAttributeKind = new EnumValuesTypeAttributeKind ( ) ; export function enumCaseValues ( e , language ) { const enumValues = enumValuesTypeAttributeKind . tryGetInAttributes ( e . getAttributes ( ) ) ; if ( enumValues === undefined ) return mapMap ( e . cases . entries ( ) , _ => undefined ) ; return mapMap ( e . cases . entries ( ) , c => lookupKey ( enumValues , c , language ) ) ; } export function enumValuesAttributeProducer ( schema , _canonicalRef , _types ) { if ( typeof schema !== "object" ) return undefined ; const maybeEnumValues = schema [ "qt-enum-values" ] ; if ( maybeEnumValues === undefined ) return undefined ; return { forType : enumValuesTypeAttributeKind . makeAttributes ( makeAccessorNames ( maybeEnumValues ) ) } ; }