inngest
Version:
Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.
73 lines (71 loc) • 1.89 kB
JavaScript
const require_InngestCommHandler = require('../components/InngestCommHandler.cjs');
//#region src/deno/fresh.ts
/**
* An adapter for Deno's Fresh to serve and register any declared functions with
* Inngest, making them available to be triggered by events.
*
* @example
* ```ts
* import { serve } from "https://esm.sh/inngest/deno/fresh";
* import { inngest } from "./src/inngest/client.ts";
* import fnA from "./src/inngest/fnA"; // Your own function
*
* export const handler = serve({
* client: inngest,
* functions: [fnA],
* });
* ```
*
* @module
*/
/**
* The name of the framework, used to identify the framework in Inngest
* dashboards and during testing.
*/
const frameworkName = "deno/fresh";
/**
* With Deno's Fresh framework, serve and register any declared functions with
* Inngest, making them available to be triggered by events.
*
* @example
* ```ts
* import { serve } from "https://esm.sh/inngest/deno/fresh";
* import { inngest } from "./src/inngest/client.ts";
* import fnA from "./src/inngest/fnA"; // Your own function
*
* export const handler = serve({
* client: inngest,
* functions: [fnA],
* });
* ```
*
* @public
*/
const serve = (options) => {
const fn = new require_InngestCommHandler.InngestCommHandler({
frameworkName,
...options,
handler: (req, env) => {
return {
body: () => req.text(),
headers: (key) => req.headers.get(key),
method: () => req.method,
env: () => env,
url: () => new URL(req.url, `https://${req.headers.get("host") || ""}`),
transformResponse: ({ body, status, headers }) => {
return new Response(body, {
status,
headers
});
}
};
}
}).createHandler();
return function handleRequest(req, ...other) {
return fn(req, Deno.env.toObject(), ...other);
};
};
//#endregion
exports.frameworkName = frameworkName;
exports.serve = serve;
//# sourceMappingURL=fresh.cjs.map