Skip to content

Commit 10a1c0e

Browse files
committed
less clutter
1 parent 0197a60 commit 10a1c0e

File tree

3 files changed

+44
-62
lines changed

3 files changed

+44
-62
lines changed

guides/providing-services.md

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -772,55 +772,48 @@ Here's an overview table:
772772
- Pessimistic locking is not supported by SQLite. H2 supports exclusive locks only.
773773
:::
774774

775-
## Input Validation
776775

777-
CAP runtimes provide generic input validation for incoming requests out of the box, based on the data types and constraints defined in CDS models. You can add custom input validation by...
776+
## Custom Logic
778777

779-
- [Declarative Constraints](./services/constraints) with the following annotations:
780-
- [`@assert`](./services/constraints#assert), incl. derivates:
781-
- [`@assert.format`](./services/constraints#assert-format)
782-
- [`@assert.range`](./services/constraints#assert-range)
783-
- [`@assert.target`](./services/constraints#assert-target)
784-
- [`@mandatory`](./services/constraints#mandatory)
785-
- [`@readonly`](./services/constraints#readonly)
786-
- [Programmatic Validations](#custom-logic) in custom event handlers
778+
As most standard tasks and use cases are covered by [generic service providers](#generic-providers), the need to add service implementation code is greatly reduced and minified, and hence the quantity of individual boilerplate coding.
787779

788-
> [!tip]
789-
> Prefer declarative constraints over programmatic validations wherever possible, as they require no implementation coding and are automatically served by CAP runtimes in optimized ways.
780+
The remaining cases that need custom handlers, reduce to real custom logic, specific to your domain and application, such as:
790781

791-
## [Constraints](services/constraints)
782+
- Domain-specific programmatic [Validations](#input-validation)
783+
- Augmenting result sets, for example to add computed fields for frontends
784+
- Programmatic [Authorization Enforcements](/guides/security/authorization#enforcement)
785+
- Triggering follow-up actions, for example calling other services or emitting outbound events in response to inbound events
786+
- And more... In general, all the things not (yet) covered by generic handlers
792787

793-
Declarative constraints allow you to express conditions using CXL expressions that are validated automatically whenever data is written, greatly reducing the need for extensive custom code for input validation.
794788

795-
::: tip Read the guide
796-
Find additional information about constraints in this guide:
797-
[→ **_Constraints_**](services/constraints)
798-
:::
799789

800-
## [Status-Transition Flows](services/status-flows)
790+
### Declarative Custom Logic
801791

802-
Status-transition flows ensure transitions are explicitly modeled, validated, and executed in a controlled and reliable way, thereby eliminating the need for extensive custom coding.
792+
CAP supports various declarative techniques to express custom logic without coding, in particular for input validation and status-transition flows.
803793

804-
::: tip Read the guide
805-
Find additional information about modeling status-transition flows in this guide:<br>
806-
[&rarr; **_Status-Transition Flows_**](services/status-flows)
807-
:::
794+
#### Status Transition Flows
808795

809-
## Custom Logic
796+
- [Status-Transition Flows](./services/status-flows.md) ensure transitions are explicitly modeled, validated, and executed in a controlled and reliable way, thereby eliminating the need for extensive custom coding.
810797

811798

799+
#### Input Validation
812800

813-
As most standard tasks and use cases are covered by [generic service providers](#generic-providers), the need to add service implementation code is greatly reduced and minified, and hence the quantity of individual boilerplate coding.
801+
- [Declarative Constraints](./services/constraints) allow to annotate your models and have the respective checks still be executed and enforced by generic runtimes, with the following annotations:
814802

815-
The remaining cases that need custom handlers, reduce to real custom logic, specific to your domain and application, such as:
803+
- [`@assert`](./services/constraints#assert), incl. derivates:
804+
- [`@assert.format`](./services/constraints#assert-format)
805+
- [`@assert.range`](./services/constraints#assert-range)
806+
- [`@assert.target`](./services/constraints#assert-target)
807+
- [`@mandatory`](./services/constraints#mandatory)
808+
- [`@readonly`](./services/constraints#readonly)
809+
810+
811+
> [!tip]
812+
> Prefer declarative constraints over programmatic validations wherever possible, as they require no implementation coding and are automatically served by CAP runtimes in optimized ways.
816813
817-
- Domain-specific programmatic [Validations](#input-validation)
818-
- Augmenting result sets, for example to add computed fields for frontends
819-
- Programmatic [Authorization Enforcements](/guides/security/authorization#enforcement)
820-
- Triggering follow-up actions, for example calling other services or emitting outbound events in response to inbound events
821-
- And more... In general, all the things not (yet) covered by generic handlers
822814

823815

816+
### Custom Service Providers
824817

825818
**In Node.js**, the easiest way to add custom implementations for services is through equally named _.js_ files placed next to a service definition's _.cds_ file:
826819

guides/services/constraints.md

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ annotate TravelService.Travels with {
243243

244244

245245

246-
### `@assert .format`
246+
### `@assert.format`
247247

248248
Allows you to specify a regular expression string (in ECMA 262 format in CAP Node.js and java.util.regex.Pattern format in CAP Java) that all string input must match.
249249

@@ -254,7 +254,7 @@ entity Foo {
254254
```
255255

256256

257-
### `@assert .range`
257+
### `@assert.range`
258258

259259
Allows you to specify `[ min, max ]` ranges for elements with ordinal types &mdash; that is, numeric or date/time types. For `enum` elements, `true` can be specified to restrict all input to the defined enum values.
260260

@@ -287,32 +287,9 @@ Support for open intervals and infinity is available for CAP Node.js since `@sap
287287

288288

289289

290-
### `@assert .target`
290+
### `@assert.target`
291291

292-
Annotate a [managed to-one association](../../cds/cdl#managed-associations) of a CDS model entity definition with the
293-
`@assert.target` annotation to check whether the target entity referenced by the association (the reference's target)
294-
exists. In other words, use this annotation to check whether a non-null foreign key input in a table has a corresponding
295-
primary key in the associated/referenced target table.
296-
297-
You can check whether multiple targets exist in the same transaction. For example, in the `Books` entity, you could
298-
annotate one or more managed to-one associations with the `@assert.target` annotation. However, it is assumed that
299-
dependent values were inserted before the current transaction. For example, in a deep create scenario, when creating a
300-
book, checking whether an associated author exists that was created as part of the same deep create transaction isn't
301-
supported, in this case, you will get an error.
302-
303-
The `@assert.target` check constraint is meant to **validate user input** and not to ensure referential integrity.
304-
Therefore only `CREATE`, and `UPDATE` events are supported (`DELETE` events are not supported). To ensure that every
305-
non-null foreign key in a table has a corresponding primary key in the associated/referenced target table
306-
(ensure referential integrity), the [`@assert.integrity`](../databases#database-constraints) constraint must be used instead.
307-
308-
If the reference's target doesn't exist, an HTTP response
309-
(error message) is provided to HTTP client applications and logged to stdout in debug mode. The HTTP response body's
310-
content adheres to the standard OData specification for an error
311-
[response body](https://docs.oasis-open.org/odata/odata-json-format/v4.01/cs01/odata-json-format-v4.01-cs01.html#sec_ErrorResponse).
312-
313-
#### Example
314-
315-
Add `@assert.target` annotation to the service definition as previously mentioned:
292+
Annotate a [managed to-one association](../../cds/cdl#managed-associations) with `@assert.target` to check whether the target entity referenced by the association (the reference's target) exists for a given input.
316293

317294
```cds
318295
entity Books {
@@ -328,7 +305,19 @@ entity Authors {
328305
}
329306
```
330307

331-
**HTTP Request***assume that an author with the ID `"796e274a-c3de-4584-9de2-3ffd7d42d646"` doesn't exist in the database*
308+
You can check whether multiple targets exist in the same transaction. For example, in the `Books` entity, you could
309+
annotate one or more managed to-one associations with the `@assert.target` annotation. However, it is assumed that
310+
dependent values were inserted before the current transaction. For example, in a deep create scenario, when creating a book, checking whether an associated author exists that was created as part of the same deep create transaction isn't supported, in this case, you will get an error.
311+
312+
The `@assert.target` check constraint is meant to **validate user input** and not to ensure referential integrity.
313+
Therefore only `CREATE`, and `UPDATE` events are supported (`DELETE` events are not supported). To ensure that every
314+
non-null foreign key in a table has a corresponding primary key in the associated/referenced target table
315+
(ensure referential integrity), the [`@assert.integrity`](../databases#database-constraints) constraint must be used instead.
316+
317+
If the reference's target doesn't exist, an HTTP response
318+
(error message) is provided to HTTP client applications and logged to stdout in debug mode. The HTTP response body's
319+
content adheres to the standard OData specification for an error
320+
[response body](https://docs.oasis-open.org/odata/odata-json-format/v4.01/cs01/odata-json-format-v4.01-cs01.html#sec_ErrorResponse).
332321

333322
```http
334323
POST Books HTTP/1.1

menu.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
### [Core Concepts](guides/providing-services#introduction)
2626
### [Service Definitions](guides/providing-services#service-definitions)
27-
### [Served out-of-the-box](guides/providing-services#generic-providers)
28-
### [Constraints](guides/services/constraints)
27+
### [Served Out-of-the-Box](guides/providing-services#generic-providers)
2928
### [Status Flows](guides/services/status-flows)
29+
### [Constraints](guides/services/constraints)
3030
### [Custom Logic](guides/providing-services#custom-logic)
3131
### [Actions & Functions](guides/providing-services#actions-functions)
3232
### [Status-Transition Flows](guides/providing-services#status-transition-flows)

0 commit comments

Comments
 (0)