@legalplace/tagextractor 1.3.0-alpha → 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-alpha",
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",
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",
19
21
  "@legalplace/referencesparser": "1.6.3",
20
- "crypto": "^1.0.1",
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();