@defra/forms-model 3.0.218 → 3.0.220

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.
@@ -10,7 +10,6 @@ export class ConditionsModel {
10
10
  #groupedConditions = [];
11
11
  #userGroupedConditions = [];
12
12
  #conditionName = undefined;
13
- constructor(_conditionsObject) {}
14
13
  clone() {
15
14
  const toReturn = new ConditionsModel();
16
15
  toReturn.#groupedConditions = this.#groupedConditions.map(it => it.clone());
@@ -1 +1 @@
1
- {"version":3,"file":"condition-model.js","names":["ConditionField","ConditionGroupDef","ConditionGroup","ConditionRef","conditionValueFrom","Condition","Coordinator","toPresentationString","toExpression","ConditionsModel","groupedConditions","userGroupedConditions","conditionName","undefined","constructor","_conditionsObject","clone","toReturn","map","it","clear","name","add","condition","coordinatorExpected","length","getCoordinator","Error","push","_applyGroups","replace","index","splice","remove","indexes","filter","_condition","includes","asFirstCondition","addGroups","groupDefs","_group","splitGroup","_ungroup","moveEarlier","switchCoordinators","moveLater","setCoordinator","asPerUserGroupings","hasConditions","lastIndex","join","correctedUserGroups","conditions","_autoGroupDefs","reduce","groups","groupDef","find","contains","startsWith","groupConditions","applyTo","splitIndex","isGroup","copy","getGroupedConditions","orPositions","forEach","OR","hasOr","hasAnd","AND","start","position","thisIsTheLastOr","thereAreMoreConditions","toJSON","from","obj","conditionFrom","conditionDisplayName","coordinator","field","operator","value"],"sources":["../../../src/conditions/condition-model.ts"],"sourcesContent":["import { ConditionField } from '~/src/conditions/condition-field.js'\nimport { ConditionGroupDef } from '~/src/conditions/condition-group-def.js'\nimport { ConditionGroup } from '~/src/conditions/condition-group.js'\nimport { ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { conditionValueFrom } from '~/src/conditions/condition-values.js'\nimport { Condition } from '~/src/conditions/condition.js'\nimport { Coordinator } from '~/src/conditions/enums.js'\nimport { toPresentationString, toExpression } from '~/src/conditions/helpers.js'\nimport { type ConditionsArray } from '~/src/conditions/types.js'\n\ntype ConditionRawObject =\n | ConditionsModel\n | {\n name: string\n conditions: Condition[]\n }\n\nexport class ConditionsModel {\n #groupedConditions: ConditionsArray = []\n #userGroupedConditions: ConditionsArray = []\n #conditionName: string | undefined = undefined\n\n constructor(_conditionsObject?: ConditionRawObject) {}\n\n clone() {\n const toReturn = new ConditionsModel()\n toReturn.#groupedConditions = this.#groupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#userGroupedConditions = this.#userGroupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#conditionName = this.#conditionName\n return toReturn\n }\n\n clear() {\n this.#userGroupedConditions = []\n this.#groupedConditions = []\n this.#conditionName = undefined\n return this\n }\n\n set name(name) {\n this.#conditionName = name\n }\n\n get name() {\n return this.#conditionName\n }\n\n add(condition: Condition) {\n const coordinatorExpected = this.#userGroupedConditions.length !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n }\n\n this.#userGroupedConditions.push(condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n replace(index: number, condition: Condition) {\n const coordinatorExpected = index !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n } else if (index >= this.#userGroupedConditions.length) {\n throw Error(\n `Cannot replace condition ${index} as no such condition exists`\n )\n }\n\n this.#userGroupedConditions.splice(index, 1, condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n remove(indexes: number[]) {\n this.#userGroupedConditions = this.#userGroupedConditions\n .filter((_condition, index) => !indexes.includes(index))\n .map((condition, index) =>\n index === 0 ? condition.asFirstCondition() : condition\n )\n\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n addGroups(groupDefs: ConditionGroupDef[]) {\n this.#userGroupedConditions = this._group(\n this.#userGroupedConditions,\n groupDefs\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n splitGroup(index: number) {\n this.#userGroupedConditions = this._ungroup(\n this.#userGroupedConditions,\n index\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n moveEarlier(index: number) {\n if (index > 0 && index < this.#userGroupedConditions.length) {\n this.#userGroupedConditions.splice(\n index - 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 1) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n moveLater(index: number) {\n if (index >= 0 && index < this.#userGroupedConditions.length - 1) {\n this.#userGroupedConditions.splice(\n index + 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 0) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n switchCoordinators() {\n this.#userGroupedConditions[1].setCoordinator(\n this.#userGroupedConditions[0].getCoordinator()\n )\n this.#userGroupedConditions[0].setCoordinator(undefined)\n }\n\n get asPerUserGroupings() {\n return [...this.#userGroupedConditions]\n }\n\n get hasConditions() {\n return this.#userGroupedConditions.length > 0\n }\n\n get lastIndex() {\n return this.#userGroupedConditions.length - 1\n }\n\n toPresentationString() {\n return this.#groupedConditions\n .map((condition) => toPresentationString(condition))\n .join(' ')\n }\n\n toExpression() {\n return this.#groupedConditions\n .map((condition) => toExpression(condition))\n .join(' ')\n }\n\n _applyGroups(\n userGroupedConditions: (Condition | ConditionGroup | ConditionRef)[]\n ) {\n const correctedUserGroups = userGroupedConditions.map((condition) =>\n condition instanceof ConditionGroup && condition.conditions.length > 2\n ? new ConditionGroup(\n this._group(\n condition.conditions,\n this._autoGroupDefs(condition.conditions)\n )\n )\n : condition\n )\n\n return this._group(\n correctedUserGroups,\n this._autoGroupDefs(correctedUserGroups)\n )\n }\n\n _group(conditions: ConditionsArray, groupDefs: ConditionGroupDef[]) {\n return conditions.reduce<ConditionsArray>(\n (groups, condition, index, conditions) => {\n const groupDef = groupDefs.find((groupDef) => groupDef.contains(index))\n\n if (groupDef) {\n if (groupDef.startsWith(index)) {\n const groupConditions = groupDef.applyTo(conditions)\n groups.push(new ConditionGroup(groupConditions))\n }\n } else {\n groups.push(condition)\n }\n\n return groups\n },\n []\n )\n }\n\n _ungroup(conditions: ConditionsArray, splitIndex: number) {\n if (conditions[splitIndex].isGroup()) {\n const copy = [...conditions]\n copy.splice(\n splitIndex,\n 1,\n ...conditions[splitIndex].getGroupedConditions()\n )\n return copy\n }\n return conditions\n }\n\n _autoGroupDefs(conditions: ConditionsArray) {\n const orPositions: number[] = []\n\n conditions.forEach((condition, index) => {\n if (condition.getCoordinator() === Coordinator.OR) {\n orPositions.push(index)\n }\n })\n\n const hasOr = orPositions.length > 0\n const hasAnd = !!conditions.find(\n (condition) => condition.getCoordinator() === Coordinator.AND\n )\n\n if (hasAnd && hasOr) {\n let start = 0\n const groupDefs: ConditionGroupDef[] = []\n orPositions.forEach((position, index) => {\n if (start < position - 1) {\n groupDefs.push(new ConditionGroupDef(start, position - 1))\n }\n const thisIsTheLastOr = orPositions.length === index + 1\n const thereAreMoreConditions = conditions.length - 1 > position\n if (thisIsTheLastOr && thereAreMoreConditions) {\n groupDefs.push(new ConditionGroupDef(position, conditions.length - 1))\n }\n start = position\n })\n return groupDefs\n }\n\n return []\n }\n\n toJSON() {\n const name = this.#conditionName\n const conditions = this.#userGroupedConditions\n return {\n name,\n conditions: conditions.map((it) => it.clone())\n }\n }\n\n // TODO:- why is this not a constructor?\n static from(obj: ConditionRawObject | ConditionsModel) {\n if (obj instanceof ConditionsModel) {\n return obj\n }\n const toReturn = new ConditionsModel()\n toReturn.#conditionName = obj.name\n toReturn.#userGroupedConditions = obj.conditions.map((condition) =>\n conditionFrom(condition)\n )\n toReturn.#groupedConditions = toReturn._applyGroups(\n toReturn.#userGroupedConditions\n )\n return toReturn\n }\n}\n\ntype ConditionFrom = (\n it: Condition | ConditionRef | ConditionGroup\n) => Condition | ConditionRef | ConditionGroup\n\nconst conditionFrom: ConditionFrom = function (it) {\n if ('conditions' in it) {\n return new ConditionGroup(\n it.conditions.map((condition) => conditionFrom(condition))\n )\n }\n\n if ('conditionName' in it) {\n return new ConditionRef(\n it.conditionName,\n it.conditionDisplayName,\n it.coordinator\n )\n }\n\n return new Condition(\n ConditionField.from(it.field),\n it.operator,\n conditionValueFrom(it.value),\n it.coordinator\n )\n}\n"],"mappings":"AAAA,SAASA,cAAc;AACvB,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,YAAY;AACrB,SAASC,kBAAkB;AAC3B,SAASC,SAAS;AAClB,SAASC,WAAW;AACpB,SAASC,oBAAoB,EAAEC,YAAY;AAU3C,OAAO,MAAMC,eAAe,CAAC;EAC3B,CAACC,iBAAiB,GAAoB,EAAE;EACxC,CAACC,qBAAqB,GAAoB,EAAE;EAC5C,CAACC,aAAa,GAAuBC,SAAS;EAE9CC,WAAWA,CAACC,iBAAsC,EAAE,CAAC;EAErDC,KAAKA,CAAA,EAAG;IACN,MAAMC,QAAQ,GAAG,IAAIR,eAAe,CAAC,CAAC;IACtCQ,QAAQ,CAAC,CAACP,iBAAiB,GAAG,IAAI,CAAC,CAACA,iBAAiB,CAACQ,GAAG,CAAEC,EAAE,IAC3DA,EAAE,CAACH,KAAK,CAAC,CACX,CAAC;IACDC,QAAQ,CAAC,CAACN,qBAAqB,GAAG,IAAI,CAAC,CAACA,qBAAqB,CAACO,GAAG,CAAEC,EAAE,IACnEA,EAAE,CAACH,KAAK,CAAC,CACX,CAAC;IACDC,QAAQ,CAAC,CAACL,aAAa,GAAG,IAAI,CAAC,CAACA,aAAa;IAC7C,OAAOK,QAAQ;EACjB;EAEAG,KAAKA,CAAA,EAAG;IACN,IAAI,CAAC,CAACT,qBAAqB,GAAG,EAAE;IAChC,IAA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IAAIA,GAAG,YAAYtE,eAAe,EAAE;MAClC,OAAOsE,GAAG;IACZ;IACA,MAAM9D,QAAQ,GAAG,IAAIR,eAAe,CAAC,CAAC;IACtCQ,QAAQ,CAAC,CAACL,aAAa,GAAGmE,GAAG,CAAC1D,IAAI;IAClCJ,QAAQ,CAAC,CAACN,qBAAqB,GAAGoE,GAAG,CAAC1B,UAAU,CAACnC,GAAG,CAAEK,SAAS,IAC7DyD,aAAa,CAACzD,SAAS,CACzB,CAAC;IACDN,QAAQ,CAAC,CAACP,iBAAiB,GAAGO,QAAQ,CAACY,YAAY,CACjDZ,QAAQ,CAAC,CAACN,qBACZ,CAAC;IACD,OAAOM,QAAQ;EACjB;AACF;AAMA,MAAM+D,aAA4B,GAAG,SAAAA,CAAU7D,EAAE,EAAE;EACjD,IAAI,YAAY,IAAIA,EAAE,EAAE;IACtB,OAAO,IAAIjB,cAAc,CACvBiB,EAAE,CAACkC,UAAU,CAACnC,GAAG,CAAEK,SAAS,IAAKyD,aAAa,CAACzD,SAAS,CAAC,CAC3D,CAAC;EACH;EAEA,IAAI,eAAe,IAAIJ,EAAE,EAAE;IACzB,OAAO,IAAIhB,YAAY,CACrBgB,EAAE,CAACP,aAAa,EAChBO,EAAE,CAAC8D,oBAAoB,EACvB9D,EAAE,CAAC+D,WACL,CAAC;EACH;EAEA,OAAO,IAAI7E,SAAS,CAClBL,cAAc,CAAC8E,IAAI,CAAC3D,EAAE,CAACgE,KAAK,CAAC,EAC7BhE,EAAE,CAACiE,QAAQ,EACXhF,kBAAkB,CAACe,EAAE,CAACkE,KAAK,CAAC,EAC5BlE,EAAE,CAAC+D,WACL,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"condition-model.js","names":["ConditionField","ConditionGroupDef","ConditionGroup","ConditionRef","conditionValueFrom","Condition","Coordinator","toPresentationString","toExpression","ConditionsModel","groupedConditions","userGroupedConditions","conditionName","undefined","clone","toReturn","map","it","clear","name","add","condition","coordinatorExpected","length","getCoordinator","Error","push","_applyGroups","replace","index","splice","remove","indexes","filter","_condition","includes","asFirstCondition","addGroups","groupDefs","_group","splitGroup","_ungroup","moveEarlier","switchCoordinators","moveLater","setCoordinator","asPerUserGroupings","hasConditions","lastIndex","join","correctedUserGroups","conditions","_autoGroupDefs","reduce","groups","groupDef","find","contains","startsWith","groupConditions","applyTo","splitIndex","isGroup","copy","getGroupedConditions","orPositions","forEach","OR","hasOr","hasAnd","AND","start","position","thisIsTheLastOr","thereAreMoreConditions","toJSON","from","obj","conditionFrom","conditionDisplayName","coordinator","field","operator","value"],"sources":["../../../src/conditions/condition-model.ts"],"sourcesContent":["import { ConditionField } from '~/src/conditions/condition-field.js'\nimport { ConditionGroupDef } from '~/src/conditions/condition-group-def.js'\nimport { ConditionGroup } from '~/src/conditions/condition-group.js'\nimport { ConditionRef } from '~/src/conditions/condition-ref.js'\nimport { conditionValueFrom } from '~/src/conditions/condition-values.js'\nimport { Condition } from '~/src/conditions/condition.js'\nimport { Coordinator } from '~/src/conditions/enums.js'\nimport { toPresentationString, toExpression } from '~/src/conditions/helpers.js'\nimport { type ConditionsArray } from '~/src/conditions/types.js'\n\ntype ConditionRawObject =\n | ConditionsModel\n | {\n name: string\n conditions: Condition[]\n }\n\nexport class ConditionsModel {\n #groupedConditions: ConditionsArray = []\n #userGroupedConditions: ConditionsArray = []\n #conditionName: string | undefined = undefined\n\n clone() {\n const toReturn = new ConditionsModel()\n toReturn.#groupedConditions = this.#groupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#userGroupedConditions = this.#userGroupedConditions.map((it) =>\n it.clone()\n )\n toReturn.#conditionName = this.#conditionName\n return toReturn\n }\n\n clear() {\n this.#userGroupedConditions = []\n this.#groupedConditions = []\n this.#conditionName = undefined\n return this\n }\n\n set name(name) {\n this.#conditionName = name\n }\n\n get name() {\n return this.#conditionName\n }\n\n add(condition: Condition) {\n const coordinatorExpected = this.#userGroupedConditions.length !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n }\n\n this.#userGroupedConditions.push(condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n replace(index: number, condition: Condition) {\n const coordinatorExpected = index !== 0\n\n if (condition.getCoordinator() && !coordinatorExpected) {\n throw Error('No coordinator allowed on the first condition')\n } else if (!condition.getCoordinator() && coordinatorExpected) {\n throw Error('Coordinator must be present on subsequent conditions')\n } else if (index >= this.#userGroupedConditions.length) {\n throw Error(\n `Cannot replace condition ${index} as no such condition exists`\n )\n }\n\n this.#userGroupedConditions.splice(index, 1, condition)\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n\n return this\n }\n\n remove(indexes: number[]) {\n this.#userGroupedConditions = this.#userGroupedConditions\n .filter((_condition, index) => !indexes.includes(index))\n .map((condition, index) =>\n index === 0 ? condition.asFirstCondition() : condition\n )\n\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n addGroups(groupDefs: ConditionGroupDef[]) {\n this.#userGroupedConditions = this._group(\n this.#userGroupedConditions,\n groupDefs\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n splitGroup(index: number) {\n this.#userGroupedConditions = this._ungroup(\n this.#userGroupedConditions,\n index\n )\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n return this\n }\n\n moveEarlier(index: number) {\n if (index > 0 && index < this.#userGroupedConditions.length) {\n this.#userGroupedConditions.splice(\n index - 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 1) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n moveLater(index: number) {\n if (index >= 0 && index < this.#userGroupedConditions.length - 1) {\n this.#userGroupedConditions.splice(\n index + 1,\n 0,\n this.#userGroupedConditions.splice(index, 1)[0]\n )\n if (index === 0) {\n this.switchCoordinators()\n }\n this.#groupedConditions = this._applyGroups(this.#userGroupedConditions)\n }\n return this\n }\n\n switchCoordinators() {\n this.#userGroupedConditions[1].setCoordinator(\n this.#userGroupedConditions[0].getCoordinator()\n )\n this.#userGroupedConditions[0].setCoordinator(undefined)\n }\n\n get asPerUserGroupings() {\n return [...this.#userGroupedConditions]\n }\n\n get hasConditions() {\n return this.#userGroupedConditions.length > 0\n }\n\n get lastIndex() {\n return this.#userGroupedConditions.length - 1\n }\n\n toPresentationString() {\n return this.#groupedConditions\n .map((condition) => toPresentationString(condition))\n .join(' ')\n }\n\n toExpression() {\n return this.#groupedConditions\n .map((condition) => toExpression(condition))\n .join(' ')\n }\n\n _applyGroups(\n userGroupedConditions: (Condition | ConditionGroup | ConditionRef)[]\n ) {\n const correctedUserGroups = userGroupedConditions.map((condition) =>\n condition instanceof ConditionGroup && condition.conditions.length > 2\n ? new ConditionGroup(\n this._group(\n condition.conditions,\n this._autoGroupDefs(condition.conditions)\n )\n )\n : condition\n )\n\n return this._group(\n correctedUserGroups,\n this._autoGroupDefs(correctedUserGroups)\n )\n }\n\n _group(conditions: ConditionsArray, groupDefs: ConditionGroupDef[]) {\n return conditions.reduce<ConditionsArray>(\n (groups, condition, index, conditions) => {\n const groupDef = groupDefs.find((groupDef) => groupDef.contains(index))\n\n if (groupDef) {\n if (groupDef.startsWith(index)) {\n const groupConditions = groupDef.applyTo(conditions)\n groups.push(new ConditionGroup(groupConditions))\n }\n } else {\n groups.push(condition)\n }\n\n return groups\n },\n []\n )\n }\n\n _ungroup(conditions: ConditionsArray, splitIndex: number) {\n if (conditions[splitIndex].isGroup()) {\n const copy = [...conditions]\n copy.splice(\n splitIndex,\n 1,\n ...conditions[splitIndex].getGroupedConditions()\n )\n return copy\n }\n return conditions\n }\n\n _autoGroupDefs(conditions: ConditionsArray) {\n const orPositions: number[] = []\n\n conditions.forEach((condition, index) => {\n if (condition.getCoordinator() === Coordinator.OR) {\n orPositions.push(index)\n }\n })\n\n const hasOr = orPositions.length > 0\n const hasAnd = !!conditions.find(\n (condition) => condition.getCoordinator() === Coordinator.AND\n )\n\n if (hasAnd && hasOr) {\n let start = 0\n const groupDefs: ConditionGroupDef[] = []\n orPositions.forEach((position, index) => {\n if (start < position - 1) {\n groupDefs.push(new ConditionGroupDef(start, position - 1))\n }\n const thisIsTheLastOr = orPositions.length === index + 1\n const thereAreMoreConditions = conditions.length - 1 > position\n if (thisIsTheLastOr && thereAreMoreConditions) {\n groupDefs.push(new ConditionGroupDef(position, conditions.length - 1))\n }\n start = position\n })\n return groupDefs\n }\n\n return []\n }\n\n toJSON() {\n const name = this.#conditionName\n const conditions = this.#userGroupedConditions\n return {\n name,\n conditions: conditions.map((it) => it.clone())\n }\n }\n\n // TODO:- why is this not a constructor?\n static from(obj: ConditionRawObject | ConditionsModel) {\n if (obj instanceof ConditionsModel) {\n return obj\n }\n const toReturn = new ConditionsModel()\n toReturn.#conditionName = obj.name\n toReturn.#userGroupedConditions = obj.conditions.map((condition) =>\n conditionFrom(condition)\n )\n toReturn.#groupedConditions = toReturn._applyGroups(\n toReturn.#userGroupedConditions\n )\n return toReturn\n }\n}\n\ntype ConditionFrom = (\n it: Condition | ConditionRef | ConditionGroup\n) => Condition | ConditionRef | ConditionGroup\n\nconst conditionFrom: ConditionFrom = function (it) {\n if ('conditions' in it) {\n return new ConditionGroup(\n it.conditions.map((condition) => conditionFrom(condition))\n )\n }\n\n if ('conditionName' in it) {\n return new ConditionRef(\n it.conditionName,\n it.conditionDisplayName,\n it.coordinator\n )\n }\n\n return new Condition(\n ConditionField.from(it.field),\n it.operator,\n conditionValueFrom(it.value),\n it.coordinator\n )\n}\n"],"mappings":"AAAA,SAASA,cAAc;AACvB,SAASC,iBAAiB;AAC1B,SAASC,cAAc;AACvB,SAASC,YAAY;AACrB,SAASC,kBAAkB;AAC3B,SAASC,SAAS;AAClB,SAASC,WAAW;AACpB,SAASC,oBAAoB,EAAEC,YAAY;AAU3C,OAAO,MAAM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K,SAAS,IAAKyD,aAAa,CAACzD,SAAS,CAAC,CAC3D,CAAC;EACH;EAEA,IAAI,eAAe,IAAIJ,EAAE,EAAE;IACzB,OAAO,IAAId,YAAY,CACrBc,EAAE,CAACL,aAAa,EAChBK,EAAE,CAAC8D,oBAAoB,EACvB9D,EAAE,CAAC+D,WACL,CAAC;EACH;EAEA,OAAO,IAAI3E,SAAS,CAClBL,cAAc,CAAC4E,IAAI,CAAC3D,EAAE,CAACgE,KAAK,CAAC,EAC7BhE,EAAE,CAACiE,QAAQ,EACX9E,kBAAkB,CAACa,EAAE,CAACkE,KAAK,CAAC,EAC5BlE,EAAE,CAAC+D,WACL,CAAC;AACH,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"condition-operators.js","names":["isConditionalType","ComponentType","timeUnits","dateUnits","dateTimeUnits","ConditionValue","RelativeTimeValue","DateDirections","Operator","OperatorName","defaultOperators","Is","inline","IsNot","withDefaults","param","Object","assign","textFieldOperators","IsLongerThan","lengthIs","IsMoreThan","IsShorterThan","IsLessThan","HasLength","absoluteDateTimeOperators","absoluteDateTime","IsBefore","IsAfter","relativeTimeOperators","units","IsAtLeast","relativeTime","IsAtMost","customOperators","RadiosField","CheckboxesField","Contains","reverseInline","DoesNotContain","not","NumberField","TimeField","DatePartsField","TextField","MultilineTextField","EmailAddressField","YesNoField","getOperatorNames","fieldType","conditionals","getConditionals","keys","sort","getExpression","fieldName","operator","value","expression","type","name","getOperatorConfig","field","formatValue","operatorDefinition","toExpression","absoluteDateOrTimeOperatorNames","relativeDateOrTimeOperatorNames","Error","pastOperator","futureOperator","isPast","direction","PAST"],"sources":["../../../src/conditions/condition-operators.ts"],"sourcesContent":["import { isConditionalType } from '../components/helpers.js'\n\nimport { ComponentType } from '~/src/components/enums.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport {\n timeUnits,\n dateUnits,\n dateTimeUnits,\n ConditionValue,\n RelativeTimeValue\n} from '~/src/conditions/condition-values.js'\nimport {\n DateDirections,\n Operator,\n OperatorName\n} from '~/src/conditions/enums.js'\nimport {\n type Conditionals,\n type DateUnits,\n type OperatorDefinition,\n type TimeUnits\n} from '~/src/conditions/types.js'\n\nconst defaultOperators = {\n [OperatorName.Is]: inline(Operator.Is),\n [OperatorName.IsNot]: inline(Operator.IsNot)\n}\n\nfunction withDefaults<T>(param: T) {\n return Object.assign({}, param, defaultOperators)\n}\n\nconst textFieldOperators = {\n [OperatorName.IsLongerThan]: lengthIs(Operator.IsMoreThan),\n [OperatorName.IsShorterThan]: lengthIs(Operator.IsLessThan),\n [OperatorName.HasLength]: lengthIs(Operator.Is)\n}\n\nconst absoluteDateTimeOperators = {\n [OperatorName.Is]: absoluteDateTime(Operator.Is),\n [OperatorName.IsNot]: absoluteDateTime(Operator.IsNot),\n [OperatorName.IsBefore]: absoluteDateTime(Operator.IsLessThan),\n [OperatorName.IsAfter]: absoluteDateTime(Operator.IsMoreThan)\n}\n\nconst relativeTimeOperators = (units: DateUnits | TimeUnits) => ({\n [OperatorName.IsAtLeast]: relativeTime(\n Operator.IsAtMost,\n Operator.IsAtLeast,\n units\n ),\n [OperatorName.IsAtMost]: relativeTime(\n Operator.IsAtLeast,\n Operator.IsAtMost,\n units\n ),\n [OperatorName.IsLessThan]: relativeTime(\n Operator.IsMoreThan,\n Operator.IsLessThan,\n units\n ),\n [OperatorName.IsMoreThan]: relativeTime(\n Operator.IsLessThan,\n Operator.IsMoreThan,\n units\n )\n})\n\nexport const customOperators = {\n [ComponentType.RadiosField]: defaultOperators,\n [ComponentType.CheckboxesField]: {\n [OperatorName.Contains]: reverseInline(Operator.Contains),\n [OperatorName.DoesNotContain]: not(reverseInline(Operator.Contains))\n },\n [ComponentType.NumberField]: withDefaults({\n [OperatorName.IsAtLeast]: inline(Operator.IsAtLeast),\n [OperatorName.IsAtMost]: inline(Operator.IsAtMost),\n [OperatorName.IsLessThan]: inline(Operator.IsLessThan),\n [OperatorName.IsMoreThan]: inline(Operator.IsMoreThan)\n }),\n [ComponentType.TimeField]: {\n ...absoluteDateTimeOperators,\n ...relativeTimeOperators(timeUnits)\n },\n [ComponentType.DatePartsField]: {\n ...absoluteDateTimeOperators,\n ...relativeTimeOperators(dateUnits)\n },\n [ComponentType.TextField]: withDefaults(textFieldOperators),\n [ComponentType.MultilineTextField]: withDefaults(textFieldOperators),\n [ComponentType.EmailAddressField]: withDefaults(textFieldOperators),\n [ComponentType.YesNoField]: defaultOperators\n}\n\nexport function getOperatorNames(fieldType?: ComponentType) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return []\n }\n\n return Object.keys(conditionals).sort()\n}\n\nexport function getExpression(\n fieldType: ComponentType,\n fieldName: string,\n operator: OperatorName,\n value: ConditionValue | RelativeTimeValue\n) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return\n }\n\n return conditionals[operator]?.expression(\n { type: fieldType, name: fieldName },\n value\n )\n}\n\nexport function getOperatorConfig(\n fieldType: ComponentType,\n operator: OperatorName\n) {\n return getConditionals(fieldType)?.[operator]\n}\n\nfunction getConditionals(\n fieldType?: ComponentType\n): Partial<Conditionals> | undefined {\n if (!fieldType || !isConditionalType(fieldType)) {\n return\n }\n\n return fieldType in customOperators\n ? customOperators[fieldType]\n : defaultOperators\n}\n\nfunction inline(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `${field.name} ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction lengthIs(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `length(${field.name}) ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction reverseInline(operator: Operator.Contains): OperatorDefinition {\n return {\n expression(field, value) {\n return `${formatValue(field, value)} ${operator} ${field.name}`\n }\n }\n}\n\nfunction not(operatorDefinition: OperatorDefinition): OperatorDefinition {\n return {\n expression(field, value) {\n return `not (${operatorDefinition.expression(field, value)})`\n }\n }\n}\n\nfunction formatValue(\n field: Pick<ComponentDef, 'type'>,\n value: ConditionValue | RelativeTimeValue\n) {\n if (\n 'value' in value &&\n (field.type === ComponentType.YesNoField ||\n field.type === ComponentType.NumberField)\n ) {\n return value.value\n }\n\n return `'${value.toExpression()}'`\n}\n\nexport const absoluteDateOrTimeOperatorNames = Object.keys(\n absoluteDateTimeOperators\n)\n\nexport const relativeDateOrTimeOperatorNames = Object.keys(\n relativeTimeOperators(dateTimeUnits)\n)\n\nfunction absoluteDateTime(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n if (!(value instanceof ConditionValue)) {\n throw new Error(\n \"Expression param 'value' must be ConditionValue instance\"\n )\n }\n\n return `${field.name} ${operator} '${formatValue(field, value)}'`\n }\n }\n}\n\nfunction relativeTime(\n pastOperator: Operator,\n futureOperator: Operator,\n units: DateUnits | TimeUnits\n): OperatorDefinition {\n return {\n units,\n expression(field, value) {\n if (!(value instanceof RelativeTimeValue)) {\n throw new Error(\n \"Expression param 'value' must be RelativeTimeValue instance\"\n )\n }\n\n const isPast = value.direction === DateDirections.PAST\n return `${field.name} ${isPast ? pastOperator : futureOperator} ${value.toExpression()}`\n }\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AAE1B,SAASC,aAAa;AAEtB,SACEC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,cAAc,EACdC,iBAAiB;AAEnB,SACEC,cAAc,EACdC,QAAQ,EACRC,YAAY;AASd,MAAMC,gBAAgB,GAAG;EACvB,CAACD,YAAY,CAACE,EAAE,GAAGC,MAAM,CAACJ,QAAQ,CAACG,EAAE,CAAC;EACtC,CAACF,YAAY,CAACI,KAAK,GAAGD,MAAM,CAACJ,QAAQ,CAACK,KAAK;AAC7C,CAAC;AAED,SAASC,YAAYA,CAAIC,KAAQ,EAAE;EACjC,OAAOC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEF,KAAK,EAAEL,gBAAgB,CAAC;AACnD;AAEA,MAAMQ,kBAAkB,GAAG;EACzB,CAACT,YAAY,CAACU,YAAY,GAAGC,QAAQ,CAACZ,QAAQ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ACI,KAAK,EAAEL,KAAK,EAAE;MACvB,IAAI,EAAEA,KAAK,YAAYnD,iBAAiB,CAAC,EAAE;QACzC,MAAM,IAAI8D,KAAK,CACb,6DACF,CAAC;MACH;MAEA,MAAMG,MAAM,GAAGd,KAAK,CAACe,SAAS,KAAKjE,cAAc,CAACkE,IAAI;MACtD,OAAO,GAAGX,KAAK,CAACF,IAAI,IAAIW,MAAM,GAAGF,YAAY,GAAGC,cAAc,IAAIb,KAAK,CAACQ,YAAY,CAAC,CAAC,EAAE;IAC1F;EACF,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"condition-operators.js","names":["isConditionalType","ComponentType","timeUnits","dateUnits","dateTimeUnits","ConditionValue","RelativeTimeValue","DateDirections","Operator","OperatorName","defaultOperators","Is","inline","IsNot","withDefaults","param","Object","assign","textFieldOperators","IsLongerThan","lengthIs","IsMoreThan","IsShorterThan","IsLessThan","HasLength","absoluteDateTimeOperators","absoluteDateTime","IsBefore","IsAfter","relativeTimeOperators","units","IsAtLeast","relativeTime","IsAtMost","customOperators","RadiosField","CheckboxesField","Contains","reverseInline","DoesNotContain","not","NumberField","TimeField","DatePartsField","TextField","MultilineTextField","EmailAddressField","YesNoField","getOperatorNames","fieldType","conditionals","getConditionals","keys","sort","getExpression","fieldName","operator","value","expression","type","name","getOperatorConfig","field","formatValue","operatorDefinition","toExpression","absoluteDateOrTimeOperatorNames","relativeDateOrTimeOperatorNames","Error","pastOperator","futureOperator","isPast","direction","PAST"],"sources":["../../../src/conditions/condition-operators.ts"],"sourcesContent":["import { isConditionalType } from '../components/helpers.js'\n\nimport { ComponentType } from '~/src/components/enums.js'\nimport { type ComponentDef } from '~/src/components/types.js'\nimport {\n timeUnits,\n dateUnits,\n dateTimeUnits,\n ConditionValue,\n RelativeTimeValue\n} from '~/src/conditions/condition-values.js'\nimport {\n DateDirections,\n Operator,\n OperatorName\n} from '~/src/conditions/enums.js'\nimport {\n type Conditionals,\n type DateUnits,\n type OperatorDefinition,\n type TimeUnits\n} from '~/src/conditions/types.js'\n\nconst defaultOperators = {\n [OperatorName.Is]: inline(Operator.Is),\n [OperatorName.IsNot]: inline(Operator.IsNot)\n}\n\nfunction withDefaults<T>(param: T) {\n return Object.assign({}, param, defaultOperators)\n}\n\nconst textFieldOperators = {\n [OperatorName.IsLongerThan]: lengthIs(Operator.IsMoreThan),\n [OperatorName.IsShorterThan]: lengthIs(Operator.IsLessThan),\n [OperatorName.HasLength]: lengthIs(Operator.Is)\n}\n\nconst absoluteDateTimeOperators = {\n [OperatorName.Is]: absoluteDateTime(Operator.Is),\n [OperatorName.IsNot]: absoluteDateTime(Operator.IsNot),\n [OperatorName.IsBefore]: absoluteDateTime(Operator.IsLessThan),\n [OperatorName.IsAfter]: absoluteDateTime(Operator.IsMoreThan)\n}\n\nconst relativeTimeOperators = (units: DateUnits | TimeUnits) => ({\n [OperatorName.IsAtLeast]: relativeTime(\n Operator.IsAtMost,\n Operator.IsAtLeast,\n units\n ),\n [OperatorName.IsAtMost]: relativeTime(\n Operator.IsAtLeast,\n Operator.IsAtMost,\n units\n ),\n [OperatorName.IsLessThan]: relativeTime(\n Operator.IsMoreThan,\n Operator.IsLessThan,\n units\n ),\n [OperatorName.IsMoreThan]: relativeTime(\n Operator.IsLessThan,\n Operator.IsMoreThan,\n units\n )\n})\n\nexport const customOperators = {\n [ComponentType.RadiosField]: defaultOperators,\n [ComponentType.CheckboxesField]: {\n [OperatorName.Contains]: reverseInline(Operator.Contains),\n [OperatorName.DoesNotContain]: not(reverseInline(Operator.Contains))\n },\n [ComponentType.NumberField]: withDefaults({\n [OperatorName.IsAtLeast]: inline(Operator.IsAtLeast),\n [OperatorName.IsAtMost]: inline(Operator.IsAtMost),\n [OperatorName.IsLessThan]: inline(Operator.IsLessThan),\n [OperatorName.IsMoreThan]: inline(Operator.IsMoreThan)\n }),\n [ComponentType.TimeField]: {\n ...absoluteDateTimeOperators,\n ...relativeTimeOperators(timeUnits)\n },\n [ComponentType.DatePartsField]: {\n ...absoluteDateTimeOperators,\n ...relativeTimeOperators(dateUnits)\n },\n [ComponentType.TextField]: withDefaults(textFieldOperators),\n [ComponentType.MultilineTextField]: withDefaults(textFieldOperators),\n [ComponentType.EmailAddressField]: withDefaults(textFieldOperators),\n [ComponentType.YesNoField]: defaultOperators\n}\n\nexport function getOperatorNames(fieldType?: ComponentType) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return []\n }\n\n return Object.keys(conditionals).sort()\n}\n\nexport function getExpression(\n fieldType: ComponentType,\n fieldName: string,\n operator: OperatorName,\n value: ConditionValue | RelativeTimeValue\n) {\n const conditionals = getConditionals(fieldType)\n if (!conditionals) {\n return\n }\n\n return conditionals[operator]?.expression(\n { type: fieldType, name: fieldName },\n value\n )\n}\n\nexport function getOperatorConfig(\n fieldType: ComponentType,\n operator: OperatorName\n) {\n return getConditionals(fieldType)?.[operator]\n}\n\nfunction getConditionals(\n fieldType?: ComponentType\n): Partial<Conditionals> | undefined {\n if (!fieldType || !isConditionalType(fieldType)) {\n return\n }\n\n return fieldType in customOperators\n ? customOperators[fieldType]\n : defaultOperators\n}\n\nfunction inline(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `${field.name} ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction lengthIs(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n return `length(${field.name}) ${operator} ${formatValue(field, value)}`\n }\n }\n}\n\nfunction reverseInline(operator: Operator.Contains): OperatorDefinition {\n return {\n expression(field, value) {\n return `${formatValue(field, value)} ${operator} ${field.name}`\n }\n }\n}\n\nfunction not(operatorDefinition: OperatorDefinition): OperatorDefinition {\n return {\n expression(field, value) {\n return `not (${operatorDefinition.expression(field, value)})`\n }\n }\n}\n\nfunction formatValue(\n field: Pick<ComponentDef, 'type'>,\n value: ConditionValue | RelativeTimeValue\n) {\n if (\n 'value' in value &&\n (field.type === ComponentType.YesNoField ||\n field.type === ComponentType.NumberField)\n ) {\n return value.value\n }\n\n return `'${value.toExpression()}'`\n}\n\nexport const absoluteDateOrTimeOperatorNames = Object.keys(\n absoluteDateTimeOperators\n) as OperatorName[]\n\nexport const relativeDateOrTimeOperatorNames = Object.keys(\n relativeTimeOperators(dateTimeUnits)\n) as OperatorName[]\n\nfunction absoluteDateTime(operator: Operator): OperatorDefinition {\n return {\n expression(field, value) {\n if (!(value instanceof ConditionValue)) {\n throw new Error(\n \"Expression param 'value' must be ConditionValue instance\"\n )\n }\n\n return `${field.name} ${operator} '${formatValue(field, value)}'`\n }\n }\n}\n\nfunction relativeTime(\n pastOperator: Operator,\n futureOperator: Operator,\n units: DateUnits | TimeUnits\n): OperatorDefinition {\n return {\n units,\n expression(field, value) {\n if (!(value instanceof RelativeTimeValue)) {\n throw new Error(\n \"Expression param 'value' must be RelativeTimeValue instance\"\n )\n }\n\n const isPast = value.direction === DateDirections.PAST\n return `${field.name} ${isPast ? pastOperator : futureOperator} ${value.toExpression()}`\n }\n }\n}\n"],"mappings":"AAAA,SAASA,iBAAiB;AAE1B,SAASC,aAAa;AAEtB,SACEC,SAAS,EACTC,SAAS,EACTC,aAAa,EACbC,cAAc,EACdC,iBAAiB;AAEnB,SACEC,cAAc,EACdC,QAAQ,EACRC,YAAY;AASd,MAAMC,gBAAgB,GAAG;EACvB,CAACD,YAAY,CAACE,EAAE,GAAGC,MAAM,CAACJ,QAAQ,CAACG,EAAE,CAAC;EACtC,CAACF,YAAY,CAACI,KAAK,GAAGD,MAAM,CAACJ,QAAQ,CAACK,KAAK;AAC7C,CAAC;AAED,SAASC,YAAYA,CAAIC,KAAQ,EAAE;EACjC,OAAOC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEF,KAAK,EAAEL,gBAAgB,CAAC;AACnD;AAEA,MAAMQ,kBAAkB,GAAG;EACzB,CAACT,YAAY,CAACU,YAAY,GAAGC,QAAQ,CAACZ,QAAQ,CAACa,UAAU,CAAC;EAC1D,CAACZ,YAAY,CAACa,aAAa,GAAGF,QAAQ,CAACZ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AiB,CAAC,EAAE;QACzC,MAAM,IAAI8D,KAAK,CACb,6DACF,CAAC;MACH;MAEA,MAAMG,MAAM,GAAGd,KAAK,CAACe,SAAS,KAAKjE,cAAc,CAACkE,IAAI;MACtD,OAAO,GAAGX,KAAK,CAACF,IAAI,IAAIW,MAAM,GAAGF,YAAY,GAAGC,cAAc,IAAIb,KAAK,CAACQ,YAAY,CAAC,CAAC,EAAE;IAC1F;EACF,CAAC;AACH","ignoreList":[]}
@@ -9,7 +9,6 @@ type ConditionRawObject = ConditionsModel | {
9
9
  };
10
10
  export declare class ConditionsModel {
11
11
  #private;
12
- constructor(_conditionsObject?: ConditionRawObject);
13
12
  clone(): ConditionsModel;
14
13
  clear(): this;
15
14
  set name(name: string | undefined);
@@ -1 +1 @@
1
- {"version":3,"file":"condition-model.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAA;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAGzD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAEhE,KAAK,kBAAkB,GACnB,eAAe,GACf;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,SAAS,EAAE,CAAA;CACxB,CAAA;AAEL,qBAAa,eAAe;;gBAKd,iBAAiB,CAAC,EAAE,kBAAkB;IAElD,KAAK;IAYL,KAAK;IAOL,IAAI,IAAI,CAAC,IAAI,oBAAA,EAEZ;IAED,IAAI,IAAI,uBAEP;IAED,GAAG,CAAC,SAAS,EAAE,SAAS;IAexB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS;IAmB3C,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;IAWxB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KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS;IAmB3C,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE;IAWxB,SAAS,CAAC,SAAS,EAAE,iBAAiB,EAAE;IASxC,UAAU,CAAC,KAAK,EAAE,MAAM;IASxB,WAAW,CAAC,KAAK,EAAE,MAAM;IAezB,SAAS,CAAC,KAAK,EAAE,MAAM;IAevB,kBAAkB;IAOlB,IAAI,kBAAkB,kDAErB;IAED,IAAI,aAAa,YAEhB;IAED,IAAI,SAAS,WAEZ;IAED,oBAAoB;IAMpB,YAAY;IAMZ,YAAY,CACV,qBAAqB,EAAE,CAAC,SAAS,GAAG,cAAc,GAAG,YAAY,CAAC,EAAE;IAmBtE,MAAM,CAAC,UAAU,EAAE,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE;IAoBlE,QAAQ,CAAC,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM;IAaxD,cAAc,CAAC,UAAU,EAAE,eAAe;IAkC1C,MAAM;;;;IAUN,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,kBAAkB,GAAG,eAAe;CActD"}
@@ -72,6 +72,6 @@ export declare const customOperators: {
72
72
  export declare function getOperatorNames(fieldType?: ComponentType): string[];
73
73
  export declare function getExpression(fieldType: ComponentType, fieldName: string, operator: OperatorName, value: ConditionValue | RelativeTimeValue): string | undefined;
74
74
  export declare function getOperatorConfig(fieldType: ComponentType, operator: OperatorName): OperatorDefinition | undefined;
75
- export declare const absoluteDateOrTimeOperatorNames: string[];
76
- export declare const relativeDateOrTimeOperatorNames: string[];
75
+ export declare const absoluteDateOrTimeOperatorNames: OperatorName[];
76
+ export declare const relativeDateOrTimeOperatorNames: OperatorName[];
77
77
  //# sourceMappingURL=condition-operators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"condition-operators.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-operators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAEzD,OAAO,EAIL,cAAc,EACd,iBAAiB,EAClB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAGL,YAAY,EACb,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,2BAA2B,CAAA;AA+ClC,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwB3B,CAAA;AAED,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,aAAa,YAOzD;AAED,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,cAAc,GAAG,iBAAiB,sBAW1C;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,aAAa,EACxB,QAAQ,EAAE,YAAY,kCAGvB;AA6DD,eAAO,MAAM,+BAA+B,UAE3C,CAAA;AAED,eAAO,MAAM,+BAA+B,UAE3C,CAAA"}
1
+ {"version":3,"file":"condition-operators.d.ts","sourceRoot":"","sources":["../../../src/conditions/condition-operators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAEzD,OAAO,EAIL,cAAc,EACd,iBAAiB,EAClB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAGL,YAAY,EACb,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAGL,KAAK,kBAAkB,EAExB,MAAM,2BAA2B,CAAA;AA+ClC,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwB3B,CAAA;AAED,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,aAAa,YAOzD;AAED,wBAAgB,aAAa,CAC3B,SAAS,EAAE,aAAa,EACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,cAAc,GAAG,iBAAiB,sBAW1C;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,aAAa,EACxB,QAAQ,EAAE,YAAY,kCAGvB;AA6DD,eAAO,MAAM,+BAA+B,EAEvC,YAAY,EAAE,CAAA;AAEnB,eAAO,MAAM,+BAA+B,EAEvC,YAAY,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-model",
3
- "version": "3.0.218",
3
+ "version": "3.0.220",
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": {
@@ -20,8 +20,6 @@ export class ConditionsModel {
20
20
  #userGroupedConditions: ConditionsArray = []
21
21
  #conditionName: string | undefined = undefined
22
22
 
23
- constructor(_conditionsObject?: ConditionRawObject) {}
24
-
25
23
  clone() {
26
24
  const toReturn = new ConditionsModel()
27
25
  toReturn.#groupedConditions = this.#groupedConditions.map((it) =>
@@ -186,11 +186,11 @@ function formatValue(
186
186
 
187
187
  export const absoluteDateOrTimeOperatorNames = Object.keys(
188
188
  absoluteDateTimeOperators
189
- )
189
+ ) as OperatorName[]
190
190
 
191
191
  export const relativeDateOrTimeOperatorNames = Object.keys(
192
192
  relativeTimeOperators(dateTimeUnits)
193
- )
193
+ ) as OperatorName[]
194
194
 
195
195
  function absoluteDateTime(operator: Operator): OperatorDefinition {
196
196
  return {