@prefecthq/prefect-ui-library
Version:
This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.
59 lines (51 loc) • 1.67 kB
text/typescript
import {
PrefectWorkerCollectionResponse,
WorkerCollectionItem
} from '@/models'
import { MapFunction } from '@/services/Mapper'
import {
SchemaValues,
WorkerBaseJobTemplate,
SchemaProperty
} from '@/types/schemas'
export const mapPrefectWorkerCollectionResponseToWorkerCollectionItemArray: MapFunction<
PrefectWorkerCollectionResponse,
WorkerCollectionItem[]
> = function(source) {
return Object.values(source)
.flatMap((package_data) => Object.values(package_data))
.map((worker_data) => ({
defaultBaseJobConfiguration: worker_data.default_base_job_configuration,
description: worker_data.description,
displayName: worker_data.display_name,
documentationUrl: worker_data.documentation_url,
installCommand: worker_data.install_command,
logoUrl: worker_data.logo_url,
type: worker_data.type,
isBeta: worker_data.is_beta ?? false,
isPushPool: worker_data.is_push_pool ?? false,
isMexPool: worker_data.is_mex_pool ?? false,
}))
}
type MapSchemaValuesSource = {
values: SchemaValues,
schema: WorkerBaseJobTemplate,
}
export const mapWorkerSchemaValuesToWorkerSchemaValuesRequest: MapFunction<
MapSchemaValuesSource,
WorkerBaseJobTemplate
> = function(source) {
const { values = {}, schema } = source
const keys = Object.keys(schema.variables?.properties ?? {})
keys.forEach((key) => {
if (schema.variables?.properties) {
const property = schema.variables.properties[key] as
| SchemaProperty
| undefined
if (property !== undefined && values[key] !== undefined) {
property.default = values[key]
}
}
})
return schema
}