@legalplace/prerenderx 3.2.1 → 3.3.1-staging.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.
Files changed (39) hide show
  1. package/.eslintrc +3 -47
  2. package/CHANGELOG.md +21 -0
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +1 -1
  5. package/dist/libs/DocumentRender.d.ts +4 -4
  6. package/dist/libs/DocumentRender.js +2 -2
  7. package/dist/libs/FillPdfForm.d.ts +1 -1
  8. package/dist/libs/FillPdfForm.js +30 -24
  9. package/dist/libs/InputsInitiator.d.ts +1 -1
  10. package/dist/libs/InputsInitiator.js +35 -11
  11. package/dist/libs/NumAuto.js +1 -1
  12. package/dist/libs/OptionRender.d.ts +4 -4
  13. package/dist/libs/OptionRender.js +30 -18
  14. package/dist/libs/OutputParser.d.ts +2 -2
  15. package/dist/libs/OutputParser.js +39 -25
  16. package/dist/libs/Prerender.d.ts +8 -8
  17. package/dist/libs/Prerender.js +29 -22
  18. package/dist/libs/SectionRender.d.ts +4 -4
  19. package/dist/libs/SectionRender.js +22 -13
  20. package/dist/libs/misc/FillPdfFormBase.d.ts +3 -3
  21. package/dist/libs/misc/FillPdfFormBase.js +25 -17
  22. package/package.json +13 -18
  23. package/src/index.ts +3 -3
  24. package/src/libs/DocumentRender.ts +27 -22
  25. package/src/libs/FillPdfForm.ts +72 -59
  26. package/src/libs/InputsInitiator.ts +91 -53
  27. package/src/libs/NumAuto.ts +16 -14
  28. package/src/libs/OptionRender.ts +85 -45
  29. package/src/libs/OutputParser.ts +128 -57
  30. package/src/libs/Prerender.ts +119 -75
  31. package/src/libs/SectionRender.ts +57 -38
  32. package/src/libs/misc/FillPdfFormBase.ts +71 -39
  33. package/src/types/types.ts +17 -14
  34. package/tsconfig.json +3 -1
  35. package/.gitlab-ci.yml +0 -43
  36. package/.prettierrc.js +0 -10
  37. package/.vscode/settings.json +0 -17
  38. package/.vscode/tasks.json +0 -24
  39. package/tsconfig.eslint.json +0 -12
@@ -1,14 +1,13 @@
1
- import { Types } from '@legalplace/referencesparser'
2
- import InputsType from '@legalplace/types/dist/inputs'
3
-
1
+ import type { Types } from "@legalplace/referencesparser";
2
+ import type InputsType from "@legalplace/types/dist/inputs";
4
3
 
5
4
  /**
6
5
  * Parses number to correct french number format ("," instead of ".")
7
6
  */
8
7
  const frenchNumber = (value: string | number) => {
9
- let result = typeof value === 'number' ? value.toString() : value;
8
+ let result = typeof value === "number" ? value.toString() : value;
10
9
  if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
11
- result = result.trim().replace('.', ',');
10
+ result = result.trim().replace(".", ",");
12
11
  return result;
13
12
  };
14
13
 
