Files
shields/frontend/lib/service-definitions/index.ts
Paul Melnikow 35ef9be434 Typescripterize BadgeExamples and SuggestionAndSearch (#3879)
The two different kinds of data that can be passed to `<BadgeExample />` were a bit less similar than I thought, so this includes a little refactor related to that which isn't perfect, but leaves things in a cleaner place than before.
2019-08-21 08:25:03 +01:00

63 lines
1.2 KiB
TypeScript

import groupBy from 'lodash.groupby'
// load using js-yaml-loader
import definitions from '../../../service-definitions.yml'
export interface Category {
id: string
name: string
}
export interface ExampleSignature {
pattern: string
namedParams: { [k: string]: string }
queryParams: { [k: string]: string }
}
export interface Preview {
label?: string
message: string
color: string
style?: string
namedLogo?: string
}
export interface Example {
title: string
example: ExampleSignature
preview: Preview
keywords: string[]
documentation?: {
__html: string
}
}
export interface Route {
pattern: string
queryParams: string[]
}
export interface LegacyRoute {
format: string
queryParams: string[]
}
export interface ServiceDefinition {
category: string
name: string
isDeprecated: boolean
route: Route | LegacyRoute
examples: Example[]
}
export const services = definitions.services as ServiceDefinition[]
export const categories = definitions.categories as Category[]
export function findCategory(category: string) {
return categories.find(({ id }) => id === category)
}
const byCategory = groupBy(services, 'category')
export function getDefinitionsForCategory(category: string) {
return byCategory[category]
}