feat: JSServerExtensionInvoker SDK — consume JS-declared server extensions from other bundles - #686
Closed
romain-pm wants to merge 1 commit into
Closed
Conversation
romain-pm
force-pushed
the
feature/js-server-extensions-sdk
branch
from
July 22, 2026 07:32
7a8f1df to
b16507d
Compare
…nsions Adds a public, polyglot-free SDK so other OSGi bundles can consume JS-declared server extensions (server.registry.add(type,...)) and invoke their callbacks: - JSServerExtensionInvoker (interface) + Impl (@component) in a new exported package org.jahia.modules.javascript.modules.engine.sdk - forEach(type, handler) runs within one pooled GraalVM context; Invoker.call executes a JS callable and converts the result to plain Java (no GraalVM types leak to consumers, so callers need no polyglot dependency) - engine bundle now Export-Package's only the sdk package Enables Formidable to run JS-authored form-field validators server-side (issue Jahia/formidable#158) without embedding GraalVM or engine internals.
romain-pm
force-pushed
the
feature/js-server-extensions-sdk
branch
from
July 22, 2026 07:53
b16507d to
fd7a229
Compare
Author
|
Folded into #687 for combined review: the SDK commit ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Exposes a small, polyglot-free public SDK so other OSGi bundles can consume JavaScript-declared server extensions — i.e. registry entries contributed by JS modules via
server.registry.add(type, key, entry)— and invoke their JS callbacks from Java.Stacked on
feature/js-server-extensions(base of this PR). One commit.Why
The built-in registrars added by
feature/js-server-extensions(action,choicelist-initializer,node-validator,render-filter) wire JS entries to Jahia's own extension points. A third-party module that wants to own its own extension type — e.g. Formidable running JS-authored form-field validators inside its submission pipeline — has no supported way to do it today:GraalVMEngine,Registry, andAbstractServiceRegistrarlive in non-exported packages, and consuming them directly would also drag GraalVM polyglot types into the consumer.First consumer: Jahia/formidable#163 (server-side JS field validators for Jahia/formidable#158).
Design
New exported package
org.jahia.modules.javascript.modules.engine.sdk— the only exported package of the engine bundle:forEachruns entirely inside one pooled GraalVM context (GraalVMEngine.doWithContext), re-resolving the registry per call — respecting the rule that JS function handles must never outlive a context (contexts are recycled on module (un)deploy).Invoker.callexecutes a JS callable from an entry and recursively converts the result to plain Java, so noorg.graalvm.polyglottype ever crosses the SDK boundary — consumers need zero GraalVM imports and no version coupling to the embedded Graal stack.@Component(JSServerExtensionInvokerImpl); consumers reference the service (optionally, for graceful degradation on older engines).AbstractServiceRegistrar/GraalVMEngine/Registry: the facade is the minimal surface, and internals stay free to evolve.Verification
Export-Package: org.jahia.modules.javascript.modules.engine.sdkand the DS descriptor is generated.formidable-field-validatorregistry type populated from a JS module, consumed fromformidable-engine— 12/12 forged/valid submission cases behaved correctly (forged values rejected, valid accepted)..chachalog/js-server-extension-sdk.md, minor).Open questions for review
sdkpackage vsspi,JSServerExtensionInvokervs something closer to "registry consumer".forEachshould also expose the entry's owning bundle (consumers may want provenance for diagnostics).feature/js-server-extensionsships (currently${project.version}).