@legalplace/prerenderx 2.3.53 → 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.
@@ -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
- if (typeof childId === 'string' && childId.trim().length === 0) {
20
- if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
21
- inputs.options[id] = new Array(occurences_1).fill(false);
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, childId)) {
26
- inputs.options[childId] = new Array(occurences_1).fill(false);
49
+ if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
50
+ inputs.options[sanitizedId] = new Array(occurences_1).fill(false);
27
51
  }
28
- inputs.options[childId][index] = true;
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' && currentOption.trim().length === 0)
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();
@@ -6,7 +6,6 @@ declare type DocumentOutputIndex = {
6
6
  slug: string;
7
7
  pdf: boolean;
8
8
  docx: boolean;
9
- displayed: boolean;
10
9
  };
11
10
  declare type DocumentPdfFormIndex = {
12
11
  name: string;
@@ -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);
@@ -36,7 +38,7 @@ var Prerender = (function () {
36
38
  Prerender.prototype.generateDocumentNamesHash = function () {
37
39
  var _this = this;
38
40
  Object.keys(this.model.documents).forEach(function (documentName) {
39
- var _a, _b, _c;
41
+ var _a, _b;
40
42
  var document = _this.model.documents[documentName];
41
43
  var documentParams = _this.model.documents[documentName].params;
42
44
  var conditionObject = _this.references.conditions.documents[documentName];
@@ -63,8 +65,7 @@ var Prerender = (function () {
63
65
  name: document.name,
64
66
  slug: documentName,
65
67
  pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) === undefined ? true : documentParams.formats.pdf,
66
- docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) === undefined ? true : documentParams.formats.docx,
67
- displayed: ((_c = documentParams === null || documentParams === void 0 ? void 0 : documentParams.visibility) === null || _c === void 0 ? void 0 : _c.displayBo) === true ? true : false
68
+ docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) === undefined ? true : documentParams.formats.docx
68
69
  };
69
70
  }
70
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "2.3.53",
3
+ "version": "2.3.55",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -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(ovc: OldOVC) {
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
- if (typeof ovc !== 'object') return inputs
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
- if (typeof childId === 'string' && childId.trim().length === 0) {
34
- // Creating input if it doesn't exist
35
- if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
36
- inputs.options[id] = new Array(occurences).fill(false)
37
- }
38
- return
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 (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
43
- inputs.options[childId] = new Array(occurences).fill(false)
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[childId][index] = true
48
- })
84
+ inputs.options[sanitizedId][index] = true;
85
+ });
49
86
  } else {
50
- if (typeof currentOption === 'string' && currentOption.trim().length === 0) return
51
- inputs.options[currentOption] = [true]
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 variables
57
- if (typeof ovc.v === 'object') {
58
- Object.keys(ovc.v).forEach(id => {
59
- const currentVariable = ovc.v[id]
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(currentVariable)) {
63
- inputs.variables[id] = currentVariable
103
+ if (Array.isArray(currentCheckbox)) {
104
+ inputs.options[id] = currentCheckbox;
64
105
  } else {
65
- inputs.variables[id] = [currentVariable]
106
+ inputs.options[id] = [currentCheckbox];
66
107
  }
67
- })
108
+ });
68
109
  }
69
110
 
70
- // Reading checkboxes
71
- if (typeof ovc.c === 'object') {
72
- Object.keys(ovc.c).forEach(id => {
73
- const currentCheckbox = ovc.c[id]
74
- if (typeof id === 'string' && id.trim().length === 0) return
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(currentCheckbox)) {
77
- inputs.options[id] = currentCheckbox
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.options[id] = [currentCheckbox]
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()
@@ -14,7 +14,6 @@ type DocumentOutputIndex = {
14
14
  slug: string
15
15
  pdf: boolean
16
16
  docx: boolean
17
- displayed: boolean
18
17
  }
19
18
  type DocumentPdfFormIndex = {
20
19
  name: string
@@ -57,15 +56,17 @@ class Prerender {
57
56
  constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC) {
58
57
  this.model = model
59
58
 
60
- // Converting OVC if needed
61
- this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc) : ovc
62
-
63
59
  // Initiating num auto
64
60
  this.NumAuto = new NumAuto()
65
61
 
66
62
  // Parsing references
67
63
  this.references = new ReferencesParser(model).getReferences()
68
64
 
65
+ // Converting OVC if needed
66
+ this.ovc = OvcConverter.isOvc(ovc)
67
+ ? OvcConverter.convertToOptionsVariables(ovc, this.references)
68
+ : ovc
69
+
69
70
  // Initiating inputs
70
71
  const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
71
72
 
@@ -122,8 +123,7 @@ class Prerender {
122
123
  name: document.name,
123
124
  slug: documentName,
124
125
  pdf: documentParams?.formats?.pdf === undefined ? true : documentParams.formats.pdf,
125
- docx: documentParams?.formats?.docx === undefined ? true : documentParams.formats.docx,
126
- displayed: documentParams?.visibility?.displayBo === true ? true : false
126
+ docx: documentParams?.formats?.docx === undefined ? true : documentParams.formats.docx
127
127
  }
128
128
  }
129
129
  }