feat: fetch effect (#1605)

* feat: fetch effect

* fix: Make not available in sandbox

* chore: Update to use text(), and to use headers

* chore: use the postman echo for testing

* chore: add json

* chore: Testing the json

* chore: Make the json lazy
This commit is contained in:
J M
2022-07-01 17:05:01 -06:00
committed by GitHub
parent b580f549a6
commit 8ba932aa36
7 changed files with 647 additions and 1 deletions

View File

@@ -51,6 +51,20 @@ const warn = (x) => Deno.core.opSync("log_warn", x);
const error = (x) => Deno.core.opSync("log_error", x);
const debug = (x) => Deno.core.opSync("log_debug", x);
const info = (x) => Deno.core.opSync("log_info", x);
const fetch = async (url, options = null) => {
const {body, ...response} = await Deno.core.opAsync("fetch", url, options);
const textValue = Promise.resolve(body)
return {
...response,
text() {
return textValue
},
json() {
return textValue.then(x => JSON.parse(x))
}
}
};
const currentFunction = Deno.core.opSync("current_function");
const input = Deno.core.opSync("get_input");
@@ -66,6 +80,7 @@ const effects = {
trace,
info,
isSandboxed,
fetch,
removeFile,
createDir,
removeDir,