@@ -18,43 +17,67 @@ const frenchNumber = (value: string | number) => {
18
17
  * @param index Occurency index
19
18
  * @param variables Variables ids list
20
19
  */
21
- type relVarsValsT = Record<string, string | number>
22
- type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: InputsType, references: Types.ReferencesType) => relVarsValsT
23
- export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, variables, ovc, references) => {
20
+ type relVarsValsT = Record<string, string | number>;
21
+ type getRelatedVarsT = (
22
+ optionId: number,
23
+ index: number,
24
+ variables: number[],
25
+ ovc: InputsType,
26
+ references: Types.ReferencesType
27
+ ) => relVarsValsT;
28
+ export const getRelatedVariablesValues: getRelatedVarsT = (
29
+ optionId,
30
+ index,
31
+ variables,
32
+ ovc,
33
+ references
34
+ ) => {
24
35
  // Getting variables values
25
- const variablesValues: Record<string, string> = {}
26
- variables.forEach(currentVariableId => {
36
+ const variablesValues: Record<string, string> = {};
37
+ variables.forEach((currentVariableId) => {
27
38
  // Getting option value
28
- let value = ovc.variables[currentVariableId] || ['']
29
- const variableParents = references.relations.variables[currentVariableId].parents
30
- if (variableParents === undefined) throw new Error(`Variable ${currentVariableId} parents object does not exist`)
31
- const rootVariableParentId = variableParents[variableParents.length - 1]
32
- const rootVariableParentRelations = references.relations.options[rootVariableParentId]
33
- if (rootVariableParentRelations === undefined) throw new Error(`Option ${rootVariableParentId} does not exist`)
34
-
35
- if (typeof variableParents === 'undefined') return
39
+ let value = ovc.variables[currentVariableId] || [""];
40
+ const variableParents =
41
+ references.relations.variables[currentVariableId].parents;
42
+ if (variableParents === undefined)
43
+ throw new Error(
44
+ `Variable ${currentVariableId} parents object does not exist`
45
+ );
46
+ const rootVariableParentId = variableParents[variableParents.length - 1];
47
+ const rootVariableParentRelations =
48
+ references.relations.options[rootVariableParentId];
49
+ if (rootVariableParentRelations === undefined)
50
+ throw new Error(`Option ${rootVariableParentId} does not exist`);
51
+
52
+ if (typeof variableParents === "undefined") return;
36
53
 
37
54
  // Getting rootOption parent
38
55
 
39
56
  // Checking if current option is related to the option that changed
40
- if (rootVariableParentRelations.children.options.includes(optionId) || rootVariableParentRelations.dependants.includes(optionId) || optionId === rootVariableParentId)
41
- value = [value[index]]
57
+ if (
58
+ rootVariableParentRelations.children.options.includes(optionId) ||
59
+ rootVariableParentRelations.dependants.includes(optionId) ||
60
+ optionId === rootVariableParentId
61
+ )
62
+ value = [value[index]];
42
63
 
43
64
  // Making sure all values are strings
44
- const cleanValues = value.map(currentValue => {
45
- if (['number', 'string'].includes(typeof currentValue)) return frenchNumber(currentValue)
46
- return ''
47
- })
65
+ const cleanValues = value.map((currentValue) => {
66
+ if (["number", "string"].includes(typeof currentValue))
67
+ return frenchNumber(currentValue);
68
+ return "";
69
+ });
48
70
 
49
71
  // Joining multiple variables if needed
50
- const currentVariableValue = cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(', ')
72
+ const currentVariableValue =
73
+ cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(", ");
51
74
 
52
75
  // Setting variable value
53
- variablesValues[currentVariableId] = currentVariableValue
54
- })
76
+ variablesValues[currentVariableId] = currentVariableValue;
77
+ });
55
78
 
56
- return variablesValues
57
- }
79
+ return variablesValues;
80
+ };
58
81
 
59
82
  /**
60
83
  * Parses output with variables
@@ -64,53 +87,101 @@ export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, vari
64
87
  * @param variables Variables values list
65
88
  * @param autonums Autonums values
66
89
  */
67
- type autonumsType = [string, string, number, string | null][]
68
- type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string
69
- export const parseOutputWithVariables: parseOutputT = (output, index, variables, autonums) => {
90
+ type autonumsType = [string, string, number, string | null][];
91
+ type parseOutputT = (
92
+ output: string,
93
+ index: number,
94
+ variables: relVarsValsT,
95
+ autonums: autonumsType
96
+ ) => string;
97
+ export const parseOutputWithVariables: parseOutputT = (
98
+ output,
99
+ index,
100
+ variables,
101
+ autonums
102
+ ) => {
70
103
  // Inserting values
71
- let parsedOutput = `${output}`
72
- Object.keys(variables).forEach(variableId => {
73
- let value: string = variables[variableId].toString()
104
+ let parsedOutput = `${output}`;
105
+ Object.keys(variables).forEach((variableId) => {
106
+ let value: string = variables[variableId].toString();
74
107
  if (value.trim().length === 0) {
75
- value = new Array(16).join('_')
108
+ value = new Array(16).join("_");
76
109
  }
77
110
 
78
111
  // Replacing linebreaks with br tags
79
- value = value.replace(/\n/g, '<br />')
80
- parsedOutput = parsedOutput.replace(new RegExp(`\\[var:${variableId}\\]`, 'g'), value)
81
- })
112
+ value = value.replace(/\n/g, "<br />");
113
+ parsedOutput = parsedOutput.replace(
114
+ new RegExp(`\\[var:${variableId}\\]`, "g"),
115
+ value
116
+ );
117
+ });
82
118
 
83
119
  // Inserting page breaks
84
- parsedOutput = parsedOutput.replace(/\[\[PAGE_BREAK\]\]/gi, '<div style="page-break-after:always"></div>')
120
+ parsedOutput = parsedOutput.replace(
121
+ /\[\[PAGE_BREAK\]\]/gi,
122
+ '<div style="page-break-after:always"></div>'
123
+ );
85
124
 
86
125
  // Cleaning BLURS
87
- parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, '')
126
+ parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, "");
88
127
 
