@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,153 @@
|
|
1
|
+
const conditionValueFactories = {}
|
2
|
+
|
3
|
+
class Registration {
|
4
|
+
type
|
5
|
+
|
6
|
+
constructor(type, factory) {
|
7
|
+
conditionValueFactories[type] = factory
|
8
|
+
this.type = type
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
export class AbstractConditionValue {
|
13
|
+
type
|
14
|
+
|
15
|
+
constructor(registration) {
|
16
|
+
if (new.target === AbstractConditionValue) {
|
17
|
+
throw new TypeError('Cannot construct ConditionValue instances directly')
|
18
|
+
}
|
19
|
+
if (!(registration instanceof Registration)) {
|
20
|
+
throw new TypeError(
|
21
|
+
'You must register your value type! Call registerValueType!'
|
22
|
+
)
|
23
|
+
}
|
24
|
+
this.type = registration.type
|
25
|
+
}
|
26
|
+
|
27
|
+
toPresentationString() {}
|
28
|
+
toExpression() {}
|
29
|
+
}
|
30
|
+
|
31
|
+
const valueType = registerValueType('Value', (obj) => ConditionValue.from(obj))
|
32
|
+
export class ConditionValue extends AbstractConditionValue {
|
33
|
+
value
|
34
|
+
display
|
35
|
+
|
36
|
+
constructor(value, display) {
|
37
|
+
super(valueType)
|
38
|
+
if (!value || typeof value !== 'string') {
|
39
|
+
throw Error(`value ${value} is not valid`)
|
40
|
+
}
|
41
|
+
if (display && typeof display !== 'string') {
|
42
|
+
throw Error(`display ${display} is not valid`)
|
43
|
+
}
|
44
|
+
this.value = value
|
45
|
+
this.display = display || value
|
46
|
+
}
|
47
|
+
|
48
|
+
toPresentationString() {
|
49
|
+
return this.display
|
50
|
+
}
|
51
|
+
|
52
|
+
toExpression() {
|
53
|
+
return this.value
|
54
|
+
}
|
55
|
+
|
56
|
+
static from(obj) {
|
57
|
+
return new ConditionValue(obj.value, obj.display)
|
58
|
+
}
|
59
|
+
|
60
|
+
clone() {
|
61
|
+
return ConditionValue.from(this)
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
export const dateDirections = {
|
66
|
+
FUTURE: 'in the future',
|
67
|
+
PAST: 'in the past'
|
68
|
+
}
|
69
|
+
|
70
|
+
export const dateUnits = {
|
71
|
+
YEARS: { display: 'year(s)', value: 'years' },
|
72
|
+
MONTHS: { display: 'month(s)', value: 'months' },
|
73
|
+
DAYS: { display: 'day(s)', value: 'days' }
|
74
|
+
}
|
75
|
+
export const timeUnits = {
|
76
|
+
HOURS: { display: 'hour(s)', value: 'hours' },
|
77
|
+
MINUTES: { display: 'minute(s)', value: 'minutes' },
|
78
|
+
SECONDS: { display: 'second(s)', value: 'seconds' }
|
79
|
+
}
|
80
|
+
export const dateTimeUnits = Object.assign({}, dateUnits, timeUnits)
|
81
|
+
|
82
|
+
export const relativeTimeValueType = registerValueType('RelativeTime', (obj) =>
|
83
|
+
RelativeTimeValue.from(obj)
|
84
|
+
)
|
85
|
+
export class RelativeTimeValue extends AbstractConditionValue {
|
86
|
+
timePeriod
|
87
|
+
timeUnit
|
88
|
+
direction
|
89
|
+
timeOnly
|
90
|
+
|
91
|
+
constructor(timePeriod, timeUnit, direction, timeOnly = false) {
|
92
|
+
super(relativeTimeValueType)
|
93
|
+
if (typeof timePeriod !== 'string') {
|
94
|
+
throw Error(`time period ${timePeriod} is not valid`)
|
95
|
+
}
|
96
|
+
if (
|
97
|
+
!Object.values(dateTimeUnits)
|
98
|
+
.map((it) => it.value)
|
99
|
+
.includes(timeUnit)
|
100
|
+
) {
|
101
|
+
throw Error(`time unit ${timeUnit} is not valid`)
|
102
|
+
}
|
103
|
+
if (!Object.values(dateDirections).includes(direction)) {
|
104
|
+
throw Error(`direction ${direction} is not valid`)
|
105
|
+
}
|
106
|
+
this.timePeriod = timePeriod
|
107
|
+
this.timeUnit = timeUnit
|
108
|
+
this.direction = direction
|
109
|
+
this.timeOnly = timeOnly
|
110
|
+
}
|
111
|
+
|
112
|
+
toPresentationString() {
|
113
|
+
return `${this.timePeriod} ${this.timeUnit} ${this.direction}`
|
114
|
+
}
|
115
|
+
|
116
|
+
toExpression() {
|
117
|
+
const timePeriod =
|
118
|
+
this.direction === dateDirections.PAST
|
119
|
+
? 0 - Number(this.timePeriod)
|
120
|
+
: this.timePeriod
|
121
|
+
return this.timeOnly
|
122
|
+
? `timeForComparison(${timePeriod}, '${this.timeUnit}')`
|
123
|
+
: `dateForComparison(${timePeriod}, '${this.timeUnit}')`
|
124
|
+
}
|
125
|
+
|
126
|
+
static from(obj) {
|
127
|
+
return new RelativeTimeValue(
|
128
|
+
obj.timePeriod,
|
129
|
+
obj.timeUnit,
|
130
|
+
obj.direction,
|
131
|
+
obj.timeOnly
|
132
|
+
)
|
133
|
+
}
|
134
|
+
|
135
|
+
clone() {
|
136
|
+
return RelativeTimeValue.from(this)
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* All value types should call this, and should be located in this file.
|
142
|
+
* Furthermore the types should be registered without the classes needing to be instantiated.
|
143
|
+
*
|
144
|
+
* Otherwise we can't guarantee they've been registered for deserialization before
|
145
|
+
* valueFrom is called
|
146
|
+
*/
|
147
|
+
function registerValueType(type, factory) {
|
148
|
+
return new Registration(type, factory)
|
149
|
+
}
|
150
|
+
|
151
|
+
export function valueFrom(obj) {
|
152
|
+
return conditionValueFactories[obj.type](obj)
|
153
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { Condition } from './condition'
|
2
|
+
import { ConditionRef } from './condition-ref'
|
3
|
+
import { ConditionGroup } from './condition-group'
|
4
|
+
|
5
|
+
export type ConditionsArray = (Condition | ConditionGroup | ConditionRef)[]
|
6
|
+
|
7
|
+
export enum Coordinator {
|
8
|
+
AND = 'and',
|
9
|
+
OR = 'or'
|
10
|
+
}
|
11
|
+
|
12
|
+
export type DateTimeUnitValues =
|
13
|
+
| 'years'
|
14
|
+
| 'months'
|
15
|
+
| 'days'
|
16
|
+
| 'hours'
|
17
|
+
| 'minutes'
|
18
|
+
| 'seconds'
|
19
|
+
|
20
|
+
export type DateUnits = {
|
21
|
+
YEARS: { display: 'year(s)'; value: 'years' }
|
22
|
+
MONTHS: { display: 'month(s)'; value: 'months' }
|
23
|
+
DAYS: { display: 'day(s)'; value: 'days' }
|
24
|
+
}
|
25
|
+
|
26
|
+
export type TimeUnits = {
|
27
|
+
HOURS: { display: 'hour(s)'; value: 'hours' }
|
28
|
+
MINUTES: { display: 'minute(s)'; value: 'minutes' }
|
29
|
+
SECONDS: { display: 'second(s)'; value: 'seconds' }
|
30
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import { Condition } from '../conditions/condition'
|
2
|
+
import { ConditionsModel } from '../conditions/condition-model'
|
3
|
+
|
4
|
+
export type ConditionWrapperValue =
|
5
|
+
| string
|
6
|
+
| {
|
7
|
+
name: string
|
8
|
+
conditions: Condition[]
|
9
|
+
}
|
10
|
+
|
11
|
+
export type ConditionRawData = {
|
12
|
+
name: string
|
13
|
+
displayName: string
|
14
|
+
value: ConditionWrapperValue
|
15
|
+
}
|
16
|
+
|
17
|
+
export class ConditionsWrapper {
|
18
|
+
name: string
|
19
|
+
displayName: string
|
20
|
+
value: ConditionWrapperValue
|
21
|
+
|
22
|
+
constructor(rawData: ConditionRawData) {
|
23
|
+
const { name, displayName, value } = rawData
|
24
|
+
this.displayName = displayName || name
|
25
|
+
this.value = value
|
26
|
+
this.name = name
|
27
|
+
}
|
28
|
+
|
29
|
+
get expression() {
|
30
|
+
if (typeof this.value === 'string') {
|
31
|
+
// Previously conditions were defined as strings, e.g: "section.age < 18"
|
32
|
+
// keep this so application can support legacy forms exports.
|
33
|
+
return this.value
|
34
|
+
}
|
35
|
+
|
36
|
+
return ConditionsModel.from(this.value).toExpression()
|
37
|
+
}
|
38
|
+
|
39
|
+
clone(): ConditionsWrapper {
|
40
|
+
return new ConditionsWrapper(this)
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { clone } from '../utils/helpers'
|
2
|
+
import { ComponentDef } from '../components/types'
|
3
|
+
import { Page } from './types'
|
4
|
+
|
5
|
+
export class InputWrapper {
|
6
|
+
name: string | undefined = undefined
|
7
|
+
title: string | undefined = undefined
|
8
|
+
type: string | undefined = undefined
|
9
|
+
propertyPath: string | undefined
|
10
|
+
#parentItemName: string | undefined
|
11
|
+
page: Page
|
12
|
+
|
13
|
+
constructor(
|
14
|
+
rawData: ComponentDef,
|
15
|
+
page: Page,
|
16
|
+
options: { ignoreSection?: boolean; parentItemName?: string }
|
17
|
+
) {
|
18
|
+
Object.assign(this, rawData)
|
19
|
+
const myPage = clone(page)
|
20
|
+
|
21
|
+
delete myPage.components
|
22
|
+
|
23
|
+
this.page = myPage
|
24
|
+
this.propertyPath =
|
25
|
+
!options.ignoreSection && page.section
|
26
|
+
? `${page.section}.${this.name}`
|
27
|
+
: this.name
|
28
|
+
this.#parentItemName = options.parentItemName
|
29
|
+
}
|
30
|
+
|
31
|
+
get displayName(): string | undefined {
|
32
|
+
const titleWithContext = this.#parentItemName
|
33
|
+
? `${this.title} under ${this.#parentItemName}`
|
34
|
+
: this.title
|
35
|
+
|
36
|
+
return this.page.section
|
37
|
+
? `${titleWithContext} in ${this.page.section}`
|
38
|
+
: titleWithContext
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,179 @@
|
|
1
|
+
import { ConditionRawData } from '.'
|
2
|
+
import { ComponentDef } from '../components/types'
|
3
|
+
|
4
|
+
type Toggleable<T> = boolean | T
|
5
|
+
|
6
|
+
export interface Next {
|
7
|
+
path: string
|
8
|
+
condition?: string
|
9
|
+
}
|
10
|
+
export type Link = Next
|
11
|
+
|
12
|
+
export interface Page {
|
13
|
+
title: string
|
14
|
+
path: string
|
15
|
+
controller: string
|
16
|
+
components?: ComponentDef[]
|
17
|
+
section: string // the section ID
|
18
|
+
next?: { path: string; condition?: string }[]
|
19
|
+
}
|
20
|
+
|
21
|
+
export interface RepeatingFieldPage extends Page {
|
22
|
+
controller: 'RepeatingFieldPageController'
|
23
|
+
options: {
|
24
|
+
summaryDisplayMode?: {
|
25
|
+
samePage?: boolean
|
26
|
+
separatePage?: boolean
|
27
|
+
hideRowTitles?: boolean
|
28
|
+
}
|
29
|
+
customText?: {
|
30
|
+
separatePageTitle?: string
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
export interface Section {
|
36
|
+
name: string
|
37
|
+
title: string
|
38
|
+
hideTitle: boolean
|
39
|
+
}
|
40
|
+
|
41
|
+
export interface Item {
|
42
|
+
text: string
|
43
|
+
value: string | number | boolean
|
44
|
+
description?: string
|
45
|
+
condition?: string
|
46
|
+
}
|
47
|
+
|
48
|
+
export interface List {
|
49
|
+
name: string
|
50
|
+
title: string
|
51
|
+
type: 'string' | 'number' | 'boolean'
|
52
|
+
items: Item[]
|
53
|
+
}
|
54
|
+
|
55
|
+
export interface Feedback {
|
56
|
+
feedbackForm?: boolean
|
57
|
+
url?: string
|
58
|
+
emailAddress?: string
|
59
|
+
}
|
60
|
+
|
61
|
+
export type PhaseBanner = {
|
62
|
+
phase?: 'alpha' | 'beta'
|
63
|
+
feedbackUrl?: string
|
64
|
+
}
|
65
|
+
|
66
|
+
export type MultipleApiKeys = {
|
67
|
+
test?: string
|
68
|
+
production?: string
|
69
|
+
}
|
70
|
+
|
71
|
+
export enum OutputType {
|
72
|
+
Email = 'email',
|
73
|
+
Notify = 'notify',
|
74
|
+
Webhook = 'webhook'
|
75
|
+
}
|
76
|
+
|
77
|
+
export type EmailOutputConfiguration = {
|
78
|
+
emailAddress: string
|
79
|
+
}
|
80
|
+
|
81
|
+
export type NotifyOutputConfiguration = {
|
82
|
+
apiKey: string
|
83
|
+
templateId: string
|
84
|
+
emailField: string
|
85
|
+
personalisation: string[]
|
86
|
+
personalisationFieldCustomisation?: {
|
87
|
+
[personalisationName: string]: string[]
|
88
|
+
}
|
89
|
+
addReferencesToPersonalisation?: boolean
|
90
|
+
emailReplyToIdConfiguration?: {
|
91
|
+
emailReplyToId: string
|
92
|
+
condition?: string | undefined
|
93
|
+
}[]
|
94
|
+
}
|
95
|
+
|
96
|
+
export type WebhookOutputConfiguration = {
|
97
|
+
url: string
|
98
|
+
}
|
99
|
+
|
100
|
+
export type OutputConfiguration =
|
101
|
+
| EmailOutputConfiguration
|
102
|
+
| NotifyOutputConfiguration
|
103
|
+
| WebhookOutputConfiguration
|
104
|
+
|
105
|
+
export type Output = {
|
106
|
+
name: string
|
107
|
+
title: string
|
108
|
+
type: OutputType
|
109
|
+
outputConfiguration: OutputConfiguration
|
110
|
+
}
|
111
|
+
|
112
|
+
export type ConfirmationPage = {
|
113
|
+
customText: {
|
114
|
+
title: string
|
115
|
+
paymentSkipped: Toggleable<string>
|
116
|
+
nextSteps: Toggleable<string>
|
117
|
+
}
|
118
|
+
components: ComponentDef[]
|
119
|
+
}
|
120
|
+
|
121
|
+
export type PaymentSkippedWarningPage = {
|
122
|
+
customText: {
|
123
|
+
title: string
|
124
|
+
caption: string
|
125
|
+
body: string
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
export type SpecialPages = {
|
130
|
+
confirmationPage?: ConfirmationPage
|
131
|
+
paymentSkippedWarningPage?: PaymentSkippedWarningPage
|
132
|
+
}
|
133
|
+
|
134
|
+
export function isMultipleApiKey(
|
135
|
+
payApiKey: string | MultipleApiKeys | undefined
|
136
|
+
): payApiKey is MultipleApiKeys {
|
137
|
+
const obj = payApiKey as MultipleApiKeys
|
138
|
+
return obj.test !== undefined || obj.production !== undefined
|
139
|
+
}
|
140
|
+
|
141
|
+
export type Fee = {
|
142
|
+
description: string
|
143
|
+
amount: number
|
144
|
+
multiplier?: string
|
145
|
+
condition?: string
|
146
|
+
prefix?: string
|
147
|
+
}
|
148
|
+
|
149
|
+
export type FeeOptions = {
|
150
|
+
paymentReferenceFormat?: string
|
151
|
+
payReturnUrl?: string
|
152
|
+
allowSubmissionWithoutPayment: boolean
|
153
|
+
maxAttempts: number
|
154
|
+
customPayErrorMessage?: string
|
155
|
+
showPaymentSkippedWarningPage: boolean
|
156
|
+
}
|
157
|
+
|
158
|
+
/**
|
159
|
+
* `FormDefinition` is a typescript representation of `Schema`
|
160
|
+
*/
|
161
|
+
export type FormDefinition = {
|
162
|
+
pages: Array<Page | RepeatingFieldPage>
|
163
|
+
conditions: ConditionRawData[]
|
164
|
+
lists: List[]
|
165
|
+
sections: Section[]
|
166
|
+
startPage?: Page['path'] | undefined
|
167
|
+
name?: string | undefined
|
168
|
+
feedback?: Feedback
|
169
|
+
phaseBanner?: PhaseBanner
|
170
|
+
fees: Fee[]
|
171
|
+
skipSummary?: boolean | undefined
|
172
|
+
outputs: Output[]
|
173
|
+
declaration?: string | undefined
|
174
|
+
metadata?: Record<string, any>
|
175
|
+
payApiKey?: string | MultipleApiKeys | undefined
|
176
|
+
specialPages?: SpecialPages
|
177
|
+
paymentReferenceFormat?: string
|
178
|
+
feeOptions: FeeOptions
|
179
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
export class FormConfiguration {
|
2
|
+
Key: string
|
3
|
+
DisplayName: string
|
4
|
+
LastModified: string | undefined
|
5
|
+
feedbackForm: boolean | undefined
|
6
|
+
|
7
|
+
constructor(
|
8
|
+
Key: string,
|
9
|
+
DisplayName?: string,
|
10
|
+
LastModified?: string,
|
11
|
+
feedbackForm?: boolean
|
12
|
+
) {
|
13
|
+
if (!Key) {
|
14
|
+
throw Error('Form configuration must have a key')
|
15
|
+
}
|
16
|
+
this.Key = Key
|
17
|
+
this.DisplayName = DisplayName || Key
|
18
|
+
this.LastModified = LastModified
|
19
|
+
this.feedbackForm = feedbackForm || false
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { FormConfiguration } from './form-configuration'
|
package/src/index.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
export { Schema, componentSchema } from './schema'
|
2
|
+
export { ConditionRawData, ConditionsWrapper } from './data-model'
|
3
|
+
export { Logger } from './utils/logger'
|
4
|
+
export { FormConfiguration } from './form'
|
5
|
+
export { ComponentTypes, ConditionalComponentTypes } from './components'
|
6
|
+
export * from './components/types'
|
7
|
+
export * from './conditions'
|
8
|
+
export * from './utils/helpers'
|
9
|
+
export * from './migration'
|
10
|
+
export * from './data-model/types'
|
11
|
+
export { whichMigrations } from './migration/whichMigrations'
|
@@ -0,0 +1 @@
|
|
1
|
+
export { whichMigrations } from './whichMigrations'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { MigrationScript } from './types'
|
2
|
+
|
3
|
+
function needsUpgrade(data) {
|
4
|
+
return !!(data.pages ?? [])
|
5
|
+
.flatMap((page) => page.components)
|
6
|
+
.find((component) => component.options?.list)
|
7
|
+
}
|
8
|
+
|
9
|
+
export function migrate(data): MigrationScript {
|
10
|
+
if (!needsUpgrade(data)) {
|
11
|
+
return { ...data, version: 2 }
|
12
|
+
}
|
13
|
+
const { pages } = data
|
14
|
+
const newPages = pages.flatMap((page) => {
|
15
|
+
return page.components.map((component) => {
|
16
|
+
if (!component.options?.list) {
|
17
|
+
return component
|
18
|
+
}
|
19
|
+
const { list, ...rest } = component.options
|
20
|
+
return { ...component, list, options: { ...rest } }
|
21
|
+
})
|
22
|
+
})
|
23
|
+
|
24
|
+
return {
|
25
|
+
...data,
|
26
|
+
pages: newPages,
|
27
|
+
version: 2
|
28
|
+
}
|
29
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
import { MigrationScript } from './types'
|
2
|
+
import { nanoid } from '../utils/helpers'
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @private
|
6
|
+
* StaticItem is a deprecated Type.
|
7
|
+
* It should only be used for aiding migration scripts.
|
8
|
+
*/
|
9
|
+
type StaticItem = {
|
10
|
+
label: string
|
11
|
+
value: string | number | boolean
|
12
|
+
hint?: string
|
13
|
+
condition?: string
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @private
|
18
|
+
* StaticComponentValues is a deprecated Type.
|
19
|
+
* It should only be used for aiding migration scripts.
|
20
|
+
*/
|
21
|
+
type StaticComponentValues = {
|
22
|
+
list: any
|
23
|
+
type: 'static' | 'listRef'
|
24
|
+
valueType: string | number
|
25
|
+
items: StaticItem[]
|
26
|
+
}
|
27
|
+
|
28
|
+
type Item = {
|
29
|
+
title: string
|
30
|
+
value: any
|
31
|
+
conditions?: any
|
32
|
+
hint?: string
|
33
|
+
}
|
34
|
+
|
35
|
+
function recastItem({ label, value, condition, hint }: StaticItem) {
|
36
|
+
const item: Item = {
|
37
|
+
title: label,
|
38
|
+
value
|
39
|
+
}
|
40
|
+
|
41
|
+
condition && (item.conditions = condition)
|
42
|
+
hint && (item.hint = hint)
|
43
|
+
return item
|
44
|
+
}
|
45
|
+
|
46
|
+
function addListId(component: { values: StaticComponentValues }) {
|
47
|
+
if (!component.values) {
|
48
|
+
return component
|
49
|
+
}
|
50
|
+
const { values } = component
|
51
|
+
return {
|
52
|
+
...component,
|
53
|
+
list: values.type === 'listRef' ? values.list : nanoid()
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
function migratePage(page) {
|
58
|
+
return {
|
59
|
+
...page,
|
60
|
+
components: page.components.map(addListId)
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
function removeValues(page) {
|
65
|
+
return {
|
66
|
+
...page,
|
67
|
+
components: page.components.map((component) => {
|
68
|
+
const { values, ...rest } = component
|
69
|
+
return {
|
70
|
+
...rest
|
71
|
+
}
|
72
|
+
})
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
function needsUpgrade(data) {
|
77
|
+
return !!data.pages
|
78
|
+
.flatMap((page) => page.components)
|
79
|
+
.find((component) => component.values)
|
80
|
+
}
|
81
|
+
|
82
|
+
export function migrate(data): MigrationScript {
|
83
|
+
if (!needsUpgrade(data)) {
|
84
|
+
return { ...data, version: 2 }
|
85
|
+
}
|
86
|
+
const pages = data.pages.map(migratePage)
|
87
|
+
const componentsWithList = pages.flatMap((page) =>
|
88
|
+
page.components.filter((c) => c.values?.items)
|
89
|
+
)
|
90
|
+
|
91
|
+
const valuesAsLists = componentsWithList.map((component) => {
|
92
|
+
return {
|
93
|
+
title: component.title,
|
94
|
+
name: component.list,
|
95
|
+
items: component.values.items.map((item) => recastItem(item))
|
96
|
+
}
|
97
|
+
})
|
98
|
+
|
99
|
+
return {
|
100
|
+
...data,
|
101
|
+
pages: pages.map(removeValues),
|
102
|
+
lists: [...(data.lists ?? []), ...valuesAsLists],
|
103
|
+
version: 2
|
104
|
+
}
|
105
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export type MigrationScript = (data: Object) => Object
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { migrate as V0_TO_V2 } from './migration.0-2'
|
2
|
+
import { migrate as V1_TO_V2 } from './migration.1-2'
|
3
|
+
import { MigrationScript } from './types'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Returns which migrations that should be run against your Object with the given version
|
7
|
+
* @param version
|
8
|
+
*/
|
9
|
+
export function whichMigrations(version: number) {
|
10
|
+
const migrations = new Set<MigrationScript>()
|
11
|
+
switch (version) {
|
12
|
+
case 0:
|
13
|
+
migrations.add(V0_TO_V2)
|
14
|
+
/**
|
15
|
+
* we are skipping v1 entirely. If we weren't you would do migrations.add([V1_TO_V2, V2_TO_V3]) for example.
|
16
|
+
*/
|
17
|
+
break
|
18
|
+
case 1:
|
19
|
+
migrations.add(V1_TO_V2)
|
20
|
+
break
|
21
|
+
}
|
22
|
+
return migrations
|
23
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { Schema, componentSchema } from './schema'
|