@sap/cds-compiler 4.7.6 → 4.9.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 (129) hide show
  1. package/CHANGELOG.md +63 -3
  2. package/bin/cds_remove_invalid_whitespace.js +135 -0
  3. package/bin/cds_update_annotations.js +180 -0
  4. package/bin/cds_update_identifiers.js +3 -4
  5. package/bin/cdsc.js +28 -1
  6. package/bin/cdshi.js +13 -3
  7. package/doc/CHANGELOG_BETA.md +24 -1
  8. package/lib/api/main.js +119 -46
  9. package/lib/api/options.js +51 -0
  10. package/lib/api/validate.js +1 -5
  11. package/lib/base/builtins.js +116 -0
  12. package/lib/base/keywords.js +5 -1
  13. package/lib/base/location.js +91 -14
  14. package/lib/base/message-registry.js +76 -46
  15. package/lib/base/messages.js +121 -35
  16. package/lib/base/model.js +4 -7
  17. package/lib/checks/actionsFunctions.js +3 -3
  18. package/lib/checks/annotationsOData.js +3 -0
  19. package/lib/checks/defaultValues.js +5 -2
  20. package/lib/checks/elements.js +2 -1
  21. package/lib/checks/enricher.js +2 -2
  22. package/lib/checks/queryNoDbArtifacts.js +5 -3
  23. package/lib/checks/utils.js +1 -1
  24. package/lib/checks/validator.js +8 -56
  25. package/lib/compiler/assert-consistency.js +11 -7
  26. package/lib/compiler/builtins.js +0 -74
  27. package/lib/compiler/checks.js +105 -29
  28. package/lib/compiler/define.js +37 -25
  29. package/lib/compiler/extend.js +35 -12
  30. package/lib/compiler/index.js +9 -10
  31. package/lib/compiler/lsp-api.js +5 -0
  32. package/lib/compiler/populate.js +13 -5
  33. package/lib/compiler/propagator.js +24 -18
  34. package/lib/compiler/resolve.js +47 -45
  35. package/lib/compiler/shared.js +61 -21
  36. package/lib/compiler/tweak-assocs.js +15 -90
  37. package/lib/compiler/utils.js +3 -3
  38. package/lib/compiler/xpr-rewrite.js +689 -0
  39. package/lib/compiler/{classes.js → xsn-model.js} +0 -16
  40. package/lib/edm/annotations/edmJson.js +7 -5
  41. package/lib/edm/annotations/genericTranslation.js +149 -71
  42. package/lib/edm/csn2edm.js +25 -9
  43. package/lib/edm/edm.js +7 -7
  44. package/lib/edm/edmInboundChecks.js +57 -5
  45. package/lib/edm/edmPreprocessor.js +54 -25
  46. package/lib/edm/edmUtils.js +3 -16
  47. package/lib/gen/Dictionary.json +138 -14
  48. package/lib/gen/language.checksum +1 -1
  49. package/lib/gen/language.interp +1 -1
  50. package/lib/gen/languageParser.js +2085 -1989
  51. package/lib/json/csnVersion.js +7 -4
  52. package/lib/json/from-csn.js +21 -11
  53. package/lib/json/to-csn.js +8 -4
  54. package/lib/language/antlrParser.js +1 -1
  55. package/lib/language/genericAntlrParser.js +23 -16
  56. package/lib/language/multiLineStringParser.js +2 -2
  57. package/lib/language/textUtils.js +1 -1
  58. package/lib/main.d.ts +90 -14
  59. package/lib/main.js +9 -1
  60. package/lib/model/cloneCsn.js +21 -9
  61. package/lib/model/csnRefs.js +153 -42
  62. package/lib/model/csnUtils.js +14 -11
  63. package/lib/model/enrichCsn.js +4 -2
  64. package/lib/model/revealInternalProperties.js +2 -1
  65. package/lib/model/sortViews.js +14 -6
  66. package/lib/modelCompare/compare.js +135 -122
  67. package/lib/optionProcessor.js +49 -2
  68. package/lib/render/DuplicateChecker.js +6 -6
  69. package/lib/render/manageConstraints.js +1 -0
  70. package/lib/render/toCdl.js +6 -3
  71. package/lib/render/toHdbcds.js +4 -48
  72. package/lib/render/toSql.js +6 -3
  73. package/lib/transform/addTenantFields.js +58 -35
  74. package/lib/transform/db/applyTransformations.js +34 -1
  75. package/lib/transform/db/constraints.js +1 -1
  76. package/lib/transform/db/expansion.js +11 -3
  77. package/lib/transform/db/flattening.js +71 -46
  78. package/lib/transform/db/groupByOrderBy.js +2 -2
  79. package/lib/transform/db/temporal.js +6 -3
  80. package/lib/transform/db/transformExists.js +2 -2
  81. package/lib/transform/db/views.js +1 -4
  82. package/lib/transform/effective/annotations.js +194 -0
  83. package/lib/transform/effective/main.js +11 -10
  84. package/lib/transform/effective/misc.js +45 -14
  85. package/lib/transform/effective/types.js +4 -3
  86. package/lib/transform/forOdata.js +29 -12
  87. package/lib/transform/forRelationalDB.js +104 -113
  88. package/lib/transform/localized.js +7 -6
  89. package/lib/transform/odata/flattening.js +228 -107
  90. package/lib/transform/odata/toFinalBaseType.js +10 -26
  91. package/lib/transform/odata/typesExposure.js +41 -25
  92. package/lib/transform/parseExpr.js +4 -7
  93. package/lib/transform/transformUtils.js +50 -43
  94. package/lib/transform/translateAssocsToJoins.js +48 -48
  95. package/lib/transform/universalCsn/coreComputed.js +2 -1
  96. package/lib/transform/universalCsn/universalCsnEnricher.js +12 -16
  97. package/package.json +2 -2
  98. package/share/messages/README.md +4 -0
  99. package/share/messages/anno-duplicate-unrelated-layer.md +1 -1
  100. package/share/messages/anno-missing-rewrite.md +45 -0
  101. package/share/messages/check-proper-type-of.md +1 -1
  102. package/share/messages/def-duplicate-autoexposed.md +1 -1
  103. package/share/messages/extend-repeated-intralayer.md +3 -16
  104. package/share/messages/extend-unrelated-layer.md +1 -1
  105. package/share/messages/message-explanations.json +2 -0
  106. package/share/messages/redirected-to-ambiguous.md +1 -1
  107. package/share/messages/redirected-to-complex.md +1 -1
  108. package/share/messages/redirected-to-unrelated.md +1 -1
  109. package/share/messages/rewrite-not-supported.md +1 -1
  110. package/share/messages/syntax-expecting-unsigned-int.md +2 -2
  111. package/share/messages/type-missing-enum-value.md +59 -0
  112. package/share/messages/wildcard-excluding-one.md +1 -1
  113. package/bin/.eslintrc.json +0 -17
  114. package/lib/api/.eslintrc.json +0 -37
  115. package/lib/checks/.eslintrc.json +0 -31
  116. package/lib/compiler/.eslintrc.json +0 -8
  117. package/lib/edm/.eslintrc.json +0 -46
  118. package/lib/inspect/.eslintrc.json +0 -4
  119. package/lib/json/.eslintrc.json +0 -4
  120. package/lib/language/.eslintrc.json +0 -4
  121. package/lib/model/.eslintrc.json +0 -13
  122. package/lib/modelCompare/utils/.eslintrc.json +0 -22
  123. package/lib/render/.eslintrc.json +0 -22
  124. package/lib/transform/.eslintrc.json +0 -13
  125. package/lib/transform/db/.eslintrc.json +0 -41
  126. package/lib/transform/draft/.eslintrc.json +0 -4
  127. package/lib/transform/effective/.eslintrc.json +0 -4
  128. package/lib/transform/universalCsn/.eslintrc.json +0 -37
  129. package/lib/utils/.eslintrc.json +0 -7
