@sap/cds-compiler 3.4.2 → 3.5.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 (143) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +1 -0
  3. package/bin/cds_update_identifiers.js +5 -5
  4. package/bin/cdsc.js +15 -16
  5. package/bin/cdshi.js +19 -6
  6. package/doc/CHANGELOG_ARCHIVE.md +2 -2
  7. package/doc/CHANGELOG_BETA.md +9 -1
  8. package/doc/CHANGELOG_DEPRECATED.md +2 -0
  9. package/lib/api/main.js +61 -59
  10. package/lib/api/options.js +4 -2
  11. package/lib/api/validate.js +2 -2
  12. package/lib/base/cleanSymbols.js +2 -3
  13. package/lib/base/dictionaries.js +6 -6
  14. package/lib/base/error.js +2 -2
  15. package/lib/base/keywords.js +6 -6
  16. package/lib/base/location.js +11 -12
  17. package/lib/base/message-registry.js +177 -58
  18. package/lib/base/messages.js +252 -180
  19. package/lib/base/model.js +14 -11
  20. package/lib/base/node-helpers.js +9 -10
  21. package/lib/base/optionProcessorHelper.js +138 -129
  22. package/lib/checks/.eslintrc.json +2 -0
  23. package/lib/checks/actionsFunctions.js +5 -5
  24. package/lib/checks/annotationsOData.js +4 -4
  25. package/lib/checks/arrayOfs.js +1 -1
  26. package/lib/checks/cdsPersistence.js +1 -1
  27. package/lib/checks/checkForTypes.js +3 -3
  28. package/lib/checks/defaultValues.js +3 -3
  29. package/lib/checks/elements.js +7 -7
  30. package/lib/checks/emptyOrOnlyVirtual.js +2 -2
  31. package/lib/checks/foreignKeys.js +1 -1
  32. package/lib/checks/invalidTarget.js +4 -4
  33. package/lib/checks/managedInType.js +1 -1
  34. package/lib/checks/managedWithoutKeys.js +1 -1
  35. package/lib/checks/nonexpandableStructured.js +5 -3
  36. package/lib/checks/nullableKeys.js +1 -1
  37. package/lib/checks/onConditions.js +5 -6
  38. package/lib/checks/parameters.js +1 -1
  39. package/lib/checks/queryNoDbArtifacts.js +2 -2
  40. package/lib/checks/selectItems.js +4 -4
  41. package/lib/checks/sql-snippets.js +4 -4
  42. package/lib/checks/types.js +7 -7
  43. package/lib/checks/utils.js +4 -4
  44. package/lib/checks/validator.js +16 -13
  45. package/lib/compiler/.eslintrc.json +4 -1
  46. package/lib/compiler/assert-consistency.js +8 -7
  47. package/lib/compiler/builtins.js +14 -14
  48. package/lib/compiler/checks.js +123 -48
  49. package/lib/compiler/define.js +12 -13
  50. package/lib/compiler/extend.js +266 -60
  51. package/lib/compiler/finalize-parse-cdl.js +10 -5
  52. package/lib/compiler/index.js +17 -14
  53. package/lib/compiler/populate.js +14 -6
  54. package/lib/compiler/propagator.js +2 -0
  55. package/lib/compiler/resolve.js +2 -15
  56. package/lib/compiler/shared.js +27 -16
  57. package/lib/compiler/tweak-assocs.js +5 -6
  58. package/lib/compiler/utils.js +20 -0
  59. package/lib/edm/annotations/genericTranslation.js +604 -358
  60. package/lib/edm/annotations/preprocessAnnotations.js +39 -35
  61. package/lib/edm/csn2edm.js +275 -222
  62. package/lib/edm/edm.js +17 -3
  63. package/lib/edm/edmAnnoPreprocessor.js +6 -6
  64. package/lib/edm/edmInboundChecks.js +2 -2
  65. package/lib/edm/edmPreprocessor.js +107 -77
  66. package/lib/edm/edmUtils.js +44 -5
  67. package/lib/gen/Dictionary.json +210 -8
  68. package/lib/gen/language.checksum +1 -1
  69. package/lib/gen/language.interp +67 -63
  70. package/lib/gen/language.tokens +81 -81
  71. package/lib/gen/languageLexer.interp +4 -10
  72. package/lib/gen/languageLexer.js +854 -869
  73. package/lib/gen/languageLexer.tokens +79 -81
  74. package/lib/gen/languageParser.js +14309 -13832
  75. package/lib/inspect/inspectModelStatistics.js +2 -2
  76. package/lib/inspect/inspectPropagation.js +6 -6
  77. package/lib/inspect/inspectUtils.js +2 -2
  78. package/lib/json/from-csn.js +102 -55
  79. package/lib/json/to-csn.js +119 -198
  80. package/lib/language/antlrParser.js +5 -2
  81. package/lib/language/docCommentParser.js +6 -6
  82. package/lib/language/errorStrategy.js +43 -23
  83. package/lib/language/genericAntlrParser.js +113 -133
  84. package/lib/language/language.g4 +1550 -1506
  85. package/lib/language/multiLineStringParser.js +3 -3
  86. package/lib/language/textUtils.js +2 -2
  87. package/lib/main.js +3 -3
  88. package/lib/model/csnRefs.js +5 -0
  89. package/lib/model/csnUtils.js +130 -122
  90. package/lib/model/revealInternalProperties.js +1 -1
  91. package/lib/model/sortViews.js +4 -6
  92. package/lib/modelCompare/compare.js +2 -2
  93. package/lib/modelCompare/utils/.eslintrc.json +22 -0
  94. package/lib/modelCompare/utils/filter.js +100 -0
  95. package/lib/optionProcessor.js +5 -0
  96. package/lib/render/.eslintrc.json +1 -0
  97. package/lib/render/DuplicateChecker.js +1 -1
  98. package/lib/render/manageConstraints.js +12 -12
  99. package/lib/render/toCdl.js +311 -276
  100. package/lib/render/toHdbcds.js +97 -94
  101. package/lib/render/toRename.js +5 -5
  102. package/lib/render/toSql.js +127 -223
  103. package/lib/render/utils/common.js +141 -108
  104. package/lib/render/utils/delta.js +227 -0
  105. package/lib/render/utils/sql.js +22 -6
  106. package/lib/render/utils/stringEscapes.js +3 -3
  107. package/lib/transform/db/.eslintrc.json +2 -0
  108. package/lib/transform/db/applyTransformations.js +3 -3
  109. package/lib/transform/db/assertUnique.js +13 -12
  110. package/lib/transform/db/associations.js +5 -5
  111. package/lib/transform/db/cdsPersistence.js +10 -8
  112. package/lib/transform/db/constraints.js +14 -14
  113. package/lib/transform/db/expansion.js +20 -22
  114. package/lib/transform/db/flattening.js +24 -42
  115. package/lib/transform/db/groupByOrderBy.js +3 -3
  116. package/lib/transform/db/temporal.js +6 -6
  117. package/lib/transform/db/transformExists.js +23 -23
  118. package/lib/transform/db/views.js +16 -16
  119. package/lib/transform/draft/.eslintrc.json +1 -35
  120. package/lib/transform/draft/db.js +10 -10
  121. package/lib/transform/draft/odata.js +2 -2
  122. package/lib/transform/forOdataNew.js +8 -29
  123. package/lib/transform/forRelationalDB.js +16 -6
  124. package/lib/transform/localized.js +11 -10
  125. package/lib/transform/odata/toFinalBaseType.js +41 -27
  126. package/lib/transform/odata/typesExposure.js +113 -47
  127. package/lib/transform/parseExpr.js +209 -106
  128. package/lib/transform/transformUtilsNew.js +17 -10
  129. package/lib/transform/translateAssocsToJoins.js +24 -19
  130. package/lib/transform/universalCsn/coreComputed.js +10 -10
  131. package/lib/transform/universalCsn/universalCsnEnricher.js +26 -26
  132. package/lib/transform/universalCsn/utils.js +3 -3
  133. package/lib/utils/file.js +5 -5
  134. package/lib/utils/moduleResolve.js +13 -13
  135. package/lib/utils/objectUtils.js +6 -6
  136. package/lib/utils/term.js +5 -2
  137. package/lib/utils/timetrace.js +51 -24
  138. package/package.json +5 -8
  139. package/share/messages/check-proper-type-of.md +1 -1
  140. package/share/messages/message-explanations.json +1 -1
  141. package/share/messages/redirected-to-complex.md +4 -4
  142. package/share/messages/{syntax-expecting-integer.md → syntax-expecting-unsigned-int.md} +7 -4
  143. package/lib/modelCompare/filter.js +0 -83
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-compiler",
3
- "version": "3.4.2",
3
+ "version": "3.5.0",
4
4
  "description": "CDS (Core Data Services) compiler and backends",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "author": "SAP SE (https://www.sap.com)",
