Skip to content

Commit 6758137

Browse files
committed
Side effects
1 parent e832ad8 commit 6758137

31 files changed

+964
-298
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1515
- Respect annotation `@Common.WebSocketChannel` for channel specification on event and service level
1616
- Document OData extension for UI5 Fiori Elements event-driven side effects
1717

18+
### Added
19+
20+
- Add sample Fiori Elements application leveraging event-driven side effects
21+
1822
## Version 1.9.1 - 2025-11-05
1923

2024
### Fixed

README.md

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ using [@sap/cds](https://www.npmjs.com/package/@sap/cds) (CDS Node.js).
4545
- [Ignore Definitions](#ignore-definitions)
4646
- [WebSocket Format](#websocket-format)
4747
- [SAP Push Channel Protocol (PCP)](#sap-push-channel-protocol-pcp)
48+
- [Fiori Side Effects](#fiori-side-effects)
4849
- [Cloud Events](#cloud-events)
4950
- [Custom Format](#custom-format)
5051
- [Generic Format](#generic-format)
@@ -59,6 +60,7 @@ using [@sap/cds](https://www.npmjs.com/package/@sap/cds) (CDS Node.js).
5960
- [Bound Operations](#bound-operations)
6061
- [CRUD Operations](#crud-operations)
6162
- [Examples](#examples)
63+
- [Fiori (UI5)](#fiori-ui5)
6264
- [Todo (UI5)](#todo-ui5)
6365
- [Chat (HTML)](#chat-html)
6466
- [Unit-Tests](#unit-tests)
@@ -1196,7 +1198,20 @@ To configure the PCP message format, the following annotations are available:
11961198
##### Fiori Side Effects
11971199
11981200
PCP format can be used to emit Fiori side effects via WebSocket events.
1199-
To configure Fiori side effects in PCP format enabled service, the following annotations are available:
1201+
1202+
First OData V4 service metadata is extended for side effects to automatically connect to the corresponding websocket endpoint and channel:
1203+
1204+
```cds
1205+
@Common : {
1206+
WebSocketBaseURL : '/ws/fiori',
1207+
WebSocketChannel #sideEffects: 'sideeffects'
1208+
}
1209+
service FioriService {
1210+
...
1211+
}
1212+
```
1213+
1214+
Fiori side effects are configured in PCP format enabled service via the following annotations:
12001215
12011216
- **Event level**:
12021217
- `@websocket.pcp.sideEffect, @ws.pcp.sideEffect: Boolean`: Expose Fiori side effects in the PCP message
@@ -1206,57 +1221,63 @@ Example:
12061221
12071222
```cds
12081223
@ws.pcp.sideEffect
1209-
@ws.pcp.channel: 'amc\://notification/notify'
1224+
@ws.pcp.channel: 'sideeffects'
12101225
event sideEffect {
12111226
sideEffectSource: String;
12121227
}
12131228
```
12141229
1215-
Side effects often are restricted to user-owned client connections only. Therefore, the annotation can be added to prevent broadcasting to all clients.
1230+
Side effects are often restricted to user-owned client connections only. Therefore, the annotation `@ws.user` can be added to prevent broadcasting to all clients.
12161231
In addition, PCP Channel can be omitted, if the common annotation `@Common.WebSocketChannel` is defined on the service level.
12171232
12181233
Example:
12191234
12201235
```cds
1221-
@ws.user
1222-
@ws.pcp.sideEffect
1223-
event sideEffect {
1236+
@Common: {
1237+
WebSocketBaseURL: '/ws/fiori',
1238+
WebSocketChannel: 'sideeffects',
1239+
}
1240+
service FioriService {
1241+
@ws.user
1242+
@ws.pcp.sideEffect
1243+
event sideEffect {
12241244
sideEffectSource: String;
1245+
}
1246+
}
1247+
```
1248+
1249+
To consume side effects in Fiori Elements, an CDS entity can be annotated with side effects as follows:
1250+
1251+
Example:
1252+
1253+
```cds
1254+
@Common.SideEffects #sideEffect: {
1255+
SourceEvents : ['sideEffect'],
1256+
TargetProperties: ['name']
12251257
}
1258+
entity Header { ... }
12261259
```
12271260
1228-
Emitting the event `sideEffect` via CDS emit, as follows:
1261+
The event `sideEffect` is emitted on server side via CDS `emit`, as follows:
12291262
12301263
```js
12311264
await srv.emit("sideEffect", {
12321265
sideEffectSource: "/Header(ID='e0582b6a-6d93-46d9-bd28-98723a285d40')",
12331266
});
12341267
```
12351268
1236-
It results in the following PCP message sent via websocket protocol:
1269+
This results in the following PCP message sent via websocket protocol to Fiori Elements:
12371270
12381271
```
12391272
pcp-action:MESSAGE
1240-
pcp-channel:amc:\:notification/notify
1273+
pcp-channel:sideeffects
12411274
sideEffectSource:/Header(ID='e0582b6a-6d93-46d9-bd28-98723a285d40')
12421275
sideEffectEventName:sideEffect
12431276
serverAction:RaiseSideEffect
12441277
12451278
12461279
```
12471280
1248-
OData V4 metadata can be extended for side effects to automatically connect the websocket endpoint:
1249-
1250-
```cds
1251-
@Common : {
1252-
WebSocketBaseURL : 'ws/odata-api',
1253-
WebSocketChannel #sideEffects: 'sideeffects'
1254-
}
1255-
service ODataService {
1256-
...
1257-
}
1258-
```
1259-
12601281
Details can be found for UI5 Fiori Elements [Event-Driven Side Effects](https://ui5.sap.com/#/topic/27c9c3bad6eb4d99bc18a661fdb5e246).
12611282
Fiori Elements V4 applications listening on channel will process the side effects, and update the UI accordingly.
12621283
@@ -1845,9 +1866,23 @@ To also include the triggering socket within the broadcast, this can be controll
18451866
18461867
### Examples
18471868
1869+
#### Fiori (UI5)
1870+
1871+
The example UI5 `fiori` application using WebSockets can be found at `test/_env/app/fiori`.
1872+
1873+
Example application can be started by:
1874+
1875+
- Basic Auth
1876+
- Starting backend: `npm start`
1877+
- Open in browser: http://localhost:4004/flp.html#Books-display
1878+
- XSUAA Auth:
1879+
- Starting approuter: `npm run start:approuter`
1880+
- Starting backend: `npm run start:uaa`
1881+
- Open in the browser: http://localhost:5001/flp.html#Books-display
1882+
18481883
#### Todo (UI5)
18491884
1850-
The example UI5 `todo` application using Socket.IO can be found at `test/_env/app/todo`.
1885+
The example UI5 `todo` application using WebSockets can be found at `test/_env/app/todo`.
18511886
18521887
Example application can be started by:
18531888
@@ -1861,7 +1896,7 @@ Example application can be started by:
18611896
18621897
#### Chat (HTML)
18631898
1864-
An example `chat` application using Socket.IO can be found at `test/_env/app/chat`.
1899+
An example `chat` application using WebSockets can be found at `test/_env/app/chat`.
18651900
18661901
Example application can be started by:
18671902

0 commit comments

Comments
 (0)