@sap/cds 5.9.8 → 6.0.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 (381) hide show
  1. package/CHANGELOG.md +277 -20
  2. package/apis/services.d.ts +1 -1
  3. package/app/fiori/preview.js +2 -6
  4. package/app/index.js +3 -3
  5. package/bin/build/buildTaskEngine.js +17 -15
  6. package/bin/build/buildTaskFactory.js +29 -19
  7. package/bin/build/buildTaskHandler.js +27 -11
  8. package/bin/build/buildTaskProvider.js +2 -4
  9. package/bin/build/buildTaskProviderFactory.js +11 -16
  10. package/bin/build/constants.js +14 -6
  11. package/bin/build/csv-reader.js +2 -1
  12. package/bin/build/index.js +12 -18
  13. package/bin/build/provider/buildTaskHandlerEdmx.js +3 -39
  14. package/bin/build/provider/buildTaskHandlerFeatureToggles.js +149 -0
  15. package/bin/build/provider/buildTaskHandlerInternal.js +2 -3
  16. package/bin/build/provider/buildTaskProviderInternal.js +108 -239
  17. package/bin/build/provider/fiori/index.js +2 -2
  18. package/bin/build/provider/hana/2migration.js +11 -11
  19. package/bin/build/provider/hana/2tabledata.js +3 -3
  20. package/bin/build/provider/hana/index.js +89 -99
  21. package/bin/build/provider/hana/migrationtable.js +4 -3
  22. package/bin/build/provider/java/index.js +101 -0
  23. package/bin/build/provider/java-cf/index.js +1 -101
  24. package/bin/build/provider/mtx/index.js +83 -41
  25. package/bin/build/provider/mtx/resourcesTarBuilder.js +68 -0
  26. package/bin/build/provider/mtx-sidecar/index.js +110 -0
  27. package/bin/build/provider/node-cf/index.js +1 -308
  28. package/bin/build/provider/nodejs/index.js +189 -0
  29. package/bin/build/util.js +21 -31
  30. package/bin/cds.js +5 -3
  31. package/bin/deploy/to-hana/cfUtil.js +31 -6
  32. package/bin/deploy/to-hana/gitUtil.js +5 -3
  33. package/bin/deploy/to-hana/hana.js +15 -13
  34. package/bin/{build → deploy/to-hana}/mtaUtil.js +10 -9
  35. package/bin/mtx/in-cds.js +19 -7
  36. package/bin/serve.js +49 -22
  37. package/bin/utils/log.js +13 -30
  38. package/bin/version.js +4 -3
  39. package/common.cds +61 -16
  40. package/lib/compile/cdsc.js +3 -2
  41. package/lib/compile/etc/_localized.js +15 -14
  42. package/lib/compile/for/drafts.js +3 -4
  43. package/lib/compile/for/java.js +13 -10
  44. package/lib/compile/for/nodejs.js +8 -8
  45. package/lib/compile/for/odata.js +7 -12
  46. package/lib/compile/for/sql.js +5 -6
  47. package/lib/compile/index.js +5 -4
  48. package/lib/compile/load.js +9 -11
  49. package/lib/compile/minify.js +8 -5
  50. package/lib/compile/parse.js +4 -2
  51. package/lib/compile/resolve.js +18 -15
  52. package/lib/compile/to/edm.js +0 -1
  53. package/lib/compile/to/gql.js +3 -2
  54. package/lib/compile/to/json.js +24 -17
  55. package/lib/connect/bindings.js +3 -2
  56. package/lib/connect/index.js +5 -5
  57. package/lib/core/classes.js +74 -2
  58. package/lib/core/entities.js +52 -3
  59. package/lib/core/reflect.js +2 -1
  60. package/lib/deploy.js +10 -8
  61. package/lib/env/defaults.js +4 -3
  62. package/lib/env/index.js +71 -31
  63. package/lib/env/presets.js +1 -14
  64. package/lib/env/requires.js +71 -20
  65. package/lib/env/serviceBindings.js +147 -0
  66. package/lib/i18n/localize.js +22 -23
  67. package/lib/index.js +148 -144
  68. package/lib/log/errors.js +55 -12
  69. package/lib/log/format/kibana.js +1 -1
  70. package/lib/log/index.js +4 -0
  71. package/lib/ql/SELECT.js +7 -2
  72. package/lib/ql/Whereable.js +8 -2
  73. package/lib/ql/index.js +2 -2
  74. package/lib/req/assert.js +71 -0
  75. package/lib/req/cds-context.js +38 -70
  76. package/lib/req/context.js +34 -21
  77. package/lib/req/request.js +12 -18
  78. package/lib/req/response.js +6 -2
  79. package/lib/req/user.js +30 -22
  80. package/lib/serve/Service-api.js +17 -12
  81. package/lib/serve/Service-dispatch.js +5 -9
  82. package/lib/serve/Service-methods.js +4 -3
  83. package/lib/serve/Transaction.js +24 -21
  84. package/lib/serve/adapters.js +15 -5
  85. package/lib/serve/factory.js +22 -20
  86. package/lib/serve/index.js +51 -54
  87. package/lib/utils/axios.js +8 -12
  88. package/lib/utils/index.js +13 -4
  89. package/lib/utils/resources/index.js +1 -44
  90. package/lib/utils/resources/tar.js +2 -1
  91. package/lib/utils/tests.js +13 -15
  92. package/libx/_runtime/.eslintrc +1 -1
  93. package/libx/_runtime/audit/Service.js +6 -4
  94. package/libx/_runtime/audit/generic/personal/access.js +19 -43
  95. package/libx/_runtime/audit/generic/personal/index.js +40 -34
  96. package/libx/_runtime/audit/generic/personal/modification.js +11 -9
  97. package/libx/_runtime/audit/generic/personal/utils.js +13 -6
  98. package/libx/_runtime/audit/utils/v2.js +6 -3
  99. package/libx/_runtime/auth/index.js +71 -66
  100. package/libx/_runtime/auth/strategies/JWT.js +3 -2
  101. package/libx/_runtime/auth/strategies/mock.js +54 -53
  102. package/libx/_runtime/auth/strategies/xssecUtils.js +3 -4
  103. package/libx/_runtime/auth/strategies/xsuaa.js +3 -2
  104. package/libx/_runtime/auth/utils.js +2 -15
  105. package/libx/_runtime/cds-services/adapter/odata-v4/Dispatcher.js +127 -41
  106. package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +9 -5
  107. package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +93 -73
  108. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +25 -45
  109. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +10 -14
  110. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +9 -5
  111. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +4 -2
  112. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +60 -53
  113. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +2 -2
  114. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +21 -26
  115. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +8 -15
  116. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +29 -41
  117. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/index.js +1 -4
  118. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +13 -13
  119. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/selectToCQN.js +0 -7
  120. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +24 -1
  121. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/edm/EdmEntityContainer.js +1 -1
  122. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriHelper.js +4 -3
  123. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/PrimitiveValueDecoder.js +4 -5
  124. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/ValueConverter.js +4 -3
  125. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/validator/ValueValidator.js +5 -3
  126. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/core/ResponseHeaderSetter.js +2 -0
  127. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/DebugSerializingCommand.js +1 -1
  128. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/PresetResponseHeadersCommand.js +1 -1
  129. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/SerializingCommand.js +1 -1
  130. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/SetResponseHeadersCommand.js +1 -1
  131. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/ContextURLFactory.js +3 -2
  132. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/ErrorJsonSerializer.js +3 -1
  133. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/SerializerFactory.js +1 -0
  134. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/TrustedResourceJsonSerializer.js +3 -3
  135. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +36 -25
  136. package/libx/_runtime/cds-services/adapter/odata-v4/utils/handlerUtils.js +97 -92
  137. package/libx/_runtime/cds-services/adapter/odata-v4/utils/metaInfo.js +382 -0
  138. package/libx/_runtime/cds-services/adapter/odata-v4/utils/oDataConfiguration.js +1 -4
  139. package/libx/_runtime/cds-services/adapter/odata-v4/utils/omitValues.js +5 -6
  140. package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +82 -21
  141. package/libx/_runtime/cds-services/adapter/odata-v4/utils/request.js +3 -11
  142. package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +91 -69
  143. package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +27 -6
  144. package/libx/_runtime/cds-services/adapter/rest/utils/validation-checks.js +7 -17
  145. package/libx/_runtime/cds-services/services/Service.js +17 -76
  146. package/libx/_runtime/cds-services/services/utils/columns.js +6 -4
  147. package/libx/_runtime/cds-services/services/utils/compareJson.js +1 -53
  148. package/libx/_runtime/cds-services/services/utils/differ.js +15 -19
  149. package/libx/_runtime/cds-services/util/assert.js +107 -34
  150. package/libx/_runtime/cds.js +1 -31
  151. package/libx/_runtime/common/aspects/Association.js +40 -54
  152. package/libx/_runtime/common/aspects/any.js +61 -6
  153. package/libx/_runtime/common/aspects/entity.js +19 -79
  154. package/libx/_runtime/common/composition/data.js +2 -2
  155. package/libx/_runtime/common/composition/delete.js +8 -7
  156. package/libx/_runtime/common/composition/tree.js +10 -10
  157. package/libx/_runtime/common/composition/update.js +3 -2
  158. package/libx/_runtime/common/constants/events.js +13 -0
  159. package/libx/_runtime/common/error/entry.js +9 -3
  160. package/libx/_runtime/common/error/frontend.js +13 -19
  161. package/libx/_runtime/common/error/index.js +8 -3
  162. package/libx/_runtime/common/generic/auth/capabilities.js +2 -1
  163. package/libx/_runtime/common/generic/auth/constants.js +1 -4
  164. package/libx/_runtime/common/generic/auth/requires.js +1 -1
  165. package/libx/_runtime/common/generic/auth/restrict.js +12 -28
  166. package/libx/_runtime/common/generic/auth/restrictions.js +12 -4
  167. package/libx/_runtime/common/generic/auth/utils.js +2 -1
  168. package/libx/_runtime/common/generic/crud.js +9 -60
  169. package/libx/_runtime/common/generic/etag.js +41 -7
  170. package/libx/_runtime/common/generic/input.js +128 -66
  171. package/libx/_runtime/common/generic/paging.js +9 -3
  172. package/libx/_runtime/common/generic/put.js +2 -2
  173. package/libx/_runtime/common/generic/sorting.js +7 -3
  174. package/libx/_runtime/common/generic/temporal.js +0 -5
  175. package/libx/_runtime/common/i18n/messages.properties +2 -1
  176. package/libx/_runtime/common/utils/binary.js +69 -0
  177. package/libx/_runtime/common/utils/cqn.js +39 -14
  178. package/libx/_runtime/common/utils/cqn2cqn4sql.js +93 -59
  179. package/libx/_runtime/common/utils/csn.js +87 -85
  180. package/libx/_runtime/common/utils/dollar.js +8 -7
  181. package/libx/_runtime/common/utils/draft.js +1 -1
  182. package/libx/_runtime/common/utils/foreignKeyPropagations.js +23 -7
  183. package/libx/_runtime/common/utils/generateOnCond.js +2 -1
  184. package/libx/_runtime/common/utils/keys.js +30 -13
  185. package/libx/_runtime/common/utils/postProcessing.js +6 -1
  186. package/libx/_runtime/common/utils/quotingStyles.js +0 -23
  187. package/libx/_runtime/common/utils/resolveStructured.js +23 -26
  188. package/libx/_runtime/common/utils/resolveView.js +4 -1
  189. package/libx/_runtime/common/utils/rewriteAsterisks.js +3 -0
  190. package/libx/_runtime/common/utils/search2cqn4sql.js +4 -13
  191. package/libx/_runtime/common/utils/searchToLike.js +9 -13
  192. package/libx/_runtime/common/utils/streamProp.js +35 -0
  193. package/libx/_runtime/common/utils/structured.js +12 -18
  194. package/libx/_runtime/common/utils/template.js +3 -5
  195. package/libx/_runtime/common/utils/templateProcessor.js +22 -14
  196. package/libx/_runtime/common/utils/unionCqnTemplate.js +4 -14
  197. package/libx/_runtime/db/Service.js +2 -1
  198. package/libx/_runtime/db/expand/expand-v2.js +2 -2
  199. package/libx/_runtime/db/expand/expandCQNToJoin.js +7 -6
  200. package/libx/_runtime/db/generic/input.js +14 -17
  201. package/libx/_runtime/db/generic/integrity.js +1 -2
  202. package/libx/_runtime/db/generic/update.js +14 -1
  203. package/libx/_runtime/db/query/read.js +0 -1
  204. package/libx/_runtime/db/query/update.js +1 -1
  205. package/libx/_runtime/db/sql-builder/BaseBuilder.js +1 -1
  206. package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +5 -31
  207. package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -1
  208. package/libx/_runtime/db/sql-builder/ReferenceBuilder.js +0 -9
  209. package/libx/_runtime/db/sql-builder/SelectBuilder.js +11 -10
  210. package/libx/_runtime/db/sql-builder/UpdateBuilder.js +2 -2
  211. package/libx/_runtime/db/sql-builder/annotations.js +1 -2
  212. package/libx/_runtime/db/utils/coloredTxCommands.js +5 -0
  213. package/libx/_runtime/db/utils/columns.js +1 -1
  214. package/libx/_runtime/db/utils/propagateForeignKeys.js +10 -2
  215. package/libx/_runtime/extensibility/activate.js +69 -0
  216. package/libx/_runtime/extensibility/add.js +41 -0
  217. package/libx/_runtime/extensibility/addExtension.js +68 -0
  218. package/libx/_runtime/extensibility/defaults.js +39 -0
  219. package/libx/_runtime/extensibility/{uiflex/handler → handler}/transformREAD.js +0 -0
  220. package/libx/_runtime/extensibility/{uiflex/handler → handler}/transformRESULT.js +2 -2
  221. package/libx/_runtime/extensibility/{uiflex/handler → handler}/transformWRITE.js +2 -2
  222. package/libx/_runtime/extensibility/push.js +61 -0
  223. package/libx/_runtime/extensibility/service.js +21 -0
  224. package/libx/_runtime/extensibility/{uiflex/utils.js → utils.js} +39 -3
  225. package/libx/_runtime/extensibility/validation.js +53 -0
  226. package/libx/_runtime/extensibility/views.js +12 -0
  227. package/libx/_runtime/fiori/generic/activate.js +2 -4
  228. package/libx/_runtime/fiori/generic/before.js +17 -29
  229. package/libx/_runtime/fiori/generic/cancel.js +2 -4
  230. package/libx/_runtime/fiori/generic/delete.js +2 -4
  231. package/libx/_runtime/fiori/generic/edit.js +4 -16
  232. package/libx/_runtime/fiori/generic/index.js +31 -0
  233. package/libx/_runtime/fiori/generic/new.js +5 -21
  234. package/libx/_runtime/fiori/generic/patch.js +10 -15
  235. package/libx/_runtime/fiori/generic/prepare.js +13 -22
  236. package/libx/_runtime/fiori/generic/read.js +148 -163
  237. package/libx/_runtime/fiori/generic/readOverDraft.js +10 -4
  238. package/libx/_runtime/fiori/utils/handler.js +10 -22
  239. package/libx/_runtime/fiori/utils/where.js +1 -4
  240. package/libx/_runtime/hana/Service.js +14 -7
  241. package/libx/_runtime/hana/customBuilder/CustomSelectBuilder.js +1 -1
  242. package/libx/_runtime/hana/dynatrace.js +2 -2
  243. package/libx/_runtime/hana/localized.js +7 -6
  244. package/libx/_runtime/hana/pool.js +9 -6
  245. package/libx/_runtime/hana/search.js +2 -3
  246. package/libx/_runtime/hana/{searchToContains.js → search2Contains.js} +5 -2
  247. package/libx/_runtime/hana/search2cqn4sql.js +20 -17
  248. package/libx/_runtime/index.js +2 -6
  249. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +30 -22
  250. package/libx/_runtime/messaging/common-utils/AMQPClient.js +4 -3
  251. package/libx/_runtime/messaging/common-utils/appId.js +9 -0
  252. package/libx/_runtime/messaging/common-utils/authorizedRequest.js +2 -18
  253. package/libx/_runtime/messaging/common-utils/connections.js +1 -1
  254. package/libx/_runtime/messaging/enterprise-messaging-shared.js +2 -2
  255. package/libx/_runtime/messaging/enterprise-messaging-utils/EMManagement.js +305 -231
  256. package/libx/_runtime/messaging/enterprise-messaging-utils/cloudEvents.js +2 -2
  257. package/libx/_runtime/messaging/enterprise-messaging-utils/options-management.js +15 -8
  258. package/libx/_runtime/messaging/enterprise-messaging-utils/options-messaging.js +57 -14
  259. package/libx/_runtime/messaging/enterprise-messaging.js +14 -19
  260. package/libx/_runtime/messaging/file-based.js +3 -1
  261. package/libx/_runtime/messaging/http-utils/token.js +18 -6
  262. package/libx/_runtime/messaging/message-queuing-utils/options-management.js +22 -12
  263. package/libx/_runtime/messaging/message-queuing-utils/options-messaging.js +27 -14
  264. package/libx/_runtime/messaging/message-queuing.js +138 -85
  265. package/libx/_runtime/messaging/outbox/utils.js +13 -7
  266. package/libx/_runtime/messaging/redis-messaging.js +0 -1
  267. package/libx/_runtime/messaging/service.js +4 -1
  268. package/libx/_runtime/remote/Service.js +24 -18
  269. package/libx/_runtime/remote/utils/client.js +90 -48
  270. package/libx/_runtime/remote/utils/data.js +23 -6
  271. package/libx/_runtime/sqlite/Service.js +14 -13
  272. package/libx/_runtime/sqlite/convertAssocToOneManaged.js +2 -0
  273. package/libx/_runtime/sqlite/customBuilder/CustomSelectBuilder.js +1 -0
  274. package/libx/_runtime/sqlite/execute.js +3 -9
  275. package/libx/_runtime/types/api.js +23 -11
  276. package/libx/common/utils/ucsn.js +15 -9
  277. package/libx/odata/afterburner.js +109 -29
  278. package/libx/odata/cqn2odata.js +48 -9
  279. package/libx/odata/grammar.pegjs +263 -156
  280. package/libx/odata/index.js +21 -9
  281. package/libx/odata/parseToCqn.js +8 -5
  282. package/libx/odata/parser.js +1 -1
  283. package/libx/odata/utils.js +13 -3
  284. package/libx/rest/RestAdapter.js +173 -113
  285. package/libx/rest/RestRequest.js +3 -2
  286. package/libx/rest/middleware/create.js +8 -6
  287. package/libx/rest/middleware/delete.js +6 -13
  288. package/libx/rest/middleware/error.js +1 -1
  289. package/libx/rest/middleware/input.js +6 -6
  290. package/libx/rest/middleware/operation.js +8 -3
  291. package/libx/rest/middleware/parse.js +3 -3
  292. package/libx/rest/middleware/payload.js +12 -0
  293. package/libx/rest/middleware/read.js +12 -2
  294. package/libx/rest/middleware/update.js +3 -3
  295. package/package.json +4 -6
  296. package/server.js +3 -44
  297. package/srv/extensibility-service.cds +56 -0
  298. package/srv/extensibility-service.js +1 -0
  299. package/srv/extensions.cds +8 -0
  300. package/srv/model-provider.cds +59 -0
  301. package/srv/model-provider.js +163 -0
  302. package/srv/mtx.cds +2 -0
  303. package/srv/mtx.js +22 -0
  304. package/srv/outbox.cds +2 -0
  305. package/tasks/enterprise-messaging-deploy.js +19 -12
  306. package/lib/serve/Service-compat.js +0 -36
  307. package/libx/_runtime/audit/generic/personal/constants.js +0 -4
  308. package/libx/_runtime/auth/strategies/dwc.js +0 -45
  309. package/libx/_runtime/cds-services/adapter/odata-v4/utils/dispatcherUtils.js +0 -56
  310. package/libx/_runtime/cds-services/adapter/rest/Rest.js +0 -183
  311. package/libx/_runtime/cds-services/adapter/rest/RestRequest.js +0 -67
  312. package/libx/_runtime/cds-services/adapter/rest/handlers/create.js +0 -82
  313. package/libx/_runtime/cds-services/adapter/rest/handlers/delete.js +0 -39
  314. package/libx/_runtime/cds-services/adapter/rest/handlers/operation.js +0 -63
  315. package/libx/_runtime/cds-services/adapter/rest/handlers/read.js +0 -52
  316. package/libx/_runtime/cds-services/adapter/rest/handlers/update.js +0 -81
  317. package/libx/_runtime/cds-services/adapter/rest/rest-to-cqn/index.js +0 -56
  318. package/libx/_runtime/cds-services/adapter/rest/rest-to-cqn/utils.js +0 -33
  319. package/libx/_runtime/cds-services/adapter/rest/to.js +0 -8
  320. package/libx/_runtime/cds-services/adapter/rest/utils/binary.js +0 -50
  321. package/libx/_runtime/cds-services/adapter/rest/utils/data.js +0 -117
  322. package/libx/_runtime/cds-services/adapter/rest/utils/header-checks.js +0 -14
  323. package/libx/_runtime/cds-services/adapter/rest/utils/key-value-utils.js +0 -30
  324. package/libx/_runtime/cds-services/adapter/rest/utils/parse-url.js +0 -250
  325. package/libx/_runtime/cds-services/adapter/rest/utils/result.js +0 -26
  326. package/libx/_runtime/cds-services/services/utils/handlerUtils.js +0 -200
  327. package/libx/_runtime/common/aspects/utils.js +0 -152
  328. package/libx/_runtime/common/toggles/handler.js +0 -21
  329. package/libx/_runtime/common/utils/extensibilityUtils.js +0 -18
  330. package/libx/_runtime/extensibility/mps/index.js +0 -5
  331. package/libx/_runtime/extensibility/mps/service.js +0 -111
  332. package/libx/_runtime/extensibility/mps/tar.js +0 -42
  333. package/libx/_runtime/extensibility/mps/utils.js +0 -11
  334. package/libx/_runtime/extensibility/uiflex/index.js +0 -54
  335. package/libx/_runtime/extensibility/uiflex/service.js +0 -276
  336. package/libx/_runtime/messaging/common-utils/naming-conventions.js +0 -20
  337. package/libx/_runtime/remote/utils/client-types.d.ts +0 -7
  338. package/libx/gql/GraphQLAdapter.js +0 -33
  339. package/libx/gql/constants/adapter.js +0 -69
  340. package/libx/gql/constants/cds.js +0 -18
  341. package/libx/gql/constants/graphql.js +0 -33
  342. package/libx/gql/readme.md +0 -1
  343. package/libx/gql/resolvers/crud/create.js +0 -20
  344. package/libx/gql/resolvers/crud/delete.js +0 -29
  345. package/libx/gql/resolvers/crud/index.js +0 -6
  346. package/libx/gql/resolvers/crud/read.js +0 -30
  347. package/libx/gql/resolvers/crud/update.js +0 -42
  348. package/libx/gql/resolvers/crud/utils/index.js +0 -36
  349. package/libx/gql/resolvers/field.js +0 -5
  350. package/libx/gql/resolvers/index.js +0 -7
  351. package/libx/gql/resolvers/mutation.js +0 -23
  352. package/libx/gql/resolvers/parse/ast/enrich.js +0 -52
  353. package/libx/gql/resolvers/parse/ast/fragment.js +0 -11
  354. package/libx/gql/resolvers/parse/ast/fromObject.js +0 -39
  355. package/libx/gql/resolvers/parse/ast/index.js +0 -3
  356. package/libx/gql/resolvers/parse/ast/meta.js +0 -4
  357. package/libx/gql/resolvers/parse/ast/variable.js +0 -7
  358. package/libx/gql/resolvers/parse/ast2cqn/columns.js +0 -44
  359. package/libx/gql/resolvers/parse/ast2cqn/entries.js +0 -31
  360. package/libx/gql/resolvers/parse/ast2cqn/index.js +0 -8
  361. package/libx/gql/resolvers/parse/ast2cqn/limit.js +0 -6
  362. package/libx/gql/resolvers/parse/ast2cqn/orderBy.js +0 -24
  363. package/libx/gql/resolvers/parse/ast2cqn/utils/index.js +0 -3
  364. package/libx/gql/resolvers/parse/ast2cqn/where.js +0 -70
  365. package/libx/gql/resolvers/parse/utils/index.js +0 -8
  366. package/libx/gql/resolvers/query.js +0 -13
  367. package/libx/gql/resolvers/root.js +0 -34
  368. package/libx/gql/schema/generate.js +0 -18
  369. package/libx/gql/schema/index.js +0 -5
  370. package/libx/gql/schema/mutation.js +0 -76
  371. package/libx/gql/schema/query.js +0 -108
  372. package/libx/gql/schema/typeDefMap.js +0 -45
  373. package/libx/gql/schema/utils/index.js +0 -54
  374. package/libx/gql/utils/index.js +0 -12
  375. package/libx/rest/middleware/auth.js +0 -20
  376. package/libx/rest/middleware/content.js +0 -19
  377. package/srv/flex.cds +0 -21
  378. package/srv/flex.js +0 -1
  379. package/srv/mps.cds +0 -23
  380. package/srv/mps.js +0 -1
  381. package/srv/outbox.js +0 -0
