[udf] Unlock JavaScript for user-defined functions #667
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there,
after bouncing on and off on the idea to leverage the
javascript
package for data transformation purposes, in order to get rid of our PutsReq instance, which is a resource hog, and ceased to exist anyway, and while being unsure whether or how to also bring it to Kotori or LorryStream exactly, I am finally making a start on behalf of mqttwarn.On the PutsReq instance I was referring to, we are running small snippets of JavaScript code like putsreq.hiveeyes.ttn_v3.js, in order to converge telemetry data packages received from TTN into a format digested by Kotori, effectively just unwrapping a few levels of JSON nestedness.
Following this idea, and annoyed about PutsReq itself, we've also explored the problem space on behalf of other projects like flow-heater already. At about the same time, Cloudflare Workers have been released, allowing to route and modify HTTP requests in different ways, using JavaScript or TypeScript. /cc @elbart
This patch essentially brings the same idea to mqttwarn, where all the routing and transforming machinery is already in place, and just needed a laughably small patch to achieve the same things with JavaScript without much further ado, thanks to the excellent JSPyBridge by @extremeheat. 💯
By providing an alternative way of writing user-defined functions, the patch challenges the current slogan "primarily written in Python". I hope you will still like it, and I will be happy to hear back about your opinion about it.
Rest assured I am not a strong advocate of the JavaScript language, nor its paradigms and its NPM ecosystem 1. But I recognize the value of the V8 runtime underneath Node.js, that it's an excellent and robust piece of software, and that people are doing many amazing things of their own kind with it.
The preview of the corresponding documentation can be inspected here:
With kind regards,
Andreas.
NB: Next stop: Lua? Edit: See GH-669.
NB: Next stop: Java? See https://github.com/jpype-project/jpype and https://github.com/kivy/pyjnius.
NB: Next stop: Golang? See https://github.com/grumpyhome/grumpy.
Footnotes
https://www.destroyallsoftware.com/talks/wat ↩