89
128
  // Parsing Signatures
90
- parsedOutput = parsedOutput.replace(/\[signature:([0-9]+)\]/g, (v, signatureId) => `<span data-signature-id="${signatureId}" data-signer-index="${index}"></span>`)
129
+ parsedOutput = parsedOutput.replace(
130
+ /\[signature:([0-9]+)\]/g,
131
+ (v, signatureId) =>
132
+ `<span data-signature="signature" data-signature-id="${signatureId}" data-signer-index="${index}"></span>`
133
+ );
91
134
 
92
- // Inserting autonums
93
- autonums.forEach(currentAn => {
94
- if (currentAn[3] === null) parsedOutput = parsedOutput.replace(`[${currentAn[0]}:${currentAn[1]}]`, `<span class="${currentAn[0]}">${currentAn[2]}</span>`)
95
- else parsedOutput = parsedOutput.replace(`[${currentAn[0]}:${currentAn[1]}](${currentAn[3]})`, `<span class="${currentAn[0]}">${currentAn[2]}</span>`)
96
- })
135
+ // Signature date tag
136
+ parsedOutput = parsedOutput.replace(
137
+ /\[signature:date\]/g,
138
+ () => '<span date-signature="date"></span>'
139
+ );
140
+ parsedOutput = parsedOutput.replace(
141
+ /\[signature:date:([0-9]+)\]/g,
142
+ (v, signatureId) =>
143
+ `<span date-signature="date" data-signature-id="${signatureId}" data-signer-index="${index}"></span>`
144
+ );
97
145
 
98
- return parsedOutput
99
- }
146
+ // Obsolete signature date tag
147
+ parsedOutput = parsedOutput.replace(
148
+ /\[date\]/g,
149
+ () => '<span date-signature="date"></span>'
150
+ );
100
151
 
152
+ // Inserting autonums
153
+ autonums.forEach((currentAn) => {
154
+ if (currentAn[3] === null)
155
+ parsedOutput = parsedOutput.replace(
156
+ `[${currentAn[0]}:${currentAn[1]}]`,
157
+ `<span class="${currentAn[0]}">${currentAn[2]}</span>`
158
+ );
159
+ else
160
+ parsedOutput = parsedOutput.replace(
161
+ `[${currentAn[0]}:${currentAn[1]}](${currentAn[3]})`,
162
+ `<span class="${currentAn[0]}">${currentAn[2]}</span>`
163
+ );
164
+ });
101
165
 
166
+ return parsedOutput;
167
+ };
102
168
 
103
169
  /**
104
170
  * Parses document name with variables
105
171
  * @param text Document's name
106
172
  */
107
- type TParseDocumentNameWithVariables = (
108
- text: string,
109
- ovc: InputsType,
110
- references: Types.ReferencesType,
111
- fallback?: string
173
+ type TParseDocumentNameWithVariables = (
174
+ text: string,
175
+ ovc: InputsType,
176
+ references: Types.ReferencesType,
177
+ fallback?: string
112
178
  ) => string;
113
- export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (text, ovc, references, fallback) => {
179
+ export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
180
+ text,
181
+ ovc,
182
+ references,
183
+ fallback
184
+ ) => {
114
185
  /**
115
186
  * Variables
116
187
  */
@@ -139,7 +210,7 @@ export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
139
210
  // Getting values
140
211
  const variablesValues: Record<string, string> = {};
141
212
  variables.forEach((variableId) => {
142
- const value = ovc.variables[variableId]?.[0] || ''
213
+ const value = ovc.variables[variableId]?.[0] || "";
143
214
  variablesValues[variableId] = value.toString();
144
215
  });
145
216
 
@@ -150,7 +221,7 @@ export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
150
221
  if (value.trim().length === 0 && fallback) parsedText = fallback;
151
222
  if (parsedText === fallback && fallback) return;
152
223
  parsedText = parsedText.replace(
153
- new RegExp(`\\[var:${variableId}\\]`, 'gi'),
224
+ new RegExp(`\\[var:${variableId}\\]`, "gi"),
154
225
  value
155
226
  );
156
227
  });
