-
Notifications
You must be signed in to change notification settings - Fork 1
/
item.ts
132 lines (105 loc) · 3.31 KB
/
item.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
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
126
127
128
129
130
131
132
import type { FormItem } from "./lform.ts";
export interface UniqueItem {
readonly questionCardinality: { min: 1; max: 1 };
}
export function isUniqueItem(i: FormItem): i is UniqueItem {
return i.questionCardinality?.min == 1 && i.questionCardinality?.max == 1;
}
export interface TextItem extends FormItem {
readonly dataType: "ST";
}
export function isTextItem(i: FormItem): i is TextItem {
return i.dataType == "ST";
}
export interface EmailAddressItem extends FormItem {
readonly dataType: "EMAIL" | "ST";
}
export interface StrictEmailAddressItem extends EmailAddressItem {
readonly dataType: "EMAIL";
}
export function isStrictEmailAddressItem(
i: FormItem,
): i is StrictEmailAddressItem {
return i.dataType == "EMAIL";
}
export interface PhoneItem extends FormItem {
readonly dataType: "PHONE" | "ST";
}
export interface StrictPhoneItem extends FormItem {
readonly dataType: "PHONE";
}
export interface ConstrainedListItem extends FormItem {
readonly dataType: "CNE";
}
export interface ExtensibleConstrainedListItem extends FormItem {
readonly dataType: "CWE";
}
export type UniqueTextItem = TextItem & UniqueItem;
export type UniqueEmailAddressItem = EmailAddressItem & UniqueItem;
export type UniqueStrictEmailAddressItem = StrictEmailAddressItem & UniqueItem;
export type UniquePhoneItem = PhoneItem & UniqueItem;
export type UniqueStrictPhoneItem = StrictPhoneItem & UniqueItem;
export interface MultiLineTextItem extends FormItem {
readonly dataType: "TX";
}
export function isMultiLineTextItem(i: FormItem): i is MultiLineTextItem {
return i.dataType == "TX";
}
export type UniqueMultiLineTextItem = MultiLineTextItem & UniqueItem;
export interface DateItem extends FormItem {
readonly dataType: "DT";
}
export function isDateItem(i: FormItem): i is DateItem {
return i.dataType == "DT";
}
export type UniqueDateItem = DateItem & UniqueItem;
export interface RequiredSingleAnswer {
readonly answerCardinality: { min: 0 | 1; max: 1 };
readonly editable?: 1 | string;
}
export interface RequiredMultipleAnswers {
readonly answerCardinality: { min: 1; max: "*" };
}
export type RequiredUniqueTextItem = UniqueTextItem & RequiredSingleAnswer;
export interface ConstrainedListItemValue extends FormItem {
readonly text: string;
readonly code?: string | number;
readonly system?: string | null;
readonly label?: string | null;
readonly score?: string | null | number;
}
export interface ContactAddressItem extends FormItem {
readonly items: [
HouseOrBuilding,
TownOrCity,
StateOrProvince,
ZipOrPostal,
CountryOrRegion,
];
}
export interface HouseOrBuilding extends FormItem {
readonly dataType?: "ST";
}
export interface TownOrCity extends FormItem {
readonly dataType?: "ST";
}
export interface StateOrProvince extends FormItem {
readonly dataType: "ST";
}
export interface ZipOrPostal extends FormItem {
readonly dataType: "ST" | "NUMBER";
}
export interface CountryOrRegion extends FormItem {
readonly dataType: "ST";
}
export interface CurrencyItem extends FormItem {
readonly dataType?: "ST";
}
export type UniqueCurrencyItem = CurrencyItem & UniqueItem;
export interface UrlItem extends FormItem {
readonly dataType: "URL";
}
export function isUrlItem(i: FormItem): i is UrlItem {
return i.dataType == "URL";
}
export type UniqueUrlItem = UrlItem & UniqueItem;