@upstash/workflow 0.1.0 → 0.1.1-canary-2
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/{chunk-JDMP6KKR.mjs → chunk-BPN5JBNG.mjs} +96 -11
- package/cloudflare.d.mts +1 -1
- package/cloudflare.d.ts +1 -1
- package/cloudflare.js +77 -2
- package/cloudflare.mjs +1 -1
- package/h3.d.mts +1 -1
- package/h3.d.ts +1 -1
- package/h3.js +77 -2
- package/h3.mjs +1 -1
- package/hono.d.mts +1 -1
- package/hono.d.ts +1 -1
- package/hono.js +77 -2
- package/hono.mjs +1 -1
- package/index.d.mts +14 -6
- package/index.d.ts +14 -6
- package/index.js +96 -11
- package/index.mjs +1 -1
- package/nextjs.d.mts +1 -1
- package/nextjs.d.ts +1 -1
- package/nextjs.js +77 -2
- package/nextjs.mjs +1 -1
- package/package.json +1 -99
- package/solidjs.d.mts +1 -1
- package/solidjs.d.ts +1 -1
- package/solidjs.js +77 -2
- package/solidjs.mjs +1 -1
- package/svelte.d.mts +1 -1
- package/svelte.d.ts +1 -1
- package/svelte.js +77 -2
- package/svelte.mjs +1 -1
- package/{types-CfN1Epuj.d.mts → types-CoXaNrxX.d.mts} +57 -8
- package/{types-CfN1Epuj.d.ts → types-CoXaNrxX.d.ts} +57 -8
package/index.js
CHANGED
|
@@ -1116,6 +1116,23 @@ var sortSteps = (steps) => {
|
|
|
1116
1116
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1117
1117
|
};
|
|
1118
1118
|
|
|
1119
|
+
// src/client/utils.ts
|
|
1120
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1121
|
+
const result = await requester.request({
|
|
1122
|
+
path: ["v2", "notify", eventId],
|
|
1123
|
+
method: "POST",
|
|
1124
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1125
|
+
});
|
|
1126
|
+
return result;
|
|
1127
|
+
};
|
|
1128
|
+
var makeGetWaitersRequest = async (requester, eventId) => {
|
|
1129
|
+
const result = await requester.request({
|
|
1130
|
+
path: ["v2", "waiters", eventId],
|
|
1131
|
+
method: "GET"
|
|
1132
|
+
});
|
|
1133
|
+
return result;
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1119
1136
|
// src/context/steps.ts
|
|
1120
1137
|
var BaseLazyStep = class {
|
|
1121
1138
|
stepName;
|
|
@@ -1274,6 +1291,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1274
1291
|
});
|
|
1275
1292
|
}
|
|
1276
1293
|
};
|
|
1294
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1295
|
+
stepType = "Notify";
|
|
1296
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1297
|
+
super(stepName, async () => {
|
|
1298
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1299
|
+
return {
|
|
1300
|
+
eventId,
|
|
1301
|
+
eventData,
|
|
1302
|
+
notifyResponse
|
|
1303
|
+
};
|
|
1304
|
+
});
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1277
1307
|
|
|
1278
1308
|
// src/context/context.ts
|
|
1279
1309
|
var WorkflowContext = class {
|
|
@@ -1520,6 +1550,38 @@ var WorkflowContext = class {
|
|
|
1520
1550
|
return result;
|
|
1521
1551
|
}
|
|
1522
1552
|
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1555
|
+
* timeout ends
|
|
1556
|
+
*
|
|
1557
|
+
* ```ts
|
|
1558
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1559
|
+
* "wait for event step",
|
|
1560
|
+
* "my-event-id",
|
|
1561
|
+
* 100 // timeout after 100 seconds
|
|
1562
|
+
* );
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1566
|
+
*
|
|
1567
|
+
* ```ts
|
|
1568
|
+
* import { Client } from "@upstash/workflow";
|
|
1569
|
+
*
|
|
1570
|
+
* const client = new Client({ token: });
|
|
1571
|
+
*
|
|
1572
|
+
* await client.notify({
|
|
1573
|
+
* eventId: "my-event-id",
|
|
1574
|
+
* eventData: "eventData"
|
|
1575
|
+
* })
|
|
1576
|
+
* ```
|
|
1577
|
+
*
|
|
1578
|
+
* @param stepName
|
|
1579
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1580
|
+
* @param timeout timeout duration in seconds
|
|
1581
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1582
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1583
|
+
* is the value passed to `client.notify`.
|
|
1584
|
+
*/
|
|
1523
1585
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1524
1586
|
const result = await this.addStep(
|
|
1525
1587
|
new LazyWaitForEventStep(
|
|
@@ -1528,7 +1590,27 @@ var WorkflowContext = class {
|
|
|
1528
1590
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1529
1591
|
)
|
|
1530
1592
|
);
|
|
1531
|
-
|
|
1593
|
+
try {
|
|
1594
|
+
return {
|
|
1595
|
+
...result,
|
|
1596
|
+
eventData: JSON.parse(result.eventData)
|
|
1597
|
+
};
|
|
1598
|
+
} catch {
|
|
1599
|
+
return result;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
async notify(stepName, eventId, eventData) {
|
|
1603
|
+
const result = await this.addStep(
|
|
1604
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1605
|
+
);
|
|
1606
|
+
try {
|
|
1607
|
+
return {
|
|
1608
|
+
...result,
|
|
1609
|
+
eventData: JSON.parse(result.eventData)
|
|
1610
|
+
};
|
|
1611
|
+
} catch {
|
|
1612
|
+
return result;
|
|
1613
|
+
}
|
|
1532
1614
|
}
|
|
1533
1615
|
/**
|
|
1534
1616
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1629,7 +1711,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1629
1711
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1630
1712
|
if (step.waitEventId) {
|
|
1631
1713
|
const newOut = {
|
|
1632
|
-
|
|
1714
|
+
eventData: step.out,
|
|
1633
1715
|
timeout: step.waitTimeout ?? false
|
|
1634
1716
|
};
|
|
1635
1717
|
step.out = newOut;
|
|
@@ -1989,7 +2071,7 @@ var import_qstash5 = require("@upstash/qstash");
|
|
|
1989
2071
|
var Client3 = class {
|
|
1990
2072
|
client;
|
|
1991
2073
|
constructor(clientConfig) {
|
|
1992
|
-
if (!clientConfig.
|
|
2074
|
+
if (!clientConfig.token) {
|
|
1993
2075
|
console.warn("[Upstash Workflow] url or the token is not set. client will not work.");
|
|
1994
2076
|
}
|
|
1995
2077
|
this.client = new import_qstash5.Client(clientConfig);
|
|
@@ -2012,18 +2094,21 @@ var Client3 = class {
|
|
|
2012
2094
|
* Notify a workflow run waiting for an event
|
|
2013
2095
|
*
|
|
2014
2096
|
* @param eventId event id to notify
|
|
2015
|
-
* @param
|
|
2097
|
+
* @param eventData data to provide to the workflow
|
|
2016
2098
|
*/
|
|
2017
2099
|
async notify({
|
|
2018
2100
|
eventId,
|
|
2019
|
-
|
|
2101
|
+
eventData
|
|
2020
2102
|
}) {
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2103
|
+
return await makeNotifyRequest(this.client.http, eventId, eventData);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Check waiters of an event
|
|
2107
|
+
*
|
|
2108
|
+
* @param eventId event id to check
|
|
2109
|
+
*/
|
|
2110
|
+
async getWaiters({ eventId }) {
|
|
2111
|
+
return await makeGetWaitersRequest(this.client.http, eventId);
|
|
2027
2112
|
}
|
|
2028
2113
|
};
|
|
2029
2114
|
// Annotate the CommonJS export names for ESM import in node:
|
package/index.mjs
CHANGED
package/nextjs.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
2
|
import { NextResponse } from 'next/server';
|
|
3
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
3
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.mjs';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
|
|
6
6
|
/**
|
package/nextjs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NextApiHandler } from 'next';
|
|
2
2
|
import { NextResponse } from 'next/server';
|
|
3
|
-
import { R as RouteFunction, W as WorkflowServeOptions } from './types-
|
|
3
|
+
import { R as RouteFunction, W as WorkflowServeOptions } from './types-CoXaNrxX.js';
|
|
4
4
|
import '@upstash/qstash';
|
|
5
5
|
|
|
6
6
|
/**
|
package/nextjs.js
CHANGED
|
@@ -1112,6 +1112,16 @@ var sortSteps = (steps) => {
|
|
|
1112
1112
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1113
1113
|
};
|
|
1114
1114
|
|
|
1115
|
+
// src/client/utils.ts
|
|
1116
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1117
|
+
const result = await requester.request({
|
|
1118
|
+
path: ["v2", "notify", eventId],
|
|
1119
|
+
method: "POST",
|
|
1120
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1121
|
+
});
|
|
1122
|
+
return result;
|
|
1123
|
+
};
|
|
1124
|
+
|
|
1115
1125
|
// src/context/steps.ts
|
|
1116
1126
|
var BaseLazyStep = class {
|
|
1117
1127
|
stepName;
|
|
@@ -1270,6 +1280,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1270
1280
|
});
|
|
1271
1281
|
}
|
|
1272
1282
|
};
|
|
1283
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1284
|
+
stepType = "Notify";
|
|
1285
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1286
|
+
super(stepName, async () => {
|
|
1287
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1288
|
+
return {
|
|
1289
|
+
eventId,
|
|
1290
|
+
eventData,
|
|
1291
|
+
notifyResponse
|
|
1292
|
+
};
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1273
1296
|
|
|
1274
1297
|
// src/context/context.ts
|
|
1275
1298
|
var WorkflowContext = class {
|
|
@@ -1516,6 +1539,38 @@ var WorkflowContext = class {
|
|
|
1516
1539
|
return result;
|
|
1517
1540
|
}
|
|
1518
1541
|
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1544
|
+
* timeout ends
|
|
1545
|
+
*
|
|
1546
|
+
* ```ts
|
|
1547
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1548
|
+
* "wait for event step",
|
|
1549
|
+
* "my-event-id",
|
|
1550
|
+
* 100 // timeout after 100 seconds
|
|
1551
|
+
* );
|
|
1552
|
+
* ```
|
|
1553
|
+
*
|
|
1554
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1555
|
+
*
|
|
1556
|
+
* ```ts
|
|
1557
|
+
* import { Client } from "@upstash/workflow";
|
|
1558
|
+
*
|
|
1559
|
+
* const client = new Client({ token: });
|
|
1560
|
+
*
|
|
1561
|
+
* await client.notify({
|
|
1562
|
+
* eventId: "my-event-id",
|
|
1563
|
+
* eventData: "eventData"
|
|
1564
|
+
* })
|
|
1565
|
+
* ```
|
|
1566
|
+
*
|
|
1567
|
+
* @param stepName
|
|
1568
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1569
|
+
* @param timeout timeout duration in seconds
|
|
1570
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1571
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1572
|
+
* is the value passed to `client.notify`.
|
|
1573
|
+
*/
|
|
1519
1574
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1520
1575
|
const result = await this.addStep(
|
|
1521
1576
|
new LazyWaitForEventStep(
|
|
@@ -1524,7 +1579,27 @@ var WorkflowContext = class {
|
|
|
1524
1579
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1525
1580
|
)
|
|
1526
1581
|
);
|
|
1527
|
-
|
|
1582
|
+
try {
|
|
1583
|
+
return {
|
|
1584
|
+
...result,
|
|
1585
|
+
eventData: JSON.parse(result.eventData)
|
|
1586
|
+
};
|
|
1587
|
+
} catch {
|
|
1588
|
+
return result;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
async notify(stepName, eventId, eventData) {
|
|
1592
|
+
const result = await this.addStep(
|
|
1593
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1594
|
+
);
|
|
1595
|
+
try {
|
|
1596
|
+
return {
|
|
1597
|
+
...result,
|
|
1598
|
+
eventData: JSON.parse(result.eventData)
|
|
1599
|
+
};
|
|
1600
|
+
} catch {
|
|
1601
|
+
return result;
|
|
1602
|
+
}
|
|
1528
1603
|
}
|
|
1529
1604
|
/**
|
|
1530
1605
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1625,7 +1700,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1625
1700
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1626
1701
|
if (step.waitEventId) {
|
|
1627
1702
|
const newOut = {
|
|
1628
|
-
|
|
1703
|
+
eventData: step.out,
|
|
1629
1704
|
timeout: step.waitTimeout ?? false
|
|
1630
1705
|
};
|
|
1631
1706
|
step.out = newOut;
|
package/nextjs.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,99 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@upstash/workflow",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"description": "Durable, Reliable and Performant Serverless Functions",
|
|
5
|
-
"main": "./index.js",
|
|
6
|
-
"module": "./index.mjs",
|
|
7
|
-
"types": "./index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"./*"
|
|
10
|
-
],
|
|
11
|
-
"exports": {
|
|
12
|
-
".": {
|
|
13
|
-
"import": "./index.mjs",
|
|
14
|
-
"require": "./index.js"
|
|
15
|
-
},
|
|
16
|
-
"./dist/nextjs": {
|
|
17
|
-
"import": "./nextjs.mjs",
|
|
18
|
-
"require": "./nextjs.js"
|
|
19
|
-
},
|
|
20
|
-
"./nextjs": {
|
|
21
|
-
"import": "./nextjs.mjs",
|
|
22
|
-
"require": "./nextjs.js"
|
|
23
|
-
},
|
|
24
|
-
"./h3": {
|
|
25
|
-
"import": "./h3.mjs",
|
|
26
|
-
"require": "./h3.js"
|
|
27
|
-
},
|
|
28
|
-
"./svelte": {
|
|
29
|
-
"import": "./svelte.mjs",
|
|
30
|
-
"require": "./svelte.js"
|
|
31
|
-
},
|
|
32
|
-
"./solidjs": {
|
|
33
|
-
"import": "./solidjs.mjs",
|
|
34
|
-
"require": "./solidjs.js"
|
|
35
|
-
},
|
|
36
|
-
"./workflow": {
|
|
37
|
-
"import": "./workflow.mjs",
|
|
38
|
-
"require": "./workflow.js"
|
|
39
|
-
},
|
|
40
|
-
"./hono": {
|
|
41
|
-
"import": "./hono.mjs",
|
|
42
|
-
"require": "./hono.js"
|
|
43
|
-
},
|
|
44
|
-
"./cloudflare": {
|
|
45
|
-
"import": "./cloudflare.mjs",
|
|
46
|
-
"require": "./cloudflare.js"
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/",
|
|
51
|
-
"test": "bun test src",
|
|
52
|
-
"fmt": "prettier --write .",
|
|
53
|
-
"lint": "tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix",
|
|
54
|
-
"check-exports": "bun run build && cd dist && attw -P",
|
|
55
|
-
"prepare": "husky"
|
|
56
|
-
},
|
|
57
|
-
"repository": {
|
|
58
|
-
"type": "git",
|
|
59
|
-
"url": "git+https://github.com/upstash/workflow-ts.git"
|
|
60
|
-
},
|
|
61
|
-
"keywords": [
|
|
62
|
-
"upstash",
|
|
63
|
-
"qstash",
|
|
64
|
-
"workflow",
|
|
65
|
-
"serverless"
|
|
66
|
-
],
|
|
67
|
-
"author": "Cahid Arda Oz",
|
|
68
|
-
"license": "MIT",
|
|
69
|
-
"bugs": {
|
|
70
|
-
"url": "https://github.com/upstash/workflow-ts/issues"
|
|
71
|
-
},
|
|
72
|
-
"homepage": "https://github.com/upstash/workflow-ts#readme",
|
|
73
|
-
"devDependencies": {
|
|
74
|
-
"@commitlint/cli": "^19.5.0",
|
|
75
|
-
"@commitlint/config-conventional": "^19.5.0",
|
|
76
|
-
"@eslint/js": "^9.11.1",
|
|
77
|
-
"@solidjs/start": "^1.0.8",
|
|
78
|
-
"@sveltejs/kit": "^2.6.1",
|
|
79
|
-
"@types/bun": "^1.1.10",
|
|
80
|
-
"eslint": "^9.11.1",
|
|
81
|
-
"eslint-plugin-unicorn": "^55.0.0",
|
|
82
|
-
"globals": "^15.10.0",
|
|
83
|
-
"h3": "^1.12.0",
|
|
84
|
-
"hono": "^4.6.3",
|
|
85
|
-
"husky": "^9.1.6",
|
|
86
|
-
"next": "^14.2.14",
|
|
87
|
-
"prettier": "3.3.3",
|
|
88
|
-
"tsc": "^2.0.4",
|
|
89
|
-
"tsup": "^8.3.0",
|
|
90
|
-
"typescript": "5.4.5",
|
|
91
|
-
"typescript-eslint": "^8.8.0"
|
|
92
|
-
},
|
|
93
|
-
"dependencies": {
|
|
94
|
-
"@upstash/qstash": "^2.7.12"
|
|
95
|
-
},
|
|
96
|
-
"directories": {
|
|
97
|
-
"example": "examples"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
{"name":"@upstash/workflow","version":"v0.1.1-canary-2","description":"Durable, Reliable and Performant Serverless Functions","main":"./index.js","module":"./index.mjs","types":"./index.d.ts","files":["./*"],"exports":{".":{"import":"./index.mjs","require":"./index.js"},"./dist/nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./nextjs":{"import":"./nextjs.mjs","require":"./nextjs.js"},"./h3":{"import":"./h3.mjs","require":"./h3.js"},"./svelte":{"import":"./svelte.mjs","require":"./svelte.js"},"./solidjs":{"import":"./solidjs.mjs","require":"./solidjs.js"},"./workflow":{"import":"./workflow.mjs","require":"./workflow.js"},"./hono":{"import":"./hono.mjs","require":"./hono.js"},"./cloudflare":{"import":"./cloudflare.mjs","require":"./cloudflare.js"}},"scripts":{"build":"tsup && cp README.md ./dist/ && cp package.json ./dist/ && cp LICENSE ./dist/","test":"bun test src","fmt":"prettier --write .","lint":"tsc && eslint \"{src,platforms}/**/*.{js,ts,tsx}\" --quiet --fix","check-exports":"bun run build && cd dist && attw -P"},"repository":{"type":"git","url":"git+https://github.com/upstash/workflow-ts.git"},"keywords":["upstash","qstash","workflow","serverless"],"author":"Cahid Arda Oz","license":"MIT","bugs":{"url":"https://github.com/upstash/workflow-ts/issues"},"homepage":"https://github.com/upstash/workflow-ts#readme","devDependencies":{"@commitlint/cli":"^19.5.0","@commitlint/config-conventional":"^19.5.0","@eslint/js":"^9.11.1","@solidjs/start":"^1.0.8","@sveltejs/kit":"^2.6.1","@types/bun":"^1.1.10","eslint":"^9.11.1","eslint-plugin-unicorn":"^55.0.0","globals":"^15.10.0","h3":"^1.12.0","hono":"^4.6.3","husky":"^9.1.6","next":"^14.2.14","prettier":"3.3.3","tsc":"^2.0.4","tsup":"^8.3.0","typescript":"5.4.5","typescript-eslint":"^8.8.0"},"dependencies":{"@upstash/qstash":"^2.7.12"}}
|
package/solidjs.d.mts
CHANGED
package/solidjs.d.ts
CHANGED
package/solidjs.js
CHANGED
|
@@ -1110,6 +1110,16 @@ var sortSteps = (steps) => {
|
|
|
1110
1110
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1111
1111
|
};
|
|
1112
1112
|
|
|
1113
|
+
// src/client/utils.ts
|
|
1114
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1115
|
+
const result = await requester.request({
|
|
1116
|
+
path: ["v2", "notify", eventId],
|
|
1117
|
+
method: "POST",
|
|
1118
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1119
|
+
});
|
|
1120
|
+
return result;
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1113
1123
|
// src/context/steps.ts
|
|
1114
1124
|
var BaseLazyStep = class {
|
|
1115
1125
|
stepName;
|
|
@@ -1268,6 +1278,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1268
1278
|
});
|
|
1269
1279
|
}
|
|
1270
1280
|
};
|
|
1281
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1282
|
+
stepType = "Notify";
|
|
1283
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1284
|
+
super(stepName, async () => {
|
|
1285
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1286
|
+
return {
|
|
1287
|
+
eventId,
|
|
1288
|
+
eventData,
|
|
1289
|
+
notifyResponse
|
|
1290
|
+
};
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1271
1294
|
|
|
1272
1295
|
// src/context/context.ts
|
|
1273
1296
|
var WorkflowContext = class {
|
|
@@ -1514,6 +1537,38 @@ var WorkflowContext = class {
|
|
|
1514
1537
|
return result;
|
|
1515
1538
|
}
|
|
1516
1539
|
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1542
|
+
* timeout ends
|
|
1543
|
+
*
|
|
1544
|
+
* ```ts
|
|
1545
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1546
|
+
* "wait for event step",
|
|
1547
|
+
* "my-event-id",
|
|
1548
|
+
* 100 // timeout after 100 seconds
|
|
1549
|
+
* );
|
|
1550
|
+
* ```
|
|
1551
|
+
*
|
|
1552
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1553
|
+
*
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* import { Client } from "@upstash/workflow";
|
|
1556
|
+
*
|
|
1557
|
+
* const client = new Client({ token: });
|
|
1558
|
+
*
|
|
1559
|
+
* await client.notify({
|
|
1560
|
+
* eventId: "my-event-id",
|
|
1561
|
+
* eventData: "eventData"
|
|
1562
|
+
* })
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* @param stepName
|
|
1566
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1567
|
+
* @param timeout timeout duration in seconds
|
|
1568
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1569
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1570
|
+
* is the value passed to `client.notify`.
|
|
1571
|
+
*/
|
|
1517
1572
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1518
1573
|
const result = await this.addStep(
|
|
1519
1574
|
new LazyWaitForEventStep(
|
|
@@ -1522,7 +1577,27 @@ var WorkflowContext = class {
|
|
|
1522
1577
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1523
1578
|
)
|
|
1524
1579
|
);
|
|
1525
|
-
|
|
1580
|
+
try {
|
|
1581
|
+
return {
|
|
1582
|
+
...result,
|
|
1583
|
+
eventData: JSON.parse(result.eventData)
|
|
1584
|
+
};
|
|
1585
|
+
} catch {
|
|
1586
|
+
return result;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
async notify(stepName, eventId, eventData) {
|
|
1590
|
+
const result = await this.addStep(
|
|
1591
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1592
|
+
);
|
|
1593
|
+
try {
|
|
1594
|
+
return {
|
|
1595
|
+
...result,
|
|
1596
|
+
eventData: JSON.parse(result.eventData)
|
|
1597
|
+
};
|
|
1598
|
+
} catch {
|
|
1599
|
+
return result;
|
|
1600
|
+
}
|
|
1526
1601
|
}
|
|
1527
1602
|
/**
|
|
1528
1603
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1623,7 +1698,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1623
1698
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1624
1699
|
if (step.waitEventId) {
|
|
1625
1700
|
const newOut = {
|
|
1626
|
-
|
|
1701
|
+
eventData: step.out,
|
|
1627
1702
|
timeout: step.waitTimeout ?? false
|
|
1628
1703
|
};
|
|
1629
1704
|
step.out = newOut;
|
package/solidjs.mjs
CHANGED
package/svelte.d.mts
CHANGED
package/svelte.d.ts
CHANGED
package/svelte.js
CHANGED
|
@@ -1110,6 +1110,16 @@ var sortSteps = (steps) => {
|
|
|
1110
1110
|
return steps.toSorted((step, stepOther) => getStepId(step) - getStepId(stepOther));
|
|
1111
1111
|
};
|
|
1112
1112
|
|
|
1113
|
+
// src/client/utils.ts
|
|
1114
|
+
var makeNotifyRequest = async (requester, eventId, eventData) => {
|
|
1115
|
+
const result = await requester.request({
|
|
1116
|
+
path: ["v2", "notify", eventId],
|
|
1117
|
+
method: "POST",
|
|
1118
|
+
body: typeof eventData === "string" ? eventData : JSON.stringify(eventData)
|
|
1119
|
+
});
|
|
1120
|
+
return result;
|
|
1121
|
+
};
|
|
1122
|
+
|
|
1113
1123
|
// src/context/steps.ts
|
|
1114
1124
|
var BaseLazyStep = class {
|
|
1115
1125
|
stepName;
|
|
@@ -1268,6 +1278,19 @@ var LazyWaitForEventStep = class extends BaseLazyStep {
|
|
|
1268
1278
|
});
|
|
1269
1279
|
}
|
|
1270
1280
|
};
|
|
1281
|
+
var LazyNotifyStep = class extends LazyFunctionStep {
|
|
1282
|
+
stepType = "Notify";
|
|
1283
|
+
constructor(stepName, eventId, eventData, requester) {
|
|
1284
|
+
super(stepName, async () => {
|
|
1285
|
+
const notifyResponse = await makeNotifyRequest(requester, eventId, eventData);
|
|
1286
|
+
return {
|
|
1287
|
+
eventId,
|
|
1288
|
+
eventData,
|
|
1289
|
+
notifyResponse
|
|
1290
|
+
};
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1271
1294
|
|
|
1272
1295
|
// src/context/context.ts
|
|
1273
1296
|
var WorkflowContext = class {
|
|
@@ -1514,6 +1537,38 @@ var WorkflowContext = class {
|
|
|
1514
1537
|
return result;
|
|
1515
1538
|
}
|
|
1516
1539
|
}
|
|
1540
|
+
/**
|
|
1541
|
+
* Makes the workflow run wait until a notify request is sent or until the
|
|
1542
|
+
* timeout ends
|
|
1543
|
+
*
|
|
1544
|
+
* ```ts
|
|
1545
|
+
* const { eventData, timeout } = await context.waitForEvent(
|
|
1546
|
+
* "wait for event step",
|
|
1547
|
+
* "my-event-id",
|
|
1548
|
+
* 100 // timeout after 100 seconds
|
|
1549
|
+
* );
|
|
1550
|
+
* ```
|
|
1551
|
+
*
|
|
1552
|
+
* To notify a waiting workflow run, you can use the notify method:
|
|
1553
|
+
*
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* import { Client } from "@upstash/workflow";
|
|
1556
|
+
*
|
|
1557
|
+
* const client = new Client({ token: });
|
|
1558
|
+
*
|
|
1559
|
+
* await client.notify({
|
|
1560
|
+
* eventId: "my-event-id",
|
|
1561
|
+
* eventData: "eventData"
|
|
1562
|
+
* })
|
|
1563
|
+
* ```
|
|
1564
|
+
*
|
|
1565
|
+
* @param stepName
|
|
1566
|
+
* @param eventId event id to wake up the waiting workflow run
|
|
1567
|
+
* @param timeout timeout duration in seconds
|
|
1568
|
+
* @returns wait response as `{ timeout: boolean, eventData: unknown }`.
|
|
1569
|
+
* timeout is true if the wait times out, if notified it is false. eventData
|
|
1570
|
+
* is the value passed to `client.notify`.
|
|
1571
|
+
*/
|
|
1517
1572
|
async waitForEvent(stepName, eventId, timeout) {
|
|
1518
1573
|
const result = await this.addStep(
|
|
1519
1574
|
new LazyWaitForEventStep(
|
|
@@ -1522,7 +1577,27 @@ var WorkflowContext = class {
|
|
|
1522
1577
|
typeof timeout === "string" ? timeout : `${timeout}s`
|
|
1523
1578
|
)
|
|
1524
1579
|
);
|
|
1525
|
-
|
|
1580
|
+
try {
|
|
1581
|
+
return {
|
|
1582
|
+
...result,
|
|
1583
|
+
eventData: JSON.parse(result.eventData)
|
|
1584
|
+
};
|
|
1585
|
+
} catch {
|
|
1586
|
+
return result;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
async notify(stepName, eventId, eventData) {
|
|
1590
|
+
const result = await this.addStep(
|
|
1591
|
+
new LazyNotifyStep(stepName, eventId, eventData, this.qstashClient.http)
|
|
1592
|
+
);
|
|
1593
|
+
try {
|
|
1594
|
+
return {
|
|
1595
|
+
...result,
|
|
1596
|
+
eventData: JSON.parse(result.eventData)
|
|
1597
|
+
};
|
|
1598
|
+
} catch {
|
|
1599
|
+
return result;
|
|
1600
|
+
}
|
|
1526
1601
|
}
|
|
1527
1602
|
/**
|
|
1528
1603
|
* Adds steps to the executor. Needed so that it can be overwritten in
|
|
@@ -1623,7 +1698,7 @@ var parsePayload = (rawPayload) => {
|
|
|
1623
1698
|
const step = JSON.parse(decodeBase64(rawStep.body));
|
|
1624
1699
|
if (step.waitEventId) {
|
|
1625
1700
|
const newOut = {
|
|
1626
|
-
|
|
1701
|
+
eventData: step.out,
|
|
1627
1702
|
timeout: step.waitTimeout ?? false
|
|
1628
1703
|
};
|
|
1629
1704
|
step.out = newOut;
|