Add function that validates whether a given value is a correct vcabulary
[arvados-workbench2.git] / src / models / vocabulary.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { isObject, has, every } from 'lodash/fp';
6
7 export interface Vocabulary {
8     strict: boolean;
9     tags: Tag[];
10 }
11
12 export interface Tag {
13     strict: boolean;
14     values: string[];
15 }
16
17 const VOCABULARY_VALIDATORS = [
18     isObject,
19     has('strict'),
20     has('tags'),
21 ];
22
23 export const isVocabulary = (value: any) =>
24     every(validator => validator(value), VOCABULARY_VALIDATORS);