-
-
Notifications
You must be signed in to change notification settings - Fork 429
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
SCRIPT transformation syntax and file naming #3465
Comments
I can't find the discussion immediately but this has been discussed before and we agreed that files in the transformation folder should have an extension that is their transformation type. My vote would be "won't fix". |
A link to the previous discussion would be appreciated!
With jsr223 rules files the .graaljs and .nashornjs extensions can already be used for avoiding ambiguity. Usually you can customize your OS and editors to add additional extensions for opening editors and syntax highlighting. |
I‘ll see if I can find it. Removing the |
No, don't remove it completely. Make it optional, both for compatibility and for the cases when it's needed. So In the case where SCRIPT(my script.script) is used, or when myscript.js alone is not sufficient because there are two js engines available,then raise an error/warning |
Another case where it would be needed: UI based transformations. I almost forgot about them because openhab/openhab-webui#1448 is now approaching its first birthday, but there we also need the prefix. It might be personal choice, but I think that a consistent way to configure the same thing is better than different ways which only work under special conditions. |
Even the webui editor needs a hint of what type of script a .script file is. Using an actual .js extension would remove that need. That too seems like a huge win for the usability factor. The nashorn/graaljs is a temporary bridging issue going forward there is no ambiguity, as nashorn is going to be dropped, right? The transformation editor would need to become a generic script editor loading whatever language depending on the extension in the same way the rule/script editor is. You never specified the transformation with only the filename. You always have to specify the transformation type e.g. SCRIPT(), MAP(), JSONPATH(), REGEX(), etc. So the type of transformation is already represented by them. The rest is the extra data for the corresponding transformation service to be interpreted individually by the respective service. It seems to be only natural to say SCRIPT(something.js). In the case of inline script SCRIPT(graaljs:|......) which is why we still support the first field containing the scripttype. |
From the transformation POV we have a UID and we request that UID from the transformation registry. We don't care about the UID itself or its structure. The UID can be a filename ( So we would introduce a new special solution for file-based configuration which additionally is totally anti-pattern. I don't think that specifying the language as prefix is a big burden for the user. |
I also found the discussion, it's in #2872 and especially #2872 (comment) lead to the removal of the |
I want to also chime in that forcing a
This only works if you only use one language for script transformations. Again, if someone has script transformations in multiple languages (say I write Ruby, but found a community contribution in JavaScript, I'd have both). Maybe I can come at this by re-stating from a slightly different point of view. The current reasoning is "extensions of files in the transformations folder inform which transformation provider should be used," no? Traditionally, transformation providers only support a single syntax, so that has been 1:1. But the script transformation provider is a polyglot, or a proxy to other languages. So saying ".rb is handled by SCRIPT provider, as well as .js is handled by SCRIPT provider" doesn't violate my original re-statement. It just seems like with JS transformation gone in 4.0 and forcing people to use SCRIPT, we'd want to make it as simple as possible for them - just replace |
Again: There is not only file-based transformation but also UI based/managed transformations. There is no way to determine the scripting language from an arbitrary UID. Why should we restrict the UID to a "special" format (with characters not allows in UIDs! and different from all other transformations) to allow something for file-based transformations that is different from all other transformations? The concept "file extension=script type" is super easy to understand, well-known to existing users and IMO not counterintuitive in any way. |
Again: just because there are UI based/managed transformations, does not mean you can't make it a good experience for file-based transformations. Especially if it doesn't harm UI based/managed transformations.
I don't recall anyone advocating restricting UIDs. Simply for file based transformations, if it has an extension, and not an explicit script type, infer the script type from the extension.
Except it is very counter-intuitive, because you just made an ambiguous presumption there. I know you meant "script type" to mean "the type of this transformation is script", but skimming it it is easy to read "the file extension indicates the type of script it is. like ruby". Keep in mind, you wrote the feature. So everything about it would be automatically intuitive to you. We're trying to point out that for other people (especially someone who has never used a transformation before, or only used the JS transformation in the past) it is not intuitive. |
I wish that the SCRIPT transformation's syntax uses the underlying scripting engine's extension, i.e. just
.js
,.rb
, etc. instead of.script
. I understand that the reason it's.script
now is because it's the name of the transformation itself (i.e.SCRIPT
transformation ->.script
file extension,MAP
transformation ->.map
file extension). As a result of this choice, an extra field must be supplied to indicate the script type (rb, graaljs, dsl, etc).But it would be so much nicer to have
SCRIPT(myscript.rb)
andSCRIPT(myscript.js)
rather thanSCRIPT(rb:myscript.script)
andSCRIPT(graaljs:myscript.script)
:The text was updated successfully, but these errors were encountered: