@upstash/workflow 0.2.8 → 0.2.10-hono-generics

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/h3.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  SDK_TELEMETRY,
3
- serveBase
4
- } from "./chunk-BPUSHNSD.mjs";
3
+ serveBase,
4
+ serveManyBase
5
+ } from "./chunk-IPXJZU3K.mjs";
5
6
 
6
7
  // node_modules/defu/dist/defu.mjs
7
8
  function isPlainObject(value) {
@@ -323,38 +324,56 @@ function transformHeaders(headers) {
323
324
  ]);
324
325
  return formattedHeaders;
325
326
  }
327
+ function getUrl(event) {
328
+ const request_ = event.node.req;
329
+ const protocol = request_.headers["x-forwarded-proto"];
330
+ const host = request_.headers.host;
331
+ const url = `${protocol}://${host}${event.path}`;
332
+ return url;
333
+ }
334
+ var telemetry = {
335
+ sdk: SDK_TELEMETRY,
336
+ framework: "h3",
337
+ runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
338
+ };
326
339
  var serve = (routeFunction, options) => {
327
340
  const handler = defineEventHandler(async (event) => {
328
341
  const method = event.node.req.method;
329
342
  if (method?.toUpperCase() !== "POST") {
330
- return {
331
- status: 405,
332
- body: "Only POST requests are allowed in worklfows"
333
- };
343
+ return new Response("Only POST requests are allowed in worklfows", {
344
+ status: 405
345
+ });
334
346
  }
335
- const request_ = event.node.req;
336
- const protocol = request_.headers["x-forwarded-proto"];
337
- const host = request_.headers.host;
338
- const url = `${protocol}://${host}${event.path}`;
339
- const headers = transformHeaders(request_.headers);
347
+ const url = getUrl(event);
348
+ const headers = transformHeaders(event.node.req.headers);
340
349
  const request = new Request(url, {
341
350
  headers,
342
351
  body: await readRawBody(event),
343
352
  method: "POST"
344
353
  });
345
- const { handler: serveHandler } = serveBase(
346
- routeFunction,
347
- {
348
- sdk: SDK_TELEMETRY,
349
- framework: "h3",
350
- runtime: process.versions.bun ? `bun@${process.versions.bun}/node@${process.version}` : `node@${process.version}`
351
- },
352
- options
353
- );
354
+ const { handler: serveHandler } = serveBase(routeFunction, telemetry, options);
354
355
  return await serveHandler(request);
355
356
  });
356
357
  return { handler };
357
358
  };
359
+ var createWorkflow = (...params) => {
360
+ const [routeFunction, options = {}] = params;
361
+ return {
362
+ routeFunction,
363
+ options,
364
+ workflowId: void 0
365
+ };
366
+ };
367
+ var serveMany = (workflows, options) => {
368
+ return serveManyBase({
369
+ workflows,
370
+ getUrl,
371
+ serveMethod: (...params) => serve(...params).handler,
372
+ options
373
+ });
374
+ };
358
375
  export {
359
- serve
376
+ createWorkflow,
377
+ serve,
378
+ serveMany
360
379
  };
package/hono.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Context } from 'hono';
2
- import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.mjs';
2
+ import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.mjs';
3
3
  import { Variables } from 'hono/types';
4
+ import { s as serveManyBase } from './serve-many-BVDpPsF-.mjs';
4
5
  import '@upstash/qstash';
5
6
  import 'zod';
6
7
  import 'ai';
@@ -14,7 +15,7 @@ type WorkflowBindings = {
14
15
  UPSTASH_WORKFLOW_URL?: string;
15
16
  };
16
17
  /**
17
- * Serve method to serve a Upstash Workflow in a Nextjs project
18
+ * Serve method to serve a Upstash Workflow in a Hono project
18
19
  *
19
20
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
20
21
  *
@@ -22,9 +23,14 @@ type WorkflowBindings = {
22
23
  * @param options workflow options
23
24
  * @returns
24
25
  */
25
- declare const serve: <TInitialPayload = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = object>(routeFunction: RouteFunction<TInitialPayload>, options?: PublicServeOptions<TInitialPayload>) => ((context: Context<{
26
+ declare const serve: <TInitialPayload = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = object, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => ((context: Context<{
26
27
  Bindings: TBindings;
27
28
  Variables: TVariables;
28
29
  }>) => Promise<Response>);
30
+ declare const createWorkflow: <TInitialPayload = unknown, TResult = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = object>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload> | undefined) => InvokableWorkflow<TInitialPayload, TResult>;
31
+ declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => (context: Context<{
32
+ Bindings: WorkflowBindings;
33
+ Variables: object;
34
+ }, any, {}>) => Promise<any>;
29
35
 
30
- export { type WorkflowBindings, serve };
36
+ export { type WorkflowBindings, createWorkflow, serve, serveMany };
package/hono.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Context } from 'hono';
2
- import { R as RouteFunction, k as PublicServeOptions } from './types-B62AnIU3.js';
2
+ import { R as RouteFunction, k as PublicServeOptions, t as InvokableWorkflow } from './types-CYhDXnf8.js';
3
3
  import { Variables } from 'hono/types';
4
+ import { s as serveManyBase } from './serve-many-e4zufyXN.js';
4
5
  import '@upstash/qstash';
5
6
  import 'zod';
6
7
  import 'ai';
@@ -14,7 +15,7 @@ type WorkflowBindings = {
14
15
  UPSTASH_WORKFLOW_URL?: string;
15
16
  };
16
17
  /**
17
- * Serve method to serve a Upstash Workflow in a Nextjs project
18
+ * Serve method to serve a Upstash Workflow in a Hono project
18
19
  *
19
20
  * See for options https://upstash.com/docs/qstash/workflows/basics/serve
20
21
  *
@@ -22,9 +23,14 @@ type WorkflowBindings = {
22
23
  * @param options workflow options
23
24
  * @returns
24
25
  */
25
- declare const serve: <TInitialPayload = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = object>(routeFunction: RouteFunction<TInitialPayload>, options?: PublicServeOptions<TInitialPayload>) => ((context: Context<{
26
+ declare const serve: <TInitialPayload = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = object, TResult = unknown>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload>) => ((context: Context<{
26
27
  Bindings: TBindings;
27
28
  Variables: TVariables;
28
29
  }>) => Promise<Response>);
30
+ declare const createWorkflow: <TInitialPayload = unknown, TResult = unknown, TBindings extends WorkflowBindings = WorkflowBindings, TVariables extends Variables = object>(routeFunction: RouteFunction<TInitialPayload, TResult>, options?: PublicServeOptions<TInitialPayload> | undefined) => InvokableWorkflow<TInitialPayload, TResult>;
31
+ declare const serveMany: (workflows: Parameters<typeof serveManyBase>[0]["workflows"], options?: Parameters<typeof serveManyBase>[0]["options"]) => (context: Context<{
32
+ Bindings: WorkflowBindings;
33
+ Variables: object;
34
+ }, any, {}>) => Promise<any>;
29
35
 
30
- export { type WorkflowBindings, serve };
36
+ export { type WorkflowBindings, createWorkflow, serve, serveMany };