@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.
- package/README.md +49 -3
- package/lib/components/checkbox/checkbox-boolean/html/checkbox-boolean.js +3 -3
- package/lib/components/checkbox/checkbox-boolean/lunatic-checkbox-boolean.js +7 -1
- package/lib/components/checkbox/checkbox-group/checkbox-group-content.js +0 -2
- package/lib/components/checkbox/checkbox-group/html/checkbox-group-content.js +4 -2
- package/lib/components/checkbox/checkbox-group/html/checkbox-group.js +3 -3
- package/lib/components/checkbox/checkbox-group/lunatic-checkbox-group.js +2 -1
- package/lib/components/checkbox/checkbox-one/lunatic-checkbox-one.js +2 -1
- package/lib/components/checkbox/commons/checkbox-option.js +3 -1
- package/lib/components/commons/components/combo-box/combo-box-container.js +1 -2
- package/lib/components/commons/components/combo-box/combo-box.js +2 -2
- package/lib/components/commons/components/combo-box/selection/LabelOrInput.js +3 -1
- package/lib/components/commons/components/combo-box/selection/input.js +3 -1
- package/lib/components/commons/components/combo-box/selection/selection.js +3 -1
- package/lib/components/commons/components/errors/errors.js +12 -10
- package/lib/components/commons/components/errors/errors.spec.js +6 -6
- package/lib/components/component-set/html/__snapshots__/component-set.spec.tsx.snap +2 -0
- package/lib/components/component-set/html/component-set.js +2 -2
- package/lib/components/datepicker/html/__snapshots__/datepicker.spec.tsx.snap +2 -0
- package/lib/components/datepicker/html/datepicker-input.js +4 -2
- package/lib/components/datepicker/html/datepicker.js +3 -3
- package/lib/components/datepicker/lunatic-datepicker.js +2 -1
- package/lib/components/dropdown/lunatic-dropdown.js +2 -1
- package/lib/components/index.js +4 -4
- package/lib/components/input/html/__snapshots__/input.spec.tsx.snap +2 -0
- package/lib/components/input/html/input.js +3 -3
- package/lib/components/input/lunatic-input.js +2 -1
- package/lib/components/input-number/html/__snapshots__/input-number.spec.tsx.snap +2 -2
- package/lib/components/input-number/html/input-number-thousand.js +4 -17
- package/lib/components/input-number/html/input-number.js +3 -5
- package/lib/components/input-number/lunatic-input-number.js +2 -3
- package/lib/components/loop/block-for-loop.js +10 -6
- package/lib/components/loop/roster-for-loop/roster-for-loop.js +35 -27
- package/lib/components/loop/utils/get-initial-nb-rows.js +17 -0
- package/lib/components/lunatic-components.js +7 -27
- package/lib/components/pairwise-links/index.js +13 -0
- package/lib/components/pairwise-links/orchestrator.js +71 -0
- package/lib/components/pairwise-links/pairwise-links.js +30 -27
- package/lib/components/pairwise-links/row.js +74 -0
- package/lib/components/radio/html/radio-group-content.js +4 -2
- package/lib/components/radio/html/radio-group.js +3 -3
- package/lib/components/radio/html/radio-option.js +3 -1
- package/lib/components/radio/lunatic-radio-group.js +2 -1
- package/lib/components/suggester/find-best-label/find-best-label.js +6 -6
- package/lib/components/suggester/idb-suggester/idb-suggester.js +4 -3
- package/lib/components/suggester/lunatic-suggester.js +7 -4
- package/lib/components/suggester/searching/create-searching.js +20 -39
- package/lib/components/switch/html/switch.js +2 -2
- package/lib/components/switch/lunatic-switch.js +2 -1
- package/lib/components/table/cell.js +89 -0
- package/lib/components/table/{table-header.js → header.js} +5 -3
- package/lib/components/table/index.js +13 -0
- package/lib/components/table/lunatic-table.js +15 -24
- package/lib/components/table/row.js +40 -0
- package/lib/components/table/table-orchestrator.js +35 -0
- package/lib/components/textarea/html/__snapshots__/textarea.spec.tsx.snap +2 -0
- package/lib/components/textarea/html/textarea.js +6 -4
- package/lib/components/textarea/lunatic-textarea.js +6 -3
- package/lib/hooks/use-auto-focus.js +26 -0
- package/lib/src/components/checkbox/checkbox-boolean/html/checkbox-boolean.d.ts +1 -1
- package/lib/src/components/checkbox/checkbox-group/html/checkbox-group-content.d.ts +2 -1
- package/lib/src/components/checkbox/checkbox-group/html/checkbox-group.d.ts +1 -1
- package/lib/src/components/checkbox/commons/checkbox-option.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/combo-box-container.d.ts +2 -2
- package/lib/src/components/commons/components/combo-box/combo-box.d.ts +2 -2
- package/lib/src/components/commons/components/combo-box/combo-box.stories.d.ts +4 -6
- package/lib/src/components/commons/components/combo-box/selection/LabelOrInput.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/selection/input.d.ts +1 -0
- package/lib/src/components/commons/components/combo-box/selection/selection.d.ts +2 -1
- package/lib/src/components/commons/components/errors/errors.d.ts +6 -3
- package/lib/src/components/datepicker/html/datepicker-input.d.ts +2 -1
- package/lib/src/components/datepicker/html/datepicker.d.ts +1 -1
- package/lib/src/components/dropdown/html/dropdown-writable/dropdown-writable.d.ts +1 -1
- package/lib/src/components/dropdown/html/dropdown.d.ts +3 -1
- package/lib/src/components/index.d.ts +2 -2
- package/lib/src/components/input/html/input.d.ts +2 -2
- package/lib/src/components/input-number/html/input-number-thousand.d.ts +2 -2
- package/lib/src/components/input-number/html/input-number.d.ts +2 -3
- package/lib/src/components/loop/block-for-loop.d.ts +4 -3
- package/lib/src/components/loop/roster-for-loop/roster-for-loop.d.ts +4 -3
- package/lib/src/components/loop/utils/get-initial-nb-rows.d.ts +4 -0
- package/lib/src/components/lunatic-components.d.ts +3 -5
- package/lib/src/components/pairwise-links/index.d.ts +1 -0
- package/lib/src/components/pairwise-links/orchestrator.d.ts +6 -0
- package/lib/src/components/pairwise-links/pairwise-links.d.ts +2 -1
- package/lib/src/components/pairwise-links/row.d.ts +7 -0
- package/lib/src/components/radio/html/radio-group-content.d.ts +2 -1
- package/lib/src/components/radio/html/radio-group.d.ts +1 -1
- package/lib/src/components/radio/html/radio-option.d.ts +1 -0
- package/lib/src/components/suggester/find-best-label/find-best-label.d.ts +1 -1
- package/lib/src/components/suggester/html/suggester.d.ts +1 -1
- package/lib/src/components/suggester/idb-suggester/idb-suggester.d.ts +5 -2
- package/lib/src/components/suggester/lunatic-suggester.d.ts +1 -1
- package/lib/src/components/suggester/searching/create-searching.d.ts +1 -1
- package/lib/src/components/switch/html/switch.d.ts +1 -1
- package/lib/src/components/table/cell.d.ts +19 -0
- package/lib/src/components/table/{table-header.d.ts → header.d.ts} +2 -2
- package/lib/src/components/table/index.d.ts +1 -0
- package/lib/src/components/table/lunatic-table.d.ts +1 -1
- package/lib/src/components/table/row.d.ts +18 -0
- package/lib/src/components/table/table-orchestrator.d.ts +4 -0
- package/lib/src/components/textarea/html/textarea.d.ts +3 -2
- package/lib/src/components/type.d.ts +9 -7
- package/lib/src/hooks/use-auto-focus.d.ts +6 -0
- package/lib/src/use-lunatic/actions.d.ts +19 -3
- package/lib/src/use-lunatic/commons/calculated-variables.d.ts +8 -0
- package/lib/src/use-lunatic/commons/compile-controls.d.ts +2 -3
- package/lib/src/use-lunatic/commons/execute-expression/create-execute-expression.d.ts +9 -0
- package/lib/src/use-lunatic/commons/execute-expression/create-memoizer.d.ts +8 -0
- package/lib/src/use-lunatic/commons/execute-expression/create-refresh-calculated.d.ts +24 -0
- package/lib/src/use-lunatic/commons/execute-expression/execute-expression.d.ts +11 -0
- package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.d.ts +7 -0
- package/lib/src/use-lunatic/commons/execute-expression/get-expressions-variables.spec.d.ts +1 -0
- package/lib/src/use-lunatic/commons/execute-expression/get-safety-expression.d.ts +6 -0
- package/lib/src/use-lunatic/commons/execute-expression/index.d.ts +1 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-required.d.ts +418 -0
- package/lib/src/use-lunatic/commons/fill-components/fill-component-value.d.ts +3 -2
- package/lib/src/use-lunatic/commons/fill-components/fill-components.d.ts +0 -6
- package/lib/src/use-lunatic/commons/fill-components/fill-from-state.d.ts +142 -107
- package/lib/src/use-lunatic/commons/fill-components/fill-specific-expression.d.ts +89 -53
- package/lib/src/use-lunatic/commons/get-compatible-vtl-expression.d.ts +0 -1
- package/lib/src/use-lunatic/commons/get-component-value/get-component-value.d.ts +6 -0
- package/lib/src/use-lunatic/commons/get-component-value/index.d.ts +1 -0
- package/lib/src/use-lunatic/commons/get-data.d.ts +26 -0
- package/lib/src/use-lunatic/commons/index.d.ts +3 -0
- package/lib/src/use-lunatic/reducer/overview/overview-on-init.d.ts +9 -10
- package/lib/src/use-lunatic/reducer/reduce-handle-change/index.d.ts +1 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.d.ts +7 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.d.ts +1 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.d.ts +4 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.d.ts +15 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-missing.d.ts +7 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-resizing.d.ts +4 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-array.d.ts +14 -0
- package/lib/src/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.d.ts +9 -0
- package/lib/src/use-lunatic/reducer/reduce-on-init.d.ts +12 -1
- package/lib/src/use-lunatic/reducer/reduce-on-init.spec.d.ts +1 -0
- package/lib/src/use-lunatic/type-source.d.ts +21 -7
- package/lib/src/use-lunatic/type.d.ts +12 -13
- package/lib/src/use-lunatic/use-lunatic.d.ts +62 -36
- package/lib/src/use-lunatic/use-suggesters.d.ts +2 -1
- package/lib/src/utils/array.d.ts +1 -6
- package/lib/src/utils/number.d.ts +0 -4
- package/lib/src/utils/suggester-workers/append-to-index/create-append-task.d.ts +1 -1
- package/lib/src/utils/suggester-workers/worker-path.d.ts +6 -0
- package/lib/src/utils/vtl/dataset-builder.d.ts +5 -0
- package/lib/src/utils/vtl/index.d.ts +1 -0
- package/lib/stories/behaviour/cleaning/source.json +151 -0
- package/lib/stories/behaviour/cleaning/test.stories.js +84 -0
- package/lib/stories/{questionnaires-test → behaviour}/controls/controls.stories.js +5 -5
- package/lib/stories/{questionnaires-test → behaviour/others}/test.stories.js +7 -7
- package/lib/stories/{paste-questionnaire → behaviour/paste}/test.stories.js +3 -3
- package/lib/stories/{resizing-questionnaire → behaviour/resizing}/test.stories.js +3 -3
- package/lib/use-lunatic/actions.js +3 -3
- package/lib/use-lunatic/commons/calculated-variables.js +104 -0
- package/lib/use-lunatic/commons/compile-controls.js +5 -3
- package/lib/use-lunatic/commons/execute-condition-filter.js +9 -1
- package/lib/use-lunatic/commons/execute-expression/create-execute-expression.js +233 -0
- package/lib/use-lunatic/commons/execute-expression/create-execute-expression.spec.js +155 -0
- package/lib/use-lunatic/commons/execute-expression/create-memoizer.js +63 -0
- package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.js +149 -0
- package/lib/use-lunatic/commons/execute-expression/create-refresh-calculated.spec.js +130 -0
- package/lib/use-lunatic/commons/execute-expression/execute-expression.js +90 -0
- package/lib/use-lunatic/commons/execute-expression/execute-expression.spec.js +38 -0
- package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.js +40 -0
- package/lib/use-lunatic/commons/execute-expression/get-expressions-variables.spec.js +31 -0
- package/lib/use-lunatic/commons/{fill-components/fill-iterations.js → execute-expression/get-safety-expression.js} +20 -30
- package/lib/use-lunatic/commons/execute-expression/index.js +13 -0
- package/lib/use-lunatic/commons/fill-components/fill-component-expressions.js +3 -2
- package/lib/use-lunatic/{reducer/reduce-handle-change.js → commons/fill-components/fill-component-required.js} +8 -14
- package/lib/use-lunatic/commons/fill-components/fill-component-value.js +7 -21
- package/lib/use-lunatic/commons/fill-components/fill-components.js +4 -5
- package/lib/use-lunatic/commons/fill-components/fill-from-state.js +2 -0
- package/lib/use-lunatic/commons/fill-components/fill-missing-response.js +13 -6
- package/lib/use-lunatic/commons/fill-components/fill-specific-expression.js +5 -58
- package/lib/use-lunatic/commons/get-compatible-vtl-expression.js +0 -1
- package/lib/use-lunatic/commons/get-component-value/get-component-value.js +174 -0
- package/lib/use-lunatic/commons/get-component-value/index.js +13 -0
- package/lib/use-lunatic/commons/get-data.js +80 -0
- package/lib/use-lunatic/commons/index.js +21 -0
- package/lib/use-lunatic/initial-state.js +4 -6
- package/lib/use-lunatic/reducer/overview/overview-on-change.js +1 -1
- package/lib/use-lunatic/reducer/reduce-handle-change/__mocks__/source-cleaning-loop.json +792 -0
- package/lib/use-lunatic/reducer/reduce-handle-change/index.js +13 -0
- package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.js +78 -0
- package/lib/use-lunatic/reducer/reduce-handle-change/reduce-cleaning.spec.js +46 -0
- package/lib/use-lunatic/reducer/reduce-handle-change/reduce-handle-change.js +115 -0
- package/lib/use-lunatic/reducer/reduce-handle-change/reduce-links-variable.js +89 -0
- package/lib/use-lunatic/reducer/reduce-handle-change/reduce-missing.js +88 -0
- package/lib/use-lunatic/reducer/reduce-handle-change/reduce-resizing.js +119 -0
- package/lib/use-lunatic/{commons/variables/get-questionnaire-data.js → reducer/reduce-handle-change/reduce-variables-array.js} +32 -53
- package/lib/use-lunatic/reducer/reduce-handle-change/reduce-variables-simple.js +28 -0
- package/lib/use-lunatic/reducer/reduce-on-init.js +184 -90
- package/lib/use-lunatic/reducer/reduce-on-init.spec.js +17 -0
- package/lib/use-lunatic/reducer/reducer.js +2 -2
- package/lib/use-lunatic/reducer/resolve-component-controls/resolve-simple-control.js +4 -2
- package/lib/use-lunatic/use-lunatic.js +29 -22
- package/lib/use-lunatic/use-lunatic.test.js +36 -133
- package/lib/use-lunatic/use-suggesters.js +4 -3
- package/lib/utils/array.js +6 -57
- package/lib/utils/get-component-value.js +9 -3
- package/lib/utils/number.js +1 -13
- package/lib/utils/suggester-workers/append-to-index/create-append-task.js +4 -3
- package/lib/utils/suggester-workers/worker-path.js +29 -0
- package/lib/utils/vtl/dataset-builder.js +27 -0
- package/lib/utils/vtl/index.js +13 -0
- package/package.json +15 -10
- package/scripts/build/add-workers-to-public.js +44 -0
- package/scripts/build/workers-paths.js +44 -0
- package/workers-release/lunatic-append-worker-0.3.0-experimental.js +2 -0
- package/workers-release/lunatic-append-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
- package/workers-release/lunatic-label-worker-0.3.0-experimental.js +2 -0
- package/workers-release/lunatic-label-worker-0.3.0-experimental.js.LICENSE.txt +13 -0
- package/workers-release/lunatic-searching-worker-0.3.0-experimental.js +2 -0
- package/workers-release/lunatic-searching-worker-0.3.0-experimental.js.LICENSE.txt +34 -0
- package/lib/hooks/use-track-changes.js +0 -50
- package/lib/src/hooks/use-track-changes.d.ts +0 -9
- package/lib/src/use-lunatic/commons/component.d.ts +0 -22
- package/lib/src/use-lunatic/commons/fill-components/fill-iterations.d.ts +0 -112
- package/lib/src/use-lunatic/commons/variables/behaviours/cleaning-behaviour.d.ts +0 -7
- package/lib/src/use-lunatic/commons/variables/behaviours/missing-behaviour.d.ts +0 -7
- package/lib/src/use-lunatic/commons/variables/behaviours/resizing-behaviour.d.ts +0 -7
- package/lib/src/use-lunatic/commons/variables/get-questionnaire-data.d.ts +0 -4
- package/lib/src/use-lunatic/commons/variables/lunatic-variables-store.d.ts +0 -77
- package/lib/src/use-lunatic/reducer/reduce-handle-change.d.ts +0 -6
- package/lib/src/utils/env.d.ts +0 -1
- package/lib/src/utils/store-tools/worker-path.d.ts +0 -1
- package/lib/src/utils/variables.d.ts +0 -5
- package/lib/src/utils/vtl.d.ts +0 -14
- package/lib/use-lunatic/commons/component.js +0 -22
- package/lib/use-lunatic/commons/variables/behaviours/cleaning-behaviour.js +0 -39
- package/lib/use-lunatic/commons/variables/behaviours/missing-behaviour.js +0 -47
- package/lib/use-lunatic/commons/variables/behaviours/resizing-behaviour.js +0 -78
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.js +0 -330
- package/lib/use-lunatic/commons/variables/lunatic-variables-store.spec.js +0 -216
- package/lib/utils/array.spec.js +0 -30
- package/lib/utils/env.js +0 -10
- package/lib/utils/store-tools/worker-path.js +0 -13
- package/lib/utils/suggester-workers/create-worker.js +0 -55
- package/lib/utils/variables.js +0 -37
- package/lib/utils/vtl.js +0 -100
- /package/lib/src/use-lunatic/commons/{variables/lunatic-variables-store.spec.d.ts → execute-expression/create-refresh-calculated.spec.d.ts} +0 -0
- /package/lib/src/{utils/array.spec.d.ts → use-lunatic/commons/execute-expression/execute-expression.spec.d.ts} +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNonNum_horsBoucle_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_ControlesNum_horsBoucle_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees2_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/V2_Controles_BouclesLiees_PasPageFin.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/boucles-n.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour}/controls/controls-externes.stories.js +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_DeclarationsSimples.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_MinMaxSum_Boucles.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_QuestSimple_Boucles.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/V2_TCMRallyeGames.json +0 -0
- /package/lib/stories/{questionnaires-test → behaviour/others}/test-dylan.json +0 -0
- /package/lib/stories/{paste-questionnaire → behaviour/paste}/source.json +0 -0
- /package/lib/stories/{resizing-questionnaire → behaviour/resizing}/source.json +0 -0
|
@@ -0,0 +1,149 @@
|
|
|
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;
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
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;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
});
|
|
@@ -3,43 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var _number = require("../../../utils/number");
|
|
9
|
-
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); }
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _constants = require("../../../utils/constants");
|
|
10
8
|
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; }
|
|
11
9
|
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; }
|
|
12
10
|
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; }
|
|
13
11
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
12
|
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); }
|
|
13
|
+
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); }
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
15
|
+
* Convert an unknown variable into a valid VTL expression object
|
|
17
16
|
*/
|
|
18
|
-
function
|
|
19
|
-
if (
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
17
|
+
function getSafetyExpression(expression) {
|
|
18
|
+
if (typeof expression === 'string') {
|
|
19
|
+
return {
|
|
20
|
+
value: expression,
|
|
21
|
+
type: _constants.VTL
|
|
22
|
+
};
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
// TODO: fix into model and supress this block
|
|
25
|
+
if (expression && _typeof(expression) === 'object' && 'value' in expression && !('type' in expression)) {
|
|
26
|
+
return _objectSpread(_objectSpread({}, expression), {}, {
|
|
27
|
+
type: _constants.VTL
|
|
28
|
+
});
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
var value = state.variables.get(component.response.name, (0, _number.isNumber)(state.pager.iteration) ? [state.pager.iteration] : undefined);
|
|
37
|
-
if (Array.isArray(value) && value.length > acc) {
|
|
38
|
-
return value.length;
|
|
39
|
-
}
|
|
40
|
-
return acc;
|
|
41
|
-
}, 0);
|
|
42
|
-
return _objectSpread(_objectSpread({}, component), {}, {
|
|
43
|
-
iterations: iterations
|
|
44
|
-
});
|
|
45
|
-
}
|
|
31
|
+
// TODO: ensure we really have an expression here or throw an error
|
|
32
|
+
return expression;
|
|
33
|
+
}
|
|
34
|
+
var _default = getSafetyExpression;
|
|
35
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 }; }
|
|
@@ -24,7 +24,7 @@ var VTL_ATTRIBUTES = ['label', 'options.label', 'responses.label', 'hierarchy.la
|
|
|
24
24
|
// Disable controls compilation
|
|
25
25
|
// 'controls.control',
|
|
26
26
|
// 'controls.errorMessage',
|
|
27
|
-
'controls.iterations', 'lines.min', 'lines.max', 'xAxisIterations', 'yAxisIterations', 'conditionFilter', 'headers.label', 'header.label', 'disabled', 'readOnly'];
|
|
27
|
+
'controls.iterations', 'lines.min', 'lines.max', 'iterations', 'xAxisIterations', 'yAxisIterations', 'conditionFilter', 'headers.label', 'header.label', 'disabled', 'readOnly'];
|
|
28
28
|
|
|
29
29
|
// Utility type to replace all expression from an object into a translated version
|
|
30
30
|
|
|
@@ -39,7 +39,8 @@ function createCrawl(_ref) {
|
|
|
39
39
|
var candidate = object[path];
|
|
40
40
|
try {
|
|
41
41
|
return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, executeExpression(candidate, {
|
|
42
|
-
iteration:
|
|
42
|
+
iteration: iteration,
|
|
43
|
+
linksIterations: linksIterations
|
|
43
44
|
})));
|
|
44
45
|
} catch (e) {
|
|
45
46
|
return _objectSpread(_objectSpread({}, object), {}, _defineProperty({}, path, e instanceof Error ? e.toString() : e));
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _number = require("../../utils/number");
|
|
6
|
+
exports.fillComponentRequired = fillComponentRequired;
|
|
8
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); }
|
|
9
8
|
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
9
|
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; }
|
|
@@ -12,18 +11,13 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
12
11
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
12
|
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
13
|
/**
|
|
15
|
-
*
|
|
14
|
+
* Add required attribute on component that are mandatory
|
|
16
15
|
*/
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
function fillComponentRequired(component) {
|
|
17
|
+
if (component.mandatory) {
|
|
18
|
+
return _objectSpread(_objectSpread({}, component), {}, {
|
|
19
|
+
required: true
|
|
20
|
+
});
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
iteration: iteration
|
|
25
|
-
});
|
|
26
|
-
return _objectSpread(_objectSpread({}, state), {}, {
|
|
27
|
-
updatedAt: Date.now()
|
|
28
|
-
});
|
|
22
|
+
return component;
|
|
29
23
|
}
|