apigear-io / cli

The ApiGear client as go project
https://apigear.io
MIT License
1 stars 2 forks source link

[FEAT]: allow filters in JS #88

Open jryannel opened 1 year ago

jryannel commented 1 year ago

Description

To better support templates with custom filters, allow filters to be written in JS and be placed inside the SDK templates.

Ideally it shall also be possible to overwrite the built-in filters and or to call these filters from the overwritten filters. Also these filters would need to have access to a larger list of helper functions, to ensure custom filters do same string handling (e.g. title case, camel case) then the go version.

Additional Information

We use already Goja (js runtime) for the simulation. We can use same js runtime to parse js filters and expose these functions.

I would expect this would be some weeks work, to ensure good error handling, documentation, elegant way to implement and overwrite filters, ....

jryannel commented 5 months ago

Any filtering in plugins will be difficult. As the filters receive a pointer to an internal data structure (e.g. model.Schema, model.TypedNode). These are only available inside the same shared memory.

Any external plugin system (e.g. go-plugin) will not work, as we can not so easily serialise the data and allow lookups on the plugin side.

Any conversion (e.g. JS might be difficult at least). JS will require to use the same string conversion methods as otherwise we will see subtle behaviour changes, e.g. snake case behaves different from library to library.

Also this will make the cli more slow and easier to fail, due to inconsistent template code.