@legalplace/prerenderx 2.3.54 → 2.3.55
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/OvcConverter.d.ts +3 -1
- package/dist/libs/OvcConverter.js +68 -20
- package/dist/libs/Prerender.js +3 -1
- package/package.json +1 -1
- package/src/libs/OvcConverter.ts +117 -36
- package/src/libs/Prerender.ts +5 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import OVC_TYPE from './ovc.type';
|
|
2
|
+
import { Types } from '@legalplace/referencesparser';
|
|
2
3
|
export interface OldOVC {
|
|
3
4
|
o: {
|
|
4
5
|
[k: string]: string | number | (string | number)[];
|
|
@@ -11,9 +12,10 @@ export interface OldOVC {
|
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
declare class OvcConverter {
|
|
14
|
-
convertToOptionsVariables(ovc: OldOVC): OVC_TYPE;
|
|
15
|
+
convertToOptionsVariables(ovc: OldOVC, references: Types.ReferencesType): OVC_TYPE;
|
|
15
16
|
isOvc(_obj: OVC_TYPE | OldOVC): _obj is OldOVC;
|
|
16
17
|
isOptionsVariables(_obj: OVC_TYPE | OldOVC): boolean;
|
|
18
|
+
private pushStaticChildren;
|
|
17
19
|
}
|
|
18
20
|
declare const _default: OvcConverter;
|
|
19
21
|
export default _default;
|
|
@@ -1,9 +1,28 @@
|
|
|
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
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
14
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
15
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
16
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
17
|
+
r[k] = a[j];
|
|
18
|
+
return r;
|
|
19
|
+
};
|
|
2
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
21
|
var OvcConverter = (function () {
|
|
4
22
|
function OvcConverter() {
|
|
5
23
|
}
|
|
6
|
-
OvcConverter.prototype.convertToOptionsVariables = function (ovc) {
|
|
24
|
+
OvcConverter.prototype.convertToOptionsVariables = function (ovc, references) {
|
|
25
|
+
var _this = this;
|
|
7
26
|
var inputs = {
|
|
8
27
|
options: {},
|
|
9
28
|
variables: {}
|
|
@@ -15,37 +34,33 @@ var OvcConverter = (function () {
|
|
|
15
34
|
var currentOption = ovc.o[id];
|
|
16
35
|
if (Array.isArray(currentOption)) {
|
|
17
36
|
var occurences_1 = currentOption.length;
|
|
37
|
+
inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, id, occurences_1, references));
|
|
18
38
|
currentOption.forEach(function (childId, index) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
39
|
+
var sanitizedId = typeof childId === 'string' && childId.split('_').length > 0
|
|
40
|
+
? childId.split('_')[0]
|
|
41
|
+
: childId;
|
|
42
|
+
if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
|
|
43
|
+
inputs.options[id] = new Array(occurences_1).fill(false);
|
|
44
|
+
}
|
|
45
|
+
if (typeof sanitizedId === 'string' &&
|
|
46
|
+
sanitizedId.trim().length === 0) {
|
|
23
47
|
return;
|
|
24
48
|
}
|
|
25
|
-
if (!Object.prototype.hasOwnProperty.call(inputs.options,
|
|
26
|
-
inputs.options[
|
|
49
|
+
if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
|
|
50
|
+
inputs.options[sanitizedId] = new Array(occurences_1).fill(false);
|
|
27
51
|
}
|
|
28
|
-
inputs.options
|
|
52
|
+
inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, sanitizedId, occurences_1, references));
|
|
53
|
+
inputs.options[sanitizedId][index] = true;
|
|
29
54
|
});
|
|
30
55
|
}
|
|
31
56
|
else {
|
|
32
|
-
if (typeof currentOption === 'string' &&
|
|
57
|
+
if (typeof currentOption === 'string' &&
|
|
58
|
+
currentOption.trim().length === 0)
|
|
33
59
|
return;
|
|
34
60
|
inputs.options[currentOption] = [true];
|
|
35
61
|
}
|
|
36
62
|
});
|
|
37
63
|
}
|
|
38
|
-
if (typeof ovc.v === 'object') {
|
|
39
|
-
Object.keys(ovc.v).forEach(function (id) {
|
|
40
|
-
var currentVariable = ovc.v[id];
|
|
41
|
-
if (Array.isArray(currentVariable)) {
|
|
42
|
-
inputs.variables[id] = currentVariable;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
inputs.variables[id] = [currentVariable];
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
64
|
if (typeof ovc.c === 'object') {
|
|
50
65
|
Object.keys(ovc.c).forEach(function (id) {
|
|
51
66
|
var currentCheckbox = ovc.c[id];
|
|
@@ -59,6 +74,25 @@ var OvcConverter = (function () {
|
|
|
59
74
|
}
|
|
60
75
|
});
|
|
61
76
|
}
|
|
77
|
+
if (typeof ovc.v === 'object') {
|
|
78
|
+
Object.keys(ovc.v).forEach(function (id) {
|
|
79
|
+
var currentVariable = ovc.v[id];
|
|
80
|
+
if (Array.isArray(currentVariable)) {
|
|
81
|
+
inputs.variables[id] = currentVariable;
|
|
82
|
+
var parentsTree = references.relations.variables[id].parents;
|
|
83
|
+
var parentOption = inputs.options["" + parentsTree[parentsTree.length - 1]];
|
|
84
|
+
if (Array.isArray(parentOption)) {
|
|
85
|
+
var occurences = parentOption.length;
|
|
86
|
+
if (currentVariable.length < occurences) {
|
|
87
|
+
inputs.variables[id] = __spreadArrays(currentVariable, Array(occurences - currentVariable.length).fill(''));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
inputs.variables[id] = [currentVariable];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
62
96
|
return inputs;
|
|
63
97
|
};
|
|
64
98
|
OvcConverter.prototype.isOvc = function (_obj) {
|
|
@@ -79,6 +113,20 @@ var OvcConverter = (function () {
|
|
|
79
113
|
.reduce(function (a, b) { return a + b; }, 0);
|
|
80
114
|
return foundKeys === 2;
|
|
81
115
|
};
|
|
116
|
+
OvcConverter.prototype.pushStaticChildren = function (inputOptions, id, occurences, references) {
|
|
117
|
+
var result = __assign({}, inputOptions);
|
|
118
|
+
var intId = typeof id === 'number' ? id : parseInt(id, 10);
|
|
119
|
+
var options = references.relations.options[intId].children.options;
|
|
120
|
+
var staticOptions = options.filter(function (childId) {
|
|
121
|
+
return references.options[childId].meta.type === 'static';
|
|
122
|
+
});
|
|
123
|
+
staticOptions.forEach(function (childId) {
|
|
124
|
+
if (!Object.prototype.hasOwnProperty.call(result, childId)) {
|
|
125
|
+
result[childId] = new Array(occurences).fill(false);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
82
130
|
return OvcConverter;
|
|
83
131
|
}());
|
|
84
132
|
exports.default = new OvcConverter();
|
package/dist/libs/Prerender.js
CHANGED
|
@@ -16,9 +16,11 @@ var Prerender = (function () {
|
|
|
16
16
|
this.documentsIndex = {};
|
|
17
17
|
this.renderedDocuments = {};
|
|
18
18
|
this.model = model;
|
|
19
|
-
this.ovc = OvcConverter_1.default.isOvc(ovc) ? OvcConverter_1.default.convertToOptionsVariables(ovc) : ovc;
|
|
20
19
|
this.NumAuto = new NumAuto_1.default();
|
|
21
20
|
this.references = new referencesparser_1.ReferencesParser(model).getReferences();
|
|
21
|
+
this.ovc = OvcConverter_1.default.isOvc(ovc)
|
|
22
|
+
? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
|
|
23
|
+
: ovc;
|
|
22
24
|
var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
|
|
23
25
|
this.conditions = new ConditionsRunner_1.default(this.references, inputs);
|
|
24
26
|
this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
|
package/package.json
CHANGED
package/src/libs/OvcConverter.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import OVC_TYPE from './ovc.type'
|
|
2
|
+
import { Types } from '@legalplace/referencesparser'
|
|
2
3
|
|
|
3
4
|
export interface OldOVC {
|
|
4
5
|
o: {
|
|
@@ -13,75 +14,128 @@ export interface OldOVC {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
class OvcConverter {
|
|
16
|
-
public convertToOptionsVariables(
|
|
17
|
+
public convertToOptionsVariables(
|
|
18
|
+
ovc: OldOVC,
|
|
19
|
+
references: Types.ReferencesType
|
|
20
|
+
) {
|
|
17
21
|
const inputs: OVC_TYPE = {
|
|
18
22
|
options: {},
|
|
19
23
|
variables: {}
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
if (typeof ovc !== 'object') return inputs;
|
|
23
27
|
|
|
24
28
|
// Reading options
|
|
25
29
|
if (typeof ovc.o === 'object') {
|
|
26
30
|
Object.keys(ovc.o).forEach(id => {
|
|
27
|
-
const currentOption = ovc.o[id]
|
|
31
|
+
const currentOption = ovc.o[id];
|
|
28
32
|
|
|
29
33
|
// If it's a multiple
|
|
30
34
|
if (Array.isArray(currentOption)) {
|
|
31
|
-
const occurences = currentOption.length
|
|
35
|
+
const occurences = currentOption.length;
|
|
36
|
+
// Adding static childrens
|
|
37
|
+
inputs.options = {
|
|
38
|
+
...inputs.options,
|
|
39
|
+
...this.pushStaticChildren(
|
|
40
|
+
inputs.options,
|
|
41
|
+
id,
|
|
42
|
+
occurences,
|
|
43
|
+
references
|
|
44
|
+
)
|
|
45
|
+
};
|
|
32
46
|
currentOption.forEach((childId, index) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
const sanitizedId =
|
|
48
|
+
typeof childId === 'string' && childId.split('_').length > 0
|
|
49
|
+
? childId.split('_')[0]
|
|
50
|
+
: childId;
|
|
51
|
+
|
|
52
|
+
// Making sure the input exist
|
|
53
|
+
if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
|
|
54
|
+
inputs.options[id] = new Array(occurences).fill(false);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Making sure the childId is not empty
|
|
58
|
+
if (
|
|
59
|
+
typeof sanitizedId === 'string' &&
|
|
60
|
+
sanitizedId.trim().length === 0
|
|
61
|
+
) {
|
|
62
|
+
return;
|
|
39
63
|
}
|
|
40
64
|
|
|
41
65
|
// Creating input if it doesn't exist
|
|
42
|
-
if (
|
|
43
|
-
inputs.options
|
|
66
|
+
if (
|
|
67
|
+
!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)
|
|
68
|
+
) {
|
|
69
|
+
inputs.options[sanitizedId] = new Array(occurences).fill(false);
|
|
44
70
|
}
|
|
45
71
|
|
|
72
|
+
// Adding static childrens
|
|
73
|
+
inputs.options = {
|
|
74
|
+
...inputs.options,
|
|
75
|
+
...this.pushStaticChildren(
|
|
76
|
+
inputs.options,
|
|
77
|
+
sanitizedId,
|
|
78
|
+
occurences,
|
|
79
|
+
references
|
|
80
|
+
)
|
|
81
|
+
};
|
|
82
|
+
|
|
46
83
|
// Setting current index to true
|
|
47
|
-
inputs.options[
|
|
48
|
-
})
|
|
84
|
+
inputs.options[sanitizedId][index] = true;
|
|
85
|
+
});
|
|
49
86
|
} else {
|
|
50
|
-
if (
|
|
51
|
-
|
|
87
|
+
if (
|
|
88
|
+
typeof currentOption === 'string' &&
|
|
89
|
+
currentOption.trim().length === 0
|
|
90
|
+
)
|
|
91
|
+
return;
|
|
92
|
+
inputs.options[currentOption] = [true];
|
|
52
93
|
}
|
|
53
|
-
})
|
|
94
|
+
});
|
|
54
95
|
}
|
|
55
96
|
|
|
56
|
-
// Reading
|
|
57
|
-
if (typeof ovc.
|
|
58
|
-
Object.keys(ovc.
|
|
59
|
-
const
|
|
60
|
-
|
|
97
|
+
// Reading checkboxes
|
|
98
|
+
if (typeof ovc.c === 'object') {
|
|
99
|
+
Object.keys(ovc.c).forEach(id => {
|
|
100
|
+
const currentCheckbox = ovc.c[id];
|
|
101
|
+
if (typeof id === 'string' && id.trim().length === 0) return;
|
|
61
102
|
// If it's a multiple
|
|
62
|
-
if (Array.isArray(
|
|
63
|
-
inputs.
|
|
103
|
+
if (Array.isArray(currentCheckbox)) {
|
|
104
|
+
inputs.options[id] = currentCheckbox;
|
|
64
105
|
} else {
|
|
65
|
-
inputs.
|
|
106
|
+
inputs.options[id] = [currentCheckbox];
|
|
66
107
|
}
|
|
67
|
-
})
|
|
108
|
+
});
|
|
68
109
|
}
|
|
69
110
|
|
|
70
|
-
// Reading
|
|
71
|
-
if (typeof ovc.
|
|
72
|
-
Object.keys(ovc.
|
|
73
|
-
const
|
|
74
|
-
|
|
111
|
+
// Reading variables
|
|
112
|
+
if (typeof ovc.v === 'object') {
|
|
113
|
+
Object.keys(ovc.v).forEach(id => {
|
|
114
|
+
const currentVariable = ovc.v[id];
|
|
115
|
+
|
|
75
116
|
// If it's a multiple
|
|
76
|
-
if (Array.isArray(
|
|
77
|
-
inputs.
|
|
117
|
+
if (Array.isArray(currentVariable)) {
|
|
118
|
+
inputs.variables[id] = currentVariable;
|
|
119
|
+
// Getting parentsTree & parent id
|
|
120
|
+
const parentsTree = references.relations.variables[id].parents;
|
|
121
|
+
const parentOption =
|
|
122
|
+
inputs.options[`${parentsTree[parentsTree.length - 1]}`];
|
|
123
|
+
if (Array.isArray(parentOption)) {
|
|
124
|
+
const occurences = parentOption.length;
|
|
125
|
+
if (currentVariable.length < occurences) {
|
|
126
|
+
inputs.variables[id] = [
|
|
127
|
+
...currentVariable,
|
|
128
|
+
...Array(occurences - currentVariable.length).fill('')
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
78
132
|
} else {
|
|
79
|
-
inputs.
|
|
133
|
+
inputs.variables[id] = [currentVariable];
|
|
80
134
|
}
|
|
81
|
-
})
|
|
135
|
+
});
|
|
82
136
|
}
|
|
83
137
|
|
|
84
|
-
return inputs
|
|
138
|
+
return inputs;
|
|
85
139
|
}
|
|
86
140
|
|
|
87
141
|
public isOvc(_obj: OVC_TYPE | OldOVC): _obj is OldOVC {
|
|
@@ -101,6 +155,33 @@ class OvcConverter {
|
|
|
101
155
|
.reduce((a, b) => a + b, 0)
|
|
102
156
|
return foundKeys === 2
|
|
103
157
|
}
|
|
158
|
+
|
|
159
|
+
private pushStaticChildren(
|
|
160
|
+
inputOptions: OVC_TYPE['options'],
|
|
161
|
+
id: number | string,
|
|
162
|
+
occurences: number,
|
|
163
|
+
references: Types.ReferencesType
|
|
164
|
+
) {
|
|
165
|
+
const result = { ...inputOptions };
|
|
166
|
+
const intId = typeof id === 'number' ? id : parseInt(id, 10);
|
|
167
|
+
|
|
168
|
+
// Getting children options and variables
|
|
169
|
+
const { options } = references.relations.options[intId].children;
|
|
170
|
+
|
|
171
|
+
// Getting static children
|
|
172
|
+
const staticOptions = options.filter(childId => {
|
|
173
|
+
return references.options[childId].meta.type === 'static';
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
staticOptions.forEach(childId => {
|
|
177
|
+
// Creating input if it doesn't exist
|
|
178
|
+
if (!Object.prototype.hasOwnProperty.call(result, childId)) {
|
|
179
|
+
result[childId] = new Array(occurences).fill(false);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
104
185
|
}
|
|
105
186
|
|
|
106
187
|
export default new OvcConverter()
|
package/src/libs/Prerender.ts
CHANGED
|
@@ -56,15 +56,17 @@ class Prerender {
|
|
|
56
56
|
constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC) {
|
|
57
57
|
this.model = model
|
|
58
58
|
|
|
59
|
-
// Converting OVC if needed
|
|
60
|
-
this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc) : ovc
|
|
61
|
-
|
|
62
59
|
// Initiating num auto
|
|
63
60
|
this.NumAuto = new NumAuto()
|
|
64
61
|
|
|
65
62
|
// Parsing references
|
|
66
63
|
this.references = new ReferencesParser(model).getReferences()
|
|
67
64
|
|
|
65
|
+
// Converting OVC if needed
|
|
66
|
+
this.ovc = OvcConverter.isOvc(ovc)
|
|
67
|
+
? OvcConverter.convertToOptionsVariables(ovc, this.references)
|
|
68
|
+
: ovc
|
|
69
|
+
|
|
68
70
|
// Initiating inputs
|
|
69
71
|
const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
|
|
70
72
|
|