-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoryBookmarkNode.ts
38 lines (32 loc) · 1.09 KB
/
StoryBookmarkNode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Element } from '../Element';
import { isBoolean, isEnum, isObject, isUuid } from '../validation';
export interface StoryBookmarkNode extends Element<typeof StoryBookmarkNode.TYPE> {
uuid: string;
story: {
uuid: string;
};
layout: `${StoryBookmarkNode.Layout}`;
show_thumbnail: boolean;
new_tab: boolean;
}
export namespace StoryBookmarkNode {
export const TYPE = 'story-bookmark';
export enum Layout {
VERTICAL = 'vertical',
HORIZONTAL = 'horizontal',
}
export function isStoryBookmarkNode(value: any): value is StoryBookmarkNode {
return Element.isElement(value, StoryBookmarkNode.TYPE);
}
export function validateStoryBookmarkNode(value: any): StoryBookmarkNode | null {
const isValid =
isStoryBookmarkNode(value) &&
isUuid(value.uuid) &&
isObject(value.story) &&
isUuid(value.story.uuid) &&
isEnum(value.layout, Layout) &&
isBoolean(value.show_thumbnail) &&
isBoolean(value.new_tab);
return isValid ? value : null;
}
}