@upstash/workflow 0.1.1-canary-2 → 0.1.2-canary-astro
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/README.md +119 -2
- package/astro.d.mts +9 -0
- package/astro.d.ts +9 -0
- package/astro.js +2128 -0
- package/astro.mjs +18 -0
- package/{chunk-BPN5JBNG.mjs → chunk-EKVRVBHL.mjs} +113 -32
- package/cloudflare.d.mts +4 -2
- package/cloudflare.d.ts +4 -2
- package/cloudflare.js +90 -35
- package/cloudflare.mjs +4 -4
- package/h3.d.mts +7 -5
- package/h3.d.ts +7 -5
- package/h3.js +92 -34
- package/h3.mjs +6 -3
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +88 -33
- package/hono.mjs +2 -2
- package/index.d.mts +41 -4
- package/index.d.ts +41 -4
- package/index.js +113 -32
- package/index.mjs +1 -1
- package/nextjs.d.mts +7 -4
- package/nextjs.d.ts +7 -4
- package/nextjs.js +97 -40
- package/nextjs.mjs +11 -9
- package/package.json +1 -1
- package/solidjs.d.mts +4 -2
- package/solidjs.d.ts +4 -2
- package/solidjs.js +89 -34
- package/solidjs.mjs +3 -3
- package/svelte.d.mts +4 -2
- package/svelte.d.ts +4 -2
- package/svelte.js +90 -35
- package/svelte.mjs +4 -4
- package/{types-CoXaNrxX.d.mts → types-p7sxktVE.d.mts} +23 -9
- package/{types-CoXaNrxX.d.ts → types-p7sxktVE.d.ts} +23 -9
package/README.md
CHANGED
|
@@ -1,3 +1,120 @@
|
|
|
1
|
-
# Upstash Workflow
|
|
1
|
+
# Upstash Workflow SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> **This project is in GA Stage.**
|
|
7
|
+
> The Upstash Professional Support fully covers this project. It receives regular updates, and bug fixes.
|
|
8
|
+
> The Upstash team is committed to maintaining and improving its functionality.
|
|
9
|
+
|
|
10
|
+
**Upstash Workflow** lets you write durable, reliable and performant serverless functions. Get delivery guarantees, automatic retries on failure, scheduling and more without managing any infrastructure.
|
|
11
|
+
|
|
12
|
+
See [the documentation](https://upstash.com/docs/workflow/getstarted) for more details
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
Here, we will briefly showcase how you can get started with Upstash Workflow.
|
|
17
|
+
|
|
18
|
+
Alternatively, you can check [our quickstarts for different frameworks](https://upstash.com/docs/workflow/quickstarts/platforms), including [Next.js](https://upstash.com/docs/qstash/workflow/quickstarts/vercel-nextjs) and [Cloudflare](https://upstash.com/docs/workflow/quickstarts/cloudflare-workers).
|
|
19
|
+
|
|
20
|
+
### Install
|
|
21
|
+
|
|
22
|
+
First, install the package with:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
npm install @upstash/workflow
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Get QStash token
|
|
29
|
+
|
|
30
|
+
Go to [Upstash Console](https://console.upstash.com/qstash) and copy the QSTASH_TOKEN.
|
|
31
|
+
|
|
32
|
+
### Define a Workflow Endpoint
|
|
33
|
+
|
|
34
|
+
To declare workflow endpoints, use the `serve` method:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { serve } from "@upstash/workflow/nextjs";
|
|
38
|
+
|
|
39
|
+
// mock function
|
|
40
|
+
const someWork = (input: string) => {
|
|
41
|
+
return `processed '${JSON.stringify(input)}'`;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// serve endpoint which expects a string payload:
|
|
45
|
+
export const { POST } = serve<string>(async (context) => {
|
|
46
|
+
// get request body:
|
|
47
|
+
const input = context.requestPayload;
|
|
48
|
+
|
|
49
|
+
// run the first step:
|
|
50
|
+
const result1 = await context.run("step1", async () => {
|
|
51
|
+
const output = someWork(input);
|
|
52
|
+
console.log("step 1 input", input, "output", output);
|
|
53
|
+
return output;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// run the second step:
|
|
57
|
+
await context.run("step2", async () => {
|
|
58
|
+
const output = someWork(result1);
|
|
59
|
+
console.log("step 2 input", result1, "output", output);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
In the example, you can see that steps are declared through the `context` object.
|
|
65
|
+
|
|
66
|
+
The kinds of steps which are available are:
|
|
67
|
+
|
|
68
|
+
- `context.run`: execute a function
|
|
69
|
+
- `context.sleep`: sleep for some time
|
|
70
|
+
- `context.sleepUntil`: sleep until some timestamp
|
|
71
|
+
- `context.call`: make a third party call without consuming any runtime
|
|
72
|
+
- `context.waitForEvent`: wait for an event
|
|
73
|
+
- `context.notify`: notify an event to make workflows waiting for the event continue
|
|
74
|
+
|
|
75
|
+
You can [learn more about these methods from our documentation](https://upstash.com/docs/workflow/basics/context).
|
|
76
|
+
|
|
77
|
+
### Workflow Client
|
|
78
|
+
|
|
79
|
+
You can use [the Upstash Workflow client](https://upstash.com/docs/workflow/basics/client) to cancel workflows, notify workflows
|
|
80
|
+
waiting for an event or get the workflows waiting for an event:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Client } from "@upstash/workflow";
|
|
84
|
+
const client = new Client({ token: "<QSTASH_TOKEN>" });
|
|
85
|
+
|
|
86
|
+
// cancel workflow:
|
|
87
|
+
await client.cancel({ workflowRunId: "<WORKFLOW_RUN_ID>" });
|
|
88
|
+
|
|
89
|
+
// notify workflows:
|
|
90
|
+
await client.notify({
|
|
91
|
+
eventId: "my-event-id",
|
|
92
|
+
eventData: "my-data", // data passed to the workflow run
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// get waiters:
|
|
96
|
+
const result = await client.getWaiters({
|
|
97
|
+
eventId: "my-event-id",
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
### Setup
|
|
104
|
+
|
|
105
|
+
This project requires [Bun](https://bun.sh/) to be installed. Please see the [Bun installation documentation](https://bun.sh/docs/installation) for further instructions.
|
|
106
|
+
|
|
107
|
+
Once you have cloned the project, you will need to install the dependencies and then you can run the project.
|
|
108
|
+
|
|
109
|
+
```sh
|
|
110
|
+
bun install
|
|
111
|
+
bun run build
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Testing
|
|
115
|
+
|
|
116
|
+
To begin testing, environment variables will need to be setup. First, create a `.env` file in the root of the project. [`.env.template`](/.env.template) can be used as a template. Your values can be found in the [Qstash Console](https://console.upstash.com/qstash).
|
|
117
|
+
|
|
118
|
+
```sh
|
|
119
|
+
bun run test
|
|
120
|
+
```
|
package/astro.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { APIContext, APIRoute } from 'astro';
|
|
2
|
+
import { b as WorkflowContext, W as WorkflowServeOptions } from './types-p7sxktVE.mjs';
|
|
3
|
+
import '@upstash/qstash';
|
|
4
|
+
|
|
5
|
+
declare function serve<TInitialPayload = unknown>(routeFunction: (workflowContext: WorkflowContext<TInitialPayload>, apiContext: APIContext) => Promise<void>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">): {
|
|
6
|
+
POST: APIRoute;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { serve };
|
package/astro.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { APIContext, APIRoute } from 'astro';
|
|
2
|
+
import { b as WorkflowContext, W as WorkflowServeOptions } from './types-p7sxktVE.js';
|
|
3
|
+
import '@upstash/qstash';
|
|
4
|
+
|
|
5
|
+
declare function serve<TInitialPayload = unknown>(routeFunction: (workflowContext: WorkflowContext<TInitialPayload>, apiContext: APIContext) => Promise<void>, options?: Omit<WorkflowServeOptions<Response, TInitialPayload>, "onStepFinish">): {
|
|
6
|
+
POST: APIRoute;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { serve };
|