@inseefr/lunatic 2.6.2 → 2.6.3-rc.1

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 (144) hide show
  1. package/lib/components/index.js +4 -4
  2. package/lib/components/loop/block-for-loop.js +6 -10
  3. package/lib/components/loop/roster-for-loop/roster-for-loop.js +27 -35
  4. package/lib/components/lunatic-components.js +16 -5
  5. package/lib/components/pairwise-links/pairwise-links.js +27 -30
  6. package/lib/components/table/lunatic-table.js +22 -13
  7. package/lib/components/table/{header.js → table-header.js} +3 -5
  8. package/lib/hooks/use-track-changes.js +50 -0
  9. package/lib/src/components/index.d.ts +2 -2
  10. package/lib/src/components/loop/block-for-loop.d.ts +3 -4
  11. package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +3 -4
  12. package/lib/src/components/lunatic-components.d.ts +5 -3
  13. package/lib/src/components/pairwise-links/pairwise-links.d.ts +1 -2
  14. package/lib/src/components/table/lunatic-table.d.ts +1 -1
  15. package/lib/src/components/table/{header.d.ts → table-header.d.ts} +2 -2
  16. package/lib/src/components/type.d.ts +5 -6
  17. package/lib/src/hooks/use-track-changes.d.ts +9 -0
  18. package/lib/src/use-lunatic/actions.d.ts +3 -16
  19. package/lib/src/use-lunatic/commons/compile-controls.d.ts +3 -2
  20. package/lib/src/use-lunatic/commons/component.d.ts +22 -0
  21. package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +2 -3
  22. package/lib/src/use-lunatic/commons/fill-components/fill-components.d.ts +6 -0
  23. package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +107 -122
  24. package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +112 -0
  25. package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +53 -89
  26. package/lib/src/use-lunatic/commons/get-compatible-vtl-expression.d.ts +1 -0
  27. package/lib/src/use-lunatic/commons/index.d.ts +0 -3
  28. package/lib/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +7 -0
  29. package/lib/src/use-lunatic/commons/variables/behaviours/missing-behaviour.d.ts +7 -0
  30. package/lib/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.d.ts +7 -0
  31. package/lib/src/use-lunatic/commons/variables/get-questionnaire-data.d.ts +4 -0
  32. package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +77 -0
  33. package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +10 -8
  34. package/lib/src/use-lunatic/reducer/reduce-handle-change.d.ts +6 -0
  35. package/lib/src/use-lunatic/reducer/reduce-on-init.d.ts +1 -12
  36. package/lib/src/use-lunatic/type-source.d.ts +7 -21
  37. package/lib/src/use-lunatic/type.d.ts +13 -11
  38. package/lib/src/use-lunatic/use-lunatic.d.ts +33 -56
  39. package/lib/src/utils/array.d.ts +6 -1
  40. package/lib/src/utils/env.d.ts +1 -0
  41. package/lib/src/utils/number.d.ts +4 -0
  42. package/lib/src/utils/variables.d.ts +5 -0
  43. package/lib/src/utils/vtl.d.ts +14 -0
  44. package/lib/use-lunatic/actions.js +3 -3
  45. package/lib/use-lunatic/commons/compile-controls.js +3 -5
  46. package/lib/use-lunatic/commons/component.js +22 -0
  47. package/lib/use-lunatic/commons/execute-condition-filter.js +1 -9
  48. package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +2 -3
  49. package/lib/use-lunatic/commons/fill-components/fill-component-value.js +21 -7
  50. package/lib/use-lunatic/commons/fill-components/fill-components.js +5 -3
  51. package/lib/use-lunatic/commons/{execute-expression/get-safety-expression.js → fill-components/fill-iterations.js} +30 -20
  52. package/lib/use-lunatic/commons/fill-components/fill-missing-response.js +6 -13
  53. package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +58 -5
  54. package/lib/use-lunatic/commons/get-compatible-vtl-expression.js +1 -0
  55. package/lib/use-lunatic/commons/index.js +0 -21
  56. package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +39 -0
  57. package/lib/use-lunatic/commons/variables/behaviours/missing-behaviour.js +47 -0
  58. package/lib/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +78 -0
  59. package/lib/use-lunatic/{reducer/reduce-handle-change/reduce-variables-array.js → commons/variables/get-questionnaire-data.js} +53 -32
  60. package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +330 -0
  61. package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +216 -0
  62. package/lib/use-lunatic/initial-state.js +5 -2
  63. package/lib/use-lunatic/reducer/overview/overview-on-change.js +1 -1
  64. package/lib/use-lunatic/reducer/{reduce-handle-change/reduce-variables-simple.js → reduce-handle-change.js} +15 -14
  65. package/lib/use-lunatic/reducer/reduce-on-init.js +89 -181
  66. package/lib/use-lunatic/reducer/reducer.js +2 -2
  67. package/lib/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.js +2 -4
  68. package/lib/use-lunatic/use-lunatic.js +18 -14
  69. package/lib/use-lunatic/use-lunatic.test.js +131 -2
  70. package/lib/utils/array.js +57 -6
  71. package/lib/utils/array.spec.js +30 -0
  72. package/lib/utils/env.js +10 -0
  73. package/lib/utils/get-component-value.js +3 -9
  74. package/lib/utils/number.js +13 -1
  75. package/lib/utils/variables.js +37 -0
  76. package/lib/utils/vtl.js +100 -0
  77. package/package.json +1 -1
  78. package/lib/components/loop/utils/get-initial-nb-rows.js +0 -17
  79. package/lib/components/pairwise-links/index.js +0 -13
  80. package/lib/components/pairwise-links/orchestrator.js +0 -71
  81. package/lib/components/pairwise-links/row.js +0 -74
  82. package/lib/components/table/cell.js +0 -89
  83. package/lib/components/table/index.js +0 -13
  84. package/lib/components/table/row.js +0 -40
  85. package/lib/components/table/table-orchestrator.js +0 -35
  86. package/lib/src/components/loop/utils/get-initial-nb-rows.d.ts +0 -4
  87. package/lib/src/components/pairwise-links/index.d.ts +0 -1
  88. package/lib/src/components/pairwise-links/orchestrator.d.ts +0 -6
  89. package/lib/src/components/pairwise-links/row.d.ts +0 -7
  90. package/lib/src/components/table/cell.d.ts +0 -19
  91. package/lib/src/components/table/index.d.ts +0 -1
  92. package/lib/src/components/table/row.d.ts +0 -18
  93. package/lib/src/components/table/table-orchestrator.d.ts +0 -4
  94. package/lib/src/use-lunatic/commons/calculated-variables.d.ts +0 -8
  95. package/lib/src/use-lunatic/commons/execute-expression/create-execute-expression.d.ts +0 -9
  96. package/lib/src/use-lunatic/commons/execute-expression/create-memoizer.d.ts +0 -8
  97. package/lib/src/use-lunatic/commons/execute-expression/create-refresh-calculated.d.ts +0 -24
  98. package/lib/src/use-lunatic/commons/execute-expression/execute-expression.d.ts +0 -11
  99. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.d.ts +0 -7
  100. package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.spec.d.ts +0 -1
  101. package/lib/src/use-lunatic/commons/execute-expression/get-safety-expression.d.ts +0 -6
  102. package/lib/src/use-lunatic/commons/execute-expression/index.d.ts +0 -1
  103. package/lib/src/use-lunatic/commons/get-component-value/get-component-value.d.ts +0 -6
  104. package/lib/src/use-lunatic/commons/get-component-value/index.d.ts +0 -1
  105. package/lib/src/use-lunatic/commons/get-data.d.ts +0 -26
  106. package/lib/src/use-lunatic/reducer/reduce-handle-change/index.d.ts +0 -1
  107. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.d.ts +0 -7
  108. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.d.ts +0 -1
  109. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.d.ts +0 -4
  110. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.d.ts +0 -15
  111. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-missing.d.ts +0 -7
  112. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-resizing.d.ts +0 -4
  113. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.d.ts +0 -14
  114. package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.d.ts +0 -9
  115. package/lib/src/use-lunatic/reducer/reduce-on-init.spec.d.ts +0 -1
  116. package/lib/src/utils/vtl/dataset-builder.d.ts +0 -5
  117. package/lib/src/utils/vtl/index.d.ts +0 -1
  118. package/lib/use-lunatic/commons/calculated-variables.js +0 -104
  119. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.js +0 -233
  120. package/lib/use-lunatic/commons/execute-expression/create-execute-expression.spec.js +0 -155
  121. package/lib/use-lunatic/commons/execute-expression/create-memoizer.js +0 -63
  122. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.js +0 -149
  123. package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +0 -130
  124. package/lib/use-lunatic/commons/execute-expression/execute-expression.js +0 -90
  125. package/lib/use-lunatic/commons/execute-expression/execute-expression.spec.js +0 -38
  126. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.js +0 -40
  127. package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.spec.js +0 -31
  128. package/lib/use-lunatic/commons/execute-expression/index.js +0 -13
  129. package/lib/use-lunatic/commons/get-component-value/get-component-value.js +0 -174
  130. package/lib/use-lunatic/commons/get-component-value/index.js +0 -13
  131. package/lib/use-lunatic/commons/get-data.js +0 -80
  132. package/lib/use-lunatic/reducer/reduce-handle-change/__mocks__/source-cleaning-loop.json +0 -792
  133. package/lib/use-lunatic/reducer/reduce-handle-change/index.js +0 -13
  134. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.js +0 -72
  135. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.js +0 -46
  136. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js +0 -115
  137. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.js +0 -89
  138. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-missing.js +0 -88
  139. package/lib/use-lunatic/reducer/reduce-handle-change/reduce-resizing.js +0 -110
  140. package/lib/use-lunatic/reducer/reduce-on-init.spec.js +0 -17
  141. package/lib/utils/vtl/dataset-builder.js +0 -27
  142. package/lib/utils/vtl/index.js +0 -13
  143. /package/lib/src/use-lunatic/commons/{execute-expression/create-refresh-calculated.spec.d.ts → variables/lunatic-variables-store.spec.d.ts} +0 -0
  144. /package/lib/src/{use-lunatic/commons/execute-expression/execute-expression.spec.d.ts → utils/array.spec.d.ts} +0 -0
