@sap/cds 6.8.4 → 7.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 (217) hide show
  1. package/CHANGELOG.md +66 -4
  2. package/README.md +0 -1
  3. package/bin/cds-serve.js +50 -3
  4. package/bin/deploy/to-hana.js +1 -0
  5. package/bin/serve.js +16 -20
  6. package/lib/auth/basic-auth.js +6 -4
  7. package/lib/auth/index.js +4 -3
  8. package/lib/auth/jwt-auth.js +2 -5
  9. package/lib/compile/cds-compile.js +34 -89
  10. package/lib/compile/cdsc.js +11 -0
  11. package/lib/compile/etc/properties.js +2 -2
  12. package/lib/compile/for/lean_drafts.js +36 -69
  13. package/lib/compile/for/nodejs.js +2 -1
  14. package/lib/compile/load.js +3 -3
  15. package/lib/compile/minify.js +2 -0
  16. package/lib/compile/to/csn.js +74 -0
  17. package/{bin/build/provider/hana/2tabledata.js → lib/compile/to/hdbtabledata.js} +4 -6
  18. package/lib/compile/to/json.js +1 -1
  19. package/lib/compile/to/sql.js +8 -6
  20. package/lib/dbs/cds-deploy.js +174 -114
  21. package/lib/env/cds-env.js +64 -79
  22. package/lib/env/cds-requires.js +11 -28
  23. package/lib/env/defaults.js +13 -3
  24. package/lib/env/plugins.js +1 -12
  25. package/lib/env/presets.js +25 -21
  26. package/lib/index.js +121 -147
  27. package/lib/{core/reflect.js → linked/models.js} +2 -2
  28. package/lib/{core/infer.js → linked/queries.js} +2 -0
  29. package/lib/{core/index.js → linked/types.js} +2 -1
  30. package/lib/log/cds-error.js +13 -7
  31. package/lib/log/format/cf.js +1 -1
  32. package/lib/plugins.js +49 -0
  33. package/lib/ql/Query.js +0 -9
  34. package/lib/ql/STREAM.js +0 -1
  35. package/lib/req/context.js +2 -7
  36. package/lib/req/request.js +6 -2
  37. package/lib/req/response.js +23 -10
  38. package/lib/srv/middlewares/ctx-model.js +2 -2
  39. package/lib/srv/middlewares/errors.js +1 -1
  40. package/lib/srv/protocols/_legacy.js +1 -0
  41. package/lib/srv/protocols/graphql.js +7 -16
  42. package/lib/srv/protocols/index.js +59 -45
  43. package/lib/srv/protocols/odata-v2-proxy.js +2 -70
  44. package/lib/srv/protocols/odata-v4.js +9 -4
  45. package/lib/srv/srv-api.js +9 -3
  46. package/lib/srv/srv-dispatch.js +12 -9
  47. package/lib/srv/srv-models.js +4 -21
  48. package/lib/srv/srv-tx.js +15 -12
  49. package/lib/utils/cds-test.js +14 -9
  50. package/lib/utils/cds-utils.js +2 -12
  51. package/lib/utils/check-version.js +17 -0
  52. package/{bin/build → lib/utils}/csv-reader.js +23 -24
  53. package/libx/_runtime/auth/index.js +27 -23
  54. package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +15 -72
  55. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +1 -1
  56. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +0 -2
  57. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +33 -63
  58. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +14 -18
  59. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +15 -5
  60. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +5 -4
  61. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +37 -40
  62. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/updateToCQN.js +7 -1
  63. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +101 -38
  64. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/errors/AbstractError.js +5 -1
  65. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriTokenizer.js +5 -8
  66. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/ValueConverter.js +2 -1
  67. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/deserializer/ResourceJsonDeserializer.js +9 -8
  68. package/libx/_runtime/cds-services/adapter/odata-v4/to.js +1 -1
  69. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +15 -11
  70. package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +4 -0
  71. package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +5 -2
  72. package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +1 -123
  73. package/libx/_runtime/cds-services/services/Service.js +79 -107
  74. package/libx/_runtime/cds-services/services/utils/columns.js +23 -19
  75. package/libx/_runtime/cds-services/services/utils/compareJson.js +11 -1
  76. package/libx/_runtime/cds-services/services/utils/differ.js +7 -2
  77. package/libx/_runtime/cds-services/util/assert.js +65 -2
  78. package/libx/_runtime/common/composition/data.js +1 -0
  79. package/libx/_runtime/common/generic/auth/expand.js +1 -1
  80. package/libx/_runtime/common/generic/auth/restrict.js +5 -10
  81. package/libx/_runtime/common/generic/auth/restrictions.js +40 -0
  82. package/libx/_runtime/common/generic/auth/utils.js +1 -2
  83. package/libx/_runtime/common/generic/crud.js +32 -16
  84. package/libx/_runtime/common/generic/etag.js +133 -104
  85. package/libx/_runtime/common/generic/input.js +6 -21
  86. package/libx/_runtime/common/generic/put.js +1 -1
  87. package/libx/_runtime/common/generic/stream.js +52 -0
  88. package/libx/_runtime/common/generic/temporal.js +25 -8
  89. package/libx/_runtime/common/i18n/messages.properties +0 -2
  90. package/libx/_runtime/common/utils/cqn.js +1 -1
  91. package/libx/_runtime/common/utils/cqn2cqn4sql.js +5 -2
  92. package/libx/_runtime/common/utils/csn.js +0 -51
  93. package/libx/_runtime/common/utils/etag.js +30 -0
  94. package/libx/_runtime/common/utils/keys.js +1 -1
  95. package/libx/_runtime/common/utils/normalizeTimestamp.js +25 -0
  96. package/libx/_runtime/common/utils/path.js +1 -1
  97. package/libx/_runtime/common/utils/resolveView.js +2 -1
  98. package/libx/_runtime/common/utils/rewriteAsterisks.js +6 -4
  99. package/libx/_runtime/common/utils/search2cqn4sql.js +12 -16
  100. package/libx/_runtime/common/utils/stream.js +140 -0
  101. package/libx/_runtime/common/utils/streamProp.js +29 -12
  102. package/libx/_runtime/common/utils/templateProcessorPathSerializer.js +0 -2
  103. package/libx/_runtime/db/generic/index.js +0 -2
  104. package/libx/_runtime/db/query/delete.js +2 -2
  105. package/libx/_runtime/db/query/insert.js +2 -2
  106. package/libx/_runtime/db/query/read.js +2 -2
  107. package/libx/_runtime/db/query/run.js +2 -2
  108. package/libx/_runtime/db/query/update.js +2 -2
  109. package/libx/_runtime/db/sql-builder/BaseBuilder.js +0 -6
  110. package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +23 -12
  111. package/libx/_runtime/db/sql-builder/FunctionBuilder.js +18 -6
  112. package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -0
  113. package/libx/_runtime/db/sql-builder/SelectBuilder.js +3 -7
  114. package/libx/_runtime/db/sql-builder/UpsertBuilder.js +1 -0
  115. package/libx/_runtime/db/utils/normalizeTimeData.js +7 -3
  116. package/libx/_runtime/fiori/draft.js +2 -0
  117. package/libx/_runtime/fiori/generic/activate.js +8 -9
  118. package/libx/_runtime/fiori/generic/before.js +30 -20
  119. package/libx/_runtime/fiori/generic/cancel.js +5 -3
  120. package/libx/_runtime/fiori/generic/delete.js +5 -3
  121. package/libx/_runtime/fiori/generic/edit.js +7 -7
  122. package/libx/_runtime/fiori/generic/index.js +10 -16
  123. package/libx/_runtime/fiori/generic/new.js +5 -3
  124. package/libx/_runtime/fiori/generic/patch.js +11 -8
  125. package/libx/_runtime/fiori/generic/prepare.js +13 -6
  126. package/libx/_runtime/fiori/generic/read.js +12 -6
  127. package/libx/_runtime/fiori/lean-draft.js +207 -152
  128. package/libx/_runtime/fiori/utils/delete.js +10 -5
  129. package/libx/_runtime/fiori/utils/req.js +17 -5
  130. package/libx/_runtime/fiori/utils/stream.js +36 -0
  131. package/libx/_runtime/hana/Service.js +12 -9
  132. package/libx/_runtime/hana/conversion.js +10 -15
  133. package/libx/_runtime/hana/driver.js +2 -0
  134. package/libx/_runtime/hana/execute.js +28 -6
  135. package/libx/_runtime/hana/pool.js +36 -122
  136. package/libx/_runtime/hana/search2cqn4sql.js +34 -36
  137. package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +2 -6
  138. package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +3 -1
  139. package/libx/_runtime/messaging/enterprise-messaging.js +10 -58
  140. package/libx/_runtime/messaging/outbox/utils.js +1 -1
  141. package/libx/_runtime/remote/Service.js +20 -1
  142. package/libx/_runtime/remote/utils/client.js +3 -5
  143. package/libx/_runtime/sqlite/Service.js +4 -6
  144. package/libx/_runtime/sqlite/conversion.js +3 -13
  145. package/libx/_runtime/sqlite/customBuilder/CustomFunctionBuilder.js +9 -6
  146. package/libx/_runtime/sqlite/customBuilder/CustomUpsertBuilder.js +6 -1
  147. package/libx/_runtime/sqlite/execute.js +5 -16
  148. package/libx/odata/afterburner.js +22 -6
  149. package/libx/odata/grammar.pegjs +6 -1
  150. package/libx/odata/parser.js +1 -1
  151. package/libx/rest/RestAdapter.js +16 -9
  152. package/libx/rest/RestRequest.js +1 -1
  153. package/libx/rest/middleware/input.js +2 -1
  154. package/libx/rest/middleware/operation.js +1 -0
  155. package/libx/rest/middleware/parse.js +3 -2
  156. package/libx/rest/middleware/payload.js +9 -8
  157. package/libx/rest/middleware/read.js +1 -0
  158. package/package.json +9 -16
  159. package/server.js +1 -1
  160. package/app/fiori/preview.js +0 -270
  161. package/app/fiori/routes.js +0 -59
  162. package/bin/build/buildTaskEngine.js +0 -360
  163. package/bin/build/buildTaskFactory.js +0 -283
  164. package/bin/build/buildTaskHandler.js +0 -241
  165. package/bin/build/buildTaskProvider.js +0 -22
  166. package/bin/build/buildTaskProviderFactory.js +0 -175
  167. package/bin/build/cds.js +0 -5
  168. package/bin/build/constants.js +0 -66
  169. package/bin/build/index.js +0 -58
  170. package/bin/build/provider/buildTaskHandlerEdmx.js +0 -82
  171. package/bin/build/provider/buildTaskHandlerFeatureToggles.js +0 -131
  172. package/bin/build/provider/buildTaskHandlerInternal.js +0 -254
  173. package/bin/build/provider/buildTaskProviderInternal.js +0 -383
  174. package/bin/build/provider/fiori/index.js +0 -171
  175. package/bin/build/provider/hana/2migration.js +0 -179
  176. package/bin/build/provider/hana/index.js +0 -505
  177. package/bin/build/provider/hana/migrationtable.js +0 -472
  178. package/bin/build/provider/hana/template/.hdiconfig-haas +0 -163
  179. package/bin/build/provider/hana/template/.hdiconfig-hanacloud +0 -137
  180. package/bin/build/provider/hana/template/.hdinamespace +0 -4
  181. package/bin/build/provider/hana/template/package.json +0 -12
  182. package/bin/build/provider/hana/template/undeploy.json +0 -5
  183. package/bin/build/provider/java/index.js +0 -111
  184. package/bin/build/provider/java-cf/index.js +0 -1
  185. package/bin/build/provider/mtx/index.js +0 -268
  186. package/bin/build/provider/mtx/resourcesTarBuilder.js +0 -95
  187. package/bin/build/provider/mtx-extension/index.js +0 -131
  188. package/bin/build/provider/mtx-sidecar/index.js +0 -137
  189. package/bin/build/provider/node-cf/index.js +0 -1
  190. package/bin/build/provider/nodejs/index.js +0 -192
  191. package/bin/build/util.js +0 -299
  192. package/bin/cds.js +0 -125
  193. package/bin/deploy/to-hana/cfUtil.js +0 -355
  194. package/bin/deploy/to-hana/gitUtil.js +0 -57
  195. package/bin/deploy/to-hana/hana.js +0 -306
  196. package/bin/deploy/to-hana/hdiDeployUtil.js +0 -153
  197. package/bin/deploy/to-hana/index.js +0 -16
  198. package/bin/deploy/to-hana/mtaUtil.js +0 -170
  199. package/bin/mtx/in-cds.js +0 -17
  200. package/bin/plugins.js +0 -32
  201. package/bin/run.js +0 -24
  202. package/bin/utils/log.js +0 -24
  203. package/bin/version.js +0 -178
  204. package/libx/_runtime/audit/Service.js +0 -222
  205. package/libx/_runtime/audit/generic/personal/access.js +0 -61
  206. package/libx/_runtime/audit/generic/personal/index.js +0 -56
  207. package/libx/_runtime/audit/generic/personal/modification.js +0 -132
  208. package/libx/_runtime/audit/generic/personal/utils.js +0 -186
  209. package/libx/_runtime/audit/utils/log.js +0 -23
  210. package/libx/_runtime/audit/utils/v2.js +0 -176
  211. package/libx/_runtime/db/data-conversion/timestamp.js +0 -9
  212. package/libx/_runtime/db/generic/integrity.js +0 -455
  213. package/srv/audit-log.cds +0 -87
  214. package/srv/mtx.cds +0 -2
  215. package/srv/mtx.js +0 -8
  216. /package/lib/{core → linked}/classes.js +0 -0
  217. /package/lib/{core → linked}/entities.js +0 -0
