@sap/cds 5.9.7 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +267 -20
- package/apis/services.d.ts +1 -1
- package/app/fiori/preview.js +2 -6
- package/app/index.js +3 -3
- package/bin/build/buildTaskEngine.js +17 -15
- package/bin/build/buildTaskFactory.js +29 -19
- package/bin/build/buildTaskHandler.js +27 -11
- package/bin/build/buildTaskProvider.js +2 -4
- package/bin/build/buildTaskProviderFactory.js +11 -16
- package/bin/build/constants.js +14 -6
- package/bin/build/csv-reader.js +2 -1
- package/bin/build/index.js +12 -18
- package/bin/build/provider/buildTaskHandlerEdmx.js +3 -39
- package/bin/build/provider/buildTaskHandlerFeatureToggles.js +149 -0
- package/bin/build/provider/buildTaskHandlerInternal.js +2 -3
- package/bin/build/provider/buildTaskProviderInternal.js +108 -239
- package/bin/build/provider/fiori/index.js +2 -2
- package/bin/build/provider/hana/2migration.js +11 -11
- package/bin/build/provider/hana/2tabledata.js +3 -3
- package/bin/build/provider/hana/index.js +89 -99
- package/bin/build/provider/hana/migrationtable.js +4 -3
- package/bin/build/provider/java/index.js +101 -0
- package/bin/build/provider/java-cf/index.js +1 -101
- package/bin/build/provider/mtx/index.js +90 -53
- package/bin/build/provider/mtx/resourcesTarBuilder.js +68 -0
- package/bin/build/provider/mtx-sidecar/index.js +110 -0
- package/bin/build/provider/node-cf/index.js +1 -308
- package/bin/build/provider/nodejs/index.js +189 -0
- package/bin/build/util.js +19 -31
- package/bin/cds.js +5 -3
- package/bin/deploy/to-hana/cfUtil.js +31 -6
- package/bin/deploy/to-hana/gitUtil.js +5 -3
- package/bin/deploy/to-hana/hana.js +9 -10
- package/bin/{build → deploy/to-hana}/mtaUtil.js +10 -9
- package/bin/mtx/in-cds.js +19 -7
- package/bin/serve.js +56 -21
- package/bin/utils/log.js +13 -30
- package/bin/version.js +5 -4
- package/common.cds +61 -16
- package/lib/compile/cdsc.js +3 -2
- package/lib/compile/etc/_localized.js +15 -14
- package/lib/compile/for/drafts.js +3 -4
- package/lib/compile/for/java.js +13 -10
- package/lib/compile/for/nodejs.js +8 -8
- package/lib/compile/for/odata.js +7 -12
- package/lib/compile/for/sql.js +5 -6
- package/lib/compile/index.js +5 -4
- package/lib/compile/load.js +9 -11
- package/lib/compile/minify.js +8 -5
- package/lib/compile/parse.js +4 -2
- package/lib/compile/resolve.js +18 -15
- package/lib/compile/to/edm.js +0 -1
- package/lib/compile/to/gql.js +3 -2
- package/lib/compile/to/json.js +24 -17
- package/lib/connect/bindings.js +3 -2
- package/lib/connect/index.js +5 -5
- package/lib/core/classes.js +74 -2
- package/lib/core/entities.js +52 -3
- package/lib/core/reflect.js +2 -1
- package/lib/deploy.js +11 -8
- package/lib/env/defaults.js +4 -3
- package/lib/env/index.js +71 -31
- package/lib/env/presets.js +1 -14
- package/lib/env/requires.js +71 -20
- package/lib/env/serviceBindings.js +147 -0
- package/lib/i18n/localize.js +22 -23
- package/lib/index.js +148 -144
- package/lib/log/errors.js +55 -12
- package/lib/log/format/kibana.js +1 -1
- package/lib/log/index.js +4 -0
- package/lib/ql/SELECT.js +7 -2
- package/lib/ql/Whereable.js +8 -2
- package/lib/ql/index.js +2 -2
- package/lib/req/assert.js +71 -0
- package/lib/req/cds-context.js +38 -70
- package/lib/req/context.js +34 -21
- package/lib/req/request.js +12 -18
- package/lib/req/response.js +6 -2
- package/lib/req/user.js +30 -22
- package/lib/serve/Service-api.js +17 -12
- package/lib/serve/Service-dispatch.js +5 -9
- package/lib/serve/Service-methods.js +4 -3
- package/lib/serve/Transaction.js +24 -21
- package/lib/serve/adapters.js +15 -5
- package/lib/serve/factory.js +23 -20
- package/lib/serve/index.js +51 -54
- package/lib/utils/axios.js +8 -12
- package/lib/utils/index.js +3 -3
- package/lib/utils/resources/index.js +1 -44
- package/lib/utils/resources/tar.js +2 -1
- package/lib/utils/tests.js +13 -15
- package/libx/_runtime/.eslintrc +1 -1
- package/libx/_runtime/audit/Service.js +6 -4
- package/libx/_runtime/audit/generic/personal/access.js +19 -43
- package/libx/_runtime/audit/generic/personal/index.js +40 -34
- package/libx/_runtime/audit/generic/personal/modification.js +11 -9
- package/libx/_runtime/audit/generic/personal/utils.js +13 -6
- package/libx/_runtime/audit/utils/v2.js +6 -3
- package/libx/_runtime/auth/index.js +71 -66
- package/libx/_runtime/auth/strategies/JWT.js +3 -2
- package/libx/_runtime/auth/strategies/mock.js +54 -53
- package/libx/_runtime/auth/strategies/xssecUtils.js +3 -4
- package/libx/_runtime/auth/strategies/xsuaa.js +3 -2
- package/libx/_runtime/auth/utils.js +2 -15
- package/libx/_runtime/cds-services/adapter/odata-v4/Dispatcher.js +128 -42
- package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +6 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +93 -73
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +10 -45
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +5 -9
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +9 -5
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +4 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +60 -53
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +15 -21
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +8 -15
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +29 -41
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/index.js +1 -4
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +13 -13
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/selectToCQN.js +0 -7
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/utils.js +24 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/edm/EdmEntityContainer.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriHelper.js +4 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/PrimitiveValueDecoder.js +4 -5
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/ValueConverter.js +4 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/validator/ValueValidator.js +5 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/core/ResponseHeaderSetter.js +2 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/DebugSerializingCommand.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/PresetResponseHeadersCommand.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/SerializingCommand.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/SetResponseHeadersCommand.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/ContextURLFactory.js +3 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/ErrorJsonSerializer.js +3 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/SerializerFactory.js +1 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/TrustedResourceJsonSerializer.js +3 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +36 -25
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/handlerUtils.js +100 -91
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/metaInfo.js +382 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/oDataConfiguration.js +1 -4
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/omitValues.js +5 -6
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +77 -21
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/request.js +3 -11
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +91 -69
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +27 -6
- package/libx/_runtime/cds-services/adapter/rest/utils/validation-checks.js +7 -17
- package/libx/_runtime/cds-services/services/Service.js +17 -76
- package/libx/_runtime/cds-services/services/utils/columns.js +6 -4
- package/libx/_runtime/cds-services/services/utils/compareJson.js +1 -53
- package/libx/_runtime/cds-services/services/utils/differ.js +15 -19
- package/libx/_runtime/cds-services/util/assert.js +107 -34
- package/libx/_runtime/cds.js +1 -31
- package/libx/_runtime/common/aspects/Association.js +40 -54
- package/libx/_runtime/common/aspects/any.js +61 -6
- package/libx/_runtime/common/aspects/entity.js +19 -79
- package/libx/_runtime/common/composition/data.js +2 -2
- package/libx/_runtime/common/composition/delete.js +8 -7
- package/libx/_runtime/common/composition/tree.js +10 -10
- package/libx/_runtime/common/composition/update.js +3 -2
- package/libx/_runtime/common/constants/events.js +15 -0
- package/libx/_runtime/common/error/entry.js +9 -3
- package/libx/_runtime/common/error/frontend.js +13 -19
- package/libx/_runtime/common/error/index.js +8 -3
- package/libx/_runtime/common/generic/auth/capabilities.js +2 -1
- package/libx/_runtime/common/generic/auth/constants.js +1 -4
- package/libx/_runtime/common/generic/auth/requires.js +1 -1
- package/libx/_runtime/common/generic/auth/restrict.js +12 -28
- package/libx/_runtime/common/generic/auth/restrictions.js +12 -4
- package/libx/_runtime/common/generic/auth/utils.js +2 -1
- package/libx/_runtime/common/generic/crud.js +9 -60
- package/libx/_runtime/common/generic/etag.js +41 -7
- package/libx/_runtime/common/generic/input.js +128 -66
- package/libx/_runtime/common/generic/paging.js +9 -3
- package/libx/_runtime/common/generic/put.js +2 -2
- package/libx/_runtime/common/generic/sorting.js +7 -3
- package/libx/_runtime/common/generic/temporal.js +0 -5
- package/libx/_runtime/common/i18n/messages.properties +2 -1
- package/libx/_runtime/common/utils/binary.js +69 -0
- package/libx/_runtime/common/utils/cqn.js +39 -14
- package/libx/_runtime/common/utils/cqn2cqn4sql.js +93 -59
- package/libx/_runtime/common/utils/csn.js +87 -85
- package/libx/_runtime/common/utils/dollar.js +8 -7
- package/libx/_runtime/common/utils/draft.js +1 -1
- package/libx/_runtime/common/utils/foreignKeyPropagations.js +23 -7
- package/libx/_runtime/common/utils/generateOnCond.js +2 -1
- package/libx/_runtime/common/utils/keys.js +30 -13
- package/libx/_runtime/common/utils/postProcessing.js +6 -1
- package/libx/_runtime/common/utils/quotingStyles.js +0 -23
- package/libx/_runtime/common/utils/resolveStructured.js +23 -26
- package/libx/_runtime/common/utils/resolveView.js +4 -1
- package/libx/_runtime/common/utils/rewriteAsterisks.js +3 -0
- package/libx/_runtime/common/utils/search2cqn4sql.js +4 -13
- package/libx/_runtime/common/utils/searchToLike.js +9 -13
- package/libx/_runtime/common/utils/streamProp.js +35 -0
- package/libx/_runtime/common/utils/structured.js +12 -18
- package/libx/_runtime/common/utils/template.js +3 -5
- package/libx/_runtime/common/utils/templateProcessor.js +22 -14
- package/libx/_runtime/common/utils/unionCqnTemplate.js +4 -14
- package/libx/_runtime/db/Service.js +2 -1
- package/libx/_runtime/db/expand/expand-v2.js +2 -2
- package/libx/_runtime/db/expand/expandCQNToJoin.js +7 -6
- package/libx/_runtime/db/generic/input.js +14 -17
- package/libx/_runtime/db/generic/integrity.js +1 -2
- package/libx/_runtime/db/generic/update.js +14 -1
- package/libx/_runtime/db/query/read.js +0 -1
- package/libx/_runtime/db/query/update.js +1 -1
- package/libx/_runtime/db/sql-builder/BaseBuilder.js +1 -1
- package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +5 -31
- package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -1
- package/libx/_runtime/db/sql-builder/ReferenceBuilder.js +0 -9
- package/libx/_runtime/db/sql-builder/SelectBuilder.js +11 -10
- package/libx/_runtime/db/sql-builder/UpdateBuilder.js +2 -2
- package/libx/_runtime/db/sql-builder/annotations.js +1 -2
- package/libx/_runtime/db/utils/coloredTxCommands.js +5 -0
- package/libx/_runtime/db/utils/columns.js +1 -1
- package/libx/_runtime/db/utils/propagateForeignKeys.js +10 -2
- package/libx/_runtime/extensibility/activate.js +69 -0
- package/libx/_runtime/extensibility/add.js +41 -0
- package/libx/_runtime/extensibility/addExtension.js +68 -0
- package/libx/_runtime/extensibility/defaults.js +39 -0
- package/libx/_runtime/extensibility/{uiflex/handler → handler}/transformREAD.js +0 -0
- package/libx/_runtime/extensibility/{uiflex/handler → handler}/transformRESULT.js +2 -2
- package/libx/_runtime/extensibility/{uiflex/handler → handler}/transformWRITE.js +2 -2
- package/libx/_runtime/extensibility/push.js +61 -0
- package/libx/_runtime/extensibility/service.js +21 -0
- package/libx/_runtime/extensibility/{uiflex/utils.js → utils.js} +39 -3
- package/libx/_runtime/extensibility/validation.js +53 -0
- package/libx/_runtime/extensibility/views.js +12 -0
- package/libx/_runtime/fiori/generic/activate.js +6 -4
- package/libx/_runtime/fiori/generic/before.js +17 -29
- package/libx/_runtime/fiori/generic/cancel.js +2 -4
- package/libx/_runtime/fiori/generic/delete.js +2 -4
- package/libx/_runtime/fiori/generic/edit.js +3 -7
- package/libx/_runtime/fiori/generic/index.js +31 -0
- package/libx/_runtime/fiori/generic/new.js +2 -4
- package/libx/_runtime/fiori/generic/patch.js +4 -8
- package/libx/_runtime/fiori/generic/prepare.js +2 -4
- package/libx/_runtime/fiori/generic/read.js +137 -162
- package/libx/_runtime/fiori/generic/readOverDraft.js +10 -4
- package/libx/_runtime/fiori/utils/handler.js +10 -5
- package/libx/_runtime/fiori/utils/where.js +1 -4
- package/libx/_runtime/hana/Service.js +14 -7
- package/libx/_runtime/hana/customBuilder/CustomSelectBuilder.js +1 -1
- package/libx/_runtime/hana/dynatrace.js +2 -2
- package/libx/_runtime/hana/localized.js +7 -6
- package/libx/_runtime/hana/pool.js +9 -6
- package/libx/_runtime/hana/search.js +2 -3
- package/libx/_runtime/hana/{searchToContains.js → search2Contains.js} +5 -2
- package/libx/_runtime/hana/search2cqn4sql.js +20 -17
- package/libx/_runtime/index.js +2 -6
- package/libx/_runtime/messaging/AMQPWebhookMessaging.js +11 -2
- package/libx/_runtime/messaging/common-utils/AMQPClient.js +4 -3
- package/libx/_runtime/messaging/common-utils/appId.js +9 -0
- package/libx/_runtime/messaging/common-utils/authorizedRequest.js +2 -18
- package/libx/_runtime/messaging/common-utils/connections.js +1 -1
- package/libx/_runtime/messaging/enterprise-messaging-shared.js +2 -2
- package/libx/_runtime/messaging/enterprise-messaging-utils/EMManagement.js +305 -231
- package/libx/_runtime/messaging/enterprise-messaging-utils/cloudEvents.js +2 -2
- package/libx/_runtime/messaging/enterprise-messaging-utils/options-management.js +15 -8
- package/libx/_runtime/messaging/enterprise-messaging-utils/options-messaging.js +57 -14
- package/libx/_runtime/messaging/enterprise-messaging.js +14 -19
- package/libx/_runtime/messaging/file-based.js +2 -1
- package/libx/_runtime/messaging/http-utils/token.js +18 -6
- package/libx/_runtime/messaging/message-queuing-utils/options-management.js +22 -12
- package/libx/_runtime/messaging/message-queuing-utils/options-messaging.js +27 -14
- package/libx/_runtime/messaging/message-queuing.js +138 -85
- package/libx/_runtime/messaging/outbox/utils.js +13 -7
- package/libx/_runtime/messaging/redis-messaging.js +0 -1
- package/libx/_runtime/messaging/service.js +4 -1
- package/libx/_runtime/remote/Service.js +24 -18
- package/libx/_runtime/remote/utils/client.js +84 -46
- package/libx/_runtime/remote/utils/data.js +23 -6
- package/libx/_runtime/sqlite/Service.js +14 -13
- package/libx/_runtime/sqlite/convertAssocToOneManaged.js +2 -0
- package/libx/_runtime/sqlite/customBuilder/CustomSelectBuilder.js +1 -0
- package/libx/_runtime/sqlite/execute.js +3 -9
- package/libx/_runtime/types/api.js +23 -11
- package/libx/common/utils/ucsn.js +15 -9
- package/libx/odata/afterburner.js +109 -29
- package/libx/odata/cqn2odata.js +48 -9
- package/libx/odata/grammar.pegjs +261 -157
- package/libx/odata/index.js +21 -9
- package/libx/odata/parseToCqn.js +8 -5
- package/libx/odata/parser.js +1 -1
- package/libx/odata/utils.js +13 -3
- package/libx/rest/RestAdapter.js +173 -113
- package/libx/rest/RestRequest.js +3 -2
- package/libx/rest/middleware/create.js +8 -6
- package/libx/rest/middleware/delete.js +6 -13
- package/libx/rest/middleware/error.js +1 -1
- package/libx/rest/middleware/input.js +6 -6
- package/libx/rest/middleware/operation.js +8 -3
- package/libx/rest/middleware/parse.js +3 -3
- package/libx/rest/middleware/payload.js +12 -0
- package/libx/rest/middleware/read.js +12 -2
- package/libx/rest/middleware/update.js +3 -3
- package/package.json +4 -6
- package/server.js +3 -44
- package/srv/extensibility-service.cds +56 -0
- package/srv/extensibility-service.js +1 -0
- package/srv/extensions.cds +8 -0
- package/srv/model-provider.cds +59 -0
- package/srv/model-provider.js +163 -0
- package/srv/mtx.cds +2 -0
- package/srv/mtx.js +22 -0
- package/srv/outbox.cds +2 -0
- package/tasks/enterprise-messaging-deploy.js +19 -12
- package/lib/serve/Service-compat.js +0 -36
- package/libx/_runtime/audit/generic/personal/constants.js +0 -4
- package/libx/_runtime/auth/strategies/dwc.js +0 -45
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/dispatcherUtils.js +0 -56
- package/libx/_runtime/cds-services/adapter/rest/Rest.js +0 -183
- package/libx/_runtime/cds-services/adapter/rest/RestRequest.js +0 -67
- package/libx/_runtime/cds-services/adapter/rest/handlers/create.js +0 -82
- package/libx/_runtime/cds-services/adapter/rest/handlers/delete.js +0 -39
- package/libx/_runtime/cds-services/adapter/rest/handlers/operation.js +0 -63
- package/libx/_runtime/cds-services/adapter/rest/handlers/read.js +0 -52
- package/libx/_runtime/cds-services/adapter/rest/handlers/update.js +0 -81
- package/libx/_runtime/cds-services/adapter/rest/rest-to-cqn/index.js +0 -56
- package/libx/_runtime/cds-services/adapter/rest/rest-to-cqn/utils.js +0 -33
- package/libx/_runtime/cds-services/adapter/rest/to.js +0 -8
- package/libx/_runtime/cds-services/adapter/rest/utils/binary.js +0 -50
- package/libx/_runtime/cds-services/adapter/rest/utils/data.js +0 -117
- package/libx/_runtime/cds-services/adapter/rest/utils/header-checks.js +0 -14
- package/libx/_runtime/cds-services/adapter/rest/utils/key-value-utils.js +0 -30
- package/libx/_runtime/cds-services/adapter/rest/utils/parse-url.js +0 -250
- package/libx/_runtime/cds-services/adapter/rest/utils/result.js +0 -26
- package/libx/_runtime/cds-services/services/utils/handlerUtils.js +0 -200
- package/libx/_runtime/common/aspects/utils.js +0 -152
- package/libx/_runtime/common/toggles/handler.js +0 -21
- package/libx/_runtime/common/utils/extensibilityUtils.js +0 -18
- package/libx/_runtime/extensibility/mps/index.js +0 -5
- package/libx/_runtime/extensibility/mps/service.js +0 -111
- package/libx/_runtime/extensibility/mps/tar.js +0 -42
- package/libx/_runtime/extensibility/mps/utils.js +0 -11
- package/libx/_runtime/extensibility/uiflex/index.js +0 -54
- package/libx/_runtime/extensibility/uiflex/service.js +0 -276
- package/libx/_runtime/messaging/common-utils/naming-conventions.js +0 -20
- package/libx/_runtime/remote/utils/client-types.d.ts +0 -7
- package/libx/gql/GraphQLAdapter.js +0 -33
- package/libx/gql/constants/adapter.js +0 -69
- package/libx/gql/constants/cds.js +0 -18
- package/libx/gql/constants/graphql.js +0 -33
- package/libx/gql/readme.md +0 -1
- package/libx/gql/resolvers/crud/create.js +0 -20
- package/libx/gql/resolvers/crud/delete.js +0 -29
- package/libx/gql/resolvers/crud/index.js +0 -6
- package/libx/gql/resolvers/crud/read.js +0 -30
- package/libx/gql/resolvers/crud/update.js +0 -42
- package/libx/gql/resolvers/crud/utils/index.js +0 -36
- package/libx/gql/resolvers/field.js +0 -5
- package/libx/gql/resolvers/index.js +0 -7
- package/libx/gql/resolvers/mutation.js +0 -23
- package/libx/gql/resolvers/parse/ast/enrich.js +0 -52
- package/libx/gql/resolvers/parse/ast/fragment.js +0 -11
- package/libx/gql/resolvers/parse/ast/fromObject.js +0 -39
- package/libx/gql/resolvers/parse/ast/index.js +0 -3
- package/libx/gql/resolvers/parse/ast/meta.js +0 -4
- package/libx/gql/resolvers/parse/ast/variable.js +0 -7
- package/libx/gql/resolvers/parse/ast2cqn/columns.js +0 -44
- package/libx/gql/resolvers/parse/ast2cqn/entries.js +0 -31
- package/libx/gql/resolvers/parse/ast2cqn/index.js +0 -8
- package/libx/gql/resolvers/parse/ast2cqn/limit.js +0 -6
- package/libx/gql/resolvers/parse/ast2cqn/orderBy.js +0 -24
- package/libx/gql/resolvers/parse/ast2cqn/utils/index.js +0 -3
- package/libx/gql/resolvers/parse/ast2cqn/where.js +0 -70
- package/libx/gql/resolvers/parse/utils/index.js +0 -8
- package/libx/gql/resolvers/query.js +0 -13
- package/libx/gql/resolvers/root.js +0 -34
- package/libx/gql/schema/generate.js +0 -18
- package/libx/gql/schema/index.js +0 -5
- package/libx/gql/schema/mutation.js +0 -76
- package/libx/gql/schema/query.js +0 -108
- package/libx/gql/schema/typeDefMap.js +0 -45
- package/libx/gql/schema/utils/index.js +0 -54
- package/libx/gql/utils/index.js +0 -12
- package/libx/rest/middleware/auth.js +0 -20
- package/libx/rest/middleware/content.js +0 -19
- package/srv/flex.cds +0 -21
- package/srv/flex.js +0 -1
- package/srv/mps.cds +0 -23
- package/srv/mps.js +0 -1
- package/srv/outbox.js +0 -0
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../cds')
|
|
2
|
-
// requesting logger without module on purpose!
|
|
3
|
-
const LOG = cds.log()
|
|
4
|
-
|
|
5
|
-
const createHandler = require('./handlers/create')
|
|
6
|
-
const readHandler = require('./handlers/read')
|
|
7
|
-
const updateHandler = require('./handlers/update')
|
|
8
|
-
const deleteHandler = require('./handlers/delete')
|
|
9
|
-
const operationHandler = require('./handlers/operation')
|
|
10
|
-
|
|
11
|
-
const { contentTypeCheck } = require('./utils/header-checks')
|
|
12
|
-
const parse = require('./utils/parse-url')
|
|
13
|
-
const { base64toBuffer } = require('./utils/binary')
|
|
14
|
-
|
|
15
|
-
const { UNAUTHORIZED, FORBIDDEN, getRequiresAsArray } = require('../../../auth/utils')
|
|
16
|
-
|
|
17
|
-
const PPP = { POST: 1, PUT: 1, PATCH: 1 }
|
|
18
|
-
const GH = { GET: 1, HEAD: 1 }
|
|
19
|
-
|
|
20
|
-
let _i18n
|
|
21
|
-
const i18n = (...args) => {
|
|
22
|
-
if (!_i18n) _i18n = require('../../../common/i18n')
|
|
23
|
-
return _i18n(...args)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const { normalizeError, isClientError } = require('../../../common/error/frontend')
|
|
27
|
-
|
|
28
|
-
const _log = err => {
|
|
29
|
-
const level = isClientError(err) ? 'warn' : 'error'
|
|
30
|
-
if ((level === 'warn' && !LOG._warn) || (level === 'error' && !LOG._error)) return
|
|
31
|
-
|
|
32
|
-
// replace messages in toLog with developer texts (i.e., undefined locale)
|
|
33
|
-
const _message = err.message
|
|
34
|
-
const _details = err.details
|
|
35
|
-
err.message = i18n(err.message || err.code, undefined, err.args) || err.message
|
|
36
|
-
if (err.details) {
|
|
37
|
-
const details = []
|
|
38
|
-
for (const d of err.details) {
|
|
39
|
-
details.push(Object.assign({}, d, { message: i18n(d.message || d.code, undefined, d.args) || d.message }))
|
|
40
|
-
}
|
|
41
|
-
err.details = details
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// log it
|
|
45
|
-
LOG[level](err)
|
|
46
|
-
|
|
47
|
-
// restore
|
|
48
|
-
err.message = _message
|
|
49
|
-
if (_details) err.details = _details
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
class Rest {
|
|
53
|
-
constructor(cdsService) {
|
|
54
|
-
this._cdsService = cdsService
|
|
55
|
-
this._createRouter()
|
|
56
|
-
this._addDispatcher()
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get _express() {
|
|
60
|
-
const express = require('express')
|
|
61
|
-
Object.defineProperty(this, '_express', { value: express })
|
|
62
|
-
return express
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
_createRouter() {
|
|
66
|
-
this.router = this._express.Router()
|
|
67
|
-
this.router.use(this._express.json())
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
_addDispatcher() {
|
|
71
|
-
const srv = this._cdsService
|
|
72
|
-
|
|
73
|
-
const create = createHandler(srv)
|
|
74
|
-
const read = readHandler(srv)
|
|
75
|
-
const update = updateHandler(srv)
|
|
76
|
-
const deleet = deleteHandler(srv)
|
|
77
|
-
const operation = operationHandler(srv)
|
|
78
|
-
|
|
79
|
-
const requires = getRequiresAsArray(srv.definition)
|
|
80
|
-
|
|
81
|
-
/*
|
|
82
|
-
* pre handler stuff
|
|
83
|
-
*/
|
|
84
|
-
this.router.use('/', (req, res, next) => {
|
|
85
|
-
// check @requires as soon as possible (DoS)
|
|
86
|
-
if (req.path !== '/' && requires.length > 0 && !requires.some(r => req.user.is(r))) {
|
|
87
|
-
// > unauthorized or forbidden?
|
|
88
|
-
if (req.user._is_anonymous) {
|
|
89
|
-
if (req.user._challenges) res.set('WWW-Authenticate', req.user._challenges.join(';'))
|
|
90
|
-
// REVISIT: security log in else case?
|
|
91
|
-
throw UNAUTHORIZED
|
|
92
|
-
}
|
|
93
|
-
// REVISIT: security log?
|
|
94
|
-
throw FORBIDDEN
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// service root
|
|
98
|
-
if (req.path === '/' && GH[req.method]) {
|
|
99
|
-
if (req.method === 'HEAD') return res.json({})
|
|
100
|
-
else
|
|
101
|
-
return res.json(
|
|
102
|
-
Object.keys(srv.entities).reduce(
|
|
103
|
-
(acc, cur) => {
|
|
104
|
-
acc.entities.push({ name: cur, url: cur })
|
|
105
|
-
return acc
|
|
106
|
-
},
|
|
107
|
-
{ entities: [] }
|
|
108
|
-
)
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// content-type check, parse url, and base64 to buffer
|
|
113
|
-
try {
|
|
114
|
-
if (PPP[req.method]) contentTypeCheck(req)
|
|
115
|
-
req._parsed = parse[req.method](srv, req)
|
|
116
|
-
base64toBuffer(req.body, req._parsed.segments[0])
|
|
117
|
-
} catch (e) {
|
|
118
|
-
return next(e)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
next()
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
// POST
|
|
125
|
-
this.router.post('/*', (req, res, next) => {
|
|
126
|
-
// CREATE or custom operation?
|
|
127
|
-
if (req._parsed.event === 'CREATE') {
|
|
128
|
-
create(req, res, next)
|
|
129
|
-
} else {
|
|
130
|
-
operation(req, res, next)
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
// HEAD
|
|
135
|
-
this.router.head('/*', (req, res, next) => {
|
|
136
|
-
read(req, res, next)
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
// GET
|
|
140
|
-
this.router.get('/*', (req, res, next) => {
|
|
141
|
-
// READ or custom operation?
|
|
142
|
-
if (req._parsed.event === 'READ') {
|
|
143
|
-
read(req, res, next)
|
|
144
|
-
} else {
|
|
145
|
-
operation(req, res, next)
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
// PUT, PATCH, DELETE
|
|
150
|
-
this.router.put('/*', update)
|
|
151
|
-
this.router.patch('/*', update)
|
|
152
|
-
this.router.delete('/*', deleet)
|
|
153
|
-
|
|
154
|
-
/*
|
|
155
|
-
* error handling (the express way)
|
|
156
|
-
*/
|
|
157
|
-
this.router.use((err, req, res, next) => {
|
|
158
|
-
// invoke srv.on('error', function (err, req) { ... }) here in special situations
|
|
159
|
-
// REVISIT: if for compat reasons, remove once cds^5.1
|
|
160
|
-
if (srv._handlers._error) {
|
|
161
|
-
let ctx = cds.context
|
|
162
|
-
if (!ctx) {
|
|
163
|
-
// > error before req was dispatched
|
|
164
|
-
ctx = new cds.Request({ req, res: req.res, user: req.user || new cds.User.Anonymous() })
|
|
165
|
-
for (const each of srv._handlers._error) each.handler.call(srv, err, ctx)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// log the error (4xx -> warn)
|
|
170
|
-
_log(err)
|
|
171
|
-
|
|
172
|
-
const { error, statusCode } = normalizeError(err, req)
|
|
173
|
-
|
|
174
|
-
if (res.statusCode === 200) {
|
|
175
|
-
// > i.e., not set in custom handler
|
|
176
|
-
res.status(statusCode)
|
|
177
|
-
}
|
|
178
|
-
res.send({ error })
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
module.exports = Rest
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../cds')
|
|
2
|
-
// requesting logger without module on purpose!
|
|
3
|
-
const LOG = cds.log()
|
|
4
|
-
|
|
5
|
-
const restToCqn = require('./rest-to-cqn')
|
|
6
|
-
const { flattenDeepToOneAssociations } = require('../../services/utils/handlerUtils')
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
* Class representing a REST request.
|
|
10
|
-
* @extends Request
|
|
11
|
-
*
|
|
12
|
-
* @param {String} parsed - The parsed url of the incoming request
|
|
13
|
-
* @param {Object} data - A deep copy of the request payload
|
|
14
|
-
* @param {Object} req - express' req
|
|
15
|
-
* @param {Object} res - express' res
|
|
16
|
-
* @param {Object} service - The underlying CAP service
|
|
17
|
-
*/
|
|
18
|
-
class RestRequest extends cds.Request {
|
|
19
|
-
constructor(parsed, data, req, res, service) {
|
|
20
|
-
const { event, target } = parsed
|
|
21
|
-
|
|
22
|
-
// for functions, data is in params (if provided)
|
|
23
|
-
if (parsed.kind === 'function' && parsed.params) data = parsed.params
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
* query
|
|
27
|
-
*/
|
|
28
|
-
const query = restToCqn(parsed, data, req, service)
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
* method, headers
|
|
32
|
-
*/
|
|
33
|
-
const { method, headers } = req
|
|
34
|
-
|
|
35
|
-
/*
|
|
36
|
-
* super
|
|
37
|
-
*/
|
|
38
|
-
const { user } = req
|
|
39
|
-
// REVISIT: _model should not be necessary
|
|
40
|
-
const _model = service.model
|
|
41
|
-
// REVISIT: public API for query options (express style req.query already in use)?
|
|
42
|
-
const _queryOptions = req.query
|
|
43
|
-
super({ event, target, data, query, user, method, headers, req, res, _model, _queryOptions })
|
|
44
|
-
|
|
45
|
-
// REVISIT: validate associations for deep insert
|
|
46
|
-
flattenDeepToOneAssociations(this, this.model)
|
|
47
|
-
|
|
48
|
-
/*
|
|
49
|
-
* req.run
|
|
50
|
-
*/
|
|
51
|
-
Object.defineProperty(this, 'run', {
|
|
52
|
-
configurable: true,
|
|
53
|
-
get:
|
|
54
|
-
() =>
|
|
55
|
-
(...args) => {
|
|
56
|
-
if (!cds._deprecationWarningForRun) {
|
|
57
|
-
LOG._warn && LOG.warn('req.run is deprecated and will be removed.')
|
|
58
|
-
cds._deprecationWarningForRun = true
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return cds.tx(this).run(...args)
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = RestRequest
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../../cds')
|
|
2
|
-
|
|
3
|
-
const RestRequest = require('../RestRequest')
|
|
4
|
-
|
|
5
|
-
const getData = require('../utils/data')
|
|
6
|
-
const { bufferToBase64 } = require('../utils/binary')
|
|
7
|
-
|
|
8
|
-
const _locationHeader = (entity, serviceName, resultObject) => {
|
|
9
|
-
const keyName = Object.keys(entity.keys)[0]
|
|
10
|
-
const entityNameWithoutServicePrefix = entity.name.replace(`${serviceName}.`, '')
|
|
11
|
-
return `../${entityNameWithoutServicePrefix}/${resultObject[keyName]}`
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
* optimistically transforms result from flat to complex based on input
|
|
16
|
-
*/
|
|
17
|
-
const _transformToComplex = (result, data) => {
|
|
18
|
-
for (let i = 0; i < result.length; i++) {
|
|
19
|
-
const d = result[i]
|
|
20
|
-
const cd = data[i]
|
|
21
|
-
|
|
22
|
-
const props = Object.keys(d)
|
|
23
|
-
const keys = Object.keys(cd).filter(k => !props.includes(k))
|
|
24
|
-
|
|
25
|
-
for (const k of keys) {
|
|
26
|
-
const inner = props.filter(p => p.startsWith(`${k}_`)).map(p => p.split(`${k}_`)[1])
|
|
27
|
-
if (inner.length > 0) {
|
|
28
|
-
d[k] = {}
|
|
29
|
-
for (const i of inner) {
|
|
30
|
-
d[k][i] = d[`${k}_${i}`]
|
|
31
|
-
delete d[`${k}_${i}`]
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
module.exports = service => {
|
|
39
|
-
return async (restReq, restRes, next) => {
|
|
40
|
-
const {
|
|
41
|
-
_parsed: parsed,
|
|
42
|
-
_parsed: { target }
|
|
43
|
-
} = restReq
|
|
44
|
-
|
|
45
|
-
const [validationError, data] = getData(parsed, restReq)
|
|
46
|
-
if (validationError) return next(validationError)
|
|
47
|
-
|
|
48
|
-
// create tx and set as cds.context
|
|
49
|
-
// REVISIT: _model should not be necessary
|
|
50
|
-
const tx = service.tx({ user: restReq.user, req: restReq, _model: service.model })
|
|
51
|
-
cds.context = tx
|
|
52
|
-
|
|
53
|
-
let result, err, location
|
|
54
|
-
try {
|
|
55
|
-
const reqs = data.map(d => new RestRequest(parsed, d, restReq, restRes, service))
|
|
56
|
-
result = await Promise.all(reqs.map(req => tx.dispatch(req)))
|
|
57
|
-
|
|
58
|
-
_transformToComplex(result, data)
|
|
59
|
-
bufferToBase64(result, target)
|
|
60
|
-
|
|
61
|
-
// batch?
|
|
62
|
-
if (!Array.isArray(restReq.body)) {
|
|
63
|
-
result = result[0]
|
|
64
|
-
location = _locationHeader(target, service.name, result)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
await tx.commit(result)
|
|
68
|
-
} catch (e) {
|
|
69
|
-
err = e
|
|
70
|
-
// REVISIT: rollback needed if error occured before commit attempted -> how to distinguish?
|
|
71
|
-
await tx.rollback(e).catch(() => {})
|
|
72
|
-
} finally {
|
|
73
|
-
if (err) next(err)
|
|
74
|
-
else {
|
|
75
|
-
// only set status if not yet modified
|
|
76
|
-
if (restRes.statusCode === 200) restRes.status(201)
|
|
77
|
-
if (location) restRes.set('location', location)
|
|
78
|
-
restRes.send(result)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../../cds')
|
|
2
|
-
|
|
3
|
-
const RestRequest = require('../RestRequest')
|
|
4
|
-
|
|
5
|
-
const getData = require('../utils/data')
|
|
6
|
-
|
|
7
|
-
module.exports = service => {
|
|
8
|
-
return async (restReq, restRes, next) => {
|
|
9
|
-
const { _parsed: parsed } = restReq
|
|
10
|
-
|
|
11
|
-
const [validationError, data] = getData(parsed, restReq)
|
|
12
|
-
if (validationError) return next(validationError)
|
|
13
|
-
|
|
14
|
-
// create tx and set as cds.context
|
|
15
|
-
// REVISIT: _model should not be necessary
|
|
16
|
-
const tx = service.tx({ user: restReq.user, req: restReq, _model: service.model })
|
|
17
|
-
cds.context = tx
|
|
18
|
-
|
|
19
|
-
const req = new RestRequest(parsed, data, restReq, restRes, service)
|
|
20
|
-
|
|
21
|
-
let err
|
|
22
|
-
try {
|
|
23
|
-
await tx.dispatch(req)
|
|
24
|
-
|
|
25
|
-
await tx.commit(null)
|
|
26
|
-
} catch (e) {
|
|
27
|
-
err = e
|
|
28
|
-
// REVISIT: rollback needed if error occured before commit attempted -> how to distinguish?
|
|
29
|
-
await tx.rollback(e).catch(() => {})
|
|
30
|
-
} finally {
|
|
31
|
-
if (err) next(err)
|
|
32
|
-
else {
|
|
33
|
-
// only set status if not yet modified
|
|
34
|
-
if (restRes.statusCode === 200) restRes.status(204)
|
|
35
|
-
restRes.send()
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../../cds')
|
|
2
|
-
|
|
3
|
-
const RestRequest = require('../RestRequest')
|
|
4
|
-
|
|
5
|
-
const getData = require('../utils/data')
|
|
6
|
-
const { validateReturnType } = require('../utils/validation-checks')
|
|
7
|
-
const { bufferToBase64 } = require('../utils/binary')
|
|
8
|
-
const { toRestResult } = require('../utils/result')
|
|
9
|
-
|
|
10
|
-
const _convertCustomOperationReturnValue = (returns, result) => {
|
|
11
|
-
if (returns.items) {
|
|
12
|
-
return result
|
|
13
|
-
} else {
|
|
14
|
-
return Array.isArray(result) ? result[0] : result
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = service => {
|
|
19
|
-
return async (restReq, restRes, next) => {
|
|
20
|
-
const {
|
|
21
|
-
_parsed: parsed,
|
|
22
|
-
_parsed: { segments, operation }
|
|
23
|
-
} = restReq
|
|
24
|
-
|
|
25
|
-
const [validationError, data] = getData(parsed, restReq)
|
|
26
|
-
if (validationError) return next(validationError)
|
|
27
|
-
|
|
28
|
-
// create tx and set as cds.context
|
|
29
|
-
// REVISIT: _model should not be necessary
|
|
30
|
-
const tx = service.tx({ user: restReq.user, req: restReq, _model: service.model })
|
|
31
|
-
cds.context = tx
|
|
32
|
-
|
|
33
|
-
const req = new RestRequest(parsed, data, restReq, restRes, service)
|
|
34
|
-
|
|
35
|
-
let result, err, status, body
|
|
36
|
-
try {
|
|
37
|
-
result = await tx.dispatch(req)
|
|
38
|
-
|
|
39
|
-
if (!operation.returns) {
|
|
40
|
-
status = 204
|
|
41
|
-
} else {
|
|
42
|
-
validateReturnType(operation, result)
|
|
43
|
-
bufferToBase64(result, segments[0])
|
|
44
|
-
body = _convertCustomOperationReturnValue(operation.returns, result)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
await tx.commit(result)
|
|
48
|
-
} catch (e) {
|
|
49
|
-
err = e
|
|
50
|
-
// REVISIT: rollback needed if error occured before commit attempted -> how to distinguish?
|
|
51
|
-
await tx.rollback(e).catch(() => {})
|
|
52
|
-
} finally {
|
|
53
|
-
if (err) next(err)
|
|
54
|
-
else {
|
|
55
|
-
// only set status if not yet modified
|
|
56
|
-
const { statusCode } = restRes
|
|
57
|
-
if (statusCode === 200 && status) restRes.status(status)
|
|
58
|
-
if (body === undefined) restRes.status(statusCode === 200 ? 204 : statusCode).end()
|
|
59
|
-
else restRes.send(toRestResult(body))
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../../cds')
|
|
2
|
-
|
|
3
|
-
const RestRequest = require('../RestRequest')
|
|
4
|
-
|
|
5
|
-
const getData = require('../utils/data')
|
|
6
|
-
const { toRestResult } = require('../utils/result')
|
|
7
|
-
const getError = require('../../../../common/error')
|
|
8
|
-
const { bufferToBase64 } = require('../utils/binary')
|
|
9
|
-
|
|
10
|
-
module.exports = service => {
|
|
11
|
-
return async (restReq, restRes, next) => {
|
|
12
|
-
const {
|
|
13
|
-
_parsed: parsed,
|
|
14
|
-
_parsed: { segments }
|
|
15
|
-
} = restReq
|
|
16
|
-
|
|
17
|
-
const [validationError, data] = getData(parsed, restReq)
|
|
18
|
-
if (validationError) return next(validationError)
|
|
19
|
-
|
|
20
|
-
// create tx and set as cds.context
|
|
21
|
-
// REVISIT: _model should not be necessary
|
|
22
|
-
const tx = service.tx({ user: restReq.user, req: restReq, _model: service.model })
|
|
23
|
-
cds.context = tx
|
|
24
|
-
|
|
25
|
-
let result, err
|
|
26
|
-
try {
|
|
27
|
-
const req = new RestRequest(parsed, data, restReq, restRes, service)
|
|
28
|
-
|
|
29
|
-
result = await tx.dispatch(req)
|
|
30
|
-
|
|
31
|
-
if (result == null) throw getError(404, 'NO_MATCHING_RESOURCE')
|
|
32
|
-
|
|
33
|
-
bufferToBase64(result, segments[0])
|
|
34
|
-
|
|
35
|
-
await tx.commit(result)
|
|
36
|
-
} catch (e) {
|
|
37
|
-
err = e
|
|
38
|
-
// REVISIT: rollback needed if error occured before commit attempted -> how to distinguish?
|
|
39
|
-
await tx.rollback(e).catch(() => {})
|
|
40
|
-
} finally {
|
|
41
|
-
if (err) next(err)
|
|
42
|
-
else if (restReq.method === 'HEAD')
|
|
43
|
-
restRes
|
|
44
|
-
.set({
|
|
45
|
-
'content-type': 'application/json; charset=utf-8',
|
|
46
|
-
'content-length': JSON.stringify(result).length
|
|
47
|
-
})
|
|
48
|
-
.end()
|
|
49
|
-
else restRes.send(toRestResult(result))
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../../cds')
|
|
2
|
-
|
|
3
|
-
const RestRequest = require('../RestRequest')
|
|
4
|
-
|
|
5
|
-
const getData = require('../utils/data')
|
|
6
|
-
const getError = require('../../../../common/error')
|
|
7
|
-
const { bufferToBase64 } = require('../utils/binary')
|
|
8
|
-
|
|
9
|
-
const UPSERT_ALLOWED = !(cds.env.runtime && cds.env.runtime.allow_upsert === false)
|
|
10
|
-
|
|
11
|
-
const _getData = (parsed, restReq) => {
|
|
12
|
-
const [validationError, data] = getData(parsed, restReq)
|
|
13
|
-
if (validationError) throw validationError
|
|
14
|
-
if (parsed.event === 'CREATE') return data[0]
|
|
15
|
-
if (Array.isArray(data)) throw getError(400, 'Batch updates are no longer supported.')
|
|
16
|
-
return data
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const _updateThenCreate = async (parsed, restReq, restRes, tx) => {
|
|
20
|
-
let req, result
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
req = new RestRequest(parsed, _getData(parsed, restReq), restReq, restRes, tx)
|
|
24
|
-
result = await tx.dispatch(req)
|
|
25
|
-
} catch (e) {
|
|
26
|
-
if ((e.code === 404 || e.status === 404 || e.statusCode === 404) && UPSERT_ALLOWED) {
|
|
27
|
-
// REVISIT: remove error (and child?) from tx.context? -> would require a unique req.id
|
|
28
|
-
|
|
29
|
-
parsed.event = 'CREATE'
|
|
30
|
-
req = new RestRequest(parsed, _getData(parsed, restReq), restReq, restRes, tx)
|
|
31
|
-
result = await tx.dispatch(req)
|
|
32
|
-
|
|
33
|
-
// REVISIT
|
|
34
|
-
result = Array.isArray(result) ? result[0] : result
|
|
35
|
-
} else {
|
|
36
|
-
throw e
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return result
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const update = service => {
|
|
44
|
-
return async (restReq, restRes, next) => {
|
|
45
|
-
const {
|
|
46
|
-
_parsed: parsed,
|
|
47
|
-
_parsed: { target }
|
|
48
|
-
} = restReq
|
|
49
|
-
|
|
50
|
-
// create tx and set as cds.context
|
|
51
|
-
// REVISIT: _model should not be necessary
|
|
52
|
-
const tx = service.tx({ user: restReq.user, req: restReq, _model: service.model })
|
|
53
|
-
cds.context = tx
|
|
54
|
-
|
|
55
|
-
let result, err, status
|
|
56
|
-
try {
|
|
57
|
-
// try UPDATE and, on 404 error, try CREATE
|
|
58
|
-
result = await _updateThenCreate(parsed, restReq, restRes, tx)
|
|
59
|
-
|
|
60
|
-
// PUT resulting in CREATE shall return 201
|
|
61
|
-
if (restReq.method === 'PUT' && parsed.event === 'CREATE') status = 201
|
|
62
|
-
|
|
63
|
-
bufferToBase64(result, target)
|
|
64
|
-
|
|
65
|
-
await tx.commit(result)
|
|
66
|
-
} catch (e) {
|
|
67
|
-
err = e
|
|
68
|
-
// REVISIT: rollback needed if error occured before commit attempted -> how to distinguish?
|
|
69
|
-
await tx.rollback(e).catch(() => {})
|
|
70
|
-
} finally {
|
|
71
|
-
if (err) next(err)
|
|
72
|
-
else {
|
|
73
|
-
// only set status if not yet modified
|
|
74
|
-
if (restRes.statusCode === 200 && status) restRes.status(status)
|
|
75
|
-
restRes.send(result)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
module.exports = update
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const cds = require('../../../../cds')
|
|
2
|
-
|
|
3
|
-
const { INSERT, SELECT, UPDATE, DELETE } = cds.ql
|
|
4
|
-
|
|
5
|
-
const { createCqlString } = require('./utils')
|
|
6
|
-
const { getColumns } = require('../../../services/utils/columns')
|
|
7
|
-
const { getMaxPageSize, getDefaultPageSize } = require('../../../../common/utils/page')
|
|
8
|
-
|
|
9
|
-
const _readToCQN = ({ isCollection, segments }, target, restReq) => {
|
|
10
|
-
const key = Object.keys(target.keys)[0]
|
|
11
|
-
|
|
12
|
-
const cqn = SELECT.from(
|
|
13
|
-
createCqlString(target, key, segments[1]),
|
|
14
|
-
getColumns(target, {
|
|
15
|
-
onlyNames: true,
|
|
16
|
-
removeIgnore: true
|
|
17
|
-
})
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
if (!isCollection) cqn.SELECT.one = true
|
|
21
|
-
|
|
22
|
-
if (isCollection && (restReq.query.$top || restReq.query.$skip)) {
|
|
23
|
-
const top = restReq.query.$top ? parseInt(restReq.query.$top) : getDefaultPageSize(target)
|
|
24
|
-
cqn.limit(Math.min(top, getMaxPageSize(target)), parseInt(restReq.query.$skip) || 0)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return cqn
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @param {object} parsed
|
|
32
|
-
* @param {object} data
|
|
33
|
-
* @param {object} restReq
|
|
34
|
-
* @returns {object}
|
|
35
|
-
*/
|
|
36
|
-
module.exports = (parsed, data, restReq, service) => {
|
|
37
|
-
const odata2cqn = cds.env.features.rest_new_parser
|
|
38
|
-
|
|
39
|
-
const { event, segments, target } = parsed
|
|
40
|
-
|
|
41
|
-
const key = target && Object.keys(target.keys)[0]
|
|
42
|
-
const value = segments && segments.length > 1 && segments[1]
|
|
43
|
-
|
|
44
|
-
switch (event) {
|
|
45
|
-
case 'CREATE':
|
|
46
|
-
return INSERT.into(target).entries(data)
|
|
47
|
-
case 'READ':
|
|
48
|
-
return odata2cqn ? cds.odata.parse(restReq, { service }) : _readToCQN(parsed, target, restReq)
|
|
49
|
-
case 'UPDATE':
|
|
50
|
-
return UPDATE(createCqlString(target, key, value)).data(data)
|
|
51
|
-
case 'DELETE':
|
|
52
|
-
return DELETE.from(createCqlString(target, key, value))
|
|
53
|
-
default:
|
|
54
|
-
return target ? SELECT.from(createCqlString(target, key, value)) : undefined
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
const DATA_TYPES_NOT_TO_BE_CONVERTED_BY_COMPILER = {
|
|
2
|
-
'cds.Boolean': 1,
|
|
3
|
-
'cds.Integer': 1,
|
|
4
|
-
'cds.Integer16': 1,
|
|
5
|
-
'cds.Integer32': 1,
|
|
6
|
-
'cds.Integer64': 1,
|
|
7
|
-
'cds.Decimal': 1,
|
|
8
|
-
'cds.DecimalFloat': 1,
|
|
9
|
-
'cds.Float': 1,
|
|
10
|
-
'cds.Double': 1
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const _convertKeyForCompiler = (keyValue, type) => {
|
|
14
|
-
if (!DATA_TYPES_NOT_TO_BE_CONVERTED_BY_COMPILER[type]) {
|
|
15
|
-
return `'${keyValue}'`
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return keyValue
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const createCqlString = (target, key, keyValue) => {
|
|
22
|
-
let keyString = ''
|
|
23
|
-
|
|
24
|
-
if (keyValue !== undefined) {
|
|
25
|
-
keyString = `[${key}=${_convertKeyForCompiler(keyValue, target.keys[key]._type)}]`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return `${target.name}${keyString}`
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
createCqlString
|
|
33
|
-
}
|