-
Notifications
You must be signed in to change notification settings - Fork 38
refactor(38512) Add JS validation to the Data Hub scripts #1327
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
base: master
Are you sure you want to change the base?
Conversation
Coverage Report
|
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
This PR implements JavaScript validation for Data Hub scripts using the TypeScript Compiler API, replacing the previously disabled new Function() approach that had security concerns. The solution provides synchronous validation that integrates cleanly with RJSF's customValidate function.
Key changes:
- Added TypeScript Compiler API-based validation (
tsValidator.ts) for synchronous JavaScript syntax checking - Created Monaco-based async validation hooks (
useJavaScriptValidation) as an alternative approach - Integrated validation into
ScriptEditorusing the synchronous TypeScript compiler approach - Added comprehensive test coverage (468 unit tests for tsValidator, 149 for useJavaScriptValidation hook, 275 for javascriptValidator)
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
useJavaScriptValidation.ts |
React hook for Monaco-based async validation with graceful degradation |
useJavaScriptValidation.spec.ts |
Test suite for validation hook (149 tests) |
tsValidator.ts |
Synchronous JavaScript validation using TypeScript Compiler API |
tsValidator.spec.ts |
Comprehensive test suite for synchronous validator (468 tests) |
javascriptValidator.ts |
Monaco-based async validator implementation |
javascriptValidator.spec.ts |
Test suite for Monaco validator (275 tests) |
index.ts |
Exports for validation module |
ScriptEditor.tsx |
Integration of synchronous validation into form's customValidate |
ScriptEditor.spec.cy.tsx |
New Cypress tests for validation integration (323 new lines) |
protobuf.config.ts |
Added type annotation for language list |
datahub-commands.ts |
Added type annotation for model parameter |
CodeEditor.Protobuf.spec.cy.tsx |
Added type annotations for language arrays |
package.json |
Upgraded monaco-editor to 0.55.1, added js-yaml override |
check-frontend.yml |
Increased Node memory to 8GB for TypeScript compiler |
| Documentation files | Added extensive task documentation and testing guidelines |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hivemq-edge-frontend/src/extensions/datahub/components/forms/monaco/validation/tsValidator.ts
Show resolved
Hide resolved
...edge-frontend/src/extensions/datahub/components/forms/monaco/CodeEditor.Protobuf.spec.cy.tsx
Show resolved
Hide resolved
...nd/src/extensions/datahub/components/forms/monaco/validation/useJavaScriptValidation.spec.ts
Show resolved
Hide resolved
|
oli-hivemq
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.
LGTM 🦣



Pull Request: JavaScript Validation for DataHub Scripts
Kanban Ticket: https://hivemq.kanbanize.com/ctrl_board/57/cards/38512/details/
Note
For context, I'm adding validation to the RJSF infrastructure.
The implementation is the third iteration. A Monaco-based was too complex due to async/sync race conditions
This one is a clean approach BUT (and it's a big but) add 1.6M to the bundle size. I don't think it's worth the effort
Description
This PR adds real-time JavaScript validation to the DataHub Script Editor, transforming how users write transformation functions. Previously, users could save scripts with syntax errors and only discover problems at runtime. Now, users receive instant feedback about syntax problems while editing, with the Save button automatically disabled until errors are resolved.
The enhancement introduces:
Technical Summary
Implementation highlights:
ts.createSourceFile()andts.getPreEmitDiagnostics()) for synchronous validationcustomValidatehook for seamless form validationOut-of-scope
Discrepancies will need to be explored and addressed in future work, as with the integration of the publish's
4xx responses, see https://hivemq.kanbanize.com/ctrl_board/57/cards/38514/details/
BEFORE
Previous Behavior - No Validation
The Script Editor allowed users to save transformation functions without checking for syntax errors:
Limitations:
new Function()validation was disabled due to security concerns (code injection risk)AFTER
https://www.loom.com/share/d4b32ae0b63c48abbc0b514a2486d3c0
New Behavior - Real-Time JavaScript Validation
The Script Editor now validates JavaScript syntax as users type, providing immediate feedback and preventing invalid scripts from being saved.
Key Visual Elements:
Test Coverage
Comprehensive Testing
tsValidator.spec.ts)ScriptEditor.spec.cy.tsx)Performance Impact
Significant impact:
Reviewer Notes
Focus areas for review:
Manual testing suggestions:
function test() {(missing closing brace)function test() { return true; }