@legalplace/tagextractor 2.1.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 ADDED
@@ -0,0 +1,2 @@
1
+ *.test.ts
2
+ *.test.tsx
package/.eslintrc CHANGED
@@ -1,59 +1,3 @@
1
1
  {
2
- "env": {
3
- "browser": true,
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/legalplace:latest
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
- - dist/
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
- - master
42
+ - master
42
43
  changes:
43
- - package.json
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
@@ -1,4 +1,4 @@
1
1
  import TagExtractor from './libs/Extractor';
2
2
  import TagsType, { OptionTagType, VariableTagType } from './types/tags.type';
3
- export { TagsType, OptionTagType, VariableTagType };
3
+ export type { TagsType, OptionTagType, VariableTagType };
4
4
  export default TagExtractor;
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
- var Extractor_1 = __importDefault(require("./libs/Extractor"));
6
+ const Extractor_1 = __importDefault(require("./libs/Extractor"));
7
7
  exports.default = Extractor_1.default;
@@ -1,8 +1,8 @@
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';
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;
@@ -1,130 +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
- var referencesparser_1 = require("@legalplace/referencesparser");
14
- var conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
15
- var ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
16
- var TagExtractor = (function () {
17
- function TagExtractor(modelOrReferences, ovc) {
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 = function (_obj) {
23
- return Object.keys(_obj).some(function (key) { return key === 'boxes'; });
15
+ this.isReferencesType = (_obj) => {
16
+ return Object.keys(_obj).some(key => key === "boxes");
24
17
  };
25
- this.references = this.isReferencesType(modelOrReferences) ? modelOrReferences : new referencesparser_1.ReferencesParser(modelOrReferences).references;
26
- this.inputs = ovc_converter_1.default.isOptionsVariables(ovc) ? ovc : ovc_converter_1.default.convertToOptionsVariables(ovc, this.references);
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
- Object.defineProperty(TagExtractor.prototype, "getTags", {
32
- get: function () {
33
- return this.tags;
34
- },
35
- enumerable: false,
36
- configurable: true
37
- });
38
- TagExtractor.prototype.extractFromOptions = function () {
39
- var _this = this;
40
- Object.keys(this.references.options).forEach(function (id) {
41
- var _a = _this.references.options[id].meta, tags = _a.tags, label = _a.label;
42
- if (Array.isArray(tags) && tags.length > 0 && _this.inputs.options[id]) {
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: index,
50
- label: label,
51
- condition: _this.getOptionCondition(parseInt(id, 10), index),
52
- visible: _this.isOptionDisplayed(parseInt(id, 10), index),
53
- value: _this.inputs.options[id][index]
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
- TagExtractor.prototype.extractFromVariables = function () {
61
- var _this = this;
62
- Object.keys(this.references.variables).forEach(function (id) {
63
- var _a = _this.references.variables[id], tags = _a.tags, label = _a.label;
64
- if (Array.isArray(tags) && tags.length > 0 && _this.inputs.variables[id]) {
65
- _this.inputs.variables[id].forEach(function (v, index) {
66
- tags.forEach(function (tag) {
67
- if (_this.tags.variables[tag] === undefined)
68
- _this.tags.variables[tag] = [];
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: index,
72
- label: label,
73
- condition: _this.getVariableCondition(parseInt(id, 10), index) !== false,
74
- visible: _this.isVariableDisplayed(parseInt(id, 10), index),
75
- value: _this.inputs.variables[id][index]
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
- TagExtractor.prototype.isVariableDisplayed = function (id, index) {
72
+ }
73
+ isVariableDisplayed(id, index) {
83
74
  var _a, _b;
84
- var variableCondition = this.getVariableCondition(id, index);
85
- var variableParents = ((_a = this.references.relations.variables[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
86
- var parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index);
87
- var parentOptionIsTruethful = ((_b = this.inputs.options[variableParents[0]]) === null || _b === void 0 ? void 0 : _b[index]) === true;
88
- return [variableCondition, parentOptionIsDisplayed, parentOptionIsTruethful].filter(function (c) { return c !== true; }).length === 0;
89
- };
90
- TagExtractor.prototype.isOptionDisplayed = function (id, index) {
91
- var _this = this;
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
- var optionCondition = this.getOptionCondition(id, index);
94
- var optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
95
- var parentsConditions = optionParents.map(function (optionId) {
96
- return _this.getOptionCondition(optionId, index) !== false;
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
- var parentsInputs = optionParents.map(function (optionId) {
99
- var _a;
100
- return ((_a = _this.inputs.options[optionId]) === null || _a === void 0 ? void 0 : _a[index]) || false;
92
+ const parentsInputs = optionParents.map(optionId => {
93
+ return this.inputs.options[optionId]
94
+ ? this.inputs.options[optionId][index]
95
+ : false;
101
96
  });
102
- var parentSectionId = this.getOptionParentSection(id);
103
- var parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
104
- return __spreadArrays([optionCondition, parentSectionCondition], parentsConditions, parentsInputs).filter(function (c) { return c !== true; }).length === 0;
105
- };
106
- TagExtractor.prototype.getVariableCondition = function (id, index) {
107
- var conditionObject = this.references.conditions.variables[id];
108
- return conditionObject === undefined ? true : this.conditionsRunner.executeCondition(conditionObject, id, index, 'variables');
109
- };
110
- TagExtractor.prototype.getOptionCondition = function (id, index) {
111
- var conditionObject = this.references.conditions.options[id];
112
- return conditionObject === undefined ? true : this.conditionsRunner.executeCondition(conditionObject, id, index, 'options');
113
- };
114
- TagExtractor.prototype.getSectionCondition = function (id) {
115
- var conditionObject = this.references.conditions.sections.main[id];
116
- return conditionObject === undefined ? true : this.conditionsRunner.executeCondition(conditionObject, id, 0, 'sections');
117
- };
118
- TagExtractor.prototype.getOptionParentSection = function (id) {
119
- var parents = this.references.relations.options[id].parents;
120
- var rootId = parents.length > 0 ? parents[parents.length - 1] : id;
121
- var sections = Object.values(this.references.sections.main);
122
- for (var i = 0; i < sections.length; i += 1) {
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) {
123
129
  if (sections[i].options.includes(rootId))
124
130
  return sections[i].id;
125
131
  }
126
- throw new Error("Cannot find parent section for option " + id + " (Root option id: " + rootId + ")");
127
- };
128
- return TagExtractor;
129
- }());
132
+ throw new Error(`Cannot find parent section for option ${id} (Root option id: ${rootId})`);
133
+ }
134
+ }
130
135
  exports.default = TagExtractor;
@@ -0,0 +1 @@
1
+ export {};