@defra/forms-model 3.0.169 → 3.0.171
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/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/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/package.json +2 -2
- 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/dist/module/conditions/condition-value-registration.js +0 -15
- package/dist/module/conditions/condition-value-registration.js.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/src/conditions/condition-value-registration.ts +0 -18
@@ -5,10 +5,10 @@ export class ConditionRef extends ConditionAbstract {
|
|
5
5
|
constructor(conditionName, conditionDisplayName, coordinator) {
|
6
6
|
super(coordinator);
|
7
7
|
if (typeof conditionName !== 'string') {
|
8
|
-
throw Error(
|
8
|
+
throw new Error("ConditionRef param 'conditionName' must be a string");
|
9
9
|
}
|
10
10
|
if (typeof conditionDisplayName !== 'string') {
|
11
|
-
throw Error(
|
11
|
+
throw new Error("ConditionRef param 'conditionDisplayName' must be a string");
|
12
12
|
}
|
13
13
|
this.conditionName = conditionName;
|
14
14
|
this.conditionDisplayName = conditionDisplayName;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-ref.js","names":["ConditionAbstract","ConditionRef","conditionName","conditionDisplayName","constructor","coordinator","Error","asFirstCondition","_asFirstCondition","conditionString","conditionExpression","clone"],"sources":["../../../src/conditions/condition-ref.ts"],"sourcesContent":["import { ConditionAbstract } from '~/src/conditions/condition-abstract.js'\nimport { type Coordinator } from '~/src/conditions/enums.js'\n\nexport class ConditionRef extends ConditionAbstract {\n conditionName: string\n conditionDisplayName: string\n\n constructor(\n conditionName: string,\n conditionDisplayName: string,\n coordinator: Coordinator | undefined\n ) {\n super(coordinator)\n\n if (typeof conditionName !== 'string') {\n throw Error(
|
1
|
+
{"version":3,"file":"condition-ref.js","names":["ConditionAbstract","ConditionRef","conditionName","conditionDisplayName","constructor","coordinator","Error","asFirstCondition","_asFirstCondition","conditionString","conditionExpression","clone"],"sources":["../../../src/conditions/condition-ref.ts"],"sourcesContent":["import { ConditionAbstract } from '~/src/conditions/condition-abstract.js'\nimport { type Coordinator } from '~/src/conditions/enums.js'\n\nexport class ConditionRef extends ConditionAbstract {\n conditionName: string\n conditionDisplayName: string\n\n constructor(\n conditionName: string,\n conditionDisplayName: string,\n coordinator: Coordinator | undefined\n ) {\n super(coordinator)\n\n if (typeof conditionName !== 'string') {\n throw new Error(\"ConditionRef param 'conditionName' must be a string\")\n }\n\n if (typeof conditionDisplayName !== 'string') {\n throw new Error(\n \"ConditionRef param 'conditionDisplayName' must be a string\"\n )\n }\n\n this.conditionName = conditionName\n this.conditionDisplayName = conditionDisplayName\n }\n\n asFirstCondition() {\n this._asFirstCondition()\n return this\n }\n\n conditionString() {\n return `'${this.conditionDisplayName}'`\n }\n\n conditionExpression() {\n return this.conditionName\n }\n\n clone() {\n return new ConditionRef(\n this.conditionName,\n this.conditionDisplayName,\n this.coordinator\n )\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AAG1B,OAAO,MAAMC,YAAY,SAASD,iBAAiB,CAAC;EAClDE,aAAa;EACbC,oBAAoB;EAEpBC,WAAWA,CACTF,aAAqB,EACrBC,oBAA4B,EAC5BE,WAAoC,EACpC;IACA,KAAK,CAACA,WAAW,CAAC;IAElB,IAAI,OAAOH,aAAa,KAAK,QAAQ,EAAE;MACrC,MAAM,IAAII,KAAK,CAAC,qDAAqD,CAAC;IACxE;IAEA,IAAI,OAAOH,oBAAoB,KAAK,QAAQ,EAAE;MAC5C,MAAM,IAAIG,KAAK,CACb,4DACF,CAAC;IACH;IAEA,IAAI,CAACJ,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACC,oBAAoB,GAAGA,oBAAoB;EAClD;EAEAI,gBAAgBA,CAAA,EAAG;IACjB,IAAI,CAACC,iBAAiB,CAAC,CAAC;IACxB,OAAO,IAAI;EACb;EAEAC,eAAeA,CAAA,EAAG;IAChB,OAAO,IAAI,IAAI,CAACN,oBAAoB,GAAG;EACzC;EAEAO,mBAAmBA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACR,aAAa;EAC3B;EAEAS,KAAKA,CAAA,EAAG;IACN,OAAO,IAAIV,YAAY,CACrB,IAAI,CAACC,aAAa,EAClB,IAAI,CAACC,oBAAoB,EACzB,IAAI,CAACE,WACP,CAAC;EACH;AACF","ignoreList":[]}
|
@@ -1,20 +1,12 @@
|
|
1
|
-
import { Registration } from "./condition-value-registration.js";
|
2
1
|
export class ConditionValueAbstract {
|
3
|
-
type;
|
4
|
-
constructor(registration) {
|
5
|
-
if (new.target === ConditionValueAbstract) {
|
6
|
-
throw new TypeError('Cannot construct ConditionValue instances directly');
|
7
|
-
}
|
8
|
-
if (!(registration instanceof Registration)) {
|
9
|
-
throw new TypeError('You must register your value type! Call registerValueType!');
|
10
|
-
}
|
11
|
-
this.type = registration.type;
|
12
|
-
}
|
13
2
|
toPresentationString() {
|
14
|
-
throw new Error('Unsupported Operation. Method toPresentationString
|
3
|
+
throw new Error('Unsupported Operation. Method toPresentationString has not been implemented');
|
15
4
|
}
|
16
5
|
toExpression() {
|
17
|
-
throw new Error('Unsupported Operation. Method toExpression
|
6
|
+
throw new Error('Unsupported Operation. Method toExpression has not been implemented');
|
7
|
+
}
|
8
|
+
clone() {
|
9
|
+
throw new Error('Unsupported Operation. Method clone has not been implemented');
|
18
10
|
}
|
19
11
|
}
|
20
12
|
//# sourceMappingURL=condition-value-abstract.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-value-abstract.js","names":["
|
1
|
+
{"version":3,"file":"condition-value-abstract.js","names":["ConditionValueAbstract","toPresentationString","Error","toExpression","clone"],"sources":["../../../src/conditions/condition-value-abstract.ts"],"sourcesContent":["export class ConditionValueAbstract {\n toPresentationString(): string {\n throw new Error(\n 'Unsupported Operation. Method toPresentationString has not been implemented'\n )\n }\n\n toExpression(): string {\n throw new Error(\n 'Unsupported Operation. Method toExpression has not been implemented'\n )\n }\n\n clone() {\n throw new Error(\n 'Unsupported Operation. Method clone has not been implemented'\n )\n }\n}\n"],"mappings":"AAAA,OAAO,MAAMA,sBAAsB,CAAC;EAClCC,oBAAoBA,CAAA,EAAW;IAC7B,MAAM,IAAIC,KAAK,CACb,6EACF,CAAC;EACH;EAEAC,YAAYA,CAAA,EAAW;IACrB,MAAM,IAAID,KAAK,CACb,qEACF,CAAC;EACH;EAEAE,KAAKA,CAAA,EAAG;IACN,MAAM,IAAIF,KAAK,CACb,8DACF,CAAC;EACH;AACF","ignoreList":[]}
|
@@ -1,18 +1,19 @@
|
|
1
1
|
import { ConditionValueAbstract } from "./condition-value-abstract.js";
|
2
|
-
import { Registration } from "./condition-value-registration.js";
|
3
2
|
export class ConditionValue extends ConditionValueAbstract {
|
3
|
+
type;
|
4
4
|
value;
|
5
5
|
display;
|
6
6
|
constructor(value, display) {
|
7
|
-
super(valueType);
|
8
7
|
if (!value || typeof value !== 'string') {
|
9
|
-
throw Error(
|
8
|
+
throw new Error("ConditionValue param 'value' must be a string");
|
10
9
|
}
|
11
10
|
if (display && typeof display !== 'string') {
|
12
|
-
throw Error(
|
11
|
+
throw new Error("ConditionValue param 'display' must be a string");
|
13
12
|
}
|
13
|
+
super();
|
14
|
+
this.type = 'Value';
|
14
15
|
this.value = value;
|
15
|
-
this.display = display
|
16
|
+
this.display = display ?? value;
|
16
17
|
}
|
17
18
|
toPresentationString() {
|
18
19
|
return this.display;
|
@@ -27,7 +28,6 @@ export class ConditionValue extends ConditionValueAbstract {
|
|
27
28
|
return ConditionValue.from(this);
|
28
29
|
}
|
29
30
|
}
|
30
|
-
const valueType = Registration.register('Value', obj => ConditionValue.from(obj));
|
31
31
|
export let DateDirections = /*#__PURE__*/function (DateDirections) {
|
32
32
|
DateDirections["FUTURE"] = "in the future";
|
33
33
|
DateDirections["PAST"] = "in the past";
|
@@ -63,21 +63,23 @@ export const timeUnits = {
|
|
63
63
|
};
|
64
64
|
export const dateTimeUnits = Object.assign({}, dateUnits, timeUnits);
|
65
65
|
export class RelativeTimeValue extends ConditionValueAbstract {
|
66
|
+
type;
|
66
67
|
timePeriod;
|
67
68
|
timeUnit;
|
68
69
|
direction;
|
69
70
|
timeOnly;
|
70
71
|
constructor(timePeriod, timeUnit, direction, timeOnly = false) {
|
71
|
-
super(relativeTimeValueType);
|
72
72
|
if (typeof timePeriod !== 'string') {
|
73
|
-
throw Error(
|
73
|
+
throw new Error("RelativeTimeValue param 'timePeriod' must be a string");
|
74
74
|
}
|
75
75
|
if (!Object.values(dateTimeUnits).map(unit => unit.value).includes(timeUnit)) {
|
76
|
-
throw Error(
|
76
|
+
throw new Error("RelativeTimeValue param 'dateTimeUnits' must only include DateTimeUnitValues keys");
|
77
77
|
}
|
78
78
|
if (!Object.values(DateDirections).includes(direction)) {
|
79
|
-
throw Error(
|
79
|
+
throw new Error("RelativeTimeValue param 'direction' must be from enum DateDirections");
|
80
80
|
}
|
81
|
+
super();
|
82
|
+
this.type = 'RelativeTime';
|
81
83
|
this.timePeriod = timePeriod;
|
82
84
|
this.timeUnit = timeUnit;
|
83
85
|
this.direction = direction;
|
@@ -97,8 +99,12 @@ export class RelativeTimeValue extends ConditionValueAbstract {
|
|
97
99
|
return RelativeTimeValue.from(this);
|
98
100
|
}
|
99
101
|
}
|
100
|
-
export const relativeTimeValueType = Registration.register('RelativeTime', obj => RelativeTimeValue.from(obj));
|
101
102
|
export function conditionValueFrom(obj) {
|
102
|
-
|
103
|
+
switch (obj.type) {
|
104
|
+
case 'Value':
|
105
|
+
return ConditionValue.from(obj);
|
106
|
+
case 'RelativeTime':
|
107
|
+
return RelativeTimeValue.from(obj);
|
108
|
+
}
|
103
109
|
}
|
104
110
|
//# sourceMappingURL=condition-values.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-values.js","names":["ConditionValueAbstract","
|
1
|
+
{"version":3,"file":"condition-values.js","names":["ConditionValueAbstract","ConditionValue","type","value","display","constructor","Error","toPresentationString","toExpression","from","obj","clone","DateDirections","dateUnits","YEARS","MONTHS","DAYS","timeUnits","HOURS","MINUTES","SECONDS","dateTimeUnits","Object","assign","RelativeTimeValue","timePeriod","timeUnit","direction","timeOnly","values","map","unit","includes","PAST","Number","conditionValueFrom"],"sources":["../../../src/conditions/condition-values.ts"],"sourcesContent":["import { ConditionValueAbstract } from '~/src/conditions/condition-value-abstract.js'\nimport {\n type DateTimeUnitValues,\n type DateUnits,\n type TimeUnits\n} from '~/src/conditions/types.js'\n\nexport class ConditionValue\n extends ConditionValueAbstract\n implements ConditionValueFrom\n{\n type: 'Value'\n value: string\n display: string\n\n constructor(value: string, display?: string) {\n if (!value || typeof value !== 'string') {\n throw new Error(\"ConditionValue param 'value' must be a string\")\n }\n\n if (display && typeof display !== 'string') {\n throw new Error(\"ConditionValue param 'display' must be a string\")\n }\n\n super()\n\n this.type = 'Value'\n this.value = value\n this.display = display ?? value\n }\n\n toPresentationString() {\n return this.display\n }\n\n toExpression() {\n return this.value\n }\n\n static from(obj: ConditionValue | ConditionValueFrom) {\n return new ConditionValue(obj.value, obj.display)\n }\n\n clone() {\n return ConditionValue.from(this)\n }\n}\n\nexport interface ConditionValueFrom {\n value: string\n display?: string\n}\n\nexport enum DateDirections {\n FUTURE = 'in the future',\n PAST = 'in the past'\n}\n\nexport const dateUnits: DateUnits = {\n YEARS: { display: 'year(s)', value: 'years' },\n MONTHS: { display: 'month(s)', value: 'months' },\n DAYS: { display: 'day(s)', value: 'days' }\n}\n\nexport const timeUnits: TimeUnits = {\n HOURS: { display: 'hour(s)', value: 'hours' },\n MINUTES: { display: 'minute(s)', value: 'minutes' },\n SECONDS: { display: 'second(s)', value: 'seconds' }\n}\n\nexport const dateTimeUnits: DateUnits & TimeUnits = Object.assign(\n {},\n dateUnits,\n timeUnits\n)\n\nexport class RelativeTimeValue\n extends ConditionValueAbstract\n implements RelativeTimeValueFrom\n{\n type: 'RelativeTime'\n timePeriod: string\n timeUnit: DateTimeUnitValues\n direction: DateDirections\n timeOnly: boolean\n\n constructor(\n timePeriod: string,\n timeUnit: DateTimeUnitValues,\n direction: DateDirections,\n timeOnly = false\n ) {\n if (typeof timePeriod !== 'string') {\n throw new Error(\"RelativeTimeValue param 'timePeriod' must be a string\")\n }\n\n if (\n !Object.values(dateTimeUnits)\n .map((unit) => unit.value)\n .includes(timeUnit)\n ) {\n throw new Error(\n \"RelativeTimeValue param 'dateTimeUnits' must only include DateTimeUnitValues keys\"\n )\n }\n\n if (!Object.values(DateDirections).includes(direction)) {\n throw new Error(\n \"RelativeTimeValue param 'direction' must be from enum DateDirections\"\n )\n }\n\n super()\n\n this.type = 'RelativeTime'\n this.timePeriod = timePeriod\n this.timeUnit = timeUnit\n this.direction = direction\n this.timeOnly = timeOnly\n }\n\n toPresentationString() {\n return `${this.timePeriod} ${this.timeUnit} ${this.direction}`\n }\n\n toExpression(): string {\n const timePeriod =\n this.direction === DateDirections.PAST\n ? 0 - Number(this.timePeriod)\n : this.timePeriod\n return this.timeOnly\n ? `timeForComparison(${timePeriod}, '${this.timeUnit}')`\n : `dateForComparison(${timePeriod}, '${this.timeUnit}')`\n }\n\n static from(obj: RelativeTimeValue | RelativeTimeValueFrom) {\n return new RelativeTimeValue(\n obj.timePeriod,\n obj.timeUnit,\n obj.direction,\n obj.timeOnly\n )\n }\n\n clone() {\n return RelativeTimeValue.from(this)\n }\n}\n\nexport interface RelativeTimeValueFrom {\n timePeriod: string\n timeUnit: DateTimeUnitValues\n direction: DateDirections\n timeOnly: boolean\n}\n\nexport function conditionValueFrom(\n obj:\n | ConditionValue\n | RelativeTimeValue\n | ({ type: 'Value' } & ConditionValueFrom)\n | ({ type: 'RelativeTime' } & RelativeTimeValueFrom)\n) {\n switch (obj.type) {\n case 'Value':\n return ConditionValue.from(obj)\n\n case 'RelativeTime':\n return RelativeTimeValue.from(obj)\n }\n}\n"],"mappings":"AAAA,SAASA,sBAAsB;AAO/B,OAAO,MAAMC,cAAc,SACjBD,sBAAsB,CAEhC;EACEE,IAAI;EACJC,KAAK;EACLC,OAAO;EAEPC,WAAWA,CAACF,KAAa,EAAEC,OAAgB,EAAE;IAC3C,IAAI,CAACD,KAAK,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;MACvC,MAAM,IAAIG,KAAK,CAAC,+CAA+C,CAAC;IAClE;IAEA,IAAIF,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE;MAC1C,MAAM,IAAIE,KAAK,CAAC,iDAAiD,CAAC;IACpE;IAEA,KAAK,CAAC,CAAC;IAEP,IAAI,CAACJ,IAAI,GAAG,OAAO;IACnB,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,OAAO,GAAGA,OAAO,IAAID,KAAK;EACjC;EAEAI,oBAAoBA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACH,OAAO;EACrB;EAEAI,YAAYA,CAAA,EAAG;IACb,OAAO,IAAI,CAACL,KAAK;EACnB;EAEA,OAAOM,IAAIA,CAACC,GAAwC,EAAE;IACpD,OAAO,IAAIT,cAAc,CAACS,GAAG,CAACP,KAAK,EAAEO,G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A,CAChCzB,GAIsD,EACtD;EACA,QAAQA,GAAG,CAACR,IAAI;IACd,KAAK,OAAO;MACV,OAAOD,cAAc,CAACQ,IAAI,CAACC,GAAG,CAAC;IAEjC,KAAK,cAAc;MACjB,OAAOc,iBAAiB,CAACf,IAAI,CAACC,GAAG,CAAC;EACtC;AACF","ignoreList":[]}
|
@@ -7,16 +7,16 @@ export class Condition extends ConditionAbstract {
|
|
7
7
|
operator;
|
8
8
|
value;
|
9
9
|
constructor(field, operator, value, coordinator) {
|
10
|
-
super(coordinator);
|
11
10
|
if (!(field instanceof ConditionField)) {
|
12
|
-
throw Error(
|
11
|
+
throw new Error("Condition param 'field' must be ConditionField instance");
|
13
12
|
}
|
14
13
|
if (typeof operator !== 'string') {
|
15
|
-
throw Error(
|
14
|
+
throw new Error("Condition param 'operator' must be a string");
|
16
15
|
}
|
17
16
|
if (!(value instanceof ConditionValueAbstract)) {
|
18
|
-
throw Error(
|
17
|
+
throw new Error("Condition param 'field' must be ConditionValueAbstract instance");
|
19
18
|
}
|
19
|
+
super(coordinator);
|
20
20
|
this.field = field;
|
21
21
|
this.operator = operator;
|
22
22
|
this.value = value;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition.js","names":["ConditionAbstract","ConditionField","getExpression","ConditionValueAbstract","Condition","field","operator","value","constructor","coordinator","Error","asFirstCondition","_asFirstCondition","conditionString","display","toPresentationString","conditionExpression","type","name","clone","from"],"sources":["../../../src/conditions/condition.ts"],"sourcesContent":["import { ConditionAbstract } from '~/src/conditions/condition-abstract.js'\nimport { ConditionField } from '~/src/conditions/condition-field.js'\nimport { getExpression } from '~/src/conditions/condition-operators.js'\nimport { ConditionValueAbstract } from '~/src/conditions/condition-value-abstract.js'\nimport {\n type ConditionValue,\n type RelativeTimeValue\n} from '~/src/conditions/condition-values.js'\nimport { type Coordinator } from '~/src/conditions/enums.js'\n\nexport class Condition extends ConditionAbstract {\n field: ConditionField\n operator: string\n value: ConditionValue | RelativeTimeValue\n\n constructor(\n field
|
1
|
+
{"version":3,"file":"condition.js","names":["ConditionAbstract","ConditionField","getExpression","ConditionValueAbstract","Condition","field","operator","value","constructor","coordinator","Error","asFirstCondition","_asFirstCondition","conditionString","display","toPresentationString","conditionExpression","type","name","clone","from"],"sources":["../../../src/conditions/condition.ts"],"sourcesContent":["import { ConditionAbstract } from '~/src/conditions/condition-abstract.js'\nimport { ConditionField } from '~/src/conditions/condition-field.js'\nimport { getExpression } from '~/src/conditions/condition-operators.js'\nimport { ConditionValueAbstract } from '~/src/conditions/condition-value-abstract.js'\nimport {\n type ConditionValue,\n type RelativeTimeValue\n} from '~/src/conditions/condition-values.js'\nimport { type Coordinator } from '~/src/conditions/enums.js'\n\nexport class Condition extends ConditionAbstract {\n field: ConditionField\n operator: string\n value: ConditionValue | RelativeTimeValue\n\n constructor(\n field?: ConditionField,\n operator?: string,\n value?: ConditionValue | RelativeTimeValue,\n coordinator?: Coordinator\n ) {\n if (!(field instanceof ConditionField)) {\n throw new Error(\"Condition param 'field' must be ConditionField instance\")\n }\n if (typeof operator !== 'string') {\n throw new Error(\"Condition param 'operator' must be a string\")\n }\n if (!(value instanceof ConditionValueAbstract)) {\n throw new Error(\n \"Condition param 'field' must be ConditionValueAbstract instance\"\n )\n }\n\n super(coordinator)\n\n this.field = field\n this.operator = operator\n this.value = value\n }\n\n asFirstCondition() {\n this._asFirstCondition()\n return this\n }\n\n conditionString() {\n return `'${this.field.display}' ${\n this.operator\n } '${this.value.toPresentationString()}'`\n }\n\n conditionExpression() {\n return getExpression(\n this.field.type,\n this.field.name,\n this.operator,\n this.value\n )\n }\n\n clone() {\n return new Condition(\n ConditionField.from(this.field),\n this.operator,\n this.value.clone(),\n this.coordinator\n )\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,aAAa;AACtB,SAASC,sBAAsB;AAO/B,OAAO,MAAMC,SAAS,SAASJ,iBAAiB,CAAC;EAC/CK,KAAK;EACLC,Q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|
1
|
-
{"version":3,"file":"condition-ref.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAE5D,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,aAAa,EAAE,MAAM,CAAA;IACrB,oBAAoB,EAAE,MAAM,CAAA;gBAG1B,aAAa,EAAE,MAAM,EACrB,oBAAoB,EAAE,MAAM,EAC5B,WAAW,EAAE,WAAW,GAAG,SAAS;
|
1
|
+
{"version":3,"file":"condition-ref.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAE5D,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,aAAa,EAAE,MAAM,CAAA;IACrB,oBAAoB,EAAE,MAAM,CAAA;gBAG1B,aAAa,EAAE,MAAM,EACrB,oBAAoB,EAAE,MAAM,EAC5B,WAAW,EAAE,WAAW,GAAG,SAAS;IAkBtC,gBAAgB;IAKhB,eAAe;IAIf,mBAAmB;IAInB,KAAK;CAON"}
|
@@ -1,8 +1,6 @@
|
|
1
|
-
import { Registration } from '../conditions/condition-value-registration.js';
|
2
1
|
export declare class ConditionValueAbstract {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
toExpression(): void;
|
2
|
+
toPresentationString(): string;
|
3
|
+
toExpression(): string;
|
4
|
+
clone(): void;
|
7
5
|
}
|
8
6
|
//# sourceMappingURL=condition-value-abstract.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-value-abstract.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-value-abstract.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"condition-value-abstract.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-value-abstract.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAsB;IACjC,oBAAoB,IAAI,MAAM;IAM9B,YAAY,IAAI,MAAM;IAMtB,KAAK;CAKN"}
|
@@ -1,18 +1,19 @@
|
|
1
1
|
import { ConditionValueAbstract } from '../conditions/condition-value-abstract.js';
|
2
|
-
import { Registration } from '../conditions/condition-value-registration.js';
|
3
2
|
import { type DateTimeUnitValues, type DateUnits, type TimeUnits } from '../conditions/types.js';
|
4
|
-
export declare class ConditionValue extends ConditionValueAbstract {
|
3
|
+
export declare class ConditionValue extends ConditionValueAbstract implements ConditionValueFrom {
|
4
|
+
type: 'Value';
|
5
5
|
value: string;
|
6
6
|
display: string;
|
7
7
|
constructor(value: string, display?: string);
|
8
8
|
toPresentationString(): string;
|
9
9
|
toExpression(): string;
|
10
|
-
static from(obj:
|
11
|
-
value: string;
|
12
|
-
display?: string;
|
13
|
-
}): ConditionValue;
|
10
|
+
static from(obj: ConditionValue | ConditionValueFrom): ConditionValue;
|
14
11
|
clone(): ConditionValue;
|
15
12
|
}
|
13
|
+
export interface ConditionValueFrom {
|
14
|
+
value: string;
|
15
|
+
display?: string;
|
16
|
+
}
|
16
17
|
export declare enum DateDirections {
|
17
18
|
FUTURE = "in the future",
|
18
19
|
PAST = "in the past"
|
@@ -20,7 +21,8 @@ export declare enum DateDirections {
|
|
20
21
|
export declare const dateUnits: DateUnits;
|
21
22
|
export declare const timeUnits: TimeUnits;
|
22
23
|
export declare const dateTimeUnits: DateUnits & TimeUnits;
|
23
|
-
export declare class RelativeTimeValue extends ConditionValueAbstract {
|
24
|
+
export declare class RelativeTimeValue extends ConditionValueAbstract implements RelativeTimeValueFrom {
|
25
|
+
type: 'RelativeTime';
|
24
26
|
timePeriod: string;
|
25
27
|
timeUnit: DateTimeUnitValues;
|
26
28
|
direction: DateDirections;
|
@@ -28,11 +30,18 @@ export declare class RelativeTimeValue extends ConditionValueAbstract {
|
|
28
30
|
constructor(timePeriod: string, timeUnit: DateTimeUnitValues, direction: DateDirections, timeOnly?: boolean);
|
29
31
|
toPresentationString(): string;
|
30
32
|
toExpression(): string;
|
31
|
-
static from(obj:
|
33
|
+
static from(obj: RelativeTimeValue | RelativeTimeValueFrom): RelativeTimeValue;
|
32
34
|
clone(): RelativeTimeValue;
|
33
35
|
}
|
34
|
-
export
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
export interface RelativeTimeValueFrom {
|
37
|
+
timePeriod: string;
|
38
|
+
timeUnit: DateTimeUnitValues;
|
39
|
+
direction: DateDirections;
|
40
|
+
timeOnly: boolean;
|
41
|
+
}
|
42
|
+
export declare function conditionValueFrom(obj: ConditionValue | RelativeTimeValue | ({
|
43
|
+
type: 'Value';
|
44
|
+
} & ConditionValueFrom) | ({
|
45
|
+
type: 'RelativeTime';
|
46
|
+
} & RelativeTimeValueFrom)): ConditionValue | RelativeTimeValue;
|
38
47
|
//# sourceMappingURL=condition-values.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition-values.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAA;AACrF,OAAO,
|
1
|
+
{"version":3,"file":"condition-values.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-values.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAA;AACrF,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,2BAA2B,CAAA;AAElC,qBAAa,cACX,SAAQ,sBACR,YAAW,kBAAkB;IAE7B,IAAI,EAAE,OAAO,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;gBAEH,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAgB3C,oB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bstract {
|
|
6
6
|
field: ConditionField;
|
7
7
|
operator: string;
|
8
8
|
value: ConditionValue | RelativeTimeValue;
|
9
|
-
constructor(field
|
9
|
+
constructor(field?: ConditionField, operator?: string, value?: ConditionValue | RelativeTimeValue, coordinator?: Coordinator);
|
10
10
|
asFirstCondition(): this;
|
11
11
|
conditionString(): string;
|
12
12
|
conditionExpression(): any;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAGpE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAE5D,qBAAa,SAAU,SAAQ,iBAAiB;IAC9C,KAAK,EAAE,cAAc,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,cAAc,GAAG,iBAAiB,CAAA;gBAGvC,KAAK,EAAE,cAAc,
|
1
|
+
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AAGpE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACvB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAE5D,qBAAa,SAAU,SAAQ,iBAAiB;IAC9C,KAAK,EAAE,cAAc,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,cAAc,GAAG,iBAAiB,CAAA;gBAGvC,KAAK,CAAC,EAAE,cAAc,EACtB,QAAQ,CAAC,EAAE,MAAM,EACjB,KAAK,CAAC,EAAE,cAAc,GAAG,iBAAiB,EAC1C,WAAW,CAAC,EAAE,WAAW;IAqB3B,gBAAgB;IAKhB,eAAe;IAMf,mBAAmB;IASnB,KAAK;CAQN"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@defra/forms-model",
|
3
|
-
"version": "3.0.
|
3
|
+
"version": "3.0.171",
|
4
4
|
"description": "A hapi plugin providing the model for Defra forms",
|
5
5
|
"homepage": "https://github.com/DEFRA/forms-designer/tree/main/model#readme",
|
6
6
|
"repository": {
|
@@ -15,7 +15,7 @@
|
|
15
15
|
"types": "dist/types/index.d.ts",
|
16
16
|
"scripts": {
|
17
17
|
"build": "npm run build:types && npm run build:node",
|
18
|
-
"build:node": "
|
18
|
+
"build:node": "babel --delete-dir-on-start --extensions \".ts\" --ignore \"**/*.test.*\" --copy-files --no-copy-ignored --source-maps --out-dir ./dist/module ./src",
|
19
19
|
"build:types": "tsc --build --force tsconfig.build.json && tsc-alias --project tsconfig.build.json",
|
20
20
|
"test": "jest --color --coverage --verbose",
|
21
21
|
"test:watch": "jest --color --watch"
|
@@ -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
|
@@ -1,15 +0,0 @@
|
|
1
|
-
const conditionValueFactories = {};
|
2
|
-
export class Registration {
|
3
|
-
type;
|
4
|
-
constructor(type, factory) {
|
5
|
-
conditionValueFactories[type] = factory;
|
6
|
-
this.type = type;
|
7
|
-
}
|
8
|
-
static register(type, factory) {
|
9
|
-
return new Registration(type, factory);
|
10
|
-
}
|
11
|
-
static conditionValueFrom(obj) {
|
12
|
-
return conditionValueFactories[obj.type](obj);
|
13
|
-
}
|
14
|
-
}
|
15
|
-
//# sourceMappingURL=condition-value-registration.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"condition-value-registration.js","names":["conditionValueFactories","Registration","type","constructor","factory","register","conditionValueFrom","obj"],"sources":["../../../src/conditions/condition-value-registration.ts"],"sourcesContent":["const conditionValueFactories = {}\n\nexport class Registration {\n type: string\n\n constructor(type: string, factory: (obj: any) => Registration) {\n conditionValueFactories[type] = factory\n this.type = type\n }\n\n static register(type: string, factory: (obj: any) => Registration) {\n return new Registration(type, factory)\n }\n\n static conditionValueFrom(obj: { type: string; [prop: string]: any }) {\n return conditionValueFactories[obj.type](obj)\n }\n}\n"],"mappings":"AAAA,MAAMA,uBAAuB,GAAG,CAAC,CAAC;AAElC,OAAO,MAAMC,YAAY,CAAC;EACxBC,IAAI;EAEJC,WAAWA,CAACD,IAAY,EAAEE,OAAmC,EAAE;IAC7DJ,uBAAuB,CAACE,IAAI,CAAC,GAAGE,OAAO;IACvC,IAAI,CAACF,IAAI,GAAGA,IAAI;EAClB;EAEA,OAAOG,QAAQA,CAACH,IAAY,EAAEE,OAAmC,EAAE;IACjE,OAAO,IAAIH,YAAY,CAACC,IAAI,EAAEE,OAAO,CAAC;EACxC;EAEA,OAAOE,kBAAkBA,CAACC,GAA0C,EAAE;IACpE,OAAOP,uBAAuB,CAACO,GAAG,CAACL,IAAI,CAAC,CAACK,GAAG,CAAC;EAC/C;AACF","ignoreList":[]}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
export declare class Registration {
|
2
|
-
type: string;
|
3
|
-
constructor(type: string, factory: (obj: any) => Registration);
|
4
|
-
static register(type: string, factory: (obj: any) => Registration): Registration;
|
5
|
-
static conditionValueFrom(obj: {
|
6
|
-
type: string;
|
7
|
-
[prop: string]: any;
|
8
|
-
}): any;
|
9
|
-
}
|
10
|
-
//# sourceMappingURL=condition-value-registration.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"condition-value-registration.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-value-registration.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,IAAI,EAAE,MAAM,CAAA;gBAEA,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,YAAY;IAK7D,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,YAAY;IAIjE,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;CAGrE"}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
const conditionValueFactories = {}
|
2
|
-
|
3
|
-
export class Registration {
|
4
|
-
type: string
|
5
|
-
|
6
|
-
constructor(type: string, factory: (obj: any) => Registration) {
|
7
|
-
conditionValueFactories[type] = factory
|
8
|
-
this.type = type
|
9
|
-
}
|
10
|
-
|
11
|
-
static register(type: string, factory: (obj: any) => Registration) {
|
12
|
-
return new Registration(type, factory)
|
13
|
-
}
|
14
|
-
|
15
|
-
static conditionValueFrom(obj: { type: string; [prop: string]: any }) {
|
16
|
-
return conditionValueFactories[obj.type](obj)
|
17
|
-
}
|
18
|
-
}
|