npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cdsgen

v0.5.12

Published

It's a helper CLI tool to generate CAP artifacts for your project

Downloads

890

Readme

CDS helper tool

It's a helper CLI tool to generate CAP artifacts for your project

Installation

npm i -D cdsgen

Commands

COMMANDS
  $ cds2syn synonyms                • Generate hdbsynonym file

Generate synonyms from CAP model

DESCRIPTION
  Generate hdbsynonym file

USAGE
  $ cds2syn synonyms

OPTIONS
  --help                            • Display instructions for the command.
  --model                           • CDS model name
  --output                          • Output file
  --parseable                       • Parseable CLI output (JSON)
  --plain                           • Use plain SQL mapping
  --quoted                          • Use quuoted SQL mapping
  --regex                           • Filter entities by regex
  --schema                          • Target schema
  • model is a required parameter compatible with cds.resolve
  • output is an optional parameter to specify the output file path
  • parseable makes sure the output of the command is parseable (JSON) format, that's how it may be used in pipe commands
  • plain and quoted directives tell the tool to which format the SQL mapping should be generated. You can use both at the same time.
  • regex is a useful parameter to filter out entities you want to generate the synonyms for.
  • schema parameter allows you to generate synonyms for a specific schema. It's optional.

Examples

One of the most common use cases is to generate synonyms for the existing database tables.

Let's say you have the app which connects to the extenal schema. In this case even if you generate relevant CDS files with a tool like hana2cds, you still need to generate synonyms for the tables and views if they use @cds.persistence.exist: true because those artifacts are not created automatically.

Let's say you have an app connected to the external schema EXTERNAL_SCHEMA . The very first step could be is to generate CDS model for the external schema with a command like :

# hana2cds always generates CSN schema
npx hana2cds --schema EXTERNAL_SCHEMA --filter EXTERNAL_TABLE > schema.csn
# You may convert it to CDS model but is ok to use CSN for synonmys generation too
# This command will generate CDS model from the created CSN file
cds compile --to cdl schema.csn --dest schema

As a result you may get a file like:

@cds.persistence.exist: true
entity EXTERNAL_TABLE {
    key ID : Integer;
    key NAME : String;
    DATE_CREATED : Timestamp;
    ...
}

Now you can generate synonyms with the following command:

npx cdsgen synonyms --model schema --output db/gen/external_schema.hdbsynonym --schema EXTERNAL_SCHEMA

as a result you will get a file like:

{
  "EXTENAL_TABLE"" : {
    "target":{
      "object":"EXTERNAL_TABLE",
      "schema":"EXTERNAL_SCHEMA"
    }
  }
}

it also allows you to generate synonyms for entities with special characters like ::.

Let's say we have a schema with hdbcds entities there in a format like org.namespace::Foo.Bar.

Generating CDS for such a table would result in a file like:

@cds.persistence.exists : true
@title : 'Foo Bar'
entity org.![namespace::Foo].Bar {
  @title : 'Id'
  key ID : String(100);
  @title : 'Type'
  key TYPE : String(100);
  @title : 'Name'
  NAME : String(255);
};

The problem is that when you build such a model for hana and let's say you want use as projection in another cds view CAP framework will transform such a name into something like org.namespace.Foo.Bar which is not the same as org.namespace::Foo.Bar. With the help of our tool - we can just give it a whole CDS model and it will try to generate synomys for such entities respecting this rule:

cdsgen synonyms --model model.cds --schema EXTERNAL_SCHEMA --quoted

The --quoted directive will generate synonyms in a format compatible to "sql_mapping" : "quoted" in cds configuration.

The result will be:

{
  "org.namespace.Foo.Bar"" : {
    "target":{
      "object":"org.namespace::Foo.Bar",
      "schema":"EXTERNAL_SCHEMA"
    }
  }
}

Another use case - is the opposite to quoted plain format. In this case you can use --plain directive and it will generate synonyms in a format compatible to "sql_mapping" : "plain" in cds configuration:

{
  "ORG_NAMESPACE_FOO_BAR"" : {
    "target":{
      "object":"org.namespace::Foo.Bar",
      "schema":"EXTERNAL_SCHEMA"
    }
  }
}

Contribution

This project is open source and you are very welcome to contribute. It is build using following tools:

  • TypeScript only
  • CAP framework is the core component. This project is supposed to be the extension of CDS toolkit and tries to delegate as much logic as it can to the core @sap/cds component.
  • moost An amazing framework to build apps ( no matter if it's CLI or web app ) build by @mav-rik. If you are not familiar with it, we recommend to check it out.