microsoft/typespec

Public

mirrored from https://github.com/microsoft/typespecAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/fix-8260-3

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

packages/events/generated-defs/TypeSpec.Events.ts

63lines · modecode

1import type { DecoratorContext, ModelProperty, Union, UnionVariant } from "@typespec/compiler";
2
3/**
4 * Specify that this union describes a set of events.
5 *
6 * @example
7 * ```typespec
8 * @events
9 * union MixedEvents {
10 * pingEvent: string;
11 *
12 * doneEvent: "done";
13 * }
14 * ```
15 */
16export type EventsDecorator = (context: DecoratorContext, target: Union) => void;
17
18/**
19 * Specifies the content type of the event envelope, event body, or event payload.
20 * When applied to an event payload, that field must also have a corresponding `@data`
21 * decorator.
22 *
23 * @example
24 * ```typespec
25 * @events union MixedEvents {
26 * @contentType("application/json")
27 * message: { id: string, text: string, }
28 * }
29 * ```
30 * @example Specify the content type of the event payload.
31 *
32 * ```typespec
33 * @events union MixedEvents {
34 * { done: true },
35 *
36 * { done: false, @data @contentType("text/plain") value: string,}
37 * }
38 * ```
39 */
40export type ContentTypeDecorator = (
41 context: DecoratorContext,
42 target: UnionVariant | ModelProperty,
43 contentType: string,
44) => void;
45
46/**
47 * Identifies the payload of an event.
48 * Only one field in an event can be marked as the payload.
49 *
50 * @example
51 * ```typespec
52 * @events union MixedEvents {
53 * { metadata: Record<string>, @data payload: string,}
54 * }
55 * ```
56 */
57export type DataDecorator = (context: DecoratorContext, target: ModelProperty) => void;
58
59export type TypeSpecEventsDecorators = {
60 events: EventsDecorator;
61 contentType: ContentTypeDecorator;
62 data: DataDecorator;
63};
64