@@ -0,0 +1,71 @@
1
+ const cds = require ('../index'), $ = cds.error.message
2
+
3
+ module.exports = (req) => (field) => {
4
+
5
+ const def = field.name ? field : field.split('.').reduce (
6
+ (target,e) => target.elements[e] || cds.error `There's no element '${e}' in ${target}`,
7
+ req.target
8
+ )
9
+ return {
10
+
11
+ isSpecified (_msg) {
12
+ return this.validate ('MANDATORY_VALUE', this.data != undefined,
13
+ _msg, ()=> $`Value has to be filled in.`
14
+ )
15
+ },
16
+
17
+ isInRange (range, _msg) {
18
+ let data = this.data; if (data == undefined) return true
19
+ return this.validate ('VALUE_IN_RANGE',
20
+ !range ? data in def.enum : data >= range[0] && data <= range[1],
21
+ _msg, ()=> $`Value has to be in range ${range || Object.keys(def.enum)}.`
22
+ )
23
+ },
24
+
25
+ matches (pattern, _msg) {
26
+ let data = this.data; if (data == undefined) return true
27
+ let re = typeof pattern === 'string' ? RegExp(pattern) : pattern
28
+ return this.validate ('VALUE_MATCHING_PATTERN', re.test(data),
29
+ _msg, ()=> $`Value has to match ${re}`
30
+ )
31
+ },
32
+
33
+ meets (code, constraint, _msg) {
34
+ if (typeof code === 'function') [code,constraint,_msg] = ['CONSTRAINT',code,constraint]
35
+ let data = this.data; if (data == undefined) return true
36
+ let ok = constraint(data)
37
+ let validate = ok => this.validate(code,ok,_msg, ()=> `Value failed to meet ${constraint}`)
38
+ return typeof ok.then === 'function' ? ok.then(validate) : validate(ok)
39
+ },
40
+
41
+ async exists (_msg) {
42
+ let data = req.target.data(req.data), ref = def.refIn(data); if (ref == undefined) return true
43
+ return this.validate ('TARGET_EXISTS', await req.tx.exists(ref).forUpdate(),
44
+ _msg, ()=> $`Record ${def.target} with ${data[def.name]} doesn't exist.`
45
+ )
46
+ },
47
+
48
+ validate: (code, ok, _msg, message) => ok || req.error ({
49
+ code: 'FAILED_'+code, target: def.name,
50
+ message: _msg || message()
51
+ }),
52
+
53
+ get data(){ return def.dataIn(req.data) },
54
+ get to(){ return {__proto__:this,
55
+ get match(){ return this.matches },
56
+ get exist(){ return this.exists },
57
+ get meet(){ return this.meets },
58
+ get be(){ return {__proto__:this,
59
+ get specified(){ return this.isSpecified },
60
+ get inRange(){ return this.isInRange },
61
+ get in(){ return {__proto__:this,
62
+ get range(){ return this.isInRange },
63
+ }}
64
+ }}
65
+ }},
66
+ get not(){ return {__proto__:this, validate:(c,ok,m,$) => this.validate(
67
+ c, !ok, m, ()=> $().replace(/must|has to/,'must not')
68
+ )}},
69
+
70
+ }
71
+ }
@@ -1,82 +1,50 @@
1
- const cds = require('../index'), { EventContext } = cds
1
+ const { AsyncLocalStorage } = require ('async_hooks')
2
2
  const { EventEmitter } = require('events')