@@ -1,149 +1,193 @@
1
- import { ModelV3 } from '@legalplace/models-v3-types'
2
- import { Types, ReferencesParser } from '@legalplace/referencesparser'
3
- import ConditionsRunner from '@legalplace/conditions-runner'
4
- import OvcConverter from '@legalplace/ovc-converter'
5
- import OvcType from '@legalplace/types/dist/ovc'
6
- import InputsType from '@legalplace/types/dist/inputs'
7
- import crypto from 'crypto'
8
- import DocumentRender from './DocumentRender'
9
- import NumAuto from './NumAuto'
10
- import IntputsInitiator from './InputsInitiator'
11
- import FillPdfForm from './FillPdfForm'
12
- import { parseDocumentNameWithVariables } from './OutputParser'
13
- import type { FDFType, DocumentIndex, DocumentOutputIndex, DocumentPdfFormIndex } from "../types/types"
1
+ import type { ModelV3 } from "@legalplace/models-v3-types";
2
+ import type { Types } from "@legalplace/referencesparser";
3
+ import { ReferencesParser } from "@legalplace/referencesparser";
4
+ import ConditionsRunner from "@legalplace/conditions-runner";
5
+ import OvcConverter from "@legalplace/ovc-converter";
6
+ import type OvcType from "@legalplace/types/dist/ovc";
7
+ import type InputsType from "@legalplace/types/dist/inputs";
8
+ import crypto from "crypto";
9
+ import DocumentRender from "./DocumentRender";
10
+ import NumAuto from "./NumAuto";
11
+ import IntputsInitiator from "./InputsInitiator";
12
+ import FillPdfForm from "./FillPdfForm";
13
+ import { parseDocumentNameWithVariables } from "./OutputParser";
14
+ import type {
15
+ FDFType,
16
+ DocumentIndex,
17
+ DocumentOutputIndex,
18
+ DocumentPdfFormIndex,
19
+ } from "../types/types";
14
20
 
15
21
  class Prerender {
16
- private model: ModelV3
22
+ private references: Types.ReferencesType;
17
23
 
18
- private references: Types.ReferencesType
24
+ private ovc: InputsType;
19
25
 
20
- private ovc: InputsType
26
+ private conditions: ConditionsRunner;
21
27
 
22
- private conditions: ConditionsRunner
28
+ private documentRender: DocumentRender;
23
29
 
24
- private documentRender: DocumentRender
30
+ private pdfFiller: FillPdfForm;
25
31
 
26
- private pdfFiller: FillPdfForm
32
+ private NumAuto: NumAuto;
27
33
 
28
- private NumAuto: NumAuto
34
+ private documentsIndex: DocumentIndex = {};
29
35
 
30
- private documentsIndex: DocumentIndex = {}
31
-
32
- private renderedDocuments: Record<string, string | FDFType> = {}
33
-
34
- constructor(model: ModelV3, ovc: InputsType | OvcType) {
35
- this.model = model
36
+ private renderedDocuments: Record<string, string | FDFType> = {};
36
37
 
38
+ constructor(
39
+ model: ModelV3 | Types.ReferencesType,
40
+ ovc: InputsType | OvcType
41
+ ) {
37
42
  // Initiating num auto
38
- this.NumAuto = new NumAuto()
43
+ this.NumAuto = new NumAuto();
39
44
 
40
45
  // Parsing references
41
- this.references = new ReferencesParser(model).getReferences()
46
+ this.references = ReferencesParser.isReferences(model)
47
+ ? model
48
+ : new ReferencesParser(model).getReferences();
42
49
 
43
50
  // Converting OVC if needed
44
- this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc, this.references) : ovc
51
+ this.ovc = OvcConverter.isOvc(ovc)
52
+ ? OvcConverter.convertToOptionsVariables(ovc, this.references)
53
+ : ovc;
45
54
 
46
55
  // Initiating inputs
47
- const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
56
+ const inputs = new IntputsInitiator(this.references, this.ovc).getInputs();
48
57
 
49
58
  // Initiating ConditionsRunner
50
- this.conditions = new ConditionsRunner(this.references, inputs)
59
+ this.conditions = new ConditionsRunner(this.references, inputs);
51
60
 
52
61
  // Rendering documents
53
- this.documentRender = new DocumentRender(this.references, this.conditions, inputs, this.NumAuto)
62
+ this.documentRender = new DocumentRender(
63
+ this.references,
64
+ this.conditions,
65
+ inputs,
66
+ this.NumAuto
67
+ );
54
68
 
55
69
  // Filling pdf documents
56
- this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs)
70
+ this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs);
57
71
 
