-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add user module registration for reusable ES modules#45
feat: add user module registration for reusable ES modules #45simongdavies wants to merge 4 commits into
Conversation
bcd0328 to
164b3f9
Compare
@ludfjig
ludfjig
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed the rust code, looks good!
164b3f9 to
fb611bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds first-class "user module" registration so handlers (and other modules) can import reusable ES modules via the <namespace>:<name> convention (defaulting to user:), spanning the Rust host library, the guest runtime loader, and the Node.js NAPI wrapper.
Changes:
- Implemented user-module storage/CRUD on
JSSandboxand registration into the guest before handlers load. - Added guest-side lazy module resolution/loading plus a
register_moduleguest function. - Added NAPI/JS wrapper APIs, docs, examples, and comprehensive Rust/JS integration tests.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/js-host-api/tests/user-modules.test.js | New vitest suite covering add/remove/clear + import/lifecycle behaviors via NAPI. |
| src/js-host-api/src/lib.rs | Adds NAPI boundary validation and sync add_module/remove_module/clear_modules methods. |
| src/js-host-api/lib.js | Wraps new sync module methods for error-code enrichment (wrapSync). |
| src/js-host-api/examples/user-modules.js | New Node example demonstrating module registration/imports and shared module state. |
| src/js-host-api/README.md | Documents user module APIs and import conventions; adds a "User Modules" section. |
| src/hyperlight-js/tests/user_modules.rs | New Rust integration tests for module registration/import behavior and lifecycle. |
| src/hyperlight-js/src/sandbox/js_sandbox.rs | Implements module storage, namespace validation, and guest registration ordering. |
| src/hyperlight-js/src/lib.rs | Re-exports module-related constants and validation helpers. |
| src/hyperlight-js/examples/user_modules/main.rs | New Rust example demonstrating user modules and shared state patterns. |
| src/hyperlight-js/Cargo.toml | Registers the new user_modules example target. |
| src/hyperlight-js-runtime/src/main/hyperlight.rs | Adds register_module guest function entrypoint. |
| src/hyperlight-js-runtime/src/lib.rs | Adds UserModuleLoader (resolver+loader) and runtime-side module registration storage. |
| README.md | Updates top-level pointer to JS Host API to mention user modules/host functions. |
| Justfile | Runs the new js-host-api user-modules.js example as part of example runs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
abf128d to
dad2999
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dad2999 to
5ca54f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c72b881 to
3f9aa08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add add_module/remove_module/clear_modules API to JSSandbox, allowing handlers (and other modules) to import reusable ES modules using the 'namespace:name' convention (default namespace: 'user'). Guest runtime: - Add UserModuleLoader (Resolver + Loader) for lazy compilation - Add register_module guest function - Modules compiled on first import, avoiding ordering issues Host library (hyperlight-js): - Add modules HashMap to JSSandbox with full CRUD API - add_module / add_module_ns / remove_module / remove_module_ns / clear_modules - Modules registered before handlers in get_loaded_sandbox() - Export DEFAULT_MODULE_NAMESPACE constant - Namespace validation: 'host' reserved, no colons allowed NAPI wrapper (js-host-api): - Add addModule / removeModule / clearModules on JSSandboxWrapper - Error enrichment wrapping for new sync methods Import capabilities: - User modules can import other user modules - User modules can import built-in modules (crypto, console, etc.) - User modules can import host function modules (host:X) - Missing modules fail at getLoadedSandbox() with clear errors Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
8f8f275 to
dfce084
Compare
rquickjs 0.12 added an Option<ImportAttributes> parameter to both Resolver::resolve and Loader::load. Update UserModuleLoader's impls to match the new trait signatures (E0050 otherwise). Also simplify the empty-module-name guard: trim().is_empty() already covers the empty-string case, so the redundant is_empty() check is removed. Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Add add_module/remove_module/clear_modules API to JSSandbox, allowing handlers (and other modules) to import reusable ES modules using the 'namespace:name' convention (default namespace: 'user').
Guest runtime:
Host library (hyperlight-js):
NAPI wrapper (js-host-api):
Import capabilities: