import { removeUndefinedFromArray } from '@crosstype/common' ; import { JsonSchema , Python , TypeScript } from './imports' ; import { Compiler , LanguagePackage , Parser } from '#system' ; const allLanguages = removeUndefinedFromArray ( [ TypeScript , JsonSchema , Python ] ) ; export namespace Language { const languages = Object . freeze ( allLanguages . filter ( l => l . active ) ) ; type AllLanguages = ( typeof allLanguages ) [ number ] ; export type Languages = Exclude < AllLanguages , { active : false ; } > ; export type ShortNames = Languages [ 'shortName' ] ; export const ShortNames = languages . map ( l => l . shortName ) as ShortNames [ ] ; export type FullNames = Languages [ 'fullName' ] ; export const FullNames = languages . map ( l => l . fullName ) as FullNames [ ] ; export type Names = ShortNames | FullNames ; export const Names = { ... ShortNames , ... FullNames } ; export const CompilerLanguages = languages . filter ( l => l . compiler ) as LanguagePackage [ ] ; export type CompilerLanguages = Exclude < Language . Languages , { compiler : undefined ; } > ; export const ParserLanguages = languages . filter ( l => l . compiler ) as LanguagePackage [ ] ; export type ParserLanguages = Exclude < Language . Languages , { parser : undefined ; } > ; export const getLanguages = ( ) : readonly LanguagePackage [ ] => < readonly LanguagePackage [ ] > < unknown > languages ; export function getCompilers ( ) { const res = [ ] ; for ( const language of getLanguages ( ) ) if ( language . compiler ) res . push ( language . compiler ) ; return Object . freeze ( res ) ; } export function getCompiler ( name ) { return getLanguage ( name ) ?. compiler ; } export function getParser ( name ) { return getLanguage ( name ) ?. parser ; } export function getLanguage ( name ) { return getLanguages ( ) . find ( l => ( name === l . shortName ) || ( name === l . name ) ) ; } export type GetLanguage < N extends Language . Names | Language . ShortNames > = Extract < Languages , { fullName : N ; } | { shortName : N ; } > ; }