@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_.
56 lines (44 loc) • 1.74 kB
text/typescript
import { createTuple } from '@/utilities/tuples'
export const { values: stateType, isValue: isStateType } = createTuple([
'completed',
'running',
'scheduled',
'pending',
'failed',
'cancelled',
'cancelling',
'crashed',
'paused',
])
export type StateType = typeof stateType[number]
export type ServerStateType = Uppercase<StateType>
export function isServerStateType(value: unknown): value is ServerStateType {
return typeof value === 'string' && stateType.includes(value.toLowerCase() as StateType)
}
export const pendingStateType = ['scheduled', 'pending']
export type PendingStateType = typeof pendingStateType[number]
export function isPendingStateType(value: unknown): value is PendingStateType {
return typeof value === 'string' && pendingStateType.includes(value as PendingStateType)
}
export const terminalStateType = [
'completed',
'cancelled',
'failed',
'crashed',
]
export type TerminalStateType = typeof terminalStateType[number]
export type ServerTerminalStateType = Uppercase<TerminalStateType>
export function isTerminalStateType(value: unknown): value is TerminalStateType {
return typeof value === 'string' && terminalStateType.includes(value as TerminalStateType)
}
export const stuckStateTypes = ['running', 'scheduled', 'pending', 'paused']
export type StuckStateType = typeof stuckStateTypes[number]
export function isStuckStateType(value: string): value is StuckStateType {
return stuckStateTypes.includes(value as StuckStateType)
}
export function isPausedStateType(value: unknown): boolean {
return typeof value === 'string' && value === 'paused'
}
export function isRunningStateType(value: unknown): boolean {
return typeof value === 'string' && value === 'running'
}