@legalplace/prerenderx 2.2.2 → 2.2.3

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,15 +1,15 @@
1
- import OVC_TYPE from "./ovc.type";
1
+ import OVC_TYPE from './ovc.type'
2
2
 
3
3
  export interface OldOVC {
4
4
  o: {
5
- [k: string]: string | number | (string | number)[];
6
- };
5
+ [k: string]: string | number | (string | number)[]
6
+ }
7
7
  v: {
8
- [k: string]: string | number | (string | number)[];
9
- };
8
+ [k: string]: string | number | (string | number)[]
9
+ }
10
10
  c: {
11
- [k: string]: boolean | boolean[];
12
- };
11
+ [k: string]: boolean | boolean[]
12
+ }
13
13
  }
14
14
 
15
15
  class OvcConverter {
@@ -17,98 +17,90 @@ class OvcConverter {
17
17
  const inputs: OVC_TYPE = {
18
18
  options: {},
19
19
  variables: {}
20
- };
20
+ }
21
21
 
22
- if (typeof ovc !== "object") return inputs;
22
+ if (typeof ovc !== 'object') return inputs
23
23
 
24
24
  // Reading options
25
- if (typeof ovc.o === "object") {
25
+ if (typeof ovc.o === 'object') {
26
26
  Object.keys(ovc.o).forEach(id => {
27
- const currentOption = ovc.o[id];
27
+ const currentOption = ovc.o[id]
28
28
 
29
29
  // If it's a multiple
30
30
  if (Array.isArray(currentOption)) {
31
- const occurences = currentOption.length;
31
+ const occurences = currentOption.length
32
32
  currentOption.forEach((childId, index) => {
33
- if (typeof childId === "string" && childId.trim().length === 0) {
33
+ if (typeof childId === 'string' && childId.trim().length === 0) {
34
34
  // Creating input if it doesn't exist
35
- if (
36
- !Object.prototype.hasOwnProperty.call(inputs.options, childId)
37
- ) {
38
- inputs.options[id] = new Array(occurences).fill(false);
35
+ if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
36
+ inputs.options[id] = new Array(occurences).fill(false)
39
37
  }
40
- return;
38
+ return
41
39
  }
42
40
 
43
41
  // Creating input if it doesn't exist
44
- if (
45
- !Object.prototype.hasOwnProperty.call(inputs.options, childId)
46
- ) {
47
- inputs.options[childId] = new Array(occurences).fill(false);
42
+ if (!Object.prototype.hasOwnProperty.call(inputs.options, childId)) {
43
+ inputs.options[childId] = new Array(occurences).fill(false)
48
44
  }
49
45
 
50
46
  // Setting current index to true
51
- inputs.options[childId][index] = true;
52
- });
47
+ inputs.options[childId][index] = true
48
+ })
53
49
  } else {
54
- if (
55
- typeof currentOption === "string" &&
56
- currentOption.trim().length === 0
57
- )
58
- return;
59
- inputs.options[currentOption] = [true];
50
+ if (typeof currentOption === 'string' && currentOption.trim().length === 0) return
51
+ inputs.options[currentOption] = [true]
60
52
  }
61
- });
53
+ })
62
54
  }
63
55
 
64
56
  // Reading variables
65
- if (typeof ovc.v === "object") {
57
+ if (typeof ovc.v === 'object') {
66
58
  Object.keys(ovc.v).forEach(id => {
67
- const currentVariable = ovc.v[id];
59
+ const currentVariable = ovc.v[id]
68
60
 
69
61
  // If it's a multiple
70
62
  if (Array.isArray(currentVariable)) {
71
- inputs.variables[id] = currentVariable;
63
+ inputs.variables[id] = currentVariable
72
64
  } else {
73
- inputs.variables[id] = [currentVariable];
65
+ inputs.variables[id] = [currentVariable]
74
66
  }
75
- });
67
+ })
76
68
  }
77
69
 
78
70
  // Reading checkboxes
79
- if (typeof ovc.c === "object") {
71
+ if (typeof ovc.c === 'object') {
80
72
  Object.keys(ovc.c).forEach(id => {
81
- const currentCheckbox = ovc.c[id];
82
- if (typeof id === "string" && id.trim().length === 0) return;
73
+ const currentCheckbox = ovc.c[id]
74
+ if (typeof id === 'string' && id.trim().length === 0) return
83
75
  // If it's a multiple
84
76
  if (Array.isArray(currentCheckbox)) {
85
- inputs.options[id] = currentCheckbox;
77
+ inputs.options[id] = currentCheckbox
86
78
  } else {
87
- inputs.options[id] = [currentCheckbox];
79
+ inputs.options[id] = [currentCheckbox]
88
80
  }
89
- });
81
+ })
90
82
  }
91
83
 
92
- return inputs;
84
+ return inputs
93
85
  }
94
86
 
