@legalplace/prerenderx 2.6.4 → 3.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.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ### [2.6.4](https://git.legalplace.eu/legalplace/prerenderx/compare/v2.6.3...v2.6.4) (2021-10-04)
5
+ ### [2.5.5](https://git.legalplace.eu/legalplace/prerenderx/compare/v2.6.3...v2.5.5) (2021-10-27)
6
6
 
7
7
  ### [2.6.3](https://git.legalplace.eu/legalplace/prerenderx/compare/v2.6.2...v2.6.3) (2021-10-04)
8
8
 
@@ -6,10 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
7
7
  var DataPopulator_1 = __importDefault(require("./DataPopulator"));
8
8
  var conditionsCache = {};
9
- var createConditionCacheKey = function (condition, id, index, conditionType) {
10
- var conditionString = JSON.stringify(condition);
11
- return id + "-" + index + "-" + conditionType + "-" + conditionString;
12
- };
13
9
  var ConditionsRunner = (function () {
14
10
  function ConditionsRunner(references, ovc) {
15
11
  this.references = references;
@@ -55,9 +51,6 @@ var ConditionsRunner = (function () {
55
51
  var _this = this;
56
52
  if (Array.isArray(condition))
57
53
  return condition.map(function (_condition) { return _this.executeCondition(_condition, id, index, conditionType); });
58
- var cacheKey = createConditionCacheKey(condition, id, index, conditionType);
59
- if (Object.prototype.hasOwnProperty.call(conditionsCache, cacheKey))
60
- return conditionsCache[cacheKey];
61
54
  var currentData;
62
55
  if (conditionType === 'options' || conditionType === 'optionValidator') {
63
56
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
@@ -69,8 +62,7 @@ var ConditionsRunner = (function () {
69
62
  else if (conditionType === 'sections' || conditionType === 'documents') {
70
63
  currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
71
64
  }
72
- conditionsCache[cacheKey] = lplogic_1.default(condition.conditions, currentData);
73
- return conditionsCache[cacheKey];
65
+ return lplogic_1.default(condition.conditions, currentData);
74
66
  };
75
67
  return ConditionsRunner;
76
68
  }());
@@ -1,5 +1,4 @@
1
1
  import { ModelV3 } from '@legalplace/models-v3-types';
2
- import { Types } from '@legalplace/referencesparser';
3
2
  import OVC_TYPE from './ovc.type';
4
3
  import { OldOVC } from './OvcConverter';
5
4
  declare type DocumentOutputIndex = {
@@ -22,6 +21,7 @@ declare type FDFType = {
22
21
  fields: Record<string, string>;
23
22
  };
24
23
  declare class Prerender {
24
+ private model;
25
25
  private references;
26
26
  private ovc;
27
27
  private conditions;
@@ -30,7 +30,7 @@ declare class Prerender {
30
30
  private NumAuto;
31
31
  private documentsIndex;
32
32
  private renderedDocuments;
33
- constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC);
33
+ constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC);
34
34
  getDocumentsIndex(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
35
35
  getDocument(documentNameHash: string): string | FDFType;
36
36
  private generateDocumentNamesHash;
@@ -13,17 +13,15 @@ var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
13
13
  var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
14
14
  var OutputParser_1 = require("./OutputParser");
15
15
  var Prerender = (function () {
16
- function Prerender(entry, ovc) {
16
+ function Prerender(model, ovc) {
17
17
  this.documentsIndex = {};
18
18
  this.renderedDocuments = {};
19
- if (referencesparser_1.ReferencesParser.isReferences(entry)) {
20
- this.references = entry;
21
- }
22
- else {
23
- this.references = new referencesparser_1.ReferencesParser(entry).getReferences();
24
- }
19
+ this.model = model;
25
20
  this.NumAuto = new NumAuto_1.default();
26
- this.ovc = OvcConverter_1.default.isOvc(ovc) ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references) : ovc;
21
+ this.references = new referencesparser_1.ReferencesParser(model).getReferences();
22
+ this.ovc = OvcConverter_1.default.isOvc(ovc)
23
+ ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
24
+ : ovc;
27
25
  var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
28
26
  this.conditions = new ConditionsRunner_1.default(this.references, inputs);
29
27
  this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
@@ -40,10 +38,10 @@ var Prerender = (function () {
40
38
  };
41
39
  Prerender.prototype.generateDocumentNamesHash = function () {
42
40
  var _this = this;
43
- Object.keys(this.references.documents).forEach(function (slug) {
41
+ Object.keys(this.model.documents).forEach(function (slug) {
44
42
  var _a, _b;
45
- var document = _this.references.documents[slug];
46
- var documentParams = _this.references.documents[slug].params;
43
+ var document = _this.model.documents[slug];
44
+ var documentParams = _this.model.documents[slug].params;
47
45
  var conditionObject = _this.references.conditions.documents[slug];
48
46
  var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
49
47
  if (condition === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "2.6.4",
3
+ "version": "3.0.0",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -15,9 +15,9 @@
15
15
  "release": "standard-version -a --no-verify"
16
16
  },
17
17
  "dependencies": {
18
- "@legalplace/lplogic": "^2.1.6",
19
- "@legalplace/models-v3-types": "^3.5.1",
20
- "@legalplace/referencesparser": "^1.7.0",
18
+ "@legalplace/lplogic": "2.1.6",
19
+ "@legalplace/models-v3-types": "3.5.1",
20
+ "@legalplace/referencesparser": "1.6.3",
21
21
  "crypto": "^1.0.1",
22
22
  "standard-version": "^9.3.1",
23
23
  "typescript": "3.9.3"
@@ -22,29 +22,6 @@ const conditionsCache: {
22
22
  [key: string]: boolean
23
23
  } = {}
24
24
 
25
- /**
26
- * Generates cache key
27
- * @param condition
28
- * @param id
29
- * @param index
30
- * @param conditionType
31
- * @returns string
32
- */
33
- const createConditionCacheKey = (
34
- condition: {
35
- dataMap: ConditionDataMap
36
- conditions: ConditionV3
37
- },
38
- id: number,
39
- index: number,
40
- conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
41
- ) => {
42
- const conditionString = JSON.stringify(condition);
43
-
44
- return `${id}-${index}-${conditionType}-${conditionString}`
45
- }
46
-
47
-
48
25
  class ConditionsRunner {
49
26
  private references: Types.ReferencesType
50
27
 
@@ -122,13 +99,6 @@ class ConditionsRunner {
122
99
  // In case we have multiple conditions let's run them here
123
100
  if (Array.isArray(condition)) return condition.map(_condition => this.executeCondition(_condition, id, index, conditionType))
124
101
 
125
- // Generating cache key
126
- const cacheKey = createConditionCacheKey(condition, id, index, conditionType)
127
-
128
- // Checking if condition was already calculated
129
- if (Object.prototype.hasOwnProperty.call(conditionsCache, cacheKey))
130
- return conditionsCache[cacheKey]
131
-
132
102
  // Populating Data
133
103
  let currentData
134
104
  if (conditionType === 'options' || conditionType === 'optionValidator') {
@@ -140,11 +110,8 @@ class ConditionsRunner {
140
110
  currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, id, index).getData()
141
111
  }
142
112
 
143
- // Running condition and storing it in cache
144
- conditionsCache[cacheKey] = LpLogic(condition.conditions, currentData);
145
-
146
113
  // Returning cache result
147
- return conditionsCache[cacheKey];
114
+ return LpLogic(condition.conditions, currentData)
148
115
  }
149
116
  }
150
117
 
@@ -34,6 +34,8 @@ type FDFType = {
34
34
  }
35
35
 
36
36
  class Prerender {
37
+ private model: ModelV3
38
+
37
39
  private references: Types.ReferencesType
38
40
 
39
41
  private ovc: OVC_TYPE
@@ -50,20 +52,19 @@ class Prerender {
50
52
 
51
53
  private renderedDocuments: Record<string, string | FDFType> = {}
52
54
 
53
- constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC) {
54
- // Initiating references
55
- if (ReferencesParser.isReferences(entry)) {
56
- this.references = entry
57
- } else {
58
- // Parsing references
59
- this.references = new ReferencesParser(entry).getReferences()
60
- }
55
+ constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC) {
56
+ this.model = model
61
57
 
62
58
  // Initiating num auto
63
59
  this.NumAuto = new NumAuto()
64
60
 
61
+ // Parsing references
62
+ this.references = new ReferencesParser(model).getReferences()
63
+
65
64
  // Converting OVC if needed
66
- this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc, this.references) : ovc
65
+ this.ovc = OvcConverter.isOvc(ovc)
66
+ ? OvcConverter.convertToOptionsVariables(ovc, this.references)
67
+ : ovc
67
68
 
68
69
  // Initiating inputs
69
70
  const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
@@ -91,9 +92,9 @@ class Prerender {
91
92
  }
92
93
 
93
94
  private generateDocumentNamesHash() {
94
- Object.keys(this.references.documents).forEach(slug => {
95
- const document = this.references.documents[slug]
96
- const documentParams = this.references.documents[slug].params
95
+ Object.keys(this.model.documents).forEach(slug => {
96
+ const document = this.model.documents[slug]
97
+ const documentParams = this.model.documents[slug].params
97
98
  const conditionObject = this.references.conditions.documents[slug]
98
99
  const condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'documents')
99
100