Skip to content

Commit

Permalink
Automatically applying Prettier changes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 30, 2024
1 parent e53b36e commit 010281d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 31 deletions.
14 changes: 7 additions & 7 deletions JS/jsonnet/src/jsonnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ if (!isArakoo) {
let vm = this.#getVm();
return __jsonnet_evaluate_file(vm, filename);
}

javascriptCallback(name, func) {
let numOfArgs = func.length;
console.debug("Constructor name is: ", func.constructor.name);
if (func.constructor && func.constructor.name === "AsyncFunction"){
console.debug("In if part")
if (func.constructor && func.constructor.name === "AsyncFunction") {
console.debug("In if part");
if (numOfArgs > 0) {
this.#setFunc(name,async (args) => {
console.debug("Args recieved in async function: ", args)
this.#setFunc(name, async (args) => {
console.debug("Args recieved in async function: ", args);
let result = await eval(func)(...JSON.parse(args));
return result.toString();
});
Expand All @@ -102,10 +102,10 @@ if (!isArakoo) {
});
}
} else {
console.debug("In else part")
console.debug("In else part");
if (numOfArgs > 0) {
this.#setFunc(name, (args) => {
console.debug("Args recieved: ", args)
console.debug("Args recieved: ", args);
let result = eval(func)(...JSON.parse(args));
return result.toString();
});
Expand Down
55 changes: 31 additions & 24 deletions JS/wasm/examples/ec-wasmjs-hono/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let jsonnet = new Jsonnet();
const app = new Hono();

function greet() {
return "Hello from JS";
return "Hello from JS";
}

const env = {};
Expand All @@ -33,7 +33,7 @@ app.get("/", (c) => {
});

app.get("/func", (c) => {
const code = `
const code = `
local username = std.extVar('name');
local Person(name='Alice') = {
name: name,
Expand All @@ -44,38 +44,42 @@ app.get("/func", (c) => {
person2: Person('Bob'),
result : arakoo.native("greet")()
}`;
let result = jsonnet.extString("name", "ll").javascriptCallback("greet", greet).evaluateSnippet(code);
return c.json(JSON.parse(result));
let result = jsonnet
.extString("name", "ll")
.javascriptCallback("greet", greet)
.evaluateSnippet(code);
return c.json(JSON.parse(result));
});

app.get("/async-func/:id", async (c) => {
let id = c.req.param("id");
async function asyncGetAtodo(id) {
try {
let response = await fetch(`https://jsonplaceholder.typicode.com/todos/${id}`);
let body = await response.json();
return JSON.stringify(body);
} catch (error) {
console.log("error occured");
console.log(error);
return c.json(output);
let id = c.req.param("id");
async function asyncGetAtodo(id) {
try {
let response = await fetch(`https://jsonplaceholder.typicode.com/todos/${id}`);
let body = await response.json();
return JSON.stringify(body);
} catch (error) {
console.log("error occured");
console.log(error);
return c.json(output);
}
}
}

let result = jsonnet.extString("id", id).javascriptCallback("getAtodo", asyncGetAtodo).evaluateSnippet(`
let result = jsonnet.extString("id", id).javascriptCallback("getAtodo", asyncGetAtodo)
.evaluateSnippet(`
local todo = std.parseJson(arakoo.native("getAtodo")(std.extVar("id")));
{
result : todo.title
}`);
return c.json(JSON.parse(result));
return c.json(JSON.parse(result));
});

app.get("/add", (c) => {
function add(arg1, arg2, arg3) {
console.log("Args recieved: ", arg1, arg2, arg3);
return arg1 + arg2 + arg3;
}
const code = `
function add(arg1, arg2, arg3) {
console.log("Args recieved: ", arg1, arg2, arg3);
return arg1 + arg2 + arg3;
}
const code = `
local username = std.extVar('name');
local Person(name='Alice') = {
name: name,
Expand All @@ -86,8 +90,11 @@ app.get("/add", (c) => {
person2: Person('Bob'),
result : arakoo.native("add")(1,2,3)
}`;
let result = jsonnet.extString("name", "ll").javascriptCallback("add", add).evaluateSnippet(code);
return c.json(JSON.parse(result));
let result = jsonnet
.extString("name", "ll")
.javascriptCallback("add", add)
.evaluateSnippet(code);
return c.json(JSON.parse(result));
});

app.get("/file", (c) => {
Expand Down

0 comments on commit 010281d

Please sign in to comment.