@sap/cds 6.8.4 → 7.0.0

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 (214) hide show
  1. package/CHANGELOG.md +58 -5
  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 +1 -1
  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 +1 -1
  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/srv-api.js +9 -3
  45. package/lib/srv/srv-dispatch.js +12 -9
  46. package/lib/srv/srv-models.js +4 -21
  47. package/lib/srv/srv-tx.js +15 -12
  48. package/lib/utils/cds-test.js +14 -9
  49. package/lib/utils/cds-utils.js +2 -12
  50. package/lib/utils/check-version.js +17 -0
  51. package/{bin/build → lib/utils}/csv-reader.js +23 -24
  52. package/libx/_runtime/auth/index.js +27 -23
  53. package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +15 -72
  54. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +1 -1
  55. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +0 -2
  56. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +33 -63
  57. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +14 -18
  58. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +15 -5
  59. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +5 -4
  60. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +37 -40
  61. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/updateToCQN.js +7 -1
  62. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +101 -38
  63. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/errors/AbstractError.js +5 -1
  64. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/ValueConverter.js +2 -1
  65. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/deserializer/ResourceJsonDeserializer.js +9 -8
  66. package/libx/_runtime/cds-services/adapter/odata-v4/to.js +1 -1
  67. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +15 -11
  68. package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +4 -0
  69. package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +5 -2
  70. package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +1 -123
  71. package/libx/_runtime/cds-services/services/Service.js +79 -107
  72. package/libx/_runtime/cds-services/services/utils/columns.js +23 -19
  73. package/libx/_runtime/cds-services/services/utils/compareJson.js +11 -1
  74. package/libx/_runtime/cds-services/services/utils/differ.js +7 -2
  75. package/libx/_runtime/cds-services/util/assert.js +65 -2
  76. package/libx/_runtime/common/composition/data.js +1 -0
  77. package/libx/_runtime/common/generic/auth/expand.js +1 -1
  78. package/libx/_runtime/common/generic/auth/restrict.js +5 -10
  79. package/libx/_runtime/common/generic/auth/restrictions.js +40 -0
  80. package/libx/_runtime/common/generic/auth/utils.js +1 -2
  81. package/libx/_runtime/common/generic/crud.js +32 -16
  82. package/libx/_runtime/common/generic/etag.js +133 -104
  83. package/libx/_runtime/common/generic/input.js +6 -21
  84. package/libx/_runtime/common/generic/put.js +1 -1
  85. package/libx/_runtime/common/generic/stream.js +52 -0
  86. package/libx/_runtime/common/generic/temporal.js +25 -8
  87. package/libx/_runtime/common/i18n/messages.properties +0 -2
  88. package/libx/_runtime/common/utils/cqn.js +1 -1
  89. package/libx/_runtime/common/utils/cqn2cqn4sql.js +5 -2
  90. package/libx/_runtime/common/utils/csn.js +0 -51
  91. package/libx/_runtime/common/utils/etag.js +30 -0
  92. package/libx/_runtime/common/utils/keys.js +1 -1
  93. package/libx/_runtime/common/utils/normalizeTimestamp.js +25 -0
  94. package/libx/_runtime/common/utils/path.js +1 -1
  95. package/libx/_runtime/common/utils/resolveView.js +2 -1
  96. package/libx/_runtime/common/utils/rewriteAsterisks.js +6 -4
  97. package/libx/_runtime/common/utils/search2cqn4sql.js +12 -16
  98. package/libx/_runtime/common/utils/stream.js +140 -0
  99. package/libx/_runtime/common/utils/streamProp.js +29 -12
  100. package/libx/_runtime/common/utils/templateProcessorPathSerializer.js +0 -2
  101. package/libx/_runtime/db/generic/index.js +0 -2
  102. package/libx/_runtime/db/query/delete.js +2 -2
  103. package/libx/_runtime/db/query/insert.js +2 -2
  104. package/libx/_runtime/db/query/read.js +2 -2
  105. package/libx/_runtime/db/query/run.js +2 -2
  106. package/libx/_runtime/db/query/update.js +2 -2
  107. package/libx/_runtime/db/sql-builder/BaseBuilder.js +0 -6
  108. package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +23 -12
  109. package/libx/_runtime/db/sql-builder/FunctionBuilder.js +18 -6
  110. package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -0
  111. package/libx/_runtime/db/sql-builder/SelectBuilder.js +3 -7
  112. package/libx/_runtime/db/sql-builder/UpsertBuilder.js +1 -0
  113. package/libx/_runtime/db/utils/normalizeTimeData.js +7 -3
  114. package/libx/_runtime/fiori/draft.js +2 -0
  115. package/libx/_runtime/fiori/generic/activate.js +8 -9
  116. package/libx/_runtime/fiori/generic/before.js +30 -20
  117. package/libx/_runtime/fiori/generic/cancel.js +5 -3
  118. package/libx/_runtime/fiori/generic/delete.js +5 -3
  119. package/libx/_runtime/fiori/generic/edit.js +7 -7
  120. package/libx/_runtime/fiori/generic/index.js +10 -16
  121. package/libx/_runtime/fiori/generic/new.js +5 -3
  122. package/libx/_runtime/fiori/generic/patch.js +11 -8
  123. package/libx/_runtime/fiori/generic/prepare.js +13 -6
  124. package/libx/_runtime/fiori/generic/read.js +12 -6
  125. package/libx/_runtime/fiori/lean-draft.js +207 -152
  126. package/libx/_runtime/fiori/utils/delete.js +10 -5
  127. package/libx/_runtime/fiori/utils/req.js +17 -5
  128. package/libx/_runtime/fiori/utils/stream.js +36 -0
  129. package/libx/_runtime/hana/Service.js +12 -9
  130. package/libx/_runtime/hana/conversion.js +10 -15
  131. package/libx/_runtime/hana/driver.js +2 -0
  132. package/libx/_runtime/hana/execute.js +28 -6
  133. package/libx/_runtime/hana/pool.js +36 -122
  134. package/libx/_runtime/hana/search2cqn4sql.js +34 -36
  135. package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +2 -6
  136. package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +3 -1
  137. package/libx/_runtime/messaging/enterprise-messaging.js +10 -58
  138. package/libx/_runtime/messaging/outbox/utils.js +1 -1
  139. package/libx/_runtime/remote/Service.js +20 -1
  140. package/libx/_runtime/remote/utils/client.js +3 -5
  141. package/libx/_runtime/sqlite/Service.js +4 -6
  142. package/libx/_runtime/sqlite/conversion.js +3 -13
  143. package/libx/_runtime/sqlite/customBuilder/CustomFunctionBuilder.js +9 -6
  144. package/libx/_runtime/sqlite/customBuilder/CustomUpsertBuilder.js +6 -1
  145. package/libx/_runtime/sqlite/execute.js +5 -16
  146. package/libx/odata/afterburner.js +22 -6
  147. package/libx/odata/grammar.pegjs +6 -1
  148. package/libx/odata/parser.js +1 -1
  149. package/libx/rest/RestAdapter.js +16 -9
  150. package/libx/rest/RestRequest.js +1 -1
  151. package/libx/rest/middleware/input.js +2 -1
  152. package/libx/rest/middleware/operation.js +1 -0
  153. package/libx/rest/middleware/parse.js +3 -2
  154. package/libx/rest/middleware/payload.js +9 -8
  155. package/libx/rest/middleware/read.js +1 -0
  156. package/package.json +9 -16
  157. package/app/fiori/preview.js +0 -270
  158. package/app/fiori/routes.js +0 -59
  159. package/bin/build/buildTaskEngine.js +0 -360
  160. package/bin/build/buildTaskFactory.js +0 -283
  161. package/bin/build/buildTaskHandler.js +0 -241
  162. package/bin/build/buildTaskProvider.js +0 -22
  163. package/bin/build/buildTaskProviderFactory.js +0 -175
  164. package/bin/build/cds.js +0 -5
  165. package/bin/build/constants.js +0 -66
  166. package/bin/build/index.js +0 -58
  167. package/bin/build/provider/buildTaskHandlerEdmx.js +0 -82
  168. package/bin/build/provider/buildTaskHandlerFeatureToggles.js +0 -131
  169. package/bin/build/provider/buildTaskHandlerInternal.js +0 -254
  170. package/bin/build/provider/buildTaskProviderInternal.js +0 -383
  171. package/bin/build/provider/fiori/index.js +0 -171
  172. package/bin/build/provider/hana/2migration.js +0 -179
  173. package/bin/build/provider/hana/index.js +0 -505
  174. package/bin/build/provider/hana/migrationtable.js +0 -472
  175. package/bin/build/provider/hana/template/.hdiconfig-haas +0 -163
  176. package/bin/build/provider/hana/template/.hdiconfig-hanacloud +0 -137
  177. package/bin/build/provider/hana/template/.hdinamespace +0 -4
  178. package/bin/build/provider/hana/template/package.json +0 -12
  179. package/bin/build/provider/hana/template/undeploy.json +0 -5
  180. package/bin/build/provider/java/index.js +0 -111
  181. package/bin/build/provider/java-cf/index.js +0 -1
  182. package/bin/build/provider/mtx/index.js +0 -268
  183. package/bin/build/provider/mtx/resourcesTarBuilder.js +0 -95
  184. package/bin/build/provider/mtx-extension/index.js +0 -131
  185. package/bin/build/provider/mtx-sidecar/index.js +0 -137
  186. package/bin/build/provider/node-cf/index.js +0 -1
  187. package/bin/build/provider/nodejs/index.js +0 -192
  188. package/bin/build/util.js +0 -299
  189. package/bin/cds.js +0 -125
  190. package/bin/deploy/to-hana/cfUtil.js +0 -355
  191. package/bin/deploy/to-hana/gitUtil.js +0 -57
  192. package/bin/deploy/to-hana/hana.js +0 -306
  193. package/bin/deploy/to-hana/hdiDeployUtil.js +0 -153
  194. package/bin/deploy/to-hana/index.js +0 -16
  195. package/bin/deploy/to-hana/mtaUtil.js +0 -170
  196. package/bin/mtx/in-cds.js +0 -17
  197. package/bin/plugins.js +0 -32
  198. package/bin/run.js +0 -24
  199. package/bin/utils/log.js +0 -24
  200. package/bin/version.js +0 -178
  201. package/libx/_runtime/audit/Service.js +0 -222
  202. package/libx/_runtime/audit/generic/personal/access.js +0 -61
  203. package/libx/_runtime/audit/generic/personal/index.js +0 -56
  204. package/libx/_runtime/audit/generic/personal/modification.js +0 -132
  205. package/libx/_runtime/audit/generic/personal/utils.js +0 -186
  206. package/libx/_runtime/audit/utils/log.js +0 -23
  207. package/libx/_runtime/audit/utils/v2.js +0 -176
  208. package/libx/_runtime/db/data-conversion/timestamp.js +0 -9
  209. package/libx/_runtime/db/generic/integrity.js +0 -455
  210. package/srv/audit-log.cds +0 -87
  211. package/srv/mtx.cds +0 -2
  212. package/srv/mtx.js +0 -8
  213. /package/lib/{core → linked}/classes.js +0 -0
  214. /package/lib/{core → linked}/entities.js +0 -0
