@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,18 +1,22 @@
1
- import { Types } from '@legalplace/referencesparser'
2
- import ConditionsRunner from '@legalplace/conditions-runner'
3
- import InputsType from '@legalplace/types/dist/inputs'
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
4
 
5
5
  class FillPdfFormBase {
6
- references: Types.ReferencesType
6
+ references: Types.ReferencesType;
7
7
 
8
- conditions: ConditionsRunner
8
+ conditions: ConditionsRunner;
9
9
 
10
- ovc: InputsType
10
+ ovc: InputsType;
11
11
 
12
- constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType) {
13
- this.references = references
14
- this.conditions = conditions
15
- this.ovc = ovc
12
+ constructor(
13
+ references: Types.ReferencesType,
14
+ conditions: ConditionsRunner,
15
+ ovc: InputsType
16
+ ) {
17
+ this.references = references;
18
+ this.conditions = conditions;
19
+ this.ovc = ovc;
16
20
  }
17
21
 
18
22
  /**
@@ -22,11 +26,18 @@ class FillPdfFormBase {
22
26
  */
23
27
  isVariableDisplayed(id: number, index: number) {
24
28
  // Getting variable's conditions & executing it if any
25
- const variableCondition = this.getVariableCondition(id, index)
26
- const variableParents = this.references.relations.variables[id]?.parents || []
27
- const parentOptionIsDisplayed = this.isOptionDisplayed(variableParents[0], index)
28
-
29
- return [variableCondition, parentOptionIsDisplayed].filter(c => c !== true).length === 0
29
+ const variableCondition = this.getVariableCondition(id, index);
30
+ const variableParents =
31
+ this.references.relations.variables[id]?.parents || [];
32
+ const parentOptionIsDisplayed = this.isOptionDisplayed(
33
+ variableParents[0],
34
+ index
35
+ );
36
+
37
+ return (
38
+ [variableCondition, parentOptionIsDisplayed].filter((c) => c !== true)
39
+ .length === 0
40
+ );
30
41
  }
31
42
 
32
43
  /**
@@ -36,18 +47,26 @@ class FillPdfFormBase {
36
47
  */
37
48
  isOptionDisplayed(id: number, index: number) {
38
49
  // Getting variable's conditions & executing it if any
39
- const optionCondition = this.getOptionCondition(id, index)
40
- const optionParents = this.references.relations.options[id]?.parents || []
41
- const parentsConditions = optionParents.map(optionId => {
42
- return this.getOptionCondition(optionId, index) !== false
43
- })
44
- const parentsInputs = optionParents.map(optionId => {
45
- return this.ovc.options[optionId][index]
46
- })
47
- const parentSectionId = this.getOptionParentSection(id)
48
- const parentSectionCondition = this.getSectionCondition(parentSectionId) !== false
49
-
50
- return [optionCondition, parentSectionCondition, ...parentsConditions, ...parentsInputs].filter(c => c !== true).length === 0
50
+ const optionCondition = this.getOptionCondition(id, index);
51
+ const optionParents = this.references.relations.options[id]?.parents || [];
52
+ const parentsConditions = optionParents.map(
53
+ (optionId) => this.getOptionCondition(optionId, index) !== false
54
+ );
55
+ const parentsInputs = optionParents.map(
56
+ (optionId) => this.ovc.options[optionId][index]
57
+ );
58
+ const parentSectionId = this.getOptionParentSection(id);
59
+ const parentSectionCondition =
60
+ this.getSectionCondition(parentSectionId) !== false;
61
+
62
+ return (
63
+ [
64
+ optionCondition,
65
+ parentSectionCondition,
66
+ ...parentsConditions,
67
+ ...parentsInputs,
68
+ ].filter((c) => c !== true).length === 0
69
+ );
51
70
  }
52
71
 
53
72
  /**
@@ -56,8 +75,15 @@ class FillPdfFormBase {
56
75
  * @param index Variable's index
57
76
  */
58
77
  private getVariableCondition(id: number, index: number) {
59
- const conditionObject = this.references.conditions.variables[id]
60
- return conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, id, index, 'variables')
78
+ const conditionObject = this.references.conditions.variables[id];
79
+ return conditionObject === undefined
80
+ ? true
81
+ : this.conditions.executeCondition(
82
+ conditionObject,
83
+ id,
84
+ index,
85
+ "variables"
86
+ );
61
87
  }
