@legalplace/tagextractor 1.1.8 → 1.3.0-alpha

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.
@@ -9,6 +9,8 @@ declare class ConditionsRunner {
9
9
  isOptionRelatedToOption(optionA: number, optionB: number): boolean;
10
10
  isVariableRelatedToOption(variableId: number, optionId: number): boolean;
11
11
  isVariableRelatedToVariable(variableA: number, variableB: number): boolean;
12
+ private executeConditionMemo;
13
+ private buildMemoizeKey;
12
14
  executeCondition(condition: {
13
15
  dataMap: ConditionDataMap;
14
16
  conditions: ConditionV3;
@@ -7,6 +7,8 @@ var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
7
7
  var DataPopulator_1 = __importDefault(require("./DataPopulator"));
8
8
  var ConditionsRunner = (function () {
9
9
  function ConditionsRunner(references, ovc) {
10
+ this.executeConditionMemo = {};
11
+ this.buildMemoizeKey = function (condition, id, index, conditionType) { return JSON.stringify(condition) + "-" + id + "-" + index + "-" + conditionType; };
10
12
  this.references = references;
11
13
  this.ovc = ovc;
12
14
  }
@@ -47,9 +49,9 @@ var ConditionsRunner = (function () {
47
49
  return false;
48
50
  };
49
51
  ConditionsRunner.prototype.executeCondition = function (condition, id, index, conditionType) {
50
- var _this = this;
51
- if (Array.isArray(condition))
52
- return condition.map(function (_condition) { return _this.executeCondition(_condition, id, index, conditionType); });
52
+ var memoizedKey = this.buildMemoizeKey(condition, id, index, conditionType);
53
+ if (this.executeConditionMemo[memoizedKey])
54
+ return this.executeConditionMemo[memoizedKey];
53
55
  var currentData;
54
56
  if (conditionType === 'options' || conditionType === 'optionValidator') {
55
57
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
@@ -61,7 +63,9 @@ var ConditionsRunner = (function () {
61
63
  else if (conditionType === 'sections' || conditionType === 'documents') {
62
64
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
63
65
  }
64
- return lplogic_1.default(condition.conditions, currentData);
66
+ var result = lplogic_1.default(condition.conditions, currentData);
67
+ this.executeConditionMemo[memoizedKey] = result;
68
+ return result;
65
69
  };
66
70
  return ConditionsRunner;
67
71
  }());
@@ -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();