@sap/cds 5.9.6 → 6.0.1

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 +266 -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 +90 -53
  25. package/bin/build/provider/mtx/resourcesTarBuilder.js +68 -0
  26. package/bin/build/provider/mtx-sidecar/index.js +80 -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 +19 -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 +9 -10
  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 +56 -21
  37. package/bin/utils/log.js +13 -30
  38. package/bin/version.js +5 -4
  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 +11 -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 +70 -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 +23 -20
  86. package/lib/serve/index.js +51 -54
  87. package/lib/utils/axios.js +8 -12
  88. package/lib/utils/index.js +3 -3
  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 +128 -42
  106. package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +6 -3
  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 +10 -45
  109. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +5 -9
  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 +1 -1
  114. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +15 -21
  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 +100 -91
  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 +77 -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 +16 -18
  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 +15 -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 +11 -4
  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 +6 -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 +3 -7
  232. package/libx/_runtime/fiori/generic/index.js +31 -0
  233. package/libx/_runtime/fiori/generic/new.js +2 -4
  234. package/libx/_runtime/fiori/generic/patch.js +4 -8
  235. package/libx/_runtime/fiori/generic/prepare.js +2 -4
  236. package/libx/_runtime/fiori/generic/read.js +137 -162
  237. package/libx/_runtime/fiori/generic/readOverDraft.js +10 -4
  238. package/libx/_runtime/fiori/utils/handler.js +10 -5
  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 +11 -2
  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 +2 -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 +84 -46
  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 +261 -157
  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