@@ -21,16 +21,14 @@
21
21
  "xmakePrepareRelease": "echo \"$(node scripts/stripReadme.js README.md)\" > README.md && node scripts/assertSnapshotVersioning.js && node scripts/assertChangelog.js && node scripts/cleanup.js --remove-dev",
22
22
  "test": "node scripts/verifyGrammarChecksum.js && mocha --reporter min --reporter-option maxDiffSize=0 scripts/testLazyLoading.js && mocha --parallel --reporter min --reporter-option maxDiffSize=0 test/ test3/",
23
23
  "testverbose": "node scripts/verifyGrammarChecksum.js && mocha --parallel test/ test3/",
24
- "test3": "node scripts/verifyGrammarChecksum.js && node scripts/linter/lintTests.js test3/ && mocha --reporter-option maxDiffSize=0 scripts/linter/lintMessages.js test3/",
25
- "deployTest3SQL": "deployRefs=true mocha --reporter-option maxDiffSize=0 test3/testHANASQLDeployment.js",
24
+ "test3": "node scripts/verifyGrammarChecksum.js && mocha --reporter-option maxDiffSize=0 test3/",
25
+ "deployTest3SQL": "deployRefs=true mocha --reporter-option maxDiffSize=0 test3/test.deploy.hana-sql.js",
26
26
  "deployTest3": "deployRefs=true mocha --reporter-option maxDiffSize=0 test3/testDeployment.js",
