Skip to content

Commit ceef0c3

Browse files
authored
refactor: standardize condition_function_id across all trigger types (#1280)
1 parent 0be5451 commit ceef0c3

File tree

14 files changed

+41
-54
lines changed

14 files changed

+41
-54
lines changed

docs/content/architecture/trigger-types.mdx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ json!({
139139

140140
**Output**: `ApiResponse` with status_code, body, headers
141141

142-
**Conditions**: Optional. Add `_condition_path` to config with a function ID. The engine invokes it before the handler; if it returns `false`, the handler function is not called. See [Trigger Conditions](#trigger-conditions).
142+
**Conditions**: Optional. Add `condition_function_id` to config with a function ID. The engine invokes it before the handler; if it returns `false`, the handler function is not called. See [Trigger Conditions](#trigger-conditions).
143143

144144
**Path Parameters**: Extract values from URL
145145

@@ -546,7 +546,7 @@ json!({
546546

547547
**Output**: Function result (optional, fire-and-forget pattern supported)
548548

549-
**Conditions**: Optional. Add `_condition_path` to config. See [Trigger Conditions](#trigger-conditions).
549+
**Conditions**: Optional. Add `condition_function_id` to config. See [Trigger Conditions](#trigger-conditions).
550550

551551
**Multiple Topics**: Register separate triggers for each topic.
552552

@@ -604,7 +604,7 @@ json!({
604604

605605
**Output**: Function result
606606

607-
**Conditions**: Optional. Add `_condition_path` to config. See [Trigger Conditions](#trigger-conditions).
607+
**Conditions**: Optional. Add `condition_function_id` to config. See [Trigger Conditions](#trigger-conditions).
608608

609609
**Cron Expression**: Standard 5-field format (minute hour day month weekday)
610610

@@ -906,7 +906,7 @@ Triggers can optionally use a **condition function** to decide whether the handl
906906
### How It Works
907907

908908
1. Register a condition function that receives the same input as the handler and returns a boolean.
909-
2. Add `_condition_path` to the trigger config for http, queue, and cron; use `condition_function_id` for state and stream triggers.
909+
2. Add `condition_function_id` to the trigger config with the condition function's ID.
910910
3. When the trigger fires, the engine calls the condition first. Only if it returns truthy does the handler run.
911911

912912
### Example: HTTP Trigger with Condition
@@ -930,7 +930,7 @@ iii.registerTrigger({
930930
config: {
931931
api_path: '/verified',
932932
http_method: 'POST',
933-
_condition_path: conditionFn.id,
933+
condition_function_id: conditionFn.id,
934934
},
935935
})
936936
```
@@ -953,7 +953,7 @@ iii.register_trigger(
953953
config={
954954
'api_path': '/verified',
955955
'http_method': 'POST',
956-
'_condition_path': condition_fn.id,
956+
'condition_function_id': condition_fn.id,
957957
},
958958
)
959959
```
@@ -972,7 +972,7 @@ iii.register_function("api::verifiedOnly", |_req: Value| async move {
972972
iii.register_trigger("http", "api::verifiedOnly", json!({
973973
"api_path": "/verified",
974974
"http_method": "POST",
975-
"_condition_path": "conditions::requireVerified"
975+
"condition_function_id": "conditions::requireVerified"
976976
}))?;
977977
```
978978
</Tab>
@@ -998,7 +998,7 @@ iii.registerTrigger({
998998
function_id: fn.id,
999999
config: {
10001000
topic: 'order.placed',
1001-
_condition_path: conditionFn.id,
1001+
condition_function_id: conditionFn.id,
10021002
},
10031003
})
10041004
```
@@ -1021,7 +1021,7 @@ iii.register_trigger(
10211021
function_id=fn.id,
10221022
config={
10231023
'topic': 'order.placed',
1024-
'_condition_path': condition_fn.id,
1024+
'condition_function_id': condition_fn.id,
10251025
},
10261026
)
10271027
```
@@ -1040,7 +1040,7 @@ iii.register_function("orders::processHighValue", |order: Value| async move {
10401040

10411041
iii.register_trigger("queue", "orders::processHighValue", json!({
10421042
"topic": "order.placed",
1043-
"_condition_path": "conditions::highValue"
1043+
"condition_function_id": "conditions::highValue"
10441044
}))?;
10451045
```
10461046
</Tab>
@@ -1115,15 +1115,9 @@ iii.register_trigger("state", "state::onProfileUpdate", json!({
11151115
</Tab>
11161116
</Tabs>
11171117

1118-
### Config Keys by Trigger Type
1118+
### Config Key
11191119

1120-
| Trigger Type | Condition Config Key |
1121-
|--------------|----------------------|
1122-
| http | `_condition_path` |
1123-
| queue | `_condition_path` |
1124-
| cron | `_condition_path` |
1125-
| stream | `condition_function_id` |
1126-
| state | `condition_function_id` |
1120+
All trigger types use `condition_function_id` in the trigger config to reference the condition function.
11271121

11281122
## Trigger Lifecycle
11291123

docs/content/examples/conditions.mdx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ iii.registerTrigger({
5151
config: {
5252
api_path: 'orders/premium',
5353
http_method: 'POST',
54-
_condition_path: 'conditions::is_premium',
54+
condition_function_id: 'conditions::is_premium',
5555
},
5656
})
5757
```
@@ -88,7 +88,7 @@ iii.register_trigger(
8888
config={
8989
"api_path": "orders/premium",
9090
"http_method": "POST",
91-
"_condition_path": "conditions::is_premium",
91+
"condition_function_id": "conditions::is_premium",
9292
},
9393
)
9494
```
@@ -120,7 +120,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
120120
iii.register_trigger("http", "orders::premium", json!({
121121
"api_path": "orders/premium",
122122
"http_method": "POST",
123-
"_condition_path": "conditions::is_premium",
123+
"condition_function_id": "conditions::is_premium",
124124
}))?;
125125

126126
loop { tokio::time::sleep(std::time::Duration::from_secs(60)).await; }
@@ -161,7 +161,7 @@ iii.registerFunction(
161161
iii.registerTrigger({
162162
type: 'queue',
163163
function_id: 'orders::high_value',
164-
config: { topic: 'order.created', _condition_path: 'conditions::is_high_value' },
164+
config: { topic: 'order.created', condition_function_id: 'conditions::is_high_value' },
165165
})
166166
```
167167

@@ -200,7 +200,7 @@ iii.register_function("orders::high_value", lambda data: orders_high_value(data,
200200
iii.register_trigger(
201201
type="queue",
202202
function_id="orders::high_value",
203-
config={"topic": "order.created", "_condition_path": "conditions::is_high_value"},
203+
config={"topic": "order.created", "condition_function_id": "conditions::is_high_value"},
204204
)
205205
```
206206

@@ -228,7 +228,7 @@ iii.register_function("orders::high_value", |input| async move {
228228

229229
iii.register_trigger("queue", "orders::high_value", json!({
230230
"topic": "order.created",
231-
"_condition_path": "conditions::is_high_value",
231+
"condition_function_id": "conditions::is_high_value",
232232
}))?;
233233
```
234234

@@ -237,7 +237,7 @@ iii.register_trigger("queue", "orders::high_value", json!({
237237

238238
## State trigger condition
239239

240-
State and stream triggers use `condition_function_id` in the config instead of `_condition_path`. The condition receives the full state event, including the event type (`created`, `updated`, `deleted`), scope, key, and both old and new values.
240+
The condition receives the full state event, including the event type (`created`, `updated`, `deleted`), scope, key, and both old and new values.
241241

242242
<Tabs groupId="language" persist items={['Node / TypeScript', 'Python', 'Rust']}>
243243
<Tab value="Node / TypeScript">
@@ -319,8 +319,7 @@ iii.register_trigger("state", "orders::on_update", json!({
319319
## Key concepts
320320

321321
- Condition functions are registered with `registerFunction` / `register_function` like any other function. They receive the same event data as the handler and must return `true` or `false`.
322-
- For HTTP, queue, and cron triggers, add `_condition_path` to the trigger config with the condition function's ID.
323-
- For state and stream triggers, use `condition_function_id` in the trigger config instead.
322+
- Add `condition_function_id` to the trigger config with the condition function's ID. This key is the same for all trigger types.
324323
- When a condition returns `false`:
325324
- **HTTP** — the engine responds with `422 Unprocessable Entity`; the handler function is not called.
326325
- **Queue / Cron** — the handler function is not called; no error is surfaced.

docs/content/how-to/use-trigger-conditions.mdx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
101101

102102
Create a Trigger and specify its condition with `condition_function_id`.
103103

104-
<Callout title="Condition differences" type="info">
105-
Use `_condition_path` for `http`, `queue`, and `cron`. Use `condition_function_id` for `state` and `stream`. This disparity will be fixed soon.
106-
</Callout>
107-
108-
{/* TODO: Replace `_condition_path` with `condition_function_id` once SDKs are updated. */}
109-
110104
Example (`state` trigger):
111105

112106
<Tabs groupId="language" persist items={["Node / TypeScript", "Python", "Rust"]}>

docs/content/modules/module-cron.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ This Module adds a new Trigger Type: `cron`.
8888
```
8989

9090
</ResponseField>
91-
<ResponseField name="_condition_path" type="string">
91+
<ResponseField name="condition_function_id" type="string">
9292
Function ID for conditional execution. The engine invokes it with the cron event; if it returns `false`, the handler function is not called.
9393
</ResponseField>
9494
</Expandable>
9595

9696
<Expandable title="Trigger Event Payload">
97-
The following fields are passed to the handler function (and to `_condition_path` if set) each time the trigger fires.
97+
The following fields are passed to the handler function (and to `condition_function_id` if set) each time the trigger fires.
9898

9999
<ResponseField name="trigger" type="string">
100100
Always `"cron"`.

docs/content/modules/module-http.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ This module adds a new Trigger Type: `http`.
9090
<ResponseField name="http_method" type="string" required>
9191
The HTTP method of the API.
9292
</ResponseField>
93-
<ResponseField name="_condition_path" type="string">
93+
<ResponseField name="condition_function_id" type="string">
9494
Function ID for conditional execution. The engine invokes it with the request; if it returns `false`, the handler function is not called.
9595
</ResponseField>
9696
</Expandable>

docs/content/modules/module-queue.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ This Module adds a new Trigger Type: `queue`.
145145
<ResponseField name="topic" type="string" required>
146146
The topic to subscribe to. The function will be invoked whenever a message is enqueued to this topic.
147147
</ResponseField>
148-
<ResponseField name="_condition_path" type="string">
148+
<ResponseField name="condition_function_id" type="string">
149149
Function ID for conditional execution. The engine invokes it with the message payload; if it returns `false`, the handler function is not called.
150150
</ResponseField>
151151
<ResponseField name="queue" type="object">

engine/src/modules/cron/cron.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl TriggerRegistrator for CronCoreModule {
108108

109109
let condition_function_id = trigger
110110
.config
111-
.get("_condition_path")
111+
.get("condition_function_id")
112112
.and_then(|v| v.as_str())
113113
.map(|v| v.to_string());
114114

@@ -324,15 +324,15 @@ mod tests {
324324
}
325325

326326
#[tokio::test]
327-
async fn register_trigger_with_condition_path() {
327+
async fn register_trigger_with_condition_function_id() {
328328
let (_engine, module) = setup_cron_module();
329329
let trigger = crate::trigger::Trigger {
330330
id: "cron-trig-cond".to_string(),
331331
trigger_type: "cron".to_string(),
332332
function_id: "test::handler".to_string(),
333333
config: json!({
334334
"expression": "0 30 * * * *",
335-
"_condition_path": "test::condition_fn"
335+
"condition_function_id": "test::condition_fn"
336336
}),
337337
worker_id: None,
338338
};

engine/src/modules/queue/queue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl TriggerRegistrator for QueueCoreModule {
107107
if !topic.is_empty() {
108108
let condition_function_id = trigger
109109
.config
110-
.get("_condition_path")
110+
.get("condition_function_id")
111111
.and_then(|v| v.as_str())
112112
.map(|v| v.to_string());
113113

@@ -574,15 +574,15 @@ mod tests {
574574
}
575575

576576
#[tokio::test]
577-
async fn register_trigger_with_condition_path_subscribes() {
577+
async fn register_trigger_with_condition_function_id_subscribes() {
578578
let (_engine, module, adapter) = setup_queue_module();
579579
let trigger = crate::trigger::Trigger {
580580
id: "trig-cond".to_string(),
581581
trigger_type: "queue".to_string(),
582582
function_id: "test::handler".to_string(),
583583
config: json!({
584584
"topic": "conditioned-topic",
585-
"_condition_path": "test::condition_fn"
585+
"condition_function_id": "test::condition_fn"
586586
}),
587587
worker_id: None,
588588
};

engine/src/modules/rest_api/api_core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl TriggerRegistrator for RestApiCoreModule {
396396

397397
let condition_function_id = trigger
398398
.config
399-
.get("_condition_path")
399+
.get("condition_function_id")
400400
.and_then(|v| v.as_str())
401401
.map(|v| v.to_string());
402402

@@ -933,7 +933,7 @@ mod tests {
933933
config: json!({
934934
"api_path": "users/:id",
935935
"http_method": "post",
936-
"_condition_path": "fn::condition"
936+
"condition_function_id": "fn::condition"
937937
}),
938938
worker_id: None,
939939
};

frameworks/motia/motia-js/packages/motia/__tests__/integration/queue.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('queue integration', () => {
143143
function_id: functionId,
144144
config: {
145145
topic,
146-
_condition_path: conditionPath,
146+
condition_function_id: conditionPath,
147147
},
148148
})
149149

0 commit comments

Comments
 (0)