TypeSpec library providing events bindings
npm install @typespec/events
Specifies the content type of the event envelope, event body, or event payload.
When applied to an event payload, that field must also have a corresponding @data
decorator.
@TypeSpec.Events.contentType(contentType: valueof string)
UnionVariant | ModelProperty
Name | Type | Description |
---|---|---|
contentType | valueof string |
@events
union MixedEvents {
@contentType("application/json")
message: {
id: string,
text: string,
},
}
@events
union MixedEvents {
{
done: true,
},
{
done: false,
@data @contentType("text/plain") value: string,
},
}
Identifies the payload of an event. Only one field in an event can be marked as the payload.
@TypeSpec.Events.data
ModelProperty
None
@events
union MixedEvents {
{
metadata: Record<string>,
@data payload: string,
},
}
Specify that this union describes a set of events.
@TypeSpec.Events.events
Union
None
@events
union MixedEvents {
pingEvent: string,
doneEvent: "done",
}