Adding support for JS prototyping using GraalJS - #960
Conversation
|
One could consider to wrap the JS inside FHIR libraries |
jamesagnew
left a comment
There was a problem hiding this comment.
A couple of initial thoughts - This is a really neat idea, but I don't think this implementation is the right approach:
- We shouldn't be defining functionality in this project - it should purely handle configuration and deployment concerns. If this is a useful feature, it should be built, documented, and tested in a hapi-fhir module, and instantiated in this project.
- It probably makes more sense to use GraalJS for the execution engine - Nashorn isn't being actively developed these days and is fairly behind.
|
I hear you on GraalJS (trifork@b8f7383) - but then we will also have to require a bump on the Java version to 21 (thats probably fine) soon ™️ . On moving it to a module to HAPI FHIR ... - I guess... 🤔 - but I wouldn't know the proper encapsulation/abstraction. The reason why I put it here in its current form was because the simple abstraction of just wrapping it in a FHIR operation seemed fine for the purpose. If we move it and just retain (or close to) the signature of executeJavascript(
@OperationParam(name = "script", min = 1, max = 1) StringType theScriptName,
@OperationParam(name = "resource", min = 0, max = OperationParam.MAX_UNLIMITED)
List<IBaseResource> theInputResources,
@OperationParam(name = "reference", min = 0, max = OperationParam.MAX_UNLIMITED)
List<Reference> theReferences,
RequestDetails theRequestDetails) Then I guess that could work just fine. |
|
This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
|
Moved to here hapifhir/hapi-fhir#8237 as requested @jamesagnew ✔ |
This pull request introduces a new feature that enables secure, server-side execution of administrator-vetted JavaScript scripts for transforming FHIR resources via the new R4
$execute-javascriptoperation. This is implemented using the GraalJS engine, is disabled by default, and includes comprehensive security measures such as sandboxing, strict script selection, and execution timeouts. The PR also adds configuration options and updates documentation and dependencies accordingly.New Feature: Server-side JavaScript Execution for FHIR Resources
Implementation of
$execute-javascriptOperation:JavaScriptExecutionR4OperationProvider, a new R4 system-level operation provider that executes administrator-installed JavaScript scripts (not user-supplied code) to transform FHIR resources.Security and Configuration:
application.yamlto enable the feature, specify the scripts directory, and set execution timeouts. The feature is disabled by default and requires explicit configuration to activate.Integration and Dependency Updates
Integration with Server Startup:
Dependency Addition:
org.graalvm.js:js) to thepom.xmlto enable script execution on stock JDKs.Documentation
$execute-javascriptoperation, its security model, configuration, usage examples, and a quickstart for Docker-based testing.