@trigora/sdk 0.6.0 → 0.9.0
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 +40 -2
- package/dist/defineFlow.d.ts +10 -3
- package/dist/index.d.ts +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -119,6 +119,33 @@ export default defineFlow({
|
|
|
119
119
|
});
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
+
### Queue
|
|
123
|
+
|
|
124
|
+
Use queue triggers to consume workspace-scoped queue messages. Deploy auto-provisions and binds the named queue to the flow.
|
|
125
|
+
|
|
126
|
+
Optional `retry` configures how many times a failed message may be redelivered. Omitted `retry` means a single attempt. `attempts > 1` is supported for queue flows only.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { defineFlow } from '@trigora/sdk';
|
|
130
|
+
|
|
131
|
+
export default defineFlow({
|
|
132
|
+
id: 'process-image',
|
|
133
|
+
trigger: { type: 'queue', queue: 'image-processing' },
|
|
134
|
+
retry: { attempts: 5, backoff: 'exponential' },
|
|
135
|
+
async run(event, ctx) {
|
|
136
|
+
await ctx.log.info('Processing message', {
|
|
137
|
+
queue: event.queue,
|
|
138
|
+
messageId: event.messageId,
|
|
139
|
+
attempt: event.attempt,
|
|
140
|
+
maxAttempts: event.maxAttempts,
|
|
141
|
+
payload: event.payload,
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Locally, `trigora trigger` and `trigora dev` invoke queue flows with a synthetic `QueueFlowEvent` (`messageId` starts with `local_`, `attempt` is `1`, and `maxAttempts` comes from `retry.attempts` or `1`). Local runs do not actually retry. Hosted runs use the real message id and attempt count.
|
|
148
|
+
|
|
122
149
|
## Return Types
|
|
123
150
|
|
|
124
151
|
Return values are trigger-aware.
|
|
@@ -152,14 +179,15 @@ export default defineFlow({
|
|
|
152
179
|
});
|
|
153
180
|
```
|
|
154
181
|
|
|
155
|
-
### Manual and
|
|
182
|
+
### Manual, cron, and queue flows
|
|
156
183
|
|
|
157
|
-
Manual and
|
|
184
|
+
Manual, cron, and queue flows do not use return values. Their `run` functions are typed as `void`.
|
|
158
185
|
|
|
159
186
|
This matches how Trigora uses them:
|
|
160
187
|
|
|
161
188
|
- manual flows are invoked locally for testing and development
|
|
162
189
|
- cron flows are background-style scheduled jobs
|
|
190
|
+
- queue flows consume workspace queue messages
|
|
163
191
|
- webhook flows are request-response flows
|
|
164
192
|
|
|
165
193
|
## Event Shape
|
|
@@ -181,6 +209,15 @@ type FlowEvent<TPayload = JsonValue> = {
|
|
|
181
209
|
};
|
|
182
210
|
```
|
|
183
211
|
|
|
212
|
+
Queue events also include:
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
queue: string;
|
|
216
|
+
messageId: string;
|
|
217
|
+
attempt: number; // 1-based delivery count
|
|
218
|
+
maxAttempts: number; // from retry.attempts, or 1 when omitted
|
|
219
|
+
```
|
|
220
|
+
|
|
184
221
|
In local manual runs, the payload comes from your JSON payload file when one is provided. In local webhook dev and deployed webhook flows, the payload is the parsed JSON request body.
|
|
185
222
|
|
|
186
223
|
If you do not provide your own payload type, `event.payload` defaults to `JsonValue`.
|
|
@@ -260,6 +297,7 @@ The exact exported type is `FlowContext<TEnv>`.
|
|
|
260
297
|
- `FlowEvent`
|
|
261
298
|
- `FlowRunFn`
|
|
262
299
|
- `JsonValue`
|
|
300
|
+
- `RetryPolicy`
|
|
263
301
|
- `Trigger`
|
|
264
302
|
- `WebhookFlowResult`
|
|
265
303
|
|
package/dist/defineFlow.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import type { CronEventPayload, CronFlowDefinition, FlowDefinition, FlowRunFn, JsonValue, ManualFlowDefinition, ManualTrigger, Trigger, WebhookTrigger, WebhookFlowDefinition, CronTrigger } from '@trigora/contracts';
|
|
1
|
+
import type { CronEventPayload, CronFlowDefinition, FlowDefinition, FlowRunFn, JsonValue, ManualFlowDefinition, ManualTrigger, QueueFlowDefinition, QueueTrigger, RetryPolicy, Trigger, WebhookTrigger, WebhookFlowDefinition, CronTrigger } from '@trigora/contracts';
|
|
2
2
|
type DefineFlowInput<TPayload, TEnv extends Record<string, string>, TTrigger extends Trigger> = {
|
|
3
3
|
id: string;
|
|
4
4
|
trigger: TTrigger;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Optional retry policy. Omitted means a single attempt.
|
|
7
|
+
* `attempts > 1` is supported for queue flows only (enforced at deploy time).
|
|
8
|
+
*/
|
|
9
|
+
retry?: RetryPolicy;
|
|
10
|
+
run: TTrigger extends ManualTrigger ? FlowRunFn<TPayload, TEnv, ManualTrigger> : TTrigger extends WebhookTrigger ? FlowRunFn<TPayload, TEnv, WebhookTrigger> : TTrigger extends CronTrigger ? FlowRunFn<CronEventPayload, TEnv, CronTrigger> : TTrigger extends QueueTrigger ? FlowRunFn<TPayload, TEnv, QueueTrigger> : never;
|
|
6
11
|
};
|
|
7
|
-
type DefineFlowOutput<TPayload, TEnv extends Record<string, string>, TTrigger extends Trigger> = TTrigger extends ManualTrigger ? ManualFlowDefinition<TPayload, TEnv> : TTrigger extends WebhookTrigger ? WebhookFlowDefinition<TPayload, TEnv> : TTrigger extends CronTrigger ? CronFlowDefinition<TEnv> : FlowDefinition<TPayload, TEnv, TTrigger>;
|
|
12
|
+
type DefineFlowOutput<TPayload, TEnv extends Record<string, string>, TTrigger extends Trigger> = TTrigger extends ManualTrigger ? ManualFlowDefinition<TPayload, TEnv> : TTrigger extends WebhookTrigger ? WebhookFlowDefinition<TPayload, TEnv> : TTrigger extends CronTrigger ? CronFlowDefinition<TEnv> : TTrigger extends QueueTrigger ? QueueFlowDefinition<TPayload, TEnv> : FlowDefinition<TPayload, TEnv, TTrigger>;
|
|
8
13
|
/**
|
|
9
14
|
* Define a Trigora flow.
|
|
10
15
|
*
|
|
@@ -12,6 +17,7 @@ type DefineFlowOutput<TPayload, TEnv extends Record<string, string>, TTrigger ex
|
|
|
12
17
|
* - `id`: the internal identifier for the flow in your project
|
|
13
18
|
* - `trigger`: how the flow is invoked
|
|
14
19
|
* - `run`: the function that executes when the flow is triggered
|
|
20
|
+
* - `retry`: optional retry policy (queue flows may use `attempts > 1`)
|
|
15
21
|
*
|
|
16
22
|
* `run` receives the incoming `event` and a `ctx` object with logging and environment access.
|
|
17
23
|
*
|
|
@@ -43,4 +49,5 @@ export declare function defineFlow<TTrigger extends Trigger, TPayload = JsonValu
|
|
|
43
49
|
export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: ManualFlowDefinition<TPayload, TEnv>): ManualFlowDefinition<TPayload, TEnv>;
|
|
44
50
|
export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: WebhookFlowDefinition<TPayload, TEnv>): WebhookFlowDefinition<TPayload, TEnv>;
|
|
45
51
|
export declare function defineFlow<TEnv extends Record<string, string> = Record<string, string>>(flow: CronFlowDefinition<TEnv>): CronFlowDefinition<TEnv>;
|
|
52
|
+
export declare function defineFlow<TPayload = JsonValue, TEnv extends Record<string, string> = Record<string, string>>(flow: QueueFlowDefinition<TPayload, TEnv>): QueueFlowDefinition<TPayload, TEnv>;
|
|
46
53
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { defineFlow } from './defineFlow';
|
|
2
|
-
export type { CronEventPayload, CronFlowEvent, FlowContext, FlowDefinition, FlowEvent, FlowRunFn, JsonValue, ManualFlowEvent, Trigger, WebhookFlowEvent, WebhookFlowResult, } from '@trigora/contracts';
|
|
2
|
+
export type { CronEventPayload, CronFlowEvent, FlowContext, FlowDefinition, FlowEvent, FlowRunFn, JsonValue, ManualFlowEvent, QueueFlowEvent, RetryBackoff, RetryPolicy, Trigger, WebhookFlowEvent, WebhookFlowResult, } from '@trigora/contracts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trigora/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/trigora-dev/trigora"
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"cli",
|
|
19
19
|
"triggers",
|
|
20
20
|
"cron",
|
|
21
|
+
"queues",
|
|
21
22
|
"webhooks"
|
|
22
23
|
],
|
|
23
24
|
"license": "MIT",
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"access": "public"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"@trigora/contracts": "0.
|
|
49
|
+
"@trigora/contracts": "^0.9.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"tsup": "^8.5.1"
|