27
+ "deployHanaDeltaSQL": "CDS_COMPILER_DEPLOY_HANA=1 mocha test3/test.deploy.hana-sql.delta.js",
27
28
  "deployDiffs": "deployRefs=true mocha --reporter-option maxDiffSize=0 test3/deployDiffs.js",
28
29
  "gentest3": "cross-env MAKEREFS=${MAKEREFS:-'true'} mocha --reporter-option maxDiffSize=0 test3/testRefFiles.js",
29
- "testdb": "node scripts/verifyGrammarChecksum.js && cross-env TESTDB='TRUE' mocha",
30
- "testmigration": "npm install --no-save @sap/hana-client@2.3.123 @sap/hdi-deploy@3.10.0 && node scripts/verifyGrammarChecksum.js && cross-env TESTMIGRATION='TRUE' mocha",
31
- "testall": "npm install --no-save @sap/hana-client@2.3.123 @sap/hdi-deploy@3.10.0 && node scripts/verifyGrammarChecksum.js && cross-env TESTDB='TRUE' TESTMIGRATION='TRUE' mocha",
32
30
  "coverage": "cross-env nyc mocha --reporter-option maxDiffSize=0 test/ test3/ && nyc report --reporter=lcov",
33
- "lint": "eslint bin/ benchmark/ lib/ test/ test3/ scripts/ types/ && node scripts/linter/lintGrammar.js && node scripts/linter/lintTests.js test3/ && markdownlint README.md CHANGELOG.md doc/ internalDoc/ && cd share/messages && markdownlint .",
31
+ "lint": "eslint bin/ benchmark/ lib/ test/ test3/ scripts/ types/ && node scripts/linter/lintGrammar.js && node scripts/linter/lintTests.js test3/ && node scripts/linter/lintMessages.js && node scripts/linter/lintMessageIdCoverage.js lib/ && markdownlint README.md CHANGELOG.md doc/ internalDoc/ && cd share/messages && markdownlint .",
34
32
  "tslint": "tsc --pretty -p .",