58
- this.generateDocumentNamesHash()
72
+ this.generateDocumentNamesHash();
59
73
  }
60
74
 
61
75
  public getDocumentsIndexWithoutFdf() {
62
- return this.documentsIndex
76
+ return this.documentsIndex;
63
77
  }
64
78
 
65
79
  public getDocumentsIndex() {
66
- this.generateAllDocuments()
67
- this.fillPdfForms()
68
- return this.documentsIndex
80
+ this.generateAllDocuments();
81
+ this.fillPdfForms();
82
+ return this.documentsIndex;
69
83
  }
70
84
 
71
85
  public getDocument(documentNameHash: string) {
72
86
  if (this.renderedDocuments[documentNameHash]) {
73
- return this.renderedDocuments[documentNameHash]
87
+ return this.renderedDocuments[documentNameHash];
74
88
  }
75
89
 
76
- const index = this.documentsIndex[documentNameHash]
90
+ const index = this.documentsIndex[documentNameHash];
77
91
 
78
- this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index) ? this.pdfFiller.fillDocument(index.slug) : this.documentRender.renderDocument(index.slug)
92
+ this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
93
+ ? this.pdfFiller.fillDocument(index.slug)
94
+ : this.documentRender.renderDocument(index.slug);
79
95
 
80
- return this.renderedDocuments[documentNameHash]
96
+ return this.renderedDocuments[documentNameHash];
81
97
  }
82
98
 
83
99
  private generateDocumentNamesHash() {
84
- Object.keys(this.model.documents).forEach(slug => {
85
- const document = this.model.documents[slug]
86
- const documentParams = this.model.documents[slug].params
87
- const conditionObject = this.references.conditions.documents[slug]
88
- const condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'documents')
100
+ Object.keys(this.references.documents).forEach((slug) => {
101
+ const document = this.references.documents[slug];
102
+ const documentParams = this.references.documents[slug].params;
103
+ const conditionObject = this.references.conditions.documents[slug];
104
+ const condition =
105
+ conditionObject === undefined
106
+ ? true
107
+ : this.conditions.executeCondition(
108
+ conditionObject,
109
+ 0,
110
+ 0,
111
+ "documents"
112
+ );
89
113
 
90
114
  // Rendering documents sections
91
115
  if (condition === true) {
92
- const hash = crypto
93
- .createHash('sha1')
94
- .update(slug)
95
- .digest('hex')
116
+ const hash = crypto.createHash("sha1").update(slug).digest("hex");
96
117
 
97
118
  // Referencing in index
98
- if (typeof document.pdf === 'object' && typeof document.pdf.id === 'string' && typeof document.pdf.form === 'object') {
119
+ if (
120
+ typeof document.pdf === "object" &&
121
+ typeof document.pdf.id === "string" &&
122
+ typeof document.pdf.form === "object"
123
+ ) {
99
124
  this.documentsIndex[hash] = {
100
- name: parseDocumentNameWithVariables(document.name, this.ovc, this.references, document.fallbackName),
125
+ name: parseDocumentNameWithVariables(
126
+ document.name,
127
+ this.ovc,
128
+ this.references,
129
+ document.fallbackName
130
+ ),
101
131
  slug,
102
132
  form: true,
103
133
  fdf: {
104
- id: '',
105
- fields: {}
106
- }
107
- }
134
+ id: "",
135
+ fields: {},
136
+ },
137
+ };
108
138
  } else {
109
139
  this.documentsIndex[hash] = {
110
- name: parseDocumentNameWithVariables(document.name, this.ovc, this.references, document.fallbackName),
140
+ name: parseDocumentNameWithVariables(
141
+ document.name,
142
+ this.ovc,
143
+ this.references,
144
+ document.fallbackName
145
+ ),
111
146
  slug,
112
147
  pdf: documentParams?.formats?.pdf !== false,
113
- docx: documentParams?.formats?.docx !== false
114
- }
148
+ docx: documentParams?.formats?.docx !== false,
149
+ };
115
150
  }
116
151
  }
117
- })
152
+ });
118
153
  }
