Compare commits

..

2 Commits

Author SHA1 Message Date
Daniel
98577c1ecc re cap 2020-05-15 09:00:56 +02:00
Daniel
e8cd0e3231 Samples for re:cap 2020-05-15 08:37:40 +02:00
12 changed files with 58 additions and 139 deletions

9
.env
View File

@@ -1 +1,8 @@
cds.features.snapi = y cds.features.snapi = true
cds.odata.version = v4
cds.odata.containment = true
cds.odata.proxies = true
cds.odata.format = structured
cds.cdsc.beta.uniqueconstraints = true
cds.cdsc.beta.aspectCompositions = true
cds.cdsc.severities.unexpected-key = info

View File

@@ -1,24 +0,0 @@
{
"extends": "eslint:recommended",
"env": {
"node": true,
"es6": true,
"jest": true
},
"parserOptions": {
"ecmaVersion": 2017
},
"globals": {
"SELECT": true,
"INSERT": true,
"UPDATE": true,
"DELETE": true,
"CREATE": true,
"DROP": true,
"cds": true
},
"rules": {
"no-console": "off",
"require-atomic-updates": "off"
}
}

30
ext/.gitignore vendored
View File

@@ -1,30 +0,0 @@
# CAP ext
_out
*.db
connection.properties
default-*.json
gen/
node_modules/
package-lock.json
target/
# Web IDE, App Studio
.che/
.gen/
# MTA
*_mta_build_tmp
*.mtar
mta_archives/
# Other
.DS_Store
*.orig
*.log
*.iml
*.flattened-pom.xml
# IDEs
.vscode
.idea

View File

@@ -1,6 +0,0 @@
using { sap.capire.bookshop.Books } from '@capire/bookshop';
extend Books with {
ISBN : String;
discount : Decimal @assert.range:[0,1];
}

View File

@@ -1,19 +0,0 @@
{
"name": "ext",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@capire/bookshop": "../bookshop",
"@sap/cds": "^4",
"express": "^4"
},
"devDependencies": {
"sqlite3": "^4"
},
"scripts": {
"start": "npx cds run"
}
}

View File

@@ -1,40 +0,0 @@
const cds = require ('@sap/cds')
const path = require ('path')
const fs = require ('fs')
const protected = {db:1,messaging:1,auth:1}
const { isfile } = cds.utils
cds.on('served', ()=>{
for (let each of cds.services) {
if (each.name in protected) continue
// search for local srv/<each>.js files and if exist
// activate them in a service extension sandbox
const impl = isfile (path.resolve('srv/'+each.name+'.js'))
if (impl) activate_sandboxed (each,impl)
}
})
function activate_sandboxed (srv,impl) {
console.log (`[cds] - extending ${srv.name} with sandboxed:`, {impl:path.relative(process.cwd(),impl)})
const src = fs.readFileSync (impl)
const sandbox = Object.keys(global).filter(name => name !== 'cds')
const fn = new Function (
'module','cds','global','process', ...sandbox,
src
)
// restricted sandboxed variant of 'module' and 'cds'
const module = {}
const cds = {
service: {
impl: fn=>fn
}
}
fn (module,cds,undefined,undefined, ...sandbox.map((()=>(undefined))))
if (typeof module.exports === 'function') try {
module.exports.call (srv,srv)
} catch (e) {
console.log (e)
}
}
module.exports = cds.server

View File

@@ -1,10 +0,0 @@
module.exports = cds.service.impl(function(){
this.before(['CREATE','UPDATE'],'Books', req => { //> ....
const book = req.data
if (book.stock < 10 && book.discount > 0.5) {
req.error('Hey, da sind so wenig übrig, die wollen wir nicht zu billig verticken')
}
})
})

View File

@@ -1,9 +0,0 @@
console.log ('Böses Zeug', global, process, cds)
// process.exit()
// const fs = require('fs')
// cds.run('Böses Zeugs')
// SELECT.from ('Foo')
module.exports = cds.service.impl(function(){
this.after('READ','Books', each => each.title += ' (served through sandbox)')
})

8
orders/.env Normal file
View File

@@ -0,0 +1,8 @@
cds.features.snapi = true
cds.odata.version = v4
cds.odata.containment = true
cds.odata.proxies = true
cds.odata.format = structured
cds.cdsc.beta.uniqueconstraints = true
cds.cdsc.beta.aspectCompositions = true
cds.cdsc.severities.unexpected-key = info

View File

@@ -0,0 +1,5 @@
using { sap.capire.bookshop.Authors } from '@capire/bookshop';
define view Foo as select from Authors {
ID, name, books[where title like 'Cat%'].currency.code
};

View File

@@ -0,0 +1,27 @@
using { User, cuid, managed } from '@sap/cds/common';
// Looks like inheritance, but isn't
entity Foo @bar : cuid, managed { bar:Car; }
// It's just syntactical sugar for Aspects
entity Boo {}
extend Boo with cuid;
extend Boo with managed;
extend Boo with { bar:Car; }
annotate Boo with @bar;
// There's close to no limits
entity Moo : Foo {}
entity Zoo {}; extend Zoo with Foo;
// This one will apply to all uses above
type Car : String;
annotate Car with @car;
// And these to all uses here and wherever else
extend managed with {
notes : String;
}
// CDS is built with CDS
annotate cds.UUID with @odata.Type: 'Edm.Integer';

10
recap/extending-views.cds Normal file
View File

@@ -0,0 +1,10 @@
using { CatalogService } from '@capire/bookshop';
extend sap.capire.bookshop.Books with {
ISBN : String;
}
/** your docs go here */
extend projection CatalogService.Books with {
ISBN
}