@legalplace/prerenderx 2.1.0 → 2.1.2

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.
@@ -0,0 +1,21 @@
1
+ import { Types } from "@legalplace/referencesparser";
2
+ declare type References = Types.ReferencesType;
3
+ declare type OVC_TYPE = {
4
+ options: {
5
+ [key: string]: boolean[];
6
+ };
7
+ variables: {
8
+ [key: string]: (number | string)[];
9
+ };
10
+ };
11
+ declare class IntputsInitiator {
12
+ private inputs;
13
+ private references;
14
+ private ovc;
15
+ constructor(references: References, ovc: OVC_TYPE | null);
16
+ getInputs(): OVC_TYPE;
17
+ private setMultiples;
18
+ private initOptionsInputs;
19
+ private initVariablesInputs;
20
+ }
21
+ export default IntputsInitiator;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var IntputsInitiator = (function () {
4
+ function IntputsInitiator(references, ovc) {
5
+ this.inputs = {
6
+ options: {},
7
+ variables: {}
8
+ };
9
+ this.references = references;
10
+ this.ovc = ovc;
11
+ this.setMultiples();
12
+ this.initOptionsInputs();
13
+ this.initVariablesInputs();
14
+ }
15
+ IntputsInitiator.prototype.getInputs = function () {
16
+ return this.inputs;
17
+ };
18
+ IntputsInitiator.prototype.setMultiples = function () {
19
+ var _this = this;
20
+ if (this.ovc === null)
21
+ return;
22
+ Object.keys(this.ovc.options).forEach(function (id) {
23
+ if (_this.ovc === null)
24
+ return;
25
+ var inputs = _this.ovc.options[id];
26
+ if (inputs.length > 1) {
27
+ var parentsTree = _this.references.relations.options[id].parents;
28
+ var rootOptionId = parentsTree.length > 0 ? parentsTree[parentsTree.length - 1] : id;
29
+ if (!_this.ovc.options[rootOptionId]) {
30
+ var rootReference = _this.references.options[rootOptionId];
31
+ if (rootReference.meta.type === "static") {
32
+ _this.ovc.options[rootOptionId] = new Array(inputs.length).fill(true);
33
+ }
34
+ }
35
+ }
36
+ });
37
+ };
38
+ IntputsInitiator.prototype.initOptionsInputs = function () {
39
+ var optionsIds = Object.keys(this.references.options);
40
+ for (var i = 0; i < optionsIds.length; i += 1) {
41
+ var optionId = optionsIds[i];
42
+ var option = this.references.options[optionId];
43
+ var values = [false];
44
+ if (this.ovc &&
45
+ Object.prototype.hasOwnProperty.call(this.ovc.options, optionId)) {
46
+ values = this.ovc.options[optionId];
47
+ }
48
+ else if ([
49
+ "static",
50
+ "hidden",
51
+ "brut-text",
52
+ "repeated",
53
+ "box",
54
+ "separator"
55
+ ].includes(option.meta.type)) {
56
+ values = [true];
57
+ }
58
+ this.inputs.options[optionId] = values;
59
+ }
60
+ };
61
+ IntputsInitiator.prototype.initVariablesInputs = function () {
62
+ var variablesIds = Object.keys(this.references.variables);
63
+ for (var i = 0; i < variablesIds.length; i += 1) {
64
+ var variableId = variablesIds[i];
65
+ var values = [""];
66
+ if (this.ovc &&
67
+ Object.prototype.hasOwnProperty.call(this.ovc.variables, variableId)) {
68
+ values = this.ovc.variables[variableId];
69
+ }
70
+ else {
71
+ var defaultValue = "";
72
+ var prefillings = this.references.variables[variableId].prefillings;
73
+ if (prefillings &&
74
+ Array.isArray(prefillings) &&
75
+ prefillings.length > 0) {
76
+ var noConditionsPrefills = prefillings.filter(function (prefill) {
77
+ return typeof prefill.conditions === "undefined" ||
78
+ Object.keys(prefill.conditions).length === 0;
79
+ });
80
+ defaultValue =
81
+ noConditionsPrefills.length > 0
82
+ ? noConditionsPrefills[0].value
83
+ : "";
84
+ }
85
+ values = [defaultValue];
86
+ }
87
+ this.inputs.variables[variableId] = values;
88
+ }
89
+ };
90
+ return IntputsInitiator;
91
+ }());
92
+ exports.default = IntputsInitiator;
@@ -9,6 +9,7 @@ var DocumentRender_1 = __importDefault(require("./DocumentRender"));
9
9
  var ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