119
154
 
120
155
  private fillPdfForms() {
121
- Object.keys(this.documentsIndex).forEach(documentNameHash => {
122
- const index = this.documentsIndex[documentNameHash]
156
+ Object.keys(this.documentsIndex).forEach((documentNameHash) => {
157
+ const index = this.documentsIndex[documentNameHash];
123
158
  if (Prerender.isPdfForm(index)) {
124
- index.fdf = this.getDocument(documentNameHash) as FDFType
159
+ index.fdf = this.getDocument(documentNameHash) as FDFType;
125
160
  }
126
- })
161
+ });
127
162
  }
128
163
 
129
164
  private generateAllDocuments() {
130
- Object.keys(this.documentsIndex).forEach(documentNameHash => {
131
- const index = this.documentsIndex[documentNameHash]
165
+ Object.keys(this.documentsIndex).forEach((documentNameHash) => {
166
+ const index = this.documentsIndex[documentNameHash];
132
167
  if (Prerender.isPdfForm(index)) {
133
- this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(this.documentsIndex[documentNameHash].slug)
168
+ this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(
169
+ this.documentsIndex[documentNameHash].slug
170
+ );
134
171
  } else {
135
- this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].slug)
172
+ this.renderedDocuments[documentNameHash] =
173
+ this.documentRender.renderDocument(
174
+ this.documentsIndex[documentNameHash].slug
175
+ );
136
176
  }
137
- })
177
+ });
138
178
  }
139
179
 
