events-backend: renamed EventBusStore params -> event

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-09-13 09:56:09 +02:00
parent f1fb54af5b
commit 94b1caee5e
5 changed files with 12 additions and 12 deletions
@@ -35,7 +35,7 @@ describe('DatabaseEventBusStore', () => {
for (let i = 0; i < 10; ++i) {
await store.publish({
params: { topic: 'test', eventPayload: { n: i } },
event: { topic: 'test', eventPayload: { n: i } },
});
}
@@ -75,7 +75,7 @@ describe('DatabaseEventBusStore', () => {
for (let i = 0; i < 10; ++i) {
await store.publish({
params: { topic: 'test', eventPayload: { n: i } },
event: { topic: 'test', eventPayload: { n: i } },
});
}
@@ -114,7 +114,7 @@ describe('DatabaseEventBusStore', () => {
for (let i = 0; i < 10; ++i) {
await store.publish({
params: { topic: 'test', eventPayload: { n: i } },
event: { topic: 'test', eventPayload: { n: i } },
});
}
@@ -348,10 +348,10 @@ export class DatabaseEventBusStore implements EventBusStore {
}
async publish(options: {
params: EventParams;
event: EventParams;
notifiedSubscribers?: string[];
}): Promise<{ eventId: string } | undefined> {
const topic = options.params.topic;
const topic = options.event.topic;
const notifiedSubscribers = options.notifiedSubscribers ?? [];
// This query inserts a new event into the database, but only if there are
// subscribers to the topic that have not already been notified
@@ -374,8 +374,8 @@ export class DatabaseEventBusStore implements EventBusStore {
this.#db.raw('?', [topic]),
this.#db.raw('?', [
JSON.stringify({
payload: options.params.eventPayload,
metadata: options.params.metadata,
payload: options.event.eventPayload,
metadata: options.event.metadata,
}),
]),
this.#db.raw('?', [notifiedSubscribers]),
@@ -33,10 +33,10 @@ export class MemoryEventBusStore implements EventBusStore {
}>();
async publish(options: {
params: EventParams;
event: EventParams;
notifiedSubscribers: string[];
}): Promise<{ eventId: string } | undefined> {
const topic = options.params.topic;
const topic = options.event.topic;
const notifiedSubscribers = new Set(options.notifiedSubscribers);
let hasOtherSubscribers = false;
@@ -51,7 +51,7 @@ export class MemoryEventBusStore implements EventBusStore {
}
const nextSeq = this.#getMaxSeq() + 1;
this.#events.push({ ...options.params, notifiedSubscribers, seq: nextSeq });
this.#events.push({ ...options.event, notifiedSubscribers, seq: nextSeq });
for (const listener of this.#listeners) {
if (listener.topics.has(topic)) {
@@ -160,7 +160,7 @@ export async function createEventBusRouter(options: {
const topic = req.body.event.topic;
const notifiedSubscribers = req.body.notifiedSubscribers;
const result = await store.publish({
params: {
event: {
topic,
eventPayload: req.body.event.payload,
} as EventParams,
@@ -18,7 +18,7 @@ import { EventParams } from '@backstage/plugin-events-node';
export type EventBusStore = {
publish(options: {
params: EventParams;
event: EventParams;
notifiedSubscribers?: string[];
}): Promise<{ eventId: string } | undefined>;