Git Product home page Git Product logo

cap-community's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cap-community's Issues

Cannot read property 'remoteAddress' of undefined

Hello CAP Enthusiasts,

during local testing I'm facing the following issue:

In the test project gregorwolf/bookshop-demo I've defined two users in .cdsrc.json: admin and littleadmin. Only admin has the scope roleadmin which is used to restrict the access to the entity Roles of the admin-service.cds.

To replicate the issue please do the following:

  1. Start the app with npm run build:deploy:startv2
  2. Open http://localhost:4004/app/fiori.html in a browser
  3. Click on the tile Approvals in the Group OData V4
  4. You should be prompted for a username and passwort
  5. Enter littleadmin as the username. The pasword can be left empty
  6. You should get a list of items to be approved
  7. Now navigate back to the homepage
  8. Click on the tile Role in the Group OData V4
  9. Now the backend will crash with the following error message:
[2020-01-19T08:10:27.442Z | ERROR | 1427824]: Cannot read property 'remoteAddress' of undefined
/Users/gwolf/Documents/Projects/cap/bookshop-demo/node_modules/@sap/cds-services/lib/adapter/odata-v4/handlers/error.js:41
        throw err
        ^

TypeError: Cannot read property 'remoteAddress' of undefined
    at getIpFromRequest (/Users/gwolf/Documents/Projects/cap/bookshop-demo/node_modules/@sap/cds-services/lib/services/utils/clientFromRequest.js:35:25)

The root cause is that in the getIpFromRequest method the variable req.connection.remoteAddress isn't checked for undefined.

Looking forward for a fix.

Best regards
Gregor

CAP insertable service error with DB defaults

Hi,

I've created a new cds project with cds init and created a db/ and srv/ service.

The db service is using a not null field with a default. The service is a projection with with Capabilities annotation;

db/

entity Test { 
  key ID : UUID; 
  VAL: Integer default 12 not null 
}

srv/

@Capabilities: { Insertable: true, Updatable: false, Deletable:false }
entity Test as projection on my.Test; 

When doing a POST to create a new entry with only the ID field supplied I get the following error:

{
 "error": {
 "code": null,
 "message": "An error occurred during serialization of the entity. Not nullable value for 'VAL' must not be null."
 }
}

The insert did work though as it is in the database. Secondly if I set Updatable to true the service works normally and returns the created entity without an error.

/D

SQLITE_ERROR due to Element named "Group"

Hello CAP Team,

in the Branch real-b1-metadata of sap-business-one-odata-cap I've adjusted the metadata to avoid the issue #59. But now a new error occurs:

[Error: SQLITE_ERROR: near "Group": syntax error] {
  errno: 1,
  code: 'SQLITE_ERROR',
  query: 'CREATE TABLE SAPB1_AssetDepreciationGroups (\n' +
    '  Code NCLOB NOT NULL,\n' +
    '  Description NCLOB,\n' +
    '  Group NCLOB,\n' +
    '  Items_ItemCode NCLOB,\n' +
    '  PRIMARY KEY(Code)\n' +
    ')',
  severity: 'Error'
}

this is the statement that cds watch tries to execute:

CREATE TABLE SAPB1_AssetDepreciationGroups (
  Code NCLOB NOT NULL,
  Description NCLOB,
  Group NCLOB,
  Items_ItemCode NCLOB,
  PRIMARY KEY(Code)
)

This issue is cased by the fact that Group is a SQLite Keyword. Is there any workaround planned for this issue? As I'm using an external service model I have no influence on the naming.

Best regards
Gregor

invalid column name: B.ID: line 1 col 423 (at pos 422)

Hello SAP CAP Experts,

currently I'm adding a functionality to maintain application specific Roles. For that I've created the entities you can see starting at:

https://github.com/gregorwolf/bookshop-nodejs/blob/master/db/data-model.cds#L36

When I run this applicaiton locally using sqlite, everything is fine and I can call the test

http://localhost:4004/v2/admin/Role?$expand=BusinessObjects,Users

without any issues. But when we deploy this applicaiton on our HANA system and call the same endpoint with the same parameters, then the following error is issued:

[2019-11-26T13:04:05.308Z | ERROR | 1452901]: invalid column name: B.ID: line 1 col 423 (at pos 422)

When I set the environment variable DEBUG=true I can see the SQL SELECT statements that where generated:

[cql] - SELECT
b.b_ID AS "b_ID",
b.b_modifiedAt AS "b_modifiedAt",
b.b_createdAt AS "b_createdAt",
b.b_createdBy AS "b_createdBy",
b.b_modifiedBy AS "b_modifiedBy",
b.b_parent_ID AS "b_parent_ID",
b.b_BusinessObject_ID AS "b_BusinessObject_ID",
b.IsActiveEntity AS "IsActiveEntity",
FALSE AS "HasActiveEntity",
CASE WHEN (
SELECT
1
FROM
AdminService_Role_BusinessObjects_drafts
WHERE
AdminService_Role_BusinessObjects_drafts.ID = b.ID ) IS NOT NULL THEN TRUE
ELSE FALSE
END AS "HasDraftEntity",
filterExpand_ID AS "filterExpand_ID",
b.filterExpand_IsActiveEntity AS "filterExpand_IsActiveEntity"
FROM
(
SELECT
TRUE AS IsActiveEntity,
filterExpand.ID AS filterExpand_ID,
TRUE AS filterExpand_IsActiveEntity,
b.ID AS b_ID,
b.modifiedAt AS b_modifiedAt,
b.createdAt AS b_createdAt,
b.createdBy AS b_createdBy,
b.modifiedBy AS b_modifiedBy,
b.parent_ID AS b_parent_ID,
b.BusinessObject_ID AS b_BusinessObject_ID,
TRUE AS b_IsActiveEntity,
FALSE AS b_HasActiveEntity,
CASE WHEN (
SELECT
1
FROM
AdminService_Role_BusinessObjects_drafts
WHERE
AdminService_Role_BusinessObjects_drafts.ID = b.ID ) IS NOT NULL THEN TRUE
ELSE FALSE
END AS HasDraftEntity,
NULL AS b_DraftAdministrativeData_DraftUUID,
ROW_NUMBER ( ) OVER ( PARTITION BY b.parent_ID ) AS rowNumber
FROM
AdminService_Role_BusinessObjects b
INNER JOIN (
SELECT
DISTINCT a.ID AS ID
FROM
AdminService_Role a
LIMIT 1000) filterExpand ON
( filterExpand.ID = b.parent_ID )) b
WHERE
b.rowNumber > ?
AND b.rowNumber < ? [ 0, 101 ]
[cql] - SELECT c.c_ID AS "c_ID", c.c_modifiedAt AS "c_modifiedAt", c.c_createdAt AS "c_createdAt", c.c_createdBy AS "c_createdBy", c.c_modifiedBy AS "c_modifiedBy", c.c_parent_ID AS "c_parent_ID", c.c_user_username AS "c_user_username", c.IsActiveEntity AS "IsActiveEntity", false AS "HasActiveEntity", CASE WHEN ( SELECT 1 FROM AdminService_Role_Users_drafts WHERE AdminService_Role_Users_drafts.ID = c.ID ) IS NOT NULL THEN TRUE ELSE FALSE END AS "HasDraftEntity", filterExpand_ID AS "filterExpand_ID", c.filterExpand_IsActiveEntity AS "filterExpand_IsActiveEntity" FROM (SELECT true AS IsActiveEntity, filterExpand.ID AS filterExpand_ID, true AS filterExpand_IsActiveEntity, c.ID AS c_ID, c.modifiedAt AS c_modifiedAt, c.createdAt AS c_createdAt, c.createdBy AS c_createdBy, c.modifiedBy AS c_modifiedBy, c.parent_ID AS c_parent_ID, c.user_username AS c_user_username, true AS c_IsActiveEntity, false AS c_HasActiveEntity, CASE WHEN ( SELECT 1 FROM AdminService_Role_Users_drafts WHERE AdminService_Role_Users_drafts.ID = c.ID ) IS NOT NULL THEN TRUE ELSE FALSE END AS HasDraftEntity, null AS c_DraftAdministrativeData_DraftUUID, ROW_NUMBER ( ) OVER ( PARTITION BY c.parent_ID ) AS rowNumber FROM AdminService_Role_Users c INNER JOIN (SELECT DISTINCT a.ID AS ID FROM AdminService_Role a LIMIT 1000) filterExpand ON ( filterExpand.ID = c.parent_ID )) c WHERE c.rowNumber > ? AND c.rowNumber < ? [ 0, 101 ]
[cql] - SELECT a.ID AS "a_ID", a.modifiedAt AS "a_modifiedAt", a.createdAt AS "a_createdAt", a.createdBy AS "a_createdBy", a.modifiedBy AS "a_modifiedBy", a.rolename AS "a_rolename", a.description AS "a_description", true AS "IsActiveEntity", false AS "HasActiveEntity", null AS "HasDraftEntity", null AS "DraftAdministrativeData_DraftUUID" FROM AdminService_Role a LIMIT 1000 []
[cql] - release connection