62
88
 
63
89
  /**
@@ -66,8 +92,10 @@ class FillPdfFormBase {
66
92
  * @param index Option's index
67
93
  */
68
94
  private getOptionCondition(id: number, index: number) {
69
- const conditionObject = this.references.conditions.options[id]
70
- return conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, id, index, 'options')
95
+ const conditionObject = this.references.conditions.options[id];
96
+ return conditionObject === undefined
97
+ ? true
98
+ : this.conditions.executeCondition(conditionObject, id, index, "options");
71
99
  }
72
100
 
73
101
  /**
@@ -75,8 +103,10 @@ class FillPdfFormBase {
75
103
  * @param id Section's id
76
104
  */
77
105
  private getSectionCondition(id: number) {
78
- const conditionObject = this.references.conditions.sections.main[id]
79
- return conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, id, 0, 'sections')
106
+ const conditionObject = this.references.conditions.sections.main[id];
107
+ return conditionObject === undefined
108
+ ? true
109
+ : this.conditions.executeCondition(conditionObject, id, 0, "sections");
80
110
  }
81
111
 
82
112
  /**
@@ -84,20 +114,22 @@ class FillPdfFormBase {
84
114
  * @param id Option's id
85
115
  */
86
116
  private getOptionParentSection(id: number) {
87
- const { parents } = this.references.relations.options[id]
117
+ const { parents } = this.references.relations.options[id];
88
118
 
89
119
  // Getting root option id
90
- const rootId = parents.length > 0 ? parents[parents.length - 1] : id
120
+ const rootId = parents.length > 0 ? parents[parents.length - 1] : id;
91
121
 
92
122
  // Looking for section
93
- const sections = Object.values(this.references.sections.main)
123
+ const sections = Object.values(this.references.sections.main);
94
124
 
95
125
  for (let i = 0; i < sections.length; i += 1) {
96
- if (sections[i].options.includes(rootId)) return sections[i].id
126
+ if (sections[i].options.includes(rootId)) return sections[i].id;
97
127
  }
98
128
 
99
- throw new Error(`Cannot find parent section for option ${id} (Root option id: ${rootId})`)
129
+ throw new Error(
130
+ `Cannot find parent section for option ${id} (Root option id: ${rootId})`
131
+ );
100
132
  }
101
133
  }
102
134
 
103
- export default FillPdfFormBase
135
+ export default FillPdfFormBase;
@@ -1,19 +1,22 @@
1
1
  export type DocumentOutputIndex = {
2
- name: string
3
- slug: string
4
- pdf: boolean
5
- docx: boolean
6
- }
2
+ name: string;
3
+ slug: string;
4
+ pdf: boolean;
5
+ docx: boolean;
6
+ };
7
7
  export type DocumentPdfFormIndex = {
8
- name: string
9
- slug: string
10
- form: boolean
11
- fdf: FDFType
12
- }
8
+ name: string;
9
+ slug: string;
10
+ form: boolean;
11
+ fdf: FDFType;
12
+ };
13
13
 
14
- export type DocumentIndex = Record<string, DocumentOutputIndex | DocumentPdfFormIndex>
14
+ export type DocumentIndex = Record<
15
+ string,
16
+ DocumentOutputIndex | DocumentPdfFormIndex
17
+ >;
15
18
 