3
+ const EventContext = require('./context')
3
4
 
5
+ module.exports = new class extends AsyncLocalStorage {
4
6
 
5
- /**
6
- * Continuation Local Storage for cds.context
7
- */
8
- exports.for = (cds,v) => {
7
+ run(v,fn,...args) { return super.run (this._context4(v),fn,...args) }
8
+ enterWith(v) { return super.enterWith (this._context4(v)) }
9
9
 
10
- if (cds.env.features.cls) {
11
-
12
- const { executionAsyncResource:current, createHook } = module.require ('async_hooks')
13
- const _context = Symbol('cds.context')
14
-
15
- createHook ({ init(id,t,tid, res) {
16
- const cr = current(); if (!cr) return
17
- const ctx = cr[_context]
18
- if (ctx) res[_context] = ctx
19
- }}).enable()
20
-
21
- Reflect.defineProperty (cds,'context',{ enumerable:1,
22
- set(v) {
23
- const cr = current(); if (!cr) return
24
- const ctx = (
25
- v instanceof EventContext || typeof v !== 'object' ? v :
26
- v.context || EventContext.for (v.req ? {_:v} : v)
27
- )
28
- cr[_context] = ctx
29
- },
30
- get() {
31
- const cr = current(); if (!cr) return undefined
32
- return cr[_context]
33
- },
34
- })
35
-
36
- } else {
10
+ _context4(v) {
11
+ if (v instanceof EventContext || typeof v !== 'object') return v
12
+ if (v.context) return v.context
13
+ if (v.req) v = v.res ? {http:v} : {http:{ ...v, res: v.req.res }}
14
+ return EventContext.for(v)
15
+ }
37
16
 
38
- Reflect.defineProperty (cds,'context',{ enumerable:1,
17
+ /** @returns {EventContext} */
18
+ _for (cds,v) {
19
+ Reflect.defineProperty (cds,'context', { enumerable:1, ... cds.env.features.cls ? {
20
+ set:(v) => this.enterWith(v),
21
+ get:()=> this.getStore(),
22
+ } : {
39
23
  get:()=> undefined,
40
24
  set:()=> {},
41
- })
42
-
25
+ }})
26
+ return cds.context = v // IMPORTANT: we need to set it initially, to get it all wired up correctly
43
27
  }
44
28
 
45
- return v ? cds.context = v : cds.context
46
- }
47
-
48
-
49
-
50
- exports.spawn = function cds_spawn (o,fn) {
51
-
52
- if (typeof o === 'function') [fn,o] = [o,fn] //> for compatibility
53
- if (o instanceof cds.EventContext) throw new Error('The passed options must not be an instance of cds.EventContext.')
54
- else if (!o) o = {}
55
-
56
- const em = new EventEmitter()
57
- const fx = () => {
58
- // create a new transaction for each run of the background job
59
- // which inherits from the current event context by default
60
- const o2 = { ...o }; delete o2.timestamp //> spawned txes set their own timestamps
61
- const tx = cds.context = cds.tx(o2)
62
- const commit = async (res) => {
63
- await tx.commit()
64
- for (const handler of em.listeners('succeeded')) await handler(res)
65
- for (const handler of em.listeners('done')) await handler()
29
+ spawn (o,fn, /** @type {import('../index')} cds */ cds=this) {
30
+ if (typeof o === 'function') [fn,o] = [o,fn] //> for compatibility
31
+ if (o instanceof EventContext) throw cds.error `The passed options must not be an instance of cds.EventContext.`
32
+ const fx = ()=>{
33
+ const tx = cds.tx({...o}) // create a new detached transaction for each run of the background job
34
+ return cds._context.run (tx, ()=> Promise.resolve(fn(tx))
35
+ .then (tx.commit, e => tx.rollback(_error(e, cds)))
36
+ .then (res => Promise.all(em.listeners('succeeded').map(each => each(res))))
37
+ .catch (err => Promise.all(em.listeners('failed').map(each => each(err))))
38
+ .finally (() => Promise.all(em.listeners('done').map(each => each())))
39
+ )
66
40
  }
67
- Promise.resolve().then(() => fn(tx)).then(commit, tx.rollback) .catch (async e => {
68
- // tx.rollback throws passed error -> we will arrive here for any error
69
- cds.log().error(`ERROR occured in background job:`, e)
70
- for (const handler of em.listeners('failed')) await handler(e)
71
- for (const handler of em.listeners('done')) await handler()
72
- })
41
+ const em = new EventEmitter; em.timer = (
42
+ (o && o.after) ? setTimeout(fx, o.after) :
43
+ (o && o.every) ? setInterval(fx, o.every) :
44
+ setImmediate(fx)
45
+ )
46
+ return em
73
47
  }
74
-
75
- const timer = (
76
- (o && o.after) ? setTimeout(fx, o.after) :
77
- (o && o.every) ? setInterval(fx, o.every) :
78
- setImmediate(fx)
79
- )
80
-
81
- return Object.assign (em, { timer })
82
48
  }
49
+
50
+ const _error = (err, cds) => { cds.log().error(`ERROR occured in background job:`, err); return err }
@@ -1,5 +1,5 @@
1
1
  const cds = require ('../index'), { features } = cds.env, { uuid } = cds.utils
2
- const async_events = { succeeded:1, failed:1, done:1 }
2
+ const async_events = { succeeded:1, failed:1, done:1, commit:1 }
3
3
  const req_locale = require('./locale')
4
4
  const { EventEmitter } = require('events')
5
5
 
@@ -84,15 +84,13 @@ class EventContext {
84
84
  }
85
85
 
86
86
  set user(u) {
87
- const user = super.user = u instanceof cds.User ? u : new cds.User(u)
88
- for (let p of ['tenant','locale']) { // compatibility
89
- if (u && u.hasOwnProperty(p)) this[p] = u[p] // eslint-disable-line no-prototype-builtins
90
- else Object.defineProperty (user, p, { get: () => this[p] })
91
- }
87
+ const user = u instanceof cds.User ? u : new cds.User(u)
88
+ if (u && typeof u === 'object') for (let p in _TENANT_LOCALE) if (p in u && u[p]) this[p] = u[p]
89
+ super.user = new Proxy (user,{ get:(t,p) => p in _TENANT_LOCALE ? this[p] : t[p] })
92
90
  }
93
91
  get user() {
94
- const u = this._propagated.user
95
- return this.user = u ? {__proto__:u} : new cds.User.default
92
+ this.user = this._propagated.user || _anonymous
93
+ return this.user // IMPORTANT: first set this.user then return it separately to ensure we return the compat-wrapped objects
96
94
  }
97
95
 
98
96
  set locale(l) {
@@ -114,41 +112,56 @@ class EventContext {
114
112
  if (h) super.headers = h
115
113
  }
116
114
  get headers() {
117
- if (this._ && this._.req && this._.req.headers) {
118
- return super.headers = this._.req.headers
119
- } else {
120
- const headers={}, outer = this._propagated.headers
115
+ let headers = this._.req?.headers
116
+ if (!headers) { headers={}
117
+ const outer = this._propagated.headers
121
118
  if (outer) for (let each of EventContext.propagateHeaders) {
122
119
  if (each in outer) headers[each] = outer[each]
123
120
  }
124
- return super.headers = headers
125
121
  }
122
+ return super.headers = headers
123
+ }
124
+
125
+ set http(rr) {
126
+ if (!this._.req) Object.assign(this._, rr)
127
+ super.http = rr
128
+ }
129
+ get http() {
130
+ return this._propagated.http || this._.req && this._.res && { req:this._.req, res:this._.res }
126
131
  }
127
132
 
128
133
 
129
- set _tx(tx) {
130
- Object.defineProperty (this,'_tx',{value:tx}) //> allowed only once!
134
+ /**
135
+ * This sets an EventContext's / Message's / Request's tx object, i.e.
136
+ * the service which this request is passed on for execution.
137
+ * In response to that, the instance will be wired up to and inherit
138
+ * context properties from tx.context.
139
+ */
140
+ set tx (tx) {
141
+ Object.defineProperty (this,'tx',{value:tx}) //> allowed only once!
131
142
  const ctx = tx.context
132
143
  if (ctx && ctx !== this) {
133
144
  if (!this.hasOwnProperty('context')) this.context = ctx // eslint-disable-line no-prototype-builtins
134
- ///////////////////////////////////////////////////////////////////
135
- // REVISIT: Eliminate req._children
136
- if (features.assert_integrity !== false) {
145
+
146
+ if (features.assert_integrity && features.assert_integrity_type == 'RT') {
137
147
  const reqs = ctx._children || ctx._set('_children', {})
138
148
  const all = reqs[tx.name] || (reqs[tx.name] = [])
139
149
  all.push(this)
140
- } //////////////////////////////////////////////////////////////////
150
+ }
141
151
  }
142
152
  }
153
+ get _tx() { return this.tx } // REVISIT: for compatibility to bade usages of req._tx
143
154
 
144
155
 
145
156
  /** REVISIT: remove -> @deprecated */
146
- set _model(m){ super._model = m }
157
+ set _model(m){ Object.defineProperty(this,'_model',{value:m}) }
147
158
  get _model() {
148
- return super._model = this._tx && this._tx.model || this._propagated._model
159
+ return this._model = this.tx && this.tx.model || this._propagated._model
149
160
  }
150
161
  }
151
162
 
163
+ const _TENANT_LOCALE = { tenant:1, locale:2 }
164
+ const _anonymous = new cds.User.default
152
165
 
153
166
  EventContext.prototype._set('_propagated', Object.seal({}))
154
167
  EventContext.propagateHeaders = [ 'x-correlation-id' ]
@@ -9,6 +9,8 @@ class Request extends require('./event') {
9
9
 
10
10
  toString() { return `${this.event} ${this.path}` }
11
11
 
12
+ get assert(){ return super.assert = require('./assert')(this) }
13
+
12
14
  set method(m) { if (m) super.method = m }
13
15
  get method() {
14
16
  return this._set ('method', Crud2Http[this.event] || this.event)
@@ -33,27 +35,23 @@ class Request extends require('./event') {
33
35
 
34
36
  set path(p) { if (p) super.path = p.startsWith('/') ? p.slice(1) : p }
35
37
  get path() {
36
- const {_} = this
37
- if (this.query) { // IMPORTANT: Bulk queries don't have a _.query
38
- const q = this.query
38
+ const q = this.query; if (this.query) { // IMPORTANT: Bulk queries don't have a _.query
39
39
  if (q.SELECT) return this._set ('path', _path4 (q.SELECT,'from'))
40
40
  if (q.INSERT) return this._set ('path', _path4 (q.INSERT,'into'))
41
41
  if (q.UPDATE) return this._set ('path', _path4 (q.UPDATE,'entity'))
42
42
  if (q.DELETE) return this._set ('path', _path4 (q.DELETE,'from'))
43
43
  }
44
+ const {_} = this
44
45
  if (_.target) return this._set ('path', _.target.name)
45
46
  if (_.entity) return this._set ('path', _.entity.name || _.entity)
46
- else return this._set ('path', undefined)
47
+ return this._set ('path', undefined)
47
48
  }
48
49
 
49
50
  set data(d) { if (d) super.data = d }
50
51
  get data() {
51
- const q = this.query
52
- if (!q) return this._set ('data', undefined)
53
- const I = q.INSERT
54
- if (I) return this._set ('data', I.rows || I.values || I.entries && (I.entries.length > 1 ? I.entries : I.entries[0]) ||{})
55
- const U = q.UPDATE
56
- if (U) return this._set ('data', U.data ||{})
52
+ const q = this.query; if (!q) return this._set ('data', undefined)
53
+ const I = q.INSERT; if (I) return this._set ('data', I.rows || I.values || I.entries && (I.entries.length > 1 ? I.entries : I.entries[0]) ||{})
54
+ const U = q.UPDATE; if (U) return this._set ('data', U.data ||{})
57
55
  return this._set ('data', {})
58
56
  }
59
57
 
@@ -63,8 +61,9 @@ class Request extends require('./event') {
63
61
  warn (...args) { return this._messages.add (3, ...args) }
64
62
  error (...args) { return this._errors.add (4, ...args) }
65
63
  reject (...args) {
66
- const e = this.error(...args)
67
- throw e.stack ? e : Object.assign(new Error,e)
64
+ let e = this.error(...args)
65
+ if (!e.stack) Error.captureStackTrace (e = Object.assign(new Error,e), this.reject)
66
+ throw e
68
67
  }
69
68
 
70
69
  // Lazily create message collectors for .errors and .messages
@@ -131,10 +130,5 @@ const _path4 = (x,p) => {
131
130
  // REVISIT: Legacy stuff...
132
131
  //
133
132
  Object.defineProperties (Request.prototype, {
134
-
135
- diff: { value: function (...args) {
136
- const {_service:d} = this.target
137
- return d ? global.cds.services[d.name]._calculateDiff(this, ...args) : Promise.resolve([])
138
- }},
139
-
133
+ diff: { get: ()=> require('../../libx/_runtime/cds-services/services/utils/differ').reqDiff }
140
134
  })
@@ -1,3 +1,5 @@
1
+ const cds = require ('../index')
2
+
1
3
  /**
2
4
  * Messages Collector, used for `req.errors` and `req.messages`
3
5
  */
@@ -20,9 +22,11 @@ class Responses extends Array {
20
22
  }
21
23
 
22
24
  class Errors extends Responses {
23
- throwable() {
24
- return this.length === 1 ? this[0] : { message: 'MULTIPLE_ERRORS', details:this }
25
+ push(e) {
26
+ 'stack' in e || Error.captureStackTrace (e = Object.assign(new Error,e), cds.Request.prototype.error)
27
+ return super.push(e)
25
28
  }
29
+ throwable() { return this.length > 1 ? Object.assign(new Error('MULTIPLE_ERRORS'), { details: this }) : this[0] }
26
30
  }
27
31
 
28
32
  module.exports = { Responses, Errors }
package/lib/req/user.js CHANGED
@@ -1,20 +1,21 @@
1
1
  class User {
2
2
 
3
3
  constructor (_) {
4
- if (new.target === Anonymous) return; else if (_ === undefined) return new User.default
4
+ if (_ === undefined) {
5
+ if (new.target === Privileged) return
6
+ if (new.target === Anonymous) return
7
+ else return new User.default
8
+ }
5
9
  if (typeof _ === 'string') { this.id = _; return }
6
- for (let each in _) super[each] = _[each] // overrides getters
7
- if (Array.isArray(_._roles)) this._roles = _._roles.reduce((p,n)=>{p[n]=1; return p},{})
10
+ for (let each in _) super[each === '_roles' ? 'roles' : each] = _[each] // overrides getters
11
+ if (Array.isArray(this.roles)) this.roles = this.roles.reduce ((p,n)=>{p[n]=1; return p},{})
8
12
  }
9
13
 
10
14
  get attr() { return super.attr = {} }
15
+ get roles(){ return super.roles = {} }
16
+ get _roles(){ return this.roles } // compatibility
11
17
 
12
- get _roles(){ return super._roles = {
13
- 'identified-user': !!this.id,
14
- 'authenticated-user': !!this.id && this.authLevel !== 'weak' // REVISIT: _.authLevel
15
- }}
16
-
17
- is (role) { return role === 'any' || !!this._roles[role] }
18
+ is (role) { return role === 'any' || role === 'identified-user' || role === 'authenticated-user' && this.authLevel !== 'weak' || !!this.roles[role] }
18
19
  valueOf() { return this.id }
19
20
 
20
21
  }
@@ -22,22 +23,29 @@ class User {
22
23
  /**
23
24
  * Subclass representing non-identified unauthenticated users.
24
25
  */
25
- class Anonymous extends User {
26
- is (role) { return role === 'any' }
27
- get _roles() { return {} }
28
- }
29
- Anonymous.prototype._is_anonymous = true
30
- Anonymous.prototype.id = 'anonymous'
26
+ class Anonymous extends User { is(role) { return role === 'any' }}
27
+ Object.defineProperties (Anonymous.prototype, {
28
+ id: {value:'anonymous',writable:true},
29
+ roles: {value:{}},
30
+ attr: {value:{}},
31
+ _is_anonymous: {value:true},
32
+ })
31
33
 
32
34
  /**
33
35
  * Subclass for executing code with superuser privileges.
34
36
  */
35
- class Privileged extends User {
36
- constructor(_) { super(_||{}) }
37
- is() { return true }
38
- }
39
- Privileged.prototype._is_privileged = true
40
- Privileged.prototype.id = 'privileged'
37
+ class Privileged extends User { is(){ return true }}
38
+ Object.defineProperties (Privileged.prototype, {
39
+ id: {value:'privileged',writable:true},
40
+ roles: {value:{},writable:true},
41
+ attr: {value:{},writable:true},
42
+ _is_privileged: {value:true},
43
+ })
44
+
41
45
 
42
46
  // exports -----------------
43
- module.exports = exports = Object.assign (User, { Anonymous, Privileged, default:Anonymous })
47
+ module.exports = exports = Object.assign (User, {
48
+ Anonymous, anonymous : Object.seal (new Anonymous),
49
+ Privileged, privileged : Object.seal (new Privileged),
50
+ default: Anonymous,
51
+ })
@@ -1,12 +1,16 @@
1
1
  const cds = require('..'), { Event, Request } = cds
2
2
  const add_methods_to = require ('./Service-methods')
3
- const { unfold_csn: cds_localized } = cds.compile._localized
4
3
 
5
4
 
6
5
  class Service extends require('./Service-handlers') {
7
6
 
8
- constructor (name, model, o={}) {
9
- super (name || new.target.name) .options = o
7
+ constructor (name, model, o) {
8
+ if (is_object(name)) {
9
+ [ model, o ] = [ name, model ]
10
+ let srv = cds.linked(model).services[0] || cds.error.expected `${{arg0:name}} to be a CSN with a service definition`
11
+ name = srv.name
12
+ }
13
+ super (name || new.target.name) .options = o || (o={})
10
14
  if (o.kind) this.kind = o.kind // shortcut
11
15
  if (model) this.model = model
12
16
  }
@@ -27,7 +31,6 @@ class Service extends require('./Service-handlers') {
27
31
  * Messaging API to emit asynchronous event messages, i.e. instances of `cds.Event`.
28
32
  */
29
33
  emit (event, data, headers) {
30
- const res = this._compat_sync (event, data, headers); if (res) return res
31
34
  const eve = event instanceof Event ? event : new Event (
32
35
  is_object(event) ? event : { event, data, headers }
33
36
  )
@@ -43,11 +46,11 @@ class Service extends require('./Service-handlers') {
43
46
  )
44
47
  return this.dispatch (req)
45
48
  }
46
- get (path, data) { return is_rest(path) ? this.send('GET', path,data) : this.read (path, data) }
47
- put (path, data) { return is_rest(path) ? this.send('PUT', path,data) : this.update (path, data) }
48
- post (path, data) { return is_rest(path) ? this.send('POST', path,data) : this.create (path, data) }
49
- patch (path, data) { return is_rest(path) ? this.send('PATCH', path,data) : this.update (path, data) }
50
- delete (path, data) { return is_rest(path) ? this.send('DELETE',path,data) : DELETE.from (path, data).bind(this) }
49
+ get (...args) { return is_rest(args[0]) ? this.send('GET', ...args) : this.read (...args) }
50
+ put (...args) { return is_rest(args[0]) ? this.send('PUT', ...args) : this.update (...args) }
51
+ post (...args) { return is_rest(args[0]) ? this.send('POST', ...args) : this.create (...args) }
52
+ patch (...args) { return is_rest(args[0]) ? this.send('PATCH', ...args) : this.update (...args) }
53
+ delete (...args) { return is_rest(args[0]) ? this.send('DELETE',...args) : DELETE.from (...args).bind(this) }
51
54
 
52
55
  /**
53
56
  * Querying API to send synchronous requests...
@@ -94,8 +97,11 @@ class Service extends require('./Service-handlers') {
94
97
  /**
95
98
  * Subclasses may override this to free private resources
96
99
  */
97
- disconnect (tenant) { // eslint-disable-line no-unused-vars
98
- if (this === cds.db) cds.db = undefined //> REVISIT: should go into DatabaseService
100
+ disconnect (tenant) {
101
+ if (this === cds.db) {
102
+ if (tenant && cds.db.dbcs) cds.db.dbcs.delete[tenant]
103
+ else if (!tenant) cds.db = undefined //> REVISIT: should go into DatabaseService
104
+ }
99
105
  delete cds.services[this.name]
100
106
  }
101
107
 
@@ -105,7 +111,6 @@ const { dispatch, handle } = require('./Service-dispatch')
105
111
  Service.prototype.dispatch = dispatch
106
112
  Service.prototype.handle = handle
107
113
  Service.prototype.transaction = Service.prototype.tx = require('./Transaction')
108
- Service.prototype._compat_sync = require('./Service-compat')
109
114
  Service.prototype._implicit_next = cds.env.features.implicit_next
110
115
  Service.prototype._is_service_instance = Service._is_service_class = true //> for factory
111
116
  module.exports = Service
@@ -13,22 +13,18 @@ exports.dispatch = async function dispatch (req) { //NOSONAR
13
13
 
14
14
  // Ensure we are in a proper transaction
15
15
  if (!this.context) {
16
- const ctx = cds.context
17
- if (ctx && ctx._tx && !ctx._done) { // join outer context with a nested tx -> we don't modify outer context
18
- return this.tx(ctx).dispatch(req)
19
- } else { // start a new root tx for subsequent continuation
20
- return this.tx(tx => (cds.context=tx).dispatch(req))
21
- }
16
+ const gc = cds.context
17
+ if (gc && gc.tx && !gc.tx._done) return this.tx(gc).dispatch(req) // with nested tx
18
+ else return this.tx(tx => tx.dispatch(req)) // as root tx
22
19
  }
23
- // `this` is a tx from now on...
24
- if (!req._tx) req._tx = this
20
+ if (!req.tx) req.tx = this // `this` is a tx from now on...
25
21
 
26
22
  // Inform potential listeners // REVISIT: -> this should move into protocol adapters
27
23
  if (_is_root(req)) req._.req.emit ('dispatch',req)
28
24
 
29
25
  // Handle batches of queries
30
26
  if (_is_array(req.query))
31
- return Promise.all (req.query.map (q => this.dispatch ({query:q,__proto__:req})))
27
+ return Promise.all (req.query.map (q => this.dispatch ({query:q,__proto__:req,context:req})))
32
28
 
33
29
  // Ensure target and fqns
34
30
  if (!req.target) _ensure_target (this,req)
@@ -5,7 +5,8 @@ const LOG = cds.log('cds-app-service-methods')
5
5
  module.exports = (srv) => {
6
6
  if (!( //> we only support that for app services
7
7
  srv instanceof cds.ApplicationService ||
8
- srv instanceof cds.RemoteService
8
+ srv instanceof cds.RemoteService ||
9
+ srv._add_stub_methods
9
10
  )) return
10
11
  for (const each of srv.operations) {
11
12
  add_handler_for (srv, each)
@@ -73,12 +74,12 @@ const add_handler_for = (srv, def) => {
73
74
  if (req.data[k]) {
74
75
  LOG._warn && LOG.warn(`
75
76
  ${target.name} has defined ${k} as key and action parameter.
76
- Key will be used in req.data.
77
+ Key will be used in req.data.
77
78
  `)
78
79
  }
79
80
  req.data[k] = named ? req.params[0][k] : req.params[pos++]
80
81
  }
81
-
82
+
82
83
  }
83
84
 
84
85
  return this.send (req)