140
- static isPdfForm(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentPdfFormIndex {
141
- return Object.prototype.hasOwnProperty.call(index, 'form')
180
+ static isPdfForm(
181
+ index: DocumentOutputIndex | DocumentPdfFormIndex
182
+ ): index is DocumentPdfFormIndex {
183
+ return Object.prototype.hasOwnProperty.call(index, "form");
142
184
  }
143
185
 
144
- static isOutput(index: DocumentOutputIndex | DocumentPdfFormIndex): index is DocumentOutputIndex {
145
- return !Object.prototype.hasOwnProperty.call(index, 'form')
186
+ static isOutput(
187
+ index: DocumentOutputIndex | DocumentPdfFormIndex
188
+ ): index is DocumentOutputIndex {
189
+ return !Object.prototype.hasOwnProperty.call(index, "form");
146
190
  }
147
191
  }
148
192
 
149
- export default Prerender
193
+ export default Prerender;
@@ -1,61 +1,80 @@
1
- import { Types } from '@legalplace/referencesparser'
2
- import ConditionsRunner from '@legalplace/conditions-runner'
3
- import InputsType from '@legalplace/types/dist/inputs'
4
- import OptionRender from './OptionRender'
5
- import NumAuto from './NumAuto'
1
+ import type { Types } from "@legalplace/referencesparser";
2
+ import type ConditionsRunner from "@legalplace/conditions-runner";
3
+ import type InputsType from "@legalplace/types/dist/inputs";
4
+ import OptionRender from "./OptionRender";
5
+ import type NumAuto from "./NumAuto";
6
6
 
7
7
  class SectionRender {
8
- outputs: string[] = []
8
+ outputs: string[] = [];
9
9
 
10
- references: Types.ReferencesType
10
+ references: Types.ReferencesType;
11
11
 
12
- currentSection: number
12
+ currentSection: number;
13
13
 
14
- documentName: string
14
+ documentName: string;
15
15
 
16
- conditions: ConditionsRunner
16
+ conditions: ConditionsRunner;
17
17
 
18
- ovc: InputsType
18
+ ovc: InputsType;
19
19
 
20
- private NumAuto: NumAuto
20
+ private NumAuto: NumAuto;
21
21
 
22
- constructor(options: { references: Types.ReferencesType; conditions: ConditionsRunner; ovc: InputsType; documentName: string; currentSection: number; numauto: NumAuto }) {
23
- this.references = options.references
24
- this.conditions = options.conditions
25
- this.documentName = options.documentName
26
- this.currentSection = options.currentSection
27
- this.ovc = options.ovc
28
- this.NumAuto = options.numauto
22
+ constructor(options: {
23
+ references: Types.ReferencesType;
24
+ conditions: ConditionsRunner;
25
+ ovc: InputsType;
26
+ documentName: string;
27
+ currentSection: number;
28
+ numauto: NumAuto;
29
+ }) {
30
+ this.references = options.references;
31
+ this.conditions = options.conditions;
32
+ this.documentName = options.documentName;
33
+ this.currentSection = options.currentSection;
34
+ this.ovc = options.ovc;
35
+ this.NumAuto = options.numauto;
29
36
 
30
- this.renderSection()
37
+ this.renderSection();
31
38
  }
32
39
 
33
40
  getOutputs() {
34
- return this.outputs
41
+ return this.outputs;
35
42
  }
36
43
 
37
44
  private renderSection() {
38
- const section = this.references.sections[this.documentName][this.currentSection]
39
- const conditionObject = this.references.conditions.sections[this.documentName][this.currentSection]
40
- const condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'sections')
45
+ const section =
46
+ this.references.sections[this.documentName][this.currentSection];
47
+ const conditionObject =
48
+ this.references.conditions.sections[this.documentName][
49
+ this.currentSection
50
+ ];
51
+ const condition =
52
+ conditionObject === undefined
53
+ ? true
54
+ : this.conditions.executeCondition(conditionObject, 0, 0, "sections");
41
55
 
42
56
  // Rendering documents sections
43
57
  if (condition === true) {
44
- section.options.forEach(optionId => {
45
- const option = this.references.options[optionId]
46
- let repeatOption = optionId
47
- if (option.meta.type === 'repeated') {
48
- if (option.meta.repeatOption === undefined) return
49
- repeatOption = typeof option.meta.repeatOption === 'number' ? option.meta.repeatOption : parseInt(option.meta.repeatOption, 10)
58
+ section.options.forEach((optionId) => {
59
+ const option = this.references.options[optionId];
60
+ let repeatOption = optionId;
61
+ if (option.meta.type === "repeated") {
62
+ if (option.meta.repeatOption === undefined) return;
63
+ repeatOption =
64
+ typeof option.meta.repeatOption === "number"
65
+ ? option.meta.repeatOption
66
+ : parseInt(option.meta.repeatOption, 10);
50
67
  }
51
68
 
52
69
  // Option inputs
53
- const inputs = this.ovc.options[repeatOption] || [!['radio', 'checkbox'].includes(option.meta.type)] // Falling back on a single value array if option doesn't exist in ovc
70
+ const inputs = this.ovc.options[repeatOption] || [
71
+ !["radio", "checkbox"].includes(option.meta.type),
72
+ ]; // Falling back on a single value array if option doesn't exist in ovc
54
73
 
55
74
  // Looping through inputs
56
75
  inputs.forEach((value, index) => {
57
76
  // If value is false we stop here
58
- if (value !== true) return
77
+ if (value !== true) return;
59
78
 
60
79
  this.outputs = [
61
80
  ...this.outputs,
@@ -65,13 +84,13 @@ class SectionRender {
65
84
  ovc: this.ovc,
66
85
  index,
67
86
  conditions: this.conditions,
68
- numauto: this.NumAuto
69
- }).getOutputs()
70
- ]
71
- })
72
- })
87
+ numauto: this.NumAuto,
88
+ }).getOutputs(),
89
+ ];
90
+ });
91
+ });
73
92
  }
74
93
  }
75
94
  }
76
95
 
77
- export default SectionRender
96
+ export default SectionRender;