@inseefr/lunatic 2.6.3-rc.1 → 2.6.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.
Files changed (257) hide show
  1. package/README.md +49 -3
  2. package/lib/components/checkbox/checkbox-boolean/html/checkbox-boolean.js +3 -3
  3. package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +7 -1
  4. package/lib/components/checkbox/checkbox-group/checkbox-group-content.js +0 -2
  5. package/lib/components/checkbox/checkbox-group/html/checkbox-group-content.js +4 -2
  6. package/lib/components/checkbox/checkbox-group/html/checkbox-group.js +3 -3
  7. package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +2 -1
  8. package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +2 -1
  9. package/lib/components/checkbox/commons/checkbox-option.js +3 -1
  10. package/lib/components/commons/components/combo-box/combo-box-container.js +1 -2
  11. package/lib/components/commons/components/combo-box/combo-box.js +2 -2
  12. package/lib/components/commons/components/combo-box/selection/LabelOrInput.js +3 -1
  13. package/lib/components/commons/components/combo-box/selection/input.js +3 -1
  14. package/lib/components/commons/components/combo-box/selection/selection.js +3 -1
  15. package/lib/components/commons/components/errors/errors.js +12 -10
  16. package/lib/components/commons/components/errors/errors.spec.js +6 -6
  17. package/lib/components/component-set/html/__snapshots__/component-set.spec.tsx.snap +2 -0
  18. package/lib/components/component-set/html/component-set.js +2 -2
  19. package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +2 -0
  20. package/lib/components/datepicker/html/datepicker-input.js +4 -2
  21. package/lib/components/datepicker/html/datepicker.js +3 -3
  22. package/lib/components/datepicker/lunatic-datepicker.js +2 -1
  23. package/lib/components/dropdown/lunatic-dropdown.js +2 -1
  24. package/lib/components/index.js +4 -4
  25. package/lib/components/input/html/__snapshots__/input.spec.tsx.snap +2 -0
  26. package/lib/components/input/html/input.js +3 -3
  27. package/lib/components/input/lunatic-input.js +2 -1
  28. package/lib/components/input-number/html/__snapshots__/input-number.spec.tsx.snap +2 -2
  29. package/lib/components/input-number/html/input-number-thousand.js +4 -17
  30. package/lib/components/input-number/html/input-number.js +3 -5
  31. package/lib/components/input-number/lunatic-input-number.js +2 -3
  32. package/lib/components/loop/block-for-loop.js +10 -6
  33. package/lib/components/loop/roster-for-loop/roster-for-loop.js +35 -27
  34. package/lib/components/loop/utils/get-initial-nb-rows.js +17 -0
  35. package/lib/components/lunatic-components.js +7 -27
  36. package/lib/components/pairwise-links/index.js +13 -0
  37. package/lib/components/pairwise-links/orchestrator.js +71 -0
  38. package/lib/components/pairwise-links/pairwise-links.js +30 -27
  39. package/lib/components/pairwise-links/row.js +74 -0
  40. package/lib/components/radio/html/radio-group-content.js +4 -2
  41. package/lib/components/radio/html/radio-group.js +3 -3
  42. package/lib/components/radio/html/radio-option.js +3 -1
  43. package/lib/components/radio/lunatic-radio-group.js +2 -1
  44. package/lib/components/suggester/find-best-label/find-best-label.js +6 -6
  45. package/lib/components/suggester/idb-suggester/idb-suggester.js +4 -3
  46. package/lib/components/suggester/lunatic-suggester.js +7 -4
  47. package/lib/components/suggester/searching/create-searching.js +20 -39
  48. package/lib/components/switch/html/switch.js +2 -2
  49. package/lib/components/switch/lunatic-switch.js +2 -1
  50. package/lib/components/table/cell.js +89 -0
  51. package/lib/components/table/{table-header.js → header.js} +5 -3
  52. package/lib/components/table/index.js +13 -0
  53. package/lib/components/table/lunatic-table.js +15 -24
  54. package/lib/components/table/row.js +40 -0
  55. package/lib/components/table/table-orchestrator.js +35 -0
  56. package/lib/components/textarea/html/__snapshots__/textarea.spec.tsx.snap +2 -0
  57. package/lib/components/textarea/html/textarea.js +6 -4
  58. package/lib/components/textarea/lunatic-textarea.js +6 -3
  59. package/lib/hooks/use-auto-focus.js +26 -0
  60. package/lib/src/components/checkbox/checkbox-boolean/html/checkbox-boolean.d.ts +1 -1
  61. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group-content.d.ts +2 -1
  62. package/lib/src/components/checkbox/checkbox-group/html/checkbox-group.d.ts +1 -1
  63. package/lib/src/components/checkbox/commons/checkbox-option.d.ts +1 -0
  64. package/lib/src/components/commons/components/combo-box/combo-box-container.d.ts +2 -2
  65. package/lib/src/components/commons/components/combo-box/combo-box.d.ts +2 -2
  66. package/lib/src/components/commons/components/combo-box/combo-box.stories.d.ts +4 -6
  67. package/lib/src/components/commons/components/combo-box/selection/LabelOrInput.d.ts +1 -0
  68. package/lib/src/components/commons/components/combo-box/selection/input.d.ts +1 -0
  69. package/lib/src/components/commons/components/combo-box/selection/selection.d.ts +2 -1
  70. package/lib/src/components/commons/components/errors/errors.d.ts +6 -3
  71. package/lib/src/components/datepicker/html/datepicker-input.d.ts +2 -1
  72. package/lib/src/components/datepicker/html/datepicker.d.ts +1 -1
  73. package/lib/src/components/dropdown/html/dropdown-writable/dropdown-writable.d.ts +1 -1
  74. package/lib/src/components/dropdown/html/dropdown.d.ts +3 -1
  75. package/lib/src/components/index.d.ts +2 -2
  76. package/lib/src/components/input/html/input.d.ts +2 -2
  77. package/lib/src/components/input-number/html/input-number-thousand.d.ts +2 -2
  78. package/lib/src/components/input-number/html/input-number.d.ts +2 -3
  79. package/lib/src/components/loop/block-for-loop.d.ts +4 -3
  80. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +4 -3
  81. package/lib/src/components/loop/utils/get-initial-nb-rows.d.ts +4 -0
  82. package/lib/src/components/lunatic-components.d.ts +3 -5
  83. package/lib/src/components/pairwise-links/index.d.ts +1 -0
  84. package/lib/src/components/pairwise-links/orchestrator.d.ts +6 -0
  85. package/lib/src/components/pairwise-links/pairwise-links.d.ts +2 -1
  86. package/lib/src/components/pairwise-links/row.d.ts +7 -0
  87. package/lib/src/components/radio/html/radio-group-content.d.ts +2 -1
  88. package/lib/src/components/radio/html/radio-group.d.ts +1 -1
  89. package/lib/src/components/radio/html/radio-option.d.ts +1 -0
  90. package/lib/src/components/suggester/find-best-label/find-best-label.d.ts +1 -1
  91. package/lib/src/components/suggester/html/suggester.d.ts +1 -1
  92. package/lib/src/components/suggester/idb-suggester/idb-suggester.d.ts +5 -2
  93. package/lib/src/components/suggester/lunatic-suggester.d.ts +1 -1
  94. package/lib/src/components/suggester/searching/create-searching.d.ts +1 -1
  95. package/lib/src/components/switch/html/switch.d.ts +1 -1
  96. package/lib/src/components/table/cell.d.ts +19 -0
  97. package/lib/src/components/table/{table-header.d.ts → header.d.ts} +2 -2
  98. package/lib/src/components/table/index.d.ts +1 -0
  99. package/lib/src/components/table/lunatic-table.d.ts +1 -1
  100. package/lib/src/components/table/row.d.ts +18 -0
  101. package/lib/src/components/table/table-orchestrator.d.ts +4 -0
  102. package/lib/src/components/textarea/html/textarea.d.ts +3 -2
  103. package/lib/src/components/type.d.ts +9 -7
  104. package/lib/src/hooks/use-auto-focus.d.ts +6 -0
  105. package/lib/src/use-lunatic/actions.d.ts +19 -3
  106. package/lib/src/use-lunatic/commons/calculated-variables.d.ts +8 -0
  107. package/lib/src/use-lunatic/commons/compile-controls.d.ts +2 -3
  108. package/lib/src/use-lunatic/commons/execute-expression/create-execute-expression.d.ts +9 -0
  109. package/lib/src/use-lunatic/commons/execute-expression/create-memoizer.d.ts +8 -0
  110. package/lib/src/use-lunatic/commons/execute-expression/create-refresh-calculated.d.ts +24 -0
  111. package/lib/src/use-lunatic/commons/execute-expression/execute-expression.d.ts +11 -0
  112. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.d.ts +7 -0
  113. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.spec.d.ts +1 -0
  114. package/lib/src/use-lunatic/commons/execute-expression/get-safety-expression.d.ts +6 -0
  115. package/lib/src/use-lunatic/commons/execute-expression/index.d.ts +1 -0
  116. package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +418 -0
  117. package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +3 -2
  118. package/lib/src/use-lunatic/commons/fill-components/fill-components.d.ts +0 -6
  119. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +142 -107
  120. package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +89 -53
  121. package/lib/src/use-lunatic/commons/get-compatible-vtl-expression.d.ts +0 -1
  122. package/lib/src/use-lunatic/commons/get-component-value/get-component-value.d.ts +6 -0
  123. package/lib/src/use-lunatic/commons/get-component-value/index.d.ts +1 -0
  124. package/lib/src/use-lunatic/commons/get-data.d.ts +26 -0
  125. package/lib/src/use-lunatic/commons/index.d.ts +3 -0
  126. package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +9 -10
  127. package/lib/src/use-lunatic/reducer/reduce-handle-change/index.d.ts +1 -0
  128. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.d.ts +7 -0
  129. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.d.ts +1 -0
  130. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.d.ts +4 -0
  131. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.d.ts +15 -0
  132. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-missing.d.ts +7 -0
  133. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-resizing.d.ts +4 -0
  134. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.d.ts +14 -0
  135. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.d.ts +9 -0
  136. package/lib/src/use-lunatic/reducer/reduce-on-init.d.ts +12 -1
  137. package/lib/src/use-lunatic/reducer/reduce-on-init.spec.d.ts +1 -0
  138. package/lib/src/use-lunatic/type-source.d.ts +21 -7
  139. package/lib/src/use-lunatic/type.d.ts +12 -13
  140. package/lib/src/use-lunatic/use-lunatic.d.ts +62 -36
  141. package/lib/src/use-lunatic/use-suggesters.d.ts +2 -1
  142. package/lib/src/utils/array.d.ts +1 -6
  143. package/lib/src/utils/number.d.ts +0 -4
  144. package/lib/src/utils/suggester-workers/append-to-index/create-append-task.d.ts +1 -1
  145. package/lib/src/utils/suggester-workers/worker-path.d.ts +6 -0
  146. package/lib/src/utils/vtl/dataset-builder.d.ts +5 -0
  147. package/lib/src/utils/vtl/index.d.ts +1 -0
  148. package/lib/stories/behaviour/cleaning/source.json +151 -0
  149. package/lib/stories/behaviour/cleaning/test.stories.js +84 -0
  150. package/lib/stories/{questionnaires-test → behaviour}/controls/controls.stories.js +5 -5
  151. package/lib/stories/{questionnaires-test → behaviour/others}/test.stories.js +7 -7
  152. package/lib/stories/{paste-questionnaire → behaviour/paste}/test.stories.js +3 -3
  153. package/lib/stories/{resizing-questionnaire → behaviour/resizing}/test.stories.js +3 -3
  154. package/lib/use-lunatic/actions.js +3 -3
  155. package/lib/use-lunatic/commons/calculated-variables.js +104 -0
  156. package/lib/use-lunatic/commons/compile-controls.js +5 -3
  157. package/lib/use-lunatic/commons/execute-condition-filter.js +9 -1
  158. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.js +233 -0
  159. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.spec.js +155 -0
  160. package/lib/use-lunatic/commons/execute-expression/create-memoizer.js +63 -0
  161. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.js +149 -0
  162. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +130 -0
  163. package/lib/use-lunatic/commons/execute-expression/execute-expression.js +90 -0
  164. package/lib/use-lunatic/commons/execute-expression/execute-expression.spec.js +38 -0
  165. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.js +40 -0
  166. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.spec.js +31 -0
  167. package/lib/use-lunatic/commons/{fill-components/fill-iterations.js → execute-expression/get-safety-expression.js} +20 -30
  168. package/lib/use-lunatic/commons/execute-expression/index.js +13 -0
  169. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +3 -2
  170. package/lib/use-lunatic/{reducer/reduce-handle-change.js → commons/fill-components/fill-component-required.js} +8 -14
  171. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +7 -21
  172. package/lib/use-lunatic/commons/fill-components/fill-components.js +4 -5
  173. package/lib/use-lunatic/commons/fill-components/fill-from-state.js +2 -0
  174. package/lib/use-lunatic/commons/fill-components/fill-missing-response.js +13 -6
  175. package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +5 -58
  176. package/lib/use-lunatic/commons/get-compatible-vtl-expression.js +0 -1
  177. package/lib/use-lunatic/commons/get-component-value/get-component-value.js +174 -0
  178. package/lib/use-lunatic/commons/get-component-value/index.js +13 -0
  179. package/lib/use-lunatic/commons/get-data.js +80 -0
  180. package/lib/use-lunatic/commons/index.js +21 -0
  181. package/lib/use-lunatic/initial-state.js +4 -6
  182. package/lib/use-lunatic/reducer/overview/overview-on-change.js +1 -1
  183. package/lib/use-lunatic/reducer/reduce-handle-change/__mocks__/source-cleaning-loop.json +792 -0
  184. package/lib/use-lunatic/reducer/reduce-handle-change/index.js +13 -0
  185. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.js +78 -0
  186. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.js +46 -0
  187. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js +115 -0
  188. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.js +89 -0
  189. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-missing.js +88 -0
  190. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-resizing.js +119 -0
  191. package/lib/use-lunatic/{commons/variables/get-questionnaire-data.js → reducer/reduce-handle-change/reduce-variables-array.js} +32 -53
  192. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.js +28 -0
  193. package/lib/use-lunatic/reducer/reduce-on-init.js +184 -90
  194. package/lib/use-lunatic/reducer/reduce-on-init.spec.js +17 -0
  195. package/lib/use-lunatic/reducer/reducer.js +2 -2
  196. package/lib/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.js +4 -2
  197. package/lib/use-lunatic/use-lunatic.js +29 -22
  198. package/lib/use-lunatic/use-lunatic.test.js +36 -133
  199. package/lib/use-lunatic/use-suggesters.js +4 -3
  200. package/lib/utils/array.js +6 -57
  201. package/lib/utils/get-component-value.js +9 -3
  202. package/lib/utils/number.js +1 -13
  203. package/lib/utils/suggester-workers/append-to-index/create-append-task.js +4 -3
  204. package/lib/utils/suggester-workers/worker-path.js +29 -0
  205. package/lib/utils/vtl/dataset-builder.js +27 -0
  206. package/lib/utils/vtl/index.js +13 -0
  207. package/package.json +15 -10
  208. package/scripts/build/add-workers-to-public.js +44 -0
  209. package/scripts/build/workers-paths.js +44 -0
  210. package/workers-release/lunatic-append-worker-0.3.0-experimental.js +2 -0
  211. package/workers-release/lunatic-append-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
  212. package/workers-release/lunatic-label-worker-0.3.0-experimental.js +2 -0
  213. package/workers-release/lunatic-label-worker-0.3.0-experimental.js.LICENSE.txt +13 -0
  214. package/workers-release/lunatic-searching-worker-0.3.0-experimental.js +2 -0
  215. package/workers-release/lunatic-searching-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
  216. package/lib/hooks/use-track-changes.js +0 -50
  217. package/lib/src/hooks/use-track-changes.d.ts +0 -9
  218. package/lib/src/use-lunatic/commons/component.d.ts +0 -22
  219. package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +0 -112
  220. package/lib/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +0 -7
  221. package/lib/src/use-lunatic/commons/variables/behaviours/missing-behaviour.d.ts +0 -7
  222. package/lib/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.d.ts +0 -7
  223. package/lib/src/use-lunatic/commons/variables/get-questionnaire-data.d.ts +0 -4
  224. package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +0 -77
  225. package/lib/src/use-lunatic/reducer/reduce-handle-change.d.ts +0 -6
  226. package/lib/src/utils/env.d.ts +0 -1
  227. package/lib/src/utils/store-tools/worker-path.d.ts +0 -1
  228. package/lib/src/utils/variables.d.ts +0 -5
  229. package/lib/src/utils/vtl.d.ts +0 -14
  230. package/lib/use-lunatic/commons/component.js +0 -22
  231. package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +0 -39
  232. package/lib/use-lunatic/commons/variables/behaviours/missing-behaviour.js +0 -47
  233. package/lib/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +0 -78
  234. package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +0 -330
  235. package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +0 -216
  236. package/lib/utils/array.spec.js +0 -30
  237. package/lib/utils/env.js +0 -10
  238. package/lib/utils/store-tools/worker-path.js +0 -13
  239. package/lib/utils/suggester-workers/create-worker.js +0 -55
  240. package/lib/utils/variables.js +0 -37
  241. package/lib/utils/vtl.js +0 -100
  242. /package/lib/src/use-lunatic/commons/{variables/lunatic-variables-store.spec.d.ts → execute-expression/create-refresh-calculated.spec.d.ts} +0 -0
  243. /package/lib/src/{utils/array.spec.d.ts → use-lunatic/commons/execute-expression/execute-expression.spec.d.ts} +0 -0
  244. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +0 -0
  245. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +0 -0
  246. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees2_PasPageFin.json +0 -0
  247. /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -0
  248. /package/lib/stories/{questionnaires-test → behaviour}/controls/boucles-n.json +0 -0
  249. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.json +0 -0
  250. /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.stories.js +0 -0
  251. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_DeclarationsSimples.json +0 -0
  252. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_MinMaxSum_Boucles.json +0 -0
  253. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_QuestSimple_Boucles.json +0 -0
  254. /package/lib/stories/{questionnaires-test → behaviour/others}/V2_TCMRallyeGames.json +0 -0
  255. /package/lib/stories/{questionnaires-test → behaviour/others}/test-dylan.json +0 -0
  256. /package/lib/stories/{paste-questionnaire → behaviour/paste}/source.json +0 -0
  257. /package/lib/stories/{resizing-questionnaire → behaviour/resizing}/source.json +0 -0
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getInitialVariableValue = getInitialVariableValue;
7
- /**
8
- * Extract the initial value from the source.json and data.json
9
- */
10
- function getInitialVariableValue(variable) {
11
- var _data$variable$variab;
12
- var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
13
- switch (variable.variableType) {
14
- case 'EXTERNAL':
15
- case 'CALCULATED':
16
- return (_data$variable$variab = data[variable.variableType]) === null || _data$variable$variab === void 0 ? void 0 : _data$variable$variab[variable.name];
17
- case 'COLLECTED':
18
- var collectedData = data.COLLECTED;
19
- var fromData;
20
- if (collectedData && variable.name in collectedData) {
21
- var _collectedData$variab = collectedData[variable.name],
22
- COLLECTED = _collectedData$variab.COLLECTED,
23
- FORCED = _collectedData$variab.FORCED;
24
- fromData = COLLECTED !== null && COLLECTED !== void 0 ? COLLECTED : FORCED;
25
- }
26
- if ('values' in variable && variable.values) {
27
- var _ref, _fromData;
28
- var _variable$values = variable.values,
29
- _COLLECTED = _variable$values.COLLECTED,
30
- _FORCED = _variable$values.FORCED;
31
- return (_ref = (_fromData = fromData) !== null && _fromData !== void 0 ? _fromData : _FORCED) !== null && _ref !== void 0 ? _ref : _COLLECTED;
32
- }
33
- return undefined;
34
- default:
35
- return null;
36
- }
37
- }
package/lib/utils/vtl.js DELETED
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getExpressionAsString = getExpressionAsString;
7
- exports.getExpressionType = getExpressionType;
8
- exports.getVTLCompatibleValue = getVTLCompatibleValue;
9
- exports.interpretVTL = interpretVTL;
10
- exports.parseVTLVariables = parseVTLVariables;
11
- var _object = require("./object");
12
- var _trevas = require("@inseefr/trevas");
13
- var _antlr = _interopRequireDefault(require("antlr4"));
14
- var _vtl = require("@inseefr/vtl-2.0-antlr-tools");
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
17
- /**
18
- * Simplified version of interpret (that converts binding and value)
19
- */
20
- function interpretVTL(expression, bindings) {
21
- var result = (0, _trevas.interpret)(expression, (0, _object.objectMap)(bindings, function (k, v) {
22
- return [k, getVTLCompatibleValue(v)];
23
- }));
24
- if (isDataSet(result)) {
25
- return extractDataSetResult(result);
26
- }
27
- return result;
28
- }
29
-
30
- /**
31
- * Extract variables used in a VTL expression
32
- */
33
- function parseVTLVariables(expression) {
34
- try {
35
- var chars = new _antlr["default"].InputStream(expression);
36
- var lexer = new _vtl.VtlLexer(chars);
37
- var dependencySet = lexer.getAllTokens().reduce(function (acc, _ref) {
38
- var start = _ref.start,
39
- stop = _ref.stop,
40
- type = _ref.type;
41
- if (type === 234) {
42
- acc.add(expression.substring(start, stop + 1));
43
- }
44
- return acc;
45
- }, new Set());
46
- dependencySet["delete"](expression); // Prevent dependency loop
47
- return Array.from(dependencySet);
48
- } catch (e) {
49
- return [];
50
- }
51
- }
52
-
53
- /**
54
- * Transform a value to make it compatible with VTL (for bindings)
55
- */
56
- function getVTLCompatibleValue(value) {
57
- if (value === undefined) {
58
- return null;
59
- }
60
- if (Array.isArray(value)) {
61
- return {
62
- dataStructure: {
63
- result: {}
64
- },
65
- dataPoints: {
66
- result: value
67
- }
68
- };
69
- }
70
- return value;
71
- }
72
- function getExpressionType(expression) {
73
- if (typeof expression === 'string') {
74
- return 'VTL';
75
- }
76
- if (expression && _typeof(expression) === 'object' && 'type' in expression && typeof expression.type === 'string') {
77
- return expression.type;
78
- }
79
- return '';
80
- }
81
- function getExpressionAsString(expression) {
82
- if (typeof expression === 'string') {
83
- return expression;
84
- }
85
- if (expression && _typeof(expression) === 'object' && 'value' in expression && typeof expression.value === 'string') {
86
- return expression.value;
87
- }
88
- return '';
89
- }
90
- function isDataSet(result) {
91
- return _typeof(result) === 'object' && result !== null && 'dataPoints' in result && result.dataPoints !== null && _typeof(result.dataPoints) === 'object' && 'result' in result.dataPoints;
92
- }
93
- function extractDataSetResult(dataSet) {
94
- var dataPoints = dataSet.dataPoints;
95
- if (dataPoints) {
96
- var result = dataPoints.result;
97
- return result;
98
- }
99
- return undefined;
100
- }