16
19
  export type FDFType = {
17
- id: string
18
- fields: Record<string, string>
19
- }
20
+ id: string;
21
+ fields: Record<string, string>;
22
+ };
package/tsconfig.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "extends": "../../tsconfig.json",
2
3
  "compileOnSave": true,
3
4
  "compilerOptions": {
4
5
  "target": "es5",
@@ -7,10 +8,11 @@
7
8
  "outDir": "./dist/",
8
9
  "strict": true,
9
10
  "typeRoots": ["node_modules/@types"],
11
+ "types": ["node"],
10
12
  "esModuleInterop": true,
11
13
  "removeComments": true,
12
14
  "declaration": true
13
15
  },
14
16
  "include": ["src"],
15
17
  "exclude": ["node_modules"]
16
- }
18
+ }
package/.gitlab-ci.yml DELETED
@@ -1,43 +0,0 @@
1
- image: 148253454541.dkr.ecr.eu-west-1.amazonaws.com/legalplace:latest
2
-
3
-
4
- stages:
5
- - setup
6
- - publish
7
-
8
- before_script:
9
- - export PATH=$PATH:./node_modules/.bin/
10
-
11
- variables:
12
- DOCKER_DRIVER: overlay2
13
-
14
- setup:
15
- stage: setup
16
- artifacts:
17
- paths:
18
- - dist/
19
- only:
20
- changes:
21
- - yarn.lock
22
- - package.json
23
- - .gitlab-ci.yml
24
- script:
25
- - yarn -v
26
- - node -v
27
- - yarn install --frozen-lockfile --check-files --silent
28
- - yarn build
29
-
30
- publish:
31
- stage: publish
32
- except:
33
- variables:
34
- - $CI_COMMIT_MESSAGE =~ /skip-publish/
35
- script:
36
- - npm publish
37
- environment:
38
- name: development
39
- only:
40
- refs:
41
- - master
42
- changes:
43
- - package.json
package/.prettierrc.js DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- printWidth: 180,
3
- useTabs: false,
4
- tabWidth: 2,
5
- semi: false,
6
- singleQuote: true,
7
- trailingComma: 'none',
8
- parser: 'typescript',
9
- endOfLine: 'lf'
10
- }
@@ -1,17 +0,0 @@
1
- {
2
- "eslint.enable": true,
3
- "editor.tabSize": 2,
4
- "eslint.options": {
5
- "extensions": [".ts", ".js"]
6
- },
7
- "files.autoSave": "off",
8
- "editor.formatOnSave": false,
9
- "editor.formatOnType": true,
10
- "prettier.singleQuote": true,
11
- "eslint.packageManager": "yarn",
12
- "eslint.quiet": true,
13
- "typescript.tsdk": "node_modules/typescript/lib",
14
- "editor.codeActionsOnSave": {
15
- "source.fixAll.eslint": true
16
- }
17
- }
@@ -1,24 +0,0 @@
1
- {
2
- // See https://go.microsoft.com/fwlink/?LinkId=733558
3
- // for the documentation about the tasks.json format
4
- "version": "2.0.0",
5
- "tasks": [
6
- {
7
- "type": "npm",
8
- "script": "lint",
9
- "problemMatcher": [
10
- "$eslint-stylish",
11
- "$tsc"
12
- ]
13
- },
14
- {
15
- "type": "typescript",
16
- "tsconfig": "tsconfig.json",
17
- "option": "watch",
18
- "problemMatcher": [
19
- "$tsc-watch"
20
- ],
21
- "group": "build"
22
- }
23
- ]
24
- }
@@ -1,12 +0,0 @@
1
- {
2
- // extend your base config so you don't have to redefine your compilerOptions
3
- "extends": "./tsconfig.json",
4
- "include": [
5
- "src/**/*.ts",
6
- "*.ts",
7
- // etc
8
-
9
- // if you have a mixed JS/TS codebase, don't forget to include your JS files
10
- "src/**/*.js"
11
- ]
12
- }