@sap/cds 6.1.3 → 6.2.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 (206) hide show
  1. package/CHANGELOG.md +83 -8
  2. package/apis/cds.d.ts +18 -6
  3. package/apis/connect.d.ts +1 -1
  4. package/apis/cqn.d.ts +1 -1
  5. package/apis/log.d.ts +23 -5
  6. package/apis/ql.d.ts +128 -61
  7. package/apis/services.d.ts +11 -0
  8. package/apis/test.d.ts +61 -0
  9. package/apis/utils.d.ts +15 -0
  10. package/app/fiori/preview.js +1 -0
  11. package/bin/build/buildTaskEngine.js +70 -22
  12. package/bin/build/buildTaskFactory.js +18 -11
  13. package/bin/build/buildTaskHandler.js +1 -1
  14. package/bin/build/buildTaskProviderFactory.js +3 -13
  15. package/bin/build/constants.js +0 -1
  16. package/bin/build/index.js +14 -6
  17. package/bin/build/provider/buildTaskHandlerEdmx.js +2 -3
  18. package/bin/build/provider/buildTaskHandlerFeatureToggles.js +2 -2
  19. package/bin/build/provider/buildTaskHandlerInternal.js +3 -6
  20. package/bin/build/provider/buildTaskProviderInternal.js +51 -39
  21. package/bin/build/provider/fiori/index.js +3 -3
  22. package/bin/build/provider/hana/2migration.js +1 -1
  23. package/bin/build/provider/hana/index.js +34 -27
  24. package/bin/build/provider/java/index.js +6 -7
  25. package/bin/build/provider/mtx/index.js +20 -18
  26. package/bin/build/provider/mtx/resourcesTarBuilder.js +8 -11
  27. package/bin/build/provider/mtx-sidecar/index.js +13 -17
  28. package/bin/build/provider/nodejs/index.js +8 -7
  29. package/bin/build/util.js +22 -4
  30. package/bin/cds.js +8 -4
  31. package/bin/deploy/to-hana/cfUtil.js +53 -18
  32. package/bin/mtx/in-cds.js +1 -0
  33. package/bin/serve.js +37 -30
  34. package/lib/auth/basic-auth.js +33 -0
  35. package/lib/auth/dummy-auth.js +7 -0
  36. package/lib/auth/ias-auth.js +2 -0
  37. package/lib/auth/index.js +31 -0
  38. package/lib/auth/jwt-auth.js +3 -0
  39. package/lib/auth/mocked-users.js +72 -0
  40. package/lib/auth/passport-basic.js +12 -0
  41. package/lib/auth/passport-digest.js +14 -0
  42. package/lib/auth/xsuaa-auth.js +3 -0
  43. package/lib/compile/cds-compile.js +3 -3
  44. package/lib/compile/to/cdl.js +5 -1
  45. package/lib/compile/to/edm.js +8 -0
  46. package/lib/compile/to/gql.js +1 -0
  47. package/lib/compile/to/json.js +30 -5
  48. package/lib/compile/to/sql.js +3 -1
  49. package/lib/core/index.js +5 -1
  50. package/lib/dbs/cds-deploy.js +36 -6
  51. package/lib/env/cds-env.js +15 -5
  52. package/lib/env/cds-requires.js +51 -58
  53. package/lib/env/defaults.js +1 -0
  54. package/lib/env/schemas/cds-package.json +4 -0
  55. package/lib/env/schemas/cds-rc.json +63 -77
  56. package/lib/i18n/localize.js +16 -5
  57. package/lib/index.js +9 -4
  58. package/lib/log/cds-error.js +4 -6
  59. package/lib/log/cds-log.js +89 -53
  60. package/lib/log/service/index.js +1 -0
  61. package/lib/ql/CREATE.js +2 -5
  62. package/lib/ql/DELETE.js +1 -1
  63. package/lib/ql/DROP.js +1 -3
  64. package/lib/ql/INSERT.js +3 -3
  65. package/lib/ql/Query.js +10 -23
  66. package/lib/ql/SELECT.js +1 -2
  67. package/lib/ql/UPDATE.js +2 -2
  68. package/lib/ql/Whereable.js +7 -15
  69. package/lib/ql/cds-ql.js +9 -3
  70. package/lib/req/cds-context.js +11 -3
  71. package/lib/req/context.js +29 -23
  72. package/lib/req/locale.js +9 -5
  73. package/lib/req/request.js +1 -0
  74. package/lib/req/user.js +2 -1
  75. package/lib/srv/cds-connect.js +1 -1
  76. package/lib/srv/cds-serve.js +21 -14
  77. package/lib/srv/middlewares/cds-context.js +29 -0
  78. package/lib/srv/middlewares/ctx-model.js +24 -0
  79. package/lib/srv/middlewares/errors.js +9 -0
  80. package/lib/srv/middlewares/index.js +22 -0
  81. package/lib/srv/middlewares/sap-statistics.js +13 -0
  82. package/lib/srv/middlewares/trace.js +102 -0
  83. package/lib/srv/protocols/_legacy.js +42 -0
  84. package/lib/srv/protocols/graphql.js +39 -0
  85. package/lib/srv/protocols/hcql.js +37 -0
  86. package/lib/srv/protocols/index.js +86 -0
  87. package/lib/srv/protocols/odata-v2-proxy.js +3767 -0
  88. package/lib/srv/protocols/odata-v2.js +26 -0
  89. package/lib/srv/protocols/odata-v4.js +16 -0
  90. package/lib/srv/protocols/rest.js +13 -0
  91. package/lib/srv/srv-api.js +5 -0
  92. package/lib/srv/srv-models.js +4 -6
  93. package/lib/utils/axios.js +3 -2
  94. package/lib/utils/cds-test.js +27 -21
  95. package/lib/utils/cds-utils.js +19 -20
  96. package/lib/utils/tar.js +175 -0
  97. package/libx/_runtime/audit/generic/personal/utils.js +18 -7
  98. package/libx/_runtime/audit/utils/v2.js +1 -0
  99. package/libx/_runtime/auth/index.js +4 -0
  100. package/libx/_runtime/auth/strategies/ias-auth.js +76 -0
  101. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +8 -3
  102. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +15 -4
  103. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +1 -1
  104. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/orderByToCQN.js +1 -1
  105. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +1 -1
  106. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/ResourcePathParser.js +9 -0
  107. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriInfo.js +5 -1
  108. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriParser.js +12 -0
  109. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/utils/BufferedWriter.js +6 -2
  110. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/validator/RequestValidator.js +47 -7
  111. package/libx/_runtime/cds-services/adapter/odata-v4/to.js +1 -1
  112. package/libx/_runtime/cds-services/util/assert.js +4 -0
  113. package/libx/_runtime/common/aspects/relation.js +1 -1
  114. package/libx/_runtime/common/composition/data.js +61 -15
  115. package/libx/_runtime/common/composition/delete.js +0 -1
  116. package/libx/_runtime/common/composition/insert.js +0 -1
  117. package/libx/_runtime/common/composition/tree.js +4 -10
  118. package/libx/_runtime/common/composition/update.js +44 -21
  119. package/libx/_runtime/common/generic/auth/capabilities.js +8 -10
  120. package/libx/_runtime/common/generic/crud.js +1 -2
  121. package/libx/_runtime/common/generic/etag.js +4 -4
  122. package/libx/_runtime/common/generic/input.js +4 -4
  123. package/libx/_runtime/common/generic/paging.js +3 -3
  124. package/libx/_runtime/common/generic/put.js +3 -3
  125. package/libx/_runtime/common/generic/sorting.js +4 -4
  126. package/libx/_runtime/common/generic/temporal.js +3 -3
  127. package/libx/_runtime/common/i18n/messages.properties +0 -7
  128. package/libx/_runtime/common/utils/cqn2cqn4sql.js +11 -6
  129. package/libx/_runtime/common/utils/csn.js +0 -28
  130. package/libx/_runtime/common/utils/draft.js +8 -1
  131. package/libx/_runtime/common/utils/path.js +7 -1
  132. package/libx/_runtime/common/utils/resolveView.js +2 -3
  133. package/libx/_runtime/db/data-conversion/post-processing.js +3 -44
  134. package/libx/_runtime/db/generic/input.js +3 -3
  135. package/libx/_runtime/db/sql-builder/dataTypes.js +4 -0
  136. package/libx/_runtime/fiori/generic/activate.js +2 -2
  137. package/libx/_runtime/fiori/generic/before.js +40 -72
  138. package/libx/_runtime/fiori/generic/cancel.js +2 -2
  139. package/libx/_runtime/fiori/generic/delete.js +2 -2
  140. package/libx/_runtime/fiori/generic/edit.js +2 -2
  141. package/libx/_runtime/fiori/generic/new.js +2 -2
  142. package/libx/_runtime/fiori/generic/patch.js +49 -37
  143. package/libx/_runtime/fiori/generic/prepare.js +2 -2
  144. package/libx/_runtime/fiori/generic/read.js +27 -37
  145. package/libx/_runtime/fiori/utils/where.js +4 -2
  146. package/libx/_runtime/hana/Service.js +1 -3
  147. package/libx/_runtime/hana/conversion.js +3 -0
  148. package/libx/_runtime/hana/driver.js +33 -3
  149. package/libx/_runtime/hana/dynatrace.js +1 -0
  150. package/libx/_runtime/hana/search2Contains.js +12 -1
  151. package/libx/_runtime/hana/search2cqn4sql.js +10 -27
  152. package/libx/_runtime/hana/streaming.js +1 -0
  153. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +4 -2
  154. package/libx/_runtime/messaging/common-utils/AMQPClient.js +1 -0
  155. package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +5 -2
  156. package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +2 -0
  157. package/libx/_runtime/messaging/enterprise-messaging.js +62 -3
  158. package/libx/_runtime/messaging/outbox/utils.js +1 -1
  159. package/libx/_runtime/messaging/redis-messaging.js +1 -0
  160. package/libx/_runtime/remote/Service.js +2 -2
  161. package/libx/_runtime/remote/utils/client.js +8 -3
  162. package/libx/_runtime/remote/utils/data.js +7 -2
  163. package/libx/_runtime/sqlite/Service.js +18 -7
  164. package/libx/_runtime/sqlite/conversion.js +3 -0
  165. package/libx/_runtime/sqlite/convertAssocToOneManaged.js +3 -3
  166. package/libx/_runtime/sqlite/localized.js +8 -8
  167. package/libx/odata/afterburner.js +39 -7
  168. package/libx/odata/cqn2odata.js +6 -3
  169. package/libx/odata/grammar.pegjs +66 -18
  170. package/libx/odata/index.js +3 -2
  171. package/libx/odata/parser.js +1 -1
  172. package/libx/odata/utils.js +2 -0
  173. package/libx/rest/RestAdapter.js +62 -43
  174. package/libx/rest/middleware/parse.js +2 -1
  175. package/libx/rest/middleware/update.js +1 -1
  176. package/package.json +2 -2
  177. package/server.js +5 -4
  178. package/srv/mtx.cds +1 -1
  179. package/srv/mtx.js +4 -33
  180. package/lib/srv/adapters.js +0 -85
  181. package/lib/utils/resources/index.js +0 -48
  182. package/lib/utils/resources/tar.js +0 -49
  183. package/lib/utils/resources/utils.js +0 -11
  184. package/libx/_runtime/extensibility/activate.js +0 -69
  185. package/libx/_runtime/extensibility/add.js +0 -50
  186. package/libx/_runtime/extensibility/addExtension.js +0 -72
  187. package/libx/_runtime/extensibility/defaults.js +0 -34
  188. package/libx/_runtime/extensibility/handler/transformREAD.js +0 -121
  189. package/libx/_runtime/extensibility/handler/transformRESULT.js +0 -51
  190. package/libx/_runtime/extensibility/handler/transformWRITE.js +0 -64
  191. package/libx/_runtime/extensibility/linter/allowlist_checker.js +0 -373
  192. package/libx/_runtime/extensibility/linter/annotations_checker.js +0 -113
  193. package/libx/_runtime/extensibility/linter/checker_base.js +0 -20
  194. package/libx/_runtime/extensibility/linter/namespace_checker.js +0 -180
  195. package/libx/_runtime/extensibility/linter.js +0 -32
  196. package/libx/_runtime/extensibility/push.js +0 -118
  197. package/libx/_runtime/extensibility/service.js +0 -38
  198. package/libx/_runtime/extensibility/token.js +0 -57
  199. package/libx/_runtime/extensibility/utils.js +0 -131
  200. package/libx/_runtime/extensibility/validation.js +0 -50
  201. package/libx/_runtime/extensibility/views.js +0 -12
  202. package/srv/extensibility-service.cds +0 -60
  203. package/srv/extensibility-service.js +0 -1
  204. package/srv/extensions.cds +0 -8
  205. package/srv/model-provider.cds +0 -61
  206. package/srv/model-provider.js +0 -143
