@legalplace/prerenderx 2.6.0 → 2.6.1
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/dist/libs/Prerender.d.ts +5 -14
- package/dist/libs/Prerender.js +30 -29
- package/package.json +2 -2
- package/src/libs/Prerender.ts +27 -25
package/dist/libs/Prerender.d.ts
CHANGED
|
@@ -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,21 +30,12 @@ declare class Prerender {
|
|
|
30
30
|
private NumAuto;
|
|
31
31
|
private documentsIndex;
|
|
32
32
|
private renderedDocuments;
|
|
33
|
-
constructor(
|
|
33
|
+
constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC);
|
|
34
34
|
getDocumentsIndex(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
|
|
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
|
-
};
|
|
35
|
+
getDocument(documentNameHash: string): string | FDFType;
|
|
47
36
|
private generateDocumentNamesHash;
|
|
37
|
+
private fillPdfForms;
|
|
38
|
+
private generateAllDocuments;
|
|
48
39
|
static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex;
|
|
49
40
|
static isOutput(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentOutputIndex;
|
|
50
41
|
}
|
package/dist/libs/Prerender.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
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
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -24,16 +13,12 @@ var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
|
|
|
24
13
|
var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
|
|
25
14
|
var OutputParser_1 = require("./OutputParser");
|
|
26
15
|
var Prerender = (function () {
|
|
27
|
-
function Prerender(
|
|
16
|
+
function Prerender(model, ovc) {
|
|
28
17
|
this.documentsIndex = {};
|
|
29
18
|
this.renderedDocuments = {};
|
|
30
|
-
|
|
31
|
-
this.references = entry;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
this.references = new referencesparser_1.ReferencesParser(entry).getReferences();
|
|
35
|
-
}
|
|
19
|
+
this.model = model;
|
|
36
20
|
this.NumAuto = new NumAuto_1.default();
|
|
21
|
+
this.references = new referencesparser_1.ReferencesParser(model).getReferences();
|
|
37
22
|
this.ovc = OvcConverter_1.default.isOvc(ovc)
|
|
38
23
|
? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
|
|
39
24
|
: ovc;
|
|
@@ -41,27 +26,22 @@ var Prerender = (function () {
|
|
|
41
26
|
this.conditions = new ConditionsRunner_1.default(this.references, inputs);
|
|
42
27
|
this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
|
|
43
28
|
this.pdfFiller = new FillPdfForm_1.default(this.references, this.conditions, inputs);
|
|
29
|
+
this.generateDocumentNamesHash();
|
|
30
|
+
this.generateAllDocuments();
|
|
31
|
+
this.fillPdfForms();
|
|
44
32
|
}
|
|
45
33
|
Prerender.prototype.getDocumentsIndex = function () {
|
|
46
|
-
this.generateDocumentNamesHash();
|
|
47
34
|
return this.documentsIndex;
|
|
48
35
|
};
|
|
49
36
|
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);
|
|
57
37
|
return this.renderedDocuments[documentNameHash];
|
|
58
38
|
};
|
|
59
39
|
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
60
40
|
var _this = this;
|
|
61
|
-
Object.keys(this.
|
|
41
|
+
Object.keys(this.model.documents).forEach(function (slug) {
|
|
62
42
|
var _a, _b;
|
|
63
|
-
var document = _this.
|
|
64
|
-
var documentParams = _this.
|
|
43
|
+
var document = _this.model.documents[slug];
|
|
44
|
+
var documentParams = _this.model.documents[slug].params;
|
|
65
45
|
var conditionObject = _this.references.conditions.documents[slug];
|
|
66
46
|
var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
|
|
67
47
|
if (condition === true) {
|
|
@@ -91,6 +71,27 @@ var Prerender = (function () {
|
|
|
91
71
|
}
|
|
92
72
|
});
|
|
93
73
|
};
|
|
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
|
+
};
|
|
94
95
|
Prerender.isPdfForm = function (index) {
|
|
95
96
|
return Object.prototype.hasOwnProperty.call(index, 'form');
|
|
96
97
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/prerenderx",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.1",
|
|
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": "
|
|
19
|
+
"@legalplace/referencesparser": "1.7.0",
|
|
20
20
|
"crypto": "^1.0.1",
|
|
21
21
|
"typescript": "3.9.3"
|
|
22
22
|
},
|
package/src/libs/Prerender.ts
CHANGED
|
@@ -51,10 +51,9 @@ class Prerender {
|
|
|
51
51
|
private renderedDocuments: Record<string, string | FDFType> = {}
|
|
52
52
|
|
|
53
53
|
constructor(entry: ModelV3 | Types.ReferencesType, ovc: OVC_TYPE | OldOVC) {
|
|
54
|
-
|
|
55
54
|
// Initiating references
|
|
56
55
|
if (ReferencesParser.isReferences(entry)) {
|
|
57
|
-
this.references = entry
|
|
56
|
+
this.references = entry
|
|
58
57
|
} else {
|
|
59
58
|
// Parsing references
|
|
60
59
|
this.references = new ReferencesParser(entry).getReferences()
|
|
@@ -62,11 +61,9 @@ class Prerender {
|
|
|
62
61
|
|
|
63
62
|
// Initiating num auto
|
|
64
63
|
this.NumAuto = new NumAuto()
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
// Converting OVC if needed
|
|
67
|
-
this.ovc = OvcConverter.isOvc(ovc)
|
|
68
|
-
? OvcConverter.convertToOptionsVariables(ovc, this.references)
|
|
69
|
-
: ovc
|
|
66
|
+
this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc, this.references) : ovc
|
|
70
67
|
|
|
71
68
|
// Initiating inputs
|
|
72
69
|
const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
|
|
@@ -79,32 +76,17 @@ class Prerender {
|
|
|
79
76
|
|
|
80
77
|
// Filling pdf documents
|
|
81
78
|
this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs)
|
|
79
|
+
|
|
80
|
+
this.generateDocumentNamesHash()
|
|
81
|
+
this.generateAllDocuments()
|
|
82
|
+
this.fillPdfForms()
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
public getDocumentsIndex() {
|
|
85
|
-
// Generating documents names
|
|
86
|
-
this.generateDocumentNamesHash();
|
|
87
|
-
|
|
88
86
|
return this.documentsIndex
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
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
|
|
108
90
|
return this.renderedDocuments[documentNameHash]
|
|
109
91
|
}
|
|
110
92
|
|
|
@@ -145,6 +127,26 @@ class Prerender {
|
|
|
145
127
|
})
|
|
146
128
|
}
|
|
147
129
|
|
|
130
|
+
private fillPdfForms() {
|
|
131
|
+
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
132
|
+
const index = this.documentsIndex[documentNameHash]
|
|
133
|
+
if (Prerender.isPdfForm(index)) {
|
|
134
|
+
index.fdf = this.getDocument(documentNameHash) as FDFType
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private generateAllDocuments() {
|
|
140
|
+
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
141
|
+
const index = this.documentsIndex[documentNameHash]
|
|
142
|
+
if (Prerender.isPdfForm(index)) {
|
|
143
|
+
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug)
|
|
144
|
+
} else {
|
|
145
|
+
this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug)
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
148
150
|
static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex {
|
|
149
151
|
return Object.prototype.hasOwnProperty.call(index, 'form')
|
|
150
152
|
}
|