@@ -9,12 +9,6 @@ Object.defineProperty(exports, "checkLoops", {
9
9
  return _checkLoops["default"];
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "createExecuteExpression", {
13
- enumerable: true,
14
- get: function get() {
15
- return _executeExpression["default"];
16
- }
17
- });
18
12
  Object.defineProperty(exports, "createMapPages", {
19
13
  enumerable: true,
20
14
  get: function get() {
@@ -45,12 +39,6 @@ Object.defineProperty(exports, "getComponentsFromState", {
45
39
  return _getComponentsFromState["default"];
46
40
  }
47
41
  });
48
- Object.defineProperty(exports, "getErrorsWithoutEmptyValue", {
49
- enumerable: true,
50
- get: function get() {
51
- return _getErrorsWithoutEmptyValue["default"];
52
- }
53
- });
54
42
  Object.defineProperty(exports, "getNewReachedPage", {
55
43
  enumerable: true,
56
44
  get: function get() {
@@ -75,12 +63,6 @@ Object.defineProperty(exports, "isNewReachedPage", {
75
63
  return _pageTag.isNewReachedPage;
76
64
  }
77
65
  });
78
- Object.defineProperty(exports, "isPaginatedLoop", {
79
- enumerable: true,
80
- get: function get() {
81
- return _isPaginatedLoop["default"];
82
- }
83
- });
84
66
  Object.defineProperty(exports, "useComponentsFromState", {
85
67
  enumerable: true,
86
68
  get: function get() {
@@ -90,13 +72,10 @@ Object.defineProperty(exports, "useComponentsFromState", {
90
72
  var _checkLoops = _interopRequireDefault(require("./check-loops"));
91
73
  var _createMapPages = _interopRequireDefault(require("./create-map-pages"));
92
74
  var _executeConditionFilter = _interopRequireDefault(require("./execute-condition-filter"));
93
- var _executeExpression = _interopRequireDefault(require("./execute-expression"));
94
75
  var _fillComponentExpressions = _interopRequireDefault(require("./fill-components/fill-component-expressions"));
95
76
  var _getCompatibleVtlExpression = _interopRequireDefault(require("./get-compatible-vtl-expression"));
96
77
  var _getComponentsFromState = _interopRequireDefault(require("./get-components-from-state"));
97
- var _getErrorsWithoutEmptyValue = _interopRequireDefault(require("./get-errors-without-empty-value"));
98
78
  var _isFirstLastPage = _interopRequireDefault(require("./is-First-last-page"));
99
- var _isPaginatedLoop = _interopRequireDefault(require("./is-paginated-loop"));
100
79
  var _pageTag = require("./page-tag");
101
80
  var _useComponentsFromState = _interopRequireDefault(require("./use-components-from-state"));
102
81
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cleaningBehaviour = cleaningBehaviour;
7
+ /**
8
+ * Cleaning behaviour for the store
9
+ * When a variable changes, other variables can be reset
10
+ */
11
+ function cleaningBehaviour(store, cleaning) {
12
+ var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
13
+ if (!cleaning) {
14
+ return;
15
+ }
16
+
17
+ // Create a map to improve performance
18
+ var cleaningMap = new Map(Object.entries(cleaning));
19
+ store.on('change', function (e) {
20
+ var cleaningInfo = cleaningMap.get(e.detail.name);
21
+
22
+ // The variable does not have cleaning
23
+ if (!cleaningInfo) {
24
+ return;
25
+ }
26
+ for (var variableName in cleaningInfo) {
27
+ var _initialValues$variab;
28
+ var skipCleaning = store.run(cleaningInfo[variableName], {
29
+ iteration: e.detail.iteration
30
+ });
31
+ if (skipCleaning) {
32
+ continue;
33
+ }
34
+ store.set(variableName, (_initialValues$variab = initialValues[variableName]) !== null && _initialValues$variab !== void 0 ? _initialValues$variab : null, {
35
+ iteration: e.detail.iteration
36
+ });
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.missingBehaviour = missingBehaviour;
7
+ 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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
8
+ 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); }
9
+ 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; }
10
+ /**
11
+ * Add missing behaviour to the store
12
+ * Missing works as a simplified cleaning that reset a linked variable
13
+ */
14
+ function missingBehaviour(store, missing) {
15
+ if (!missing) {
16
+ return;
17
+ }
18
+
19
+ // Create a map to improve performance
20
+ var missingMap = new Map(Object.entries(missing));
21
+ store.on('change', function (e) {
22
+ // Only clean if a value is set
23
+ if (e.detail.value === null || e.detail.value === undefined) {
24
+ return;
25
+ }
26
+ var linkedVariables = missingMap.get(e.detail.name);
27
+
28
+ // The variable does not have missing variable linked
29
+ if (!linkedVariables) {
30
+ return;
31
+ }
32
+ var _iterator = _createForOfIteratorHelper(linkedVariables),
33
+ _step;
34
+ try {
35
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
36
+ var variableName = _step.value;
37
+ store.set(variableName, null, {
38
+ iteration: e.detail.iteration
39
+ });
40
+ }
41
+ } catch (err) {
42
+ _iterator.e(err);
43
+ } finally {
44
+ _iterator.f();
45
+ }
46
+ });
47
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resizingBehaviour = resizingBehaviour;
7
+ var _number = require("../../../../utils/number");
8
+ var _commons = require("../../../reducer/commons");
9
+ var _vtl = require("../../../../utils/vtl");
10
+ var _array = require("../../../../utils/array");
11
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
14
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
+ 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(_e2) { throw _e2; }, 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 e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
16
+ 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); }
17
+ 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; }
18
+ /**
19
+ * Resizing behaviour for the store
20
+ * When a variable changes, multiple other variables can change size (size of the array)
21
+ */
22
+ function resizingBehaviour(store, resizing) {
23
+ if (!resizing) {
24
+ return;
25
+ }
26
+
27
+ // Create a map to improve performance
28
+ var resizingMap = new Map(Object.entries(resizing));
29
+ store.on('change', function (e) {
30
+ // The variable does not have resizing
31
+ var resizingInfo = resizingMap.get(e.detail.name);
32
+ if (!resizingInfo) {
33
+ return;
34
+ }
35
+
36
+ // Pairwise resizing
37
+ if ('sizeForLinksVariables' in resizingInfo) {
38
+ resizePairwise(store, resizingInfo, e.detail);
39
+ return;
40
+ }
41
+ if (!resizingInfo.size) {
42
+ throw new Error("Cannot resize ".concat(e.detail.name, " missing \"size\" property"));
43
+ }
44
+ var newSize = (0, _number.forceInt)(store.run(resizingInfo.size));
45
+ var _iterator = _createForOfIteratorHelper(resizingInfo.variables),
46
+ _step;
47
+ try {
48
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
49
+ var variableName = _step.value;
50
+ var value = store.get(variableName);
51
+ if (!Array.isArray(value) || value.length !== newSize) {
52
+ store.set(variableName, (0, _commons.resizeArrayVariable)(value, newSize, null));
53
+ }
54
+ }
55
+ } catch (err) {
56
+ _iterator.e(err);
57
+ } finally {
58
+ _iterator.f();
59
+ }
60
+ });
61
+ }
62
+ function resizePairwise(store, resizingInfo, args) {
63
+ var _resizingInfo$sizeFor = resizingInfo.sizeForLinksVariables.map(function (expression) {
64
+ return (0, _number.forceInt)(store.run((0, _vtl.getExpressionAsString)(expression)));
65
+ }),
66
+ _resizingInfo$sizeFor2 = _slicedToArray(_resizingInfo$sizeFor, 2),
67
+ xSize = _resizingInfo$sizeFor2[0],
68
+ ySize = _resizingInfo$sizeFor2[1];
69
+ resizingInfo.linksVariables.forEach(function (variable) {
70
+ var value = store.get(variable, args.iteration);
71
+ var resizedValue = (0, _array.resizeArray)(
72
+ // The value is not an array, force an array
73
+ Array.isArray(value) ? value.map(function (i) {
74
+ return (0, _array.resizeArray)(i, ySize, null);
75
+ }) : [], xSize, new Array(ySize).fill(null));
76
+ store.set(variable, resizedValue);
77
+ });
78
+ }
@@ -1,44 +1,65 @@
1
1
  "use strict";
2
2
 
3
- 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); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
- exports["default"] = void 0;
8
- var _commons = require("../commons");
6
+ exports.getQuestionnaireData = getQuestionnaireData;
7
+ 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); }
8
+ 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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
9
+ 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); }
10
+ 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; }
9
11
  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; }
