@sap/cds 5.9.7 → 6.0.2

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 +267 -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 +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 +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 +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 +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 +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 +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 +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 +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
@@ -2,7 +2,6 @@ const cds = require('../index'), { cds_tx_protection } = cds.env.features
2
2
  const EventContext = require('../req/context')
3
3
  class RootContext extends EventContext {}
4
4
 
5
-
6
5
  /**
7
6
  * This is the implementation of the `srv.tx(req)` method. It constructs
8
7
  * a new Transaction as a derivate of the `srv` (i.e. {__proto__:srv})
@@ -16,23 +15,27 @@ module.exports = function tx (ctx,fn) { const srv = this
16
15
  // Last arg may be a function -> srv.tx (tx => { ... })
17
16
  if (typeof ctx === 'function') [ ctx, fn ] = [ undefined, ctx ]
18
17
  if (typeof fn === 'function') {
19
- const tx = srv.tx(ctx)
20
- return Promise.resolve(tx).then(fn) .then (tx.commit,tx.rollback)
18
+ const tx = srv.tx(ctx), fx = ()=> Promise.resolve(fn(tx)).then(tx.commit,tx.rollback)
19
+ const gc = cds.context, _has_tx = gc && gc.tx && !gc.tx._done
20
+ return _has_tx ? fx() : cds._context.run(tx,fx)
21
21
  }
22
22
 
23
- // This is for compatibility with cds.tx(req)
24
- if (ctx instanceof EventContext) {
25
- if (ctx.context !== ctx) return NestedTransaction.for (srv, ctx.context)
26
- if (ctx._tx) return NestedTransaction.for (srv, ctx)
27
- else return RootTransaction.for (srv, ctx)
28
- }
23
+ if (ctx) {
24
+ if (ctx.context) ctx = ctx.context
29
25
 
30
- // `ctx` is a plain context object or undefined
31
- if (ctx) { // REVISIT: This is for compatibility with AFC only
26
+ // REVISIT: This is for compatibility with former srv.tx(req) usages
27
+ if (ctx instanceof EventContext) {
28
+ if (ctx.tx) return NestedTransaction.for (srv, ctx)
29
+ else return RootTransaction.for (srv, ctx)
30
+ }
31
+
32
+ // REVISIT: This is for compatibility with AFC only
32
33
  if (ctx._txed_before) return NestedTransaction.for (srv, ctx._txed_before)
33
- else Object.defineProperty(ctx, '_txed_before', { value: RootContext.for(ctx) }) // > must be non-enumerable
34
- return RootTransaction.for (srv, ctx._txed_before)
34
+ else Object.defineProperty(ctx, '_txed_before', { value: ctx = RootContext.for(ctx) })
35
+ return RootTransaction.for (srv, ctx)
35
36
  }
37
+
38
+ // `ctx` is a plain context object or undefined
36
39
  return RootTransaction.for (srv, RootContext.for(ctx))
37
40
  }
38
41
 
@@ -51,11 +54,11 @@ class Transaction {
51
54
  }
52
55
 
53
56
  constructor (srv,root) {
54
- const tx = _init ({ __proto__:srv, context:root })
57
+ const tx = { __proto__:srv, context:root }
55
58
  const proto = new.target.prototype
56
59
  tx.commit = proto.commit.bind(tx)
57
60
  tx.rollback = proto.rollback.bind(tx)
58
- return tx
61
+ return _init(tx)
59
62
  }
60
63
 
61
64
  /**
@@ -103,7 +106,7 @@ class RootTransaction extends Transaction {
103
106
  * @param {EventContext} root
104
107
  */
105
108
  static for (srv,root) {
106
- return root._tx = super.for (srv,root)
109
+ return root.tx = super.for (srv,root)
107
110
  }
108
111
 
109
112
  /**
@@ -111,7 +114,7 @@ class RootTransaction extends Transaction {
111
114
  * are informed by emitting 'succeeded' event to them all.
112
115
  */
