@legalplace/tagextractor 2.2.0 → 2.3.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 ADDED
@@ -0,0 +1,17 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 2.3.0 (2022-01-10)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix test version api[#4631](https://git.legalplace.eu/legalplace/tagextractor/issues/4631) ([f5f15c2](https://git.legalplace.eu/legalplace/tagextractor/commits/f5f15c2e5fdd9b0d98edb822f1aeb02d3823a6ca))
12
+ * remove unneeded gitlab-ci file api[#4631](https://git.legalplace.eu/legalplace/tagextractor/issues/4631) ([97b8424](https://git.legalplace.eu/legalplace/tagextractor/commits/97b8424281d804720438061bec2a7c0171f79b3b))
13
+
14
+
15
+ ### Features
16
+
17
+ * add the tagExtractor package api[#4631](https://git.legalplace.eu/legalplace/tagextractor/issues/4631) ([70c502a](https://git.legalplace.eu/legalplace/tagextractor/commits/70c502a734ea8bf1df842d4d44c89f360d96d7db))
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import TagExtractor from './libs/Extractor';
2
- import TagsType, { OptionTagType, VariableTagType } from './types/tags.type';
1
+ import TagExtractor from "./libs/Extractor";
2
+ import TagsType, { OptionTagType, VariableTagType } from "./types/tags.type";
3
3
  export type { TagsType, OptionTagType, VariableTagType };
4
4
  export default TagExtractor;
@@ -1,7 +1,7 @@
1
1
  import { ModelV3 } from "@legalplace/models-v3-types";
2
2
  import { ReferencesType } from "@legalplace/referencesparser/dist/libs/References.type";
3
- import InputsType from "@legalplace/types/dist/inputs";
4
- import OvcType from "@legalplace/types/dist/ovc";
3
+ import type InputsType from "@legalplace/types/dist/inputs";
4
+ import type OvcType from "@legalplace/types/dist/ovc";
5
5
  import TagsType from "../types/tags.type";
6
6
  declare class TagExtractor {
7
7
  private references;
@@ -10,11 +10,9 @@ class TagExtractor {
10
10
  constructor(modelOrReferences, ovc) {
11
11
  this.tags = {
12
12
  options: {},
13
- variables: {}
14
- };
15
- this.isReferencesType = (_obj) => {
16
- return Object.keys(_obj).some(key => key === "boxes");
13
+ variables: {},
17
14
  };
15
+ this.isReferencesType = (_obj) => Object.keys(_obj).some((key) => key === "boxes");
18
16
  this.references = this.isReferencesType(modelOrReferences)
19
17
  ? modelOrReferences
20
18
  : new referencesparser_1.ReferencesParser(modelOrReferences).references;
@@ -29,11 +27,11 @@ class TagExtractor {
29
27
  return this.tags;
30
28
  }
31
29
  extractFromOptions() {
32
- Object.keys(this.references.options).forEach(id => {
30
+ Object.keys(this.references.options).forEach((id) => {
33
31
  const { tags, label } = this.references.options[id].meta;
34
32
  if (Array.isArray(tags) && tags.length > 0 && this.inputs.options[id]) {
35
33
  this.inputs.options[id].forEach((v, index) => {
36
- tags.forEach(tag => {
34
+ tags.forEach((tag) => {
37
35
  if (this.tags.options[tag] === undefined)
38
36
  this.tags.options[tag] = [];
39
37
  this.tags.options[tag].push({
@@ -42,7 +40,7 @@ class TagExtractor {
42
40
  label,
43
41
  condition: this.getOptionCondition(parseInt(id, 10), index),
44
42
  visible: this.isOptionDisplayed(parseInt(id, 10), index),
45
- value: this.inputs.options[id][index]
43
+ value: this.inputs.options[id][index],
46
44
  });
47
45
  });
48
46
  });
@@ -50,11 +48,11 @@ class TagExtractor {
50
48
  });
51
49
  }
52
50
  extractFromVariables() {
53
- Object.keys(this.references.variables).forEach(id => {
51
+ Object.keys(this.references.variables).forEach((id) => {
54
52
  const { tags, label } = this.references.variables[id];
55
53
  if (Array.isArray(tags) && tags.length > 0 && this.inputs.variables[id]) {
56
54
  this.inputs.variables[id].forEach((v, index) => {
57
- tags.forEach(tag => {
55
+ tags.forEach((tag) => {
58
56
  if (this.tags.variables[tag] === undefined)
59
57
  this.tags.variables[tag] = [];
60
58
  this.tags.variables[tag].push({
@@ -63,7 +61,7 @@ class TagExtractor {
63
61
  label,
64
62
  condition: this.getVariableCondition(parseInt(id, 10), index) !== false,
65
63
  visible: this.isVariableDisplayed(parseInt(id, 10), index),
66
- value: this.inputs.variables[id][index]
64
+ value: this.inputs.variables[id][index],
67
65
  });
68
66
  });
69
67
  });
@@ -79,29 +77,25 @@ class TagExtractor {
79
77
  return ([
80
78
  variableCondition,
81
79
  parentOptionIsDisplayed,
82
- parentOptionIsTruethful
83
- ].filter(c => c !== true).length === 0);
80
+ parentOptionIsTruethful,
81
+ ].filter((c) => c !== true).length === 0);
84
82
  }
85
83
  isOptionDisplayed(id, index) {
86
84
  var _a;
87
85
  const optionCondition = this.getOptionCondition(id, index);
88
86
  const optionParents = ((_a = this.references.relations.options[id]) === null || _a === void 0 ? void 0 : _a.parents) || [];
89
- const parentsConditions = optionParents.map(optionId => {
90
- return this.getOptionCondition(optionId, index) !== false;
91
- });
92
- const parentsInputs = optionParents.map(optionId => {
93
- return this.inputs.options[optionId]
94
- ? this.inputs.options[optionId][index]
95
- : false;
96
- });
87
+ const parentsConditions = optionParents.map((optionId) => this.getOptionCondition(optionId, index) !== false);
88
+ const parentsInputs = optionParents.map((optionId) => this.inputs.options[optionId]
89
+ ? this.inputs.options[optionId][index]
90
+ : false);
97
91
  const parentSectionId = this.getOptionParentSection(id);
98
92
  const parentSectionCondition = this.getSectionCondition(parentSectionId) !== false;
99
93
  return ([
100
94
  optionCondition,
101
95
  parentSectionCondition,
102
96
  ...parentsConditions,
103
- ...parentsInputs
104
- ].filter(c => c !== true).length === 0);
97
+ ...parentsInputs,
98
+ ].filter((c) => c !== true).length === 0);
105
99
  }
106
100
  getVariableCondition(id, index) {
107
101
  const conditionObject = this.references.conditions.variables[id];
@@ -34,7 +34,7 @@ describe("TagsExtractor", () => {
34
34
  it("should return false when parent Option is not truthful", () => {
35
35
  const inputsWithParentsFalse = {
36
36
  ...simpleInputs,
37
- options: { ...simpleInputs.options, "6": [false] }
37
+ options: { ...simpleInputs.options, "6": [false] },
38
38
  };
39
39
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsFalse);
40
40
  expect(customTagExtractor.isVariableDisplayed(1, 0)).toBeFalsy();
@@ -42,7 +42,7 @@ describe("TagsExtractor", () => {
42
42
  it("should return true when all checks are okay", () => {
43
43
  const inputsWithAllChecks = {
44
44
  ...simpleInputs,
45
- options: { ...simpleInputs.options, "8": [true] }
45
+ options: { ...simpleInputs.options, "8": [true] },
46
46
  };
47
47
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithAllChecks);
48
48
  expect(customTagExtractor.isVariableDisplayed(1, 0)).toBeTruthy();
@@ -51,9 +51,7 @@ describe("TagsExtractor", () => {
51
51
  describe("IsOptionDisplayed", () => {
52
52
  it("should return false when option condition is false", () => {
53
53
  const getOptionCondition = jest.spyOn(Extractor_1.default.prototype, "getOptionCondition");
54
- getOptionCondition.mockImplementation((id, index) => {
55
- return !(id === 24 && index === 0);
56
- });
54
+ getOptionCondition.mockImplementation((id, index) => !(id === 24 && index === 0));
57
55
  expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
58
56
  expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
59
57
  });
@@ -65,16 +63,14 @@ describe("TagsExtractor", () => {
65
63
  });
66
64
  it("should return false when parentCondition contains false value", () => {
67
65
  const getOptionCondition = jest.spyOn(Extractor_1.default.prototype, "getOptionCondition");
68
- getOptionCondition.mockImplementation((id, index) => {
69
- return !(id === 6 && index === 0);
70
- });
66
+ getOptionCondition.mockImplementation((id, index) => !(id === 6 && index === 0));
71
67
  expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
72
68
  expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
73
69
  });
74
70
  it("should return false when parentsInputs list contains false value", () => {
75
71
  const inputsWithParentsInputsFalse = {
76
72
  ...simpleInputs,
77
- options: { ...simpleInputs.options, "6": [false] }
73
+ options: { ...simpleInputs.options, "6": [false] },
78
74
  };
79
75
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsInputsFalse);
80
76
  expect(customTagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
@@ -82,7 +78,7 @@ describe("TagsExtractor", () => {
82
78
  it("should not return errors when parentsInputs is undefined", () => {
83
79
  const inputsWithParentsInputsUndefined = {
84
80
  ...simpleInputs,
85
- options: { ...simpleInputs.options }
81
+ options: { ...simpleInputs.options },
86
82
  };
87
83
  delete inputsWithParentsInputsUndefined.options["6"];
88
84
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithParentsInputsUndefined);
@@ -116,9 +112,9 @@ describe("TagsExtractor", () => {
116
112
  ...simpleReferences.options,
117
113
  "7": {
118
114
  ...simpleReferences.options["7"],
119
- meta: { ...simpleReferences.options["7"].meta, tags: undefined }
120
- }
121
- }
115
+ meta: { ...simpleReferences.options["7"].meta, tags: undefined },
116
+ },
117
+ },
122
118
  };
123
119
  const customTagExtractor = new Extractor_1.default(referencesWithoutOptionTagArray, simpleInputs);
124
120
  expect(customTagExtractor.getTags.options).toMatchObject({});
@@ -130,9 +126,9 @@ describe("TagsExtractor", () => {
130
126
  ...simpleReferences.options,
131
127
  "7": {
132
128
  ...simpleReferences.options["7"],
133
- meta: { ...simpleReferences.options["7"].meta, tags: [] }
134
- }
135
- }
129
+ meta: { ...simpleReferences.options["7"].meta, tags: [] },
130
+ },
131
+ },
136
132
  };
137
133
  const customTagExtractor = new Extractor_1.default(referencesWithoutOptionTags, simpleInputs);
138
134
  expect(customTagExtractor.getTags.options).toMatchObject({});
@@ -140,7 +136,7 @@ describe("TagsExtractor", () => {
140
136
  it("should return empty tags when input's option is undefined", () => {
141
137
  const inputsWithoutOptionTaggedAnswer = {
142
138
  ...simpleInputs,
143
- options: { ...simpleInputs.options }
139
+ options: { ...simpleInputs.options },
144
140
  };
145
141
  delete inputsWithoutOptionTaggedAnswer.options["7"];
146
142
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithoutOptionTaggedAnswer);
@@ -149,7 +145,7 @@ describe("TagsExtractor", () => {
149
145
  it("should return option tag when champ multiples", () => {
150
146
  const inputWithChampMultiple = {
151
147
  ...simpleInputs,
152
- options: { ...simpleInputs.options, "7": [true, false] }
148
+ options: { ...simpleInputs.options, "7": [true, false] },
153
149
  };
154
150
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputWithChampMultiple);
155
151
  const expectedOptionTags = {
@@ -160,7 +156,7 @@ describe("TagsExtractor", () => {
160
156
  label: "Connaissiez-vous déjà LegalPlace ?",
161
157
  condition: true,
162
158
  visible: true,
163
- value: true
159
+ value: true,
164
160
  },
165
161
  {
166
162
  id: 7,
@@ -168,9 +164,9 @@ describe("TagsExtractor", () => {
168
164
  label: "Connaissiez-vous déjà LegalPlace ?",
169
165
  condition: true,
170
166
  visible: true,
171
- value: false
172
- }
173
- ]
167
+ value: false,
168
+ },
169
+ ],
174
170
  };
175
171
  expect(customTagExtractor.getTags.options).toMatchObject(expectedOptionTags);
176
172
  });
@@ -183,9 +179,9 @@ describe("TagsExtractor", () => {
183
179
  label: "Connaissiez-vous déjà LegalPlace ?",
184
180
  condition: true,
185
181
  visible: true,
186
- value: true
187
- }
188
- ]
182
+ value: true,
183
+ },
184
+ ],
189
185
  };
190
186
  expect(tagExtractor.getTags.options).toMatchObject(expectedOptionTags);
191
187
  });
@@ -196,8 +192,8 @@ describe("TagsExtractor", () => {
196
192
  ...simpleReferences,
197
193
  variables: {
198
194
  ...simpleReferences.variables,
199
- "1": { ...simpleReferences.variables["1"], tags: undefined }
200
- }
195
+ "1": { ...simpleReferences.variables["1"], tags: undefined },
196
+ },
201
197
  };
202
198
  const customTagExtractor = new Extractor_1.default(referenceWithoutVariableTagArray, simpleInputs);
203
199
  expect(customTagExtractor.getTags.variables).toMatchObject({});
@@ -207,8 +203,8 @@ describe("TagsExtractor", () => {
207
203
  ...simpleReferences,
208
204
  variables: {
209
205
  ...simpleReferences.variables,
210
- "1": { ...simpleReferences.variables["1"], tags: [] }
211
- }
206
+ "1": { ...simpleReferences.variables["1"], tags: [] },
207
+ },
212
208
  };
213
209
  const customTagExtractor = new Extractor_1.default(referenceWithoutTags, simpleInputs);
214
210
  expect(customTagExtractor.getTags.variables).toMatchObject({});
@@ -216,7 +212,7 @@ describe("TagsExtractor", () => {
216
212
  it("should return empty tags when input's variable is undefined", () => {
217
213
  const inputsWithoutVariableTaggedAnswer = {
218
214
  ...simpleInputs,
219
- variables: { ...simpleInputs.variables }
215
+ variables: { ...simpleInputs.variables },
220
216
  };
221
217
  delete inputsWithoutVariableTaggedAnswer.variables[1];
222
218
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputsWithoutVariableTaggedAnswer);
@@ -225,7 +221,7 @@ describe("TagsExtractor", () => {
225
221
  it("should not throw error when input's variable does not match any references variable", () => {
226
222
  const referenceWithoutMatchingVariable = {
227
223
  ...simpleReferences,
228
- variables: { ...simpleReferences.variables }
224
+ variables: { ...simpleReferences.variables },
229
225
  };
230
226
  delete referenceWithoutMatchingVariable.variables["2"];
231
227
  const customTagExtractor = new Extractor_1.default(referenceWithoutMatchingVariable, simpleInputs);
@@ -237,9 +233,9 @@ describe("TagsExtractor", () => {
237
233
  label: "Nom de l'entreprise",
238
234
  condition: false,
239
235
  visible: false,
240
- value: "Company"
241
- }
242
- ]
236
+ value: "Company",
237
+ },
238
+ ],
243
239
  };
244
240
  expect(customTagExtractor.getTags.variables).toMatchObject(expectedVariableTags);
245
241
  });
@@ -248,8 +244,8 @@ describe("TagsExtractor", () => {
248
244
  ...simpleInputs,
249
245
  variables: {
250
246
  ...simpleInputs.variables,
251
- "1": ["Nom de la companie", "Testing Company"]
252
- }
247
+ "1": ["Nom de la companie", "Testing Company"],
248
+ },
253
249
  };
254
250
  const customTagExtractor = new Extractor_1.default(simpleReferences, inputVariableWithChampMultiple);
255
251
  const expectedVariableTags = {
@@ -260,7 +256,7 @@ describe("TagsExtractor", () => {
260
256
  label: "Nom de l'entreprise",
261
257
  condition: false,
262
258
  visible: false,
263
- value: "Nom de la companie"
259
+ value: "Nom de la companie",
264
260
  },
265
261
  {
266
262
  id: 1,
@@ -268,9 +264,9 @@ describe("TagsExtractor", () => {
268
264
  label: "Nom de l'entreprise",
269
265
  condition: false,
270
266
  visible: false,
271
- value: "Testing Company"
272
- }
273
- ]
267
+ value: "Testing Company",
268
+ },
269
+ ],
274
270
  };
275
271
  expect(customTagExtractor.getTags.variables).toMatchObject(expectedVariableTags);
276
272
  });
package/jest.config.ts CHANGED
@@ -24,7 +24,7 @@ const jestConfig = {
24
24
  "src/**/*.ts",
25
25
  "src/**/*.tsx",
26
26
  "!**/node_modules/**",
27
- "!src/**/*.d.ts"
27
+ "!src/**/*.d.ts",
28
28
  ],
29
29
 
30
30
  // The directory where Jest should output its coverage files
@@ -89,7 +89,7 @@ const jestConfig = {
89
89
  moduleNameMapper: {
90
90
  "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
91
91
  "<rootDir>__mocks__/fileMock.js",
92
- "\\.(css|less|sass|scss)$": "identity-obj-proxy"
92
+ "\\.(css|less|sass|scss)$": "identity-obj-proxy",
93
93
  },
94
94
 
95
95
  // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
@@ -180,8 +180,8 @@ const jestConfig = {
180
180
 
181
181
  // A map from regular expressions to paths to transformers
182
182
  transform: {
183
- "^.+\\.tsx?$": "@swc-node/jest"
184
- }
183
+ "^.+\\.tsx?$": "@swc-node/jest",
184
+ },
185
185
 
186
186
  // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
187
187
  // transformIgnorePatterns: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/tagextractor",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "TagExtractor",
5
5
  "main": "dist/index.js",
6
6
  "repository": "https://git.legalplace.eu/legalplace/tagextractor",
@@ -27,19 +27,20 @@
27
27
  "@legalplace/prettier-config": "^2.1.3",
28
28
  "@legalplace/types": "1.1.0",
29
29
  "@swc-node/jest": "^1.4.3",
30
- "@types/jest": "27.0.2",
30
+ "@types/jest": "27.4.0",
31
31
  "@typescript-eslint/eslint-plugin": "^5.8.0",
32
32
  "eslint": "^8.5.0",
33
33
  "eslint-config-airbnb": "^19.0.2",
34
34
  "eslint-config-prettier": "^8.3.0",
35
35
  "eslint-config-react-app": "^7.0.0",
36
- "jest": "27.2.4",
36
+ "jest": "27.4.7",
37
37
  "jest-fetch-mock": "^3.0.3",
38
38
  "jest-junit": "^13.0.0",
39
39
  "prettier": "^2.5.1",
40
- "ts-jest": "27.0.5",
40
+ "ts-jest": "27.1.2",
41
41
  "ts-node": "^10.4.0",
42
42
  "typescript": "4.5.2"
43
43
  },
44
- "prettier": "@legalplace/prettier-config"
44
+ "prettier": "@legalplace/prettier-config",
45
+ "gitHead": "b78de6625e6f2651aeb2bdb470ae4dfc6e4a8487"
45
46
  }
package/setupJest.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable import/no-extraneous-dependencies */
2
2
  import { GlobalWithFetchMock } from "jest-fetch-mock";
3
3
 
4
- const customGlobal: GlobalWithFetchMock = (global as unknown) as GlobalWithFetchMock;
4
+ const customGlobal: GlobalWithFetchMock =
5
+ global as unknown as GlobalWithFetchMock;
5
6
  customGlobal.fetch = require("jest-fetch-mock");
6
7
 
7
8
  customGlobal.fetchMock = customGlobal.fetch;
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import TagExtractor from './libs/Extractor'
1
+ import TagExtractor from "./libs/Extractor";
2
2
 
3
- import TagsType, { OptionTagType, VariableTagType } from './types/tags.type'
3
+ import TagsType, { OptionTagType, VariableTagType } from "./types/tags.type";
4
4
 
5
- export type { TagsType, OptionTagType, VariableTagType }
6
- export default TagExtractor
5
+ export type { TagsType, OptionTagType, VariableTagType };
6
+ export default TagExtractor;
@@ -8,10 +8,10 @@ import inputsJson from "./fixtures/inputs.json";
8
8
  import referencesJson from "./fixtures/references.json";
9
9
  import modelJson from "./fixtures/model.json";
10
10
 
11
- const simpleReferences = (referencesJson as unknown) as ReferencesType;
12
- const simpleModel = (modelJson as unknown) as ModelV3;
13
- const simpleOvc = (ovcJson as unknown) as OvcType;
14
- const simpleInputs = (inputsJson as unknown) as InputsType;
11
+ const simpleReferences = referencesJson as unknown as ReferencesType;
12
+ const simpleModel = modelJson as unknown as ModelV3;
13
+ const simpleOvc = ovcJson as unknown as OvcType;
14
+ const simpleInputs = inputsJson as unknown as InputsType;
15
15
 
16
16
  describe("TagsExtractor", () => {
17
17
  const tagExtractor = new TagExtractor(simpleReferences, simpleInputs);
@@ -45,7 +45,7 @@ describe("TagsExtractor", () => {
45
45
  it("should return false when parent Option is not truthful", () => {
46
46
  const inputsWithParentsFalse = {
47
47
  ...simpleInputs,
48
- options: { ...simpleInputs.options, "6": [false] }
48
+ options: { ...simpleInputs.options, "6": [false] },
49
49
  };
50
50
  const customTagExtractor = new TagExtractor(
51
51
  simpleReferences,
@@ -56,7 +56,7 @@ describe("TagsExtractor", () => {
56
56
  it("should return true when all checks are okay", () => {
57
57
  const inputsWithAllChecks = {
58
58
  ...simpleInputs,
59
- options: { ...simpleInputs.options, "8": [true] }
59
+ options: { ...simpleInputs.options, "8": [true] },
60
60
  };
61
61
  const customTagExtractor = new TagExtractor(
62
62
  simpleReferences,
@@ -72,9 +72,9 @@ describe("TagsExtractor", () => {
72
72
  TagExtractor.prototype as any,
73
73
  "getOptionCondition"
74
74
  );
75
- getOptionCondition.mockImplementation((id, index) => {
76
- return !(id === 24 && index === 0);
77
- });
75
+ getOptionCondition.mockImplementation(
76
+ (id, index) => !(id === 24 && index === 0)
77
+ );
78
78
 
79
79
  expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
80
80
  expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
@@ -94,9 +94,9 @@ describe("TagsExtractor", () => {
94
94
  TagExtractor.prototype as any,
95
95
  "getOptionCondition"
96
96
  );
97
- getOptionCondition.mockImplementation((id, index) => {
98
- return !(id === 6 && index === 0);
99
- });
97
+ getOptionCondition.mockImplementation(
98
+ (id, index) => !(id === 6 && index === 0)
99
+ );
100
100
 
101
101
  expect(tagExtractor.isOptionDisplayed(24, 0)).toBeFalsy();
102
102
  expect(getOptionCondition).toHaveBeenCalledWith(24, 0);
@@ -104,7 +104,7 @@ describe("TagsExtractor", () => {
104
104
  it("should return false when parentsInputs list contains false value", () => {
105
105
  const inputsWithParentsInputsFalse = {
106
106
  ...simpleInputs,
107
- options: { ...simpleInputs.options, "6": [false] }
107
+ options: { ...simpleInputs.options, "6": [false] },
108
108
  };
109
109
  const customTagExtractor = new TagExtractor(
110
110
  simpleReferences,
@@ -116,7 +116,7 @@ describe("TagsExtractor", () => {
116
116
  it("should not return errors when parentsInputs is undefined", () => {
117
117
  const inputsWithParentsInputsUndefined = {
118
118
  ...simpleInputs,
119
- options: { ...simpleInputs.options }
119
+ options: { ...simpleInputs.options },
120
120
  };
121
121
  delete inputsWithParentsInputsUndefined.options["6"];
122
122
  const customTagExtractor = new TagExtractor(
@@ -156,9 +156,9 @@ describe("TagsExtractor", () => {
156
156
  ...simpleReferences.options,
157
157
  "7": {
158
158
  ...simpleReferences.options["7"],
159
- meta: { ...simpleReferences.options["7"].meta, tags: undefined }
160
- }
161
- }
159
+ meta: { ...simpleReferences.options["7"].meta, tags: undefined },
160
+ },
161
+ },
162
162
  };
163
163
  const customTagExtractor = new TagExtractor(
164
164
  referencesWithoutOptionTagArray,
@@ -174,9 +174,9 @@ describe("TagsExtractor", () => {
174
174
  ...simpleReferences.options,
175
175
  "7": {
176
176
  ...simpleReferences.options["7"],
177
- meta: { ...simpleReferences.options["7"].meta, tags: [] }
178
- }
179
- }
177
+ meta: { ...simpleReferences.options["7"].meta, tags: [] },
178
+ },
179
+ },
180
180
  };
181
181
  const customTagExtractor = new TagExtractor(
182
182
  referencesWithoutOptionTags,
@@ -188,7 +188,7 @@ describe("TagsExtractor", () => {
188
188
  it("should return empty tags when input's option is undefined", () => {
189
189
  const inputsWithoutOptionTaggedAnswer = {
190
190
  ...simpleInputs,
191
- options: { ...simpleInputs.options }
191
+ options: { ...simpleInputs.options },
192
192
  };
193
193
  delete inputsWithoutOptionTaggedAnswer.options["7"];
194
194
  const customTagExtractor = new TagExtractor(
@@ -201,7 +201,7 @@ describe("TagsExtractor", () => {
201
201
  it("should return option tag when champ multiples", () => {
202
202
  const inputWithChampMultiple = {
203
203
  ...simpleInputs,
204
- options: { ...simpleInputs.options, "7": [true, false] }
204
+ options: { ...simpleInputs.options, "7": [true, false] },
205
205
  };
206
206
  const customTagExtractor = new TagExtractor(
207
207
  simpleReferences,
@@ -215,7 +215,7 @@ describe("TagsExtractor", () => {
215
215
  label: "Connaissiez-vous déjà LegalPlace ?",
216
216
  condition: true,
217
217
  visible: true,
218
- value: true
218
+ value: true,
219
219
  },
220
220
  {
221
221
  id: 7,
@@ -223,9 +223,9 @@ describe("TagsExtractor", () => {
223
223
  label: "Connaissiez-vous déjà LegalPlace ?",
224
224
  condition: true,
225
225
  visible: true,
226
- value: false
227
- }
228
- ]
226
+ value: false,
227
+ },
228
+ ],
229
229
  };
230
230
  expect(customTagExtractor.getTags.options).toMatchObject(
231
231
  expectedOptionTags
@@ -240,9 +240,9 @@ describe("TagsExtractor", () => {
240
240
  label: "Connaissiez-vous déjà LegalPlace ?",
241
241
  condition: true,
242
242
  visible: true,
243
- value: true
244
- }
245
- ]
243
+ value: true,
244
+ },
245
+ ],
246
246
  };
247
247
  expect(tagExtractor.getTags.options).toMatchObject(expectedOptionTags);
248
248
  });
@@ -253,8 +253,8 @@ describe("TagsExtractor", () => {
253
253
  ...simpleReferences,
254
254
  variables: {
255
255
  ...simpleReferences.variables,
256
- "1": { ...simpleReferences.variables["1"], tags: undefined }
257
- }
256
+ "1": { ...simpleReferences.variables["1"], tags: undefined },
257
+ },
258
258
  };
259
259
  const customTagExtractor = new TagExtractor(
260
260
  referenceWithoutVariableTagArray,
@@ -268,8 +268,8 @@ describe("TagsExtractor", () => {
268
268
  ...simpleReferences,
269
269
  variables: {
270
270
  ...simpleReferences.variables,
271
- "1": { ...simpleReferences.variables["1"], tags: [] }
272
- }
271
+ "1": { ...simpleReferences.variables["1"], tags: [] },
272
+ },
273
273
  };
274
274
  const customTagExtractor = new TagExtractor(
275
275
  referenceWithoutTags,
@@ -281,7 +281,7 @@ describe("TagsExtractor", () => {
281
281
  it("should return empty tags when input's variable is undefined", () => {
282
282
  const inputsWithoutVariableTaggedAnswer = {
283
283
  ...simpleInputs,
284
- variables: { ...simpleInputs.variables }
284
+ variables: { ...simpleInputs.variables },
285
285
  };
286
286
  delete inputsWithoutVariableTaggedAnswer.variables[1];
287
287
  const customTagExtractor = new TagExtractor(
@@ -294,7 +294,7 @@ describe("TagsExtractor", () => {
294
294
  it("should not throw error when input's variable does not match any references variable", () => {
295
295
  const referenceWithoutMatchingVariable = {
296
296
  ...simpleReferences,
297
- variables: { ...simpleReferences.variables }
297
+ variables: { ...simpleReferences.variables },
298
298
  };
299
299
  delete referenceWithoutMatchingVariable.variables["2"];
300
300
 
@@ -310,9 +310,9 @@ describe("TagsExtractor", () => {
310
310
  label: "Nom de l'entreprise",
311
311
  condition: false,
312
312
  visible: false,
313
- value: "Company"
314
- }
315
- ]
313
+ value: "Company",
314
+ },
315
+ ],
316
316
  };
317
317
 
318
318
  expect(customTagExtractor.getTags.variables).toMatchObject(
@@ -324,8 +324,8 @@ describe("TagsExtractor", () => {
324
324
  ...simpleInputs,
325
325
  variables: {
326
326
  ...simpleInputs.variables,
327
- "1": ["Nom de la companie", "Testing Company"]
328
- }
327
+ "1": ["Nom de la companie", "Testing Company"],
328
+ },
329
329
  };
330
330
  const customTagExtractor = new TagExtractor(
331
331
  simpleReferences,
@@ -339,7 +339,7 @@ describe("TagsExtractor", () => {
339
339
  label: "Nom de l'entreprise",
340
340
  condition: false,
341
341
  visible: false,
342
- value: "Nom de la companie"
342
+ value: "Nom de la companie",
343
343
  },
344
344
  {
345
345
  id: 1,
@@ -347,9 +347,9 @@ describe("TagsExtractor", () => {
347
347
  label: "Nom de l'entreprise",
348
348
  condition: false,
349
349
  visible: false,
350
- value: "Testing Company"
351
- }
352
- ]
350
+ value: "Testing Company",
351
+ },
352
+ ],
353
353
  };
354
354
 
355
355
  expect(customTagExtractor.getTags.variables).toMatchObject(
@@ -3,8 +3,8 @@ import { ReferencesParser, Types } from "@legalplace/referencesparser";
3
3
  import { ReferencesType } from "@legalplace/referencesparser/dist/libs/References.type";
4
4
  import ConditionsRunner from "@legalplace/conditions-runner";
5
5
  import OvcConverter from "@legalplace/ovc-converter";
6
- import InputsType from "@legalplace/types/dist/inputs";
7
- import OvcType from "@legalplace/types/dist/ovc";
6
+ import type InputsType from "@legalplace/types/dist/inputs";
7
+ import type OvcType from "@legalplace/types/dist/ovc";
8
8
  import TagsType from "../types/tags.type";
9
9
 
10
10
  class TagExtractor {
@@ -16,15 +16,14 @@ class TagExtractor {
16
16
 
17
17
  private tags: TagsType = {
18
18
  options: {},
19
- variables: {}
19
+ variables: {},
20
20
  };
21
21
 
22
22
  private isReferencesType = (
23
23
  _obj: ModelV3 | ReferencesType
24
- ): _obj is ReferencesType => {
24
+ ): _obj is ReferencesType =>
25
25
  // We check if the object contains one of the fields only contained in ReferencesType
26
- return Object.keys(_obj).some(key => key === "boxes");
27
- };
26
+ Object.keys(_obj).some((key) => key === "boxes");
28
27
 
29
28
  constructor(
30
29
  modelOrReferences: ModelV3 | ReferencesType,
@@ -57,12 +56,12 @@ class TagExtractor {
57
56
  * Reads Options
58
57
  */
59
58
  private extractFromOptions() {
60
- Object.keys(this.references.options).forEach(id => {
59
+ Object.keys(this.references.options).forEach((id) => {
61
60
  const { tags, label } = this.references.options[id].meta;
62
61
 
63
62
  if (Array.isArray(tags) && tags.length > 0 && this.inputs.options[id]) {
64
63
  this.inputs.options[id].forEach((v, index) => {
65
- tags.forEach(tag => {
64
+ tags.forEach((tag) => {
66
65
  if (this.tags.options[tag] === undefined)
67
66
  this.tags.options[tag] = [];
68
67
  this.tags.options[tag].push({
@@ -71,7 +70,7 @@ class TagExtractor {
71
70
  label,
72
71
  condition: this.getOptionCondition(parseInt(id, 10), index),
73
72
  visible: this.isOptionDisplayed(parseInt(id, 10), index),
74
- value: this.inputs.options[id][index]
73
+ value: this.inputs.options[id][index],
75
74
  });
76
75
  });
77
76
  });
@@ -83,12 +82,12 @@ class TagExtractor {
83
82
  * Reads Variables
84
83
  */
85
84
  private extractFromVariables() {
86
- Object.keys(this.references.variables).forEach(id => {
85
+ Object.keys(this.references.variables).forEach((id) => {
87
86
  const { tags, label } = this.references.variables[id];
88
87
 
89
88
  if (Array.isArray(tags) && tags.length > 0 && this.inputs.variables[id]) {
90
89
  this.inputs.variables[id].forEach((v, index) => {
91
- tags.forEach(tag => {
90
+ tags.forEach((tag) => {
92
91
  if (this.tags.variables[tag] === undefined)
93
92
  this.tags.variables[tag] = [];
94
93
  this.tags.variables[tag].push({
@@ -98,7 +97,7 @@ class TagExtractor {
98
97
  condition:
99
98
  this.getVariableCondition(parseInt(id, 10), index) !== false,
100
99
  visible: this.isVariableDisplayed(parseInt(id, 10), index),
101
- value: this.inputs.variables[id][index]
100
+ value: this.inputs.variables[id][index],
102
101
  });
103
102
  });
104
103
  });
@@ -127,8 +126,8 @@ class TagExtractor {
127
126
  [
128
127
  variableCondition,
129
128
  parentOptionIsDisplayed,
130
- parentOptionIsTruethful
131
- ].filter(c => c !== true).length === 0
129
+ parentOptionIsTruethful,
130
+ ].filter((c) => c !== true).length === 0
132
131
  );
133
132
  }
134
133
 
@@ -141,15 +140,15 @@ class TagExtractor {
141
140
  // Getting variable's conditions & executing it if any
142
141
  const optionCondition = this.getOptionCondition(id, index);
143
142
  const optionParents = this.references.relations.options[id]?.parents || [];
144
- const parentsConditions = optionParents.map(optionId => {
145
- return this.getOptionCondition(optionId, index) !== false;
146
- });
147
- const parentsInputs = optionParents.map(optionId => {
143
+ const parentsConditions = optionParents.map(
144
+ (optionId) => this.getOptionCondition(optionId, index) !== false
145
+ );
146
+ const parentsInputs = optionParents.map((optionId) =>
148
147
  // If the parent option is not already defined we set the displayed parameter to false
149
- return this.inputs.options[optionId]
148
+ this.inputs.options[optionId]
150
149
  ? this.inputs.options[optionId][index]
151
- : false;
152
- });
150
+ : false
151
+ );
153
152
  const parentSectionId = this.getOptionParentSection(id);
154
153
  const parentSectionCondition =
155
154
  this.getSectionCondition(parentSectionId) !== false;
@@ -159,8 +158,8 @@ class TagExtractor {
159
158
  optionCondition,
160
159
  parentSectionCondition,
161
160
  ...parentsConditions,
162
- ...parentsInputs
163
- ].filter(c => c !== true).length === 0
161
+ ...parentsInputs,
162
+ ].filter((c) => c !== true).length === 0
164
163
  );
165
164
  }
166
165
 
@@ -1,24 +1,24 @@
1
1
  interface TagsType {
2
- options: Record<string, OptionTagType[]>
3
- variables: Record<string, VariableTagType[]>
2
+ options: Record<string, OptionTagType[]>;
3
+ variables: Record<string, VariableTagType[]>;
4
4
  }
5
5
 
6
6
  export interface OptionTagType {
7
- id: number
8
- index: number
9
- label: string
10
- condition: boolean
11
- visible: boolean
12
- value: boolean
7
+ id: number;
8
+ index: number;
9
+ label: string;
10
+ condition: boolean;
11
+ visible: boolean;
12
+ value: boolean;
13
13
  }
14
14
 
15
15
  export interface VariableTagType {
16
- id: number
17
- index: number
18
- label: string
19
- condition: boolean
20
- visible: boolean
21
- value: string | number
16
+ id: number;
17
+ index: number;
18
+ label: string;
19
+ condition: boolean;
20
+ visible: boolean;
21
+ value: string | number;
22
22
  }
23
23
 
24
- export default TagsType
24
+ export default TagsType;
package/tsconfig.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
+ "extends": "../../tsconfig.json",
2
3
  "compilerOptions": {
3
4
  "target": "es2019",
4
5
  "module": "commonjs",
5
6
  "outDir": "dist",
6
7
  "lib": ["dom", "dom.iterable", "esnext"],
7
8
  "strict": true,
8
- "typeRoots": ["node_modules/@types"],
9
+ "typeRoots": ["node_modules/@types", "../../node_modules/@types"],
9
10
  "useUnknownInCatchVariables": false,
10
11
  "esModuleInterop": true,
11
12
  "removeComments": true,
package/.gitlab-ci.yml DELETED
@@ -1,44 +0,0 @@
1
- image: 148253454541.dkr.ecr.eu-west-1.amazonaws.com/deploydock:node14
2
-
3
- stages:
4
- - setup
5
- - publish
6
-
7
- before_script:
8
- - export PATH=$PATH:./node_modules/.bin/
9
-
10
- variables:
11
- DOCKER_DRIVER: overlay2
12
-
13
- setup:
14
- stage: setup
15
- artifacts:
16
- paths:
17
- - dist/
18
- only:
19
- changes:
20
- - yarn.lock
21
- - package.json
22
- - .gitlab-ci.yml
23
- script:
24
- - echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
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
- - echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
37
- - npm publish
38
- environment:
39
- name: development
40
- only:
41
- refs:
42
- - master
43
- changes:
44
- - package.json
@@ -1,25 +0,0 @@
1
- {
2
- "eslint.enable": true,
3
- "editor.tabSize": 2,
4
- "eslint.validate": [
5
- "javascript",
6
- "javascriptreact",
7
- "typescript",
8
- "typescriptreact"
9
- ],
10
- "eslint.options": {
11
- "extensions": [".ts", ".tsx", ".js", ".jsx"]
12
- },
13
- "files.autoSave": "onFocusChange",
14
- "editor.formatOnSave": true,
15
- "editor.formatOnType": true,
16
- "prettier.singleQuote": true,
17
- "eslint.packageManager": "yarn",
18
- "eslint.quiet": true,
19
- "editor.codeActionsOnSave": {
20
- "source.fixAll.eslint": true
21
- },
22
- "typescript.tsdk": "node_modules/typescript/lib",
23
- "editor.formatOnPaste": true,
24
- "files.insertFinalNewline": true
25
- }