package/bin/build/util.js DELETED
@@ -1,299 +0,0 @@
1
- const fs = require('fs')
2
- const path = require('path')
3
- const cds = require('./cds')
4
- const { SEVERITY_ERROR, FILE_EXT_CDS } = require('./constants')
5
-
6
- function getProperty(src, segments) {
7
- segments = Array.isArray(segments) ? segments : segments.split('.')
8
- return segments.reduce((p, n) => p && p[n], src)
9
- }
10
-
11
- function setProperty(src, segments, value) {
12
- segments = Array.isArray(segments) ? segments : segments.split('.')
13
- segments.reduce((p, n, idx) => {
14
- if (segments.length === idx + 1) {
15
- p[n] = value
16
- } else {
17
- if (p[n] === undefined) {
18
- p[n] = {}
19
- }
20
- }
21
- return p[n]
22
- }, src)
23
- }
24
-
25
- /**
26
- * Returns an array of pom.xml file paths found in the given directories.
27
- * @param {Array} dirs - the absolute path names to check.
28
- */
29
- function readPomFilePaths(dirs) {
30
- return dirs.flat().reduce((acc, dir) => {
31
- if (dir) {
32
- const file = path.join(dir, 'pom.xml')
33
- if (fs.existsSync(file)) {
34
- acc.push(file)
35
- }
36
- }
37
- return acc
38
- }, [])
39
- }
40
-
41
- /**
42
- * Returns whether this project is a java project or not.
43
- * @param {Array} dirs - the absolute path names to check.
44
- */
45
- function hasJavaNature(dirs) {
46
- return readPomFilePaths(dirs).length > 0
47
- }
48
-
49
- /**
50
- * Determines whether the both values are identical.
51
- * @param {*} actual
52
- * @param {*} expected
53
- */
54
- function hasOptionValue(actual, expected) {
55
- if (typeof expected === 'undefined') {
56
- return actual !== undefined
57
- }
58
- if (typeof actual === 'undefined') {
59
- return false
60
- }
61
- if (typeof expected === 'boolean') {
62
- if (typeof actual === 'string') {
63
- return String(expected) === actual
64
- }
65
- }
66
- return actual === expected
67
- }
68
-
69
- // Returning the project relative path representation of the given path(s),
70
- function relativePaths(root, qualifiedPaths) {
71
- qualifiedPaths = typeof qualifiedPaths === "string" ? [qualifiedPaths] : qualifiedPaths
72
- if (Array.isArray(qualifiedPaths)) {
73
- return qualifiedPaths.map(qualifiedPath => {
74
- const relPath = path.relative(root, qualifiedPath)
75
- return relPath || "."
76
- })
77
- }
78
- return qualifiedPaths
79
- }
80
-
81
- /**
82
- * Returns <code>true</code> if this project is an old java service-sdk project,
83
- * <code>false</code> if it is a java-NG project or if no pom.xml has been found.
84
- * @param {Array} dirs - the absolute path names to check.
85
- */
86
- async function isOldJavaStack(dirs) {
87
- const files = readPomFilePaths(dirs)
88
- if (files.length > 0) {
89
- return (await Promise.all(files.map(async file => {
90
- const content = await fs.promises.readFile(file, 'utf-8')
91
- return content && /<groupId>\s*com\.sap\.cloud\.servicesdk\.prov\s*<\/groupId>/.test(content)
92
- }))).some(result => result)
93
- }
94
- return false
95
- }
96
-
97
- function redactCredentials(config, o) {
98
- return JSON.stringify(config, (k, v) => {
99
- if (!v) {
100
- return v
101
- }
102
- if (k === 'credentials') {
103
- try {
104
- return _redacted(v)
105
- } catch (e) {/* ignored */ }
106
- }
107
- return v
108
- }, o && o.indents || 2)
109
- }
110
-
111
- /** redacts password-like strings, also reducing clutter in output */
112
- function _redacted(cred) {
113
- const secrets = /(password)|(certificate)|(ca)/i // 'certificate' and 'ca' on HANA
114
- const newCred = Object.assign({}, cred)
115
- Object.keys(newCred)
116
- .filter(k => typeof newCred[k] === 'string' && secrets.test(k))
117
- .forEach(k => newCred[k] = '...')
118
- return newCred
119
- }
120
-
121
- /**
122
- * Distinguishes whether the Nodejs project is a Streamlined MTX (cds >=6) or an old MTX project.
123
- */
124
- function isStreamlinedMtx() {
125
- if (cds.utils._oldMtx()) {
126
- return false
127
- }
128
- return (cds.env.requires.toggles
129
- || cds.env.profiles.includes('with-mtx-sidecar') // new presets
130
- || cds.env.requires['cds.xt.ModelProviderService']
131
- || (typeof cds.env.requires.multitenancy === "object")
132
- ) && !(() => { try { return cds.mtx } catch (e) { /**/ } })()
133
- }
134
-
135
- /**
136
- * Returns a list of fully qualified model names belonging to the '@sap' namespace that cannot be resolved.
137
- * E.g. the module might NOT have been installed.
138
- * @param {Array} modelPaths
139
- * @returns {Array}
140
- */
141
- function resolveRequiredSapModels(modelPaths) {
142
- return Array.isArray(modelPaths) && modelPaths.filter(p => {
143
- if (p.startsWith('@sap/')) {
144
- const files = cds.resolve(p)
145
- return !files || files.length === 0
146
- }
147
- })
148
- }
149
-
150
- function getDefaultModelOptions(projectPath) {
151
- const fts = cds.env.features.folders
152
- const modelPaths = cds.resolve(!fts ? '*' : ['*', fts], false)
153
- return _pushModelPaths(projectPath, modelPaths)
154
- }
155
-
156
- function _pushModelPaths(projectPath, ...modelPaths) {
157
- const model = new Set()
158
- // may contain nested arrays
159
- modelPaths = flatten(modelPaths)
160
- const { roots } = cds.env
161
- modelPaths.forEach(m => {
162
- if (m && !model.has(m) && !model.has(m + "/")) {
163
- // filter root model paths that do not exist
164
- // other entries are added as is, e.g. reuse model entries
165
- if (roots.includes(m)) {
166
- const dir = path.resolve(projectPath, m)
167
- if (fs.existsSync(dir)) {
168
- model.add(m.replace(/\/$/, ''))
169
- } else if (fs.existsSync(dir + FILE_EXT_CDS)) { //might be cds file name, compatibility to old build configs
170
- model.add(m)
171
- }
172
- } else {
173
- model.add(m)
174
- }
175
- }
176
- })
177
- return [...model]
178
- }
179
-
180
- function flatten(modelPaths) {
181
- return modelPaths.reduce((acc, m) => {
182
- if (Array.isArray(m)) {
183
- acc = acc.concat(flatten(m))
184
- } else if (m) {
185
- acc.push(m)
186
- }
187
- return acc
188
- }, [])
189
- }
190
-
191
- /**
192
- * Copy a file or directory. The directory can have contents.
193
- * REVISIT: 'fs.promises.cp' replacement for nodejs 14
194
- * @param src <String> Note that if src is a directory it will copy everything inside of this directory, not the entire directory itself.
195
- * @param dest <String> Note that if src is a file, dest cannot be a directory.
196
- */
197
- async function copy(src, dest) {
198
- if ((await fs.promises.stat(src)).isDirectory()) {
199
- const entries = await fs.promises.readdir(src)
200
- return Promise.all(entries.map(async each => copy(path.join(src, each), path.join(dest, each))))
201
- } else {
202
- await fs.promises.mkdir(path.dirname(dest), { recursive: true })
203
- return fs.promises.copyFile(src, dest)
204
- }
205
- }
206
-
207
- /**
208
- * Return gnu-style error string for location `loc`:
209
- * - 'File:Line:Col' without `loc.end`
210
- * - 'File:Line:StartCol-EndCol' if Line = start.line = end.line
211
- * - 'File:StartLine.StartCol-EndLine.EndCol' otherwise
212
- *
213
- * @param {CSN.Location|CSN.Location} location
214
- */
215
- function _locationString(loc) {
216
- if (!loc)
217
- return '<???>';
218
- if (!(loc instanceof Object))
219
- return loc;
220
- if (!loc.line) {
221
- return loc.file;
222
- }
223
- else if (!loc.endLine) {
224
- return (loc.col)
225
- ? `${loc.file}:${loc.line}:${loc.col}`
226
- : `${loc.file}:${loc.line}`;
227
- }
228
-
229
- return (loc.line === loc.endLine)
230
- ? `${loc.file}:${loc.line}:${loc.col}-${loc.endCol}`
231
- : `${loc.file}:${loc.line}.${loc.col}-${loc.endLine}.${loc.endCol}`;
232
- }
233
-
234
- /**
235
- * Class for individual build message.
236
- *
237
- * @class BuildMessage
238
- */
239
- class BuildMessage {
240
- /**
241
- * Creates an instance of BuildMessage.
242
- * @param {string} message The message text
243
- * @param {string} [severity='Error'] Severity: Debug, Info, Warning, Error
244
- * @param {any} location Location of the message
245
- *
246
- * @memberOf BuildMessage
247
- */
248
- constructor(message, severity = SEVERITY_ERROR, location) {
249
- this.message = message
250
- this.name = "BuildMessage"
251
- this.severity = severity
252
- this.$location = location
253
- }
254
- toString() {
255
- return `${this.$location?.file ? _locationString(this.$location) + ':' : ''} ${this.severity}: ${this.message}`
256
- }
257
- }
258
-
259
- /**
260
- * Class for combined build and compiler errors.
261
- * Additional members:
262
- * messages: vector of detailed build messages
263
- * @class BuildError
264
- * @extends {Error}
265
- */
266
- class BuildError extends Error {
267
- constructor(message, messages = []) {
268
- super(message)
269
- this.name = "BuildError"
270
- this.messages = Array.isArray(messages) ? messages : [messages]
271
- this.stack = ""
272
- }
273
-
274
- // for compatibility reasons
275
- get errors() {
276
- return this.messages
277
- }
278
-
279
- toString() {
280
- return this.message + (this.messages.length > 0 ? '\n' + this.messages.map(m => m.toString()).join('\n') : '')
281
- }
282
- }
283
-
284
- module.exports = {
285
- getProperty,
286
- setProperty,
287
- hasJavaNature,
288
- isOldJavaStack,
289
- redactCredentials,
290
- hasOptionValue,
291
- relativePaths,
292
- isStreamlinedMtx,
293
- resolveRequiredSapModels,
294
- getDefaultModelOptions,
295
- flatten,
296
- copy,
297
- BuildMessage,
298
- BuildError
299
- }
package/bin/cds.js DELETED
@@ -1,125 +0,0 @@
1
- #!/usr/bin/env node
2
- const cds = require('../lib') //> ensure we are the first to load @sap/cds locally
3
- const cli = { //NOSONAR
4
-
5
- Shortcuts: {
6
- s: 'serve',
7
- v: 'version', '-v':'version', '--version':'version'
8
- },
9
-
10
- exec (cmd = process.argv[2], ...argv) {
11
- if (!argv.length) argv = process.argv.slice(3)
12
- if (cmd in this.Shortcuts) cmd = process.argv[2] = this.Shortcuts[cmd]
13
- if (!module.parent && ['serve', 'run'].includes(cmd)) _deprecationHint(cmd)
14
-
15
- const task = this.load ('./'+cmd)
16
-
17
- let args = []
18
- try {
19
- if (task && cmd !== 'build') args = this.args(task, argv)
20
- }
21
- catch (err) { process.exitCode = 1; return console.error(err) }
22
-
23
- if (task && cmd !== 'build') return task.apply (this, args)
24
-
25
- // delegate to cds-dk for rest of commands (usually shortcuts like `cds c` including cds build if cds-dk is available)
26
- const dk = _requireDk('cds')
27
- if (dk) return dk.exec(cmd, ...argv)
28
- if (cmd === 'build') return task.apply (this, args)
29
- _die_needsDk (cmd)
30
- },
31
-
32
- load (cmd) {
33
- return _require ('./'+cmd) || _requireDk (cmd)
34
- },
35
-
36
- help (cmd) { return this.exec ('help', cmd) },
37
-
38
- args (task, argv) {
39
-
40
- const { options:o=[], flags:f=[], shortcuts:s=[] } = task
41
- const _global = /^--(profile|production|sql|odata|build-.*|cdsc-.*|odata-.*|folders-.*)$/
42
- const _flags = { '--production':true }
43
- const options = {}, args = []
44
- let k,a, env = null
45
-
46
- if (argv.length) for (let i=0; i < argv.length; ++i) {
47
- if ((a = argv[i])[0] !== '-') args.push(a)
48
- else if ((k = s.indexOf(a)) >= 0) k < o.length ? add(o[k],argv[++i]) : add(f[k-o.length])
49
- else if ((k = o.indexOf(a)) >= 0) add(o[k],argv[++i])
50
- else if ((k = f.indexOf(a)) >= 0) add(f[k])
51
- else if (_global.test(a)) add_global(a, _flags[a] || argv[++i])
52
- else throw 'Invalid option: '+ a
53
- }
54
-
55
- function add (k,v) { options[k.slice(2)] = v || true }
56
- function add_global (k,v='') {
57
- if (k === '--production') return process.env.NODE_ENV = 'production'
58
- if (k === '--profile') return process.env.CDS_ENV = v.split(',')
59
- if (k === '--odata') v = { flavor:v }
60
- let e=env || (env={}), path = k.slice(2).split('-')
61
- while (path.length > 1) { let p = path.shift(); e = e[p]||(e[p]={}) }
62
- add (k, e[path[0]] = v)
63
- }
64
-
65
- if (env) cds.env.add (env)
66
- return [ args, options ]
67
- },
68
-
69
- errorHandlers () {
70
- // for compatibility with lkg -> remove after next release of cds-dk
71
- },
72
-
73
- get log() { return this.log = require('./utils/log') }
74
- }
75
-
76
- const _require = (id,o) => {
77
- try { var resolved = require.resolve(id,o) } catch(e){ return }
78
- return require (resolved)
79
- }
80
-
81
- const _requireDk = (cmd) => {
82
- const { npmGlobalModules } = require('./utils/modules')
83
- return _require ('@sap/cds-dk/bin/'+cmd) // if dk is in installed modules
84
- || _require (npmGlobalModules()+'/@sap/cds-dk/bin/'+cmd) // needed for running cds in npm scripts
85
- }
86
-
87
- const _die_needsDk = (cmd) => {
88
- const dk = {add:1,build:1,compile:1,deploy:1,env:1,eval:1,help:1,import:1,init:1,repl:1,watch:1}
89
- let message
90
- if (!cmd) { message = `
91
- Install '@sap/cds-dk' to use cds:\n
92
- npm i -g @sap/cds-dk\n`
93
- }
94
- else if (cmd in dk) { message = `
95
- 'cds ${cmd}' needs '@sap/cds-dk' to be installed. Get it with:\n
96
- npm i -g @sap/cds-dk\n`
97
- }
98
- else { message = `
99
- Unknown command '${cmd}'. Install '@sap/cds-dk', then try again:\n
100
- npm i -g @sap/cds-dk\n`
101
- }
102
- process.exitCode = 1
103
- return console.error (message)
104
- }
105
-
106
- function _deprecationHint(cmd) {
107
- console.error(require('./utils/term').warn(`
108
- Warning: \`cds ${cmd}\` will be removed with the next major version.
109
- Use \`cds-serve\` instead in your start script. Set it with:
110
-
111
- npm pkg set scripts.start="cds-serve"
112
- `))
113
- }
114
-
115
- require('util').inspect.defaultOptions = {
116
- colors: !!process.stdout.isTTY && !!process.stderr.isTTY,
117
- depth:11, breakLength:111
118
- }
119
- if (process[Symbol.for('ts-node.register.instance')]) {
120
- process.env.CDS_TYPESCRIPT = process.env.CDS_TYPESCRIPT || 'true'
121
- }
122
-
123
- module.exports = Object.assign ((..._) => cli.exec(..._), cli)
124
- if (!module.parent) cli.exec()
125
- /* eslint no-console:off */