15067: Updates the vocabulary model to match the new format.
[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_tags: boolean;
9     tags: Record<string, Tag>;
10 }
11
12 export interface Label {
13     lang?: string;
14     label: string;
15 }
16
17 export interface TagValue {
18     labels: Label[];
19 }
20
21 export interface Tag {
22     strict?: boolean;
23     labels: Label[];
24     values?: Record<string, TagValue>;
25 }
26
27 const VOCABULARY_VALIDATORS = [
28     isObject,
29     has('strict_tags'),
30     has('tags'),
31 ];
32
33 export const isVocabulary = (value: any) =>
34     every(validator => validator(value), VOCABULARY_VALIDATORS);