-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry-specs.ts
55 lines (44 loc) · 1.83 KB
/
entry-specs.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {EntryType, MarkdownKnowledgeEntry, TooltipKnowledgeEntry, UnsupportedEntry} from './entry-types';
import {
KnowledgeBaseEntrySpecification,
KnowledgeCompoundEntry,
SubEntries
} from './entry-types';
export interface SimpleEntryOptions {
entryKey?: string;
}
export const textEntry = (options: SimpleEntryOptions = {}): KnowledgeBaseEntrySpecification<string> => ({
entryType: EntryType.PlainText,
entryKey: options.entryKey,
});
export interface TextWithPlaceholdersEntryOptions<TReplacements extends Record<string, string> = Record<string, string>> {
entryKey?: string;
replacements: TReplacements;
}
export const textWithPlaceholdersEntry = <TReplacements extends Record<string, string>>(options: TextWithPlaceholdersEntryOptions<TReplacements>)
: KnowledgeBaseEntrySpecification<string> => ({
entryType: EntryType.TextWithPlaceholders,
entryKey: options.entryKey,
replacements: options.replacements
});
export const tooltipEntry = (options: SimpleEntryOptions = {}): KnowledgeBaseEntrySpecification<TooltipKnowledgeEntry> => ({
entryType: EntryType.Tooltip,
entryKey: options.entryKey,
});
export const markdownEntry = (options: SimpleEntryOptions = {}): KnowledgeBaseEntrySpecification<MarkdownKnowledgeEntry> => ({
entryType: EntryType.Markdown,
entryKey: options.entryKey,
});
export interface CompoundEntryOptions<T extends KnowledgeCompoundEntry> {
entryKey?: string;
subEntries: SubEntries<T>;
}
export const compoundEntry = <T extends KnowledgeCompoundEntry>(
options: CompoundEntryOptions<T>): KnowledgeBaseEntrySpecification<T> => ({
entryType: EntryType.Compound,
subEntries: options.subEntries
});
export const unsupportedEntry = (options: SimpleEntryOptions = {}): KnowledgeBaseEntrySpecification<UnsupportedEntry> => ({
entryType: EntryType.Unsupported,
entryKey: options.entryKey,
});