@inseefr/lunatic 2.6.2-rc.1 → 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
@@ -1,149 +0,0 @@
1
- "use strict";
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
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _constants = require("../../../utils/constants");
9
- 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
- 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
- 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
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
13
- 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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
15
- 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."); }
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
- 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; } }
19
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
- /**
21
- * Refresh calculated variables with the new value in the bindings
22
- */
23
- function createRefreshCalculated(_ref) {
24
- var variables = _ref.variables,
25
- execute = _ref.execute,
26
- bindings = _ref.bindings;
27
- /**
28
- * Links beetween calculated and collected variables :
29
- * changes on collected involve changes on correlated variables.
30
- */
31
- var toRefreshVariables = new Map();
32
-
33
- // On start, all calculated variables need to be refresh.
34
- Object.values(variables).forEach(function (_ref2) {
35
- var variable = _ref2.variable;
36
- var variableType = variable.variableType,
37
- name = variable.name;
38
- if (variableType === _constants.CALCULATED) {
39
- toRefreshVariables.set(name, variable);
40
- }
41
- });
42
- function getIteration(_ref3) {
43
- var name = _ref3.name,
44
- iteration = _ref3.iteration,
45
- linksIterations = _ref3.linksIterations;
46
- if (name === _constants.X_AXIS && linksIterations) return linksIterations[0];
47
- if (name === _constants.Y_AXIS && linksIterations) return linksIterations[1];
48
- return iteration;
49
- }
50
- function buildValue(args) {
51
- var expression = args.expression,
52
- logging = args.logging,
53
- shapeFrom = args.shapeFrom,
54
- name = args.name,
55
- iteration = args.iteration,
56
- linksIterations = args.linksIterations;
57
- var value = execute(expression, {
58
- logging: logging,
59
- iteration: shapeFrom ? getIteration({
60
- name: name,
61
- iteration: iteration,
62
- linksIterations: linksIterations
63
- }) : undefined
64
- });
65
- if (linksIterations !== undefined) return value;
66
- if (shapeFrom && iteration !== undefined) {
67
- if (bindings[name] === undefined) {
68
- var shapeVariable = bindings[shapeFrom];
69
- if (Array.isArray(shapeVariable)) {
70
- var initialValue = shapeVariable.map(function (_, i) {
71
- return execute(expression, {
72
- logging: logging,
73
- iteration: i
74
- });
75
- });
76
- bindings[name] = initialValue;
77
- return initialValue[iteration];
78
- }
79
- }
80
- var binding = bindings[name];
81
- if (Array.isArray(binding)) {
82
- binding[iteration] = value;
83
- return binding[iteration];
84
- } else {
85
- console.error("Binding not array! ".concat(bindings[name], " for ").concat(name));
86
- bindings[name] = null;
87
- return null;
88
- }
89
- } else if (shapeFrom && iteration === undefined) {
90
- // TODO: optimize
91
- var baseVar = bindings[shapeFrom];
92
- if (Array.isArray(baseVar)) {
93
- var v = baseVar.map(function (_, i) {
94
- return execute(expression, {
95
- logging: logging,
96
- iteration: i
97
- });
98
- });
99
- bindings[name] = v;
100
- return v;
101
- }
102
- }
103
- bindings[name] = value;
104
- return value;
105
- }
106
- function refreshCalculated(map) {
107
- var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
108
- rootExpression = _ref4.rootExpression,
109
- iteration = _ref4.iteration,
110
- linksIterations = _ref4.linksIterations;
111
- return Object.entries(map).reduce(function (sub, _ref5) {
112
- var _ref6 = _slicedToArray(_ref5, 2),
113
- name = _ref6[0],
114
- current = _ref6[1];
115
- var calculatedVariable = variables[name];
116
- if (calculatedVariable.variable.variableType === _constants.CALCULATED && toRefreshVariables.has(name)) {
117
- var _calculatedVariable$v = calculatedVariable.variable,
118
- expression = _calculatedVariable$v.expression,
119
- shapeFrom = _calculatedVariable$v.shapeFrom;
120
- var logging = function logging(expression, bindings, e) {
121
- if (process.env.NODE_ENV === 'development') {
122
- console.warn("VTL error when refreshing calculated variable ".concat(name, " : ").concat(typeof expression === 'string' ? expression : expression.value), {
123
- bindings: bindings
124
- });
125
- console.warn("root expression : ".concat(rootExpression));
126
- console.warn(e);
127
- }
128
- };
129
- var value = buildValue({
130
- expression: expression,
131
- logging: logging,
132
- shapeFrom: shapeFrom,
133
- name: name,
134
- iteration: iteration,
135
- linksIterations: linksIterations
136
- });
137
- if (iteration !== undefined) toRefreshVariables["delete"](name);
138
- return _objectSpread(_objectSpread({}, sub), {}, _defineProperty({}, name, value));
139
- }
140
- return _objectSpread(_objectSpread({}, sub), {}, _defineProperty({}, name, current));
141
- }, {});
142
- }
143
- function setToRefreshCalculated(name, variable) {
144
- toRefreshVariables.set(name, variable);
145
- }
146
- return [refreshCalculated, setToRefreshCalculated];
147
- }
148
- var _default = createRefreshCalculated;
149
- exports["default"] = _default;
@@ -1,130 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _createRefreshCalculated = _interopRequireDefault(require("./create-refresh-calculated"));
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
- 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."); }
8
- 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; } }
9
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
11
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
13
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
14
- 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."); }
15
- 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); }
16
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
18
- 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; }
19
- var variables = {
20
- AGE: {
21
- type: 'COLLECTED',
22
- value: null,
23
- variable: {
24
- variableType: 'COLLECTED',
25
- values: {
26
- PREVIOUS: null,
27
- COLLECTED: null,
28
- FORCED: null,
29
- EDITED: null,
30
- INPUTED: null
31
- },
32
- name: 'AGE'
33
- }
34
- },
35
- COUNT_AGES: {
36
- type: 'CALCULATED',
37
- value: null,
38
- variable: {
39
- variableType: 'CALCULATED',
40
- name: 'COUNT_AGES',
41
- expression: {
42
- value: 'AGE.length',
43
- type: 'VTL'
44
- },
45
- bindingDependencies: ['AGE'],
46
- inFilter: 'true'
47
- }
48
- },
49
- AGE_ONE_PLUS: {
50
- type: 'CALCULATED',
51
- value: null,
52
- variable: {
53
- variableType: 'CALCULATED',
54
- name: 'AGE_ONE_PLUS',
55
- expression: {
56
- value: 'AGE + 1',
57
- type: 'VTL'
58
- },
59
- bindingDependencies: ['AGE'],
60
- inFilter: 'true',
61
- shapeFrom: 'AGE'
62
- }
63
- }
64
- };
65
-
66
- /**
67
- * Execute JavaScript expression to simulate VTL behaviour
68
- */
69
- var fakeExecute = function fakeExecute(bindings) {
70
- return function (expression) {
71
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
72
- // Assume this code doesn't provide vulnerabilities (only in test)
73
- // eslint-disable-next-line no-new-func
74
- return _construct(Function, _toConsumableArray(Object.keys(bindings)).concat(["return ".concat(expression.value)])).apply(void 0, _toConsumableArray(Object.values(bindings).map(function (value) {
75
- return options.iteration !== undefined && Array.isArray(value) ? value[options.iteration] : value;
76
- })));
77
- };
78
- };
79
- (0, _vitest.describe)('createRefreshCalculated', function () {
80
- (0, _vitest.it)('should recalculate simple variable', function () {
81
- var bindings = {
82
- AGE: [10, 20, 30]
83
- };
84
- var _createRefreshCalcula = (0, _createRefreshCalculated["default"])({
85
- variables: variables,
86
- execute: fakeExecute(bindings),
87
- bindings: bindings
88
- }),
89
- _createRefreshCalcula2 = _slicedToArray(_createRefreshCalcula, 1),
90
- refresh = _createRefreshCalcula2[0];
91
- (0, _vitest.expect)(refresh(variables, {}).COUNT_AGES).toBe(3);
92
- (0, _vitest.expect)(refresh(variables, {
93
- iteration: 1
94
- }).COUNT_AGES).toBe(3);
95
- (0, _vitest.expect)(bindings.AGE).toEqual([10, 20, 30]);
96
- (0, _vitest.expect)(bindings.COUNT_AGES).toEqual(3);
97
- });
98
- (0, _vitest.it)('should recalculate loop variables', function () {
99
- var bindings = {
100
- AGE: [10, 20, 30]
101
- };
102
- var _createRefreshCalcula3 = (0, _createRefreshCalculated["default"])({
103
- variables: variables,
104
- execute: fakeExecute(bindings),
105
- bindings: bindings
106
- }),
107
- _createRefreshCalcula4 = _slicedToArray(_createRefreshCalcula3, 1),
108
- refresh = _createRefreshCalcula4[0];
109
- (0, _vitest.expect)(refresh(variables).AGE_ONE_PLUS).toEqual([11, 21, 31]);
110
- (0, _vitest.expect)(bindings.AGE).toEqual([10, 20, 30]);
111
- (0, _vitest.expect)(bindings.AGE_ONE_PLUS).toEqual([11, 21, 31]);
112
- });
113
- (0, _vitest.it)('should recalculate loop variables with specific iteration', function () {
114
- var bindings = {
115
- AGE: [10, 20, 30]
116
- };
117
- var _createRefreshCalcula5 = (0, _createRefreshCalculated["default"])({
118
- variables: variables,
119
- execute: fakeExecute(bindings),
120
- bindings: bindings
121
- }),
122
- _createRefreshCalcula6 = _slicedToArray(_createRefreshCalcula5, 1),
123
- refresh = _createRefreshCalcula6[0];
124
- (0, _vitest.expect)(refresh(variables, {
125
- iteration: 1
126
- }).AGE_ONE_PLUS).toEqual(21);
127
- (0, _vitest.expect)(bindings.AGE).toEqual([10, 20, 30]);
128
- (0, _vitest.expect)(bindings.AGE_ONE_PLUS).toEqual([11, 21, 31]);
129
- });
130
- });
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- exports.executeVtlExpression = executeVtlExpression;
8
- var _trevas = require("@inseefr/trevas");
9
- var _mdLabel = _interopRequireDefault(require("../../../components/commons/components/md-label"));
10
- var _vtl = _interopRequireDefault(require("../../../utils/vtl"));
11
- var _constants = require("../../../utils/constants");
12
- var _jsxRuntime = require("react/jsx-runtime");
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
- 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; }
15
- 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; }
16
- 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; }
17
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
18
- 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); }
19
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
20
- 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."); }
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 _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; } }
24
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
- 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); }
26
- function isDataSet(result) {
27
- return _typeof(result) === 'object' && result !== null && 'dataPoints' in result && result.dataPoints !== null && _typeof(result.dataPoints) === 'object' && 'result' in result.dataPoints;
28
- }
29
- function extractDataSetResult(dataSet) {
30
- var dataPoints = dataSet.dataPoints;
31
- if (dataPoints) {
32
- var result = dataPoints.result;
33
- return result;
34
- }
35
- return undefined;
36
- }
37
-
38
- /**
39
- * Run a VTL expression and return the result
40
- */
41
- function executeVtlExpression(expression, vtlBindings) {
42
- // Make sur all values can be handled by VTL
43
- var legalVtlBindings = Object.entries(vtlBindings).reduce(function (acc, _ref) {
44
- var _ref2 = _slicedToArray(_ref, 2),
45
- k = _ref2[0],
46
- v = _ref2[1];
47
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, k, (0, _vtl["default"])(v)));
48
- }, {});
49
- var result = (0, _trevas.interpret)(expression, legalVtlBindings);
50
- if (isDataSet(result)) {
51
- return extractDataSetResult(result);
52
- }
53
- if (result === null) {
54
- return null;
55
- }
56
- if (_typeof(result) === 'object') {
57
- return expression;
58
- }
59
- return result;
60
- }
61
- function executeVTL(expression, vtlBindings, logging) {
62
- if (expression) {
63
- try {
64
- return executeVtlExpression(expression, vtlBindings);
65
- } catch (e) {
66
- logging(expression, vtlBindings, e);
67
- return expression;
68
- }
69
- }
70
- return '';
71
- }
72
- function loggingDefault(expression, bindings, e) {
73
- if (process.env.NODE_ENV === 'development') {
74
- console.warn("VTL error : ".concat(expression), bindings);
75
- console.warn(e);
76
- }
77
- }
78
- function executeExpression(vtlBindings, expression, type, features) {
79
- var logging = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : loggingDefault;
80
- if (features.includes(_constants.VTL) && type.includes(_constants.VTL)) {
81
- var vtl = executeVTL(expression, vtlBindings, logging);
82
- if (features.includes(_constants.MD) && type.includes(_constants.MD) && typeof vtl === 'string') return /*#__PURE__*/(0, _jsxRuntime.jsx)(_mdLabel["default"], {
83
- expression: vtl
84
- });
85
- return vtl;
86
- }
87
- return expression;
88
- }
89
- var _default = executeExpression;
90
- exports["default"] = _default;
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _executeExpression = _interopRequireDefault(require("./execute-expression"));
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
- 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."); }
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
- 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; } }
11
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
- (0, _vitest.describe)('executeVTL', function () {
13
- var cases = [['"Hello World"', {}, 'Hello World'], ['1', {}, 1], ['true', {}, true], ['this is a string', {}, 'this is a string'], ['"Hello" || " World"', {}, 'Hello World'], ['"Hello" || W', {
14
- W: ' World'
15
- }, 'Hello World'], ['W = 2', {
16
- W: 2
17
- }, true], ['W = 1', {
18
- W: 2
19
- }, false], ['cast(AGE, integer)', {
20
- AGE: '18'
21
- }, 18], ['count(V)', {
22
- V: [1, 2, 3]
23
- }, 3], ['(READY)', {
24
- READY: true
25
- }, true]];
26
- var _loop = function _loop() {
27
- var _cases$_i = _slicedToArray(_cases[_i], 3),
28
- expression = _cases$_i[0],
29
- bindings = _cases$_i[1],
30
- expectation = _cases$_i[2];
31
- (0, _vitest.test)("it should convert `".concat(expression, "` into ").concat(JSON.stringify(expectation)), function () {
32
- (0, _vitest.expect)((0, _executeExpression["default"])(bindings, expression, 'VTL', ['VTL'])).toBe(expectation);
33
- });
34
- };
35
- for (var _i = 0, _cases = cases; _i < _cases.length; _i++) {
36
- _loop();
37
- }
38
- });
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _vtl = require("@inseefr/vtl-2.0-antlr-tools");
8
- var _antlr = _interopRequireDefault(require("antlr4"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
11
- 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."); }
12
- 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); }
13
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
14
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
15
- 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; }
16
- /**
17
- * Find variables used in an expression
18
- */
19
- function getExpressionVariables(expression, variables) {
20
- try {
21
- var chars = new _antlr["default"].InputStream(expression);
22
- var lexer = new _vtl.VtlLexer(chars);
23
- return lexer.getAllTokens().reduce(function (array, _ref) {
24
- var start = _ref.start,
25
- stop = _ref.stop,
26
- type = _ref.type;
27
- if (type === 234) {
28
- var token = expression.substring(start, stop + 1);
29
- if (array.indexOf(token) === -1 && token in variables) {
30
- return [].concat(_toConsumableArray(array), [token]);
31
- }
32
- }
33
- return array;
34
- }, []);
35
- } catch (e) {
36
- return [];
37
- }
38
- }
39
- var _default = getExpressionVariables;
40
- exports["default"] = _default;
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _getExpressionsVariables = _interopRequireDefault(require("./get-expressions-variables"));
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
7
- 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."); }
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
- 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; } }
11
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
- (0, _vitest.describe)('getExpressionVariables', function () {
13
- var cases = [['(READY)', ['READY']]];
14
- var declaredVariables = {
15
- READY: {
16
- type: 'COLLECTED',
17
- value: true
18
- }
19
- };
20
- var _loop = function _loop() {
21
- var _cases$_i = _slicedToArray(_cases[_i], 2),
22
- expression = _cases$_i[0],
23
- variables = _cases$_i[1];
24
- (0, _vitest.test)("it should convert find variables in `".concat(expression, "`"), function () {
25
- (0, _vitest.expect)((0, _getExpressionsVariables["default"])(expression, declaredVariables)).toEqual(variables);
26
- });
27
- };
28
- for (var _i = 0, _cases = cases; _i < _cases.length; _i++) {
29
- _loop();
30
- }
31
- });
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "default", {
7
- enumerable: true,
8
- get: function get() {
9
- return _createExecuteExpression["default"];
10
- }
11
- });
12
- var _createExecuteExpression = _interopRequireDefault(require("./create-execute-expression"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }