@defra/forms-model 3.0.168 → 3.0.170
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/components/component-types.js +47 -46
- package/dist/module/components/component-types.js.map +1 -1
- package/dist/module/components/enums.js +31 -24
- package/dist/module/components/enums.js.map +1 -1
- package/dist/module/components/index.js +1 -2
- package/dist/module/components/index.js.map +1 -1
- package/dist/module/components/types.js.map +1 -1
- package/dist/module/conditions/condition-field.js.map +1 -1
- package/dist/module/conditions/condition-operators.js +12 -11
- package/dist/module/conditions/condition-operators.js.map +1 -1
- package/dist/module/conditions/condition-ref.js +2 -2
- package/dist/module/conditions/condition-ref.js.map +1 -1
- package/dist/module/conditions/condition-value-abstract.js +5 -13
- package/dist/module/conditions/condition-value-abstract.js.map +1 -1
- package/dist/module/conditions/condition-values.js +18 -12
- package/dist/module/conditions/condition-values.js.map +1 -1
- package/dist/module/conditions/condition.js +4 -4
- package/dist/module/conditions/condition.js.map +1 -1
- package/dist/module/conditions/enums.js +5 -0
- package/dist/module/conditions/enums.js.map +1 -1
- package/dist/module/conditions/index.js +1 -1
- package/dist/module/conditions/index.js.map +1 -1
- package/dist/module/form/form-definition/index.js +4 -3
- package/dist/module/form/form-definition/index.js.map +1 -1
- package/dist/module/index.js +0 -1
- package/dist/module/index.js.map +1 -1
- package/dist/types/components/component-types.d.ts.map +1 -1
- package/dist/types/components/enums.d.ts +8 -2
- package/dist/types/components/enums.d.ts.map +1 -1
- package/dist/types/components/index.d.ts +1 -2
- package/dist/types/components/index.d.ts.map +1 -1
- package/dist/types/components/types.d.ts +46 -47
- package/dist/types/components/types.d.ts.map +1 -1
- package/dist/types/conditions/condition-field.d.ts +1 -1
- package/dist/types/conditions/condition-operators.d.ts +2 -1
- package/dist/types/conditions/condition-operators.d.ts.map +1 -1
- package/dist/types/conditions/condition-ref.d.ts.map +1 -1
- package/dist/types/conditions/condition-value-abstract.d.ts +3 -5
- package/dist/types/conditions/condition-value-abstract.d.ts.map +1 -1
- package/dist/types/conditions/condition-values.d.ts +21 -12
- package/dist/types/conditions/condition-values.d.ts.map +1 -1
- package/dist/types/conditions/condition.d.ts +1 -1
- package/dist/types/conditions/condition.d.ts.map +1 -1
- package/dist/types/conditions/enums.d.ts +4 -0
- package/dist/types/conditions/enums.d.ts.map +1 -1
- package/dist/types/conditions/index.d.ts +1 -1
- package/dist/types/conditions/index.d.ts.map +1 -1
- package/dist/types/form/form-definition/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/component-types.ts +47 -46
- package/src/components/enums.ts +9 -2
- package/src/components/index.ts +1 -2
- package/src/components/types.ts +68 -71
- package/src/conditions/condition-field.ts +1 -1
- package/src/conditions/condition-operators.ts +19 -15
- package/src/conditions/condition-ref.ts +4 -2
- package/src/conditions/condition-value-abstract.ts +8 -20
- package/src/conditions/condition-values.ts +52 -31
- package/src/conditions/condition.ts +10 -8
- package/src/conditions/enums.ts +5 -0
- package/src/conditions/index.ts +1 -1
- package/src/form/form-definition/index.ts +20 -11
- package/src/index.ts +0 -1
- package/dist/module/components/conditional-component-types.js +0 -10
- package/dist/module/components/conditional-component-types.js.map +0 -1
- package/dist/module/conditions/condition-value-registration.js +0 -15
- package/dist/module/conditions/condition-value-registration.js.map +0 -1
- package/dist/module/form/form-configuration/index.js +0 -16
- package/dist/module/form/form-configuration/index.js.map +0 -1
- package/dist/types/components/conditional-component-types.d.ts +0 -3
- package/dist/types/components/conditional-component-types.d.ts.map +0 -1
- package/dist/types/conditions/condition-value-registration.d.ts +0 -10
- package/dist/types/conditions/condition-value-registration.d.ts.map +0 -1
- package/dist/types/form/form-configuration/index.d.ts +0 -8
- package/dist/types/form/form-configuration/index.d.ts.map +0 -1
- package/src/components/conditional-component-types.ts +0 -14
- package/src/conditions/condition-value-registration.ts +0 -18
- package/src/form/form-configuration/index.ts +0 -21
package/src/components/types.ts
CHANGED
@@ -1,34 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
| 'DateField'
|
6
|
-
| 'TimeField'
|
7
|
-
| 'DateTimeField'
|
8
|
-
| 'MonthYearField'
|
9
|
-
| 'DatePartsField'
|
10
|
-
| 'DateTimePartsField'
|
11
|
-
| 'SelectField'
|
12
|
-
| 'AutocompleteField'
|
13
|
-
| 'RadiosField'
|
14
|
-
| 'CheckboxesField'
|
15
|
-
| 'NumberField'
|
16
|
-
| 'UkAddressField'
|
17
|
-
| 'TelephoneNumberField'
|
18
|
-
| 'EmailAddressField'
|
19
|
-
| 'FileUploadField'
|
20
|
-
| 'Html'
|
21
|
-
| 'InsetText'
|
22
|
-
| 'Details'
|
23
|
-
| 'List'
|
24
|
-
| 'WebsiteField'
|
25
|
-
|
26
|
-
export type ComponentSubType = 'field' | 'content'
|
1
|
+
import {
|
2
|
+
type ComponentSubType,
|
3
|
+
type ComponentType
|
4
|
+
} from '~/src/components/enums.js'
|
27
5
|
|
28
6
|
export interface ConditionalComponent {
|
29
|
-
name:
|
7
|
+
name: string
|
30
8
|
title: string
|
31
|
-
subType:
|
9
|
+
subType: ComponentSubType.Field
|
32
10
|
}
|
33
11
|
|
34
12
|
export interface ContentOptions {
|
@@ -39,8 +17,16 @@ export interface ContentOptions {
|
|
39
17
|
* Types for Components JSON structure which are expected by engine and turned into actual form input/content/lists
|
40
18
|
*/
|
41
19
|
interface TextFieldBase {
|
42
|
-
|
43
|
-
|
20
|
+
type:
|
21
|
+
| ComponentType.EmailAddressField
|
22
|
+
| ComponentType.MultilineTextField
|
23
|
+
| ComponentType.NumberField
|
24
|
+
| ComponentType.TelephoneNumberField
|
25
|
+
| ComponentType.TextField
|
26
|
+
| ComponentType.UkAddressField
|
27
|
+
| ComponentType.WebsiteField
|
28
|
+
| ComponentType.YesNoField
|
29
|
+
subType?: ComponentSubType.Field
|
44
30
|
name: string
|
45
31
|
title: string
|
46
32
|
hint?: string
|
@@ -58,13 +44,13 @@ interface TextFieldBase {
|
|
58
44
|
min?: number
|
59
45
|
length?: number
|
60
46
|
regex?: string
|
61
|
-
error?:
|
47
|
+
error?: unknown
|
62
48
|
}
|
63
49
|
}
|
64
50
|
|
65
51
|
interface NumberFieldBase {
|
66
|
-
|
67
|
-
|
52
|
+
type: ComponentType
|
53
|
+
subType?: ComponentSubType.Field
|
68
54
|
name: string
|
69
55
|
title: string
|
70
56
|
hint: string
|
@@ -81,8 +67,13 @@ interface NumberFieldBase {
|
|
81
67
|
}
|
82
68
|
|
83
69
|
interface ListFieldBase {
|
84
|
-
|
85
|
-
|
70
|
+
type:
|
71
|
+
| ComponentType.AutocompleteField
|
72
|
+
| ComponentType.CheckboxesField
|
73
|
+
| ComponentType.List
|
74
|
+
| ComponentType.RadiosField
|
75
|
+
| ComponentType.SelectField
|
76
|
+
subType?: ComponentSubType.Content | ComponentSubType.ListField
|
86
77
|
name: string
|
87
78
|
title: string
|
88
79
|
options: {
|
@@ -96,22 +87,28 @@ interface ListFieldBase {
|
|
96
87
|
allowPrePopulation?: boolean
|
97
88
|
}
|
98
89
|
list: string
|
99
|
-
schema:
|
90
|
+
schema: object
|
100
91
|
}
|
101
92
|
|
102
93
|
interface ContentFieldBase {
|
103
|
-
|
104
|
-
|
94
|
+
type: ComponentType.Details | ComponentType.Html | ComponentType.InsetText
|
95
|
+
subType?: ComponentSubType.Content
|
105
96
|
name: string
|
106
97
|
title: string
|
107
98
|
content: string
|
108
99
|
options: ContentOptions
|
109
|
-
schema
|
100
|
+
schema?: object
|
110
101
|
}
|
111
102
|
|
112
103
|
interface DateFieldBase {
|
113
|
-
|
114
|
-
|
104
|
+
type:
|
105
|
+
| ComponentType.DateField
|
106
|
+
| ComponentType.DatePartsField
|
107
|
+
| ComponentType.DateTimeField
|
108
|
+
| ComponentType.DateTimePartsField
|
109
|
+
| ComponentType.MonthYearField
|
110
|
+
| ComponentType.TimeField
|
111
|
+
subType?: ComponentSubType.Field
|
115
112
|
name: string
|
116
113
|
title: string
|
117
114
|
hint: string
|
@@ -123,45 +120,45 @@ interface DateFieldBase {
|
|
123
120
|
maxDaysInPast?: number
|
124
121
|
exposeToContext?: boolean
|
125
122
|
}
|
126
|
-
schema:
|
123
|
+
schema: object
|
127
124
|
}
|
128
125
|
|
129
126
|
// Text Fields
|
130
127
|
export interface TextFieldComponent extends TextFieldBase {
|
131
|
-
type:
|
128
|
+
type: ComponentType.TextField
|
132
129
|
options: TextFieldBase['options'] & {
|
133
130
|
customValidationMessage?: string
|
134
131
|
}
|
135
132
|
}
|
136
133
|
|
137
134
|
export interface EmailAddressFieldComponent extends TextFieldBase {
|
138
|
-
type:
|
135
|
+
type: ComponentType.EmailAddressField
|
139
136
|
}
|
140
137
|
|
141
138
|
export interface NumberFieldComponent extends NumberFieldBase {
|
142
|
-
type:
|
139
|
+
type: ComponentType.NumberField
|
143
140
|
}
|
144
141
|
|
145
142
|
export interface WebsiteFieldComponent extends TextFieldBase {
|
146
|
-
type:
|
143
|
+
type: ComponentType.WebsiteField
|
147
144
|
options: TextFieldBase['options'] & {
|
148
145
|
customValidationMessage?: string
|
149
146
|
}
|
150
147
|
}
|
151
148
|
|
152
149
|
export interface TelephoneNumberFieldComponent extends TextFieldBase {
|
153
|
-
type:
|
150
|
+
type: ComponentType.TelephoneNumberField
|
154
151
|
options: TextFieldBase['options'] & {
|
155
152
|
customValidationMessage?: string
|
156
153
|
}
|
157
154
|
}
|
158
155
|
|
159
156
|
export interface YesNoFieldComponent extends TextFieldBase {
|
160
|
-
type:
|
157
|
+
type: ComponentType.YesNoField
|
161
158
|
}
|
162
159
|
|
163
160
|
export interface MultilineTextFieldComponent extends TextFieldBase {
|
164
|
-
type:
|
161
|
+
type: ComponentType.MultilineTextField
|
165
162
|
options: TextFieldBase['options'] & {
|
166
163
|
customValidationMessage?: string
|
167
164
|
rows?: number
|
@@ -174,8 +171,8 @@ export interface MultilineTextFieldComponent extends TextFieldBase {
|
|
174
171
|
}
|
175
172
|
|
176
173
|
export interface FileUploadFieldComponent {
|
177
|
-
|
178
|
-
|
174
|
+
type: ComponentType.FileUploadField
|
175
|
+
subType?: ComponentSubType.Field
|
179
176
|
name: string
|
180
177
|
title: string
|
181
178
|
hint: string
|
@@ -187,75 +184,75 @@ export interface FileUploadFieldComponent {
|
|
187
184
|
exposeToContext?: boolean
|
188
185
|
imageQualityPlayback?: boolean
|
189
186
|
}
|
190
|
-
schema:
|
187
|
+
schema: object
|
191
188
|
}
|
192
189
|
|
193
190
|
export interface UkAddressFieldComponent extends TextFieldBase {
|
194
|
-
type:
|
191
|
+
type: ComponentType.UkAddressField
|
195
192
|
}
|
196
193
|
|
197
194
|
// Date Fields
|
198
195
|
export interface DateFieldComponent extends DateFieldBase {
|
199
|
-
type:
|
196
|
+
type: ComponentType.DateField
|
200
197
|
}
|
201
198
|
|
202
199
|
export interface DateTimeFieldComponent extends DateFieldBase {
|
203
|
-
type:
|
200
|
+
type: ComponentType.DateTimeField
|
204
201
|
}
|
205
202
|
|
206
203
|
export interface DatePartsFieldFieldComponent extends DateFieldBase {
|
207
|
-
type:
|
204
|
+
type: ComponentType.DatePartsField
|
208
205
|
}
|
209
206
|
|
210
207
|
export interface MonthYearFieldComponent extends DateFieldBase {
|
211
|
-
type:
|
208
|
+
type: ComponentType.MonthYearField
|
212
209
|
}
|
213
210
|
|
214
211
|
export interface DateTimePartsFieldComponent extends DateFieldBase {
|
215
|
-
type:
|
212
|
+
type: ComponentType.DateTimePartsField
|
216
213
|
}
|
217
214
|
|
218
215
|
export interface TimeFieldComponent extends DateFieldBase {
|
219
|
-
type:
|
216
|
+
type: ComponentType.TimeField
|
220
217
|
}
|
221
218
|
|
222
219
|
// Content Fields
|
223
220
|
export interface DetailsComponent extends ContentFieldBase {
|
224
|
-
type:
|
221
|
+
type: ComponentType.Details
|
225
222
|
}
|
226
223
|
|
227
224
|
export interface HtmlComponent extends ContentFieldBase {
|
228
|
-
type:
|
225
|
+
type: ComponentType.Html
|
229
226
|
}
|
230
227
|
|
231
228
|
export interface InsetTextComponent extends ContentFieldBase {
|
232
|
-
type:
|
229
|
+
type: ComponentType.InsetText
|
233
230
|
}
|
234
231
|
|
235
232
|
// List Fields
|
236
233
|
export interface ListComponent extends ListFieldBase {
|
237
|
-
type:
|
234
|
+
type: ComponentType.List
|
238
235
|
}
|
239
236
|
|
240
237
|
export interface AutocompleteFieldComponent extends ListFieldBase {
|
241
|
-
type:
|
242
|
-
subType?:
|
238
|
+
type: ComponentType.AutocompleteField
|
239
|
+
subType?: ComponentSubType.ListField
|
243
240
|
}
|
244
241
|
|
245
242
|
export interface CheckboxesFieldComponent extends ListFieldBase {
|
246
|
-
type:
|
247
|
-
subType?:
|
243
|
+
type: ComponentType.CheckboxesField
|
244
|
+
subType?: ComponentSubType.ListField
|
248
245
|
}
|
249
246
|
|
250
247
|
export interface RadiosFieldComponent extends ListFieldBase {
|
251
|
-
type:
|
252
|
-
subType?:
|
248
|
+
type: ComponentType.RadiosField
|
249
|
+
subType?: ComponentSubType.ListField
|
253
250
|
}
|
254
251
|
|
255
252
|
export interface SelectFieldComponent extends ListFieldBase {
|
256
|
-
type:
|
253
|
+
type: ComponentType.SelectField
|
254
|
+
subType?: ComponentSubType.ListField
|
257
255
|
options: ListFieldBase['options'] & { autocomplete?: string }
|
258
|
-
subType?: 'listField'
|
259
256
|
}
|
260
257
|
|
261
258
|
export type ComponentDef =
|
@@ -1,7 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
type ComponentDef
|
4
|
-
} from '~/src/components/types.js'
|
1
|
+
import { ComponentType } from '~/src/components/enums.js'
|
2
|
+
import { type ComponentDef } from '~/src/components/types.js'
|
5
3
|
import { type ConditionValueAbstract } from '~/src/conditions/condition-value-abstract.js'
|
6
4
|
import {
|
7
5
|
timeUnits,
|
@@ -44,44 +42,46 @@ const relativeTimeOperators = (units) => ({
|
|
44
42
|
})
|
45
43
|
|
46
44
|
export const customOperators = {
|
47
|
-
CheckboxesField: {
|
45
|
+
[ComponentType.CheckboxesField]: {
|
48
46
|
contains: reverseInline('in'),
|
49
47
|
'does not contain': not(reverseInline('in'))
|
50
48
|
},
|
51
|
-
NumberField: withDefaults({
|
49
|
+
[ComponentType.NumberField]: withDefaults({
|
52
50
|
'is at least': inline('>='),
|
53
51
|
'is at most': inline('<='),
|
54
52
|
'is less than': inline('<'),
|
55
53
|
'is more than': inline('>')
|
56
54
|
}),
|
57
|
-
DateField: Object.assign(
|
55
|
+
[ComponentType.DateField]: Object.assign(
|
58
56
|
{},
|
59
57
|
absoluteDateTimeOperators,
|
60
58
|
relativeTimeOperators(dateUnits)
|
61
59
|
),
|
62
|
-
TimeField: Object.assign(
|
60
|
+
[ComponentType.TimeField]: Object.assign(
|
63
61
|
{},
|
64
62
|
absoluteDateTimeOperators,
|
65
63
|
relativeTimeOperators(timeUnits)
|
66
64
|
),
|
67
|
-
DatePartsField: Object.assign(
|
65
|
+
[ComponentType.DatePartsField]: Object.assign(
|
68
66
|
{},
|
69
67
|
absoluteDateTimeOperators,
|
70
68
|
relativeTimeOperators(dateUnits)
|
71
69
|
),
|
72
|
-
DateTimeField: Object.assign(
|
70
|
+
[ComponentType.DateTimeField]: Object.assign(
|
73
71
|
{},
|
74
72
|
absoluteDateTimeOperators,
|
75
73
|
relativeTimeOperators(dateTimeUnits)
|
76
74
|
),
|
77
|
-
DateTimePartsField: Object.assign(
|
75
|
+
[ComponentType.DateTimePartsField]: Object.assign(
|
78
76
|
{},
|
79
77
|
absoluteDateTimeOperators,
|
80
78
|
relativeTimeOperators(dateTimeUnits)
|
81
79
|
),
|
82
|
-
TextField: withDefaults(textBasedFieldCustomisations),
|
83
|
-
MultilineTextField: withDefaults(
|
84
|
-
|
80
|
+
[ComponentType.TextField]: withDefaults(textBasedFieldCustomisations),
|
81
|
+
[ComponentType.MultilineTextField]: withDefaults(
|
82
|
+
textBasedFieldCustomisations
|
83
|
+
),
|
84
|
+
[ComponentType.EmailAddressField]: withDefaults(textBasedFieldCustomisations)
|
85
85
|
}
|
86
86
|
|
87
87
|
export function getOperatorNames(fieldType) {
|
@@ -137,9 +137,13 @@ function not(operatorDefinition) {
|
|
137
137
|
}
|
138
138
|
|
139
139
|
function formatValue(fieldType: ComponentType, value) {
|
140
|
-
if (
|
140
|
+
if (
|
141
|
+
fieldType === ComponentType.YesNoField ||
|
142
|
+
fieldType === ComponentType.NumberField
|
143
|
+
) {
|
141
144
|
return value
|
142
145
|
}
|
146
|
+
|
143
147
|
return `'${value}'`
|
144
148
|
}
|
145
149
|
|
@@ -13,11 +13,13 @@ export class ConditionRef extends ConditionAbstract {
|
|
13
13
|
super(coordinator)
|
14
14
|
|
15
15
|
if (typeof conditionName !== 'string') {
|
16
|
-
throw Error(
|
16
|
+
throw new Error("ConditionRef param 'conditionName' must be a string")
|
17
17
|
}
|
18
18
|
|
19
19
|
if (typeof conditionDisplayName !== 'string') {
|
20
|
-
throw Error(
|
20
|
+
throw new Error(
|
21
|
+
"ConditionRef param 'conditionDisplayName' must be a string"
|
22
|
+
)
|
21
23
|
}
|
22
24
|
|
23
25
|
this.conditionName = conditionName
|
@@ -1,31 +1,19 @@
|
|
1
|
-
import { Registration } from '~/src/conditions/condition-value-registration.js'
|
2
|
-
|
3
1
|
export class ConditionValueAbstract {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
throw new TypeError('Cannot construct ConditionValue instances directly')
|
9
|
-
}
|
10
|
-
|
11
|
-
if (!(registration instanceof Registration)) {
|
12
|
-
throw new TypeError(
|
13
|
-
'You must register your value type! Call registerValueType!'
|
14
|
-
)
|
15
|
-
}
|
16
|
-
|
17
|
-
this.type = registration.type
|
2
|
+
toPresentationString(): string {
|
3
|
+
throw new Error(
|
4
|
+
'Unsupported Operation. Method toPresentationString has not been implemented'
|
5
|
+
)
|
18
6
|
}
|
19
7
|
|
20
|
-
|
8
|
+
toExpression(): string {
|
21
9
|
throw new Error(
|
22
|
-
'Unsupported Operation. Method
|
10
|
+
'Unsupported Operation. Method toExpression has not been implemented'
|
23
11
|
)
|
24
12
|
}
|
25
13
|
|
26
|
-
|
14
|
+
clone() {
|
27
15
|
throw new Error(
|
28
|
-
'Unsupported Operation. Method
|
16
|
+
'Unsupported Operation. Method clone has not been implemented'
|
29
17
|
)
|
30
18
|
}
|
31
19
|
}
|
@@ -1,28 +1,32 @@
|
|
1
1
|
import { ConditionValueAbstract } from '~/src/conditions/condition-value-abstract.js'
|
2
|
-
import { Registration } from '~/src/conditions/condition-value-registration.js'
|
3
2
|
import {
|
4
3
|
type DateTimeUnitValues,
|
5
4
|
type DateUnits,
|
6
5
|
type TimeUnits
|
7
6
|
} from '~/src/conditions/types.js'
|
8
7
|
|
9
|
-
export class ConditionValue
|
8
|
+
export class ConditionValue
|
9
|
+
extends ConditionValueAbstract
|
10
|
+
implements ConditionValueFrom
|
11
|
+
{
|
12
|
+
type: 'Value'
|
10
13
|
value: string
|
11
14
|
display: string
|
12
15
|
|
13
16
|
constructor(value: string, display?: string) {
|
14
|
-
super(valueType)
|
15
|
-
|
16
17
|
if (!value || typeof value !== 'string') {
|
17
|
-
throw Error(
|
18
|
+
throw new Error("ConditionValue param 'value' must be a string")
|
18
19
|
}
|
19
20
|
|
20
21
|
if (display && typeof display !== 'string') {
|
21
|
-
throw Error(
|
22
|
+
throw new Error("ConditionValue param 'display' must be a string")
|
22
23
|
}
|
23
24
|
|
25
|
+
super()
|
26
|
+
|
27
|
+
this.type = 'Value'
|
24
28
|
this.value = value
|
25
|
-
this.display = display
|
29
|
+
this.display = display ?? value
|
26
30
|
}
|
27
31
|
|
28
32
|
toPresentationString() {
|
@@ -33,7 +37,7 @@ export class ConditionValue extends ConditionValueAbstract {
|
|
33
37
|
return this.value
|
34
38
|
}
|
35
39
|
|
36
|
-
static from(obj:
|
40
|
+
static from(obj: ConditionValue | ConditionValueFrom) {
|
37
41
|
return new ConditionValue(obj.value, obj.display)
|
38
42
|
}
|
39
43
|
|
@@ -42,9 +46,10 @@ export class ConditionValue extends ConditionValueAbstract {
|
|
42
46
|
}
|
43
47
|
}
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
export interface ConditionValueFrom {
|
50
|
+
value: string
|
51
|
+
display?: string
|
52
|
+
}
|
48
53
|
|
49
54
|
export enum DateDirections {
|
50
55
|
FUTURE = 'in the future',
|
@@ -69,7 +74,11 @@ export const dateTimeUnits: DateUnits & TimeUnits = Object.assign(
|
|
69
74
|
timeUnits
|
70
75
|
)
|
71
76
|
|
72
|
-
export class RelativeTimeValue
|
77
|
+
export class RelativeTimeValue
|
78
|
+
extends ConditionValueAbstract
|
79
|
+
implements RelativeTimeValueFrom
|
80
|
+
{
|
81
|
+
type: 'RelativeTime'
|
73
82
|
timePeriod: string
|
74
83
|
timeUnit: DateTimeUnitValues
|
75
84
|
direction: DateDirections
|
@@ -81,10 +90,8 @@ export class RelativeTimeValue extends ConditionValueAbstract {
|
|
81
90
|
direction: DateDirections,
|
82
91
|
timeOnly = false
|
83
92
|
) {
|
84
|
-
super(relativeTimeValueType)
|
85
|
-
|
86
93
|
if (typeof timePeriod !== 'string') {
|
87
|
-
throw Error(
|
94
|
+
throw new Error("RelativeTimeValue param 'timePeriod' must be a string")
|
88
95
|
}
|
89
96
|
|
90
97
|
if (
|
@@ -92,13 +99,20 @@ export class RelativeTimeValue extends ConditionValueAbstract {
|
|
92
99
|
.map((unit) => unit.value)
|
93
100
|
.includes(timeUnit)
|
94
101
|
) {
|
95
|
-
throw Error(
|
102
|
+
throw new Error(
|
103
|
+
"RelativeTimeValue param 'dateTimeUnits' must only include DateTimeUnitValues keys"
|
104
|
+
)
|
96
105
|
}
|
97
106
|
|
98
107
|
if (!Object.values(DateDirections).includes(direction)) {
|
99
|
-
throw Error(
|
108
|
+
throw new Error(
|
109
|
+
"RelativeTimeValue param 'direction' must be from enum DateDirections"
|
110
|
+
)
|
100
111
|
}
|
101
112
|
|
113
|
+
super()
|
114
|
+
|
115
|
+
this.type = 'RelativeTime'
|
102
116
|
this.timePeriod = timePeriod
|
103
117
|
this.timeUnit = timeUnit
|
104
118
|
this.direction = direction
|
@@ -119,7 +133,7 @@ export class RelativeTimeValue extends ConditionValueAbstract {
|
|
119
133
|
: `dateForComparison(${timePeriod}, '${this.timeUnit}')`
|
120
134
|
}
|
121
135
|
|
122
|
-
static from(obj) {
|
136
|
+
static from(obj: RelativeTimeValue | RelativeTimeValueFrom) {
|
123
137
|
return new RelativeTimeValue(
|
124
138
|
obj.timePeriod,
|
125
139
|
obj.timeUnit,
|
@@ -133,18 +147,25 @@ export class RelativeTimeValue extends ConditionValueAbstract {
|
|
133
147
|
}
|
134
148
|
}
|
135
149
|
|
136
|
-
export
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
| Pick<ConditionValue, 'type' | 'value' | 'display'>
|
143
|
-
| Pick<
|
144
|
-
RelativeTimeValue,
|
145
|
-
'type' | 'timePeriod' | 'timeUnit' | 'direction' | 'timeOnly'
|
146
|
-
>
|
150
|
+
export interface RelativeTimeValueFrom {
|
151
|
+
timePeriod: string
|
152
|
+
timeUnit: DateTimeUnitValues
|
153
|
+
direction: DateDirections
|
154
|
+
timeOnly: boolean
|
155
|
+
}
|
147
156
|
|
148
|
-
export function conditionValueFrom(
|
149
|
-
|
157
|
+
export function conditionValueFrom(
|
158
|
+
obj:
|
159
|
+
| ConditionValue
|
160
|
+
| RelativeTimeValue
|
161
|
+
| ({ type: 'Value' } & ConditionValueFrom)
|
162
|
+
| ({ type: 'RelativeTime' } & RelativeTimeValueFrom)
|
163
|
+
) {
|
164
|
+
switch (obj.type) {
|
165
|
+
case 'Value':
|
166
|
+
return ConditionValue.from(obj)
|
167
|
+
|
168
|
+
case 'RelativeTime':
|
169
|
+
return RelativeTimeValue.from(obj)
|
170
|
+
}
|
150
171
|
}
|
@@ -14,23 +14,25 @@ export class Condition extends ConditionAbstract {
|
|
14
14
|
value: ConditionValue | RelativeTimeValue
|
15
15
|
|
16
16
|
constructor(
|
17
|
-
field
|
18
|
-
operator
|
19
|
-
value
|
17
|
+
field?: ConditionField,
|
18
|
+
operator?: string,
|
19
|
+
value?: ConditionValue | RelativeTimeValue,
|
20
20
|
coordinator?: Coordinator
|
21
21
|
) {
|
22
|
-
super(coordinator)
|
23
|
-
|
24
22
|
if (!(field instanceof ConditionField)) {
|
25
|
-
throw Error(
|
23
|
+
throw new Error("Condition param 'field' must be ConditionField instance")
|
26
24
|
}
|
27
25
|
if (typeof operator !== 'string') {
|
28
|
-
throw Error(
|
26
|
+
throw new Error("Condition param 'operator' must be a string")
|
29
27
|
}
|
30
28
|
if (!(value instanceof ConditionValueAbstract)) {
|
31
|
-
throw Error(
|
29
|
+
throw new Error(
|
30
|
+
"Condition param 'field' must be ConditionValueAbstract instance"
|
31
|
+
)
|
32
32
|
}
|
33
33
|
|
34
|
+
super(coordinator)
|
35
|
+
|
34
36
|
this.field = field
|
35
37
|
this.operator = operator
|
36
38
|
this.value = value
|
package/src/conditions/enums.ts
CHANGED
package/src/conditions/index.ts
CHANGED
@@ -24,4 +24,4 @@ export { ConditionsModel } from '~/src/conditions/condition-model.js'
|
|
24
24
|
export { ConditionGroupDef } from '~/src/conditions/condition-group-def.js'
|
25
25
|
export { toExpression, toPresentationString } from '~/src/conditions/helpers.js'
|
26
26
|
|
27
|
-
export { Coordinator } from '~/src/conditions/enums.js'
|
27
|
+
export { ConditionType, Coordinator } from '~/src/conditions/enums.js'
|