-
Notifications
You must be signed in to change notification settings - Fork 6
Wasm integration #47
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
Merged
Wasm integration #47
Changes from 43 commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
aae8c2d
working wasm implementation
Sreedeep-rougeloop 7a60260
fixing the promise
Sreedeep-rougeloop 0afffff
got the result back to web from wasm
Sreedeep-rougeloop 8d61989
promise return working
Sreedeep-rougeloop 2d1e752
bug fix
Sreedeep-rougeloop 888cb6a
widget basic working design
Sreedeep-rougeloop 67787e2
removing goja dependancy
Sreedeep-rougeloop 17b350b
removing goja dependancy
Sreedeep-rougeloop 5470ef5
removing zerolog completely
Sreedeep-rougeloop 4bc3708
Removed net http dependancy
Sreedeep-rougeloop 1894b80
proxy chenges
Sreedeep-rougeloop 4a40c6d
addings an common wokspace
Sreedeep-rougeloop 19d3e4c
Fixed proxy url
RijulTP 8d25a15
removing some useles code
Sreedeep-rougeloop 2f68122
Different files for wasm and cli build
Sreedeep-rougeloop 4e20d80
Removing comments conveting to wasm build files
Sreedeep-rougeloop 6df60ba
Add cleaning the commnets
Sreedeep-rougeloop ef7305e
cleaning code
Sreedeep-rougeloop 5e645f0
removing zerolog comments
Sreedeep-rougeloop 9886c29
fixing workflow
Sreedeep-rougeloop 703c800
fixing workflow
Sreedeep-rougeloop 61cb447
Removing zerolog
Sreedeep-rougeloop 4754562
removing comments and unused code
Sreedeep-rougeloop 6a97e0b
Removing unused dependeny
Sreedeep-rougeloop 8eadb84
removing duplication
Sreedeep-rougeloop 7eb34be
Fixed duplication in controller, lama2cmd and outputmanager
RijulTP a48a9cf
intermediate commit
Sreedeep-rougeloop 66236db
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop f77c1c5
adressing the code repetetion issues
Sreedeep-rougeloop 5c87003
fixing code repetetion
Sreedeep-rougeloop e0f3fdf
fixed cli build
Sreedeep-rougeloop 69f0dce
Fixed the testcases failing issues
Sreedeep-rougeloop 8a14d44
handling usename in env
Sreedeep-rougeloop 6b09d77
Removing code duplication
Sreedeep-rougeloop 8996428
removing reduntant deps
Sreedeep-rougeloop b2a0856
updated the httpie-go version to latest
Sreedeep-rougeloop b6e9594
fixing yams addind tag for test
Sreedeep-rougeloop b797654
fixing output parsing issues
Sreedeep-rougeloop 2cd120c
removing unused imports
Sreedeep-rougeloop 8cd876f
Removing reduntant code
Sreedeep-rougeloop 8619733
fixed some code duplccation remaining
Sreedeep-rougeloop 22bb77e
fixing major code duplications in expandvar and preprocess
Sreedeep-rougeloop 5fb6459
removing preprocess.wasm
Sreedeep-rougeloop a7364fc
fixing small errr in expandvar
Sreedeep-rougeloop e0eee8b
fixed the null point issue with VM
Sreedeep-rougeloop 18ff371
removed unused imports
Sreedeep-rougeloop c915394
adding old error message back
Sreedeep-rougeloop fbf3f64
Added 2 more tests \n 1.Wrong file format error check \n 2. Multipart…
Sreedeep-rougeloop c49c7f0
implementing wasm code converter
Sreedeep-rougeloop f441a82
removing some unused files
Sreedeep-rougeloop b4457e6
code converter for multipart
Sreedeep-rougeloop 3af3893
added a return promise for code converter
Sreedeep-rougeloop b702455
converted vm type to interface
Sreedeep-rougeloop 0a8782f
fixed cli build
Sreedeep-rougeloop ae09eed
Fixed wasm build
RijulTP 568a2ec
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
RijulTP 65449ae
Converter expandvar to webworkers
RijulTP e6ec4bc
Removing goja dependency for wasm
RijulTP a84f7e3
Adding webworkers
RijulTP a7e344e
fixing the datastructure build issue
Sreedeep-rougeloop 6d04379
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop 02a12fa
fixed play button
Sreedeep-rougeloop f8f95f5
fixed code convertion using browser js interpreter
Sreedeep-rougeloop 782c193
Fixing deadlock issue
RijulTP e99b903
Fixed sync issue in expand var webworkers
RijulTP 9673ba3
Fixed result variable issue in chain request
RijulTP 3c0ae3f
Renamed webworker file
RijulTP 98953f7
Fixed cli build issue
RijulTP 7ab6474
Added seperator
Sreedeep-rougeloop 30e22e3
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop bf4e836
Removed unwanted code
RijulTP f7d6312
Issue: Heap overflow
Sreedeep-rougeloop dcc4bd4
Merge branch 'Wasm' of github.com:HexmosTech/Lama2 into Wasm
Sreedeep-rougeloop 4a22fad
added inlining to silence heap failing
Sreedeep-rougeloop df60536
Removed httpsnippet log
RijulTP 69693ce
Fixed build issues
RijulTP 704ce78
Embedded workerjs file
RijulTP e54872d
Added correction to pyhon and js single stage code convert
Sreedeep-rougeloop 5dd3417
Added support for php
Sreedeep-rougeloop 4a79319
Updated httpsnippet
RijulTP fffc451
Updated httpiego
RijulTP e741821
Added new httpe vesion
Sreedeep-rougeloop c457908
pulled changes
RijulTP 3e92c17
fixing merge conflicts
Sreedeep-rougeloop 8a1625d
Merge remote-tracking branch 'origin/main' into Wasm
Sreedeep-rougeloop 4ebde26
fixing the mkdocs build
Sreedeep-rougeloop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
build/ | ||
lama2 | ||
.vscode | ||
buildAndPublish.sh | ||
static/ | ||
.env |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//go:build wasm | ||
|
||
// Package `cmdexec` provides a facility to execute | ||
// l2 commands, stream output to stdout, while also | ||
// providing ability to retrieve the command output as | ||
// a string. | ||
package cmdexec | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"strings" | ||
|
||
"github.com/HexmosTech/httpie-go" | ||
) | ||
|
||
// ExecCommand changes directory to the given `apiDir` | ||
// and then executes the command specified in `cmdStr` | ||
// During command execution, ExecCommand streams output | ||
// to stdout. | ||
// Once execution finishes, previous CWD is restored, | ||
// and the command output is returned as a string | ||
func ExecCommand(cmdSlice []string, stdinBody string, apiDir string) (httpie.ExResponse, error) { | ||
proxyURL := os.Getenv("PROXY_URL") | ||
proxyUserName := os.Getenv("PROXY_USERNAME") | ||
proxyUserPassword := os.Getenv("PROXY_PASSWORD") | ||
allowRedirects := true | ||
resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), proxyURL, proxyUserName, proxyUserPassword, allowRedirects) | ||
if err != nil { | ||
fmt.Println("Got error while executing", err) | ||
return httpie.ExResponse{}, errors.New("Error from API executor: " + err.Error()) | ||
} | ||
return resp, nil | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//go:build wasm | ||
|
||
package cmdexec | ||
|
||
import ( | ||
"syscall/js" | ||
|
||
"github.com/dop251/goja" | ||
) | ||
|
||
func RunVMCode(jsCode string, vm *goja.Runtime) { | ||
js.Global().Call("eval", jsCode) | ||
} | ||
|
||
// The GenerateChainCode function creates a JavaScript code snippet | ||
// that attempts to parse a given HTTP response body as JSON, logging | ||
// success or failure, and stores the result accordingly. | ||
func GenerateChainCode(httpRespBody string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment on what this function is doing? what is generate chain code? |
||
code := `try { | ||
result = JSON.parse(String.raw` + "`" + httpRespBody + "`" + `) | ||
console.log("Stored as JSON") | ||
} catch (e) { | ||
result = String.raw` + "`" + httpRespBody + "`" + ` | ||
console.log(e) | ||
console.log("Stored as string") | ||
}` | ||
return code | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build cli | ||
|
||
package cmdgen | ||
|
||
import ( | ||
"github.com/HexmosTech/gabs/v2" | ||
"github.com/HexmosTech/lama2/lama2cmd" | ||
) | ||
|
||
func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string, string) { | ||
httpv, url, jsonObj, headers, multipartBool, formBool := ConstructCommandHelper(parsedInput) | ||
res, stdinBody := assembleCmdString(httpv, url, jsonObj, headers, multipartBool, formBool, o) | ||
return res, stdinBody | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,40 +12,27 @@ import ( | |
|
||
"github.com/HexmosTech/gabs/v2" | ||
"github.com/HexmosTech/lama2/lama2cmd" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// The assembleCmdString function constructs a httpie | ||
// command string for an HTTP request based on the provided | ||
// HTTP method, URL, JSON object, headers, and options. It also | ||
// handle multipart and form data. | ||
func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, headers *gabs.Container, multipart bool, form bool, o *lama2cmd.Opts) ([]string, string) { | ||
command := make([]string, 0) | ||
log.Info(). | ||
Str("Type", "Construct Command"). | ||
Str("httpv", httpv). | ||
Str("url", url). | ||
Bool("multipart", multipart). | ||
Bool("form", form). | ||
Msg(fmt.Sprint("Construct parameters")) | ||
|
||
log.Debug(). | ||
Str("JSONObj", jsonObj.String()). | ||
Str("Headers", headers.String()).Msg("") | ||
|
||
var files *gabs.Container | ||
if multipart { | ||
if jsonObj.ExistsP("@files") { | ||
files = jsonObj.S("@files") | ||
log.Debug().Str("Files", files.String()).Msg("") | ||
jsonObj.Delete("@files") | ||
log.Trace().Str("Shortened JsonObj", jsonObj.String()).Msg("") | ||
} | ||
} | ||
|
||
jsonStr := "" | ||
if jsonObj != nil && !multipart && !form { | ||
dst := &bytes.Buffer{} | ||
if err := json.Compact(dst, []byte(jsonObj.String())); err != nil { | ||
log.Fatal(). | ||
Str("Error", err.Error()). | ||
Msg("Couldn't minify JSON") | ||
fmt.Println(err) | ||
} | ||
jsonStr = dst.String() | ||
} | ||
|
@@ -58,7 +45,7 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header | |
}*/ | ||
|
||
command = append(command, "ht ") | ||
if o.Nocolor { | ||
if o != nil && o.Nocolor { | ||
command = append(command, "--pretty=none ") | ||
} | ||
if multipart || form { | ||
|
@@ -70,7 +57,8 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header | |
|
||
if multipart { | ||
for key, val := range jsonObj.Data().(*gabs.Container).ChildrenMap() { | ||
command = append(command, "'"+key+"'='"+val.Data().(string)+"' ") | ||
keyValuePair := fmt.Sprintf("%s=%s", key, val.Data().(string)) | ||
command = append(command, keyValuePair) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these changes tested? |
||
} | ||
for key, val := range files.ChildrenMap() { | ||
command = append(command, key+"@"+val.Data().(string)) | ||
|
@@ -79,7 +67,7 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header | |
|
||
if form { | ||
for key, val := range jsonObj.Data().(*gabs.Container).ChildrenMap() { | ||
keyValuePair := fmt.Sprintf("'%s'='%s' ", key, val.Data().(string)) | ||
keyValuePair := fmt.Sprintf("%s=%s", key, val.Data().(string)) | ||
command = append(command, keyValuePair) | ||
} | ||
} | ||
|
@@ -104,20 +92,17 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header | |
// API file inputs, figures out the type of target command | ||
// and finally generates a string representing the generated | ||
// command | ||
func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string, string) { | ||
log.Info().Str("ParsedInput", parsedInput.String()).Msg("") | ||
func ConstructCommandHelper(parsedInput *gabs.Container) (string, string, *gabs.Container, *gabs.Container, bool, bool) { | ||
httpv := parsedInput.S("verb", "value") | ||
url := parsedInput.S("url", "value") | ||
jsonObj := parsedInput.S("details", "ip_data") | ||
headers := parsedInput.S("details", "headers") | ||
multipart := parsedInput.S("multipart", "value") | ||
form := parsedInput.S("form", "value") | ||
multipartBool := false | ||
if multipart != nil { | ||
multipartBool = true | ||
} | ||
form := parsedInput.S("form", "value") | ||
formBool := form != nil | ||
|
||
res, stdinBody := assembleCmdString(httpv.Data().(string), url.Data().(string), jsonObj, headers, multipartBool, formBool, o) | ||
return res, stdinBody | ||
return httpv.Data().(string), url.Data().(string), jsonObj, headers, multipartBool, formBool | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build wasm | ||
|
||
package cmdgen | ||
|
||
import ( | ||
"github.com/HexmosTech/gabs/v2" | ||
"github.com/HexmosTech/lama2/lama2cmd" | ||
) | ||
|
||
func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string, string) { | ||
httpv, url, jsonObj, headers, multipartBool, formBool := ConstructCommandHelper(parsedInput) | ||
res, stdinBody := assembleCmdString(httpv, url, jsonObj, headers, multipartBool, formBool, nil) | ||
return res, stdinBody | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//go:build cli | ||
|
||
// Package controller coordinates all the other | ||
// components in the `Lama2` project. The high | ||
// level overview of command execution is easily | ||
// understood from this package | ||
package contoller | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/HexmosTech/gabs/v2" | ||
"github.com/HexmosTech/httpie-go" | ||
"github.com/HexmosTech/lama2/cmdexec" | ||
"github.com/HexmosTech/lama2/codegen" | ||
"github.com/HexmosTech/lama2/lama2cmd" | ||
outputmanager "github.com/HexmosTech/lama2/outputManager" | ||
"github.com/HexmosTech/lama2/parser" | ||
"github.com/HexmosTech/lama2/preprocess" | ||
"github.com/HexmosTech/lama2/prettify" | ||
"github.com/HexmosTech/lama2/utils" | ||
"github.com/dop251/goja" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func ExecuteProcessorBlock(block *gabs.Container, vm *goja.Runtime) httpie.ExResponse { | ||
return ExecuteProcessorBlockHelper(block, vm) | ||
} | ||
|
||
// func ExecuteRequestorBlock(block *gabs.Container, vm *goja.Runtime, opts *lama2cmd.Opts, dir string) httpie.ExResponse { | ||
// return ExecuteRequestorBlockHelper(block, vm, opts, dir) | ||
// } | ||
|
||
func HandleParsedFile(parsedAPI *gabs.Container, o *lama2cmd.Opts, dir string) (httpie.ExResponse, *lama2cmd.Opts) { | ||
vm := cmdexec.GetJSVm() | ||
return HandleParsedFileHelper(parsedAPI, o, dir, vm) | ||
} | ||
|
||
// Process initiates the following tasks in the given order: | ||
// 1. Parse command line arguments | ||
// 2. Read API file contents | ||
// 3. Expand environment variables in API file | ||
// 4. Parse the API contents | ||
// 5. Generate API request command | ||
// 6. Execute command & retrieve results | ||
// 7. Optionally, post-process and write results to a JSON file | ||
func Process(version string) { | ||
o := lama2cmd.GetAndValidateCmd(os.Args) | ||
lama2cmd.ArgParsing(o, version) | ||
|
||
apiContent := preprocess.GetLamaFileAsString(o.Positional.LamaAPIFile) | ||
_, dir, _ := utils.GetFilePathComponents(o.Positional.LamaAPIFile) | ||
oldDir, _ := os.Getwd() | ||
utils.ChangeWorkingDir(dir) | ||
|
||
preprocess.LoadEnvironments(dir) | ||
utils.ChangeWorkingDir(oldDir) | ||
p := parser.NewLama2Parser() | ||
parsedAPI, e := p.Parse(apiContent) | ||
if o.Convert != "" { | ||
codegen.GenerateTargetCode(o.Convert, parsedAPI) | ||
return | ||
} | ||
|
||
if o.Prettify { | ||
prettify.Prettify(parsedAPI, p.Context, p.MarkRange, apiContent, o.Positional.LamaAPIFile) | ||
return | ||
} | ||
|
||
if e != nil { | ||
log.Fatal(). | ||
Str("Type", "Controller"). | ||
Str("LamaFile", o.Positional.LamaAPIFile). | ||
Str("Error", e.Error()). | ||
Msg("Parse Error") | ||
} | ||
log.Debug().Str("Parsed API", parsedAPI.String()).Msg("") | ||
res, out := HandleParsedFile(parsedAPI, o, dir) | ||
if out.Output != "" { | ||
outputmanager.WriteJSONOutput(res, out.Output) | ||
} | ||
} | ||
|
||
func ExecuteRequestorBlockHelper(resp httpie.ExResponse, headersString string, e1 error, vm *goja.Runtime) httpie.ExResponse { | ||
if e1 == nil { | ||
chainCode := cmdexec.GenerateChainCode(resp.Body) | ||
cmdexec.RunVMCode(chainCode, vm) | ||
} else { | ||
fmt.Printf("Error from ExecCommand", e1) | ||
os.Exit(1) | ||
} | ||
return resp | ||
} |
Oops, something went wrong.
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.
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.
Is this done only for ones with tag cli, are there any other tags
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.
yes there is
wasm
tag also currently build is failing , checking that now