@kontur.candy/generator 5.21.0 → 5.22.0-descriptionvalidations.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 (2) hide show
  1. package/dist/index.js +106 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -77223,6 +77223,51 @@ const formulaExpressions = [FormulaSumExpression, FormulaArgumentExpression, For
77223
77223
 
77224
77224
  /***/ }),
77225
77225
 
77226
+ /***/ "./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaParsingDescription.ts":
77227
+ /*!************************************************************************************************************************************!*\
77228
+ !*** ./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaParsingDescription.ts ***!
77229
+ \************************************************************************************************************************************/
77230
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
77231
+
77232
+ "use strict";
77233
+ __webpack_require__.r(__webpack_exports__);
77234
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
77235
+ /* harmony export */ "splitConditionDescriptionToParts": () => (/* binding */ splitConditionDescriptionToParts)
77236
+ /* harmony export */ });
77237
+ /* harmony import */ var _Formula__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Formula */ "./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/Formula.ts");
77238
+
77239
+ function splitConditionDescriptionToParts(description) {
77240
+ const reg = new RegExp(/\('|'\)/g);
77241
+ const words = description.split(reg);
77242
+ const splitWords = words.map(item => {
77243
+ if (item.includes("{")) {
77244
+ const word = item.substring(1, item.length - 1);
77245
+ const argument = new _Formula__WEBPACK_IMPORTED_MODULE_0__.FormulaArgumentExpression();
77246
+ argument.select = word;
77247
+ argument.type = "string";
77248
+ return argument;
77249
+ } else {
77250
+ return item;
77251
+ }
77252
+ });
77253
+ const wordsInFormulas = splitWords.map(part => {
77254
+ if (part instanceof _Formula__WEBPACK_IMPORTED_MODULE_0__.FormulaArgumentExpression) {
77255
+ const formulaPart = new _Formula__WEBPACK_IMPORTED_MODULE_0__.FormulaArgumentExpression();
77256
+ formulaPart.select = part.select;
77257
+ formulaPart.type = "string";
77258
+ return formulaPart;
77259
+ } else {
77260
+ const stringPart = new _Formula__WEBPACK_IMPORTED_MODULE_0__.FormulaConstExpression();
77261
+ stringPart.type = "string";
77262
+ stringPart.value = part;
77263
+ return stringPart;
77264
+ }
77265
+ });
77266
+ return wordsInFormulas;
77267
+ }
77268
+
77269
+ /***/ }),
77270
+
77226
77271
  /***/ "./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaReader.ts":
77227
77272
  /*!************************************************************************************************************************!*\
77228
77273
  !*** ./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaReader.ts ***!
@@ -79476,15 +79521,19 @@ __webpack_require__.r(__webpack_exports__);
79476
79521
  /* harmony export */ "KCXmlValidationGenerator": () => (/* binding */ KCXmlValidationGenerator)
79477
79522
  /* harmony export */ });
79478
79523
  /* harmony import */ var _Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../../Common/ModelPath/ModelPath */ "./Common/ModelPath/ModelPath.ts");
