@kontur.candy/generator 5.26.0-fs8433.0 → 5.26.0

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 (2) hide show
  1. package/dist/index.js +49 -21
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -75336,6 +75336,10 @@ __webpack_require__.r(__webpack_exports__);
75336
75336
  /* harmony import */ var _Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../../../Common/ModelPath/ModelPath */ "./Common/ModelPath/ModelPath.ts");
75337
75337
  /* harmony import */ var _KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../../KCXmlGenerator/KCXmlGeneratorBase */ "./Generator/src/generators/KCXmlGenerator/KCXmlGeneratorBase.ts");
75338
75338
  /* harmony import */ var _Common_IterableUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../../../../Common/IterableUtils */ "./Common/IterableUtils.ts");
75339
+ /* harmony import */ var _Common_Errors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../../../../Common/Errors */ "./Common/Errors.ts");
75340
+ /* harmony import */ var _Common_TypingUtils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../../../../Common/TypingUtils */ "./Common/TypingUtils.ts");
75341
+
75342
+
75339
75343
 
75340
75344
 
75341
75345
 
@@ -75345,9 +75349,9 @@ class AutoCalculationsCalculator2Generator extends _KCXmlGenerator_KCXmlGenerato
75345
75349
  this.dataDeclarationHelper = void 0;
75346
75350
  this.dataDeclarationHelper = dataDeclarationHelper;
75347
75351
  }
75348
- generate(formulas) {
75352
+ generate(formulas, options) {
75349
75353
  var _ref;
75350
- const compiledFormulas = (_ref = formulas !== null && formulas !== void 0 ? formulas : []) === null || _ref === void 0 ? void 0 : _ref.map(x => this.compileFormula(x));
75354
+ const compiledFormulas = (_ref = formulas !== null && formulas !== void 0 ? formulas : []) === null || _ref === void 0 ? void 0 : _ref.map(x => this.compileFormula(x, options)).filter(_Common_TypingUtils__WEBPACK_IMPORTED_MODULE_4__.isNotNullOrUndefined);
75351
75355
  const compiledAggregationFunctions = this.compileAggregationDependencies(compiledFormulas.map(x => x.dependencies).flat());
75352
75356
  const indent = " ";
75353
75357
  const allItemsText = compiledFormulas.map(x => x.compiledFunction).concat(compiledAggregationFunctions).map(x => `${indent}form.calculator2.addCalculationFunction(${x});`).join("\n");
@@ -75364,11 +75368,18 @@ class AutoCalculationsCalculator2Generator extends _KCXmlGenerator_KCXmlGenerato
75364
75368
  const compiledBlock = `(${compiledArgumentsCondition} ? undefined : ${innerExpression})`;
75365
75369
  return compiledBlock;
75366
75370
  }
75367
- compileFormula(formula) {
75371
+ compileFormula(formula, options) {
75368
75372
  const prefix = (0,_Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.createFromMask)(this.removeAttributePrefix(formula.match), true, _Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.PathTokens.each).toAbsolute();
75369
75373
  const target = this.schema.adjustPathMultiplicity(prefix.joinWith((0,_Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.createFromMask)(this.removeAttributePrefix(formula.target), false, _Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.PathTokens.each)).normalize());
75370
75374
  const dependencies = [];
75371
- const compiledExpression = this.compileExpression(prefix, target, formula.expression, dependencies);
75375
+ const compiledExpression = this.compileExpressionWithUnsupportedHandled(prefix, target, formula.expression, dependencies);
75376
+ if (compiledExpression instanceof _Common_Errors__WEBPACK_IMPORTED_MODULE_3__.NotSupportedError) {
75377
+ if (options.skipNotSupportedFunction) {
75378
+ return undefined;
75379
+ } else {
75380
+ throw compiledExpression;
75381
+ }
75382
+ }
75372
75383
  const defaultValue = this.dataDeclarationHelper.getDefaultValue(target.toLegacyPath());
75373
75384
  const autoField = this.dataDeclarationHelper.isNodeHasAutoFlagEntry(target.toLegacyPath());
75374
75385
  const disabled = this.dataDeclarationHelper.isNodeHasDisabledEntry(target.toLegacyPath());
@@ -79272,6 +79283,16 @@ class KCXmlGeneratorBase {
79272
79283
  });
79273
79284
  return [...sumCompiledFunctions];
79274
79285
  }
79286
+ compileExpressionWithUnsupportedHandled(prefix, targetFullPath, expression, deps) {
79287
+ try {
79288
+ return this.compileExpression(prefix, targetFullPath, expression, deps);
79289
+ } catch (e) {
79290
+ if (e instanceof _Common_Errors__WEBPACK_IMPORTED_MODULE_5__.NotSupportedError) {
79291
+ return e;
79292
+ }
79293
+ throw e;
79294
+ }
79295
+ }
79275
79296
 
79276
79297
  /* eslint-disable @typescript-eslint/unbound-method */
79277
79298
  compileExpression(prefix, targetFullPath, expression, deps) {
@@ -79535,7 +79556,7 @@ class KCXmlGeneratorBase {
79535
79556
  }
79536
79557
  // -----
79537
79558
 
79538
- throw new Error(`Unsupported node type: ${expression.constructor.name}`);
79559
+ throw new _Common_Errors__WEBPACK_IMPORTED_MODULE_5__.NotSupportedError(`Unsupported node type: ${expression.constructor.name}`);
79539
79560
  }
79540
79561
  /* eslint-enable @typescript-eslint/unbound-method */
79541
79562
 
@@ -79611,6 +79632,10 @@ __webpack_require__.r(__webpack_exports__);
79611
79632
  /* harmony import */ var _KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../KCXmlGenerator/KCXmlGeneratorBase */ "./Generator/src/generators/KCXmlGenerator/KCXmlGeneratorBase.ts");