35
33
  "updateVocs": "node scripts/odataAnnotations/generateDictMain.js && npm run generateAllRefs",
36
34
  "generateCompilerRefs": "cross-env MAKEREFS='true' mocha test/testCompiler.js",
@@ -41,7 +39,6 @@
41
39
  "generateToSqlRefs": "cross-env MAKEREFS='true' mocha test/testToSql.js",
42
40
  "generateToRenameRefs": "cross-env MAKEREFS='true' mocha test/testToRename.js",
43
41
  "generateChecksRefs": "cross-env MAKEREFS='true' mocha test/testChecks.js",
44
- "generateScenarioRefs": "cross-env MAKEREFS='true' mocha test/testScenarios.js",
45
42
  "generateDraftRefs": "cross-env MAKEREFS='true' mocha test/testDraft.js",
46
43
  "generateAllRefs": "node scripts/verifyGrammarChecksum.js && cross-env MAKEREFS='true' mocha --reporter-option maxDiffSize=0 test/ test3/"
47
44
  },
@@ -19,7 +19,7 @@ view ViewFoo as select from Foo {
19
19
  };
20
20
  entity Bar {
21
21
  // `e` has no proper type but has the annotation `@anno`.
22
- e : type of ViewFoo:calculatedField;
22
+ e : ViewFoo:calculatedField;
23
23
  };
24
24
  ```
25
25
 
@@ -11,7 +11,7 @@
11
11
  "redirected-to-complex",
12
12
  "redirected-to-unrelated",
13
13
  "rewrite-not-supported",
14
- "syntax-expecting-integer",
14
+ "syntax-expecting-unsigned-int",
15
15
  "wildcard-excluding-one"
16
16
  ]
17
17
  }
@@ -3,7 +3,7 @@
3
3
  The redirected target is a complex view, for example, contains a JOIN or UNION.
4
4
 
5
5
  The message's severity is `Info` and is raised by the compiler.
6
- It is emitted to help developers identify possible modelling issues.
6
+ It is emitted to help developers identify possible modeling issues.
7
7
 
8
8
  ## Example
9
9
 
@@ -33,7 +33,7 @@ The cross join in the view `CrossJoin` results in multiple rows with the same
33
33
  `id`. Following the redirected view now returns multiple results, effectively
34
34
  making the to-one association a to-many association.
35
35
 
36
- Visualizing the tables with a bit of data, this issues becomes obvious:
36
+ Visualizing the tables with a bit of data, this issue becomes obvious:
37
37
 
38
38
  ```markdown
39
39
  Main Secondary
@@ -54,8 +54,8 @@ CrossJoin
54
54
  ## How to Fix
55
55
 
56
56
  Ensure that the redirected association points to an entity that is a reasonable
57
- redirection target. You must ensure that the redirection does not accidentally
58
- result in a to-one association becoming a to-many association.
57
+ redirection target. That means, the redirection target shouldn't accidentally
58
+ make it a to-many association.
59
59
 
60
60
  ## Related Messages
61
61
 
@@ -1,6 +1,6 @@
1
- # syntax-expecting-integer
1
+ # syntax-expecting-unsigned-int
2
2
 
3
- The compiler expects a safe integer here.
3
+ The compiler expects a safe non-negative integer here.
4
4
  The last safe integer is `2^53 - 1` or `9007199254740991`.
5
5
 
6
6
  A safe integer is an integer that fulfills all of the following:
@@ -34,5 +34,8 @@ type LengthIsSafe : String(9007199254740991);
34
34
  type AnInteger : String(42);
