From 5a23ba0f7626ecbfb5a2752b9a3e7691c7682a81 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 1 Apr 2021 16:42:55 +0200 Subject: [PATCH 1/5] Prepare cds5 --- test/hierarchical-data.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/hierarchical-data.test.js b/test/hierarchical-data.test.js index e411eff0..b374a320 100644 --- a/test/hierarchical-data.test.js +++ b/test/hierarchical-data.test.js @@ -1,11 +1,10 @@ const {expect} = require('../test') const cds = require('@sap/cds/lib') -// monkey patching older releases: -if (!cds.compile.cdl) cds.compile.cdl = cds.parse const { parse:cdr } = cds.ql -const model = cds.compile.cdl (` +// should become cds.compile(...) when cds5 is released +const model = cds.compile.to.csn (` entity Categories { key ID : Integer; name : String; From 450577d5a714787133aee12d92d9ff209dabce24 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Tue, 6 Apr 2021 16:09:12 +0200 Subject: [PATCH 2/5] Refer to fiori app instead of bookshop --- reviews/readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reviews/readme.md b/reviews/readme.md index 29f8eff0..2fe87b4e 100644 --- a/reviews/readme.md +++ b/reviews/readme.md @@ -2,10 +2,10 @@ ## Run all-in-one -Open a terminal window and run the bookshop in it: +Open a terminal window and run the `fiori` app in it: ```sh -npm run bookshop +npm run fiori ``` @@ -17,8 +17,8 @@ Open two terminal windows. In the first one start the reviews service stand-alon npm run reviews-service ``` -In the second one start the bookshop: +In the second one start the `fiori` app: ```sh -npm run bookshop +npm run fiori ``` From 33cd70065ae3aac2e913b1e44a90ca48659b3d7a Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Tue, 6 Apr 2021 16:23:25 +0200 Subject: [PATCH 3/5] Use cds.test --- test/index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/index.js b/test/index.js index c44d3400..5a4fdd26 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,2 @@ - -const test = require('@sap/cds/lib/utils/tests').in(__dirname,'..') -module.exports = Object.assign(test,{run:test}) - -// REVISIT: With upcoming release of @sap/cds this should become: -// module.exports = require('@sap/cds/tests').in(__dirname,'..') +const cds = require('@sap/cds') +module.exports = cds.test.in(__dirname,'..') From 0c4658a3efa767f7a42bcc304063530e797822ee Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 10 Apr 2021 13:04:33 +0200 Subject: [PATCH 4/5] Fixed and adjusted to cds5 --- bookshop/package.json | 2 +- bookshop/srv/cat-service.js | 12 +++++------- test/messaging.test.js | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/bookshop/package.json b/bookshop/package.json index 25a9f529..e7125251 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -4,7 +4,7 @@ "description": "A simple self-contained bookshop service.", "dependencies": { "@capire/common": "*", - "@sap/cds": ">=4", + "@sap/cds": "^5.0.4", "express": "^4.17.1", "passport": "0.4.1" }, diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index 4676dcd5..a27aa397 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -5,10 +5,10 @@ class CatalogService extends cds.ApplicationService { init(){ // Reduce stock of ordered books if available stock suffices this.on ('submitOrder', async req => { - const {book,amount} = req.data, tx = cds.tx(req) - let {stock} = await tx.read('stock').from(Books,book) + const {book,amount} = req.data + let {stock} = await SELECT `stock` .from (Books,book) if (stock >= amount) { - await tx.update (Books,book).with ({ stock: stock -= amount }) + await UPDATE (Books,book) .with (`stock -=`, amount) await this.emit ('OrderedBook', { book, amount, buyer:req.user.id }) return { stock } } @@ -16,10 +16,8 @@ class CatalogService extends cds.ApplicationService { init(){ }) // Add some discount for overstocked books - this.after ('READ','Books', each => { - if (each.stock > 111) { - each.title += ` -- 11% discount!` - } + this.after ('READ','ListOfBooks', each => { + if (each.stock > 111) each.title += ` -- 11% discount!` }) return super.init() diff --git a/test/messaging.test.js b/test/messaging.test.js index 42d20d38..3e2176b1 100644 --- a/test/messaging.test.js +++ b/test/messaging.test.js @@ -20,11 +20,11 @@ describe('Messaging', ()=>{ let N=0, received=[], M=0 it ('should add messaging event handlers', ()=>{ - srv.on('reviewed', (msg,next)=> { received.push(msg); return next() }) + srv.on('reviewed', (msg)=> received.push(msg)) }) it ('should add more messaging event handlers', ()=>{ - srv.on('reviewed', (_,next)=> { ++M; return next() }) + srv.on('reviewed', ()=> ++M) }) it ('should add review', async ()=>{ From 5f160c0927dad7a2cbe0cfe0a4741b6aecd571a0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 10 Apr 2021 13:04:48 +0200 Subject: [PATCH 5/5] Added debug conf --- .vscode/launch.json | 37 ++++++++++++++++++++----------------- .vscode/settings.json | 11 ++++++++++- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ad51dcef..40b41090 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,28 +4,31 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - { - "name": "Attach by Process ID", - "processId": "${command:PickProcess}", - "request": "attach", - "skipFiles": [ - "/**" - ], - "type": "pwa-node" - }, { "name": "bookshop", - "command": "cds watch bookshop", - "request": "launch", + "command": "npx cds watch bookshop", "type": "node-terminal", - "skipFiles": ["/**"] + "request": "launch", + "skipFiles": [ + "/**", + "**/node_modules/**", + "**/cds/lib/lazy.js", + "**/cds/lib/req/cls.js", + "**/odata-v4/okra/**" + ] }, { - "name": "Fiori app", - "command": "cds watch fiori", - "request": "launch", + "name": "Fiori App", + "command": "npx cds watch fiori", "type": "node-terminal", - "skipFiles": ["/**"] + "request": "launch", + "skipFiles": [ + "/**", + "**/node_modules/**", + "**/cds/lib/lazy.js", + "**/cds/lib/req/cls.js", + "**/odata-v4/okra/**" + ] } ], "inputs": [ @@ -33,7 +36,7 @@ "type": "pickString", "id": "sample", "description": "Which sample do you want to start?", - "options": ["bookshop", "fiori", "reviews", "reviews/test/bookshop"], + "options": [ "bookshop", "fiori", "reviews", "reviews" ], "default": "bookshop" } ] diff --git a/.vscode/settings.json b/.vscode/settings.json index 545b837e..7431ebe8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,14 @@ "**/.gitignore": true, "**/.vscode": true, "LICENSES/**": true - } + }, + "debug.javascript.terminalOptions": { + "skipFiles": [ + "/**", + "**/node_modules/**", + "**/cds/lib/lazy.js", + "**/cds/lib/req/cls.js", + "**/odata-v4/okra/**" + ] + }, }