Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions cmd/tools/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
package main

import (
"syscall/js"

"github.com/warpstreamlabs/bento/internal/cli/blobl"
"github.com/warpstreamlabs/bento/internal/bloblang"
"github.com/warpstreamlabs/bento/internal/cli/blobl/wasm"
_ "github.com/warpstreamlabs/bento/public/components/pure"
)

// main initializes and exposes Bloblang playground functions to JavaScript via WebAssembly
// main initializes and exposes Bloblang playground functions to JS via WASM.
func main() {
// Executes a Bloblang mapping on a JSON input string and returns the result or error
js.Global().Set("executeBloblangMapping", blobl.ExecuteBloblangMapping())
// Returns Bloblang syntax metadata for editor tooling
js.Global().Set("generateBloblangSyntax", blobl.GenerateBloblangSyntax())
// Indicates when the WASM module is ready for use
js.Global().Set("wasmReady", js.ValueOf(true))

// Keep the Go runtime alive to handle JS calls
select {}
env := bloblang.GlobalEnvironment().WithoutFunctions("env", "file")
wasm.Init(env)
select {} // Keep Go runtime alive to handle JS calls
}
136 changes: 69 additions & 67 deletions internal/bloblang/query/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,33 @@ var (
StatusHidden Status = "hidden"
)

// ------------------------------------------------------------------------------

// BaseSpec contains fields shared by function and method specifications.
type BaseSpec struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

// The release status of the function.
Status Status `json:"status"`

// Name of the method (as it appears in config).
Name string `json:"name"`

// Description of the method purpose (in markdown).
Description string `json:"description,omitempty"`

// Params defines the expected arguments of the method.
Params Params `json:"params"`

// Examples shows general usage for the method.
Examples []ExampleSpec `json:"examples,omitempty"`

// Impure indicates that a method accesses or interacts with the outer
// environment, and is therefore unsafe to execute in shared environments.
Impure bool `json:"impure"`

// Version is the Bento version this component was introduced.
Version string `json:"version,omitempty"`
}

//------------------------------------------------------------------------------

// Function categories.
Expand All @@ -66,43 +93,27 @@ var (
FunctionCategoryFakeData = "Fake Data Generation"
)

// FunctionSpec describes a Bloblang function.
type FunctionSpec struct {
// The release status of the function.
Status Status `json:"status"`
BaseSpec

// A category to place the function within.
Category string `json:"category"`

// Name of the function (as it appears in config).
Name string `json:"name"`

// Description of the functions purpose (in markdown).
Description string `json:"description,omitempty"`

// Params defines the expected arguments of the function.
Params Params `json:"params"`

// Examples shows general usage for the function.
Examples []ExampleSpec `json:"examples,omitempty"`

// Impure indicates that a function accesses or interacts with the outer
// environment, and is therefore unsafe to execute in shared environments.
Impure bool `json:"impure"`

// Version is the Bento version this component was introduced.
Version string `json:"version,omitempty"`
}

// NewFunctionSpec creates a new function spec.
func NewFunctionSpec(category, name, description string, examples ...ExampleSpec) FunctionSpec {
return FunctionSpec{
Status: StatusStable,
Category: category,
Name: name,
Description: description,
Examples: examples,
Params: NewParams(),
BaseSpec: BaseSpec{
Status: StatusStable,
Name: name,
Description: description,
Params: NewParams(),
},
Category: category,
Examples: examples,
}
}

Expand Down Expand Up @@ -144,21 +155,25 @@ func NewDeprecatedFunctionSpec(name, description string, examples ...ExampleSpec
` + description

return FunctionSpec{
Status: StatusDeprecated,
Category: FunctionCategoryDeprecated,
Name: name,
Description: description,
Examples: examples,
Params: NewParams(),
BaseSpec: BaseSpec{
Status: StatusDeprecated,
Name: name,
Description: description,
Params: NewParams(),
},
Examples: examples,
Category: FunctionCategoryDeprecated,
}
}

// NewHiddenFunctionSpec creates a new function spec that is hidden from the docs.
func NewHiddenFunctionSpec(name string) FunctionSpec {
return FunctionSpec{
Status: StatusHidden,
Name: name,
Params: NewParams(),
BaseSpec: BaseSpec{
Status: StatusHidden,
Name: name,
Params: NewParams(),
},
}
}

Expand Down Expand Up @@ -188,42 +203,25 @@ type MethodCatSpec struct {
Examples []ExampleSpec
}

// MethodSpec describes a Bloblang method.
// MethodSpec describes a Bloblang method.
type MethodSpec struct {
// The release status of the function.
Status Status `json:"status"`

// Name of the method (as it appears in config).
Name string `json:"name"`

// Description of the method purpose (in markdown).
Description string `json:"description,omitempty"`

// Params defines the expected arguments of the method.
Params Params `json:"params"`

// Examples shows general usage for the method.
Examples []ExampleSpec `json:"examples,omitempty"`
BaseSpec

// Categories that this method fits within.
Categories []MethodCatSpec `json:"categories,omitempty"`

// Impure indicates that a method accesses or interacts with the outer
// environment, and is therefore unsafe to execute in shared environments.
Impure bool `json:"impure"`

// Version is the Bento version this component was introduced.
Version string `json:"version,omitempty"`
}

// NewMethodSpec creates a new method spec.
func NewMethodSpec(name, description string, examples ...ExampleSpec) MethodSpec {
return MethodSpec{
Name: name,
Status: StatusStable,
Description: description,
Examples: examples,
Params: NewParams(),
BaseSpec: BaseSpec{
Status: StatusStable,
Name: name,
Description: description,
Params: NewParams(),
Examples: examples,
},
}
}

Expand All @@ -232,19 +230,23 @@ func NewMethodSpec(name, description string, examples ...ExampleSpec) MethodSpec
// mappings.
func NewDeprecatedMethodSpec(name, description string, examples ...ExampleSpec) MethodSpec {
return MethodSpec{
Name: name,
Status: StatusDeprecated,
Examples: examples,
Params: NewParams(),
BaseSpec: BaseSpec{
Status: StatusDeprecated,
Name: name,
Params: NewParams(),
Examples: examples,
},
}
}

// NewHiddenMethodSpec creates a new method spec that is hidden from docs.
func NewHiddenMethodSpec(name string) MethodSpec {
return MethodSpec{
Name: name,
Status: StatusHidden,
Params: NewParams(),
BaseSpec: BaseSpec{
Status: StatusHidden,
Name: name,
Params: NewParams(),
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/blobl/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func run(c *cli.Context) error {
return
}

resultStr, err := execCache.executeBloblangMapping(exec, raw, pretty, input)
resultStr, err := execCache.runBloblangExecutor(exec, raw, pretty, input)
if err != nil {
fmt.Fprintln(os.Stderr, red(fmt.Sprintf("failed to execute map: %v", err)))
continue
Expand Down
Loading