@sap/cds 5.6.3 → 5.7.3

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 (187) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/_i18n/i18n_fr.properties +4 -4
  3. package/apis/cds.d.ts +7 -10
  4. package/apis/connect.d.ts +3 -3
  5. package/apis/core.d.ts +2 -4
  6. package/apis/models.d.ts +2 -3
  7. package/apis/ql.d.ts +0 -1
  8. package/apis/services.d.ts +3 -3
  9. package/bin/build/buildTaskFactory.js +16 -10
  10. package/bin/build/buildTaskProviderFactory.js +3 -3
  11. package/bin/build/constants.js +2 -1
  12. package/bin/build/provider/buildTaskProviderInternal.js +14 -14
  13. package/bin/build/provider/hana/2migration.js +2 -3
  14. package/bin/build/provider/hana/index.js +34 -0
  15. package/bin/build/provider/hana/migrationtable.js +90 -22
  16. package/bin/build/provider/hana/template/undeploy.json +5 -0
  17. package/bin/build/provider/node-cf/index.js +9 -2
  18. package/bin/serve.js +16 -18
  19. package/lib/compile/cdsc.js +15 -5
  20. package/lib/compile/etc/_localized.js +4 -4
  21. package/lib/compile/extend.js +8 -0
  22. package/lib/compile/index.js +3 -1
  23. package/lib/compile/minify.js +61 -0
  24. package/lib/compile/resolve.js +4 -1
  25. package/lib/compile/to/gql.js +9 -0
  26. package/lib/compile/to/sql.js +26 -30
  27. package/lib/connect/index.js +1 -1
  28. package/lib/core/entities.js +0 -3
  29. package/lib/core/infer.js +1 -0
  30. package/lib/core/reflect.js +0 -34
  31. package/lib/deploy.js +25 -17
  32. package/lib/env/defaults.js +3 -1
  33. package/lib/env/index.js +8 -3
  34. package/lib/env/presets.js +38 -0
  35. package/lib/env/requires.js +16 -11
  36. package/lib/index.js +13 -11
  37. package/lib/log/format/kibana.js +4 -2
  38. package/lib/log/index.js +2 -2
  39. package/lib/ql/Whereable.js +1 -0
  40. package/lib/req/cds-context.js +79 -0
  41. package/lib/req/context.js +5 -77
  42. package/lib/req/request.js +1 -1
  43. package/lib/serve/Service-api.js +8 -4
  44. package/lib/serve/Service-dispatch.js +0 -7
  45. package/lib/serve/Service-methods.js +6 -8
  46. package/lib/serve/Transaction.js +35 -30
  47. package/lib/serve/adapters.js +1 -4
  48. package/lib/utils/axios.js +1 -1
  49. package/libx/_runtime/audit/Service.js +44 -20
  50. package/libx/_runtime/audit/generic/personal/access.js +16 -11
  51. package/libx/_runtime/audit/generic/personal/modification.js +5 -5
  52. package/libx/_runtime/audit/generic/personal/utils.js +46 -37
  53. package/libx/_runtime/{common/auth → auth}/index.js +21 -7
  54. package/libx/_runtime/{common/auth → auth}/strategies/JWT.js +2 -2
  55. package/libx/_runtime/{common/auth → auth}/strategies/basic.js +2 -2
  56. package/libx/_runtime/{common/auth → auth}/strategies/dummy.js +1 -1
  57. package/libx/_runtime/{common/auth → auth}/strategies/mock.js +2 -2
  58. package/libx/_runtime/{common/auth → auth}/strategies/utils/uaa.js +1 -1
  59. package/libx/_runtime/{common/auth → auth}/strategies/utils/xssec.js +0 -0
  60. package/libx/_runtime/{common/auth → auth}/strategies/xsuaa.js +2 -2
  61. package/libx/_runtime/cds-services/adapter/odata-v4/Dispatcher.js +7 -2
  62. package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +0 -7
  63. package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +0 -8
  64. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +3 -4
  65. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +6 -7
  66. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/delete.js +3 -4
  67. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +2 -11
  68. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +16 -6
  69. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +26 -69
  70. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +0 -7
  71. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +3 -66
  72. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +29 -1
  73. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +7 -1
  74. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +9 -5
  75. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +2 -2
  76. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriParser.js +13 -10
  77. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/ConditionalRequestControlCommand.js +0 -7
  78. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/validator/ConditionalRequestValidator.js +0 -8
  79. package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +54 -76
  80. package/libx/_runtime/cds-services/adapter/rest/RestRequest.js +0 -7
  81. package/libx/_runtime/cds-services/adapter/rest/handlers/create.js +3 -6
  82. package/libx/_runtime/cds-services/adapter/rest/handlers/delete.js +3 -6
  83. package/libx/_runtime/cds-services/adapter/rest/handlers/operation.js +3 -6
  84. package/libx/_runtime/cds-services/adapter/rest/handlers/read.js +3 -6
  85. package/libx/_runtime/cds-services/adapter/rest/handlers/update.js +3 -6
  86. package/libx/_runtime/cds-services/adapter/rest/rest-to-cqn/index.js +2 -2
  87. package/libx/_runtime/cds-services/adapter/rest/utils/parse-url.js +8 -4
  88. package/libx/_runtime/cds-services/services/Service.js +0 -6
  89. package/libx/_runtime/cds-services/services/utils/columns.js +10 -3
  90. package/libx/_runtime/cds-services/services/utils/compareJson.js +4 -7
  91. package/libx/_runtime/cds-services/services/utils/differ.js +4 -1
  92. package/libx/_runtime/cds-services/services/utils/handlerUtils.js +1 -41
  93. package/libx/_runtime/cds-services/util/assert.js +1 -262
  94. package/libx/_runtime/cds.js +6 -9
  95. package/libx/_runtime/common/aspects/entity.js +1 -1
  96. package/libx/_runtime/common/composition/delete.js +4 -2
  97. package/libx/_runtime/common/composition/update.js +22 -38
  98. package/libx/_runtime/common/composition/utils.js +3 -7
  99. package/libx/_runtime/common/error/standardError.js +11 -0
  100. package/libx/_runtime/common/generic/auth.js +63 -33
  101. package/libx/_runtime/common/generic/crud.js +11 -23
  102. package/libx/_runtime/common/generic/input.js +20 -0
  103. package/libx/_runtime/common/generic/paging.js +2 -2
  104. package/libx/_runtime/common/generic/put.js +4 -10
  105. package/libx/_runtime/common/generic/sorting.js +12 -30
  106. package/libx/_runtime/common/i18n/messages.properties +2 -0
  107. package/libx/_runtime/common/perf/index.js +24 -0
  108. package/libx/_runtime/common/utils/cqn.js +58 -1
  109. package/libx/_runtime/common/utils/cqn2cqn4sql.js +298 -121
  110. package/libx/_runtime/common/utils/csn.js +38 -56
  111. package/libx/_runtime/common/utils/entityFromCqn.js +6 -6
  112. package/libx/_runtime/common/utils/resolveView.js +4 -5
  113. package/libx/_runtime/common/utils/rewriteAsterisks.js +46 -5
  114. package/libx/_runtime/common/utils/search2cqn4sql.js +21 -9
  115. package/libx/_runtime/common/utils/structured.js +35 -25
  116. package/libx/_runtime/db/Service.js +0 -6
  117. package/libx/_runtime/db/expand/expand-v2.js +130 -0
  118. package/libx/_runtime/db/expand/expandCQNToJoin.js +38 -52
  119. package/libx/_runtime/db/expand/index.js +3 -1
  120. package/libx/_runtime/db/generic/arrayed.js +3 -1
  121. package/libx/_runtime/db/generic/input.js +52 -10
  122. package/libx/_runtime/db/generic/integrity.js +367 -26
  123. package/libx/_runtime/db/generic/virtual.js +51 -13
  124. package/libx/_runtime/db/query/read.js +12 -8
  125. package/libx/_runtime/db/query/update.js +9 -3
  126. package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +8 -9
  127. package/libx/_runtime/{common → db}/utils/propagateForeignKeys.js +11 -14
  128. package/libx/_runtime/fiori/generic/activate.js +1 -0
  129. package/libx/_runtime/fiori/generic/before.js +2 -1
  130. package/libx/_runtime/fiori/generic/edit.js +1 -0
  131. package/libx/_runtime/fiori/generic/patch.js +1 -1
  132. package/libx/_runtime/fiori/generic/read.js +128 -57
  133. package/libx/_runtime/fiori/uiflex/handler/transformRESULT.js +0 -4
  134. package/libx/_runtime/fiori/uiflex/index.js +1 -1
  135. package/libx/_runtime/fiori/uiflex/{extensibility/index.js → service.js} +6 -4
  136. package/libx/_runtime/fiori/utils/delete.js +7 -1
  137. package/libx/_runtime/hana/Service.js +1 -8
  138. package/libx/_runtime/hana/customBuilder/CustomSelectBuilder.js +5 -14
  139. package/libx/_runtime/hana/execute.js +10 -4
  140. package/libx/_runtime/hana/pool.js +55 -45
  141. package/libx/_runtime/hana/search.js +7 -6
  142. package/libx/_runtime/hana/search2cqn4sql.js +8 -5
  143. package/libx/_runtime/hana/searchToContains.js +3 -1
  144. package/libx/_runtime/index.js +5 -5
  145. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +3 -3
  146. package/libx/_runtime/messaging/Outbox.js +53 -0
  147. package/libx/_runtime/messaging/common-utils/AMQPClient.js +17 -10
  148. package/libx/_runtime/messaging/common-utils/connections.js +14 -9
  149. package/libx/_runtime/messaging/common-utils/waitingTime.js +2 -0
  150. package/libx/_runtime/messaging/enterprise-messaging-shared.js +2 -3
  151. package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +2 -2
  152. package/libx/_runtime/messaging/enterprise-messaging.js +21 -15
  153. package/libx/_runtime/messaging/file-based.js +5 -5
  154. package/libx/_runtime/messaging/message-queuing-utils/options-messaging.js +1 -0
  155. package/libx/_runtime/messaging/message-queuing.js +2 -3
  156. package/libx/_runtime/messaging/outbox/OutboxRunner.js +75 -0
  157. package/libx/_runtime/messaging/outbox/utils.js +192 -0
  158. package/libx/_runtime/messaging/service.js +16 -30
  159. package/libx/_runtime/remote/Service.js +15 -0
  160. package/libx/_runtime/remote/utils/client.js +15 -3
  161. package/libx/_runtime/remote/utils/{dataConversion.js → data.js} +12 -2
  162. package/libx/_runtime/sqlite/Service.js +7 -10
  163. package/libx/_runtime/sqlite/customBuilder/CustomExpressionBuilder.js +19 -0
  164. package/libx/_runtime/sqlite/execute.js +18 -12
  165. package/libx/_runtime/types/api.js +2 -1
  166. package/libx/gql/resolvers/parse/ast2cqn/columns.js +1 -1
  167. package/libx/odata/{odata2cqn/afterburner.js → afterburner.js} +28 -16
  168. package/libx/odata/{cqn2odata/index.js → cqn2odata.js} +1 -1
  169. package/libx/odata/{odata2cqn/grammar.pegjs → grammar.pegjs} +222 -130
  170. package/libx/odata/index.js +23 -14
  171. package/libx/odata/parser.js +1 -0
  172. package/libx/odata/utils.js +57 -0
  173. package/libx/rest/RestAdapter.js +2 -6
  174. package/libx/rest/utils/data.js +1 -6
  175. package/package.json +4 -3
  176. package/server.js +4 -5
  177. package/srv/audit-log.cds +87 -0
  178. package/{libx/_runtime/fiori/uiflex/extensibility/index.cds → srv/flex.cds} +0 -0
  179. package/srv/flex.js +1 -0
  180. package/srv/outbox.cds +11 -0
  181. package/srv/outbox.js +0 -0
  182. package/libx/_runtime/cds-services/adapter/perf/performance.js +0 -104
  183. package/libx/_runtime/cds-services/adapter/perf/performanceMeasurement.js +0 -33
  184. package/libx/odata/odata2cqn/index.js +0 -3
  185. package/libx/odata/odata2cqn/parser.js +0 -1
  186. package/libx/odata/readme.md +0 -1
  187. package/libx/odata/utils/index.js +0 -64