@@ -1,175 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const cds = require('./cds')
4
- const { OUTPUT_MODE_DEFAULT, LOG_MODULE_NAMES } = require("./constants")
5
- const BuildTaskProviderInternal = require('./provider/buildTaskProviderInternal')
6
- const BuildTaskProvider = require('./buildTaskProvider')
7
-
8
- class BuildTaskProviderFactory {
9
- constructor(logger, buildOptions) {
10
- this._logger = logger || cds.log(LOG_MODULE_NAMES)
11
- buildOptions.for = buildOptions.for || {}
12
- buildOptions.outputMode = buildOptions.outputMode || OUTPUT_MODE_DEFAULT
13
- this._buildOptions = buildOptions
14
- }
15
- get logger() {
16
- return this._logger
17
- }
18
- get buildOptions() {
19
- return this._buildOptions
20
- }
21
- get providers() {
22
- if (!this._providers) {
23
- this._providers = this._loadProviders()
24
- }
25
- return this._providers
26
- }
27
-
28
- async applyTaskDefaults(tasks) {
29
- return Promise.all(tasks.map(async task => {
30
- if (!task.for && !task.use) {
31
- throw new Error("Invalid build task definition - property 'for' and property 'use' missing")
32
- }
33
- const provider = this.providers.find(provider => {
34
- try {
35
- return provider.canHandleTask(task)
36
- } catch (e) {
37
- this.logger.error(`Build task provider ${provider.constructor.name} returned error:\n` + e)
38
- throw e
39
- }
40
- })
41
- if (!provider) {
42
- throw new Error(`No provider found for build task '${task.for || task.use}'`)
43
- }
44
- if (provider instanceof DefaultBuildTaskProvider) {
45
- this.logger._debug && this.logger.debug(`No provider found for build task '${task.use}', using default provider`)
46
- }
47
- await this._applyTaskDefaults(provider, [task])
48
- }))
49
- }
50
-
51
- async lookupTasks(tasks = []) {
52
- await Promise.all(this.providers.map(async (provider) => {
53
- const snapShot = tasks
54
- await this._lookupTasks(provider, tasks)
55
- // apply defaults
56
- const newTasks = tasks.filter(task => !snapShot.includes(task))
57
- await this._applyTaskDefaults(provider, newTasks)
58
- this.logger._debug && this.logger.debug(`Build task provider ${provider.constructor.name} returned build tasks ${JSON.stringify(newTasks)}`)
59
- }))
60
- return tasks
61
- }
62
-
63
- /**
64
- * Create a BuildTaskHandler instance for the given build task.
65
- * The implementation is loaded based on the build task's 'for' or 'use' option.
66
- * @param {*} task
67
- * @param {*} buildOptions
68
- */
69
- createHandler(task) {
70
- const BuildTaskHandlerClass = this.loadHandler(task)
71
- const resolvedTask = this.resolveTask(task)
72
- this.logger._debug && this.logger.debug(`loaded build task handler [${resolvedTask.use}]`)
73
-
74
- const handler = new BuildTaskHandlerClass()
75
- handler._task = resolvedTask
76
- handler._logger = this.logger
77
- handler._buildOptions = this.buildOptions
78
- this.logger._debug && this.logger.debug(`created BuildTaskHandler [${resolvedTask.use}]`)
79
- return handler
80
- }
81
-
82
- /**
83
- * Loads the build task handler implementation for the given build task.
84
- * 'for' defines an alias for built-in handlers like 'hana', 'java', 'node', 'fiori' or 'mtx'.
85
- * 'use' defines the fully qualified module name of external build task handler implemenations.
86
- * @param {object} task
87
- */
88
- loadHandler(task) {
89
- let provider = this.providers.find(provider => provider.canHandleTask(task))
90
- if (!provider) {
91
- throw new Error(`No provider found for build task '${task.for || task.use}'`)
92
- }
93
- try {
94
- return provider.loadHandler(task)
95
- }
96
- catch (e) {
97
- this.logger.error(`Provider failed to load handler class - provider: ${provider.constructor.name}, task: ${task.for || task.use} :\n` + e)
98
- throw e
99
- }
100
- }
101
-
102
- resolveTasks(tasks) {
103
- return tasks.map(task => this.resolveTask(task))
104
- }
105
-
106
- /**
107
- * Resolves the given build task based on the project root folder.<br>
108
- * The task is validated in order to ensure that 'src' refers to a valid folder and 'for' or 'use' reference can be required.
109
- * @param {*} task
110
- * @param {*} buildOptions
111
- */
112
- resolveTask(task) {
113
- // first validate handler implementation
114
- this.loadHandler(task)
115
-
116
- // second valdiate src path
117
- const resolvedTask = JSON.parse(JSON.stringify(task))
118
-
119
- // Do not store resolved symlinks as this is causing issues on Windows, e.g. if git projects are
120
- // located under 'C:\SAPDevelop\git\...' using a sym-link from '%USERHOME%\git' to 'C:\SAPDevelop\git'.
121
- // see cap/issues/#8694
122
- resolvedTask.src = path.resolve(this.buildOptions.root, task.src)
123
- try {
124
- //validate source path
125
- fs.realpathSync(resolvedTask.src)
126
- } catch (e) {
127
- throw new Error(`Build task [${resolvedTask.for || resolvedTask.use}] could not be resolved - folder src [${path.resolve(this.buildOptions.root, task.src)}] does not exist`)
128
- }
129
- resolvedTask.dest = path.resolve(this.buildOptions.target, task.dest || task.src)
130
- resolvedTask.options = task.options || {}
131
- return resolvedTask
132
- }
133
-
134
- async _lookupTasks(provider, tasks) {
135
- return provider.lookupTasks(tasks, this.buildOptions)
136
- }
137
-
138
- async _applyTaskDefaults(provider, tasks) {
139
- return Promise.all(tasks.map(task => provider.applyTaskDefaults(task, this.buildOptions)))
140
- }
141
-
142
- _loadProviders() {
143
- // order is important - the DefaultBuildTaskProvider has to be the last provider in the list
144
- return [this._createProvider(BuildTaskProviderInternal), this._createProvider(DefaultBuildTaskProvider)]
145
- }
146
-
147
- _createProvider(clazz, plugin) {
148
- const provider = new clazz()
149
- provider._logger = this.logger
150
- provider._plugin = plugin
151
- return provider
152
- }
153
- }
154
-
155
- /**
156
- * Default provider implementation handling fully qualified custom build task declarations.
157
- * Has to be the last entry in the providers list.
158
- */
159
- class DefaultBuildTaskProvider extends BuildTaskProvider {
160
- canHandleTask(task) {
161
- return !!task.use
162
- }
163
- loadHandler(task) {
164
- if (!task.use) {
165
- throw new Error(`Invalid build task definition [${task.for}] - property 'use' missing`)
166
- }
167
- try {
168
- return require(require.resolve(task.use, { paths: [cds.root] }))
169
- }
170
- catch (e) {
171
- throw new Error(`Build task could not be resolved - module [${task.use}] cannot be loaded:\n` + e)
172
- }
173
- }
174
- }
175
- module.exports = BuildTaskProviderFactory
package/bin/build/cds.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * This is the single depedency to @sap/cds/lib.
3
- * There shall be no other/direct dependencies from other modules in ./**.
4
- */
5
- module.exports = require ('../../lib')
@@ -1,66 +0,0 @@
1
- exports.BUILD_OPTION_OUTPUT_MODE = "outputMode"
2
-
3
- exports.OUTPUT_MODE_DEFAULT = "default"
4
- exports.OUTPUT_MODE_PREVIEW = "preview"
5
- exports.OUTPUT_MODE_RESULT_ONLY = "resultOnly"
6
-
7
- exports.BUILD_TASK_NPM_SCOPE = "@sap"
8
- exports.BUILD_TASK_PREFIX = exports.BUILD_TASK_NPM_SCOPE + "/cds/build"
9
- exports.BUILD_TASK_JAVA = "java"
10
- exports.BUILD_TASK_JAVA_CF = "java-cf"
11
- exports.BUILD_TASK_NODEJS = "nodejs"
12
- exports.BUILD_TASK_NODE_CF = "node-cf"
13
- exports.BUILD_TASK_HANA = "hana"
14
- exports.BUILD_TASK_FIORI = "fiori"
15
- exports.BUILD_TASK_MTX = "mtx"
16
- exports.BUILD_TASK_MTX_SIDECAR = "mtx-sidecar"
17
- exports.BUILD_TASK_MTX_EXTENSION = "mtx-extension"
18
- exports.BUILD_TASKS = [this.BUILD_TASK_JAVA, this.BUILD_TASK_JAVA_CF, this.BUILD_TASK_NODEJS, this.BUILD_TASK_NODE_CF, this.BUILD_TASK_HANA, this.BUILD_TASK_FIORI, this.BUILD_TASK_MTX, this.BUILD_TASK_MTX_SIDECAR, this.BUILD_TASK_MTX_EXTENSION]
19
-
20
- exports.ODATA_VERSION_V2 = "v2"
21
- exports.ODATA_VERSION_V4 = "v4"
22
-
23
- exports.BUILD_NODEJS_EDMX_GENERATION = "build.nodejs.edmxgeneration" // WebIDE Fullstack
24
- exports.EDMX_GENERATION = "edmxGeneration"
25
-
26
- exports.SKIP_MANIFEST_GENERATION = "skipManifestGeneration"
27
- exports.SKIP_PACKAGE_JSON_GENERATION = "skipPackageJsonGeneration"
28
- exports.SKIP_HDBTABLEDATA_GENERATION = "skipHdbtabledataGeneration"
29
-
30
- exports.CONTENT_LANGUAGE_BUNDLES = "contentLanguageBundles" // create i18n.json language bundles
31
- exports.CONTENT_DEFAULT_CSN = "contentDefaultCsn" // create default CSN format flavor: "inferred"
32
- exports.CONTENT_EDMX = "contentEdmx" // create EDMX for required languages
33
- exports.CONTENT_MANIFEST = "contentManifest" // create manifest.yml and .cfignore files
34
- exports.CONTENT_PACKAGE_JSON = "contentPackageJson" // create package.json file if not existing, or modify existing package.json
35
- exports.CONTENT_PACKAGELOCK_JSON = "contentPackageLockJson" // copy package-lock.json file if existing into deployment folder
36
- exports.CONTENT_HDBTABLEDATA = "contentHdbtabledata" // create .hdbtabledata files for .csv files if not existing
37
- exports.CONTENT_NPMRC = "contentNpmrc" // copy .npmrc file if existing into deployment folder
38
- exports.CONTENT_CDSRC_JSON = "contentCdsrcJson" // copy .cdsrc.json file if existing into deployment folder
39
- exports.CONTENT_NODE_MODULES = "contentNodeModules" // copy node_modules folder if existing into deployment folder
40
- exports.CONTENT_ENV = "contentEnv" // copy .env file if existing into deployment folder
41
- exports.CONTENT_DEFAULT_ENV_JSON = "contentDefaultEnvJson" // copy default-env.json file if existing into deployment folder
42
- exports.CSV_FILE_DETECTION = "csvFileDetection" // detect CSV files based on CDS model location
43
- exports.EXTENSION_POINT_VALIDATION = "extensionPointValidation" // validate extension point restrictions defined by the extended SaaS app
44
- exports.DEFAULT_BUILT_IN_MODELS = "defaultBuiltInModels" // add @sap/cds* built-in models to build tasks
45
-
46
- exports.FOLDER_GEN = "gen"
47
- exports.FILE_EXT_CDS = ".cds"
48
- exports.MTX_SIDECAR_FOLDER = "mtx/sidecar" // default name of the mtx sidecar folder
49
- exports.DEFAULT_CSN_FILE_NAME = "csn.json"
50
- // REVISIT: the models are not required if a custom server.js file is used for MTX bootstrap
51
- exports.NODEJS_MODEL_EXCLUDE_LIST = ['@sap/cds/srv/mtx', '@sap/cds-mtxs/srv/bootstrap']
52
-
53
- exports.CDS_CONFIG_PATH_SEP = "/"
54
- exports.SKIP_ASSERT_COMPILER_V2 = "skip-assert-compiler-v2"
55
- exports.SEVERITY_ERROR = "Error"
56
- exports.SEVERITY_WARNING = "Warning"
57
- exports.SEVERITY_INFO = "Info"
58
- exports.SEVERITY_DEBUG = "Debug"
59
- exports.SEVERITIES = [exports.SEVERITY_ERROR, exports.SEVERITY_WARNING, exports.SEVERITY_INFO, exports.SEVERITY_DEBUG]
60
- exports.LOG_LEVEL_ERROR = "error"
61
- exports.LOG_LEVEL_WARN = "warn"
62
- exports.LOG_LEVEL_INFO = "info"
63
- exports.LOG_LEVEL_DEBUG = "debug"
64
- exports.LOG_LEVELS = [exports.LOG_LEVEL_ERROR, exports.LOG_LEVEL_WARN, exports.LOG_LEVEL_INFO, exports.LOG_LEVEL_DEBUG]
65
- exports.LOG_MODULE_NAMES = "cds|build"
66
- exports.OVERRIDE_METHOD_MSG = "Must override method"
@@ -1,58 +0,0 @@
1
- const path = require('path')
2
- const fs = require('fs')
3
- const BuildTaskEngine = require('./buildTaskEngine')
4
- const BuildTaskFactory = require('./buildTaskFactory')
5
- const BuildTaskHandler = require('./buildTaskHandler')
6
- const { LOG_MODULE_NAMES } = require('./constants')
7
- const { BuildError } = require('./util')
8
-
9
- module.exports = Object.assign(build,
10
- { build, BuildTaskFactory, BuildTaskEngine, BuildTaskHandler, BuildError }
11
- )
12
-
13
- /**
14
- * New modular build.
15
- *
16
- * @param {object} options - command options as defined by build command.
17
- */
18
- async function build(options = {}) {
19
- const projectPath = path.resolve(options.project || '.')
20
- if (!fs.lstatSync(projectPath).isDirectory()) {
21
- return Promise.reject(`Project [${projectPath}] does not exist`)
22
- }
23
-
24
- const cds = require('./cds')
25
- const cdsEnv = cds.env, cdsRoot = cds.root
26
- if (projectPath !== process.cwd()) {
27
- const env = cds.env.for('cds', projectPath);
28
- cds.env = env // REVISIT: not good / fragile
29
- cds.root = projectPath // REVISIT: not good / fragile
30
- }
31
- const logger = options.logger || cds.log(LOG_MODULE_NAMES)
32
- const buildOptions = _mergeCliOptions({ root: cds.root }, options)
33
- const buildTaskFactory = new BuildTaskFactory(logger)
34
- const buildTaskEngine = new BuildTaskEngine(logger)
35
- let buildResult
36
-
37
- try {
38
- const tasks = await buildTaskFactory.getTasks(buildOptions)
39
- buildResult = await buildTaskEngine.processTasks(tasks, buildOptions)
40
- } catch (e) {
41
- // cds CLI layer logs if invoked from CLI
42
- if (!buildOptions.cli) {
43
- buildTaskEngine._logMessages(buildOptions, [e])
44
- }
45
- throw e
46
- } finally {
47
- cds.root = cdsRoot
48
- cds.env = cdsEnv
49
- }
50
- return buildResult
51
- }
52
-
53
- function _mergeCliOptions(buildOptions, options) {
54
- buildOptions["log-level"] = options["log-level"]
55
- buildOptions.cli = options.cli
56
- buildOptions.cmdOptions = options
57
- return buildOptions
58
- }
@@ -1,82 +0,0 @@
1
- const path = require('path')
2
- const cds = require('../cds')
3
- const BuildTaskHandlerFeatureToggles = require('./buildTaskHandlerFeatureToggles')
4
- const { BUILD_OPTION_OUTPUT_MODE, OUTPUT_MODE_RESULT_ONLY } = require('../constants')
5
-
6
- class BuildTaskHandlerEdmx extends BuildTaskHandlerFeatureToggles {
7
- async compileToEdmx(model, edmxDest, compileOptions = {}) { // NOSONAR
8
- const promises = []
9
-
10
- // generate edmx for services only that have the odata protocol
11
- const serviceNames = cds.reflect(model).services
12
- .filter(service => this._isOdataProtocol(service))
13
- .map(service => service.name)
14
-
15
- // TODO mtx build_helper tests currently expects this, strange...
16
- this._result.languages.add('')
17
-
18
- // new compile impl is throwing error in case no services exist!
19
- if (serviceNames.length > 0) {
20
- const options = {
21
- ...this._options4edmx(),
22
- ...compileOptions,
23
- serviceNames
24
- }
25
- this.logger._debug && this.logger.debug(`compiling edmx files using OData version ${options.version}`)
26
-
27
- const result = cds.compile.to.edmx(model, options)
28
-
29
- if (result) {
30
- let langs = this.task.options.lang || cds.env.i18n.languages
31
- if (langs.split) { // string to array
32
- langs = langs.split(',')
33
- }
34
- if (langs.length > 0 && langs[0] !== 'all' && langs.indexOf('') < 0) {
35
- langs.push('') // make sure fallback language is in, runtimes expect it
36
- }
37
- for (let [content, key] of result) {
38
- const serviceName = key.file ? key.file : key.name
39
- this._result.services.add(serviceName)
40
- const locResult = cds.localize(model, langs, content)
41
- if (locResult[Symbol.iterator]) { // multi result
42
- for (let [localizedContent, { lang }] of locResult) {
43
- promises.push(this._writeEdmxForLang(localizedContent, serviceName, lang, edmxDest))
44
- }
45
- } else { // single result
46
- promises.push(this._writeEdmxForLang(locResult, serviceName, langs[0], edmxDest))
47
- }
48
- }
49
- }
50
- }
51
- return Promise.all(promises)
52
- }
53
-
54
- _isOdataProtocol(srv) {
55
- return cds.service.protocols.protocol4(srv).startsWith('odata')
56
- }
57
-
58
- _options4odata() {
59
- const o = this.options()
60
- o.version = cds.env.odata.version
61
- return o
62
- }
63
-
64
- _options4edmx() {
65
- const o = this._options4odata()
66
- o.service = 'all'
67
- return o
68
- }
69
-
70
- _writeEdmxForLang(content, serviceName, lang, edmxDest) {
71
- this._result.languages.add(lang)
72
- const fileName = serviceName + (lang ? '_' + lang + '.xml' : '.xml')
73
- this._result.edmx.set(fileName, content)
74
-
75
- //edmxDest might be null
76
- if (edmxDest && !this.hasBuildOption(BUILD_OPTION_OUTPUT_MODE, OUTPUT_MODE_RESULT_ONLY)) {
77
- return this.write(content).to(path.join(edmxDest, fileName))
78
- }
79
- return Promise.resolve()
80
- }
81
- }
82
- module.exports = BuildTaskHandlerEdmx
@@ -1,131 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const cds = require('../cds')
4
- const { DEFAULT_CSN_FILE_NAME } = require('../constants')
5
- const BuildTaskHandlerInternal = require('./buildTaskHandlerInternal')
6
-
7
- class FeatureToggleBuilder extends BuildTaskHandlerInternal {
8
- init() {
9
- this._result = {
10
- dest: this.task.dest,
11
- csn: {},
12
- edmx: new Map(),
13
- languages: new Set(),
14
- services: new Set(),
15
- languageBundles: {}
16
- }
17
- }
18
-
19
- get ftsName() {
20
- return path.dirname(cds.env.features.folders || 'fts/*')
21
- }
22
-
23
- async compileAll(csn, destBase, destFts) {
24
- const sources = await this._resolveSourcePaths(csn)
25
- const dictionary = { base: null, features: null }
26
-
27
- if (sources.features) {
28
- // create base model as the given CSN is containing all features
29
- dictionary.base = await cds.load(sources.base, this.options())
30
- } else {
31
- // CSN already represents the base model as no features exist
32
- dictionary.base = csn
33
- }
34
- // preserve @location as @source properties
35
- const csnStr = await this.compileToJson(dictionary.base, path.join(destBase, DEFAULT_CSN_FILE_NAME))
36
- const csnModel = JSON.parse(csnStr)
37
- csnModel.meta = csn.meta
38
- this._result.csn = csnModel
39
-
40
- if (sources.features) {
41
- dictionary.features = await this._compileFeatures(sources.features, destBase, destFts)
42
- }
43
- return { dictionary, sources }
44
- }
45
-
46
- async collectAllLanguageBundles(dictionary, paths, destBase, destFts) {
47
- const i18nFolder = cds.env.i18n.folders?.[0] || 'i18n'
48
- // create language bundle for base model
49
- const i18n = await this.collectLanguageBundles(dictionary.base, path.join(destBase, i18nFolder))
50
- if (i18n) {
51
- this._result.languageBundles = i18n.bundles
52
- }
53
-
54
- if (dictionary.features) {
55
- // create language bundles for all features
56
- for (const ftName in dictionary.features) {
57
- // attach the sources information for i18n location reference
58
- dictionary.features[ftName]['$sources'] = paths.features[ftName]
59
- await this.collectLanguageBundles(dictionary.features[ftName], path.join(destFts, this.ftsName, ftName, i18nFolder))
60
- }
61
- }
62
- }
63
-
64
- async _resolveSourcePaths(csn) {
65
- const regex = new RegExp(path.resolve(this.buildOptions.root, this.ftsName).replace(/\\/g, '\\\\') + '[/|\\\\](?<ftName>[^/|\\\\]*)')
66
- let paths = { base: [] }
67
-
68
- // add ROOT source file paths for the base model
69
- paths.base = this._resolveModel().reduce((acc, file) => {
70
- const match = file.match(regex)
71
- if (!match) {
72
- acc.push(file)
73
- }
74
- return acc
75
- }, [])
76
-
77
- // keep existing behavior and return paths returned by cds.resolve if features are not supported by this project
78
- if (!fs.existsSync(path.join(this.buildOptions.root, this.ftsName))) {
79
- return paths
80
- }
81
-
82
- // add source file paths for the features
83
- paths.features = csn['$sources'].reduce((acc, file) => {
84
- const match = file.match(regex)
85
- if (match) {
86
- const { ftName } = match.groups
87
- //feature
88
- if (!acc[ftName]) {
89
- acc[ftName] = []
90
- }
91
- acc[ftName].push(file)
92
- }
93
- return acc
94
- }, {})
95
-
96
- return paths
97
- }
98
-
99
- async _compileFeatures(ftsPaths, destBase, destFts) {
100
- if (!ftsPaths) {
101
- return
102
- }
103
- const features = {}
104
- const options = { ...this.options(), flavor: 'parsed' }
105
-
106
- // create feature models
107
- for (const ftName in ftsPaths) {
108
- const ftCsn = await cds.load(ftsPaths[ftName], options)
109
- const ftPath = path.join(destFts, this.ftsName, ftName)
110
-
111
- // replace require paths by base model path to ensure precedence of feature annotations
112
- // see https://pages.github.tools.sap/cap/docs/cds/compiler-messages#anno-duplicate-unrelated-layer
113
- ftCsn.requires = [path.join(path.relative(ftPath, destBase), DEFAULT_CSN_FILE_NAME).replace(/\\/g, '/')]
114
-
115
- await this.compileToJson(ftCsn, path.join(ftPath, DEFAULT_CSN_FILE_NAME))
116
- await this._validateFeature(ftPath)
117
- features[ftName] = ftCsn
118
- }
119
- return features
120
- }
121
-
122
- async _validateFeature(ftPath) {
123
- // features must not have other than base model dependencies, cross feature dependencies are not supported
124
- // do not pass options.messages in order to avoid duplicate compiler messages
125
- return cds.load([ftPath])
126
- // version 2.13.9 of compileSources does not read the requires definition of parsed CSNs
127
- // require('@sap/cds-compiler').compileSources({ '../..csn.json': baseCsn, 'feature.csn': ftCsn }, this.options())
128
- }
129
- }
130
-
131
- module.exports = FeatureToggleBuilder