cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use @impl flag with typescript in cap?

Animatron56
Participant
0 Kudos

I am currently developing a cap application with typescript. My project structure looks as follows: 

  • srv
    • Controllers
      • bookshop.ts
    • Definitions
      • bookshop.cds

We used the structure like this since we have a lot of different definitions for different applications and want it to be as readable as possible. 

Since the contorllers are in a different folder, we use the @impl annotation to get the right controller. As an example: 

service bookshopService @(path: '/bookshop', impl: './../Controllers/bookshop.ts') {
...
}

Since we use typescript we also use cds-ts to test our application locally. Locally everything works fine. 

However now when we try to deploy our application we get the error, that the bookshop.ts file cannot be found. This also makes sense since we compile all typescript files into javascript files before deploying. So for the application to find the right files the impl annotation would need to be "./../Controllers/bookshop.js" and not ts. 

However when we change it to js, we cannot test it locally without building it for js beforehand. 

Is there a good solution for this problem using CAP? For example is it possible to change the behavior of the compiled Definitions?

Thank you in advance

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert
0 Kudos
Have you tried to use the 'class' as implementation option described here: https://cap.cloud.sap/docs/node.js/core-services#how-to-provide-custom-service-implementations ?

Accepted Solutions (1)

Accepted Solutions (1)

Dinu
Contributor

If you omit the extension in @impl the .ts file will be picked-up if .js file is not found. 

service bookshopService @(path: '/bookshop', impl: './../Controllers/bookshop') {
...
}

A pitfall is if you have a .js file with the same name, that will be picked-up.   

Animatron56
Participant
0 Kudos
That solved it, thanks 🙂

Answers (0)