genezio
Version:
Command line utility to interact with Genezio infrastructure.
53 lines (52 loc) • 1.61 kB
JavaScript
;
/**
* This is an auto generated code. This code should not be modified since the file can be overwritten
* if new genezio commands are executed.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Remote = void 0;
const replacer = (_, value) => typeof value === "bigint" ? { $bigint: value.toString() } : value;
const reviver = (_, value) => value !== null &&
typeof value === "object" &&
"$bigint" in value &&
typeof value.$bigint === "string"
? BigInt(value.$bigint)
: value;
async function makeRequestBrowser(request, url) {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(request, replacer),
});
const textBody = await response.text();
return JSON.parse(textBody, reviver);
}
/**
* The class through which all request to the Genezio backend will be passed.
*
*/
class Remote {
constructor(url) {
this.url = undefined;
this.agent = undefined;
this.url = url;
}
deserialize(s) {
const e = new Error(s.message);
e.stack = s.stack;
e.info = s.info;
e.code = s.code;
return e;
}
async call(method, ...args) {
const requestContent = { jsonrpc: "2.0", method: method, params: args, id: 3 };
const response = await makeRequestBrowser(requestContent, this.url);
if (response.error) {
throw this.deserialize(response.error);
}
return response.result;
}
}
exports.Remote = Remote;