Add NodeJS bindings to synapse_auto_compressor#167
Add NodeJS bindings to synapse_auto_compressor#167jaywink wants to merge 15 commits intomatrix-org:mainfrom
synapse_auto_compressor#167Conversation
Similarish to the Python bindings, we'll expose Node bindings to run `synapse_auto_compressor` tool. The function naming and parameters hav been kept the same as the Python equivelent. Currently the Node bindings don't set up logging. Also due to the Python bindings sitting at the `synapse_auto_compressor` root, the node bindings are in a submodule `node`. Also adds some structured result information for the `compress_chunks_of_database`, which is useful for more programmatic analysis of what was done. This has also been reflected in the Python bindings. TODO: needs NPM publish steps
|
|
reivilibre
left a comment
There was a problem hiding this comment.
Generally happy with this, what do you think?
|
|
||
| `$ cd synapse_auto_compressor` | ||
|
|
||
| 2. Build and install the library |
There was a problem hiding this comment.
Any objection to using pnpm instead?
On the team, we are more familiar with that, so if possible it's nice to keep our tools in alignment.
There was a problem hiding this comment.
Hmm, trying to use the node bindings appears to be causing this now after converting to pnpm:
Error initializing: Error: Cannot find native binding. npm has a bug related to optional dependencies (npm/cli#4828). Please try
npm iagain after removing both package-lock.json and node_modules directory.
Unsure if this is due to the way I'm bundling the build locally to our nodejs app, but I suspect pnpm does something differently to the napi suggested yarn 🤔 Any ideas?
There was a problem hiding this comment.
Looks like the yarn built node native binding is approx 3.3MB, while the one built by pnpm is ~700KB (+ a node_modules directory, which the yarn version doesn't generate).
There was a problem hiding this comment.
Actually no, reverting to yarn doesn't seem to fix things, so broke something with the feature refactoring probably.
There was a problem hiding this comment.
Right, after some amount of hair tearing, it seems I had dropped the node module declaration 🤦
There was a problem hiding this comment.
Thanks and sorry for the trouble!
| napi = "3.0.0" | ||
| napi-derive = "3.0.0" |
There was a problem hiding this comment.
would it be reasonable to make these optional dependencies (see pyo3 for instance)?
This way if someone only wants the Python bindings they don't have to bring along the Node ones.
I think it would be a matter of adding a feature flag for this, making these optional and 3 or 4 #[cfg] / #[cfg_attr] conditional compilation directives
There was a problem hiding this comment.
Have done so, hopefully the code makes sense, had some issues getting things to compile in a way that the features can also return the result into Python and Node, basically gave each their own struct and copied things over. I've not done a lot of rust so happy to receive feedback if something doesn't make sense. Will do some testing to ensure things actually work.
Co-authored-by: Olivier 'reivilibre' <olivier@librepush.net>
Also fix the Python bindings for the new result return.
|
Right I think my local clippy is now updated to a version that fails it seems: Probably shouldn't be touching that in this pr tho 🤔 |
Have opened #169 |
|
|
||
| `$ cd synapse_auto_compressor` | ||
|
|
||
| 2. Build and install the library |
There was a problem hiding this comment.
Thanks and sorry for the trouble!
| } | ||
|
|
||
| #[allow(dead_code)] | ||
| pub struct CompressedChunkResult { |
There was a problem hiding this comment.
I'm not sure which one would be generally preferable (I'm not against duplicating this struct for each binding), but if interested you could
#[cfg_attr(feature = "pyo3", pyclass)]
#[cfg_attr(feature = "node", napi(constructor))]
etc
There was a problem hiding this comment.
Well, yes, that is much simpler, thanks for the suggestion!
|
|
||
| ## Publishing to NPM | ||
|
|
||
| TODO TBD |
There was a problem hiding this comment.
Is this something you intend to PR after?
There was a problem hiding this comment.
I was thinking in a follow-up pr, yes, if that is ok.
Similarish to the Python bindings, we'll expose Node bindings to run
synapse_auto_compressortool. The function naming and parameters hav been kept the same as the Python equivelent. Currently the Node bindings don't set up logging. Also due to the Python bindings sitting at thesynapse_auto_compressorroot, the node bindings are in a submodulenode.Also adds some structured result information for the
compress_chunks_of_database, which is useful for more programmatic analysis of what was done. This has also been reflected in the Python bindings.TODO: needs NPM publish steps