95
87
  public isOvc(_obj: OVC_TYPE | OldOVC): _obj is OldOVC {
96
- if (typeof _obj !== "object" || _obj === null) return false;
97
- const ovcKeys = ["o", "v", "c"];
88
+ if (typeof _obj !== 'object' || _obj === null) return false
89
+ const ovcKeys = ['o', 'v', 'c']
98
90
  const foundKeys = Object.keys(_obj)
99
91
  .map((key): number => (ovcKeys.includes(key) ? 1 : 0))
100
- .reduce((a, b) => a + b, 0);
101
- return foundKeys > 1;
92
+ .reduce((a, b) => a + b, 0)
93
+ return foundKeys > 1
102
94
  }
103
95
 
104
96
  public isOptionsVariables(_obj: OVC_TYPE | OldOVC) {
105
- if (typeof _obj !== "object" || _obj === null) return false;
106
- const optionsVariablesKeys = ["options", "variables"];
97
+ if (typeof _obj !== 'object' || _obj === null) return false
98
+ const optionsVariablesKeys = ['options', 'variables']
107
99
  const foundKeys = Object.keys(_obj)
108
100
  .map((key): number => (optionsVariablesKeys.includes(key) ? 1 : 0))
109
- .reduce((a, b) => a + b, 0);
110
- return foundKeys === 2;
101
+ .reduce((a, b) => a + b, 0)
102
+ return foundKeys === 2
111
103
  }
112
104
  }
113
105
 
114
- export default new OvcConverter();
106
+ export default new OvcConverter()
@@ -1,118 +1,97 @@
1
- import { ModelV3 } from "@legalplace/models-v3-types";
2
- import { Types, ReferencesParser } from "@legalplace/referencesparser";
3
- import crypto from "crypto";
4
- import DocumentRender from "./DocumentRender";
5
- import ConditionsRunner from "./ConditionsRunner";
6
- import OVC_TYPE from "./ovc.type";
7
- import OvcConverter, { OldOVC } from "./OvcConverter";
8
- import NumAuto from "./NumAuto";
9
- import IntputsInitiator from "./InputsInitiator";
1
+ import { ModelV3 } from '@legalplace/models-v3-types'
2
+ import { Types, ReferencesParser } from '@legalplace/referencesparser'
3
+ import crypto from 'crypto'
4
+ import DocumentRender from './DocumentRender'
5
+ import ConditionsRunner from './ConditionsRunner'
6
+ import OVC_TYPE from './ovc.type'
7
+ import OvcConverter, { OldOVC } from './OvcConverter'
8
+ import NumAuto from './NumAuto'
9
+ import IntputsInitiator from './InputsInitiator'
10
10
 
11
11
  class Prerender {
12
- private model: ModelV3;
12
+ private model: ModelV3
13
13
 
14
- private references: Types.ReferencesType;
14
+ private references: Types.ReferencesType
15
15
 
16
- private ovc: OVC_TYPE;
16
+ private ovc: OVC_TYPE
17
17
 
18
- private conditions: ConditionsRunner;
18
+ private conditions: ConditionsRunner
19
19
 
20
- private documentRender: DocumentRender;
20
+ private documentRender: DocumentRender
21
21
 
22
- private NumAuto: NumAuto;
22
+ private NumAuto: NumAuto
23
23
 
24
24
  private documentsIndex: Record<
25
25
  string,
26
26
  {
27
- name: string;
28
- pdf: boolean;
29
- docx: boolean;
27
+ name: string
28
+ pdf: boolean
29
+ docx: boolean
30
30
  }
31
- > = {};
31
+ > = {}
32
32
 
33
- private renderedDocuments: Record<string, string> = {};
33
+ private renderedDocuments: Record<string, string> = {}
34
34
 
35
35
  constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC) {
36
- this.model = model;
36
+ this.model = model
37
37
 
38
38
  // Converting OVC if needed
39
- this.ovc = OvcConverter.isOvc(ovc)
40
- ? OvcConverter.convertToOptionsVariables(ovc)
41
- : ovc;
39
+ this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc) : ovc
42
40
 
43
41
  // Initiating num auto
44
- this.NumAuto = new NumAuto();
42
+ this.NumAuto = new NumAuto()
45
43
 
46
44
  // Parsing references
47
- this.references = new ReferencesParser(model).getReferences();
45
+ this.references = new ReferencesParser(model).getReferences()
48
46
 
49
47
  // Initiating inputs
50
- const inputs = new IntputsInitiator(this.references, this.ovc).getInputs();
48
+ const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
51
49
 
52
50
  // Initiating ConditionsRunner
53
- this.conditions = new ConditionsRunner(this.references, inputs);
51
+ this.conditions = new ConditionsRunner(this.references, inputs)
54
52
 
55
53
  // Rendering documents
56
- this.documentRender = new DocumentRender(
57
- this.references,
58
- this.conditions,
59
- inputs,
60
- this.NumAuto
61
- );
62
-
63
- this.generateDocumentNamesHash();
64
- this.generateAllDocuments();
54
+ this.documentRender = new DocumentRender(this.references, this.conditions, inputs, this.NumAuto)
55
+
56
+ this.generateDocumentNamesHash()
57
+ this.generateAllDocuments()
65
58
  }
