@defra/forms-model 3.0.2
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/LICENCE +8 -0
- package/README.md +22 -0
- package/dist/browser/components/component-types.d.ts +3 -0
- package/dist/browser/components/component-types.d.ts.map +1 -0
- package/dist/browser/components/component-types.js +220 -0
- package/dist/browser/components/component-types.js.map +1 -0
- package/dist/browser/components/conditional-component-types.d.ts +3 -0
- package/dist/browser/components/conditional-component-types.d.ts.map +1 -0
- package/dist/browser/components/conditional-component-types.js +28 -0
- package/dist/browser/components/conditional-component-types.js.map +1 -0
- package/dist/browser/components/index.d.ts +4 -0
- package/dist/browser/components/index.d.ts.map +1 -0
- package/dist/browser/components/index.js +45 -0
- package/dist/browser/components/index.js.map +1 -0
- package/dist/browser/components/types.d.ts +244 -0
- package/dist/browser/components/types.d.ts.map +1 -0
- package/dist/browser/components/types.js +56 -0
- package/dist/browser/components/types.js.map +1 -0
- package/dist/browser/conditions/condition-abstract.d.ts +16 -0
- package/dist/browser/conditions/condition-abstract.d.ts.map +1 -0
- package/dist/browser/conditions/condition-abstract.js +62 -0
- package/dist/browser/conditions/condition-abstract.js.map +1 -0
- package/dist/browser/conditions/condition-field.d.ts +13 -0
- package/dist/browser/conditions/condition-field.d.ts.map +1 -0
- package/dist/browser/conditions/condition-field.js +45 -0
- package/dist/browser/conditions/condition-field.js.map +1 -0
- package/dist/browser/conditions/condition-group-def.d.ts +10 -0
- package/dist/browser/conditions/condition-group-def.d.ts.map +1 -0
- package/dist/browser/conditions/condition-group-def.js +45 -0
- package/dist/browser/conditions/condition-group-def.js.map +1 -0
- package/dist/browser/conditions/condition-group.d.ts +15 -0
- package/dist/browser/conditions/condition-group.d.ts.map +1 -0
- package/dist/browser/conditions/condition-group.js +64 -0
- package/dist/browser/conditions/condition-group.js.map +1 -0
- package/dist/browser/conditions/condition-model.d.ts +41 -0
- package/dist/browser/conditions/condition-model.d.ts.map +1 -0
- package/dist/browser/conditions/condition-model.js +214 -0
- package/dist/browser/conditions/condition-model.js.map +1 -0
- package/dist/browser/conditions/condition-operators.d.ts +248 -0
- package/dist/browser/conditions/condition-operators.d.ts.map +1 -0
- package/dist/browser/conditions/condition-operators.js +132 -0
- package/dist/browser/conditions/condition-operators.js.map +1 -0
- package/dist/browser/conditions/condition-ref.d.ts +12 -0
- package/dist/browser/conditions/condition-ref.d.ts.map +1 -0
- package/dist/browser/conditions/condition-ref.js +51 -0
- package/dist/browser/conditions/condition-ref.js.map +1 -0
- package/dist/browser/conditions/condition-value-abstract.d.ts +8 -0
- package/dist/browser/conditions/condition-value-abstract.d.ts.map +1 -0
- package/dist/browser/conditions/condition-value-abstract.js +41 -0
- package/dist/browser/conditions/condition-value-abstract.js.map +1 -0
- package/dist/browser/conditions/condition-value-registration.d.ts +10 -0
- package/dist/browser/conditions/condition-value-registration.d.ts.map +1 -0
- package/dist/browser/conditions/condition-value-registration.js +37 -0
- package/dist/browser/conditions/condition-value-registration.js.map +1 -0
- package/dist/browser/conditions/condition-values.d.ts +38 -0
- package/dist/browser/conditions/condition-values.d.ts.map +1 -0
- package/dist/browser/conditions/condition-values.js +127 -0
- package/dist/browser/conditions/condition-values.js.map +1 -0
- package/dist/browser/conditions/condition.d.ts +15 -0
- package/dist/browser/conditions/condition.d.ts.map +1 -0
- package/dist/browser/conditions/condition.js +56 -0
- package/dist/browser/conditions/condition.js.map +1 -0
- package/dist/browser/conditions/helpers.d.ts +3 -0
- package/dist/browser/conditions/helpers.d.ts.map +1 -0
- package/dist/browser/conditions/helpers.js +26 -0
- package/dist/browser/conditions/helpers.js.map +1 -0
- package/dist/browser/conditions/index.d.ts +11 -0
- package/dist/browser/conditions/index.d.ts.map +1 -0
- package/dist/browser/conditions/index.js +144 -0
- package/dist/browser/conditions/index.js.map +1 -0
- package/dist/browser/conditions/inline-condition-model.d.ts +86 -0
- package/dist/browser/conditions/inline-condition-model.d.ts.map +1 -0
- package/dist/browser/conditions/inline-condition-model.js +418 -0
- package/dist/browser/conditions/inline-condition-model.js.map +1 -0
- package/dist/browser/conditions/inline-condition-operators.d.ts +175 -0
- package/dist/browser/conditions/inline-condition-operators.d.ts.map +1 -0
- package/dist/browser/conditions/inline-condition-operators.js +132 -0
- package/dist/browser/conditions/inline-condition-operators.js.map +1 -0
- package/dist/browser/conditions/inline-condition-values.d.ts +93 -0
- package/dist/browser/conditions/inline-condition-values.d.ts.map +1 -0
- package/dist/browser/conditions/inline-condition-values.js +159 -0
- package/dist/browser/conditions/inline-condition-values.js.map +1 -0
- package/dist/browser/conditions/types.d.ts +38 -0
- package/dist/browser/conditions/types.d.ts.map +1 -0
- package/dist/browser/conditions/types.js +24 -0
- package/dist/browser/conditions/types.js.map +1 -0
- package/dist/browser/data-model/conditions-wrapper.d.ts +19 -0
- package/dist/browser/data-model/conditions-wrapper.d.ts.map +1 -0
- package/dist/browser/data-model/conditions-wrapper.js +49 -0
- package/dist/browser/data-model/conditions-wrapper.js.map +1 -0
- package/dist/browser/data-model/index.d.ts +4 -0
- package/dist/browser/data-model/index.d.ts.map +1 -0
- package/dist/browser/data-model/index.js +66 -0
- package/dist/browser/data-model/index.js.map +1 -0
- package/dist/browser/data-model/input-wrapper.d.ts +16 -0
- package/dist/browser/data-model/input-wrapper.d.ts.map +1 -0
- package/dist/browser/data-model/input-wrapper.js +49 -0
- package/dist/browser/data-model/input-wrapper.js.map +1 -0
- package/dist/browser/data-model/types.d.ts +153 -0
- package/dist/browser/data-model/types.d.ts.map +1 -0
- package/dist/browser/data-model/types.js +34 -0
- package/dist/browser/data-model/types.js.map +1 -0
- package/dist/browser/form/form-configuration.d.ts +8 -0
- package/dist/browser/form/form-configuration.d.ts.map +1 -0
- package/dist/browser/form/form-configuration.js +38 -0
- package/dist/browser/form/form-configuration.js.map +1 -0
- package/dist/browser/form/index.d.ts +2 -0
- package/dist/browser/form/index.d.ts.map +1 -0
- package/dist/browser/form/index.js +24 -0
- package/dist/browser/form/index.js.map +1 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +138 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/migration/index.d.ts +2 -0
- package/dist/browser/migration/index.d.ts.map +1 -0
- package/dist/browser/migration/index.js +24 -0
- package/dist/browser/migration/index.js.map +1 -0
- package/dist/browser/migration/migration.0-2.d.ts +3 -0
- package/dist/browser/migration/migration.0-2.d.ts.map +1 -0
- package/dist/browser/migration/migration.0-2.js +65 -0
- package/dist/browser/migration/migration.0-2.js.map +1 -0
- package/dist/browser/migration/migration.1-2.d.ts +3 -0
- package/dist/browser/migration/migration.1-2.d.ts.map +1 -0
- package/dist/browser/migration/migration.1-2.js +108 -0
- package/dist/browser/migration/migration.1-2.js.map +1 -0
- package/dist/browser/migration/types.d.ts +2 -0
- package/dist/browser/migration/types.d.ts.map +1 -0
- package/dist/browser/migration/types.js +16 -0
- package/dist/browser/migration/types.js.map +1 -0
- package/dist/browser/migration/whichMigrations.d.ts +7 -0
- package/dist/browser/migration/whichMigrations.d.ts.map +1 -0
- package/dist/browser/migration/whichMigrations.js +38 -0
- package/dist/browser/migration/whichMigrations.js.map +1 -0
- package/dist/browser/schema/index.d.ts +2 -0
- package/dist/browser/schema/index.d.ts.map +1 -0
- package/dist/browser/schema/index.js +30 -0
- package/dist/browser/schema/index.js.map +1 -0
- package/dist/browser/schema/schema.d.ts +20 -0
- package/dist/browser/schema/schema.d.ts.map +1 -0
- package/dist/browser/schema/schema.js +255 -0
- package/dist/browser/schema/schema.js.map +1 -0
- package/dist/browser/utils/helpers.d.ts +9 -0
- package/dist/browser/utils/helpers.d.ts.map +1 -0
- package/dist/browser/utils/helpers.js +48 -0
- package/dist/browser/utils/helpers.js.map +1 -0
- package/dist/browser/utils/logger.d.ts +11 -0
- package/dist/browser/utils/logger.d.ts.map +1 -0
- package/dist/browser/utils/logger.js +46 -0
- package/dist/browser/utils/logger.js.map +1 -0
- package/dist/module/components/component-types.d.ts +3 -0
- package/dist/module/components/component-types.d.ts.map +1 -0
- package/dist/module/components/component-types.js +206 -0
- package/dist/module/components/component-types.js.map +1 -0
- package/dist/module/components/conditional-component-types.d.ts +3 -0
- package/dist/module/components/conditional-component-types.d.ts.map +1 -0
- package/dist/module/components/conditional-component-types.js +14 -0
- package/dist/module/components/conditional-component-types.js.map +1 -0
- package/dist/module/components/index.d.ts +4 -0
- package/dist/module/components/index.d.ts.map +1 -0
- package/dist/module/components/index.js +34 -0
- package/dist/module/components/index.js.map +1 -0
- package/dist/module/components/types.d.ts +244 -0
- package/dist/module/components/types.d.ts.map +1 -0
- package/dist/module/components/types.js +42 -0
- package/dist/module/components/types.js.map +1 -0
- package/dist/module/conditions/condition-abstract.d.ts +16 -0
- package/dist/module/conditions/condition-abstract.d.ts.map +1 -0
- package/dist/module/conditions/condition-abstract.js +45 -0
- package/dist/module/conditions/condition-abstract.js.map +1 -0
- package/dist/module/conditions/condition-field.d.ts +13 -0
- package/dist/module/conditions/condition-field.d.ts.map +1 -0
- package/dist/module/conditions/condition-field.js +26 -0
- package/dist/module/conditions/condition-field.js.map +1 -0
- package/dist/module/conditions/condition-group-def.d.ts +10 -0
- package/dist/module/conditions/condition-group-def.d.ts.map +1 -0
- package/dist/module/conditions/condition-group-def.js +26 -0
- package/dist/module/conditions/condition-group-def.js.map +1 -0
- package/dist/module/conditions/condition-group.d.ts +15 -0
- package/dist/module/conditions/condition-group.d.ts.map +1 -0
- package/dist/module/conditions/condition-group.js +47 -0
- package/dist/module/conditions/condition-group.js.map +1 -0
- package/dist/module/conditions/condition-model.d.ts +41 -0
- package/dist/module/conditions/condition-model.d.ts.map +1 -0
- package/dist/module/conditions/condition-model.js +199 -0
- package/dist/module/conditions/condition-model.js.map +1 -0
- package/dist/module/conditions/condition-operators.d.ts +248 -0
- package/dist/module/conditions/condition-operators.d.ts.map +1 -0
- package/dist/module/conditions/condition-operators.js +119 -0
- package/dist/module/conditions/condition-operators.js.map +1 -0
- package/dist/module/conditions/condition-ref.d.ts +12 -0
- package/dist/module/conditions/condition-ref.d.ts.map +1 -0
- package/dist/module/conditions/condition-ref.js +33 -0
- package/dist/module/conditions/condition-ref.js.map +1 -0
- package/dist/module/conditions/condition-value-abstract.d.ts +8 -0
- package/dist/module/conditions/condition-value-abstract.d.ts.map +1 -0
- package/dist/module/conditions/condition-value-abstract.js +24 -0
- package/dist/module/conditions/condition-value-abstract.js.map +1 -0
- package/dist/module/conditions/condition-value-registration.d.ts +10 -0
- package/dist/module/conditions/condition-value-registration.d.ts.map +1 -0
- package/dist/module/conditions/condition-value-registration.js +19 -0
- package/dist/module/conditions/condition-value-registration.js.map +1 -0
- package/dist/module/conditions/condition-values.d.ts +38 -0
- package/dist/module/conditions/condition-values.d.ts.map +1 -0
- package/dist/module/conditions/condition-values.js +106 -0
- package/dist/module/conditions/condition-values.js.map +1 -0
- package/dist/module/conditions/condition.d.ts +15 -0
- package/dist/module/conditions/condition.d.ts.map +1 -0
- package/dist/module/conditions/condition.js +40 -0
- package/dist/module/conditions/condition.js.map +1 -0
- package/dist/module/conditions/helpers.d.ts +3 -0
- package/dist/module/conditions/helpers.d.ts.map +1 -0
- package/dist/module/conditions/helpers.js +12 -0
- package/dist/module/conditions/helpers.js.map +1 -0
- package/dist/module/conditions/index.d.ts +11 -0
- package/dist/module/conditions/index.d.ts.map +1 -0
- package/dist/module/conditions/index.js +140 -0
- package/dist/module/conditions/index.js.map +1 -0
- package/dist/module/conditions/inline-condition-model.d.ts +86 -0
- package/dist/module/conditions/inline-condition-model.d.ts.map +1 -0
- package/dist/module/conditions/inline-condition-model.js +384 -0
- package/dist/module/conditions/inline-condition-model.js.map +1 -0
- package/dist/module/conditions/inline-condition-operators.d.ts +175 -0
- package/dist/module/conditions/inline-condition-operators.d.ts.map +1 -0
- package/dist/module/conditions/inline-condition-operators.js +119 -0
- package/dist/module/conditions/inline-condition-operators.js.map +1 -0
- package/dist/module/conditions/inline-condition-values.d.ts +93 -0
- package/dist/module/conditions/inline-condition-values.d.ts.map +1 -0
- package/dist/module/conditions/inline-condition-values.js +134 -0
- package/dist/module/conditions/inline-condition-values.js.map +1 -0
- package/dist/module/conditions/types.d.ts +38 -0
- package/dist/module/conditions/types.d.ts.map +1 -0
- package/dist/module/conditions/types.js +10 -0
- package/dist/module/conditions/types.js.map +1 -0
- package/dist/module/data-model/conditions-wrapper.d.ts +19 -0
- package/dist/module/data-model/conditions-wrapper.d.ts.map +1 -0
- package/dist/module/data-model/conditions-wrapper.js +30 -0
- package/dist/module/data-model/conditions-wrapper.js.map +1 -0
- package/dist/module/data-model/index.d.ts +4 -0
- package/dist/module/data-model/index.d.ts.map +1 -0
- package/dist/module/data-model/index.js +55 -0
- package/dist/module/data-model/index.js.map +1 -0
- package/dist/module/data-model/input-wrapper.d.ts +16 -0
- package/dist/module/data-model/input-wrapper.d.ts.map +1 -0
- package/dist/module/data-model/input-wrapper.js +25 -0
- package/dist/module/data-model/input-wrapper.js.map +1 -0
- package/dist/module/data-model/types.d.ts +153 -0
- package/dist/module/data-model/types.d.ts.map +1 -0
- package/dist/module/data-model/types.js +20 -0
- package/dist/module/data-model/types.js.map +1 -0
- package/dist/module/form/form-configuration.d.ts +8 -0
- package/dist/module/form/form-configuration.d.ts.map +1 -0
- package/dist/module/form/form-configuration.js +17 -0
- package/dist/module/form/form-configuration.js.map +1 -0
- package/dist/module/form/index.d.ts +2 -0
- package/dist/module/form/index.d.ts.map +1 -0
- package/dist/module/form/index.js +11 -0
- package/dist/module/form/index.js.map +1 -0
- package/dist/module/index.d.ts +12 -0
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +135 -0
- package/dist/module/index.js.map +1 -0
- package/dist/module/migration/index.d.ts +2 -0
- package/dist/module/migration/index.d.ts.map +1 -0
- package/dist/module/migration/index.js +11 -0
- package/dist/module/migration/index.js.map +1 -0
- package/dist/module/migration/migration.0-2.d.ts +3 -0
- package/dist/module/migration/migration.0-2.d.ts.map +1 -0
- package/dist/module/migration/migration.0-2.js +42 -0
- package/dist/module/migration/migration.0-2.js.map +1 -0
- package/dist/module/migration/migration.1-2.d.ts +3 -0
- package/dist/module/migration/migration.1-2.d.ts.map +1 -0
- package/dist/module/migration/migration.1-2.js +90 -0
- package/dist/module/migration/migration.1-2.js.map +1 -0
- package/dist/module/migration/types.d.ts +2 -0
- package/dist/module/migration/types.d.ts.map +1 -0
- package/dist/module/migration/types.js +1 -0
- package/dist/module/migration/types.js.map +1 -0
- package/dist/module/migration/whichMigrations.d.ts +7 -0
- package/dist/module/migration/whichMigrations.d.ts.map +1 -0
- package/dist/module/migration/whichMigrations.js +26 -0
- package/dist/module/migration/whichMigrations.js.map +1 -0
- package/dist/module/schema/index.d.ts +2 -0
- package/dist/module/schema/index.d.ts.map +1 -0
- package/dist/module/schema/index.js +17 -0
- package/dist/module/schema/index.js.map +1 -0
- package/dist/module/schema/schema.d.ts +20 -0
- package/dist/module/schema/schema.d.ts.map +1 -0
- package/dist/module/schema/schema.js +239 -0
- package/dist/module/schema/schema.js.map +1 -0
- package/dist/module/utils/helpers.d.ts +9 -0
- package/dist/module/utils/helpers.d.ts.map +1 -0
- package/dist/module/utils/helpers.js +35 -0
- package/dist/module/utils/helpers.js.map +1 -0
- package/dist/module/utils/logger.d.ts +11 -0
- package/dist/module/utils/logger.d.ts.map +1 -0
- package/dist/module/utils/logger.js +27 -0
- package/dist/module/utils/logger.js.map +1 -0
- package/package.json +35 -0
- package/src/components/component-types.ts +229 -0
- package/src/components/conditional-component-types.ts +14 -0
- package/src/components/index.ts +3 -0
- package/src/components/types.ts +362 -0
- package/src/conditions/condition-abstract.ts +59 -0
- package/src/conditions/condition-field.ts +29 -0
- package/src/conditions/condition-group-def.ts +29 -0
- package/src/conditions/condition-group.ts +61 -0
- package/src/conditions/condition-model.ts +314 -0
- package/src/conditions/condition-operators.ts +176 -0
- package/src/conditions/condition-ref.ts +47 -0
- package/src/conditions/condition-value-abstract.ts +31 -0
- package/src/conditions/condition-value-registration.ts +18 -0
- package/src/conditions/condition-values.ts +146 -0
- package/src/conditions/condition.ts +64 -0
- package/src/conditions/helpers.ts +7 -0
- package/src/conditions/index.ts +27 -0
- package/src/conditions/inline-condition-model.ts +550 -0
- package/src/conditions/inline-condition-operators.ts +166 -0
- package/src/conditions/inline-condition-values.ts +153 -0
- package/src/conditions/types.ts +30 -0
- package/src/data-model/conditions-wrapper.ts +42 -0
- package/src/data-model/index.ts +3 -0
- package/src/data-model/input-wrapper.ts +40 -0
- package/src/data-model/types.ts +179 -0
- package/src/form/form-configuration.ts +21 -0
- package/src/form/index.ts +1 -0
- package/src/index.ts +11 -0
- package/src/migration/index.ts +1 -0
- package/src/migration/migration.0-2.ts +29 -0
- package/src/migration/migration.1-2.ts +105 -0
- package/src/migration/types.ts +1 -0
- package/src/migration/whichMigrations.ts +23 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/schema.ts +300 -0
- package/src/utils/helpers.ts +37 -0
- package/src/utils/logger.ts +29 -0
@@ -0,0 +1,146 @@
|
|
1
|
+
import { ConditionValueAbstract } from './condition-value-abstract'
|
2
|
+
import { Registration } from './condition-value-registration'
|
3
|
+
import { DateTimeUnitValues, DateUnits, TimeUnits } from './types'
|
4
|
+
|
5
|
+
export class ConditionValue extends ConditionValueAbstract {
|
6
|
+
value: string
|
7
|
+
display: string
|
8
|
+
|
9
|
+
constructor(value: string, display?: string) {
|
10
|
+
super(valueType)
|
11
|
+
|
12
|
+
if (!value || typeof value !== 'string') {
|
13
|
+
throw Error(`value ${value} is not valid`)
|
14
|
+
}
|
15
|
+
|
16
|
+
if (display && typeof display !== 'string') {
|
17
|
+
throw Error(`display ${display} is not valid`)
|
18
|
+
}
|
19
|
+
|
20
|
+
this.value = value
|
21
|
+
this.display = display || value
|
22
|
+
}
|
23
|
+
|
24
|
+
toPresentationString() {
|
25
|
+
return this.display
|
26
|
+
}
|
27
|
+
|
28
|
+
toExpression() {
|
29
|
+
return this.value
|
30
|
+
}
|
31
|
+
|
32
|
+
static from(obj: { value: string; display?: string }) {
|
33
|
+
return new ConditionValue(obj.value, obj.display)
|
34
|
+
}
|
35
|
+
|
36
|
+
clone() {
|
37
|
+
return ConditionValue.from(this)
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
const valueType = Registration.register('Value', (obj) =>
|
42
|
+
ConditionValue.from(obj)
|
43
|
+
)
|
44
|
+
|
45
|
+
export enum DateDirections {
|
46
|
+
FUTURE = 'in the future',
|
47
|
+
PAST = 'in the past'
|
48
|
+
}
|
49
|
+
|
50
|
+
export const dateUnits: DateUnits = {
|
51
|
+
YEARS: { display: 'year(s)', value: 'years' },
|
52
|
+
MONTHS: { display: 'month(s)', value: 'months' },
|
53
|
+
DAYS: { display: 'day(s)', value: 'days' }
|
54
|
+
}
|
55
|
+
|
56
|
+
export const timeUnits: TimeUnits = {
|
57
|
+
HOURS: { display: 'hour(s)', value: 'hours' },
|
58
|
+
MINUTES: { display: 'minute(s)', value: 'minutes' },
|
59
|
+
SECONDS: { display: 'second(s)', value: 'seconds' }
|
60
|
+
}
|
61
|
+
|
62
|
+
export const dateTimeUnits: DateUnits & TimeUnits = Object.assign(
|
63
|
+
{},
|
64
|
+
dateUnits,
|
65
|
+
timeUnits
|
66
|
+
)
|
67
|
+
|
68
|
+
export class RelativeTimeValue extends ConditionValueAbstract {
|
69
|
+
timePeriod: string
|
70
|
+
timeUnit: DateTimeUnitValues
|
71
|
+
direction: DateDirections
|
72
|
+
timeOnly: boolean
|
73
|
+
|
74
|
+
constructor(
|
75
|
+
timePeriod: string,
|
76
|
+
timeUnit: DateTimeUnitValues,
|
77
|
+
direction: DateDirections,
|
78
|
+
timeOnly = false
|
79
|
+
) {
|
80
|
+
super(relativeTimeValueType)
|
81
|
+
|
82
|
+
if (typeof timePeriod !== 'string') {
|
83
|
+
throw Error(`time period ${timePeriod} is not valid`)
|
84
|
+
}
|
85
|
+
|
86
|
+
if (
|
87
|
+
!Object.values(dateTimeUnits)
|
88
|
+
.map((unit) => unit.value)
|
89
|
+
.includes(timeUnit)
|
90
|
+
) {
|
91
|
+
throw Error(`time unit ${timeUnit} is not valid`)
|
92
|
+
}
|
93
|
+
|
94
|
+
if (!Object.values(DateDirections).includes(direction)) {
|
95
|
+
throw Error(`direction ${direction} is not valid`)
|
96
|
+
}
|
97
|
+
|
98
|
+
this.timePeriod = timePeriod
|
99
|
+
this.timeUnit = timeUnit
|
100
|
+
this.direction = direction
|
101
|
+
this.timeOnly = timeOnly
|
102
|
+
}
|
103
|
+
|
104
|
+
toPresentationString() {
|
105
|
+
return `${this.timePeriod} ${this.timeUnit} ${this.direction}`
|
106
|
+
}
|
107
|
+
|
108
|
+
toExpression(): string {
|
109
|
+
const timePeriod =
|
110
|
+
this.direction === DateDirections.PAST
|
111
|
+
? 0 - Number(this.timePeriod)
|
112
|
+
: this.timePeriod
|
113
|
+
return this.timeOnly
|
114
|
+
? `timeForComparison(${timePeriod}, '${this.timeUnit}')`
|
115
|
+
: `dateForComparison(${timePeriod}, '${this.timeUnit}')`
|
116
|
+
}
|
117
|
+
|
118
|
+
static from(obj) {
|
119
|
+
return new RelativeTimeValue(
|
120
|
+
obj.timePeriod,
|
121
|
+
obj.timeUnit,
|
122
|
+
obj.direction,
|
123
|
+
obj.timeOnly
|
124
|
+
)
|
125
|
+
}
|
126
|
+
|
127
|
+
clone() {
|
128
|
+
return RelativeTimeValue.from(this)
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
export const relativeTimeValueType = Registration.register(
|
133
|
+
'RelativeTime',
|
134
|
+
(obj): RelativeTimeValue => RelativeTimeValue.from(obj)
|
135
|
+
)
|
136
|
+
|
137
|
+
type ConditionValueFrom =
|
138
|
+
| Pick<ConditionValue, 'type' | 'value' | 'display'>
|
139
|
+
| Pick<
|
140
|
+
RelativeTimeValue,
|
141
|
+
'type' | 'timePeriod' | 'timeUnit' | 'direction' | 'timeOnly'
|
142
|
+
>
|
143
|
+
|
144
|
+
export function conditionValueFrom(obj: ConditionValueFrom) {
|
145
|
+
return Registration.conditionValueFrom(obj)
|
146
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { ConditionField } from './condition-field'
|
2
|
+
import { ConditionAbstract } from './condition-abstract'
|
3
|
+
import { getExpression } from './condition-operators'
|
4
|
+
import { ConditionValue, RelativeTimeValue } from './condition-values'
|
5
|
+
import { ConditionValueAbstract } from './condition-value-abstract'
|
6
|
+
import { Coordinator } from './types'
|
7
|
+
|
8
|
+
export class Condition extends ConditionAbstract {
|
9
|
+
field: ConditionField
|
10
|
+
operator: string
|
11
|
+
value: ConditionValue | RelativeTimeValue
|
12
|
+
|
13
|
+
constructor(
|
14
|
+
field: ConditionField,
|
15
|
+
operator: string,
|
16
|
+
value: ConditionValue | RelativeTimeValue,
|
17
|
+
coordinator?: Coordinator
|
18
|
+
) {
|
19
|
+
super(coordinator)
|
20
|
+
|
21
|
+
if (!(field instanceof ConditionField)) {
|
22
|
+
throw Error(`field ${field} is not a valid ConditionField object`)
|
23
|
+
}
|
24
|
+
if (typeof operator !== 'string') {
|
25
|
+
throw Error(`operator ${operator} is not a valid operator`)
|
26
|
+
}
|
27
|
+
if (!(value instanceof ConditionValueAbstract)) {
|
28
|
+
throw Error(`value ${value} is not a valid value type`)
|
29
|
+
}
|
30
|
+
|
31
|
+
this.field = field
|
32
|
+
this.operator = operator
|
33
|
+
this.value = value
|
34
|
+
}
|
35
|
+
|
36
|
+
asFirstCondition() {
|
37
|
+
this._asFirstCondition()
|
38
|
+
return this
|
39
|
+
}
|
40
|
+
|
41
|
+
conditionString() {
|
42
|
+
return `'${this.field.display}' ${
|
43
|
+
this.operator
|
44
|
+
} '${this.value.toPresentationString()}'`
|
45
|
+
}
|
46
|
+
|
47
|
+
conditionExpression() {
|
48
|
+
return getExpression(
|
49
|
+
this.field.type,
|
50
|
+
this.field.name,
|
51
|
+
this.operator,
|
52
|
+
this.value
|
53
|
+
)
|
54
|
+
}
|
55
|
+
|
56
|
+
clone() {
|
57
|
+
return new Condition(
|
58
|
+
ConditionField.from(this.field),
|
59
|
+
this.operator,
|
60
|
+
this.value.clone(),
|
61
|
+
this.coordinator
|
62
|
+
)
|
63
|
+
}
|
64
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
export {
|
2
|
+
getExpression,
|
3
|
+
getOperatorConfig,
|
4
|
+
getOperatorNames,
|
5
|
+
absoluteDateOrTimeOperatorNames,
|
6
|
+
relativeDateOrTimeOperatorNames
|
7
|
+
} from './condition-operators'
|
8
|
+
|
9
|
+
export {
|
10
|
+
timeUnits,
|
11
|
+
dateUnits,
|
12
|
+
dateTimeUnits,
|
13
|
+
ConditionValue,
|
14
|
+
DateDirections,
|
15
|
+
RelativeTimeValue,
|
16
|
+
conditionValueFrom
|
17
|
+
} from './condition-values'
|
18
|
+
|
19
|
+
export { ConditionField } from './condition-field'
|
20
|
+
export { Condition } from './condition'
|
21
|
+
export { ConditionRef } from './condition-ref'
|
22
|
+
export { ConditionGroup } from './condition-group'
|
23
|
+
export { ConditionsModel } from './condition-model'
|
24
|
+
export { ConditionGroupDef } from './condition-group-def'
|
25
|
+
export { toExpression, toPresentationString } from './helpers'
|
26
|
+
|
27
|
+
export { Coordinator } from './types'
|