@@ -1,7 +1,7 @@
1
- const cds = require('../../_runtime/cds')
1
+ const cds = require('../_runtime/cds')
2
2
 
3
- const { where2obj } = require('../../_runtime/common/utils/cqn')
4
- const { findCsnTargetFor } = require('../../_runtime/common/utils/csn')
3
+ const { where2obj } = require('../_runtime/common/utils/cqn')
4
+ const { findCsnTargetFor } = require('../_runtime/common/utils/csn')
5
5
 
6
6
  function _keysOf(entity) {
7
7
  return entity && entity.keys
@@ -11,11 +11,11 @@ function _keysOf(entity) {
11
11
  : []
12
12
  }
13
13
 
14
- function _getDefinition(definition, name) {
14
+ function _getDefinition(definition, name, namespace) {
15
15
  return (
16
16
  (definition.definitions && definition.definitions[name]) ||
17
17
  (definition.elements && definition.elements[name]) ||
18
- (definition.actions && definition.actions[name]) ||
18
+ (definition.actions && (definition.actions[name] || definition.actions[name.replace(namespace + '.', '')])) ||
19
19
  definition[name]
20
20
  )
21
21
  }
@@ -29,7 +29,7 @@ function _resolveAliasInWhere(where, entity) {
29
29
  }
30
30
 
31
31
  // case: single key without name, e.g., Foo(1)
32
- function _addRefToWhereIfNecessary(where, entity) {
32
+ function addRefToWhereIfNecessary(where, entity) {
33
33
  if (!where || where.length !== 1) return 0
34
34
  const keys = _keysOf(entity)
35
35
  if (keys.length !== 1) return 0
@@ -37,8 +37,9 @@ function _addRefToWhereIfNecessary(where, entity) {
37
37
  return 1
38
38
  }
39
39
 
40
- function _processSegments(cqn, model) {
41
- const { ref } = cqn.SELECT.from
40
+ function _processSegments(cqn, model, namespace) {
41
+ const from = _resolveFrom(cqn.SELECT.from)
42
+ const ref = from.ref
42
43
 
43
44
  let current = model
44
45
  let path
@@ -59,7 +60,15 @@ function _processSegments(cqn, model) {
59
60
  let base = ref[i - keyCount]
60
61
  if (!base.id) base = { id: base, where: [] }
61
62
  if (base.where.length) base.where.push('and')
62
- base.where.push({ ref: [key] }, '=', { val: element.type === 'cds.Integer' ? Number(seg) : seg })
63
+ if (ref[i].id) {
64
+ // > fix case key value parsed to collection with filter
65
+ const val = `${ref[i].id}(${Object.keys(params)
66
+ .map(k => `${k}='${params[k]}'`)
67
+ .join(',')})`
68
+ base.where.push({ ref: [key] }, '=', { val })
69
+ } else {
70
+ base.where.push({ ref: [key] }, '=', { val: element.type === 'cds.Integer' ? Number(seg) : seg })
71
+ }
63
72
  ref[i] = null
64
73
  ref[i - keyCount] = base
65
74
  incompleteKeys = keyCount < keys.length
@@ -71,7 +80,7 @@ function _processSegments(cqn, model) {
71
80
 
72
81
  path = path ? path + `${path.match(/:/) ? '.' : ':'}${seg}` : seg
73
82
  // REVISIT: replace use case: <namespace>.<entity>_history is at <namespace>.<entity>.history
74
- current = _getDefinition(current, seg) || _getDefinition(current, seg.replace(/_/g, '.'))
83
+ current = _getDefinition(current, seg, namespace) || _getDefinition(current, seg.replace(/_/g, '.'), namespace)
75
84
  // REVISIT: 404 or 400?
76
85
  if (!current) cds.error(`Invalid resource path "${path}"`, { code: 404 })
77
86
 
@@ -80,7 +89,7 @@ function _processSegments(cqn, model) {
80
89
  one = !!(ref[i].where || current._isSingleton)
81
90
  incompleteKeys = ref[i].where ? false : i === ref.length - 1 || one ? false : true
82
91
  if (ref[i].where) {
83
- keyCount += _addRefToWhereIfNecessary(ref[i].where, current)
92
+ keyCount += addRefToWhereIfNecessary(ref[i].where, current)
84
93
  _resolveAliasInWhere(ref[i].where, current)
85
94
  }
86
95
  } else if ({ action: 1, function: 1 }[current.kind]) {
@@ -98,7 +107,7 @@ function _processSegments(cqn, model) {
98
107
  incompleteKeys = one || i === ref.length - 1 ? false : true
99
108
  current = model.definitions[current.target]
100
109
  if (ref[i].where) {
101
- keyCount += _addRefToWhereIfNecessary(ref[i].where, current)
110
+ keyCount += addRefToWhereIfNecessary(ref[i].where, current)
102
111
  _resolveAliasInWhere(ref[i].where, current)
103
112
  }
104
113
  } else if (current._isStructured) {
@@ -125,7 +134,7 @@ function _processSegments(cqn, model) {
125
134
  }
126
135
 
127
136
  // remove all nulled refs
128
- cqn.SELECT.from.ref = ref.filter(r => r)
137
+ from.ref = ref.filter(r => r)
129
138
 
130
139
  // one?
131
140
  if (one) cqn.SELECT.one = true
@@ -135,11 +144,13 @@ function _processSegments(cqn, model) {
135
144
  cqn.__target = current
136
145
  }
137
146
 
147
+ const _resolveFrom = from => (from.SELECT ? _resolveFrom(from.SELECT.from) : from)
148
+
138
149
  function _4service(service) {
139
150
  const { namespace, model } = service
140
151
 
141
152
  return cqn => {
142
- const { ref } = cqn.SELECT.from
153
+ const { ref } = _resolveFrom(cqn.SELECT.from)
143
154
 
144
155
  // REVISIT: shouldn't be necessary
145
156
  /*
@@ -154,7 +165,7 @@ function _4service(service) {
154
165
  /*
155
166
  * key vs. path segments (/Books/1/author/books/2/...) and more
156
167
  */
157
- _processSegments(cqn, model)
168
+ _processSegments(cqn, model, namespace)
158
169
 
159
170
  return cqn
160
171
  }
@@ -166,5 +177,6 @@ module.exports = {
166
177
  for: service => {
167
178
  if (!cache.has(service)) cache.set(service, _4service(service))
168
179
  return cache.get(service)
169
- }
180
+ },
181
+ addRefToWhereIfNecessary
170
182
  }
@@ -1,4 +1,4 @@
1
- const { formatVal } = require('../utils')
1
+ const { formatVal } = require('./utils')
2
2
 
3
3
  const OPERATORS = {
4
4
  '=': 'eq',