Compare commits
51 Commits
audit-log-
...
sandbox_vm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f1af693c9 | ||
|
|
d2ab511d6d | ||
|
|
6c27228d62 | ||
|
|
44880c7745 | ||
|
|
9c2a7598f2 | ||
|
|
9617e576f0 | ||
|
|
c3c9dae80d | ||
|
|
2b6d4c625e | ||
|
|
7d46db42ec | ||
|
|
df57a9d8d0 | ||
|
|
2d92b851f1 | ||
|
|
e157fc8a92 | ||
|
|
3b69a80975 | ||
|
|
b80ba7445d | ||
|
|
b733643f2a | ||
|
|
bf317bc2c9 | ||
|
|
bbebff4066 | ||
|
|
eb75394044 | ||
|
|
b8f65b687f | ||
|
|
c49c9691bd | ||
|
|
7e4bc0985e | ||
|
|
912271338d | ||
|
|
bbf1194a09 | ||
|
|
529c431518 | ||
|
|
3f85676edd | ||
|
|
959c07cee3 | ||
|
|
8cc09fde38 | ||
|
|
bb55c432c9 | ||
|
|
5fc86d45ad | ||
|
|
e86d0dc3a2 | ||
|
|
a661fb2d45 | ||
|
|
bfe0c831d6 | ||
|
|
cad615a662 | ||
|
|
7101c58920 | ||
|
|
07dc1e88b3 | ||
|
|
6f8d74dc9a | ||
|
|
ec57c5ea48 | ||
|
|
c040a47279 | ||
|
|
30bfd70c49 | ||
|
|
6fb9581cf1 | ||
|
|
e87d6cdfc5 | ||
|
|
29ea2bc2da | ||
|
|
12574271ac | ||
|
|
17b5cc1ad2 | ||
|
|
26ca7f54ad | ||
|
|
573e78253d | ||
|
|
a7511ed677 | ||
|
|
f1289b436b | ||
|
|
984ea2133b | ||
|
|
179d301acb | ||
|
|
bbf20b1ca3 |
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: /
|
||||||
|
versioning-strategy: increase-if-necessary
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
@@ -16,7 +16,8 @@ app.use('/-/:tarball', (req,res,next) => {
|
|||||||
console.debug ('GET', req.params)
|
console.debug ('GET', req.params)
|
||||||
try {
|
try {
|
||||||
const { tarball } = req.params
|
const { tarball } = req.params
|
||||||
const [, pkg ] = /^\w+-(\w+)/.exec(tarball)
|
const pkgFull = tarball.substring(0, tarball.lastIndexOf('-'))
|
||||||
|
const [, pkg ] = /^\w+-(.+)/.exec(pkgFull)
|
||||||
fs.lstat(tarball,(err => {
|
fs.lstat(tarball,(err => {
|
||||||
if (err) console.debug (`npm pack ../${pkg}`)
|
if (err) console.debug (`npm pack ../${pkg}`)
|
||||||
if (err) exec(`npm pack ../${pkg}`,{cwd},next)
|
if (err) exec(`npm pack ../${pkg}`,{cwd},next)
|
||||||
@@ -31,7 +32,7 @@ app.use('/-/:tarball', (req,res,next) => {
|
|||||||
app.use('/-', express.static(__dirname))
|
app.use('/-', express.static(__dirname))
|
||||||
|
|
||||||
app.get('/*', (req,res)=>{
|
app.get('/*', (req,res)=>{
|
||||||
const urlRegex = /^\/(@\w+)\/(\w+)/
|
const urlRegex = /^\/(@[\w-]+)\/(.+)/
|
||||||
const url = decodeURIComponent(req.url)
|
const url = decodeURIComponent(req.url)
|
||||||
console.debug ('GET',url)
|
console.debug ('GET',url)
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ const $ = sel => document.querySelector(sel)
|
|||||||
const GET = (url) => axios.get('/browse'+url)
|
const GET = (url) => axios.get('/browse'+url)
|
||||||
const POST = (cmd,data) => axios.post('/browse'+cmd,data)
|
const POST = (cmd,data) => axios.post('/browse'+cmd,data)
|
||||||
|
|
||||||
const books = new Vue ({
|
const books = Vue.createApp ({
|
||||||
|
|
||||||
el:'#app',
|
data() {
|
||||||
|
return {
|
||||||
data: {
|
|
||||||
list: [],
|
list: [],
|
||||||
book: undefined,
|
book: undefined,
|
||||||
order: { quantity:1, succeeded:'', failed:'' }
|
order: { quantity:1, succeeded:'', failed:'' },
|
||||||
|
user: {}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
@@ -37,12 +38,24 @@ const books = new Vue ({
|
|||||||
book.stock = res.data.stock
|
book.stock = res.data.stock
|
||||||
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
|
books.order = { quantity, succeeded: `Successfully ordered ${quantity} item(s).` }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
books.order = { quantity, failed: e.response.data.error.message }
|
books.order = { quantity, failed: e.response.data.error ? e.response.data.error.message : e.response.data }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async fetchUserInfo() {
|
||||||
|
try {
|
||||||
|
const { data } = await axios.get('/user/me')
|
||||||
|
books.user = data
|
||||||
|
} catch (err) { books.user = { id: err.message } }
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
}).mount("#app")
|
||||||
|
|
||||||
// initially fill list of books
|
// initially fill list of books
|
||||||
books.fetch()
|
books.fetch()
|
||||||
|
|
||||||
|
books.fetchUserInfo()
|
||||||
|
document.addEventListener('keydown', (event) => {
|
||||||
|
// hide user info on request
|
||||||
|
if (event.key === 'u') books.user = undefined
|
||||||
|
})
|
||||||
|
|||||||
@@ -5,19 +5,26 @@
|
|||||||
<title> Capire Books </title>
|
<title> Capire Books </title>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/primitive-ui/dist/css/main.css">
|
<link rel="stylesheet" href="https://unpkg.com/primitive-ui/dist/css/main.css">
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
|
||||||
<style>
|
<style>
|
||||||
.hovering tr:hover td { color:cyan; background: #123; cursor: pointer; }
|
.hovering tr:hover td { color:cyan; background: #123; cursor: pointer; }
|
||||||
.rating-stars { color:teal }
|
.rating-stars { color:teal }
|
||||||
.succeeded { color:teal }
|
.succeeded { color:teal }
|
||||||
.failed { color:red }
|
.failed { color:red }
|
||||||
|
.user {text-align: end; color: grey;}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="small-container", style="margin-top: 70px;">
|
<body class="small-container", style="margin-top: 70px;">
|
||||||
<div id='app'>
|
<div id='app'>
|
||||||
|
|
||||||
<h1> {{ document.title }} </h1>
|
<div v-if="user" class="user">
|
||||||
|
<div>User: {{ user.id || 'anonymous' }}</div>
|
||||||
|
<div>Locale: {{ user.locale }}</div>
|
||||||
|
<div v-if="user.tenant">Tenant: {{ user.tenant }}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1> Capire Books </h1>
|
||||||
|
|
||||||
<input type="text" placeholder="Search..." @input="search">
|
<input type="text" placeholder="Search..." @input="search">
|
||||||
|
|
||||||
|
|||||||
2
bookshop/db/handlers/sandbox.cds
Normal file
2
bookshop/db/handlers/sandbox.cds
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
using from '..\..\schema';
|
||||||
|
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
using { Currency, managed, sap } from '@sap/cds/common';
|
using {
|
||||||
|
Currency,
|
||||||
|
managed,
|
||||||
|
sap,
|
||||||
|
extensible
|
||||||
|
} from '@sap/cds/common';
|
||||||
|
|
||||||
namespace sap.capire.bookshop;
|
namespace sap.capire.bookshop;
|
||||||
|
|
||||||
entity Books : managed {
|
@Extensibility.Any.Enabled : true
|
||||||
|
entity Books : managed, extensible {
|
||||||
key ID : Integer;
|
key ID : Integer;
|
||||||
title : localized String(111);
|
title : localized String(111);
|
||||||
descr : localized String(1111);
|
descr : localized String(1111);
|
||||||
@@ -11,21 +18,39 @@ entity Books : managed {
|
|||||||
price : Decimal;
|
price : Decimal;
|
||||||
currency : Currency;
|
currency : Currency;
|
||||||
image : LargeBinary @Core.MediaType : 'image/png';
|
image : LargeBinary @Core.MediaType : 'image/png';
|
||||||
|
authorName : String;
|
||||||
}
|
}
|
||||||
|
|
||||||
entity Authors : managed {
|
|
||||||
|
entity Authors : managed, extensible {
|
||||||
key ID : Integer;
|
key ID : Integer;
|
||||||
name : String(111);
|
name : String(111);
|
||||||
dateOfBirth : Date;
|
dateOfBirth : Date;
|
||||||
dateOfDeath : Date;
|
dateOfDeath : Date;
|
||||||
placeOfBirth : String;
|
placeOfBirth : String;
|
||||||
placeOfDeath : String;
|
placeOfDeath : String;
|
||||||
books : Association to many Books on books.author = $self;
|
|
||||||
|
books : Association to many Books
|
||||||
|
on books.author = $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Hierarchically organized Code List for Genres */
|
extend Authors with {
|
||||||
|
virtual age : Integer;
|
||||||
|
virtual exampleBook: String;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hierarchically organized Code List for Genres
|
||||||
|
*/
|
||||||
entity Genres : sap.common.CodeList {
|
entity Genres : sap.common.CodeList {
|
||||||
key ID : Integer;
|
key ID : Integer;
|
||||||
parent : Association to Genres;
|
parent : Association to Genres;
|
||||||
children : Composition of many Genres on children.parent = $self;
|
children : Composition of many Genres
|
||||||
|
on children.parent = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Publishers: managed {
|
||||||
|
key ID: Integer;
|
||||||
|
name: String(111);
|
||||||
|
|
||||||
}
|
}
|
||||||
17
bookshop/handlers/AdminService.Authors.CREATE.js
Normal file
17
bookshop/handlers/AdminService.Authors.CREATE.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
async function run() {
|
||||||
|
//debugger
|
||||||
|
//while (true) {}
|
||||||
|
//process.exit()
|
||||||
|
//1.substring()
|
||||||
|
// let res = await specialselect
|
||||||
|
let res = await SELECT.one`title`.from(`Books`).where(`ID=201`)
|
||||||
|
let { title } = res
|
||||||
|
let Author = req.data
|
||||||
|
//await srv.read('Books')
|
||||||
|
|
||||||
|
Author.modifiedBy = "Custom Event handler changed this!"
|
||||||
|
Author.placeOfDeath = " --- Somewhere over " + title + " --- create in Sandbox"
|
||||||
|
//await this.emit("createdAuthor", { Author })
|
||||||
|
return Author
|
||||||
|
}
|
||||||
|
run()
|
||||||
41
bookshop/handlers/AdminService.Authors.READ.js
Normal file
41
bookshop/handlers/AdminService.Authors.READ.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
function getYear(v) {
|
||||||
|
return parseInt(v.substr(0, 4))
|
||||||
|
}
|
||||||
|
function getMonth(v) {
|
||||||
|
return parseInt(v.substr(5, 2))
|
||||||
|
}
|
||||||
|
function getDay(v) {
|
||||||
|
return parseInt(v.substr(8, 2))
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAge(from, to) {
|
||||||
|
if (from === undefined || from == null) return 0
|
||||||
|
if (to === undefined || to == null) to = new Date().toISOString()
|
||||||
|
let year = getYear(to) - getYear(from) - 1
|
||||||
|
if (
|
||||||
|
getMonth(to) > getMonth(from) ||
|
||||||
|
(getMonth(to) === getMonth(from) && getDay(to) >= getDay(from))
|
||||||
|
) {
|
||||||
|
year++
|
||||||
|
}
|
||||||
|
return year
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
const result_ = Array.isArray(result) ? result : [result]
|
||||||
|
for (const row of result_) {
|
||||||
|
row.age = getAge(row.dateOfBirth, row.dateOfDeath)
|
||||||
|
let res = await SELECT.one`title`.from(`Books`).where({ author_ID: row.ID })
|
||||||
|
if (!res) {
|
||||||
|
res = {}
|
||||||
|
}
|
||||||
|
let { title } = res
|
||||||
|
if (!title) {
|
||||||
|
title = "no Books yet"
|
||||||
|
}
|
||||||
|
row.exampleBook = title
|
||||||
|
//let pub = await SELECT.one`name`.from(`sap_capire_bookshop_Publishers`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run()
|
||||||
9
bookshop/handlers/AdminService.Books.CREATE.js
Normal file
9
bookshop/handlers/AdminService.Books.CREATE.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
async function run() {
|
||||||
|
const {stock, price, author_ID} = req.data
|
||||||
|
if (stock<0) return req.reject('409', 'Stock must not be negative')
|
||||||
|
if (price<0) return req.reject('409', 'Price must not be negative')
|
||||||
|
let {name} = await SELECT.one`name`.from(`Authors`).where({ID: author_ID})
|
||||||
|
req.data.authorName=name
|
||||||
|
}
|
||||||
|
output = run()
|
||||||
6
bookshop/handlers/AdminService.Books.READ.js
Normal file
6
bookshop/handlers/AdminService.Books.READ.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
const result_ = Array.isArray(result) ? result : [result];
|
||||||
|
for (const row of result_) {
|
||||||
|
if (row.stock > 50) {
|
||||||
|
row.title += " ---Order now for a 10% discount!";
|
||||||
|
}
|
||||||
|
}
|
||||||
9
bookshop/handlers/AdminService.renameAuthor.ON.js
Normal file
9
bookshop/handlers/AdminService.renameAuthor.ON.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
async function run() {
|
||||||
|
const {author, newName} = req.data
|
||||||
|
let a = await SELECT `name`.from(`Authors`).where({ID: author})
|
||||||
|
if(!a) return req.error (404, `Can't rename a non-existing author`)
|
||||||
|
await UPDATE (`Authors`,author).with ({ name: newName })
|
||||||
|
//await this.emit ('renamedAuthor', { author, newName })
|
||||||
|
output.msg = 'Success'
|
||||||
|
}
|
||||||
|
run()
|
||||||
5
bookshop/handlers/createdAuthor.ON.js
Normal file
5
bookshop/handlers/createdAuthor.ON.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
async function run() {
|
||||||
|
let {Author} = req.data
|
||||||
|
Author.placeOfBirth += ' --- modified in custom event'
|
||||||
|
}
|
||||||
|
run()
|
||||||
112
bookshop/notebook.md
Normal file
112
bookshop/notebook.md
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
# Base assumption
|
||||||
|
|
||||||
|
Event handlers will always use **publicly available application API's**(services)
|
||||||
|
|
||||||
|
- already done in Sandbox API by overwriting **SELECT**, **UPDATE**, **READ** and **CREATE**
|
||||||
|
|
||||||
|
## Inbound data for validations
|
||||||
|
|
||||||
|
- req.target plus expand on related data
|
||||||
|
- lazy loading on expand
|
||||||
|
- event facade could have an explicit publishing of specific services or documents (e.g. remote services)
|
||||||
|
- CQN Protocol adapter for subsequent reads --> req.data plus application service calls
|
||||||
|
- what is the CDS subset to put in?
|
||||||
|
- req.data + target-rec (proxy, unloaded)
|
||||||
|
- ORM type lazy loading (dereferenced)
|
||||||
|
- application developer could actually provide custom proxies for specific functions
|
||||||
|
- performance impact of multiple accesses to object graph and multiple DB roundtrips
|
||||||
|
- can static code checking or developer annotations influence what is loaded into a graph?
|
||||||
|
- alternative: Stripped-down SELECT limited to req.target and ID
|
||||||
|
- application service only
|
||||||
|
- access rights of user respected
|
||||||
|
- What about to-many relationships? For compositions essential, for associations to be questioned
|
||||||
|
- Application Service Reads
|
||||||
|
- outbound data for changes
|
||||||
|
- call remote services
|
||||||
|
- register new remote services dynamically
|
||||||
|
- CAP provides an API on remote services - connect doesn't need to be done by extension developer
|
||||||
|
- alternative: declarative remote services plumbing with CDS service facade
|
||||||
|
- model looks like static internal services, remote calls done transparently behind the scenes
|
||||||
|
|
||||||
|
-Emit Events
|
||||||
|
|
||||||
|
- choreography of extension points
|
||||||
|
- deep inserts vs. fine grained operations
|
||||||
|
- input validation may be suited for fine grained operations
|
||||||
|
- today not in scope for performance reasons
|
||||||
|
- two different use case: Insert new page to book vs. update order-header with items-constraints in place
|
||||||
|
- reject request, return errors and warnings - suitable for UI, too
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Annotations available:
|
||||||
|
|
||||||
|
Entity level
|
||||||
|
@expression.constraint : [{if: 'expression evaluates to bool'}, on: ['INSERT, UPDATE, DELETE'], error: 'Transaction Rollback and error message', warning: 'Transaction proceeds and warning message']
|
||||||
|
@expression.computed : [{expression: 'ability to access request payload and modify it', on: ['INSERT, UPDATE']}]
|
||||||
|
@event : [{if: 'expression evaluates to bool', on: ['INSERT, UPDATE, DELETE, READ'], when: 'before or after, default before', emit: 'Event Name', to: 'Messaging target, optional'}]
|
||||||
|
@expresion.code :[{file: 'file name', on:['insert', 'update'], when: 'before or after, default before'},
|
||||||
|
{source: 'each => { if (each.stock > 111) {each.title += `-- 11% discount!`; each.price= each.price*0.9}', on:['insert', 'update'], when: 'before or after'}]
|
||||||
|
Atribute Level
|
||||||
|
@assert.constraint : {if: 'stock>=0 OR stock <1000', error: 'i18n/error102'};
|
||||||
|
@event : {if: 'expression evaluates to bool', on: ['INSERT, UPDATE, DELETE, READ'], when: 'before or after', emit: 'Event Name', to: 'Messaging target, optional' }
|
||||||
|
|
||||||
|
Functions available:
|
||||||
|
EXISTS(association target)
|
||||||
|
COUNT,AVG,MIN,MAX,SUM: Composition items, arrays etc
|
||||||
|
OLD: before image
|
||||||
|
EACH: loop over composition items
|
||||||
|
|
||||||
|
Events covered:
|
||||||
|
CRUD --> Longhand and Shorthand supported?
|
||||||
|
Upsert as one event?
|
||||||
|
Before and after:
|
||||||
|
Before can change change request payload and stop transaction
|
||||||
|
After should trigger only asynchronous messages
|
||||||
|
Specific Events for status changes? I think expression based event emitter suffices
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Entity level annotations
|
||||||
|
@expression.constraint : [{if: 'stock>100 AND price>15)', on: ['INSERT', 'UPDATE'], error: 'No Book over price 15 should have more than 100 stock' }, // error, rollback transactions
|
||||||
|
{if: 'stock>90 AND price>15)', on: ['I', 'U'], warning: 'No Book over price 15 should have more than 100 stock' }] //warning, proceed with transaction but report warning back to UI
|
||||||
|
@expression.computed : {expression: 'if(stock>100) then price=price*0.9', on: ['INSERT']} //ability to modify the payload of the request, but nothing beyond it
|
||||||
|
@expresion.code :[{file: 'sap.capire.bookshop-Books-beforeInsert', on:['insert', 'update'], when: 'before'}, //naming can be arbitrary?
|
||||||
|
{source: 'each => { if (each.stock > 111) {each.title += `-- 11% discount!`; each.price= each.price*0.9}', on:['insert', 'update'], when: 'before'}] //alternative
|
||||||
|
@event : { if:'price>200', emit: 'Expensive Book', to: 'RulesEngine'}
|
||||||
|
entity Books : managed {
|
||||||
|
key ID : Integer;
|
||||||
|
title : localized String(111); @event : {if: 'old.title="Hello"', emit: 'Hello changed' } //old refers to before Image. No "to" clause means message is emitted to any subscriber interested
|
||||||
|
descr : localized String(1111);
|
||||||
|
author : Association to Authors @assert.constraint: 'exists(author)'; //function calls need to evaluate to bool
|
||||||
|
genre : Association to Genres;
|
||||||
|
stock : Integer @assert.constraint : {if: 'stock>=0 OR stock <1000', error: 'Stock not within permitted parameters'}; //when operand is used, no auto-insert
|
||||||
|
price : Decimal(9,2) @assert.constraint : '>0'; //insert operand on left side by default
|
||||||
|
currency : Currency;
|
||||||
|
image : LargeBinary @Core.MediaType : 'image/png';
|
||||||
|
stockWorth: Decimal(9,2) @expression.computed : 'stock*price'; //persisted on write. Overhead in runtime, but performance benefit on read. Payload ignored?
|
||||||
|
// stockWorth2 = stock*price; -- long term goal from compiler team, not persisted on write, but calculated on read
|
||||||
|
stockWorth3 : Decimal @expression.computed: 'if (stock*price>1000) then stockWorth3=stock.price else stockworth3=1000'; //which altenative?
|
||||||
|
stockWorth4 : Decimal @expression.computed: {if: '(stock*price>1000)', then: 'stockWorth3=stock.price', else: 'stockworth3=1000'};
|
||||||
|
}
|
||||||
|
//@assert.expression: 'dateOfBirth<dateOfDeath'
|
||||||
|
entity Authors : managed {
|
||||||
|
key ID : Integer;
|
||||||
|
name : String(111);
|
||||||
|
dateOfBirth : Date ;
|
||||||
|
dateOfDeath : Date @expression.constraint: '>dateOfBirth';
|
||||||
|
placeOfBirth : String;
|
||||||
|
placeOfDeath : String;
|
||||||
|
books : Association to many Books on books.author = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Hierarchically organized Code List for Genres */
|
||||||
|
entity Genres : sap.common.CodeList {
|
||||||
|
key ID : Integer;
|
||||||
|
parent : Association to Genres;
|
||||||
|
children : Composition of many Genres on children.parent = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
@@ -2,10 +2,18 @@
|
|||||||
"name": "@capire/bookshop",
|
"name": "@capire/bookshop",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "A simple self-contained bookshop service.",
|
"description": "A simple self-contained bookshop service.",
|
||||||
|
"files": [
|
||||||
|
"app",
|
||||||
|
"srv",
|
||||||
|
"db",
|
||||||
|
"index.cds",
|
||||||
|
"index.js"
|
||||||
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^5.0.4",
|
"@sap/cds": ">=5.9",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"passport": "0.4.1"
|
"passport": ">=0.4.1",
|
||||||
|
"vm2": ">=3.9.9"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"genres": "cds serve test/genres.cds",
|
"genres": "cds serve test/genres.cds",
|
||||||
@@ -14,8 +22,12 @@
|
|||||||
},
|
},
|
||||||
"cds": {
|
"cds": {
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"code-extensibility" : true,
|
||||||
"db": {
|
"db": {
|
||||||
"kind": "sql"
|
"kind": "sqlite",
|
||||||
|
"credentials": {
|
||||||
|
"database": "sqlite.db"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
bookshop/sqlite.db
Normal file
BIN
bookshop/sqlite.db
Normal file
Binary file not shown.
@@ -1,5 +1,30 @@
|
|||||||
using { sap.capire.bookshop as my } from '../db/schema';
|
using {sap.capire.bookshop as my} from '../db/schema';
|
||||||
service AdminService @(requires:'admin') {
|
|
||||||
entity Books as projection on my.Books;
|
service AdminService // @(requires : 'admin')
|
||||||
entity Authors as projection on my.Authors;
|
{
|
||||||
|
entity Books as projection on my.Books actions {
|
||||||
|
action increaseStock(count : Integer);
|
||||||
|
function stock() returns Integer;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Extensibility : {
|
||||||
|
Fields.Enabled : true,
|
||||||
|
Fields.Quota: 100,
|
||||||
|
Relations.Enabled : false,
|
||||||
|
Annotations.Enabled : true,
|
||||||
|
Logic.Enabled : true,
|
||||||
|
Logic.constraints: true,
|
||||||
|
Logic.calculations: true,
|
||||||
|
Logic.Handler : [create, update, delete, read]
|
||||||
|
}
|
||||||
|
entity Authors as projection on my.Authors;
|
||||||
|
|
||||||
|
action renameAuthor(author : Authors:ID, newName : String) returns {
|
||||||
|
msg : String
|
||||||
|
};
|
||||||
|
function getStock(book: Books:ID) returns Integer;
|
||||||
|
event newBook : {
|
||||||
|
book : Books:ID;
|
||||||
|
name : Books:title
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,135 @@
|
|||||||
const cds = require('@sap/cds')
|
const cds = require("@sap/cds")
|
||||||
|
//const cds_sandbox = require("sap/cds/sandbox")
|
||||||
|
const { VM, VMScript } = require("vm2")
|
||||||
|
const fs = require("fs")
|
||||||
|
const path = require("path")
|
||||||
|
const { nextTick } = require("process")
|
||||||
|
|
||||||
module.exports = cds.service.impl (function(){
|
class AdminService extends cds.ApplicationService {
|
||||||
this.before ('NEW','Authors', genid)
|
init() {
|
||||||
this.before ('NEW','Books', genid)
|
this.after("READ", async (result, req) => {
|
||||||
})
|
if (!(result === undefined || result == null)) {
|
||||||
|
const code = getCode(req.target.name, "READ")
|
||||||
|
if (code) {
|
||||||
|
await executeCode.call(this, code, req, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
/** Generate primary keys for target entity in request */
|
this.before("CREATE", async (req) => {
|
||||||
async function genid (req) {
|
const code = getCode(req.target.name, "CREATE")
|
||||||
const {ID} = await cds.tx(req).run (SELECT.one.from(req.target).columns('max(ID) as ID'))
|
if (code) {
|
||||||
req.data.ID = ID - ID % 100 + 100 + 1
|
await executeCode.call(this, code, req)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.before("UPDATE", async (req) => {
|
||||||
|
const code = getCode(req.target.name, "CREATE")
|
||||||
|
if (code) {
|
||||||
|
await executeCode.call(this, code, req)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.on("*", async (req, next) => {
|
||||||
|
if (!(req.target === undefined || req.target == null)) return next()
|
||||||
|
//ToDo: check whether action or event is part of an extension
|
||||||
|
// DO NOT OVERWRITE EXISTING Action Implementations!
|
||||||
|
// evaluate: Can we augment action implementation with super.next?
|
||||||
|
if (req.constructor.name === "EventMessage") {
|
||||||
|
const code = getCode(req.event, "ON")
|
||||||
|
if (code) {
|
||||||
|
await executeCode.call(this, code, req)
|
||||||
|
}
|
||||||
|
} else if (req.constructor.name === "ODataRequest") {
|
||||||
|
var output = {}
|
||||||
|
const code = getCode(this.name + "." + req.event, "ON")
|
||||||
|
if (code) {
|
||||||
|
await executeCode.call(this, code, req, {}, output)
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//ToDo: Prefix for Service not in event emitter
|
||||||
|
this.before("CREATE", "Authors", async (req) => {
|
||||||
|
let Author = req.data
|
||||||
|
await this.emit("createdAuthor", { Author })
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
return super.init()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var counter = 1;
|
||||||
|
|
||||||
|
function newLabel() {return "VM2 - req: " + counter++}
|
||||||
|
|
||||||
|
//should only work in local exection (cds watch)
|
||||||
|
// alternative: Upon Bootstrapping, merge files into CSN
|
||||||
|
function getCodeFromFile(name, operation) {
|
||||||
|
const filename = name + "." + operation + ".js"
|
||||||
|
const file = path.join(__dirname, "..", "handlers", filename)
|
||||||
|
try {
|
||||||
|
const code = fs.readFileSync(file, "utf8")
|
||||||
|
return code
|
||||||
|
} catch (error) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//after push this should be the only thing that works
|
||||||
|
function getCodeFromAnnotation(name, operation) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCode(name, operation) {
|
||||||
|
let code=getCodeFromAnnotation(name, operation)
|
||||||
|
if (code==="") {code=getCodeFromFile(name, operation)}
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
|
||||||
|
function scanCode(code) {
|
||||||
|
//ESLINT
|
||||||
|
}
|
||||||
|
|
||||||
|
async function executeCode(code, req, result, output) {
|
||||||
|
const srv = this
|
||||||
|
const label=newLabel()
|
||||||
|
console.time(label)
|
||||||
|
const vm = new VM({
|
||||||
|
console: "inherit",
|
||||||
|
timeout: 500,
|
||||||
|
allowAsync: true,
|
||||||
|
sandbox: { req, //todo: isolate req.data, req.reject, req.error, req.message
|
||||||
|
result, //important for READ
|
||||||
|
output, //used for Action Implementation
|
||||||
|
SELECT : (class extends require('@sap/cds/lib/ql/SELECT') {then(r,e) {return srv.run(this).then(r,e)}})._api(),
|
||||||
|
INSERT : (class extends require('@sap/cds/lib/ql/INSERT') {then(r,e) {return srv.run(this).then(r,e)}})._api(),
|
||||||
|
UPDATE : (class extends require('@sap/cds/lib/ql/UPDATE') {then(r,e) {return srv.run(this).then(r,e)}})._api(),
|
||||||
|
CREATE : (class extends require('@sap/cds/lib/ql/CREATE') {then(r,e) {return srv.run(this).then(r,e)}})._api(),
|
||||||
|
//srv: this,
|
||||||
|
JSON },
|
||||||
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
await vm.run(code)
|
||||||
|
return output
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
req.reject("409", "Error in VM")
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
console.timeEnd(label)
|
||||||
|
}
|
||||||
|
// console.log(req.data)
|
||||||
|
}
|
||||||
|
/** Generate primary keys for target entity in request */
|
||||||
|
async function genid(req) {
|
||||||
|
const { ID } = await cds
|
||||||
|
.tx(req)
|
||||||
|
.run(SELECT.one.from(req.target).columns("max(ID) as ID"))
|
||||||
|
req.data.ID = ID - (ID % 100) + 100 + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { AdminService }
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ service CatalogService @(path:'/browse') {
|
|||||||
author.name as author
|
author.name as author
|
||||||
} excluding { createdBy, modifiedBy };
|
} excluding { createdBy, modifiedBy };
|
||||||
|
|
||||||
|
@readonly entity Publishers as projection on my.Publishers;
|
||||||
|
|
||||||
@requires: 'authenticated-user'
|
@requires: 'authenticated-user'
|
||||||
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
|
action submitOrder ( book: Books:ID, quantity: Integer ) returns { stock: Integer };
|
||||||
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
|
event OrderedBook : { book: Books:ID; quantity: Integer; buyer: String };
|
||||||
|
|||||||
11
bookshop/srv/code-extensions.cds
Normal file
11
bookshop/srv/code-extensions.cds
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//this file is machine-created during cds.build
|
||||||
|
namespace sap.capire.bookshop; //> important for reflection
|
||||||
|
using from '../db/schema';
|
||||||
|
using from '../srv/cat-service';
|
||||||
|
using from '../srv/admin-service';
|
||||||
|
|
||||||
|
annotate AdminService.Authors with @extension.logic: [{when: 'CREATE', code: 'async function run() {\r\n \/\/debugger\r\n \/\/while (true) {}\r\n \/\/process.exit()\r\n \/\/1.substring()\r\n \/\/ let res = await specialselect\r\n let res = await SELECT.one`title`.from(`Books`).where(`ID=201`)\r\n let { title } = res\r\n let Author = req.data\r\n Author.modifiedBy = \"Custom Event handler changed this!\"\r\n Author.placeOfDeath = \" --- Somewhere over \" + title + \" --- create in Sandbox\"\r\n \/\/await this.emit(\"createdAuthor\", { Author })\r\n return Author\r\n}\r\nrun()\r\n'},
|
||||||
|
{when: 'READ', code: 'function getYear(v) {\r\n return parseInt(v.substr(0, 4))\r\n}\r\nfunction getMonth(v) {\r\n return parseInt(v.substr(5, 2))\r\n}\r\nfunction getDay(v) {\r\n return parseInt(v.substr(8, 2))\r\n}\r\n\r\nfunction getAge(from, to) {\r\n if (from === undefined || from == null) return 0\r\n if (to === undefined || to == null) to = new Date().toISOString()\r\n let year = getYear(to) - getYear(from) - 1\r\n if (\r\n getMonth(to) > getMonth(from) ||\r\n (getMonth(to) === getMonth(from) && getDay(to) >= getDay(from))\r\n ) {\r\n year++\r\n }\r\n return year\r\n}\r\n\r\nconst result_ = Array.isArray(result) ? result : [result]\r\nfor (const row of result_) {\r\n row.modifiedBy += \" --- read in sandbox\"\r\n row.age = getAge(row.dateOfBirth, row.dateOfDeath)\r\n}'}
|
||||||
|
];
|
||||||
|
annotate AdminService.Books with @extension.logic;
|
||||||
|
annotate CatalogService.ListOfBooks with @extension.logic;
|
||||||
16
bookshop/srv/user-service.cds
Normal file
16
bookshop/srv/user-service.cds
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Exposes user information
|
||||||
|
*/
|
||||||
|
@requires: 'authenticated-user'
|
||||||
|
service UserService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current user
|
||||||
|
*/
|
||||||
|
@odata.singleton entity me {
|
||||||
|
id : String; // user id
|
||||||
|
locale : String;
|
||||||
|
tenant : String;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
4
bookshop/srv/user-service.js
Normal file
4
bookshop/srv/user-service.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
const cds = require('@sap/cds')
|
||||||
|
module.exports = cds.service.impl((srv) => {
|
||||||
|
srv.on('READ', 'me', ({ tenant, user, locale }) => ({ id: user.id, locale, tenant }))
|
||||||
|
})
|
||||||
@@ -1,10 +1,46 @@
|
|||||||
@server = http://localhost:4004
|
@server = http://localhost:4004
|
||||||
@me = Authorization: Basic {{$processEnv USER}}:
|
@me = Authorization: Basic {{$processEnv USER}}:
|
||||||
|
@id = 2000
|
||||||
|
|
||||||
|
|
||||||
|
### ------------------------------------------------------------------------
|
||||||
|
# Fetch Authors
|
||||||
|
GET {{server}}/admin/Authors
|
||||||
|
|
||||||
|
### ------------------------------------------------------------------------
|
||||||
|
# Fetch one Author
|
||||||
|
GET {{server}}/admin/Authors({{id}})
|
||||||
|
|
||||||
|
### ------------------------------------------------------------------------
|
||||||
|
# Create Author
|
||||||
|
POST {{server}}/admin/Authors
|
||||||
|
Content-Type: application/json;IEEE754Compatible=true
|
||||||
|
|
||||||
|
{
|
||||||
|
"ID": {{id}},
|
||||||
|
"name": "Nick",
|
||||||
|
"placeOfBirth": "Somewhere",
|
||||||
|
"placeOfDeath": "over the Rainbox",
|
||||||
|
"dateOfBirth" : "1975-05-27"
|
||||||
|
}
|
||||||
|
|
||||||
|
### ------------------------------------------------------------------------
|
||||||
|
# rename author via unbound action
|
||||||
|
POST {{server}}/admin/renameAuthor
|
||||||
|
Content-Type: application/json
|
||||||
|
{{me}}
|
||||||
|
|
||||||
|
{ "author":{{id}}, "newName":"Super Nick" }
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
# Get service info
|
# Get service info
|
||||||
GET {{server}}/browse
|
GET {{server}}/admin
|
||||||
|
{{me}}
|
||||||
|
|
||||||
|
### ------------------------------------------------------------------------
|
||||||
|
# Get $metadata document
|
||||||
|
GET {{server}}/admin/$metadata
|
||||||
{{me}}
|
{{me}}
|
||||||
|
|
||||||
|
|
||||||
@@ -16,34 +52,19 @@ GET {{server}}/browse/$metadata
|
|||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
# Browse Books as any user
|
# Browse Books as any user
|
||||||
GET {{server}}/browse/Books?
|
GET {{server}}/browse/ListOfBooks?
|
||||||
# &$select=title,stock
|
# &$select=title,stock
|
||||||
# &$expand=currency
|
&$expand=genre
|
||||||
# &sap-language=de
|
# &sap-language=de
|
||||||
{{me}}
|
{{me}}
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
|
||||||
# Fetch Authors as admin
|
|
||||||
GET {{server}}/admin/Authors?
|
|
||||||
# &$select=name,dateOfBirth,placeOfBirth
|
|
||||||
# &$expand=books($select=title;$expand=currency)
|
|
||||||
# &$filter=ID eq 101
|
|
||||||
# &sap-language=de
|
|
||||||
Authorization: Basic alice:
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
# Create Author
|
# Fetch Books as admin
|
||||||
POST {{server}}/admin/Authors
|
GET {{server}}/admin/Books
|
||||||
Content-Type: application/json;IEEE754Compatible=true
|
|
||||||
Authorization: Basic alice:
|
|
||||||
|
|
||||||
{
|
|
||||||
"ID": 112,
|
|
||||||
"name": "Shakespeeeeere",
|
|
||||||
"age": 22
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### ------------------------------------------------------------------------
|
### ------------------------------------------------------------------------
|
||||||
# Create book
|
# Create book
|
||||||
@@ -52,12 +73,12 @@ Content-Type: application/json;IEEE754Compatible=true
|
|||||||
Authorization: Basic alice:
|
Authorization: Basic alice:
|
||||||
|
|
||||||
{
|
{
|
||||||
"ID": 2,
|
"ID": 16,
|
||||||
"title": "Poems : Pocket Poets",
|
"title": "Deh4",
|
||||||
"descr": "The Everyman's Library Pocket Poets hardcover series is popular for its compact size and reasonable price which does not compromise content. Poems: Bronte contains poems that demonstrate a sensibility elemental in its force with an imaginative discipline and flexibility of the highest order. Also included are an Editor's Note and an index of first lines.",
|
"descr": "The Everyman's Library Pocket Poets hardcover series is popular for its compact size and reasonable price which does not compromise content. Poems: Bronte contains poems that demonstrate a sensibility elemental in its force with an imaginative discipline and flexibility of the highest order. Also included are an Editor's Note and an index of first lines.",
|
||||||
"author": { "ID": 101 },
|
"author": { "ID": 101 },
|
||||||
"genre": { "ID": 12 },
|
"genre": { "ID": 12 },
|
||||||
"stock": 5,
|
"stock": -100,
|
||||||
"price": "12.05",
|
"price": "12.05",
|
||||||
"currency": { "code": "USD" }
|
"currency": { "code": "USD" }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"@capire/orders": "*",
|
"@capire/orders": "*",
|
||||||
"@capire/common": "*",
|
"@capire/common": "*",
|
||||||
"@capire/data-viewer": "*",
|
"@capire/data-viewer": "*",
|
||||||
"@sap/cds": "^5",
|
"@sap/cds": ">=5",
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1"
|
||||||
},
|
},
|
||||||
"cds": {
|
"cds": {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "A generic browser for data",
|
"description": "A generic browser for data",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^5.0.4"
|
"@sap/cds": ">=5.0.4"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"app",
|
"app",
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ annotate AdminService.Authors with @(UI : {
|
|||||||
|
|
||||||
// Workaround to avoid errors for unknown db-specific calculated fields above
|
// Workaround to avoid errors for unknown db-specific calculated fields above
|
||||||
extend sap.capire.bookshop.Authors with {
|
extend sap.capire.bookshop.Authors with {
|
||||||
virtual age : Integer;
|
//virtual age : Integer;
|
||||||
virtual lifetime : String;
|
virtual lifetime : String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"dataSources": {
|
"dataSources": {
|
||||||
"AdminService": {
|
"AdminService": {
|
||||||
"uri": "/admin/",
|
"uri": "admin/",
|
||||||
"type": "OData",
|
"type": "OData",
|
||||||
"settings": {
|
"settings": {
|
||||||
"odataVersion": "4.0"
|
"odataVersion": "4.0"
|
||||||
@@ -50,6 +50,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sap.ui5": {
|
"sap.ui5": {
|
||||||
|
"flexEnabled": true,
|
||||||
|
"config": {
|
||||||
|
"experimentalCAPScenario": true
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minUI5Version": "1.81.0",
|
"minUI5Version": "1.81.0",
|
||||||
"libs": {
|
"libs": {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"i18n": "i18n/i18n.properties",
|
"i18n": "i18n/i18n.properties",
|
||||||
"dataSources": {
|
"dataSources": {
|
||||||
"AdminService": {
|
"AdminService": {
|
||||||
"uri": "/admin/",
|
"uri": "admin/",
|
||||||
"type": "OData",
|
"type": "OData",
|
||||||
"settings": {
|
"settings": {
|
||||||
"odataVersion": "4.0"
|
"odataVersion": "4.0"
|
||||||
@@ -22,6 +22,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sap.ui5": {
|
"sap.ui5": {
|
||||||
|
"flexEnabled": true,
|
||||||
|
"config": {
|
||||||
|
"experimentalCAPScenario": true
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"libs": {
|
"libs": {
|
||||||
"sap.fe.templates": {}
|
"sap.fe.templates": {}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"dataSources": {
|
"dataSources": {
|
||||||
"CatalogService": {
|
"CatalogService": {
|
||||||
"uri": "/browse/",
|
"uri": "browse/",
|
||||||
"type": "OData",
|
"type": "OData",
|
||||||
"settings": {
|
"settings": {
|
||||||
"odataVersion": "4.0"
|
"odataVersion": "4.0"
|
||||||
@@ -53,6 +53,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sap.ui5": {
|
"sap.ui5": {
|
||||||
|
"flexEnabled": true,
|
||||||
|
"config": {
|
||||||
|
"experimentalCAPScenario": true
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minUI5Version": "1.81.0",
|
"minUI5Version": "1.81.0",
|
||||||
"libs": {
|
"libs": {
|
||||||
|
|||||||
@@ -10,7 +10,21 @@
|
|||||||
<script>
|
<script>
|
||||||
window["sap-ushell-config"] = {
|
window["sap-ushell-config"] = {
|
||||||
defaultRenderer: "fiori2",
|
defaultRenderer: "fiori2",
|
||||||
applications: {}
|
applications: {},
|
||||||
|
bootstrapPlugins: {
|
||||||
|
RuntimeAuthoringPlugin: {
|
||||||
|
component: "sap.ushell.plugins.rta",
|
||||||
|
config: {
|
||||||
|
validateAppVersion: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PersonalizePlugin: {
|
||||||
|
component: "sap.ushell.plugins.rta-personalize",
|
||||||
|
config: {
|
||||||
|
validateAppVersion: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -18,11 +32,15 @@
|
|||||||
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
|
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
|
||||||
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
|
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
|
||||||
data-sap-ui-compatVersion="edge"
|
data-sap-ui-compatVersion="edge"
|
||||||
data-sap-ui-theme="sap_fiori_3"
|
data-sap-ui-theme="sap_horizon"
|
||||||
data-sap-ui-frameOptions="allow"
|
data-sap-ui-frameOptions="allow"
|
||||||
></script>
|
></script>
|
||||||
<script>
|
<script>
|
||||||
sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"))
|
sap.ui.getCore().attachInit(()=> sap.ushell.Container.createRenderer().placeAt("content"));
|
||||||
|
sap.ui
|
||||||
|
.getCore()
|
||||||
|
.getConfiguration()
|
||||||
|
.setFlexibilityServices([{ connector: "SessionStorageConnector" }]);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capire/bookstore": "*",
|
"@capire/bookstore": "*",
|
||||||
"@sap/cds": "^5",
|
"@sap/cds": ">=5",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"passport": "^0.4.1"
|
"passport": ">=0.4.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cds run --in-memory?",
|
"start": "cds run --in-memory?",
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"cds": {
|
"cds": {
|
||||||
"requires": {
|
"requires": {
|
||||||
"auth": {
|
"auth": {
|
||||||
"strategy": "dummy"
|
"kind": "dummy-auth"
|
||||||
},
|
},
|
||||||
"ReviewsService": {
|
"ReviewsService": {
|
||||||
"kind": "odata",
|
"kind": "odata",
|
||||||
@@ -36,7 +36,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"db": {
|
"db": {
|
||||||
"kind": "sql"
|
"kind": "sqlite",
|
||||||
|
"credentials": {
|
||||||
|
"database": "sqlite.db"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"db-ext": {
|
"db-ext": {
|
||||||
"[development]": {
|
"[development]": {
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
"start:ts": "cds-ts serve srv/world.cds"
|
"start:ts": "cds-ts serve srv/world.cds"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^5.0.4"
|
"@sap/cds": ">=5.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "*",
|
||||||
"@types/node": "^16.11.6",
|
"@types/node": "*",
|
||||||
"ts-jest": "^27.0.2",
|
"ts-jest": "^27.0.2",
|
||||||
"typescript": "^4.3.5"
|
"typescript": "^4.3.5"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
|
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
|
||||||
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
|
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
|
||||||
data-sap-ui-compatVersion="edge"
|
data-sap-ui-compatVersion="edge"
|
||||||
data-sap-ui-theme="sap_fiori_3"
|
data-sap-ui-theme="sap_horizon"
|
||||||
data-sap-ui-frameOptions="allow"
|
data-sap-ui-frameOptions="allow"
|
||||||
></script>
|
></script>
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capire/common": "*",
|
"@capire/common": "*",
|
||||||
"@sap/cds": "^5"
|
"@sap/cds": ">=5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11533
package-lock.json
generated
11533
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -14,13 +14,14 @@
|
|||||||
"@capire/media": "./media",
|
"@capire/media": "./media",
|
||||||
"@capire/orders": "./orders",
|
"@capire/orders": "./orders",
|
||||||
"@capire/reviews": "./reviews",
|
"@capire/reviews": "./reviews",
|
||||||
"@sap/cds": "^5.5.3"
|
"@sap/cds": ">=5.5.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
"chai-subset": "^1.6.0",
|
"chai-subset": "^1.6.0",
|
||||||
"sqlite3": "npm:@mendix/sqlite3@^5"
|
"semver": "^7",
|
||||||
|
"sqlite3": "^5"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
|
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ const GET = (url) => axios.get('/reviews'+url)
|
|||||||
const PUT = (cmd,data) => axios.patch('/reviews'+cmd,data)
|
const PUT = (cmd,data) => axios.patch('/reviews'+cmd,data)
|
||||||
const POST = (cmd,data) => axios.post('/reviews'+cmd,data)
|
const POST = (cmd,data) => axios.post('/reviews'+cmd,data)
|
||||||
|
|
||||||
const reviews = new Vue ({
|
const reviews = Vue.createApp ({
|
||||||
|
|
||||||
el:'#app',
|
data() {
|
||||||
|
return {
|
||||||
data: {
|
|
||||||
list: [],
|
list: [],
|
||||||
review: undefined,
|
review: undefined,
|
||||||
message: {},
|
message: {},
|
||||||
@@ -19,6 +18,7 @@ const reviews = new Vue ({
|
|||||||
2 : '★★',
|
2 : '★★',
|
||||||
1 : '★',
|
1 : '★',
|
||||||
}).reverse()
|
}).reverse()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
@@ -66,7 +66,7 @@ const reviews = new Vue ({
|
|||||||
datetime: (d) => d && new Date(d).toLocaleString(),
|
datetime: (d) => d && new Date(d).toLocaleString(),
|
||||||
},
|
},
|
||||||
|
|
||||||
})
|
}).mount("#app")
|
||||||
|
|
||||||
// initially fill list of my reviews
|
// initially fill list of my reviews
|
||||||
reviews.fetch()
|
reviews.fetch()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<title> Capire Reviews </title>
|
<title> Capire Reviews </title>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/primitive-ui/dist/css/main.css">
|
<link rel="stylesheet" href="https://unpkg.com/primitive-ui/dist/css/main.css">
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
|
||||||
<style>
|
<style>
|
||||||
.hovering tr:hover td { color:cyan; background: #123; cursor: pointer; }
|
.hovering tr:hover td { color:cyan; background: #123; cursor: pointer; }
|
||||||
.rating-stars { color:teal }
|
.rating-stars { color:teal }
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<body class="small-container", style="margin-top: 70px;">
|
<body class="small-container", style="margin-top: 70px;">
|
||||||
<div id='app'>
|
<div id='app'>
|
||||||
|
|
||||||
<h1> {{ document.title }} </h1>
|
<h1> Capire Reviews </h1>
|
||||||
|
|
||||||
<input type="text" placeholder="Search..." @input="search">
|
<input type="text" placeholder="Search..." @input="search">
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"index.cds"
|
"index.cds"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sap/cds": "^5",
|
"@sap/cds": ">=5",
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1"
|
||||||
},
|
},
|
||||||
"cds": {
|
"cds": {
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ describe('cds.ql → cqn', () => {
|
|||||||
.to.eql(SELECT('Foo','Boo').from('Bar'))
|
.to.eql(SELECT('Foo','Boo').from('Bar'))
|
||||||
.to.eql(SELECT(['Foo','Boo']).from('Bar'))
|
.to.eql(SELECT(['Foo','Boo']).from('Bar'))
|
||||||
.to.eql(SELECT `Bar` .columns `Foo, Boo`)
|
.to.eql(SELECT `Bar` .columns `Foo, Boo`)
|
||||||
|
.to.eql(SELECT `Bar` .columns `{ Foo, Boo }`)
|
||||||
|
.to.eql(SELECT `Bar` .columns ('{ Foo, Boo }'))
|
||||||
.to.eql(SELECT `Bar` .columns ('Foo','Boo'))
|
.to.eql(SELECT `Bar` .columns ('Foo','Boo'))
|
||||||
.to.eql(SELECT `Bar` .columns (['Foo','Boo']))
|
.to.eql(SELECT `Bar` .columns (['Foo','Boo']))
|
||||||
.to.eql(SELECT.from `Bar` .columns ('Foo','Boo'))
|
.to.eql(SELECT.from `Bar` .columns ('Foo','Boo'))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const cds = require('@sap/cds/lib')
|
const cds = require('@sap/cds/lib')
|
||||||
const { expect } = cds.test ('@capire/bookshop')
|
const { expect } = cds.test ('@capire/bookshop')
|
||||||
|
|
||||||
describe('Consuming Services locally', () => {
|
describe('cap/samples - Consuming Services locally', () => {
|
||||||
//
|
//
|
||||||
it('bootstrapped the database successfully', ()=>{
|
it('bootstrapped the database successfully', ()=>{
|
||||||
const { AdminService } = cds.services
|
const { AdminService } = cds.services
|
||||||
@@ -32,6 +32,27 @@ describe('Consuming Services locally', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).where(`name like`, 'E%')
|
}).where(`name like`, 'E%')
|
||||||
|
if (require('semver').gte(cds.version, '5.9.0')) {
|
||||||
|
expect(authors).to.containSubset([
|
||||||
|
{
|
||||||
|
name: 'Emily Brontë',
|
||||||
|
books: [
|
||||||
|
{
|
||||||
|
title: 'Wuthering Heights',
|
||||||
|
currency: { name: 'British Pound', symbol: '£' },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Edgar Allen Poe',
|
||||||
|
books: [
|
||||||
|
{ title: 'The Raven', currency: { name: 'US Dollar', symbol: '$' } },
|
||||||
|
{ title: 'Eleonora', currency: { name: 'US Dollar', symbol: '$' } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
return
|
||||||
|
}
|
||||||
expect(authors).to.containSubset([
|
expect(authors).to.containSubset([
|
||||||
{
|
{
|
||||||
name: 'Emily Brontë',
|
name: 'Emily Brontë',
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const { GET, POST, expect } = cds.test(__dirname+'/../bookshop')
|
|||||||
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
||||||
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
||||||
|
|
||||||
describe('Custom Handlers', () => {
|
describe('cap/samples - Custom Handlers', () => {
|
||||||
|
|
||||||
it('should reject out-of-stock orders', async () => {
|
it('should reject out-of-stock orders', async () => {
|
||||||
await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`
|
await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const cds = require('@sap/cds/lib')
|
const cds = require('@sap/cds/lib')
|
||||||
const { GET, expect } = cds.test (__dirname+'/../hello')
|
const { GET, expect } = cds.test (__dirname+'/../hello')
|
||||||
|
|
||||||
describe('Hello world!', () => {
|
describe('cap/samples - Hello world!', () => {
|
||||||
|
|
||||||
it('should say hello with class impl', async () => {
|
it('should say hello with class impl', async () => {
|
||||||
const {data} = await GET `/say/hello(to='world')`
|
const {data} = await GET `/say/hello(to='world')`
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const model = cds.compile.to.csn (`
|
|||||||
const {Categories:Cats} = model.definitions
|
const {Categories:Cats} = model.definitions
|
||||||
|
|
||||||
|
|
||||||
describe('Hierarchical Data', ()=>{
|
describe('cap/samples - Hierarchical Data', ()=>{
|
||||||
|
|
||||||
before ('bootstrap sqlite in-memory db...', async()=>{
|
before ('bootstrap sqlite in-memory db...', async()=>{
|
||||||
await cds.deploy (model) .to ('sqlite::memory:')
|
await cds.deploy (model) .to ('sqlite::memory:')
|
||||||
@@ -35,6 +35,21 @@ describe('Hierarchical Data', ()=>{
|
|||||||
))
|
))
|
||||||
|
|
||||||
it ('supports nested reads', async()=>{
|
it ('supports nested reads', async()=>{
|
||||||
|
if (require('semver').gte(cds.version, '5.9.0')) {
|
||||||
|
expect (await
|
||||||
|
SELECT.one.from (Cats, c=>{
|
||||||
|
c.ID, c.name.as('parent'), c.children (c=>{
|
||||||
|
c.name.as('child')
|
||||||
|
})
|
||||||
|
}) .where ({name:'Cat'})
|
||||||
|
) .to.eql (
|
||||||
|
{ ID:101, parent:'Cat', children:[
|
||||||
|
{ child:'Kitty' },
|
||||||
|
{ child:'Catwoman' },
|
||||||
|
]}
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
expect (await
|
expect (await
|
||||||
SELECT.one.from (Cats, c=>{
|
SELECT.one.from (Cats, c=>{
|
||||||
c.ID, c.name.as('parent'), c.children (c=>{
|
c.ID, c.name.as('parent'), c.children (c=>{
|
||||||
@@ -50,6 +65,25 @@ describe('Hierarchical Data', ()=>{
|
|||||||
})
|
})
|
||||||
|
|
||||||
it ('supports deeply nested reads', async()=>{
|
it ('supports deeply nested reads', async()=>{
|
||||||
|
if (require('semver').gte(cds.version, '5.9.0')) {
|
||||||
|
expect (await SELECT.one.from (Cats, c=>{
|
||||||
|
c.ID, c.name, c.children (
|
||||||
|
c => { c.name },
|
||||||
|
{levels:3}
|
||||||
|
)
|
||||||
|
}) .where ({name:'Cat'})
|
||||||
|
) .to.eql (
|
||||||
|
{ ID:101, name:'Cat', children:[
|
||||||
|
{ name:'Kitty', children:[
|
||||||
|
{ name:'Kitty Cat', children:[
|
||||||
|
{ name:'Aristocat' }, ]}, // level 3
|
||||||
|
{ name:'Kitty Bat', children:[] }, ]},
|
||||||
|
{ name:'Catwoman', children:[
|
||||||
|
{ name:'Catalina', children:[] } ]},
|
||||||
|
]}
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
expect (await SELECT.one.from (Cats, c=>{
|
expect (await SELECT.one.from (Cats, c=>{
|
||||||
c.ID, c.name, c.children (
|
c.ID, c.name, c.children (
|
||||||
c => { c.name },
|
c => { c.name },
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const { GET, expect, cds } = require('@sap/cds/lib').test (__dirname)
|
|||||||
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
||||||
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
||||||
|
|
||||||
describe('Localized Data', () => {
|
describe('cap/samples - Localized Data', () => {
|
||||||
|
|
||||||
it('serves localized $metadata documents', async () => {
|
it('serves localized $metadata documents', async () => {
|
||||||
const { data } = await GET`/browse/$metadata?sap-language=de`
|
const { data } = await GET`/browse/$metadata?sap-language=de`
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const _model = '@capire/reviews'
|
|||||||
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
||||||
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
||||||
|
|
||||||
describe('Messaging', ()=>{
|
describe('cap/samples - Messaging', ()=>{
|
||||||
|
|
||||||
it ('should bootstrap sqlite in-memory db', async()=>{
|
it ('should bootstrap sqlite in-memory db', async()=>{
|
||||||
const db = await cds.deploy (_model) .to ('sqlite::memory:')
|
const db = await cds.deploy (_model) .to ('sqlite::memory:')
|
||||||
|
|||||||
@@ -1,9 +1,48 @@
|
|||||||
const cds = require('@sap/cds/lib')
|
const cds = require('@sap/cds/lib')
|
||||||
const { GET, expect } = cds.test ('@capire/bookshop')
|
const { GET, expect, axios } = cds.test ('@capire/bookshop')
|
||||||
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
axios.defaults.auth = { username: 'alice', password: 'admin' }
|
||||||
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
|
||||||
|
|
||||||
describe('OData Protocol', () => {
|
describe('cap/samples - Bookshop APIs', () => {
|
||||||
|
|
||||||
|
// Genres
|
||||||
|
const Drama = {
|
||||||
|
"name": "Drama",
|
||||||
|
"descr": null,
|
||||||
|
"ID": 11,
|
||||||
|
"parent_ID": 10
|
||||||
|
}
|
||||||
|
const Mystery = {
|
||||||
|
"name": "Mystery",
|
||||||
|
"descr": null,
|
||||||
|
"ID": 16,
|
||||||
|
"parent_ID": 10
|
||||||
|
}
|
||||||
|
const Fantasy = {
|
||||||
|
"name": "Fantasy",
|
||||||
|
"descr": null,
|
||||||
|
"ID": 13,
|
||||||
|
"parent_ID": 10
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currencies
|
||||||
|
const GBP = {
|
||||||
|
"name": "British Pound",
|
||||||
|
"descr": null,
|
||||||
|
"code": "GBP",
|
||||||
|
"symbol": "£"
|
||||||
|
}
|
||||||
|
const USD = {
|
||||||
|
"name": "US Dollar",
|
||||||
|
"descr": null,
|
||||||
|
"code": "USD",
|
||||||
|
"symbol": "$"
|
||||||
|
}
|
||||||
|
const JPY = {
|
||||||
|
"name": "Yen",
|
||||||
|
"descr": null,
|
||||||
|
"code": "JPY",
|
||||||
|
"symbol": "¥"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
it('serves $metadata documents in v4', async () => {
|
it('serves $metadata documents in v4', async () => {
|
||||||
@@ -17,6 +56,16 @@ describe('OData Protocol', () => {
|
|||||||
expect(data).to.contain('<Annotation Term="Common.Label" String="Currency"/>')
|
expect(data).to.contain('<Annotation Term="Common.Label" String="Currency"/>')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('serves ListOfBooks?$expand=genre,currency', async () => {
|
||||||
|
const { data } = await GET `/browse/ListOfBooks ${{
|
||||||
|
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
|
||||||
|
}}`
|
||||||
|
expect(data.value).to.eql([
|
||||||
|
{ ID: 251, title: 'The Raven', author: 'Edgar Allen Poe', genre:Mystery, currency:USD },
|
||||||
|
{ ID: 252, title: 'Eleonora', author: 'Edgar Allen Poe', genre:Mystery, currency:USD },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
it('supports $search in multiple fields', async () => {
|
it('supports $search in multiple fields', async () => {
|
||||||
const { data } = await GET `/browse/Books ${{
|
const { data } = await GET `/browse/Books ${{
|
||||||
params: { $search: 'Po', $select: `title,author` },
|
params: { $search: 'Po', $select: `title,author` },
|
||||||
@@ -75,4 +124,16 @@ describe('OData Protocol', () => {
|
|||||||
{ ID: 271, title: 'Catweazle' },
|
{ ID: 271, title: 'Catweazle' },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('serves user info', async () => {
|
||||||
|
{
|
||||||
|
const { data } = await GET (`/user/me`)
|
||||||
|
expect(data).to.containSubset({ id: 'alice', locale:'en', tenant: null })
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const { data } = await GET (`/user/me`, {auth: { username: 'joe' }})
|
||||||
|
expect(data).to.containSubset({ id: 'joe', locale:'en', tenant: null })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const { resolve } = require('path')
|
|||||||
const verbose = process.env.CDS_TEST_VERBOSE
|
const verbose = process.env.CDS_TEST_VERBOSE
|
||||||
// ||true
|
// ||true
|
||||||
|
|
||||||
describe('Local NPM registry', () => {
|
describe('cap/samples - Local NPM registry', () => {
|
||||||
let registry
|
let registry
|
||||||
let axios
|
let axios
|
||||||
const cwd = resolve(__dirname, '..')
|
const cwd = resolve(__dirname, '..')
|
||||||
@@ -20,7 +20,7 @@ describe('Local NPM registry', () => {
|
|||||||
|
|
||||||
after(() => { registry.kill() })
|
after(() => { registry.kill() })
|
||||||
|
|
||||||
for (const mod of ['bookshop','fiori','orders','reviews']) {
|
for (const mod of ['bookshop', 'data-viewer', 'fiori','orders','reviews']) {
|
||||||
it(`should serve ${mod}`, async () => {
|
it(`should serve ${mod}`, async () => {
|
||||||
const resp = await axios.get(`/@capire/${mod}`)
|
const resp = await axios.get(`/@capire/${mod}`)
|
||||||
expect(resp.data).to.containSubset({name: `@capire/${mod}`, versions:{}})
|
expect(resp.data).to.containSubset({name: `@capire/${mod}`, versions:{}})
|
||||||
|
|||||||
Reference in New Issue
Block a user