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

[udf] Unlock JavaScript for user-defined functions #667

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amotl
Copy link
Member

@amotl amotl commented May 9, 2023

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. 💯

A highly configurable MQTT message router, where the routing targets are notification plugins, primarily written in Python.

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

  1. https://www.destroyallsoftware.com/talks/wat

@codecov
Copy link

codecov bot commented May 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (772f9f5) 49.75% compared to head (8cd99f7) 49.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #667      +/-   ##
==========================================
+ Coverage   49.75%   49.96%   +0.21%     
==========================================
  Files          81       81              
  Lines        4034     4051      +17     
==========================================
+ Hits         2007     2024      +17     
  Misses       2027     2027              
Flag Coverage Δ
unittests 49.96% <100.00%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

1 participant