1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { Resource, ResourceKind } from "./resource";
6 import { safeLoad } from 'js-yaml';
8 export interface WorkflowResource extends Resource {
9 kind: ResourceKind.WORKFLOW;
14 export interface WorkflowResoruceDefinition {
16 $graph: Array<Workflow | CommandLineTool>;
18 export interface Workflow {
22 inputs: CommandInputParameter[];
27 export interface CommandLineTool {
28 class: 'CommandLineTool';
30 inputs: CommandInputParameter[];
34 export type CommandInputParameter =
35 BooleanCommandInputParameter |
36 IntCommandInputParameter |
37 LongCommandInputParameter |
38 FloatCommandInputParameter |
39 DoubleCommandInputParameter |
40 StringCommandInputParameter |
41 FileCommandInputParameter |
42 DirectoryCommandInputParameter |
43 StringArrayCommandInputParameter |
44 FileArrayCommandInputParameter |
45 DirectoryArrayCommandInputParameter |
46 EnumCommandInputParameter;
57 DIRECTORY = 'Directory',
60 export interface CommandInputEnumSchema {
67 export interface CommandInputArraySchema<ItemType> {
73 export interface File {
80 export interface Directory {
81 class: CWLType.DIRECTORY;
87 export interface GenericCommandInputParameter<Type, Value> {
90 doc?: string | string[];
92 type?: Type | Array<Type | CWLType.NULL>;
94 export type GenericArrayCommandInputParameter<Type, Value> = GenericCommandInputParameter<CommandInputArraySchema<Type>, Value[]>;
96 export type BooleanCommandInputParameter = GenericCommandInputParameter<CWLType.BOOLEAN, boolean>;
97 export type IntCommandInputParameter = GenericCommandInputParameter<CWLType.INT, number>;
98 export type LongCommandInputParameter = GenericCommandInputParameter<CWLType.LONG, number>;
99 export type FloatCommandInputParameter = GenericCommandInputParameter<CWLType.FLOAT, number>;
100 export type DoubleCommandInputParameter = GenericCommandInputParameter<CWLType.DOUBLE, number>;
101 export type StringCommandInputParameter = GenericCommandInputParameter<CWLType.STRING, string>;
102 export type FileCommandInputParameter = GenericCommandInputParameter<CWLType.FILE, File>;
103 export type DirectoryCommandInputParameter = GenericCommandInputParameter<CWLType.DIRECTORY, Directory>;
104 export type EnumCommandInputParameter = GenericCommandInputParameter<CommandInputEnumSchema, string>;
106 export type StringArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.STRING, string>;
107 export type FileArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.FILE, File>;
108 export type DirectoryArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.DIRECTORY, Directory>;
110 export const parseWorkflowDefinition = (workflow: WorkflowResource): WorkflowResoruceDefinition => {
111 const definition = safeLoad(workflow.definition);
115 export const getWorkflowInputs = (workflowDefinition: WorkflowResoruceDefinition) => {
116 const mainWorkflow = workflowDefinition.$graph.find(item => item.class === 'Workflow' && item.id === '#main');
118 ? mainWorkflow.inputs
122 export const stringifyInputType = ({ type }: CommandInputParameter) => {
123 if (typeof type === 'string') {
125 } else if (type instanceof Array) {
126 return type.join(' | ');
127 } else if (typeof type === 'object') {
128 if (type.type === 'enum') {
130 } else if (type.type === 'array') {
131 return `${type.items}[]`;