@legalplace/tagextractor 2.0.0 → 2.2.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.
- package/.eslintignore +2 -0
- package/.eslintrc +2 -58
- package/.gitlab-ci.yml +7 -6
- package/.vscode/settings.json +25 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/libs/Extractor.d.ts +5 -5
- package/dist/libs/Extractor.js +101 -95
- package/dist/libs/Extractor.test.d.ts +1 -0
- package/dist/libs/Extractor.test.js +278 -0
- package/dist/libs/fixtures/inputs.json +60 -0
- package/dist/libs/fixtures/model.json +291 -0
- package/dist/libs/fixtures/ovc.json +15 -0
- package/dist/libs/fixtures/references.json +946 -0
- package/jest.config.ts +205 -0
- package/package.json +25 -23
- package/setupJest.ts +7 -0
- package/src/index.ts +1 -1
- package/src/libs/Extractor.test.ts +360 -0
- package/src/libs/Extractor.ts +120 -63
- package/src/libs/fixtures/inputs.json +60 -0
- package/src/libs/fixtures/model.json +291 -0
- package/src/libs/fixtures/ovc.json +15 -0
- package/src/libs/fixtures/references.json +946 -0
- package/tsconfig.json +19 -7
- package/.prettierrc.js +0 -10
- package/tsconfig.eslint.json +0 -12
package/.eslintignore
ADDED
package/.eslintrc
CHANGED
|
@@ -1,59 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
"commonjs": true,
|
|
5
|
-
"es6": true,
|
|
6
|
-
"jest": true,
|
|
7
|
-
"node": true
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
"extends": [
|
|
11
|
-
"airbnb-base",
|
|
12
|
-
"plugin:prettier/recommended"
|
|
13
|
-
],
|
|
14
|
-
|
|
15
|
-
"parser": "@typescript-eslint/parser",
|
|
16
|
-
"parserOptions": {
|
|
17
|
-
"project": "./tsconfig.eslint.json"
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
"plugins": [
|
|
21
|
-
"prettier", "@typescript-eslint"
|
|
22
|
-
],
|
|
23
|
-
|
|
24
|
-
"rules": {
|
|
25
|
-
"prettier/prettier": ["error"],
|
|
26
|
-
"no-unused-vars": "off",
|
|
27
|
-
"@typescript-eslint/no-unused-vars": ["error", {
|
|
28
|
-
"vars": "all",
|
|
29
|
-
"args": "after-used",
|
|
30
|
-
"ignoreRestSiblings": false
|
|
31
|
-
}],
|
|
32
|
-
"import/no-extraneous-dependencies": ["error", {
|
|
33
|
-
"devDependencies": true
|
|
34
|
-
}],
|
|
35
|
-
"no-continue": 0,
|
|
36
|
-
"class-methods-use-this": 0,
|
|
37
|
-
"no-underscore-dangle": 0,
|
|
38
|
-
"import/prefer-default-export": "warn",
|
|
39
|
-
"camelcase": "error",
|
|
40
|
-
"no-undef": 0,
|
|
41
|
-
"no-dupe-class-members": "off",
|
|
42
|
-
"import/extensions": ["error", "ignorePackages", {
|
|
43
|
-
"js": "never",
|
|
44
|
-
"jsx": "never",
|
|
45
|
-
"ts": "never",
|
|
46
|
-
"tsx": "never",
|
|
47
|
-
"mjs": "never"
|
|
48
|
-
}]
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"settings": {
|
|
53
|
-
"import/resolver": {
|
|
54
|
-
"node": {
|
|
55
|
-
"extensions": [".js", ".jsx", ".ts", ".tsx"]
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
2
|
+
"extends": ["@legalplace/eslint-config"]
|
|
3
|
+
}
|
package/.gitlab-ci.yml
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
image: 148253454541.dkr.ecr.eu-west-1.amazonaws.com/
|
|
2
|
-
|
|
1
|
+
image: 148253454541.dkr.ecr.eu-west-1.amazonaws.com/deploydock:node14
|
|
3
2
|
|
|
4
3
|
stages:
|
|
5
4
|
- setup
|
|
6
5
|
- publish
|
|
7
6
|
|
|
8
7
|
before_script:
|
|
9
|
-
- export PATH=$PATH:./node_modules/.bin/
|
|
8
|
+
- export PATH=$PATH:./node_modules/.bin/
|
|
10
9
|
|
|
11
10
|
variables:
|
|
12
11
|
DOCKER_DRIVER: overlay2
|
|
@@ -15,13 +14,14 @@ setup:
|
|
|
15
14
|
stage: setup
|
|
16
15
|
artifacts:
|
|
17
16
|
paths:
|
|
18
|
-
|
|
17
|
+
- dist/
|
|
19
18
|
only:
|
|
20
19
|
changes:
|
|
21
20
|
- yarn.lock
|
|
22
21
|
- package.json
|
|
23
22
|
- .gitlab-ci.yml
|
|
24
23
|
script:
|
|
24
|
+
- echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
|
|
25
25
|
- yarn -v
|
|
26
26
|
- node -v
|
|
27
27
|
- yarn install --frozen-lockfile --check-files --silent
|
|
@@ -33,11 +33,12 @@ publish:
|
|
|
33
33
|
variables:
|
|
34
34
|
- $CI_COMMIT_MESSAGE =~ /skip-publish/
|
|
35
35
|
script:
|
|
36
|
+
- echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
|
|
36
37
|
- npm publish
|
|
37
38
|
environment:
|
|
38
39
|
name: development
|
|
39
40
|
only:
|
|
40
41
|
refs:
|
|
41
|
-
|
|
42
|
+
- master
|
|
42
43
|
changes:
|
|
43
|
-
|
|
44
|
+
- package.json
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"eslint.enable": true,
|
|
3
|
+
"editor.tabSize": 2,
|
|
4
|
+
"eslint.validate": [
|
|
5
|
+
"javascript",
|
|
6
|
+
"javascriptreact",
|
|
7
|
+
"typescript",
|
|
8
|
+
"typescriptreact"
|
|
9
|
+
],
|
|
10
|
+
"eslint.options": {
|
|
11
|
+
"extensions": [".ts", ".tsx", ".js", ".jsx"]
|
|
12
|
+
},
|
|
13
|
+
"files.autoSave": "onFocusChange",
|
|
14
|
+
"editor.formatOnSave": true,
|
|
15
|
+
"editor.formatOnType": true,
|
|
16
|
+
"prettier.singleQuote": true,
|
|
17
|
+
"eslint.packageManager": "yarn",
|
|
18
|
+
"eslint.quiet": true,
|
|
19
|
+
"editor.codeActionsOnSave": {
|
|
20
|
+
"source.fixAll.eslint": true
|
|
21
|
+
},
|
|
22
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
23
|
+
"editor.formatOnPaste": true,
|
|
24
|
+
"files.insertFinalNewline": true
|
|
25
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,5 +3,5 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const Extractor_1 = __importDefault(require("./libs/Extractor"));
|
|
7
7
|
exports.default = Extractor_1.default;
|
package/dist/libs/Extractor.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ModelV3 } from
|
|
2
|
-
import { ReferencesType } from
|
|
3
|
-
import InputsType from
|
|
4
|
-
import OvcType from
|
|
5
|
-
import TagsType from
|
|
1
|
+
import { ModelV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import { ReferencesType } from "@legalplace/referencesparser/dist/libs/References.type";
|
|
3
|
+
import InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import OvcType from "@legalplace/types/dist/ovc";
|
|
5
|
+
import TagsType from "../types/tags.type";
|
|
6
6
|
declare class TagExtractor {
|
|
7
7
|
private references;
|
|
8
8
|
private inputs;
|
package/dist/libs/Extractor.js
CHANGED
|
@@ -1,129 +1,135 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
4
|
};
|
|
12
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const referencesparser_1 = require("@legalplace/referencesparser");
|
|
7
|
+
const conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
|
|
8
|
+
const ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
|
|
9
|
+
class TagExtractor {
|
|
10
|
+
constructor(modelOrReferences, ovc) {
|
|
18
11
|
this.tags = {
|
|
19
12
|
options: {},
|
|
20
13
|
variables: {}
|
|
21
14
|
};
|
|
22
|
-
this.isReferencesType =
|
|
23
|
-
return Object.keys(_obj).some(
|
|
15
|
+
this.isReferencesType = (_obj) => {
|
|
16
|
+
return Object.keys(_obj).some(key => key === "boxes");
|
|
24
17
|
};
|
|
25
|
-
this.references = this.isReferencesType(modelOrReferences)
|
|
26
|
-
|
|
18
|
+
this.references = this.isReferencesType(modelOrReferences)
|
|
19
|
+
? modelOrReferences
|
|
20
|
+
: new referencesparser_1.ReferencesParser(modelOrReferences).references;
|
|
21
|
+
this.inputs = ovc_converter_1.default.isOptionsVariables(ovc)
|
|
22
|
+
? ovc
|
|
23
|
+
: ovc_converter_1.default.convertToOptionsVariables(ovc, this.references);
|
|
27
24
|
this.conditionsRunner = new conditions_runner_1.default(this.references, this.inputs);
|
|
28
25
|
this.extractFromOptions();
|
|
29
26
|
this.extractFromVariables();
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_this.inputs.options[id].forEach(function (v, index) {
|
|
44
|
-
tags.forEach(function (tag) {
|
|
45
|
-
if (_this.tags.options[tag] === undefined)
|
|
46
|
-
_this.tags.options[tag] = [];
|
|
47
|
-
_this.tags.options[tag].push({
|
|
28
|
+
get getTags() {
|
|
29
|
+
return this.tags;
|
|
30
|
+
}
|
|
31
|
+
extractFromOptions() {
|
|
32
|
+
Object.keys(this.references.options).forEach(id => {
|
|
33
|
+
const { tags, label } = this.references.options[id].meta;
|
|
34
|
+
if (Array.isArray(tags) && tags.length > 0 && this.inputs.options[id]) {
|
|
35
|
+
this.inputs.options[id].forEach((v, index) => {
|
|
36
|
+
tags.forEach(tag => {
|
|
37
|
+
if (this.tags.options[tag] === undefined)
|
|
38
|
+
this.tags.options[tag] = [];
|
|
39
|
+
this.tags.options[tag].push({
|
|
48
40
|
id: parseInt(id, 10),
|
|
49
|
-
index
|
|
50
|
-
label
|
|
51
|
-
condition:
|
|
52
|
-
visible:
|
|
53
|
-
value:
|
|
41
|
+
index,
|
|
42
|
+
label,
|
|
43
|
+
condition: this.getOptionCondition(parseInt(id, 10), index),
|
|
44
|
+
visible: this.isOptionDisplayed(parseInt(id, 10), index),
|
|
45
|
+
value: this.inputs.options[id][index]
|
|
54
46
|
});
|
|
55
47
|
});
|
|
56
48
|
});
|
|
57
49
|
}
|
|
58
50
|
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
_this.tags.variables[tag].push({
|
|
51
|
+
}
|
|
52
|
+
extractFromVariables() {
|
|
53
|
+
Object.keys(this.references.variables).forEach(id => {
|
|
54
|
+
const { tags, label } = this.references.variables[id];
|
|
55
|
+
if (Array.isArray(tags) && tags.length > 0 && this.inputs.variables[id]) {
|
|
56
|
+
this.inputs.variables[id].forEach((v, index) => {
|
|
57
|
+
tags.forEach(tag => {
|
|
58
|
+
if (this.tags.variables[tag] === undefined)
|
|
59
|
+
this.tags.variables[tag] = [];
|
|
60
|
+
this.tags.variables[tag].push({
|
|
70
61
|
id: parseInt(id, 10),
|
|
71
|
-
index
|
|
72
|
-
label
|
|
73
|
-
condition:
|
|
74
|
-
visible:
|
|
75
|
-
value:
|
|
62
|
+
index,
|
|
63
|
+
label,
|
|
64
|
+
condition: this.getVariableCondition(parseInt(id, 10), index) !== false,
|
|
65
|
+
visible: this.isVariableDisplayed(parseInt(id, 10), index),
|
|
66
|
+
value: this.inputs.variables[id][index]
|
|
76
67
|
});
|
|
77
68
|
});
|
|
78
69
|
});
|
|
79
70
|
}
|
|
80
71
|
});
|
|
81
|
-
}
|
|
82
|
-
|
|
72
|
+
}
|
|
73
|
+
isVariableDisplayed(id, index) {
|
|
83
74
|
var _a, _b;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return [
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
const variableCondition = this.getVariableCondition(id, index);
|
|
76
|
+
const variableParents = ((_a = this.references.relations.variables[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
77
|
+
const parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index);
|
|
78
|
+
const parentOptionIsTruethful = ((_b = this.inputs.options[variableParents[0]]) === null || _b === void 0 ? void 0 : _b[index]) === true;
|
|
79
|
+
return ([
|
|
80
|
+
variableCondition,
|
|
81
|
+
parentOptionIsDisplayed,
|
|
82
|
+
parentOptionIsTruethful
|
|
83
|
+
].filter(c => c !== true).length === 0);
|
|
84
|
+
}
|
|
85
|
+
isOptionDisplayed(id, index) {
|
|
92
86
|
var _a;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return
|
|
87
|
+
const optionCondition = this.getOptionCondition(id, index);
|
|
88
|
+
const optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
|
|
89
|
+
const parentsConditions = optionParents.map(optionId => {
|
|
90
|
+
return this.getOptionCondition(optionId, index) !== false;
|
|
97
91
|
});
|
|
98
|
-
|
|
99
|
-
return
|
|
92
|
+
const parentsInputs = optionParents.map(optionId => {
|
|
93
|
+
return this.inputs.options[optionId]
|
|
94
|
+
? this.inputs.options[optionId][index]
|
|
95
|
+
: false;
|
|
100
96
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
97
|
+
const parentSectionId = this.getOptionParentSection(id);
|
|
98
|
+
const parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
|
|
99
|
+
return ([
|
|
100
|
+
optionCondition,
|
|
101
|
+
parentSectionCondition,
|
|
102
|
+
...parentsConditions,
|
|
103
|
+
...parentsInputs
|
|
104
|
+
].filter(c => c !== true).length === 0);
|
|
105
|
+
}
|
|
106
|
+
getVariableCondition(id, index) {
|
|
107
|
+
const conditionObject = this.references.conditions.variables[id];
|
|
108
|
+
return conditionObject === undefined
|
|
109
|
+
? true
|
|
110
|
+
: this.conditionsRunner.executeCondition(conditionObject, id, index, "variables");
|
|
111
|
+
}
|
|
112
|
+
getOptionCondition(id, index) {
|
|
113
|
+
const conditionObject = this.references.conditions.options[id];
|
|
114
|
+
return conditionObject === undefined
|
|
115
|
+
? true
|
|
116
|
+
: this.conditionsRunner.executeCondition(conditionObject, id, index, "options");
|
|
117
|
+
}
|
|
118
|
+
getSectionCondition(id) {
|
|
119
|
+
const conditionObject = this.references.conditions.sections.main[id];
|
|
120
|
+
return conditionObject === undefined
|
|
121
|
+
? true
|
|
122
|
+
: this.conditionsRunner.executeCondition(conditionObject, id, 0, "sections");
|
|
123
|
+
}
|
|
124
|
+
getOptionParentSection(id) {
|
|
125
|
+
const { parents } = this.references.relations.options[id];
|
|
126
|
+
const rootId = parents.length > 0 ? parents[parents.length - 1] : id;
|
|
127
|
+
const sections = Object.values(this.references.sections.main);
|
|
128
|
+
for (let i = 0; i < sections.length; i += 1) {
|
|
122
129
|
if (sections[i].options.includes(rootId))
|
|
123
130
|
return sections[i].id;
|
|
124
131
|
}
|
|
125
|
-
throw new Error(
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}());
|
|
132
|
+
throw new Error(`Cannot find parent section for option ${id} (Root option id: ${rootId})`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
129
135
|
exports.default = TagExtractor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|