@sap/cds 5.4.6 → 5.5.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 (228) hide show
  1. package/CHANGELOG.md +208 -2
  2. package/apis/ql.d.ts +17 -15
  3. package/app/index.js +1 -1
  4. package/bin/build/buildTaskEngine.js +26 -42
  5. package/bin/build/buildTaskFactory.js +6 -10
  6. package/bin/build/buildTaskHandler.js +2 -4
  7. package/bin/build/buildTaskProvider.js +3 -1
  8. package/bin/build/buildTaskProviderFactory.js +9 -15
  9. package/bin/build/constants.js +15 -3
  10. package/bin/build/index.js +5 -4
  11. package/bin/build/mtaUtil.js +8 -11
  12. package/bin/build/provider/buildTaskHandlerEdmx.js +63 -6
  13. package/bin/build/provider/buildTaskHandlerInternal.js +2 -34
  14. package/bin/build/provider/buildTaskProviderInternal.js +16 -42
  15. package/bin/build/provider/fiori/index.js +13 -24
  16. package/bin/build/provider/hana/2migration.js +17 -15
  17. package/bin/build/provider/hana/2tabledata.js +52 -48
  18. package/bin/build/provider/hana/index.js +27 -25
  19. package/bin/build/provider/hana/migrationtable.js +91 -67
  20. package/bin/build/provider/java-cf/index.js +14 -24
  21. package/bin/build/provider/mtx/index.js +12 -14
  22. package/bin/build/provider/node-cf/index.js +18 -32
  23. package/bin/cds.js +5 -5
  24. package/bin/serve.js +29 -23
  25. package/bin/version.js +0 -1
  26. package/lib/compile/etc/_localized.js +4 -9
  27. package/lib/compile/for/sql.js +5 -2
  28. package/lib/compile/parse.js +25 -17
  29. package/lib/compile/to/srvinfo.js +2 -1
  30. package/lib/connect/bindings.js +2 -1
  31. package/lib/connect/index.js +48 -49
  32. package/lib/core/classes.js +1 -1
  33. package/lib/core/reflect.js +10 -2
  34. package/lib/deploy.js +26 -23
  35. package/lib/env/defaults.js +13 -6
  36. package/lib/env/index.js +73 -78
  37. package/lib/env/requires.js +38 -19
  38. package/lib/index.js +9 -10
  39. package/lib/lazy.js +2 -2
  40. package/lib/log/index.js +33 -45
  41. package/lib/log/service/index.js +2 -2
  42. package/lib/ql/CREATE.js +14 -9
  43. package/lib/ql/DELETE.js +6 -5
  44. package/lib/ql/DROP.js +12 -9
  45. package/lib/ql/INSERT.js +40 -16
  46. package/lib/ql/Query.js +67 -40
  47. package/lib/ql/SELECT.js +162 -127
  48. package/lib/ql/UPDATE.js +74 -42
  49. package/lib/ql/Whereable.js +77 -87
  50. package/lib/ql/index.js +36 -24
  51. package/lib/ql/parse.js +35 -0
  52. package/lib/req/context.js +44 -8
  53. package/lib/req/locale.js +7 -7
  54. package/lib/serve/Service-api.js +21 -14
  55. package/lib/serve/Service-dispatch.js +28 -12
  56. package/lib/serve/Transaction.js +22 -10
  57. package/lib/serve/index.js +16 -11
  58. package/lib/utils/axios.js +23 -16
  59. package/lib/utils/data.js +35 -0
  60. package/lib/utils/tests.js +27 -18
  61. package/libx/_runtime/audit/generic/personal/access.js +81 -0
  62. package/libx/_runtime/audit/generic/personal/constants.js +4 -0
  63. package/libx/_runtime/audit/generic/personal/index.js +50 -0
  64. package/libx/_runtime/audit/generic/personal/modification.js +138 -0
  65. package/libx/_runtime/audit/generic/personal/utils.js +186 -0
  66. package/libx/_runtime/audit/utils/v2.js +10 -4
  67. package/libx/_runtime/cds-services/adapter/odata-v4/Dispatcher.js +5 -5
  68. package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +6 -7
  69. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +5 -7
  70. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +5 -7
  71. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/delete.js +2 -3
  72. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +4 -0
  73. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +7 -4
  74. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +59 -8
  75. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +11 -1
  76. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +6 -10
  77. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +3 -46
  78. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/applyToCQN.js +2 -5
  79. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/createToCQN.js +2 -2
  80. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/deleteToCQN.js +4 -3
  81. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +1 -2
  82. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/index.js +0 -1
  83. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/selectHelper.js +1 -1
  84. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/updateToCQN.js +2 -2
  85. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +16 -18
  86. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/edm/EdmEntityType.js +6 -3
  87. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/format/RepresentationKind.js +4 -1
  88. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/core/OdataRequest.js +1 -0
  89. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/SerializerFactory.js +15 -2
  90. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/validator/OperationValidator.js +1 -0
  91. package/libx/_runtime/cds-services/adapter/odata-v4/to.js +1 -1
  92. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +8 -1
  93. package/libx/_runtime/cds-services/adapter/odata-v4/utils/handlerUtils.js +6 -1
  94. package/libx/_runtime/cds-services/adapter/odata-v4/utils/omitValues.js +12 -5
  95. package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +1 -7
  96. package/libx/_runtime/cds-services/adapter/odata-v4/utils/request.js +7 -7
  97. package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +14 -18
  98. package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +13 -13
  99. package/libx/_runtime/cds-services/adapter/rest/handlers/create.js +0 -1
  100. package/libx/_runtime/cds-services/adapter/rest/handlers/operation.js +2 -1
  101. package/libx/_runtime/cds-services/adapter/rest/handlers/read.js +2 -2
  102. package/libx/_runtime/cds-services/adapter/rest/rest-to-cqn/index.js +2 -4
  103. package/libx/_runtime/cds-services/adapter/rest/utils/result.js +4 -2
  104. package/libx/_runtime/cds-services/services/Service.js +40 -5
  105. package/libx/_runtime/cds-services/services/utils/columns.js +13 -7
  106. package/libx/_runtime/cds-services/services/utils/compareJson.js +88 -4
  107. package/libx/_runtime/cds-services/services/utils/differ.js +24 -6
  108. package/libx/_runtime/cds-services/services/utils/handlerUtils.js +2 -2
  109. package/libx/_runtime/common/composition/data.js +44 -55
  110. package/libx/_runtime/common/composition/delete.js +97 -71
  111. package/libx/_runtime/common/composition/index.js +2 -1
  112. package/libx/_runtime/common/composition/insert.js +34 -11
  113. package/libx/_runtime/common/composition/tree.js +119 -92
  114. package/libx/_runtime/common/composition/update.js +4 -1
  115. package/libx/_runtime/common/composition/utils.js +1 -3
  116. package/libx/_runtime/common/constants/draft.js +12 -1
  117. package/libx/_runtime/common/generic/auth.js +6 -22
  118. package/libx/_runtime/common/generic/crud.js +14 -13
  119. package/libx/_runtime/common/generic/input.js +23 -26
  120. package/libx/_runtime/common/generic/put.js +1 -1
  121. package/libx/_runtime/common/generic/sorting.js +16 -16
  122. package/libx/_runtime/common/i18n/index.js +1 -1
  123. package/libx/_runtime/common/i18n/messages.properties +4 -0
  124. package/libx/_runtime/common/utils/backlinks.js +12 -5
  125. package/libx/_runtime/common/utils/cqn.js +6 -1
  126. package/libx/_runtime/common/utils/cqn2cqn4sql.js +102 -101
  127. package/libx/_runtime/common/utils/csn.js +47 -4
  128. package/libx/_runtime/common/utils/data.js +0 -37
  129. package/libx/_runtime/common/utils/enrichWithKeysFromWhere.js +1 -1
  130. package/libx/_runtime/common/utils/entityFromCqn.js +7 -24
  131. package/libx/_runtime/common/utils/foreignKeyPropagations.js +39 -7
  132. package/libx/_runtime/common/utils/generateOnCond.js +11 -12
  133. package/libx/_runtime/common/utils/onlyKeysRemain.js +10 -0
  134. package/libx/_runtime/common/utils/path.js +35 -0
  135. package/libx/_runtime/common/utils/postProcessing.js +86 -0
  136. package/libx/_runtime/common/utils/quotingStyles.js +37 -26
  137. package/libx/_runtime/common/utils/resolveView.js +223 -171
  138. package/libx/_runtime/common/utils/rewriteAsterisk.js +46 -26
  139. package/libx/_runtime/common/utils/structured.js +6 -12
  140. package/libx/_runtime/common/utils/template.js +10 -5
  141. package/libx/_runtime/common/utils/templateDelimiter.js +1 -0
  142. package/libx/_runtime/common/utils/templateProcessor.js +22 -30
  143. package/libx/_runtime/common/utils/union.js +31 -0
  144. package/libx/_runtime/common/utils/unionCqnTemplate.js +184 -0
  145. package/libx/_runtime/db/Service.js +1 -1
  146. package/libx/_runtime/db/data-conversion/timestamp.js +2 -9
  147. package/libx/_runtime/db/expand/expandCQNToJoin.js +204 -297
  148. package/libx/_runtime/db/expand/index.js +3 -3
  149. package/libx/_runtime/db/expand/rawToExpanded.js +36 -7
  150. package/libx/_runtime/db/generic/index.js +1 -1
  151. package/libx/_runtime/db/generic/input.js +5 -7
  152. package/libx/_runtime/db/generic/integrity.js +1 -1
  153. package/libx/_runtime/db/generic/rewrite.js +2 -10
  154. package/libx/_runtime/db/generic/update.js +13 -5
  155. package/libx/_runtime/db/generic/virtual.js +22 -58
  156. package/libx/_runtime/db/query/delete.js +7 -4
  157. package/libx/_runtime/db/query/insert.js +6 -4
  158. package/libx/_runtime/db/query/read.js +13 -20
  159. package/libx/_runtime/db/query/run.js +4 -1
  160. package/libx/_runtime/db/query/update.js +5 -4
  161. package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +35 -2
  162. package/libx/_runtime/db/sql-builder/FunctionBuilder.js +17 -2
  163. package/libx/_runtime/db/sql-builder/InsertBuilder.js +6 -5
  164. package/libx/_runtime/db/sql-builder/ReferenceBuilder.js +10 -0
  165. package/libx/_runtime/db/sql-builder/SelectBuilder.js +35 -24
  166. package/libx/_runtime/db/sql-builder/UpdateBuilder.js +14 -4
  167. package/libx/_runtime/db/sql-builder/arrayed.js +4 -0
  168. package/libx/_runtime/db/utils/deep.js +8 -0
  169. package/libx/_runtime/db/utils/generateAliases.js +2 -1
  170. package/libx/_runtime/fiori/generic/activate.js +19 -15
  171. package/libx/_runtime/fiori/generic/before.js +3 -11
  172. package/libx/_runtime/fiori/generic/cancel.js +1 -1
  173. package/libx/_runtime/fiori/generic/delete.js +3 -1
  174. package/libx/_runtime/fiori/generic/edit.js +12 -2
  175. package/libx/_runtime/fiori/generic/new.js +5 -5
  176. package/libx/_runtime/fiori/generic/patch.js +0 -18
  177. package/libx/_runtime/fiori/generic/read.js +241 -189
  178. package/libx/_runtime/fiori/utils/delete.js +36 -7
  179. package/libx/_runtime/fiori/utils/handler.js +43 -44
  180. package/libx/_runtime/fiori/utils/where.js +30 -15
  181. package/libx/_runtime/hana/customBuilder/CustomSelectBuilder.js +4 -6
  182. package/libx/_runtime/hana/execute.js +2 -2
  183. package/libx/_runtime/hana/localized.js +4 -4
  184. package/libx/_runtime/hana/pool.js +29 -14
  185. package/libx/_runtime/hana/search2cqn4sql.js +2 -1
  186. package/libx/_runtime/hana/searchToContains.js +18 -14
  187. package/libx/_runtime/index.js +0 -5
  188. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +13 -5
  189. package/libx/_runtime/messaging/common-utils/naming-conventions.js +4 -1
  190. package/libx/_runtime/messaging/enterprise-messaging-utils/EMManagement.js +31 -19
  191. package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +1 -2
  192. package/libx/_runtime/messaging/enterprise-messaging.js +6 -4
  193. package/libx/_runtime/messaging/service.js +7 -6
  194. package/libx/_runtime/odata/cqn2odata.js +110 -43
  195. package/libx/_runtime/odata/index.js +26 -48
  196. package/libx/_runtime/odata/odata2cqn.js +1 -6154
  197. package/libx/_runtime/odata/odata2cqn.pegjs +559 -0
  198. package/libx/_runtime/odata/readToCqn.js +94 -64
  199. package/libx/_runtime/remote/Service.js +74 -21
  200. package/libx/_runtime/remote/cqn2odata/index.js +1 -5
  201. package/libx/_runtime/remote/utils/client.js +24 -101
  202. package/libx/_runtime/remote/utils/dataConversion.js +27 -12
  203. package/libx/_runtime/sqlite/Service.js +3 -5
  204. package/libx/_runtime/sqlite/execute.js +23 -24
  205. package/libx/_runtime/sqlite/localized.js +12 -7
  206. package/libx/_runtime/types/api.js +10 -0
  207. package/package.json +1 -1
  208. package/server.js +16 -2
  209. package/lib/ql/grammar.pegjs +0 -208
  210. package/lib/ql/parser.js +0 -1
  211. package/lib/ql/rt/DELETE.js +0 -29
  212. package/lib/ql/rt/INSERT.js +0 -23
  213. package/lib/ql/rt/Query.js +0 -84
  214. package/lib/ql/rt/SELECT.js +0 -174
  215. package/lib/ql/rt/UPDATE.js +0 -119
  216. package/lib/ql/rt/_helpers.js +0 -91
  217. package/lib/ql/rt/index.js +0 -32
  218. package/libx/_runtime/audit/generic/personal.js +0 -260
  219. package/libx/_runtime/cds-services/statements/BaseStatement.js +0 -72
  220. package/libx/_runtime/cds-services/statements/Create.js +0 -57
  221. package/libx/_runtime/cds-services/statements/Delete.js +0 -33
  222. package/libx/_runtime/cds-services/statements/Drop.js +0 -42
  223. package/libx/_runtime/cds-services/statements/Insert.js +0 -201
  224. package/libx/_runtime/cds-services/statements/Select.js +0 -826
  225. package/libx/_runtime/cds-services/statements/Update.js +0 -181
  226. package/libx/_runtime/cds-services/statements/Where.js +0 -726
  227. package/libx/_runtime/cds-services/statements/index.js +0 -25
  228. package/libx/_runtime/common/generic/resolve-mock.js +0 -9
