diff --git a/bookshop/db/init.js b/bookshop/db/init.js index 77a50c0f..9fc04e34 100644 --- a/bookshop/db/init.js +++ b/bookshop/db/init.js @@ -1,4 +1,4 @@ -const cds = require('@sap/cds') +import cds from '@sap/cds' /** * In order to keep basic bookshop sample as simple as possible, we don't add @@ -8,7 +8,7 @@ const cds = require('@sap/cds') // NOTE: We use cds.on('served') to delay the UPSERTs after the db init // to run after all INSERTs from .csv files happened. -module.exports = cds.on('served', ()=> +export default cds.on('served', ()=> UPSERT.into ('sap.common.Currencies') .columns ( [ 'code', 'symbol', 'name' ] ) .rows ( diff --git a/bookshop/package.json b/bookshop/package.json index 7aff6651..2fdb544c 100644 --- a/bookshop/package.json +++ b/bookshop/package.json @@ -2,6 +2,7 @@ "name": "@capire/bookshop", "version": "1.0.0", "description": "A simple self-contained bookshop service.", + "type": "module", "files": [ "app", "srv", diff --git a/bookshop/srv/admin-service.js b/bookshop/srv/admin-service.js index f3e910f4..4508c751 100644 --- a/bookshop/srv/admin-service.js +++ b/bookshop/srv/admin-service.js @@ -1,6 +1,6 @@ -const cds = require('@sap/cds') +import cds from '@sap/cds' -module.exports = class AdminService extends cds.ApplicationService { init(){ +export class AdminService extends cds.ApplicationService { init(){ this.before (['NEW','CREATE'],'Authors', genid) this.before (['NEW','CREATE'],'Books', genid) return super.init() diff --git a/bookshop/srv/cat-service.js b/bookshop/srv/cat-service.js index 40896f4b..a5e9f09b 100644 --- a/bookshop/srv/cat-service.js +++ b/bookshop/srv/cat-service.js @@ -1,6 +1,6 @@ -const cds = require('@sap/cds') +import cds from '@sap/cds' -class CatalogService extends cds.ApplicationService { init() { +export class CatalogService extends cds.ApplicationService { init() { const { Books } = cds.entities('sap.capire.bookshop') const { ListOfBooks } = this.entities @@ -34,5 +34,3 @@ class CatalogService extends cds.ApplicationService { init() { // Delegate requests to the underlying generic service return super.init() }} - -module.exports = CatalogService diff --git a/bookshop/srv/user-service.js b/bookshop/srv/user-service.js index 2ecb68d9..446dbf23 100644 --- a/bookshop/srv/user-service.js +++ b/bookshop/srv/user-service.js @@ -1,5 +1,5 @@ -const cds = require('@sap/cds') -module.exports = class UserService extends cds.Service { init(){ +import cds from '@sap/cds' +export class UserService extends cds.Service { init(){ this.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant })) this.on('login', (req) => { if (req.user._is_anonymous) diff --git a/bookstore/package.json b/bookstore/package.json index 7802fcef..bc905129 100644 --- a/bookstore/package.json +++ b/bookstore/package.json @@ -1,6 +1,7 @@ { "name": "@capire/bookstore", "version": "1.0.0", + "type": "module", "dependencies": { "@capire/bookshop": "*", "@capire/reviews": "*", diff --git a/bookstore/server.js b/bookstore/server.js index 4b68f508..535d66bd 100644 --- a/bookstore/server.js +++ b/bookstore/server.js @@ -1,7 +1,8 @@ -const cds = require ('@sap/cds') +import mashup from './srv/mashup.js' +import cds from '@sap/cds' // Add mashup logic -cds.once('served', require('./srv/mashup')) +cds.once('served', mashup) // Add routes to UIs from imported packages cds.once('bootstrap',(app)=>{ @@ -10,6 +11,3 @@ cds.once('bootstrap',(app)=>{ app.serve ('/orders') .from('@capire/orders','app/orders') app.serve ('/data') .from('@capire/data-viewer','app/viewer') }) - -// Add Swagger UI -require('./srv/swagger-ui') diff --git a/bookstore/srv/mashup.js b/bookstore/srv/mashup.js index c92840a9..a4a19650 100644 --- a/bookstore/srv/mashup.js +++ b/bookstore/srv/mashup.js @@ -1,10 +1,11 @@ +import cds from '@sap/cds' + //////////////////////////////////////////////////////////////////////////// // // Mashing up bookshop services with required services... // -module.exports = async()=>{ // called by server.js +export default async()=>{ // called by server.js - const cds = require('@sap/cds') const CatalogService = await cds.connect.to ('CatalogService') const ReviewsService = await cds.connect.to ('ReviewsService') const OrdersService = await cds.connect.to ('OrdersService') diff --git a/bookstore/srv/swagger-ui.js b/bookstore/srv/swagger-ui.js deleted file mode 100644 index 22fe3a18..00000000 --- a/bookstore/srv/swagger-ui.js +++ /dev/null @@ -1,10 +0,0 @@ - -// ----------------------------------------------------------------------- -// Adding Swagger UI - see https://cap.cloud.sap/docs/advanced/openapi -const cds = require ('@sap/cds') -try { - const cds_swagger = require ('cds-swagger-ui-express') - cds.once ('bootstrap', app => app.use (cds_swagger()) ) -} catch (err) { - if (err.code !== 'MODULE_NOT_FOUND') throw err -} diff --git a/hello/package.json b/hello/package.json index fb33e171..1a52055b 100644 --- a/hello/package.json +++ b/hello/package.json @@ -1,6 +1,7 @@ { "name": "@capire/hello-world", "version": "1.0.0", + "type": "module", "scripts": { "test": "npx jest --silent", "start": "cds-serve srv/world.cds", diff --git a/hello/srv/world.js b/hello/srv/world.js index c5cd2495..da58d3cb 100644 --- a/hello/srv/world.js +++ b/hello/srv/world.js @@ -1,7 +1,6 @@ -module.exports = class say { - hello(req) { - let {to} = req.data - if (to === 'me') to = require('os').userInfo().username +import cds from '@sap/cds' +export class say extends cds.ApplicationService { + hello (to = 'World') { return `Hello ${to}!` } } diff --git a/hello/srv/world.ts b/hello/srv/world.ts index e812c41e..0aaeb2f1 100644 --- a/hello/srv/world.ts +++ b/hello/srv/world.ts @@ -1,7 +1,6 @@ -import { Request } from "@sap/cds" - -module.exports = class say { - hello(req: Request) { - return `Hello ${req.data.to} from a TypeScript file!` - } +import cds from '@sap/cds' +export class say extends cds.ApplicationService { + hello (to : String = 'World') { + return `Hello ${to} from TypeScript!` + } }