@@ -0,0 +1,59 @@
1
+ # type-missing-enum-value
2
+
3
+ An enum definition is missing explicit values for one or more of its entries.
4
+
5
+ Enum definitions that aren't based on string-types do not get implicit values.
6
+ They have therefore to be defined explicitly in the model.
7
+
8
+ The message’s severity is `Warning` and is raised by the compiler. You need
9
+ to adapt your model to fix the warning.
10
+
11
+ ## Example
12
+
13
+ Erroneous code example:
14
+
15
+ ```cds
16
+ entity Books {
17
+ // …
18
+ category: Integer enum {
19
+ Fiction; // ❌
20
+ Action; // ❌
21
+ // …
22
+ } default #Action;
23
+ };
24
+ ```
25
+
26
+ Both entries `#Fiction` and `#Action` of the enum `category` are missing an
27
+ explicit value. Because the base type `Integer` is not a string, no implicit
28
+ values are defined for them.
29
+
30
+ ## How to Fix
31
+
32
+ Explicitly assign a value or change the type to a string if the values are not
33
+ important in your model. The erroneous example above can be changed to:
34
+
35
+ ```cds
36
+ entity Books {
37
+ // …
38
+ category: Integer enum {
39
+ Fiction = 1;
40
+ Action = 2;
41
+ // …
42
+ } default #Action;
43
+ };
44
+ ```
45
+
46
+ ## Background
47
+
48
+ Many languages support implicit values for integer-like enums. However,
49
+ CAP CDS does not have this feature, because otherwise, if values are persisted,
50
+ adding a new entry in-between existing ones would lead to issues during
51
+ deserialization later on.
52
+
53
+ Assume that CAP would assign implicit values for integer enums. If a new value
54
+ were to be added between `Fiction` and `Action` in the erroneous example above,
55
+ then the generated SQL statement for entity `Books` would change:
56
+ Instead of default value `2`, value `3` would be persisted. Without data
57
+ migration, existing action books would have changed their category.
58
+
59
+ To avoid this scenario, always add explicit values to enums.
@@ -17,7 +17,7 @@ entity Book {
17
17
  };
