Open newtack opened 5 years ago
@newtack it's not directly supported, but there's a way to do it anyway. I wrote about it a few months ago: https://thomaslevesque.com/2019/07/15/using-typescript-to-write-cosmos-db-stored-procedures-with-async-await/
The method detailed above is very brittle and has a lot of moving parts. Consider this, instead:
@Oblarg very nice!
Yes, I know my approach isn't ideal... I'm not a front-end dev and I don't know much about the JS toolchain, so I was unable to achieve what I wanted using webpack. Your solution is probably more robust. A few remarks:
Modify database.js to include your actual connection string, database name, and container names.
This is a bit annoying... Any chance it could be packaged in a way that doesn't involve modifying the code? I assume database.js is only used for deployment, right? Maybe it could just be done by passing arguments to the npm task?
Also, I think it would make sense to split build-storedprocs
into 2 separate steps:
Because one might want to build without deploying immediately, e.g. in a CI process.
Also, it looks like there is no support for user-defined functions or triggers.
Anyway, this is a nice step in the right direction!
The Azure Portal interface for writing stored procs has autocomplete enabled yet the library does not containing typings to hit the autocompleter. This results in a poor and confusing experience. Adding typings would considerably increase developer confidence when writing stored procs as they would have immediate confirmation whether their code will run without integration issues, and would allow developers to remain in the editor rather than having to constantly view documentation.
Can you re-implement the library in Typescript, or at a minimum provide modern Typescript API (with support for promises/async/await, good typings, etc.)? The API uses an old-style callback approach and should be using promises instead. While I could wrap it myself (e.g. https://medium.freecodecamp.org/how-to-make-a-promise-out-of-a-callback-function-in-javascript-d8ec35d1f981), I really shouldn't have to do this.
Typescript is awesome and I would have expected that a modern Microsoft product would use it.