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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
import { Config } from "../config.ts";
import { SlideError } from "../errors.ts";
import { Revision, stringToDate } from "../revision.ts";
export type Slide = {
sourceFilePath: string;
uuid: string;
title: string;
event: string;
talkType: string;
slideLink: string;
tags: string[];
revisions: Revision[];
};
type Toml = {
slide: {
uuid: string;
title: string;
event: string;
talkType: string;
link: string;
tags: string[];
revisions: {
date: string;
remark: string;
}[];
};
};
export function createNewSlideFromTomlRootObject(
root: Toml,
sourceFilePath: string,
_config: Config,
): Slide {
const slide = root.slide ?? null;
if (root.slide === undefined) {
throw new SlideError(
`[slide.new] 'slide' field not found`,
);
}
const uuid = slide.uuid ?? null;
if (!uuid) {
throw new SlideError(
`[slide.new] 'slide.uuid' field not found`,
);
}
const title = slide.title ?? null;
if (!title) {
throw new SlideError(
`[slide.new] 'slide.title' field not found`,
);
}
const event = slide.event ?? null;
if (!event) {
throw new SlideError(
`[slide.new] 'slide.event' field not found`,
);
}
const talkType = slide.talkType ?? null;
if (!talkType) {
throw new SlideError(
`[slide.new] 'slide.talkType' field not found`,
);
}
const link = slide.link ?? null;
if (!link) {
throw new SlideError(
`[slide.new] 'slide.link' field not found`,
);
}
const tags = slide.tags ?? [];
const revisions = slide.revisions ?? null;
if (!revisions) {
throw new SlideError(
`[slide.new] 'slide.revisions' field not found`,
);
}
if (revisions.length === 0) {
throw new SlideError(
`[slide.new] 'slide.revisions' field not found`,
);
}
const revisions_ = revisions.map(
(x: { date: string; remark: string; isInternal?: boolean }, i: number) => {
const date = x.date ?? null;
if (!date) {
throw new SlideError(
`[slide.new] 'date' field not found`,
);
}
const remark = x.remark ?? null;
if (!remark) {
throw new SlideError(
`[slide.new] 'remark' field not found`,
);
}
const isInternal = x.isInternal ?? false;
return {
number: i + 1,
date: stringToDate(date),
remark,
isInternal,
};
},
);
return {
sourceFilePath: sourceFilePath,
uuid: uuid,
title: title,
event: event,
talkType: talkType,
slideLink: link,
tags: tags,
revisions: revisions_,
};
}
|