Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDEA] Script Preprocessor #4475

Open
MichaelLeeHobbs opened this issue Mar 14, 2021 · 10 comments
Open

[IDEA] Script Preprocessor #4475

MichaelLeeHobbs opened this issue Mar 14, 2021 · 10 comments
Labels
enhancement New feature or request

Comments

@MichaelLeeHobbs
Copy link

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

A script preprocessor that receives the the script string from the generateScript in server/src/com/mirth/connect/server/builders/JavaScriptBuilder.java and returns a modified/processed script for generateScript to use as the transformer source.

Describe your use case
I need this feature so I can accomplish .

This would enable adding missing JS features for example Template literal.

Describe the solution you'd like
A clear and concise description of what you want to happen.

I think the easiest way to do this would be to add a Edit Script Preprocessor between Edit Filter and Edit Transformer. It may even be desirable to have this as a flag in the server config to enable/disable this and have it disabled by default as it would be a very advance feature.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Alternative solutions are ugly. You can in theory run script through something like Babel.js before loading them into mirth.

Additional context
Add any other context or screenshots about the feature request here.

Would need to run scripts through the preprocessor before checking the script is valid. May even be desirable to disable the linter in the editor if someone is using the preprocessor. By adding this feature Mirth would effectively enable the community to add missing JS functionality that cannot be added via polyfills. I understand there are many places where scripts are used besides source/destination transformers but I would start with those two as a proof of concept.

@MichaelLeeHobbs MichaelLeeHobbs added the enhancement New feature or request label Mar 14, 2021
@cturczynskyj
Copy link
Collaborator

Hello @MichaelLeeHobbs, could you add some detail as to why you need/want this? A specific example would be great! Are you trying to insert JS features that, currently, are not supported in RHINO?

@MichaelLeeHobbs
Copy link
Author

Are you trying to insert JS features that, currently, are not supported in RHINO?

That is correct. There are other possible use cases but that is the primary.

@ChristopherSchultz
Copy link
Contributor

I place stuff like this into the global script. The only thing I have right now is adding prototypes for Array.includes and String.startsWith.

Would this work for you, or is it important to be able to do this at an individual channel-level?

@MichaelLeeHobbs
Copy link
Author

MichaelLeeHobbs commented Apr 24, 2021

@ChristopherSchultz first your method cannot handle literals ie

var a = `some test ${val}` 

secondly if you are doing your polyfils that way then they are incorrect. Take a look at https://gist.github.com/MichaelLeeHobbs/8888395f6ada28df992aadeff92d074f

@ChristopherSchultz
Copy link
Contributor

My polyfills look like yours. How exactly am I doing it wrong?

@MichaelLeeHobbs
Copy link
Author

@ChristopherSchultz You showed String.startsWith not String.prototype.startsWith which is why I brought it up.

@ChristopherSchultz
Copy link
Contributor

@MichaelLeeHobbs Well... I'm prototyping String.startsWith, not String.prototype.startsWith, which is why I said it that way. Apologies for the noise.

@MichaelLeeHobbs
Copy link
Author

String.startsWith = function() {...} // creates a static method and will break on new String

String.prototype.startsWith = function() {...} // creates a method prototype that does not break on new String

Just to be clear

@tonygermano
Copy link
Collaborator

tonygermano commented Apr 30, 2021

This is getting way off topic. I believe the intention of the request was to be able to use syntax which will not compile under Rhino, which could then be transpiled to javascript that would work in Rhino. Rhino's ES6+ coverage is very spotty (but improving,) but the ES5 coverage is really good. Many of the ES6 built-in Objects are working, but the syntax changes are very slow to get implemented.

@thorst
Copy link

thorst commented May 15, 2024

I like this, but would vote to allow it to be applied to the filter as well. We dont use transformers and instead do all our coding in 1 js filter, so all the code is in one spot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants