@legalplace/tagextractor 1.3.0 → 2.0.0

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.
@@ -1,7 +1,7 @@
1
1
  import { ModelV3 } from '@legalplace/models-v3-types';
2
2
  import { ReferencesType } from '@legalplace/referencesparser/dist/libs/References.type';
3
- import InputsType from '../types/inputs.type';
4
- import OvcType from '../types/ovc.type';
3
+ import InputsType from '@legalplace/types/dist/inputs';
4
+ import OvcType from '@legalplace/types/dist/ovc';
5
5
  import TagsType from '../types/tags.type';
6
6
  declare class TagExtractor {
7
7
  private references;
@@ -11,8 +11,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  var referencesparser_1 = require("@legalplace/referencesparser");
14
- var ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
15
- var OvcConverter_1 = __importDefault(require("./OvcConverter"));
14
+ var conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
15
+ var ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
16
16
  var TagExtractor = (function () {
17
17
  function TagExtractor(modelOrReferences, ovc) {
18
18
  this.tags = {
@@ -23,8 +23,8 @@ var TagExtractor = (function () {
23
23
  return Object.keys(_obj).some(function (key) { return key === 'boxes'; });
24
24
  };
25
25
  this.references = this.isReferencesType(modelOrReferences) ? modelOrReferences : new referencesparser_1.ReferencesParser(modelOrReferences).references;
26
- this.inputs = OvcConverter_1.default.isOptionsVariables(ovc) ? ovc : OvcConverter_1.default.convertToOptionsVariables(ovc, this.references);
27
- this.conditionsRunner = new ConditionsRunner_1.default(this.references, this.inputs);
26
+ this.inputs = ovc_converter_1.default.isOptionsVariables(ovc) ? ovc : ovc_converter_1.default.convertToOptionsVariables(ovc, this.references);
27
+ this.conditionsRunner = new conditions_runner_1.default(this.references, this.inputs);
28
28
  this.extractFromOptions();
29
29
  this.extractFromVariables();
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/tagextractor",
3
- "version": "1.3.0",
3
+ "version": "2.0.0",
4
4
  "description": "TagExtractor",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/tagextractor",
@@ -14,15 +14,17 @@
14
14
  "build": "tsc"
15
15
  },
16
16
  "dependencies": {
17
- "@legalplace/lplogic": "^2.1.6",
18
- "@legalplace/models-v3-types": "^3.4.47",
19
- "@legalplace/referencesparser": "^1.6.1",
20
- "crypto": "^1.0.1",
17
+ "@legalplace/conditions-runner": "1.1.0",
18
+ "@legalplace/lplogic": "2.1.6",
19
+ "@legalplace/models-v3-types": "3.4.47",
20
+ "@legalplace/ovc-converter": "1.1.0",
21
+ "@legalplace/referencesparser": "1.6.3",
21
22
  "typescript": "3.9.3"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@babel/core": "^7.7.2",
25
26
  "@babel/preset-typescript": "^7.7.2",
27
+ "@legalplace/types": "1.1.0",
26
28
  "@types/jest": "^24.0.15",
27
29
  "@types/node": "^12.12.6",
28
30
  "@typescript-eslint/eslint-plugin": "^2.6.1",
@@ -38,4 +40,4 @@
38
40
  "redux-mock-store": "^1.5.3",
39
41
  "ts-jest": "^24.0.2"
40
42
  }
41
- }
43
+ }
@@ -1,11 +1,11 @@
1
1
  import { ModelV3 } from '@legalplace/models-v3-types'
2
2
  import { ReferencesParser, Types } from '@legalplace/referencesparser'
3
3
  import { ReferencesType } from '@legalplace/referencesparser/dist/libs/References.type'
4
- import InputsType from '../types/inputs.type'
5
- import OvcType from '../types/ovc.type'
4
+ import ConditionsRunner from '@legalplace/conditions-runner'
5
+ import OvcConverter from '@legalplace/ovc-converter'
6
+ import InputsType from '@legalplace/types/dist/inputs'
7
+ import OvcType from '@legalplace/types/dist/ovc'
6
8
  import TagsType from '../types/tags.type'
7
- import ConditionsRunner from './ConditionsRunner'
8
- import OvcConverter from './OvcConverter'
9
9
 
10
10
  class TagExtractor {
11
11
  private references: Types.ReferencesType
@@ -1,19 +0,0 @@
1
- import { Types } from '@legalplace/referencesparser';
2
- import { ConditionV3 } from '@legalplace/models-v3-types';
3
- import { ConditionDataMap } from './DataPopulator';
4
- import InputsType from '../types/inputs.type';
5
- declare class ConditionsRunner {
6
- private references;
7
- private ovc;
8
- constructor(references: Types.ReferencesType, ovc: InputsType);
9
- isOptionRelatedToOption(optionA: number, optionB: number): boolean;
10
- isVariableRelatedToOption(variableId: number, optionId: number): boolean;
11
- isVariableRelatedToVariable(variableA: number, variableB: number): boolean;
12
- private executeConditionMemo;
13
- private buildMemoizeKey;
14
- executeCondition(condition: {
15
- dataMap: ConditionDataMap;
16
- conditions: ConditionV3;
17
- }, id: number, index: number, conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'): any;
18
- }
19
- export default ConditionsRunner;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
7
- var DataPopulator_1 = __importDefault(require("./DataPopulator"));
8
- var ConditionsRunner = (function () {
9
- function ConditionsRunner(references, ovc) {
10
- this.executeConditionMemo = {};
11
- this.buildMemoizeKey = function (condition, id, index, conditionType) { return JSON.stringify(condition) + "-" + id + "-" + index + "-" + conditionType; };
12
- this.references = references;
13
- this.ovc = ovc;
14
- }
15
- ConditionsRunner.prototype.isOptionRelatedToOption = function (optionA, optionB) {
16
- var OptionBParents = this.references.relations.options[optionB].parents;
17
- var OptionBRoot = OptionBParents[OptionBParents.length - 1];
18
- var OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined;
19
- if (OptionBRootRelations) {
20
- if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
21
- return true;
22
- }
23
- }
24
- return false;
25
- };
26
- ConditionsRunner.prototype.isVariableRelatedToOption = function (variableId, optionId) {
27
- var variableParentId = this.references.relations.variables[variableId].parents[0];
28
- var optionParents = this.references.relations.options[variableParentId].parents;
29
- var optionRoot = optionParents[optionParents.length - 1];
30
- var optionRootRelations = optionRoot ? this.references.relations.options[optionRoot] : undefined;
31
- if (optionRootRelations) {
32
- if (optionRootRelations.children.options.includes(optionId) || optionRootRelations.dependants.includes(optionId)) {
33
- return true;
34
- }
35
- }
36
- return false;
37
- };
38
- ConditionsRunner.prototype.isVariableRelatedToVariable = function (variableA, variableB) {
39
- var optionA = this.references.relations.variables[variableA].parents[0];
40
- var optionB = this.references.relations.variables[variableB].parents[0];
41
- var OptionBParents = this.references.relations.options[optionB].parents;
42
- var OptionBRoot = OptionBParents[OptionBParents.length - 1];
43
- var OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined;
44
- if (OptionBRootRelations) {
45
- if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
46
- return true;
47
- }
48
- }
49
- return false;
50
- };
51
- ConditionsRunner.prototype.executeCondition = function (condition, id, index, conditionType) {
52
- var memoizedKey = this.buildMemoizeKey(condition, id, index, conditionType);
53
- if (this.executeConditionMemo[memoizedKey])
54
- return this.executeConditionMemo[memoizedKey];
55
- var currentData;
56
- if (conditionType === 'options' || conditionType === 'optionValidator') {
57
- currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
58
- }
59
- else if (conditionType === 'variables' || conditionType === 'prefillers' || conditionType === 'variableValidator') {
60
- var dataId = this.references.relations.variables[id].parents[0];
61
- currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, dataId, index).getData();
62
- }
63
- else if (conditionType === 'sections' || conditionType === 'documents') {
64
- currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
65
- }
66
- var result = lplogic_1.default(condition.conditions, currentData);
67
- this.executeConditionMemo[memoizedKey] = result;
68
- return result;
69
- };
70
- return ConditionsRunner;
71
- }());
72
- exports.default = ConditionsRunner;
@@ -1,53 +0,0 @@
1
- import { Types } from '@legalplace/referencesparser';
2
- import ConditionsRunner from './ConditionsRunner';
3
- declare type OVC_TYPE = {
4
- options: {
5
- [key: string]: boolean[];
6
- };
7
- variables: {
8
- [key: string]: (number | string)[];
9
- };
10
- };
11
- declare class DataPopulator {
12
- private references;
13
- private ovc;
14
- private conditionsRunner;
15
- private id?;
16
- private index?;
17
- private dataMap;
18
- private data;
19
- constructor(conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: OVC_TYPE, dataMap: ConditionDataMap, id?: number, index?: number);
20
- getData(): Readonly<ConditionData>;
21
- private populateConditions;
22
- private getOptionConditions;
23
- private getVariablesConditions;
24
- private populateVariables;
25
- private getVariableValues;
26
- private getVariableRootParent;
27
- private cleanArrayFromNullValues;
28
- populateOptions(): void;
29
- private getOptionInputs;
30
- private getOptionRootParent;
31
- private optionConditionValue;
32
- private variableConditionValue;
33
- private sectionConditionValue;
34
- }
35
- export interface ConditionDataMap {
36
- o: number[];
37
- v: number[];
38
- c: {
39
- o: number[];
40
- s: number[];
41
- v: number[];
42
- };
43
- }
44
- export interface ConditionData {
45
- o: Record<string, boolean[]>;
46
- v: Record<string, (string | number)[]>;
47
- c: {
48
- o: Record<string, boolean[]>;
49
- s: Record<string, boolean[]>;
50
- v: Record<string, boolean[]>;
51
- };
52
- }
53
- export default DataPopulator;
@@ -1,171 +0,0 @@
1
- "use strict";
2
- var __spreadArrays = (this && this.__spreadArrays) || function () {
3
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
- r[k] = a[j];
7
- return r;
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- var DataPopulator = (function () {
11
- function DataPopulator(conditionsRunner, references, ovc, dataMap, id, index) {
12
- this.data = {
13
- o: {},
14
- v: {},
15
- c: {
16
- o: {},
17
- s: {},
18
- v: {}
19
- }
20
- };
21
- this.id = id;
22
- this.ovc = ovc;
23
- this.index = index;
24
- this.dataMap = dataMap;
25
- this.references = references;
26
- this.conditionsRunner = conditionsRunner;
27
- this.populateVariables();
28
- this.populateOptions();
29
- this.populateConditions();
30
- }
31
- DataPopulator.prototype.getData = function () {
32
- return this.data;
33
- };
34
- DataPopulator.prototype.populateConditions = function () {
35
- for (var i = 0; i < this.dataMap.c.s.length; i += 1) {
36
- var sectionId = this.dataMap.c.s[i];
37
- var sectionCondition = this.sectionConditionValue(sectionId);
38
- this.data.c.s[sectionId] = [sectionCondition !== false];
39
- }
40
- for (var i = 0; i < this.dataMap.c.o.length; i += 1) {
41
- var optionId = this.dataMap.c.o[i];
42
- var optionCondition = __spreadArrays(this.getOptionConditions(optionId));
43
- this.data.c.o[optionId] = optionCondition === undefined ? [false] : optionCondition;
44
- }
45
- for (var i = 0; i < this.dataMap.c.v.length; i += 1) {
46
- var variableId = this.dataMap.c.v[i];
47
- var variableCondition = __spreadArrays(this.getVariablesConditions(variableId));
48
- this.data.c.v[variableId] = variableCondition === undefined ? [false] : variableCondition;
49
- }
50
- };
51
- DataPopulator.prototype.getOptionConditions = function (optionId) {
52
- var conditions = this.optionConditionValue(optionId);
53
- if (conditions === undefined)
54
- return [true];
55
- if (this.id === undefined || this.index === undefined) {
56
- return conditions;
57
- }
58
- var optionRootParent = this.getOptionRootParent(optionId);
59
- var optionRootRelations = this.references.relations.options[optionRootParent];
60
- if (optionRootRelations.children.options.includes(this.id) || optionRootRelations.dependants.includes(this.id) || this.id === optionRootParent) {
61
- if (conditions !== undefined && conditions[this.index] === false)
62
- return [false];
63
- return [conditions[this.index]];
64
- }
65
- return conditions;
66
- };
67
- DataPopulator.prototype.getVariablesConditions = function (variableId) {
68
- var conditions = this.variableConditionValue(variableId);
69
- if (conditions === undefined)
70
- return [true];
71
- if (this.id === undefined || this.index === undefined) {
72
- return conditions;
73
- }
74
- var variableRootParent = this.getVariableRootParent(variableId);
75
- var variableRootRelations = this.references.relations.options[variableRootParent];
76
- if (variableRootRelations.children.options.includes(this.id) || variableRootRelations.dependants.includes(this.id) || this.id === variableRootParent) {
77
- return [conditions[this.index]];
78
- }
79
- return conditions;
80
- };
81
- DataPopulator.prototype.populateVariables = function () {
82
- var _loop_1 = function (i) {
83
- var variableId = this_1.dataMap.v[i];
84
- var variableReference = this_1.references.variables[variableId];
85
- var values = this_1.getVariableValues(variableId);
86
- var parseNumber = function (v) {
87
- var result = parseFloat(v);
88
- return Number.isNaN(result) ? '' : result;
89
- };
90
- if (variableReference.type === 'number') {
91
- values = values.map(function (v) { return (typeof v === 'number' ? v : parseNumber(v)); });
92
- }
93
- this_1.data.v[variableId] = __spreadArrays(values);
94
- };
95
- var this_1 = this;
96
- for (var i = 0; i < this.dataMap.v.length; i += 1) {
97
- _loop_1(i);
98
- }
99
- };
100
- DataPopulator.prototype.getVariableValues = function (variableId) {
101
- var value = this.ovc.variables[variableId];
102
- if (this.id === undefined || this.index === undefined) {
103
- return value;
104
- }
105
- var variableRootParent = this.getVariableRootParent(variableId);
106
- var variableRootRelations = this.references.relations.options[variableRootParent];
107
- if (variableRootRelations.children.options.includes(this.id) || variableRootRelations.dependants.includes(this.id) || this.id === variableRootParent) {
108
- return [value[this.index]];
109
- }
110
- return this.cleanArrayFromNullValues(__spreadArrays(value));
111
- };
112
- DataPopulator.prototype.getVariableRootParent = function (variableId) {
113
- var variableParents = this.references.relations.variables[variableId].parents;
114
- return variableParents[variableParents.length - 1];
115
- };
116
- DataPopulator.prototype.cleanArrayFromNullValues = function (arr) {
117
- return arr.map(function (v) { return (v === null ? '' : v); });
118
- };
119
- DataPopulator.prototype.populateOptions = function () {
120
- for (var i = 0; i < this.dataMap.o.length; i += 1) {
121
- var optionId = this.dataMap.o[i];
122
- var inputs = this.getOptionInputs(optionId);
123
- this.data.o[optionId] = __spreadArrays(inputs);
124
- }
125
- };
126
- DataPopulator.prototype.getOptionInputs = function (optionId) {
127
- var inputs = this.ovc.options[optionId];
128
- if (this.id === undefined || this.index === undefined) {
129
- return inputs;
130
- }
131
- var optionRootParent = this.getOptionRootParent(optionId);
132
- var optionRootRelations = this.references.relations.options[optionRootParent];
133
- if (optionRootRelations.children.options.includes(this.id) || optionRootRelations.dependants.includes(this.id) || this.id === optionRootParent) {
134
- return [inputs[this.index]];
135
- }
136
- return inputs;
137
- };
138
- DataPopulator.prototype.getOptionRootParent = function (optionId) {
139
- var optionParents = this.references.relations.options[optionId].parents;
140
- return optionParents.length > 0 ? optionParents[optionParents.length - 1] : optionId;
141
- };
142
- DataPopulator.prototype.optionConditionValue = function (optionId) {
143
- var _this = this;
144
- var conditions = this.references.conditions.options[optionId];
145
- if (conditions === undefined)
146
- return undefined;
147
- var inputs = this.ovc.options[optionId];
148
- return inputs.map(function (input, index) {
149
- return _this.conditionsRunner.executeCondition(conditions, optionId, index, 'options');
150
- });
151
- };
152
- DataPopulator.prototype.variableConditionValue = function (variableId) {
153
- var _this = this;
154
- var conditions = this.references.conditions.variables[variableId];
155
- if (conditions === undefined)
156
- return undefined;
157
- var inputs = this.ovc.variables[variableId];
158
- var result = inputs.map(function (input, index) {
159
- return _this.conditionsRunner.executeCondition(conditions, variableId, index, 'variables');
160
- });
161
- return result;
162
- };
163
- DataPopulator.prototype.sectionConditionValue = function (sectionId) {
164
- var conditions = this.references.conditions.sections.main[sectionId];
165
- if (conditions === undefined)
166
- return undefined;
167
- return this.conditionsRunner.executeCondition(conditions, 0, 0, 'sections');
168
- };
169
- return DataPopulator;
170
- }());
171
- exports.default = DataPopulator;
@@ -1,14 +0,0 @@
1
- import { Types } from '@legalplace/referencesparser';
2
- import InputsType from '../types/inputs.type';
3
- import OvcType from '../types/ovc.type';
4
- declare class OvcConverter {
5
- convertToOptionsVariables(ovc: OvcType, references: Types.ReferencesType): InputsType;
6
- isOvc(_obj: InputsType | OvcType): _obj is OvcType;
7
- isOptionsVariables(_obj: InputsType | OvcType): _obj is InputsType;
8
- private pushStaticChildren;
9
- private pushLeftOver;
10
- private pushLeftOverOption;
11
- private pushLeftOverVariable;
12
- }
13
- declare const _default: OvcConverter;
14
- export default _default;
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __spreadArrays = (this && this.__spreadArrays) || function () {
14
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
15
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
16
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
17
- r[k] = a[j];
18
- return r;
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- var OvcConverter = (function () {
22
- function OvcConverter() {
23
- }
24
- OvcConverter.prototype.convertToOptionsVariables = function (ovc, references) {
25
- var _this = this;
26
- var inputs = {
27
- options: {},
28
- variables: {}
29
- };
30
- if (typeof ovc !== 'object')
31
- return inputs;
32
- if (typeof ovc.o === 'object') {
33
- Object.keys(ovc.o).forEach(function (id) {
34
- var currentOption = ovc.o[id];
35
- if (Array.isArray(currentOption)) {
36
- var occurences_1 = currentOption.length;
37
- inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, id, occurences_1, references));
38
- currentOption.forEach(function (childId, index) {
39
- var sanitizedId = typeof childId === 'string' && childId.split('_').length > 0 ? childId.split('_')[0] : childId;
40
- if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
41
- var defaultValue = references.options[id].meta.type === 'static';
42
- inputs.options[id] = new Array(occurences_1).fill(defaultValue);
43
- }
44
- if (typeof sanitizedId === 'string' && sanitizedId.trim().length === 0) {
45
- return;
46
- }
47
- if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
48
- var defaultValue = references.options[sanitizedId].meta.type === 'static';
49
- inputs.options[sanitizedId] = new Array(occurences_1).fill(defaultValue);
50
- }
51
- inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, sanitizedId, occurences_1, references));
52
- inputs.options[sanitizedId][index] = true;
53
- });
54
- }
55
- else {
56
- if (typeof currentOption === 'string' && currentOption.trim().length === 0)
57
- return;
58
- inputs.options[currentOption] = [true];
59
- }
60
- });
61
- }
62
- Object.keys(references.options).forEach(function (optionId) {
63
- var option = references.options[optionId];
64
- var parents = references.relations.options[optionId].parents;
65
- if (inputs.options[optionId] === undefined && parents.length === 0 && option.meta.type === 'static') {
66
- inputs.options[optionId] = [true];
67
- }
68
- });
69
- if (typeof ovc.c === 'object') {
70
- Object.keys(ovc.c).forEach(function (id) {
71
- var currentCheckbox = ovc.c[id];
72
- if (typeof id === 'string' && id.trim().length === 0)
73
- return;
74
- if (Array.isArray(currentCheckbox)) {
75
- inputs.options[id] = currentCheckbox;
76
- }
77
- else {
78
- inputs.options[id] = [currentCheckbox];
79
- }
80
- });
81
- }
82
- if (typeof ovc.v === 'object') {
83
- Object.keys(ovc.v).forEach(function (id) {
84
- var currentVariable = ovc.v[id];
85
- if (Array.isArray(currentVariable)) {
86
- inputs.variables[id] = currentVariable;
87
- var parentsTree = references.relations.variables[id].parents;
88
- var parentOption = inputs.options["" + parentsTree[parentsTree.length - 1]];
89
- if (Array.isArray(parentOption)) {
90
- var occurences = parentOption.length;
91
- if (currentVariable.length < occurences) {
92
- inputs.variables[id] = __spreadArrays(currentVariable, Array(occurences - currentVariable.length).fill(''));
93
- }
94
- }
95
- }
96
- else {
97
- inputs.variables[id] = [currentVariable];
98
- }
99
- });
100
- }
101
- return this.pushLeftOver(inputs, references);
102
- };
103
- OvcConverter.prototype.isOvc = function (_obj) {
104
- if (typeof _obj !== 'object' || _obj === null)
105
- return false;
106
- var ovcKeys = ['o', 'v', 'c'];
107
- var foundKeys = Object.keys(_obj)
108
- .map(function (key) { return (ovcKeys.includes(key) ? 1 : 0); })
109
- .reduce(function (a, b) { return a + b; }, 0);
110
- return foundKeys > 1;
111
- };
112
- OvcConverter.prototype.isOptionsVariables = function (_obj) {
113
- if (typeof _obj !== 'object' || _obj === null)
114
- return false;
115
- var optionsVariablesKeys = ['options', 'variables'];
116
- var foundKeys = Object.keys(_obj)
117
- .map(function (key) { return (optionsVariablesKeys.includes(key) ? 1 : 0); })
118
- .reduce(function (a, b) { return a + b; }, 0);
119
- return foundKeys === 2;
120
- };
121
- OvcConverter.prototype.pushStaticChildren = function (inputOptions, id, occurences, references) {
122
- var result = __assign({}, inputOptions);
123
- var intId = typeof id === 'number' ? id : parseInt(id, 10);
124
- var options = references.relations.options[intId].children.options;
125
- var staticOptions = options.filter(function (childId) {
126
- return references.options[childId].meta.type === 'static';
127
- });
128
- staticOptions.forEach(function (childId) {
129
- if (!Object.prototype.hasOwnProperty.call(result, childId)) {
130
- result[childId] = new Array(occurences).fill(true);
131
- }
132
- });
133
- return result;
134
- };
135
- OvcConverter.prototype.pushLeftOver = function (inputs, references) {
136
- var _this = this;
137
- var result = __assign({}, inputs);
138
- Object.values(references.sections).forEach(function (document) {
139
- Object.values(document).forEach(function (section) {
140
- section.options.forEach(function (optionId) {
141
- var occurences = inputs.options[optionId] === undefined ? 1 : inputs.options[optionId].length;
142
- result = _this.pushLeftOverOption(result, references, references.options[optionId], occurences);
143
- });
144
- });
145
- });
146
- return result;
147
- };
148
- OvcConverter.prototype.pushLeftOverOption = function (inputs, references, option, occurences) {
149
- var _a;
150
- var _this = this;
151
- var result = __assign({}, inputs);
152
- var defaultValue = !['radio', 'checkbox'].includes(option.meta.type);
153
- if (!Object.prototype.hasOwnProperty.call(result.options, option.meta.id)) {
154
- result = __assign(__assign({}, result), { options: __assign(__assign({}, result.options), (_a = {}, _a[option.meta.id] = new Array(occurences).fill(defaultValue), _a)) });
155
- }
156
- option.options.forEach(function (optionId) {
157
- result = _this.pushLeftOverOption(result, references, references.options[optionId], occurences);
158
- });
159
- option.variables.forEach(function (variableId) {
160
- result = _this.pushLeftOverVariable(result, variableId, occurences);
161
- });
162
- return result;
163
- };
164
- OvcConverter.prototype.pushLeftOverVariable = function (inputs, id, occurences) {
165
- var _a;
166
- if (!Object.prototype.hasOwnProperty.call(inputs.variables, id)) {
167
- return __assign(__assign({}, inputs), { variables: __assign(__assign({}, inputs.variables), (_a = {}, _a[id] = new Array(occurences).fill(''), _a)) });
168
- }
169
- return inputs;
170
- };
171
- return OvcConverter;
172
- }());
173
- exports.default = new OvcConverter();
@@ -1,9 +0,0 @@
1
- declare type InputsType = {
2
- options: {
3
- [key: string]: boolean[];
4
- };
5
- variables: {
6
- [key: string]: (number | string)[];
7
- };
8
- };
9
- export default InputsType;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +0,0 @@
1
- interface OvcType {
2
- o: {
3
- [k: string]: string | number | (string | number)[];
4
- };
5
- v: {
6
- [k: string]: string | number | (string | number)[];
7
- };
8
- c: {
9
- [k: string]: boolean | boolean[];
10
- };
11
- }
12
- export default OvcType;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,114 +0,0 @@
1
- /* eslint-disable max-len */
2
- import LpLogic from '@legalplace/lplogic'
3
- import { Types } from '@legalplace/referencesparser'
4
- import { ConditionV3 } from '@legalplace/models-v3-types'
5
- import DataPopulator, { ConditionDataMap } from './DataPopulator'
6
- import InputsType from '../types/inputs.type'
7
-
8
- class ConditionsRunner {
9
- private references: Types.ReferencesType
10
-
11
- private ovc: InputsType
12
-
13
- constructor(references: Types.ReferencesType, ovc: InputsType) {
14
- this.references = references
15
- this.ovc = ovc
16
- }
17
-
18
- isOptionRelatedToOption(optionA: number, optionB: number): boolean {
19
- // Getting B relations
20
- const OptionBParents = this.references.relations.options[optionB].parents
21
- const OptionBRoot = OptionBParents[OptionBParents.length - 1]
22
- const OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined
23
-
24
- // Checking if B option is related to the option that changed
25
- if (OptionBRootRelations) {
26
- if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
27
- return true
28
- }
29
- }
30
-
31
- return false
32
- }
33
-
34
- isVariableRelatedToOption(variableId: number, optionId: number): boolean {
35
- // Variable parent
36
- const variableParentId = this.references.relations.variables[variableId].parents[0]
37
-
38
- // Getting B relations
39
- const optionParents = this.references.relations.options[variableParentId].parents
40
- const optionRoot = optionParents[optionParents.length - 1]
41
- const optionRootRelations = optionRoot ? this.references.relations.options[optionRoot] : undefined
42
-
43
- // Checking if B option is related to the option that changed
44
- if (optionRootRelations) {
45
- if (optionRootRelations.children.options.includes(optionId) || optionRootRelations.dependants.includes(optionId)) {
46
- return true
47
- }
48
- }
49
-
50
- return false
51
- }
52
-
53
- isVariableRelatedToVariable(variableA: number, variableB: number): boolean {
54
- // Getting variables options
55
- const optionA = this.references.relations.variables[variableA].parents[0]
56
- const optionB = this.references.relations.variables[variableB].parents[0]
57
-
58
- // Getting B relations
59
- const OptionBParents = this.references.relations.options[optionB].parents
60
- const OptionBRoot = OptionBParents[OptionBParents.length - 1]
61
- const OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined
62
-
63
- // Checking if B option is related to the option that changed
64
- if (OptionBRootRelations) {
65
- if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
66
- return true
67
- }
68
- }
69
-
70
- return false
71
- }
72
-
73
- private executeConditionMemo: Record<string, any> = {}
74
-
75
- private buildMemoizeKey = (
76
- condition: {
77
- dataMap: ConditionDataMap
78
- conditions: ConditionV3
79
- },
80
- id: number,
81
- index: number,
82
- conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
83
- ) => `${JSON.stringify(condition)}-${id}-${index}-${conditionType}`
84
-
85
- executeCondition(
86
- condition: {
87
- dataMap: ConditionDataMap
88
- conditions: ConditionV3
89
- },
90
- id: number,
91
- index: number,
92
- conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
93
- ): any {
94
- const memoizedKey = this.buildMemoizeKey(condition, id, index, conditionType)
95
- if (this.executeConditionMemo[memoizedKey]) return this.executeConditionMemo[memoizedKey]
96
-
97
- // Populating Data
98
- let currentData
99
- if (conditionType === 'options' || conditionType === 'optionValidator') {
100
- currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, id, index).getData()
101
- } else if (conditionType === 'variables' || conditionType === 'prefillers' || conditionType === 'variableValidator') {
102
- const dataId = this.references.relations.variables[id].parents[0]
103
- currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, dataId, index).getData()
104
- } else if (conditionType === 'sections' || conditionType === 'documents') {
105
- currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, id, index).getData()
106
- }
107
-
108
- const result = LpLogic(condition.conditions, currentData)
109
- this.executeConditionMemo[memoizedKey] = result
110
- return result
111
- }
112
- }
113
-
114
- export default ConditionsRunner
@@ -1,296 +0,0 @@
1
- import { Types } from '@legalplace/referencesparser'
2
- import ConditionsRunner from './ConditionsRunner'
3
-
4
- type OVC_TYPE = {
5
- options: {
6
- [key: string]: boolean[]
7
- }
8
- variables: {
9
- [key: string]: (number | string)[]
10
- }
11
- }
12
-
13
- class DataPopulator {
14
- private references: Types.ReferencesType
15
-
16
- private ovc: OVC_TYPE
17
-
18
- private conditionsRunner: ConditionsRunner
19
-
20
- private id?: number
21
-
22
- private index?: number
23
-
24
- private dataMap: ConditionDataMap
25
-
26
- private data: ConditionData = {
27
- o: {},
28
- v: {},
29
- c: {
30
- o: {},
31
- s: {},
32
- v: {}
33
- }
34
- }
35
-
36
- constructor(conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: OVC_TYPE, dataMap: ConditionDataMap, id?: number, index?: number) {
37
- this.id = id
38
- this.ovc = ovc
39
- this.index = index
40
- this.dataMap = dataMap
41
- this.references = references
42
- this.conditionsRunner = conditionsRunner
43
-
44
- // Populating variables
45
- this.populateVariables()
46
-
47
- // Populating options
48
- this.populateOptions()
49
-
50
- // Populating conditions
51
- this.populateConditions()
52
- }
53
-
54
- /**
55
- * Returns resulting data object
56
- */
57
- public getData(): Readonly<ConditionData> {
58
- return this.data
59
- }
60
-
61
- private populateConditions(): void {
62
- // Sections
63
- for (let i = 0; i < this.dataMap.c.s.length; i += 1) {
64
- const sectionId = this.dataMap.c.s[i]
65
- const sectionCondition = this.sectionConditionValue(sectionId)
66
- this.data.c.s[sectionId] = [sectionCondition !== false]
67
- }
68
-
69
- // Options
70
- for (let i = 0; i < this.dataMap.c.o.length; i += 1) {
71
- const optionId = this.dataMap.c.o[i]
72
- const optionCondition = [...this.getOptionConditions(optionId)]
73
- this.data.c.o[optionId] = optionCondition === undefined ? [false] : optionCondition
74
- }
75
-
76
- // Variables
77
- for (let i = 0; i < this.dataMap.c.v.length; i += 1) {
78
- const variableId = this.dataMap.c.v[i]
79
- const variableCondition = [...this.getVariablesConditions(variableId)]
80
- this.data.c.v[variableId] = variableCondition === undefined ? [false] : variableCondition
81
- }
82
- }
83
-
84
- /**
85
- * Returns a give option's conditions
86
- * @param optionId Option's id
87
- */
88
- private getOptionConditions(optionId: number): Readonly<boolean[]> {
89
- const conditions = this.optionConditionValue(optionId)
90
- if (conditions === undefined) return [true]
91
- if (this.id === undefined || this.index === undefined) {
92
- return conditions
93
- }
94
-
95
- // Getting variable parent option
96
- const optionRootParent = this.getOptionRootParent(optionId)
97
- const optionRootRelations = this.references.relations.options[optionRootParent]
98
- if (optionRootRelations.children.options.includes(this.id) || optionRootRelations.dependants.includes(this.id) || this.id === optionRootParent) {
99
- if (conditions !== undefined && conditions[this.index] === false) return [false]
100
- return [conditions[this.index]]
101
- }
102
-
103
- return conditions
104
- }
105
-
106
- /**
107
- * Returns a give variables conditions
108
- * @param variableId Variable's id
109
- */
110
- private getVariablesConditions(variableId: number): Readonly<boolean[]> {
111
- const conditions = this.variableConditionValue(variableId)
112
- if (conditions === undefined) return [true]
113
- if (this.id === undefined || this.index === undefined) {
114
- return conditions
115
- }
116
-
117
- // Getting variable parent option
118
- const variableRootParent = this.getVariableRootParent(variableId)
119
- const variableRootRelations = this.references.relations.options[variableRootParent]
120
- if (variableRootRelations.children.options.includes(this.id) || variableRootRelations.dependants.includes(this.id) || this.id === variableRootParent) {
121
- return [conditions[this.index]]
122
- }
123
-
124
- return conditions
125
- }
126
-
127
- /**
128
- * Populates variables according to the current dataMap object
129
- */
130
- private populateVariables(): void {
131
- for (let i = 0; i < this.dataMap.v.length; i += 1) {
132
- const variableId = this.dataMap.v[i]
133
- const variableReference = this.references.variables[variableId]
134
- let values = this.getVariableValues(variableId)
135
-
136
- const parseNumber = (v: string) => {
137
- const result = parseFloat(v)
138
- return Number.isNaN(result) ? '' : result
139
- }
140
- // If variable is of type number
141
- if (variableReference.type === 'number') {
142
- values = values.map(v => (typeof v === 'number' ? v : parseNumber(v)))
143
- }
144
-
145
- // Adding variables
146
- this.data.v[variableId] = [...values]
147
- }
148
- }
149
-
150
- /**
151
- * Returns a give variables value
152
- * @param variableId Variable's id
153
- */
154
- private getVariableValues(variableId: number): Readonly<(string | number)[]> {
155
- const value = this.ovc.variables[variableId]
156
- if (this.id === undefined || this.index === undefined) {
157
- return value
158
- }
159
-
160
- // Getting variable parent option
161
- const variableRootParent = this.getVariableRootParent(variableId)
162
- const variableRootRelations = this.references.relations.options[variableRootParent]
163
- if (variableRootRelations.children.options.includes(this.id) || variableRootRelations.dependants.includes(this.id) || this.id === variableRootParent) {
164
- return [value[this.index]]
165
- }
166
-
167
- return this.cleanArrayFromNullValues([...value])
168
- }
169
-
170
- /**
171
- * Return a given variable root option relations
172
- * @param variableId Variable's id
173
- */
174
- private getVariableRootParent(variableId: number) {
175
- const variableParents = this.references.relations.variables[variableId].parents
176
- return variableParents[variableParents.length - 1]
177
- }
178
-
179
- /**
180
- * Cleans values array from any null value by replacing it
181
- * with an empty string
182
- * @param arr Values array
183
- */
184
- private cleanArrayFromNullValues(arr: (string | number | null)[]): (string | number)[] {
185
- return arr.map(v => (v === null ? '' : v))
186
- }
187
-
188
- /**
189
- * Populates options data object accodring to current dataMap object
190
- */
191
- populateOptions() {
192
- for (let i = 0; i < this.dataMap.o.length; i += 1) {
193
- const optionId = this.dataMap.o[i]
194
- const inputs = this.getOptionInputs(optionId)
195
-
196
- // Adding option
197
- this.data.o[optionId] = [...inputs]
198
- }
199
- }
200
-
201
- /**
202
- * Returns a give option's inputs
203
- * @param optionId Option's id
204
- */
205
- private getOptionInputs(optionId: number): Readonly<boolean[]> {
206
- const inputs = this.ovc.options[optionId]
207
- if (this.id === undefined || this.index === undefined) {
208
- return inputs
209
- }
210
-
211
- // Getting variable parent option
212
- const optionRootParent = this.getOptionRootParent(optionId)
213
- const optionRootRelations = this.references.relations.options[optionRootParent]
214
- if (optionRootRelations.children.options.includes(this.id) || optionRootRelations.dependants.includes(this.id) || this.id === optionRootParent) {
215
- return [inputs[this.index]]
216
- }
217
-
218
- return inputs
219
- }
220
-
221
- /**
222
- * Returns option's root parent
223
- * @param optionId Root parent
224
- */
225
- private getOptionRootParent(optionId: number) {
226
- const optionParents = this.references.relations.options[optionId].parents
227
- return optionParents.length > 0 ? optionParents[optionParents.length - 1] : optionId
228
- }
229
-
230
- /**
231
- * Calculates option's condition
232
- */
233
- private optionConditionValue(optionId: number) {
234
- // Getting option conditions
235
- const conditions = this.references.conditions.options[optionId]
236
- if (conditions === undefined) return undefined
237
-
238
- // Getting option inputs length
239
- const inputs = this.ovc.options[optionId]
240
-
241
- return inputs.map((input, index) => {
242
- return this.conditionsRunner.executeCondition(conditions, optionId, index, 'options')
243
- })
244
- }
245
-
246
- /**
247
- * Calculates variable's condition
248
- */
249
- private variableConditionValue(variableId: number) {
250
- // Getting variable conditions
251
- const conditions = this.references.conditions.variables[variableId]
252
- if (conditions === undefined) return undefined
253
-
254
- // Getting variable inputs length
255
- const inputs = this.ovc.variables[variableId]
256
-
257
- const result = inputs.map((input, index) => {
258
- return this.conditionsRunner.executeCondition(conditions, variableId, index, 'variables')
259
- })
260
-
261
- return result
262
- }
263
-
264
- /**
265
- * Calculates section's condition
266
- */
267
- private sectionConditionValue(sectionId: number) {
268
- // Getting section conditions
269
- const conditions = this.references.conditions.sections.main[sectionId]
270
- if (conditions === undefined) return undefined
271
-
272
- return this.conditionsRunner.executeCondition(conditions, 0, 0, 'sections')
273
- }
274
- }
275
-
276
- export interface ConditionDataMap {
277
- o: number[]
278
- v: number[]
279
- c: {
280
- o: number[]
281
- s: number[]
282
- v: number[]
283
- }
284
- }
285
-
286
- export interface ConditionData {
287
- o: Record<string, boolean[]>
288
- v: Record<string, (string | number)[]>
289
- c: {
290
- o: Record<string, boolean[]>
291
- s: Record<string, boolean[]>
292
- v: Record<string, boolean[]>
293
- }
294
- }
295
-
296
- export default DataPopulator
@@ -1,218 +0,0 @@
1
- import { OptionV3 } from '@legalplace/models-v3-types'
2
- import { Types } from '@legalplace/referencesparser'
3
- import InputsType from '../types/inputs.type'
4
- import OvcType from '../types/ovc.type'
5
-
6
- class OvcConverter {
7
- public convertToOptionsVariables(ovc: OvcType, references: Types.ReferencesType) {
8
- const inputs: InputsType = {
9
- options: {},
10
- variables: {}
11
- }
12
-
13
- if (typeof ovc !== 'object') return inputs
14
-
15
- // Reading options
16
- if (typeof ovc.o === 'object') {
17
- Object.keys(ovc.o).forEach(id => {
18
- const currentOption = ovc.o[id]
19
-
20
- // If it's a multiple
21
- if (Array.isArray(currentOption)) {
22
- const occurences = currentOption.length
23
- // Adding static childrens
24
- inputs.options = {
25
- ...inputs.options,
26
- ...this.pushStaticChildren(inputs.options, id, occurences, references)
27
- }
28
- currentOption.forEach((childId, index) => {
29
- const sanitizedId = typeof childId === 'string' && childId.split('_').length > 0 ? childId.split('_')[0] : childId
30
-
31
- // Making sure the input exist
32
- if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
33
- const defaultValue = references.options[id].meta.type === 'static'
34
- inputs.options[id] = new Array(occurences).fill(defaultValue)
35
- }
36
-
37
- // Making sure the childId is not empty
38
- if (typeof sanitizedId === 'string' && sanitizedId.trim().length === 0) {
39
- return
40
- }
41
-
42
- // Creating input if it doesn't exist
43
- if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
44
- const defaultValue = references.options[sanitizedId].meta.type === 'static'
45
- inputs.options[sanitizedId] = new Array(occurences).fill(defaultValue)
46
- }
47
-
48
- // Adding static childrens
49
- inputs.options = {
50
- ...inputs.options,
51
- ...this.pushStaticChildren(inputs.options, sanitizedId, occurences, references)
52
- }
53
-
54
- // Setting current index to true
55
- inputs.options[sanitizedId][index] = true
56
- })
57
- } else {
58
- if (typeof currentOption === 'string' && currentOption.trim().length === 0) return
59
- inputs.options[currentOption] = [true]
60
- }
61
- })
62
- }
63
-
64
- // Adding static root options
65
- Object.keys(references.options).forEach(optionId => {
66
- const option = references.options[optionId]
67
- const { parents } = references.relations.options[optionId]
68
-
69
- if (inputs.options[optionId] === undefined && parents.length === 0 && option.meta.type === 'static') {
70
- inputs.options[optionId] = [true]
71
- }
72
- })
73
-
74
- // Reading checkboxes
75
- if (typeof ovc.c === 'object') {
76
- Object.keys(ovc.c).forEach(id => {
77
- const currentCheckbox = ovc.c[id]
78
- if (typeof id === 'string' && id.trim().length === 0) return
79
- // If it's a multiple
80
- if (Array.isArray(currentCheckbox)) {
81
- inputs.options[id] = currentCheckbox
82
- } else {
83
- inputs.options[id] = [currentCheckbox]
84
- }
85
- })
86
- }
87
-
88
- // Reading variables
89
- if (typeof ovc.v === 'object') {
90
- Object.keys(ovc.v).forEach(id => {
91
- const currentVariable = ovc.v[id]
92
-
93
- // If it's a multiple
94
- if (Array.isArray(currentVariable)) {
95
- inputs.variables[id] = currentVariable
96
- // Getting parentsTree & parent id
97
- const parentsTree = references.relations.variables[id].parents
98
- const parentOption = inputs.options[`${parentsTree[parentsTree.length - 1]}`]
99
- if (Array.isArray(parentOption)) {
100
- const occurences = parentOption.length
101
- if (currentVariable.length < occurences) {
102
- inputs.variables[id] = [...currentVariable, ...Array(occurences - currentVariable.length).fill('')]
103
- }
104
- }
105
- } else {
106
- inputs.variables[id] = [currentVariable]
107
- }
108
- })
109
- }
110
-
111
- // Pushing left over and returning inputs
112
- return this.pushLeftOver(inputs, references)
113
- }
114
-
115
- public isOvc(_obj: InputsType | OvcType): _obj is OvcType {
116
- if (typeof _obj !== 'object' || _obj === null) return false
117
- const ovcKeys = ['o', 'v', 'c']
118
- const foundKeys = Object.keys(_obj)
119
- .map((key): number => (ovcKeys.includes(key) ? 1 : 0))
120
- .reduce((a, b) => a + b, 0)
121
-
122
- return foundKeys > 1
123
- }
124
-
125
- public isOptionsVariables(_obj: InputsType | OvcType): _obj is InputsType {
126
- if (typeof _obj !== 'object' || _obj === null) return false
127
- const optionsVariablesKeys = ['options', 'variables']
128
- const foundKeys = Object.keys(_obj)
129
- .map((key): number => (optionsVariablesKeys.includes(key) ? 1 : 0))
130
- .reduce((a, b) => a + b, 0)
131
- return foundKeys === 2
132
- }
133
-
134
- private pushStaticChildren(inputOptions: InputsType['options'], id: number | string, occurences: number, references: Types.ReferencesType) {
135
- const result = { ...inputOptions }
136
- const intId = typeof id === 'number' ? id : parseInt(id, 10)
137
-
138
- // Getting children options and variables
139
- const { options } = references.relations.options[intId].children
140
-
141
- // Getting static children
142
- const staticOptions = options.filter(childId => {
143
- return references.options[childId].meta.type === 'static'
144
- })
145
-
146
- staticOptions.forEach(childId => {
147
- // Creating input if it doesn't exist
148
- if (!Object.prototype.hasOwnProperty.call(result, childId)) {
149
- result[childId] = new Array(occurences).fill(true)
150
- }
151
- })
152
-
153
- return result
154
- }
155
-
156
- private pushLeftOver(inputs: InputsType, references: Types.ReferencesType): InputsType {
157
- let result = {
158
- ...inputs
159
- }
160
-
161
- Object.values(references.sections).forEach(document => {
162
- Object.values(document).forEach(section => {
163
- section.options.forEach(optionId => {
164
- const occurences = inputs.options[optionId] === undefined ? 1 : inputs.options[optionId].length
165
- result = this.pushLeftOverOption(result, references, references.options[optionId], occurences)
166
- })
167
- })
168
- })
169
-
170
- return result
171
- }
172
-
173
- private pushLeftOverOption(inputs: InputsType, references: Types.ReferencesType, option: OptionV3, occurences: number): InputsType {
174
- let result = {
175
- ...inputs
176
- }
177
-
178
- const defaultValue = !['radio', 'checkbox'].includes(option.meta.type)
179
-
180
- // Adding option if it doesn't exist
181
- if (!Object.prototype.hasOwnProperty.call(result.options, option.meta.id)) {
182
- result = {
183
- ...result,
184
- options: {
185
- ...result.options,
186
- [option.meta.id]: new Array(occurences).fill(defaultValue)
187
- }
188
- }
189
- }
190
-
191
- // Reading option's children
192
- option.options.forEach(optionId => {
193
- result = this.pushLeftOverOption(result, references, references.options[optionId], occurences)
194
- })
195
-
196
- // Reading option variables
197
- option.variables.forEach(variableId => {
198
- result = this.pushLeftOverVariable(result, variableId, occurences)
199
- })
200
-
201
- return result
202
- }
203
-
204
- private pushLeftOverVariable(inputs: InputsType, id: number, occurences: number): InputsType {
205
- if (!Object.prototype.hasOwnProperty.call(inputs.variables, id)) {
206
- return {
207
- ...inputs,
208
- variables: {
209
- ...inputs.variables,
210
- [id]: new Array(occurences).fill('')
211
- }
212
- }
213
- }
214
- return inputs
215
- }
216
- }
217
-
218
- export default new OvcConverter()
@@ -1,10 +0,0 @@
1
- type InputsType = {
2
- options: {
3
- [key: string]: boolean[]
4
- }
5
- variables: {
6
- [key: string]: (number | string)[]
7
- }
8
- }
9
-
10
- export default InputsType
@@ -1,13 +0,0 @@
1
- interface OvcType {
2
- o: {
3
- [k: string]: string | number | (string | number)[]
4
- }
5
- v: {
6
- [k: string]: string | number | (string | number)[]
7
- }
8
- c: {
9
- [k: string]: boolean | boolean[]
10
- }
11
- }
12
-
13
- export default OvcType