79479
- /* harmony import */ var _KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../KCXmlGenerator/KCXmlGeneratorBase */ "./Generator/src/generators/KCXmlGenerator/KCXmlGeneratorBase.ts");
79480
- /* harmony import */ var _Common_IterableUtils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../../../../Common/IterableUtils */ "./Common/IterableUtils.ts");
79524
+ /* harmony import */ var _AutoCalculationsGenerator_AutoCalculationsFromFormulas_KCXmlContract_Formula__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/Formula */ "./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/Formula.ts");
79525
+ /* harmony import */ var _KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../KCXmlGenerator/KCXmlGeneratorBase */ "./Generator/src/generators/KCXmlGenerator/KCXmlGeneratorBase.ts");
79526
+ /* harmony import */ var _Common_IterableUtils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../../../../Common/IterableUtils */ "./Common/IterableUtils.ts");
79527
+ /* 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");
79528
+
79529
+
79481
79530
 
79482
79531
 
79483
79532
 
79484
79533
  const emptyResult = `
79485
79534
  export default function kcXmlValidationConfigurator ({ form, ModelPath, ValidationFunction, KCCondition }) {}
79486
79535
  `;
79487
- class KCXmlValidationGenerator extends _KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_1__.KCXmlGeneratorBase {
79536
+ class KCXmlValidationGenerator extends _KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_2__.KCXmlGeneratorBase {
79488
79537
  generate(kcXmlConditions) {
79489
79538
  const compiledConditions = Iterator.from(kcXmlConditions).map(condition => this.compileCondition(condition)).toArray();
79490
79539
  if (compiledConditions.length === 0) {
@@ -79503,15 +79552,23 @@ class KCXmlValidationGenerator extends _KCXmlGenerator_KCXmlGeneratorBase__WEBPA
79503
79552
  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());
79504
79553
  const deps = [];
79505
79554
  const compiledExpression = this.compileExpression(prefix, target, condition.expression, deps);
79555
+ 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");
79556
+ let concatDescription;
79557
+ if (compiledDescriptionParts.length > 1) {
79558
+ concatDescription = new _AutoCalculationsGenerator_AutoCalculationsFromFormulas_KCXmlContract_Formula__WEBPACK_IMPORTED_MODULE_1__.FormulaConcatExpression();
79559
+ concatDescription.arguments = compiledDescriptionParts;
79560
+ } else {
79561
+ concatDescription = compiledDescriptionParts[0];
79562
+ }
79563
+ const compiledDescription = this.compileExpression(prefix, target, concatDescription, deps);
79506
79564
  const compiledTarget = this.modelPathInstance(target);
79507
- const dependencyModelPaths = Array.from(_Common_IterableUtils__WEBPACK_IMPORTED_MODULE_2__.IterUtils.distinctBy(deps.map(x => ({
79565
+ const dependencyModelPaths = Array.from(_Common_IterableUtils__WEBPACK_IMPORTED_MODULE_3__.IterUtils.distinctBy(deps.map(x => ({
79508
79566
  path: x.asDependencyModelPath(),
79509
- isIgnoreForChecks: (0,_KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_1__.isDependencyWithoutChecks)(x),
79567
+ isIgnoreForChecks: (0,_KCXmlGenerator_KCXmlGeneratorBase__WEBPACK_IMPORTED_MODULE_2__.isDependencyWithoutChecks)(x),
79510
79568
  pathString: (0,_Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.createAbsoluteFromTokens)(x.asDependencyModelPath().getPathPartsAsArray().map(token => token === _Common_ModelPath_ModelPath__WEBPACK_IMPORTED_MODULE_0__.PathTokens.current ? "!" : token)).toLegacyPath()
79511
79569
  })).filter(x => !x.path.isEquals(target)), x => x.pathString));
79512
79570
  const compiledDeps = dependencyModelPaths.map(x => x.path).map(x => this.modelPathInstance(x)).join(", ");
79513
- const compiledDescription = (_condition$descriptio = condition.description) !== null && _condition$descriptio !== void 0 ? _condition$descriptio : "Error Message";
79514
- const compiledDelegate = `context => KCCondition.execute(context, expression => ${compiledExpression}, ` + `() => "${compiledDescription}", "${(_condition$errorLevel = condition.errorLevel) !== null && _condition$errorLevel !== void 0 ? _condition$errorLevel : "Error"}")`;
79571
+ const compiledDelegate = `context => KCCondition.execute(context, expression => ${compiledExpression}, ` + `(expression) => ${compiledDescription}, "${(_condition$errorLevel = condition.errorLevel) !== null && _condition$errorLevel !== void 0 ? _condition$errorLevel : "Error"}")`;
79515
79572
  return `new ValidationFunction(${compiledTarget}, [${compiledDeps}], ${compiledDelegate})`;
79516
79573
  }
79517
79574
  }
@@ -80897,6 +80954,7 @@ __webpack_require__.r(__webpack_exports__);
80897
80954
  /* harmony export */ "ReduceCallExpression": () => (/* binding */ ReduceCallExpression),
80898
80955
  /* harmony export */ "ReduceMultipleCallExpression": () => (/* binding */ ReduceMultipleCallExpression),
80899
80956
  /* harmony export */ "CastExpression": () => (/* binding */ CastExpression),
80957
+ /* harmony export */ "JoinExpression": () => (/* binding */ JoinExpression),
80900
80958
  /* harmony export */ "ConstExpression": () => (/* binding */ ConstExpression),
80901
80959
  /* harmony export */ "StringLiteralExpression": () => (/* binding */ StringLiteralExpression),
