Skip to content

Commit

Permalink
Removing comments conveting to wasm build files
Browse files Browse the repository at this point in the history
  • Loading branch information
thekingn committed May 23, 2024
1 parent 2f68122 commit 4e20d80
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 109 deletions.
13 changes: 0 additions & 13 deletions cmdexec/cmdexec.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ import (
"errors"
"fmt"

// "os"
"strings"

"github.com/HexmosTech/httpie-go"
// "github.com/HexmosTech/lama2/utils"
// "github.com/rs/zerolog/log"
// "github.com/HexmosTech/httpie-go"
)

// ExecCommand changes directory to the given `apiDir`
Expand All @@ -26,23 +22,14 @@ import (
// Once execution finishes, previous CWD is restored,
// and the command output is returned as a string
func ExecCommand(cmdSlice []string, stdinBody string) (httpie.ExResponse, error) {
fmt.Println("Inside cmd exec code")
fmt.Println("Inside cmd exec code httpie Integer", httpie.Int(24601))
proxyURL := "https://proxyserver.hexmos.com/"
proxyUserName := "proxyServer"
proxyUserPassword := "proxy22523146server"
allowRedirects := true
resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), proxyURL, proxyUserName, proxyUserPassword, allowRedirects)
// resp, err := httpie.Lama2Entry(cmdSlice, strings.NewReader(stdinBody), "", "", "", false)
fmt.Println("error:", err)
fmt.Println("Data Response:", resp)
if err != nil {
// log.Fatal().Str("Error from the API executor", err.Error()).Msg("")
fmt.Println("Got error while executing", err)
return httpie.ExResponse{}, errors.New("Error from API executor: " + err.Error())
}
// log.Debug().Str("Response body from API executor", resp.Body).Msg("")
// utils.ChangeWorkingDir(oldDir)
// fmt.Println("Reponse fro httpie", resp)
return resp, nil
}
3 changes: 0 additions & 3 deletions cmdexec/js.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
package cmdexec

import (
// "github.com/rs/zerolog/log"
"fmt"
"syscall/js"
)

