Spring Cleaning → removing obsolete stuff, and moved non-app things to ./etc (#810)
* Remove obsolete stuff, and moved non-app things to ./etc * remove test * Update package-lock --------- Co-authored-by: Christian Georgi <christian.georgi@sap.com>
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
# Hello World Getting Started Sample
|
||||
|
||||
## Next Steps
|
||||
|
||||
- To run the JavaScript implementation, open a new terminal and run `cds watch`.
|
||||
- To run the TypeScript implementation, open a new terminal and run `cds-ts watch`.
|
||||
|
||||
Then call the service at: http://localhost:4004/say/hello(to='world')
|
||||
|
||||
## Learn More
|
||||
|
||||
Learn more about:
|
||||
|
||||
- [Hello World!](https://cap.cloud.sap/docs/get-started/hello-world)
|
||||
- [Using TypeScript](https://cap.cloud.sap/docs/node.js/typescript)
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "@capire/hello-world",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "npx jest --silent",
|
||||
"start": "cds-serve srv/world.cds",
|
||||
"start:ts": "cds-ts serve srv/world.cds"
|
||||
},
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=5.0.4"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
service say {
|
||||
function hello (to:String) returns String;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
module.exports = class say {
|
||||
hello(req) {
|
||||
let {to} = req.data
|
||||
if (to === 'me') to = require('os').userInfo().username
|
||||
return `Hello ${to}!`
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Request } from "@sap/cds"
|
||||
|
||||
module.exports = class say {
|
||||
hello(req: Request) {
|
||||
return `Hello ${req.data.to} from a TypeScript file!`
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
GET http://localhost:4004/odata/v4/say/hello
|
||||
###
|
||||
|
||||
GET http://localhost:4004/odata/v4/say/hello(to='me')
|
||||
###
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace sap.capire.media;
|
||||
|
||||
entity Media {
|
||||
|
||||
key id:Integer;
|
||||
@Core.MediaType: mediaType
|
||||
content : LargeBinary ;
|
||||
|
||||
@Core.IsMediaType: true
|
||||
mediaType : String;
|
||||
fileName : String;
|
||||
applicationName:String;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
using from './db/data-model';
|
||||
using from './srv/media-service';
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "@capire/media",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"lokijs": "^1.5.6"
|
||||
},
|
||||
"files": [
|
||||
"db",
|
||||
"srv",
|
||||
"index.cds"
|
||||
],
|
||||
"cds": {
|
||||
"requires": {
|
||||
"db": {
|
||||
"kind": "sql"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using { sap.capire.media as db } from '../db/data-model';
|
||||
namespace sap.capire.media;
|
||||
|
||||
@path: '/media-server'
|
||||
service MediaServer {
|
||||
entity Media as projection on db.Media ;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
const loki = require('lokijs')
|
||||
const db = new loki('DB')
|
||||
const mediaDB = db.addCollection('Media')
|
||||
const { Readable, PassThrough } = require('stream')
|
||||
|
||||
module.exports = srv => {
|
||||
srv.before('CREATE', 'Media', req => {
|
||||
const obj = mediaDB.insert({ media: '' })
|
||||
req.data.id = obj.$loki
|
||||
})
|
||||
|
||||
srv.on('UPDATE', 'Media', (req, next) => {
|
||||
const url = req.path
|
||||
if (url.includes('content')) {
|
||||
const id = req.data.id
|
||||
const obj = mediaDB.get(id)
|
||||
if (!obj) {
|
||||
req.reject(404, 'No record found for the ID')
|
||||
return
|
||||
}
|
||||
const stream = new PassThrough()
|
||||
const chunks = []
|
||||
stream.on('data', chunk => {
|
||||
chunks.push(chunk)
|
||||
})
|
||||
stream.on('end', () => {
|
||||
obj.media = Buffer.concat(chunks).toString('base64')
|
||||
mediaDB.update(obj)
|
||||
})
|
||||
req.data.content.pipe(stream)
|
||||
} else return next()
|
||||
})
|
||||
|
||||
srv.on('READ', 'Media', (req, next) => {
|
||||
const url = req.path
|
||||
if (url.includes('content')) {
|
||||
const id = req.data.id
|
||||
const mediaObj = mediaDB.get(id)
|
||||
if (!mediaObj) {
|
||||
req.reject(404, 'Media not found for the ID')
|
||||
return
|
||||
}
|
||||
const decodedMedia = Buffer.from(
|
||||
mediaObj.media.split(';base64,').pop(),
|
||||
'base64'
|
||||
)
|
||||
return _formatResult(decodedMedia)
|
||||
} else return next() //> delegate to next/default handlers
|
||||
})
|
||||
|
||||
srv.on('DELETE', 'Media', (req, next) => {
|
||||
const id = req.data.id
|
||||
mediaDB
|
||||
.chain()
|
||||
.find({ $loki: id })
|
||||
.remove()
|
||||
return next() //> delegate to next/default handlers
|
||||
})
|
||||
|
||||
function _formatResult (decodedMedia) {
|
||||
const readable = new Readable()
|
||||
const result = new Array()
|
||||
readable.push(decodedMedia)
|
||||
readable.push(null)
|
||||
result.push({ value: readable })
|
||||
return result
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 KiB |
@@ -1,35 +0,0 @@
|
||||
### Requires REST Client for VS Code
|
||||
### https://marketplace.visualstudio.com/items?itemName=humao.rest-client
|
||||
###
|
||||
@protocol = http
|
||||
@host = localhost
|
||||
@port = 4004
|
||||
### Read Pictures
|
||||
GET {{protocol}}://{{host}}:{{port}}/media-server/Media
|
||||
Authorization: Basic admin:
|
||||
|
||||
### Create Picture with mediatype
|
||||
POST {{protocol}}://{{host}}:{{port}}/media-server/Media
|
||||
Authorization: Basic admin:
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"id": 1,
|
||||
"mediaType": "image/png"
|
||||
}
|
||||
|
||||
### Upload Binary PNG
|
||||
PUT {{protocol}}://{{host}}:{{port}}/media-server/Media(1)/content
|
||||
Authorization: Basic admin:
|
||||
Content-Type: image/png
|
||||
|
||||
< ./Test.png
|
||||
|
||||
### Read Binary
|
||||
GET {{protocol}}://{{host}}:{{port}}/media-server/Media(1)/content
|
||||
Authorization: Basic admin:
|
||||
|
||||
### Delete Image
|
||||
DELETE {{protocol}}://{{host}}:{{port}}/media-server/Media(1)
|
||||
Authorization: Basic admin:
|
||||
49
package-lock.json
generated
49
package-lock.json
generated
@@ -1,24 +1,22 @@
|
||||
{
|
||||
"name": "@capire/samples",
|
||||
"version": "2.1.0",
|
||||
"version": "3.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@capire/samples",
|
||||
"version": "2.1.0",
|
||||
"version": "3.0.0",
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"workspaces": [
|
||||
"./bookshop",
|
||||
"./bookstore",
|
||||
"./common",
|
||||
"./data-viewer",
|
||||
"./fiori",
|
||||
"./hello",
|
||||
"./media",
|
||||
"./orders",
|
||||
"./loggers",
|
||||
"./reviews"
|
||||
"./reviews",
|
||||
"./etc/data-viewer",
|
||||
"./etc/loggers"
|
||||
],
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=8"
|
||||
@@ -68,10 +66,26 @@
|
||||
"data-viewer": {
|
||||
"name": "@capire/data-viewer",
|
||||
"version": "0.1.0",
|
||||
"extraneous": true,
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=5.0.4"
|
||||
}
|
||||
},
|
||||
"etc/data-viewer": {
|
||||
"name": "@capire/data-viewer",
|
||||
"version": "0.1.0",
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=5.0.4"
|
||||
}
|
||||
},
|
||||
"etc/loggers": {
|
||||
"name": "@capire/loggers",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=5.9",
|
||||
"express": "^4.17.1"
|
||||
}
|
||||
},
|
||||
"fiori": {
|
||||
"name": "@capire/fiori",
|
||||
"version": "1.0.0",
|
||||
@@ -88,6 +102,7 @@
|
||||
"hello": {
|
||||
"name": "@capire/hello-world",
|
||||
"version": "1.0.0",
|
||||
"extraneous": true,
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=5.0.4"
|
||||
}
|
||||
@@ -95,6 +110,7 @@
|
||||
"loggers": {
|
||||
"name": "@capire/loggers",
|
||||
"version": "1.0.0",
|
||||
"extraneous": true,
|
||||
"dependencies": {
|
||||
"@sap/cds": ">=5.9",
|
||||
"express": "^4.17.1"
|
||||
@@ -103,6 +119,7 @@
|
||||
"media": {
|
||||
"name": "@capire/media",
|
||||
"version": "1.0.0",
|
||||
"extraneous": true,
|
||||
"dependencies": {
|
||||
"lokijs": "^1.5.6"
|
||||
}
|
||||
@@ -176,23 +193,15 @@
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@capire/data-viewer": {
|
||||
"resolved": "data-viewer",
|
||||
"resolved": "etc/data-viewer",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@capire/fiori": {
|
||||
"resolved": "fiori",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@capire/hello-world": {
|
||||
"resolved": "hello",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@capire/loggers": {
|
||||
"resolved": "loggers",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@capire/media": {
|
||||
"resolved": "media",
|
||||
"resolved": "etc/loggers",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@capire/orders": {
|
||||
@@ -2176,12 +2185,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lokijs": {
|
||||
"version": "1.5.12",
|
||||
"resolved": "https://registry.npmjs.org/lokijs/-/lokijs-1.5.12.tgz",
|
||||
"integrity": "sha512-Q5ALD6JiS6xAUWCwX3taQmgwxyveCtIIuL08+ml0nHwT3k0S/GIFJN+Hd38b1qYIMaE5X++iqsqWVksz7SYW+Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/loupe": {
|
||||
"version": "2.3.7",
|
||||
"resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz",
|
||||
|
||||
16
package.json
16
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@capire/samples",
|
||||
"version": "2.1.0",
|
||||
"version": "3.0.0",
|
||||
"description": "A monorepo with several samples for CAP.",
|
||||
"repository": "https://github.com/sap-samples/cloud-cap-samples.git",
|
||||
"author": "daniel.hutzel@sap.com",
|
||||
@@ -11,13 +11,11 @@
|
||||
"./bookshop",
|
||||
"./bookstore",
|
||||
"./common",
|
||||
"./data-viewer",
|
||||
"./fiori",
|
||||
"./hello",
|
||||
"./media",
|
||||
"./orders",
|
||||
"./loggers",
|
||||
"./reviews"
|
||||
"./reviews",
|
||||
"./etc/data-viewer",
|
||||
"./etc/loggers"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@cap-js/cds-types": "^0",
|
||||
@@ -31,15 +29,11 @@
|
||||
},
|
||||
"scripts": {
|
||||
"bookshop": "cds watch bookshop",
|
||||
"start": "cds watch fiori",
|
||||
"fiori": "cds watch fiori",
|
||||
"hello": "cds watch hello",
|
||||
"media": "cds watch media",
|
||||
"lint": "eslint",
|
||||
"test": "npx jest --silent",
|
||||
"jest": "npx jest --silent",
|
||||
"mocha": "CDS_TEST_SILENT=y npx mocha",
|
||||
"test:hello": "cd hello && npm test"
|
||||
"mocha": "CDS_TEST_SILENT=y npx mocha"
|
||||
},
|
||||
"mocha": {
|
||||
"recursive": true,
|
||||
|
||||
10
samples.md
10
samples.md
@@ -6,12 +6,6 @@ Each sub directory essentially is an individual npm package arranged in an [all-
|
||||

|
||||
|
||||
|
||||
## [@capire/hello-world](hello)
|
||||
|
||||
- A simplistic [Hello World](https://cap.cloud.sap/docs/get-started/hello-world) service using [CDS](https://cap.cloud.sap/docs/cds/) and [cds.services](https://cap.cloud.sap/docs/node.js/api#services-api).
|
||||
- [Typescript support](https://cap.cloud.sap/docs/node.js/typescript)
|
||||
|
||||
|
||||
## [@capire/bookshop](bookshop)
|
||||
|
||||
- [Getting Started](https://cap.cloud.sap/docs/get-started/in-a-nutshell) with CAP, briefly introducing:
|
||||
@@ -60,10 +54,10 @@ Each sub directory essentially is an individual npm package arranged in an [all-
|
||||
- [@capire/reviews](reviews)
|
||||
- [@capire/orders](orders)
|
||||
- [@capire/common](common)
|
||||
- [@capire/data-viewer](data-viewer)
|
||||
- [@capire/data-viewer](etc/data-viewer)
|
||||
- [The Vue.js app](bookshop/app/vue) imported from `bookshop` is served as well
|
||||
- [The Vue.js app](reviews/app/vue) imported from `reviews` is served as well
|
||||
- [The Vue.js app](data-viewer/app/data) imported from `data-viewer` is served as well
|
||||
- [The Vue.js app](etc/data-viewer/app/data) imported from `data-viewer` is served as well
|
||||
- [The Fiori app](orders/app) imported from `orders` is served as well
|
||||
- [OpenAPI export + Swagger UI](https://cap.cloud.sap/docs/advanced/openapi)
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
const cds = require('@sap/cds')
|
||||
|
||||
describe('cap/samples - Hello world!', () => {
|
||||
|
||||
const { GET, expect } = cds.test (__dirname+'/../hello')
|
||||
|
||||
it('should say hello with class impl', async () => {
|
||||
const {data} = await GET `/odata/v4/say/hello(to='world')`
|
||||
expect(data.value).to.eql('Hello world!')
|
||||
})
|
||||
|
||||
it('should say hello with another impl', async () => {
|
||||
await cds.serve('say').from(cds.model)
|
||||
.at('/say-again').in(cds.app)
|
||||
.with(srv => {
|
||||
srv.on('hello', (req) => `Hello again ${req.data.to}!`)
|
||||
})
|
||||
const {data} = await GET `/say-again/hello(to='world')`
|
||||
expect(data.value).to.eql('Hello again world!')
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user