feat(bloblang): Improve Bloblang playground with Go/WASM migration#570
feat(bloblang): Improve Bloblang playground with Go/WASM migration#570iamramtin wants to merge 24 commits intowarpstreamlabs:mainfrom
Conversation
- Replaced JavaScript integration with Go and WASM instead - Improved WASM API exposure and updated JS integration - Added full syntax support to formatter (operators, keywords, pipes) Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
…lidation API - Moved documentation HTML generation from JS to Go - Pre-generate docHTML for functions/methods - Added validation function - Added JSON utilities (format/minify/validate) with WASM and HTTP endpoints - Updated JS to prioritise WASM with native fallbacks - Centralized WASM function registration Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
- Tests core functions: execute, validate, syntax, format, autocomplete - Tests JSON utilities: formatJSON, minifyJSON, validateJSON Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
- Replace hardcoded values with CSS variables - Remove duplicate CSS rules - Fix mobile responsive layout - Add Bento-themed scrollbars to all editors Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Also simplified WASM initialization and auto-register server/WASM handlers. Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
- Remove redundant JSON utilities from Go/WASM (use native JS instead) - Extract BloblangAPI abstraction layer for WASM/server routing - Remove unused code and dead methods - Improve error handling and WASM initialization flow - Improve UX Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
0b9da37 to
0d0b520
Compare
- Fix type mismatch in getCompletions() for functionSpecWithHTML/methodSpecWithHTML - Improve autocompletion suggestions for Bloblang keywords - Add tests to verify completion types and structure Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
0d0b520 to
fe4aa15
Compare
a6dd66b to
4e96b2c
Compare
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
4e96b2c to
b98ab91
Compare
|
Hey @gregfurman @jem-davies just a friendly ping to see if we can get this merged in? |
|
@iamramtin hey! Thanks for the ping and sorry for delay, will give this a priority review 👍 |
gregfurman
left a comment
There was a problem hiding this comment.
I'll do another pass but have left some comments on structure and the pattern(s) used. Lmk thoughts!
| type FormatMappingResponse struct { | ||
| Success bool `json:"success"` | ||
| Formatted string `json:"formatted"` | ||
| Error string `json:"error,omitempty"` |
There was a problem hiding this comment.
I think we can use the globally available Error function from the JS environment i.e
var errorResp FormatMappingResponse
err := js.Global().Get("Error").New(errorResp.Error)
panic(err) // or maybe ignore if errorThen we can treat the error case as a JS-level error and handle with a try-catch instead of this error payload approach.
Also, that way we don't need to pass around an error attribute and can focus on payload responses.
wdyt?
|
|
||
| // FunctionSpecWrapper wraps query.FunctionSpec to implement Spec interface | ||
| type FunctionSpecWrapper struct { | ||
| query.FunctionSpec |
There was a problem hiding this comment.
I don't think the entire struct needs to be embedded here since you're just using some attributes. Consider
| query.FunctionSpec | |
| spec query.FunctionSpec |
and then
func (f FunctionSpecWrapper) GetDescription() string { return f.spec.Description }There was a problem hiding this comment.
Good call, I think this explicitness is much better 👍
| } | ||
|
|
||
| // Spec represents a unified interface for function and method specs | ||
| type Spec interface { |
There was a problem hiding this comment.
Why not use a dedicated Spec struct here instead with the attributes we need? Feels like 2 more structs + an interface is a bit of overkill.
There was a problem hiding this comment.
How would you feel about me adding a BaseSpec to internal/bloblang/query/docs.go and having FunctionSpec and MethodSpec embed those shared attributes instead of duplicating all this logic in this file?
There was a problem hiding this comment.
See commit 407ffa62b and LMK what you think, this is non-breaking and fully compatible and should let me not have to redeclare these shared attributes
There was a problem hiding this comment.
And follow up 1da4e310a to see how it affects the current code
…nd MethodSpec Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
Signed-off-by: Ramtin Mesgari <26694963+iamramtin@users.noreply.github.com>
|
@gregfurman addressed comments, LMK WYT 🏁 |
| } | ||
| } | ||
|
|
||
| // Test validate (Bloblang validation) |
There was a problem hiding this comment.
| // Test validate (Bloblang validation) |
| } | ||
|
|
||
| // formatBloblang formats Bloblang code with indentation and consistent spacing | ||
| func formatBloblang(originalMapping string) (string, error) { |
There was a problem hiding this comment.
ok wow I can't pretend to say I understand much of what is happening here re: all of this parsing. How did we do it previously in the playground?
There was a problem hiding this comment.
Would it be possible to revert this refactor? I'm finding it a bit tough to see what was added versus what was refactored
There was a problem hiding this comment.
I understand the difficulty in reviewing this as a mixed change, but I'd prefer not to revert as most of the diff is structural rather than behavioural
The refactor separates server lifecycle, routing, and handlers into explicit types and methods, removes large inline closures, and centralises the state into a server type. This was necessary to make this file more idiomatic when adding the new endpoints cleanly without further growing what was previously essentially just a single function
Functionally, behaviuor is the same, main change is turning implicit structure into explicit structure so future additions don't compound the layout
I’m happy to walk through the structure or split follow-ups if that helps
| // ------------------------------------------------------------------------------ | ||
|
|
||
| // BaseSpec contains fields shared by function and method specifications. | ||
| type BaseSpec struct { |
There was a problem hiding this comment.
Thoughts on just having a custom struct inside the blobl package that maps FunctionSpec or MethodSpec to a common single type? That way, the internal/bloblang functionality does not need to be touched at all and we can keep this unified approach logic where its needed
6503d67 to
62a32b8
Compare
78f3ab1 to
bf9d364
Compare
Summary
Improves the Bloblang playground by migrating core logic from JavaScript to Go/WASM.
The playground previously duplicated some of Bloblang logic in JavaScript, creating maintenance overhead and potential inconsistencies. By moving to Go/WASM, we:
Changes
Go/WASM Migration:
JavaScript Simplification:
Other Improvements:
Testing
1. Run Unit Tests
2. Test Server Mode (Go backend via HTTP)
Visit playground and verify:
3. Test WASM Mode (Client-side execution)
Visit the playground in the docs and verify:
Breaking Changes
None