@@ -7,6 +7,7 @@ const { Readable } = require('stream')
7
7
 
8
8
  const cds = require('../cds')
9
9
  const LOG = cds.log('sqlite|db|sql')
10
+ // && {_debug:true, debug(sql){ cds._debug && console.log(sql+';\n') }} //> please keep that for debugging stakeholder tests
10
11
  const { inspect } = require('util')
11
12
 
12
13
  /*
@@ -26,24 +27,26 @@ const _captureStack = DEBUG
26
27
  /*
27
28
  * helpers
28
29
  */
29
- const colored = {
30
+ const _colored = {
30
31
  BEGIN: '\x1b[1m\x1b[33mBEGIN\x1b[0m',
31
32
  COMMIT: '\x1b[1m\x1b[32mCOMMIT\x1b[0m',
32
33
  ROLLBACK: '\x1b[1m\x1b[91mROLLBACK\x1b[0m'
33
34
  }
35
+ const _augmented = (err, sql, o) => {
36
+ err.query = sql
37
+ err.message += ' in: \n' + sql
38
+ if (o) err.stack = err.message + o.stack.slice(5)
39
+ return err
40
+ }
34
41
 
35
42
  function _executeSimpleSQL(dbc, sql, values) {
36
- LOG._debug && LOG.debug(colored[sql] || sql, values || '')
43
+ LOG._debug && LOG.debug(_colored[sql] || sql, values || '')
37
44
 
38
45
  return new Promise((resolve, reject) => {
39
46
  const o = _captureStack()
40
47
  dbc.run(sql, values, function (err) {
41
- if (err) {
42
- err.query = sql
43
- err.message += ' in: \n' + sql
44
- if (o) err.stack = err.message + o.stack.slice(5)
45
- return reject(err)
46
- }
48
+ if (err) return reject(_augmented(err, sql, o))
49
+
47
50
  resolve(this.changes)
48
51
  })
49
52
  })
@@ -55,12 +58,7 @@ function executeSelectSQL(dbc, sql, values, isOne, postMapper) {
55
58
  return new Promise((resolve, reject) => {
56
59
  const o = _captureStack()
57
60
  dbc[isOne ? 'get' : 'all'](sql, values, (err, result) => {
58
- if (err) {
59
- err.query = sql
60
- err.message += ' in: \n' + sql
61
- if (o) err.stack = err.message + o.stack.slice(5)
62
- return reject(err)
63
- }
61
+ if (err) return reject(_augmented(err, sql, o))
64
62
 
65
63
  // REVISIT
66
64
  // .get returns undefined if nothing in db
@@ -82,7 +80,7 @@ function executeSelectSQL(dbc, sql, values, isOne, postMapper) {
82
80
 
83
81
  function _processExpand(model, dbc, cqn, user, locale, txTimestamp) {
84
82
  const queries = []
85
- const expandQueries = createJoinCQNFromExpanded(cqn, model, false, locale)
83
+ const expandQueries = createJoinCQNFromExpanded(cqn, model, locale)
86
84
 
87
85
  for (const cqn of expandQueries.queries) {
88
86
  cqn._conversionMapper = getPostProcessMapper(SQLITE_TYPE_CONVERSION_MAP, model, cqn)
@@ -93,7 +91,7 @@ function _processExpand(model, dbc, cqn, user, locale, txTimestamp) {
93
91
  queries.push(executeSelectSQL(dbc, sql, values, false))
94
92
  }
95
93
 
96
- return rawToExpanded(expandQueries, queries, cqn.SELECT.one)
94
+ return rawToExpanded(expandQueries, queries, cqn.SELECT.one, cqn._rootEntity)
97
95
  }
98
96
 
99
97
  function executeSelectCQN(model, dbc, query, user, locale, txTimestamp) {
@@ -141,11 +139,9 @@ const _executeBulkInsertSQL = (dbc, sql, values) =>
141
139
  }
142
140
 
143
141
  LOG._debug && LOG.debug(sql, values)
142
+ const o = _captureStack()
144
143
  const stmt = dbc.prepare(sql, err => {
145
- if (err) {
146
- err.query = sql
147
- return reject(err)
148
- }
144
+ if (err) return reject(_augmented(err, sql, o))
149
145
 
150
146
  if (!Array.isArray(values[0])) values = [values]
151
147
 
@@ -163,9 +159,10 @@ const _executeBulkInsertSQL = (dbc, sql, values) =>
163
159
  if (!isFinalized) {
164
160
  isFinalized = true
165
161
  stmt.finalize()
166
- return reject(err)
162
+ return reject(_augmented(err, sql, o))
167
163
  }
168
164
  }
165
+
169
166
  // InsertResult needs an object per row with its values
170
167
  results[k] = { lastID: this.lastID, affectedRows: 1, values: each }
171
168
  n--
@@ -214,9 +211,11 @@ function executeInsertSQL(dbc, sql, values, query) {
214
211
 
215
212
  LOG._debug && LOG.debug(sql, values)
216
213
 
217
- return new Promise((resolve, reject) =>
214
+ return new Promise((resolve, reject) => {
215
+ const o = _captureStack()
218
216
  dbc.run(sql, values, function (err) {
219
- if (err) return reject(Object.assign(err, { query: sql }))
217
+ if (err) return reject(_augmented(err, sql, o))
218
+
220
219
  // InsertResult needs an object per row with its values
221
220
  if (query && values.length > 0) {
222
221
  // > single row via cqn
@@ -226,7 +225,7 @@ function executeInsertSQL(dbc, sql, values, query) {
226
225
  resolve([{ lastID: this.lastID, affectedRows: this.changes }])
227
226
  }
228
227
  })
229
- )
228
+ })
230
229
  }
231
230
 
232
231
  function _convertStreamValues(values) {
@@ -24,19 +24,24 @@ const getLocalize = (locale, model) => name => {
24
24
  }
25
25
 
26
26
  const _handler = function (req) {
27
+ const { query } = req
28
+
27
29
  // do simple checks upfront and exit early
28
- if (!req.query || typeof req.query === 'string') return
29
- if (!req.query.SELECT) return
30
- if (!req.user || !req.user.locale) return
30
+ if (!query || typeof query === 'string') return
31
+ if (!query.SELECT) return
31
32
  if (!this.model) return
33
+ if (!req.locale) return
34
+
35
+ // suppress localization by instruction
36
+ if (query._suppressLocalization) return
32
37
 
33
- // prevent localization for pure counts
34
- const columns = req.query.SELECT.columns
38
+ // suppress localization for pure counts
39
+ const columns = query.SELECT.columns
35
40
  if (columns && columns.length === 1 && columns[0].func === 'count') return
36
41
 
37
- // prevent localization in "select for update" n/a for sqlite
42
+ // suppress localization in "select for update" n/a for sqlite
38
43
 
39
- redirect(req.query.SELECT, getLocalize(req.user.locale, this.model))
44
+ redirect(query.SELECT, getLocalize(req.locale, this.model))
40
45
  }
41
46
 
42
47
  _handler._initial = true
@@ -63,6 +63,16 @@
63
63
  * @property {TemplateProcessorPathOptions} [pathOptions=null]
64
64
  */
65
65
 
66
+ /**
67
+ * @typedef {object} templateProcessorProcessFnArgs
68
+ * @property {object} row
69
+ * @property {string} key
70
+ * @property {object} element
71
+ * @property {boolean} plain
72
+ * @property {boolean} isRoot
73
+ * @property {Array<String>} [pathSegments]
74
+ */
75
+
66
76
  // Search
67
77
 
68
78
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds",
3
- "version": "5.4.6",
3
+ "version": "5.5.0",
4
4
  "description": "SAP Cloud Application Programming Model - CDS for Node.js",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [
package/server.js CHANGED
@@ -25,11 +25,14 @@ const cds = require('./lib')
25
25
  */
26
26
  module.exports = async function cds_server (options, o = { ...options, __proto__:defaults }) {
27
27
 
28
+ const _in_prod = process.env.NODE_ENV === 'production'
29
+
28
30
  const app = cds.app = o.app || express()
29
31
  app.serve = _app_serve //> app.serve allows delegating to sub modules
30
32
  cds.emit ('bootstrap',app) //> hook for project-local server.js
31
33
 
32
34
  // mount static resources and logger middleware
35
+ if (o.cors) !_in_prod && app.use (o.cors) //> CORS
33
36
  if (o.static) app.use (express.static (o.static)) //> defaults to ./app
34
37
  if (o.favicon) app.use ('/favicon.ico', o.favicon) //> if none in ./app
35
38
  if (o.index) app.get ('/',o.index) //> if none in ./app
@@ -63,6 +66,17 @@ module.exports = async function cds_server (options, o = { ...options, __proto__
63
66
  //
64
67
  const defaults = {
65
68
 
69
+ // CORS
70
+ get cors() {
71
+ return (req, res, next) => {
72
+ const { origin } = req.headers
73
+ if (origin) res.set('access-control-allow-origin', origin)
74
+ if (origin && req.method === 'OPTIONS')
75
+ return res.set('access-control-allow-methods', 'GET,HEAD,PUT,PATCH,POST,DELETE').end()
76
+ next()
77
+ }
78
+ },
79
+
66
80
  get static() { return cds.env.folders.app }, //> defaults to ./app
67
81
 
68
82
  // default generic index.html page
@@ -97,9 +111,9 @@ const defaults = {
97
111
  get logger() {
98
112
  const LOG = cds.log(), DEBUG = cds.debug('server')
99
113
  return (req,_,next) => {
100
- LOG (req.method, decodeURI(req.url))
114
+ LOG && LOG (req.method, decodeURI(req.url))
101
115
  if (/\$batch/.test(req.url)) req.on ('dispatch', (req) => {
102
- LOG ('>', req.event, decodeURI(req._path), req._query||'')
116
+ LOG && LOG ('>', req.event, decodeURI(req._path), req._query||'')
103
117
  if (DEBUG && req.query) DEBUG (req.query)
104
118
  })
105
119
  next()
@@ -1,208 +0,0 @@
1
- // TEST = o x:(expr) o {return x}
2
-
3
- //--------------------------------------------------------------------------
4
- // Queries
5
-
6
- columns
7
- = cols:(c:column {return[c]}) tail:(COMMA c:column {cols.push(c)})*
8
- {return cols}
9
-
10
- column
11
- = "*"
12
- / r:ref ".*" { r.inline=['*']; return r }
13
- / x:expr ((_"as"i_/_) a:name {x.as=a})? {return x}
14
-
15
- obyx = x:expr
16
- (_ ad:("ASC"i / "DESC"i) {x.sort=ad.toLowerCase()} )?
17
- (_"NULLS"i_ fl:("FIRST"i / "LAST"i) {x.nulls=fl.toLowerCase()} )?
18
- {return x}
19
-
20
- //
21
-
22
- //--------------------------------------------------------------------------
23
- // Expressions
24
-
25
- expr "an expression" // returns one of {val:...}, {ref:...} or {xpr:...}
26
- = xpr:_xpr ( ao:(and/or) y:_xpr {xpr.push(ao,...y)})*
27
- { return xpr.length === 1 ? xpr[0] : {xpr} }
28
-
29
- _xpr //> internal rule to construct a single expressions as arrays
30
-
31
- = o:unary_operator b:operand
32
- {return [o,b] }
33
-
34
- / a:operand o"?"o b:operand o":"o c:operand
35
- {return ['case','when',a,'then',b,'else',c,'end'] }
36
-
37
- / a:operand o"?:"o b:operand
38
- {return [{func:'coalesce', args:[a,b]}]}
39
-
40
- / a:operand is? n:not? null
41
- {return n ? [a,'is','not','null'] : [a,'is','null']}
42
-
43
- / a:operand n:not? o:keyword_operator b:operand
44
- {return n ? [a,'not',o,b] : [a,o,b] }
45
-
46
- / a:operand o:binary_operator b:operand
47
- {return [a,o,b]}
48
-
49
- / a:operand
50
- {return [a]}
51
-
52
-
53
- operand
54
- = OPEN x:expr CLOSE {return x}
55
- / function
56
- / val
57
- / ref
58
- / list
59
- / param
60
- / unparsed
61
-
62
- list
63
- = OPEN head:expr tail:(COMMA x:expr {return x})* CLOSE
64
- { return {list:[head,...tail]}}
65
-
66
- function
67
- = func:$(name('.'? name)*) args:args
68
- {return {func,args}}
69
-
70
- param
71
- = ':' p:(name/number) {return {param:true,ref:[p]}}
72
- / "?" {return {param:true,ref:['?']}}
73
-
74
- unary_operator
75
- = o op:(
76
- "EXISTS"i !ALPHA {return 'exists'}
77
- / "-" !number {return '-'}
78
- / "+" !number {return '+'}
79
- / "!" {return 'not'}
80
- / "~"
81
- / not
82
- ) o {return op}
83
-
84
- binary_operator
85
- = o op:(
86
- ne / eq / le / lt / ge / gt
87
- / "||" / "&&" / "+=" / "-="
88
- / [*/%+-]
89
- ) o {return op}
90
-
91
- keyword_operator
92
- = o op:(
93
- o:( "IN"i / "BETWEEN"i / "LIKE"i / "GLOB"i / "MATCH"i / "REGEXP"i )!ALPHA {return o}
94
- / !("as"i / and / or) n:name {return n}
95
- ) o {return op}
96
-
97
- //
98
-
99
- is = o "is"i !ALPHA o {return "is"}
100
- not = o "not"i !ALPHA o {return "not"}
101
- and = o "and"i !ALPHA o {return "and"}
102
- or = o "or"i !ALPHA o {return "or"}
103
-
104
- ne = ( "ne"i !ALPHA / is not / "!=" / "<>" ){return "!="}
105
- eq = ( "eq"i !ALPHA / is / "==" / "=" ){return "="}
106
- le = ( "le"i !ALPHA / "<=" ){return "<="}
107
- lt = ( "lt"i !ALPHA / "<" ){return "<"}
108
- ge = ( "ge"i !ALPHA / ">=" ){return ">="}
109
- gt = ( "gt"i !ALPHA / ">" ){return ">"}
110
-
111
- // maybe_operator "an operator" = o op:$[:!|&~\?^]+ o {return op}
112
-
113
-
114
- //--------------------------------------------------------------------------
115
- // Names and References
116
-
117
-
118
- ref "a reference"
119
- = head:segment tail:(o'.'o? s:segment {return s})*
120
- {return {ref:[head,...tail]}}
121
-
122
- segment
123
- = id:name filter:filter?
124
- {return !filter ? id : {id,...filter}}
125
-
126
- name "a name"
127
- = $( !DIGIT ALPHA+ )
128
-
129
- filter
130
- = o"["o one:("1:")? o ("where"_)? where:( expr / "*" )? o"]"
131
- {let f={where}; if(one) f.cardinality={max:1}; return f}
132
-
133
- args
134
- = OPEN a:( '*'{return['*']} / named_args / positional_args / ""{return[]} ) CLOSE
135
- {return a}
136
-
137
- named_args
138
- = args:(n:name COLON v:expr {return {[n]:v}})
139
- ( COMMA n:name COLON v:expr {args[n]=v} )*
140
- {return args}
141
-
142
- positional_args
143
- = head:expr tail:(COMMA x:expr {return x})*
144
- {return [head, ...tail]}
145
-
146
- //
147
-
148
-
149
- //--------------------------------------------------------------------------
150
- // Literals
151
-
152
- val "a literal value"
153
- = literal:literal_prefix val:string {return {val,literal}}
154
- / val:literal {return {val}}
155
-
156
- literal_prefix
157
- = "datetime"
158
- / "timestamp"
159
- / "date"
160
- / "time"
161
-
162
- literal
163
- = true / false / null
164
- / number
165
- / string
166
- / symbol
167
-
168
- number
169
- = x:$( [+-]? DIGIT+ ("." DIGIT+)? ("e" [+-]? DIGIT+)? )
170
- { return Number(x) }
171
-
172
- string
173
- = "'" s:$("''"/[^'])* "'"
174
- {return s.replace(/''/g,"'")}
175
-
176
- symbol // an enum symbol
177
- = "#" s:name
178
- {return{'#':s}}
179
-
180
- null = "null"i !ALPHA {return null}
181
- true = "true"i !ALPHA {return true}
182
- false = "false"i !ALPHA {return false}
183
-
184
- unparsed "#(...)" = "#" u:_unparsed
185
- {return Object.assign(String(u.trim()),{unparsed:true})}
186
-
187
- _unparsed = "(" u:$( [^()] / _unparsed )* ")"o {return u}
188
- //> reads arbitrary input between balanced parentheses
189
-
190
-
191
- //--------------------------------------------------------------------------
192
- // Punctuation
193
-
194
- OPEN "(" = o"("o {return "("}
195
- CLOSE ")" = o")" {return ")"}
196
- COLON "a colon" = o":"o {return ":"}
197
- COMMA "a comma" = o","o {return ","}
198
- ALPHA = [_$A-Za-z0-9]
199
- DIGIT = [0-9]
200
-
201
-
202
- //--------------------------------------------------------------------------
203
- // Whitespaces and Comments
204
-
205
- _ "" = [ \t\n]+
206
- o "" = [ \t\n]*
207
-
208
- //--------------------------------------------------------------------------
package/lib/ql/parser.js DELETED
@@ -1 +0,0 @@
1
- "use strict";function peg$subclass(r,t){function e(){this.constructor=r}e.prototype=t.prototype,r.prototype=new e}function peg$SyntaxError(r,t,e,n){this.message=r,this.expected=t,this.found=e,this.location=n,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,peg$SyntaxError)}function peg$parse(r,t){t=void 0!==t?t:{};var e,n={},u={columns:St},s=St,o=function(r,t){r.push(t)},a="*",c=Ct("*",!1),i=Ct(".*",!1),l="as",f=Ct("as",!0),h=(Ct("ASC",!0),Ct("DESC",!0),Ct("NULLS",!0),Ct("FIRST",!0),Ct("LAST",!0),wt("an expression")),p=function(r,t,e){r.push(t,...e)},d=Ct("?",!1),v=":",b=Ct(":",!1),A=Ct("?:",!1),g=function(r,t){return t},C=".",x=Ct(".",!1),w="exists",m=Ct("EXISTS",!0),L=Ct("-",!1),y=Ct("+",!1),E=Ct("!",!1),S=Ct("~",!1),$="||",F=Ct("||",!1),T="&&",R=Ct("&&",!1),I="+=",N=Ct("+=",!1),k="-=",M=Ct("-=",!1),j=/^[*\/%+\-]/,q=xt(["*","/","%","+","-"],!1,!1),z=Ct("IN",!0),B="between",G=Ct("BETWEEN",!0),O="like",U=Ct("LIKE",!0),X="glob",Z=Ct("GLOB",!0),_="match",D=Ct("MATCH",!0),H="regexp",K=Ct("REGEXP",!0),P=Ct("is",!0),W=Ct("not",!0),J=Ct("and",!0),Q=Ct("or",!0),V=Ct("ne",!0),Y="!=",rr=Ct("!=",!1),tr="<>",er=Ct("<>",!1),nr=Ct("eq",!0),ur="==",sr=Ct("==",!1),or=Ct("=",!1),ar=Ct("le",!0),cr="<=",ir=Ct("<=",!1),lr=Ct("lt",!0),fr=Ct("<",!1),hr=Ct("ge",!0),pr=">=",dr=Ct(">=",!1),vr=Ct("gt",!0),br=Ct(">",!1),Ar=wt("a reference"),gr=function(r,t){return t},Cr=wt("a name"),xr=Ct("[",!1),wr="1:",mr=Ct("1:",!1),Lr="where",yr=Ct("where",!1),Er=Ct("]",!1),Sr=function(r,t,e){r[t]=e},$r=wt("a literal value"),Fr="datetime",Tr=Ct("datetime",!1),Rr="timestamp",Ir=Ct("timestamp",!1),Nr="date",kr=Ct("date",!1),Mr="time",jr=Ct("time",!1),qr=/^[+\-]/,zr=xt(["+","-"],!1,!1),Br=Ct("e",!1),Gr=Ct("'",!1),Or="''",Ur=Ct("''",!1),Xr=/^[^']/,Zr=xt(["'"],!0,!1),_r="#",Dr=Ct("#",!1),Hr=Ct("null",!0),Kr="true",Pr=Ct("true",!0),Wr="false",Jr=Ct("false",!0),Qr=wt("#(...)"),Vr=Ct("(",!1),Yr=/^[^()]/,rt=xt(["(",")"],!0,!1),tt=Ct(")",!1),et=wt("("),nt=wt(")"),ut=wt("a colon"),st=wt("a comma"),ot=Ct(",",!1),at=/^[_$A-Za-z0-9]/,ct=xt(["_","$",["A","Z"],["a","z"],["0","9"]],!1,!1),it=/^[0-9]/,lt=xt([["0","9"]],!1,!1),ft=wt(""),ht=/^[ \t\n]/,pt=xt([" ","\t","\n"],!1,!1),dt=0,vt=[{line:1,column:1}],bt=0,At=[],gt=0;if("startRule"in t){if(!(t.startRule in u))throw new Error("Can't start parsing from rule \""+t.startRule+'".');s=u[t.startRule]}function Ct(r,t){return{type:"literal",text:r,ignoreCase:t}}function xt(r,t,e){return{type:"class",parts:r,inverted:t,ignoreCase:e}}function wt(r){return{type:"other",description:r}}function mt(t){var e,n=vt[t];if(n)return n;for(e=t-1;!vt[e];)e--;for(n={line:(n=vt[e]).line,column:n.column};e<t;)10===r.charCodeAt(e)?(n.line++,n.column=1):n.column++,e++;return vt[t]=n,n}function Lt(r,t){var e=mt(r),n=mt(t);return{start:{offset:r,line:e.line,column:e.column},end:{offset:t,line:n.line,column:n.column}}}function yt(r){dt<bt||(dt>bt&&(bt=dt,At=[]),At.push(r))}function Et(r,t,e){return new peg$SyntaxError(peg$SyntaxError.buildMessage(r,t),r,t,e)}function St(){var r,t,e,u,s;if(r=dt,t=dt,(e=$t())!==n&&(t,e=[e]),(t=e)!==n){for(e=[],u=dt,Dt()!==n&&(s=$t())!==n?(u,u=o(t,s)):(dt=u,u=n);u!==n;)e.push(u),u=dt,Dt()!==n&&(s=$t())!==n?(u,u=o(t,s)):(dt=u,u=n);e!==n?(r,r=t=t):(dt=r,r=n)}else dt=r,r=n;return r}function $t(){var t,e,u,s,o,a,l,h,p;return 42===r.charCodeAt(dt)?(t="*",dt++):(t=n,0===gt&&yt(c)),t===n&&(t=dt,(e=jt())!==n?(".*"===r.substr(dt,2)?(u=".*",dt+=2):(u=n,0===gt&&yt(i)),u!==n?(t,(p=e).inline=["*"],t=e=p):(dt=t,t=n)):(dt=t,t=n),t===n&&(t=dt,(e=Ft())!==n?(u=dt,s=dt,(o=Pt())!==n?("as"===r.substr(dt,2).toLowerCase()?(a=r.substr(dt,2),dt+=2):(a=n,0===gt&&yt(f)),a!==n&&(l=Pt())!==n?s=o=[o,a,l]:(dt=s,s=n)):(dt=s,s=n),s===n&&(s=Pt()),s!==n&&(o=zt())!==n?(u,h=o,u=s=void(e.as=h)):(dt=u,u=n),u===n&&(u=null),u!==n?(t,t=e=e):(dt=t,t=n)):(dt=t,t=n))),t}function Ft(){var r,t,e,u,s,o,a;if(gt++,r=dt,(t=Tt())!==n){for(e=[],u=dt,(s=kt())===n&&(s=Mt()),s!==n&&(o=Tt())!==n?(u,u=s=p(t,s,o)):(dt=u,u=n);u!==n;)e.push(u),u=dt,(s=kt())===n&&(s=Mt()),s!==n&&(o=Tt())!==n?(u,u=s=p(t,s,o)):(dt=u,u=n);e!==n?(r,r=t=1===(a=t).length?a[0]:{xpr:a}):(dt=r,r=n)}else dt=r,r=n;return gt--,r===n&&(t=n,0===gt&&yt(h)),r}function Tt(){var t,e,u,s,o,a,c,i,h;return t=dt,(e=function(){var t,e,u,s,o;t=dt,Wt()!==n?(e=dt,r.substr(dt,6).toLowerCase()===w?(u=r.substr(dt,6),dt+=6):(u=n,0===gt&&yt(m)),u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?(e,e=u="exists"):(dt=e,e=n)):(dt=e,e=n),e===n&&(e=dt,45===r.charCodeAt(dt)?(u="-",dt++):(u=n,0===gt&&yt(L)),u!==n?(s=dt,gt++,o=Bt(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?(e,e=u="-"):(dt=e,e=n)):(dt=e,e=n),e===n&&(e=dt,43===r.charCodeAt(dt)?(u="+",dt++):(u=n,0===gt&&yt(y)),u!==n?(s=dt,gt++,o=Bt(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?(e,e=u="+"):(dt=e,e=n)):(dt=e,e=n),e===n&&(e=dt,33===r.charCodeAt(dt)?(u="!",dt++):(u=n,0===gt&&yt(E)),u!==n&&(e,u="not"),(e=u)===n&&(126===r.charCodeAt(dt)?(e="~",dt++):(e=n,0===gt&&yt(S)),e===n&&(e=Nt()))))),e!==n&&(u=Wt())!==n?(t,t=e):(dt=t,t=n)):(dt=t,t=n);return t}())!==n&&(u=Rt())!==n?(t,t=e=[e,u]):(dt=t,t=n),t===n&&(t=dt,(e=Rt())!==n&&(u=Wt())!==n?(63===r.charCodeAt(dt)?(s="?",dt++):(s=n,0===gt&&yt(d)),s!==n&&(o=Wt())!==n&&(a=Rt())!==n&&Wt()!==n?(58===r.charCodeAt(dt)?(c=":",dt++):(c=n,0===gt&&yt(b)),c!==n&&Wt()!==n&&(i=Rt())!==n?(t,t=e=function(r,t,e){return["case","when",r,"then",t,"else",e,"end"]}(e,a,i)):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n),t===n&&(t=dt,(e=Rt())!==n&&(u=Wt())!==n?("?:"===r.substr(dt,2)?(s="?:",dt+=2):(s=n,0===gt&&yt(A)),s!==n&&(o=Wt())!==n&&(a=Rt())!==n?(t,t=e=function(r,t){return[{func:"coalesce",args:[r,t]}]}(e,a)):(dt=t,t=n)):(dt=t,t=n),t===n&&(t=dt,(e=Rt())!==n?((u=It())===n&&(u=null),u!==n?((s=Nt())===n&&(s=null),s!==n&&(o=Ot())!==n?(t,h=e,t=e=s?[h,"is","not","null"]:[h,"is","null"]):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n),t===n&&(t=dt,(e=Rt())!==n?((u=Nt())===n&&(u=null),u!==n&&(s=function(){var t,e,u,s,o;t=dt,Wt()!==n?(e=dt,"in"===r.substr(dt,2).toLowerCase()?(u=r.substr(dt,2),dt+=2):(u=n,0===gt&&yt(z)),u===n&&(r.substr(dt,7).toLowerCase()===B?(u=r.substr(dt,7),dt+=7):(u=n,0===gt&&yt(G)),u===n&&(r.substr(dt,4).toLowerCase()===O?(u=r.substr(dt,4),dt+=4):(u=n,0===gt&&yt(U)),u===n&&(r.substr(dt,4).toLowerCase()===X?(u=r.substr(dt,4),dt+=4):(u=n,0===gt&&yt(Z)),u===n&&(r.substr(dt,5).toLowerCase()===_?(u=r.substr(dt,5),dt+=5):(u=n,0===gt&&yt(D)),u===n&&(r.substr(dt,6).toLowerCase()===H?(u=r.substr(dt,6),dt+=6):(u=n,0===gt&&yt(K))))))),u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?(e,e=u=u):(dt=e,e=n)):(dt=e,e=n),e===n&&(e=dt,u=dt,gt++,r.substr(dt,2).toLowerCase()===l?(s=r.substr(dt,2),dt+=2):(s=n,0===gt&&yt(f)),s===n&&(s=kt())===n&&(s=Mt()),gt--,s===n?u=void 0:(dt=u,u=n),u!==n&&(s=zt())!==n?(e,e=u=s):(dt=e,e=n)),e!==n&&(u=Wt())!==n?(t,t=e):(dt=t,t=n)):(dt=t,t=n);return t}())!==n&&(o=Rt())!==n?(t,t=e=function(r,t,e,n){return t?[r,"not",e,n]:[r,e,n]}(e,u,s,o)):(dt=t,t=n)):(dt=t,t=n),t===n&&(t=dt,(e=Rt())!==n&&(u=function(){var t,e;t=dt,Wt()!==n?((e=function(){var t,e,u,s,o;t=dt,e=dt,"ne"===r.substr(dt,2).toLowerCase()?(u=r.substr(dt,2),dt+=2):(u=n,0===gt&&yt(V));u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?e=u=[u,s]:(dt=e,e=n)):(dt=e,e=n);e===n&&(e=dt,(u=It())!==n&&(s=Nt())!==n?e=u=[u,s]:(dt=e,e=n),e===n&&(r.substr(dt,2)===Y?(e=Y,dt+=2):(e=n,0===gt&&yt(rr)),e===n&&(r.substr(dt,2)===tr?(e=tr,dt+=2):(e=n,0===gt&&yt(er)))));e!==n&&(t,e="!=");return t=e}())===n&&(e=function(){var t,e,u,s,o;t=dt,e=dt,"eq"===r.substr(dt,2).toLowerCase()?(u=r.substr(dt,2),dt+=2):(u=n,0===gt&&yt(nr));u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?e=u=[u,s]:(dt=e,e=n)):(dt=e,e=n);e===n&&(e=It())===n&&(r.substr(dt,2)===ur?(e=ur,dt+=2):(e=n,0===gt&&yt(sr)),e===n&&(61===r.charCodeAt(dt)?(e="=",dt++):(e=n,0===gt&&yt(or))));e!==n&&(t,e="=");return t=e}())===n&&(e=function(){var t,e,u,s,o;t=dt,e=dt,"le"===r.substr(dt,2).toLowerCase()?(u=r.substr(dt,2),dt+=2):(u=n,0===gt&&yt(ar));u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?e=u=[u,s]:(dt=e,e=n)):(dt=e,e=n);e===n&&(r.substr(dt,2)===cr?(e=cr,dt+=2):(e=n,0===gt&&yt(ir)));e!==n&&(t,e="<=");return t=e}())===n&&(e=function(){var t,e,u,s,o;t=dt,e=dt,"lt"===r.substr(dt,2).toLowerCase()?(u=r.substr(dt,2),dt+=2):(u=n,0===gt&&yt(lr));u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?e=u=[u,s]:(dt=e,e=n)):(dt=e,e=n);e===n&&(60===r.charCodeAt(dt)?(e="<",dt++):(e=n,0===gt&&yt(fr)));e!==n&&(t,e="<");return t=e}())===n&&(e=function(){var t,e,u,s,o;t=dt,e=dt,"ge"===r.substr(dt,2).toLowerCase()?(u=r.substr(dt,2),dt+=2):(u=n,0===gt&&yt(hr));u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?e=u=[u,s]:(dt=e,e=n)):(dt=e,e=n);e===n&&(r.substr(dt,2)===pr?(e=pr,dt+=2):(e=n,0===gt&&yt(dr)));e!==n&&(t,e=">=");return t=e}())===n&&(e=function(){var t,e,u,s,o;t=dt,e=dt,"gt"===r.substr(dt,2).toLowerCase()?(u=r.substr(dt,2),dt+=2):(u=n,0===gt&&yt(vr));u!==n?(s=dt,gt++,o=Ht(),gt--,o===n?s=void 0:(dt=s,s=n),s!==n?e=u=[u,s]:(dt=e,e=n)):(dt=e,e=n);e===n&&(62===r.charCodeAt(dt)?(e=">",dt++):(e=n,0===gt&&yt(br)));e!==n&&(t,e=">");return t=e}())===n&&(r.substr(dt,2)===$?(e=$,dt+=2):(e=n,0===gt&&yt(F)),e===n&&(r.substr(dt,2)===T?(e=T,dt+=2):(e=n,0===gt&&yt(R)),e===n&&(r.substr(dt,2)===I?(e=I,dt+=2):(e=n,0===gt&&yt(N)),e===n&&(r.substr(dt,2)===k?(e=k,dt+=2):(e=n,0===gt&&yt(M)),e===n&&(j.test(r.charAt(dt))?(e=r.charAt(dt),dt++):(e=n,0===gt&&yt(q))))))),e!==n&&Wt()!==n?(t,t=e):(dt=t,t=n)):(dt=t,t=n);return t}())!==n&&(s=Rt())!==n?(t,t=e=function(r,t,e){return[r,t,e]}(e,u,s)):(dt=t,t=n),t===n&&(t=dt,(e=Rt())!==n&&(t,e=function(r){return[r]}(e)),t=e)))))),t}function Rt(){var t,e;return t=dt,Xt()!==n&&(e=Ft())!==n&&Zt()!==n?(t,t=e):(dt=t,t=n),t===n&&(t=function(){var t,e,u,s,o,i,l,f;if(t=dt,e=dt,u=dt,(s=zt())!==n){for(o=[],i=dt,46===r.charCodeAt(dt)?(l=C,dt++):(l=n,0===gt&&yt(x)),l===n&&(l=null),l!==n&&(f=zt())!==n?i=l=[l,f]:(dt=i,i=n);i!==n;)o.push(i),i=dt,46===r.charCodeAt(dt)?(l=C,dt++):(l=n,0===gt&&yt(x)),l===n&&(l=null),l!==n&&(f=zt())!==n?i=l=[l,f]:(dt=i,i=n);o!==n?u=s=[s,o]:(dt=u,u=n)}else dt=u,u=n;e=u!==n?r.substring(e,dt):u;e!==n&&(u=function(){var t,e,u;t=dt,Xt()!==n?(e=dt,42===r.charCodeAt(dt)?(u=a,dt++):(u=n,0===gt&&yt(c)),u!==n&&(e,u=["*"]),(e=u)===n&&(e=function(){var r,t,e,u,s,o,a;r=dt,t=dt,(e=zt())!==n&&(u=_t())!==n&&(s=Ft())!==n?(t,t=e={[e]:s}):(dt=t,t=n);if(t!==n){for(e=[],u=dt,(s=Dt())!==n&&(o=zt())!==n&&_t()!==n&&(a=Ft())!==n?(u,u=s=Sr(t,o,a)):(dt=u,u=n);u!==n;)e.push(u),u=dt,(s=Dt())!==n&&(o=zt())!==n&&_t()!==n&&(a=Ft())!==n?(u,u=s=Sr(t,o,a)):(dt=u,u=n);e!==n?(r,r=t=t):(dt=r,r=n)}else dt=r,r=n;return r}())===n&&(e=function(){var r,t,e,u,s;if(r=dt,(t=Ft())!==n){for(e=[],u=dt,Dt()!==n&&(s=Ft())!==n?(u,u=g(0,s)):(dt=u,u=n);u!==n;)e.push(u),u=dt,Dt()!==n&&(s=Ft())!==n?(u,u=g(0,s)):(dt=u,u=n);e!==n?(r,o=e,r=t=[t,...o]):(dt=r,r=n)}else dt=r,r=n;var o;return r}())===n&&(e=dt,(u="")!==n&&(e,u=[]),e=u),e!==n&&(u=Zt())!==n?(t,t=e):(dt=t,t=n)):(dt=t,t=n);return t}())!==n?(t,t=e={func:e,args:u}):(dt=t,t=n);return t}())===n&&(t=function(){var t,e,u;gt++,t=dt,(e=function(){var t;r.substr(dt,8)===Fr?(t=Fr,dt+=8):(t=n,0===gt&&yt(Tr));t===n&&(r.substr(dt,9)===Rr?(t=Rr,dt+=9):(t=n,0===gt&&yt(Ir)),t===n&&(r.substr(dt,4)===Nr?(t=Nr,dt+=4):(t=n,0===gt&&yt(kr)),t===n&&(r.substr(dt,4)===Mr?(t=Mr,dt+=4):(t=n,0===gt&&yt(jr)))));return t}())!==n&&(u=Gt())!==n?(t,t=e={val:u,literal:e}):(dt=t,t=n);t===n&&(t=dt,(e=function(){var t;(t=function(){var t,e,u,s;t=dt,r.substr(dt,4).toLowerCase()===Kr?(e=r.substr(dt,4),dt+=4):(e=n,0===gt&&yt(Pr));e!==n?(u=dt,gt++,s=Ht(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n?(t,t=e=!0):(dt=t,t=n)):(dt=t,t=n);return t}())===n&&(t=function(){var t,e,u,s;t=dt,r.substr(dt,5).toLowerCase()===Wr?(e=r.substr(dt,5),dt+=5):(e=n,0===gt&&yt(Jr));e!==n?(u=dt,gt++,s=Ht(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n?(t,t=e=!1):(dt=t,t=n)):(dt=t,t=n);return t}())===n&&(t=Ot())===n&&(t=Bt())===n&&(t=Gt())===n&&(t=function(){var t,e,u;t=dt,35===r.charCodeAt(dt)?(e="#",dt++):(e=n,0===gt&&yt(Dr));e!==n&&(u=zt())!==n?(t,t=e={"#":u}):(dt=t,t=n);return t}());return t}())!==n&&(t,e=function(r){return{val:r}}(e)),t=e);gt--,t===n&&(e=n,0===gt&&yt($r));return t}())===n&&(t=jt())===n&&(t=function(){var r,t,e,u,s;if(r=dt,Xt()!==n)if((t=Ft())!==n){for(e=[],u=dt,Dt()!==n&&(s=Ft())!==n?(u,u=g(0,s)):(dt=u,u=n);u!==n;)e.push(u),u=dt,Dt()!==n&&(s=Ft())!==n?(u,u=g(0,s)):(dt=u,u=n);e!==n&&(u=Zt())!==n?(r,o=e,r={list:[t,...o]}):(dt=r,r=n)}else dt=r,r=n;else dt=r,r=n;var o;return r}())===n&&(t=function(){var t,e,u;t=dt,58===r.charCodeAt(dt)?(e=v,dt++):(e=n,0===gt&&yt(b));e!==n?((u=zt())===n&&(u=Bt()),u!==n?(t,t=e={param:!0,ref:[u]}):(dt=t,t=n)):(dt=t,t=n);t===n&&(t=dt,63===r.charCodeAt(dt)?(e="?",dt++):(e=n,0===gt&&yt(d)),e!==n&&(t,e={param:!0,ref:["?"]}),t=e);return t}())===n&&(t=function(){var t,e,u;gt++,t=dt,35===r.charCodeAt(dt)?(e=_r,dt++):(e=n,0===gt&&yt(Dr));e!==n&&(u=Ut())!==n?(t,s=u,t=e=Object.assign(String(s.trim()),{unparsed:!0})):(dt=t,t=n);var s;gt--,t===n&&(e=n,0===gt&&yt(Qr));return t}()),t}function It(){var t,e,u,s;return t=dt,Wt()!==n?("is"===r.substr(dt,2).toLowerCase()?(e=r.substr(dt,2),dt+=2):(e=n,0===gt&&yt(P)),e!==n?(u=dt,gt++,s=Ht(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n&&(s=Wt())!==n?(t,t="is"):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n),t}function Nt(){var t,e,u,s;return t=dt,Wt()!==n?("not"===r.substr(dt,3).toLowerCase()?(e=r.substr(dt,3),dt+=3):(e=n,0===gt&&yt(W)),e!==n?(u=dt,gt++,s=Ht(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n&&(s=Wt())!==n?(t,t="not"):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n),t}function kt(){var t,e,u,s;return t=dt,Wt()!==n?("and"===r.substr(dt,3).toLowerCase()?(e=r.substr(dt,3),dt+=3):(e=n,0===gt&&yt(J)),e!==n?(u=dt,gt++,s=Ht(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n&&(s=Wt())!==n?(t,t="and"):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n),t}function Mt(){var t,e,u,s;return t=dt,Wt()!==n?("or"===r.substr(dt,2).toLowerCase()?(e=r.substr(dt,2),dt+=2):(e=n,0===gt&&yt(Q)),e!==n?(u=dt,gt++,s=Ht(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n&&(s=Wt())!==n?(t,t="or"):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n),t}function jt(){var t,e,u,s,o,a,c,i;if(gt++,t=dt,(e=qt())!==n){for(u=[],s=dt,Wt()!==n?(46===r.charCodeAt(dt)?(o=C,dt++):(o=n,0===gt&&yt(x)),o!==n?((a=Wt())===n&&(a=null),a!==n&&(c=qt())!==n?(s,s=gr(0,c)):(dt=s,s=n)):(dt=s,s=n)):(dt=s,s=n);s!==n;)u.push(s),s=dt,Wt()!==n?(46===r.charCodeAt(dt)?(o=C,dt++):(o=n,0===gt&&yt(x)),o!==n?((a=Wt())===n&&(a=null),a!==n&&(c=qt())!==n?(s,s=gr(0,c)):(dt=s,s=n)):(dt=s,s=n)):(dt=s,s=n);u!==n?(t,i=u,t=e={ref:[e,...i]}):(dt=t,t=n)}else dt=t,t=n;return gt--,t===n&&(e=n,0===gt&&yt(Ar)),t}function qt(){var t,e,u,s,o;return t=dt,(e=zt())!==n?((u=function(){var t,e,u,s,o,i,l;t=dt,Wt()!==n?(91===r.charCodeAt(dt)?(e="[",dt++):(e=n,0===gt&&yt(xr)),e!==n&&Wt()!==n?(r.substr(dt,2)===wr?(u=wr,dt+=2):(u=n,0===gt&&yt(mr)),u===n&&(u=null),u!==n&&Wt()!==n?(s=dt,r.substr(dt,5)===Lr?(o=Lr,dt+=5):(o=n,0===gt&&yt(yr)),o!==n&&(i=Pt())!==n?s=o=[o,i]:(dt=s,s=n),s===n&&(s=null),s!==n?((o=Ft())===n&&(42===r.charCodeAt(dt)?(o=a,dt++):(o=n,0===gt&&yt(c))),o===n&&(o=null),o!==n&&(i=Wt())!==n?(93===r.charCodeAt(dt)?(l="]",dt++):(l=n,0===gt&&yt(Er)),l!==n?(t,t=function(r,t){let e={where:t};return r&&(e.cardinality={max:1}),e}(u,o)):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n)):(dt=t,t=n);return t}())===n&&(u=null),u!==n?(t,s=e,t=e=(o=u)?{id:s,...o}:s):(dt=t,t=n)):(dt=t,t=n),t}function zt(){var t,e,u,s,o;if(gt++,t=dt,e=dt,u=dt,gt++,s=Kt(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n){if(s=[],(o=Ht())!==n)for(;o!==n;)s.push(o),o=Ht();else s=n;s!==n?e=u=[u,s]:(dt=e,e=n)}else dt=e,e=n;return t=e!==n?r.substring(t,dt):e,gt--,t===n&&(e=n,0===gt&&yt(Cr)),t}function Bt(){var t,e,u,s,o,a,c,i,l,f,h;if(t=dt,e=dt,u=dt,qr.test(r.charAt(dt))?(s=r.charAt(dt),dt++):(s=n,0===gt&&yt(zr)),s===n&&(s=null),s!==n){if(o=[],(a=Kt())!==n)for(;a!==n;)o.push(a),a=Kt();else o=n;if(o!==n){if(a=dt,46===r.charCodeAt(dt)?(c=C,dt++):(c=n,0===gt&&yt(x)),c!==n){if(i=[],(l=Kt())!==n)for(;l!==n;)i.push(l),l=Kt();else i=n;i!==n?a=c=[c,i]:(dt=a,a=n)}else dt=a,a=n;if(a===n&&(a=null),a!==n){if(c=dt,101===r.charCodeAt(dt)?(i="e",dt++):(i=n,0===gt&&yt(Br)),i!==n)if(qr.test(r.charAt(dt))?(l=r.charAt(dt),dt++):(l=n,0===gt&&yt(zr)),l===n&&(l=null),l!==n){if(f=[],(h=Kt())!==n)for(;h!==n;)f.push(h),h=Kt();else f=n;f!==n?c=i=[i,l,f]:(dt=c,c=n)}else dt=c,c=n;else dt=c,c=n;c===n&&(c=null),c!==n?u=s=[s,o,a,c]:(dt=u,u=n)}else dt=u,u=n}else dt=u,u=n}else dt=u,u=n;return(e=u!==n?r.substring(e,dt):u)!==n&&(t,e=Number(e)),t=e}function Gt(){var t,e,u,s,o;if(t=dt,39===r.charCodeAt(dt)?(e="'",dt++):(e=n,0===gt&&yt(Gr)),e!==n){for(u=dt,s=[],r.substr(dt,2)===Or?(o=Or,dt+=2):(o=n,0===gt&&yt(Ur)),o===n&&(Xr.test(r.charAt(dt))?(o=r.charAt(dt),dt++):(o=n,0===gt&&yt(Zr)));o!==n;)s.push(o),r.substr(dt,2)===Or?(o=Or,dt+=2):(o=n,0===gt&&yt(Ur)),o===n&&(Xr.test(r.charAt(dt))?(o=r.charAt(dt),dt++):(o=n,0===gt&&yt(Zr)));(u=s!==n?r.substring(u,dt):s)!==n?(39===r.charCodeAt(dt)?(s="'",dt++):(s=n,0===gt&&yt(Gr)),s!==n?(t,t=e=u.replace(/''/g,"'")):(dt=t,t=n)):(dt=t,t=n)}else dt=t,t=n;return t}function Ot(){var t,e,u,s;return t=dt,"null"===r.substr(dt,4).toLowerCase()?(e=r.substr(dt,4),dt+=4):(e=n,0===gt&&yt(Hr)),e!==n?(u=dt,gt++,s=Ht(),gt--,s===n?u=void 0:(dt=u,u=n),u!==n?(t,t=e=null):(dt=t,t=n)):(dt=t,t=n),t}function Ut(){var t,e,u,s,o;if(t=dt,40===r.charCodeAt(dt)?(e="(",dt++):(e=n,0===gt&&yt(Vr)),e!==n){for(u=dt,s=[],Yr.test(r.charAt(dt))?(o=r.charAt(dt),dt++):(o=n,0===gt&&yt(rt)),o===n&&(o=Ut());o!==n;)s.push(o),Yr.test(r.charAt(dt))?(o=r.charAt(dt),dt++):(o=n,0===gt&&yt(rt)),o===n&&(o=Ut());(u=s!==n?r.substring(u,dt):s)!==n?(41===r.charCodeAt(dt)?(s=")",dt++):(s=n,0===gt&&yt(tt)),s!==n&&(o=Wt())!==n?(t,t=e=u):(dt=t,t=n)):(dt=t,t=n)}else dt=t,t=n;return t}function Xt(){var t,e;return gt++,t=dt,Wt()!==n?(40===r.charCodeAt(dt)?(e="(",dt++):(e=n,0===gt&&yt(Vr)),e!==n&&Wt()!==n?(t,t="("):(dt=t,t=n)):(dt=t,t=n),gt--,t===n&&(n,0===gt&&yt(et)),t}function Zt(){var t,e;return gt++,t=dt,Wt()!==n?(41===r.charCodeAt(dt)?(e=")",dt++):(e=n,0===gt&&yt(tt)),e!==n?(t,t=")"):(dt=t,t=n)):(dt=t,t=n),gt--,t===n&&(n,0===gt&&yt(nt)),t}function _t(){var t,e;return gt++,t=dt,Wt()!==n?(58===r.charCodeAt(dt)?(e=v,dt++):(e=n,0===gt&&yt(b)),e!==n&&Wt()!==n?(t,t=":"):(dt=t,t=n)):(dt=t,t=n),gt--,t===n&&(n,0===gt&&yt(ut)),t}function Dt(){var t,e;return gt++,t=dt,Wt()!==n?(44===r.charCodeAt(dt)?(e=",",dt++):(e=n,0===gt&&yt(ot)),e!==n&&Wt()!==n?(t,t=","):(dt=t,t=n)):(dt=t,t=n),gt--,t===n&&(n,0===gt&&yt(st)),t}function Ht(){var t;return at.test(r.charAt(dt))?(t=r.charAt(dt),dt++):(t=n,0===gt&&yt(ct)),t}function Kt(){var t;return it.test(r.charAt(dt))?(t=r.charAt(dt),dt++):(t=n,0===gt&&yt(lt)),t}function Pt(){var t,e;if(gt++,t=[],ht.test(r.charAt(dt))?(e=r.charAt(dt),dt++):(e=n,0===gt&&yt(pt)),e!==n)for(;e!==n;)t.push(e),ht.test(r.charAt(dt))?(e=r.charAt(dt),dt++):(e=n,0===gt&&yt(pt));else t=n;return gt--,t===n&&(e=n,0===gt&&yt(ft)),t}function Wt(){var t,e;for(gt++,t=[],ht.test(r.charAt(dt))?(e=r.charAt(dt),dt++):(e=n,0===gt&&yt(pt));e!==n;)t.push(e),ht.test(r.charAt(dt))?(e=r.charAt(dt),dt++):(e=n,0===gt&&yt(pt));return gt--,t===n&&(e=n,0===gt&&yt(ft)),t}if((e=s())!==n&&dt===r.length)return e;throw e!==n&&dt<r.length&&yt({type:"end"}),Et(At,bt<r.length?r.charAt(bt):null,bt<r.length?Lt(bt,bt+1):Lt(bt,bt))}peg$subclass(peg$SyntaxError,Error),peg$SyntaxError.buildMessage=function(r,t){var e={literal:function(r){return'"'+u(r.text)+'"'},class:function(r){var t,e="";for(t=0;t<r.parts.length;t++)e+=r.parts[t]instanceof Array?s(r.parts[t][0])+"-"+s(r.parts[t][1]):s(r.parts[t]);return"["+(r.inverted?"^":"")+e+"]"},any:function(r){return"any character"},end:function(r){return"end of input"},other:function(r){return r.description}};function n(r){return r.charCodeAt(0).toString(16).toUpperCase()}function u(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(r){return"\\x0"+n(r)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(r){return"\\x"+n(r)}))}function s(r){return r.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(r){return"\\x0"+n(r)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(r){return"\\x"+n(r)}))}return"Expected "+function(r){var t,n,u,s=new Array(r.length);for(t=0;t<r.length;t++)s[t]=(u=r[t],e[u.type](u));if(s.sort(),s.length>0){for(t=1,n=1;t<s.length;t++)s[t-1]!==s[t]&&(s[n]=s[t],n++);s.length=n}switch(s.length){case 1:return s[0];case 2:return s[0]+" or "+s[1];default:return s.slice(0,-1).join(", ")+", or "+s[s.length-1]}}(r)+" but "+function(r){return r?'"'+u(r)+'"':"end of input"}(t)+" found."},module.exports={SyntaxError:peg$SyntaxError,parse:peg$parse};
@@ -1,29 +0,0 @@
1
- const { CXL, cds, libx } = require('./_helpers')
2
- const $ = Object.assign
3
-
4
- // We'll extend and replace these below...
5
- const DELETE = libx.DELETE.from('X').constructor
6
- const delete_where = DELETE.prototype.where
7
-
8
-
9
- module.exports = cds.extend (DELETE) .with (class {
10
-
11
- static _api() {
12
- return $((..._) => (this.new).from(..._), {
13
- from: (..._) => (this.new).from(..._),
14
- })
15
- }
16
-
17
- from (target, key) {
18
- this._.from = this._target_name4 (...arguments)
19
- if (key) this.byKey (key)
20
- return this
21
- }
22
-
23
- where(...args) {
24
- if (!args[0]) return this
25
- if (args[0].raw) args = [CXL(...args).xpr]
26
- return delete_where.apply(this,args)
27
- }
28
-
29
- })
@@ -1,23 +0,0 @@
1
- const { libx } = require('./_helpers')
2
- const cds = require('../../index')
3
- const $ = Object.assign
4
-
5
- // We'll extend this below...
6
- const INSERT = libx.INSERT.into('x').constructor
7
-
8
-
9
- module.exports = cds.extend (INSERT) .with (class {
10
-
11
- static _api() {
12
- return $((..._) => (this.new).entries(..._), {
13
- into: (..._) => (this.new).into(..._),
14
- })
15
- }
16
-
17
- into (target, ...data) {
18
- this._.into = this._target_name4 (...arguments)
19
- if (data[0]) this.entries (...data)
20
- return this
21
- }
22
-
23
- })
@@ -1,84 +0,0 @@
1
- const { cds, _predicate4, libx } = require('./_helpers')
2
- const { BaseStatement } = libx
3
- const { inspect } = require('util')
4
-
5
- module.exports = cds.extend (BaseStatement) .with (class {
6
-
7
- static get new() {
8
- const q = new this, cmd = this.name.toUpperCase() // NOSONAR
9
- return Object.defineProperties (q, {_:{value:q[cmd]}, cmd:{value:cmd}})
10
- }
11
-
12
- /** Binds this query to be executed with the given service */
13
- bind (srv) {
14
- return Object.defineProperty (this,'_srv',{value:srv})
15
- }
16
-
17
- /** Turns all queries into Thenables which execute with primary db by default */
18
- then (r,e) {
19
- return (this._srv || cds.db) .run (this) .then (r,e)
20
- }
21
-
22
- /** Beautifies output in REPL */
23
- [inspect.custom]() {
24
- const colors = process.env.CDS_TERM_COLORS !== false
25
- const cmd = this.cmd
26
- return (
27
- `{ ${cmd}: ` +
28
- inspect(this[cmd], { colors, depth: 22 })
29
- .replace(/^\w*\s/, '')
30
- .replace(
31
- /{ ref: \[([^\]]*)\] }/g,
32
- (_, ref) => '{ref:[' + ref.slice(1, -1) + ']}'
33
- )
34
- .replace(/{ val: ([^ ]*) }/g, '{val:$1}')
35
- .replace(/{ (xpr|ref|val): /g, '{$1:') +
36
- '}'
37
- )
38
- }
39
-
40
- _target_ref4 (target) {
41
-
42
- // Resolving this._target --> REVISIT: this is not reliable !!!
43
- Object.defineProperty (this, '_target', { value: target && (
44
- typeof target === 'string' ? { name: target } :
45
- target.name ? target : //> assumed to be a linked csn definition
46
- target.ref ? { name: target.ref[0] } :
47
- target._target || { name: undefined }
48
- ), configurable:true })
49
-
50
- return target && (
51
- typeof target === 'string' ? cds.parse.path(target) :
52
- target.ref ? target :
53
- target.SELECT ? target :
54
- target.SET ? target :
55
- target.raw ? cds.parse.path(...arguments) :
56
- target.name ? {ref:[target.name]} : 0
57
- )
58
- || cds.error.expected `${{target}} to be an entity path string, a CSN definition, a {ref}, a {SELECT}, or a {SET}`
59
- }
60
-
61
- //> REVISIT: should we rather have consistent .from/.entity/.into in CQN?
62
- _target_name4 (target) {
63
- const {ref} = this._target_ref4 (target)
64
- return ref.length === 1 && typeof ref[0] === 'string' ? ref[0] : {ref}
65
- }
66
-
67
- byKey(key) {
68
- if (this.SELECT) this.SELECT.one = true
69
- if (typeof key !== 'object') {
70
- const e = this._target
71
- const ID = e.keys ? Object.keys(e.keys)[0] : 'ID'
72
- key = { [ID]: key }
73
- }
74
- this._.where = _predicate4 (key)
75
- return this
76
- }
77
-
78
- clone() {
79
- const q = this.constructor.new
80
- Object.assign (q._, this._)
81
- return this._srv ? q.bind(this._srv) : q
82
- }
83
-
84
- })