80902
80960
  /* harmony export */ "DecimalLiteralExpression": () => (/* binding */ DecimalLiteralExpression),
@@ -81441,6 +81499,25 @@ class CastExpression extends FLangExpression {
81441
81499
  return this.targetType;
81442
81500
  }
81443
81501
  }
81502
+ class JoinExpression extends FLangExpression {
81503
+ constructor(expression, separator) {
81504
+ super();
81505
+ this.expression = void 0;
81506
+ this.separator = void 0;
81507
+ this.expression = expression;
81508
+ this.separator = separator;
81509
+ }
81510
+ getType() {
81511
+ return BuildInTypeExpression.string;
81512
+ }
81513
+ *getChildNodes() {
81514
+ yield this.expression;
81515
+ yield this.separator;
81516
+ }
81517
+ convertToString() {
81518
+ return `join(${this.expression.convertToString()}, ${this.separator.convertToString()})`;
81519
+ }
81520
+ }
81444
81521
  class ConstExpression extends FLangExpression {
81445
81522
  getChildNodes() {
81446
81523
  return [];
@@ -83401,8 +83478,10 @@ __webpack_require__.r(__webpack_exports__);
83401
83478
  /* harmony import */ var _Common_ModelPath_EachCurrentCollision__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../../../../../Common/ModelPath/EachCurrentCollision */ "./Common/ModelPath/EachCurrentCollision.ts");
83402
83479
  /* harmony import */ var _DataSchema_DataSchemaUtils__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../../DataSchema/DataSchemaUtils */ "./Generator/src/generators/DataSchema/DataSchemaUtils.ts");
83403
83480
  /* harmony import */ var _FLang_FlangUtils__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../FLang/FlangUtils */ "./Generator/src/generators/ServerSideFLangNormalization/FLang/FlangUtils.ts");
83404
- /* harmony import */ var _NodeTypeInfoHelper__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../NodeTypeInfoHelper */ "./Generator/src/generators/ServerSideFLangNormalization/NodeTypeInfoHelper.ts");
83405
- /* harmony import */ var _Common_ModelPath_AbsoluteModelFieldPath__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../../../../Common/ModelPath/AbsoluteModelFieldPath */ "./Common/ModelPath/AbsoluteModelFieldPath.ts");
83481
+ /* harmony import */ var _AutoCalculationsGenerator_AutoCalculationsFromFormulas_KCXmlContract_FormulaParsingDescription__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaParsingDescription */ "./Generator/src/generators/AutoCalculationsGenerator/AutoCalculationsFromFormulas/KCXmlContract/FormulaParsingDescription.ts");
83482
+ /* harmony import */ var _NodeTypeInfoHelper__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../NodeTypeInfoHelper */ "./Generator/src/generators/ServerSideFLangNormalization/NodeTypeInfoHelper.ts");
83483
+ /* harmony import */ var _Common_ModelPath_AbsoluteModelFieldPath__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ../../../../../Common/ModelPath/AbsoluteModelFieldPath */ "./Common/ModelPath/AbsoluteModelFieldPath.ts");
83484
+
83406
83485
 
83407
83486
 
83408
83487
 