@@ -1,152 +0,0 @@
1
- const Relation = require('./relation')
2
-
3
- const CommonFieldControl = e => {
4
- const cfr = e['@Common.FieldControl']
5
- return cfr && cfr['#']
6
- }
7
-
8
- const isMandatory = e => {
9
- return (
10
- e['@assert.mandatory'] !== false &&
11
- (e['@mandatory'] ||
12
- e['@Common.FieldControl.Mandatory'] ||
13
- e['@FieldControl.Mandatory'] ||
14
- CommonFieldControl(e) === 'Mandatory')
15
- )
16
- }
17
-
18
- const isReadOnly = e => {
19
- return (
20
- e['@readonly'] ||
21
- e['@cds.on.update'] ||
22
- e['@cds.on.insert'] ||
23
- e['@Core.Computed'] ||
24
- e['@Common.FieldControl.ReadOnly'] ||
25
- e['@FieldControl.ReadOnly'] ||
26
- CommonFieldControl(e) === 'ReadOnly'
27
- )
28
- }
29
-
30
- const getETag = entity => {
31
- let val
32
- for (const ele in entity.elements) {
33
- if (entity.elements[ele]['@odata.etag']) {
34
- val = ele
35
- break
36
- }
37
- }
38
- return val
39
- }
40
-
41
- const hasPersonalData = entity => {
42
- let val
43
- if (entity['@PersonalData.DataSubjectRole'] && entity['@PersonalData.EntitySemantics']) {
44
- for (const ele in entity.elements) {
45
- if (
46
- entity.elements[ele]['@PersonalData.IsPotentiallyPersonal'] ||
47
- entity.elements[ele]['@PersonalData.IsPotentiallySensitive'] ||
48
- (entity.elements[ele]['@PersonalData.FieldSemantics'] &&
49
- entity.elements[ele]['@PersonalData.FieldSemantics'] === 'DataSubjectID')
50
- ) {
51
- val = true
52
- break
53
- }
54
- }
55
- }
56
- return !!val
57
- }
58
-
59
- const hasSensitiveData = entity => {
60
- let val
61
- if (entity['@PersonalData.DataSubjectRole'] && entity['@PersonalData.EntitySemantics']) {
62
- for (const ele in entity.elements) {
63
- if (
64
- entity.elements[ele]['@PersonalData.IsPotentiallySensitive'] ||
65
- (entity.elements[ele]['@PersonalData.FieldSemantics'] &&
66
- entity.elements[ele]['@PersonalData.FieldSemantics'] === 'DataSubjectID')
67
- ) {
68
- val = true
69
- break
70
- }
71
- }
72
- }
73
- return !!val
74
- }
75
-
76
- const _exposeRelation = relation => Object.defineProperty({}, '_', { get: () => relation })
77
-
78
- const _relationHandler = relation => ({
79
- get: (target, name) => {
80
- const path = name.split(',')
81
- const prop = path.join('_')
82
- if (!target[prop]) {
83
- if (path.length === 1) {
84
- // REVISIT: property 'join' must not be used in CSN to make this working
85
- if (relation._has(prop)) return relation[prop]
86
- const newRelation = Relation.to(relation, prop)
87
- if (newRelation) {
88
- target[prop] = new Proxy(_exposeRelation(newRelation), _relationHandler(newRelation))
89
- }
90
- return target[prop]
91
- }
92
- target[prop] = path.reduce((r, p) => r[p] || r.csn._relations[p], relation)
93
- target[prop].path = path
94
- }
95
- return target[prop]
96
- }
97
- })
98
-
99
- const getRelations = e => {
100
- const newRelation = Relation.to(e)
101
- return new Proxy(_exposeRelation(newRelation), _relationHandler(newRelation))
102
- }
103
-
104
- const _hasJoinCondition = e => e.isAssociation && e.on && e.on.length > 2
105
-
106
- const _isSelfRef = e => e.ref && e.ref[0] === '$self'
107
-
108
- const _getBacklinkName = on => {
109
- const i = on.findIndex(_isSelfRef)
110
- if (i === -1) return
111
- let ref
112
- if (on[i + 1] && on[i + 1] === '=') ref = on[i + 2].ref
113
- if (on[i - 1] && on[i - 1] === '=') ref = on[i - 2].ref
114
- return ref && ref[ref.length - 1]
115
- }
116
-
117
- const isSelfManaged = e => {
118
- if (!_hasJoinCondition(e)) return
119
- return !!e.on.find(_isSelfRef)
120
- }
121
-
122
- const isBacklink = (e, checkComposition) => getAnchor(e, checkComposition) && true
123
-
124
- const _isUnManagedAssociation = (e, checkComposition) =>
125
- e.isAssociation && (!checkComposition || e._isCompositionEffective) && _hasJoinCondition(e)
126
-
127
- const getAnchor = (e, checkComposition) => {
128
- if (!(e._isAssociationStrict && (e.keys || e.on))) return
129
- for (const anchor of Object.values(e._target.associations || {})) {
130
- if (!_isUnManagedAssociation(anchor, checkComposition)) continue
131
- if (_getBacklinkName(anchor.on) === e.name && anchor.target === e.parent.name) return anchor
132
- }
133
- }
134
-
135
- const getBacklink = (e, checkComposition) => {
136
- if (!_isUnManagedAssociation(e, checkComposition)) return
137
- const backlinkName = _getBacklinkName(e.on)
138
- if (backlinkName) return e._target && e._target.elements && e._target.elements[backlinkName]
139
- }
140
-
141
- module.exports = {
142
- isMandatory,
143
- isReadOnly,
144
- getETag,
145
- hasPersonalData,
146
- hasSensitiveData,
147
- getRelations,
148
- isSelfManaged,
149
- isBacklink,
150
- getAnchor,
151
- getBacklink
152
- }
@@ -1,21 +0,0 @@
1
- /*
2
- * addition for feature toggles
3
- */
4
- module.exports = cds => {
5
- if (!cds.requires.toggles) return (req, res, next) => next()
6
-
7
- return (req, res, next) => {
8
- // inject features from dwc header
9
- const fth = req.headers['dwc-product-configuration']
10
- if (fth) {
11
- const { features } = JSON.parse(Buffer.from(fth, 'base64').toString('utf-8'))
12
- req.features = features
13
- .filter(f => f.enabled)
14
- .map(f => f.name)
15
- .sort((a, b) => a.localeCompare(b))
16
- Object.freeze(req.features)
17
- }
18
-
19
- next()
20
- }
21
- }
@@ -1,18 +0,0 @@
1
- const optionsApp = require('./vcap.js')
2
-
3
- const BASE_TENANT = 'anonymous'
4
-
5
- const channelName = () => {
6
- // REVISIT: Why so complicated?
7
-
8
- const appName = optionsApp.appName || 'CAP'
9
- const appID = optionsApp.appID || '00000000'
10
- const shrunkAppID = appID.substring(0, 4)
11
-
12
- return `${appName}/${shrunkAppID}`
13
- }
14
-
15
- module.exports = {
16
- BASE_TENANT,
17
- channelName
18
- }
@@ -1,5 +0,0 @@
1
- const cds = require('../../cds')
2
- if (cds.requires.db && !(cds.model && 'cds_r.ModelProviderService' in cds.model.definitions)) {
3
- const model = require('path').join(__dirname, '../../../..', 'srv/mps.cds')
4
- module.exports = cds.serve(model, { silent: true }).in(cds.app)
5
- }
@@ -1,111 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
-
4
- const cds = require('../../cds')
5
- const { exists } = require('./utils')
6
- const { supplementaryFiles } = require('./tar')
7
-
8
- const { BASE_TENANT } = require('../../common/utils/extensibilityUtils')
9
-
10
- const _getAllFeatures = async function () {
11
- const features = path.join(global.cds.root, 'fts')
12
- if (await exists(features)) {
13
- return (await fs.promises.readdir(features, { withFileTypes: true })).map(dir => path.join(features, dir.name))
14
- }
15
-
16
- return []
17
- }
18
-
19
- const _addExtensions = async function (csn, tenant) {
20
- const rs = await cds.tx({ tenant }, tx => tx.run(SELECT.from('cds_r.Extensions')))
21
-
22
- if (rs.length !== 0) {
23
- const extensions = []
24
- const definitions = {}
25
- rs.forEach(row => {
26
- const csn = JSON.parse(row.csn)
27
- if (csn.extensions) extensions.push(...csn.extensions)
28
- if (csn.definitions) {
29
- Object.keys(csn.definitions).forEach(key => {
30
- definitions[key] = csn.definitions[key]
31
- })
32
- }
33
- })
34
- const extCsn = cds.compile({
35
- 'base.csn': cds.compile.to.json(csn),
36
- 'ext.csn': cds.compile.to.json({ extensions, definitions })
37
- })
38
- // Sources are used to load resources like i18n
39
- extCsn.$sources = csn.$sources
40
- extCsn.$location = csn.$location
41
-
42
- return extCsn
43
- }
44
-
45
- return csn
46
- }
47
-
48
- const _isExtended = async function (req) {
49
- const rs = await cds.tx({ tenant: req.data.tenant }, tx => tx.run('SELECT * from cds_r_Extensions'))
50
- return rs.length !== 0
51
- }
52
-
53
- const _csn4 = async function (req, _flavor) {
54
- let { tenant, toggles, flavor = _flavor } = req.data
55
- if (!tenant) tenant = BASE_TENANT
56
-
57
- let features = []
58
- // Star is only for deployment - not a valid DwC protocol configuration.
59
- if (toggles && toggles.includes('*')) {
60
- features = await _getAllFeatures()
61
- } else if (toggles) {
62
- features = toggles.map(t => path.join(global.cds.root, 'fts', t))
63
- }
64
-
65
- let csn = await cds.load(['*', ...features]).then(cds.minify)
66
-
67
- if (cds.requires.extensibility && !(cds.requires.multitenancy && tenant === BASE_TENANT))
68
- csn = await _addExtensions(csn, tenant)
69
-
70
- if (flavor) csn = cds.compile.for[flavor](csn)
71
-
72
- return csn
73
- }
74
-
75
- const _edmx4 = async function (req) {
76
- const csn = await _csn4(req)
77
- const { serviceName, locale, odataFlavor } = req.data
78
-
79
- return cds.localize(csn, locale, cds.compile.to.edmx(csn, { service: serviceName, version: odataFlavor }))
80
- }
81
-
82
- module.exports = function (srv) {
83
- srv.on('getCsn', async function (req) {
84
- return await _csn4(req)
85
- })
86
-
87
- // REVISIT: Replace by getCsn(..., flavor=node/java)
88
- srv.on('getOdataCsn', async function (req) {
89
- return await _csn4(req, 'java')
90
- })
91
-
92
- srv.on('getEdmx', async function (req) {
93
- return await _edmx4(req)
94
- })
95
-
96
- srv.after('getEdmx', function (result, req, res) {
97
- req._.res && req._.res.set('Content-Type', 'application/xml')
98
- })
99
-
100
- srv.on('isExtended', async function (req) {
101
- return await _isExtended(req)
102
- })
103
-
104
- srv.on('getResources', async function (req) {
105
- return await supplementaryFiles(req)
106
- })
107
-
108
- srv.after('getResources', function (_, req) {
109
- req._.res && req._.res.set('content-type', 'application/octet-stream; charset=binary')
110
- })
111
- }
@@ -1,42 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const cds = require('../../cds')
4
- const { TAR_CLI, findCsvFiles, collectCsvFiles, packTarArchive } = require('../../../../lib/utils/resources')
5
- const { exists } = require('./utils')
6
-
7
- // REVISIT: resource folder and file to be defined
8
- const RESOURCE_FILE = 'to_be_defined/to_be_defined.tgz'
9
-
10
- const supplementaryFiles = async req => {
11
- // first look for files in the resource folder
12
- const resource = path.join(global.cds.root, RESOURCE_FILE)
13
- if (await exists(resource)) {
14
- return fs.promises.readFile(resource, 'binary')
15
- }
16
-
17
- // check if collected in sdc folder
18
- // REVISIT: to be deleted
19
- let files
20
- const sdc = path.join(global.cds.root, 'sdc')
21
- if (await exists(sdc)) {
22
- files = await findCsvFiles(sdc, true)
23
- }
24
-
25
- // if not collected, then collect
26
- if (!files || !files.length) {
27
- const features = (cds.env.features && cds.env.features.folders) || 'fts/*'
28
- const csn = await cds.load(['*', features])
29
- files = await collectCsvFiles(csn.$sources)
30
- }
31
-
32
- if (!files.length) {
33
- req.reject(404)
34
- }
35
-
36
- return await packTarArchive(files, global.cds.root, req.data.flat, TAR_CLI)
37
- }
38
-
39
- module.exports = {
40
- TAR_CLI,
41
- supplementaryFiles
42
- }
@@ -1,11 +0,0 @@
1
- const fs = require('fs')
2
-
3
- const exists = async fileOrDir => {
4
- try {
5
- return await fs.promises.stat(fileOrDir)
6
- } catch (_) {
7
- return false
8
- }
9
- }
10
-
11
- module.exports = { exists }
@@ -1,54 +0,0 @@
1
- module.exports = (async () => {
2
- const cds = require('../../cds')
3
- const path = require('path')
4
-
5
- if (!cds.requires.db) return
6
- if (cds.db) return // avoid duplicates
7
-
8
- // do not add extensions in case of multitenancy
9
- if (!cds.requires.multitenancy) {
10
- // add extensions
11
- if (cds.requires.db.credentials && cds.requires.db.credentials.database !== ':memory:') {
12
- const db = await cds.connect.to({ ...cds.requires.db, model: null, silent: true })
13
- const rs = await db.read('cds_r.Extensions')
14
- if (rs.length !== 0) {
15
- const extensions = []
16
- rs.forEach(row => extensions.push(...JSON.parse(row.csn).extensions))
17
- cds.once('loaded', csn => {
18
- if (cds.model) return // extend cds.model only
19
- const extended = cds.compile({
20
- 'base.csn': cds.compile.to.json(csn),
21
- 'ext.csn': cds.compile.to.json({ extensions })
22
- })
23
- csn.definitions = extended.definitions
24
- })
25
- }
26
- await db.disconnect()
27
- }
28
-
29
- cds.on('connect', async srv => {
30
- if (srv.name !== 'db') return
31
-
32
- // deploy in case of in-memory
33
- if (cds.requires.db.credentials && cds.requires.db.credentials.database === ':memory:') {
34
- const mf = await cds.load(path.join(__dirname, '../../../..', 'srv/flex.cds'))
35
- await cds.deploy(mf).to(srv)
36
- }
37
- })
38
- }
39
-
40
- cds.once('served', async () => {
41
- const { transformExtendedFieldsCREATE, transformExtendedFieldsUPDATE } = require('./handler/transformWRITE')
42
- const { transformExtendedFieldsREAD } = require('./handler/transformREAD')
43
- const { transformExtendedFieldsRESULT } = require('./handler/transformRESULT')
44
- cds.db
45
- .before('CREATE', transformExtendedFieldsCREATE)
46
- .before('UPDATE', transformExtendedFieldsUPDATE)
47
- .before('READ', transformExtendedFieldsREAD)
48
- .after('READ', transformExtendedFieldsRESULT)
49
- if ('cds_r.ExtensibilityService' in cds.services) return
50
- await require('../mps')
51
- const model = require('path').join(__dirname, '../../../..', 'srv/flex.cds')
52
- return cds.serve(model, { silent: true }).in(cds.app)
53
- })
54
- })()
@@ -1,276 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const cds = require('../../cds')
4
- const { ensureDraftsSuffix } = require('../../common/utils/draft')
5
- const { BASE_TENANT, channelName } = require('../../common/utils/extensibilityUtils')
6
- const { EXT_BACK_PACK } = require('./utils')
7
- const TMP_DIR = fs.realpathSync(require('os').tmpdir())
8
-
9
- const _getDraftTable = view => {
10
- return cds.model.definitions[view]._isDraftEnabled ? ensureDraftsSuffix(view) : undefined
11
- }
12
-
13
- const _addAnnotation = extension => {
14
- Object.values(extension.elements).forEach(el => {
15
- el['@cds.extension'] = true
16
- })
17
- }
18
-
19
- const _isProjection = target => target && target.query && target.query._target
20
-
21
- const _resolveViews = (target, views_ = []) => {
22
- if (_isProjection(target)) {
23
- views_.push(target)
24
- return _resolveViews(target.query._target, views_)
25
- }
26
-
27
- return target
28
- }
29
-
30
- const _getCsn = req => {
31
- const csn = {
32
- extensions: req.data.extensions.map(ext => JSON.parse(ext))
33
- }
34
-
35
- return csn
36
- }
37
-
38
- const _addViews = csn => {
39
- csn.extensions.forEach(extension => {
40
- const target = cds.model.definitions[extension.extend]
41
- const views_ = []
42
- const view = _resolveViews(target, views_)
43
- extension.extend = view && view.name
44
- _addAnnotation(extension)
45
-
46
- // All projection views leading to the db entity are extended with back pack in case view columns are explicitly listed.
47
- // The views using projections with '*' obtain the back pack automatically.
48
- views_.forEach(view => {
49
- if (!view.projection || (view.projection.columns && !view.projection.columns.some(col => col === '*'))) {
50
- csn.extensions.push({
51
- extend: view.name,
52
- columns: Object.keys(extension.elements).map(key => {
53
- return { ref: [key] }
54
- })
55
- })
56
- }
57
- })
58
- })
59
- }
60
-
61
- const _needsQuotations = t => t instanceof cds.builtin.classes.string || t instanceof cds.builtin.classes.date
62
-
63
- const _handleDefaults = async (extension, dbEntity, draftEntity) => {
64
- const ext = Object.keys(extension.elements)
65
- .filter(key => extension.elements[key].default)
66
- .map(key => {
67
- const element = extension.elements[key]
68
- // .type as ui flex extensions are not linked
69
- const t = cds.model.definitions[element.type] || cds.builtin.types[element.type]
70
- const value = t && _needsQuotations(t) ? `"${element.default.val}"` : element.default.val
71
- return `"${key}":${value}`
72
- })
73
-
74
- if (ext.length !== 0) {
75
- const extStr = ext.join(',')
76
- const changed = `'{${extStr},' || substr(${EXT_BACK_PACK}, 2, length(${EXT_BACK_PACK})-1)`
77
- const assign = `${EXT_BACK_PACK} = CASE WHEN ${EXT_BACK_PACK} IS NULL THEN '{${extStr}}' ELSE ${changed} END`
78
- await UPDATE(dbEntity).with(assign)
79
- if (draftEntity) await UPDATE(draftEntity).with(assign)
80
- }
81
- }
82
-
83
- const _validateCsn = (csn, req) => {
84
- if (!csn) req.reject(400, 'Missing extension')
85
- if (!csn.extensions) return
86
-
87
- csn.extensions.forEach(extension => {
88
- if (!extension.extend || !cds.model.definitions[extension.extend]) {
89
- req.reject(400, 'Invalid extension. Parameter "extend" missing or malformed')
90
- }
91
-
92
- if (!extension.elements) {
93
- req.reject(400, 'Invalid extension. Missing parameter "elements"')
94
- }
95
- })
96
- }
97
-
98
- const _validateExtensionFields = (csn, req) => {
99
- if (!csn.extensions) return
100
-
101
- csn.extensions.forEach(extension => {
102
- if (extension.elements) {
103
- Object.keys(extension.elements).forEach(name => {
104
- if (!/^[A-Za-z]\w*$/.test(name)) {
105
- req.reject(400, `Invalid extension. Bad element name "${name}"`)
106
- }
107
-
108
- if (Object.keys(cds.model.definitions[extension.extend].elements).includes(name)) {
109
- req.reject(400, `Invalid extension. Element "${name}" already exists`)
110
- }
111
- })
112
- }
113
- })
114
- }
115
-
116
- const _getCompilerError = messages => {
117
- const defaultMsg = 'Error while compiling extension'
118
- if (!messages) return defaultMsg
119
-
120
- for (const msg of messages) {
121
- if (msg.severity === 'Error') return msg.message
122
- }
123
-
124
- return defaultMsg
125
- }
126
-
127
- const _validateExtension = async (ext, req) => {
128
- try {
129
- const { 'cds_r.ModelProviderService': mps } = cds.services
130
- const csn = await mps.getCsn(req.tenant, ['*'])
131
- const extCsn = cds.compile.to.json(ext)
132
- await cds.compile.to.csn({ 'base.csn': JSON.stringify(csn), 'ext.csn': extCsn })
133
- } catch (err) {
134
- console.trace(err) // eslint-disable-line no-console
135
- req.reject(400, _getCompilerError(err.messages))
136
- }
137
- }
138
-
139
- const _addExtension = async function (req) {
140
- // validate extension
141
- const csn = _getCsn(req)
142
- _validateCsn(csn, req)
143
- await _validateExtensionFields(csn, req)
144
- _addViews(csn, cds)
145
- await _validateExtension(csn, req)
146
-
147
- // save extension
148
- const ID = cds.utils.uuid()
149
- await INSERT.into('cds_r.Extensions').entries([{ ID, csn: JSON.stringify(csn), activated: false }])
150
-
151
- // defaults
152
- for (const ext of req.data.extensions) {
153
- const extension = JSON.parse(ext)
154
- const draft = _getDraftTable(extension.extend)
155
- const target = cds.model.definitions[extension.extend]
156
- const dbEntity = _resolveViews(target).name
157
- await _handleDefaults(extension, dbEntity, draft)
158
- }
159
-
160
- // update event
161
- await this.redis.emit(channelName(), { tenant: req.tenant || BASE_TENANT })
162
- }
163
-
164
- const _activate = async function (req) {
165
- // get extensions
166
- const rs = await cds.tx({ tenant: req.tenant }, tx => tx.run(SELECT.from('cds_r.Extensions')))
167
- rs.forEach(row => {
168
- row.csn = row.csn.replace(/,"@cds.extension":true/g, '')
169
- row.activated = true
170
- })
171
-
172
- // activate
173
- const { MultitenancyService: mts } = cds.services
174
- await mts.activateExtensions(req.data.tenant)
175
-
176
- // restore extensions
177
- await INSERT.into('cds_r.Extensions').entries(rs)
178
-
179
- // update event
180
- await this.redis.emit(channelName(), { tenant: req.tenant || BASE_TENANT })
181
- }
182
-
183
- const _exists = async fileOrDir => {
184
- try {
185
- return await fs.promises.stat(fileOrDir)
186
- } catch (_) {
187
- return false
188
- }
189
- }
190
-
191
- const _compileProject = async function (extension, req) {
192
- let csn, root
193
- try {
194
- root = await fs.promises.mkdtemp(`${TMP_DIR}${path.sep}extension-`)
195
- const files = []
196
- for (const ext of extension) {
197
- if (ext.filename.indexOf('/') > -1) {
198
- await fs.promises.mkdir(path.join(root, path.dirname(ext.filename)), { recursive: true })
199
- }
200
- const file = path.join(root, ext.filename)
201
- await fs.promises.writeFile(file, ext.model)
202
- files.push(file)
203
- }
204
- csn = await cds.compile(files, { flavor: 'parsed' })
205
- if (csn.requires) delete csn.requires
206
- } catch (err) {
207
- // req.reject(400, _getCompilerError(err.messages))
208
- if (err.messages) req.reject(400, _getCompilerError(err.messages))
209
- else {
210
- // eslint-disable-next-line no-console
211
- console.error(err)
212
- throw err
213
- }
214
- } finally {
215
- if (await _exists(root)) {
216
- await (fs.promises.rm || fs.promises.rmdir)(root, { recursive: true, force: true })
217
- }
218
- }
219
-
220
- return csn
221
- }
222
-
223
- const _activateProject = async function (req) {
224
- if (req.data.extension.length === 0) return
225
-
226
- const csn = await _compileProject(req.data.extension, req)
227
- await _validateExtension(csn, req)
228
-
229
- // keep only extension to be activated
230
- const ID = cds.utils.uuid()
231
- let activated, notActivated
232
- await cds.tx({ tenant: req.tenant }, async tx => {
233
- activated = await tx.run(SELECT.from('cds_r.Extensions').where({ activated: true }))
234
- notActivated = await tx.run(SELECT.from('cds_r.Extensions').where({ activated: false }))
235
- await tx.run(DELETE.from('cds_r.Extensions').where({ activated: false }))
236
- await tx.run(INSERT.into('cds_r.Extensions').entries([{ ID, csn: JSON.stringify(csn), activated: false }]))
237
- })
238
-
239
- // activate
240
- const { MultitenancyService: mts } = cds.services
241
- await mts.activateExtensions(req.data.tenant)
242
-
243
- // restore extensions
244
- await cds.tx({ tenant: req.tenant }, async tx => {
245
- const inserted = await tx.run(SELECT.from('cds_r.Extensions').where({ ID }))
246
- if (!inserted.length) {
247
- if (activated.length !== 0) await tx.run(INSERT.into('cds_r.Extensions').entries(activated))
248
- await tx.run(INSERT.into('cds_r.Extensions').entries([{ ID, csn: JSON.stringify(csn), activated: true }]))
249
- }
250
- if (notActivated.length !== 0) await tx.run(INSERT.into('cds_r.Extensions').entries(notActivated))
251
- })
252
-
253
- // default values for not activated extensions
254
- for (const na of notActivated) {
255
- for (const extension of JSON.parse(na.csn).extensions) {
256
- const target = cds.model.definitions[extension.extend]
257
- const dbEntity = _resolveViews(target).name
258
-
259
- // only db entities
260
- if (target.name !== dbEntity) continue
261
-
262
- const draft = _getDraftTable(extension.extend)
263
- await _handleDefaults(extension, dbEntity, draft)
264
- }
265
- }
266
-
267
- // update event
268
- await this.redis.emit(channelName(), { tenant: req.tenant || BASE_TENANT })
269
- }
270
-
271
- module.exports = async function () {
272
- this.redis = await cds.connect.to('mtx-messaging')
273
- this.on('addExtension', _addExtension)
274
- this.on('activate', _activate)
275
- this.on('activateProject', _activateProject)
276
- }