I think the issue is in the line:

AdminService_Role_BusinessObjects_drafts.ID = b.ID ) IS NOT NULL THEN TRUE

which works when changed to:

AdminService_Role_BusinessObjects_drafts.ID = b.b_ID ) IS NOT NULL THEN TRUE

Best regards
Gregor Wolf

P.S.: This issue is also filed as an SAP incident with the number 688930 / 2019

$expand not working for mocked service

Hello CAP Experts,

in the Project S/4HANA Business Partner Mock Service I've implemented a mock based on the documentation at Mocking App Services. As the used Business Partner has quite some Associations. My expectation was that also they should also work out of the box. Unfortunately as you can proof with the REST Client Extension for Visual Studio Code test script in srv/test/test.http the expanded entities stay empty even as the test data provides a consistent set for the Association.

Looking forward for some insight.

Best regards
Gregor

CDS 3.31.2 does not detect duplicate definition of an artefact as type and entity

Hello SAP CAP Team,

via the Incident 172922 / 2020 @David-Kunz already verified that the CDS compiler in with @sap/cds 3.31.2 does not recognise a duplicate definition of an artefact. In the commit gregorwolf/bookshop-demo@34c4323 I've added an example for the type User and entity User that works with 3.21.3. But as soon as I sue 3.31.2 the following error occurs at startup:

(node:91560) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '_target' of undefined
    at ApplicationService.on (/Users/gwolf/Documents/Projects/cap/bookshop-demo/node_modules/@sap/cds-services/lib/services/Service.js:494:42)
    at ApplicationService.module.exports (/Users/gwolf/Documents/Projects/cap/bookshop-demo/srv/admin-service.js:69:6)
    at ApplicationService.impl (/Users/gwolf/Documents/Projects/cap/bookshop-demo/node_modules/@sap/cds-services/lib/services/Service.js:244:32)
    at loaded.then.csn (/Users/gwolf/Documents/Projects/cap/bookshop-demo/node_modules/@sap/cds/lib/srv/serve.js:67:29)
(node:91560) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:91560) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Best regards
Gregor

Documentation: Spelling Mistake in Defining Services

Small spelling mistake in the documentation of Defining Services in the example under All-in-one Definitions. (providing-services.html)