10
12
  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; }
11
13
  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; }
12
14
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
15
  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); }
14
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
- 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."); }
16
- 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); }
17
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
18
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
- 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; }
20
- /**
21
- * Inject the value at a specific index (and resize the value if necessary)
22
- */
23
- function reduceVariablesArray(variables, args) {
24
- var name = args.name,
25
- value = args.value,
26
- index = args.index,
27
- length = args.length;
28
- if (name in variables) {
29
- var variable = variables[name];
30
- var previousValue = variable.value;
31
-
32
- // Ensure the value is an array of corresponding size
33
- var valueNext = _toConsumableArray((0, _commons.resizeArrayVariable)(previousValue, length));
16
+ function getQuestionnaireData(store, variables) {
17
+ var withCalculated = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
18
+ var variableNames = arguments.length > 3 ? arguments[3] : undefined;
19
+ var result = {
20
+ EXTERNAL: {},
21
+ CALCULATED: {},
22
+ COLLECTED: {}
23
+ };
24
+ if (!variables) {
25
+ return result;
26
+ }
34
27
 
35
- // Inject the new value at the corresponding index
36
- valueNext[index] = value;
37
- return _objectSpread(_objectSpread({}, variables), {}, _defineProperty({}, name, _objectSpread(_objectSpread({}, variable), {}, {
38
- value: valueNext
39
- })));
28
+ // Only return requested variables
29
+ if (variableNames) {
30
+ return _objectSpread(_objectSpread({}, result), {}, {
31
+ COLLECTED: Object.fromEntries(variableNames.map(function (name) {
32
+ return [name, {
33
+ EDITED: null,
34
+ FORCED: null,
35
+ INPUTED: null,
36
+ PREVIOUS: null,
37
+ COLLECTED: store.get(name)
38
+ }];
39
+ }))
40
+ });
41
+ }
42
+ var _iterator = _createForOfIteratorHelper(variables),
43
+ _step;
44
+ try {
45
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
46
+ var variable = _step.value;
47
+ // Skip calculated value if necessary
48
+ if (variable.variableType === 'CALCULATED' && !withCalculated) {
49
+ continue;
50
+ }
51
+ if (variable.variableType === 'COLLECTED') {
52
+ result.COLLECTED[variable.name] = _objectSpread(_objectSpread({}, variable.values), {}, {
53
+ COLLECTED: store.get(variable.name)
54
+ });
55
+ } else {
56
+ result[variable.variableType][variable.name] = store.get(variable.name);
57
+ }
58
+ }
59
+ } catch (err) {
60
+ _iterator.e(err);
61
+ } finally {
62
+ _iterator.f();
40
63
  }
41
- return variables;
42
- }
43
- var _default = reduceVariablesArray;
44
- exports["default"] = _default;
64
+ return result;
65
+ }
@@ -0,0 +1,330 @@
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
+ }();