35
35
  ```
36
36
 
37
- If it's not feasible to use a safe integer, a string representation of the
38
- number needs to be used, for example, in annotation values.
37
+ At other places, using unsafe integers (or non-integer numbers) is allowed:
38
+
39
+ - Annotation values: The value is then simply a string.
40
+ - Expressions: The `val` property in the CSN contains a string
41
+ having a sibling `literal: 'number'`.
@@ -1,83 +0,0 @@
1
- // Each db has some changes that it can and cannot represent, or that cause problems only on that specific db
2
- // In this file, we define rules for each db-dialect to detect and act on these cases.
3
-
4
- const { forEach } = require("../utils/objectUtils");
5
- const { isPersistedAsTable } = require('../model/csnUtils');
6
-
7
- function isKey(element) {
8
- return element.key;
9
- }
10
-
11
- module.exports = {
12
- sqlite: getFilterObject(
13
- 'sqlite',
14
- (extend, name, element, error) => {
15
- if(isKey(element)) { // Key must not be extended
16
- error(null, ['definitions', extend, 'elements', name], {id: name, name: 'sqlite'}, "Added element $(ID) is a primary key change and will not work with $(NAME)")
17
- }
18
- },
19
- (migrate, name, migration, change, error) => {
20
- const newIsKey = isKey(migration.new);
21
- const oldIsKey = isKey(migration.old);
22
- if((newIsKey || oldIsKey) && oldIsKey !== newIsKey) { // Turned into key or key was removed
23
- error(null, ['definitions', migrate, 'elements', name], {id: name, name: 'sqlite'}, "Changed element $(ID) is a primary key change and will not work with $(NAME)")
24
- } else { // Ignore simple migrations
25
- delete change[name];
26
- }
27
- })
28
- }
29
-
30
- function getFilterObject(dialect, extensionCallback, migrationCallback) {
31
- return {
32
- // will be called with a simple Array.forEach
33
- extension: ({ elements, extend }, error) => {
34
- forEach(elements, (name, element) => {
35
- extensionCallback(extend, name, element, error);
36
- });
37
- },
38
- // will be called with a Array.map, as we need to filter "change" for SQLite
39
- migration: ({ change, migrate, remove }, error) => {
40
- forEach(remove, (name) => {
41
- error(null, ['definitions', migrate, 'elements', name], {}, "Dropping elements is not supported")
42
- });
43
-
44
- forEach(change, (name, migration) => {
45
- if(migration.new.type !== migration.old.type && typeChangeIsNotCompatible(dialect, migration.old.type, migration.new.type)) {
46
- error(null, ['definitions', migrate, 'elements', name], { id: name, name: migration.old.type, type: migration.new.type }, "Changed element $(ID) is a lossy type change from $(NAME) to $(TYPE) and is not supported")
47
- } else if(migration.new.length < migration.old.length) {
48
- error(null, ['definitions', migrate, 'elements', name], { id: name }, "Changed element $(ID) is a length reduction and is not supported")
49
- } else {
50
- migrationCallback(migrate, name, migration, change, error);
51
- }
52
-
53
- // TODO: precision/scale growth
54
- });
55
- },
56
- deletion: ([artifactName, artifact ], error) => {
57
- if(isPersistedAsTable(artifact))
58
- error(null, ['definitions', artifactName], "Dropping tables is not supported");
59
- }
60
- }
61
- }
62
-
63
- const baseMatrix = {
64
- // Integer types
65
- 'cds.hana.tinyint':['cds.UInt8', 'cds.Int16', 'cds.Int32', 'cds.Integer', 'cds.Int64', 'cds.Integer64'],
66
- 'cds.UInt8': ['cds.hana.tinyint', 'cds.Int16', 'cds.Int32', 'cds.Integer', 'cds.Int64', 'cds.Integer64'],
67
- 'cds.Int16': ['cds.hana.smallint', 'cds.Int32', 'cds.Integer', 'cds.Int64', 'cds.Integer64'],
68
- 'cds.hana.smallint':['cds.Int16', 'cds.Int32', 'cds.Integer', 'cds.Int64', 'cds.Integer64'],
69
- 'cds.Int32': ['cds.Integer', 'cds.Int64', 'cds.Integer64'],
70
- 'cds.Integer': ['cds.Int32', 'cds.Int64', 'cds.Integer64'],
71
- 'cds.Integer64': ['cds.Int64'],
72
- 'cds.Int64': ['cds.Integer64']
73
- }
74
-
75
- const allowedTypeChanges = {
76
- 'sqlite': baseMatrix
77
- };
78
-
79
- function typeChangeIsNotCompatible(dialect, before, after) {
80
- if(allowedTypeChanges[dialect])
81
- return allowedTypeChanges[dialect][before]?.indexOf(after) === -1;
82
- return true;
83
- }