entity LibraryService {
enity Books {

Admittedly not world changing, but caught my eye..

xs-security.json contains "[32m" and "[39m" when using compile --to xsuaa

When I upgrade my example project bookshop-nodejs to @sap/cds version 3.31.1:

cds -v
@sap/cds: 3.31.1
@sap/cds-compiler: 1.23.2
@sap/cds-foss: 1.1.0
@sap/cds-messaging: 1.7.0
@sap/cds-reflect: 2.10.1
@sap/cds-rest: 1.5.1
@sap/cds-services: 1.25.1
Node.js: v12.16.1
home: /Users/gwolf/Documents/Projects/cap/bookshop-nodejs/node_modules/@sap/cds

and then run the command:

cds compile srv/ --to xsuaa > xs-security.json

the generated xs-security.json looks like this:

{
  xsappname: �[32m'bookshop-nodejs'�[39m,
  �[32m'tenant-mode'�[39m: �[32m'dedicated'�[39m,
  scopes: [ { name: �[32m'$XSAPPNAME.admin'�[39m, description: �[32m'admin'�[39m } ],
  attributes: [],
  �[32m'role-templates'�[39m: [
    {
      name: �[32m'admin'�[39m,
      description: �[32m'generated'�[39m,
      �[32m'scope-references'�[39m: [ �[32m'$XSAPPNAME.admin'�[39m ],
      �[32m'attribute-references'�[39m: []
    }
  ]
}

with 3.21.3 it was generated like this:

{
  "xsappname": "bookshop-nodejs",
  "tenant-mode": "dedicated",
  "scopes": [
    {
      "name": "$XSAPPNAME.admin",
      "description": "admin"
    }
  ],
  "attributes": [],
  "role-templates": [
    {
      "name": "admin",
      "description": "generated",
      "scope-references": [
        "$XSAPPNAME.admin"
      ],
      "attribute-references": []
    }
  ]
}

Installing @sap/[email protected] fails with npm but works with yarn

Hello CAP Team,

installing @sap/[email protected] currently fails when I try with:

npm i -g @sap/cds-dk  

With the following error messages:

npm i -g @sap/cds-dk        
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! code EINTEGRITY
npm ERR! sha512-uHdbvD/2MqXH8suqHwlk2BgUxvZaxYiNLkYVRVPZYwQ2mNgnVDyvwKGqdQQ8k56Le+dnlJHzeorhciP3TuqXXw== integrity checksum failed when using sha512: wanted sha512-uHdbvD/2MqXH8suqHwlk2BgUxvZaxYiNLkYVRVPZYwQ2mNgnVDyvwKGqdQQ8k56Le+dnlJHzeorhciP3TuqXXw== but got sha512-s6giiC7whCO6gnVc9cYSHKCSPv704q2N132r8MQA/Yt3HD1+aAYqqqyabpd5BAasVturVfhNv2gcfVaL0DtrpQ==. (14858 bytes)
npm WARN tarball tarball data for @sap/[email protected] (sha512-hvdF9Lj466R3lnvmBdYk+SbAhWDSJDKsGxF8oE1jET/VJHeZClhx+ZxEVAVDOo+xMgWQXjUdvWMTRnUARXt/WA==) seems to be corrupted. Trying one more time.
npm ERR! code EINTEGRITY
npm ERR! sha512-fcCedZ/W92oxMzNI2e8c0jhr9Kh/Q8o5ELj81NPyo+Xm9Q4lIEzikgZ6a/Ci9XrH/f+CGOqDL4DXS+AoYww88Q== integrity checksum failed when using sha512: wanted sha512-fcCedZ/W92oxMzNI2e8c0jhr9Kh/Q8o5ELj81NPyo+Xm9Q4lIEzikgZ6a/Ci9XrH/f+CGOqDL4DXS+AoYww88Q== but got sha512-NtKDRX08NLXVqnvCkxK8WaJajDYoR8FH/C0c2AUw5DPfA9peNK5bYqRpdJRC7D398fIpfSCwh4a6G1Y0oH9nnQ==. (17633 bytes)
npm WARN tarball tarball data for @sap/[email protected] (sha512-hVjuhC0J5tE180wj+yzRImooB9yoJ81qa0kqcQUdx2qWgBci0HP4s9QoQa5CaSgfJP0fwLgvdVR9SpvqkHtU1w==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-sNLSL7Hoy5Z/Y5jlMRO12t8FZhbLEKsj9ySi7/40+xR2LqPbQPR8z5kzD5NSJImeADpiPbKulwU3ksOpJCH3Sg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-hvdF9Lj466R3lnvmBdYk+SbAhWDSJDKsGxF8oE1jET/VJHeZClhx+ZxEVAVDOo+xMgWQXjUdvWMTRnUARXt/WA==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-sNLSL7Hoy5Z/Y5jlMRO12t8FZhbLEKsj9ySi7/40+xR2LqPbQPR8z5kzD5NSJImeADpiPbKulwU3ksOpJCH3Sg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-hVjuhC0J5tE180wj+yzRImooB9yoJ81qa0kqcQUdx2qWgBci0HP4s9QoQa5CaSgfJP0fwLgvdVR9SpvqkHtU1w==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-sNLSL7Hoy5Z/Y5jlMRO12t8FZhbLEKsj9ySi7/40+xR2LqPbQPR8z5kzD5NSJImeADpiPbKulwU3ksOpJCH3Sg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-sNLSL7Hoy5Z/Y5jlMRO12t8FZhbLEKsj9ySi7/40+xR2LqPbQPR8z5kzD5NSJImeADpiPbKulwU3ksOpJCH3Sg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-2aNbWfKo+DAb0ub8VXBFVkWDH55jc2ncdjTTz7x/xuajtSbfoTLGS5686vUN2Q8M4x9gXkSVSahDFsYLC+7lmg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-qjYQZWj/b7agKL/lUV1llx16ux37BNUz5bzC375Hr4H/DYLluYzWIKteMqcGpTuB+spI8eM4myYgt7YFFe0PLQ==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-gwDCATyTao2+K050KHbkmJjSeL7684SfF33/7C7cYWJLeOi68WY7L9PXA9QSAzPtqjfDaiGSer8Lm7Ug6WeCYA==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-okh9SxWtsNCWmkTEC8UTNdywDGw8ppS7wOzOcl2pN4SkrAglegeOEQhgQMFB3NJLgXEdGpRvR1MuRQZ7BSi+XQ==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-G3PkF/KiCiYEOcTMpWplAYXAX61Iwf9EDjfHCsn5HoPKlL6Eh0+pZiMot7Yy/x4VqUWAhMUwOLF8CwMYaIpKVQ==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-2aNbWfKo+DAb0ub8VXBFVkWDH55jc2ncdjTTz7x/xuajtSbfoTLGS5686vUN2Q8M4x9gXkSVSahDFsYLC+7lmg==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-qjYQZWj/b7agKL/lUV1llx16ux37BNUz5bzC375Hr4H/DYLluYzWIKteMqcGpTuB+spI8eM4myYgt7YFFe0PLQ==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-gwDCATyTao2+K050KHbkmJjSeL7684SfF33/7C7cYWJLeOi68WY7L9PXA9QSAzPtqjfDaiGSer8Lm7Ug6WeCYA==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-okh9SxWtsNCWmkTEC8UTNdywDGw8ppS7wOzOcl2pN4SkrAglegeOEQhgQMFB3NJLgXEdGpRvR1MuRQZ7BSi+XQ==) seems to be corrupted. Trying one more time.
npm WARN tarball tarball data for @sap/[email protected] (sha512-G3PkF/KiCiYEOcTMpWplAYXAX61Iwf9EDjfHCsn5HoPKlL6Eh0+pZiMot7Yy/x4VqUWAhMUwOLF8CwMYaIpKVQ==) seems to be corrupted. Trying one more time.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/gwolf/.npm/_logs/2020-03-02T12_47_16_670Z-debug.log

Using

yarn global add @sap/cds-dk

Simply works.

Best regards
Gregor

Experimental Stuff - OpenAPI

Hi all, this is Daniel.
As already mentioned on Twitter, I'd like to share a piece of old code I did some months ago in a experimental section (no warranties, no liability, etc.)...

It's a very simplistic and experimental CSN-to-OpenAPI (actually just the JSON Schema part) converter.

const cds = require ('@sap/cds')
const options = {
    skip_foreign_keys: true,
    // simple_refs: true,
}

const { Association, Composition, entity, array, struct, string } = cds.builtin.classes
const TypeMappings = {
	number: { type: 'number', format: 'double' },
	boolean: { type: 'boolean', },
	string: { type: 'string', },
	UUID: { type: 'string', format: 'uuid' },
	Integer16: { type: 'integer', format: 'int16' },
	Integer32: { type: 'integer', format: 'int32' },
	Integer64: { type: 'integer', format: 'int64' },
	Float: { type: 'number', format: 'float' },
	Date: { type: 'string', format: 'date' },
	DateTime: { type: 'string', format: 'date-time' },
	Binary: { type: 'string', format: 'binary' },
}; for (let each in TypeMappings) {
    cds.builtin.types[each]._schema = TypeMappings[each]
}

module.exports = (csn, service) => {


    let m = cds.linked (csn)
    const srv = service ? m.all('service').find (d => d.name.includes(service)) : m.find ('service')
    if (srv)  m = cds.linked (cds.compile.for.odata(csn))
    const namespace = srv ? srv.name : m.namespace || ''
    const visited = {}

    const targets = {}, types = { __proto__: targets }

    const entities = m.entities (namespace)
    for (let e in entities) {
        targets[e] = {}
        targets[e] = _define (entities[e])
    }
    return {
        openapi: '3.0.0', info: {
            title: namespace || 'all entities',
            description: `generated from ${m._sources[0]}`,
            version: '0.0.0'
        },
        components: {
            schemas: Object.assign(targets,types)
        },
        paths: {},
    }

    function _define (d) {
        if (d.name in visited) return; else visited[d.name] = true
        if (d.type && !(d.type in cds.builtin.types))  return $ref2(d.type)
        if (d instanceof Composition)  return _Composition(d)
        if (d instanceof Association)  return _Association(d)
        if (d instanceof entity)  return _entity(d)
        if (d instanceof struct)  return _struct(d)
        if (d instanceof array)  return _array(d)
        if (d instanceof string)  return _string(d)
        else  return _any(d)
    }

    function _entity (def) {
        return {properties: _properties4 (def.elements) }
    }

    function _any (def) {
        const x = Object.assign ({}, def._schema)
        const f = def['@format']; if (f) x.format = f
        return x
    }

    function _array (def) {
        const {type} = def.items
        return $arrayOf (_define (def.items))
    }

    function _string (def) {
        let s = _any(def); if (s.$ref) return s
        if (def.length) s.maxLength = def.length
        if (def.enum) s.enum = Object.keys (def.enum)
        return s
    }

    function _struct (def) {
        return { properties: _properties4(def.elements) }
    }

    function _properties4 (elements, filter=()=>true) {
        const properties = {}
        for (let each in elements) {
            if (options.skip_foreign_keys) {
                const [ head, tail ] = each.split('_')
                if (tail && elements[head] instanceof Association)  continue
            }
            const e = elements[each]; if (!filter(e))  continue
            const x = _define(e); if (!x) continue
            const d = e['@description'];  if(d && !d.startsWith('{i18n>')) x.description = d
            properties[each] = x
        }
        return properties
    }

    function _Association (a) {
        let spec = $ref2 (a.target)
        if (options.simple_refs) {
            const keys = Object.keys(a._target.keys)
            if (keys.length == 1) spec = {oneOf:[ spec, {$ref: `${spec.$ref}/properties/${keys[0]}`} ]}
        }
        if (a.is2many) spec = $arrayOf (spec)
        return spec
    }

    function _Composition (a) {
        if (a.is2many)  return $arrayOf ($ref2 (a.target))
        else  return $ref2 (a.target)
    }

    function $ref2 (type, def) {
        const name = _name4 (type)
        if (!types[name])  types[name] = def || _define (m.definitions[type], name)
        return { $ref: `#/components/schemas/${name}` }
    }

    function $arrayOf (items) {
        return { type:'array', items }
    }

    function _name4 (type) {
        return type.startsWith(namespace+'.') ? type.slice (namespace.length+1) : type
    }

}


if (!module.parent) {

    const [,, model ] = process.argv
    if (!model)  return console.error ('Please specify a cds model to process')
    cds.compile.to.swgr = module.exports

    cds.load (model)
    .then (cds.compile.to.swgr)
    .then (cds.compile.to.yml)
    .then (console.log)
    .catch (console.error)
}

For example, use that in the samples as follows:

node 2swgr.js packages/bookshop/srv/admin-service.cds

That would spit out this:

openapi: 3.0.0
info: 
  title: AdminService
  description: generated from /Users/daniel/cap/samples/packages/bookshop/srv/admin-service.cds
  version: 0.0.0
components: 
  schemas: 
    Authors: 
      properties: 
        modifiedAt: {type: string, format: date-time}
        createdAt: {type: string, format: date-time}
        createdBy: {type: string, maxLength: 255}
        modifiedBy: {type: string, maxLength: 255}
        ID: {type: number, format: double}
        name: {type: string, maxLength: 111}
        dateOfBirth: {type: string, format: date}
        dateOfDeath: {type: string, format: date}
        placeOfBirth: {type: string}
        placeOfDeath: {type: string}
        books: {type: array, items: {$ref: "#/components/schemas/Books"}}
    Books: 
      properties: 
        title: {type: string, maxLength: 111}
        descr: {type: string, maxLength: 1111}
        author: {$ref: "#/components/schemas/Authors"}
        stock: {type: number, format: double}
        price: {type: number, format: double}
        currency: {$ref: "#/components/schemas/Currencies"}
    Books_texts: {properties: {}}
    Currencies: 
      properties: 
        code: {type: string, maxLength: 3}
        symbol: {type: string, maxLength: 5}
        texts: {type: array, items: {$ref: "#/components/schemas/Currencies_texts"}}
        localized: {$ref: "#/components/schemas/Currencies_texts"}
    Currencies_texts: {properties: {locale: {type: string, maxLength: 5}}}
    DraftAdministrativeData: 
      properties: 
        DraftUUID: {type: string, format: uuid}
        CreationDateTime: {}
        CreatedByUser: {type: string, maxLength: 256}
        DraftIsCreatedByMe: {type: boolean}
        LastChangeDateTime: {}
        LastChangedByUser: {type: string, maxLength: 256}
        InProcessByUser: {type: string, maxLength: 256}
        DraftIsProcessedByMe: {type: boolean}
    OrderItems: 
      properties: 
        parent: {$ref: "#/components/schemas/Orders"}
        book: {$ref: "#/components/schemas/Books"}
        amount: {type: number, format: double}
        netAmount: {type: number, format: double}
    Orders: 
      properties: 
        OrderNo: {type: string}
        Items: {type: array, items: {$ref: "#/components/schemas/OrderItems"}}
        total: {type: number, format: double}
        IsActiveEntity: {type: boolean}
        HasActiveEntity: {type: boolean}
        HasDraftEntity: {type: boolean}
        DraftAdministrativeData: {$ref: "#/components/schemas/DraftAdministrativeData"}
        SiblingEntity: {$ref: "#/components/schemas/Orders"}
paths: {}

Update virtual and @readonly fields

Not sure whether it is a bug or a feature: When I'm sending PUT requests to update virtual fields or fields annotated with @readonly, updating is not happening (correct!), but the response status is 200 OK. So, the http client gets no indication that he is trying to work against the model. (cds version 3.31.1 on Node.js).

I would consider this to be an error, but I don't know what others think about it ... ?

Klaus

Entities available without authentication using non-existing URLs

Hello,

I have a service deployed on CF using @(requires: 'authenticated-user'). Calling the service directly without app router (/myservice/myentityset) results in an unauthorized error, which is what I expect. Now the security issue: If I add another path in the URL the service is callable without authentication (e.g. /NONEXISTINGPATH/myservice/myentityset). This is a severe security issue!

Thanks and best regards,
Thorsten

Adding SAP Business One EDMX File causes [ERROR] Dubious entity or type without non-virtual elements

Hello CAP Team,

I'm trying to build a CAP layer on top of the SAP Business One OData API's. To try that out I've created a new CAP project and used the new cool functionality of Integrate and Mashup with cds watch. But unfortunately the drag & drop of the SAP Business One EDMX File (Orders) causes this issue:

[ERROR] srv/external/Orders.csn:28747: Dubious entity or type without non-virtual elements
[ERROR] srv/external/Orders.csn:30632: Dubious entity or type without non-virtual elements
[ERROR] srv/external/Orders.csn:35798: Dubious entity or type without non-virtual elements
[ERROR] srv/external/Orders.csn:37793: Dubious entity or type without non-virtual elements

This are the elements in order of occurence:

"SAPB1.RclRecurringExecutionParams": {
  "kind": "type",
  "elements": {}
},

"SAPB1.AlertManagementDocument": {
  "kind": "type",
  "elements": {}
},

"SAPB1.MaterialRevaluationFIFO": {
  "kind": "type",
  "elements": {}
},

"SAPB1.ApprovalTemplateDocument": {
  "kind": "type",
  "elements": {}
},

The question is now is that an issue with the cds EDMX to CSN converter or an issue with the EDMX file itself. To make this error easy to reproduce I've created the repository sap-business-one-odata-cap.

Looking forward for your input.

CU
Gregor

Restrict with user attribute does not work with mock user

Hi,

We have tried out the mock user features for local development.

I have a mock user looking like this:
"users": { "koray": { "roles": [ "qperiordemorole" ], "userAttributes": { "country": "CH" } } }
"Requires" on service level works fine using this mock user
service CatalogService @(requires : 'qperiordemorole') {
Only with user "koray" I can call the entities from the service.
But if I want to make a restriction like this:
entity DVDs @readonly @(restrict : [{ grant : 'READ', to : 'qperiordemorole', where : 'country = $user.country' }]) as projection on qperiordemo.DVDs;
I still get all items from the entity. Not only "CH" entries. If I deploy the solution on CF the restriction works fine. So I thought this should be a bug for mock users + restriction usage.
Regards,
Koray

Build options not working

I'm using cds-dk 1.8.0 or 1.7.1 on Windows 10. I've found that most of the build options described by cds help build are not working anymore. Example:

>> cds build --log-level info
[ERROR] invalid option: --log-level
    at Object.exports.parseArgs (C:\Users\\AppData\Roaming\npm\node_modules\@sap\cds-dk\node_modules\@sap\cds\bin\utils\cli.js:46:11)
    at Module.exports (C:\Users\\AppData\Roaming\npm\node_modules\@sap\cds-dk\node_modules\@sap\cds\bin\cds.js:43:53)
    at Object.<anonymous> (C:\Users\\AppData\Roaming\npm\node_modules\@sap\cds-dk\bin\cds.js:32:10)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
>>

SQLite Expanded Filter Query Error

Hi,

Using SQLite, it is not possible to filter on expanded entities.

Example, clone this repo and cd examples/computed-field && npm i && DEBUG=true cds run --in-memory.

Books is associated to authors, so performing query http://localhost:4004/catalog/Books?$expand=author&$filter=author/name eq 'Emily Bronte' is expected to return the list of books by Emily Bronte.

However when running this on SQLite, an error is returned instead:

GET /catalog/Books?$expand=author&$filter=author/name%20eq%20%27Emily%20Bronte%27
[cql] - acquire connection
[cql] - SELECT a.ID AS "a_ID", a.title AS "a_title", a.stock AS "a_stock", a.author_ID AS "a_author_ID", b.ID AS "b_ID", b.name AS "b_name", b.numberOfBooks AS "b_numberOfBooks" FROM CatalogService_Books a LEFT JOIN CatalogService_Authors b ON ( b.ID = a.author_ID ) WHERE author.name = ? LIMIT 1000 [ 'Emily Bronte' ]
[cql] - release connection
[2019-12-30T15:08:11.663Z | ERROR | 1070439]: SQLITE_ERROR: no such column: author.name

E.g.
image

When running on a HANA db, a query with a filter on the expanded entity works.

Oli

@odata.draft.enabled - Error "The requested resource is not concurrent" with OData V2 and SAPUI5 1.60

Hello CAP Community,

due to the limitations of SAPUI5 Fiori Elements when using OData V4 we are using OData V2 created by the @sap/cds-odata-v2-adapter-proxy module. Unfortunately there is an error message when creating a new entry in a draft enabled entity. As soon as I leave the first field after entering some data the save draft is triggered. During this the following error occurs:

"The requested resource is not concurrent"

To make it easy to replicate the issue I've created the entity Approval and a Fiori Elements app that can be started via the configured launchpad. Simply clone:

https://github.com/gregorwolf/bookshop-demo

then run:

npm run setup
npm run startv2

and open http://localhost:4004/fiori-ui5-1.60.12.html. You should see the tiles Approvals in the OData V2 and V4 group. Test it by creating a new entry.

It seems that this is a SAPUI5 related issue as it doesn't occur when using this version:

SAPUI5 1.71.2 (built at 2019/10/21 11:20h)

Best regards
Gregor

Process media resources as multipart/form-data in OData v4 as sent by sap.ui.unified.FileUploader

Hello UI5 Experts,

in addition to the issue #20 there is also a problem when using the OData v4 endpoint from an SAPUI5 UI. The control sap.ui.unified.FileUploader uses a HTTP POST and multipart/form-data to upload the file. To switch to the required PUT operation as described here I've used the a CustomFileUploader from Arindam Seth. But also this one uses multipart/form-data. As CAP and UI5 are both created by SAP I would expect that both work together smoothly.

You can replicate the issue by using my example project that can be found at:

https://github.com/gregorwolf/cap-community/tree/master/examples/media-handling

you can get it running by using:

npm run build
npm run deploy
npm run start

Now open http://localhost:4004/ and try to upload a png file. I.e. the one from the srv/tests folder of the project.

After the upload the picture should be displayed in the list below the field. But you will only see a GUID. That is caused due to to fact that simply all body data is stored without parsing. When you run the tests in srv/tests/media.http with the VS Code REST Client you will see the uploaded picture.

Best regards
Gregor

Documentation still mentions Eclipse 2019-09 but 2019-12 is already supported

Hello SAP CAP Documentation Team,

in the section Add the SAP Cloud Business Application Tools for Eclipse of the page Java > Getting Started the URL mentioned there is https://tools.hana.ondemand.com/2019-09/. But when I check https://tools.hana.ondemand.com/#cloud then I see also https://tools.hana.ondemand.com/2019-12/. So maybe it's better to add a link to https://tools.hana.ondemand.com/#cloud instead of updating the documentation all 3 month.

Best regards
Gregor

Deep insert with only child data not possible in combination with jest/supertest and cds 3.21.3

We're using Jest and supertest to unit test our cds-based endpoints. While upgrading from @sap/cds 3.18.x to 3.21.3 our tests started to break on a deep insert.

I've been able to reproduce the issue in an isolated scenario here: https://github.com/bvmeggelen/cds-jest-supertest-use-case-1.

Basically, when trying to deep insert without setting an additional field on the same level, the test breaks. However, using Postman and the same example data, it works just fine.

The following example JSON breaks the test:
{ "child": [ { "key": "value" } ] }

However, when using this it works as expected:
{ "some-field": "some-value", "child": [ { "key": "value" } ] }

Please see the referred git repository for a full reproducible example.

Documentation: Spelling Mistake in Generic Providers

Small spelling mistake in the documentation of Generic Providers in the section With Order By in Entity Definition

Now, assumed we might want to definde a default order

Admittedly not world changing, but caught my eye..

Data type Decimal not validated completely?

I'm not sure if it's a bug, or a feature ;)
I'm using the data type Decimal(9,2). I'm filling data into sqlite using a csv-file. If I fill data in a wrong format, a GET on the data reports an error. However, the only criterion for being valid is that my decimal number has 9 digits in total, no matter how many decimal places. Examples:

1234567.89  --> valid
12345.6789  --> valid
12345678    --> not valid
123.45678   --> not valid

I would have expected that 12345.6789 is not valid.

My cds version is 3.21.3.

Thanks

Wrong hdbtabledata for Draft-enabled localized entities

My deployments to HANA are failing for localized entities which are Fiori draft enabled.
For Fiori drafts, the compiler generates an additional key column for the _texts-tables (e.g.. ID_TEXT as UUID). This key column is not part of my csv-File (had no idea before that this column exist and what to put in there).

Deploying to SQLite works well. There, this key column gets filled automatically with a UUID.

Deploying to HANA fails however, because this artificial key is not considered at all.

Regards

Issue with OpenUI5 sap.ui.unified.FileUploader and OData V2

Hello CAP Experts,

I'm trying to extend the media-handling example with a working SAPUI5 UI. But when I use the @sap/cds-odata-v2-adapter-proxy to provide OData V2 and try to upload a file using the Control sap.ui.unified.FileUploader the following error is returned:

No payload deserializer available for resource kind 'ENTITY' and mime type 'multipart/form-data'

The example project can be found at:

https://github.com/gregorwolf/cap-community/tree/master/examples/media-handling

you can get it running by using:

npm run build
npm run deploy
npm run startv2

Now open http://localhost:4004/v2/ and try to upload a png file. I.e. the one from the srv/tests folder of the project.

I would expect that either CAP would support how sap.ui.unified.FileUploader does the upload or that sap.ui.unified.FileUploader is adjusted to the way CAP expects the upload.

Best regards
Gregor

Enhancement to service definition documentation

Copied from Slack per Gregor Wolf

One thing I struggled with for a while was the automated Service paths as described here: https://cap.cloud.sap/docs/cds/cdl#service-definitions

It mentions “kebab-case is enforced” - but no examples in any of the documentation (that I could find, at least) where the service name had two cased letters. I thought I had a caching issue when only my “old” services (“NotificationService” @ path “/notification”) were being served but the new ones weren’t, when really I had been trying to find my new service named “MasterDataService” at path “/masterdata” instead of the correct path of “/master-data”.

I’m aware I can add a @(path:“/newpath”) annotation to the service, but wanted to raise this flag in case anyone else was struggling with it. Perhaps it would help to add examples of how kebab-case is enforced or to mention that “PascalCase” is transformed to “pascal-case”? Thanks!

Read with an after hook implementation fails from Fiori Elements

Hello CAP Enthusiasts,

During my local testing I ran into a strange issue using the Fiori Elements front-end.

I've added a virtual spotsAvalaible property to my entity Courses. This virtual property I'm going to fill in the after hook of the READ of the Courses:

srv.after('READ', 'Courses', (courses, req) => {
            // problem from fiori: couses has counted object --> $count
            return courses
                .map(async course => {
                    // Get the reservations for this course
                    const reservations = await cds.transaction(req).run(
                        SELECT.from(Reservations).where({course_ID: course.ID})
                    )
                    // Caluclate spots taken
                    const spotsTaken = reservations.reduce((total, reservation) => total + reservation.quantity, 0)
                    course.spotsAvailable = course.spots - spotsTaken
                })
        })

This works when I use postman and do a get on the courses. (http://localhost:4004/training/Courses)

{
"@odata.context": "$metadata#Courses",
"@odata.metadataEtag": "W/\"BmT9sdj4fnWqz4BxxDN0o+XSNGD5CW69Y8wbhe1uRYk=\"",
"value": [
{
"ID": "ee0b3d38-729d-4237-a7fe-b922f753e87e",
"modifiedAt": null,
"createdAt": "2020-01-18T18:45:57Z",
"createdBy": "anonymous",
"modifiedBy": null,
"title": "Some course",
"days": 1,
"spots": 15,
"courseType": "Technical",
"spotsAvailable": 15,
"trainer_ID": "880331ae-ae41-4a46-b49b-b7a3cbd049b0"
}
]
}

But when using the Fiori elements front-end the hook crashes with following error. For the following request in the $batch:
GET Courses?$count=true&$select=ID,days,spots,title,trainer_ID&$expand=trainer($select=ID,name)&$skip=0&$top=30 HTTP/1.1

`
POST /training/$batch

READ Courses {
'$count': 'true',
'$select': 'ID,days,spots,title,trainer_ID',
'$expand': 'trainer($select=ID,name)',
'$skip': '0',
'$top': '30'
}
READ Courses {
'$count': 'true',
'$select': 'ID,days,spots,title,trainer_ID',
'$expand': 'trainer($select=ID,name)',
'$skip': '0',
'$top': '30'
}
[2020-01-19T14:45:18.101Z | ERROR | 1221510]: Cannot read property 'run' of undefined
TypeError: Cannot read property 'run' of undefined
at C:\repo\CAP\training-reservations\node_modules@sap\cds-services\lib\connect\Transaction.js:84:27
`

When debugging i notice that the after-hook gets called a second time, but this time the courses-parameter is filled with a counted object:

[{counted: 1}]

Is there a way to solve this?

Thanks!

Kind regards,

Robin

$user in where-clause not working?

Dear CAP-Team,
In my Bookshop-style sample, I want to introduce the following service:

service CatalogService {
    @readonly
    entity myOrders as select from domain.Orders {
            ID, orderNo, Items
        } where createdBy = $user.id;
}

It seems that the pseudo-variable $user.id is not evaluated properly (I also tried $user). domain.Orders is including the usual managed-aspect. When I'm importing csv-data, or doing POST requests, $user is set to "anoynmous". Using explicitely where createdBy = 'anonymous' is retrieving these data sets, whereas the above query returns an empty data set.

Is this a known issue?

Thanks
Klaus

Send JWT Bearer token in Authorization when consuming services

Hello CAP Team,

in my sample project controller-api I try to consume the SAP HANA XSA Controller REST API with CAP. @jung-thomas has described how to access the API in the blogpost SAP HANA XSA Controller API Interaction. There you find also his GitHub project: controllerAPI and links to the API documentation.

In my project I've tried several approaches to get to the goal. First I've tried my luck with the approach documented in Consuming Services - Sending Requests:

      const controllerAPI = cds.connect.to('controller-config')
      console.log("JWT: " + req.attr.token)
      const tx = controllerAPI.transaction(req)
      response = await tx.get('/v2/users')

as the API endpoint expects authentication with a JWT sent in the Authorization header as a Bearer token as this header isn't sent.

My next try was the executeHttpRequest method of the SAP Cloud SDK for JavaScript that @sacnl described in the post New Versions of SAP Cloud SDK: 2.19.1 for Java, 1.6.1 for JavaScript, and v22 of Continuous Delivery Toolkit:

      const destinationNameAndJwt = { destinationName: 'controller-config', jwt: req.attr.token};
      const httpRequest = {
          method: HttpMethod.GET,
          url: "/v2/users"
      };
      response = await executeHttpRequest(destinationNameAndJwt, httpRequest)

But also here the JWT wasn't sent to the backend. So I finally used:

      const destinationNameAndJwt = { destinationName: 'controller-config', jwt: req.attr.token};
      const httpRequest = {
        method: HttpMethod.GET,
        url: "/v2/users"
      };

      var config = await addDestinationToRequestConfig(destinationNameAndJwt, httpRequest)
      // Providing the destinationNameAndJwt does not have the effect to send the token so we add it manually
      config.headers = {"Authorization": "Bearer " + req.attr.token}
      response = await axios(config)

where I manually add the token to the Authorization header.

I hope the handling of service requests that don't use basic authentication will be improved.

Best regards
Gregor

Using the environment variable 'destinations' should not raise a warning when deployed to HANA XSA

I've deployed the sample controller-api to a HANA XSA instance. When I access the service I get the following warning in the logs:

(9223372036854775789)[1583424131985] [APP/13-0] OUT {"message":"Environment variable 'destinations' is set. Destinations will be read from this variable. This is discouraged for a productive application! Unset the variable to read destinations from the destination service on SAP Cloud Platform.","level":"warn","custom_fields":{"package":"core","messageContext":"destination-accessor"},"logger":"sap-cloud-sdk-logger","timestamp":"2020-03-05T16:02:11.984Z","msg":"Environment variable 'destinations' is set. Destinations will be read from this variable. This is discouraged for a productive application! Unset the variable to read destinations from the destination service on SAP Cloud Platform.","written_ts":1583424131984,"written_at":"2020-03-05T16:02:11.984Z"}

As the destination access in HANA XSA works via the environment variable 'destinations' that should not result in a warning.

OData V2 Proxy issue with Decimal data type

In my example project bookshop-demo I've defined an attribute testDecimal of type Decimal(9,2) in the entity Approval. When I try to update this attribute using the provided OData V4 service it does work without any issues. But when I use the @sap/cds-odata-v2-adapter-proxy i get the error message:

Error while deserializing payload. An error occurred during deserialization of the entity. A JSON number is not supported as Edm.Decimal value.

You can replicate the issue by cloning the issue, and then running:

npm i
npm run build:deploy:startv2

Then use the Fiori App Approval V2 or V4 via the launchpad at http://localhost:4004/app/fiori.html. When you create a new entry in V4 you will have no issues to i.e. enter 3.14 in the Field Test Decimal (9,2). But when you do the same using V2, you should get the error I've described above.

Mismatched TRIM, expecting Boolean, Identifier, Number, QuotedLiteral, String

Hello CAP Experts,

in our UI annotations we've added the field named Trim:

	    {$Type: 'UI.DataField', Label: 'Trim', Value: Trim }

For this we get the error message:

Mismatched TRIM, expecting Boolean, Identifier, Number, QuotedLiteral, String, '[', '{', '#', '+', '-', NULL

Unfortunately I haven't found anything documented why this is a reserved word. Please give us a clarification.

Best regards
Gregor

Hybrid development is not working when using ``cds deploy --to hana``

I've found that credentials are not read from default-env-json if the environment variable NODE_ENV is set to "production". This prevents from using "kind": "sql" for a required db in hybrid scenarios where the CAP server is running locally agains a HANA DB on CF. "kind": "sql" is automatically inserted into my package.json when I'm using cds deploy --to hana, so that people are automatically lead into this issue.

Other SAP components, like the Approuter, behave differently, when interpreting default-env.json. An environment variable is taken from this file, if this variable is not set in the real environment. That's why this file is called default-env.json, and not just env.json.

As a solution, I would suggest to either consider default-env.json appropriately, or not to use the "kind": "sql" trick of cds deploy --to hana.

Some details:

In my scenario, I've deployed to HANA on CF with cd deploy --to hana. I'm starting the Node.js CAP server and a Fiori UI locally. My package.json service requirement is

    "requires": {
      "db": {
        "kind": "sql"
      }
    }

When setting NODE_ENV="" (or "development") and running cds watch correctly leads to a deployment to SQLite and also my Fiori UI works fine against the CAP service on localhost:4004.

When setting NODE_ENV="production", I was expecting that the kind sql now resolves to hana and that the HANA credentials are read from my default-env.json. This is not the case. The log output of cds watch is showing [cds] - connect to hana db {}. The empty curly braces show me that no credentials are read. This can be confirmed using the cds env ls requires command, which shows:

requires.db.kind = sql
requires.db.use = hana
requires.hana.use = hana
requires.sql.use = hana
requires.sqlite.credentials.database = sqlite.db
requires.sqlite.use = sqlite

When requesting data, the following error occurs (necessarily):

[2020-05-04T08:51:26.176Z | ERROR | 1502486]: Cannot read property 'schema' of undefined
[INTERNAL ERROR] TypeError: Cannot read property 'schema' of undefined
    at C:\SAPDevelop\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-hana\client\Client.js:93:31
    at new Promise (<anonymous>)
    at Client.connect (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-hana\client\Client.js:66:12)
    at SQLDatabase._testConnection (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-services\connect\Service.js:314:18)
    at SQLDatabase._getAndCheckCredentials (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-services\connect\Service.js:296:17)
    at SQLDatabase._createPool (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-services\connect\Service.js:243:24)
    at SQLDatabase.acquire (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-services\connect\Service.js:149:49)
    at SQLDatabase.run (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-services\connect\Service.js:386:31)
    at OdataContext.context.run (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-services\services\Service.js:946:30)
    at Object.handler (C:\\Local\prod-cat\node_modules\@sap\cds-runtime\lib\cds-services\services\handlers\onRead.js:45:18)
Please report this error.

Setting "kind": "hana" and NODE_ENV="development" resolves this issue, but as said above, cds deploy --to hana is leading to a different setup.

Versions:

>> cds -v
@sap/cds: 3.34.1
@sap/cds-compiler: 1.26.2
@sap/cds-dk: 1.8.0
@sap/cds-foss: 1.2.0
@sap/cds-reflect: 2.11.0
@sap/cds-runtime: 1.1.1
@sap/hana-client: 2.4.196
Node.js: v12.16.3
home: C:\Local\prod-cat\node_modules\@sap\cds

Fallback to lookup destination with the name of the configured data source doesn't work when deployed to HANA XSA

Hello CAP Team,

the documentation Configuring Required Services - For HTTP-Based Consumption states:

If the destination is omitted, the runtime looks for a destination with the name of the configured data source.

But my sample project controller-api that I have to deploy to a HANA XSA returns the following error:

(9223372036854775784)[1583215124568][APP/9-0] ERR [ERROR] In production mode it is required to set `options.destination`
(9223372036854775785)[1583215124568][APP/9-0] ERR at new RestClient (/node_modules/@sap/cds-rest/lib/client/Client.js:67:13)

when I leave out the destination in the package.json. With the following configuration the destination is at least called:

      "controller-config": {
        "kind": "rest",
        "credentials": {
          "requestTimeout": 10000,
          "destination": "controller-config"
        },
        "pool": {
          "min": 1,
          "max": 10
        }
      }

Best regards
Gregor

Odata V2 adapter for CAP service

When i try to use Odata V2 adapter( github.com/gregorwolf/SAP-NPM-API-collection/tree/master/apis/cds-odata-v2-adapter-proxy ) , the V2 link gives an internal server error response. I chose the "CDS combined backend (Node.js) - custom" for my use case - when i run index.js , it works fine for V4 , but for the V2 path it gives internal server error. A look at the log for the service shows an error as follows: "Error: CDS compilation failed\ncat-service.cds:1:40-58: Error: Cannot find local module '../db/data-model' .

I'm sharing a Github link to my sample project here : https://github.com/shyamkumarc/CAP_POC

Please guide.

@cds.on.insert: #user returns value of #now.

Hi,

When I use @cds.on.insert: #user as described on https://cap.cloud.sap/docs/guides/generic-providers#administrative-data the value that is inserted is #now instead of #user.

db/

entity Test {
    key ID: Integer;
    @cds.on.insert: #user
    usr: String;
}

srv/

@Capabilities: { Insertable:true, Updatable:true, Deletable:false }
entity Test as projection on my.Test;

Postman POST

{
	"ID": 1
}

Response:

{
    "@odata.context": "$metadata#Test/$entity",
    "@odata.metadataEtag": "W/\"Z8vYLBwhpE88xl0GqG7dG6jh6IDcOeIONQBT8O5NY1s=\"",
    "ID": 1,
    "usr": "2020-01-15T17:01:35.173Z"
}

Data from Postman GET:

{
    "@odata.context": "$metadata#Test",
    "@odata.metadataEtag": "W/\"Z8vYLBwhpE88xl0GqG7dG6jh6IDcOeIONQBT8O5NY1s=\"",
    "value": [
        {
            "ID": 1,
            "usr": "2020-01-15T17:01:35.173Z"
        }
    ]
}

The response and the saved value are incorrect they should be anonymous in this case.

Changing updatable in the srv/

@Capabilities: { Insertable:true, Updatable:false, Deletable:false }
entity Test as projection on my.Test;

Postman Response:

{
    "@odata.context": "$metadata#Test/$entity",
    "@odata.metadataEtag": "W/\"JgUx0o1vV3RvDxgdNoz2tqILWXhgpO67KWVu8rVJZd4=\"",
    "ID": 1,
    "usr": null
}

Data from GET:

{
    "@odata.context": "$metadata#Test",
    "@odata.metadataEtag": "W/\"JgUx0o1vV3RvDxgdNoz2tqILWXhgpO67KWVu8rVJZd4=\"",
    "value": [
        {
            "ID": 1,
            "usr": "anonymous"
        }
    ]
}

The response is incorrect the "usr" value should be anonymous.

The first issue is plain wrong the value should be that of #user not #now.
The second issues is alike: CAP insertable service error with DB defaults #25

/D

Create Media Resource (OData v4) doesn't works as documented

The Documentation at:

https://cap.cloud.sap/docs/guides/generic-providers#media-data

states in the "Create Media Resource (OData v4)" section "The MIME type is passed in the Content-Type header."

I've expected that the Content-Type would be stored in the column annotated with @Core.IsMediaType. But as shown in the tests (provided for VS-Code REST Client) in:

https://github.com/gregorwolf/cap-community/tree/master/examples/media-handling

this results the wrong content-type when reading the file. It does return:

content-type: application/octet-stream

As shown in the example with the JPEG picture it works fine when attribute mediatype is set during creation of the media.

Issues installing @sap/cds-dk on Windows 10

Hello CAP Team,

as the issues reported about the installation of @sap/cds-dk on Windows in the CAP OpenSAP course increase I create this issue to track the topic better. I've just also tried to install @sap/cds-dk on my Windows 10 system with this release:

Screenshot 2020-04-23 at 07 50 56

I've used the following command:

C:\Users\Gregor>npm rm -g @sap/cds

npm WARN deprecated [email protected]: this package has been deprecated
removed 69 packages in 1.063s

C:\Users\Gregor>npm i -g @sap/cds-dk
npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)

> @sap/[email protected] preinstall C:\Users\Gregor\AppData\Roaming\npm\node_modules\@sap\cds-dk
> node ./lib/util/preinstall.js


The command 'cds' has moved from library @sap/cds to @sap/cds-dk.
It is recommended to remove the global version of @sap/cds and
reinstall @sap/cds-dk via
    npm rm -g @sap/cds
    npm i -g @sap/cds-dk

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\@sap\cds-dk\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @sap/[email protected] preinstall: `node ./lib/util/preinstall.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @sap/[email protected] preinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Gregor\AppData\Roaming\npm-cache\_logs\2020-04-23T05_39_29_058Z-debug.log

at the end of the debug.log file I see this errors:

6998 verbose stack Error: @sap/[email protected] preinstall: `node ./lib/util/preinstall.js`
6998 verbose stack Exit status 1
6998 verbose stack     at EventEmitter.<anonymous> (C:\Users\Gregor\AppData\Roaming\nvm\v12.16.1\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
6998 verbose stack     at EventEmitter.emit (events.js:311:20)
6998 verbose stack     at ChildProcess.<anonymous> (C:\Users\Gregor\AppData\Roaming\nvm\v12.16.1\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
6998 verbose stack     at ChildProcess.emit (events.js:311:20)
6998 verbose stack     at maybeClose (internal/child_process.js:1021:16)
6998 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
6999 verbose pkgid @sap/[email protected]
7000 verbose cwd C:\Users\Gregor
7001 verbose Windows_NT 10.0.17763
7002 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "i" "-g" "@sap/cds-dk"
7003 verbose node v12.16.1
7004 verbose npm  v6.13.4
7005 error code ELIFECYCLE
7006 error errno 1
7007 error @sap/[email protected] preinstall: `node ./lib/util/preinstall.js`
7007 error Exit status 1
7008 error Failed at the @sap/[email protected] preinstall script.
7008 error This is probably not a problem with npm. There is likely additional logging output above.
7009 verbose exit [ 1, true ]

hope that someone who can fix this issue can also replicate it and provide a fixed version.

CU
Gregor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.