Hacker News new | ask | show | jobs
by fuhrysteve 3739 days ago
I'm a little horrified to suggest this seriously, but this could be a cool way to accomplish consistent field validation between server and client.

I wrote this little library https://github.com/fuhrysteve/marshmallow-jsonschema#complet... to convert marshmallow schemas to a JSON representation with the intention of passing it to a browser or mobile device for rendering. Imagine if you could also pass native code to be used by the client for validation. In other words: write your validator in python and use it server side - but also convert it to javascript so that the client can attempt to validate it before bothering to send a web request.

2 comments

Javascripthon supports converting either a python source file or a python function object directly, but actually using the embedded js interpreter to do the transpilation takes some time due to BabelJS code bootstrap time.

Having a "HOT" interpreter with an execution context that is persistent and can be used to convert code to ES5 on the fly has been already implemented by duckpy creator and i plan to intergate it very soon.

See https://github.com/amol-/dukpy/issues/4

Interesting idea. In the context of educational software, the "validation logic" would be the answer checking. The backend could do the checking in Python, but the same logic can also be shipped to the client as js for offline usage.

related: a LaTeX to .js "transpiler" for the exercises https://ximera.osu.edu/

Now if only someone could transpile SymPy to javascript...