Skip to content
Search

    CDS Design Time APIs

    This guide is about consuming CDS design-time APIs programmatically.

    Import @sap/cds-dk

    The design-time APIs are provided with package @sap/cds-dk and can be used as follows:

    1. Install it locally:
      npm add @sap/cds-dk
      
    2. Import it in Node.js:
      const cds = require('@sap/cds-dk')
      

    cds.import (file, options) csn

    As an application developer, you have the option to convert EDMX files to CSN from JavaScript API as an alternative to the cds import command.

    cds.import is available in the CDS development tool kit version 4.3.1 onwards .

    The API signature looks like this:

    const csn = await cds.import(file,options)
    
    Arguments:
    • file — Specify the path to a single EDMX file to be converted for CSN.
    • optionscds.import() support the following options:

    options.keepNamespace

    Value Description
    true Keep the original namespace from the EDMX content.
    false Take the filename as namespace.

    Note: If the option is not defined, then the CSN is generated with the namespace defined as EDMX filename.

    Usage example:

    const cds = require('@sap/cds-dk')
    module.exports = async (srv)=>{
      const csn = await cds.import('./northwind.xml',{keepNamespace:true})
      const json = cds.compile.to.json (csn)
      console.log (json)
    }