feat: allow defining signal type
this makes using especially the frontend API much usable as the signal can be typed instead having plain json object to play around with. Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -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<SignalType extends JsonObject = JsonObject>(
|
||||
signal: SignalPayload<SignalType>,
|
||||
) {
|
||||
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<SignalType extends JsonObject = JsonObject>(
|
||||
signal: SignalPayload<SignalType>,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ export type SignalServiceOptions = {
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type SignalPayload = {
|
||||
export type SignalPayload<SignalType extends JsonObject = JsonObject> = {
|
||||
recipients: string[] | string | null;
|
||||
channel: string;
|
||||
message: JsonObject;
|
||||
message: SignalType;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user