@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,330 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.LunaticVariablesStore = void 0;
7
- var _vtl = require("../../../utils/vtl");
8
- var _env = require("../../../utils/env");
9
- var _variables = require("../../../utils/variables");
10
- var _resizingBehaviour = require("./behaviours/resizing-behaviour");
11
- var _cleaningBehaviour = require("./behaviours/cleaning-behaviour");
12
- var _missingBehaviour = require("./behaviours/missing-behaviour");
13
- var _array = require("../../../utils/array");
14
- var _number = require("../../../utils/number");
15
- 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); }
16
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
17
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
19
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
20
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
21
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
23
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
26
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
27
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
28
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
29
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
30
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
31
- // Interpret counter, used for testing purpose
32
- var interpretCount = 0;
33
- var LunaticVariablesStore = /*#__PURE__*/function () {
34
- function LunaticVariablesStore() {
35
- _classCallCheck(this, LunaticVariablesStore);
36
- this.dictionary = new Map();
37
- this.eventTarget = new EventTarget();
38
- interpretCount = 0;
39
- }
40
- _createClass(LunaticVariablesStore, [{
41
- key: "get",
42
- value:
43
- /**
44
- * Retrieve variable value
45
- */
46
- function get(name, iteration) {
47
- if (!this.dictionary.has(name)) {
48
- return null;
49
- }
50
- return this.dictionary.get(name).getValue(iteration);
51
- }
52
-
53
- /**
54
- * Set variable value
55
- */
56
- }, {
57
- key: "set",
58
- value: function set(name, value) {
59
- var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
60
- if (!this.dictionary.has(name)) {
61
- this.dictionary.set(name, new LunaticVariable({
62
- name: name
63
- }));
64
- }
65
- var variable = this.dictionary.get(name);
66
- if (variable.setValue(value, args.iteration)) {
67
- this.eventTarget.dispatchEvent(new CustomEvent('change', {
68
- detail: _objectSpread(_objectSpread({}, args), {}, {
69
- name: name,
70
- value: value
71
- })
72
- }));
73
- }
74
- return variable;
75
- }
76
-
77
- /**
78
- * Register calculated variable
79
- */
80
- }, {
81
- key: "setCalculated",
82
- value: function setCalculated(name, expression) {
83
- var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
84
- dependencies = _ref.dependencies,
85
- iterationDepth = _ref.iterationDepth;
86
- if (this.dictionary.has(name)) {
87
- return this.dictionary.get(name);
88
- }
89
- var variable = new LunaticVariable({
90
- expression: expression,
91
- dictionary: this.dictionary,
92
- dependencies: dependencies,
93
- iterationDepth: iterationDepth,
94
- name: name
95
- });
96
- this.dictionary.set(name, variable);
97
- return variable;
98
- }
99
-
100
- /**
101
- * Run a VTL expression
102
- */
103
- }, {
104
- key: "run",
105
- value: function run(expression) {
106
- var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
107
- return this.setCalculated(expression, expression, {
108
- dependencies: args.deps
109
- }).getValue(args.iteration);
110
- }
111
-
112
- /**
113
- * Bind event listeners
114
- */
115
- }, {
116
- key: "on",
117
- value: function on(eventName, cb) {
118
- this.eventTarget.addEventListener(eventName, cb);
119
- }
120
-
121
- /**
122
- * Detach a listener
123
- */
124
- }, {
125
- key: "off",
126
- value: function off(eventName, cb) {
127
- this.eventTarget.removeEventListener(eventName, cb);
128
- }
129
-
130
- // Retrieve the number of interpret() run (used in testing only)
131
- }, {
132
- key: "interpretCount",
133
- get: function get() {
134
- return interpretCount;
135
- }
136
- }], [{
137
- key: "makeFromSource",
138
- value: function makeFromSource(source, data) {
139
- var _variable$name;
140
- var store = new LunaticVariablesStore();
141
- if (!source.variables) {
142
- return store;
143
- }
144
- var initialValues = Object.fromEntries(source.variables.map(function (variable) {
145
- return [variable.name, (0, _variables.getInitialVariableValue)(variable, data)];
146
- }));
147
- var getIterationDepth = function getIterationDepth(name) {
148
- if (name === 'xAxis') return 0;
149
- if (name === 'yAxis') return 1;
150
- return undefined;
151
- };
152
- var _iterator = _createForOfIteratorHelper(source.variables),
153
- _step;
154
- try {
155
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
156
- var variable = _step.value;
157
- switch (variable.variableType) {
158
- case 'CALCULATED':
159
- store.setCalculated(variable.name, variable.expression.value, {
160
- dependencies: variable.bindingDependencies,
161
- iterationDepth: getIterationDepth(variable.name)
162
- });
163
- break;
164
- case 'COLLECTED':
165
- case 'EXTERNAL':
166
- store.set(variable.name, initialValues[(_variable$name = variable.name) !== null && _variable$name !== void 0 ? _variable$name : null]);
167
- break;
168
- }
169
- }
170
- } catch (err) {
171
- _iterator.e(err);
172
- } finally {
173
- _iterator.f();
174
- }
175
- (0, _resizingBehaviour.resizingBehaviour)(store, source.resizing);
176
- (0, _cleaningBehaviour.cleaningBehaviour)(store, source.cleaning, initialValues);
177
- (0, _missingBehaviour.missingBehaviour)(store, source.missingBlock);
178
- return store;
179
- }
180
- }]);
181
- return LunaticVariablesStore;
182
- }();
183
- exports.LunaticVariablesStore = LunaticVariablesStore;
184
- var LunaticVariable = /*#__PURE__*/function () {
185
- function LunaticVariable() {
186
- var _args$name;
187
- var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
188
- _classCallCheck(this, LunaticVariable);
189
- // Last time the value was updated (changed)
190
- this.updatedAt = new Map();
191
- // Last time "calculation" was run (for calculated variable)
192
- this.calculatedAt = new Map();
193
- // Internal value for the variable
194
- this.value = void 0;
195
- // List of dependencies, ex: ['FIRSTNAME', 'LASTNAME']
196
- this.dependencies = void 0;
197
- // Expression for calculated variable
198
- this.expression = void 0;
199
- // Dictionary holding all the available variables
200
- this.dictionary = void 0;
201
- // Specific iteration depth to get value from dependencies (used for yAxis for instance)
202
- this.iterationDepth = void 0;
203
- // Keep a record of variable name (optional, used for debug)
204
- this.name = void 0;
205
- if (args.expression && !args.dictionary) {
206
- throw new Error("A calculated variable needs a dictionary to retrieve his deps");
207
- }
208
- this.expression = args.expression;
209
- this.dictionary = args.dictionary;
210
- this.dependencies = args.dependencies;
211
- this.iterationDepth = args.iterationDepth;
212
- this.name = (_args$name = args.name) !== null && _args$name !== void 0 ? _args$name : args.expression;
213
- }
214
- _createClass(LunaticVariable, [{
215
- key: "getValue",
216
- value: function getValue(iteration) {
217
- // The variable is not calculated
218
- if (!this.expression) {
219
- return this.getSavedValue(iteration);
220
- }
221
- // Calculate bindings first to refresh "updatedAt" on calculated dependencies
222
- var bindings = this.getDependenciesValues(iteration);
223
- if (!this.isOutdated(iteration)) {
224
- return this.getSavedValue(iteration);
225
- }
226
- if ((0, _env.isTestEnv)()) {
227
- interpretCount++;
228
- }
229
- // Remember the value
230
- try {
231
- this.setValue((0, _vtl.interpretVTL)(this.expression, bindings), iteration);
232
- } catch (e) {
233
- throw new Error("Cannot interpret expression \"".concat(this.expression, "\" with bindings ").concat(JSON.stringify(bindings), ", error : ").concat(e.toString()));
234
- }
235
- this.calculatedAt.set(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'), performance.now());
236
- this.calculatedAt.set(undefined, performance.now());
237
- return this.getSavedValue(iteration);
238
- }
239
-
240
- /**
241
- * Set the value and returns true if the variable is touched
242
- */
243
- }, {
244
- key: "setValue",
245
- value: function setValue(value, iteration) {
246
- var _this = this;
247
- if (value === this.getSavedValue(iteration)) {
248
- return false;
249
- }
250
- // Decompose arrays, to only update items that changed
251
- if (Array.isArray(value) && !Array.isArray(iteration)) {
252
- return !!value.map(function (v, k) {
253
- return _this.setValue(v, [k]);
254
- }).find(function (v) {
255
- return v;
256
- });
257
- }
258
- // We want to save a value at a specific iteration, but the value is not an array yet
259
- if (iteration !== undefined && !Array.isArray(this.value)) {
260
- this.value = [];
261
- }
262
- this.value = !Array.isArray(iteration) ? value : (0, _array.setAtIndex)(this.value, iteration, value);
263
- this.updatedAt.set(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'), performance.now());
264
- this.updatedAt.set(undefined, performance.now());
265
- return true;
266
- }
267
- }, {
268
- key: "getSavedValue",
269
- value: function getSavedValue(iteration) {
270
- if (!Array.isArray(iteration)) {
271
- return this.value;
272
- }
273
- var current = this.value;
274
- var _iterator2 = _createForOfIteratorHelper(iteration),
275
- _step2;
276
- try {
277
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
278
- var index = _step2.value;
279
- if (!Array.isArray(current)) {
280
- return current;
281
- }
282
- current = current[index];
283
- }
284
- } catch (err) {
285
- _iterator2.e(err);
286
- } finally {
287
- _iterator2.f();
288
- }
289
- return current;
290
- }
291
- }, {
292
- key: "getDependencies",
293
- value: function getDependencies() {
294
- // Calculate dependencies from expression on the fly if necessary
295
- if (this.dependencies === undefined) {
296
- this.dependencies = (0, _vtl.parseVTLVariables)(this.expression);
297
- }
298
- return this.dependencies;
299
- }
300
- }, {
301
- key: "getDependenciesValues",
302
- value: function getDependenciesValues(iteration) {
303
- var _this2 = this;
304
- try {
305
- return Object.fromEntries(this.getDependencies().map(function (dep) {
306
- var _this2$dictionary;
307
- var dependencyIteration = (0, _number.isNumber)(_this2.iterationDepth) && Array.isArray(iteration) ? [iteration[_this2.iterationDepth]] : iteration;
308
- return [dep, (_this2$dictionary = _this2.dictionary) === null || _this2$dictionary === void 0 || (_this2$dictionary = _this2$dictionary.get(dep)) === null || _this2$dictionary === void 0 ? void 0 : _this2$dictionary.getValue(dependencyIteration)];
309
- }));
310
- } catch (e) {
311
- if (e instanceof RangeError) {
312
- throw new Error("Cannot resolve dependencies for \"".concat(this.expression, "\" with dependencies ").concat(JSON.stringify(this.getDependencies()), " \n ").concat(e.toString()));
313
- }
314
- throw e;
315
- }
316
- }
317
- }, {
318
- key: "isOutdated",
319
- value: function isOutdated(iteration) {
320
- var _this3 = this,
321
- _this$calculatedAt$ge;
322
- var dependenciesUpdatedAt = Math.max.apply(Math, [0].concat(_toConsumableArray(this.getDependencies().map(function (dep) {
323
- var _this3$dictionary$get, _this3$dictionary;
324
- return (_this3$dictionary$get = (_this3$dictionary = _this3.dictionary) === null || _this3$dictionary === void 0 || (_this3$dictionary = _this3$dictionary.get(dep)) === null || _this3$dictionary === void 0 ? void 0 : _this3$dictionary.updatedAt.get(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'))) !== null && _this3$dictionary$get !== void 0 ? _this3$dictionary$get : 0;
325
- }))));
326
- return dependenciesUpdatedAt > ((_this$calculatedAt$ge = this.calculatedAt.get(iteration === null || iteration === void 0 ? void 0 : iteration.join('.'))) !== null && _this$calculatedAt$ge !== void 0 ? _this$calculatedAt$ge : -1);
327
- }
328
- }]);
329
- return LunaticVariable;
330
- }();
@@ -1,216 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _lunaticVariablesStore = require("./lunatic-variables-store");
5
- var _resizingBehaviour = require("./behaviours/resizing-behaviour");
6
- var _cleaningBehaviour = require("./behaviours/cleaning-behaviour");
7
- var _missingBehaviour = require("./behaviours/missing-behaviour");
8
- (0, _vitest.describe)('lunatic-variables-store', function () {
9
- var variables;
10
- (0, _vitest.beforeEach)(function () {
11
- variables = new _lunaticVariablesStore.LunaticVariablesStore();
12
- });
13
- (0, _vitest.it)('should record basic variables', function () {
14
- variables.set('FIRSTNAME', 'John');
15
- (0, _vitest.expect)(variables.get('FIRSTNAME')).toEqual('John');
16
- });
17
- (0, _vitest.it)('should run simple types', function () {
18
- (0, _vitest.expect)(variables.run('"Hello world"')).toEqual('Hello world');
19
- (0, _vitest.expect)(variables.run('true')).toEqual(true);
20
- (0, _vitest.expect)(variables.run('2')).toEqual(2);
21
- });
22
- (0, _vitest.it)('should handle calculated', function () {
23
- variables.set('FIRSTNAME', 'John');
24
- variables.set('LASTNAME', 'Doe');
25
- variables.setCalculated('FULLNAME', 'FIRSTNAME || " " || LASTNAME', {
26
- dependencies: ['FIRSTNAME', 'LASTNAME']
27
- });
28
- (0, _vitest.expect)(variables.get('FULLNAME')).toEqual('John Doe');
29
- (0, _vitest.expect)(variables.interpretCount).toBe(1);
30
- // The result should be cached
31
- (0, _vitest.expect)(variables.get('FULLNAME')).toEqual('John Doe');
32
- (0, _vitest.expect)(variables.interpretCount).toBe(1);
33
- // But refreshed if a variable was updated
34
- variables.set('FIRSTNAME', 'Jane');
35
- (0, _vitest.expect)(variables.get('FULLNAME')).toEqual('Jane Doe');
36
- (0, _vitest.expect)(variables.interpretCount).toBe(2);
37
- });
38
- (0, _vitest.it)('should handle deep calculation', function () {
39
- variables.set('FIRSTNAME', 'John');
40
- variables.set('LASTNAME', 'Doe');
41
- variables.set('AGE', '18');
42
- variables.setCalculated('FULLNAME', 'FIRSTNAME || " " || LASTNAME', {
43
- dependencies: ['FIRSTNAME', 'LASTNAME']
44
- });
45
- variables.setCalculated('LABEL', 'FULLNAME || " is " || AGE', {
46
- dependencies: ['FULLNAME', 'AGE']
47
- });
48
- (0, _vitest.expect)(variables.get('LABEL')).toEqual('John Doe is 18');
49
- (0, _vitest.expect)(variables.interpretCount).toBe(2);
50
- variables.set('AGE', '20');
51
- (0, _vitest.expect)(variables.get('LABEL')).toEqual('John Doe is 20');
52
- (0, _vitest.expect)(variables.interpretCount).toBe(3);
53
- variables.set('FIRSTNAME', 'Jane');
54
- (0, _vitest.expect)(variables.get('LABEL')).toEqual('Jane Doe is 20');
55
- (0, _vitest.expect)(variables.interpretCount).toBe(5);
56
- variables.get('LABEL');
57
- (0, _vitest.expect)(variables.interpretCount).toBe(5);
58
- });
59
- (0, _vitest.it)('should handle dependencies resolution', function () {
60
- variables.set('FIRSTNAME', 'John');
61
- variables.set('LASTNAME', 'Doe');
62
- variables.setCalculated('FULLNAME', 'FIRSTNAME || " " || LASTNAME');
63
- (0, _vitest.expect)(variables.get('FULLNAME')).toEqual('John Doe');
64
- variables.set('FIRSTNAME', 'Jane');
65
- (0, _vitest.expect)(variables.get('FULLNAME')).toEqual('Jane Doe');
66
- });
67
- (0, _vitest.it)('should run expression on the fly', function () {
68
- variables.set('FIRSTNAME', 'John');
69
- variables.set('LASTNAME', 'Doe');
70
- (0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('John Doe');
71
- (0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('John Doe');
72
- (0, _vitest.expect)(variables.interpretCount).toBe(1);
73
- variables.set('FIRSTNAME', 'Jane');
74
- (0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME')).toEqual('Jane Doe');
75
- });
76
- (0, _vitest.describe)('with iteration', function () {
77
- (0, _vitest.it)('should handle arrays', function () {
78
- variables.set('FIRSTNAME', ['John', 'Jane']);
79
- (0, _vitest.expect)(variables.get('FIRSTNAME')).toEqual(['John', 'Jane']);
80
- (0, _vitest.expect)(variables.get('FIRSTNAME', [0])).toEqual('John');
81
- (0, _vitest.expect)(variables.get('FIRSTNAME', [1])).toEqual('Jane');
82
- });
83
- (0, _vitest.it)('should handle setting at a specific index', function () {
84
- variables.set('FIRSTNAME', ['John', 'Jane']);
85
- variables.set('LASTNAME', null);
86
- variables.set('FIRSTNAME', 'Marc', {
87
- iteration: [1]
88
- });
89
- (0, _vitest.expect)(variables.get('FIRSTNAME')).toEqual(['John', 'Marc']);
90
- variables.set('LASTNAME', 'Doe', {
91
- iteration: [1]
92
- });
93
- (0, _vitest.expect)(variables.get('LASTNAME')).toEqual([null, 'Doe']);
94
- });
95
- (0, _vitest.it)('should ignore non array values', function () {
96
- variables.set('FIRSTNAME', 'John');
97
- (0, _vitest.expect)(variables.get('FIRSTNAME', [0])).toEqual('John');
98
- });
99
- (0, _vitest.it)('should handle iteration in calculation', function () {
100
- variables.set('FIRSTNAME', ['John', 'Jane']);
101
- variables.set('LASTNAME', ['Doe', 'Dae']);
102
- variables.setCalculated('FULLNAME', 'FIRSTNAME || " " || LASTNAME', {
103
- dependencies: ['FIRSTNAME', 'LASTNAME']
104
- });
105
- (0, _vitest.expect)(variables.get('FULLNAME', [0])).toEqual('John Doe');
106
- (0, _vitest.expect)(variables.get('FULLNAME', [1])).toEqual('Jane Dae');
107
- (0, _vitest.expect)(variables.interpretCount).toBe(2);
108
- (0, _vitest.expect)(variables.get('FULLNAME', [0])).toEqual('John Doe');
109
- (0, _vitest.expect)(variables.get('FULLNAME', [1])).toEqual('Jane Dae');
110
- (0, _vitest.expect)(variables.interpretCount).toBe(2);
111
- (0, _vitest.expect)(variables.get('FULLNAME', [0])).toEqual('John Doe');
112
- variables.set('FIRSTNAME', ['John', 'Marc']);
113
- (0, _vitest.expect)(variables.get('FULLNAME', [0])).toEqual('John Doe');
114
- (0, _vitest.expect)(variables.get('FULLNAME', [1])).toEqual('Marc Dae');
115
- // Only the second iteration should be calculated
116
- (0, _vitest.expect)(variables.interpretCount).toBe(3);
117
- });
118
- (0, _vitest.it)('should handle aggregation expression', function () {
119
- variables.set('FIRSTNAME', ['John', 'Jane']);
120
- (0, _vitest.expect)(variables.run('count(FIRSTNAME)')).toEqual(2);
121
- variables.set('FIRSTNAME', ['John', 'Jane', 'Marc']);
122
- (0, _vitest.expect)(variables.run('count(FIRSTNAME)')).toEqual(3);
123
- });
124
- (0, _vitest.it)('should handle non array values', function () {
125
- variables.set('FIRSTNAME', ['John', 'Jane']);
126
- variables.set('LASTNAME', 'Doe');
127
- (0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME', {
128
- iteration: [0]
129
- })).toEqual('John Doe');
130
- (0, _vitest.expect)(variables.run('FIRSTNAME || " " || LASTNAME', {
131
- iteration: [1]
132
- })).toEqual('Jane Doe');
133
- });
134
- });
135
- (0, _vitest.describe)('resizing', function () {
136
- (0, _vitest.it)('should resize variables', function () {
137
- variables.set('PRENOM', ['John', 'Jane']);
138
- variables.set('NOM', ['Doe']);
139
- (0, _resizingBehaviour.resizingBehaviour)(variables, {
140
- PRENOM: {
141
- size: 'count(PRENOM)',
142
- variables: ['NOM']
143
- }
144
- });
145
- variables.set('PRENOM', ['John', 'Jane', 'Marc']);
146
- (0, _vitest.expect)(variables.get('PRENOM').length).toEqual(3);
147
- (0, _vitest.expect)(variables.get('NOM').length).toEqual(3);
148
- });
149
- });
150
- (0, _vitest.describe)('cleaning', function () {
151
- (0, _vitest.it)('should clean variables', function () {
152
- variables.set('PRENOM', 'John');
153
- variables.set('NOM', 'Doe');
154
- variables.set('READY', true);
155
- (0, _cleaningBehaviour.cleaningBehaviour)(variables, {
156
- READY: {
157
- PRENOM: 'READY'
158
- }
159
- });
160
- (0, _vitest.expect)(variables.get('PRENOM')).toEqual('John');
161
- variables.set('READY', false);
162
- (0, _vitest.expect)(variables.get('PRENOM')).toEqual(null);
163
- });
164
- (0, _vitest.it)('should clean variables with initial values', function () {
165
- variables.set('PRENOM', 'John');
166
- variables.set('READY', true);
167
- (0, _cleaningBehaviour.cleaningBehaviour)(variables, {
168
- READY: {
169
- PRENOM: 'READY'
170
- }
171
- }, {
172
- PRENOM: 'Jane'
173
- });
174
- variables.set('READY', false);
175
- (0, _vitest.expect)(variables.get('PRENOM')).toEqual('Jane');
176
- });
177
- (0, _vitest.it)('should clean variables at a specific iteration', function () {
178
- variables.set('PRENOM', ['John', 'Jane', 'Marc']);
179
- variables.set('READY', [true, true, true]);
180
- (0, _cleaningBehaviour.cleaningBehaviour)(variables, {
181
- READY: {
182
- PRENOM: 'READY'
183
- }
184
- });
185
- variables.set('READY', false, {
186
- iteration: [1]
187
- });
188
- (0, _vitest.expect)(variables.get('PRENOM')).toEqual(['John', null, 'Marc']);
189
- });
190
- });
191
- (0, _vitest.describe)('missing', function () {
192
- (0, _vitest.beforeEach)(function () {
193
- (0, _missingBehaviour.missingBehaviour)(variables, {
194
- PRENOM: ['PRENOM_MISSING'],
195
- PRENOM_MISSING: ['PRENOM']
196
- });
197
- });
198
- (0, _vitest.it)('should handle missing', function () {
199
- variables.set('PRENOM', 'John');
200
- (0, _vitest.expect)(variables.get('PRENOM')).toEqual('John');
201
- (0, _vitest.expect)(variables.get('PRENOM_MISSING')).toEqual(null);
202
- variables.set('PRENOM_MISSING', 'DK');
203
- (0, _vitest.expect)(variables.get('PRENOM')).toEqual(null);
204
- (0, _vitest.expect)(variables.get('PRENOM_MISSING')).toEqual('DK');
205
- });
206
- (0, _vitest.it)('should handle missing for iteration', function () {
207
- variables.set('PRENOM', ['John', 'Jane', 'Marc']);
208
- (0, _vitest.expect)(variables.get('PRENOM_MISSING')).toEqual(null);
209
- variables.set('PRENOM_MISSING', 'DK', {
210
- iteration: [1]
211
- });
212
- (0, _vitest.expect)(variables.get('PRENOM')).toEqual(['John', null, 'Marc']);
213
- (0, _vitest.expect)(variables.get('PRENOM_MISSING', [1])).toEqual('DK');
214
- });
215
- });
216
- });
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _array = require("./array");
5
- (0, _vitest.describe)('array', function () {
6
- (0, _vitest.describe)('resizeArray()', function () {
7
- (0, _vitest.it)('should append new value', function () {
8
- (0, _vitest.expect)((0, _array.resizeArray)([1, 2], 3, 3)).toEqual([1, 2, 3]);
9
- (0, _vitest.expect)((0, _array.resizeArray)([1, 2], 4, 3)).toEqual([1, 2, 3, 3]);
10
- });
11
- (0, _vitest.it)('should remove value', function () {
12
- (0, _vitest.expect)((0, _array.resizeArray)([1, 2, 3], 1)).toEqual([1]);
13
- });
14
- });
15
- (0, _vitest.describe)('setAtIndex', function () {
16
- (0, _vitest.it)('should work with simple index', function () {
17
- (0, _vitest.expect)((0, _array.setAtIndex)([1, 2, 3], 1, 3)).toEqual([1, 3, 3]);
18
- });
19
- (0, _vitest.it)('should work with non array value', function () {
20
- (0, _vitest.expect)((0, _array.setAtIndex)(null, 1, 3)).toEqual([null, 3]);
21
- (0, _vitest.expect)((0, _array.setAtIndex)(4, 1, 3)).toEqual([4, 3]);
22
- });
23
- (0, _vitest.it)('should work with deep index', function () {
24
- (0, _vitest.expect)((0, _array.setAtIndex)([[1, 2, 3], [1, 2, 3], [1, 2, 3]], [1, 2], 10)).toEqual([[1, 2, 3], [1, 2, 10], [1, 2, 3]]);
25
- });
26
- (0, _vitest.it)('should work with deep and non array value', function () {
27
- (0, _vitest.expect)((0, _array.setAtIndex)([null], [1, 2], 10)).toEqual([null, [null, null, 10]]);
28
- });
29
- });
30
- });
package/lib/utils/env.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isTestEnv = isTestEnv;
7
- function isTestEnv() {
8
- var meta = import.meta;
9
- return meta && meta !== null && meta !== void 0 && meta.env ? import.meta.env.MODE === 'test' : false;
10
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getWorkerPath = getWorkerPath;
7
- function getWorkerPath() {
8
- var _ref, _process$env$LUNATIC_;
9
- if ('LUNATIC_WORKER_PATH' in window) {
10
- return window.LUNATIC_WORKER_PATH;
11
- }
12
- return (_ref = (_process$env$LUNATIC_ = process.env.LUNATIC_LOADER_WORKER_PATH) !== null && _process$env$LUNATIC_ !== void 0 ? _process$env$LUNATIC_ : process.env.REACT_APP_LUNATIC_LOADER_WORKER_PATH) !== null && _ref !== void 0 ? _ref : 'workers/lunatic-loader-worker-0.1.0.js';
13
- }
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createWorker = void 0;
7
- var _logger = require("../logger");
8
- // Enable cross domain workers
9
-
10
- var testSameOrigin = function testSameOrigin(url) {
11
- var loc = window.location;
12
- var a = document.createElement('a');
13
- a.href = url;
14
- return a.hostname === loc.hostname && a.port === loc.port && a.protocol === loc.protocol;
15
- };
16
- var createWorkerFallback = function createWorkerFallback(workerUrl) {
17
- _logger.Logger.info('Create worker for MFE');
18
- var worker = null;
19
- try {
20
- var blob;
21
- try {
22
- blob = new Blob(["importScripts('".concat(workerUrl, "');")], {
23
- type: 'application/javascript'
24
- });
25
- } catch (e) {
26
- var blobBuilder = new (window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder)();
27
- blobBuilder.append("importScripts('".concat(workerUrl, "');"));
28
- blob = blobBuilder.getBlob('application/javascript');
29
- }
30
- var url = window.URL || window.webkitURL;
31
- var blobUrl = url.createObjectURL(blob);
32
- worker = new Worker(blobUrl);
33
- } catch (e1) {
34
- console.error("Lunatic-worker : Failed to load web worker : ".concat(workerUrl));
35
- }
36
- return worker;
37
- };
38
- var createWorker = function createWorker(workerUrl) {
39
- var worker = null;
40
- try {
41
- if (testSameOrigin(workerUrl)) {
42
- worker = new Worker(workerUrl);
43
- worker.onerror = function (event) {
44
- event.preventDefault();
45
- worker = createWorkerFallback(workerUrl);
46
- };
47
- } else {
48
- worker = createWorkerFallback(workerUrl);
49
- }
50
- } catch (e) {
51
- worker = createWorkerFallback(workerUrl);
52
- }
53
- return worker;
54
- };
55
- exports.createWorker = createWorker;