79612
79633
  /* harmony import */ var _Common_IterableUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../../Common/IterableUtils */ "./Common/IterableUtils.ts");
79613
79634
  /* harmony import */ var _AutoCalculationsGenerator_AutoCalculationsFromFormulas_KCXmlContract_FormulaParsingDescription__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaParsingDescription */ "./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaParsingDescription.ts");
79635
+ /* harmony import */ var _Common_Errors__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../../../Common/Errors */ "./Common/Errors.ts");
79636
+ /* harmony import */ var _Common_TypingUtils__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../../../Common/TypingUtils */ "./Common/TypingUtils.ts");
79637
+
79638
+
79614
79639
 
79615
79640
 
79616
79641
 
@@ -79620,8 +79645,8 @@ const emptyResult = `
79620
79645
  export default function kcXmlValidationConfigurator ({ form, ModelPath, ValidationFunction, KCCondition }) {}
79621
79646
  `;
79622
79647
  class KCXmlValidationGenerator extends _KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_2__.KCXmlGeneratorBase {
79623
- generate(kcXmlConditions) {
79624
- const compiledConditions = Iterator.from(kcXmlConditions).map(condition => this.compileCondition(condition)).toArray();
79648
+ generate(kcXmlConditions, options) {
79649
+ const compiledConditions = Iterator.from(kcXmlConditions).map(condition => this.compileCondition(condition, options)).filter(_Common_TypingUtils__WEBPACK_IMPORTED_MODULE_6__.isNotNullOrUndefined).toArray();
79625
79650
  if (compiledConditions.length === 0) {
79626
79651
  // NOTE Просто, чтоб не падали аппрувал тесты
79627
79652
  return emptyResult;
@@ -79632,12 +79657,19 @@ class KCXmlValidationGenerator extends _KCXmlGenerator_KCXmlGeneratorBase__WEBPA
79632
79657
  `;
79633
79658
  return result;
79634
79659
  }
79635
- compileCondition(condition) {
79660
+ compileCondition(condition, options) {
79636
79661
  var _condition$descriptio, _condition$errorLevel;
79637
79662
  const prefix = (0,_Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.createFromMask)(this.removeMultiplicity(this.removeAttributePrefix(condition.match)), true, _Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.PathTokens.each).toAbsolute();
79638
79663
  const target = this.schema.adjustPathMultiplicity(prefix.joinWith((0,_Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.createFromMask)(this.removeMultiplicity(this.removeAttributePrefix(condition.target)), false, _Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.PathTokens.each)).normalize());
79639
79664
  const deps = [];
79640
- const compiledExpression = this.compileExpression(prefix, target, condition.expression, deps);
79665
+ const compiledExpression = this.compileExpressionWithUnsupportedHandled(prefix, target, condition.expression, deps);
79666
+ if (compiledExpression instanceof _Common_Errors__WEBPACK_IMPORTED_MODULE_5__.NotSupportedError) {
79667
+ if (options.skipNotSupportedFunction) {
79668
+ return undefined;
79669
+ } else {
79670
+ throw compiledExpression;
79671
+ }
79672
+ }
79641
79673
  const compiledDescriptionParts = (0,_AutoCalculationsGenerator_AutoCalculationsFromFormulas_KCXmlContract_FormulaParsingDescription__WEBPACK_IMPORTED_MODULE_4__.splitConditionDescriptionToParts)((_condition$descriptio = condition.description) !== null && _condition$descriptio !== void 0 ? _condition$descriptio : "Error Message");
79642
79674
  let concatDescription;
79643
79675
  if (compiledDescriptionParts.length > 1) {
@@ -79925,7 +79957,7 @@ function processSugar(formSugarContent, additionalContent, generationOptions) {
79925
79957
  const formulasFromSugar = extractFormulasFromSugarKCLang(sugarRoot);
79926
79958
  const formulas = ((_kxXmlMathContainer$f = kxXmlMathContainer === null || kxXmlMathContainer === void 0 ? void 0 : (_kxXmlMathContainer$f2 = kxXmlMathContainer.formulas) === null || _kxXmlMathContainer$f2 === void 0 ? void 0 : _kxXmlMathContainer$f2.items) !== null && _kxXmlMathContainer$f !== void 0 ? _kxXmlMathContainer$f : []).concat((_kcLangMathContainer$ = kcLangMathContainer === null || kcLangMathContainer === void 0 ? void 0 : (_kcLangMathContainer$2 = kcLangMathContainer.formulas) === null || _kcLangMathContainer$2 === void 0 ? void 0 : _kcLangMathContainer$2.items) !== null && _kcLangMathContainer$ !== void 0 ? _kcLangMathContainer$ : []).concat([...formulasFromSugar]);
79927
79959
  const useServerCalculations = (_additionalContent$fo = (_additionalContent$fo2 = additionalContent.formJsonSettings) === null || _additionalContent$fo2 === void 0 ? void 0 : _additionalContent$fo2.useServerSideCalculations) !== null && _additionalContent$fo !== void 0 ? _additionalContent$fo : false;
79928
- const useCalculator2 = !useServerCalculations && (((_additionalContent$fo3 = additionalContent.formJsonSettings) === null || _additionalContent$fo3 === void 0 ? void 0 : _additionalContent$fo3.autoCalculationCalculatorImpl) === "calculator2" || ((_additionalContent$fo4 = additionalContent.formJsonSettings) === null || _additionalContent$fo4 === void 0 ? void 0 : _additionalContent$fo4.useServerSideFLangNormalization));
79960
+ const useCalculator2 = ((_additionalContent$fo3 = additionalContent.formJsonSettings) === null || _additionalContent$fo3 === void 0 ? void 0 : _additionalContent$fo3.autoCalculationCalculatorImpl) === "calculator2" || ((_additionalContent$fo4 = additionalContent.formJsonSettings) === null || _additionalContent$fo4 === void 0 ? void 0 : _additionalContent$fo4.useServerSideFLangNormalization);
79929
79961
  const useOldCalculator = !useCalculator2 && !useServerCalculations;
79930
79962
  const kcXmlConditions = (_Iterator$from$map$fl = Iterator.from(getImportedKcXmlValidations(sugarRoot, additionalContent)).map(x => {
79931
79963
  var _container$conditions, _container$conditions2;
@@ -80015,10 +80047,14 @@ function processSugar(formSugarContent, additionalContent, generationOptions) {
80015
80047
  builder.addResource("rngSchemaValidationConfigurator.js", rngSchemaValidationConfigurator);
80016
80048
  const formulasForCalculator2 = useCalculator2 ? formulas : [];
80017
80049
  const kcXmlAutoCalcGenerator = new _AutoCalculationsGenerator_AutoCalculationsFromFormulas_Calculator2_AutoCalculationsCalculator2Generator__WEBPACK_IMPORTED_MODULE_28__.AutoCalculationsCalculator2Generator(formSchemaRng, dataDeclarationHelper);
80018
- builder.addResource("kcXmlAutoCalculationConfigurator.js", kcXmlAutoCalcGenerator.generate(formulasForCalculator2));
80050
+ builder.addResource("kcXmlAutoCalculationConfigurator.js", kcXmlAutoCalcGenerator.generate(formulasForCalculator2, {
80051
+ skipNotSupportedFunction: useServerCalculations
80052
+ }));
80019
80053
  const kcXmlValidationGenerator = new _KCXmlValidationGenerator_KCXmlValidationGenerator__WEBPACK_IMPORTED_MODULE_23__.KCXmlValidationGenerator(formSchemaRng);
80020
- const kcXmlConditionsForCalculator2 = !useServerCalculations ? kcXmlConditions : [];
80021
- builder.addResource("kcXmlValidationConfigurator.js", kcXmlValidationGenerator.generate(kcXmlConditionsForCalculator2));
80054
+ const kcXmlConditionsForCalculator2 = kcXmlConditions;
80055
+ builder.addResource("kcXmlValidationConfigurator.js", kcXmlValidationGenerator.generate(kcXmlConditionsForCalculator2, {
80056
+ skipNotSupportedFunction: useServerCalculations
80057
+ }));
80022
80058
  // const importedAutoCalculations = getImportedAutoCalculations(sugarRoot);
80023
80059
  builder.addResource("autocalculationConfigurators.js", `export default []`);
80024
80060
  builder.addResource("FakeStyles.less", `// empty styles to enforce style files`);
@@ -80069,14 +80105,6 @@ function mergeFetchFunctionRegistries(registries) {
80069
80105
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
80070
80106
  return Object.assign({}, ...registries);
80071
80107
  }
80072
-
80073
- // function getImportedAutoCalculations(formNode: FormNode): string[] {
80074
- // if (formNode.imports != undefined) {
80075
- // return formNode.imports.autocalculations.map(x => x.from);
80076
- // }
80077
- // return [];
80078
- // }
80079
-
80080
80108
  const kclangExtensionRegex = /\.kclang$/;
80081
80109
  function getKcXmlByKclangOrKcXml(fileName, content) {
80082
80110
  return kclangExtensionRegex.test(fileName) ? _common_KCLang_KCLangToXmlTranspiler__WEBPACK_IMPORTED_MODULE_6__.KCLangToXmlTranspiler.transpile(content) : content;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontur.candy/generator",
3
- "version": "5.26.0-fs8433.0",
3
+ "version": "5.26.0",
4
4
  "description": "Candy forms generator",
5
5
  "author": "SKBKontur Candy Team",
6
6
  "private": false,