10
10
  var OvcConverter_1 = __importDefault(require("./OvcConverter"));
11
11
  var NumAuto_1 = __importDefault(require("./NumAuto"));
12
+ var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
12
13
  var Prerender = (function () {
13
14
  function Prerender(model, ovc) {
14
15
  this.documentsIndex = {};
@@ -19,8 +20,9 @@ var Prerender = (function () {
19
20
  : ovc;
20
21
  this.NumAuto = new NumAuto_1.default();
21
22
  this.references = new referencesparser_1.ReferencesParser(model).getReferences();
22
- this.conditions = new ConditionsRunner_1.default(this.references, this.ovc);
23
- this.documentRender = new DocumentRender_1.default(this.references, this.conditions, this.ovc, this.NumAuto);
23
+ var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
24
+ this.conditions = new ConditionsRunner_1.default(this.references, inputs);
25
+ this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
24
26
  this.generateDocumentNamesHash();
25
27
  this.generateAllDocuments();
26
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -15,7 +15,7 @@
15
15
  "crypto": "^1.0.1",
16
16
  "@legalplace/lplogic": "^2.0.0",
17
17
  "@legalplace/models-v3-types": "^3.1.1",
18
- "@legalplace/referencesparser": "^1.1.0"
18
+ "@legalplace/referencesparser": "^1.2.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@babel/core": "^7.7.2",
@@ -0,0 +1,146 @@
1
+ import { Types } from "@legalplace/referencesparser";
2
+
3
+ type References = Types.ReferencesType;
4
+
5
+ type OVC_TYPE = {
6
+ options: {
7
+ [key: string]: boolean[];
8
+ };
9
+ variables: {
10
+ [key: string]: (number | string)[];
11
+ };
12
+ };
13
+
14
+ class IntputsInitiator {
15
+ private inputs: OVC_TYPE = {
16
+ options: {},
17
+ variables: {}
18
+ };
19
+
20
+ private references: References;
21
+
22
+ private ovc: OVC_TYPE | null;
23
+
24
+ /**
25
+ * InitalConditions Constructor
26
+ * @param references References object
27
+ */
28
+ constructor(references: References, ovc: OVC_TYPE | null) {
29
+ this.references = references;
30
+ this.ovc = ovc;
31
+
32
+ // Setting multiples
33
+ this.setMultiples();
34
+
35
+ // Initiating inputs
36
+ this.initOptionsInputs();
37
+ this.initVariablesInputs();
38
+ }
39
+
40
+ public getInputs() {
41
+ return this.inputs;
42
+ }
43
+
44
+ private setMultiples() {
45
+ if (this.ovc === null) return;
46
+ Object.keys(this.ovc.options).forEach(id => {
47
+ if (this.ovc === null) return;
48
+ const inputs = this.ovc.options[id];
49
+
50
+ if (inputs.length > 1) {
51
+ // Getting parents
52
+ const parentsTree = this.references.relations.options[id].parents;
53
+
54
+ // root parent
55
+ const rootOptionId =
56
+ parentsTree.length > 0 ? parentsTree[parentsTree.length - 1] : id;
57
+
58
+ if (!this.ovc.options[rootOptionId]) {
59
+ // root Option reference
60
+ const rootReference = this.references.options[rootOptionId];
61
+ if (rootReference.meta.type === "static") {
62
+ this.ovc.options[rootOptionId] = new Array(inputs.length).fill(
63
+ true
64
+ );
65
+ }
66
+ }
67
+ }
68
+ });
69
+ }
70
+
71
+ /**
72
+ * Initates options inputs
73
+ */
74
+ private initOptionsInputs() {
75
+ // Options
76
+ const optionsIds = Object.keys(this.references.options);
77
+ for (let i = 0; i < optionsIds.length; i += 1) {
78
+ const optionId = optionsIds[i];
79
+ const option = this.references.options[optionId];
80
+
81
+ let values = [false];
82
+ if (
83
+ this.ovc &&
84
+ Object.prototype.hasOwnProperty.call(this.ovc.options, optionId)
85
+ ) {
86
+ values = this.ovc.options[optionId];
87
+ } else if (
88
+ [
89
+ "static",
90
+ "hidden",
91
+ "brut-text",
92
+ "repeated",
93
+ "box",
94
+ "separator"
95
+ ].includes(option.meta.type)
96
+ ) {
97
+ values = [true];
98
+ }
99
+
100
+ this.inputs.options[optionId] = values;
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Initates variables inputs
106
+ */
107
+ private initVariablesInputs() {
108
+ const variablesIds = Object.keys(this.references.variables);
109
+ for (let i = 0; i < variablesIds.length; i += 1) {
110
+ const variableId = variablesIds[i];
111
+
112
+ let values: (string | number)[] = [""];
113
+ if (
114
+ this.ovc &&
115
+ Object.prototype.hasOwnProperty.call(this.ovc.variables, variableId)
116
+ ) {
117
+ values = this.ovc.variables[variableId];
118
+ } else {
119
+ let defaultValue = "";
120
+
121
+ // Checking for first prefill without condition
122
+ const { prefillings } = this.references.variables[variableId];
123
+ if (
124
+ prefillings &&
125
+ Array.isArray(prefillings) &&
126
+ prefillings.length > 0
127
+ ) {
128
+ const noConditionsPrefills = prefillings.filter(
129
+ prefill =>
130
+ typeof prefill.conditions === "undefined" ||
131
+ Object.keys(prefill.conditions).length === 0
132
+ );
133
+ defaultValue =
134
+ noConditionsPrefills.length > 0
135
+ ? noConditionsPrefills[0].value
136
+ : "";
137
+ }
138
+ values = [defaultValue];
139
+ }
140
+
141
+ this.inputs.variables[variableId] = values;
142
+ }
143
+ }
144
+ }
145
+
146
+ export default IntputsInitiator;
@@ -6,6 +6,7 @@ import ConditionsRunner from "./ConditionsRunner";
6
6
  import OVC_TYPE from "./ovc.type";
7
7
  import OvcConverter, { OldOVC } from "./OvcConverter";
8
8
  import NumAuto from "./NumAuto";
9
+ import IntputsInitiator from "./InputsInitiator";
9
10
 
10
11
  class Prerender {
11
12
  private model: ModelV3;
@@ -45,14 +46,17 @@ class Prerender {
45
46
  // Parsing references
46
47
  this.references = new ReferencesParser(model).getReferences();
47
48
 
49
+ // Initiating inputs
50
+ const inputs = new IntputsInitiator(this.references, this.ovc).getInputs();
51
+
48
52
  // Initiating ConditionsRunner
49
- this.conditions = new ConditionsRunner(this.references, this.ovc);
53
+ this.conditions = new ConditionsRunner(this.references, inputs);
50
54
 
51
55
  // Rendering documents
52
56
  this.documentRender = new DocumentRender(
53
57
  this.references,
54
58
  this.conditions,
55
- this.ovc,
59
+ inputs,
56
60
  this.NumAuto
57
61
  );
58
62
 
package/yarn.lock CHANGED
@@ -364,10 +364,10 @@
364
364
  resolved "https://registry.yarnpkg.com/@legalplace/models-v3-types/-/models-v3-types-3.1.1.tgz#433a2f6d93a99e9a61d040457627772a2167a7ee"
365
365
  integrity sha512-+c0EFH4bBQw7xB239PLtn1p83t4R1ygWrZwwuvFJnRGWuVle0w/RFkQ+gfwQZApvSx06U/vhNu8doRn/PVd3KQ==
366
366
 
367
- "@legalplace/referencesparser@^1.1.0":
368
- version "1.1.0"
369
- resolved "https://registry.yarnpkg.com/@legalplace/referencesparser/-/referencesparser-1.1.0.tgz#f9393bda190a8f11e168833ca3b235e046e996d5"
370
- integrity sha512-VSOBzzhilab1tWZzjs2M+3pJuZ/P/GB8O7slaMebHxJ3JyQ3bNnqh/HoUbIJ7al7m0DjdcVJ11vEVIFC5ciBYA==
367
+ "@legalplace/referencesparser@^1.2.0":
368
+ version "1.2.0"
369
+ resolved "https://registry.yarnpkg.com/@legalplace/referencesparser/-/referencesparser-1.2.0.tgz#4add3afb144a8b8af27abae486d6f5cba1ec31e7"
370
+ integrity sha512-5S32TzwmslgQ4Pqh2dkI3JmAmzJRTy+f0FNaxZ+upl0oTLSAS1JhhMqmFNCdSKnCsUR+Ub+TbxxkrEby9PgWAA==
371
371
 
372
372
  "@types/babel__core@^7.1.0":
373
373
  version "7.1.3"