Merge pull request #22656 from drodil/signals_types
feat: allow defining signal type
This commit is contained in:
@@ -11,19 +11,23 @@ import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
export class DefaultSignalService implements SignalService {
|
||||
// (undocumented)
|
||||
static create(options: SignalServiceOptions): DefaultSignalService;
|
||||
publish(signal: SignalPayload): Promise<void>;
|
||||
publish<TMessage extends JsonObject = JsonObject>(
|
||||
signal: SignalPayload<TMessage>,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export type SignalPayload = {
|
||||
export type SignalPayload<TMessage extends JsonObject = JsonObject> = {
|
||||
recipients: string[] | string | null;
|
||||
channel: string;
|
||||
message: JsonObject;
|
||||
message: TMessage;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export interface SignalService {
|
||||
publish(signal: SignalPayload): Promise<void>;
|
||||
publish<TMessage extends JsonObject = JsonObject>(
|
||||
signal: SignalPayload<TMessage>,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import { EventBroker } from '@backstage/plugin-events-node';
|
||||
import { SignalPayload, SignalServiceOptions } from './types';
|
||||
import { SignalService } from './SignalService';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/** @public */
|
||||
export class DefaultSignalService implements SignalService {
|
||||
@@ -31,12 +32,12 @@ export class DefaultSignalService implements SignalService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes a message to user refs to specific topic
|
||||
* @param recipients - string or array of user ref strings to publish message to
|
||||
* @param topic - message topic
|
||||
* @param message - message to publish
|
||||
* Publishes a signal to user refs to specific topic
|
||||
* @param signal - Signal to publish
|
||||
*/
|
||||
async publish(signal: SignalPayload) {
|
||||
async publish<TMessage extends JsonObject = JsonObject>(
|
||||
signal: SignalPayload<TMessage>,
|
||||
) {
|
||||
await this.eventBroker?.publish({
|
||||
topic: 'signals',
|
||||
eventPayload: signal,
|
||||
|
||||
@@ -14,11 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { SignalPayload } from './types';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/** @public */
|
||||
export interface SignalService {
|
||||
/**
|
||||
* Publishes a message to user refs to specific topic
|
||||
* Publishes a signal to user refs to specific topic
|
||||
* @param signal - Signal to publish
|
||||
*/
|
||||
publish(signal: SignalPayload): Promise<void>;
|
||||
publish<TMessage extends JsonObject = JsonObject>(
|
||||
signal: SignalPayload<TMessage>,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ export type SignalServiceOptions = {
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type SignalPayload = {
|
||||
export type SignalPayload<TMessage extends JsonObject = JsonObject> = {
|
||||
recipients: string[] | string | null;
|
||||
channel: string;
|
||||
message: JsonObject;
|
||||
message: TMessage;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user