18
18
  entity IsbnBook as projection on Book {
19
19
  *,
20
- isbn as id,
20
+ isbn as id, // ❌
21
21
  };
22
22
  ```
23
23
 
@@ -1,17 +0,0 @@
1
- {
2
- "extends": ["../.eslintrc-ydkjsi.json"],
3
- "rules": {
4
- "prefer-const": "error",
5
- "quotes": ["error", "single", "avoid-escape"],
6
- "prefer-template": "error",
7
- "no-trailing-spaces": "error",
8
- "template-curly-spacing": ["error", "never"],
9
- "max-len": "off",
10
- "no-console": "off",
11
- "no-process-exit": "off",
12
- "camelcase": "off",
13
- "radix": "off",
14
- "no-shadow": "warn",
15
- "global-require": "off"
16
- }
17
- }
@@ -1,37 +0,0 @@
1
- {
2
- "root": true,
3
- "env": {
4
- "es2022": true,
5
- "node": true
6
- },
7
- // we actually do not extend airbnb-base, as it weakens some eslint:recommended rules
8
- "extends": ["plugin:jsdoc/recommended", "../../.eslintrc-ydkjsi.json"],
9
- "parserOptions": {
10
- "ecmaVersion": 2022,
11
- "sourceType": "script"
12
- },
13
- "plugins": [
14
- "jsdoc"
15
- ],
16
- "rules": {
17
- // Does not recognize TS types
18
- "jsdoc/no-undefined-types": "off",
19
- // eslint-plugin-jsdoc warning
20
- "jsdoc/require-property": 0,
21
- "jsdoc/tag-lines": "off",
22
- // =airbnb, >eslint:
23
- "max-len": [ "error", {
24
- "code": 100,
25
- "tabWidth": 2,
26
- "ignoreComments": true,
27
- "ignoreRegExpLiterals": true,
28
- "ignoreStrings": true,
29
- "ignoreTemplateLiterals": true
30
- }]
31
- },
32
- "settings": {
33
- "jsdoc": {
34
- "mode": "typescript"
35
- }
36
- }
37
- }
@@ -1,31 +0,0 @@
1
- {
2
- // we actually do not extend airbnb-base, as it weakens some eslint:recommended rules
3
- "extends": ["plugin:jsdoc/recommended", "../../.eslintrc-ydkjsi.json"],
4
- "plugins": [
5
- "jsdoc"
6
- ],
7
- "rules": {
8
- "cds-compiler/message-no-quotes": "off",
9
- "quotes": ["error", "single", {
10
- "avoidEscape": true,
11
- "allowTemplateLiterals": true
12
- }],
13
- "jsdoc/no-undefined-types": 0,
14
- // eslint-plugin-jsdoc warning
15
- "jsdoc/require-property": 0,
16
- // most of the main functions have the normal forEachArtifact/Member signature anyway
17
- "jsdoc/require-param-description": 0,
18
- // there seem to be false positives
19
- "jsdoc/require-returns-check": 0,
20
- "jsdoc/tag-lines": 0,
21
- // =airbnb, >eslint:
22
- "max-len": [ "error", {
23
- "code": 110,
24
- "tabWidth": 2,
25
- "ignoreComments": true,
26
- "ignoreRegExpLiterals": true,
27
- "ignoreStrings": true,
28
- "ignoreTemplateLiterals": true
29
- }]
30
- }
31
- }
@@ -1,8 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "../../.eslintrc-ydkjsi.json",
4
- "rules": {
5
- "cds-compiler/message-no-quotes": "warn",
6
- "cds-compiler/space-in-func-call": "warn"
7
- }
8
- }
@@ -1,46 +0,0 @@
1
- {
2
- "root": true,
3
- //"plugins": ["sonarjs", "jsdoc"],
4
- //"extends": ["plugin:jsdoc/recommended", "../../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
5
- "plugins": ["sonarjs"],
6
- "extends": ["../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
7
- "rules": {
8
- "cds-compiler/message-no-quotes": "off",
9
- "cds-compiler/message-template-string": "off",
10
- "prefer-const": "error",
11
- "quotes": ["error", "single", "avoid-escape"],
12
- "prefer-template": "error",
13
- "no-trailing-spaces": "error",
14
- "template-curly-spacing":["error", "never"],
15
- "complexity": ["warn", 50],
16
- "max-len": "off",
17
- // there seem to be false positives
18
- "jsdoc/require-returns-check": "off",
19
- // Don't enforce stupid descriptions
20
- "jsdoc/require-param-description": "off",
21
- "jsdoc/require-returns-description": "off",
22
- // Sometimes if-else's are more specific
23
- "sonarjs/prefer-single-boolean-return": "off",
24
- // Very whiny and nitpicky
25
- "sonarjs/cognitive-complexity": "off",
26
- "sonarjs/no-duplicate-string": "off",
27
- // Does not recognize TS types
28
- "jsdoc/no-undefined-types": "off",
29
- "jsdoc/tag-lines": "off",
30
- "no-nested-ternary": "off",
31
- "sonarjs/no-nested-template-literals": "off"
32
- },
33
- "parserOptions": {
34
- "ecmaVersion": 2022,
35
- "sourceType": "script"
36
- },
37
- "env": {
38
- "es2022": true,
39
- "node": true
40
- },
41
- "settings": {
42
- "jsdoc": {
43
- "mode": "typescript"
44
- }
45
- }
46
- }
@@ -1,4 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "../../.eslintrc-ydkjsi.json"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "../../.eslintrc-ydkjsi.json"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "../../.eslintrc-ydkjsi.json"
4
- }
@@ -1,13 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "../../.eslintrc-ydkjsi.json",
4
- "rules": {
5
- "max-len": [ "error", {
6
- "code": 180, // TODO: Remove
7
- "tabWidth": 2,
8
- "ignoreRegExpLiterals": false,
9
- "ignoreStrings": false,
10
- "ignoreTemplateLiterals": true
11
- }]
12
- }
13
- }
@@ -1,22 +0,0 @@
1
- {
2
- "plugins": ["sonarjs"],
3
- "extends": ["../../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
4
- "rules": {
5
- "prefer-const": "error",
6
- "quotes": ["error", "single", "avoid-escape"],
7
- "prefer-template": "error",
8
- "no-trailing-spaces": "error",
9
- "sonarjs/cognitive-complexity": "off",
10
- "sonarjs/no-duplicate-string": ["off"],
11
- "sonarjs/no-nested-template-literals": "off",
12
- "template-curly-spacing":["error", "never"],
13
- "class-methods-use-this": "off",
14
- // Who cares - just very whiny and in the way
15
- "complexity": "off",
16
- "max-len": "off",
17
- "no-shadow": "warn"
18
- },
19
- "env": {
20
- "es2022": true
21
- }
22
- }
@@ -1,22 +0,0 @@
1
- {
2
- "plugins": ["sonarjs"],
3
- "extends": ["../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
4
- "rules": {
5
- "cds-compiler/message-no-quotes": "off",
6
- "prefer-const": "error",
7
- "quotes": ["error", "single", "avoid-escape"],
8
- "prefer-template": "error",
9
- "no-trailing-spaces": "error",
10
- "sonarjs/cognitive-complexity": "off",
11
- "sonarjs/no-duplicate-string": ["off"],
12
- "sonarjs/no-nested-template-literals": "off",
13
- "template-curly-spacing":["error", "never"],
14
- "class-methods-use-this": "off",
15
- "complexity": "off",
16
- "max-len": "off",
17
- "no-shadow": "warn"
18
- },
19
- "env": {
20
- "es2022": true
21
- }
22
- }
@@ -1,13 +0,0 @@
1
- {
2
- "rules": {
3
- "no-shadow": "off"
4
- },
5
- "overrides": [
6
- {
7
- "files": [
8
- "addTenantFields.js"
9
- ],
10
- "extends": "../../.eslintrc-ydkjsi.json"
11
- }
12
- ]
13
- }
@@ -1,41 +0,0 @@
1
- {
2
- "root": true,
3
- "plugins": ["sonarjs", "jsdoc"],
4
- "extends": ["plugin:jsdoc/recommended", "../../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
5
- "rules": {
6
- "cds-compiler/message-no-quotes": "off",
7
- "prefer-const": "error",
8
- "quotes": ["error", "single", "avoid-escape"],
9
- "prefer-template": "error",
10
- "no-trailing-spaces": "error",
11
- "template-curly-spacing":["error", "never"],
12
- "complexity": ["warn", 40],
13
- "max-len": "off",
14
- // there seem to be false positives
15
- "jsdoc/require-returns-check": "off",
16
- // Don't enforce stupid descriptions
17
- "jsdoc/require-param-description": "off",
18
- "jsdoc/require-returns-description": "off",
19
- // Sometimes if-else's are more specific
20
- "sonarjs/prefer-single-boolean-return": "off",
21
- // Very whiny and nitpicky
22
- "sonarjs/cognitive-complexity": "off",
23
- "sonarjs/no-duplicate-string": "off",
24
- // Does not recognize TS types
25
- "jsdoc/no-undefined-types": "off",
26
- "jsdoc/tag-lines": "off"
27
- },
28
- "parserOptions": {
29
- "ecmaVersion": 2022,
30
- "sourceType": "script"
31
- },
32
- "env": {
33
- "es2022": true,
34
- "node": true
35
- },
36
- "settings": {
37
- "jsdoc": {
38
- "mode": "typescript"
39
- }
40
- }
41
- }
@@ -1,4 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": ["../db/.eslintrc.json"]
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": ["../db/.eslintrc.json"]
4
- }
@@ -1,37 +0,0 @@
1
- {
2
- "root": true,
3
- "plugins": ["sonarjs", "jsdoc"],
4
- "extends": ["plugin:jsdoc/recommended", "../../../.eslintrc-ydkjsi.json", "plugin:sonarjs/recommended"],
5
- "rules": {
6
- "prefer-const": "error",
7
- "quotes": ["error", "single", "avoid-escape"],
8
- "prefer-template": "error",
9
- "no-trailing-spaces": "error",
10
- "template-curly-spacing":["error", "never"],
11
- "complexity": ["warn", 30],
12
- "max-len": "off",
13
- // Don't enforce stupid descriptions
14
- "jsdoc/require-param-description": "off",
15
- "jsdoc/require-returns-description": "off",
16
- // Very whiny and nitpicky
17
- "sonarjs/cognitive-complexity": "off",
18
- // Does not recognize TS types
19
- "jsdoc/no-undefined-types": "off",
20
- "jsdoc/tag-lines": "off",
21
- // Just annoying as hell
22
- "sonarjs/no-duplicate-string": "off"
23
- },
24
- "parserOptions": {
25
- "ecmaVersion": 2022,
26
- "sourceType": "script"
27
- },
28
- "env": {
29
- "es2022": true,
30
- "node": true
31
- },
32
- "settings": {
33
- "jsdoc": {
34
- "mode": "typescript"
35
- }
36
- }
37
- }
@@ -1,7 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "../../.eslintrc-ydkjsi.json",
4
- "rules": {
5
- "prefer-const": "warn"
6
- }
7
- }