@legalplace/prerenderx 3.0.0 → 3.2.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.2.0](https://git.legalplace.eu/legalplace/prerenderx/compare/v3.1.0...v3.2.0) (2022-04-04)
6
+
7
+
8
+ ### Features
9
+
10
+ * bump conditions-runner ([7df10d2](https://git.legalplace.eu/legalplace/prerenderx/commit/7df10d2a778ed69f6cb803dc355b983e55492b8d))
11
+ * optimization of documents rendering ([f0afac8](https://git.legalplace.eu/legalplace/prerenderx/commit/f0afac8839ceb75b1415187c7970de9edf0f99ee))
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * fix review ([ec04225](https://git.legalplace.eu/legalplace/prerenderx/commit/ec04225660d5a412af5ac5e351fc2916d603fb24))
17
+
18
+ ## [3.1.0](https://git.legalplace.eu/legalplace/prerenderx/compare/v2.5.5-alpha...v3.1.0) (2021-12-16)
19
+
20
+
21
+ ### Features
22
+
23
+ * add .gitlab-automator to .gitignore file ([56c8502](https://git.legalplace.eu/legalplace/prerenderx/commit/56c8502787a6f4b0019c8e3c91f4aec9f4d2e94c))
24
+ * add conditions-runner, types and ovc-converter as packages ([772bfdc](https://git.legalplace.eu/legalplace/prerenderx/commit/772bfdce518ac90306da996c54159fc7919427f4))
25
+ * add InputsType from Types package for OVC_TYPE ([24eb6b0](https://git.legalplace.eu/legalplace/prerenderx/commit/24eb6b01f8c0904d4a2612748b1cfe0175c0e2d8))
26
+ * move package types from dependencies to devDependencies ([8abc056](https://git.legalplace.eu/legalplace/prerenderx/commit/8abc05623d6d69f473139e613bbfe1c438f732f8))
27
+ * remove cache key ([e89e5d5](https://git.legalplace.eu/legalplace/prerenderx/commit/e89e5d5dd0353d44927151cc19c23a6192263c60))
28
+ * use package in FillPdfFormBase ([c96b782](https://git.legalplace.eu/legalplace/prerenderx/commit/c96b7829a378483e9f3f02b50a1ff1da6829bf2d))
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * use types package instead of ovc.type file ([d0af6ee](https://git.legalplace.eu/legalplace/prerenderx/commit/d0af6ee936a054dd6292e054e035f92e5954caad))
34
+
5
35
  ### [2.5.5](https://git.legalplace.eu/legalplace/prerenderx/compare/v2.6.3...v2.5.5) (2021-10-27)
6
36
 
7
37
  ### [2.6.3](https://git.legalplace.eu/legalplace/prerenderx/compare/v2.6.2...v2.6.3) (2021-10-04)
@@ -1,13 +1,13 @@
1
1
  import { Types } from '@legalplace/referencesparser';
2
- import ConditionsRunner from './ConditionsRunner';
3
- import OVC_TYPE from './ovc.type';
2
+ import ConditionsRunner from '@legalplace/conditions-runner';
3
+ import InputsType from '@legalplace/types/dist/inputs';
4
4
  import NumAuto from './NumAuto';
5
5
  declare class DocumentRender {
6
6
  references: Types.ReferencesType;
7
7
  conditions: ConditionsRunner;
8
- ovc: OVC_TYPE;
8
+ ovc: InputsType;
9
9
  private NumAuto;
10
- constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE, numauto: NumAuto);
10
+ constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType, numauto: NumAuto);
11
11
  renderDocument(documentName: string): string;
12
12
  }
13
13
  export default DocumentRender;
@@ -1,6 +1,6 @@
1
1
  import { Types } from '@legalplace/referencesparser';
2
- import ConditionsRunner from './ConditionsRunner';
3
- import OVC_TYPE from './ovc.type';
2
+ import ConditionsRunner from '@legalplace/conditions-runner';
3
+ import InputsType from '@legalplace/types/dist/inputs';
4
4
  import NumAuto from './NumAuto';
5
5
  declare class OptionRender {
6
6
  outputs: string[];
@@ -8,12 +8,12 @@ declare class OptionRender {
8
8
  index: number;
9
9
  id: number;
10
10
  conditions: ConditionsRunner;
11
- ovc: OVC_TYPE;
11
+ ovc: InputsType;
12
12
  private NumAuto;
13
13
  constructor(options: {
14
14
  references: Types.ReferencesType;
15
15
  conditions: ConditionsRunner;
16
- ovc: OVC_TYPE;
16
+ ovc: InputsType;
17
17
  index: number;
18
18
  id: number;
19
19
  numauto: NumAuto;
@@ -1,11 +1,11 @@
1
1
  import { Types } from '@legalplace/referencesparser';
2
- import OVC_TYPE from './ovc.type';
2
+ import InputsType from '@legalplace/types/dist/inputs';
3
3
  declare type relVarsValsT = Record<string, string | number>;
4
- declare type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT;
4
+ declare type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: InputsType, references: Types.ReferencesType) => relVarsValsT;
5
5
  export declare const getRelatedVariablesValues: getRelatedVarsT;
6
6
  declare type autonumsType = [string, string, number, string | null][];
7
7
  declare type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
8
8
  export declare const parseOutputWithVariables: parseOutputT;
9
- declare type TParseDocumentNameWithVariables = (text: string, ovc: OVC_TYPE, references: Types.ReferencesType, fallback?: string) => string;
9
+ declare type TParseDocumentNameWithVariables = (text: string, ovc: InputsType, references: Types.ReferencesType, fallback?: string) => string;
10
10
  export declare const parseDocumentNameWithVariables: TParseDocumentNameWithVariables;
11
11
  export {};
@@ -1,6 +1,6 @@
1
1
  import { ModelV3 } from '@legalplace/models-v3-types';
2
- import OVC_TYPE from './ovc.type';
3
- import { OldOVC } from './OvcConverter';
2
+ import OvcType from '@legalplace/types/dist/ovc';
3
+ import InputsType from '@legalplace/types/dist/inputs';
4
4
  declare type DocumentOutputIndex = {
5
5
  name: string;
6
6
  slug: string;
@@ -30,7 +30,8 @@ declare class Prerender {
30
30
  private NumAuto;
31
31
  private documentsIndex;
32
32
  private renderedDocuments;
33
- constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC);
33
+ constructor(model: ModelV3, ovc: InputsType | OvcType);
34
+ getDocumentsIndexWithoutFdf(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
34
35
  getDocumentsIndex(): Record<string, DocumentOutputIndex | DocumentPdfFormIndex>;
35
36
  getDocument(documentNameHash: string): string | FDFType;
36
37
  private generateDocumentNamesHash;
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var referencesparser_1 = require("@legalplace/referencesparser");
7
+ var conditions_runner_1 = __importDefault(require("@legalplace/conditions-runner"));
8
+ var ovc_converter_1 = __importDefault(require("@legalplace/ovc-converter"));
7
9
  var crypto_1 = __importDefault(require("crypto"));
8
10
  var DocumentRender_1 = __importDefault(require("./DocumentRender"));
9
- var ConditionsRunner_1 = __importDefault(require("./ConditionsRunner"));
10
- var OvcConverter_1 = __importDefault(require("./OvcConverter"));
11
11
  var NumAuto_1 = __importDefault(require("./NumAuto"));
12
12
  var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
13
13
  var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
@@ -19,21 +19,27 @@ var Prerender = (function () {
19
19
  this.model = model;
20
20
  this.NumAuto = new NumAuto_1.default();
21
21
  this.references = new referencesparser_1.ReferencesParser(model).getReferences();
22
- this.ovc = OvcConverter_1.default.isOvc(ovc)
23
- ? OvcConverter_1.default.convertToOptionsVariables(ovc, this.references)
24
- : ovc;
22
+ this.ovc = ovc_converter_1.default.isOvc(ovc) ? ovc_converter_1.default.convertToOptionsVariables(ovc, this.references) : ovc;
25
23
  var inputs = new InputsInitiator_1.default(this.references, this.ovc).getInputs();
26
- this.conditions = new ConditionsRunner_1.default(this.references, inputs);
24
+ this.conditions = new conditions_runner_1.default(this.references, inputs);
27
25
  this.documentRender = new DocumentRender_1.default(this.references, this.conditions, inputs, this.NumAuto);
28
26
  this.pdfFiller = new FillPdfForm_1.default(this.references, this.conditions, inputs);
29
27
  this.generateDocumentNamesHash();
30
- this.generateAllDocuments();
31
- this.fillPdfForms();
32
28
  }
29
+ Prerender.prototype.getDocumentsIndexWithoutFdf = function () {
30
+ return this.documentsIndex;
31
+ };
33
32
  Prerender.prototype.getDocumentsIndex = function () {
33
+ this.generateAllDocuments();
34
+ this.fillPdfForms();
34
35
  return this.documentsIndex;
35
36
  };
36
37
  Prerender.prototype.getDocument = function (documentNameHash) {
38
+ if (this.renderedDocuments[documentNameHash]) {
39
+ return this.renderedDocuments[documentNameHash];
40
+ }
41
+ var index = this.documentsIndex[documentNameHash];
42
+ this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index) ? this.pdfFiller.fillDocument(index.slug) : this.documentRender.renderDocument(index.slug);
37
43
  return this.renderedDocuments[documentNameHash];
38
44
  };
39
45
  Prerender.prototype.generateDocumentNamesHash = function () {
@@ -1,6 +1,6 @@
1
1
  import { Types } from '@legalplace/referencesparser';
2
- import ConditionsRunner from './ConditionsRunner';
3
- import OVC_TYPE from './ovc.type';
2
+ import ConditionsRunner from '@legalplace/conditions-runner';
3
+ import InputsType from '@legalplace/types/dist/inputs';
4
4
  import NumAuto from './NumAuto';
5
5
  declare class SectionRender {
6
6
  outputs: string[];
@@ -8,12 +8,12 @@ declare class SectionRender {
8
8
  currentSection: number;
9
9
  documentName: string;
10
10
  conditions: ConditionsRunner;
11
- ovc: OVC_TYPE;
11
+ ovc: InputsType;
12
12
  private NumAuto;
13
13
  constructor(options: {
14
14
  references: Types.ReferencesType;
15
15
  conditions: ConditionsRunner;
16
- ovc: OVC_TYPE;
16
+ ovc: InputsType;
17
17
  documentName: string;
18
18
  currentSection: number;
19
19
  numauto: NumAuto;
@@ -1,11 +1,11 @@
1
1
  import { Types } from '@legalplace/referencesparser';
2
- import ConditionsRunner from '../ConditionsRunner';
3
- import OVC_TYPE from '../ovc.type';
2
+ import ConditionsRunner from '@legalplace/conditions-runner';
3
+ import InputsType from '@legalplace/types/dist/inputs';
4
4
  declare class FillPdfFormBase {
5
5
  references: Types.ReferencesType;
6
6
  conditions: ConditionsRunner;
7
- ovc: OVC_TYPE;
8
- constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE);
7
+ ovc: InputsType;
8
+ constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType);
9
9
  isVariableDisplayed(id: number, index: number): boolean;
10
10
  isOptionDisplayed(id: number, index: number): boolean;
11
11
  private getVariableCondition;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -15,8 +15,10 @@
15
15
  "release": "standard-version -a --no-verify"
16
16
  },
17
17
  "dependencies": {
18
+ "@legalplace/conditions-runner": "1.1.7",
18
19
  "@legalplace/lplogic": "2.1.6",
19
20
  "@legalplace/models-v3-types": "3.5.1",
21
+ "@legalplace/ovc-converter": "1.1.0",
20
22
  "@legalplace/referencesparser": "1.6.3",
21
23
  "crypto": "^1.0.1",
22
24
  "standard-version": "^9.3.1",
@@ -25,6 +27,7 @@
25
27
  "devDependencies": {
26
28
  "@babel/core": "^7.7.2",
27
29
  "@babel/preset-typescript": "^7.7.2",
30
+ "@legalplace/types": "1.1.0",
28
31
  "@types/jest": "^24.0.15",
29
32
  "@types/node": "^12.12.6",
30
33
  "@typescript-eslint/eslint-plugin": "^2.6.1",
@@ -1,7 +1,7 @@
1
1
  import { Types } from '@legalplace/referencesparser'
2
- import ConditionsRunner from './ConditionsRunner'
2
+ import ConditionsRunner from '@legalplace/conditions-runner'
3
+ import InputsType from '@legalplace/types/dist/inputs'
3
4
  import SectionRender from './SectionRender'
4
- import OVC_TYPE from './ovc.type'
5
5
  import NumAuto from './NumAuto'
6
6
 
7
7
  class DocumentRender {
@@ -9,11 +9,11 @@ class DocumentRender {
9
9
 
10
10
  conditions: ConditionsRunner
11
11
 
12
- ovc: OVC_TYPE
12
+ ovc: InputsType
13
13
 
14
14
  private NumAuto: NumAuto
15
15
 
16
- constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE, numauto: NumAuto) {
16
+ constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType, numauto: NumAuto) {
17
17
  this.references = references
18
18
  this.conditions = conditions
19
19
  this.ovc = ovc
@@ -1,6 +1,6 @@
1
1
  import { Types } from '@legalplace/referencesparser'
2
- import ConditionsRunner from './ConditionsRunner'
3
- import OVC_TYPE from './ovc.type'
2
+ import ConditionsRunner from '@legalplace/conditions-runner'
3
+ import InputsType from '@legalplace/types/dist/inputs'
4
4
  import { parseOutputWithVariables, getRelatedVariablesValues } from './OutputParser'
5
5
  import NumAuto from './NumAuto'
6
6
 
@@ -15,11 +15,11 @@ class OptionRender {
15
15
 
16
16
  conditions: ConditionsRunner
17
17
 
18
- ovc: OVC_TYPE
18
+ ovc: InputsType
19
19
 
20
20
  private NumAuto: NumAuto
21
21
 
22
- constructor(options: { references: Types.ReferencesType; conditions: ConditionsRunner; ovc: OVC_TYPE; index: number; id: number; numauto: NumAuto }) {
22
+ constructor(options: { references: Types.ReferencesType; conditions: ConditionsRunner; ovc: InputsType; index: number; id: number; numauto: NumAuto }) {
23
23
  this.references = options.references
24
24
  this.conditions = options.conditions
25
25
  this.index = options.index
@@ -1,5 +1,6 @@
1
1
  import { Types } from '@legalplace/referencesparser'
2
- import OVC_TYPE from './ovc.type'
2
+ import InputsType from '@legalplace/types/dist/inputs'
3
+
3
4
 
4
5
  /**
5
6
  * Parses number to correct french number format ("," instead of ".")
@@ -18,7 +19,7 @@ const frenchNumber = (value: string | number) => {
18
19
  * @param variables Variables ids list
19
20
  */
20
21
  type relVarsValsT = Record<string, string | number>
21
- type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT
22
+ type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: InputsType, references: Types.ReferencesType) => relVarsValsT
22
23
  export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, variables, ovc, references) => {
23
24
  // Getting variables values
24
25
  const variablesValues: Record<string, string> = {}
@@ -105,7 +106,7 @@ export const parseOutputWithVariables: parseOutputT = (output, index, variables,
105
106
  */
106
107
  type TParseDocumentNameWithVariables = (
107
108
  text: string,
108
- ovc: OVC_TYPE,
109
+ ovc: InputsType,
109
110
  references: Types.ReferencesType,
110
111
  fallback?: string
111
112
  ) => string;
@@ -1,10 +1,11 @@
1
1
  import { ModelV3 } from '@legalplace/models-v3-types'
2
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'
3
7
  import crypto from 'crypto'
4
8
  import DocumentRender from './DocumentRender'
5
- import ConditionsRunner from './ConditionsRunner'
6
- import OVC_TYPE from './ovc.type'
7
- import OvcConverter, { OldOVC } from './OvcConverter'
8
9
  import NumAuto from './NumAuto'
9
10
  import IntputsInitiator from './InputsInitiator'
10
11
  import FillPdfForm from './FillPdfForm'
@@ -38,7 +39,7 @@ class Prerender {
38
39
 
39
40
  private references: Types.ReferencesType
40
41
 
41
- private ovc: OVC_TYPE
42
+ private ovc: InputsType
42
43
 
43
44
  private conditions: ConditionsRunner
44
45
 
@@ -52,7 +53,7 @@ class Prerender {
52
53
 
53
54
  private renderedDocuments: Record<string, string | FDFType> = {}
54
55
 
55
- constructor(model: ModelV3, ovc: OVC_TYPE | OldOVC) {
56
+ constructor(model: ModelV3, ovc: InputsType | OvcType) {
56
57
  this.model = model
57
58
 
58
59
  // Initiating num auto
@@ -62,9 +63,7 @@ class Prerender {
62
63
  this.references = new ReferencesParser(model).getReferences()
63
64
 
64
65
  // Converting OVC if needed
65
- this.ovc = OvcConverter.isOvc(ovc)
66
- ? OvcConverter.convertToOptionsVariables(ovc, this.references)
67
- : ovc
66
+ this.ovc = OvcConverter.isOvc(ovc) ? OvcConverter.convertToOptionsVariables(ovc, this.references) : ovc
68
67
 
69
68
  // Initiating inputs
70
69
  const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
@@ -79,15 +78,27 @@ class Prerender {
79
78
  this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs)
80
79
 
81
80
  this.generateDocumentNamesHash()
82
- this.generateAllDocuments()
83
- this.fillPdfForms()
81
+ }
82
+
83
+ public getDocumentsIndexWithoutFdf() {
84
+ return this.documentsIndex
84
85
  }
85
86
 
86
87
  public getDocumentsIndex() {
88
+ this.generateAllDocuments()
89
+ this.fillPdfForms()
87
90
  return this.documentsIndex
88
91
  }
89
92
 
90
93
  public getDocument(documentNameHash: string) {
94
+ if (this.renderedDocuments[documentNameHash]) {
95
+ return this.renderedDocuments[documentNameHash]
96
+ }
97
+
98
+ const index = this.documentsIndex[documentNameHash]
99
+
100
+ this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index) ? this.pdfFiller.fillDocument(index.slug) : this.documentRender.renderDocument(index.slug)
101
+
91
102
  return this.renderedDocuments[documentNameHash]
92
103
  }
93
104
 
@@ -1,7 +1,7 @@
1
1
  import { Types } from '@legalplace/referencesparser'
2
- import ConditionsRunner from './ConditionsRunner'
2
+ import ConditionsRunner from '@legalplace/conditions-runner'
3
+ import InputsType from '@legalplace/types/dist/inputs'
3
4
  import OptionRender from './OptionRender'
4
- import OVC_TYPE from './ovc.type'
5
5
  import NumAuto from './NumAuto'
6
6
 
7
7
  class SectionRender {
@@ -15,11 +15,11 @@ class SectionRender {
15
15
 
16
16
  conditions: ConditionsRunner
17
17
 
18
- ovc: OVC_TYPE
18
+ ovc: InputsType
19
19
 
20
20
  private NumAuto: NumAuto
21
21
 
22
- constructor(options: { references: Types.ReferencesType; conditions: ConditionsRunner; ovc: OVC_TYPE; documentName: string; currentSection: number; numauto: NumAuto }) {
22
+ constructor(options: { references: Types.ReferencesType; conditions: ConditionsRunner; ovc: InputsType; documentName: string; currentSection: number; numauto: NumAuto }) {
23
23
  this.references = options.references
24
24
  this.conditions = options.conditions
25
25
  this.documentName = options.documentName
@@ -1,15 +1,15 @@
1
1
  import { Types } from '@legalplace/referencesparser'
2
- import ConditionsRunner from '../ConditionsRunner'
3
- import OVC_TYPE from '../ovc.type'
2
+ import ConditionsRunner from '@legalplace/conditions-runner'
3
+ import InputsType from '@legalplace/types/dist/inputs'
4
4
 
5
5
  class FillPdfFormBase {
6
6
  references: Types.ReferencesType
7
7
 
8
8
  conditions: ConditionsRunner
9
9
 
10
- ovc: OVC_TYPE
10
+ ovc: InputsType
11
11
 
12
- constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE) {
12
+ constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: InputsType) {
13
13
  this.references = references
14
14
  this.conditions = conditions
15
15
  this.ovc = ovc
@@ -1,24 +0,0 @@
1
- import { Types } from '@legalplace/referencesparser';
2
- import { ConditionV3 } from '@legalplace/models-v3-types';
3
- import { ConditionDataMap } from './DataPopulator';
4
- declare type OVC_TYPE = {
5
- options: {
6
- [key: string]: boolean[];
7
- };
8
- variables: {
9
- [key: string]: (number | string)[];
10
- };
11
- };
12
- declare class ConditionsRunner {
13
- private references;
14
- private ovc;
15
- constructor(references: Types.ReferencesType, ovc: OVC_TYPE);
16
- isOptionRelatedToOption(optionA: number, optionB: number): boolean;
17
- isVariableRelatedToOption(variableId: number, optionId: number): boolean;
18
- isVariableRelatedToVariable(variableA: number, variableB: number): boolean;
19
- executeCondition(condition: {
20
- dataMap: ConditionDataMap;
21
- conditions: ConditionV3;
22
- }, id: number, index: number, conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'): any;
23
- }
24
- export default ConditionsRunner;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var lplogic_1 = __importDefault(require("@legalplace/lplogic"));
7
- var DataPopulator_1 = __importDefault(require("./DataPopulator"));
8
- var conditionsCache = {};
9
- var ConditionsRunner = (function () {
10
- function ConditionsRunner(references, ovc) {
11
- this.references = references;
12
- this.ovc = ovc;
13
- }
14
- ConditionsRunner.prototype.isOptionRelatedToOption = function (optionA, optionB) {
15
- var OptionBParents = this.references.relations.options[optionB].parents;
16
- var OptionBRoot = OptionBParents[OptionBParents.length - 1];
17
- var OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined;
18
- if (OptionBRootRelations) {
19
- if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
20
- return true;
21
- }
22
- }
23
- return false;
24
- };
25
- ConditionsRunner.prototype.isVariableRelatedToOption = function (variableId, optionId) {
26
- var variableParentId = this.references.relations.variables[variableId].parents[0];
27
- var optionParents = this.references.relations.options[variableParentId].parents;
28
- var optionRoot = optionParents[optionParents.length - 1];
29
- var optionRootRelations = optionRoot ? this.references.relations.options[optionRoot] : undefined;
30
- if (optionRootRelations) {
31
- if (optionRootRelations.children.options.includes(optionId) || optionRootRelations.dependants.includes(optionId)) {
32
- return true;
33
- }
34
- }
35
- return false;
36
- };
37
- ConditionsRunner.prototype.isVariableRelatedToVariable = function (variableA, variableB) {
38
- var optionA = this.references.relations.variables[variableA].parents[0];
39
- var optionB = this.references.relations.variables[variableB].parents[0];
40
- var OptionBParents = this.references.relations.options[optionB].parents;
41
- var OptionBRoot = OptionBParents[OptionBParents.length - 1];
42
- var OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined;
43
- if (OptionBRootRelations) {
44
- if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
45
- return true;
46
- }
47
- }
48
- return false;
49
- };
50
- ConditionsRunner.prototype.executeCondition = function (condition, id, index, conditionType) {
51
- var _this = this;
52
- if (Array.isArray(condition))
53
- return condition.map(function (_condition) { return _this.executeCondition(_condition, id, index, conditionType); });
54
- var currentData;
55
- if (conditionType === 'options' || conditionType === 'optionValidator') {
56
- currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
57
- }
58
- else if (conditionType === 'variables' || conditionType === 'prefillers' || conditionType === 'variableValidator') {
59
- var dataId = this.references.relations.variables[id].parents[0];
60
- currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, dataId, index).getData();
61
- }
62
- else if (conditionType === 'sections' || conditionType === 'documents') {
63
- currentData = new DataPopulator_1.default(this, this.references, this.ovc, condition.dataMap, id, index).getData();
64
- }
65
- return lplogic_1.default(condition.conditions, currentData);
66
- };
67
- return ConditionsRunner;
68
- }());
69
- exports.default = ConditionsRunner;
@@ -1,53 +0,0 @@
1
- import { Types } from '@legalplace/referencesparser';
2
- import ConditionsRunner from './ConditionsRunner';
3
- declare type OVC_TYPE = {
4
- options: {
5
- [key: string]: boolean[];
6
- };
7
- variables: {
8
- [key: string]: (number | string)[];
9
- };
10
- };
11
- declare class DataPopulator {
12
- private references;
13
- private ovc;
14
- private conditionsRunner;
15
- private id?;
16
- private index?;
17
- private dataMap;
18
- private data;
19
- constructor(conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: OVC_TYPE, dataMap: ConditionDataMap, id?: number, index?: number);
20
- getData(): Readonly<ConditionData>;
21
- private populateConditions;
22
- private getOptionConditions;
23
- private getVariablesConditions;
24
- private populateVariables;
25
- private getVariableValues;
26
- private getVariableRootParent;
27
- private cleanArrayFromNullValues;
28
- populateOptions(): void;
29
- private getOptionInputs;
30
- private getOptionRootParent;
31
- private optionConditionValue;
32
- private variableConditionValue;
33
- private sectionConditionValue;
34
- }
35
- export interface ConditionDataMap {
36
- o: number[];
37
- v: number[];
38
- c: {
39
- o: number[];
40
- s: number[];
41
- v: number[];
42
- };
43
- }
44
- export interface ConditionData {
45
- o: Record<string, boolean[]>;
46
- v: Record<string, (string | number)[]>;
47
- c: {
48
- o: Record<string, boolean[]>;
49
- s: Record<string, boolean[]>;
50
- v: Record<string, boolean[]>;
51
- };
52
- }
53
- export default DataPopulator;