@sapui5/sap.fe.base 1.128.0 → 1.129.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.
@@ -101,6 +101,7 @@ type ComplexTypeExpression<T> = BaseExpression<T> & {
101
101
  _type: "ComplexType";
102
102
  type: string;
103
103
  formatOptions: FormatOptions;
104
+ constraints: object;
104
105
  parameters: object;
105
106
  bindingParameters: BindingToolkitExpression<unknown>[];
106
107
  };
@@ -174,7 +175,6 @@ export function isProperty(serviceObject: unknown): serviceObject is Property {
174
175
 
175
176
  /**
176
177
  * An expression that evaluates to type T.
177
- *
178
178
  * @typedef BindingToolkitExpression
179
179
  */
180
180
  export type BindingToolkitExpression<T> =
@@ -275,7 +275,6 @@ export function hasUnresolvableExpression(...expressions: BindingToolkitExpressi
275
275
  }
276
276
  /**
277
277
  * Check two expressions for (deep) equality.
278
- *
279
278
  * @param a
280
279
  * @param b
281
280
  * @returns `true` if the two expressions are equal
@@ -375,7 +374,6 @@ export function _checkExpressionsAreEqual<T>(a: BindingToolkitExpression<T>, b:
375
374
 
376
375
  /**
377
376
  * Converts a nested SetExpression by inlining operands of type SetExpression with the same operator.
378
- *
379
377
  * @param expression The expression to flatten
380
378
  * @returns A new SetExpression with the same operator
381
379
  */
@@ -397,7 +395,6 @@ function flattenSetExpression(expression: SetExpression): SetExpression {
397
395
 
398
396
  /**
399
397
  * Detects whether an array of boolean expressions contains an expression and its negation.
400
- *
401
398
  * @param expressions Array of expressions
402
399
  * @returns `true` if the set of expressions contains an expression and its negation
403
400
  */
@@ -418,7 +415,6 @@ function hasOppositeExpressions(expressions: BindingToolkitExpression<boolean>[]
418
415
  *
419
416
  * The expression is simplified to false if this can be decided statically (that is, if one operand is a constant
420
417
  * false or if the expression contains an operand and its negation).
421
- *
422
418
  * @param operands Expressions to connect by `and`
423
419
  * @returns Expression evaluating to boolean
424
420
  */
@@ -463,7 +459,6 @@ export function and(...operands: ExpressionOrPrimitive<boolean>[]): BindingToolk
463
459
  *
464
460
  * The expression is simplified to true if this can be decided statically (that is, if one operand is a constant
465
461
  * true or if the expression contains an operand and its negation).
466
- *
467
462
  * @param operands Expressions to connect by `or`
468
463
  * @returns Expression evaluating to boolean
469
464
  */
@@ -504,7 +499,6 @@ export function or(...operands: ExpressionOrPrimitive<boolean>[]): BindingToolki
504
499
 
505
500
  /**
506
501
  * Logical `not` operator.
507
- *
508
502
  * @param operand The expression to reverse
509
503
  * @returns The resulting expression that evaluates to boolean
510
504
  */
@@ -556,7 +550,6 @@ export function not(operand: ExpressionOrPrimitive<boolean>): BindingToolkitExpr
556
550
 
557
551
  /**
558
552
  * Evaluates whether a binding expression is equal to true with a loose equality.
559
- *
560
553
  * @param operand The expression to check
561
554
  * @returns The resulting expression that evaluates to boolean
562
555
  */
@@ -573,7 +566,6 @@ export function isTruthy(operand: BindingToolkitExpression<string>): BindingTool
573
566
 
574
567
  /**
575
568
  * Creates a binding expression that will be evaluated by the corresponding model.
576
- *
577
569
  * @param path
578
570
  * @param modelName
579
571
  * @param visitedNavigationPaths
@@ -592,7 +584,6 @@ export function bindingExpression<TargetType extends PrimitiveType>(
592
584
 
593
585
  /**
594
586
  * Creates a binding expression that will be evaluated by the corresponding model.
595
- *
596
587
  * @template TargetType
597
588
  * @param path The path on the model
598
589
  * @param [modelName] The name of the model
@@ -649,7 +640,6 @@ type PlainExpressionObject = { [index: string]: BindingToolkitExpression<unknown
649
640
 
650
641
  /**
651
642
  * Creates a constant expression based on a primitive value.
652
- *
653
643
  * @template T
654
644
  * @param value The constant to wrap in an expression
655
645
  * @returns The constant expression
@@ -711,7 +701,6 @@ export function resolveBindingString<T extends PrimitiveType>(
711
701
 
712
702
  /**
713
703
  * A named reference.
714
- *
715
704
  * @see fn
716
705
  * @param reference Reference
717
706
  * @returns The object reference binding part
@@ -722,7 +711,6 @@ export function ref(reference: string | null): ReferenceExpression {
722
711
 
723
712
  /**
724
713
  * Wrap a primitive into a constant expression if it is not already an expression.
725
- *
726
714
  * @template T
727
715
  * @param something The object to wrap in a Constant expression
728
716
  * @returns Either the original object or the wrapped one depending on the case
@@ -740,7 +728,6 @@ export function wrapPrimitive<T extends PrimitiveType>(something: ExpressionOrPr
740
728
  *
741
729
  * Every object having a property named `_type` of some value is considered an expression, even if there is actually
742
730
  * no such expression type supported.
743
- *
744
731
  * @param expression
745
732
  * @returns `true` if the expression is a binding toolkit expression
746
733
  */
@@ -752,7 +739,6 @@ export function isBindingToolkitExpression(
752
739
 
753
740
  /**
754
741
  * Checks if the expression or value provided is constant or not.
755
- *
756
742
  * @template T The target type
757
743
  * @param maybeConstant The expression or primitive value that is to be checked
758
744
  * @returns `true` if it is constant
@@ -771,7 +757,6 @@ function isFalse(expression: BindingToolkitExpression<PrimitiveType>): boolean {
771
757
 
772
758
  /**
773
759
  * Checks if the expression or value provided is a path in model expression or not.
774
- *
775
760
  * @template T The target type
776
761
  * @param maybeBinding The expression or primitive value that is to be checked
777
762
  * @returns `true` if it is a path in model expression
@@ -784,7 +769,6 @@ export function isPathInModelExpression<T extends PrimitiveType>(
784
769
 
785
770
  /**
786
771
  * Checks if the expression or value provided is a complex type expression.
787
- *
788
772
  * @template T The target type
789
773
  * @param maybeBinding The expression or primitive value that is to be checked
790
774
  * @returns `true` if it is a path in model expression
@@ -797,7 +781,6 @@ export function isComplexTypeExpression<T extends PrimitiveType>(
797
781
 
798
782
  /**
799
783
  * Checks if the expression or value provided is a concat expression or not.
800
- *
801
784
  * @param expression
802
785
  * @returns `true` if the expression is a ConcatExpression
803
786
  */
@@ -807,7 +790,6 @@ function isConcatExpression(expression: BindingToolkitExpression<PrimitiveType>)
807
790
 
808
791
  /**
809
792
  * Checks if the expression or value provided is a IfElse expression or not.
810
- *
811
793
  * @param expression
812
794
  * @returns `true` if the expression is a IfElseExpression
813
795
  */
@@ -817,7 +799,6 @@ function isIfElseExpression(expression: BindingToolkitExpression<PrimitiveType>)
817
799
 
818
800
  /**
819
801
  * Checks if the expression provided is a comparison or not.
820
- *
821
802
  * @template T The target type
822
803
  * @param expression The expression
823
804
  * @returns `true` if the expression is a ComparisonExpression
@@ -828,7 +809,6 @@ function isComparison<T extends PrimitiveType>(expression: BindingToolkitExpress
828
809
 
829
810
  /**
830
811
  * Checks whether the input parameter is a constant expression of type undefined.
831
- *
832
812
  * @param expression The input expression or object in general
833
813
  * @returns `true` if the input is constant which has undefined for value
834
814
  */
@@ -863,7 +843,6 @@ function isPrimitiveObject(objectType: object): boolean {
863
843
  }
864
844
  /**
865
845
  * Check if the passed annotation annotationValue is a ComplexAnnotationExpression.
866
- *
867
846
  * @template T The target type
868
847
  * @param annotationValue The annotation annotationValue to evaluate
869
848
  * @returns `true` if the object is a {ComplexAnnotationExpression}
@@ -874,7 +853,6 @@ function isComplexAnnotationExpression<T>(annotationValue: PropertyAnnotationVal
874
853
 
875
854
  /**
876
855
  * Generate the corresponding annotationValue for a given annotation annotationValue.
877
- *
878
856
  * @template T The target type
879
857
  * @param annotationValue The source annotation annotationValue
880
858
  * @param visitedNavigationPaths The path from the root entity set
@@ -961,7 +939,6 @@ export function getExpressionFromAnnotation<T extends PrimitiveType>(
961
939
 
962
940
  /**
963
941
  * Parse the annotation condition into an expression.
964
- *
965
942
  * @template T The target type
966
943
  * @param annotationValue The condition or value from the annotation
967
944
  * @param visitedNavigationPaths The path from the root entity set
@@ -1052,7 +1029,6 @@ function parseAnnotationCondition<T extends PrimitiveType>(
1052
1029
 
1053
1030
  /**
1054
1031
  * Process the {IfAnnotationExpressionValue} into an expression.
1055
- *
1056
1032
  * @template T The target type
1057
1033
  * @param annotationValue An If expression returning the type T
1058
1034
  * @param visitedNavigationPaths The path from the root entity set
@@ -1144,7 +1120,6 @@ export function annotationApplyExpression(
1144
1120
 
1145
1121
  /**
1146
1122
  * Generic helper for the comparison operations (equal, notEqual, ...).
1147
- *
1148
1123
  * @template T The target type
1149
1124
  * @param operator The operator to apply
1150
1125
  * @param leftOperand The operand on the left side of the operator
@@ -1220,7 +1195,6 @@ function comparison<T extends PrimitiveType>(
1220
1195
 
1221
1196
  /**
1222
1197
  * Generic helper for the length of an expression.
1223
- *
1224
1198
  * @param expression The input expression pointing to an array
1225
1199
  * @param checkUndefined Is the array potentially undefined
1226
1200
  * @returns An expression representing the length
@@ -1243,7 +1217,6 @@ export function length(
1243
1217
 
1244
1218
  /**
1245
1219
  * Comparison: "equal" (===).
1246
- *
1247
1220
  * @template T The target type
1248
1221
  * @param leftOperand The operand on the left side
1249
1222
  * @param rightOperand The operand on the right side of the comparison
@@ -1295,7 +1268,6 @@ export function equal<T extends PrimitiveType>(
1295
1268
 
1296
1269
  /**
1297
1270
  * Comparison: "not equal" (!==).
1298
- *
1299
1271
  * @template T The target type
1300
1272
  * @param leftOperand The operand on the left side
1301
1273
  * @param rightOperand The operand on the right side of the comparison
@@ -1310,7 +1282,6 @@ export function notEqual<T extends PrimitiveType>(
1310
1282
 
1311
1283
  /**
1312
1284
  * Comparison: "greater or equal" (>=).
1313
- *
1314
1285
  * @template T The target type
1315
1286
  * @param leftOperand The operand on the left side
1316
1287
  * @param rightOperand The operand on the right side of the comparison
@@ -1325,7 +1296,6 @@ export function greaterOrEqual<T extends DefinedPrimitiveType>(
1325
1296
 
1326
1297
  /**
1327
1298
  * Comparison: "greater than" (>).
1328
- *
1329
1299
  * @template T The target type
1330
1300
  * @param leftOperand The operand on the left side
1331
1301
  * @param rightOperand The operand on the right side of the comparison
@@ -1340,7 +1310,6 @@ export function greaterThan<T extends DefinedPrimitiveType>(
1340
1310
 
1341
1311
  /**
1342
1312
  * Comparison: "less or equal" (<=).
1343
- *
1344
1313
  * @template T The target type
1345
1314
  * @param leftOperand The operand on the left side
1346
1315
  * @param rightOperand The operand on the right side of the comparison
@@ -1355,7 +1324,6 @@ export function lessOrEqual<T extends DefinedPrimitiveType>(
1355
1324
 
1356
1325
  /**
1357
1326
  * Comparison: "less than" (<).
1358
- *
1359
1327
  * @template T The target type
1360
1328
  * @param leftOperand The operand on the left side
1361
1329
  * @param rightOperand The operand on the right side of the comparison
@@ -1372,7 +1340,6 @@ export function lessThan<T extends DefinedPrimitiveType>(
1372
1340
  * If-then-else expression.
1373
1341
  *
1374
1342
  * Evaluates to onTrue if the condition evaluates to true, else evaluates to onFalse.
1375
- *
1376
1343
  * @template T The target type
1377
1344
  * @param condition The condition to evaluate
1378
1345
  * @param onTrue Expression result if the condition evaluates to true
@@ -1470,7 +1437,6 @@ export function ifElse<T extends PrimitiveType>(
1470
1437
 
1471
1438
  /**
1472
1439
  * Checks whether the current expression has a reference to the default model (undefined).
1473
- *
1474
1440
  * @param expression The expression to evaluate
1475
1441
  * @returns `true` if there is a reference to the default context
1476
1442
  */
@@ -1528,7 +1494,6 @@ type FunctionParameters<T, F extends FunctionOrName<T>> = F extends Fn<T> ? Para
1528
1494
  /**
1529
1495
  * Calls a formatter function to process the parameters.
1530
1496
  * If requireContext is set to true and no context is passed a default context will be added automatically.
1531
- *
1532
1497
  * @template T
1533
1498
  * @template U
1534
1499
  * @param parameters The list of parameter that should match the type and number of the formatter function
@@ -1640,7 +1605,6 @@ export function setUpConstraints(targetMapping: TypeMappingDefinition, property:
1640
1605
 
1641
1606
  /**
1642
1607
  * Generates the binding expression for the property, and sets up the formatOptions and constraints.
1643
- *
1644
1608
  * @param property The Property for which we are setting up the binding
1645
1609
  * @param propertyBindingExpression The BindingExpression of the property above. Serves as the basis to which information can be added
1646
1610
  * @param ignoreConstraints Ignore constraints of the property
@@ -1678,7 +1642,7 @@ export function formatWithTypeInformation<T>(
1678
1642
  });
1679
1643
  }
1680
1644
  if (outExpression.type === "sap.ui.model.odata.type.String" && isProperty(property)) {
1681
- if (outExpression.constraints?.isDigitSequence || outExpression.constraints?.nullable !== false) {
1645
+ if (outExpression.constraints?.isDigitSequence || (outExpression.constraints?.nullable !== false && property.nullable === true)) {
1682
1646
  outExpression.formatOptions.parseKeepsEmptyString = false;
1683
1647
  } else {
1684
1648
  outExpression.formatOptions.parseKeepsEmptyString = true;
@@ -1750,20 +1714,21 @@ export const getFiscalType = function (property: Property): string | undefined {
1750
1714
  /**
1751
1715
  * Calls a complex type to process the parameters.
1752
1716
  * If requireContext is set to true and no context is passed, a default context will be added automatically.
1753
- *
1754
1717
  * @template T
1755
1718
  * @template U
1756
1719
  * @param parameters The list of parameters that should match the type for the complex type=
1757
1720
  * @param type The complex type to use
1758
1721
  * @param [contextEntityType] The context entity type to consider
1759
1722
  * @param oFormatOptions
1723
+ * @param oConstraintOptions
1760
1724
  * @returns The corresponding expression
1761
1725
  */
1762
1726
  export function addTypeInformation<T, U extends Fn<T>>(
1763
1727
  parameters: WrappedTuple<Parameters<U>>,
1764
1728
  type: string,
1765
1729
  contextEntityType?: EntityType,
1766
- oFormatOptions?: ComplexTypeFormatOptions
1730
+ oFormatOptions?: ComplexTypeFormatOptions,
1731
+ oConstraintOptions?: ComplexTypeConstraintOptions
1767
1732
  ): UnresolvablePathExpression | ComplexTypeExpression<T> | ConstantExpression<T> {
1768
1733
  const parameterExpressions = (parameters as ExpressionOrPrimitive<PrimitiveType>[]).map(wrapPrimitive);
1769
1734
  if (hasUnresolvableExpression(...parameterExpressions)) {
@@ -1796,6 +1761,7 @@ export function addTypeInformation<T, U extends Fn<T>>(
1796
1761
  _type: "ComplexType",
1797
1762
  type: type,
1798
1763
  formatOptions: oFormatOptions || {},
1764
+ constraints: oConstraintOptions || {},
1799
1765
  parameters: {},
1800
1766
  bindingParameters: parameterExpressions
1801
1767
  };
@@ -1812,9 +1778,12 @@ type ComplexTypeFormatOptions = {
1812
1778
  showTimezone?: boolean;
1813
1779
  };
1814
1780
 
1781
+ export type ComplexTypeConstraintOptions = {
1782
+ skipDecimalsValidation?: boolean;
1783
+ };
1784
+
1815
1785
  /**
1816
1786
  * Process the formatOptions for a complexType based on the first parameter.
1817
- *
1818
1787
  * @param param The first parameter of the complex type
1819
1788
  * @param formatOptions Initial formatOptions
1820
1789
  * @returns The modified formatOptions
@@ -1837,13 +1806,16 @@ function _getComplexTypeFormatOptionsFromFirstParam<T, U extends Fn<T>>(
1837
1806
  } else {
1838
1807
  formatOptions = formatOptions?.showMeasure === false ? { parseAsString: false, showMeasure: false } : { parseAsString: false };
1839
1808
  }
1840
- formatOptions.emptyString = null;
1809
+ if (param?.constraints?.nullable !== false) {
1810
+ formatOptions.emptyString = null;
1811
+ } else {
1812
+ formatOptions.emptyString = "";
1813
+ }
1841
1814
  }
1842
1815
  return formatOptions;
1843
1816
  }
1844
1817
  /**
1845
1818
  * Function call, optionally with arguments.
1846
- *
1847
1819
  * @param func Function name or reference to function
1848
1820
  * @param parameters Arguments
1849
1821
  * @param on Object to call the function on
@@ -1868,7 +1840,6 @@ export function fn<T, U extends FunctionOrName<T>>(
1868
1840
 
1869
1841
  /**
1870
1842
  * Shortcut function to determine if a binding value is null, undefined or empty.
1871
- *
1872
1843
  * @param expression
1873
1844
  * @returns A Boolean expression evaluating the fact that the current element is empty
1874
1845
  */
@@ -2075,7 +2046,6 @@ const needParenthesis = function <T extends PrimitiveType>(expr: ExpressionOrPri
2075
2046
 
2076
2047
  /**
2077
2048
  * Compiles a constant object to a string.
2078
- *
2079
2049
  * @param expr
2080
2050
  * @param isNullable
2081
2051
  * @returns The compiled string
@@ -2098,7 +2068,6 @@ function compileConstantObject(expr: ConstantExpression<object>, isNullable = fa
2098
2068
 
2099
2069
  /**
2100
2070
  * Compiles a Constant Binding Expression.
2101
- *
2102
2071
  * @param expr
2103
2072
  * @param embeddedInBinding
2104
2073
  * @param isNullable
@@ -2156,7 +2125,6 @@ export function compileConstant<T extends PrimitiveType>(
2156
2125
 
2157
2126
  /**
2158
2127
  * Generates the binding string for a Binding expression.
2159
- *
2160
2128
  * @param expressionForBinding The expression to compile
2161
2129
  * @param embeddedInBinding Whether the expression to compile is embedded into another expression
2162
2130
  * @param embeddedSeparator The binding value evaluator ($ or % depending on whether we want to force the type or not)
@@ -2207,6 +2175,9 @@ function compileComplexTypeExpression<T extends PrimitiveType>(expression: Compl
2207
2175
  if (hasElements(expression.formatOptions)) {
2208
2176
  outputEnd += `, formatOptions: ${compileExpression(expression.formatOptions)}`;
2209
2177
  }
2178
+ if (hasElements(expression.constraints)) {
2179
+ outputEnd += `, constraints: ${compileExpression(expression.constraints)}`;
2180
+ }
2210
2181
  if (hasElements(expression.parameters)) {
2211
2182
  outputEnd += `, parameters: ${compileExpression(expression.parameters)}`;
2212
2183
  }
@@ -2219,7 +2190,6 @@ function compileComplexTypeExpression<T extends PrimitiveType>(expression: Compl
2219
2190
 
2220
2191
  /**
2221
2192
  * Wrap the compiled binding string as required depending on its context.
2222
- *
2223
2193
  * @param expression The compiled expression
2224
2194
  * @param embeddedInBinding True if the compiled expression is to be embedded in a binding
2225
2195
  * @param parenthesisRequired True if the embedded binding needs to be wrapped in parethesis so that it is evaluated as one
@@ -2243,7 +2213,6 @@ export function wrapBindingExpression(
2243
2213
 
2244
2214
  /**
2245
2215
  * Compile an expression into an expression binding.
2246
- *
2247
2216
  * @template T The target type
2248
2217
  * @param expression The expression to compile
2249
2218
  * @param embeddedInBinding Whether the expression to compile is embedded into another expression
@@ -2368,7 +2337,6 @@ export function compileExpression<T extends PrimitiveType>(
2368
2337
 
2369
2338
  /**
2370
2339
  * Compile a comparison expression.
2371
- *
2372
2340
  * @param expression The comparison expression.
2373
2341
  * @returns The compiled expression. Needs wrapping before it can be used as an expression binding.
2374
2342
  */
@@ -2383,7 +2351,6 @@ function compileComparisonExpression(expression: ComparisonExpression): string {
2383
2351
 
2384
2352
  /**
2385
2353
  * Compile a formatter expression.
2386
- *
2387
2354
  * @param expression The formatter expression.
2388
2355
  * @returns The compiled expression.
2389
2356
  */
@@ -2406,7 +2373,6 @@ function compileFormatterExpression<T extends PrimitiveType>(expression: Formatt
2406
2373
 
2407
2374
  /**
2408
2375
  * Compile the path parameter of a formatter call.
2409
- *
2410
2376
  * @param expression The binding part to evaluate
2411
2377
  * @param singlePath Whether there is one or multiple path to consider
2412
2378
  * @returns The string snippet to include in the overall binding definition
@@ -2448,7 +2414,6 @@ function hasElements(obj: object | undefined): boolean {
2448
2414
 
2449
2415
  /**
2450
2416
  * Compile a binding expression path.
2451
- *
2452
2417
  * @param expression The expression to compile.
2453
2418
  * @returns The compiled path.
2454
2419
  */