66
59
 
67
60
  public getDocumentsIndex() {
68
- return this.documentsIndex;
61
+ return this.documentsIndex
69
62
  }
70
63
 
71
64
  private generateDocumentNamesHash() {
72
65
  Object.keys(this.model.documents).forEach(documentName => {
73
- const conditionObject = this.references.conditions.documents[
74
- documentName
75
- ];
76
- const condition =
77
- conditionObject === undefined
78
- ? true
79
- : this.conditions.executeCondition(
80
- conditionObject,
81
- 0,
82
- 0,
83
- "documents"
84
- );
66
+ const conditionObject = this.references.conditions.documents[documentName]
67
+ const condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, 0, 0, 'documents')
85
68
 
86
69
  // Rendering documents sections
87
70
  if (condition === true) {
88
71
  const hash = crypto
89
- .createHash("sha1")
72
+ .createHash('sha1')
90
73
  .update(documentName)
91
- .digest("hex");
74
+ .digest('hex')
92
75
 
93
76
  // Referencing in index
94
77
  this.documentsIndex[hash] = {
95
78
  name: documentName,
96
79
  pdf: true,
97
80
  docx: true
98
- };
81
+ }
99
82
  }
100
- });
83
+ })
101
84
  }
102
85
 
103
86
  private generateAllDocuments() {
104
87
  Object.keys(this.documentsIndex).forEach(documentNameHash => {
105
- this.renderedDocuments[
106
- documentNameHash
107
- ] = this.documentRender.renderDocument(
108
- this.documentsIndex[documentNameHash].name
109
- );
110
- });
88
+ this.renderedDocuments[documentNameHash] = this.documentRender.renderDocument(this.documentsIndex[documentNameHash].name)
89
+ })
111
90
  }
112
91
 
113
92
  public getDocument(documentNameHash: string) {
114
- return this.renderedDocuments[documentNameHash];
93
+ return this.renderedDocuments[documentNameHash]
115
94
  }
116
95
  }
117
96
 
118
- export default Prerender;
97
+ export default Prerender
@@ -1,80 +1,61 @@
1
- import { Types } from "@legalplace/referencesparser";
2
- import ConditionsRunner from "./ConditionsRunner";
3
- import OptionRender from "./OptionRender";
4
- import OVC_TYPE from "./ovc.type";
5
- import NumAuto from "./NumAuto";
1
+ import { Types } from '@legalplace/referencesparser'
2
+ import ConditionsRunner from './ConditionsRunner'
3
+ import OptionRender from './OptionRender'
4
+ import OVC_TYPE from './ovc.type'
5
+ import 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: OVC_TYPE;
18
+ ovc: OVC_TYPE
19
19
 
20
- private NumAuto: NumAuto;
20
+ private NumAuto: NumAuto
21
21
 
22
- constructor(options: {
23
- references: Types.ReferencesType;
24
- conditions: ConditionsRunner;
25
- ovc: OVC_TYPE;
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;
22
+ constructor(options: { references: Types.ReferencesType; conditions: ConditionsRunner; ovc: OVC_TYPE; 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
36
29
 
37
- this.renderSection();
30
+ this.renderSection()
38
31
  }
39
32
 
40
33
  getOutputs() {
41
- return this.outputs;
34
+ return this.outputs
42
35
  }
43
36
 
44
37
  private renderSection() {
45
- const section = this.references.sections[this.documentName][
46
- this.currentSection
47
- ];
48
- const conditionObject = this.references.conditions.sections[
49
- this.documentName
50
- ][this.currentSection];
51
- const condition =
52
- conditionObject === undefined
53
- ? true
54
- : this.conditions.executeCondition(conditionObject, 0, 0, "sections");
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')
55
41
 
56
42
  // Rendering documents sections
57
43
  if (condition === true) {
58
44
  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);
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)
67
50
  }
68
51
 
69
52
  // Option inputs
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
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
73
54
 
74
55
  // Looping through inputs
75
56
  inputs.forEach((value, index) => {
76
57
  // If value is false we stop here
77
- if (value !== true) return;
58
+ if (value !== true) return
78
59
 
79
60
  this.outputs = [
80
61
  ...this.outputs,
@@ -86,11 +67,11 @@ class SectionRender {
86
67
  conditions: this.conditions,
87
68
  numauto: this.NumAuto
88
69
  }).getOutputs()
89
- ];
90
- });
91
- });
70
+ ]
71
+ })
72
+ })
92
73
  }
93
74
  }
94
75
  }
95
76
 
96
- export default SectionRender;
77
+ export default SectionRender
@@ -1,10 +1,10 @@
1
1
  type OVC_TYPE = {
2
2
  options: {
3
- [key: string]: boolean[];
4
- };
3
+ [key: string]: boolean[]
4
+ }
5
5
  variables: {
6
- [key: string]: (number | string)[];
7
- };
8
- };
6
+ [key: string]: (number | string)[]
7
+ }
8
+ }
9
9
 
10
- export default OVC_TYPE;
10
+ export default OVC_TYPE