@@ -1,61 +0,0 @@
1
- context cds.xt { // IMPORTANT: we don't use namespaces to avoid issues with cds.db default namespace
2
-
3
- @open type CSN {};
4
- type TAR : LargeBinary;
5
- type XML : LargeString;
6
- type Locale : String;
7
- type TenantID : String;
8
- type CSNConsumer : String enum { nodejs; java; };
9
-
10
-
11
- /**
12
- * Used by CAP runtimes to retrieve tenant-specific variants of
13
- * deployed models used to serve requests.
14
- */
15
- @protocol: 'rest'
16
- @requires: [ 'internal-user' ] //> we check that ourselves programmatically in production only
17
- service ModelProviderService @(path:'/-/cds/model-provider', impl:'@sap/cds/srv/model-provider.js') {
18
-
19
- action getCsn(
20
- tenant : TenantID,
21
- toggles : array of String,
22
- for : CSNConsumer @cds.java.name: 'runtime',
23
- flavor : String enum { parsed ; xtended ; inferred },
24
- base : Boolean,
25
- ) returns CSN;
26
-
27
- action getExtCsn(
28
- tenant : TenantID,
29
- toggles : array of String,
30
- for : CSNConsumer @cds.java.name: 'runtime',
31
- ) returns CSN;
32
-
33
- action getEdmx(
34
- tenant : TenantID,
35
- toggles : array of String,
36
- service : String,
37
- locale : Locale,
38
- flavor : String enum { v2; v4; w4; x4 },
39
- for : CSNConsumer @cds.java.name: 'runtime',
40
- ) returns XML;
41
-
42
- action isExtended(
43
- tenant : TenantID,
44
- ) returns Boolean;
45
-
46
- action getExtensions(
47
- tenant : TenantID,
48
- ) returns CSN;
49
-
50
- action getResources () returns TAR;
51
- action getExtResources() returns TAR;
52
-
53
- // -------------------------------
54
- // Later, possibly:
55
- // function GET csn(...)
56
- // function GET edmx(...)
57
- // function GET extended(...)
58
- // function GET resources(...)
59
- }
60
-
61
- }
@@ -1,143 +0,0 @@
1
- const { packTarArchive, unpackTarArchive } = require('../lib/utils/resources')
2
- const { collectFiles } = require('../libx/_runtime/extensibility/utils')
3
- const fs = require('fs').promises
4
- const os = require('os')
5
- const path = require('path')
6
-
7
- const cds = require('../lib')
8
- const conf = cds.requires['cds.xt.ModelProviderService'] || cds.requires.kinds['cds.xt.ModelProviderService']
9
- const main = conf.root ? new class { //> we're running in sidecar -> use env of main app
10
- get env() { return super.env = cds.env.for ('cds', this.root) }
11
- get root() { return super.root = path.resolve (cds.root, conf.root) }
12
- get requires() { return super.requires = this.env.requires }
13
- cache = {} //> for cds.resolve()
14
- } : { //> not in sidecar
15
- requires: cds.requires,
16
- root: cds.root,
17
- env: cds.env,
18
- }
19
- const fts = main.env.features.folders
20
- const DEBUG = cds.debug('mtx')
21
- if (DEBUG) cds.once('served', ()=> DEBUG ('model provider options:', conf))
22
-
23
-
24
- module.exports = class ModelProviderService extends cds.ApplicationService {
25
-
26
- /**
27
- * Overload `.on` to decorate handlers to set `cds.context.tenant` based on incoming arg `tenant`.
28
- */
29
- on (event, handler) {
30
- return super.on(event, (req) => {
31
- if (req.data.tenant) cds.context = { tenant: req.data.tenant }
32
- // REVISIT: might not be correct when called via ExtensibilityService.add(...)
33
- //> const tenant = req.tenant || (req.user.is('internal-user') && req.data.tenant)
34
- return handler(req)
35
- })
36
- }
37
-
38
- init() {
39
-
40
- // REVISIT: We should do the enforcement only in production
41
- // let requires = this.definition['@requires_']
42
- // if (requires && process.env.NODE_ENV === 'production') this.before ('*', req => {
43
- // if (!cds.context?.http) return //> not called from external
44
- // if (req.user._is_anonymous) return req.reject({ code:401 })
45
- // if (!requires.some(r => req.user.is(r))) return req.reject({ code:403 })
46
- // })
47
-
48
- this._in_sidecar = (conf.kind === 'in-sidecar') // REVISIT: eliminate this 'private API' if possible
49
-
50
- this.on('getCsn', req => _getCsn(req))
51
- this.on('getExtCsn', req => {
52
- if (!main.requires.extensibility) return req.reject(400, 'Missing extensibility parameter')
53
- return _getCsn (req, true)
54
- })
55
-
56
- this.on('getEdmx', async req => {
57
- const { res } = req._; if (res) res.set('Content-Type', 'application/xml')
58
- const { service, locale, flavor } = req.data
59
- delete req.data.flavor // we need to delete the OData 'flavor' argument, as getCsn has a different CSN `flavor` argument
60
- const csn = await _getCsn(req)
61
- const edmx = cds.compile.to.edmx(csn, { service, flavor })
62
- return cds.localize(csn, locale, edmx)
63
- })
64
-
65
- this.on('getResources', async req => {
66
- if (req._.res) req._.res.set('content-type', 'application/octet-stream; charset=binary')
67
- // REVISIT: Works only w/o encoding parameter. Default encoding is 'utf8'.
68
- // try { return await cds.utils.read('resources.tgz') }
69
- // root is defined in cds.requires, in case of the sidecar scenario it is set to "_main"
70
- try { return await fs.readFile (path.resolve (main.root, 'resources.tgz')) }
71
- catch(e) { if (e.code !== 'ENOENT') throw e }
72
- const files = Object.keys(await cds.deploy.resources(['*', cds.env.features.folders]))
73
- if (!files.length) return req.reject(404)
74
- if (req._.res) req._.res.set('content-type', 'application/octet-stream; charset=binary')
75
- return packTarArchive (files, cds.root)
76
- })
77
-
78
- this.on('getExtResources', async req => {
79
- if (!main.requires.extensibility) return req.reject(400, 'Missing extensibility parameter')
80
- const rs = await SELECT('sources').from('cds.xt.Extensions')
81
- if (!rs.length) return req.reject(404, 'Missing extensions')
82
- if (rs.every(row => row.sources === null)) return req.reject(404, 'Extension resources not found')
83
- if (req._.res) req._.res.set('content-type', 'application/octet-stream; charset=binary')
84
- const tmp = await fs.realpath(os.tmpdir())
85
- const dir = await fs.mkdtemp(tmp + path.sep + 'tar-') // REVISIT: hase to be exactly this folder -> weird
86
- try {
87
- await Promise.all (rs.map (row => unpackTarArchive (Buffer.from(row.sources), dir, false))) // REVISIT: use pipe instead
88
- return await packTarArchive (collectFiles (dir, ['.csv', '.properties']), dir) // REVISIT: better tar APIs -> collectFiles should not be required
89
- } finally {
90
- await fs.rm (dir, { recursive: true, force: true }).catch(()=>{})
91
- }
92
- })
93
-
94
- this.on('isExtended', async req => {
95
- if (!main.requires.extensibility) return false
96
- if (!req.data.tenant && main.requires.multitenancy) return false
97
- const one = await SELECT.one(1).from('cds.xt.Extensions')
98
- return !!one
99
- })
100
-
101
- this.on('getExtensions', async req => {
102
- if (!main.requires.extensibility) return req.reject(400, 'Missing extensibility parameter')
103
- return await _getExtensions4(req.data.tenant) || req.reject(404, 'Missing extensions')
104
- })
105
-
106
- /** Implementation for getCsn */
107
- async function _getCsn (req, checkExt) {
108
- const { tenant, toggles, base, flavor, for:javaornode } = req.data
109
- const extensions = !base && await _getExtensions4 (req.data.tenant)
110
- if (!extensions && checkExt) req.reject(404, 'Missing extensions')
111
-
112
- const features = (!toggles || !main.requires.toggles) ? [] : toggles === '*' || toggles.includes('*') ? [fts] : toggles.map (f => fts.replace('*',f))
113
- const models = cds.resolve (['*',...features], main); if (!models) return
114
-
115
- DEBUG && DEBUG ('loading models for', { tenant, toggles } ,'from', models.map (cds.utils.local))
116
- let csn = await cds.load (models, { flavor, silent:true })
117
- if (csn.meta?.flavor === 'inferred') csn = cds.minify (csn)
118
- if (extensions) csn = cds.extend (csn) .with (extensions)
119
- if (javaornode) csn = cds.compile.for[javaornode] (csn)
120
-
121
- // Dirty hack for cds.localize in Node sidecar setup
122
- Object.defineProperty (csn,'$sources',{ value:csn.$sources, enumerable:true })
123
- return csn
124
- }
125
-
126
- /** Implementation for getExtensions */
127
- async function _getExtensions4 (tenant) {
128
- if (!main.requires.extensibility || !tenant && main.requires.multitenancy) return
129
- const exts = await SELECT('csn').from('cds.xt.Extensions'); if (!exts.length) return
130
- const merged = { extensions: [], definitions: {} }
131
- for (let each of exts) {
132
- let {definitions,extensions} = JSON.parse(each.csn)
133
- if (definitions) Object.assign (merged.definitions, definitions)
134
- if (extensions) merged.extensions.push (...extensions)
135
- }
136
- return merged
137
- }
138
-
139
- }
140
-
141
- get isExtensible () { return false } // REVISIT: Do we want to keep this?
142
- }
143
- module.exports.prototype._add_stub_methods = true