113
116
  async commit (res) {
114
- if (cds_tx_protection) this.context._done = 'committed'
117
+ if (cds_tx_protection) this._done = 'committed'
115
118
  try {
116
119
  await this.context.emit ('commit',res) //> allow custom handlers req.before('commit')
117
120
  await super.commit (res)
@@ -131,7 +134,7 @@ class RootTransaction extends Transaction {
131
134
  // nothing to do if transaction already rolled back (we need to check here as well to not emit failed twice)
132
135
  if (this.ready === 'rolled back') return
133
136
 
134
- if (cds_tx_protection) this.context._done = 'rolled back'
137
+ if (cds_tx_protection) this._done = 'rolled back'
135
138
  try {
136
139
  await this.context.emit ('failed',err)
137
140
  await super.rollback (err)
@@ -172,11 +175,11 @@ const _init = (tx) => {
172
175
  const _begin = async function (req) {
173
176
  if (!req.query && req.method === 'BEGIN') // IMPORTANT: !req.query is to exclude batch requests
174
177
  return this.ready = this.__proto__.dispatch.call (this,req)
175
- // Protection against unintended tx.run() after tx.commit/rollback()
176
- if (typeof this.ready === 'string' || !this.ready && this.context._done) {
178
+ // Protection against unintended tx.run() after root tx.commit/rollback()
179
+ if (typeof this.ready === 'string' || !this.ready && this.context.tx._done) {
177
180
  if (!cds_tx_protection) this.ready = this.begin() // compatibiliy to former behavior, which allowed tx.run() after commit/rollback
178
181
  else throw cds.error (
179
- `Transaction is ${this.ready || this.context._done}, no subsequent .run allowed, without prior .begin`,
182
+ `Transaction is ${this.ready || this.context.tx._done}, no subsequent .run allowed, without prior .begin`,
180
183
  { code: 'TRANSACTION_CLOSED' }
181
184
  )
182
185
  }
@@ -1,18 +1,18 @@
1
1
  const lib = require('../../libx/_runtime')
2
+ const cds = require('../index')
2
3
  const registry = {
3
- get rest() { return lib.to.old_rest },
4
- get new_rest() { return lib.to.new_rest },
4
+ get rest() { return lib.to.rest },
5
5
  get odata() { return lib.to.odata_v4 },
6
6
  get odata_v2() { return lib.to.odata_v4 },
7
7
  get odata_v4() { return lib.to.odata_v4 },
8
8
  get fiori() { return lib.to.odata_v4 },
9
+ none: ()=>{}
9
10
  }
10
11
 
11
12
 
12
13
  class ProtocolAdapter {
13
14
 
14
15
  static at (protocol) {
15
- if (protocol === 'rest' && global.cds.env.features.rest_new_adapter) protocol = 'new_rest'
16
16
  const factory = registry[protocol]; if (factory) return factory
17
17
  else throw new Error (`Service protocol ${protocol} is not supported`)
18
18
  }
@@ -33,10 +33,20 @@ class ProtocolAdapter {
33
33
  * Mounts the adapter to an express app.
34
34
  */
35
35
  in (app, at) {
36
+ const LOG = cds.log(), DEBUG = cds.debug('server')
36
37
  const srv = this.service, path = at || srv.path
37
- lib.perf (app)
38
- lib.auth (srv, app, srv.options)
39
38
  app.use (path+'/webapp/', (_,res)=> res.sendStatus(404))
39
+ lib.auth (srv, app, srv.options)
40
+ lib.perf (app)
41
+ app.use (path, (req,_,next) => {
42
+ if (req.user?.tenant && !cds.context?.tenant) cds.context = { user: req.user } // REVISIT: should move to auth middleware
43
+ LOG && LOG (req.method, decodeURI(req.originalUrl), req.body||'')
44
+ if (/\$batch/.test(req.url)) req.on ('dispatch', (req) => {
45
+ LOG && LOG ('>', req.event, decodeURI(req._path), req._query||'')
46
+ if (DEBUG && req.query) DEBUG (req.query)
47
+ })
48
+ next()
49
+ })
40
50
  app.use (path, this)
41
51
  return srv
42
52
  }
@@ -1,3 +1,4 @@
1
+ const { pathToFileURL } = require('url') // on Windows, must use a file: URL for ESM import
1
2
  const cds = require('..'), { path, isfile } = cds.utils
2
3
  const paths = Array.from (new Set ([ cds.root, ...require.resolve.paths('x') ]))
3
4
  const DEBUG = cds.debug('srv.factory'); DEBUG && DEBUG ({ 'cds.root':cds.root, paths })
@@ -5,9 +6,10 @@ const DEBUG = cds.debug('srv.factory'); DEBUG && DEBUG ({ 'cds.root':cds.root, p
5
6
  /** @typedef {import('./Service-api')} Service @type { (()=>Service) & (new()=>Service) } */
6
7
  const ServiceFactory = function (name, model, options) { //NOSONAR
7
8
 
8
- const o = {...options} // avoid changing shared options
9
- const serve = !cds.requires[name] || o.mocked
10
- const defs = !model ? {[name]:{}} : model.definitions || cds.error (`Invalid argument for 'model': ${model}`)
9
+ const o = { ...options } // avoid changing shared options
10
+ const conf = cds.requires[name]
11
+ const serve = !(conf && conf.external && (!o.mocked || conf.credentials))
12
+ const defs = !model ? {[name]:{}} : model.definitions || cds.error `Invalid argument for 'model': ${model}`
11
13
  const def = !name || name === 'db' ? {} : defs[name] || {}
12
14
  DEBUG && DEBUG ({ name, definition:def, options:o })
13
15
 
@@ -18,21 +20,21 @@ const ServiceFactory = function (name, model, options) { //NOSONAR
18
20
  if (it = o.impl) return _use (it) // from cds.connect (<options>)
19
21
  return _use (_required())
20
22
 
21
- function _use (it) {
23
+ async function _use (it) {
22
24
  if (it._is_service_class) return new it (name,model,o)
23
25
  if (it._is_service_instance) return it
24
- if (typeof it === 'function') return _use (_required(), /*with:*/ o.impl = _function(it)) // NOSONAR
25
- if (typeof it === 'object') return _use (it && it[name] || _required())
26
- if (typeof it === 'string') return Object.assign (_use (_require(it,def)), {_source:it})
27
- throw cds.error (`Invalid service implementation for ${name}: ${it}`)
26
+ if (typeof it === 'function') return _use (await _required(), /*with:*/ o.impl = _function(it)) // NOSONAR
27
+ if (typeof it === 'object') return _use (it[name] || it.default || await _required())
28
+ if (typeof it === 'string') return Object.assign (await _use (await _require(it,def)), {_source:it})
29
+ throw cds.error `Invalid service implementation for ${name}: ${it}`
28
30
  }
29
31
 
30
32
  function _required() {
31
33
  const kind = o.kind = serve && def['@kind'] || o.kind || 'app-service'
32
34
  if (_require[kind]) return _require[kind]
33
- const {impl} = cds.requires[kind] || cds.error (`No configuration found for 'cds.requires.${kind}'`)
35
+ const {impl} = cds.requires[kind] || cds.requires.kinds[kind] || cds.error `No configuration found for 'cds.requires.${kind}'`
34
36
  DEBUG && DEBUG ('requires',{kind,impl})
35
- return _require[kind] = _require (impl || cds.error (`No 'impl' configured for 'cds.requires.${kind}'`))
37
+ return _require[kind] = _require (impl || cds.error `No 'impl' configured for 'cds.requires.${kind}'`)
36
38
  }
37
39
  }
38
40
 
@@ -41,13 +43,12 @@ const _require = (it,d) => {
41
43
  if (it.startsWith('@sap/cds/')) it = cds.home + it.slice(8) //> for local tests in @sap/cds dev
42
44
  if (it.startsWith('./')) it = _relative (d,it.slice(2)) //> relative to <service>.cds
43
45
  try { var resolved = require.resolve(it,{paths}) } catch(e) {
44
- try { resolved = require.resolve(it = path.resolve(cds.root,it)) } catch(e) { // for compatibility
45
- DEBUG && DEBUG (`Failed loading service implementation from '${it}'`, { 'cds.root':cds.root, paths })
46
- throw cds.error(`Failed loading service implementation from '${it}'`)
46
+ try { resolved = require.resolve(path.join(cds.root,it)) } catch(e) { // compatibility
47
+ throw cds.error `Failed loading service implementation from '${it}' ${{ Reason:e, paths, 'cds.root':cds.root }}`
47
48
  }
48
49
  }
49
50
  DEBUG && DEBUG({resolved})
50
- return require(resolved)
51
+ return typeof jest !== 'undefined' ? require(resolved) : import(pathToFileURL(resolved).href)
51
52
  }
52
53
 
53
54
  const _function = (impl) => !_is_class(impl) ? impl : (srv) => {
@@ -58,12 +59,9 @@ const _function = (impl) => !_is_class(impl) ? impl : (srv) => {
58
59
  }
59
60
 
60
61
  const sibling = (d) => {
61
- const src = _source(d), home = path.resolve(cds.root,src,'..')
62
- const file = path.parse(src).name
63
- for (let each of ['', './lib', './handlers']) {
64
- let found
65
- if (process.env.CDS_TYPESCRIPT === 'true') found = isfile(path.join(home, each, file + '.ts'))
66
- if (!found) found = isfile(path.join(home, each, file + '.js'))
62
+ const { dir, name } = path.parse(_source(d)), TS = process.env.CDS_TYPESCRIPT
63
+ for (let subdir of ['', './lib', './handlers']) {
64
+ let found = TS && _resolve(dir,subdir,name+'.ts') || _resolve(dir,subdir,name+'.js')
67
65
  if (found) return found //> equiv to '.'+found.slice(home.length)
68
66
  }
69
67
  }
@@ -71,6 +69,11 @@ const sibling = (d) => {
71
69
  // Note: @source has precedence over $location for csn.json cases
72
70
  const _source = (d) => d['@source'] || (d['@source'] = d.$location && d.$location.file.replace(/\\/g, '/') || '.')
73
71
  const _relative = (d,x,cwd=cds.root) => typeof x !== 'string' ? x : path.resolve (cwd, _source(d),'..',x)
72
+ const _resolve = (...args) => {
73
+ const f = path.join(...args)
74
+ try { return require.resolve(f) }
75
+ catch(e) { if (e.code === 'MODULE_NOT_FOUND') return isfile(path.resolve(cds.root,f)); else throw e }
76
+ }
74
77
  const _is_class = (impl) => typeof impl === 'function' && impl.prototype && /^class\b/.test(impl)
75
78
 
76
79
  module.exports = Object.assign (ServiceFactory, { Service: ServiceFactory, resolve:_relative })
@@ -4,9 +4,9 @@ const { Service } = cds.service.factory
4
4
  const _ready = Symbol(), _pending = cds.services._pending || {}
5
5
 
6
6
  /** @param som - a service name or a model (name or csn) */
7
- function cds_serve (som, _options) { // NOSONAR
7
+ module.exports = function cds_serve (som, _options) { // NOSONAR
8
8
 
9
- if (som && typeof som === 'object' && !is_csn(som)) {
9
+ if (som && typeof som === 'object' && !is_csn(som) && !is_files(som)) {
10
10
  [som,_options] = [undefined,
11
11
  som._is_service_instance ? { service:som, from:'*' } :
12
12
  som._is_service_class ? { service:som, from:'*' } :
@@ -16,35 +16,27 @@ function cds_serve (som, _options) { // NOSONAR
16
16
  else if (Array.isArray(som) && som.length === 1) som = som[0]
17
17
  const o = {..._options} // we must not modify inbound data
18
18
 
19
- // 1) Use fluent API to fill in remaining options...
20
- const fluent = {
21
- from (model) { o.from = model; return this },
22
- with (impl) { o.with = impl; return this },
23
- at (path) { o.at = path; return this },
24
- to (protocol) { o.to = protocol; return this },
25
- }
26
-
27
- // 2) Ensure options are filled in canonically based on defaults
19
+ // Ensure options are filled in canonically based on defaults
28
20
  const options = Promise.resolve(o).then (o => { // noformat
29
21
  if (o.service) { o.from ||( o.from = som); return o }
30
22
  if (o.from) { o.service ||( o.service = som); return o }
31
23
  if (som === 'all') { o.service ='all'; o.from = '*' ; return o }
32
24
  if (is_csn(som)) { o.service ='all'; o.from = som ; return o }
33
- if (is_file(som)) { o.service ='all'; o.from = som ; return o }
25
+ if (is_files(som)) { o.service ='all'; o.from = som ; return o }
34
26
  if (is_class(som)) { o.service = som; o.from = '?' ; return o }
35
27
  else { o.service = som; o.from = '*' ; return o }
36
28
  })
37
29
 
38
- // 3) Load/resolve the model asynchronously...
30
+ // Load/resolve the model asynchronously...
39
31
  const loaded = options.then (async ({from}=o) => {
40
32
  if (!from || from === 'all' || from === '*') from = cds.model || '*'
41
33
  if (from.definitions) return from
42
34
  if (from === '?') try { return await cds.load('*',o) } catch(e){ return }
43
- return cds.load(from,o)
35
+ return cds.load(from, {...o, silent:true })
44
36
  })
45
37
 
46
- // 4) Pass 1: Construct service provider instances...
47
- const all=[], provided = loaded.then (csn => { // NOSONAR
38
+ // Pass 1: Construct service provider instances...
39
+ const all=[], provided = loaded.then (async csn => { // NOSONAR
48
40
 
49
41
  // Shortcut for directly passed service instances
50
42
  if (o.service && o.service._is_service_instance) {
@@ -54,7 +46,7 @@ function cds_serve (som, _options) { // NOSONAR
54
46
  // Shortcut for directly passed service classes
55
47
  if (o.service && o.service._is_service_class) {
56
48
  const Service = o.service, d = { name: o.service.name }
57
- const srv = _new (Service, d,csn,o)
49
+ const srv = await _new (Service, d,csn,o)
58
50
  return all.push (srv)
59
51
  }
60
52
 
@@ -71,17 +63,17 @@ function cds_serve (som, _options) { // NOSONAR
71
63
  // skip all services marked to be ignored
72
64
  d['@cds.ignore'] || d['@cds.serve.ignore'] ||
73
65
  // skip external services, unless asked to mock them and unbound
74
- required[d.name] && (!o.mocked || required[d.name].credentials)
66
+ d['@cds.external'] || required[d.name]?.external && (!o.mocked || required[d.name].credentials)
75
67
  ))
76
68
  if (services.length > 1 && o.at) {
77
69
  throw cds.error `You cannot specify 'path' for multiple services`
78
70
  }
79
71
 
80
72
  // Construct service instances and register them to cds.services
81
- all.push (...services.map (d => _new (Service,d,csn,o)))
73
+ all.push (... await Promise.all (services.map (d => _new (Service,d,csn,o))))
82
74
  })
83
75
 
84
- // 5) Pass 2: Finalize service bootstrapping by calling their impl functions.
76
+ // Pass 2: Finalize service bootstrapping by calling their impl functions.
85
77
  // Note: doing that in a second pass guarantees all own services are in
86
78
  // cds.services, so they'll be found when they cds.connect to each others.
87
79
  let ready = provided.then (()=> Promise.all (all.map (async srv => {
@@ -95,61 +87,66 @@ function cds_serve (som, _options) { // NOSONAR
95
87
  })))
96
88
 
97
89
 
98
- // 6) Fluent method to serve constructed providers to express app
99
- fluent.in = (app) => {
100
- ready = ready.then (()=>{
101
- const edms = {}
102
- if (cds.env.features.precompile_edms) { // > unofficial config for eval
103
- const all = cds.compile.to.edm(cds.model, { service: 'all' })
104
- for (let [edm,{ file }] of all) edms[file] = edm
105
- }
90
+ // Return fluent API to fill in remaining options...
91
+ return {
106
92
 
107
- for (let each of all) {
108
- each._edm = edms[each.name]
93
+ from (model) { o.from = model; return this },
94
+ with (impl) { o.with = impl; return this },
95
+ at (path) { o.at = path; return this },
96
+ to (protocol) { o.to = protocol; return this },
97
+
98
+ /** Fluent method to serve constructed providers to express app */
99
+ in (app) {
100
+ ready = ready.then (()=> all.forEach (each => {
101
+ const d = each.definition
102
+ if (d['@protocol'] === 'none' || d['@cds.api.ignore']) return each._is_dark = true
109
103
  ProtocolAdapter.serve(each,o.to).in(app)
110
104
  if (!o.silent) cds.emit ('serving',each)
105
+ }))
106
+ return this
107
+ },
108
+
109
+ /** Finally resolve to a single picked provider or a map of all */
110
+ then: (resolve, failed) => ready.then (()=>{
111
+ if (all.length === 0) return resolve()
112
+ let response={}
113
+ for (let each of all) {
114
+ response[each.name] = each._is_dark || !each.definition ? each : ProtocolAdapter.serve(each,o.to).asRouter()
111
115
  }
112
- })
113
- return fluent
114
- }
115
-
116
- // 7) Finally resolve to a single picked provider or a map of all
117
- fluent.then = (resolve, failed) => ready.then (()=>{
118
- if (all.length === 0) return resolve()
119
- let response={}
120
- for (let each of all) {
121
- response[each.name] = !each.definition ? each : ProtocolAdapter.serve(each,o.to).asRouter()
122
- }
123
- if (all.length === 1 && all[0].name.endsWith (o.service)) {
124
- response = Object.assign (all[0], response)
125
- }
126
- return resolve (response)
127
- }, failed)
128
- fluent.catch = (e) => ready.catch(e)
116
+ if (all.length === 1) {
117
+ response = Object.assign (all[0], response)
118
+ }
119
+ return resolve (response)
120
+ }, failed),
129
121
 
130
- return fluent
122
+ catch: (e) => ready.catch(e)
123
+ }
131
124
  }
132
125
 
133
126
 
134
- function _new (Service, d,m,o) {
135
- const srv = new Service (d.name,m,o)
127
+ async function _new (Service, d,m,o) {
128
+ const srv = await new Service (d.name,m,o)
136
129
  const required = cds.requires[d.name]
137
130
  if (required) {
131
+ // Object.assign (srv.options, required)
138
132
  if (required.name) srv.name = required.name
139
- if (o.mocked) srv.mocked = true
133
+ if (required.external && o.mocked) srv.mocked = true
140
134
  }
141
135
  if (!srv.path) srv.path = cds.service.path4(srv,o.at)
142
136
  _pending[srv.name] = new Promise (r => srv[_ready]=r).finally(()=>{
143
137
  delete _pending[srv.name]
144
138
  delete srv[_ready]
139
+ if (srv.mocked) {
140
+ let service = cds.env.requires[srv.name]?.service
141
+ if (service && !cds.services[service]) Object.defineProperty (cds.services, service, {value:srv})
142
+ }
145
143
  })
146
144
  return srv
147
145
  }
148
146
 
149
147
 
150
148
  const is_csn = x => x && x.definitions
151
- const is_file = x => typeof x === 'string' && !/^[\w$]*$/.test(x)
149
+ const is_files = x => Array.isArray(x) || typeof x === 'string' && !/^[\w$]*$/.test(x)
152
150
  const is_class = x => typeof x === 'function' && x.prototype && /^class\b/.test(x)
153
151
 
154
- Object.defineProperty (cds_serve, 'path4', { get(){ return cds.service.path4 } })
155
- module.exports = cds_serve
152
+ Object.defineProperty (module.exports, 'path4', { get(){ return cds.service.path4 } })
@@ -36,18 +36,14 @@ const _args = (args) => {
36
36
  }
37
37
 
38
38
  const _error = (e) => {
39
- if (e.code === 'ECONNREFUSED' && e.port === 80 /*unchanged default port*/) {
40
- // retain original error properties (code,...)
41
- e = Object.assign(new Error(e.message +
42
- '\nIt seems that the server was not started. Make sure to call \'cds.test(...)\' or \'cds.test.run(...)\'.'),e)
43
- e.stack = null // stack is just clutter here
44
- throw e
45
- }
46
- if (!e.response) throw e
47
- if (!e.response.data) throw e
48
- if (!e.response.data.error) throw new Error(e.message + '\n\n' + JSON.stringify(e.response.data, null, 2))
49
- const { code, message } = e.response.data.error
50
- throw new Error (code && code !== 'null' ? `${code} - ${message}` : message)
39
+ Error.captureStackTrace (e,_error) //> adds the stack trace from caller code
40
+ if (e.code === 'ECONNREFUSED' && e.port === 80 /* default port */) throw Object.assign (e, {
41
+ message: e.message + '\nIt seems that the server was not started. Make sure to call \'cds.test(...)\' or \'cds.test.run(...)\'.',
42
+ stack: null // stack is just clutter here
43
+ })
44
+ const { code, message } = e.response && e.response.data && e.response.data.error || {}
45
+ if (message) e.message = code && code !== 'null' ? `${code} - ${message}` : message
46
+ throw e
51
47
  }
52
48
 
53
49
  const _ = Axios.prototype // eslint-disable-line no-unused-vars
@@ -1,7 +1,7 @@
1
1
  const cwd = process.env._original_cwd || process.cwd()
2
2
  const path = require ('path'), { dirname, join, resolve, sep, relative } = path
3
3
  const fs = require('fs')
4
- const cds = global.cds
4
+ const cds = require('../index')
5
5
 
6
6
  const all = module.exports = exports = { ...fs,
7
7
  get inspect() { return $set (this, 'inspect', require('util').inspect) },
@@ -11,7 +11,7 @@ const all = module.exports = exports = { ...fs,
11
11
  exports.fs = all
12
12
  exports.path = path
13
13
 
14
- exports.local = (file) => '.' + sep + relative(cwd,file)
14
+ exports.local = (file) => relative(cwd,file)
15
15
 
16
16
  exports.readdir = async function (x) {
17
17
  const d = resolve (cds.root,x)
@@ -92,7 +92,7 @@ exports.copy = async function copy (x,y) {
92
92
  const entries = await fs.promises.readdir(src)
93
93
  return Promise.all (entries.map (async each => {
94
94
  const e = join (src,each)
95
- const f = join (src,each)
95
+ const f = join (dst,each)
96
96
  return copy (e,f)
97
97
  }))
98
98
  } else {
@@ -6,48 +6,8 @@ const { packArchive, packArchiveCLI, unpackArchive, unpackArchiveCLI } = require
6
6
  const { exists } = require('./utils')
7
7
 
8
8
  // use tar command line interface
9
- const TAR_CLI = true
10
9
  const TEMP_DIR = fs.realpathSync(require('os').tmpdir())
11
10
 
12
- const findCsvFiles = async (folder, deep = false) => {
13
- const files = await fs.promises.readdir(folder)
14
- const result = []
15
-
16
- for (const file of files) {
17
- const filePath = path.join(folder, file)
18
- if (deep && (await fs.promises.stat(filePath)).isDirectory()) {
19
- const files = await findCsvFiles(filePath)
20
- result.push(...files)
21
- } else {
22
- if (path.extname(file) === '.csv') {
23
- result.push(filePath)
24
- }
25
- }
26
- }
27
-
28
- return result
29
- }
30
-
31
- const collectCsvFiles = async sources => {
32
- const folders = sources.map(file => path.dirname(file))
33
- const uniqueFolders = [...new Set(folders)].filter(folder => !/node_modules/.test(folder))
34
- const db = (cds.env.folders && cds.env.folders.db) || 'db/'
35
- let dbFolder = path.join(global.cds.root, db)
36
- if (dbFolder.endsWith('/') || dbFolder.endsWith('\\')) dbFolder = dbFolder.slice(0, -1)
37
- if (!uniqueFolders.includes(dbFolder)) uniqueFolders.push(dbFolder)
38
-
39
- const result = []
40
- for (const folder of uniqueFolders) {
41
- const dataPath = path.join(folder, 'data')
42
- const dataFiles = (await exists(dataPath)) ? await findCsvFiles(dataPath) : []
43
- const csvPath = path.join(folder, 'csv')
44
- const csvFiles = (await exists(csvPath)) ? await findCsvFiles(csvPath) : []
45
- result.push(...dataFiles, ...csvFiles)
46
- }
47
-
48
- return result
49
- }
50
-
51
11
  const packTarArchive = async (files, root, flat = false, cli = true) => {
52
12
  let tgzBuffer, temp
53
13
 
@@ -83,7 +43,7 @@ const packTarArchive = async (files, root, flat = false, cli = true) => {
83
43
  const unpackTarArchive = async (buffer, folder, cli = true) => {
84
44
  const temp = await fs.promises.mkdtemp(`${TEMP_DIR}${path.sep}tar-`)
85
45
  const tgz = path.join(temp, 'resources.tgz')
86
- await fs.promises.writeFile(tgz, buffer, 'binary')
46
+ await fs.promises.writeFile(tgz, Buffer.from(buffer), 'binary')
87
47
 
88
48
  try {
89
49
  cli ? await unpackArchiveCLI(tgz, folder) : await unpackArchive(tgz, folder)
@@ -93,9 +53,6 @@ const unpackTarArchive = async (buffer, folder, cli = true) => {
93
53
  }
94
54
 
95
55
  module.exports = {
96
- TAR_CLI,
97
- findCsvFiles,
98
- collectCsvFiles,
99
56
  packTarArchive,
100
57
  unpackTarArchive
101
58
  }
@@ -1,9 +1,9 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
- const tar = require('tar')
4
3
  const exec = require('child_process').exec
5
4
 
6
5
  const _createArchive = (files, root) => {
6
+ const tar = require('tar')
7
7
  return tar.c(
8
8
  {
9
9
  gzip: true,
@@ -45,6 +45,7 @@ const packArchiveCLI = async (files, root, output) => {
45
45
  }
46
46
 
47
47
  const unpackArchive = async (tgz, folder) => {
48
+ const tar = require('tar')
48
49
  await tar.x({
49
50
  file: tgz,
50
51
  gzip: true,
@@ -8,26 +8,23 @@ class Test extends require('./axios') {
8
8
  */
9
9
  run (cmd='.', ...args) {
10
10
 
11
- this.cmd = cmd, this.args = args
11
+ const {cds} = this; this.cmd = cmd, this.args = args
12
+ if (!/^(serve|run)$/.test(cmd)) try {
13
+ const project = cds.utils.isdir(cmd) || require.resolve (cmd+'/package.json').slice(0,-13)
14
+ this.cmd = cmd = 'serve'; args.push ('--in-memory?')
15
+ this.in (project)
16
+ } catch(e) {
17
+ throw cds.error (`No such folder or package '${process.cwd()}' -> '${cmd}'`)
18
+ }
12
19
 
13
20
  // launch cds server...
14
- before (`launching ${cmd} ${args.join(' ')}...`, () => { // NOSONAR
15
-
16
- const {cds} = this
17
- if (!/^(serve|run)$/.test(cmd)) try {
18
- const project = cds.utils.isdir (cmd) || require.resolve (cmd+'/package.json').slice(0,-13)
19
- cmd='serve'; args.push ('--in-memory?', '--project', project)
20
- } catch(e) {
21
- throw cds.error (`No such folder or package '${process.cwd()}' -> '${cmd}'`)
22
- }
23
-
21
+ before (`launching ${cmd} ${args.join(' ')}...`, () => {
24
22
  cds.once ('listening', ({server,url}) => {
25
23
  const axp = Reflect.getOwnPropertyDescriptor(this,'axios')
26
24
  if (axp) axp.value.defaults.baseURL = url
27
25
  this.server = server
28
26
  this.url = url
29
27
  })
30
-
31
28
  try { return cds.exec (cmd, ...args, '--port','0') }
32
29
  catch (e) { if (is_mocha) console.error(e) } // eslint-disable-line no-console
33
30
  })
@@ -51,7 +48,7 @@ class Test extends require('./axios') {
51
48
  */
52
49
  in (...paths) {
53
50
  const {cds} = this; cds.root = require('path').resolve (cds.root, ...paths)
54
- // const env = Reflect.getOwnPropertyDescriptor(global.cds,'env')
51
+ // const env = Reflect.getOwnPropertyDescriptor(cds,'env')
55
52
  // if (env && env.value && env.value._home !== cds.root) {
56
53
  // throw new Error (`[cds.test] - 'cds.env' was invoked before 'cds.test.in' from a different home:
57
54
 
@@ -136,10 +133,11 @@ function initLogging() {
136
133
  ? { deploy:'info', serve:'info', server:'info',cds:'info' }
137
134
  : { deploy:'warn', serve:'warn', server:'warn',cds:'silent' /* silences provoked request errors */ }
138
135
 
139
- const env = Reflect.getOwnPropertyDescriptor(global.cds,'env')
136
+ const cds = require('../index')
137
+ const env = Reflect.getOwnPropertyDescriptor(cds,'env')
140
138
  for (const id of Object.keys(levels)) {
141
139
  if (env && env.value)
142
- global.cds.log(id, { level:levels[id] })
140
+ cds.log(id, { level:levels[id] })
143
141
  else // uninitialized cds.env -> set env variables to avoid initializing cds.env eagerly
144
142
  process.env['cds_log_levels_'+id] = levels[id]
145
143
  }
@@ -3,7 +3,7 @@
3
3
  "node": true,
4
4
  "jest": true
5
5
  },
6
- "extends": ["prettier-standard"],
6
+ // "extends": ["prettier-standard"],
7
7
  "ignorePatterns": ["**/okra/**/*.js"],
8
8
  "rules": {
9
9
  "no-console": ["error"],