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

feat(validation): validate concerto objects from dotnet using node #29

Merged
merged 14 commits into from
Jan 9, 2024

Conversation

jamieshorten
Copy link
Collaborator

@jamieshorten jamieshorten commented Dec 21, 2023

Closes #5

Validate Concerto objects against a provided concerto models from .Net code using Javascript.NodeJS to run the core Concerto engine in NodeJS.

Changes

This works by wrapping the core Concerto engine with a TypeScript function that is then webpacked to Module that Node can execute. Javascript.NodeJS takes care of orchestrating the communication between the host .Net application and NodeJS.

How Javascript.NodeJS works

This package works by serialising any parameters using the built in dotnet JSON serialiser. It then calls a function in a NodeJS module with the supplied parameters. The module needs to contain functions that conform to a signature defined here.

The module can either be passed as a string or a file path. In the case of a file path the module is cached for as long as the NodeJS process is running. If the module is passed as a string then the client needs to specify a cache key manually if it needs the module to be cached.

The NodeJS processes spawned by Javascript.NodeJS are terminated when the INodeJSService is disposed.

Returned objects are deserialised to a client provided type.
All communication with the NodeJS process happens over HTTP.

Finally this project does not handle creation of the INodeJSService instance. The client application should do this and use whatever DI system it uses to inject it into the AccordProject.Concerto.Validate.Validator instance at construction time. This is to allow the client to configure any specific NodeJS settings it needs such as multiprocess concurrency.

Flags

NodeJS needs to be present on the host system. There are two major alternatives to this approach:

  • ClearScript, which embeds V8.
  • One of the other embeddable JS engines (some are even written entirely in .Net)

Neither approach is suitable because Concerto requires enough functionality that is only present in either the browser or NodeJS that shimming or polyfilling the required types and functions is impractical.

Screenshots or Video

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to master from fork:branchname

@dselman
Copy link

dselman commented Dec 21, 2023

It would be wonderful if you could describe the processes/architecture for a .NET application that is using this. For example, how does the data get serialised between .NET and Node?

@jamieshorten
Copy link
Collaborator Author

It would be wonderful if you could describe the processes/architecture for a .NET application that is using this. For example, how does the data get serialised between .NET and Node?

Added a brief description

@jamieshorten jamieshorten marked this pull request as ready for review January 8, 2024 16:19
mttrbrts
mttrbrts previously approved these changes Jan 8, 2024
Copy link
Member

@mttrbrts mttrbrts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, with one minor comment

mttrbrts
mttrbrts previously approved these changes Jan 9, 2024
Copy link
Member

@mttrbrts mttrbrts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge once the build and DCO are fixed.

@jamieshorten jamieshorten merged commit d134f9b into accordproject:main Jan 9, 2024
3 checks passed
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.

Port Validation from JavaScript Implementation
3 participants