@@ -83441,8 +83520,8 @@ class ValidationRulesBuilder {
83441
83520
  const precalculationRules = [];
83442
83521
  return {
83443
83522
  target: fullTarget,
83444
- checkExpression: this.formulaExprConverter.compileExpressionToFlangExpression(condition.expression, prefix, new _Common_ModelPath_AbsoluteModelFieldPath__WEBPACK_IMPORTED_MODULE_10__.AbsoluteModelFieldPath(fullTarget, condition.errorLevel === "Error" ? "error" : "warning"), x => precalculationRules.push(x)),
83445
- message: condition.description,
83523
+ checkExpression: this.formulaExprConverter.compileExpressionToFlangExpression(condition.expression, prefix, new _Common_ModelPath_AbsoluteModelFieldPath__WEBPACK_IMPORTED_MODULE_11__.AbsoluteModelFieldPath(fullTarget, condition.errorLevel === "Error" ? "error" : "warning"), x => precalculationRules.push(x)),
83524
+ message: (0,_AutoCalculationsGenerator_AutoCalculationsFromFormulas_KCXmlContract_FormulaParsingDescription__WEBPACK_IMPORTED_MODULE_9__.splitConditionDescriptionToParts)(condition.description).map(item => this.formulaExprConverter.compileExpressionToFlangExpression(item, prefix, new _Common_ModelPath_AbsoluteModelFieldPath__WEBPACK_IMPORTED_MODULE_11__.AbsoluteModelFieldPath(fullTarget, condition.errorLevel === "Error" ? "error" : "warning"), x => precalculationRules.push(x))),
83446
83525
  errorLevel: condition.errorLevel,
83447
83526
  precalculationRules: precalculationRules
83448
83527
  };
@@ -83453,8 +83532,8 @@ class ValidationRulesBuilder {
83453
83532
  const path = current.target.toLegacyPath();
83454
83533
  const targetCtx = current.errorLevel === "Warning" ? ctx.warnings : ctx.errors;
83455
83534
  const currentExpression = (_targetCtx$path = targetCtx[path]) !== null && _targetCtx$path !== void 0 ? _targetCtx$path : new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.NullLiteralExpression();
83456
- const condition = new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.ConditionalExpression(new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.NegateUnaryExpression(current.checkExpression), new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.StringLiteralExpression("[" + JSON.stringify(current.message) + "]"), currentExpression);
83457
- targetCtx[path] = condition;
83535
+ const validationRule = this.generateValidationText(currentExpression, current);
83536
+ targetCtx[path] = validationRule;
83458
83537
  return ctx;
83459
83538
  }, {
83460
83539
  errors: {},
@@ -83462,9 +83541,22 @@ class ValidationRulesBuilder {
83462
83541
  });
83463
83542
  return allRulesCheck;
83464
83543
  }
83544
+ generateValidationText(current, next) {
83545
+ const validationText = next.message.reduce((acc, item) => {
83546
+ if (item instanceof _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.StringLiteralExpression) {
83547
+ return new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.ConcatStringsExpression(acc, (0,_FLang_FlangUtils__WEBPACK_IMPORTED_MODULE_8__.castOperandToStringIfNeed)(item));
83548
+ } else if (item instanceof _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.ValueReferenceExpression) {
83549
+ return new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.ConcatStringsExpression(acc, new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.JoinExpression(new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.DeserializeEnumerationExpression([item], new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.BoolLiteralExpression(true)), new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.StringLiteralExpression(", ")));
83550
+ } else {
83551
+ throw new Error(`Invalid WithDescription ${item.toString()}`);
83552
+ }
83553
+ }, new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.StringLiteralExpression(""));
83554
+ const condition = new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.ConditionalExpression(new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.NegateUnaryExpression(next.checkExpression), new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.ConcatStringsExpression(new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.ConcatStringsExpression(new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.StringLiteralExpression(`["`), validationText), new _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.StringLiteralExpression(`"]`)), current);
83555
+ return condition;
83556
+ }
83465
83557
  *buildSugarValidationRules() {
83466
83558
  const converter = new _markupGenerator_ElementProcessors_FormParts_Form_FormConverter__WEBPACK_IMPORTED_MODULE_2__.FormConverter(this.sugarRoot);
83467
- const context = new _FLangValidationBuildContext__WEBPACK_IMPORTED_MODULE_3__.FLangValidationBuildContext(this.formSchemaRng, this.formulaExprConverter, new _NodeTypeInfoHelper__WEBPACK_IMPORTED_MODULE_9__.NodeTypeInfoHelper(this.formSchemaRng, this.typesRegistry, this.useSchemaValidations));
83559
+ const context = new _FLangValidationBuildContext__WEBPACK_IMPORTED_MODULE_3__.FLangValidationBuildContext(this.formSchemaRng, this.formulaExprConverter, new _NodeTypeInfoHelper__WEBPACK_IMPORTED_MODULE_10__.NodeTypeInfoHelper(this.formSchemaRng, this.typesRegistry, this.useSchemaValidations));
83468
83560
  const sugarRules = Iterator.from(converter.buildFLangValidations(context, this.formSchemaRng)).reduce((ctx, current) => {
83469
83561
  const statement = current.statement;
83470
83562
  if (!(statement instanceof _FLang_FLangCodeDom__WEBPACK_IMPORTED_MODULE_1__.SetStatement)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kontur.candy/generator",
3
- "version": "5.21.0",
3
+ "version": "5.22.0-descriptionvalidations.1",
4
4
  "description": "Candy forms generator",
5
5
  "author": "SKBKontur Candy Team",
6
6
  "private": false,