Expand Down Expand Up @@ -50,6 +48,5 @@ func GenerateChainCode(httpRespBody string) string {
console.log("Stored as string")
}`
// log.Info().Str("Chain code generated", code).Msg("")
fmt.Println("code:", code)
return code
}
2 changes: 0 additions & 2 deletions cmdgen/cmdgen.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"strings"

"github.com/HexmosTech/gabs/v2"
// "github.com/HexmosTech/lama2/lama2cmd"
// "github.com/rs/zerolog/log"
)

func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, headers *gabs.Container, multipart bool, form bool) ([]string, string) {
Expand Down
25 changes: 3 additions & 22 deletions codegen/codegen.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import (
_ "embed"
"fmt"
"strings"
"text/template"
"syscall/js"
// "github.com/rs/zerolog/log"
"text/template"

"github.com/HexmosTech/gabs/v2"
// "github.com/HexmosTech/lama2/cmdexec"
"github.com/HexmosTech/lama2/preprocess"
)

Expand Down Expand Up @@ -136,14 +134,10 @@ func GetRequestHARString(block *gabs.Container) string {
}

func GenerateTargetCode(targetLangLib string, parsedAPI *gabs.Container) {
// initialize()
parsedAPIblocks := parsedAPI.S("value").Data().(*gabs.Container).Children()
convertedSnippetList := make([]string, 0)

for i, block := range parsedAPIblocks {
// log.Debug().Int("Block num", i).Msg("")
fmt.Println(i)
// log.Debug().Str("Block getting processed", block.String()).Msg("")
blockType := block.S("type").Data().(string)
if blockType == "processor" {
snippet := block.S("value").Data().(*gabs.Container).Data().(string)
Expand All @@ -157,21 +151,8 @@ func GenerateTargetCode(targetLangLib string, parsedAPI *gabs.Container) {
snippetArgs.HARRequest = harRequest
snippetArgs.SnippetCore = snippetcore
httpsnippetCode := PrepareHTTPSnippetGenerator(snippetArgs)

// vm := cmdexec.GetJSVm()
// _, e := vm.RunString(httpsnippetCode)
js.Global().Call("eval", httpsnippetCode)

// if e != nil {
// log.Fatal().
// Str("Type", "CodeGen").
// Str("Error", e.Error()).
// Msg("Code generator error")
// }
// Init returns an error if the package is not ready for use.
// convertedSnippet := vm.Get("convertedSnippet").String()

convertedSnippet := js.Global().Get("convertedSnippet").String()
js.Global().Call("eval", httpsnippetCode)
convertedSnippet := js.Global().Get("convertedSnippet").String()
convertedSnippetList = append(convertedSnippetList, convertedSnippet)
}
}
Expand Down
67 changes: 0 additions & 67 deletions controller/controller.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ package contoller
import (
"fmt"
"os"

// "os"

"strings"

"reflect"
Expand All @@ -21,16 +18,9 @@ import (
"github.com/HexmosTech/lama2/cmdexec"
"github.com/HexmosTech/lama2/cmdgen"

// "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/rs/zerolog/log"
"syscall/js"
)

Expand All @@ -40,27 +30,17 @@ func GetParsedAPIBlocks(parsedAPI *gabs.Container) []*gabs.Container {

func ExecuteProcessorBlock(block *gabs.Container) {
b := block.S("value").Data().(*gabs.Container)
// log.Info().Str("Processor block incoming block", block.String()).Msg("")
script := b.Data().(string)
// cmdexec.RunVMCode(script, vm)
fmt.Println("<-----JS CODE----->:", script)
// log.Info().Str("Evaluated through syscall js:", script).Msg("")
js.Global().Call("eval", script)
}

func ExecuteRequestorBlock(block *gabs.Container) httpie.ExResponse {
preprocess.ProcessVarsInBlock(block)
// TODO - replace stuff in headers, and varjson and json as well
cmd, stdinBody := cmdgen.ConstructCommand(block)
fmt.Println("Reached ExecuteRequestorBlock")
resp, e1 := cmdexec.ExecCommand(cmd, stdinBody)
fmt.Println("Command to execute:", cmd)
fmt.Println("Value of e1 lets see:", e1)
printFields(resp)

headers := resp.Headers
fmt.Println("Value of Headders:", headers)

var headersString string
for key, value := range headers {
headersString += fmt.Sprintf("%s: %s\n", key, value)
Expand All @@ -75,25 +55,13 @@ func ExecuteRequestorBlock(block *gabs.Container) httpie.ExResponse {
} else {
fmt.Printf("'%s' is not present in the headers.\n", targetHeader)
if e1 == nil {
fmt.Println("Chain code evaluator")
chainCode := cmdexec.GenerateChainCode(resp.Body)
fmt.Println("chainCode:", chainCode)
js.Global().Call("eval", chainCode)
} else {
fmt.Println("Exiting ........")
os.Exit(1)
}
}

// if e1 == nil {
// fmt.Println("Chain code evaluator")
// chainCode := cmdexec.GenerateChainCode(resp.Body)
// fmt.Println("chainCode:", chainCode)
// js.Global().Call("eval", chainCode)
// } else {
// fmt.Println("Exiting ........")
// os.Exit(1)
// }
return resp
}

Expand All @@ -120,44 +88,9 @@ func HandleParsedFile(parsedAPI *gabs.Container) httpie.ExResponse {
resp = ExecuteRequestorBlock(block)
}
}
// if o.Output != "" {
// outputmanager.WriteJSONOutput(resp, o.Output)
// }
return resp
}

// 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
// }
// HandleParsedFile(parsedAPI)
// }

func ProcessWasmInput(data string) httpie.ExResponse {
apiContent := data
Expand Down
2 changes: 0 additions & 2 deletions l2.wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ func wasmLamaPromise() js.Func {
resolve := args[0]
go func() {
result := controller.ProcessWasmInput(inputdata)
fmt.Println("<-----Result----->:", result)
resultJSON, err := json.Marshal(result)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Result: ", string(resultJSON))
resolve.Invoke(js.ValueOf(string(resultJSON)))
}()
return nil
Expand Down

0 comments on commit 4e20d80

Please sign in to comment.