let sequence = 0;
const host = globalThis.__fetchletClaimHost();
function acknowledgeStart() {
const started = JSON.parse(
host.call(
"fetch.start",
JSON.stringify({
service: "SIGNAL",
redirect: "follow",
request: {
url: "https://signal.test/started",
method: "GET",
headers: [],
body: null,
},
}),
),
);
if (!started.ok) {
throw new Error("Signal service was not installed");
}
host.call("host.poll", "null");
}
globalThis.fetchletExports = {
echo: (value) => value,
add: (left, right) => left + right,
sequence: () => ++sequence,
fail: () => {
throw new Error("guest failure");
},
never: () => {
acknowledgeStart();
return new Promise(() => {});
},
handle: (request, context) => ({
status: 201,
headers: [
["set-cookie", "first=1"],
["set-cookie", "second=2"],
["x-context", context?.name ?? "none"],
],
body: request.body ?? [],
}),
};