@sap/cds 5.9.8 → 6.0.3
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 +277 -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 +83 -41
- 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 +21 -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 +15 -13
- package/bin/{build → deploy/to-hana}/mtaUtil.js +10 -9
- package/bin/mtx/in-cds.js +19 -7
- package/bin/serve.js +49 -22
- package/bin/utils/log.js +13 -30
- package/bin/version.js +4 -3
- 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 +10 -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 +22 -20
- package/lib/serve/index.js +51 -54
- package/lib/utils/axios.js +8 -12
- package/lib/utils/index.js +13 -4
- 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 +127 -41
- package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +9 -5
- package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +93 -73
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +25 -45
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +10 -14
- 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 +2 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +21 -26
- 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 +97 -92
- 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 +82 -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 +13 -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 +2 -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 +4 -16
- package/libx/_runtime/fiori/generic/index.js +31 -0
- package/libx/_runtime/fiori/generic/new.js +5 -21
- package/libx/_runtime/fiori/generic/patch.js +10 -15
- package/libx/_runtime/fiori/generic/prepare.js +13 -22
- package/libx/_runtime/fiori/generic/read.js +148 -163
- package/libx/_runtime/fiori/generic/readOverDraft.js +10 -4
- package/libx/_runtime/fiori/utils/handler.js +10 -22
- 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 +30 -22
- 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 +3 -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 +90 -48
- 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 +263 -156
- 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
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const cds = require ('../index'), $ = cds.error.message
|
|
2
|
+
|
|
3
|
+
module.exports = (req) => (field) => {
|
|
4
|
+
|
|
5
|
+
const def = field.name ? field : field.split('.').reduce (
|
|
6
|
+
(target,e) => target.elements[e] || cds.error `There's no element '${e}' in ${target}`,
|
|
7
|
+
req.target
|
|
8
|
+
)
|
|
9
|
+
return {
|
|
10
|
+
|
|
11
|
+
isSpecified (_msg) {
|
|
12
|
+
return this.validate ('MANDATORY_VALUE', this.data != undefined,
|
|
13
|
+
_msg, ()=> $`Value has to be filled in.`
|
|
14
|
+
)
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
isInRange (range, _msg) {
|
|
18
|
+
let data = this.data; if (data == undefined) return true
|
|
19
|
+
return this.validate ('VALUE_IN_RANGE',
|
|
20
|
+
!range ? data in def.enum : data >= range[0] && data <= range[1],
|
|
21
|
+
_msg, ()=> $`Value has to be in range ${range || Object.keys(def.enum)}.`
|
|
22
|
+
)
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
matches (pattern, _msg) {
|
|
26
|
+
let data = this.data; if (data == undefined) return true
|
|
27
|
+
let re = typeof pattern === 'string' ? RegExp(pattern) : pattern
|
|
28
|
+
return this.validate ('VALUE_MATCHING_PATTERN', re.test(data),
|
|
29
|
+
_msg, ()=> $`Value has to match ${re}`
|
|
30
|
+
)
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
meets (code, constraint, _msg) {
|
|
34
|
+
if (typeof code === 'function') [code,constraint,_msg] = ['CONSTRAINT',code,constraint]
|
|
35
|
+
let data = this.data; if (data == undefined) return true
|
|
36
|
+
let ok = constraint(data)
|
|
37
|
+
let validate = ok => this.validate(code,ok,_msg, ()=> `Value failed to meet ${constraint}`)
|
|
38
|
+
return typeof ok.then === 'function' ? ok.then(validate) : validate(ok)
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
async exists (_msg) {
|
|
42
|
+
let data = req.target.data(req.data), ref = def.refIn(data); if (ref == undefined) return true
|
|
43
|
+
return this.validate ('TARGET_EXISTS', await req.tx.exists(ref).forUpdate(),
|
|
44
|
+
_msg, ()=> $`Record ${def.target} with ${data[def.name]} doesn't exist.`
|
|
45
|
+
)
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
validate: (code, ok, _msg, message) => ok || req.error ({
|
|
49
|
+
code: 'FAILED_'+code, target: def.name,
|
|
50
|
+
message: _msg || message()
|
|
51
|
+
}),
|
|
52
|
+
|
|
53
|
+
get data(){ return def.dataIn(req.data) },
|
|
54
|
+
get to(){ return {__proto__:this,
|
|
55
|
+
get match(){ return this.matches },
|
|
56
|
+
get exist(){ return this.exists },
|
|
57
|
+
get meet(){ return this.meets },
|
|
58
|
+
get be(){ return {__proto__:this,
|
|
59
|
+
get specified(){ return this.isSpecified },
|
|
60
|
+
get inRange(){ return this.isInRange },
|
|
61
|
+
get in(){ return {__proto__:this,
|
|
62
|
+
get range(){ return this.isInRange },
|
|
63
|
+
}}
|
|
64
|
+
}}
|
|
65
|
+
}},
|
|
66
|
+
get not(){ return {__proto__:this, validate:(c,ok,m,$) => this.validate(
|
|
67
|
+
c, !ok, m, ()=> $().replace(/must|has to/,'must not')
|
|
68
|
+
)}},
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
}
|
package/lib/req/cds-context.js
CHANGED
|
@@ -1,82 +1,50 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { AsyncLocalStorage } = require ('async_hooks')
|
|
2
2
|
const { EventEmitter } = require('events')
|
|
3
|
+
const EventContext = require('./context')
|
|
3
4
|
|
|
5
|
+
module.exports = new class extends AsyncLocalStorage {
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
exports.for = (cds,v) => {
|
|
7
|
+
run(v,fn,...args) { return super.run (this._context4(v),fn,...args) }
|
|
8
|
+
enterWith(v) { return super.enterWith (this._context4(v)) }
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const cr = current(); if (!cr) return
|
|
17
|
-
const ctx = cr[_context]
|
|
18
|
-
if (ctx) res[_context] = ctx
|
|
19
|
-
}}).enable()
|
|
20
|
-
|
|
21
|
-
Reflect.defineProperty (cds,'context',{ enumerable:1,
|
|
22
|
-
set(v) {
|
|
23
|
-
const cr = current(); if (!cr) return
|
|
24
|
-
const ctx = (
|
|
25
|
-
v instanceof EventContext || typeof v !== 'object' ? v :
|
|
26
|
-
v.context || EventContext.for (v.req ? {_:v} : v)
|
|
27
|
-
)
|
|
28
|
-
cr[_context] = ctx
|
|
29
|
-
},
|
|
30
|
-
get() {
|
|
31
|
-
const cr = current(); if (!cr) return undefined
|
|
32
|
-
return cr[_context]
|
|
33
|
-
},
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
} else {
|
|
10
|
+
_context4(v) {
|
|
11
|
+
if (v instanceof EventContext || typeof v !== 'object') return v
|
|
12
|
+
if (v.context) return v.context
|
|
13
|
+
if (v.req) v = v.res ? {http:v} : {http:{ ...v, res: v.req.res }}
|
|
14
|
+
return EventContext.for(v)
|
|
15
|
+
}
|
|
37
16
|
|
|
38
|
-
|
|
17
|
+
/** @returns {EventContext} */
|
|
18
|
+
_for (cds,v) {
|
|
19
|
+
Reflect.defineProperty (cds,'context', { enumerable:1, ... cds.env.features.cls ? {
|
|
20
|
+
set:(v) => this.enterWith(v),
|
|
21
|
+
get:()=> this.getStore(),
|
|
22
|
+
} : {
|
|
39
23
|
get:()=> undefined,
|
|
40
24
|
set:()=> {},
|
|
41
|
-
})
|
|
42
|
-
|
|
25
|
+
}})
|
|
26
|
+
return cds.context = v // IMPORTANT: we need to set it initially, to get it all wired up correctly
|
|
43
27
|
}
|
|
44
28
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const em = new EventEmitter()
|
|
57
|
-
const fx = () => {
|
|
58
|
-
// create a new transaction for each run of the background job
|
|
59
|
-
// which inherits from the current event context by default
|
|
60
|
-
const o2 = { ...o }; delete o2.timestamp //> spawned txes set their own timestamps
|
|
61
|
-
const tx = cds.context = cds.tx(o2)
|
|
62
|
-
const commit = async (res) => {
|
|
63
|
-
await tx.commit()
|
|
64
|
-
for (const handler of em.listeners('succeeded')) await handler(res)
|
|
65
|
-
for (const handler of em.listeners('done')) await handler()
|
|
29
|
+
spawn (o,fn, /** @type {import('../index')} cds */ cds=this) {
|
|
30
|
+
if (typeof o === 'function') [fn,o] = [o,fn] //> for compatibility
|
|
31
|
+
if (o instanceof EventContext) throw cds.error `The passed options must not be an instance of cds.EventContext.`
|
|
32
|
+
const fx = ()=>{
|
|
33
|
+
const tx = cds.tx({...o}) // create a new detached transaction for each run of the background job
|
|
34
|
+
return cds._context.run (tx, ()=> Promise.resolve(fn(tx))
|
|
35
|
+
.then (tx.commit, e => tx.rollback(_error(e, cds)))
|
|
36
|
+
.then (res => Promise.all(em.listeners('succeeded').map(each => each(res))))
|
|
37
|
+
.catch (err => Promise.all(em.listeners('failed').map(each => each(err))))
|
|
38
|
+
.finally (() => Promise.all(em.listeners('done').map(each => each())))
|
|
39
|
+
)
|
|
66
40
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
41
|
+
const em = new EventEmitter; em.timer = (
|
|
42
|
+
(o && o.after) ? setTimeout(fx, o.after) :
|
|
43
|
+
(o && o.every) ? setInterval(fx, o.every) :
|
|
44
|
+
setImmediate(fx)
|
|
45
|
+
)
|
|
46
|
+
return em
|
|
73
47
|
}
|
|
74
|
-
|
|
75
|
-
const timer = (
|
|
76
|
-
(o && o.after) ? setTimeout(fx, o.after) :
|
|
77
|
-
(o && o.every) ? setInterval(fx, o.every) :
|
|
78
|
-
setImmediate(fx)
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
return Object.assign (em, { timer })
|
|
82
48
|
}
|
|
49
|
+
|
|
50
|
+
const _error = (err, cds) => { cds.log().error(`ERROR occured in background job:`, err); return err }
|
package/lib/req/context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const cds = require ('../index'), { features } = cds.env, { uuid } = cds.utils
|
|
2
|
-
const async_events = { succeeded:1, failed:1, done:1 }
|
|
2
|
+
const async_events = { succeeded:1, failed:1, done:1, commit:1 }
|
|
3
3
|
const req_locale = require('./locale')
|
|
4
4
|
const { EventEmitter } = require('events')
|
|
5
5
|
|
|
@@ -84,15 +84,13 @@ class EventContext {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
set user(u) {
|
|
87
|
-
const user =
|
|
88
|
-
for (let p
|
|
89
|
-
|
|
90
|
-
else Object.defineProperty (user, p, { get: () => this[p] })
|
|
91
|
-
}
|
|
87
|
+
const user = u instanceof cds.User ? u : new cds.User(u)
|
|
88
|
+
if (u && typeof u === 'object') for (let p in _TENANT_LOCALE) if (p in u && u[p]) this[p] = u[p]
|
|
89
|
+
super.user = new Proxy (user,{ get:(t,p) => p in _TENANT_LOCALE ? this[p] : t[p] })
|
|
92
90
|
}
|
|
93
91
|
get user() {
|
|
94
|
-
|
|
95
|
-
return this.user
|
|
92
|
+
this.user = this._propagated.user || _anonymous
|
|
93
|
+
return this.user // IMPORTANT: first set this.user then return it separately to ensure we return the compat-wrapped objects
|
|
96
94
|
}
|
|
97
95
|
|
|
98
96
|
set locale(l) {
|
|
@@ -114,41 +112,56 @@ class EventContext {
|
|
|
114
112
|
if (h) super.headers = h
|
|
115
113
|
}
|
|
116
114
|
get headers() {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const headers={}, outer = this._propagated.headers
|
|
115
|
+
let headers = this._.req?.headers
|
|
116
|
+
if (!headers) { headers={}
|
|
117
|
+
const outer = this._propagated.headers
|
|
121
118
|
if (outer) for (let each of EventContext.propagateHeaders) {
|
|
122
119
|
if (each in outer) headers[each] = outer[each]
|
|
123
120
|
}
|
|
124
|
-
return super.headers = headers
|
|
125
121
|
}
|
|
122
|
+
return super.headers = headers
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
set http(rr) {
|
|
126
|
+
if (!this._.req) Object.assign(this._, rr)
|
|
127
|
+
super.http = rr
|
|
128
|
+
}
|
|
129
|
+
get http() {
|
|
130
|
+
return this._propagated.http || this._.req && this._.res && { req:this._.req, res:this._.res }
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
134
|
+
/**
|
|
135
|
+
* This sets an EventContext's / Message's / Request's tx object, i.e.
|
|
136
|
+
* the service which this request is passed on for execution.
|
|
137
|
+
* In response to that, the instance will be wired up to and inherit
|
|
138
|
+
* context properties from tx.context.
|
|
139
|
+
*/
|
|
140
|
+
set tx (tx) {
|
|
141
|
+
Object.defineProperty (this,'tx',{value:tx}) //> allowed only once!
|
|
131
142
|
const ctx = tx.context
|
|
132
143
|
if (ctx && ctx !== this) {
|
|
133
144
|
if (!this.hasOwnProperty('context')) this.context = ctx // eslint-disable-line no-prototype-builtins
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (features.assert_integrity !== false) {
|
|
145
|
+
|
|
146
|
+
if (features.assert_integrity && features.assert_integrity_type == 'RT') {
|
|
137
147
|
const reqs = ctx._children || ctx._set('_children', {})
|
|
138
148
|
const all = reqs[tx.name] || (reqs[tx.name] = [])
|
|
139
149
|
all.push(this)
|
|
140
|
-
}
|
|
150
|
+
}
|
|
141
151
|
}
|
|
142
152
|
}
|
|
153
|
+
get _tx() { return this.tx } // REVISIT: for compatibility to bade usages of req._tx
|
|
143
154
|
|
|
144
155
|
|
|
145
156
|
/** REVISIT: remove -> @deprecated */
|
|
146
|
-
set _model(m){
|
|
157
|
+
set _model(m){ Object.defineProperty(this,'_model',{value:m}) }
|
|
147
158
|
get _model() {
|
|
148
|
-
return
|
|
159
|
+
return this._model = this.tx && this.tx.model || this._propagated._model
|
|
149
160
|
}
|
|
150
161
|
}
|
|
151
162
|
|
|
163
|
+
const _TENANT_LOCALE = { tenant:1, locale:2 }
|
|
164
|
+
const _anonymous = new cds.User.default
|
|
152
165
|
|
|
153
166
|
EventContext.prototype._set('_propagated', Object.seal({}))
|
|
154
167
|
EventContext.propagateHeaders = [ 'x-correlation-id' ]
|
package/lib/req/request.js
CHANGED
|
@@ -9,6 +9,8 @@ class Request extends require('./event') {
|
|
|
9
9
|
|
|
10
10
|
toString() { return `${this.event} ${this.path}` }
|
|
11
11
|
|
|
12
|
+
get assert(){ return super.assert = require('./assert')(this) }
|
|
13
|
+
|
|
12
14
|
set method(m) { if (m) super.method = m }
|
|
13
15
|
get method() {
|
|
14
16
|
return this._set ('method', Crud2Http[this.event] || this.event)
|
|
@@ -33,27 +35,23 @@ class Request extends require('./event') {
|
|
|
33
35
|
|
|
34
36
|
set path(p) { if (p) super.path = p.startsWith('/') ? p.slice(1) : p }
|
|
35
37
|
get path() {
|
|
36
|
-
const
|
|
37
|
-
if (this.query) { // IMPORTANT: Bulk queries don't have a _.query
|
|
38
|
-
const q = this.query
|
|
38
|
+
const q = this.query; if (this.query) { // IMPORTANT: Bulk queries don't have a _.query
|
|
39
39
|
if (q.SELECT) return this._set ('path', _path4 (q.SELECT,'from'))
|
|
40
40
|
if (q.INSERT) return this._set ('path', _path4 (q.INSERT,'into'))
|
|
41
41
|
if (q.UPDATE) return this._set ('path', _path4 (q.UPDATE,'entity'))
|
|
42
42
|
if (q.DELETE) return this._set ('path', _path4 (q.DELETE,'from'))
|
|
43
43
|
}
|
|
44
|
+
const {_} = this
|
|
44
45
|
if (_.target) return this._set ('path', _.target.name)
|
|
45
46
|
if (_.entity) return this._set ('path', _.entity.name || _.entity)
|
|
46
|
-
|
|
47
|
+
return this._set ('path', undefined)
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
set data(d) { if (d) super.data = d }
|
|
50
51
|
get data() {
|
|
51
|
-
const q = this.query
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
if (I) return this._set ('data', I.rows || I.values || I.entries && (I.entries.length > 1 ? I.entries : I.entries[0]) ||{})
|
|
55
|
-
const U = q.UPDATE
|
|
56
|
-
if (U) return this._set ('data', U.data ||{})
|
|
52
|
+
const q = this.query; if (!q) return this._set ('data', undefined)
|
|
53
|
+
const I = q.INSERT; if (I) return this._set ('data', I.rows || I.values || I.entries && (I.entries.length > 1 ? I.entries : I.entries[0]) ||{})
|
|
54
|
+
const U = q.UPDATE; if (U) return this._set ('data', U.data ||{})
|
|
57
55
|
return this._set ('data', {})
|
|
58
56
|
}
|
|
59
57
|
|
|
@@ -63,8 +61,9 @@ class Request extends require('./event') {
|
|
|
63
61
|
warn (...args) { return this._messages.add (3, ...args) }
|
|
64
62
|
error (...args) { return this._errors.add (4, ...args) }
|
|
65
63
|
reject (...args) {
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
let e = this.error(...args)
|
|
65
|
+
if (!e.stack) Error.captureStackTrace (e = Object.assign(new Error,e), this.reject)
|
|
66
|
+
throw e
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
// Lazily create message collectors for .errors and .messages
|
|
@@ -131,10 +130,5 @@ const _path4 = (x,p) => {
|
|
|
131
130
|
// REVISIT: Legacy stuff...
|
|
132
131
|
//
|
|
133
132
|
Object.defineProperties (Request.prototype, {
|
|
134
|
-
|
|
135
|
-
diff: { value: function (...args) {
|
|
136
|
-
const {_service:d} = this.target
|
|
137
|
-
return d ? global.cds.services[d.name]._calculateDiff(this, ...args) : Promise.resolve([])
|
|
138
|
-
}},
|
|
139
|
-
|
|
133
|
+
diff: { get: ()=> require('../../libx/_runtime/cds-services/services/utils/differ').reqDiff }
|
|
140
134
|
})
|
package/lib/req/response.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const cds = require ('../index')
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Messages Collector, used for `req.errors` and `req.messages`
|
|
3
5
|
*/
|
|
@@ -20,9 +22,11 @@ class Responses extends Array {
|
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
class Errors extends Responses {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
push(e) {
|
|
26
|
+
'stack' in e || Error.captureStackTrace (e = Object.assign(new Error,e), cds.Request.prototype.error)
|
|
27
|
+
return super.push(e)
|
|
25
28
|
}
|
|
29
|
+
throwable() { return this.length > 1 ? Object.assign(new Error('MULTIPLE_ERRORS'), { details: this }) : this[0] }
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
module.exports = { Responses, Errors }
|
package/lib/req/user.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
class User {
|
|
2
2
|
|
|
3
3
|
constructor (_) {
|
|
4
|
-
if (
|
|
4
|
+
if (_ === undefined) {
|
|
5
|
+
if (new.target === Privileged) return
|
|
6
|
+
if (new.target === Anonymous) return
|
|
7
|
+
else return new User.default
|
|
8
|
+
}
|
|
5
9
|
if (typeof _ === 'string') { this.id = _; return }
|
|
6
|
-
for (let each in _) super[each] = _[each] // overrides getters
|
|
7
|
-
if (Array.isArray(
|
|
10
|
+
for (let each in _) super[each === '_roles' ? 'roles' : each] = _[each] // overrides getters
|
|
11
|
+
if (Array.isArray(this.roles)) this.roles = this.roles.reduce ((p,n)=>{p[n]=1; return p},{})
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
get attr() { return super.attr = {} }
|
|
15
|
+
get roles(){ return super.roles = {} }
|
|
16
|
+
get _roles(){ return this.roles } // compatibility
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
'identified-user': !!this.id,
|
|
14
|
-
'authenticated-user': !!this.id && this.authLevel !== 'weak' // REVISIT: _.authLevel
|
|
15
|
-
}}
|
|
16
|
-
|
|
17
|
-
is (role) { return role === 'any' || !!this._roles[role] }
|
|
18
|
+
is (role) { return role === 'any' || role === 'identified-user' || role === 'authenticated-user' && this.authLevel !== 'weak' || !!this.roles[role] }
|
|
18
19
|
valueOf() { return this.id }
|
|
19
20
|
|
|
20
21
|
}
|
|
@@ -22,22 +23,29 @@ class User {
|
|
|
22
23
|
/**
|
|
23
24
|
* Subclass representing non-identified unauthenticated users.
|
|
24
25
|
*/
|
|
25
|
-
class Anonymous extends User {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
class Anonymous extends User { is(role) { return role === 'any' }}
|
|
27
|
+
Object.defineProperties (Anonymous.prototype, {
|
|
28
|
+
id: {value:'anonymous',writable:true},
|
|
29
|
+
roles: {value:{}},
|
|
30
|
+
attr: {value:{}},
|
|
31
|
+
_is_anonymous: {value:true},
|
|
32
|
+
})
|
|
31
33
|
|
|
32
34
|
/**
|
|
33
35
|
* Subclass for executing code with superuser privileges.
|
|
34
36
|
*/
|
|
35
|
-
class Privileged extends User {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
class Privileged extends User { is(){ return true }}
|
|
38
|
+
Object.defineProperties (Privileged.prototype, {
|
|
39
|
+
id: {value:'privileged',writable:true},
|
|
40
|
+
roles: {value:{},writable:true},
|
|
41
|
+
attr: {value:{},writable:true},
|
|
42
|
+
_is_privileged: {value:true},
|
|
43
|
+
})
|
|
44
|
+
|
|
41
45
|
|
|
42
46
|
// exports -----------------
|
|
43
|
-
module.exports = exports = Object.assign (User, {
|
|
47
|
+
module.exports = exports = Object.assign (User, {
|
|
48
|
+
Anonymous, anonymous : Object.seal (new Anonymous),
|
|
49
|
+
Privileged, privileged : Object.seal (new Privileged),
|
|
50
|
+
default: Anonymous,
|
|
51
|
+
})
|
package/lib/serve/Service-api.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
const cds = require('..'), { Event, Request } = cds
|
|
2
2
|
const add_methods_to = require ('./Service-methods')
|
|
3
|
-
const { unfold_csn: cds_localized } = cds.compile._localized
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
class Service extends require('./Service-handlers') {
|
|
7
6
|
|
|
8
|
-
constructor (name, model, o
|
|
9
|
-
|
|
7
|
+
constructor (name, model, o) {
|
|
8
|
+
if (is_object(name)) {
|
|
9
|
+
[ model, o ] = [ name, model ]
|
|
10
|
+
let srv = cds.linked(model).services[0] || cds.error.expected `${{arg0:name}} to be a CSN with a service definition`
|
|
11
|
+
name = srv.name
|
|
12
|
+
}
|
|
13
|
+
super (name || new.target.name) .options = o || (o={})
|
|
10
14
|
if (o.kind) this.kind = o.kind // shortcut
|
|
11
15
|
if (model) this.model = model
|
|
12
16
|
}
|
|
@@ -27,7 +31,6 @@ class Service extends require('./Service-handlers') {
|
|
|
27
31
|
* Messaging API to emit asynchronous event messages, i.e. instances of `cds.Event`.
|
|
28
32
|
*/
|
|
29
33
|
emit (event, data, headers) {
|
|
30
|
-
const res = this._compat_sync (event, data, headers); if (res) return res
|
|
31
34
|
const eve = event instanceof Event ? event : new Event (
|
|
32
35
|
is_object(event) ? event : { event, data, headers }
|
|
33
36
|
)
|
|
@@ -43,11 +46,11 @@ class Service extends require('./Service-handlers') {
|
|
|
43
46
|
)
|
|
44
47
|
return this.dispatch (req)
|
|
45
48
|
}
|
|
46
|
-
get (
|
|
47
|
-
put (
|
|
48
|
-
post (
|
|
49
|
-
patch (
|
|
50
|
-
delete (
|
|
49
|
+
get (...args) { return is_rest(args[0]) ? this.send('GET', ...args) : this.read (...args) }
|
|
50
|
+
put (...args) { return is_rest(args[0]) ? this.send('PUT', ...args) : this.update (...args) }
|
|
51
|
+
post (...args) { return is_rest(args[0]) ? this.send('POST', ...args) : this.create (...args) }
|
|
52
|
+
patch (...args) { return is_rest(args[0]) ? this.send('PATCH', ...args) : this.update (...args) }
|
|
53
|
+
delete (...args) { return is_rest(args[0]) ? this.send('DELETE',...args) : DELETE.from (...args).bind(this) }
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
56
|
* Querying API to send synchronous requests...
|
|
@@ -94,8 +97,11 @@ class Service extends require('./Service-handlers') {
|
|
|
94
97
|
/**
|
|
95
98
|
* Subclasses may override this to free private resources
|
|
96
99
|
*/
|
|
97
|
-
disconnect (tenant) {
|
|
98
|
-
if (this === cds.db)
|
|
100
|
+
disconnect (tenant) {
|
|
101
|
+
if (this === cds.db) {
|
|
102
|
+
if (tenant && cds.db.dbcs) cds.db.dbcs.delete[tenant]
|
|
103
|
+
else if (!tenant) cds.db = undefined //> REVISIT: should go into DatabaseService
|
|
104
|
+
}
|
|
99
105
|
delete cds.services[this.name]
|
|
100
106
|
}
|
|
101
107
|
|
|
@@ -105,7 +111,6 @@ const { dispatch, handle } = require('./Service-dispatch')
|
|
|
105
111
|
Service.prototype.dispatch = dispatch
|
|
106
112
|
Service.prototype.handle = handle
|
|
107
113
|
Service.prototype.transaction = Service.prototype.tx = require('./Transaction')
|
|
108
|
-
Service.prototype._compat_sync = require('./Service-compat')
|
|
109
114
|
Service.prototype._implicit_next = cds.env.features.implicit_next
|
|
110
115
|
Service.prototype._is_service_instance = Service._is_service_class = true //> for factory
|
|
111
116
|
module.exports = Service
|
|
@@ -13,22 +13,18 @@ exports.dispatch = async function dispatch (req) { //NOSONAR
|
|
|
13
13
|
|
|
14
14
|
// Ensure we are in a proper transaction
|
|
15
15
|
if (!this.context) {
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
} else { // start a new root tx for subsequent continuation
|
|
20
|
-
return this.tx(tx => (cds.context=tx).dispatch(req))
|
|
21
|
-
}
|
|
16
|
+
const gc = cds.context
|
|
17
|
+
if (gc && gc.tx && !gc.tx._done) return this.tx(gc).dispatch(req) // with nested tx
|
|
18
|
+
else return this.tx(tx => tx.dispatch(req)) // as root tx
|
|
22
19
|
}
|
|
23
|
-
// `this` is a tx from now on...
|
|
24
|
-
if (!req._tx) req._tx = this
|
|
20
|
+
if (!req.tx) req.tx = this // `this` is a tx from now on...
|
|
25
21
|
|
|
26
22
|
// Inform potential listeners // REVISIT: -> this should move into protocol adapters
|
|
27
23
|
if (_is_root(req)) req._.req.emit ('dispatch',req)
|
|
28
24
|
|
|
29
25
|
// Handle batches of queries
|
|
30
26
|
if (_is_array(req.query))
|
|
31
|
-
return Promise.all (req.query.map (q => this.dispatch ({query:q,__proto__:req})))
|
|
27
|
+
return Promise.all (req.query.map (q => this.dispatch ({query:q,__proto__:req,context:req})))
|
|
32
28
|
|
|
33
29
|
// Ensure target and fqns
|
|
34
30
|
if (!req.target) _ensure_target (this,req)
|
|
@@ -5,7 +5,8 @@ const LOG = cds.log('cds-app-service-methods')
|
|
|
5
5
|
module.exports = (srv) => {
|
|
6
6
|
if (!( //> we only support that for app services
|
|
7
7
|
srv instanceof cds.ApplicationService ||
|
|
8
|
-
srv instanceof cds.RemoteService
|
|
8
|
+
srv instanceof cds.RemoteService ||
|
|
9
|
+
srv._add_stub_methods
|
|
9
10
|
)) return
|
|
10
11
|
for (const each of srv.operations) {
|
|
11
12
|
add_handler_for (srv, each)
|
|
@@ -73,12 +74,12 @@ const add_handler_for = (srv, def) => {
|
|
|
73
74
|
if (req.data[k]) {
|
|
74
75
|
LOG._warn && LOG.warn(`
|
|
75
76
|
${target.name} has defined ${k} as key and action parameter.
|
|
76
|
-
Key will be used in req.data.
|
|
77
|
+
Key will be used in req.data.
|
|
77
78
|
`)
|
|
78
79
|
}
|
|
79
80
|
req.data[k] = named ? req.params[0][k] : req.params[pos++]
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
return this.send (req)
|