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

Add JSON output to check command #20

Open
fermuch opened this issue Nov 22, 2024 · 5 comments
Open

Add JSON output to check command #20

fermuch opened this issue Nov 22, 2024 · 5 comments

Comments

@fermuch
Copy link

fermuch commented Nov 22, 2024

It would be very helpful to get the output of the check command in JSON format, so it can be used pragmatically.

@ascandone
Copy link
Contributor

Hi! Thanks for the issue :)
Currently the "check" command already emits a 0/1 error code so that it can be used in the CI
To use the diagnostics programmatically some alternatives are:

  • using the numscript language server (whose command is not showed by default but can be started with numscript lsp
  • use numscript as a golang dependency directly
    Could you describe your use case?

@fermuch
Copy link
Author

fermuch commented Dec 6, 2024

Sure! My use-case is to embed numscript in WASM so I can call it from anywhere :)

Would you describe me on how we could use numscript as a golang dependency, since almost all if not all of the library is inside internal/? I've tried but I cannot import anything, and AFAIK there is no workaround for importing from internal

@ascandone
Copy link
Contributor

ascandone commented Dec 6, 2024

Sounds interesting :)

The library is intended to be mostly "internal", as it's hard to guarantee semver for many parts of it, e.g. the AST representation
There's, however, a publicly exposed API surface which should be somewhat stable (albeit less flexible): https://github.com/formancehq/numscript/blob/main/numscript.go
That's the API used in the ledger, in which this numscript rewrite is going to be soon (v2.2.0) available in the ledger
https://github.com/formancehq/ledger/blob/04a2d4672b9cebd3a9d38bdbd6c16a1ff0f0f566/internal/controller/ledger/numscript_parser.go#L39
https://github.com/formancehq/ledger/blob/04a2d4672b9cebd3a9d38bdbd6c16a1ff0f0f566/internal/controller/ledger/numscript_runtime.go#L103

The currently exposed API surface is focused on the runtime part (numscript run in the CLI, and also the one running in the playground ) and not the static analysis part (CLI's numscript check, and also the one running in the vscode extension ) but we are considering adding analysis support to numscript's public API

Last but not least: we are also considering releasing a numscript WASM build too - but no promises yet. So if you happen make progress with it feel free to ping us, or even consider contributing directly here :)

In case you haven't, you can also join Formance's Slack, which has a #contributors channel

@fermuch
Copy link
Author

fermuch commented Dec 18, 2024

Sorry for the delay! End of the year sure is a crazy time.



We're in the process of porting the lib by re-writing the frontend to be compilable with WASM (using tinygo). Please note, this is very early and we are still experimenting.


We would love to use the public API if possible, but we'd need to wait to have a way to get the check output too. I think porting the LSP server would be too much overhead, as we are trying to get the API surface small and the binary as small as possible too (right now is around ~3MB, and can be smaller).


Our final step would be for the WASM file to be called from elixir as a library, and maybe from javascript & flutter in the frontend.

In the backend we want to use Numscript as a DSL to process complex rules from traditional contracts.

And in the frontend we want to display the users what the output of their transactions would be, and how their money would go through each step of the pipeline.


We are open to back porting the changes! But it is ok if you need more time to stabilize the API. We are still at the experimentation phase too.

@ascandone
Copy link
Contributor

That is very interesting! Using numscript in a broader context than just the Formance ledger is surely one of the design goals, and I would love to hear more about the use cases you are trying to accomplish. It would be great to arrange a live call if you have the time - you can text me in the Formance community slack to arrange that, name's Alessandro Scandone (Formance)

By the way, if I understood correctly, what you are most interested into would be the "run" command output, which is the one that outputs the postings. The "check" command is basically a linter. Every error that is caught by the "check" command would be a runtime error as well.
The "run" command is already machine-readable, with the --output-format=json flag

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

No branches or pull requests

2 participants