@legalplace/tagextractor 1.1.7 → 1.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.
@@ -1,4 +1,5 @@
1
1
  import { ModelV3 } from '@legalplace/models-v3-types';
2
+ import { ReferencesType } from '@legalplace/referencesparser/dist/libs/References.type';
2
3
  import InputsType from '../types/inputs.type';
3
4
  import OvcType from '../types/ovc.type';
4
5
  import TagsType from '../types/tags.type';
@@ -7,7 +8,8 @@ declare class TagExtractor {
7
8
  private inputs;
8
9
  private conditionsRunner;
9
10
  private tags;
10
- constructor(model: ModelV3, ovc: OvcType | InputsType);
11
+ private isReferencesType;
12
+ constructor(modelOrReferences: ModelV3 | ReferencesType, ovc: OvcType | InputsType);
11
13
  get getTags(): TagsType;
12
14
  private extractFromOptions;
13
15
  private extractFromVariables;
@@ -14,12 +14,15 @@ var referencesparser_1 = require("@legalplace/referencesparser");
14
14
  var ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
15
15
  var OvcConverter_1 = __importDefault(require("./OvcConverter"));
16
16
  var TagExtractor = (function () {
17
- function TagExtractor(model, ovc) {
17
+ function TagExtractor(modelOrReferences, ovc) {
18
18
  this.tags = {
19
19
  options: {},
20
20
  variables: {}
21
21
  };
22
- this.references = new referencesparser_1.ReferencesParser(model).references;
22
+ this.isReferencesType = function (_obj) {
23
+ return Object.keys(_obj).some(function (key) { return key === 'boxes'; });
24
+ };
25
+ this.references = this.isReferencesType(modelOrReferences) ? modelOrReferences : new referencesparser_1.ReferencesParser(modelOrReferences).references;
23
26
  this.inputs = OvcConverter_1.default.isOptionsVariables(ovc) ? ovc : OvcConverter_1.default.convertToOptionsVariables(ovc, this.references);
24
27
  this.conditionsRunner = new ConditionsRunner_1.default(this.references, this.inputs);
25
28
  this.extractFromOptions();
@@ -36,7 +39,7 @@ var TagExtractor = (function () {
36
39
  var _this = this;
37
40
  Object.keys(this.references.options).forEach(function (id) {
38
41
  var _a = _this.references.options[id].meta, tags = _a.tags, label = _a.label;
39
- if (Array.isArray(tags) && tags.length > 0) {
42
+ if (Array.isArray(tags) && tags.length > 0 && _this.inputs.options[id]) {
40
43
  _this.inputs.options[id].forEach(function (v, index) {
41
44
  tags.forEach(function (tag) {
42
45
  if (_this.tags.options[tag] === undefined)
@@ -58,7 +61,7 @@ var TagExtractor = (function () {
58
61
  var _this = this;
59
62
  Object.keys(this.references.variables).forEach(function (id) {
60
63
  var _a = _this.references.variables[id], tags = _a.tags, label = _a.label;
61
- if (Array.isArray(tags) && tags.length > 0) {
64
+ if (Array.isArray(tags) && tags.length > 0 && _this.inputs.variables[id]) {
62
65
  _this.inputs.variables[id].forEach(function (v, index) {
63
66
  tags.forEach(function (tag) {
64
67
  if (_this.tags.variables[tag] === undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/tagextractor",
3
- "version": "1.1.7",
3
+ "version": "1.2.0",
4
4
  "description": "TagExtractor",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/tagextractor",
@@ -38,4 +38,4 @@
38
38
  "redux-mock-store": "^1.5.3",
39
39
  "ts-jest": "^24.0.2"
40
40
  }
41
- }
41
+ }
@@ -1,5 +1,6 @@
1
1
  import { ModelV3 } from '@legalplace/models-v3-types'
2
2
  import { ReferencesParser, Types } from '@legalplace/referencesparser'
3
+ import { ReferencesType } from '@legalplace/referencesparser/dist/libs/References.type'
3
4
  import InputsType from '../types/inputs.type'
4
5
  import OvcType from '../types/ovc.type'
5
6
  import TagsType from '../types/tags.type'
@@ -18,9 +19,13 @@ class TagExtractor {
18
19
  variables: {}
19
20
  }
20
21
 
21
- constructor(model: ModelV3, ovc: OvcType | InputsType) {
22
- // Parsing references
23
- this.references = new ReferencesParser(model).references
22
+ private isReferencesType = (_obj: ModelV3 | ReferencesType): _obj is ReferencesType => {
23
+ // We check if the object contains one of the fields only contained in ReferencesType
24
+ return Object.keys(_obj).some(key => key === 'boxes')
25
+ }
26
+
27
+ constructor(modelOrReferences: ModelV3 | ReferencesType, ovc: OvcType | InputsType) {
28
+ this.references = this.isReferencesType(modelOrReferences) ? modelOrReferences : new ReferencesParser(modelOrReferences).references
24
29
 
25
30
  // Converting inputs if needed
26
31
  this.inputs = OvcConverter.isOptionsVariables(ovc) ? ovc : OvcConverter.convertToOptionsVariables(ovc, this.references)
@@ -46,7 +51,7 @@ class TagExtractor {
46
51
  Object.keys(this.references.options).forEach(id => {
47
52
  const { tags, label } = this.references.options[id].meta
48
53
 
49
- if (Array.isArray(tags) && tags.length > 0) {
54
+ if (Array.isArray(tags) && tags.length > 0 && this.inputs.options[id]) {
50
55
  this.inputs.options[id].forEach((v, index) => {
51
56
  tags.forEach(tag => {
52
57
  if (this.tags.options[tag] === undefined) this.tags.options[tag] = []
@@ -71,7 +76,7 @@ class TagExtractor {
71
76
  Object.keys(this.references.variables).forEach(id => {
72
77
  const { tags, label } = this.references.variables[id]
73
78
 
74
- if (Array.isArray(tags) && tags.length > 0) {
79
+ if (Array.isArray(tags) && tags.length > 0 && this.inputs.variables[id]) {
75
80
  this.inputs.variables[id].forEach((v, index) => {
76
81
  tags.forEach(tag => {
77
82
  if (this.tags.variables[tag] === undefined) this.tags.variables[tag] = []