@legalplace/prerenderx 2.5.3 → 2.5.5-alpha

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 @@
1
+ { "o": { "64": 65, "67": 68, "149": 150, "152": 153, "159": 160, "176": 177, "323": 324, "330": 331, "340": 341, "343": 344, "349": 350, "400": 403, "426": 427, "550": [""], "561": [""], "571": [""], "634": 74 }, "v": { "2": [""], "3": [""], "4": [""], "5": [""], "6": [""], "7": [""], "8": [""], "9": [""], "10": [""], "11": [""], "13": [""], "14": [""], "15": [""], "28": [""], "29": "", "30": "Samy", "31": "19/94/0226", "32": "Paris", "40": "", "41": "", "52": "", "53": "Monsieur", "56": "Madame", "57": "", "58": "jyr", "59": "11/11/1111", "61": "111", "64": "11/11/1111", "74": "", "81": "", "82": "", "83": "", "92": "", "93": "", "95": "", "97": "", "98": "", "99": "", "100": "", "101": "jytr", "129": "", "130": "", "131": "", "132": "", "133": "", "147": "", "148": "", "149": "", "150": "", "151": "", "152": "", "153": "yjt'", "154": "jytrjytr", "155": "", "165": ["Artisanat (Création, Fabrication, Réparation)"], "168": "0619487401", "169": "40 rue de paradis", "170": "75010", "171": "Paris", "177": "", "178": "75010", "179": "11/11/1111", "180": "au moins bac +3", "181": "licenciement économique", "182": "employé, ouvrier", "183": "", "184": "4", "186": "", "187": "60 rue François 1er - 75008 Paris", "188": "", "189": "", "190": "", "191": "", "192": "", "193": "jytrjytr", "194": "jytrjytr", "197": "Madame", "198": "Samy M'Nasri", "199": "19/94/0226", "200": "Paris", "207": "", "208": "", "209": "", "213": "M'Nasri", "214": "19/10/2021", "215": "0", "216": "jytr", "218": "", "219": "", "220": "", "221": "", "222": "", "223": "", "225": "", "265": ["Artisanat (Création, Fabrication, Réparation) - Broderie - "], "266": "", "268": "aaa", "273": "", "275": "", "277": "111111111111111", "278": "", "279": "", "280": [""], "281": [""], "282": [""], "283": ["Broderie"], "284": [""], "285": ["artisanale"], "286": "", "287": "FRANCE", "288": "Française", "289": "true", "294": "", "295": "", "296": "Française", "297": "FRANCE", "298": "", "299": "M'Nasri", "300": "FRANCE", "301": ["Broderie"], "302": "", "303": "", "304": "Samy", "305": "M'Nasri", "306": "", "307": "", "308": "", "309": "xavier.saintgeorges+super@legalplace.fr", "310": "xavier.saintgeorges+super@legalplace.fr", "311": [""], "312": [""], "313": [""], "314": [""], "315": [""], "316": [""], "317": "xavier.saintgeorges+super@legalplace.fr", "318": ["1"], "319": "1", "320": "", "321": "", "322": "", "323": "", "324": "", "325": "", "326": "Française", "327": "Française", "328": "FRANCE", "329": "FRANCE", "330": "x", "331": "", "332": "x", "333": "", "334": "", "335": "x", "336": "", "337": "", "338": "", "339": "", "340": "", "341": "", "342": "", "343": "", "344": "", "345": "", "348": "1", "349": "1", "350": "2", "352": "", "353": "", "354": "jytr", "355": "Samy M'Nasri", "356": "19/10/2021", "357": "false", "358": "optional", "359": "", "360": "[361]", "361": "19/10/2021", "362": "Nom", "363": "", "364": "", "365": "", "366": "40 rue de paradis 75010 Paris", "367": "", "368": "", "369": "", "370": "", "371": "", "372": "", "373": "", "374": "", "375": "", "376": "#domi-vf", "377": "", "378": "", "379": "40 rue de paradis 75010 Paris", "380": "représentant légal", "381": "40 rue de paradis 75010 Paris", "382": "Samy M'Nasri", "383": "newprocessupselloui", "384": "non", "385": "", "386": "non", "387": "signing", "388": "", "389": "", "390": "", "391": "", "392": "la micro-entreprise Samy M'Nasri", "393": "la micro-entreprise Samy M'Nasri", "394": "", "396": "", "397": "N/A (non applicable)", "401": "", "402": "", "403": "", "404": "", "405": "1" }, "c": { "72": false, "129": false, "196": false, "208": false, "210": false, "433": false, "434": false, "435": false, "437": true, "438": false, "439": false, "440": false, "445": false, "451": false, "452": false, "523": false, "525": false, "541": false, "579": [false], "580": [false], "581": [false], "677": false, "689": false, "733": false } }
package/dist/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/test.js ADDED
@@ -0,0 +1,12 @@
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 Prerender_1 = __importDefault(require("./libs/Prerender"));
7
+ var prod_ovc_json_1 = __importDefault(require("./prod_ovc.json"));
8
+ var model_json_1 = __importDefault(require("./model.json"));
9
+ console.time('test');
10
+ var docIndex = new Prerender_1.default(model_json_1.default, prod_ovc_json_1.default).getDocumentsIndex();
11
+ console.timeEnd('test');
12
+ console.log(JSON.stringify(docIndex));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/prerenderx",
3
- "version": "2.5.3",
3
+ "version": "2.5.5-alpha",
4
4
  "description": "PrerenderX",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/prerenderx",
