@legalplace/prerenderx 2.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/.eslintrc +52 -0
- package/.gitlab-ci.yml +28 -0
- package/.vscode/settings.json +22 -0
- package/.vscode/tasks.json +24 -0
- package/README.md +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/libs/ConditionsRunner.d.ts +27 -0
- package/dist/libs/ConditionsRunner.js +134 -0
- package/dist/libs/DocumentRender.d.ts +15 -0
- package/dist/libs/DocumentRender.js +34 -0
- package/dist/libs/NumAuto.d.ts +8 -0
- package/dist/libs/NumAuto.js +32 -0
- package/dist/libs/OptionRender.d.ts +25 -0
- package/dist/libs/OptionRender.js +73 -0
- package/dist/libs/OutputParser.d.ts +9 -0
- package/dist/libs/OutputParser.js +49 -0
- package/dist/libs/Prerender.d.ts +22 -0
- package/dist/libs/Prerender.js +58 -0
- package/dist/libs/SectionRender.d.ts +24 -0
- package/dist/libs/SectionRender.js +67 -0
- package/dist/libs/ovc.type.d.ts +9 -0
- package/dist/libs/ovc.type.js +2 -0
- package/jest.config.js +11 -0
- package/package.json +39 -0
- package/src/index.ts +3 -0
- package/src/libs/ConditionsRunner.ts +237 -0
- package/src/libs/DocumentRender.ts +52 -0
- package/src/libs/NumAuto.ts +48 -0
- package/src/libs/OptionRender.ts +124 -0
- package/src/libs/OutputParser.ts +122 -0
- package/src/libs/Prerender.ts +107 -0
- package/src/libs/SectionRender.ts +96 -0
- package/src/libs/ovc.type.ts +10 -0
- package/tsconfig.eslint.json +12 -0
- package/tsconfig.json +16 -0
- package/yarn.lock +5087 -0
package/.eslintrc
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"commonjs": true,
|
|
5
|
+
"es6": true,
|
|
6
|
+
"jest": true,
|
|
7
|
+
"node": true
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
"extends": [
|
|
11
|
+
"airbnb-base",
|
|
12
|
+
"plugin:prettier/recommended"
|
|
13
|
+
],
|
|
14
|
+
|
|
15
|
+
"parser": "@typescript-eslint/parser",
|
|
16
|
+
"parserOptions": {
|
|
17
|
+
"project": "./tsconfig.eslint.json"
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
"plugins": [
|
|
21
|
+
"prettier", "@typescript-eslint"
|
|
22
|
+
],
|
|
23
|
+
|
|
24
|
+
"rules": {
|
|
25
|
+
"prettier/prettier": ["error"],
|
|
26
|
+
"no-unused-vars": "off",
|
|
27
|
+
"@typescript-eslint/no-unused-vars": ["error", {
|
|
28
|
+
"vars": "all",
|
|
29
|
+
"args": "after-used",
|
|
30
|
+
"ignoreRestSiblings": false
|
|
31
|
+
}],
|
|
32
|
+
"import/no-extraneous-dependencies": ["error", {
|
|
33
|
+
"devDependencies": true
|
|
34
|
+
}],
|
|
35
|
+
"no-continue": 0,
|
|
36
|
+
"class-methods-use-this": 0,
|
|
37
|
+
"no-underscore-dangle": 0,
|
|
38
|
+
"import/prefer-default-export": "warn",
|
|
39
|
+
"camelcase": "error",
|
|
40
|
+
"no-undef": 0,
|
|
41
|
+
"no-dupe-class-members": "off"
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
"settings": {
|
|
46
|
+
"import/resolver": {
|
|
47
|
+
"node": {
|
|
48
|
+
"extensions": [".js", ".jsx", ".ts", ".tsx"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
image: node:11-alpine
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
stages:
|
|
5
|
+
- deploy
|
|
6
|
+
|
|
7
|
+
before_script:
|
|
8
|
+
- export PATH=$PATH:./node_modules/.bin/
|
|
9
|
+
|
|
10
|
+
variables:
|
|
11
|
+
DOCKER_DRIVER: overlay2
|
|
12
|
+
|
|
13
|
+
publish:
|
|
14
|
+
image: node:11-alpine
|
|
15
|
+
stage: deploy
|
|
16
|
+
except:
|
|
17
|
+
variables:
|
|
18
|
+
- $CI_COMMIT_MESSAGE =~ /skip-publish/
|
|
19
|
+
script:
|
|
20
|
+
- echo -e "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
|
|
21
|
+
- yarn install
|
|
22
|
+
- yarn build
|
|
23
|
+
- npm publish
|
|
24
|
+
- echo "PUBLISHED SUCCESSFULLY"
|
|
25
|
+
environment:
|
|
26
|
+
name: development
|
|
27
|
+
only:
|
|
28
|
+
- master
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"eslint.enable": true,
|
|
3
|
+
"eslint.autoFixOnSave": true,
|
|
4
|
+
"editor.tabSize": 2,
|
|
5
|
+
"eslint.validate": [
|
|
6
|
+
"javascript",
|
|
7
|
+
{
|
|
8
|
+
"autoFix": true,
|
|
9
|
+
"language": "typescript"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"eslint.options": {
|
|
13
|
+
"extensions": [".ts", ".js"]
|
|
14
|
+
},
|
|
15
|
+
"files.autoSave": "off",
|
|
16
|
+
"editor.formatOnSave": false,
|
|
17
|
+
"editor.formatOnType": true,
|
|
18
|
+
"prettier.singleQuote": true,
|
|
19
|
+
"eslint.packageManager": "yarn",
|
|
20
|
+
"eslint.quiet": true,
|
|
21
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
3
|
+
// for the documentation about the tasks.json format
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"tasks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "npm",
|
|
8
|
+
"script": "lint",
|
|
9
|
+
"problemMatcher": [
|
|
10
|
+
"$eslint-stylish",
|
|
11
|
+
"$tsc"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"type": "typescript",
|
|
16
|
+
"tsconfig": "tsconfig.json",
|
|
17
|
+
"option": "watch",
|
|
18
|
+
"problemMatcher": [
|
|
19
|
+
"$tsc-watch"
|
|
20
|
+
],
|
|
21
|
+
"group": "build"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# PrerenderX v1.0.0
|
|
2
|
+
|
|
3
|
+
# Install
|
|
4
|
+
```
|
|
5
|
+
yarn add git+https://git.legalplace.eu/legalplace/prerenderx.git#1.0.0
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
# Usage
|
|
9
|
+
```javascript
|
|
10
|
+
import { Prerender } from 'prerenderx';
|
|
11
|
+
|
|
12
|
+
const model = {}; // Your v3 (non final) model
|
|
13
|
+
const ovc = {options: {}, variables: {}}; // Your OVC
|
|
14
|
+
|
|
15
|
+
const prerender = new Prerender(modelV3, ovc);
|
|
16
|
+
|
|
17
|
+
const documents = prerender.getDocuments();
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Variable `documents` will now contain an object containing all documents and their respective outputs
|
|
21
|
+
```
|
|
22
|
+
{
|
|
23
|
+
'main': [..., 'some output', ...],
|
|
24
|
+
'some secondary document': [..., 'some other output', ...]
|
|
25
|
+
...
|
|
26
|
+
}
|
|
27
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var Prerender_1 = __importDefault(require("./libs/Prerender"));
|
|
7
|
+
exports.Prerender = Prerender_1.default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import { ConditionV3 } from "@legalplace/models-v3-types";
|
|
3
|
+
declare type OVC_TYPE = {
|
|
4
|
+
options: {
|
|
5
|
+
[key: string]: boolean[];
|
|
6
|
+
};
|
|
7
|
+
variables: {
|
|
8
|
+
[key: string]: (number | string)[];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
declare class ConditionsRunner {
|
|
12
|
+
private references;
|
|
13
|
+
private ovc;
|
|
14
|
+
constructor(references: Types.ReferencesType, ovc: OVC_TYPE);
|
|
15
|
+
private populateData;
|
|
16
|
+
isOptionRelatedToOption(optionA: number, optionB: number): boolean;
|
|
17
|
+
isVariableRelatedToOption(variableId: number, optionId: number): boolean;
|
|
18
|
+
isVariableRelatedToVariable(variableA: number, variableB: number): boolean;
|
|
19
|
+
executeCondition(condition: {
|
|
20
|
+
dataMap: {
|
|
21
|
+
o: number[];
|
|
22
|
+
v: number[];
|
|
23
|
+
};
|
|
24
|
+
conditions: ConditionV3;
|
|
25
|
+
}, id: number, index: number, conditionType: "options" | "optionValidator" | "variables" | "prefillers" | "variableValidator" | "sections" | "documents"): any;
|
|
26
|
+
}
|
|
27
|
+
export default ConditionsRunner;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
|
|
7
|
+
var ConditionsRunner = (function () {
|
|
8
|
+
function ConditionsRunner(references, ovc) {
|
|
9
|
+
this.references = references;
|
|
10
|
+
this.ovc = ovc;
|
|
11
|
+
}
|
|
12
|
+
ConditionsRunner.prototype.populateData = function (id, index, dataMap, withRelations) {
|
|
13
|
+
var _this = this;
|
|
14
|
+
if (withRelations === void 0) { withRelations = true; }
|
|
15
|
+
var data = {
|
|
16
|
+
o: {},
|
|
17
|
+
v: {}
|
|
18
|
+
};
|
|
19
|
+
dataMap.o.forEach(function (currentOptionId) {
|
|
20
|
+
var value = _this.ovc.options[currentOptionId];
|
|
21
|
+
var currentOptionParents = _this.references.relations.options[currentOptionId].parents;
|
|
22
|
+
var currentOptionRoot = currentOptionParents[currentOptionParents.length - 1];
|
|
23
|
+
var currentOptionRootRelations = currentOptionRoot
|
|
24
|
+
? _this.references.relations.options[currentOptionId]
|
|
25
|
+
: undefined;
|
|
26
|
+
if (withRelations === true && currentOptionRootRelations) {
|
|
27
|
+
if (id === currentOptionId ||
|
|
28
|
+
currentOptionRootRelations.children.options.includes(id) ||
|
|
29
|
+
currentOptionRootRelations.dependants.includes(id))
|
|
30
|
+
value = [value[index]];
|
|
31
|
+
}
|
|
32
|
+
data.o[currentOptionId] = value;
|
|
33
|
+
});
|
|
34
|
+
dataMap.v.forEach(function (currentVariableId) {
|
|
35
|
+
var variableReference = _this.references.variables[currentVariableId];
|
|
36
|
+
var value = _this.ovc.variables[currentVariableId];
|
|
37
|
+
var variableParents = _this.references.relations.variables[currentVariableId].parents;
|
|
38
|
+
var currentOptionId = variableParents[0];
|
|
39
|
+
var currentOptionParents = _this.references.relations.options[currentOptionId].parents;
|
|
40
|
+
var currentOptionRoot = currentOptionParents[currentOptionParents.length - 1];
|
|
41
|
+
var currentOptionRootRelations = currentOptionRoot
|
|
42
|
+
? _this.references.relations.options[currentOptionId]
|
|
43
|
+
: undefined;
|
|
44
|
+
if (withRelations === true && currentOptionRootRelations) {
|
|
45
|
+
if (currentOptionRootRelations.children.options.includes(currentOptionId) ||
|
|
46
|
+
currentOptionRootRelations.dependants.includes(currentOptionId)) {
|
|
47
|
+
value = [value[index]];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var dataValue = value.map(function (v) {
|
|
51
|
+
return v === null ? "" : v;
|
|
52
|
+
});
|
|
53
|
+
if (variableReference.type === "number") {
|
|
54
|
+
dataValue = dataValue.map(function (v) {
|
|
55
|
+
return typeof v === "number" ? v : parseFloat(v);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
data.v[currentVariableId] = dataValue;
|
|
59
|
+
});
|
|
60
|
+
return data;
|
|
61
|
+
};
|
|
62
|
+
ConditionsRunner.prototype.isOptionRelatedToOption = function (optionA, optionB) {
|
|
63
|
+
var OptionBParents = this.references.relations.options[optionB].parents;
|
|
64
|
+
var OptionBRoot = OptionBParents[OptionBParents.length - 1];
|
|
65
|
+
var OptionBRootRelations = OptionBRoot
|
|
66
|
+
? this.references.relations.options[OptionBRoot]
|
|
67
|
+
: undefined;
|
|
68
|
+
if (OptionBRootRelations) {
|
|
69
|
+
if (optionA === optionB ||
|
|
70
|
+
OptionBRootRelations.children.options.includes(optionA) ||
|
|
71
|
+
OptionBRootRelations.dependants.includes(optionA)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
};
|
|
77
|
+
ConditionsRunner.prototype.isVariableRelatedToOption = function (variableId, optionId) {
|
|
78
|
+
var variableParentId = this.references.relations.variables[variableId]
|
|
79
|
+
.parents[0];
|
|
80
|
+
var optionParents = this.references.relations.options[variableParentId]
|
|
81
|
+
.parents;
|
|
82
|
+
var optionRoot = optionParents[optionParents.length - 1];
|
|
83
|
+
var optionRootRelations = optionRoot
|
|
84
|
+
? this.references.relations.options[optionRoot]
|
|
85
|
+
: undefined;
|
|
86
|
+
if (optionRootRelations) {
|
|
87
|
+
if (optionRootRelations.children.options.includes(optionId) ||
|
|
88
|
+
optionRootRelations.dependants.includes(optionId)) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
};
|
|
94
|
+
ConditionsRunner.prototype.isVariableRelatedToVariable = function (variableA, variableB) {
|
|
95
|
+
var optionA = this.references.relations.variables[variableA].parents[0];
|
|
96
|
+
var optionB = this.references.relations.variables[variableB].parents[0];
|
|
97
|
+
var OptionBParents = this.references.relations.options[optionB].parents;
|
|
98
|
+
var OptionBRoot = OptionBParents[OptionBParents.length - 1];
|
|
99
|
+
var OptionBRootRelations = OptionBRoot
|
|
100
|
+
? this.references.relations.options[OptionBRoot]
|
|
101
|
+
: undefined;
|
|
102
|
+
if (OptionBRootRelations) {
|
|
103
|
+
if (optionA === optionB ||
|
|
104
|
+
OptionBRootRelations.children.options.includes(optionA) ||
|
|
105
|
+
OptionBRootRelations.dependants.includes(optionA)) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
};
|
|
111
|
+
ConditionsRunner.prototype.executeCondition = function (condition, id, index, conditionType) {
|
|
112
|
+
var _this = this;
|
|
113
|
+
if (Array.isArray(condition))
|
|
114
|
+
return condition.map(function (_condition) {
|
|
115
|
+
return _this.executeCondition(_condition, id, index, conditionType);
|
|
116
|
+
});
|
|
117
|
+
var currentData;
|
|
118
|
+
if (conditionType === "options" || conditionType === "optionValidator") {
|
|
119
|
+
currentData = this.populateData(id, index, condition.dataMap);
|
|
120
|
+
}
|
|
121
|
+
else if (conditionType === "variables" ||
|
|
122
|
+
conditionType === "prefillers" ||
|
|
123
|
+
conditionType === "variableValidator") {
|
|
124
|
+
var dataId = this.references.relations.variables[id].parents[0];
|
|
125
|
+
currentData = this.populateData(dataId, index, condition.dataMap);
|
|
126
|
+
}
|
|
127
|
+
else if (conditionType === "sections" || conditionType === "documents") {
|
|
128
|
+
currentData = this.populateData(id, index, condition.dataMap, false);
|
|
129
|
+
}
|
|
130
|
+
return lplogic_1.default(condition.conditions, currentData);
|
|
131
|
+
};
|
|
132
|
+
return ConditionsRunner;
|
|
133
|
+
}());
|
|
134
|
+
exports.default = ConditionsRunner;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import ConditionsRunner from "./ConditionsRunner";
|
|
3
|
+
import OVC_TYPE from "./ovc.type";
|
|
4
|
+
import NumAuto from "./NumAuto";
|
|
5
|
+
declare class DocumentRender {
|
|
6
|
+
references: Types.ReferencesType;
|
|
7
|
+
conditions: ConditionsRunner;
|
|
8
|
+
ovc: OVC_TYPE;
|
|
9
|
+
documents: Record<string, string[]>;
|
|
10
|
+
documentsNamesHash: Record<string, string>;
|
|
11
|
+
private NumAuto;
|
|
12
|
+
constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE, numauto: NumAuto);
|
|
13
|
+
renderDocument(documentName: string): string;
|
|
14
|
+
}
|
|
15
|
+
export default DocumentRender;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var SectionRender_1 = __importDefault(require("./SectionRender"));
|
|
7
|
+
var DocumentRender = (function () {
|
|
8
|
+
function DocumentRender(references, conditions, ovc, numauto) {
|
|
9
|
+
this.documents = {};
|
|
10
|
+
this.documentsNamesHash = {};
|
|
11
|
+
this.references = references;
|
|
12
|
+
this.conditions = conditions;
|
|
13
|
+
this.ovc = ovc;
|
|
14
|
+
this.NumAuto = numauto;
|
|
15
|
+
}
|
|
16
|
+
DocumentRender.prototype.renderDocument = function (documentName) {
|
|
17
|
+
var _this = this;
|
|
18
|
+
var documentOutputs = [];
|
|
19
|
+
this.NumAuto.resetIndexes();
|
|
20
|
+
Object.keys(this.references.sections[documentName]).forEach(function (sectionId) {
|
|
21
|
+
documentOutputs.push.apply(documentOutputs, new SectionRender_1.default({
|
|
22
|
+
references: _this.references,
|
|
23
|
+
conditions: _this.conditions,
|
|
24
|
+
documentName: documentName,
|
|
25
|
+
ovc: _this.ovc,
|
|
26
|
+
currentSection: parseInt(sectionId, 10),
|
|
27
|
+
numauto: _this.NumAuto
|
|
28
|
+
}).getOutputs());
|
|
29
|
+
});
|
|
30
|
+
return documentOutputs.join("");
|
|
31
|
+
};
|
|
32
|
+
return DocumentRender;
|
|
33
|
+
}());
|
|
34
|
+
exports.default = DocumentRender;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var NumAuto = (function () {
|
|
4
|
+
function NumAuto() {
|
|
5
|
+
var _this = this;
|
|
6
|
+
this.indexesList = {};
|
|
7
|
+
this.tagsIndex = {};
|
|
8
|
+
this.getNum = function (index, tag) {
|
|
9
|
+
if (!Object.prototype.hasOwnProperty.call(_this.indexesList, index)) {
|
|
10
|
+
if (Object.prototype.hasOwnProperty.call(_this.tagsIndex, index))
|
|
11
|
+
return _this.tagsIndex[index];
|
|
12
|
+
_this.indexesList[index] = 0;
|
|
13
|
+
}
|
|
14
|
+
_this.indexesList[index] += 1;
|
|
15
|
+
if (typeof tag === "string")
|
|
16
|
+
_this.tagsIndex[tag] = _this.indexesList[index];
|
|
17
|
+
return _this.indexesList[index];
|
|
18
|
+
};
|
|
19
|
+
this.getNumPre = function (index) {
|
|
20
|
+
if (!Object.prototype.hasOwnProperty.call(_this.indexesList, index)) {
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(_this.tagsIndex, index))
|
|
22
|
+
return _this.tagsIndex[index];
|
|
23
|
+
}
|
|
24
|
+
return _this.indexesList[index];
|
|
25
|
+
};
|
|
26
|
+
this.resetIndexes = function () {
|
|
27
|
+
_this.indexesList = {};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return NumAuto;
|
|
31
|
+
}());
|
|
32
|
+
exports.default = NumAuto;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import ConditionsRunner from "./ConditionsRunner";
|
|
3
|
+
import OVC_TYPE from "./ovc.type";
|
|
4
|
+
import NumAuto from "./NumAuto";
|
|
5
|
+
declare class OptionRender {
|
|
6
|
+
outputs: string[];
|
|
7
|
+
references: Types.ReferencesType;
|
|
8
|
+
index: number;
|
|
9
|
+
id: number;
|
|
10
|
+
conditions: ConditionsRunner;
|
|
11
|
+
ovc: OVC_TYPE;
|
|
12
|
+
private NumAuto;
|
|
13
|
+
constructor(options: {
|
|
14
|
+
references: Types.ReferencesType;
|
|
15
|
+
conditions: ConditionsRunner;
|
|
16
|
+
ovc: OVC_TYPE;
|
|
17
|
+
index: number;
|
|
18
|
+
id: number;
|
|
19
|
+
numauto: NumAuto;
|
|
20
|
+
});
|
|
21
|
+
getOutputs(): string[];
|
|
22
|
+
private renderOption;
|
|
23
|
+
private renderChildren;
|
|
24
|
+
}
|
|
25
|
+
export default OptionRender;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
+
r[k] = a[j];
|
|
7
|
+
return r;
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
var OutputParser_1 = require("./OutputParser");
|
|
11
|
+
var OptionRender = (function () {
|
|
12
|
+
function OptionRender(options) {
|
|
13
|
+
this.outputs = [];
|
|
14
|
+
this.references = options.references;
|
|
15
|
+
this.conditions = options.conditions;
|
|
16
|
+
this.index = options.index;
|
|
17
|
+
this.id = options.id;
|
|
18
|
+
this.ovc = options.ovc;
|
|
19
|
+
this.NumAuto = options.numauto;
|
|
20
|
+
this.renderOption();
|
|
21
|
+
}
|
|
22
|
+
OptionRender.prototype.getOutputs = function () {
|
|
23
|
+
return this.outputs;
|
|
24
|
+
};
|
|
25
|
+
OptionRender.prototype.renderOption = function () {
|
|
26
|
+
var _this = this;
|
|
27
|
+
var option = this.references.options[this.id];
|
|
28
|
+
var conditionObject = this.references.conditions.options[this.id];
|
|
29
|
+
var condition = conditionObject === undefined
|
|
30
|
+
? true
|
|
31
|
+
: this.conditions.executeCondition(conditionObject, this.id, this.index, "options");
|
|
32
|
+
if (condition === true) {
|
|
33
|
+
if (typeof option.meta.output === "string" &&
|
|
34
|
+
option.meta.output.trim().length > 0) {
|
|
35
|
+
var outputReference = this.references.outputs[this.id];
|
|
36
|
+
var autonums = [];
|
|
37
|
+
if (condition !== false) {
|
|
38
|
+
autonums = outputReference.autonums.map(function (currentAn) {
|
|
39
|
+
var fn = currentAn[0] === "numauto-pre"
|
|
40
|
+
? _this.NumAuto.getNumPre
|
|
41
|
+
: _this.NumAuto.getNum;
|
|
42
|
+
return [
|
|
43
|
+
currentAn[0],
|
|
44
|
+
currentAn[1],
|
|
45
|
+
fn(currentAn[1], currentAn[2]),
|
|
46
|
+
currentAn[2]
|
|
47
|
+
];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
var variables = OutputParser_1.getRelatedVariablesValues(this.id, this.index, outputReference.variables, this.ovc, this.references);
|
|
51
|
+
var output = OutputParser_1.parseOutputWithVariables(option.meta.output, variables, autonums);
|
|
52
|
+
this.outputs.push(output);
|
|
53
|
+
}
|
|
54
|
+
this.renderChildren();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
OptionRender.prototype.renderChildren = function () {
|
|
58
|
+
var _this = this;
|
|
59
|
+
var option = this.references.options[this.id];
|
|
60
|
+
option.options.forEach(function (optionId) {
|
|
61
|
+
_this.outputs = __spreadArrays(_this.outputs, new OptionRender({
|
|
62
|
+
references: _this.references,
|
|
63
|
+
id: optionId,
|
|
64
|
+
ovc: _this.ovc,
|
|
65
|
+
index: _this.index,
|
|
66
|
+
conditions: _this.conditions,
|
|
67
|
+
numauto: _this.NumAuto
|
|
68
|
+
}).getOutputs());
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
return OptionRender;
|
|
72
|
+
}());
|
|
73
|
+
exports.default = OptionRender;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import OVC_TYPE from "./ovc.type";
|
|
3
|
+
declare type relVarsValsT = Record<string, string | number>;
|
|
4
|
+
declare type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT;
|
|
5
|
+
export declare const getRelatedVariablesValues: getRelatedVarsT;
|
|
6
|
+
declare type autonumsType = [string, string, number, string | null][];
|
|
7
|
+
declare type parseOutputT = (output: string, variables: relVarsValsT, autonums: autonumsType) => string;
|
|
8
|
+
export declare const parseOutputWithVariables: parseOutputT;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
|
|
4
|
+
var variablesValues = {};
|
|
5
|
+
variables.forEach(function (currentVariableId) {
|
|
6
|
+
var value = ovc.variables[currentVariableId] || [""];
|
|
7
|
+
var variableParents = references.relations.variables[currentVariableId].parents;
|
|
8
|
+
if (variableParents === undefined)
|
|
9
|
+
throw new Error("Variable " + currentVariableId + " parents object does not exist");
|
|
10
|
+
var rootVariableParentId = variableParents[variableParents.length - 1];
|
|
11
|
+
var rootVariableParentRelations = references.relations.options[rootVariableParentId];
|
|
12
|
+
if (rootVariableParentRelations === undefined)
|
|
13
|
+
throw new Error("Option " + rootVariableParentId + " does not exist");
|
|
14
|
+
if (typeof variableParents === "undefined")
|
|
15
|
+
return;
|
|
16
|
+
if (rootVariableParentRelations.children.options.includes(optionId) ||
|
|
17
|
+
rootVariableParentRelations.dependants.includes(optionId) ||
|
|
18
|
+
optionId === rootVariableParentId)
|
|
19
|
+
value = [value[index]];
|
|
20
|
+
var cleanValues = value.map(function (currentValue) {
|
|
21
|
+
if (typeof currentValue === "number")
|
|
22
|
+
return currentValue.toString();
|
|
23
|
+
if (typeof currentValue === "string")
|
|
24
|
+
return currentValue;
|
|
25
|
+
return "";
|
|
26
|
+
});
|
|
27
|
+
variablesValues[currentVariableId] =
|
|
28
|
+
cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(", ");
|
|
29
|
+
});
|
|
30
|
+
return variablesValues;
|
|
31
|
+
};
|
|
32
|
+
exports.parseOutputWithVariables = function (output, variables, autonums) {
|
|
33
|
+
var parsedOutput = "" + output;
|
|
34
|
+
Object.keys(variables).forEach(function (variableId) {
|
|
35
|
+
var value = variables[variableId].toString();
|
|
36
|
+
if (value.trim().length === 0) {
|
|
37
|
+
value = new Array(16).join("_");
|
|
38
|
+
}
|
|
39
|
+
parsedOutput = parsedOutput.replace(new RegExp("\\[var:" + variableId + "\\]", "g"), value);
|
|
40
|
+
});
|
|
41
|
+
parsedOutput = parsedOutput.replace("[[PAGE_BREAK]]", '<p class="pagebreak"><!-- pagebreak --></p>');
|
|
42
|
+
autonums.forEach(function (currentAn) {
|
|
43
|
+
if (currentAn[3] === null)
|
|
44
|
+
parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "]", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
|
|
45
|
+
else
|
|
46
|
+
parsedOutput = parsedOutput.replace("[" + currentAn[0] + ":" + currentAn[1] + "](" + currentAn[3] + ")", "<span class=\"" + currentAn[0] + "\">" + currentAn[2] + "</span>");
|
|
47
|
+
});
|
|
48
|
+
return parsedOutput;
|
|
49
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ModelV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import OVC_TYPE from "./ovc.type";
|
|
3
|
+
declare class Prerender {
|
|
4
|
+
private model;
|
|
5
|
+
private references;
|
|
6
|
+
private ovc;
|
|
7
|
+
private conditions;
|
|
8
|
+
private documentRender;
|
|
9
|
+
private NumAuto;
|
|
10
|
+
private documentsIndex;
|
|
11
|
+
private renderedDocuments;
|
|
12
|
+
constructor(model: ModelV3, ovc: OVC_TYPE);
|
|
13
|
+
getDocumentsIndex(): Record<string, {
|
|
14
|
+
name: string;
|
|
15
|
+
pdf: boolean;
|
|
16
|
+
docx: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
private generateDocumentNamesHash;
|
|
19
|
+
private generateAllDocuments;
|
|
20
|
+
getDocument(documentNameHash: string): string;
|
|
21
|
+
}
|
|
22
|
+
export default Prerender;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var referencesparser_1 = require("@legalplace/referencesparser");
|
|
7
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
var DocumentRender_1 = __importDefault(require("./DocumentRender"));
|
|
9
|
+
var ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
|
|
10
|
+
var NumAuto_1 = __importDefault(require("./NumAuto"));
|
|
11
|
+
var Prerender = (function () {
|
|
12
|
+
function Prerender(model, ovc) {
|
|
13
|
+
this.documentsIndex = {};
|
|
14
|
+
this.renderedDocuments = {};
|
|
15
|
+
this.model = model;
|
|
16
|
+
this.ovc = ovc;
|
|
17
|
+
this.NumAuto = new NumAuto_1.default();
|
|
18
|
+
this.references = new referencesparser_1.ReferencesParser(model).getReferences();
|
|
19
|
+
this.conditions = new ConditionsRunner_1.default(this.references, this.ovc);
|
|
20
|
+
this.documentRender = new DocumentRender_1.default(this.references, this.conditions, this.ovc, this.NumAuto);
|
|
21
|
+
this.generateDocumentNamesHash();
|
|
22
|
+
this.generateAllDocuments();
|
|
23
|
+
}
|
|
24
|
+
Prerender.prototype.getDocumentsIndex = function () {
|
|
25
|
+
return this.documentsIndex;
|
|
26
|
+
};
|
|
27
|
+
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
28
|
+
var _this = this;
|
|
29
|
+
Object.keys(this.model.documents).forEach(function (documentName) {
|
|
30
|
+
var conditionObject = _this.references.conditions.documents[documentName];
|
|
31
|
+
var condition = conditionObject === undefined
|
|
32
|
+
? true
|
|
33
|
+
: _this.conditions.executeCondition(conditionObject, 0, 0, "documents");
|
|
34
|
+
if (condition === true) {
|
|
35
|
+
var hash = crypto_1.default
|
|
36
|
+
.createHash("sha1")
|
|
37
|
+
.update(documentName)
|
|
38
|
+
.digest("hex");
|
|
39
|
+
_this.documentsIndex[hash] = {
|
|
40
|
+
name: documentName,
|
|
41
|
+
pdf: true,
|
|
42
|
+
docx: true
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
Prerender.prototype.generateAllDocuments = function () {
|
|
48
|
+
var _this = this;
|
|
49
|
+
Object.keys(this.documentsIndex).forEach(function (documentNameHash) {
|
|
50
|
+
_this.renderedDocuments[documentNameHash] = _this.documentRender.renderDocument(_this.documentsIndex[documentNameHash].name);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
Prerender.prototype.getDocument = function (documentNameHash) {
|
|
54
|
+
return this.renderedDocuments[documentNameHash];
|
|
55
|
+
};
|
|
56
|
+
return Prerender;
|
|
57
|
+
}());
|
|
58
|
+
exports.default = Prerender;
|