Skip to content

Commit 9385e91

Browse files
committed
feat: make POST /events synchronous with validation feedback
- POST /events now blocks until the event is validated by the pipeline - Returns 201 Created with eventId and streamId on successful validation - Returns 202 Accepted with eventId if validation times out (event stored, validation pending) - Returns 400 Bad Request with validation errors if event fails schema validation - Uses event-based subscription to aggregator broadcast - Adds wait_for_event_validation convenience method on AggregatorHandle - updateDocument (SDK) now uses deep merge for partial content updates (nested objects merged recursively, arrays replaced)
1 parent 89b1c0c commit 9385e91

File tree

23 files changed

+1083
-28
lines changed

23 files changed

+1083
-28
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api-server/.openapi-generator/FILES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ api/openapi.yaml
66
docs/BadRequestResponse.md
77
docs/ErrorResponse.md
88
docs/Event.md
9+
docs/EventAcceptedResponse.md
10+
docs/EventCreatedResponse.md
911
docs/EventData.md
1012
docs/EventFeed.md
1113
docs/EventsGet.md

api-server/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To see how to make this your own, look here:
1515
[README]((https://openapi-generator.tech))
1616

1717
- API version: 0.58.0
18-
- Build date: 2025-12-08T21:21:04.734650742Z[Etc/UTC]
18+
- Build date: 2025-12-14T22:29:40.738562-05:00[America/New_York]
1919

2020

2121

@@ -160,6 +160,8 @@ Method | HTTP request | Description
160160
- [BadRequestResponse](docs/BadRequestResponse.md)
161161
- [ErrorResponse](docs/ErrorResponse.md)
162162
- [Event](docs/Event.md)
163+
- [EventAcceptedResponse](docs/EventAcceptedResponse.md)
164+
- [EventCreatedResponse](docs/EventCreatedResponse.md)
163165
- [EventData](docs/EventData.md)
164166
- [EventFeed](docs/EventFeed.md)
165167
- [EventsGet](docs/EventsGet.md)

api-server/api/openapi.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,20 @@ paths:
101101
requestBody:
102102
$ref: '#/components/requestBodies/EventData'
103103
responses:
104-
"204":
104+
"201":
105+
content:
106+
application/json:
107+
schema:
108+
$ref: '#/components/schemas/EventCreatedResponse'
105109
description: success
110+
"202":
111+
content:
112+
application/json:
113+
schema:
114+
$ref: '#/components/schemas/EventAcceptedResponse'
115+
description: Event accepted but validation pending. The event was stored
116+
but validation did not complete in time. Use the returned event_id to
117+
check status.
106118
"400":
107119
content:
108120
application/json:
@@ -700,6 +712,38 @@ components:
700712
- data
701713
title: A Ceramic Event Data Payload
702714
type: object
715+
EventCreatedResponse:
716+
description: Returned when an event is successfully created and validated
717+
example:
718+
eventId: eventId
719+
streamId: streamId
720+
properties:
721+
eventId:
722+
description: The CID of the created event
723+
type: string
724+
streamId:
725+
description: The stream ID this event belongs to
726+
type: string
727+
required:
728+
- eventId
729+
- streamId
730+
title: Response after event creation
731+
type: object
732+
EventAcceptedResponse:
733+
description: Returned when an event is stored but validation did not complete
734+
in time. The event may still be validated successfully.
735+
properties:
736+
eventId:
737+
description: The CID of the accepted event
738+
type: string
739+
message:
740+
description: Information about the pending validation status
741+
type: string
742+
required:
743+
- eventId
744+
- message
745+
title: Response when event is accepted but validation is pending
746+
type: object
703747
EventFeed:
704748
description: Ceramic event keys as part of a Ceramic Stream
705749
example:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# EventAcceptedResponse
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**event_id** | **String** | The CID of the accepted event |
7+
**message** | **String** | Information about the pending validation status |
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# EventCreatedResponse
2+
3+
## Properties
4+
Name | Type | Description | Notes
5+
------------ | ------------- | ------------- | -------------
6+
**event_id** | **String** | The CID of the created event |
7+
**stream_id** | **String** | The stream ID this event belongs to |
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+
11+

api-server/docs/default_api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ No authorization required
197197
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
198198

199199
# ****
200-
> (event_data)
200+
> models::EventCreatedResponse (event_data)
201201
Creates a new event
202202

203203
### Required Parameters
@@ -208,7 +208,7 @@ Name | Type | Description | Notes
208208

209209
### Return type
210210

211-
(empty response body)
211+
[**models::EventCreatedResponse**](EventCreatedResponse.md)
212212

213213
### Authorization
214214

api-server/src/client/mod.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,34 @@ where
10601060
.await?;
10611061

10621062
match response.status().as_u16() {
1063-
204 => Ok(EventsPostResponse::Success),
1063+
201 => {
1064+
let body = response.into_body();
1065+
let body = body
1066+
.into_raw()
1067+
.map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1068+
.await?;
1069+
let body = str::from_utf8(&body)
1070+
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
1071+
let body =
1072+
serde_json::from_str::<models::EventCreatedResponse>(body).map_err(|e| {
1073+
ApiError(format!("Response body did not match the schema: {}", e))
1074+
})?;
1075+
Ok(EventsPostResponse::Success(body))
1076+
}
1077+
202 => {
1078+
let body = response.into_body();
1079+
let body = body
1080+
.into_raw()
1081+
.map_err(|e| ApiError(format!("Failed to read response: {}", e)))
1082+
.await?;
1083+
let body = str::from_utf8(&body)
1084+
.map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?;
1085+
let body =
1086+
serde_json::from_str::<models::EventAcceptedResponse>(body).map_err(|e| {
1087+
ApiError(format!("Response body did not match the schema: {}", e))
1088+
})?;
1089+
Ok(EventsPostResponse::EventAcceptedButValidationPending(body))
1090+
}
10641091
400 => {
10651092
let body = response.into_body();
10661093
let body = body

api-server/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ pub enum EventsOptionsResponse {
8181
#[must_use]
8282
pub enum EventsPostResponse {
8383
/// success
84-
Success,
84+
Success(models::EventCreatedResponse),
85+
/// Event accepted but validation pending. The event was stored but validation did not complete in time. Use the returned event_id to check status.
86+
EventAcceptedButValidationPending(models::EventAcceptedResponse),
8587
/// bad request
8688
BadRequest(models::BadRequestResponse),
8789
/// Internal server error

0 commit comments

Comments
 (0)