@@ -11,13 +11,15 @@
11
11
  "lint": "tsc && eslint ./src/ --ext ts,js",
12
12
  "lint:fix": "tsc && eslint 'src/**/*.{js,jsx,ts,tsx}' --fix",
13
13
  "test": "jest",
14
- "build": "tsc"
14
+ "build": "tsc",
15
+ "release": "standard-version -a --no-verify"
15
16
  },
16
17
  "dependencies": {
17
- "@legalplace/lplogic": "^2.1.6",
18
- "@legalplace/models-v3-types": "^3.5.1",
19
- "@legalplace/referencesparser": "^1.6.3",
18
+ "@legalplace/lplogic": "2.1.6",
19
+ "@legalplace/models-v3-types": "3.5.1",
20
+ "@legalplace/referencesparser": "1.6.3",
20
21
  "crypto": "^1.0.1",
22
+ "standard-version": "^9.3.1",
21
23
  "typescript": "3.9.3"
22
24
  },
23
25
  "devDependencies": {
@@ -18,6 +18,33 @@ interface ConditionData {
18
18
  v: Record<string, (string | number)[]>
19
19
  }
20
20
 
21
+ const conditionsCache: {
22
+ [key: string]: boolean
23
+ } = {}
24
+
25
+ /**
26
+ * Generates cache key
27
+ * @param condition
28
+ * @param id
29
+ * @param index
30
+ * @param conditionType
31
+ * @returns string
32
+ */
33
+ const createConditionCacheKey = (
34
+ condition: {
35
+ dataMap: ConditionDataMap
36
+ conditions: ConditionV3
37
+ },
38
+ id: number,
39
+ index: number,
40
+ conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
41
+ ) => {
42
+ const conditionString = JSON.stringify(condition);
43
+
44
+ return `${id}-${index}-${conditionType}-${conditionString}`
45
+ }
46
+
47
+
21
48
  class ConditionsRunner {
22
49
  private references: Types.ReferencesType
23
50
 
@@ -92,8 +119,16 @@ class ConditionsRunner {
92
119
  index: number,
93
120
  conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
94
121
  ): any {
122
+ // In case we have multiple conditions let's run them here
95
123
  if (Array.isArray(condition)) return condition.map(_condition => this.executeCondition(_condition, id, index, conditionType))
96
124
 
125
+ // Generating cache key
126
+ const cacheKey = createConditionCacheKey(condition, id, index, conditionType)
127
+
128
+ // Checking if condition was already calculated
129
+ if (Object.prototype.hasOwnProperty.call(conditionsCache, cacheKey))
130
+ return conditionsCache[cacheKey]
131
+
97
132
  // Populating Data
98
133
  let currentData
99
134
  if (conditionType === 'options' || conditionType === 'optionValidator') {
@@ -105,7 +140,11 @@ class ConditionsRunner {
105
140
  currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, id, index).getData()
106
141
  }
107
142
 
108
- return LpLogic(condition.conditions, currentData)
143
+ // Running condition and storing it in cache
144
+ conditionsCache[cacheKey] = LpLogic(condition.conditions, currentData);
145
+
146
+ // Returning cache result
147
+ return conditionsCache[cacheKey];
109
148
  }
110
149
  }
111
150
 
@@ -1,6 +1,16 @@
1
1
  import { Types } from '@legalplace/referencesparser'
2
2
  import OVC_TYPE from './ovc.type'
3
3
 
4
+ /**
5
+ * Parses number to correct french number format ("," instead of ".")
6
+ */
7
+ const frenchNumber = (value: string | number) => {
8
+ let result = typeof value === 'number' ? value.toString() : value;
9
+ if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
10
+ result = result.trim().replace('.', ',');
11
+ return result;
12
+ };
13
+
4
14
  /**
5
15
  * Returns option's related variable values
6
16
  * @param optionId Option's id
@@ -31,8 +41,7 @@ export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, vari
31
41
 
32
42
  // Making sure all values are strings
33
43
  const cleanValues = value.map(currentValue => {
34
- if (typeof currentValue === 'number') return currentValue.toString()
35
- if (typeof currentValue === 'string') return currentValue
44
+ if (['number', 'string'].includes(typeof currentValue)) return frenchNumber(currentValue)
36
45
  return ''
37
46
  })
38
47