@legalplace/prerenderx 2.5.7 → 2.6.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 { Types } from '@legalplace/referencesparser';
2
3
  import OVC_TYPE from './ovc.type';
3
4
  import { OldOVC } from './OvcConverter';
4
5
  declare type DocumentOutputIndex = {
@@ -21,7 +22,6 @@ declare type FDFType = {
21
22
  fields: Record<string, string>;
22
23
  };
23
24
  declare class Prerender {
24
- private model;
25
25
  private references;
26
26
  private ovc;
27
27
  private conditions;
@@ -30,12 +30,21 @@ declare class Prerender {
30
30
  private NumAuto;
31
31
  private documentsIndex;
32
32
  private renderedDocuments;
33
- constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC);
33
+ constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC);
34
34
  getDocumentsIndex(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
35
- getDocument(documentNameHash: string): string | FDFType;
35
+ getDocument(documentNameHash: string): string | FDFType | {
36
+ fdf: string | FDFType;
37
+ name: string;
38
+ slug: string;
39
+ pdf: boolean;
40
+ docx: boolean;
41
+ } | {
42
+ fdf: string | FDFType;
43
+ name: string;
44
+ slug: string;
45
+ form: boolean;
46
+ };
36
47
  private generateDocumentNamesHash;
37
- private fillPdfForms;
38
- private generateAllDocuments;
39
48
  static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex;
40
49
  static isOutput(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentOutputIndex;
41
50
  }
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -13,12 +24,16 @@ var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
13
24
  var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
14
25
  var OutputParser_1 = require("./OutputParser");
15
26
  var Prerender = (function () {
16
- function Prerender(model, ovc) {
27
+ function Prerender(entry, ovc) {
17
28
  this.documentsIndex = {};
18
29
  this.renderedDocuments = {};
19
- this.model = model;
30
+ if (referencesparser_1.ReferencesParser.isReferences(entry)) {
31
+ this.references = entry;
32
+ }
33
+ else {
34
+ this.references = new referencesparser_1.ReferencesParser(entry).getReferences();
35
+ }
20
36
  this.NumAuto = new NumAuto_1.default();
21
- this.references = new referencesparser_1.ReferencesParser(model).getReferences();
22
37
  this.ovc = OvcConverter_1.default.isOvc(ovc)
23
38
  ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
24
39
  : ovc;
@@ -26,22 +41,27 @@ var Prerender = (function () {
26
41
  this.conditions = new ConditionsRunner_1.default(this.references, inputs);
27
42
  this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
28
43
  this.pdfFiller = new FillPdfForm_1.default(this.references, this.conditions, inputs);
29
- this.generateDocumentNamesHash();
30
- this.generateAllDocuments();
31
- this.fillPdfForms();
32
44
  }
33
45
  Prerender.prototype.getDocumentsIndex = function () {
46
+ this.generateDocumentNamesHash();
34
47
  return this.documentsIndex;
35
48
  };
36
49
  Prerender.prototype.getDocument = function (documentNameHash) {
50
+ if (Prerender.isPdfForm(this.documentsIndex[documentNameHash])) {
51
+ if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
52
+ this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug);
53
+ return __assign(__assign({}, this.documentsIndex[documentNameHash]), { fdf: this.renderedDocuments[documentNameHash] });
54
+ }
55
+ if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
56
+ this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug);
37
57
  return this.renderedDocuments[documentNameHash];
38
58
  };
39
59
  Prerender.prototype.generateDocumentNamesHash = function () {
40
60
  var _this = this;
41
- Object.keys(this.model.documents).forEach(function (slug) {
61
+ Object.keys(this.references.documents).forEach(function (slug) {
42
62
  var _a, _b;
43
- var document = _this.model.documents[slug];
44
- var documentParams = _this.model.documents[slug].params;
63
+ var document = _this.references.documents[slug];
64
+ var documentParams = _this.references.documents[slug].params;
45
65
  var conditionObject = _this.references.conditions.documents[slug];
46
66
  var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
47
67
  if (condition === true) {
@@ -71,27 +91,6 @@ var Prerender = (function () {
71
91
  }
72
92
  });
73
93
  };
74
- Prerender.prototype.fillPdfForms = function () {
75
- var _this = this;
76
- Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
77
- var index = _this.documentsIndex[documentNameHash];
78
- if (Prerender.isPdfForm(index)) {
79
- index.fdf = _this.getDocument(documentNameHash);
80
- }
81
- });
82
- };
83
- Prerender.prototype.generateAllDocuments = function () {
84
- var _this = this;
85
- Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
86
- var index = _this.documentsIndex[documentNameHash];
87
- if (Prerender.isPdfForm(index)) {
88
- _this.renderedDocuments[documentNameHash] = _this.pdfFiller.fillDocument(_this.documentsIndex[documentNameHash].slug);
89
- }
90
- else {
91
- _this.renderedDocuments[documentNameHash] = _this.documentRender.renderDocument(_this.documentsIndex[documentNameHash].slug);
92
- }
93
- });
94
- };
95
94
  Prerender.isPdfForm = function (index) {
96
95
  return Object.prototype.hasOwnProperty.call(index, 'form');
97
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "2.5.7",
3
+ "version": "2.6.0",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -16,7 +16,7 @@
16
16
  "dependencies": {
17
17
  "@legalplace/lplogic": "^2.1.6",
18
18
  "@legalplace/models-v3-types": "^3.5.1",
19
- "@legalplace/referencesparser": "1.7.0",
19
+ "@legalplace/referencesparser": "^1.7.0",
20
20
  "crypto": "^1.0.1",
21
21
  "typescript": "3.9.3"
22
22
  },
@@ -34,8 +34,6 @@ type FDFType = {
34
34
  }
35
35
 
36
36
  class Prerender {
37
- private model: ModelV3
38
-
39
37
  private references: Types.ReferencesType
40
38
 
41
39
  private ovc: OVC_TYPE
@@ -52,15 +50,19 @@ class Prerender {
52
50
 
53
51
  private renderedDocuments: Record<string, string | FDFType> = {}
54
52
 
55
- constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC) {
56
- this.model = model
53
+ constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC) {
54
+
55
+ // Initiating references
56
+ if (ReferencesParser.isReferences(entry)) {
57
+ this.references = entry;
58
+ } else {
59
+ // Parsing references
60
+ this.references = new ReferencesParser(entry).getReferences()
61
+ }
57
62
 
58
63
  // Initiating num auto
59
64
  this.NumAuto = new NumAuto()
60
-
61
- // Parsing references
62
- this.references = new ReferencesParser(model).getReferences()
63
-
65
+
64
66
  // Converting OVC if needed
65
67
  this.ovc = OvcConverter.isOvc(ovc)
66
68
  ? OvcConverter.convertToOptionsVariables(ovc, this.references)
@@ -77,24 +79,39 @@ class Prerender {
77
79
 
78
80
  // Filling pdf documents
79
81
  this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs)
80
-
81
- this.generateDocumentNamesHash()
82
- this.generateAllDocuments()
83
- this.fillPdfForms()
84
82
  }
85
83
 
86
84
  public getDocumentsIndex() {
85
+ // Generating documents names
86
+ this.generateDocumentNamesHash();
87
+
87
88
  return this.documentsIndex
88
89
  }
89
90
 
90
91
  public getDocument(documentNameHash: string) {
92
+ // Handling Pdf form
93
+ if (Prerender.isPdfForm(this.documentsIndex[documentNameHash])) {
94
+ if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
95
+ this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug);
96
+
97
+ return {
98
+ ...this.documentsIndex[documentNameHash],
99
+ fdf: this.renderedDocuments[documentNameHash]
100
+ }
101
+ }
102
+
103
+ // Avoiding regeneration if document exists before rendering it
104
+ if (!Object.prototype.hasOwnProperty.call(this.renderedDocuments, documentNameHash))
105
+ this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug)
106
+
107
+ // Returning rendered document
91
108
  return this.renderedDocuments[documentNameHash]
92
109
  }
93
110
 
94
111
  private generateDocumentNamesHash() {
95
- Object.keys(this.model.documents).forEach(slug => {
96
- const document = this.model.documents[slug]
97
- const documentParams = this.model.documents[slug].params
112
+ Object.keys(this.references.documents).forEach(slug => {
113
+ const document = this.references.documents[slug]
114
+ const documentParams = this.references.documents[slug].params
98
115
  const conditionObject = this.references.conditions.documents[slug]
99
116
  const condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'documents')
100
117
 
@@ -128,26 +145,6 @@ class Prerender {
128
145
  })
129
146
  }
130
147
 
131
- private fillPdfForms() {
132
- Object.keys(this.documentsIndex).forEach(documentNameHash => {
133
- const index = this.documentsIndex[documentNameHash]
134
- if (Prerender.isPdfForm(index)) {
135
- index.fdf = this.getDocument(documentNameHash) as FDFType
136
- }
137
- })
138
- }
139
-
140
- private generateAllDocuments() {
141
- Object.keys(this.documentsIndex).forEach(documentNameHash => {
142
- const index = this.documentsIndex[documentNameHash]
143
- if (Prerender.isPdfForm(index)) {
144
- this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug)
145
- } else {
146
- this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug)
147
- }
148
- })
149
- }
150
-
151
148
  static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex {
152
149
  return Object.prototype.hasOwnProperty.call(index, 'form')
153
150
  }