@sap/cds 7.9.4 → 8.0.4
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.
- package/CHANGELOG.md +128 -3659
- package/_i18n/i18n_en_US_saptrc.properties +113 -0
- package/_i18n/i18n_zh_CN.properties +7 -4
- package/app/index.css +129 -0
- package/app/index.html +16 -64
- package/app/index.js +14 -9
- package/bin/args.js +34 -0
- package/bin/serve.js +18 -24
- package/bin/test.js +97 -0
- package/common.cds +5 -12
- package/eslint.config.mjs +133 -0
- package/lib/auth/basic-auth.js +16 -20
- package/lib/auth/dummy-auth.js +1 -1
- package/lib/auth/ias-auth.js +9 -41
- package/lib/auth/index.js +1 -14
- package/lib/auth/jwt-auth.js +10 -40
- package/lib/compile/cds-compile.js +1 -2
- package/lib/compile/cdsc.js +21 -26
- package/lib/compile/etc/_localized.js +1 -6
- package/lib/compile/etc/csv.js +1 -1
- package/lib/compile/etc/properties.js +1 -1
- package/lib/compile/for/java.js +1 -1
- package/lib/compile/for/lean_drafts.js +4 -6
- package/lib/compile/for/nodejs.js +1 -1
- package/lib/compile/parse.js +4 -0
- package/lib/compile/resolve.js +4 -4
- package/lib/compile/to/edm-files.js +16 -23
- package/lib/compile/to/hana.js +27 -0
- package/lib/compile/to/json.js +1 -1
- package/lib/compile/to/sql.js +5 -1
- package/lib/compile/to/yaml.js +3 -3
- package/lib/dbs/cds-deploy.js +4 -2
- package/lib/env/cds-env.js +10 -14
- package/lib/env/cds-requires.js +30 -13
- package/lib/env/defaults.js +46 -16
- package/lib/env/plugins.js +1 -1
- package/lib/env/schemas/cds-rc.js +8 -4
- package/lib/env/schemas/index.js +7 -7
- package/lib/env/serviceBindings.js +1 -1
- package/lib/index.js +12 -10
- package/lib/lazy.js +1 -1
- package/lib/linked/classes.js +36 -8
- package/lib/linked/entities.js +2 -10
- package/lib/linked/models.js +2 -1
- package/lib/linked/validate.js +292 -0
- package/lib/log/cds-error.js +0 -6
- package/lib/log/cds-log.js +3 -3
- package/lib/log/format/json.js +1 -1
- package/lib/log/service/index.js +0 -1
- package/lib/plugins.js +2 -2
- package/lib/ql/Query.js +2 -10
- package/lib/ql/SELECT.js +1 -1
- package/lib/ql/Whereable.js +3 -2
- package/lib/req/cds-context.js +14 -25
- package/lib/req/context.js +23 -25
- package/lib/req/request.js +1 -34
- package/lib/req/user.js +47 -35
- package/lib/srv/bindings.js +1 -1
- package/lib/srv/cds-connect.js +4 -4
- package/lib/srv/cds-serve.js +2 -2
- package/lib/srv/factory.js +1 -1
- package/lib/srv/middlewares/cds-context.js +11 -22
- package/lib/srv/middlewares/ctx-model.js +2 -3
- package/lib/srv/middlewares/errors.js +41 -8
- package/lib/srv/middlewares/index.js +3 -3
- package/lib/srv/middlewares/trace.js +0 -2
- package/lib/srv/protocols/hcql.js +15 -10
- package/lib/srv/protocols/http.js +44 -49
- package/lib/srv/protocols/index.js +1 -23
- package/lib/srv/protocols/odata-v4.js +12 -74
- package/lib/srv/protocols/rest.js +1 -13
- package/lib/srv/srv-api.js +0 -20
- package/lib/srv/srv-dispatch.js +3 -2
- package/lib/srv/srv-handlers.js +22 -11
- package/lib/srv/srv-methods.js +2 -2
- package/lib/srv/srv-models.js +3 -36
- package/lib/test/expect.js +343 -0
- package/lib/test/index.js +2 -0
- package/lib/test/reporter.js +176 -0
- package/lib/utils/axios.js +10 -9
- package/lib/utils/cds-test.js +85 -36
- package/lib/utils/cds-utils.js +54 -7
- package/lib/utils/check-version.js +0 -4
- package/lib/utils/colors.js +49 -0
- package/lib/utils/data.js +5 -4
- package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +2 -7
- package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +3 -30
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +6 -12
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +1 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +0 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +4 -7
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +12 -6
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +2 -4
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/applyToCQN.js +1 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/index.js +0 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +1 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/edm/AbstractEdmStructuredType.js +1 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/deserializer/ResourceJsonDeserializer.js +5 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/ContextURLFactory.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +9 -43
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/metaInfo.js +0 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +8 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/request.js +4 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +1 -3
- package/libx/_runtime/cds-services/util/assert.js +1 -1
- package/libx/_runtime/cds.js +10 -3
- package/libx/_runtime/common/Service.js +12 -32
- package/libx/_runtime/common/aspects/any.js +1 -0
- package/libx/_runtime/common/code-ext/execute.js +1 -1
- package/libx/_runtime/common/code-ext/worker.js +0 -1
- package/libx/_runtime/common/composition/data.js +0 -1
- package/libx/_runtime/common/composition/delete.js +0 -1
- package/libx/_runtime/common/composition/tree.js +0 -1
- package/libx/_runtime/common/composition/update.js +3 -3
- package/libx/_runtime/common/error/frontend.js +21 -12
- package/libx/_runtime/common/error/log.js +36 -0
- package/libx/_runtime/common/error/utils.js +2 -5
- package/libx/_runtime/common/generic/auth/autoexpose.js +18 -17
- package/libx/_runtime/common/generic/auth/expand.js +1 -1
- package/libx/_runtime/common/generic/auth/readOnly.js +1 -2
- package/libx/_runtime/common/generic/auth/restrict.js +23 -42
- package/libx/_runtime/common/generic/auth/restrictions.js +2 -7
- package/libx/_runtime/common/generic/auth/utils.js +91 -88
- package/libx/_runtime/common/generic/crud.js +6 -5
- package/libx/_runtime/common/generic/etag.js +7 -12
- package/libx/_runtime/common/generic/input.js +70 -68
- package/libx/_runtime/common/generic/paging.js +1 -0
- package/libx/_runtime/common/generic/sorting.js +1 -0
- package/libx/_runtime/common/generic/temporal.js +8 -2
- package/libx/_runtime/common/i18n/index.js +1 -1
- package/libx/_runtime/common/i18n/messages.properties +3 -1
- package/libx/_runtime/common/utils/binary.js +8 -2
- package/libx/_runtime/common/utils/compareJson.js +5 -1
- package/libx/_runtime/common/utils/copy.js +6 -11
- package/libx/_runtime/common/utils/cqn2cqn4sql.js +16 -14
- package/libx/_runtime/common/utils/differ.js +3 -6
- package/libx/_runtime/common/utils/keys.js +77 -18
- package/libx/_runtime/common/utils/postProcess.js +12 -15
- package/libx/_runtime/common/utils/propagateForeignKeys.js +0 -1
- package/libx/_runtime/common/utils/resolveView.js +2 -3
- package/libx/_runtime/common/utils/restrictions.js +45 -17
- package/libx/_runtime/common/utils/rewriteAsterisks.js +1 -8
- package/libx/_runtime/common/utils/stream.js +3 -16
- package/libx/_runtime/common/utils/streamProp.js +8 -18
- package/libx/_runtime/common/utils/structured.js +1 -1
- package/libx/_runtime/common/utils/ucsn.js +0 -2
- package/libx/_runtime/db/Service.js +0 -72
- package/libx/_runtime/db/data-conversion/post-processing.js +0 -1
- package/libx/_runtime/db/expand/expandCQNToJoin.js +9 -9
- package/libx/_runtime/db/expand/rawToExpanded.js +0 -8
- package/libx/_runtime/db/generic/input.js +3 -8
- package/libx/_runtime/db/generic/rewrite.js +1 -0
- package/libx/_runtime/db/query/read.js +2 -2
- package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +0 -1
- package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -1
- package/libx/_runtime/db/utils/columns.js +2 -6
- package/libx/_runtime/fiori/lean-draft.js +138 -56
- package/libx/_runtime/hana/Service.js +0 -1
- package/libx/_runtime/hana/driver.js +1 -1
- package/libx/_runtime/hana/dynatrace.js +1 -2
- package/libx/_runtime/hana/pool.js +11 -21
- package/libx/_runtime/hana/streaming.js +0 -1
- package/libx/_runtime/messaging/common-utils/AMQPClient.js +0 -1
- package/libx/_runtime/messaging/common-utils/authorizedRequest.js +1 -1
- package/libx/_runtime/messaging/common-utils/normalizeIncomingMessage.js +1 -1
- package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +1 -1
- package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +19 -33
- package/libx/_runtime/messaging/event-broker.js +54 -27
- package/libx/_runtime/messaging/file-based.js +3 -3
- package/libx/_runtime/messaging/http-utils/token.js +1 -1
- package/libx/_runtime/messaging/kafka.js +2 -2
- package/libx/_runtime/messaging/redis-messaging.js +0 -1
- package/libx/_runtime/remote/Service.js +25 -25
- package/libx/_runtime/remote/utils/client.js +4 -5
- package/libx/_runtime/remote/utils/cloudSdkProvider.js +0 -3
- package/libx/_runtime/remote/utils/data.js +0 -1
- package/libx/_runtime/sqlite/Service.js +1 -2
- package/libx/_runtime/ucl/Service.js +37 -78
- package/libx/common/assert/index.js +22 -21
- package/libx/common/assert/type-relaxed.js +39 -0
- package/libx/common/assert/utils.js +3 -2
- package/libx/common/assert/validation.js +3 -8
- package/libx/common/utils/index.js +5 -0
- package/libx/common/utils/path.js +51 -0
- package/libx/odata/ODataAdapter.js +126 -0
- package/libx/odata/index.js +15 -2
- package/libx/odata/middleware/batch.js +320 -84
- package/libx/odata/middleware/body-parser.js +33 -0
- package/libx/odata/middleware/create.js +44 -59
- package/libx/odata/middleware/delete.js +23 -12
- package/libx/odata/middleware/error.js +30 -6
- package/libx/odata/middleware/metadata.js +38 -26
- package/libx/odata/middleware/operation.js +93 -69
- package/libx/odata/middleware/parse.js +6 -8
- package/libx/odata/middleware/read.js +117 -93
- package/libx/odata/middleware/service-document.js +22 -19
- package/libx/odata/middleware/stream.js +54 -56
- package/libx/odata/middleware/update.js +79 -87
- package/libx/odata/parse/afterburner.js +191 -175
- package/libx/odata/parse/cqn2odata.js +5 -5
- package/libx/odata/parse/grammar.peggy +27 -20
- package/libx/odata/parse/multipartToJson.js +17 -9
- package/libx/odata/parse/parser.js +1 -1
- package/libx/odata/utils/etag.js +14 -6
- package/libx/odata/utils/index.js +84 -12
- package/libx/odata/utils/metadata.js +161 -0
- package/libx/odata/utils/postProcess.js +89 -0
- package/libx/odata/utils/readAfterWrite.js +134 -17
- package/libx/odata/utils/result.js +36 -142
- package/libx/outbox/index.js +4 -3
- package/libx/rest/RestAdapter.js +115 -182
- package/libx/rest/middleware/create.js +28 -24
- package/libx/rest/middleware/delete.js +7 -10
- package/libx/rest/middleware/error.js +26 -16
- package/libx/rest/middleware/operation.js +48 -41
- package/libx/rest/middleware/parse.js +128 -126
- package/libx/rest/middleware/read.js +20 -27
- package/libx/rest/middleware/update.js +26 -31
- package/package.json +17 -8
- package/server.js +4 -2
- package/apis/cds.d.ts +0 -3
- package/apis/core.d.ts +0 -21
- package/apis/cqn.d.ts +0 -18
- package/apis/csn.d.ts +0 -21
- package/apis/events.d.ts +0 -18
- package/apis/internal/inference.d.ts +0 -18
- package/apis/linked.d.ts +0 -18
- package/apis/log.d.ts +0 -20
- package/apis/models.d.ts +0 -18
- package/apis/ql.d.ts +0 -18
- package/apis/reflect.d.ts +0 -32
- package/apis/server.d.ts +0 -18
- package/apis/services.d.ts +0 -22
- package/bin/cds-serve.js +0 -56
- package/lib/compile/to/gql.js +0 -15
- package/lib/srv/protocols/_legacy.js +0 -44
- package/lib/utils/jest.js +0 -43
- package/libx/_runtime/auth/index.js +0 -193
- package/libx/_runtime/auth/strategies/JWT.js +0 -37
- package/libx/_runtime/auth/strategies/basic.js +0 -20
- package/libx/_runtime/auth/strategies/dummy.js +0 -14
- package/libx/_runtime/auth/strategies/ias-auth.js +0 -1
- package/libx/_runtime/auth/strategies/mock.js +0 -77
- package/libx/_runtime/auth/strategies/xssecUtils.js +0 -93
- package/libx/_runtime/auth/strategies/xsuaa.js +0 -38
- package/libx/_runtime/common/perf/index.js +0 -19
- package/libx/_runtime/common/utils/ensureIEEE754.js +0 -29
- package/libx/_runtime/fiori/draft.js +0 -2
- package/libx/_runtime/fiori/generic/activate.js +0 -190
- package/libx/_runtime/fiori/generic/before.js +0 -201
- package/libx/_runtime/fiori/generic/cancel.js +0 -19
- package/libx/_runtime/fiori/generic/delete.js +0 -21
- package/libx/_runtime/fiori/generic/edit.js +0 -157
- package/libx/_runtime/fiori/generic/index.js +0 -25
- package/libx/_runtime/fiori/generic/new.js +0 -82
- package/libx/_runtime/fiori/generic/patch.js +0 -101
- package/libx/_runtime/fiori/generic/prepare.js +0 -57
- package/libx/_runtime/fiori/generic/read.js +0 -1340
- package/libx/_runtime/fiori/generic/readOverDraft.js +0 -146
- package/libx/_runtime/fiori/utils/csn.js +0 -13
- package/libx/_runtime/fiori/utils/delete.js +0 -114
- package/libx/_runtime/fiori/utils/handler.js +0 -264
- package/libx/_runtime/fiori/utils/lockInfo.js +0 -27
- package/libx/_runtime/fiori/utils/req.js +0 -23
- package/libx/_runtime/fiori/utils/stream.js +0 -36
- package/libx/_runtime/fiori/utils/where.js +0 -254
- package/libx/_runtime/index.js +0 -22
- package/libx/odata/utils/handler.js +0 -120
- package/libx/odata/utils/metaInfo.js +0 -410
- package/libx/odata/utils/path.js +0 -75
- package/libx/rest/RestRequest.js +0 -32
- package/libx/rest/index.js +0 -3
- package/libx/rest/readme.md +0 -1
- /package/libx/common/assert/{type.js → type-strict.js} +0 -0
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
const AND_OR = { and: 1, or: 1 }
|
|
2
|
-
|
|
3
|
-
const _removeMultipleBrackets = (index, whereCondition, isXpr) => {
|
|
4
|
-
if (isXpr) return index
|
|
5
|
-
|
|
6
|
-
let resIndex = index
|
|
7
|
-
if (whereCondition[index - 1] === '(') {
|
|
8
|
-
while (resIndex - 2 >= 0 && whereCondition[resIndex - 2] === '(') {
|
|
9
|
-
const indexClose = whereCondition.findIndex((element, elementIndex) => element === ')' && elementIndex > index)
|
|
10
|
-
|
|
11
|
-
if (whereCondition[indexClose + 1] === ')') {
|
|
12
|
-
whereCondition.splice(indexClose + 1, 1)
|
|
13
|
-
whereCondition.splice(resIndex - 2, 1)
|
|
14
|
-
resIndex--
|
|
15
|
-
} else {
|
|
16
|
-
break
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return resIndex
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const _calculateSpliceArgs = (index, whereCondition, isXpr = false) => {
|
|
25
|
-
const len = isXpr ? 1 : 3
|
|
26
|
-
if (whereCondition[index - 1] in AND_OR) {
|
|
27
|
-
return { index: index - 1, count: 1 + len }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (whereCondition[index + len] in AND_OR) {
|
|
31
|
-
return { index: index, count: len + 1 }
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (whereCondition[index - 1] === '(' && whereCondition[index + len] === ')') {
|
|
35
|
-
if (whereCondition[index - 2] in AND_OR) {
|
|
36
|
-
return { index: index - 2, count: len + 3 }
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (whereCondition[index + len + 1] in AND_OR) {
|
|
40
|
-
return { index: index - 1, count: len + 3 }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return { index: index - 1, count: len + 2 }
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return { index: index, count: len }
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const _isActiveEntity = entry => entry.ref && entry.ref[entry.ref.length - 1] === 'IsActiveEntity'
|
|
50
|
-
|
|
51
|
-
const _removeIsActiveEntityCondition = where => {
|
|
52
|
-
const newWhere = []
|
|
53
|
-
const length = where.length
|
|
54
|
-
let i = 0
|
|
55
|
-
|
|
56
|
-
while (i < length) {
|
|
57
|
-
if (_isActiveEntity(where[i])) {
|
|
58
|
-
i = i + 3
|
|
59
|
-
} else if (where[i] === 'and' && _isActiveEntity(where[i + 1])) {
|
|
60
|
-
i = i + 4
|
|
61
|
-
} else if (where[i].xpr) {
|
|
62
|
-
if (where[i].xpr.length) {
|
|
63
|
-
newWhere.push({ xpr: _removeIsActiveEntityCondition(where[i].xpr) })
|
|
64
|
-
}
|
|
65
|
-
i++
|
|
66
|
-
} else {
|
|
67
|
-
newWhere.push(where[i])
|
|
68
|
-
i++
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (newWhere[0] === 'and' || newWhere[0] === 'or') {
|
|
73
|
-
newWhere.splice(0, 1)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return newWhere
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const _isKeyValue = (i, keys, where) => {
|
|
80
|
-
if (!where[i].ref || !keys.includes(where[i].ref[0])) {
|
|
81
|
-
return false
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return where[i + 1] === '=' && 'val' in where[i + 2]
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const deleteCondition = (index, whereCondition, isXpr = false) => {
|
|
88
|
-
index = _removeMultipleBrackets(index, whereCondition, isXpr)
|
|
89
|
-
const spliceArgs = _calculateSpliceArgs(index, whereCondition, isXpr)
|
|
90
|
-
whereCondition.splice(spliceArgs.index, spliceArgs.count)
|
|
91
|
-
return spliceArgs.index
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const readAndDeleteKeywords = (keywords, whereCondition, toDelete = true) => {
|
|
95
|
-
let index = -1
|
|
96
|
-
for (let i = 0; i < whereCondition.length; i++) {
|
|
97
|
-
const entry = whereCondition[i]
|
|
98
|
-
if (entry.xpr) {
|
|
99
|
-
const result = readAndDeleteKeywords(keywords, entry.xpr, toDelete)
|
|
100
|
-
if (result) {
|
|
101
|
-
if (entry.xpr.length === 0) {
|
|
102
|
-
deleteCondition(i, whereCondition, true)
|
|
103
|
-
}
|
|
104
|
-
return result
|
|
105
|
-
}
|
|
106
|
-
} else if (entry.ref) {
|
|
107
|
-
const refLastIndex = entry.ref.length - 1
|
|
108
|
-
|
|
109
|
-
if (keywords.length === 1) {
|
|
110
|
-
if (entry.ref[refLastIndex] === keywords[0]) {
|
|
111
|
-
index = i
|
|
112
|
-
break
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (keywords.length === 2 && entry.ref.length >= 2) {
|
|
117
|
-
if (entry.ref[refLastIndex - 1] === keywords[0] && entry.ref[refLastIndex] === keywords[1]) {
|
|
118
|
-
index = i
|
|
119
|
-
break
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (index === -1) {
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const result = {
|
|
130
|
-
op: whereCondition[index + 1],
|
|
131
|
-
value: whereCondition[index + 2]
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (toDelete) {
|
|
135
|
-
deleteCondition(index, whereCondition)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return result
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const removeIsActiveEntityRecursively = where => {
|
|
142
|
-
for (const entry of where) {
|
|
143
|
-
if (entry.xpr) {
|
|
144
|
-
entry.xpr = removeIsActiveEntityRecursively(entry.xpr)
|
|
145
|
-
continue
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (entry.SELECT && entry.SELECT.where && entry.SELECT.from.ref && !entry.SELECT.from.ref[0].endsWith('_drafts')) {
|
|
149
|
-
entry.SELECT.where = removeIsActiveEntityRecursively(entry.SELECT.where)
|
|
150
|
-
|
|
151
|
-
if (entry.SELECT.where.length === 0) {
|
|
152
|
-
delete entry.SELECT.where
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return _removeIsActiveEntityCondition(where)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const isActiveEntityRequested = where => {
|
|
161
|
-
if (!where) return true
|
|
162
|
-
|
|
163
|
-
let i = 0
|
|
164
|
-
|
|
165
|
-
while (where[i]) {
|
|
166
|
-
if (where[i].xpr) {
|
|
167
|
-
const isRequested = isActiveEntityRequested(where[i].xpr)
|
|
168
|
-
if (isRequested) return true
|
|
169
|
-
}
|
|
170
|
-
if (
|
|
171
|
-
where[i].ref &&
|
|
172
|
-
where[i].ref[where[i].ref.length - 1] === 'IsActiveEntity' &&
|
|
173
|
-
where[i + 1] === '=' &&
|
|
174
|
-
'val' in where[i + 2]
|
|
175
|
-
) {
|
|
176
|
-
return where[i + 2].val === 'true' || where[i + 2].val === true
|
|
177
|
-
}
|
|
178
|
-
i++
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return true
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const getKeyData = (keys, where) => {
|
|
185
|
-
if (!where) {
|
|
186
|
-
return {}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const data = {}
|
|
190
|
-
let i = 0
|
|
191
|
-
|
|
192
|
-
while (where[i]) {
|
|
193
|
-
if (_isKeyValue(i, keys, where)) {
|
|
194
|
-
data[where[i].ref[0]] = where[i + 2].val
|
|
195
|
-
i = i + 3
|
|
196
|
-
} else {
|
|
197
|
-
i++
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return data
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const extractKeyConditions = whereCondition => {
|
|
205
|
-
const result = {
|
|
206
|
-
keyList: []
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const newWhere = [...whereCondition]
|
|
210
|
-
const readKeywords = readAndDeleteKeywords(['IsActiveEntity'], newWhere)
|
|
211
|
-
result.IsActiveEntity = readKeywords && readKeywords.value && readKeywords.value.val !== false
|
|
212
|
-
result.keyList = newWhere
|
|
213
|
-
|
|
214
|
-
return result
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const getKeysCondition = req => {
|
|
218
|
-
const data = req.data
|
|
219
|
-
const target = req.target
|
|
220
|
-
const where = []
|
|
221
|
-
for (const k in target.keys) {
|
|
222
|
-
const key = target.keys[k]
|
|
223
|
-
if (!key.isAssociation && key.name !== 'IsActiveEntity' && data[key.name] != undefined) {
|
|
224
|
-
if (where.length) where.push('and')
|
|
225
|
-
where.push({ ref: [key.name] }, '=', { val: data[key.name] })
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return where
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const getLockWhere = (where, columnsMap) => {
|
|
232
|
-
if (columnsMap.size === 0) return where
|
|
233
|
-
const whereKeys = Object.keys(where)
|
|
234
|
-
const lockWhere = {}
|
|
235
|
-
|
|
236
|
-
whereKeys.forEach(key => {
|
|
237
|
-
const mappedKey = columnsMap.get(key)
|
|
238
|
-
const lockKey = mappedKey ? mappedKey.ref[0] : key
|
|
239
|
-
lockWhere[lockKey] = where[key]
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
return lockWhere
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
module.exports = {
|
|
246
|
-
deleteCondition,
|
|
247
|
-
readAndDeleteKeywords,
|
|
248
|
-
removeIsActiveEntityRecursively,
|
|
249
|
-
isActiveEntityRequested,
|
|
250
|
-
getKeyData,
|
|
251
|
-
extractKeyConditions,
|
|
252
|
-
getKeysCondition,
|
|
253
|
-
getLockWhere
|
|
254
|
-
}
|
package/libx/_runtime/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
to: {
|
|
3
|
-
/** @type {import('./cds-services/adapter/odata-v4/to')} */
|
|
4
|
-
get odata_v4() {
|
|
5
|
-
return this._odatav4 || (this._odatav4 = require('./cds-services/adapter/odata-v4/to'))
|
|
6
|
-
},
|
|
7
|
-
|
|
8
|
-
get rest() {
|
|
9
|
-
return this._rest || (this._rest = require('../rest'))
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
/** @type {import('./auth')} */
|
|
14
|
-
get auth() {
|
|
15
|
-
return this._auth || (this._auth = require('./auth'))
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
/** @type {import('./common/perf')} */
|
|
19
|
-
get perf() {
|
|
20
|
-
return this._perf || (this._perf = require('./common/perf'))
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
const cds = require('../../_runtime/cds')
|
|
2
|
-
const { SELECT } = cds.ql
|
|
3
|
-
|
|
4
|
-
const { DRAFT_COLUMNS_MAP } = require('../../_runtime/common/constants/draft')
|
|
5
|
-
|
|
6
|
-
const _keysOf = (row, target) => {
|
|
7
|
-
const keyElements = Object.values(target.keys || {}).filter(v => !v.virtual)
|
|
8
|
-
// > singleton
|
|
9
|
-
if (!keyElements.length) return
|
|
10
|
-
const keys = {}
|
|
11
|
-
for (const key of keyElements) {
|
|
12
|
-
if (key._isAssociationStrict) continue
|
|
13
|
-
if (row[key.name] === undefined) continue // key is not in data, so ignore it
|
|
14
|
-
keys[key.name] = key.elements ? { val: JSON.stringify(row[key.name]) } : row[key.name]
|
|
15
|
-
}
|
|
16
|
-
return keys
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const getSimpleSelectCQN = (target, data, columns, subject) => {
|
|
20
|
-
const keys = _keysOf(data, target)
|
|
21
|
-
// don't use `ql.where()` to get `where` in `from` for location header
|
|
22
|
-
let cqn
|
|
23
|
-
// reflect request path in read after write
|
|
24
|
-
if (subject?.ref.length > 1) {
|
|
25
|
-
cqn = SELECT.one(subject)
|
|
26
|
-
if (keys) cqn.where(keys)
|
|
27
|
-
} else {
|
|
28
|
-
cqn = keys ? SELECT.one(target, keys) : /* singleton */ SELECT.one(target)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (columns) {
|
|
32
|
-
cqn.columns(...columns)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (target.query && target.query.SELECT && target.query.SELECT.orderBy) {
|
|
36
|
-
cqn.SELECT.orderBy = target.query.SELECT.orderBy
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return cqn
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const _mergeExpandCQNs = cqns => {
|
|
43
|
-
const cols = cqns[0].SELECT.columns
|
|
44
|
-
for (const cqn of cqns.slice(1)) {
|
|
45
|
-
for (const col of cqn.SELECT.columns) {
|
|
46
|
-
if (!col.expand) continue
|
|
47
|
-
const idx = cols.findIndex(ele => {
|
|
48
|
-
if (!col.ref) return
|
|
49
|
-
if (ele.ref) return ele.ref[0] === col.ref[0]
|
|
50
|
-
if (ele.as) return ele.as === col.ref[0]
|
|
51
|
-
})
|
|
52
|
-
if (idx === -1) {
|
|
53
|
-
cols.push(col)
|
|
54
|
-
} else {
|
|
55
|
-
const colExists = cols[idx]
|
|
56
|
-
if (colExists.as && colExists.val === null) {
|
|
57
|
-
cols[idx] = col
|
|
58
|
-
continue
|
|
59
|
-
}
|
|
60
|
-
if (col.as && col.val === null) continue
|
|
61
|
-
const mergedExpandCQN = _mergeExpandCQNs([
|
|
62
|
-
{ SELECT: { columns: colExists.expand } },
|
|
63
|
-
{ SELECT: { columns: col.expand } }
|
|
64
|
-
])
|
|
65
|
-
colExists.expand = mergedExpandCQN.SELECT.columns
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return cqns[0]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const _getExpandColumn = (data, element) => {
|
|
73
|
-
const key = element.name
|
|
74
|
-
if (!(key in data)) return
|
|
75
|
-
data = data[key]
|
|
76
|
-
if ((Array.isArray(data) && data.length === 0) || data == null) {
|
|
77
|
-
// performance tweak, keep in mind it is only for compositions
|
|
78
|
-
return { val: null, as: key }
|
|
79
|
-
}
|
|
80
|
-
const cqn = Array.isArray(data)
|
|
81
|
-
? _mergeExpandCQNs(data.map(data => getDeepSelect({ target: element._target, data })))
|
|
82
|
-
: getDeepSelect({ target: element._target, data })
|
|
83
|
-
return { ref: [key], expand: cqn.SELECT.columns }
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const _getColumns = (target, data, prefix = []) => {
|
|
87
|
-
const columns = []
|
|
88
|
-
for (const each in target.elements) {
|
|
89
|
-
if (target.elements[each]['@cds.api.ignore']) continue
|
|
90
|
-
if (each in DRAFT_COLUMNS_MAP) continue
|
|
91
|
-
if (!cds.env.features.stream_compat && target.elements[each].type === 'cds.LargeBinary') continue
|
|
92
|
-
const element = target.elements[each]
|
|
93
|
-
if (element.elements && data[each]) {
|
|
94
|
-
prefix.push(element.name)
|
|
95
|
-
columns.push(..._getColumns(element, data[each], prefix))
|
|
96
|
-
prefix.pop()
|
|
97
|
-
} else if (element.isComposition && !prefix.length) {
|
|
98
|
-
const col = _getExpandColumn(data, element, prefix)
|
|
99
|
-
if (col) columns.push(col)
|
|
100
|
-
} else if (!element.isAssociation) {
|
|
101
|
-
columns.push({ ref: [...prefix, each] })
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return columns
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/*
|
|
108
|
-
* recursively builds a select cqn for deep read after write
|
|
109
|
-
* (depth determined by req.data)
|
|
110
|
-
*/
|
|
111
|
-
const getDeepSelect = req => {
|
|
112
|
-
let { target, data, subject } = req
|
|
113
|
-
const columns = _getColumns(target, data)
|
|
114
|
-
return getSimpleSelectCQN(target, data, columns, subject)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
module.exports = {
|
|
118
|
-
getDeepSelect,
|
|
119
|
-
getSimpleSelectCQN
|
|
120
|
-
}
|