1- import type { Block , TextObject } from '@rocket.chat/ui-kit' ;
2-
31/**
42 * Reserved discriminator stamped by the `EventResult.*` factories below.
5- * App authors never write this by hand — see
6- * docs/proposals/apps-engine-event-result-return-type.md §"The discriminator".
73 */
84export const EVENT_RESULT_KIND = 'EventResult' ;
95
@@ -16,26 +12,14 @@ export type I18nMessage = {
1612 args ?: { [ key : string ] : string | number } ;
1713} ;
1814
19- type PromptPayload =
20- | { message : string }
21- | { i18n : I18nMessage }
22- | {
23- title ?: TextObject ;
24- text ?: TextObject ;
25- blocks ?: Block [ ] ;
26- confirmLabel ?: string ;
27- cancelLabel ?: string ;
28- } ;
29-
3015/**
3116 * Author-facing, marker-free union — the type app authors annotate a handler's
3217 * return type against (directly, or via a per-event restricted alias).
3318 */
3419export type EventResult < T = unknown > =
3520 | { type : 'pass' }
3621 | { type : 'patch' ; patch : Partial < T > }
37- | ( { type : 'prevent' } & ( { reason : string } | { i18n : I18nMessage } ) )
38- | ( { type : 'prompt' } & PromptPayload ) ;
22+ | ( { type : 'prevent' } & ( { reason : string } | { i18n : I18nMessage } ) ) ;
3923
4024/** Branded variant returned by `EventResult.pass()`. */
4125export type PassEventResult = IMarker & { type : 'pass' } ;
@@ -46,22 +30,19 @@ export type PatchEventResult<T> = IMarker & { type: 'patch'; patch: Partial<T> }
4630/** Branded variant returned by `EventResult.prevent()`. */
4731export type PreventEventResult = IMarker & { type : 'prevent' } & ( { reason : string } | { i18n : I18nMessage } ) ;
4832
49- /** Branded variant returned by `EventResult.prompt()`. */
50- export type PromptEventResult = IMarker & { type : 'prompt' } & PromptPayload ;
51-
5233/**
5334 * The shape that actually crosses the JSON-RPC boundary and that
5435 * `isEventResult()` recognizes — `EventResult` widened with the `@kind` marker.
5536 */
56- export type MarkedEventResult < T = unknown > = PassEventResult | PatchEventResult < T > | PreventEventResult | PromptEventResult ;
37+ export type MarkedEventResult < T = unknown > = PassEventResult | PatchEventResult < T > | PreventEventResult ;
5738
5839/**
5940 * Companion-object factories. `EventResult` is simultaneously the marker-free
6041 * union *type* above and this factory *value* namespace (same name, separate
6142 * type/value namespaces — no declaration-merging trick needed). Each factory
6243 * stamps `@kind` and returns a branded per-variant type so that a handler whose
6344 * return type is a restricted union (e.g. `pass | patch`) fails to typecheck if
64- * an author returns a disallowed variant (e.g. `prompt `).
45+ * an author returns a disallowed variant (e.g. `prevent `).
6546 */
6647// eslint-disable-next-line @typescript-eslint/no-redeclare -- the union type and the factory namespace share a name on purpose
6748export const EventResult = {
@@ -76,8 +57,4 @@ export const EventResult = {
7657 prevent ( input : { reason : string } | { i18n : I18nMessage } ) : PreventEventResult {
7758 return { '@kind' : EVENT_RESULT_KIND , 'type' : 'prevent' , ...input } ;
7859 } ,
79-
80- prompt ( input : PromptPayload ) : PromptEventResult {
81- return { '@kind' : EVENT_RESULT_KIND , 'type' : 'prompt' , ...input } ;
82- } ,
8360} ;
0 commit comments